1 /* mh.h 2 3 Originally written by Frederic Bois 4 5 Copyright (c) 1996-2017 Free Software Foundation, Inc. 6 7 This file is part of GNU MCSim. 8 9 GNU MCSim is free software; you can redistribute it and/or 10 modify it under the terms of the GNU General Public License 11 as published by the Free Software Foundation; either version 3 12 of the License, or (at your option) any later version. 13 14 GNU MCSim is distributed in the hope that it will be useful, 15 but WITHOUT ANY WARRANTY; without even the implied warranty of 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 GNU General Public License for more details. 18 19 You should have received a copy of the GNU General Public License 20 along with GNU MCSim; if not, see <http://www.gnu.org/licenses/> 21 22 Header file for mh.c 23 */ 24 25 #ifndef MH_H_DEFINED 26 27 /* ---------------------------------------------------------------------------- 28 Inclusions 29 */ 30 31 #include <float.h> /* Floating point limits */ 32 #include <stdarg.h> 33 34 #include "sim.h" 35 #include "config.h" 36 37 #define UPDATE_BASE 20 /* Change MH criterion */ 38 39 /* ---------------------------------------------------------------------------- 40 Global/External variables 41 */ 42 #define NTEMP 50 43 44 45 /* ---------------------------------------------------------------------------- 46 Definitions 47 */ 48 49 #define MAX_ARGS 25 50 51 #define NULL_SUPPORT -1.0E+100 52 #define MISSING_VALUE (-DBL_MAX) 53 #define INPUT_MISSING_VALUE -1 54 55 /* ---------------------------------------------------------------------------- 56 Typedefs 57 */ 58 59 /* Specification for PrintTemperatureDiagnostics */ 60 typedef enum {Geyer, NoGeyer} EGEYER; 61 62 63 /* ---------------------------------------------------------------------------- 64 Prototypes 65 */ 66 void CollectConvInfo (PLEVEL plevel, char **args); 67 int checkConvergence(int nOut, int variableCount,int p_count, 68 double **meansForAll, double **varsForAll, 69 double *Rhat); 70 void CalculateMeanAndVariance (long n, double x, double *xi_bari, 71 double *si_2i) ; 72 void CalculateTotals (PLEVEL plevel, char **args); 73 void CheckForFixed (PLEVEL plevel, char **args); 74 void CheckPrintStatements (PLEVEL plevel, char **args); 75 void CloneLikes (PLEVEL plevel, char **args); 76 void CloneLikesL (PVOID pData, PVOID pUser1, PVOID pUser2, PVOID pUser3); 77 void CloneMCVars (PLEVEL plevel, char **args); 78 void CloneMCVarsL (PVOID pData, PVOID pUser1, PVOID pUser2, PVOID pUser3); 79 void CloseMarkovFiles (PGIBBSDATA pgd); 80 void ConvertLists (PLEVEL plevel, char **args); 81 void DoMarkov (PANALYSIS panal); 82 void FindLikeParents (PLEVEL plevel, char **args); 83 void FindMCDependents(PLEVEL plevel, char **args); 84 void FindMCParents (PLEVEL plevel, char **args); 85 void GetNumberOfMCVars (PLEVEL plevel, char **args); 86 void InitArrays (long lDim, long nSubjs, double ***pdSum, 87 double ****prgdSumProd); 88 void InitMCVars (PLEVEL plevel, char **args); 89 void InitPerks (PANALYSIS panal); 90 void ListToPMCArray (PANALYSIS panal, PLIST plist, 91 long *nMCVars, PMCVAR **rgpMCVars); 92 void ListToPMCArrayL (PVOID pData, PVOID pUser1, PVOID pUser2, PVOID pUser3); 93 void ListToPVArray (PANALYSIS panal, PLIST plist, 94 long *nFixedVars, PVARMOD **rgpFixedVars); 95 void ListToPVArrayL (PVOID pData, PVOID pUser1, PVOID pUser2, PVOID pUser3); 96 double LnDensity (PMCVAR pMCVar, PANALYSIS panal); 97 double LnLike (PMCVAR pMCVar, PANALYSIS panal); 98 double LnLikeData (PLEVEL plevel, PANALYSIS panal); 99 double MaxMCVar (PMCVAR pMCVar); 100 double MinMCVar (PMCVAR pMCVar); 101 void OpenMarkovFiles (PANALYSIS panal); 102 void PrintAllExpts (PLEVEL plevel, PANALYSIS panal, PFILE pOutFile); 103 void PrintDeps (PLEVEL plevel, char **args); 104 int PrintExpt (PLEVEL plevel, char **args); 105 void PrintTemperatureDiagnostics (PFILE fOut, PGIBBSDATA pgd); 106 void ReadData (PLEVEL plevel, char **args); 107 void ReadDataFile (PANALYSIS panal); 108 void ReadKernel (PLEVEL plevel, char **args); 109 void ReadRestart (FILE *pfileRestart, long nThetas, PDOUBLE *pdTheta, 110 PDOUBLE *pdSum, PDOUBLE **prgdSumProd, long *pIter); 111 void ReadRestartTemper (FILE *pfileRestart, long nThetas, 112 int nInvTemperatures, PDOUBLE *pdTheta, 113 PDOUBLE *pdSum, PDOUBLE **prgdSumProd, 114 long *pIter, int *pindexT, double *pdlnPi); 115 int RestoreLikelihoods (PLEVEL plevel, char **args); 116 int RunAllExpts(PANALYSIS panal, PDOUBLE pdLnData); 117 int RunExpt (PLEVEL plevel, char **args); 118 double SampleTheta (PMCVAR pMCVar); 119 long SampleTemperature (PGIBBSDATA pgd, double dLnPrior, double dLnData); 120 long SampleTemperature2 (PGIBBSDATA pgd, double dLnPrior, double dLnData); 121 void SampleThetas (PLEVEL plevel, char **args); 122 void SampleThetasTempered (PLEVEL plevel, char **args); 123 void SampleThetaVector (PLEVEL pLevel, PANALYSIS panal, long nThetas, 124 double *pdTheta, double *pdSum, double **prgdSumProd, 125 long iter, long nUpdateAt, long nTotal, 126 PDOUBLE pdLnPrior, PDOUBLE pdLnData); 127 int SaveLikelihoods (PLEVEL plevel, char **args); 128 void SetFixedVars (PLEVEL plevel); 129 int SetMCVars (PLEVEL plevel, char **args); 130 void SetModelVars (PLEVEL plevel); 131 void SetKernel (PLEVEL plevel, char **args); 132 void SetPointers (PLEVEL plevel, char **args); 133 int SumAllExpts (PLEVEL plevel, char **args); 134 double Temper_probabilities(int n, long i, long j); 135 BOOL TestImpRatio (PGIBBSDATA pgd, BOOL bExptIsDep, 136 double dLnKern, double dLnKernNew, 137 double dLnPrior, double dLnPriorNew, 138 double dLnLike, double dLnLikeNew, 139 double dLnData, double dLnDataNew); 140 BOOL TestImpRatioTemper (PGIBBSDATA pgd, BOOL bExptIsDep, 141 double dLnKern, double dLnKernNew, 142 double dLnPrior, double dLnPriorNew, 143 double dLnLike, double dLnLikeNew, 144 double dLnData, double dLnDataNew, long indexT); 145 BOOL TestTemper (PGIBBSDATA pgd, long indexT, long indexT_new, 146 double dLnPrior, double dLnData, double pseudo, 147 double pseudonew); 148 void TraverseLevels (PLEVEL plevel, 149 void (*routinePtr)(PLEVEL plevel, char **args), ...); 150 int TraverseLevels1 (PLEVEL plevel, 151 int (*routinePtr)(PLEVEL plevel, char **args), ...); 152 void WriteHeader (PANALYSIS panal); 153 void WriteParameterNames (PLEVEL plevel, char **args); 154 void WriteKernel (PLEVEL plevel, char **args); 155 void WriteMCVars (PLEVEL plevel, char **args); 156 157 #define MH_H_DEFINED 158 #endif /* _MH_H_ */ 159 160 /* End */ 161