ADMB Documentation  11.1.1890
 All Classes Files Functions Variables Typedefs Friends Defines
ad3d.h
Go to the documentation of this file.
00001 /*
00002  * $Id: ad3d.h 1729 2014-03-04 01:26:24Z johnoel $
00003  *
00004  * Author: David Fournier
00005  * Copyright (c) 2008-2012 Regents of the University of California
00006  *
00007  * ADModelbuilder and associated libraries and documentations are
00008  * provided under the general terms of the "BSD" license.
00009  *
00010  * License:
00011  *
00012  * Redistribution and use in source and binary forms, with or without
00013  * modification, are permitted provided that the following conditions are
00014  * met:
00015  *
00016  * 1. Redistributions of source code must retain the above copyright
00017  * notice, this list of conditions and the following disclaimer.
00018  *
00019  * 2.  Redistributions in binary form must reproduce the above copyright
00020  * notice, this list of conditions and the following disclaimer in the
00021  * documentation and/or other materials provided with the distribution.
00022  *
00023  * 3.  Neither the name of the  University of California, Otter Research,
00024  * nor the ADMB Foundation nor the names of its contributors may be used
00025  * to endorse or promote products derived from this software without
00026  * specific prior written permission.
00027  *
00028  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00029  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00030  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00031  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00032  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00033  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00034  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00035  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00036  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00037  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00038  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00039  *
00040  */
00045 #include <admodel.h>
00046 
00051 class param_init_d3array: public named_dvar3_array,public initial_params
00052 {
00053 public:
00054   virtual void set_value(const dvar_vector& x, const int& ii,
00055     const dvariable& pen);
00056   virtual void copy_value_to_vector(const dvector& x, const int& ii);
00057   virtual void restore_value_from_vector(const dvector&, const int&);
00058   virtual void set_value_inv(const dvector& x, const int& ii);
00059   virtual int size_count(void);
00060   virtual void save_value(void);
00061   virtual void save_value(const ofstream& ofs, int prec);
00062   virtual void restore_value(const ifstream& ifs);
00063   void report_value(void);
00064   //virtual void read_value(void);
00065   virtual const char * label(void);
00066   virtual void sd_scale(const dvector& d, const dvector& x, const int& ii);
00067   virtual void hess_scale(const dvector& d, const dvector& x, const int& ii){};
00068 
00069 public:
00070   void allocate(int smin,int smax,int rmin,int rmax,int cmin,int cmax,
00071     int phase_start=1,const char * = "UNNAMED");
00072   void allocate(int smin,int smax,int rmin,int rmax,int cmin,int cmax,
00073     const char * = "UNNAMED");
00074   param_init_d3array(void);
00075 };
00076 
00081   void param_init_d3array::copy_value_to_vector(const dvector& x, const int& ii)
00082   {
00083     ::copy_value_to_vector(*this,x,ii);
00084   }
00085 
00090 void param_init_d3array::restore_value_from_vector(const dvector& x,
00091   const int& ii)
00092   {
00093     ::restore_value_from_vector(*this,x,ii);
00094   }
00095 
00100   void param_init_d3array::save_value(const ofstream& ofs,int prec)
00101   {
00102     ofs << setw(prec+6) << setprecision(prec) << dvar3_array(*this) << endl;
00103   }
00104 
00109   void param_init_d3array::allocate(int smin,int smax,int rmin,int rmax,
00110     int cmin,int cmax,const char * s)
00111   {
00112     allocate(smin,smax,rmin,rmax,cmin,cmax,phase_start,s);
00113   }
00114 
00119   void param_init_d3array::allocate(int smin,int smax,int rmin,int rmax,
00120     int cmin,int cmax,int phase_start, const char * s)
00121   {
00122     named_dvar3_array::allocate(smin,smax,rmin,rmax,cmin,cmax,s);
00123     initial_params::allocate(phase_start);
00124     if (ad_comm::global_parfile)
00125     {
00126       *(ad_comm::global_parfile) >> dvar3_array(*this);
00127     }
00128     else
00129     {
00130       dvar3_array::operator=(initial_value);
00131     }
00132   }
00133 
00138 void param_init_d3array::hess_scale(const dvector& v, const dvector& x,
00139   const int& ii)
00140   {
00141     int smin=slicemin();
00142     int smax=slicemax();
00143     for (int k=smin;k<=smax;i++)
00144     {
00145       int mmin=(*this(k)).rowmin();
00146       int mmax=(*this(k)).rowmax();
00147       for (int i=mmin;i<=mmax;i++)
00148       {
00149         int cmin=((*this)(k,i)).indexmin();
00150         int cmax=((*this)(k,i)).indexmax();
00151         for (int j=cmin;j<=cmax;j++)
00152         {
00153           v(ii++)=0.;
00154         }
00155       }
00156     }
00157   }
00158 
00163 void param_init_d3array::sd_scale(const dvector& v, const dvector& x,
00164   const int& ii)
00165   {
00166     int smin=slicemin();
00167     int smax=slicemax();
00168     for (int k=smin;k<=smax;i++)
00169     {
00170       int mmin=(*this(k)).rowmin();
00171       int mmax=(*this(k)).rowmax();
00172       for (int i=mmin;i<=mmax;i++)
00173       {
00174         int cmin=((*this)(k,i)).indexmin();
00175         int cmax=((*this)(k,i)).indexmax();
00176         for (int j=cmin;j<=cmax;j++)
00177         {
00178           v(ii++)=1.;
00179         }
00180       }
00181     }
00182   }
00183 
00188 cifstream& operator>>(const cifstream& s, param_init_3darray& m)
00189 {
00190   s >> dvar3_array(m);
00191   return s;
00192 }
00193 
00198 void param_init_d3array::restore_value(const ifstream& ofs)
00199 {
00200   ofs  >> dvar3_array(*this);
00201 }