ADMB Documentation  11.5.3197
 All Classes Files Functions Variables Typedefs Friends Defines
Files | Functions
Functions created at the Quantitative Fisheries Center(QFC), Michigan State University.
User-Contributed Libraries.

Files

file  qfc_est.cpp
 

negative log likelihood functions with other functions useful for model estimation


file  qfc_sim.cpp
 

functions useful for simulation model in admb


Functions

dvar_vector boundp (const dvar_vector &x, const double fmin, const double fmax, const dvariable &fpen)
 overloading bounded functions for vector, ADMB has builtin boundp, but not for vector type

bool doubleEqual (double nVal1, double nVal2, int nPrecision)
 determine if two double values are equal within some precision
dmatrix findValFromFile (adstring filename, adstring varName, int numVals)
 find the number of values(numVals) for one specific variable(varName) from an admb output file
dvar_vector invLogitProp (const dvar_vector &p)
 reverse function for LogitProp
df1b2vector log_comb (const df1b2vector &n, const df1b2vector &x)
 overloading function for log_comb(n choose x) for randome effect, used in nllBinomial below, ADMB built in function log_comb() not for vector type in RE
dvar_vector logitProp (const dvar_vector &a)
 constrain probability vector as 1 and I forgot who create this first, may give credit to Punt., let logit(p)=log(p/(1-p))=a, so p=exp(a)/(1+exp(a)) ~[0,1]
dvector matrix2vector (const dmatrix &input, int byrow=1)
 convert the matrix as a vector eithter by row=1(default) or by column=0,
dvar_vector matrix2vector (const dvar_matrix &input, int byrow=1)
 convert the matrix as a vector eithter by row=1(default) or by column=0, overloading function
df1b2vector matrix2vector (const df1b2matrix &input, int byrow=1)
 convert the matrix as a vector eithter by row=1(default) or by column=0, overloading function
dvariable mf_upper_bound2 (const dvariable &x, const double fmax, dvariable &fpen)
 constrain parameter with upper threshold, if return bigger than it, then with penalty ADMB have built in function mf_upper_bound(), which have more constrain on the values higher than the bounds with bigger penalty than this version
double nllBeta (const double x, const double a, const double b)
 nll for beta for one sample $ -\ln(\Gamma(a+b)) +\ln(\Gamma(a)) + \ln(\Gamma(b))-(a-1)\ln(x)-(b-1)\ln(1-x) $
df1b2variable nllBeta (const df1b2variable &x, const double a, const double b)
 nll for beta for one sample for random effect $ -\ln(\Gamma(a+b)) +\ln(\Gamma(a)) + \ln(\Gamma(b))-(a-1)\ln(x)-(b-1)\ln(1-x) $
dvariable nllBeta (const dvar_vector &x, const double a, const double b)
 nll for beta for many samples $ -n\ln(\Gamma(a+b)) +n\ln(\Gamma(a)) + n\ln(\Gamma(b))-(a-1)\sum(\ln(x)) -(b-1)\sum(\ln(1-x)) $
df1b2variable nllBeta (const df1b2vector &x, const double a, const double b)
 nll for beta for many samples for random effect $ -n\ln(\Gamma(a+b)) +n\ln(\Gamma(a)) + n\ln(\Gamma(b))-(a-1)\sum(\ln(x)) -(b-1)\sum(\ln(1-x)) $
double nllBinomial (const double x, const double n, const double p)
 nll for binomial for one sample $ \ln(x!) + \ln((n-x)!) -\ln(n!) - x \ln(p) - (n-x) \ln(1-p) $
df1b2variable nllBinomial (const df1b2variable &x, const double n, const double p)
 nll for binomial for one sample for random effect $ \ln(x!) + \ln((n-x)!) -\ln(n!) - x \ln(p) - (n-x) \ln(1-p) $
dvariable nllBinomial (const dvar_vector &x, const dvector &n, const double p)
 nll for binomial for many samples $ -\sum\ln{{n_{i}}\choose{x_{i}}}- \sum(x_{i})\ln(p)- \sum(n_{i}-x_{i})\ln(1-p) $
df1b2variable nllBinomial (const dvector &x, const df1b2vector &n, const df1b2variable &p)
 nll for binomial for many samples for random effect $ -\sum\ln{{n_{i}}\choose{x_{i}}}- \sum(x_{i})\ln(p)- \sum(n_{i}-x_{i})\ln(1-p) $
double nllDirichlet (const dvector &p, const dvector &shape)
 nll for dirichlet for one sample $ -\ln\Gamma(\sum_{i}(\alpha_{i})) -\sum_{i}(\ln(\Gamma(\alpha_{i}))) +\sum_{i}((\alpha_{i}-1)\ln(p_{i})) $
df1b2variable nllDirichlet (const df1b2vector &p, const dvector &shape)
 nll for dirichlet for one sample for random effect $ -\ln\Gamma(\sum_{i}(\alpha_{i})) -\sum_{i}(\ln(\Gamma(\alpha_{i}))) +\sum_{i}((\alpha_{i}-1)\ln(p_{i})) $
double nllGamma (const double &x, const double a, const double b)
 nll for gamma for one sample Gamma(a,b) similar to log_gamma_density(r,mu) in admb, in which a=r, b=mu $ -a \ln(b) + \ln(\Gamma(a)) - (a-1)\ln(x)+ bx $
df1b2variable nllGamma (const df1b2variable &x, const double a, const double b)
 nll for gamma for one sample for random effect Gamma(a,b) similar to log_gamma_density(r,mu) in admb, in which a=r, b=mu $ -a \ln(b) + \ln(\Gamma(a)) - (a-1)\ln(x)+ bx $
double nllGamma (const dvector &x, const double a, const double b)
 nll for gamma for many samples $ -na\ln(b) + n\ln(\Gamma(a)) - (a-1)\sum(\ln(x))+ b\sum(x) $
df1b2variable nllGamma (const df1b2vector &x, const double a, const double b)
 nll for gamma for many samples for random effect $ -na\ln(b) + n\ln(\Gamma(a)) - (a-1)\sum(\ln(x))+ b\sum(x) $
double nllInverseGamma (const double x, const double a, const double b)
 nll for inverse gamma for one sample $ -a \ln(b) + \ln(\Gamma(a)) + (a+1)\ln(x)+ b/x $
df1b2variable nllInverseGamma (const df1b2variable &x, const double a, const double b)
 nll for inverse gamma for one sample for random effect $ -a \ln(b) + \ln(\Gamma(a)) + (a+1)\ln(x)+ b/x $
dvariable nllInverseGamma (const dvar_vector &x, const double a, const double b)
 nll for inverse gamma for many samples $ -na \ln(b) + n\ln(\Gamma(a)) + (a+1)\sum(\ln(x))+ b/\sum(x) $
df1b2variable nllInverseGamma (const dvector &x, const df1b2variable &a, const df1b2variable &b)
 nll for inverse gamma for many samples for random effect $ -na \ln(b) + n\ln(\Gamma(a)) + (a+1)\sum(\ln(x))+ b/\sum(x) $
double nllLognormal (const double x, const double mu, const double sigma)
 nll for lognormal for one sample $ 0.5\ln(2 \pi) + \ln(x) +\ln(\sigma) + 0.5(\frac{\ln(x)-\mu}{\sigma})^2 $
df1b2variable nllLognormal (const df1b2variable &x, const double mu, const double sigma)
 nll for lognormal for one sample for random effect $ 0.5\ln(2 \pi) + \ln(x) +\ln(\sigma) + 0.5(\frac{\ln(x)-\mu}{\sigma})^2 $
dvariable nllLognormal (const dvar_vector &x, const double mu, const double sigma)
 nll for lognormal for many samples $ 0.5n\ln(2 \pi) + \sum\ln(x) +n\ln(\sigma) + 0.5\sum(\frac{\ln(x)-\mu}{\sigma})^2 $
df1b2variable nllLognormal (const df1b2vector &x, const double mu, const double sigma)
 nll for lognormal for many samples for random effect $ 0.5n\ln(2 \pi) + \sum\ln(x) +n\ln(\sigma) + 0.5\sum(\frac{\ln(x)-\mu}{\sigma})^2 $
dvariable nllLognormal (const dvar_vector &x, const dvector &mu, const double sigma)
 nll for lognormal for many samples, each has its mean $ 0.5n\ln(2 \pi) + \sum\ln(x_{i}) +n\ln(\sigma) + 0.5\sum(\frac{\ln(x_{i})-\mu_{i}}{\sigma})^2 $
df1b2variable nllLognormal (const df1b2vector &x, const dvector &mu, const double sigma)
 nll for lognormal for many samples, each has its mean, for random effect $ 0.5n\ln(2 \pi) + \sum\ln(x_{i}) +n\ln(\sigma) + 0.5\sum(\frac{\ln(x_{i})-\mu_{i}}{\sigma})^2 $
dvariable nllLognormal2 (const double x, const dvariable &mu, const dvariable &tau)
 nll for lognormal(mu,tau) for one sample $ 0.5\ln(2 \pi) + \ln(x) -0.5\ln(\tau) + 0.5\tau(\ln(x)-\mu)^2 $
df1b2variable nllLognormal2 (const df1b2variable x, const double mu, const double tau)
 nll for lognormal(mu,tau) for one sample for random effect $ 0.5\ln(2 \pi) + \ln(x) -0.5\ln(\tau) + 0.5\tau(\ln(x)-\mu)^2 $
dvariable nllLognormal2 (const dvar_vector &x, const double mu, const double tau)
 nll for lognormal(mu,tau) for many samples $ 0.5n\ln(2 \pi) + \sum\ln(x) -0.5n\ln(\tau) + 0.5\tau\sum(\ln(x)-\mu)^2 $
df1b2variable nllLognormal2 (const dvector &x, const df1b2variable &mu, const df1b2variable &tau)
 nll for lognormal(mu,tau) for many samples for random effect $ 0.5n\ln(2 \pi) + \sum\ln(x) -0.5n\ln(\tau) + 0.5\tau\sum(\ln(x)-\mu)^2 $
dvariable nllLognormal2 (const dvar_vector &x, const dvector &mu, const double tau)
 nll for lognormal(mu,tau) for many samples, each has its mean $ 0.5n\ln(2 \pi) + \sum\ln(x_{i}) -0.5n\ln(\tau) + 0.5\tau\sum(\ln(x_{i})-\mu_{i})^2 $
df1b2variable nllLognormal2 (const df1b2vector &x, const dvector &mu, const double tau)
 nll for lognormal(mu,tau) for many samples, each has its mean, overload for random effect, $ 0.5n\ln(2 \pi) + \sum\ln(x_{i}) -0.5n\ln(\tau) + 0.5\tau\sum(\ln(x_{i})-\mu_{i})^2 $
double nllMultiNomial (const dvector &obsN, const dvector &p)
 nll for Multinomial for one sample $ -\sum_{i}(n_{i}\ln(p_{i})) -\ln((\sum_{i}n_{i})!) +\sum_{i}(\ln(n_{i}!)) $
df1b2variable nllMultiNomial (const df1b2vector &obsN, const dvector &p)
 nll for Multinomial for one sample for random effect $ -\sum_{i}(n_{i}\ln(p_{i})) -\ln((\sum_{i}n_{i})!) +\sum_{i}(\ln(n_{i}!)) $
double nllNegativeBinomial (const double obs, const double m, const double s)
 nll for negative binomial N(m,s) for one sample, admb built in log_negbinomial_density(obs,mu,tau), in which tau=1.
df1b2variable nllNegativeBinomial (const df1b2variable &obs, const double m, const double s)
 nll for negative binomial N(m,s) for one sample,overload for random effect, admb built in log_negbinomial_density(obs,mu,tau), in which tau=1.
dvariable nllNegativeBinomial (const dvector &obs, const dvariable &m, const dvariable &s)
 nll for negative binomial N(m,s) for many samples, admb built in log_negbinomial_density(obs,mu,tau), in which tau=1.
df1b2variable nllNegativeBinomial (const df1b2vector &obs, const double m, const double s)
 nll for negative binomial N(m,s) for many samples, overload for random effect, admb built in log_negbinomial_density(obs,mu,tau), in which tau=1.
double nllNegativeBinomial2 (const double obs, const double m, const double tau)
 nll for negative binomial N(mu,tau) for one sample, admb built in log_negbinomial_density(obs,mu,tau), in which tau=1.
df1b2variable nllNegativeBinomial2 (const df1b2variable &obs, const double m, const double tau)
 nll for negative binomial N(mu,tau) for one sample,overload for random effect admb built in log_negbinomial_density(obs,mu,tau), in which tau=1.
double nllNormal (const double x, const double mu, const double sigma)
 nll for normal for one sample $ 0.5\ln(2 \pi) + \ln(\sigma) + 0.5(\frac{x-\mu}{\sigma})^2 $
df1b2variable nllNormal (const df1b2variable &x, const double mu, const double sigma)
 nll for normal for one sample for random effect $ 0.5\ln(2 \pi) + \ln(\sigma) + 0.5(\frac{x-\mu}{\sigma})^2 $
double nllNormal (const dvector &x, const double mu, const double sigma)
 nll for normal for many samples, but mu is for common $ 0.5n\ln(2 \pi) + n\ln(\sigma) + 0.5\sum(\frac{x-\mu}{\sigma})^2 $
df1b2variable nllNormal (const df1b2vector &x, const double mu, const double sigma)
 nll for normal for many samples, but mu is for common, overload for random effect $ 0.5n\ln(2 \pi) + n\ln(\sigma) + 0.5\sum(\frac{x-\mu}{\sigma})^2 $
dvariable nllNormal (const dvar_vector &x, const dvector &mu, const double sigma)
 nll for normal for many samples, each has its own mean $ 0.5n\ln(2 \pi) + n\ln(\sigma) + 0.5\sum(\frac{x_{i}-\mu_{i}}{\sigma})^2 $
df1b2variable nllNormal (const df1b2vector &x, const dvector &mu, const double sigma)
 nll for normal for many samples, each has its own mean for random effect $ 0.5n\ln(2 \pi) + n\ln(\sigma) + 0.5\sum(\frac{x_{i}-\mu_{i}}{\sigma})^2 $
dvariable nllNormal2 (const dvariable &x, const double mu, const double tau)
 nll for normal(mu,tau) for one sample $ 0.5\ln(2 \pi) -0.5 \ln(\tau) + 0.5\tau(x-\mu)^2 $
df1b2variable nllNormal2 (const df1b2variable &x, const double mu, const double tau)
 nll for normal(mu,tau) for one sample for random effect $ 0.5\ln(2 \pi) -0.5 \ln(\tau) + 0.5\tau(x-\mu)^2 $
dvariable nllNormal2 (const dvar_vector &x, const double mu, const double tau)
 nll for normal(mu,tau) for many samples $ 0.5n\ln(2 \pi) -0.5n\ln(\tau) + 0.5\tau\sum(x-\mu)^2 $
df1b2variable nllNormal2 (const df1b2vector &x, const double mu, const double tau)
 nll for normal(mu,tau) for many samples for random effect $ 0.5n\ln(2 \pi) -0.5n\ln(\tau) + 0.5\tau\sum(x-\mu)^2 $
dvariable nllNormal2 (const dvar_vector &x, const dvector &mu, const double tau)
 nll for normal(mu,tau) for many samples, each has its own mean $ 0.5n\ln(2 \pi) + n\ln(\sigma) + 0.5\tau\sum(x_{i}-\mu_{i})^2 $
df1b2variable nllNormal2 (const df1b2vector &x, const dvector &mu, const double tau)
 nll for normal(mu,tau) for many samples, each has its own mean, overload for random effect, $ 0.5n\ln(2 \pi) + n\ln(\sigma) + 0.5\tau\sum(x_{i}-\mu_{i})^2 $
double nllPoisson (const double x, const double lambda)
 nll for poisson for one sample $ \lambda -x\ln(\lambda)+\ln(x!) $
df1b2variable nllPoisson (const df1b2variable &x, const double lambda)
 nll for poisson for one sample for random effect $ \lambda -x\ln(\lambda)+\ln(x!) $
dvariable nllPoisson (const dvar_vector &x, const double lambda)
 nll for poisson for many samples $ n\lambda -\sum(x)\ln(\lambda)+\sum(\ln(x!)) $
df1b2variable nllPoisson (const dvector &x, const df1b2variable &lambda)
 nll for poisson for many samples for random effect $ n\lambda -\sum(x)\ln(\lambda)+\sum(\ln(x!)) $
dvar_vector normalize_p (dvar_vector &p, dvariable fpen)
 normailize p as sum(p)=1, return p and penalty if sum(p)!=1
int numRows4VarFromFile (adstring filename, adstring varName)
 get how many rows for one specific variable(varName) in admb output file(filename)
dvar_vector posfun (dvar_vector &x, const dvector &eps, dvariable &pen)
 overloading functions for posfun for vector and matrix, not sure if admb already do this in latest version
dvar_matrix posfun (dvar_matrix &x, const dmatrix &eps, dvariable &pen)
 overloading functions for posfun for vector and matrix, not sure if admb already do this in latest version
overloading function for matrix
double rbeta (double alpha, double beta, random_number_generator &rng)
 generate random beta(alpha, beta) number,
dvector rdirichlet (const dvector &shape, random_number_generator &rng)
 generate random dirichlet number
double rgamma (double alpha, random_number_generator &rng)
 generate random gamma number, pseudo code see http://en.wikipedia.org/wiki/Gamma_distribution , Gamma(alpha, belta)=x^(alpha-1)*belta^alpha*exp(-belta*x)/gamma(alpha)
double rgamma (double alpha, double beta, random_number_generator &rng)
 generate random gamma number, mean is alpha/belta, variance is alpha/(belta^2)
double rlnorm (double mu, double sigma, random_number_generator &rng)
 generate one random lognormal number LN(mu,sigma)
double rnorm (double mu, double sigma, random_number_generator &rng)
 generate one random normal number N(mu,sigma)
double runif (double low, double upper, random_number_generator &rng)
 generate one random uniform from (low,upper)
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 replacement
dvector unique (const dvector &in)
 find the unique values from input vector and only return the unique (by remove the duplicate) values in ascending order
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,
df1b2matrix vector2matrix (df1b2vector &input, int nrow, int ncol, int byrow=1)
 convert the Vector as a Matrix eithter by row=1(default) or by column=0, overloading function
dvar_matrix vector2matrix (const dvar_vector &input, int nrow, int ncol, int byrow=1)
 convert the Vector as a Matrix eithter by row=1(default) or by column=0, overloading function

Detailed Description

Contributed by Weihai Liu


Function Documentation

dvar_vector boundp ( const dvar_vector x,
const double  fmin,
const double  fmax,
const dvariable fpen 
)

overloading bounded functions for vector, ADMB has builtin boundp, but not for vector type

Parameters:
x: being constrained input value
fmin: lower bound value
fmax: upper bound value
fpen: hold extra penalty, need add to objective function value later
Returns:
return value within the bounds (fmin,fmax) without penalty or return outbouds value with fpen

Definition at line 243 of file qfc_est.cpp.

bool doubleEqual ( double  nVal1,
double  nVal2,
int  nPrecision 
)

determine if two double values are equal within some precision

Parameters:
nVal1: double value used for comparison
nVal2: another double value used for comparison
nPrecision: the number of decimals
Returns:
return true/false for two double values compare based on some specific number of decimals

Definition at line 383 of file qfc_sim.cpp.

dmatrix findValFromFile ( adstring  filename,
adstring  varName,
int  numVals 
)

find the number of values(numVals) for one specific variable(varName) from an admb output file

Parameters:
filename: search for admb output file name
varName: variable name being searched for
numVals: number of values following that specific variable names for return
Returns:
return the found number of values for that variable name, if having unique name, then return one row matrix if having same name, return several rows matrix

Definition at line 74 of file qfc_sim.cpp.

reverse function for LogitProp

Parameters:
p: the prob. vector
Returns:
return the a, one element less than input p

Definition at line 82 of file qfc_est.cpp.

df1b2vector log_comb ( const df1b2vector n,
const df1b2vector x 
)

overloading function for log_comb(n choose x) for randome effect, used in nllBinomial below, ADMB built in function log_comb() not for vector type in RE

Parameters:
n: number of trials
x: number of selected trial
Returns:
return n choose x $ {{n}\choose{x}} $

Definition at line 271 of file qfc_est.cpp.

constrain probability vector as 1 and I forgot who create this first, may give credit to Punt., let logit(p)=log(p/(1-p))=a, so p=exp(a)/(1+exp(a)) ~[0,1]

Parameters:
a: defined as real number without bounds in parameter_section, one element less than return p
Returns:
return the prob. vector p in procedure_section

Definition at line 51 of file qfc_est.cpp.

dvector matrix2vector ( const dmatrix input,
int  byrow = 1 
)

convert the matrix as a vector eithter by row=1(default) or by column=0,

Parameters:
input: the matrix being converted, can also be ragged matrix
byrow: default as by row, use 1, anynumber other than 1 as by column
Returns:
return a vector which index starting from 1

Definition at line 208 of file qfc_sim.cpp.

dvar_vector matrix2vector ( const dvar_matrix input,
int  byrow = 1 
)

convert the matrix as a vector eithter by row=1(default) or by column=0, overloading function

Parameters:
input: the matrix being converted, can also be ragged matrix
byrow: default as by row, use 1, anynumber other than 1 as by column
Returns:
return a vector which index starting from 1

Definition at line 232 of file qfc_sim.cpp.

df1b2vector matrix2vector ( const df1b2matrix input,
int  byrow = 1 
)

convert the matrix as a vector eithter by row=1(default) or by column=0, overloading function

Parameters:
input: the matrix being converted, can also be ragged matrix
byrow: default as by row, use 1, anynumber other than 1 as by column
Returns:
return a vector which index starting from 1

Definition at line 256 of file qfc_sim.cpp.

dvariable mf_upper_bound2 ( const dvariable x,
const double  fmax,
dvariable fpen 
)

constrain parameter with upper threshold, if return bigger than it, then with penalty ADMB have built in function mf_upper_bound(), which have more constrain on the values higher than the bounds with bigger penalty than this version

Parameters:
x: mean parameter
fmax: upper threshold or maximum value, be positive
fpen: penalty
Returns:
return itself without penalty if input value <fmax , or return ajusted value which >fmax but with penalty

Definition at line 210 of file qfc_est.cpp.

double nllBeta ( const double  x,
const double  a,
const double  b 
)

nll for beta for one sample $ -\ln(\Gamma(a+b)) +\ln(\Gamma(a)) + \ln(\Gamma(b))-(a-1)\ln(x)-(b-1)\ln(1-x) $

Parameters:
x: data
a: alpha parameter,>0
b: beta parameter,>0
Returns:
return the nll for beta for one sample

Definition at line 885 of file qfc_est.cpp.

df1b2variable nllBeta ( const df1b2variable x,
const double  a,
const double  b 
)

nll for beta for one sample for random effect $ -\ln(\Gamma(a+b)) +\ln(\Gamma(a)) + \ln(\Gamma(b))-(a-1)\ln(x)-(b-1)\ln(1-x) $

Parameters:
x: data
a: alpha parameter,>0
b: beta parameter,>0
Returns:
return the nll for beta for one sample

Definition at line 940 of file qfc_est.cpp.

dvariable nllBeta ( const dvar_vector x,
const double  a,
const double  b 
)

nll for beta for many samples $ -n\ln(\Gamma(a+b)) +n\ln(\Gamma(a)) + n\ln(\Gamma(b))-(a-1)\sum(\ln(x)) -(b-1)\sum(\ln(1-x)) $

Parameters:
x: data
a: alpha parameter
b: beta parameter
Returns:
return the nll for beta for many samples

Definition at line 981 of file qfc_est.cpp.

df1b2variable nllBeta ( const df1b2vector x,
const double  a,
const double  b 
)

nll for beta for many samples for random effect $ -n\ln(\Gamma(a+b)) +n\ln(\Gamma(a)) + n\ln(\Gamma(b))-(a-1)\sum(\ln(x)) -(b-1)\sum(\ln(1-x)) $

Parameters:
x: data
a: alpha parameter
b: beta parameter
Returns:
return the nll for beta for many samples

Definition at line 1017 of file qfc_est.cpp.

double nllBinomial ( const double  x,
const double  n,
const double  p 
)

nll for binomial for one sample $ \ln(x!) + \ln((n-x)!) -\ln(n!) - x \ln(p) - (n-x) \ln(1-p) $

Parameters:
x: data
n: number of trials
p: probability
Returns:
return the nll for binomial for one samples

Definition at line 1513 of file qfc_est.cpp.

df1b2variable nllBinomial ( const df1b2variable x,
const double  n,
const double  p 
)

nll for binomial for one sample for random effect $ \ln(x!) + \ln((n-x)!) -\ln(n!) - x \ln(p) - (n-x) \ln(1-p) $

Parameters:
x: data
n: number of trials
p: probability
Returns:
return the nll for binomial for one samples

Definition at line 1552 of file qfc_est.cpp.

dvariable nllBinomial ( const dvar_vector x,
const dvector n,
const double  p 
)

nll for binomial for many samples $ -\sum\ln{{n_{i}}\choose{x_{i}}}- \sum(x_{i})\ln(p)- \sum(n_{i}-x_{i})\ln(1-p) $

Parameters:
x: data
n: number of trials
p: probability
Returns:
return the nll for binomial for many samples

Definition at line 1582 of file qfc_est.cpp.

df1b2variable nllBinomial ( const dvector x,
const df1b2vector n,
const df1b2variable p 
)

nll for binomial for many samples for random effect $ -\sum\ln{{n_{i}}\choose{x_{i}}}- \sum(x_{i})\ln(p)- \sum(n_{i}-x_{i})\ln(1-p) $

Parameters:
x: data
n: number of trials
p: probability
Returns:
return the nll for binomial for many samples

Definition at line 1615 of file qfc_est.cpp.

double nllDirichlet ( const dvector p,
const dvector shape 
)

nll for dirichlet for one sample $ -\ln\Gamma(\sum_{i}(\alpha_{i})) -\sum_{i}(\ln(\Gamma(\alpha_{i}))) +\sum_{i}((\alpha_{i}-1)\ln(p_{i})) $

Parameters:
p: observation proportion, sum as 1
shape: alpha parameter, >0
Returns:
return the nll for dirichlet for one sample

Definition at line 633 of file qfc_est.cpp.

df1b2variable nllDirichlet ( const df1b2vector p,
const dvector shape 
)

nll for dirichlet for one sample for random effect $ -\ln\Gamma(\sum_{i}(\alpha_{i})) -\sum_{i}(\ln(\Gamma(\alpha_{i}))) +\sum_{i}((\alpha_{i}-1)\ln(p_{i})) $

Parameters:
p: observation proportion, sum as 1
shape: alpha parameter, >0
Returns:
return the nll for dirichlet for one sample

Definition at line 671 of file qfc_est.cpp.

double nllGamma ( const double &  x,
const double  a,
const double  b 
)

nll for gamma for one sample Gamma(a,b) similar to log_gamma_density(r,mu) in admb, in which a=r, b=mu $ -a \ln(b) + \ln(\Gamma(a)) - (a-1)\ln(x)+ bx $

Parameters:
x: data
a: alpha parameter,also call shape,>0
b: beta parameter,also call rate,>0
Returns:
return the nll for gamma for one sample

Definition at line 708 of file qfc_est.cpp.

df1b2variable nllGamma ( const df1b2variable x,
const double  a,
const double  b 
)

nll for gamma for one sample for random effect Gamma(a,b) similar to log_gamma_density(r,mu) in admb, in which a=r, b=mu $ -a \ln(b) + \ln(\Gamma(a)) - (a-1)\ln(x)+ bx $

Parameters:
x: data
a: alpha parameter,>0
b: beta parameter,>0
Returns:
return the nll for gamma for one sample

Definition at line 762 of file qfc_est.cpp.

double nllGamma ( const dvector x,
const double  a,
const double  b 
)

nll for gamma for many samples $ -na\ln(b) + n\ln(\Gamma(a)) - (a-1)\sum(\ln(x))+ b\sum(x) $

Parameters:
x: data
a: alpha parameter,>0
b: beta parameter,>0
Returns:
return the nll for gamma for many samples

Definition at line 803 of file qfc_est.cpp.

df1b2variable nllGamma ( const df1b2vector x,
const double  a,
const double  b 
)

nll for gamma for many samples for random effect $ -na\ln(b) + n\ln(\Gamma(a)) - (a-1)\sum(\ln(x))+ b\sum(x) $

Parameters:
x: data
a: alpha parameter,>0
b: beta parameter,>0
Returns:
return the nll for gamma for many samples

Definition at line 846 of file qfc_est.cpp.

double nllInverseGamma ( const double  x,
const double  a,
const double  b 
)

nll for inverse gamma for one sample $ -a \ln(b) + \ln(\Gamma(a)) + (a+1)\ln(x)+ b/x $

Parameters:
x: data
a: alpha parameter,>0
b: beta parameter,>0
Returns:
return the nll for inverse gamma for one sample

Definition at line 2274 of file qfc_est.cpp.

df1b2variable nllInverseGamma ( const df1b2variable x,
const double  a,
const double  b 
)

nll for inverse gamma for one sample for random effect $ -a \ln(b) + \ln(\Gamma(a)) + (a+1)\ln(x)+ b/x $

Parameters:
x: data
a: alpha parameter,>0
b: beta parameter,>0
Returns:
return the nll for inverse gamma for one sample

Definition at line 2313 of file qfc_est.cpp.

dvariable nllInverseGamma ( const dvar_vector x,
const double  a,
const double  b 
)

nll for inverse gamma for many samples $ -na \ln(b) + n\ln(\Gamma(a)) + (a+1)\sum(\ln(x))+ b/\sum(x) $

Parameters:
x: data
a: alpha parameter,>0
b: beta parameter,>0
Returns:
return the nll for inverse gamma for many samples

Definition at line 2355 of file qfc_est.cpp.

df1b2variable nllInverseGamma ( const dvector x,
const df1b2variable a,
const df1b2variable b 
)

nll for inverse gamma for many samples for random effect $ -na \ln(b) + n\ln(\Gamma(a)) + (a+1)\sum(\ln(x))+ b/\sum(x) $

Parameters:
x: data
a: alpha parameter,>0
b: beta parameter,>0
Returns:
return the nll for inverse gamma for many samples

Definition at line 2391 of file qfc_est.cpp.

double nllLognormal ( const double  x,
const double  mu,
const double  sigma 
)

nll for lognormal for one sample $ 0.5\ln(2 \pi) + \ln(x) +\ln(\sigma) + 0.5(\frac{\ln(x)-\mu}{\sigma})^2 $

Parameters:
x: data
mu: mean parameter
sigma: std deviation parameter
Returns:
return the nll for lognormal for one sample

Definition at line 1655 of file qfc_est.cpp.

df1b2variable nllLognormal ( const df1b2variable x,
const double  mu,
const double  sigma 
)

nll for lognormal for one sample for random effect $ 0.5\ln(2 \pi) + \ln(x) +\ln(\sigma) + 0.5(\frac{\ln(x)-\mu}{\sigma})^2 $

Parameters:
x: data
mu: mean parameter
sigma: std deviation parameter
Returns:
return the nll for lognormal for one sample

Definition at line 1710 of file qfc_est.cpp.

dvariable nllLognormal ( const dvar_vector x,
const double  mu,
const double  sigma 
)

nll for lognormal for many samples $ 0.5n\ln(2 \pi) + \sum\ln(x) +n\ln(\sigma) + 0.5\sum(\frac{\ln(x)-\mu}{\sigma})^2 $

Parameters:
x: data
mu: mean parameter
sigma: std deviation parameter
Returns:
return the nll for lognormal for many samples

Definition at line 1752 of file qfc_est.cpp.

df1b2variable nllLognormal ( const df1b2vector x,
const double  mu,
const double  sigma 
)

nll for lognormal for many samples for random effect $ 0.5n\ln(2 \pi) + \sum\ln(x) +n\ln(\sigma) + 0.5\sum(\frac{\ln(x)-\mu}{\sigma})^2 $

Parameters:
x: data
mu: mean parameter
sigma: std deviation parameter
Returns:
return the nll for lognormal for many samples

Definition at line 1788 of file qfc_est.cpp.

dvariable nllLognormal ( const dvar_vector x,
const dvector mu,
const double  sigma 
)

nll for lognormal for many samples, each has its mean $ 0.5n\ln(2 \pi) + \sum\ln(x_{i}) +n\ln(\sigma) + 0.5\sum(\frac{\ln(x_{i})-\mu_{i}}{\sigma})^2 $

Parameters:
x: data
mu: mean parameter
sigma: std deviation parameter
Returns:
return the nll for lognormal for many samples

Definition at line 1820 of file qfc_est.cpp.

df1b2variable nllLognormal ( const df1b2vector x,
const dvector mu,
const double  sigma 
)

nll for lognormal for many samples, each has its mean, for random effect $ 0.5n\ln(2 \pi) + \sum\ln(x_{i}) +n\ln(\sigma) + 0.5\sum(\frac{\ln(x_{i})-\mu_{i}}{\sigma})^2 $

Parameters:
x: data
mu: mean parameter
sigma: std deviation parameter
Returns:
return the nll for lognormal for many samples

Definition at line 1856 of file qfc_est.cpp.

dvariable nllLognormal2 ( const double  x,
const dvariable mu,
const dvariable tau 
)

nll for lognormal(mu,tau) for one sample $ 0.5\ln(2 \pi) + \ln(x) -0.5\ln(\tau) + 0.5\tau(\ln(x)-\mu)^2 $

Parameters:
x: data
mu: mean parameter
tau: precision parameter, 1/variance
Returns:
return the nll for lognormal for one sample

Definition at line 1897 of file qfc_est.cpp.

df1b2variable nllLognormal2 ( const df1b2variable  x,
const double  mu,
const double  tau 
)

nll for lognormal(mu,tau) for one sample for random effect $ 0.5\ln(2 \pi) + \ln(x) -0.5\ln(\tau) + 0.5\tau(\ln(x)-\mu)^2 $

Parameters:
x: data
mu: mean parameter
tau: precision parameter, 1/variance
Returns:
return the nll for lognormal for one sample

Definition at line 1930 of file qfc_est.cpp.

dvariable nllLognormal2 ( const dvar_vector x,
const double  mu,
const double  tau 
)

nll for lognormal(mu,tau) for many samples $ 0.5n\ln(2 \pi) + \sum\ln(x) -0.5n\ln(\tau) + 0.5\tau\sum(\ln(x)-\mu)^2 $

Parameters:
x: data
mu: mean parameter
tau: precision parameter, 1/variance
Returns:
return the nll for lognormal for many samples

Definition at line 1972 of file qfc_est.cpp.

df1b2variable nllLognormal2 ( const dvector x,
const df1b2variable mu,
const df1b2variable tau 
)

nll for lognormal(mu,tau) for many samples for random effect $ 0.5n\ln(2 \pi) + \sum\ln(x) -0.5n\ln(\tau) + 0.5\tau\sum(\ln(x)-\mu)^2 $

Parameters:
x: data
mu: mean parameter
tau: precision parameter, 1/variance
Returns:
return the nll for lognormal for many samples

Definition at line 2008 of file qfc_est.cpp.

dvariable nllLognormal2 ( const dvar_vector x,
const dvector mu,
const double  tau 
)

nll for lognormal(mu,tau) for many samples, each has its mean $ 0.5n\ln(2 \pi) + \sum\ln(x_{i}) -0.5n\ln(\tau) + 0.5\tau\sum(\ln(x_{i})-\mu_{i})^2 $

Parameters:
x: data
mu: mean parameter
tau: precision parameter, 1/variance
Returns:
return the nll for lognormal for many samples

Definition at line 2055 of file qfc_est.cpp.

df1b2variable nllLognormal2 ( const df1b2vector x,
const dvector mu,
const double  tau 
)

nll for lognormal(mu,tau) for many samples, each has its mean, overload for random effect, $ 0.5n\ln(2 \pi) + \sum\ln(x_{i}) -0.5n\ln(\tau) + 0.5\tau\sum(\ln(x_{i})-\mu_{i})^2 $

Parameters:
x: data
mu: mean parameter
tau: precision parameter, 1/variance
Returns:
return the nll for lognormal for many samples

Definition at line 2091 of file qfc_est.cpp.

double nllMultiNomial ( const dvector obsN,
const dvector p 
)

nll for Multinomial for one sample $ -\sum_{i}(n_{i}\ln(p_{i})) -\ln((\sum_{i}n_{i})!) +\sum_{i}(\ln(n_{i}!)) $

Parameters:
obsN: observation data
p: proportion vector, sum as 1
Returns:
return the nll for Multinomial for one sample

Definition at line 560 of file qfc_est.cpp.

df1b2variable nllMultiNomial ( const df1b2vector obsN,
const dvector p 
)

nll for Multinomial for one sample for random effect $ -\sum_{i}(n_{i}\ln(p_{i})) -\ln((\sum_{i}n_{i})!) +\sum_{i}(\ln(n_{i}!)) $

Parameters:
obsN: observation data
p: proportion vector, sum as 1
Returns:
return the nll for Multinomial for one sample

Definition at line 598 of file qfc_est.cpp.

double nllNegativeBinomial ( const double  obs,
const double  m,
const double  s 
)

nll for negative binomial N(m,s) for one sample, admb built in log_negbinomial_density(obs,mu,tau), in which tau=1.

+mu/s for NB(m,s), winbug use NB(p,r), in which p=s/(m+s) and r=s,

\[ -\ln(\Gamma(x+s))+ \ln(\Gamma(s))+\ln(x!)-s\ln(\frac{s}{m+s})-x\ln(\frac{m}{m+s}) \]

Parameters:
obs: observation data x
m: mean
s: scaling factor, some use r NB(p,r)
Returns:
return the nll for neg. binomial for one sample

Definition at line 315 of file qfc_est.cpp.

Referenced by nllNegativeBinomial2().

df1b2variable nllNegativeBinomial ( const df1b2variable obs,
const double  m,
const double  s 
)

nll for negative binomial N(m,s) for one sample,overload for random effect, admb built in log_negbinomial_density(obs,mu,tau), in which tau=1.

+mu/s for NB(m,s), winbug use NB(p,r), in which p=s/(m+s) and r=s,

\[ -\ln(\Gamma(x+s))+ \ln(\Gamma(s))+\ln(x!)-s\ln(\frac{s}{m+s})-x\ln(\frac{m}{m+s}) \]

Parameters:
obs: observation data x
m: mean
s: scaling factor, some use r NB(p,r)
Returns:
return the nll for neg. binomial for one sample

Definition at line 372 of file qfc_est.cpp.

dvariable nllNegativeBinomial ( const dvector obs,
const dvariable m,
const dvariable s 
)

nll for negative binomial N(m,s) for many samples, admb built in log_negbinomial_density(obs,mu,tau), in which tau=1.

+mu/s for NB(m,s), winbug use NB(p,r), in which p=s/(m+s) and r=s,

\[ -\sum(\ln(\Gamma(x+s)))+ n\ln(\Gamma(s))+\sum(\ln(x!))-ns\ln(\frac{s}{m+s})-\sum(x)\ln(\frac{m}{m+s}) \]

Parameters:
obs: observation data
m: mean
s: scaling factor
Returns:
return the nll for neg. binomial for many samples

Definition at line 417 of file qfc_est.cpp.

df1b2variable nllNegativeBinomial ( const df1b2vector obs,
const double  m,
const double  s 
)

nll for negative binomial N(m,s) for many samples, overload for random effect, admb built in log_negbinomial_density(obs,mu,tau), in which tau=1.

+mu/s for NB(m,s), winbug use NB(p,r), in which p=s/(m+s) and r=s,

\[ -\sum(\ln(\Gamma(x+s)))+ n\ln(\Gamma(s))+\sum(\ln(x!))-ns\ln(\frac{s}{m+s})-\sum(x)\ln(\frac{m}{m+s}) \]

Parameters:
obs: observation data
m: mean
s: scaling factor
Returns:
return the nll for neg. binomial for many samples

Definition at line 455 of file qfc_est.cpp.

double nllNegativeBinomial2 ( const double  obs,
const double  m,
const double  tau 
)

nll for negative binomial N(mu,tau) for one sample, admb built in log_negbinomial_density(obs,mu,tau), in which tau=1.

+mu/s for NB(m,s), winbug us NB(p,r), in which p=s/(m+s) and r=s,

Parameters:
obs: observation data
m: mean
tau: overdispersion parameter,
Returns:
return the nll for neg. binomial for one sample

Definition at line 495 of file qfc_est.cpp.

df1b2variable nllNegativeBinomial2 ( const df1b2variable obs,
const double  m,
const double  tau 
)

nll for negative binomial N(mu,tau) for one sample,overload for random effect admb built in log_negbinomial_density(obs,mu,tau), in which tau=1.

+mu/s for NB(m,s), winbug us NB(p,r), in which p=s/(m+s) and r=s,

Parameters:
obs: observation data
m: mean
tau: overdispersion parameter,
Returns:
return the nll for neg. binomial for one sample

Definition at line 529 of file qfc_est.cpp.

double nllNormal ( const double  x,
const double  mu,
const double  sigma 
)

nll for normal for one sample $ 0.5\ln(2 \pi) + \ln(\sigma) + 0.5(\frac{x-\mu}{\sigma})^2 $

Parameters:
x: data
mu: mean parameter
sigma: std deviation parameter
Returns:
return the nll for normal for one sample

Definition at line 1056 of file qfc_est.cpp.

df1b2variable nllNormal ( const df1b2variable x,
const double  mu,
const double  sigma 
)

nll for normal for one sample for random effect $ 0.5\ln(2 \pi) + \ln(\sigma) + 0.5(\frac{x-\mu}{\sigma})^2 $

Parameters:
x: data
mu: mean parameter
sigma: std deviation parameter
Returns:
return the nll for normal for one sample

Definition at line 1111 of file qfc_est.cpp.

double nllNormal ( const dvector x,
const double  mu,
const double  sigma 
)

nll for normal for many samples, but mu is for common $ 0.5n\ln(2 \pi) + n\ln(\sigma) + 0.5\sum(\frac{x-\mu}{\sigma})^2 $

Parameters:
x: data
mu: mean parameter
sigma: std deviation parameter
Returns:
return the nll for normal for many samples sharing one mu

Definition at line 1152 of file qfc_est.cpp.

df1b2variable nllNormal ( const df1b2vector x,
const double  mu,
const double  sigma 
)

nll for normal for many samples, but mu is for common, overload for random effect $ 0.5n\ln(2 \pi) + n\ln(\sigma) + 0.5\sum(\frac{x-\mu}{\sigma})^2 $

Parameters:
x: data
mu: mean parameter
sigma: std deviation parameter
Returns:
return the nll for normal for many samples sharing one mu

Definition at line 1195 of file qfc_est.cpp.

dvariable nllNormal ( const dvar_vector x,
const dvector mu,
const double  sigma 
)

nll for normal for many samples, each has its own mean $ 0.5n\ln(2 \pi) + n\ln(\sigma) + 0.5\sum(\frac{x_{i}-\mu_{i}}{\sigma})^2 $

Parameters:
x: data
mu: mean parameter
sigma: std deviation parameter
Returns:
return the nll for normal for many samples, each has own mean

Definition at line 1227 of file qfc_est.cpp.

df1b2variable nllNormal ( const df1b2vector x,
const dvector mu,
const double  sigma 
)

nll for normal for many samples, each has its own mean for random effect $ 0.5n\ln(2 \pi) + n\ln(\sigma) + 0.5\sum(\frac{x_{i}-\mu_{i}}{\sigma})^2 $

Parameters:
x: data
mu: mean parameter
sigma: std deviation parameter
Returns:
return the nll for normal for many samples, each has own mean

Definition at line 1263 of file qfc_est.cpp.

dvariable nllNormal2 ( const dvariable x,
const double  mu,
const double  tau 
)

nll for normal(mu,tau) for one sample $ 0.5\ln(2 \pi) -0.5 \ln(\tau) + 0.5\tau(x-\mu)^2 $

Parameters:
x: data
mu: mean parameter
tau: precision, 1/variance
Returns:
return the nll for normal for one sample

Definition at line 1304 of file qfc_est.cpp.

df1b2variable nllNormal2 ( const df1b2variable x,
const double  mu,
const double  tau 
)

nll for normal(mu,tau) for one sample for random effect $ 0.5\ln(2 \pi) -0.5 \ln(\tau) + 0.5\tau(x-\mu)^2 $

Parameters:
x: data
mu: mean parameter
tau: precision, 1/variance
Returns:
return the nll for normal for one sample

Definition at line 1337 of file qfc_est.cpp.

dvariable nllNormal2 ( const dvar_vector x,
const double  mu,
const double  tau 
)

nll for normal(mu,tau) for many samples $ 0.5n\ln(2 \pi) -0.5n\ln(\tau) + 0.5\tau\sum(x-\mu)^2 $

Parameters:
x: data
mu: mean parameter
tau: precision, 1/variance
Returns:
return the nll for normal for many samples

Definition at line 1367 of file qfc_est.cpp.

df1b2variable nllNormal2 ( const df1b2vector x,
const double  mu,
const double  tau 
)

nll for normal(mu,tau) for many samples for random effect $ 0.5n\ln(2 \pi) -0.5n\ln(\tau) + 0.5\tau\sum(x-\mu)^2 $

Parameters:
x: data
mu: mean parameter
tau: precision, 1/variance
Returns:
return the nll for normal for many samples

Definition at line 1403 of file qfc_est.cpp.

dvariable nllNormal2 ( const dvar_vector x,
const dvector mu,
const double  tau 
)

nll for normal(mu,tau) for many samples, each has its own mean $ 0.5n\ln(2 \pi) + n\ln(\sigma) + 0.5\tau\sum(x_{i}-\mu_{i})^2 $

Parameters:
x: data
mu: mean parameter
tau: precision, 1/variance
Returns:
return the nll for normal for many samples, each has own mean

Definition at line 1435 of file qfc_est.cpp.

df1b2variable nllNormal2 ( const df1b2vector x,
const dvector mu,
const double  tau 
)

nll for normal(mu,tau) for many samples, each has its own mean, overload for random effect, $ 0.5n\ln(2 \pi) + n\ln(\sigma) + 0.5\tau\sum(x_{i}-\mu_{i})^2 $

Parameters:
x: data
mu: mean parameter
tau: precision, 1/variance
Returns:
return the nll for normal for many samples, each has own mean

Definition at line 1471 of file qfc_est.cpp.

double nllPoisson ( const double  x,
const double  lambda 
)

nll for poisson for one sample $ \lambda -x\ln(\lambda)+\ln(x!) $

Parameters:
x: data
lambda: mean parameter
Returns:
return the nll for poisson for one sample

Definition at line 2132 of file qfc_est.cpp.

df1b2variable nllPoisson ( const df1b2variable x,
const double  lambda 
)

nll for poisson for one sample for random effect $ \lambda -x\ln(\lambda)+\ln(x!) $

Parameters:
x: data
lambda: mean parameter
Returns:
return the nll for poisson for one sample

Definition at line 2170 of file qfc_est.cpp.

dvariable nllPoisson ( const dvar_vector x,
const double  lambda 
)

nll for poisson for many samples $ n\lambda -\sum(x)\ln(\lambda)+\sum(\ln(x!)) $

Parameters:
x: data
lambda: mean parameter
Returns:
return the nll for poisson for many samples

Definition at line 2198 of file qfc_est.cpp.

df1b2variable nllPoisson ( const dvector x,
const df1b2variable lambda 
)

nll for poisson for many samples for random effect $ n\lambda -\sum(x)\ln(\lambda)+\sum(\ln(x!)) $

Parameters:
x: data
lambda: mean parameter
Returns:
return the nll for poisson for many samples

Definition at line 2233 of file qfc_est.cpp.

normailize p as sum(p)=1, return p and penalty if sum(p)!=1

Parameters:
p: the prob. vector
fpen: penalty
Returns:
return p as sum(p)=1 the a, one element less than input p

Definition at line 115 of file qfc_est.cpp.

int numRows4VarFromFile ( adstring  filename,
adstring  varName 
)

get how many rows for one specific variable(varName) in admb output file(filename)

Parameters:
filename: search for admb output file name
varName: variable name being searched for
Returns:
return 1 for unique name or many rows for same name , return 0 for not found

Definition at line 40 of file qfc_sim.cpp.

Referenced by findValFromFile().

dvar_vector posfun ( dvar_vector x,
const dvector eps,
dvariable pen 
)

overloading functions for posfun for vector and matrix, not sure if admb already do this in latest version

Parameters:
x: being constrained input value
eps: positive vector as lower thresholds
pen: hold extra penalty, need add to objective function value later
Returns:
return value between (0,eps) with penalty fpen for input x< eps, or return x itself if x>=eps with no penalty

Definition at line 142 of file qfc_est.cpp.

dvar_matrix posfun ( dvar_matrix x,
const dmatrix eps,
dvariable pen 
)

overloading functions for posfun for vector and matrix, not sure if admb already do this in latest version
overloading function for matrix

Parameters:
x: being constrained input value
eps: positive vector as lower thresholds
pen: hold extra penalty, need add to objective function value later
Returns:
return value between (0,eps) with penalty fpen for input x< eps, or return x itself if x>=eps with no penalty

Definition at line 172 of file qfc_est.cpp.

double rbeta ( double  alpha,
double  beta,
random_number_generator rng 
)

generate random beta(alpha, beta) number,

Parameters:
alpha: alpha parameter
beta: beta parameter
rng: admb build in random number generator
Returns:
return beta random number

Definition at line 511 of file qfc_sim.cpp.

dvector rdirichlet ( const dvector shape,
random_number_generator rng 
)

generate random dirichlet number

Parameters:
shape: shape parameter
rng: admb build in random number generator
Returns:
return dirichlet random number

Definition at line 524 of file qfc_sim.cpp.

double rgamma ( double  alpha,
random_number_generator rng 
)

generate random gamma number, pseudo code see http://en.wikipedia.org/wiki/Gamma_distribution , Gamma(alpha, belta)=x^(alpha-1)*belta^alpha*exp(-belta*x)/gamma(alpha)

Parameters:
alpha: shape parameter, >0 =1/CV^2
rng: admb build in random number generator
Returns:
return gamma random number

Definition at line 449 of file qfc_sim.cpp.

Referenced by rbeta(), rdirichlet(), and rgamma().

double rgamma ( double  alpha,
double  beta,
random_number_generator rng 
)

generate random gamma number, mean is alpha/belta, variance is alpha/(belta^2)

Parameters:
alpha: shape parameter, >0 =1/CV^2
beta: rate =1/scale,inverse of the scale parameter, >0 =1/(mean*CV^2)
rng: admb build in random number generator
Returns:
return gamma random number

Definition at line 497 of file qfc_sim.cpp.

double rlnorm ( double  mu,
double  sigma,
random_number_generator rng 
)

generate one random lognormal number LN(mu,sigma)

Parameters:
mu: mean
sigma: std. deviation
rng: admb build in random number generator
Returns:
return lognormal random number LN(mu,sigma)

Definition at line 433 of file qfc_sim.cpp.

double rnorm ( double  mu,
double  sigma,
random_number_generator rng 
)

generate one random normal number N(mu,sigma)

Parameters:
mu: mean
sigma: std. deviation
rng: admb build in random number generator
Returns:
return normal random number N(mu,sigma)

Definition at line 418 of file qfc_sim.cpp.

double runif ( double  low,
double  upper,
random_number_generator rng 
)

generate one random uniform from (low,upper)

Parameters:
low: low range
upper: high range
rng: admb build in random number generator
Returns:
return uniform random number within range (low, upper)

Definition at line 403 of file qfc_sim.cpp.

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 replacement

Parameters:
source: baseline samples as input
nSample: random sample size for output
withReplace: if 0 for without replacement, nonzero means with replacement
rng: admb build in random number generator
Returns:
return an index vector which are the index from the samples, if want to access the values, use return dvector version

Definition at line 171 of file qfc_sim.cpp.

dvector unique ( const dvector in)

find the unique values from input vector and only return the unique (by remove the duplicate) values in ascending order

Parameters:
in: contain duplicate values in the input vector
Returns:
return a vector comprised of unique values in ascending order and its index starting from 1

Definition at line 127 of file qfc_sim.cpp.

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,

Parameters:
input: long vector/array being converted
nrow: the number of rows for output matrix
ncol: the number of columns for output matrix
byrow: default as by row, use 1, which fill the each row from top to bottom Or any number other than 1 as by column, which fill each column from left to right
Returns:
return a matrix which row and column index all starting from 1

Definition at line 286 of file qfc_sim.cpp.

df1b2matrix vector2matrix ( df1b2vector input,
int  nrow,
int  ncol,
int  byrow = 1 
)

convert the Vector as a Matrix eithter by row=1(default) or by column=0, overloading function

Parameters:
input: long vector/array being converted
nrow: the number of rows for output matrix
ncol: the number of columns for output matrix
byrow: default as by row, use 1, which fill the each row from top to bottom Or any number other than 1 as by column, which fill each column from left to right
Returns:
return a matrix which row and column index all starting from 1

Definition at line 317 of file qfc_sim.cpp.

dvar_matrix vector2matrix ( const dvar_vector input,
int  nrow,
int  ncol,
int  byrow = 1 
)

convert the Vector as a Matrix eithter by row=1(default) or by column=0, overloading function

Parameters:
input: long vector/array being converted
nrow: the number of rows for output matrix
ncol: the number of columns for output matrix
byrow: default as by row, use 1, which fill the each row from top to bottom Or any number other than 1 as by column, which fill each column from left to right
Returns:
return a matrix which row and column index all starting from 1

Definition at line 348 of file qfc_sim.cpp.