Revision 307

trunk/contrib/qfclib/qfclib.h (revision 307)
1
 /** 
2
  * \file	qfc_sim.h
3
  * \brief functions useful for simulation model in admb
4
  * \date 7/28/2011
5
  * \author Weihai Liu
6
  * \ingroup QFC
7
  *
8
  *  Following user defined functions are more useful for doing simulation model in admb, 
9
  *  the easy way to use these functions is with your tpl file
10
  *  under the GLOBALS_SECTION , add a line on top as   #include "qfclib.h", 
11
  *  there is a testfunction.tpl file within this folder show how to use these functions.
12
  *
13
  *  ================  brief list for usage  ============================\n
14
  *  1. return some values for the specific variable name in admb ouput file,
15
  *     such as find the parameter value and its std value from .std file, 
16
  *     use findValFromFile("test.std","linf",2), see findValFromFile()  \n
17
  *  2. doing random sampling with or without replacement, see sample()  \n 
18
  *  3. remove the duplicate values from a vector, see unique()  \n  
19
  *  4. several random number generator, runif(), rnorm(), rgamma(), rdirichlet() \n
20
  *  5. convert vector to matrix by row or by column or its reverse form,  
21
  *     see matrix2vector(), vector2matrix() \n
22
  *  =============================================================\n
23
  *
24
  *  found any bug , contact Weihai Liu at liuweih@msu.edu \n
25
  *  Quantitative Fisheries Center(QFC), Michigan State University \n
26
  */
27

  
28
#ifndef _QFCLIB_H_
29
#define _QFCLIB_H_
30

  
31
#include <math.h>
32
#include <admodel.h>
33
#include <df1b2fun.h>
34
#include <adrndeff.h>
35
// define constant variable
36
const double EPS = 1.e-20;   
37

  
38
//function defined for simulation model
39
int 		numRows4VarFromFile (adstring filename, adstring varName);
40
dmatrix 	findValFromFile (adstring filename, adstring varName, int numVals);
41
dvector 	unique (const dvector &in);
42
ivector 	sample (const dvector &source, int nSample, int withReplace, const random_number_generator &rng);
43
dvector 	matrix2vector (const dmatrix &input, int byrow);
44
dvar_vector 	matrix2vector (const dvar_matrix &input, int byrow);
45
df1b2vector 	matrix2vector (const df1b2matrix &input, int byrow);
46
dmatrix 	vector2matrix (dvector &input, int nrow, int ncol, int byrow);
47
df1b2matrix 	vector2matrix (df1b2vector &input, int nrow, int ncol, int byrow);
48
dvar_matrix 	vector2matrix (const dvar_vector &input, int nrow, int ncol, int byrow);
49
bool 		doubleEqual (double nVal1, double nVal2, int nPrecision);
50
double 		runif (double low, double upper, random_number_generator &rng);
51
double 		rnorm (double mu, double sigma, random_number_generator &rng);
52
double rlnorm(double mu, double sigma, random_number_generator & rng);
53
double 		rgamma (double alpha, random_number_generator &rng);
54
double 		rgamma (double alpha, double beta, random_number_generator &rng);
55
double rbeta(double alpha, double beta, random_number_generator& rng);
56
dvector 	rdirichlet (const dvector &shape, random_number_generator &rng);
57

  
58
//function defined for estimation model
59
dvar_vector 	logitProp (const dvar_vector &a);
60
df1b2vector 	logitProp (const df1b2vector &a);
61
dvar_vector 	invLogitProp (const dvar_vector &p);
62
df1b2vector 	invLogitProp (const df1b2vector &p);
63
dvar_vector 	normalize_p (dvar_vector &p, dvariable fpen);
64
df1b2vector 	normalize_p (df1b2vector &p, df1b2variable fpen);
65
dvar_vector 	posfun (dvar_vector &x, const dvector &eps, dvariable &pen);
66
df1b2vector 	posfun (df1b2vector &x, const dvector &eps, df1b2variable &pen);
67
dvar_matrix 	posfun (dvar_matrix &x, const dmatrix &eps, dvariable &pen);
68
df1b2matrix 	posfun (df1b2matrix &x, const dmatrix &eps, df1b2variable &pen);
69
dvariable 	mf_upper_bound2 (const dvariable &x, const double fmax, dvariable &fpen);
70
df1b2variable 	mf_upper_bound2 (const df1b2variable &x, const double fmax, df1b2variable &fpen);
71
dvar_vector 	boundp (const dvar_vector &x, const double fmin, const double fmax, const dvariable &fpen);
72
df1b2vector 	boundp (const df1b2vector &x, const double fmin, const double fmax, const df1b2variable &fpen);
73
df1b2vector 	log_comb (const df1b2vector &n, const df1b2vector &x);
74
df1b2vector 	log_comb (const df1b2vector &n, const dvector &x);
75
df1b2vector 	log_comb (const dvector &n, const df1b2vector &x);
76
double 	nllNegativeBinomial (const double obs, const double m, const double s);
77
dvariable 	nllNegativeBinomial (const dvariable &obs, const double m, const double s);
78
dvariable 	nllNegativeBinomial (const double obs, const dvariable &m, const dvariable &s);
79
dvariable 	nllNegativeBinomial (const dvariable &obs, const dvariable &m, const double s);
80
dvariable 	nllNegativeBinomial (const dvariable &obs, const double m, const dvariable &s);
81
dvariable 	nllNegativeBinomial (const dvariable &obs, const dvariable &m, const dvariable &s);
82
df1b2variable 	nllNegativeBinomial (const df1b2variable &obs, const double m, const double s);
83
df1b2variable 	nllNegativeBinomial (const double obs, const df1b2variable &m, const df1b2variable &s);
84
df1b2variable 	nllNegativeBinomial (const df1b2variable &obs, const df1b2variable &m, const double s);
85
df1b2variable 	nllNegativeBinomial (const df1b2variable &obs, const double m, const df1b2variable &s);
86
df1b2variable 	nllNegativeBinomial (const df1b2variable &obs, const df1b2variable &m, const df1b2variable &s);
87
dvariable 	nllNegativeBinomial (const dvector &obs, const dvariable &m, const dvariable &s);
88
dvariable 	nllNegativeBinomial (const dvar_vector &obs, const double m, const double s);
89
dvariable 	nllNegativeBinomial (const dvar_vector &obs, const dvariable &m, const dvariable &s);
90
df1b2variable 	nllNegativeBinomial (const df1b2vector &obs, const double m, const double s);
91
df1b2variable 	nllNegativeBinomial (const dvector &obs, const df1b2variable &m, const df1b2variable &s);
92
df1b2variable 	nllNegativeBinomial (const df1b2vector &obs, const df1b2variable &m, const df1b2variable &s);
93
double 	nllNegativeBinomial2 (const double obs, const double m, const double tau);
94
dvariable 	nllNegativeBinomial2 (const double obs, const dvariable &m, const dvariable &tau);
95
dvariable 	nllNegativeBinomial2 (const dvariable &obs, const double m, const double tau);
96
dvariable 	nllNegativeBinomial2 (const dvariable &obs, const dvariable &m, const double tau);
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff