22 GAUSS_varcovariance_matrix = &((
dmatrix&)(m) );
27 GAUSS_varcovariance_matrix = &((
dmatrix&)(m) );
32 GAUSS_varcovariance_matrix = &((
dmatrix&)(m) );
37 GAUSS_varcovariance_matrix = &((
dmatrix&)(m) );
42 const std::chrono::time_point<std::chrono::system_clock>& from,
43 const std::chrono::time_point<std::chrono::system_clock>& to)
52 auto elapsed = to - from;
53 auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(elapsed);
54 auto count = ms.count();
56 if (count >= 86400000)
58 ss << (count / 86400000) <<
" d ";
63 ss << (count / 3600000) <<
" h ";
68 ss << (count / 60000) <<
" m ";
71 ss << setprecision(2) << (static_cast<double>(count) * 0.001) <<
" s";
91 return std::move(ss.str());
95 const std::chrono::time_point<std::chrono::system_clock>& from,
96 const std::chrono::time_point<std::chrono::system_clock>& to)
103 std::chrono::time_point<std::chrono::system_clock> from_start;
106 from_start = std::chrono::system_clock::now();
107 cout <<
"Starting standard error calculations... " ;
124 size_t max_name_length = 0;
144 int start_stdlabels=ii;
157 int end_stdlabels=ii-1;
169 cerr <<
"Incorrect number of independent variables in file"
170 " model.cov" <<
endl;
176 cerr <<
"error reading covariance matrix from model.cov" <<
endl;
189 ofstream ofs(
"admodel.tmp");
191 #if defined(__GNU__) || defined(DOS386) || defined(__GNUDOS__)
197 for (
int i=1;i<=nvar;i++)
199 for (
int j=1;j<=i;j++)
201 tmp(j)=S(i,j)*scale(i)*scale(j);
202 ofs << tmp(j) <<
" ";
213 int tmp_nvar = 0, tmp_ndvar = 0;
214 cif >> tmp_nvar >> tmp_ndvar;
217 cerr <<
" tmp_nvar != nvar1 in file " << tmpstring
226 for (
int i=1;i<=ndvar;i++)
228 for (
int j=1;j<=nvar;j++)
230 tmpsub(j)=(tv(i)*S(j))*scale(j);
232 ofs << tmpsub <<
" ";
234 for (
int j=1;j<=i;j++)
236 tmp(nvar+j)=tmpsub*tv(j);
237 ofs << tmp(nvar+j) <<
" ";
239 diag(i+nvar)=tmp(i+nvar);
241 if (diag(i + nvar) <= 0.0)
244 output_stream <<
"Estimated covariance matrix may not be positive definite.\n"
251 cout <<
"\n Warning: Non-positive variance of sdreport variables: ";
261 if (bad_vars) cout <<
endl;
272 int tmp_nvar = 0, tmp_ndvar = 0;
273 cif >> tmp_nvar >> tmp_ndvar;
276 cerr <<
" tmp_nvar != nvar1 in file " << tmpstring
283 get_bigS(ndvar,nvar1,nvar,S,BS,scale);
290 cerr <<
"error opening file " << tmpstring <<
endl;
297 cerr <<
"error writing to file " << tmpstring <<
endl;
303 double* pscalei = scale.
get_v() + 1;
304 double* ptmpi = tmp.
get_v() + 1;
305 double* pdiagi = diag.
get_v() + 1;
306 for (
int i=1;i<=nvar1;i++)
308 double* pBSij = pBSi->
get_v() + 1;
309 double* ptmpj = tmp.
get_v() + 1;
310 double* pscalej = scale.
get_v() + 1;
311 for (
int j=1;j<=i;j++)
313 *ptmpj = *pBSij * *pscalei * *pscalej;
314 ofs << *ptmpj <<
" ";
333 for (
int i=1;i<=ndvar;i++)
335 for (
int j=1;j<=nvar1;j++)
337 tmpsub(j)=(tv(i)*BS(j))*scale(j);
339 ofs << tmpsub <<
" ";
341 for (
int j=1;j<=i;j++)
343 tmp(nvar1+j)=tmpsub*tv(j);
344 ofs << tmp(nvar1+j) <<
" ";
346 diag(i+nvar1)=tmp(i+nvar1);
348 if (diag(i+nvar1)<=0.0)
350 if (
norm(tv(i))>1.e-100)
352 cerr <<
"Estimated covariance matrix may not"
353 " be positive definite" <<
endl;
366 for (
int i=1;i<=nvar;i++)
368 for (
int j=1;j<=i;j++)
370 tmp(j)=S(i,j)*scale(i)*scale(j);
371 ofs << tmp(j) <<
" ";
381 int tmp_nvar,tmp_ndvar;
382 cif >> tmp_nvar >> tmp_ndvar;
384 for (
int i=1;i<=ndvar;i++)
387 for (
int j=1;j<=nvar;j++)
389 tmpsub(j)=(tv*S(j))*scale(j);
391 ofs << tmpsub <<
" ";
393 cif.seekg(0,ios::beg);
394 cif >> tmp_nvar >> tmp_ndvar;
395 for (
int j=1;j<=i;j++)
398 tmp(nvar+j)=tmpsub*v;
399 ofs << tmp(nvar+j) <<
" ";
401 diag(i+nvar)=tmp(i+nvar);
403 if (diag(i+nvar)<=0.0)
405 cerr <<
"Estimated covariance matrix may not be positive definite"
424 dvector param_values(1,nvar1+ndvar);
428 for (
int i=1;i<=nvar1;i++)
432 cerr <<
"Estimated covariance matrix may not be positive definite"
438 diag(i)=
sqrt(diag(i));
441 for (
int i=nvar1+1;i<=nvar1+ndvar;i++)
445 cerr <<
"Estimated covariance matrix may not be positive definite"
449 else if (diag(i)==0.0)
455 diag(i)=
sqrt(diag(i));
460 dvector dd=diag(nvar1+1,nvar1+ndvar);
468 ofs <<
" The logarithm of the determinant of the hessian = "
474 size_t inmax = max_name_length > 5 ? max_name_length - 5 : 0;
475 for (
size_t in = 1;in <= inmax; in++)
480 ofs <<
" value std.dev ";
481 ofsd <<
" value std.dev";
482 for (
int i=1;i<=nvar+ndvar;i++)
484 ofs <<
" " << setw(4) << i <<
" ";
489 if (GAUSS_varcovariance_matrix) (*GAUSS_varcovariance_matrix).initialize();
491 double* pdiagi = diag.
get_v() + 1;
492 for (
int i=1;i<=nvar1+ndvar;i++)
494 double* ptmpj = tmp.
get_v() + 1;
495 for (
int j=1;j<=i;j++)
501 ptmpj = tmp.
get_v() + 1;
502 double* pdiagj = diag.
get_v() + 1;
503 for (
int j=1;j<=i;j++)
505 if (*pdiagi == 0.0 || *pdiagj == 0.0)
513 *ptmpj /= (*pdiagi * *pdiagj);
523 ofs <<
" " << setw(4) << i <<
" ";
524 ofsd <<
" " << setw(4) << i <<
" ";
526 ofsd << param_labels[lc];
528 if (start_stdlabels <= lc && end_stdlabels >= lc)
539 inmax = max_name_length + 1 > param_labels[lc].size()
540 ? max_name_length + 1 - param_labels[lc].size() : 0;
541 for (
size_t in = 1; in <= inmax; in++)
551 ofs <<
setscientific() << setw(11) << setprecision(4) << param_values(i)
553 ofs <<
setscientific() << setw(10) << setprecision(4) << *pdiagi <<
" ";
555 if (GAUSS_varcovariance_matrix)
557 if (GAUSS_varcovariance_matrix->
indexmax()>=i)
558 (*GAUSS_varcovariance_matrix) (i,1)= *pdiagi;
561 ofsd <<
setscientific() << setw(11) << setprecision(4) << param_values(i)
563 ofsd <<
setscientific() << setw(10) << setprecision(4) << *pdiagi;
564 ptmpj = tmp.
get_v() + 1;
565 for (
int j=1;j<=i;j++)
567 ofs <<
" " <<
setfixed() << setprecision(4) << setw(7) << *ptmpj;
568 if (GAUSS_varcovariance_matrix)
570 if (GAUSS_varcovariance_matrix->
indexmax()>=i &&
571 (*GAUSS_varcovariance_matrix)(i).indexmax()>j)
573 (*GAUSS_varcovariance_matrix) (i,j+1) = *ptmpj;
584 #if defined(_MSC_VER)
585 if (system(
"del admodel.tmp") == -1)
587 if (unlink(
"admodel.tmp") == -1)
590 char msg[40] = {
"Error trying to delete temporary file "};
591 cerr << msg <<
"admodel.tmp" <<
endl;
static likeprof_params * likeprofptr[500]
static void set_active_random_effects(void)
int withinbound(int lb, int n, int ub)
dmatrix * GAUSS_varcovariance_matrix
static int num_active_calc(void)
dvector eigenvalues(const banded_symmetric_dmatrix &_SS)
Description not yet available.
Vector of double precision numbers.
double sum(const d3_array &darray)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
void print_elapsed_time(const std::chrono::time_point< std::chrono::system_clock > &from, const std::chrono::time_point< std::chrono::system_clock > &to)
void set_gauss_covariance_matrix(const dll_data_matrix &m)
virtual double & get_sigma(void)=0
void set_covariance_matrix(const dll_data_matrix &m)
static void restore_start_phase(void)
static adstring adprogram_name
static int num_stddev_calc(void)
double norm(const d3_array &a)
Return computed norm value of a.
std::string get_elapsed_time(const std::chrono::time_point< std::chrono::system_clock > &from, const std::chrono::time_point< std::chrono::system_clock > &to)
ivector sgn(const dvector &v)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
virtual unsigned int size_count() const =0
prescientific setscientific(void)
Description not yet available.
void allocate(int min, int max)
Allocate vector of adstring with range [min, max].
virtual const char * label()=0
dmatrix sort(const dmatrix &m, int column, int NSTACK)
Description not yet available.
prnstream & endl(prnstream &)
d3_array sqrt(const d3_array &arr3)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
Description not yet available.
Description not yet available.
static void xinit(const dvector &x)
adstring_array param_labels
void get_bigS(int ndvar, int nvar1, int nvar, dmatrix &S, dmatrix &BS, dvector &scale)
Description not yet available.
Description not yet available.
dvector & shift(int min)
Shift valid range of subscripts.
Description not yet available.
static void copy_all_values(const dvector &x, const int &ii)
static int num_initial_params
double ln_det(const dmatrix &m1, int &sgn)
Compute log determinant of a constant matrix.
std::ostream & get_output_stream()
static stddev_params * stddevptr[150]
unsigned int size_count(const dvector &x)
Returns total size of elements in vector x.
Description not yet available.
Description not yet available.
static void get_all_sd_values(const dvector &x, const int &ii)
static void copy_all_values(const dvector &x, const int &ii)
static int stddev_scale(const dvector &d, const dvector &x)
prefixed setfixed(void)
Description not yet available.
void initialize(void)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
static unsigned int wd_flag
void allocate(const ad_integer &ncl, const index_type &ncu)
Allocate vector of integers with dimension [_ncl to _nch].
d3_array log(const d3_array &arr3)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
static adlist_ptr varsptr
static int num_stddev_params
static int num_likeprof_params
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.