Revision 324 trunk/contrib/qfclib/qfclib.h
qfclib.h (revision 324)  

1 
#ifndef __QFCLIB_H__ 

2 
#define __QFCLIB_H__ 

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_ 

3  30  
4 
#include <math.h> 

5 
#include <admodel.h> 

6 
#include <df1b2fun.h> 

7 
#include <adrndeff.h> 

8 
const double EPS = 1.e30; //tiny number to avoid 0 in log 

9  
10 
dvar_vector logitProp(const dvar_vector& a); 

11 
// Weihei, add the rest of the prototypes here... 

12  
13 
#endif 

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.e20; 

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); 
Also available in: Unified diff