ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
normmix.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 <fvar.hpp>
12 
13 static double cc=0.39894228040143267794; // 1/sqrt(2*pi)
14 
15 typedef double (*pinit_f)(double y,double a);
16 
21 static double cumd_normal_mixture(double x,double a)
22 {
23  // "normal" value for a is 3.0
24  double y=0.95*cumd_norm(x)+0.05*cumd_norm(x/a);
25  return y;
26 }
27 
32 static double df_cumd_normal_mixture(double x,double a)
33 {
34  double x2=x*x;
35  double dfx=cc*(0.95*exp(-0.5*x2)+0.05/a*exp(-0.5*x2/(a*a)) );
36 
37  return dfx;
38 }
39 
44 static double cumd_normal_mixture_initx(double y,double a)
45 {
46  double x;
47  if (y>0.999)
48  {
49  x= a*inv_cumd_norm((y-0.95)/0.05);
50  }
51  else if (y<.001)
52  {
53  x= 1.0-a*inv_cumd_norm((.05-y)/0.05);
54  }
55  else
56  {
57  x=inv_cumd_norm(y);
58  }
59  return x;
60 }
61 
66 double nr_generic(double y,pinit_f p_get_initial_x,
67  pinit_f pfun,pinit_f pdfun)
68 {
69  double x=(*p_get_initial_x)(y,3.0);
70 
71  const int imax=15;
72  int icount=0;
73  do
74  {
75  icount++;
76  double cy=(*pfun)(x,3.0);
77  double der=(*pdfun)(x,3.0);
78  double diff=y-cy;
79  double h=diff/der;
80  x+=h;
81  if (fabs(h)<1.e-12) break;
82  }
83  while(icount<imax);
84  //cout << " x = " << x << " icount = " << icount << endl;
85 
86 
87  return x;
88 }
89 
95 {
99  dvariable z;
100  value(z)=x;
101  double dfx=1.0/df_cumd_normal_mixture(x,a);
103  &(value(z)), &(value(yy)),dfx);
104  return z;
105 }
Base class for dvariable.
Definition: fvar.hpp:1315
#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
df1_two_variable fabs(const df1_two_variable &x)
Definition: df12fun.cpp:891
static double cumd_normal_mixture_initx(double y, double a)
Description not yet available.
Definition: normmix.cpp:44
static double cc
Definition: normmix.cpp:13
static double cumd_normal_mixture(double x, double a)
Description not yet available.
Definition: cnormmix.cpp:21
void set_gradient_stack(void(*func)(void), double *dep_addr, double *ind_addr1=NULL, double mult1=0, double *ind_addr2=NULL, double mult2=0)
Description not yet available.
Definition: fvar.hpp:1045
static double df_cumd_normal_mixture(double x, double a)
Description not yet available.
Definition: normmix.cpp:32
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
d3_array exp(const d3_array &arr3)
Returns d3_array results with computed exp from elements in arr3.
Definition: d3arr2a.cpp:28
void default_evaluation(void)
Description not yet available.
Definition: def_eval.cpp:61
double(* pinit_f)(double y, double a)
Definition: cnorlogmix.cpp:15
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
dvector value(const df1_one_vector &v)
Definition: df11fun.cpp:69
static _THREAD grad_stack * GRAD_STACK1
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
Fundamental data type for reverse mode automatic differentiation.
Definition: fvar.hpp:1518