ADMB Documentation  11.5.3197
 All Classes Files Functions Variables Typedefs Friends Defines
ccumdlog.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id$
00003  *
00004  * Author: David Fournier
00005  * Copyright (c) 2008-2012 Regents of the University of California
00006  */
00011 #include <fvar.hpp>
00012 
00013 double inv_cumd_norm_inner(double x);
00014 
00019 double cumd_logistic(const double& x)
00020 {
00021   if (x>=0.0)
00022   {
00023     return 1.0/(1.0+exp(-x));
00024   }
00025   else
00026   {
00027     double y=exp(x);
00028     return y/(1.0+y);
00029   }
00030 }
00031 
00036 double inv_cumd_logistic(const double& x)
00037 {
00038   return log(x/(1.0-x));
00039 }
00040 
00045 double inv_cumd_norm_logistic(double x,double p)
00046 {
00047 #if defined(SAFE_ALL)
00048   if (0.0<p || 1.0>p)
00049   {
00050     cerr << "Error in double inv_cumd_norm_logistic -- illegal p value = "
00051          << p << endl;
00052     exit(1);
00053   }
00054 #endif
00055   cout << log(x) << " ";
00056   double y=inv_cumd_logistic(x);
00057   cout << log(cumd_norm_logistic(y,p)) << " ";
00058   if (y>0)
00059   {
00060     for (int i=1;i<=10;i++)
00061     {
00062       double yp=(1.0-p)*0.39894228*exp(-.5*y*y) + p*exp(-y)/square(1.0+exp(-y));
00063       y+= 1/yp* (x-cumd_norm_logistic(y,p));
00064       cout << cumd_norm_logistic(y,p) << " ";
00065     }
00066   }
00067   else
00068   {
00069     for (int i=1;i<=10;i++)
00070     {
00071       double yp=(1.0-p)*0.39894228*exp(-.5*y*y) + p*exp(y)/square(1.0+exp(y));
00072       y+= 1/yp* (x-cumd_norm_logistic(y,p));
00073       cout << cumd_norm_logistic(y,p) << " ";
00074     }
00075   }
00076   cout << endl;
00077   return y;
00078 }
00079 
00084 double cumd_norm_logistic(double _x,double p)
00085 {
00086   return (1.0-p)*cumd_norm(_x)+p*cumd_logistic(_x);
00087 }