ADMB Documentation  11.1.1916
 All Classes Files Functions Variables Typedefs Friends Defines
mceval.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id: mceval.cpp 1673 2014-02-25 18:47:21Z johnoel $
00003  *
00004  * Author: David Fournier
00005  * Copyright (c) 2008-2012 Regents of the University of California
00006  */
00011 #include <admodel.h>
00012 
00017 void function_minimizer::mcmc_eval(void)
00018 {
00019   gradient_structure::set_NO_DERIVATIVES();
00020   initial_params::current_phase=initial_params::max_number_phases;
00021   uistream * pifs_psave = NULL;
00022 
00023 #if defined(USE_LAPLACE)
00024 #endif
00025 
00026 #if defined(USE_LAPLACE)
00027     initial_params::set_active_random_effects();
00028     int nvar1=initial_params::nvarcalc();
00029 #else
00030   int nvar1=initial_params::nvarcalc(); // get the number of active parameters
00031 #endif
00032   int nvar = 0;
00033 
00034   pifs_psave= new
00035     uistream((char*)(ad_comm::adprogram_name + adstring(".psv")));
00036   if (!pifs_psave || !(*pifs_psave))
00037   {
00038     cerr << "Error opening file "
00039             << (char*)(ad_comm::adprogram_name + adstring(".psv"))
00040        << endl;
00041     if (pifs_psave)
00042     {
00043       delete pifs_psave;
00044       pifs_psave=NULL;
00045       return;
00046     }
00047   }
00048   else
00049   {
00050     (*pifs_psave) >> nvar;
00051     if (nvar!=nvar1)
00052     {
00053       cout << "Incorrect value for nvar in file "
00054            << "should be " << nvar1 << " but read " << nvar << endl;
00055       if (pifs_psave)
00056       {
00057         delete pifs_psave;
00058         pifs_psave=NULL;
00059       }
00060       return;
00061     }
00062   }
00063 
00064   independent_variables y(1,nvar);
00065 
00066   do
00067   {
00068     if (pifs_psave->eof())
00069     {
00070       break;
00071     }
00072     else
00073     {
00074       (*pifs_psave) >> y;
00075       if (pifs_psave->eof())
00076       {
00077         break;
00078       }
00079       int ii=1;
00080       initial_params::restore_all_values(y,ii);
00081       initial_params::xinit(y);
00082       /*double ll=-*/get_monte_carlo_value(nvar,y);
00083     }
00084   }
00085   while(1);
00086   if (pifs_psave)
00087   {
00088     delete pifs_psave;
00089     pifs_psave=NULL;
00090   }
00091   return;
00092 }