ADMB Documentation  11.1.2503
 All Classes Files Functions Variables Typedefs Friends Defines
df1b2f25.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id: df1b2f25.cpp 1967 2014-04-30 23:36:04Z johnoel $
00003  *
00004  * Author: David Fournier
00005  * Copyright (c) 2008-2012 Regents of the University of California
00006  */
00012 #include <df1b2fun.h>
00013 #include <admodel.h>
00014 
00015 //double ndfboundp( double x, double fmin, double fmax,const double& fpen);
00016 
00021   int initial_df1b2params::stddev_scale(const dvector& d,const dvector& x)
00022   {
00023     int ii=1;
00024     for (int i=0;i<num_initial_df1b2params;i++)
00025     {
00026       if (withinbound(0,(varsptr[i])->phase_start,current_phase))
00027         (varsptr[i])->sd_scale(d,x,ii);
00028     }
00029     return ii-1;
00030   }
00031 
00036 void df1b2_init_number::sd_scale(const dvector& _d,const dvector& x,
00037   const int& _ii)
00038   {
00039     int& ii=(int&) _ii;
00040     dvector& d=(dvector&) _d;
00041     d(ii)=1;
00042     if (scalefactor) d(ii)/=scalefactor;
00043     ii++;
00044   }
00045 
00050 void df1b2_init_bounded_number::sd_scale(const dvector& _d,const dvector& x,
00051   const int& _ii)
00052   {
00053     int& ii=(int&) _ii;
00054     dvector& d=(dvector&) _d;
00055     double pen=0;
00056     if(!initial_params::mc_phase)
00057     {
00058       if (!scalefactor)
00059         d(ii)=ndfboundp(x(ii),minb,maxb,pen);
00060       else
00061         d(ii)=ndfboundp(x(ii)/scalefactor,minb,maxb,pen)/scalefactor;
00062     }
00063     else
00064     {
00065       if (!scalefactor)
00066         d(ii)=ndfboundp_mc(x(ii),minb,maxb,pen);
00067       else
00068         d(ii)=ndfboundp_mc(x(ii)/scalefactor,minb,maxb,pen)/scalefactor;
00069     }
00070 
00071     //d(ii)=(boundp(x(ii)+1.e-6,minb,maxb,pen)-
00072     //boundp(x(ii)-1.e-6,minb,maxb,pen))/2.e-6;
00073     ii++;
00074   }
00075 
00080 void df1b2_init_vector::sd_scale(const dvector& _v,const dvector& x,
00081   const int& _ii)
00082   {
00083     if (allocated())
00084     {
00085       int& ii=(int&) _ii;
00086       dvector& v=(dvector&) _v;
00087       int mmin=indexmin();
00088       int mmax=indexmax();
00089       for (int i=mmin;i<=mmax;i++)
00090       {
00091         v(ii)=1.;
00092         if (scalefactor) v(ii)/=scalefactor;
00093         ii++;
00094       }
00095     }
00096   }
00097 
00102 void df1b2_init_matrix::sd_scale(const dvector& _v,const dvector& x,
00103   const int& _ii)
00104   {
00105     if (allocated())
00106     {
00107       int& ii=(int&) _ii;
00108       dvector& v=(dvector&) _v;
00109       int mmin=indexmin();
00110       int mmax=indexmax();
00111       for (int i=mmin;i<=mmax;i++)
00112       {
00113         if (::allocated((*this)(i)))
00114         {
00115           int cmin=((*this)(i)).indexmin();
00116           int cmax=((*this)(i)).indexmax();
00117           for (int j=cmin;j<=cmax;j++)
00118           {
00119             v(ii)=1.;
00120             if (scalefactor) v(ii)/=scalefactor;
00121             ii++;
00122           }
00123         }
00124       }
00125     }
00126   }
00127 
00132 void df1b2_init_bounded_vector::sd_scale(const dvector& _v,const dvector& x,
00133   const int& _ii)
00134   {
00135     if (allocated())
00136     {
00137       int& ii=(int&) _ii;
00138       dvector& v=(dvector&) _v;
00139       int mmin=indexmin();
00140       int mmax=indexmax();
00141       double pen=0;
00142       if(!initial_params::mc_phase)
00143       {
00144         for (int i=mmin;i<=mmax;i++)
00145         {
00146           if (!scalefactor)
00147             v(ii)=ndfboundp(x(ii),minb,maxb,pen);
00148           else
00149             v(ii)=ndfboundp(x(ii)/scalefactor,minb,maxb,pen)/scalefactor;
00150           ii++;
00151         }
00152       }
00153       else
00154       {
00155         for (int i=mmin;i<=mmax;i++)
00156         {
00157           v(ii)=ndfboundp_mc(x(ii),minb,maxb,pen);
00158           ii++;
00159         }
00160       }
00161     }
00162   }
00163 
00168 void df1b2_init_bounded_matrix::sd_scale(const dvector& _v,const dvector& x,
00169   const int& _ii)
00170   {
00171     if (allocated())
00172     {
00173       int& ii=(int&) _ii;
00174       dvector& v=(dvector&) _v;
00175       int rmin=indexmin();
00176       int rmax=indexmax();
00177       double pen=0;
00178       for (int i=rmin;i<=rmax;i++)
00179       {
00180         if (::allocated((*this)(i)))
00181         {
00182           int cmin=(*this)(i).indexmin();
00183           int cmax=(*this)(i).indexmax();
00184           for (int j=cmin;j<=cmax;j++)
00185           {
00186             if (!scalefactor)
00187               v(ii)=ndfboundp(x(ii),minb,maxb,pen);
00188             else
00189               v(ii)=ndfboundp(x(ii)/scalefactor,minb,maxb,pen)/
00190                 scalefactor;
00191             ii++;
00192           }
00193         }
00194       }
00195     }
00196   }
00197 
00202 int allocated(const df1b2vector& _x)
00203 {
00204   ADUNCONST(df1b2vector,x)
00205   return x.allocated();
00206 }
00207 
00212 int allocated(const df1b2_init_vector& _x)
00213 {
00214   ADUNCONST(df1b2_init_vector,x)
00215   return x.allocated();
00216 }
00217 
00222 int allocated(const df1b2_init_matrix& _x)
00223 {
00224   ADUNCONST(df1b2_init_matrix,x)
00225   return x.allocated();
00226 }
00227 
00232 int allocated(const df1b2matrix& _x)
00233 {
00234   ADUNCONST(df1b2matrix,x)
00235   return x.allocated();
00236 }