ADMB Documentation  11.1.1916
 All Classes Files Functions Variables Typedefs Friends Defines
xmodelm5.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id: xmodelm5.cpp 1108 2013-07-11 23:46:23Z johnoel $
00003  *
00004  * Author: David Fournier
00005  * Copyright (c) 2008-2012 Regents of the University of California
00006  */
00007 #include <admodel.h>
00008 
00009 #if defined(USE_LAPLACE)
00010 #  include <df1b2fun.h>
00011 #  include <adrndeff.h>
00012 #endif
00013 
00014 #if defined(USE_LAPLACE)
00015 dvariable function_minimizer::do_gauss_hermite_integration(void)
00016 {
00017   if (lapprox->gh->mi)
00018   {
00019     return do_gauss_hermite_integration_multi();
00020   }
00021   else
00022   {
00023     dvariable fun=0.0;
00024     int nsc=lapprox->num_separable_calls;
00025     dvector& w=lapprox->gh->w;
00026     for (int is=1;is<=nsc;is++)
00027     {
00028       fun-=log(1.e-50+exp(-lapprox->gh->gauss_hermite_values(is))*w);
00029     }
00030     return fun;
00031   }
00032 }
00033 
00034 dvariable function_minimizer::do_gauss_hermite_integration_multi(void)
00035 {
00036   multi_index mi=*(lapprox->gh->mi);
00037   dvariable fun=0.0;
00038   int nsc=lapprox->num_separable_calls;
00039   dvector& w=lapprox->gh->w;
00040   ivector& lrea = *(lapprox->num_local_re_array);
00041   for (int isc=1;isc<=nsc;isc++)
00042   {
00043     dvariable ftmp=0.0;
00044     int lus=lrea(isc);
00045     mi.initialize();
00046     double ww;
00047     do
00048     {
00049       ww=1.0;
00050       for (int iu=1;iu<=lus;iu++)
00051       {
00052         ww*= w(mi()(iu));
00053       }
00054       int is=mi.get_offset()+1;
00055       ftmp+=exp(-lapprox->gh->gauss_hermite_values(isc,is))*ww;
00056       ++mi;
00057     }
00058     while(mi.get_depth()<=lus);
00059     fun-=log(ftmp);
00060   }
00061   return fun;
00062 }
00063 #endif // #if defined(USE_LAPLACE)