ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
df1b2normmix.cpp
Go to the documentation of this file.
1 /*
2  * $Id$
3  *
4  * Author: David Fournier
5  * Copyright (c) 2008-2012 Regents of the University of California
6  */
11 #include <df1b2fun.h>
12 
13 static double cc=0.39894228040143267794;
14 
15 typedef double (*pinit_f)(double y,double a);
16 
17 double nr_generic(double y,pinit_f p_get_initial_x,
18  pinit_f pfun,pinit_f pdfun);
19 
24 static double cumd_normal_mixture(double x,double a)
25 {
26  double y=0.95*cumd_norm(x)+0.05*cumd_norm(x/a);
27  return y;
28 }
29 
34 static double df_cumd_normal_mixture(double x,double a)
35 {
36  double x2=x*x;
37  double dfx=cc*(0.95*exp(-0.5*x2)+0.05/a*exp(-0.5*x2/(a*a)) );
38 
39  return dfx;
40 }
41 
46 static double cumd_normal_mixture_initx(double y,double a)
47 {
48  double x;
49  if (y>0.999)
50  {
51  x= a*inv_cumd_norm((y-0.95)/0.05);
52  }
53  else if (y<.001)
54  {
55  x= 1.0-a*inv_cumd_norm((.05-y)/0.05);
56  }
57  else
58  {
59  x=inv_cumd_norm(y);
60  }
61  return x;
62 }
63 
69 {
71  df1b2variable z;
74 
75  // the derivatives of the inverse
76  double x2=x*x;
77  double a2=a*a;
78  double a3=a2*a;
79  double a5=a2*a3;
80  double e1=exp(-0.5*x2);
81  double e2=exp(-0.5*x2/a2);
82 
83  double dgx=cc*(0.95*e1+0.05/a*e2);
84 
85  double d2g=-cc*x*(0.95*e1+0.05/a3*e2);
86 
87  double d3g=-cc*(0.95*e1+0.05/a3*e2)
88  +cc*x2*(0.95*e1+0.05/a5*e2);
89 
90  double dfx=1.0/dgx;
91  double d2f=-d2g*cube(dfx);
92  double d3f=-d3g*cube(dfx)*dfx-3.0*d2g*d2f*square(dfx);
93 
94  double * yd=yy.get_u_dot();
95  double * zd=z.get_u_dot();
96  *z.get_u()=x;
97  for (unsigned int i=0;i<df1b2variable::nvar;i++)
98  {
99  *zd++ =dfx * *yd++;
100  }
102  f1b2gradlist->write_pass1(&yy,&z,dfx,d2f,d3f);
103 
104  return z;
105 }
106 
df1b2_gradlist * f1b2gradlist
Definition: df1b2glo.cpp:49
static double df_cumd_normal_mixture(double x, double a)
Description not yet available.
double * get_u() const
Definition: df1b2fun.h:228
#define x
#define ADUNCONST(type, obj)
Creates a shallow copy of obj that is not CONST.
Definition: fvar.hpp:140
double inv_cumd_norm(const double &x)
Description not yet available.
Definition: cumdist.cpp:78
d3_array cube(const d3_array &m)
Description not yet available.
Definition: d3arr5.cpp:17
static double cumd_normal_mixture(double x, double a)
Description not yet available.
Definition: cnormmix.cpp:21
Description not yet available.
Definition: df1b2fun.h:266
static double cc
double * get_u_dot() const
Definition: df1b2fun.h:229
static int no_derivatives
Definition: df1b2fun.h:759
d3_array exp(const d3_array &arr3)
Returns d3_array results with computed exp from elements in arr3.
Definition: d3arr2a.cpp:28
double(* pinit_f)(double y, double a)
Definition: cnorlogmix.cpp:15
int write_pass1(const df1b2variable *px, const df1b2variable *py, df1b2variable *pz, df1b2function2 *pf)
Description not yet available.
Definition: df1b2f12.cpp:17
double nr_generic(double y, double a, pinit_f p_get_initial_x, pinit_f pfun, pinit_f pdfun)
Description not yet available.
Definition: normmix2.cpp:73
static unsigned int nvar
Definition: df1b2fun.h:290
Description not yet available.
static double cumd_normal_mixture_initx(double y, double a)
Description not yet available.
dvector value(const df1_one_vector &v)
Definition: df11fun.cpp:69
double cumd_norm(const double &x)
Culative normal distribution; constant objects.
Definition: cumdist.cpp:90
double inv_cumd_normal_mixture(double yy, double a)
Description not yet available.
Definition: cnormmix.cpp:90
double square(const double value)
Return square of value; constant object.
Definition: d3arr4.cpp:16