41 int mmin=cti(cti.
indexmin()).indexmin();
42 int mmax=cti(cti.
indexmin()).indexmax();
45 for (
int i=mmin+1;i<=mmax;i++)
47 if (cti(1,i)>cti(1,i-1))
52 else if (cti(2,i)>lmin)
77 int mmin=cti(cti.
indexmin()).indexmin();
78 int mmax=cti(cti.
indexmin()).indexmax();
87 (*sparse_triplet2)(1,ii)=cti(1,1);
88 (*sparse_triplet2)(2,ii)=cti(2,1);
89 (*sparse_iterator)(cti(3,1))=ii;
90 for (
int i=mmin+1;i<=mmax;i++)
92 if (cti(1,i)>cti(1,i-1))
95 (*sparse_triplet2)(1,ii)=cti(1,i);
96 (*sparse_triplet2)(2,ii)=cti(2,i);
99 else if (cti(2,i)>lmin)
102 (*sparse_triplet2)(1,ii)=cti(1,i);
103 (*sparse_triplet2)(2,ii)=cti(2,i);
106 (*sparse_iterator)(cti(3,i))=ii;
143 if (itmp(i) != itmp(i-1))
145 cerr <<
"At present can only use antithetical rv's when "
146 "all separable calls are the same size" <<
endl;
156 double mid=
sqrt(
double(n-1));
159 if (mid-spread<=0.001)
163 double tmax=(n-1)*
log(mid)-0.5*mid*mid;
164 for (x=mid-spread;x<=mid+spread;x+=delta)
166 ssum+=
exp((n-1)*
log(x)-0.5*x*x-tmax);
173 for (x=mid-spread;x<=mid+spread;x+=delta)
175 tsum+=
exp((n-1)*
log(x)-0.5*x*x-tmax)/ssum*samplesize;
177 for (ii=1;ii<=ns;ii++)
183 if (is==samplesize-1)
185 dist(samplesize)=mid;
187 else if (is<samplesize-1)
189 cerr <<
"This can't happen" <<
endl;
208 for (
int i=1;i<=samplesize;i++)
212 int nvar=(samplesize-1)*n;
215 for (
int i=2;i<=samplesize;i++)
217 for (
int j=1;j<=n;j++)
231 double fbest=1.e+50;;
251 f=
fcomp1(xx,dist,samplesize,n,g,M);
263 for (
int i=2;i<=samplesize;i++)
265 for (
int j=1;j<=n;j++)
270 for (
int i=1;i<=samplesize;i++)
284 dmatrix C(1,samplesize,1,samplesize);
287 dmatrix dfVM(1,samplesize,1,n);
288 dmatrix dfVM0(1,samplesize,1,n);
297 for (
int i=2;i<=samplesize;i++)
299 for (
int j=1;j<=n;j++)
304 for (
int i=1;i<=samplesize;i++)
307 VM(i)=VM0(i)*(d(i)/
N(i));
309 for (
int i=1;i<=samplesize;i++)
311 for (ii=i+1;ii<=samplesize;ii++)
315 C(i,ii)=
norm2(VM(i)-VM(ii));
321 for (
int i=1;i<=samplesize;i++)
324 dfN(i)+=200*
log(
N(i))/
N(i);
325 for (ii=i+1;ii<=samplesize;ii++)
330 dvector vtmp=-2.0*(VM(i)-VM(ii));
335 for (
int i=1;i<=samplesize;i++)
338 dfVM0(i)=dfVM(i)*d(i)/
N(i);
339 dfN(i)-=(dfVM(i)*VM0(i))*d(i)/
square(
N(i));
342 dfVM0(i)+=dfN(i)/
N(i)*VM0(i);
345 for (
int i=2;i<=samplesize;i++)
347 for (
int j=1;j<=n;j++)
455 (*re_objective_function_value::pobjfun)=0;
499 for (
int i=mmin;i<=mmax;i++)
503 ndim+=(*triplet_information)(i,1).indexmax();
512 (*compressed_triplet_information)(3).fill_seqadd(1,1);
514 for (
int i=mmin;i<=mmax;i++)
518 int jmin=(*triplet_information)(i,1).indexmin();
519 int jmax=(*triplet_information)(i,1).indexmax();
520 for (
int j=jmin;j<=jmax;j++)
523 (*compressed_triplet_information)(ii,1)=
525 (*compressed_triplet_information)(ii,2)=
527 (*compressed_triplet_information)(ii,3)=ii;
535 for (
int i=2;i<=ndim;i++)
537 if (cti(i,1)>cti(i-1,1))
540 cti.
sub(lmin,lmax)=
sort(cti.
sub(lmin,lmax),2);
544 cti.
sub(lmin,ndim)=
sort(cti.
sub(lmin,ndim),2);
552 int non_block_diagonal=0;
557 non_block_diagonal=1;
561 if (non_block_diagonal)
574 cerr <<
"Error allocating banded_symmetric_dmatrix" <<
endl;
584 cerr <<
"Error allocating banded_symmetric_dmatrix" <<
endl;
596 cerr <<
"Error allocating banded_symmetric_dmatrix" <<
endl;
606 cerr <<
"Error allocating banded_symmetric_dmatrix" <<
endl;
738 cerr <<
"error_allocating d3_array" <<
endl;
751 cerr <<
"error_allocating imatrix" <<
endl;
764 cerr <<
"error_allocating imatrix" <<
endl;
778 cerr <<
"error_allocating d3_array" <<
endl;
793 cerr <<
"error_allocating d3_array" <<
endl;
806 cerr <<
"error_allocating d3_array" <<
endl;
851 cerr <<
"error_allocating d3_array" <<
endl;
863 cerr <<
"error_allocating imatrix" <<
endl;
875 cerr <<
"error_allocating imatrix" <<
endl;
888 cerr <<
"error_allocating d3_array" <<
endl;
903 cerr <<
"error_allocating d3_array" <<
endl;
916 cerr <<
"error_allocating d3_array" <<
endl;
926 int num_local_re,
int num_fixed_effects)
929 if (*num_local_re_array == NULL)
931 *num_local_re_array =
new ivector(1,1000);
932 if (*num_local_re_array == NULL)
934 cerr <<
"error allocating ivector" <<
endl;
939 if (num_separable_calls> (*num_local_re_array)->indexmax())
941 if (num_separable_calls != (*num_local_re_array)->indexmax()+1)
943 cerr <<
"this can't happen" <<
endl;
946 int old_max=(*num_local_re_array)->indexmax();
948 int new_max=old_max+100+(int)(10.0*
sqrt(
double(old_max)));
950 double sqrt_oldmax = 10.0 *
sqrt(
double(old_max));
951 assert(sqrt_oldmax <= INT_MAX);
952 int new_max=old_max+100+(int)sqrt_oldmax;
955 tmp=(**num_local_re_array);
957 delete *num_local_re_array;
958 *num_local_re_array =
new ivector(1,new_max);
959 if (*num_local_re_array == NULL)
961 cerr <<
"error allocating ivector" <<
endl;
964 (**num_local_re_array)(1,old_max)=tmp;
966 (**num_local_re_array)(num_separable_calls)=num_local_re;
973 if (*num_local_fixed_array == NULL)
975 *num_local_fixed_array =
new ivector(1,1000);
976 if (*num_local_fixed_array == NULL)
978 cerr <<
"error allocating ivector" <<
endl;
983 if (num_separable_calls> (*num_local_fixed_array)->indexmax())
985 if (num_separable_calls != (*num_local_fixed_array)->indexmax()+1)
987 cerr <<
"this can't happen" <<
endl;
990 int old_max=(*num_local_fixed_array)->indexmax();
992 int new_max=old_max+100+(int)(10.0*
sqrt(
double(old_max)));
994 double sqrt_oldmax = 10.0 *
sqrt(
double(old_max));
995 assert(sqrt_oldmax <= INT_MAX);
996 int new_max=old_max+100+(int)sqrt_oldmax;
999 tmp=(**num_local_fixed_array);
1001 delete *num_local_fixed_array;
1002 *num_local_fixed_array =
new ivector(1,new_max);
1003 if (*num_local_fixed_array == NULL)
1005 cerr <<
"error allocating ivector" <<
endl;
1008 (**num_local_fixed_array)(1,old_max)=tmp;
1010 (**num_local_fixed_array)(num_separable_calls)=num_fixed_effects;
1025 int num_fixed_effects=0;
1030 ivector lfe_index(1, (
int)funnel_init_var::num_active_parameters);
1032 for (
int i=1;i<=(int)funnel_init_var::num_active_parameters;i++)
1034 if (list(i,1)>
xsize)
1036 lre_index(++num_local_re)=i;
1038 else if (list(i,1)>0)
1040 lfe_index(++num_fixed_effects)=i;
1053 for (
int i=1;i<=num_local_re;i++)
1055 int lrei=lre_index(i);
1056 for (
int j=1;j<=num_local_re;j++)
1058 int lrej=lre_index(j);
1059 int i1=list(lrei,1)-
xsize;
1060 int j1=list(lrej,1)-
xsize;
1091 int dim= num_local_re*num_local_re;
1095 for (
int i=1;i<=num_local_re;i++)
1097 int lrei=lre_index(i);
1098 for (
int j=1;j<=num_local_re;j++)
1100 int lrej=lre_index(j);
1101 int i1=list(lrei,1)-
xsize;
1102 int j1=list(lrej,1)-
xsize;
1105 cout <<
"cant happen?" <<
endl;
1136 cerr <<
"Need to increase the maximum number of separable calls allowed"
1139 cerr <<
"Use the -ndi N command line option" <<
endl;
1146 for (
int i=1;i<=num_local_re;i++)
1148 int lrei=lre_index(i);
1149 int i1=list(lrei,1)-
xsize;
1163 funnel_init_var::num_active_parameters=0;
1186 for (
int i=1;i<=n;i++)
1189 for (
int j=1;j<=n;j++)
1195 for (
int k=1;k<=rowsize(row);k++)
1197 if (tmp(row,k)==col)
1206 if (rowsize(row)> tmp(row).indexmax())
1208 tmp(row).reallocate(2);
1210 tmp(row,rowsize(row))=col;
1219 ofstream ofs(
"sparseness.info");
1220 ofs <<
"# Number of parameters" <<
endl;
1222 ofs <<
"# Number of off diagonal elements in each row" <<
endl;
1223 ofs << rowsize <<
endl;
1224 ofs <<
"# The nonempty rows of M" <<
endl;
1225 for (
int i=1;i<=
usize;i++)
1229 M(i)=
sort(tmp(i)(1,rowsize(i)));
1230 ofs << setw(4) <<
M(i) <<
endl;
Description not yet available.
void safe_deallocate()
Safely deallocates memory by reporting if shallow copies are still in scope.
laplace_approximation_calculator * lapprox
void initialize(void)
Description not yet available.
static void reset(const init_df1b2vector &, const df1b2variable &)
Description not yet available.
dcompressed_triplet * sparse_triplet2
virtual void AD_uf_inner()
df1b2_gradlist * f1b2gradlist
static void set_no_derivatives(void)
int separable_calls_counter
function_minimizer * pmin
Description not yet available.
dcompressed_triplet * sparse_triplet
Description not yet available.
void allocate(void)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
void generate_antithetical_rvs()
Description not yet available.
void deallocate()
Deallocate dmatrix memory.
void fmin(const double &f, const dvector &x, const dvector &g)
Description not yet available.
imatrix * block_diagonal_re_list
dmatrix trans(const dmatrix &m1)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
int allocated(const ivector &v)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
Vector of double precision numbers.
dvar_matrix * importance_sampling_components
imatrix * block_diagonal_fe_list
double fcomp1(dvector x, dvector d, int samplesize, int n, dvector &g, dmatrix &M)
Description not yet available.
void fill_seqadd(double, double)
Fills dvector elements with values starting from base and incremented by offset.
static int sparse_hessian_flag
static int num_inactive_vars
hs_symbolic * sparse_symbolic2
void fill_randn(long int &n)
Fill matrix with random numbers.
imatrix * compressed_triplet_information
void initialize(void)
Description not yet available.
d3_array * block_diagonal_Dux
dvector row(const dmatrix &matrix, int i)
Returns a copied row for matrix at i.
void check_hessian_type(const dvector &_x, function_minimizer *)
Description not yet available.
d3_array * block_diagonal_ch
double norm(const d3_array &a)
Return computed norm value of a.
Description not yet available.
banded_symmetric_dmatrix * bHess
ivector * sparse_iterator
void deallocate(void)
If no other copies exist, free df1b2variable::ptr.
void initialize(void)
Description not yet available.
void check_for_need_to_reallocate(int ip)
Does Nothing.
int num_importance_samples
dvar3_array * block_diagonal_vch
static laplace_approximation_calculator * lapprox
Description not yet available.
dmatrix sort(const dmatrix &m, int column, int NSTACK)
Description not yet available.
prnstream & endl(prnstream &)
Description not yet available.
Array of integers(int) with indexes from index_min to indexmax.
d3_array sqrt(const d3_array &arr3)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
static unsigned int num_active_parameters
void initialize(void)
Description not yet available.
Description not yet available.
d3_array exp(const d3_array &arr3)
Returns d3_array results with computed exp from elements in arr3.
Description not yet available.
void pre_user_function(void)
Description not yet available.
void save_number_of_local_effects(int num_separable_calls, ivector **num_local_re_array, ivector **num_local_fixed_array, int num_local_re, int num_fixed_effects)
Description not yet available.
i3_array * triplet_information
void initialize(void)
Initialze all elements of dvector to zero.
Description not yet available.
double norm2(const d3_array &a)
Return sum of squared elements in a.
d3_array * block_diagonal_vhessianadjoint
void allocate_block_diagonal_stuff(void)
Description not yet available.
ivector * num_local_re_array
Description not yet available.
void initialize(void)
Description not yet available.
dvar3_array * block_diagonal_vhessian
Description not yet available.
ivector * num_local_fixed_array
imatrix check_sparse_matrix_structure(void)
Description not yet available.
Description not yet available.
Class definition of matrix with derivitive information .
void make_sparse_triplet(void)
Description not yet available.
static int set_index(void)
void do_separable_stuff_hessian_type_information(void)
Description not yet available.
banded_symmetric_dmatrix * bHessadjoint
d3_array * block_diagonal_hessian
Description not yet available.
Description not yet available.
virtual void user_function()
void initialize(int sl, int sh, int nrl, const ivector &nrh, int ncl, const ivector &nch)
void safe_allocate(int ncl, int ncu)
Description not yet available.
Description not yet available.
Description not yet available.
static unsigned int num_vars
imatrix sub(int, int)
Description not yet available.
void initialize(void)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
static int get_num_quadratic_prior(void)
void reset(void)
Description not yet available.
double square(const double value)
Return square of value; constant object.
d3_array log(const d3_array &arr3)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
int bandwidth(void) const
static int in_qp_calculations