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