42 const int MAXCHARS=1000;
43 const char *delim=
" ,#:=";
45 ifstream infile(filename);
46 char readin[MAXCHARS];
49 infile.getline(readin,MAXCHARS);
51 pch = strtok(readin,delim);
55 if(strcmp(pch,(
char*)varName)== 0) {cnt++;
break;}
56 pch = strtok(NULL,delim);
77 if (repeat<=0) {cerr<<
"Can not found that variable name in this file"<<
endl; exit(1);}
78 const int MAXCHARS=1000;
79 const char *delim=
" ,#:=";
81 ifstream infile(filename);
82 dmatrix results(1,repeat,1,numVals);
83 char readin[MAXCHARS];
89 infile.getline(readin,MAXCHARS);
91 pch = strtok(readin,delim);
97 results(lines,cnt)=atof(pch);
99 if(cnt==numVals) start=0;
101 if(strcmp(pch,(
char*)varName)== 0) {
105 if(lines>repeat)
break;
108 pch = strtok(NULL,delim);
139 for(
int j=i+1;j<=all.
size();j++)
148 int tot=int(
sum(lookup));
173 int totN=source.
size();
182 for(
int i=2;i<=nSample;i++){
184 while(lookup(out(i))==0){
190 for(
int i=1;i<=nSample;i++)
215 out(idx++)=input(i,j);
220 out(idx++)=input(j,i);
239 out(idx++)=input(i,j);
244 out(idx++)=input(j,i);
263 out(idx++)=input(i,j);
268 out(idx++)=input(j,i);
288 if(nrow*ncol != input.
size()){
289 cerr<<
"In vector2matrix(): Defined matrix dimension not fit the input vector size"<<
endl;
295 for(
int i=1;i<=nrow;i++)
296 for(
int j=1;j<=ncol;j++)
297 out(i,j)=input(idx++);
300 for(
int i=1;i<=ncol;i++)
301 for(
int j=1;j<=nrow;j++)
302 out(j,i)=input(idx++);
319 if(nrow*ncol != input.
size()){
320 cerr<<
"In vector2matrix(): Defined matrix dimension not fit the input vector size"<<
endl;
326 for(
int i=1;i<=nrow;i++)
327 for(
int j=1;j<=ncol;j++)
328 out(i,j)=input(idx++);
331 for(
int i=1;i<=ncol;i++)
332 for(
int j=1;j<=nrow;j++)
333 out(j,i)=input(idx++);
350 if(nrow*ncol != input.
size()){
351 cerr<<
"In vector2matrix(): Defined matrix dimension not fit the input vector size"<<
endl;
357 for(
int i=1;i<=nrow;i++)
358 for(
int j=1;j<=ncol;j++)
359 out(i,j)=input(idx++);
362 for(
int i=1;i<=ncol;i++)
363 for(
int j=1;j<=nrow;j++)
364 out(j,i)=input(idx++);
385 const double base = 10;
387 bool bRet = (((nVal2 -
pow(base,-nPrecision)) < nVal1) && (nVal1 < (nVal2 +
pow(base,-nPrecision))));
405 return low+
randu(rng)*(upper-low);
420 return mu +
randn(rng)*sigma;
449 double v0, v1, v2, fract, em, qm, tmp, gam_n1;
457 for( i = 1;i<=int(alpha);i++)
460 gam_n1 = -1. *
log(tmp);
463 fract = alpha - int(alpha) +
EPS;
471 em =
pow(v1 / (v0 + EPS), 1. / fract);
472 qm = v2 *
pow(em, fract - 1.);
474 em = 1. -
log((v1 - v0) / (1. - v0 + EPS));
475 qm = v2 *
mfexp(-em);
477 if (qm <= (
pow(em, fract - 1.) *
mfexp(-em)))
break;
480 return (em + gam_n1);
524 int ncat=shape.
size();
531 gam[i]=
rgamma(shape[i],rng);
537 results[i] = gam[i]/tot;
double rgamma(double alpha, random_number_generator &rng)
generate random gamma number, pseudo code see http://en.wikipedia.org/wiki/Gamma_distribution ...
dvector unique(const dvector &in)
find the unique values from input vector and only return the unique (by remove the duplicate) values ...
double runif(double low, double upper, random_number_generator &rng)
generate one random uniform from (low,upper)
dmatrix findValFromFile(adstring filename, adstring varName, int numVals)
find the number of values(numVals) for one specific variable(varName) from an admb output file ...
Vector of double precision numbers.
int indexmin() const
Get minimum valid index.
double sum(const d3_array &darray)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
Description not yet available.
unsigned int size() const
ivector sample(const dvector &source, int nSample, int withReplace, const random_number_generator &rng)
generate a random sample index(size is nSample) based on the input samples(source) with or without re...
d3_array mfexp(const d3_array &m)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
double randu(const random_number_generator &rng)
Uniform random number generator.
Description not yet available.
dmatrix sort(const dmatrix &m, int column, int NSTACK)
Description not yet available.
prnstream & endl(prnstream &)
Array of integers(int) with indexes from index_min to indexmax.
double rbeta(double alpha, double beta, random_number_generator &rng)
generate random beta(alpha, beta) number,
double rnorm(double mu, double sigma, random_number_generator &rng)
generate one random normal number N(mu,sigma)
int indexmax() const
Get maximum valid index.
double rlnorm(double mu, double sigma, random_number_generator &rng)
generate one random lognormal number LN(mu,sigma)
dvariable beta(const prevariable &a, const prevariable &b)
Beta density function.
Description not yet available.
bool doubleEqual(double nVal1, double nVal2, int nPrecision)
determine if two double values are equal within some precision
unsigned int size() const
Get number of elements in array.
Description not yet available.
dvector matrix2vector(const dmatrix &input, int byrow=1)
convert the matrix as a vector eithter by row=1(default) or by column=0,
double randn(const random_number_generator &rng)
Normal number generator.
Class definition of matrix with derivitive information .
unsigned int size_count(const dvector &x)
Returns total size of elements in vector x.
int numRows4VarFromFile(adstring filename, adstring varName)
get how many rows for one specific variable(varName) in admb output file(filename) ...
dmatrix vector2matrix(dvector &input, int nrow, int ncol, int byrow=1)
convert the Vector as a Matrix eithter by row=1(default) or by column=0,
d3_array log(const d3_array &arr3)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
d3_array pow(const d3_array &m, int e)
Description not yet available.
double rgamma(double alpha, random_number_generator &rng)
Copyright (c) 2016 ADMB Foundation.
dvector rdirichlet(const dvector &shape, random_number_generator &rng)
generate random dirichlet number