ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
adrndeff.h
Go to the documentation of this file.
1 /*
2  * $Id$
3  *
4  * Author: David Fournier
5  * Copyright (c) 2008-2012 Regents of the University of California
6  *
7  * ADModelbuilder and associated libraries and documentations are
8  * provided under the general terms of the "BSD" license.
9  *
10  * License:
11  *
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions are
14  * met:
15  *
16  * 1. Redistributions of source code must retain the above copyright
17  * notice, this list of conditions and the following disclaimer.
18  *
19  * 2. Redistributions in binary form must reproduce the above copyright
20  * notice, this list of conditions and the following disclaimer in the
21  * documentation and/or other materials provided with the distribution.
22  *
23  * 3. Neither the name of the University of California, Otter Research,
24  * nor the ADMB Foundation nor the names of its contributors may be used
25  * to endorse or promote products derived from this software without
26  * specific prior written permission.
27  *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39  *
40  */
46 #if !defined(__RANDEFFECTS__)
47 # define __RANDEFFECTS__
48 
49 # include <admodel.h>
50 
52 class hs_symbolic;
54 
59 {
60  virtual void set_random_effects_active();
61  virtual void set_random_effects_inactive();
62  virtual void set_only_random_effects_active();
63  virtual void set_only_random_effects_inactive();
64 };
65 
70 {
71  virtual void set_random_effects_active();
72  virtual void set_random_effects_inactive();
73  virtual void set_only_random_effects_active();
74  virtual void set_only_random_effects_inactive();
75 };
76 
81 {
82  virtual void set_random_effects_active();
83  virtual void set_random_effects_inactive();
84  virtual void set_only_random_effects_active();
85  virtual void set_only_random_effects_inactive();
86 };
87 
88 
90 
95 {
96  virtual void set_random_effects_active();
97  virtual void set_random_effects_inactive();
98  virtual void set_only_random_effects_active();
99  virtual void set_only_random_effects_inactive();
100 };
101 
106 {
107  virtual void set_random_effects_active();
108  virtual void set_random_effects_inactive();
109  virtual void set_only_random_effects_active();
110  virtual void set_only_random_effects_inactive();
111 };
112 
117 {
118  virtual void set_random_effects_active();
119  virtual void set_random_effects_inactive();
120  virtual void set_only_random_effects_active();
121  virtual void set_only_random_effects_inactive();
122 };
123 
124 class gauss_hermite_stuff;
125 
126 class nested_calls_shape;
127 //class sparse_symbolic;
128 
133 {
138 public:
139  nested_calls_indices(void) : ptr1(0),ptr2(0),ptr3(0),ptr4(0){}
140  ivector & level1(int i) {return (*ptr1)(i);}
141  ivector & level2(int i,int j) {return (*ptr2)(i,j);}
142  ivector & level3(int i,int j,int k) {return (*ptr3)(i,j,k);}
143  ivector & level4(int i,int j,int k,int l) {return (*ptr4)(i,j,k,l);}
144  void allocate(const nested_calls_shape& nsc);
145 };
146 
151 {
156 public:
157  nested_calls_shape(void) : ptr1(0),ptr2(0),ptr3(0),ptr4(0){}
158  ivector * get_ptr1(void);
159  imatrix * get_ptr2(void);
160  i3_array * get_ptr3(void);
161  i4_array * get_ptr4(void);
162  void trim(void);
163  void allocate(int);
164  void allocate(int,int);
165  void allocate(int,int,int);
166  void allocate(int,int,int,int);
167  void initialize(void);
169  int & level1(int i) {return (*ptr1)(i);}
170  int & operator () (int i) {return (*ptr1)(i);}
171  int & level2(int i,int j) {return (*ptr2)(i,j);}
172  int & operator () (int i,int j) {return (*ptr2)(i,j);}
173  int & level3(int i,int j,int k) {return (*ptr3)(i,j,k);}
174  int & operator () (int i,int j,int k) {return (*ptr3)(i,j,k);}
175  int & level4(int i,int j,int k,int l) {return (*ptr4)(i,j,k,l);}
176  int & operator () (int i,int j,int k,int l) {return (*ptr4)(i,j,k,l);}
177 };
178 
183 {
184 public:
198  static int saddlepointflag;
201  static int antiflag;
202  int rseed;
205  // 1 in inner opt 2 in newton-raphson 3 in laplace approximation
206  static int where_are_we_flag;
207  // 1 in inner opt 2 in newton-raphson 3 in
209  // 1 in inner opt 2 in newton-raphson 3 in
213  // 1 in inner opt 2 in newton-raphson 3 in
215  // 1 in inner opt 2 in newton-raphson 3 in
235  double inner_crit;
237  double nr_crit;
241  int nr_debug;
248  int bw;
249  int xsize;
250  int usize;
252  unsigned int nvar;
259  int hesstype;
260  int var_flag;
276 
277  void make_sparse_triplet(void);
278  void check_for_need_to_reallocate(int ip);
284  double do_one_feval(const dvector& x,function_minimizer * pfmin);
288  dvector lincg(dvector& x,dvector& c, dmatrix& H,double tol,double Delta,
289  function_minimizer * pfmin,double& truef,double& e,double& f,
290  double& fbest,int& iflag,int& iter,int maxfn);
291  dvector test_trust_region_method(const dvector& _x,const double& _f,
292  function_minimizer * pfmin);
294  double & f);
296  //fmmt1 fmc1;
320  function_minimizer * pfmin);
323  void set_u_dot(int i);
324 
326  (const df1b2variable& ff);
327 
329 
331  laplace_approximation_calculator(int _xsize,int _usize,int _minder,
332  int _maxder,function_minimizer * pfmin);
333 
334  laplace_approximation_calculator(int _xsize,int _usize,ivector _minder,
335  ivector _maxder, function_minimizer * pfmin);
336 
337  dvector operator () (const dvector& _x,const double& _f,
338  function_minimizer * pfmin);
339 
340  dvector get_uhat(const dvector& x,function_minimizer * pfmin);
341 
343 
344  void do_separable_stuff(void);
350  function_minimizer * pfmin,const double& f);
351  dvector default_calculations(const dvector& _x,const double& _f,
352  function_minimizer * pfmin);
353  dvector banded_calculations(const dvector& _x,const double& _f,
354  function_minimizer * pfmin);
355  dvector block_diagonal_calculations(const dvector& _x,const double& _f,
356  function_minimizer * pfmin);
358  const double& _f,function_minimizer * pfmin);
360  const double& _f,function_minimizer * pfmin);
365  double inner_optimization_banded(/*dvector& uhat,*/ dvector& x,
366  function_minimizer * pfmin,int& no_converge_flag);
367  void set_default_hessian_type(void);
368  void check_hessian_type(const dvector& _x,function_minimizer * );
374 
376  (df1b2variable&);
379  dvector banded_calculations_lme(const dvector& _x,const double& _f,
380  function_minimizer * pfmin);
383  dvector get_gradient_lme_hp(const double& x,function_minimizer * pfmin);
384  void check_pool_size(void);
385  void check_derivatives(const dvector&,function_minimizer * pfmin,
386  double fval1);
388  dvector& grad,double lambda);
390  dvector& grad,double lambda);
392  double get_fx_fu(function_minimizer * pfmin);
395  double standard_type3_loop(int no_converge_flag);
397  (function_minimizer * pfmin,double f_from_1,int& no_converge_flag);
398  void begin_separable_call_stuff(void);
399  void end_separable_call_stuff(void);
400  void build_up_nested_shape(void);
401 };
402 
407 {
408 public:
412  int is;
414 
416  int use_gauss_hermite,int num_separable_calls ,const ivector& itmp);
417 
419 };
420 
421  ostream& operator << (const ostream &,const nested_calls_shape &);
422 
423 #endif // #if !defined(__RANDEFFECTS__)
dvector operator()(const dvector &_x, const double &_f, function_minimizer *pfmin)
Description not yet available.
Definition: df1b2lap.cpp:1298
Description not yet available.
Definition: fvar.hpp:7981
virtual void set_random_effects_active()
Definition: model52.cpp:75
i3_array * ptr3
Definition: adrndeff.h:154
static dvar_vector * variance_components_vector
Definition: adrndeff.h:204
dcompressed_triplet * sparse_triplet2
Definition: adrndeff.h:271
void do_newton_raphson_banded(function_minimizer *pmin, double, int &)
Description not yet available.
Definition: df1b2lp6.cpp:53
dvector banded_calculations(const dvector &_x, const double &_f, function_minimizer *pfmin)
Description not yet available.
Definition: df1b2lp6.cpp:335
i5_array * ptr4
Definition: adrndeff.h:137
Description not yet available.
Definition: adrndeff.h:182
virtual void set_random_effects_active()
Definition: model52.cpp:85
function_minimizer * pmin
Definition: adrndeff.h:246
dvector get_uhat(const dvector &x, function_minimizer *pfmin)
i4_array * ptr3
Definition: adrndeff.h:136
i3_array * ptr2
Definition: adrndeff.h:135
Description not yet available.
Definition: imatrix.h:69
void test_trust_region_method(function_minimizer *pmin)
dcompressed_triplet * sparse_triplet
Definition: adrndeff.h:267
Description not yet available.
Definition: adrndeff.h:105
void generate_antithetical_rvs()
Description not yet available.
Definition: df1b2lp8.cpp:136
virtual void set_only_random_effects_active()
Definition: model52.cpp:22
void get_complete_hessian(dmatrix &H, function_minimizer *pfmin)
ivector * ptr1
Definition: adrndeff.h:152
double get_fx_fu(function_minimizer *pfmin)
Description not yet available.
Definition: df1b2lap.cpp:2330
Description not yet available.
Definition: adrndeff.h:80
void check_pool_size(void)
Description not yet available.
Definition: df1b2lp1.cpp:871
void do_separable_stuff(void)
Description not yet available.
Definition: f1b2fnl2.cpp:26
void begin_separable_call_stuff(void)
Description not yet available.
Definition: df1b2lap.cpp:2367
i4_array * ptr4
Definition: adrndeff.h:155
dvector default_calculations_check_derivatives(const dvector &_x, function_minimizer *pfmin, const double &f)
Description not yet available.
Definition: df1b2chkder.cpp:55
i3_array * get_ptr3(void)
Description not yet available.
Definition: df1b2lap.cpp:2507
virtual void set_only_random_effects_active()
Definition: model52.cpp:27
dvector get_gradient_lme(const dvector &x, function_minimizer *pfmin)
Description not yet available.
Definition: df1b2lme.cpp:264
#define x
double do_one_feval(const dvector &x, function_minimizer *pfmin)
Description not yet available.
Definition: test_trust.cpp:526
Vector of double precision numbers.
Definition: dvector.h:50
dvar_matrix * importance_sampling_components
Definition: adrndeff.h:224
Description not yet available.
Definition: fvar.hpp:9222
Description not yet available.
Definition: admodel.h:1151
int & level1(int i)
Definition: adrndeff.h:169
void get_hessian_components_banded_lme(function_minimizer *pfmin)
Description not yet available.
Definition: df1b2lme.cpp:20
imatrix * compressed_triplet_information
Definition: adrndeff.h:193
gauss_hermite_stuff * gh
Definition: adrndeff.h:223
virtual void set_only_random_effects_inactive()
Definition: model52.cpp:45
Description not yet available.
Definition: admodel.h:1409
dvar_matrix get_hessian_from_components_lme(function_minimizer *pfmin)
Description not yet available.
Definition: df1b2lme.cpp:128
void build_up_nested_shape(void)
Description not yet available.
Definition: df1b2lap.cpp:2391
virtual void set_random_effects_inactive()
Definition: model52.cpp:125
dvector get_gradient_lme_hp(const double &x, function_minimizer *pfmin)
Description not yet available.
Definition: df1b2lme.cpp:291
void do_separable_stuff_laplace_approximation_importance_sampling_adjoint(df1b2variable &)
Description not yet available.
Definition: f1b2fnl5.cpp:176
dvector get_newton_raphson_info_block_diagonal(function_minimizer *pmin)
Description not yet available.
Definition: df1b2lp2.cpp:414
gauss_hermite_stuff(laplace_approximation_calculator *lapprox, int use_gauss_hermite, int num_separable_calls, const ivector &itmp)
Description not yet available.
Definition: df1b2lap.cpp:2250
void allocate(int)
Description not yet available.
Definition: df1b2lap.cpp:2740
void pvm_slave_function_evaluation_random_effects(void)
void do_newton_raphson_state_space(function_minimizer *pfmin, double f_from_1, int &no_converge_flag)
Definition: df1b2lp11.cpp:203
virtual void set_only_random_effects_inactive()
Definition: model52.cpp:50
int & level2(int i, int j)
Definition: adrndeff.h:171
imatrix * ptr2
Definition: adrndeff.h:153
ADMB variable vector.
Definition: fvar.hpp:2172
dvector banded_calculations_lme(const dvector &_x, const double &_f, function_minimizer *pfmin)
Description not yet available.
Definition: df1b2lme.cpp:178
void do_separable_stuff_laplace_approximation_banded(df1b2variable &)
Description not yet available.
Definition: df1b2lp6.cpp:897
void check_hessian_type(const dvector &_x, function_minimizer *)
Description not yet available.
Definition: df1b2lp8.cpp:360
void trim(void)
Description not yet available.
Definition: df1b2lap.cpp:2548
laplace_approximation_calculator(int _xsize, int _usize, int _minder, int _maxder, function_minimizer *pfmin)
Description not yet available.
Definition: df1b2lap.cpp:324
void initialize(void)
Description not yet available.
Definition: df1b2lap.cpp:2713
virtual void set_only_random_effects_active()
Definition: model52.cpp:34
void check_hessian_type2(function_minimizer *pfmin)
Description not yet available.
Definition: df1b2lp10.cpp:98
dvector local_minimization_routine(dvector &s, dmatrix &Hess, dvector &grad, double lambda)
Description not yet available.
Definition: dflocmin.cpp:98
nested_calls_shape(void)
Definition: adrndeff.h:157
Description not yet available.
Definition: df1b2fun.h:266
Description not yet available.
Definition: admodel.h:968
void get_block_diagonal_hessian(df1b2variable &)
Description not yet available.
Definition: f1b2fnl5.cpp:23
dvector block_diagonal_calculations(const dvector &_x, const double &_f, function_minimizer *pfmin)
Description not yet available.
Definition: df1b2lp2.cpp:32
void get_newton_raphson_info_slave(function_minimizer *pmin)
void get_newton_raphson_info_master(function_minimizer *pmin)
~laplace_approximation_calculator()
Destructor.
Definition: df1b2lap.cpp:1140
virtual void set_only_random_effects_inactive()
Definition: model52.cpp:55
void set_u_dot(int i)
Description not yet available.
Definition: df1b2lp1.cpp:856
Description not yet available.
Definition: fvar.hpp:5769
banded_symmetric_dmatrix * bHess
Definition: adrndeff.h:265
virtual void set_random_effects_inactive()
Definition: model52.cpp:110
Description not yet available.
Definition: adrndeff.h:94
dcompressed_triplet * vsparse_triplet_adjoint
Definition: adrndeff.h:273
Description not yet available.
Definition: admodel.h:1228
Description not yet available.
Definition: admodel.h:1058
void do_separable_stuff_newton_raphson_block_diagonal(df1b2variable &)
Description not yet available.
Definition: f1b2fnl2.cpp:143
void check_for_need_to_reallocate(int ip)
Does Nothing.
Definition: df1b2lap.cpp:1968
void set_default_hessian_type(void)
Description not yet available.
Definition: df1b2lap.cpp:2302
dvar3_array * block_diagonal_vch
Definition: adrndeff.h:228
dvector get_uhat_quasi_newton(const dvector &x, function_minimizer *pfmin)
Description not yet available.
Definition: df1b2lap.cpp:63
dvector default_calculations(const dvector &_x, const double &_f, function_minimizer *pfmin)
Description not yet available.
Definition: df1b2lp1.cpp:44
Array of integers(int) with indexes from index_min to indexmax.
Definition: ivector.h:50
virtual void set_random_effects_active()
Definition: model52.cpp:80
virtual void set_only_random_effects_inactive()
Definition: model52.cpp:70
dvector local_minimization(dvector &s, dmatrix &Hess, dvector &grad, double lambda)
Description not yet available.
Definition: dflocmin.cpp:42
void default_calculations_parallel_slave(const dvector &_x, const double &_f, function_minimizer *pfmin)
double inner_optimization_banded(dvector &x, function_minimizer *pfmin, int &no_converge_flag)
Description not yet available.
Definition: df1b2lp6.cpp:297
virtual void set_only_random_effects_active()
Definition: model52.cpp:40
multi_index * mi
Definition: adrndeff.h:413
double standard_type3_loop(int no_converge_flag)
Description not yet available.
Definition: adrndeff.h:58
Description not yet available.
Functions and variables for function minimizer.
Definition: fvar.hpp:3290
Description not yet available.
Definition: fvar.hpp:9345
Description not yet available.
Definition: adrndeff.h:69
virtual void set_only_random_effects_inactive()
Definition: model52.cpp:65
ivector & level1(int i)
Definition: adrndeff.h:140
Description not yet available.
Definition: fvar.hpp:2819
dvector get_newton_raphson_info_banded(function_minimizer *pmin)
Description not yet available.
Definition: df1b2lp6.cpp:822
Description not yet available.
Definition: fvar.hpp:4197
d3_array * block_diagonal_vhessianadjoint
Definition: adrndeff.h:232
virtual void set_random_effects_active()
Definition: model52.cpp:100
void allocate_block_diagonal_stuff(void)
Description not yet available.
Definition: df1b2lp8.cpp:821
void do_separable_stuff_newton_raphson_banded(df1b2variable &)
Description not yet available.
Definition: df1b2lp6.cpp:680
Description not yet available.
Definition: fvar.hpp:9293
Description not yet available.
Definition: admodel.h:1316
dvector banded_calculations_trust_region_approach(const dvector &_uhat, function_minimizer *pmin)
Description not yet available.
Definition: df1b2lp6.cpp:1143
dvar3_array * block_diagonal_vhessian
Definition: adrndeff.h:233
Description not yet available.
Definition: adrndeff.h:406
void do_separable_stuff_laplace_approximation_banded_adjoint(const df1b2variable &ff)
Description not yet available.
Definition: df1b2lp7.cpp:24
void allocate(const nested_calls_shape &nsc)
Description not yet available.
Definition: df1b2lap.cpp:2774
virtual void set_random_effects_inactive()
Definition: model52.cpp:105
Description not yet available.
Definition: df1b2fun.h:373
ostream & operator<<(const ostream &_s, preshowpoint p)
Description not yet available.
Definition: admanip.cpp:48
dvector get_uhat_quasi_newton_block_diagonal(const dvector &x, function_minimizer *pfmin)
Description not yet available.
Definition: df1b2lp9.cpp:34
virtual void set_only_random_effects_inactive()
Definition: model52.cpp:60
nested_calls_indices nested_indices
Definition: adrndeff.h:186
imatrix check_sparse_matrix_structure(void)
Description not yet available.
Definition: df1b2lp8.cpp:1171
Description not yet available.
Definition: fvar.hpp:9410
dvector lincg(dvector &x, dvector &c, dmatrix &H, double tol, double Delta, function_minimizer *pfmin, double &truef, double &e, double &f, double &fbest, int &iflag, int &iter, int maxfn)
Description not yet available.
Definition: test_trust.cpp:629
dvector default_calculations_parallel_master(const dvector &_x, const double &_f, function_minimizer *pfmin)
Class definition of matrix with derivitive information .
Definition: fvar.hpp:2480
~nested_calls_shape()
Description not yet available.
Definition: df1b2lap.cpp:2617
virtual void set_random_effects_inactive()
Definition: model52.cpp:115
ivector * get_ptr1(void)
Description not yet available.
Definition: df1b2lap.cpp:2489
virtual void set_random_effects_active()
Definition: model52.cpp:95
dvar_matrix gauss_hermite_values
Definition: adrndeff.h:409
Description not yet available.
Definition: adrndeff.h:150
ivector & level2(int i, int j)
Definition: adrndeff.h:141
Description not yet available.
Definition: fvar.hpp:6067
nested_calls_indices(void)
Definition: adrndeff.h:139
i4_array * get_ptr4(void)
Description not yet available.
Definition: df1b2lap.cpp:2516
ivector & level3(int i, int j, int k)
Definition: adrndeff.h:142
void make_sparse_triplet(void)
Description not yet available.
Definition: df1b2lp8.cpp:25
Description not yet available.
Definition: adrndeff.h:116
dvector get_uhat_quasi_newton_qd(const dvector &x, function_minimizer *pfmin)
Description not yet available.
Definition: f1b2lapqd.cpp:28
virtual void set_only_random_effects_active()
Definition: model52.cpp:10
dvar_compressed_triplet * vsparse_triplet
Definition: adrndeff.h:272
void do_separable_stuff_hessian_type_information(void)
Description not yet available.
Definition: df1b2lp8.cpp:1019
banded_symmetric_dmatrix * bHessadjoint
Definition: adrndeff.h:266
int & level4(int i, int j, int k, int l)
Definition: adrndeff.h:175
Description not yet available.
Definition: admodel.h:1850
void get_newton_raphson_info(function_minimizer *pmin)
Description not yet available.
Definition: df1b2lp1.cpp:718
virtual void set_random_effects_active()
Definition: model52.cpp:90
void do_separable_stuff_x_u_block_diagonal(df1b2variable &ff)
Description not yet available.
Definition: f1b2fnl3.cpp:24
Description not yet available.
Definition: fvar.hpp:3944
virtual void set_random_effects_inactive()
Definition: model52.cpp:120
dvector get_uhat_lm_newton2(const dvector &x, function_minimizer *pfmin)
Description not yet available.
Definition: df1b2lap.cpp:2814
Description not yet available.
Definition: fvar.hpp:3727
void end_separable_call_stuff(void)
Description not yet available.
Definition: df1b2lap.cpp:2380
virtual void set_only_random_effects_active()
Definition: model52.cpp:16
int & level3(int i, int j, int k)
Definition: adrndeff.h:173
dvector get_uhat_lm_newton(const dvector &x, function_minimizer *pfmin)
Description not yet available.
Definition: df1b2lap.cpp:218
virtual void set_random_effects_inactive()
Definition: model52.cpp:130
void do_separable_stuff_laplace_approximation_block_diagonal(df1b2variable &)
Calculates the Laplace approximation for a single separable function in the &quot;block diagonal&quot;...
Definition: f1b2fnl3.cpp:159
ivector & level4(int i, int j, int k, int l)
Definition: adrndeff.h:143
nested_calls_shape nested_shape
Definition: adrndeff.h:187
static int alternative_user_function_flag
Definition: adrndeff.h:199
Description not yet available.
Definition: adrndeff.h:132
static int print_importance_sampling_weights_flag
Definition: adrndeff.h:203
imatrix * get_ptr2(void)
Description not yet available.
Definition: df1b2lap.cpp:2498
void check_derivatives(const dvector &, function_minimizer *pfmin, double fval1)
Description not yet available.
Definition: df1b2chkder.cpp:42
int & operator()(int i)
Definition: adrndeff.h:170
dmatrix get_gradient_for_hessian_calcs(const dmatrix &local_Hess, double &f)
Description not yet available.
Definition: f1b2fnl3.cpp:364