ADMB Documentation  11.1.2192
 All Classes Files Functions Variables Typedefs Friends Defines
model10.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id: model10.cpp 1919 2014-04-22 22:02:01Z johnoel $
00003  *
00004  * Author: David Fournier
00005  * Copyright (c) 2008-2012 Regents of the University of California
00006  */
00007 #include <admodel.h>
00008 
00009 //double ndfboundp(double x, double fmin, double fmax, const double& fpen);
00010 
00011 void param_init_number::sd_scale(const dvector& _d, const dvector& x,
00012   const int& _ii)
00013   {
00014     int& ii=(int&) _ii;
00015     dvector& d=(dvector&) _d;
00016     d(ii)=1;
00017     if (scalefactor) d(ii)/=scalefactor;
00018     ii++;
00019   }
00020 
00021 void param_init_bounded_number::sd_scale(const dvector& _d, const dvector& x,
00022   const int& _ii)
00023   {
00024     int& ii=(int&) _ii;
00025     dvector& d=(dvector&) _d;
00026     double pen=0;
00027     if(!initial_params::mc_phase)
00028     {
00029       if (!scalefactor)
00030         d(ii)=ndfboundp(x(ii),minb,maxb,pen);
00031       else
00032         d(ii)=ndfboundp(x(ii)/scalefactor,minb,maxb,pen)/scalefactor;
00033     }
00034     else
00035     {
00036       if (!scalefactor)
00037         d(ii)=ndfboundp_mc(x(ii),minb,maxb,pen);
00038       else
00039         d(ii)=ndfboundp_mc(x(ii)/scalefactor,minb,maxb,pen)/scalefactor;
00040     }
00041     //d(ii)=(boundp(x(ii)+1.e-6,minb,maxb,pen)-
00042     //boundp(x(ii)-1.e-6,minb,maxb,pen))/2.e-6;
00043     ii++;
00044   }
00045 
00046 void param_init_vector::sd_scale(const dvector& _v, const dvector& x,
00047   const int& _ii)
00048   {
00049     if (allocated(*this))
00050     {
00051       int& ii=(int&) _ii;
00052       dvector& v=(dvector&) _v;
00053       int mmin=indexmin();
00054       int mmax=indexmax();
00055       for (int i=mmin;i<=mmax;i++)
00056       {
00057         v(ii)=1.;
00058         if (scalefactor) v(ii)/=scalefactor;
00059         ii++;
00060       }
00061     }
00062   }
00063 
00064 void param_init_matrix::sd_scale(const dvector& _v, const dvector& x,
00065   const int& _ii)
00066   {
00067     if (allocated(*this))
00068     {
00069       int& ii=(int&) _ii;
00070       dvector& v=(dvector&) _v;
00071       int mmin=rowmin();
00072       int mmax=rowmax();
00073       for (int i=mmin;i<=mmax;i++)
00074       {
00075         if (allocated((*this)(i)))
00076         {
00077           int cmin=((*this)(i)).indexmin();
00078           int cmax=((*this)(i)).indexmax();
00079           for (int j=cmin;j<=cmax;j++)
00080           {
00081             v(ii)=1.;
00082             if (scalefactor) v(ii)/=scalefactor;
00083             ii++;
00084           }
00085         }
00086       }
00087     }
00088   }
00089 
00090 void param_init_bounded_vector::sd_scale(const dvector& _v, const dvector& x,
00091   const int& _ii)
00092   {
00093     if (allocated(*this))
00094     {
00095       int& ii=(int&) _ii;
00096       dvector& v=(dvector&) _v;
00097       int mmin=indexmin();
00098       int mmax=indexmax();
00099       double pen=0;
00100       if(!initial_params::mc_phase)
00101       {
00102         for (int i=mmin;i<=mmax;i++)
00103         {
00104           if (!scalefactor)
00105             v(ii)=ndfboundp(x(ii),minb,maxb,pen);
00106           else
00107             v(ii)=ndfboundp(x(ii)/scalefactor,minb,maxb,pen)/scalefactor;
00108           ii++;
00109         }
00110       }
00111       else
00112       {
00113         for (int i=mmin;i<=mmax;i++)
00114         {
00115           v(ii)=ndfboundp_mc(x(ii),minb,maxb,pen);
00116           ii++;
00117         }
00118       }
00119     }
00120   }
00121 
00122 void param_init_bounded_matrix::sd_scale(const dvector& _v, const dvector& x,
00123   const int& _ii)
00124   {
00125     if (allocated(*this))
00126     {
00127       int& ii=(int&) _ii;
00128       dvector& v=(dvector&) _v;
00129       int rmin=rowmin();
00130       int rmax=rowmax();
00131       double pen=0;
00132       for (int i=rmin;i<=rmax;i++)
00133       {
00134         if (allocated((*this)(i)))
00135         {
00136           int cmin=(*this)(i).indexmin();
00137           int cmax=(*this)(i).indexmax();
00138           for (int j=cmin;j<=cmax;j++)
00139           {
00140             if (!scalefactor)
00141               v(ii)=ndfboundp(x(ii),minb,maxb,pen);
00142             else
00143               v(ii)=ndfboundp(x(ii)/scalefactor,minb,maxb,pen)/
00144                 scalefactor;
00145             ii++;
00146           }
00147         }
00148       }
00149     }
00150   }
00151 
00152   void param_init_bounded_number::set_minb(double x)
00153   {
00154     minb=x;
00155   }
00156 
00157   double param_init_bounded_number::get_minb(void)
00158   {
00159     return minb;
00160   }
00161 
00162   void param_init_bounded_vector::set_minb(double x)
00163   {
00164     minb=x;
00165   }
00166 
00167   double param_init_bounded_vector::get_minb(void)
00168   {
00169     return minb;
00170   }
00171 
00172   void param_init_bounded_matrix::set_minb(double x)
00173   {
00174     minb=x;
00175   }
00176 
00177   double param_init_bounded_matrix::get_minb(void)
00178   {
00179     return minb;
00180   }