### SWZ: remove out of date code

parent 06fe0c85
 sbvar_draws sbvar_init_file sbvar_mhm_1 sbvar_mhm_2 sbvar_probabilities sbvar_estimation
 //== Flat Independent Markov States and Simple Restrictions ==// //-----------------------------------------------------------------------------// //-- Read by CreateMarkovStateVariable_File() only if the passed number of --// //-- observations is less than or equal to zero. Can be omitted if the --// //-- passed number of observations is positive. --// //-----------------------------------------------------------------------------// //== Number Observations ==// 200 //== Number Independent State Variables ==// 2 //-----------------------------------------------------------------------------// //-- state_variable (1 <= i <= n_state_variables) --// //-----------------------------------------------------------------------------// //== Number of states for state_variable ==// 3 //-----------------------------------------------------------------------------// //-- Each column contains the parameters for a Dirichlet prior on the --// //-- corresponding column of the transition matrix. Each element must be --// //-- positive. For each column, the relative size of the prior elements --// //-- determine the relative size of the elements of the transition matrix --// //-- and overall larger sizes implies a tighter prior. --// //-----------------------------------------------------------------------------// //== Transition matrix prior for state_variable. (n_states x n_states) ==// 10 1 1 1 10 1 1 1 10 //-----------------------------------------------------------------------------// //-- An array of n_states integers with each entry between 1 and n_states, --// //-- inclusive. Determines the number of quasi-free Dirichlet dimensions --// //-- each column. Since the sum of the elements in a Dirichlet distribution --// //-- must equal to one, the actual number of free dimensions is one less. --// //-----------------------------------------------------------------------------// //== Free Dirichet dimensions for state_variable ==// 3 3 3 //-----------------------------------------------------------------------------// //-- The jth restriction matrix is n_states x free[j]. Each row of the --// //-- restriction matrix has at most one non-zero entry and the sum of each --// //-- column of the restriction matrix must be one. If (x(1),...,x(free[j])) --// //-- is the Dirichlet random variable for column j, then the jth column of --// //-- the transition matrix Q is the jth restriction matrix times the --// //-- Dirichlet random random variable. --// //-----------------------------------------------------------------------------// //== Column restrictions for state_variable ==// 1 0 0 0 1 0 0 0 1 1 0 0 0 1 0 0 0 1 1 0 0 0 1 0 0 0 1 //-----------------------------------------------------------------------------// //-- Allows for lagged values of the state variable to be encoded --// //-----------------------------------------------------------------------------// //== Number of lags encoded for state_variable ==// 2 //-----------------------------------------------------------------------------// //-- state_variable --// //-----------------------------------------------------------------------------// //== Number of states for state_variable ==// 2 //-----------------------------------------------------------------------------// //-- Each column contains the parameters for a Dirichlet prior on the --// //-- corresponding column of the transition matrix. Each element must be --// //-- positive. For each column, the relative size of the prior elements --// //-- determine the relative size of the elements of the transition matrix --// //-- and overall larger sizes implies a tighter prior. --// //-----------------------------------------------------------------------------// //== Transition matrix prior for state_variable. (n_states x n_states) ==// 5 1 1 5 //-----------------------------------------------------------------------------// //-- An array of n_states integers with each entry between 1 and n_states, --// //-- inclusive. Determines the number of quasi-free Dirichlet dimensions --// //-- each column. Since the sum of the elements in a Dirichlet distribution --// //-- must equal to one, the actual number of free dimensions is one less. --// //-----------------------------------------------------------------------------// //== Free Dirichet dimensions for state_variable ==// 2 2 //-----------------------------------------------------------------------------// //-- The jth restriction matrix is n_states x free[j]. Each row of the --// //-- restriction matrix has at most one non-zero entry and the sum of each --// //-- column of the restriction matrix must be one. If (x(1),...,x(free[j])) --// //-- is the Dirichlet random variable for column j, then the jth column of --// //-- the transition matrix Q is the jth restriction matrix times the --// //-- Dirichlet random random variable. --// //-----------------------------------------------------------------------------// //== Column restrictions for state_variable ==// 1 0 0 1 1 0 0 1 //-----------------------------------------------------------------------------// //-- Allows for lagged values of the state variable to be encoded --// //-----------------------------------------------------------------------------// //== Number of lags encoded for state_variable ==// 0
This diff is collapsed.
This diff is collapsed.
 #include "switch_opt.h" #include #include #include #include "modify_for_mex.h" /* //====== Static Global Variables ====== ansi-c*/ static TStateModel *Model=(TStateModel*)NULL; static PRECISION *buffer=(PRECISION*)NULL; static PRECISION *ModifiedFreeParameters=(PRECISION*)NULL; static PRECISION *FreeParameters_Q=(PRECISION*)NULL; static int NumberFreeParameters_Q=0; static PRECISION *FreeParameters_Theta=(PRECISION*)NULL; static int NumberFreeParameters_Theta=0; void SetupObjectiveFunction(TStateModel *model, PRECISION *Modified, PRECISION *FreeQ, PRECISION *FreeTheta) { if (buffer) swzFree(buffer); Model=model; FreeParameters_Q=FreeQ; NumberFreeParameters_Q=NumberFreeParametersQ(model); FreeParameters_Theta=FreeTheta; NumberFreeParameters_Theta=model->routines->pNumberFreeParametersTheta(model); ModifiedFreeParameters=Modified; } void SetupObjectiveFunction_new(TStateModel *model, int FreeTheta_Idx, int FreeQ_Idx, int Modified_Idx) { if (buffer) swzFree(buffer); Model=model; NumberFreeParameters_Q=NumberFreeParametersQ(model); NumberFreeParameters_Theta=model->routines->pNumberFreeParametersTheta(model); buffer=(PRECISION*)swzMalloc((NumberFreeParameters_Q + NumberFreeParameters_Theta)*sizeof(PRECISION)); FreeParameters_Q=buffer+FreeQ_Idx; FreeParameters_Theta=buffer+FreeTheta_Idx; ModifiedFreeParameters=buffer+Modified_Idx; } PRECISION PosteriorObjectiveFunction(PRECISION *x, int n) { if (x != ModifiedFreeParameters) memmove(ModifiedFreeParameters,x,n*sizeof(PRECISION)); ConvertFreeParametersToQ(Model,FreeParameters_Q); ConvertFreeParametersToTheta(Model,FreeParameters_Theta); return -LogPosterior_StatesIntegratedOut(Model); /* //PRECISION lp_Q, lp_Theta, li; ansi-c*/ /* //FILE *f_out; ansi-c*/ /* //lp_Q=LogPrior_Q(Model); ansi-c*/ /* //lp_Theta=LogPrior_Theta(Model); ansi-c*/ /* //li=LogLikelihood_StatesIntegratedOut(Model); ansi-c*/ /* //if (isnan(lp_Q) || isnan(lp_Theta) || isnan(li)) ansi-c*/ /* // { ansi-c*/ /* // f_out=fopen("tmp.tmp","wt"); ansi-c*/ /* // Write_VAR_Specification(f_out,(char*)NULL,Model); ansi-c*/ /* // WriteTransitionMatrices(f_out,(char*)NULL,"Error: ",Model); ansi-c*/ /* // Write_VAR_Parameters(f_out,(char*)NULL,"Error: ",Model); ansi-c*/ /* // fprintf(f_out,"LogPrior_Theta(): %le\n",lp_Theta); ansi-c*/ /* // fprintf(f_out,"LogPrior_Q(): %le\n",lp_Q); ansi-c*/ /* // fprintf(f_out,"LogLikelihood_StatesIntegratedOut(): %le\n",li); ansi-c*/ /* // fprintf(f_out,"Posterior: %le\n\n",lp_Q+lp_Theta+li); ansi-c*/ /* // fclose(f_out); ansi-c*/ /* // swzExit(0); ansi-c*/ /* // } ansi-c*/ /* //return -(lp_Q+lp_Theta+li); ansi-c*/ } PRECISION PosteriorObjectiveFunction_csminwel(double *x, int n, double **args, int *dims) { return PosteriorObjectiveFunction(x,n); } void PosteriorObjectiveFunction_npsol(int *mode, int *n, double *x, double *f, double *g, int *nstate) { *f=PosteriorObjectiveFunction(x,*n); } PRECISION MLEObjectiveFunction(PRECISION *x, int n) { if (x != ModifiedFreeParameters) memmove(ModifiedFreeParameters,x,n*sizeof(PRECISION)); ConvertFreeParametersToQ(Model,FreeParameters_Q); ConvertFreeParametersToTheta(Model,FreeParameters_Theta); return -LogLikelihood_StatesIntegratedOut(Model); } PRECISION MLEObjectiveFunction_csminwel(double *x, int n, double **args, int *dims) { return MLEObjectiveFunction(x,n); } void MLEObjectiveFunction_npsol(int *mode, int *n, double *x, double *f, double *g, int *nstate) { *f=MLEObjectiveFunction(x,*n); } PRECISION MLEObjectiveFunction_LogQ(PRECISION *x, int n) { if (x != ModifiedFreeParameters) memmove(ModifiedFreeParameters,x,n*sizeof(PRECISION)); ConvertLogFreeParametersToQ(Model,FreeParameters_Q); ConvertFreeParametersToTheta(Model,FreeParameters_Theta); return -LogLikelihood_StatesIntegratedOut(Model); } PRECISION MLEObjectiveFunction_LogQ_csminwel(double *x, int n, double **args, int *dims) { return MLEObjectiveFunction_LogQ(x,n); }
 #ifndef __MARKOV_SWITCHING_OPTIMIZATION__ #define __MARKOV_SWITCHING_OPTIMIZATION__ #include "switch.h" void SetupObjectiveFunction(TStateModel *model, PRECISION *MFPparms, PRECISION *FTMparms, PRECISION *FMSparms); PRECISION PosteriorObjectiveFunction(PRECISION *x, int n); PRECISION PosteriorObjectiveFunction_csminwel(double *x, int n, double **args, int *dims); void PosteriorObjectiveFunction_npsol(int *mode, int *n, double *x, double *f, double *g, int *nstate); PRECISION MLEObjectiveFunction(PRECISION *x, int n); PRECISION MLEObjectiveFunction_csminwel(double *x, int n, double **args, int *dims); void MLEObjectiveFunction_npsol(int *mode, int *n, double *x, double *f, double *g, int *nstate); PRECISION MLEObjectiveFunction_LogQ(PRECISION *x, int n); PRECISION MLEObjectiveFunction_LogQ_csminwel(double *x, int n, double **args, int *dims); #endif
This diff is collapsed.