ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cnormmix.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 
40 static double cumd_normal_mixture_initx(double y,double a)
41 {
42  double x;
43  if (y>0.999)
44  {
45  x= a*inv_cumd_norm((y-0.95)/0.05);
46  }
47  else if (y<.001)
48  {
49  x= 1.0-a*inv_cumd_norm((.05-y)/0.05);
50  }
51  else
52  {
53  x=inv_cumd_norm(y);
54  }
55  return x;
56 }
57 
62 static double nr_generic(double y,pinit_f p_get_initial_x,
63  pinit_f pfun,pinit_f pdfun)
64 {
65  double x=(*p_get_initial_x)(y,3.0);
66 
67  const int imax=15;
68  int icount=0;
69  do
70  {
71  icount++;
72  double cy=(*pfun)(x,3.0);
73  double der=(*pdfun)(x,3.0);
74  double diff=y-cy;
75  double h=diff/der;
76  x+=h;
77  if (fabs(h)<1.e-12) break;
78  }
79  while(icount<imax);
80  //cout << " x = " << x << " icount = " << icount << endl;
81 
82 
83  return x;
84 }
85 
90 double inv_cumd_normal_mixture(double yy,double a)
91 {
94  return x;
95 }
#define x
static double cc
Definition: cnormmix.cpp:13
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)
Definition: cnormmix.cpp:40
static double cumd_normal_mixture(double x, double a)
Description not yet available.
Definition: cnormmix.cpp:21
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
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
double cumd_norm(const double &x)
Culative normal distribution; constant objects.
Definition: cumdist.cpp:90
static double df_cumd_normal_mixture(double x, double a)
Description not yet available.
Definition: cnormmix.cpp:32
double inv_cumd_normal_mixture(double yy, double a)
Description not yet available.
Definition: cnormmix.cpp:90