ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cnorlogmix.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;
14 
15 typedef double (*pinit_f)(double y,double a);
16 
21 static double cumd_normal_logistic_mixture(double x,double a)
22 {
23  // "normal" value for a is 3.0
24  double y;
25  if (x>-20.0)
26  {
27  y=0.95*cumd_norm(x)+0.05/(1.0+exp(-x/a));
28  }
29  else
30  {
31  y=0.95*cumd_norm(x)+0.05/(1.0+exp(-x/a));
32  }
33  return y;
34 }
35 
40 static double df_cumd_normal_logistic_mixture(double x,double a)
41 {
42  // "normal" value for a is 3.0
43  //double y=0.95*cumd_norm(x)+0.05*cumd_norm(x/a)
44  double x2=x*x;
45  double dfx;
46  if (x>-20.0)
47  {
48  dfx=cc*0.95*exp(-0.5*x2)+0.05/a*exp(-x/a)/square(1.0+exp(-x/a));
49  }
50  else
51  {
52  dfx=cc*0.95*exp(-0.5*x2)+0.05/a*exp(-x/a)/square(1.0+exp(-x/a));
53  }
54 
55  return dfx;
56 }
57 
62 static double cumd_normal_logistic_mixture_initx(double y,double a)
63 {
64  double x;
65  if (y>0.999)
66  {
67  x= a*inv_cumd_logistic((y-0.95)/0.05);
68  }
69  else if (y<.001)
70  {
71  x= 1.0-a*inv_cumd_logistic((.05-y)/0.05);
72  }
73  else
74  {
75  x=inv_cumd_norm(y);
76  }
77  return x;
78 }
79 
84 double nr_generic(double y,double a,pinit_f p_get_initial_x,
85  pinit_f pfun,pinit_f pdfun);
86 
88 {
92  dvariable z;
93  value(z)=x;
94  double dfx=1.0/df_cumd_normal_logistic_mixture(x,a);
96  &(value(z)), &(value(yy)),dfx);
97  return z;
98 }
99 
100 /*
101 main()
102 {
103  gradient_structure gs(10000);
104  dvariable y;
105  cin >> y;
106  dvariable x=inv_cumd_normal_logistic_mixture(y,3.0);
107 }
108 */
109 //********************************************************
110 //********************************************************
111 //********************************************************
112 #include <fvar.hpp>
113 
118 double robust_normal_logistic_mixture_deviate(double x,double spread)
119 {
120  double y=cumd_norm(x);
121  y = 0.99999999*y + 0.000000005; // To gain numerical stability
122  double z = inv_cumd_normal_logistic_mixture(y,spread);
123  return z;
124 }
125 
130 double robust_normal_mixture_deviate(double x,double spread)
131 {
132  double y=cumd_norm(x);
133  y = 0.99999999*y + 0.000000005; // To gain numerical stability
134  double z = inv_cumd_normal_mixture(y,spread);
135  return z;
136 }
137 
142 double inv_cumd_normal_logistic_mixture(double yy,double a)
143 {
146  return x;
147 }
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 robust_normal_mixture_deviate(double x, double spread)
Description not yet available.
Definition: cnorlogmix.cpp:130
double inv_cumd_norm(const double &x)
Description not yet available.
Definition: cumdist.cpp:78
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
double inv_cumd_logistic(const double &x)
Description not yet available.
Definition: ccumdlog.cpp:30
static double cumd_normal_logistic_mixture(double x, double a)
Description not yet available.
Definition: cnorlogmix.cpp:21
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
dvariable inv_cumd_normal_logistic_mixture(const prevariable &_yy, double a)
Definition: cnorlogmix.cpp:87
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 robust_normal_logistic_mixture_deviate(double x, double spread)
Description not yet available.
Definition: cnorlogmix.cpp:118
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 double df_cumd_normal_logistic_mixture(double x, double a)
Description not yet available.
Definition: cnorlogmix.cpp:40
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
double square(const double value)
Return square of value; constant object.
Definition: d3arr4.cpp:16
Fundamental data type for reverse mode automatic differentiation.
Definition: fvar.hpp:1518
static double cc
Definition: cnorlogmix.cpp:13
static double cumd_normal_logistic_mixture_initx(double y, double a)
Description not yet available.
Definition: cnorlogmix.cpp:62