ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
mc_scale.cpp
Go to the documentation of this file.
1 
5 #include <admodel.h>
6 
7 double set_value_mc(double z,double min,double max);
8 //double ndfboundp( double x, double fmin, double fmax,const double& fpen);
9 //double ndfboundp_mc( double x, double fmin, double fmax,const double& fpen);
10 
16 {
17  int ii = 1;
18  for (int i = 0; i < num_initial_params; i++)
19  {
20  //if ((varsptr[i])->phase_start <= current_phase)
22  (varsptr[i])->mc_scale(d,x,ii);
23  }
24  return ii - 1;
25 }
26 
32  const int& _ii)
33 {
34  dvector& d=(dvector&) _d;
35  int& ii=(int&) _ii;
36  d(ii)=1;
37  ii++;
38 }
39 
45  const int& _ii)
46 {
47  dvector& d=(dvector&) _d;
48  int& ii=(int&) _ii;
49  double pen=0;
50  //double var;
51  double xx=set_value_inv_mc(*this,minb,maxb);
52  double yy=boundpin(*this,minb,maxb);
53  double a=ndfboundp(yy,minb,maxb,pen);
54  double b=ndfboundp_mc(xx,minb,maxb,pen);
55  d(ii)=b/a;
56  ii++;
57 }
58 
63 double ndfboundp_mc(double x, double fmin, double fmax,const double& fpen)
64 {
65  if (x<-0.99999)
66  {
67  double df1=(set_value_mc(x+1.e-6,fmin,fmax)-
68  set_value_mc(x,fmin,fmax))/1.e-6;
69  double df2=(set_value_mc(x+2.e-6,fmin,fmax)
70  -set_value_mc(x,fmin,fmax))/2.e-6;
71  return 2.*df1-df2;
72  }
73  else if (x>0.99999)
74  {
75  double df1=(set_value_mc(x,fmin,fmax)
76  -set_value_mc(x-1.e-6,fmin,fmax))/1.e-6;
77  double df2=(set_value_mc(x,fmin,fmax)-
78  set_value_mc(x-2.e-6,fmin,fmax))/2.e-6;
79  return 2.*df1-df2;
80  }
81  else
82  {
83  return (set_value_mc(x+1.e-6,fmin,fmax)-
84  set_value_mc(x-1.e-6,fmin,fmax))/2.e-6;
85  }
86 }
87 
93  const int& _ii)
94 {
95  int& ii=(int&) _ii;
96  dvector& v=(dvector&) _v;
97  int mmin=indexmin();
98  int mmax=indexmax();
99  for (int i=mmin;i<=mmax;i++)
100  {
101  v(ii++)=1.;
102  }
103 }
104 
110  const int& _ii)
111 {
112  int& ii=(int&) _ii;
113  dvector& v=(dvector&) _v;
114  int mmin=rowmin();
115  int mmax=rowmax();
116  for (int i=mmin;i<=mmax;i++)
117  {
118  int cmin=((*this)(i)).indexmin();
119  int cmax=((*this)(i)).indexmax();
120  for (int j=cmin;j<=cmax;j++)
121  {
122  v(ii++)=1.;
123  }
124  }
125 }
126 
132  const int& _ii)
133 {
134  int& ii=(int&) _ii;
135  dvector& v=(dvector&) _v;
136  int mmin=slicemin();
137  int mmax=slicemax();
138  for (int i=mmin;i<=mmax;i++)
139  {
140  int rmin=((*this)(i)).rowmin();
141  int rmax=((*this)(i)).rowmax();
142  for (int j=rmin;j<=rmax;j++)
143  {
144  int cmin=((*this)(i))(j).indexmin();
145  int cmax=((*this)(i))(j).indexmax();
146  for (int k=cmin;k<=cmax;k++)
147  {
148  v(ii++)=1.;
149  }
150  }
151  }
152 }
153 
159  const int& _ii)
160 {
161  int& ii=(int&) _ii;
162  dvector& v=(dvector&) _v;
163  int mmin=indexmin();
164  int mmax=indexmax();
165  double pen=0;
166  for (int i=mmin;i<=mmax;i++)
167  {
168  double var=set_value_mc(x(ii),minb,maxb);
169  double xx=boundpin(var,minb,maxb);
170  double a=ndfboundp(xx,minb,maxb,pen);
171  double b=ndfboundp_mc(x(ii),minb,maxb,pen);
172  v(ii)=b/a;
173  ii++;
174  }
175 }
176 
182  const int& _ii)
183 {
184  int& ii=(int&) _ii;
185  dvector& v=(dvector&) _v;
186  int rmin=rowmin();
187  int rmax=rowmax();
188  double pen=0;
189  for (int i=rmin;i<=rmax;i++)
190  {
191  int cmin=(*this)(i).indexmin();
192  int cmax=(*this)(i).indexmax();
193  for (int j=cmin;j<=cmax;j++)
194  {
195  v(ii)=ndfboundp(x(ii),minb,maxb,pen);
196  double var=set_value_mc(x(ii),minb,maxb);
197  double xx=set_value_inv_mc(var,minb,maxb);
198  double a=ndfboundp(xx,minb,maxb,pen);
199  double b=ndfboundp_mc(xx,minb,maxb,pen);
200  v(ii)=b/a;
201  ii++;
202  }
203  }
204 }
int rowmax(void) const
Definition: fvar.hpp:2564
int slicemin() const
Definition: fvar.hpp:4274
int withinbound(int lb, int n, int ub)
Definition: model.cpp:45
#define x
Vector of double precision numbers.
Definition: dvector.h:50
void fmin(double f, const independent_variables &x, const dvector &g, const int &n, const dvector &w, const dvector &h, const fmm_control &fmc)
int slicemax() const
Definition: fvar.hpp:4275
virtual void mc_scale(const dvector &d, const dvector &x, const int &)
Description not yet available.
Definition: mc_scale.cpp:181
virtual void mc_scale(const dvector &d, const dvector &x, const int &)
Description not yet available.
Definition: mc_scale.cpp:44
virtual void mc_scale(const dvector &d, const dvector &x, const int &)
Description not yet available.
Definition: mc_scale.cpp:158
int indexmax() const
Definition: fvar.hpp:4273
virtual void mc_scale(const dvector &d, const dvector &x, const int &)
Description not yet available.
Definition: mc_scale.cpp:109
double boundpin(double x, double fmin, double fmax, double s)
Scale model variable over [-1,1]; constant objects.
Definition: boundfun.cpp:378
static int current_phase
Definition: admodel.h:842
double var(const dvector &vec)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
Definition: cranfill.cpp:23
#define min(a, b)
Definition: cbivnorm.cpp:188
Description not yet available.
double set_value_inv_mc(double v, double fmin, double fmax)
Definition: mod_mc3.cpp:116
double ndfboundp(double x, double fmin, double fmax, const double &fpen)
Derivatative code for double nd2fboundp( double x, double fmin, double fmax,const double&amp; fpen) ...
Definition: boundfun.cpp:210
int rowmin(void) const
Definition: fvar.hpp:2560
static int num_initial_params
Definition: admodel.h:836
void set_value_mc(const dvar_vector &x, const dvar_vector &v, const int &ii, const double fmin, const double fmax)
Definition: mod_mc3.cpp:152
virtual void mc_scale(const dvector &d, const dvector &x, const int &)
Description not yet available.
Definition: mc_scale.cpp:92
virtual void mc_scale(const dvector &d, const dvector &x, const int &)
Description not yet available.
Definition: mc_scale.cpp:31
int indexmin() const
Definition: fvar.hpp:2287
int indexmax(void) const
Definition: fvar.hpp:2572
virtual void mc_scale(const dvector &d, const dvector &x, const int &)
Description not yet available.
Definition: mc_scale.cpp:131
int phase_start
Definition: admodel.h:848
double ndfboundp_mc(double x, double fmin, double fmax, const double &fpen)
Description not yet available.
Definition: mc_scale.cpp:63
#define max(a, b)
Definition: cbivnorm.cpp:189
virtual void mc_scale(const dvector &d, const dvector &x, const int &ii)=0
int indexmin(void) const
Definition: fvar.hpp:2568
int indexmax() const
Definition: fvar.hpp:2292
int indexmin() const
Definition: fvar.hpp:4272
static adlist_ptr varsptr
Definition: admodel.h:838
static int montecarlo_scale(const dvector &d, const dvector &x)
Description not yet available.
Definition: mc_scale.cpp:15