From 190340a51d0755c762b4bffa0836cde81c79854f Mon Sep 17 00:00:00 2001 From: tzha <tzha@eco-tzha-01i.(none)> Date: Tue, 9 Feb 2010 15:11:42 -0500 Subject: [PATCH] Initial commit --- CFiles/Copy of kalman.c | 2751 ++ CFiles/Copy of kalman.h | 300 + CFiles/congradmin.c | 580 + CFiles/congradmin.h | 33 + CFiles/congradminOrigWorks.c | 557 + CFiles/congradminOrigWorks.h | 33 + CFiles/csminwel.c | 848 + CFiles/csminwel.h | 23 + CFiles/csminwelOrigWorks.c | 706 + CFiles/csminwelOrigWorks.h | 22 + CFiles/cstz.c | 2774 ++ CFiles/cstz.h | 201 + CFiles/cstz_dw.c | 2791 ++ CFiles/fn_filesetup.c | 851 + CFiles/fn_filesetup.h | 69 + CFiles/gensys.c | 1272 + CFiles/gensys.h | 67 + CFiles/gensys01Mar06Works.c | 1114 + CFiles/gensys01Mar06Works.h | 65 + CFiles/gensys08Mar06.c | 1113 + CFiles/gensysOldVersionWorks.c | 1114 + CFiles/gensysOldVersionWorks.h | 65 + CFiles/gradcd_switch.c | 202 + CFiles/gradcd_switch.h | 6 + CFiles/kalman.c | 2908 +++ CFiles/kalman.h | 314 + CFiles/kalmanOldWorks.c | 2634 ++ CFiles/kalmanOldWorks.h | 290 + CFiles/kalmanOldWorks2.c | 2907 +++ CFiles/kalmanOldWorks2.h | 314 + CFiles/mathlib.c | 5506 ++++ CFiles/mathlib.h | 395 + CFiles/numgradgenTemplate.c | 83 + CFiles/optpackage.c | 1109 + CFiles/optpackage.h | 497 + CFiles/rand.c | 499 + CFiles/rand.h | 44 + CFiles/template_proj.vcproj | 376 + CFiles/template_proj2.vcproj | 291 + CFiles/template_proj2_MKL8.0.vcproj | 296 + CFiles/template_proj2_MSV2005_MKL9.0.vcproj | 292 + CFiles/tzmatlab.c | 831 + CFiles/tzmatlab.h | 326 + .../Applications/BayesianDistributions.m | 259 + .../Applications/BinnedKernelDensity.m | 1110 + MathematicaFiles/Applications/DateFunctions.m | 206 + MathematicaFiles/Applications/Difference.m | 58 + .../Applications/DirichletDistribution.m | 141 + MathematicaFiles/Applications/DotPlot.m | 179 + MathematicaFiles/Applications/EulerSimulate.m | 146 + .../Applications/Eurodollar Data.nb | 21433 ++++++++++++++++ .../Applications/EurodollarDataFunctions.m | 281 + .../Applications/GaussianKernel.m | 118 + MathematicaFiles/Applications/GenSys.m | 358 + .../Applications/HierarchicalMetropolis.m | 94 + .../Applications/ImportExportBinary.m | 138 + MathematicaFiles/Applications/ItosLemma.m | 365 + MathematicaFiles/Applications/KalmanFilter.m | 65 + .../Applications/Kernel Configuration.nb | 542 + .../Applications/MaxEntSimplexDistribution.m | 350 + MathematicaFiles/Applications/Metropolis.m | 69 + .../Applications/MetropolisMCMC.m | 545 + .../Applications/MetropolisStep.nb | 1221 + .../Applications/Metropolis_working.m | 68 + MathematicaFiles/Applications/OddsandEnds.m | 1298 + MathematicaFiles/Applications/PagePrint.m | 143 + .../Applications/Parallel Test.nb | 591 + .../Parse Eurodollar Data from PDF.nb | 1700 ++ .../Applications/ParticleFilter.m | 306 + .../Applications/ParticleFilter.old | 280 + .../Applications/PenalizedSmooth.m | 76 + .../Applications/PlotEnhancements.m | 23 + .../Applications/RandomNumberGenerators.nb | 1004 + .../Applications/RecursivePreferencesPDE.m | 169 + .../Remaining/TempFiles/Thumbs.db | Bin 0 -> 5120 bytes .../Applications/ReversibleJumpMetropolis.m | 311 + .../Applications/SmoothedHistogram.m | 288 + .../Applications/StandardNormal.m | 114 + .../Applications/StatisticalStuff.m | 82 + .../Applications/StatisticsEnhancements.m | 429 + .../The Virtual Mathematica Book (v6).nb | 13110 ++++++++++ .../WriteBriefingFilesWithHeaders.m | 212 + MathematicaFiles/Applications/WulfGanglia.m | 53 + .../Applications/ZhaMathematicaLibrary.m | 168 + MatlabFiles/A0LHFUN.M | 38 + MatlabFiles/A0LHGRAD.M | 21 + MatlabFiles/A0lhgh.m | 19 + MatlabFiles/BinRead.m | 15 + MatlabFiles/BinWrite.m | 20 + MatlabFiles/CONTENTS.M | 5 + MatlabFiles/CSMINWEL.M0 | 271 + MatlabFiles/ERRORS.M | 86 + MatlabFiles/ERRORS.OLD | 91 + MatlabFiles/ERRORS.m1 | 91 + MatlabFiles/ERRORS.sav | 86 + MatlabFiles/FORECAST.M | 25 + MatlabFiles/Forecasterr.m | 28 + MatlabFiles/GENSYSCT.M | 180 + MatlabFiles/GIBBSGLB.M | 57 + MatlabFiles/GIBBSVAR.M | 77 + MatlabFiles/GRADCD.M | 66 + MatlabFiles/Gibbsvar.bak | 74 + MatlabFiles/HESSCD.M | 63 + MatlabFiles/HESSCD.M1 | 55 + MatlabFiles/HISTORY.M | 108 + MatlabFiles/IMPULSE.OLD | 58 + MatlabFiles/IMPULSE.m1 | 58 + MatlabFiles/IMPULSEO.M | 61 + MatlabFiles/MFORMD.M | 33 + MatlabFiles/MSV/MSV_Newton.m | 109 + MatlabFiles/MSV/dw_gensys.m | 46 + MatlabFiles/MSV/gensys.m | 177 + MatlabFiles/MSV/msv_all.m | 150 + MatlabFiles/MSV/msv_all_complex.m | 177 + MatlabFiles/MSV/msv_complex_AR.m | 69 + MatlabFiles/MSV/msv_one.m | 143 + MatlabFiles/MSV/msv_simple.m | 62 + MatlabFiles/MSV/qzcomputesolution.m | 120 + MatlabFiles/MSV/qzdiv.m | 40 + MatlabFiles/MSV/qzmoveindex.m | 18 + MatlabFiles/MSV/qzslide.m | 80 + MatlabFiles/MSV/qzsort.m | 21 + MatlabFiles/MSV/qzswitch.m | 60 + MatlabFiles/MSV/test_gensys.m | 30 + MatlabFiles/PHG233.M | 254 + MatlabFiles/PMDDF233.M | 260 + MatlabFiles/PMDDF234.M | 243 + MatlabFiles/PMDDG233.M | 50 + MatlabFiles/PMDDG234.M | 49 + MatlabFiles/PWF233.M | 224 + MatlabFiles/SRestrictRWZalg.m | 145 + MatlabFiles/SYE.M | 84 + MatlabFiles/SYED.M | 68 + MatlabFiles/Smtplis2seq.m | 99 + MatlabFiles/ZIMPULSE.M | 55 + MatlabFiles/a0asfun.m | 35 + MatlabFiles/a0asgrad.m | 27 + MatlabFiles/a0freefun.m | 45 + MatlabFiles/a0freegrad.m | 50 + MatlabFiles/a0impsmp.m | 83 + MatlabFiles/a0onlysim.m | 270 + MatlabFiles/adapt.m | 37 + MatlabFiles/adaptstp.m | 27 + MatlabFiles/betapar.m | 10 + MatlabFiles/bfgsi.m | 29 + MatlabFiles/bfgsi.m0 | 24 + MatlabFiles/bfgsi.m1 | 24 + MatlabFiles/calyrqm.m | 58 + MatlabFiles/cfore.m | 466 + MatlabFiles/chol2.m | 14 + MatlabFiles/clgls.m | 50 + MatlabFiles/clmonq.m | 25 + MatlabFiles/csminit.m | 199 + MatlabFiles/csminit.m0 | 163 + MatlabFiles/csminit.m1 | 147 + MatlabFiles/csminit.m2 | 158 + MatlabFiles/csminitWorksUntiil0205.m | 197 + MatlabFiles/csminwel.m | 291 + MatlabFiles/csminwel.m1 | 206 + MatlabFiles/csminwel.m2 | 271 + MatlabFiles/datactcon.m | 117 + MatlabFiles/dataext.m | 44 + MatlabFiles/datana.m | 96 + MatlabFiles/dataxy.m | 143 + MatlabFiles/demarcate.m | 98 + MatlabFiles/demarw.m | 48 + MatlabFiles/dlrpostr.m | 42 + MatlabFiles/eigsort.m | 30 + MatlabFiles/ellipse.m | 70 + MatlabFiles/empdfsort.m | 30 + MatlabFiles/fcstidcnd.m | 305 + MatlabFiles/fcstidcnd2.m | 342 + MatlabFiles/fidcnderr.m | 249 + MatlabFiles/fidcndexa.m | 46 + MatlabFiles/fidencond.m | 176 + MatlabFiles/find_betapar.m | 41 + MatlabFiles/find_gampar.m | 40 + MatlabFiles/find_invgampar.m | 41 + MatlabFiles/find_normpar.m | 31 + MatlabFiles/fn_PlotRecessionShades57_01.m | 9 + .../fn_PosteriorVarianceDecomposition.m | 48 + MatlabFiles/fn_ReadRecessionDates57_01.m | 16 + MatlabFiles/fn_a0cfreefun_tv.m | 60 + MatlabFiles/fn_a0cfreegrad_tv.m | 56 + MatlabFiles/fn_a0freefun.m | 39 + MatlabFiles/fn_a0freegrad.m | 42 + MatlabFiles/fn_a0sfreefun.m | 59 + MatlabFiles/fn_a0sfreefun2.m | 81 + MatlabFiles/fn_a0sfreegrad.m | 65 + MatlabFiles/fn_a0sfreegrad2.m | 125 + MatlabFiles/fn_calyrqm.m | 58 + MatlabFiles/fn_construct_cov.m | 19 + MatlabFiles/fn_corr.m | 18 + MatlabFiles/fn_dataext.m | 43 + MatlabFiles/fn_dataext2.m | 56 + MatlabFiles/fn_datana.m | 100 + MatlabFiles/fn_datana2.m | 177 + MatlabFiles/fn_dataxy.m | 147 + MatlabFiles/fn_dataxy7982.m | 166 + MatlabFiles/fn_dataxyOldVer.m | 140 + MatlabFiles/fn_demarw.m | 58 + MatlabFiles/fn_dirichprior.m | 78 + MatlabFiles/fn_dlrpostr.m | 44 + MatlabFiles/fn_empdfsort.m | 32 + MatlabFiles/fn_ergodp.m | 16 + MatlabFiles/fn_fcstcnd.m | 236 + MatlabFiles/fn_fcstidcnd.m | 310 + MatlabFiles/fn_fcstidcnd2.m | 348 + MatlabFiles/fn_forecast.m | 57 + MatlabFiles/fn_forecastfixe.m | 61 + MatlabFiles/fn_forecastsim.m | 62 + MatlabFiles/fn_foregraph.m | 50 + MatlabFiles/fn_forerrgraph.m | 55 + MatlabFiles/fn_fprintmatrix.m | 38 + MatlabFiles/fn_fprintvector.m | 29 + MatlabFiles/fn_gfmean.m | 41 + MatlabFiles/fn_gibbsglb.m | 57 + MatlabFiles/fn_gibbsrvar.m | 66 + MatlabFiles/fn_gibbsrvarOldWorks.m | 63 + MatlabFiles/fn_gibbsrvar_setup.m | 58 + MatlabFiles/fn_gradcd.m | 69 + MatlabFiles/fn_gradcd2.m | 82 + MatlabFiles/fn_gyrfore.m | 45 + MatlabFiles/fn_hesscd.m | 65 + MatlabFiles/fn_histpdfcnt.m | 78 + MatlabFiles/fn_histwpdfg.m | 68 + MatlabFiles/fn_histwpdfg2D.m | 118 + MatlabFiles/fn_histwpdfg_bound.m | 69 + MatlabFiles/fn_imc2errgraph.m | 115 + MatlabFiles/fn_imcerrgraph.m | 106 + MatlabFiles/fn_imcerrgraph_scl.m | 105 + MatlabFiles/fn_imcgraph.m | 107 + MatlabFiles/fn_imcgraph_scl.m | 112 + MatlabFiles/fn_impulse.m | 59 + MatlabFiles/fn_irf_var1.m | 34 + MatlabFiles/fn_kalfil_tv.m | 138 + MatlabFiles/fn_kalfil_tv2.m | 147 + MatlabFiles/fn_logsum.m | 21 + MatlabFiles/fn_mimfgraph.m | 135 + MatlabFiles/fn_mseriesgraph.m | 66 + MatlabFiles/fn_msv_sw.m | 62 + MatlabFiles/fn_mtpdf.m | 38 + MatlabFiles/fn_multigraph1.m | 109 + MatlabFiles/fn_multigraph1_ver2.m | 122 + MatlabFiles/fn_multigraph1_ver2_all_labels.m | 127 + MatlabFiles/fn_multigraph2.m | 109 + MatlabFiles/fn_multigraph2_ver2.m | 122 + MatlabFiles/fn_multigraph2_ver2_all_labels.m | 133 + .../fn_multigraph2_ver2_all_labels_dates.m | 141 + MatlabFiles/fn_multigraphn_ver2.m | 158 + MatlabFiles/fn_nmlzvar.m | 92 + MatlabFiles/fn_numstruct2numcell_nummatrix.m | 20 + MatlabFiles/fn_ols.m | 29 + MatlabFiles/fn_printmatrix4tex.m | 38 + MatlabFiles/fn_printmatrix4tex_ver2.m | 48 + MatlabFiles/fn_reset_ini_seed.m | 13 + MatlabFiles/fn_rlrpostr.m | 50 + MatlabFiles/fn_rlrprior.m | 39 + MatlabFiles/fn_rnrprior.m | 224 + MatlabFiles/fn_rnrprior2.m | 220 + MatlabFiles/fn_rnrprior_covres.m | 243 + MatlabFiles/fn_rnrprior_covres_dobs.m | 281 + MatlabFiles/fn_rnrprior_covres_dobs_tv.m | 294 + MatlabFiles/fn_rnrprior_covres_dobs_tv2.m | 309 + MatlabFiles/fn_rnrprior_covres_tv.m | 258 + MatlabFiles/fn_rnrprior_tv.m | 236 + MatlabFiles/fn_seriesgraph.m | 49 + MatlabFiles/fn_simul.m | 26 + MatlabFiles/fn_tran_a2b.m | 25 + MatlabFiles/fn_tran_b2a.m | 24 + MatlabFiles/fn_tran_f2g.m | 26 + MatlabFiles/fn_tran_g2f.m | 25 + MatlabFiles/fn_uncondfcst_var1.m | 28 + MatlabFiles/fn_varoots.m | 30 + MatlabFiles/fn_vds.m | 17 + MatlabFiles/fn_vds_abs.m | 17 + MatlabFiles/fore_cal.m | 251 + MatlabFiles/fore_gh.m | 241 + MatlabFiles/fore_mqy.m | 322 + MatlabFiles/forefixe.m | 30 + MatlabFiles/fshock.m | 28 + MatlabFiles/fsim.m | 33 + MatlabFiles/gactual.m | 181 + MatlabFiles/gaf.m | 88 + MatlabFiles/gaferr1.m | 90 + MatlabFiles/gampar.m | 15 + MatlabFiles/gensys.m | 169 + MatlabFiles/gensysOldVersion.m | 151 + MatlabFiles/gensys_z2.m | 68 + MatlabFiles/gensys_z2new.m | 74 + MatlabFiles/gfmean.m | 49 + MatlabFiles/gfore.m | 86 + MatlabFiles/gforerr1.m | 82 + MatlabFiles/ghistd.m | 77 + MatlabFiles/gradcd.m1 | 53 + MatlabFiles/gshock.m | 71 + MatlabFiles/gstate.m | 96 + MatlabFiles/gyrfore.m | 44 + MatlabFiles/hist2.m | 68 + MatlabFiles/history2.m | 144 + MatlabFiles/histpdfcnt.m | 118 + MatlabFiles/histpdfg.m | 32 + MatlabFiles/histpdfg2D.m | 108 + MatlabFiles/histwpdfg.m | 62 + MatlabFiles/histwpdfg2D.m | 111 + MatlabFiles/imc2errgraph.m | 103 + MatlabFiles/imcerrgraph.m | 59 + MatlabFiles/imcgraph.m | 64 + MatlabFiles/imfsim.m | 330 + MatlabFiles/imfvdscksim.m | 536 + MatlabFiles/impgraphs.m | 56 + MatlabFiles/imrgraph.m | 55 + MatlabFiles/invgamcdf.m | 27 + MatlabFiles/invgampar.m | 11 + MatlabFiles/lcnmean.m | 19 + MatlabFiles/mformd1.m | 54 + MatlabFiles/mnpdf.m | 28 + MatlabFiles/mtpdf.m | 32 + MatlabFiles/nmlzvar.m | 105 + MatlabFiles/normpar.m | 12 + MatlabFiles/nqzdiv.m | 44 + MatlabFiles/numgrad.m | 86 + MatlabFiles/numgradOrig.m | 99 + MatlabFiles/numgradcd.m | 87 + MatlabFiles/ols.m | 28 + MatlabFiles/pathdef.m | 247 + MatlabFiles/pdfforg.m | 37 + MatlabFiles/perr1graph.m | 116 + MatlabFiles/perr2graph.m | 112 + MatlabFiles/phg234.m | 243 + MatlabFiles/phg235.m | 195 + MatlabFiles/pmddf235.m | 204 + MatlabFiles/pmddf236.m | 213 + MatlabFiles/pmddg235.m | 49 + MatlabFiles/pmddg236.m | 50 + MatlabFiles/pmddwf23.m | 197 + MatlabFiles/probvalsec.m | 73 + MatlabFiles/pwf234.m | 208 + MatlabFiles/pwf235.m | 190 + MatlabFiles/qplot2.m | 63 + MatlabFiles/qzdiv.m | 41 + MatlabFiles/qzdivct.m | 70 + MatlabFiles/qzswitch.m | 60 + MatlabFiles/reset_ini_seed.m | 11 + MatlabFiles/rlrpostr.m | 46 + MatlabFiles/rlrprior.m | 39 + MatlabFiles/rnrprior.m | 215 + MatlabFiles/run.m | 3 + MatlabFiles/sbcontest.m | 63 + MatlabFiles/simtanzphi.m | 45 + MatlabFiles/smtplis.m | 45 + MatlabFiles/smtplis2.m | 99 + MatlabFiles/startd.m | 7 + MatlabFiles/startup.m | 27 + MatlabFiles/subtitle.m | 20 + MatlabFiles/suptitle.m | 103 + MatlabFiles/szasbvar.m | 486 + MatlabFiles/szbvar.m | 337 + MatlabFiles/tran_a2b.m | 29 + MatlabFiles/tran_b2a.m | 29 + MatlabFiles/xydata.m | 174 + MatlabFiles/zroot.m | 30 + 362 files changed, 112743 insertions(+) create mode 100755 CFiles/Copy of kalman.c create mode 100755 CFiles/Copy of kalman.h create mode 100755 CFiles/congradmin.c create mode 100755 CFiles/congradmin.h create mode 100755 CFiles/congradminOrigWorks.c create mode 100755 CFiles/congradminOrigWorks.h create mode 100755 CFiles/csminwel.c create mode 100755 CFiles/csminwel.h create mode 100755 CFiles/csminwelOrigWorks.c create mode 100755 CFiles/csminwelOrigWorks.h create mode 100755 CFiles/cstz.c create mode 100755 CFiles/cstz.h create mode 100755 CFiles/cstz_dw.c create mode 100755 CFiles/fn_filesetup.c create mode 100755 CFiles/fn_filesetup.h create mode 100755 CFiles/gensys.c create mode 100755 CFiles/gensys.h create mode 100755 CFiles/gensys01Mar06Works.c create mode 100755 CFiles/gensys01Mar06Works.h create mode 100755 CFiles/gensys08Mar06.c create mode 100755 CFiles/gensysOldVersionWorks.c create mode 100755 CFiles/gensysOldVersionWorks.h create mode 100755 CFiles/gradcd_switch.c create mode 100755 CFiles/gradcd_switch.h create mode 100755 CFiles/kalman.c create mode 100755 CFiles/kalman.h create mode 100755 CFiles/kalmanOldWorks.c create mode 100755 CFiles/kalmanOldWorks.h create mode 100755 CFiles/kalmanOldWorks2.c create mode 100755 CFiles/kalmanOldWorks2.h create mode 100755 CFiles/mathlib.c create mode 100755 CFiles/mathlib.h create mode 100755 CFiles/numgradgenTemplate.c create mode 100755 CFiles/optpackage.c create mode 100755 CFiles/optpackage.h create mode 100755 CFiles/rand.c create mode 100755 CFiles/rand.h create mode 100755 CFiles/template_proj.vcproj create mode 100755 CFiles/template_proj2.vcproj create mode 100755 CFiles/template_proj2_MKL8.0.vcproj create mode 100755 CFiles/template_proj2_MSV2005_MKL9.0.vcproj create mode 100755 CFiles/tzmatlab.c create mode 100755 CFiles/tzmatlab.h create mode 100755 MathematicaFiles/Applications/BayesianDistributions.m create mode 100755 MathematicaFiles/Applications/BinnedKernelDensity.m create mode 100755 MathematicaFiles/Applications/DateFunctions.m create mode 100755 MathematicaFiles/Applications/Difference.m create mode 100755 MathematicaFiles/Applications/DirichletDistribution.m create mode 100755 MathematicaFiles/Applications/DotPlot.m create mode 100755 MathematicaFiles/Applications/EulerSimulate.m create mode 100755 MathematicaFiles/Applications/Eurodollar Data.nb create mode 100755 MathematicaFiles/Applications/EurodollarDataFunctions.m create mode 100755 MathematicaFiles/Applications/GaussianKernel.m create mode 100755 MathematicaFiles/Applications/GenSys.m create mode 100755 MathematicaFiles/Applications/HierarchicalMetropolis.m create mode 100755 MathematicaFiles/Applications/ImportExportBinary.m create mode 100755 MathematicaFiles/Applications/ItosLemma.m create mode 100755 MathematicaFiles/Applications/KalmanFilter.m create mode 100755 MathematicaFiles/Applications/Kernel Configuration.nb create mode 100755 MathematicaFiles/Applications/MaxEntSimplexDistribution.m create mode 100755 MathematicaFiles/Applications/Metropolis.m create mode 100755 MathematicaFiles/Applications/MetropolisMCMC.m create mode 100755 MathematicaFiles/Applications/MetropolisStep.nb create mode 100755 MathematicaFiles/Applications/Metropolis_working.m create mode 100755 MathematicaFiles/Applications/OddsandEnds.m create mode 100755 MathematicaFiles/Applications/PagePrint.m create mode 100755 MathematicaFiles/Applications/Parallel Test.nb create mode 100755 MathematicaFiles/Applications/Parse Eurodollar Data from PDF.nb create mode 100755 MathematicaFiles/Applications/ParticleFilter.m create mode 100755 MathematicaFiles/Applications/ParticleFilter.old create mode 100755 MathematicaFiles/Applications/PenalizedSmooth.m create mode 100755 MathematicaFiles/Applications/PlotEnhancements.m create mode 100755 MathematicaFiles/Applications/RandomNumberGenerators.nb create mode 100755 MathematicaFiles/Applications/RecursivePreferencesPDE.m create mode 100755 MathematicaFiles/Applications/Remaining/TempFiles/Thumbs.db create mode 100755 MathematicaFiles/Applications/ReversibleJumpMetropolis.m create mode 100755 MathematicaFiles/Applications/SmoothedHistogram.m create mode 100755 MathematicaFiles/Applications/StandardNormal.m create mode 100755 MathematicaFiles/Applications/StatisticalStuff.m create mode 100755 MathematicaFiles/Applications/StatisticsEnhancements.m create mode 100755 MathematicaFiles/Applications/The Virtual Mathematica Book (v6).nb create mode 100755 MathematicaFiles/Applications/WriteBriefingFilesWithHeaders.m create mode 100755 MathematicaFiles/Applications/WulfGanglia.m create mode 100755 MathematicaFiles/Applications/ZhaMathematicaLibrary.m create mode 100755 MatlabFiles/A0LHFUN.M create mode 100755 MatlabFiles/A0LHGRAD.M create mode 100755 MatlabFiles/A0lhgh.m create mode 100755 MatlabFiles/BinRead.m create mode 100755 MatlabFiles/BinWrite.m create mode 100755 MatlabFiles/CONTENTS.M create mode 100755 MatlabFiles/CSMINWEL.M0 create mode 100755 MatlabFiles/ERRORS.M create mode 100755 MatlabFiles/ERRORS.OLD create mode 100755 MatlabFiles/ERRORS.m1 create mode 100755 MatlabFiles/ERRORS.sav create mode 100755 MatlabFiles/FORECAST.M create mode 100755 MatlabFiles/Forecasterr.m create mode 100755 MatlabFiles/GENSYSCT.M create mode 100755 MatlabFiles/GIBBSGLB.M create mode 100755 MatlabFiles/GIBBSVAR.M create mode 100755 MatlabFiles/GRADCD.M create mode 100755 MatlabFiles/Gibbsvar.bak create mode 100755 MatlabFiles/HESSCD.M create mode 100755 MatlabFiles/HESSCD.M1 create mode 100755 MatlabFiles/HISTORY.M create mode 100755 MatlabFiles/IMPULSE.OLD create mode 100755 MatlabFiles/IMPULSE.m1 create mode 100755 MatlabFiles/IMPULSEO.M create mode 100755 MatlabFiles/MFORMD.M create mode 100755 MatlabFiles/MSV/MSV_Newton.m create mode 100755 MatlabFiles/MSV/dw_gensys.m create mode 100755 MatlabFiles/MSV/gensys.m create mode 100755 MatlabFiles/MSV/msv_all.m create mode 100755 MatlabFiles/MSV/msv_all_complex.m create mode 100755 MatlabFiles/MSV/msv_complex_AR.m create mode 100755 MatlabFiles/MSV/msv_one.m create mode 100755 MatlabFiles/MSV/msv_simple.m create mode 100755 MatlabFiles/MSV/qzcomputesolution.m create mode 100755 MatlabFiles/MSV/qzdiv.m create mode 100755 MatlabFiles/MSV/qzmoveindex.m create mode 100755 MatlabFiles/MSV/qzslide.m create mode 100755 MatlabFiles/MSV/qzsort.m create mode 100755 MatlabFiles/MSV/qzswitch.m create mode 100755 MatlabFiles/MSV/test_gensys.m create mode 100755 MatlabFiles/PHG233.M create mode 100755 MatlabFiles/PMDDF233.M create mode 100755 MatlabFiles/PMDDF234.M create mode 100755 MatlabFiles/PMDDG233.M create mode 100755 MatlabFiles/PMDDG234.M create mode 100755 MatlabFiles/PWF233.M create mode 100755 MatlabFiles/SRestrictRWZalg.m create mode 100755 MatlabFiles/SYE.M create mode 100755 MatlabFiles/SYED.M create mode 100755 MatlabFiles/Smtplis2seq.m create mode 100755 MatlabFiles/ZIMPULSE.M create mode 100755 MatlabFiles/a0asfun.m create mode 100755 MatlabFiles/a0asgrad.m create mode 100755 MatlabFiles/a0freefun.m create mode 100755 MatlabFiles/a0freegrad.m create mode 100755 MatlabFiles/a0impsmp.m create mode 100755 MatlabFiles/a0onlysim.m create mode 100755 MatlabFiles/adapt.m create mode 100755 MatlabFiles/adaptstp.m create mode 100755 MatlabFiles/betapar.m create mode 100755 MatlabFiles/bfgsi.m create mode 100755 MatlabFiles/bfgsi.m0 create mode 100755 MatlabFiles/bfgsi.m1 create mode 100755 MatlabFiles/calyrqm.m create mode 100755 MatlabFiles/cfore.m create mode 100755 MatlabFiles/chol2.m create mode 100755 MatlabFiles/clgls.m create mode 100755 MatlabFiles/clmonq.m create mode 100755 MatlabFiles/csminit.m create mode 100755 MatlabFiles/csminit.m0 create mode 100755 MatlabFiles/csminit.m1 create mode 100755 MatlabFiles/csminit.m2 create mode 100755 MatlabFiles/csminitWorksUntiil0205.m create mode 100755 MatlabFiles/csminwel.m create mode 100755 MatlabFiles/csminwel.m1 create mode 100755 MatlabFiles/csminwel.m2 create mode 100755 MatlabFiles/datactcon.m create mode 100755 MatlabFiles/dataext.m create mode 100755 MatlabFiles/datana.m create mode 100755 MatlabFiles/dataxy.m create mode 100755 MatlabFiles/demarcate.m create mode 100755 MatlabFiles/demarw.m create mode 100755 MatlabFiles/dlrpostr.m create mode 100755 MatlabFiles/eigsort.m create mode 100755 MatlabFiles/ellipse.m create mode 100755 MatlabFiles/empdfsort.m create mode 100755 MatlabFiles/fcstidcnd.m create mode 100755 MatlabFiles/fcstidcnd2.m create mode 100755 MatlabFiles/fidcnderr.m create mode 100755 MatlabFiles/fidcndexa.m create mode 100755 MatlabFiles/fidencond.m create mode 100755 MatlabFiles/find_betapar.m create mode 100755 MatlabFiles/find_gampar.m create mode 100755 MatlabFiles/find_invgampar.m create mode 100755 MatlabFiles/find_normpar.m create mode 100755 MatlabFiles/fn_PlotRecessionShades57_01.m create mode 100644 MatlabFiles/fn_PosteriorVarianceDecomposition.m create mode 100755 MatlabFiles/fn_ReadRecessionDates57_01.m create mode 100755 MatlabFiles/fn_a0cfreefun_tv.m create mode 100755 MatlabFiles/fn_a0cfreegrad_tv.m create mode 100755 MatlabFiles/fn_a0freefun.m create mode 100755 MatlabFiles/fn_a0freegrad.m create mode 100755 MatlabFiles/fn_a0sfreefun.m create mode 100755 MatlabFiles/fn_a0sfreefun2.m create mode 100755 MatlabFiles/fn_a0sfreegrad.m create mode 100755 MatlabFiles/fn_a0sfreegrad2.m create mode 100755 MatlabFiles/fn_calyrqm.m create mode 100755 MatlabFiles/fn_construct_cov.m create mode 100755 MatlabFiles/fn_corr.m create mode 100755 MatlabFiles/fn_dataext.m create mode 100755 MatlabFiles/fn_dataext2.m create mode 100755 MatlabFiles/fn_datana.m create mode 100755 MatlabFiles/fn_datana2.m create mode 100755 MatlabFiles/fn_dataxy.m create mode 100755 MatlabFiles/fn_dataxy7982.m create mode 100755 MatlabFiles/fn_dataxyOldVer.m create mode 100755 MatlabFiles/fn_demarw.m create mode 100755 MatlabFiles/fn_dirichprior.m create mode 100755 MatlabFiles/fn_dlrpostr.m create mode 100755 MatlabFiles/fn_empdfsort.m create mode 100755 MatlabFiles/fn_ergodp.m create mode 100755 MatlabFiles/fn_fcstcnd.m create mode 100755 MatlabFiles/fn_fcstidcnd.m create mode 100755 MatlabFiles/fn_fcstidcnd2.m create mode 100755 MatlabFiles/fn_forecast.m create mode 100755 MatlabFiles/fn_forecastfixe.m create mode 100755 MatlabFiles/fn_forecastsim.m create mode 100755 MatlabFiles/fn_foregraph.m create mode 100755 MatlabFiles/fn_forerrgraph.m create mode 100755 MatlabFiles/fn_fprintmatrix.m create mode 100755 MatlabFiles/fn_fprintvector.m create mode 100755 MatlabFiles/fn_gfmean.m create mode 100755 MatlabFiles/fn_gibbsglb.m create mode 100755 MatlabFiles/fn_gibbsrvar.m create mode 100755 MatlabFiles/fn_gibbsrvarOldWorks.m create mode 100755 MatlabFiles/fn_gibbsrvar_setup.m create mode 100755 MatlabFiles/fn_gradcd.m create mode 100755 MatlabFiles/fn_gradcd2.m create mode 100755 MatlabFiles/fn_gyrfore.m create mode 100755 MatlabFiles/fn_hesscd.m create mode 100755 MatlabFiles/fn_histpdfcnt.m create mode 100755 MatlabFiles/fn_histwpdfg.m create mode 100755 MatlabFiles/fn_histwpdfg2D.m create mode 100755 MatlabFiles/fn_histwpdfg_bound.m create mode 100755 MatlabFiles/fn_imc2errgraph.m create mode 100755 MatlabFiles/fn_imcerrgraph.m create mode 100755 MatlabFiles/fn_imcerrgraph_scl.m create mode 100755 MatlabFiles/fn_imcgraph.m create mode 100755 MatlabFiles/fn_imcgraph_scl.m create mode 100755 MatlabFiles/fn_impulse.m create mode 100755 MatlabFiles/fn_irf_var1.m create mode 100755 MatlabFiles/fn_kalfil_tv.m create mode 100755 MatlabFiles/fn_kalfil_tv2.m create mode 100755 MatlabFiles/fn_logsum.m create mode 100755 MatlabFiles/fn_mimfgraph.m create mode 100755 MatlabFiles/fn_mseriesgraph.m create mode 100755 MatlabFiles/fn_msv_sw.m create mode 100755 MatlabFiles/fn_mtpdf.m create mode 100755 MatlabFiles/fn_multigraph1.m create mode 100755 MatlabFiles/fn_multigraph1_ver2.m create mode 100755 MatlabFiles/fn_multigraph1_ver2_all_labels.m create mode 100755 MatlabFiles/fn_multigraph2.m create mode 100755 MatlabFiles/fn_multigraph2_ver2.m create mode 100755 MatlabFiles/fn_multigraph2_ver2_all_labels.m create mode 100755 MatlabFiles/fn_multigraph2_ver2_all_labels_dates.m create mode 100755 MatlabFiles/fn_multigraphn_ver2.m create mode 100755 MatlabFiles/fn_nmlzvar.m create mode 100644 MatlabFiles/fn_numstruct2numcell_nummatrix.m create mode 100755 MatlabFiles/fn_ols.m create mode 100755 MatlabFiles/fn_printmatrix4tex.m create mode 100755 MatlabFiles/fn_printmatrix4tex_ver2.m create mode 100755 MatlabFiles/fn_reset_ini_seed.m create mode 100755 MatlabFiles/fn_rlrpostr.m create mode 100755 MatlabFiles/fn_rlrprior.m create mode 100755 MatlabFiles/fn_rnrprior.m create mode 100755 MatlabFiles/fn_rnrprior2.m create mode 100755 MatlabFiles/fn_rnrprior_covres.m create mode 100755 MatlabFiles/fn_rnrprior_covres_dobs.m create mode 100755 MatlabFiles/fn_rnrprior_covres_dobs_tv.m create mode 100755 MatlabFiles/fn_rnrprior_covres_dobs_tv2.m create mode 100755 MatlabFiles/fn_rnrprior_covres_tv.m create mode 100755 MatlabFiles/fn_rnrprior_tv.m create mode 100755 MatlabFiles/fn_seriesgraph.m create mode 100755 MatlabFiles/fn_simul.m create mode 100755 MatlabFiles/fn_tran_a2b.m create mode 100755 MatlabFiles/fn_tran_b2a.m create mode 100755 MatlabFiles/fn_tran_f2g.m create mode 100755 MatlabFiles/fn_tran_g2f.m create mode 100755 MatlabFiles/fn_uncondfcst_var1.m create mode 100755 MatlabFiles/fn_varoots.m create mode 100755 MatlabFiles/fn_vds.m create mode 100755 MatlabFiles/fn_vds_abs.m create mode 100755 MatlabFiles/fore_cal.m create mode 100755 MatlabFiles/fore_gh.m create mode 100755 MatlabFiles/fore_mqy.m create mode 100755 MatlabFiles/forefixe.m create mode 100755 MatlabFiles/fshock.m create mode 100755 MatlabFiles/fsim.m create mode 100755 MatlabFiles/gactual.m create mode 100755 MatlabFiles/gaf.m create mode 100755 MatlabFiles/gaferr1.m create mode 100755 MatlabFiles/gampar.m create mode 100755 MatlabFiles/gensys.m create mode 100755 MatlabFiles/gensysOldVersion.m create mode 100755 MatlabFiles/gensys_z2.m create mode 100755 MatlabFiles/gensys_z2new.m create mode 100755 MatlabFiles/gfmean.m create mode 100755 MatlabFiles/gfore.m create mode 100755 MatlabFiles/gforerr1.m create mode 100755 MatlabFiles/ghistd.m create mode 100755 MatlabFiles/gradcd.m1 create mode 100755 MatlabFiles/gshock.m create mode 100755 MatlabFiles/gstate.m create mode 100755 MatlabFiles/gyrfore.m create mode 100755 MatlabFiles/hist2.m create mode 100755 MatlabFiles/history2.m create mode 100755 MatlabFiles/histpdfcnt.m create mode 100755 MatlabFiles/histpdfg.m create mode 100755 MatlabFiles/histpdfg2D.m create mode 100755 MatlabFiles/histwpdfg.m create mode 100755 MatlabFiles/histwpdfg2D.m create mode 100755 MatlabFiles/imc2errgraph.m create mode 100755 MatlabFiles/imcerrgraph.m create mode 100755 MatlabFiles/imcgraph.m create mode 100755 MatlabFiles/imfsim.m create mode 100755 MatlabFiles/imfvdscksim.m create mode 100755 MatlabFiles/impgraphs.m create mode 100755 MatlabFiles/imrgraph.m create mode 100755 MatlabFiles/invgamcdf.m create mode 100755 MatlabFiles/invgampar.m create mode 100755 MatlabFiles/lcnmean.m create mode 100755 MatlabFiles/mformd1.m create mode 100755 MatlabFiles/mnpdf.m create mode 100755 MatlabFiles/mtpdf.m create mode 100755 MatlabFiles/nmlzvar.m create mode 100755 MatlabFiles/normpar.m create mode 100755 MatlabFiles/nqzdiv.m create mode 100755 MatlabFiles/numgrad.m create mode 100755 MatlabFiles/numgradOrig.m create mode 100755 MatlabFiles/numgradcd.m create mode 100755 MatlabFiles/ols.m create mode 100644 MatlabFiles/pathdef.m create mode 100755 MatlabFiles/pdfforg.m create mode 100755 MatlabFiles/perr1graph.m create mode 100755 MatlabFiles/perr2graph.m create mode 100755 MatlabFiles/phg234.m create mode 100755 MatlabFiles/phg235.m create mode 100755 MatlabFiles/pmddf235.m create mode 100755 MatlabFiles/pmddf236.m create mode 100755 MatlabFiles/pmddg235.m create mode 100755 MatlabFiles/pmddg236.m create mode 100755 MatlabFiles/pmddwf23.m create mode 100755 MatlabFiles/probvalsec.m create mode 100755 MatlabFiles/pwf234.m create mode 100755 MatlabFiles/pwf235.m create mode 100755 MatlabFiles/qplot2.m create mode 100755 MatlabFiles/qzdiv.m create mode 100755 MatlabFiles/qzdivct.m create mode 100755 MatlabFiles/qzswitch.m create mode 100755 MatlabFiles/reset_ini_seed.m create mode 100755 MatlabFiles/rlrpostr.m create mode 100755 MatlabFiles/rlrprior.m create mode 100755 MatlabFiles/rnrprior.m create mode 100755 MatlabFiles/run.m create mode 100755 MatlabFiles/sbcontest.m create mode 100755 MatlabFiles/simtanzphi.m create mode 100755 MatlabFiles/smtplis.m create mode 100755 MatlabFiles/smtplis2.m create mode 100755 MatlabFiles/startd.m create mode 100755 MatlabFiles/startup.m create mode 100755 MatlabFiles/subtitle.m create mode 100755 MatlabFiles/suptitle.m create mode 100755 MatlabFiles/szasbvar.m create mode 100755 MatlabFiles/szbvar.m create mode 100755 MatlabFiles/tran_a2b.m create mode 100755 MatlabFiles/tran_b2a.m create mode 100755 MatlabFiles/xydata.m create mode 100755 MatlabFiles/zroot.m diff --git a/CFiles/Copy of kalman.c b/CFiles/Copy of kalman.c new file mode 100755 index 0000000..b53d44e --- /dev/null +++ b/CFiles/Copy of kalman.c @@ -0,0 +1,2751 @@ +/*=============================================================================================================== + * Check $$$ for important notes. + * Check <<>> for updating DW's new switch code or questions for DW. + * + * kalcvf_urw(): the Kalman filter forward prediction specialized for only a univariate random walk (urw) process. + * + * State space model is defined as follows: + * z(t+1) = z(t)+eta(t) (state or transition equation) + * y(t) = x(t)'*z(t)+eps(t) (observation or measurement equation) + * where for this function, eta and eps must be uncorrelated; y(t) must be 1-by-1. Note that + * x(t): k-by-1; + * z(t): k-by-1; + * eps(t): 1-by-1 and ~ N(0, sigma^2); + * eta(t): ~ N(0, V) where V is a k-by-k covariance matrix. + * + * + * Written by Tao Zha, May 2004. + * Revised, May 2008; +=================================================================================================================*/ + +/** +//=== For debugging purpose. +if (1) +{ + double t_loglht; + + t_loglht = -(0.5*ny)*LOG2PI - 0.5*logdeterminant(Dtdata_dm) - 0.5*VectorDotVector(wny_dv, etdata_dv); + fprintf(FPTR_DEBUG, " %10.5f\n", t_loglht); + + fprintf(FPTR_DEBUG, "%%st=%d, inpt=%d, and sti=%d\n", st, inpt, sti); + + fprintf(FPTR_DEBUG, "\n wP0_dv:\n"); + WriteVector(FPTR_DEBUG, wP0_dv, " %10.5f "); + fprintf(FPTR_DEBUG, "\n Vt_dc->C[sti_v=%d]:\n", sti_v); + WriteMatrix(FPTR_DEBUG, Vt_dc->C[sti_v], " %10.5f "); + + fflush(FPTR_DEBUG); +} +/**/ + + +#include "kalman.h" + + +static int Update_et_Dt_1stapp(int t_1, struct TSkalfilmsinputs_1stapp_tag *kalfilmsinputs_1stapp_ps); +static int Updatekalfilms_1stapp(int inpt, struct TSkalfilmsinputs_1stapp_tag *kalfilmsinputs_1stapp_ps, struct TStateModel_tag *smodel_ps); + + +TSkalcvfurw *CreateTSkalcvfurw(TFlearninguni *func, int T, int k, int tv) //, int storeZ, int storeV) +{ + int _i; + //=== + TSivector *rows_iv = NULL; + TSivector *cols_iv = NULL; + //--- + TSkalcvfurw *kalcvfurw_ps = tzMalloc(1, TSkalcvfurw); + + + kalcvfurw_ps->indx_tvsigmasq = tv; + kalcvfurw_ps->fss = T; + kalcvfurw_ps->kx = k; + + //=== + kalcvfurw_ps->V_dm = CreateMatrix_lf(k, k); + kalcvfurw_ps->ylhtran_dv = CreateVector_lf(T); + kalcvfurw_ps->Xrhtran_dm = CreateMatrix_lf(k, T); + kalcvfurw_ps->z10_dv = CreateVector_lf(k); + kalcvfurw_ps->P10_dm = CreateMatrix_lf(k, k); + + kalcvfurw_ps->zupdate_dv = CreateVector_lf(k); + kalcvfurw_ps->Zpredtran_dm = CreateMatrix_lf(k, T); + kalcvfurw_ps->ylhtranpred_dv = CreateVector_lf(T); + // + rows_iv = CreateVector_int(T); + cols_iv = CreateVector_int(T); + for (_i=T-1; _i>=0; _i--) rows_iv->v[_i] = cols_iv->v[_i] = k; + kalcvfurw_ps->Ppred_dc = CreateCell_lf(rows_iv, cols_iv); + // if (!storeZ) kalcvfurw_ps->Zpredtran_dm = (TSdmatrix *)NULL; + // else kalcvfurw_ps->Zpredtran_dm = CreateMatrix_lf(k, T); + // if (!storeV) kalcvfurw_ps->Ppred_dc = (TSdcell *)NULL; + // else { + // rows_iv = CreateVector_int(T); + // cols_iv = CreateVector_int(T); + // for (_i=T; _i>=0; _i--) rows_iv->v[_i] = cols_iv->v[_i] = k; + // kalcvfurw_ps->Ppred_dc = CreateCell_lf(rows_iv, cols_iv); + // } + + DestroyVector_int(rows_iv); + DestroyVector_int(cols_iv); + return (kalcvfurw_ps); +} + +TSkalcvfurw *DestroyTSkalcvfurw(TSkalcvfurw *kalcvfurw_ps) +{ + if (kalcvfurw_ps) { + DestroyMatrix_lf(kalcvfurw_ps->V_dm); + DestroyVector_lf(kalcvfurw_ps->ylhtran_dv); + DestroyMatrix_lf(kalcvfurw_ps->Xrhtran_dm); + DestroyVector_lf(kalcvfurw_ps->z10_dv); + DestroyMatrix_lf(kalcvfurw_ps->P10_dm); + + DestroyVector_lf(kalcvfurw_ps->zupdate_dv); + DestroyMatrix_lf(kalcvfurw_ps->Zpredtran_dm); + DestroyCell_lf(kalcvfurw_ps->Ppred_dc); + DestroyVector_lf(kalcvfurw_ps->ylhtranpred_dv); + + free(kalcvfurw_ps); + return ((TSkalcvfurw *)NULL); + } + else return (kalcvfurw_ps); +} + + +void kalcvf_urw(TSkalcvfurw *kalcvfurw_ps, void *dummy_ps) +{ + //See the notes of SWZ regarding the government's updating of the parameters in their Phillips-curve equation. + //NOTE: make sure that the value of kalcvfurw_ps->sigmasq and other input values are given. + int ti; + double workd, workdenominv; + //--- + int fss, kx; + double sigmasq_fix = kalcvfurw_ps->sigmasq; +// double sigmasq; + TSdmatrix *V_dm; + TSdmatrix *Zpredtran_dm; + TSdcell *Ppred_dc; + TSdvector *ylhtran_dv; + TSdmatrix *Xrhtran_dm; + //=== + TSdvector *workkxby1_dv = NULL; //kx-by-1. +// TSdvector *work1kxby1_dv = NULL; //kx-by-1. + TSdmatrix *workkxbykx_dm = NULL; //kx-by-kx symmetric and positive positive. +// //=== +// TSdvector *zbefore_dv = CreateVector_lf(kalcvfurw_ps->kx); +// TSdmatrix *Vbefore_dm = CreateMatrix_lf(kalcvfurw_ps->kx, kalcvfurw_ps->kx); +// TSdvector *zafter_dv = CreateVector_lf(kalcvfurw_ps->kx); +// TSdmatrix *Vafter_dm = CreateMatrix_lf(kalcvfurw_ps->kx, kalcvfurw_ps->kx); + //******* WARNING: Some dangerous pointer movement to gain efficiency ******* +// double *yt_p; +// double *Vbefore_p; +// double *Vafter_p; + TSdvector xt_sdv; + TSdvector zbefore_sdv; + //TSdmatrix Vbefore_sdm; + TSdvector zafter_sdv; + //TSdmatrix Vafter_sdm; + + + if (!kalcvfurw_ps) fn_DisplayError(".../kalcvf_urw(): the input argument kalcvfurw_ps must be created"); + if (!kalcvfurw_ps->V_dm || !kalcvfurw_ps->ylhtran_dv || !kalcvfurw_ps->Xrhtran_dm || !kalcvfurw_ps->z10_dv || !kalcvfurw_ps->P10_dm) + fn_DisplayError(".../kalcvf_urw(): input arguments kalcvfurw_ps->V_dm, kalcvfurw_ps->ylhtran_dv, kalcvfurw_ps->Xrhtran_dm, kalcvfurw_ps->z10_dv, kalcvfurw_ps->P10_dm must be given legal values"); + if (!(kalcvfurw_ps->P10_dm->flag & (M_SU | M_SL))) fn_DisplayError(".../kalcvf_urw(): the input argument kalcvfurw_ps->P10_dm must be symmetric"); + fss = kalcvfurw_ps->fss; + kx = kalcvfurw_ps->kx; + V_dm = kalcvfurw_ps->V_dm; + Zpredtran_dm = kalcvfurw_ps->Zpredtran_dm; + Ppred_dc = kalcvfurw_ps->Ppred_dc; + ylhtran_dv = kalcvfurw_ps->ylhtran_dv; + Xrhtran_dm = kalcvfurw_ps->Xrhtran_dm; + //--- + xt_sdv.n = kx; + xt_sdv.flag = V_DEF; + zbefore_sdv.n = kx; + zbefore_sdv.flag = V_DEF; + zafter_sdv.n = kx; + zafter_sdv.flag = V_DEF; + + //=== Memory allocation. + workkxby1_dv = CreateVector_lf(kx); + workkxbykx_dm = CreateMatrix_lf(kx, kx); + + + //------- The first period (ti=0). ------- + zbefore_sdv.v = kalcvfurw_ps->z10_dv->v; + zafter_sdv.v = Zpredtran_dm->M; + xt_sdv.v = Xrhtran_dm->M; + //--- + + workd = ylhtran_dv->v[0] - (kalcvfurw_ps->ylhtranpred_dv->v[0]=VectorDotVector(&xt_sdv, &zbefore_sdv)); //y_t - x_t'*z_{t-1}. + SymmatrixTimesVector(workkxby1_dv, kalcvfurw_ps->P10_dm, &xt_sdv, 1.0, 0.0); //P_{t|t-1} x_t; + + if (!kalcvfurw_ps->indx_tvsigmasq) + workdenominv = 1.0/(sigmasq_fix + VectorDotVector(&xt_sdv, workkxby1_dv)); //1/[sigma^2 + x_t' P_{t|t-1} x_t] + else if (kalcvfurw_ps->indx_tvsigmasq == 1) //See pp.37 and 37a in SWZ Learning NOTES. + workdenominv = 1.0/(sigmasq_fix*square(kalcvfurw_ps->z10_dv->v[0]) + VectorDotVector(&xt_sdv, workkxby1_dv)); //1/[sigma^2 + x_t' P_{t|t-1} x_t]; + else { + printf(".../kalman.c/kalcvf_urw(): Have not got time to deal with kalcvfurw_ps->indx_tvsigmasq defined in kalman.h other than 0 or 1"); + exit(EXIT_FAILURE); + } + + + //--- Updating z_{t+1|t}. + CopyVector0(&zafter_sdv, &zbefore_sdv); + VectorPlusMinusVectorUpdate(&zafter_sdv, workkxby1_dv, workd*workdenominv); //z_{t+1|t} = z_{t|t-1} + P_{t|t-1} x_t [y_t - x_t'*z_{t-1}] / [sigma^2 + x_t' P_{t|t-1} x_t]; + //--- Updating P_{t+1|t}. + CopyMatrix0(workkxbykx_dm, V_dm); + VectorTimesSelf(workkxbykx_dm, workkxby1_dv, -workdenominv, 1.0, (V_dm->flag & M_SU) ? 'U' : 'L'); + // - P_{t|t-1}*x_t * xt'*P_{t|t-1} / [sigma^2 + x_t' P_{t|t-1} x_t] + V; + MatrixPlusMatrix(Ppred_dc->C[0], kalcvfurw_ps->P10_dm, workkxbykx_dm); + //P_{t|t-1} - P_{t|t-1}*x_t * xt'*P_{t|t-1} / [sigma^2 + x_t' P_{t|t-1} x_t] + V; + Ppred_dc->C[0]->flag = M_GE | M_SU | M_SL; //This is necessary because if P10_dm is initialized as diagonal, it will have M_GE | M_SU | M_SL | M_UT | M_LT, + // which is no longer true for workkxbykx_dm and therefore gives Ppred_dc->C[0] with M_GE only as a result of MatrixPlusMatrix(). + //Done with all work* arrays. + + //------- The rest of the periods (ti=1:T-1). ------- + for (ti=1; ti<fss; ti++) { + //NOTE: ti=0 has been taken care of outside of this loop. + zbefore_sdv.v = Zpredtran_dm->M + (ti-1)*kx; + zafter_sdv.v = Zpredtran_dm->M + ti*kx; + xt_sdv.v = Xrhtran_dm->M + ti*kx; + //--- + workd = ylhtran_dv->v[ti] - (kalcvfurw_ps->ylhtranpred_dv->v[ti]=VectorDotVector(&xt_sdv, &zbefore_sdv)); //y_t - x_t'*z_{t-1}. + SymmatrixTimesVector(workkxby1_dv, Ppred_dc->C[ti-1], &xt_sdv, 1.0, 0.0); //P_{t|t-1} x_t; + if (!kalcvfurw_ps->indx_tvsigmasq) + workdenominv = 1.0/(sigmasq_fix + VectorDotVector(&xt_sdv, workkxby1_dv)); //1/[sigma^2 + x_t' P_{t|t-1} x_t] + else if (kalcvfurw_ps->indx_tvsigmasq == 1) //See pp.37 and 37a in SWZ Learning NOTES. + workdenominv = 1.0/(sigmasq_fix*square(zbefore_sdv.v[0]) + VectorDotVector(&xt_sdv, workkxby1_dv)); //1/[sigma^2 + x_t' P_{t|t-1} x_t] + else { + printf(".../kalman.c/kalcvf_urw(): Have not got time to deal with kalcvfurw_ps->indx_tvsigmasq defined in kalman.h other than 0 or 1"); + exit(EXIT_FAILURE); + } + //--- Updating z_{t+1|t}. + CopyVector0(&zafter_sdv, &zbefore_sdv); + VectorPlusMinusVectorUpdate(&zafter_sdv, workkxby1_dv, workd*workdenominv); //z_{t+1|t} = z_{t|t-1} + P_{t|t-1} x_t [y_t - x_t'*z_{t-1}] / [sigma^2 + x_t' P_{t|t-1} x_t]; + //--- Updating P_{t+1|t}. + CopyMatrix0(workkxbykx_dm, V_dm); + VectorTimesSelf(workkxbykx_dm, workkxby1_dv, -workdenominv, 1.0, (V_dm->flag & M_SU) ? 'U' : 'L'); + // - P_{t|t-1}*x_t * xt'*P_{t|t-1} / [sigma^2 + x_t' P_{t|t-1} x_t] + V; + MatrixPlusMatrix(Ppred_dc->C[ti], Ppred_dc->C[ti-1], workkxbykx_dm); + //P_{t|t-1} - P_{t|t-1}*x_t * xt'*P_{t|t-1} / [sigma^2 + x_t' P_{t|t-1} x_t] + V; + Ppred_dc->C[ti]->flag = M_GE | M_SU | M_SL; //This is necessary because if P10_dm is initialized as diagonal, it will have M_GE | M_SU | M_SL | M_UT | M_LT, + // which is no longer true for workkxbykx_dm and therefore gives Ppred_dc->C[0] with M_GE only as a result of MatrixPlusMatrix(). + //Done with all work* arrays. + } + CopyVector0(kalcvfurw_ps->zupdate_dv, &zafter_sdv); + Zpredtran_dm->flag = M_GE; + kalcvfurw_ps->ylhtranpred_dv->flag = V_DEF; + +// DestroyVector_lf(zbefore_dv); +// DestroyMatrix_lf(Vbefore_dm); +// DestroyVector_lf(zafter_dv); +// DestroyMatrix_lf(Vafter_dm); + + DestroyVector_lf(workkxby1_dv); +// DestroyVector_lf(work1kxby1_dv); + DestroyMatrix_lf(workkxbykx_dm); +} + + + +//----------------------------------------------------------------------------------------------------------------------- +//-- General constant (known-time-varying) Kalman filter for DSGE models. +//----------------------------------------------------------------------------------------------------------------------- +struct TSkalfiltv_tag *CreateTSkalfiltv(int ny, int nz, int T) +{ + int _i; + //=== + TSivector *rows_iv = CreateVector_int(T); + TSivector *cols_iv = CreateVector_int(T); + //~~~ Creating the structure and initializing the NULL pointers. + struct TSkalfiltv_tag *kalfiltv_ps = tzMalloc(1, struct TSkalfiltv_tag); + + + //--- Default value. + kalfiltv_ps->indxIni = 0; //1: using the initial condition with zt_tm1(:,1)=z0 and Pt_tm1(:,:,1)=P0; + //0: using the unconditional mean for any given regime at time 0. + //--- Other assignments. + kalfiltv_ps->ny = ny; + kalfiltv_ps->nz = nz; + kalfiltv_ps->T = T; + + + + //--------- Creates memory and assigns values. The order matters. + kalfiltv_ps->yt_dm = CreateMatrix_lf(ny, T); + kalfiltv_ps->at_dm = CreateMatrix_lf(ny, T); + // + for (_i=T-1; _i>=0; _i--) + { + rows_iv->v[_i] = ny; + cols_iv->v[_i] = nz; + } + rows_iv->flag = cols_iv->flag = V_DEF; + kalfiltv_ps->Ht_dc = CreateCell_lf(rows_iv, cols_iv); + // + for (_i=T-1; _i>=0; _i--) + { + rows_iv->v[_i] = ny; + cols_iv->v[_i] = ny; + } + kalfiltv_ps->Rt_dc = CreateCell_lf(rows_iv, cols_iv); + // + for (_i=T-1; _i>=0; _i--) + { + rows_iv->v[_i] = nz; + cols_iv->v[_i] = ny; + } + kalfiltv_ps->Gt_dc = CreateCell_lf(rows_iv, cols_iv); + // + kalfiltv_ps->bt_dm = CreateMatrix_lf(nz, T); + // + for (_i=T-1; _i>=0; _i--) + { + rows_iv->v[_i] = nz; + cols_iv->v[_i] = nz; + } + kalfiltv_ps->Ft_dc = CreateCell_lf(rows_iv, cols_iv); + kalfiltv_ps->Vt_dc = CreateCell_lf(rows_iv, cols_iv); + // + kalfiltv_ps->z0_dv = CreateVector_lf(nz); + kalfiltv_ps->P0_dm = CreateMatrix_lf(nz, nz); + + + //--- + kalfiltv_ps->zt_tm1_dm = CreateMatrix_lf(nz, T); + for (_i=T-1; _i>=0; _i--) + { + rows_iv->v[_i] = nz; + cols_iv->v[_i] = nz; + } + kalfiltv_ps->Pt_tm1_dc = CreateCell_lf(rows_iv, cols_iv); + + + //=== + DestroyVector_int(rows_iv); + DestroyVector_int(cols_iv); + + return (kalfiltv_ps); + +} +//--- +struct TSkalfiltv_tag *DestroyTSkalfiltv(struct TSkalfiltv_tag *kalfiltv_ps) +{ + if (kalfiltv_ps) + { + //=== The order matters! + DestroyMatrix_lf(kalfiltv_ps->yt_dm); + DestroyMatrix_lf(kalfiltv_ps->at_dm); + DestroyCell_lf(kalfiltv_ps->Ht_dc); + DestroyCell_lf(kalfiltv_ps->Rt_dc); + DestroyCell_lf(kalfiltv_ps->Gt_dc); + //--- + DestroyMatrix_lf(kalfiltv_ps->bt_dm); + DestroyCell_lf(kalfiltv_ps->Ft_dc); + DestroyCell_lf(kalfiltv_ps->Vt_dc); + //--- + DestroyVector_lf(kalfiltv_ps->z0_dv); + DestroyMatrix_lf(kalfiltv_ps->P0_dm); + //--- + DestroyMatrix_lf(kalfiltv_ps->zt_tm1_dm); + DestroyCell_lf(kalfiltv_ps->Pt_tm1_dc); + + + //--- + tzDestroy(kalfiltv_ps); //Must be freed last! + + return ((struct TSkalfiltv_tag *)NULL); + } + else return (kalfiltv_ps); +}; + + +//----------------------------------------------------------------------------------------------------------------------- +//-- Inputs for filter for Markov-switching DSGE models at any time t. +//----------------------------------------------------------------------------------------------------------------------- +struct TSkalfilmsinputs_1stapp_tag *CreateTSkalfilmsinputs_1stapp(int ny, int nz, int nst, int T) +{ + //~~~ Creating the structure and initializing the NULL pointers. + struct TSkalfilmsinputs_1stapp_tag *kalfilmsinputs_1stapp_ps = tzMalloc(1, struct TSkalfilmsinputs_1stapp_tag); + + //=== + TSivector *rows_iv = NULL; + TSivector *cols_iv = NULL; + + //=== Default value. + kalfilmsinputs_1stapp_ps->indxIni = 0; //1: using the initial condition with zt_tm1(:,1)=z0 and Pt_tm1(:,:,1)=P0; + //0: using the unconditional mean for any given regime at time 0. + kalfilmsinputs_1stapp_ps->indxDiffuse = 1; //1: using the diffuse condition for z_{1|0} and P_{1|0} (default option), according to Koopman and Durbin, "Filtering and Smoothing of State Vector for Diffuse State-Space Models," J. of Time Series Analysis, Vol 24(1), pp.85-99. + //0: using the unconditional moments. + kalfilmsinputs_1stapp_ps->DiffuseScale = 100.0; + kalfilmsinputs_1stapp_ps->ztm1_track = -1; + kalfilmsinputs_1stapp_ps->dtm1_track = -1; + + //--- Other key assignments. + kalfilmsinputs_1stapp_ps->ny = ny; + kalfilmsinputs_1stapp_ps->nz = nz; + kalfilmsinputs_1stapp_ps->nst = nst; + kalfilmsinputs_1stapp_ps->T = T; + + //--------- Creates memory and assigns values. The order matters. + kalfilmsinputs_1stapp_ps->yt_dm = CreateMatrix_lf(ny, T); + kalfilmsinputs_1stapp_ps->at_dm = CreateMatrix_lf(ny, nst); + // + rows_iv = CreateConstantVector_int(nst, ny); + cols_iv = CreateConstantVector_int(nst, nz); + kalfilmsinputs_1stapp_ps->Ht_dc = CreateCell_lf(rows_iv, cols_iv); + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + // + rows_iv = CreateConstantVector_int(nst, ny); + cols_iv = CreateConstantVector_int(nst, ny); + kalfilmsinputs_1stapp_ps->Rt_dc = CreateCell_lf(rows_iv, cols_iv); + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + // + rows_iv = CreateConstantVector_int(nst, nz); + cols_iv = CreateConstantVector_int(nst, ny); + kalfilmsinputs_1stapp_ps->Gt_dc = CreateCell_lf(rows_iv, cols_iv); + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + // + kalfilmsinputs_1stapp_ps->bt_dm = CreateMatrix_lf(nz, nst); + // + rows_iv = CreateConstantVector_int(nst, nz); + cols_iv = CreateConstantVector_int(nst, nz); + kalfilmsinputs_1stapp_ps->Ft_dc = CreateCell_lf(rows_iv, cols_iv); + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + // + rows_iv = CreateConstantVector_int(nst, nz); + cols_iv = CreateConstantVector_int(nst, nz); + kalfilmsinputs_1stapp_ps->Vt_dc = CreateCell_lf(rows_iv, cols_iv); + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + // + kalfilmsinputs_1stapp_ps->z0_dm = CreateMatrix_lf(nz, nst); //nz-by-nst. + kalfilmsinputs_1stapp_ps->z0_0_dm = CreateMatrix_lf(nz, nst); //nz-by-nst. + // + rows_iv = CreateConstantVector_int(nst, nz); + cols_iv = CreateConstantVector_int(nst, nz); + kalfilmsinputs_1stapp_ps->P0_dc = CreateCell_lf(rows_iv, cols_iv); //nz-by-nz-by-nst. + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + + //--- For output arguments. + rows_iv = CreateConstantVector_int(T+1, nz); + cols_iv = CreateConstantVector_int(T+1, nst); + kalfilmsinputs_1stapp_ps->zt_tm1_dc = CreateCell_lf(rows_iv, cols_iv); //nz-by-nst-by-(T+1). + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + // + rows_iv = CreateConstantVector_int(nst, nz); + cols_iv = CreateConstantVector_int(nst, nz); + kalfilmsinputs_1stapp_ps->Pt_tm1_d4 = CreateFourth_lf(T+1, rows_iv, cols_iv); //nz-by-nz-by-nst-by-(T+1). + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + // + rows_iv = CreateConstantVector_int(nst, nz); + cols_iv = CreateConstantVector_int(nst, ny); + kalfilmsinputs_1stapp_ps->PHtran_tdata_d4 = CreateFourth_lf(T, rows_iv, cols_iv); //nz-by-ny-by-nst-T, saved only for updating Kalman filter Updatekalfilms_1stapp(). + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + // + rows_iv = CreateConstantVector_int(T, ny); + cols_iv = CreateConstantVector_int(T, nst); + kalfilmsinputs_1stapp_ps->etdata_dc = CreateCell_lf(rows_iv, cols_iv); //ny-by-nst-by-T, used for updating Kalman filter Updatekalfilms_1stapp(). + rows_iv = CreateConstantVector_int(T, ny); + cols_iv = CreateConstantVector_int(T, nst); + // + rows_iv = CreateConstantVector_int(nst, ny); + cols_iv = CreateConstantVector_int(nst, ny); + kalfilmsinputs_1stapp_ps->Dtdata_d4 = CreateFourth_lf(T, rows_iv, cols_iv); //ny-by-ny-nst-by-T, used for updating Kalman filter Updatekalfilms_1stapp(). + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + + return (kalfilmsinputs_1stapp_ps); +} +//--- +struct TSkalfilmsinputs_1stapp_tag *DestroyTSkalfilmsinputs_1stapp(struct TSkalfilmsinputs_1stapp_tag *kalfilmsinputs_1stapp_ps) +{ + if (kalfilmsinputs_1stapp_ps) + { + //=== The order matters! + DestroyMatrix_lf(kalfilmsinputs_1stapp_ps->yt_dm); + DestroyMatrix_lf(kalfilmsinputs_1stapp_ps->at_dm); + DestroyCell_lf(kalfilmsinputs_1stapp_ps->Ht_dc); + DestroyCell_lf(kalfilmsinputs_1stapp_ps->Rt_dc); + DestroyCell_lf(kalfilmsinputs_1stapp_ps->Gt_dc); + //--- + DestroyMatrix_lf(kalfilmsinputs_1stapp_ps->bt_dm); + DestroyCell_lf(kalfilmsinputs_1stapp_ps->Ft_dc); + DestroyCell_lf(kalfilmsinputs_1stapp_ps->Vt_dc); + //--- + DestroyMatrix_lf(kalfilmsinputs_1stapp_ps->z0_dm); + DestroyMatrix_lf(kalfilmsinputs_1stapp_ps->z0_0_dm); + DestroyCell_lf(kalfilmsinputs_1stapp_ps->P0_dc); + //--- + DestroyCell_lf(kalfilmsinputs_1stapp_ps->zt_tm1_dc); + DestroyFourth_lf(kalfilmsinputs_1stapp_ps->Pt_tm1_d4); + DestroyFourth_lf(kalfilmsinputs_1stapp_ps->PHtran_tdata_d4); + DestroyCell_lf(kalfilmsinputs_1stapp_ps->etdata_dc); + DestroyFourth_lf(kalfilmsinputs_1stapp_ps->Dtdata_d4); + //--- + tzDestroy(kalfilmsinputs_1stapp_ps); //Must be freed last! + + return ((struct TSkalfilmsinputs_1stapp_tag *)NULL); + } + else return (kalfilmsinputs_1stapp_ps); +}; + + +//----------------------------------------------------------------------------------------------------------------------- +//-- OLD Code: Inputs for filter for Markov-switching DSGE models at any time t. +//----------------------------------------------------------------------------------------------------------------------- +struct TSkalfilmsinputs_tag *CreateTSkalfilmsinputs(int ny, int nz, int nRc, int nRstc, int nRv, int indxIndRegimes, int T) +{ + //~~~ Creating the structure and initializing the NULL pointers. + struct TSkalfilmsinputs_tag *kalfilmsinputs_ps = tzMalloc(1, struct TSkalfilmsinputs_tag); + + //=== + TSivector *rows_iv = NULL; + TSivector *cols_iv = NULL; + + //--- Default value. + kalfilmsinputs_ps->indxIni = 0; //1: using the initial condition with zt_tm1(:,1)=z0 and Pt_tm1(:,:,1)=P0; + //0: using the unconditional mean for any given regime at time 0. + //--- Other assignments. + kalfilmsinputs_ps->ny = ny; + kalfilmsinputs_ps->nz = nz; + kalfilmsinputs_ps->nRc = nRc; + kalfilmsinputs_ps->nRstc = nRstc; + kalfilmsinputs_ps->nRv = nRv; + kalfilmsinputs_ps->indxIndRegimes = indxIndRegimes; + kalfilmsinputs_ps->T = T; + + + //--------- Creates memory and assigns values. The order matters. + kalfilmsinputs_ps->yt_dm = CreateMatrix_lf(ny, T); + kalfilmsinputs_ps->at_dm = CreateMatrix_lf(ny, nRc); + // + rows_iv = CreateConstantVector_int(nRc, ny); + cols_iv = CreateConstantVector_int(nRc, nz); + kalfilmsinputs_ps->Ht_dc = CreateCell_lf(rows_iv, cols_iv); + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + // + rows_iv = CreateConstantVector_int(nRv, ny); + cols_iv = CreateConstantVector_int(nRv, ny); + kalfilmsinputs_ps->Rt_dc = CreateCell_lf(rows_iv, cols_iv); + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + // + rows_iv = CreateConstantVector_int(nRv, nz); + cols_iv = CreateConstantVector_int(nRv, ny); + kalfilmsinputs_ps->Gt_dc = CreateCell_lf(rows_iv, cols_iv); + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + // + kalfilmsinputs_ps->bt_dm = CreateMatrix_lf(nz, nRc); + // + rows_iv = CreateConstantVector_int(nRc, nz); + cols_iv = CreateConstantVector_int(nRc, nz); + kalfilmsinputs_ps->Ft_dc = CreateCell_lf(rows_iv, cols_iv); + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + // + rows_iv = CreateConstantVector_int(nRv, nz); + cols_iv = CreateConstantVector_int(nRv, nz); + kalfilmsinputs_ps->Vt_dc = CreateCell_lf(rows_iv, cols_iv); + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + // + if (indxIndRegimes) + { + kalfilmsinputs_ps->z0_dm = CreateMatrix_lf(nz, nRc*nRv); //nz-by-nRc*nRv if indxIndRegimes == 1 or nz-by-nRv if indxIndRegimes == 0. + // + rows_iv = CreateConstantVector_int(nRc*nRv, nz); + cols_iv = CreateConstantVector_int(nRc*nRv, nz); + kalfilmsinputs_ps->P0_dc = CreateCell_lf(rows_iv, cols_iv); //nz-by-nz-by-nRc*nRv if indxIndRegimes == 1 or nz-by-nz-by-nRv if indxIndRegimes == 0. + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + } + else + { + if (nRstc != nRv) fn_DisplayError("kalman.c/CreateTSkalfilmsinputs(): nRstc must equal to nRv when indxIndRegimes==0"); + kalfilmsinputs_ps->z0_dm = CreateMatrix_lf(nz, nRv); //nz-by-nRc*nRv if indxIndRegimes == 1 or nz-by-nRv if indxIndRegimes == 0. + // + rows_iv = CreateConstantVector_int(nRv, nz); + cols_iv = CreateConstantVector_int(nRv, nz); + kalfilmsinputs_ps->P0_dc = CreateCell_lf(rows_iv, cols_iv); //nz-by-nz-by-nRc*nRv if indxIndRegimes == 1 or nz-by-nz-by-nRv if indxIndRegimes == 0. + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + } + //--- For output arguments. + if (indxIndRegimes) + { + rows_iv = CreateConstantVector_int(T, nz); + cols_iv = CreateConstantVector_int(T, nRc*nRv); + kalfilmsinputs_ps->zt_tm1_dc = CreateCell_lf(rows_iv, cols_iv); //nz-by-nRc*nRv-by-T if indxIndRegimes==1, nz-by-nRv-by-T if indxIndRegimes==0 where nRc=nRv. + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + // + rows_iv = CreateConstantVector_int(nRc*nRv, nz); + cols_iv = CreateConstantVector_int(nRc*nRv, nz); + kalfilmsinputs_ps->Pt_tm1_d4 = CreateFourth_lf(T, rows_iv, cols_iv); //nz-by-nz-by-nRc*nRv-T if indxIndRegimes==1, nz-by-nz-by-nRv-by-T if indxIndRegimes==0 where nRc=nRv. + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + } + else + { + if (nRstc != nRv) fn_DisplayError("kalman.c/CreateTSkalfilmsinputs(): nRstc must equal to nRv when indxIndRegimes==0"); + rows_iv = CreateConstantVector_int(T, nz); + cols_iv = CreateConstantVector_int(T, nRv); + kalfilmsinputs_ps->zt_tm1_dc = CreateCell_lf(rows_iv, cols_iv); //nz-by-nRc*nRv-by-T if indxIndRegimes==1, nz-by-nRv-by-T if indxIndRegimes==0 where nRc=nRv. + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + // + rows_iv = CreateConstantVector_int(nRv, nz); + cols_iv = CreateConstantVector_int(nRv, nz); + kalfilmsinputs_ps->Pt_tm1_d4 = CreateFourth_lf(T, rows_iv, cols_iv); //nz-by-nz-by-nRc*nRv-T if indxIndRegimes==1, nz-by-nz-by-nRv-by-T if indxIndRegimes==0 where nRc=nRv. + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + } + + + //=== + DestroyVector_int(rows_iv); + DestroyVector_int(cols_iv); + + return (kalfilmsinputs_ps); + +} +//--- +struct TSkalfilmsinputs_tag *DestroyTSkalfilmsinputs(struct TSkalfilmsinputs_tag *kalfilmsinputs_ps) +{ + if (kalfilmsinputs_ps) + { + //=== The order matters! + DestroyMatrix_lf(kalfilmsinputs_ps->yt_dm); + DestroyMatrix_lf(kalfilmsinputs_ps->at_dm); + DestroyCell_lf(kalfilmsinputs_ps->Ht_dc); + DestroyCell_lf(kalfilmsinputs_ps->Rt_dc); + DestroyCell_lf(kalfilmsinputs_ps->Gt_dc); + //--- + DestroyMatrix_lf(kalfilmsinputs_ps->bt_dm); + DestroyCell_lf(kalfilmsinputs_ps->Ft_dc); + DestroyCell_lf(kalfilmsinputs_ps->Vt_dc); + //--- + DestroyMatrix_lf(kalfilmsinputs_ps->z0_dm); + DestroyCell_lf(kalfilmsinputs_ps->P0_dc); + //--- + DestroyCell_lf(kalfilmsinputs_ps->zt_tm1_dc); + DestroyFourth_lf(kalfilmsinputs_ps->Pt_tm1_d4); + //--- + tzDestroy(kalfilmsinputs_ps); //Must be freed last! + + return ((struct TSkalfilmsinputs_tag *)NULL); + } + else return (kalfilmsinputs_ps); +}; + + +#define LOG2PI (1.837877066409345e+000) //log(2*pi) +//----------------------------------------------------- +//-- Constant-parameters (known-time-varying) Kalman filter +//----------------------------------------------------- +double tz_kalfiltv(struct TSkalfiltv_tag *kalfiltv_ps) +{ + //General constant (known-time-varying) Kalman filter for DSGE models (conditional on all the parameters). + // It computes a sequence of one-step predictions and their covariance matrices, and the log likelihood. + // The function uses a forward recursion algorithm. See also the Matlab function fn_kalfil_tv.m + // + // State space model is defined as follows: + // y(t) = a(t) + H(t)*z(t) + eps(t) (observation or measurement equation) + // z(t) = b(t) + F(t)*z(t) + eta(t) (state or transition equation) + // where a(t), H(t), b(t), and F(t) depend on s_t that follows a Markov-chain process and are taken as given. + // + // Inputs are as follows: + // Y_T is a n_y-by-T matrix containing data [y(1), ... , y(T)]. + // a is an n_y-by-T matrix of time-varying input vectors in the measurement equation. + // H is an n_y-by-n_z-by-T 3-D of time-varying matrices in the measurement equation. + // R is an n_y-by-n_y-by-T 3-D of time-varying covariance matrices for the error in the measurement equation. + // G is an n_z-by-n_y-by-T 3-D of time-varying E(eta_t * eps_t'). + // ------ + // b is an n_z-by-T matrix of time-varying input vectors in the state equation with b(:,1) as an initial condition. + // F is an n_z-by-n_z-by-T 3-D of time-varying transition matrices in the state equation with F(:,:,1) as an initial condition. + // V is an n_z-by-n_z-by-T 3-D of time-varying covariance matrices for the error in the state equation with V(:,:,1) as an initial condition. + // ------ + // indxIni: 1: using the initial condition with zt_tm1(:,1)=z0 and Pt_tm1(:,:,1)=P0; + // 0: using the unconditional mean for any given regime at time 0. + // z0 is an n_z-by-1 vector of initial condition when indxIni=1. (Do not enter if indxIni=0.) + // P0 is an n_z-by-n_z matrix of initial condition when indxIni=1. (Do not enter if indxIni=0.) + // + // Outputs are as follows: + // loglh is a value of the log likelihood function of the state-space model + // under the assumption that errors are multivariate Gaussian. + // zt_tm1 is an n_z-by-T matrices of one-step predicted state vectors with z0_0m1 as an initial condition (base-0 first element) + // and with z_{T|T-1} as the last element. Thus, we can use it as a base-1 vector. + // Pt_tm1 is an n_z-by-n_z-by-T 3-D of covariance matrices of zt_tm1 with P0_0m1 as though it were a initial condition + // and with P_{T|T-1} as the last element. Thus, we can use it as though it were a base-1 cell. + // + // The initial state vector and its covariance matrix are computed under the bounded (stationary) condition: + // z0_0m1 = (I-F(:,:,1))\b(:,1) + // vec(P0_0m1) = (I-kron(F(:,:,1),F(:,:,1)))\vec(V(:,:,1)) + // Note that all eigenvalues of the matrix F(:,:,1) are inside the unit circle when the state-space model is bounded (stationary). + // + // March 2007, written by Tao Zha + // See Hamilton's book ([13.2.13] -- [13.2.22]), Harvey (pp.100-106), and LiuWZ Model I NOTES pp.001-003. + + int T = kalfiltv_ps->T; + int Tp1 = T + 1; + int ny = kalfiltv_ps->ny; + int nz = kalfiltv_ps->nz; + int indx_badlh = 0; //1: bad likelihood with, say, -infinity of the LH value. + int tdata, ti; + //--- Work arguments. + int nz2 = square(nz); + TSdmatrix *Wnzbynz_dm = CreateMatrix_lf(nz,nz); + TSdmatrix *Wnz2bynz2_dm = CreateMatrix_lf(nz2,nz2); + TSdmatrix *W2nz2bynz2_dm = CreateMatrix_lf(nz2,nz2); + TSdvector *wP0_dv = CreateVector_lf(nz2); + //+ + TSdvector yt_sdv, at_sdv, zt_tm1_sdv, ztp1_t_sdv, btp1_sdv; //double loglh_tdata; //logdetDtdata. + TSdvector *wny_dv = CreateVector_lf(ny); + TSdmatrix *Wnzbyny_dm = CreateMatrix_lf(nz,ny); + TSdmatrix *W2nzbynz_dm = CreateMatrix_lf(nz,nz); + TSdmatrix *PHtran_tdata_dm = CreateMatrix_lf(nz,ny); + TSdvector *etdata_dv = CreateVector_lf(ny); + TSdmatrix *Dtdata_dm = CreateMatrix_lf(ny,ny); + TSdmatrix *Kt_tdata0_dm = CreateMatrix_lf(nz,ny); + TSdmatrix *Kt_tdata_dm = CreateMatrix_lf(nz,ny); + //--- For eigenvalue decompositions + int ki; + int errflag; + double eigmax, logdet_Dtdata; + TSdzvector *evals_dzv = NULL; + TSdvector *evals_abs_dv = NULL; //Absolute eigenvalues. + //--- Input arguments. + TSdmatrix *yt_dm = kalfiltv_ps->yt_dm; //ny-by-T. + TSdmatrix *at_dm = kalfiltv_ps->at_dm; //ny-by-T. + TSdcell *Ht_dc = kalfiltv_ps->Ht_dc; //ny-by-nz-by-T. + TSdcell *Rt_dc = kalfiltv_ps->Rt_dc; //ny-by-ny-by-T. Covariance matrix for the measurement equation. + TSdcell *Gt_dc = kalfiltv_ps->Gt_dc; //nz-by-ny-by-T. Cross-covariance. + // + TSdmatrix *bt_dm = kalfiltv_ps->bt_dm; //nz-by-T. + TSdcell *Ft_dc = kalfiltv_ps->Ft_dc; //nz-by-nz-by-T. + TSdcell *Vt_dc = kalfiltv_ps->Vt_dc; //nz-by-nz-by-T. Covariance matrix for the state equation. + // + TSdvector *z0_dv = kalfiltv_ps->z0_dv; //nz-by-1; + TSdmatrix *P0_dm = kalfiltv_ps->P0_dm; //nz-by-nz. + //--- Output arguments. + double loglh; //log likelihood. + TSdmatrix *zt_tm1_dm = kalfiltv_ps->zt_tm1_dm; //nz-by-T. + TSdcell *Pt_tm1_dc = kalfiltv_ps->Pt_tm1_dc; //nz-by-nz-T. + + + + //=== Initializing. + if (!kalfiltv_ps->indxIni) + { + InitializeDiagonalMatrix_lf(Wnzbynz_dm, 1.0); //To be used for I(nz) - + InitializeDiagonalMatrix_lf(Wnz2bynz2_dm, 1.0); //To be used for I(nz2) - + + //=== Eigenanalysis to determine the roots to ensure boundedness. + evals_dzv = CreateVector_dz(nz); + evals_abs_dv = CreateVector_lf(nz); + errflag = eigrgen(evals_dzv, (TSdzmatrix *)NULL, (TSdzmatrix *)NULL, Ft_dc->C[0]); + if (errflag) fn_DisplayError("tz_kalfiltv() in kalman.c: eigen decomposition failed"); + for (ki=nz-1; ki>=0; ki--) evals_abs_dv->v[ki] = sqrt(square(evals_dzv->real->v[ki]) + square(evals_dzv->imag->v[ki])); + evals_abs_dv->flag = V_DEF; + eigmax = MaxVector(evals_abs_dv); + if (eigmax < (1.0+1.0e-14)) + { + //--- Getting z0_dv: zt_tm1(:,1) = (eye(n_z)-F(:,:,1))\b(:,1); + MatrixMinusMatrix(Wnzbynz_dm, Wnzbynz_dm, Ft_dc->C[0]); + CopySubmatrix2vector(z0_dv, 0, bt_dm, 0, 0, bt_dm->nrows); + bdivA_rgens(z0_dv, z0_dv, '\\', Wnzbynz_dm); + //Done with Wnzbynz_dm. + //--- Getting P0_dm: Pt_tm1(:,:,1) = reshape((eye(n_z^2)-kron(F(:,:,1),F(:,:,1)))\V1(:),n_z,n_z); + tz_kron(W2nz2bynz2_dm, Ft_dc->C[0], Ft_dc->C[0]); + MatrixMinusMatrix(Wnz2bynz2_dm, Wnz2bynz2_dm, W2nz2bynz2_dm); + CopySubmatrix2vector(wP0_dv, 0, Vt_dc->C[0], 0, 0, nz2); + bdivA_rgens(wP0_dv, wP0_dv, '\\', Wnz2bynz2_dm); + CopySubvector2matrix_unr(P0_dm, 0, 0, wP0_dv, 0, nz2); + //Done with all w*_dv and W*_dm. + } + else + { + fprintf(stdout, "Fatal error: tz_kalfiltv() in kalman.c: the system is non-stationary solutions\n" + " and the initial conditions must be supplied by, say, input arguments"); + fflush(stdout); + exit( EXIT_FAILURE ); + } + } + CopySubvector2matrix(zt_tm1_dm, 0, 0, z0_dv, 0, z0_dv->n); + CopyMatrix0(Pt_tm1_dc->C[0], P0_dm); + + //====== See p.002 in LiuWZ. ====== + at_sdv.n = yt_sdv.n = yt_dm->nrows; + at_sdv.flag = yt_sdv.flag = V_DEF; + zt_tm1_sdv.n = ztp1_t_sdv.n = zt_tm1_dm->nrows; + zt_tm1_sdv.flag = ztp1_t_sdv.flag = V_DEF; + btp1_sdv.n = bt_dm->nrows; + btp1_sdv.flag = V_DEF; + loglh = 0.0; + for (tdata=0; tdata<T; tdata++ ) + { + //Base-0 timing. + ti = tdata + 1; //Next period. + + //--- Setup. + MatrixTimesMatrix(PHtran_tdata_dm, Pt_tm1_dc->C[tdata], Ht_dc->C[tdata], 1.0, 0.0, 'N', 'T'); + + //--- Data. + //- etdata = Y_T(:,tdata) - a(:,tdata) - Htdata*ztdata; + yt_sdv.v = yt_dm->M + tdata*yt_dm->nrows; + at_sdv.v = at_dm->M + tdata*at_dm->nrows; + zt_tm1_sdv.v = zt_tm1_dm->M + tdata*zt_tm1_dm->nrows; + VectorMinusVector(etdata_dv, &yt_sdv, &at_sdv); + MatrixTimesVector(etdata_dv, Ht_dc->C[tdata], &zt_tm1_sdv, -1.0, 1.0, 'N'); + //+ Dtdata = Htdata*PHtran_tdata + R(:,:,tdata); + CopyMatrix0(Dtdata_dm, Rt_dc->C[tdata]); + MatrixTimesMatrix(Dtdata_dm, Ht_dc->C[tdata], PHtran_tdata_dm, 1.0, 1.0, 'N', 'N'); + ScalarTimesMatrixSquare(Dtdata_dm, 0.5, Dtdata_dm, 'T', 0.5); //Making it symmetric against some rounding errors. + //This making-symmetric is very IMPORTANT; otherwise, we will get the matrix being singular message + // and eigenvalues being negative for the SPD matrix, etc. Then the likelihood becomes either + // a bad number or a complex number. + Dtdata_dm->flag = Dtdata_dm->flag | M_SU | M_SL; + + //--- Forming the log likelihood. + if (!isfinite(logdet_Dtdata=logdetspd(Dtdata_dm))) return (kalfiltv_ps->loglh = -NEARINFINITY); + bdivA_rgens(wny_dv, etdata_dv, '/', Dtdata_dm); + loglh += -(0.5*ny)*LOG2PI - 0.5*logdet_Dtdata - 0.5*VectorDotVector(wny_dv, etdata_dv); + //loglh += -(0.5*ny)*LOG2PI - 0.5*logdeterminant(Dtdata_dm) - 0.5*VectorDotVector(wny_dv, etdata_dv); + //Done with all w*_dv. + + + //--- Updating zt_tm1_dm and Pt_tm1_dc by ztp1_t_sdv and Pt_tm1_dc->C[ti]. + if (ti<T) + { + //Updating only up to tdata=T-2. The values at ti=T or tdata=T-1 will not be used in the likelihood function. + + //- Kt_tdata = (Ft*PHtran_tdata+G(:,:,tdata))/Dtdata; + CopyMatrix0(Kt_tdata0_dm, Gt_dc->C[tdata]); + MatrixTimesMatrix(Kt_tdata0_dm, Ft_dc->C[ti], PHtran_tdata_dm, 1.0, 1.0, 'N', 'N'); + BdivA_rrect(Kt_tdata_dm, Kt_tdata0_dm, '/', Dtdata_dm); + //+ zt_tm1(:,t) = b(:,t) + Ft*zt_tm1(:,tdata) + Kt_tdata*etdata; + ztp1_t_sdv.v = zt_tm1_dm->M + ti*zt_tm1_dm->nrows; + MatrixTimesVector(&ztp1_t_sdv, Ft_dc->C[ti], &zt_tm1_sdv, 1.0, 0.0, 'N'); + MatrixTimesVector(&ztp1_t_sdv, Kt_tdata_dm, etdata_dv, 1.0, 1.0, 'N'); + btp1_sdv.v = bt_dm->M + ti*btp1_sdv.n; + VectorPlusMinusVectorUpdate(&ztp1_t_sdv, &btp1_sdv, 1.0); + //+ Pt_tm1(:,:,t) = Ft*Ptdata*Fttran - Kt_tdata*Dtdata*Kt_tdatatran + V(:,:,t); + CopyMatrix0(Pt_tm1_dc->C[ti], Vt_dc->C[ti]); + MatrixTimesMatrix(Wnzbyny_dm, Kt_tdata_dm, Dtdata_dm, 1.0, 0.0, 'N', 'N'); + MatrixTimesMatrix(Wnzbynz_dm, Wnzbyny_dm, Kt_tdata_dm, 1.0, 0.0, 'N', 'T'); + MatrixPlusMinusMatrixUpdate(Pt_tm1_dc->C[ti], Wnzbynz_dm, -1.0); + //Done with all W*_dm. + MatrixTimesMatrix(Wnzbynz_dm, Ft_dc->C[ti], Pt_tm1_dc->C[tdata], 1.0, 0.0, 'N', 'N'); + MatrixTimesMatrix(W2nzbynz_dm, Wnzbynz_dm, Ft_dc->C[ti], 1.0, 0.0, 'N', 'T'); + MatrixPlusMatrixUpdate(Pt_tm1_dc->C[ti], W2nzbynz_dm); + //Done with all W*_dm. + } + } + zt_tm1_dm->flag = M_GE; + + //=== + DestroyVector_dz(evals_dzv); + DestroyVector_lf(evals_abs_dv); + DestroyMatrix_lf(Wnzbynz_dm); + DestroyMatrix_lf(Wnz2bynz2_dm); + DestroyMatrix_lf(W2nz2bynz2_dm); + DestroyVector_lf(wP0_dv); + // + DestroyVector_lf(wny_dv); + DestroyMatrix_lf(Wnzbyny_dm); + DestroyMatrix_lf(W2nzbynz_dm); + DestroyMatrix_lf(PHtran_tdata_dm); + DestroyVector_lf(etdata_dv); + DestroyMatrix_lf(Dtdata_dm); + DestroyMatrix_lf(Kt_tdata0_dm); + DestroyMatrix_lf(Kt_tdata_dm); + + return (kalfiltv_ps->loglh = loglh); +} +/** +double tz_kalfiltv(struct TSkalfiltv_tag *kalfiltv_ps) +{ + //This function is used to test tz_logTimetCondLH_kalfiltv(). + int T = kalfiltv_ps->T; + int tdata; + double loglh; + + loglh = 0.0; + for (tdata=0; tdata<T; tdata++) loglh += tz_logTimetCondLH_kalfiltv(0, tdata+1, kalfiltv_ps); + + return (loglh); +} +/**/ +//----------------------------------------------------- +//-- Updating Kalman filter at time t for constant-parameters (or known-time-varying) Kalman filter. +//----------------------------------------------------- +double tz_logTimetCondLH_kalfiltv(int st, int inpt, struct TSkalfiltv_tag *kalfiltv_ps) +{ + //st: base-0 grand regime at time t, which is just a dummy for this constant-parameter function in order to use + // Waggoner's automatic functions. + //inpt: base-1 in the sense that inpt>=1 to deal with the time series situation where S_T is (T+1)-by-1 and Y_T is T+nlags_max-by-1. + // The 1st element for S_T is S_T[1] while S_T[0] is s_0 (initial condition). + // The 1st element for Y_T, however, is Y_T[nlags_max+1-1]. + //See (42.3) on p.42 in the SWZII NOTES. + // + //log LH at time t for constant (known-time-varying) Kalman-filter DSGE models (conditional on all the parameters). + // It computes a sequence of one-step predictions and their covariance matrices, and the log likelihood at time t. + // The function uses a forward recursion algorithm. See also the Matlab function fn_kalfil_tv.m + // + // State space model is defined as follows: + // y(t) = a(t) + H(t)*z(t) + eps(t) (observation or measurement equation) + // z(t) = b(t) + F(t)*z(t) + eta(t) (state or transition equation) + // where a(t), H(t), b(t), and F(t) depend on s_t that follows a Markov-chain process and are taken as given. + // + // Inputs are as follows: + // Y_T is a n_y-by-T matrix containing data [y(1), ... , y(T)]. + // a is an n_y-by-T matrix of time-varying input vectors in the measurement equation. + // H is an n_y-by-n_z-by-T 3-D of time-varying matrices in the measurement equation. + // R is an n_y-by-n_y-by-T 3-D of time-varying covariance matrices for the error in the measurement equation. + // G is an n_z-by-n_y-by-T 3-D of time-varying E(eta_t * eps_t'). + // ------ + // b is an n_z-by-T matrix of time-varying input vectors in the state equation with b(:,1) as an initial condition. + // F is an n_z-by-n_z-by-T 3-D of time-varying transition matrices in the state equation with F(:,:,1) as an initial condition. + // V is an n_z-by-n_z-by-T 3-D of time-varying covariance matrices for the error in the state equation with V(:,:,1) as an initial condition. + // ------ + // indxIni: 1: using the initial condition with zt_tm1(:,1)=z0 and Pt_tm1(:,:,1)=P0; + // 0: using the unconditional mean for any given regime at time 0. + // z0 is an n_z-by-1 vector of initial condition when indxIni=1. (Value to be assigned if indxIni=0.) + // P0 is an n_z-by-n_z matrix of initial condition when indxIni=1. (Value to be assigned if indxIni=0.) + // + // Outputs are as follows: + // loglh is a value of the log likelihood function of the state-space model + // under the assumption that errors are multivariate Gaussian. + // zt_tm1 is an n_z-by-T matrices of one-step predicted state vectors with z0_0m1 as an initial condition (base-0 first element) + // and with z_{T|T-1} as the last element. Thus, we can use it as a base-1 vector. + // Pt_tm1 is an n_z-by-n_z-by-T 3-D of covariance matrices of zt_tm1 with P0_0m1 as though it were a initial condition + // and with P_{T|T-1} as the last element. Thus, we can use it as though it were a base-1 cell. + // + // The initial state vector and its covariance matrix are computed under the bounded (stationary) condition: + // z0_0m1 = (I-F(:,:,1))\b(:,1) + // vec(P0_0m1) = (I-kron(F(:,:,1),F(:,:,1)))\vec(V(:,:,1)) + // Note that all eigenvalues of the matrix F(:,:,1) are inside the unit circle when the state-space model is bounded (stationary). + // + // April 2008, written by Tao Zha + // See Hamilton's book ([13.2.13] -- [13.2.22]), Harvey (pp.100-106), and LiuWZ Model I NOTES pp.001-003. + + //--- Output arguments. + double loglh_timet; //log likelihood at time t. + TSdmatrix *zt_tm1_dm = kalfiltv_ps->zt_tm1_dm; //nz-by-T. + TSdcell *Pt_tm1_dc = kalfiltv_ps->Pt_tm1_dc; //nz-by-nz-T. + //--- Input arguments. + int tdata, tp1; + TSdvector *z0_dv = kalfiltv_ps->z0_dv; //nz-by-1; + TSdmatrix *P0_dm = kalfiltv_ps->P0_dm; //nz-by-nz. + int T = kalfiltv_ps->T; + int ny = kalfiltv_ps->ny; + int nz = kalfiltv_ps->nz; + //--- Work arguments. + int nz2 = square(nz); + TSdmatrix *Wnzbynz_dm = CreateMatrix_lf(nz,nz); + TSdmatrix *Wnz2bynz2_dm = CreateMatrix_lf(nz2,nz2); + TSdmatrix *W2nz2bynz2_dm = CreateMatrix_lf(nz2,nz2); + TSdvector *wP0_dv = CreateVector_lf(nz2); + //+ + TSdvector yt_sdv, at_sdv, zt_tm1_sdv, ztp1_t_sdv, btp1_sdv; + TSdvector *wny_dv = CreateVector_lf(ny); + TSdmatrix *Wnzbyny_dm = CreateMatrix_lf(nz,ny); + TSdmatrix *W2nzbynz_dm = CreateMatrix_lf(nz,nz); + TSdmatrix *PHtran_tdata_dm = CreateMatrix_lf(nz,ny); + TSdvector *etdata_dv = CreateVector_lf(ny); + TSdmatrix *Dtdata_dm = CreateMatrix_lf(ny,ny); + TSdmatrix *Kt_tdata0_dm = CreateMatrix_lf(nz,ny); + TSdmatrix *Kt_tdata_dm = CreateMatrix_lf(nz,ny); + //--- For eigenvalue decompositions + int ki; + int errflag; + double eigmax, logdet_Dtdata; + TSdzvector *evals_dzv = NULL; + TSdvector *evals_abs_dv = NULL; //Absolute eigenvalues. + //--- Input arguments. + TSdmatrix *yt_dm = kalfiltv_ps->yt_dm; //ny-by-T. + TSdmatrix *at_dm = kalfiltv_ps->at_dm; //ny-by-T. + TSdcell *Ht_dc = kalfiltv_ps->Ht_dc; //ny-by-nz-by-T. + TSdcell *Rt_dc = kalfiltv_ps->Rt_dc; //ny-by-ny-by-T. Covariance matrix for the measurement equation. + TSdcell *Gt_dc = kalfiltv_ps->Gt_dc; //nz-by-ny-by-T. Cross-covariance. + // + TSdmatrix *bt_dm = kalfiltv_ps->bt_dm; //nz-by-T. + TSdcell *Ft_dc = kalfiltv_ps->Ft_dc; //nz-by-nz-by-T. + TSdcell *Vt_dc = kalfiltv_ps->Vt_dc; //nz-by-nz-by-T. Covariance matrix for the state equation. + // + + + tdata = (tp1=inpt) - 1; //Base-0 time. + + //======= Initial condition. ======= + if (tdata==0) + { + //=== Initializing. + if (!kalfiltv_ps->indxIni) + { + InitializeDiagonalMatrix_lf(Wnzbynz_dm, 1.0); //To be used for I(nz) - + InitializeDiagonalMatrix_lf(Wnz2bynz2_dm, 1.0); //To be used for I(nz2) - + + //=== Eigenanalysis to determine the roots to ensure boundedness. + evals_dzv = CreateVector_dz(nz); + evals_abs_dv = CreateVector_lf(nz); + errflag = eigrgen(evals_dzv, (TSdzmatrix *)NULL, (TSdzmatrix *)NULL, Ft_dc->C[0]); + if (errflag) fn_DisplayError("tz_logTimetCondLH_kalfiltv() in kalman.c: eigen decomposition failed"); + for (ki=nz-1; ki>=0; ki--) evals_abs_dv->v[ki] = sqrt(square(evals_dzv->real->v[ki]) + square(evals_dzv->imag->v[ki])); + evals_abs_dv->flag = V_DEF; + eigmax = MaxVector(evals_abs_dv); + if (eigmax < (1.0+1.0e-14)) + { + //--- Getting z0_dv: zt_tm1(:,1) = (eye(n_z)-F(:,:,1))\b(:,1); + MatrixMinusMatrix(Wnzbynz_dm, Wnzbynz_dm, Ft_dc->C[0]); + CopySubmatrix2vector(z0_dv, 0, bt_dm, 0, 0, bt_dm->nrows); + bdivA_rgens(z0_dv, z0_dv, '\\', Wnzbynz_dm); + //Done with Wnzbynz_dm. + //--- Getting P0_dm: Pt_tm1(:,:,1) = reshape((eye(n_z^2)-kron(F(:,:,1),F(:,:,1)))\V1(:),n_z,n_z); + tz_kron(W2nz2bynz2_dm, Ft_dc->C[0], Ft_dc->C[0]); + MatrixMinusMatrix(Wnz2bynz2_dm, Wnz2bynz2_dm, W2nz2bynz2_dm); + CopySubmatrix2vector(wP0_dv, 0, Vt_dc->C[0], 0, 0, nz2); + bdivA_rgens(wP0_dv, wP0_dv, '\\', Wnz2bynz2_dm); + CopySubvector2matrix_unr(P0_dm, 0, 0, wP0_dv, 0, nz2); + //Done with all w*_dv and W*_dm. + } + else + { + fprintf(FPTR_DEBUG, "Fatal error: tz_logTimetCondLH_kalfiltv() in kalman.c: the system is non-stationary solutions\n" + " and thus the initial conditions must be supplied by, say, input arguments"); + fflush(FPTR_DEBUG); + exit( EXIT_FAILURE ); + } + } + CopySubvector2matrix(zt_tm1_dm, 0, 0, z0_dv, 0, z0_dv->n); + CopyMatrix0(Pt_tm1_dc->C[tdata], P0_dm); + } + + + //======= Liklihood at time t (see p.002 in LiuWZ). ======= + at_sdv.n = yt_sdv.n = yt_dm->nrows; + at_sdv.flag = yt_sdv.flag = V_DEF; + zt_tm1_sdv.n = ztp1_t_sdv.n = zt_tm1_dm->nrows; + zt_tm1_sdv.flag = ztp1_t_sdv.flag = V_DEF; + btp1_sdv.n = bt_dm->nrows; + btp1_sdv.flag = V_DEF; + + //--- Setup. + MatrixTimesMatrix(PHtran_tdata_dm, Pt_tm1_dc->C[tdata], Ht_dc->C[tdata], 1.0, 0.0, 'N', 'T'); + + //--- Data. + //- etdata = Y_T(:,tdata) - a(:,tdata) - Htdata*ztdata; + yt_sdv.v = yt_dm->M + tdata*yt_dm->nrows; + at_sdv.v = at_dm->M + tdata*at_dm->nrows; + zt_tm1_sdv.v = zt_tm1_dm->M + tdata*zt_tm1_dm->nrows; + VectorMinusVector(etdata_dv, &yt_sdv, &at_sdv); + MatrixTimesVector(etdata_dv, Ht_dc->C[tdata], &zt_tm1_sdv, -1.0, 1.0, 'N'); + //+ Dtdata = Htdata*PHtran_tdata + R(:,:,tdata); + CopyMatrix0(Dtdata_dm, Rt_dc->C[tdata]); + MatrixTimesMatrix(Dtdata_dm, Ht_dc->C[tdata], PHtran_tdata_dm, 1.0, 1.0, 'N', 'N'); + ScalarTimesMatrixSquare(Dtdata_dm, 0.5, Dtdata_dm, 'T', 0.5); //Making it symmetric against some rounding errors. + //This making-symmetric is very IMPORTANT; otherwise, we will get the matrix being singular message + // and eigenvalues being negative for the SPD matrix, etc. Then the likelihood becomes either + // a bad number or a complex number. + Dtdata_dm->flag = Dtdata_dm->flag | M_SU | M_SL; + + //--- Forming the log likelihood. + if (!isfinite(logdet_Dtdata=logdetspd(Dtdata_dm))) return (loglh_timet = -NEARINFINITY); + bdivA_rgens(wny_dv, etdata_dv, '/', Dtdata_dm); + loglh_timet = -(0.5*ny)*LOG2PI - 0.5*logdet_Dtdata - 0.5*VectorDotVector(wny_dv, etdata_dv); + //Done with all w*_dv. + + + //======= Updating for the next period. ======= + //--- Updating zt_tm1_dm and Pt_tm1_dc by ztp1_t_sdv and Pt_tm1_dc->C[ti]. + if (tp1<T) + { + //Updating only up to tdata=T-2, because the values at tp1=T or tdata=T-1 will NOT be used in the likelihood function. + + //- Kt_tdata = (Ft*PHtran_tdata+G(:,:,tdata))/Dtdata; + CopyMatrix0(Kt_tdata0_dm, Gt_dc->C[tdata]); + MatrixTimesMatrix(Kt_tdata0_dm, Ft_dc->C[tp1], PHtran_tdata_dm, 1.0, 1.0, 'N', 'N'); + BdivA_rrect(Kt_tdata_dm, Kt_tdata0_dm, '/', Dtdata_dm); + //+ zt_tm1(:,t) = b(:,t) + Ft*zt_tm1(:,tdata) + Kt_tdata*etdata; + ztp1_t_sdv.v = zt_tm1_dm->M + tp1*zt_tm1_dm->nrows; + MatrixTimesVector(&ztp1_t_sdv, Ft_dc->C[tp1], &zt_tm1_sdv, 1.0, 0.0, 'N'); + MatrixTimesVector(&ztp1_t_sdv, Kt_tdata_dm, etdata_dv, 1.0, 1.0, 'N'); + btp1_sdv.v = bt_dm->M + tp1*btp1_sdv.n; + VectorPlusMinusVectorUpdate(&ztp1_t_sdv, &btp1_sdv, 1.0); + //+ Pt_tm1(:,:,t) = Ft*Ptdata*Fttran - Kt_tdata*Dtdata*Kt_tdatatran + V(:,:,t); + CopyMatrix0(Pt_tm1_dc->C[tp1], Vt_dc->C[tp1]); + MatrixTimesMatrix(Wnzbyny_dm, Kt_tdata_dm, Dtdata_dm, 1.0, 0.0, 'N', 'N'); + MatrixTimesMatrix(Wnzbynz_dm, Wnzbyny_dm, Kt_tdata_dm, 1.0, 0.0, 'N', 'T'); + MatrixPlusMinusMatrixUpdate(Pt_tm1_dc->C[tp1], Wnzbynz_dm, -1.0); + //Done with all W*_dm. + MatrixTimesMatrix(Wnzbynz_dm, Ft_dc->C[tp1], Pt_tm1_dc->C[tdata], 1.0, 0.0, 'N', 'N'); + MatrixTimesMatrix(W2nzbynz_dm, Wnzbynz_dm, Ft_dc->C[tp1], 1.0, 0.0, 'N', 'T'); + MatrixPlusMatrixUpdate(Pt_tm1_dc->C[tp1], W2nzbynz_dm); + //Done with all W*_dm. + } + zt_tm1_dm->flag = M_GE; + + //=== + DestroyVector_dz(evals_dzv); + DestroyVector_lf(evals_abs_dv); + DestroyMatrix_lf(Wnzbynz_dm); + DestroyMatrix_lf(Wnz2bynz2_dm); + DestroyMatrix_lf(W2nz2bynz2_dm); + DestroyVector_lf(wP0_dv); + // + DestroyVector_lf(wny_dv); + DestroyMatrix_lf(Wnzbyny_dm); + DestroyMatrix_lf(W2nzbynz_dm); + DestroyMatrix_lf(PHtran_tdata_dm); + DestroyVector_lf(etdata_dv); + DestroyMatrix_lf(Dtdata_dm); + DestroyMatrix_lf(Kt_tdata0_dm); + DestroyMatrix_lf(Kt_tdata_dm); + + return (loglh_timet); +} + + + + +//----------------------------------------------------- +//- WARNING: bedore using this function, make sure to call the following functions +// Only once in creating lwzmodel_ps: Refresh_kalfilms_*(lwzmodel_ps); +// Everytime when parameters are changed: RefreshEverything(); RefreRunningGensys_allcases(lwzmodel_ps) in particular. +//----------------------------------------------------- +double logTimetCondLH_kalfilms_1stapp(int st, int inpt, struct TSkalfilmsinputs_1stapp_tag *kalfilmsinputs_1stapp_ps, struct TStateModel_tag *smodel_ps) +{ + //st: base-0 grand regime -- deals with the cross-section values at time t. + //inpt: base-1 in the sense that inpt>=1 to deal with the time series situation where S_T is (T+1)-by-1 and Y_T is T+nlags_max-by-1. + // The 1st element for S_T is S_T[1] while S_T[0] is s_0 (initial condition). + // The 1st element for Y_T, however, is Y_T[nlags_max+1-1]. + //See (42.3) on p.42 in the SWZII NOTES. + + //-- Output arguments + double loglh_timet; + //--- Input arguments + TSdcell *etdata_dc = kalfilmsinputs_1stapp_ps->etdata_dc; //ny-by-nst-by-T, save for computing the likelihood. + TSdfourth *Dtdata_d4 = kalfilmsinputs_1stapp_ps->Dtdata_d4; //ny-by-ny-nst-by-T, save for computing the likelihood and updating Kalman filter Updatekalfilms_1stapp(). + //--- Local variables + int tbase0; + double logdet_Dtdata; + //--- Accessible variables + int ny = kalfilmsinputs_1stapp_ps->ny; + TSdvector etdata_sdv; + //=== Work arguments. + TSdvector *wny_dv = CreateVector_lf(ny); + + + + //--- Critical checking. + if (inpt > kalfilmsinputs_1stapp_ps->T) + fn_DisplayError(".../kalman.c/logTimetCondLH_kalfilms_1stapp(): The time exceeds the\n" + " data sample size allocated the structure TSkalfilmsinputs_1stapp_tag"); + + //--- The following is for safe guard. InitializeKalman_z10_P10() should be called in, say, RefreshEverything(). + if (kalfilmsinputs_1stapp_ps->ztm1_track < 0) + if (!InitializeKalman_z10_P10(kalfilmsinputs_1stapp_ps, (TSdmatrix *)NULL, (TSdcell *)NULL)) + fn_DisplayError(".../kalman.c/logTimetCondLH_kalfilms_1stapp(): the system is non-stationary when calling" + " InitializeKalman_z10_P10(). Please call this function in RefreshEverthing() and" + " set the likehood to be -infty for early exit"); + + tbase0=inpt-1; + + //------------------- The order matters. Updatekalfilms_1stapp() must be called before Update_et_Dt_1stapp(). ----------------- + //--- $$$ Critical updating where we MUSt have inpt-1. If inpt, Updatekalfilms_1stapp() will call this function again + //--- $$$ because DW function ProbabilityStateConditionalCurrent() need to access this function at time inpt, + //--- $$$ which has not computed before Updatekalfilms_1stapp(). Thus, we'll have an infinite loop. + Updatekalfilms_1stapp(tbase0, kalfilmsinputs_1stapp_ps, smodel_ps); +// //--- $$$ Critical updating. +// Update_et_Dt_1stapp(tbase0, kalfilmsinputs_1stapp_ps); +// //This function will give Dtdata_d4->F[tbase0], etdata_dc->C[tbase0], and PHtran_tdata_d4->F[tbase0]. + + + + //====================================================== + //= Getting the logLH at time tbase0 or time inpt. + //====================================================== + //--- Forming the log conditional likelihood at t. + etdata_sdv.n = ny; + etdata_sdv.v = etdata_dc->C[tbase0]->M + ny*st; + etdata_sdv.flag = V_DEF; + if (!isfinite(logdet_Dtdata=logdetspd(Dtdata_d4->F[tbase0]->C[st]))) return (loglh_timet = -NEARINFINITY); + bdivA_rgens(wny_dv, &etdata_sdv, '/', Dtdata_d4->F[tbase0]->C[st]); + loglh_timet = -(0.5*ny)*LOG2PI - 0.5*logdet_Dtdata - 0.5*VectorDotVector(wny_dv, &etdata_sdv); + //Done with all w*_dv. + + //=== + DestroyVector_lf(wny_dv); + + return (loglh_timet); +} +//====================================================== +//= Computing z_{1|0} and P_{1|0} for each new parameter values. +//====================================================== +int InitializeKalman_z10_P10(struct TSkalfilmsinputs_1stapp_tag *kalfilmsinputs_1stapp_ps, TSdmatrix *z10_dm, TSdcell *P10_dc) +{ + //See p.001 and p.004 in LWZ Model II. + //Outputs: + // return 1: success in initializing; 0: initializing fails, so the likelihood must be set to -infty outside this function. + // ztm1_track to track the time up to which Kalman filter have been updated. + // z0_dm, zt_tm1_dc->C[0] + // P0_dc, Pt_tm1_d4->F[0] + + //--- Output arguments + TSdmatrix *z0_0_dm = kalfilmsinputs_1stapp_ps->z0_dm; //nz-by-nst. + TSdmatrix *z0_dm = kalfilmsinputs_1stapp_ps->z0_dm; //nz-by-nst. + TSdcell *P0_dc = kalfilmsinputs_1stapp_ps->P0_dc; //nz-by-nz-by-nst. + //+ Used to get zt_tm1_dc->C[0] and Pt_tm1_d4->F[0] only. + TSdcell *zt_tm1_dc = kalfilmsinputs_1stapp_ps->zt_tm1_dc; //nz-by-nst-by-(T+1). + TSdfourth *Pt_tm1_d4 = kalfilmsinputs_1stapp_ps->Pt_tm1_d4; //nz-by-nz-by-nst-by-(T+1). + //--- Input arguments + TSdmatrix *yt_dm = kalfilmsinputs_1stapp_ps->yt_dm; //ny-by-T. + TSdmatrix *at_dm = kalfilmsinputs_1stapp_ps->at_dm; //ny-by-nst. + TSdcell *Ht_dc = kalfilmsinputs_1stapp_ps->Ht_dc; //ny-by-nz-by-nst. + TSdcell *Rt_dc = kalfilmsinputs_1stapp_ps->Rt_dc; //ny-by-ny-by-nst. Covariance matrix for the measurement equation. + //+ + TSdmatrix *bt_dm = kalfilmsinputs_1stapp_ps->bt_dm; //nz-by-nst. + TSdcell *Ft_dc = kalfilmsinputs_1stapp_ps->Ft_dc; //nz-by-nz-by-nst. + TSdcell *Vt_dc = kalfilmsinputs_1stapp_ps->Vt_dc; //nz-by-nz-by-nst. Covariance matrix for the state equation. + //--- Local variables + int sti; + //--- Accessible variables + int ny = kalfilmsinputs_1stapp_ps->ny; + int nz = kalfilmsinputs_1stapp_ps->nz; + int nst = kalfilmsinputs_1stapp_ps->nst; + TSdvector z0_sdv, z0_0_sdv, bt_sdv; + TSdvector yt_sdv, at_sdv; + //--- For the initial conditions: eigenvalue decompositions + int ki; + int errflag; + double eigmax; + //=== + int nz2 = square(nz); + TSdmatrix *Wnzbynz_dm = CreateMatrix_lf(nz,nz); + TSdmatrix *Wnz2bynz2_dm = CreateMatrix_lf(nz2,nz2); + TSdmatrix *W2nz2bynz2_dm = CreateMatrix_lf(nz2,nz2); + TSdvector *wP0_dv = CreateVector_lf(nz2); + // + TSdzvector *evals_dzv = evals_dzv = CreateVector_dz(nz); + TSdvector *evals_abs_dv = CreateVector_lf(nz); //Absolute eigenvalues. + + + if (kalfilmsinputs_1stapp_ps->ztm1_track < 0) + { + z0_sdv.n = z0_0_sdv.n = bt_sdv.n = nz; + z0_sdv.flag = z0_0_sdv.flag = bt_sdv.flag = V_DEF; + at_sdv.n = yt_sdv.n = ny; + at_sdv.flag = yt_sdv.flag = V_DEF; + + + //======= Initial condition. ======= + if (!kalfilmsinputs_1stapp_ps->indxIni) + { + z0_0_dm->flag = z0_dm->flag = M_GE; + for (sti=nst-1; sti>=0; sti--) + { + if (kalfilmsinputs_1stapp_ps->DiffuseScale) //Diffuse initial conditions are used. + { + //--- Diffuse condition for z0_dv. + z0_sdv.v = z0_dm->M + z0_sdv.n*sti; + z0_0_sdv.v = z0_0_dm->M + z0_0_sdv.n*sti; + bt_sdv.v = bt_dm->M + bt_sdv.n*sti; + InitializeConstantVector_lf(&z0_0_sdv, 0.0); + MatrixTimesVector(&z0_sdv, Ft_dc->C[sti], &z0_0_sdv, 1.0, 0.0, 'N'); + VectorPlusVector(&z0_sdv, &z0_sdv, &bt_sdv); + //--- Diffuse condition for P0_dm. + InitializeDiagonalMatrix_lf(Wnzbynz_dm, kalfilmsinputs_1stapp_ps->DiffuseScale); //To be used for DiffuseScale*I(nz) + CopyMatrix0(P0_dc->C[sti], Wnzbynz_dm); + //Done with W*_dm. + } + else //Unconditional moments for initial conditions are used. + { + InitializeDiagonalMatrix_lf(Wnzbynz_dm, 1.0); //To be used for I(nz) - + InitializeDiagonalMatrix_lf(Wnz2bynz2_dm, 1.0); //To be used for I(nz2) - + + //=== Eigenanalysis to determine the roots to ensure boundedness. + errflag = eigrgen(evals_dzv, (TSdzmatrix *)NULL, (TSdzmatrix *)NULL, Ft_dc->C[sti]); + if (errflag) fn_DisplayError("kalman.c/InitializeKalman_z10_P10(): eigen decomposition failed"); + for (ki=nz-1; ki>=0; ki--) evals_abs_dv->v[ki] = sqrt(square(evals_dzv->real->v[ki]) + square(evals_dzv->imag->v[ki])); + evals_abs_dv->flag = V_DEF; + eigmax = MaxVector(evals_abs_dv); + if (eigmax < (1.0-SQRTEPSILON)) //(1.0+EPSILON)) + { + //--- Getting z0_dv: zt_tm1(:,1) = (eye(n_z)-F(:,:,sti))\b(:,sti); + z0_0_sdv.v = z0_0_dm->M + z0_0_sdv.n*sti; + z0_sdv.v = z0_dm->M + z0_sdv.n*sti; + MatrixMinusMatrix(Wnzbynz_dm, Wnzbynz_dm, Ft_dc->C[sti]); + CopySubmatrix2vector(&z0_0_sdv, 0, bt_dm, 0, sti, bt_dm->nrows); + bdivA_rgens(&z0_0_sdv, &z0_0_sdv, '\\', Wnzbynz_dm); + //- Under the assumption s_0 = s_1 (this is a short-cut). + MatrixTimesVector(&z0_sdv, Ft_dc->C[sti], &z0_0_sdv, 1.0, 0.0, 'N'); + VectorPlusVector(&z0_sdv, &z0_sdv, &bt_sdv); + //Done with Wnzbynz_dm. + //--- Getting P0_dm: Pt_tm1(:,:,1) = reshape((eye(n_z^2)-kron(F(:,:,sti),F(:,:,sti)))\V1(:),n_z,n_z); + tz_kron(W2nz2bynz2_dm, Ft_dc->C[sti], Ft_dc->C[sti]); + MatrixMinusMatrix(Wnz2bynz2_dm, Wnz2bynz2_dm, W2nz2bynz2_dm); + CopySubmatrix2vector(wP0_dv, 0, Vt_dc->C[sti], 0, 0, nz2); + bdivA_rgens(wP0_dv, wP0_dv, '\\', Wnz2bynz2_dm); + CopySubvector2matrix_unr(P0_dc->C[sti], 0, 0, wP0_dv, 0, nz2); + //Done with all w*_dv and W*_dm. + } + else + { + if (0) //0: no printing. + { + #if defined (USE_DEBUG_FILE) + fprintf(FPTR_DEBUG, "\n-------WARNING: ----------\n"); + fprintf(FPTR_DEBUG, "\nIn grand regime sti=%d\n", sti); + fprintf(FPTR_DEBUG, ".../kalman.c/InitializeKalman_z10_P10(): the system is non-stationary solutions\n" + " and see p.003 in LWZ Model II"); + #else + fprintf(stdout, "\n-----------------\n"); + fprintf(stdout, "\nIn grand regime sti=%d\n", sti); + fprintf(stdout, ".../kalman.c/InitializeKalman_z10_P10(): the system is non-stationary solutions\n" + " and see p.003 in LWZ Model II"); + #endif + } + //=== See p.000.3 in LWZ Model II. + //=== Do NOT use the following option. It turns out that this will often generate explosive conditional liklihood + //=== at the end of the sample, because Pt_tm1 shrinks to zero overtime due to the sigularity of + //=== the initila condition P_{1|0}. + //--- Letting z0_dv = 0.0 + // z0_sdv.v = z0_dm->M + z0_sdv.n*sti; + // InitializeConstantVector_lf(&z0_sdv, 0.0); + // //--- Letting P0_dm = V + // CopyMatrix0(P0_dc->C[sti], Vt_dc->C[sti]); + + //=== + DestroyVector_dz(evals_dzv); + DestroyVector_lf(evals_abs_dv); + DestroyMatrix_lf(Wnzbynz_dm); + DestroyMatrix_lf(Wnz2bynz2_dm); + DestroyMatrix_lf(W2nz2bynz2_dm); + DestroyVector_lf(wP0_dv); + + return (0); //Early exit with kalfilmsinputs_1stapp_ps->ztm1_track continues to be -1. + } + } + } + } + else + { + if (!z10_dm) fn_DisplayError(".../kalman.c/InitializeKalman_z10_P10(): The initial condition z_{1|0}\n" + " must be supplied as valid input arguments for when indxIni == 1"); + else + CopyMatrix0(z0_dm, z10_dm); + + if (!P10_dc) fn_DisplayError(".../kalman.c/InitializeKalman_z10_P10(): The initial condition P_{1|0}\n" + " must be supplied as valid input arguments for when indxIni == 1"); + else + CopyCell0(P0_dc, P10_dc); + } + CopyMatrix0(zt_tm1_dc->C[0], z0_dm); //At time t-1 = 1. + CopyCell0(Pt_tm1_d4->F[0], P0_dc); //At time t-1 = 1. + + + kalfilmsinputs_1stapp_ps->ztm1_track = 0; //Must reset to 0, meaning initial setting is done and ready for computing LH at t = 1. + + Update_et_Dt_1stapp(0, kalfilmsinputs_1stapp_ps); + + //=== + DestroyVector_dz(evals_dzv); + DestroyVector_lf(evals_abs_dv); + DestroyMatrix_lf(Wnzbynz_dm); + DestroyMatrix_lf(Wnz2bynz2_dm); + DestroyMatrix_lf(W2nz2bynz2_dm); + DestroyVector_lf(wP0_dv); + + return (1); + } + else + { + fn_DisplayError(".../kalman.c/InitializeKalman_z10_P10(): calling this function makes sense only if" + " kalfilmsinputs_1stapp_ps->ztm1_track is -1. Please check this value."); + + //=== + DestroyVector_dz(evals_dzv); + DestroyVector_lf(evals_abs_dv); + DestroyMatrix_lf(Wnzbynz_dm); + DestroyMatrix_lf(Wnz2bynz2_dm); + DestroyMatrix_lf(W2nz2bynz2_dm); + DestroyVector_lf(wP0_dv); + + return (0); + } +} +//====================================================== +//= Integrating out the lagged regimes in order to +//= updating zt_tm1 and Pt_tm1 for next perid tp1 through Kim-Nelson filter. +//= tdata representing base-0 t timing, while inpt represents base-1 t timing. +// +//= Purpose: for each inpt, we integrate out grand regimes st +//= only ONCE to prevent the dimension of updated zt_tm1 and Pt_tm1 through Kim-Nelson filter. +//====================================================== +static int Updatekalfilms_1stapp(int t_1, struct TSkalfilmsinputs_1stapp_tag *kalfilmsinputs_1stapp_ps, struct TStateModel_tag *smodel_ps) +{ + //Output: + // tm1update + // z_{t_1+1|t_1} + // P_{t_1+1|t_1} + //Input: + // t-1: base-1 t timing. Thus t-1=inpt-1. + + //--- Local variables + int stp1i, sti, t_2, t_2p1; + double prob_previous_regimes; + //-- Output arguments + TSdcell *zt_tm1_dc = kalfilmsinputs_1stapp_ps->zt_tm1_dc; //nz-by-nst-by-(T+1). + TSdfourth *Pt_tm1_d4 = kalfilmsinputs_1stapp_ps->Pt_tm1_d4; //nz-by-nz-by-nst-by-(T+1). + //--- Input arguments + TSdcell *Gt_dc = kalfilmsinputs_1stapp_ps->Gt_dc; //nz-by-ny-by-nst. Cross-covariance. + //+ + TSdmatrix *bt_dm = kalfilmsinputs_1stapp_ps->bt_dm; //nz-by-nst. + TSdcell *Ft_dc = kalfilmsinputs_1stapp_ps->Ft_dc; //nz-by-nz-by-nst. + TSdcell *Vt_dc = kalfilmsinputs_1stapp_ps->Vt_dc; //nz-by-nz-by-nst. Covariance matrix for the state equation. + //+ + TSdfourth *PHtran_tdata_d4 = kalfilmsinputs_1stapp_ps->PHtran_tdata_d4; //nz-by-ny-by-nst-T, saved only for updating Kalman filter Updatekalfilms_1stapp(). + TSdcell *etdata_dc = kalfilmsinputs_1stapp_ps->etdata_dc; //ny-by-nst-by-T, save for computing the likelihood. + TSdfourth *Dtdata_d4 = kalfilmsinputs_1stapp_ps->Dtdata_d4; //ny-by-ny-nst-by-T, save for computing the likelihood and updating Kalman filter Updatekalfilms_1stapp(). + //--- Accessible variables + int ny = kalfilmsinputs_1stapp_ps->ny; + int nz = kalfilmsinputs_1stapp_ps->nz; + int nst = kalfilmsinputs_1stapp_ps->nst; + int T = kalfilmsinputs_1stapp_ps->T; + TSdvector z0_sdv; + TSdvector btp1_sdv; + TSdvector etdata_sdv; + //=== Work arguments. + TSdmatrix *Wnzbynz_dm = CreateMatrix_lf(nz,nz); + //+ + TSdmatrix *Wnzbyny_dm = CreateMatrix_lf(nz,ny); + TSdmatrix *W2nzbynz_dm = CreateMatrix_lf(nz,nz); + TSdmatrix *Kt_tdata0_dm = CreateMatrix_lf(nz,ny); + TSdmatrix *Kt_tdata_dm = CreateMatrix_lf(nz,ny); + //=== For updating zt_tm1_dm and Pt_tm1. + TSdvector *ztp1_t_dv = CreateVector_lf(nz); + TSdmatrix *Ptp1_t_dm = CreateMatrix_lf(nz, nz); + TSdvector *ztp1_dv = CreateVector_lf(nz); + TSdmatrix *Ptp1_dm = CreateMatrix_lf(nz, nz); + + + //--- Critical checking. + if (kalfilmsinputs_1stapp_ps->ztm1_track < 0) + fn_DisplayError(".../kalman.c/Updatekalfilms_1stapp(): Make sure InitializeKalman_z10_P10() is called in the function RefreshEverthing()"); + + + z0_sdv.n = nz; + z0_sdv.flag = V_DEF; + btp1_sdv.n = nz; + btp1_sdv.flag = V_DEF; + //+ + etdata_sdv.n = ny; + etdata_sdv.flag = V_DEF; + + for (t_2=kalfilmsinputs_1stapp_ps->ztm1_track; t_2<t_1; t_2++) + { + //If t_1 <= ztm1_track, no updating. + //If t_1 > ztm1_track, updating z_{t|t-1} and P_{t|t-1} up to t-1 = t_1. + + zt_tm1_dc->C[t_2p1=t_2+1]->flag = M_GE; + for (stp1i=nst-1; stp1i>=0; stp1i--) + { + InitializeConstantVector_lf(ztp1_dv, 0.0); //To be summed over sti. + InitializeConstantMatrix_lf(Ptp1_dm, 0.0); //To be summed over sti. + + for (sti=nst-1; sti>=0; sti--) + { + //=== Updating for next period by integrating out sti.. + //--- Ktp1_t = (F_tp1*PHtran_t+G(:,:,t))/Dt; + //--- Kt_tdata = (Ft*PHtran_tdata+G(:,:,tdata))/Dtdata where t=tp1 and tdata=t. + CopyMatrix0(Kt_tdata0_dm, Gt_dc->C[sti]); + MatrixTimesMatrix(Kt_tdata0_dm, Ft_dc->C[stp1i], PHtran_tdata_d4->F[t_2]->C[sti], 1.0, 1.0, 'N', 'N'); + BdivA_rrect(Kt_tdata_dm, Kt_tdata0_dm, '/', Dtdata_d4->F[t_2]->C[sti]); + //+ zt_tm1(:,t) = b(:,t) + Ft*zt_tm1(:,tdata) + Kt_tdata*etdata where t=tp1 and tm1=t. + etdata_sdv.v = etdata_dc->C[t_2]->M + ny*sti; + z0_sdv.v = zt_tm1_dc->C[t_2]->M + nz*sti; //sti: regime at time t_2. + MatrixTimesVector(ztp1_t_dv, Ft_dc->C[stp1i], &z0_sdv, 1.0, 0.0, 'N'); + MatrixTimesVector(ztp1_t_dv, Kt_tdata_dm, &etdata_sdv, 1.0, 1.0, 'N'); + btp1_sdv.v = bt_dm->M + stp1i*btp1_sdv.n; + VectorPlusMinusVectorUpdate(ztp1_t_dv, &btp1_sdv, 1.0); + //+ Pt_tm1(:,:,t) = Ft*Ptdata*Fttran - Kt_tdata*Dtdata*Kt_tdatatran + V(:,:,t); + CopyMatrix0(Ptp1_t_dm, Vt_dc->C[stp1i]); + MatrixTimesMatrix(Wnzbyny_dm, Kt_tdata_dm, Dtdata_d4->F[t_2]->C[sti], 1.0, 0.0, 'N', 'N'); + MatrixTimesMatrix(Wnzbynz_dm, Wnzbyny_dm, Kt_tdata_dm, 1.0, 0.0, 'N', 'T'); + MatrixPlusMinusMatrixUpdate(Ptp1_t_dm, Wnzbynz_dm, -1.0); + //Done with all W*_dm. + MatrixTimesMatrix(Wnzbynz_dm, Ft_dc->C[stp1i], Pt_tm1_d4->F[t_2]->C[sti], 1.0, 0.0, 'N', 'N'); + MatrixTimesMatrix(W2nzbynz_dm, Wnzbynz_dm, Ft_dc->C[stp1i], 1.0, 0.0, 'N', 'T'); + MatrixPlusMatrixUpdate(Ptp1_t_dm, W2nzbynz_dm); + //Done with all W*_dm. + + + //--- Integrating out the state at t_2 using + //--- P(s_t_2|Y_{t_2}, theta) = ProbabilityStateConditionalCurrent(sti, t_2, smodel_ps); + //--- One can also access to P(s_t_2|Y_{t_2}, theta) by using ElementV(smodel_ps->V[t_2],s_{t_2}i), + //--- but this access will not call my function logTimetCondLH(), thus no updating for + //--- P(s_t_2|Y_{t_2}, and thus leading to incorrect results. + prob_previous_regimes = ProbabilityStateConditionalCurrent(sti, t_2, smodel_ps); + ScalarTimesVectorUpdate(ztp1_dv, prob_previous_regimes, ztp1_t_dv); + ScalarTimesMatrix(Ptp1_dm, prob_previous_regimes, Ptp1_t_dm, 1.0); + Ptp1_dm->flag = M_GE | M_SU | M_SL; + //Done with ztp1_t_dv and Ptp1_t_dm. + } + //--- Filling zt_tm1 and Pt_tm1 for next period. + z0_sdv.v = zt_tm1_dc->C[t_2p1]->M + z0_sdv.n*stp1i; //stp1i: regime at time tp1. + CopyVector0(&z0_sdv, ztp1_dv); + CopyMatrix0(Pt_tm1_d4->F[t_2p1]->C[stp1i], Ptp1_dm); //stp1i: regime at time tp1. + //Done with ztp1_dv, z0_sdv, Ptp1_dm. + } + //--- $$$ The following is important because it tells ProbabilityStateConditionalCurrent(), which calls + //--- $$$ logTimetCondLH_kalfilms_1stapp(), which calls recursively this function again, that there is no + //--- $$$ need to update Kalman filter for the period before kalfilmsinputs_1stapp_ps->ztm1_track. + kalfilmsinputs_1stapp_ps->ztm1_track = t_2p1; //Means that z_{t_2p1+1|t_2p1} and P_{t_2p1+1|t_2p1} are done. + + //--- $$$ This function must be called after all the above computations are done. + Update_et_Dt_1stapp(t_2p1, kalfilmsinputs_1stapp_ps); + } + + + //=== + DestroyMatrix_lf(Wnzbynz_dm); + // + DestroyMatrix_lf(Wnzbyny_dm); + DestroyMatrix_lf(W2nzbynz_dm); + DestroyMatrix_lf(Kt_tdata0_dm); + DestroyMatrix_lf(Kt_tdata_dm); + // + DestroyVector_lf(ztp1_t_dv); + DestroyMatrix_lf(Ptp1_t_dm); + DestroyVector_lf(ztp1_dv); + DestroyMatrix_lf(Ptp1_dm); + + return (kalfilmsinputs_1stapp_ps->ztm1_track); +} +//====================================================== +//= Computes etdata and Dtdata for all grand regimes st at tbase0=inpt-1 or dtm1_track +//= to prevent recomputing this object for different st at given tbase0. +//====================================================== +static int Update_et_Dt_1stapp(int t_1, struct TSkalfilmsinputs_1stapp_tag *kalfilmsinputs_1stapp_ps) +{ + //Output: + // dtm1_track is updated in this function. + // PHtran_tdata_d4->F[t-1] + // etdata_dc->C[t-1] + // Dtdata_d4->F[t-1] + //Input: + // t_1=inpt-1: base-0 timing for et and Dt before the likelihood at time inpt is computed. + + //--- Local variables + int sti, tbase0; + //-- Output arguments + TSdfourth *PHtran_tdata_d4 = kalfilmsinputs_1stapp_ps->PHtran_tdata_d4; //nz-by-ny-by-nst-T, saved only for updating Kalman filter Updatekalfilms_1stapp(). + TSdcell *etdata_dc = kalfilmsinputs_1stapp_ps->etdata_dc; //ny-by-nst-by-T, save for computing the likelihood. + TSdcell *yt_tm1_dc = kalfilmsinputs_1stapp_ps->yt_tm1_dc; //ny-by-nst-by-T, one-step forecast y_{t|t-1} for t=0 to T-1 (base-0). + TSdfourth *Dtdata_d4 = kalfilmsinputs_1stapp_ps->Dtdata_d4; //ny-by-ny-nst-by-T, save for computing the likelihood and updating Kalman filter Updatekalfilms_1stapp(). + //--- input arguments + TSdcell *zt_tm1_dc = kalfilmsinputs_1stapp_ps->zt_tm1_dc; //nz-by-nst-by-T. + TSdfourth *Pt_tm1_d4 = kalfilmsinputs_1stapp_ps->Pt_tm1_d4; //nz-by-nz-by-nst-by-T. + //+ + TSdmatrix *yt_dm = kalfilmsinputs_1stapp_ps->yt_dm; //ny-by-T. + TSdmatrix *at_dm = kalfilmsinputs_1stapp_ps->at_dm; //ny-by-nst. + TSdcell *Ht_dc = kalfilmsinputs_1stapp_ps->Ht_dc; //ny-by-nz-by-nst. + TSdcell *Rt_dc = kalfilmsinputs_1stapp_ps->Rt_dc; //ny-by-ny-by-nst. Covariance matrix for the measurement equation. + //--- Accessible variables + int ny = kalfilmsinputs_1stapp_ps->ny; + int nz = kalfilmsinputs_1stapp_ps->nz; + int nst = kalfilmsinputs_1stapp_ps->nst; + TSdvector z0_sdv; + TSdvector yt_sdv, at_sdv; + TSdvector etdata_sdv, yt_tm1_sdv; + //=== Work arguments. + TSdmatrix *PHtran_tdata_dm = CreateMatrix_lf(nz,ny); + TSdmatrix *Dtdata_dm = CreateMatrix_lf(ny,ny); + + + z0_sdv.n = nz; + z0_sdv.flag = V_DEF; + at_sdv.n = yt_sdv.n = ny; + at_sdv.flag = yt_sdv.flag = V_DEF; + etdata_sdv.n = yt_tm1_sdv.n = ny; + etdata_sdv.flag = yt_tm1_sdv.flag = V_DEF; + + for (tbase0=(kalfilmsinputs_1stapp_ps->dtm1_track+1); tbase0<=t_1; tbase0++) + { + //Note tbase0<=t_1, NOT tbase0<t_1. + //If t_1 < (dtm1_track+1), no updating. + //If t_1 >= (dtm1_track+1), updating etdata_dc->C[t-1] and Dtdata_d4->F[t-1] up to t-1=t_1. + + for (sti=nst-1; sti>=0; sti--) + { + //--- Setup. + MatrixTimesMatrix(PHtran_tdata_dm, Pt_tm1_d4->F[tbase0]->C[sti], Ht_dc->C[sti], 1.0, 0.0, 'N', 'T'); + CopyMatrix0(kalfilmsinputs_1stapp_ps->PHtran_tdata_d4->F[tbase0]->C[sti], PHtran_tdata_dm); + + + //--- Data. + //- etdata = Y_T(:,tdata) - a(:,tdata) - Htdata*ztdata where tdata = tbase0 = inpt-1. + yt_sdv.v = yt_dm->M + tbase0*yt_dm->nrows; + at_sdv.v = at_dm->M + sti*at_dm->nrows; //grand regime at time tbase0. + z0_sdv.v = zt_tm1_dc->C[tbase0]->M + z0_sdv.n*sti; //sti: regime at time tbase0. + etdata_sdv.v = etdata_dc->C[tbase0]->M + etdata_sdv.n*sti; + yt_tm1_sdv.v = etdata_dc->C[tbase0]->M + yt_tm1_sdv.n*sti; + CopyVector0(&yt_tm1_sdv, &at_sdv); + MatrixTimesVector(&yt_tm1_sdv, Ht_dc->C[sti], &z0_sdv, 1.0, 1.0, 'N'); //a + H*z_{t|t-1}. + VectorMinusVector(&etdata_sdv, &yt_sdv, &yt_tm1_sdv); //y_t - a - H*z_{t|t-1}. + //+ Dtdata = Htdata*PHtran_tdata + R(:,:,tbase0); + CopyMatrix0(Dtdata_dm, Rt_dc->C[sti]); + MatrixTimesMatrix(Dtdata_dm, Ht_dc->C[sti], PHtran_tdata_dm, 1.0, 1.0, 'N', 'N'); + //Done with z0_sdv.v. + ScalarTimesMatrixSquare(Dtdata_dm, 0.5, Dtdata_dm, 'T', 0.5); //Making it symmetric against some rounding errors. + //This making-symmetric is very IMPORTANT; otherwise, we will get the matrix being singular message + // and eigenvalues being negative for the SPD matrix, etc. Then the likelihood becomes either + // a bad number or a complex number. + Dtdata_dm->flag = Dtdata_dm->flag | M_SU | M_SL; + CopyMatrix0(Dtdata_d4->F[tbase0]->C[sti], Dtdata_dm); //Saved to be used for logTimetCondLH_kalfilms_1stapp(). + } + + //--- $$$ This tracker functions the same way as kalfilmsinputs_1stapp_ps->ztm1_track. + kalfilmsinputs_1stapp_ps->dtm1_track = tbase0; + } + + //=== + DestroyMatrix_lf(PHtran_tdata_dm); + DestroyMatrix_lf(Dtdata_dm); + + return (kalfilmsinputs_1stapp_ps->dtm1_track); +} + + + + + + +//----------------------------------------------------- +//------------ OLD Code -------------------------- +//- Updating or refreshing all Kalman filter at time t for Markov-switching DSGE model. +//- WARNING: make sure to call the following functions +// RunningGensys_const7varionly(lwzmodel_ps); +// Refresh_kalfilms_*(lwzmodel_ps); //Creates or refreshes kalfilmsinputs_ps at new parameter values. +//- before using tz_Refresh_z_T7P_T_in_kalfilms_1st_approx(). +// +//- IMPORTANT NOTE: in the Markov-switching input file datainp_markov*.prn, it MUST be that +//- the coefficient regime is the 1st state variable, and +//- the volatility regime is the 2nd state variable. +//----------------------------------------------------- +#if defined (NEWVERSIONofDW_SWITCH) +double tz_logTimetCondLH_kalfilms_1st_approx(int st, int inpt, struct TSkalfilmsinputs_tag *kalfilmsinputs_ps, struct TStateModel_tag *smodel_ps) +{ + //st, st_c, and st_v: base-0: deals with the cross-section values at time t where + // st is a grand regime, st_c is an encoded coefficient regime, and st_c is an encoded volatility regime. + //inpt: base-1 in the sense that inpt>=1 to deal with the time series situation where S_T is (T+1)-by-1 and Y_T is T+nlags_max-by-1. + // The 1st element for S_T is S_T[1] while S_T[0] is s_0 (initial condition). + // The 1st element for Y_T, however, is Y_T[nlags_max+1-1]. + //See (42.3) on p.42 in the SWZII NOTES. + + + //--- Local variables + int comst_c; //composite (s_tc, s_{t-1}c) + int st_c, stm1_c, st_v; + int comsti_c; //composite (s_tc, s_{t-1}c) + int sti, sti_c, stm1i_c, sti_v; + int comstp1i_c; //composite (s_{t+1}c, s_tc) + int stp1i, stp1i_c, stp1i_v; + int tbase0, tp1; + double logdet_Dtdata, loglh_timet; + static int record_tbase1_or_inpt_or_tp1 = 0; + static int passonce; + double prob_previous_regimes; + //=== Accessible variables + int ny = kalfilmsinputs_ps->ny; + int nz = kalfilmsinputs_ps->nz; + int nRc = kalfilmsinputs_ps->nRc; + int nRstc = kalfilmsinputs_ps->nRstc; + int nRv = kalfilmsinputs_ps->nRv; + int T = kalfilmsinputs_ps->T; + int indxIndRegimes = kalfilmsinputs_ps->indxIndRegimes; + int **Index = smodel_ps->sv->index; //Regime-switching states. + //smodel_ps->sv->index is for our new code. + // For old code (before 9 April 08 and before dsge_switch is created), use smodel_ps->sv->Index; + TSdvector z0_sdv; + //+ input arguments. + TSdmatrix *yt_dm = kalfilmsinputs_ps->yt_dm; //ny-by-T. + TSdmatrix *at_dm = kalfilmsinputs_ps->at_dm; //ny-by-nRc. + TSdcell *Ht_dc = kalfilmsinputs_ps->Ht_dc; //ny-by-nz-by-nRc. + TSdcell *Rt_dc = kalfilmsinputs_ps->Rt_dc; //ny-by-ny-by-nRv. Covariance matrix for the measurement equation. + TSdcell *Gt_dc = kalfilmsinputs_ps->Gt_dc; //nz-by-ny-by-nRv. Cross-covariance. + // + TSdmatrix *bt_dm = kalfilmsinputs_ps->bt_dm; //nz-by-nRc. + TSdcell *Ft_dc = kalfilmsinputs_ps->Ft_dc; //nz-by-nz-by-nRc. + TSdcell *Vt_dc = kalfilmsinputs_ps->Vt_dc; //nz-by-nz-by-nRv. Covariance matrix for the state equation. + // + TSdmatrix *z0_dm = kalfilmsinputs_ps->z0_dm; //nz-by-nRc*nRv or nz-by-nRv, depending on indxIndRegimes. + TSdcell *P0_dc = kalfilmsinputs_ps->P0_dc; //nz-by-nz-by-nRc*nRv or nz-by-nRv, depending on indxIndRegimes. + //+ Output arguments. + TSdcell *zt_tm1_dc = kalfilmsinputs_ps->zt_tm1_dc; //nz-by-nRc*nRv-by-T if indxIndRegimes==1, nz-by-nRv-by-T if indxIndRegimes==0 where nRc=nRv. + TSdfourth *Pt_tm1_d4 = kalfilmsinputs_ps->Pt_tm1_d4; //nz-by-nz-by-nRc*nRv-T if indxIndRegimes==1, nz-by-nz-by-nRv-by-T if indxIndRegimes==0 where nRc=nRv. + //=== Work arguments. + int nz2 = square(nz); + TSdmatrix *Wnzbynz_dm = CreateMatrix_lf(nz,nz); + TSdmatrix *Wnz2bynz2_dm = CreateMatrix_lf(nz2,nz2); + TSdmatrix *W2nz2bynz2_dm = CreateMatrix_lf(nz2,nz2); + TSdvector *wP0_dv = CreateVector_lf(nz2); + //+ + TSdvector yt_sdv, at_sdv, btp1_sdv; //zt_tm1_sdv, ztp1_t_sdv, + TSdvector *wny_dv = CreateVector_lf(ny); + TSdmatrix *Wnzbyny_dm = CreateMatrix_lf(nz,ny); + TSdmatrix *W2nzbynz_dm = CreateMatrix_lf(nz,nz); + TSdmatrix *PHtran_tdata_dm = CreateMatrix_lf(nz,ny); + TSdvector *etdata_dv = CreateVector_lf(ny); + TSdmatrix *Dtdata_dm = CreateMatrix_lf(ny,ny); + TSdmatrix *Kt_tdata0_dm = CreateMatrix_lf(nz,ny); + TSdmatrix *Kt_tdata_dm = CreateMatrix_lf(nz,ny); + //--- For eigenvalue decompositions + int ki; + int errflag; + double eigmax; + TSdzvector *evals_dzv = evals_dzv = CreateVector_dz(nz); + TSdvector *evals_abs_dv = CreateVector_lf(nz); //Absolute eigenvalues. + //--- For updating zt_tm1_dm and Pt_tm1. + TSdvector *ztp1_t_dv = CreateVector_lf(z0_dm->nrows); + TSdmatrix *Ptp1_t_dm = CreateMatrix_lf(nz, nz); + TSdvector *ztp1_dv = CreateVector_lf(z0_dm->nrows); + TSdmatrix *Ptp1_dm = CreateMatrix_lf(nz, nz); + + + + if (smodel_ps->sv->nstates != z0_dm->ncols) fn_DisplayError("kalman.c/tz_logTimetLH_kalfilms_1st_approx():\n" + " Make sure that the column dimension of z0_dm is the same as smodel_ps->sv->nstates"); + if (indxIndRegimes && (nRc>1) && (nRv>1)) + if (smodel_ps->sv->n_state_variables != 2) fn_DisplayError("kalman.c/tz_Refresh_z_T7P_T_in_kalfilms_1st_approx():\n" + " Number of state variables must be coincide with indxIndRegimes"); + + tbase0 = (tp1=inpt) - 1; + + z0_sdv.n = z0_dm->nrows; + z0_sdv.flag = V_DEF; + // + at_sdv.n = yt_sdv.n = yt_dm->nrows; + at_sdv.flag = yt_sdv.flag = V_DEF; + btp1_sdv.n = bt_dm->nrows; + btp1_sdv.flag = V_DEF; + + + //======= Initial condition. ======= + if (tbase0==0) + { + for (sti=smodel_ps->sv->nstates-1; sti>=0; sti--) + { + if (indxIndRegimes) + { + if (nRc==1) //Volatility. + { + comsti_c = sti_c = 0; + sti_v = sti; + } + else if ((nRv>1) && (nRc>nRstc)) //Trend inflation, both sc_t and sc_{t-1} enters coefficient regime. + { + comsti_c = Index[sti][0]; //composite (s_tc, s_{t-1}c) + sti_v = Index[sti][1]; //volatility state s_tv + sti_c = smodel_ps->sv->state_variable[0]->lag_index[comsti_c][0]; //coefficient regime at t. + stm1i_c = smodel_ps->sv->state_variable[0]->lag_index[comsti_c][1]; //coefficient regime at t-1: tm1: t-1; + } + else if ((nRv==1) && (nRc>nRstc)) + { + comsti_c = Index[sti][0]; //composite (s_tc, s_{t-1}c) + sti_c = smodel_ps->sv->state_variable[0]->lag_index[comsti_c][0]; //coefficient regime at t. + stm1i_c = smodel_ps->sv->state_variable[0]->lag_index[comsti_c][1]; //coefficient regime at t-1: tm1: t-1; + sti_v = 0; + } + else if ((nRv==1) && (nRc==nRstc)) + { + comsti_c = sti_c = sti; + sti_v = 0; + } + else if ((nRv>1) && (nRc==nRstc)) //only sc_t enters coefficient regime. + { + comsti_c = sti_c = Index[sti][0]; + sti_v = Index[sti][1]; + } + } + else //Syncronized regimes. + { + if (nRc>nRstc) + { + comsti_c = Index[sti][0]; //composite (s_tc, s_{t-1}c) + sti_c = smodel_ps->sv->state_variable[0]->lag_index[comsti_c][0]; //coefficient regime at t. + stm1i_c = smodel_ps->sv->state_variable[0]->lag_index[comsti_c][1]; //coefficient regime at t-1: tm1: t-1; + sti_v = sti_c; + } + else + comsti_c = sti_c = sti_v = sti; + } + + + if (!kalfilmsinputs_ps->indxIni) + { + InitializeDiagonalMatrix_lf(Wnzbynz_dm, 1.0); //To be used for I(nz) - + InitializeDiagonalMatrix_lf(Wnz2bynz2_dm, 1.0); //To be used for I(nz2) - + + //=== Eigenanalysis to determine the roots to ensure boundedness. + errflag = eigrgen(evals_dzv, (TSdzmatrix *)NULL, (TSdzmatrix *)NULL, Ft_dc->C[comsti_c]); + if (errflag) fn_DisplayError("kalman.c/tz_Refresh_z_T7P_T_in_kalfilms_1st_approx(): eigen decomposition failed"); + for (ki=nz-1; ki>=0; ki--) evals_abs_dv->v[ki] = sqrt(square(evals_dzv->real->v[ki]) + square(evals_dzv->imag->v[ki])); + evals_abs_dv->flag = V_DEF; + eigmax = MaxVector(evals_abs_dv); + if (eigmax < (1.0+1.0e-14)) + { + //--- Getting z0_dv: zt_tm1(:,1) = (eye(n_z)-F(:,:,1))\b(:,1); + MatrixMinusMatrix(Wnzbynz_dm, Wnzbynz_dm, Ft_dc->C[comsti_c]); + z0_sdv.v = z0_dm->M + z0_sdv.n*sti; + CopySubmatrix2vector(&z0_sdv, 0, bt_dm, 0, comsti_c, bt_dm->nrows); + bdivA_rgens(&z0_sdv, &z0_sdv, '\\', Wnzbynz_dm); + //Done with Wnzbynz_dm. + //--- Getting P0_dm: Pt_tm1(:,:,1) = reshape((eye(n_z^2)-kron(F(:,:,1),F(:,:,1)))\V1(:),n_z,n_z); + tz_kron(W2nz2bynz2_dm, Ft_dc->C[comsti_c], Ft_dc->C[comsti_c]); + MatrixMinusMatrix(Wnz2bynz2_dm, Wnz2bynz2_dm, W2nz2bynz2_dm); + CopySubmatrix2vector(wP0_dv, 0, Vt_dc->C[sti_v], 0, 0, nz2); +//=== ???????? For debugging purpose. +//if ((inpt<2) && (st==0)) +//{ +// fprintf(FPTR_DEBUG, "%%st=%d, inpt=%d, and sti=%d\n", st, inpt, sti); + +// fprintf(FPTR_DEBUG, "wP0_dv:\n"); +// WriteVector(FPTR_DEBUG, wP0_dv, " %10.5f "); +// fprintf(FPTR_DEBUG, "Vt_dc->C[sti_v=%d]:\n", sti_v); +// WriteMatrix(FPTR_DEBUG, Vt_dc->C[sti_v], " %10.5f "); + +// fflush(FPTR_DEBUG); + +//} + bdivA_rgens(wP0_dv, wP0_dv, '\\', Wnz2bynz2_dm); + CopySubvector2matrix_unr(P0_dc->C[sti], 0, 0, wP0_dv, 0, nz2); + //Done with all w*_dv and W*_dm. + } + else + { + fprintf(stdout, "\n-----------------\n"); + fprintf(stdout, "\nIn regime comsti_c=%d and sti_v=%d and at time=%d\n", comsti_c, sti_v, 0); + fn_DisplayError("kalman.c/tz_Refresh_z_T7P_T_in_kalfilms_1st_approx(): the system is non-stationary solutions\n" + " and the initial conditions must be supplied by, say, input arguments"); + fflush(stdout); + } + } + } + z0_dm->flag = M_GE; + CopyMatrix0(zt_tm1_dc->C[0], z0_dm); //At time t=0. + CopyCell0(Pt_tm1_d4->F[0], P0_dc); //At time t=0. + } + + + //====================================================== + //= Getting the logLH at time tbase0 or time inpt. + //====================================================== + if (indxIndRegimes ) + { + if (nRc==1) //Volatility. + { + comst_c = st_c = 0; + st_v = st; + } + else if ((nRv>1) && (nRc>nRstc)) //Trend inflation, both sc_t and sc_{t-1} enters coefficient regime. + { + if (smodel_ps->sv->n_state_variables != 2) fn_DisplayError("kalman.c/kalfilms_timet_1st_approx():\n" + " Number of state variables must be coincide with indxIndRegimes"); + + comst_c = Index[st][0]; //composite (s_tc, s_{t-1}c) + st_v = Index[st][1]; //volatility state s_tv + st_c = smodel_ps->sv->state_variable[0]->lag_index[comst_c][0]; //coefficient regime at t. + stm1_c = smodel_ps->sv->state_variable[0]->lag_index[comst_c][1]; //coefficient regime at t-1: tm1: t-1; + } + else if ((nRv==1) && (nRc>nRstc)) + { + comst_c = Index[st][0]; //composite (s_tc, s_{t-1}c) + st_c = smodel_ps->sv->state_variable[0]->lag_index[comst_c][0]; //coefficient regime at t. + stm1_c = smodel_ps->sv->state_variable[0]->lag_index[comst_c][1]; //coefficient regime at t-1: tm1: t-1; + st_v = 0; + } + else if ((nRv==1) && (nRc==nRstc)) + { + comst_c = st_c = st; + st_v = 0; + } + else if ((nRv>1) && (nRc==nRstc)) //only sc_t enters coefficient regime. + { + if (smodel_ps->sv->n_state_variables != 2) fn_DisplayError("kalman.c/kalfilms_timet_1st_approx():\n" + " Number of state variables must be coincide with indxIndRegimes"); + + comst_c = st_c = Index[st][0]; + st_v = Index[st][1]; + } + } + else //Syncronized regimes + { + if (nRc>nRstc) + { + comst_c = Index[st][0]; //composite (s_tc, s_{t-1}c) + st_c = smodel_ps->sv->state_variable[0]->lag_index[comst_c][0]; //coefficient regime at t. + stm1_c = smodel_ps->sv->state_variable[0]->lag_index[comst_c][1]; //coefficient regime at t-1: tm1: t-1; + st_v = st_c; + } + else + comst_c = st_c = st_v = st; + } + + + z0_sdv.n = zt_tm1_dc->C[0]->nrows; + z0_sdv.flag = V_DEF; + // + at_sdv.n = yt_sdv.n = yt_dm->nrows; + at_sdv.flag = yt_sdv.flag = V_DEF; + + //====== Computing the conditional LH at time t. ====== + //--- Setup. + MatrixTimesMatrix(PHtran_tdata_dm, Pt_tm1_d4->F[tbase0]->C[st], Ht_dc->C[comst_c], 1.0, 0.0, 'N', 'T'); + + //--- Data. + //- etdata = Y_T(:,tdata) - a(:,tdata) - Htdata*ztdata where tdata = tbase0 = inpt-1. + yt_sdv.v = yt_dm->M + tbase0*yt_dm->nrows; + at_sdv.v = at_dm->M + comst_c*at_dm->nrows; //comst_c: coefficient regime at time tbase0. + z0_sdv.v = zt_tm1_dc->C[tbase0]->M + z0_sdv.n*st; //st: regime at time tbase0 for zt_tm1. + VectorMinusVector(etdata_dv, &yt_sdv, &at_sdv); + MatrixTimesVector(etdata_dv, Ht_dc->C[comst_c], &z0_sdv, -1.0, 1.0, 'N'); + //+ Dtdata = Htdata*PHtran_tdata + R(:,:,tbase0); + CopyMatrix0(Dtdata_dm, Rt_dc->C[st_v]); + MatrixTimesMatrix(Dtdata_dm, Ht_dc->C[comst_c], PHtran_tdata_dm, 1.0, 1.0, 'N', 'N'); + ScalarTimesMatrixSquare(Dtdata_dm, 0.5, Dtdata_dm, 'T', 0.5); //Making it symmetric against some rounding errors. + //This making-symmetric is very IMPORTANT; otherwise, we will get the matrix being singular message + // and eigenvalues being negative for the SPD matrix, etc. Then the likelihood becomes either + // a bad number or a complex number. + Dtdata_dm->flag = Dtdata_dm->flag | M_SU | M_SL; + + + //--- Forming the log conditional likelihood at t. + if (!isfinite(logdet_Dtdata=logdetspd(Dtdata_dm))) return (loglh_timet = -NEARINFINITY); + bdivA_rgens(wny_dv, etdata_dv, '/', Dtdata_dm); +//if ((inpt>82) && (inpt<86) ) +//{ +// //Must be declared at the top of this "if" block. +// int kip1; +// double tmp_Dtdata; +// double tmp_expterm; + +// fprintf(FPTR_DEBUG, "%%------------------------\n"); +// fprintf(FPTR_DEBUG, "%%st=%d and inpt=%d\n", st, inpt); +// fprintf(FPTR_DEBUG, "loglh_timet = %10.5f;\n", loglh_timet); + + +// fprintf(FPTR_DEBUG, "wny_dv:\n"); +// WriteVector(FPTR_DEBUG, wny_dv, " %10.5f "); +// fprintf(FPTR_DEBUG, "etdata_dv:\n"); +// WriteVector(FPTR_DEBUG, etdata_dv, " %10.5f "); +// fprintf(FPTR_DEBUG, "Dtdata_dm:\n"); +// WriteMatrix(FPTR_DEBUG, Dtdata_dm, " %.16e "); + +// fflush(FPTR_DEBUG); +//} + loglh_timet = -(0.5*ny)*LOG2PI - 0.5*logdet_Dtdata - 0.5*VectorDotVector(wny_dv, etdata_dv); + //Done with all w*_dv. + + + + +//=== ???????? For debugging purpose. +if (inpt==1) +{ + double wk1, wk2; + + wk1 = logdet_Dtdata; + wk2 = VectorDotVector(wny_dv, etdata_dv); + fprintf(FPTR_DEBUG, "logdet_Dtdata = %10.5f\n", wk1); + fprintf(FPTR_DEBUG, "VectorDotVector(wny_dv, etdata_dv) = %10.5f\n", wk2); + fprintf(FPTR_DEBUG, "----- etdata_dv: \n"); + WriteVector(FPTR_DEBUG, etdata_dv, " %10.5f "); + fprintf(FPTR_DEBUG, "----- yt_dv: \n"); + WriteVector(FPTR_DEBUG, &yt_sdv, " %10.5f "); + fprintf(FPTR_DEBUG, "----- at_dv: \n"); + WriteVector(FPTR_DEBUG, &at_sdv, " %10.5f "); + fprintf(FPTR_DEBUG, "----- z0_dv: \n"); + WriteVector(FPTR_DEBUG, &z0_sdv, " %10.5f "); + fprintf(FPTR_DEBUG, "----- Ht_dc->C[comst_c=%d]:\n", comst_c); + WriteMatrix(FPTR_DEBUG, Ht_dc->C[comst_c], " %10.5f "); + + fprintf(FPTR_DEBUG, "\n\n"); + +} +// +fprintf(FPTR_DEBUG, " %10.5f\n", loglh_timet); +fflush(FPTR_DEBUG); + + +//=== ???????? For debugging purpose. +//fprintf(FPTR_DEBUG, "------------------------\n"); +//fprintf(FPTR_DEBUG, "st=%d and inpt=%d\n", st, inpt); +//fprintf(FPTR_DEBUG, "loglh_timet = %10.5f\n", loglh_timet); +//fprintf(FPTR_DEBUG, "&yt_sdv:\n"); +//WriteVector(FPTR_DEBUG, &yt_sdv, " %10.5f "); +////WriteVector(FPTR_DEBUG, etdata_dv, " %10.5f "); +////fprintf(FPTR_DEBUG, "\n"); +////WriteMatrix(FPTR_DEBUG, Dtdata_dm, " %10.5f "); +//fflush(FPTR_DEBUG); + + +//=== ???????? For debugging purpose. +//if ((inpt>82) && (inpt<86) ) +//if (inpt<2) +//{ +// //Must be declared at the top of this "if" block. +// int kip1; +// double tmp_Dtdata; +// double tmp_expterm; + +// fprintf(FPTR_DEBUG, "%%------------------------\n"); +// fprintf(FPTR_DEBUG, "%%st=%d and inpt=%d\n", st, inpt); +// fprintf(FPTR_DEBUG, "loglh_timet = %10.5f;\n", loglh_timet); + + +// tmp_Dtdata = logdeterminant(Dtdata_dm); +// tmp_expterm = VectorDotVector(wny_dv, etdata_dv); +// fprintf(FPTR_DEBUG, "logdeterminant(Dtdata_dm) = %10.5f;\n", tmp_Dtdata); +// fprintf(FPTR_DEBUG, "VectorDotVector(wny_dv, etdata_dv) = %10.5f;\n", tmp_expterm); +// fprintf(FPTR_DEBUG, "wny_dv:\n"); +// WriteVector(FPTR_DEBUG, wny_dv, " %10.5f "); +// fprintf(FPTR_DEBUG, "etdata_dv:\n"); +// WriteVector(FPTR_DEBUG, etdata_dv, " %10.5f "); +// fprintf(FPTR_DEBUG, "&yt_sdv:\n"); +// WriteVector(FPTR_DEBUG, &yt_sdv, " %10.5f "); +// fprintf(FPTR_DEBUG, "&at_sdv:\n"); +// WriteVector(FPTR_DEBUG, &at_sdv, " %10.5f "); +// fprintf(FPTR_DEBUG, "&z0_sdv:\n"); +// WriteVector(FPTR_DEBUG, &z0_sdv, " %10.5f "); +// fprintf(FPTR_DEBUG, "Ht_dc->C[comst_c=%d]:\n",comst_c); +// WriteMatrix(FPTR_DEBUG, Ht_dc->C[comst_c], " %10.5f "); +// fprintf(FPTR_DEBUG, "Rt_dc->C[st_v=%d]:\n", st_v); +// WriteMatrix(FPTR_DEBUG, Rt_dc->C[st_v], " %10.5f "); +// fprintf(FPTR_DEBUG, "Pt_tm1_d4->F[tbase0]->C[st = %d]:\n",st); +// WriteMatrix(FPTR_DEBUG, Pt_tm1_d4->F[tbase0]->C[st], " %10.5f "); +// fprintf(FPTR_DEBUG, "Dtdata_dm:\n"); +// WriteMatrix(FPTR_DEBUG, Dtdata_dm, " %10.5f "); + + + + +//// WriteMatrix(FPTR_DEBUG, Dtdata_dm, " %10.5f "); +//// fprintf(FPTR_DEBUG, "zt_tm1_dc->C[tbase0]:\n"); +//// WriteMatrix(FPTR_DEBUG, zt_tm1_dc->C[tbase0], " %10.5f "); +//// //WriteVector(FPTR_DEBUG, &z0_sdv, " %10.5f "); +//// //fprintf(FPTR_DEBUG, "\n"); +//// fprintf(FPTR_DEBUG, "bt_dm = [\n"); +//// WriteMatrix(FPTR_DEBUG, bt_dm, " %10.5f "); +//// fprintf(FPTR_DEBUG, "];\n"); + +//// fprintf(FPTR_DEBUG, "et:\n"); +//// WriteVector(FPTR_DEBUG, etdata_dv, " %10.5f "); +//// fprintf(FPTR_DEBUG, "yt_dv=[\n"); +//// WriteVector(FPTR_DEBUG, &yt_sdv, " %10.5f "); +//// fprintf(FPTR_DEBUG, "]';\n"); + +//// fprintf(FPTR_DEBUG, "at_dv=[\n"); +//// WriteVector(FPTR_DEBUG, &at_sdv, " %10.5f "); +//// fprintf(FPTR_DEBUG, "]';\n"); + + +//// for (ki=0; ki<Ht_dc->ncells; ki++) +//// { +//// kip1 = ki+1; +//// fprintf(FPTR_DEBUG, "Ht_dc(:,:,%d)=[\n", kip1); +//// WriteMatrix(FPTR_DEBUG, Ht_dc->C[ki], " %10.5f "); +//// fprintf(FPTR_DEBUG, "];\n"); +//// } +//// for (ki=0; ki<Ft_dc->ncells; ki++) +//// { +//// kip1 = ki+1; +//// fprintf(FPTR_DEBUG, "Ft_dc(:,:,%d)=[\n", kip1); +//// WriteMatrix(FPTR_DEBUG, Ft_dc->C[ki], " %10.5f "); +//// fprintf(FPTR_DEBUG, "];\n"); +//// } +//// for (ki=0; ki<Vt_dc->ncells; ki++) +//// { +//// kip1 = ki+1; +//// fprintf(FPTR_DEBUG, "Vt_dc(:,:,%d)=[\n", kip1); +//// WriteMatrix(FPTR_DEBUG, Vt_dc->C[ki], " %10.5f "); +//// fprintf(FPTR_DEBUG, "];\n"); +//// } +// fflush(FPTR_DEBUG); +//} + + + //====================================================== + //= Updating zt_tm1 and Pt_tm1 for next perid tp1. + //= tdata = tbase0 is base-0 timing. + //====================================================== + if (inpt > record_tbase1_or_inpt_or_tp1) //This condition always satisfies at the 1st period (which is inpt=1). + { + passonce = 0; + record_tbase1_or_inpt_or_tp1 = inpt; + } + if (!passonce) + { + for (stp1i=smodel_ps->sv->nstates-1; stp1i>=0; stp1i--) + { + if (indxIndRegimes) + { + if (nRc==1) //Volatility. + { + comstp1i_c = stp1i_c = 0; + stp1i_v = stp1i; + } + else if ((nRv>1) && (nRc>nRstc)) //Trend inflation, both sc_t and sc_{t-1} enters coefficient regime. + { + comstp1i_c = Index[stp1i][0]; //composite (s_tc, s_{t-1}c) + stp1i_v = Index[stp1i][1]; //volatility state s_tv + stp1i_c = smodel_ps->sv->state_variable[0]->lag_index[comstp1i_c][0]; //coefficient regime at t. + //sti_c = smodel_ps->sv->state_variable[0]->lag_index[comstp1i_c][1]; //coefficient regime at t-1: tm1: t-1; + } + else if ((nRv==1) && (nRc>nRstc)) + { + comstp1i_c = Index[stp1i][0]; //composite (s_tc, s_{t-1}c) + stp1i_c = smodel_ps->sv->state_variable[0]->lag_index[comstp1i_c][0]; //coefficient regime at t. + //sti_c = smodel_ps->sv->state_variable[0]->lag_index[comstp1i_c][1]; //coefficient regime at t-1: tm1: t-1; + stp1i_v = 0; + } + else if ((nRv==1) && (nRc==nRstc)) + { + comstp1i_c = stp1i_c = stp1i; + stp1i_v = 0; + } + else if ((nRv>1) && (nRc==nRstc)) //only sc_t enters coefficient regime. + { + comstp1i_c = stp1i_c = Index[stp1i][0]; + stp1i_v = Index[stp1i][1]; + } + } + else //Syncronized regimes. + { + if (nRc>nRstc) + { + comstp1i_c = Index[stp1i][0]; //composite (s_tc, s_{t-1}c) + stp1i_c = smodel_ps->sv->state_variable[0]->lag_index[comstp1i_c][0]; //coefficient regime at t. + //sti_c = smodel_ps->sv->state_variable[0]->lag_index[comstp1i_c][1]; //coefficient regime at t-1: tm1: t-1; + stp1i_v = stp1i_c; + } + else + comstp1i_c = stp1i_c = stp1i_v = stp1i; + } + + + InitializeConstantVector_lf(ztp1_dv, 0.0); //To be summed over sti. + InitializeConstantMatrix_lf(Ptp1_dm, 0.0); //To be summed over sti. + + for (sti=smodel_ps->sv->nstates-1; sti>=0; sti--) + { + if (indxIndRegimes) + { + if (nRc==1) //Volatility. + { + comsti_c = sti_c = 0; + sti_v = sti; + } + else if ((nRv>1) && (nRc>nRstc)) //Trend inflation, both sc_t and sc_{t-1} enters coefficient regime. + { + comsti_c = Index[sti][0]; //composite (s_tc, s_{t-1}c) + sti_v = Index[sti][1]; //volatility state s_tv + sti_c = smodel_ps->sv->state_variable[0]->lag_index[comsti_c][0]; //coefficient regime at t. + stm1i_c = smodel_ps->sv->state_variable[0]->lag_index[comsti_c][1]; //coefficient regime at t-1: tm1: t-1; + } + else if ((nRv==1) && (nRc>nRstc)) + { + comsti_c = Index[sti][0]; //composite (s_tc, s_{t-1}c) + sti_c = smodel_ps->sv->state_variable[0]->lag_index[comsti_c][0]; //coefficient regime at t. + stm1i_c = smodel_ps->sv->state_variable[0]->lag_index[comsti_c][1]; //coefficient regime at t-1: tm1: t-1; + sti_v = 0; + } + else if ((nRv==1) && (nRc==nRstc)) + { + comsti_c = sti_c = sti; + sti_v = 0; + } + else if ((nRv>1) && (nRc==nRstc)) //only sc_t enters coefficient regime. + { + comsti_c = sti_c = Index[sti][0]; + sti_v = Index[sti][1]; + } + } + else //Syncronized regimes. + { + if (nRc>nRstc) + { + comsti_c = Index[sti][0]; //composite (s_tc, s_{t-1}c) + sti_c = smodel_ps->sv->state_variable[0]->lag_index[comsti_c][0]; //coefficient regime at t. + stm1i_c = smodel_ps->sv->state_variable[0]->lag_index[comsti_c][1]; //coefficient regime at t-1: tm1: t-1; + sti_v = sti_c; + } + else + comsti_c = sti_c = sti_v = sti; + } + + + //--- Setup. + MatrixTimesMatrix(PHtran_tdata_dm, Pt_tm1_d4->F[tbase0]->C[sti], Ht_dc->C[comsti_c], 1.0, 0.0, 'N', 'T'); + + //--- Data. + //- etdata = Y_T(:,tdata) - a(:,tdata) - Htdata*ztdata where tdata = tbase0 = inpt-1. + yt_sdv.v = yt_dm->M + tbase0*yt_dm->nrows; + at_sdv.v = at_dm->M + comsti_c*at_dm->nrows; //comsti_c: coefficient regime at time tbase0. + z0_sdv.v = zt_tm1_dc->C[tbase0]->M + z0_sdv.n*sti; //sti: regime at time tbase0. + VectorMinusVector(etdata_dv, &yt_sdv, &at_sdv); + MatrixTimesVector(etdata_dv, Ht_dc->C[comsti_c], &z0_sdv, -1.0, 1.0, 'N'); + //+ Dtdata = Htdata*PHtran_tdata + R(:,:,tbase0); + CopyMatrix0(Dtdata_dm, Rt_dc->C[sti_v]); + MatrixTimesMatrix(Dtdata_dm, Ht_dc->C[comsti_c], PHtran_tdata_dm, 1.0, 1.0, 'N', 'N'); + //Done with z0_sdv.v. + ScalarTimesMatrixSquare(Dtdata_dm, 0.5, Dtdata_dm, 'T', 0.5); //Making it symmetric against some rounding errors. + //This making-symmetric is very IMPORTANT; otherwise, we will get the matrix being singular message + // and eigenvalues being negative for the SPD matrix, etc. Then the likelihood becomes either + // a bad number or a complex number. + Dtdata_dm->flag = Dtdata_dm->flag | M_SU | M_SL; + + + //=== Updating for next period by integrating out sti.. + if (tp1<T) + { + //Updating only up to tbase0=T-2. The values at tp1=T or tbase0=T-1 will not be used in the likelihood function. + + //--- Ktp1_t = (F_tp1*PHtran_t+G(:,:,t))/Dt; + //--- Kt_tdata = (Ft*PHtran_tdata+G(:,:,tdata))/Dtdata where t=tp1 and tdata=t. + CopyMatrix0(Kt_tdata0_dm, Gt_dc->C[sti_v]); + MatrixTimesMatrix(Kt_tdata0_dm, Ft_dc->C[stp1i_c], PHtran_tdata_dm, 1.0, 1.0, 'N', 'N'); + BdivA_rrect(Kt_tdata_dm, Kt_tdata0_dm, '/', Dtdata_dm); + //+ zt_tm1(:,t) = b(:,t) + Ft*zt_tm1(:,tdata) + Kt_tdata*etdata where t=tp1 and tm1=t. + MatrixTimesVector(ztp1_t_dv, Ft_dc->C[stp1i_c], &z0_sdv, 1.0, 0.0, 'N'); + MatrixTimesVector(ztp1_t_dv, Kt_tdata_dm, etdata_dv, 1.0, 1.0, 'N'); + btp1_sdv.v = bt_dm->M + stp1i_c*btp1_sdv.n; + VectorPlusMinusVectorUpdate(ztp1_t_dv, &btp1_sdv, 1.0); + //+ Pt_tm1(:,:,t) = Ft*Ptdata*Fttran - Kt_tdata*Dtdata*Kt_tdatatran + V(:,:,t); + CopyMatrix0(Ptp1_t_dm, Vt_dc->C[stp1i_v]); + MatrixTimesMatrix(Wnzbyny_dm, Kt_tdata_dm, Dtdata_dm, 1.0, 0.0, 'N', 'N'); + MatrixTimesMatrix(Wnzbynz_dm, Wnzbyny_dm, Kt_tdata_dm, 1.0, 0.0, 'N', 'T'); + MatrixPlusMinusMatrixUpdate(Ptp1_t_dm, Wnzbynz_dm, -1.0); + //Done with all W*_dm. + MatrixTimesMatrix(Wnzbynz_dm, Ft_dc->C[stp1i_c], Pt_tm1_d4->F[tbase0]->C[sti], 1.0, 0.0, 'N', 'N'); + MatrixTimesMatrix(W2nzbynz_dm, Wnzbynz_dm, Ft_dc->C[stp1i_c], 1.0, 0.0, 'N', 'T'); + MatrixPlusMatrixUpdate(Ptp1_t_dm, W2nzbynz_dm); + //Done with all W*_dm. + + //--- Integrating out the state at tbase0 using P(s_t|Y_{t-1}, theta) = ElementV(smodel_ps->Z[inpt],s_{inpt}_i). + //--- Note tbase0 = inpt-1 because the data in DW code (ElementV) is base-1. + //--- Note at this point, we cannot access to P(s_t|Y_t, theta) = ElementV(smodel_ps->V[inpt],s_{inpt}_i) + //--- through DW's code. But we can modify my own code to do this later. + prob_previous_regimes = ElementV(smodel_ps->Z[inpt],sti); + ScalarTimesVectorUpdate(ztp1_dv, prob_previous_regimes, ztp1_t_dv); + ScalarTimesMatrix(Ptp1_dm, prob_previous_regimes, Ptp1_t_dm, 1.0); + Ptp1_dm->flag = M_GE | M_SU | M_SL; + //Done with ztp1_t_dv and Ptp1_t_dm. + } + } + //--- Filling zt_tm1 and Pt_tm1 for next period + if (tp1<T) + { + z0_sdv.v = zt_tm1_dc->C[tp1]->M + z0_sdv.n*stp1i; //stp1i: regime at time tp1. + CopyVector0(&z0_sdv, ztp1_dv); + CopyMatrix0(Pt_tm1_d4->F[tp1]->C[stp1i], Ptp1_dm); //stp1i: regime at time tp1. + //Done with ztp1_dv, z0_sdv, Ptp1_dm. + } + } + if (tp1<T) + zt_tm1_dc->C[tp1]->flag = M_GE; + } + + +//=== ???????? For debugging purpose. +//if ((inpt>60) && (inpt<65) ) //if (inpt<5) +//{ +// int kip1; //Must be declared at the top of this "if" block. + +// fprintf(FPTR_DEBUG, "zt_tm1t=[\n"); +// WriteMatrix(FPTR_DEBUG, zt_tm1_dc->C[tbase0], " %10.5f "); +// fprintf(FPTR_DEBUG, "];\n"); + +// for (ki=0; ki<Pt_tm1_d4->F[tbase0]->ncells; ki++) +// { +// kip1 = ki+1; +// fprintf(FPTR_DEBUG, "Pt_tm1_d4t(:,:,%d)=[\n", kip1); +// WriteMatrix(FPTR_DEBUG, Pt_tm1_d4->F[tbase0]->C[ki], " %10.5f "); +// fprintf(FPTR_DEBUG, "];\n"); +// } + +// fflush(FPTR_DEBUG); +//} + + +//=== ???????? For debugging purpose. +fprintf(FPTR_DEBUG, " loglh_timet = %10.5f\n", loglh_timet); +fflush(FPTR_DEBUG); + + + //=== + DestroyVector_dz(evals_dzv); + DestroyVector_lf(evals_abs_dv); + DestroyMatrix_lf(Wnzbynz_dm); + DestroyMatrix_lf(Wnz2bynz2_dm); + DestroyMatrix_lf(W2nz2bynz2_dm); + DestroyVector_lf(wP0_dv); + // + DestroyVector_lf(wny_dv); + DestroyMatrix_lf(Wnzbyny_dm); + DestroyMatrix_lf(W2nzbynz_dm); + DestroyMatrix_lf(PHtran_tdata_dm); + DestroyVector_lf(etdata_dv); + DestroyMatrix_lf(Dtdata_dm); + DestroyMatrix_lf(Kt_tdata0_dm); + DestroyMatrix_lf(Kt_tdata_dm); + // + DestroyVector_lf(ztp1_t_dv); + DestroyMatrix_lf(Ptp1_t_dm); + DestroyVector_lf(ztp1_dv); + DestroyMatrix_lf(Ptp1_dm); + + return (loglh_timet); +} +#undef LOG2PI +#endif + + +/** +//---------------------------------------------------------------- +//-- Tested OK, but has not use because tz_Refresh_z_T7P_T_in_kalfilms_1st_approx() +//-- cannot access to ElementV(smodel_ps->V[tp1],sti) or ElementV(smodel_ps->V[tbase0],sti) +//-- because no likelihood has been formed at all before this function is called. +//---------------------------------------------------------------- +#define LOG2PI (1.837877066409345e+000) //log(2*pi) +//----------------------------------------------------- +//- Updating or refreshing all Kalman filter at time t for Markov-switching DSGE model. +//- WARNING: make sure to call the following functions +// RunningGensys_const7varionly(lwzmodel_ps); +// Refresh_kalfilms_*(lwzmodel_ps); //Creates or refreshes kalfilmsinputs_ps at new parameter values. +//- before using tz_Refresh_z_T7P_T_in_kalfilms_1st_approx(). +//----------------------------------------------------- +void tz_Refresh_z_T7P_T_in_kalfilms_1st_approx(struct TSkalfilmsinputs_tag *kalfilmsinputs_ps, struct TStateModel_tag *smodel_ps) +{ + double debug1; + //--- Local variables + int stp1i, stp1i_c, stp1i_v, sti, sti_c, sti_v, tbase0, tp1; + //=== Accessible variables + int ny = kalfilmsinputs_ps->ny; + int nz = kalfilmsinputs_ps->nz; + int nRc = kalfilmsinputs_ps->nRc; + int nRv = kalfilmsinputs_ps->nRv; + int T = kalfilmsinputs_ps->T; + int indxIndRegimes = kalfilmsinputs_ps->indxIndRegimes; + TSdvector z0_sdv; + //+ input arguments. + TSdmatrix *yt_dm = kalfilmsinputs_ps->yt_dm; //ny-by-T. + TSdmatrix *at_dm = kalfilmsinputs_ps->at_dm; //ny-by-nRc. + TSdcell *Ht_dc = kalfilmsinputs_ps->Ht_dc; //ny-by-nz-by-nRc. + TSdcell *Rt_dc = kalfilmsinputs_ps->Rt_dc; //ny-by-ny-by-nRv. Covariance matrix for the measurement equation. + TSdcell *Gt_dc = kalfilmsinputs_ps->Gt_dc; //nz-by-ny-by-nRv. Cross-covariance. + // + TSdmatrix *bt_dm = kalfilmsinputs_ps->bt_dm; //nz-by-nRc. + TSdcell *Ft_dc = kalfilmsinputs_ps->Ft_dc; //nz-by-nz-by-nRc. + TSdcell *Vt_dc = kalfilmsinputs_ps->Vt_dc; //nz-by-nz-by-nRv. Covariance matrix for the state equation. + // + TSdmatrix *z0_dm = kalfilmsinputs_ps->z0_dm; //nz-by-nRc*nRv or nz-by-nRv, depending on indxIndRegimes. + TSdcell *P0_dc = kalfilmsinputs_ps->P0_dc; //nz-by-nz-by-nRc*nRv or nz-by-nRv, depending on indxIndRegimes. + //+ Output arguments. + TSdcell *zt_tm1_dc = kalfilmsinputs_ps->zt_tm1_dc; //nz-by-nRc*nRv-by-T if indxIndRegimes==1, nz-by-nRv-by-T if indxIndRegimes==0 where nRc=nRv. + TSdfourth *Pt_tm1_d4 = kalfilmsinputs_ps->Pt_tm1_d4; //nz-by-nz-by-nRc*nRv-T if indxIndRegimes==1, nz-by-nz-by-nRv-by-T if indxIndRegimes==0 where nRc=nRv. + //=== Work arguments. + int nz2 = square(nz); + TSdmatrix *Wnzbynz_dm = CreateMatrix_lf(nz,nz); + TSdmatrix *Wnz2bynz2_dm = CreateMatrix_lf(nz2,nz2); + TSdmatrix *W2nz2bynz2_dm = CreateMatrix_lf(nz2,nz2); + TSdvector *wP0_dv = CreateVector_lf(nz2); + //+ + TSdvector yt_sdv, at_sdv, btp1_sdv; //zt_tm1_sdv, ztp1_t_sdv, + TSdvector *wny_dv = CreateVector_lf(ny); + TSdmatrix *Wnzbyny_dm = CreateMatrix_lf(nz,ny); + TSdmatrix *W2nzbynz_dm = CreateMatrix_lf(nz,nz); + TSdmatrix *PHtran_tdata_dm = CreateMatrix_lf(nz,ny); + TSdvector *etdata_dv = CreateVector_lf(ny); + TSdmatrix *Dtdata_dm = CreateMatrix_lf(ny,ny); + TSdmatrix *Kt_tdata0_dm = CreateMatrix_lf(nz,ny); + TSdmatrix *Kt_tdata_dm = CreateMatrix_lf(nz,ny); + //--- For eigenvalue decompositions + int ki; + int errflag; + double eigmax; + TSdzvector *evals_dzv = evals_dzv = CreateVector_dz(nz); + TSdvector *evals_abs_dv = CreateVector_lf(nz); //Absolute eigenvalues. + //--- For updating zt_tm1_dm and Pt_tm1. + TSdvector *ztp1_t_dv = CreateVector_lf(z0_dm->nrows); + TSdmatrix *Ptp1_t_dm = CreateMatrix_lf(nz, nz); + TSdvector *ztp1_dv = CreateVector_lf(z0_dm->nrows); + TSdmatrix *Ptp1_dm = CreateMatrix_lf(nz, nz); + + + if (smodel_ps->sv->nstates != z0_dm->ncols) fn_DisplayError("kalman.c/tz_Refresh_z_T7P_T_in_kalfilms_1st_approx():\n" + " Make sure that the column dimension of z0_dm is the same as smodel_ps->sv->nstates"); + if (indxIndRegimes && (nRc>1) && (nRv>1)) + if (smodel_ps->sv->n_state_variables != 2) fn_DisplayError("kalman.c/tz_Refresh_z_T7P_T_in_kalfilms_1st_approx():\n" + " Number of state variables must be coincide with indxIndRegimes"); + + + z0_sdv.n = z0_dm->nrows; + z0_sdv.flag = V_DEF; + // + at_sdv.n = yt_sdv.n = yt_dm->nrows; + at_sdv.flag = yt_sdv.flag = V_DEF; + btp1_sdv.n = bt_dm->nrows; + btp1_sdv.flag = V_DEF; + + + //======= Initial condition. ======= + for (sti=smodel_ps->sv->nstates-1; sti>=0; sti--) + { + if (indxIndRegimes && (nRc==1)) + { + sti_c = 0; + sti_v = sti; + } + else if (indxIndRegimes && (nRv==1)) + { + sti_c = sti; + sti_v = 0; + } + else if (indxIndRegimes) + { + sti_c = smodel_ps->sv->Index[sti][0]; + sti_v = smodel_ps->sv->Index[sti][1]; + } + else + { + sti_c = sti_v = sti; + } + + + if (!kalfilmsinputs_ps->indxIni) + { + InitializeDiagonalMatrix_lf(Wnzbynz_dm, 1.0); //To be used for I(nz) - + InitializeDiagonalMatrix_lf(Wnz2bynz2_dm, 1.0); //To be used for I(nz2) - + + //=== Eigenanalysis to determine the roots to ensure boundedness. + errflag = eigrgen(evals_dzv, (TSdzmatrix *)NULL, (TSdzmatrix *)NULL, Ft_dc->C[sti_c]); + if (errflag) fn_DisplayError("kalman.c/tz_Refresh_z_T7P_T_in_kalfilms_1st_approx(): eigen decomposition failed"); + for (ki=nz-1; ki>=0; ki--) evals_abs_dv->v[ki] = sqrt(square(evals_dzv->real->v[ki]) + square(evals_dzv->imag->v[ki])); + evals_abs_dv->flag = V_DEF; + eigmax = MaxVector(evals_abs_dv); + if (eigmax < (1.0+1.0e-14)) + { + //--- Getting z0_dv: zt_tm1(:,1) = (eye(n_z)-F(:,:,1))\b(:,1); + MatrixMinusMatrix(Wnzbynz_dm, Wnzbynz_dm, Ft_dc->C[sti_c]); + z0_sdv.v = z0_dm->M + z0_sdv.n*sti; + CopySubmatrix2vector(&z0_sdv, 0, bt_dm, 0, sti_c, bt_dm->nrows); + bdivA_rgens(&z0_sdv, &z0_sdv, '\\', Wnzbynz_dm); + //Done with Wnzbynz_dm. + //--- Getting P0_dm: Pt_tm1(:,:,1) = reshape((eye(n_z^2)-kron(F(:,:,1),F(:,:,1)))\V1(:),n_z,n_z); + tz_kron(W2nz2bynz2_dm, Ft_dc->C[sti_c], Ft_dc->C[sti_c]); + MatrixMinusMatrix(Wnz2bynz2_dm, Wnz2bynz2_dm, W2nz2bynz2_dm); + CopySubmatrix2vector(wP0_dv, 0, Vt_dc->C[sti_v], 0, 0, nz2); + bdivA_rgens(wP0_dv, wP0_dv, '\\', Wnz2bynz2_dm); + CopySubvector2matrix_unr(P0_dc->C[sti], 0, 0, wP0_dv, 0, nz2); + //Done with all w*_dv and W*_dm. + } + else + { + fprintf(stdout, "\n-----------------\n"); + fprintf(stdout, "\nIn regime sti_c=%d and sti_v=%d and at time=%d\n", sti_c, sti_v, 0); + fn_DisplayError("kalman.c/tz_Refresh_z_T7P_T_in_kalfilms_1st_approx(): the system is non-stationary solutions\n" + " and the initial conditions must be supplied by, say, input arguments"); + fflush(stdout); + } + } + } + z0_dm->flag = M_GE; + CopyMatrix0(zt_tm1_dc->C[0], z0_dm); //At time t=0. + CopyCell0(Pt_tm1_d4->F[0], P0_dc); //At time t=0. + + +// fprintf(FPTR_DEBUG, "\n zt_tm1_dc->C[0]:\n"); +// WriteMatrix(FPTR_DEBUG, zt_tm1_dc->C[0], " %.16e "); +// fprintf(FPTR_DEBUG, "\n"); +// fprintf(FPTR_DEBUG, "\n Pt_tm1_d4->F[0]->C[0]:\n"); +// WriteMatrix(FPTR_DEBUG, Pt_tm1_d4->F[0]->C[0], " %.16e "); + + + //============== Updating zt_tm1 and Pt_tm1. ================== + for (tbase0=0; tbase0<T; tbase0++ ) + { + //tdata = tbase0 is base-0 timing. + tp1 = tbase0 + 1; //Next period. + + for (stp1i=smodel_ps->sv->nstates-1; stp1i>=0; stp1i--) + { + if (indxIndRegimes && (nRc==1)) + { + stp1i_c = 0; + stp1i_v = stp1i; + } + else if (indxIndRegimes && (nRv==1)) + { + stp1i_c = stp1i; + stp1i_v = 0; + } + else if (indxIndRegimes) + { + stp1i_c = smodel_ps->sv->Index[stp1i][0]; + stp1i_v = smodel_ps->sv->Index[stp1i][1]; + } + else + { + stp1i_c = stp1i_v = stp1i; + } + + + InitializeConstantVector_lf(ztp1_dv, 0.0); //To be summed over sti. + InitializeConstantMatrix_lf(Ptp1_dm, 0.0); //To be summed over sti. + for (sti=smodel_ps->sv->nstates-1; sti>=0; sti--) + { + if (indxIndRegimes && (nRc==1)) + { + sti_c = 0; + sti_v = sti; + } + else if (indxIndRegimes && (nRv==1)) + { + sti_c = sti; + sti_v = 0; + } + else if (indxIndRegimes) + { + sti_c = smodel_ps->sv->Index[sti][0]; + sti_v = smodel_ps->sv->Index[sti][1]; + } + else + { + sti_c = sti_v = sti; + } + + //--- Setup. + MatrixTimesMatrix(PHtran_tdata_dm, Pt_tm1_d4->F[tbase0]->C[sti], Ht_dc->C[sti_c], 1.0, 0.0, 'N', 'T'); + + //--- Data. + //- etdata = Y_T(:,tdata) - a(:,tdata) - Htdata*ztdata where tdata = tbase0 = inpt-1. + yt_sdv.v = yt_dm->M + tbase0*yt_dm->nrows; + at_sdv.v = at_dm->M + sti_c*at_dm->nrows; //sti_c: coefficient regime at time tbase0. + z0_sdv.v = zt_tm1_dc->C[tbase0]->M + z0_sdv.n*sti; //sti: regime at time tbase0. + VectorMinusVector(etdata_dv, &yt_sdv, &at_sdv); + MatrixTimesVector(etdata_dv, Ht_dc->C[sti_c], &z0_sdv, -1.0, 1.0, 'N'); + //+ Dtdata = Htdata*PHtran_tdata + R(:,:,tbase0); + CopyMatrix0(Dtdata_dm, Rt_dc->C[sti_v]); + MatrixTimesMatrix(Dtdata_dm, Ht_dc->C[sti_c], PHtran_tdata_dm, 1.0, 1.0, 'N', 'N'); + //Done with z0_sdv.v. + + + //=== Updating for next period by integrating out sti.. + if (tp1<T) + { + //Updating only up to tbase0=T-2. The values at tp1=T or tbase0=T-1 will not be used in the likelihood function. + + //--- Ktp1_t = (F_tp1*PHtran_t+G(:,:,t))/Dt; + //--- Kt_tdata = (Ft*PHtran_tdata+G(:,:,tdata))/Dtdata where t=tp1 and tdata=t. + CopyMatrix0(Kt_tdata0_dm, Gt_dc->C[sti_v]); + MatrixTimesMatrix(Kt_tdata0_dm, Ft_dc->C[stp1i_c], PHtran_tdata_dm, 1.0, 1.0, 'N', 'N'); + BdivA_rrect(Kt_tdata_dm, Kt_tdata0_dm, '/', Dtdata_dm); + //+ zt_tm1(:,t) = b(:,t) + Ft*zt_tm1(:,tdata) + Kt_tdata*etdata where t=tp1 and tm1=t. + MatrixTimesVector(ztp1_t_dv, Ft_dc->C[stp1i_c], &z0_sdv, 1.0, 0.0, 'N'); + MatrixTimesVector(ztp1_t_dv, Kt_tdata_dm, etdata_dv, 1.0, 1.0, 'N'); + btp1_sdv.v = bt_dm->M + stp1i_c*btp1_sdv.n; + VectorPlusMinusVectorUpdate(ztp1_t_dv, &btp1_sdv, 1.0); + //+ Pt_tm1(:,:,t) = Ft*Ptdata*Fttran - Kt_tdata*Dtdata*Kt_tdatatran + V(:,:,t); + CopyMatrix0(Ptp1_t_dm, Vt_dc->C[stp1i]); + MatrixTimesMatrix(Wnzbyny_dm, Kt_tdata_dm, Dtdata_dm, 1.0, 0.0, 'N', 'N'); + MatrixTimesMatrix(Wnzbynz_dm, Wnzbyny_dm, Kt_tdata_dm, 1.0, 0.0, 'N', 'T'); + MatrixPlusMinusMatrixUpdate(Ptp1_t_dm, Wnzbynz_dm, -1.0); + //Done with all W*_dm. + MatrixTimesMatrix(Wnzbynz_dm, Ft_dc->C[stp1i_c], Pt_tm1_d4->F[tbase0]->C[sti], 1.0, 0.0, 'N', 'N'); + MatrixTimesMatrix(W2nzbynz_dm, Wnzbynz_dm, Ft_dc->C[stp1i_c], 1.0, 0.0, 'N', 'T'); + MatrixPlusMatrixUpdate(Ptp1_t_dm, W2nzbynz_dm); + //Done with all W*_dm. + + //--- Integrating out the state at tbase0 using P(s_t|Y_t, theta) = ElementV(smodel_ps->V[t+1],s_{t+1}_i). + //--- Note because the data in DW code (ElementV) is base-1, t+1 is actually tbase0. + debug1 = ElementV(smodel_ps->V[tp1],sti); //?????? Debug. + //ScalarTimesVectorUpdate(ztp1_dv, ElementV(smodel_ps->V[tp1],sti), ztp1_t_dv); + //ScalarTimesMatrix(Ptp1_dm, ElementV(smodel_ps->V[tp1],sti), Ptp1_t_dm, 1.0); + ScalarTimesVectorUpdate(ztp1_dv, 0.5, ztp1_t_dv); + ScalarTimesMatrix(Ptp1_dm, 0.5, Ptp1_t_dm, 1.0); + Ptp1_dm->flag = M_GE | M_SU | M_SL; + //Done with ztp1_t_dv and Ptp1_t_dm. + } + } + //--- Filling zt_tm1 and Pt_tm1 for next period + if (tp1<T) + { + z0_sdv.v = zt_tm1_dc->C[tp1]->M + z0_sdv.n*stp1i; //stp1i: regime at time tp1. + CopyVector0(&z0_sdv, ztp1_dv); + CopyMatrix0(Pt_tm1_d4->F[tp1]->C[stp1i], Ptp1_dm); //stp1i: regime at time tp1. + //Done with ztp1_dv, z0_sdv, Ptp1_dm. + } + } + if (tp1<T) + zt_tm1_dc->C[tp1]->flag = M_GE; + +// fprintf(FPTR_DEBUG, "\n &yt_sdv:\n"); +// WriteMatrix(FPTR_DEBUG, &yt_sdv, " %.16e "); +// fprintf(FPTR_DEBUG, "\n zt_tm1_dc->C[tp1]:\n"); +// WriteMatrix(FPTR_DEBUG, zt_tm1_dc->C[tp1], " %.16e "); +// fprintf(FPTR_DEBUG, "\n"); +// fprintf(FPTR_DEBUG, "\n Pt_tm1_d4->F[tp1]->C[0]:\n"); +// WriteMatrix(FPTR_DEBUG, Pt_tm1_d4->F[tp1]->C[0], " %.16e "); +// fprintf(FPTR_DEBUG, "\n"); +// fflush(FPTR_DEBUG); + + + } + + //=== + DestroyVector_dz(evals_dzv); + DestroyVector_lf(evals_abs_dv); + DestroyMatrix_lf(Wnzbynz_dm); + DestroyMatrix_lf(Wnz2bynz2_dm); + DestroyMatrix_lf(W2nz2bynz2_dm); + DestroyVector_lf(wP0_dv); + // + DestroyVector_lf(wny_dv); + DestroyMatrix_lf(Wnzbyny_dm); + DestroyMatrix_lf(W2nzbynz_dm); + DestroyMatrix_lf(PHtran_tdata_dm); + DestroyVector_lf(etdata_dv); + DestroyMatrix_lf(Dtdata_dm); + DestroyMatrix_lf(Kt_tdata0_dm); + DestroyMatrix_lf(Kt_tdata_dm); + // + DestroyVector_lf(ztp1_t_dv); + DestroyMatrix_lf(Ptp1_t_dm); + DestroyVector_lf(ztp1_dv); + DestroyMatrix_lf(Ptp1_dm); +} +//----------------------------------------------------- +//- Kalman filter at time t for Markov-switching DSGE model. +//- WARNING: make sure to call the following functions +// (1) RunningGensys_const7varionly(lwzmodel_ps); +// (2) Refresh_kalfilms_*(lwzmodel_ps); //Creates or refreshes kalfilmsinputs_ps at new parameter values. +// (3) tz_Refresh_z_T7P_T_in_kalfilms_1st_approx(); +//- before using kalfilms_timet_1st_approx(). +//----------------------------------------------------- +double tz_kalfilms_timet_1st_approx(int st, int inpt, struct TSkalfilmsinputs_tag *kalfilmsinputs_ps, struct TStateModel_tag *smodel_ps) +{ + //st, st_c, and st_v: base-0: deals with the cross-section values at time t where + // st is a grand regime, st_c is an encoded coefficient regime, and st_c is an encoded volatility regime. + //inpt: base-1 in the sense that inpt>=1 to deal with the time series situation where S_T is (T+1)-by-1 and Y_T is T+nlags_max-by-1. + // The 1st element for S_T is S_T[1] while S_T[0] is s_0. The same for (T+1)-by-1 gbeta_dv and nlcoefs-by-(T+1) galpha_dm. + // The 1st element for Y_T, however, is Y_T[nlags_max+1-1]. + //See (42.3) on p.42 in the SWZII NOTES. + + + //--- Local variables + int st_c, st_v, tbase0; + double loglh_timet; + //--- Accessible variables + int ny = kalfilmsinputs_ps->ny; + int nz = kalfilmsinputs_ps->nz; + int nRc = kalfilmsinputs_ps->nRc; + int nRv = kalfilmsinputs_ps->nRv; + int indxIndRegimes = kalfilmsinputs_ps->indxIndRegimes; + TSdvector z0_sdv; + //+ input arguments. + TSdmatrix *yt_dm = kalfilmsinputs_ps->yt_dm; //ny-by-T. + TSdmatrix *at_dm = kalfilmsinputs_ps->at_dm; //ny-by-nRc. + TSdcell *Ht_dc = kalfilmsinputs_ps->Ht_dc; //ny-by-nz-by-nRc. + TSdcell *Rt_dc = kalfilmsinputs_ps->Rt_dc; //ny-by-ny-by-nRv. Covariance matrix for the measurement equation. + //+ Output arguments. + TSdcell *zt_tm1_dc = kalfilmsinputs_ps->zt_tm1_dc; //nz-by-nRc*nRv-by-T if indxIndRegimes==1, nz-by-nRv-by-T if indxIndRegimes==0 where nRc=nRv. + TSdfourth *Pt_tm1_d4 = kalfilmsinputs_ps->Pt_tm1_d4; //nz-by-nz-by-nRc*nRv-T if indxIndRegimes==1, nz-by-nz-by-nRv-by-T if indxIndRegimes==0 where nRc=nRv. + //=== Work arguments. + TSdvector yt_sdv, at_sdv; + TSdvector *wny_dv = CreateVector_lf(ny); + TSdmatrix *PHtran_tdata_dm = CreateMatrix_lf(nz,ny); + TSdvector *etdata_dv = CreateVector_lf(ny); + TSdmatrix *Dtdata_dm = CreateMatrix_lf(ny,ny); + + + if (smodel_ps->sv->nstates != zt_tm1_dc->C[0]->ncols) fn_DisplayError("kalman.c/kalfilms_timet_1st_approx():\n" + " Make sure that the column dimension of zt_tm1_dc->C is the same as smodel_ps->sv->nstates"); + + tbase0 = inpt - 1; //base-0 time t. + + if (indxIndRegimes && (nRc==1)) + { + st_c = 0; + st_v = st; + } + else if (indxIndRegimes && (nRv==1)) + { + st_c = st; + st_v = 0; + } + else if (indxIndRegimes) + { + if (smodel_ps->sv->n_state_variables != 2) fn_DisplayError("kalman.c/kalfilms_timet_1st_approx():\n" + " Number of state variables must be coincide with indxIndRegimes"); + st_c = smodel_ps->sv->Index[st][0]; + st_v = smodel_ps->sv->Index[st][1]; + } + else + { + st_c = st_v = st; + } + + + z0_sdv.n = zt_tm1_dc->C[0]->nrows; + z0_sdv.flag = V_DEF; + // + at_sdv.n = yt_sdv.n = yt_dm->nrows; + at_sdv.flag = yt_sdv.flag = V_DEF; + + //====== Computing the conditional LH at time t. ====== + //--- Setup. + MatrixTimesMatrix(PHtran_tdata_dm, Pt_tm1_d4->F[tbase0]->C[st], Ht_dc->C[st_c], 1.0, 0.0, 'N', 'T'); + + //--- Data. + //- etdata = Y_T(:,tdata) - a(:,tdata) - Htdata*ztdata where tdata = tbase0 = inpt-1. + yt_sdv.v = yt_dm->M + tbase0*yt_dm->nrows; + at_sdv.v = at_dm->M + st_c*at_dm->nrows; //st_c: coefficient regime at time tbase0. + z0_sdv.v = zt_tm1_dc->C[tbase0]->M + z0_sdv.n*st; //st: regime at time tbase0 for zt_tm1. + VectorMinusVector(etdata_dv, &yt_sdv, &at_sdv); + MatrixTimesVector(etdata_dv, Ht_dc->C[st_c], &z0_sdv, -1.0, 1.0, 'N'); + //+ Dtdata = Htdata*PHtran_tdata + R(:,:,tbase0); + CopyMatrix0(Dtdata_dm, Rt_dc->C[st_v]); + MatrixTimesMatrix(Dtdata_dm, Ht_dc->C[st_c], PHtran_tdata_dm, 1.0, 1.0, 'N', 'N'); + + //--- Forming the log conditional likelihood at t. + bdivA_rgens(wny_dv, etdata_dv, '/', Dtdata_dm); + loglh_timet = -(0.5*ny)*LOG2PI - 0.5*logdeterminant(Dtdata_dm) - 0.5*VectorDotVector(wny_dv, etdata_dv); + //Done with all w*_dv. + + + //=== + DestroyVector_lf(wny_dv); + DestroyMatrix_lf(PHtran_tdata_dm); + DestroyVector_lf(etdata_dv); + DestroyMatrix_lf(Dtdata_dm); + + return (loglh_timet); +} +#undef LOG2PI +/**/ + + + + diff --git a/CFiles/Copy of kalman.h b/CFiles/Copy of kalman.h new file mode 100755 index 0000000..7e869dd --- /dev/null +++ b/CFiles/Copy of kalman.h @@ -0,0 +1,300 @@ +#ifndef __KALMAN_H__ + #define __KALMAN_H__ + + #include "tzmatlab.h" + #include "mathlib.h" + #include "switch.h" + #include "fn_filesetup.h" //Used to call WriteMatrix(FPTR_DEBUG,....). + + + typedef struct TSkalcvfurw_tag { + //urw: univariate random walk kalman filter. Desigend specially for the 2006 AER SWZ paper. + + //=== Input arguments. + int indx_tvsigmasq; //0: constant siqmasq in Kalman updating (default); + //1: Keyensian (project-specific) type of time-varying sigmasq in Kalman updating; See pp.37 and 37a in SWZ Learning NOTES; + //2: project-specific type; + //3: another project-specific type. + double sigmasq; //Variance for the residual eps(t) of the measurement equation. + int fss; //T: effective sample size (excluding lags). + int kx; //dimension for x(t). + TSdmatrix *V_dm; //kx-by-kx. Covariance (symmetric and positive definite) matrix for the residual eta(t) of the transition equation. + TSdvector *ylhtran_dv; //1-by-T of y(t). The term lh means lelf hand side and tran means transpose. + TSdmatrix *Xrhtran_dm; //kx-by-T of x(t). The term rh means right hand side and tran means transpose. + TSdvector *z10_dv; //kx-by-1. Initial condition for prediction: z_{1|0}. + TSdmatrix *P10_dm; //kx-by-kx symmetric matrix. Initial condition for the variance of the prediction: P_{1|0}. + + //=== Output arguments. + TSdvector *zupdate_dv; //kx-by-1. z_{T+1|T}. + TSdmatrix *Zpredtran_dm; //kx-by-T matrix of one-step predicted values of z(t). [z_{2|1}, ..., z_{t+1|t}, ..., z_{T+1|T}]. + //Set to NULL (no output) if storeZ = 0; + TSdcell *Ppred_dc; //T cells and kx-by-kx symmetric and positive definite matrix for each cell. Mean square errors of predicted state variables. + //{P_{2|1}, ..., P{t+1|t}, ..., P{T+1|T}. Set to NULL (no output if storeV = 0). + TSdvector *ylhtranpred_dv; //1-by-T one-step prediction of y(t) or ylhtran_dv. Added 03/17/05. + + //=== Function itself. + void (*learning_fnc)(struct TSkalcvfurw_tag *, void *); + } TSkalcvfurw; //urw: univariate random walk. + // + typedef void TFlearninguni(struct TSkalcvfurw_tag *, void *); //For linear rational expectations models. + + + //=== Better version is TSkalfilmsinputs_1stapp_tag. Kalman filter for constant or known-time-varying DSGE models. + typedef struct TSkalfiltv_tag + { + //General (known-time-varying) Kalman filter for DSGE models. + // It computes a sequence of one-step predictions and their covariance matrices, and the log likelihood. + // The function uses a forward recursion algorithm. See also the Matlab function fn_kalfil_tv.m + // + // State space model is defined as follows: + // y(t) = a(t) + H(t)*z(t) + eps(t) (observation or measurement equation) + // z(t) = b(t) + F(t)*z(t) + eta(t) (state or transition equation) + // where a(t), H(t), b(t), and F(t) depend on s_t that follows a Markov-chain process and are taken as given. + // + // Inputs are as follows: + // Y_T is a n_y-by-T matrix containing data [y(1), ... , y(T)]. + // a is an n_y-by-T matrix of time-varying input vectors in the measurement equation. + // H is an n_y-by-n_z-by-T 3-D of time-varying matrices in the measurement equation. + // R is an n_y-by-n_y-by-T 3-D of time-varying covariance matrices for the error in the measurement equation. + // G is an n_z-by-n_y-by-T 3-D of time-varying E(eta_t * eps_t'). + // ------ + // b is an n_z-by-T matrix of time-varying input vectors in the state equation with b(:,1) as an initial condition. + // F is an n_z-by-n_z-by-T 3-D of time-varying transition matrices in the state equation with F(:,:,1) as an initial condition. + // V is an n_z-by-n_z-by-T 3-D of time-varying covariance matrices for the error in the state equation with V(:,:,1) as an initial condition. + // ------ + // indxIni: 1: using the initial condition with zt_tm1(:,1)=z0 and Pt_tm1(:,:,1)=P0; + // 0: using the unconditional mean for any given regime at time 0. + // z0 is an n_z-by-1 vector of initial condition when indxIni=1. (Not used if indxIni=0.) + // P0 is an n_z-by-n_z matrix of initial condition when indxIni=1. (Not used if indxIni=0.) + // + // Outputs are as follows: + // loglh is a value of the log likelihood function of the state-space model + // under the assumption that errors are multivariate Gaussian. + // zt_tm1 is an n_z-by-T matrices of one-step predicted state vectors with z0_0m1 as a initial condition + // and with z_{t+1|t} as the last element. Thus, we can use it as a base-1 vector. + // Pt_tm1 is an n_z-by-n_z-by-T 3-D of covariance matrices of zt_tm1 with P0_0m1 as a initial condition + // and with P_{t+1|t} as the last element. Thus, we can use it as a base-1 cell. + // + // The initial state vector and its covariance matrix are computed under the bounded (stationary) condition: + // z0_0m1 = (I-F(:,:,1))\b(:,1) + // vec(P0_0m1) = (I-kron(F(:,:,1),F(:,:,1)))\vec(V(:,:,1)) + // Note that all eigenvalues of the matrix F(:,:,1) are inside the unit circle when the state-space model is bounded (stationary). + // + // March 2007, written by Tao Zha + // See Hamilton's book ([13.2.13] -- [13.2.22]), Harvey (pp.100-106), and LiuWZ Model I NOTES pp.001-003. + + //=== Input arguments. + int ny; //number of observables. + int nz; //number of state variables. + int T; //sample size. + int indxIni; //1: using the initial condition with zt_tm1(:,1)=z0 and Pt_tm1(:,:,1)=P0; + //0: using the unconditional mean for any given regime at time 0. (Default value) + TSdmatrix *yt_dm; //ny-by-T. + TSdmatrix *at_dm; //ny-by-T. + TSdcell *Ht_dc; //ny-by-nz-by-T. + TSdcell *Rt_dc; //ny-by-ny-by-T. Covariance matrix for the measurement equation. + TSdcell *Gt_dc; //nz-by-ny-by-T. Cross-covariance. + // + TSdmatrix *bt_dm; //nz-by-T. + TSdcell *Ft_dc; //nz-by-nz-by-T. + TSdcell *Vt_dc; //nz-by-nz-by-T. Covariance matrix for the state equation. + // + TSdvector *z0_dv; //nz-by-1; + TSdmatrix *P0_dm; //nz-by-nz. + + //=== Output arguments. + double loglh; //log likelihood. + TSdmatrix *zt_tm1_dm; //nz-by-T. + TSdcell *Pt_tm1_dc; //nz-by-nz-T. + } TSkalfiltv; + + + + //=== Inputs for filter for Markov-switching DSGE models at any time t. + typedef struct TSkalfilmsinputs_1stapp_tag + { + //Inputs Markov-switching Kalman filter for DSGE models (conditional on all the regimes at time t). + // It computes a sequence of one-step predictions and their covariance matrices, and the log likelihood. + // The function uses a forward recursion algorithm. See also the Matlab function fn_kalfil_tv.m + // + // State space model is defined as follows: + // y(t) = a(t) + H(t)*z(t) + eps(t) (observation or measurement equation) + // z(t) = b(t) + F(t)*z(t) + eta(t) (state or transition equation) + // where a(t), H(t), b(t), and F(t) depend on the grand regime s_t that follows a Markov-chain process + // and is taken as given. + // + // Inputs at time t are as follows where nst is number of grand regimes (including lagged regime + // and coefficients and shock variances): + // Y_T is a n_y-by-T matrix containing data [y(1), ... , y(T)]. + // a is an n_y-by-nst matrix of Markov-switching input vectors in the measurement equation. + // H is an n_y-by-n_z-by-nst 3-D of Markov-switching matrices in the measurement equation. + // R is an n_y-by-n_y-by-nst 3-D of Markov-switching covariance matrices for the error in the measurement equation. + // G is an n_z-by-n_y-by-nst 3-D of Markov-switching E(eta_t * eps_t'). + // ------ + // b is an n_z-by-nst matrix of Markov-switching input vectors in the state equation with b(:,st) as an initial condition. + // (alternatively, with the ergodic weighted b(:,st) as an initial condition). + // F is an n_z-by-n_z-by-nst 3-D of Markov-switching transition matrices in the state equation with F(:,:,st) + // as an initial condition (alternatively, with the ergodic weighted F(:,:,st) as an initial condition). + // V is an n_z-by-n_z-by-nRv 3-D of Markov-switching covariance matrices for the error in the state equation + // with V(:,:,st) as an initial condition (alternatively, with the ergodic weighted V(:,:,st) as an initial condition). + // ------ + // indxIni: 1: using the initial condition with zt_tm1(:,1)=z0 and Pt_tm1(:,:,1)=P0; + // 0: using the unconditional mean for any given regime at time 0. + // z0 is an n_z-by-nst matrix of initial condition (Not used if indxIni=0). + // P0 is an n_z-by-n_z-by-nst 3-D of initial condition (Not used if indxIni=0). + // + // The initial state vector and its covariance matrix are computed under the bounded (stationary) condition: + // z0_0m1 = (I-F(:,:,st))\b(:,st) + // vec(P0_0m1) = (I-kron(F(:,:,st),F(:,:,st)))\vec(V(:,:,st)) + // Note that all eigenvalues of the matrix F(:,:,st) are inside the unit circle when the state-space model is bounded (stationary). + // + // November 2007, written by Tao Zha. Revised, April 2008. + // See Hamilton's book ([13.2.13] -- [13.2.22]), Harvey (pp.100-106), and LiuWZ Model I NOTES pp.001-003. + + //=== Input arguments. + int ny; //number of observables. + int nz; //number of state variables. + int nst; //number of grand composite regimes (current and past regimes, coefficient and volatility regimes). + int T; //sample size. + int indxIni; //1: using the initial condition with zt_tm1(:,1)=z0 and Pt_tm1(:,:,1)=P0, + //0: using the unconditional momnets for any given regime at time 0 (default when indxDiffuse = 0). + int indxDiffuse; //1: using the diffuse condition for z_{1|0} and P_{1|0} (default option), according to Koopman and Durbin, "Filtering and Smoothing of State Vector for Diffuse State-Space Models," J. of Time Series Analysis, Vol 24(1), pp.85-99. + //0: using the unconditional moments. + double DiffuseScale; //A large (infinity) number when indxDiffuse = 1. + int ztm1_track; //t-1 = -1: no initial conditions z_{1|0} and P_{1|0} has been computed yet, but will be using InitializeKalman_z10_P10(), + //t-1 >= 0:T-1: z_{t|t-1} and P_{t|t-1} are updated up to t-1. + int dtm1_track; //t-1 = -1: no etdata_dc->C[0] or Dtdata_d4->F[0] has been computed yet. + //t-1 >= 0:T-1: etdata_dc->C[t-1] and Dtdata_d4->F[t-1] are updated up to t-1. + + TSdmatrix *yt_dm; //ny-by-T. + TSdmatrix *at_dm; //ny-by-nst. + TSdcell *Ht_dc; //ny-by-nz-by-nst. + TSdcell *Rt_dc; //ny-by-ny-by-nst. Covariance matrix for the measurement equation. + TSdcell *Gt_dc; //nz-by-ny-by-nst. Cross-covariance. + // + TSdmatrix *bt_dm; //nz-by-nst. + TSdcell *Ft_dc; //nz-by-nz-by-nst. + TSdcell *Vt_dc; //nz-by-nz-by-nst. Covariance matrix for the state equation. + // + TSdmatrix *z0_0_dm; //nz-by-nst. z_{0|0}. + TSdmatrix *z0_dm; //nz-by-nst. z_{1|0}. + TSdcell *P0_dc; //nz-by-nz-by-nst. P_{1|0} + + + //=== Output arguments only used for 1st order approximation to zt and Pt depending on infinite past regimes. + TSdcell *zt_tm1_dc; //nz-by-nst-by-(T+1), where z_{1|0} is an initial condition (1st element with t-1=0 or t=1 for base-1) and + // the terminal condition z_{T+1|T} using Updatekalfilms_1stapp(T, ...) is not computed + // when the likelihood logTimetCondLH_kalfilms_1stapp() is computed. Thus, z_{T+1|T} + // has not legal value computed in most applications unless in out-of-sample forecasting problems. + TSdfourth *Pt_tm1_d4; //nz-by-nz-by-nst-by-(T+1), where P_{1|0} is an initial condition (1st element with t-1=0) and + // the terminal condition P_{T+1|T} using Updatekalfilms_1stapp(T, ...) is not computed + // when the likelihood logTimetCondLH_kalfilms_1stapp() is computed. Thus, P_{T+1|T} + // has not legal value computed in most applications unless in out-of-sample forecasting problems. + //+ Will be save for updating likelihood and Kalman filter Updatekalfilms_1stapp(), so save time to recompute these objects again. + TSdfourth *PHtran_tdata_d4; //nz-by-ny-by-nst-T, P_{t|t-1}*H_t'. Saved only for updating Kalman filter Updatekalfilms_1stapp(). + TSdcell *etdata_dc; //ny-by-nst-by-T (with base-0 T), forecast errors e_t in the likelihood. + TSdcell *yt_tm1_dc; //ny-by-nst-by-T, one-step forecast y_{t|t-1} for t=0 to T-1 (base-0). Incorrect now (Used to back out structural shocks). + TSdfourth *Dtdata_d4; //ny-by-ny-nst-by-T, forecast covariance D_t in the likelihood. Saved for updating Kalman filter Updatekalfilms_1stapp(). + } TSkalfilmsinputs_1stapp; + + + //=== OLD Code: Inputs for filter for Markov-switching DSGE models at any time t. + typedef struct TSkalfilmsinputs_tag + { + //Inputs Markov-switching Kalman filter for DSGE models (conditional on all the regimes at time t). + // It computes a sequence of one-step predictions and their covariance matrices, and the log likelihood. + // The function uses a forward recursion algorithm. See also the Matlab function fn_kalfil_tv.m + // + // State space model is defined as follows: + // y(t) = a(t) + H(t)*z(t) + eps(t) (observation or measurement equation) + // z(t) = b(t) + F(t)*z(t) + eta(t) (state or transition equation) + // where a(t), H(t), b(t), and F(t) depend on s_t that follows a Markov-chain process and are taken as given. + // + // Inputs at time t are as follows where nRc is number of regimes for coefficients + // nRv is number of regimes for volatility (shock variances): + // Y_T is a n_y-by-T matrix containing data [y(1), ... , y(T)]. + // a is an n_y-by-nRc matrix of Markov-switching input vectors in the measurement equation. + // H is an n_y-by-n_z-by-nRc 3-D of Markov-switching matrices in the measurement equation. + // R is an n_y-by-n_y-by-nRv 3-D of Markov-switching covariance matrices for the error in the measurement equation. + // G is an n_z-by-n_y-by-nRv 3-D of Markov-switching E(eta_t * eps_t'). + // ------ + // b is an n_z-by-nRc matrix of Markov-switching input vectors in the state equation with b(:,1) as an initial condition. + // F is an n_z-by-n_z-by-nRc 3-D of Markov-switching transition matrices in the state equation with F(:,:,1) as an initial condition. + // V is an n_z-by-n_z-by-nRv 3-D of Markov-switching covariance matrices for the error in the state equation with V(:,:,1) as an initial condition. + // ------ + // indxIndRegimes: 1: coefficient regime and volatility regime are independent; 0: these two regimes are synchronized completely. + // indxIni: 1: using the initial condition with zt_tm1(:,1)=z0 and Pt_tm1(:,:,1)=P0; + // 0: using the unconditional mean for any given regime at time 0. + // z0 is an n_z-by-nRc*nRv matrix of initial condition when indxIni=1 and indxIndRegimes=1. (Not used if indxIni=0.) + // z0 is an n_z-by-nRv matrix of initial condition when indxIni=1 and indxIndRegimes=0. (Not used if indxIni=0.) + // P0 is an n_z-by-n_z-by-nRc*nRv 3-D of initial condition when indxIni=1 and indxIndRegimes=1. (Not used if indxIni=0.) + // P0 is an n_z-by-n_z-by-nRv 3-D of initial condition when indxIni=1 and indxIndRegimes=0. (Not used if indxIni=0.) + // + // The initial state vector and its covariance matrix are computed under the bounded (stationary) condition: + // z0_0m1 = (I-F(:,:,1))\b(:,1) + // vec(P0_0m1) = (I-kron(F(:,:,1),F(:,:,1)))\vec(V(:,:,1)) + // Note that all eigenvalues of the matrix F(:,:,1) are inside the unit circle when the state-space model is bounded (stationary). + // + // November 2007, written by Tao Zha + // See Hamilton's book ([13.2.13] -- [13.2.22]), Harvey (pp.100-106), and LiuWZ Model I NOTES pp.001-003. + + //=== Input arguments. + int ny; //number of observables. + int nz; //number of state variables. + int nRc; //number of composite regimes (current and past regimes) for coefficients. + int nRstc; //number of coefficient regimes at time t. + int nRv; //number of regimes for volatility (shock variances). + int indxIndRegimes; //1: coefficient regime and volatility regime are independent; 0: these two regimes are synchronized completely. + int T; //sample size. + int indxIni; //1: using the initial condition with zt_tm1(:,1)=z0 and Pt_tm1(:,:,1)=P0; + //0: using the unconditional mean for any given regime at time 0. (Default value) + TSdmatrix *yt_dm; //ny-by-T. + TSdmatrix *at_dm; //ny-by-nRc. + TSdcell *Ht_dc; //ny-by-nz-by-nRc. + TSdcell *Rt_dc; //ny-by-ny-by-nRv. Covariance matrix for the measurement equation. + TSdcell *Gt_dc; //nz-by-ny-by-nRv. Cross-covariance. + // + TSdmatrix *bt_dm; //nz-by-nRc. + TSdcell *Ft_dc; //nz-by-nz-by-nRc. + TSdcell *Vt_dc; //nz-by-nz-by-nRv. Covariance matrix for the state equation. + // + TSdmatrix *z0_dm; //nz-by-nRc*nRv if indxIndRegimes == 1 or nz-by-nRv if indxIndRegimes == 0. + TSdcell *P0_dc; //nz-by-nz-by-nRc*nRv if indxIndRegimes == 1 or nz-by-nz-by-nRv if indxIndRegimes == 0. + + + //=== Output arguments only used for 1st order approximation to zt and Pt depending on infinite past regimes. + TSdcell *zt_tm1_dc; //nz-by-nRc*nRv-by-T if indxIndRegimes==1, nz-by-nRv-by-T if indxIndRegimes==0 where nRc=nRv. + TSdfourth *Pt_tm1_d4; //nz-by-nz-by-nRc*nRv-T if indxIndRegimes==1, nz-by-nz-by-nRv-by-T if indxIndRegimes==0 where nRc=nRv. + } TSkalfilmsinputs; + + + + + //--- Functions for univariate random walk kalman filter. + TSkalcvfurw *CreateTSkalcvfurw(TFlearninguni *func, int T, int k, int tv); //, int storeZ, int storeV); + TSkalcvfurw *DestroyTSkalcvfurw(TSkalcvfurw *kalcvfurw_ps); + void kalcvf_urw(TSkalcvfurw *kalcvfurw_ps, void *dummy_ps); + + //--- New Code: Functions for Markov-switching Kalman filter. + struct TSkalfilmsinputs_1stapp_tag *CreateTSkalfilmsinputs_1stapp(int ny, int nz, int nst, int T); + struct TSkalfilmsinputs_1stapp_tag *DestroyTSkalfilmsinputs_1stapp(struct TSkalfilmsinputs_1stapp_tag *kalfilmsinputs_1stapp_ps); + int InitializeKalman_z10_P10(struct TSkalfilmsinputs_1stapp_tag *kalfilmsinputs_1stapp_ps, TSdmatrix *z10_dm, TSdcell *P10_dc); + double logTimetCondLH_kalfilms_1stapp(int st, int inpt, struct TSkalfilmsinputs_1stapp_tag *kalfilmsinputs_1stapp_ps, struct TStateModel_tag *smodel_ps); + + + + //--- OLD Code: Functions for general constant Kalman filter. + struct TSkalfiltv_tag *CreateTSkalfiltv(int ny, int nz, int T); + struct TSkalfiltv_tag *DestroyTSkalfiltv(struct TSkalfiltv_tag *kalfiltv_ps); + //Used to test tz_logTimetCondLH_kalfiltv(). (Done April 08). double tz_kalfiltv(struct TSkalfiltv_tag *kalfiltv_ps); + double tz_logTimetCondLH_kalfiltv(int st, int inpt, struct TSkalfiltv_tag *kalfiltv_ps); + + //--- OLD Code: Functions for Markov-switching Kalman filter. + struct TSkalfilmsinputs_tag *CreateTSkalfilmsinputs(int ny, int nz, int nRc, int nRstc, int nRv, int indxIndRegimes, int T); + struct TSkalfilmsinputs_tag *DestroyTSkalfilmsinputs(struct TSkalfilmsinputs_tag *kalfilmsinputs_ps); + double tz_logTimetCondLH_kalfilms_1st_approx(int st, int inpt, struct TSkalfilmsinputs_tag *kalfilmsinputs_ps, struct TStateModel_tag *smodel_ps); + //IMPORTANT NOTE: in the Markov-switching input file datainp_markov*.prn, it MUST be that + // the coefficient regime is the 1st state variable, and + // the volatility regime is the 2nd state variable. +#endif + diff --git a/CFiles/congradmin.c b/CFiles/congradmin.c new file mode 100755 index 0000000..b09abf9 --- /dev/null +++ b/CFiles/congradmin.c @@ -0,0 +1,580 @@ +/************************************************************* + * Conjugate Gradient Minimization Methods. See Numerical Recipes in C by Press, Flannery, Teukolsky, and Vetterling. + * (I) frprmn(): Plolak-Ribiere method with the line minimization without using the derivative information. + * (II) dlinmin(): Fletcher-Reeves method with the line minimization using the derivative information. + * + * Modified by Tao Zha, September 2003. +*************************************************************/ + +#include "congradmin.h" + +static void linmin(double p[], double xi[], int n, double *fret, double tol_brent, int itmax_brent, double (*func)(double [], int)); +static double brent(double ax, double bx, double cx, double (*f)(double), double tol_brent, double itmax_brent, double *xmin); +// +static void dlinmin(double p[], double xi[], int n, double *fret, double tol_dbrent, double itmax_dbrent, double *grdh_p, double (*func)(double [], int), void (*dfunc)(double [], double [], int, double (*func)(double [], int), double *, double)); +static double dbrent(double ax, double bx, double cx, double (*f)(double), double (*df)(double, double *), double *grdh_p, double tol_dbrent, double itmax_dbrent, double *xmin); +static double df1dim(double x, double *grdh_p); +// +static void mnbrak(double *ax, double *bx, double *cx, double *fa, double *fb, double *fc, double (*func)(double)); +static double f1dim(double x); +// +static double ftd_norm2(double *vnew_p, double *vold_p, int _n); +static double ftd_innerproduct(double *x, double *y, int _n); + + +#define ANGLE 0.001 //.0 implies 90.00 degress (acrcos(ANGLE)*180/pi). + //.005 implies 89.71 degrees (acrcos(ANGLE)*180/pi). + //.01 implies 89.43 degrees (acrcos(ANGLE)*180/pi). + //.05 implies 87.13 degrees (acrcos(ANGLE)*180/pi). + //.1 implies 84.26 degrees (acrcos(ANGLE)*180/pi). +#define STRLEN 192 +static FILE *fptr_interesults = (FILE *)NULL; //Printing intermediate results to a file. +static char filename_sp3vecs[STRLEN]; //Three vectors. 1st row: line search direction; 2nd row: numerical gradient; 3rd row: vectorized parameters. +//static FILE *fptr_interesults_db = (FILE *)NULL; //Printing intermediate results to a file for debugging (db). +#define PRINTON //Added by TZ, September 2003. +#define EPS 1.0e-10 //Small number to rectify special case of converging to exactly zero function value. +#ifdef PRINTON //Added by TZ, September 2003. + #define FREEALL {tzDestroy(xi); tzDestroy(h); tzDestroy(g); tzDestroy(pold); tzDestroy(numgrad)} +#else + #define FREEALL {tzDestroy(xi); tzDestroy(h); tzDestroy(g);} +#endif +void frprmn(double p[], int n, int *iter, double *fret, + double (*func)(double [], int), void (*dfunc)(double [], double [], int, double (*func)(double [], int), double *, double), + double *ftol_p, int *itmax_p, double *tol_brent_p, int *itmax_brent_p, double *grdh_p) { + //Outputs: + // p[0, ..., n-1]: the location of the minimum if it converges, which replaces the starting value. + // iter: pointer to the number of iterations that were performed. + // fret: pointer to the minimum value of the function. + //Inputs: + // p[0, ..., n-1]: a starting point for the minimization. + // n: the dimension of p. + // ftol_p: pointer to the convergence tolerance on the objective function value. Default: 1.0e-4 if NULL. + // itmax_p: pointer to the maximum number of iterations in the main minimization program frprmn(). Default: 2000 if NULL. + // tol_brent_p: pointer to the convergence tolerance for the line minimization in brent(). Default: 2.0e-4 if NULL. + // itmax_brent_p: pointer to the maximum number of iterations for the line minimization in brent(). Default: 100 if NULL. + // grdh: pointer to the user's specified step size for a numerical gradient. If NULL, dfunc() (i.e., gradcd_gen()) will select grdh automatically. + // func(): the objective function. + // dfunc(): the gradient function computing the numerical gradient. In the form of gradcd_gen() in cstz.c. + int j, its, itmax, itmax_brent; + double gg, gam, fp, dgg, ftol, tol_brent; + double *g=NULL, *h=NULL, *xi=NULL; + #ifdef PRINTON //Added by TZ, September 2003. + time_t begtime, currentime; + double normforp, *pold = NULL, *numgrad = NULL; + int cnt_wrong_dirs = -1; //Counts the number of times that a numerical direction in the line search has a wrong sign. + #endif + + //=== Memory allocation. + g=tzMalloc(n, double); + h=tzMalloc(n, double); + xi=tzMalloc(n, double); + // + numgrad = tzMalloc(n, double); //Added by TZ, September 2003. + #ifdef PRINTON //Added by TZ, September 2003. + pold = tzMalloc(n, double); + #endif + + //=== Default values. + if (!ftol_p) ftol = 1.0e-4; else ftol = *ftol_p; + if (!itmax_p) itmax = 200; else itmax = *itmax_p; + if (!tol_brent_p) tol_brent = 2.0e-4; else tol_brent = *tol_brent_p; + if (!itmax_brent_p) itmax_brent = 100; else itmax_brent = *itmax_brent_p; + + fp=(*func)(p, n); + (*dfunc)(xi, p, n, func, grdh_p, fp); + for (j=n-1;j>=0;j--) { + g[j] = -xi[j]; + xi[j]=h[j]=g[j]; + } + memcpy(numgrad, xi, n*sizeof(double)); //Added by TZ, September 2003. Save the numerical gradient to be printed out at the right place. + for (its=0;its<itmax;its++) { + #ifdef PRINTON + time(&begtime); //Added by TZ, September 2003. + memcpy(pold, p, n*sizeof(double)); //Added by TZ, September 2003. + #endif + //====== Added by TZ, September 2003 ====== + if ( !(fptr_interesults = fopen(filename_sp3vecs,"w")) ) { + printf("\n\nUnable to create the starting point data file %s in congradmin.c!\n", filename_sp3vecs); + getchar(); + exit(EXIT_FAILURE); + } + // rewind(fptr_interesults); //Must put the pointer at the beginning of the file. + //=== Prints out the line search direction. + fprintf(fptr_interesults, "--------Line search direction---------\n"); + for (j=0; j<n; j++) fprintf(fptr_interesults, " %0.16e ", xi[j]); + fprintf(fptr_interesults, "\n"); + // fflush( fptr_interesults ); + //=== Prints out the message about a wrong numerical direction in the line search for the miminziation. + if ( ftd_innerproduct(xi, numgrad, n)/(ftd_norm2(xi, xi, n)*ftd_norm2(numgrad, numgrad, n)) > - ANGLE ) { + #ifdef PRINTON + printf("\n----------------\n" + "Warning: wrong numerical direction in the line search for the miminziation (a total of %d times)!\n" + "----------------\n", ++cnt_wrong_dirs); + #endif + } + + + *iter=its; + #if defined (CGI_OPTIMIZATION) + linmin(p,xi,n,fret, tol_brent, itmax_brent, func); + #elif defined (CGII_OPTIMIZATION) + dlinmin(p, xi, n, fret, tol_brent, itmax_brent, grdh_p, func, dfunc); + #else + fn_DisplayError("The minimization routine frprmn() requires activating CGI_OPTIMIZATION or CGII_OPTIMIZATION in tzmatlab.h"); + #endif + #ifdef PRINTON + normforp = ftd_norm2(p, pold, n); + //=== Prints out intermediate results. + printf("\n========================================\n"); + printf("Intermediate results for the conjugate gradient algorithm."); + printf("\n (1) Number of iterations so far (maximum number): %d (%d)\n (2) New value of objective function (old value, improvement): %0.9f (%0.9f, %0.9f)\n" + " (3) Norm-2 of dx: %0.9f\n", + its, itmax, *fret, fp, fp-(*fret), normforp); + fflush(stdout); // Flush the buffer to get out this message without delay. + #endif + //====== The following statements print out intermediate results. Added by TZ, September 2003 ====== + //=== Prints out the gradient. + fprintf(fptr_interesults, "--------Numerical graident---------\n"); + for (j=0; j<n; j++) fprintf(fptr_interesults, " %0.16e ", numgrad[j]); + fprintf(fptr_interesults, "\n"); + // + fprintf(fptr_interesults, "--------Restarting point---------\n"); + for (j=0; j<n; j++) fprintf(fptr_interesults, " %0.16e ", p[j]); + fprintf(fptr_interesults, "\n\n"); +// fflush( fptr_interesults ); + tzFclose(fptr_interesults); + + + if (2.0*fabs(*fret-fp) <= ftol*(fabs(*fret)+fabs(fp)+EPS)) { + //This is a normal convergence. + printf("\n----- Normal convergence by the criterion of the objective function evaluation -----------\n"); + FREEALL + return; + } + fp=(*func)(p, n); + (*dfunc)(xi, p, n, func, grdh_p, fp); + memcpy(numgrad, xi, n*sizeof(double)); //Added by TZ, September 2003. Save the numerical gradient to be printed out at the right place. +// if (filename_sp3vecs) { +// //=== Prints out the gradient. +// fprintf(fptr_interesults, "--------Numerical graident---------\n"); +// for (j=0; j<n; j++) fprintf(fptr_interesults, " %0.16e ", xi[j]); +// fprintf(fptr_interesults, "\n\n"); +//// fflush( fptr_interesults ); + +// tzFclose(fptr_interesults); +// } + dgg=gg=0.0; + for (j=n-1;j>=0;j--) { + gg += g[j]*g[j]; + dgg += (xi[j]+g[j])*xi[j]; + } + if (gg == 0.0) { + FREEALL + return; + } + gam=dgg/gg; + for (j=n-1;j>=0;j--) { + g[j] = -xi[j]; + xi[j]=h[j]=g[j]+gam*h[j]; + } + + #ifdef PRINTON + time(¤time); + //=== Times the iterative progress. + printf(" (4) Seconds to complete one iteration: %0.4f\n (5) Current time of day: %s\n", difftime(currentime, begtime), ctime(¤time)); + fflush(stdout); // Flush the buffer to get out this message without delay. + #endif + } + fn_DisplayError("The maximum number of iterations in frprmn() is reached before convergence"); +} +#undef PRINTON +#undef EPS +#undef FREEALL + + +#if defined (CGI_OPTIMIZATION) + static int ncom; + static double *pcom=NULL, *xicom=NULL, (*nrfunc)(double [], int); //nrfunc(), pcom, ncom, and xicom will be used by f1dim(). + static void linmin(double p[], double xi[], int n, double *fret, double tol_brent, int itmax_brent, double (*func)(double [], int)) { + //Outputs: + // p[0, ..., n-1]: a returned and reset value. + // xi[0, ..., n-1]: a value repaced by the actual vector displacement that p was moved. + // fret: the value of func at the returned location p. + //Inputs: + // p[0, ..., n-1]: a given point. + // xi[0, ..., n-1]: a given multidimensional direction. + // n: the dimension of p and xi. + // func(): the objective function. + int j; + double xx,xmin,fx,fb,fa,bx,ax; + + ncom=n; + pcom = tzMalloc(n, double); + xicom = tzMalloc(n, double); + nrfunc=func; + for (j=n-1;j>=0;j--) { + pcom[j]=p[j]; + xicom[j]=xi[j]; + } + ax=0.0; + xx=1.0; + mnbrak(&ax,&xx,&bx,&fa,&fx,&fb,f1dim); + *fret=brent(ax,xx,bx,f1dim, tol_brent, itmax_brent, &xmin); + for (j=n-1;j>=0;j--) { + xi[j] *= xmin; + p[j] += xi[j]; + } + tzDestroy(xicom); + tzDestroy(pcom); + } + + + //=== Used by linmin() only; + #define CGOLD 0.3819660 + #define ZEPS 1.0e-10 + #define SHFT(a,b,c,d) {(a)=(b);(b)=(c);(c)=(d);} + #define SIGN(a,b) ((b) >= 0.0 ? fabs(a) : -fabs(a)) + static double brent(double ax, double bx, double cx, double (*f)(double), double tol_brent, double itmax_brent, double *xmin) { + int iter; + double a,b,d,etemp,fu,fv,fw,fx,p,q,r,tol1,tol2,u,v,w,x,xm; + double e=0.0; + + a=(ax < cx ? ax : cx); + b=(ax > cx ? ax : cx); + x=w=v=bx; + fw=fv=fx=(*f)(x); + for (iter=0;iter<itmax_brent;iter++) { + xm=0.5*(a+b); + tol2=2.0*(tol1=tol_brent*fabs(x)+ZEPS); + if (fabs(x-xm) <= (tol2-0.5*(b-a))) { + *xmin=x; + return fx; + } + if (fabs(e) > tol1) { + r=(x-w)*(fx-fv); + q=(x-v)*(fx-fw); + p=(x-v)*q-(x-w)*r; + q=2.0*(q-r); + if (q > 0.0) p = -p; + q=fabs(q); + etemp=e; + e=d; + if (fabs(p) >= fabs(0.5*q*etemp) || p <= q*(a-x) || p >= q*(b-x)) + d=CGOLD*(e=(x >= xm ? a-x : b-x)); + else { + d=p/q; + u=x+d; + if (u-a < tol2 || b-u < tol2) + d=SIGN(tol1,xm-x); + } + } else { + d=CGOLD*(e=(x >= xm ? a-x : b-x)); + } + u=(fabs(d) >= tol1 ? x+d : x+SIGN(tol1,d)); + fu=(*f)(u); + if (fu <= fx) { + if (u >= x) a=x; else b=x; + SHFT(v,w,x,u) + SHFT(fv,fw,fx,fu) + } else { + if (u < x) a=u; else b=u; + if (fu <= fw || w == x) { + v=w; + w=u; + fv=fw; + fw=fu; + } else if (fu <= fv || v == x || v == w) { + v=u; + fv=fu; + } + } + } + fn_DisplayError("The maximum number of iterations in brent() is reached before convergence"); + *xmin=x; + return fx; + } + #undef CGOLD + #undef ZEPS + #undef SHFT + #undef SIGN + +#else //Default to CGII_OPTIMIZATION + + static int ncom; + static double *pcom=NULL, *xicom=NULL, (*nrfunc)(double [], int); //nrfunc(), pcom, ncom, and xicom will be used by f1dim() and df1dim(). + static void (*nrdfun)(double [], double [], int, double (*func)(double [], int), double *, double); + static void dlinmin(double p[], double xi[], int n, double *fret, double tol_dbrent, double itmax_dbrent, double *grdh_p, double (*func)(double [], int), void (*dfunc)(double [], double [], int, double (*func)(double [], int), double *, double)) { + //Outputs: + // p[0, ..., n-1]: a returned and reset value. + // xi[0, ..., n-1]: a value repaced by the actual vector displacement that p was moved. + // fret: the value of func at the returned location p. + //Inputs: + // p[0, ..., n-1]: a given point. + // xi[0, ..., n-1]: a given multidimensional direction. + // n: the dimension of p and xi. + // func(): the objective function. + // dfunc(): the gradient function computing the numerical gradient. In the form of gradcd_gen() in cstz.c. + + int j; + double xx,xmin,fx,fb,fa,bx,ax; + + ncom=n; + pcom = tzMalloc(n, double); + xicom = tzMalloc(n, double); + nrfunc=func; + nrdfun=dfunc; + for (j=n-1;j>=0;j--) { + pcom[j]=p[j]; + xicom[j]=xi[j]; + } + ax=0.0; + xx=1.0; + mnbrak(&ax,&xx,&bx,&fa,&fx,&fb,f1dim); + *fret=dbrent(ax,xx,bx,f1dim, df1dim, grdh_p, tol_dbrent, itmax_dbrent, &xmin); + for (j=n-1;j>=0;j--) { + xi[j] *= xmin; + p[j] += xi[j]; + } + tzDestroy(xicom); + tzDestroy(pcom); + } + + + //=== Used by dlinmin() only; + #define ZEPS 1.0e-10 + #define MOV3(a,b,c, d,e,f) {(a)=(d);(b)=(e);(c)=(f);} + #define SIGN(a,b) ((b) >= 0.0 ? fabs(a) : -fabs(a)) + static double dbrent(double ax, double bx, double cx, double (*f)(double), double (*df)(double, double *), double *grdh_p, double tol_dbrent, double itmax_dbrent, double *xmin) { + int iter,ok1,ok2; + double a,b,d,d1,d2,du,dv,dw,dx,e=0.0; + double fu,fv,fw,fx,olde,tol1,tol2,u,u1,u2,v,w,x,xm; + + a=(ax < cx ? ax : cx); + b=(ax > cx ? ax : cx); + x=w=v=bx; + fw=fv=fx=(*f)(x); + dw=dv=dx=(*df)(x, grdh_p); + for (iter=1;iter<=itmax_dbrent;iter++) { + xm=0.5*(a+b); + tol1=tol_dbrent*fabs(x)+ZEPS; + tol2=2.0*tol1; + if (fabs(x-xm) <= (tol2-0.5*(b-a))) { + *xmin=x; + return fx; + } + if (fabs(e) > tol1) { + d1=2.0*(b-a); + d2=d1; + if (dw != dx) d1=(w-x)*dx/(dx-dw); + if (dv != dx) d2=(v-x)*dx/(dx-dv); + u1=x+d1; + u2=x+d2; + ok1 = (a-u1)*(u1-b) > 0.0 && dx*d1 <= 0.0; + ok2 = (a-u2)*(u2-b) > 0.0 && dx*d2 <= 0.0; + olde=e; + e=d; + if (ok1 || ok2) { + if (ok1 && ok2) + d=(fabs(d1) < fabs(d2) ? d1 : d2); + else if (ok1) + d=d1; + else + d=d2; + if (fabs(d) <= fabs(0.5*olde)) { + u=x+d; + if (u-a < tol2 || b-u < tol2) + d=SIGN(tol1,xm-x); + } else { + d=0.5*(e=(dx >= 0.0 ? a-x : b-x)); + } + } else { + d=0.5*(e=(dx >= 0.0 ? a-x : b-x)); + } + } else { + d=0.5*(e=(dx >= 0.0 ? a-x : b-x)); + } + if (fabs(d) >= tol1) { + u=x+d; + fu=(*f)(u); + } else { + u=x+SIGN(tol1,d); + fu=(*f)(u); + if (fu > fx) { + *xmin=x; + return fx; + } + } + du=(*df)(u, grdh_p); + if (fu <= fx) { + if (u >= x) a=x; else b=x; + MOV3(v,fv,dv, w,fw,dw) + MOV3(w,fw,dw, x,fx,dx) + MOV3(x,fx,dx, u,fu,du) + } else { + if (u < x) a=u; else b=u; + if (fu <= fw || w == x) { + MOV3(v,fv,dv, w,fw,dw) + MOV3(w,fw,dw, u,fu,du) + } else if (fu < fv || v == x || v == w) { + MOV3(v,fv,dv, u,fu,du) + } + } + } + fn_DisplayError("The maximum number of iterations in dbrent() is reached before convergence"); + return 0.0; + } + #undef ZEPS + #undef MOV3 + #undef SIGN + + //=== Used by dlinmin() and dbrent() only; + static double df1dim(double x, double *grdh_p) { + int j; + double df1=0.0; + double *xt,*df; + + xt = tzMalloc(ncom, double); + df = tzMalloc(ncom, double); + for (j=ncom-1;j>=0;j--) xt[j]=pcom[j]+x*xicom[j]; + (*nrdfun)(df, xt, ncom, nrfunc, grdh_p, nrfunc(xt, ncom)); + //=================== WARNING ====================== + //We use 0.0 because the current gradient function gradcd_gen() in cstz.c do not use this function value. A more + // sophisticated central gradient method would require this function value, and therefore we must pass + // nrfunc(xt, ncom) instead of 0.0. TZ, September 2003. + //=================== WARNING ====================== + for (j=ncom-1;j>=0;j--) df1 += df[j]*xicom[j]; + tzDestroy(df); + tzDestroy(xt); + return df1; + } + +#endif + + + +static double f1dim(double x) { + //Collapsing to one dimension line search, used by limin() or dlimin(). + int j; + double f,*xt=NULL; + + xt = tzMalloc(ncom, double); + for (j=ncom-1;j>=0;j--) xt[j]=pcom[j]+x*xicom[j]; + f=(*nrfunc)(xt, ncom); + tzDestroy(xt); + return f; +} + + +#define GOLD 1.618034 +#define GLIMIT 100.0 +#define TINY 1.0e-20 +#define SHFT(a,b,c,d) {(a)=(b);(b)=(c);(c)=(d);} +#define SIGN(a,b) ((b) >= 0.0 ? fabs(a) : -fabs(a)) +static void mnbrak(double *ax, double *bx, double *cx, double *fa, double *fb, double *fc, double (*func)(double)) { + double ulim,u,r,q,fu,dum, tmpd; + + *fa=(*func)(*ax); + *fb=(*func)(*bx); + if (*fb > *fa) { + SHFT(dum,*ax,*bx,dum) + SHFT(dum,*fb,*fa,dum) + } + *cx=(*bx)+GOLD*(*bx-*ax); + *fc=(*func)(*cx); + while (*fb > *fc) { + r=(*bx-*ax)*(*fb-*fc); + q=(*bx-*cx)*(*fb-*fa); + u=(*bx)-((*bx-*cx)*q-(*bx-*ax)*r)/ + (2.0*SIGN((tmpd=fabs(q-r))>TINY ? tmpd : TINY,q-r)); //Original: (2.0*SIGN(FMAX(fabs(q-r),TINY),q-r)); + ulim=(*bx)+GLIMIT*(*cx-*bx); + if ((*bx-u)*(u-*cx) > 0.0) { + fu=(*func)(u); + if (fu < *fc) { + *ax=(*bx); + *bx=u; + *fa=(*fb); + *fb=fu; + return; + } else if (fu > *fb) { + *cx=u; + *fc=fu; + return; + } + u=(*cx)+GOLD*(*cx-*bx); + fu=(*func)(u); + } else if ((*cx-u)*(u-ulim) > 0.0) { + fu=(*func)(u); + if (fu < *fc) { + SHFT(*bx,*cx,u,*cx+GOLD*(*cx-*bx)) + SHFT(*fb,*fc,fu,(*func)(u)) + } + } else if ((u-ulim)*(ulim-*cx) >= 0.0) { + u=ulim; + fu=(*func)(u); + } else { + u=(*cx)+GOLD*(*cx-*bx); + fu=(*func)(u); + } + SHFT(*ax,*bx,*cx,u) + SHFT(*fa,*fb,*fc,fu) + } +} +#undef GOLD +#undef GLIMIT +#undef TINY +#undef SHFT +#undef SIGN + + + + + +//------------------- +// My own functions. +//------------------- +//=== Computing Norm2 of dv. +static double ftd_norm2(double *vnew_p, double *vold_p, int _n) { + int _i; + double dtheta=0.0, //Cumulative. + tmpd; + + for (_i=_n-1; _i>=0; _i--) { + tmpd = vnew_p[_i] - vold_p[_i]; + dtheta += square(tmpd); + } + + return ( sqrt(dtheta) ); +} + +//=== Computing the inner product of x and y. +static double ftd_innerproduct(double *x, double *y, int _n) { + int _i; + double a = 0.0; //Cumulative. + for (_i=_n-1; _i>=0; _i--) a += x[_i] * y[_i]; //a += (*x++) * (*y++); Be aware that this alternative maybe too fancy. + return (a); +} + + + + +//=== Extern function to be accessed by other C files. +void congradmin_SetPrintFile(char *filename) { + if (!filename) sprintf(filename_sp3vecs, "outdata5congradmin.prn"); //Default filename. + else { + strcpy(filename_sp3vecs, filename); + //filename_sp3vecs[STRLEN-1] = '\0'; //The end of the string is set to NUL to prevent it from be a non-string. + } +} + + + +//void congradmin_SetPrintFile(FILE *fptr_sp) { +// fptr_interesults = fptr_sp; +//} + +//void congradmin_SetPrintFile_db(FILE *fptr_sp) { +// fptr_interesults_db = fptr_sp; +//} + + +#undef STRLEN diff --git a/CFiles/congradmin.h b/CFiles/congradmin.h new file mode 100755 index 0000000..cd412ee --- /dev/null +++ b/CFiles/congradmin.h @@ -0,0 +1,33 @@ +#ifndef __CONGRADMIN_H__ +#define __CONGRADMIN_H__ + #include "tzmatlab.h" + + #include <string.h> + + + + + void frprmn(double p[], int n, int *iter, double *fret, + double (*func)(double [], int), void (*dfunc)(double [], double [], int, double (*func)(double [], int), double *, double), + double *ftol_p, int *itmax_p, double *tol_brent_p, int *itmax_brent_p, double *grdh_p); + //Outputs: + // p[0, ..., n-1]: the location of the minimum if it converges, which replaces the starting value. + // iter: pointer to the number of iterations that were performed. + // fret: pointer to the minimum value of the function. + //Inputs: + // p[0, ..., n-1]: a starting point for the minimization. + // n: the dimension of p. + // ftol_p: pointer to the convergence tolerance on the objective function value. Default: 1.0e-4 if NULL. + // itmax_p: pointer to the maximum number of iterations in the main minimization program frprmn(). Default: 2000 if NULL. + // tol_brent_p: pointer to the convergence tolerance for the line minimization in brent(). Default: 2.0e-4 if NULL. + // itmax_brent_p: pointer to the maximum number of iterations for the line minimization in brent(). Default: 100 if NULL. + // grdh: pointer to the user's specified step size for a numerical gradient. If NULL, dfunc() (i.e., gradcd_gen()) will select grdh automatically. + // func(): the objective function. + // dfunc(): the gradient function computing the numerical gradient. In the form of gradcd_gen() in cstz.c. + + void congradmin_SetPrintFile(char *filename); + //If filename=NULL, no intermediate results will be printed out to a file. +// void congradmin_SetPrintFile(FILE *fptr_sp); + //If fptr_sp=NULL, no intermediate results will be printed out to a file. +// void congradmin_SetPrintFile_db(FILE *fptr_sp); +#endif diff --git a/CFiles/congradminOrigWorks.c b/CFiles/congradminOrigWorks.c new file mode 100755 index 0000000..e4cbb6e --- /dev/null +++ b/CFiles/congradminOrigWorks.c @@ -0,0 +1,557 @@ +/************************************************************* + * Conjugate Gradient Minimization Methods. See Numerical Recipes in C by Press, Flannery, Teukolsky, and Vetterling. + * (I) frprmn(): Plolak-Ribiere method with the line minimization without using the derivative information. + * (II) dlinmin(): Fletcher-Reeves method with the line minimization using the derivative information. + * + * Modified by Tao Zha, September 2003. +*************************************************************/ + +#include "congradmin.h" + +static void linmin(double p[], double xi[], int n, double *fret, double tol_brent, int itmax_brent, double (*func)(double [], int)); +static double brent(double ax, double bx, double cx, double (*f)(double), double tol_brent, double itmax_brent, double *xmin); +// +static void dlinmin(double p[], double xi[], int n, double *fret, double tol_dbrent, double itmax_dbrent, double *grdh_p, double (*func)(double [], int), void (*dfunc)(double [], double [], int, double (*func)(double [], int), double *, double)); +static double dbrent(double ax, double bx, double cx, double (*f)(double), double (*df)(double, double *), double *grdh_p, double tol_dbrent, double itmax_dbrent, double *xmin); +static double df1dim(double x, double *grdh_p); +// +static void mnbrak(double *ax, double *bx, double *cx, double *fa, double *fb, double *fc, double (*func)(double)); +static double f1dim(double x); +// +static double ftd_norm2(double *vnew_p, double *vold_p, int _n); + + + +#define STRLEN 192 +static FILE *fptr_interesults = (FILE *)NULL; //Printing intermediate results to a file. +static char filename_sp3vecs[STRLEN]; //Three vectors. 1st row: line search direction; 2nd row: numerical gradient; 3rd row: vectorized parameters. +//static FILE *fptr_interesults_db = (FILE *)NULL; //Printing intermediate results to a file for debugging (db). +#define PRINTON //Added by TZ, September 2003. +#define EPS 1.0e-10 //Small number to rectify special case of converging to exactly zero function value. +#ifdef PRINTON //Added by TZ, September 2003. + #define FREEALL {tzDestroy(xi); tzDestroy(h); tzDestroy(g); tzDestroy(pold); tzDestroy(numgrad)} +#else + #define FREEALL {tzDestroy(xi); tzDestroy(h); tzDestroy(g);} +#endif +void frprmn(double p[], int n, int *iter, double *fret, + double (*func)(double [], int), void (*dfunc)(double [], double [], int, double (*func)(double [], int), double *, double), + double *ftol_p, int *itmax_p, double *tol_brent_p, int *itmax_brent_p, double *grdh_p) { + //Outputs: + // p[0, ..., n-1]: the location of the minimum if it converges, which replaces the starting value. + // iter: pointer to the number of iterations that were performed. + // fret: pointer to the minimum value of the function. + //Inputs: + // p[0, ..., n-1]: a starting point for the minimization. + // n: the dimension of p. + // ftol_p: pointer to the convergence tolerance on the objective function value. Default: 1.0e-4 if NULL. + // itmax_p: pointer to the maximum number of iterations in the main minimization program frprmn(). Default: 2000 if NULL. + // tol_brent_p: pointer to the convergence tolerance for the line minimization in brent(). Default: 2.0e-4 if NULL. + // itmax_brent_p: pointer to the maximum number of iterations for the line minimization in brent(). Default: 100 if NULL. + // grdh: pointer to the user's specified step size for a numerical gradient. If NULL, dfunc() (i.e., gradcd_gen()) will select grdh automatically. + // func(): the objective function. + // dfunc(): the gradient function computing the numerical gradient. In the form of gradcd_gen() in cstz.c. + int j, its, itmax, itmax_brent; + double gg, gam, fp, dgg, ftol, tol_brent; + double *g=NULL, *h=NULL, *xi=NULL; + #ifdef PRINTON //Added by TZ, September 2003. + time_t begtime, currentime; + double normforp, *pold = NULL, *numgrad = NULL; + #endif + + //=== Memory allocation. + g=tzMalloc(n, double); + h=tzMalloc(n, double); + xi=tzMalloc(n, double); + // + numgrad = tzMalloc(n, double); //Added by TZ, September 2003. + #ifdef PRINTON //Added by TZ, September 2003. + pold = tzMalloc(n, double); + #endif + + //=== Default values. + if (!ftol_p) ftol = 1.0e-4; else ftol = *ftol_p; + if (!itmax_p) itmax = 200; else itmax = *itmax_p; + if (!tol_brent_p) tol_brent = 2.0e-4; else tol_brent = *tol_brent_p; + if (!itmax_brent_p) itmax_brent = 100; else itmax_brent = *itmax_brent_p; + + fp=(*func)(p, n); + (*dfunc)(xi, p, n, func, grdh_p, fp); + for (j=n-1;j>=0;j--) { + g[j] = -xi[j]; + xi[j]=h[j]=g[j]; + } + memcpy(numgrad, xi, n*sizeof(double)); //Added by TZ, September 2003. Save the numerical gradient to be printed out at the right place. + for (its=0;its<itmax;its++) { + #ifdef PRINTON + time(&begtime); //Added by TZ, September 2003. + memcpy(pold, p, n*sizeof(double)); //Added by TZ, September 2003. + #endif + //====== Added by TZ, September 2003 ====== + if ( !(fptr_interesults = fopen(filename_sp3vecs,"w")) ) { + printf("\n\nUnable to create the starting point data file %s in congradmin.c!\n", filename_sp3vecs); + getchar(); + exit(EXIT_FAILURE); + } +// rewind(fptr_interesults); //Must put the pointer at the beginning of the file. + //=== Prints out the line search direction. + fprintf(fptr_interesults, "--------Line search direction---------\n"); + for (j=0; j<n; j++) fprintf(fptr_interesults, " %0.16e ", xi[j]); + fprintf(fptr_interesults, "\n"); +// fflush( fptr_interesults ); + + + *iter=its; + #if defined (CGI_OPTIMIZATION) + linmin(p,xi,n,fret, tol_brent, itmax_brent, func); + #elif defined (CGII_OPTIMIZATION) + dlinmin(p, xi, n, fret, tol_brent, itmax_brent, grdh_p, func, dfunc); + #else + fn_DisplayError("The minimization routine frprmn() requires activating CGI_OPTIMIZATION or CGII_OPTIMIZATION in tzmatlab.h"); + #endif + #ifdef PRINTON + normforp = ftd_norm2(p, pold, n); + //=== Prints out intermediate results. + printf("\n========================================\n"); + printf("Intermediate results for the conjugate gradient algorithm."); + printf("\n (1) Number of iterations so far (maximum number): %d (%d)\n (2) New value of log posterior kernal (old value, improvement): %0.9f (%0.9f, %0.9f)\n" + " (3) Norm-2 of dx: %0.9f\n", + its, itmax, -(*fret), -fp, fp-(*fret), normforp); + fflush(stdout); // Flush the buffer to get out this message without delay. + #endif + //====== The following statements print out intermediate results. Added by TZ, September 2003 ====== + //=== Prints out the gradient. + fprintf(fptr_interesults, "--------Numerical graident---------\n"); + for (j=0; j<n; j++) fprintf(fptr_interesults, " %0.16e ", numgrad[j]); + fprintf(fptr_interesults, "\n"); + // + fprintf(fptr_interesults, "--------Restarting point---------\n"); + for (j=0; j<n; j++) fprintf(fptr_interesults, " %0.16e ", p[j]); + fprintf(fptr_interesults, "\n\n"); +// fflush( fptr_interesults ); + tzFclose(fptr_interesults); + + + if (2.0*fabs(*fret-fp) <= ftol*(fabs(*fret)+fabs(fp)+EPS)) { + //This is a normal convergence. + printf("\n----- Normal convergence by the criterion of the objective function evaluation -----------\n"); + FREEALL + return; + } + fp=(*func)(p, n); + (*dfunc)(xi, p, n, func, grdh_p, fp); + memcpy(numgrad, xi, n*sizeof(double)); //Added by TZ, September 2003. Save the numerical gradient to be printed out at the right place. +// if (filename_sp3vecs) { +// //=== Prints out the gradient. +// fprintf(fptr_interesults, "--------Numerical graident---------\n"); +// for (j=0; j<n; j++) fprintf(fptr_interesults, " %0.16e ", xi[j]); +// fprintf(fptr_interesults, "\n\n"); +//// fflush( fptr_interesults ); + +// tzFclose(fptr_interesults); +// } + dgg=gg=0.0; + for (j=n-1;j>=0;j--) { + gg += g[j]*g[j]; + dgg += (xi[j]+g[j])*xi[j]; + } + if (gg == 0.0) { + FREEALL + return; + } + gam=dgg/gg; + for (j=n-1;j>=0;j--) { + g[j] = -xi[j]; + xi[j]=h[j]=g[j]+gam*h[j]; + } + + #ifdef PRINTON + time(¤time); + //=== Times the iterative progress. + printf(" (4) Seconds to complete one iteration: %0.4f\n (5) Current time of day: %s\n", difftime(currentime, begtime), ctime(¤time)); + fflush(stdout); // Flush the buffer to get out this message without delay. + #endif + } + fn_DisplayError("The maximum number of iterations in frprmn() is reached before convergence"); +} +#undef PRINTON +#undef EPS +#undef FREEALL + + +#if defined (CGI_OPTIMIZATION) + static int ncom; + static double *pcom=NULL, *xicom=NULL, (*nrfunc)(double [], int); //nrfunc(), pcom, ncom, and xicom will be used by f1dim(). + static void linmin(double p[], double xi[], int n, double *fret, double tol_brent, int itmax_brent, double (*func)(double [], int)) { + //Outputs: + // p[0, ..., n-1]: a returned and reset value. + // xi[0, ..., n-1]: a value repaced by the actual vector displacement that p was moved. + // fret: the value of func at the returned location p. + //Inputs: + // p[0, ..., n-1]: a given point. + // xi[0, ..., n-1]: a given multidimensional direction. + // n: the dimension of p and xi. + // func(): the objective function. + int j; + double xx,xmin,fx,fb,fa,bx,ax; + + ncom=n; + pcom = tzMalloc(n, double); + xicom = tzMalloc(n, double); + nrfunc=func; + for (j=n-1;j>=0;j--) { + pcom[j]=p[j]; + xicom[j]=xi[j]; + } + ax=0.0; + xx=1.0; + mnbrak(&ax,&xx,&bx,&fa,&fx,&fb,f1dim); + *fret=brent(ax,xx,bx,f1dim, tol_brent, itmax_brent, &xmin); + for (j=n-1;j>=0;j--) { + xi[j] *= xmin; + p[j] += xi[j]; + } + tzDestroy(xicom); + tzDestroy(pcom); + } + + + //=== Used by linmin() only; + #define CGOLD 0.3819660 + #define ZEPS 1.0e-10 + #define SHFT(a,b,c,d) {(a)=(b);(b)=(c);(c)=(d);} + #define SIGN(a,b) ((b) >= 0.0 ? fabs(a) : -fabs(a)) + static double brent(double ax, double bx, double cx, double (*f)(double), double tol_brent, double itmax_brent, double *xmin) { + int iter; + double a,b,d,etemp,fu,fv,fw,fx,p,q,r,tol1,tol2,u,v,w,x,xm; + double e=0.0; + + a=(ax < cx ? ax : cx); + b=(ax > cx ? ax : cx); + x=w=v=bx; + fw=fv=fx=(*f)(x); + for (iter=0;iter<itmax_brent;iter++) { + xm=0.5*(a+b); + tol2=2.0*(tol1=tol_brent*fabs(x)+ZEPS); + if (fabs(x-xm) <= (tol2-0.5*(b-a))) { + *xmin=x; + return fx; + } + if (fabs(e) > tol1) { + r=(x-w)*(fx-fv); + q=(x-v)*(fx-fw); + p=(x-v)*q-(x-w)*r; + q=2.0*(q-r); + if (q > 0.0) p = -p; + q=fabs(q); + etemp=e; + e=d; + if (fabs(p) >= fabs(0.5*q*etemp) || p <= q*(a-x) || p >= q*(b-x)) + d=CGOLD*(e=(x >= xm ? a-x : b-x)); + else { + d=p/q; + u=x+d; + if (u-a < tol2 || b-u < tol2) + d=SIGN(tol1,xm-x); + } + } else { + d=CGOLD*(e=(x >= xm ? a-x : b-x)); + } + u=(fabs(d) >= tol1 ? x+d : x+SIGN(tol1,d)); + fu=(*f)(u); + if (fu <= fx) { + if (u >= x) a=x; else b=x; + SHFT(v,w,x,u) + SHFT(fv,fw,fx,fu) + } else { + if (u < x) a=u; else b=u; + if (fu <= fw || w == x) { + v=w; + w=u; + fv=fw; + fw=fu; + } else if (fu <= fv || v == x || v == w) { + v=u; + fv=fu; + } + } + } + fn_DisplayError("The maximum number of iterations in brent() is reached before convergence"); + *xmin=x; + return fx; + } + #undef CGOLD + #undef ZEPS + #undef SHFT + #undef SIGN + +#else //Default to CGII_OPTIMIZATION + + static int ncom; + static double *pcom=NULL, *xicom=NULL, (*nrfunc)(double [], int); //nrfunc(), pcom, ncom, and xicom will be used by f1dim() and df1dim(). + static void (*nrdfun)(double [], double [], int, double (*func)(double [], int), double *, double); + static void dlinmin(double p[], double xi[], int n, double *fret, double tol_dbrent, double itmax_dbrent, double *grdh_p, double (*func)(double [], int), void (*dfunc)(double [], double [], int, double (*func)(double [], int), double *, double)) { + //Outputs: + // p[0, ..., n-1]: a returned and reset value. + // xi[0, ..., n-1]: a value repaced by the actual vector displacement that p was moved. + // fret: the value of func at the returned location p. + //Inputs: + // p[0, ..., n-1]: a given point. + // xi[0, ..., n-1]: a given multidimensional direction. + // n: the dimension of p and xi. + // func(): the objective function. + // dfunc(): the gradient function computing the numerical gradient. In the form of gradcd_gen() in cstz.c. + + int j; + double xx,xmin,fx,fb,fa,bx,ax; + + ncom=n; + pcom = tzMalloc(n, double); + xicom = tzMalloc(n, double); + nrfunc=func; + nrdfun=dfunc; + for (j=n-1;j>=0;j--) { + pcom[j]=p[j]; + xicom[j]=xi[j]; + } + ax=0.0; + xx=1.0; + mnbrak(&ax,&xx,&bx,&fa,&fx,&fb,f1dim); + *fret=dbrent(ax,xx,bx,f1dim, df1dim, grdh_p, tol_dbrent, itmax_dbrent, &xmin); + for (j=n-1;j>=0;j--) { + xi[j] *= xmin; + p[j] += xi[j]; + } + tzDestroy(xicom); + tzDestroy(pcom); + } + + + //=== Used by dlinmin() only; + #define ZEPS 1.0e-10 + #define MOV3(a,b,c, d,e,f) {(a)=(d);(b)=(e);(c)=(f);} + #define SIGN(a,b) ((b) >= 0.0 ? fabs(a) : -fabs(a)) + static double dbrent(double ax, double bx, double cx, double (*f)(double), double (*df)(double, double *), double *grdh_p, double tol_dbrent, double itmax_dbrent, double *xmin) { + int iter,ok1,ok2; + double a,b,d,d1,d2,du,dv,dw,dx,e=0.0; + double fu,fv,fw,fx,olde,tol1,tol2,u,u1,u2,v,w,x,xm; + + a=(ax < cx ? ax : cx); + b=(ax > cx ? ax : cx); + x=w=v=bx; + fw=fv=fx=(*f)(x); + dw=dv=dx=(*df)(x, grdh_p); + for (iter=1;iter<=itmax_dbrent;iter++) { + xm=0.5*(a+b); + tol1=tol_dbrent*fabs(x)+ZEPS; + tol2=2.0*tol1; + if (fabs(x-xm) <= (tol2-0.5*(b-a))) { + *xmin=x; + return fx; + } + if (fabs(e) > tol1) { + d1=2.0*(b-a); + d2=d1; + if (dw != dx) d1=(w-x)*dx/(dx-dw); + if (dv != dx) d2=(v-x)*dx/(dx-dv); + u1=x+d1; + u2=x+d2; + ok1 = (a-u1)*(u1-b) > 0.0 && dx*d1 <= 0.0; + ok2 = (a-u2)*(u2-b) > 0.0 && dx*d2 <= 0.0; + olde=e; + e=d; + if (ok1 || ok2) { + if (ok1 && ok2) + d=(fabs(d1) < fabs(d2) ? d1 : d2); + else if (ok1) + d=d1; + else + d=d2; + if (fabs(d) <= fabs(0.5*olde)) { + u=x+d; + if (u-a < tol2 || b-u < tol2) + d=SIGN(tol1,xm-x); + } else { + d=0.5*(e=(dx >= 0.0 ? a-x : b-x)); + } + } else { + d=0.5*(e=(dx >= 0.0 ? a-x : b-x)); + } + } else { + d=0.5*(e=(dx >= 0.0 ? a-x : b-x)); + } + if (fabs(d) >= tol1) { + u=x+d; + fu=(*f)(u); + } else { + u=x+SIGN(tol1,d); + fu=(*f)(u); + if (fu > fx) { + *xmin=x; + return fx; + } + } + du=(*df)(u, grdh_p); + if (fu <= fx) { + if (u >= x) a=x; else b=x; + MOV3(v,fv,dv, w,fw,dw) + MOV3(w,fw,dw, x,fx,dx) + MOV3(x,fx,dx, u,fu,du) + } else { + if (u < x) a=u; else b=u; + if (fu <= fw || w == x) { + MOV3(v,fv,dv, w,fw,dw) + MOV3(w,fw,dw, u,fu,du) + } else if (fu < fv || v == x || v == w) { + MOV3(v,fv,dv, u,fu,du) + } + } + } + fn_DisplayError("The maximum number of iterations in dbrent() is reached before convergence"); + return 0.0; + } + #undef ZEPS + #undef MOV3 + #undef SIGN + + //=== Used by dlinmin() and dbrent() only; + static double df1dim(double x, double *grdh_p) { + int j; + double df1=0.0; + double *xt,*df; + + xt = tzMalloc(ncom, double); + df = tzMalloc(ncom, double); + for (j=ncom-1;j>=0;j--) xt[j]=pcom[j]+x*xicom[j]; + (*nrdfun)(df, xt, ncom, nrfunc, grdh_p, nrfunc(xt, ncom)); + //=================== WARNING ====================== + //We use 0.0 because the current gradient function gradcd_gen() in cstz.c do not use this function value. A more + // sophisticated central gradient method would require this function value, and therefore we must pass + // nrfunc(xt, ncom) instead of 0.0. TZ, September 2003. + //=================== WARNING ====================== + for (j=ncom-1;j>=0;j--) df1 += df[j]*xicom[j]; + tzDestroy(df); + tzDestroy(xt); + return df1; + } + +#endif + + + +static double f1dim(double x) { + //Collapsing to one dimension line search, used by limin() or dlimin(). + int j; + double f,*xt=NULL; + + xt = tzMalloc(ncom, double); + for (j=ncom-1;j>=0;j--) xt[j]=pcom[j]+x*xicom[j]; + f=(*nrfunc)(xt, ncom); + tzDestroy(xt); + return f; +} + + +#define GOLD 1.618034 +#define GLIMIT 100.0 +#define TINY 1.0e-20 +#define SHFT(a,b,c,d) {(a)=(b);(b)=(c);(c)=(d);} +#define SIGN(a,b) ((b) >= 0.0 ? fabs(a) : -fabs(a)) +static void mnbrak(double *ax, double *bx, double *cx, double *fa, double *fb, double *fc, double (*func)(double)) { + double ulim,u,r,q,fu,dum, tmpd; + + *fa=(*func)(*ax); + *fb=(*func)(*bx); + if (*fb > *fa) { + SHFT(dum,*ax,*bx,dum) + SHFT(dum,*fb,*fa,dum) + } + *cx=(*bx)+GOLD*(*bx-*ax); + *fc=(*func)(*cx); + while (*fb > *fc) { + r=(*bx-*ax)*(*fb-*fc); + q=(*bx-*cx)*(*fb-*fa); + u=(*bx)-((*bx-*cx)*q-(*bx-*ax)*r)/ + (2.0*SIGN((tmpd=fabs(q-r))>TINY ? tmpd : TINY,q-r)); //Original: (2.0*SIGN(FMAX(fabs(q-r),TINY),q-r)); + ulim=(*bx)+GLIMIT*(*cx-*bx); + if ((*bx-u)*(u-*cx) > 0.0) { + fu=(*func)(u); + if (fu < *fc) { + *ax=(*bx); + *bx=u; + *fa=(*fb); + *fb=fu; + return; + } else if (fu > *fb) { + *cx=u; + *fc=fu; + return; + } + u=(*cx)+GOLD*(*cx-*bx); + fu=(*func)(u); + } else if ((*cx-u)*(u-ulim) > 0.0) { + fu=(*func)(u); + if (fu < *fc) { + SHFT(*bx,*cx,u,*cx+GOLD*(*cx-*bx)) + SHFT(*fb,*fc,fu,(*func)(u)) + } + } else if ((u-ulim)*(ulim-*cx) >= 0.0) { + u=ulim; + fu=(*func)(u); + } else { + u=(*cx)+GOLD*(*cx-*bx); + fu=(*func)(u); + } + SHFT(*ax,*bx,*cx,u) + SHFT(*fa,*fb,*fc,fu) + } +} +#undef GOLD +#undef GLIMIT +#undef TINY +#undef SHFT +#undef SIGN + + + + + +//------------------- +// My own functions. +//------------------- +//=== Computing Norm2 of dx. +static double ftd_norm2(double *vnew_p, double *vold_p, int _n) { + int _i; + double dtheta=0.0, //Cumulative. + tmpd; + + for (_i=_n; _i>=0; _i--) { + tmpd = vnew_p[_i] - vold_p[_i]; + dtheta += square(tmpd); + } + + return ( sqrt(dtheta) ); +} + + + +//=== Extern function to be accessed by other C files. +void congradmin_SetPrintFile(char *filename) { + if (!filename) sprintf(filename_sp3vecs, "outdata5congradmin.prn"); //Default filename. + else { + strcpy(filename_sp3vecs, filename); + //filename_sp3vecs[STRLEN-1] = '\0'; //The end of the string is set to NUL to prevent it from be a non-string. + } +} + + + +//void congradmin_SetPrintFile(FILE *fptr_sp) { +// fptr_interesults = fptr_sp; +//} + +//void congradmin_SetPrintFile_db(FILE *fptr_sp) { +// fptr_interesults_db = fptr_sp; +//} + + +#undef STRLEN diff --git a/CFiles/congradminOrigWorks.h b/CFiles/congradminOrigWorks.h new file mode 100755 index 0000000..567c40a --- /dev/null +++ b/CFiles/congradminOrigWorks.h @@ -0,0 +1,33 @@ +#ifndef __CONGRADMIN_H__ +#define __CONGRADMIN_H__ + + #include <math.h> + #include <string.h> + + #include "tzmatlab.h" + + + void frprmn(double p[], int n, int *iter, double *fret, + double (*func)(double [], int), void (*dfunc)(double [], double [], int, double (*func)(double [], int), double *, double), + double *ftol_p, int *itmax_p, double *tol_brent_p, int *itmax_brent_p, double *grdh_p); + //Outputs: + // p[0, ..., n-1]: the location of the minimum if it converges, which replaces the starting value. + // iter: pointer to the number of iterations that were performed. + // fret: pointer to the minimum value of the function. + //Inputs: + // p[0, ..., n-1]: a starting point for the minimization. + // n: the dimension of p. + // ftol_p: pointer to the convergence tolerance on the objective function value. Default: 1.0e-4 if NULL. + // itmax_p: pointer to the maximum number of iterations in the main minimization program frprmn(). Default: 2000 if NULL. + // tol_brent_p: pointer to the convergence tolerance for the line minimization in brent(). Default: 2.0e-4 if NULL. + // itmax_brent_p: pointer to the maximum number of iterations for the line minimization in brent(). Default: 100 if NULL. + // grdh: pointer to the user's specified step size for a numerical gradient. If NULL, dfunc() (i.e., gradcd_gen()) will select grdh automatically. + // func(): the objective function. + // dfunc(): the gradient function computing the numerical gradient. In the form of gradcd_gen() in cstz.c. + + void congradmin_SetPrintFile(char *filename); + //If filename=NULL, no intermediate results will be printed out to a file. +// void congradmin_SetPrintFile(FILE *fptr_sp); + //If fptr_sp=NULL, no intermediate results will be printed out to a file. +// void congradmin_SetPrintFile_db(FILE *fptr_sp); +#endif diff --git a/CFiles/csminwel.c b/CFiles/csminwel.c new file mode 100755 index 0000000..6bae180 --- /dev/null +++ b/CFiles/csminwel.c @@ -0,0 +1,848 @@ +//======= Revisions by T. Zha. +//======= Fixing bugs: convering all if-else loop. 02/24/05 +/*========================================================= + * csminwel.c + * + * Unconstrained minimization. Uses a quasi-Newton method with BFGS update of + * the estimated inverse hessian. It is robust against certain pathologies + * common on likelihood functions. It attempts to be robust against "cliffs", + * i.e. hyperplane discontinuities, though it is not really clear whether what + * it does in such cases succeeds reliably. + * + * function [fhat,xhat,ghat,Hhat,itct,fcount,retcodehat] = csminwelmex(fcn,x0,H0,grad,crit,nit,varargin) + * fcn: string naming the objective function to be minimized + * x0: initial value of the parameter vector + * H0: initial value for the inverse Hessian. Must be positive definite. + * grad: Either a string naming a function that calculates the gradient, or the null matrix. + * If it's null, the program calculates a numerical gradient. In this case fcn must + * be written so that it can take a matrix argument and produce a row vector of values. + * crit: Convergence criterion. Iteration will cease when it proves impossible to improve the + * function value by more than crit. + * nit: Maximum number of iterations. + * varargin: A list of optional length of additional parameters that get handed off to fcn each + * time it is called. + * Note that if the program ends abnormally, it is possible to retrieve the current x, + * f, and H from the files g1.mat and H.mat that are written at each iteration and at each + * hessian update, respectively. (When the routine hits certain kinds of difficulty, it + * write g2.mat and g3.mat as well. If all were written at about the same time, any of them + * may be a decent starting point. One can also start from the one with best function value.) + * + * retcodes: 0, normal step (converged). 1, zero gradient (converged). + * 4,2, back and forth adjustment of stepsize didn't finish. + * 3, smallest stepsize still improves too slow. 5, largest step still improves too fast. + * 6, no improvement found. + *--------------------- + * Fixed 7/17/93 to use inverse-hessian instead of hessian itself in bfgs update. + * Fixed 7/19/93 to flip eigenvalues of H to get better performance when it's not psd. + * + * Note: to set the level of display output, change preprocessor definitions at the beginning of this file. + * to display all output, uncomment both VERBOSE_WARNINGS and VERBOSE_DETOUTPUT + * to display only warnings without output, uncomment VERBOSE_WARNINGS + * to display no ouput, comment both VERBOSE_DETOUTPUT and VERBOSE_WARNINGS + * + * MATLAB algorithm by Christopher Sims + * C implementation by Iskander Karibzhanov + * Modified by Dan Waggoner and Tao Zha + * + * Copyright(c) 1996 Christopher Sims + * Copyright(c) 2003 Karibzhanov, Waggoner, and Zha + *======================================================= + * Revision history by T. Zha: + * + * 10/3/2002 - 1. corrected problem with memory corruption in C-MEX-file (csminwelmex.c) + * (needed to switch fcnRhs[0] back to x[0] before destroying it. + * If we don't do this, we will later clear previously destroyed array + * (one of x[1], x[2] or x[3]) which causes memory fault. + * The reason why fcnRhs[0] pointed to array other than x[0] is + * because we use mxSetPr in feval and gfeval. + * This was not a problem in C-file (csminwel.c). + * + * 10/11/2002 - 1. changed csminit function to avoid using fPeak without first initializing it + * 2. added two switches in csminit function to assign retcode to 7 for lambda>=4 + * 3. added one more verbose level to display only warnings or all output * + * + * 07/13/2005 - Change #define GRADSTPS_CSMINWEL to double GRADSTPS_CSMINWEL in the .h file so the user can change the value. + * + * 03/10/2006 - Iskander's use of randmax=1/RAND_MAX is incorrect. Changed to randmax=1.0/RAND_MAX. Note rand() is in stdlib.h and time() is in time.h. + * - Fatal BUG by Iskander to have eye(n) instead of eye(nn). Corrected by TZ. + * +========================================================*/ + +//#include "csminwel.h" +#include "optpackage.h" + +#define VERBOSE_WARNINGS //Display warnings. +#define VERBOSE_DETOUTPUT //Display detailed output. +#define STRLEN 192 +//#define INDXNUMGRAD_CSMINWEL 2 //Index for choosing the numerical gradient. 1, forward difference; 2, central difference. + +double GRADSTPS_CSMINWEL = 1.0e-04; //Default value. Will be overwritten by the data in the input file if it exists. + //1.0e-04 (for monthly TBVAR) + //Step size for numerical gradient only when the value of x is less than 1.0 in absolute value. + //If abs(x)>1.0, the step size is GRADSTPS_CSMINWEL*x. +static int RANDOMSEED_CSMINWEL = 0; //Default value: no fixed seed. Will be initialized somewhere else through csminwel_randomseedChanged(). + + +static double GLB_sclForHess; +static int numgrad(double *g, double *x, int n, + double (*fcn)(double *x, int n, double **args, int *dims), + double **args, int *dims); +static void csminit(double *fhat, double *xhat, int *fcount, int *retcode, + double *x0, double f0, double *g, int badg, double *H0, int n, + double (*fcn)(double *x, int n, double **args, int *dims), + double **args, int *dims); +static void bfgsi(double *H, double *dg, double *dx, int n, int nn); +static int peakwall(double *g, int retcode, double *x, int n, + int (*gfcn)(double *x, int n, double *g, double **args, int *dims), + double (*fcn)(double *x, int n, double **args, int *dims), + double **args, int *dims); +static double times(double *x, double *y, int n); +static double *mtimes(double *x, double *y, int n, int nn); +static double *mminus(double *x, double *y, int n); + + +static FILE *fptr_interesults = (FILE *)NULL; //Printing intermediate results to a file. +static char filename_sp2vecs[STRLEN]; //Two vectors. 1st row: numerical gradient; 2nd row: vectorized parameters. + + + +#define MAX_NUM_BADCASES 3 +#define EPS (1.0e-10) //Small number to rectify special case of converging to exactly zero function value. +#define TERMINATEVALUE (1.0e+300) //If the value of the objective function at the intial value is greater than this, terminates the program. +void csminwel(double (*fcn)(double *x, int n, double **args, int *dims), + double *xh, int n, double *H, double *gh, + int (*gfcn)(double *x, int n, double *g, double **args, int *dims), + double *fh, double crit, int *itct, int nit, + int *fcount, int *retcodeh, double **args, int *dims) +{ + //If gfcn is passed as NULL, numerical gradient is automatically computed. + //unsigned int randomseed = (unsigned int)time((time_t)RANDOMSEED_CSMINWEL); //793; + + unsigned int randomseed; + static int first_time = TZ_TRUE; //Added by T.Zha; 03/10/2006. + + int done=0, badg[4], badgh, nogh=1, stuck=0; + double *x[4], *g[4], f[4], *dg, *dx; + int retcode[3], fc=0, ih, nn, i; + int cnt_n_badcases = 0; //Must set to 0. Counts the number of bad cases before restarting with the initial diagonal (inverse of) Hessian. Added by TZ. + TSdmatrix *H_dm = tzMalloc(1, TSdmatrix); //H_dm wil point to the same location as H. + #ifdef VERBOSE_DETOUTPUT + time_t begtime, currentime; + #endif + + //=== Seed for random number generator in stdlib.h. Added by T.Zha; 03/10/2006. + if (!RANDOMSEED_CSMINWEL) + randomseed = (unsigned int)time((time_t *)NULL); + //Note that (unsigned int)time(0) uses the time of day for random seed. + //Added by T.Zha; 03/10/2006. time() is in time.h. + else + randomseed = (unsigned int)RANDOMSEED_CSMINWEL; + + if ( first_time ) + { + first_time = TZ_FALSE; + srand( randomseed ); + } + + + GLB_sclForHess = H[0]; //The scale factor for the initial (inverse of) Hessian, which was supposed to be **diagonal**. Added by TZ. + + nn = n*n; /* n: dimension size of x or xh */ + *itct = -1; /* itct: number of actual iterations */ + *fcount = -1; /* fcount: number of evaluations of the function */ + + for (i=0; i<4; i++) + x[i] = tzMalloc(n, double); //x[i] = calloc(n, sizeof(double)); Commented out by TZ. + memcpy(x[0],xh,n*sizeof(double)); + + for (i=0; i<4; i++) + g[i] = tzMalloc(n, double); //calloc(n, sizeof(double)); Commented out by TZ. + + f[0] = fcn(x[0],n,args,dims); + + if (f[0] > TERMINATEVALUE) { + printf("Bad initial parameter. Minimization is terminated without any returned value!\n"); + return; + } + + if (gfcn) + /* if grad is a string, compute it */ + badg[0] = gfcn(x[0],n,g[0],args,dims); + else + /* if grad is not string, compute it */ + badg[0] = numgrad(g[0],x[0],n,fcn,args,dims); + retcode[2] = 101; + /* iterate until done is false */ + while (!done) { + #ifdef VERBOSE_DETOUTPUT + time(&begtime); + #endif + + for (i=0; i<n; i++) + g[1][i] = g[2][i] = g[3][i] = 0; + +// #ifdef VERBOSE_DETOUTPUT +// printf("-----------------\n-----------------\n"); +// printf("f at the beginning of new iteration, %.10f\nx = ",f[0]); +// for (i=0; i<n; i++) { +// printf("%15.8g ",x[0][i]); +// if (i%4==3) printf("\n"); +// } +// if (i%4>0) printf("\n"); +// #endif + + (*itct)++; + csminit(&f[1],x[1],&fc,&retcode[0],x[0],f[0],g[0],badg[0],H,n,fcn,args,dims); + *fcount += fc; + /* if retcode1=1 gradient is zero and you are at the peak */ + if (retcode[0]!=1) { + badg[1] = peakwall(g[1],retcode[0],x[1],n,gfcn,fcn,args,dims); + /* Bad gradient or back and forth on step length. + Possibly at cliff edge. Try perturbing search direction. */ + if (badg[1]) { + double *Hcliff = tzMalloc(nn, double); //calloc(nn,sizeof(double)); Commented out by TZ. + double randmax=1.0/(double)RAND_MAX; //03/10/2006, changed from 1/ to 1.0/ to make randmax a legal double. + /* if stuck, give it another try by perturbing Hessian */ + memcpy(Hcliff,H,nn*sizeof(double)); + for (i=0; i<nn; i+=n+1) + Hcliff[i] *= 1+rand()*randmax; //DDDDebugging. Hcliff[i] *= 1+0.5; + + #ifdef VERBOSE_WARNINGS + printf("======= Random search takes place now. =======\n"); + printf("Cliff. Perturbing search direction.\n"); + #endif + + csminit(&f[2],x[2],&fc,&retcode[1],x[0],f[0],g[0],badg[0],Hcliff,n,fcn,args,dims); + *fcount += fc; + if (f[2] < f[0]) { + badg[2] = peakwall(g[2],retcode[1],x[2],n,gfcn,fcn,args,dims); + if (badg[2]) { + double *xx = tzMalloc(n, double), nx; //calloc(n,sizeof(double)), nx; Commented out by TZ. + + #ifdef VERBOSE_WARNINGS + printf("Cliff again. Try traversing.\n"); + #endif + + for (i=0; i<n; i++) + xx[i] = x[2][i]-x[1][i]; + nx = times(xx,xx,n); + if (sqrt(nx) < 1e-13) { + f[3] = f[0]; + memcpy(x[3],x[0],n*sizeof(double)); + badg[3] = 1; + retcode[2] = 101; + } else { + double *gcliff = tzMalloc(n, double), //calloc(n,sizeof(double)), Commented out by TZ. + *eye = tzMalloc(nn, double); //calloc(n,sizeof(double)); Bugs of Iskander. Changed from n to nn. 03/10/06. + double dfnx = (f[2]-f[1])/nx; + for (i=0; i<n; i++) { + gcliff[i] = dfnx*xx[i]; + eye[i*(n+1)] = 1; + } + csminit(&f[3],x[3],&fc,&retcode[2],x[0],f[0],gcliff,0,eye,n,fcn,args,dims); + *fcount += fc; + badg[3] = peakwall(g[3],retcode[2],x[3],n,gfcn,fcn,args,dims); + tzDestroy(eye); + tzDestroy(gcliff); + } + tzDestroy(xx); + } else { + f[3] = f[0]; + memcpy(x[3],x[0],n*sizeof(double)); + badg[3] = 1; + retcode[2] = 101; + } + } else { + f[3] = f[0]; + memcpy(x[3],x[0],n*sizeof(double)); + badg[3] = 1; + retcode[2] = 101; + } + tzDestroy(Hcliff); + } else { + /* normal iteration, no walls, or else we're finished here. */ + f[2] = f[0]; + f[3] = f[0]; + badg[2] = 1; + badg[3] = 1; + retcode[1] = 101; + retcode[2] = 101; + } + } + else //Bugs fixed by T. Zha -- 02/24/05. + { + f[1] = f[0]; + f[2] = f[0]; + f[3] = f[0]; + retcode[1] = retcode[0]; + retcode[2] = retcode[0]; + } +// % normal iteration, no walls, or else we're finished here. +// f2=f; f3=f; badg2=1; badg3=1; retcode2=101; retcode3=101; +// f1=f; f2=f; f3=f; retcode2=retcode1; retcode3=retcode1; + + /* how to pick gh and xh */ + if (f[3]<f[0] && badg[3]==0) { + /* if 3 (transversing) was needed, it improved and gradient is good, take that */ + ih = 3; + *fh = f[3]; + memcpy(xh,x[3],n*sizeof(double)); + memcpy(gh,g[3],n*sizeof(double)); + badgh = badg[3]; + *retcodeh = retcode[2]; + } + else if (f[2]<f[0] && badg[2]==0) { + /* if 2 (perturbig) was needed, it improved and gradient is good, take that */ + ih = 2; + *fh = f[2]; + memcpy(xh,x[2],n*sizeof(double)); + memcpy(gh,g[2],n*sizeof(double)); + badgh = badg[2]; + *retcodeh = retcode[1]; + } + else if (f[1]<f[0] && badg[1]==0) { + /* if first try went fine, take that */ + ih = 1; + *fh = f[1]; + memcpy(xh,x[1],n*sizeof(double)); + memcpy(gh,g[1],n*sizeof(double)); + badgh = badg[1]; + *retcodeh = retcode[0]; + } + else { + /* if nothing worked, just take the min of your attempts and compute the gradient */ + if (f[1] <= f[2]) + if (f[1] <= f[3]) ih = 1; + else ih = 3; + else + if (f[2] <= f[3]) ih = 2; + else ih = 3; + *fh = f[ih]; + memcpy(xh,x[ih],n*sizeof(double)); + *retcodeh = retcode[ih-1]; + if (nogh) { + nogh = 0; + if (gfcn) + badgh = gfcn(xh,n,gh,args,dims); + else + badgh = numgrad(gh,xh,n,fcn,args,dims); + } + badgh = 1; + } + /* end of picking */ + stuck = fabs(*fh-f[0]) < crit; // Used if fh>0. TZ, 9/03. + //stuck = (2.0*fabs(*fh-f[0]) <= crit*(fabs(*fh)+fabs(f[0])+EPS)); //Used if fh<0. Added by TZ, 9/03. + /* if nothing REALLY worked, too bad, you're stuck */ + if (!badg[0] && !badgh && !stuck) { + /* if you are not stuck, update H0 matrix */ + dg = mminus(gh,g[0],n); + dx = mminus(xh,x[0],n); + bfgsi(H,dg,dx,n,nn); + tzDestroy(dx); + tzDestroy(dg); + } + + #ifdef VERBOSE_DETOUTPUT + //=== Prints out intermediate results. + printf("========================================\n"); + printf(" (1) New value of the obj. func. on iteration %d: %.9f\n (2) Old value: %.9f\n (3) Downhill improvement: %.9f\n", + (int)*itct, *fh, f[0], f[0]-(*fh)); + + time(¤time); + //=== Times the iterative progress. + printf(" (4) Seconds to complete one iteration: %0.4f\n (5) Current time of day: %s\n\n", difftime(currentime, begtime), ctime(¤time)); + fflush(stdout); // Flush the buffer to get out this message without delay. + #endif + + //--------- Prints outputs to a file. --------- + if ( !(fptr_interesults = fopen(filename_sp2vecs,"w")) ) { + printf("\n\nUnable to create the starting point data file %s in csminwel.c!\n", filename_sp2vecs); + getchar(); + exit(EXIT_FAILURE); + } + fprintf(fptr_interesults, "========= Only one block at a time if more-than-one blocks are used. ========== \n"); + fprintf(fptr_interesults, "--------Numerical gradient---------\n"); + for (i=0; i<n; i++) fprintf(fptr_interesults, " %0.16e ", gh[i]); + fprintf(fptr_interesults, "\n"); + fprintf(fptr_interesults, "--------Restarting point---------\n"); + for (i=0; i<n; i++) fprintf(fptr_interesults, " %0.16e ", xh[i]); + fprintf(fptr_interesults, "\n\n"); + fflush(fptr_interesults); + tzFclose(fptr_interesults); + + if ((int)*itct > nit) { + #ifdef VERBOSE_WARNINGS + printf("\nWarning: termination as the maximum number of iterations is reached.\n"); + #endif + done = 1; + } + else if (stuck) { + #ifdef VERBOSE_DETOUTPUT + printf("\nConvergence (improvement < crit %.4e) with return code %d.\n", crit, *retcodeh); + #endif + + done = 1; + } + + + #ifdef VERBOSE_WARNINGS + switch (*retcodeh) { + case 1: + printf("\nCoverged: Zero gradient.\n"); break; + case 2: + printf("\nWarning: Back adjustment of stepsize didn't finish.\n"); break; + case 3: + printf("\nWarning: Smallest stepsize still improving too slow.\n"); break; + case 4: + printf("\nWarning: Forth adjustment of stepsize didn't finish.\n"); break; + case 6: + printf("\nWarning: Smallest step still improving too slow, reversed gradient.\n"); break; + case 5: + printf("\nWarning: Largest stepsize still improving too fast.\n"); break; + case 7: + printf("\nWarning: Possible inaccuracy in Hessian matrix.\n"); break; + } + #endif + + //=== Restarts from the initial (inverse of) Hessian when stuck for a while in bad cases. Added by TZ. + if (*retcodeh && *retcodeh != 1) + if (++cnt_n_badcases >= MAX_NUM_BADCASES) { + H_dm->M = H; + H_dm->nrows = H_dm->ncols = n; + InitializeDiagonalMatrix_lf(H_dm, GLB_sclForHess); + //H_dm->flag = M_GE | M_SU | M_SL; //Hessian is symmetric. + cnt_n_badcases = 0; //Reset after we restart wtih the initial Hessian. + #ifdef VERBOSE_WARNINGS + printf("Hessian is reset to the initial value because the maximum number of bad cases, %d, is reached!\n", MAX_NUM_BADCASES); + #endif + } + + f[0] = *fh; + memcpy(x[0],xh,n*sizeof(double)); + memcpy(g[0],gh,n*sizeof(double)); + badg[0] = badgh; + } + + + //--------- Prints outputs to a file. --------- + if ( !(fptr_interesults = fopen(filename_sp2vecs,"w")) ) { + printf("\n\nUnable to create the starting point data file %s in csminwel.c!\n", filename_sp2vecs); + getchar(); + exit(EXIT_FAILURE); + } + fprintf(fptr_interesults, "========= Only a block at a time if more-than-one blocks are used. ========== \n"); + fprintf(fptr_interesults, "--------Numerical gradient---------\n"); + for (i=0; i<n; i++) fprintf(fptr_interesults, " %0.16e ", g[0][i]); + fprintf(fptr_interesults, "\n"); + fprintf(fptr_interesults, "--------Restarting point---------\n"); + for (i=0; i<n; i++) fprintf(fptr_interesults, " %0.16e ", x[0][i]); + fprintf(fptr_interesults, "\n\n"); + fflush(fptr_interesults); + tzFclose(fptr_interesults); + + + //=== Frees memory. + for (i=0; i<4; i++) { + tzDestroy(g[i]); + tzDestroy(x[i]); + } + tzDestroy(H_dm); +} +#undef MAX_NUM_BADCASES +#undef EPS +#undef TERMINATEVALUE + + +#if INDXNUMGRAD_CSMINWEL == 1 + #define SCALE 1.0 + static int numgrad(double *g, double *x, int n, + double (*fcn)(double *x, int n, double **args, int *dims), + double **args, int *dims) { + //Forward difference gradient method. + double delta, deltai; + double f0, g0, ff, tmp, *xp; + int i; + int badg; + f0 = fcn(x,n,args,dims); + badg = 0; + for (i=0, xp=x; i<n; i++, xp++, g++) { + delta=SCALE*GRADSTPS_CSMINWEL, deltai=1.0/delta; //e+5/SCALE; + + tmp = *xp; + *xp += delta; + delta = *xp - tmp; // This increases the precision slightly. Added by TZ. + if ( (ff=fcn(x,n,args,dims)) < NEARINFINITY ) g0 = (ff-f0)*deltai; //Not over the boundary. + else { + //Switches to the other side of the boundary. + *xp = tmp - delta; + g0 = (f0-fcn(x,n,args,dims))*deltai; + } + + *xp = tmp; //Puts back to the original place. TZ, 9/03. + if (fabs(g0)<1.0e+15) + *g = g0; + else { + #ifdef VERBOSE_WARNINGS + printf("Bad gradient.\n"); + #endif + + *g = 0; + badg = 1; + } + } + return badg; + } + //#elif INDXNUMGRAD_CSMINWEL == 2 +#else + //#define STPS 1.0e-04 // 6.0554544523933391e-6 step size = pow(DBL_EPSILON,1.0/3) + static int numgrad(double *g, double *x, int n, + double (*fcn)(double *x, int n, double **args, int *dims), + double **args, int *dims) { + //Central difference gradient method. Added by TZ. + double dh; + double f0, fp, fm, tmp, *xp; + int i; + int badg; + + badg = 0; + for (i=0, xp=x; i<n; i++, xp++, g++) { + dh = fabs(*xp)<=1 ? GRADSTPS_CSMINWEL : GRADSTPS_CSMINWEL*(*xp); + + tmp = *xp; + *xp += dh; + dh = *xp - tmp; // This increases the precision slightly. + fp = fcn(x,n,args,dims); + *xp = tmp - dh; + fm = fcn(x,n,args,dims); + + //=== Checking the boundary condition for the minimization problem. + if (fp >= NEARINFINITY) { + *xp = tmp; //Puts back to the original place. TZ, 9/03. + f0 = fcn(x,n,args,dims); + *g = (f0-fm)/dh; + } + else if (fm >= NEARINFINITY) { + //Switches to the other side of the boundary. + *xp = tmp; //Puts back to the original place. TZ, 9/03. + f0 = fcn(x,n,args,dims); + *g = (fp-f0)/dh; + } + else { + *g = (fp-fm)/(2.0*dh); + *xp = tmp; //Puts back to the original place. TZ, 9/03. + } + + if (fabs(*g)>1.0e+15) { + #ifdef VERBOSE_WARNINGS + printf("Bad gradient.\n"); + #endif + *g = 0.0; + badg = 1; + } + } + return badg; + } +#endif +////#undef INDXNUMGRAD_CSMINWEL +////#undef GRADSTPS_CSMINWEL + + + + +#define ANGLE 0.01 //When output of this variable becomes negative, we have a wrong analytical graident. + //.005 works for identified VARs and OLS. + //.005 implies 89.71 degrees (acrcos(ANGLE)*180/pi). + //.01 implies 89.43 degrees (acrcos(ANGLE)*180/pi). + //.05 implies 87.13 degrees (acrcos(ANGLE)*180/pi). + //.1 implies 84.26 degrees (acrcos(ANGLE)*180/pi). +#define THETA .4 //(0<THETA<.5) THETA near .5 makes long line searches, possibly fewer iterations. + //.1 works for OLS or other nonlinear functions. + //.3 works for identified VARs. +#define FCHANGE 1000 +#define MINLAMB 1e-9 +#define MINDFAC .01 +static void csminit(double *fhat, double *xhat, int *fcount, int *retcode, + double *x0, double f0, double *g, int badg, double *H0, int n, + double (*fcn)(double *x, int n, double **args, int *dims), + double **args, int *dims) { + double lambda=1, gnorm=0, dxnorm=0, factor=3, lambdaPeak=0; + double f, dfhat, a, tmp, fPeak=f0, lambdaMax=DBL_MAX; + double *dx, *dxtest; + int done=0, shrink=1, shrinkSignal, growSignal; + int i; + + memcpy(xhat, x0, n*sizeof(double)); //Iskander's original code does not have this line, which is a major bug. Corrected by TZ. + *fhat = f0; + *fcount = 0; + *retcode = 0; + gnorm = sqrt(times(g,g,n)); + if ((gnorm < 1.e-12) && !badg) + *retcode = 1; /* gradient convergence */ + else { + /* with badg 1, we don't try to match rate of improvement to directional + derivative. We're satisfied just to get some improvement in f. */ + dx = tzMalloc(n, double); //dx = calloc(n, sizeof(double)); Commented out by TZ. + //if (!dx) printf("Dynamic memory allocation error.\n"); Commnted out by TZ. + for (i=0; i<n; i++) + dx[i] = -times(&H0[i*n],g,n); + dxnorm = sqrt(times(dx,dx,n)); + if (dxnorm > 1e12) { + #ifdef VERBOSE_WARNINGS + printf("Near-singular H problem.\n"); + #endif + + for (i=0; i<n; i++) + dx[i] *= FCHANGE/dxnorm; + } + dfhat = times(dx,g,n); + if (!badg) { + /* If the gradient is good, test for alignment of dx with gradient and fix if necessary */ + + if ((a=-dfhat/(gnorm*dxnorm))<ANGLE) { + tmp = (ANGLE*dxnorm+dfhat/gnorm)/gnorm; + for (i=0; i<n; i++) + dx[i] -= tmp*g[i]; + dfhat = times(dx,g,n); + dxnorm = sqrt(times(dx,dx,n)); + + #ifdef VERBOSE_DETOUTPUT + printf("Correct for low angle: %g\n",a); + #endif + } + } + + #ifdef VERBOSE_DETOUTPUT + printf("Predicted improvement: %18.9f, Norm of gradient: %18.9f\n", -dfhat*0.5, gnorm); + #endif + + dxtest = tzMalloc(n, double); //calloc(n, sizeof(double)); Commented out by TZ. + while (!done) { + for (i=0; i<n; i++) + dxtest[i] = x0[i]+dx[i]*lambda; + f = fcn(dxtest,n,args,dims); + + #ifdef VERBOSE_DETOUTPUT + printf("lambda = %10.5g; f = %20.7e\n",lambda,f); + #endif + + if (f<*fhat) { + *fhat = f; + memcpy(xhat,dxtest,n*sizeof(double)); + } + (*fcount)++; + tmp = -THETA*dfhat*lambda; + + /* the optimal lambda should be such that f0-f > -THETA*dfhat*lambda (see Berndt et al.) + If that's not the case and grad is good, OR + if grad is bad and f is not going down, shrinkSignal = 1 */ + shrinkSignal = ( !badg && (f0-f <= (tmp>0?tmp:0)) ) || + ( badg && (f0-f < 0 ) ); + + /* the optimal lambda should also be such that f0-f<-(1-THETA)*dfhat*lambda + If that's not the case with lambda>0, AND grad is good, growthSignal = 1 */ + growSignal = !badg && ( (lambda > 0) && (f0-f >= -(1-THETA)*dfhat*lambda) ); + + /* If shrinkSignal=1 AND ( lambda>lambdaPeak or lambda negative ) + (note when lambdaPeak=0 the second part only excludes lambda=0) + try shrinking lambda */ + if ( shrinkSignal && ( (lambda>lambdaPeak) || (lambda<0) ) ) { + /* if shrink=0 OR lambda/factor is already smaller than lambdaPeak, increase factor */ + if ( (lambda>0) && ((!shrink) || (lambda/factor <= lambdaPeak)) ) { + shrink = 1; + factor = pow(factor,.6); + while (lambda/factor <= lambdaPeak) + factor = pow(factor,.6); + if (fabs(factor-1)<MINDFAC) { + if (fabs(lambda) < 4) + *retcode = 2; + else + *retcode = 7; + done = 1; + } + } + if ((lambda<lambdaMax) && (lambda>lambdaPeak)) + lambdaMax=lambda; + /* shrink lambda */ + lambda /= factor; + /* if lambda has already been shrunk as much as possible */ + if (fabs(lambda) < MINLAMB) + /* if lambda is positive AND you have not made any improvement + try going against gradient, which may be inaccurate */ + if ((lambda > 0) && (f0 <= *fhat)) + lambda = -lambda*pow(factor,6); + else { + /* if lambda is negative: let it be known and quit trying */ + if (lambda < 0) + *retcode = 6; + /* if you have not made any imporvement: + let it be known and quit trying */ + else + *retcode = 3; + done = 1; + } + } + /* If growSignal=1 and lambda positive OR ( lambda>lambdaPeak or lambda negative ) + (note when lambdaPeak=0 the second part only excludes lambda=0) + try increase lambda */ + else + if ( (growSignal && (lambda > 0) ) || + ( shrinkSignal && (lambda <= lambdaPeak) && (lambda > 0) ) ) { + if (shrink) { + shrink = 0; + factor = pow(factor,.6); + if (fabs(factor-1) < MINDFAC) { + if (fabs(lambda) < 4) + *retcode = 4; + else + *retcode = 7; + done = 1; + } + } + if ( (f<fPeak) && (lambda>0) ) { + fPeak = f; + lambdaPeak = lambda; + if (lambdaMax <= lambdaPeak) + lambdaMax = lambdaPeak*factor*factor; + } + /* increase lambda (up to 1e20) */ + lambda *= factor; + /* if lambda has been increased up to the limit and + you have not made any imporvement: + let it be known and quit trying */ + if (fabs(lambda) > 1e20) { + *retcode = 5; + done = 1; + } + } + /* If growthSignal=shrinkSignal=0 you found a good lambda, you are done */ + else { + done = 1; + *retcode = factor<1.2 ? 7 : 0; + } + } + tzDestroy(dxtest); + tzDestroy(dx); + } + #ifdef VERBOSE_DETOUTPUT + printf("Norm of dx %10.5g\n", dxnorm); + #endif +} +#undef ANGLE +#undef THETA +#undef FCHANGE +#undef MINLAMB +#undef MINDFAC + + +static double times(double *x, double *y, int n) { + double z = 0; + int i; + for (i=0; i<n; i++, x++, y++) + z += (*x)*(*y); + return z; +} + +static int peakwall(double *g, int retcode, double *x, int n, + int (*gfcn)(double *x, int n, double *g, double **args, int *dims), + double (*fcn)(double *x, int n, double **args, int *dims), + double **args, int *dims) { + /* if retcode=2 or 4 you have shrunk or increased lambda as much as you could: + exhausted search possibilities the csminit step has failed */ + if (retcode==2 || retcode==4) + return 1; + else + /* if you are not at the peak but the csminit has improved, + compute the gradient again to update H0 */ + if (gfcn) + return gfcn(x,n,g,args,dims); + else + return numgrad(g,x,n,fcn,args,dims); +} + +static void bfgsi(double *H, double *dg, double *dx, int n, int nn) { + double *Hdg, *dxdx, *dxHdg, *Hdgdx; + double dgdx, m; + int i; + TSdmatrix *H_dm = NULL; + + Hdg = tzMalloc(n, double); //calloc(n, sizeof(double)); Commented out by TZ. + //if (!Hdg) printf("Dynamic memory allocation error.\n"); Commented out by TZ. + + /* Hdg = H0*dg; */ + for (i=0; i<n; i++) + Hdg[i] = times(&H[i*n],dg,n); + /* dgdx = dg'*dx; */ + dgdx = 1/times(dg,dx,n); + if (fabs(dgdx)<1e12) { + dxdx = mtimes(dx,dx,n,nn); + dxHdg = mtimes(dx,Hdg,n,nn); + Hdgdx = mtimes(Hdg,dx,n,nn); + m = 1+times(dg,Hdg,n)*dgdx; + for (i=0; i<nn; i++, H++, dxdx++, dxHdg++, Hdgdx++) + *H += (m*(*dxdx)-(*dxHdg)-(*Hdgdx))*dgdx; + free(Hdgdx-nn); + Hdgdx=NULL; //DDDDDebugging. + free(dxHdg-nn); + dxHdg = NULL; + free(dxdx-nn); + dxdx = NULL; + } + else { + //=== Restarting the inverse of Hessian at its initial value. Added by TZ. + H_dm = tzMalloc(1, TSdmatrix); //H_dm wil point to the same location as H. + H_dm->M = H; + H_dm->nrows = H_dm->ncols = n; + InitializeDiagonalMatrix_lf(H_dm, GLB_sclForHess); + //H_dm->flag = M_GE | M_SU | M_SL; //Hessian is symmetric. + tzDestroy(H_dm); + + #ifdef VERBOSE_WARNINGS + printf("BFGS update failed.\n"); + printf("|dg| = %f |dx| = %f\n",sqrt(times(dg,dg,n)),sqrt(times(dx,dx,n))); + printf("dg\'*dx = %f\n",dgdx); + printf("|H*dg| = %f\n",sqrt(times(Hdg,Hdg,n))); + #endif + } + tzDestroy(Hdg); +} + +static double *mtimes(double *x, double *y, int n, int nn) { + double *x0; + double *z; + int i, j; + z = tzMalloc(nn, double); //calloc(nn, sizeof(double)); Commented out by TZ. + for (i=0, x0=x; i<n; i++, y++) + for (j=0, x=x0; j<n; j++, x++, z++) + *z = (*x)*(*y); + return z-nn; +} + +static double *mminus(double *x, double *y, int n) { + double *z; + int i; + z = tzMalloc(n, double); //calloc(n, sizeof(double)); Commented out by TZ. + for (i=0; i<n; i++, x++, y++, z++) + *z = (*x)-(*y); + return z-n; +} + + +//=== The following two extern functions to be accessed by other C files. +void csminwel_SetPrintFile(char *filename) { + if (!filename) sprintf(filename_sp2vecs, "outdata5csminwel.prn"); //Default filename. + else if (STRLEN-1 < strlen(filename)) fn_DisplayError(".../csminwel.c: the allocated length STRLEN for filename_sp2vecs is too short. Must increase the string length"); + else strcpy(filename_sp2vecs, filename); +} +int csminwel_randomseedChanged(int seednumber) +{ + int oldseednumber = RANDOMSEED_CSMINWEL; + RANDOMSEED_CSMINWEL = seednumber; + return (oldseednumber); +} + + + +#undef STRLEN + + + diff --git a/CFiles/csminwel.h b/CFiles/csminwel.h new file mode 100755 index 0000000..84915ad --- /dev/null +++ b/CFiles/csminwel.h @@ -0,0 +1,23 @@ +#ifndef __CSMINWEL_H__ +#define __CSMINWEL_H__ + +#include "tzmatlab.h" + +#include <string.h> +#include <float.h> + +//--- This extern variable allows an input by the user from an input data file. +extern double GRADSTPS_CSMINWEL; + +void csminwel(double (*fcn)(double *x, int n, double **args, int *dims), + double *x, int n, double *H, double *gh, + int (*grad)(double *x, int n, double *g, double **args, int *dims), + double *fh, double crit, int *itct, int nit, + int *fcount, int *retcodeh, double **args, int *dims); +// Alternative but less clear way: ... (double (*fcn)(double *, int, double **, int *), ... + +void csminwel_SetPrintFile(char *filename); +int csminwel_randomseedChanged(int seednumber); + + +#endif diff --git a/CFiles/csminwelOrigWorks.c b/CFiles/csminwelOrigWorks.c new file mode 100755 index 0000000..fc118aa --- /dev/null +++ b/CFiles/csminwelOrigWorks.c @@ -0,0 +1,706 @@ +/*========================================================= + * csminwel.c + * + * Unconstrained minimization. Uses a quasi-Newton method with BFGS update of + * the estimated inverse hessian. It is robust against certain pathologies + * common on likelihood functions. It attempts to be robust against "cliffs", + * i.e. hyperplane discontinuities, though it is not really clear whether what + * it does in such cases succeeds reliably. + * + * function [fhat,xhat,ghat,Hhat,itct,fcount,retcodehat] = csminwelmex(fcn,x0,H0,grad,crit,nit,varargin) + * fcn: string naming the objective function to be minimized + * x0: initial value of the parameter vector + * H0: initial value for the inverse Hessian. Must be positive definite. + * grad: Either a string naming a function that calculates the gradient, or the null matrix. + * If it's null, the program calculates a numerical gradient. In this case fcn must + * be written so that it can take a matrix argument and produce a row vector of values. + * crit: Convergence criterion. Iteration will cease when it proves impossible to improve the + * function value by more than crit. + * nit: Maximum number of iterations. + * varargin: A list of optional length of additional parameters that get handed off to fcn each + * time it is called. + * Note that if the program ends abnormally, it is possible to retrieve the current x, + * f, and H from the files g1.mat and H.mat that are written at each iteration and at each + * hessian update, respectively. (When the routine hits certain kinds of difficulty, it + * write g2.mat and g3.mat as well. If all were written at about the same time, any of them + * may be a decent starting point. One can also start from the one with best function value.) + * + * Note: to set the level of display output, change preprocessor definitions in csminwel.h + * to display all output, uncomment both VERBOSE_WARNINGS and VERBOSE_DETOUTPUT + * to display only warnings without output, uncomment VERBOSE_WARNINGS + * to display no ouput, comment both VERBOSE_DETOUTPUT and VERBOSE_WARNINGS + * + * MATLAB algorithm by Christopher Sims + * C implementation by Iskander Karibzhanov + * Modified by Dan Waggoner and Tao Zha + * + * Copyright(c) 1996 Christopher Sims + * Copyright(c) 2003 Karibzhanov, Waggoner, and Zha + *======================================================= + * Revision history: + * + * 10/3/2002 - 1. corrected problem with memory corruption in C-MEX-file (csminwelmex.c) + * (needed to switch fcnRhs[0] back to x[0] before destroying it. + * If we don't do this, we will later clear previously destroyed array + * (one of x[1], x[2] or x[3]) which causes memory fault. + * The reason why fcnRhs[0] pointed to array other than x[0] is + * because we use mxSetPr in feval and gfeval. + * This was not a problem in C-file (csminwel.c). + * + * 10/11/2002 - 1. changed csminit function to avoid using fPeak without first initializing it + * 2. added two switches in csminit function to assign retcode to 7 for lambda>=4 + * 3. added one more verbose level to display only warnings or all output * + *=======================================================*/ + +#include "csminwel.h" +#define STRLEN 192 +static int numgrad(double *g, double *x, int n, + double (*fcn)(double *x, int n, double **args, int *dims), + double **args, int *dims); +static void csminit(double *fhat, double *xhat, int *fcount, int *retcode, + double *x0, double f0, double *g, int badg, double *H0, int n, + double (*fcn)(double *x, int n, double **args, int *dims), + double **args, int *dims); +static void bfgsi(double *H, double *dg, double *dx, int n, int nn); +static int peakwall(double *g, int retcode, double *x, int n, + int (*gfcn)(double *x, int n, double *g, double **args, int *dims), + double (*fcn)(double *x, int n, double **args, int *dims), + double **args, int *dims); +static double times(double *x, double *y, int n); +static double *mtimes(double *x, double *y, int n, int nn); +static double *mminus(double *x, double *y, int n); + + +static FILE *fptr_interesults = (FILE *)NULL; //Printing intermediate results to a file. +static char filename_sp2vecs[STRLEN]; //Two vectors. 1st row: numerical gradient; 2nd row: vectorized parameters. + + +void csminwel(double (*fcn)(double *x, int n, double **args, int *dims), + double *xh, int n, double *H, double *gh, + int (*gfcn)(double *x, int n, double *g, double **args, + int *dims), double *fh, double crit, int *itct, int nit, + int *fcount, int *retcodeh, double **args, int *dims) { + + int done=0, badg[4], badgh, nogh=1, stuck=0; + double *x[4], *g[4], f[4], *dg, *dx; + int retcode[3], fc=0, ih, nn, i; + #ifdef VERBOSE_DETOUTPUT + time_t begtime, currentime; + #endif + + + nn = n*n; /* n: dimension size of x or xh */ + *itct = -1; /* itct: number of actual iterations */ + *fcount = -1; /* fcount: number of evaluations of the function */ + + for (i=0; i<4; i++) + x[i] = tzMalloc(n, double); //x[i] = calloc(n, sizeof(double)); Commented out by TZ. + memcpy(x[0],xh,n*sizeof(double)); + + for (i=0; i<4; i++) + g[i] = tzMalloc(n, double); //calloc(n, sizeof(double)); Commented out by TZ. + + f[0] = fcn(x[0],n,args,dims); + + if (f[0] > 1.0e+50) { + printf("Bad initial parameter.\n"); + return; + } + + if (gfcn) + /* if grad is a string, compute it */ + badg[0] = gfcn(x[0],n,g[0],args,dims); + else + /* if grad is not string, compute it */ + badg[0] = numgrad(g[0],x[0],n,fcn,args,dims); + retcode[2] = 101; + /* iterate until done is false */ + while (!done) { + #ifdef VERBOSE_DETOUTPUT + time(&begtime); + #endif + + for (i=0; i<n; i++) + g[1][i] = g[2][i] = g[3][i] = 0; + +// #ifdef VERBOSE_DETOUTPUT +// printf("-----------------\n-----------------\n"); +// printf("f at the beginning of new iteration, %.10f\nx = ",f[0]); +// for (i=0; i<n; i++) { +// printf("%15.8g ",x[0][i]); +// if (i%4==3) printf("\n"); +// } +// if (i%4>0) printf("\n"); +// #endif + + (*itct)++; + csminit(&f[1],x[1],&fc,&retcode[0],x[0],f[0],g[0],badg[0],H,n,fcn,args,dims); + *fcount += fc; + /* if retcode1=1 gradient is zero and you are at the peak */ + if (retcode[0]!=1) { + badg[1] = peakwall(g[1],retcode[0],x[1],n,gfcn,fcn,args,dims); + /* Bad gradient or back and forth on step length. + Possibly at cliff edge. Try perturbing search direction. */ + if (badg[1]) { + double *Hcliff = tzMalloc(nn, double); //calloc(nn,sizeof(double)); Commented out by TZ. + double randmax=1/RAND_MAX; + /* if stuck, give it another try by perturbing Hessian */ + memcpy(Hcliff,H,nn*sizeof(double)); + for (i=0; i<nn; i+=n+1) + Hcliff[i] *= 1+rand()*randmax; + + #ifdef VERBOSE_WARNINGS + printf("Cliff. Perturbing search direction.\n"); + #endif + + csminit(&f[2],x[2],&fc,&retcode[1],x[0],f[0],g[0],badg[0],Hcliff,n,fcn,args,dims); + *fcount += fc; + if (f[2] < f[0]) { + badg[2] = peakwall(g[2],retcode[1],x[2],n,gfcn,fcn,args,dims); + if (badg[2]) { + double *xx = tzMalloc(n, double), nx; //calloc(n,sizeof(double)), nx; Commented out by TZ. + + #ifdef VERBOSE_WARNINGS + printf("Cliff again. Try traversing.\n"); + #endif + + for (i=0; i<n; i++) + xx[i] = x[2][i]-x[1][i]; + nx = times(xx,xx,n); + if (sqrt(nx) < 1e-13) { + f[3] = f[0]; + memcpy(x[3],x[0],n*sizeof(double)); + badg[3] = 1; + retcode[2] = 101; + } else { + double *gcliff = tzMalloc(n, double), //calloc(n,sizeof(double)), Commented out by TZ. + *eye = tzMalloc(n, double); //calloc(n,sizeof(double)); Commented out by TZ. + double dfnx = (f[2]-f[1])/nx; + for (i=0; i<n; i++) { + gcliff[i] = dfnx*xx[i]; + eye[i*(n+1)] = 1; + } + csminit(&f[3],x[3],&fc,&retcode[2],x[0],f[0],gcliff,0,eye,n,fcn,args,dims); + *fcount += fc; + badg[3] = peakwall(g[3],retcode[2],x[3],n,gfcn,fcn,args,dims); + free(eye); + free(gcliff); + } + free(xx); + } else { + f[3] = f[0]; + memcpy(x[3],x[0],n*sizeof(double)); + badg[3] = 1; + retcode[2] = 101; + } + } else { + f[3] = f[0]; + memcpy(x[3],x[0],n*sizeof(double)); + badg[3] = 1; + retcode[2] = 101; + } + free(Hcliff); + } else { + /* normal iteration, no walls, or else we're finished here. */ + f[2] = f[0]; + f[3] = f[0]; + badg[2] = 1; + badg[3] = 1; + retcode[1] = 101; + retcode[2] = 101; + } + } + + + /* how to pick gh and xh */ + if (f[3]<f[0] && badg[3]==0) { + /* if 3 (transversing) was needed, it improved and gradient is good, take that */ + ih = 3; + *fh = f[3]; + memcpy(xh,x[3],n*sizeof(double)); + memcpy(gh,g[3],n*sizeof(double)); + badgh = badg[3]; + *retcodeh = retcode[2]; + } + else if (f[2]<f[0] && badg[2]==0) { + /* if 2 (perturbig) was needed, it improved and gradient is good, take that */ + ih = 2; + *fh = f[2]; + memcpy(xh,x[2],n*sizeof(double)); + memcpy(gh,g[2],n*sizeof(double)); + badgh = badg[2]; + *retcodeh = retcode[1]; + } + else if (f[1]<f[0] && badg[1]==0) { + /* if first try went fine, take that */ + ih = 1; + *fh = f[1]; + memcpy(xh,x[1],n*sizeof(double)); + memcpy(gh,g[1],n*sizeof(double)); + badgh = badg[1]; + *retcodeh = retcode[0]; + } + else { + /* if nothing worked, just take the min of your attempts and compute the gradient */ + if (f[1] <= f[2]) + if (f[1] <= f[3]) ih = 1; + else ih = 3; + else if (f[2] <= f[3]) ih = 2; + else ih = 3; + *fh = f[i]; + memcpy(xh,x[ih],n*sizeof(double)); + *retcodeh = retcode[ih-1]; + if (nogh) { + nogh = 0; + if (gfcn) + badgh = gfcn(xh,n,gh,args,dims); + else + badgh = numgrad(gh,xh,n,fcn,args,dims); + } + badgh = 1; + } + /* end of picking */ + stuck = fabs(*fh-f[0]) < crit; + /* if nothing REALLY worked, too bad, you're stuck */ + if (!badg[0] && !badgh && !stuck) { + /* if you are not stuck, update H0 matrix */ + dg = mminus(gh,g[0],n); + dx = mminus(xh,x[0],n); + bfgsi(H,dg,dx,n,nn); + free(dx); + free(dg); + } + + #ifdef VERBOSE_DETOUTPUT + //=== Prints out intermediate results. + printf("========================================\n"); + printf(" (1) New value of the obj. func. on iteration %d: %.9f\n (2) Old value: %.9f\n (3) Downhill improvement: %.9f\n", + (int)*itct, *fh, f[0], f[0]-(*fh)); + + time(¤time); + //=== Times the iterative progress. + printf(" (4) Seconds to complete one iteration: %0.4f\n (5) Current time of day: %s\n\n", difftime(currentime, begtime), ctime(¤time)); + fflush(stdout); // Flush the buffer to get out this message without delay. + #endif + + //--------- Prints outputs to a file. --------- + if ( !(fptr_interesults = fopen(filename_sp2vecs,"w")) ) { + printf("\n\nUnable to create the starting point data file %s in csminwel.c!\n", filename_sp2vecs); + getchar(); + exit(EXIT_FAILURE); + } + fprintf(fptr_interesults, "--------Numerical gradient---------\n"); + for (i=0; i<n; i++) fprintf(fptr_interesults, " %0.16e ", gh[i]); + fprintf(fptr_interesults, "\n"); + fprintf(fptr_interesults, "--------Restarting point---------\n"); + for (i=0; i<n; i++) fprintf(fptr_interesults, " %0.16e ", xh[i]); + fprintf(fptr_interesults, "\n\n"); + tzFclose(fptr_interesults); + + if ((int)*itct > nit) { + #ifdef VERBOSE_WARNINGS + printf("\nWarning: termination as the maximum number of iterations is reached.\n"); + #endif + done = 1; + } + else if (stuck) { + #ifdef VERBOSE_DETOUTPUT + printf("improvement < crit termination\n"); + #endif + + done = 1; + } + + #ifdef VERBOSE_WARNINGS + switch ((int)*retcodeh) { + case 1: + printf("\nWarning: Zero gradient.\n"); break; + case 2: + printf("\nWarning: Back adjustment of stepsize didn't finish.\n"); break; + case 3: + printf("\nWarning: Smallest stepsize still improving too slow.\n"); break; + case 4: + printf("\nWarning: Forth adjustment of stepsize didn't finish.\n"); break; + case 6: + printf("\nWarning: Smallest step still improving too slow, reversed gradient.\n"); break; + case 5: + printf("\nWarning: Largest stepsize still improving too fast.\n"); break; + case 7: + printf("\nWarning: Possible inaccuracy in Hessian matrix.\n"); break; + } + #endif + + f[0] = *fh; + memcpy(x[0],xh,n*sizeof(double)); + memcpy(g[0],gh,n*sizeof(double)); + badg[0] = badgh; + } + for (i=0; i<4; i++) { + free(g[i]); + free(x[i]); + } +} + +/**/ +#define SCALE 1.0 +static int numgrad(double *g, double *x, int n, + double (*fcn)(double *x, int n, double **args, int *dims), + double **args, int *dims) { + //Forward difference gradient method. + double delta, deltai; + double f0, g0, ff, tmp, *xp; + int i; + int badg; + f0 = fcn(x,n,args,dims); + badg = 0; + for (i=0, xp=x; i<n; i++, xp++, g++) { + delta=SCALE*1.0e-5, deltai=1.0e+5/SCALE; + + tmp = *xp; + *xp += delta; + delta = *xp - tmp; // This increases the precision slightly. Added by TZ. + if ( (ff=fcn(x,n,args,dims)) < NEARINFINITY ) g0 = (ff-f0)*deltai; //Not over the boundary. + else { + //Switches to the other side of the boundary. + *xp = tmp - delta; + g0 = (f0-fcn(x,n,args,dims))*deltai; + } + + *xp = tmp; //Puts back to the original place. TZ, 9/03. + if (fabs(g0)<1.0e+15) + *g = g0; + else { + #ifdef VERBOSE_WARNINGS + printf("Bad gradient.\n"); + #endif + + *g = 0; + badg = 1; + } + } + return badg; +} +#undef SCALE + +/** +#define STPS 1.0e-04 // 6.0554544523933391e-6 step size = pow(DBL_EPSILON,1.0/3) +static int numgrad(double *g, double *x, int n, + double (*fcn)(double *x, int n, double **args, int *dims), + double **args, int *dims) { + //Central difference gradient method. Added by TZ. + double dh; + double f0, fp, fm, tmp, *xp; + int i; + int badg; + + badg = 0; + for (i=0, xp=x; i<n; i++, xp++, g++) { + dh = fabs(*xp)<=1 ? STPS : STPS*(*xp); + + tmp = *xp; + *xp += dh; + dh = *xp - tmp; // This increases the precision slightly. + fp = fcn(x,n,args,dims); + *xp = tmp - dh; + fm = fcn(x,n,args,dims); + + //=== Checking the boundary condition for the minimization problem. + if (fp >= NEARINFINITY) { + *xp = tmp; //Puts back to the original place. TZ, 9/03. + f0 = fcn(x,n,args,dims); + *g = (f0-fm)/dh; + } + else if (fm >= NEARINFINITY) { + //Switches to the other side of the boundary. + *xp = tmp; //Puts back to the original place. TZ, 9/03. + f0 = fcn(x,n,args,dims); + *g = (fp-f0)/dh; + } + else { + *g = (fp-fm)/(2.0*dh); + *xp = tmp; //Puts back to the original place. TZ, 9/03. + } + + if (fabs(*g)>1.0e+15) { + #ifdef VERBOSE_WARNINGS + printf("Bad gradient.\n"); + #endif + *g = 0.0; + badg = 1; + } + } + return badg; +} +#undef STPS +/**/ + + +#define ANGLE 0.05 //When output of this variable becomes negative, we have a wrong analytical graident. + //.005 works for identified VARs and OLS. +#define THETA .4 //(0<THETA<.5) THETA near .5 makes long line searches, possibly fewer iterations. + //.1 works for OLS or other nonlinear functions. + //.3 works for identified VARs. +#define FCHANGE 1000 +#define MINLAMB 1e-9 +#define MINDFAC .01 +static void csminit(double *fhat, double *xhat, int *fcount, int *retcode, + double *x0, double f0, double *g, int badg, double *H0, int n, + double (*fcn)(double *x, int n, double **args, int *dims), + double **args, int *dims) { + double lambda=1, gnorm=0, dxnorm=0, factor=3, lambdaPeak=0; + double f, dfhat, a, tmp, fPeak=f0, lambdaMax=DBL_MAX; + double *dx, *dxtest; + int done=0, shrink=1, shrinkSignal, growSignal; + int i; + + *fhat = f0; + *fcount = 0; + *retcode = 0; + gnorm = sqrt(times(g,g,n)); + if ((gnorm < 1.e-12) && !badg) + *retcode = 1; /* gradient convergence */ + else { + /* with badg 1, we don't try to match rate of improvement to directional + derivative. We're satisfied just to get some improvement in f. */ + dx = tzMalloc(n, double); //dx = calloc(n, sizeof(double)); Commented out by TZ. + //if (!dx) printf("Dynamic memory allocation error.\n"); Commnted out by TZ. + for (i=0; i<n; i++) + dx[i] = -times(&H0[i*n],g,n); + dxnorm = sqrt(times(dx,dx,n)); + if (dxnorm > 1e12) { + #ifdef VERBOSE_WARNINGS + printf("Near-singular H problem.\n"); + #endif + + for (i=0; i<n; i++) + dx[i] *= FCHANGE/dxnorm; + } + dfhat = times(dx,g,n); + if (!badg) { + /* test for alignment of dx with gradient and fix if necessary */ + a = -dfhat/(gnorm*dxnorm); + if (a<ANGLE) { + tmp = (ANGLE*dxnorm+dfhat/gnorm)/gnorm; + for (i=0; i<n; i++) + dx[i] -= tmp*g[i]; + dfhat = times(dx,g,n); + dxnorm = sqrt(times(dx,dx,n)); + + #ifdef VERBOSE_DETOUTPUT + printf("Correct for low angle: %g\n",a); + #endif + } + } + + #ifdef VERBOSE_DETOUTPUT + printf("Predicted improvement: %18.9f, Norm of gradient: %18.9f\n",-dfhat/2,gnorm); + #endif + + dxtest = tzMalloc(n, double); //calloc(n, sizeof(double)); Commented out by TZ. + while (!done) { + for (i=0; i<n; i++) + dxtest[i] = x0[i]+dx[i]*lambda; + f = fcn(dxtest,n,args,dims); + + #ifdef VERBOSE_DETOUTPUT + printf("lambda = %10.5g; f = %20.7f\n",lambda,f); + #endif + + if (f<*fhat) { + *fhat = f; + memcpy(xhat,dxtest,n*sizeof(double)); + } + (*fcount)++; + tmp = -THETA*dfhat*lambda; + + /* the optimal lambda should be such that f0-f > -THETA*dfhat*lambda (see Berndt et al.) + If that's not the case and grad is good, OR + if grad is bad and f is not going down, shrinkSignal = 1 */ + shrinkSignal = ( !badg && (f0-f <= (tmp>0?tmp:0)) ) || + ( badg && (f0-f < 0 ) ); + + /* the optimal lambda should also be such that f0-f<-(1-THETA)*dfhat*lambda + If that's not the case with lambda>0, AND grad is good, growthSignal = 1 */ + growSignal = !badg && ( (lambda > 0) && (f0-f >= -(1-THETA)*dfhat*lambda) ); + + /* If shrinkSignal=1 AND ( lambda>lambdaPeak or lambda negative ) + (note when lambdaPeak=0 the second part only excludes lambda=0) + try shrinking lambda */ + if ( shrinkSignal && ( (lambda>lambdaPeak) || (lambda<0) ) ) { + /* if shrink=0 OR lambda/factor is already smaller than lambdaPeak, increase factor */ + if ( (lambda>0) && ((!shrink) || (lambda/factor <= lambdaPeak)) ) { + shrink = 1; + factor = pow(factor,.6); + while (lambda/factor <= lambdaPeak) + factor = pow(factor,.6); + if (fabs(factor-1)<MINDFAC) { + if (fabs(lambda) < 4) + *retcode = 2; + else + *retcode = 7; + done = 1; + } + } + if ((lambda<lambdaMax) && (lambda>lambdaPeak)) + lambdaMax=lambda; + /* shrink lambda */ + lambda /= factor; + /* if lambda has already been shrunk as much as possible */ + if (fabs(lambda) < MINLAMB) + /* if lambda is positive AND you have not made any improvement + try going against gradient, which may be inaccurate */ + if ((lambda > 0) && (f0 <= *fhat)) + lambda = -lambda*pow(factor,6); + else { + /* if lambda is negative: let it be known and quit trying */ + if (lambda < 0) + *retcode = 6; + /* if you have not made any imporvement: + let it be known and quit trying */ + else + *retcode = 3; + done = 1; + } + } + /* If growSignal=1 and lambda positive OR ( lambda>lambdaPeak or lambda negative ) + (note when lambdaPeak=0 the second part only excludes lambda=0) + try increase lambda */ + else + if ( (growSignal && (lambda > 0) ) || + ( shrinkSignal && (lambda <= lambdaPeak) && (lambda > 0) ) ) { + if (shrink) { + shrink = 0; + factor = pow(factor,.6); + if (fabs(factor-1) < MINDFAC) { + if (fabs(lambda) < 4) + *retcode = 4; + else + *retcode = 7; + done = 1; + } + } + if ( (f<fPeak) && (lambda>0) ) { + fPeak = f; + lambdaPeak = lambda; + if (lambdaMax <= lambdaPeak) + lambdaMax = lambdaPeak*factor*factor; + } + /* increase lambda (up to 1e20) */ + lambda *= factor; + /* if lambda has been increased up to the limit and + you have not made any imporvement: + let it be known and quit trying */ + if (fabs(lambda) > 1e20) { + *retcode = 5; + done = 1; + } + } + /* If growthSignal=shrinkSignal=0 you found a good lambda, you are done */ + else { + done = 1; + *retcode = factor<1.2 ? 7 : 0; + } + } + free(dxtest); + free(dx); + } + #ifdef VERBOSE_DETOUTPUT + printf("Norm of dx %10.5g\n", dxnorm); + #endif +} +#undef ANGLE +#undef THETA +#undef FCHANGE +#undef MINLAMB +#undef MINDFAC + + +static double times(double *x, double *y, int n) { + double z = 0; + int i; + for (i=0; i<n; i++, x++, y++) + z += (*x)*(*y); + return z; +} + +static int peakwall(double *g, int retcode, double *x, int n, + int (*gfcn)(double *x, int n, double *g, double **args, int *dims), + double (*fcn)(double *x, int n, double **args, int *dims), + double **args, int *dims) { + /* if retcode=2 or 4 you have shrunk or increased lambda as much as you could: + exhausted search possibilities the csminit step has failed */ + if (retcode==2 || retcode==4) + return 1; + else + /* if you are not at the peak but the csminit has improved, + compute the gradient again to update H0 */ + if (gfcn) + return gfcn(x,n,g,args,dims); + else + return numgrad(g,x,n,fcn,args,dims); +} + +static void bfgsi(double *H, double *dg, double *dx, int n, int nn) { + double *Hdg, *dxdx, *dxHdg, *Hdgdx; + double dgdx, m; + int i; + + Hdg = tzMalloc(n, double); //calloc(n, sizeof(double)); Commented out by TZ. + //if (!Hdg) printf("Dynamic memory allocation error.\n"); Commented out by TZ. + + /* Hdg = H0*dg; */ + for (i=0; i<n; i++) + Hdg[i] = times(&H[i*n],dg,n); + /* dgdx = dg'*dx; */ + dgdx = 1/times(dg,dx,n); + if (fabs(dgdx)<1e12) { + dxdx = mtimes(dx,dx,n,nn); + dxHdg = mtimes(dx,Hdg,n,nn); + Hdgdx = mtimes(Hdg,dx,n,nn); + m = 1+times(dg,Hdg,n)*dgdx; + for (i=0; i<nn; i++, H++, dxdx++, dxHdg++, Hdgdx++) + *H += (m*(*dxdx)-(*dxHdg)-(*Hdgdx))*dgdx; + free(Hdgdx-nn); + free(dxHdg-nn); + free(dxdx-nn); + } + else { + #ifdef VERBOSE_WARNINGS + printf("BFGS update failed.\n"); + printf("|dg| = %f |dx| = %f\n",sqrt(times(dg,dg,n)),sqrt(times(dx,dx,n))); + printf("dg\'*dx = %f\n",dgdx); + printf("|H*dg| = %f\n",sqrt(times(Hdg,Hdg,n))); + #endif + } + free(Hdg); +} + +static double *mtimes(double *x, double *y, int n, int nn) { + double *x0; + double *z; + int i, j; + z = tzMalloc(nn, double); //calloc(nn, sizeof(double)); Commented out by TZ. + for (i=0, x0=x; i<n; i++, y++) + for (j=0, x=x0; j<n; j++, x++, z++) + *z = (*x)*(*y); + return z-nn; +} + +static double *mminus(double *x, double *y, int n) { + double *z; + int i; + z = tzMalloc(n, double); //calloc(n, sizeof(double)); Commented out by TZ. + for (i=0; i<n; i++, x++, y++, z++) + *z = (*x)-(*y); + return z-n; +} + + +//=== Extern function to be accessed by other C files. +void csminwel_SetPrintFile(char *filename) { + if (!filename) sprintf(filename_sp2vecs, "outdata5csminwel.prn"); //Default filename. + else if (STRLEN-1 < strlen(filename)) fn_DisplayError(".../csminwel.c: the allocated length STRLEN for filename_sp2vecs is too short. Must increase the string length"); + else strcpy(filename_sp2vecs, filename); +} + +#undef STRLEN diff --git a/CFiles/csminwelOrigWorks.h b/CFiles/csminwelOrigWorks.h new file mode 100755 index 0000000..bb4e8da --- /dev/null +++ b/CFiles/csminwelOrigWorks.h @@ -0,0 +1,22 @@ +#ifndef __CSMINWEL_H__ +#define __CSMINWEL_H__ + + #define VERBOSE_WARNINGS // display warnings + #define VERBOSE_DETOUTPUT // display detailed output + + #include <math.h> + #include <string.h> + #include <stdio.h> + #include <float.h> + + #include "tzmatlab.h" + + void csminwel(double (*fcn)(double *x, int n, double **args, int *dims), + double *x, int n, double *H, double *gh, + int (*grad)(double *x, int n, double *g, double **args, + int *dims), double *fh, double crit, int *itct, int nit, + int *fcount, int *retcodeh, double **args, int *dims); + // Alternative but less clear way: ... (double (*fcn)(double *, int, double **, int *), ... + + void csminwel_SetPrintFile(char *filename); +#endif diff --git a/CFiles/cstz.c b/CFiles/cstz.c new file mode 100755 index 0000000..1ac3dfc --- /dev/null +++ b/CFiles/cstz.c @@ -0,0 +1,2774 @@ +#include "cstz.h" + +#include <float.h> +#include <string.h> //For memmove, etc. +#include "mathlib.h" + + +//???????? +//------- For computing inverse Hessian only. ------- +//static struct TStateModel_tag *SetModelGlobalForCovariance(struct TStateModel_tag *smodel_ps); +//static double ObjFuncForSmodel(double *x0_p, int d_x0); +//static double opt_logOverallPosteriorKernal(struct TStateModel_tag *smodel_ps, TSdvector *xchange_dv); + +static double logCondPostKernTimet(double *xchange_p, int t, struct TStateModel_tag *smodel_ps); +static double neglogPostKern_hess(double *xchange_pd, struct TStateModel_tag *smodel_ps); +static void hesscd_smodel(TSdmatrix *H_dm, TSdvector *x_dv, struct TStateModel_tag *smodel_ps, double (*fcn)(double *x, struct TStateModel_tag *), double grdh, double f0); + +TSdp2m5 *CreateP2m5(const double p, const double bound) +{ + TSdp2m5 *x_dp2m5 = tzMalloc(1, TSdp2m5); + + if (p<=0.0 && p>=1.0) fn_DisplayError(".../cstz.c/CreateP2m5(): Input probability p must be between 0.0 and 1.0"); + if ((x_dp2m5->bound=bound)<=0.0) fn_DisplayError(".../cstz.c/CreateP2m5(): Real bound must be positive"); + + x_dp2m5->cnt = 0; + x_dp2m5->ndeg = 0; + x_dp2m5->p = tzMalloc(5, double); + x_dp2m5->q = tzMalloc(5, double); + x_dp2m5->m = tzMalloc(5, int); + + //=== 5 markers. + x_dp2m5->p[0] = 0.00; + x_dp2m5->p[1] = 0.5*p; + x_dp2m5->p[2] = p; + x_dp2m5->p[3] = 0.5*(1.0+p); + x_dp2m5->p[4] = 1.00; + //=== Now 9 markers. + // x_dp2m5->p[0] = 0.00; + // x_dp2m5->p[1] = 0.25*p + // x_dp2m5->p[2] = 0.5*p; + // x_dp2m5->p[3] = 0.75*p; + // x_dp2m5->p[4] = p; + // x_dp2m5->p[5] = 0.25 + 0.75*p; + // x_dp2m5->p[6] = 0.5*(1.0+p); + // x_dp2m5->p[7] = 0.75 + 0.25*p; + // x_dp2m5->p[8] = 1.00; + + return (x_dp2m5); +} +TSdp2m5 *DestroyP2m5(TSdp2m5 *x_dp2m5) +{ + if (x_dp2m5) { + free(x_dp2m5->m); + free(x_dp2m5->q); + free(x_dp2m5->p); + + free(x_dp2m5); + return ((TSdp2m5 *)NULL); + } + else return (x_dp2m5); +} +TSdvectorp2m5 *CreateVectorP2m5(const int n, const double p, const double bound) +{ + int _i; + // + TSdvectorp2m5 *x_dvp2m5 = tzMalloc(1, TSdvectorp2m5); + + x_dvp2m5->n = n; + x_dvp2m5->v = tzMalloc(n, TSdp2m5 *); + for (_i=n-1; _i>=0; _i--) + x_dvp2m5->v[_i] = CreateP2m5(p, bound); + + return (x_dvp2m5); +} +TSdvectorp2m5 *DestroyVectorP2m5(TSdvectorp2m5 *x_dvp2m5) +{ + int _i; + + if (x_dvp2m5) { + for (_i=x_dvp2m5->n-1; _i>=0; _i--) + x_dvp2m5->v[_i] = DestroyP2m5(x_dvp2m5->v[_i]); + free(x_dvp2m5->v); + + free(x_dvp2m5); + return ((TSdvectorp2m5 *)NULL); + } + else return (x_dvp2m5); +} +TSdmatrixp2m5 *CreateMatrixP2m5(const int nrows, const int ncols, const double p, const double bound) +{ + int _i; + // + TSdmatrixp2m5 *X_dmp2m5 = tzMalloc(1, TSdmatrixp2m5); + + X_dmp2m5->nrows = nrows; + X_dmp2m5->ncols = ncols; + X_dmp2m5->M = tzMalloc(nrows*ncols, TSdp2m5 *); + for (_i=nrows*ncols-1; _i>=0; _i--) + X_dmp2m5->M[_i] = CreateP2m5(p, bound); + + return (X_dmp2m5); +} +TSdmatrixp2m5 *DestroyMatrixP2m5(TSdmatrixp2m5 *X_dmp2m5) +{ + int _i; + + if (X_dmp2m5) { + for (_i=X_dmp2m5->nrows*X_dmp2m5->ncols-1; _i>=0; _i--) + X_dmp2m5->M[_i] = DestroyP2m5(X_dmp2m5->M[_i]); + free(X_dmp2m5->M); + + free(X_dmp2m5); + return ((TSdmatrixp2m5 *)NULL); + } + else return (X_dmp2m5); +} +TSdcellp2m5 *CreateCellP2m5(const TSivector *rows_iv, const TSivector *cols_iv, const double p, const double bound) +{ + int _i; + int ncells; + // + TSdcellp2m5 *X_dcp2m5 = tzMalloc(1, TSdcellp2m5); + + + if (!rows_iv || !cols_iv || !rows_iv->flag || !cols_iv->flag) fn_DisplayError(".../cstz.c/CreateCellP2m5(): Input row and column vectors must be (1) created and (2) assigned legal values"); + if ((ncells=rows_iv->n) != cols_iv->n) fn_DisplayError(".../cstz.c/CreateCellP2m5(): Length of rows_iv must be the same as that of cols_iv"); + + + X_dcp2m5->ncells = ncells; + X_dcp2m5->C = tzMalloc(ncells, TSdmatrixp2m5 *); + for (_i=ncells-1; _i>=0; _i--) + X_dcp2m5->C[_i] = CreateMatrixP2m5(rows_iv->v[_i], cols_iv->v[_i], p, bound); + + return (X_dcp2m5); +} +TSdcellp2m5 *DestroyCellP2m5(TSdcellp2m5 *X_dcp2m5) +{ + int _i; + + if (X_dcp2m5) { + for (_i=X_dcp2m5->ncells-1; _i>=0; _i--) + X_dcp2m5->C[_i] = DestroyMatrixP2m5(X_dcp2m5->C[_i]); + free(X_dcp2m5->C); + + free(X_dcp2m5); + return ((TSdcellp2m5 *)NULL); + } + else return (X_dcp2m5); +} +TSdfourthp2m5 *CreateFourthP2m5(const int ndims, const TSivector *rows_iv, const TSivector *cols_iv, const double p, const double bound) +{ + int _i; + // + TSdfourthp2m5 *X_d4p2m5 = tzMalloc(1, TSdfourthp2m5); + + + if (!rows_iv || !cols_iv || !rows_iv->flag || !cols_iv->flag) fn_DisplayError(".../cstz.c/CreateFourthP2m5(): Input row and column vectors must be (1) created and (2) assigned legal values"); + if (rows_iv->n != cols_iv->n) fn_DisplayError(".../cstz.c/CreateFourthP2m5(): Length of rows_iv must be the same as that of cols_iv"); + + + X_d4p2m5->ndims = ndims; + X_d4p2m5->F = tzMalloc(ndims, TSdcellp2m5 *); + for (_i=ndims-1; _i>=0; _i--) + X_d4p2m5->F[_i] = CreateCellP2m5(rows_iv, cols_iv, p, bound); + + return (X_d4p2m5); +} +TSdfourthp2m5 *DestroyFourthP2m5(TSdfourthp2m5 *X_d4p2m5) +{ + int _i; + + if (X_d4p2m5) { + for (_i=X_d4p2m5->ndims-1; _i>=0; _i--) + X_d4p2m5->F[_i] = DestroyCellP2m5(X_d4p2m5->F[_i]); + free(X_d4p2m5->F); + + free(X_d4p2m5); + return ((TSdfourthp2m5 *)NULL); + } + else return (X_d4p2m5); +} + + + +int P2m5Update(TSdp2m5 *x_dp2m5, const double newval) +{ + //5-marker P2 algorithm. + //quantiles q[0] to q[4] correspond to 5-marker probabilities {0.0, p/5, p, (1+p)/5, 1.0}. + //Outputs: + // x_dp2m5->q, the markers x_dp2m5->m, is updated and only x_dp2m5->q[2] is used. + //Inputs: + // newval: new random number. + // + // January 2003. + int k, j; + double a; + double qm, dq; + int i, dm, dn; + + + if (!x_dp2m5) fn_DisplayError(".../cstz.c/P2m5Update(): x_dp2m5 must be created"); + + //if (isgreater(newval, -P2REALBOUND) && isless(newval, P2REALBOUND)) { + if (isfinite(newval) && newval > -x_dp2m5->bound && newval < x_dp2m5->bound) { + if (++x_dp2m5->cnt > 5) { + //Updating the quantiles and markers. + for (i=0; x_dp2m5->q[i]<=newval && i<5; i++) ; + if (i==0) { x_dp2m5->q[0]=newval; i++; } + if (i==5) { x_dp2m5->q[4]=newval; i--; } + for (; i<5; i++) x_dp2m5->m[i]++; + for (i=1; i<4; i++) { + dq = x_dp2m5->p[i]*x_dp2m5->m[4]; + if (x_dp2m5->m[i]+1<=dq && (dm=x_dp2m5->m[i+1]-x_dp2m5->m[i])>1) { + dn = x_dp2m5->m[i]-x_dp2m5->m[i-1]; + dq = ((dn+1)*(qm=x_dp2m5->q[i+1]-x_dp2m5->q[i])/dm+ + (dm-1)*(x_dp2m5->q[i]-x_dp2m5->q[i-1])/dn)/(dm+dn); + if (qm<dq) dq = qm/dm; + x_dp2m5->q[i] += dq; + x_dp2m5->m[i]++; + } else + if (x_dp2m5->m[i]-1>=dq && (dm=x_dp2m5->m[i]-x_dp2m5->m[i-1])>1) { + dn = x_dp2m5->m[i+1]-x_dp2m5->m[i]; + dq = ((dn+1)*(qm=x_dp2m5->q[i]-x_dp2m5->q[i-1])/dm+ + (dm-1)*(x_dp2m5->q[i+1]-x_dp2m5->q[i])/dn)/(dm+dn); + if (qm<dq) dq = qm/dm; + x_dp2m5->q[i] -= dq; + x_dp2m5->m[i]--; + } + } + } + else if (x_dp2m5->cnt < 5) { + //Fills the initial values. + x_dp2m5->q[x_dp2m5->cnt-1] = newval; + x_dp2m5->m[x_dp2m5->cnt-1] = x_dp2m5->cnt-1; + } + else { + //=== Last filling of initial values. + x_dp2m5->q[4] = newval; + x_dp2m5->m[4] = 4; + //=== P2 algorithm begins with reshuffling quantiles and makers. + for (j=1; j<5; j++) { + a = x_dp2m5->q[j]; + for (k=j-1; k>=0 && x_dp2m5->q[k]>a; k--) + x_dp2m5->q[k+1] = x_dp2m5->q[k]; + x_dp2m5->q[k+1]=a; + } + } + } + else ++x_dp2m5->ndeg; //Throwing away the draws to treat exceptions. + + return (x_dp2m5->cnt); +} + +void P2m5VectorUpdate(TSdvectorp2m5 *x_dvp2m5, const TSdvector *newval_dv) +{ + int _i, _n; + + if (!x_dvp2m5 || !newval_dv || !newval_dv->flag) fn_DisplayError(".../cstz.c/P2m5VectorUpdate(): (1) Vector struct x_dvp2m5 must be created and (2) input new value vector must be crated and given legal values"); + if ((_n=newval_dv->n) != x_dvp2m5->n) + fn_DisplayError(".../cstz.c/P2m5VectorUpdate(): dimension of x_dvp2m5 must match that of newval_dv"); + + for (_i=_n-1; _i>=0; _i--) + P2m5Update(x_dvp2m5->v[_i], newval_dv->v[_i]); +} + +void P2m5MatrixUpdate(TSdmatrixp2m5 *X_dmp2m5, const TSdmatrix *newval_dm) +{ + int _i; + int nrows, ncols; + + if (!X_dmp2m5 || !newval_dm || !newval_dm->flag) fn_DisplayError(".../cstz.c/P2m5MatrixUpdate(): (1) Matrix struct X_dmp2m5 must be created and (2) input new value matrix must be crated and given legal values"); + if ((nrows=newval_dm->nrows) != X_dmp2m5->nrows || (ncols=newval_dm->ncols) != X_dmp2m5->ncols) + fn_DisplayError(".../cstz.c/P2m5MatrixUpdate(): Number of rows and colums in X_dmp2m5 must match those of newval_dm"); + + for (_i=nrows*ncols-1; _i>=0; _i--) + P2m5Update(X_dmp2m5->M[_i], newval_dm->M[_i]); +} + +void P2m5CellUpdate(TSdcellp2m5 *X_dcp2m5, const TSdcell *newval_dc) +{ + int _i; + int ncells; + + if (!X_dcp2m5 || !newval_dc) fn_DisplayError(".../cstz.c/P2m5CellUpdate(): (1) Cell struct X_dcp2m5 must be created and (2) input new value cell must be crated and given legal values"); + if ((ncells=newval_dc->ncells) != X_dcp2m5->ncells) + fn_DisplayError(".../cstz.c/P2m5MatrixUpdate(): Number of cells in X_dcp2m5 must match that of newval_dc"); + + for (_i=ncells-1; _i>=0; _i--) + P2m5MatrixUpdate(X_dcp2m5->C[_i], newval_dc->C[_i]); +} + +void P2m5FourthUpdate(TSdfourthp2m5 *X_d4p2m5, const TSdfourth *newval_d4) +{ + int _i; + int ndims; + + if (!X_d4p2m5 || !newval_d4) fn_DisplayError(".../cstz.c/P2m5FourthUpdate(): (1) Fourth struct X_d4p2m5 must be created and (2) input new value fourth must be crated and given legal values"); + if ((ndims=newval_d4->ndims) != X_d4p2m5->ndims) + fn_DisplayError(".../cstz.c/P2m5FourthUpdate(): Number of fourths in X_d4p2m5 must match that of newval_d4"); + + for (_i=ndims-1; _i>=0; _i--) + P2m5CellUpdate(X_d4p2m5->F[_i], newval_d4->F[_i]); +} + + + + +//--------------------------------------------------------------------- +//--------------------------------------------------------------------- +#if defined( CSMINWEL_OPTIMIZATION ) + #define STPS 6.0554544523933391e-6 /* step size = pow(DBL_EPSILON,1.0/3) */ + void fn_gradcd(double *g, double *x, int n, double grdh, + double (*fcn)(double *x, int n, double **args, int *dims), + double **args, int *dims) { + //Outputs: + // g: the gradient n-by-1 g (no need to be initialized). + //Inputs: + // grdh: step size. If ==0.0, then dh is set automatically; otherwise, grdh is taken as a step size, often set as 1.0e-004. + // x: no change in the end although will be added or substracted by dh during the function (but in the end the original value will be put back). + + double dh, fp, fm, tmp, *xp; + int i; + for (i=0, xp=x; i<n; i++, xp++, g++) { + dh = grdh?grdh:(fabs(*xp)<1?STPS:STPS*(*xp)); + tmp = *xp; + *xp += dh; + dh = *xp - tmp; // This increases the precision slightly. + fp = fcn(x,n,args,dims); + *xp = tmp - dh; + fm = fcn(x,n,args,dims); + *g = (fp-fm)/(2*dh); + *xp = tmp; // Put the original value of x[i] back to x[i] so that the content x[i] is still unaltered. + } + } + #undef STPS + + #define STPS 6.0554544523933391e-6 /* step size = pow(DBL_EPSILON,1.0/3) */ + void fn_hesscd(double *H, double *x, int n, double grdh, + double (*fcn)(double *x, int n, double **args, int *dims), + double **args, int *dims) { + double dhi, dhj, f1, f2, f3, f4, tmpi, tmpj, *xpi, *xpj; + int i, j; + for (i=0, xpi=x; i<n; i++, xpi++) { + dhi = grdh?grdh:(fabs(*xpi)<1?STPS:STPS*(*xpi)); + tmpi = *xpi; + for (j=i, xpj=x+i; j<n; j++, xpj++) + if (i==j) { + /* f2 = f3 when i = j */ + f2 = fcn(x,n,args,dims); + + /* this increases precision slightly */ + *xpi += dhi; + dhi = *xpi - tmpi; + + /* calculate f1 and f4 */ + *xpi = tmpi + 2*dhi; + f1 = fcn(x,n,args,dims); + *xpi = tmpi - 2*dhi; + f4 = fcn(x,n,args,dims); + + /* diagonal element */ + H[i*(n+1)] = (f1-2*f2+f4)/(4*dhi*dhi); + + /* reset to intial value */ + *xpi = tmpi; + } else { + dhj = grdh?grdh:(fabs(*xpj)<1?STPS:STPS*(*xpj)); + tmpj = *xpj; + + /* this increases precision slightly */ + *xpi += dhi; + dhi = *xpi - tmpi; + *xpj += dhj; + dhj = *xpj - tmpj; + + /* calculate f1, f2, f3 and f4 */ + *xpj = tmpj + dhj; + f1 = fcn(x,n,args,dims); + *xpi = tmpi - dhi; + f2 = fcn(x,n,args,dims); + *xpi = tmpi + dhi; + *xpj = tmpj - dhj; + f3 = fcn(x,n,args,dims); + *xpi = tmpi - dhi; + f4 = fcn(x,n,args,dims); + + /* symmetric elements */ + H[i+j*n] = H[j+i*n] = (f1-f2-f3+f4)/(4*dhi*dhj); + + /* reset to intial values */ + *xpi = tmpi; + *xpj = tmpj; + } + } + } + #undef STPS +#elif defined( IMSL_OPTIMIZATION ) + #define STPS 6.0554544523933391e-6 /* step size = pow(DBL_EPSILON,1.0/3) */ + void fn_gradcd(double *g, double *x, int n, double grdh, + double fcn(int n, double *x) // IMSL + //void NAG_CALL fcn(Integer n,double x[],double *f,double g[],Nag_Comm *comm) + ) { + //Outputs: + // g: the gradient n-by-1 g (no need to be initialized). + //Inputs: + // grdh: step size. If ==0.0, then dh is set automatically; otherwise, grdh is taken as a step size, often set as 1.0e-004. + // x: no change in the end although will be added or substracted by dh during the function (but in the end the original value will be put back). + + double dh, fp, fm, tmp, *xp; + int i; + for (i=0, xp=x; i<n; i++, xp++, g++) { + dh = grdh?grdh:(fabs(*xp)<1?STPS:STPS*(*xp)); + tmp = *xp; + *xp += dh; + dh = *xp - tmp; // This increases the precision slightly. + fp = fcn(n,x); // IMSL + //fcn(n,x,&fp,NULL,NULL); /* NAG */ + *xp = tmp - dh; + fm = fcn(n,x); // IMSL + //fcn(n,x,&fm,NULL,NULL); + *g = (fp-fm)/(2*dh); + *xp = tmp; // Put the original value of x[i] back to x[i] so that the content x[i] is still unaltered. + } + } + #undef STPS + + #define STPS 6.0554544523933391e-6 /* step size = pow(DBL_EPSILON,1.0/3) */ + void fn_hesscd(double *H, double *x, int n, double grdh, + double fcn(int n, double *x) // IMSL + //void NAG_CALL fcn(Integer n,double x[],double *f,double g[],Nag_Comm *comm) + ) { + double dhi, dhj, f1, f2, f3, f4, tmpi, tmpj, *xpi, *xpj; + int i, j; + for (i=0, xpi=x; i<n; i++, xpi++) { + dhi = grdh?grdh:(fabs(*xpi)<1?STPS:STPS*(*xpi)); + tmpi = *xpi; + for (j=i, xpj=x+i; j<n; j++, xpj++) + if (i==j) { + /* f2 = f3 when i = j */ + f2 = fcn(n,x); // IMSL + //fcn(n,x,&f2,NULL,NULL); + + /* this increases precision slightly */ + *xpi += dhi; + dhi = *xpi - tmpi; + + /* calculate f1 and f4 */ + *xpi = tmpi + 2*dhi; + f1 = fcn(n,x); // IMSL + //fcn(n,x,&f1,NULL,NULL); + *xpi = tmpi - 2*dhi; + f4 = fcn(n,x); /* IMSL */ + //fcn(n,x,&f4,NULL,NULL); + + /* diagonal element */ + H[i*(n+1)] = (f1-2*f2+f4)/(4*dhi*dhi); + + /* reset to intial value */ + *xpi = tmpi; + } else { + dhj = grdh?grdh:(fabs(*xpj)<1?STPS:STPS*(*xpj)); + tmpj = *xpj; + + /* this increases precision slightly */ + *xpi += dhi; + dhi = *xpi - tmpi; + *xpj += dhj; + dhj = *xpj - tmpj; + + /* calculate f1, f2, f3 and f4 */ + *xpj = tmpj + dhj; + f1 = fcn(n,x); // IMSL + //fcn(n,x,&f1,NULL,NULL); + *xpi = tmpi - dhi; + f2 = fcn(n,x); // IMSL + //fcn(n,x,&f2,NULL,NULL); + *xpi = tmpi + dhi; + *xpj = tmpj - dhj; + f3 = fcn(n,x); // IMSL + //fcn(n,x,&f3,NULL,NULL); + *xpi = tmpi - dhi; + f4 = fcn(n,x); // IMSL + //fcn(n,x,&f4,NULL,NULL); + + /* symmetric elements */ + H[i+j*n] = H[j+i*n] = (f1-f2-f3+f4)/(4*dhi*dhj); + + /* reset to intial values */ + *xpi = tmpi; + *xpj = tmpj; + } + } + } + #undef STPS +#endif + + + +//------------------------------- +//Modified from fn_gradcd() in cstz.c for the conjugate gradient method I or II +//------------------------------- +#define STPS 1.0e-04 // 6.0554544523933391e-6 step size = pow(DBL_EPSILON,1.0/3) +#define GRADMANUAL 1.0e+01 //Arbitrarily (manually) set gradient. +void gradcd_gen(double *g, double *x, int n, double (*fcn)(double *x, int n), double *grdh, double f0) { + //Outputs: + // g: the gradient n-by-1 g (no need to be initialized). + //Inputs: + // x: the vector point at which the gradient is evaluated. No change in the end although will be added or substracted by dh during the function (but in the end the original value will be put back). + // n: the dimension of g or x. + // fcn(): the function for which the gradient is evaluated + // grdh: step size. If NULL, then dh is set automatically; otherwise, grdh is taken as a step size, often set as 1.0e-004. + // f0: the value of (*fcn)(x). NOT used in this function except dealing with the boundary (NEARINFINITY) for the + // minimization problem, but to be compatible with a genral function call where, say, gradfw_gen() and cubic + // interpolation of central difference method will use f0. + + double dh, dhi, dh2i, fp, fm, tmp, *xp; + int i; + + if (grdh) { + //=== If f0 >= NEARINFINITY, we're in a bad region and so we assume it's flat in this bad region. This assumption may or may not work for a third-party optimimization routine. + if (f0 >= NEARINFINITY) + { + for (i=n-1; i>=0; i--) + g[i] = GRADMANUAL; + return;; //Early exit. + } + + dh2i = (dhi=1.0/(dh=*grdh))/2.0; + for (i=0, xp=x; i<n; i++, xp++, g++) { + tmp = *xp; + *xp += dh; + //The following statement is bad because dh does not get reset at the beginning of the loop and thus may get changed continually within the loop. + // dh = *xp - tmp; // This increases the precision slightly. + fp = fcn(x, n); //For frprmn() CGI_OPTIMIZATION + //fp = fcn(n,x); // IMSL + //fcn(n,x,&fp,NULL,NULL); /* NAG */ + *xp = tmp - dh; + fm = fcn(x, n); //For frprmn() CGI_OPTIMIZATION + //fm = fcn(n,x); // IMSL + //fcn(n,x,&fm,NULL,NULL); + + //=== Checking the boundary condition for the minimization problem. + if ((fp < NEARINFINITY) && (fm < NEARINFINITY)) *g = (fp-fm)*dh2i; + else if (fp < NEARINFINITY) *g = (fp-f0)*dhi; + else if (fm < NEARINFINITY) *g = (f0-fm)*dhi; + else *g = GRADMANUAL; + + *xp = tmp; // Put the original value of x[i] back to x[i] so that the content x[i] is still unaltered. + } + + } + else { + //=== If f0 >= NEARINFINITY, we're in a bad region and so we assume it's flat in this bad region. This assumption may or may not work for a third-party optimimization routine. + if (f0 >= NEARINFINITY) + { + for (i=n-1; i>=0; i--) + g[i] = GRADMANUAL; + return;; //Early exit. + } + + for (i=0, xp=x; i<n; i++, xp++, g++) { + dh = fabs(*xp)<=1 ? STPS : STPS*(*xp); + tmp = *xp; + *xp += dh; + dh = *xp - tmp; // This increases the precision slightly. + fp = fcn(x, n); //For frprmn() CGI_OPTIMIZATION + //fp = fcn(n,x); // IMSL + //fcn(n,x,&fp,NULL,NULL); /* NAG */ + *xp = tmp - dh; + fm = fcn(x, n); //For frprmn() CGI_OPTIMIZATION + //fm = fcn(n,x); // IMSL + //fcn(n,x,&fm,NULL,NULL); + + //=== Checking the boundary condition for the minimization problem. + if ((fp < 0.5*NEARINFINITY) && (fm < 0.5*NEARINFINITY)) *g = (fp-fm)/(2.0*dh); + else if (fp < 0.5*NEARINFINITY) *g = (fp-f0)/dh; + else if (fm < 0.5*NEARINFINITY) *g = (f0-fm)/dh; + else *g = GRADMANUAL; + + *xp = tmp; // Put the original value of x[i] back to x[i] so that the content x[i] is still unaltered. + } + } +} +#undef STPS +#undef GRADMANUAL + + +//------------------------------- +//Forward difference gradient: much faster than gradcd_gen() when the objective function is very expensive to evaluate. +//------------------------------- +#define STPS 1.0e-04 // 6.0554544523933391e-6 step size = pow(DBL_EPSILON,1.0/3) +void gradfd_gen(double *g, double *x, int n, double (*fcn)(double *x, int n), double *grdh, double f0) { + //Outputs: + // g: the gradient n-by-1 g (no need to be initialized). + //Inputs: + // x: the vector point at which the gradient is evaluated. No change in the end although will be added or substracted by dh during the function (but in the end the original value will be put back). + // n: the dimension of g or x. + // fcn(): the function for which the gradient is evaluated + // grdh: step size. If NULL, then dh is set automatically; otherwise, grdh is taken as a step size, often set as 1.0e-004. + // f0: the value of (*fcn)(x). NOT used in this function except dealing with the boundary (NEARINFINITY) for the + // minimization problem, but to be compatible with a genral function call where, say, gradfw_gen() and cubic + // interpolation of central difference method will use f0. + + double dh, dhi, fp, tmp, *xp; + int i; + if (grdh) { + dhi = 1.0/(dh=*grdh); + for (i=0, xp=x; i<n; i++, xp++, g++) { + dh = fabs(*xp)<=1 ? STPS : STPS*(*xp); + tmp = *xp; + *xp += dh; + if ( (fp=fcn(x, n)) < NEARINFINITY ) *g = (fp-f0)*dhi; //For frprmn() CGI_OPTIMIZATION + else { + //Switches to the other side of the boundary. + *xp = tmp - dh; + *g = (f0-fcn(x,n))*dhi; + } + *xp = tmp; // Put the original value of x[i] back to x[i] so that the content x[i] is still unaltered. + } + + } + else { + for (i=0, xp=x; i<n; i++, xp++, g++) { + dh = fabs(*xp)<=1 ? STPS : STPS*(*xp); + tmp = *xp; + *xp += dh; + dh = *xp - tmp; // This increases the precision slightly. + if ( (fp=fcn(x, n)) < NEARINFINITY ) *g = (fp-f0)/dh; //For frprmn() CGI_OPTIMIZATION + else { + //Switches to the other side of the boundary. + *xp = tmp - dh; + *g = (f0-fcn(x,n))/dh; + } + + *xp = tmp; // Put the original value of x[i] back to x[i] so that the content x[i] is still unaltered. + } + } +} +#undef STPS + + + +//==================================================================================================== +//= Central difference gradient for logLH at time t, using DW's smodel. +//==================================================================================================== +#define STPS 1.0e-04 // 6.0554544523933391e-6 step size = pow(DBL_EPSILON,1.0/3) +#define GRADMANUAL 1.0e+01 //Arbitrarily (manually) set gradient. +void gradcd_timet(TSdvector *g_dv, TSdvector *x_dv, int t, struct TStateModel_tag *smodel_ps, double (*fcn)(double *x, int t, struct TStateModel_tag *smodel_ps), double grdh, double f0) +{ + //Outputs: + // g_dv: the gradient n-by-1 g (no need to be initialized). + //Inputs: + // x_dv: the vector point at which the gradient is evaluated. No change in the end although will be added or substracted by dh during the function (but in the end the original value will be put back). + // fcn(): the log LH or posterior function for which the gradient is evaluated + // grdh: step size. If 0.0, then dh is set automatically; otherwise, grdh is taken as a step size, often set as 1.0e-004. + // f0: the value of (*fcn)(x). NOT used in this function except dealing with the boundary (NEARINFINITY) for the + // minimization problem, but to be compatible with a genral function call where, say, gradfw_gen() and cubic + // interpolation of central difference method will use f0. + + double dh, dhi, dh2i, fp, fm, tmp, *xp; + int i; + //--- Accessible variables. + int n; + double *g, *x; + + if (!g_dv) fn_DisplayError(".../cstz.c/gradcd_timet(): the input g_dv must be allocated memory"); + if (!x_dv) fn_DisplayError(".../cstz.c/gradcd_timet(): the input x_dv must be allocated memory"); + if (!x_dv->flag) fn_DisplayError(".../cstz.c/gradcd_timet(): the input x_dv must be given legal values"); + if ((n=g_dv->n) != x_dv->n) fn_DisplayError(".../cstz.c/gradcd_timet(): dimensions of g_dv and x_dv must be the same"); + + g = g_dv->v; + x = x_dv->v; + + if (grdh>0.0) + { + //=== If f0 <= -0.5*NEARINFINITY, we're in a bad region and so we assume it's GRADMANUAL in this bad region. This assumption may or may not work for a third-party optimimization routine. + if (f0 < -0.5*NEARINFINITY) + { + for (i=n-1; i>=0; i--) + g[i] = GRADMANUAL; + return;; //Early exit. + } + + dh2i = (dhi=1.0/(dh=grdh))/2.0; + for (i=0, xp=x; i<n; i++, xp++, g++) { + tmp = *xp; + *xp += dh; + //The following statement is bad because dh does not get reset at the beginning of the loop and thus may get changed continually within the loop. + // dh = *xp - tmp; // This increases the precision slightly. + fp = fcn(x, t, smodel_ps); + *xp = tmp - dh; + fm = fcn(x, t, smodel_ps); + + //=== Checking the boundary condition for the minimization problem. + if ((fp > -0.5*NEARINFINITY) && (fm > -0.5*NEARINFINITY)) *g = (fp-fm)*dh2i; + else if (fp > -0.5*NEARINFINITY) *g = (fp-f0)*dhi; + else if (fm > -0.5*NEARINFINITY) *g = (f0-fm)*dhi; + else *g = GRADMANUAL; + + *xp = tmp; // Put the original value of x[i] back to x[i] so that the content x[i] is still unaltered. + } + + } + else { + //=== If f0 <= -0.5*NEARINFINITY, we're in a bad region and so we assume it's GRADMANUAL in this bad region. This assumption may or may not work for a third-party optimimization routine. + if (f0 <= -0.5*NEARINFINITY) + { + for (i=n-1; i>=0; i--) + g[i] = GRADMANUAL; + return;; //Early exit. + } + + for (i=0, xp=x; i<n; i++, xp++, g++) { + dh = fabs(*xp)<=1 ? STPS : STPS*(*xp); + tmp = *xp; + *xp += dh; + dh = *xp - tmp; // This increases the precision slightly. + fp = fcn(x, t, smodel_ps); + *xp = tmp - dh; + fm = fcn(x, t, smodel_ps); + + //=== Checking the boundary condition for the minimization problem. + if ((fp > -0.5*NEARINFINITY) && (fm > -0.5*NEARINFINITY)) *g = (fp-fm)/(2.0*dh); + else if (fp > -0.5*NEARINFINITY) *g = (fp-f0)/dh; + else if (fm > -0.5*NEARINFINITY) *g = (f0-fm)/dh; + else *g = GRADMANUAL; + + *xp = tmp; // Put the original value of x[i] back to x[i] so that the content x[i] is still unaltered. + } + } + g_dv->flag = V_DEF; +} +#undef STPS +#undef GRADMANUAL +//--- +#if defined (NEWVERSIONofDW_SWITCH) +static double logCondPostKernTimet(double *xchange_pd, int t, struct TStateModel_tag *smodel_ps) +{ + //Evaluating log conditional posterior kernel at time t -- p(y_t | Y_{t-1}, theta, q). + int fss = smodel_ps->nobs - smodel_ps->fobs + 1; + double *x1_pd, *x2_pd; + + + x1_pd = xchange_pd; + x2_pd = xchange_pd + NumberFreeParametersTheta(smodel_ps); + //Note that NumberFreeParametersTheta() is DW's function, which points to TZ's function. + //In the constant parameter model, this will point to an invalid place, + // but will be taken care of automatically by DW's function ConvertFreeParametersToQ(). + + //======= This is a must step to refresh the value at the new point. ======= + ConvertFreeParametersToTheta(smodel_ps, x1_pd); //Waggoner's function, which calls TZ's Convertphi2*(). + ConvertFreeParametersToQ(smodel_ps, x2_pd); //Waggoner's function, which automatically takes care of the constant-parameter situition + ThetaChanged(smodel_ps); //DW's function, which will also call my function to set a flag for refreshing everything under these new parameters. + + + if (1) //Posterior function. + return ( LogConditionalLikelihood_StatesIntegratedOut(t, smodel_ps) + LogPrior(smodel_ps)/((double)fss) ); //DW's function. + else //Likelihood (with no prior) + return ( LogConditionalLikelihood_StatesIntegratedOut(t, smodel_ps) ); //DW's function. +} +#endif + +//------------------------ +// Computing the Hessian at the log posterior or log likelihood peak, using the outer-product Hessian. +//------------------------ +#if defined (NEWVERSIONofDW_SWITCH) +TSdmatrix *ComputeHessianFromOuterProduct(TSdmatrix *Hessian_dm, struct TStateModel_tag *smodel_ps, TSdvector *xhat_dv) +{ + //Output: + // Hessian_dm: its inverse equals to Omega (covariance matrix) produced by ComputeCovarianceFromOuterProduct(). + //Inputs: + // xhat_dv: Hessian at this point. + + int ti; + double f0; + int nData = smodel_ps->nobs; + //=== + TSdvector *grad_dv; + + + grad_dv = CreateVector_lf(xhat_dv->n); + if (!Hessian_dm) Hessian_dm = CreateConstantMatrix_lf(xhat_dv->n, xhat_dv->n, 0.0); + + //=== Computing the outer-product Hessian. + for (ti=smodel_ps->fobs; ti<=nData; ti++) //Base-1 set-up, thus <=nData, NOT <nData. + { + f0 = logCondPostKernTimet(xhat_dv->v, ti, smodel_ps); + gradcd_timet(grad_dv, xhat_dv, ti, smodel_ps, logCondPostKernTimet, 0.0, f0); + VectorTimesSelf(Hessian_dm, grad_dv, 1.0, 1.0, 'U'); + } + + + SUtoGE(Hessian_dm); //Making upper symmetric matarix to a full matrix. + Hessian_dm->flag = M_GE; //Reset this flag, so + ScalarTimesMatrixSquare(Hessian_dm, 0.5, Hessian_dm, 'T', 0.5); //Making it symmetric against some rounding errors. + //This making-symmetric is very IMPORTANT; otherwise, we will get the matrix being singular message + // and eigenvalues being negative for the SPD matrix, etc. Then the likelihood becomes either + // a bad number or a complex number. + Hessian_dm->flag |= M_SU | M_SL; + + + //=== + DestroyVector_lf(grad_dv); + + return (Hessian_dm); +} +//------------------------ +// Computing the covariance matrix for standard errors at the log posterior or likelihood peak, using the outer-product Hessian. +//------------------------ +TSdmatrix *ComputeCovarianceFromOuterProduct(TSdmatrix *Omega_dm, struct TStateModel_tag *smodel_ps, TSdvector *xhat_dv) +{ + //Output: + // Omega_dm: covariance matrix, which equals to the inverse of the Hessian produced by ComputeHessianFromOuterProduct(). + //Inputs: + // xhat_dv: Hessian at this point. + + int ti; + double f0; + int nData = smodel_ps->nobs; + //=== + TSdvector *grad_dv; + + + grad_dv = CreateVector_lf(xhat_dv->n); + if (!Omega_dm) Omega_dm = CreateConstantMatrix_lf(xhat_dv->n, xhat_dv->n, 0.0); + + //=== Computing the outer-product Hessian. + for (ti=smodel_ps->fobs; ti<=nData; ti++) //Base-1 set-up, thus <=nData, NOT <nData. + { + f0 = logCondPostKernTimet(xhat_dv->v, ti, smodel_ps); + gradcd_timet(grad_dv, xhat_dv, ti, smodel_ps, logCondPostKernTimet, 0.0, f0); + VectorTimesSelf(Omega_dm, grad_dv, 1.0, 1.0, 'U'); + } + SUtoGE(Omega_dm); //Making upper symmetric matarix to a full matrix. + ScalarTimesMatrixSquare(Omega_dm, 0.5, Omega_dm, 'T', 0.5); //Making it symmetric against some rounding errors. + //This making-symmetric is very IMPORTANT; otherwise, we will get the matrix being singular message + // and eigenvalues being negative for the SPD matrix, etc. Then the likelihood becomes either + // a bad number or a complex number. + Omega_dm->flag |= M_SU | M_SL; + + + //--- Converting or inverting the Hessian to covariance. + if (invspd(Omega_dm, Omega_dm, 'U')) + fn_DisplayError(".../cstz.c/ComputeCovarianceFromOuterProduct(): Hessian must be invertible"); + + + //-- Doubly safe to force it to be symmetric. + SUtoGE(Omega_dm); //Making upper symmetric matarix to a full matrix. + ScalarTimesMatrixSquare(Omega_dm, 0.5, Omega_dm, 'T', 0.5); //Making it symmetric against some rounding errors. + //This making-symmetric is very IMPORTANT; otherwise, we will get the matrix being singular message + // and eigenvalues being negative for the SPD matrix, etc. Then the likelihood becomes either + // a bad number or a complex number. + Omega_dm->flag |= M_SU | M_SL; + + //--- Checking if it's symmetric, positive definite. + + + //=== + DestroyVector_lf(grad_dv); + + return (Omega_dm); +} + + + +//------------------------ +// Computing the Hessian at the log posterior or log likelihood peak, using second derivatives. +//------------------------ +TSdmatrix *ComputeHessianFrom2ndDerivative(TSdmatrix *Hessian_dm, struct TStateModel_tag *smodel_ps, TSdvector *xhat_dv) +{ + //Output: + // Hessian_dm: its inverse equals to Omega (covariance matrix). + // The flag is set to M_GE | M_SU | M_SL by hesscd_smodel(). + //Inputs: + // xhat_dv: Hessian at this point. + + double f0; + int nData = smodel_ps->nobs; + + + if (!Hessian_dm) Hessian_dm = CreateConstantMatrix_lf(xhat_dv->n, xhat_dv->n, 0.0); + + //=== Computing the inner-product Hessian. + f0 = neglogPostKern_hess(xhat_dv->v, smodel_ps); + hesscd_smodel(Hessian_dm, xhat_dv, smodel_ps, neglogPostKern_hess, 0.0, f0); + + return (Hessian_dm); +} +//--- +#define STPS 1.0e-4 //6.0554544523933391e-6 /* step size = pow(DBL_EPSILON,1.0/3) */ +static void hesscd_smodel(TSdmatrix *H_dm, TSdvector *x_dv, struct TStateModel_tag *smodel_ps, double (*fcn)(double *, struct TStateModel_tag *), double grdh, double f0) +{ + //Outputs: + // H_dm: the Hessian n-by-n (no need to be initialized). + //Inputs: + // x_dv: the vector point at which the gradient is evaluated. No change in the end although will be added or substracted by dh during the function (but in the end the original value will be put back). + // fcn(): the negative (-) log LH or posterior function for which the gradient is evaluated + // grdh: step size. If 0.0, then dh is set automatically; otherwise, grdh is taken as a step size, often set as 1.0e-004. + // f0: the value of (*fcn)(x). NOT used in this function except dealing with the boundary (NEARINFINITY) for the + // minimization problem, but to be compatible with a genral function call where, say, gradfw_gen() and cubic + // interpolation of central difference method will use f0. + + double dhi, dhj, f1, f2, f3, f4, tmpi, tmpj, *xpi, *xpj; + int i, j; + //--- Accessible variables. + int n; + double *H, *x; + + if (!x_dv) fn_DisplayError(".../cstz.c/hesscd_smodel(): the input x_dv must be allocated memory"); + if (!x_dv->flag) fn_DisplayError(".../cstz.c/hesscd_smodel(): the input x_dv must be given legal values"); + if (!H_dm) fn_DisplayError(".../cstz.c/hesscd_smodel(): H_dm must be allocated memory"); + if ( ((n=x_dv->n) != H_dm->nrows) || (n != H_dm->ncols) ) fn_DisplayError(".../cstz.c/hesscd_smodel(): Check the dimension of x_dv and H_dm"); + + H = H_dm->M; + x = x_dv->v; + + for (i=0, xpi=x; i<n; i++, xpi++) { + dhi = grdh?grdh:(fabs(*xpi)<1?STPS:STPS*(*xpi)); + tmpi = *xpi; + for (j=i, xpj=x+i; j<n; j++, xpj++) + if (i==j) + { + /* f2 = f3 when i = j */ + if ((f2 = fcn(x, smodel_ps)) > 0.5*NEARINFINITY) f2 = f0; + + /* this increases precision slightly */ + *xpi += dhi; + dhi = *xpi - tmpi; + + /* calculate f1 and f4 */ + *xpi = tmpi + 2*dhi; + if ((f1 = fcn(x, smodel_ps)) > 0.5*NEARINFINITY) f1 = f0; + + *xpi = tmpi - 2*dhi; + if ((f4 = fcn(x, smodel_ps)) > 0.5*NEARINFINITY) f4 = f0; + + /* diagonal element */ + H[i*(n+1)] = (f1-2*f2+f4)/(4*dhi*dhi); + + /* reset to intial value */ + *xpi = tmpi; + } + else + { + dhj = grdh?grdh:(fabs(*xpj)<1?STPS:STPS*(*xpj)); + tmpj = *xpj; + + /* this increases precision slightly */ + *xpi += dhi; + dhi = *xpi - tmpi; + *xpj += dhj; + dhj = *xpj - tmpj; + + /* calculate f1, f2, f3 and f4 */ + *xpj = tmpj + dhj; + if ((f1 = fcn(x, smodel_ps)) > 0.5*NEARINFINITY) f1 = f0; + *xpi = tmpi - dhi; + if ((f2 = fcn(x, smodel_ps)) > 0.5*NEARINFINITY) f2 = f0; + *xpi = tmpi + dhi; + *xpj = tmpj - dhj; + if ((f3 = fcn(x, smodel_ps)) > 0.5*NEARINFINITY) f3 = f0; + *xpi = tmpi - dhi; + if ((f4 = fcn(x, smodel_ps)) > 0.5*NEARINFINITY) f4 = f0; + + /* symmetric elements */ + H[i+j*n] = H[j+i*n] = (f1-f2-f3+f4)/(4*dhi*dhj); + + /* reset to intial values */ + *xpi = tmpi; + *xpj = tmpj; + } + } + + //--- To be safe. + H_dm->flag = M_SU; + SUtoGE(H_dm); //Making upper symmetric matarix to a full matrix. + H_dm->flag = M_GE; //Reset this flag, so + + ScalarTimesMatrixSquare(H_dm, 0.5, H_dm, 'T', 0.5); //Making it symmetric against some rounding errors. + //This making-symmetric is very IMPORTANT; otherwise, we will get the matrix being singular message + // and eigenvalues being negative for the SPD matrix, etc. Then the likelihood becomes either + // a bad number or a complex number. + H_dm->flag |= M_SU | M_SL; +} +#undef STPS +//--- +static double neglogPostKern_hess(double *xchange_pd, struct TStateModel_tag *smodel_ps) +{ + //Evaluating negative log posterior kernel p(y_T | theta, q). + int fss = smodel_ps->nobs - smodel_ps->fobs + 1; + double *x1_pd, *x2_pd; + + + x1_pd = xchange_pd; + x2_pd = xchange_pd + NumberFreeParametersTheta(smodel_ps); + //Note that NumberFreeParametersTheta() is DW's function, which points to TZ's function. + //In the constant parameter model, this will point to an invalid place, + // but will be taken care of automatically by DW's function ConvertFreeParametersToQ(). + + //======= This is a must step to refresh the value at the new point. ======= + ConvertFreeParametersToTheta(smodel_ps, x1_pd); //Waggoner's function, which calls TZ's Convertphi2*(). + ConvertFreeParametersToQ(smodel_ps, x2_pd); //Waggoner's function, which automatically takes care of the constant-parameter situition + ThetaChanged(smodel_ps); //DW's function, which will also call my function to set a flag for refreshing everything under these new parameters. + + + if (1) //Posterior function. + return ( -LogLikelihood_StatesIntegratedOut(smodel_ps) - LogPrior(smodel_ps) ); //DW's function. + else //Likelihood (with no prior) + return ( -LogLikelihood_StatesIntegratedOut(smodel_ps) ); //DW's function. +} +#endif + + + + + + + + + + +//???????????????? +/** +//=== +static struct TStateModel_tag *SMODEL_PS = NULL; //Minimization to find the MLE or posterior peak. +static struct TStateModel_tag *SetModelGlobalForCovariance(struct TStateModel_tag *smodel_ps) +{ + //Returns the old pointer in order to preserve the previous value. + struct TStateModel_tag *tmp_ps =SMODEL_PS; + SMODEL_PS = smodel_ps; + return (tmp_ps); +} +//--- Can be used for conjugate gradient minimization as well. +static double ObjFuncForSmodel(double *x0_p, int d_x0) +{ + TSdvector x0_sdv; + x0_sdv.v = x0_p; + x0_sdv.n = d_x0; + x0_sdv.flag = V_DEF; + + return ( -opt_logOverallPosteriorKernal(SMODEL_PS, &x0_sdv) ); +} +//--- +static double opt_logOverallPosteriorKernal(struct TStateModel_tag *smodel_ps, TSdvector *xchange_dv) +{ + double *x1_pd, *x2_pd; + + + x1_pd = xchange_dv->v; + x2_pd = xchange_dv->v + NumberFreeParametersTheta(smodel_ps); + //Note that NumberFreeParametersTheta() is DW's function, which points to TZ's function. + //In the constant parameter model, this will point to invalid, + // but will be taken care of automatically by DW's function ConvertFreeParametersToQ(). + + //======= This is a must step to refresh the value at the new point. ======= + ConvertFreeParametersToTheta(smodel_ps, x1_pd); //Waggoner's function, which calls TZ's Convertphi2*(). + ConvertFreeParametersToQ(smodel_ps, x2_pd); //Waggoner's function, which automatically takes care of the constant-parameter situition + ThetaChanged(smodel_ps); //DW's function, which will also call my function to set a flag for refreshing everything under these new parameters. + if (1) //Posterior function. + return ( LogPosterior_StatesIntegratedOut(smodel_ps) ); //DW's function. + else //Likelihood (with no prior) + return ( LogLikelihood_StatesIntegratedOut(smodel_ps) ); //DW's function. +} +/**/ + + + + + + + + +int next_permutation(int *first, int *last) +{ + // Given the permulation, say, [3 2 1 0], the ouput is the next permulation [0 1 2 3], and so on. + // Note that last is simply a pointer. Because it is not allocated to a memory, it cannot be accessed. + // So last is used for (1) gauging the dimension size of the array first; + // (2) being accssed but with --last (which points to a valid memory place), NOT last. + // + // first: n-by-1 vector of integers filled with 0, 1, 2, ..., n. + // last: simply a pointer to the address after the last element of first. Note that no memory is allocated. + + int *i = last, *ii, *j, tmp; + if (first == last || first == --i) + return 0; + + for(; ; ) { + ii = i; + if (*--i < *ii) { + j = last; + while (!(*i < *--j)); + tmp = *i; *i = *j; *j = tmp; + for (; ii != last && ii != --last; ++ii) { + tmp = *ii; *ii = *last; *last = tmp; + } + return 1; + } + if (i == first) { + for (; first != last && first != --last; ++first) { + tmp = *first; *first = *last; *last = tmp; + } + return 0; + } + } +} + + + +/** +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +void permute_matrix(double *a, int n, int *indx) { + double *b; + int nn=n*n; + register int i; + b = calloc(nn,sizeof(double)); + memcpy(b, a, nn*sizeof(double)); + for (i=0; i<nn; i++, a++) + *a = b[indx[i%n]+indx[i/n]*n]; +} + +int main() { + double a[9]={1,2,3,4,5,6,7,8,9}; + int indx[3]={1,2,0}; + permute_matrix(a,3,indx); + return 0; +} +/**/ + + +int fn_cumsum_int(int *x_v, const int d_x_v) { + //Outputs: + // x_v: an int vector of cumulative sums over an input int vector. + // return: the sum of an input int vector. + //Inputs: + // x_v: a vector of ints. + // d_x_v: dimension of x_v. + // + // Compute cumulative sums of a vector of ints. + int _i; + + if (x_v==NULL) fn_DisplayError(".../cstz/fn_cumsum_lf: x_v must be allocated with memory"); + + for (_i=1; _i<d_x_v; _i++) { + x_v[_i] = x_v[_i-1] + x_v[_i]; + } + + return (x_v[d_x_v-1]); +} + + +double fn_cumsum_lf(double *x_v, const int d_x_v) { + //Outputs: + // x_v: a double vector of cumulative sums over an input double vector. + // return: the sum of an input double vector. + //Inputs: + // x_v: a vector of doubles. + // d_x_v: dimension of x_v. + // + // Compute cumulative sums of a vector of doubles. + int _i; + + if (!x_v) fn_DisplayError(".../cstz/fn_cumsum_lf: x_v must be allocated with memory"); + + for (_i=1; _i<d_x_v; _i++) { + x_v[_i] = x_v[_i-1] + x_v[_i]; + } + + return (x_v[d_x_v-1]); +} + + +double fn_mean(const double *a_v, const int _n) { + int _i; + double x=0.0; + + for (_i=0; _i<_n; _i++) x += a_v[_i]; + x /= (double)_n; + + return x; +} + +//<<--------------- +static double *tz_BaseForComp; // This base variable is to be sorted and thus made global for this source file. +void fn_SetBaseArrayForComp(TSdvector *x_dv) +{ + if ( !x_dv->flag ) fn_DisplayError(".../cstz.c/ftd_SetBaseArrayForComp(): input vector used for comparison must be given legal values"); + else tz_BaseForComp = x_dv->v; +} +int fn_compare(const void *i1, const void *i2) +{ + // Ascending order according to tz_BaseForComp. + return ( (tz_BaseForComp[*((int*)i1)]<tz_BaseForComp[*((int*)i2)]) ? -1 : (tz_BaseForComp[*((int*)i1)]>tz_BaseForComp[*((int*)i2)]) ? 1 : 0 ); +} +int fn_compare2(const void *i1, const void *i2) +{ + // Descending order according to tz_BaseForComp. + return ( (tz_BaseForComp[*((int*)i1)]<tz_BaseForComp[*((int*)i2)]) ? 1 : (tz_BaseForComp[*((int*)i1)]>tz_BaseForComp[*((int*)i2)]) ? -1 : 0); +} +//======= Quick sort. ======= +static int ftd_CompareDouble(const void *a, const void *b) +{ + // Ascending order for the series that contains a and b. + return (*(double *)a < *(double *)b ? -1 : *(double *)a > *(double *)b ? 1 : 0); +} +static int ftd_CompareDouble2(const void *a, const void *b) +{ + // Dscending order for the series that contains a and b. + return (*(double *)a < *(double *)b ? 1 : *(double *)a > *(double *)b ? -1 : 0); +} +//--- +void tz_sort(TSdvector *x_dv, char ad) +{ + //x_dv will be replaced by the sorted value. + //Sort x_dv according to the descending or ascending order indicated by ad. + //ad == "A' or 'a': acending order. + //ad == 'D' or 'd': descending order. + if (!x_dv || !x_dv->flag) fn_DisplayError("cstz.c/tz_sort(): input vector x_dv must be (1) created and (2) assigned values"); + + qsort( (void *)x_dv->v, (size_t)x_dv->n, sizeof(double), ((ad=='A') || (ad=='a')) ? ftd_CompareDouble : ftd_CompareDouble2); +} +void tz_sortindex_lf(TSivector *x_iv, TSdvector *base_dv, char ad) +{ + //???????NOT fully tested yet. + //x_iv will be replaced by the sorted integer vector. + //base_dv will not be affected. + //Sort x_iv according to the descending or ascending order of base_dv. + //ad == "A' or 'a': acending order. + //ad == 'D' or 'd': descending order. + if (!x_iv || !base_dv || !x_iv->flag || !base_dv->flag) fn_DisplayError("cstz.c/tz_sortindex(): input vectors x_iv and base_dv must be (1) created and (2) assigned values"); + if (x_iv->n != base_dv->n) fn_DisplayError("cstz.c/tz_sortindex(): lengths of the two input vectors must be the same"); + + fn_SetBaseArrayForComp(base_dv); + qsort( (void *)x_iv->v, (size_t)x_iv->n, sizeof(int), ((ad=='A') || (ad=='a')) ? fn_compare : fn_compare2); +} +void tz_sortindex(TSivector *x_iv, TSvoidvector *base_voidv, char ad) +{ + //???????NOT fully tested yet. + //Allowing x_iv = base_voidv or sets base_voidv=NULL + //Sort x_iv according to the descending or ascending order of base_voidv. + //ad == "A' or 'a': acending order. + //ad == 'D' or 'd': descending order. + if (!x_iv || !base_voidv || !x_iv->flag || !base_voidv->flag) fn_DisplayError("cstz.c/tz_sort_int(): input vectors x_iv and base_voidv must be (1) created and (2) assigned values"); + if (x_iv->n != base_voidv->n) fn_DisplayError("cstz.c/tz_sort_int(): lengths of the two input vectors must be the same"); + + fn_SetBaseArrayForComp((TSdvector *)base_voidv); + qsort( (void *)x_iv->v, (size_t)x_iv->n, sizeof(int), ((ad=='A') || (ad=='a')) ? fn_compare : fn_compare2); +} +//--- +void tz_sort_matrix(TSdmatrix *X_dm, char ad, char rc) +{ + //Fast method: rc = 'C' (sort each column). + //Output: X_dm will be replaced by the sorted value. + // Sort X_dm (1) by columns or rows indicated by rc and (2) according to the descending or ascending order indicated by ad. + //Inputs: + // ad == 'A' or 'a': acending order. + // ad == 'D' or 'd': descending order. + // rc == 'C' or 'c': sort each column. + // rc == 'R' or 'r': sort each row. + int nrows, ncols, _j, begloc; + TSdvector x_sdv; + double *X; + //=== + TSdmatrix *Xtran_dm = NULL; + + if (!X_dm || !(X_dm->flag & M_GE)) fn_DisplayError("cstz.c/tz_sort_matrix(): input matrix X_dm must be (1) created and (2) assigned values and (3) regular (M_GE)"); + x_sdv.flag = V_DEF; + + if (rc=='C' || rc=='c') + { + X = X_dm->M; + nrows = X_dm->nrows; + ncols = X_dm->ncols; + } + else + { + Xtran_dm = tz_TransposeRegular((TSdmatrix *)NULL, X_dm); + X = Xtran_dm->M; + nrows = Xtran_dm->nrows; + ncols = Xtran_dm->ncols; + } + x_sdv.n = nrows; + for (begloc=nrows*(ncols-1), _j=ncols-1; _j>=0; begloc-=nrows, _j--) + { + x_sdv.v = X + begloc; + tz_sort(&x_sdv, ad); + } + + if (rc=='R' || rc=='r') + { + tz_TransposeRegular(X_dm, Xtran_dm); + //=== + DestroyMatrix_lf(Xtran_dm); + } +} +//--- +TSdvector *tz_prctile_matrix(TSdvector *z_dv, const double prc, TSdmatrix *Z_dm, const char rc) +{ + //Fast method: rc = 'C' (sort each column). + //Output: %prc percentile (i.e., containing 0% to %prc). + // z_dv: an n-by-1 vector if rc=='C' or an m-by-1 vector if rc=='R'. + // If z_dv==NULL, it will be created and has to be destroyed outside this function. + //Inputs: + // prc: percent (must be between 0.0 and 1.0 inclusive). + // X_dm: an m-by-n general matrix. + // rc == 'C' or 'c': sort each column. + // rc == 'R' or 'r': sort each row. + int nrows, ncols, _j, begloc; + TSdvector x_sdv; + double *X; + //=== + TSdmatrix *X_dm = NULL; + TSdmatrix *Xtran_dm = NULL; + + if (!Z_dm || !Z_dm->flag) fn_DisplayError("cstz.c/tz_prctile_matrix(): input matrix Z_dm must be (1) created and (2) assigned values"); + if (prc<0.0 || prc>1.0) fn_DisplayError("cstz.c/tz_prctile_matrix(): percentile mark prc must be between 0.0 and 1.0 inclusive"); + x_sdv.flag = V_DEF; + + nrows = Z_dm->nrows; + ncols = Z_dm->ncols; + if (!z_dv) + { + if (rc=='C' || rc=='c') z_dv = CreateVector_lf(ncols); + else z_dv = CreateVector_lf(nrows); + } + else + { + if ((rc=='C' || rc=='c')) + { + if (ncols != z_dv->n) fn_DisplayError("cstz.c/tz_prctile_matrix(): z_dv->n must be the same as ncols of X_dm when sorting each column"); + } + else + { + if (nrows != z_dv->n) fn_DisplayError("cstz.c/tz_prctile_matrix(): z_dv->n must be the same as nrows of X_dm when sorting each row"); + } + } + X_dm = CreateMatrix_lf(nrows, ncols); + CopyMatrix0(X_dm, Z_dm); + + if (rc=='C' || rc=='c') + { + X = X_dm->M; + nrows = X_dm->nrows; + ncols = X_dm->ncols; + } + else + { + Xtran_dm = tz_TransposeRegular((TSdmatrix *)NULL, X_dm); + X = Xtran_dm->M; + nrows = Xtran_dm->nrows; + ncols = Xtran_dm->ncols; + } + x_sdv.n = nrows; + for (begloc=nrows*(ncols-1), _j=ncols-1; _j>=0; begloc-=nrows, _j--) + { + x_sdv.v = X + begloc; + tz_sort(&x_sdv, 'A'); + z_dv->v[_j] = x_sdv.v[(int)floor(prc*(double)nrows)]; + } + z_dv->flag = V_DEF; + if (rc=='R' || rc=='r') DestroyMatrix_lf(Xtran_dm); + + //=== + DestroyMatrix_lf(X_dm); + + return (z_dv); +} +//--- +TSdvector *tz_mean_matrix(TSdvector *z_dv, TSdmatrix *Z_dm, const char rc) +{ + //Fast method: rc = 'C' (mean for each column). + //Output: %prc percentile (i.e., containing 0% to %prc). + // z_dv: an n-by-1 vector if rc=='C' or an m-by-1 vector if rc=='R'. + // If z_dv==NULL, it will be created and has to be destroyed outside this function. + //Inputs: + // X_dm: an m-by-n general matrix. + // rc == 'C' or 'c': mean for each column. + // rc == 'R' or 'r': mean for each row. + int nrows, ncols, _j, begloc; + TSdvector x_sdv; + double *X; + //=== + TSdmatrix *X_dm = NULL; + TSdmatrix *Xtran_dm = NULL; + + if (!Z_dm || !Z_dm->flag) fn_DisplayError("cstz.c/tz_mean_matrix(): input matrix Z_dm must be (1) created and (2) assigned values"); + x_sdv.flag = V_DEF; + + nrows = Z_dm->nrows; + ncols = Z_dm->ncols; + if (!z_dv) + { + if (rc=='C' || rc=='c') z_dv = CreateVector_lf(ncols); + else z_dv = CreateVector_lf(nrows); + } + else + { + if ((rc=='C' || rc=='c')) + { + if (ncols != z_dv->n) fn_DisplayError("cstz.c/tz_mean_matrix(): z_dv->n must be the same as ncols of X_dm when computing mean for each column"); + } + else + { + if (nrows != z_dv->n) fn_DisplayError("cstz.c/tz_mean_matrix(): z_dv->n must be the same as nrows of X_dm when computing mean for each row"); + } + } + X_dm = CreateMatrix_lf(nrows, ncols); + CopyMatrix0(X_dm, Z_dm); + + if (rc=='C' || rc=='c') + { + X = X_dm->M; + nrows = X_dm->nrows; + ncols = X_dm->ncols; + } + else + { + Xtran_dm = tz_TransposeRegular((TSdmatrix *)NULL, X_dm); + X = Xtran_dm->M; + nrows = Xtran_dm->nrows; + ncols = Xtran_dm->ncols; + } + x_sdv.n = nrows; + for (begloc=nrows*(ncols-1), _j=ncols-1; _j>=0; begloc-=nrows, _j--) + { + x_sdv.v = X + begloc; + z_dv->v[_j] = fn_mean(x_sdv.v, x_sdv.n); + } + z_dv->flag = V_DEF; + if (rc=='R' || rc=='r') DestroyMatrix_lf(Xtran_dm); + + //=== + DestroyMatrix_lf(X_dm); + + return (z_dv); +} +//--------------->> + + + +//<<--------------- +// WZ normalization on VARs. +//--------------->> +void fn_wznormalization(TSdvector *wznmlz_dv, TSdmatrix *A0draw_dm, TSdmatrix *A0peak_dm) +{ + //Outputs: + // wznmlz_dv (n-by-1): If negative, the sign of the equation must switch; if positive: no action needs be taken. + // If NULL as an input, remains NULL. + // A0draw_dm (n-by-n): replaced by wz-normalized draw. + //Inputs: + // wznmlz_dv (n-by-1): if NULL, no output for wznmlz_dv; otherwise, a memory allocated vector. + // A0draw_dm (n-by-n): a draw of A0. + // A0peak_dm (n-by-n): reference point to which normalized A0draw_dm is closest. + int _j, _n, + errflag = -2; + double *v; + TSdmatrix *X_dm = NULL; + TSdvector *diagX_dv = NULL; + + if ( !A0peak_dm ) fn_DisplayError(".../cstz.c/fn_wznormalization(): input matrix for ML estimates must be created (memory allocated) and have legal values"); + //This is a minimum check to prevent crash without error messages. More robust checks are done in BdivA_rgens(). + + _n = A0peak_dm->nrows; + X_dm = CreateMatrix_lf(_n, _n); + + if ( errflag=BdivA_rgens(X_dm, A0peak_dm, '\\', A0draw_dm) ) { + printf(".../cstz.c/fn_wznormalization(): errors when calling BdivA_rgens() with error flag %d", errflag); + exit(EXIT_FAILURE); + } + + if (wznmlz_dv) { + diagdv(wznmlz_dv, X_dm); + v = wznmlz_dv->v; + } + else { + diagX_dv = CreateVector_lf(_n); + diagdv(diagX_dv, X_dm); + v = diagX_dv->v; + } + + + for (_j=_n-1; _j>=0; _j--) + if (v[_j]<0) ScalarTimesColofMatrix((TSdvector *)NULL, -1.0, A0draw_dm, _j); + + //=== Destroys memory allocated for this function only. + DestroyMatrix_lf(X_dm); + DestroyVector_lf(diagX_dv); +} + + + + +//---------------<< +// Handling under or over flows with log values. +//--------------->> +struct TSveclogsum_tag *CreateVeclogsum(int n) +{ + struct TSveclogsum_tag *veclogsum_ps = tzMalloc(1, struct TSveclogsum_tag); + + //=== Memory allocation and initialization. + veclogsum_ps->n = n; //Number of sums or the dimension of logofsum. + veclogsum_ps->N_iv = CreateConstantVector_int(n, 0); //Cumulative. (N_1, ..., N_n). + veclogsum_ps->logsum_dv = CreateConstantVector_lf(n, -MACHINEINFINITY); //Cumulative. (logofsum_1, ..., logofsum_n). + veclogsum_ps->logmax_dv = CreateConstantVector_lf(n, -MACHINEINFINITY); //(logmax_1, ..., logmax_n). + + return (veclogsum_ps); +} +//--- +struct TSveclogsum_tag *DestroyVeclogsum(struct TSveclogsum_tag *veclogsum_ps) +{ + + if (veclogsum_ps) { + DestroyVector_int(veclogsum_ps->N_iv); + DestroyVector_lf(veclogsum_ps->logsum_dv); + DestroyVector_lf(veclogsum_ps->logmax_dv); + + //=== + free(veclogsum_ps); + return ((struct TSveclogsum_tag *)NULL); + } + else return (veclogsum_ps); +} +//=== +//------------------ +//Updating the sum (not divided by n) for the mean and the second moment. +//------------------ +void UpdateSumFor1st2ndMoments(TSdvector *x1stsum_dv, TSdmatrix *X2ndsum_dm, const TSdvector *xdraw_dv) +{ + static int ini_indicator = 0; + + if (!ini_indicator) { + //Pass this loop once and no more. + CopyVector0(x1stsum_dv, xdraw_dv); + VectorTimesSelf(X2ndsum_dm, xdraw_dv, 1.0, 0.0, 'U'); + ini_indicator = 1; + } + else { + VectorPlusVectorUpdate(x1stsum_dv, xdraw_dv); + VectorTimesSelf(X2ndsum_dm, xdraw_dv, 1.0, 1.0, 'U'); + } +} +//--- +int tz_update_logofsum(double *Y_N_dp, double *y_Nmax_dp, double ynew, int N) +{ + //Recursive algorithm to update Y_N (=log(sum of x_i)) for i=1, ..., N with the new value ynew = log(x_{N+1}). + //Returns (1) the updated value Y_{N+1} = log(sum of x_i)) for i=1, ..., N+1; + // (2) the updated value y_(N+1)max_dp; + // (3) the integer N+1. + //See TVBVAR Notes p.81a. + + if (*y_Nmax_dp>=ynew) *Y_N_dp = log( exp(*Y_N_dp - *y_Nmax_dp) + exp(ynew - *y_Nmax_dp) ) + *y_Nmax_dp; + else { + *y_Nmax_dp = ynew; + *Y_N_dp = log( exp(*Y_N_dp - ynew) + 1.0 ) + ynew; + } + + return (N+1); +} +int fn_update_logofsum(int N, double ynew, double *Y_N_dp, double *y_Nmax_dp) +{ + //Recursive algorithm to update Y_N (=log(sum of x_i)) for i=1, ..., N with the new value ynew = log(x_{N+1}). + //Returns (1) the updated value Y_{N+1} = log(sum of x_i)) for i=1, ..., N+1; + // (2) the updated value y_(N+1)max_dp; + // (3) the integer N+1. + //See TVBVAR Notes p.81a. + //If N=0, then ynew = -infty (no value yet) and thus no value is added to *Y_N_dp. + +// if (N>0) +// { + if (*y_Nmax_dp>=ynew) *Y_N_dp = log( exp(*Y_N_dp - *y_Nmax_dp) + exp(ynew - *y_Nmax_dp) ) + *y_Nmax_dp; + else { + *y_Nmax_dp = ynew; + *Y_N_dp = log( exp(*Y_N_dp - ynew) + 1.0 ) + ynew; + } +// } + + return (N+1); +} +double fn_replace_logofsumsbt(double *yold, double _a, double ynew, double _b) +{ + //Outputs: + // *yold is replaced by log abs(a*xold + b*xnew). + // 1.0 or -1.0: sign of a*xold + b*xnew. + // + //Given yold=log(xold) and ynew=log(xnew), it updates and returns yold = log abs(a*xold + b*xnew). + //sbt: subtraction or subtract. + //See TVBVAR Notes p.81a. + double tmpd; + //*yold = (*yold > ynew) ? (log( _a + _b*exp(ynew - *yold)) + *yold) : (log( _a*exp(*yold - ynew) + _b) + ynew); + + if (*yold > ynew) { + if ((tmpd=_a + _b*exp(ynew - *yold) ) < 0.0) { + // printf("WARNING! .../cstz.c/fn_replace_logofsumsbt(): Expression inside log is negative and the function returns the negative sign!\n"); + *yold += log(fabs(tmpd)); + return (-1.0); + } + else { + *yold += log(tmpd); + return (1.0); + } + } + else { + if ((tmpd=_a*exp(*yold - ynew) + _b) < 0.0 ) { + // printf("WARNING! .../cstz.c/fn_replace_logofsumsbt(): Expression inside log is negative and the function returns the negative sign!\n"); + *yold = log(fabs(tmpd)) + ynew; + return (-1.0); + } + else { + *yold = log(tmpd) + ynew; + return (1.0); + } + } +} + + + + + +//<<--------------- +// Evaluating the inverse of the chi-square cumulative distribution function. +//--------------->> +#if defined( IMSL_STATISTICSTOOLBOX ) +double fn_chi2inv(double p, double df) +{ + //Returns x where p = int_{0}^{x} chi2pdf(t, df) dt + if (df<=0.0) fn_DisplayError("cstz.c/fn_chi2inv(): degrees of freedom df must be greater than 0.0"); + + if (p<=0.0) return (0.0); + else if (p>=1.0) return (MACHINEINFINITY); + else return (imsls_d_chi_squared_inverse_cdf(p, df)); +} +#else + ***No default routine yet; +#endif + + +//<<--------------- +// Evaluating the standard normal cumulative distribution function. +//--------------->> +#if defined( IMSL_STATISTICSTOOLBOX ) +double fn_normalcdf(double x) +{ + return (imsls_d_normal_cdf(x)); +} +#else + ***No default routine yet; +#endif + +//<<--------------- +// Evaluating the inverse of the standard normal cumulative distribution function. +//--------------->> +#if defined( IMSL_STATISTICSTOOLBOX ) +double fn_normalinv(double p) +{ + return (imsls_d_normal_inverse_cdf(p)); +} +#else + ***No default routine yet; +#endif + + +//<<--------------- +// Evaluating the inverse of the beta cumulative distribution function. +//--------------->> +#if defined( IMSL_STATISTICSTOOLBOX ) +double fn_betainv(double p, double _alpha, double _beta) +{ + //p = int_{0}^{\infty} betapdf(t, _alpha, _beta) dt where betapdf(t,_alpha,_beta) \propt t^{_alpha-1}*(1-t)^(_beta-1}. + return (imsls_d_beta_inverse_cdf(p, _alpha, _beta)); +} +#else + ***No default routine yet; +#endif + + +//<<--------------- +// Computes log gamma (x) where gamma(n+1) = n! and gamma(x) = int_0^{\infty} e^{-t} t^{x-1} dt. +//--------------->> +#if defined( IMSL_STATISTICSTOOLBOX ) +double fn_gammalog(double x) +{ + return (imsl_d_log_gamma(x)); +} +#else +No default routine yet; +#endif + + +//<<--------------- +// Computes log beta(x, y) where beta(x, y) = gamma(x)*gamm(y)/gamma(x+y). +//--------------->> +#if defined( IMSL_STATISTICSTOOLBOX ) +double fn_betalog(double x, double y) +{ + return (imsl_d_log_beta(x, y)); +} +#else + ***No default routine yet; +#endif + + + +//<<--------------- +// Computes log gamma (x) where gamma(n+1) = n! and gamma(x) = int_0^{\infty} e^{-t} t^{x-1} dt. +//--------------->> +#if defined( IMSL_STATISTICSTOOLBOX ) +double gammalog(double x) +{ + return (imsl_d_log_gamma(x)); +} +#else +**No default routine yet; +#endif + + +//----------------------------------------------------------------------------------- +//------------------------------ Normal distribution ------------------------------// +//--- p(x) = (1.0/sqrt(2*pi)*sigma) exp( -(1.0/(2.0*sigma^2.0)) (x-mu)^2.0 ) +//--- for sigma>0. +//----------------------------------------------------------------------------------- +#define LOGSQRTOF2PI 9.189385332046727e-001 +double tz_lognormalpdf(double _x, double _m, double _s) +{ + double xmm = _x-_m; + if (_s <= 0.0) return (-NEARINFINITY); + //fn_DisplayError("cstz.c/tz_lognormalpdf(): standard deviation must be positive"); + + return ( -LOGSQRTOF2PI - log(_s) - (1.0/(2.0*square(_s))) * square(xmm) ); +} +#undef LOGSQRTOF2PI + +//----------------------------------------------------------------------------------- +//----------------------------- Beta density function -----------------------------// +//--- p(x) = ( Gamma(a+b)/(Gamma(a)*Gamma(b)) ) x^(a-1) (1-x)^(b-1) for a>0 and b>0. +//--- E(x) = a/(a+b); var(x) = a*b/( (a+b)^2*(a+b+1) ); +//--- The density is finite if a,b>=1. +//--- Noninformative density: (1) a=b=1; (2) a=b=0.5; or (3) a=b=0. +//----------------------------------------------------------------------------------- +double tz_logbetapdf(double _x, double _a, double _b) +{ + if ((_x < 0.0) || (_x > 1.0) || (_a <=0.0) || (_b <= 0.0)) return (-NEARINFINITY); + if ((_x <= 0.0) && (_a != 1.0)) return (-NEARINFINITY); + //Note that it should be +infinity for a < 1.0. We return -infinity anyway for the purpose of giving zero LH. + if ((_x >= 1.0) && (_b != 1.0)) return (-NEARINFINITY); + //Note that it should be +infinity for b < 1.0. We return -infinity anyway for the purpose of giving zero LH. + //fn_DisplayError("cstz.c/tz_logbetapdf(): x must be (0,1) and a, b must be positive"); + + if ((_x == 0.0 && _a == 1.0) || (_x == 1.0 && _b == 1.0)) return (-fn_betalog(_a, _b)); + else return ( -fn_betalog(_a, _b) + (_a-1.0)*log(_x) + (_b-1.0)*log(1.0-_x) ); +} +//----------------------------------------------------------------------------------- +//---------------------------- Gamma distribution ----------------------------------// +//--- p(x) = ( b^a/Gamma(a) ) x^(a-1) exp(-bx) for a>0 and b>0. +//--- where a is shape and b is inverse scale (rate) parameter. +//--- E(x) = a/b; var(x) = a/b^2; +//--- Noninformative distribution: a,b -> 0. +//--- The density function is finite if a >= 1. +//----------------------------------------------------------------------------------- +double tz_loggammapdf(double _x, double _a, double _b) +{ + if (_x < 0.0 || _a <= 0.0 || _b <= 0.0) return (-NEARINFINITY); + if (_x <= 0.0 && _a != 1.0) return (-NEARINFINITY); + //Note that it should be +infinity for a < 1.0. We return -infinity anyway for the purpose of giving zero LH. + //fn_DisplayError("cstz.c/tz_loggammapdf(): x, a, and b must be positive"); + + if (_x == 0.0 && _a == 1.0) return ( _a*log(_b) - fn_gammalog(_a) ); + else return ( _a*log(_b) - fn_gammalog(_a) + (_a-1.0)*log(_x) - _b*_x ); +} +//----------------------------------------------------------------------------------- +//------------------------ Inverse-Gamma distribution ------------------------------// +//--- p(x) = ( b^a/Gamma(a) ) x^(-a-1) exp(-b/x) for a>0 and b>0. +//--- where a is shape and b is scale parameter. +//--- E(x) = b/(a-1) for a>1; var(x) = b^2/( (a-1)^2*(a-2) ) for a>2; +//--- Noninformative distribution: a,b -> 0. +//--- How to draw: (1) draw z from Gamma(a,b); (2) let x=1/z. +//----------------------------------------------------------------------------------- +double tz_loginversegammapdf(double _x, double _a, double _b) +{ + //This denisity is always finite. + //If a < 1.0, 1st moment does not exist, + // a < 2.0, 2nd moment does not exist, + // a < 3.0, 3rd moment does not exist, + // a < 4.0, 4th moment does not exist. + + if (_x < 0.0 || _a <= 0.0 || _b <= 0.0) return (-NEARINFINITY); + //fn_DisplayError("cstz.c/tz_loginversegammapdf(): x, a, and b must be positive"); + + return ( _a*log(_b) - fn_gammalog(_a) - (_a+1.0)*log(_x) - _b /_x ); +} + + + + + + + +//<<--------------- +// P2 algorithm ??????? +//--------------->> +void psqr(double *q, int *m, double x, const double *p, int n) +{ + //Outputs: + // q: n-by-1 vector of + // m: n-by-1 vector of + // x: a random draw. + //------ + //Inputs: + // p: n-by-1 vector of cumulative cut-off probabilties for the error bands. + static double qm, dq; + static int i, dm, dn; + + for (i=0; q[i]<=x && i<n; i++) ; + if (i==0) { q[0]=x; i++; } + if (i==n) { q[n-1]=x; i--; } + for (; i<n; i++) m[i]++; + for (i=1; i<n-1; i++) { + dq = p[i]*m[n-1]; + if (m[i]+1<=dq && (dm=m[i+1]-m[i])>1) { + dn = m[i]-m[i-1]; + dq = ((dn+1)*(qm=q[i+1]-q[i])/dm+ + (dm-1)*(q[i]-q[i-1])/dn)/(dm+dn); + if (qm<dq) dq = qm/dm; + q[i] += dq; + m[i]++; + } else + if (m[i]-1>=dq && (dm=m[i]-m[i-1])>1) { + dn = m[i+1]-m[i]; + dq = ((dn+1)*(qm=q[i]-q[i-1])/dm+ + (dm-1)*(q[i+1]-q[i])/dn)/(dm+dn); + if (qm<dq) dq = qm/dm; + q[i] -= dq; + m[i]--; + } + } +} +void piksrt(double *arr, int n) +{ + //Outputs: + // arr: replaced by new values. + //Inputs: + // arr: n-by-1 vector ?????? + int i, j; + double a; + + for (j=1; j<n; j++) { + a = arr[j]; + for (i=j-1; i>=0 && arr[i]>a; i--) + arr[i+1] = arr[i]; + arr[i+1]=a; + } +} + + + +//---------------------------- Some high-level VAR functions --------------------- +void fn_lev2growthanual(TSdmatrix *levgro_dm, const TSdmatrix *levgrominus1_dm, const TSivector *indxlogper_iv) +{ + //******* It is the user's responsibility to check memory allocations and dimensions of inputs. ******* + //Outputs: + // levgro_dm: nfores-by-nvar matrix of annual growth rates (percent) except interest rates and unemployment rate in level. + //Inputs: + // levgro_dm: nfores-by-nvar matrix of log levels and, say, interest rates already divided by 100. + // levgrominus1_dm: qm-by-nvar matrix in the previous year (not necessarily a calendar year). + // indxlogper_iv: nvar-by-1 array of 1, 2, or 4 for the list of endogenous variables. 1: decimal point with annual rate like the interest rate; 2: decimal point (NOT at annual rate) like the unemployment rate; 4: log level value. + int ti, vj, qm, nvar, nfores, totrows; + TSdmatrix *tf_levgroplus_dm = NULL; + + if ((qm=levgrominus1_dm->nrows) != 12 && qm != 4) fn_DisplayError("fn_lev2growthanual(): the second input must have 12 or 4 rows for monthly or quarterly data"); + if ((nvar=levgrominus1_dm->ncols) != indxlogper_iv->n || nvar != levgro_dm->ncols) fn_DisplayError("fn_lev2growthanual(): column dimensions and vector dimension of all inputs must be same"); + + //=== Memory allocation for this function. + tf_levgroplus_dm = CreateMatrix_lf(qm+(nfores=levgro_dm->nrows), nvar=levgrominus1_dm->ncols); + + + CopySubmatrix0(tf_levgroplus_dm, (TSdmatrix *)levgrominus1_dm, 0, 0, qm, nvar); + CopySubmatrix(tf_levgroplus_dm, qm, 0, levgro_dm, 0, 0, nfores, nvar); + totrows = qm + nfores; + for (vj=nvar-1; vj>=0; vj--) { + switch (indxlogper_iv->v[vj]) { + case 4: + for (ti=nfores-1; ti>=0; ti--) + levgro_dm->M[mos(ti, vj, nfores)] = 100.0*( exp(tf_levgroplus_dm->M[mos(ti+qm, vj, totrows)] - tf_levgroplus_dm->M[mos(ti, vj, totrows)]) - 1.0 ); + break; + case 2: + case 1: + for (ti=nfores-1; ti>=0; ti--) + levgro_dm->M[mos(ti, vj, nfores)] *= 100.0; + break; + default: + fn_DisplayError("fn_lev2growthanual(): the input vector, indxlogper_iv, must have the integer values 4, 2, and 1"); + } + } + + + + //=== Destroys memory allocated for this function. + tf_levgroplus_dm = DestroyMatrix_lf(tf_levgroplus_dm); +} + + + +//------------------- +// Generating a counterfactual paths conditional on S_T and specified shocks_t(s_t) for _sm (a switching model). +//------------------- +void fn_ctfals_givenshocks_sm(TSdmatrix *ctfalstran_dm, TSdvector *xprimeminus1_dv, const int bloc, const int eloc, const TSdmatrix *strshockstran_dm, + const TSivector *S_Tdraw_iv, const TSdcell *Bsdraw_dc, const TSdcell *A0sdrawinv_dc, const TSivector *noshocks_iv) +{ + //******* It is the user's responsibility to check memory allocations and dimensions of inputs. ******* + //Outputs: ctflasdrawtran = xprimeminus1*Bsdraw{s} + shocks'*A0sdrawinv{s}. + // ctfalstran_dm: nvar-by-nfores where nfores (=eloc-bloc+1) is the forecast horizon. Conterfactual paths of nvar variables. + // xprimeminus1_dv: updated 1-by-ncoef right-hand-side variables at the end of the forecast horizon, ready for the forecasts at the step nfores+1. + // In the order of [nvar for 1st lag, ..., nvar for last lag, other exogenous terms, const term]. + //Inputs: + // xprimeminus1_dv: 1-by-ncoef vector of right-hand-side variables at the beginning of the forecast horizon. + // bloc: beginning location for the forecast horizon. + // eloc: end location for the forecast horizon. + // strshockstran_dm: nvar-by-T. Matrix transpose of unit-variance (time-invariant) structural shocks. + // S_Tdraw_iv: fss-by-1 or SampleSize-by-1 vector of (s_t|I_T,theta). + // Bsdraw_dc: nStates cells. For each cell, ncoef-by-nvar reduced-form coefficient matrix. + // A0sdrawinv_dc: nStates cells. For each cell, nvar-by-nvar inverse of contemporaneous coefficient matrix. + // noshocks_iv: a (no greater than nvar) vector of base-0 integers indicating the corresponding equations whose shocks are set + // to zero. Each element of this integer vector must be less than nvar. + int ti, si, vi; + int nfores = eloc - bloc + 1, + nvar = ctfalstran_dm->nrows, + ncoefminusnvar7const = Bsdraw_dc->C[0]->nrows - nvar - 1; + TSdvector ctfals_sdv, strshocks_sdv; + TSivector STnfores_siv; //nfores-by-1 vector of s_t's. + + if (nfores < 1) fn_DisplayError("cstz.c/fn_ctfals_givenshocks_sm(): Number of forecast steps must be greater than 0"); + if (eloc > strshockstran_dm->ncols-1) fn_DisplayError("cstz.c/fn_ctfals_givenshocks_sm(): End location in the forecast horizon must be no greater than the sample size"); + if (nvar != strshockstran_dm->nrows) fn_DisplayError("cstz.c/fn_ctfals_givenshocks_sm(): the number of rows of strshockstran_dm must be equal to nvar"); + + + //******* WARNING: The operation involves ctfals_sdv.v, strshocks_sdv.v, STnfores_siv.v ******* + //******* throughout this function is dangerous because of pointer movements. ******* + //******* But it gives us efficiency. ******* + ctfals_sdv.n = nvar; + ctfals_sdv.v = ctfalstran_dm->M; //Points to the beginning of the 1st column of ctfalstran_dm. + //+ + strshocks_sdv.n = nvar; + strshocks_sdv.flag = V_DEF; + strshocks_sdv.v = strshockstran_dm->M + strshockstran_dm->nrows*bloc; //Points to the beginning of the bloc_th column of strshockstran_dm. + for (vi=noshocks_iv->n-1; vi>=0; vi--) + strshocks_sdv.v[noshocks_iv->v[vi]] = 0.0; //Set shocks in those equations to be zero. + //+ + STnfores_siv.n = nfores; + STnfores_siv.flag = V_DEF; + STnfores_siv.v = S_Tdraw_iv->v + bloc; //Points to the bloc_th position of S_Tdraw_iv. + + + for (ti=0; ti<nfores; ti++) { + //Must have a forward recursion. + VectorTimesMatrix(&ctfals_sdv, xprimeminus1_dv, Bsdraw_dc->C[si=STnfores_siv.v[ti]], 1.0, 0.0, 'N'); + VectorTimesMatrix(&ctfals_sdv, &strshocks_sdv, A0sdrawinv_dc->C[si], 1.0, 1.0, 'N'); + //=== Updates the recursion. The order matters. + memmove(xprimeminus1_dv->v+nvar, xprimeminus1_dv->v, ncoefminusnvar7const*sizeof(double)); + memcpy(xprimeminus1_dv->v, ctfals_sdv.v, nvar*sizeof(double)); + //+ + if (ti < nfores-1) //This is needed to prevent memory leak at the end when we have strshocks_sdv.v[noshocks_iv->v[vi]] = 0.0. + { + ctfals_sdv.v += nvar; //Points to the beginning of the next column of ctfalstran_dm. + strshocks_sdv.v += nvar; //Points to the beginning of the next column of strshockstran_dm. + for (vi=noshocks_iv->n-1; vi>=0; vi--) + strshocks_sdv.v[noshocks_iv->v[vi]] = 0.0; //Set shocks in those equations to be zero. + } + } + + ctfalstran_dm->flag = M_GE; +} + + +//------------------- +// Generating a random sequence of counterfactual (ctfal) paths for _sm (a switching model). +//------------------- +void fn_ctfals_sm(TSdmatrix *ctfalstran_dm, TSdvector *xprimeminus1_dv, const int bloc, const int eloc, const TSdmatrix *strshockstran_dm, const TSivector *Snfores_iv, const TSdcell *Bsdraw_dc, const TSdcell *A0sdrawinv_dc) +{ + //******* It is the user's responsibility to check memory allocations and dimensions of inputs. ******* + //Outputs: ctflasdrawtran = xprimeminus1*Bsdraw{s} + shocks'*A0sdrawinv{s}. + // ctfalstran_dm: nvar-by-nfores where nfores (=eloc-bloc+1) is the forecast horizon. Conterfactual paths of nvar variables. + // xprimeminus1_dv: updated 1-by-ncoef right-hand-side variables at the end of the forecast horizon, ready for the forecasts at the step nfores+1. + // In the order of [nvar for 1st lag, ..., nvar for last lag, other exogenous terms, const term]. + //Inputs: + // xprimeminus1_dv: 1-by-ncoef vector of right-hand-side variables at the beginning of the forecast horizon. + // bloc: beginning location for the forecast horizon. + // eloc: end location for the forecast horizon. + // strshockstran_dm: nvar-by-T. Matrix transpose of unit-variance (time-invariant) structural shocks. + // Snfores_iv: nfores-by-1 vector of states where each element is less than nStates. + // Bsdraw_dc: nStates cells. For each cell, ncoef-by-nvar reduced-form coefficient matrix. + // A0sdrawinv_dc: nStates cells. For each cell, nvar-by-nvar inverse of contemporaneous coefficient matrix. + int ti, si; + int nfores = eloc - bloc + 1, + nvar = ctfalstran_dm->nrows, + ncoefminusnvar7const = Bsdraw_dc->C[0]->nrows - nvar - 1; + TSdvector ctfals_sdv, strshocks_sdv; + + if (nfores < 1) fn_DisplayError("cstz.c/fn_ctfals_sm(): Number of forecast steps must be greater than 0"); + if (eloc > strshockstran_dm->ncols-1) fn_DisplayError("cstz.c/fn_ctfals_sm(): End location in the forecast horizon must be no greater than the sample size"); + if (nvar != strshockstran_dm->nrows) fn_DisplayError("cstz.c/fn_ctfals_sm(): the number of rows of strshockstran_dm must be equal to nvar"); + + + //******* WARNING: The operation involves ctfals_sdv.v and strshocks_sdv.v throughout this function ******* + //******* is dangerous because of pointer movements. But it gives us efficiency. ******* + ctfals_sdv.n = nvar; + ctfals_sdv.v = ctfalstran_dm->M; //Points to the beginning of the 1st column of ctfalstran_dm. + strshocks_sdv.n = nvar; + strshocks_sdv.flag = V_DEF; + strshocks_sdv.v = strshockstran_dm->M + strshockstran_dm->nrows*bloc; //Points to the beginning of the bloc_th column of strshockstran_dm. + + + for (ti=0; ti<nfores; ti++) { + //Must have a forward recursion. + VectorTimesMatrix(&ctfals_sdv, xprimeminus1_dv, Bsdraw_dc->C[si=Snfores_iv->v[ti]], 1.0, 0.0, 'N'); + VectorTimesMatrix(&ctfals_sdv, &strshocks_sdv, A0sdrawinv_dc->C[si], 1.0, 1.0, 'N'); + //=== Updates the recursion. The order matters. + memmove(xprimeminus1_dv->v+nvar, xprimeminus1_dv->v, ncoefminusnvar7const*sizeof(double)); + memcpy(xprimeminus1_dv->v, ctfals_sdv.v, nvar*sizeof(double)); + //+ + ctfals_sdv.v += nvar; //Points to the beginning of the next column of ctfalstran_dm. + strshocks_sdv.v += nvar; //Points to the beginning of the next column of strshockstran_dm. + } + + ctfalstran_dm->flag = M_GE; +} + +//------------------- +// Generating a random sequence of counterfactual (ctfal) paths with only monetary policy equation changing to a specified regime while holding other equations' regimes the same as historical ones. +//------------------- +void fn_ctfals_policyonly(TSdmatrix *ctfalstran_dm, TSdvector *xprimeminus1_dv, const int bloc, const int eloc, const TSdmatrix *strshockstran_dm, const TSivector *S_Tdraw_iv, const int statecon, const int selej, const TSdcell *A0sdraw_dc, const TSdcell *Apsdraw_dc) +{ + //******* It is the user's responsibility to check memory allocations and dimensions of inputs. ******* + //Outputs: ctflasdrawtran = xprimeminus1*Bsdraw{s} + shocks'*A0sdrawinv{s}. + // ctfalstran_dm: nvar-by-nfores where nfores (=eloc-bloc+1) is the forecast horizon. Conterfactual paths of nvar variables. + // xprimeminus1_dv: updated 1-by-ncoef right-hand-side variables at the end of the forecast horizon, ready for the forecasts at the step nfores+1. + // In the order of [nvar for 1st lag, ..., nvar for last lag, other exogenous terms, const term]. + //Inputs: + // xprimeminus1_dv: 1-by-ncoef vector of right-hand-side variables at the beginning of the forecast horizon. + // bloc: beginning location for the forecast horizon. + // eloc: end location for the forecast horizon. + // strshockstran_dm: nvar-by-T. Matrix transpose of unit-variance (time-invariant) structural shocks. + // S_Tdraw_iv; fss-by-1 or SampleSize-by-1. Stores (s_t|I_T,theta). + // statecon: the ith state conditioned for counterfactuals (base 0). Must be < nStates. + // selej: location (base 0) of the selected structural equation (e.g., the monetary policy equation). Only for (1) long-run and short-run responses and (2) counterfactuals with only policy equation at specific state imposed. + // A0sdraw_dc: nStates cells. For each cell, nvar-by-nvar contemporaneous coefficient matrix. + // Apsdraw_dc: nStates cells. For each cell, ncoef-by-nvar lagged structural coefficient matrix. + int ti, si; + int errflag = -2, //Initialized to be unsuccessful. When 0, successful. + nfores = eloc - bloc + 1, + nvar = ctfalstran_dm->nrows, + ncoef = Apsdraw_dc->C[0]->nrows, + nStates = Apsdraw_dc->ncells, + ncoefminusnvar7const = ncoef - nvar - 1; + TSdvector ctfals_sdv, strshocks_sdv; + TSivector sact_nfores_siv; + // + TSivector *tf_rnstates_iv = CreateConstantVector_int(nStates, nvar), //nStates-by-1: ncoef for each element for *p*_dc or nvar for each elment for *0*_dc. + *tf_cnstates_iv = CreateConstantVector_int(nStates, nvar); //nStates-by-1: nvar for each element for both *p*_dc and *0*_dc. + TSdcell *tf_A0sinv_dc = NULL; + TSdcell *tf_Aps_dc = NULL, + *tf_Bs_dc = NULL; + + + + if (nfores < 1) fn_DisplayError("cstz.c/fn_ctfals_policyonly(): Number of forecast steps must be greater than 0"); + if (eloc > strshockstran_dm->ncols-1) fn_DisplayError("cstz.c/fn_ctfals_policyonly(): End location in the forecast horizon must be no greater than the sample size"); + if (nvar != strshockstran_dm->nrows) fn_DisplayError("cstz.c/fn_ctfals_policyonly(): the number of rows of strshockstran_dm must be equal to nvar"); + + + //=== Memory allocation. + tf_A0sinv_dc = CreateCell_lf(tf_rnstates_iv, tf_cnstates_iv); //Note rnstates_iv and cnstates_iv are already assigned right values. + //+ + for (si=nStates-1; si>=0; si--) tf_rnstates_iv->v[si] = ncoef; //Note rnstates_iv is already assigned right values. + tf_Aps_dc = CreateCell_lf(tf_rnstates_iv, tf_cnstates_iv); + tf_Bs_dc = CreateCell_lf(tf_rnstates_iv, tf_cnstates_iv); + + + //******* WARNING: The operation involves ctfals_sdv.v and strshocks_sdv.v throughout this function ******* + //******* is dangerous because of pointer movements. But it gives us efficiency. ******* + ctfals_sdv.n = nvar; + ctfals_sdv.v = ctfalstran_dm->M; //Points to the beginning of the 1st column of ctfalstran_dm. + strshocks_sdv.n = nvar; + strshocks_sdv.flag = V_DEF; + strshocks_sdv.v = strshockstran_dm->M + strshockstran_dm->nrows*bloc; //Points to the beginning of the bloc_th column of strshockstran_dm. + //+ + sact_nfores_siv.n = nfores; + sact_nfores_siv.flag = V_DEF; + sact_nfores_siv.v = S_Tdraw_iv->v + bloc; //Points to the beginning of the bloc_th element of S_Tdraw_iv. + + //=== Sticks the policy equation at the statecon_th state to A0s and A0p. + for (si=nStates-1; si>=0; si--) { + CopyMatrix0(tf_A0sinv_dc->C[si], A0sdraw_dc->C[si]); //tf_A0sinv_dc is A0s for a moment. + CopyMatrix0(tf_Aps_dc->C[si], Apsdraw_dc->C[si]); + //=== Sticks the specified regime statecon in the counterfactual period. + CopySubmatrix(tf_A0sinv_dc->C[si], 0, selej, A0sdraw_dc->C[statecon], 0, selej, nvar, 1); + CopySubmatrix(tf_Aps_dc->C[si], 0, selej, Apsdraw_dc->C[statecon], 0, selej, ncoef, 1); + + if ( errflag=BdivA_rgens(tf_Bs_dc->C[si], tf_Aps_dc->C[si], '/', tf_A0sinv_dc->C[si]) ) { + //tf_A0sinv_dc is at this moment tf_A0s_dc. + printf(".../cstz.c/fn_ctfals_policyonly(): tf_Bs_dc->C[si] -- errors when calling BdivA_rgens() with error flag %d", errflag); + exit(EXIT_FAILURE); + } + if ( errflag=invrgen(tf_A0sinv_dc->C[si], tf_A0sinv_dc->C[si]) ) { + printf(".../cstz.c/fn_ctfals_policyonly(): tf_A0sinv_dc->C -- errors when calling invrgen() with error flag %d", errflag); + exit(EXIT_FAILURE); + } + } + + for (ti=0; ti<nfores; ti++) { + //Must have a forward recursion. + VectorTimesMatrix(&ctfals_sdv, xprimeminus1_dv, tf_Bs_dc->C[si=sact_nfores_siv.v[ti]], 1.0, 0.0, 'N'); + VectorTimesMatrix(&ctfals_sdv, &strshocks_sdv, tf_A0sinv_dc->C[si], 1.0, 1.0, 'N'); + //=== Updates the recursion. The order matters. + memmove(xprimeminus1_dv->v+nvar, xprimeminus1_dv->v, ncoefminusnvar7const*sizeof(double)); + memcpy(xprimeminus1_dv->v, ctfals_sdv.v, nvar*sizeof(double)); + //+ + ctfals_sdv.v += nvar; //Points to the beginning of the next column of ctfalstran_dm. + strshocks_sdv.v += nvar; //Points to the beginning of the next column of strshockstran_dm. + } + + ctfalstran_dm->flag = M_GE; + + //=== Destroys memory allocated for this function. + tf_rnstates_iv = DestroyVector_int(tf_rnstates_iv); + tf_cnstates_iv = DestroyVector_int(tf_cnstates_iv); + tf_A0sinv_dc = DestroyCell_lf(tf_A0sinv_dc); + tf_Aps_dc = DestroyCell_lf(tf_Aps_dc); + tf_Bs_dc = DestroyCell_lf(tf_Bs_dc); +} + + +#if defined (INTELCMATHLIBRARY) +void fn_impulse(TSdmatrix *imftran_dm, const TSdmatrix *Bh_dm, const TSdmatrix *swishtran_dm, const int nlags, const int imsteps) +{ + //Outputs (memory allocated already): + // imftran_dm: nvar^2-by-imsteps where imf_dm (imsteps-by-nvar^2) is in the same format as in RATS. + // Rows: nvar responses to the 1st shock, ..., nvar responses to the last shock. + // Columns: steps of impulse responses. + //Inputs: + // Bh_dm: ldbh-by-nvar reduced-form coefficient matrix (where ldbh is the leading dimension of Bh_dm and must be at least nvar*nlags) of the form: + // Y(T*nvar) = X*Bh_dm + U, X: T*ldbh(ldbh may include all exogenous terms). Note that columns corresponding equations. + // Columns of Bh_dm: nvar variables for the 1st lag, ..., nvariables for the last lag + (possible exogenous terms) + const = ldbh. + // swishtran_dm: transponse of nvar-by-nvar inv(A0) in the structural model y(t)A0 = e(t). + // nlags: lag length (number of lags); + // imsteps: steps for impulse responses. + + int i, j, + nvar, nvar2, ldbh, jmax; + double *Bh, *imftran; + + if (!imftran_dm) fn_DisplayError(".../fn_impulse(): the output impulse matrix imftran_dm must be created (memory-allocated)"); + else if (!Bh_dm || !swishtran_dm) fn_DisplayError(".../fn_impulse(): the input matrices Bh_dm and swich_dm must be created (memory-allocated)"); + else if (!Bh_dm->flag || !swishtran_dm->flag) fn_DisplayError(".../fn_impulse(): the input matrices Bh_dm and swich_dm must be given legal values"); + else if (nlags < 1) fn_DisplayError(".../fn_impulse(): the lag length, nlags, must be equal to or greater than 1"); + else if (imsteps <1) fn_DisplayError(".../fn_impulse(): the number of steps for impulse responses, imsteps, must be must be equal to or greater than 1"); + else if ((nvar = swishtran_dm->nrows) != swishtran_dm->ncols ) fn_DisplayError(".../fn_impulse(): the input matrix, swishtran_dm, must be square"); + else if (nvar != Bh_dm->ncols) fn_DisplayError(".../fn_impulse(): the number of columns in Bh_dm must equal to the number of equations or endogenous variables"); + else if (square(nvar) != imftran_dm->nrows || imsteps != imftran_dm->ncols) fn_DisplayError(".../fn_impulse(): Dimension of impulse matrix input matrix imftran_dm is incompatible with other input matrices or with the number of steps"); + + //if ( !(imftran_dm->flag & M_CN) && imftran_dm[0] !=0.0 ) InitializeConstantMatrix_lf(imftran_dm, 0.0); + InitializeConstantMatrix_lf(imftran_dm, 0.0); //Cumulative. Always initialize it to zero. + + + nvar2 = square(nvar); + Bh = Bh_dm->M; + imftran = imftran_dm->M; + + + if ((ldbh=Bh_dm->nrows) < nvar*nlags) fn_DisplayError("Input matrix Bh_dm must have at least nvar*nlags rows"); + cblas_dcopy(nvar2, swishtran_dm->M, 1, imftran, 1); + for (i=1; i<imsteps; i++) { + jmax = i<nlags?i:nlags; + for (j=0; j<jmax; j++) { + cblas_dgemm(CblasColMajor, CblasTrans, CblasNoTrans, nvar, nvar, nvar, + 1.0, &Bh[j*nvar], ldbh, &imftran[(i-j-1)*nvar2], nvar, + 1.0, &imftran[i*nvar2], nvar); + } + } + + + imftran_dm->flag = M_GE; +} +#else +//No default routine yet. 7 Oct 2003 +#endif + + +TSdmatrix *tz_impulse2levels(TSdmatrix *imflev_dm, TSdmatrix *imf_dm, TSivector *vlist2levels_iv) +{ + //Converting imf_dm to the level impulse responses imflev_dm according to vlist2levels_iv. + //If imflev_dm = imf_dm, then the value of imf_dm will be replaced by the new value. + // + //imf_dm; nsteps-by-nvar^2 where + // rows: steps of impulse responses; + // columns: nvar responses to the 1st shock, ..., nvar responses to the last shock. + //vlist2levels_iv; must be in ascending order. A list of base-0 variables to be converted to levels. Example: [0 1 3] + int _i, _j, _t; + int largestvar; //last variable corresponding to the largest number. + int _n, nsq, imsteps; + TSdvector imf_sdv; + TSdvector imflev_sdv; + + if (!imf_dm || !imf_dm->flag) + fn_DisplayError(".../cstz.c/tz_impulse2levels(): the input matrix imf_dm must be (1) allocated memory and (2) given legal values"); + + if (!imflev_dm) { + imflev_dm = CreateMatrix_lf(imf_dm->nrows, imf_dm->ncols); + imflev_dm->flag = M_GE; //Legal values will be given below. + } + else if (imflev_dm != imf_dm ) + if ( (imflev_dm->nrows != imf_dm->nrows) || (imflev_dm->ncols != imf_dm->ncols)) + fn_DisplayError(".../cstz.c/tz_impulse2levels(): dimensions of the input matrix imf_dm and the output matrix imflev_dm must match exactly"); + else imflev_dm->flag = M_GE; //Legal values will be given below. + + largestvar = vlist2levels_iv->v[vlist2levels_iv->n-1]+1; + _n = (int)floor(sqrt(imf_dm->ncols)+0.5); + nsq = imf_dm->ncols; + if ( square(largestvar) > nsq) + fn_DisplayError(".../cstz.c/tz_impulse2levels(): the last specified variable in vlist2levels_iv is out of the range of impulse responses"); + + + imflev_sdv.n = imf_sdv.n = imf_dm->nrows; + imflev_sdv.flag = imf_sdv.flag = V_DEF; //Legal values will be given below. + imsteps = imf_dm->nrows; + for (_i=vlist2levels_iv->n-1; _i>=0; _i--) + for (_j=vlist2levels_iv->v[_i]; _j<nsq; _j += _n) { + imflev_sdv.v = imflev_dm->M + _j*imsteps; + imf_sdv.v = imf_dm->M + _j*imsteps; + imflev_sdv.v[0] = imf_sdv.v[0]; + for (_t=1; _t<imsteps; _t++) + imflev_sdv.v[_t] = imflev_sdv.v[_t-1] + imf_sdv.v[_t]; + } + + return (imflev_dm); +} + + +void DynamicResponsesForStructuralEquation(TSdmatrix *Resps_dm, const int loclv, const int nlags, const TSdvector *a0p_dv) +{ + //Outputs: + // Resps_dm: k-by-nvar where k responses of the loclv_th variable to the _ith variable for _i=1:nvar. + // The loclv_th column of Resps_dm is meaningless but as a debug check should be close to -1 for the kth responses as k->\infty. + //Inputs: + // loclv: loction of the left-hand variable either in difference (growth) or level. + // nlags: number of lags. + // a0p_dv: m-by-1 vector of [a0 a+] either in difference (growth) or level for the strctural equation considered where m>= (nlags+1)*nvar because m may + // include the constant term. Note a0 is on the left hand side of the equation and a+ is on the right hand side of the equation. + int vi, li; + int nvar, K; + double tmpdsum, c0, a0inv; + TSdvector resps_sdv; //k-by-1. + //---- + TSdvector *a1_dv = NULL; //nlags-by-1. + + if (!Resps_dm || !a0p_dv || !a0p_dv->flag) fn_DisplayError(".../cstz/DynamicResponsesForStructuralEquation(): (1) both input vector and output matrix must be allocated memory; (2) the input vector must have legal values"); + if (a0p_dv->n < (nlags+1)*(nvar=Resps_dm->ncols)) fn_DisplayError(".../cstz/DynamicResponsesForStructuralEquation(): the length of the input vector must be at least (nvar+1)*nlags"); + if (loclv >= nvar || loclv < 0) fn_DisplayError(".../cstz/DynamicResponsesForStructuralEquation(): the location for the left-hand-side variable must be between 0 and number of variables-1, inclusive"); + a1_dv = CreateVector_lf(nlags); + a1_dv->flag = V_DEF; //which will be given legal values below. + + resps_sdv.n = K = Resps_dm->nrows; + resps_sdv.flag = V_UNDEF; + + a0inv = 1.0/a0p_dv->v[loclv]; + for (li=nlags; li>=1; li--) //Note li=1; li<=nlags, NOT li=0; li<nlags. + a1_dv->v[li-1] = a0p_dv->v[loclv+nvar*li]*a0inv; + //Constructing the lagged coefficients for the loclv_th variable. + for (vi=nvar-1; vi>=0; vi--) { + //=== Constructing the constant term. + tmpdsum = - a0p_dv->v[vi]; //Assigned to -a_0. + for (li=nlags; li>=1; li--) //Note li=1; li<=nlags, NOT li=0; li<nlags. + tmpdsum += a0p_dv->v[vi+nvar*li]; + c0 = tmpdsum*a0inv; + //Done with t* array. + + //=== Getting dynamic responses to the vi_th variable. + resps_sdv.v = Resps_dm->M + vi*K; + DynamicResponsesAR(&resps_sdv, c0, a1_dv); + } + Resps_dm->flag = M_GE; + + + //=== Destroys memory allocated for this function only. + a1_dv = DestroyVector_lf(a1_dv); +} + + + +void DynamicResponsesAR(TSdvector *resps_dv, const double c0, const TSdvector *a1_dv) +{ + //Outputs: + // resps_dv: k-by-1 where k responses r_{t+1} to r_{t+k} are computed from r_{t+1} = c0 + a1'*[r_t; ...; r_{t-nlags+1}]. + //Inputs: + // c0: constant term. + // a1_dv: nlags-by-1 vector of coefficients in the AR process. + int ti; + int k, nlags; + double *rv; + TSdvector *rlags_dv = NULL; + + if (!resps_dv || !a1_dv || !a1_dv->flag) fn_DisplayError(".../cstz/DynamicResponsesAR(): (1) both input and output vectors must be allocated memory; (2) the input vector must have legal values"); + rlags_dv = CreateConstantVector_lf(nlags=a1_dv->n, 0.0); + + rv = resps_dv->v; + k = resps_dv->n; + + *(rlags_dv->v) = *rv = c0; + + + for (ti=1; ti<k; ti++) { + //Note ti=1, NOT ti=0. + rv[ti] = c0 + VectorDotVector((TSdvector *)a1_dv, rlags_dv); + //=== Updating rlags_dv. + memmove(rlags_dv->v+1, rlags_dv->v, (nlags-1)*sizeof(double)); + *(rlags_dv->v) = rv[ti]; + } + resps_dv->flag = V_DEF; + + //=== Destroys memory allocated for this function only. + rlags_dv = DestroyVector_lf(rlags_dv); +} + + + + + +//---------------------------- Some regular vector or matrix operations --------------------- +double MinVector_lf(TSdvector *x_dv) { + //Input: no change for x_dv in this function. + int _i, n; + double minvalue; + double *v; + + if (!x_dv || !x_dv->flag) fn_DisplayError(".../cstz.c/MinVector_lf(): Input vector x_dv must be (1) allocated memory and (2) assigned legal values"); + n = x_dv->n; + v = x_dv->v; + + minvalue = v[0]; + for (_i=n-1; _i>0; _i--) + if (v[_i]<minvalue) minvalue = v[_i]; + + return( minvalue ); +} + +TSdvector *ConvertVector2exp(TSdvector *y_dv, TSdvector *x_dv) +{ + //y=exp(x): output vector. If NULL, y will be created and memory-allocated. + //x: input vector. + TSdvector *z_dv=NULL; + #if !defined (INTELCMATHLIBRARY) + int _i; + #endif + + + if (!x_dv || !x_dv->flag) fn_DisplayError(".../cstz.c/ConvertVector2exp(): input vector must be (1) created and (2) given legal values"); + + #if defined (INTELCMATHLIBRARY) + + if (!y_dv) + { + z_dv = CreateVector_lf(x_dv->n); + vdExp(x_dv->n, x_dv->v, z_dv->v); + z_dv->flag = V_DEF; + return (z_dv); + } + else if (x_dv!=y_dv) + { + vdExp(x_dv->n, x_dv->v, y_dv->v); + y_dv->flag = V_DEF; + return (y_dv); + } + else + { + z_dv = CreateVector_lf(x_dv->n); + vdExp(x_dv->n, x_dv->v, z_dv->v); + z_dv->flag = V_DEF; + CopyVector0(x_dv, z_dv); + DestroyVector_lf(z_dv); + return (x_dv); + } + + #else + + if (!y_dv) z_dv = CreateVector_lf(x_dv->n); + else z_dv = y_dv; + for (_i=x_dv->n-1; _i>=0; _i--) z_dv->v[_i] = exp(x_dv->v[_i]); + z_dv->flag = V_DEF; + return (z_dv); + + #endif +} +//--- +TSdvector *ConvertVector2log(TSdvector *y_dv, TSdvector *x_dv) +{ + //y=log(x): output vector. If NULL, y will be created and memory-allocated. + //x: input vector. + TSdvector *z_dv=NULL; + #if !defined (INTELCMATHLIBRARY) + int _i; + #endif + + + if (!x_dv || !x_dv->flag) fn_DisplayError(".../cstz.c/ConvertVector2exp(): input vector must be (1) created and (2) given legal values"); + + #if defined (INTELCMATHLIBRARY) + + if (!y_dv) + { + z_dv = CreateVector_lf(x_dv->n); + vdLn(x_dv->n, x_dv->v, z_dv->v); + z_dv->flag = V_DEF; + return (z_dv); + } + else if (x_dv!=y_dv) + { + vdLn(x_dv->n, x_dv->v, y_dv->v); + y_dv->flag = V_DEF; + return (y_dv); + } + else + { + z_dv = CreateVector_lf(x_dv->n); + vdLn(x_dv->n, x_dv->v, z_dv->v); + z_dv->flag = V_DEF; + CopyVector0(x_dv, z_dv); + DestroyVector_lf(z_dv); + return (x_dv); + } + + #else + + if (!y_dv) z_dv = CreateVector_lf(x_dv->n); + else z_dv = y_dv; + for (_i=x_dv->n-1; _i>=0; _i--) z_dv->v[_i] = log(x_dv->v[_i]); + z_dv->flag = V_DEF; + return (z_dv); + + #endif +} + +double tz_normofvector(TSdvector *x_dv, double p) +{ + double norm = 0.0; + int ki, _n; + double *v; + + if ( !x_dv || !x_dv->flag ) fn_DisplayError("/cstz.c/tz_normofvector(): Input x_dv must have (1) memory and (2) legal values"); + if (p<1.0) fn_DisplayError("/cstz.c/tz_normofvector(): The input p must be no less than 1.0"); + _n = x_dv->n; + v = x_dv->v; + + if (p==2.0) + { + for (ki=_n-1; ki>=0; ki--) norm += v[ki]*v[ki]; + norm = sqrt(norm); + } + else + { + printf("\n/cstz.c/tz_normofvector(): HELLO I TRICK YOU and YOU MUST DO fabs(p-2.0)<MICHINEZERO!!!!!!\n"); //???? + if (p==1.0) + for (ki=_n-1; ki>=0; ki--) norm += fabs(v[ki]); + else + { + for (ki=_n-1; ki>=0; ki--) norm += pow(fabs(v[ki]), p); + norm = pow(norm, 1.0/p); + } + } + + return (norm); +} + + + +//---------------------------- Not used often --------------------- +void fn_cumsum(double **aos_v, int *aods_v, double *v, int d_v) { + // Compute a cumulative sum of a vector. + // + // v: an n-by-1 vector. + // d_v: n -- size of the vector v to be used for a cumulative sum. + // aos_v: address of the pointer to the n-by-1 vector s_v. + // aods_v: address of the size of the dimension of s_v. + //---------- + // *aos_v: An n-by-1 vector of cumulative sum s_v. + // *aods_v: n -- size of the dimension for s_v. + + int ki; + + *aos_v = tzMalloc(d_v, double); + (*aods_v) = d_v; // n for the n-by-1 vector s_v. + *(*aos_v) = *v; + if (d_v>1) { + for (ki=1; ki<d_v; ki++) (*aos_v)[ki] = (*aos_v)[ki-1] + v[ki]; + } +} + + + +/** +void fn_ergodp(double **aop, int *aod, mxArray *cp) { + // Compute the ergodic probabilities. See Hamilton p.681. + // + // cp: n-by-n Markovian transition matrix. + // aop: address of the pointer to the n-by-1 vector p. + // aod: address of the size of the dimension of p. + //---------- + // *aop: n-by-1 vector of ergodic probabilities p. @@Must be freed outside this function.@@ + // *aod: n -- size of the dimension for p (automatically supplied within this function). + + mxArray *gpim=NULL, *gpid=NULL; // m: n-by-n eigvector matrix; d: n-by-n eigvalue diagonal. + double *gpim_p, *gpid_p; // _p: a pointer to the corresponding mxArray whose name occurs before _p. + //------- Note the following two lines will cause Matlab or C to crash because gpim has not been initialized so it points to garbage. + // double *gpim_p = mxGetPr(gpim); + // double *gpid_p = mxGetPr(gpid); + int eigmaxindx, // Index of the column corresponding to the max eigenvalue. + n, ki; + double gpisum=0.0, + eigmax, tmpd0; + + n=mxGetM(cp); // Get n for the n-by-n mxArray cp. + (*aod)=n; + + *aop = tzMalloc(n, double); + + gpim = mlfEig(&gpid,cp,NULL,NULL); + gpim_p = mxGetPr(gpim); + gpid_p = mxGetPr(gpid); + + eigmax = *gpid_p; + eigmaxindx = 0; + if (n>1) { + for (ki=1;ki<n;ki++) { + if (gpid_p[n*ki+ki] > eigmax) { + eigmax=gpid_p[n*ki+ki]; + eigmaxindx=ki; + } // Note that n*ki+ki refers to a diagonal location in the n-by-n matrix. + } + } + for (ki=0;ki<n;ki++) { + gpisum += gpim_p[n*eigmaxindx+ki]; // Sum over the eigmaxindx_th column. + } + tmpd0 = 1.0/gpisum; + for (ki=0;ki<n;ki++) { + (*aop)[ki] = gpim_p[n*eigmaxindx+ki]*tmpd0; // Normalized eigmaxindx_th column as ergodic probabilities. + } + + mxDestroyArray(gpim); // ????? free(gpim_p) + mxDestroyArray(gpid); +} +/**/ + + + +//---------- Must keep the following code forever. --------------- +/** +TSdp2m5 *CreateP2m5(const double p) +{ + TSdp2m5 *x_dp2m5 = tzMalloc(1, TSdp2m5); + + if (p<=0.0 && p>=1.0) fn_DisplayError(".../cstz.c/CreateP2m5_lf(): input probability p must be between 0.0 and 1.0"); + + x_dp2m5->cnt = 0; + x_dp2m5->ndeg = 0; + x_dp2m5->p = tzMalloc(5, double); + x_dp2m5->q = tzMalloc(5, double); + x_dp2m5->m = tzMalloc(5, int); + + x_dp2m5->p[0] = 0.00; + x_dp2m5->p[1] = 0.5*p; + x_dp2m5->p[2] = p; + x_dp2m5->p[3] = 0.5*(1.0+p); + x_dp2m5->p[4] = 1.00; + + return (x_dp2m5); +} +TSdp2m5 *DestroyP2m5(TSdp2m5 *x_dp2m5) +{ + if (x_dp2m5) { + free(x_dp2m5->m); + free(x_dp2m5->q); + free(x_dp2m5->p); + + free(x_dp2m5); + return ((TSdp2m5 *)NULL); + } + else return (x_dp2m5); +} +TSdvectorp2m5 *CreateVectorP2m5(const int n, const double p) +{ + int _i; + // + TSdvectorp2m5 *x_dvp2m5 = tzMalloc(1, TSdvectorp2m5); + + x_dvp2m5->n = n; + x_dvp2m5->v = tzMalloc(n, TSdp2m5 *); + for (_i=n-1; _i>=0; _i--) + x_dvp2m5->v[_i] = CreateP2m5(p); + + return (x_dvp2m5); +} +TSdvectorp2m5 *DestroyVectorP2m5(TSdvectorp2m5 *x_dvp2m5) +{ + int _i; + + if (x_dvp2m5) { + for (_i=x_dvp2m5->n-1; _i>=0; _i--) + x_dvp2m5->v[_i] = DestroyP2m5(x_dvp2m5->v[_i]); + free(x_dvp2m5->v); + + free(x_dvp2m5); + return ((TSdvectorp2m5 *)NULL); + } + return (x_dvp2m5); +} +TSdmatrixp2m5 *CreateMatrixP2m5(const int nrows, const int ncols, const double p) +{ + int _i; + // + TSdmatrixp2m5 *X_dmp2m5 = tzMalloc(1, TSdmatrixp2m5); + + X_dmp2m5->nrows = nrows; + X_dmp2m5->ncols = ncols; + X_dmp2m5->M = tzMalloc(nrows*ncols, TSdp2m5 *); + for (_i=nrows*ncols-1; _i>=0; _i--) + X_dmp2m5->M[_i] = CreateP2m5(p); + + return (X_dmp2m5); +} +TSdmatrixp2m5 *DestroyMatrixP2m5(TSdmatrixp2m5 *X_dmp2m5) +{ + int _i; + + if (X_dmp2m5) { + for (_i=X_dmp2m5->nrows*X_dmp2m5->ncols-1; _i>=0; _i--) + X_dmp2m5->M[_i] = DestroyP2m5(X_dmp2m5->M[_i]); + free(X_dmp2m5->M); + + free(X_dmp2m5); + return ((TSdmatrixp2m5 *)NULL); + } + else return (X_dmp2m5); +} +TSdcellp2m5 *CreateCellP2m5(const TSivector *rows_iv, const TSivector *cols_iv, const double p) +{ + int _i; + int ncells; + // + TSdcellp2m5 *X_dcp2m5 = tzMalloc(1, TSdcellp2m5); + + + if (!rows_iv || !cols_iv || !rows_iv->flag || !cols_iv->flag) fn_DisplayError(".../cstz.c/CreateCellP2m5(): Input row and column vectors must be (1) created and (2) assigned legal values"); + if ((ncells=rows_iv->n) != cols_iv->n) fn_DisplayError(".../cstz.c/CreateCellP2m5(): Length of rows_iv must be the same as that of cols_iv"); + + + X_dcp2m5->ncells = ncells; + X_dcp2m5->C = tzMalloc(ncells, TSdmatrixp2m5 *); + for (_i=ncells-1; _i>=0; _i--) + X_dcp2m5->C[_i] = CreateMatrixP2m5(rows_iv->v[_i], cols_iv->v[_i], p); + + return (X_dcp2m5); +} +TSdcellp2m5 *DestroyCellP2m5(TSdcellp2m5 *X_dcp2m5) +{ + int _i; + + if (X_dcp2m5) { + for (_i=X_dcp2m5->ncells-1; _i>=0; _i--) + X_dcp2m5->C[_i] = DestroyMatrixP2m5(X_dcp2m5->C[_i]); + free(X_dcp2m5->C); + + free(X_dcp2m5); + return ((TSdcellp2m5 *)NULL); + } + else return (X_dcp2m5); +} + + +#define P2REALBOUND DBL_MAX +int P2m5Update(TSdp2m5 *x_dp2m5, const double newval) +{ + //5-marker P2 algorithm. + //quantiles q[0] to q[4] correspond to 5-marker probabilities {0.0, p/5, p, (1+p)/5, 1.0}. + //Outputs: + // x_dp2m5->q, the markers x_dp2m5->m, is updated and only x_dp2m5->q[2] is used. + //Inputs: + // newval: new random number. + // + // January 2003. + int k, j; + double a; + double qm, dq; + int i, dm, dn; + + + if (!x_dp2m5) fn_DisplayError(".../cstz.c/P2m5Update(): x_dp2m5 must be created"); + + //if (isgreater(newval, -P2REALBOUND) && isless(newval, P2REALBOUND)) { + if (isfinite(newval) && newval > -P2REALBOUND && newval < P2REALBOUND) { + if (++x_dp2m5->cnt > 5) { + //Updating the quantiles and markers. + for (i=0; x_dp2m5->q[i]<=newval && i<5; i++) ; + if (i==0) { x_dp2m5->q[0]=newval; i++; } + if (i==5) { x_dp2m5->q[4]=newval; i--; } + for (; i<5; i++) x_dp2m5->m[i]++; + for (i=1; i<4; i++) { + dq = x_dp2m5->p[i]*x_dp2m5->m[4]; + if (x_dp2m5->m[i]+1<=dq && (dm=x_dp2m5->m[i+1]-x_dp2m5->m[i])>1) { + dn = x_dp2m5->m[i]-x_dp2m5->m[i-1]; + dq = ((dn+1)*(qm=x_dp2m5->q[i+1]-x_dp2m5->q[i])/dm+ + (dm-1)*(x_dp2m5->q[i]-x_dp2m5->q[i-1])/dn)/(dm+dn); + if (qm<dq) dq = qm/dm; + x_dp2m5->q[i] += dq; + x_dp2m5->m[i]++; + } else + if (x_dp2m5->m[i]-1>=dq && (dm=x_dp2m5->m[i]-x_dp2m5->m[i-1])>1) { + dn = x_dp2m5->m[i+1]-x_dp2m5->m[i]; + dq = ((dn+1)*(qm=x_dp2m5->q[i]-x_dp2m5->q[i-1])/dm+ + (dm-1)*(x_dp2m5->q[i+1]-x_dp2m5->q[i])/dn)/(dm+dn); + if (qm<dq) dq = qm/dm; + x_dp2m5->q[i] -= dq; + x_dp2m5->m[i]--; + } + } + } + else if (x_dp2m5->cnt < 5) { + //Fills the initial values. + x_dp2m5->q[x_dp2m5->cnt-1] = newval; + x_dp2m5->m[x_dp2m5->cnt-1] = x_dp2m5->cnt-1; + } + else { + //=== Last filling of initial values. + x_dp2m5->q[4] = newval; + x_dp2m5->m[4] = 4; + //=== P2 algorithm begins with reshuffling quantiles and makers. + for (j=1; j<5; j++) { + a = x_dp2m5->q[j]; + for (k=j-1; k>=0 && x_dp2m5->q[k]>a; k--) + x_dp2m5->q[k+1] = x_dp2m5->q[k]; + x_dp2m5->q[k+1]=a; + } + } + } + else ++x_dp2m5->ndeg; //Throwing away the draws to treat exceptions. + + return (x_dp2m5->cnt); +} +#undef P2REALBOUND + +void P2m5MatrixUpdate(TSdmatrixp2m5 *X_dmp2m5, const TSdmatrix *newval_dm) +{ + int _i; + int nrows, ncols; + + if (!X_dmp2m5 || !newval_dm || !newval_dm->flag) fn_DisplayError(".../cstz.c/P2m5MatrixUpdate(): (1) Matrix struct X_dmp2m5 must be created and (2) input new value matrix must be crated and given legal values"); + if ((nrows=newval_dm->nrows) != X_dmp2m5->nrows || (ncols=newval_dm->ncols) != X_dmp2m5->ncols) + fn_DisplayError(".../cstz.c/P2m5MatrixUpdate(): Number of rows and colums in X_dmp2m5 must match those of newval_dm"); + + for (_i=nrows*ncols-1; _i>=0; _i--) + P2m5Update(X_dmp2m5->M[_i], newval_dm->M[_i]); +} + +void P2m5CellUpdate(TSdcellp2m5 *X_dcp2m5, const TSdcell *newval_dc) +{ + int _i; + int ncells; + + if (!X_dcp2m5 || !newval_dc) fn_DisplayError(".../cstz.c/P2m5CellUpdate(): (1) Cell struct X_dcp2m5 must be created and (2) input new value cell must be crated and given legal values"); + if ((ncells=newval_dc->ncells) != X_dcp2m5->ncells) + fn_DisplayError(".../cstz.c/P2m5MatrixUpdate(): Number of cells in X_dcp2m5 must match that of newval_dc"); + + for (_i=ncells-1-1; _i>=0; _i--) + P2m5MatrixUpdate(X_dcp2m5->C[_i], newval_dc->C[_i]); +} +/**/ diff --git a/CFiles/cstz.h b/CFiles/cstz.h new file mode 100755 index 0000000..e52a2bf --- /dev/null +++ b/CFiles/cstz.h @@ -0,0 +1,201 @@ +#ifndef __CSTZ_H__ +#define __CSTZ_H__ + #include "tzmatlab.h" + #include "switch_opt.h" //DW's Markov-switching routines, only used by gradcd_timet() and ComputeCovarianceFromOuterProduct(). + + + typedef struct { + double bound; //Real bounds to avoid extreme values that may make the P2 algorithm fail. + double *p; //5-by-1 probabilities as {0.0, p/2, p, (1+p)/2, 1.0}. + double *q; //5-by-1 quantiles. Only q[2] is used as an estimate of p[2]-quantile or p-quantile. + int *m; //5-by-1 markers. + int cnt; + int ndeg; //Number of exceptions such as degenerate numbers like inf. + } TSdp2m5; + typedef struct { + TSdp2m5 **v; + int n; + } TSdvectorp2m5; + typedef struct { + TSdp2m5 **M; + int nrows; + int ncols; + } TSdmatrixp2m5; + typedef struct { + TSdmatrixp2m5 **C; + int ncells; + } TSdcellp2m5; + typedef struct { + TSdcellp2m5 **F; + int ndims; + } TSdfourthp2m5; + TSdp2m5 *CreateP2m5(const double p, const double bound); + TSdp2m5 *DestroyP2m5(TSdp2m5 *x_dp2m5); + TSdvectorp2m5 *CreateVectorP2m5(const int n, const double p, const double bound); + TSdvectorp2m5 *DestroyVectorP2m5(TSdvectorp2m5 *x_dvp2m5); + TSdmatrixp2m5 *CreateMatrixP2m5(const int nrows, const int ncols, const double p, const double bound); + TSdmatrixp2m5 *DestroyMatrixP2m5(TSdmatrixp2m5 *X_dmp2m5); + TSdcellp2m5 *CreateCellP2m5(const TSivector *rows_iv, const TSivector *cols_iv, const double p, const double bound); + TSdcellp2m5 *DestroyCellP2m5(TSdcellp2m5 *X_dcp2m5); + TSdfourthp2m5 *CreateFourthP2m5(const int ndims, const TSivector *rows_iv, const TSivector *cols_iv, const double p, const double bound); + TSdfourthp2m5 *DestroyFourthP2m5(TSdfourthp2m5 *X_d4p2m5); + // + int P2m5Update(TSdp2m5 *x_dp2m5, const double newval); + void P2m5VectorUpdate(TSdvectorp2m5 *x_dvp2m5, const TSdvector *newval_dv); + void P2m5MatrixUpdate(TSdmatrixp2m5 *X_dmp2m5, const TSdmatrix *newval_dm); + void P2m5CellUpdate(TSdcellp2m5 *X_dcp2m5, const TSdcell *newval_dc); + void P2m5FourthUpdate(TSdfourthp2m5 *X_d4p2m5, const TSdfourth *newval_d4); + + + #if defined ( CSMINWEL_OPTIMIZATION ) + void fn_gradcd(double *g, double *x, int n, double grdh, + double (*fcn)(double *x, int n, double **args, int *dims), + double **args, int *dims); + + void fn_hesscd(double *H, double *x, int n, double grdh, + double (*fcn)(double *x, int n, double **args, int *dims), + double **args, int *dims); + #elif defined ( IMSL_OPTIMIZATION ) + void fn_gradcd(double *g, double *x, int n, double grdh, + double fcn(int n, double *x)); + void fn_hesscd(double *H, double *x, int n, double grdh, + double fcn(int n, double *x)); + #endif + + //=== For the conjugate gradient method I or II + void gradcd_gen(double *g, double *x, int n, double (*fcn)(double *x, int n), double *grdh, double f0); + void gradfd_gen(double *g, double *x, int n, double (*fcn)(double *x, int n), double *grdh, double f0); + + //=== For computing inverse Hessian. + TSdmatrix *ComputeHessianFrom2ndDerivative(TSdmatrix *Hessian_dm, struct TStateModel_tag *smodel_ps, TSdvector *xhat_dv); + //+ + void gradcd_timet(TSdvector *g_dv, TSdvector *x_dv, int t, struct TStateModel_tag *smodel_ps, double (*fcn)(double *x, int t, struct TStateModel_tag *smodel_ps), double grdh, double f0); + TSdmatrix *ComputeHessianFromOuterProduct(TSdmatrix *Hessian_dm, struct TStateModel_tag *smodel_ps, TSdvector *xhat_dv); + TSdmatrix *ComputeCovarianceFromOuterProduct(TSdmatrix *Omega_dm, struct TStateModel_tag *smodel_ps, TSdvector *xhat_dv); + + + + + int next_permutation(int *first, int *last); + + //void fn_ergodp(double **aop, int *aod, mxArray *cp); + void fn_cumsum(double **aos_v, int *aods_v, double *v, int d_v); + int fn_cumsum_int(int *x_v, const int d_x_v); + double fn_cumsum_lf(double *x_v, const int d_x_v); + double fn_mean(const double *a_v, const int _n); + + + //=== For sorting according to x_dv. + void tz_sort(TSdvector *x_dv, char ad); + void tz_sortindex_lf(TSivector *x_iv, TSdvector *base_dv, char ad); + void tz_sortindex(TSivector *x_iv, TSvoidvector *base_voidv, char ad); //??????Not fully tested yet. + //+ + void tz_sort_matrix(TSdmatrix *X_dm, char ad, char rc); + TSdvector *tz_prctile_matrix(TSdvector *z_dv, const double prc, TSdmatrix *Z_dm, const char rc); + TSdvector *tz_mean_matrix(TSdvector *z_dv, TSdmatrix *Z_dm, const char rc); + //--- The following 3 functions should be hided (static) but are made visible to accomodate the old code that uses these functions. + void fn_SetBaseArrayForComp(TSdvector *x_dv); + int fn_compare(const void *i1, const void *i2); + int fn_compare2(const void *i1, const void *i2); + + + //=== Normalization for VARs. + void fn_wznormalization(TSdvector *wznmlz_dv, TSdmatrix *A0draw_dm, TSdmatrix *A0peak_dm); + + //=== Handling under or over flows with log values. + typedef struct TSveclogsum_tag { + //For a recurisve algorithm to compute the log of sum (and therefore log of mean). See p.81a and p.105 in TVBAR Notes. + int n; //Number of sums, which is the dimension for N_iv, Ysum_dv, and ymax_dv. + TSivector *N_iv; //(N_1, ..., N_n). + TSdvector *logsum_dv, //(logofsum_1, ..., logofsum_n). + *logmax_dv; //(logmax_1, ..., logmax_n). + } TSveclogsum; + struct TSveclogsum_tag *CreateVeclogsum(int n); + struct TSveclogsum_tag *DestroyVeclogsum(struct TSveclogsum_tag *); + // + void UpdateSumFor1st2ndMoments(TSdvector *x1stsum_dv, TSdmatrix *X2ndsum_dm, const TSdvector *xdraw_dv); + int tz_update_logofsum(double *Y_N_dp, double *y_Nmax_dp, double ynew, int N); + int fn_update_logofsum(int N, double ynew, double *Y_N_dp, double *y_Nmax_dp); + double fn_replace_logofsumsbt(double *yold, double _a, double ynew, double _b); + + + + //---------------------------- Special functions and densities. --------------------- + double fn_normalcdf(double x); + double fn_normalinv(double p); //Inverse of normal cdf. + double fn_chi2inv(double p, double df); + //p = int_{0}^{\infty} chi2pdf(t, df) dt + double fn_betainv(double p, double _alpha, double _beta); + //p = int_{0}^{\infty} betapdf(t, _alpha, _beta) dt where betapdf(t,_alpha,_beta) \propt t^{_alpha-1}*(1-t)^(_beta-1}. + double fn_gammalog(double x); + //log gamma (x) where gamma(n+1) = n! and gamma(x) = int_0^{\infty} e^{-t} t^{x-1} dt. + double fn_betalog(double x, double y); + //log beta(x, y) where beta(x, y) = gamma(x)*gamm(y)/gamma(x+y). + //+ Density functions + double tz_lognormalpdf(double _x, double _m, double _s); + double tz_logbetapdf(double _x, double _a, double _b); + double tz_loggammapdf(double _x, double _a, double _b); + double tz_loginversegammapdf(double _x, double _a, double _b); + + + //---------------------------- Some high-level VAR functions --------------------- + void fn_lev2growthanual(TSdmatrix *levgro_dm, const TSdmatrix *levgrominus1_dm, const TSivector *indxlogper_iv); + void fn_ctfals_givenshocks_sm(TSdmatrix *ctfalstran_dm, TSdvector *xprimeminus1_dv, const int bloc, const int eloc, const TSdmatrix *strshockstran_dm, + const TSivector *S_Tdraw_iv, const TSdcell *Bsdraw_dc, const TSdcell *A0sdrawinv_dc, const TSivector *noshocks_iv); + void fn_ctfals_sm(TSdmatrix *ctfalstran_dm, TSdvector *xprimeminus1_dv, const int bloc, const int eloc, const TSdmatrix *strshockstran_dm, const TSivector *Snfores_iv, const TSdcell *Bsdraw_dc, const TSdcell *A0sdrawinv_dc); + void fn_ctfals_policyonly(TSdmatrix *ctfalstran_dm, TSdvector *xprimeminus1_dv, const int bloc, const int eloc, const TSdmatrix *strshockstran_dm, const TSivector *S_Tdraw_iv, const int statecon, const int selej, const TSdcell *A0sdraw_dc, const TSdcell *Apsdraw_dc); + void fn_impulse(TSdmatrix *imftran_dm, const TSdmatrix *Bh_dm, const TSdmatrix *swishtran_dm, const int nlags, const int imsteps); + TSdmatrix *tz_impulse2levels(TSdmatrix *imflev_dm, TSdmatrix *imf_dm, TSivector *vlist2levels_iv); + // + void DynamicResponsesAR(TSdvector *resps_dv, const double c0, const TSdvector *a1_dv); + void DynamicResponsesForStructuralEquation(TSdmatrix *Resps_dm, const int loclv, const int nlags, const TSdvector *a0p_dv); + + + + //---------------------------- Some regular vector or matrix operations --------------------- + double MinVector_lf(TSdvector *x_dv); + TSdvector *ConvertVector2exp(TSdvector *y_dv, TSdvector *x_dv); //y=exp(x): output; x: input. + TSdvector *ConvertVector2log(TSdvector *y_dv, TSdvector *x_dv); //y=log(x): output; x: input. + double tz_normofvector(TSdvector *x_dv, double p); + + + //---------------------------- Old Interface --------------------- + double gammalog(double x); + //log gamma (x) where gamma(n+1) = n! and gamma(x) = int_0^{\infty} e^{-t} t^{x-1} dt. + + + + + //----------- Must keep the following forever. ------------- + /** + typedef struct { + double *p; //5-by-1 probabilities as {0.0, p/2, p, (1+p)/2, 1.0}. + double *q; //5-by-1 quantiles. Only q[2] is used as an estimate of p[2]-quantile or p-quantile. + int *m; //5-by-1 markers. + int cnt; + int ndeg; //Number of exceptions such as degenerate numbers like inf. + } TSdp2m5; + typedef struct { + TSdp2m5 **v; + int n; + } TSdvectorp2m5; + typedef struct { + TSdp2m5 **M; + int nrows; + int ncols; + } TSdmatrixp2m5; + typedef struct { + TSdmatrixp2m5 **C; + int ncells; + } TSdcellp2m5; + + TSdp2m5 *CreateP2m5(const double p); + TSdp2m5 *DestroyP2m5(TSdp2m5 *x_dp2m5); + TSdvectorp2m5 *CreateVectorP2m5(const int n, const double p); + TSdvectorp2m5 *DestroyVectorP2m5(TSdvectorp2m5 *x_dvp2m5); + TSdmatrixp2m5 *CreateMatrixP2m5(const int nrows, const int ncols, const double p); + TSdmatrixp2m5 *DestroyMatrixP2m5(TSdmatrixp2m5 *X_dmp2m5); + TSdcellp2m5 *CreateCellP2m5(const TSivector *rows_iv, const TSivector *cols_iv, const double p); + TSdcellp2m5 *DestroyCellP2m5(TSdcellp2m5 *X_dcp2m5); + /**/ +#endif diff --git a/CFiles/cstz_dw.c b/CFiles/cstz_dw.c new file mode 100755 index 0000000..9bbb758 --- /dev/null +++ b/CFiles/cstz_dw.c @@ -0,0 +1,2791 @@ +#include "cstz.h" + +#include <float.h> +#include <string.h> //For memmove, etc. +#include "mathlib.h" + + +//???????? +//------- For computing inverse Hessian only. ------- +//static struct TStateModel_tag *SetModelGlobalForCovariance(struct TStateModel_tag *smodel_ps); +//static double ObjFuncForSmodel(double *x0_p, int d_x0); +//static double opt_logOverallPosteriorKernal(struct TStateModel_tag *smodel_ps, TSdvector *xchange_dv); + +static double logCondPostKernTimet(double *xchange_p, int t, struct TStateModel_tag *smodel_ps); +static double neglogPostKern_hess(double *xchange_pd, struct TStateModel_tag *smodel_ps); +static void hesscd_smodel(TSdmatrix *H_dm, TSdvector *x_dv, struct TStateModel_tag *smodel_ps, double (*fcn)(double *x, struct TStateModel_tag *), double grdh, double f0); + +TSdp2m5 *CreateP2m5(const double p, const double bound) +{ + TSdp2m5 *x_dp2m5 = tzMalloc(1, TSdp2m5); + + if (p<=0.0 && p>=1.0) fn_DisplayError(".../cstz.c/CreateP2m5(): Input probability p must be between 0.0 and 1.0"); + if ((x_dp2m5->bound=bound)<=0.0) fn_DisplayError(".../cstz.c/CreateP2m5(): Real bound must be positive"); + + x_dp2m5->cnt = 0; + x_dp2m5->ndeg = 0; + x_dp2m5->p = tzMalloc(5, double); + x_dp2m5->q = tzMalloc(5, double); + x_dp2m5->m = tzMalloc(5, int); + + //=== 5 markers. + x_dp2m5->p[0] = 0.00; + x_dp2m5->p[1] = 0.5*p; + x_dp2m5->p[2] = p; + x_dp2m5->p[3] = 0.5*(1.0+p); + x_dp2m5->p[4] = 1.00; + //=== Now 9 markers. + // x_dp2m5->p[0] = 0.00; + // x_dp2m5->p[1] = 0.25*p + // x_dp2m5->p[2] = 0.5*p; + // x_dp2m5->p[3] = 0.75*p; + // x_dp2m5->p[4] = p; + // x_dp2m5->p[5] = 0.25 + 0.75*p; + // x_dp2m5->p[6] = 0.5*(1.0+p); + // x_dp2m5->p[7] = 0.75 + 0.25*p; + // x_dp2m5->p[8] = 1.00; + + return (x_dp2m5); +} +TSdp2m5 *DestroyP2m5(TSdp2m5 *x_dp2m5) +{ + if (x_dp2m5) { + free(x_dp2m5->m); + free(x_dp2m5->q); + free(x_dp2m5->p); + + free(x_dp2m5); + return ((TSdp2m5 *)NULL); + } + else return (x_dp2m5); +} +TSdvectorp2m5 *CreateVectorP2m5(const int n, const double p, const double bound) +{ + int _i; + // + TSdvectorp2m5 *x_dvp2m5 = tzMalloc(1, TSdvectorp2m5); + + x_dvp2m5->n = n; + x_dvp2m5->v = tzMalloc(n, TSdp2m5 *); + for (_i=n-1; _i>=0; _i--) + x_dvp2m5->v[_i] = CreateP2m5(p, bound); + + return (x_dvp2m5); +} +TSdvectorp2m5 *DestroyVectorP2m5(TSdvectorp2m5 *x_dvp2m5) +{ + int _i; + + if (x_dvp2m5) { + for (_i=x_dvp2m5->n-1; _i>=0; _i--) + x_dvp2m5->v[_i] = DestroyP2m5(x_dvp2m5->v[_i]); + free(x_dvp2m5->v); + + free(x_dvp2m5); + return ((TSdvectorp2m5 *)NULL); + } + else return (x_dvp2m5); +} +TSdmatrixp2m5 *CreateMatrixP2m5(const int nrows, const int ncols, const double p, const double bound) +{ + int _i; + // + TSdmatrixp2m5 *X_dmp2m5 = tzMalloc(1, TSdmatrixp2m5); + + X_dmp2m5->nrows = nrows; + X_dmp2m5->ncols = ncols; + X_dmp2m5->M = tzMalloc(nrows*ncols, TSdp2m5 *); + for (_i=nrows*ncols-1; _i>=0; _i--) + X_dmp2m5->M[_i] = CreateP2m5(p, bound); + + return (X_dmp2m5); +} +TSdmatrixp2m5 *DestroyMatrixP2m5(TSdmatrixp2m5 *X_dmp2m5) +{ + int _i; + + if (X_dmp2m5) { + for (_i=X_dmp2m5->nrows*X_dmp2m5->ncols-1; _i>=0; _i--) + X_dmp2m5->M[_i] = DestroyP2m5(X_dmp2m5->M[_i]); + free(X_dmp2m5->M); + + free(X_dmp2m5); + return ((TSdmatrixp2m5 *)NULL); + } + else return (X_dmp2m5); +} +TSdcellp2m5 *CreateCellP2m5(const TSivector *rows_iv, const TSivector *cols_iv, const double p, const double bound) +{ + int _i; + int ncells; + // + TSdcellp2m5 *X_dcp2m5 = tzMalloc(1, TSdcellp2m5); + + + if (!rows_iv || !cols_iv || !rows_iv->flag || !cols_iv->flag) fn_DisplayError(".../cstz.c/CreateCellP2m5(): Input row and column vectors must be (1) created and (2) assigned legal values"); + if ((ncells=rows_iv->n) != cols_iv->n) fn_DisplayError(".../cstz.c/CreateCellP2m5(): Length of rows_iv must be the same as that of cols_iv"); + + + X_dcp2m5->ncells = ncells; + X_dcp2m5->C = tzMalloc(ncells, TSdmatrixp2m5 *); + for (_i=ncells-1; _i>=0; _i--) + X_dcp2m5->C[_i] = CreateMatrixP2m5(rows_iv->v[_i], cols_iv->v[_i], p, bound); + + return (X_dcp2m5); +} +TSdcellp2m5 *DestroyCellP2m5(TSdcellp2m5 *X_dcp2m5) +{ + int _i; + + if (X_dcp2m5) { + for (_i=X_dcp2m5->ncells-1; _i>=0; _i--) + X_dcp2m5->C[_i] = DestroyMatrixP2m5(X_dcp2m5->C[_i]); + free(X_dcp2m5->C); + + free(X_dcp2m5); + return ((TSdcellp2m5 *)NULL); + } + else return (X_dcp2m5); +} +TSdfourthp2m5 *CreateFourthP2m5(const int ndims, const TSivector *rows_iv, const TSivector *cols_iv, const double p, const double bound) +{ + int _i; + // + TSdfourthp2m5 *X_d4p2m5 = tzMalloc(1, TSdfourthp2m5); + + + if (!rows_iv || !cols_iv || !rows_iv->flag || !cols_iv->flag) fn_DisplayError(".../cstz.c/CreateFourthP2m5(): Input row and column vectors must be (1) created and (2) assigned legal values"); + if (rows_iv->n != cols_iv->n) fn_DisplayError(".../cstz.c/CreateFourthP2m5(): Length of rows_iv must be the same as that of cols_iv"); + + + X_d4p2m5->ndims = ndims; + X_d4p2m5->F = tzMalloc(ndims, TSdcellp2m5 *); + for (_i=ndims-1; _i>=0; _i--) + X_d4p2m5->F[_i] = CreateCellP2m5(rows_iv, cols_iv, p, bound); + + return (X_d4p2m5); +} +TSdfourthp2m5 *DestroyFourthP2m5(TSdfourthp2m5 *X_d4p2m5) +{ + int _i; + + if (X_d4p2m5) { + for (_i=X_d4p2m5->ndims-1; _i>=0; _i--) + X_d4p2m5->F[_i] = DestroyCellP2m5(X_d4p2m5->F[_i]); + free(X_d4p2m5->F); + + free(X_d4p2m5); + return ((TSdfourthp2m5 *)NULL); + } + else return (X_d4p2m5); +} + + + +int P2m5Update(TSdp2m5 *x_dp2m5, const double newval) +{ + //5-marker P2 algorithm. + //quantiles q[0] to q[4] correspond to 5-marker probabilities {0.0, p/5, p, (1+p)/5, 1.0}. + //Outputs: + // x_dp2m5->q, the markers x_dp2m5->m, is updated and only x_dp2m5->q[2] is used. + //Inputs: + // newval: new random number. + // + // January 2003. + int k, j; + double a; + double qm, dq; + int i, dm, dn; + + + if (!x_dp2m5) fn_DisplayError(".../cstz.c/P2m5Update(): x_dp2m5 must be created"); + + //if (isgreater(newval, -P2REALBOUND) && isless(newval, P2REALBOUND)) { + if (isfinite(newval) && newval > -x_dp2m5->bound && newval < x_dp2m5->bound) { + if (++x_dp2m5->cnt > 5) { + //Updating the quantiles and markers. + for (i=0; x_dp2m5->q[i]<=newval && i<5; i++) ; + if (i==0) { x_dp2m5->q[0]=newval; i++; } + if (i==5) { x_dp2m5->q[4]=newval; i--; } + for (; i<5; i++) x_dp2m5->m[i]++; + for (i=1; i<4; i++) { + dq = x_dp2m5->p[i]*x_dp2m5->m[4]; + if (x_dp2m5->m[i]+1<=dq && (dm=x_dp2m5->m[i+1]-x_dp2m5->m[i])>1) { + dn = x_dp2m5->m[i]-x_dp2m5->m[i-1]; + dq = ((dn+1)*(qm=x_dp2m5->q[i+1]-x_dp2m5->q[i])/dm+ + (dm-1)*(x_dp2m5->q[i]-x_dp2m5->q[i-1])/dn)/(dm+dn); + if (qm<dq) dq = qm/dm; + x_dp2m5->q[i] += dq; + x_dp2m5->m[i]++; + } else + if (x_dp2m5->m[i]-1>=dq && (dm=x_dp2m5->m[i]-x_dp2m5->m[i-1])>1) { + dn = x_dp2m5->m[i+1]-x_dp2m5->m[i]; + dq = ((dn+1)*(qm=x_dp2m5->q[i]-x_dp2m5->q[i-1])/dm+ + (dm-1)*(x_dp2m5->q[i+1]-x_dp2m5->q[i])/dn)/(dm+dn); + if (qm<dq) dq = qm/dm; + x_dp2m5->q[i] -= dq; + x_dp2m5->m[i]--; + } + } + } + else if (x_dp2m5->cnt < 5) { + //Fills the initial values. + x_dp2m5->q[x_dp2m5->cnt-1] = newval; + x_dp2m5->m[x_dp2m5->cnt-1] = x_dp2m5->cnt-1; + } + else { + //=== Last filling of initial values. + x_dp2m5->q[4] = newval; + x_dp2m5->m[4] = 4; + //=== P2 algorithm begins with reshuffling quantiles and makers. + for (j=1; j<5; j++) { + a = x_dp2m5->q[j]; + for (k=j-1; k>=0 && x_dp2m5->q[k]>a; k--) + x_dp2m5->q[k+1] = x_dp2m5->q[k]; + x_dp2m5->q[k+1]=a; + } + } + } + else ++x_dp2m5->ndeg; //Throwing away the draws to treat exceptions. + + return (x_dp2m5->cnt); +} + +void P2m5VectorUpdate(TSdvectorp2m5 *x_dvp2m5, const TSdvector *newval_dv) +{ + int _i, _n; + + if (!x_dvp2m5 || !newval_dv || !newval_dv->flag) fn_DisplayError(".../cstz.c/P2m5VectorUpdate(): (1) Vector struct x_dvp2m5 must be created and (2) input new value vector must be crated and given legal values"); + if ((_n=newval_dv->n) != x_dvp2m5->n) + fn_DisplayError(".../cstz.c/P2m5VectorUpdate(): dimension of x_dvp2m5 must match that of newval_dv"); + + for (_i=_n-1; _i>=0; _i--) + P2m5Update(x_dvp2m5->v[_i], newval_dv->v[_i]); +} + +void P2m5MatrixUpdate(TSdmatrixp2m5 *X_dmp2m5, const TSdmatrix *newval_dm) +{ + int _i; + int nrows, ncols; + + if (!X_dmp2m5 || !newval_dm || !newval_dm->flag) fn_DisplayError(".../cstz.c/P2m5MatrixUpdate(): (1) Matrix struct X_dmp2m5 must be created and (2) input new value matrix must be crated and given legal values"); + if ((nrows=newval_dm->nrows) != X_dmp2m5->nrows || (ncols=newval_dm->ncols) != X_dmp2m5->ncols) + fn_DisplayError(".../cstz.c/P2m5MatrixUpdate(): Number of rows and colums in X_dmp2m5 must match those of newval_dm"); + + for (_i=nrows*ncols-1; _i>=0; _i--) + P2m5Update(X_dmp2m5->M[_i], newval_dm->M[_i]); +} + +void P2m5CellUpdate(TSdcellp2m5 *X_dcp2m5, const TSdcell *newval_dc) +{ + int _i; + int ncells; + + if (!X_dcp2m5 || !newval_dc) fn_DisplayError(".../cstz.c/P2m5CellUpdate(): (1) Cell struct X_dcp2m5 must be created and (2) input new value cell must be crated and given legal values"); + if ((ncells=newval_dc->ncells) != X_dcp2m5->ncells) + fn_DisplayError(".../cstz.c/P2m5MatrixUpdate(): Number of cells in X_dcp2m5 must match that of newval_dc"); + + for (_i=ncells-1; _i>=0; _i--) + P2m5MatrixUpdate(X_dcp2m5->C[_i], newval_dc->C[_i]); +} + +void P2m5FourthUpdate(TSdfourthp2m5 *X_d4p2m5, const TSdfourth *newval_d4) +{ + int _i; + int ndims; + + if (!X_d4p2m5 || !newval_d4) fn_DisplayError(".../cstz.c/P2m5FourthUpdate(): (1) Fourth struct X_d4p2m5 must be created and (2) input new value fourth must be crated and given legal values"); + if ((ndims=newval_d4->ndims) != X_d4p2m5->ndims) + fn_DisplayError(".../cstz.c/P2m5FourthUpdate(): Number of fourths in X_d4p2m5 must match that of newval_d4"); + + for (_i=ndims-1; _i>=0; _i--) + P2m5CellUpdate(X_d4p2m5->F[_i], newval_d4->F[_i]); +} + + + + +//--------------------------------------------------------------------- +//--------------------------------------------------------------------- +#if defined( CSMINWEL_OPTIMIZATION ) + #define STPS 6.0554544523933391e-6 /* step size = pow(DBL_EPSILON,1.0/3) */ + void fn_gradcd(double *g, double *x, int n, double grdh, + double (*fcn)(double *x, int n, double **args, int *dims), + double **args, int *dims) { + //Outputs: + // g: the gradient n-by-1 g (no need to be initialized). + //Inputs: + // grdh: step size. If ==0.0, then dh is set automatically; otherwise, grdh is taken as a step size, often set as 1.0e-004. + // x: no change in the end although will be added or substracted by dh during the function (but in the end the original value will be put back). + + double dh, fp, fm, tmp, *xp; + int i; + for (i=0, xp=x; i<n; i++, xp++, g++) { + dh = grdh?grdh:(fabs(*xp)<1?STPS:STPS*(*xp)); + tmp = *xp; + *xp += dh; + dh = *xp - tmp; // This increases the precision slightly. + fp = fcn(x,n,args,dims); + *xp = tmp - dh; + fm = fcn(x,n,args,dims); + *g = (fp-fm)/(2*dh); + *xp = tmp; // Put the original value of x[i] back to x[i] so that the content x[i] is still unaltered. + } + } + #undef STPS + + #define STPS 6.0554544523933391e-6 /* step size = pow(DBL_EPSILON,1.0/3) */ + void fn_hesscd(double *H, double *x, int n, double grdh, + double (*fcn)(double *x, int n, double **args, int *dims), + double **args, int *dims) { + double dhi, dhj, f1, f2, f3, f4, tmpi, tmpj, *xpi, *xpj; + int i, j; + for (i=0, xpi=x; i<n; i++, xpi++) { + dhi = grdh?grdh:(fabs(*xpi)<1?STPS:STPS*(*xpi)); + tmpi = *xpi; + for (j=i, xpj=x+i; j<n; j++, xpj++) + if (i==j) { + /* f2 = f3 when i = j */ + f2 = fcn(x,n,args,dims); + + /* this increases precision slightly */ + *xpi += dhi; + dhi = *xpi - tmpi; + + /* calculate f1 and f4 */ + *xpi = tmpi + 2*dhi; + f1 = fcn(x,n,args,dims); + *xpi = tmpi - 2*dhi; + f4 = fcn(x,n,args,dims); + + /* diagonal element */ + H[i*(n+1)] = (f1-2*f2+f4)/(4*dhi*dhi); + + /* reset to intial value */ + *xpi = tmpi; + } else { + dhj = grdh?grdh:(fabs(*xpj)<1?STPS:STPS*(*xpj)); + tmpj = *xpj; + + /* this increases precision slightly */ + *xpi += dhi; + dhi = *xpi - tmpi; + *xpj += dhj; + dhj = *xpj - tmpj; + + /* calculate f1, f2, f3 and f4 */ + *xpj = tmpj + dhj; + f1 = fcn(x,n,args,dims); + *xpi = tmpi - dhi; + f2 = fcn(x,n,args,dims); + *xpi = tmpi + dhi; + *xpj = tmpj - dhj; + f3 = fcn(x,n,args,dims); + *xpi = tmpi - dhi; + f4 = fcn(x,n,args,dims); + + /* symmetric elements */ + H[i+j*n] = H[j+i*n] = (f1-f2-f3+f4)/(4*dhi*dhj); + + /* reset to intial values */ + *xpi = tmpi; + *xpj = tmpj; + } + } + } + #undef STPS +#elif defined( IMSL_OPTIMIZATION ) + #define STPS 6.0554544523933391e-6 /* step size = pow(DBL_EPSILON,1.0/3) */ + void fn_gradcd(double *g, double *x, int n, double grdh, + double fcn(int n, double *x) // IMSL + //void NAG_CALL fcn(Integer n,double x[],double *f,double g[],Nag_Comm *comm) + ) { + //Outputs: + // g: the gradient n-by-1 g (no need to be initialized). + //Inputs: + // grdh: step size. If ==0.0, then dh is set automatically; otherwise, grdh is taken as a step size, often set as 1.0e-004. + // x: no change in the end although will be added or substracted by dh during the function (but in the end the original value will be put back). + + double dh, fp, fm, tmp, *xp; + int i; + for (i=0, xp=x; i<n; i++, xp++, g++) { + dh = grdh?grdh:(fabs(*xp)<1?STPS:STPS*(*xp)); + tmp = *xp; + *xp += dh; + dh = *xp - tmp; // This increases the precision slightly. + fp = fcn(n,x); // IMSL + //fcn(n,x,&fp,NULL,NULL); /* NAG */ + *xp = tmp - dh; + fm = fcn(n,x); // IMSL + //fcn(n,x,&fm,NULL,NULL); + *g = (fp-fm)/(2*dh); + *xp = tmp; // Put the original value of x[i] back to x[i] so that the content x[i] is still unaltered. + } + } + #undef STPS + + #define STPS 6.0554544523933391e-6 /* step size = pow(DBL_EPSILON,1.0/3) */ + void fn_hesscd(double *H, double *x, int n, double grdh, + double fcn(int n, double *x) // IMSL + //void NAG_CALL fcn(Integer n,double x[],double *f,double g[],Nag_Comm *comm) + ) { + double dhi, dhj, f1, f2, f3, f4, tmpi, tmpj, *xpi, *xpj; + int i, j; + for (i=0, xpi=x; i<n; i++, xpi++) { + dhi = grdh?grdh:(fabs(*xpi)<1?STPS:STPS*(*xpi)); + tmpi = *xpi; + for (j=i, xpj=x+i; j<n; j++, xpj++) + if (i==j) { + /* f2 = f3 when i = j */ + f2 = fcn(n,x); // IMSL + //fcn(n,x,&f2,NULL,NULL); + + /* this increases precision slightly */ + *xpi += dhi; + dhi = *xpi - tmpi; + + /* calculate f1 and f4 */ + *xpi = tmpi + 2*dhi; + f1 = fcn(n,x); // IMSL + //fcn(n,x,&f1,NULL,NULL); + *xpi = tmpi - 2*dhi; + f4 = fcn(n,x); /* IMSL */ + //fcn(n,x,&f4,NULL,NULL); + + /* diagonal element */ + H[i*(n+1)] = (f1-2*f2+f4)/(4*dhi*dhi); + + /* reset to intial value */ + *xpi = tmpi; + } else { + dhj = grdh?grdh:(fabs(*xpj)<1?STPS:STPS*(*xpj)); + tmpj = *xpj; + + /* this increases precision slightly */ + *xpi += dhi; + dhi = *xpi - tmpi; + *xpj += dhj; + dhj = *xpj - tmpj; + + /* calculate f1, f2, f3 and f4 */ + *xpj = tmpj + dhj; + f1 = fcn(n,x); // IMSL + //fcn(n,x,&f1,NULL,NULL); + *xpi = tmpi - dhi; + f2 = fcn(n,x); // IMSL + //fcn(n,x,&f2,NULL,NULL); + *xpi = tmpi + dhi; + *xpj = tmpj - dhj; + f3 = fcn(n,x); // IMSL + //fcn(n,x,&f3,NULL,NULL); + *xpi = tmpi - dhi; + f4 = fcn(n,x); // IMSL + //fcn(n,x,&f4,NULL,NULL); + + /* symmetric elements */ + H[i+j*n] = H[j+i*n] = (f1-f2-f3+f4)/(4*dhi*dhj); + + /* reset to intial values */ + *xpi = tmpi; + *xpj = tmpj; + } + } + } + #undef STPS +#endif + + + +//------------------------------- +//Modified from fn_gradcd() in cstz.c for the conjugate gradient method I or II +//------------------------------- +#define STPS 1.0e-04 // 6.0554544523933391e-6 step size = pow(DBL_EPSILON,1.0/3) +#define GRADMANUAL 1.0e+01 //Arbitrarily (manually) set gradient. +void gradcd_gen(double *g, double *x, int n, double (*fcn)(double *x, int n), double *grdh, double f0) { + //Outputs: + // g: the gradient n-by-1 g (no need to be initialized). + //Inputs: + // x: the vector point at which the gradient is evaluated. No change in the end although will be added or substracted by dh during the function (but in the end the original value will be put back). + // n: the dimension of g or x. + // fcn(): the function for which the gradient is evaluated + // grdh: step size. If NULL, then dh is set automatically; otherwise, grdh is taken as a step size, often set as 1.0e-004. + // f0: the value of (*fcn)(x). NOT used in this function except dealing with the boundary (NEARINFINITY) for the + // minimization problem, but to be compatible with a genral function call where, say, gradfw_gen() and cubic + // interpolation of central difference method will use f0. + + double dh, dhi, dh2i, fp, fm, tmp, *xp; + int i; + + if (grdh) { + //=== If f0 >= NEARINFINITY, we're in a bad region and so we assume it's flat in this bad region. This assumption may or may not work for a third-party optimimization routine. + if (f0 >= NEARINFINITY) + { + for (i=n-1; i>=0; i--) + g[i] = GRADMANUAL; + return;; //Early exit. + } + + dh2i = (dhi=1.0/(dh=*grdh))/2.0; + for (i=0, xp=x; i<n; i++, xp++, g++) { + tmp = *xp; + *xp += dh; + //The following statement is bad because dh does not get reset at the beginning of the loop and thus may get changed continually within the loop. + // dh = *xp - tmp; // This increases the precision slightly. + fp = fcn(x, n); //For frprmn() CGI_OPTIMIZATION + //fp = fcn(n,x); // IMSL + //fcn(n,x,&fp,NULL,NULL); /* NAG */ + *xp = tmp - dh; + fm = fcn(x, n); //For frprmn() CGI_OPTIMIZATION + //fm = fcn(n,x); // IMSL + //fcn(n,x,&fm,NULL,NULL); + + //=== Checking the boundary condition for the minimization problem. + if ((fp < NEARINFINITY) && (fm < NEARINFINITY)) *g = (fp-fm)*dh2i; + else if (fp < NEARINFINITY) *g = (fp-f0)*dhi; + else if (fm < NEARINFINITY) *g = (f0-fm)*dhi; + else *g = GRADMANUAL; + + *xp = tmp; // Put the original value of x[i] back to x[i] so that the content x[i] is still unaltered. + } + + } + else { + //=== If f0 >= NEARINFINITY, we're in a bad region and so we assume it's flat in this bad region. This assumption may or may not work for a third-party optimimization routine. + if (f0 >= NEARINFINITY) + { + for (i=n-1; i>=0; i--) + g[i] = GRADMANUAL; + return;; //Early exit. + } + + for (i=0, xp=x; i<n; i++, xp++, g++) { + dh = fabs(*xp)<=1 ? STPS : STPS*(*xp); + tmp = *xp; + *xp += dh; + dh = *xp - tmp; // This increases the precision slightly. + fp = fcn(x, n); //For frprmn() CGI_OPTIMIZATION + //fp = fcn(n,x); // IMSL + //fcn(n,x,&fp,NULL,NULL); /* NAG */ + *xp = tmp - dh; + fm = fcn(x, n); //For frprmn() CGI_OPTIMIZATION + //fm = fcn(n,x); // IMSL + //fcn(n,x,&fm,NULL,NULL); + + //=== Checking the boundary condition for the minimization problem. + if ((fp < 0.5*NEARINFINITY) && (fm < 0.5*NEARINFINITY)) *g = (fp-fm)/(2.0*dh); + else if (fp < 0.5*NEARINFINITY) *g = (fp-f0)/dh; + else if (fm < 0.5*NEARINFINITY) *g = (f0-fm)/dh; + else *g = GRADMANUAL; + + *xp = tmp; // Put the original value of x[i] back to x[i] so that the content x[i] is still unaltered. + } + } +} +#undef STPS +#undef GRADMANUAL + + +//------------------------------- +//Forward difference gradient: much faster than gradcd_gen() when the objective function is very expensive to evaluate. +//------------------------------- +#define STPS 1.0e-04 // 6.0554544523933391e-6 step size = pow(DBL_EPSILON,1.0/3) +void gradfd_gen(double *g, double *x, int n, double (*fcn)(double *x, int n), double *grdh, double f0) { + //Outputs: + // g: the gradient n-by-1 g (no need to be initialized). + //Inputs: + // x: the vector point at which the gradient is evaluated. No change in the end although will be added or substracted by dh during the function (but in the end the original value will be put back). + // n: the dimension of g or x. + // fcn(): the function for which the gradient is evaluated + // grdh: step size. If NULL, then dh is set automatically; otherwise, grdh is taken as a step size, often set as 1.0e-004. + // f0: the value of (*fcn)(x). NOT used in this function except dealing with the boundary (NEARINFINITY) for the + // minimization problem, but to be compatible with a genral function call where, say, gradfw_gen() and cubic + // interpolation of central difference method will use f0. + + double dh, dhi, fp, tmp, *xp; + int i; + if (grdh) { + dhi = 1.0/(dh=*grdh); + for (i=0, xp=x; i<n; i++, xp++, g++) { + dh = fabs(*xp)<=1 ? STPS : STPS*(*xp); + tmp = *xp; + *xp += dh; + if ( (fp=fcn(x, n)) < NEARINFINITY ) *g = (fp-f0)*dhi; //For frprmn() CGI_OPTIMIZATION + else { + //Switches to the other side of the boundary. + *xp = tmp - dh; + *g = (f0-fcn(x,n))*dhi; + } + *xp = tmp; // Put the original value of x[i] back to x[i] so that the content x[i] is still unaltered. + } + + } + else { + for (i=0, xp=x; i<n; i++, xp++, g++) { + dh = fabs(*xp)<=1 ? STPS : STPS*(*xp); + tmp = *xp; + *xp += dh; + dh = *xp - tmp; // This increases the precision slightly. + if ( (fp=fcn(x, n)) < NEARINFINITY ) *g = (fp-f0)/dh; //For frprmn() CGI_OPTIMIZATION + else { + //Switches to the other side of the boundary. + *xp = tmp - dh; + *g = (f0-fcn(x,n))/dh; + } + + *xp = tmp; // Put the original value of x[i] back to x[i] so that the content x[i] is still unaltered. + } + } +} +#undef STPS + + + +//==================================================================================================== +//= Central difference gradient for logLH at time t, using DW's smodel. +//==================================================================================================== +#define STPS 1.0e-04 // 6.0554544523933391e-6 step size = pow(DBL_EPSILON,1.0/3) +#define GRADMANUAL 1.0e+01 //Arbitrarily (manually) set gradient. +void gradcd_timet(TSdvector *g_dv, TSdvector *x_dv, int t, struct TStateModel_tag *smodel_ps, double (*fcn)(double *x, int t, struct TStateModel_tag *smodel_ps), double grdh, double f0) +{ + //Outputs: + // g_dv: the gradient n-by-1 g (no need to be initialized). + //Inputs: + // x_dv: the vector point at which the gradient is evaluated. No change in the end although will be added or substracted by dh during the function (but in the end the original value will be put back). + // fcn(): the log LH or posterior function for which the gradient is evaluated + // grdh: step size. If 0.0, then dh is set automatically; otherwise, grdh is taken as a step size, often set as 1.0e-004. + // f0: the value of (*fcn)(x). NOT used in this function except dealing with the boundary (NEARINFINITY) for the + // minimization problem, but to be compatible with a genral function call where, say, gradfw_gen() and cubic + // interpolation of central difference method will use f0. + + double dh, dhi, dh2i, fp, fm, tmp, *xp; + int i; + //--- Accessible variables. + int n; + double *g, *x; + + if (!g_dv) fn_DisplayError(".../cstz.c/gradcd_timet(): the input g_dv must be allocated memory"); + if (!x_dv) fn_DisplayError(".../cstz.c/gradcd_timet(): the input x_dv must be allocated memory"); + if (!x_dv->flag) fn_DisplayError(".../cstz.c/gradcd_timet(): the input x_dv must be given legal values"); + if ((n=g_dv->n) != x_dv->n) fn_DisplayError(".../cstz.c/gradcd_timet(): dimensions of g_dv and x_dv must be the same"); + + g = g_dv->v; + x = x_dv->v; + + if (grdh>0.0) + { + //=== If f0 <= -0.5*NEARINFINITY, we're in a bad region and so we assume it's GRADMANUAL in this bad region. This assumption may or may not work for a third-party optimimization routine. + if (f0 < -0.5*NEARINFINITY) + { + for (i=n-1; i>=0; i--) + g[i] = GRADMANUAL; + return;; //Early exit. + } + + dh2i = (dhi=1.0/(dh=grdh))/2.0; + for (i=0, xp=x; i<n; i++, xp++, g++) { + tmp = *xp; + *xp += dh; + //The following statement is bad because dh does not get reset at the beginning of the loop and thus may get changed continually within the loop. + // dh = *xp - tmp; // This increases the precision slightly. + fp = fcn(x, t, smodel_ps); + *xp = tmp - dh; + fm = fcn(x, t, smodel_ps); + + //=== Checking the boundary condition for the minimization problem. + if ((fp > -0.5*NEARINFINITY) && (fm > -0.5*NEARINFINITY)) *g = (fp-fm)*dh2i; + else if (fp > -0.5*NEARINFINITY) *g = (fp-f0)*dhi; + else if (fm > -0.5*NEARINFINITY) *g = (f0-fm)*dhi; + else *g = GRADMANUAL; + + *xp = tmp; // Put the original value of x[i] back to x[i] so that the content x[i] is still unaltered. + } + + } + else { + //=== If f0 <= -0.5*NEARINFINITY, we're in a bad region and so we assume it's GRADMANUAL in this bad region. This assumption may or may not work for a third-party optimimization routine. + if (f0 <= -0.5*NEARINFINITY) + { + for (i=n-1; i>=0; i--) + g[i] = GRADMANUAL; + return;; //Early exit. + } + + for (i=0, xp=x; i<n; i++, xp++, g++) { + dh = fabs(*xp)<=1 ? STPS : STPS*(*xp); + tmp = *xp; + *xp += dh; + dh = *xp - tmp; // This increases the precision slightly. + fp = fcn(x, t, smodel_ps); + *xp = tmp - dh; + fm = fcn(x, t, smodel_ps); + + //=== Checking the boundary condition for the minimization problem. + if ((fp > -0.5*NEARINFINITY) && (fm > -0.5*NEARINFINITY)) *g = (fp-fm)/(2.0*dh); + else if (fp > -0.5*NEARINFINITY) *g = (fp-f0)/dh; + else if (fm > -0.5*NEARINFINITY) *g = (f0-fm)/dh; + else *g = GRADMANUAL; + + *xp = tmp; // Put the original value of x[i] back to x[i] so that the content x[i] is still unaltered. + } + } + g_dv->flag = V_DEF; +} +#undef STPS +#undef GRADMANUAL +//--- +#if defined (__SWITCHING_VER_200__) +static double logCondPostKernTimet(double *xchange_pd, int t, struct TStateModel_tag *smodel_ps) +{ + //Evaluating log conditional posterior kernel at time t -- p(y_t | Y_{t-1}, theta, q). + int fss = smodel_ps->nobs - smodel_ps->fobs + 1; + double *x1_pd, *x2_pd; + + + x1_pd = xchange_pd; + x2_pd = xchange_pd + NumberFreeParametersTheta(smodel_ps); + //Note that NumberFreeParametersTheta() is DW's function, which points to TZ's function. + //In the constant parameter model, this will point to an invalid place, + // but will be taken care of automatically by DW's function ConvertFreeParametersToQ(). + + //======= This is a must step to refresh the value at the new point. ======= + ConvertFreeParametersToTheta(smodel_ps, x1_pd); //Waggoner's function, which calls TZ's Convertphi2*(). + ConvertFreeParametersToQ(smodel_ps, x2_pd); //Waggoner's function, which automatically takes care of the constant-parameter situition + ThetaChanged(smodel_ps); //DW's function, which will also call my function to set a flag for refreshing everything under these new parameters. + + + if (1) //Posterior function. + return ( LogConditionalLikelihood_StatesIntegratedOut(t, smodel_ps) + LogPrior(smodel_ps)/((double)fss) ); //DW's function. + else //Likelihood (with no prior) + return ( LogConditionalLikelihood_StatesIntegratedOut(t, smodel_ps) ); //DW's function. +} +#endif + +//------------------------ +// Computing the Hessian at the log posterior or log likelihood peak, using the outer-product Hessian. +//------------------------ +#if defined (__SWITCHING_VER_200__) +TSdmatrix *ComputeHessianFromOuterProduct(TSdmatrix *Hessian_dm, struct TStateModel_tag *smodel_ps, TSdvector *xhat_dv) +{ + //Output: + // Hessian_dm: its inverse equals to Omega (covariance matrix) produced by ComputeCovarianceFromOuterProduct(). + //Inputs: + // xhat_dv: Hessian at this point. + + int ti; + double f0; + int nData = smodel_ps->nobs; + //=== + TSdvector *grad_dv; + + + grad_dv = CreateVector_lf(xhat_dv->n); + if (!Hessian_dm) Hessian_dm = CreateConstantMatrix_lf(xhat_dv->n, xhat_dv->n, 0.0); + + //=== Computing the outer-product Hessian. + for (ti=smodel_ps->fobs; ti<=nData; ti++) //Base-1 set-up, thus <=nData, NOT <nData. + { + f0 = logCondPostKernTimet(xhat_dv->v, ti, smodel_ps); + gradcd_timet(grad_dv, xhat_dv, ti, smodel_ps, logCondPostKernTimet, 0.0, f0); + VectorTimesSelf(Hessian_dm, grad_dv, 1.0, 1.0, 'U'); + } + + + SUtoGE(Hessian_dm); //Making upper symmetric matarix to a full matrix. + Hessian_dm->flag = M_GE; //Reset this flag, so + ScalarTimesMatrixSquare(Hessian_dm, 0.5, Hessian_dm, 'T', 0.5); //Making it symmetric against some rounding errors. + //This making-symmetric is very IMPORTANT; otherwise, we will get the matrix being singular message + // and eigenvalues being negative for the SPD matrix, etc. Then the likelihood becomes either + // a bad number or a complex number. + Hessian_dm->flag |= M_SU | M_SL; + + + //=== + DestroyVector_lf(grad_dv); + + return (Hessian_dm); +} +//------------------------ +// Computing the covariance matrix for standard errors at the log posterior or likelihood peak, using the outer-product Hessian. +//------------------------ +TSdmatrix *ComputeCovarianceFromOuterProduct(TSdmatrix *Omega_dm, struct TStateModel_tag *smodel_ps, TSdvector *xhat_dv) +{ + //Output: + // Omega_dm: covariance matrix, which equals to the inverse of the Hessian produced by ComputeHessianFromOuterProduct(). + //Inputs: + // xhat_dv: Hessian at this point. + + int ti; + double f0; + int nData = smodel_ps->nobs; + //=== + TSdvector *grad_dv; + + + grad_dv = CreateVector_lf(xhat_dv->n); + if (!Omega_dm) Omega_dm = CreateConstantMatrix_lf(xhat_dv->n, xhat_dv->n, 0.0); + + //=== Computing the outer-product Hessian. + for (ti=smodel_ps->fobs; ti<=nData; ti++) //Base-1 set-up, thus <=nData, NOT <nData. + { + f0 = logCondPostKernTimet(xhat_dv->v, ti, smodel_ps); + gradcd_timet(grad_dv, xhat_dv, ti, smodel_ps, logCondPostKernTimet, 0.0, f0); + VectorTimesSelf(Omega_dm, grad_dv, 1.0, 1.0, 'U'); + } + SUtoGE(Omega_dm); //Making upper symmetric matarix to a full matrix. + ScalarTimesMatrixSquare(Omega_dm, 0.5, Omega_dm, 'T', 0.5); //Making it symmetric against some rounding errors. + //This making-symmetric is very IMPORTANT; otherwise, we will get the matrix being singular message + // and eigenvalues being negative for the SPD matrix, etc. Then the likelihood becomes either + // a bad number or a complex number. + Omega_dm->flag |= M_SU | M_SL; + + + //--- Converting or inverting the Hessian to covariance. + if (invspd(Omega_dm, Omega_dm, 'U')) + fn_DisplayError(".../cstz.c/ComputeCovarianceFromOuterProduct(): Hessian must be invertible"); + + + //-- Doubly safe to force it to be symmetric. + SUtoGE(Omega_dm); //Making upper symmetric matarix to a full matrix. + ScalarTimesMatrixSquare(Omega_dm, 0.5, Omega_dm, 'T', 0.5); //Making it symmetric against some rounding errors. + //This making-symmetric is very IMPORTANT; otherwise, we will get the matrix being singular message + // and eigenvalues being negative for the SPD matrix, etc. Then the likelihood becomes either + // a bad number or a complex number. + Omega_dm->flag |= M_SU | M_SL; + + //--- Checking if it's symmetric, positive definite. + + + //=== + DestroyVector_lf(grad_dv); + + return (Omega_dm); +} + + + +//------------------------ +// Computing the Hessian at the log posterior or log likelihood peak, using second derivatives. +//------------------------ +TSdmatrix *ComputeHessianFrom2ndDerivative(TSdmatrix *Hessian_dm, struct TStateModel_tag *smodel_ps, TSdvector *xhat_dv) +{ + //Output: + // Hessian_dm: its inverse equals to Omega (covariance matrix). + // The flag is set to M_GE | M_SU | M_SL by hesscd_smodel(). + //Inputs: + // xhat_dv: Hessian at this point. + + double f0; + int nData = smodel_ps->nobs; + + + if (!Hessian_dm) Hessian_dm = CreateConstantMatrix_lf(xhat_dv->n, xhat_dv->n, 0.0); + + //=== Computing the inner-product Hessian. + f0 = neglogPostKern_hess(xhat_dv->v, smodel_ps); + hesscd_smodel(Hessian_dm, xhat_dv, smodel_ps, neglogPostKern_hess, 0.0, f0); + + return (Hessian_dm); +} +//--- +#define STPS 1.0e-4 //6.0554544523933391e-6 /* step size = pow(DBL_EPSILON,1.0/3) */ +static void hesscd_smodel(TSdmatrix *H_dm, TSdvector *x_dv, struct TStateModel_tag *smodel_ps, double (*fcn)(double *, struct TStateModel_tag *), double grdh, double f0) +{ + //Outputs: + // H_dm: the Hessian n-by-n (no need to be initialized). + //Inputs: + // x_dv: the vector point at which the gradient is evaluated. No change in the end although will be added or substracted by dh during the function (but in the end the original value will be put back). + // fcn(): the negative (-) log LH or posterior function for which the gradient is evaluated + // grdh: step size. If 0.0, then dh is set automatically; otherwise, grdh is taken as a step size, often set as 1.0e-004. + // f0: the value of (*fcn)(x). NOT used in this function except dealing with the boundary (NEARINFINITY) for the + // minimization problem, but to be compatible with a genral function call where, say, gradfw_gen() and cubic + // interpolation of central difference method will use f0. + + double dhi, dhj, f1, f2, f3, f4, tmpi, tmpj, *xpi, *xpj; + int i, j; + //--- Accessible variables. + int n; + double *H, *x; + + if (!x_dv) fn_DisplayError(".../cstz.c/hesscd_smodel(): the input x_dv must be allocated memory"); + if (!x_dv->flag) fn_DisplayError(".../cstz.c/hesscd_smodel(): the input x_dv must be given legal values"); + if (!H_dm) fn_DisplayError(".../cstz.c/hesscd_smodel(): H_dm must be allocated memory"); + if ( ((n=x_dv->n) != H_dm->nrows) || (n != H_dm->ncols) ) fn_DisplayError(".../cstz.c/hesscd_smodel(): Check the dimension of x_dv and H_dm"); + + H = H_dm->M; + x = x_dv->v; + + for (i=0, xpi=x; i<n; i++, xpi++) { + dhi = grdh?grdh:(fabs(*xpi)<1?STPS:STPS*(*xpi)); + tmpi = *xpi; + for (j=i, xpj=x+i; j<n; j++, xpj++) + if (i==j) + { + /* f2 = f3 when i = j */ + if ((f2 = fcn(x, smodel_ps)) > 0.5*NEARINFINITY) f2 = f0; + + /* this increases precision slightly */ + *xpi += dhi; + dhi = *xpi - tmpi; + + /* calculate f1 and f4 */ + *xpi = tmpi + 2*dhi; + if ((f1 = fcn(x, smodel_ps)) > 0.5*NEARINFINITY) f1 = f0; + + *xpi = tmpi - 2*dhi; + if ((f4 = fcn(x, smodel_ps)) > 0.5*NEARINFINITY) f4 = f0; + + /* diagonal element */ + H[i*(n+1)] = (f1-2*f2+f4)/(4*dhi*dhi); + + /* reset to intial value */ + *xpi = tmpi; + } + else + { + dhj = grdh?grdh:(fabs(*xpj)<1?STPS:STPS*(*xpj)); + tmpj = *xpj; + + /* this increases precision slightly */ + *xpi += dhi; + dhi = *xpi - tmpi; + *xpj += dhj; + dhj = *xpj - tmpj; + + /* calculate f1, f2, f3 and f4 */ + *xpj = tmpj + dhj; + if ((f1 = fcn(x, smodel_ps)) > 0.5*NEARINFINITY) f1 = f0; + *xpi = tmpi - dhi; + if ((f2 = fcn(x, smodel_ps)) > 0.5*NEARINFINITY) f2 = f0; + *xpi = tmpi + dhi; + *xpj = tmpj - dhj; + if ((f3 = fcn(x, smodel_ps)) > 0.5*NEARINFINITY) f3 = f0; + *xpi = tmpi - dhi; + if ((f4 = fcn(x, smodel_ps)) > 0.5*NEARINFINITY) f4 = f0; + + /* symmetric elements */ + H[i+j*n] = H[j+i*n] = (f1-f2-f3+f4)/(4*dhi*dhj); + + /* reset to intial values */ + *xpi = tmpi; + *xpj = tmpj; + } + } + + //--- To be safe. + H_dm->flag = M_SU; + SUtoGE(H_dm); //Making upper symmetric matarix to a full matrix. + H_dm->flag = M_GE; //Reset this flag, so + + ScalarTimesMatrixSquare(H_dm, 0.5, H_dm, 'T', 0.5); //Making it symmetric against some rounding errors. + //This making-symmetric is very IMPORTANT; otherwise, we will get the matrix being singular message + // and eigenvalues being negative for the SPD matrix, etc. Then the likelihood becomes either + // a bad number or a complex number. + H_dm->flag |= M_SU | M_SL; +} +#undef STPS +//--- +static double neglogPostKern_hess(double *xchange_pd, struct TStateModel_tag *smodel_ps) +{ + //Evaluating negative log posterior kernel p(y_T | theta, q). + int fss = smodel_ps->nobs - smodel_ps->fobs + 1; + double *x1_pd, *x2_pd; + + + x1_pd = xchange_pd; + x2_pd = xchange_pd + NumberFreeParametersTheta(smodel_ps); + //Note that NumberFreeParametersTheta() is DW's function, which points to TZ's function. + //In the constant parameter model, this will point to an invalid place, + // but will be taken care of automatically by DW's function ConvertFreeParametersToQ(). + + //======= This is a must step to refresh the value at the new point. ======= + ConvertFreeParametersToTheta(smodel_ps, x1_pd); //Waggoner's function, which calls TZ's Convertphi2*(). + ConvertFreeParametersToQ(smodel_ps, x2_pd); //Waggoner's function, which automatically takes care of the constant-parameter situition + ThetaChanged(smodel_ps); //DW's function, which will also call my function to set a flag for refreshing everything under these new parameters. + + + if (1) //Posterior function. + return ( -LogLikelihood_StatesIntegratedOut(smodel_ps) - LogPrior(smodel_ps) ); //DW's function. + else //Likelihood (with no prior) + return ( -LogLikelihood_StatesIntegratedOut(smodel_ps) ); //DW's function. +} +#endif + + + + + + + + + + +//???????????????? +/** +//=== +static struct TStateModel_tag *SMODEL_PS = NULL; //Minimization to find the MLE or posterior peak. +static struct TStateModel_tag *SetModelGlobalForCovariance(struct TStateModel_tag *smodel_ps) +{ + //Returns the old pointer in order to preserve the previous value. + struct TStateModel_tag *tmp_ps =SMODEL_PS; + SMODEL_PS = smodel_ps; + return (tmp_ps); +} +//--- Can be used for conjugate gradient minimization as well. +static double ObjFuncForSmodel(double *x0_p, int d_x0) +{ + TSdvector x0_sdv; + x0_sdv.v = x0_p; + x0_sdv.n = d_x0; + x0_sdv.flag = V_DEF; + + return ( -opt_logOverallPosteriorKernal(SMODEL_PS, &x0_sdv) ); +} +//--- +static double opt_logOverallPosteriorKernal(struct TStateModel_tag *smodel_ps, TSdvector *xchange_dv) +{ + double *x1_pd, *x2_pd; + + + x1_pd = xchange_dv->v; + x2_pd = xchange_dv->v + NumberFreeParametersTheta(smodel_ps); + //Note that NumberFreeParametersTheta() is DW's function, which points to TZ's function. + //In the constant parameter model, this will point to invalid, + // but will be taken care of automatically by DW's function ConvertFreeParametersToQ(). + + //======= This is a must step to refresh the value at the new point. ======= + ConvertFreeParametersToTheta(smodel_ps, x1_pd); //Waggoner's function, which calls TZ's Convertphi2*(). + ConvertFreeParametersToQ(smodel_ps, x2_pd); //Waggoner's function, which automatically takes care of the constant-parameter situition + ThetaChanged(smodel_ps); //DW's function, which will also call my function to set a flag for refreshing everything under these new parameters. + if (1) //Posterior function. + return ( LogPosterior_StatesIntegratedOut(smodel_ps) ); //DW's function. + else //Likelihood (with no prior) + return ( LogLikelihood_StatesIntegratedOut(smodel_ps) ); //DW's function. +} +/**/ + + + + + + + + +int next_permutation(int *first, int *last) +{ + // Given the permulation, say, [3 2 1 0], the ouput is the next permulation [0 1 2 3], and so on. + // Note that last is simply a pointer. Because it is not allocated to a memory, it cannot be accessed. + // So last is used for (1) gauging the dimension size of the array first; + // (2) being accssed but with --last (which points to a valid memory place), NOT last. + // + // first: n-by-1 vector of integers filled with 0, 1, 2, ..., n. + // last: simply a pointer to the address after the last element of first. Note that no memory is allocated. + + int *i = last, *ii, *j, tmp; + if (first == last || first == --i) + return 0; + + for(; ; ) { + ii = i; + if (*--i < *ii) { + j = last; + while (!(*i < *--j)); + tmp = *i; *i = *j; *j = tmp; + for (; ii != last && ii != --last; ++ii) { + tmp = *ii; *ii = *last; *last = tmp; + } + return 1; + } + if (i == first) { + for (; first != last && first != --last; ++first) { + tmp = *first; *first = *last; *last = tmp; + } + return 0; + } + } +} + + + +/** +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +void permute_matrix(double *a, int n, int *indx) { + double *b; + int nn=n*n; + register int i; + b = calloc(nn,sizeof(double)); + memcpy(b, a, nn*sizeof(double)); + for (i=0; i<nn; i++, a++) + *a = b[indx[i%n]+indx[i/n]*n]; +} + +int main() { + double a[9]={1,2,3,4,5,6,7,8,9}; + int indx[3]={1,2,0}; + permute_matrix(a,3,indx); + return 0; +} +/**/ + + +int fn_cumsum_int(int *x_v, const int d_x_v) { + //Outputs: + // x_v: an int vector of cumulative sums over an input int vector. + // return: the sum of an input int vector. + //Inputs: + // x_v: a vector of ints. + // d_x_v: dimension of x_v. + // + // Compute cumulative sums of a vector of ints. + int _i; + + if (x_v==NULL) fn_DisplayError(".../cstz/fn_cumsum_lf: x_v must be allocated with memory"); + + for (_i=1; _i<d_x_v; _i++) { + x_v[_i] = x_v[_i-1] + x_v[_i]; + } + + return (x_v[d_x_v-1]); +} + + +double fn_cumsum_lf(double *x_v, const int d_x_v) { + //Outputs: + // x_v: a double vector of cumulative sums over an input double vector. + // return: the sum of an input double vector. + //Inputs: + // x_v: a vector of doubles. + // d_x_v: dimension of x_v. + // + // Compute cumulative sums of a vector of doubles. + int _i; + + if (!x_v) fn_DisplayError(".../cstz/fn_cumsum_lf: x_v must be allocated with memory"); + + for (_i=1; _i<d_x_v; _i++) { + x_v[_i] = x_v[_i-1] + x_v[_i]; + } + + return (x_v[d_x_v-1]); +} + + +double fn_mean(const double *a_v, const int _n) { + int _i; + double x=0.0; + + for (_i=0; _i<_n; _i++) x += a_v[_i]; + x /= (double)_n; + + return x; +} + +//<<--------------- +static double *tz_BaseForComp; // This base variable is to be sorted and thus made global for this source file. +void fn_SetBaseArrayForComp(TSdvector *x_dv) +{ + if ( !x_dv->flag ) fn_DisplayError(".../cstz.c/ftd_SetBaseArrayForComp(): input vector used for comparison must be given legal values"); + else tz_BaseForComp = x_dv->v; +} +int fn_compare(const void *i1, const void *i2) +{ + // Ascending order according to tz_BaseForComp. + return ( (tz_BaseForComp[*((int*)i1)]<tz_BaseForComp[*((int*)i2)]) ? -1 : (tz_BaseForComp[*((int*)i1)]>tz_BaseForComp[*((int*)i2)]) ? 1 : 0 ); +} +int fn_compare2(const void *i1, const void *i2) +{ + // Descending order according to tz_BaseForComp. + return ( (tz_BaseForComp[*((int*)i1)]<tz_BaseForComp[*((int*)i2)]) ? 1 : (tz_BaseForComp[*((int*)i1)]>tz_BaseForComp[*((int*)i2)]) ? -1 : 0); +} +//======= Quick sort. ======= +static int ftd_CompareDouble(const void *a, const void *b) +{ + // Ascending order for the series that contains a and b. + return (*(double *)a < *(double *)b ? -1 : *(double *)a > *(double *)b ? 1 : 0); +} +static int ftd_CompareDouble2(const void *a, const void *b) +{ + // Dscending order for the series that contains a and b. + return (*(double *)a < *(double *)b ? 1 : *(double *)a > *(double *)b ? -1 : 0); +} +//--- +void tz_sort(TSdvector *x_dv, char ad) +{ + //x_dv will be replaced by the sorted value. + //Sort x_dv according to the descending or ascending order indicated by ad. + //ad == "A' or 'a': acending order. + //ad == 'D' or 'd': descending order. + if (!x_dv || !x_dv->flag) fn_DisplayError("cstz.c/tz_sort(): input vector x_dv must be (1) created and (2) assigned values"); + + qsort( (void *)x_dv->v, (size_t)x_dv->n, sizeof(double), ((ad=='A') || (ad=='a')) ? ftd_CompareDouble : ftd_CompareDouble2); +} +void tz_sortindex_lf(TSivector *x_iv, TSdvector *base_dv, char ad) +{ + //???????NOT fully tested yet. + //x_iv will be replaced by the sorted integer vector. + //base_dv will not be affected. + //Sort x_iv according to the descending or ascending order of base_dv. + //ad == "A' or 'a': acending order. + //ad == 'D' or 'd': descending order. + if (!x_iv || !base_dv || !x_iv->flag || !base_dv->flag) fn_DisplayError("cstz.c/tz_sortindex(): input vectors x_iv and base_dv must be (1) created and (2) assigned values"); + if (x_iv->n != base_dv->n) fn_DisplayError("cstz.c/tz_sortindex(): lengths of the two input vectors must be the same"); + + fn_SetBaseArrayForComp(base_dv); + qsort( (void *)x_iv->v, (size_t)x_iv->n, sizeof(int), ((ad=='A') || (ad=='a')) ? fn_compare : fn_compare2); +} +void tz_sortindex(TSivector *x_iv, TSvoidvector *base_voidv, char ad) +{ + //???????NOT fully tested yet. + //Allowing x_iv = base_voidv or sets base_voidv=NULL + //Sort x_iv according to the descending or ascending order of base_voidv. + //ad == "A' or 'a': acending order. + //ad == 'D' or 'd': descending order. + if (!x_iv || !base_voidv || !x_iv->flag || !base_voidv->flag) fn_DisplayError("cstz.c/tz_sort_int(): input vectors x_iv and base_voidv must be (1) created and (2) assigned values"); + if (x_iv->n != base_voidv->n) fn_DisplayError("cstz.c/tz_sort_int(): lengths of the two input vectors must be the same"); + + fn_SetBaseArrayForComp((TSdvector *)base_voidv); + qsort( (void *)x_iv->v, (size_t)x_iv->n, sizeof(int), ((ad=='A') || (ad=='a')) ? fn_compare : fn_compare2); +} +//--- +void tz_sort_matrix(TSdmatrix *X_dm, char ad, char rc) +{ + //Fast method: rc = 'C' (sort each column). + //Output: X_dm will be replaced by the sorted value. + // Sort X_dm (1) by columns or rows indicated by rc and (2) according to the descending or ascending order indicated by ad. + //Inputs: + // ad == 'A' or 'a': acending order. + // ad == 'D' or 'd': descending order. + // rc == 'C' or 'c': sort each column. + // rc == 'R' or 'r': sort each row. + int nrows, ncols, _j, begloc; + TSdvector x_sdv; + double *X; + //=== + TSdmatrix *Xtran_dm = NULL; + + if (!X_dm || !(X_dm->flag & M_GE)) fn_DisplayError("cstz.c/tz_sort_matrix(): input matrix X_dm must be (1) created and (2) assigned values and (3) regular (M_GE)"); + x_sdv.flag = V_DEF; + + if (rc=='C' || rc=='c') + { + X = X_dm->M; + nrows = X_dm->nrows; + ncols = X_dm->ncols; + } + else + { + Xtran_dm = tz_TransposeRegular((TSdmatrix *)NULL, X_dm); + X = Xtran_dm->M; + nrows = Xtran_dm->nrows; + ncols = Xtran_dm->ncols; + } + x_sdv.n = nrows; + for (begloc=nrows*(ncols-1), _j=ncols-1; _j>=0; begloc-=nrows, _j--) + { + x_sdv.v = X + begloc; + tz_sort(&x_sdv, ad); + } + + if (rc=='R' || rc=='r') + { + tz_TransposeRegular(X_dm, Xtran_dm); + //=== + DestroyMatrix_lf(Xtran_dm); + } +} +//--- +TSdvector *tz_prctile_matrix(TSdvector *z_dv, const double prc, TSdmatrix *Z_dm, const char rc) +{ + //Fast method: rc = 'C' (sort each column). + //Output: %prc percentile (i.e., containing 0% to %prc). + // z_dv: an n-by-1 vector if rc=='C' or an m-by-1 vector if rc=='R'. + // If z_dv==NULL, it will be created and has to be destroyed outside this function. + //Inputs: + // prc: percent (must be between 0.0 and 1.0 inclusive). + // X_dm: an m-by-n general matrix. + // rc == 'C' or 'c': sort each column. + // rc == 'R' or 'r': sort each row. + int nrows, ncols, _j, begloc; + TSdvector x_sdv; + double *X; + //=== + TSdmatrix *X_dm = NULL; + TSdmatrix *Xtran_dm = NULL; + + if (!Z_dm || !Z_dm->flag) fn_DisplayError("cstz.c/tz_prctile_matrix(): input matrix Z_dm must be (1) created and (2) assigned values"); + if (prc<0.0 || prc>1.0) fn_DisplayError("cstz.c/tz_prctile_matrix(): percentile mark prc must be between 0.0 and 1.0 inclusive"); + x_sdv.flag = V_DEF; + + nrows = Z_dm->nrows; + ncols = Z_dm->ncols; + if (!z_dv) + { + if (rc=='C' || rc=='c') z_dv = CreateVector_lf(ncols); + else z_dv = CreateVector_lf(nrows); + } + else + { + if ((rc=='C' || rc=='c')) + { + if (ncols != z_dv->n) fn_DisplayError("cstz.c/tz_prctile_matrix(): z_dv->n must be the same as ncols of X_dm when sorting each column"); + } + else + { + if (nrows != z_dv->n) fn_DisplayError("cstz.c/tz_prctile_matrix(): z_dv->n must be the same as nrows of X_dm when sorting each row"); + } + } + X_dm = CreateMatrix_lf(nrows, ncols); + CopyMatrix0(X_dm, Z_dm); + + if (rc=='C' || rc=='c') + { + X = X_dm->M; + nrows = X_dm->nrows; + ncols = X_dm->ncols; + } + else + { + Xtran_dm = tz_TransposeRegular((TSdmatrix *)NULL, X_dm); + X = Xtran_dm->M; + nrows = Xtran_dm->nrows; + ncols = Xtran_dm->ncols; + } + x_sdv.n = nrows; + for (begloc=nrows*(ncols-1), _j=ncols-1; _j>=0; begloc-=nrows, _j--) + { + x_sdv.v = X + begloc; + tz_sort(&x_sdv, 'A'); + z_dv->v[_j] = x_sdv.v[(int)floor(prc*(double)nrows)]; + } + z_dv->flag = V_DEF; + if (rc=='R' || rc=='r') DestroyMatrix_lf(Xtran_dm); + + //=== + DestroyMatrix_lf(X_dm); + + return (z_dv); +} +//--- +TSdvector *tz_mean_matrix(TSdvector *z_dv, TSdmatrix *Z_dm, const char rc) +{ + //Fast method: rc = 'C' (mean for each column). + //Output: %prc percentile (i.e., containing 0% to %prc). + // z_dv: an n-by-1 vector if rc=='C' or an m-by-1 vector if rc=='R'. + // If z_dv==NULL, it will be created and has to be destroyed outside this function. + //Inputs: + // X_dm: an m-by-n general matrix. + // rc == 'C' or 'c': mean for each column. + // rc == 'R' or 'r': mean for each row. + int nrows, ncols, _j, begloc; + TSdvector x_sdv; + double *X; + //=== + TSdmatrix *X_dm = NULL; + TSdmatrix *Xtran_dm = NULL; + + if (!Z_dm || !Z_dm->flag) fn_DisplayError("cstz.c/tz_mean_matrix(): input matrix Z_dm must be (1) created and (2) assigned values"); + x_sdv.flag = V_DEF; + + nrows = Z_dm->nrows; + ncols = Z_dm->ncols; + if (!z_dv) + { + if (rc=='C' || rc=='c') z_dv = CreateVector_lf(ncols); + else z_dv = CreateVector_lf(nrows); + } + else + { + if ((rc=='C' || rc=='c')) + { + if (ncols != z_dv->n) fn_DisplayError("cstz.c/tz_mean_matrix(): z_dv->n must be the same as ncols of X_dm when computing mean for each column"); + } + else + { + if (nrows != z_dv->n) fn_DisplayError("cstz.c/tz_mean_matrix(): z_dv->n must be the same as nrows of X_dm when computing mean for each row"); + } + } + X_dm = CreateMatrix_lf(nrows, ncols); + CopyMatrix0(X_dm, Z_dm); + + if (rc=='C' || rc=='c') + { + X = X_dm->M; + nrows = X_dm->nrows; + ncols = X_dm->ncols; + } + else + { + Xtran_dm = tz_TransposeRegular((TSdmatrix *)NULL, X_dm); + X = Xtran_dm->M; + nrows = Xtran_dm->nrows; + ncols = Xtran_dm->ncols; + } + x_sdv.n = nrows; + for (begloc=nrows*(ncols-1), _j=ncols-1; _j>=0; begloc-=nrows, _j--) + { + x_sdv.v = X + begloc; + z_dv->v[_j] = fn_mean(x_sdv.v, x_sdv.n); + } + z_dv->flag = V_DEF; + if (rc=='R' || rc=='r') DestroyMatrix_lf(Xtran_dm); + + //=== + DestroyMatrix_lf(X_dm); + + return (z_dv); +} +//--------------->> + + + +//<<--------------- +// WZ normalization on VARs. +//--------------->> +void fn_wznormalization(TSdvector *wznmlz_dv, TSdmatrix *A0draw_dm, TSdmatrix *A0peak_dm) +{ + //Outputs: + // wznmlz_dv (n-by-1): If negative, the sign of the equation must switch; if positive: no action needs be taken. + // If NULL as an input, remains NULL. + // A0draw_dm (n-by-n): replaced by wz-normalized draw. + //Inputs: + // wznmlz_dv (n-by-1): if NULL, no output for wznmlz_dv; otherwise, a memory allocated vector. + // A0draw_dm (n-by-n): a draw of A0. + // A0peak_dm (n-by-n): reference point to which normalized A0draw_dm is closest. + int _j, _n, + errflag = -2; + double *v; + TSdmatrix *X_dm = NULL; + TSdvector *diagX_dv = NULL; + + if ( !A0peak_dm ) fn_DisplayError(".../cstz.c/fn_wznormalization(): input matrix for ML estimates must be created (memory allocated) and have legal values"); + //This is a minimum check to prevent crash without error messages. More robust checks are done in BdivA_rgens(). + + _n = A0peak_dm->nrows; + X_dm = CreateMatrix_lf(_n, _n); + + if ( errflag=BdivA_rgens(X_dm, A0peak_dm, '\\', A0draw_dm) ) { + printf(".../cstz.c/fn_wznormalization(): errors when calling BdivA_rgens() with error flag %d", errflag); + exit(EXIT_FAILURE); + } + + if (wznmlz_dv) { + diagdv(wznmlz_dv, X_dm); + v = wznmlz_dv->v; + } + else { + diagX_dv = CreateVector_lf(_n); + diagdv(diagX_dv, X_dm); + v = diagX_dv->v; + } + + + for (_j=_n-1; _j>=0; _j--) + if (v[_j]<0) ScalarTimesColofMatrix((TSdvector *)NULL, -1.0, A0draw_dm, _j); + + //=== Destroys memory allocated for this function only. + DestroyMatrix_lf(X_dm); + DestroyVector_lf(diagX_dv); +} + + + + +//---------------<< +// Handling under or over flows with log values. +//--------------->> +struct TSveclogsum_tag *CreateVeclogsum(int n) +{ + struct TSveclogsum_tag *veclogsum_ps = tzMalloc(1, struct TSveclogsum_tag); + + //=== Memory allocation and initialization. + veclogsum_ps->n = n; //Number of sums or the dimension of logofsum. + veclogsum_ps->N_iv = CreateConstantVector_int(n, 0); //Cumulative. (N_1, ..., N_n). + veclogsum_ps->logsum_dv = CreateConstantVector_lf(n, -MACHINEINFINITY); //Cumulative. (logofsum_1, ..., logofsum_n). + veclogsum_ps->logmax_dv = CreateConstantVector_lf(n, -MACHINEINFINITY); //(logmax_1, ..., logmax_n). + + return (veclogsum_ps); +} +//--- +struct TSveclogsum_tag *DestroyVeclogsum(struct TSveclogsum_tag *veclogsum_ps) +{ + + if (veclogsum_ps) { + DestroyVector_int(veclogsum_ps->N_iv); + DestroyVector_lf(veclogsum_ps->logsum_dv); + DestroyVector_lf(veclogsum_ps->logmax_dv); + + //=== + free(veclogsum_ps); + return ((struct TSveclogsum_tag *)NULL); + } + else return (veclogsum_ps); +} +//=== +//------------------ +//Updating the sum (not divided by n) for the mean and the second moment. +//------------------ +void UpdateSumFor1st2ndMoments(TSdvector *x1stsum_dv, TSdmatrix *X2ndsum_dm, const TSdvector *xdraw_dv) +{ + static int ini_indicator = 0; + + if (!ini_indicator) { + //Pass this loop once and no more. + CopyVector0(x1stsum_dv, xdraw_dv); + VectorTimesSelf(X2ndsum_dm, xdraw_dv, 1.0, 0.0, 'U'); + ini_indicator = 1; + } + else { + VectorPlusVectorUpdate(x1stsum_dv, xdraw_dv); + VectorTimesSelf(X2ndsum_dm, xdraw_dv, 1.0, 1.0, 'U'); + } +} +//--- +int tz_update_logofsum(double *Y_N_dp, double *y_Nmax_dp, double ynew, int N) +{ + //Recursive algorithm to update Y_N (=log(sum of x_i)) for i=1, ..., N with the new value ynew = log(x_{N+1}). + //Returns (1) the updated value Y_{N+1} = log(sum of x_i)) for i=1, ..., N+1; + // (2) the updated value y_(N+1)max_dp; + // (3) the integer N+1. + //See TVBVAR Notes p.81a. + + if (*y_Nmax_dp>=ynew) *Y_N_dp = log( exp(*Y_N_dp - *y_Nmax_dp) + exp(ynew - *y_Nmax_dp) ) + *y_Nmax_dp; + else { + *y_Nmax_dp = ynew; + *Y_N_dp = log( exp(*Y_N_dp - ynew) + 1.0 ) + ynew; + } + + return (N+1); +} +int fn_update_logofsum(int N, double ynew, double *Y_N_dp, double *y_Nmax_dp) +{ + //Recursive algorithm to update Y_N (=log(sum of x_i)) for i=1, ..., N with the new value ynew = log(x_{N+1}). + //Returns (1) the updated value Y_{N+1} = log(sum of x_i)) for i=1, ..., N+1; + // (2) the updated value y_(N+1)max_dp; + // (3) the integer N+1. + //See TVBVAR Notes p.81a. + //If N=0, then ynew = -infty (no value yet) and thus no value is added to *Y_N_dp. + +// if (N>0) +// { + if (*y_Nmax_dp>=ynew) *Y_N_dp = log( exp(*Y_N_dp - *y_Nmax_dp) + exp(ynew - *y_Nmax_dp) ) + *y_Nmax_dp; + else { + *y_Nmax_dp = ynew; + *Y_N_dp = log( exp(*Y_N_dp - ynew) + 1.0 ) + ynew; + } +// } + + return (N+1); +} +double fn_replace_logofsumsbt(double *yold, double _a, double ynew, double _b) +{ + //Outputs: + // *yold is replaced by log abs(a*xold + b*xnew). + // 1.0 or -1.0: sign of a*xold + b*xnew. + // + //Given yold=log(xold) and ynew=log(xnew), it updates and returns yold = log abs(a*xold + b*xnew). + //sbt: subtraction or subtract. + //See TVBVAR Notes p.81a. + double tmpd; + //*yold = (*yold > ynew) ? (log( _a + _b*exp(ynew - *yold)) + *yold) : (log( _a*exp(*yold - ynew) + _b) + ynew); + + if (*yold > ynew) { + if ((tmpd=_a + _b*exp(ynew - *yold) ) < 0.0) { + // printf("WARNING! .../cstz.c/fn_replace_logofsumsbt(): Expression inside log is negative and the function returns the negative sign!\n"); + *yold += log(fabs(tmpd)); + return (-1.0); + } + else { + *yold += log(tmpd); + return (1.0); + } + } + else { + if ((tmpd=_a*exp(*yold - ynew) + _b) < 0.0 ) { + // printf("WARNING! .../cstz.c/fn_replace_logofsumsbt(): Expression inside log is negative and the function returns the negative sign!\n"); + *yold = log(fabs(tmpd)) + ynew; + return (-1.0); + } + else { + *yold = log(tmpd) + ynew; + return (1.0); + } + } +} + + +//<<--------------- +// Evaluating the inverse of the chi-square cumulative distribution function. +//--------------->> +double fn_chi2inv(double p, double df) +{ +#if defined( IMSL_STATISTICSTOOLBOX ) + //Returns x where p = int_{0}^{x} chi2pdf(t, df) dt + if (df<=0.0) fn_DisplayError("cstz.c/fn_chi2inv(): degrees of freedom df must be greater than 0.0"); + + if (p<=0.0) return (0.0); + else if (p>=1.0) return (MACHINEINFINITY); + else return (imsls_d_chi_squared_inverse_cdf(p, df)); +#elif defined( USE_GSL_LIBRARY ) + if (df<=0.0) fn_DisplayError("cstz.c/fn_chi2inv(): degrees of freedom df must be greater than 0.0"); + + if (p<=0.0) return (0.0); + else if (p>=1.0) return (MACHINEINFINITY); + else + return gsl_cdf_chisq_Pinv(p,df); +#else + ***No default routine yet; +#endif +} + + +//<<--------------- +// Evaluating the standard normal cumulative distribution function. +//--------------->> +double fn_normalcdf(double x) +{ +#if defined( IMSL_STATISTICSTOOLBOX ) + return (imsls_d_normal_cdf(x)); +#elif defined( USE_GSL_LIBRARY ) + return gsl_cdf_ugaussian_P(x); +#else + ***No default routine yet; +#endif +} + + +//<<--------------- +// Evaluating the inverse of the standard normal cumulative distribution function. +//--------------->> +double fn_normalinv(double p) +{ +#if defined( IMSL_STATISTICSTOOLBOX ) + return (imsls_d_normal_inverse_cdf(p)); +#elif defined( USE_GSL_LIBRARY ) + return gsl_cdf_ugaussian_Pinv(p); +#else + ***No default routine yet; +#endif +} + + +//<<--------------- +// Evaluating the inverse of the beta cumulative distribution function. +//--------------->> +double fn_betainv(double p, double _alpha, double _beta) +{ +#if defined( IMSL_STATISTICSTOOLBOX ) + //p = int_{0}^{\infty} betapdf(t, _alpha, _beta) dt where betapdf(t,_alpha,_beta) \propt t^{_alpha-1}*(1-t)^(_beta-1}. + return (imsls_d_beta_inverse_cdf(p, _alpha, _beta)); +#elif defined( USE_GSL_LIBRARY) + return gsl_cdf_beta_Pinv(p,_alpha,_beta); +#else + ***No default routine yet; +#endif +} + + +//<<--------------- +// Computes log gamma (x) where gamma(n+1) = n! and gamma(x) = int_0^{\infty} e^{-t} t^{x-1} dt. +//--------------->> +double fn_gammalog(double x) +{ +#if defined( IMSL_STATISTICSTOOLBOX ) + return (imsl_d_log_gamma(x)); +#elif defined( USE_GSL_LIBRARY ) + return gsl_sf_lngamma(x); +#else + ***No default routine yet; +#endif +} + + +//<<--------------- +// Computes log beta(x, y) where beta(x, y) = gamma(x)*gamm(y)/gamma(x+y). +//--------------->> +double fn_betalog(double x, double y) +{ +#if defined( IMSL_STATISTICSTOOLBOX ) + return (imsl_d_log_beta(x, y)); +#elif defined( USE_GSL_LIBRARY ) + return gsl_sf_lnbeta(x,y); +#else + ***No default routine yet; +#endif +} + + + +//<<--------------- +// Computes log gamma (x) where gamma(n+1) = n! and gamma(x) = int_0^{\infty} e^{-t} t^{x-1} dt. +//--------------->> +double gammalog(double x) +{ +#if defined( IMSL_STATISTICSTOOLBOX ) + return (imsl_d_log_gamma(x)); +#elif defined( USE_GSL_LIBRARY ) + return gsl_sf_lngamma(x); +#else + ***No default routine yet; +#endif +} + + +//----------------------------------------------------------------------------------- +//------------------------------ Normal distribution ------------------------------// +//--- p(x) = (1.0/sqrt(2*pi)*sigma) exp( -(1.0/(2.0*sigma^2.0)) (x-mu)^2.0 ) +//--- for sigma>0. +//----------------------------------------------------------------------------------- +#define LOGSQRTOF2PI 9.189385332046727e-001 +double tz_lognormalpdf(double _x, double _m, double _s) +{ + double xmm = _x-_m; + if (_s <= 0.0) return (-NEARINFINITY); + //fn_DisplayError("cstz.c/tz_lognormalpdf(): standard deviation must be positive"); + + return ( -LOGSQRTOF2PI - log(_s) - (1.0/(2.0*square(_s))) * square(xmm) ); +} +#undef LOGSQRTOF2PI + +//----------------------------------------------------------------------------------- +//----------------------------- Beta density function -----------------------------// +//--- p(x) = ( Gamma(a+b)/(Gamma(a)*Gamma(b)) ) x^(a-1) (1-x)^(b-1) for a>0 and b>0. +//--- E(x) = a/(a+b); var(x) = a*b/( (a+b)^2*(a+b+1) ); +//--- The density is finite if a,b>=1. +//--- Noninformative density: (1) a=b=1; (2) a=b=0.5; or (3) a=b=0. +//----------------------------------------------------------------------------------- +double tz_logbetapdf(double _x, double _a, double _b) +{ + if ((_x < 0.0) || (_x > 1.0) || (_a <=0.0) || (_b <= 0.0)) return (-NEARINFINITY); + if ((_x <= 0.0) && (_a != 1.0)) return (-NEARINFINITY); + //Note that it should be +infinity for a < 1.0. We return -infinity anyway for the purpose of giving zero LH. + if ((_x >= 1.0) && (_b != 1.0)) return (-NEARINFINITY); + //Note that it should be +infinity for b < 1.0. We return -infinity anyway for the purpose of giving zero LH. + //fn_DisplayError("cstz.c/tz_logbetapdf(): x must be (0,1) and a, b must be positive"); + + if ((_x == 0.0 && _a == 1.0) || (_x == 1.0 && _b == 1.0)) return (-fn_betalog(_a, _b)); + else return ( -fn_betalog(_a, _b) + (_a-1.0)*log(_x) + (_b-1.0)*log(1.0-_x) ); +} +//----------------------------------------------------------------------------------- +//---------------------------- Gamma distribution ----------------------------------// +//--- p(x) = ( b^a/Gamma(a) ) x^(a-1) exp(-bx) for a>0 and b>0. +//--- where a is shape and b is inverse scale (rate) parameter. +//--- E(x) = a/b; var(x) = a/b^2; +//--- Noninformative distribution: a,b -> 0. +//--- The density function is finite if a >= 1. +//----------------------------------------------------------------------------------- +double tz_loggammapdf(double _x, double _a, double _b) +{ + if (_x < 0.0 || _a <= 0.0 || _b <= 0.0) return (-NEARINFINITY); + if (_x <= 0.0 && _a != 1.0) return (-NEARINFINITY); + //Note that it should be +infinity for a < 1.0. We return -infinity anyway for the purpose of giving zero LH. + //fn_DisplayError("cstz.c/tz_loggammapdf(): x, a, and b must be positive"); + + if (_x == 0.0 && _a == 1.0) return ( _a*log(_b) - fn_gammalog(_a) ); + else return ( _a*log(_b) - fn_gammalog(_a) + (_a-1.0)*log(_x) - _b*_x ); +} +//----------------------------------------------------------------------------------- +//------------------------ Inverse-Gamma distribution ------------------------------// +//--- p(x) = ( b^a/Gamma(a) ) x^(-a-1) exp(-b/x) for a>0 and b>0. +//--- where a is shape and b is scale parameter. +//--- E(x) = b/(a-1) for a>1; var(x) = b^2/( (a-1)^2*(a-2) ) for a>2; +//--- Noninformative distribution: a,b -> 0. +//--- How to draw: (1) draw z from Gamma(a,b); (2) let x=1/z. +//----------------------------------------------------------------------------------- +double tz_loginversegammapdf(double _x, double _a, double _b) +{ + //This denisity is always finite. + //If a < 1.0, 1st moment does not exist, + // a < 2.0, 2nd moment does not exist, + // a < 3.0, 3rd moment does not exist, + // a < 4.0, 4th moment does not exist. + + if (_x < 0.0 || _a <= 0.0 || _b <= 0.0) return (-NEARINFINITY); + //fn_DisplayError("cstz.c/tz_loginversegammapdf(): x, a, and b must be positive"); + + return ( _a*log(_b) - fn_gammalog(_a) - (_a+1.0)*log(_x) - _b /_x ); +} + + + + + + + +//<<--------------- +// P2 algorithm ??????? +//--------------->> +void psqr(double *q, int *m, double x, const double *p, int n) +{ + //Outputs: + // q: n-by-1 vector of + // m: n-by-1 vector of + // x: a random draw. + //------ + //Inputs: + // p: n-by-1 vector of cumulative cut-off probabilties for the error bands. + static double qm, dq; + static int i, dm, dn; + + for (i=0; q[i]<=x && i<n; i++) ; + if (i==0) { q[0]=x; i++; } + if (i==n) { q[n-1]=x; i--; } + for (; i<n; i++) m[i]++; + for (i=1; i<n-1; i++) { + dq = p[i]*m[n-1]; + if (m[i]+1<=dq && (dm=m[i+1]-m[i])>1) { + dn = m[i]-m[i-1]; + dq = ((dn+1)*(qm=q[i+1]-q[i])/dm+ + (dm-1)*(q[i]-q[i-1])/dn)/(dm+dn); + if (qm<dq) dq = qm/dm; + q[i] += dq; + m[i]++; + } else + if (m[i]-1>=dq && (dm=m[i]-m[i-1])>1) { + dn = m[i+1]-m[i]; + dq = ((dn+1)*(qm=q[i]-q[i-1])/dm+ + (dm-1)*(q[i+1]-q[i])/dn)/(dm+dn); + if (qm<dq) dq = qm/dm; + q[i] -= dq; + m[i]--; + } + } +} +void piksrt(double *arr, int n) +{ + //Outputs: + // arr: replaced by new values. + //Inputs: + // arr: n-by-1 vector ?????? + int i, j; + double a; + + for (j=1; j<n; j++) { + a = arr[j]; + for (i=j-1; i>=0 && arr[i]>a; i--) + arr[i+1] = arr[i]; + arr[i+1]=a; + } +} + + + +//---------------------------- Some high-level VAR functions --------------------- +void fn_lev2growthanual(TSdmatrix *levgro_dm, const TSdmatrix *levgrominus1_dm, const TSivector *indxlogper_iv) +{ + //******* It is the user's responsibility to check memory allocations and dimensions of inputs. ******* + //Outputs: + // levgro_dm: nfores-by-nvar matrix of annual growth rates (percent) except interest rates and unemployment rate in level. + //Inputs: + // levgro_dm: nfores-by-nvar matrix of log levels and, say, interest rates already divided by 100. + // levgrominus1_dm: qm-by-nvar matrix in the previous year (not necessarily a calendar year). + // indxlogper_iv: nvar-by-1 array of 1, 2, or 4 for the list of endogenous variables. 1: decimal point with annual rate like the interest rate; 2: decimal point (NOT at annual rate) like the unemployment rate; 4: log level value. + int ti, vj, qm, nvar, nfores, totrows; + TSdmatrix *tf_levgroplus_dm = NULL; + + if ((qm=levgrominus1_dm->nrows) != 12 && qm != 4) fn_DisplayError("fn_lev2growthanual(): the second input must have 12 or 4 rows for monthly or quarterly data"); + if ((nvar=levgrominus1_dm->ncols) != indxlogper_iv->n || nvar != levgro_dm->ncols) fn_DisplayError("fn_lev2growthanual(): column dimensions and vector dimension of all inputs must be same"); + + //=== Memory allocation for this function. + tf_levgroplus_dm = CreateMatrix_lf(qm+(nfores=levgro_dm->nrows), nvar=levgrominus1_dm->ncols); + + + CopySubmatrix0(tf_levgroplus_dm, (TSdmatrix *)levgrominus1_dm, 0, 0, qm, nvar); + CopySubmatrix(tf_levgroplus_dm, qm, 0, levgro_dm, 0, 0, nfores, nvar); + totrows = qm + nfores; + for (vj=nvar-1; vj>=0; vj--) { + switch (indxlogper_iv->v[vj]) { + case 4: + for (ti=nfores-1; ti>=0; ti--) + levgro_dm->M[mos(ti, vj, nfores)] = 100.0*( exp(tf_levgroplus_dm->M[mos(ti+qm, vj, totrows)] - tf_levgroplus_dm->M[mos(ti, vj, totrows)]) - 1.0 ); + break; + case 2: + case 1: + for (ti=nfores-1; ti>=0; ti--) + levgro_dm->M[mos(ti, vj, nfores)] *= 100.0; + break; + default: + fn_DisplayError("fn_lev2growthanual(): the input vector, indxlogper_iv, must have the integer values 4, 2, and 1"); + } + } + + + + //=== Destroys memory allocated for this function. + tf_levgroplus_dm = DestroyMatrix_lf(tf_levgroplus_dm); +} + + + +//------------------- +// Generating a counterfactual paths conditional on S_T and specified shocks_t(s_t) for _sm (a switching model). +//------------------- +void fn_ctfals_givenshocks_sm(TSdmatrix *ctfalstran_dm, TSdvector *xprimeminus1_dv, const int bloc, const int eloc, const TSdmatrix *strshockstran_dm, + const TSivector *S_Tdraw_iv, const TSdcell *Bsdraw_dc, const TSdcell *A0sdrawinv_dc, const TSivector *noshocks_iv) +{ + //******* It is the user's responsibility to check memory allocations and dimensions of inputs. ******* + //Outputs: ctflasdrawtran = xprimeminus1*Bsdraw{s} + shocks'*A0sdrawinv{s}. + // ctfalstran_dm: nvar-by-nfores where nfores (=eloc-bloc+1) is the forecast horizon. Conterfactual paths of nvar variables. + // xprimeminus1_dv: updated 1-by-ncoef right-hand-side variables at the end of the forecast horizon, ready for the forecasts at the step nfores+1. + // In the order of [nvar for 1st lag, ..., nvar for last lag, other exogenous terms, const term]. + //Inputs: + // xprimeminus1_dv: 1-by-ncoef vector of right-hand-side variables at the beginning of the forecast horizon. + // bloc: beginning location for the forecast horizon. + // eloc: end location for the forecast horizon. + // strshockstran_dm: nvar-by-T. Matrix transpose of unit-variance (time-invariant) structural shocks. + // S_Tdraw_iv: fss-by-1 or SampleSize-by-1 vector of (s_t|I_T,theta). + // Bsdraw_dc: nStates cells. For each cell, ncoef-by-nvar reduced-form coefficient matrix. + // A0sdrawinv_dc: nStates cells. For each cell, nvar-by-nvar inverse of contemporaneous coefficient matrix. + // noshocks_iv: a (no greater than nvar) vector of base-0 integers indicating the corresponding equations whose shocks are set + // to zero. Each element of this integer vector must be less than nvar. + int ti, si, vi; + int nfores = eloc - bloc + 1, + nvar = ctfalstran_dm->nrows, + ncoefminusnvar7const = Bsdraw_dc->C[0]->nrows - nvar - 1; + TSdvector ctfals_sdv, strshocks_sdv; + TSivector STnfores_siv; //nfores-by-1 vector of s_t's. + + if (nfores < 1) fn_DisplayError("cstz.c/fn_ctfals_givenshocks_sm(): Number of forecast steps must be greater than 0"); + if (eloc > strshockstran_dm->ncols-1) fn_DisplayError("cstz.c/fn_ctfals_givenshocks_sm(): End location in the forecast horizon must be no greater than the sample size"); + if (nvar != strshockstran_dm->nrows) fn_DisplayError("cstz.c/fn_ctfals_givenshocks_sm(): the number of rows of strshockstran_dm must be equal to nvar"); + + + //******* WARNING: The operation involves ctfals_sdv.v, strshocks_sdv.v, STnfores_siv.v ******* + //******* throughout this function is dangerous because of pointer movements. ******* + //******* But it gives us efficiency. ******* + ctfals_sdv.n = nvar; + ctfals_sdv.v = ctfalstran_dm->M; //Points to the beginning of the 1st column of ctfalstran_dm. + //+ + strshocks_sdv.n = nvar; + strshocks_sdv.flag = V_DEF; + strshocks_sdv.v = strshockstran_dm->M + strshockstran_dm->nrows*bloc; //Points to the beginning of the bloc_th column of strshockstran_dm. + for (vi=noshocks_iv->n-1; vi>=0; vi--) + strshocks_sdv.v[noshocks_iv->v[vi]] = 0.0; //Set shocks in those equations to be zero. + //+ + STnfores_siv.n = nfores; + STnfores_siv.flag = V_DEF; + STnfores_siv.v = S_Tdraw_iv->v + bloc; //Points to the bloc_th position of S_Tdraw_iv. + + + for (ti=0; ti<nfores; ti++) { + //Must have a forward recursion. + VectorTimesMatrix(&ctfals_sdv, xprimeminus1_dv, Bsdraw_dc->C[si=STnfores_siv.v[ti]], 1.0, 0.0, 'N'); + VectorTimesMatrix(&ctfals_sdv, &strshocks_sdv, A0sdrawinv_dc->C[si], 1.0, 1.0, 'N'); + //=== Updates the recursion. The order matters. + memmove(xprimeminus1_dv->v+nvar, xprimeminus1_dv->v, ncoefminusnvar7const*sizeof(double)); + memcpy(xprimeminus1_dv->v, ctfals_sdv.v, nvar*sizeof(double)); + //+ + if (ti < nfores-1) //This is needed to prevent memory leak at the end when we have strshocks_sdv.v[noshocks_iv->v[vi]] = 0.0. + { + ctfals_sdv.v += nvar; //Points to the beginning of the next column of ctfalstran_dm. + strshocks_sdv.v += nvar; //Points to the beginning of the next column of strshockstran_dm. + for (vi=noshocks_iv->n-1; vi>=0; vi--) + strshocks_sdv.v[noshocks_iv->v[vi]] = 0.0; //Set shocks in those equations to be zero. + } + } + + ctfalstran_dm->flag = M_GE; +} + + +//------------------- +// Generating a random sequence of counterfactual (ctfal) paths for _sm (a switching model). +//------------------- +void fn_ctfals_sm(TSdmatrix *ctfalstran_dm, TSdvector *xprimeminus1_dv, const int bloc, const int eloc, const TSdmatrix *strshockstran_dm, const TSivector *Snfores_iv, const TSdcell *Bsdraw_dc, const TSdcell *A0sdrawinv_dc) +{ + //******* It is the user's responsibility to check memory allocations and dimensions of inputs. ******* + //Outputs: ctflasdrawtran = xprimeminus1*Bsdraw{s} + shocks'*A0sdrawinv{s}. + // ctfalstran_dm: nvar-by-nfores where nfores (=eloc-bloc+1) is the forecast horizon. Conterfactual paths of nvar variables. + // xprimeminus1_dv: updated 1-by-ncoef right-hand-side variables at the end of the forecast horizon, ready for the forecasts at the step nfores+1. + // In the order of [nvar for 1st lag, ..., nvar for last lag, other exogenous terms, const term]. + //Inputs: + // xprimeminus1_dv: 1-by-ncoef vector of right-hand-side variables at the beginning of the forecast horizon. + // bloc: beginning location for the forecast horizon. + // eloc: end location for the forecast horizon. + // strshockstran_dm: nvar-by-T. Matrix transpose of unit-variance (time-invariant) structural shocks. + // Snfores_iv: nfores-by-1 vector of states where each element is less than nStates. + // Bsdraw_dc: nStates cells. For each cell, ncoef-by-nvar reduced-form coefficient matrix. + // A0sdrawinv_dc: nStates cells. For each cell, nvar-by-nvar inverse of contemporaneous coefficient matrix. + int ti, si; + int nfores = eloc - bloc + 1, + nvar = ctfalstran_dm->nrows, + ncoefminusnvar7const = Bsdraw_dc->C[0]->nrows - nvar - 1; + TSdvector ctfals_sdv, strshocks_sdv; + + if (nfores < 1) fn_DisplayError("cstz.c/fn_ctfals_sm(): Number of forecast steps must be greater than 0"); + if (eloc > strshockstran_dm->ncols-1) fn_DisplayError("cstz.c/fn_ctfals_sm(): End location in the forecast horizon must be no greater than the sample size"); + if (nvar != strshockstran_dm->nrows) fn_DisplayError("cstz.c/fn_ctfals_sm(): the number of rows of strshockstran_dm must be equal to nvar"); + + + //******* WARNING: The operation involves ctfals_sdv.v and strshocks_sdv.v throughout this function ******* + //******* is dangerous because of pointer movements. But it gives us efficiency. ******* + ctfals_sdv.n = nvar; + ctfals_sdv.v = ctfalstran_dm->M; //Points to the beginning of the 1st column of ctfalstran_dm. + strshocks_sdv.n = nvar; + strshocks_sdv.flag = V_DEF; + strshocks_sdv.v = strshockstran_dm->M + strshockstran_dm->nrows*bloc; //Points to the beginning of the bloc_th column of strshockstran_dm. + + + for (ti=0; ti<nfores; ti++) { + //Must have a forward recursion. + VectorTimesMatrix(&ctfals_sdv, xprimeminus1_dv, Bsdraw_dc->C[si=Snfores_iv->v[ti]], 1.0, 0.0, 'N'); + VectorTimesMatrix(&ctfals_sdv, &strshocks_sdv, A0sdrawinv_dc->C[si], 1.0, 1.0, 'N'); + //=== Updates the recursion. The order matters. + memmove(xprimeminus1_dv->v+nvar, xprimeminus1_dv->v, ncoefminusnvar7const*sizeof(double)); + memcpy(xprimeminus1_dv->v, ctfals_sdv.v, nvar*sizeof(double)); + //+ + ctfals_sdv.v += nvar; //Points to the beginning of the next column of ctfalstran_dm. + strshocks_sdv.v += nvar; //Points to the beginning of the next column of strshockstran_dm. + } + + ctfalstran_dm->flag = M_GE; +} + +//------------------- +// Generating a random sequence of counterfactual (ctfal) paths with only monetary policy equation changing to a specified regime while holding other equations' regimes the same as historical ones. +//------------------- +void fn_ctfals_policyonly(TSdmatrix *ctfalstran_dm, TSdvector *xprimeminus1_dv, const int bloc, const int eloc, const TSdmatrix *strshockstran_dm, const TSivector *S_Tdraw_iv, const int statecon, const int selej, const TSdcell *A0sdraw_dc, const TSdcell *Apsdraw_dc) +{ + //******* It is the user's responsibility to check memory allocations and dimensions of inputs. ******* + //Outputs: ctflasdrawtran = xprimeminus1*Bsdraw{s} + shocks'*A0sdrawinv{s}. + // ctfalstran_dm: nvar-by-nfores where nfores (=eloc-bloc+1) is the forecast horizon. Conterfactual paths of nvar variables. + // xprimeminus1_dv: updated 1-by-ncoef right-hand-side variables at the end of the forecast horizon, ready for the forecasts at the step nfores+1. + // In the order of [nvar for 1st lag, ..., nvar for last lag, other exogenous terms, const term]. + //Inputs: + // xprimeminus1_dv: 1-by-ncoef vector of right-hand-side variables at the beginning of the forecast horizon. + // bloc: beginning location for the forecast horizon. + // eloc: end location for the forecast horizon. + // strshockstran_dm: nvar-by-T. Matrix transpose of unit-variance (time-invariant) structural shocks. + // S_Tdraw_iv; fss-by-1 or SampleSize-by-1. Stores (s_t|I_T,theta). + // statecon: the ith state conditioned for counterfactuals (base 0). Must be < nStates. + // selej: location (base 0) of the selected structural equation (e.g., the monetary policy equation). Only for (1) long-run and short-run responses and (2) counterfactuals with only policy equation at specific state imposed. + // A0sdraw_dc: nStates cells. For each cell, nvar-by-nvar contemporaneous coefficient matrix. + // Apsdraw_dc: nStates cells. For each cell, ncoef-by-nvar lagged structural coefficient matrix. + int ti, si; + int errflag = -2, //Initialized to be unsuccessful. When 0, successful. + nfores = eloc - bloc + 1, + nvar = ctfalstran_dm->nrows, + ncoef = Apsdraw_dc->C[0]->nrows, + nStates = Apsdraw_dc->ncells, + ncoefminusnvar7const = ncoef - nvar - 1; + TSdvector ctfals_sdv, strshocks_sdv; + TSivector sact_nfores_siv; + // + TSivector *tf_rnstates_iv = CreateConstantVector_int(nStates, nvar), //nStates-by-1: ncoef for each element for *p*_dc or nvar for each elment for *0*_dc. + *tf_cnstates_iv = CreateConstantVector_int(nStates, nvar); //nStates-by-1: nvar for each element for both *p*_dc and *0*_dc. + TSdcell *tf_A0sinv_dc = NULL; + TSdcell *tf_Aps_dc = NULL, + *tf_Bs_dc = NULL; + + + + if (nfores < 1) fn_DisplayError("cstz.c/fn_ctfals_policyonly(): Number of forecast steps must be greater than 0"); + if (eloc > strshockstran_dm->ncols-1) fn_DisplayError("cstz.c/fn_ctfals_policyonly(): End location in the forecast horizon must be no greater than the sample size"); + if (nvar != strshockstran_dm->nrows) fn_DisplayError("cstz.c/fn_ctfals_policyonly(): the number of rows of strshockstran_dm must be equal to nvar"); + + + //=== Memory allocation. + tf_A0sinv_dc = CreateCell_lf(tf_rnstates_iv, tf_cnstates_iv); //Note rnstates_iv and cnstates_iv are already assigned right values. + //+ + for (si=nStates-1; si>=0; si--) tf_rnstates_iv->v[si] = ncoef; //Note rnstates_iv is already assigned right values. + tf_Aps_dc = CreateCell_lf(tf_rnstates_iv, tf_cnstates_iv); + tf_Bs_dc = CreateCell_lf(tf_rnstates_iv, tf_cnstates_iv); + + + //******* WARNING: The operation involves ctfals_sdv.v and strshocks_sdv.v throughout this function ******* + //******* is dangerous because of pointer movements. But it gives us efficiency. ******* + ctfals_sdv.n = nvar; + ctfals_sdv.v = ctfalstran_dm->M; //Points to the beginning of the 1st column of ctfalstran_dm. + strshocks_sdv.n = nvar; + strshocks_sdv.flag = V_DEF; + strshocks_sdv.v = strshockstran_dm->M + strshockstran_dm->nrows*bloc; //Points to the beginning of the bloc_th column of strshockstran_dm. + //+ + sact_nfores_siv.n = nfores; + sact_nfores_siv.flag = V_DEF; + sact_nfores_siv.v = S_Tdraw_iv->v + bloc; //Points to the beginning of the bloc_th element of S_Tdraw_iv. + + //=== Sticks the policy equation at the statecon_th state to A0s and A0p. + for (si=nStates-1; si>=0; si--) { + CopyMatrix0(tf_A0sinv_dc->C[si], A0sdraw_dc->C[si]); //tf_A0sinv_dc is A0s for a moment. + CopyMatrix0(tf_Aps_dc->C[si], Apsdraw_dc->C[si]); + //=== Sticks the specified regime statecon in the counterfactual period. + CopySubmatrix(tf_A0sinv_dc->C[si], 0, selej, A0sdraw_dc->C[statecon], 0, selej, nvar, 1); + CopySubmatrix(tf_Aps_dc->C[si], 0, selej, Apsdraw_dc->C[statecon], 0, selej, ncoef, 1); + + if ( errflag=BdivA_rgens(tf_Bs_dc->C[si], tf_Aps_dc->C[si], '/', tf_A0sinv_dc->C[si]) ) { + //tf_A0sinv_dc is at this moment tf_A0s_dc. + printf(".../cstz.c/fn_ctfals_policyonly(): tf_Bs_dc->C[si] -- errors when calling BdivA_rgens() with error flag %d", errflag); + exit(EXIT_FAILURE); + } + if ( errflag=invrgen(tf_A0sinv_dc->C[si], tf_A0sinv_dc->C[si]) ) { + printf(".../cstz.c/fn_ctfals_policyonly(): tf_A0sinv_dc->C -- errors when calling invrgen() with error flag %d", errflag); + exit(EXIT_FAILURE); + } + } + + for (ti=0; ti<nfores; ti++) { + //Must have a forward recursion. + VectorTimesMatrix(&ctfals_sdv, xprimeminus1_dv, tf_Bs_dc->C[si=sact_nfores_siv.v[ti]], 1.0, 0.0, 'N'); + VectorTimesMatrix(&ctfals_sdv, &strshocks_sdv, tf_A0sinv_dc->C[si], 1.0, 1.0, 'N'); + //=== Updates the recursion. The order matters. + memmove(xprimeminus1_dv->v+nvar, xprimeminus1_dv->v, ncoefminusnvar7const*sizeof(double)); + memcpy(xprimeminus1_dv->v, ctfals_sdv.v, nvar*sizeof(double)); + //+ + ctfals_sdv.v += nvar; //Points to the beginning of the next column of ctfalstran_dm. + strshocks_sdv.v += nvar; //Points to the beginning of the next column of strshockstran_dm. + } + + ctfalstran_dm->flag = M_GE; + + //=== Destroys memory allocated for this function. + tf_rnstates_iv = DestroyVector_int(tf_rnstates_iv); + tf_cnstates_iv = DestroyVector_int(tf_cnstates_iv); + tf_A0sinv_dc = DestroyCell_lf(tf_A0sinv_dc); + tf_Aps_dc = DestroyCell_lf(tf_Aps_dc); + tf_Bs_dc = DestroyCell_lf(tf_Bs_dc); +} + + +#if defined (INTELCMATHLIBRARY) +void fn_impulse(TSdmatrix *imftran_dm, const TSdmatrix *Bh_dm, const TSdmatrix *swishtran_dm, const int nlags, const int imsteps) +{ + //Outputs (memory allocated already): + // imftran_dm: nvar^2-by-imsteps where imf_dm (imsteps-by-nvar^2) is in the same format as in RATS. + // Rows: nvar responses to the 1st shock, ..., nvar responses to the last shock. + // Columns: steps of impulse responses. + //Inputs: + // Bh_dm: ldbh-by-nvar reduced-form coefficient matrix (where ldbh is the leading dimension of Bh_dm and must be at least nvar*nlags) of the form: + // Y(T*nvar) = X*Bh_dm + U, X: T*ldbh(ldbh may include all exogenous terms). Note that columns corresponding equations. + // Columns of Bh_dm: nvar variables for the 1st lag, ..., nvariables for the last lag + (possible exogenous terms) + const = ldbh. + // swishtran_dm: transponse of nvar-by-nvar inv(A0) in the structural model y(t)A0 = e(t). + // nlags: lag length (number of lags); + // imsteps: steps for impulse responses. + + int i, j, + nvar, nvar2, ldbh, jmax; + double *Bh, *imftran; + + if (!imftran_dm) fn_DisplayError(".../fn_impulse(): the output impulse matrix imftran_dm must be created (memory-allocated)"); + else if (!Bh_dm || !swishtran_dm) fn_DisplayError(".../fn_impulse(): the input matrices Bh_dm and swich_dm must be created (memory-allocated)"); + else if (!Bh_dm->flag || !swishtran_dm->flag) fn_DisplayError(".../fn_impulse(): the input matrices Bh_dm and swich_dm must be given legal values"); + else if (nlags < 1) fn_DisplayError(".../fn_impulse(): the lag length, nlags, must be equal to or greater than 1"); + else if (imsteps <1) fn_DisplayError(".../fn_impulse(): the number of steps for impulse responses, imsteps, must be must be equal to or greater than 1"); + else if ((nvar = swishtran_dm->nrows) != swishtran_dm->ncols ) fn_DisplayError(".../fn_impulse(): the input matrix, swishtran_dm, must be square"); + else if (nvar != Bh_dm->ncols) fn_DisplayError(".../fn_impulse(): the number of columns in Bh_dm must equal to the number of equations or endogenous variables"); + else if (square(nvar) != imftran_dm->nrows || imsteps != imftran_dm->ncols) fn_DisplayError(".../fn_impulse(): Dimension of impulse matrix input matrix imftran_dm is incompatible with other input matrices or with the number of steps"); + + //if ( !(imftran_dm->flag & M_CN) && imftran_dm[0] !=0.0 ) InitializeConstantMatrix_lf(imftran_dm, 0.0); + InitializeConstantMatrix_lf(imftran_dm, 0.0); //Cumulative. Always initialize it to zero. + + + nvar2 = square(nvar); + Bh = Bh_dm->M; + imftran = imftran_dm->M; + + + if ((ldbh=Bh_dm->nrows) < nvar*nlags) fn_DisplayError("Input matrix Bh_dm must have at least nvar*nlags rows"); + cblas_dcopy(nvar2, swishtran_dm->M, 1, imftran, 1); + for (i=1; i<imsteps; i++) { + jmax = i<nlags?i:nlags; + for (j=0; j<jmax; j++) { + cblas_dgemm(CblasColMajor, CblasTrans, CblasNoTrans, nvar, nvar, nvar, + 1.0, &Bh[j*nvar], ldbh, &imftran[(i-j-1)*nvar2], nvar, + 1.0, &imftran[i*nvar2], nvar); + } + } + + + imftran_dm->flag = M_GE; +} +#else +//No default routine yet. 7 Oct 2003 +#endif + + +TSdmatrix *tz_impulse2levels(TSdmatrix *imflev_dm, TSdmatrix *imf_dm, TSivector *vlist2levels_iv) +{ + //Converting imf_dm to the level impulse responses imflev_dm according to vlist2levels_iv. + //If imflev_dm = imf_dm, then the value of imf_dm will be replaced by the new value. + // + //imf_dm; nsteps-by-nvar^2 where + // rows: steps of impulse responses; + // columns: nvar responses to the 1st shock, ..., nvar responses to the last shock. + //vlist2levels_iv; must be in ascending order. A list of base-0 variables to be converted to levels. Example: [0 1 3] + int _i, _j, _t; + int largestvar; //last variable corresponding to the largest number. + int _n, nsq, imsteps; + TSdvector imf_sdv; + TSdvector imflev_sdv; + + if (!imf_dm || !imf_dm->flag) + fn_DisplayError(".../cstz.c/tz_impulse2levels(): the input matrix imf_dm must be (1) allocated memory and (2) given legal values"); + + if (!imflev_dm) { + imflev_dm = CreateMatrix_lf(imf_dm->nrows, imf_dm->ncols); + imflev_dm->flag = M_GE; //Legal values will be given below. + } + else if (imflev_dm != imf_dm ) + if ( (imflev_dm->nrows != imf_dm->nrows) || (imflev_dm->ncols != imf_dm->ncols)) + fn_DisplayError(".../cstz.c/tz_impulse2levels(): dimensions of the input matrix imf_dm and the output matrix imflev_dm must match exactly"); + else imflev_dm->flag = M_GE; //Legal values will be given below. + + largestvar = vlist2levels_iv->v[vlist2levels_iv->n-1]+1; + _n = (int)floor(sqrt(imf_dm->ncols)+0.5); + nsq = imf_dm->ncols; + if ( square(largestvar) > nsq) + fn_DisplayError(".../cstz.c/tz_impulse2levels(): the last specified variable in vlist2levels_iv is out of the range of impulse responses"); + + + imflev_sdv.n = imf_sdv.n = imf_dm->nrows; + imflev_sdv.flag = imf_sdv.flag = V_DEF; //Legal values will be given below. + imsteps = imf_dm->nrows; + for (_i=vlist2levels_iv->n-1; _i>=0; _i--) + for (_j=vlist2levels_iv->v[_i]; _j<nsq; _j += _n) { + imflev_sdv.v = imflev_dm->M + _j*imsteps; + imf_sdv.v = imf_dm->M + _j*imsteps; + imflev_sdv.v[0] = imf_sdv.v[0]; + for (_t=1; _t<imsteps; _t++) + imflev_sdv.v[_t] = imflev_sdv.v[_t-1] + imf_sdv.v[_t]; + } + + return (imflev_dm); +} + + +void DynamicResponsesForStructuralEquation(TSdmatrix *Resps_dm, const int loclv, const int nlags, const TSdvector *a0p_dv) +{ + //Outputs: + // Resps_dm: k-by-nvar where k responses of the loclv_th variable to the _ith variable for _i=1:nvar. + // The loclv_th column of Resps_dm is meaningless but as a debug check should be close to -1 for the kth responses as k->\infty. + //Inputs: + // loclv: loction of the left-hand variable either in difference (growth) or level. + // nlags: number of lags. + // a0p_dv: m-by-1 vector of [a0 a+] either in difference (growth) or level for the strctural equation considered where m>= (nlags+1)*nvar because m may + // include the constant term. Note a0 is on the left hand side of the equation and a+ is on the right hand side of the equation. + int vi, li; + int nvar, K; + double tmpdsum, c0, a0inv; + TSdvector resps_sdv; //k-by-1. + //---- + TSdvector *a1_dv = NULL; //nlags-by-1. + + if (!Resps_dm || !a0p_dv || !a0p_dv->flag) fn_DisplayError(".../cstz/DynamicResponsesForStructuralEquation(): (1) both input vector and output matrix must be allocated memory; (2) the input vector must have legal values"); + if (a0p_dv->n < (nlags+1)*(nvar=Resps_dm->ncols)) fn_DisplayError(".../cstz/DynamicResponsesForStructuralEquation(): the length of the input vector must be at least (nvar+1)*nlags"); + if (loclv >= nvar || loclv < 0) fn_DisplayError(".../cstz/DynamicResponsesForStructuralEquation(): the location for the left-hand-side variable must be between 0 and number of variables-1, inclusive"); + a1_dv = CreateVector_lf(nlags); + a1_dv->flag = V_DEF; //which will be given legal values below. + + resps_sdv.n = K = Resps_dm->nrows; + resps_sdv.flag = V_UNDEF; + + a0inv = 1.0/a0p_dv->v[loclv]; + for (li=nlags; li>=1; li--) //Note li=1; li<=nlags, NOT li=0; li<nlags. + a1_dv->v[li-1] = a0p_dv->v[loclv+nvar*li]*a0inv; + //Constructing the lagged coefficients for the loclv_th variable. + for (vi=nvar-1; vi>=0; vi--) { + //=== Constructing the constant term. + tmpdsum = - a0p_dv->v[vi]; //Assigned to -a_0. + for (li=nlags; li>=1; li--) //Note li=1; li<=nlags, NOT li=0; li<nlags. + tmpdsum += a0p_dv->v[vi+nvar*li]; + c0 = tmpdsum*a0inv; + //Done with t* array. + + //=== Getting dynamic responses to the vi_th variable. + resps_sdv.v = Resps_dm->M + vi*K; + DynamicResponsesAR(&resps_sdv, c0, a1_dv); + } + Resps_dm->flag = M_GE; + + + //=== Destroys memory allocated for this function only. + a1_dv = DestroyVector_lf(a1_dv); +} + + + +void DynamicResponsesAR(TSdvector *resps_dv, const double c0, const TSdvector *a1_dv) +{ + //Outputs: + // resps_dv: k-by-1 where k responses r_{t+1} to r_{t+k} are computed from r_{t+1} = c0 + a1'*[r_t; ...; r_{t-nlags+1}]. + //Inputs: + // c0: constant term. + // a1_dv: nlags-by-1 vector of coefficients in the AR process. + int ti; + int k, nlags; + double *rv; + TSdvector *rlags_dv = NULL; + + if (!resps_dv || !a1_dv || !a1_dv->flag) fn_DisplayError(".../cstz/DynamicResponsesAR(): (1) both input and output vectors must be allocated memory; (2) the input vector must have legal values"); + rlags_dv = CreateConstantVector_lf(nlags=a1_dv->n, 0.0); + + rv = resps_dv->v; + k = resps_dv->n; + + *(rlags_dv->v) = *rv = c0; + + + for (ti=1; ti<k; ti++) { + //Note ti=1, NOT ti=0. + rv[ti] = c0 + VectorDotVector((TSdvector *)a1_dv, rlags_dv); + //=== Updating rlags_dv. + memmove(rlags_dv->v+1, rlags_dv->v, (nlags-1)*sizeof(double)); + *(rlags_dv->v) = rv[ti]; + } + resps_dv->flag = V_DEF; + + //=== Destroys memory allocated for this function only. + rlags_dv = DestroyVector_lf(rlags_dv); +} + + + + + +//---------------------------- Some regular vector or matrix operations --------------------- +double MinVector_lf(TSdvector *x_dv) { + //Input: no change for x_dv in this function. + int _i, n; + double minvalue; + double *v; + + if (!x_dv || !x_dv->flag) fn_DisplayError(".../cstz.c/MinVector_lf(): Input vector x_dv must be (1) allocated memory and (2) assigned legal values"); + n = x_dv->n; + v = x_dv->v; + + minvalue = v[0]; + for (_i=n-1; _i>0; _i--) + if (v[_i]<minvalue) minvalue = v[_i]; + + return( minvalue ); +} + +TSdvector *ConvertVector2exp(TSdvector *y_dv, TSdvector *x_dv) +{ + //y=exp(x): output vector. If NULL, y will be created and memory-allocated. + //x: input vector. + TSdvector *z_dv=NULL; + #if !defined (INTELCMATHLIBRARY) + int _i; + #endif + + + if (!x_dv || !x_dv->flag) fn_DisplayError(".../cstz.c/ConvertVector2exp(): input vector must be (1) created and (2) given legal values"); + + #if defined (INTELCMATHLIBRARY) + + if (!y_dv) + { + z_dv = CreateVector_lf(x_dv->n); + vdExp(x_dv->n, x_dv->v, z_dv->v); + z_dv->flag = V_DEF; + return (z_dv); + } + else if (x_dv!=y_dv) + { + vdExp(x_dv->n, x_dv->v, y_dv->v); + y_dv->flag = V_DEF; + return (y_dv); + } + else + { + z_dv = CreateVector_lf(x_dv->n); + vdExp(x_dv->n, x_dv->v, z_dv->v); + z_dv->flag = V_DEF; + CopyVector0(x_dv, z_dv); + DestroyVector_lf(z_dv); + return (x_dv); + } + + #else + + if (!y_dv) z_dv = CreateVector_lf(x_dv->n); + else z_dv = y_dv; + for (_i=x_dv->n-1; _i>=0; _i--) z_dv->v[_i] = exp(x_dv->v[_i]); + z_dv->flag = V_DEF; + return (z_dv); + + #endif +} +//--- +TSdvector *ConvertVector2log(TSdvector *y_dv, TSdvector *x_dv) +{ + //y=log(x): output vector. If NULL, y will be created and memory-allocated. + //x: input vector. + TSdvector *z_dv=NULL; + #if !defined (INTELCMATHLIBRARY) + int _i; + #endif + + + if (!x_dv || !x_dv->flag) fn_DisplayError(".../cstz.c/ConvertVector2exp(): input vector must be (1) created and (2) given legal values"); + + #if defined (INTELCMATHLIBRARY) + + if (!y_dv) + { + z_dv = CreateVector_lf(x_dv->n); + vdLn(x_dv->n, x_dv->v, z_dv->v); + z_dv->flag = V_DEF; + return (z_dv); + } + else if (x_dv!=y_dv) + { + vdLn(x_dv->n, x_dv->v, y_dv->v); + y_dv->flag = V_DEF; + return (y_dv); + } + else + { + z_dv = CreateVector_lf(x_dv->n); + vdLn(x_dv->n, x_dv->v, z_dv->v); + z_dv->flag = V_DEF; + CopyVector0(x_dv, z_dv); + DestroyVector_lf(z_dv); + return (x_dv); + } + + #else + + if (!y_dv) z_dv = CreateVector_lf(x_dv->n); + else z_dv = y_dv; + for (_i=x_dv->n-1; _i>=0; _i--) z_dv->v[_i] = log(x_dv->v[_i]); + z_dv->flag = V_DEF; + return (z_dv); + + #endif +} + +double tz_normofvector(TSdvector *x_dv, double p) +{ + double norm = 0.0; + int ki, _n; + double *v; + + if ( !x_dv || !x_dv->flag ) fn_DisplayError("/cstz.c/tz_normofvector(): Input x_dv must have (1) memory and (2) legal values"); + if (p<1.0) fn_DisplayError("/cstz.c/tz_normofvector(): The input p must be no less than 1.0"); + _n = x_dv->n; + v = x_dv->v; + + if (p==2.0) + { + for (ki=_n-1; ki>=0; ki--) norm += v[ki]*v[ki]; + norm = sqrt(norm); + } + else + { + printf("\n/cstz.c/tz_normofvector(): HELLO I TRICK YOU and YOU MUST DO fabs(p-2.0)<MICHINEZERO!!!!!!\n"); //???? + if (p==1.0) + for (ki=_n-1; ki>=0; ki--) norm += fabs(v[ki]); + else + { + for (ki=_n-1; ki>=0; ki--) norm += pow(fabs(v[ki]), p); + norm = pow(norm, 1.0/p); + } + } + + return (norm); +} + + + +//---------------------------- Not used often --------------------- +void fn_cumsum(double **aos_v, int *aods_v, double *v, int d_v) { + // Compute a cumulative sum of a vector. + // + // v: an n-by-1 vector. + // d_v: n -- size of the vector v to be used for a cumulative sum. + // aos_v: address of the pointer to the n-by-1 vector s_v. + // aods_v: address of the size of the dimension of s_v. + //---------- + // *aos_v: An n-by-1 vector of cumulative sum s_v. + // *aods_v: n -- size of the dimension for s_v. + + int ki; + + *aos_v = tzMalloc(d_v, double); + (*aods_v) = d_v; // n for the n-by-1 vector s_v. + *(*aos_v) = *v; + if (d_v>1) { + for (ki=1; ki<d_v; ki++) (*aos_v)[ki] = (*aos_v)[ki-1] + v[ki]; + } +} + + + +/** +void fn_ergodp(double **aop, int *aod, mxArray *cp) { + // Compute the ergodic probabilities. See Hamilton p.681. + // + // cp: n-by-n Markovian transition matrix. + // aop: address of the pointer to the n-by-1 vector p. + // aod: address of the size of the dimension of p. + //---------- + // *aop: n-by-1 vector of ergodic probabilities p. @@Must be freed outside this function.@@ + // *aod: n -- size of the dimension for p (automatically supplied within this function). + + mxArray *gpim=NULL, *gpid=NULL; // m: n-by-n eigvector matrix; d: n-by-n eigvalue diagonal. + double *gpim_p, *gpid_p; // _p: a pointer to the corresponding mxArray whose name occurs before _p. + //------- Note the following two lines will cause Matlab or C to crash because gpim has not been initialized so it points to garbage. + // double *gpim_p = mxGetPr(gpim); + // double *gpid_p = mxGetPr(gpid); + int eigmaxindx, // Index of the column corresponding to the max eigenvalue. + n, ki; + double gpisum=0.0, + eigmax, tmpd0; + + n=mxGetM(cp); // Get n for the n-by-n mxArray cp. + (*aod)=n; + + *aop = tzMalloc(n, double); + + gpim = mlfEig(&gpid,cp,NULL,NULL); + gpim_p = mxGetPr(gpim); + gpid_p = mxGetPr(gpid); + + eigmax = *gpid_p; + eigmaxindx = 0; + if (n>1) { + for (ki=1;ki<n;ki++) { + if (gpid_p[n*ki+ki] > eigmax) { + eigmax=gpid_p[n*ki+ki]; + eigmaxindx=ki; + } // Note that n*ki+ki refers to a diagonal location in the n-by-n matrix. + } + } + for (ki=0;ki<n;ki++) { + gpisum += gpim_p[n*eigmaxindx+ki]; // Sum over the eigmaxindx_th column. + } + tmpd0 = 1.0/gpisum; + for (ki=0;ki<n;ki++) { + (*aop)[ki] = gpim_p[n*eigmaxindx+ki]*tmpd0; // Normalized eigmaxindx_th column as ergodic probabilities. + } + + mxDestroyArray(gpim); // ????? free(gpim_p) + mxDestroyArray(gpid); +} +/**/ + + + +//---------- Must keep the following code forever. --------------- +/** +TSdp2m5 *CreateP2m5(const double p) +{ + TSdp2m5 *x_dp2m5 = tzMalloc(1, TSdp2m5); + + if (p<=0.0 && p>=1.0) fn_DisplayError(".../cstz.c/CreateP2m5_lf(): input probability p must be between 0.0 and 1.0"); + + x_dp2m5->cnt = 0; + x_dp2m5->ndeg = 0; + x_dp2m5->p = tzMalloc(5, double); + x_dp2m5->q = tzMalloc(5, double); + x_dp2m5->m = tzMalloc(5, int); + + x_dp2m5->p[0] = 0.00; + x_dp2m5->p[1] = 0.5*p; + x_dp2m5->p[2] = p; + x_dp2m5->p[3] = 0.5*(1.0+p); + x_dp2m5->p[4] = 1.00; + + return (x_dp2m5); +} +TSdp2m5 *DestroyP2m5(TSdp2m5 *x_dp2m5) +{ + if (x_dp2m5) { + free(x_dp2m5->m); + free(x_dp2m5->q); + free(x_dp2m5->p); + + free(x_dp2m5); + return ((TSdp2m5 *)NULL); + } + else return (x_dp2m5); +} +TSdvectorp2m5 *CreateVectorP2m5(const int n, const double p) +{ + int _i; + // + TSdvectorp2m5 *x_dvp2m5 = tzMalloc(1, TSdvectorp2m5); + + x_dvp2m5->n = n; + x_dvp2m5->v = tzMalloc(n, TSdp2m5 *); + for (_i=n-1; _i>=0; _i--) + x_dvp2m5->v[_i] = CreateP2m5(p); + + return (x_dvp2m5); +} +TSdvectorp2m5 *DestroyVectorP2m5(TSdvectorp2m5 *x_dvp2m5) +{ + int _i; + + if (x_dvp2m5) { + for (_i=x_dvp2m5->n-1; _i>=0; _i--) + x_dvp2m5->v[_i] = DestroyP2m5(x_dvp2m5->v[_i]); + free(x_dvp2m5->v); + + free(x_dvp2m5); + return ((TSdvectorp2m5 *)NULL); + } + return (x_dvp2m5); +} +TSdmatrixp2m5 *CreateMatrixP2m5(const int nrows, const int ncols, const double p) +{ + int _i; + // + TSdmatrixp2m5 *X_dmp2m5 = tzMalloc(1, TSdmatrixp2m5); + + X_dmp2m5->nrows = nrows; + X_dmp2m5->ncols = ncols; + X_dmp2m5->M = tzMalloc(nrows*ncols, TSdp2m5 *); + for (_i=nrows*ncols-1; _i>=0; _i--) + X_dmp2m5->M[_i] = CreateP2m5(p); + + return (X_dmp2m5); +} +TSdmatrixp2m5 *DestroyMatrixP2m5(TSdmatrixp2m5 *X_dmp2m5) +{ + int _i; + + if (X_dmp2m5) { + for (_i=X_dmp2m5->nrows*X_dmp2m5->ncols-1; _i>=0; _i--) + X_dmp2m5->M[_i] = DestroyP2m5(X_dmp2m5->M[_i]); + free(X_dmp2m5->M); + + free(X_dmp2m5); + return ((TSdmatrixp2m5 *)NULL); + } + else return (X_dmp2m5); +} +TSdcellp2m5 *CreateCellP2m5(const TSivector *rows_iv, const TSivector *cols_iv, const double p) +{ + int _i; + int ncells; + // + TSdcellp2m5 *X_dcp2m5 = tzMalloc(1, TSdcellp2m5); + + + if (!rows_iv || !cols_iv || !rows_iv->flag || !cols_iv->flag) fn_DisplayError(".../cstz.c/CreateCellP2m5(): Input row and column vectors must be (1) created and (2) assigned legal values"); + if ((ncells=rows_iv->n) != cols_iv->n) fn_DisplayError(".../cstz.c/CreateCellP2m5(): Length of rows_iv must be the same as that of cols_iv"); + + + X_dcp2m5->ncells = ncells; + X_dcp2m5->C = tzMalloc(ncells, TSdmatrixp2m5 *); + for (_i=ncells-1; _i>=0; _i--) + X_dcp2m5->C[_i] = CreateMatrixP2m5(rows_iv->v[_i], cols_iv->v[_i], p); + + return (X_dcp2m5); +} +TSdcellp2m5 *DestroyCellP2m5(TSdcellp2m5 *X_dcp2m5) +{ + int _i; + + if (X_dcp2m5) { + for (_i=X_dcp2m5->ncells-1; _i>=0; _i--) + X_dcp2m5->C[_i] = DestroyMatrixP2m5(X_dcp2m5->C[_i]); + free(X_dcp2m5->C); + + free(X_dcp2m5); + return ((TSdcellp2m5 *)NULL); + } + else return (X_dcp2m5); +} + + +#define P2REALBOUND DBL_MAX +int P2m5Update(TSdp2m5 *x_dp2m5, const double newval) +{ + //5-marker P2 algorithm. + //quantiles q[0] to q[4] correspond to 5-marker probabilities {0.0, p/5, p, (1+p)/5, 1.0}. + //Outputs: + // x_dp2m5->q, the markers x_dp2m5->m, is updated and only x_dp2m5->q[2] is used. + //Inputs: + // newval: new random number. + // + // January 2003. + int k, j; + double a; + double qm, dq; + int i, dm, dn; + + + if (!x_dp2m5) fn_DisplayError(".../cstz.c/P2m5Update(): x_dp2m5 must be created"); + + //if (isgreater(newval, -P2REALBOUND) && isless(newval, P2REALBOUND)) { + if (isfinite(newval) && newval > -P2REALBOUND && newval < P2REALBOUND) { + if (++x_dp2m5->cnt > 5) { + //Updating the quantiles and markers. + for (i=0; x_dp2m5->q[i]<=newval && i<5; i++) ; + if (i==0) { x_dp2m5->q[0]=newval; i++; } + if (i==5) { x_dp2m5->q[4]=newval; i--; } + for (; i<5; i++) x_dp2m5->m[i]++; + for (i=1; i<4; i++) { + dq = x_dp2m5->p[i]*x_dp2m5->m[4]; + if (x_dp2m5->m[i]+1<=dq && (dm=x_dp2m5->m[i+1]-x_dp2m5->m[i])>1) { + dn = x_dp2m5->m[i]-x_dp2m5->m[i-1]; + dq = ((dn+1)*(qm=x_dp2m5->q[i+1]-x_dp2m5->q[i])/dm+ + (dm-1)*(x_dp2m5->q[i]-x_dp2m5->q[i-1])/dn)/(dm+dn); + if (qm<dq) dq = qm/dm; + x_dp2m5->q[i] += dq; + x_dp2m5->m[i]++; + } else + if (x_dp2m5->m[i]-1>=dq && (dm=x_dp2m5->m[i]-x_dp2m5->m[i-1])>1) { + dn = x_dp2m5->m[i+1]-x_dp2m5->m[i]; + dq = ((dn+1)*(qm=x_dp2m5->q[i]-x_dp2m5->q[i-1])/dm+ + (dm-1)*(x_dp2m5->q[i+1]-x_dp2m5->q[i])/dn)/(dm+dn); + if (qm<dq) dq = qm/dm; + x_dp2m5->q[i] -= dq; + x_dp2m5->m[i]--; + } + } + } + else if (x_dp2m5->cnt < 5) { + //Fills the initial values. + x_dp2m5->q[x_dp2m5->cnt-1] = newval; + x_dp2m5->m[x_dp2m5->cnt-1] = x_dp2m5->cnt-1; + } + else { + //=== Last filling of initial values. + x_dp2m5->q[4] = newval; + x_dp2m5->m[4] = 4; + //=== P2 algorithm begins with reshuffling quantiles and makers. + for (j=1; j<5; j++) { + a = x_dp2m5->q[j]; + for (k=j-1; k>=0 && x_dp2m5->q[k]>a; k--) + x_dp2m5->q[k+1] = x_dp2m5->q[k]; + x_dp2m5->q[k+1]=a; + } + } + } + else ++x_dp2m5->ndeg; //Throwing away the draws to treat exceptions. + + return (x_dp2m5->cnt); +} +#undef P2REALBOUND + +void P2m5MatrixUpdate(TSdmatrixp2m5 *X_dmp2m5, const TSdmatrix *newval_dm) +{ + int _i; + int nrows, ncols; + + if (!X_dmp2m5 || !newval_dm || !newval_dm->flag) fn_DisplayError(".../cstz.c/P2m5MatrixUpdate(): (1) Matrix struct X_dmp2m5 must be created and (2) input new value matrix must be crated and given legal values"); + if ((nrows=newval_dm->nrows) != X_dmp2m5->nrows || (ncols=newval_dm->ncols) != X_dmp2m5->ncols) + fn_DisplayError(".../cstz.c/P2m5MatrixUpdate(): Number of rows and colums in X_dmp2m5 must match those of newval_dm"); + + for (_i=nrows*ncols-1; _i>=0; _i--) + P2m5Update(X_dmp2m5->M[_i], newval_dm->M[_i]); +} + +void P2m5CellUpdate(TSdcellp2m5 *X_dcp2m5, const TSdcell *newval_dc) +{ + int _i; + int ncells; + + if (!X_dcp2m5 || !newval_dc) fn_DisplayError(".../cstz.c/P2m5CellUpdate(): (1) Cell struct X_dcp2m5 must be created and (2) input new value cell must be crated and given legal values"); + if ((ncells=newval_dc->ncells) != X_dcp2m5->ncells) + fn_DisplayError(".../cstz.c/P2m5MatrixUpdate(): Number of cells in X_dcp2m5 must match that of newval_dc"); + + for (_i=ncells-1-1; _i>=0; _i--) + P2m5MatrixUpdate(X_dcp2m5->C[_i], newval_dc->C[_i]); +} +/**/ diff --git a/CFiles/fn_filesetup.c b/CFiles/fn_filesetup.c new file mode 100755 index 0000000..f756f5c --- /dev/null +++ b/CFiles/fn_filesetup.c @@ -0,0 +1,851 @@ +/*********** + * Reads the input file name and output file names specified by the user from the command line with automatic default to + * both input an output files. +***********/ + +#include "fn_filesetup.h" + + +//----------------- +// For command line. +// Finds /ch in the command line. If found, returns the args location +// indexed by int and zero otherwise. +//----------------- +int fn_ParseCommandLine(int n_arg, char **args, char ch) { + int i; + for (i=1; i<n_arg; i++) + if ( ((args[i][0] == '/') || (args[i][0] == '-')) && (args[i][1] == ch) && (args[i][2] == '\0')) return i; + return 0; +} + + +//----------------- +// For command line. +// Finds /ch in the command line. If found returns a pointer +// to the string trailing /ch. If /ch is not found or there is +// no trailing string or the trailing string is another argument, +// then default_return is returned. No memory is allocated and +// the calling routine should not free the returned pointer. +//----------------- +char *fn_ParseCommandLine_String(int n_arg, char **args, char ch, char *default_return) { + int i=fn_ParseCommandLine(n_arg,args,ch); + if (i > 0) + //if (strlen(args[i]) > 2) return args[i]+2; + // // In case the user forgot typing a space between /ch and string following it, still returns a pointer to the string folloing /ch. + //else if ((i+1 < n_arg) && (args[i+1][0] != '/')) return args[i+1]; + // // Returns a pointer to the string that does NOT begin with / and there is a whitespace between /ch and the string. + if (i+1 < n_arg) return args[i+1]; + // Returns a pointer to the string that does NOT begin with / and there is a whitespace between /ch and the string. + return default_return; +} + + +//----------------- +// For command line. +// Finds /ch in the command line. If found returns the integer +// value of the string trailing /ch (e.g, the integer value is +// sample size or normalization index. If /ch is not found or there +// is no trailing string or the trailing string is another argument, +// then the default_return value is returned. +//----------------- +int fn_ParseCommandLine_Integer(int n_arg, char **args, char ch, int default_return) { + char *str=fn_ParseCommandLine_String(n_arg,args,ch,(char*)NULL); + return str ? atoi(str) : default_return; +} + + +//----------------- +// Finds proper location in the input data file. +// Returns 1 if the NUL-terminated string id is found +// in the file and 0 otherwise. The file pointer is set +// to the line immediately after the line containing id. +// If the string id has a length (including the new line +// character \n) more than 1023, it will be cut off at 1023. +//----------------- +int fn_SetFilePosition(FILE *f, const char *id) { + // As an output, the file pointer f will be reset to the beginning of the line next to the line headed by the string id. + char buffer[1024]; + size_t n=strlen(id); + int ch; + + if ( !f ) fn_DisplayError(".../fn_filesetup.c/fn_SetFilePosition(): the file, *f, must be created (opened)"); + if (n>1023) n=1023; + rewind(f); // Reset a file poiniter to the beginning of the file. There may be more efficient ways but this is good enough as long as the file is not too long. + while (fgets(buffer,1024,f)) { // Reads a line at a time in the file f (including \n and a NUL byte) until it matches id. fgets returns the pointer to the buffer and is often only used to check for EOF. + if (buffer[strlen(buffer)-1] != '\n') // -1 because the first element of the buffer is indexed by buffer[0]. + // If the end of the buffer (excluding the NUL byte) encounters no new line, f points to the next character after + // the end of the buffer on the SAME line (i.e., f does not point to the begining of the new line at this point). + // The following do loop will take f to point to the beginning of the new line. + do ch=fgetc(f); // Gets one character at a time until it reachs the end of the current '\n' or the end of the file EOF. + while ( (ch != '\n') && (ch != EOF) ); + if (!memcmp(buffer,id,n)) return 1; // The match is found. + } + return 0; // No match is found. +} + + +//----------------- +// Reads a string from the input data file with the NULL-terminated +// character but without the new line character. +// Returns 1 if the vector of characters is all read without +// errors and 0 otherwise. The file pointer is then moved +// to point to the next non-whitespace character after these +// characters. +//----------------- +int ReadNullTerminatedString(FILE *fptr, TScvector *x_cv) +{ + //x_cv will have a string without the new line character and with the NULL character. + //It is the user's responsiblity to ensure the string x_cv has an enough length to use fgets(). + // If not, it stops after x_cv->n-1 characters have been stored in x_cv->v and a NULL byte is appended to make it a string. + // If yet, reading stops after a newline character is read and stored in x_cv->v and a NULL byte is then appended. + int _n; + char *cv; + if (!fptr || !x_cv) fn_DisplayError(".../fn_filesetup.c/ReadNullTerminatedString(): File or input string must be created (memory-allocated)"); + _n = x_cv->n; + cv = x_cv->v; + if ( !fgets(cv, _n, fptr) ) return 0; + cv[strlen(cv)-1] = '\0'; //Removes the new line character and replaces it with the NULL character. + //The string length (size_t type) strlen(cv) does NOT count the NULL byte at the end, but it counts the new line character. + return 1; +} + + +//----------------- +// Reads a vector of integers from the input data file. +// Returns 1 if the vector of integers is all read without +// errors and 0 otherwise. The file pointer is then moved +// to point to the next non-whitespace character after these +// integers. +//----------------- +int fn_ReadVector_int(FILE *fptr, int *x_v, const int d_x_v) { + int ki; + for (ki=0; ki<d_x_v; ki++) + if ( fscanf(fptr, " %d ", &x_v[ki]) !=1 ) return 0; + return 1; +} +int ReadVector_int(FILE *fptr, TSivector *x_iv) { + int ki, _n, + *v; + if (!fptr || !x_iv) fn_DisplayError(".../fn_filesetup.c/ReadVector_int(): File or input matrix must be created (memory-allocated)"); + _n = x_iv->n; + v = x_iv->v; + for (ki=0; ki<_n; ki++) + if ( fscanf(fptr, " %d ", &v[ki]) != 1 ) return 0; + return 1; +} + + +//----------------- +// Reads a vector of doubles from the input data file. +// Returns 1 if the vector of doubles is all read without +// errors and 0 otherwise. The file pointer is then moved +// to point to the next non-whitespace character after these +// doubles. +//----------------- +int fn_ReadVector_lf(FILE *fptr, double *x_v, const int d_x_v) { + int ki; + for (ki=0; ki<d_x_v; ki++) + if ( fscanf(fptr, " %lf ", &x_v[ki]) !=1 ) return 0; + return 1; +} +int ReadVector_lf(FILE *fptr, TSdvector *x_dv) { + int ki, _n; + double *v; + if (!fptr || !x_dv) fn_DisplayError(".../fn_filesetup.c/ReadVector_lf(): File or input matrix must be created (memory-allocated)"); + _n = x_dv->n; + v = x_dv->v; + for (ki=0; ki<_n; ki++) + if ( fscanf(fptr, " %lf ", &v[ki]) != 1 ) return 0; + + x_dv->flag = V_DEF; + return 1; +} + + +//----------------- +// Reads a column-major matrix of integers from the input data file. +// Returns 1 if the matrix of integers is all read without +// errors and 0 otherwise. The file pointer is then moved +// to point to the next non-whitespace character after these +// integers. +//----------------- +int fn_ReadMatrix_int(FILE *fptr, int *x_m, const int r_x_m, const int c_x_m) { + int ki, kj; + + for (ki=0; ki<r_x_m; ki++) + for (kj=0; kj<c_x_m; kj++) + if ( fscanf(fptr, " %d ", &x_m[kj*r_x_m+ki]) !=1 ) return 0; + return 1; +} +int ReadMatrix_int(FILE *fptr, TSimatrix *X_im) +{ + int ki, kj; + int nrows, ncols; + if (!fptr || !X_im) fn_DisplayError(".../fn_filesetup.c/ReadMatrix_int(): File or input matrix must be created (memory-allocated)"); + + nrows = X_im->nrows; + ncols = X_im->ncols; + for (ki=0; ki<nrows; ki++) + for (kj=0; kj<ncols; kj++) + if ( fscanf(fptr, " %d ", (X_im->M+mos(ki,kj,nrows))) !=1 ) return 0; + return 1; +} + + +//----------------- +// Reads a column-major matrix of doubles from the input data file. +// Returns 1 if the matrix of doubles is all read without +// errors and 0 otherwise. The file pointer is then moved +// to point to the next non-whitespace character after these +// doubles. +//----------------- +int fn_ReadMatrix_lf(FILE *fptr, double *x_m, const int r_x_m, const int c_x_m) { + int ki, kj; + for (ki=0; ki<r_x_m; ki++) + for (kj=0; kj<c_x_m; kj++) + if ( fscanf(fptr, " %lf ", &x_m[kj*r_x_m+ki]) !=1 ) return 0; + return 1; +} +int ReadMatrix_lf(FILE *fptr, TSdmatrix *x_dm) { + //Outputs: + // x_dm (whose memory is already allocated): To be filled with the numbers from the file fptr. + int ki, kj, nrows, ncols; + double *M; + if (!fptr || !x_dm) fn_DisplayError(".../fn_filesetup.c/ReadMatrix_lf(): File or input matrix must be created (memory-allocated)"); + nrows = x_dm->nrows; + ncols = x_dm->ncols; + M = x_dm->M; + for (ki=0; ki<nrows; ki++) + for (kj=0; kj<ncols; kj++) + if ( fscanf(fptr, " %lf ", &M[mos(ki,kj,nrows)]) !=1 ) return 0; + + x_dm->flag = M_GE; + return 1; +} + + + +//----------------- +// Reads a column-major cell of double vectors from the input data file. +// Returns 1 if all data are read without errors and 0 otherwise. +// The file pointer is then moved to point to the next non-whitespace character +// after these doubles. +//----------------- +int ReadCellvec_lf(FILE *fptr, TSdcellvec *x_dcv) { + //Outputs: + // x_dcv (whose memory is already allocated): To be filled with the numbers from the file fptr. + int ci, kj, _n, ncells; + double *v; + if (!fptr || !x_dcv) fn_DisplayError(".../fn_filesetup.c/ReadCellvec_lf(): File or input cell must be created (memory-allocated)"); + ncells = x_dcv->ncells; + for (ci=0; ci<ncells; ci++) { + _n = x_dcv->C[ci]->n; + v = x_dcv->C[ci]->v; + for (kj=0; kj<_n; kj++) + if ( fscanf(fptr, " %lf ", &v[kj]) != 1 ) return 0; + } + return 1; +} + + + + +//----------------- +// Reads a column-major cell of double matrices from the input data file. +// Returns 1 if all data are read without errors and 0 otherwise. +// The file pointer is then moved to point to the next non-whitespace character +// after these doubles. +//----------------- +int ReadCell_lf(FILE *fptr, TSdcell *x_dc) { + //Outputs: + // x_dc (whose memory is already allocated): To be filled with the numbers from the file fptr. + int ci, ki, kj, nrows, ncols, ncells; + double *M; + if (!fptr || !x_dc) fn_DisplayError(".../fn_filesetup.c/ReadCell_lf(): File or input cell must be created (memory-allocated)"); + ncells = x_dc->ncells; + for (ci=0; ci<ncells; ci++) { + nrows = x_dc->C[ci]->nrows; + ncols = x_dc->C[ci]->ncols; + M = x_dc->C[ci]->M; + for (ki=0; ki<nrows; ki++) + for (kj=0; kj<ncols; kj++) + if ( fscanf(fptr, " %lf ", &M[mos(ki,kj,nrows)]) != 1 ) return 0; + } + return 1; +} + + + +//----------------- +// Write a column-major matrix of floats to the output file. +// The file pointer is then moved to point to the next +// non-whitespace character after these doubles. +//----------------- +void fn_WriteMatrix_f(FILE *fptr_debug, const double *x_m, const int r_x_m, const int c_x_m) { + int _i, _j; + + for (_i=0; _i<r_x_m; _i++) { + for (_j=0; _j<c_x_m; _j++) { + fprintf(fptr_debug, " %f ", x_m[_j*r_x_m + _i]); + if (_j==c_x_m-1) fprintf(fptr_debug, "\n"); + } + if (_i==r_x_m-1) fprintf(fptr_debug, "\n\n"); + } +} +void WriteMatrix_f(FILE *fptr_debug, const TSdmatrix *x_dm) { + int _i, _j; + if (!fptr_debug || !x_dm) fn_DisplayError(".../fn_filesetup.c/WriteMatrix_f(): File or input matrix cannot be NULL (must be created)"); + for (_i=0; _i<x_dm->nrows; _i++) { + for (_j=0; _j<x_dm->ncols; _j++) { + fprintf(fptr_debug, " %10.5f ", x_dm->M[_j*x_dm->nrows + _i]); + if (_j==x_dm->ncols-1) fprintf(fptr_debug, "\n"); + } + if (_i==x_dm->nrows-1) fprintf(fptr_debug, "\n\n"); + } +} + + +//----------------- +// Write a column-major matrix of doubles to the output file. +// The file pointer is then moved to point to the next +// non-whitespace character after these doubles. +//----------------- +void fn_WriteMatrix_lf(FILE *fptr_debug, const double *x_m, const int r_x_m, const int c_x_m) { + int _i, _j; + for (_i=0; _i<r_x_m; _i++) { + for (_j=0; _j<c_x_m; _j++) { + fprintf(fptr_debug, " %.16e ", x_m[_j*r_x_m + _i]); + if (_j==c_x_m-1) fprintf(fptr_debug, "\n"); + } + if (_i==r_x_m-1) fprintf(fptr_debug, "\n\n"); + } +} +void WriteMatrix_lf(FILE *fptr_debug, const TSdmatrix *x_dm) { + int _i, _j; + if (!fptr_debug || !x_dm) fn_DisplayError(".../fn_filesetup.c/WriteMatrix_lf(): File or input matrix cannot be NULL (must be created)"); + for (_i=0; _i<x_dm->nrows; _i++) { + for (_j=0; _j<x_dm->ncols; _j++) { + fprintf(fptr_debug, " %.16e ", x_dm->M[_j*x_dm->nrows + _i]); + if (_j==x_dm->ncols-1) fprintf(fptr_debug, "\n"); + } + if (_i==x_dm->nrows-1) fprintf(fptr_debug, "\n\n"); + } +} +void WriteMatrix(FILE *fptr_debug, const TSdmatrix *x_dm, const char *format) { + int _i, _j, nrows, ncols; + double *M; + if (!fptr_debug || !x_dm) fn_DisplayError(".../fn_filesetup.c/WriteMatrix(): File or input matrix cannot be NULL (must be created)"); + nrows = x_dm->nrows; + ncols = x_dm->ncols; + M = x_dm->M; + if (!format) format=" %10.5f "; //Default format. + for (_i=0; _i<nrows; _i++) + for (_j=0; _j<ncols; _j++) { + fprintf(fptr_debug, format, M[_j*x_dm->nrows + _i]); + if (_j==ncols-1) fprintf(fptr_debug, "\n"); + } + //fprintf(fptr_debug, "\n"); +} +//+ +void WriteMatrixTranspose(FILE *fptr_debug, const TSdmatrix *x_dm, const char *format) +{ + int _i, _j, nrows, ncols; + double *M; + //=== + TSdmatrix *Xtran_dm = NULL; + + if (!fptr_debug || !x_dm) fn_DisplayError(".../fn_filesetup.c/WriteMatrixTranspose(): File or input matrix cannot be NULL (must be created)"); + + Xtran_dm = tz_TransposeRegular((TSdmatrix *)NULL, x_dm); + + nrows = Xtran_dm->nrows; + ncols = Xtran_dm->ncols; + M = Xtran_dm->M; + if (!format) format=" %10.5f "; //Default format. + for (_i=0; _i<nrows; _i++) + for (_j=0; _j<ncols; _j++) { + fprintf(fptr_debug, format, M[_j*Xtran_dm->nrows + _i]); + if (_j==ncols-1) fprintf(fptr_debug, "\n"); + } + //fprintf(fptr_debug, "\n"); + + //=== + DestroyMatrix_lf(Xtran_dm); +} + + +//----------------- +// Write cells of column-major double matrices to the output file. +// The file pointer is then moved to point to the next +// non-whitespace character after these doubles. +//----------------- +void WriteCell_lf(FILE *fptr_debug, const TSdcell *x_dc) { + int _i, _n; + if (!fptr_debug || !x_dc) fn_DisplayError(".../fn_filesetup.c/WriteCell_lf(): File or input cell cannot be NULL (must be created)"); + _n = x_dc->ncells; + for (_i=0; _i<_n; _i++) { + fprintf(fptr_debug, "Cell %d\n", _i); + WriteMatrix_lf(fptr_debug, x_dc->C[_i]); + } +} +void WriteCell_f(FILE *fptr_debug, const TSdcell *x_dc) { + int _i, _n; + if (!fptr_debug || !x_dc) fn_DisplayError(".../fn_filesetup.c/WriteCell_f(): File or input cell cannot be NULL (must be created)"); + _n = x_dc->ncells; + for (_i=0; _i<_n; _i++) { + fprintf(fptr_debug, "Cell %d\n", _i); + WriteMatrix_f(fptr_debug, x_dc->C[_i]); + } +} +void WriteCell(FILE *fptr_debug, const TSdcell *x_dc, const char *format) { + int _i, _n; + if (!fptr_debug || !x_dc) fn_DisplayError(".../fn_filesetup.c/WriteCell(): File or input cell cannot be NULL (must be created)"); + _n = x_dc->ncells; + for (_i=0; _i<_n; _i++) + { + WriteMatrix(fptr_debug, x_dc->C[_i], format); + fprintf(fptr_debug, "\n"); + } +} +//+ +void WriteCellTranspose(FILE *fptr_debug, const TSdcell *x_dc, const char *format) +{ + int _i, _n; + if (!fptr_debug || !x_dc) fn_DisplayError(".../fn_filesetup.c/WriteCell(): File or input cell cannot be NULL (must be created)"); + _n = x_dc->ncells; + for (_i=0; _i<_n; _i++) + { + WriteMatrixTranspose(fptr_debug, x_dc->C[_i], format); + fprintf(fptr_debug, "\n"); + } +} + + +//----------------- +// Write cells of vectors to the output file. +// The file pointer is then moved to point to the next +// non-whitespace character after these doubles. +//----------------- +void WriteCellvec_lf(FILE *fptr_debug, const TSdcellvec *x_dcv) { + int _i; + if (!fptr_debug || !x_dcv) fn_DisplayError(".../fn_filesetup.c/WriteCellvec_lf(): File or input cell cannot be NULL (must be created)"); + for (_i=0; _i<x_dcv->ncells; _i++) { + fprintf(fptr_debug, "Cell %d\n", _i); + WriteVector_lf(fptr_debug, x_dcv->C[_i]); + } +} +void WriteCellvec_f(FILE *fptr_debug, const TSdcellvec *x_dcv) { + int _i; + if (!fptr_debug || !x_dcv) fn_DisplayError(".../fn_filesetup.c/WriteCellvec_lf(): File or input cell cannot be NULL (must be created)"); + for (_i=0; _i<x_dcv->ncells; _i++) { + fprintf(fptr_debug, "Cell %d\n", _i); + WriteVector_f(fptr_debug, x_dcv->C[_i]); + } +} +void WriteCellvec(FILE *fptr_debug, const TSdcellvec *x_dcv, const char *format) { + int _i, _n; + if (!fptr_debug || !x_dcv) fn_DisplayError(".../fn_filesetup.c/WriteCellvec(): File or input cell cannot be NULL (must be created)"); + _n = x_dcv->ncells; + for (_i=0; _i<_n; _i++) WriteVector(fptr_debug, x_dcv->C[_i], format); +} +void WriteCellvec_int(FILE *fptr_debug, const TSicellvec *x_icv) +{ + int _i, _n; + if (!fptr_debug || !x_icv) fn_DisplayError(".../fn_filesetup.c/WriteCellvec_int(): File or input cell cannot be NULL (must be created)"); + _n = x_icv->ncells; + for (_i=0; _i<_n; _i++) WriteVector_int(fptr_debug, x_icv->C[_i]); +} + + + +//----------------- +// Write fourths of column-major double matrices to an output file. +// The file pointer is then moved to point to the next +// non-whitespace character after these doubles. +//----------------- +void WriteFourth_f(FILE *fptr_debug, const TSdfourth *x_d4) { + int _j, _i, _m, _n; + if (!fptr_debug || !x_d4) fn_DisplayError(".../fn_filesetup.c/WriteFourth_f(): File or input fourth cannot be NULL (must be created)"); + _m = x_d4->ndims; + for (_j=0; _j<_m; _j++) { + _n = x_d4->F[_j]->ncells; + fprintf(fptr_debug, "Fourth %d\n", _j); + for (_i=0; _i<_n; _i++) { + fprintf(fptr_debug, "Cell %d\n", _i); + WriteMatrix_f(fptr_debug, x_d4->F[_j]->C[_i]); + } + } +} +void WriteFourth(FILE *fptr_debug, const TSdfourth *x_d4, const char *format) { + int _j, _i, _m, _n; + if (!fptr_debug || !x_d4) fn_DisplayError(".../fn_filesetup.c/WriteFourth_f(): File or input fourth cannot be NULL (must be created)"); + _m = x_d4->ndims; + for (_j=0; _j<_m; _j++) { + _n = x_d4->F[_j]->ncells; + for (_i=0; _i<_n; _i++) { + WriteMatrix(fptr_debug, x_d4->F[_j]->C[_i], format); + } + } +} + + +//----------------- +// Write a column-major matrix of ints to the output file. +// The file pointer is then moved to point to the next +// non-whitespace character after these doubles. +//----------------- +void fn_WriteMatrix_int(FILE *fptr_debug, const int *x_m, const int r_x_m, const int c_x_m) { + int _i, _j; + for (_i=0; _i<r_x_m; _i++) { + for (_j=0; _j<c_x_m; _j++) { + fprintf(fptr_debug, " %d ", x_m[_j*r_x_m + _i]); + if (_j==c_x_m-1) fprintf(fptr_debug, "\n"); + } + if (_i==r_x_m-1) fprintf(fptr_debug, "\n\n"); + } +} +void WriteMatrix_int(FILE *fptr_debug, const TSimatrix *x_im) { + int _i, _j; + if (!fptr_debug || !x_im) fn_DisplayError(".../fn_filesetup.c/WriteMatrix_int(): File or input matrix cannot be NULL (must be created)"); + for (_i=0; _i<x_im->nrows; _i++) { + for (_j=0; _j<x_im->ncols; _j++) { + fprintf(fptr_debug, " %d ", x_im->M[_j*x_im->nrows + _i]); + if (_j==x_im->ncols-1) fprintf(fptr_debug, "\n"); + } + if (_i==x_im->nrows-1) fprintf(fptr_debug, "\n\n"); + } +} + + +//----------------- +// Write a vector of doubles to the output file. +// The file pointer is then moved to point to the next +// non-whitespace character after these doubles. +//----------------- +void fn_WriteVector_lf(FILE *fptr_debug, const double *x_v, const int d_x_v) { + int _i; + for (_i=0; _i<d_x_v; _i++) { + fprintf(fptr_debug, " %20.16f ", x_v[_i]); + if (_i==d_x_v-1) fprintf(fptr_debug, "\n\n"); + } +} +void WriteVector_lf(FILE *fptr_debug, const TSdvector *x_dv) { + int _i; + for (_i=0; _i<x_dv->n; _i++) { + fprintf(fptr_debug, " %20.16f ", x_dv->v[_i]); + if (_i==x_dv->n-1) fprintf(fptr_debug, "\n\n"); + } +} +void WriteVector(FILE *fptr_debug, const TSdvector *x_dv, const char *format) { + int _i, _n; + double *v; + if ( !fptr_debug || !x_dv ) fn_DisplayError(".../fn_filesetup.c/WriteVector(): File or input vector cannot be NULL (must be created)"); + _n = x_dv->n; + v = x_dv->v; + if (!format) format=" %10.5f "; //Default format. + for (_i=0; _i<_n; _i++) fprintf(fptr_debug, format, v[_i]); + fprintf(fptr_debug, "\n"); +} +void WriteVector_column(FILE *fptr_debug, const TSdvector *x_dv, const char *format) +{ + int _i, _n; + double *v; + if ( !fptr_debug || !x_dv ) fn_DisplayError(".../fn_filesetup.c/WriteVector_column(): File or input vector cannot be NULL (must be created)"); + _n = x_dv->n; + v = x_dv->v; + if (!format) format=" %10.5f "; //Default format. + for (_i=0; _i<_n; _i++) + { + fprintf(fptr_debug, format, v[_i]); + fprintf(fptr_debug, "\n"); + } +} + + +//----------------- +// Write a vector of floats to the output file. +// The file pointer is then moved to point to the next +// non-whitespace character after these doubles. +//----------------- +void fn_WriteVector_f(FILE *fptr_debug, const double *x_v, const int d_x_v) { + int _i; + for (_i=0; _i<d_x_v; _i++) fprintf(fptr_debug, " %f ", x_v[_i]); + fprintf(fptr_debug, "\n"); +} +void WriteVector_f(FILE *fptr_debug, const TSdvector *x_dv) { + int _i; + if (!fptr_debug || !x_dv) fn_DisplayError(".../fn_filesetup.c/WriteVector_f(): File or input vector cannot be NULL (must be created)"); + for (_i=0; _i<x_dv->n; _i++) fprintf(fptr_debug, " %10.5f ", x_dv->v[_i]); + fprintf(fptr_debug, "\n"); +} + + + +//----------------- +// Write a vector of integers to the output file. +// The file pointer is then moved to point to the next +// non-whitespace character after these doubles. +//----------------- +void WriteVector_int(FILE *fptr_debug, const TSivector *x_iv) +{ + int _i; + if (!fptr_debug || !x_iv) fn_DisplayError(".../fn_filesetup.c/WriteVector_int(): File or input vector cannot be NULL (must be created)"); + for (_i=0; _i<x_iv->n; _i++) { + fprintf(fptr_debug, " %d ", x_iv->v[_i]); + if (_i==x_iv->n-1) fprintf(fptr_debug, "\n\n"); + } +} + + + +void PrintVector_int(const TSivector *x_iv) +{ + int _i, _n; + + if (!x_iv) fn_DisplayError(".../fn_filesetup.c/PrintVector_int(): Input vector must be created (memory-allocated)"); + _n = x_iv->n; + // printf("\nVector:\n"); + for (_i=0; _i<_n; _i++) { + printf("v[%d]=%d\n", _i, x_iv->v[_i]); + } +} + +//----------------- +// Print a vector of doubles to the screen. +//----------------- +void PrintVector(const TSdvector *x_dv, const char *format) +{ + int _i, _n; + + if (!x_dv) fn_DisplayError(".../fn_filesetup.c/PrintVector(): Input vector must be created (memory-allocated)"); + _n = x_dv->n; + // printf("\n\nVector:\n"); + for (_i=0; _i<_n; _i++) { + printf(format, x_dv->v[_i]); + } +} +//+ +void PrintVector_f(const TSdvector *x_dv) +{ + int _i, _n; + + if (!x_dv) fn_DisplayError(".../fn_filesetup.c/PrintVector_f(): Input vector must be created (memory-allocated)"); + _n = x_dv->n; + // printf("\n\nVector:\n"); + for (_i=0; _i<_n; _i++) { + printf("v[%d]=%6.4f\n", _i, x_dv->v[_i]); + } +} + +void PrintVector_dz(const TSdzvector *x_dzv) +{ + int _i; + + if (!x_dzv) fn_DisplayError(".../fn_filesetup.c/PrintVector_dz(): Input complex vector must be created (memory-allocated)"); + + printf("\n\nComplex vector:\n"); + for (_i=0; _i<x_dzv->real->n; _i++) { + printf("vreal[%d]=%6.4f; vimag[%d]=%6.4f\n", _i, x_dzv->real->v[_i], _i, x_dzv->imag->v[_i]); + } +} + + +void PrintMatrix_int(const TSimatrix *X_im) +{ + int _i, _j, nrows, ncols; + int *M=X_im->M; + + if (!X_im) fn_DisplayError(".../fn_filesetup.c/PrintMatrix_int(): Input matrix must be created (memory-allocated)"); + else { + nrows = X_im->nrows; + ncols = X_im->ncols; + M = X_im->M; + } + + printf("\n\nMatrix:\n"); + for (_i=0; _i<nrows; _i++) { + for (_j=0; _j<ncols; _j++) { + printf(" %d ", M[_j*nrows + _i]); + if (_j==ncols-1) printf("\n"); + } + if (_i==nrows-1) printf("\n"); + } +} + +void PrintMatrix_f(const TSdmatrix *x_dm) +{ + int _i, _j, nrows, ncols; + double *M=x_dm->M; + + if (!x_dm) fn_DisplayError(".../fn_filesetup.c/PrintMatrix_f(): Input matrix must be created (memory-allocated)"); + else { + nrows = x_dm->nrows; + ncols = x_dm->ncols; + M = x_dm->M; + } + + printf("\n\nMatrix:\n"); + for (_i=0; _i<nrows; _i++) { + for (_j=0; _j<ncols; _j++) { + printf(" %6.4f ", M[_j*nrows + _i]); + if (_j==ncols-1) printf("\n"); + } + if (_i==nrows-1) printf("\n"); + } +} + +void PrintMatrix(const TSdmatrix *x_dm, const char *format) +{ + int _i, _j, nrows, ncols; + double *M=x_dm->M; + + if (!x_dm) fn_DisplayError(".../fn_filesetup.c/PrintMatrix_f(): Input matrix must be created (memory-allocated)"); + else { + nrows = x_dm->nrows; + ncols = x_dm->ncols; + M = x_dm->M; + } + + printf("\n\nMatrix:\n"); + if (!format) format=" %10.5f "; //Default format. + for (_i=0; _i<nrows; _i++) { + for (_j=0; _j<ncols; _j++) { + printf(format, M[_j*nrows + _i]); + if (_j==ncols-1) printf("\n"); + } + if (_i==nrows-1) printf("\n"); + } +} + +void PrintMatrix_dz(const TSdzmatrix *x_dzm) { + int _i, _j, nrows, ncols; + double *Mr=NULL, + *Mi=NULL; + + if (!x_dzm) fn_DisplayError(".../fn_filesetup.c/PrintMatrix_dz(): Input complex matrix must be created (memory-allocated)"); + else { + nrows = x_dzm->real->nrows; + ncols = x_dzm->real->ncols; + Mr = x_dzm->real->M, + Mi = x_dzm->imag->M; + } + + printf("\n\nReal part of the matrix:\n"); + for (_i=0; _i<nrows; _i++) { + for (_j=0; _j<ncols; _j++) { + printf(" %6.4f ", Mr[_j*nrows + _i]); + if (_j==ncols-1) printf("\n"); + } + if (_i==nrows-1) printf("\n"); + } + + printf("\n\nImaginary part of the matrix:\n"); + for (_i=0; _i<nrows; _i++) { + for (_j=0; _j<ncols; _j++) { + printf(" %6.4f ", Mi[_j*nrows + _i]); + if (_j==ncols-1) printf("\n"); + } + if (_i==nrows-1) printf("\n"); + } +} + +void PrintCellvec_f(const TSdcellvec *x_dcv) { + int _i, ci, _n; + double *v; + + if (!x_dcv) fn_DisplayError(".../fn_filesetup.c/PrintCellvec_f(): Input cell must be created (memory-allocated)"); + for (ci=0; ci<x_dcv->ncells; ci++ ) { + _n = x_dcv->C[ci]->n; + v = x_dcv->C[ci]->v; + printf("\nCellvec %d:\n", ci); + for (_i=0; _i<_n; _i++) { + printf("v[%d]=%6.4f\n", _i, v[_i]); + } + } +} +void PrintCell_f(const TSdcell *x_dc) { + int _i, _j, ci, nrows, ncols; + double *M; + + if (!x_dc) fn_DisplayError(".../fn_filesetup.c/PrintCell_f(): Input cell must be created (memory-allocated)"); + for (ci=0; ci<x_dc->ncells; ci++ ) { + nrows = x_dc->C[ci]->nrows; + ncols = x_dc->C[ci]->ncols; + M = x_dc->C[ci]->M; + + printf("\nCell %d:\n", ci); + for (_i=0; _i<nrows; _i++) { + for (_j=0; _j<ncols; _j++) { + printf(" %6.4f ", M[_j*nrows + _i]); + if (_j==ncols-1) printf("\n"); + } + if (_i==nrows-1) printf("\n"); + } + } +} + + +void PrintCell(const TSdcell *x_dc, const char *format) +{ + int _i, _j, ci, nrows, ncols; + double *M; + + if (!x_dc) fn_DisplayError(".../fn_filesetup.c/PrintCell_f(): Input cell must be created (memory-allocated)"); + for (ci=0; ci<x_dc->ncells; ci++ ) { + nrows = x_dc->C[ci]->nrows; + ncols = x_dc->C[ci]->ncols; + M = x_dc->C[ci]->M; + + printf("\nCell %d:\n", ci); + if (!format) format=" %10.5f "; //Default format. + for (_i=0; _i<nrows; _i++) { + for (_j=0; _j<ncols; _j++) { + printf(format, M[_j*nrows + _i]); + if (_j==ncols-1) printf("\n"); + } + if (_i==nrows-1) printf("\n"); + } + } +} + + +void PrintFourthvec_f(TSdfourthvec *x_d4v) { + int _j, _i, _k, _m, _n, _o; + if (!x_d4v) fn_DisplayError(".../fn_filesetup.c/PrintFourthvec_f(): Input fourthvec cannot be NULL (must be created)"); + _m = x_d4v->ndims; + for (_j=0; _j<_m; _j++) { + _n = x_d4v->F[_j]->ncells; + for (_i=0; _i<_n; _i++) { + printf("\nFourthvec %d and Cell %d:\n", _j, _i); + _o = x_d4v->F[_j]->C[_i]->n; + for (_k=0; _k<_o; _k++) { + printf("v[%d]=%6.4f\n", _k, x_d4v->F[_j]->C[_i]->v[_k]); + } + } + } +} + + + + +//------------------- +// Prints entire input data (fptr_in) to the output file (fptr_out) +// for the user to know what has produced the output. +// The maximum number of characters in each line of the input file +// is 4095 (excluding the NUL byte), but the rest of the line will +// continue to be printed in new lines in the output file. +//------------------- +#define BUFFERLEN 4096 +void ReprintInputData(FILE *fptr_in, FILE *fptr_out) +{ + char *inpbuffer; + + inpbuffer = tzMalloc(BUFFERLEN, char); //@ Allocate memory to the string (including the NUL byte). + rewind(fptr_in); + while (fgets(inpbuffer,BUFFERLEN,fptr_in)) + fprintf(fptr_out, "%s", inpbuffer); + fprintf(fptr_out, "\n\n\n\n\n//------------------------------- Output Data Begin Here -------------------------------\n"); + free(inpbuffer); +} +#undef BUFFERLEN + diff --git a/CFiles/fn_filesetup.h b/CFiles/fn_filesetup.h new file mode 100755 index 0000000..0859f39 --- /dev/null +++ b/CFiles/fn_filesetup.h @@ -0,0 +1,69 @@ +#ifndef __FN_FILESETUP_H__ +#define __FN_FILESETUP_H__ + #include <string.h> + //#include <malloc.h> // For malloc, calloc, etc. + + #include "tzmatlab.h" + #include "mathlib.h" //Used for tz_TransposeRegular(). + + int fn_ParseCommandLine(int n_arg, char **args, char ch); + char *fn_ParseCommandLine_String(int n_arg, char **args, char ch, char *default_return); + int fn_ParseCommandLine_Integer(int n_arg, char **args, char ch, int default_return); + int fn_SetFilePosition(FILE *f, const char *id); + + int fn_ReadVector_int(FILE *fptr, int *x_v, const int d_x_v); + int fn_ReadVector_lf(FILE *fptr, double *x_v, const int d_x_v); + int fn_ReadMatrix_int(FILE *fptr, int *x_m, const int r_x_m, const int c_x_m); + int fn_ReadMatrix_lf(FILE *fptr, double *x_m, const int r_x_m, const int c_x_m); + + int ReadNullTerminatedString(FILE *fptr, TScvector *x_cv); + int ReadVector_int(FILE *fptr, TSivector *x_iv); + int ReadVector_lf(FILE *fptr, TSdvector *x_dv); + int ReadMatrix_int(FILE *fptr, TSimatrix *X_im); + int ReadMatrix_lf(FILE *fptr, TSdmatrix *x_dm); + int ReadCell_lf(FILE *fptr, TSdcell *x_dc); + int ReadCellvec_lf(FILE *fptr, TSdcellvec *x_dcv); + + void fn_WriteMatrix_f(FILE *fprt_debug, const double *x_m, const int r_x_m, const int c_x_m); + void fn_WriteMatrix_lf(FILE *fprt_debug, const double *x_m, const int r_x_m, const int c_x_m); + void fn_WriteMatrix_int(FILE *fprt_debug, const int *x_m, const int r_x_m, const int c_x_m); + void fn_WriteVector_f(FILE *fprt_debug, const double *x_v, const int d_x_v); + + void WriteMatrix_f(FILE *fprt_debug, const TSdmatrix *x_dm); + void WriteMatrix_lf(FILE *fprt_debug, const TSdmatrix *x_dm); + void WriteMatrix(FILE *fprt_debug, const TSdmatrix *x_dm, const char *format); + void WriteMatrixTranspose(FILE *fptr_debug, const TSdmatrix *x_dm, const char *format); + void WriteCell_lf(FILE *fprt_debug, const TSdcell *x_dc); + void WriteCell_f(FILE *fprt_debug, const TSdcell *x_dc); + void WriteCell(FILE *fprt_debug, const TSdcell *x_dc, const char *format); + void WriteCellTranspose(FILE *fptr_debug, const TSdcell *x_dc, const char *format); + void WriteCellvec_lf(FILE *fprt_debug, const TSdcellvec *x_dcv); + void WriteCellvec_f(FILE *fprt_debug, const TSdcellvec *x_dcv); + void WriteCellvec(FILE *fptr_debug, const TSdcellvec *x_dcv, const char *format); + void WriteFourth_f(FILE *fptr_debug, const TSdfourth *x_d4); + void WriteFourth(FILE *fptr_debug, const TSdfourth *x_d4, const char *format); + void WriteVector_f(FILE *fprt_debug, const TSdvector *x_dv); + void WriteVector_lf(FILE *fprt_debug, const TSdvector *x_dv); + void WriteVector(FILE *fprt_debug, const TSdvector *x_dv, const char *format); + void WriteVector_column(FILE *fptr_debug, const TSdvector *x_dv, const char *format); + void WriteCellvec_int(FILE *fptr_debug, const TSicellvec *x_icv); + void WriteMatrix_int(FILE *fprt_debug, const TSimatrix *x_im); + void WriteVector_int(FILE *fprt_debug, const TSivector *x_iv); + + + void PrintVector_int(const TSivector *x_iv); + void PrintVector(const TSdvector *x_dv, const char *format); + void PrintVector_f(const TSdvector *x_dv); + void PrintVector_dz(const TSdzvector *x_dzv); + void PrintMatrix_int(const TSimatrix *X_im); + void PrintMatrix_f(const TSdmatrix *x_dm); + void PrintMatrix(const TSdmatrix *x_dm, const char *format); + void PrintMatrix_dz(const TSdzmatrix *x_dzm); + void PrintCellvec_f(const TSdcellvec *x_dcv); + void PrintCell_f(const TSdcell *x_dc); + void PrintCell(const TSdcell *x_dc, const char *format); + void PrintFourthvec_f(TSdfourthvec *x_d4v); + + + void ReprintInputData(FILE *fptr_in, FILE *fptr_out); +#endif diff --git a/CFiles/gensys.c b/CFiles/gensys.c new file mode 100755 index 0000000..998b51c --- /dev/null +++ b/CFiles/gensys.c @@ -0,0 +1,1272 @@ +/******************************************************************* + * [G1,C,impact,fmat,fwt,ywt,gev,eu]=gensys(g0,g1,c,psi,pi,div) + * + * System given as + * g0*y(t)=g1*y(t-1)+c+psi*z(t)+pi*eta(t), + * with z an exogenous variable process and eta being endogenously determined + * one-step-ahead expectational errors. Returned system is + * y(t)=G1*y(t-1)+C+impact*z(t)+ywt*inv(I-fmat*inv(L))*fwt*z(t+1) . + * If z(t) is i.i.d., the last term drops out. + * If div or stake is omitted from argument list, a div>1 or stake>1 is calculated. + * eu(1)=1 for existence, eu(2)=1 for uniqueness. eu(1)=-1 for + * existence only with not-serially correlated z(t); eu=[-2,-2] for coincident zeros. + * + * g0, g1: n-by-n matrices. + * c: n-by-1 constant terms. + * z(t): m-by-1 vector of exogenous residuals where m < n. + * psi: n-by-m matrix. + * eta(t): h-by-1 vector of expectational (endogenous) errors. + * pi: n-by-h matrix. + * div: a real number dividing stable and unstable roots.. If < 1.0, a div>1.0 is calculated mechanically. + *------- + * G1 or Theta_dm: n-by-n matrices. + * C: n-by-1 vector of constant terms. + * impact: n-by-m matrix. + * gev: n-by-2 z vector of stacked generalized eigenvalues where gev(;,2) ./ gev(:,1) = eig(g0, g1). + * ywt: n-by-nunstab z matrix of possible complex numbers. Initialized to NULL and dynamically allocated. + * fmat: nunstab-by-nunstab z matrix where nunstab is the number of non-stable roots. + * fwt: nunstab-by-m z matrix. + * + * 1996 MATLAB algorithm by Christopher Sims + * 2002 Mex implementation by Iskander Karibzhanov + * 2004 Modified to C function by Tao Zha (April), correcting a few bugs of Iskander. + * 03/01/06 Another modification by Tao Zha, to be consistent with the CAS 3/10/04 correction. + * + * Note: Iskander is transforming g0 and g1 to complex matrices and uses zgges() as a qz decomposition. + * This is really wasting efficiency. One should keep g0 and g1 as real matrices and use + * dgges() as a qz decomposition. I don't have time to overhaul this at this point. 04/20/04, T. Zha. + * Note: 02/22/06. I take the above note back. According to DW, it is easy to *order* the + * the generalized eigenvalues by using the complex g0 and g1. In principle, one could + * order the roots using the real qz decomposition on real matrices g0 and g1. But so far + * Dan has found it a pain to do it. Perhaps we should read the MKL Lapack manual more + * carefully at a later point. +********************************************************************/ +#include "gensys.h" + + +//----- NOTE: We can't replace MKL_Complex16 with a different name because the Intel Lapack uses MKL_Complex16. +//----- The only way to do this is to overhaul the code and put a wrapper function on each Intel Lapack function. +static int selctg(MKL_Complex16 *alpha, MKL_Complex16 *beta); +static int qz(MKL_Complex16 *a, MKL_Complex16 *b, MKL_Complex16 *q, MKL_Complex16 *z, int n); +static MKL_Complex16* CreateComplexMatrix5RealMatrix(TSdmatrix *X_dm); +static MKL_Complex16* CreateComplexMatrix5RealVector(TSdvector *x_dv); +static void ComplexMatrix2RealMatrix(TSdmatrix *Y_dm, MKL_Complex16 *Z); +static void ComplexMatrix2RealVector(TSdvector *y_dv, MKL_Complex16 *Z); +static TSdzmatrix *SubComplexMatrix2Zmatrix(TSdzmatrix *X_dzm, MKL_Complex16 *Z, const int nrowsforZ, const int _m, const int _n); +static void copy_eigenvalues(TSdzmatrix *Gev_dzm, MKL_Complex16 *a, MKL_Complex16 *b); +static int compute_svd(MKL_Complex16 *a, MKL_Complex16 **u, double **d, MKL_Complex16 **v, int m, int n); +static int compute_norm(MKL_Complex16 *a, double **d, int m, int n); +//--- 03/01/06 TZ. Commented out to be consistent with the CAS 3/10/04 correction. +// static int compute_normx(MKL_Complex16 *a, MKL_Complex16 *b, MKL_Complex16 *zwt, MKL_Complex16 *ueta, double **normx, int nunstab, int psin, int n, int bigev); +static void cblas_zdupe(int m, int n, MKL_Complex16 *a, int lda, MKL_Complex16 *b, int ldb); +static void cblas_zdscali(int n, double *a, int lda, MKL_Complex16 *b, int ldb); +static void cblas_zdscale(int n, double *a, int lda, MKL_Complex16 *b, int ldb); +static void cblas_zdpsb(int m, int n, MKL_Complex16 *a, int lda, MKL_Complex16 *b, int ldb, MKL_Complex16 *c, int ldc); +// +static void InitializeConstantMLK_Complex16(MKL_Complex16 *x_clx, const int _n, const double c); +static void InitializeConstantDouble(double *x_p, const int _n, const double c); +static void ConverteZeroSquareMatrix2RealDiagonalMLK_Complex16(MKL_Complex16 *x_pc, const int _n, const double c); + + +TSgensys *CreateTSgensys(TFlinratexp *func, const int _n, const int _m, const int _k, const double div) +{ + //_n is the number of stacked variables (endogenous, Lagurangian multiplier, expected multiplier, etc.). + //_m is the number of exogenous shocks. + //_k is the number of expectational errors. + //div is the dividing number to determine what constitutes an unstable root. If div<1.0, a div>1.0 is calculated mechanically. + TSgensys *gensys_ps = tzMalloc(1, TSgensys); + + //=== Output arguments. + gensys_ps->Theta_dm = CreateMatrix_lf(_n, _n); //n-by-n. + gensys_ps->c_dv = CreateVector_lf(_n); //n-by-1. + gensys_ps->Impact_dm = CreateMatrix_lf(_n, _m); //n-by-m. + gensys_ps->Fmat_dzm = (TSdzmatrix *)NULL; //nunstab-by-nunstab z matrix. Initialized to NULL and will be dynamically allocated whenever gensys() is called. + gensys_ps->Fwt_dzm = (TSdzmatrix *)NULL; //nunstab-by-m z matrix of possible complex numbers. Initialized to NULL and dynamically allocated. + gensys_ps->Ywt_dzm = (TSdzmatrix *)NULL; //n-by-nunstab z matrix of possible complex numbers. Initialized to NULL and dynamically allocated. + gensys_ps->Gev_dzm = CreateMatrix_dz(_n, 2); //n-by-2 z matrix of possible complex numbers. + gensys_ps->eu_iv = CreateConstantVector_int(2, 0); //2-by-1. + + //=== Function itself. + gensys_ps->gensys = func; + + //=== Input arguments. + gensys_ps->G0_dm = CreateConstantMatrix_lf(_n, _n, 0.0); //n-by-n. + gensys_ps->G0_dm->flag = M_GE; + gensys_ps->G1_dm = CreateConstantMatrix_lf(_n, _n, 0.0); //n-by-n. + gensys_ps->G1_dm->flag = M_GE; + gensys_ps->c0_dv = CreateConstantVector_lf(_n, 0.0); //n-by-1. + gensys_ps->Psi_dm = CreateConstantMatrix_lf(_n, _m, 0.0); //n-by-m. + gensys_ps->Psi_dm->flag = M_GE; + gensys_ps->Pi_dm = CreateConstantMatrix_lf(_n, _k, 0.0); //n-by-k where k is the number of expectational errors. + gensys_ps->Pi_dm->flag = M_GE; + gensys_ps->div = div; + + return (gensys_ps); +} +//------- +TSgensys *DestroyTSgensys(TSgensys *gensys_ps) +{ + if (gensys_ps) { + //=== Output arguments. + DestroyMatrix_lf(gensys_ps->Theta_dm); //n-by-n. + DestroyVector_lf(gensys_ps->c_dv); //n-by-1. + DestroyMatrix_lf(gensys_ps->Impact_dm); //n-by-m. + DestroyMatrix_dz(gensys_ps->Fmat_dzm); //nunstab-by-nunstab z matrix. Initialized to NULL and will be dynamically allocated whenever gensys() is called. + DestroyMatrix_dz(gensys_ps->Fwt_dzm); //nunstab-by-m z matrix of possible complex numbers. Initialized to NULL and dynamically allocated. + DestroyMatrix_dz(gensys_ps->Ywt_dzm); //n-by-nunstab z matrix of possible complex numbers. Initialized to NULL and dynamically allocated. + DestroyMatrix_dz(gensys_ps->Gev_dzm); //n-by-2 z matrix of possible complex numbers. + DestroyVector_int(gensys_ps->eu_iv); //2-by-1. + + //=== Input arguments. + DestroyMatrix_lf(gensys_ps->G0_dm); //n-by-n. + DestroyMatrix_lf(gensys_ps->G1_dm); //n-by-n. + DestroyVector_lf(gensys_ps->c0_dv); //n-by-1. + DestroyMatrix_lf(gensys_ps->Psi_dm); //n-by-m. + DestroyMatrix_lf(gensys_ps->Pi_dm); //n-by-k where k is the number of expectational errors. + + free(gensys_ps); + + return ((TSgensys *)NULL); + } + else return (gensys_ps); +} + + +//--------------------------- For the function gensys_sims() ------------------------------------ +static int fixdiv = 1, zxz = 0; +static double stake = 1.01; +static int nunstab = 0; +static MKL_Complex16 one, minusone, zero; + +/* [G1,C,impact,fmat,fwt,ywt,gev,eu]=gensysmkl(g0,g1,c,psi,pi,stake) */ +//void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { +int gensys_sims(TSgensys *gensys_ps, void *dummy_ps) +{ + //Returns 1 if successful and 0 for fatal errors (such as qz or svd fails or all roots are explosive). Added DW and TZ, 03/08/06. + int tmpi; + int n, psin, pin, nsquare, md, md1, i, bigev, bigev1; //mds, bigevs, //03/01/06 TZ. Commented out to be consistent with the CAS 3/10/04 correction. + int *eu; + int exist = 0, existx = 0, unique = 0; + //=== Memory will be allocated to the following. + double *deta = NULL, *deta1 = NULL, *norm = NULL; //*normx = NULL, *dz = NULL, //03/01/06 TZ. Commented out to be consistent with the CAS 3/10/04 correction. + MKL_Complex16 *a = NULL, *b = NULL, *q = NULL, *z = NULL, *pi = NULL, *psi = NULL; + MKL_Complex16 *tmat = NULL, *g0 = NULL, *g1 = NULL, *dummy = NULL, *tmatq = NULL, *c = NULL, *impact = NULL, *ab = NULL; + MKL_Complex16 *fmat = NULL, *fwt = NULL, *ywt = NULL; + MKL_Complex16 *etawt = NULL, *ueta = NULL, *veta = NULL, *etawt1 = NULL, *ueta1 = NULL, *veta1 = NULL; + // *uz = NULL, *vz = NULL, *zwt = NULL, //03/01/06 TZ. Commented out to be consistent with the CAS 3/10/04 correction. + //--- Dimensions. + n = gensys_ps->G0_dm->nrows; + psin = gensys_ps->Psi_dm->ncols; + pin = gensys_ps->Pi_dm->ncols; + //--- Pointer. + eu = gensys_ps->eu_iv->v; + + eu[0]=eu[1]=0; //Must be initialized because gensys_ps->eu_iv->v may have values in repeated loops. + + //=== [a b q z]=qz(g0,g1); + a = CreateComplexMatrix5RealMatrix(gensys_ps->G0_dm); + b = CreateComplexMatrix5RealMatrix(gensys_ps->G1_dm); + q = tzMalloc(nsquare=square(n), MKL_Complex16); + z = tzMalloc(nsquare, MKL_Complex16); + InitializeConstantMLK_Complex16(q, nsquare, 0.0); + InitializeConstantMLK_Complex16(z, nsquare, 0.0); + + fixdiv = (gensys_ps->div < 1.0); + stake = fixdiv ? 1.01 : gensys_ps->div; + nunstab = 0; + zxz = 0; + + if (qz(a, b, q, z, n)) { + printf("WARNING: QZ factorization failed.\n"); + tzDestroy(a); + tzDestroy(b); + tzDestroy(q); + tzDestroy(z); + eu[0] = 0; + return 0; + } + + nunstab /= 2; + + if (zxz) { + printf("WARNING: Coincident zeros. Indeterminacy and/or nonexistence.\n"); + eu[0] = eu[1] = -2; + tzDestroy(a); + tzDestroy(b); + tzDestroy(q); + tzDestroy(z); + return 1; + } + copy_eigenvalues(gensys_ps->Gev_dzm, a, b); + + one.real = 1.0; + one.imag = 0.0; + + minusone.real = -1.0; + minusone.imag = 0.0; + + zero.real = 0.0; + zero.imag = 0.0; + + pi = CreateComplexMatrix5RealMatrix(gensys_ps->Pi_dm); + //============================================= + // Modified by DW and TZ to deal with the case where nunstab=0 (no explosive roots). 03/08/06. + //============================================= + if (nunstab) //This branch belongs to original CAS code. + { + etawt = tzMalloc(tmpi=nunstab*pin, MKL_Complex16); + InitializeConstantMLK_Complex16(etawt, tmpi, 0.0); //Must be initialized to 0.0 in order to have legal values of this pointer. + cblas_zgemm(CblasColMajor, CblasConjTrans, CblasNoTrans, nunstab, pin, n, + &one, q+n*(n-nunstab), n, pi, n, &zero, etawt, nunstab); + if (compute_svd(etawt, &ueta, &deta, &veta, nunstab, pin)) { + //Memory is now allocated to ueta, deta, and veta. + printf("WARNING: SVD failed.\n"); + tzDestroy(pi); + tzDestroy(ueta); + tzDestroy(deta); + tzDestroy(veta); + tzDestroy(etawt); + tzDestroy(a); + tzDestroy(b); + tzDestroy(q); + tzDestroy(z); + eu[0] = 0; + return 0; + } + tzDestroy(etawt); + md = nunstab<pin?nunstab:pin; + bigev = md; + for (i=0; i<md; i++) + if (deta[i]<=REALSMALL) { + bigev=i; + break; + } + //------ 03/01/06 TZ: corrected code by CAS, 3/10/04. + if ((eu[0]=(bigev >= nunstab))==0) //DW & TZ, 03/08/06 + { + tzDestroy(pi); + tzDestroy(ueta); + tzDestroy(deta); + tzDestroy(veta); + tzDestroy(a); + tzDestroy(b); + tzDestroy(q); + tzDestroy(z); + return 1; + } + } + else //DW & TZ. 03/08/06. This is where we deal with the case when nunstab=0. + { + eu[0] = 1; //Existence. + } + + + //--------------------------------- + // ueta = nunstab x bigev + // deta = bigev x 1 + // veta = bigev x pin, ldveta = md + // uz = nunstab x bigevs + // dz = bigevs x 1 + // vz = bigevs x psin, ldvz = mds + //--------------------------------- + + //====== 03/01/06 TZ: the following note is added by CAS 3/10/04. + //------ Code below allowed "existence" in cases where the initial lagged state was free to take on values + //------ inconsistent with existence, so long as the state could w.p.1 remain consistent with a stable solution + //------ if its initial lagged value was consistent with a stable solution. This is a mistake, though perhaps there + //------ are situations where we would like to know that this "existence for restricted initial state" situation holds. + // psi = CreateComplexMatrix5RealMatrix(gensys_ps->Psi_dm); + // zwt = tzMalloc(tmpi=nunstab*psin, MKL_Complex16); + // InitializeConstantMLK_Complex16(zwt, tmpi, 0.0); //Must be initialized to 0.0 in order to have legal values of this pointer. + // cblas_zgemm(CblasColMajor, CblasConjTrans, CblasNoTrans, nunstab, psin, n, + // &one, q+n*(n-nunstab), n, psi, n, &zero, zwt, nunstab); + // if (compute_svd(zwt, &uz, &dz, &vz, nunstab, psin)) { + // //Memory is now allocated to uz, dz, and vz. + // printf("WARNING: SV decomposition failed.\n"); + // tzDestroy(ueta); + // tzDestroy(deta); + // tzDestroy(veta); + // tzDestroy(uz); + // tzDestroy(dz); + // tzDestroy(vz); + // tzDestroy(zwt); + // tzDestroy(a); + // tzDestroy(b); + // tzDestroy(q); + // tzDestroy(z); + // return; + // } + // tzDestroy(vz); + // mds = nunstab<psin?nunstab:psin; + // bigevs = mds; + // for (i=0; i<mds; i++) + // if (dz[i]<=REALSMALL) { + // bigevs=i; + // break; + // } + // tzDestroy(dz); + // + // if (!bigevs) { + // exist = 1; + // existx = 1; + // } else { + // /* uz-ueta*ueta'*uz */ + // MKL_Complex16 *tmp = tzMalloc(tmpi=nunstab*nunstab, MKL_Complex16); + // InitializeConstantMLK_Complex16(tmp, tmpi, 0.0); //Must be initialized to 0.0 in order to have legal values of this pointer. + // cblas_zgemm(CblasColMajor, CblasNoTrans, CblasConjTrans, nunstab, nunstab, + // bigev, &one, ueta, nunstab, ueta, nunstab, &zero, tmp, nunstab); + // cblas_zhemm(CblasColMajor, CblasLeft, CblasUpper, nunstab, + // bigevs, &minusone, tmp, nunstab, uz, nunstab, &one, uz, nunstab); + // tzDestroy(tmp); + // if (compute_norm(uz, &norm, nunstab, bigevs)) { + // //Memory is now allocated to norm. + // printf("WARNING: SVD failed.\n"); + // tzDestroy(norm); + // tzDestroy(ueta); + // tzDestroy(deta); + // tzDestroy(veta); + // tzDestroy(uz); + // tzDestroy(zwt); + // tzDestroy(a); + // tzDestroy(b); + // tzDestroy(q); + // tzDestroy(z); + // return; + // } + // exist = *norm < REALSMALL*n; + // tzDestroy(norm); + // if (compute_normx(a, b, zwt, ueta, &normx, nunstab, psin, n, bigev)) { + // //If 0, memory is now allocated to normx; otherwise, normx is destroyed within the function compute_normx(). + // tzDestroy(ueta); + // tzDestroy(deta); + // tzDestroy(veta); + // tzDestroy(uz); + // tzDestroy(zwt); + // tzDestroy(a); + // tzDestroy(b); + // tzDestroy(q); + // tzDestroy(z); + // return; + // } + // existx = *normx < REALSMALL*n; + // tzDestroy(normx); + // } + // + // tzDestroy(uz); + // tzDestroy(zwt); + + //--------------------------------------------------------------------------- + // Note that existence and uniqueness are not just matters of comparing + // numbers of roots and numbers of endogenous errors. These counts are + // reported below because usually they point to the source of the problem. + //--------------------------------------------------------------------------- + //============================================= + // Modified by DW and TZ to deal with the case + // where nunstab=n (all explosive roots). 03/08/06. + //============================================= + if (nunstab == n) + { + tzDestroy(pi); + tzDestroy(ueta); + tzDestroy(deta); + tzDestroy(veta); + tzDestroy(a); + tzDestroy(b); + tzDestroy(q); + tzDestroy(z); + + printf("\n******** Fatal error: All roots are explosive while we have a solution. But this should NOT happen.***********\n"); + eu[0] = 0; + return 0; + } + + //======= Otherwise, returns to CAS's original code. 03/08/06. =======// + etawt1 = tzMalloc(tmpi=(n-nunstab)*pin, MKL_Complex16); + InitializeConstantMLK_Complex16(etawt1, tmpi, 0.0); //Must be initialized to 0.0 in order to have legal values of this pointer. + cblas_zgemm(CblasColMajor, CblasConjTrans, CblasNoTrans, n-nunstab, pin, n, + &one, q, n, pi, n, &zero, etawt1, n-nunstab); + tzDestroy(pi); + if (compute_svd(etawt1, &ueta1, &deta1, &veta1, n-nunstab, pin)) { + //Memory is now allocated to ueta1, deta1, and veta1. + printf("WARNING: SVD failed for compute_svd().\n"); + tzDestroy(ueta1); + tzDestroy(deta1); + tzDestroy(veta1); + tzDestroy(etawt1); + tzDestroy(ueta); + tzDestroy(deta); + tzDestroy(veta); + tzDestroy(a); + tzDestroy(b); + tzDestroy(q); + tzDestroy(z); + eu[0] = 0; + return 0; + } + tzDestroy(etawt1); + md1 = n-nunstab<pin?n-nunstab:pin; + bigev1 = md1; + for (i=0; i<md1; i++) + if (deta1[i]<=REALSMALL) { + bigev1=i; + break; + } + + //====== 03/01/06 TZ: the following is commented out by CAS 3/10/04. + // if (existx || !nunstab) { + // //=== Solution exists. + // eu[0] = 1; + // } else { + // if (exist) { + // printf("WARNING: Solution exists for unforecastable z only\n"); + // eu[0] = -1; + // } /* else + // mexPrintf("No solution. %d unstable roots. %d endog errors.\n",nunstab,bigev1); */ + // /* mexPrintf("Generalized eigenvalues\n"); + // mexCallMATLAB(0,NULL,1, &plhs[6], "disp"); */ + // } + + + //------------------------------- + // ueta1 = n-nunstab x bigev1 + // deta1 = bigev1 x 1 + // veta1 = bigev1 x pin, ldveta1 = md1 + //------------------------------- + if (!bigev1) + unique = 1; + else { + // veta1-veta1*veta*veta' + // veta = bigev x pin, ldveta1 = md + // veta1 = bigev1 x pin, ldveta1 = md1 + MKL_Complex16 *tmp = tzMalloc(pin*pin, MKL_Complex16); + MKL_Complex16 *veta1_copy = tzMalloc(pin*bigev1, MKL_Complex16); + InitializeConstantMLK_Complex16(tmp, pin*pin, 0.0); //Must be initialized to 0.0 in order to have legal values of this pointer. + InitializeConstantMLK_Complex16(veta1_copy, pin*bigev1, 0.0); //Must be initialized to 0.0 in order to have legal values of this pointer. + if (nunstab) + { + cblas_zgemm(CblasColMajor, CblasConjTrans, CblasNoTrans, pin, pin, + bigev, &one, veta, md, veta, md, &zero, tmp, pin); //tmp=veta'*veta; + cblas_zdupe(bigev1,pin,veta1,md1,veta1_copy,bigev1); + cblas_zhemm(CblasColMajor, CblasRight, CblasUpper, bigev1, pin, + &minusone, tmp, pin, veta1_copy, bigev1, &one, veta1_copy, bigev1); + } + else //Added by DW & TZ, 03/08/06. + { + cblas_zdupe(bigev1,pin,veta1,md1,veta1_copy,bigev1); + } + tzDestroy(tmp); + if (compute_norm(veta1_copy, &norm, bigev1, pin)) { + //Memory is now allocated to norm. + printf("WARNING: SVD failed.\n"); + tzDestroy(norm); + tzDestroy(ueta1); + tzDestroy(deta1); + tzDestroy(veta1); + tzDestroy(ueta); + tzDestroy(deta); + tzDestroy(veta); + tzDestroy(veta1_copy); + tzDestroy(a); + tzDestroy(b); + tzDestroy(q); + tzDestroy(z); + eu[0] = 0; + return 0; + } + tzDestroy(veta1_copy); + unique = *norm < REALSMALL*n; + tzDestroy(norm); + } + if (unique) { + //=== Unique solution. + eu[1] = 1; + } else { + eu[1] = 0; + #if defined (PRINTWARNINGofSUNSPOT) + if (nunstab) + printf("WARNING: Indeterminacy. %d loose endog errors with eu being [%d, %d].\n",bigev1-bigev, eu[0], eu[1]); + else + printf("WARNING: Indeterminacy. %d loose endog errors with eu being [%d, %d].\n",pin, eu[0], eu[1]); + //printf("WARNING: Indeterminacy. %d loose endog errors with eu being [%g, %g].\n",bigev1-bigev, gensys_ps->eu_dv->v[0], gensys_ps->eu_dv->v[1]); + //printf("WARNING: Indeterminacy. %d loose endog errors.\n",bigev1-bigev); + #endif + } + + //---------------------------------------------------------// + //------------------ Obtaining the outputs. ---------------// + //---------------------------------------------------------// + if (nunstab) + { + //=== All the following lines are used to compute only ONE object tmat, which is used subsequently. ===// + cblas_zdscali(pin,deta,bigev,veta,md); /* veta' = deta\veta' */ + tzDestroy(deta); + cblas_zdscale(pin,deta1,bigev1,veta1,md1); /* veta1' = deta1*veta1' */ + tzDestroy(deta1); + etawt = tzMalloc(tmpi=nunstab*pin, MKL_Complex16); /* etawt = ueta*veta' */ + InitializeConstantMLK_Complex16(etawt, tmpi, 0.0); //Must be initialized to 0.0 in order to have legal values of this pointer. + cblas_zgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, nunstab, pin, bigev, + &one, ueta, nunstab, veta, md, &zero, etawt, nunstab); + tzDestroy(ueta); + tzDestroy(veta); + etawt1 = tzMalloc(tmpi=(n-nunstab)*pin, MKL_Complex16); /* etawt1 = ueta1*veta1' */ + InitializeConstantMLK_Complex16(etawt1, tmpi, 0.0); //Must be initialized to 0.0 in order to have legal values of this pointer. + cblas_zgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, n-nunstab, pin, bigev1, + &one, ueta1, n-nunstab, veta1, md1, &zero, etawt1, n-nunstab); + tzDestroy(ueta1); + tzDestroy(veta1); + tmat = tzMalloc(tmpi=(n-nunstab)*nunstab, MKL_Complex16); /* tmat = etawt1*etawt' */ + InitializeConstantMLK_Complex16(tmat, tmpi, 0.0); //Must be initialized to 0.0 in order to have legal values of this pointer. + cblas_zgemm(CblasColMajor, CblasNoTrans, CblasConjTrans, n-nunstab, nunstab, pin, + &one, etawt1, n-nunstab, etawt, nunstab, &zero, tmat, n-nunstab); + tzDestroy(etawt1); + tzDestroy(etawt); + + //=== Getting the solution Theta ===// + g0 = tzMalloc(tmpi=n*n, MKL_Complex16); + InitializeConstantMLK_Complex16(g0, tmpi, 0.0); //Must be initialized to 0.0 in order to have legal values of this pointer. + cblas_zdupe(n-nunstab, n, a, n, g0, n); + cblas_zgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, n-nunstab, nunstab, nunstab, + &minusone, tmat, n-nunstab, a+(n-nunstab)*(n+1), n, &one, g0+(n-nunstab)*n, n); + cblas_zcopy(nunstab, &one, 0, g0+(n-nunstab)*(n+1), n+1); + + g1 = tzMalloc(tmpi=n*n, MKL_Complex16); + InitializeConstantMLK_Complex16(g1, tmpi, 0.0); //Must be initialized to 0.0 in order to have legal values of this pointer. + cblas_zdupe(n-nunstab, n, b, n, g1, n); + cblas_zgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, n-nunstab, nunstab, nunstab, + &minusone, tmat, n-nunstab, b+(n-nunstab)*(n+1), n, &one, g1+(n-nunstab)*n, n); + cblas_ztrsm(CblasColMajor, CblasLeft, CblasUpper, CblasNoTrans, CblasNonUnit, + n, n, &one, g0, n, g1, n); + dummy = tzMalloc(tmpi=n*n, MKL_Complex16); + InitializeConstantMLK_Complex16(dummy, tmpi, 0.0); //Must be initialized to 0.0 in order to have legal values of this pointer. + cblas_zgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, n, n, n, &one, z, n, g1, n, &zero, dummy, n); + cblas_zgemm(CblasColMajor, CblasNoTrans, CblasConjTrans, n, n, n, &one, dummy, n, z, n, &zero, g1, n); + tzDestroy(dummy); + ComplexMatrix2RealMatrix(gensys_ps->Theta_dm, g1); //Output. + tzDestroy(g1); + + //=== Getting the constant term c ===// + tmatq = tzMalloc(tmpi=n*n, MKL_Complex16); + InitializeConstantMLK_Complex16(tmatq, tmpi, 0.0); //Must be initialized to 0.0 in order to have legal values of this pointer. + cblas_zcopy(n*n, q, 1, tmatq, 1); + cblas_zgemm(CblasColMajor, CblasNoTrans, CblasConjTrans, n, n-nunstab, nunstab, + &minusone, tmatq+(n-nunstab)*n, n, tmat, n-nunstab, &one, tmatq, n); + tzDestroy(tmat); + + ab = tzMalloc(tmpi=nunstab*nunstab, MKL_Complex16); + InitializeConstantMLK_Complex16(ab, tmpi, 0.0); //Must be initialized to 0.0 in order to have legal values of this pointer. + cblas_zdpsb(nunstab, nunstab, a+(n-nunstab)*(n+1), n, b+(n-nunstab)*(n+1), n, ab, nunstab); + cblas_ztrsm(CblasColMajor, CblasRight, CblasUpper, CblasConjTrans, CblasNonUnit, + n, nunstab, &one, ab, nunstab, tmatq+(n-nunstab)*n, n); + tzDestroy(ab); + + c = CreateComplexMatrix5RealVector(gensys_ps->c0_dv); + dummy = tzMalloc(gensys_ps->c0_dv->n, MKL_Complex16); + //$$$$$$$ The following is Iskander's fatal code error. One cannot use c in the two different places; otherwise, it makes c be zero completely! + // cblas_zgemv(CblasColMajor, CblasConjTrans, n, n, &one, tmatq, n, c, 1, &zero, c, 1); + // cblas_ztrsv(CblasColMajor, CblasUpper, CblasNoTrans, CblasNonUnit, n, g0, n, c, 1); + // cblas_zgemv(CblasColMajor, CblasNoTrans, n, n, &one, z, n, c, 1, &zero, c, 1); + cblas_zgemv(CblasColMajor, CblasConjTrans, n, n, &one, tmatq, n, c, 1, &zero, dummy, 1); + cblas_ztrsv(CblasColMajor, CblasUpper, CblasNoTrans, CblasNonUnit, n, g0, n, dummy, 1); + cblas_zgemv(CblasColMajor, CblasNoTrans, n, n, &one, z, n, dummy, 1, &zero, c, 1); + ComplexMatrix2RealVector(gensys_ps->c_dv, c); //Output. + tzDestroy(c); + tzDestroy(dummy); + + //=== Getting the term Impact ===// + impact = tzMalloc(tmpi=n*psin, MKL_Complex16); + InitializeConstantMLK_Complex16(impact, tmpi, 0.0); //Must be initialized to 0.0 in order to have legal values of this pointer. + psi = CreateComplexMatrix5RealMatrix(gensys_ps->Psi_dm); //03/01/06 TZ. Added to be consistent with the CAS 3/10/04 correction. + cblas_zgemm(CblasColMajor, CblasConjTrans, CblasNoTrans, n-nunstab, psin, n, + &one, tmatq, n, psi, n, &zero, impact, n); + tzDestroy(tmatq); + cblas_ztrsm(CblasColMajor, CblasLeft, CblasUpper, CblasNoTrans, CblasNonUnit, + n, psin, &one, g0, n, impact, n); + dummy = tzMalloc(tmpi=n*psin, MKL_Complex16); + InitializeConstantMLK_Complex16(dummy, tmpi, 0.0); //Must be initialized to 0.0 in order to have legal values of this pointer. + cblas_zgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, n, psin, n, + &one, z, n, impact, n, &zero, dummy, n); + tzDestroy(impact); + ComplexMatrix2RealMatrix(gensys_ps->Impact_dm, dummy); //Output. + tzDestroy(dummy); + + //=== Finishing up the other terms such as Fmat, Fwt, and Ywt. ===// + fmat = a+(n-nunstab)*(n+1); + cblas_ztrsm(CblasColMajor, CblasLeft, CblasUpper, CblasNoTrans, CblasNonUnit, + nunstab, nunstab, &one, b+(n-nunstab)*(n+1), n, fmat, n); + gensys_ps->Fmat_dzm = SubComplexMatrix2Zmatrix(gensys_ps->Fmat_dzm, fmat, n, nunstab, nunstab); + tzDestroy(a); + + fwt = tzMalloc(tmpi=nunstab*psin, MKL_Complex16); + InitializeConstantMLK_Complex16(fwt, tmpi, 0.0); //Must be initialized to 0.0 in order to have legal values of this pointer. + cblas_ztrsm(CblasColMajor, CblasRight, CblasUpper, CblasConjTrans, CblasNonUnit, + n, nunstab, &one, b+(n-nunstab)*(n+1), n, q+(n-nunstab)*n, n); + tzDestroy(b); + cblas_zgemm(CblasColMajor, CblasConjTrans, CblasNoTrans, nunstab, psin, n, + &minusone, q+(n-nunstab)*n, n, psi, n, &zero, fwt, nunstab); + tzDestroy(q); + tzDestroy(psi); + gensys_ps->Fwt_dzm = SubComplexMatrix2Zmatrix(gensys_ps->Fwt_dzm, fwt, nunstab, nunstab, psin); + tzDestroy(fwt); + + ywt = tzMalloc(tmpi=n*nunstab, MKL_Complex16); + InitializeConstantMLK_Complex16(ywt, tmpi, 0.0); + cblas_zcopy(nunstab, &one, 0, ywt+n-nunstab, n+1); + cblas_ztrsm(CblasColMajor, CblasLeft, CblasUpper, CblasNoTrans, CblasNonUnit, + n, nunstab, &one, g0, n, ywt, n); + tzDestroy(g0); + dummy = tzMalloc(tmpi=n*nunstab, MKL_Complex16); + InitializeConstantMLK_Complex16(dummy, tmpi, 0.0); //Must be initialized to 0.0 in order to have legal values of this pointer. + cblas_zgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, n, nunstab, n, + &one, z, n, ywt, n, &zero, dummy, n); + tzDestroy(z); + tzDestroy(ywt); + gensys_ps->Ywt_dzm = SubComplexMatrix2Zmatrix(gensys_ps->Ywt_dzm, dummy, n, n, nunstab); + tzDestroy(dummy); + } + else //This part is added by DW and TZ, 03/08/06. + { + //======= Getting Theta = real(z*(G0\G1)*z') =======// + cblas_ztrsm(CblasColMajor, CblasLeft, CblasUpper, CblasNoTrans, CblasNonUnit, + n, n, &one, a, n, b, n); //Note that a is triangular and b = a\b (overwritten). + dummy = tzMalloc(tmpi=n*n, MKL_Complex16); + InitializeConstantMLK_Complex16(dummy, tmpi, 0.0); //Must be initialized to 0.0 in order to have legal values of this pointer. + //--- Getting Theta = real(z*b*z'); + cblas_zgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, n, n, n, &one, z, n, b, n, &zero, dummy, n); //dummy=z*b; + cblas_zgemm(CblasColMajor, CblasNoTrans, CblasConjTrans, n, n, n, &one, dummy, n, z, n, &zero, b, n); //dummy=dummy*z'; + ComplexMatrix2RealMatrix(gensys_ps->Theta_dm, b); //Output. + tzDestroy(dummy); + + //======= Getting c = real(z*G0\q*c0) =======// + c = CreateComplexMatrix5RealVector(gensys_ps->c0_dv); + dummy = tzMalloc(gensys_ps->c0_dv->n, MKL_Complex16); + cblas_zgemv(CblasColMajor, CblasConjTrans, n, n, &one, q, n, c, 1, &zero, dummy, 1); //dummy = q*c; + cblas_ztrsv(CblasColMajor, CblasUpper, CblasNoTrans, CblasNonUnit, n, a, n, dummy, 1); //dummy=a\dummy where a is triangular. + cblas_zgemv(CblasColMajor, CblasNoTrans, n, n, &one, z, n, dummy, 1, &zero, c, 1); //dummy=z*dummy; + ComplexMatrix2RealVector(gensys_ps->c_dv, c); //Output. + tzDestroy(dummy); + + //======= Getting Impact = real(z*G0\q*psi) =======// + impact = tzMalloc(tmpi=n*psin, MKL_Complex16); + InitializeConstantMLK_Complex16(impact, tmpi, 0.0); //Must be initialized to 0.0 in order to have legal values of this pointer. + psi = CreateComplexMatrix5RealMatrix(gensys_ps->Psi_dm); //03/01/06 TZ. Added to be consistent with the CAS 3/10/04 correction. + dummy = tzMalloc(tmpi=n*psin, MKL_Complex16); + cblas_zgemm(CblasColMajor, CblasConjTrans, CblasNoTrans, n, psin, n, + &one, q, n, psi, n, &zero, impact, n); //impact = q*psi; + cblas_ztrsm(CblasColMajor, CblasLeft, CblasUpper, CblasNoTrans, CblasNonUnit, + n, psin, &one, a, n, impact, n); //impact = a\impact; + InitializeConstantMLK_Complex16(dummy, tmpi, 0.0); //Must be initialized to 0.0 in order to have legal values of this pointer. + cblas_zgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, n, psin, n, + &one, z, n, impact, n, &zero, dummy, n); //dummy = z*impact; + ComplexMatrix2RealMatrix(gensys_ps->Impact_dm, dummy); //Output. + tzDestroy(dummy); + + + //=== Some of destructions may have been done, but it is better to be safe. + tzDestroy(ueta1); + tzDestroy(deta1); + tzDestroy(veta1); + tzDestroy(etawt); + tzDestroy(etawt1); + //+ + tzDestroy(a); + tzDestroy(b); + tzDestroy(q); + tzDestroy(z); + //+ + tzDestroy(c); + tzDestroy(impact); + tzDestroy(psi); + } + + //=== Save this debugging format -- DDDDDebugging. + // if (!nunstab) + // { + // fprintf(FPTR_DEBUG, "Aind=[\n"); + // WriteMatrix(FPTR_DEBUG, gensys_ps->G0_dm, " %.16e "); + // fprintf(FPTR_DEBUG, "];\n"); + // fprintf(FPTR_DEBUG, "Bind=[\n"); + // WriteMatrix(FPTR_DEBUG, gensys_ps->G1_dm, " %.16e "); + // fprintf(FPTR_DEBUG, "];\n"); + // fprintf(FPTR_DEBUG, "Consterm=[\n"); + // WriteVector(FPTR_DEBUG, gensys_ps->c0_dv, " %.16e "); + // fprintf(FPTR_DEBUG, "]';\n"); + // fprintf(FPTR_DEBUG, "gUpsiloneind=[\n"); + // WriteMatrix(FPTR_DEBUG, gensys_ps->Psi_dm, " %.16e "); + // fprintf(FPTR_DEBUG, "];\n"); + // fprintf(FPTR_DEBUG, "gUpsilonxind=[\n"); + // WriteMatrix(FPTR_DEBUG, gensys_ps->Pi_dm, " %.16e "); + // fprintf(FPTR_DEBUG, "];\n"); + // fflush(FPTR_DEBUG); + // + // fprintf(FPTR_DEBUG, "\n********** Output ******************\n"); + // fprintf(FPTR_DEBUG, "Theta=[\n"); + // WriteMatrix(FPTR_DEBUG, gensys_ps->Theta_dm, " %.16e "); + // fprintf(FPTR_DEBUG, "];\n"); + // fprintf(FPTR_DEBUG, "Impact=[\n"); + // WriteMatrix(FPTR_DEBUG, gensys_ps->Impact_dm, " %.16e "); + // fprintf(FPTR_DEBUG, "];\n"); + // fprintf(FPTR_DEBUG, "Consterm=[\n"); + // WriteVector(FPTR_DEBUG, gensys_ps->c_dv, " %.16e "); + // fprintf(FPTR_DEBUG, "]';\n"); + // fprintf(FPTR_DEBUG, "eu=[\n"); + // WriteVector_int(FPTR_DEBUG, gensys_ps->eu_iv); + // fprintf(FPTR_DEBUG, "]';\n"); + // fflush(FPTR_DEBUG); + // } + + return 1; +} + + +/****************************************************************************** + * function selctg orders the eigenvalues so that a selected cluster of * + * eigenvalues appears in the leading diagonal blocks of the upper * + * quasi-triangular matrix S and the upper triangular matrix T. * + ******************************************************************************/ + +static int selctg(MKL_Complex16 *alpha, MKL_Complex16 *beta) +{ + double absA = sqrt(alpha->real*alpha->real+alpha->imag*alpha->imag), + absB = fabs(beta->real); + if (absA) { + double divhat = absB/absA; + //bug detected by Vasco Curdia and Daria Finocchiaro, 2/25/2004 CAS. A root of + //exactly 1.01 and no root between 1 and 1.02, led to div being stuck at 1.01 + //and the 1.01 root being misclassified as stable. Changing < to <= below fixes this. + if (fixdiv && 1+REALSMALL<divhat && divhat<=stake) + stake = (1+divhat)/2; + } + if (absA<REALSMALL && absB<REALSMALL) + zxz = 1; + if (absB>stake*absA) { + nunstab++; + return(0); + } else + return(1); +} + +/****************************************************************************** + * compute for a pair of N-by-N complex nonsymmetric matrices (A,B), * + * the generalized eigenvalues, the generalized complex Schur form (S, T), * + * and optionally left and/or right Schur vectors (VSL and VSR) * + ******************************************************************************/ + +static int qz(MKL_Complex16 *a, MKL_Complex16 *b, MKL_Complex16 *q, MKL_Complex16 *z, int n) +{ +// unsigned char msg[101]; + int sdim, lwork = -1, info = 0; + MKL_Complex16 *alpha = tzMalloc(n,MKL_Complex16), + *beta = tzMalloc(n,MKL_Complex16), + *work, work1; + double *rwork = tzMalloc(8*n, double); + int *bwork = tzMalloc(4*n, int); + + /* Query zgges on the value of lwork */ + zgges("V", "V", "S", &selctg, &n, a, &n, b, &n, &sdim, alpha, beta, q, + &n, z, &n, &work1, &lwork, rwork, bwork, &info); + + if (info < 0) { + printf("WARNING: Input %d to the Intel MKL function zgges() has an illegal value",-info); + tzDestroy(bwork); + tzDestroy(rwork); + tzDestroy(alpha); + tzDestroy(beta); + return(info); + } + + lwork = (int)(work1.real); + work = tzMalloc(lwork, MKL_Complex16); + zgges("V", "V", "S", &selctg, &n, a, &n, b, &n, &sdim, alpha, beta, q, + &n, z, &n, work, &lwork, rwork, bwork, &info); + + tzDestroy(work); + tzDestroy(bwork); + tzDestroy(rwork); + tzDestroy(alpha); + tzDestroy(beta); + + if (info < 0) { + printf("WARNING: Input %d to the Intel MKL function zgges() has an illegal value",-info); + return(info); + } + + if (info > 0) + if (info < n) + printf("WARNING: The QZ iteration failed. (A,B) are not in Schur form,\n" + "but ALPHA(j) and BETA(j) should be correct for j=%d,...,N.",info+1); + else { + switch (info-n) { + case 1: + printf("WARNING: LAPACK problem: error return from ZGGBAL"); + break; + case 2: + printf("WARNING: LAPACK problem: error return from ZGEQRF"); + break; + case 3: + printf("WARNING: LAPACK problem: error return from ZUNMQR"); + break; + case 4: + printf("WARNING: LAPACK problem: error return from ZUNGQR"); + break; + case 5: + printf("WARNING: LAPACK problem: error return from ZGGHRD"); + break; + case 6: + printf("WARNING: LAPACK problem: error return from ZHGEQZ (other than failed iteration)"); + break; + case 7: + printf("WARNING: LAPACK problem: error return from ZGGBAK (computing VSL)"); + break; + case 8: + printf("WARNING: LAPACK problem: error return from ZGGBAK (computing VSR)"); + break; + case 9: + printf("WARNING: LAPACK problem: error return from ZLASCL (various places)"); + break; + default: + printf("WARNING: LAPACK problem: unknown error."); + break; + } + } + return(info); +} + +/* + * Convert MATLAB complex matrix to MKL complex storage. + * + * Z = mat2mkl(X,ldz,ndz) + * + * converts MATLAB's mxArray X to MKL_Complex16 Z(ldz,ndz). + * The parameters ldz and ndz determine the storage allocated for Z, + * while mxGetM(X) and mxGetN(X) determine the amount of data copied. + */ + +//MKL_Complex16* mat2mkl(const mxArray *X, int ldz, int ndz) { +// MKL_Complex16 *Z, *zp; +// int m, n, incz, cmplxflag; +// register int i, j; +// double *xr, *xi; + +// Z = mxCalloc(ldz*ndz, sizeof(MKL_Complex16)); +// xr = mxGetPr(X); +// xi = mxGetPi(X); +// m = mxGetM(X); +// n = mxGetN(X); +// zp = Z; +// incz = ldz-m; +// cmplxflag = (xi != NULL); +// for (j = 0; j < n; j++) { +// if (cmplxflag) { +// for (i = 0; i < m; i++) { +// zp->real = *xr++; +// zp->imag = *xi++; +// zp++; +// } +// } else { +// for (i = 0; i < m; i++) { +// zp->real = *xr++; +// zp++; +// } +// } +// zp += incz; +// } +// return(Z); +//} + + +/* + * Convert MKL complex storage to MATLAB real and imaginary parts. + * + * X = mkl2mat(Z,ldz,m,n) + * + * copies MKL_Complex16 Z to X, producing a complex mxArray + * with mxGetM(X) = m and mxGetN(X) = n. + */ + +//mxArray* mkl2mat(MKL_Complex16 *Z, int ldz, int m, int n) { +// int i, j, incz; +// double *xr, *xi; +// MKL_Complex16 *zp; +// mxArray *X; + +// X = mxCreateDoubleMatrix(m,n,mxCOMPLEX); +// xr = mxGetPr(X); +// xi = mxGetPi(X); +// zp = Z; +// incz = ldz-m; +// for (j = 0; j < n; j++) { +// for (i = 0; i < m; i++) { +// *xr++ = zp->real; +// *xi++ = zp->imag; +// zp++; +// } +// zp += incz; +// } +// return(X); +//} + +//plhs[3] = mkl2mat(fmat, n, nunstab, nunstab) + +/* + * Convert MKL complex storage to MATLAB real matrix ignoring imaginary part. + * + * X = mkl2mat(Z,ldz,m,n) + * + * copies MKL_Complex16 Z to X, producing a real mxArray + * with mxGetM(X) = m and mxGetN(X) = n. + */ + +//mxArray* mkl2mat_real(MKL_Complex16 *Z, int ldz, int m, int n) { +// int i, j, incz; +// double *xr; +// MKL_Complex16 *zp; +// mxArray *X; + +// X = mxCreateDoubleMatrix(m,n,mxREAL); +// xr = mxGetPr(X); +// zp = Z; +// incz = ldz-m; +// for (j = 0; j < n; j++) { +// for (i = 0; i < m; i++) { +// *xr++ = zp->real; +// zp++; +// } +// zp += incz; +// } +// return(X); +//} + +//void copy_eigenvalues(mxArray *gev, MKL_Complex16 *a, MKL_Complex16 *b, int n) { +// double *gevr = mxGetPr(gev), +// *gevi = mxGetPi(gev); +// int i; + +// for (i=0; i<n; i++, gevr++, gevi++, a+=n+1) { +// *gevr = a->real; +// *gevi = a->imag; +// } + +// for (i=0; i<n; i++, gevr++, gevi++, b+=n+1) { +// *gevr = b->real; +// *gevi = b->imag; +// } +//} + +static void copy_eigenvalues(TSdzmatrix *Gev_dzm, MKL_Complex16 *a, MKL_Complex16 *b) +{ + int n = Gev_dzm->real->nrows; + double *gevr = Gev_dzm->real->M, + *gevi = Gev_dzm->imag->M; + int i; + + for (i=0; i<n; i++, gevr++, gevi++, a+=n+1) { + *gevr = a->real; + *gevi = a->imag; + } + + for (i=0; i<n; i++, gevr++, gevi++, b+=n+1) { + *gevr = b->real; + *gevi = b->imag; + } +} + + +static int compute_svd(MKL_Complex16 *x, MKL_Complex16 **u, double **d, MKL_Complex16 **v, int m, int n) +{ + //$$$Memory allocated to u, d, and v will be destroyed outside this function.$$$ + int tmpi; + int md = m<n?m:n, lwork = -1, info = 0; + MKL_Complex16 *a, *work, work1; + double *rwork = tzMalloc(5*md>1?5*md:1, double); + + a = tzMalloc(m*n, MKL_Complex16); + cblas_zcopy(m*n, x, 1, a, 1); + + *u = tzMalloc(tmpi=m*md,MKL_Complex16); + InitializeConstantMLK_Complex16(*u, tmpi, 0.0); + *v = tzMalloc(tmpi=md*n, MKL_Complex16); + InitializeConstantMLK_Complex16(*v, tmpi, 0.0); + *d = tzMalloc(md, double); + InitializeConstantDouble(*d, md, 0.0); + + /* Query zgges on the value of lwork */ + zgesvd("S", "S", &m, &n, a, &m, *d, *u, &m, *v, &md, &work1, &lwork, rwork, &info); + + if (info < 0) { + printf("WARNING: Input %d to zgesvd had an illegal value",-info); + tzDestroy(rwork); + return(info); + } + + lwork = (int)(work1.real); + work = tzMalloc(lwork, MKL_Complex16); + zgesvd("S", "S", &m, &n, a, &m, *d, *u, &m, *v, &md, work, &lwork, rwork, &info); + + tzDestroy(work); + tzDestroy(rwork); + tzDestroy(a); + + if (info < 0) + printf("WARNING: Input %d to zgesvd had an illegal value",-info); + + if (info > 0) + printf("WARNING: ZBDSQR did not converge.\n%d superdiagonals of an intermediate " + "bidiagonal form B did not converge to zero.",info); + return(info); +} + +static int compute_norm(MKL_Complex16 *a, double **d, int m, int n) +{ + //Memory will be allocated to d, which will be destroyed outside this function. + int md = m<n?m:n, lwork = -1, info = 0; + MKL_Complex16 *work = NULL, work1; + double *rwork = tzMalloc(5*md>1?5*md:1, double); + + *d = tzMalloc(md, double); + + /* Query zgges on the value of lwork */ + zgesvd("N", "N", &m, &n, a, &m, *d, NULL, &m, NULL, &md, &work1, &lwork, rwork, &info); + + if (info < 0) { + printf("WARNING: Input %d to zgesvd had an illegal value",-info); + tzDestroy(rwork); + return(info); + } + + lwork = (int)(work1.real); + work = tzMalloc(lwork, MKL_Complex16); + zgesvd("N", "N", &m, &n, a, &m, *d, NULL, &m, NULL, &md, work, &lwork, rwork, &info); + + tzDestroy(work); + tzDestroy(rwork); + + if (info < 0) + printf("WARNING: Input %d to zgesvd had an illegal value",-info); + + if (info > 0) + printf("WARNING: ZBDSQR() in Intel MKL did not converge.\n%d superdiagonals of an intermediate " + "bidiagonal form B did not converge to zero.",info); + + return(info); +} + + +//======= 03/01/06 TZ. Commented out to be consistent with the CAS 3/10/04 correction. =======// +//static int compute_normx(MKL_Complex16 *a, MKL_Complex16 *b, MKL_Complex16 *zwt, MKL_Complex16 *ueta, double **normx, int nunstab, int psin, int n, int bigev) +//{ +// //Memory is allocated to normx, which will be freed outside this function. +// int tmpi; +// int info = 0, i, bigevs; +// // +// MKL_Complex16 *M = NULL, *zwtx = NULL, *ux = NULL, *vx = NULL, *tmp = NULL; +// double *dx = NULL; + + +// a += (n+1)*(n-nunstab); +// b += (n+1)*(n-nunstab); +// cblas_ztrsm(CblasColMajor, CblasLeft, CblasUpper, CblasNoTrans, CblasNonUnit, +// nunstab, psin, &one, b, n, zwt, nunstab); +// M = tzMalloc(nunstab*nunstab, MKL_Complex16); +// cblas_zdupe(nunstab, nunstab, a, n, M, nunstab); +// cblas_ztrsm(CblasColMajor, CblasLeft, CblasUpper, CblasNoTrans, CblasNonUnit, +// nunstab, nunstab, &one, b, n, M, nunstab); + +// zwtx = tzMalloc(nunstab*nunstab*psin, MKL_Complex16); +// cblas_zcopy(nunstab*psin, zwt, 1, zwtx, 1); +// for (i=1; i<nunstab; i++) { +// cblas_ztrmm(CblasColMajor, CblasLeft, CblasUpper, CblasNoTrans, CblasNonUnit, nunstab, psin*i, &one, M, nunstab, zwtx, nunstab); +// cblas_zcopy(nunstab*psin, zwt, 1, zwtx+nunstab*psin*i, 1); +// } +// tzDestroy(M); +// cblas_ztrmm(CblasColMajor, CblasLeft, CblasUpper, CblasNoTrans, CblasNonUnit, nunstab, nunstab*psin, &one, b, n, zwtx, nunstab); +// info = compute_svd(zwtx, &ux, &dx, &vx, nunstab, nunstab*psin); //Memory is allocated to ux, dx, and vx. +// tzDestroy(vx); +// tzDestroy(zwtx); +// if (info) { +// printf("WARNING: SVD failed.\n"); +// tzDestroy(ux); +// tzDestroy(dx); +// return(info); +// } +// bigevs = nunstab; +// for (i=0; i<nunstab; i++) +// if (dx[i]<=REALSMALL) { +// bigevs = i; +// break; +// } +// tzDestroy(dx); +// /* ux-ueta*ueta'*ux */ +// tmp = tzMalloc(tmpi=nunstab*nunstab, MKL_Complex16); +// InitializeConstantMLK_Complex16(tmp, tmpi, 0.0); //Must be initialized to 0.0 in order to have legal values of this pointer. +// cblas_zgemm(CblasColMajor, CblasNoTrans, CblasConjTrans, nunstab, nunstab, +// bigev, &one, ueta, nunstab, ueta, nunstab, &zero, tmp, nunstab); +// cblas_zhemm(CblasColMajor, CblasLeft, CblasUpper, nunstab, +// bigevs, &minusone, tmp, nunstab, ux, nunstab, &one, ux, nunstab); +// tzDestroy(tmp); +// info = compute_norm(ux, normx, nunstab, bigevs); //Memory is allocated to normx. +// if (info) { +// printf("WARNING: SVD failed.\n"); +// tzDestroy(normx); +// tzDestroy(ux); +// return(info); +// } +// tzDestroy(ux); +// return(info); +//} + +static void cblas_zdupe(int m, int n, MKL_Complex16 *a, int lda, MKL_Complex16 *b, int ldb) +{ + //Copying from a to b. + int i; + for (i=0; i<m; i++, a++, b++) + cblas_zcopy(n, a, lda, b, ldb); +} + +static void cblas_zdscali(int n, double *a, int lda, MKL_Complex16 *b, int ldb) +{ + int i; + for (i=0; i<lda; i++, a++, b++) + cblas_zdscal(n, 1.0/(*a), b, ldb); +} + +static void cblas_zdscale(int n, double *a, int lda, MKL_Complex16 *b, int ldb) +{ + int i; + for (i=0; i<lda; i++, a++, b++) + cblas_zdscal(n, *a, b, ldb); +} + +static void cblas_zdpsb(int m, int n, MKL_Complex16 *a, int lda, MKL_Complex16 *b, int ldb, MKL_Complex16 *c, int ldc) +{ + int i; + cblas_zdupe(m, n, a, lda, c, ldc); + for (i=0; i<m; i++, b++, c++) + cblas_zaxpy(n, &minusone, b, ldb, c, ldc); +} + + +static MKL_Complex16* CreateComplexMatrix5RealMatrix(TSdmatrix *X_dm) +{ + int mn, k; + double *M; + // + MKL_Complex16 *Z = NULL; + + if (!X_dm) fn_DisplayError("CreateComplexMatrix5RealMatrix(): Input matrix X_dm must be allocated memory"); + M = X_dm->M; + + Z = tzMalloc(mn=X_dm->nrows*X_dm->ncols, MKL_Complex16); + for (k=mn-1; k>=0; k--) { + Z[k].real = M[k]; + Z[k].imag = 0.0; + } + return(Z); +} + +static MKL_Complex16* CreateComplexMatrix5RealVector(TSdvector *x_dv) +{ + int n, k; + double *v; + // + MKL_Complex16 *Z = NULL; + + if (!x_dv) fn_DisplayError("CreateComplexMatrix5RealVector(): Input vector x_dv must be allocated memory"); + v = x_dv->v; + + Z = tzMalloc(n=x_dv->n, MKL_Complex16); + for (k=n-1; k>=0; k--) { + Z[k].real = v[k]; + Z[k].imag = 0.0; + } + return(Z); +} + + +static void ComplexMatrix2RealMatrix(TSdmatrix *Y_dm, MKL_Complex16 *Z) +{ + int _k; + double *M; + + if (!Y_dm) fn_DisplayError("ComplexMatrix2RealMatrix(): Output matrix Y_dm must be allocated memory"); + M = Y_dm->M; + + for (_k=Y_dm->nrows*Y_dm->ncols-1; _k>=0; _k--) M[_k] = Z[_k].real; + Y_dm->flag = M_GE; +} + + +static void ComplexMatrix2RealVector(TSdvector *y_dv, MKL_Complex16 *Z) +{ + int _k; + double *v; + + if (!y_dv) fn_DisplayError("ComplexMatrix2RealVector(): Output matrix y_dv must be allocated memory"); + v = y_dv->v; + + for (_k=y_dv->n-1; _k>=0; _k--) v[_k] = Z[_k].real; + y_dv->flag = V_DEF; +} + + +static TSdzmatrix *SubComplexMatrix2Zmatrix(TSdzmatrix *X_dzm, MKL_Complex16 *Z, const int nrowsforZ, const int _m, const int _n) +{ + //X_dzm is _m-by_n comlex types where nrowsforZ <= _m and Z is nrowsforZ-by-_n. + int _i, _j, incz; + double *Mreal, *Mimag; + MKL_Complex16 *zp; + // + TSdzmatrix *Y_dzm = NULL; + + if (!X_dzm || X_dzm->real->nrows != _m || X_dzm->real->ncols != _n) { + DestroyMatrix_dz(X_dzm); //Destroys Y_dzm if already allocated memory to accommodate a possbible change of its dimension. + Y_dzm = CreateMatrix_dz(_m, _n); + } + else Y_dzm = X_dzm; + + Mreal = Y_dzm->real->M; + Mimag = Y_dzm->imag->M; + zp = Z; + if ((incz=nrowsforZ-_m)<0) fn_DisplayError("SubComplexMatrix2ZMatrix(): Number of rows for the input complex matrix Z must be greater that of the output Z matrix Y_dzm"); + + for (_j=0; _j<_n; _j++) { + for (_i=0; _i<_m; _i++) { + *Mreal++ = zp->real; + *Mimag++ = zp->imag; + zp++; + } + zp += incz; + } + return (Y_dzm); +} + + +static void InitializeConstantMLK_Complex16(MKL_Complex16 *x_clx, const int _n, const double c) +{ + int _i; + + for (_i=_n-1; _i>=0; _i--) + x_clx[_i].real = x_clx[_i].imag = c; +} + +static void InitializeConstantDouble(double *x_p, const int _n, const double c) +{ + int _i; + + for (_i=_n-1; _i>=0; _i--) x_p[_i] = c; +} + +static void ConverteZeroSquareMatrix2RealDiagonalMLK_Complex16(MKL_Complex16 *x_pc, const int _n, const double c) +{ + //Written by TZ, 03/08/06. + //Output: + // x_pc: _n-by-_n, with the diagonal + //Inputs: + // _n: dimension of x_pc so that x_pc is _n-by-_n. + // x_pc: _n-by-_n, all initialized to zeros. + int _i; + int np1 = _n+1; + + for (_i=_n*_n-1; _i>=0; _i -= np1) + x_pc[_i].real = x_pc[_i].imag = c; +} + diff --git a/CFiles/gensys.h b/CFiles/gensys.h new file mode 100755 index 0000000..ea1e2ac --- /dev/null +++ b/CFiles/gensys.h @@ -0,0 +1,67 @@ +/******************************************************************* + * [G1,C,impact,fmat,fwt,ywt,gev,eu]=gensys(g0,g1,c,psi,pi,div) + * + * System given as + * g0*y(t)=g1*y(t-1)+c+psi*z(t)+pi*eta(t), + * with z an exogenous variable process and eta being endogenously determined + * one-step-ahead expectational errors. Returned system is + * y(t)=G1*y(t-1)+C+impact*z(t)+ywt*inv(I-fmat*inv(L))*fwt*z(t+1) . + * If z(t) is i.i.d., the last term drops out. + * If div or stake is omitted from argument list, a div>1 or stake>1 is calculated. + * eu(1)=1 for existence, eu(2)=1 for uniqueness. eu(1)=-1 for + * existence only with not-serially correlated z(t); eu=[-2,-2] for coincident zeros. + * + * g0, g1: n-by-n matrices. + * c: n-by-1 constant terms. + * z(t): m-by-1 vector of exogenous residuals where m < n. + * psi: n-by-m matrix. + * eta(t): h-by-1 vector of expectational (endogenous) errors. + * pi: n-by-h matrix. + * div: a real number dividing stable and unstable roots.. If < 1.0, a div>1.0 is calculated mechanically. + *------- + * G1 or Theta_dm: n-by-n matrices. + * C: n-by-1 vector of constant terms. + * impact: n-by-m matrix. + * gev: n-by-2 z vector of stacked generalized eigenvalues where gev(;,2) ./ gev(:,1) = eig(g0, g1). + * ywt: n-by-nunstab z matrix of possible complex numbers. Initialized to NULL and dynamically allocated. + * fmat: nunstab-by-nunstab z matrix where nunstab is the number of non-stable roots. + * fwt: nunstab-by-m z matrix. +********************************************************************/ + +#ifndef __GENSYS_H__ + #define __GENSYS_H__ + + #include "tzmatlab.h" + //#include "fn_filesetup.h" //For DDDDebugging purpose. + + #define REALSMALL 1e-7 + //#define PRINTWARNINGofSUNSPOT + + typedef struct TSgensys_tag { + //=== Output arguments. + TSdmatrix *Theta_dm; //n-by-n. + TSdvector *c_dv; //n-by-1. + TSdmatrix *Impact_dm; //n-by-m. + TSdzmatrix *Fmat_dzm; //nunstab-by-nunstab z matrix. Initialized to NULL and will be dynamically allocated whenever gensys() is called. + TSdzmatrix *Fwt_dzm; //nunstab-by-m z matrix of possible complex numbers. Initialized to NULL and dynamically allocated. + TSdzmatrix *Ywt_dzm; //n-by-nunstab z matrix of possible complex numbers. Initialized to NULL and dynamically allocated. + TSdzmatrix *Gev_dzm; //n-by-2 z matrix of possible complex numbers. + TSivector *eu_iv; //2-by-1. + //=== Function itself. + void (*gensys)(struct TSgensys_tag *, void *); + //=== Input arguments, which are all intialized to 0.0 and whose flags are set to M_GE. + TSdmatrix *G0_dm; //n-by-n. + TSdmatrix *G1_dm; //n-by-n. + TSdvector *c0_dv; //n-by-1. + TSdmatrix *Psi_dm; //n-by-m. + TSdmatrix *Pi_dm; //n-by-k whtere k is the number of expectational errors. + double div; //Real number dividing stable and unstable roots.. If < 1.0, a div>1.0 is calculated mechanically. + } TSgensys; + // + typedef int TFlinratexp(struct TSgensys_tag *, void *); //For linear rational expectations models. + + struct TSgensys_tag *CreateTSgensys(TFlinratexp *func, const int _n, const int _m, const int _k, const double div); + struct TSgensys_tag *DestroyTSgensys(struct TSgensys_tag *gensys_ps); + int gensys_sims(struct TSgensys_tag *gensys_ps, void *dummy_ps); +#endif + diff --git a/CFiles/gensys01Mar06Works.c b/CFiles/gensys01Mar06Works.c new file mode 100755 index 0000000..d185626 --- /dev/null +++ b/CFiles/gensys01Mar06Works.c @@ -0,0 +1,1114 @@ +/******************************************************************* + * [G1,C,impact,fmat,fwt,ywt,gev,eu]=gensys(g0,g1,c,psi,pi,div) + * + * System given as + * g0*y(t)=g1*y(t-1)+c+psi*z(t)+pi*eta(t), + * with z an exogenous variable process and eta being endogenously determined + * one-step-ahead expectational errors. Returned system is + * y(t)=G1*y(t-1)+C+impact*z(t)+ywt*inv(I-fmat*inv(L))*fwt*z(t+1) . + * If z(t) is i.i.d., the last term drops out. + * If div or stake is omitted from argument list, a div>1 or stake>1 is calculated. + * eu(1)=1 for existence, eu(2)=1 for uniqueness. eu(1)=-1 for + * existence only with not-serially correlated z(t); eu=[-2,-2] for coincident zeros. + * + * g0, g1: n-by-n matrices. + * c: n-by-1 constant terms. + * z(t): m-by-1 vector of exogenous residuals where m < n. + * psi: n-by-m matrix. + * eta(t): h-by-1 vector of expectational (endogenous) errors. + * pi: n-by-h matrix. + * div: a real number dividing stable and unstable roots.. If < 1.0, a div>1.0 is calculated mechanically. + *------- + * G1 or Theta_dm: n-by-n matrices. + * C: n-by-1 vector of constant terms. + * impact: n-by-m matrix. + * gev: n-by-2 z vector of stacked generalized eigenvalues where gev(;,2) ./ gev(:,1) = eig(g0, g1). + * ywt: n-by-nunstab z matrix of possible complex numbers. Initialized to NULL and dynamically allocated. + * fmat: nunstab-by-nunstab z matrix where nunstab is the number of non-stable roots. + * fwt: nunstab-by-m z matrix. + * + * 1996 MATLAB algorithm by Christopher Sims + * 2002 Mex implementation by Iskander Karibzhanov + * 2004 Modified to C function by Tao Zha (April) + * + * Note: Iskander is transforming g0 and g1 to complex matrices and uses zgges() as a qz decomposition. + * This is really wasting efficiency. One should keep g0 and g1 as real matrices and use + * dgges() as a qz decomposition. I don't have time to overhaul this at this point. 04/20/04, T. Zha. + * Note: 02/22/06. I take the above note back. According to DW, it is easy to order the + * the generalized eigenvalues by using the complex g0 and g1. In principle, one could + * order the roots using the real qz decomposition on real matrices g0 and g1. But so far + * Dan has found it a pain to do it. Perhaps we should read the MKL Lapack manual more + * carefully at a later point. +********************************************************************/ + +#include "gensys.h" + + +//----- NOTE: We can't replace MKL_Complex16 with a different name because the Intel Lapack uses MKL_Complex16. +//----- The only way to do this is to overhaul the code and put a wrapper function on each Intel Lapack function. +static int selctg(MKL_Complex16 *alpha, MKL_Complex16 *beta); +static int qz(MKL_Complex16 *a, MKL_Complex16 *b, MKL_Complex16 *q, MKL_Complex16 *z, int n); +static MKL_Complex16* CreateComplexMatrix5RealMatrix(TSdmatrix *X_dm); +static MKL_Complex16* CreateComplexMatrix5RealVector(TSdvector *x_dv); +static void ComplexMatrix2RealMatrix(TSdmatrix *Y_dm, MKL_Complex16 *Z); +static void ComplexMatrix2RealVector(TSdvector *y_dv, MKL_Complex16 *Z); +static TSdzmatrix *SubComplexMatrix2Zmatrix(TSdzmatrix *X_dzm, MKL_Complex16 *Z, const int nrowsforZ, const int _m, const int _n); +static void copy_eigenvalues(TSdzmatrix *Gev_dzm, MKL_Complex16 *a, MKL_Complex16 *b); +static int compute_svd(MKL_Complex16 *a, MKL_Complex16 **u, double **d, MKL_Complex16 **v, int m, int n); +static int compute_norm(MKL_Complex16 *a, double **d, int m, int n); +// +static int compute_normx(MKL_Complex16 *a, MKL_Complex16 *b, MKL_Complex16 *zwt, MKL_Complex16 *ueta, double **normx, int nunstab, int psin, int n, int bigev); +static void cblas_zdupe(int m, int n, MKL_Complex16 *a, int lda, MKL_Complex16 *b, int ldb); +static void cblas_zdscali(int n, double *a, int lda, MKL_Complex16 *b, int ldb); +static void cblas_zdscale(int n, double *a, int lda, MKL_Complex16 *b, int ldb); +static void cblas_zdpsb(int m, int n, MKL_Complex16 *a, int lda, MKL_Complex16 *b, int ldb, MKL_Complex16 *c, int ldc); +// +static void InitializeConstantMLK_Complex16(MKL_Complex16 *x_clx, const int _n, const double c); +static void InitializeConstantDouble(double *x_p, const int _n, const double c); + + + +TSgensys *CreateTSgensys(TFlinratexp *func, const int _n, const int _m, const int _k, const double div) +{ + //_n is the number of stacked variables (endogenous, Lagurangian multiplier, expected multiplier, etc.). + //_m is the number of exogenous shocks. + //_k is the number of expectational errors. + //div is the dividing number to determine what constitutes an unstable root. If div<1.0, a div>1.0 is calculated mechanically. + TSgensys *gensys_ps = tzMalloc(1, TSgensys); + + //=== Output arguments. + gensys_ps->Theta_dm = CreateMatrix_lf(_n, _n); //n-by-n. + gensys_ps->c_dv = CreateVector_lf(_n); //n-by-1. + gensys_ps->Impact_dm = CreateMatrix_lf(_n, _m); //n-by-m. + gensys_ps->Fmat_dzm = (TSdzmatrix *)NULL; //nunstab-by-nunstab z matrix. Initialized to NULL and will be dynamically allocated whenever gensys() is called. + gensys_ps->Fwt_dzm = (TSdzmatrix *)NULL; //nunstab-by-m z matrix of possible complex numbers. Initialized to NULL and dynamically allocated. + gensys_ps->Ywt_dzm = (TSdzmatrix *)NULL; //n-by-nunstab z matrix of possible complex numbers. Initialized to NULL and dynamically allocated. + gensys_ps->Gev_dzm = CreateMatrix_dz(_n, 2); //n-by-2 z matrix of possible complex numbers. + gensys_ps->eu_iv = CreateConstantVector_int(2, 0); //2-by-1. + + //=== Function itself. + gensys_ps->gensys = func; + + //=== Input arguments. + gensys_ps->G0_dm = CreateConstantMatrix_lf(_n, _n, 0.0); //n-by-n. + gensys_ps->G0_dm->flag = M_GE; + gensys_ps->G1_dm = CreateConstantMatrix_lf(_n, _n, 0.0); //n-by-n. + gensys_ps->G1_dm->flag = M_GE; + gensys_ps->c0_dv = CreateConstantVector_lf(_n, 0.0); //n-by-1. + gensys_ps->Psi_dm = CreateConstantMatrix_lf(_n, _m, 0.0); //n-by-m. + gensys_ps->Psi_dm->flag = M_GE; + gensys_ps->Pi_dm = CreateConstantMatrix_lf(_n, _k, 0.0); //n-by-k where k is the number of expectational errors. + gensys_ps->Pi_dm->flag = M_GE; + gensys_ps->div = div; + + return (gensys_ps); +} +//------- +TSgensys *DestroyTSgensys(TSgensys *gensys_ps) +{ + if (gensys_ps) { + //=== Output arguments. + DestroyMatrix_lf(gensys_ps->Theta_dm); //n-by-n. + DestroyVector_lf(gensys_ps->c_dv); //n-by-1. + DestroyMatrix_lf(gensys_ps->Impact_dm); //n-by-m. + DestroyMatrix_dz(gensys_ps->Fmat_dzm); //nunstab-by-nunstab z matrix. Initialized to NULL and will be dynamically allocated whenever gensys() is called. + DestroyMatrix_dz(gensys_ps->Fwt_dzm); //nunstab-by-m z matrix of possible complex numbers. Initialized to NULL and dynamically allocated. + DestroyMatrix_dz(gensys_ps->Ywt_dzm); //n-by-nunstab z matrix of possible complex numbers. Initialized to NULL and dynamically allocated. + DestroyMatrix_dz(gensys_ps->Gev_dzm); //n-by-2 z matrix of possible complex numbers. + DestroyVector_int(gensys_ps->eu_iv); //2-by-1. + + //=== Input arguments. + DestroyMatrix_lf(gensys_ps->G0_dm); //n-by-n. + DestroyMatrix_lf(gensys_ps->G1_dm); //n-by-n. + DestroyVector_lf(gensys_ps->c0_dv); //n-by-1. + DestroyMatrix_lf(gensys_ps->Psi_dm); //n-by-m. + DestroyMatrix_lf(gensys_ps->Pi_dm); //n-by-k where k is the number of expectational errors. + + free(gensys_ps); + + return ((TSgensys *)NULL); + } + else return (gensys_ps); +} + + +//--------------------------- For the function gensys_sims() ------------------------------------ +static int fixdiv = 1, zxz = 0; +static double stake = 1.01; +static int nunstab = 0; +static MKL_Complex16 one, minusone, zero; + +/* [G1,C,impact,fmat,fwt,ywt,gev,eu]=gensysmkl(g0,g1,c,psi,pi,stake) */ +//void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { +void gensys_sims(TSgensys *gensys_ps, void *dummy_ps) +{ + int tmpi; + int n, psin, pin, nsquare, md, mds, md1, i, bigev, bigevs, bigev1; + int *eu; + int exist = 0, existx = 0, unique = 0; + //=== Memory will be allocated to the following. + double *deta = NULL, *dz = NULL, *normx = NULL, *deta1 = NULL, *norm = NULL; + MKL_Complex16 *a = NULL, *b = NULL, *q = NULL, *z = NULL, *pi = NULL, *psi = NULL; + MKL_Complex16 *tmat = NULL, *g0 = NULL, *g1 = NULL, *dummy = NULL, *tmatq = NULL, *c = NULL, *impact = NULL, *ab = NULL; + MKL_Complex16 *fmat = NULL, *fwt = NULL, *ywt = NULL; + MKL_Complex16 *etawt = NULL, *ueta = NULL, *veta = NULL, *zwt = NULL, *uz = NULL, *vz = NULL, *etawt1 = NULL, *ueta1 = NULL, *veta1 = NULL; + +// /* Check for proper number of input and output arguments */ +// if (nrhs < 5 || nrhs > 6) +// mexErrMsgTxt("Five or six input arguments required.\n"); +// if (nlhs != 8) +// mexErrMsgTxt("Eight output arguments required.\n"); + +// /* Dimensions */ +// n = mxGetM(prhs[0]); +// psin = mxGetN(prhs[3]); +// pin = mxGetN(prhs[4]); + n = gensys_ps->G0_dm->nrows; + psin = gensys_ps->Psi_dm->ncols; + pin = gensys_ps->Pi_dm->ncols; + // + eu = gensys_ps->eu_iv->v; + //eu = mxGetPr(plhs[7]=mxCreateDoubleMatrix(2,1,mxREAL)); + +// /* Check for consistency of input matrix dimensions */ +// if (mxGetM(prhs[0])!=n || mxGetM(prhs[1])!=n) +// mexErrMsgTxt("g0 and g1 must be square matrices.\n"); + +// if (mxGetM(prhs[3])!=n || mxGetM(prhs[4])!=n) +// mexErrMsgTxt("psi and pi must have the same number of rows as g0.\n"); + +// eu = mxGetPr(plhs[7]=mxCreateDoubleMatrix(2,1,mxREAL)); + + //=== [a b q z]=qz(g0,g1); +// a = mat2mkl(prhs[0],n,n); +// b = mat2mkl(prhs[1],n,n); +// q = mxCalloc(n*n,sizeof(MKL_Complex16)); +// z = mxCalloc(n*n,sizeof(MKL_Complex16)); + a = CreateComplexMatrix5RealMatrix(gensys_ps->G0_dm); + b = CreateComplexMatrix5RealMatrix(gensys_ps->G1_dm); + q = tzMalloc(nsquare=square(n), MKL_Complex16); + z = tzMalloc(nsquare, MKL_Complex16); + InitializeConstantMLK_Complex16(q, nsquare, 0.0); + InitializeConstantMLK_Complex16(z, nsquare, 0.0); + +// fixdiv = nrhs != 6; +// stake = fixdiv ? 1.01 : mxGetScalar(prhs[5]); + fixdiv = (gensys_ps->div < 1.0); + stake = fixdiv ? 1.01 : gensys_ps->div; + nunstab = 0; + zxz = 0; + + if (qz(a, b, q, z, n)) { + printf("WARNING: QZ factorization failed.\n"); + tzDestroy(a); + tzDestroy(b); + tzDestroy(q); + tzDestroy(z); + return; + } + + nunstab /= 2; + + if (zxz) { + printf("WARNING: Coincident zeros. Indeterminacy and/or nonexistence.\n"); + eu[0] = eu[1] = -2; + tzDestroy(a); + tzDestroy(b); + tzDestroy(q); + tzDestroy(z); + return; + } + +// plhs[6] = mxCreateDoubleMatrix(n, 2, mxCOMPLEX); //For Gev_dzm. +// copy_eigenvalues(plhs[6], a, b, n); + copy_eigenvalues(gensys_ps->Gev_dzm, a, b); + + one.real = 1.0; + one.imag = 0.0; + + minusone.real = -1.0; + minusone.imag = 0.0; + + zero.real = 0.0; + zero.imag = 0.0; + +// pi = mat2mkl(prhs[4],n,pin); +// etawt = mxCalloc(nunstab*pin,sizeof(MKL_Complex16)); + pi = CreateComplexMatrix5RealMatrix(gensys_ps->Pi_dm); + etawt = tzMalloc(tmpi=nunstab*pin, MKL_Complex16); + InitializeConstantMLK_Complex16(etawt, tmpi, 0.0); //Must be initialized to 0.0 in order to have legal values of this pointer. + cblas_zgemm(CblasColMajor, CblasConjTrans, CblasNoTrans, nunstab, pin, n, + &one, q+n*(n-nunstab), n, pi, n, &zero, etawt, nunstab); + if (compute_svd(etawt, &ueta, &deta, &veta, nunstab, pin)) { + //Memory is now allocated to ueta, deta, and veta. + printf("WARNING: SVD failed.\n"); + tzDestroy(ueta); + tzDestroy(deta); + tzDestroy(veta); + tzDestroy(etawt); + tzDestroy(a); + tzDestroy(b); + tzDestroy(q); + tzDestroy(z); + return; + } + tzDestroy(etawt); + md = nunstab<pin?nunstab:pin; + bigev = md; + for (i=0; i<md; i++) + if (deta[i]<=REALSMALL) { + bigev=i; + break; + } + +// psi = mat2mkl(prhs[3],n,psin); +// zwt = mxCalloc(nunstab*psin,sizeof(MKL_Complex16)); + psi = CreateComplexMatrix5RealMatrix(gensys_ps->Psi_dm); + zwt = tzMalloc(tmpi=nunstab*psin, MKL_Complex16); + InitializeConstantMLK_Complex16(zwt, tmpi, 0.0); //Must be initialized to 0.0 in order to have legal values of this pointer. + cblas_zgemm(CblasColMajor, CblasConjTrans, CblasNoTrans, nunstab, psin, n, + &one, q+n*(n-nunstab), n, psi, n, &zero, zwt, nunstab); + if (compute_svd(zwt, &uz, &dz, &vz, nunstab, psin)) { + //Memory is now allocated to uz, dz, and vz. + printf("WARNING: SV decomposition failed.\n"); + tzDestroy(ueta); + tzDestroy(deta); + tzDestroy(veta); + tzDestroy(uz); + tzDestroy(dz); + tzDestroy(vz); + tzDestroy(zwt); + tzDestroy(a); + tzDestroy(b); + tzDestroy(q); + tzDestroy(z); + return; + } + tzDestroy(vz); + mds = nunstab<psin?nunstab:psin; + bigevs = mds; + for (i=0; i<mds; i++) + if (dz[i]<=REALSMALL) { + bigevs=i; + break; + } + tzDestroy(dz); + + + /* ueta = nunstab x bigev + deta = bigev x 1 + veta = bigev x pin, ldveta = md + uz = nunstab x bigevs + dz = bigevs x 1 + vz = bigevs x psin, ldvz = mds */ + + if (!bigevs) { + exist = 1; + existx = 1; + } else { + /* uz-ueta*ueta'*uz */ + MKL_Complex16 *tmp = tzMalloc(tmpi=nunstab*nunstab, MKL_Complex16); + InitializeConstantMLK_Complex16(tmp, tmpi, 0.0); //Must be initialized to 0.0 in order to have legal values of this pointer. + cblas_zgemm(CblasColMajor, CblasNoTrans, CblasConjTrans, nunstab, nunstab, + bigev, &one, ueta, nunstab, ueta, nunstab, &zero, tmp, nunstab); + cblas_zhemm(CblasColMajor, CblasLeft, CblasUpper, nunstab, + bigevs, &minusone, tmp, nunstab, uz, nunstab, &one, uz, nunstab); + tzDestroy(tmp); + if (compute_norm(uz, &norm, nunstab, bigevs)) { + //Memory is now allocated to norm. + printf("WARNING: SVD failed.\n"); + tzDestroy(norm); + tzDestroy(ueta); + tzDestroy(deta); + tzDestroy(veta); + tzDestroy(uz); + tzDestroy(zwt); + tzDestroy(a); + tzDestroy(b); + tzDestroy(q); + tzDestroy(z); + return; + } + exist = *norm < REALSMALL*n; + tzDestroy(norm); + if (compute_normx(a, b, zwt, ueta, &normx, nunstab, psin, n, bigev)) { + //If 0, memory is now allocated to normx; otherwise, normx is destroyed within the function compute_normx(). + tzDestroy(ueta); + tzDestroy(deta); + tzDestroy(veta); + tzDestroy(uz); + tzDestroy(zwt); + tzDestroy(a); + tzDestroy(b); + tzDestroy(q); + tzDestroy(z); + return; + } + existx = *normx < REALSMALL*n; + tzDestroy(normx); + } + + tzDestroy(uz); + tzDestroy(zwt); + + +/* Note that existence and uniqueness are not just matters of comparing + numbers of roots and numbers of endogenous errors. These counts are + reported below because usually they point to the source of the problem. */ + + etawt1 = tzMalloc(tmpi=(n-nunstab)*pin, MKL_Complex16); + InitializeConstantMLK_Complex16(etawt1, tmpi, 0.0); //Must be initialized to 0.0 in order to have legal values of this pointer. + cblas_zgemm(CblasColMajor, CblasConjTrans, CblasNoTrans, n-nunstab, pin, n, + &one, q, n, pi, n, &zero, etawt1, n-nunstab); + tzDestroy(pi); + if (compute_svd(etawt1, &ueta1, &deta1, &veta1, n-nunstab, pin)) { + //Memory is now allocated to ueta1, deta1, and veta1. + printf("WARNING: SVD failed for compute_svd().\n"); + tzDestroy(ueta1); + tzDestroy(deta1); + tzDestroy(veta1); + tzDestroy(etawt1); + tzDestroy(ueta); + tzDestroy(deta); + tzDestroy(veta); + tzDestroy(a); + tzDestroy(b); + tzDestroy(q); + tzDestroy(z); + return; + } + tzDestroy(etawt1); + md1 = n-nunstab<pin?n-nunstab:pin; + bigev1 = md1; + for (i=0; i<md1; i++) + if (deta1[i]<=REALSMALL) { + bigev1=i; + break; + } + /* ueta1 = n-nunstab x bigev1 + deta1 = bigev1 x 1 + veta1 = bigev1 x pin, ldveta1 = md1 */ + + if (existx || !nunstab) { + //=== Solution exists. + eu[0] = 1; + } else { + if (exist) { + printf("WARNING: Solution exists for unforecastable z only\n"); + eu[0] = -1; + } /* else + mexPrintf("No solution. %d unstable roots. %d endog errors.\n",nunstab,bigev1); */ + /* mexPrintf("Generalized eigenvalues\n"); + mexCallMATLAB(0,NULL,1, &plhs[6], "disp"); */ + } + if (!bigev1) + unique = 1; + else { + /* veta1-veta1*veta*veta' */ + /* veta = bigev x pin, ldveta1 = md + veta1 = bigev1 x pin, ldveta1 = md1 */ + MKL_Complex16 *tmp = tzMalloc(pin*pin, MKL_Complex16); + MKL_Complex16 *veta1_copy = tzMalloc(pin*bigev1, MKL_Complex16); + InitializeConstantMLK_Complex16(tmp, pin*pin, 0.0); //Must be initialized to 0.0 in order to have legal values of this pointer. + InitializeConstantMLK_Complex16(veta1_copy, pin*bigev1, 0.0); //Must be initialized to 0.0 in order to have legal values of this pointer. + cblas_zgemm(CblasColMajor, CblasConjTrans, CblasNoTrans, pin, pin, + bigev, &one, veta, md, veta, md, &zero, tmp, pin); + cblas_zdupe(bigev1,pin,veta1,md1,veta1_copy,bigev1); + cblas_zhemm(CblasColMajor, CblasRight, CblasUpper, bigev1, pin, + &minusone, tmp, pin, veta1_copy, bigev1, &one, veta1_copy, bigev1); + tzDestroy(tmp); + if (compute_norm(veta1_copy, &norm, bigev1, pin)) { + //Memory is now allocated to norm. + printf("WARNING: SVD failed.\n"); + tzDestroy(norm); + tzDestroy(ueta1); + tzDestroy(deta1); + tzDestroy(veta1); + tzDestroy(ueta); + tzDestroy(deta); + tzDestroy(veta); + tzDestroy(veta1_copy); + tzDestroy(a); + tzDestroy(b); + tzDestroy(q); + tzDestroy(z); + return; + } + tzDestroy(veta1_copy); + unique = *norm < REALSMALL*n; + tzDestroy(norm); + } + if (unique) { + //=== Unique solution. + eu[1] = 1; + } else { + eu[1] = 0; + printf("WARNING: Indeterminacy. %d loose endog errors with eu being [%d, %d].\n",bigev1-bigev, eu[0], eu[1]); + //printf("WARNING: Indeterminacy. %d loose endog errors with eu being [%g, %g].\n",bigev1-bigev, gensys_ps->eu_dv->v[0], gensys_ps->eu_dv->v[1]); + //printf("WARNING: Indeterminacy. %d loose endog errors.\n",bigev1-bigev); + /* mexPrintf("Generalized eigenvalues\n"); + mexCallMATLAB(0,NULL,1, &plhs[6], "disp"); */ + } + + cblas_zdscali(pin,deta,bigev,veta,md); /* veta' = deta\veta' */ + tzDestroy(deta); + cblas_zdscale(pin,deta1,bigev1,veta1,md1); /* veta1' = deta1*veta1' */ + tzDestroy(deta1); + etawt = tzMalloc(tmpi=nunstab*pin, MKL_Complex16); /* etawt = ueta*veta' */ + InitializeConstantMLK_Complex16(etawt, tmpi, 0.0); //Must be initialized to 0.0 in order to have legal values of this pointer. + cblas_zgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, nunstab, pin, bigev, + &one, ueta, nunstab, veta, md, &zero, etawt, nunstab); + tzDestroy(ueta); + tzDestroy(veta); + etawt1 = tzMalloc(tmpi=(n-nunstab)*pin, MKL_Complex16); /* etawt1 = ueta1*veta1' */ + InitializeConstantMLK_Complex16(etawt1, tmpi, 0.0); //Must be initialized to 0.0 in order to have legal values of this pointer. + cblas_zgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, n-nunstab, pin, bigev1, + &one, ueta1, n-nunstab, veta1, md1, &zero, etawt1, n-nunstab); + tzDestroy(ueta1); + tzDestroy(veta1); + tmat = tzMalloc(tmpi=(n-nunstab)*nunstab, MKL_Complex16); /* tmat = etawt1*etawt' */ + InitializeConstantMLK_Complex16(tmat, tmpi, 0.0); //Must be initialized to 0.0 in order to have legal values of this pointer. + cblas_zgemm(CblasColMajor, CblasNoTrans, CblasConjTrans, n-nunstab, nunstab, pin, + &one, etawt1, n-nunstab, etawt, nunstab, &zero, tmat, n-nunstab); + tzDestroy(etawt1); + tzDestroy(etawt); + + g0 = tzMalloc(tmpi=n*n, MKL_Complex16); + InitializeConstantMLK_Complex16(g0, tmpi, 0.0); //Must be initialized to 0.0 in order to have legal values of this pointer. + cblas_zdupe(n-nunstab, n, a, n, g0, n); + cblas_zgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, n-nunstab, nunstab, nunstab, + &minusone, tmat, n-nunstab, a+(n-nunstab)*(n+1), n, &one, g0+(n-nunstab)*n, n); + cblas_zcopy(nunstab, &one, 0, g0+(n-nunstab)*(n+1), n+1); + + g1 = tzMalloc(tmpi=n*n, MKL_Complex16); + InitializeConstantMLK_Complex16(g1, tmpi, 0.0); //Must be initialized to 0.0 in order to have legal values of this pointer. + cblas_zdupe(n-nunstab, n, b, n, g1, n); + cblas_zgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, n-nunstab, nunstab, nunstab, + &minusone, tmat, n-nunstab, b+(n-nunstab)*(n+1), n, &one, g1+(n-nunstab)*n, n); + cblas_ztrsm(CblasColMajor, CblasLeft, CblasUpper, CblasNoTrans, CblasNonUnit, + n, n, &one, g0, n, g1, n); + dummy = tzMalloc(tmpi=n*n, MKL_Complex16); + InitializeConstantMLK_Complex16(dummy, tmpi, 0.0); //Must be initialized to 0.0 in order to have legal values of this pointer. + cblas_zgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, n, n, n, &one, z, n, g1, n, &zero, dummy, n); + cblas_zgemm(CblasColMajor, CblasNoTrans, CblasConjTrans, n, n, n, &one, dummy, n, z, n, &zero, g1, n); + tzDestroy(dummy); + //plhs[0] = mkl2mat_real(g1, n, n, n); + ComplexMatrix2RealMatrix(gensys_ps->Theta_dm, g1); //Output. + tzDestroy(g1); + + tmatq = tzMalloc(tmpi=n*n, MKL_Complex16); + InitializeConstantMLK_Complex16(tmatq, tmpi, 0.0); //Must be initialized to 0.0 in order to have legal values of this pointer. + cblas_zcopy(n*n, q, 1, tmatq, 1); + cblas_zgemm(CblasColMajor, CblasNoTrans, CblasConjTrans, n, n-nunstab, nunstab, + &minusone, tmatq+(n-nunstab)*n, n, tmat, n-nunstab, &one, tmatq, n); + tzDestroy(tmat); + + ab = tzMalloc(tmpi=nunstab*nunstab, MKL_Complex16); + InitializeConstantMLK_Complex16(ab, tmpi, 0.0); //Must be initialized to 0.0 in order to have legal values of this pointer. + cblas_zdpsb(nunstab, nunstab, a+(n-nunstab)*(n+1), n, b+(n-nunstab)*(n+1), n, ab, nunstab); + cblas_ztrsm(CblasColMajor, CblasRight, CblasUpper, CblasConjTrans, CblasNonUnit, + n, nunstab, &one, ab, nunstab, tmatq+(n-nunstab)*n, n); + tzDestroy(ab); + + //c = mat2mkl(prhs[2],n,1); + c = CreateComplexMatrix5RealVector(gensys_ps->c0_dv); + dummy = tzMalloc(gensys_ps->c0_dv->n, MKL_Complex16); + //$$$$$$$ The following is Iskander's fatal code error. One cannot use c in the two different places; otherwise, it makes c be zero completely! + // cblas_zgemv(CblasColMajor, CblasConjTrans, n, n, &one, tmatq, n, c, 1, &zero, c, 1); + // cblas_ztrsv(CblasColMajor, CblasUpper, CblasNoTrans, CblasNonUnit, n, g0, n, c, 1); + // cblas_zgemv(CblasColMajor, CblasNoTrans, n, n, &one, z, n, c, 1, &zero, c, 1); + cblas_zgemv(CblasColMajor, CblasConjTrans, n, n, &one, tmatq, n, c, 1, &zero, dummy, 1); + cblas_ztrsv(CblasColMajor, CblasUpper, CblasNoTrans, CblasNonUnit, n, g0, n, dummy, 1); + cblas_zgemv(CblasColMajor, CblasNoTrans, n, n, &one, z, n, dummy, 1, &zero, c, 1); + //plhs[1] = mkl2mat_real(c, n, n, 1); + ComplexMatrix2RealVector(gensys_ps->c_dv, c); //Output. + tzDestroy(c); + tzDestroy(dummy); + + impact = tzMalloc(tmpi=n*psin, MKL_Complex16); + InitializeConstantMLK_Complex16(impact, tmpi, 0.0); //Must be initialized to 0.0 in order to have legal values of this pointer. + cblas_zgemm(CblasColMajor, CblasConjTrans, CblasNoTrans, n-nunstab, psin, n, + &one, tmatq, n, psi, n, &zero, impact, n); + tzDestroy(tmatq); + cblas_ztrsm(CblasColMajor, CblasLeft, CblasUpper, CblasNoTrans, CblasNonUnit, + n, psin, &one, g0, n, impact, n); + dummy = tzMalloc(tmpi=n*psin, MKL_Complex16); + InitializeConstantMLK_Complex16(dummy, tmpi, 0.0); //Must be initialized to 0.0 in order to have legal values of this pointer. + cblas_zgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, n, psin, n, + &one, z, n, impact, n, &zero, dummy, n); + tzDestroy(impact); + //plhs[2] = mkl2mat_real(dummy, n, n, psin); + ComplexMatrix2RealMatrix(gensys_ps->Impact_dm, dummy); //Output. + tzDestroy(dummy); + + fmat = a+(n-nunstab)*(n+1); + cblas_ztrsm(CblasColMajor, CblasLeft, CblasUpper, CblasNoTrans, CblasNonUnit, + nunstab, nunstab, &one, b+(n-nunstab)*(n+1), n, fmat, n); + //plhs[3] = mkl2mat(fmat, n, nunstab, nunstab); + gensys_ps->Fmat_dzm = SubComplexMatrix2Zmatrix(gensys_ps->Fmat_dzm, fmat, n, nunstab, nunstab); + tzDestroy(a); + + fwt = tzMalloc(tmpi=nunstab*psin, MKL_Complex16); + InitializeConstantMLK_Complex16(fwt, tmpi, 0.0); //Must be initialized to 0.0 in order to have legal values of this pointer. + cblas_ztrsm(CblasColMajor, CblasRight, CblasUpper, CblasConjTrans, CblasNonUnit, + n, nunstab, &one, b+(n-nunstab)*(n+1), n, q+(n-nunstab)*n, n); + tzDestroy(b); + cblas_zgemm(CblasColMajor, CblasConjTrans, CblasNoTrans, nunstab, psin, n, + &minusone, q+(n-nunstab)*n, n, psi, n, &zero, fwt, nunstab); + tzDestroy(q); + tzDestroy(psi); + //plhs[4] = mkl2mat(fwt, nunstab, nunstab, psin); + gensys_ps->Fwt_dzm = SubComplexMatrix2Zmatrix(gensys_ps->Fwt_dzm, fwt, nunstab, nunstab, psin); + tzDestroy(fwt); + + ywt = tzMalloc(tmpi=n*nunstab, MKL_Complex16); + InitializeConstantMLK_Complex16(ywt, tmpi, 0.0); + cblas_zcopy(nunstab, &one, 0, ywt+n-nunstab, n+1); + cblas_ztrsm(CblasColMajor, CblasLeft, CblasUpper, CblasNoTrans, CblasNonUnit, + n, nunstab, &one, g0, n, ywt, n); + tzDestroy(g0); + dummy = tzMalloc(tmpi=n*nunstab, MKL_Complex16); + InitializeConstantMLK_Complex16(dummy, tmpi, 0.0); //Must be initialized to 0.0 in order to have legal values of this pointer. + cblas_zgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, n, nunstab, n, + &one, z, n, ywt, n, &zero, dummy, n); + tzDestroy(z); + tzDestroy(ywt); + //plhs[5] = mkl2mat(dummy, n, n, nunstab); + gensys_ps->Ywt_dzm = SubComplexMatrix2Zmatrix(gensys_ps->Ywt_dzm, dummy, n, n, nunstab); + tzDestroy(dummy); +} + + +/****************************************************************************** + * function selctg orders the eigenvalues so that a selected cluster of * + * eigenvalues appears in the leading diagonal blocks of the upper * + * quasi-triangular matrix S and the upper triangular matrix T. * + ******************************************************************************/ + +static int selctg(MKL_Complex16 *alpha, MKL_Complex16 *beta) +{ + double absA = sqrt(alpha->real*alpha->real+alpha->imag*alpha->imag), + absB = fabs(beta->real); + if (absA) { + double divhat = absB/absA; + //bug detected by Vasco Curdia and Daria Finocchiaro, 2/25/2004 CAS. A root of + //exactly 1.01 and no root between 1 and 1.02, led to div being stuck at 1.01 + //and the 1.01 root being misclassified as stable. Changing < to <= below fixes this. + if (fixdiv && 1+REALSMALL<divhat && divhat<=stake) + stake = (1+divhat)/2; + } + if (absA<REALSMALL && absB<REALSMALL) + zxz = 1; + if (absB>stake*absA) { + nunstab++; + return(0); + } else + return(1); +} + +/****************************************************************************** + * compute for a pair of N-by-N complex nonsymmetric matrices (A,B), * + * the generalized eigenvalues, the generalized complex Schur form (S, T), * + * and optionally left and/or right Schur vectors (VSL and VSR) * + ******************************************************************************/ + +static int qz(MKL_Complex16 *a, MKL_Complex16 *b, MKL_Complex16 *q, MKL_Complex16 *z, int n) +{ +// unsigned char msg[101]; + int sdim, lwork = -1, info = 0; + MKL_Complex16 *alpha = tzMalloc(n,MKL_Complex16), + *beta = tzMalloc(n,MKL_Complex16), + *work, work1; + double *rwork = tzMalloc(8*n, double); + int *bwork = tzMalloc(4*n, int); + + /* Query zgges on the value of lwork */ + zgges("V", "V", "S", &selctg, &n, a, &n, b, &n, &sdim, alpha, beta, q, + &n, z, &n, &work1, &lwork, rwork, bwork, &info); + + if (info < 0) { + printf("WARNING: Input %d to the Intel MKL function zgges() has an illegal value",-info); + tzDestroy(bwork); + tzDestroy(rwork); + tzDestroy(alpha); + tzDestroy(beta); + return(info); + } + + lwork = (int)(work1.real); + work = tzMalloc(lwork, MKL_Complex16); + zgges("V", "V", "S", &selctg, &n, a, &n, b, &n, &sdim, alpha, beta, q, + &n, z, &n, work, &lwork, rwork, bwork, &info); + + tzDestroy(work); + tzDestroy(bwork); + tzDestroy(rwork); + tzDestroy(alpha); + tzDestroy(beta); + + if (info < 0) { + printf("WARNING: Input %d to the Intel MKL function zgges() has an illegal value",-info); + return(info); + } + + if (info > 0) + if (info < n) + printf("WARNING: The QZ iteration failed. (A,B) are not in Schur form,\n" + "but ALPHA(j) and BETA(j) should be correct for j=%d,...,N.",info+1); + else { + switch (info-n) { + case 1: + printf("WARNING: LAPACK problem: error return from ZGGBAL"); + break; + case 2: + printf("WARNING: LAPACK problem: error return from ZGEQRF"); + break; + case 3: + printf("WARNING: LAPACK problem: error return from ZUNMQR"); + break; + case 4: + printf("WARNING: LAPACK problem: error return from ZUNGQR"); + break; + case 5: + printf("WARNING: LAPACK problem: error return from ZGGHRD"); + break; + case 6: + printf("WARNING: LAPACK problem: error return from ZHGEQZ (other than failed iteration)"); + break; + case 7: + printf("WARNING: LAPACK problem: error return from ZGGBAK (computing VSL)"); + break; + case 8: + printf("WARNING: LAPACK problem: error return from ZGGBAK (computing VSR)"); + break; + case 9: + printf("WARNING: LAPACK problem: error return from ZLASCL (various places)"); + break; + default: + printf("WARNING: LAPACK problem: unknown error."); + break; + } + } + return(info); +} + +/* + * Convert MATLAB complex matrix to MKL complex storage. + * + * Z = mat2mkl(X,ldz,ndz) + * + * converts MATLAB's mxArray X to MKL_Complex16 Z(ldz,ndz). + * The parameters ldz and ndz determine the storage allocated for Z, + * while mxGetM(X) and mxGetN(X) determine the amount of data copied. + */ + +//MKL_Complex16* mat2mkl(const mxArray *X, int ldz, int ndz) { +// MKL_Complex16 *Z, *zp; +// int m, n, incz, cmplxflag; +// register int i, j; +// double *xr, *xi; + +// Z = mxCalloc(ldz*ndz, sizeof(MKL_Complex16)); +// xr = mxGetPr(X); +// xi = mxGetPi(X); +// m = mxGetM(X); +// n = mxGetN(X); +// zp = Z; +// incz = ldz-m; +// cmplxflag = (xi != NULL); +// for (j = 0; j < n; j++) { +// if (cmplxflag) { +// for (i = 0; i < m; i++) { +// zp->real = *xr++; +// zp->imag = *xi++; +// zp++; +// } +// } else { +// for (i = 0; i < m; i++) { +// zp->real = *xr++; +// zp++; +// } +// } +// zp += incz; +// } +// return(Z); +//} + + +/* + * Convert MKL complex storage to MATLAB real and imaginary parts. + * + * X = mkl2mat(Z,ldz,m,n) + * + * copies MKL_Complex16 Z to X, producing a complex mxArray + * with mxGetM(X) = m and mxGetN(X) = n. + */ + +//mxArray* mkl2mat(MKL_Complex16 *Z, int ldz, int m, int n) { +// int i, j, incz; +// double *xr, *xi; +// MKL_Complex16 *zp; +// mxArray *X; + +// X = mxCreateDoubleMatrix(m,n,mxCOMPLEX); +// xr = mxGetPr(X); +// xi = mxGetPi(X); +// zp = Z; +// incz = ldz-m; +// for (j = 0; j < n; j++) { +// for (i = 0; i < m; i++) { +// *xr++ = zp->real; +// *xi++ = zp->imag; +// zp++; +// } +// zp += incz; +// } +// return(X); +//} + +//plhs[3] = mkl2mat(fmat, n, nunstab, nunstab) + +/* + * Convert MKL complex storage to MATLAB real matrix ignoring imaginary part. + * + * X = mkl2mat(Z,ldz,m,n) + * + * copies MKL_Complex16 Z to X, producing a real mxArray + * with mxGetM(X) = m and mxGetN(X) = n. + */ + +//mxArray* mkl2mat_real(MKL_Complex16 *Z, int ldz, int m, int n) { +// int i, j, incz; +// double *xr; +// MKL_Complex16 *zp; +// mxArray *X; + +// X = mxCreateDoubleMatrix(m,n,mxREAL); +// xr = mxGetPr(X); +// zp = Z; +// incz = ldz-m; +// for (j = 0; j < n; j++) { +// for (i = 0; i < m; i++) { +// *xr++ = zp->real; +// zp++; +// } +// zp += incz; +// } +// return(X); +//} + +//void copy_eigenvalues(mxArray *gev, MKL_Complex16 *a, MKL_Complex16 *b, int n) { +// double *gevr = mxGetPr(gev), +// *gevi = mxGetPi(gev); +// int i; + +// for (i=0; i<n; i++, gevr++, gevi++, a+=n+1) { +// *gevr = a->real; +// *gevi = a->imag; +// } + +// for (i=0; i<n; i++, gevr++, gevi++, b+=n+1) { +// *gevr = b->real; +// *gevi = b->imag; +// } +//} + +static void copy_eigenvalues(TSdzmatrix *Gev_dzm, MKL_Complex16 *a, MKL_Complex16 *b) +{ + int n = Gev_dzm->real->nrows; + double *gevr = Gev_dzm->real->M, + *gevi = Gev_dzm->imag->M; + int i; + + for (i=0; i<n; i++, gevr++, gevi++, a+=n+1) { + *gevr = a->real; + *gevi = a->imag; + } + + for (i=0; i<n; i++, gevr++, gevi++, b+=n+1) { + *gevr = b->real; + *gevi = b->imag; + } +} + + +static int compute_svd(MKL_Complex16 *x, MKL_Complex16 **u, double **d, MKL_Complex16 **v, int m, int n) +{ + //$$$Memory allocated to u, d, and v will be destroyed outside this function.$$$ + int tmpi; + int md = m<n?m:n, lwork = -1, info = 0; + MKL_Complex16 *a, *work, work1; + double *rwork = tzMalloc(5*md>1?5*md:1, double); + + a = tzMalloc(m*n, MKL_Complex16); + cblas_zcopy(m*n, x, 1, a, 1); + + *u = tzMalloc(tmpi=m*md,MKL_Complex16); + InitializeConstantMLK_Complex16(*u, tmpi, 0.0); + *v = tzMalloc(tmpi=md*n, MKL_Complex16); + InitializeConstantMLK_Complex16(*v, tmpi, 0.0); + *d = tzMalloc(md, double); + InitializeConstantDouble(*d, md, 0.0); + + /* Query zgges on the value of lwork */ + zgesvd("S", "S", &m, &n, a, &m, *d, *u, &m, *v, &md, &work1, &lwork, rwork, &info); + + if (info < 0) { + printf("WARNING: Input %d to zgesvd had an illegal value",-info); + tzDestroy(rwork); + return(info); + } + + lwork = (int)(work1.real); + work = tzMalloc(lwork, MKL_Complex16); + zgesvd("S", "S", &m, &n, a, &m, *d, *u, &m, *v, &md, work, &lwork, rwork, &info); + + tzDestroy(work); + tzDestroy(rwork); + tzDestroy(a); + + if (info < 0) + printf("WARNING: Input %d to zgesvd had an illegal value",-info); + + if (info > 0) + printf("WARNING: ZBDSQR did not converge.\n%d superdiagonals of an intermediate " + "bidiagonal form B did not converge to zero.",info); + return(info); +} + +static int compute_norm(MKL_Complex16 *a, double **d, int m, int n) +{ + //Memory will be allocated to d, which will be destroyed outside this function. + int md = m<n?m:n, lwork = -1, info = 0; + MKL_Complex16 *work = NULL, work1; + double *rwork = tzMalloc(5*md>1?5*md:1, double); + + *d = tzMalloc(md, double); + + /* Query zgges on the value of lwork */ + zgesvd("N", "N", &m, &n, a, &m, *d, NULL, &m, NULL, &md, &work1, &lwork, rwork, &info); + + if (info < 0) { + printf("WARNING: Input %d to zgesvd had an illegal value",-info); + tzDestroy(rwork); + return(info); + } + + lwork = (int)(work1.real); + work = tzMalloc(lwork, MKL_Complex16); + zgesvd("N", "N", &m, &n, a, &m, *d, NULL, &m, NULL, &md, work, &lwork, rwork, &info); + + tzDestroy(work); + tzDestroy(rwork); + + if (info < 0) + printf("WARNING: Input %d to zgesvd had an illegal value",-info); + + if (info > 0) + printf("WARNING: ZBDSQR() in Intel MKL did not converge.\n%d superdiagonals of an intermediate " + "bidiagonal form B did not converge to zero.",info); + + return(info); +} + +static int compute_normx(MKL_Complex16 *a, MKL_Complex16 *b, MKL_Complex16 *zwt, MKL_Complex16 *ueta, double **normx, int nunstab, int psin, int n, int bigev) +{ + //Memory is allocated to normx, which will be freed outside this function. + int tmpi; + int info = 0, i, bigevs; + // + MKL_Complex16 *M = NULL, *zwtx = NULL, *ux = NULL, *vx = NULL, *tmp = NULL; + double *dx = NULL; + + + a += (n+1)*(n-nunstab); + b += (n+1)*(n-nunstab); + cblas_ztrsm(CblasColMajor, CblasLeft, CblasUpper, CblasNoTrans, CblasNonUnit, + nunstab, psin, &one, b, n, zwt, nunstab); + M = tzMalloc(nunstab*nunstab, MKL_Complex16); + cblas_zdupe(nunstab, nunstab, a, n, M, nunstab); + cblas_ztrsm(CblasColMajor, CblasLeft, CblasUpper, CblasNoTrans, CblasNonUnit, + nunstab, nunstab, &one, b, n, M, nunstab); + + zwtx = tzMalloc(nunstab*nunstab*psin, MKL_Complex16); + cblas_zcopy(nunstab*psin, zwt, 1, zwtx, 1); + for (i=1; i<nunstab; i++) { + cblas_ztrmm(CblasColMajor, CblasLeft, CblasUpper, CblasNoTrans, CblasNonUnit, nunstab, psin*i, &one, M, nunstab, zwtx, nunstab); + cblas_zcopy(nunstab*psin, zwt, 1, zwtx+nunstab*psin*i, 1); + } + tzDestroy(M); + cblas_ztrmm(CblasColMajor, CblasLeft, CblasUpper, CblasNoTrans, CblasNonUnit, nunstab, nunstab*psin, &one, b, n, zwtx, nunstab); + info = compute_svd(zwtx, &ux, &dx, &vx, nunstab, nunstab*psin); //Memory is allocated to ux, dx, and vx. + tzDestroy(vx); + tzDestroy(zwtx); + if (info) { + printf("WARNING: SVD failed.\n"); + tzDestroy(ux); + tzDestroy(dx); + return(info); + } + bigevs = nunstab; + for (i=0; i<nunstab; i++) + if (dx[i]<=REALSMALL) { + bigevs = i; + break; + } + tzDestroy(dx); + /* ux-ueta*ueta'*ux */ + tmp = tzMalloc(tmpi=nunstab*nunstab, MKL_Complex16); + InitializeConstantMLK_Complex16(tmp, tmpi, 0.0); //Must be initialized to 0.0 in order to have legal values of this pointer. + cblas_zgemm(CblasColMajor, CblasNoTrans, CblasConjTrans, nunstab, nunstab, + bigev, &one, ueta, nunstab, ueta, nunstab, &zero, tmp, nunstab); + cblas_zhemm(CblasColMajor, CblasLeft, CblasUpper, nunstab, + bigevs, &minusone, tmp, nunstab, ux, nunstab, &one, ux, nunstab); + tzDestroy(tmp); + info = compute_norm(ux, normx, nunstab, bigevs); //Memory is allocated to normx. + if (info) { + printf("WARNING: SVD failed.\n"); + tzDestroy(normx); + tzDestroy(ux); + return(info); + } + tzDestroy(ux); + return(info); +} + +static void cblas_zdupe(int m, int n, MKL_Complex16 *a, int lda, MKL_Complex16 *b, int ldb) +{ + int i; + for (i=0; i<m; i++, a++, b++) + cblas_zcopy(n, a, lda, b, ldb); +} + +static void cblas_zdscali(int n, double *a, int lda, MKL_Complex16 *b, int ldb) +{ + int i; + for (i=0; i<lda; i++, a++, b++) + cblas_zdscal(n, 1.0/(*a), b, ldb); +} + +static void cblas_zdscale(int n, double *a, int lda, MKL_Complex16 *b, int ldb) +{ + int i; + for (i=0; i<lda; i++, a++, b++) + cblas_zdscal(n, *a, b, ldb); +} + +static void cblas_zdpsb(int m, int n, MKL_Complex16 *a, int lda, MKL_Complex16 *b, int ldb, MKL_Complex16 *c, int ldc) +{ + int i; + cblas_zdupe(m, n, a, lda, c, ldc); + for (i=0; i<m; i++, b++, c++) + cblas_zaxpy(n, &minusone, b, ldb, c, ldc); +} + + +static MKL_Complex16* CreateComplexMatrix5RealMatrix(TSdmatrix *X_dm) +{ + int mn, k; + double *M; + // + MKL_Complex16 *Z = NULL; + + if (!X_dm) fn_DisplayError("CreateComplexMatrix5RealMatrix(): Input matrix X_dm must be allocated memory"); + M = X_dm->M; + + Z = tzMalloc(mn=X_dm->nrows*X_dm->ncols, MKL_Complex16); + for (k=mn-1; k>=0; k--) { + Z[k].real = M[k]; + Z[k].imag = 0.0; + } + return(Z); +} + +static MKL_Complex16* CreateComplexMatrix5RealVector(TSdvector *x_dv) +{ + int n, k; + double *v; + // + MKL_Complex16 *Z = NULL; + + if (!x_dv) fn_DisplayError("CreateComplexMatrix5RealVector(): Input vector x_dv must be allocated memory"); + v = x_dv->v; + + Z = tzMalloc(n=x_dv->n, MKL_Complex16); + for (k=n-1; k>=0; k--) { + Z[k].real = v[k]; + Z[k].imag = 0.0; + } + return(Z); +} + + +static void ComplexMatrix2RealMatrix(TSdmatrix *Y_dm, MKL_Complex16 *Z) +{ + int _k; + double *M; + + if (!Y_dm) fn_DisplayError("ComplexMatrix2RealMatrix(): Output matrix Y_dm must be allocated memory"); + M = Y_dm->M; + + for (_k=Y_dm->nrows*Y_dm->ncols-1; _k>=0; _k--) M[_k] = Z[_k].real; + Y_dm->flag = M_GE; +} + + +static void ComplexMatrix2RealVector(TSdvector *y_dv, MKL_Complex16 *Z) +{ + int _k; + double *v; + + if (!y_dv) fn_DisplayError("ComplexMatrix2RealVector(): Output matrix y_dv must be allocated memory"); + v = y_dv->v; + + for (_k=y_dv->n-1; _k>=0; _k--) v[_k] = Z[_k].real; + y_dv->flag = V_DEF; +} + + +static TSdzmatrix *SubComplexMatrix2Zmatrix(TSdzmatrix *X_dzm, MKL_Complex16 *Z, const int nrowsforZ, const int _m, const int _n) +{ + //X_dzm is _m-by_n comlex types where nrowsforZ <= _m and Z is nrowsforZ-by-_n. + int _i, _j, incz; + double *Mreal, *Mimag; + MKL_Complex16 *zp; + // + TSdzmatrix *Y_dzm = NULL; + + if (!X_dzm || X_dzm->real->nrows != _m || X_dzm->real->ncols != _n) { + DestroyMatrix_dz(X_dzm); //Destroys Y_dzm if already allocated memory to accommodate a possbible change of its dimension. + Y_dzm = CreateMatrix_dz(_m, _n); + } + else Y_dzm = X_dzm; + + Mreal = Y_dzm->real->M; + Mimag = Y_dzm->imag->M; + zp = Z; + if ((incz=nrowsforZ-_m)<0) fn_DisplayError("SubComplexMatrix2ZMatrix(): Number of rows for the input complex matrix Z must be greater that of the output Z matrix Y_dzm"); + + for (_j=0; _j<_n; _j++) { + for (_i=0; _i<_m; _i++) { + *Mreal++ = zp->real; + *Mimag++ = zp->imag; + zp++; + } + zp += incz; + } + return (Y_dzm); +} + + +static void InitializeConstantMLK_Complex16(MKL_Complex16 *x_clx, const int _n, const double c) +{ + int _i; + + for (_i=_n-1; _i>=0; _i--) + x_clx[_i].real = x_clx[_i].imag = c; +} + +static void InitializeConstantDouble(double *x_p, const int _n, const double c) +{ + int _i; + + for (_i=_n-1; _i>=0; _i--) x_p[_i] = c; +} diff --git a/CFiles/gensys01Mar06Works.h b/CFiles/gensys01Mar06Works.h new file mode 100755 index 0000000..e2a3477 --- /dev/null +++ b/CFiles/gensys01Mar06Works.h @@ -0,0 +1,65 @@ +/******************************************************************* + * [G1,C,impact,fmat,fwt,ywt,gev,eu]=gensys(g0,g1,c,psi,pi,div) + * + * System given as + * g0*y(t)=g1*y(t-1)+c+psi*z(t)+pi*eta(t), + * with z an exogenous variable process and eta being endogenously determined + * one-step-ahead expectational errors. Returned system is + * y(t)=G1*y(t-1)+C+impact*z(t)+ywt*inv(I-fmat*inv(L))*fwt*z(t+1) . + * If z(t) is i.i.d., the last term drops out. + * If div or stake is omitted from argument list, a div>1 or stake>1 is calculated. + * eu(1)=1 for existence, eu(2)=1 for uniqueness. eu(1)=-1 for + * existence only with not-serially correlated z(t); eu=[-2,-2] for coincident zeros. + * + * g0, g1: n-by-n matrices. + * c: n-by-1 constant terms. + * z(t): m-by-1 vector of exogenous residuals where m < n. + * psi: n-by-m matrix. + * eta(t): h-by-1 vector of expectational (endogenous) errors. + * pi: n-by-h matrix. + * div: a real number dividing stable and unstable roots.. If < 1.0, a div>1.0 is calculated mechanically. + *------- + * G1 or Theta_dm: n-by-n matrices. + * C: n-by-1 vector of constant terms. + * impact: n-by-m matrix. + * gev: n-by-2 z vector of stacked generalized eigenvalues where gev(;,2) ./ gev(:,1) = eig(g0, g1). + * ywt: n-by-nunstab z matrix of possible complex numbers. Initialized to NULL and dynamically allocated. + * fmat: nunstab-by-nunstab z matrix where nunstab is the number of non-stable roots. + * fwt: nunstab-by-m z matrix. +********************************************************************/ + +#ifndef __GENSYS_H__ + #define __GENSYS_H__ + + #include "tzmatlab.h" + + #define REALSMALL 1e-7 + + typedef struct TSgensys_tag { + //=== Output arguments. + TSdmatrix *Theta_dm; //n-by-n. + TSdvector *c_dv; //n-by-1. + TSdmatrix *Impact_dm; //n-by-m. + TSdzmatrix *Fmat_dzm; //nunstab-by-nunstab z matrix. Initialized to NULL and will be dynamically allocated whenever gensys() is called. + TSdzmatrix *Fwt_dzm; //nunstab-by-m z matrix of possible complex numbers. Initialized to NULL and dynamically allocated. + TSdzmatrix *Ywt_dzm; //n-by-nunstab z matrix of possible complex numbers. Initialized to NULL and dynamically allocated. + TSdzmatrix *Gev_dzm; //n-by-2 z matrix of possible complex numbers. + TSivector *eu_iv; //2-by-1. + //=== Function itself. + void (*gensys)(struct TSgensys_tag *, void *); + //=== Input arguments, which are all intialized to 0.0 and whose flags are set to M_GE. + TSdmatrix *G0_dm; //n-by-n. + TSdmatrix *G1_dm; //n-by-n. + TSdvector *c0_dv; //n-by-1. + TSdmatrix *Psi_dm; //n-by-m. + TSdmatrix *Pi_dm; //n-by-k whtere k is the number of expectational errors. + double div; //A real number dividing stable and unstable roots.. If < 1.0, a div>1.0 is calculated mechanically. + } TSgensys; + // + typedef void TFlinratexp(struct TSgensys_tag *, void *); //For linear rational expectations models. + + struct TSgensys_tag *CreateTSgensys(TFlinratexp *func, const int _n, const int _m, const int _k, const double div); + struct TSgensys_tag *DestroyTSgensys(struct TSgensys_tag *gensys_ps); + void gensys_sims(struct TSgensys_tag *gensys_ps, void *dummy_ps); +#endif + diff --git a/CFiles/gensys08Mar06.c b/CFiles/gensys08Mar06.c new file mode 100755 index 0000000..f51c7c6 --- /dev/null +++ b/CFiles/gensys08Mar06.c @@ -0,0 +1,1113 @@ +/******************************************************************* + * [G1,C,impact,fmat,fwt,ywt,gev,eu]=gensys(g0,g1,c,psi,pi,div) + * + * System given as + * g0*y(t)=g1*y(t-1)+c+psi*z(t)+pi*eta(t), + * with z an exogenous variable process and eta being endogenously determined + * one-step-ahead expectational errors. Returned system is + * y(t)=G1*y(t-1)+C+impact*z(t)+ywt*inv(I-fmat*inv(L))*fwt*z(t+1) . + * If z(t) is i.i.d., the last term drops out. + * If div or stake is omitted from argument list, a div>1 or stake>1 is calculated. + * eu(1)=1 for existence, eu(2)=1 for uniqueness. eu(1)=-1 for + * existence only with not-serially correlated z(t); eu=[-2,-2] for coincident zeros. + * + * g0, g1: n-by-n matrices. + * c: n-by-1 constant terms. + * z(t): m-by-1 vector of exogenous residuals where m < n. + * psi: n-by-m matrix. + * eta(t): h-by-1 vector of expectational (endogenous) errors. + * pi: n-by-h matrix. + * div: a real number dividing stable and unstable roots.. If < 1.0, a div>1.0 is calculated mechanically. + *------- + * G1 or Theta_dm: n-by-n matrices. + * C: n-by-1 vector of constant terms. + * impact: n-by-m matrix. + * gev: n-by-2 z vector of stacked generalized eigenvalues where gev(;,2) ./ gev(:,1) = eig(g0, g1). + * ywt: n-by-nunstab z matrix of possible complex numbers. Initialized to NULL and dynamically allocated. + * fmat: nunstab-by-nunstab z matrix where nunstab is the number of non-stable roots. + * fwt: nunstab-by-m z matrix. + * + * 1996 MATLAB algorithm by Christopher Sims + * 2002 Mex implementation by Iskander Karibzhanov + * 2004 Modified to C function by Tao Zha (April), correcting a few bugs of Iskander. + * 03/01/06 Another modification by Tao Zha, to be consistent with the CAS 3/10/04 correction. + * + * Note: Iskander is transforming g0 and g1 to complex matrices and uses zgges() as a qz decomposition. + * This is really wasting efficiency. One should keep g0 and g1 as real matrices and use + * dgges() as a qz decomposition. I don't have time to overhaul this at this point. 04/20/04, T. Zha. + * Note: 02/22/06. I take the above note back. According to DW, it is easy to *order* the + * the generalized eigenvalues by using the complex g0 and g1. In principle, one could + * order the roots using the real qz decomposition on real matrices g0 and g1. But so far + * Dan has found it a pain to do it. Perhaps we should read the MKL Lapack manual more + * carefully at a later point. +********************************************************************/ +#include "gensys.h" + + +//----- NOTE: We can't replace MKL_Complex16 with a different name because the Intel Lapack uses MKL_Complex16. +//----- The only way to do this is to overhaul the code and put a wrapper function on each Intel Lapack function. +static int selctg(MKL_Complex16 *alpha, MKL_Complex16 *beta); +static int qz(MKL_Complex16 *a, MKL_Complex16 *b, MKL_Complex16 *q, MKL_Complex16 *z, int n); +static MKL_Complex16* CreateComplexMatrix5RealMatrix(TSdmatrix *X_dm); +static MKL_Complex16* CreateComplexMatrix5RealVector(TSdvector *x_dv); +static void ComplexMatrix2RealMatrix(TSdmatrix *Y_dm, MKL_Complex16 *Z); +static void ComplexMatrix2RealVector(TSdvector *y_dv, MKL_Complex16 *Z); +static TSdzmatrix *SubComplexMatrix2Zmatrix(TSdzmatrix *X_dzm, MKL_Complex16 *Z, const int nrowsforZ, const int _m, const int _n); +static void copy_eigenvalues(TSdzmatrix *Gev_dzm, MKL_Complex16 *a, MKL_Complex16 *b); +static int compute_svd(MKL_Complex16 *a, MKL_Complex16 **u, double **d, MKL_Complex16 **v, int m, int n); +static int compute_norm(MKL_Complex16 *a, double **d, int m, int n); +//--- 03/01/06 TZ. Commented out to be consistent with the CAS 3/10/04 correction. +// static int compute_normx(MKL_Complex16 *a, MKL_Complex16 *b, MKL_Complex16 *zwt, MKL_Complex16 *ueta, double **normx, int nunstab, int psin, int n, int bigev); +static void cblas_zdupe(int m, int n, MKL_Complex16 *a, int lda, MKL_Complex16 *b, int ldb); +static void cblas_zdscali(int n, double *a, int lda, MKL_Complex16 *b, int ldb); +static void cblas_zdscale(int n, double *a, int lda, MKL_Complex16 *b, int ldb); +static void cblas_zdpsb(int m, int n, MKL_Complex16 *a, int lda, MKL_Complex16 *b, int ldb, MKL_Complex16 *c, int ldc); +// +static void InitializeConstantMLK_Complex16(MKL_Complex16 *x_clx, const int _n, const double c); +static void InitializeConstantDouble(double *x_p, const int _n, const double c); + + + +TSgensys *CreateTSgensys(TFlinratexp *func, const int _n, const int _m, const int _k, const double div) +{ + //_n is the number of stacked variables (endogenous, Lagurangian multiplier, expected multiplier, etc.). + //_m is the number of exogenous shocks. + //_k is the number of expectational errors. + //div is the dividing number to determine what constitutes an unstable root. If div<1.0, a div>1.0 is calculated mechanically. + TSgensys *gensys_ps = tzMalloc(1, TSgensys); + + //=== Output arguments. + gensys_ps->Theta_dm = CreateMatrix_lf(_n, _n); //n-by-n. + gensys_ps->c_dv = CreateVector_lf(_n); //n-by-1. + gensys_ps->Impact_dm = CreateMatrix_lf(_n, _m); //n-by-m. + gensys_ps->Fmat_dzm = (TSdzmatrix *)NULL; //nunstab-by-nunstab z matrix. Initialized to NULL and will be dynamically allocated whenever gensys() is called. + gensys_ps->Fwt_dzm = (TSdzmatrix *)NULL; //nunstab-by-m z matrix of possible complex numbers. Initialized to NULL and dynamically allocated. + gensys_ps->Ywt_dzm = (TSdzmatrix *)NULL; //n-by-nunstab z matrix of possible complex numbers. Initialized to NULL and dynamically allocated. + gensys_ps->Gev_dzm = CreateMatrix_dz(_n, 2); //n-by-2 z matrix of possible complex numbers. + gensys_ps->eu_iv = CreateConstantVector_int(2, 0); //2-by-1. + + //=== Function itself. + gensys_ps->gensys = func; + + //=== Input arguments. + gensys_ps->G0_dm = CreateConstantMatrix_lf(_n, _n, 0.0); //n-by-n. + gensys_ps->G0_dm->flag = M_GE; + gensys_ps->G1_dm = CreateConstantMatrix_lf(_n, _n, 0.0); //n-by-n. + gensys_ps->G1_dm->flag = M_GE; + gensys_ps->c0_dv = CreateConstantVector_lf(_n, 0.0); //n-by-1. + gensys_ps->Psi_dm = CreateConstantMatrix_lf(_n, _m, 0.0); //n-by-m. + gensys_ps->Psi_dm->flag = M_GE; + gensys_ps->Pi_dm = CreateConstantMatrix_lf(_n, _k, 0.0); //n-by-k where k is the number of expectational errors. + gensys_ps->Pi_dm->flag = M_GE; + gensys_ps->div = div; + + return (gensys_ps); +} +//------- +TSgensys *DestroyTSgensys(TSgensys *gensys_ps) +{ + if (gensys_ps) { + //=== Output arguments. + DestroyMatrix_lf(gensys_ps->Theta_dm); //n-by-n. + DestroyVector_lf(gensys_ps->c_dv); //n-by-1. + DestroyMatrix_lf(gensys_ps->Impact_dm); //n-by-m. + DestroyMatrix_dz(gensys_ps->Fmat_dzm); //nunstab-by-nunstab z matrix. Initialized to NULL and will be dynamically allocated whenever gensys() is called. + DestroyMatrix_dz(gensys_ps->Fwt_dzm); //nunstab-by-m z matrix of possible complex numbers. Initialized to NULL and dynamically allocated. + DestroyMatrix_dz(gensys_ps->Ywt_dzm); //n-by-nunstab z matrix of possible complex numbers. Initialized to NULL and dynamically allocated. + DestroyMatrix_dz(gensys_ps->Gev_dzm); //n-by-2 z matrix of possible complex numbers. + DestroyVector_int(gensys_ps->eu_iv); //2-by-1. + + //=== Input arguments. + DestroyMatrix_lf(gensys_ps->G0_dm); //n-by-n. + DestroyMatrix_lf(gensys_ps->G1_dm); //n-by-n. + DestroyVector_lf(gensys_ps->c0_dv); //n-by-1. + DestroyMatrix_lf(gensys_ps->Psi_dm); //n-by-m. + DestroyMatrix_lf(gensys_ps->Pi_dm); //n-by-k where k is the number of expectational errors. + + free(gensys_ps); + + return ((TSgensys *)NULL); + } + else return (gensys_ps); +} + + +//--------------------------- For the function gensys_sims() ------------------------------------ +static int fixdiv = 1, zxz = 0; +static double stake = 1.01; +static int nunstab = 0; +static MKL_Complex16 one, minusone, zero; + +/* [G1,C,impact,fmat,fwt,ywt,gev,eu]=gensysmkl(g0,g1,c,psi,pi,stake) */ +//void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { +void gensys_sims(TSgensys *gensys_ps, void *dummy_ps) +{ + int tmpi; + int n, psin, pin, nsquare, md, md1, i, bigev, bigev1; //mds, bigevs, //03/01/06 TZ. Commented out to be consistent with the CAS 3/10/04 correction. + int *eu; + int exist = 0, existx = 0, unique = 0; + //=== Memory will be allocated to the following. + double *deta = NULL, *deta1 = NULL, *norm = NULL; //*normx = NULL, *dz = NULL, //03/01/06 TZ. Commented out to be consistent with the CAS 3/10/04 correction. + MKL_Complex16 *a = NULL, *b = NULL, *q = NULL, *z = NULL, *pi = NULL, *psi = NULL; + MKL_Complex16 *tmat = NULL, *g0 = NULL, *g1 = NULL, *dummy = NULL, *tmatq = NULL, *c = NULL, *impact = NULL, *ab = NULL; + MKL_Complex16 *fmat = NULL, *fwt = NULL, *ywt = NULL; + MKL_Complex16 *etawt = NULL, *ueta = NULL, *veta = NULL, *etawt1 = NULL, *ueta1 = NULL, *veta1 = NULL; + // *uz = NULL, *vz = NULL, *zwt = NULL, //03/01/06 TZ. Commented out to be consistent with the CAS 3/10/04 correction. + //--- Dimensions. + n = gensys_ps->G0_dm->nrows; + psin = gensys_ps->Psi_dm->ncols; + pin = gensys_ps->Pi_dm->ncols; + //--- Pointer. + eu = gensys_ps->eu_iv->v; + + + //=== [a b q z]=qz(g0,g1); + a = CreateComplexMatrix5RealMatrix(gensys_ps->G0_dm); + b = CreateComplexMatrix5RealMatrix(gensys_ps->G1_dm); + q = tzMalloc(nsquare=square(n), MKL_Complex16); + z = tzMalloc(nsquare, MKL_Complex16); + InitializeConstantMLK_Complex16(q, nsquare, 0.0); + InitializeConstantMLK_Complex16(z, nsquare, 0.0); + + fixdiv = (gensys_ps->div < 1.0); + stake = fixdiv ? 1.01 : gensys_ps->div; + nunstab = 0; + zxz = 0; + + if (qz(a, b, q, z, n)) { + printf("WARNING: QZ factorization failed.\n"); + tzDestroy(a); + tzDestroy(b); + tzDestroy(q); + tzDestroy(z); + return; + } + + nunstab /= 2; + + if (zxz) { + printf("WARNING: Coincident zeros. Indeterminacy and/or nonexistence.\n"); + eu[0] = eu[1] = -2; + tzDestroy(a); + tzDestroy(b); + tzDestroy(q); + tzDestroy(z); + return; + } + copy_eigenvalues(gensys_ps->Gev_dzm, a, b); + + one.real = 1.0; + one.imag = 0.0; + + minusone.real = -1.0; + minusone.imag = 0.0; + + zero.real = 0.0; + zero.imag = 0.0; + + pi = CreateComplexMatrix5RealMatrix(gensys_ps->Pi_dm); + etawt = tzMalloc(tmpi=nunstab*pin, MKL_Complex16); + InitializeConstantMLK_Complex16(etawt, tmpi, 0.0); //Must be initialized to 0.0 in order to have legal values of this pointer. + cblas_zgemm(CblasColMajor, CblasConjTrans, CblasNoTrans, nunstab, pin, n, + &one, q+n*(n-nunstab), n, pi, n, &zero, etawt, nunstab); + if (compute_svd(etawt, &ueta, &deta, &veta, nunstab, pin)) { + //Memory is now allocated to ueta, deta, and veta. + + //=== DDDDDebugging + fprintf(FPTR_DEBUG, "Aind=[\n"); + WriteMatrix(FPTR_DEBUG, gensys_ps->G0_dm, " %.16e "); + fprintf(FPTR_DEBUG, "];\n"); + fprintf(FPTR_DEBUG, "Bind=[\n"); + WriteMatrix(FPTR_DEBUG, gensys_ps->G1_dm, " %.16e "); + fprintf(FPTR_DEBUG, "];\n"); + fprintf(FPTR_DEBUG, "Consterm=[\n"); + WriteVector(FPTR_DEBUG, gensys_ps->c0_dv, " %.16e "); + fprintf(FPTR_DEBUG, "]';\n"); + fprintf(FPTR_DEBUG, "gUpsiloneind=[\n"); + WriteMatrix(FPTR_DEBUG, gensys_ps->Psi_dm, " %.16e "); + fprintf(FPTR_DEBUG, "];\n"); + fprintf(FPTR_DEBUG, "gUpsilonxind=[\n"); + WriteMatrix(FPTR_DEBUG, gensys_ps->Pi_dm, " %.16e "); + fprintf(FPTR_DEBUG, "];\n"); + fflush(FPTR_DEBUG); + + + printf("WARNING: SVD failed.\n"); + tzDestroy(ueta); + tzDestroy(deta); + tzDestroy(veta); + tzDestroy(etawt); + tzDestroy(a); + tzDestroy(b); + tzDestroy(q); + tzDestroy(z); + return; + } + tzDestroy(etawt); + md = nunstab<pin?nunstab:pin; + bigev = md; + for (i=0; i<md; i++) + if (deta[i]<=REALSMALL) { + bigev=i; + break; + } + //------ 03/01/06 TZ: corrected code by CAS, 3/10/04. + eu[0] = (bigev >= nunstab); + //--------------------------------- + // ueta = nunstab x bigev + // deta = bigev x 1 + // veta = bigev x pin, ldveta = md + // uz = nunstab x bigevs + // dz = bigevs x 1 + // vz = bigevs x psin, ldvz = mds + //--------------------------------- + + //====== 03/01/06 TZ: the following note is added by CAS 3/10/04. + //------ Code below allowed "existence" in cases where the initial lagged state was free to take on values + //------ inconsistent with existence, so long as the state could w.p.1 remain consistent with a stable solution + //------ if its initial lagged value was consistent with a stable solution. This is a mistake, though perhaps there + //------ are situations where we would like to know that this "existence for restricted initial state" situation holds. + // psi = CreateComplexMatrix5RealMatrix(gensys_ps->Psi_dm); + // zwt = tzMalloc(tmpi=nunstab*psin, MKL_Complex16); + // InitializeConstantMLK_Complex16(zwt, tmpi, 0.0); //Must be initialized to 0.0 in order to have legal values of this pointer. + // cblas_zgemm(CblasColMajor, CblasConjTrans, CblasNoTrans, nunstab, psin, n, + // &one, q+n*(n-nunstab), n, psi, n, &zero, zwt, nunstab); + // if (compute_svd(zwt, &uz, &dz, &vz, nunstab, psin)) { + // //Memory is now allocated to uz, dz, and vz. + // printf("WARNING: SV decomposition failed.\n"); + // tzDestroy(ueta); + // tzDestroy(deta); + // tzDestroy(veta); + // tzDestroy(uz); + // tzDestroy(dz); + // tzDestroy(vz); + // tzDestroy(zwt); + // tzDestroy(a); + // tzDestroy(b); + // tzDestroy(q); + // tzDestroy(z); + // return; + // } + // tzDestroy(vz); + // mds = nunstab<psin?nunstab:psin; + // bigevs = mds; + // for (i=0; i<mds; i++) + // if (dz[i]<=REALSMALL) { + // bigevs=i; + // break; + // } + // tzDestroy(dz); + // + // if (!bigevs) { + // exist = 1; + // existx = 1; + // } else { + // /* uz-ueta*ueta'*uz */ + // MKL_Complex16 *tmp = tzMalloc(tmpi=nunstab*nunstab, MKL_Complex16); + // InitializeConstantMLK_Complex16(tmp, tmpi, 0.0); //Must be initialized to 0.0 in order to have legal values of this pointer. + // cblas_zgemm(CblasColMajor, CblasNoTrans, CblasConjTrans, nunstab, nunstab, + // bigev, &one, ueta, nunstab, ueta, nunstab, &zero, tmp, nunstab); + // cblas_zhemm(CblasColMajor, CblasLeft, CblasUpper, nunstab, + // bigevs, &minusone, tmp, nunstab, uz, nunstab, &one, uz, nunstab); + // tzDestroy(tmp); + // if (compute_norm(uz, &norm, nunstab, bigevs)) { + // //Memory is now allocated to norm. + // printf("WARNING: SVD failed.\n"); + // tzDestroy(norm); + // tzDestroy(ueta); + // tzDestroy(deta); + // tzDestroy(veta); + // tzDestroy(uz); + // tzDestroy(zwt); + // tzDestroy(a); + // tzDestroy(b); + // tzDestroy(q); + // tzDestroy(z); + // return; + // } + // exist = *norm < REALSMALL*n; + // tzDestroy(norm); + // if (compute_normx(a, b, zwt, ueta, &normx, nunstab, psin, n, bigev)) { + // //If 0, memory is now allocated to normx; otherwise, normx is destroyed within the function compute_normx(). + // tzDestroy(ueta); + // tzDestroy(deta); + // tzDestroy(veta); + // tzDestroy(uz); + // tzDestroy(zwt); + // tzDestroy(a); + // tzDestroy(b); + // tzDestroy(q); + // tzDestroy(z); + // return; + // } + // existx = *normx < REALSMALL*n; + // tzDestroy(normx); + // } + // + // tzDestroy(uz); + // tzDestroy(zwt); + + //--------------------------------------------------------------------------- + // Note that existence and uniqueness are not just matters of comparing + // numbers of roots and numbers of endogenous errors. These counts are + // reported below because usually they point to the source of the problem. + //--------------------------------------------------------------------------- + etawt1 = tzMalloc(tmpi=(n-nunstab)*pin, MKL_Complex16); + InitializeConstantMLK_Complex16(etawt1, tmpi, 0.0); //Must be initialized to 0.0 in order to have legal values of this pointer. + cblas_zgemm(CblasColMajor, CblasConjTrans, CblasNoTrans, n-nunstab, pin, n, + &one, q, n, pi, n, &zero, etawt1, n-nunstab); + tzDestroy(pi); + if (compute_svd(etawt1, &ueta1, &deta1, &veta1, n-nunstab, pin)) { + //Memory is now allocated to ueta1, deta1, and veta1. + printf("WARNING: SVD failed for compute_svd().\n"); + tzDestroy(ueta1); + tzDestroy(deta1); + tzDestroy(veta1); + tzDestroy(etawt1); + tzDestroy(ueta); + tzDestroy(deta); + tzDestroy(veta); + tzDestroy(a); + tzDestroy(b); + tzDestroy(q); + tzDestroy(z); + return; + } + tzDestroy(etawt1); + md1 = n-nunstab<pin?n-nunstab:pin; + bigev1 = md1; + for (i=0; i<md1; i++) + if (deta1[i]<=REALSMALL) { + bigev1=i; + break; + } + + //====== 03/01/06 TZ: the following is commented out by CAS 3/10/04. + // if (existx || !nunstab) { + // //=== Solution exists. + // eu[0] = 1; + // } else { + // if (exist) { + // printf("WARNING: Solution exists for unforecastable z only\n"); + // eu[0] = -1; + // } /* else + // mexPrintf("No solution. %d unstable roots. %d endog errors.\n",nunstab,bigev1); */ + // /* mexPrintf("Generalized eigenvalues\n"); + // mexCallMATLAB(0,NULL,1, &plhs[6], "disp"); */ + // } + + + //------------------------------- + // ueta1 = n-nunstab x bigev1 + // deta1 = bigev1 x 1 + // veta1 = bigev1 x pin, ldveta1 = md1 + //------------------------------- + if (!bigev1) + unique = 1; + else { + // veta1-veta1*veta*veta' + // veta = bigev x pin, ldveta1 = md + // veta1 = bigev1 x pin, ldveta1 = md1 + MKL_Complex16 *tmp = tzMalloc(pin*pin, MKL_Complex16); + MKL_Complex16 *veta1_copy = tzMalloc(pin*bigev1, MKL_Complex16); + InitializeConstantMLK_Complex16(tmp, pin*pin, 0.0); //Must be initialized to 0.0 in order to have legal values of this pointer. + InitializeConstantMLK_Complex16(veta1_copy, pin*bigev1, 0.0); //Must be initialized to 0.0 in order to have legal values of this pointer. + cblas_zgemm(CblasColMajor, CblasConjTrans, CblasNoTrans, pin, pin, + bigev, &one, veta, md, veta, md, &zero, tmp, pin); + cblas_zdupe(bigev1,pin,veta1,md1,veta1_copy,bigev1); + cblas_zhemm(CblasColMajor, CblasRight, CblasUpper, bigev1, pin, + &minusone, tmp, pin, veta1_copy, bigev1, &one, veta1_copy, bigev1); + tzDestroy(tmp); + if (compute_norm(veta1_copy, &norm, bigev1, pin)) { + //Memory is now allocated to norm. + printf("WARNING: SVD failed.\n"); + tzDestroy(norm); + tzDestroy(ueta1); + tzDestroy(deta1); + tzDestroy(veta1); + tzDestroy(ueta); + tzDestroy(deta); + tzDestroy(veta); + tzDestroy(veta1_copy); + tzDestroy(a); + tzDestroy(b); + tzDestroy(q); + tzDestroy(z); + return; + } + tzDestroy(veta1_copy); + unique = *norm < REALSMALL*n; + tzDestroy(norm); + } + if (unique) { + //=== Unique solution. + eu[1] = 1; + } else { + eu[1] = 0; + printf("WARNING: Indeterminacy. %d loose endog errors with eu being [%d, %d].\n",bigev1-bigev, eu[0], eu[1]); + //printf("WARNING: Indeterminacy. %d loose endog errors with eu being [%g, %g].\n",bigev1-bigev, gensys_ps->eu_dv->v[0], gensys_ps->eu_dv->v[1]); + //printf("WARNING: Indeterminacy. %d loose endog errors.\n",bigev1-bigev); + } + + cblas_zdscali(pin,deta,bigev,veta,md); /* veta' = deta\veta' */ + tzDestroy(deta); + cblas_zdscale(pin,deta1,bigev1,veta1,md1); /* veta1' = deta1*veta1' */ + tzDestroy(deta1); + etawt = tzMalloc(tmpi=nunstab*pin, MKL_Complex16); /* etawt = ueta*veta' */ + InitializeConstantMLK_Complex16(etawt, tmpi, 0.0); //Must be initialized to 0.0 in order to have legal values of this pointer. + cblas_zgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, nunstab, pin, bigev, + &one, ueta, nunstab, veta, md, &zero, etawt, nunstab); + tzDestroy(ueta); + tzDestroy(veta); + etawt1 = tzMalloc(tmpi=(n-nunstab)*pin, MKL_Complex16); /* etawt1 = ueta1*veta1' */ + InitializeConstantMLK_Complex16(etawt1, tmpi, 0.0); //Must be initialized to 0.0 in order to have legal values of this pointer. + cblas_zgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, n-nunstab, pin, bigev1, + &one, ueta1, n-nunstab, veta1, md1, &zero, etawt1, n-nunstab); + tzDestroy(ueta1); + tzDestroy(veta1); + tmat = tzMalloc(tmpi=(n-nunstab)*nunstab, MKL_Complex16); /* tmat = etawt1*etawt' */ + InitializeConstantMLK_Complex16(tmat, tmpi, 0.0); //Must be initialized to 0.0 in order to have legal values of this pointer. + cblas_zgemm(CblasColMajor, CblasNoTrans, CblasConjTrans, n-nunstab, nunstab, pin, + &one, etawt1, n-nunstab, etawt, nunstab, &zero, tmat, n-nunstab); + tzDestroy(etawt1); + tzDestroy(etawt); + + g0 = tzMalloc(tmpi=n*n, MKL_Complex16); + InitializeConstantMLK_Complex16(g0, tmpi, 0.0); //Must be initialized to 0.0 in order to have legal values of this pointer. + cblas_zdupe(n-nunstab, n, a, n, g0, n); + cblas_zgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, n-nunstab, nunstab, nunstab, + &minusone, tmat, n-nunstab, a+(n-nunstab)*(n+1), n, &one, g0+(n-nunstab)*n, n); + cblas_zcopy(nunstab, &one, 0, g0+(n-nunstab)*(n+1), n+1); + + g1 = tzMalloc(tmpi=n*n, MKL_Complex16); + InitializeConstantMLK_Complex16(g1, tmpi, 0.0); //Must be initialized to 0.0 in order to have legal values of this pointer. + cblas_zdupe(n-nunstab, n, b, n, g1, n); + cblas_zgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, n-nunstab, nunstab, nunstab, + &minusone, tmat, n-nunstab, b+(n-nunstab)*(n+1), n, &one, g1+(n-nunstab)*n, n); + cblas_ztrsm(CblasColMajor, CblasLeft, CblasUpper, CblasNoTrans, CblasNonUnit, + n, n, &one, g0, n, g1, n); + dummy = tzMalloc(tmpi=n*n, MKL_Complex16); + InitializeConstantMLK_Complex16(dummy, tmpi, 0.0); //Must be initialized to 0.0 in order to have legal values of this pointer. + cblas_zgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, n, n, n, &one, z, n, g1, n, &zero, dummy, n); + cblas_zgemm(CblasColMajor, CblasNoTrans, CblasConjTrans, n, n, n, &one, dummy, n, z, n, &zero, g1, n); + tzDestroy(dummy); + ComplexMatrix2RealMatrix(gensys_ps->Theta_dm, g1); //Output. + tzDestroy(g1); + + tmatq = tzMalloc(tmpi=n*n, MKL_Complex16); + InitializeConstantMLK_Complex16(tmatq, tmpi, 0.0); //Must be initialized to 0.0 in order to have legal values of this pointer. + cblas_zcopy(n*n, q, 1, tmatq, 1); + cblas_zgemm(CblasColMajor, CblasNoTrans, CblasConjTrans, n, n-nunstab, nunstab, + &minusone, tmatq+(n-nunstab)*n, n, tmat, n-nunstab, &one, tmatq, n); + tzDestroy(tmat); + + ab = tzMalloc(tmpi=nunstab*nunstab, MKL_Complex16); + InitializeConstantMLK_Complex16(ab, tmpi, 0.0); //Must be initialized to 0.0 in order to have legal values of this pointer. + cblas_zdpsb(nunstab, nunstab, a+(n-nunstab)*(n+1), n, b+(n-nunstab)*(n+1), n, ab, nunstab); + cblas_ztrsm(CblasColMajor, CblasRight, CblasUpper, CblasConjTrans, CblasNonUnit, + n, nunstab, &one, ab, nunstab, tmatq+(n-nunstab)*n, n); + tzDestroy(ab); + + //c = mat2mkl(prhs[2],n,1); + c = CreateComplexMatrix5RealVector(gensys_ps->c0_dv); + dummy = tzMalloc(gensys_ps->c0_dv->n, MKL_Complex16); + //$$$$$$$ The following is Iskander's fatal code error. One cannot use c in the two different places; otherwise, it makes c be zero completely! + // cblas_zgemv(CblasColMajor, CblasConjTrans, n, n, &one, tmatq, n, c, 1, &zero, c, 1); + // cblas_ztrsv(CblasColMajor, CblasUpper, CblasNoTrans, CblasNonUnit, n, g0, n, c, 1); + // cblas_zgemv(CblasColMajor, CblasNoTrans, n, n, &one, z, n, c, 1, &zero, c, 1); + cblas_zgemv(CblasColMajor, CblasConjTrans, n, n, &one, tmatq, n, c, 1, &zero, dummy, 1); + cblas_ztrsv(CblasColMajor, CblasUpper, CblasNoTrans, CblasNonUnit, n, g0, n, dummy, 1); + cblas_zgemv(CblasColMajor, CblasNoTrans, n, n, &one, z, n, dummy, 1, &zero, c, 1); + //plhs[1] = mkl2mat_real(c, n, n, 1); + ComplexMatrix2RealVector(gensys_ps->c_dv, c); //Output. + tzDestroy(c); + tzDestroy(dummy); + + impact = tzMalloc(tmpi=n*psin, MKL_Complex16); + InitializeConstantMLK_Complex16(impact, tmpi, 0.0); //Must be initialized to 0.0 in order to have legal values of this pointer. + psi = CreateComplexMatrix5RealMatrix(gensys_ps->Psi_dm); //03/01/06 TZ. Added to be consistent with the CAS 3/10/04 correction. + cblas_zgemm(CblasColMajor, CblasConjTrans, CblasNoTrans, n-nunstab, psin, n, + &one, tmatq, n, psi, n, &zero, impact, n); + tzDestroy(tmatq); + cblas_ztrsm(CblasColMajor, CblasLeft, CblasUpper, CblasNoTrans, CblasNonUnit, + n, psin, &one, g0, n, impact, n); + dummy = tzMalloc(tmpi=n*psin, MKL_Complex16); + InitializeConstantMLK_Complex16(dummy, tmpi, 0.0); //Must be initialized to 0.0 in order to have legal values of this pointer. + cblas_zgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, n, psin, n, + &one, z, n, impact, n, &zero, dummy, n); + tzDestroy(impact); + //plhs[2] = mkl2mat_real(dummy, n, n, psin); + ComplexMatrix2RealMatrix(gensys_ps->Impact_dm, dummy); //Output. + tzDestroy(dummy); + + fmat = a+(n-nunstab)*(n+1); + cblas_ztrsm(CblasColMajor, CblasLeft, CblasUpper, CblasNoTrans, CblasNonUnit, + nunstab, nunstab, &one, b+(n-nunstab)*(n+1), n, fmat, n); + //plhs[3] = mkl2mat(fmat, n, nunstab, nunstab); + gensys_ps->Fmat_dzm = SubComplexMatrix2Zmatrix(gensys_ps->Fmat_dzm, fmat, n, nunstab, nunstab); + tzDestroy(a); + + fwt = tzMalloc(tmpi=nunstab*psin, MKL_Complex16); + InitializeConstantMLK_Complex16(fwt, tmpi, 0.0); //Must be initialized to 0.0 in order to have legal values of this pointer. + cblas_ztrsm(CblasColMajor, CblasRight, CblasUpper, CblasConjTrans, CblasNonUnit, + n, nunstab, &one, b+(n-nunstab)*(n+1), n, q+(n-nunstab)*n, n); + tzDestroy(b); + cblas_zgemm(CblasColMajor, CblasConjTrans, CblasNoTrans, nunstab, psin, n, + &minusone, q+(n-nunstab)*n, n, psi, n, &zero, fwt, nunstab); + tzDestroy(q); + tzDestroy(psi); + gensys_ps->Fwt_dzm = SubComplexMatrix2Zmatrix(gensys_ps->Fwt_dzm, fwt, nunstab, nunstab, psin); + tzDestroy(fwt); + + ywt = tzMalloc(tmpi=n*nunstab, MKL_Complex16); + InitializeConstantMLK_Complex16(ywt, tmpi, 0.0); + cblas_zcopy(nunstab, &one, 0, ywt+n-nunstab, n+1); + cblas_ztrsm(CblasColMajor, CblasLeft, CblasUpper, CblasNoTrans, CblasNonUnit, + n, nunstab, &one, g0, n, ywt, n); + tzDestroy(g0); + dummy = tzMalloc(tmpi=n*nunstab, MKL_Complex16); + InitializeConstantMLK_Complex16(dummy, tmpi, 0.0); //Must be initialized to 0.0 in order to have legal values of this pointer. + cblas_zgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, n, nunstab, n, + &one, z, n, ywt, n, &zero, dummy, n); + tzDestroy(z); + tzDestroy(ywt); + gensys_ps->Ywt_dzm = SubComplexMatrix2Zmatrix(gensys_ps->Ywt_dzm, dummy, n, n, nunstab); + tzDestroy(dummy); +} + + +/****************************************************************************** + * function selctg orders the eigenvalues so that a selected cluster of * + * eigenvalues appears in the leading diagonal blocks of the upper * + * quasi-triangular matrix S and the upper triangular matrix T. * + ******************************************************************************/ + +static int selctg(MKL_Complex16 *alpha, MKL_Complex16 *beta) +{ + double absA = sqrt(alpha->real*alpha->real+alpha->imag*alpha->imag), + absB = fabs(beta->real); + if (absA) { + double divhat = absB/absA; + //bug detected by Vasco Curdia and Daria Finocchiaro, 2/25/2004 CAS. A root of + //exactly 1.01 and no root between 1 and 1.02, led to div being stuck at 1.01 + //and the 1.01 root being misclassified as stable. Changing < to <= below fixes this. + if (fixdiv && 1+REALSMALL<divhat && divhat<=stake) + stake = (1+divhat)/2; + } + if (absA<REALSMALL && absB<REALSMALL) + zxz = 1; + if (absB>stake*absA) { + nunstab++; + return(0); + } else + return(1); +} + +/****************************************************************************** + * compute for a pair of N-by-N complex nonsymmetric matrices (A,B), * + * the generalized eigenvalues, the generalized complex Schur form (S, T), * + * and optionally left and/or right Schur vectors (VSL and VSR) * + ******************************************************************************/ + +static int qz(MKL_Complex16 *a, MKL_Complex16 *b, MKL_Complex16 *q, MKL_Complex16 *z, int n) +{ +// unsigned char msg[101]; + int sdim, lwork = -1, info = 0; + MKL_Complex16 *alpha = tzMalloc(n,MKL_Complex16), + *beta = tzMalloc(n,MKL_Complex16), + *work, work1; + double *rwork = tzMalloc(8*n, double); + int *bwork = tzMalloc(4*n, int); + + /* Query zgges on the value of lwork */ + zgges("V", "V", "S", &selctg, &n, a, &n, b, &n, &sdim, alpha, beta, q, + &n, z, &n, &work1, &lwork, rwork, bwork, &info); + + if (info < 0) { + printf("WARNING: Input %d to the Intel MKL function zgges() has an illegal value",-info); + tzDestroy(bwork); + tzDestroy(rwork); + tzDestroy(alpha); + tzDestroy(beta); + return(info); + } + + lwork = (int)(work1.real); + work = tzMalloc(lwork, MKL_Complex16); + zgges("V", "V", "S", &selctg, &n, a, &n, b, &n, &sdim, alpha, beta, q, + &n, z, &n, work, &lwork, rwork, bwork, &info); + + tzDestroy(work); + tzDestroy(bwork); + tzDestroy(rwork); + tzDestroy(alpha); + tzDestroy(beta); + + if (info < 0) { + printf("WARNING: Input %d to the Intel MKL function zgges() has an illegal value",-info); + return(info); + } + + if (info > 0) + if (info < n) + printf("WARNING: The QZ iteration failed. (A,B) are not in Schur form,\n" + "but ALPHA(j) and BETA(j) should be correct for j=%d,...,N.",info+1); + else { + switch (info-n) { + case 1: + printf("WARNING: LAPACK problem: error return from ZGGBAL"); + break; + case 2: + printf("WARNING: LAPACK problem: error return from ZGEQRF"); + break; + case 3: + printf("WARNING: LAPACK problem: error return from ZUNMQR"); + break; + case 4: + printf("WARNING: LAPACK problem: error return from ZUNGQR"); + break; + case 5: + printf("WARNING: LAPACK problem: error return from ZGGHRD"); + break; + case 6: + printf("WARNING: LAPACK problem: error return from ZHGEQZ (other than failed iteration)"); + break; + case 7: + printf("WARNING: LAPACK problem: error return from ZGGBAK (computing VSL)"); + break; + case 8: + printf("WARNING: LAPACK problem: error return from ZGGBAK (computing VSR)"); + break; + case 9: + printf("WARNING: LAPACK problem: error return from ZLASCL (various places)"); + break; + default: + printf("WARNING: LAPACK problem: unknown error."); + break; + } + } + return(info); +} + +/* + * Convert MATLAB complex matrix to MKL complex storage. + * + * Z = mat2mkl(X,ldz,ndz) + * + * converts MATLAB's mxArray X to MKL_Complex16 Z(ldz,ndz). + * The parameters ldz and ndz determine the storage allocated for Z, + * while mxGetM(X) and mxGetN(X) determine the amount of data copied. + */ + +//MKL_Complex16* mat2mkl(const mxArray *X, int ldz, int ndz) { +// MKL_Complex16 *Z, *zp; +// int m, n, incz, cmplxflag; +// register int i, j; +// double *xr, *xi; + +// Z = mxCalloc(ldz*ndz, sizeof(MKL_Complex16)); +// xr = mxGetPr(X); +// xi = mxGetPi(X); +// m = mxGetM(X); +// n = mxGetN(X); +// zp = Z; +// incz = ldz-m; +// cmplxflag = (xi != NULL); +// for (j = 0; j < n; j++) { +// if (cmplxflag) { +// for (i = 0; i < m; i++) { +// zp->real = *xr++; +// zp->imag = *xi++; +// zp++; +// } +// } else { +// for (i = 0; i < m; i++) { +// zp->real = *xr++; +// zp++; +// } +// } +// zp += incz; +// } +// return(Z); +//} + + +/* + * Convert MKL complex storage to MATLAB real and imaginary parts. + * + * X = mkl2mat(Z,ldz,m,n) + * + * copies MKL_Complex16 Z to X, producing a complex mxArray + * with mxGetM(X) = m and mxGetN(X) = n. + */ + +//mxArray* mkl2mat(MKL_Complex16 *Z, int ldz, int m, int n) { +// int i, j, incz; +// double *xr, *xi; +// MKL_Complex16 *zp; +// mxArray *X; + +// X = mxCreateDoubleMatrix(m,n,mxCOMPLEX); +// xr = mxGetPr(X); +// xi = mxGetPi(X); +// zp = Z; +// incz = ldz-m; +// for (j = 0; j < n; j++) { +// for (i = 0; i < m; i++) { +// *xr++ = zp->real; +// *xi++ = zp->imag; +// zp++; +// } +// zp += incz; +// } +// return(X); +//} + +//plhs[3] = mkl2mat(fmat, n, nunstab, nunstab) + +/* + * Convert MKL complex storage to MATLAB real matrix ignoring imaginary part. + * + * X = mkl2mat(Z,ldz,m,n) + * + * copies MKL_Complex16 Z to X, producing a real mxArray + * with mxGetM(X) = m and mxGetN(X) = n. + */ + +//mxArray* mkl2mat_real(MKL_Complex16 *Z, int ldz, int m, int n) { +// int i, j, incz; +// double *xr; +// MKL_Complex16 *zp; +// mxArray *X; + +// X = mxCreateDoubleMatrix(m,n,mxREAL); +// xr = mxGetPr(X); +// zp = Z; +// incz = ldz-m; +// for (j = 0; j < n; j++) { +// for (i = 0; i < m; i++) { +// *xr++ = zp->real; +// zp++; +// } +// zp += incz; +// } +// return(X); +//} + +//void copy_eigenvalues(mxArray *gev, MKL_Complex16 *a, MKL_Complex16 *b, int n) { +// double *gevr = mxGetPr(gev), +// *gevi = mxGetPi(gev); +// int i; + +// for (i=0; i<n; i++, gevr++, gevi++, a+=n+1) { +// *gevr = a->real; +// *gevi = a->imag; +// } + +// for (i=0; i<n; i++, gevr++, gevi++, b+=n+1) { +// *gevr = b->real; +// *gevi = b->imag; +// } +//} + +static void copy_eigenvalues(TSdzmatrix *Gev_dzm, MKL_Complex16 *a, MKL_Complex16 *b) +{ + int n = Gev_dzm->real->nrows; + double *gevr = Gev_dzm->real->M, + *gevi = Gev_dzm->imag->M; + int i; + + for (i=0; i<n; i++, gevr++, gevi++, a+=n+1) { + *gevr = a->real; + *gevi = a->imag; + } + + for (i=0; i<n; i++, gevr++, gevi++, b+=n+1) { + *gevr = b->real; + *gevi = b->imag; + } +} + + +static int compute_svd(MKL_Complex16 *x, MKL_Complex16 **u, double **d, MKL_Complex16 **v, int m, int n) +{ + //$$$Memory allocated to u, d, and v will be destroyed outside this function.$$$ + int tmpi; + int md = m<n?m:n, lwork = -1, info = 0; + MKL_Complex16 *a, *work, work1; + double *rwork = tzMalloc(5*md>1?5*md:1, double); + + a = tzMalloc(m*n, MKL_Complex16); + cblas_zcopy(m*n, x, 1, a, 1); + + *u = tzMalloc(tmpi=m*md,MKL_Complex16); + InitializeConstantMLK_Complex16(*u, tmpi, 0.0); + *v = tzMalloc(tmpi=md*n, MKL_Complex16); + InitializeConstantMLK_Complex16(*v, tmpi, 0.0); + *d = tzMalloc(md, double); + InitializeConstantDouble(*d, md, 0.0); + + /* Query zgges on the value of lwork */ + zgesvd("S", "S", &m, &n, a, &m, *d, *u, &m, *v, &md, &work1, &lwork, rwork, &info); + + if (info < 0) { + printf("WARNING: Input %d to zgesvd had an illegal value",-info); + tzDestroy(rwork); + return(info); + } + + lwork = (int)(work1.real); + work = tzMalloc(lwork, MKL_Complex16); + zgesvd("S", "S", &m, &n, a, &m, *d, *u, &m, *v, &md, work, &lwork, rwork, &info); + + tzDestroy(work); + tzDestroy(rwork); + tzDestroy(a); + + if (info < 0) + printf("WARNING: Input %d to zgesvd had an illegal value",-info); + + if (info > 0) + printf("WARNING: ZBDSQR did not converge.\n%d superdiagonals of an intermediate " + "bidiagonal form B did not converge to zero.",info); + return(info); +} + +static int compute_norm(MKL_Complex16 *a, double **d, int m, int n) +{ + //Memory will be allocated to d, which will be destroyed outside this function. + int md = m<n?m:n, lwork = -1, info = 0; + MKL_Complex16 *work = NULL, work1; + double *rwork = tzMalloc(5*md>1?5*md:1, double); + + *d = tzMalloc(md, double); + + /* Query zgges on the value of lwork */ + zgesvd("N", "N", &m, &n, a, &m, *d, NULL, &m, NULL, &md, &work1, &lwork, rwork, &info); + + if (info < 0) { + printf("WARNING: Input %d to zgesvd had an illegal value",-info); + tzDestroy(rwork); + return(info); + } + + lwork = (int)(work1.real); + work = tzMalloc(lwork, MKL_Complex16); + zgesvd("N", "N", &m, &n, a, &m, *d, NULL, &m, NULL, &md, work, &lwork, rwork, &info); + + tzDestroy(work); + tzDestroy(rwork); + + if (info < 0) + printf("WARNING: Input %d to zgesvd had an illegal value",-info); + + if (info > 0) + printf("WARNING: ZBDSQR() in Intel MKL did not converge.\n%d superdiagonals of an intermediate " + "bidiagonal form B did not converge to zero.",info); + + return(info); +} + + +//======= 03/01/06 TZ. Commented out to be consistent with the CAS 3/10/04 correction. =======// +//static int compute_normx(MKL_Complex16 *a, MKL_Complex16 *b, MKL_Complex16 *zwt, MKL_Complex16 *ueta, double **normx, int nunstab, int psin, int n, int bigev) +//{ +// //Memory is allocated to normx, which will be freed outside this function. +// int tmpi; +// int info = 0, i, bigevs; +// // +// MKL_Complex16 *M = NULL, *zwtx = NULL, *ux = NULL, *vx = NULL, *tmp = NULL; +// double *dx = NULL; + + +// a += (n+1)*(n-nunstab); +// b += (n+1)*(n-nunstab); +// cblas_ztrsm(CblasColMajor, CblasLeft, CblasUpper, CblasNoTrans, CblasNonUnit, +// nunstab, psin, &one, b, n, zwt, nunstab); +// M = tzMalloc(nunstab*nunstab, MKL_Complex16); +// cblas_zdupe(nunstab, nunstab, a, n, M, nunstab); +// cblas_ztrsm(CblasColMajor, CblasLeft, CblasUpper, CblasNoTrans, CblasNonUnit, +// nunstab, nunstab, &one, b, n, M, nunstab); + +// zwtx = tzMalloc(nunstab*nunstab*psin, MKL_Complex16); +// cblas_zcopy(nunstab*psin, zwt, 1, zwtx, 1); +// for (i=1; i<nunstab; i++) { +// cblas_ztrmm(CblasColMajor, CblasLeft, CblasUpper, CblasNoTrans, CblasNonUnit, nunstab, psin*i, &one, M, nunstab, zwtx, nunstab); +// cblas_zcopy(nunstab*psin, zwt, 1, zwtx+nunstab*psin*i, 1); +// } +// tzDestroy(M); +// cblas_ztrmm(CblasColMajor, CblasLeft, CblasUpper, CblasNoTrans, CblasNonUnit, nunstab, nunstab*psin, &one, b, n, zwtx, nunstab); +// info = compute_svd(zwtx, &ux, &dx, &vx, nunstab, nunstab*psin); //Memory is allocated to ux, dx, and vx. +// tzDestroy(vx); +// tzDestroy(zwtx); +// if (info) { +// printf("WARNING: SVD failed.\n"); +// tzDestroy(ux); +// tzDestroy(dx); +// return(info); +// } +// bigevs = nunstab; +// for (i=0; i<nunstab; i++) +// if (dx[i]<=REALSMALL) { +// bigevs = i; +// break; +// } +// tzDestroy(dx); +// /* ux-ueta*ueta'*ux */ +// tmp = tzMalloc(tmpi=nunstab*nunstab, MKL_Complex16); +// InitializeConstantMLK_Complex16(tmp, tmpi, 0.0); //Must be initialized to 0.0 in order to have legal values of this pointer. +// cblas_zgemm(CblasColMajor, CblasNoTrans, CblasConjTrans, nunstab, nunstab, +// bigev, &one, ueta, nunstab, ueta, nunstab, &zero, tmp, nunstab); +// cblas_zhemm(CblasColMajor, CblasLeft, CblasUpper, nunstab, +// bigevs, &minusone, tmp, nunstab, ux, nunstab, &one, ux, nunstab); +// tzDestroy(tmp); +// info = compute_norm(ux, normx, nunstab, bigevs); //Memory is allocated to normx. +// if (info) { +// printf("WARNING: SVD failed.\n"); +// tzDestroy(normx); +// tzDestroy(ux); +// return(info); +// } +// tzDestroy(ux); +// return(info); +//} + +static void cblas_zdupe(int m, int n, MKL_Complex16 *a, int lda, MKL_Complex16 *b, int ldb) +{ + int i; + for (i=0; i<m; i++, a++, b++) + cblas_zcopy(n, a, lda, b, ldb); +} + +static void cblas_zdscali(int n, double *a, int lda, MKL_Complex16 *b, int ldb) +{ + int i; + for (i=0; i<lda; i++, a++, b++) + cblas_zdscal(n, 1.0/(*a), b, ldb); +} + +static void cblas_zdscale(int n, double *a, int lda, MKL_Complex16 *b, int ldb) +{ + int i; + for (i=0; i<lda; i++, a++, b++) + cblas_zdscal(n, *a, b, ldb); +} + +static void cblas_zdpsb(int m, int n, MKL_Complex16 *a, int lda, MKL_Complex16 *b, int ldb, MKL_Complex16 *c, int ldc) +{ + int i; + cblas_zdupe(m, n, a, lda, c, ldc); + for (i=0; i<m; i++, b++, c++) + cblas_zaxpy(n, &minusone, b, ldb, c, ldc); +} + + +static MKL_Complex16* CreateComplexMatrix5RealMatrix(TSdmatrix *X_dm) +{ + int mn, k; + double *M; + // + MKL_Complex16 *Z = NULL; + + if (!X_dm) fn_DisplayError("CreateComplexMatrix5RealMatrix(): Input matrix X_dm must be allocated memory"); + M = X_dm->M; + + Z = tzMalloc(mn=X_dm->nrows*X_dm->ncols, MKL_Complex16); + for (k=mn-1; k>=0; k--) { + Z[k].real = M[k]; + Z[k].imag = 0.0; + } + return(Z); +} + +static MKL_Complex16* CreateComplexMatrix5RealVector(TSdvector *x_dv) +{ + int n, k; + double *v; + // + MKL_Complex16 *Z = NULL; + + if (!x_dv) fn_DisplayError("CreateComplexMatrix5RealVector(): Input vector x_dv must be allocated memory"); + v = x_dv->v; + + Z = tzMalloc(n=x_dv->n, MKL_Complex16); + for (k=n-1; k>=0; k--) { + Z[k].real = v[k]; + Z[k].imag = 0.0; + } + return(Z); +} + + +static void ComplexMatrix2RealMatrix(TSdmatrix *Y_dm, MKL_Complex16 *Z) +{ + int _k; + double *M; + + if (!Y_dm) fn_DisplayError("ComplexMatrix2RealMatrix(): Output matrix Y_dm must be allocated memory"); + M = Y_dm->M; + + for (_k=Y_dm->nrows*Y_dm->ncols-1; _k>=0; _k--) M[_k] = Z[_k].real; + Y_dm->flag = M_GE; +} + + +static void ComplexMatrix2RealVector(TSdvector *y_dv, MKL_Complex16 *Z) +{ + int _k; + double *v; + + if (!y_dv) fn_DisplayError("ComplexMatrix2RealVector(): Output matrix y_dv must be allocated memory"); + v = y_dv->v; + + for (_k=y_dv->n-1; _k>=0; _k--) v[_k] = Z[_k].real; + y_dv->flag = V_DEF; +} + + +static TSdzmatrix *SubComplexMatrix2Zmatrix(TSdzmatrix *X_dzm, MKL_Complex16 *Z, const int nrowsforZ, const int _m, const int _n) +{ + //X_dzm is _m-by_n comlex types where nrowsforZ <= _m and Z is nrowsforZ-by-_n. + int _i, _j, incz; + double *Mreal, *Mimag; + MKL_Complex16 *zp; + // + TSdzmatrix *Y_dzm = NULL; + + if (!X_dzm || X_dzm->real->nrows != _m || X_dzm->real->ncols != _n) { + DestroyMatrix_dz(X_dzm); //Destroys Y_dzm if already allocated memory to accommodate a possbible change of its dimension. + Y_dzm = CreateMatrix_dz(_m, _n); + } + else Y_dzm = X_dzm; + + Mreal = Y_dzm->real->M; + Mimag = Y_dzm->imag->M; + zp = Z; + if ((incz=nrowsforZ-_m)<0) fn_DisplayError("SubComplexMatrix2ZMatrix(): Number of rows for the input complex matrix Z must be greater that of the output Z matrix Y_dzm"); + + for (_j=0; _j<_n; _j++) { + for (_i=0; _i<_m; _i++) { + *Mreal++ = zp->real; + *Mimag++ = zp->imag; + zp++; + } + zp += incz; + } + return (Y_dzm); +} + + +static void InitializeConstantMLK_Complex16(MKL_Complex16 *x_clx, const int _n, const double c) +{ + int _i; + + for (_i=_n-1; _i>=0; _i--) + x_clx[_i].real = x_clx[_i].imag = c; +} + +static void InitializeConstantDouble(double *x_p, const int _n, const double c) +{ + int _i; + + for (_i=_n-1; _i>=0; _i--) x_p[_i] = c; +} diff --git a/CFiles/gensysOldVersionWorks.c b/CFiles/gensysOldVersionWorks.c new file mode 100755 index 0000000..c78aa43 --- /dev/null +++ b/CFiles/gensysOldVersionWorks.c @@ -0,0 +1,1114 @@ +/******************************************************************* + * [G1,C,impact,fmat,fwt,ywt,gev,eu]=gensys(g0,g1,c,psi,pi,div) + * + * System given as + * g0*y(t)=g1*y(t-1)+c+psi*z(t)+pi*eta(t), + * with z an exogenous variable process and eta being endogenously determined + * one-step-ahead expectational errors. Returned system is + * y(t)=G1*y(t-1)+C+impact*z(t)+ywt*inv(I-fmat*inv(L))*fwt*z(t+1) . + * If z(t) is i.i.d., the last term drops out. + * If div or stake is omitted from argument list, a div>1 or stake>1 is calculated. + * eu(1)=1 for existence, eu(2)=1 for uniqueness. eu(1)=-1 for + * existence only with not-serially correlated z(t); eu=[-2,-2] for coincident zeros. + * + * g0, g1: n-by-n matrices. + * c: n-by-1 constant terms. + * z(t): m-by-1 vector of exogenous residuals where m < n. + * psi: n-by-m matrix. + * eta(t): h-by-1 vector of expectational (endogenous) errors. + * pi: n-by-h matrix. + * div: a real number dividing stable and unstable roots.. If < 1.0, a div>1.0 is calculated mechanically. + *------- + * G1 or Theta_dm: n-by-n matrices. + * C: n-by-1 vector of constant terms. + * impact: n-by-m matrix. + * gev: n-by-2 z vector of stacked generalized eigenvalues where gev(;,2) ./ gev(:,1) = eig(g0, g1). + * ywt: n-by-nunstab z matrix of possible complex numbers. Initialized to NULL and dynamically allocated. + * fmat: nunstab-by-nunstab z matrix where nunstab is the number of non-stable roots. + * fwt: nunstab-by-m z matrix. + * + * 1996 MATLAB algorithm by Christopher Sims + * 2002 Mex implementation by Iskander Karibzhanov + * 2004 Modified to C function by Tao Zha (April) + * + * Note: Iskander is transforming g0 and g1 to complex matrices and uses zgges() as a qz decomposition. + * This is really wasting efficiency. One should keep g0 and g1 as real matrices and use + * dgges() as a qz decomposition. I don't have time to overhaul this at this point. 04/20/04, T. Zha. + * Note: 02/22/06. I take the above note back. According to DW, it is easy to order the + * the generalized eigenvalues by using the complex g0 and g1. In principle, one could + * order the roots using the real qz decomposition on real matrices g0 and g1. But so far + * Dan has found it a pain to do it. Perhaps we should read the MKL Lapack manual more + * carefully at a later point. +********************************************************************/ + +#include "gensys.h" + + +//----- NOTE: We can't replace MKL_Complex16 with a different name because the Intel Lapack uses MKL_Complex16. +//----- The only way to do this is to overhaul the code and put a wrapper function on each Intel Lapack function. +static int selctg(MKL_Complex16 *alpha, MKL_Complex16 *beta); +static int qz(MKL_Complex16 *a, MKL_Complex16 *b, MKL_Complex16 *q, MKL_Complex16 *z, int n); +static MKL_Complex16* CreateComplexMatrix5RealMatrix(TSdmatrix *X_dm); +static MKL_Complex16* CreateComplexMatrix5RealVector(TSdvector *x_dv); +static void ComplexMatrix2RealMatrix(TSdmatrix *Y_dm, MKL_Complex16 *Z); +static void ComplexMatrix2RealVector(TSdvector *y_dv, MKL_Complex16 *Z); +static TSdzmatrix *SubComplexMatrix2Zmatrix(TSdzmatrix *X_dzm, MKL_Complex16 *Z, const int nrowsforZ, const int _m, const int _n); +static void copy_eigenvalues(TSdzmatrix *Gev_dzm, MKL_Complex16 *a, MKL_Complex16 *b); +static int compute_svd(MKL_Complex16 *a, MKL_Complex16 **u, double **d, MKL_Complex16 **v, int m, int n); +static int compute_norm(MKL_Complex16 *a, double **d, int m, int n); +// +static int compute_normx(MKL_Complex16 *a, MKL_Complex16 *b, MKL_Complex16 *zwt, MKL_Complex16 *ueta, double **normx, int nunstab, int psin, int n, int bigev); +static void cblas_zdupe(int m, int n, MKL_Complex16 *a, int lda, MKL_Complex16 *b, int ldb); +static void cblas_zdscali(int n, double *a, int lda, MKL_Complex16 *b, int ldb); +static void cblas_zdscale(int n, double *a, int lda, MKL_Complex16 *b, int ldb); +static void cblas_zdpsb(int m, int n, MKL_Complex16 *a, int lda, MKL_Complex16 *b, int ldb, MKL_Complex16 *c, int ldc); +// +static void InitializeConstantMLK_Complex16(MKL_Complex16 *x_clx, const int _n, const double c); +static void InitializeConstantDouble(double *x_p, const int _n, const double c); + + + +TSgensys *CreateTSgensys(TFlinratexp *func, const int _n, const int _m, const int _k, const double div) +{ + //_n is the number of stacked variables (endogenous, Lagurangian multiplier, expected multiplier, etc.). + //_m is the number of exogenous shocks. + //_k is the number of expectational errors. + //div is the dividing number to determine what constitutes an unstable root. If div<1.0, a div>1.0 is calculated mechanically. + TSgensys *gensys_ps = tzMalloc(1, TSgensys); + + //=== Output arguments. + gensys_ps->Theta_dm = CreateMatrix_lf(_n, _n); //n-by-n. + gensys_ps->c_dv = CreateVector_lf(_n); //n-by-1. + gensys_ps->Impact_dm = CreateMatrix_lf(_n, _m); //n-by-m. + gensys_ps->Fmat_dzm = (TSdzmatrix *)NULL; //nunstab-by-nunstab z matrix. Initialized to NULL and will be dynamically allocated whenever gensys() is called. + gensys_ps->Fwt_dzm = (TSdzmatrix *)NULL; //nunstab-by-m z matrix of possible complex numbers. Initialized to NULL and dynamically allocated. + gensys_ps->Ywt_dzm = (TSdzmatrix *)NULL; //n-by-nunstab z matrix of possible complex numbers. Initialized to NULL and dynamically allocated. + gensys_ps->Gev_dzm = CreateMatrix_dz(_n, 2); //n-by-2 z matrix of possible complex numbers. + gensys_ps->eu_dv = CreateConstantVector_lf(2, 0.0); //2-by-1. + + //=== Function itself. + gensys_ps->gensys = func; + + //=== Input arguments. + gensys_ps->G0_dm = CreateConstantMatrix_lf(_n, _n, 0.0); //n-by-n. + gensys_ps->G0_dm->flag = M_GE; + gensys_ps->G1_dm = CreateConstantMatrix_lf(_n, _n, 0.0); //n-by-n. + gensys_ps->G1_dm->flag = M_GE; + gensys_ps->c0_dv = CreateConstantVector_lf(_n, 0.0); //n-by-1. + gensys_ps->Psi_dm = CreateConstantMatrix_lf(_n, _m, 0.0); //n-by-m. + gensys_ps->Psi_dm->flag = M_GE; + gensys_ps->Pi_dm = CreateConstantMatrix_lf(_n, _k, 0.0); //n-by-k where k is the number of expectational errors. + gensys_ps->Pi_dm->flag = M_GE; + gensys_ps->div = div; + + return (gensys_ps); +} +//------- +TSgensys *DestroyTSgensys(TSgensys *gensys_ps) +{ + if (gensys_ps) { + //=== Output arguments. + DestroyMatrix_lf(gensys_ps->Theta_dm); //n-by-n. + DestroyVector_lf(gensys_ps->c_dv); //n-by-1. + DestroyMatrix_lf(gensys_ps->Impact_dm); //n-by-m. + DestroyMatrix_dz(gensys_ps->Fmat_dzm); //nunstab-by-nunstab z matrix. Initialized to NULL and will be dynamically allocated whenever gensys() is called. + DestroyMatrix_dz(gensys_ps->Fwt_dzm); //nunstab-by-m z matrix of possible complex numbers. Initialized to NULL and dynamically allocated. + DestroyMatrix_dz(gensys_ps->Ywt_dzm); //n-by-nunstab z matrix of possible complex numbers. Initialized to NULL and dynamically allocated. + DestroyMatrix_dz(gensys_ps->Gev_dzm); //n-by-2 z matrix of possible complex numbers. + DestroyVector_lf(gensys_ps->eu_dv); //2-by-1. + + //=== Input arguments. + DestroyMatrix_lf(gensys_ps->G0_dm); //n-by-n. + DestroyMatrix_lf(gensys_ps->G1_dm); //n-by-n. + DestroyVector_lf(gensys_ps->c0_dv); //n-by-1. + DestroyMatrix_lf(gensys_ps->Psi_dm); //n-by-m. + DestroyMatrix_lf(gensys_ps->Pi_dm); //n-by-k where k is the number of expectational errors. + + free(gensys_ps); + + return ((TSgensys *)NULL); + } + else return (gensys_ps); +} + + +//--------------------------- For the function gensys_sims() ------------------------------------ +static int fixdiv = 1, zxz = 0; +static double stake = 1.01; +static int nunstab = 0; +static MKL_Complex16 one, minusone, zero; + +/* [G1,C,impact,fmat,fwt,ywt,gev,eu]=gensysmkl(g0,g1,c,psi,pi,stake) */ +//void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { +void gensys_sims(TSgensys *gensys_ps, void *dummy_ps) +{ + int tmpi; + int n, psin, pin, nsquare, md, mds, md1, i, bigev, bigevs, bigev1; + double *eu; + int exist = 0, existx = 0, unique = 0; + //=== Memory will be allocated to the following. + double *deta = NULL, *dz = NULL, *normx = NULL, *deta1 = NULL, *norm = NULL; + MKL_Complex16 *a = NULL, *b = NULL, *q = NULL, *z = NULL, *pi = NULL, *psi = NULL; + MKL_Complex16 *tmat = NULL, *g0 = NULL, *g1 = NULL, *dummy = NULL, *tmatq = NULL, *c = NULL, *impact = NULL, *ab = NULL; + MKL_Complex16 *fmat = NULL, *fwt = NULL, *ywt = NULL; + MKL_Complex16 *etawt = NULL, *ueta = NULL, *veta = NULL, *zwt = NULL, *uz = NULL, *vz = NULL, *etawt1 = NULL, *ueta1 = NULL, *veta1 = NULL; + +// /* Check for proper number of input and output arguments */ +// if (nrhs < 5 || nrhs > 6) +// mexErrMsgTxt("Five or six input arguments required.\n"); +// if (nlhs != 8) +// mexErrMsgTxt("Eight output arguments required.\n"); + +// /* Dimensions */ +// n = mxGetM(prhs[0]); +// psin = mxGetN(prhs[3]); +// pin = mxGetN(prhs[4]); + n = gensys_ps->G0_dm->nrows; + psin = gensys_ps->Psi_dm->ncols; + pin = gensys_ps->Pi_dm->ncols; + // + eu = gensys_ps->eu_dv->v; + //eu = mxGetPr(plhs[7]=mxCreateDoubleMatrix(2,1,mxREAL)); + +// /* Check for consistency of input matrix dimensions */ +// if (mxGetM(prhs[0])!=n || mxGetM(prhs[1])!=n) +// mexErrMsgTxt("g0 and g1 must be square matrices.\n"); + +// if (mxGetM(prhs[3])!=n || mxGetM(prhs[4])!=n) +// mexErrMsgTxt("psi and pi must have the same number of rows as g0.\n"); + +// eu = mxGetPr(plhs[7]=mxCreateDoubleMatrix(2,1,mxREAL)); + + //=== [a b q z]=qz(g0,g1); +// a = mat2mkl(prhs[0],n,n); +// b = mat2mkl(prhs[1],n,n); +// q = mxCalloc(n*n,sizeof(MKL_Complex16)); +// z = mxCalloc(n*n,sizeof(MKL_Complex16)); + a = CreateComplexMatrix5RealMatrix(gensys_ps->G0_dm); + b = CreateComplexMatrix5RealMatrix(gensys_ps->G1_dm); + q = tzMalloc(nsquare=square(n), MKL_Complex16); + z = tzMalloc(nsquare, MKL_Complex16); + InitializeConstantMLK_Complex16(q, nsquare, 0.0); + InitializeConstantMLK_Complex16(z, nsquare, 0.0); + +// fixdiv = nrhs != 6; +// stake = fixdiv ? 1.01 : mxGetScalar(prhs[5]); + fixdiv = (gensys_ps->div < 1.0); + stake = fixdiv ? 1.01 : gensys_ps->div; + nunstab = 0; + zxz = 0; + + if (qz(a, b, q, z, n)) { + printf("WARNING: QZ factorization failed.\n"); + tzDestroy(a); + tzDestroy(b); + tzDestroy(q); + tzDestroy(z); + return; + } + + nunstab /= 2; + + if (zxz) { + printf("WARNING: Coincident zeros. Indeterminacy and/or nonexistence.\n"); + eu[0] = eu[1] = -2.0; + tzDestroy(a); + tzDestroy(b); + tzDestroy(q); + tzDestroy(z); + return; + } + +// plhs[6] = mxCreateDoubleMatrix(n, 2, mxCOMPLEX); //For Gev_dzm. +// copy_eigenvalues(plhs[6], a, b, n); + copy_eigenvalues(gensys_ps->Gev_dzm, a, b); + + one.real = 1.0; + one.imag = 0.0; + + minusone.real = -1.0; + minusone.imag = 0.0; + + zero.real = 0.0; + zero.imag = 0.0; + +// pi = mat2mkl(prhs[4],n,pin); +// etawt = mxCalloc(nunstab*pin,sizeof(MKL_Complex16)); + pi = CreateComplexMatrix5RealMatrix(gensys_ps->Pi_dm); + etawt = tzMalloc(tmpi=nunstab*pin, MKL_Complex16); + InitializeConstantMLK_Complex16(etawt, tmpi, 0.0); //Must be initialized to 0.0 in order to have legal values of this pointer. + cblas_zgemm(CblasColMajor, CblasConjTrans, CblasNoTrans, nunstab, pin, n, + &one, q+n*(n-nunstab), n, pi, n, &zero, etawt, nunstab); + if (compute_svd(etawt, &ueta, &deta, &veta, nunstab, pin)) { + //Memory is now allocated to ueta, deta, and veta. + printf("WARNING: SVD failed.\n"); + tzDestroy(ueta); + tzDestroy(deta); + tzDestroy(veta); + tzDestroy(etawt); + tzDestroy(a); + tzDestroy(b); + tzDestroy(q); + tzDestroy(z); + return; + } + tzDestroy(etawt); + md = nunstab<pin?nunstab:pin; + bigev = md; + for (i=0; i<md; i++) + if (deta[i]<=REALSMALL) { + bigev=i; + break; + } + +// psi = mat2mkl(prhs[3],n,psin); +// zwt = mxCalloc(nunstab*psin,sizeof(MKL_Complex16)); + psi = CreateComplexMatrix5RealMatrix(gensys_ps->Psi_dm); + zwt = tzMalloc(tmpi=nunstab*psin, MKL_Complex16); + InitializeConstantMLK_Complex16(zwt, tmpi, 0.0); //Must be initialized to 0.0 in order to have legal values of this pointer. + cblas_zgemm(CblasColMajor, CblasConjTrans, CblasNoTrans, nunstab, psin, n, + &one, q+n*(n-nunstab), n, psi, n, &zero, zwt, nunstab); + if (compute_svd(zwt, &uz, &dz, &vz, nunstab, psin)) { + //Memory is now allocated to uz, dz, and vz. + printf("WARNING: SV decomposition failed.\n"); + tzDestroy(ueta); + tzDestroy(deta); + tzDestroy(veta); + tzDestroy(uz); + tzDestroy(dz); + tzDestroy(vz); + tzDestroy(zwt); + tzDestroy(a); + tzDestroy(b); + tzDestroy(q); + tzDestroy(z); + return; + } + tzDestroy(vz); + mds = nunstab<psin?nunstab:psin; + bigevs = mds; + for (i=0; i<mds; i++) + if (dz[i]<=REALSMALL) { + bigevs=i; + break; + } + tzDestroy(dz); + + + /* ueta = nunstab x bigev + deta = bigev x 1 + veta = bigev x pin, ldveta = md + uz = nunstab x bigevs + dz = bigevs x 1 + vz = bigevs x psin, ldvz = mds */ + + if (!bigevs) { + exist = 1; + existx = 1; + } else { + /* uz-ueta*ueta'*uz */ + MKL_Complex16 *tmp = tzMalloc(tmpi=nunstab*nunstab, MKL_Complex16); + InitializeConstantMLK_Complex16(tmp, tmpi, 0.0); //Must be initialized to 0.0 in order to have legal values of this pointer. + cblas_zgemm(CblasColMajor, CblasNoTrans, CblasConjTrans, nunstab, nunstab, + bigev, &one, ueta, nunstab, ueta, nunstab, &zero, tmp, nunstab); + cblas_zhemm(CblasColMajor, CblasLeft, CblasUpper, nunstab, + bigevs, &minusone, tmp, nunstab, uz, nunstab, &one, uz, nunstab); + tzDestroy(tmp); + if (compute_norm(uz, &norm, nunstab, bigevs)) { + //Memory is now allocated to norm. + printf("WARNING: SVD failed.\n"); + tzDestroy(norm); + tzDestroy(ueta); + tzDestroy(deta); + tzDestroy(veta); + tzDestroy(uz); + tzDestroy(zwt); + tzDestroy(a); + tzDestroy(b); + tzDestroy(q); + tzDestroy(z); + return; + } + exist = *norm < REALSMALL*n; + tzDestroy(norm); + if (compute_normx(a, b, zwt, ueta, &normx, nunstab, psin, n, bigev)) { + //If 0, memory is now allocated to normx; otherwise, normx is destroyed within the function compute_normx(). + tzDestroy(ueta); + tzDestroy(deta); + tzDestroy(veta); + tzDestroy(uz); + tzDestroy(zwt); + tzDestroy(a); + tzDestroy(b); + tzDestroy(q); + tzDestroy(z); + return; + } + existx = *normx < REALSMALL*n; + tzDestroy(normx); + } + + tzDestroy(uz); + tzDestroy(zwt); + + +/* Note that existence and uniqueness are not just matters of comparing + numbers of roots and numbers of endogenous errors. These counts are + reported below because usually they point to the source of the problem. */ + + etawt1 = tzMalloc(tmpi=(n-nunstab)*pin, MKL_Complex16); + InitializeConstantMLK_Complex16(etawt1, tmpi, 0.0); //Must be initialized to 0.0 in order to have legal values of this pointer. + cblas_zgemm(CblasColMajor, CblasConjTrans, CblasNoTrans, n-nunstab, pin, n, + &one, q, n, pi, n, &zero, etawt1, n-nunstab); + tzDestroy(pi); + if (compute_svd(etawt1, &ueta1, &deta1, &veta1, n-nunstab, pin)) { + //Memory is now allocated to ueta1, deta1, and veta1. + printf("WARNING: SVD failed for compute_svd().\n"); + tzDestroy(ueta1); + tzDestroy(deta1); + tzDestroy(veta1); + tzDestroy(etawt1); + tzDestroy(ueta); + tzDestroy(deta); + tzDestroy(veta); + tzDestroy(a); + tzDestroy(b); + tzDestroy(q); + tzDestroy(z); + return; + } + tzDestroy(etawt1); + md1 = n-nunstab<pin?n-nunstab:pin; + bigev1 = md1; + for (i=0; i<md1; i++) + if (deta1[i]<=REALSMALL) { + bigev1=i; + break; + } + /* ueta1 = n-nunstab x bigev1 + deta1 = bigev1 x 1 + veta1 = bigev1 x pin, ldveta1 = md1 */ + + if (existx || !nunstab) { + //=== Solution exists. + eu[0] = 1.0; + } else { + if (exist) { + printf("WARNING: Solution exists for unforecastable z only\n"); + eu[0] = -1.0; + } /* else + mexPrintf("No solution. %d unstable roots. %d endog errors.\n",nunstab,bigev1); */ + /* mexPrintf("Generalized eigenvalues\n"); + mexCallMATLAB(0,NULL,1, &plhs[6], "disp"); */ + } + if (!bigev1) + unique = 1; + else { + /* veta1-veta1*veta*veta' */ + /* veta = bigev x pin, ldveta1 = md + veta1 = bigev1 x pin, ldveta1 = md1 */ + MKL_Complex16 *tmp = tzMalloc(pin*pin, MKL_Complex16); + MKL_Complex16 *veta1_copy = tzMalloc(pin*bigev1, MKL_Complex16); + InitializeConstantMLK_Complex16(tmp, pin*pin, 0.0); //Must be initialized to 0.0 in order to have legal values of this pointer. + InitializeConstantMLK_Complex16(veta1_copy, pin*bigev1, 0.0); //Must be initialized to 0.0 in order to have legal values of this pointer. + cblas_zgemm(CblasColMajor, CblasConjTrans, CblasNoTrans, pin, pin, + bigev, &one, veta, md, veta, md, &zero, tmp, pin); + cblas_zdupe(bigev1,pin,veta1,md1,veta1_copy,bigev1); + cblas_zhemm(CblasColMajor, CblasRight, CblasUpper, bigev1, pin, + &minusone, tmp, pin, veta1_copy, bigev1, &one, veta1_copy, bigev1); + tzDestroy(tmp); + if (compute_norm(veta1_copy, &norm, bigev1, pin)) { + //Memory is now allocated to norm. + printf("WARNING: SVD failed.\n"); + tzDestroy(norm); + tzDestroy(ueta1); + tzDestroy(deta1); + tzDestroy(veta1); + tzDestroy(ueta); + tzDestroy(deta); + tzDestroy(veta); + tzDestroy(veta1_copy); + tzDestroy(a); + tzDestroy(b); + tzDestroy(q); + tzDestroy(z); + return; + } + tzDestroy(veta1_copy); + unique = *norm < REALSMALL*n; + tzDestroy(norm); + } + if (unique) { + //=== Unique solution. + eu[1] = 1.0; + } else { + eu[1] = 0.0; + printf("WARNING: Indeterminacy. %d loose endog errors with eu being [%g, %g].\n",bigev1-bigev, eu[0], eu[1]); + //printf("WARNING: Indeterminacy. %d loose endog errors with eu being [%g, %g].\n",bigev1-bigev, gensys_ps->eu_dv->v[0], gensys_ps->eu_dv->v[1]); + //printf("WARNING: Indeterminacy. %d loose endog errors.\n",bigev1-bigev); + /* mexPrintf("Generalized eigenvalues\n"); + mexCallMATLAB(0,NULL,1, &plhs[6], "disp"); */ + } + + cblas_zdscali(pin,deta,bigev,veta,md); /* veta' = deta\veta' */ + tzDestroy(deta); + cblas_zdscale(pin,deta1,bigev1,veta1,md1); /* veta1' = deta1*veta1' */ + tzDestroy(deta1); + etawt = tzMalloc(tmpi=nunstab*pin, MKL_Complex16); /* etawt = ueta*veta' */ + InitializeConstantMLK_Complex16(etawt, tmpi, 0.0); //Must be initialized to 0.0 in order to have legal values of this pointer. + cblas_zgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, nunstab, pin, bigev, + &one, ueta, nunstab, veta, md, &zero, etawt, nunstab); + tzDestroy(ueta); + tzDestroy(veta); + etawt1 = tzMalloc(tmpi=(n-nunstab)*pin, MKL_Complex16); /* etawt1 = ueta1*veta1' */ + InitializeConstantMLK_Complex16(etawt1, tmpi, 0.0); //Must be initialized to 0.0 in order to have legal values of this pointer. + cblas_zgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, n-nunstab, pin, bigev1, + &one, ueta1, n-nunstab, veta1, md1, &zero, etawt1, n-nunstab); + tzDestroy(ueta1); + tzDestroy(veta1); + tmat = tzMalloc(tmpi=(n-nunstab)*nunstab, MKL_Complex16); /* tmat = etawt1*etawt' */ + InitializeConstantMLK_Complex16(tmat, tmpi, 0.0); //Must be initialized to 0.0 in order to have legal values of this pointer. + cblas_zgemm(CblasColMajor, CblasNoTrans, CblasConjTrans, n-nunstab, nunstab, pin, + &one, etawt1, n-nunstab, etawt, nunstab, &zero, tmat, n-nunstab); + tzDestroy(etawt1); + tzDestroy(etawt); + + g0 = tzMalloc(tmpi=n*n, MKL_Complex16); + InitializeConstantMLK_Complex16(g0, tmpi, 0.0); //Must be initialized to 0.0 in order to have legal values of this pointer. + cblas_zdupe(n-nunstab, n, a, n, g0, n); + cblas_zgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, n-nunstab, nunstab, nunstab, + &minusone, tmat, n-nunstab, a+(n-nunstab)*(n+1), n, &one, g0+(n-nunstab)*n, n); + cblas_zcopy(nunstab, &one, 0, g0+(n-nunstab)*(n+1), n+1); + + g1 = tzMalloc(tmpi=n*n, MKL_Complex16); + InitializeConstantMLK_Complex16(g1, tmpi, 0.0); //Must be initialized to 0.0 in order to have legal values of this pointer. + cblas_zdupe(n-nunstab, n, b, n, g1, n); + cblas_zgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, n-nunstab, nunstab, nunstab, + &minusone, tmat, n-nunstab, b+(n-nunstab)*(n+1), n, &one, g1+(n-nunstab)*n, n); + cblas_ztrsm(CblasColMajor, CblasLeft, CblasUpper, CblasNoTrans, CblasNonUnit, + n, n, &one, g0, n, g1, n); + dummy = tzMalloc(tmpi=n*n, MKL_Complex16); + InitializeConstantMLK_Complex16(dummy, tmpi, 0.0); //Must be initialized to 0.0 in order to have legal values of this pointer. + cblas_zgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, n, n, n, &one, z, n, g1, n, &zero, dummy, n); + cblas_zgemm(CblasColMajor, CblasNoTrans, CblasConjTrans, n, n, n, &one, dummy, n, z, n, &zero, g1, n); + tzDestroy(dummy); + //plhs[0] = mkl2mat_real(g1, n, n, n); + ComplexMatrix2RealMatrix(gensys_ps->Theta_dm, g1); //Output. + tzDestroy(g1); + + tmatq = tzMalloc(tmpi=n*n, MKL_Complex16); + InitializeConstantMLK_Complex16(tmatq, tmpi, 0.0); //Must be initialized to 0.0 in order to have legal values of this pointer. + cblas_zcopy(n*n, q, 1, tmatq, 1); + cblas_zgemm(CblasColMajor, CblasNoTrans, CblasConjTrans, n, n-nunstab, nunstab, + &minusone, tmatq+(n-nunstab)*n, n, tmat, n-nunstab, &one, tmatq, n); + tzDestroy(tmat); + + ab = tzMalloc(tmpi=nunstab*nunstab, MKL_Complex16); + InitializeConstantMLK_Complex16(ab, tmpi, 0.0); //Must be initialized to 0.0 in order to have legal values of this pointer. + cblas_zdpsb(nunstab, nunstab, a+(n-nunstab)*(n+1), n, b+(n-nunstab)*(n+1), n, ab, nunstab); + cblas_ztrsm(CblasColMajor, CblasRight, CblasUpper, CblasConjTrans, CblasNonUnit, + n, nunstab, &one, ab, nunstab, tmatq+(n-nunstab)*n, n); + tzDestroy(ab); + + //c = mat2mkl(prhs[2],n,1); + c = CreateComplexMatrix5RealVector(gensys_ps->c0_dv); + dummy = tzMalloc(gensys_ps->c0_dv->n, MKL_Complex16); + //$$$$$$$ The following is Iskander's fatal code error. One cannot use c in the two different places; otherwise, it makes c be zero completely! + // cblas_zgemv(CblasColMajor, CblasConjTrans, n, n, &one, tmatq, n, c, 1, &zero, c, 1); + // cblas_ztrsv(CblasColMajor, CblasUpper, CblasNoTrans, CblasNonUnit, n, g0, n, c, 1); + // cblas_zgemv(CblasColMajor, CblasNoTrans, n, n, &one, z, n, c, 1, &zero, c, 1); + cblas_zgemv(CblasColMajor, CblasConjTrans, n, n, &one, tmatq, n, c, 1, &zero, dummy, 1); + cblas_ztrsv(CblasColMajor, CblasUpper, CblasNoTrans, CblasNonUnit, n, g0, n, dummy, 1); + cblas_zgemv(CblasColMajor, CblasNoTrans, n, n, &one, z, n, dummy, 1, &zero, c, 1); + //plhs[1] = mkl2mat_real(c, n, n, 1); + ComplexMatrix2RealVector(gensys_ps->c_dv, c); //Output. + tzDestroy(c); + tzDestroy(dummy); + + impact = tzMalloc(tmpi=n*psin, MKL_Complex16); + InitializeConstantMLK_Complex16(impact, tmpi, 0.0); //Must be initialized to 0.0 in order to have legal values of this pointer. + cblas_zgemm(CblasColMajor, CblasConjTrans, CblasNoTrans, n-nunstab, psin, n, + &one, tmatq, n, psi, n, &zero, impact, n); + tzDestroy(tmatq); + cblas_ztrsm(CblasColMajor, CblasLeft, CblasUpper, CblasNoTrans, CblasNonUnit, + n, psin, &one, g0, n, impact, n); + dummy = tzMalloc(tmpi=n*psin, MKL_Complex16); + InitializeConstantMLK_Complex16(dummy, tmpi, 0.0); //Must be initialized to 0.0 in order to have legal values of this pointer. + cblas_zgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, n, psin, n, + &one, z, n, impact, n, &zero, dummy, n); + tzDestroy(impact); + //plhs[2] = mkl2mat_real(dummy, n, n, psin); + ComplexMatrix2RealMatrix(gensys_ps->Impact_dm, dummy); //Output. + tzDestroy(dummy); + + fmat = a+(n-nunstab)*(n+1); + cblas_ztrsm(CblasColMajor, CblasLeft, CblasUpper, CblasNoTrans, CblasNonUnit, + nunstab, nunstab, &one, b+(n-nunstab)*(n+1), n, fmat, n); + //plhs[3] = mkl2mat(fmat, n, nunstab, nunstab); + gensys_ps->Fmat_dzm = SubComplexMatrix2Zmatrix(gensys_ps->Fmat_dzm, fmat, n, nunstab, nunstab); + tzDestroy(a); + + fwt = tzMalloc(tmpi=nunstab*psin, MKL_Complex16); + InitializeConstantMLK_Complex16(fwt, tmpi, 0.0); //Must be initialized to 0.0 in order to have legal values of this pointer. + cblas_ztrsm(CblasColMajor, CblasRight, CblasUpper, CblasConjTrans, CblasNonUnit, + n, nunstab, &one, b+(n-nunstab)*(n+1), n, q+(n-nunstab)*n, n); + tzDestroy(b); + cblas_zgemm(CblasColMajor, CblasConjTrans, CblasNoTrans, nunstab, psin, n, + &minusone, q+(n-nunstab)*n, n, psi, n, &zero, fwt, nunstab); + tzDestroy(q); + tzDestroy(psi); + //plhs[4] = mkl2mat(fwt, nunstab, nunstab, psin); + gensys_ps->Fwt_dzm = SubComplexMatrix2Zmatrix(gensys_ps->Fwt_dzm, fwt, nunstab, nunstab, psin); + tzDestroy(fwt); + + ywt = tzMalloc(tmpi=n*nunstab, MKL_Complex16); + InitializeConstantMLK_Complex16(ywt, tmpi, 0.0); + cblas_zcopy(nunstab, &one, 0, ywt+n-nunstab, n+1); + cblas_ztrsm(CblasColMajor, CblasLeft, CblasUpper, CblasNoTrans, CblasNonUnit, + n, nunstab, &one, g0, n, ywt, n); + tzDestroy(g0); + dummy = tzMalloc(tmpi=n*nunstab, MKL_Complex16); + InitializeConstantMLK_Complex16(dummy, tmpi, 0.0); //Must be initialized to 0.0 in order to have legal values of this pointer. + cblas_zgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, n, nunstab, n, + &one, z, n, ywt, n, &zero, dummy, n); + tzDestroy(z); + tzDestroy(ywt); + //plhs[5] = mkl2mat(dummy, n, n, nunstab); + gensys_ps->Ywt_dzm = SubComplexMatrix2Zmatrix(gensys_ps->Ywt_dzm, dummy, n, n, nunstab); + tzDestroy(dummy); +} + + +/****************************************************************************** + * function selctg orders the eigenvalues so that a selected cluster of * + * eigenvalues appears in the leading diagonal blocks of the upper * + * quasi-triangular matrix S and the upper triangular matrix T. * + ******************************************************************************/ + +static int selctg(MKL_Complex16 *alpha, MKL_Complex16 *beta) +{ + double absA = sqrt(alpha->real*alpha->real+alpha->imag*alpha->imag), + absB = fabs(beta->real); + if (absA) { + double divhat = absB/absA; + //bug detected by Vasco Curdia and Daria Finocchiaro, 2/25/2004 CAS. A root of + //exactly 1.01 and no root between 1 and 1.02, led to div being stuck at 1.01 + //and the 1.01 root being misclassified as stable. Changing < to <= below fixes this. + if (fixdiv && 1+REALSMALL<divhat && divhat<=stake) + stake = (1+divhat)/2; + } + if (absA<REALSMALL && absB<REALSMALL) + zxz = 1; + if (absB>stake*absA) { + nunstab++; + return(0); + } else + return(1); +} + +/****************************************************************************** + * compute for a pair of N-by-N complex nonsymmetric matrices (A,B), * + * the generalized eigenvalues, the generalized complex Schur form (S, T), * + * and optionally left and/or right Schur vectors (VSL and VSR) * + ******************************************************************************/ + +static int qz(MKL_Complex16 *a, MKL_Complex16 *b, MKL_Complex16 *q, MKL_Complex16 *z, int n) +{ +// unsigned char msg[101]; + int sdim, lwork = -1, info = 0; + MKL_Complex16 *alpha = tzMalloc(n,MKL_Complex16), + *beta = tzMalloc(n,MKL_Complex16), + *work, work1; + double *rwork = tzMalloc(8*n, double); + int *bwork = tzMalloc(4*n, int); + + /* Query zgges on the value of lwork */ + zgges("V", "V", "S", &selctg, &n, a, &n, b, &n, &sdim, alpha, beta, q, + &n, z, &n, &work1, &lwork, rwork, bwork, &info); + + if (info < 0) { + printf("WARNING: Input %d to the Intel MKL function zgges() has an illegal value",-info); + tzDestroy(bwork); + tzDestroy(rwork); + tzDestroy(alpha); + tzDestroy(beta); + return(info); + } + + lwork = (int)(work1.real); + work = tzMalloc(lwork, MKL_Complex16); + zgges("V", "V", "S", &selctg, &n, a, &n, b, &n, &sdim, alpha, beta, q, + &n, z, &n, work, &lwork, rwork, bwork, &info); + + tzDestroy(work); + tzDestroy(bwork); + tzDestroy(rwork); + tzDestroy(alpha); + tzDestroy(beta); + + if (info < 0) { + printf("WARNING: Input %d to the Intel MKL function zgges() has an illegal value",-info); + return(info); + } + + if (info > 0) + if (info < n) + printf("WARNING: The QZ iteration failed. (A,B) are not in Schur form,\n" + "but ALPHA(j) and BETA(j) should be correct for j=%d,...,N.",info+1); + else { + switch (info-n) { + case 1: + printf("WARNING: LAPACK problem: error return from ZGGBAL"); + break; + case 2: + printf("WARNING: LAPACK problem: error return from ZGEQRF"); + break; + case 3: + printf("WARNING: LAPACK problem: error return from ZUNMQR"); + break; + case 4: + printf("WARNING: LAPACK problem: error return from ZUNGQR"); + break; + case 5: + printf("WARNING: LAPACK problem: error return from ZGGHRD"); + break; + case 6: + printf("WARNING: LAPACK problem: error return from ZHGEQZ (other than failed iteration)"); + break; + case 7: + printf("WARNING: LAPACK problem: error return from ZGGBAK (computing VSL)"); + break; + case 8: + printf("WARNING: LAPACK problem: error return from ZGGBAK (computing VSR)"); + break; + case 9: + printf("WARNING: LAPACK problem: error return from ZLASCL (various places)"); + break; + default: + printf("WARNING: LAPACK problem: unknown error."); + break; + } + } + return(info); +} + +/* + * Convert MATLAB complex matrix to MKL complex storage. + * + * Z = mat2mkl(X,ldz,ndz) + * + * converts MATLAB's mxArray X to MKL_Complex16 Z(ldz,ndz). + * The parameters ldz and ndz determine the storage allocated for Z, + * while mxGetM(X) and mxGetN(X) determine the amount of data copied. + */ + +//MKL_Complex16* mat2mkl(const mxArray *X, int ldz, int ndz) { +// MKL_Complex16 *Z, *zp; +// int m, n, incz, cmplxflag; +// register int i, j; +// double *xr, *xi; + +// Z = mxCalloc(ldz*ndz, sizeof(MKL_Complex16)); +// xr = mxGetPr(X); +// xi = mxGetPi(X); +// m = mxGetM(X); +// n = mxGetN(X); +// zp = Z; +// incz = ldz-m; +// cmplxflag = (xi != NULL); +// for (j = 0; j < n; j++) { +// if (cmplxflag) { +// for (i = 0; i < m; i++) { +// zp->real = *xr++; +// zp->imag = *xi++; +// zp++; +// } +// } else { +// for (i = 0; i < m; i++) { +// zp->real = *xr++; +// zp++; +// } +// } +// zp += incz; +// } +// return(Z); +//} + + +/* + * Convert MKL complex storage to MATLAB real and imaginary parts. + * + * X = mkl2mat(Z,ldz,m,n) + * + * copies MKL_Complex16 Z to X, producing a complex mxArray + * with mxGetM(X) = m and mxGetN(X) = n. + */ + +//mxArray* mkl2mat(MKL_Complex16 *Z, int ldz, int m, int n) { +// int i, j, incz; +// double *xr, *xi; +// MKL_Complex16 *zp; +// mxArray *X; + +// X = mxCreateDoubleMatrix(m,n,mxCOMPLEX); +// xr = mxGetPr(X); +// xi = mxGetPi(X); +// zp = Z; +// incz = ldz-m; +// for (j = 0; j < n; j++) { +// for (i = 0; i < m; i++) { +// *xr++ = zp->real; +// *xi++ = zp->imag; +// zp++; +// } +// zp += incz; +// } +// return(X); +//} + +//plhs[3] = mkl2mat(fmat, n, nunstab, nunstab) + +/* + * Convert MKL complex storage to MATLAB real matrix ignoring imaginary part. + * + * X = mkl2mat(Z,ldz,m,n) + * + * copies MKL_Complex16 Z to X, producing a real mxArray + * with mxGetM(X) = m and mxGetN(X) = n. + */ + +//mxArray* mkl2mat_real(MKL_Complex16 *Z, int ldz, int m, int n) { +// int i, j, incz; +// double *xr; +// MKL_Complex16 *zp; +// mxArray *X; + +// X = mxCreateDoubleMatrix(m,n,mxREAL); +// xr = mxGetPr(X); +// zp = Z; +// incz = ldz-m; +// for (j = 0; j < n; j++) { +// for (i = 0; i < m; i++) { +// *xr++ = zp->real; +// zp++; +// } +// zp += incz; +// } +// return(X); +//} + +//void copy_eigenvalues(mxArray *gev, MKL_Complex16 *a, MKL_Complex16 *b, int n) { +// double *gevr = mxGetPr(gev), +// *gevi = mxGetPi(gev); +// int i; + +// for (i=0; i<n; i++, gevr++, gevi++, a+=n+1) { +// *gevr = a->real; +// *gevi = a->imag; +// } + +// for (i=0; i<n; i++, gevr++, gevi++, b+=n+1) { +// *gevr = b->real; +// *gevi = b->imag; +// } +//} + +static void copy_eigenvalues(TSdzmatrix *Gev_dzm, MKL_Complex16 *a, MKL_Complex16 *b) +{ + int n = Gev_dzm->real->nrows; + double *gevr = Gev_dzm->real->M, + *gevi = Gev_dzm->imag->M; + int i; + + for (i=0; i<n; i++, gevr++, gevi++, a+=n+1) { + *gevr = a->real; + *gevi = a->imag; + } + + for (i=0; i<n; i++, gevr++, gevi++, b+=n+1) { + *gevr = b->real; + *gevi = b->imag; + } +} + + +static int compute_svd(MKL_Complex16 *x, MKL_Complex16 **u, double **d, MKL_Complex16 **v, int m, int n) +{ + //$$$Memory allocated to u, d, and v will be destroyed outside this function.$$$ + int tmpi; + int md = m<n?m:n, lwork = -1, info = 0; + MKL_Complex16 *a, *work, work1; + double *rwork = tzMalloc(5*md>1?5*md:1, double); + + a = tzMalloc(m*n, MKL_Complex16); + cblas_zcopy(m*n, x, 1, a, 1); + + *u = tzMalloc(tmpi=m*md,MKL_Complex16); + InitializeConstantMLK_Complex16(*u, tmpi, 0.0); + *v = tzMalloc(tmpi=md*n, MKL_Complex16); + InitializeConstantMLK_Complex16(*v, tmpi, 0.0); + *d = tzMalloc(md, double); + InitializeConstantDouble(*d, md, 0.0); + + /* Query zgges on the value of lwork */ + zgesvd("S", "S", &m, &n, a, &m, *d, *u, &m, *v, &md, &work1, &lwork, rwork, &info); + + if (info < 0) { + printf("WARNING: Input %d to zgesvd had an illegal value",-info); + tzDestroy(rwork); + return(info); + } + + lwork = (int)(work1.real); + work = tzMalloc(lwork, MKL_Complex16); + zgesvd("S", "S", &m, &n, a, &m, *d, *u, &m, *v, &md, work, &lwork, rwork, &info); + + tzDestroy(work); + tzDestroy(rwork); + tzDestroy(a); + + if (info < 0) + printf("WARNING: Input %d to zgesvd had an illegal value",-info); + + if (info > 0) + printf("WARNING: ZBDSQR did not converge.\n%d superdiagonals of an intermediate " + "bidiagonal form B did not converge to zero.",info); + return(info); +} + +static int compute_norm(MKL_Complex16 *a, double **d, int m, int n) +{ + //Memory will be allocated to d, which will be destroyed outside this function. + int md = m<n?m:n, lwork = -1, info = 0; + MKL_Complex16 *work = NULL, work1; + double *rwork = tzMalloc(5*md>1?5*md:1, double); + + *d = tzMalloc(md, double); + + /* Query zgges on the value of lwork */ + zgesvd("N", "N", &m, &n, a, &m, *d, NULL, &m, NULL, &md, &work1, &lwork, rwork, &info); + + if (info < 0) { + printf("WARNING: Input %d to zgesvd had an illegal value",-info); + tzDestroy(rwork); + return(info); + } + + lwork = (int)(work1.real); + work = tzMalloc(lwork, MKL_Complex16); + zgesvd("N", "N", &m, &n, a, &m, *d, NULL, &m, NULL, &md, work, &lwork, rwork, &info); + + tzDestroy(work); + tzDestroy(rwork); + + if (info < 0) + printf("WARNING: Input %d to zgesvd had an illegal value",-info); + + if (info > 0) + printf("WARNING: ZBDSQR() in Intel MKL did not converge.\n%d superdiagonals of an intermediate " + "bidiagonal form B did not converge to zero.",info); + + return(info); +} + +static int compute_normx(MKL_Complex16 *a, MKL_Complex16 *b, MKL_Complex16 *zwt, MKL_Complex16 *ueta, double **normx, int nunstab, int psin, int n, int bigev) +{ + //Memory is allocated to normx, which will be freed outside this function. + int tmpi; + int info = 0, i, bigevs; + // + MKL_Complex16 *M = NULL, *zwtx = NULL, *ux = NULL, *vx = NULL, *tmp = NULL; + double *dx = NULL; + + + a += (n+1)*(n-nunstab); + b += (n+1)*(n-nunstab); + cblas_ztrsm(CblasColMajor, CblasLeft, CblasUpper, CblasNoTrans, CblasNonUnit, + nunstab, psin, &one, b, n, zwt, nunstab); + M = tzMalloc(nunstab*nunstab, MKL_Complex16); + cblas_zdupe(nunstab, nunstab, a, n, M, nunstab); + cblas_ztrsm(CblasColMajor, CblasLeft, CblasUpper, CblasNoTrans, CblasNonUnit, + nunstab, nunstab, &one, b, n, M, nunstab); + + zwtx = tzMalloc(nunstab*nunstab*psin, MKL_Complex16); + cblas_zcopy(nunstab*psin, zwt, 1, zwtx, 1); + for (i=1; i<nunstab; i++) { + cblas_ztrmm(CblasColMajor, CblasLeft, CblasUpper, CblasNoTrans, CblasNonUnit, nunstab, psin*i, &one, M, nunstab, zwtx, nunstab); + cblas_zcopy(nunstab*psin, zwt, 1, zwtx+nunstab*psin*i, 1); + } + tzDestroy(M); + cblas_ztrmm(CblasColMajor, CblasLeft, CblasUpper, CblasNoTrans, CblasNonUnit, nunstab, nunstab*psin, &one, b, n, zwtx, nunstab); + info = compute_svd(zwtx, &ux, &dx, &vx, nunstab, nunstab*psin); //Memory is allocated to ux, dx, and vx. + tzDestroy(vx); + tzDestroy(zwtx); + if (info) { + printf("WARNING: SVD failed.\n"); + tzDestroy(ux); + tzDestroy(dx); + return(info); + } + bigevs = nunstab; + for (i=0; i<nunstab; i++) + if (dx[i]<=REALSMALL) { + bigevs = i; + break; + } + tzDestroy(dx); + /* ux-ueta*ueta'*ux */ + tmp = tzMalloc(tmpi=nunstab*nunstab, MKL_Complex16); + InitializeConstantMLK_Complex16(tmp, tmpi, 0.0); //Must be initialized to 0.0 in order to have legal values of this pointer. + cblas_zgemm(CblasColMajor, CblasNoTrans, CblasConjTrans, nunstab, nunstab, + bigev, &one, ueta, nunstab, ueta, nunstab, &zero, tmp, nunstab); + cblas_zhemm(CblasColMajor, CblasLeft, CblasUpper, nunstab, + bigevs, &minusone, tmp, nunstab, ux, nunstab, &one, ux, nunstab); + tzDestroy(tmp); + info = compute_norm(ux, normx, nunstab, bigevs); //Memory is allocated to normx. + if (info) { + printf("WARNING: SVD failed.\n"); + tzDestroy(normx); + tzDestroy(ux); + return(info); + } + tzDestroy(ux); + return(info); +} + +static void cblas_zdupe(int m, int n, MKL_Complex16 *a, int lda, MKL_Complex16 *b, int ldb) +{ + int i; + for (i=0; i<m; i++, a++, b++) + cblas_zcopy(n, a, lda, b, ldb); +} + +static void cblas_zdscali(int n, double *a, int lda, MKL_Complex16 *b, int ldb) +{ + int i; + for (i=0; i<lda; i++, a++, b++) + cblas_zdscal(n, 1.0/(*a), b, ldb); +} + +static void cblas_zdscale(int n, double *a, int lda, MKL_Complex16 *b, int ldb) +{ + int i; + for (i=0; i<lda; i++, a++, b++) + cblas_zdscal(n, *a, b, ldb); +} + +static void cblas_zdpsb(int m, int n, MKL_Complex16 *a, int lda, MKL_Complex16 *b, int ldb, MKL_Complex16 *c, int ldc) +{ + int i; + cblas_zdupe(m, n, a, lda, c, ldc); + for (i=0; i<m; i++, b++, c++) + cblas_zaxpy(n, &minusone, b, ldb, c, ldc); +} + + +static MKL_Complex16* CreateComplexMatrix5RealMatrix(TSdmatrix *X_dm) +{ + int mn, k; + double *M; + // + MKL_Complex16 *Z = NULL; + + if (!X_dm) fn_DisplayError("CreateComplexMatrix5RealMatrix(): Input matrix X_dm must be allocated memory"); + M = X_dm->M; + + Z = tzMalloc(mn=X_dm->nrows*X_dm->ncols, MKL_Complex16); + for (k=mn-1; k>=0; k--) { + Z[k].real = M[k]; + Z[k].imag = 0.0; + } + return(Z); +} + +static MKL_Complex16* CreateComplexMatrix5RealVector(TSdvector *x_dv) +{ + int n, k; + double *v; + // + MKL_Complex16 *Z = NULL; + + if (!x_dv) fn_DisplayError("CreateComplexMatrix5RealVector(): Input vector x_dv must be allocated memory"); + v = x_dv->v; + + Z = tzMalloc(n=x_dv->n, MKL_Complex16); + for (k=n-1; k>=0; k--) { + Z[k].real = v[k]; + Z[k].imag = 0.0; + } + return(Z); +} + + +static void ComplexMatrix2RealMatrix(TSdmatrix *Y_dm, MKL_Complex16 *Z) +{ + int _k; + double *M; + + if (!Y_dm) fn_DisplayError("ComplexMatrix2RealMatrix(): Output matrix Y_dm must be allocated memory"); + M = Y_dm->M; + + for (_k=Y_dm->nrows*Y_dm->ncols-1; _k>=0; _k--) M[_k] = Z[_k].real; + Y_dm->flag = M_GE; +} + + +static void ComplexMatrix2RealVector(TSdvector *y_dv, MKL_Complex16 *Z) +{ + int _k; + double *v; + + if (!y_dv) fn_DisplayError("ComplexMatrix2RealVector(): Output matrix y_dv must be allocated memory"); + v = y_dv->v; + + for (_k=y_dv->n-1; _k>=0; _k--) v[_k] = Z[_k].real; + y_dv->flag = V_DEF; +} + + +static TSdzmatrix *SubComplexMatrix2Zmatrix(TSdzmatrix *X_dzm, MKL_Complex16 *Z, const int nrowsforZ, const int _m, const int _n) +{ + //X_dzm is _m-by_n comlex types where nrowsforZ <= _m and Z is nrowsforZ-by-_n. + int _i, _j, incz; + double *Mreal, *Mimag; + MKL_Complex16 *zp; + // + TSdzmatrix *Y_dzm = NULL; + + if (!X_dzm || X_dzm->real->nrows != _m || X_dzm->real->ncols != _n) { + DestroyMatrix_dz(X_dzm); //Destroys Y_dzm if already allocated memory to accommodate a possbible change of its dimension. + Y_dzm = CreateMatrix_dz(_m, _n); + } + else Y_dzm = X_dzm; + + Mreal = Y_dzm->real->M; + Mimag = Y_dzm->imag->M; + zp = Z; + if ((incz=nrowsforZ-_m)<0) fn_DisplayError("SubComplexMatrix2ZMatrix(): Number of rows for the input complex matrix Z must be greater that of the output Z matrix Y_dzm"); + + for (_j=0; _j<_n; _j++) { + for (_i=0; _i<_m; _i++) { + *Mreal++ = zp->real; + *Mimag++ = zp->imag; + zp++; + } + zp += incz; + } + return (Y_dzm); +} + + +static void InitializeConstantMLK_Complex16(MKL_Complex16 *x_clx, const int _n, const double c) +{ + int _i; + + for (_i=_n-1; _i>=0; _i--) + x_clx[_i].real = x_clx[_i].imag = c; +} + +static void InitializeConstantDouble(double *x_p, const int _n, const double c) +{ + int _i; + + for (_i=_n-1; _i>=0; _i--) x_p[_i] = c; +} diff --git a/CFiles/gensysOldVersionWorks.h b/CFiles/gensysOldVersionWorks.h new file mode 100755 index 0000000..9c6b23a --- /dev/null +++ b/CFiles/gensysOldVersionWorks.h @@ -0,0 +1,65 @@ +/******************************************************************* + * [G1,C,impact,fmat,fwt,ywt,gev,eu]=gensys(g0,g1,c,psi,pi,div) + * + * System given as + * g0*y(t)=g1*y(t-1)+c+psi*z(t)+pi*eta(t), + * with z an exogenous variable process and eta being endogenously determined + * one-step-ahead expectational errors. Returned system is + * y(t)=G1*y(t-1)+C+impact*z(t)+ywt*inv(I-fmat*inv(L))*fwt*z(t+1) . + * If z(t) is i.i.d., the last term drops out. + * If div or stake is omitted from argument list, a div>1 or stake>1 is calculated. + * eu(1)=1 for existence, eu(2)=1 for uniqueness. eu(1)=-1 for + * existence only with not-serially correlated z(t); eu=[-2,-2] for coincident zeros. + * + * g0, g1: n-by-n matrices. + * c: n-by-1 constant terms. + * z(t): m-by-1 vector of exogenous residuals where m < n. + * psi: n-by-m matrix. + * eta(t): h-by-1 vector of expectational (endogenous) errors. + * pi: n-by-h matrix. + * div: a real number dividing stable and unstable roots.. If < 1.0, a div>1.0 is calculated mechanically. + *------- + * G1 or Theta_dm: n-by-n matrices. + * C: n-by-1 vector of constant terms. + * impact: n-by-m matrix. + * gev: n-by-2 z vector of stacked generalized eigenvalues where gev(;,2) ./ gev(:,1) = eig(g0, g1). + * ywt: n-by-nunstab z matrix of possible complex numbers. Initialized to NULL and dynamically allocated. + * fmat: nunstab-by-nunstab z matrix where nunstab is the number of non-stable roots. + * fwt: nunstab-by-m z matrix. +********************************************************************/ + +#ifndef __GENSYS_H__ + #define __GENSYS_H__ + + #include "tzmatlab.h" + + #define REALSMALL 1e-7 + + typedef struct TSgensys_tag { + //=== Output arguments. + TSdmatrix *Theta_dm; //n-by-n. + TSdvector *c_dv; //n-by-1. + TSdmatrix *Impact_dm; //n-by-m. + TSdzmatrix *Fmat_dzm; //nunstab-by-nunstab z matrix. Initialized to NULL and will be dynamically allocated whenever gensys() is called. + TSdzmatrix *Fwt_dzm; //nunstab-by-m z matrix of possible complex numbers. Initialized to NULL and dynamically allocated. + TSdzmatrix *Ywt_dzm; //n-by-nunstab z matrix of possible complex numbers. Initialized to NULL and dynamically allocated. + TSdzmatrix *Gev_dzm; //n-by-2 z matrix of possible complex numbers. + TSdvector *eu_dv; //2-by-1. + //=== Function itself. + void (*gensys)(struct TSgensys_tag *, void *); + //=== Input arguments, which are all intialized to 0.0 and whose flags are set to M_GE. + TSdmatrix *G0_dm; //n-by-n. + TSdmatrix *G1_dm; //n-by-n. + TSdvector *c0_dv; //n-by-1. + TSdmatrix *Psi_dm; //n-by-m. + TSdmatrix *Pi_dm; //n-by-k whtere k is the number of expectational errors. + double div; //A real number dividing stable and unstable roots.. If < 1.0, a div>1.0 is calculated mechanically. + } TSgensys; + // + typedef void TFlinratexp(struct TSgensys_tag *, void *); //For linear rational expectations models. + + struct TSgensys_tag *CreateTSgensys(TFlinratexp *func, const int _n, const int _m, const int _k, const double div); + struct TSgensys_tag *DestroyTSgensys(struct TSgensys_tag *gensys_ps); + void gensys_sims(struct TSgensys_tag *gensys_ps, void *dummy_ps); +#endif + diff --git a/CFiles/gradcd_switch.c b/CFiles/gradcd_switch.c new file mode 100755 index 0000000..95c4179 --- /dev/null +++ b/CFiles/gradcd_switch.c @@ -0,0 +1,202 @@ + +#include "gradcd_switch.h" +//#include "dw_array.h" +//#include "m_array.h" +//#include "dw_error.h" +//#include "dw_rand.h" + +#include <math.h> +#include <string.h> + + +/* + Assumes: + model is a pointer to a properly initialized TStateModel. +*/ +double logTimetLHgivenparameters(TStateModel *model, TSdvector *x_dv, int nmodelpars, int endt_base1) +{ + //void *model is TStateModel *model + //endt_base1: base-1 t. + int s, t; + double logvalue; + PRECISION scale, u; + TMarkovStateVariable *sv=model->sv; + + //--- Added by Zha. + if (endt_base1 < 1 || endt_base1 > sv->nobs) + { + printf("gradcd_switch.c/logLHgivenparameters_time_t(): Input endt_base1 must be between 1 and T.\n"); + exit(EXIT_FAILURE); + } + if (nmodelpars > x_dv->n) + { + printf("gradcd_switch.c/logLHgivenparameters_time_t(): Number of model parameters, nmodelpars, must be <= x_dv->n.\n"); + exit(EXIT_FAILURE); + } + ConvertFreeParametersToQ(model, x_dv->v + nmodelpars); + ConvertFreeParametersToTheta(model,x_dv->v); + + + + //====== Initializes prior to forward recursion if necessary ====== + if (model->routines->pInitializeForwardRecursion) + model->routines->pInitializeForwardRecursion(model); + + //====== Get ergodic distribution if necessary ====== + if (sv->UseErgodic) + if (!Ergodic(model->V[0],sv->Q)) + { + printf("ForwardRecursion(): Ergodic distribution does not exist.\n"); + exit(0); + } + + //====== forward recursion ====== + for (t=1; t <= sv->nobs; t++) + { + //------ compute Z[t] ------ + ProductMV(model->Z[t],sv->Q,model->V[t-1]); + + //------ compute log conditional probabilities and scale ------ + scale=MINUS_INFINITY; + for (s=sv->nstates-1; s >= 0; s--) + { + if (ElementV(model->Z[t],s) > 0.0) + { + u=LogConditionalLikelihood(s,t,model); + scale=AddScaledLogs(1.0,scale,ElementV(model->Z[t],s),u); + ElementV(model->V[t],s)=log(ElementV(model->Z[t],s)) + u; + } + else + ElementV(model->V[t],s)=MINUS_INFINITY; + } + + //------ update L ------ + model->L+=scale; + + //--- Added by Zha. + if (t==endt_base1) logvalue = scale; + + //------ scale V[t] ------ + for (s=sv->nstates-1; s >= 0; s--) + if (ElementV(model->V[t],s) != MINUS_INFINITY) + ElementV(model->V[t],s)=exp(ElementV(model->V[t],s) - scale); + else + ElementV(model->V[t],s)=0.0; + } + + model->ValidForwardRecursion=1; + + return (logvalue); +} + + + + +//------------------------------- +//Modified from fn_gradcd() in cstz.c for the conjugate gradient method I or II +//------------------------------- +#define STPS 1.0e-04 // 6.0554544523933391e-6 step size = pow(DBL_EPSILON,1.0/3) +#define GRADMANUAL 0.0e+01 //Arbitrarily (manually) set gradient. +void gradcd_switch(TSdvector *g_dv, TStateModel *model, TSdvector *x_dv, int nmodelpars, int endt_base1, double (*fcn)(TStateModel *model, TSdvector *x_dv, int nmodelpars, int endt_base1), TSdvector *grdh_dv, double f0) +{ + //Outputs: + // g: the gradient n-by-1 g (no need to be initialized). + //Inputs: + // x: the vector point at which the gradient is evaluated. No change in the end although will be added or substracted by dh during the function (but in the end the original value will be put back). + // n: the dimension of g or x. + // fcn(): the function for which the gradient is evaluated + // grdh: step size. If NULL, then dh is set automatically; otherwise, grdh is taken as a step size, often set as 1.0e-004. + // f0: the value of (*fcn)(x). NOT used in this function except dealing with the boundary (NEARINFINITY) for the + // minimization problem, but to be compatible with a genral function call where, say, gradfw_gen() and cubic + // interpolation of central difference method will use f0. + + double *g, *x, *grdh; + double dh, dhi, dh2i, fp, fm, tmp, *xp; + int n, i; + + g = g_dv->v; + x = x_dv->v; + if (!grdh_dv) grdh = NULL; + else grdh = grdh_dv->v; + n = g_dv->n; + if (n != x_dv->n) + { + printf("gradcd_switch.c/gradcd_switch(): Input vectors g_dv and x_dv must have the same length.\n"); + exit(EXIT_FAILURE); + } + if (grdh_dv && n != grdh_dv->n) + { + printf("gradcd_switch.c/gradcd_switch(): Input vector grdh_dv mush have the same length as x_dv.\n"); + exit(EXIT_FAILURE); + } + + if (grdh) { + //=== If f0 >= NEARINFINITY, we're in a bad region and so we assume it's flat in this bad region. This assumption may or may not work for a third-party optimimization routine. + if (f0 >= NEARINFINITY) + { + for (i=n-1; i>=0; i--) + g[i] = GRADMANUAL; + return;; //Early exit. + } + + dh2i = (dhi=1.0/(dh=*grdh))/2.0; + for (i=0, xp=x; i<n; i++, xp++, g++) { + tmp = *xp; + *xp += dh; + //The following statement is bad because dh does not get reset at the beginning of the loop and thus may get changed continually within the loop. + // dh = *xp - tmp; // This increases the precision slightly. + fp = fcn(model, x_dv, nmodelpars, endt_base1); + //fp = fcn(n,x); // IMSL + //fcn(n,x,&fp,NULL,NULL); /* NAG */ + *xp = tmp - dh; + fm = fcn(model, x_dv, nmodelpars, endt_base1); + //fm = fcn(n,x); // IMSL + //fcn(n,x,&fm,NULL,NULL); + + //=== Checking the boundary condition for the minimization problem. + if ((fp < NEARINFINITY) && (fm < NEARINFINITY)) *g = (fp-fm)*dh2i; + else if (fp < NEARINFINITY) *g = (fp-f0)*dhi; + else if (fm < NEARINFINITY) *g = (f0-fm)*dhi; + else *g = GRADMANUAL; + + *xp = tmp; // Put the original value of x[i] back to x[i] so that the content x[i] is still unaltered. + } + + } + else { + //=== If f0 >= NEARINFINITY, we're in a bad region and so we assume it's flat in this bad region. This assumption may or may not work for a third-party optimimization routine. + if (f0 >= NEARINFINITY) + { + for (i=n-1; i>=0; i--) + g[i] = GRADMANUAL; + return;; //Early exit. + } + + for (i=0, xp=x; i<n; i++, xp++, g++) { + dh = fabs(*xp)<=1 ? STPS : STPS*(*xp); + tmp = *xp; + *xp += dh; + dh = *xp - tmp; // This increases the precision slightly. + fp = fcn(model, x_dv, nmodelpars, endt_base1); + //fp = fcn(n,x); // IMSL + //fcn(n,x,&fp,NULL,NULL); /* NAG */ + *xp = tmp - dh; + fm = fcn(model, x_dv, nmodelpars, endt_base1); + //fm = fcn(n,x); // IMSL + //fcn(n,x,&fm,NULL,NULL); + + //=== Checking the boundary condition for the minimization problem. + if ((fp < NEARINFINITY) && (fm < NEARINFINITY)) *g = (fp-fm)/(2.0*dh); + else if (fp < NEARINFINITY) *g = (fp-f0)/dh; + else if (fm < NEARINFINITY) *g = (f0-fm)/dh; + else *g = GRADMANUAL; + + *xp = tmp; // Put the original value of x[i] back to x[i] so that the content x[i] is still unaltered. + } + } + + g_dv->flag = V_DEF; +} +#undef STPS +#undef GRADMANUAL + diff --git a/CFiles/gradcd_switch.h b/CFiles/gradcd_switch.h new file mode 100755 index 0000000..e6b7097 --- /dev/null +++ b/CFiles/gradcd_switch.h @@ -0,0 +1,6 @@ + +#include "switch.h" + + +double logTimetLHgivenparameters(TStateModel *model, TSdvector *x_dv, int nmodelpars, int endt_base1); +void gradcd_switch(TSdvector *g_dv, TStateModel *model, TSdvector *x_dv, int nmodelpars, int endt_base1, double (*fcn)(TStateModel *model, TSdvector *x_dv, int nmodelpars, int endt_base1), TSdvector *grdh_dv, double f0); diff --git a/CFiles/kalman.c b/CFiles/kalman.c new file mode 100755 index 0000000..d9b4df9 --- /dev/null +++ b/CFiles/kalman.c @@ -0,0 +1,2908 @@ +/*=============================================================================================================== + * Check $$$ for important notes. + * Check <<>> for updating DW's new switch code or questions for DW. + * + * kalcvf_urw(): the Kalman filter forward prediction specialized for only a univariate random walk (urw) process. + * + * State space model is defined as follows: + * z(t+1) = z(t)+eta(t) (state or transition equation) + * y(t) = x(t)'*z(t)+eps(t) (observation or measurement equation) + * where for this function, eta and eps must be uncorrelated; y(t) must be 1-by-1. Note that + * x(t): k-by-1; + * z(t): k-by-1; + * eps(t): 1-by-1 and ~ N(0, sigma^2); + * eta(t): ~ N(0, V) where V is a k-by-k covariance matrix. + * + * + * Written by Tao Zha, May 2004. + * Revised, May 2008; +=================================================================================================================*/ + +/** +//=== For debugging purpose. +if (1) +{ + double t_loglht; + + t_loglht = -(0.5*ny)*LOG2PI - 0.5*logdeterminant(Dtdata_dm) - 0.5*VectorDotVector(wny_dv, etdata_dv); + fprintf(FPTR_DEBUG, " %10.5f\n", t_loglht); + + fprintf(FPTR_DEBUG, "%%st=%d, inpt=%d, and sti=%d\n", st, inpt, sti); + + fprintf(FPTR_DEBUG, "\n wP0_dv:\n"); + WriteVector(FPTR_DEBUG, wP0_dv, " %10.5f "); + fprintf(FPTR_DEBUG, "\n Vt_dc->C[sti_v=%d]:\n", sti_v); + WriteMatrix(FPTR_DEBUG, Vt_dc->C[sti_v], " %10.5f "); + + fflush(FPTR_DEBUG); +} +/**/ + + +#include "kalman.h" + + +static int Update_et_Dt_1stapp(int t_1, struct TSkalfilmsinputs_1stapp_tag *kalfilmsinputs_1stapp_ps); +static int Updatekalfilms_1stapp(int inpt, struct TSkalfilmsinputs_1stapp_tag *kalfilmsinputs_1stapp_ps, struct TStateModel_tag *smodel_ps); + + +TSkalcvfurw *CreateTSkalcvfurw(TFlearninguni *func, int T, int k, int tv) //, int storeZ, int storeV) +{ + int _i; + //=== + TSivector *rows_iv = NULL; + TSivector *cols_iv = NULL; + //--- + TSkalcvfurw *kalcvfurw_ps = tzMalloc(1, TSkalcvfurw); + + + kalcvfurw_ps->indx_tvsigmasq = tv; + kalcvfurw_ps->fss = T; + kalcvfurw_ps->kx = k; + + //=== + kalcvfurw_ps->V_dm = CreateMatrix_lf(k, k); + kalcvfurw_ps->ylhtran_dv = CreateVector_lf(T); + kalcvfurw_ps->Xrhtran_dm = CreateMatrix_lf(k, T); + kalcvfurw_ps->z10_dv = CreateVector_lf(k); + kalcvfurw_ps->P10_dm = CreateMatrix_lf(k, k); + + kalcvfurw_ps->zupdate_dv = CreateVector_lf(k); + kalcvfurw_ps->Zpredtran_dm = CreateMatrix_lf(k, T); + kalcvfurw_ps->ylhtranpred_dv = CreateVector_lf(T); + // + rows_iv = CreateVector_int(T); + cols_iv = CreateVector_int(T); + for (_i=T-1; _i>=0; _i--) rows_iv->v[_i] = cols_iv->v[_i] = k; + kalcvfurw_ps->Ppred_dc = CreateCell_lf(rows_iv, cols_iv); + // if (!storeZ) kalcvfurw_ps->Zpredtran_dm = (TSdmatrix *)NULL; + // else kalcvfurw_ps->Zpredtran_dm = CreateMatrix_lf(k, T); + // if (!storeV) kalcvfurw_ps->Ppred_dc = (TSdcell *)NULL; + // else { + // rows_iv = CreateVector_int(T); + // cols_iv = CreateVector_int(T); + // for (_i=T; _i>=0; _i--) rows_iv->v[_i] = cols_iv->v[_i] = k; + // kalcvfurw_ps->Ppred_dc = CreateCell_lf(rows_iv, cols_iv); + // } + + DestroyVector_int(rows_iv); + DestroyVector_int(cols_iv); + return (kalcvfurw_ps); +} + +TSkalcvfurw *DestroyTSkalcvfurw(TSkalcvfurw *kalcvfurw_ps) +{ + if (kalcvfurw_ps) { + DestroyMatrix_lf(kalcvfurw_ps->V_dm); + DestroyVector_lf(kalcvfurw_ps->ylhtran_dv); + DestroyMatrix_lf(kalcvfurw_ps->Xrhtran_dm); + DestroyVector_lf(kalcvfurw_ps->z10_dv); + DestroyMatrix_lf(kalcvfurw_ps->P10_dm); + + DestroyVector_lf(kalcvfurw_ps->zupdate_dv); + DestroyMatrix_lf(kalcvfurw_ps->Zpredtran_dm); + DestroyCell_lf(kalcvfurw_ps->Ppred_dc); + DestroyVector_lf(kalcvfurw_ps->ylhtranpred_dv); + + free(kalcvfurw_ps); + return ((TSkalcvfurw *)NULL); + } + else return (kalcvfurw_ps); +} + + +void kalcvf_urw(TSkalcvfurw *kalcvfurw_ps, void *dummy_ps) +{ + //See the notes of SWZ regarding the government's updating of the parameters in their Phillips-curve equation. + //NOTE: make sure that the value of kalcvfurw_ps->sigmasq and other input values are given. + int ti; + double workd, workdenominv; + //--- + int fss, kx; + double sigmasq_fix = kalcvfurw_ps->sigmasq; +// double sigmasq; + TSdmatrix *V_dm; + TSdmatrix *Zpredtran_dm; + TSdcell *Ppred_dc; + TSdvector *ylhtran_dv; + TSdmatrix *Xrhtran_dm; + //=== + TSdvector *workkxby1_dv = NULL; //kx-by-1. +// TSdvector *work1kxby1_dv = NULL; //kx-by-1. + TSdmatrix *workkxbykx_dm = NULL; //kx-by-kx symmetric and positive positive. +// //=== +// TSdvector *zbefore_dv = CreateVector_lf(kalcvfurw_ps->kx); +// TSdmatrix *Vbefore_dm = CreateMatrix_lf(kalcvfurw_ps->kx, kalcvfurw_ps->kx); +// TSdvector *zafter_dv = CreateVector_lf(kalcvfurw_ps->kx); +// TSdmatrix *Vafter_dm = CreateMatrix_lf(kalcvfurw_ps->kx, kalcvfurw_ps->kx); + //******* WARNING: Some dangerous pointer movement to gain efficiency ******* +// double *yt_p; +// double *Vbefore_p; +// double *Vafter_p; + TSdvector xt_sdv; + TSdvector zbefore_sdv; + //TSdmatrix Vbefore_sdm; + TSdvector zafter_sdv; + //TSdmatrix Vafter_sdm; + + + if (!kalcvfurw_ps) fn_DisplayError(".../kalcvf_urw(): the input argument kalcvfurw_ps must be created"); + if (!kalcvfurw_ps->V_dm || !kalcvfurw_ps->ylhtran_dv || !kalcvfurw_ps->Xrhtran_dm || !kalcvfurw_ps->z10_dv || !kalcvfurw_ps->P10_dm) + fn_DisplayError(".../kalcvf_urw(): input arguments kalcvfurw_ps->V_dm, kalcvfurw_ps->ylhtran_dv, kalcvfurw_ps->Xrhtran_dm, kalcvfurw_ps->z10_dv, kalcvfurw_ps->P10_dm must be given legal values"); + if (!(kalcvfurw_ps->P10_dm->flag & (M_SU | M_SL))) fn_DisplayError(".../kalcvf_urw(): the input argument kalcvfurw_ps->P10_dm must be symmetric"); + fss = kalcvfurw_ps->fss; + kx = kalcvfurw_ps->kx; + V_dm = kalcvfurw_ps->V_dm; + Zpredtran_dm = kalcvfurw_ps->Zpredtran_dm; + Ppred_dc = kalcvfurw_ps->Ppred_dc; + ylhtran_dv = kalcvfurw_ps->ylhtran_dv; + Xrhtran_dm = kalcvfurw_ps->Xrhtran_dm; + //--- + xt_sdv.n = kx; + xt_sdv.flag = V_DEF; + zbefore_sdv.n = kx; + zbefore_sdv.flag = V_DEF; + zafter_sdv.n = kx; + zafter_sdv.flag = V_DEF; + + //=== Memory allocation. + workkxby1_dv = CreateVector_lf(kx); + workkxbykx_dm = CreateMatrix_lf(kx, kx); + + + //------- The first period (ti=0). ------- + zbefore_sdv.v = kalcvfurw_ps->z10_dv->v; + zafter_sdv.v = Zpredtran_dm->M; + xt_sdv.v = Xrhtran_dm->M; + //--- + + workd = ylhtran_dv->v[0] - (kalcvfurw_ps->ylhtranpred_dv->v[0]=VectorDotVector(&xt_sdv, &zbefore_sdv)); //y_t - x_t'*z_{t-1}. + SymmatrixTimesVector(workkxby1_dv, kalcvfurw_ps->P10_dm, &xt_sdv, 1.0, 0.0); //P_{t|t-1} x_t; + + if (!kalcvfurw_ps->indx_tvsigmasq) + workdenominv = 1.0/(sigmasq_fix + VectorDotVector(&xt_sdv, workkxby1_dv)); //1/[sigma^2 + x_t' P_{t|t-1} x_t] + else if (kalcvfurw_ps->indx_tvsigmasq == 1) //See pp.37 and 37a in SWZ Learning NOTES. + workdenominv = 1.0/(sigmasq_fix*square(kalcvfurw_ps->z10_dv->v[0]) + VectorDotVector(&xt_sdv, workkxby1_dv)); //1/[sigma^2 + x_t' P_{t|t-1} x_t]; + else { + printf(".../kalman.c/kalcvf_urw(): Have not got time to deal with kalcvfurw_ps->indx_tvsigmasq defined in kalman.h other than 0 or 1"); + exit(EXIT_FAILURE); + } + + + //--- Updating z_{t+1|t}. + CopyVector0(&zafter_sdv, &zbefore_sdv); + VectorPlusMinusVectorUpdate(&zafter_sdv, workkxby1_dv, workd*workdenominv); //z_{t+1|t} = z_{t|t-1} + P_{t|t-1} x_t [y_t - x_t'*z_{t-1}] / [sigma^2 + x_t' P_{t|t-1} x_t]; + //--- Updating P_{t+1|t}. + CopyMatrix0(workkxbykx_dm, V_dm); + VectorTimesSelf(workkxbykx_dm, workkxby1_dv, -workdenominv, 1.0, (V_dm->flag & M_SU) ? 'U' : 'L'); + // - P_{t|t-1}*x_t * xt'*P_{t|t-1} / [sigma^2 + x_t' P_{t|t-1} x_t] + V; + MatrixPlusMatrix(Ppred_dc->C[0], kalcvfurw_ps->P10_dm, workkxbykx_dm); + //P_{t|t-1} - P_{t|t-1}*x_t * xt'*P_{t|t-1} / [sigma^2 + x_t' P_{t|t-1} x_t] + V; + Ppred_dc->C[0]->flag = M_GE | M_SU | M_SL; //This is necessary because if P10_dm is initialized as diagonal, it will have M_GE | M_SU | M_SL | M_UT | M_LT, + // which is no longer true for workkxbykx_dm and therefore gives Ppred_dc->C[0] with M_GE only as a result of MatrixPlusMatrix(). + //Done with all work* arrays. + + //------- The rest of the periods (ti=1:T-1). ------- + for (ti=1; ti<fss; ti++) { + //NOTE: ti=0 has been taken care of outside of this loop. + zbefore_sdv.v = Zpredtran_dm->M + (ti-1)*kx; + zafter_sdv.v = Zpredtran_dm->M + ti*kx; + xt_sdv.v = Xrhtran_dm->M + ti*kx; + //--- + workd = ylhtran_dv->v[ti] - (kalcvfurw_ps->ylhtranpred_dv->v[ti]=VectorDotVector(&xt_sdv, &zbefore_sdv)); //y_t - x_t'*z_{t-1}. + SymmatrixTimesVector(workkxby1_dv, Ppred_dc->C[ti-1], &xt_sdv, 1.0, 0.0); //P_{t|t-1} x_t; + if (!kalcvfurw_ps->indx_tvsigmasq) + workdenominv = 1.0/(sigmasq_fix + VectorDotVector(&xt_sdv, workkxby1_dv)); //1/[sigma^2 + x_t' P_{t|t-1} x_t] + else if (kalcvfurw_ps->indx_tvsigmasq == 1) //See pp.37 and 37a in SWZ Learning NOTES. + workdenominv = 1.0/(sigmasq_fix*square(zbefore_sdv.v[0]) + VectorDotVector(&xt_sdv, workkxby1_dv)); //1/[sigma^2 + x_t' P_{t|t-1} x_t] + else { + printf(".../kalman.c/kalcvf_urw(): Have not got time to deal with kalcvfurw_ps->indx_tvsigmasq defined in kalman.h other than 0 or 1"); + exit(EXIT_FAILURE); + } + //--- Updating z_{t+1|t}. + CopyVector0(&zafter_sdv, &zbefore_sdv); + VectorPlusMinusVectorUpdate(&zafter_sdv, workkxby1_dv, workd*workdenominv); //z_{t+1|t} = z_{t|t-1} + P_{t|t-1} x_t [y_t - x_t'*z_{t-1}] / [sigma^2 + x_t' P_{t|t-1} x_t]; + //--- Updating P_{t+1|t}. + CopyMatrix0(workkxbykx_dm, V_dm); + VectorTimesSelf(workkxbykx_dm, workkxby1_dv, -workdenominv, 1.0, (V_dm->flag & M_SU) ? 'U' : 'L'); + // - P_{t|t-1}*x_t * xt'*P_{t|t-1} / [sigma^2 + x_t' P_{t|t-1} x_t] + V; + MatrixPlusMatrix(Ppred_dc->C[ti], Ppred_dc->C[ti-1], workkxbykx_dm); + //P_{t|t-1} - P_{t|t-1}*x_t * xt'*P_{t|t-1} / [sigma^2 + x_t' P_{t|t-1} x_t] + V; + Ppred_dc->C[ti]->flag = M_GE | M_SU | M_SL; //This is necessary because if P10_dm is initialized as diagonal, it will have M_GE | M_SU | M_SL | M_UT | M_LT, + // which is no longer true for workkxbykx_dm and therefore gives Ppred_dc->C[0] with M_GE only as a result of MatrixPlusMatrix(). + //Done with all work* arrays. + } + CopyVector0(kalcvfurw_ps->zupdate_dv, &zafter_sdv); + Zpredtran_dm->flag = M_GE; + kalcvfurw_ps->ylhtranpred_dv->flag = V_DEF; + +// DestroyVector_lf(zbefore_dv); +// DestroyMatrix_lf(Vbefore_dm); +// DestroyVector_lf(zafter_dv); +// DestroyMatrix_lf(Vafter_dm); + + DestroyVector_lf(workkxby1_dv); +// DestroyVector_lf(work1kxby1_dv); + DestroyMatrix_lf(workkxbykx_dm); +} + + + +//----------------------------------------------------------------------------------------------------------------------- +//-- General constant (known-time-varying) Kalman filter for DSGE models. +//----------------------------------------------------------------------------------------------------------------------- +struct TSkalfiltv_tag *CreateTSkalfiltv(int ny, int nz, int T) +{ + int _i; + //=== + TSivector *rows_iv = CreateVector_int(T); + TSivector *cols_iv = CreateVector_int(T); + //~~~ Creating the structure and initializing the NULL pointers. + struct TSkalfiltv_tag *kalfiltv_ps = tzMalloc(1, struct TSkalfiltv_tag); + + + //--- Default value. + kalfiltv_ps->indxIni = 0; //1: using the initial condition with zt_tm1(:,1)=z0 and Pt_tm1(:,:,1)=P0; + //0: using the unconditional mean for any given regime at time 0. + //--- Other assignments. + kalfiltv_ps->ny = ny; + kalfiltv_ps->nz = nz; + kalfiltv_ps->T = T; + + + + //--------- Creates memory and assigns values. The order matters. + kalfiltv_ps->yt_dm = CreateMatrix_lf(ny, T); + kalfiltv_ps->at_dm = CreateMatrix_lf(ny, T); + // + for (_i=T-1; _i>=0; _i--) + { + rows_iv->v[_i] = ny; + cols_iv->v[_i] = nz; + } + rows_iv->flag = cols_iv->flag = V_DEF; + kalfiltv_ps->Ht_dc = CreateCell_lf(rows_iv, cols_iv); + // + for (_i=T-1; _i>=0; _i--) + { + rows_iv->v[_i] = ny; + cols_iv->v[_i] = ny; + } + kalfiltv_ps->Rt_dc = CreateCell_lf(rows_iv, cols_iv); + // + for (_i=T-1; _i>=0; _i--) + { + rows_iv->v[_i] = nz; + cols_iv->v[_i] = ny; + } + kalfiltv_ps->Gt_dc = CreateCell_lf(rows_iv, cols_iv); + // + kalfiltv_ps->bt_dm = CreateMatrix_lf(nz, T); + // + for (_i=T-1; _i>=0; _i--) + { + rows_iv->v[_i] = nz; + cols_iv->v[_i] = nz; + } + kalfiltv_ps->Ft_dc = CreateCell_lf(rows_iv, cols_iv); + kalfiltv_ps->Vt_dc = CreateCell_lf(rows_iv, cols_iv); + // + kalfiltv_ps->z0_dv = CreateVector_lf(nz); + kalfiltv_ps->P0_dm = CreateMatrix_lf(nz, nz); + + + //--- + kalfiltv_ps->zt_tm1_dm = CreateMatrix_lf(nz, T); + for (_i=T-1; _i>=0; _i--) + { + rows_iv->v[_i] = nz; + cols_iv->v[_i] = nz; + } + kalfiltv_ps->Pt_tm1_dc = CreateCell_lf(rows_iv, cols_iv); + + + //=== + DestroyVector_int(rows_iv); + DestroyVector_int(cols_iv); + + return (kalfiltv_ps); + +} +//--- +struct TSkalfiltv_tag *DestroyTSkalfiltv(struct TSkalfiltv_tag *kalfiltv_ps) +{ + if (kalfiltv_ps) + { + //=== The order matters! + DestroyMatrix_lf(kalfiltv_ps->yt_dm); + DestroyMatrix_lf(kalfiltv_ps->at_dm); + DestroyCell_lf(kalfiltv_ps->Ht_dc); + DestroyCell_lf(kalfiltv_ps->Rt_dc); + DestroyCell_lf(kalfiltv_ps->Gt_dc); + //--- + DestroyMatrix_lf(kalfiltv_ps->bt_dm); + DestroyCell_lf(kalfiltv_ps->Ft_dc); + DestroyCell_lf(kalfiltv_ps->Vt_dc); + //--- + DestroyVector_lf(kalfiltv_ps->z0_dv); + DestroyMatrix_lf(kalfiltv_ps->P0_dm); + //--- + DestroyMatrix_lf(kalfiltv_ps->zt_tm1_dm); + DestroyCell_lf(kalfiltv_ps->Pt_tm1_dc); + + + //--- + tzDestroy(kalfiltv_ps); //Must be freed last! + + return ((struct TSkalfiltv_tag *)NULL); + } + else return (kalfiltv_ps); +}; + + +//----------------------------------------------------------------------------------------------------------------------- +//-- New code: Inputs for filter for Markov-switching DSGE models at any time t. +//----------------------------------------------------------------------------------------------------------------------- +struct TSkalfilmsinputs_1stapp_tag *CreateTSkalfilmsinputs_1stapp2(int ny, int nz, int nu, int ne, int nst, int T) +{ + //~~~ Creating the structure and initializing the NULL pointers. + struct TSkalfilmsinputs_1stapp_tag *kalfilmsinputs_1stapp_ps = tzMalloc(1, struct TSkalfilmsinputs_1stapp_tag); + + //=== + TSivector *rows_iv = NULL; + TSivector *cols_iv = NULL; + + //=== Default value. + kalfilmsinputs_1stapp_ps->indxIni = 0; //1: using the initial condition with zt_tm1(:,1)=z0 and Pt_tm1(:,:,1)=P0; + //0: using the unconditional mean for any given regime at time 0. + kalfilmsinputs_1stapp_ps->indxDiffuse = 1; //1: using the diffuse condition for z_{1|0} and P_{1|0} (default option), according to Koopman and Durbin, "Filtering and Smoothing of State Vector for Diffuse State-Space Models," J. of Time Series Analysis, Vol 24(1), pp.85-99. + //0: using the unconditional moments. + kalfilmsinputs_1stapp_ps->DiffuseScale = 100.0; + kalfilmsinputs_1stapp_ps->ztm1_track = -1; + kalfilmsinputs_1stapp_ps->dtm1_track = -1; + + //--- Other key assignments. + kalfilmsinputs_1stapp_ps->ny = ny; + kalfilmsinputs_1stapp_ps->nz = nz; + kalfilmsinputs_1stapp_ps->nu = nu; + kalfilmsinputs_1stapp_ps->ne = ne; + kalfilmsinputs_1stapp_ps->nst = nst; + kalfilmsinputs_1stapp_ps->T = T; + + //--------- Creates memory and assigns values. The order matters. + kalfilmsinputs_1stapp_ps->yt_dm = CreateMatrix_lf(ny, T); + kalfilmsinputs_1stapp_ps->at_dm = CreateMatrix_lf(ny, nst); + // + rows_iv = CreateConstantVector_int(nst, ny); + cols_iv = CreateConstantVector_int(nst, nz); + kalfilmsinputs_1stapp_ps->Ht_dc = CreateCell_lf(rows_iv, cols_iv); + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + // + if (nu) + { + rows_iv = CreateConstantVector_int(nst, ny); + cols_iv = CreateConstantVector_int(nst, nu); + kalfilmsinputs_1stapp_ps->Psiut_dc = CreateCell_lf(rows_iv, cols_iv); + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + } + else + kalfilmsinputs_1stapp_ps->Psiut_dc = NULL; + // + rows_iv = CreateConstantVector_int(nst, ny); + cols_iv = CreateConstantVector_int(nst, ny); + kalfilmsinputs_1stapp_ps->Rt_dc = CreateCell_lf(rows_iv, cols_iv); + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + // + rows_iv = CreateConstantVector_int(nst, nz); + cols_iv = CreateConstantVector_int(nst, ny); + kalfilmsinputs_1stapp_ps->Gt_dc = CreateCell_lf(rows_iv, cols_iv); + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + // + kalfilmsinputs_1stapp_ps->bt_dm = CreateMatrix_lf(nz, nst); + // + rows_iv = CreateConstantVector_int(nst, nz); + cols_iv = CreateConstantVector_int(nst, nz); + kalfilmsinputs_1stapp_ps->Ft_dc = CreateCell_lf(rows_iv, cols_iv); + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + // + rows_iv = CreateConstantVector_int(nst, nz); + cols_iv = CreateConstantVector_int(nst, ne); + kalfilmsinputs_1stapp_ps->Psiet_dc = CreateCell_lf(rows_iv, cols_iv); + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + // + rows_iv = CreateConstantVector_int(nst, nz); + cols_iv = CreateConstantVector_int(nst, nz); + kalfilmsinputs_1stapp_ps->Vt_dc = CreateCell_lf(rows_iv, cols_iv); + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + // + kalfilmsinputs_1stapp_ps->z0_dm = CreateMatrix_lf(nz, nst); //nz-by-nst. + kalfilmsinputs_1stapp_ps->z0_0_dm = CreateMatrix_lf(nz, nst); //nz-by-nst. + // + rows_iv = CreateConstantVector_int(nst, nz); + cols_iv = CreateConstantVector_int(nst, nz); + kalfilmsinputs_1stapp_ps->P0_dc = CreateCell_lf(rows_iv, cols_iv); //nz-by-nz-by-nst. + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + + //--- For output arguments. + rows_iv = CreateConstantVector_int(T+1, nz); + cols_iv = CreateConstantVector_int(T+1, nst); + kalfilmsinputs_1stapp_ps->zt_tm1_dc = CreateCell_lf(rows_iv, cols_iv); //nz-by-nst-by-(T+1). + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + // + rows_iv = CreateConstantVector_int(nst, nz); + cols_iv = CreateConstantVector_int(nst, nz); + kalfilmsinputs_1stapp_ps->Pt_tm1_d4 = CreateFourth_lf(T+1, rows_iv, cols_iv); //nz-by-nz-by-nst-by-(T+1). + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + // + rows_iv = CreateConstantVector_int(nst, nz); + cols_iv = CreateConstantVector_int(nst, ny); + kalfilmsinputs_1stapp_ps->PHtran_tdata_d4 = CreateFourth_lf(T, rows_iv, cols_iv); //nz-by-ny-by-nst-T, saved only for updating Kalman filter Updatekalfilms_1stapp(). + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + // + rows_iv = CreateConstantVector_int(T, ny); + cols_iv = CreateConstantVector_int(T, nst); + kalfilmsinputs_1stapp_ps->etdata_dc = CreateCell_lf(rows_iv, cols_iv); //ny-by-nst-by-T, used for updating Kalman filter Updatekalfilms_1stapp(). + rows_iv = CreateConstantVector_int(T, ny); + cols_iv = CreateConstantVector_int(T, nst); + // + rows_iv = CreateConstantVector_int(nst, ny); + cols_iv = CreateConstantVector_int(nst, ny); + kalfilmsinputs_1stapp_ps->Dtdata_d4 = CreateFourth_lf(T, rows_iv, cols_iv); //ny-by-ny-nst-by-T, used for updating Kalman filter Updatekalfilms_1stapp(). + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + + return (kalfilmsinputs_1stapp_ps); +} +//--- +struct TSkalfilmsinputs_1stapp_tag *DestroyTSkalfilmsinputs_1stapp2(struct TSkalfilmsinputs_1stapp_tag *kalfilmsinputs_1stapp_ps) +{ + if (kalfilmsinputs_1stapp_ps) + { + //=== The order matters! + DestroyMatrix_lf(kalfilmsinputs_1stapp_ps->yt_dm); + DestroyMatrix_lf(kalfilmsinputs_1stapp_ps->at_dm); + DestroyCell_lf(kalfilmsinputs_1stapp_ps->Ht_dc); + DestroyCell_lf(kalfilmsinputs_1stapp_ps->Psiut_dc); + DestroyCell_lf(kalfilmsinputs_1stapp_ps->Rt_dc); + DestroyCell_lf(kalfilmsinputs_1stapp_ps->Gt_dc); + //--- + DestroyMatrix_lf(kalfilmsinputs_1stapp_ps->bt_dm); + DestroyCell_lf(kalfilmsinputs_1stapp_ps->Ft_dc); + DestroyCell_lf(kalfilmsinputs_1stapp_ps->Psiet_dc); + DestroyCell_lf(kalfilmsinputs_1stapp_ps->Vt_dc); + //--- + DestroyMatrix_lf(kalfilmsinputs_1stapp_ps->z0_dm); + DestroyMatrix_lf(kalfilmsinputs_1stapp_ps->z0_0_dm); + DestroyCell_lf(kalfilmsinputs_1stapp_ps->P0_dc); + //--- + DestroyCell_lf(kalfilmsinputs_1stapp_ps->zt_tm1_dc); + DestroyFourth_lf(kalfilmsinputs_1stapp_ps->Pt_tm1_d4); + DestroyFourth_lf(kalfilmsinputs_1stapp_ps->PHtran_tdata_d4); + DestroyCell_lf(kalfilmsinputs_1stapp_ps->etdata_dc); + DestroyFourth_lf(kalfilmsinputs_1stapp_ps->Dtdata_d4); + //--- + tzDestroy(kalfilmsinputs_1stapp_ps); //Must be freed last! + + return ((struct TSkalfilmsinputs_1stapp_tag *)NULL); + } + else return (kalfilmsinputs_1stapp_ps); +}; + +struct TSkalfilmsinputs_1stapp_tag *CreateTSkalfilmsinputs_1stapp(int ny, int nz, int nst, int T) +{ + //~~~ Creating the structure and initializing the NULL pointers. + struct TSkalfilmsinputs_1stapp_tag *kalfilmsinputs_1stapp_ps = tzMalloc(1, struct TSkalfilmsinputs_1stapp_tag); + + //=== + TSivector *rows_iv = NULL; + TSivector *cols_iv = NULL; + + //=== Default value. + kalfilmsinputs_1stapp_ps->indxIni = 0; //1: using the initial condition with zt_tm1(:,1)=z0 and Pt_tm1(:,:,1)=P0; + //0: using the unconditional mean for any given regime at time 0. + kalfilmsinputs_1stapp_ps->indxDiffuse = 1; //1: using the diffuse condition for z_{1|0} and P_{1|0} (default option), according to Koopman and Durbin, "Filtering and Smoothing of State Vector for Diffuse State-Space Models," J. of Time Series Analysis, Vol 24(1), pp.85-99. + //0: using the unconditional moments. + kalfilmsinputs_1stapp_ps->DiffuseScale = 100.0; + kalfilmsinputs_1stapp_ps->ztm1_track = -1; + kalfilmsinputs_1stapp_ps->dtm1_track = -1; + + //--- Other key assignments. + kalfilmsinputs_1stapp_ps->ny = ny; + kalfilmsinputs_1stapp_ps->nz = nz; + kalfilmsinputs_1stapp_ps->nst = nst; + kalfilmsinputs_1stapp_ps->T = T; + + //--------- Creates memory and assigns values. The order matters. + kalfilmsinputs_1stapp_ps->yt_dm = CreateMatrix_lf(ny, T); + kalfilmsinputs_1stapp_ps->at_dm = CreateMatrix_lf(ny, nst); + // + rows_iv = CreateConstantVector_int(nst, ny); + cols_iv = CreateConstantVector_int(nst, nz); + kalfilmsinputs_1stapp_ps->Ht_dc = CreateCell_lf(rows_iv, cols_iv); + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + // + rows_iv = CreateConstantVector_int(nst, ny); + cols_iv = CreateConstantVector_int(nst, ny); + kalfilmsinputs_1stapp_ps->Rt_dc = CreateCell_lf(rows_iv, cols_iv); + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + // + rows_iv = CreateConstantVector_int(nst, nz); + cols_iv = CreateConstantVector_int(nst, ny); + kalfilmsinputs_1stapp_ps->Gt_dc = CreateCell_lf(rows_iv, cols_iv); + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + // + kalfilmsinputs_1stapp_ps->bt_dm = CreateMatrix_lf(nz, nst); + // + rows_iv = CreateConstantVector_int(nst, nz); + cols_iv = CreateConstantVector_int(nst, nz); + kalfilmsinputs_1stapp_ps->Ft_dc = CreateCell_lf(rows_iv, cols_iv); + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + // + rows_iv = CreateConstantVector_int(nst, nz); + cols_iv = CreateConstantVector_int(nst, nz); + kalfilmsinputs_1stapp_ps->Vt_dc = CreateCell_lf(rows_iv, cols_iv); + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + // + kalfilmsinputs_1stapp_ps->z0_dm = CreateMatrix_lf(nz, nst); //nz-by-nst. + kalfilmsinputs_1stapp_ps->z0_0_dm = CreateMatrix_lf(nz, nst); //nz-by-nst. + // + rows_iv = CreateConstantVector_int(nst, nz); + cols_iv = CreateConstantVector_int(nst, nz); + kalfilmsinputs_1stapp_ps->P0_dc = CreateCell_lf(rows_iv, cols_iv); //nz-by-nz-by-nst. + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + + //--- For output arguments. + rows_iv = CreateConstantVector_int(T+1, nz); + cols_iv = CreateConstantVector_int(T+1, nst); + kalfilmsinputs_1stapp_ps->zt_tm1_dc = CreateCell_lf(rows_iv, cols_iv); //nz-by-nst-by-(T+1). + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + // + rows_iv = CreateConstantVector_int(nst, nz); + cols_iv = CreateConstantVector_int(nst, nz); + kalfilmsinputs_1stapp_ps->Pt_tm1_d4 = CreateFourth_lf(T+1, rows_iv, cols_iv); //nz-by-nz-by-nst-by-(T+1). + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + // + rows_iv = CreateConstantVector_int(nst, nz); + cols_iv = CreateConstantVector_int(nst, ny); + kalfilmsinputs_1stapp_ps->PHtran_tdata_d4 = CreateFourth_lf(T, rows_iv, cols_iv); //nz-by-ny-by-nst-T, saved only for updating Kalman filter Updatekalfilms_1stapp(). + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + // + rows_iv = CreateConstantVector_int(T, ny); + cols_iv = CreateConstantVector_int(T, nst); + kalfilmsinputs_1stapp_ps->etdata_dc = CreateCell_lf(rows_iv, cols_iv); //ny-by-nst-by-T, used for updating Kalman filter Updatekalfilms_1stapp(). + rows_iv = CreateConstantVector_int(T, ny); + cols_iv = CreateConstantVector_int(T, nst); + // + rows_iv = CreateConstantVector_int(nst, ny); + cols_iv = CreateConstantVector_int(nst, ny); + kalfilmsinputs_1stapp_ps->Dtdata_d4 = CreateFourth_lf(T, rows_iv, cols_iv); //ny-by-ny-nst-by-T, used for updating Kalman filter Updatekalfilms_1stapp(). + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + + return (kalfilmsinputs_1stapp_ps); +} +//--- +struct TSkalfilmsinputs_1stapp_tag *DestroyTSkalfilmsinputs_1stapp(struct TSkalfilmsinputs_1stapp_tag *kalfilmsinputs_1stapp_ps) +{ + if (kalfilmsinputs_1stapp_ps) + { + //=== The order matters! + DestroyMatrix_lf(kalfilmsinputs_1stapp_ps->yt_dm); + DestroyMatrix_lf(kalfilmsinputs_1stapp_ps->at_dm); + DestroyCell_lf(kalfilmsinputs_1stapp_ps->Ht_dc); + DestroyCell_lf(kalfilmsinputs_1stapp_ps->Rt_dc); + DestroyCell_lf(kalfilmsinputs_1stapp_ps->Gt_dc); + //--- + DestroyMatrix_lf(kalfilmsinputs_1stapp_ps->bt_dm); + DestroyCell_lf(kalfilmsinputs_1stapp_ps->Ft_dc); + DestroyCell_lf(kalfilmsinputs_1stapp_ps->Vt_dc); + //--- + DestroyMatrix_lf(kalfilmsinputs_1stapp_ps->z0_dm); + DestroyMatrix_lf(kalfilmsinputs_1stapp_ps->z0_0_dm); + DestroyCell_lf(kalfilmsinputs_1stapp_ps->P0_dc); + //--- + DestroyCell_lf(kalfilmsinputs_1stapp_ps->zt_tm1_dc); + DestroyFourth_lf(kalfilmsinputs_1stapp_ps->Pt_tm1_d4); + DestroyFourth_lf(kalfilmsinputs_1stapp_ps->PHtran_tdata_d4); + DestroyCell_lf(kalfilmsinputs_1stapp_ps->etdata_dc); + DestroyFourth_lf(kalfilmsinputs_1stapp_ps->Dtdata_d4); + //--- + tzDestroy(kalfilmsinputs_1stapp_ps); //Must be freed last! + + return ((struct TSkalfilmsinputs_1stapp_tag *)NULL); + } + else return (kalfilmsinputs_1stapp_ps); +}; + + +//----------------------------------------------------------------------------------------------------------------------- +//-- OLD Code: Inputs for filter for Markov-switching DSGE models at any time t. +//----------------------------------------------------------------------------------------------------------------------- +struct TSkalfilmsinputs_tag *CreateTSkalfilmsinputs(int ny, int nz, int nRc, int nRstc, int nRv, int indxIndRegimes, int T) +{ + //~~~ Creating the structure and initializing the NULL pointers. + struct TSkalfilmsinputs_tag *kalfilmsinputs_ps = tzMalloc(1, struct TSkalfilmsinputs_tag); + + //=== + TSivector *rows_iv = NULL; + TSivector *cols_iv = NULL; + + //--- Default value. + kalfilmsinputs_ps->indxIni = 0; //1: using the initial condition with zt_tm1(:,1)=z0 and Pt_tm1(:,:,1)=P0; + //0: using the unconditional mean for any given regime at time 0. + //--- Other assignments. + kalfilmsinputs_ps->ny = ny; + kalfilmsinputs_ps->nz = nz; + kalfilmsinputs_ps->nRc = nRc; + kalfilmsinputs_ps->nRstc = nRstc; + kalfilmsinputs_ps->nRv = nRv; + kalfilmsinputs_ps->indxIndRegimes = indxIndRegimes; + kalfilmsinputs_ps->T = T; + + + //--------- Creates memory and assigns values. The order matters. + kalfilmsinputs_ps->yt_dm = CreateMatrix_lf(ny, T); + kalfilmsinputs_ps->at_dm = CreateMatrix_lf(ny, nRc); + // + rows_iv = CreateConstantVector_int(nRc, ny); + cols_iv = CreateConstantVector_int(nRc, nz); + kalfilmsinputs_ps->Ht_dc = CreateCell_lf(rows_iv, cols_iv); + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + // + rows_iv = CreateConstantVector_int(nRv, ny); + cols_iv = CreateConstantVector_int(nRv, ny); + kalfilmsinputs_ps->Rt_dc = CreateCell_lf(rows_iv, cols_iv); + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + // + rows_iv = CreateConstantVector_int(nRv, nz); + cols_iv = CreateConstantVector_int(nRv, ny); + kalfilmsinputs_ps->Gt_dc = CreateCell_lf(rows_iv, cols_iv); + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + // + kalfilmsinputs_ps->bt_dm = CreateMatrix_lf(nz, nRc); + // + rows_iv = CreateConstantVector_int(nRc, nz); + cols_iv = CreateConstantVector_int(nRc, nz); + kalfilmsinputs_ps->Ft_dc = CreateCell_lf(rows_iv, cols_iv); + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + // + rows_iv = CreateConstantVector_int(nRv, nz); + cols_iv = CreateConstantVector_int(nRv, nz); + kalfilmsinputs_ps->Vt_dc = CreateCell_lf(rows_iv, cols_iv); + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + // + if (indxIndRegimes) + { + kalfilmsinputs_ps->z0_dm = CreateMatrix_lf(nz, nRc*nRv); //nz-by-nRc*nRv if indxIndRegimes == 1 or nz-by-nRv if indxIndRegimes == 0. + // + rows_iv = CreateConstantVector_int(nRc*nRv, nz); + cols_iv = CreateConstantVector_int(nRc*nRv, nz); + kalfilmsinputs_ps->P0_dc = CreateCell_lf(rows_iv, cols_iv); //nz-by-nz-by-nRc*nRv if indxIndRegimes == 1 or nz-by-nz-by-nRv if indxIndRegimes == 0. + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + } + else + { + if (nRstc != nRv) fn_DisplayError("kalman.c/CreateTSkalfilmsinputs(): nRstc must equal to nRv when indxIndRegimes==0"); + kalfilmsinputs_ps->z0_dm = CreateMatrix_lf(nz, nRv); //nz-by-nRc*nRv if indxIndRegimes == 1 or nz-by-nRv if indxIndRegimes == 0. + // + rows_iv = CreateConstantVector_int(nRv, nz); + cols_iv = CreateConstantVector_int(nRv, nz); + kalfilmsinputs_ps->P0_dc = CreateCell_lf(rows_iv, cols_iv); //nz-by-nz-by-nRc*nRv if indxIndRegimes == 1 or nz-by-nz-by-nRv if indxIndRegimes == 0. + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + } + //--- For output arguments. + if (indxIndRegimes) + { + rows_iv = CreateConstantVector_int(T, nz); + cols_iv = CreateConstantVector_int(T, nRc*nRv); + kalfilmsinputs_ps->zt_tm1_dc = CreateCell_lf(rows_iv, cols_iv); //nz-by-nRc*nRv-by-T if indxIndRegimes==1, nz-by-nRv-by-T if indxIndRegimes==0 where nRc=nRv. + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + // + rows_iv = CreateConstantVector_int(nRc*nRv, nz); + cols_iv = CreateConstantVector_int(nRc*nRv, nz); + kalfilmsinputs_ps->Pt_tm1_d4 = CreateFourth_lf(T, rows_iv, cols_iv); //nz-by-nz-by-nRc*nRv-T if indxIndRegimes==1, nz-by-nz-by-nRv-by-T if indxIndRegimes==0 where nRc=nRv. + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + } + else + { + if (nRstc != nRv) fn_DisplayError("kalman.c/CreateTSkalfilmsinputs(): nRstc must equal to nRv when indxIndRegimes==0"); + rows_iv = CreateConstantVector_int(T, nz); + cols_iv = CreateConstantVector_int(T, nRv); + kalfilmsinputs_ps->zt_tm1_dc = CreateCell_lf(rows_iv, cols_iv); //nz-by-nRc*nRv-by-T if indxIndRegimes==1, nz-by-nRv-by-T if indxIndRegimes==0 where nRc=nRv. + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + // + rows_iv = CreateConstantVector_int(nRv, nz); + cols_iv = CreateConstantVector_int(nRv, nz); + kalfilmsinputs_ps->Pt_tm1_d4 = CreateFourth_lf(T, rows_iv, cols_iv); //nz-by-nz-by-nRc*nRv-T if indxIndRegimes==1, nz-by-nz-by-nRv-by-T if indxIndRegimes==0 where nRc=nRv. + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + } + + + //=== + DestroyVector_int(rows_iv); + DestroyVector_int(cols_iv); + + return (kalfilmsinputs_ps); + +} +//--- +struct TSkalfilmsinputs_tag *DestroyTSkalfilmsinputs(struct TSkalfilmsinputs_tag *kalfilmsinputs_ps) +{ + if (kalfilmsinputs_ps) + { + //=== The order matters! + DestroyMatrix_lf(kalfilmsinputs_ps->yt_dm); + DestroyMatrix_lf(kalfilmsinputs_ps->at_dm); + DestroyCell_lf(kalfilmsinputs_ps->Ht_dc); + DestroyCell_lf(kalfilmsinputs_ps->Rt_dc); + DestroyCell_lf(kalfilmsinputs_ps->Gt_dc); + //--- + DestroyMatrix_lf(kalfilmsinputs_ps->bt_dm); + DestroyCell_lf(kalfilmsinputs_ps->Ft_dc); + DestroyCell_lf(kalfilmsinputs_ps->Vt_dc); + //--- + DestroyMatrix_lf(kalfilmsinputs_ps->z0_dm); + DestroyCell_lf(kalfilmsinputs_ps->P0_dc); + //--- + DestroyCell_lf(kalfilmsinputs_ps->zt_tm1_dc); + DestroyFourth_lf(kalfilmsinputs_ps->Pt_tm1_d4); + //--- + tzDestroy(kalfilmsinputs_ps); //Must be freed last! + + return ((struct TSkalfilmsinputs_tag *)NULL); + } + else return (kalfilmsinputs_ps); +}; + + +#define LOG2PI (1.837877066409345e+000) //log(2*pi) +//----------------------------------------------------- +//-- Constant-parameters (known-time-varying) Kalman filter +//----------------------------------------------------- +double tz_kalfiltv(struct TSkalfiltv_tag *kalfiltv_ps) +{ + //General constant (known-time-varying) Kalman filter for DSGE models (conditional on all the parameters). + // It computes a sequence of one-step predictions and their covariance matrices, and the log likelihood. + // The function uses a forward recursion algorithm. See also the Matlab function fn_kalfil_tv.m + // + // State space model is defined as follows: + // y(t) = a(t) + H(t)*z(t) + eps(t) (observation or measurement equation) + // z(t) = b(t) + F(t)*z(t) + eta(t) (state or transition equation) + // where a(t), H(t), b(t), and F(t) depend on s_t that follows a Markov-chain process and are taken as given. + // + // Inputs are as follows: + // Y_T is a n_y-by-T matrix containing data [y(1), ... , y(T)]. + // a is an n_y-by-T matrix of time-varying input vectors in the measurement equation. + // H is an n_y-by-n_z-by-T 3-D of time-varying matrices in the measurement equation. + // R is an n_y-by-n_y-by-T 3-D of time-varying covariance matrices for the error in the measurement equation. + // G is an n_z-by-n_y-by-T 3-D of time-varying E(eta_t * eps_t'). + // ------ + // b is an n_z-by-T matrix of time-varying input vectors in the state equation with b(:,1) as an initial condition. + // F is an n_z-by-n_z-by-T 3-D of time-varying transition matrices in the state equation with F(:,:,1) as an initial condition. + // V is an n_z-by-n_z-by-T 3-D of time-varying covariance matrices for the error in the state equation with V(:,:,1) as an initial condition. + // ------ + // indxIni: 1: using the initial condition with zt_tm1(:,1)=z0 and Pt_tm1(:,:,1)=P0; + // 0: using the unconditional mean for any given regime at time 0. + // z0 is an n_z-by-1 vector of initial condition when indxIni=1. (Do not enter if indxIni=0.) + // P0 is an n_z-by-n_z matrix of initial condition when indxIni=1. (Do not enter if indxIni=0.) + // + // Outputs are as follows: + // loglh is a value of the log likelihood function of the state-space model + // under the assumption that errors are multivariate Gaussian. + // zt_tm1 is an n_z-by-T matrices of one-step predicted state vectors with z0_0m1 as an initial condition (base-0 first element) + // and with z_{T|T-1} as the last element. Thus, we can use it as a base-1 vector. + // Pt_tm1 is an n_z-by-n_z-by-T 3-D of covariance matrices of zt_tm1 with P0_0m1 as though it were a initial condition + // and with P_{T|T-1} as the last element. Thus, we can use it as though it were a base-1 cell. + // + // The initial state vector and its covariance matrix are computed under the bounded (stationary) condition: + // z0_0m1 = (I-F(:,:,1))\b(:,1) + // vec(P0_0m1) = (I-kron(F(:,:,1),F(:,:,1)))\vec(V(:,:,1)) + // Note that all eigenvalues of the matrix F(:,:,1) are inside the unit circle when the state-space model is bounded (stationary). + // + // March 2007, written by Tao Zha + // See Hamilton's book ([13.2.13] -- [13.2.22]), Harvey (pp.100-106), and LiuWZ Model I NOTES pp.001-003. + + int T = kalfiltv_ps->T; + int Tp1 = T + 1; + int ny = kalfiltv_ps->ny; + int nz = kalfiltv_ps->nz; + int indx_badlh = 0; //1: bad likelihood with, say, -infinity of the LH value. + int tdata, ti; + //--- Work arguments. + int nz2 = square(nz); + TSdmatrix *Wnzbynz_dm = CreateMatrix_lf(nz,nz); + TSdmatrix *Wnz2bynz2_dm = CreateMatrix_lf(nz2,nz2); + TSdmatrix *W2nz2bynz2_dm = CreateMatrix_lf(nz2,nz2); + TSdvector *wP0_dv = CreateVector_lf(nz2); + //+ + TSdvector yt_sdv, at_sdv, zt_tm1_sdv, ztp1_t_sdv, btp1_sdv; //double loglh_tdata; //logdetDtdata. + TSdvector *wny_dv = CreateVector_lf(ny); + TSdmatrix *Wnzbyny_dm = CreateMatrix_lf(nz,ny); + TSdmatrix *W2nzbynz_dm = CreateMatrix_lf(nz,nz); + TSdmatrix *PHtran_tdata_dm = CreateMatrix_lf(nz,ny); + TSdvector *etdata_dv = CreateVector_lf(ny); + TSdmatrix *Dtdata_dm = CreateMatrix_lf(ny,ny); + TSdmatrix *Kt_tdata0_dm = CreateMatrix_lf(nz,ny); + TSdmatrix *Kt_tdata_dm = CreateMatrix_lf(nz,ny); + //--- For eigenvalue decompositions + int ki; + int errflag; + double eigmax, logdet_Dtdata; + TSdzvector *evals_dzv = NULL; + TSdvector *evals_abs_dv = NULL; //Absolute eigenvalues. + //--- Input arguments. + TSdmatrix *yt_dm = kalfiltv_ps->yt_dm; //ny-by-T. + TSdmatrix *at_dm = kalfiltv_ps->at_dm; //ny-by-T. + TSdcell *Ht_dc = kalfiltv_ps->Ht_dc; //ny-by-nz-by-T. + TSdcell *Rt_dc = kalfiltv_ps->Rt_dc; //ny-by-ny-by-T. Covariance matrix for the measurement equation. + TSdcell *Gt_dc = kalfiltv_ps->Gt_dc; //nz-by-ny-by-T. Cross-covariance. + // + TSdmatrix *bt_dm = kalfiltv_ps->bt_dm; //nz-by-T. + TSdcell *Ft_dc = kalfiltv_ps->Ft_dc; //nz-by-nz-by-T. + TSdcell *Vt_dc = kalfiltv_ps->Vt_dc; //nz-by-nz-by-T. Covariance matrix for the state equation. + // + TSdvector *z0_dv = kalfiltv_ps->z0_dv; //nz-by-1; + TSdmatrix *P0_dm = kalfiltv_ps->P0_dm; //nz-by-nz. + //--- Output arguments. + double loglh; //log likelihood. + TSdmatrix *zt_tm1_dm = kalfiltv_ps->zt_tm1_dm; //nz-by-T. + TSdcell *Pt_tm1_dc = kalfiltv_ps->Pt_tm1_dc; //nz-by-nz-T. + + + + //=== Initializing. + if (!kalfiltv_ps->indxIni) + { + InitializeDiagonalMatrix_lf(Wnzbynz_dm, 1.0); //To be used for I(nz) - + InitializeDiagonalMatrix_lf(Wnz2bynz2_dm, 1.0); //To be used for I(nz2) - + + //=== Eigenanalysis to determine the roots to ensure boundedness. + evals_dzv = CreateVector_dz(nz); + evals_abs_dv = CreateVector_lf(nz); + errflag = eigrgen(evals_dzv, (TSdzmatrix *)NULL, (TSdzmatrix *)NULL, Ft_dc->C[0]); + if (errflag) fn_DisplayError("tz_kalfiltv() in kalman.c: eigen decomposition failed"); + for (ki=nz-1; ki>=0; ki--) evals_abs_dv->v[ki] = sqrt(square(evals_dzv->real->v[ki]) + square(evals_dzv->imag->v[ki])); + evals_abs_dv->flag = V_DEF; + eigmax = MaxVector(evals_abs_dv); + if (eigmax < (1.0+1.0e-14)) + { + //--- Getting z0_dv: zt_tm1(:,1) = (eye(n_z)-F(:,:,1))\b(:,1); + MatrixMinusMatrix(Wnzbynz_dm, Wnzbynz_dm, Ft_dc->C[0]); + CopySubmatrix2vector(z0_dv, 0, bt_dm, 0, 0, bt_dm->nrows); + bdivA_rgens(z0_dv, z0_dv, '\\', Wnzbynz_dm); + //Done with Wnzbynz_dm. + //--- Getting P0_dm: Pt_tm1(:,:,1) = reshape((eye(n_z^2)-kron(F(:,:,1),F(:,:,1)))\V1(:),n_z,n_z); + tz_kron(W2nz2bynz2_dm, Ft_dc->C[0], Ft_dc->C[0]); + MatrixMinusMatrix(Wnz2bynz2_dm, Wnz2bynz2_dm, W2nz2bynz2_dm); + CopySubmatrix2vector(wP0_dv, 0, Vt_dc->C[0], 0, 0, nz2); + bdivA_rgens(wP0_dv, wP0_dv, '\\', Wnz2bynz2_dm); + CopySubvector2matrix_unr(P0_dm, 0, 0, wP0_dv, 0, nz2); + //Done with all w*_dv and W*_dm. + } + else + { + fprintf(stdout, "Fatal error: tz_kalfiltv() in kalman.c: the system is non-stationary solutions\n" + " and the initial conditions must be supplied by, say, input arguments"); + fflush(stdout); + exit( EXIT_FAILURE ); + } + } + CopySubvector2matrix(zt_tm1_dm, 0, 0, z0_dv, 0, z0_dv->n); + CopyMatrix0(Pt_tm1_dc->C[0], P0_dm); + + //====== See p.002 in LiuWZ. ====== + at_sdv.n = yt_sdv.n = yt_dm->nrows; + at_sdv.flag = yt_sdv.flag = V_DEF; + zt_tm1_sdv.n = ztp1_t_sdv.n = zt_tm1_dm->nrows; + zt_tm1_sdv.flag = ztp1_t_sdv.flag = V_DEF; + btp1_sdv.n = bt_dm->nrows; + btp1_sdv.flag = V_DEF; + loglh = 0.0; + for (tdata=0; tdata<T; tdata++ ) + { + //Base-0 timing. + ti = tdata + 1; //Next period. + + //--- Setup. + MatrixTimesMatrix(PHtran_tdata_dm, Pt_tm1_dc->C[tdata], Ht_dc->C[tdata], 1.0, 0.0, 'N', 'T'); + + //--- Data. + //- etdata = Y_T(:,tdata) - a(:,tdata) - Htdata*ztdata; + yt_sdv.v = yt_dm->M + tdata*yt_dm->nrows; + at_sdv.v = at_dm->M + tdata*at_dm->nrows; + zt_tm1_sdv.v = zt_tm1_dm->M + tdata*zt_tm1_dm->nrows; + VectorMinusVector(etdata_dv, &yt_sdv, &at_sdv); + MatrixTimesVector(etdata_dv, Ht_dc->C[tdata], &zt_tm1_sdv, -1.0, 1.0, 'N'); + //+ Dtdata = Htdata*PHtran_tdata + R(:,:,tdata); + CopyMatrix0(Dtdata_dm, Rt_dc->C[tdata]); + MatrixTimesMatrix(Dtdata_dm, Ht_dc->C[tdata], PHtran_tdata_dm, 1.0, 1.0, 'N', 'N'); + ScalarTimesMatrixSquare(Dtdata_dm, 0.5, Dtdata_dm, 'T', 0.5); //Making it symmetric against some rounding errors. + //This making-symmetric is very IMPORTANT; otherwise, we will get the matrix being singular message + // and eigenvalues being negative for the SPD matrix, etc. Then the likelihood becomes either + // a bad number or a complex number. + Dtdata_dm->flag = Dtdata_dm->flag | M_SU | M_SL; + + //--- Forming the log likelihood. + if (!isfinite(logdet_Dtdata=logdetspd(Dtdata_dm))) return (kalfiltv_ps->loglh = -NEARINFINITY); + bdivA_rgens(wny_dv, etdata_dv, '/', Dtdata_dm); + loglh += -(0.5*ny)*LOG2PI - 0.5*logdet_Dtdata - 0.5*VectorDotVector(wny_dv, etdata_dv); + //loglh += -(0.5*ny)*LOG2PI - 0.5*logdeterminant(Dtdata_dm) - 0.5*VectorDotVector(wny_dv, etdata_dv); + //Done with all w*_dv. + + + //--- Updating zt_tm1_dm and Pt_tm1_dc by ztp1_t_sdv and Pt_tm1_dc->C[ti]. + if (ti<T) + { + //Updating only up to tdata=T-2. The values at ti=T or tdata=T-1 will not be used in the likelihood function. + + //- Kt_tdata = (Ft*PHtran_tdata+G(:,:,tdata))/Dtdata; + CopyMatrix0(Kt_tdata0_dm, Gt_dc->C[tdata]); + MatrixTimesMatrix(Kt_tdata0_dm, Ft_dc->C[ti], PHtran_tdata_dm, 1.0, 1.0, 'N', 'N'); + BdivA_rrect(Kt_tdata_dm, Kt_tdata0_dm, '/', Dtdata_dm); + //+ zt_tm1(:,t) = b(:,t) + Ft*zt_tm1(:,tdata) + Kt_tdata*etdata; + ztp1_t_sdv.v = zt_tm1_dm->M + ti*zt_tm1_dm->nrows; + MatrixTimesVector(&ztp1_t_sdv, Ft_dc->C[ti], &zt_tm1_sdv, 1.0, 0.0, 'N'); + MatrixTimesVector(&ztp1_t_sdv, Kt_tdata_dm, etdata_dv, 1.0, 1.0, 'N'); + btp1_sdv.v = bt_dm->M + ti*btp1_sdv.n; + VectorPlusMinusVectorUpdate(&ztp1_t_sdv, &btp1_sdv, 1.0); + //+ Pt_tm1(:,:,t) = Ft*Ptdata*Fttran - Kt_tdata*Dtdata*Kt_tdatatran + V(:,:,t); + CopyMatrix0(Pt_tm1_dc->C[ti], Vt_dc->C[ti]); + MatrixTimesMatrix(Wnzbyny_dm, Kt_tdata_dm, Dtdata_dm, 1.0, 0.0, 'N', 'N'); + MatrixTimesMatrix(Wnzbynz_dm, Wnzbyny_dm, Kt_tdata_dm, 1.0, 0.0, 'N', 'T'); + MatrixPlusMinusMatrixUpdate(Pt_tm1_dc->C[ti], Wnzbynz_dm, -1.0); + //Done with all W*_dm. + MatrixTimesMatrix(Wnzbynz_dm, Ft_dc->C[ti], Pt_tm1_dc->C[tdata], 1.0, 0.0, 'N', 'N'); + MatrixTimesMatrix(W2nzbynz_dm, Wnzbynz_dm, Ft_dc->C[ti], 1.0, 0.0, 'N', 'T'); + MatrixPlusMatrixUpdate(Pt_tm1_dc->C[ti], W2nzbynz_dm); + //Done with all W*_dm. + } + } + zt_tm1_dm->flag = M_GE; + + //=== + DestroyVector_dz(evals_dzv); + DestroyVector_lf(evals_abs_dv); + DestroyMatrix_lf(Wnzbynz_dm); + DestroyMatrix_lf(Wnz2bynz2_dm); + DestroyMatrix_lf(W2nz2bynz2_dm); + DestroyVector_lf(wP0_dv); + // + DestroyVector_lf(wny_dv); + DestroyMatrix_lf(Wnzbyny_dm); + DestroyMatrix_lf(W2nzbynz_dm); + DestroyMatrix_lf(PHtran_tdata_dm); + DestroyVector_lf(etdata_dv); + DestroyMatrix_lf(Dtdata_dm); + DestroyMatrix_lf(Kt_tdata0_dm); + DestroyMatrix_lf(Kt_tdata_dm); + + return (kalfiltv_ps->loglh = loglh); +} +/** +double tz_kalfiltv(struct TSkalfiltv_tag *kalfiltv_ps) +{ + //This function is used to test tz_logTimetCondLH_kalfiltv(). + int T = kalfiltv_ps->T; + int tdata; + double loglh; + + loglh = 0.0; + for (tdata=0; tdata<T; tdata++) loglh += tz_logTimetCondLH_kalfiltv(0, tdata+1, kalfiltv_ps); + + return (loglh); +} +/**/ +//----------------------------------------------------- +//-- Updating Kalman filter at time t for constant-parameters (or known-time-varying) Kalman filter. +//----------------------------------------------------- +double tz_logTimetCondLH_kalfiltv(int st, int inpt, struct TSkalfiltv_tag *kalfiltv_ps) +{ + //st: base-0 grand regime at time t, which is just a dummy for this constant-parameter function in order to use + // Waggoner's automatic functions. + //inpt: base-1 in the sense that inpt>=1 to deal with the time series situation where S_T is (T+1)-by-1 and Y_T is T+nlags_max-by-1. + // The 1st element for S_T is S_T[1] while S_T[0] is s_0 (initial condition). + // The 1st element for Y_T, however, is Y_T[nlags_max+1-1]. + //See (42.3) on p.42 in the SWZII NOTES. + // + //log LH at time t for constant (known-time-varying) Kalman-filter DSGE models (conditional on all the parameters). + // It computes a sequence of one-step predictions and their covariance matrices, and the log likelihood at time t. + // The function uses a forward recursion algorithm. See also the Matlab function fn_kalfil_tv.m + // + // State space model is defined as follows: + // y(t) = a(t) + H(t)*z(t) + eps(t) (observation or measurement equation) + // z(t) = b(t) + F(t)*z(t) + eta(t) (state or transition equation) + // where a(t), H(t), b(t), and F(t) depend on s_t that follows a Markov-chain process and are taken as given. + // + // Inputs are as follows: + // Y_T is a n_y-by-T matrix containing data [y(1), ... , y(T)]. + // a is an n_y-by-T matrix of time-varying input vectors in the measurement equation. + // H is an n_y-by-n_z-by-T 3-D of time-varying matrices in the measurement equation. + // R is an n_y-by-n_y-by-T 3-D of time-varying covariance matrices for the error in the measurement equation. + // G is an n_z-by-n_y-by-T 3-D of time-varying E(eta_t * eps_t'). + // ------ + // b is an n_z-by-T matrix of time-varying input vectors in the state equation with b(:,1) as an initial condition. + // F is an n_z-by-n_z-by-T 3-D of time-varying transition matrices in the state equation with F(:,:,1) as an initial condition. + // V is an n_z-by-n_z-by-T 3-D of time-varying covariance matrices for the error in the state equation with V(:,:,1) as an initial condition. + // ------ + // indxIni: 1: using the initial condition with zt_tm1(:,1)=z0 and Pt_tm1(:,:,1)=P0; + // 0: using the unconditional mean for any given regime at time 0. + // z0 is an n_z-by-1 vector of initial condition when indxIni=1. (Value to be assigned if indxIni=0.) + // P0 is an n_z-by-n_z matrix of initial condition when indxIni=1. (Value to be assigned if indxIni=0.) + // + // Outputs are as follows: + // loglh is a value of the log likelihood function of the state-space model + // under the assumption that errors are multivariate Gaussian. + // zt_tm1 is an n_z-by-T matrices of one-step predicted state vectors with z0_0m1 as an initial condition (base-0 first element) + // and with z_{T|T-1} as the last element. Thus, we can use it as a base-1 vector. + // Pt_tm1 is an n_z-by-n_z-by-T 3-D of covariance matrices of zt_tm1 with P0_0m1 as though it were a initial condition + // and with P_{T|T-1} as the last element. Thus, we can use it as though it were a base-1 cell. + // + // The initial state vector and its covariance matrix are computed under the bounded (stationary) condition: + // z0_0m1 = (I-F(:,:,1))\b(:,1) + // vec(P0_0m1) = (I-kron(F(:,:,1),F(:,:,1)))\vec(V(:,:,1)) + // Note that all eigenvalues of the matrix F(:,:,1) are inside the unit circle when the state-space model is bounded (stationary). + // + // April 2008, written by Tao Zha + // See Hamilton's book ([13.2.13] -- [13.2.22]), Harvey (pp.100-106), and LiuWZ Model I NOTES pp.001-003. + + //--- Output arguments. + double loglh_timet; //log likelihood at time t. + TSdmatrix *zt_tm1_dm = kalfiltv_ps->zt_tm1_dm; //nz-by-T. + TSdcell *Pt_tm1_dc = kalfiltv_ps->Pt_tm1_dc; //nz-by-nz-T. + //--- Input arguments. + int tdata, tp1; + TSdvector *z0_dv = kalfiltv_ps->z0_dv; //nz-by-1; + TSdmatrix *P0_dm = kalfiltv_ps->P0_dm; //nz-by-nz. + int T = kalfiltv_ps->T; + int ny = kalfiltv_ps->ny; + int nz = kalfiltv_ps->nz; + //--- Work arguments. + int nz2 = square(nz); + TSdmatrix *Wnzbynz_dm = CreateMatrix_lf(nz,nz); + TSdmatrix *Wnz2bynz2_dm = CreateMatrix_lf(nz2,nz2); + TSdmatrix *W2nz2bynz2_dm = CreateMatrix_lf(nz2,nz2); + TSdvector *wP0_dv = CreateVector_lf(nz2); + //+ + TSdvector yt_sdv, at_sdv, zt_tm1_sdv, ztp1_t_sdv, btp1_sdv; + TSdvector *wny_dv = CreateVector_lf(ny); + TSdmatrix *Wnzbyny_dm = CreateMatrix_lf(nz,ny); + TSdmatrix *W2nzbynz_dm = CreateMatrix_lf(nz,nz); + TSdmatrix *PHtran_tdata_dm = CreateMatrix_lf(nz,ny); + TSdvector *etdata_dv = CreateVector_lf(ny); + TSdmatrix *Dtdata_dm = CreateMatrix_lf(ny,ny); + TSdmatrix *Kt_tdata0_dm = CreateMatrix_lf(nz,ny); + TSdmatrix *Kt_tdata_dm = CreateMatrix_lf(nz,ny); + //--- For eigenvalue decompositions + int ki; + int errflag; + double eigmax, logdet_Dtdata; + TSdzvector *evals_dzv = NULL; + TSdvector *evals_abs_dv = NULL; //Absolute eigenvalues. + //--- Input arguments. + TSdmatrix *yt_dm = kalfiltv_ps->yt_dm; //ny-by-T. + TSdmatrix *at_dm = kalfiltv_ps->at_dm; //ny-by-T. + TSdcell *Ht_dc = kalfiltv_ps->Ht_dc; //ny-by-nz-by-T. + TSdcell *Rt_dc = kalfiltv_ps->Rt_dc; //ny-by-ny-by-T. Covariance matrix for the measurement equation. + TSdcell *Gt_dc = kalfiltv_ps->Gt_dc; //nz-by-ny-by-T. Cross-covariance. + // + TSdmatrix *bt_dm = kalfiltv_ps->bt_dm; //nz-by-T. + TSdcell *Ft_dc = kalfiltv_ps->Ft_dc; //nz-by-nz-by-T. + TSdcell *Vt_dc = kalfiltv_ps->Vt_dc; //nz-by-nz-by-T. Covariance matrix for the state equation. + // + + + tdata = (tp1=inpt) - 1; //Base-0 time. + + //======= Initial condition. ======= + if (tdata==0) + { + //=== Initializing. + if (!kalfiltv_ps->indxIni) + { + InitializeDiagonalMatrix_lf(Wnzbynz_dm, 1.0); //To be used for I(nz) - + InitializeDiagonalMatrix_lf(Wnz2bynz2_dm, 1.0); //To be used for I(nz2) - + + //=== Eigenanalysis to determine the roots to ensure boundedness. + evals_dzv = CreateVector_dz(nz); + evals_abs_dv = CreateVector_lf(nz); + errflag = eigrgen(evals_dzv, (TSdzmatrix *)NULL, (TSdzmatrix *)NULL, Ft_dc->C[0]); + if (errflag) fn_DisplayError("tz_logTimetCondLH_kalfiltv() in kalman.c: eigen decomposition failed"); + for (ki=nz-1; ki>=0; ki--) evals_abs_dv->v[ki] = sqrt(square(evals_dzv->real->v[ki]) + square(evals_dzv->imag->v[ki])); + evals_abs_dv->flag = V_DEF; + eigmax = MaxVector(evals_abs_dv); + if (eigmax < (1.0+1.0e-14)) + { + //--- Getting z0_dv: zt_tm1(:,1) = (eye(n_z)-F(:,:,1))\b(:,1); + MatrixMinusMatrix(Wnzbynz_dm, Wnzbynz_dm, Ft_dc->C[0]); + CopySubmatrix2vector(z0_dv, 0, bt_dm, 0, 0, bt_dm->nrows); + bdivA_rgens(z0_dv, z0_dv, '\\', Wnzbynz_dm); + //Done with Wnzbynz_dm. + //--- Getting P0_dm: Pt_tm1(:,:,1) = reshape((eye(n_z^2)-kron(F(:,:,1),F(:,:,1)))\V1(:),n_z,n_z); + tz_kron(W2nz2bynz2_dm, Ft_dc->C[0], Ft_dc->C[0]); + MatrixMinusMatrix(Wnz2bynz2_dm, Wnz2bynz2_dm, W2nz2bynz2_dm); + CopySubmatrix2vector(wP0_dv, 0, Vt_dc->C[0], 0, 0, nz2); + bdivA_rgens(wP0_dv, wP0_dv, '\\', Wnz2bynz2_dm); + CopySubvector2matrix_unr(P0_dm, 0, 0, wP0_dv, 0, nz2); + //Done with all w*_dv and W*_dm. + } + else + { + fprintf(FPTR_DEBUG, "Fatal error: tz_logTimetCondLH_kalfiltv() in kalman.c: the system is non-stationary solutions\n" + " and thus the initial conditions must be supplied by, say, input arguments"); + fflush(FPTR_DEBUG); + exit( EXIT_FAILURE ); + } + } + CopySubvector2matrix(zt_tm1_dm, 0, 0, z0_dv, 0, z0_dv->n); + CopyMatrix0(Pt_tm1_dc->C[tdata], P0_dm); + } + + + //======= Liklihood at time t (see p.002 in LiuWZ). ======= + at_sdv.n = yt_sdv.n = yt_dm->nrows; + at_sdv.flag = yt_sdv.flag = V_DEF; + zt_tm1_sdv.n = ztp1_t_sdv.n = zt_tm1_dm->nrows; + zt_tm1_sdv.flag = ztp1_t_sdv.flag = V_DEF; + btp1_sdv.n = bt_dm->nrows; + btp1_sdv.flag = V_DEF; + + //--- Setup. + MatrixTimesMatrix(PHtran_tdata_dm, Pt_tm1_dc->C[tdata], Ht_dc->C[tdata], 1.0, 0.0, 'N', 'T'); + + //--- Data. + //- etdata = Y_T(:,tdata) - a(:,tdata) - Htdata*ztdata; + yt_sdv.v = yt_dm->M + tdata*yt_dm->nrows; + at_sdv.v = at_dm->M + tdata*at_dm->nrows; + zt_tm1_sdv.v = zt_tm1_dm->M + tdata*zt_tm1_dm->nrows; + VectorMinusVector(etdata_dv, &yt_sdv, &at_sdv); + MatrixTimesVector(etdata_dv, Ht_dc->C[tdata], &zt_tm1_sdv, -1.0, 1.0, 'N'); + //+ Dtdata = Htdata*PHtran_tdata + R(:,:,tdata); + CopyMatrix0(Dtdata_dm, Rt_dc->C[tdata]); + MatrixTimesMatrix(Dtdata_dm, Ht_dc->C[tdata], PHtran_tdata_dm, 1.0, 1.0, 'N', 'N'); + ScalarTimesMatrixSquare(Dtdata_dm, 0.5, Dtdata_dm, 'T', 0.5); //Making it symmetric against some rounding errors. + //This making-symmetric is very IMPORTANT; otherwise, we will get the matrix being singular message + // and eigenvalues being negative for the SPD matrix, etc. Then the likelihood becomes either + // a bad number or a complex number. + Dtdata_dm->flag = Dtdata_dm->flag | M_SU | M_SL; + + //--- Forming the log likelihood. + if (!isfinite(logdet_Dtdata=logdetspd(Dtdata_dm))) return (loglh_timet = -NEARINFINITY); + bdivA_rgens(wny_dv, etdata_dv, '/', Dtdata_dm); + loglh_timet = -(0.5*ny)*LOG2PI - 0.5*logdet_Dtdata - 0.5*VectorDotVector(wny_dv, etdata_dv); + //Done with all w*_dv. + + + //======= Updating for the next period. ======= + //--- Updating zt_tm1_dm and Pt_tm1_dc by ztp1_t_sdv and Pt_tm1_dc->C[ti]. + if (tp1<T) + { + //Updating only up to tdata=T-2, because the values at tp1=T or tdata=T-1 will NOT be used in the likelihood function. + + //- Kt_tdata = (Ft*PHtran_tdata+G(:,:,tdata))/Dtdata; + CopyMatrix0(Kt_tdata0_dm, Gt_dc->C[tdata]); + MatrixTimesMatrix(Kt_tdata0_dm, Ft_dc->C[tp1], PHtran_tdata_dm, 1.0, 1.0, 'N', 'N'); + BdivA_rrect(Kt_tdata_dm, Kt_tdata0_dm, '/', Dtdata_dm); + //+ zt_tm1(:,t) = b(:,t) + Ft*zt_tm1(:,tdata) + Kt_tdata*etdata; + ztp1_t_sdv.v = zt_tm1_dm->M + tp1*zt_tm1_dm->nrows; + MatrixTimesVector(&ztp1_t_sdv, Ft_dc->C[tp1], &zt_tm1_sdv, 1.0, 0.0, 'N'); + MatrixTimesVector(&ztp1_t_sdv, Kt_tdata_dm, etdata_dv, 1.0, 1.0, 'N'); + btp1_sdv.v = bt_dm->M + tp1*btp1_sdv.n; + VectorPlusMinusVectorUpdate(&ztp1_t_sdv, &btp1_sdv, 1.0); + //+ Pt_tm1(:,:,t) = Ft*Ptdata*Fttran - Kt_tdata*Dtdata*Kt_tdatatran + V(:,:,t); + CopyMatrix0(Pt_tm1_dc->C[tp1], Vt_dc->C[tp1]); + MatrixTimesMatrix(Wnzbyny_dm, Kt_tdata_dm, Dtdata_dm, 1.0, 0.0, 'N', 'N'); + MatrixTimesMatrix(Wnzbynz_dm, Wnzbyny_dm, Kt_tdata_dm, 1.0, 0.0, 'N', 'T'); + MatrixPlusMinusMatrixUpdate(Pt_tm1_dc->C[tp1], Wnzbynz_dm, -1.0); + //Done with all W*_dm. + MatrixTimesMatrix(Wnzbynz_dm, Ft_dc->C[tp1], Pt_tm1_dc->C[tdata], 1.0, 0.0, 'N', 'N'); + MatrixTimesMatrix(W2nzbynz_dm, Wnzbynz_dm, Ft_dc->C[tp1], 1.0, 0.0, 'N', 'T'); + MatrixPlusMatrixUpdate(Pt_tm1_dc->C[tp1], W2nzbynz_dm); + //Done with all W*_dm. + } + zt_tm1_dm->flag = M_GE; + + //=== + DestroyVector_dz(evals_dzv); + DestroyVector_lf(evals_abs_dv); + DestroyMatrix_lf(Wnzbynz_dm); + DestroyMatrix_lf(Wnz2bynz2_dm); + DestroyMatrix_lf(W2nz2bynz2_dm); + DestroyVector_lf(wP0_dv); + // + DestroyVector_lf(wny_dv); + DestroyMatrix_lf(Wnzbyny_dm); + DestroyMatrix_lf(W2nzbynz_dm); + DestroyMatrix_lf(PHtran_tdata_dm); + DestroyVector_lf(etdata_dv); + DestroyMatrix_lf(Dtdata_dm); + DestroyMatrix_lf(Kt_tdata0_dm); + DestroyMatrix_lf(Kt_tdata_dm); + + return (loglh_timet); +} + + + + +//----------------------------------------------------- +//- WARNING: bedore using this function, make sure to call the following functions +// Only once in creating lwzmodel_ps: Refresh_kalfilms_*(lwzmodel_ps); +// Everytime when parameters are changed: RefreshEverything(); RefreRunningGensys_allcases(lwzmodel_ps) in particular. +//----------------------------------------------------- +double logTimetCondLH_kalfilms_1stapp(int st, int inpt, struct TSkalfilmsinputs_1stapp_tag *kalfilmsinputs_1stapp_ps, struct TStateModel_tag *smodel_ps) +{ + //st: base-0 grand regime -- deals with the cross-section values at time t. + //inpt: base-1 in the sense that inpt>=1 to deal with the time series situation where S_T is (T+1)-by-1 and Y_T is T+nlags_max-by-1. + // The 1st element for S_T is S_T[1] while S_T[0] is s_0 (initial condition). + // The 1st element for Y_T, however, is Y_T[nlags_max+1-1]. + //See (42.3) on p.42 in the SWZII NOTES. + + //-- Output arguments + double loglh_timet; + //--- Input arguments + TSdcell *etdata_dc = kalfilmsinputs_1stapp_ps->etdata_dc; //ny-by-nst-by-T, save for computing the likelihood. + TSdfourth *Dtdata_d4 = kalfilmsinputs_1stapp_ps->Dtdata_d4; //ny-by-ny-nst-by-T, save for computing the likelihood and updating Kalman filter Updatekalfilms_1stapp(). + //--- Local variables + int tbase0; + double logdet_Dtdata; + //--- Accessible variables + int ny = kalfilmsinputs_1stapp_ps->ny; + TSdvector etdata_sdv; + //=== Work arguments. + TSdvector *wny_dv = CreateVector_lf(ny); + + + + //--- Critical checking. + if (inpt > kalfilmsinputs_1stapp_ps->T) + fn_DisplayError(".../kalman.c/logTimetCondLH_kalfilms_1stapp(): The time exceeds the\n" + " data sample size allocated the structure TSkalfilmsinputs_1stapp_tag"); + + //--- The following is for safe guard. InitializeKalman_z10_P10() should be called in, say, RefreshEverything(). + if (kalfilmsinputs_1stapp_ps->ztm1_track < 0) + if (!InitializeKalman_z10_P10(kalfilmsinputs_1stapp_ps, (TSdmatrix *)NULL, (TSdcell *)NULL)) + fn_DisplayError(".../kalman.c/logTimetCondLH_kalfilms_1stapp(): the system is non-stationary when calling" + " InitializeKalman_z10_P10(). Please call this function in RefreshEverthing() and" + " set the likehood to be -infty for early exit"); + + tbase0=inpt-1; + + //------------------- The order matters. Updatekalfilms_1stapp() must be called before Update_et_Dt_1stapp(). ----------------- + //--- $$$ Critical updating where we MUSt have inpt-1. If inpt, Updatekalfilms_1stapp() will call this function again + //--- $$$ because DW function ProbabilityStateConditionalCurrent() need to access this function at time inpt, + //--- $$$ which has not computed before Updatekalfilms_1stapp(). Thus, we'll have an infinite loop. + Updatekalfilms_1stapp(tbase0, kalfilmsinputs_1stapp_ps, smodel_ps); +// //--- $$$ Critical updating. +// Update_et_Dt_1stapp(tbase0, kalfilmsinputs_1stapp_ps); +// //This function will give Dtdata_d4->F[tbase0], etdata_dc->C[tbase0], and PHtran_tdata_d4->F[tbase0]. + + + + //====================================================== + //= Getting the logLH at time tbase0 or time inpt. + //====================================================== + //--- Forming the log conditional likelihood at t. + etdata_sdv.n = ny; + etdata_sdv.v = etdata_dc->C[tbase0]->M + ny*st; + etdata_sdv.flag = V_DEF; + if (!isfinite(logdet_Dtdata=logdetspd(Dtdata_d4->F[tbase0]->C[st]))) return (loglh_timet = -NEARINFINITY); + bdivA_rgens(wny_dv, &etdata_sdv, '/', Dtdata_d4->F[tbase0]->C[st]); + loglh_timet = -(0.5*ny)*LOG2PI - 0.5*logdet_Dtdata - 0.5*VectorDotVector(wny_dv, &etdata_sdv); + //Done with all w*_dv. + + //=== + DestroyVector_lf(wny_dv); + + return (loglh_timet); +} +//====================================================== +//= Computing z_{1|0} and P_{1|0} for each new parameter values. +//====================================================== +int InitializeKalman_z10_P10(struct TSkalfilmsinputs_1stapp_tag *kalfilmsinputs_1stapp_ps, TSdmatrix *z10_dm, TSdcell *P10_dc) +{ + //See p.001 and p.004 in LWZ Model II. + //Outputs: + // return 1: success in initializing; 0: initializing fails, so the likelihood must be set to -infty outside this function. + // ztm1_track to track the time up to which Kalman filter have been updated. + // z0_dm, zt_tm1_dc->C[0] + // P0_dc, Pt_tm1_d4->F[0] + + //--- Output arguments + TSdmatrix *z0_0_dm = kalfilmsinputs_1stapp_ps->z0_dm; //nz-by-nst. + TSdmatrix *z0_dm = kalfilmsinputs_1stapp_ps->z0_dm; //nz-by-nst. + TSdcell *P0_dc = kalfilmsinputs_1stapp_ps->P0_dc; //nz-by-nz-by-nst. + //+ Used to get zt_tm1_dc->C[0] and Pt_tm1_d4->F[0] only. + TSdcell *zt_tm1_dc = kalfilmsinputs_1stapp_ps->zt_tm1_dc; //nz-by-nst-by-(T+1). + TSdfourth *Pt_tm1_d4 = kalfilmsinputs_1stapp_ps->Pt_tm1_d4; //nz-by-nz-by-nst-by-(T+1). + //--- Input arguments + TSdmatrix *yt_dm = kalfilmsinputs_1stapp_ps->yt_dm; //ny-by-T. + TSdmatrix *at_dm = kalfilmsinputs_1stapp_ps->at_dm; //ny-by-nst. + TSdcell *Ht_dc = kalfilmsinputs_1stapp_ps->Ht_dc; //ny-by-nz-by-nst. + TSdcell *Rt_dc = kalfilmsinputs_1stapp_ps->Rt_dc; //ny-by-ny-by-nst. Covariance matrix for the measurement equation. + //+ + TSdmatrix *bt_dm = kalfilmsinputs_1stapp_ps->bt_dm; //nz-by-nst. + TSdcell *Ft_dc = kalfilmsinputs_1stapp_ps->Ft_dc; //nz-by-nz-by-nst. + TSdcell *Vt_dc = kalfilmsinputs_1stapp_ps->Vt_dc; //nz-by-nz-by-nst. Covariance matrix for the state equation. + //--- Local variables + int sti; + //--- Accessible variables + int ny = kalfilmsinputs_1stapp_ps->ny; + int nz = kalfilmsinputs_1stapp_ps->nz; + int nst = kalfilmsinputs_1stapp_ps->nst; + TSdvector z0_sdv, z0_0_sdv, bt_sdv; + TSdvector yt_sdv, at_sdv; + //--- For the initial conditions: eigenvalue decompositions + int ki; + int errflag; + double eigmax; + //=== + int nz2 = square(nz); + TSdmatrix *Wnzbynz_dm = CreateMatrix_lf(nz,nz); + TSdmatrix *Wnz2bynz2_dm = CreateMatrix_lf(nz2,nz2); + TSdmatrix *W2nz2bynz2_dm = CreateMatrix_lf(nz2,nz2); + TSdvector *wP0_dv = CreateVector_lf(nz2); + // + TSdzvector *evals_dzv = evals_dzv = CreateVector_dz(nz); + TSdvector *evals_abs_dv = CreateVector_lf(nz); //Absolute eigenvalues. + + + if (kalfilmsinputs_1stapp_ps->ztm1_track < 0) + { + z0_sdv.n = z0_0_sdv.n = bt_sdv.n = nz; + z0_sdv.flag = z0_0_sdv.flag = bt_sdv.flag = V_DEF; + at_sdv.n = yt_sdv.n = ny; + at_sdv.flag = yt_sdv.flag = V_DEF; + + + //======= Initial condition. ======= + if (!kalfilmsinputs_1stapp_ps->indxIni) + { + z0_0_dm->flag = z0_dm->flag = M_GE; + for (sti=nst-1; sti>=0; sti--) + { + if (kalfilmsinputs_1stapp_ps->DiffuseScale) //Diffuse initial conditions are used. + { + //--- Diffuse condition for z0_dv. + z0_sdv.v = z0_dm->M + z0_sdv.n*sti; + z0_0_sdv.v = z0_0_dm->M + z0_0_sdv.n*sti; + bt_sdv.v = bt_dm->M + bt_sdv.n*sti; + InitializeConstantVector_lf(&z0_0_sdv, 0.0); + MatrixTimesVector(&z0_sdv, Ft_dc->C[sti], &z0_0_sdv, 1.0, 0.0, 'N'); + VectorPlusVector(&z0_sdv, &z0_sdv, &bt_sdv); + //--- Diffuse condition for P0_dm. + InitializeDiagonalMatrix_lf(Wnzbynz_dm, kalfilmsinputs_1stapp_ps->DiffuseScale); //To be used for DiffuseScale*I(nz) + CopyMatrix0(P0_dc->C[sti], Wnzbynz_dm); + //Done with W*_dm. + } + else //Unconditional moments for initial conditions are used. + { + InitializeDiagonalMatrix_lf(Wnzbynz_dm, 1.0); //To be used for I(nz) - + InitializeDiagonalMatrix_lf(Wnz2bynz2_dm, 1.0); //To be used for I(nz2) - + + //=== Eigenanalysis to determine the roots to ensure boundedness. + errflag = eigrgen(evals_dzv, (TSdzmatrix *)NULL, (TSdzmatrix *)NULL, Ft_dc->C[sti]); + if (errflag) fn_DisplayError("kalman.c/InitializeKalman_z10_P10(): eigen decomposition failed"); + for (ki=nz-1; ki>=0; ki--) evals_abs_dv->v[ki] = sqrt(square(evals_dzv->real->v[ki]) + square(evals_dzv->imag->v[ki])); + evals_abs_dv->flag = V_DEF; + eigmax = MaxVector(evals_abs_dv); + if (eigmax < (1.0-SQRTEPSILON)) //(1.0+EPSILON)) + { + //--- Getting z0_dv: zt_tm1(:,1) = (eye(n_z)-F(:,:,sti))\b(:,sti); + z0_0_sdv.v = z0_0_dm->M + z0_0_sdv.n*sti; + z0_sdv.v = z0_dm->M + z0_sdv.n*sti; + MatrixMinusMatrix(Wnzbynz_dm, Wnzbynz_dm, Ft_dc->C[sti]); + CopySubmatrix2vector(&z0_0_sdv, 0, bt_dm, 0, sti, bt_dm->nrows); + bdivA_rgens(&z0_0_sdv, &z0_0_sdv, '\\', Wnzbynz_dm); + //- Under the assumption s_0 = s_1 (this is a short-cut). + MatrixTimesVector(&z0_sdv, Ft_dc->C[sti], &z0_0_sdv, 1.0, 0.0, 'N'); + VectorPlusVector(&z0_sdv, &z0_sdv, &bt_sdv); + //Done with Wnzbynz_dm. + //--- Getting P0_dm: Pt_tm1(:,:,1) = reshape((eye(n_z^2)-kron(F(:,:,sti),F(:,:,sti)))\V1(:),n_z,n_z); + tz_kron(W2nz2bynz2_dm, Ft_dc->C[sti], Ft_dc->C[sti]); + MatrixMinusMatrix(Wnz2bynz2_dm, Wnz2bynz2_dm, W2nz2bynz2_dm); + CopySubmatrix2vector(wP0_dv, 0, Vt_dc->C[sti], 0, 0, nz2); + bdivA_rgens(wP0_dv, wP0_dv, '\\', Wnz2bynz2_dm); + CopySubvector2matrix_unr(P0_dc->C[sti], 0, 0, wP0_dv, 0, nz2); + //Done with all w*_dv and W*_dm. + } + else + { + if (0) //0: no printing. + { + #if defined (USE_DEBUG_FILE) + fprintf(FPTR_DEBUG, "\n-------WARNING: ----------\n"); + fprintf(FPTR_DEBUG, "\nIn grand regime sti=%d\n", sti); + fprintf(FPTR_DEBUG, ".../kalman.c/InitializeKalman_z10_P10(): the system is non-stationary solutions\n" + " and see p.003 in LWZ Model II"); + #else + fprintf(stdout, "\n-----------------\n"); + fprintf(stdout, "\nIn grand regime sti=%d\n", sti); + fprintf(stdout, ".../kalman.c/InitializeKalman_z10_P10(): the system is non-stationary solutions\n" + " and see p.003 in LWZ Model II"); + #endif + } + //=== See p.000.3 in LWZ Model II. + //=== Do NOT use the following option. It turns out that this will often generate explosive conditional liklihood + //=== at the end of the sample, because Pt_tm1 shrinks to zero overtime due to the sigularity of + //=== the initila condition P_{1|0}. + //--- Letting z0_dv = 0.0 + // z0_sdv.v = z0_dm->M + z0_sdv.n*sti; + // InitializeConstantVector_lf(&z0_sdv, 0.0); + // //--- Letting P0_dm = V + // CopyMatrix0(P0_dc->C[sti], Vt_dc->C[sti]); + + //=== + DestroyVector_dz(evals_dzv); + DestroyVector_lf(evals_abs_dv); + DestroyMatrix_lf(Wnzbynz_dm); + DestroyMatrix_lf(Wnz2bynz2_dm); + DestroyMatrix_lf(W2nz2bynz2_dm); + DestroyVector_lf(wP0_dv); + + return (0); //Early exit with kalfilmsinputs_1stapp_ps->ztm1_track continues to be -1. + } + } + } + } + else + { + if (!z10_dm) fn_DisplayError(".../kalman.c/InitializeKalman_z10_P10(): The initial condition z_{1|0}\n" + " must be supplied as valid input arguments for when indxIni == 1"); + else + CopyMatrix0(z0_dm, z10_dm); + + if (!P10_dc) fn_DisplayError(".../kalman.c/InitializeKalman_z10_P10(): The initial condition P_{1|0}\n" + " must be supplied as valid input arguments for when indxIni == 1"); + else + CopyCell0(P0_dc, P10_dc); + } + CopyMatrix0(zt_tm1_dc->C[0], z0_dm); //At time t-1 = 1. + CopyCell0(Pt_tm1_d4->F[0], P0_dc); //At time t-1 = 1. + + + kalfilmsinputs_1stapp_ps->ztm1_track = 0; //Must reset to 0, meaning initial setting is done and ready for computing LH at t = 1. + + Update_et_Dt_1stapp(0, kalfilmsinputs_1stapp_ps); + + //=== + DestroyVector_dz(evals_dzv); + DestroyVector_lf(evals_abs_dv); + DestroyMatrix_lf(Wnzbynz_dm); + DestroyMatrix_lf(Wnz2bynz2_dm); + DestroyMatrix_lf(W2nz2bynz2_dm); + DestroyVector_lf(wP0_dv); + + return (1); + } + else + { + fn_DisplayError(".../kalman.c/InitializeKalman_z10_P10(): calling this function makes sense only if" + " kalfilmsinputs_1stapp_ps->ztm1_track is -1. Please check this value."); + + //=== + DestroyVector_dz(evals_dzv); + DestroyVector_lf(evals_abs_dv); + DestroyMatrix_lf(Wnzbynz_dm); + DestroyMatrix_lf(Wnz2bynz2_dm); + DestroyMatrix_lf(W2nz2bynz2_dm); + DestroyVector_lf(wP0_dv); + + return (0); + } +} +//====================================================== +//= Integrating out the lagged regimes in order to +//= updating zt_tm1 and Pt_tm1 for next perid tp1 through Kim-Nelson filter. +//= tdata representing base-0 t timing, while inpt represents base-1 t timing. +// +//= Purpose: for each inpt, we integrate out grand regimes st +//= only ONCE to prevent the dimension of updated zt_tm1 and Pt_tm1 through Kim-Nelson filter. +//====================================================== +static int Updatekalfilms_1stapp(int t_1, struct TSkalfilmsinputs_1stapp_tag *kalfilmsinputs_1stapp_ps, struct TStateModel_tag *smodel_ps) +{ + //Output: + // tm1update + // z_{t_1+1|t_1} + // P_{t_1+1|t_1} + //Input: + // t-1: base-1 t timing. Thus t-1=inpt-1. + + //--- Local variables + int stp1i, sti, t_2, t_2p1; + double prob_previous_regimes; + //-- Output arguments + TSdcell *zt_tm1_dc = kalfilmsinputs_1stapp_ps->zt_tm1_dc; //nz-by-nst-by-(T+1). + TSdfourth *Pt_tm1_d4 = kalfilmsinputs_1stapp_ps->Pt_tm1_d4; //nz-by-nz-by-nst-by-(T+1). + //--- Input arguments + TSdcell *Gt_dc = kalfilmsinputs_1stapp_ps->Gt_dc; //nz-by-ny-by-nst. Cross-covariance. + //+ + TSdmatrix *bt_dm = kalfilmsinputs_1stapp_ps->bt_dm; //nz-by-nst. + TSdcell *Ft_dc = kalfilmsinputs_1stapp_ps->Ft_dc; //nz-by-nz-by-nst. + TSdcell *Vt_dc = kalfilmsinputs_1stapp_ps->Vt_dc; //nz-by-nz-by-nst. Covariance matrix for the state equation. + //+ + TSdfourth *PHtran_tdata_d4 = kalfilmsinputs_1stapp_ps->PHtran_tdata_d4; //nz-by-ny-by-nst-T, saved only for updating Kalman filter Updatekalfilms_1stapp(). + TSdcell *etdata_dc = kalfilmsinputs_1stapp_ps->etdata_dc; //ny-by-nst-by-T, save for computing the likelihood. + TSdfourth *Dtdata_d4 = kalfilmsinputs_1stapp_ps->Dtdata_d4; //ny-by-ny-nst-by-T, save for computing the likelihood and updating Kalman filter Updatekalfilms_1stapp(). + //--- Accessible variables + int ny = kalfilmsinputs_1stapp_ps->ny; + int nz = kalfilmsinputs_1stapp_ps->nz; + int nst = kalfilmsinputs_1stapp_ps->nst; + int T = kalfilmsinputs_1stapp_ps->T; + TSdvector z0_sdv; + TSdvector btp1_sdv; + TSdvector etdata_sdv; + //=== Work arguments. + TSdmatrix *Wnzbynz_dm = CreateMatrix_lf(nz,nz); + //+ + TSdmatrix *Wnzbyny_dm = CreateMatrix_lf(nz,ny); + TSdmatrix *W2nzbynz_dm = CreateMatrix_lf(nz,nz); + TSdmatrix *Kt_tdata0_dm = CreateMatrix_lf(nz,ny); + TSdmatrix *Kt_tdata_dm = CreateMatrix_lf(nz,ny); + //=== For updating zt_tm1_dm and Pt_tm1. + TSdvector *ztp1_t_dv = CreateVector_lf(nz); + TSdmatrix *Ptp1_t_dm = CreateMatrix_lf(nz, nz); + TSdvector *ztp1_dv = CreateVector_lf(nz); + TSdmatrix *Ptp1_dm = CreateMatrix_lf(nz, nz); + + + //--- Critical checking. + if (kalfilmsinputs_1stapp_ps->ztm1_track < 0) + fn_DisplayError(".../kalman.c/Updatekalfilms_1stapp(): Make sure InitializeKalman_z10_P10() is called in the function RefreshEverthing()"); + + + z0_sdv.n = nz; + z0_sdv.flag = V_DEF; + btp1_sdv.n = nz; + btp1_sdv.flag = V_DEF; + //+ + etdata_sdv.n = ny; + etdata_sdv.flag = V_DEF; + + for (t_2=kalfilmsinputs_1stapp_ps->ztm1_track; t_2<t_1; t_2++) + { + //If t_1 <= ztm1_track, no updating. + //If t_1 > ztm1_track, updating z_{t|t-1} and P_{t|t-1} up to t-1 = t_1. + + zt_tm1_dc->C[t_2p1=t_2+1]->flag = M_GE; + for (stp1i=nst-1; stp1i>=0; stp1i--) + { + InitializeConstantVector_lf(ztp1_dv, 0.0); //To be summed over sti. + InitializeConstantMatrix_lf(Ptp1_dm, 0.0); //To be summed over sti. + + for (sti=nst-1; sti>=0; sti--) + { + //=== Updating for next period by integrating out sti.. + //--- Ktp1_t = (F_tp1*PHtran_t+G(:,:,t))/Dt; + //--- Kt_tdata = (Ft*PHtran_tdata+G(:,:,tdata))/Dtdata where t=tp1 and tdata=t. + CopyMatrix0(Kt_tdata0_dm, Gt_dc->C[sti]); + MatrixTimesMatrix(Kt_tdata0_dm, Ft_dc->C[stp1i], PHtran_tdata_d4->F[t_2]->C[sti], 1.0, 1.0, 'N', 'N'); + BdivA_rrect(Kt_tdata_dm, Kt_tdata0_dm, '/', Dtdata_d4->F[t_2]->C[sti]); + //+ zt_tm1(:,t) = b(:,t) + Ft*zt_tm1(:,tdata) + Kt_tdata*etdata where t=tp1 and tm1=t. + etdata_sdv.v = etdata_dc->C[t_2]->M + ny*sti; + z0_sdv.v = zt_tm1_dc->C[t_2]->M + nz*sti; //sti: regime at time t_2. + MatrixTimesVector(ztp1_t_dv, Ft_dc->C[stp1i], &z0_sdv, 1.0, 0.0, 'N'); + MatrixTimesVector(ztp1_t_dv, Kt_tdata_dm, &etdata_sdv, 1.0, 1.0, 'N'); + btp1_sdv.v = bt_dm->M + stp1i*btp1_sdv.n; + VectorPlusMinusVectorUpdate(ztp1_t_dv, &btp1_sdv, 1.0); + //+ Pt_tm1(:,:,t) = Ft*Ptdata*Fttran - Kt_tdata*Dtdata*Kt_tdatatran + V(:,:,t); + CopyMatrix0(Ptp1_t_dm, Vt_dc->C[stp1i]); + MatrixTimesMatrix(Wnzbyny_dm, Kt_tdata_dm, Dtdata_d4->F[t_2]->C[sti], 1.0, 0.0, 'N', 'N'); + MatrixTimesMatrix(Wnzbynz_dm, Wnzbyny_dm, Kt_tdata_dm, 1.0, 0.0, 'N', 'T'); + MatrixPlusMinusMatrixUpdate(Ptp1_t_dm, Wnzbynz_dm, -1.0); + //Done with all W*_dm. + MatrixTimesMatrix(Wnzbynz_dm, Ft_dc->C[stp1i], Pt_tm1_d4->F[t_2]->C[sti], 1.0, 0.0, 'N', 'N'); + MatrixTimesMatrix(W2nzbynz_dm, Wnzbynz_dm, Ft_dc->C[stp1i], 1.0, 0.0, 'N', 'T'); + MatrixPlusMatrixUpdate(Ptp1_t_dm, W2nzbynz_dm); + //Done with all W*_dm. + + + //--- Integrating out the state at t_2 using + //--- P(s_t_2|Y_{t_2}, theta) = ProbabilityStateConditionalCurrent(sti, t_2, smodel_ps); + //--- One can also access to P(s_t_2|Y_{t_2}, theta) by using ElementV(smodel_ps->V[t_2],s_{t_2}i), + //--- but this access will not call my function logTimetCondLH(), thus no updating for + //--- P(s_t_2|Y_{t_2}, and thus leading to incorrect results. + //--- we must pass t_2+1 as opposed to t_2. + prob_previous_regimes = ProbabilityStateConditionalCurrent(sti, t_2+1, smodel_ps); + ScalarTimesVectorUpdate(ztp1_dv, prob_previous_regimes, ztp1_t_dv); + ScalarTimesMatrix(Ptp1_dm, prob_previous_regimes, Ptp1_t_dm, 1.0); + Ptp1_dm->flag = M_GE | M_SU | M_SL; + //Done with ztp1_t_dv and Ptp1_t_dm. + } + //--- Filling zt_tm1 and Pt_tm1 for next period. + z0_sdv.v = zt_tm1_dc->C[t_2p1]->M + z0_sdv.n*stp1i; //stp1i: regime at time tp1. + CopyVector0(&z0_sdv, ztp1_dv); + CopyMatrix0(Pt_tm1_d4->F[t_2p1]->C[stp1i], Ptp1_dm); //stp1i: regime at time tp1. + //Done with ztp1_dv, z0_sdv, Ptp1_dm. + } + //--- $$$ The following is important because it tells ProbabilityStateConditionalCurrent(), which calls + //--- $$$ logTimetCondLH_kalfilms_1stapp(), which calls recursively this function again, that there is no + //--- $$$ need to update Kalman filter for the period before kalfilmsinputs_1stapp_ps->ztm1_track. + kalfilmsinputs_1stapp_ps->ztm1_track = t_2p1; //Means that z_{t_2p1+1|t_2p1} and P_{t_2p1+1|t_2p1} are done. + + //--- $$$ This function must be called after all the above computations are done. + Update_et_Dt_1stapp(t_2p1, kalfilmsinputs_1stapp_ps); + } + + + //=== + DestroyMatrix_lf(Wnzbynz_dm); + // + DestroyMatrix_lf(Wnzbyny_dm); + DestroyMatrix_lf(W2nzbynz_dm); + DestroyMatrix_lf(Kt_tdata0_dm); + DestroyMatrix_lf(Kt_tdata_dm); + // + DestroyVector_lf(ztp1_t_dv); + DestroyMatrix_lf(Ptp1_t_dm); + DestroyVector_lf(ztp1_dv); + DestroyMatrix_lf(Ptp1_dm); + + return (kalfilmsinputs_1stapp_ps->ztm1_track); +} +//====================================================== +//= Computes etdata and Dtdata for all grand regimes st at tbase0=inpt-1 or dtm1_track +//= to prevent recomputing this object for different st at given tbase0. +//====================================================== +static int Update_et_Dt_1stapp(int t_1, struct TSkalfilmsinputs_1stapp_tag *kalfilmsinputs_1stapp_ps) +{ + //Output: + // dtm1_track is updated in this function. + // PHtran_tdata_d4->F[t-1] + // etdata_dc->C[t-1] + // Dtdata_d4->F[t-1] + //Input: + // t_1=inpt-1: base-0 timing for et and Dt before the likelihood at time inpt is computed. + + //--- Local variables + int sti, tbase0; + //-- Output arguments + TSdfourth *PHtran_tdata_d4 = kalfilmsinputs_1stapp_ps->PHtran_tdata_d4; //nz-by-ny-by-nst-T, saved only for updating Kalman filter Updatekalfilms_1stapp(). + TSdcell *etdata_dc = kalfilmsinputs_1stapp_ps->etdata_dc; //ny-by-nst-by-T, save for computing the likelihood. + TSdcell *yt_tm1_dc = kalfilmsinputs_1stapp_ps->yt_tm1_dc; //ny-by-nst-by-T, one-step forecast y_{t|t-1} for t=0 to T-1 (base-0). + TSdfourth *Dtdata_d4 = kalfilmsinputs_1stapp_ps->Dtdata_d4; //ny-by-ny-nst-by-T, save for computing the likelihood and updating Kalman filter Updatekalfilms_1stapp(). + //--- input arguments + TSdcell *zt_tm1_dc = kalfilmsinputs_1stapp_ps->zt_tm1_dc; //nz-by-nst-by-T. + TSdfourth *Pt_tm1_d4 = kalfilmsinputs_1stapp_ps->Pt_tm1_d4; //nz-by-nz-by-nst-by-T. + //+ + TSdmatrix *yt_dm = kalfilmsinputs_1stapp_ps->yt_dm; //ny-by-T. + TSdmatrix *at_dm = kalfilmsinputs_1stapp_ps->at_dm; //ny-by-nst. + TSdcell *Ht_dc = kalfilmsinputs_1stapp_ps->Ht_dc; //ny-by-nz-by-nst. + TSdcell *Rt_dc = kalfilmsinputs_1stapp_ps->Rt_dc; //ny-by-ny-by-nst. Covariance matrix for the measurement equation. + //--- Accessible variables + int ny = kalfilmsinputs_1stapp_ps->ny; + int nz = kalfilmsinputs_1stapp_ps->nz; + int nst = kalfilmsinputs_1stapp_ps->nst; + TSdvector z0_sdv; + TSdvector yt_sdv, at_sdv; + TSdvector etdata_sdv, yt_tm1_sdv; + //=== Work arguments. + TSdmatrix *PHtran_tdata_dm = CreateMatrix_lf(nz,ny); + TSdmatrix *Dtdata_dm = CreateMatrix_lf(ny,ny); + + + z0_sdv.n = nz; + z0_sdv.flag = V_DEF; + at_sdv.n = yt_sdv.n = ny; + at_sdv.flag = yt_sdv.flag = V_DEF; + etdata_sdv.n = yt_tm1_sdv.n = ny; + etdata_sdv.flag = yt_tm1_sdv.flag = V_DEF; + + for (tbase0=(kalfilmsinputs_1stapp_ps->dtm1_track+1); tbase0<=t_1; tbase0++) + { + //Note tbase0<=t_1, NOT tbase0<t_1. + //If t_1 < (dtm1_track+1), no updating. + //If t_1 >= (dtm1_track+1), updating etdata_dc->C[t-1] and Dtdata_d4->F[t-1] up to t-1=t_1. + + for (sti=nst-1; sti>=0; sti--) + { + //--- Setup. + MatrixTimesMatrix(PHtran_tdata_dm, Pt_tm1_d4->F[tbase0]->C[sti], Ht_dc->C[sti], 1.0, 0.0, 'N', 'T'); + CopyMatrix0(kalfilmsinputs_1stapp_ps->PHtran_tdata_d4->F[tbase0]->C[sti], PHtran_tdata_dm); + + + //--- Data. + //- etdata = Y_T(:,tdata) - a(:,tdata) - Htdata*ztdata where tdata = tbase0 = inpt-1. + yt_sdv.v = yt_dm->M + tbase0*yt_dm->nrows; + at_sdv.v = at_dm->M + sti*at_dm->nrows; //grand regime at time tbase0. + z0_sdv.v = zt_tm1_dc->C[tbase0]->M + z0_sdv.n*sti; //sti: regime at time tbase0. + etdata_sdv.v = etdata_dc->C[tbase0]->M + etdata_sdv.n*sti; + yt_tm1_sdv.v = etdata_dc->C[tbase0]->M + yt_tm1_sdv.n*sti; + CopyVector0(&yt_tm1_sdv, &at_sdv); + MatrixTimesVector(&yt_tm1_sdv, Ht_dc->C[sti], &z0_sdv, 1.0, 1.0, 'N'); //a + H*z_{t|t-1}. + VectorMinusVector(&etdata_sdv, &yt_sdv, &yt_tm1_sdv); //y_t - a - H*z_{t|t-1}. + //+ Dtdata = Htdata*PHtran_tdata + R(:,:,tbase0); + CopyMatrix0(Dtdata_dm, Rt_dc->C[sti]); + MatrixTimesMatrix(Dtdata_dm, Ht_dc->C[sti], PHtran_tdata_dm, 1.0, 1.0, 'N', 'N'); + //Done with z0_sdv.v. + ScalarTimesMatrixSquare(Dtdata_dm, 0.5, Dtdata_dm, 'T', 0.5); //Making it symmetric against some rounding errors. + //This making-symmetric is very IMPORTANT; otherwise, we will get the matrix being singular message + // and eigenvalues being negative for the SPD matrix, etc. Then the likelihood becomes either + // a bad number or a complex number. + Dtdata_dm->flag = Dtdata_dm->flag | M_SU | M_SL; + CopyMatrix0(Dtdata_d4->F[tbase0]->C[sti], Dtdata_dm); //Saved to be used for logTimetCondLH_kalfilms_1stapp(). + } + + //--- $$$ This tracker functions the same way as kalfilmsinputs_1stapp_ps->ztm1_track. + kalfilmsinputs_1stapp_ps->dtm1_track = tbase0; + } + + //=== + DestroyMatrix_lf(PHtran_tdata_dm); + DestroyMatrix_lf(Dtdata_dm); + + return (kalfilmsinputs_1stapp_ps->dtm1_track); +} + + + + + + +//----------------------------------------------------- +//------------ OLD Code -------------------------- +//- Updating or refreshing all Kalman filter at time t for Markov-switching DSGE model. +//- WARNING: make sure to call the following functions +// RunningGensys_const7varionly(lwzmodel_ps); +// Refresh_kalfilms_*(lwzmodel_ps); //Creates or refreshes kalfilmsinputs_ps at new parameter values. +//- before using tz_Refresh_z_T7P_T_in_kalfilms_1st_approx(). +// +//- IMPORTANT NOTE: in the Markov-switching input file datainp_markov*.prn, it MUST be that +//- the coefficient regime is the 1st state variable, and +//- the volatility regime is the 2nd state variable. +//----------------------------------------------------- +#if defined (NEWVERSIONofDW_SWITCH) +double tz_logTimetCondLH_kalfilms_1st_approx(int st, int inpt, struct TSkalfilmsinputs_tag *kalfilmsinputs_ps, struct TStateModel_tag *smodel_ps) +{ + //st, st_c, and st_v: base-0: deals with the cross-section values at time t where + // st is a grand regime, st_c is an encoded coefficient regime, and st_c is an encoded volatility regime. + //inpt: base-1 in the sense that inpt>=1 to deal with the time series situation where S_T is (T+1)-by-1 and Y_T is T+nlags_max-by-1. + // The 1st element for S_T is S_T[1] while S_T[0] is s_0 (initial condition). + // The 1st element for Y_T, however, is Y_T[nlags_max+1-1]. + //See (42.3) on p.42 in the SWZII NOTES. + + + //--- Local variables + int comst_c; //composite (s_tc, s_{t-1}c) + int st_c, stm1_c, st_v; + int comsti_c; //composite (s_tc, s_{t-1}c) + int sti, sti_c, stm1i_c, sti_v; + int comstp1i_c; //composite (s_{t+1}c, s_tc) + int stp1i, stp1i_c, stp1i_v; + int tbase0, tp1; + double logdet_Dtdata, loglh_timet; + static int record_tbase1_or_inpt_or_tp1 = 0; + static int passonce; + double prob_previous_regimes; + //=== Accessible variables + int ny = kalfilmsinputs_ps->ny; + int nz = kalfilmsinputs_ps->nz; + int nRc = kalfilmsinputs_ps->nRc; + int nRstc = kalfilmsinputs_ps->nRstc; + int nRv = kalfilmsinputs_ps->nRv; + int T = kalfilmsinputs_ps->T; + int indxIndRegimes = kalfilmsinputs_ps->indxIndRegimes; + int **Index = smodel_ps->sv->index; //Regime-switching states. + //smodel_ps->sv->index is for our new code. + // For old code (before 9 April 08 and before dsge_switch is created), use smodel_ps->sv->Index; + TSdvector z0_sdv; + //+ input arguments. + TSdmatrix *yt_dm = kalfilmsinputs_ps->yt_dm; //ny-by-T. + TSdmatrix *at_dm = kalfilmsinputs_ps->at_dm; //ny-by-nRc. + TSdcell *Ht_dc = kalfilmsinputs_ps->Ht_dc; //ny-by-nz-by-nRc. + TSdcell *Rt_dc = kalfilmsinputs_ps->Rt_dc; //ny-by-ny-by-nRv. Covariance matrix for the measurement equation. + TSdcell *Gt_dc = kalfilmsinputs_ps->Gt_dc; //nz-by-ny-by-nRv. Cross-covariance. + // + TSdmatrix *bt_dm = kalfilmsinputs_ps->bt_dm; //nz-by-nRc. + TSdcell *Ft_dc = kalfilmsinputs_ps->Ft_dc; //nz-by-nz-by-nRc. + TSdcell *Vt_dc = kalfilmsinputs_ps->Vt_dc; //nz-by-nz-by-nRv. Covariance matrix for the state equation. + // + TSdmatrix *z0_dm = kalfilmsinputs_ps->z0_dm; //nz-by-nRc*nRv or nz-by-nRv, depending on indxIndRegimes. + TSdcell *P0_dc = kalfilmsinputs_ps->P0_dc; //nz-by-nz-by-nRc*nRv or nz-by-nRv, depending on indxIndRegimes. + //+ Output arguments. + TSdcell *zt_tm1_dc = kalfilmsinputs_ps->zt_tm1_dc; //nz-by-nRc*nRv-by-T if indxIndRegimes==1, nz-by-nRv-by-T if indxIndRegimes==0 where nRc=nRv. + TSdfourth *Pt_tm1_d4 = kalfilmsinputs_ps->Pt_tm1_d4; //nz-by-nz-by-nRc*nRv-T if indxIndRegimes==1, nz-by-nz-by-nRv-by-T if indxIndRegimes==0 where nRc=nRv. + //=== Work arguments. + int nz2 = square(nz); + TSdmatrix *Wnzbynz_dm = CreateMatrix_lf(nz,nz); + TSdmatrix *Wnz2bynz2_dm = CreateMatrix_lf(nz2,nz2); + TSdmatrix *W2nz2bynz2_dm = CreateMatrix_lf(nz2,nz2); + TSdvector *wP0_dv = CreateVector_lf(nz2); + //+ + TSdvector yt_sdv, at_sdv, btp1_sdv; //zt_tm1_sdv, ztp1_t_sdv, + TSdvector *wny_dv = CreateVector_lf(ny); + TSdmatrix *Wnzbyny_dm = CreateMatrix_lf(nz,ny); + TSdmatrix *W2nzbynz_dm = CreateMatrix_lf(nz,nz); + TSdmatrix *PHtran_tdata_dm = CreateMatrix_lf(nz,ny); + TSdvector *etdata_dv = CreateVector_lf(ny); + TSdmatrix *Dtdata_dm = CreateMatrix_lf(ny,ny); + TSdmatrix *Kt_tdata0_dm = CreateMatrix_lf(nz,ny); + TSdmatrix *Kt_tdata_dm = CreateMatrix_lf(nz,ny); + //--- For eigenvalue decompositions + int ki; + int errflag; + double eigmax; + TSdzvector *evals_dzv = evals_dzv = CreateVector_dz(nz); + TSdvector *evals_abs_dv = CreateVector_lf(nz); //Absolute eigenvalues. + //--- For updating zt_tm1_dm and Pt_tm1. + TSdvector *ztp1_t_dv = CreateVector_lf(z0_dm->nrows); + TSdmatrix *Ptp1_t_dm = CreateMatrix_lf(nz, nz); + TSdvector *ztp1_dv = CreateVector_lf(z0_dm->nrows); + TSdmatrix *Ptp1_dm = CreateMatrix_lf(nz, nz); + + + + if (smodel_ps->sv->nstates != z0_dm->ncols) fn_DisplayError("kalman.c/tz_logTimetLH_kalfilms_1st_approx():\n" + " Make sure that the column dimension of z0_dm is the same as smodel_ps->sv->nstates"); + if (indxIndRegimes && (nRc>1) && (nRv>1)) + if (smodel_ps->sv->n_state_variables != 2) fn_DisplayError("kalman.c/tz_Refresh_z_T7P_T_in_kalfilms_1st_approx():\n" + " Number of state variables must be coincide with indxIndRegimes"); + + tbase0 = (tp1=inpt) - 1; + + z0_sdv.n = z0_dm->nrows; + z0_sdv.flag = V_DEF; + // + at_sdv.n = yt_sdv.n = yt_dm->nrows; + at_sdv.flag = yt_sdv.flag = V_DEF; + btp1_sdv.n = bt_dm->nrows; + btp1_sdv.flag = V_DEF; + + + //======= Initial condition. ======= + if (tbase0==0) + { + for (sti=smodel_ps->sv->nstates-1; sti>=0; sti--) + { + if (indxIndRegimes) + { + if (nRc==1) //Volatility. + { + comsti_c = sti_c = 0; + sti_v = sti; + } + else if ((nRv>1) && (nRc>nRstc)) //Trend inflation, both sc_t and sc_{t-1} enters coefficient regime. + { + comsti_c = Index[sti][0]; //composite (s_tc, s_{t-1}c) + sti_v = Index[sti][1]; //volatility state s_tv + sti_c = smodel_ps->sv->state_variable[0]->lag_index[comsti_c][0]; //coefficient regime at t. + stm1i_c = smodel_ps->sv->state_variable[0]->lag_index[comsti_c][1]; //coefficient regime at t-1: tm1: t-1; + } + else if ((nRv==1) && (nRc>nRstc)) + { + comsti_c = Index[sti][0]; //composite (s_tc, s_{t-1}c) + sti_c = smodel_ps->sv->state_variable[0]->lag_index[comsti_c][0]; //coefficient regime at t. + stm1i_c = smodel_ps->sv->state_variable[0]->lag_index[comsti_c][1]; //coefficient regime at t-1: tm1: t-1; + sti_v = 0; + } + else if ((nRv==1) && (nRc==nRstc)) + { + comsti_c = sti_c = sti; + sti_v = 0; + } + else if ((nRv>1) && (nRc==nRstc)) //only sc_t enters coefficient regime. + { + comsti_c = sti_c = Index[sti][0]; + sti_v = Index[sti][1]; + } + } + else //Syncronized regimes. + { + if (nRc>nRstc) + { + comsti_c = Index[sti][0]; //composite (s_tc, s_{t-1}c) + sti_c = smodel_ps->sv->state_variable[0]->lag_index[comsti_c][0]; //coefficient regime at t. + stm1i_c = smodel_ps->sv->state_variable[0]->lag_index[comsti_c][1]; //coefficient regime at t-1: tm1: t-1; + sti_v = sti_c; + } + else + comsti_c = sti_c = sti_v = sti; + } + + + if (!kalfilmsinputs_ps->indxIni) + { + InitializeDiagonalMatrix_lf(Wnzbynz_dm, 1.0); //To be used for I(nz) - + InitializeDiagonalMatrix_lf(Wnz2bynz2_dm, 1.0); //To be used for I(nz2) - + + //=== Eigenanalysis to determine the roots to ensure boundedness. + errflag = eigrgen(evals_dzv, (TSdzmatrix *)NULL, (TSdzmatrix *)NULL, Ft_dc->C[comsti_c]); + if (errflag) fn_DisplayError("kalman.c/tz_Refresh_z_T7P_T_in_kalfilms_1st_approx(): eigen decomposition failed"); + for (ki=nz-1; ki>=0; ki--) evals_abs_dv->v[ki] = sqrt(square(evals_dzv->real->v[ki]) + square(evals_dzv->imag->v[ki])); + evals_abs_dv->flag = V_DEF; + eigmax = MaxVector(evals_abs_dv); + if (eigmax < (1.0+1.0e-14)) + { + //--- Getting z0_dv: zt_tm1(:,1) = (eye(n_z)-F(:,:,1))\b(:,1); + MatrixMinusMatrix(Wnzbynz_dm, Wnzbynz_dm, Ft_dc->C[comsti_c]); + z0_sdv.v = z0_dm->M + z0_sdv.n*sti; + CopySubmatrix2vector(&z0_sdv, 0, bt_dm, 0, comsti_c, bt_dm->nrows); + bdivA_rgens(&z0_sdv, &z0_sdv, '\\', Wnzbynz_dm); + //Done with Wnzbynz_dm. + //--- Getting P0_dm: Pt_tm1(:,:,1) = reshape((eye(n_z^2)-kron(F(:,:,1),F(:,:,1)))\V1(:),n_z,n_z); + tz_kron(W2nz2bynz2_dm, Ft_dc->C[comsti_c], Ft_dc->C[comsti_c]); + MatrixMinusMatrix(Wnz2bynz2_dm, Wnz2bynz2_dm, W2nz2bynz2_dm); + CopySubmatrix2vector(wP0_dv, 0, Vt_dc->C[sti_v], 0, 0, nz2); +//=== ???????? For debugging purpose. +//if ((inpt<2) && (st==0)) +//{ +// fprintf(FPTR_DEBUG, "%%st=%d, inpt=%d, and sti=%d\n", st, inpt, sti); + +// fprintf(FPTR_DEBUG, "wP0_dv:\n"); +// WriteVector(FPTR_DEBUG, wP0_dv, " %10.5f "); +// fprintf(FPTR_DEBUG, "Vt_dc->C[sti_v=%d]:\n", sti_v); +// WriteMatrix(FPTR_DEBUG, Vt_dc->C[sti_v], " %10.5f "); + +// fflush(FPTR_DEBUG); + +//} + bdivA_rgens(wP0_dv, wP0_dv, '\\', Wnz2bynz2_dm); + CopySubvector2matrix_unr(P0_dc->C[sti], 0, 0, wP0_dv, 0, nz2); + //Done with all w*_dv and W*_dm. + } + else + { + fprintf(stdout, "\n-----------------\n"); + fprintf(stdout, "\nIn regime comsti_c=%d and sti_v=%d and at time=%d\n", comsti_c, sti_v, 0); + fn_DisplayError("kalman.c/tz_Refresh_z_T7P_T_in_kalfilms_1st_approx(): the system is non-stationary solutions\n" + " and the initial conditions must be supplied by, say, input arguments"); + fflush(stdout); + } + } + } + z0_dm->flag = M_GE; + CopyMatrix0(zt_tm1_dc->C[0], z0_dm); //At time t=0. + CopyCell0(Pt_tm1_d4->F[0], P0_dc); //At time t=0. + } + + + //====================================================== + //= Getting the logLH at time tbase0 or time inpt. + //====================================================== + if (indxIndRegimes ) + { + if (nRc==1) //Volatility. + { + comst_c = st_c = 0; + st_v = st; + } + else if ((nRv>1) && (nRc>nRstc)) //Trend inflation, both sc_t and sc_{t-1} enters coefficient regime. + { + if (smodel_ps->sv->n_state_variables != 2) fn_DisplayError("kalman.c/kalfilms_timet_1st_approx():\n" + " Number of state variables must be coincide with indxIndRegimes"); + + comst_c = Index[st][0]; //composite (s_tc, s_{t-1}c) + st_v = Index[st][1]; //volatility state s_tv + st_c = smodel_ps->sv->state_variable[0]->lag_index[comst_c][0]; //coefficient regime at t. + stm1_c = smodel_ps->sv->state_variable[0]->lag_index[comst_c][1]; //coefficient regime at t-1: tm1: t-1; + } + else if ((nRv==1) && (nRc>nRstc)) + { + comst_c = Index[st][0]; //composite (s_tc, s_{t-1}c) + st_c = smodel_ps->sv->state_variable[0]->lag_index[comst_c][0]; //coefficient regime at t. + stm1_c = smodel_ps->sv->state_variable[0]->lag_index[comst_c][1]; //coefficient regime at t-1: tm1: t-1; + st_v = 0; + } + else if ((nRv==1) && (nRc==nRstc)) + { + comst_c = st_c = st; + st_v = 0; + } + else if ((nRv>1) && (nRc==nRstc)) //only sc_t enters coefficient regime. + { + if (smodel_ps->sv->n_state_variables != 2) fn_DisplayError("kalman.c/kalfilms_timet_1st_approx():\n" + " Number of state variables must be coincide with indxIndRegimes"); + + comst_c = st_c = Index[st][0]; + st_v = Index[st][1]; + } + } + else //Syncronized regimes + { + if (nRc>nRstc) + { + comst_c = Index[st][0]; //composite (s_tc, s_{t-1}c) + st_c = smodel_ps->sv->state_variable[0]->lag_index[comst_c][0]; //coefficient regime at t. + stm1_c = smodel_ps->sv->state_variable[0]->lag_index[comst_c][1]; //coefficient regime at t-1: tm1: t-1; + st_v = st_c; + } + else + comst_c = st_c = st_v = st; + } + + + z0_sdv.n = zt_tm1_dc->C[0]->nrows; + z0_sdv.flag = V_DEF; + // + at_sdv.n = yt_sdv.n = yt_dm->nrows; + at_sdv.flag = yt_sdv.flag = V_DEF; + + //====== Computing the conditional LH at time t. ====== + //--- Setup. + MatrixTimesMatrix(PHtran_tdata_dm, Pt_tm1_d4->F[tbase0]->C[st], Ht_dc->C[comst_c], 1.0, 0.0, 'N', 'T'); + + //--- Data. + //- etdata = Y_T(:,tdata) - a(:,tdata) - Htdata*ztdata where tdata = tbase0 = inpt-1. + yt_sdv.v = yt_dm->M + tbase0*yt_dm->nrows; + at_sdv.v = at_dm->M + comst_c*at_dm->nrows; //comst_c: coefficient regime at time tbase0. + z0_sdv.v = zt_tm1_dc->C[tbase0]->M + z0_sdv.n*st; //st: regime at time tbase0 for zt_tm1. + VectorMinusVector(etdata_dv, &yt_sdv, &at_sdv); + MatrixTimesVector(etdata_dv, Ht_dc->C[comst_c], &z0_sdv, -1.0, 1.0, 'N'); + //+ Dtdata = Htdata*PHtran_tdata + R(:,:,tbase0); + CopyMatrix0(Dtdata_dm, Rt_dc->C[st_v]); + MatrixTimesMatrix(Dtdata_dm, Ht_dc->C[comst_c], PHtran_tdata_dm, 1.0, 1.0, 'N', 'N'); + ScalarTimesMatrixSquare(Dtdata_dm, 0.5, Dtdata_dm, 'T', 0.5); //Making it symmetric against some rounding errors. + //This making-symmetric is very IMPORTANT; otherwise, we will get the matrix being singular message + // and eigenvalues being negative for the SPD matrix, etc. Then the likelihood becomes either + // a bad number or a complex number. + Dtdata_dm->flag = Dtdata_dm->flag | M_SU | M_SL; + + + //--- Forming the log conditional likelihood at t. + if (!isfinite(logdet_Dtdata=logdetspd(Dtdata_dm))) return (loglh_timet = -NEARINFINITY); + bdivA_rgens(wny_dv, etdata_dv, '/', Dtdata_dm); +//if ((inpt>82) && (inpt<86) ) +//{ +// //Must be declared at the top of this "if" block. +// int kip1; +// double tmp_Dtdata; +// double tmp_expterm; + +// fprintf(FPTR_DEBUG, "%%------------------------\n"); +// fprintf(FPTR_DEBUG, "%%st=%d and inpt=%d\n", st, inpt); +// fprintf(FPTR_DEBUG, "loglh_timet = %10.5f;\n", loglh_timet); + + +// fprintf(FPTR_DEBUG, "wny_dv:\n"); +// WriteVector(FPTR_DEBUG, wny_dv, " %10.5f "); +// fprintf(FPTR_DEBUG, "etdata_dv:\n"); +// WriteVector(FPTR_DEBUG, etdata_dv, " %10.5f "); +// fprintf(FPTR_DEBUG, "Dtdata_dm:\n"); +// WriteMatrix(FPTR_DEBUG, Dtdata_dm, " %.16e "); + +// fflush(FPTR_DEBUG); +//} + loglh_timet = -(0.5*ny)*LOG2PI - 0.5*logdet_Dtdata - 0.5*VectorDotVector(wny_dv, etdata_dv); + //Done with all w*_dv. + + + + +//=== ???????? For debugging purpose. +if (inpt==1) +{ + double wk1, wk2; + + wk1 = logdet_Dtdata; + wk2 = VectorDotVector(wny_dv, etdata_dv); + fprintf(FPTR_DEBUG, "logdet_Dtdata = %10.5f\n", wk1); + fprintf(FPTR_DEBUG, "VectorDotVector(wny_dv, etdata_dv) = %10.5f\n", wk2); + fprintf(FPTR_DEBUG, "----- etdata_dv: \n"); + WriteVector(FPTR_DEBUG, etdata_dv, " %10.5f "); + fprintf(FPTR_DEBUG, "----- yt_dv: \n"); + WriteVector(FPTR_DEBUG, &yt_sdv, " %10.5f "); + fprintf(FPTR_DEBUG, "----- at_dv: \n"); + WriteVector(FPTR_DEBUG, &at_sdv, " %10.5f "); + fprintf(FPTR_DEBUG, "----- z0_dv: \n"); + WriteVector(FPTR_DEBUG, &z0_sdv, " %10.5f "); + fprintf(FPTR_DEBUG, "----- Ht_dc->C[comst_c=%d]:\n", comst_c); + WriteMatrix(FPTR_DEBUG, Ht_dc->C[comst_c], " %10.5f "); + + fprintf(FPTR_DEBUG, "\n\n"); + +} +// +fprintf(FPTR_DEBUG, " %10.5f\n", loglh_timet); +fflush(FPTR_DEBUG); + + +//=== ???????? For debugging purpose. +//fprintf(FPTR_DEBUG, "------------------------\n"); +//fprintf(FPTR_DEBUG, "st=%d and inpt=%d\n", st, inpt); +//fprintf(FPTR_DEBUG, "loglh_timet = %10.5f\n", loglh_timet); +//fprintf(FPTR_DEBUG, "&yt_sdv:\n"); +//WriteVector(FPTR_DEBUG, &yt_sdv, " %10.5f "); +////WriteVector(FPTR_DEBUG, etdata_dv, " %10.5f "); +////fprintf(FPTR_DEBUG, "\n"); +////WriteMatrix(FPTR_DEBUG, Dtdata_dm, " %10.5f "); +//fflush(FPTR_DEBUG); + + +//=== ???????? For debugging purpose. +//if ((inpt>82) && (inpt<86) ) +//if (inpt<2) +//{ +// //Must be declared at the top of this "if" block. +// int kip1; +// double tmp_Dtdata; +// double tmp_expterm; + +// fprintf(FPTR_DEBUG, "%%------------------------\n"); +// fprintf(FPTR_DEBUG, "%%st=%d and inpt=%d\n", st, inpt); +// fprintf(FPTR_DEBUG, "loglh_timet = %10.5f;\n", loglh_timet); + + +// tmp_Dtdata = logdeterminant(Dtdata_dm); +// tmp_expterm = VectorDotVector(wny_dv, etdata_dv); +// fprintf(FPTR_DEBUG, "logdeterminant(Dtdata_dm) = %10.5f;\n", tmp_Dtdata); +// fprintf(FPTR_DEBUG, "VectorDotVector(wny_dv, etdata_dv) = %10.5f;\n", tmp_expterm); +// fprintf(FPTR_DEBUG, "wny_dv:\n"); +// WriteVector(FPTR_DEBUG, wny_dv, " %10.5f "); +// fprintf(FPTR_DEBUG, "etdata_dv:\n"); +// WriteVector(FPTR_DEBUG, etdata_dv, " %10.5f "); +// fprintf(FPTR_DEBUG, "&yt_sdv:\n"); +// WriteVector(FPTR_DEBUG, &yt_sdv, " %10.5f "); +// fprintf(FPTR_DEBUG, "&at_sdv:\n"); +// WriteVector(FPTR_DEBUG, &at_sdv, " %10.5f "); +// fprintf(FPTR_DEBUG, "&z0_sdv:\n"); +// WriteVector(FPTR_DEBUG, &z0_sdv, " %10.5f "); +// fprintf(FPTR_DEBUG, "Ht_dc->C[comst_c=%d]:\n",comst_c); +// WriteMatrix(FPTR_DEBUG, Ht_dc->C[comst_c], " %10.5f "); +// fprintf(FPTR_DEBUG, "Rt_dc->C[st_v=%d]:\n", st_v); +// WriteMatrix(FPTR_DEBUG, Rt_dc->C[st_v], " %10.5f "); +// fprintf(FPTR_DEBUG, "Pt_tm1_d4->F[tbase0]->C[st = %d]:\n",st); +// WriteMatrix(FPTR_DEBUG, Pt_tm1_d4->F[tbase0]->C[st], " %10.5f "); +// fprintf(FPTR_DEBUG, "Dtdata_dm:\n"); +// WriteMatrix(FPTR_DEBUG, Dtdata_dm, " %10.5f "); + + + + +//// WriteMatrix(FPTR_DEBUG, Dtdata_dm, " %10.5f "); +//// fprintf(FPTR_DEBUG, "zt_tm1_dc->C[tbase0]:\n"); +//// WriteMatrix(FPTR_DEBUG, zt_tm1_dc->C[tbase0], " %10.5f "); +//// //WriteVector(FPTR_DEBUG, &z0_sdv, " %10.5f "); +//// //fprintf(FPTR_DEBUG, "\n"); +//// fprintf(FPTR_DEBUG, "bt_dm = [\n"); +//// WriteMatrix(FPTR_DEBUG, bt_dm, " %10.5f "); +//// fprintf(FPTR_DEBUG, "];\n"); + +//// fprintf(FPTR_DEBUG, "et:\n"); +//// WriteVector(FPTR_DEBUG, etdata_dv, " %10.5f "); +//// fprintf(FPTR_DEBUG, "yt_dv=[\n"); +//// WriteVector(FPTR_DEBUG, &yt_sdv, " %10.5f "); +//// fprintf(FPTR_DEBUG, "]';\n"); + +//// fprintf(FPTR_DEBUG, "at_dv=[\n"); +//// WriteVector(FPTR_DEBUG, &at_sdv, " %10.5f "); +//// fprintf(FPTR_DEBUG, "]';\n"); + + +//// for (ki=0; ki<Ht_dc->ncells; ki++) +//// { +//// kip1 = ki+1; +//// fprintf(FPTR_DEBUG, "Ht_dc(:,:,%d)=[\n", kip1); +//// WriteMatrix(FPTR_DEBUG, Ht_dc->C[ki], " %10.5f "); +//// fprintf(FPTR_DEBUG, "];\n"); +//// } +//// for (ki=0; ki<Ft_dc->ncells; ki++) +//// { +//// kip1 = ki+1; +//// fprintf(FPTR_DEBUG, "Ft_dc(:,:,%d)=[\n", kip1); +//// WriteMatrix(FPTR_DEBUG, Ft_dc->C[ki], " %10.5f "); +//// fprintf(FPTR_DEBUG, "];\n"); +//// } +//// for (ki=0; ki<Vt_dc->ncells; ki++) +//// { +//// kip1 = ki+1; +//// fprintf(FPTR_DEBUG, "Vt_dc(:,:,%d)=[\n", kip1); +//// WriteMatrix(FPTR_DEBUG, Vt_dc->C[ki], " %10.5f "); +//// fprintf(FPTR_DEBUG, "];\n"); +//// } +// fflush(FPTR_DEBUG); +//} + + + //====================================================== + //= Updating zt_tm1 and Pt_tm1 for next perid tp1. + //= tdata = tbase0 is base-0 timing. + //====================================================== + if (inpt > record_tbase1_or_inpt_or_tp1) //This condition always satisfies at the 1st period (which is inpt=1). + { + passonce = 0; + record_tbase1_or_inpt_or_tp1 = inpt; + } + if (!passonce) + { + for (stp1i=smodel_ps->sv->nstates-1; stp1i>=0; stp1i--) + { + if (indxIndRegimes) + { + if (nRc==1) //Volatility. + { + comstp1i_c = stp1i_c = 0; + stp1i_v = stp1i; + } + else if ((nRv>1) && (nRc>nRstc)) //Trend inflation, both sc_t and sc_{t-1} enters coefficient regime. + { + comstp1i_c = Index[stp1i][0]; //composite (s_tc, s_{t-1}c) + stp1i_v = Index[stp1i][1]; //volatility state s_tv + stp1i_c = smodel_ps->sv->state_variable[0]->lag_index[comstp1i_c][0]; //coefficient regime at t. + //sti_c = smodel_ps->sv->state_variable[0]->lag_index[comstp1i_c][1]; //coefficient regime at t-1: tm1: t-1; + } + else if ((nRv==1) && (nRc>nRstc)) + { + comstp1i_c = Index[stp1i][0]; //composite (s_tc, s_{t-1}c) + stp1i_c = smodel_ps->sv->state_variable[0]->lag_index[comstp1i_c][0]; //coefficient regime at t. + //sti_c = smodel_ps->sv->state_variable[0]->lag_index[comstp1i_c][1]; //coefficient regime at t-1: tm1: t-1; + stp1i_v = 0; + } + else if ((nRv==1) && (nRc==nRstc)) + { + comstp1i_c = stp1i_c = stp1i; + stp1i_v = 0; + } + else if ((nRv>1) && (nRc==nRstc)) //only sc_t enters coefficient regime. + { + comstp1i_c = stp1i_c = Index[stp1i][0]; + stp1i_v = Index[stp1i][1]; + } + } + else //Syncronized regimes. + { + if (nRc>nRstc) + { + comstp1i_c = Index[stp1i][0]; //composite (s_tc, s_{t-1}c) + stp1i_c = smodel_ps->sv->state_variable[0]->lag_index[comstp1i_c][0]; //coefficient regime at t. + //sti_c = smodel_ps->sv->state_variable[0]->lag_index[comstp1i_c][1]; //coefficient regime at t-1: tm1: t-1; + stp1i_v = stp1i_c; + } + else + comstp1i_c = stp1i_c = stp1i_v = stp1i; + } + + + InitializeConstantVector_lf(ztp1_dv, 0.0); //To be summed over sti. + InitializeConstantMatrix_lf(Ptp1_dm, 0.0); //To be summed over sti. + + for (sti=smodel_ps->sv->nstates-1; sti>=0; sti--) + { + if (indxIndRegimes) + { + if (nRc==1) //Volatility. + { + comsti_c = sti_c = 0; + sti_v = sti; + } + else if ((nRv>1) && (nRc>nRstc)) //Trend inflation, both sc_t and sc_{t-1} enters coefficient regime. + { + comsti_c = Index[sti][0]; //composite (s_tc, s_{t-1}c) + sti_v = Index[sti][1]; //volatility state s_tv + sti_c = smodel_ps->sv->state_variable[0]->lag_index[comsti_c][0]; //coefficient regime at t. + stm1i_c = smodel_ps->sv->state_variable[0]->lag_index[comsti_c][1]; //coefficient regime at t-1: tm1: t-1; + } + else if ((nRv==1) && (nRc>nRstc)) + { + comsti_c = Index[sti][0]; //composite (s_tc, s_{t-1}c) + sti_c = smodel_ps->sv->state_variable[0]->lag_index[comsti_c][0]; //coefficient regime at t. + stm1i_c = smodel_ps->sv->state_variable[0]->lag_index[comsti_c][1]; //coefficient regime at t-1: tm1: t-1; + sti_v = 0; + } + else if ((nRv==1) && (nRc==nRstc)) + { + comsti_c = sti_c = sti; + sti_v = 0; + } + else if ((nRv>1) && (nRc==nRstc)) //only sc_t enters coefficient regime. + { + comsti_c = sti_c = Index[sti][0]; + sti_v = Index[sti][1]; + } + } + else //Syncronized regimes. + { + if (nRc>nRstc) + { + comsti_c = Index[sti][0]; //composite (s_tc, s_{t-1}c) + sti_c = smodel_ps->sv->state_variable[0]->lag_index[comsti_c][0]; //coefficient regime at t. + stm1i_c = smodel_ps->sv->state_variable[0]->lag_index[comsti_c][1]; //coefficient regime at t-1: tm1: t-1; + sti_v = sti_c; + } + else + comsti_c = sti_c = sti_v = sti; + } + + + //--- Setup. + MatrixTimesMatrix(PHtran_tdata_dm, Pt_tm1_d4->F[tbase0]->C[sti], Ht_dc->C[comsti_c], 1.0, 0.0, 'N', 'T'); + + //--- Data. + //- etdata = Y_T(:,tdata) - a(:,tdata) - Htdata*ztdata where tdata = tbase0 = inpt-1. + yt_sdv.v = yt_dm->M + tbase0*yt_dm->nrows; + at_sdv.v = at_dm->M + comsti_c*at_dm->nrows; //comsti_c: coefficient regime at time tbase0. + z0_sdv.v = zt_tm1_dc->C[tbase0]->M + z0_sdv.n*sti; //sti: regime at time tbase0. + VectorMinusVector(etdata_dv, &yt_sdv, &at_sdv); + MatrixTimesVector(etdata_dv, Ht_dc->C[comsti_c], &z0_sdv, -1.0, 1.0, 'N'); + //+ Dtdata = Htdata*PHtran_tdata + R(:,:,tbase0); + CopyMatrix0(Dtdata_dm, Rt_dc->C[sti_v]); + MatrixTimesMatrix(Dtdata_dm, Ht_dc->C[comsti_c], PHtran_tdata_dm, 1.0, 1.0, 'N', 'N'); + //Done with z0_sdv.v. + ScalarTimesMatrixSquare(Dtdata_dm, 0.5, Dtdata_dm, 'T', 0.5); //Making it symmetric against some rounding errors. + //This making-symmetric is very IMPORTANT; otherwise, we will get the matrix being singular message + // and eigenvalues being negative for the SPD matrix, etc. Then the likelihood becomes either + // a bad number or a complex number. + Dtdata_dm->flag = Dtdata_dm->flag | M_SU | M_SL; + + + //=== Updating for next period by integrating out sti.. + if (tp1<T) + { + //Updating only up to tbase0=T-2. The values at tp1=T or tbase0=T-1 will not be used in the likelihood function. + + //--- Ktp1_t = (F_tp1*PHtran_t+G(:,:,t))/Dt; + //--- Kt_tdata = (Ft*PHtran_tdata+G(:,:,tdata))/Dtdata where t=tp1 and tdata=t. + CopyMatrix0(Kt_tdata0_dm, Gt_dc->C[sti_v]); + MatrixTimesMatrix(Kt_tdata0_dm, Ft_dc->C[stp1i_c], PHtran_tdata_dm, 1.0, 1.0, 'N', 'N'); + BdivA_rrect(Kt_tdata_dm, Kt_tdata0_dm, '/', Dtdata_dm); + //+ zt_tm1(:,t) = b(:,t) + Ft*zt_tm1(:,tdata) + Kt_tdata*etdata where t=tp1 and tm1=t. + MatrixTimesVector(ztp1_t_dv, Ft_dc->C[stp1i_c], &z0_sdv, 1.0, 0.0, 'N'); + MatrixTimesVector(ztp1_t_dv, Kt_tdata_dm, etdata_dv, 1.0, 1.0, 'N'); + btp1_sdv.v = bt_dm->M + stp1i_c*btp1_sdv.n; + VectorPlusMinusVectorUpdate(ztp1_t_dv, &btp1_sdv, 1.0); + //+ Pt_tm1(:,:,t) = Ft*Ptdata*Fttran - Kt_tdata*Dtdata*Kt_tdatatran + V(:,:,t); + CopyMatrix0(Ptp1_t_dm, Vt_dc->C[stp1i_v]); + MatrixTimesMatrix(Wnzbyny_dm, Kt_tdata_dm, Dtdata_dm, 1.0, 0.0, 'N', 'N'); + MatrixTimesMatrix(Wnzbynz_dm, Wnzbyny_dm, Kt_tdata_dm, 1.0, 0.0, 'N', 'T'); + MatrixPlusMinusMatrixUpdate(Ptp1_t_dm, Wnzbynz_dm, -1.0); + //Done with all W*_dm. + MatrixTimesMatrix(Wnzbynz_dm, Ft_dc->C[stp1i_c], Pt_tm1_d4->F[tbase0]->C[sti], 1.0, 0.0, 'N', 'N'); + MatrixTimesMatrix(W2nzbynz_dm, Wnzbynz_dm, Ft_dc->C[stp1i_c], 1.0, 0.0, 'N', 'T'); + MatrixPlusMatrixUpdate(Ptp1_t_dm, W2nzbynz_dm); + //Done with all W*_dm. + + //--- Integrating out the state at tbase0 using P(s_t|Y_{t-1}, theta) = ElementV(smodel_ps->Z[inpt],s_{inpt}_i). + //--- Note tbase0 = inpt-1 because the data in DW code (ElementV) is base-1. + //--- Note at this point, we cannot access to P(s_t|Y_t, theta) = ElementV(smodel_ps->V[inpt],s_{inpt}_i) + //--- through DW's code. But we can modify my own code to do this later. + prob_previous_regimes = ElementV(smodel_ps->Z[inpt],sti); + ScalarTimesVectorUpdate(ztp1_dv, prob_previous_regimes, ztp1_t_dv); + ScalarTimesMatrix(Ptp1_dm, prob_previous_regimes, Ptp1_t_dm, 1.0); + Ptp1_dm->flag = M_GE | M_SU | M_SL; + //Done with ztp1_t_dv and Ptp1_t_dm. + } + } + //--- Filling zt_tm1 and Pt_tm1 for next period + if (tp1<T) + { + z0_sdv.v = zt_tm1_dc->C[tp1]->M + z0_sdv.n*stp1i; //stp1i: regime at time tp1. + CopyVector0(&z0_sdv, ztp1_dv); + CopyMatrix0(Pt_tm1_d4->F[tp1]->C[stp1i], Ptp1_dm); //stp1i: regime at time tp1. + //Done with ztp1_dv, z0_sdv, Ptp1_dm. + } + } + if (tp1<T) + zt_tm1_dc->C[tp1]->flag = M_GE; + } + + +//=== ???????? For debugging purpose. +//if ((inpt>60) && (inpt<65) ) //if (inpt<5) +//{ +// int kip1; //Must be declared at the top of this "if" block. + +// fprintf(FPTR_DEBUG, "zt_tm1t=[\n"); +// WriteMatrix(FPTR_DEBUG, zt_tm1_dc->C[tbase0], " %10.5f "); +// fprintf(FPTR_DEBUG, "];\n"); + +// for (ki=0; ki<Pt_tm1_d4->F[tbase0]->ncells; ki++) +// { +// kip1 = ki+1; +// fprintf(FPTR_DEBUG, "Pt_tm1_d4t(:,:,%d)=[\n", kip1); +// WriteMatrix(FPTR_DEBUG, Pt_tm1_d4->F[tbase0]->C[ki], " %10.5f "); +// fprintf(FPTR_DEBUG, "];\n"); +// } + +// fflush(FPTR_DEBUG); +//} + + +//=== ???????? For debugging purpose. +fprintf(FPTR_DEBUG, " loglh_timet = %10.5f\n", loglh_timet); +fflush(FPTR_DEBUG); + + + //=== + DestroyVector_dz(evals_dzv); + DestroyVector_lf(evals_abs_dv); + DestroyMatrix_lf(Wnzbynz_dm); + DestroyMatrix_lf(Wnz2bynz2_dm); + DestroyMatrix_lf(W2nz2bynz2_dm); + DestroyVector_lf(wP0_dv); + // + DestroyVector_lf(wny_dv); + DestroyMatrix_lf(Wnzbyny_dm); + DestroyMatrix_lf(W2nzbynz_dm); + DestroyMatrix_lf(PHtran_tdata_dm); + DestroyVector_lf(etdata_dv); + DestroyMatrix_lf(Dtdata_dm); + DestroyMatrix_lf(Kt_tdata0_dm); + DestroyMatrix_lf(Kt_tdata_dm); + // + DestroyVector_lf(ztp1_t_dv); + DestroyMatrix_lf(Ptp1_t_dm); + DestroyVector_lf(ztp1_dv); + DestroyMatrix_lf(Ptp1_dm); + + return (loglh_timet); +} +#undef LOG2PI +#endif + + +/** +//---------------------------------------------------------------- +//-- Tested OK, but has not use because tz_Refresh_z_T7P_T_in_kalfilms_1st_approx() +//-- cannot access to ElementV(smodel_ps->V[tp1],sti) or ElementV(smodel_ps->V[tbase0],sti) +//-- because no likelihood has been formed at all before this function is called. +//---------------------------------------------------------------- +#define LOG2PI (1.837877066409345e+000) //log(2*pi) +//----------------------------------------------------- +//- Updating or refreshing all Kalman filter at time t for Markov-switching DSGE model. +//- WARNING: make sure to call the following functions +// RunningGensys_const7varionly(lwzmodel_ps); +// Refresh_kalfilms_*(lwzmodel_ps); //Creates or refreshes kalfilmsinputs_ps at new parameter values. +//- before using tz_Refresh_z_T7P_T_in_kalfilms_1st_approx(). +//----------------------------------------------------- +void tz_Refresh_z_T7P_T_in_kalfilms_1st_approx(struct TSkalfilmsinputs_tag *kalfilmsinputs_ps, struct TStateModel_tag *smodel_ps) +{ + double debug1; + //--- Local variables + int stp1i, stp1i_c, stp1i_v, sti, sti_c, sti_v, tbase0, tp1; + //=== Accessible variables + int ny = kalfilmsinputs_ps->ny; + int nz = kalfilmsinputs_ps->nz; + int nRc = kalfilmsinputs_ps->nRc; + int nRv = kalfilmsinputs_ps->nRv; + int T = kalfilmsinputs_ps->T; + int indxIndRegimes = kalfilmsinputs_ps->indxIndRegimes; + TSdvector z0_sdv; + //+ input arguments. + TSdmatrix *yt_dm = kalfilmsinputs_ps->yt_dm; //ny-by-T. + TSdmatrix *at_dm = kalfilmsinputs_ps->at_dm; //ny-by-nRc. + TSdcell *Ht_dc = kalfilmsinputs_ps->Ht_dc; //ny-by-nz-by-nRc. + TSdcell *Rt_dc = kalfilmsinputs_ps->Rt_dc; //ny-by-ny-by-nRv. Covariance matrix for the measurement equation. + TSdcell *Gt_dc = kalfilmsinputs_ps->Gt_dc; //nz-by-ny-by-nRv. Cross-covariance. + // + TSdmatrix *bt_dm = kalfilmsinputs_ps->bt_dm; //nz-by-nRc. + TSdcell *Ft_dc = kalfilmsinputs_ps->Ft_dc; //nz-by-nz-by-nRc. + TSdcell *Vt_dc = kalfilmsinputs_ps->Vt_dc; //nz-by-nz-by-nRv. Covariance matrix for the state equation. + // + TSdmatrix *z0_dm = kalfilmsinputs_ps->z0_dm; //nz-by-nRc*nRv or nz-by-nRv, depending on indxIndRegimes. + TSdcell *P0_dc = kalfilmsinputs_ps->P0_dc; //nz-by-nz-by-nRc*nRv or nz-by-nRv, depending on indxIndRegimes. + //+ Output arguments. + TSdcell *zt_tm1_dc = kalfilmsinputs_ps->zt_tm1_dc; //nz-by-nRc*nRv-by-T if indxIndRegimes==1, nz-by-nRv-by-T if indxIndRegimes==0 where nRc=nRv. + TSdfourth *Pt_tm1_d4 = kalfilmsinputs_ps->Pt_tm1_d4; //nz-by-nz-by-nRc*nRv-T if indxIndRegimes==1, nz-by-nz-by-nRv-by-T if indxIndRegimes==0 where nRc=nRv. + //=== Work arguments. + int nz2 = square(nz); + TSdmatrix *Wnzbynz_dm = CreateMatrix_lf(nz,nz); + TSdmatrix *Wnz2bynz2_dm = CreateMatrix_lf(nz2,nz2); + TSdmatrix *W2nz2bynz2_dm = CreateMatrix_lf(nz2,nz2); + TSdvector *wP0_dv = CreateVector_lf(nz2); + //+ + TSdvector yt_sdv, at_sdv, btp1_sdv; //zt_tm1_sdv, ztp1_t_sdv, + TSdvector *wny_dv = CreateVector_lf(ny); + TSdmatrix *Wnzbyny_dm = CreateMatrix_lf(nz,ny); + TSdmatrix *W2nzbynz_dm = CreateMatrix_lf(nz,nz); + TSdmatrix *PHtran_tdata_dm = CreateMatrix_lf(nz,ny); + TSdvector *etdata_dv = CreateVector_lf(ny); + TSdmatrix *Dtdata_dm = CreateMatrix_lf(ny,ny); + TSdmatrix *Kt_tdata0_dm = CreateMatrix_lf(nz,ny); + TSdmatrix *Kt_tdata_dm = CreateMatrix_lf(nz,ny); + //--- For eigenvalue decompositions + int ki; + int errflag; + double eigmax; + TSdzvector *evals_dzv = evals_dzv = CreateVector_dz(nz); + TSdvector *evals_abs_dv = CreateVector_lf(nz); //Absolute eigenvalues. + //--- For updating zt_tm1_dm and Pt_tm1. + TSdvector *ztp1_t_dv = CreateVector_lf(z0_dm->nrows); + TSdmatrix *Ptp1_t_dm = CreateMatrix_lf(nz, nz); + TSdvector *ztp1_dv = CreateVector_lf(z0_dm->nrows); + TSdmatrix *Ptp1_dm = CreateMatrix_lf(nz, nz); + + + if (smodel_ps->sv->nstates != z0_dm->ncols) fn_DisplayError("kalman.c/tz_Refresh_z_T7P_T_in_kalfilms_1st_approx():\n" + " Make sure that the column dimension of z0_dm is the same as smodel_ps->sv->nstates"); + if (indxIndRegimes && (nRc>1) && (nRv>1)) + if (smodel_ps->sv->n_state_variables != 2) fn_DisplayError("kalman.c/tz_Refresh_z_T7P_T_in_kalfilms_1st_approx():\n" + " Number of state variables must be coincide with indxIndRegimes"); + + + z0_sdv.n = z0_dm->nrows; + z0_sdv.flag = V_DEF; + // + at_sdv.n = yt_sdv.n = yt_dm->nrows; + at_sdv.flag = yt_sdv.flag = V_DEF; + btp1_sdv.n = bt_dm->nrows; + btp1_sdv.flag = V_DEF; + + + //======= Initial condition. ======= + for (sti=smodel_ps->sv->nstates-1; sti>=0; sti--) + { + if (indxIndRegimes && (nRc==1)) + { + sti_c = 0; + sti_v = sti; + } + else if (indxIndRegimes && (nRv==1)) + { + sti_c = sti; + sti_v = 0; + } + else if (indxIndRegimes) + { + sti_c = smodel_ps->sv->Index[sti][0]; + sti_v = smodel_ps->sv->Index[sti][1]; + } + else + { + sti_c = sti_v = sti; + } + + + if (!kalfilmsinputs_ps->indxIni) + { + InitializeDiagonalMatrix_lf(Wnzbynz_dm, 1.0); //To be used for I(nz) - + InitializeDiagonalMatrix_lf(Wnz2bynz2_dm, 1.0); //To be used for I(nz2) - + + //=== Eigenanalysis to determine the roots to ensure boundedness. + errflag = eigrgen(evals_dzv, (TSdzmatrix *)NULL, (TSdzmatrix *)NULL, Ft_dc->C[sti_c]); + if (errflag) fn_DisplayError("kalman.c/tz_Refresh_z_T7P_T_in_kalfilms_1st_approx(): eigen decomposition failed"); + for (ki=nz-1; ki>=0; ki--) evals_abs_dv->v[ki] = sqrt(square(evals_dzv->real->v[ki]) + square(evals_dzv->imag->v[ki])); + evals_abs_dv->flag = V_DEF; + eigmax = MaxVector(evals_abs_dv); + if (eigmax < (1.0+1.0e-14)) + { + //--- Getting z0_dv: zt_tm1(:,1) = (eye(n_z)-F(:,:,1))\b(:,1); + MatrixMinusMatrix(Wnzbynz_dm, Wnzbynz_dm, Ft_dc->C[sti_c]); + z0_sdv.v = z0_dm->M + z0_sdv.n*sti; + CopySubmatrix2vector(&z0_sdv, 0, bt_dm, 0, sti_c, bt_dm->nrows); + bdivA_rgens(&z0_sdv, &z0_sdv, '\\', Wnzbynz_dm); + //Done with Wnzbynz_dm. + //--- Getting P0_dm: Pt_tm1(:,:,1) = reshape((eye(n_z^2)-kron(F(:,:,1),F(:,:,1)))\V1(:),n_z,n_z); + tz_kron(W2nz2bynz2_dm, Ft_dc->C[sti_c], Ft_dc->C[sti_c]); + MatrixMinusMatrix(Wnz2bynz2_dm, Wnz2bynz2_dm, W2nz2bynz2_dm); + CopySubmatrix2vector(wP0_dv, 0, Vt_dc->C[sti_v], 0, 0, nz2); + bdivA_rgens(wP0_dv, wP0_dv, '\\', Wnz2bynz2_dm); + CopySubvector2matrix_unr(P0_dc->C[sti], 0, 0, wP0_dv, 0, nz2); + //Done with all w*_dv and W*_dm. + } + else + { + fprintf(stdout, "\n-----------------\n"); + fprintf(stdout, "\nIn regime sti_c=%d and sti_v=%d and at time=%d\n", sti_c, sti_v, 0); + fn_DisplayError("kalman.c/tz_Refresh_z_T7P_T_in_kalfilms_1st_approx(): the system is non-stationary solutions\n" + " and the initial conditions must be supplied by, say, input arguments"); + fflush(stdout); + } + } + } + z0_dm->flag = M_GE; + CopyMatrix0(zt_tm1_dc->C[0], z0_dm); //At time t=0. + CopyCell0(Pt_tm1_d4->F[0], P0_dc); //At time t=0. + + +// fprintf(FPTR_DEBUG, "\n zt_tm1_dc->C[0]:\n"); +// WriteMatrix(FPTR_DEBUG, zt_tm1_dc->C[0], " %.16e "); +// fprintf(FPTR_DEBUG, "\n"); +// fprintf(FPTR_DEBUG, "\n Pt_tm1_d4->F[0]->C[0]:\n"); +// WriteMatrix(FPTR_DEBUG, Pt_tm1_d4->F[0]->C[0], " %.16e "); + + + //============== Updating zt_tm1 and Pt_tm1. ================== + for (tbase0=0; tbase0<T; tbase0++ ) + { + //tdata = tbase0 is base-0 timing. + tp1 = tbase0 + 1; //Next period. + + for (stp1i=smodel_ps->sv->nstates-1; stp1i>=0; stp1i--) + { + if (indxIndRegimes && (nRc==1)) + { + stp1i_c = 0; + stp1i_v = stp1i; + } + else if (indxIndRegimes && (nRv==1)) + { + stp1i_c = stp1i; + stp1i_v = 0; + } + else if (indxIndRegimes) + { + stp1i_c = smodel_ps->sv->Index[stp1i][0]; + stp1i_v = smodel_ps->sv->Index[stp1i][1]; + } + else + { + stp1i_c = stp1i_v = stp1i; + } + + + InitializeConstantVector_lf(ztp1_dv, 0.0); //To be summed over sti. + InitializeConstantMatrix_lf(Ptp1_dm, 0.0); //To be summed over sti. + for (sti=smodel_ps->sv->nstates-1; sti>=0; sti--) + { + if (indxIndRegimes && (nRc==1)) + { + sti_c = 0; + sti_v = sti; + } + else if (indxIndRegimes && (nRv==1)) + { + sti_c = sti; + sti_v = 0; + } + else if (indxIndRegimes) + { + sti_c = smodel_ps->sv->Index[sti][0]; + sti_v = smodel_ps->sv->Index[sti][1]; + } + else + { + sti_c = sti_v = sti; + } + + //--- Setup. + MatrixTimesMatrix(PHtran_tdata_dm, Pt_tm1_d4->F[tbase0]->C[sti], Ht_dc->C[sti_c], 1.0, 0.0, 'N', 'T'); + + //--- Data. + //- etdata = Y_T(:,tdata) - a(:,tdata) - Htdata*ztdata where tdata = tbase0 = inpt-1. + yt_sdv.v = yt_dm->M + tbase0*yt_dm->nrows; + at_sdv.v = at_dm->M + sti_c*at_dm->nrows; //sti_c: coefficient regime at time tbase0. + z0_sdv.v = zt_tm1_dc->C[tbase0]->M + z0_sdv.n*sti; //sti: regime at time tbase0. + VectorMinusVector(etdata_dv, &yt_sdv, &at_sdv); + MatrixTimesVector(etdata_dv, Ht_dc->C[sti_c], &z0_sdv, -1.0, 1.0, 'N'); + //+ Dtdata = Htdata*PHtran_tdata + R(:,:,tbase0); + CopyMatrix0(Dtdata_dm, Rt_dc->C[sti_v]); + MatrixTimesMatrix(Dtdata_dm, Ht_dc->C[sti_c], PHtran_tdata_dm, 1.0, 1.0, 'N', 'N'); + //Done with z0_sdv.v. + + + //=== Updating for next period by integrating out sti.. + if (tp1<T) + { + //Updating only up to tbase0=T-2. The values at tp1=T or tbase0=T-1 will not be used in the likelihood function. + + //--- Ktp1_t = (F_tp1*PHtran_t+G(:,:,t))/Dt; + //--- Kt_tdata = (Ft*PHtran_tdata+G(:,:,tdata))/Dtdata where t=tp1 and tdata=t. + CopyMatrix0(Kt_tdata0_dm, Gt_dc->C[sti_v]); + MatrixTimesMatrix(Kt_tdata0_dm, Ft_dc->C[stp1i_c], PHtran_tdata_dm, 1.0, 1.0, 'N', 'N'); + BdivA_rrect(Kt_tdata_dm, Kt_tdata0_dm, '/', Dtdata_dm); + //+ zt_tm1(:,t) = b(:,t) + Ft*zt_tm1(:,tdata) + Kt_tdata*etdata where t=tp1 and tm1=t. + MatrixTimesVector(ztp1_t_dv, Ft_dc->C[stp1i_c], &z0_sdv, 1.0, 0.0, 'N'); + MatrixTimesVector(ztp1_t_dv, Kt_tdata_dm, etdata_dv, 1.0, 1.0, 'N'); + btp1_sdv.v = bt_dm->M + stp1i_c*btp1_sdv.n; + VectorPlusMinusVectorUpdate(ztp1_t_dv, &btp1_sdv, 1.0); + //+ Pt_tm1(:,:,t) = Ft*Ptdata*Fttran - Kt_tdata*Dtdata*Kt_tdatatran + V(:,:,t); + CopyMatrix0(Ptp1_t_dm, Vt_dc->C[stp1i]); + MatrixTimesMatrix(Wnzbyny_dm, Kt_tdata_dm, Dtdata_dm, 1.0, 0.0, 'N', 'N'); + MatrixTimesMatrix(Wnzbynz_dm, Wnzbyny_dm, Kt_tdata_dm, 1.0, 0.0, 'N', 'T'); + MatrixPlusMinusMatrixUpdate(Ptp1_t_dm, Wnzbynz_dm, -1.0); + //Done with all W*_dm. + MatrixTimesMatrix(Wnzbynz_dm, Ft_dc->C[stp1i_c], Pt_tm1_d4->F[tbase0]->C[sti], 1.0, 0.0, 'N', 'N'); + MatrixTimesMatrix(W2nzbynz_dm, Wnzbynz_dm, Ft_dc->C[stp1i_c], 1.0, 0.0, 'N', 'T'); + MatrixPlusMatrixUpdate(Ptp1_t_dm, W2nzbynz_dm); + //Done with all W*_dm. + + //--- Integrating out the state at tbase0 using P(s_t|Y_t, theta) = ElementV(smodel_ps->V[t+1],s_{t+1}_i). + //--- Note because the data in DW code (ElementV) is base-1, t+1 is actually tbase0. + debug1 = ElementV(smodel_ps->V[tp1],sti); //?????? Debug. + //ScalarTimesVectorUpdate(ztp1_dv, ElementV(smodel_ps->V[tp1],sti), ztp1_t_dv); + //ScalarTimesMatrix(Ptp1_dm, ElementV(smodel_ps->V[tp1],sti), Ptp1_t_dm, 1.0); + ScalarTimesVectorUpdate(ztp1_dv, 0.5, ztp1_t_dv); + ScalarTimesMatrix(Ptp1_dm, 0.5, Ptp1_t_dm, 1.0); + Ptp1_dm->flag = M_GE | M_SU | M_SL; + //Done with ztp1_t_dv and Ptp1_t_dm. + } + } + //--- Filling zt_tm1 and Pt_tm1 for next period + if (tp1<T) + { + z0_sdv.v = zt_tm1_dc->C[tp1]->M + z0_sdv.n*stp1i; //stp1i: regime at time tp1. + CopyVector0(&z0_sdv, ztp1_dv); + CopyMatrix0(Pt_tm1_d4->F[tp1]->C[stp1i], Ptp1_dm); //stp1i: regime at time tp1. + //Done with ztp1_dv, z0_sdv, Ptp1_dm. + } + } + if (tp1<T) + zt_tm1_dc->C[tp1]->flag = M_GE; + +// fprintf(FPTR_DEBUG, "\n &yt_sdv:\n"); +// WriteMatrix(FPTR_DEBUG, &yt_sdv, " %.16e "); +// fprintf(FPTR_DEBUG, "\n zt_tm1_dc->C[tp1]:\n"); +// WriteMatrix(FPTR_DEBUG, zt_tm1_dc->C[tp1], " %.16e "); +// fprintf(FPTR_DEBUG, "\n"); +// fprintf(FPTR_DEBUG, "\n Pt_tm1_d4->F[tp1]->C[0]:\n"); +// WriteMatrix(FPTR_DEBUG, Pt_tm1_d4->F[tp1]->C[0], " %.16e "); +// fprintf(FPTR_DEBUG, "\n"); +// fflush(FPTR_DEBUG); + + + } + + //=== + DestroyVector_dz(evals_dzv); + DestroyVector_lf(evals_abs_dv); + DestroyMatrix_lf(Wnzbynz_dm); + DestroyMatrix_lf(Wnz2bynz2_dm); + DestroyMatrix_lf(W2nz2bynz2_dm); + DestroyVector_lf(wP0_dv); + // + DestroyVector_lf(wny_dv); + DestroyMatrix_lf(Wnzbyny_dm); + DestroyMatrix_lf(W2nzbynz_dm); + DestroyMatrix_lf(PHtran_tdata_dm); + DestroyVector_lf(etdata_dv); + DestroyMatrix_lf(Dtdata_dm); + DestroyMatrix_lf(Kt_tdata0_dm); + DestroyMatrix_lf(Kt_tdata_dm); + // + DestroyVector_lf(ztp1_t_dv); + DestroyMatrix_lf(Ptp1_t_dm); + DestroyVector_lf(ztp1_dv); + DestroyMatrix_lf(Ptp1_dm); +} +//----------------------------------------------------- +//- Kalman filter at time t for Markov-switching DSGE model. +//- WARNING: make sure to call the following functions +// (1) RunningGensys_const7varionly(lwzmodel_ps); +// (2) Refresh_kalfilms_*(lwzmodel_ps); //Creates or refreshes kalfilmsinputs_ps at new parameter values. +// (3) tz_Refresh_z_T7P_T_in_kalfilms_1st_approx(); +//- before using kalfilms_timet_1st_approx(). +//----------------------------------------------------- +double tz_kalfilms_timet_1st_approx(int st, int inpt, struct TSkalfilmsinputs_tag *kalfilmsinputs_ps, struct TStateModel_tag *smodel_ps) +{ + //st, st_c, and st_v: base-0: deals with the cross-section values at time t where + // st is a grand regime, st_c is an encoded coefficient regime, and st_c is an encoded volatility regime. + //inpt: base-1 in the sense that inpt>=1 to deal with the time series situation where S_T is (T+1)-by-1 and Y_T is T+nlags_max-by-1. + // The 1st element for S_T is S_T[1] while S_T[0] is s_0. The same for (T+1)-by-1 gbeta_dv and nlcoefs-by-(T+1) galpha_dm. + // The 1st element for Y_T, however, is Y_T[nlags_max+1-1]. + //See (42.3) on p.42 in the SWZII NOTES. + + + //--- Local variables + int st_c, st_v, tbase0; + double loglh_timet; + //--- Accessible variables + int ny = kalfilmsinputs_ps->ny; + int nz = kalfilmsinputs_ps->nz; + int nRc = kalfilmsinputs_ps->nRc; + int nRv = kalfilmsinputs_ps->nRv; + int indxIndRegimes = kalfilmsinputs_ps->indxIndRegimes; + TSdvector z0_sdv; + //+ input arguments. + TSdmatrix *yt_dm = kalfilmsinputs_ps->yt_dm; //ny-by-T. + TSdmatrix *at_dm = kalfilmsinputs_ps->at_dm; //ny-by-nRc. + TSdcell *Ht_dc = kalfilmsinputs_ps->Ht_dc; //ny-by-nz-by-nRc. + TSdcell *Rt_dc = kalfilmsinputs_ps->Rt_dc; //ny-by-ny-by-nRv. Covariance matrix for the measurement equation. + //+ Output arguments. + TSdcell *zt_tm1_dc = kalfilmsinputs_ps->zt_tm1_dc; //nz-by-nRc*nRv-by-T if indxIndRegimes==1, nz-by-nRv-by-T if indxIndRegimes==0 where nRc=nRv. + TSdfourth *Pt_tm1_d4 = kalfilmsinputs_ps->Pt_tm1_d4; //nz-by-nz-by-nRc*nRv-T if indxIndRegimes==1, nz-by-nz-by-nRv-by-T if indxIndRegimes==0 where nRc=nRv. + //=== Work arguments. + TSdvector yt_sdv, at_sdv; + TSdvector *wny_dv = CreateVector_lf(ny); + TSdmatrix *PHtran_tdata_dm = CreateMatrix_lf(nz,ny); + TSdvector *etdata_dv = CreateVector_lf(ny); + TSdmatrix *Dtdata_dm = CreateMatrix_lf(ny,ny); + + + if (smodel_ps->sv->nstates != zt_tm1_dc->C[0]->ncols) fn_DisplayError("kalman.c/kalfilms_timet_1st_approx():\n" + " Make sure that the column dimension of zt_tm1_dc->C is the same as smodel_ps->sv->nstates"); + + tbase0 = inpt - 1; //base-0 time t. + + if (indxIndRegimes && (nRc==1)) + { + st_c = 0; + st_v = st; + } + else if (indxIndRegimes && (nRv==1)) + { + st_c = st; + st_v = 0; + } + else if (indxIndRegimes) + { + if (smodel_ps->sv->n_state_variables != 2) fn_DisplayError("kalman.c/kalfilms_timet_1st_approx():\n" + " Number of state variables must be coincide with indxIndRegimes"); + st_c = smodel_ps->sv->Index[st][0]; + st_v = smodel_ps->sv->Index[st][1]; + } + else + { + st_c = st_v = st; + } + + + z0_sdv.n = zt_tm1_dc->C[0]->nrows; + z0_sdv.flag = V_DEF; + // + at_sdv.n = yt_sdv.n = yt_dm->nrows; + at_sdv.flag = yt_sdv.flag = V_DEF; + + //====== Computing the conditional LH at time t. ====== + //--- Setup. + MatrixTimesMatrix(PHtran_tdata_dm, Pt_tm1_d4->F[tbase0]->C[st], Ht_dc->C[st_c], 1.0, 0.0, 'N', 'T'); + + //--- Data. + //- etdata = Y_T(:,tdata) - a(:,tdata) - Htdata*ztdata where tdata = tbase0 = inpt-1. + yt_sdv.v = yt_dm->M + tbase0*yt_dm->nrows; + at_sdv.v = at_dm->M + st_c*at_dm->nrows; //st_c: coefficient regime at time tbase0. + z0_sdv.v = zt_tm1_dc->C[tbase0]->M + z0_sdv.n*st; //st: regime at time tbase0 for zt_tm1. + VectorMinusVector(etdata_dv, &yt_sdv, &at_sdv); + MatrixTimesVector(etdata_dv, Ht_dc->C[st_c], &z0_sdv, -1.0, 1.0, 'N'); + //+ Dtdata = Htdata*PHtran_tdata + R(:,:,tbase0); + CopyMatrix0(Dtdata_dm, Rt_dc->C[st_v]); + MatrixTimesMatrix(Dtdata_dm, Ht_dc->C[st_c], PHtran_tdata_dm, 1.0, 1.0, 'N', 'N'); + + //--- Forming the log conditional likelihood at t. + bdivA_rgens(wny_dv, etdata_dv, '/', Dtdata_dm); + loglh_timet = -(0.5*ny)*LOG2PI - 0.5*logdeterminant(Dtdata_dm) - 0.5*VectorDotVector(wny_dv, etdata_dv); + //Done with all w*_dv. + + + //=== + DestroyVector_lf(wny_dv); + DestroyMatrix_lf(PHtran_tdata_dm); + DestroyVector_lf(etdata_dv); + DestroyMatrix_lf(Dtdata_dm); + + return (loglh_timet); +} +#undef LOG2PI +/**/ + + + + diff --git a/CFiles/kalman.h b/CFiles/kalman.h new file mode 100755 index 0000000..df661b5 --- /dev/null +++ b/CFiles/kalman.h @@ -0,0 +1,314 @@ +#ifndef __KALMAN_H__ + #define __KALMAN_H__ + + #include "tzmatlab.h" + #include "mathlib.h" + #include "switch.h" + #include "fn_filesetup.h" //Used to call WriteMatrix(FPTR_DEBUG,....). + + + typedef struct TSkalcvfurw_tag { + //urw: univariate random walk kalman filter. Desigend specially for the 2006 AER SWZ paper. + + //=== Input arguments. + int indx_tvsigmasq; //0: constant siqmasq in Kalman updating (default); + //1: Keyensian (project-specific) type of time-varying sigmasq in Kalman updating; See pp.37 and 37a in SWZ Learning NOTES; + //2: project-specific type; + //3: another project-specific type. + double sigmasq; //Variance for the residual eps(t) of the measurement equation. + int fss; //T: effective sample size (excluding lags). + int kx; //dimension for x(t). + TSdmatrix *V_dm; //kx-by-kx. Covariance (symmetric and positive definite) matrix for the residual eta(t) of the transition equation. + TSdvector *ylhtran_dv; //1-by-T of y(t). The term lh means lelf hand side and tran means transpose. + TSdmatrix *Xrhtran_dm; //kx-by-T of x(t). The term rh means right hand side and tran means transpose. + TSdvector *z10_dv; //kx-by-1. Initial condition for prediction: z_{1|0}. + TSdmatrix *P10_dm; //kx-by-kx symmetric matrix. Initial condition for the variance of the prediction: P_{1|0}. + + //=== Output arguments. + TSdvector *zupdate_dv; //kx-by-1. z_{T+1|T}. + TSdmatrix *Zpredtran_dm; //kx-by-T matrix of one-step predicted values of z(t). [z_{2|1}, ..., z_{t+1|t}, ..., z_{T+1|T}]. + //Set to NULL (no output) if storeZ = 0; + TSdcell *Ppred_dc; //T cells and kx-by-kx symmetric and positive definite matrix for each cell. Mean square errors of predicted state variables. + //{P_{2|1}, ..., P{t+1|t}, ..., P{T+1|T}. Set to NULL (no output if storeV = 0). + TSdvector *ylhtranpred_dv; //1-by-T one-step prediction of y(t) or ylhtran_dv. Added 03/17/05. + + //=== Function itself. + void (*learning_fnc)(struct TSkalcvfurw_tag *, void *); + } TSkalcvfurw; //urw: univariate random walk. + // + typedef void TFlearninguni(struct TSkalcvfurw_tag *, void *); //For linear rational expectations models. + + + //=== Better version is TSkalfilmsinputs_1stapp_tag. Kalman filter for constant or known-time-varying DSGE models. + typedef struct TSkalfiltv_tag + { + //General (known-time-varying) Kalman filter for DSGE models. + // It computes a sequence of one-step predictions and their covariance matrices, and the log likelihood. + // The function uses a forward recursion algorithm. See also the Matlab function fn_kalfil_tv.m + // + // State space model is defined as follows: + // y(t) = a(t) + H(t)*z(t) + eps(t) (observation or measurement equation) + // z(t) = b(t) + F(t)*z(t) + eta(t) (state or transition equation) + // where a(t), H(t), b(t), and F(t) depend on s_t that follows a Markov-chain process and are taken as given. + // + // Inputs are as follows: + // Y_T is a n_y-by-T matrix containing data [y(1), ... , y(T)]. + // a is an n_y-by-T matrix of time-varying input vectors in the measurement equation. + // H is an n_y-by-n_z-by-T 3-D of time-varying matrices in the measurement equation. + // R is an n_y-by-n_y-by-T 3-D of time-varying covariance matrices for the error in the measurement equation. + // G is an n_z-by-n_y-by-T 3-D of time-varying E(eta_t * eps_t'). + // ------ + // b is an n_z-by-T matrix of time-varying input vectors in the state equation with b(:,1) as an initial condition. + // F is an n_z-by-n_z-by-T 3-D of time-varying transition matrices in the state equation with F(:,:,1) as an initial condition. + // V is an n_z-by-n_z-by-T 3-D of time-varying covariance matrices for the error in the state equation with V(:,:,1) as an initial condition. + // ------ + // indxIni: 1: using the initial condition with zt_tm1(:,1)=z0 and Pt_tm1(:,:,1)=P0; + // 0: using the unconditional mean for any given regime at time 0. + // z0 is an n_z-by-1 vector of initial condition when indxIni=1. (Not used if indxIni=0.) + // P0 is an n_z-by-n_z matrix of initial condition when indxIni=1. (Not used if indxIni=0.) + // + // Outputs are as follows: + // loglh is a value of the log likelihood function of the state-space model + // under the assumption that errors are multivariate Gaussian. + // zt_tm1 is an n_z-by-T matrices of one-step predicted state vectors with z0_0m1 as a initial condition + // and with z_{t+1|t} as the last element. Thus, we can use it as a base-1 vector. + // Pt_tm1 is an n_z-by-n_z-by-T 3-D of covariance matrices of zt_tm1 with P0_0m1 as a initial condition + // and with P_{t+1|t} as the last element. Thus, we can use it as a base-1 cell. + // + // The initial state vector and its covariance matrix are computed under the bounded (stationary) condition: + // z0_0m1 = (I-F(:,:,1))\b(:,1) + // vec(P0_0m1) = (I-kron(F(:,:,1),F(:,:,1)))\vec(V(:,:,1)) + // Note that all eigenvalues of the matrix F(:,:,1) are inside the unit circle when the state-space model is bounded (stationary). + // + // March 2007, written by Tao Zha + // See Hamilton's book ([13.2.13] -- [13.2.22]), Harvey (pp.100-106), and LiuWZ Model I NOTES pp.001-003. + + //=== Input arguments. + int ny; //number of observables. + int nz; //number of state variables. + int T; //sample size. + int indxIni; //1: using the initial condition with zt_tm1(:,1)=z0 and Pt_tm1(:,:,1)=P0; + //0: using the unconditional mean for any given regime at time 0. (Default value) + TSdmatrix *yt_dm; //ny-by-T. + TSdmatrix *at_dm; //ny-by-T. + TSdcell *Ht_dc; //ny-by-nz-by-T. + TSdcell *Rt_dc; //ny-by-ny-by-T. Covariance matrix for the measurement equation. + TSdcell *Gt_dc; //nz-by-ny-by-T. Cross-covariance. + // + TSdmatrix *bt_dm; //nz-by-T. + TSdcell *Ft_dc; //nz-by-nz-by-T. + TSdcell *Vt_dc; //nz-by-nz-by-T. Covariance matrix for the state equation. + // + TSdvector *z0_dv; //nz-by-1; + TSdmatrix *P0_dm; //nz-by-nz. + + //=== Output arguments. + double loglh; //log likelihood. + TSdmatrix *zt_tm1_dm; //nz-by-T. + TSdcell *Pt_tm1_dc; //nz-by-nz-T. + } TSkalfiltv; + + + + //=== Inputs for filter for Markov-switching DSGE models at any time t. + typedef struct TSkalfilmsinputs_1stapp_tag + { + //Inputs Markov-switching Kalman filter for DSGE models (conditional on all the regimes at time t). + // It computes a sequence of one-step predictions and their covariance matrices, and the log likelihood. + // The function uses a forward recursion algorithm. See also the Matlab function fn_kalfil_tv.m + // + // State space model is defined as follows: + // y(t) = a(t) + H(t)*z(t) + eps(t) (observation or measurement equation) + // z(t) = b(t) + F(t)*z(t) + eta(t) (state or transition equation) + // where a(t), H(t), b(t), and F(t) depend on the grand regime s_t that follows a Markov-chain process + // and is taken as given, and + // eps(t) = Psi_u(t)*u(t), where Psi_u(t) is n_y-by-n_u and u(t) is n_u-by-1; + // eta(t) = Psi_e(t)*e(t), where Psi_e(t) is n_z-by-n_e and e(t) is n_e-by-1. + // + // Inputs at time t are as follows where nst is number of grand regimes (including lagged regime + // and coefficients and shock variances): + // Y_T is a n_y-by-T matrix containing data [y(1), ... , y(T)]. + // a is an n_y-by-nst matrix of Markov-switching input vectors in the measurement equation. + // H is an n_y-by-n_z-by-nst 3-D of Markov-switching matrices in the measurement equation. + // Psi_u is an n_y-by-n_u-by-nst 3-D Markov-switching matrices. + // R is an n_y-by-n_y-by-nst 3-D of Markov-switching covariance matrices, + // E(eps(t) * eps(t)') = Psi_u(t)*Psi_u(t)', for the error in the measurement equation. + // G is an n_z-by-n_y-by-nst 3-D of Markov-switching E(eta_t * eps_t') = Psi_e(t)*Psi_u(t)'. + // ------ + // b is an n_z-by-nst matrix of Markov-switching input vectors in the state equation with b(:,st) as an initial condition. + // (alternatively, with the ergodic weighted b(:,st) as an initial condition). + // F is an n_z-by-n_z-by-nst 3-D of Markov-switching transition matrices in the state equation with F(:,:,st) + // as an initial condition (alternatively, with the ergodic weighted F(:,:,st) as an initial condition). + // Psi_e is an n_z-by-n_e-by-nst 3-D Markov-switching matrices. + // V is an n_z-by-n_z-by-nRv 3-D of Markov-switching covariance matrices, + // E(eta(t)*eta(t)') = Psi_e(t)*Psi_e(t)', for the error in the state equation + // with V(:,:,st) as an initial condition (alternatively, with the ergodic weighted V(:,:,st) as an initial condition). + // ------ + // indxIni: 1: using the initial condition with zt_tm1(:,1)=z0 and Pt_tm1(:,:,1)=P0; + // 0: using the unconditional mean for any given regime at time 0. + // z0 is an n_z-by-nst matrix of initial condition (Not used if indxIni=0). + // P0 is an n_z-by-n_z-by-nst 3-D of initial condition (Not used if indxIni=0). + // + // The initial state vector and its covariance matrix are computed under the bounded (stationary) condition: + // z0_0m1 = (I-F(:,:,st))\b(:,st) + // vec(P0_0m1) = (I-kron(F(:,:,st),F(:,:,st)))\vec(V(:,:,st)) + // Note that all eigenvalues of the matrix F(:,:,st) are inside the unit circle when the state-space model is bounded (stationary). + // + // November 2007, written by Tao Zha. Revised, April 2008. + // See Hamilton's book ([13.2.13] -- [13.2.22]), Harvey (pp.100-106), and LiuWZ Model I NOTES pp.001-003. + + //=== Input arguments. + int ny; //number of observables. + int nz; //number of state variables. + int nu; //number of measurement errors. + int ne; //number of fundamental errors. + int nst; //number of grand composite regimes (current and past regimes, coefficient and volatility regimes). + int T; //sample size. + int indxIni; //1: using the initial condition with zt_tm1(:,1)=z0 and Pt_tm1(:,:,1)=P0, + //0: using the unconditional momnets for any given regime at time 0 (default when indxDiffuse = 0). + int indxDiffuse; //1: using the diffuse condition for z_{1|0} and P_{1|0} (default option), according to Koopman and Durbin, "Filtering and Smoothing of State Vector for Diffuse State-Space Models," J. of Time Series Analysis, Vol 24(1), pp.85-99. + //0: using the unconditional moments. + double DiffuseScale; //A large (infinity) number when indxDiffuse = 1. + int ztm1_track; //t-1 = -1: no initial conditions z_{1|0} and P_{1|0} has been computed yet, but will be using InitializeKalman_z10_P10(), + //t-1 >= 0:T-1: z_{t|t-1} and P_{t|t-1} are updated up to t-1. + int dtm1_track; //t-1 = -1: no etdata_dc->C[0] or Dtdata_d4->F[0] has been computed yet. + //t-1 >= 0:T-1: etdata_dc->C[t-1] and Dtdata_d4->F[t-1] are updated up to t-1. + + TSdmatrix *yt_dm; //ny-by-T. + TSdmatrix *at_dm; //ny-by-nst. + TSdcell *Ht_dc; //ny-by-nz-by-nst. + TSdcell *Psiut_dc; //ny-by-nu-by-nst. Measurement error coefficient matrix. + TSdcell *Rt_dc; //ny-by-ny-by-nst. Covariance matrix for the measurement equation. + TSdcell *Gt_dc; //nz-by-ny-by-nst. Cross-covariance. + // + TSdmatrix *bt_dm; //nz-by-nst. + TSdcell *Ft_dc; //nz-by-nz-by-nst. + TSdcell *Psiet_dc; //nz-by-ne-by-nst. Impact matrix in the state equation. + TSdcell *Vt_dc; //nz-by-nz-by-nst. Covariance matrix for the state equation. + // + TSdmatrix *z0_0_dm; //nz-by-nst. z_{0|0}. + TSdmatrix *z0_dm; //nz-by-nst. z_{1|0}. + TSdcell *P0_dc; //nz-by-nz-by-nst. P_{1|0} + + + //=== Output arguments only used for 1st order approximation to zt and Pt depending on infinite past regimes. + TSdcell *zt_tm1_dc; //nz-by-nst-by-(T+1), where z_{1|0} is an initial condition (1st element with t-1=0 or t=1 for base-1) and + // the terminal condition z_{T+1|T} using Updatekalfilms_1stapp(T, ...) is not computed + // when the likelihood logTimetCondLH_kalfilms_1stapp() is computed. Thus, z_{T+1|T} + // has not legal value computed in most applications unless in out-of-sample forecasting problems. + TSdfourth *Pt_tm1_d4; //nz-by-nz-by-nst-by-(T+1), where P_{1|0} is an initial condition (1st element with t-1=0) and + // the terminal condition P_{T+1|T} using Updatekalfilms_1stapp(T, ...) is not computed + // when the likelihood logTimetCondLH_kalfilms_1stapp() is computed. Thus, P_{T+1|T} + // has not legal value computed in most applications unless in out-of-sample forecasting problems. + //+ Will be save for updating likelihood and Kalman filter Updatekalfilms_1stapp(), so save time to recompute these objects again. + TSdfourth *PHtran_tdata_d4; //nz-by-ny-by-nst-T, P_{t|t-1}*H_t'. Saved only for updating Kalman filter Updatekalfilms_1stapp(). + TSdcell *etdata_dc; //ny-by-nst-by-T (with base-0 T), forecast errors e_t in the likelihood. + TSdcell *yt_tm1_dc; //ny-by-nst-by-T, one-step forecast y_{t|t-1} for t=0 to T-1 (base-0). Incorrect now (Used to back out structural shocks). + TSdfourth *Dtdata_d4; //ny-by-ny-nst-by-T, forecast covariance D_t in the likelihood. Saved for updating Kalman filter Updatekalfilms_1stapp(). + } TSkalfilmsinputs_1stapp; + + + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + //~~~ OLD Code: Inputs for filter for Markov-switching DSGE models at any time t. + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + typedef struct TSkalfilmsinputs_tag + { + //Inputs Markov-switching Kalman filter for DSGE models (conditional on all the regimes at time t). + // It computes a sequence of one-step predictions and their covariance matrices, and the log likelihood. + // The function uses a forward recursion algorithm. See also the Matlab function fn_kalfil_tv.m + // + // State space model is defined as follows: + // y(t) = a(t) + H(t)*z(t) + eps(t) (observation or measurement equation) + // z(t) = b(t) + F(t)*z(t) + eta(t) (state or transition equation) + // where a(t), H(t), b(t), and F(t) depend on s_t that follows a Markov-chain process and are taken as given. + // + // Inputs at time t are as follows where nRc is number of regimes for coefficients + // nRv is number of regimes for volatility (shock variances): + // Y_T is a n_y-by-T matrix containing data [y(1), ... , y(T)]. + // a is an n_y-by-nRc matrix of Markov-switching input vectors in the measurement equation. + // H is an n_y-by-n_z-by-nRc 3-D of Markov-switching matrices in the measurement equation. + // R is an n_y-by-n_y-by-nRv 3-D of Markov-switching covariance matrices for the error in the measurement equation. + // G is an n_z-by-n_y-by-nRv 3-D of Markov-switching E(eta_t * eps_t'). + // ------ + // b is an n_z-by-nRc matrix of Markov-switching input vectors in the state equation with b(:,1) as an initial condition. + // F is an n_z-by-n_z-by-nRc 3-D of Markov-switching transition matrices in the state equation with F(:,:,1) as an initial condition. + // V is an n_z-by-n_z-by-nRv 3-D of Markov-switching covariance matrices for the error in the state equation with V(:,:,1) as an initial condition. + // ------ + // indxIndRegimes: 1: coefficient regime and volatility regime are independent; 0: these two regimes are synchronized completely. + // indxIni: 1: using the initial condition with zt_tm1(:,1)=z0 and Pt_tm1(:,:,1)=P0; + // 0: using the unconditional mean for any given regime at time 0. + // z0 is an n_z-by-nRc*nRv matrix of initial condition when indxIni=1 and indxIndRegimes=1. (Not used if indxIni=0.) + // z0 is an n_z-by-nRv matrix of initial condition when indxIni=1 and indxIndRegimes=0. (Not used if indxIni=0.) + // P0 is an n_z-by-n_z-by-nRc*nRv 3-D of initial condition when indxIni=1 and indxIndRegimes=1. (Not used if indxIni=0.) + // P0 is an n_z-by-n_z-by-nRv 3-D of initial condition when indxIni=1 and indxIndRegimes=0. (Not used if indxIni=0.) + // + // The initial state vector and its covariance matrix are computed under the bounded (stationary) condition: + // z0_0m1 = (I-F(:,:,1))\b(:,1) + // vec(P0_0m1) = (I-kron(F(:,:,1),F(:,:,1)))\vec(V(:,:,1)) + // Note that all eigenvalues of the matrix F(:,:,1) are inside the unit circle when the state-space model is bounded (stationary). + // + // November 2007, written by Tao Zha + // See Hamilton's book ([13.2.13] -- [13.2.22]), Harvey (pp.100-106), and LiuWZ Model I NOTES pp.001-003. + + //=== Input arguments. + int ny; //number of observables. + int nz; //number of state variables. + int nRc; //number of composite regimes (current and past regimes) for coefficients. + int nRstc; //number of coefficient regimes at time t. + int nRv; //number of regimes for volatility (shock variances). + int indxIndRegimes; //1: coefficient regime and volatility regime are independent; 0: these two regimes are synchronized completely. + int T; //sample size. + int indxIni; //1: using the initial condition with zt_tm1(:,1)=z0 and Pt_tm1(:,:,1)=P0; + //0: using the unconditional mean for any given regime at time 0. (Default value) + TSdmatrix *yt_dm; //ny-by-T. + TSdmatrix *at_dm; //ny-by-nRc. + TSdcell *Ht_dc; //ny-by-nz-by-nRc. + TSdcell *Rt_dc; //ny-by-ny-by-nRv. Covariance matrix for the measurement equation. + TSdcell *Gt_dc; //nz-by-ny-by-nRv. Cross-covariance. + // + TSdmatrix *bt_dm; //nz-by-nRc. + TSdcell *Ft_dc; //nz-by-nz-by-nRc. + TSdcell *Vt_dc; //nz-by-nz-by-nRv. Covariance matrix for the state equation. + // + TSdmatrix *z0_dm; //nz-by-nRc*nRv if indxIndRegimes == 1 or nz-by-nRv if indxIndRegimes == 0. + TSdcell *P0_dc; //nz-by-nz-by-nRc*nRv if indxIndRegimes == 1 or nz-by-nz-by-nRv if indxIndRegimes == 0. + + + //=== Output arguments only used for 1st order approximation to zt and Pt depending on infinite past regimes. + TSdcell *zt_tm1_dc; //nz-by-nRc*nRv-by-T if indxIndRegimes==1, nz-by-nRv-by-T if indxIndRegimes==0 where nRc=nRv. + TSdfourth *Pt_tm1_d4; //nz-by-nz-by-nRc*nRv-T if indxIndRegimes==1, nz-by-nz-by-nRv-by-T if indxIndRegimes==0 where nRc=nRv. + } TSkalfilmsinputs; + + + + + //--- Functions for univariate random walk kalman filter. + TSkalcvfurw *CreateTSkalcvfurw(TFlearninguni *func, int T, int k, int tv); //, int storeZ, int storeV); + TSkalcvfurw *DestroyTSkalcvfurw(TSkalcvfurw *kalcvfurw_ps); + void kalcvf_urw(TSkalcvfurw *kalcvfurw_ps, void *dummy_ps); + + //--- New Code: Functions for Markov-switching Kalman filter. + struct TSkalfilmsinputs_1stapp_tag *CreateTSkalfilmsinputs_1stapp2(int ny, int nz, int nu, int ne, int nst, int T); + struct TSkalfilmsinputs_1stapp_tag *DestroyTSkalfilmsinputs_1stapp2(struct TSkalfilmsinputs_1stapp_tag *kalfilmsinputs_1stapp_ps); + struct TSkalfilmsinputs_1stapp_tag *CreateTSkalfilmsinputs_1stapp(int ny, int nz, int nst, int T); + struct TSkalfilmsinputs_1stapp_tag *DestroyTSkalfilmsinputs_1stapp(struct TSkalfilmsinputs_1stapp_tag *kalfilmsinputs_1stapp_ps); + int InitializeKalman_z10_P10(struct TSkalfilmsinputs_1stapp_tag *kalfilmsinputs_1stapp_ps, TSdmatrix *z10_dm, TSdcell *P10_dc); + double logTimetCondLH_kalfilms_1stapp(int st, int inpt, struct TSkalfilmsinputs_1stapp_tag *kalfilmsinputs_1stapp_ps, struct TStateModel_tag *smodel_ps); + + + + //--- OLD Code: Functions for general constant Kalman filter. + struct TSkalfiltv_tag *CreateTSkalfiltv(int ny, int nz, int T); + struct TSkalfiltv_tag *DestroyTSkalfiltv(struct TSkalfiltv_tag *kalfiltv_ps); + //Used to test tz_logTimetCondLH_kalfiltv(). (Done April 08). double tz_kalfiltv(struct TSkalfiltv_tag *kalfiltv_ps); + double tz_logTimetCondLH_kalfiltv(int st, int inpt, struct TSkalfiltv_tag *kalfiltv_ps); + + //--- OLD Code: Functions for Markov-switching Kalman filter. + struct TSkalfilmsinputs_tag *CreateTSkalfilmsinputs(int ny, int nz, int nRc, int nRstc, int nRv, int indxIndRegimes, int T); + struct TSkalfilmsinputs_tag *DestroyTSkalfilmsinputs(struct TSkalfilmsinputs_tag *kalfilmsinputs_ps); + double tz_logTimetCondLH_kalfilms_1st_approx(int st, int inpt, struct TSkalfilmsinputs_tag *kalfilmsinputs_ps, struct TStateModel_tag *smodel_ps); + //IMPORTANT NOTE: in the Markov-switching input file datainp_markov*.prn, it MUST be that + // the coefficient regime is the 1st state variable, and + // the volatility regime is the 2nd state variable. +#endif + diff --git a/CFiles/kalmanOldWorks.c b/CFiles/kalmanOldWorks.c new file mode 100755 index 0000000..0918ed1 --- /dev/null +++ b/CFiles/kalmanOldWorks.c @@ -0,0 +1,2634 @@ +/*=============================================================================================================== + * Check $$$ for important notes. + * Check <<>> for updating DW's new switch code or questions for DW. + * + * kalcvf_urw(): the Kalman filter forward prediction specialized for only a univariate random walk (urw) process. + * + * State space model is defined as follows: + * z(t+1) = z(t)+eta(t) (state or transition equation) + * y(t) = x(t)'*z(t)+eps(t) (observation or measurement equation) + * where for this function, eta and eps must be uncorrelated; y(t) must be 1-by-1. Note that + * x(t): k-by-1; + * z(t): k-by-1; + * eps(t): 1-by-1 and ~ N(0, sigma^2); + * eta(t): ~ N(0, V) where V is a k-by-k covariance matrix. + * + * + * Written by Tao Zha, May 2004. + * Revised, May 2008; +=================================================================================================================*/ + +/** +//=== For debugging purpose. +if (1) +{ + double t_loglht; + + t_loglht = -(0.5*ny)*LOG2PI - 0.5*logdeterminant(Dtdata_dm) - 0.5*VectorDotVector(wny_dv, etdata_dv); + fprintf(FPTR_DEBUG, " %10.5f\n", t_loglht); + + fprintf(FPTR_DEBUG, "%%st=%d, inpt=%d, and sti=%d\n", st, inpt, sti); + + fprintf(FPTR_DEBUG, "\n wP0_dv:\n"); + WriteVector(FPTR_DEBUG, wP0_dv, " %10.5f "); + fprintf(FPTR_DEBUG, "\n Vt_dc->C[sti_v=%d]:\n", sti_v); + WriteMatrix(FPTR_DEBUG, Vt_dc->C[sti_v], " %10.5f "); + + fflush(FPTR_DEBUG); +} +/**/ + + +#include "kalman.h" + + +static int Updatekalfilms_1stapp(int inpt, struct TSkalfilmsinputs_1stapp_tag *kalfilmsinputs_1stapp_ps, struct TStateModel_tag *smodel_ps); + + +TSkalcvfurw *CreateTSkalcvfurw(TFlearninguni *func, int T, int k, int tv) //, int storeZ, int storeV) +{ + int _i; + //=== + TSivector *rows_iv = NULL; + TSivector *cols_iv = NULL; + //--- + TSkalcvfurw *kalcvfurw_ps = tzMalloc(1, TSkalcvfurw); + + + kalcvfurw_ps->indx_tvsigmasq = tv; + kalcvfurw_ps->fss = T; + kalcvfurw_ps->kx = k; + + //=== + kalcvfurw_ps->V_dm = CreateMatrix_lf(k, k); + kalcvfurw_ps->ylhtran_dv = CreateVector_lf(T); + kalcvfurw_ps->Xrhtran_dm = CreateMatrix_lf(k, T); + kalcvfurw_ps->z10_dv = CreateVector_lf(k); + kalcvfurw_ps->P10_dm = CreateMatrix_lf(k, k); + + kalcvfurw_ps->zupdate_dv = CreateVector_lf(k); + kalcvfurw_ps->Zpredtran_dm = CreateMatrix_lf(k, T); + kalcvfurw_ps->ylhtranpred_dv = CreateVector_lf(T); + // + rows_iv = CreateVector_int(T); + cols_iv = CreateVector_int(T); + for (_i=T-1; _i>=0; _i--) rows_iv->v[_i] = cols_iv->v[_i] = k; + kalcvfurw_ps->Ppred_dc = CreateCell_lf(rows_iv, cols_iv); + // if (!storeZ) kalcvfurw_ps->Zpredtran_dm = (TSdmatrix *)NULL; + // else kalcvfurw_ps->Zpredtran_dm = CreateMatrix_lf(k, T); + // if (!storeV) kalcvfurw_ps->Ppred_dc = (TSdcell *)NULL; + // else { + // rows_iv = CreateVector_int(T); + // cols_iv = CreateVector_int(T); + // for (_i=T; _i>=0; _i--) rows_iv->v[_i] = cols_iv->v[_i] = k; + // kalcvfurw_ps->Ppred_dc = CreateCell_lf(rows_iv, cols_iv); + // } + + DestroyVector_int(rows_iv); + DestroyVector_int(cols_iv); + return (kalcvfurw_ps); +} + +TSkalcvfurw *DestroyTSkalcvfurw(TSkalcvfurw *kalcvfurw_ps) +{ + if (kalcvfurw_ps) { + DestroyMatrix_lf(kalcvfurw_ps->V_dm); + DestroyVector_lf(kalcvfurw_ps->ylhtran_dv); + DestroyMatrix_lf(kalcvfurw_ps->Xrhtran_dm); + DestroyVector_lf(kalcvfurw_ps->z10_dv); + DestroyMatrix_lf(kalcvfurw_ps->P10_dm); + + DestroyVector_lf(kalcvfurw_ps->zupdate_dv); + DestroyMatrix_lf(kalcvfurw_ps->Zpredtran_dm); + DestroyCell_lf(kalcvfurw_ps->Ppred_dc); + DestroyVector_lf(kalcvfurw_ps->ylhtranpred_dv); + + free(kalcvfurw_ps); + return ((TSkalcvfurw *)NULL); + } + else return (kalcvfurw_ps); +} + + +void kalcvf_urw(TSkalcvfurw *kalcvfurw_ps, void *dummy_ps) +{ + //See the notes of SWZ regarding the government's updating of the parameters in their Phillips-curve equation. + //NOTE: make sure that the value of kalcvfurw_ps->sigmasq and other input values are given. + int ti; + double workd, workdenominv; + //--- + int fss, kx; + double sigmasq_fix = kalcvfurw_ps->sigmasq; +// double sigmasq; + TSdmatrix *V_dm; + TSdmatrix *Zpredtran_dm; + TSdcell *Ppred_dc; + TSdvector *ylhtran_dv; + TSdmatrix *Xrhtran_dm; + //=== + TSdvector *workkxby1_dv = NULL; //kx-by-1. +// TSdvector *work1kxby1_dv = NULL; //kx-by-1. + TSdmatrix *workkxbykx_dm = NULL; //kx-by-kx symmetric and positive positive. +// //=== +// TSdvector *zbefore_dv = CreateVector_lf(kalcvfurw_ps->kx); +// TSdmatrix *Vbefore_dm = CreateMatrix_lf(kalcvfurw_ps->kx, kalcvfurw_ps->kx); +// TSdvector *zafter_dv = CreateVector_lf(kalcvfurw_ps->kx); +// TSdmatrix *Vafter_dm = CreateMatrix_lf(kalcvfurw_ps->kx, kalcvfurw_ps->kx); + //******* WARNING: Some dangerous pointer movement to gain efficiency ******* +// double *yt_p; +// double *Vbefore_p; +// double *Vafter_p; + TSdvector xt_sdv; + TSdvector zbefore_sdv; + //TSdmatrix Vbefore_sdm; + TSdvector zafter_sdv; + //TSdmatrix Vafter_sdm; + + + if (!kalcvfurw_ps) fn_DisplayError(".../kalcvf_urw(): the input argument kalcvfurw_ps must be created"); + if (!kalcvfurw_ps->V_dm || !kalcvfurw_ps->ylhtran_dv || !kalcvfurw_ps->Xrhtran_dm || !kalcvfurw_ps->z10_dv || !kalcvfurw_ps->P10_dm) + fn_DisplayError(".../kalcvf_urw(): input arguments kalcvfurw_ps->V_dm, kalcvfurw_ps->ylhtran_dv, kalcvfurw_ps->Xrhtran_dm, kalcvfurw_ps->z10_dv, kalcvfurw_ps->P10_dm must be given legal values"); + if (!(kalcvfurw_ps->P10_dm->flag & (M_SU | M_SL))) fn_DisplayError(".../kalcvf_urw(): the input argument kalcvfurw_ps->P10_dm must be symmetric"); + fss = kalcvfurw_ps->fss; + kx = kalcvfurw_ps->kx; + V_dm = kalcvfurw_ps->V_dm; + Zpredtran_dm = kalcvfurw_ps->Zpredtran_dm; + Ppred_dc = kalcvfurw_ps->Ppred_dc; + ylhtran_dv = kalcvfurw_ps->ylhtran_dv; + Xrhtran_dm = kalcvfurw_ps->Xrhtran_dm; + //--- + xt_sdv.n = kx; + xt_sdv.flag = V_DEF; + zbefore_sdv.n = kx; + zbefore_sdv.flag = V_DEF; + zafter_sdv.n = kx; + zafter_sdv.flag = V_DEF; + + //=== Memory allocation. + workkxby1_dv = CreateVector_lf(kx); + workkxbykx_dm = CreateMatrix_lf(kx, kx); + + + //------- The first period (ti=0). ------- + zbefore_sdv.v = kalcvfurw_ps->z10_dv->v; + zafter_sdv.v = Zpredtran_dm->M; + xt_sdv.v = Xrhtran_dm->M; + //--- + + workd = ylhtran_dv->v[0] - (kalcvfurw_ps->ylhtranpred_dv->v[0]=VectorDotVector(&xt_sdv, &zbefore_sdv)); //y_t - x_t'*z_{t-1}. + SymmatrixTimesVector(workkxby1_dv, kalcvfurw_ps->P10_dm, &xt_sdv, 1.0, 0.0); //P_{t|t-1} x_t; + + if (!kalcvfurw_ps->indx_tvsigmasq) + workdenominv = 1.0/(sigmasq_fix + VectorDotVector(&xt_sdv, workkxby1_dv)); //1/[sigma^2 + x_t' P_{t|t-1} x_t] + else if (kalcvfurw_ps->indx_tvsigmasq == 1) //See pp.37 and 37a in SWZ Learning NOTES. + workdenominv = 1.0/(sigmasq_fix*square(kalcvfurw_ps->z10_dv->v[0]) + VectorDotVector(&xt_sdv, workkxby1_dv)); //1/[sigma^2 + x_t' P_{t|t-1} x_t]; + else { + printf(".../kalman.c/kalcvf_urw(): Have not got time to deal with kalcvfurw_ps->indx_tvsigmasq defined in kalman.h other than 0 or 1"); + exit(EXIT_FAILURE); + } + + + //--- Updating z_{t+1|t}. + CopyVector0(&zafter_sdv, &zbefore_sdv); + VectorPlusMinusVectorUpdate(&zafter_sdv, workkxby1_dv, workd*workdenominv); //z_{t+1|t} = z_{t|t-1} + P_{t|t-1} x_t [y_t - x_t'*z_{t-1}] / [sigma^2 + x_t' P_{t|t-1} x_t]; + //--- Updating P_{t+1|t}. + CopyMatrix0(workkxbykx_dm, V_dm); + VectorTimesSelf(workkxbykx_dm, workkxby1_dv, -workdenominv, 1.0, (V_dm->flag & M_SU) ? 'U' : 'L'); + // - P_{t|t-1}*x_t * xt'*P_{t|t-1} / [sigma^2 + x_t' P_{t|t-1} x_t] + V; + MatrixPlusMatrix(Ppred_dc->C[0], kalcvfurw_ps->P10_dm, workkxbykx_dm); + //P_{t|t-1} - P_{t|t-1}*x_t * xt'*P_{t|t-1} / [sigma^2 + x_t' P_{t|t-1} x_t] + V; + Ppred_dc->C[0]->flag = M_GE | M_SU | M_SL; //This is necessary because if P10_dm is initialized as diagonal, it will have M_GE | M_SU | M_SL | M_UT | M_LT, + // which is no longer true for workkxbykx_dm and therefore gives Ppred_dc->C[0] with M_GE only as a result of MatrixPlusMatrix(). + //Done with all work* arrays. + + //------- The rest of the periods (ti=1:T-1). ------- + for (ti=1; ti<fss; ti++) { + //NOTE: ti=0 has been taken care of outside of this loop. + zbefore_sdv.v = Zpredtran_dm->M + (ti-1)*kx; + zafter_sdv.v = Zpredtran_dm->M + ti*kx; + xt_sdv.v = Xrhtran_dm->M + ti*kx; + //--- + workd = ylhtran_dv->v[ti] - (kalcvfurw_ps->ylhtranpred_dv->v[ti]=VectorDotVector(&xt_sdv, &zbefore_sdv)); //y_t - x_t'*z_{t-1}. + SymmatrixTimesVector(workkxby1_dv, Ppred_dc->C[ti-1], &xt_sdv, 1.0, 0.0); //P_{t|t-1} x_t; + if (!kalcvfurw_ps->indx_tvsigmasq) + workdenominv = 1.0/(sigmasq_fix + VectorDotVector(&xt_sdv, workkxby1_dv)); //1/[sigma^2 + x_t' P_{t|t-1} x_t] + else if (kalcvfurw_ps->indx_tvsigmasq == 1) //See pp.37 and 37a in SWZ Learning NOTES. + workdenominv = 1.0/(sigmasq_fix*square(zbefore_sdv.v[0]) + VectorDotVector(&xt_sdv, workkxby1_dv)); //1/[sigma^2 + x_t' P_{t|t-1} x_t] + else { + printf(".../kalman.c/kalcvf_urw(): Have not got time to deal with kalcvfurw_ps->indx_tvsigmasq defined in kalman.h other than 0 or 1"); + exit(EXIT_FAILURE); + } + //--- Updating z_{t+1|t}. + CopyVector0(&zafter_sdv, &zbefore_sdv); + VectorPlusMinusVectorUpdate(&zafter_sdv, workkxby1_dv, workd*workdenominv); //z_{t+1|t} = z_{t|t-1} + P_{t|t-1} x_t [y_t - x_t'*z_{t-1}] / [sigma^2 + x_t' P_{t|t-1} x_t]; + //--- Updating P_{t+1|t}. + CopyMatrix0(workkxbykx_dm, V_dm); + VectorTimesSelf(workkxbykx_dm, workkxby1_dv, -workdenominv, 1.0, (V_dm->flag & M_SU) ? 'U' : 'L'); + // - P_{t|t-1}*x_t * xt'*P_{t|t-1} / [sigma^2 + x_t' P_{t|t-1} x_t] + V; + MatrixPlusMatrix(Ppred_dc->C[ti], Ppred_dc->C[ti-1], workkxbykx_dm); + //P_{t|t-1} - P_{t|t-1}*x_t * xt'*P_{t|t-1} / [sigma^2 + x_t' P_{t|t-1} x_t] + V; + Ppred_dc->C[ti]->flag = M_GE | M_SU | M_SL; //This is necessary because if P10_dm is initialized as diagonal, it will have M_GE | M_SU | M_SL | M_UT | M_LT, + // which is no longer true for workkxbykx_dm and therefore gives Ppred_dc->C[0] with M_GE only as a result of MatrixPlusMatrix(). + //Done with all work* arrays. + } + CopyVector0(kalcvfurw_ps->zupdate_dv, &zafter_sdv); + Zpredtran_dm->flag = M_GE; + kalcvfurw_ps->ylhtranpred_dv->flag = V_DEF; + +// DestroyVector_lf(zbefore_dv); +// DestroyMatrix_lf(Vbefore_dm); +// DestroyVector_lf(zafter_dv); +// DestroyMatrix_lf(Vafter_dm); + + DestroyVector_lf(workkxby1_dv); +// DestroyVector_lf(work1kxby1_dv); + DestroyMatrix_lf(workkxbykx_dm); +} + + + +//----------------------------------------------------------------------------------------------------------------------- +//-- General constant (known-time-varying) Kalman filter for DSGE models. +//----------------------------------------------------------------------------------------------------------------------- +struct TSkalfiltv_tag *CreateTSkalfiltv(int ny, int nz, int T) +{ + int _i; + //=== + TSivector *rows_iv = CreateVector_int(T); + TSivector *cols_iv = CreateVector_int(T); + //~~~ Creating the structure and initializing the NULL pointers. + struct TSkalfiltv_tag *kalfiltv_ps = tzMalloc(1, struct TSkalfiltv_tag); + + + //--- Default value. + kalfiltv_ps->indxIni = 0; //1: using the initial condition with zt_tm1(:,1)=z0 and Pt_tm1(:,:,1)=P0; + //0: using the unconditional mean for any given regime at time 0. + //--- Other assignments. + kalfiltv_ps->ny = ny; + kalfiltv_ps->nz = nz; + kalfiltv_ps->T = T; + + + + //--------- Creates memory and assigns values. The order matters. + kalfiltv_ps->yt_dm = CreateMatrix_lf(ny, T); + kalfiltv_ps->at_dm = CreateMatrix_lf(ny, T); + // + for (_i=T-1; _i>=0; _i--) + { + rows_iv->v[_i] = ny; + cols_iv->v[_i] = nz; + } + rows_iv->flag = cols_iv->flag = V_DEF; + kalfiltv_ps->Ht_dc = CreateCell_lf(rows_iv, cols_iv); + // + for (_i=T-1; _i>=0; _i--) + { + rows_iv->v[_i] = ny; + cols_iv->v[_i] = ny; + } + kalfiltv_ps->Rt_dc = CreateCell_lf(rows_iv, cols_iv); + // + for (_i=T-1; _i>=0; _i--) + { + rows_iv->v[_i] = nz; + cols_iv->v[_i] = ny; + } + kalfiltv_ps->Gt_dc = CreateCell_lf(rows_iv, cols_iv); + // + kalfiltv_ps->bt_dm = CreateMatrix_lf(nz, T); + // + for (_i=T-1; _i>=0; _i--) + { + rows_iv->v[_i] = nz; + cols_iv->v[_i] = nz; + } + kalfiltv_ps->Ft_dc = CreateCell_lf(rows_iv, cols_iv); + kalfiltv_ps->Vt_dc = CreateCell_lf(rows_iv, cols_iv); + // + kalfiltv_ps->z0_dv = CreateVector_lf(nz); + kalfiltv_ps->P0_dm = CreateMatrix_lf(nz, nz); + + + //--- + kalfiltv_ps->zt_tm1_dm = CreateMatrix_lf(nz, T); + for (_i=T-1; _i>=0; _i--) + { + rows_iv->v[_i] = nz; + cols_iv->v[_i] = nz; + } + kalfiltv_ps->Pt_tm1_dc = CreateCell_lf(rows_iv, cols_iv); + + + //=== + DestroyVector_int(rows_iv); + DestroyVector_int(cols_iv); + + return (kalfiltv_ps); + +} +//--- +struct TSkalfiltv_tag *DestroyTSkalfiltv(struct TSkalfiltv_tag *kalfiltv_ps) +{ + if (kalfiltv_ps) + { + //=== The order matters! + DestroyMatrix_lf(kalfiltv_ps->yt_dm); + DestroyMatrix_lf(kalfiltv_ps->at_dm); + DestroyCell_lf(kalfiltv_ps->Ht_dc); + DestroyCell_lf(kalfiltv_ps->Rt_dc); + DestroyCell_lf(kalfiltv_ps->Gt_dc); + //--- + DestroyMatrix_lf(kalfiltv_ps->bt_dm); + DestroyCell_lf(kalfiltv_ps->Ft_dc); + DestroyCell_lf(kalfiltv_ps->Vt_dc); + //--- + DestroyVector_lf(kalfiltv_ps->z0_dv); + DestroyMatrix_lf(kalfiltv_ps->P0_dm); + //--- + DestroyMatrix_lf(kalfiltv_ps->zt_tm1_dm); + DestroyCell_lf(kalfiltv_ps->Pt_tm1_dc); + + + //--- + tzDestroy(kalfiltv_ps); //Must be freed last! + + return ((struct TSkalfiltv_tag *)NULL); + } + else return (kalfiltv_ps); +}; + + +//----------------------------------------------------------------------------------------------------------------------- +//-- Inputs for filter for Markov-switching DSGE models at any time t. +//----------------------------------------------------------------------------------------------------------------------- +struct TSkalfilmsinputs_1stapp_tag *CreateTSkalfilmsinputs_1stapp(int ny, int nz, int nst, int T) +{ + //~~~ Creating the structure and initializing the NULL pointers. + struct TSkalfilmsinputs_1stapp_tag *kalfilmsinputs_1stapp_ps = tzMalloc(1, struct TSkalfilmsinputs_1stapp_tag); + + //=== + TSivector *rows_iv = NULL; + TSivector *cols_iv = NULL; + + //--- Default value. + kalfilmsinputs_1stapp_ps->indxIni = 0; //1: using the initial condition with zt_tm1(:,1)=z0 and Pt_tm1(:,:,1)=P0; + //0: using the unconditional mean for any given regime at time 0. + kalfilmsinputs_1stapp_ps->tm1_track = -1; + //t-1 = -1: the initial conditions z_{1|0} and P_{1|0} are yet to be computed using InitializeKalman_z10_P10(). + //t-1 >= 0: z_{t|t-1} and P_{t|t-1} are updated up to t where t-1 = 1 to T. + //--- Other assignments. + kalfilmsinputs_1stapp_ps->ny = ny; + kalfilmsinputs_1stapp_ps->nz = nz; + kalfilmsinputs_1stapp_ps->nst = nst; + kalfilmsinputs_1stapp_ps->T = T; + + //--------- Creates memory and assigns values. The order matters. + kalfilmsinputs_1stapp_ps->yt_dm = CreateMatrix_lf(ny, T); + kalfilmsinputs_1stapp_ps->at_dm = CreateMatrix_lf(ny, nst); + // + rows_iv = CreateConstantVector_int(nst, ny); + cols_iv = CreateConstantVector_int(nst, nz); + kalfilmsinputs_1stapp_ps->Ht_dc = CreateCell_lf(rows_iv, cols_iv); + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + // + rows_iv = CreateConstantVector_int(nst, ny); + cols_iv = CreateConstantVector_int(nst, ny); + kalfilmsinputs_1stapp_ps->Rt_dc = CreateCell_lf(rows_iv, cols_iv); + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + // + rows_iv = CreateConstantVector_int(nst, nz); + cols_iv = CreateConstantVector_int(nst, ny); + kalfilmsinputs_1stapp_ps->Gt_dc = CreateCell_lf(rows_iv, cols_iv); + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + // + kalfilmsinputs_1stapp_ps->bt_dm = CreateMatrix_lf(nz, nst); + // + rows_iv = CreateConstantVector_int(nst, nz); + cols_iv = CreateConstantVector_int(nst, nz); + kalfilmsinputs_1stapp_ps->Ft_dc = CreateCell_lf(rows_iv, cols_iv); + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + // + rows_iv = CreateConstantVector_int(nst, nz); + cols_iv = CreateConstantVector_int(nst, nz); + kalfilmsinputs_1stapp_ps->Vt_dc = CreateCell_lf(rows_iv, cols_iv); + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + + kalfilmsinputs_1stapp_ps->z0_dm = CreateMatrix_lf(nz, nst); //nz-by-nst. + rows_iv = CreateConstantVector_int(nst, nz); + cols_iv = CreateConstantVector_int(nst, nz); + kalfilmsinputs_1stapp_ps->P0_dc = CreateCell_lf(rows_iv, cols_iv); //nz-by-nz-by-nst. + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + + //--- For output arguments. + rows_iv = CreateConstantVector_int(T+1, nz); + cols_iv = CreateConstantVector_int(T+1, nst); + kalfilmsinputs_1stapp_ps->zt_tm1_dc = CreateCell_lf(rows_iv, cols_iv); //nz-by-nst-by-(T+1). + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + // + rows_iv = CreateConstantVector_int(nst, nz); + cols_iv = CreateConstantVector_int(nst, nz); + kalfilmsinputs_1stapp_ps->Pt_tm1_d4 = CreateFourth_lf(T+1, rows_iv, cols_iv); //nz-by-nz-by-nst-by-(T+1). + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + + return (kalfilmsinputs_1stapp_ps); +} +//--- +struct TSkalfilmsinputs_1stapp_tag *DestroyTSkalfilmsinputs_1stapp(struct TSkalfilmsinputs_1stapp_tag *kalfilmsinputs_1stapp_ps) +{ + if (kalfilmsinputs_1stapp_ps) + { + //=== The order matters! + DestroyMatrix_lf(kalfilmsinputs_1stapp_ps->yt_dm); + DestroyMatrix_lf(kalfilmsinputs_1stapp_ps->at_dm); + DestroyCell_lf(kalfilmsinputs_1stapp_ps->Ht_dc); + DestroyCell_lf(kalfilmsinputs_1stapp_ps->Rt_dc); + DestroyCell_lf(kalfilmsinputs_1stapp_ps->Gt_dc); + //--- + DestroyMatrix_lf(kalfilmsinputs_1stapp_ps->bt_dm); + DestroyCell_lf(kalfilmsinputs_1stapp_ps->Ft_dc); + DestroyCell_lf(kalfilmsinputs_1stapp_ps->Vt_dc); + //--- + DestroyMatrix_lf(kalfilmsinputs_1stapp_ps->z0_dm); + DestroyCell_lf(kalfilmsinputs_1stapp_ps->P0_dc); + //--- + DestroyCell_lf(kalfilmsinputs_1stapp_ps->zt_tm1_dc); + DestroyFourth_lf(kalfilmsinputs_1stapp_ps->Pt_tm1_d4); + //--- + tzDestroy(kalfilmsinputs_1stapp_ps); //Must be freed last! + + return ((struct TSkalfilmsinputs_1stapp_tag *)NULL); + } + else return (kalfilmsinputs_1stapp_ps); +}; + + +//----------------------------------------------------------------------------------------------------------------------- +//-- OLD Code: Inputs for filter for Markov-switching DSGE models at any time t. +//----------------------------------------------------------------------------------------------------------------------- +struct TSkalfilmsinputs_tag *CreateTSkalfilmsinputs(int ny, int nz, int nRc, int nRstc, int nRv, int indxIndRegimes, int T) +{ + //~~~ Creating the structure and initializing the NULL pointers. + struct TSkalfilmsinputs_tag *kalfilmsinputs_ps = tzMalloc(1, struct TSkalfilmsinputs_tag); + + //=== + TSivector *rows_iv = NULL; + TSivector *cols_iv = NULL; + + //--- Default value. + kalfilmsinputs_ps->indxIni = 0; //1: using the initial condition with zt_tm1(:,1)=z0 and Pt_tm1(:,:,1)=P0; + //0: using the unconditional mean for any given regime at time 0. + //--- Other assignments. + kalfilmsinputs_ps->ny = ny; + kalfilmsinputs_ps->nz = nz; + kalfilmsinputs_ps->nRc = nRc; + kalfilmsinputs_ps->nRstc = nRstc; + kalfilmsinputs_ps->nRv = nRv; + kalfilmsinputs_ps->indxIndRegimes = indxIndRegimes; + kalfilmsinputs_ps->T = T; + + + //--------- Creates memory and assigns values. The order matters. + kalfilmsinputs_ps->yt_dm = CreateMatrix_lf(ny, T); + kalfilmsinputs_ps->at_dm = CreateMatrix_lf(ny, nRc); + // + rows_iv = CreateConstantVector_int(nRc, ny); + cols_iv = CreateConstantVector_int(nRc, nz); + kalfilmsinputs_ps->Ht_dc = CreateCell_lf(rows_iv, cols_iv); + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + // + rows_iv = CreateConstantVector_int(nRv, ny); + cols_iv = CreateConstantVector_int(nRv, ny); + kalfilmsinputs_ps->Rt_dc = CreateCell_lf(rows_iv, cols_iv); + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + // + rows_iv = CreateConstantVector_int(nRv, nz); + cols_iv = CreateConstantVector_int(nRv, ny); + kalfilmsinputs_ps->Gt_dc = CreateCell_lf(rows_iv, cols_iv); + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + // + kalfilmsinputs_ps->bt_dm = CreateMatrix_lf(nz, nRc); + // + rows_iv = CreateConstantVector_int(nRc, nz); + cols_iv = CreateConstantVector_int(nRc, nz); + kalfilmsinputs_ps->Ft_dc = CreateCell_lf(rows_iv, cols_iv); + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + // + rows_iv = CreateConstantVector_int(nRv, nz); + cols_iv = CreateConstantVector_int(nRv, nz); + kalfilmsinputs_ps->Vt_dc = CreateCell_lf(rows_iv, cols_iv); + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + // + if (indxIndRegimes) + { + kalfilmsinputs_ps->z0_dm = CreateMatrix_lf(nz, nRc*nRv); //nz-by-nRc*nRv if indxIndRegimes == 1 or nz-by-nRv if indxIndRegimes == 0. + // + rows_iv = CreateConstantVector_int(nRc*nRv, nz); + cols_iv = CreateConstantVector_int(nRc*nRv, nz); + kalfilmsinputs_ps->P0_dc = CreateCell_lf(rows_iv, cols_iv); //nz-by-nz-by-nRc*nRv if indxIndRegimes == 1 or nz-by-nz-by-nRv if indxIndRegimes == 0. + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + } + else + { + if (nRstc != nRv) fn_DisplayError("kalman.c/CreateTSkalfilmsinputs(): nRstc must equal to nRv when indxIndRegimes==0"); + kalfilmsinputs_ps->z0_dm = CreateMatrix_lf(nz, nRv); //nz-by-nRc*nRv if indxIndRegimes == 1 or nz-by-nRv if indxIndRegimes == 0. + // + rows_iv = CreateConstantVector_int(nRv, nz); + cols_iv = CreateConstantVector_int(nRv, nz); + kalfilmsinputs_ps->P0_dc = CreateCell_lf(rows_iv, cols_iv); //nz-by-nz-by-nRc*nRv if indxIndRegimes == 1 or nz-by-nz-by-nRv if indxIndRegimes == 0. + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + } + //--- For output arguments. + if (indxIndRegimes) + { + rows_iv = CreateConstantVector_int(T, nz); + cols_iv = CreateConstantVector_int(T, nRc*nRv); + kalfilmsinputs_ps->zt_tm1_dc = CreateCell_lf(rows_iv, cols_iv); //nz-by-nRc*nRv-by-T if indxIndRegimes==1, nz-by-nRv-by-T if indxIndRegimes==0 where nRc=nRv. + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + // + rows_iv = CreateConstantVector_int(nRc*nRv, nz); + cols_iv = CreateConstantVector_int(nRc*nRv, nz); + kalfilmsinputs_ps->Pt_tm1_d4 = CreateFourth_lf(T, rows_iv, cols_iv); //nz-by-nz-by-nRc*nRv-T if indxIndRegimes==1, nz-by-nz-by-nRv-by-T if indxIndRegimes==0 where nRc=nRv. + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + } + else + { + if (nRstc != nRv) fn_DisplayError("kalman.c/CreateTSkalfilmsinputs(): nRstc must equal to nRv when indxIndRegimes==0"); + rows_iv = CreateConstantVector_int(T, nz); + cols_iv = CreateConstantVector_int(T, nRv); + kalfilmsinputs_ps->zt_tm1_dc = CreateCell_lf(rows_iv, cols_iv); //nz-by-nRc*nRv-by-T if indxIndRegimes==1, nz-by-nRv-by-T if indxIndRegimes==0 where nRc=nRv. + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + // + rows_iv = CreateConstantVector_int(nRv, nz); + cols_iv = CreateConstantVector_int(nRv, nz); + kalfilmsinputs_ps->Pt_tm1_d4 = CreateFourth_lf(T, rows_iv, cols_iv); //nz-by-nz-by-nRc*nRv-T if indxIndRegimes==1, nz-by-nz-by-nRv-by-T if indxIndRegimes==0 where nRc=nRv. + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + } + + + //=== + DestroyVector_int(rows_iv); + DestroyVector_int(cols_iv); + + return (kalfilmsinputs_ps); + +} +//--- +struct TSkalfilmsinputs_tag *DestroyTSkalfilmsinputs(struct TSkalfilmsinputs_tag *kalfilmsinputs_ps) +{ + if (kalfilmsinputs_ps) + { + //=== The order matters! + DestroyMatrix_lf(kalfilmsinputs_ps->yt_dm); + DestroyMatrix_lf(kalfilmsinputs_ps->at_dm); + DestroyCell_lf(kalfilmsinputs_ps->Ht_dc); + DestroyCell_lf(kalfilmsinputs_ps->Rt_dc); + DestroyCell_lf(kalfilmsinputs_ps->Gt_dc); + //--- + DestroyMatrix_lf(kalfilmsinputs_ps->bt_dm); + DestroyCell_lf(kalfilmsinputs_ps->Ft_dc); + DestroyCell_lf(kalfilmsinputs_ps->Vt_dc); + //--- + DestroyMatrix_lf(kalfilmsinputs_ps->z0_dm); + DestroyCell_lf(kalfilmsinputs_ps->P0_dc); + //--- + DestroyCell_lf(kalfilmsinputs_ps->zt_tm1_dc); + DestroyFourth_lf(kalfilmsinputs_ps->Pt_tm1_d4); + //--- + tzDestroy(kalfilmsinputs_ps); //Must be freed last! + + return ((struct TSkalfilmsinputs_tag *)NULL); + } + else return (kalfilmsinputs_ps); +}; + + +#define LOG2PI (1.837877066409345e+000) //log(2*pi) +//----------------------------------------------------- +//-- Constant-parameters (known-time-varying) Kalman filter +//----------------------------------------------------- +double tz_kalfiltv(struct TSkalfiltv_tag *kalfiltv_ps) +{ + //General constant (known-time-varying) Kalman filter for DSGE models (conditional on all the parameters). + // It computes a sequence of one-step predictions and their covariance matrices, and the log likelihood. + // The function uses a forward recursion algorithm. See also the Matlab function fn_kalfil_tv.m + // + // State space model is defined as follows: + // y(t) = a(t) + H(t)*z(t) + eps(t) (observation or measurement equation) + // z(t) = b(t) + F(t)*z(t) + eta(t) (state or transition equation) + // where a(t), H(t), b(t), and F(t) depend on s_t that follows a Markov-chain process and are taken as given. + // + // Inputs are as follows: + // Y_T is a n_y-by-T matrix containing data [y(1), ... , y(T)]. + // a is an n_y-by-T matrix of time-varying input vectors in the measurement equation. + // H is an n_y-by-n_z-by-T 3-D of time-varying matrices in the measurement equation. + // R is an n_y-by-n_y-by-T 3-D of time-varying covariance matrices for the error in the measurement equation. + // G is an n_z-by-n_y-by-T 3-D of time-varying E(eta_t * eps_t'). + // ------ + // b is an n_z-by-T matrix of time-varying input vectors in the state equation with b(:,1) as an initial condition. + // F is an n_z-by-n_z-by-T 3-D of time-varying transition matrices in the state equation with F(:,:,1) as an initial condition. + // V is an n_z-by-n_z-by-T 3-D of time-varying covariance matrices for the error in the state equation with V(:,:,1) as an initial condition. + // ------ + // indxIni: 1: using the initial condition with zt_tm1(:,1)=z0 and Pt_tm1(:,:,1)=P0; + // 0: using the unconditional mean for any given regime at time 0. + // z0 is an n_z-by-1 vector of initial condition when indxIni=1. (Do not enter if indxIni=0.) + // P0 is an n_z-by-n_z matrix of initial condition when indxIni=1. (Do not enter if indxIni=0.) + // + // Outputs are as follows: + // loglh is a value of the log likelihood function of the state-space model + // under the assumption that errors are multivariate Gaussian. + // zt_tm1 is an n_z-by-T matrices of one-step predicted state vectors with z0_0m1 as an initial condition (base-0 first element) + // and with z_{T|T-1} as the last element. Thus, we can use it as a base-1 vector. + // Pt_tm1 is an n_z-by-n_z-by-T 3-D of covariance matrices of zt_tm1 with P0_0m1 as though it were a initial condition + // and with P_{T|T-1} as the last element. Thus, we can use it as though it were a base-1 cell. + // + // The initial state vector and its covariance matrix are computed under the bounded (stationary) condition: + // z0_0m1 = (I-F(:,:,1))\b(:,1) + // vec(P0_0m1) = (I-kron(F(:,:,1),F(:,:,1)))\vec(V(:,:,1)) + // Note that all eigenvalues of the matrix F(:,:,1) are inside the unit circle when the state-space model is bounded (stationary). + // + // March 2007, written by Tao Zha + // See Hamilton's book ([13.2.13] -- [13.2.22]), Harvey (pp.100-106), and LiuWZ Model I NOTES pp.001-003. + + int T = kalfiltv_ps->T; + int Tp1 = T + 1; + int ny = kalfiltv_ps->ny; + int nz = kalfiltv_ps->nz; + int indx_badlh = 0; //1: bad likelihood with, say, -infinity of the LH value. + int tdata, ti; + //--- Work arguments. + int nz2 = square(nz); + TSdmatrix *Wnzbynz_dm = CreateMatrix_lf(nz,nz); + TSdmatrix *Wnz2bynz2_dm = CreateMatrix_lf(nz2,nz2); + TSdmatrix *W2nz2bynz2_dm = CreateMatrix_lf(nz2,nz2); + TSdvector *wP0_dv = CreateVector_lf(nz2); + //+ + TSdvector yt_sdv, at_sdv, zt_tm1_sdv, ztp1_t_sdv, btp1_sdv; //double loglh_tdata; //logdetDtdata. + TSdvector *wny_dv = CreateVector_lf(ny); + TSdmatrix *Wnzbyny_dm = CreateMatrix_lf(nz,ny); + TSdmatrix *W2nzbynz_dm = CreateMatrix_lf(nz,nz); + TSdmatrix *PHtran_tdata_dm = CreateMatrix_lf(nz,ny); + TSdvector *etdata_dv = CreateVector_lf(ny); + TSdmatrix *Dtdata_dm = CreateMatrix_lf(ny,ny); + TSdmatrix *Kt_tdata0_dm = CreateMatrix_lf(nz,ny); + TSdmatrix *Kt_tdata_dm = CreateMatrix_lf(nz,ny); + //--- For eigenvalue decompositions + int ki; + int errflag; + double eigmax, logdet_Dtdata; + TSdzvector *evals_dzv = NULL; + TSdvector *evals_abs_dv = NULL; //Absolute eigenvalues. + //--- Input arguments. + TSdmatrix *yt_dm = kalfiltv_ps->yt_dm; //ny-by-T. + TSdmatrix *at_dm = kalfiltv_ps->at_dm; //ny-by-T. + TSdcell *Ht_dc = kalfiltv_ps->Ht_dc; //ny-by-nz-by-T. + TSdcell *Rt_dc = kalfiltv_ps->Rt_dc; //ny-by-ny-by-T. Covariance matrix for the measurement equation. + TSdcell *Gt_dc = kalfiltv_ps->Gt_dc; //nz-by-ny-by-T. Cross-covariance. + // + TSdmatrix *bt_dm = kalfiltv_ps->bt_dm; //nz-by-T. + TSdcell *Ft_dc = kalfiltv_ps->Ft_dc; //nz-by-nz-by-T. + TSdcell *Vt_dc = kalfiltv_ps->Vt_dc; //nz-by-nz-by-T. Covariance matrix for the state equation. + // + TSdvector *z0_dv = kalfiltv_ps->z0_dv; //nz-by-1; + TSdmatrix *P0_dm = kalfiltv_ps->P0_dm; //nz-by-nz. + //--- Output arguments. + double loglh; //log likelihood. + TSdmatrix *zt_tm1_dm = kalfiltv_ps->zt_tm1_dm; //nz-by-T. + TSdcell *Pt_tm1_dc = kalfiltv_ps->Pt_tm1_dc; //nz-by-nz-T. + + + + //=== Initializing. + if (!kalfiltv_ps->indxIni) + { + InitializeDiagonalMatrix_lf(Wnzbynz_dm, 1.0); //To be used for I(nz) - + InitializeDiagonalMatrix_lf(Wnz2bynz2_dm, 1.0); //To be used for I(nz2) - + + //=== Eigenanalysis to determine the roots to ensure boundedness. + evals_dzv = CreateVector_dz(nz); + evals_abs_dv = CreateVector_lf(nz); + errflag = eigrgen(evals_dzv, (TSdzmatrix *)NULL, (TSdzmatrix *)NULL, Ft_dc->C[0]); + if (errflag) fn_DisplayError("tz_kalfiltv() in kalman.c: eigen decomposition failed"); + for (ki=nz-1; ki>=0; ki--) evals_abs_dv->v[ki] = sqrt(square(evals_dzv->real->v[ki]) + square(evals_dzv->imag->v[ki])); + evals_abs_dv->flag = V_DEF; + eigmax = MaxVector(evals_abs_dv); + if (eigmax < (1.0+1.0e-14)) + { + //--- Getting z0_dv: zt_tm1(:,1) = (eye(n_z)-F(:,:,1))\b(:,1); + MatrixMinusMatrix(Wnzbynz_dm, Wnzbynz_dm, Ft_dc->C[0]); + CopySubmatrix2vector(z0_dv, 0, bt_dm, 0, 0, bt_dm->nrows); + bdivA_rgens(z0_dv, z0_dv, '\\', Wnzbynz_dm); + //Done with Wnzbynz_dm. + //--- Getting P0_dm: Pt_tm1(:,:,1) = reshape((eye(n_z^2)-kron(F(:,:,1),F(:,:,1)))\V1(:),n_z,n_z); + tz_kron(W2nz2bynz2_dm, Ft_dc->C[0], Ft_dc->C[0]); + MatrixMinusMatrix(Wnz2bynz2_dm, Wnz2bynz2_dm, W2nz2bynz2_dm); + CopySubmatrix2vector(wP0_dv, 0, Vt_dc->C[0], 0, 0, nz2); + bdivA_rgens(wP0_dv, wP0_dv, '\\', Wnz2bynz2_dm); + CopySubvector2matrix_unr(P0_dm, 0, 0, wP0_dv, 0, nz2); + //Done with all w*_dv and W*_dm. + } + else + { + fprintf(stdout, "Fatal error: tz_kalfiltv() in kalman.c: the system is non-stationary solutions\n" + " and the initial conditions must be supplied by, say, input arguments"); + fflush(stdout); + exit( EXIT_FAILURE ); + } + } + CopySubvector2matrix(zt_tm1_dm, 0, 0, z0_dv, 0, z0_dv->n); + CopyMatrix0(Pt_tm1_dc->C[0], P0_dm); + + //====== See p.002 in LiuWZ. ====== + at_sdv.n = yt_sdv.n = yt_dm->nrows; + at_sdv.flag = yt_sdv.flag = V_DEF; + zt_tm1_sdv.n = ztp1_t_sdv.n = zt_tm1_dm->nrows; + zt_tm1_sdv.flag = ztp1_t_sdv.flag = V_DEF; + btp1_sdv.n = bt_dm->nrows; + btp1_sdv.flag = V_DEF; + loglh = 0.0; + for (tdata=0; tdata<T; tdata++ ) + { + //Base-0 timing. + ti = tdata + 1; //Next period. + + //--- Setup. + MatrixTimesMatrix(PHtran_tdata_dm, Pt_tm1_dc->C[tdata], Ht_dc->C[tdata], 1.0, 0.0, 'N', 'T'); + + //--- Data. + //- etdata = Y_T(:,tdata) - a(:,tdata) - Htdata*ztdata; + yt_sdv.v = yt_dm->M + tdata*yt_dm->nrows; + at_sdv.v = at_dm->M + tdata*at_dm->nrows; + zt_tm1_sdv.v = zt_tm1_dm->M + tdata*zt_tm1_dm->nrows; + VectorMinusVector(etdata_dv, &yt_sdv, &at_sdv); + MatrixTimesVector(etdata_dv, Ht_dc->C[tdata], &zt_tm1_sdv, -1.0, 1.0, 'N'); + //+ Dtdata = Htdata*PHtran_tdata + R(:,:,tdata); + CopyMatrix0(Dtdata_dm, Rt_dc->C[tdata]); + MatrixTimesMatrix(Dtdata_dm, Ht_dc->C[tdata], PHtran_tdata_dm, 1.0, 1.0, 'N', 'N'); + ScalarTimesMatrixSquare(Dtdata_dm, 0.5, Dtdata_dm, 'T', 0.5); //Making it symmetric against some rounding errors. + //This making-symmetric is very IMPORTANT; otherwise, we will get the matrix being singular message + // and eigenvalues being negative for the SPD matrix, etc. Then the likelihood becomes either + // a bad number or a complex number. + Dtdata_dm->flag = Dtdata_dm->flag | M_SU | M_SL; + + //--- Forming the log likelihood. + if (!isfinite(logdet_Dtdata=logdetspd(Dtdata_dm))) return (kalfiltv_ps->loglh = -NEARINFINITY); + bdivA_rgens(wny_dv, etdata_dv, '/', Dtdata_dm); + loglh += -(0.5*ny)*LOG2PI - 0.5*logdet_Dtdata - 0.5*VectorDotVector(wny_dv, etdata_dv); + //loglh += -(0.5*ny)*LOG2PI - 0.5*logdeterminant(Dtdata_dm) - 0.5*VectorDotVector(wny_dv, etdata_dv); + //Done with all w*_dv. + + + //--- Updating zt_tm1_dm and Pt_tm1_dc by ztp1_t_sdv and Pt_tm1_dc->C[ti]. + if (ti<T) + { + //Updating only up to tdata=T-2. The values at ti=T or tdata=T-1 will not be used in the likelihood function. + + //- Kt_tdata = (Ft*PHtran_tdata+G(:,:,tdata))/Dtdata; + CopyMatrix0(Kt_tdata0_dm, Gt_dc->C[tdata]); + MatrixTimesMatrix(Kt_tdata0_dm, Ft_dc->C[ti], PHtran_tdata_dm, 1.0, 1.0, 'N', 'N'); + BdivA_rrect(Kt_tdata_dm, Kt_tdata0_dm, '/', Dtdata_dm); + //+ zt_tm1(:,t) = b(:,t) + Ft*zt_tm1(:,tdata) + Kt_tdata*etdata; + ztp1_t_sdv.v = zt_tm1_dm->M + ti*zt_tm1_dm->nrows; + MatrixTimesVector(&ztp1_t_sdv, Ft_dc->C[ti], &zt_tm1_sdv, 1.0, 0.0, 'N'); + MatrixTimesVector(&ztp1_t_sdv, Kt_tdata_dm, etdata_dv, 1.0, 1.0, 'N'); + btp1_sdv.v = bt_dm->M + ti*btp1_sdv.n; + VectorPlusMinusVectorUpdate(&ztp1_t_sdv, &btp1_sdv, 1.0); + //+ Pt_tm1(:,:,t) = Ft*Ptdata*Fttran - Kt_tdata*Dtdata*Kt_tdatatran + V(:,:,t); + CopyMatrix0(Pt_tm1_dc->C[ti], Vt_dc->C[ti]); + MatrixTimesMatrix(Wnzbyny_dm, Kt_tdata_dm, Dtdata_dm, 1.0, 0.0, 'N', 'N'); + MatrixTimesMatrix(Wnzbynz_dm, Wnzbyny_dm, Kt_tdata_dm, 1.0, 0.0, 'N', 'T'); + MatrixPlusMinusMatrixUpdate(Pt_tm1_dc->C[ti], Wnzbynz_dm, -1.0); + //Done with all W*_dm. + MatrixTimesMatrix(Wnzbynz_dm, Ft_dc->C[ti], Pt_tm1_dc->C[tdata], 1.0, 0.0, 'N', 'N'); + MatrixTimesMatrix(W2nzbynz_dm, Wnzbynz_dm, Ft_dc->C[ti], 1.0, 0.0, 'N', 'T'); + MatrixPlusMatrixUpdate(Pt_tm1_dc->C[ti], W2nzbynz_dm); + //Done with all W*_dm. + } + } + zt_tm1_dm->flag = M_GE; + + //=== + DestroyVector_dz(evals_dzv); + DestroyVector_lf(evals_abs_dv); + DestroyMatrix_lf(Wnzbynz_dm); + DestroyMatrix_lf(Wnz2bynz2_dm); + DestroyMatrix_lf(W2nz2bynz2_dm); + DestroyVector_lf(wP0_dv); + // + DestroyVector_lf(wny_dv); + DestroyMatrix_lf(Wnzbyny_dm); + DestroyMatrix_lf(W2nzbynz_dm); + DestroyMatrix_lf(PHtran_tdata_dm); + DestroyVector_lf(etdata_dv); + DestroyMatrix_lf(Dtdata_dm); + DestroyMatrix_lf(Kt_tdata0_dm); + DestroyMatrix_lf(Kt_tdata_dm); + + return (kalfiltv_ps->loglh = loglh); +} +/** +double tz_kalfiltv(struct TSkalfiltv_tag *kalfiltv_ps) +{ + //This function is used to test tz_logTimetCondLH_kalfiltv(). + int T = kalfiltv_ps->T; + int tdata; + double loglh; + + loglh = 0.0; + for (tdata=0; tdata<T; tdata++) loglh += tz_logTimetCondLH_kalfiltv(0, tdata+1, kalfiltv_ps); + + return (loglh); +} +/**/ +//----------------------------------------------------- +//-- Updating Kalman filter at time t for constant-parameters (or known-time-varying) Kalman filter. +//----------------------------------------------------- +double tz_logTimetCondLH_kalfiltv(int st, int inpt, struct TSkalfiltv_tag *kalfiltv_ps) +{ + //st: base-0 grand regime at time t, which is just a dummy for this constant-parameter function in order to use + // Waggoner's automatic functions. + //inpt: base-1 in the sense that inpt>=1 to deal with the time series situation where S_T is (T+1)-by-1 and Y_T is T+nlags_max-by-1. + // The 1st element for S_T is S_T[1] while S_T[0] is s_0 (initial condition). + // The 1st element for Y_T, however, is Y_T[nlags_max+1-1]. + //See (42.3) on p.42 in the SWZII NOTES. + // + //log LH at time t for constant (known-time-varying) Kalman-filter DSGE models (conditional on all the parameters). + // It computes a sequence of one-step predictions and their covariance matrices, and the log likelihood at time t. + // The function uses a forward recursion algorithm. See also the Matlab function fn_kalfil_tv.m + // + // State space model is defined as follows: + // y(t) = a(t) + H(t)*z(t) + eps(t) (observation or measurement equation) + // z(t) = b(t) + F(t)*z(t) + eta(t) (state or transition equation) + // where a(t), H(t), b(t), and F(t) depend on s_t that follows a Markov-chain process and are taken as given. + // + // Inputs are as follows: + // Y_T is a n_y-by-T matrix containing data [y(1), ... , y(T)]. + // a is an n_y-by-T matrix of time-varying input vectors in the measurement equation. + // H is an n_y-by-n_z-by-T 3-D of time-varying matrices in the measurement equation. + // R is an n_y-by-n_y-by-T 3-D of time-varying covariance matrices for the error in the measurement equation. + // G is an n_z-by-n_y-by-T 3-D of time-varying E(eta_t * eps_t'). + // ------ + // b is an n_z-by-T matrix of time-varying input vectors in the state equation with b(:,1) as an initial condition. + // F is an n_z-by-n_z-by-T 3-D of time-varying transition matrices in the state equation with F(:,:,1) as an initial condition. + // V is an n_z-by-n_z-by-T 3-D of time-varying covariance matrices for the error in the state equation with V(:,:,1) as an initial condition. + // ------ + // indxIni: 1: using the initial condition with zt_tm1(:,1)=z0 and Pt_tm1(:,:,1)=P0; + // 0: using the unconditional mean for any given regime at time 0. + // z0 is an n_z-by-1 vector of initial condition when indxIni=1. (Value to be assigned if indxIni=0.) + // P0 is an n_z-by-n_z matrix of initial condition when indxIni=1. (Value to be assigned if indxIni=0.) + // + // Outputs are as follows: + // loglh is a value of the log likelihood function of the state-space model + // under the assumption that errors are multivariate Gaussian. + // zt_tm1 is an n_z-by-T matrices of one-step predicted state vectors with z0_0m1 as an initial condition (base-0 first element) + // and with z_{T|T-1} as the last element. Thus, we can use it as a base-1 vector. + // Pt_tm1 is an n_z-by-n_z-by-T 3-D of covariance matrices of zt_tm1 with P0_0m1 as though it were a initial condition + // and with P_{T|T-1} as the last element. Thus, we can use it as though it were a base-1 cell. + // + // The initial state vector and its covariance matrix are computed under the bounded (stationary) condition: + // z0_0m1 = (I-F(:,:,1))\b(:,1) + // vec(P0_0m1) = (I-kron(F(:,:,1),F(:,:,1)))\vec(V(:,:,1)) + // Note that all eigenvalues of the matrix F(:,:,1) are inside the unit circle when the state-space model is bounded (stationary). + // + // April 2008, written by Tao Zha + // See Hamilton's book ([13.2.13] -- [13.2.22]), Harvey (pp.100-106), and LiuWZ Model I NOTES pp.001-003. + + //--- Output arguments. + double loglh_timet; //log likelihood at time t. + TSdmatrix *zt_tm1_dm = kalfiltv_ps->zt_tm1_dm; //nz-by-T. + TSdcell *Pt_tm1_dc = kalfiltv_ps->Pt_tm1_dc; //nz-by-nz-T. + //--- Input arguments. + int tdata, tp1; + TSdvector *z0_dv = kalfiltv_ps->z0_dv; //nz-by-1; + TSdmatrix *P0_dm = kalfiltv_ps->P0_dm; //nz-by-nz. + int T = kalfiltv_ps->T; + int ny = kalfiltv_ps->ny; + int nz = kalfiltv_ps->nz; + //--- Work arguments. + int nz2 = square(nz); + TSdmatrix *Wnzbynz_dm = CreateMatrix_lf(nz,nz); + TSdmatrix *Wnz2bynz2_dm = CreateMatrix_lf(nz2,nz2); + TSdmatrix *W2nz2bynz2_dm = CreateMatrix_lf(nz2,nz2); + TSdvector *wP0_dv = CreateVector_lf(nz2); + //+ + TSdvector yt_sdv, at_sdv, zt_tm1_sdv, ztp1_t_sdv, btp1_sdv; + TSdvector *wny_dv = CreateVector_lf(ny); + TSdmatrix *Wnzbyny_dm = CreateMatrix_lf(nz,ny); + TSdmatrix *W2nzbynz_dm = CreateMatrix_lf(nz,nz); + TSdmatrix *PHtran_tdata_dm = CreateMatrix_lf(nz,ny); + TSdvector *etdata_dv = CreateVector_lf(ny); + TSdmatrix *Dtdata_dm = CreateMatrix_lf(ny,ny); + TSdmatrix *Kt_tdata0_dm = CreateMatrix_lf(nz,ny); + TSdmatrix *Kt_tdata_dm = CreateMatrix_lf(nz,ny); + //--- For eigenvalue decompositions + int ki; + int errflag; + double eigmax, logdet_Dtdata; + TSdzvector *evals_dzv = NULL; + TSdvector *evals_abs_dv = NULL; //Absolute eigenvalues. + //--- Input arguments. + TSdmatrix *yt_dm = kalfiltv_ps->yt_dm; //ny-by-T. + TSdmatrix *at_dm = kalfiltv_ps->at_dm; //ny-by-T. + TSdcell *Ht_dc = kalfiltv_ps->Ht_dc; //ny-by-nz-by-T. + TSdcell *Rt_dc = kalfiltv_ps->Rt_dc; //ny-by-ny-by-T. Covariance matrix for the measurement equation. + TSdcell *Gt_dc = kalfiltv_ps->Gt_dc; //nz-by-ny-by-T. Cross-covariance. + // + TSdmatrix *bt_dm = kalfiltv_ps->bt_dm; //nz-by-T. + TSdcell *Ft_dc = kalfiltv_ps->Ft_dc; //nz-by-nz-by-T. + TSdcell *Vt_dc = kalfiltv_ps->Vt_dc; //nz-by-nz-by-T. Covariance matrix for the state equation. + // + + + tdata = (tp1=inpt) - 1; //Base-0 time. + + //======= Initial condition. ======= + if (tdata==0) + { + //=== Initializing. + if (!kalfiltv_ps->indxIni) + { + InitializeDiagonalMatrix_lf(Wnzbynz_dm, 1.0); //To be used for I(nz) - + InitializeDiagonalMatrix_lf(Wnz2bynz2_dm, 1.0); //To be used for I(nz2) - + + //=== Eigenanalysis to determine the roots to ensure boundedness. + evals_dzv = CreateVector_dz(nz); + evals_abs_dv = CreateVector_lf(nz); + errflag = eigrgen(evals_dzv, (TSdzmatrix *)NULL, (TSdzmatrix *)NULL, Ft_dc->C[0]); + if (errflag) fn_DisplayError("tz_logTimetCondLH_kalfiltv() in kalman.c: eigen decomposition failed"); + for (ki=nz-1; ki>=0; ki--) evals_abs_dv->v[ki] = sqrt(square(evals_dzv->real->v[ki]) + square(evals_dzv->imag->v[ki])); + evals_abs_dv->flag = V_DEF; + eigmax = MaxVector(evals_abs_dv); + if (eigmax < (1.0+1.0e-14)) + { + //--- Getting z0_dv: zt_tm1(:,1) = (eye(n_z)-F(:,:,1))\b(:,1); + MatrixMinusMatrix(Wnzbynz_dm, Wnzbynz_dm, Ft_dc->C[0]); + CopySubmatrix2vector(z0_dv, 0, bt_dm, 0, 0, bt_dm->nrows); + bdivA_rgens(z0_dv, z0_dv, '\\', Wnzbynz_dm); + //Done with Wnzbynz_dm. + //--- Getting P0_dm: Pt_tm1(:,:,1) = reshape((eye(n_z^2)-kron(F(:,:,1),F(:,:,1)))\V1(:),n_z,n_z); + tz_kron(W2nz2bynz2_dm, Ft_dc->C[0], Ft_dc->C[0]); + MatrixMinusMatrix(Wnz2bynz2_dm, Wnz2bynz2_dm, W2nz2bynz2_dm); + CopySubmatrix2vector(wP0_dv, 0, Vt_dc->C[0], 0, 0, nz2); + bdivA_rgens(wP0_dv, wP0_dv, '\\', Wnz2bynz2_dm); + CopySubvector2matrix_unr(P0_dm, 0, 0, wP0_dv, 0, nz2); + //Done with all w*_dv and W*_dm. + } + else + { + fprintf(FPTR_DEBUG, "Fatal error: tz_logTimetCondLH_kalfiltv() in kalman.c: the system is non-stationary solutions\n" + " and thus the initial conditions must be supplied by, say, input arguments"); + fflush(FPTR_DEBUG); + exit( EXIT_FAILURE ); + } + } + CopySubvector2matrix(zt_tm1_dm, 0, 0, z0_dv, 0, z0_dv->n); + CopyMatrix0(Pt_tm1_dc->C[tdata], P0_dm); + } + + + //======= Liklihood at time t (see p.002 in LiuWZ). ======= + at_sdv.n = yt_sdv.n = yt_dm->nrows; + at_sdv.flag = yt_sdv.flag = V_DEF; + zt_tm1_sdv.n = ztp1_t_sdv.n = zt_tm1_dm->nrows; + zt_tm1_sdv.flag = ztp1_t_sdv.flag = V_DEF; + btp1_sdv.n = bt_dm->nrows; + btp1_sdv.flag = V_DEF; + + //--- Setup. + MatrixTimesMatrix(PHtran_tdata_dm, Pt_tm1_dc->C[tdata], Ht_dc->C[tdata], 1.0, 0.0, 'N', 'T'); + + //--- Data. + //- etdata = Y_T(:,tdata) - a(:,tdata) - Htdata*ztdata; + yt_sdv.v = yt_dm->M + tdata*yt_dm->nrows; + at_sdv.v = at_dm->M + tdata*at_dm->nrows; + zt_tm1_sdv.v = zt_tm1_dm->M + tdata*zt_tm1_dm->nrows; + VectorMinusVector(etdata_dv, &yt_sdv, &at_sdv); + MatrixTimesVector(etdata_dv, Ht_dc->C[tdata], &zt_tm1_sdv, -1.0, 1.0, 'N'); + //+ Dtdata = Htdata*PHtran_tdata + R(:,:,tdata); + CopyMatrix0(Dtdata_dm, Rt_dc->C[tdata]); + MatrixTimesMatrix(Dtdata_dm, Ht_dc->C[tdata], PHtran_tdata_dm, 1.0, 1.0, 'N', 'N'); + ScalarTimesMatrixSquare(Dtdata_dm, 0.5, Dtdata_dm, 'T', 0.5); //Making it symmetric against some rounding errors. + //This making-symmetric is very IMPORTANT; otherwise, we will get the matrix being singular message + // and eigenvalues being negative for the SPD matrix, etc. Then the likelihood becomes either + // a bad number or a complex number. + Dtdata_dm->flag = Dtdata_dm->flag | M_SU | M_SL; + + //--- Forming the log likelihood. + if (!isfinite(logdet_Dtdata=logdetspd(Dtdata_dm))) return (loglh_timet = -NEARINFINITY); + bdivA_rgens(wny_dv, etdata_dv, '/', Dtdata_dm); + loglh_timet = -(0.5*ny)*LOG2PI - 0.5*logdet_Dtdata - 0.5*VectorDotVector(wny_dv, etdata_dv); + //Done with all w*_dv. + + + //======= Updating for the next period. ======= + //--- Updating zt_tm1_dm and Pt_tm1_dc by ztp1_t_sdv and Pt_tm1_dc->C[ti]. + if (tp1<T) + { + //Updating only up to tdata=T-2, because the values at tp1=T or tdata=T-1 will NOT be used in the likelihood function. + + //- Kt_tdata = (Ft*PHtran_tdata+G(:,:,tdata))/Dtdata; + CopyMatrix0(Kt_tdata0_dm, Gt_dc->C[tdata]); + MatrixTimesMatrix(Kt_tdata0_dm, Ft_dc->C[tp1], PHtran_tdata_dm, 1.0, 1.0, 'N', 'N'); + BdivA_rrect(Kt_tdata_dm, Kt_tdata0_dm, '/', Dtdata_dm); + //+ zt_tm1(:,t) = b(:,t) + Ft*zt_tm1(:,tdata) + Kt_tdata*etdata; + ztp1_t_sdv.v = zt_tm1_dm->M + tp1*zt_tm1_dm->nrows; + MatrixTimesVector(&ztp1_t_sdv, Ft_dc->C[tp1], &zt_tm1_sdv, 1.0, 0.0, 'N'); + MatrixTimesVector(&ztp1_t_sdv, Kt_tdata_dm, etdata_dv, 1.0, 1.0, 'N'); + btp1_sdv.v = bt_dm->M + tp1*btp1_sdv.n; + VectorPlusMinusVectorUpdate(&ztp1_t_sdv, &btp1_sdv, 1.0); + //+ Pt_tm1(:,:,t) = Ft*Ptdata*Fttran - Kt_tdata*Dtdata*Kt_tdatatran + V(:,:,t); + CopyMatrix0(Pt_tm1_dc->C[tp1], Vt_dc->C[tp1]); + MatrixTimesMatrix(Wnzbyny_dm, Kt_tdata_dm, Dtdata_dm, 1.0, 0.0, 'N', 'N'); + MatrixTimesMatrix(Wnzbynz_dm, Wnzbyny_dm, Kt_tdata_dm, 1.0, 0.0, 'N', 'T'); + MatrixPlusMinusMatrixUpdate(Pt_tm1_dc->C[tp1], Wnzbynz_dm, -1.0); + //Done with all W*_dm. + MatrixTimesMatrix(Wnzbynz_dm, Ft_dc->C[tp1], Pt_tm1_dc->C[tdata], 1.0, 0.0, 'N', 'N'); + MatrixTimesMatrix(W2nzbynz_dm, Wnzbynz_dm, Ft_dc->C[tp1], 1.0, 0.0, 'N', 'T'); + MatrixPlusMatrixUpdate(Pt_tm1_dc->C[tp1], W2nzbynz_dm); + //Done with all W*_dm. + } + zt_tm1_dm->flag = M_GE; + + //=== + DestroyVector_dz(evals_dzv); + DestroyVector_lf(evals_abs_dv); + DestroyMatrix_lf(Wnzbynz_dm); + DestroyMatrix_lf(Wnz2bynz2_dm); + DestroyMatrix_lf(W2nz2bynz2_dm); + DestroyVector_lf(wP0_dv); + // + DestroyVector_lf(wny_dv); + DestroyMatrix_lf(Wnzbyny_dm); + DestroyMatrix_lf(W2nzbynz_dm); + DestroyMatrix_lf(PHtran_tdata_dm); + DestroyVector_lf(etdata_dv); + DestroyMatrix_lf(Dtdata_dm); + DestroyMatrix_lf(Kt_tdata0_dm); + DestroyMatrix_lf(Kt_tdata_dm); + + return (loglh_timet); +} + + +//----------------------------------------------------- +//- WARNING: bedore using this function, make sure to call the following functions +// Only once in creating lwzmodel_ps: Refresh_kalfilms_*(lwzmodel_ps); +// Everytime when parameters are changed: RefreshEverything(); RefreRunningGensys_allcases(lwzmodel_ps) in particular. +//----------------------------------------------------- +double logTimetCondLH_kalfilms_1stapp(int st, int inpt, struct TSkalfilmsinputs_1stapp_tag *kalfilmsinputs_1stapp_ps, struct TStateModel_tag *smodel_ps) +{ + //st: base-0 grand regime -- deals with the cross-section values at time t. + //inpt: base-1 in the sense that inpt>=1 to deal with the time series situation where S_T is (T+1)-by-1 and Y_T is T+nlags_max-by-1. + // The 1st element for S_T is S_T[1] while S_T[0] is s_0 (initial condition). + // The 1st element for Y_T, however, is Y_T[nlags_max+1-1]. + //See (42.3) on p.42 in the SWZII NOTES. + + //-- Output arguments + double loglh_timet; + //--- input arguments + TSdmatrix *yt_dm = kalfilmsinputs_1stapp_ps->yt_dm; //ny-by-T. + TSdmatrix *at_dm = kalfilmsinputs_1stapp_ps->at_dm; //ny-by-nst. + TSdcell *Ht_dc = kalfilmsinputs_1stapp_ps->Ht_dc; //ny-by-nz-by-nst. + TSdcell *Rt_dc = kalfilmsinputs_1stapp_ps->Rt_dc; //ny-by-ny-by-nst. Covariance matrix for the measurement equation. + TSdcell *Gt_dc = kalfilmsinputs_1stapp_ps->Gt_dc; //nz-by-ny-by-nst. Cross-covariance. + //+ + TSdmatrix *bt_dm = kalfilmsinputs_1stapp_ps->bt_dm; //nz-by-nst. + TSdcell *Ft_dc = kalfilmsinputs_1stapp_ps->Ft_dc; //nz-by-nz-by-nst. + TSdcell *Vt_dc = kalfilmsinputs_1stapp_ps->Vt_dc; //nz-by-nz-by-nst. Covariance matrix for the state equation. + //+ + TSdmatrix *z0_dm = kalfilmsinputs_1stapp_ps->z0_dm; //nz-by-nst. + TSdcell *P0_dc = kalfilmsinputs_1stapp_ps->P0_dc; //nz-by-nz-by-nst. + //--- Used to get zt_tm1_dc->C[0] and Pt_tm1_d4->F[0] only. + TSdcell *zt_tm1_dc = kalfilmsinputs_1stapp_ps->zt_tm1_dc; //nz-by-nst-by-(T+1). + TSdfourth *Pt_tm1_d4 = kalfilmsinputs_1stapp_ps->Pt_tm1_d4; //nz-by-nz-by-nst-by-(T+1). + //--- Local variables + int tbase0; + double logdet_Dtdata; + //--- Accessible variables + int ny = kalfilmsinputs_1stapp_ps->ny; + int nz = kalfilmsinputs_1stapp_ps->nz; + int nst = kalfilmsinputs_1stapp_ps->nst; + int T = kalfilmsinputs_1stapp_ps->T; + TSdvector z0_sdv; + TSdvector yt_sdv, at_sdv; + //=== Work arguments. + TSdvector *wny_dv = CreateVector_lf(ny); + TSdmatrix *PHtran_tdata_dm = CreateMatrix_lf(nz,ny); + TSdvector *etdata_dv = CreateVector_lf(ny); + TSdmatrix *Dtdata_dm = CreateMatrix_lf(ny,ny); + + //--- Critical checking. + if (inpt > T) fn_DisplayError(".../kalman.c/logTimetCondLH_kalfilms_1stapp(): The time exceeds the\n" + " data sample size allocated the structure TSkalfilmsinputs_1stapp_tag"); + + //--- $$$ Critical updating where we MUSt have inpt-1. If inpt, Updatekalfilms_1stapp() will call this function again + //--- $$$ because DW function ProbabilityStateConditionalCurrent() need to access this function at time inpt, + //--- $$$ which has not computed before Updatekalfilms_1stapp(). Thus, we'll have an infinite loop. + Updatekalfilms_1stapp(tbase0=inpt-1, kalfilmsinputs_1stapp_ps, smodel_ps); + + //====================================================== + //= Getting the logLH at time tbase0 or time inpt. + //====================================================== + z0_sdv.n = nz; + z0_sdv.flag = V_DEF; + at_sdv.n = yt_sdv.n = ny; + at_sdv.flag = yt_sdv.flag = V_DEF; + + //====== Computing the conditional LH at time t. ====== + //--- Setup. + MatrixTimesMatrix(PHtran_tdata_dm, Pt_tm1_d4->F[tbase0]->C[st], Ht_dc->C[st], 1.0, 0.0, 'N', 'T'); + + //--- Data. + //- etdata = Y_T(:,tdata) - a(:,tdata) - Htdata*ztdata where tdata = tbase0 = inpt-1. + yt_sdv.v = yt_dm->M + tbase0*yt_dm->nrows; + at_sdv.v = at_dm->M + st*at_dm->nrows; //comst_c: coefficient regime at time tbase0. + z0_sdv.v = zt_tm1_dc->C[tbase0]->M + z0_sdv.n*st; //st: regime at time tbase0 for zt_tm1. + VectorMinusVector(etdata_dv, &yt_sdv, &at_sdv); + MatrixTimesVector(etdata_dv, Ht_dc->C[st], &z0_sdv, -1.0, 1.0, 'N'); + //+ Dtdata = Htdata*PHtran_tdata + R(:,:,tbase0); + CopyMatrix0(Dtdata_dm, Rt_dc->C[st]); + MatrixTimesMatrix(Dtdata_dm, Ht_dc->C[st], PHtran_tdata_dm, 1.0, 1.0, 'N', 'N'); + ScalarTimesMatrixSquare(Dtdata_dm, 0.5, Dtdata_dm, 'T', 0.5); //Making it symmetric against some rounding errors. + //This making-symmetric is very IMPORTANT; otherwise, we will get the matrix being singular message + // and eigenvalues being negative for the SPD matrix, etc. Then the likelihood becomes either + // a bad number or a complex number. + Dtdata_dm->flag |= M_SU | M_SL; + + + //--- Forming the log conditional likelihood at t. + if (!isfinite(logdet_Dtdata=logdetspd(Dtdata_dm))) return (loglh_timet = -NEARINFINITY); + bdivA_rgens(wny_dv, etdata_dv, '/', Dtdata_dm); + loglh_timet = -(0.5*ny)*LOG2PI - 0.5*logdet_Dtdata - 0.5*VectorDotVector(wny_dv, etdata_dv); + //Done with all w*_dv. + + //=== + DestroyVector_lf(wny_dv); + DestroyMatrix_lf(PHtran_tdata_dm); + DestroyVector_lf(etdata_dv); + DestroyMatrix_lf(Dtdata_dm); + + + return (loglh_timet); +} +//====================================================== +//= Computing z_{1|0} and P_{1|0} for each new parameter values. +//====================================================== +int InitializeKalman_z10_P10(struct TSkalfilmsinputs_1stapp_tag *kalfilmsinputs_1stapp_ps, TSdmatrix *z10_dm, TSdcell *P10_dc) +{ + //See p.001 in LWZ Model II. + //Outputs: + // return 1: success in initializing; 0: initializing fails, so the likelihood must be set to -infty outside this function. + // tm1_track to track the time up to which Kalman filter have been updated. + // z0_dm, zt_tm1_dc->C[0] + // P0_dc, Pt_tm1_d4->F[0] + + //--- input arguments + TSdmatrix *bt_dm = kalfilmsinputs_1stapp_ps->bt_dm; //nz-by-nst. + TSdcell *Ft_dc = kalfilmsinputs_1stapp_ps->Ft_dc; //nz-by-nz-by-nst. + TSdcell *Vt_dc = kalfilmsinputs_1stapp_ps->Vt_dc; //nz-by-nz-by-nst. Covariance matrix for the state equation. + //+ + TSdmatrix *z0_dm = kalfilmsinputs_1stapp_ps->z0_dm; //nz-by-nst. + TSdcell *P0_dc = kalfilmsinputs_1stapp_ps->P0_dc; //nz-by-nz-by-nst. + //--- Used to get zt_tm1_dc->C[0] and Pt_tm1_d4->F[0] only. + TSdcell *zt_tm1_dc = kalfilmsinputs_1stapp_ps->zt_tm1_dc; //nz-by-nst-by-(T+1). + TSdfourth *Pt_tm1_d4 = kalfilmsinputs_1stapp_ps->Pt_tm1_d4; //nz-by-nz-by-nst-by-(T+1). + //--- Local variables + int sti; + //--- Accessible variables + int nz = kalfilmsinputs_1stapp_ps->nz; + int nst = kalfilmsinputs_1stapp_ps->nst; + TSdvector z0_sdv; + //--- For the initial conditions: eigenvalue decompositions + int ki; + int errflag; + double eigmax; + //=== + int nz2 = square(nz); + TSdmatrix *Wnzbynz_dm = CreateMatrix_lf(nz,nz); + TSdmatrix *Wnz2bynz2_dm = CreateMatrix_lf(nz2,nz2); + TSdmatrix *W2nz2bynz2_dm = CreateMatrix_lf(nz2,nz2); + TSdvector *wP0_dv = CreateVector_lf(nz2); + // + TSdzvector *evals_dzv = evals_dzv = CreateVector_dz(nz); + TSdvector *evals_abs_dv = CreateVector_lf(nz); //Absolute eigenvalues. + + + if (kalfilmsinputs_1stapp_ps->tm1_track < 0) + { + z0_sdv.n = nz; + z0_sdv.flag = V_DEF; + //======= Initial condition. ======= + if (!kalfilmsinputs_1stapp_ps->indxIni) + { + z0_dm->flag = M_GE; + for (sti=nst-1; sti>=0; sti--) + { + InitializeDiagonalMatrix_lf(Wnzbynz_dm, 1.0); //To be used for I(nz) - + InitializeDiagonalMatrix_lf(Wnz2bynz2_dm, 1.0); //To be used for I(nz2) - + + //=== Eigenanalysis to determine the roots to ensure boundedness. + errflag = eigrgen(evals_dzv, (TSdzmatrix *)NULL, (TSdzmatrix *)NULL, Ft_dc->C[sti]); + if (errflag) fn_DisplayError("kalman.c/InitializeKalman_z10_P10(): eigen decomposition failed"); + for (ki=nz-1; ki>=0; ki--) evals_abs_dv->v[ki] = sqrt(square(evals_dzv->real->v[ki]) + square(evals_dzv->imag->v[ki])); + evals_abs_dv->flag = V_DEF; + eigmax = MaxVector(evals_abs_dv); + if (eigmax < 1.0) //(1.0+EPSILON)) + { + //--- Getting z0_dv: zt_tm1(:,1) = (eye(n_z)-F(:,:,sti))\b(:,sti); + MatrixMinusMatrix(Wnzbynz_dm, Wnzbynz_dm, Ft_dc->C[sti]); + z0_sdv.v = z0_dm->M + z0_sdv.n*sti; + CopySubmatrix2vector(&z0_sdv, 0, bt_dm, 0, sti, bt_dm->nrows); + bdivA_rgens(&z0_sdv, &z0_sdv, '\\', Wnzbynz_dm); + //Done with Wnzbynz_dm. + //--- Getting P0_dm: Pt_tm1(:,:,1) = reshape((eye(n_z^2)-kron(F(:,:,sti),F(:,:,sti)))\V1(:),n_z,n_z); + tz_kron(W2nz2bynz2_dm, Ft_dc->C[sti], Ft_dc->C[sti]); + MatrixMinusMatrix(Wnz2bynz2_dm, Wnz2bynz2_dm, W2nz2bynz2_dm); + CopySubmatrix2vector(wP0_dv, 0, Vt_dc->C[sti], 0, 0, nz2); + bdivA_rgens(wP0_dv, wP0_dv, '\\', Wnz2bynz2_dm); + CopySubvector2matrix_unr(P0_dc->C[sti], 0, 0, wP0_dv, 0, nz2); + //Done with all w*_dv and W*_dm. + } + else + { + if (0) //0: no printing. + { + #if defined (USE_DEBUG_FILE) + fprintf(FPTR_DEBUG, "\n-------WARNING: ----------\n"); + fprintf(FPTR_DEBUG, "\nIn grand regime sti=%d\n", sti); + fprintf(FPTR_DEBUG, ".../kalman.c/InitializeKalman_z10_P10(): the system is non-stationary solutions\n" + " and see p.003 in LWZ Model II"); + #else + fprintf(stdout, "\n-----------------\n"); + fprintf(stdout, "\nIn grand regime sti=%d\n", sti); + fprintf(stdout, ".../kalman.c/InitializeKalman_z10_P10(): the system is non-stationary solutions\n" + " and see p.003 in LWZ Model II"); + #endif + } + //=== See p.000.3 in LWZ Model II. + //=== Do NOT use the following option. It turns out that this will often generate explosive conditional liklihood + //=== at the end of the sample, because Pt_tm1 shrinks to zero overtime due to the sigularity of + //=== the initila condition P_{1|0}. + //--- Letting z0_dv = 0.0 + // z0_sdv.v = z0_dm->M + z0_sdv.n*sti; + // InitializeConstantVector_lf(&z0_sdv, 0.0); + // //--- Letting P0_dm = V + // CopyMatrix0(P0_dc->C[sti], Vt_dc->C[sti]); + return (0); //Early exit with kalfilmsinputs_1stapp_ps->tm1_track continues to be -1. + } + +// //====== Getting etdata_dv and Dtdata_dm for the likelihood function. +// //--- Setup. +// MatrixTimesMatrix(PHtran_tdata_dm, Pt_tm1_d4->F[tbase0]->C[st], Ht_dc->C[st], 1.0, 0.0, 'N', 'T'); + +// //--- Data. +// //- etdata = Y_T(:,tdata) - a(:,tdata) - Htdata*ztdata where tdata = tbase0 = inpt-1. +// yt_sdv.v = yt_dm->M + tbase0*yt_dm->nrows; +// at_sdv.v = at_dm->M + st*at_dm->nrows; //comst_c: coefficient regime at time tbase0. +// z0_sdv.v = zt_tm1_dc->C[tbase0]->M + z0_sdv.n*st; //st: regime at time tbase0 for zt_tm1. +// VectorMinusVector(etdata_dv, &yt_sdv, &at_sdv); +// MatrixTimesVector(etdata_dv, Ht_dc->C[st], &z0_sdv, -1.0, 1.0, 'N'); +// //+ Dtdata = Htdata*PHtran_tdata + R(:,:,tbase0); +// CopyMatrix0(Dtdata_dm, Rt_dc->C[st]); +// MatrixTimesMatrix(Dtdata_dm, Ht_dc->C[st], PHtran_tdata_dm, 1.0, 1.0, 'N', 'N'); +// ScalarTimesMatrixSquare(Dtdata_dm, 0.5, Dtdata_dm, 'T', 0.5); //Making it symmetric against some rounding errors. +// //This making-symmetric is very IMPORTANT; otherwise, we will get the matrix being singular message +// // and eigenvalues being negative for the SPD matrix, etc. Then the likelihood becomes either +// // a bad number or a complex number. +// Dtdata_dm->flag |= M_SU | M_SL; + + } + } + else + { + if (!z10_dm) fn_DisplayError(".../kalman.c/InitializeKalman_z10_P10(): The initial condition z_{1|0}\n" + " must be supplied as valid input arguments for when indxIni == 1"); + else + CopyMatrix0(z0_dm, z10_dm); + + if (!P10_dc) fn_DisplayError(".../kalman.c/InitializeKalman_z10_P10(): The initial condition P_{1|0}\n" + " must be supplied as valid input arguments for when indxIni == 1"); + else + CopyCell0(P0_dc, P10_dc); + } + CopyMatrix0(zt_tm1_dc->C[0], z0_dm); //At time t-1 = 1. + CopyCell0(Pt_tm1_d4->F[0], P0_dc); //At time t-1 = 1. + + kalfilmsinputs_1stapp_ps->tm1_track = 0; //Must reset to 0, meaning initial setting is done and ready for computing LH at t = 1. + + return (1); + } + else fn_DisplayError(".../kalman.c/InitializeKalman_z10_P10(): calling this function makes sense only if" + " kalfilmsinputs_1stapp_ps->tm1_track is -1. Please check this value."); +} + + +//====================================================== +//= Integrating out the lagged regimes in order to +//= updating zt_tm1 and Pt_tm1 for next perid tp1 through Kim-Nelson filter. +//= tdata representing base-0 t timing, while inpt represents base-1 t timing. +// +//= Purpose: for each inpt, we integrate out grand regimes st +//= only ONCE to prevent the dimension of updated zt_tm1 and Pt_tm1 through Kim-Nelson filter. +//====================================================== +static int Updatekalfilms_1stapp(int inpt, struct TSkalfilmsinputs_1stapp_tag *kalfilmsinputs_1stapp_ps, struct TStateModel_tag *smodel_ps) +{ + //Output: + // tm1update + // z_{inpt+1|inpt} + // P_{inpt+1|inpt} + //Input: + // inpt: base-1 t timing. Thus inpt=1 is the first period. + + //--- Local variables + int stp1i, sti, tbase0, tbase0p1; + double prob_previous_regimes; + //-- Output arguments + TSdcell *zt_tm1_dc = kalfilmsinputs_1stapp_ps->zt_tm1_dc; //nz-by-nst-by-T. + TSdfourth *Pt_tm1_d4 = kalfilmsinputs_1stapp_ps->Pt_tm1_d4; //nz-by-nz-by-nst-by-T. + //--- input arguments + TSdmatrix *yt_dm = kalfilmsinputs_1stapp_ps->yt_dm; //ny-by-T. + TSdmatrix *at_dm = kalfilmsinputs_1stapp_ps->at_dm; //ny-by-nst. + TSdcell *Ht_dc = kalfilmsinputs_1stapp_ps->Ht_dc; //ny-by-nz-by-nst. + TSdcell *Rt_dc = kalfilmsinputs_1stapp_ps->Rt_dc; //ny-by-ny-by-nst. Covariance matrix for the measurement equation. + TSdcell *Gt_dc = kalfilmsinputs_1stapp_ps->Gt_dc; //nz-by-ny-by-nst. Cross-covariance. + //+ + TSdmatrix *bt_dm = kalfilmsinputs_1stapp_ps->bt_dm; //nz-by-nst. + TSdcell *Ft_dc = kalfilmsinputs_1stapp_ps->Ft_dc; //nz-by-nz-by-nst. + TSdcell *Vt_dc = kalfilmsinputs_1stapp_ps->Vt_dc; //nz-by-nz-by-nst. Covariance matrix for the state equation. + //--- Accessible variables + int ny = kalfilmsinputs_1stapp_ps->ny; + int nz = kalfilmsinputs_1stapp_ps->nz; + int nst = kalfilmsinputs_1stapp_ps->nst; + int T = kalfilmsinputs_1stapp_ps->T; + TSdvector z0_sdv; + TSdvector yt_sdv, at_sdv, btp1_sdv; //zt_tm1_sdv, ztp1_t_sdv, + //=== Work arguments. + TSdmatrix *Wnzbynz_dm = CreateMatrix_lf(nz,nz); + //+ + TSdmatrix *Wnzbyny_dm = CreateMatrix_lf(nz,ny); + TSdmatrix *W2nzbynz_dm = CreateMatrix_lf(nz,nz); + TSdmatrix *PHtran_tdata_dm = CreateMatrix_lf(nz,ny); + TSdvector *etdata_dv = CreateVector_lf(ny); + TSdmatrix *Dtdata_dm = CreateMatrix_lf(ny,ny); + TSdmatrix *Kt_tdata0_dm = CreateMatrix_lf(nz,ny); + TSdmatrix *Kt_tdata_dm = CreateMatrix_lf(nz,ny); + //=== For updating zt_tm1_dm and Pt_tm1. + TSdvector *ztp1_t_dv = CreateVector_lf(nz); + TSdmatrix *Ptp1_t_dm = CreateMatrix_lf(nz, nz); + TSdvector *ztp1_dv = CreateVector_lf(nz); + TSdmatrix *Ptp1_dm = CreateMatrix_lf(nz, nz); + + + //--- The following is for safe guard. InitializeKalman_z10_P10() should be called in, say, RefreshEverthing(). + if (kalfilmsinputs_1stapp_ps->tm1_track < 0) + if (!InitializeKalman_z10_P10(kalfilmsinputs_1stapp_ps, (TSdmatrix *)NULL, (TSdcell *)NULL)) + fn_DisplayError(".../kalman.c/Updatekalfilms_1stapp(): the system is non-stationary when calling" + " InitializeKalman_z10_P10(). Please call this function in RefreshEverthing() and" + " set the likehood to be -infty for early exit"); + + z0_sdv.n = nz; + z0_sdv.flag = V_DEF; + at_sdv.n = yt_sdv.n = ny; + at_sdv.flag = yt_sdv.flag = V_DEF; + btp1_sdv.n = nz; + btp1_sdv.flag = V_DEF; + + for (tbase0=kalfilmsinputs_1stapp_ps->tm1_track; tbase0<inpt; tbase0++) + { + //If inpt <= tm1_track, no updating. + //If inpt > tm1_track, updating z_{t|t-1} and P_{t|t-1} up to t-1 = inpt. + + zt_tm1_dc->C[tbase0p1=tbase0+1]->flag = M_GE; + for (stp1i=nst-1; stp1i>=0; stp1i--) + { + InitializeConstantVector_lf(ztp1_dv, 0.0); //To be summed over sti. + InitializeConstantMatrix_lf(Ptp1_dm, 0.0); //To be summed over sti. + + for (sti=nst-1; sti>=0; sti--) + { + //--- Setup. + MatrixTimesMatrix(PHtran_tdata_dm, Pt_tm1_d4->F[tbase0]->C[sti], Ht_dc->C[sti], 1.0, 0.0, 'N', 'T'); + + //--- Data. + //- etdata = Y_T(:,tdata) - a(:,tdata) - Htdata*ztdata where tdata = tbase0 = inpt-1. + yt_sdv.v = yt_dm->M + tbase0*yt_dm->nrows; + at_sdv.v = at_dm->M + sti*at_dm->nrows; //grand regime at time tbase0. + z0_sdv.v = zt_tm1_dc->C[tbase0]->M + z0_sdv.n*sti; //sti: regime at time tbase0. + VectorMinusVector(etdata_dv, &yt_sdv, &at_sdv); + MatrixTimesVector(etdata_dv, Ht_dc->C[sti], &z0_sdv, -1.0, 1.0, 'N'); + //+ Dtdata = Htdata*PHtran_tdata + R(:,:,tbase0); + CopyMatrix0(Dtdata_dm, Rt_dc->C[sti]); + MatrixTimesMatrix(Dtdata_dm, Ht_dc->C[sti], PHtran_tdata_dm, 1.0, 1.0, 'N', 'N'); + //Done with z0_sdv.v. + ScalarTimesMatrixSquare(Dtdata_dm, 0.5, Dtdata_dm, 'T', 0.5); //Making it symmetric against some rounding errors. + //This making-symmetric is very IMPORTANT; otherwise, we will get the matrix being singular message + // and eigenvalues being negative for the SPD matrix, etc. Then the likelihood becomes either + // a bad number or a complex number. + Dtdata_dm->flag = Dtdata_dm->flag | M_SU | M_SL; + + + //=== Updating for next period by integrating out sti.. + //--- Ktp1_t = (F_tp1*PHtran_t+G(:,:,t))/Dt; + //--- Kt_tdata = (Ft*PHtran_tdata+G(:,:,tdata))/Dtdata where t=tp1 and tdata=t. + CopyMatrix0(Kt_tdata0_dm, Gt_dc->C[sti]); + MatrixTimesMatrix(Kt_tdata0_dm, Ft_dc->C[stp1i], PHtran_tdata_dm, 1.0, 1.0, 'N', 'N'); + BdivA_rrect(Kt_tdata_dm, Kt_tdata0_dm, '/', Dtdata_dm); + //+ zt_tm1(:,t) = b(:,t) + Ft*zt_tm1(:,tdata) + Kt_tdata*etdata where t=tp1 and tm1=t. + MatrixTimesVector(ztp1_t_dv, Ft_dc->C[stp1i], &z0_sdv, 1.0, 0.0, 'N'); + MatrixTimesVector(ztp1_t_dv, Kt_tdata_dm, etdata_dv, 1.0, 1.0, 'N'); + btp1_sdv.v = bt_dm->M + stp1i*btp1_sdv.n; + VectorPlusMinusVectorUpdate(ztp1_t_dv, &btp1_sdv, 1.0); + //+ Pt_tm1(:,:,t) = Ft*Ptdata*Fttran - Kt_tdata*Dtdata*Kt_tdatatran + V(:,:,t); + CopyMatrix0(Ptp1_t_dm, Vt_dc->C[stp1i]); + MatrixTimesMatrix(Wnzbyny_dm, Kt_tdata_dm, Dtdata_dm, 1.0, 0.0, 'N', 'N'); + MatrixTimesMatrix(Wnzbynz_dm, Wnzbyny_dm, Kt_tdata_dm, 1.0, 0.0, 'N', 'T'); + MatrixPlusMinusMatrixUpdate(Ptp1_t_dm, Wnzbynz_dm, -1.0); + //Done with all W*_dm. + MatrixTimesMatrix(Wnzbynz_dm, Ft_dc->C[stp1i], Pt_tm1_d4->F[tbase0]->C[sti], 1.0, 0.0, 'N', 'N'); + MatrixTimesMatrix(W2nzbynz_dm, Wnzbynz_dm, Ft_dc->C[stp1i], 1.0, 0.0, 'N', 'T'); + MatrixPlusMatrixUpdate(Ptp1_t_dm, W2nzbynz_dm); + //Done with all W*_dm. + + + //--- Integrating out the state at tbase0 using + //--- P(s_tbase0|Y_{tbase0}, theta) = ProbabilityStateConditionalCurrent(sti, tbase0, smodel_ps); + //--- One can also access to P(s_tbase0|Y_{tbase0}, theta) by using ElementV(smodel_ps->V[tbase0],s_{tbase0}i), + //--- but this access will not call my function logTimetCondLH(), thus no updating for + //--- P(s_tbase0|Y_{tbase0}, and thus leading to incorrect results. + prob_previous_regimes = ProbabilityStateConditionalCurrent(sti, tbase0, smodel_ps); + ScalarTimesVectorUpdate(ztp1_dv, prob_previous_regimes, ztp1_t_dv); + ScalarTimesMatrix(Ptp1_dm, prob_previous_regimes, Ptp1_t_dm, 1.0); + Ptp1_dm->flag = M_GE | M_SU | M_SL; + //Done with ztp1_t_dv and Ptp1_t_dm. + } + //--- Filling zt_tm1 and Pt_tm1 for next period. + z0_sdv.v = zt_tm1_dc->C[tbase0p1]->M + z0_sdv.n*stp1i; //stp1i: regime at time tp1. + CopyVector0(&z0_sdv, ztp1_dv); + CopyMatrix0(Pt_tm1_d4->F[tbase0p1]->C[stp1i], Ptp1_dm); //stp1i: regime at time tp1. + //Done with ztp1_dv, z0_sdv, Ptp1_dm. + + //--- $$$ This following is important because it tells ProbabilityStateConditionalCurrent(), which calls + //--- $$$ logTimetCondLH_kalfilms_1stapp(), which calls recursively this function again, that there is no + //--- $$$ need to update Kalman filter for the period before kalfilmsinputs_1stapp_ps->tm1_track. + kalfilmsinputs_1stapp_ps->tm1_track = tbase0p1; //Means that z_{tbase0p1+1|tbase0p1} and P_{tbase0p1+1|tbase0p1} are done. + } + } + + + //=== + DestroyMatrix_lf(Wnzbynz_dm); + // + DestroyMatrix_lf(Wnzbyny_dm); + DestroyMatrix_lf(W2nzbynz_dm); + DestroyMatrix_lf(PHtran_tdata_dm); + DestroyVector_lf(etdata_dv); + DestroyMatrix_lf(Dtdata_dm); + DestroyMatrix_lf(Kt_tdata0_dm); + DestroyMatrix_lf(Kt_tdata_dm); + // + DestroyVector_lf(ztp1_t_dv); + DestroyMatrix_lf(Ptp1_t_dm); + DestroyVector_lf(ztp1_dv); + DestroyMatrix_lf(Ptp1_dm); + + return (kalfilmsinputs_1stapp_ps->tm1_track); +} + + + + +//----------------------------------------------------- +//------------ OLD Code -------------------------- +//- Updating or refreshing all Kalman filter at time t for Markov-switching DSGE model. +//- WARNING: make sure to call the following functions +// RunningGensys_const7varionly(lwzmodel_ps); +// Refresh_kalfilms_*(lwzmodel_ps); //Creates or refreshes kalfilmsinputs_ps at new parameter values. +//- before using tz_Refresh_z_T7P_T_in_kalfilms_1st_approx(). +// +//- IMPORTANT NOTE: in the Markov-switching input file datainp_markov*.prn, it MUST be that +//- the coefficient regime is the 1st state variable, and +//- the volatility regime is the 2nd state variable. +//----------------------------------------------------- +double tz_logTimetCondLH_kalfilms_1st_approx(int st, int inpt, struct TSkalfilmsinputs_tag *kalfilmsinputs_ps, struct TStateModel_tag *smodel_ps) +{ + //st, st_c, and st_v: base-0: deals with the cross-section values at time t where + // st is a grand regime, st_c is an encoded coefficient regime, and st_c is an encoded volatility regime. + //inpt: base-1 in the sense that inpt>=1 to deal with the time series situation where S_T is (T+1)-by-1 and Y_T is T+nlags_max-by-1. + // The 1st element for S_T is S_T[1] while S_T[0] is s_0 (initial condition). + // The 1st element for Y_T, however, is Y_T[nlags_max+1-1]. + //See (42.3) on p.42 in the SWZII NOTES. + + + //--- Local variables + int comst_c; //composite (s_tc, s_{t-1}c) + int st_c, stm1_c, st_v; + int comsti_c; //composite (s_tc, s_{t-1}c) + int sti, sti_c, stm1i_c, sti_v; + int comstp1i_c; //composite (s_{t+1}c, s_tc) + int stp1i, stp1i_c, stp1i_v; + int tbase0, tp1; + double logdet_Dtdata, loglh_timet; + static int record_tbase1_or_inpt_or_tp1 = 0; + static int passonce; + double prob_previous_regimes; + //=== Accessible variables + int ny = kalfilmsinputs_ps->ny; + int nz = kalfilmsinputs_ps->nz; + int nRc = kalfilmsinputs_ps->nRc; + int nRstc = kalfilmsinputs_ps->nRstc; + int nRv = kalfilmsinputs_ps->nRv; + int T = kalfilmsinputs_ps->T; + int indxIndRegimes = kalfilmsinputs_ps->indxIndRegimes; + int **Index = smodel_ps->sv->index; //Regime-switching states. + //smodel_ps->sv->index is for our new code. + // For old code (before 9 April 08 and before dsge_switch is created), use smodel_ps->sv->Index; + TSdvector z0_sdv; + //+ input arguments. + TSdmatrix *yt_dm = kalfilmsinputs_ps->yt_dm; //ny-by-T. + TSdmatrix *at_dm = kalfilmsinputs_ps->at_dm; //ny-by-nRc. + TSdcell *Ht_dc = kalfilmsinputs_ps->Ht_dc; //ny-by-nz-by-nRc. + TSdcell *Rt_dc = kalfilmsinputs_ps->Rt_dc; //ny-by-ny-by-nRv. Covariance matrix for the measurement equation. + TSdcell *Gt_dc = kalfilmsinputs_ps->Gt_dc; //nz-by-ny-by-nRv. Cross-covariance. + // + TSdmatrix *bt_dm = kalfilmsinputs_ps->bt_dm; //nz-by-nRc. + TSdcell *Ft_dc = kalfilmsinputs_ps->Ft_dc; //nz-by-nz-by-nRc. + TSdcell *Vt_dc = kalfilmsinputs_ps->Vt_dc; //nz-by-nz-by-nRv. Covariance matrix for the state equation. + // + TSdmatrix *z0_dm = kalfilmsinputs_ps->z0_dm; //nz-by-nRc*nRv or nz-by-nRv, depending on indxIndRegimes. + TSdcell *P0_dc = kalfilmsinputs_ps->P0_dc; //nz-by-nz-by-nRc*nRv or nz-by-nRv, depending on indxIndRegimes. + //+ Output arguments. + TSdcell *zt_tm1_dc = kalfilmsinputs_ps->zt_tm1_dc; //nz-by-nRc*nRv-by-T if indxIndRegimes==1, nz-by-nRv-by-T if indxIndRegimes==0 where nRc=nRv. + TSdfourth *Pt_tm1_d4 = kalfilmsinputs_ps->Pt_tm1_d4; //nz-by-nz-by-nRc*nRv-T if indxIndRegimes==1, nz-by-nz-by-nRv-by-T if indxIndRegimes==0 where nRc=nRv. + //=== Work arguments. + int nz2 = square(nz); + TSdmatrix *Wnzbynz_dm = CreateMatrix_lf(nz,nz); + TSdmatrix *Wnz2bynz2_dm = CreateMatrix_lf(nz2,nz2); + TSdmatrix *W2nz2bynz2_dm = CreateMatrix_lf(nz2,nz2); + TSdvector *wP0_dv = CreateVector_lf(nz2); + //+ + TSdvector yt_sdv, at_sdv, btp1_sdv; //zt_tm1_sdv, ztp1_t_sdv, + TSdvector *wny_dv = CreateVector_lf(ny); + TSdmatrix *Wnzbyny_dm = CreateMatrix_lf(nz,ny); + TSdmatrix *W2nzbynz_dm = CreateMatrix_lf(nz,nz); + TSdmatrix *PHtran_tdata_dm = CreateMatrix_lf(nz,ny); + TSdvector *etdata_dv = CreateVector_lf(ny); + TSdmatrix *Dtdata_dm = CreateMatrix_lf(ny,ny); + TSdmatrix *Kt_tdata0_dm = CreateMatrix_lf(nz,ny); + TSdmatrix *Kt_tdata_dm = CreateMatrix_lf(nz,ny); + //--- For eigenvalue decompositions + int ki; + int errflag; + double eigmax; + TSdzvector *evals_dzv = evals_dzv = CreateVector_dz(nz); + TSdvector *evals_abs_dv = CreateVector_lf(nz); //Absolute eigenvalues. + //--- For updating zt_tm1_dm and Pt_tm1. + TSdvector *ztp1_t_dv = CreateVector_lf(z0_dm->nrows); + TSdmatrix *Ptp1_t_dm = CreateMatrix_lf(nz, nz); + TSdvector *ztp1_dv = CreateVector_lf(z0_dm->nrows); + TSdmatrix *Ptp1_dm = CreateMatrix_lf(nz, nz); + + + + if (smodel_ps->sv->nstates != z0_dm->ncols) fn_DisplayError("kalman.c/tz_logTimetLH_kalfilms_1st_approx():\n" + " Make sure that the column dimension of z0_dm is the same as smodel_ps->sv->nstates"); + if (indxIndRegimes && (nRc>1) && (nRv>1)) + if (smodel_ps->sv->n_state_variables != 2) fn_DisplayError("kalman.c/tz_Refresh_z_T7P_T_in_kalfilms_1st_approx():\n" + " Number of state variables must be coincide with indxIndRegimes"); + + tbase0 = (tp1=inpt) - 1; + + z0_sdv.n = z0_dm->nrows; + z0_sdv.flag = V_DEF; + // + at_sdv.n = yt_sdv.n = yt_dm->nrows; + at_sdv.flag = yt_sdv.flag = V_DEF; + btp1_sdv.n = bt_dm->nrows; + btp1_sdv.flag = V_DEF; + + + //======= Initial condition. ======= + if (tbase0==0) + { + for (sti=smodel_ps->sv->nstates-1; sti>=0; sti--) + { + if (indxIndRegimes) + { + if (nRc==1) //Volatility. + { + comsti_c = sti_c = 0; + sti_v = sti; + } + else if ((nRv>1) && (nRc>nRstc)) //Trend inflation, both sc_t and sc_{t-1} enters coefficient regime. + { + comsti_c = Index[sti][0]; //composite (s_tc, s_{t-1}c) + sti_v = Index[sti][1]; //volatility state s_tv + sti_c = smodel_ps->sv->state_variable[0]->lag_index[comsti_c][0]; //coefficient regime at t. + stm1i_c = smodel_ps->sv->state_variable[0]->lag_index[comsti_c][1]; //coefficient regime at t-1: tm1: t-1; + } + else if ((nRv==1) && (nRc>nRstc)) + { + comsti_c = Index[sti][0]; //composite (s_tc, s_{t-1}c) + sti_c = smodel_ps->sv->state_variable[0]->lag_index[comsti_c][0]; //coefficient regime at t. + stm1i_c = smodel_ps->sv->state_variable[0]->lag_index[comsti_c][1]; //coefficient regime at t-1: tm1: t-1; + sti_v = 0; + } + else if ((nRv==1) && (nRc==nRstc)) + { + comsti_c = sti_c = sti; + sti_v = 0; + } + else if ((nRv>1) && (nRc==nRstc)) //only sc_t enters coefficient regime. + { + comsti_c = sti_c = Index[sti][0]; + sti_v = Index[sti][1]; + } + } + else //Syncronized regimes. + { + if (nRc>nRstc) + { + comsti_c = Index[sti][0]; //composite (s_tc, s_{t-1}c) + sti_c = smodel_ps->sv->state_variable[0]->lag_index[comsti_c][0]; //coefficient regime at t. + stm1i_c = smodel_ps->sv->state_variable[0]->lag_index[comsti_c][1]; //coefficient regime at t-1: tm1: t-1; + sti_v = sti_c; + } + else + comsti_c = sti_c = sti_v = sti; + } + + + if (!kalfilmsinputs_ps->indxIni) + { + InitializeDiagonalMatrix_lf(Wnzbynz_dm, 1.0); //To be used for I(nz) - + InitializeDiagonalMatrix_lf(Wnz2bynz2_dm, 1.0); //To be used for I(nz2) - + + //=== Eigenanalysis to determine the roots to ensure boundedness. + errflag = eigrgen(evals_dzv, (TSdzmatrix *)NULL, (TSdzmatrix *)NULL, Ft_dc->C[comsti_c]); + if (errflag) fn_DisplayError("kalman.c/tz_Refresh_z_T7P_T_in_kalfilms_1st_approx(): eigen decomposition failed"); + for (ki=nz-1; ki>=0; ki--) evals_abs_dv->v[ki] = sqrt(square(evals_dzv->real->v[ki]) + square(evals_dzv->imag->v[ki])); + evals_abs_dv->flag = V_DEF; + eigmax = MaxVector(evals_abs_dv); + if (eigmax < (1.0+1.0e-14)) + { + //--- Getting z0_dv: zt_tm1(:,1) = (eye(n_z)-F(:,:,1))\b(:,1); + MatrixMinusMatrix(Wnzbynz_dm, Wnzbynz_dm, Ft_dc->C[comsti_c]); + z0_sdv.v = z0_dm->M + z0_sdv.n*sti; + CopySubmatrix2vector(&z0_sdv, 0, bt_dm, 0, comsti_c, bt_dm->nrows); + bdivA_rgens(&z0_sdv, &z0_sdv, '\\', Wnzbynz_dm); + //Done with Wnzbynz_dm. + //--- Getting P0_dm: Pt_tm1(:,:,1) = reshape((eye(n_z^2)-kron(F(:,:,1),F(:,:,1)))\V1(:),n_z,n_z); + tz_kron(W2nz2bynz2_dm, Ft_dc->C[comsti_c], Ft_dc->C[comsti_c]); + MatrixMinusMatrix(Wnz2bynz2_dm, Wnz2bynz2_dm, W2nz2bynz2_dm); + CopySubmatrix2vector(wP0_dv, 0, Vt_dc->C[sti_v], 0, 0, nz2); +//=== ???????? For debugging purpose. +//if ((inpt<2) && (st==0)) +//{ +// fprintf(FPTR_DEBUG, "%%st=%d, inpt=%d, and sti=%d\n", st, inpt, sti); + +// fprintf(FPTR_DEBUG, "wP0_dv:\n"); +// WriteVector(FPTR_DEBUG, wP0_dv, " %10.5f "); +// fprintf(FPTR_DEBUG, "Vt_dc->C[sti_v=%d]:\n", sti_v); +// WriteMatrix(FPTR_DEBUG, Vt_dc->C[sti_v], " %10.5f "); + +// fflush(FPTR_DEBUG); + +//} + bdivA_rgens(wP0_dv, wP0_dv, '\\', Wnz2bynz2_dm); + CopySubvector2matrix_unr(P0_dc->C[sti], 0, 0, wP0_dv, 0, nz2); + //Done with all w*_dv and W*_dm. + } + else + { + fprintf(stdout, "\n-----------------\n"); + fprintf(stdout, "\nIn regime comsti_c=%d and sti_v=%d and at time=%d\n", comsti_c, sti_v, 0); + fn_DisplayError("kalman.c/tz_Refresh_z_T7P_T_in_kalfilms_1st_approx(): the system is non-stationary solutions\n" + " and the initial conditions must be supplied by, say, input arguments"); + fflush(stdout); + } + } + } + z0_dm->flag = M_GE; + CopyMatrix0(zt_tm1_dc->C[0], z0_dm); //At time t=0. + CopyCell0(Pt_tm1_d4->F[0], P0_dc); //At time t=0. + } + + + //====================================================== + //= Getting the logLH at time tbase0 or time inpt. + //====================================================== + if (indxIndRegimes ) + { + if (nRc==1) //Volatility. + { + comst_c = st_c = 0; + st_v = st; + } + else if ((nRv>1) && (nRc>nRstc)) //Trend inflation, both sc_t and sc_{t-1} enters coefficient regime. + { + if (smodel_ps->sv->n_state_variables != 2) fn_DisplayError("kalman.c/kalfilms_timet_1st_approx():\n" + " Number of state variables must be coincide with indxIndRegimes"); + + comst_c = Index[st][0]; //composite (s_tc, s_{t-1}c) + st_v = Index[st][1]; //volatility state s_tv + st_c = smodel_ps->sv->state_variable[0]->lag_index[comst_c][0]; //coefficient regime at t. + stm1_c = smodel_ps->sv->state_variable[0]->lag_index[comst_c][1]; //coefficient regime at t-1: tm1: t-1; + } + else if ((nRv==1) && (nRc>nRstc)) + { + comst_c = Index[st][0]; //composite (s_tc, s_{t-1}c) + st_c = smodel_ps->sv->state_variable[0]->lag_index[comst_c][0]; //coefficient regime at t. + stm1_c = smodel_ps->sv->state_variable[0]->lag_index[comst_c][1]; //coefficient regime at t-1: tm1: t-1; + st_v = 0; + } + else if ((nRv==1) && (nRc==nRstc)) + { + comst_c = st_c = st; + st_v = 0; + } + else if ((nRv>1) && (nRc==nRstc)) //only sc_t enters coefficient regime. + { + if (smodel_ps->sv->n_state_variables != 2) fn_DisplayError("kalman.c/kalfilms_timet_1st_approx():\n" + " Number of state variables must be coincide with indxIndRegimes"); + + comst_c = st_c = Index[st][0]; + st_v = Index[st][1]; + } + } + else //Syncronized regimes + { + if (nRc>nRstc) + { + comst_c = Index[st][0]; //composite (s_tc, s_{t-1}c) + st_c = smodel_ps->sv->state_variable[0]->lag_index[comst_c][0]; //coefficient regime at t. + stm1_c = smodel_ps->sv->state_variable[0]->lag_index[comst_c][1]; //coefficient regime at t-1: tm1: t-1; + st_v = st_c; + } + else + comst_c = st_c = st_v = st; + } + + + z0_sdv.n = zt_tm1_dc->C[0]->nrows; + z0_sdv.flag = V_DEF; + // + at_sdv.n = yt_sdv.n = yt_dm->nrows; + at_sdv.flag = yt_sdv.flag = V_DEF; + + //====== Computing the conditional LH at time t. ====== + //--- Setup. + MatrixTimesMatrix(PHtran_tdata_dm, Pt_tm1_d4->F[tbase0]->C[st], Ht_dc->C[comst_c], 1.0, 0.0, 'N', 'T'); + + //--- Data. + //- etdata = Y_T(:,tdata) - a(:,tdata) - Htdata*ztdata where tdata = tbase0 = inpt-1. + yt_sdv.v = yt_dm->M + tbase0*yt_dm->nrows; + at_sdv.v = at_dm->M + comst_c*at_dm->nrows; //comst_c: coefficient regime at time tbase0. + z0_sdv.v = zt_tm1_dc->C[tbase0]->M + z0_sdv.n*st; //st: regime at time tbase0 for zt_tm1. + VectorMinusVector(etdata_dv, &yt_sdv, &at_sdv); + MatrixTimesVector(etdata_dv, Ht_dc->C[comst_c], &z0_sdv, -1.0, 1.0, 'N'); + //+ Dtdata = Htdata*PHtran_tdata + R(:,:,tbase0); + CopyMatrix0(Dtdata_dm, Rt_dc->C[st_v]); + MatrixTimesMatrix(Dtdata_dm, Ht_dc->C[comst_c], PHtran_tdata_dm, 1.0, 1.0, 'N', 'N'); + ScalarTimesMatrixSquare(Dtdata_dm, 0.5, Dtdata_dm, 'T', 0.5); //Making it symmetric against some rounding errors. + //This making-symmetric is very IMPORTANT; otherwise, we will get the matrix being singular message + // and eigenvalues being negative for the SPD matrix, etc. Then the likelihood becomes either + // a bad number or a complex number. + Dtdata_dm->flag = Dtdata_dm->flag | M_SU | M_SL; + + + //--- Forming the log conditional likelihood at t. + if (!isfinite(logdet_Dtdata=logdetspd(Dtdata_dm))) return (loglh_timet = -NEARINFINITY); + bdivA_rgens(wny_dv, etdata_dv, '/', Dtdata_dm); +//if ((inpt>82) && (inpt<86) ) +//{ +// //Must be declared at the top of this "if" block. +// int kip1; +// double tmp_Dtdata; +// double tmp_expterm; + +// fprintf(FPTR_DEBUG, "%%------------------------\n"); +// fprintf(FPTR_DEBUG, "%%st=%d and inpt=%d\n", st, inpt); +// fprintf(FPTR_DEBUG, "loglh_timet = %10.5f;\n", loglh_timet); + + +// fprintf(FPTR_DEBUG, "wny_dv:\n"); +// WriteVector(FPTR_DEBUG, wny_dv, " %10.5f "); +// fprintf(FPTR_DEBUG, "etdata_dv:\n"); +// WriteVector(FPTR_DEBUG, etdata_dv, " %10.5f "); +// fprintf(FPTR_DEBUG, "Dtdata_dm:\n"); +// WriteMatrix(FPTR_DEBUG, Dtdata_dm, " %.16e "); + +// fflush(FPTR_DEBUG); +//} + loglh_timet = -(0.5*ny)*LOG2PI - 0.5*logdet_Dtdata - 0.5*VectorDotVector(wny_dv, etdata_dv); + //Done with all w*_dv. + + + + +//=== ???????? For debugging purpose. +if (inpt==1) +{ + double wk1, wk2; + + wk1 = logdet_Dtdata; + wk2 = VectorDotVector(wny_dv, etdata_dv); + fprintf(FPTR_DEBUG, "logdet_Dtdata = %10.5f\n", wk1); + fprintf(FPTR_DEBUG, "VectorDotVector(wny_dv, etdata_dv) = %10.5f\n", wk2); + fprintf(FPTR_DEBUG, "----- etdata_dv: \n"); + WriteVector(FPTR_DEBUG, etdata_dv, " %10.5f "); + fprintf(FPTR_DEBUG, "----- yt_dv: \n"); + WriteVector(FPTR_DEBUG, &yt_sdv, " %10.5f "); + fprintf(FPTR_DEBUG, "----- at_dv: \n"); + WriteVector(FPTR_DEBUG, &at_sdv, " %10.5f "); + fprintf(FPTR_DEBUG, "----- z0_dv: \n"); + WriteVector(FPTR_DEBUG, &z0_sdv, " %10.5f "); + fprintf(FPTR_DEBUG, "----- Ht_dc->C[comst_c=%d]:\n", comst_c); + WriteMatrix(FPTR_DEBUG, Ht_dc->C[comst_c], " %10.5f "); + + fprintf(FPTR_DEBUG, "\n\n"); + +} +// +fprintf(FPTR_DEBUG, " %10.5f\n", loglh_timet); +fflush(FPTR_DEBUG); + + +//=== ???????? For debugging purpose. +//fprintf(FPTR_DEBUG, "------------------------\n"); +//fprintf(FPTR_DEBUG, "st=%d and inpt=%d\n", st, inpt); +//fprintf(FPTR_DEBUG, "loglh_timet = %10.5f\n", loglh_timet); +//fprintf(FPTR_DEBUG, "&yt_sdv:\n"); +//WriteVector(FPTR_DEBUG, &yt_sdv, " %10.5f "); +////WriteVector(FPTR_DEBUG, etdata_dv, " %10.5f "); +////fprintf(FPTR_DEBUG, "\n"); +////WriteMatrix(FPTR_DEBUG, Dtdata_dm, " %10.5f "); +//fflush(FPTR_DEBUG); + + +//=== ???????? For debugging purpose. +//if ((inpt>82) && (inpt<86) ) +//if (inpt<2) +//{ +// //Must be declared at the top of this "if" block. +// int kip1; +// double tmp_Dtdata; +// double tmp_expterm; + +// fprintf(FPTR_DEBUG, "%%------------------------\n"); +// fprintf(FPTR_DEBUG, "%%st=%d and inpt=%d\n", st, inpt); +// fprintf(FPTR_DEBUG, "loglh_timet = %10.5f;\n", loglh_timet); + + +// tmp_Dtdata = logdeterminant(Dtdata_dm); +// tmp_expterm = VectorDotVector(wny_dv, etdata_dv); +// fprintf(FPTR_DEBUG, "logdeterminant(Dtdata_dm) = %10.5f;\n", tmp_Dtdata); +// fprintf(FPTR_DEBUG, "VectorDotVector(wny_dv, etdata_dv) = %10.5f;\n", tmp_expterm); +// fprintf(FPTR_DEBUG, "wny_dv:\n"); +// WriteVector(FPTR_DEBUG, wny_dv, " %10.5f "); +// fprintf(FPTR_DEBUG, "etdata_dv:\n"); +// WriteVector(FPTR_DEBUG, etdata_dv, " %10.5f "); +// fprintf(FPTR_DEBUG, "&yt_sdv:\n"); +// WriteVector(FPTR_DEBUG, &yt_sdv, " %10.5f "); +// fprintf(FPTR_DEBUG, "&at_sdv:\n"); +// WriteVector(FPTR_DEBUG, &at_sdv, " %10.5f "); +// fprintf(FPTR_DEBUG, "&z0_sdv:\n"); +// WriteVector(FPTR_DEBUG, &z0_sdv, " %10.5f "); +// fprintf(FPTR_DEBUG, "Ht_dc->C[comst_c=%d]:\n",comst_c); +// WriteMatrix(FPTR_DEBUG, Ht_dc->C[comst_c], " %10.5f "); +// fprintf(FPTR_DEBUG, "Rt_dc->C[st_v=%d]:\n", st_v); +// WriteMatrix(FPTR_DEBUG, Rt_dc->C[st_v], " %10.5f "); +// fprintf(FPTR_DEBUG, "Pt_tm1_d4->F[tbase0]->C[st = %d]:\n",st); +// WriteMatrix(FPTR_DEBUG, Pt_tm1_d4->F[tbase0]->C[st], " %10.5f "); +// fprintf(FPTR_DEBUG, "Dtdata_dm:\n"); +// WriteMatrix(FPTR_DEBUG, Dtdata_dm, " %10.5f "); + + + + +//// WriteMatrix(FPTR_DEBUG, Dtdata_dm, " %10.5f "); +//// fprintf(FPTR_DEBUG, "zt_tm1_dc->C[tbase0]:\n"); +//// WriteMatrix(FPTR_DEBUG, zt_tm1_dc->C[tbase0], " %10.5f "); +//// //WriteVector(FPTR_DEBUG, &z0_sdv, " %10.5f "); +//// //fprintf(FPTR_DEBUG, "\n"); +//// fprintf(FPTR_DEBUG, "bt_dm = [\n"); +//// WriteMatrix(FPTR_DEBUG, bt_dm, " %10.5f "); +//// fprintf(FPTR_DEBUG, "];\n"); + +//// fprintf(FPTR_DEBUG, "et:\n"); +//// WriteVector(FPTR_DEBUG, etdata_dv, " %10.5f "); +//// fprintf(FPTR_DEBUG, "yt_dv=[\n"); +//// WriteVector(FPTR_DEBUG, &yt_sdv, " %10.5f "); +//// fprintf(FPTR_DEBUG, "]';\n"); + +//// fprintf(FPTR_DEBUG, "at_dv=[\n"); +//// WriteVector(FPTR_DEBUG, &at_sdv, " %10.5f "); +//// fprintf(FPTR_DEBUG, "]';\n"); + + +//// for (ki=0; ki<Ht_dc->ncells; ki++) +//// { +//// kip1 = ki+1; +//// fprintf(FPTR_DEBUG, "Ht_dc(:,:,%d)=[\n", kip1); +//// WriteMatrix(FPTR_DEBUG, Ht_dc->C[ki], " %10.5f "); +//// fprintf(FPTR_DEBUG, "];\n"); +//// } +//// for (ki=0; ki<Ft_dc->ncells; ki++) +//// { +//// kip1 = ki+1; +//// fprintf(FPTR_DEBUG, "Ft_dc(:,:,%d)=[\n", kip1); +//// WriteMatrix(FPTR_DEBUG, Ft_dc->C[ki], " %10.5f "); +//// fprintf(FPTR_DEBUG, "];\n"); +//// } +//// for (ki=0; ki<Vt_dc->ncells; ki++) +//// { +//// kip1 = ki+1; +//// fprintf(FPTR_DEBUG, "Vt_dc(:,:,%d)=[\n", kip1); +//// WriteMatrix(FPTR_DEBUG, Vt_dc->C[ki], " %10.5f "); +//// fprintf(FPTR_DEBUG, "];\n"); +//// } +// fflush(FPTR_DEBUG); +//} + + + //====================================================== + //= Updating zt_tm1 and Pt_tm1 for next perid tp1. + //= tdata = tbase0 is base-0 timing. + //====================================================== + if (inpt > record_tbase1_or_inpt_or_tp1) //This condition always satisfies at the 1st period (which is inpt=1). + { + passonce = 0; + record_tbase1_or_inpt_or_tp1 = inpt; + } + if (!passonce) + { + for (stp1i=smodel_ps->sv->nstates-1; stp1i>=0; stp1i--) + { + if (indxIndRegimes) + { + if (nRc==1) //Volatility. + { + comstp1i_c = stp1i_c = 0; + stp1i_v = stp1i; + } + else if ((nRv>1) && (nRc>nRstc)) //Trend inflation, both sc_t and sc_{t-1} enters coefficient regime. + { + comstp1i_c = Index[stp1i][0]; //composite (s_tc, s_{t-1}c) + stp1i_v = Index[stp1i][1]; //volatility state s_tv + stp1i_c = smodel_ps->sv->state_variable[0]->lag_index[comstp1i_c][0]; //coefficient regime at t. + //sti_c = smodel_ps->sv->state_variable[0]->lag_index[comstp1i_c][1]; //coefficient regime at t-1: tm1: t-1; + } + else if ((nRv==1) && (nRc>nRstc)) + { + comstp1i_c = Index[stp1i][0]; //composite (s_tc, s_{t-1}c) + stp1i_c = smodel_ps->sv->state_variable[0]->lag_index[comstp1i_c][0]; //coefficient regime at t. + //sti_c = smodel_ps->sv->state_variable[0]->lag_index[comstp1i_c][1]; //coefficient regime at t-1: tm1: t-1; + stp1i_v = 0; + } + else if ((nRv==1) && (nRc==nRstc)) + { + comstp1i_c = stp1i_c = stp1i; + stp1i_v = 0; + } + else if ((nRv>1) && (nRc==nRstc)) //only sc_t enters coefficient regime. + { + comstp1i_c = stp1i_c = Index[stp1i][0]; + stp1i_v = Index[stp1i][1]; + } + } + else //Syncronized regimes. + { + if (nRc>nRstc) + { + comstp1i_c = Index[stp1i][0]; //composite (s_tc, s_{t-1}c) + stp1i_c = smodel_ps->sv->state_variable[0]->lag_index[comstp1i_c][0]; //coefficient regime at t. + //sti_c = smodel_ps->sv->state_variable[0]->lag_index[comstp1i_c][1]; //coefficient regime at t-1: tm1: t-1; + stp1i_v = stp1i_c; + } + else + comstp1i_c = stp1i_c = stp1i_v = stp1i; + } + + + InitializeConstantVector_lf(ztp1_dv, 0.0); //To be summed over sti. + InitializeConstantMatrix_lf(Ptp1_dm, 0.0); //To be summed over sti. + + for (sti=smodel_ps->sv->nstates-1; sti>=0; sti--) + { + if (indxIndRegimes) + { + if (nRc==1) //Volatility. + { + comsti_c = sti_c = 0; + sti_v = sti; + } + else if ((nRv>1) && (nRc>nRstc)) //Trend inflation, both sc_t and sc_{t-1} enters coefficient regime. + { + comsti_c = Index[sti][0]; //composite (s_tc, s_{t-1}c) + sti_v = Index[sti][1]; //volatility state s_tv + sti_c = smodel_ps->sv->state_variable[0]->lag_index[comsti_c][0]; //coefficient regime at t. + stm1i_c = smodel_ps->sv->state_variable[0]->lag_index[comsti_c][1]; //coefficient regime at t-1: tm1: t-1; + } + else if ((nRv==1) && (nRc>nRstc)) + { + comsti_c = Index[sti][0]; //composite (s_tc, s_{t-1}c) + sti_c = smodel_ps->sv->state_variable[0]->lag_index[comsti_c][0]; //coefficient regime at t. + stm1i_c = smodel_ps->sv->state_variable[0]->lag_index[comsti_c][1]; //coefficient regime at t-1: tm1: t-1; + sti_v = 0; + } + else if ((nRv==1) && (nRc==nRstc)) + { + comsti_c = sti_c = sti; + sti_v = 0; + } + else if ((nRv>1) && (nRc==nRstc)) //only sc_t enters coefficient regime. + { + comsti_c = sti_c = Index[sti][0]; + sti_v = Index[sti][1]; + } + } + else //Syncronized regimes. + { + if (nRc>nRstc) + { + comsti_c = Index[sti][0]; //composite (s_tc, s_{t-1}c) + sti_c = smodel_ps->sv->state_variable[0]->lag_index[comsti_c][0]; //coefficient regime at t. + stm1i_c = smodel_ps->sv->state_variable[0]->lag_index[comsti_c][1]; //coefficient regime at t-1: tm1: t-1; + sti_v = sti_c; + } + else + comsti_c = sti_c = sti_v = sti; + } + + + //--- Setup. + MatrixTimesMatrix(PHtran_tdata_dm, Pt_tm1_d4->F[tbase0]->C[sti], Ht_dc->C[comsti_c], 1.0, 0.0, 'N', 'T'); + + //--- Data. + //- etdata = Y_T(:,tdata) - a(:,tdata) - Htdata*ztdata where tdata = tbase0 = inpt-1. + yt_sdv.v = yt_dm->M + tbase0*yt_dm->nrows; + at_sdv.v = at_dm->M + comsti_c*at_dm->nrows; //comsti_c: coefficient regime at time tbase0. + z0_sdv.v = zt_tm1_dc->C[tbase0]->M + z0_sdv.n*sti; //sti: regime at time tbase0. + VectorMinusVector(etdata_dv, &yt_sdv, &at_sdv); + MatrixTimesVector(etdata_dv, Ht_dc->C[comsti_c], &z0_sdv, -1.0, 1.0, 'N'); + //+ Dtdata = Htdata*PHtran_tdata + R(:,:,tbase0); + CopyMatrix0(Dtdata_dm, Rt_dc->C[sti_v]); + MatrixTimesMatrix(Dtdata_dm, Ht_dc->C[comsti_c], PHtran_tdata_dm, 1.0, 1.0, 'N', 'N'); + //Done with z0_sdv.v. + ScalarTimesMatrixSquare(Dtdata_dm, 0.5, Dtdata_dm, 'T', 0.5); //Making it symmetric against some rounding errors. + //This making-symmetric is very IMPORTANT; otherwise, we will get the matrix being singular message + // and eigenvalues being negative for the SPD matrix, etc. Then the likelihood becomes either + // a bad number or a complex number. + Dtdata_dm->flag = Dtdata_dm->flag | M_SU | M_SL; + + + //=== Updating for next period by integrating out sti.. + if (tp1<T) + { + //Updating only up to tbase0=T-2. The values at tp1=T or tbase0=T-1 will not be used in the likelihood function. + + //--- Ktp1_t = (F_tp1*PHtran_t+G(:,:,t))/Dt; + //--- Kt_tdata = (Ft*PHtran_tdata+G(:,:,tdata))/Dtdata where t=tp1 and tdata=t. + CopyMatrix0(Kt_tdata0_dm, Gt_dc->C[sti_v]); + MatrixTimesMatrix(Kt_tdata0_dm, Ft_dc->C[stp1i_c], PHtran_tdata_dm, 1.0, 1.0, 'N', 'N'); + BdivA_rrect(Kt_tdata_dm, Kt_tdata0_dm, '/', Dtdata_dm); + //+ zt_tm1(:,t) = b(:,t) + Ft*zt_tm1(:,tdata) + Kt_tdata*etdata where t=tp1 and tm1=t. + MatrixTimesVector(ztp1_t_dv, Ft_dc->C[stp1i_c], &z0_sdv, 1.0, 0.0, 'N'); + MatrixTimesVector(ztp1_t_dv, Kt_tdata_dm, etdata_dv, 1.0, 1.0, 'N'); + btp1_sdv.v = bt_dm->M + stp1i_c*btp1_sdv.n; + VectorPlusMinusVectorUpdate(ztp1_t_dv, &btp1_sdv, 1.0); + //+ Pt_tm1(:,:,t) = Ft*Ptdata*Fttran - Kt_tdata*Dtdata*Kt_tdatatran + V(:,:,t); + CopyMatrix0(Ptp1_t_dm, Vt_dc->C[stp1i_v]); + MatrixTimesMatrix(Wnzbyny_dm, Kt_tdata_dm, Dtdata_dm, 1.0, 0.0, 'N', 'N'); + MatrixTimesMatrix(Wnzbynz_dm, Wnzbyny_dm, Kt_tdata_dm, 1.0, 0.0, 'N', 'T'); + MatrixPlusMinusMatrixUpdate(Ptp1_t_dm, Wnzbynz_dm, -1.0); + //Done with all W*_dm. + MatrixTimesMatrix(Wnzbynz_dm, Ft_dc->C[stp1i_c], Pt_tm1_d4->F[tbase0]->C[sti], 1.0, 0.0, 'N', 'N'); + MatrixTimesMatrix(W2nzbynz_dm, Wnzbynz_dm, Ft_dc->C[stp1i_c], 1.0, 0.0, 'N', 'T'); + MatrixPlusMatrixUpdate(Ptp1_t_dm, W2nzbynz_dm); + //Done with all W*_dm. + + //--- Integrating out the state at tbase0 using P(s_t|Y_{t-1}, theta) = ElementV(smodel_ps->Z[inpt],s_{inpt}_i). + //--- Note tbase0 = inpt-1 because the data in DW code (ElementV) is base-1. + //--- Note at this point, we cannot access to P(s_t|Y_t, theta) = ElementV(smodel_ps->V[inpt],s_{inpt}_i) + //--- through DW's code. But we can modify my own code to do this later. + prob_previous_regimes = ElementV(smodel_ps->Z[inpt],sti); + ScalarTimesVectorUpdate(ztp1_dv, prob_previous_regimes, ztp1_t_dv); + ScalarTimesMatrix(Ptp1_dm, prob_previous_regimes, Ptp1_t_dm, 1.0); + Ptp1_dm->flag = M_GE | M_SU | M_SL; + //Done with ztp1_t_dv and Ptp1_t_dm. + } + } + //--- Filling zt_tm1 and Pt_tm1 for next period + if (tp1<T) + { + z0_sdv.v = zt_tm1_dc->C[tp1]->M + z0_sdv.n*stp1i; //stp1i: regime at time tp1. + CopyVector0(&z0_sdv, ztp1_dv); + CopyMatrix0(Pt_tm1_d4->F[tp1]->C[stp1i], Ptp1_dm); //stp1i: regime at time tp1. + //Done with ztp1_dv, z0_sdv, Ptp1_dm. + } + } + if (tp1<T) + zt_tm1_dc->C[tp1]->flag = M_GE; + } + + +//=== ???????? For debugging purpose. +//if ((inpt>60) && (inpt<65) ) //if (inpt<5) +//{ +// int kip1; //Must be declared at the top of this "if" block. + +// fprintf(FPTR_DEBUG, "zt_tm1t=[\n"); +// WriteMatrix(FPTR_DEBUG, zt_tm1_dc->C[tbase0], " %10.5f "); +// fprintf(FPTR_DEBUG, "];\n"); + +// for (ki=0; ki<Pt_tm1_d4->F[tbase0]->ncells; ki++) +// { +// kip1 = ki+1; +// fprintf(FPTR_DEBUG, "Pt_tm1_d4t(:,:,%d)=[\n", kip1); +// WriteMatrix(FPTR_DEBUG, Pt_tm1_d4->F[tbase0]->C[ki], " %10.5f "); +// fprintf(FPTR_DEBUG, "];\n"); +// } + +// fflush(FPTR_DEBUG); +//} + + +//=== ???????? For debugging purpose. +fprintf(FPTR_DEBUG, " loglh_timet = %10.5f\n", loglh_timet); +fflush(FPTR_DEBUG); + + + //=== + DestroyVector_dz(evals_dzv); + DestroyVector_lf(evals_abs_dv); + DestroyMatrix_lf(Wnzbynz_dm); + DestroyMatrix_lf(Wnz2bynz2_dm); + DestroyMatrix_lf(W2nz2bynz2_dm); + DestroyVector_lf(wP0_dv); + // + DestroyVector_lf(wny_dv); + DestroyMatrix_lf(Wnzbyny_dm); + DestroyMatrix_lf(W2nzbynz_dm); + DestroyMatrix_lf(PHtran_tdata_dm); + DestroyVector_lf(etdata_dv); + DestroyMatrix_lf(Dtdata_dm); + DestroyMatrix_lf(Kt_tdata0_dm); + DestroyMatrix_lf(Kt_tdata_dm); + // + DestroyVector_lf(ztp1_t_dv); + DestroyMatrix_lf(Ptp1_t_dm); + DestroyVector_lf(ztp1_dv); + DestroyMatrix_lf(Ptp1_dm); + + return (loglh_timet); +} +#undef LOG2PI + + + +/** +//---------------------------------------------------------------- +//-- Tested OK, but has not use because tz_Refresh_z_T7P_T_in_kalfilms_1st_approx() +//-- cannot access to ElementV(smodel_ps->V[tp1],sti) or ElementV(smodel_ps->V[tbase0],sti) +//-- because no likelihood has been formed at all before this function is called. +//---------------------------------------------------------------- +#define LOG2PI (1.837877066409345e+000) //log(2*pi) +//----------------------------------------------------- +//- Updating or refreshing all Kalman filter at time t for Markov-switching DSGE model. +//- WARNING: make sure to call the following functions +// RunningGensys_const7varionly(lwzmodel_ps); +// Refresh_kalfilms_*(lwzmodel_ps); //Creates or refreshes kalfilmsinputs_ps at new parameter values. +//- before using tz_Refresh_z_T7P_T_in_kalfilms_1st_approx(). +//----------------------------------------------------- +void tz_Refresh_z_T7P_T_in_kalfilms_1st_approx(struct TSkalfilmsinputs_tag *kalfilmsinputs_ps, struct TStateModel_tag *smodel_ps) +{ + double debug1; + //--- Local variables + int stp1i, stp1i_c, stp1i_v, sti, sti_c, sti_v, tbase0, tp1; + //=== Accessible variables + int ny = kalfilmsinputs_ps->ny; + int nz = kalfilmsinputs_ps->nz; + int nRc = kalfilmsinputs_ps->nRc; + int nRv = kalfilmsinputs_ps->nRv; + int T = kalfilmsinputs_ps->T; + int indxIndRegimes = kalfilmsinputs_ps->indxIndRegimes; + TSdvector z0_sdv; + //+ input arguments. + TSdmatrix *yt_dm = kalfilmsinputs_ps->yt_dm; //ny-by-T. + TSdmatrix *at_dm = kalfilmsinputs_ps->at_dm; //ny-by-nRc. + TSdcell *Ht_dc = kalfilmsinputs_ps->Ht_dc; //ny-by-nz-by-nRc. + TSdcell *Rt_dc = kalfilmsinputs_ps->Rt_dc; //ny-by-ny-by-nRv. Covariance matrix for the measurement equation. + TSdcell *Gt_dc = kalfilmsinputs_ps->Gt_dc; //nz-by-ny-by-nRv. Cross-covariance. + // + TSdmatrix *bt_dm = kalfilmsinputs_ps->bt_dm; //nz-by-nRc. + TSdcell *Ft_dc = kalfilmsinputs_ps->Ft_dc; //nz-by-nz-by-nRc. + TSdcell *Vt_dc = kalfilmsinputs_ps->Vt_dc; //nz-by-nz-by-nRv. Covariance matrix for the state equation. + // + TSdmatrix *z0_dm = kalfilmsinputs_ps->z0_dm; //nz-by-nRc*nRv or nz-by-nRv, depending on indxIndRegimes. + TSdcell *P0_dc = kalfilmsinputs_ps->P0_dc; //nz-by-nz-by-nRc*nRv or nz-by-nRv, depending on indxIndRegimes. + //+ Output arguments. + TSdcell *zt_tm1_dc = kalfilmsinputs_ps->zt_tm1_dc; //nz-by-nRc*nRv-by-T if indxIndRegimes==1, nz-by-nRv-by-T if indxIndRegimes==0 where nRc=nRv. + TSdfourth *Pt_tm1_d4 = kalfilmsinputs_ps->Pt_tm1_d4; //nz-by-nz-by-nRc*nRv-T if indxIndRegimes==1, nz-by-nz-by-nRv-by-T if indxIndRegimes==0 where nRc=nRv. + //=== Work arguments. + int nz2 = square(nz); + TSdmatrix *Wnzbynz_dm = CreateMatrix_lf(nz,nz); + TSdmatrix *Wnz2bynz2_dm = CreateMatrix_lf(nz2,nz2); + TSdmatrix *W2nz2bynz2_dm = CreateMatrix_lf(nz2,nz2); + TSdvector *wP0_dv = CreateVector_lf(nz2); + //+ + TSdvector yt_sdv, at_sdv, btp1_sdv; //zt_tm1_sdv, ztp1_t_sdv, + TSdvector *wny_dv = CreateVector_lf(ny); + TSdmatrix *Wnzbyny_dm = CreateMatrix_lf(nz,ny); + TSdmatrix *W2nzbynz_dm = CreateMatrix_lf(nz,nz); + TSdmatrix *PHtran_tdata_dm = CreateMatrix_lf(nz,ny); + TSdvector *etdata_dv = CreateVector_lf(ny); + TSdmatrix *Dtdata_dm = CreateMatrix_lf(ny,ny); + TSdmatrix *Kt_tdata0_dm = CreateMatrix_lf(nz,ny); + TSdmatrix *Kt_tdata_dm = CreateMatrix_lf(nz,ny); + //--- For eigenvalue decompositions + int ki; + int errflag; + double eigmax; + TSdzvector *evals_dzv = evals_dzv = CreateVector_dz(nz); + TSdvector *evals_abs_dv = CreateVector_lf(nz); //Absolute eigenvalues. + //--- For updating zt_tm1_dm and Pt_tm1. + TSdvector *ztp1_t_dv = CreateVector_lf(z0_dm->nrows); + TSdmatrix *Ptp1_t_dm = CreateMatrix_lf(nz, nz); + TSdvector *ztp1_dv = CreateVector_lf(z0_dm->nrows); + TSdmatrix *Ptp1_dm = CreateMatrix_lf(nz, nz); + + + if (smodel_ps->sv->nstates != z0_dm->ncols) fn_DisplayError("kalman.c/tz_Refresh_z_T7P_T_in_kalfilms_1st_approx():\n" + " Make sure that the column dimension of z0_dm is the same as smodel_ps->sv->nstates"); + if (indxIndRegimes && (nRc>1) && (nRv>1)) + if (smodel_ps->sv->n_state_variables != 2) fn_DisplayError("kalman.c/tz_Refresh_z_T7P_T_in_kalfilms_1st_approx():\n" + " Number of state variables must be coincide with indxIndRegimes"); + + + z0_sdv.n = z0_dm->nrows; + z0_sdv.flag = V_DEF; + // + at_sdv.n = yt_sdv.n = yt_dm->nrows; + at_sdv.flag = yt_sdv.flag = V_DEF; + btp1_sdv.n = bt_dm->nrows; + btp1_sdv.flag = V_DEF; + + + //======= Initial condition. ======= + for (sti=smodel_ps->sv->nstates-1; sti>=0; sti--) + { + if (indxIndRegimes && (nRc==1)) + { + sti_c = 0; + sti_v = sti; + } + else if (indxIndRegimes && (nRv==1)) + { + sti_c = sti; + sti_v = 0; + } + else if (indxIndRegimes) + { + sti_c = smodel_ps->sv->Index[sti][0]; + sti_v = smodel_ps->sv->Index[sti][1]; + } + else + { + sti_c = sti_v = sti; + } + + + if (!kalfilmsinputs_ps->indxIni) + { + InitializeDiagonalMatrix_lf(Wnzbynz_dm, 1.0); //To be used for I(nz) - + InitializeDiagonalMatrix_lf(Wnz2bynz2_dm, 1.0); //To be used for I(nz2) - + + //=== Eigenanalysis to determine the roots to ensure boundedness. + errflag = eigrgen(evals_dzv, (TSdzmatrix *)NULL, (TSdzmatrix *)NULL, Ft_dc->C[sti_c]); + if (errflag) fn_DisplayError("kalman.c/tz_Refresh_z_T7P_T_in_kalfilms_1st_approx(): eigen decomposition failed"); + for (ki=nz-1; ki>=0; ki--) evals_abs_dv->v[ki] = sqrt(square(evals_dzv->real->v[ki]) + square(evals_dzv->imag->v[ki])); + evals_abs_dv->flag = V_DEF; + eigmax = MaxVector(evals_abs_dv); + if (eigmax < (1.0+1.0e-14)) + { + //--- Getting z0_dv: zt_tm1(:,1) = (eye(n_z)-F(:,:,1))\b(:,1); + MatrixMinusMatrix(Wnzbynz_dm, Wnzbynz_dm, Ft_dc->C[sti_c]); + z0_sdv.v = z0_dm->M + z0_sdv.n*sti; + CopySubmatrix2vector(&z0_sdv, 0, bt_dm, 0, sti_c, bt_dm->nrows); + bdivA_rgens(&z0_sdv, &z0_sdv, '\\', Wnzbynz_dm); + //Done with Wnzbynz_dm. + //--- Getting P0_dm: Pt_tm1(:,:,1) = reshape((eye(n_z^2)-kron(F(:,:,1),F(:,:,1)))\V1(:),n_z,n_z); + tz_kron(W2nz2bynz2_dm, Ft_dc->C[sti_c], Ft_dc->C[sti_c]); + MatrixMinusMatrix(Wnz2bynz2_dm, Wnz2bynz2_dm, W2nz2bynz2_dm); + CopySubmatrix2vector(wP0_dv, 0, Vt_dc->C[sti_v], 0, 0, nz2); + bdivA_rgens(wP0_dv, wP0_dv, '\\', Wnz2bynz2_dm); + CopySubvector2matrix_unr(P0_dc->C[sti], 0, 0, wP0_dv, 0, nz2); + //Done with all w*_dv and W*_dm. + } + else + { + fprintf(stdout, "\n-----------------\n"); + fprintf(stdout, "\nIn regime sti_c=%d and sti_v=%d and at time=%d\n", sti_c, sti_v, 0); + fn_DisplayError("kalman.c/tz_Refresh_z_T7P_T_in_kalfilms_1st_approx(): the system is non-stationary solutions\n" + " and the initial conditions must be supplied by, say, input arguments"); + fflush(stdout); + } + } + } + z0_dm->flag = M_GE; + CopyMatrix0(zt_tm1_dc->C[0], z0_dm); //At time t=0. + CopyCell0(Pt_tm1_d4->F[0], P0_dc); //At time t=0. + + +// fprintf(FPTR_DEBUG, "\n zt_tm1_dc->C[0]:\n"); +// WriteMatrix(FPTR_DEBUG, zt_tm1_dc->C[0], " %.16e "); +// fprintf(FPTR_DEBUG, "\n"); +// fprintf(FPTR_DEBUG, "\n Pt_tm1_d4->F[0]->C[0]:\n"); +// WriteMatrix(FPTR_DEBUG, Pt_tm1_d4->F[0]->C[0], " %.16e "); + + + //============== Updating zt_tm1 and Pt_tm1. ================== + for (tbase0=0; tbase0<T; tbase0++ ) + { + //tdata = tbase0 is base-0 timing. + tp1 = tbase0 + 1; //Next period. + + for (stp1i=smodel_ps->sv->nstates-1; stp1i>=0; stp1i--) + { + if (indxIndRegimes && (nRc==1)) + { + stp1i_c = 0; + stp1i_v = stp1i; + } + else if (indxIndRegimes && (nRv==1)) + { + stp1i_c = stp1i; + stp1i_v = 0; + } + else if (indxIndRegimes) + { + stp1i_c = smodel_ps->sv->Index[stp1i][0]; + stp1i_v = smodel_ps->sv->Index[stp1i][1]; + } + else + { + stp1i_c = stp1i_v = stp1i; + } + + + InitializeConstantVector_lf(ztp1_dv, 0.0); //To be summed over sti. + InitializeConstantMatrix_lf(Ptp1_dm, 0.0); //To be summed over sti. + for (sti=smodel_ps->sv->nstates-1; sti>=0; sti--) + { + if (indxIndRegimes && (nRc==1)) + { + sti_c = 0; + sti_v = sti; + } + else if (indxIndRegimes && (nRv==1)) + { + sti_c = sti; + sti_v = 0; + } + else if (indxIndRegimes) + { + sti_c = smodel_ps->sv->Index[sti][0]; + sti_v = smodel_ps->sv->Index[sti][1]; + } + else + { + sti_c = sti_v = sti; + } + + //--- Setup. + MatrixTimesMatrix(PHtran_tdata_dm, Pt_tm1_d4->F[tbase0]->C[sti], Ht_dc->C[sti_c], 1.0, 0.0, 'N', 'T'); + + //--- Data. + //- etdata = Y_T(:,tdata) - a(:,tdata) - Htdata*ztdata where tdata = tbase0 = inpt-1. + yt_sdv.v = yt_dm->M + tbase0*yt_dm->nrows; + at_sdv.v = at_dm->M + sti_c*at_dm->nrows; //sti_c: coefficient regime at time tbase0. + z0_sdv.v = zt_tm1_dc->C[tbase0]->M + z0_sdv.n*sti; //sti: regime at time tbase0. + VectorMinusVector(etdata_dv, &yt_sdv, &at_sdv); + MatrixTimesVector(etdata_dv, Ht_dc->C[sti_c], &z0_sdv, -1.0, 1.0, 'N'); + //+ Dtdata = Htdata*PHtran_tdata + R(:,:,tbase0); + CopyMatrix0(Dtdata_dm, Rt_dc->C[sti_v]); + MatrixTimesMatrix(Dtdata_dm, Ht_dc->C[sti_c], PHtran_tdata_dm, 1.0, 1.0, 'N', 'N'); + //Done with z0_sdv.v. + + + //=== Updating for next period by integrating out sti.. + if (tp1<T) + { + //Updating only up to tbase0=T-2. The values at tp1=T or tbase0=T-1 will not be used in the likelihood function. + + //--- Ktp1_t = (F_tp1*PHtran_t+G(:,:,t))/Dt; + //--- Kt_tdata = (Ft*PHtran_tdata+G(:,:,tdata))/Dtdata where t=tp1 and tdata=t. + CopyMatrix0(Kt_tdata0_dm, Gt_dc->C[sti_v]); + MatrixTimesMatrix(Kt_tdata0_dm, Ft_dc->C[stp1i_c], PHtran_tdata_dm, 1.0, 1.0, 'N', 'N'); + BdivA_rrect(Kt_tdata_dm, Kt_tdata0_dm, '/', Dtdata_dm); + //+ zt_tm1(:,t) = b(:,t) + Ft*zt_tm1(:,tdata) + Kt_tdata*etdata where t=tp1 and tm1=t. + MatrixTimesVector(ztp1_t_dv, Ft_dc->C[stp1i_c], &z0_sdv, 1.0, 0.0, 'N'); + MatrixTimesVector(ztp1_t_dv, Kt_tdata_dm, etdata_dv, 1.0, 1.0, 'N'); + btp1_sdv.v = bt_dm->M + stp1i_c*btp1_sdv.n; + VectorPlusMinusVectorUpdate(ztp1_t_dv, &btp1_sdv, 1.0); + //+ Pt_tm1(:,:,t) = Ft*Ptdata*Fttran - Kt_tdata*Dtdata*Kt_tdatatran + V(:,:,t); + CopyMatrix0(Ptp1_t_dm, Vt_dc->C[stp1i]); + MatrixTimesMatrix(Wnzbyny_dm, Kt_tdata_dm, Dtdata_dm, 1.0, 0.0, 'N', 'N'); + MatrixTimesMatrix(Wnzbynz_dm, Wnzbyny_dm, Kt_tdata_dm, 1.0, 0.0, 'N', 'T'); + MatrixPlusMinusMatrixUpdate(Ptp1_t_dm, Wnzbynz_dm, -1.0); + //Done with all W*_dm. + MatrixTimesMatrix(Wnzbynz_dm, Ft_dc->C[stp1i_c], Pt_tm1_d4->F[tbase0]->C[sti], 1.0, 0.0, 'N', 'N'); + MatrixTimesMatrix(W2nzbynz_dm, Wnzbynz_dm, Ft_dc->C[stp1i_c], 1.0, 0.0, 'N', 'T'); + MatrixPlusMatrixUpdate(Ptp1_t_dm, W2nzbynz_dm); + //Done with all W*_dm. + + //--- Integrating out the state at tbase0 using P(s_t|Y_t, theta) = ElementV(smodel_ps->V[t+1],s_{t+1}_i). + //--- Note because the data in DW code (ElementV) is base-1, t+1 is actually tbase0. + debug1 = ElementV(smodel_ps->V[tp1],sti); //?????? Debug. + //ScalarTimesVectorUpdate(ztp1_dv, ElementV(smodel_ps->V[tp1],sti), ztp1_t_dv); + //ScalarTimesMatrix(Ptp1_dm, ElementV(smodel_ps->V[tp1],sti), Ptp1_t_dm, 1.0); + ScalarTimesVectorUpdate(ztp1_dv, 0.5, ztp1_t_dv); + ScalarTimesMatrix(Ptp1_dm, 0.5, Ptp1_t_dm, 1.0); + Ptp1_dm->flag = M_GE | M_SU | M_SL; + //Done with ztp1_t_dv and Ptp1_t_dm. + } + } + //--- Filling zt_tm1 and Pt_tm1 for next period + if (tp1<T) + { + z0_sdv.v = zt_tm1_dc->C[tp1]->M + z0_sdv.n*stp1i; //stp1i: regime at time tp1. + CopyVector0(&z0_sdv, ztp1_dv); + CopyMatrix0(Pt_tm1_d4->F[tp1]->C[stp1i], Ptp1_dm); //stp1i: regime at time tp1. + //Done with ztp1_dv, z0_sdv, Ptp1_dm. + } + } + if (tp1<T) + zt_tm1_dc->C[tp1]->flag = M_GE; + +// fprintf(FPTR_DEBUG, "\n &yt_sdv:\n"); +// WriteMatrix(FPTR_DEBUG, &yt_sdv, " %.16e "); +// fprintf(FPTR_DEBUG, "\n zt_tm1_dc->C[tp1]:\n"); +// WriteMatrix(FPTR_DEBUG, zt_tm1_dc->C[tp1], " %.16e "); +// fprintf(FPTR_DEBUG, "\n"); +// fprintf(FPTR_DEBUG, "\n Pt_tm1_d4->F[tp1]->C[0]:\n"); +// WriteMatrix(FPTR_DEBUG, Pt_tm1_d4->F[tp1]->C[0], " %.16e "); +// fprintf(FPTR_DEBUG, "\n"); +// fflush(FPTR_DEBUG); + + + } + + //=== + DestroyVector_dz(evals_dzv); + DestroyVector_lf(evals_abs_dv); + DestroyMatrix_lf(Wnzbynz_dm); + DestroyMatrix_lf(Wnz2bynz2_dm); + DestroyMatrix_lf(W2nz2bynz2_dm); + DestroyVector_lf(wP0_dv); + // + DestroyVector_lf(wny_dv); + DestroyMatrix_lf(Wnzbyny_dm); + DestroyMatrix_lf(W2nzbynz_dm); + DestroyMatrix_lf(PHtran_tdata_dm); + DestroyVector_lf(etdata_dv); + DestroyMatrix_lf(Dtdata_dm); + DestroyMatrix_lf(Kt_tdata0_dm); + DestroyMatrix_lf(Kt_tdata_dm); + // + DestroyVector_lf(ztp1_t_dv); + DestroyMatrix_lf(Ptp1_t_dm); + DestroyVector_lf(ztp1_dv); + DestroyMatrix_lf(Ptp1_dm); +} +//----------------------------------------------------- +//- Kalman filter at time t for Markov-switching DSGE model. +//- WARNING: make sure to call the following functions +// (1) RunningGensys_const7varionly(lwzmodel_ps); +// (2) Refresh_kalfilms_*(lwzmodel_ps); //Creates or refreshes kalfilmsinputs_ps at new parameter values. +// (3) tz_Refresh_z_T7P_T_in_kalfilms_1st_approx(); +//- before using kalfilms_timet_1st_approx(). +//----------------------------------------------------- +double tz_kalfilms_timet_1st_approx(int st, int inpt, struct TSkalfilmsinputs_tag *kalfilmsinputs_ps, struct TStateModel_tag *smodel_ps) +{ + //st, st_c, and st_v: base-0: deals with the cross-section values at time t where + // st is a grand regime, st_c is an encoded coefficient regime, and st_c is an encoded volatility regime. + //inpt: base-1 in the sense that inpt>=1 to deal with the time series situation where S_T is (T+1)-by-1 and Y_T is T+nlags_max-by-1. + // The 1st element for S_T is S_T[1] while S_T[0] is s_0. The same for (T+1)-by-1 gbeta_dv and nlcoefs-by-(T+1) galpha_dm. + // The 1st element for Y_T, however, is Y_T[nlags_max+1-1]. + //See (42.3) on p.42 in the SWZII NOTES. + + + //--- Local variables + int st_c, st_v, tbase0; + double loglh_timet; + //--- Accessible variables + int ny = kalfilmsinputs_ps->ny; + int nz = kalfilmsinputs_ps->nz; + int nRc = kalfilmsinputs_ps->nRc; + int nRv = kalfilmsinputs_ps->nRv; + int indxIndRegimes = kalfilmsinputs_ps->indxIndRegimes; + TSdvector z0_sdv; + //+ input arguments. + TSdmatrix *yt_dm = kalfilmsinputs_ps->yt_dm; //ny-by-T. + TSdmatrix *at_dm = kalfilmsinputs_ps->at_dm; //ny-by-nRc. + TSdcell *Ht_dc = kalfilmsinputs_ps->Ht_dc; //ny-by-nz-by-nRc. + TSdcell *Rt_dc = kalfilmsinputs_ps->Rt_dc; //ny-by-ny-by-nRv. Covariance matrix for the measurement equation. + //+ Output arguments. + TSdcell *zt_tm1_dc = kalfilmsinputs_ps->zt_tm1_dc; //nz-by-nRc*nRv-by-T if indxIndRegimes==1, nz-by-nRv-by-T if indxIndRegimes==0 where nRc=nRv. + TSdfourth *Pt_tm1_d4 = kalfilmsinputs_ps->Pt_tm1_d4; //nz-by-nz-by-nRc*nRv-T if indxIndRegimes==1, nz-by-nz-by-nRv-by-T if indxIndRegimes==0 where nRc=nRv. + //=== Work arguments. + TSdvector yt_sdv, at_sdv; + TSdvector *wny_dv = CreateVector_lf(ny); + TSdmatrix *PHtran_tdata_dm = CreateMatrix_lf(nz,ny); + TSdvector *etdata_dv = CreateVector_lf(ny); + TSdmatrix *Dtdata_dm = CreateMatrix_lf(ny,ny); + + + if (smodel_ps->sv->nstates != zt_tm1_dc->C[0]->ncols) fn_DisplayError("kalman.c/kalfilms_timet_1st_approx():\n" + " Make sure that the column dimension of zt_tm1_dc->C is the same as smodel_ps->sv->nstates"); + + tbase0 = inpt - 1; //base-0 time t. + + if (indxIndRegimes && (nRc==1)) + { + st_c = 0; + st_v = st; + } + else if (indxIndRegimes && (nRv==1)) + { + st_c = st; + st_v = 0; + } + else if (indxIndRegimes) + { + if (smodel_ps->sv->n_state_variables != 2) fn_DisplayError("kalman.c/kalfilms_timet_1st_approx():\n" + " Number of state variables must be coincide with indxIndRegimes"); + st_c = smodel_ps->sv->Index[st][0]; + st_v = smodel_ps->sv->Index[st][1]; + } + else + { + st_c = st_v = st; + } + + + z0_sdv.n = zt_tm1_dc->C[0]->nrows; + z0_sdv.flag = V_DEF; + // + at_sdv.n = yt_sdv.n = yt_dm->nrows; + at_sdv.flag = yt_sdv.flag = V_DEF; + + //====== Computing the conditional LH at time t. ====== + //--- Setup. + MatrixTimesMatrix(PHtran_tdata_dm, Pt_tm1_d4->F[tbase0]->C[st], Ht_dc->C[st_c], 1.0, 0.0, 'N', 'T'); + + //--- Data. + //- etdata = Y_T(:,tdata) - a(:,tdata) - Htdata*ztdata where tdata = tbase0 = inpt-1. + yt_sdv.v = yt_dm->M + tbase0*yt_dm->nrows; + at_sdv.v = at_dm->M + st_c*at_dm->nrows; //st_c: coefficient regime at time tbase0. + z0_sdv.v = zt_tm1_dc->C[tbase0]->M + z0_sdv.n*st; //st: regime at time tbase0 for zt_tm1. + VectorMinusVector(etdata_dv, &yt_sdv, &at_sdv); + MatrixTimesVector(etdata_dv, Ht_dc->C[st_c], &z0_sdv, -1.0, 1.0, 'N'); + //+ Dtdata = Htdata*PHtran_tdata + R(:,:,tbase0); + CopyMatrix0(Dtdata_dm, Rt_dc->C[st_v]); + MatrixTimesMatrix(Dtdata_dm, Ht_dc->C[st_c], PHtran_tdata_dm, 1.0, 1.0, 'N', 'N'); + + //--- Forming the log conditional likelihood at t. + bdivA_rgens(wny_dv, etdata_dv, '/', Dtdata_dm); + loglh_timet = -(0.5*ny)*LOG2PI - 0.5*logdeterminant(Dtdata_dm) - 0.5*VectorDotVector(wny_dv, etdata_dv); + //Done with all w*_dv. + + + //=== + DestroyVector_lf(wny_dv); + DestroyMatrix_lf(PHtran_tdata_dm); + DestroyVector_lf(etdata_dv); + DestroyMatrix_lf(Dtdata_dm); + + return (loglh_timet); +} +#undef LOG2PI +/**/ + + + + diff --git a/CFiles/kalmanOldWorks.h b/CFiles/kalmanOldWorks.h new file mode 100755 index 0000000..1752338 --- /dev/null +++ b/CFiles/kalmanOldWorks.h @@ -0,0 +1,290 @@ +#ifndef __KALMAN_H__ + #define __KALMAN_H__ + + #include "tzmatlab.h" + #include "mathlib.h" + #include "switch.h" + #include "fn_filesetup.h" //Used to call WriteMatrix(FPTR_DEBUG,....). + + + typedef struct TSkalcvfurw_tag { + //urw: univariate random walk kalman filter. Desigend specially for the 2006 AER SWZ paper. + + //=== Input arguments. + int indx_tvsigmasq; //0: constant siqmasq in Kalman updating (default); + //1: Keyensian (project-specific) type of time-varying sigmasq in Kalman updating; See pp.37 and 37a in SWZ Learning NOTES; + //2: project-specific type; + //3: another project-specific type. + double sigmasq; //Variance for the residual eps(t) of the measurement equation. + int fss; //T: effective sample size (excluding lags). + int kx; //dimension for x(t). + TSdmatrix *V_dm; //kx-by-kx. Covariance (symmetric and positive definite) matrix for the residual eta(t) of the transition equation. + TSdvector *ylhtran_dv; //1-by-T of y(t). The term lh means lelf hand side and tran means transpose. + TSdmatrix *Xrhtran_dm; //kx-by-T of x(t). The term rh means right hand side and tran means transpose. + TSdvector *z10_dv; //kx-by-1. Initial condition for prediction: z_{1|0}. + TSdmatrix *P10_dm; //kx-by-kx symmetric matrix. Initial condition for the variance of the prediction: P_{1|0}. + + //=== Output arguments. + TSdvector *zupdate_dv; //kx-by-1. z_{T+1|T}. + TSdmatrix *Zpredtran_dm; //kx-by-T matrix of one-step predicted values of z(t). [z_{2|1}, ..., z_{t+1|t}, ..., z_{T+1|T}]. + //Set to NULL (no output) if storeZ = 0; + TSdcell *Ppred_dc; //T cells and kx-by-kx symmetric and positive definite matrix for each cell. Mean square errors of predicted state variables. + //{P_{2|1}, ..., P{t+1|t}, ..., P{T+1|T}. Set to NULL (no output if storeV = 0). + TSdvector *ylhtranpred_dv; //1-by-T one-step prediction of y(t) or ylhtran_dv. Added 03/17/05. + + //=== Function itself. + void (*learning_fnc)(struct TSkalcvfurw_tag *, void *); + } TSkalcvfurw; //urw: univariate random walk. + // + typedef void TFlearninguni(struct TSkalcvfurw_tag *, void *); //For linear rational expectations models. + + + //=== General Kalman filter for constant or known-time-varying DSGE models. + typedef struct TSkalfiltv_tag + { + //General (known-time-varying) Kalman filter for DSGE models. + // It computes a sequence of one-step predictions and their covariance matrices, and the log likelihood. + // The function uses a forward recursion algorithm. See also the Matlab function fn_kalfil_tv.m + // + // State space model is defined as follows: + // y(t) = a(t) + H(t)*z(t) + eps(t) (observation or measurement equation) + // z(t) = b(t) + F(t)*z(t) + eta(t) (state or transition equation) + // where a(t), H(t), b(t), and F(t) depend on s_t that follows a Markov-chain process and are taken as given. + // + // Inputs are as follows: + // Y_T is a n_y-by-T matrix containing data [y(1), ... , y(T)]. + // a is an n_y-by-T matrix of time-varying input vectors in the measurement equation. + // H is an n_y-by-n_z-by-T 3-D of time-varying matrices in the measurement equation. + // R is an n_y-by-n_y-by-T 3-D of time-varying covariance matrices for the error in the measurement equation. + // G is an n_z-by-n_y-by-T 3-D of time-varying E(eta_t * eps_t'). + // ------ + // b is an n_z-by-T matrix of time-varying input vectors in the state equation with b(:,1) as an initial condition. + // F is an n_z-by-n_z-by-T 3-D of time-varying transition matrices in the state equation with F(:,:,1) as an initial condition. + // V is an n_z-by-n_z-by-T 3-D of time-varying covariance matrices for the error in the state equation with V(:,:,1) as an initial condition. + // ------ + // indxIni: 1: using the initial condition with zt_tm1(:,1)=z0 and Pt_tm1(:,:,1)=P0; + // 0: using the unconditional mean for any given regime at time 0. + // z0 is an n_z-by-1 vector of initial condition when indxIni=1. (Not used if indxIni=0.) + // P0 is an n_z-by-n_z matrix of initial condition when indxIni=1. (Not used if indxIni=0.) + // + // Outputs are as follows: + // loglh is a value of the log likelihood function of the state-space model + // under the assumption that errors are multivariate Gaussian. + // zt_tm1 is an n_z-by-T matrices of one-step predicted state vectors with z0_0m1 as a initial condition + // and with z_{t+1|t} as the last element. Thus, we can use it as a base-1 vector. + // Pt_tm1 is an n_z-by-n_z-by-T 3-D of covariance matrices of zt_tm1 with P0_0m1 as a initial condition + // and with P_{t+1|t} as the last element. Thus, we can use it as a base-1 cell. + // + // The initial state vector and its covariance matrix are computed under the bounded (stationary) condition: + // z0_0m1 = (I-F(:,:,1))\b(:,1) + // vec(P0_0m1) = (I-kron(F(:,:,1),F(:,:,1)))\vec(V(:,:,1)) + // Note that all eigenvalues of the matrix F(:,:,1) are inside the unit circle when the state-space model is bounded (stationary). + // + // March 2007, written by Tao Zha + // See Hamilton's book ([13.2.13] -- [13.2.22]), Harvey (pp.100-106), and LiuWZ Model I NOTES pp.001-003. + + //=== Input arguments. + int ny; //number of observables. + int nz; //number of state variables. + int T; //sample size. + int indxIni; //1: using the initial condition with zt_tm1(:,1)=z0 and Pt_tm1(:,:,1)=P0; + //0: using the unconditional mean for any given regime at time 0. (Default value) + TSdmatrix *yt_dm; //ny-by-T. + TSdmatrix *at_dm; //ny-by-T. + TSdcell *Ht_dc; //ny-by-nz-by-T. + TSdcell *Rt_dc; //ny-by-ny-by-T. Covariance matrix for the measurement equation. + TSdcell *Gt_dc; //nz-by-ny-by-T. Cross-covariance. + // + TSdmatrix *bt_dm; //nz-by-T. + TSdcell *Ft_dc; //nz-by-nz-by-T. + TSdcell *Vt_dc; //nz-by-nz-by-T. Covariance matrix for the state equation. + // + TSdvector *z0_dv; //nz-by-1; + TSdmatrix *P0_dm; //nz-by-nz. + + //=== Output arguments. + double loglh; //log likelihood. + TSdmatrix *zt_tm1_dm; //nz-by-T. + TSdcell *Pt_tm1_dc; //nz-by-nz-T. + + } TSkalfiltv; + + + + //=== Inputs for filter for Markov-switching DSGE models at any time t. + typedef struct TSkalfilmsinputs_1stapp_tag + { + //Inputs Markov-switching Kalman filter for DSGE models (conditional on all the regimes at time t). + // It computes a sequence of one-step predictions and their covariance matrices, and the log likelihood. + // The function uses a forward recursion algorithm. See also the Matlab function fn_kalfil_tv.m + // + // State space model is defined as follows: + // y(t) = a(t) + H(t)*z(t) + eps(t) (observation or measurement equation) + // z(t) = b(t) + F(t)*z(t) + eta(t) (state or transition equation) + // where a(t), H(t), b(t), and F(t) depend on the grand regime s_t that follows a Markov-chain process + // and is taken as given. + // + // Inputs at time t are as follows where nst is number of grand regimes (including lagged regime + // and coefficients and shock variances): + // Y_T is a n_y-by-T matrix containing data [y(1), ... , y(T)]. + // a is an n_y-by-nst matrix of Markov-switching input vectors in the measurement equation. + // H is an n_y-by-n_z-by-nst 3-D of Markov-switching matrices in the measurement equation. + // R is an n_y-by-n_y-by-nst 3-D of Markov-switching covariance matrices for the error in the measurement equation. + // G is an n_z-by-n_y-by-nst 3-D of Markov-switching E(eta_t * eps_t'). + // ------ + // b is an n_z-by-nst matrix of Markov-switching input vectors in the state equation with b(:,st) as an initial condition. + // (alternatively, with the ergodic weighted b(:,st) as an initial condition). + // F is an n_z-by-n_z-by-nst 3-D of Markov-switching transition matrices in the state equation with F(:,:,st) + // as an initial condition (alternatively, with the ergodic weighted F(:,:,st) as an initial condition). + // V is an n_z-by-n_z-by-nRv 3-D of Markov-switching covariance matrices for the error in the state equation + // with V(:,:,st) as an initial condition (alternatively, with the ergodic weighted V(:,:,st) as an initial condition). + // ------ + // indxIni: 1: using the initial condition with zt_tm1(:,1)=z0 and Pt_tm1(:,:,1)=P0; + // 0: using the unconditional mean for any given regime at time 0. + // z0 is an n_z-by-nst matrix of initial condition (Not used if indxIni=0). + // P0 is an n_z-by-n_z-by-nst 3-D of initial condition (Not used if indxIni=0). + // + // The initial state vector and its covariance matrix are computed under the bounded (stationary) condition: + // z0_0m1 = (I-F(:,:,st))\b(:,st) + // vec(P0_0m1) = (I-kron(F(:,:,st),F(:,:,st)))\vec(V(:,:,st)) + // Note that all eigenvalues of the matrix F(:,:,st) are inside the unit circle when the state-space model is bounded (stationary). + // + // November 2007, written by Tao Zha. Revised, April 2008. + // See Hamilton's book ([13.2.13] -- [13.2.22]), Harvey (pp.100-106), and LiuWZ Model I NOTES pp.001-003. + + //=== Input arguments. + int ny; //number of observables. + int nz; //number of state variables. + int nst; //number of grand composite regimes (current and past regimes, coefficient and volatility regimes). + int T; //sample size. + int indxIni; //1: using the initial condition with zt_tm1(:,1)=z0 and Pt_tm1(:,:,1)=P0; + //0: using the unconditional mean for any given regime at time 0. (Default value) + int tm1_track; //t-1 = -1: the initial conditions z_{1|0} and P_{1|0} are yet to be computed using InitializeKalman_z10_P10(). + //t-1 >= 0: z_{t|t-1} and P_{t|t-1} are updated up to t where t-1 = 1 to T. + TSdmatrix *yt_dm; //ny-by-T. + TSdmatrix *at_dm; //ny-by-nst. + TSdcell *Ht_dc; //ny-by-nz-by-nst. + TSdcell *Rt_dc; //ny-by-ny-by-nst. Covariance matrix for the measurement equation. + TSdcell *Gt_dc; //nz-by-ny-by-nst. Cross-covariance. + // + TSdmatrix *bt_dm; //nz-by-nst. + TSdcell *Ft_dc; //nz-by-nz-by-nst. + TSdcell *Vt_dc; //nz-by-nz-by-nst. Covariance matrix for the state equation. + // + TSdmatrix *z0_dm; //nz-by-nst. + TSdcell *P0_dc; //nz-by-nz-by-nst. + + + //=== Output arguments only used for 1st order approximation to zt and Pt depending on infinite past regimes. + TSdcell *zt_tm1_dc; //nz-by-nst-by-(T+1), where z_{1|0} is an initial condition (1st element with t-1=0) and + // the terminal condition z_{T+1|T} using Updatekalfilms_1stapp(T, ...) is not computed + // when the likelihood logTimetCondLH_kalfilms_1stapp() is computed. Thus, z_{T+1|T} + // has not legal value computed in most applications unless in out-of-sample forecasting problems. + TSdfourth *Pt_tm1_d4; //nz-by-nz-by-nst-by-(T+1), where P_{1|0} is an initial condition (1st element with t-1=0) and + // the terminal condition P_{T+1|T} using Updatekalfilms_1stapp(T, ...) is not computed + // when the likelihood logTimetCondLH_kalfilms_1stapp() is computed. Thus, P_{T+1|T} + // has not legal value computed in most applications unless in out-of-sample forecasting problems. + } TSkalfilmsinputs_1stapp; + + + //=== OLD Code: Inputs for filter for Markov-switching DSGE models at any time t. + typedef struct TSkalfilmsinputs_tag + { + //Inputs Markov-switching Kalman filter for DSGE models (conditional on all the regimes at time t). + // It computes a sequence of one-step predictions and their covariance matrices, and the log likelihood. + // The function uses a forward recursion algorithm. See also the Matlab function fn_kalfil_tv.m + // + // State space model is defined as follows: + // y(t) = a(t) + H(t)*z(t) + eps(t) (observation or measurement equation) + // z(t) = b(t) + F(t)*z(t) + eta(t) (state or transition equation) + // where a(t), H(t), b(t), and F(t) depend on s_t that follows a Markov-chain process and are taken as given. + // + // Inputs at time t are as follows where nRc is number of regimes for coefficients + // nRv is number of regimes for volatility (shock variances): + // Y_T is a n_y-by-T matrix containing data [y(1), ... , y(T)]. + // a is an n_y-by-nRc matrix of Markov-switching input vectors in the measurement equation. + // H is an n_y-by-n_z-by-nRc 3-D of Markov-switching matrices in the measurement equation. + // R is an n_y-by-n_y-by-nRv 3-D of Markov-switching covariance matrices for the error in the measurement equation. + // G is an n_z-by-n_y-by-nRv 3-D of Markov-switching E(eta_t * eps_t'). + // ------ + // b is an n_z-by-nRc matrix of Markov-switching input vectors in the state equation with b(:,1) as an initial condition. + // F is an n_z-by-n_z-by-nRc 3-D of Markov-switching transition matrices in the state equation with F(:,:,1) as an initial condition. + // V is an n_z-by-n_z-by-nRv 3-D of Markov-switching covariance matrices for the error in the state equation with V(:,:,1) as an initial condition. + // ------ + // indxIndRegimes: 1: coefficient regime and volatility regime are independent; 0: these two regimes are synchronized completely. + // indxIni: 1: using the initial condition with zt_tm1(:,1)=z0 and Pt_tm1(:,:,1)=P0; + // 0: using the unconditional mean for any given regime at time 0. + // z0 is an n_z-by-nRc*nRv matrix of initial condition when indxIni=1 and indxIndRegimes=1. (Not used if indxIni=0.) + // z0 is an n_z-by-nRv matrix of initial condition when indxIni=1 and indxIndRegimes=0. (Not used if indxIni=0.) + // P0 is an n_z-by-n_z-by-nRc*nRv 3-D of initial condition when indxIni=1 and indxIndRegimes=1. (Not used if indxIni=0.) + // P0 is an n_z-by-n_z-by-nRv 3-D of initial condition when indxIni=1 and indxIndRegimes=0. (Not used if indxIni=0.) + // + // The initial state vector and its covariance matrix are computed under the bounded (stationary) condition: + // z0_0m1 = (I-F(:,:,1))\b(:,1) + // vec(P0_0m1) = (I-kron(F(:,:,1),F(:,:,1)))\vec(V(:,:,1)) + // Note that all eigenvalues of the matrix F(:,:,1) are inside the unit circle when the state-space model is bounded (stationary). + // + // November 2007, written by Tao Zha + // See Hamilton's book ([13.2.13] -- [13.2.22]), Harvey (pp.100-106), and LiuWZ Model I NOTES pp.001-003. + + //=== Input arguments. + int ny; //number of observables. + int nz; //number of state variables. + int nRc; //number of composite regimes (current and past regimes) for coefficients. + int nRstc; //number of coefficient regimes at time t. + int nRv; //number of regimes for volatility (shock variances). + int indxIndRegimes; //1: coefficient regime and volatility regime are independent; 0: these two regimes are synchronized completely. + int T; //sample size. + int indxIni; //1: using the initial condition with zt_tm1(:,1)=z0 and Pt_tm1(:,:,1)=P0; + //0: using the unconditional mean for any given regime at time 0. (Default value) + TSdmatrix *yt_dm; //ny-by-T. + TSdmatrix *at_dm; //ny-by-nRc. + TSdcell *Ht_dc; //ny-by-nz-by-nRc. + TSdcell *Rt_dc; //ny-by-ny-by-nRv. Covariance matrix for the measurement equation. + TSdcell *Gt_dc; //nz-by-ny-by-nRv. Cross-covariance. + // + TSdmatrix *bt_dm; //nz-by-nRc. + TSdcell *Ft_dc; //nz-by-nz-by-nRc. + TSdcell *Vt_dc; //nz-by-nz-by-nRv. Covariance matrix for the state equation. + // + TSdmatrix *z0_dm; //nz-by-nRc*nRv if indxIndRegimes == 1 or nz-by-nRv if indxIndRegimes == 0. + TSdcell *P0_dc; //nz-by-nz-by-nRc*nRv if indxIndRegimes == 1 or nz-by-nz-by-nRv if indxIndRegimes == 0. + + + //=== Output arguments only used for 1st order approximation to zt and Pt depending on infinite past regimes. + TSdcell *zt_tm1_dc; //nz-by-nRc*nRv-by-T if indxIndRegimes==1, nz-by-nRv-by-T if indxIndRegimes==0 where nRc=nRv. + TSdfourth *Pt_tm1_d4; //nz-by-nz-by-nRc*nRv-T if indxIndRegimes==1, nz-by-nz-by-nRv-by-T if indxIndRegimes==0 where nRc=nRv. + + } TSkalfilmsinputs; + + + + + //--- Functions for univariate random walk kalman filter. + TSkalcvfurw *CreateTSkalcvfurw(TFlearninguni *func, int T, int k, int tv); //, int storeZ, int storeV); + TSkalcvfurw *DestroyTSkalcvfurw(TSkalcvfurw *kalcvfurw_ps); + void kalcvf_urw(TSkalcvfurw *kalcvfurw_ps, void *dummy_ps); + + //--- New Code: Functions for Markov-switching Kalman filter. + struct TSkalfilmsinputs_1stapp_tag *CreateTSkalfilmsinputs_1stapp(int ny, int nz, int nst, int T); + struct TSkalfilmsinputs_1stapp_tag *DestroyTSkalfilmsinputs_1stapp(struct TSkalfilmsinputs_1stapp_tag *kalfilmsinputs_1stapp_ps); + int InitializeKalman_z10_P10(struct TSkalfilmsinputs_1stapp_tag *kalfilmsinputs_1stapp_ps, TSdmatrix *z10_dm, TSdcell *P10_dc); + double logTimetCondLH_kalfilms_1stapp(int st, int inpt, struct TSkalfilmsinputs_1stapp_tag *kalfilmsinputs_1stapp_ps, struct TStateModel_tag *smodel_ps); + + + + //--- OLD Code: Functions for general constant Kalman filter. + struct TSkalfiltv_tag *CreateTSkalfiltv(int ny, int nz, int T); + struct TSkalfiltv_tag *DestroyTSkalfiltv(struct TSkalfiltv_tag *kalfiltv_ps); + //Used to test tz_logTimetCondLH_kalfiltv(). (Done April 08). double tz_kalfiltv(struct TSkalfiltv_tag *kalfiltv_ps); + double tz_logTimetCondLH_kalfiltv(int st, int inpt, struct TSkalfiltv_tag *kalfiltv_ps); + + //--- OLD Code: Functions for Markov-switching Kalman filter. + struct TSkalfilmsinputs_tag *CreateTSkalfilmsinputs(int ny, int nz, int nRc, int nRstc, int nRv, int indxIndRegimes, int T); + struct TSkalfilmsinputs_tag *DestroyTSkalfilmsinputs(struct TSkalfilmsinputs_tag *kalfilmsinputs_ps); + double tz_logTimetCondLH_kalfilms_1st_approx(int st, int inpt, struct TSkalfilmsinputs_tag *kalfilmsinputs_ps, struct TStateModel_tag *smodel_ps); + //IMPORTANT NOTE: in the Markov-switching input file datainp_markov*.prn, it MUST be that + // the coefficient regime is the 1st state variable, and + // the volatility regime is the 2nd state variable. +#endif + diff --git a/CFiles/kalmanOldWorks2.c b/CFiles/kalmanOldWorks2.c new file mode 100755 index 0000000..3a66f3e --- /dev/null +++ b/CFiles/kalmanOldWorks2.c @@ -0,0 +1,2907 @@ +/*=============================================================================================================== + * Check $$$ for important notes. + * Check <<>> for updating DW's new switch code or questions for DW. + * + * kalcvf_urw(): the Kalman filter forward prediction specialized for only a univariate random walk (urw) process. + * + * State space model is defined as follows: + * z(t+1) = z(t)+eta(t) (state or transition equation) + * y(t) = x(t)'*z(t)+eps(t) (observation or measurement equation) + * where for this function, eta and eps must be uncorrelated; y(t) must be 1-by-1. Note that + * x(t): k-by-1; + * z(t): k-by-1; + * eps(t): 1-by-1 and ~ N(0, sigma^2); + * eta(t): ~ N(0, V) where V is a k-by-k covariance matrix. + * + * + * Written by Tao Zha, May 2004. + * Revised, May 2008; +=================================================================================================================*/ + +/** +//=== For debugging purpose. +if (1) +{ + double t_loglht; + + t_loglht = -(0.5*ny)*LOG2PI - 0.5*logdeterminant(Dtdata_dm) - 0.5*VectorDotVector(wny_dv, etdata_dv); + fprintf(FPTR_DEBUG, " %10.5f\n", t_loglht); + + fprintf(FPTR_DEBUG, "%%st=%d, inpt=%d, and sti=%d\n", st, inpt, sti); + + fprintf(FPTR_DEBUG, "\n wP0_dv:\n"); + WriteVector(FPTR_DEBUG, wP0_dv, " %10.5f "); + fprintf(FPTR_DEBUG, "\n Vt_dc->C[sti_v=%d]:\n", sti_v); + WriteMatrix(FPTR_DEBUG, Vt_dc->C[sti_v], " %10.5f "); + + fflush(FPTR_DEBUG); +} +/**/ + + +#include "kalman.h" + + +static int Update_et_Dt_1stapp(int t_1, struct TSkalfilmsinputs_1stapp_tag *kalfilmsinputs_1stapp_ps); +static int Updatekalfilms_1stapp(int inpt, struct TSkalfilmsinputs_1stapp_tag *kalfilmsinputs_1stapp_ps, struct TStateModel_tag *smodel_ps); + + +TSkalcvfurw *CreateTSkalcvfurw(TFlearninguni *func, int T, int k, int tv) //, int storeZ, int storeV) +{ + int _i; + //=== + TSivector *rows_iv = NULL; + TSivector *cols_iv = NULL; + //--- + TSkalcvfurw *kalcvfurw_ps = tzMalloc(1, TSkalcvfurw); + + + kalcvfurw_ps->indx_tvsigmasq = tv; + kalcvfurw_ps->fss = T; + kalcvfurw_ps->kx = k; + + //=== + kalcvfurw_ps->V_dm = CreateMatrix_lf(k, k); + kalcvfurw_ps->ylhtran_dv = CreateVector_lf(T); + kalcvfurw_ps->Xrhtran_dm = CreateMatrix_lf(k, T); + kalcvfurw_ps->z10_dv = CreateVector_lf(k); + kalcvfurw_ps->P10_dm = CreateMatrix_lf(k, k); + + kalcvfurw_ps->zupdate_dv = CreateVector_lf(k); + kalcvfurw_ps->Zpredtran_dm = CreateMatrix_lf(k, T); + kalcvfurw_ps->ylhtranpred_dv = CreateVector_lf(T); + // + rows_iv = CreateVector_int(T); + cols_iv = CreateVector_int(T); + for (_i=T-1; _i>=0; _i--) rows_iv->v[_i] = cols_iv->v[_i] = k; + kalcvfurw_ps->Ppred_dc = CreateCell_lf(rows_iv, cols_iv); + // if (!storeZ) kalcvfurw_ps->Zpredtran_dm = (TSdmatrix *)NULL; + // else kalcvfurw_ps->Zpredtran_dm = CreateMatrix_lf(k, T); + // if (!storeV) kalcvfurw_ps->Ppred_dc = (TSdcell *)NULL; + // else { + // rows_iv = CreateVector_int(T); + // cols_iv = CreateVector_int(T); + // for (_i=T; _i>=0; _i--) rows_iv->v[_i] = cols_iv->v[_i] = k; + // kalcvfurw_ps->Ppred_dc = CreateCell_lf(rows_iv, cols_iv); + // } + + DestroyVector_int(rows_iv); + DestroyVector_int(cols_iv); + return (kalcvfurw_ps); +} + +TSkalcvfurw *DestroyTSkalcvfurw(TSkalcvfurw *kalcvfurw_ps) +{ + if (kalcvfurw_ps) { + DestroyMatrix_lf(kalcvfurw_ps->V_dm); + DestroyVector_lf(kalcvfurw_ps->ylhtran_dv); + DestroyMatrix_lf(kalcvfurw_ps->Xrhtran_dm); + DestroyVector_lf(kalcvfurw_ps->z10_dv); + DestroyMatrix_lf(kalcvfurw_ps->P10_dm); + + DestroyVector_lf(kalcvfurw_ps->zupdate_dv); + DestroyMatrix_lf(kalcvfurw_ps->Zpredtran_dm); + DestroyCell_lf(kalcvfurw_ps->Ppred_dc); + DestroyVector_lf(kalcvfurw_ps->ylhtranpred_dv); + + free(kalcvfurw_ps); + return ((TSkalcvfurw *)NULL); + } + else return (kalcvfurw_ps); +} + + +void kalcvf_urw(TSkalcvfurw *kalcvfurw_ps, void *dummy_ps) +{ + //See the notes of SWZ regarding the government's updating of the parameters in their Phillips-curve equation. + //NOTE: make sure that the value of kalcvfurw_ps->sigmasq and other input values are given. + int ti; + double workd, workdenominv; + //--- + int fss, kx; + double sigmasq_fix = kalcvfurw_ps->sigmasq; +// double sigmasq; + TSdmatrix *V_dm; + TSdmatrix *Zpredtran_dm; + TSdcell *Ppred_dc; + TSdvector *ylhtran_dv; + TSdmatrix *Xrhtran_dm; + //=== + TSdvector *workkxby1_dv = NULL; //kx-by-1. +// TSdvector *work1kxby1_dv = NULL; //kx-by-1. + TSdmatrix *workkxbykx_dm = NULL; //kx-by-kx symmetric and positive positive. +// //=== +// TSdvector *zbefore_dv = CreateVector_lf(kalcvfurw_ps->kx); +// TSdmatrix *Vbefore_dm = CreateMatrix_lf(kalcvfurw_ps->kx, kalcvfurw_ps->kx); +// TSdvector *zafter_dv = CreateVector_lf(kalcvfurw_ps->kx); +// TSdmatrix *Vafter_dm = CreateMatrix_lf(kalcvfurw_ps->kx, kalcvfurw_ps->kx); + //******* WARNING: Some dangerous pointer movement to gain efficiency ******* +// double *yt_p; +// double *Vbefore_p; +// double *Vafter_p; + TSdvector xt_sdv; + TSdvector zbefore_sdv; + //TSdmatrix Vbefore_sdm; + TSdvector zafter_sdv; + //TSdmatrix Vafter_sdm; + + + if (!kalcvfurw_ps) fn_DisplayError(".../kalcvf_urw(): the input argument kalcvfurw_ps must be created"); + if (!kalcvfurw_ps->V_dm || !kalcvfurw_ps->ylhtran_dv || !kalcvfurw_ps->Xrhtran_dm || !kalcvfurw_ps->z10_dv || !kalcvfurw_ps->P10_dm) + fn_DisplayError(".../kalcvf_urw(): input arguments kalcvfurw_ps->V_dm, kalcvfurw_ps->ylhtran_dv, kalcvfurw_ps->Xrhtran_dm, kalcvfurw_ps->z10_dv, kalcvfurw_ps->P10_dm must be given legal values"); + if (!(kalcvfurw_ps->P10_dm->flag & (M_SU | M_SL))) fn_DisplayError(".../kalcvf_urw(): the input argument kalcvfurw_ps->P10_dm must be symmetric"); + fss = kalcvfurw_ps->fss; + kx = kalcvfurw_ps->kx; + V_dm = kalcvfurw_ps->V_dm; + Zpredtran_dm = kalcvfurw_ps->Zpredtran_dm; + Ppred_dc = kalcvfurw_ps->Ppred_dc; + ylhtran_dv = kalcvfurw_ps->ylhtran_dv; + Xrhtran_dm = kalcvfurw_ps->Xrhtran_dm; + //--- + xt_sdv.n = kx; + xt_sdv.flag = V_DEF; + zbefore_sdv.n = kx; + zbefore_sdv.flag = V_DEF; + zafter_sdv.n = kx; + zafter_sdv.flag = V_DEF; + + //=== Memory allocation. + workkxby1_dv = CreateVector_lf(kx); + workkxbykx_dm = CreateMatrix_lf(kx, kx); + + + //------- The first period (ti=0). ------- + zbefore_sdv.v = kalcvfurw_ps->z10_dv->v; + zafter_sdv.v = Zpredtran_dm->M; + xt_sdv.v = Xrhtran_dm->M; + //--- + + workd = ylhtran_dv->v[0] - (kalcvfurw_ps->ylhtranpred_dv->v[0]=VectorDotVector(&xt_sdv, &zbefore_sdv)); //y_t - x_t'*z_{t-1}. + SymmatrixTimesVector(workkxby1_dv, kalcvfurw_ps->P10_dm, &xt_sdv, 1.0, 0.0); //P_{t|t-1} x_t; + + if (!kalcvfurw_ps->indx_tvsigmasq) + workdenominv = 1.0/(sigmasq_fix + VectorDotVector(&xt_sdv, workkxby1_dv)); //1/[sigma^2 + x_t' P_{t|t-1} x_t] + else if (kalcvfurw_ps->indx_tvsigmasq == 1) //See pp.37 and 37a in SWZ Learning NOTES. + workdenominv = 1.0/(sigmasq_fix*square(kalcvfurw_ps->z10_dv->v[0]) + VectorDotVector(&xt_sdv, workkxby1_dv)); //1/[sigma^2 + x_t' P_{t|t-1} x_t]; + else { + printf(".../kalman.c/kalcvf_urw(): Have not got time to deal with kalcvfurw_ps->indx_tvsigmasq defined in kalman.h other than 0 or 1"); + exit(EXIT_FAILURE); + } + + + //--- Updating z_{t+1|t}. + CopyVector0(&zafter_sdv, &zbefore_sdv); + VectorPlusMinusVectorUpdate(&zafter_sdv, workkxby1_dv, workd*workdenominv); //z_{t+1|t} = z_{t|t-1} + P_{t|t-1} x_t [y_t - x_t'*z_{t-1}] / [sigma^2 + x_t' P_{t|t-1} x_t]; + //--- Updating P_{t+1|t}. + CopyMatrix0(workkxbykx_dm, V_dm); + VectorTimesSelf(workkxbykx_dm, workkxby1_dv, -workdenominv, 1.0, (V_dm->flag & M_SU) ? 'U' : 'L'); + // - P_{t|t-1}*x_t * xt'*P_{t|t-1} / [sigma^2 + x_t' P_{t|t-1} x_t] + V; + MatrixPlusMatrix(Ppred_dc->C[0], kalcvfurw_ps->P10_dm, workkxbykx_dm); + //P_{t|t-1} - P_{t|t-1}*x_t * xt'*P_{t|t-1} / [sigma^2 + x_t' P_{t|t-1} x_t] + V; + Ppred_dc->C[0]->flag = M_GE | M_SU | M_SL; //This is necessary because if P10_dm is initialized as diagonal, it will have M_GE | M_SU | M_SL | M_UT | M_LT, + // which is no longer true for workkxbykx_dm and therefore gives Ppred_dc->C[0] with M_GE only as a result of MatrixPlusMatrix(). + //Done with all work* arrays. + + //------- The rest of the periods (ti=1:T-1). ------- + for (ti=1; ti<fss; ti++) { + //NOTE: ti=0 has been taken care of outside of this loop. + zbefore_sdv.v = Zpredtran_dm->M + (ti-1)*kx; + zafter_sdv.v = Zpredtran_dm->M + ti*kx; + xt_sdv.v = Xrhtran_dm->M + ti*kx; + //--- + workd = ylhtran_dv->v[ti] - (kalcvfurw_ps->ylhtranpred_dv->v[ti]=VectorDotVector(&xt_sdv, &zbefore_sdv)); //y_t - x_t'*z_{t-1}. + SymmatrixTimesVector(workkxby1_dv, Ppred_dc->C[ti-1], &xt_sdv, 1.0, 0.0); //P_{t|t-1} x_t; + if (!kalcvfurw_ps->indx_tvsigmasq) + workdenominv = 1.0/(sigmasq_fix + VectorDotVector(&xt_sdv, workkxby1_dv)); //1/[sigma^2 + x_t' P_{t|t-1} x_t] + else if (kalcvfurw_ps->indx_tvsigmasq == 1) //See pp.37 and 37a in SWZ Learning NOTES. + workdenominv = 1.0/(sigmasq_fix*square(zbefore_sdv.v[0]) + VectorDotVector(&xt_sdv, workkxby1_dv)); //1/[sigma^2 + x_t' P_{t|t-1} x_t] + else { + printf(".../kalman.c/kalcvf_urw(): Have not got time to deal with kalcvfurw_ps->indx_tvsigmasq defined in kalman.h other than 0 or 1"); + exit(EXIT_FAILURE); + } + //--- Updating z_{t+1|t}. + CopyVector0(&zafter_sdv, &zbefore_sdv); + VectorPlusMinusVectorUpdate(&zafter_sdv, workkxby1_dv, workd*workdenominv); //z_{t+1|t} = z_{t|t-1} + P_{t|t-1} x_t [y_t - x_t'*z_{t-1}] / [sigma^2 + x_t' P_{t|t-1} x_t]; + //--- Updating P_{t+1|t}. + CopyMatrix0(workkxbykx_dm, V_dm); + VectorTimesSelf(workkxbykx_dm, workkxby1_dv, -workdenominv, 1.0, (V_dm->flag & M_SU) ? 'U' : 'L'); + // - P_{t|t-1}*x_t * xt'*P_{t|t-1} / [sigma^2 + x_t' P_{t|t-1} x_t] + V; + MatrixPlusMatrix(Ppred_dc->C[ti], Ppred_dc->C[ti-1], workkxbykx_dm); + //P_{t|t-1} - P_{t|t-1}*x_t * xt'*P_{t|t-1} / [sigma^2 + x_t' P_{t|t-1} x_t] + V; + Ppred_dc->C[ti]->flag = M_GE | M_SU | M_SL; //This is necessary because if P10_dm is initialized as diagonal, it will have M_GE | M_SU | M_SL | M_UT | M_LT, + // which is no longer true for workkxbykx_dm and therefore gives Ppred_dc->C[0] with M_GE only as a result of MatrixPlusMatrix(). + //Done with all work* arrays. + } + CopyVector0(kalcvfurw_ps->zupdate_dv, &zafter_sdv); + Zpredtran_dm->flag = M_GE; + kalcvfurw_ps->ylhtranpred_dv->flag = V_DEF; + +// DestroyVector_lf(zbefore_dv); +// DestroyMatrix_lf(Vbefore_dm); +// DestroyVector_lf(zafter_dv); +// DestroyMatrix_lf(Vafter_dm); + + DestroyVector_lf(workkxby1_dv); +// DestroyVector_lf(work1kxby1_dv); + DestroyMatrix_lf(workkxbykx_dm); +} + + + +//----------------------------------------------------------------------------------------------------------------------- +//-- General constant (known-time-varying) Kalman filter for DSGE models. +//----------------------------------------------------------------------------------------------------------------------- +struct TSkalfiltv_tag *CreateTSkalfiltv(int ny, int nz, int T) +{ + int _i; + //=== + TSivector *rows_iv = CreateVector_int(T); + TSivector *cols_iv = CreateVector_int(T); + //~~~ Creating the structure and initializing the NULL pointers. + struct TSkalfiltv_tag *kalfiltv_ps = tzMalloc(1, struct TSkalfiltv_tag); + + + //--- Default value. + kalfiltv_ps->indxIni = 0; //1: using the initial condition with zt_tm1(:,1)=z0 and Pt_tm1(:,:,1)=P0; + //0: using the unconditional mean for any given regime at time 0. + //--- Other assignments. + kalfiltv_ps->ny = ny; + kalfiltv_ps->nz = nz; + kalfiltv_ps->T = T; + + + + //--------- Creates memory and assigns values. The order matters. + kalfiltv_ps->yt_dm = CreateMatrix_lf(ny, T); + kalfiltv_ps->at_dm = CreateMatrix_lf(ny, T); + // + for (_i=T-1; _i>=0; _i--) + { + rows_iv->v[_i] = ny; + cols_iv->v[_i] = nz; + } + rows_iv->flag = cols_iv->flag = V_DEF; + kalfiltv_ps->Ht_dc = CreateCell_lf(rows_iv, cols_iv); + // + for (_i=T-1; _i>=0; _i--) + { + rows_iv->v[_i] = ny; + cols_iv->v[_i] = ny; + } + kalfiltv_ps->Rt_dc = CreateCell_lf(rows_iv, cols_iv); + // + for (_i=T-1; _i>=0; _i--) + { + rows_iv->v[_i] = nz; + cols_iv->v[_i] = ny; + } + kalfiltv_ps->Gt_dc = CreateCell_lf(rows_iv, cols_iv); + // + kalfiltv_ps->bt_dm = CreateMatrix_lf(nz, T); + // + for (_i=T-1; _i>=0; _i--) + { + rows_iv->v[_i] = nz; + cols_iv->v[_i] = nz; + } + kalfiltv_ps->Ft_dc = CreateCell_lf(rows_iv, cols_iv); + kalfiltv_ps->Vt_dc = CreateCell_lf(rows_iv, cols_iv); + // + kalfiltv_ps->z0_dv = CreateVector_lf(nz); + kalfiltv_ps->P0_dm = CreateMatrix_lf(nz, nz); + + + //--- + kalfiltv_ps->zt_tm1_dm = CreateMatrix_lf(nz, T); + for (_i=T-1; _i>=0; _i--) + { + rows_iv->v[_i] = nz; + cols_iv->v[_i] = nz; + } + kalfiltv_ps->Pt_tm1_dc = CreateCell_lf(rows_iv, cols_iv); + + + //=== + DestroyVector_int(rows_iv); + DestroyVector_int(cols_iv); + + return (kalfiltv_ps); + +} +//--- +struct TSkalfiltv_tag *DestroyTSkalfiltv(struct TSkalfiltv_tag *kalfiltv_ps) +{ + if (kalfiltv_ps) + { + //=== The order matters! + DestroyMatrix_lf(kalfiltv_ps->yt_dm); + DestroyMatrix_lf(kalfiltv_ps->at_dm); + DestroyCell_lf(kalfiltv_ps->Ht_dc); + DestroyCell_lf(kalfiltv_ps->Rt_dc); + DestroyCell_lf(kalfiltv_ps->Gt_dc); + //--- + DestroyMatrix_lf(kalfiltv_ps->bt_dm); + DestroyCell_lf(kalfiltv_ps->Ft_dc); + DestroyCell_lf(kalfiltv_ps->Vt_dc); + //--- + DestroyVector_lf(kalfiltv_ps->z0_dv); + DestroyMatrix_lf(kalfiltv_ps->P0_dm); + //--- + DestroyMatrix_lf(kalfiltv_ps->zt_tm1_dm); + DestroyCell_lf(kalfiltv_ps->Pt_tm1_dc); + + + //--- + tzDestroy(kalfiltv_ps); //Must be freed last! + + return ((struct TSkalfiltv_tag *)NULL); + } + else return (kalfiltv_ps); +}; + + +//----------------------------------------------------------------------------------------------------------------------- +//-- New code: Inputs for filter for Markov-switching DSGE models at any time t. +//----------------------------------------------------------------------------------------------------------------------- +struct TSkalfilmsinputs_1stapp_tag *CreateTSkalfilmsinputs_1stapp2(int ny, int nz, int nu, int ne, int nst, int T) +{ + //~~~ Creating the structure and initializing the NULL pointers. + struct TSkalfilmsinputs_1stapp_tag *kalfilmsinputs_1stapp_ps = tzMalloc(1, struct TSkalfilmsinputs_1stapp_tag); + + //=== + TSivector *rows_iv = NULL; + TSivector *cols_iv = NULL; + + //=== Default value. + kalfilmsinputs_1stapp_ps->indxIni = 0; //1: using the initial condition with zt_tm1(:,1)=z0 and Pt_tm1(:,:,1)=P0; + //0: using the unconditional mean for any given regime at time 0. + kalfilmsinputs_1stapp_ps->indxDiffuse = 1; //1: using the diffuse condition for z_{1|0} and P_{1|0} (default option), according to Koopman and Durbin, "Filtering and Smoothing of State Vector for Diffuse State-Space Models," J. of Time Series Analysis, Vol 24(1), pp.85-99. + //0: using the unconditional moments. + kalfilmsinputs_1stapp_ps->DiffuseScale = 100.0; + kalfilmsinputs_1stapp_ps->ztm1_track = -1; + kalfilmsinputs_1stapp_ps->dtm1_track = -1; + + //--- Other key assignments. + kalfilmsinputs_1stapp_ps->ny = ny; + kalfilmsinputs_1stapp_ps->nz = nz; + kalfilmsinputs_1stapp_ps->nu = nu; + kalfilmsinputs_1stapp_ps->ne = ne; + kalfilmsinputs_1stapp_ps->nst = nst; + kalfilmsinputs_1stapp_ps->T = T; + + //--------- Creates memory and assigns values. The order matters. + kalfilmsinputs_1stapp_ps->yt_dm = CreateMatrix_lf(ny, T); + kalfilmsinputs_1stapp_ps->at_dm = CreateMatrix_lf(ny, nst); + // + rows_iv = CreateConstantVector_int(nst, ny); + cols_iv = CreateConstantVector_int(nst, nz); + kalfilmsinputs_1stapp_ps->Ht_dc = CreateCell_lf(rows_iv, cols_iv); + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + // + if (nu) + { + rows_iv = CreateConstantVector_int(nst, ny); + cols_iv = CreateConstantVector_int(nst, nu); + kalfilmsinputs_1stapp_ps->Psiut_dc = CreateCell_lf(rows_iv, cols_iv); + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + } + else + kalfilmsinputs_1stapp_ps->Psiut_dc = NULL; + // + rows_iv = CreateConstantVector_int(nst, ny); + cols_iv = CreateConstantVector_int(nst, ny); + kalfilmsinputs_1stapp_ps->Rt_dc = CreateCell_lf(rows_iv, cols_iv); + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + // + rows_iv = CreateConstantVector_int(nst, nz); + cols_iv = CreateConstantVector_int(nst, ny); + kalfilmsinputs_1stapp_ps->Gt_dc = CreateCell_lf(rows_iv, cols_iv); + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + // + kalfilmsinputs_1stapp_ps->bt_dm = CreateMatrix_lf(nz, nst); + // + rows_iv = CreateConstantVector_int(nst, nz); + cols_iv = CreateConstantVector_int(nst, nz); + kalfilmsinputs_1stapp_ps->Ft_dc = CreateCell_lf(rows_iv, cols_iv); + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + // + rows_iv = CreateConstantVector_int(nst, nz); + cols_iv = CreateConstantVector_int(nst, ne); + kalfilmsinputs_1stapp_ps->Psiet_dc = CreateCell_lf(rows_iv, cols_iv); + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + // + rows_iv = CreateConstantVector_int(nst, nz); + cols_iv = CreateConstantVector_int(nst, nz); + kalfilmsinputs_1stapp_ps->Vt_dc = CreateCell_lf(rows_iv, cols_iv); + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + // + kalfilmsinputs_1stapp_ps->z0_dm = CreateMatrix_lf(nz, nst); //nz-by-nst. + kalfilmsinputs_1stapp_ps->z0_0_dm = CreateMatrix_lf(nz, nst); //nz-by-nst. + // + rows_iv = CreateConstantVector_int(nst, nz); + cols_iv = CreateConstantVector_int(nst, nz); + kalfilmsinputs_1stapp_ps->P0_dc = CreateCell_lf(rows_iv, cols_iv); //nz-by-nz-by-nst. + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + + //--- For output arguments. + rows_iv = CreateConstantVector_int(T+1, nz); + cols_iv = CreateConstantVector_int(T+1, nst); + kalfilmsinputs_1stapp_ps->zt_tm1_dc = CreateCell_lf(rows_iv, cols_iv); //nz-by-nst-by-(T+1). + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + // + rows_iv = CreateConstantVector_int(nst, nz); + cols_iv = CreateConstantVector_int(nst, nz); + kalfilmsinputs_1stapp_ps->Pt_tm1_d4 = CreateFourth_lf(T+1, rows_iv, cols_iv); //nz-by-nz-by-nst-by-(T+1). + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + // + rows_iv = CreateConstantVector_int(nst, nz); + cols_iv = CreateConstantVector_int(nst, ny); + kalfilmsinputs_1stapp_ps->PHtran_tdata_d4 = CreateFourth_lf(T, rows_iv, cols_iv); //nz-by-ny-by-nst-T, saved only for updating Kalman filter Updatekalfilms_1stapp(). + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + // + rows_iv = CreateConstantVector_int(T, ny); + cols_iv = CreateConstantVector_int(T, nst); + kalfilmsinputs_1stapp_ps->etdata_dc = CreateCell_lf(rows_iv, cols_iv); //ny-by-nst-by-T, used for updating Kalman filter Updatekalfilms_1stapp(). + rows_iv = CreateConstantVector_int(T, ny); + cols_iv = CreateConstantVector_int(T, nst); + // + rows_iv = CreateConstantVector_int(nst, ny); + cols_iv = CreateConstantVector_int(nst, ny); + kalfilmsinputs_1stapp_ps->Dtdata_d4 = CreateFourth_lf(T, rows_iv, cols_iv); //ny-by-ny-nst-by-T, used for updating Kalman filter Updatekalfilms_1stapp(). + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + + return (kalfilmsinputs_1stapp_ps); +} +//--- +struct TSkalfilmsinputs_1stapp_tag *DestroyTSkalfilmsinputs_1stapp2(struct TSkalfilmsinputs_1stapp_tag *kalfilmsinputs_1stapp_ps) +{ + if (kalfilmsinputs_1stapp_ps) + { + //=== The order matters! + DestroyMatrix_lf(kalfilmsinputs_1stapp_ps->yt_dm); + DestroyMatrix_lf(kalfilmsinputs_1stapp_ps->at_dm); + DestroyCell_lf(kalfilmsinputs_1stapp_ps->Ht_dc); + DestroyCell_lf(kalfilmsinputs_1stapp_ps->Psiut_dc); + DestroyCell_lf(kalfilmsinputs_1stapp_ps->Rt_dc); + DestroyCell_lf(kalfilmsinputs_1stapp_ps->Gt_dc); + //--- + DestroyMatrix_lf(kalfilmsinputs_1stapp_ps->bt_dm); + DestroyCell_lf(kalfilmsinputs_1stapp_ps->Ft_dc); + DestroyCell_lf(kalfilmsinputs_1stapp_ps->Psiet_dc); + DestroyCell_lf(kalfilmsinputs_1stapp_ps->Vt_dc); + //--- + DestroyMatrix_lf(kalfilmsinputs_1stapp_ps->z0_dm); + DestroyMatrix_lf(kalfilmsinputs_1stapp_ps->z0_0_dm); + DestroyCell_lf(kalfilmsinputs_1stapp_ps->P0_dc); + //--- + DestroyCell_lf(kalfilmsinputs_1stapp_ps->zt_tm1_dc); + DestroyFourth_lf(kalfilmsinputs_1stapp_ps->Pt_tm1_d4); + DestroyFourth_lf(kalfilmsinputs_1stapp_ps->PHtran_tdata_d4); + DestroyCell_lf(kalfilmsinputs_1stapp_ps->etdata_dc); + DestroyFourth_lf(kalfilmsinputs_1stapp_ps->Dtdata_d4); + //--- + tzDestroy(kalfilmsinputs_1stapp_ps); //Must be freed last! + + return ((struct TSkalfilmsinputs_1stapp_tag *)NULL); + } + else return (kalfilmsinputs_1stapp_ps); +}; + +struct TSkalfilmsinputs_1stapp_tag *CreateTSkalfilmsinputs_1stapp(int ny, int nz, int nst, int T) +{ + //~~~ Creating the structure and initializing the NULL pointers. + struct TSkalfilmsinputs_1stapp_tag *kalfilmsinputs_1stapp_ps = tzMalloc(1, struct TSkalfilmsinputs_1stapp_tag); + + //=== + TSivector *rows_iv = NULL; + TSivector *cols_iv = NULL; + + //=== Default value. + kalfilmsinputs_1stapp_ps->indxIni = 0; //1: using the initial condition with zt_tm1(:,1)=z0 and Pt_tm1(:,:,1)=P0; + //0: using the unconditional mean for any given regime at time 0. + kalfilmsinputs_1stapp_ps->indxDiffuse = 1; //1: using the diffuse condition for z_{1|0} and P_{1|0} (default option), according to Koopman and Durbin, "Filtering and Smoothing of State Vector for Diffuse State-Space Models," J. of Time Series Analysis, Vol 24(1), pp.85-99. + //0: using the unconditional moments. + kalfilmsinputs_1stapp_ps->DiffuseScale = 100.0; + kalfilmsinputs_1stapp_ps->ztm1_track = -1; + kalfilmsinputs_1stapp_ps->dtm1_track = -1; + + //--- Other key assignments. + kalfilmsinputs_1stapp_ps->ny = ny; + kalfilmsinputs_1stapp_ps->nz = nz; + kalfilmsinputs_1stapp_ps->nst = nst; + kalfilmsinputs_1stapp_ps->T = T; + + //--------- Creates memory and assigns values. The order matters. + kalfilmsinputs_1stapp_ps->yt_dm = CreateMatrix_lf(ny, T); + kalfilmsinputs_1stapp_ps->at_dm = CreateMatrix_lf(ny, nst); + // + rows_iv = CreateConstantVector_int(nst, ny); + cols_iv = CreateConstantVector_int(nst, nz); + kalfilmsinputs_1stapp_ps->Ht_dc = CreateCell_lf(rows_iv, cols_iv); + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + // + rows_iv = CreateConstantVector_int(nst, ny); + cols_iv = CreateConstantVector_int(nst, ny); + kalfilmsinputs_1stapp_ps->Rt_dc = CreateCell_lf(rows_iv, cols_iv); + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + // + rows_iv = CreateConstantVector_int(nst, nz); + cols_iv = CreateConstantVector_int(nst, ny); + kalfilmsinputs_1stapp_ps->Gt_dc = CreateCell_lf(rows_iv, cols_iv); + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + // + kalfilmsinputs_1stapp_ps->bt_dm = CreateMatrix_lf(nz, nst); + // + rows_iv = CreateConstantVector_int(nst, nz); + cols_iv = CreateConstantVector_int(nst, nz); + kalfilmsinputs_1stapp_ps->Ft_dc = CreateCell_lf(rows_iv, cols_iv); + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + // + rows_iv = CreateConstantVector_int(nst, nz); + cols_iv = CreateConstantVector_int(nst, nz); + kalfilmsinputs_1stapp_ps->Vt_dc = CreateCell_lf(rows_iv, cols_iv); + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + // + kalfilmsinputs_1stapp_ps->z0_dm = CreateMatrix_lf(nz, nst); //nz-by-nst. + kalfilmsinputs_1stapp_ps->z0_0_dm = CreateMatrix_lf(nz, nst); //nz-by-nst. + // + rows_iv = CreateConstantVector_int(nst, nz); + cols_iv = CreateConstantVector_int(nst, nz); + kalfilmsinputs_1stapp_ps->P0_dc = CreateCell_lf(rows_iv, cols_iv); //nz-by-nz-by-nst. + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + + //--- For output arguments. + rows_iv = CreateConstantVector_int(T+1, nz); + cols_iv = CreateConstantVector_int(T+1, nst); + kalfilmsinputs_1stapp_ps->zt_tm1_dc = CreateCell_lf(rows_iv, cols_iv); //nz-by-nst-by-(T+1). + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + // + rows_iv = CreateConstantVector_int(nst, nz); + cols_iv = CreateConstantVector_int(nst, nz); + kalfilmsinputs_1stapp_ps->Pt_tm1_d4 = CreateFourth_lf(T+1, rows_iv, cols_iv); //nz-by-nz-by-nst-by-(T+1). + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + // + rows_iv = CreateConstantVector_int(nst, nz); + cols_iv = CreateConstantVector_int(nst, ny); + kalfilmsinputs_1stapp_ps->PHtran_tdata_d4 = CreateFourth_lf(T, rows_iv, cols_iv); //nz-by-ny-by-nst-T, saved only for updating Kalman filter Updatekalfilms_1stapp(). + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + // + rows_iv = CreateConstantVector_int(T, ny); + cols_iv = CreateConstantVector_int(T, nst); + kalfilmsinputs_1stapp_ps->etdata_dc = CreateCell_lf(rows_iv, cols_iv); //ny-by-nst-by-T, used for updating Kalman filter Updatekalfilms_1stapp(). + rows_iv = CreateConstantVector_int(T, ny); + cols_iv = CreateConstantVector_int(T, nst); + // + rows_iv = CreateConstantVector_int(nst, ny); + cols_iv = CreateConstantVector_int(nst, ny); + kalfilmsinputs_1stapp_ps->Dtdata_d4 = CreateFourth_lf(T, rows_iv, cols_iv); //ny-by-ny-nst-by-T, used for updating Kalman filter Updatekalfilms_1stapp(). + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + + return (kalfilmsinputs_1stapp_ps); +} +//--- +struct TSkalfilmsinputs_1stapp_tag *DestroyTSkalfilmsinputs_1stapp(struct TSkalfilmsinputs_1stapp_tag *kalfilmsinputs_1stapp_ps) +{ + if (kalfilmsinputs_1stapp_ps) + { + //=== The order matters! + DestroyMatrix_lf(kalfilmsinputs_1stapp_ps->yt_dm); + DestroyMatrix_lf(kalfilmsinputs_1stapp_ps->at_dm); + DestroyCell_lf(kalfilmsinputs_1stapp_ps->Ht_dc); + DestroyCell_lf(kalfilmsinputs_1stapp_ps->Rt_dc); + DestroyCell_lf(kalfilmsinputs_1stapp_ps->Gt_dc); + //--- + DestroyMatrix_lf(kalfilmsinputs_1stapp_ps->bt_dm); + DestroyCell_lf(kalfilmsinputs_1stapp_ps->Ft_dc); + DestroyCell_lf(kalfilmsinputs_1stapp_ps->Vt_dc); + //--- + DestroyMatrix_lf(kalfilmsinputs_1stapp_ps->z0_dm); + DestroyMatrix_lf(kalfilmsinputs_1stapp_ps->z0_0_dm); + DestroyCell_lf(kalfilmsinputs_1stapp_ps->P0_dc); + //--- + DestroyCell_lf(kalfilmsinputs_1stapp_ps->zt_tm1_dc); + DestroyFourth_lf(kalfilmsinputs_1stapp_ps->Pt_tm1_d4); + DestroyFourth_lf(kalfilmsinputs_1stapp_ps->PHtran_tdata_d4); + DestroyCell_lf(kalfilmsinputs_1stapp_ps->etdata_dc); + DestroyFourth_lf(kalfilmsinputs_1stapp_ps->Dtdata_d4); + //--- + tzDestroy(kalfilmsinputs_1stapp_ps); //Must be freed last! + + return ((struct TSkalfilmsinputs_1stapp_tag *)NULL); + } + else return (kalfilmsinputs_1stapp_ps); +}; + + +//----------------------------------------------------------------------------------------------------------------------- +//-- OLD Code: Inputs for filter for Markov-switching DSGE models at any time t. +//----------------------------------------------------------------------------------------------------------------------- +struct TSkalfilmsinputs_tag *CreateTSkalfilmsinputs(int ny, int nz, int nRc, int nRstc, int nRv, int indxIndRegimes, int T) +{ + //~~~ Creating the structure and initializing the NULL pointers. + struct TSkalfilmsinputs_tag *kalfilmsinputs_ps = tzMalloc(1, struct TSkalfilmsinputs_tag); + + //=== + TSivector *rows_iv = NULL; + TSivector *cols_iv = NULL; + + //--- Default value. + kalfilmsinputs_ps->indxIni = 0; //1: using the initial condition with zt_tm1(:,1)=z0 and Pt_tm1(:,:,1)=P0; + //0: using the unconditional mean for any given regime at time 0. + //--- Other assignments. + kalfilmsinputs_ps->ny = ny; + kalfilmsinputs_ps->nz = nz; + kalfilmsinputs_ps->nRc = nRc; + kalfilmsinputs_ps->nRstc = nRstc; + kalfilmsinputs_ps->nRv = nRv; + kalfilmsinputs_ps->indxIndRegimes = indxIndRegimes; + kalfilmsinputs_ps->T = T; + + + //--------- Creates memory and assigns values. The order matters. + kalfilmsinputs_ps->yt_dm = CreateMatrix_lf(ny, T); + kalfilmsinputs_ps->at_dm = CreateMatrix_lf(ny, nRc); + // + rows_iv = CreateConstantVector_int(nRc, ny); + cols_iv = CreateConstantVector_int(nRc, nz); + kalfilmsinputs_ps->Ht_dc = CreateCell_lf(rows_iv, cols_iv); + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + // + rows_iv = CreateConstantVector_int(nRv, ny); + cols_iv = CreateConstantVector_int(nRv, ny); + kalfilmsinputs_ps->Rt_dc = CreateCell_lf(rows_iv, cols_iv); + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + // + rows_iv = CreateConstantVector_int(nRv, nz); + cols_iv = CreateConstantVector_int(nRv, ny); + kalfilmsinputs_ps->Gt_dc = CreateCell_lf(rows_iv, cols_iv); + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + // + kalfilmsinputs_ps->bt_dm = CreateMatrix_lf(nz, nRc); + // + rows_iv = CreateConstantVector_int(nRc, nz); + cols_iv = CreateConstantVector_int(nRc, nz); + kalfilmsinputs_ps->Ft_dc = CreateCell_lf(rows_iv, cols_iv); + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + // + rows_iv = CreateConstantVector_int(nRv, nz); + cols_iv = CreateConstantVector_int(nRv, nz); + kalfilmsinputs_ps->Vt_dc = CreateCell_lf(rows_iv, cols_iv); + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + // + if (indxIndRegimes) + { + kalfilmsinputs_ps->z0_dm = CreateMatrix_lf(nz, nRc*nRv); //nz-by-nRc*nRv if indxIndRegimes == 1 or nz-by-nRv if indxIndRegimes == 0. + // + rows_iv = CreateConstantVector_int(nRc*nRv, nz); + cols_iv = CreateConstantVector_int(nRc*nRv, nz); + kalfilmsinputs_ps->P0_dc = CreateCell_lf(rows_iv, cols_iv); //nz-by-nz-by-nRc*nRv if indxIndRegimes == 1 or nz-by-nz-by-nRv if indxIndRegimes == 0. + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + } + else + { + if (nRstc != nRv) fn_DisplayError("kalman.c/CreateTSkalfilmsinputs(): nRstc must equal to nRv when indxIndRegimes==0"); + kalfilmsinputs_ps->z0_dm = CreateMatrix_lf(nz, nRv); //nz-by-nRc*nRv if indxIndRegimes == 1 or nz-by-nRv if indxIndRegimes == 0. + // + rows_iv = CreateConstantVector_int(nRv, nz); + cols_iv = CreateConstantVector_int(nRv, nz); + kalfilmsinputs_ps->P0_dc = CreateCell_lf(rows_iv, cols_iv); //nz-by-nz-by-nRc*nRv if indxIndRegimes == 1 or nz-by-nz-by-nRv if indxIndRegimes == 0. + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + } + //--- For output arguments. + if (indxIndRegimes) + { + rows_iv = CreateConstantVector_int(T, nz); + cols_iv = CreateConstantVector_int(T, nRc*nRv); + kalfilmsinputs_ps->zt_tm1_dc = CreateCell_lf(rows_iv, cols_iv); //nz-by-nRc*nRv-by-T if indxIndRegimes==1, nz-by-nRv-by-T if indxIndRegimes==0 where nRc=nRv. + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + // + rows_iv = CreateConstantVector_int(nRc*nRv, nz); + cols_iv = CreateConstantVector_int(nRc*nRv, nz); + kalfilmsinputs_ps->Pt_tm1_d4 = CreateFourth_lf(T, rows_iv, cols_iv); //nz-by-nz-by-nRc*nRv-T if indxIndRegimes==1, nz-by-nz-by-nRv-by-T if indxIndRegimes==0 where nRc=nRv. + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + } + else + { + if (nRstc != nRv) fn_DisplayError("kalman.c/CreateTSkalfilmsinputs(): nRstc must equal to nRv when indxIndRegimes==0"); + rows_iv = CreateConstantVector_int(T, nz); + cols_iv = CreateConstantVector_int(T, nRv); + kalfilmsinputs_ps->zt_tm1_dc = CreateCell_lf(rows_iv, cols_iv); //nz-by-nRc*nRv-by-T if indxIndRegimes==1, nz-by-nRv-by-T if indxIndRegimes==0 where nRc=nRv. + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + // + rows_iv = CreateConstantVector_int(nRv, nz); + cols_iv = CreateConstantVector_int(nRv, nz); + kalfilmsinputs_ps->Pt_tm1_d4 = CreateFourth_lf(T, rows_iv, cols_iv); //nz-by-nz-by-nRc*nRv-T if indxIndRegimes==1, nz-by-nz-by-nRv-by-T if indxIndRegimes==0 where nRc=nRv. + rows_iv = DestroyVector_int(rows_iv); + cols_iv = DestroyVector_int(cols_iv); + } + + + //=== + DestroyVector_int(rows_iv); + DestroyVector_int(cols_iv); + + return (kalfilmsinputs_ps); + +} +//--- +struct TSkalfilmsinputs_tag *DestroyTSkalfilmsinputs(struct TSkalfilmsinputs_tag *kalfilmsinputs_ps) +{ + if (kalfilmsinputs_ps) + { + //=== The order matters! + DestroyMatrix_lf(kalfilmsinputs_ps->yt_dm); + DestroyMatrix_lf(kalfilmsinputs_ps->at_dm); + DestroyCell_lf(kalfilmsinputs_ps->Ht_dc); + DestroyCell_lf(kalfilmsinputs_ps->Rt_dc); + DestroyCell_lf(kalfilmsinputs_ps->Gt_dc); + //--- + DestroyMatrix_lf(kalfilmsinputs_ps->bt_dm); + DestroyCell_lf(kalfilmsinputs_ps->Ft_dc); + DestroyCell_lf(kalfilmsinputs_ps->Vt_dc); + //--- + DestroyMatrix_lf(kalfilmsinputs_ps->z0_dm); + DestroyCell_lf(kalfilmsinputs_ps->P0_dc); + //--- + DestroyCell_lf(kalfilmsinputs_ps->zt_tm1_dc); + DestroyFourth_lf(kalfilmsinputs_ps->Pt_tm1_d4); + //--- + tzDestroy(kalfilmsinputs_ps); //Must be freed last! + + return ((struct TSkalfilmsinputs_tag *)NULL); + } + else return (kalfilmsinputs_ps); +}; + + +#define LOG2PI (1.837877066409345e+000) //log(2*pi) +//----------------------------------------------------- +//-- Constant-parameters (known-time-varying) Kalman filter +//----------------------------------------------------- +double tz_kalfiltv(struct TSkalfiltv_tag *kalfiltv_ps) +{ + //General constant (known-time-varying) Kalman filter for DSGE models (conditional on all the parameters). + // It computes a sequence of one-step predictions and their covariance matrices, and the log likelihood. + // The function uses a forward recursion algorithm. See also the Matlab function fn_kalfil_tv.m + // + // State space model is defined as follows: + // y(t) = a(t) + H(t)*z(t) + eps(t) (observation or measurement equation) + // z(t) = b(t) + F(t)*z(t) + eta(t) (state or transition equation) + // where a(t), H(t), b(t), and F(t) depend on s_t that follows a Markov-chain process and are taken as given. + // + // Inputs are as follows: + // Y_T is a n_y-by-T matrix containing data [y(1), ... , y(T)]. + // a is an n_y-by-T matrix of time-varying input vectors in the measurement equation. + // H is an n_y-by-n_z-by-T 3-D of time-varying matrices in the measurement equation. + // R is an n_y-by-n_y-by-T 3-D of time-varying covariance matrices for the error in the measurement equation. + // G is an n_z-by-n_y-by-T 3-D of time-varying E(eta_t * eps_t'). + // ------ + // b is an n_z-by-T matrix of time-varying input vectors in the state equation with b(:,1) as an initial condition. + // F is an n_z-by-n_z-by-T 3-D of time-varying transition matrices in the state equation with F(:,:,1) as an initial condition. + // V is an n_z-by-n_z-by-T 3-D of time-varying covariance matrices for the error in the state equation with V(:,:,1) as an initial condition. + // ------ + // indxIni: 1: using the initial condition with zt_tm1(:,1)=z0 and Pt_tm1(:,:,1)=P0; + // 0: using the unconditional mean for any given regime at time 0. + // z0 is an n_z-by-1 vector of initial condition when indxIni=1. (Do not enter if indxIni=0.) + // P0 is an n_z-by-n_z matrix of initial condition when indxIni=1. (Do not enter if indxIni=0.) + // + // Outputs are as follows: + // loglh is a value of the log likelihood function of the state-space model + // under the assumption that errors are multivariate Gaussian. + // zt_tm1 is an n_z-by-T matrices of one-step predicted state vectors with z0_0m1 as an initial condition (base-0 first element) + // and with z_{T|T-1} as the last element. Thus, we can use it as a base-1 vector. + // Pt_tm1 is an n_z-by-n_z-by-T 3-D of covariance matrices of zt_tm1 with P0_0m1 as though it were a initial condition + // and with P_{T|T-1} as the last element. Thus, we can use it as though it were a base-1 cell. + // + // The initial state vector and its covariance matrix are computed under the bounded (stationary) condition: + // z0_0m1 = (I-F(:,:,1))\b(:,1) + // vec(P0_0m1) = (I-kron(F(:,:,1),F(:,:,1)))\vec(V(:,:,1)) + // Note that all eigenvalues of the matrix F(:,:,1) are inside the unit circle when the state-space model is bounded (stationary). + // + // March 2007, written by Tao Zha + // See Hamilton's book ([13.2.13] -- [13.2.22]), Harvey (pp.100-106), and LiuWZ Model I NOTES pp.001-003. + + int T = kalfiltv_ps->T; + int Tp1 = T + 1; + int ny = kalfiltv_ps->ny; + int nz = kalfiltv_ps->nz; + int indx_badlh = 0; //1: bad likelihood with, say, -infinity of the LH value. + int tdata, ti; + //--- Work arguments. + int nz2 = square(nz); + TSdmatrix *Wnzbynz_dm = CreateMatrix_lf(nz,nz); + TSdmatrix *Wnz2bynz2_dm = CreateMatrix_lf(nz2,nz2); + TSdmatrix *W2nz2bynz2_dm = CreateMatrix_lf(nz2,nz2); + TSdvector *wP0_dv = CreateVector_lf(nz2); + //+ + TSdvector yt_sdv, at_sdv, zt_tm1_sdv, ztp1_t_sdv, btp1_sdv; //double loglh_tdata; //logdetDtdata. + TSdvector *wny_dv = CreateVector_lf(ny); + TSdmatrix *Wnzbyny_dm = CreateMatrix_lf(nz,ny); + TSdmatrix *W2nzbynz_dm = CreateMatrix_lf(nz,nz); + TSdmatrix *PHtran_tdata_dm = CreateMatrix_lf(nz,ny); + TSdvector *etdata_dv = CreateVector_lf(ny); + TSdmatrix *Dtdata_dm = CreateMatrix_lf(ny,ny); + TSdmatrix *Kt_tdata0_dm = CreateMatrix_lf(nz,ny); + TSdmatrix *Kt_tdata_dm = CreateMatrix_lf(nz,ny); + //--- For eigenvalue decompositions + int ki; + int errflag; + double eigmax, logdet_Dtdata; + TSdzvector *evals_dzv = NULL; + TSdvector *evals_abs_dv = NULL; //Absolute eigenvalues. + //--- Input arguments. + TSdmatrix *yt_dm = kalfiltv_ps->yt_dm; //ny-by-T. + TSdmatrix *at_dm = kalfiltv_ps->at_dm; //ny-by-T. + TSdcell *Ht_dc = kalfiltv_ps->Ht_dc; //ny-by-nz-by-T. + TSdcell *Rt_dc = kalfiltv_ps->Rt_dc; //ny-by-ny-by-T. Covariance matrix for the measurement equation. + TSdcell *Gt_dc = kalfiltv_ps->Gt_dc; //nz-by-ny-by-T. Cross-covariance. + // + TSdmatrix *bt_dm = kalfiltv_ps->bt_dm; //nz-by-T. + TSdcell *Ft_dc = kalfiltv_ps->Ft_dc; //nz-by-nz-by-T. + TSdcell *Vt_dc = kalfiltv_ps->Vt_dc; //nz-by-nz-by-T. Covariance matrix for the state equation. + // + TSdvector *z0_dv = kalfiltv_ps->z0_dv; //nz-by-1; + TSdmatrix *P0_dm = kalfiltv_ps->P0_dm; //nz-by-nz. + //--- Output arguments. + double loglh; //log likelihood. + TSdmatrix *zt_tm1_dm = kalfiltv_ps->zt_tm1_dm; //nz-by-T. + TSdcell *Pt_tm1_dc = kalfiltv_ps->Pt_tm1_dc; //nz-by-nz-T. + + + + //=== Initializing. + if (!kalfiltv_ps->indxIni) + { + InitializeDiagonalMatrix_lf(Wnzbynz_dm, 1.0); //To be used for I(nz) - + InitializeDiagonalMatrix_lf(Wnz2bynz2_dm, 1.0); //To be used for I(nz2) - + + //=== Eigenanalysis to determine the roots to ensure boundedness. + evals_dzv = CreateVector_dz(nz); + evals_abs_dv = CreateVector_lf(nz); + errflag = eigrgen(evals_dzv, (TSdzmatrix *)NULL, (TSdzmatrix *)NULL, Ft_dc->C[0]); + if (errflag) fn_DisplayError("tz_kalfiltv() in kalman.c: eigen decomposition failed"); + for (ki=nz-1; ki>=0; ki--) evals_abs_dv->v[ki] = sqrt(square(evals_dzv->real->v[ki]) + square(evals_dzv->imag->v[ki])); + evals_abs_dv->flag = V_DEF; + eigmax = MaxVector(evals_abs_dv); + if (eigmax < (1.0+1.0e-14)) + { + //--- Getting z0_dv: zt_tm1(:,1) = (eye(n_z)-F(:,:,1))\b(:,1); + MatrixMinusMatrix(Wnzbynz_dm, Wnzbynz_dm, Ft_dc->C[0]); + CopySubmatrix2vector(z0_dv, 0, bt_dm, 0, 0, bt_dm->nrows); + bdivA_rgens(z0_dv, z0_dv, '\\', Wnzbynz_dm); + //Done with Wnzbynz_dm. + //--- Getting P0_dm: Pt_tm1(:,:,1) = reshape((eye(n_z^2)-kron(F(:,:,1),F(:,:,1)))\V1(:),n_z,n_z); + tz_kron(W2nz2bynz2_dm, Ft_dc->C[0], Ft_dc->C[0]); + MatrixMinusMatrix(Wnz2bynz2_dm, Wnz2bynz2_dm, W2nz2bynz2_dm); + CopySubmatrix2vector(wP0_dv, 0, Vt_dc->C[0], 0, 0, nz2); + bdivA_rgens(wP0_dv, wP0_dv, '\\', Wnz2bynz2_dm); + CopySubvector2matrix_unr(P0_dm, 0, 0, wP0_dv, 0, nz2); + //Done with all w*_dv and W*_dm. + } + else + { + fprintf(stdout, "Fatal error: tz_kalfiltv() in kalman.c: the system is non-stationary solutions\n" + " and the initial conditions must be supplied by, say, input arguments"); + fflush(stdout); + exit( EXIT_FAILURE ); + } + } + CopySubvector2matrix(zt_tm1_dm, 0, 0, z0_dv, 0, z0_dv->n); + CopyMatrix0(Pt_tm1_dc->C[0], P0_dm); + + //====== See p.002 in LiuWZ. ====== + at_sdv.n = yt_sdv.n = yt_dm->nrows; + at_sdv.flag = yt_sdv.flag = V_DEF; + zt_tm1_sdv.n = ztp1_t_sdv.n = zt_tm1_dm->nrows; + zt_tm1_sdv.flag = ztp1_t_sdv.flag = V_DEF; + btp1_sdv.n = bt_dm->nrows; + btp1_sdv.flag = V_DEF; + loglh = 0.0; + for (tdata=0; tdata<T; tdata++ ) + { + //Base-0 timing. + ti = tdata + 1; //Next period. + + //--- Setup. + MatrixTimesMatrix(PHtran_tdata_dm, Pt_tm1_dc->C[tdata], Ht_dc->C[tdata], 1.0, 0.0, 'N', 'T'); + + //--- Data. + //- etdata = Y_T(:,tdata) - a(:,tdata) - Htdata*ztdata; + yt_sdv.v = yt_dm->M + tdata*yt_dm->nrows; + at_sdv.v = at_dm->M + tdata*at_dm->nrows; + zt_tm1_sdv.v = zt_tm1_dm->M + tdata*zt_tm1_dm->nrows; + VectorMinusVector(etdata_dv, &yt_sdv, &at_sdv); + MatrixTimesVector(etdata_dv, Ht_dc->C[tdata], &zt_tm1_sdv, -1.0, 1.0, 'N'); + //+ Dtdata = Htdata*PHtran_tdata + R(:,:,tdata); + CopyMatrix0(Dtdata_dm, Rt_dc->C[tdata]); + MatrixTimesMatrix(Dtdata_dm, Ht_dc->C[tdata], PHtran_tdata_dm, 1.0, 1.0, 'N', 'N'); + ScalarTimesMatrixSquare(Dtdata_dm, 0.5, Dtdata_dm, 'T', 0.5); //Making it symmetric against some rounding errors. + //This making-symmetric is very IMPORTANT; otherwise, we will get the matrix being singular message + // and eigenvalues being negative for the SPD matrix, etc. Then the likelihood becomes either + // a bad number or a complex number. + Dtdata_dm->flag = Dtdata_dm->flag | M_SU | M_SL; + + //--- Forming the log likelihood. + if (!isfinite(logdet_Dtdata=logdetspd(Dtdata_dm))) return (kalfiltv_ps->loglh = -NEARINFINITY); + bdivA_rgens(wny_dv, etdata_dv, '/', Dtdata_dm); + loglh += -(0.5*ny)*LOG2PI - 0.5*logdet_Dtdata - 0.5*VectorDotVector(wny_dv, etdata_dv); + //loglh += -(0.5*ny)*LOG2PI - 0.5*logdeterminant(Dtdata_dm) - 0.5*VectorDotVector(wny_dv, etdata_dv); + //Done with all w*_dv. + + + //--- Updating zt_tm1_dm and Pt_tm1_dc by ztp1_t_sdv and Pt_tm1_dc->C[ti]. + if (ti<T) + { + //Updating only up to tdata=T-2. The values at ti=T or tdata=T-1 will not be used in the likelihood function. + + //- Kt_tdata = (Ft*PHtran_tdata+G(:,:,tdata))/Dtdata; + CopyMatrix0(Kt_tdata0_dm, Gt_dc->C[tdata]); + MatrixTimesMatrix(Kt_tdata0_dm, Ft_dc->C[ti], PHtran_tdata_dm, 1.0, 1.0, 'N', 'N'); + BdivA_rrect(Kt_tdata_dm, Kt_tdata0_dm, '/', Dtdata_dm); + //+ zt_tm1(:,t) = b(:,t) + Ft*zt_tm1(:,tdata) + Kt_tdata*etdata; + ztp1_t_sdv.v = zt_tm1_dm->M + ti*zt_tm1_dm->nrows; + MatrixTimesVector(&ztp1_t_sdv, Ft_dc->C[ti], &zt_tm1_sdv, 1.0, 0.0, 'N'); + MatrixTimesVector(&ztp1_t_sdv, Kt_tdata_dm, etdata_dv, 1.0, 1.0, 'N'); + btp1_sdv.v = bt_dm->M + ti*btp1_sdv.n; + VectorPlusMinusVectorUpdate(&ztp1_t_sdv, &btp1_sdv, 1.0); + //+ Pt_tm1(:,:,t) = Ft*Ptdata*Fttran - Kt_tdata*Dtdata*Kt_tdatatran + V(:,:,t); + CopyMatrix0(Pt_tm1_dc->C[ti], Vt_dc->C[ti]); + MatrixTimesMatrix(Wnzbyny_dm, Kt_tdata_dm, Dtdata_dm, 1.0, 0.0, 'N', 'N'); + MatrixTimesMatrix(Wnzbynz_dm, Wnzbyny_dm, Kt_tdata_dm, 1.0, 0.0, 'N', 'T'); + MatrixPlusMinusMatrixUpdate(Pt_tm1_dc->C[ti], Wnzbynz_dm, -1.0); + //Done with all W*_dm. + MatrixTimesMatrix(Wnzbynz_dm, Ft_dc->C[ti], Pt_tm1_dc->C[tdata], 1.0, 0.0, 'N', 'N'); + MatrixTimesMatrix(W2nzbynz_dm, Wnzbynz_dm, Ft_dc->C[ti], 1.0, 0.0, 'N', 'T'); + MatrixPlusMatrixUpdate(Pt_tm1_dc->C[ti], W2nzbynz_dm); + //Done with all W*_dm. + } + } + zt_tm1_dm->flag = M_GE; + + //=== + DestroyVector_dz(evals_dzv); + DestroyVector_lf(evals_abs_dv); + DestroyMatrix_lf(Wnzbynz_dm); + DestroyMatrix_lf(Wnz2bynz2_dm); + DestroyMatrix_lf(W2nz2bynz2_dm); + DestroyVector_lf(wP0_dv); + // + DestroyVector_lf(wny_dv); + DestroyMatrix_lf(Wnzbyny_dm); + DestroyMatrix_lf(W2nzbynz_dm); + DestroyMatrix_lf(PHtran_tdata_dm); + DestroyVector_lf(etdata_dv); + DestroyMatrix_lf(Dtdata_dm); + DestroyMatrix_lf(Kt_tdata0_dm); + DestroyMatrix_lf(Kt_tdata_dm); + + return (kalfiltv_ps->loglh = loglh); +} +/** +double tz_kalfiltv(struct TSkalfiltv_tag *kalfiltv_ps) +{ + //This function is used to test tz_logTimetCondLH_kalfiltv(). + int T = kalfiltv_ps->T; + int tdata; + double loglh; + + loglh = 0.0; + for (tdata=0; tdata<T; tdata++) loglh += tz_logTimetCondLH_kalfiltv(0, tdata+1, kalfiltv_ps); + + return (loglh); +} +/**/ +//----------------------------------------------------- +//-- Updating Kalman filter at time t for constant-parameters (or known-time-varying) Kalman filter. +//----------------------------------------------------- +double tz_logTimetCondLH_kalfiltv(int st, int inpt, struct TSkalfiltv_tag *kalfiltv_ps) +{ + //st: base-0 grand regime at time t, which is just a dummy for this constant-parameter function in order to use + // Waggoner's automatic functions. + //inpt: base-1 in the sense that inpt>=1 to deal with the time series situation where S_T is (T+1)-by-1 and Y_T is T+nlags_max-by-1. + // The 1st element for S_T is S_T[1] while S_T[0] is s_0 (initial condition). + // The 1st element for Y_T, however, is Y_T[nlags_max+1-1]. + //See (42.3) on p.42 in the SWZII NOTES. + // + //log LH at time t for constant (known-time-varying) Kalman-filter DSGE models (conditional on all the parameters). + // It computes a sequence of one-step predictions and their covariance matrices, and the log likelihood at time t. + // The function uses a forward recursion algorithm. See also the Matlab function fn_kalfil_tv.m + // + // State space model is defined as follows: + // y(t) = a(t) + H(t)*z(t) + eps(t) (observation or measurement equation) + // z(t) = b(t) + F(t)*z(t) + eta(t) (state or transition equation) + // where a(t), H(t), b(t), and F(t) depend on s_t that follows a Markov-chain process and are taken as given. + // + // Inputs are as follows: + // Y_T is a n_y-by-T matrix containing data [y(1), ... , y(T)]. + // a is an n_y-by-T matrix of time-varying input vectors in the measurement equation. + // H is an n_y-by-n_z-by-T 3-D of time-varying matrices in the measurement equation. + // R is an n_y-by-n_y-by-T 3-D of time-varying covariance matrices for the error in the measurement equation. + // G is an n_z-by-n_y-by-T 3-D of time-varying E(eta_t * eps_t'). + // ------ + // b is an n_z-by-T matrix of time-varying input vectors in the state equation with b(:,1) as an initial condition. + // F is an n_z-by-n_z-by-T 3-D of time-varying transition matrices in the state equation with F(:,:,1) as an initial condition. + // V is an n_z-by-n_z-by-T 3-D of time-varying covariance matrices for the error in the state equation with V(:,:,1) as an initial condition. + // ------ + // indxIni: 1: using the initial condition with zt_tm1(:,1)=z0 and Pt_tm1(:,:,1)=P0; + // 0: using the unconditional mean for any given regime at time 0. + // z0 is an n_z-by-1 vector of initial condition when indxIni=1. (Value to be assigned if indxIni=0.) + // P0 is an n_z-by-n_z matrix of initial condition when indxIni=1. (Value to be assigned if indxIni=0.) + // + // Outputs are as follows: + // loglh is a value of the log likelihood function of the state-space model + // under the assumption that errors are multivariate Gaussian. + // zt_tm1 is an n_z-by-T matrices of one-step predicted state vectors with z0_0m1 as an initial condition (base-0 first element) + // and with z_{T|T-1} as the last element. Thus, we can use it as a base-1 vector. + // Pt_tm1 is an n_z-by-n_z-by-T 3-D of covariance matrices of zt_tm1 with P0_0m1 as though it were a initial condition + // and with P_{T|T-1} as the last element. Thus, we can use it as though it were a base-1 cell. + // + // The initial state vector and its covariance matrix are computed under the bounded (stationary) condition: + // z0_0m1 = (I-F(:,:,1))\b(:,1) + // vec(P0_0m1) = (I-kron(F(:,:,1),F(:,:,1)))\vec(V(:,:,1)) + // Note that all eigenvalues of the matrix F(:,:,1) are inside the unit circle when the state-space model is bounded (stationary). + // + // April 2008, written by Tao Zha + // See Hamilton's book ([13.2.13] -- [13.2.22]), Harvey (pp.100-106), and LiuWZ Model I NOTES pp.001-003. + + //--- Output arguments. + double loglh_timet; //log likelihood at time t. + TSdmatrix *zt_tm1_dm = kalfiltv_ps->zt_tm1_dm; //nz-by-T. + TSdcell *Pt_tm1_dc = kalfiltv_ps->Pt_tm1_dc; //nz-by-nz-T. + //--- Input arguments. + int tdata, tp1; + TSdvector *z0_dv = kalfiltv_ps->z0_dv; //nz-by-1; + TSdmatrix *P0_dm = kalfiltv_ps->P0_dm; //nz-by-nz. + int T = kalfiltv_ps->T; + int ny = kalfiltv_ps->ny; + int nz = kalfiltv_ps->nz; + //--- Work arguments. + int nz2 = square(nz); + TSdmatrix *Wnzbynz_dm = CreateMatrix_lf(nz,nz); + TSdmatrix *Wnz2bynz2_dm = CreateMatrix_lf(nz2,nz2); + TSdmatrix *W2nz2bynz2_dm = CreateMatrix_lf(nz2,nz2); + TSdvector *wP0_dv = CreateVector_lf(nz2); + //+ + TSdvector yt_sdv, at_sdv, zt_tm1_sdv, ztp1_t_sdv, btp1_sdv; + TSdvector *wny_dv = CreateVector_lf(ny); + TSdmatrix *Wnzbyny_dm = CreateMatrix_lf(nz,ny); + TSdmatrix *W2nzbynz_dm = CreateMatrix_lf(nz,nz); + TSdmatrix *PHtran_tdata_dm = CreateMatrix_lf(nz,ny); + TSdvector *etdata_dv = CreateVector_lf(ny); + TSdmatrix *Dtdata_dm = CreateMatrix_lf(ny,ny); + TSdmatrix *Kt_tdata0_dm = CreateMatrix_lf(nz,ny); + TSdmatrix *Kt_tdata_dm = CreateMatrix_lf(nz,ny); + //--- For eigenvalue decompositions + int ki; + int errflag; + double eigmax, logdet_Dtdata; + TSdzvector *evals_dzv = NULL; + TSdvector *evals_abs_dv = NULL; //Absolute eigenvalues. + //--- Input arguments. + TSdmatrix *yt_dm = kalfiltv_ps->yt_dm; //ny-by-T. + TSdmatrix *at_dm = kalfiltv_ps->at_dm; //ny-by-T. + TSdcell *Ht_dc = kalfiltv_ps->Ht_dc; //ny-by-nz-by-T. + TSdcell *Rt_dc = kalfiltv_ps->Rt_dc; //ny-by-ny-by-T. Covariance matrix for the measurement equation. + TSdcell *Gt_dc = kalfiltv_ps->Gt_dc; //nz-by-ny-by-T. Cross-covariance. + // + TSdmatrix *bt_dm = kalfiltv_ps->bt_dm; //nz-by-T. + TSdcell *Ft_dc = kalfiltv_ps->Ft_dc; //nz-by-nz-by-T. + TSdcell *Vt_dc = kalfiltv_ps->Vt_dc; //nz-by-nz-by-T. Covariance matrix for the state equation. + // + + + tdata = (tp1=inpt) - 1; //Base-0 time. + + //======= Initial condition. ======= + if (tdata==0) + { + //=== Initializing. + if (!kalfiltv_ps->indxIni) + { + InitializeDiagonalMatrix_lf(Wnzbynz_dm, 1.0); //To be used for I(nz) - + InitializeDiagonalMatrix_lf(Wnz2bynz2_dm, 1.0); //To be used for I(nz2) - + + //=== Eigenanalysis to determine the roots to ensure boundedness. + evals_dzv = CreateVector_dz(nz); + evals_abs_dv = CreateVector_lf(nz); + errflag = eigrgen(evals_dzv, (TSdzmatrix *)NULL, (TSdzmatrix *)NULL, Ft_dc->C[0]); + if (errflag) fn_DisplayError("tz_logTimetCondLH_kalfiltv() in kalman.c: eigen decomposition failed"); + for (ki=nz-1; ki>=0; ki--) evals_abs_dv->v[ki] = sqrt(square(evals_dzv->real->v[ki]) + square(evals_dzv->imag->v[ki])); + evals_abs_dv->flag = V_DEF; + eigmax = MaxVector(evals_abs_dv); + if (eigmax < (1.0+1.0e-14)) + { + //--- Getting z0_dv: zt_tm1(:,1) = (eye(n_z)-F(:,:,1))\b(:,1); + MatrixMinusMatrix(Wnzbynz_dm, Wnzbynz_dm, Ft_dc->C[0]); + CopySubmatrix2vector(z0_dv, 0, bt_dm, 0, 0, bt_dm->nrows); + bdivA_rgens(z0_dv, z0_dv, '\\', Wnzbynz_dm); + //Done with Wnzbynz_dm. + //--- Getting P0_dm: Pt_tm1(:,:,1) = reshape((eye(n_z^2)-kron(F(:,:,1),F(:,:,1)))\V1(:),n_z,n_z); + tz_kron(W2nz2bynz2_dm, Ft_dc->C[0], Ft_dc->C[0]); + MatrixMinusMatrix(Wnz2bynz2_dm, Wnz2bynz2_dm, W2nz2bynz2_dm); + CopySubmatrix2vector(wP0_dv, 0, Vt_dc->C[0], 0, 0, nz2); + bdivA_rgens(wP0_dv, wP0_dv, '\\', Wnz2bynz2_dm); + CopySubvector2matrix_unr(P0_dm, 0, 0, wP0_dv, 0, nz2); + //Done with all w*_dv and W*_dm. + } + else + { + fprintf(FPTR_DEBUG, "Fatal error: tz_logTimetCondLH_kalfiltv() in kalman.c: the system is non-stationary solutions\n" + " and thus the initial conditions must be supplied by, say, input arguments"); + fflush(FPTR_DEBUG); + exit( EXIT_FAILURE ); + } + } + CopySubvector2matrix(zt_tm1_dm, 0, 0, z0_dv, 0, z0_dv->n); + CopyMatrix0(Pt_tm1_dc->C[tdata], P0_dm); + } + + + //======= Liklihood at time t (see p.002 in LiuWZ). ======= + at_sdv.n = yt_sdv.n = yt_dm->nrows; + at_sdv.flag = yt_sdv.flag = V_DEF; + zt_tm1_sdv.n = ztp1_t_sdv.n = zt_tm1_dm->nrows; + zt_tm1_sdv.flag = ztp1_t_sdv.flag = V_DEF; + btp1_sdv.n = bt_dm->nrows; + btp1_sdv.flag = V_DEF; + + //--- Setup. + MatrixTimesMatrix(PHtran_tdata_dm, Pt_tm1_dc->C[tdata], Ht_dc->C[tdata], 1.0, 0.0, 'N', 'T'); + + //--- Data. + //- etdata = Y_T(:,tdata) - a(:,tdata) - Htdata*ztdata; + yt_sdv.v = yt_dm->M + tdata*yt_dm->nrows; + at_sdv.v = at_dm->M + tdata*at_dm->nrows; + zt_tm1_sdv.v = zt_tm1_dm->M + tdata*zt_tm1_dm->nrows; + VectorMinusVector(etdata_dv, &yt_sdv, &at_sdv); + MatrixTimesVector(etdata_dv, Ht_dc->C[tdata], &zt_tm1_sdv, -1.0, 1.0, 'N'); + //+ Dtdata = Htdata*PHtran_tdata + R(:,:,tdata); + CopyMatrix0(Dtdata_dm, Rt_dc->C[tdata]); + MatrixTimesMatrix(Dtdata_dm, Ht_dc->C[tdata], PHtran_tdata_dm, 1.0, 1.0, 'N', 'N'); + ScalarTimesMatrixSquare(Dtdata_dm, 0.5, Dtdata_dm, 'T', 0.5); //Making it symmetric against some rounding errors. + //This making-symmetric is very IMPORTANT; otherwise, we will get the matrix being singular message + // and eigenvalues being negative for the SPD matrix, etc. Then the likelihood becomes either + // a bad number or a complex number. + Dtdata_dm->flag = Dtdata_dm->flag | M_SU | M_SL; + + //--- Forming the log likelihood. + if (!isfinite(logdet_Dtdata=logdetspd(Dtdata_dm))) return (loglh_timet = -NEARINFINITY); + bdivA_rgens(wny_dv, etdata_dv, '/', Dtdata_dm); + loglh_timet = -(0.5*ny)*LOG2PI - 0.5*logdet_Dtdata - 0.5*VectorDotVector(wny_dv, etdata_dv); + //Done with all w*_dv. + + + //======= Updating for the next period. ======= + //--- Updating zt_tm1_dm and Pt_tm1_dc by ztp1_t_sdv and Pt_tm1_dc->C[ti]. + if (tp1<T) + { + //Updating only up to tdata=T-2, because the values at tp1=T or tdata=T-1 will NOT be used in the likelihood function. + + //- Kt_tdata = (Ft*PHtran_tdata+G(:,:,tdata))/Dtdata; + CopyMatrix0(Kt_tdata0_dm, Gt_dc->C[tdata]); + MatrixTimesMatrix(Kt_tdata0_dm, Ft_dc->C[tp1], PHtran_tdata_dm, 1.0, 1.0, 'N', 'N'); + BdivA_rrect(Kt_tdata_dm, Kt_tdata0_dm, '/', Dtdata_dm); + //+ zt_tm1(:,t) = b(:,t) + Ft*zt_tm1(:,tdata) + Kt_tdata*etdata; + ztp1_t_sdv.v = zt_tm1_dm->M + tp1*zt_tm1_dm->nrows; + MatrixTimesVector(&ztp1_t_sdv, Ft_dc->C[tp1], &zt_tm1_sdv, 1.0, 0.0, 'N'); + MatrixTimesVector(&ztp1_t_sdv, Kt_tdata_dm, etdata_dv, 1.0, 1.0, 'N'); + btp1_sdv.v = bt_dm->M + tp1*btp1_sdv.n; + VectorPlusMinusVectorUpdate(&ztp1_t_sdv, &btp1_sdv, 1.0); + //+ Pt_tm1(:,:,t) = Ft*Ptdata*Fttran - Kt_tdata*Dtdata*Kt_tdatatran + V(:,:,t); + CopyMatrix0(Pt_tm1_dc->C[tp1], Vt_dc->C[tp1]); + MatrixTimesMatrix(Wnzbyny_dm, Kt_tdata_dm, Dtdata_dm, 1.0, 0.0, 'N', 'N'); + MatrixTimesMatrix(Wnzbynz_dm, Wnzbyny_dm, Kt_tdata_dm, 1.0, 0.0, 'N', 'T'); + MatrixPlusMinusMatrixUpdate(Pt_tm1_dc->C[tp1], Wnzbynz_dm, -1.0); + //Done with all W*_dm. + MatrixTimesMatrix(Wnzbynz_dm, Ft_dc->C[tp1], Pt_tm1_dc->C[tdata], 1.0, 0.0, 'N', 'N'); + MatrixTimesMatrix(W2nzbynz_dm, Wnzbynz_dm, Ft_dc->C[tp1], 1.0, 0.0, 'N', 'T'); + MatrixPlusMatrixUpdate(Pt_tm1_dc->C[tp1], W2nzbynz_dm); + //Done with all W*_dm. + } + zt_tm1_dm->flag = M_GE; + + //=== + DestroyVector_dz(evals_dzv); + DestroyVector_lf(evals_abs_dv); + DestroyMatrix_lf(Wnzbynz_dm); + DestroyMatrix_lf(Wnz2bynz2_dm); + DestroyMatrix_lf(W2nz2bynz2_dm); + DestroyVector_lf(wP0_dv); + // + DestroyVector_lf(wny_dv); + DestroyMatrix_lf(Wnzbyny_dm); + DestroyMatrix_lf(W2nzbynz_dm); + DestroyMatrix_lf(PHtran_tdata_dm); + DestroyVector_lf(etdata_dv); + DestroyMatrix_lf(Dtdata_dm); + DestroyMatrix_lf(Kt_tdata0_dm); + DestroyMatrix_lf(Kt_tdata_dm); + + return (loglh_timet); +} + + + + +//----------------------------------------------------- +//- WARNING: bedore using this function, make sure to call the following functions +// Only once in creating lwzmodel_ps: Refresh_kalfilms_*(lwzmodel_ps); +// Everytime when parameters are changed: RefreshEverything(); RefreRunningGensys_allcases(lwzmodel_ps) in particular. +//----------------------------------------------------- +double logTimetCondLH_kalfilms_1stapp(int st, int inpt, struct TSkalfilmsinputs_1stapp_tag *kalfilmsinputs_1stapp_ps, struct TStateModel_tag *smodel_ps) +{ + //st: base-0 grand regime -- deals with the cross-section values at time t. + //inpt: base-1 in the sense that inpt>=1 to deal with the time series situation where S_T is (T+1)-by-1 and Y_T is T+nlags_max-by-1. + // The 1st element for S_T is S_T[1] while S_T[0] is s_0 (initial condition). + // The 1st element for Y_T, however, is Y_T[nlags_max+1-1]. + //See (42.3) on p.42 in the SWZII NOTES. + + //-- Output arguments + double loglh_timet; + //--- Input arguments + TSdcell *etdata_dc = kalfilmsinputs_1stapp_ps->etdata_dc; //ny-by-nst-by-T, save for computing the likelihood. + TSdfourth *Dtdata_d4 = kalfilmsinputs_1stapp_ps->Dtdata_d4; //ny-by-ny-nst-by-T, save for computing the likelihood and updating Kalman filter Updatekalfilms_1stapp(). + //--- Local variables + int tbase0; + double logdet_Dtdata; + //--- Accessible variables + int ny = kalfilmsinputs_1stapp_ps->ny; + TSdvector etdata_sdv; + //=== Work arguments. + TSdvector *wny_dv = CreateVector_lf(ny); + + + + //--- Critical checking. + if (inpt > kalfilmsinputs_1stapp_ps->T) + fn_DisplayError(".../kalman.c/logTimetCondLH_kalfilms_1stapp(): The time exceeds the\n" + " data sample size allocated the structure TSkalfilmsinputs_1stapp_tag"); + + //--- The following is for safe guard. InitializeKalman_z10_P10() should be called in, say, RefreshEverything(). + if (kalfilmsinputs_1stapp_ps->ztm1_track < 0) + if (!InitializeKalman_z10_P10(kalfilmsinputs_1stapp_ps, (TSdmatrix *)NULL, (TSdcell *)NULL)) + fn_DisplayError(".../kalman.c/logTimetCondLH_kalfilms_1stapp(): the system is non-stationary when calling" + " InitializeKalman_z10_P10(). Please call this function in RefreshEverthing() and" + " set the likehood to be -infty for early exit"); + + tbase0=inpt-1; + + //------------------- The order matters. Updatekalfilms_1stapp() must be called before Update_et_Dt_1stapp(). ----------------- + //--- $$$ Critical updating where we MUSt have inpt-1. If inpt, Updatekalfilms_1stapp() will call this function again + //--- $$$ because DW function ProbabilityStateConditionalCurrent() need to access this function at time inpt, + //--- $$$ which has not computed before Updatekalfilms_1stapp(). Thus, we'll have an infinite loop. + Updatekalfilms_1stapp(tbase0, kalfilmsinputs_1stapp_ps, smodel_ps); +// //--- $$$ Critical updating. +// Update_et_Dt_1stapp(tbase0, kalfilmsinputs_1stapp_ps); +// //This function will give Dtdata_d4->F[tbase0], etdata_dc->C[tbase0], and PHtran_tdata_d4->F[tbase0]. + + + + //====================================================== + //= Getting the logLH at time tbase0 or time inpt. + //====================================================== + //--- Forming the log conditional likelihood at t. + etdata_sdv.n = ny; + etdata_sdv.v = etdata_dc->C[tbase0]->M + ny*st; + etdata_sdv.flag = V_DEF; + if (!isfinite(logdet_Dtdata=logdetspd(Dtdata_d4->F[tbase0]->C[st]))) return (loglh_timet = -NEARINFINITY); + bdivA_rgens(wny_dv, &etdata_sdv, '/', Dtdata_d4->F[tbase0]->C[st]); + loglh_timet = -(0.5*ny)*LOG2PI - 0.5*logdet_Dtdata - 0.5*VectorDotVector(wny_dv, &etdata_sdv); + //Done with all w*_dv. + + //=== + DestroyVector_lf(wny_dv); + + return (loglh_timet); +} +//====================================================== +//= Computing z_{1|0} and P_{1|0} for each new parameter values. +//====================================================== +int InitializeKalman_z10_P10(struct TSkalfilmsinputs_1stapp_tag *kalfilmsinputs_1stapp_ps, TSdmatrix *z10_dm, TSdcell *P10_dc) +{ + //See p.001 and p.004 in LWZ Model II. + //Outputs: + // return 1: success in initializing; 0: initializing fails, so the likelihood must be set to -infty outside this function. + // ztm1_track to track the time up to which Kalman filter have been updated. + // z0_dm, zt_tm1_dc->C[0] + // P0_dc, Pt_tm1_d4->F[0] + + //--- Output arguments + TSdmatrix *z0_0_dm = kalfilmsinputs_1stapp_ps->z0_dm; //nz-by-nst. + TSdmatrix *z0_dm = kalfilmsinputs_1stapp_ps->z0_dm; //nz-by-nst. + TSdcell *P0_dc = kalfilmsinputs_1stapp_ps->P0_dc; //nz-by-nz-by-nst. + //+ Used to get zt_tm1_dc->C[0] and Pt_tm1_d4->F[0] only. + TSdcell *zt_tm1_dc = kalfilmsinputs_1stapp_ps->zt_tm1_dc; //nz-by-nst-by-(T+1). + TSdfourth *Pt_tm1_d4 = kalfilmsinputs_1stapp_ps->Pt_tm1_d4; //nz-by-nz-by-nst-by-(T+1). + //--- Input arguments + TSdmatrix *yt_dm = kalfilmsinputs_1stapp_ps->yt_dm; //ny-by-T. + TSdmatrix *at_dm = kalfilmsinputs_1stapp_ps->at_dm; //ny-by-nst. + TSdcell *Ht_dc = kalfilmsinputs_1stapp_ps->Ht_dc; //ny-by-nz-by-nst. + TSdcell *Rt_dc = kalfilmsinputs_1stapp_ps->Rt_dc; //ny-by-ny-by-nst. Covariance matrix for the measurement equation. + //+ + TSdmatrix *bt_dm = kalfilmsinputs_1stapp_ps->bt_dm; //nz-by-nst. + TSdcell *Ft_dc = kalfilmsinputs_1stapp_ps->Ft_dc; //nz-by-nz-by-nst. + TSdcell *Vt_dc = kalfilmsinputs_1stapp_ps->Vt_dc; //nz-by-nz-by-nst. Covariance matrix for the state equation. + //--- Local variables + int sti; + //--- Accessible variables + int ny = kalfilmsinputs_1stapp_ps->ny; + int nz = kalfilmsinputs_1stapp_ps->nz; + int nst = kalfilmsinputs_1stapp_ps->nst; + TSdvector z0_sdv, z0_0_sdv, bt_sdv; + TSdvector yt_sdv, at_sdv; + //--- For the initial conditions: eigenvalue decompositions + int ki; + int errflag; + double eigmax; + //=== + int nz2 = square(nz); + TSdmatrix *Wnzbynz_dm = CreateMatrix_lf(nz,nz); + TSdmatrix *Wnz2bynz2_dm = CreateMatrix_lf(nz2,nz2); + TSdmatrix *W2nz2bynz2_dm = CreateMatrix_lf(nz2,nz2); + TSdvector *wP0_dv = CreateVector_lf(nz2); + // + TSdzvector *evals_dzv = evals_dzv = CreateVector_dz(nz); + TSdvector *evals_abs_dv = CreateVector_lf(nz); //Absolute eigenvalues. + + + if (kalfilmsinputs_1stapp_ps->ztm1_track < 0) + { + z0_sdv.n = z0_0_sdv.n = bt_sdv.n = nz; + z0_sdv.flag = z0_0_sdv.flag = bt_sdv.flag = V_DEF; + at_sdv.n = yt_sdv.n = ny; + at_sdv.flag = yt_sdv.flag = V_DEF; + + + //======= Initial condition. ======= + if (!kalfilmsinputs_1stapp_ps->indxIni) + { + z0_0_dm->flag = z0_dm->flag = M_GE; + for (sti=nst-1; sti>=0; sti--) + { + if (kalfilmsinputs_1stapp_ps->DiffuseScale) //Diffuse initial conditions are used. + { + //--- Diffuse condition for z0_dv. + z0_sdv.v = z0_dm->M + z0_sdv.n*sti; + z0_0_sdv.v = z0_0_dm->M + z0_0_sdv.n*sti; + bt_sdv.v = bt_dm->M + bt_sdv.n*sti; + InitializeConstantVector_lf(&z0_0_sdv, 0.0); + MatrixTimesVector(&z0_sdv, Ft_dc->C[sti], &z0_0_sdv, 1.0, 0.0, 'N'); + VectorPlusVector(&z0_sdv, &z0_sdv, &bt_sdv); + //--- Diffuse condition for P0_dm. + InitializeDiagonalMatrix_lf(Wnzbynz_dm, kalfilmsinputs_1stapp_ps->DiffuseScale); //To be used for DiffuseScale*I(nz) + CopyMatrix0(P0_dc->C[sti], Wnzbynz_dm); + //Done with W*_dm. + } + else //Unconditional moments for initial conditions are used. + { + InitializeDiagonalMatrix_lf(Wnzbynz_dm, 1.0); //To be used for I(nz) - + InitializeDiagonalMatrix_lf(Wnz2bynz2_dm, 1.0); //To be used for I(nz2) - + + //=== Eigenanalysis to determine the roots to ensure boundedness. + errflag = eigrgen(evals_dzv, (TSdzmatrix *)NULL, (TSdzmatrix *)NULL, Ft_dc->C[sti]); + if (errflag) fn_DisplayError("kalman.c/InitializeKalman_z10_P10(): eigen decomposition failed"); + for (ki=nz-1; ki>=0; ki--) evals_abs_dv->v[ki] = sqrt(square(evals_dzv->real->v[ki]) + square(evals_dzv->imag->v[ki])); + evals_abs_dv->flag = V_DEF; + eigmax = MaxVector(evals_abs_dv); + if (eigmax < (1.0-SQRTEPSILON)) //(1.0+EPSILON)) + { + //--- Getting z0_dv: zt_tm1(:,1) = (eye(n_z)-F(:,:,sti))\b(:,sti); + z0_0_sdv.v = z0_0_dm->M + z0_0_sdv.n*sti; + z0_sdv.v = z0_dm->M + z0_sdv.n*sti; + MatrixMinusMatrix(Wnzbynz_dm, Wnzbynz_dm, Ft_dc->C[sti]); + CopySubmatrix2vector(&z0_0_sdv, 0, bt_dm, 0, sti, bt_dm->nrows); + bdivA_rgens(&z0_0_sdv, &z0_0_sdv, '\\', Wnzbynz_dm); + //- Under the assumption s_0 = s_1 (this is a short-cut). + MatrixTimesVector(&z0_sdv, Ft_dc->C[sti], &z0_0_sdv, 1.0, 0.0, 'N'); + VectorPlusVector(&z0_sdv, &z0_sdv, &bt_sdv); + //Done with Wnzbynz_dm. + //--- Getting P0_dm: Pt_tm1(:,:,1) = reshape((eye(n_z^2)-kron(F(:,:,sti),F(:,:,sti)))\V1(:),n_z,n_z); + tz_kron(W2nz2bynz2_dm, Ft_dc->C[sti], Ft_dc->C[sti]); + MatrixMinusMatrix(Wnz2bynz2_dm, Wnz2bynz2_dm, W2nz2bynz2_dm); + CopySubmatrix2vector(wP0_dv, 0, Vt_dc->C[sti], 0, 0, nz2); + bdivA_rgens(wP0_dv, wP0_dv, '\\', Wnz2bynz2_dm); + CopySubvector2matrix_unr(P0_dc->C[sti], 0, 0, wP0_dv, 0, nz2); + //Done with all w*_dv and W*_dm. + } + else + { + if (0) //0: no printing. + { + #if defined (USE_DEBUG_FILE) + fprintf(FPTR_DEBUG, "\n-------WARNING: ----------\n"); + fprintf(FPTR_DEBUG, "\nIn grand regime sti=%d\n", sti); + fprintf(FPTR_DEBUG, ".../kalman.c/InitializeKalman_z10_P10(): the system is non-stationary solutions\n" + " and see p.003 in LWZ Model II"); + #else + fprintf(stdout, "\n-----------------\n"); + fprintf(stdout, "\nIn grand regime sti=%d\n", sti); + fprintf(stdout, ".../kalman.c/InitializeKalman_z10_P10(): the system is non-stationary solutions\n" + " and see p.003 in LWZ Model II"); + #endif + } + //=== See p.000.3 in LWZ Model II. + //=== Do NOT use the following option. It turns out that this will often generate explosive conditional liklihood + //=== at the end of the sample, because Pt_tm1 shrinks to zero overtime due to the sigularity of + //=== the initila condition P_{1|0}. + //--- Letting z0_dv = 0.0 + // z0_sdv.v = z0_dm->M + z0_sdv.n*sti; + // InitializeConstantVector_lf(&z0_sdv, 0.0); + // //--- Letting P0_dm = V + // CopyMatrix0(P0_dc->C[sti], Vt_dc->C[sti]); + + //=== + DestroyVector_dz(evals_dzv); + DestroyVector_lf(evals_abs_dv); + DestroyMatrix_lf(Wnzbynz_dm); + DestroyMatrix_lf(Wnz2bynz2_dm); + DestroyMatrix_lf(W2nz2bynz2_dm); + DestroyVector_lf(wP0_dv); + + return (0); //Early exit with kalfilmsinputs_1stapp_ps->ztm1_track continues to be -1. + } + } + } + } + else + { + if (!z10_dm) fn_DisplayError(".../kalman.c/InitializeKalman_z10_P10(): The initial condition z_{1|0}\n" + " must be supplied as valid input arguments for when indxIni == 1"); + else + CopyMatrix0(z0_dm, z10_dm); + + if (!P10_dc) fn_DisplayError(".../kalman.c/InitializeKalman_z10_P10(): The initial condition P_{1|0}\n" + " must be supplied as valid input arguments for when indxIni == 1"); + else + CopyCell0(P0_dc, P10_dc); + } + CopyMatrix0(zt_tm1_dc->C[0], z0_dm); //At time t-1 = 1. + CopyCell0(Pt_tm1_d4->F[0], P0_dc); //At time t-1 = 1. + + + kalfilmsinputs_1stapp_ps->ztm1_track = 0; //Must reset to 0, meaning initial setting is done and ready for computing LH at t = 1. + + Update_et_Dt_1stapp(0, kalfilmsinputs_1stapp_ps); + + //=== + DestroyVector_dz(evals_dzv); + DestroyVector_lf(evals_abs_dv); + DestroyMatrix_lf(Wnzbynz_dm); + DestroyMatrix_lf(Wnz2bynz2_dm); + DestroyMatrix_lf(W2nz2bynz2_dm); + DestroyVector_lf(wP0_dv); + + return (1); + } + else + { + fn_DisplayError(".../kalman.c/InitializeKalman_z10_P10(): calling this function makes sense only if" + " kalfilmsinputs_1stapp_ps->ztm1_track is -1. Please check this value."); + + //=== + DestroyVector_dz(evals_dzv); + DestroyVector_lf(evals_abs_dv); + DestroyMatrix_lf(Wnzbynz_dm); + DestroyMatrix_lf(Wnz2bynz2_dm); + DestroyMatrix_lf(W2nz2bynz2_dm); + DestroyVector_lf(wP0_dv); + + return (0); + } +} +//====================================================== +//= Integrating out the lagged regimes in order to +//= updating zt_tm1 and Pt_tm1 for next perid tp1 through Kim-Nelson filter. +//= tdata representing base-0 t timing, while inpt represents base-1 t timing. +// +//= Purpose: for each inpt, we integrate out grand regimes st +//= only ONCE to prevent the dimension of updated zt_tm1 and Pt_tm1 through Kim-Nelson filter. +//====================================================== +static int Updatekalfilms_1stapp(int t_1, struct TSkalfilmsinputs_1stapp_tag *kalfilmsinputs_1stapp_ps, struct TStateModel_tag *smodel_ps) +{ + //Output: + // tm1update + // z_{t_1+1|t_1} + // P_{t_1+1|t_1} + //Input: + // t-1: base-1 t timing. Thus t-1=inpt-1. + + //--- Local variables + int stp1i, sti, t_2, t_2p1; + double prob_previous_regimes; + //-- Output arguments + TSdcell *zt_tm1_dc = kalfilmsinputs_1stapp_ps->zt_tm1_dc; //nz-by-nst-by-(T+1). + TSdfourth *Pt_tm1_d4 = kalfilmsinputs_1stapp_ps->Pt_tm1_d4; //nz-by-nz-by-nst-by-(T+1). + //--- Input arguments + TSdcell *Gt_dc = kalfilmsinputs_1stapp_ps->Gt_dc; //nz-by-ny-by-nst. Cross-covariance. + //+ + TSdmatrix *bt_dm = kalfilmsinputs_1stapp_ps->bt_dm; //nz-by-nst. + TSdcell *Ft_dc = kalfilmsinputs_1stapp_ps->Ft_dc; //nz-by-nz-by-nst. + TSdcell *Vt_dc = kalfilmsinputs_1stapp_ps->Vt_dc; //nz-by-nz-by-nst. Covariance matrix for the state equation. + //+ + TSdfourth *PHtran_tdata_d4 = kalfilmsinputs_1stapp_ps->PHtran_tdata_d4; //nz-by-ny-by-nst-T, saved only for updating Kalman filter Updatekalfilms_1stapp(). + TSdcell *etdata_dc = kalfilmsinputs_1stapp_ps->etdata_dc; //ny-by-nst-by-T, save for computing the likelihood. + TSdfourth *Dtdata_d4 = kalfilmsinputs_1stapp_ps->Dtdata_d4; //ny-by-ny-nst-by-T, save for computing the likelihood and updating Kalman filter Updatekalfilms_1stapp(). + //--- Accessible variables + int ny = kalfilmsinputs_1stapp_ps->ny; + int nz = kalfilmsinputs_1stapp_ps->nz; + int nst = kalfilmsinputs_1stapp_ps->nst; + int T = kalfilmsinputs_1stapp_ps->T; + TSdvector z0_sdv; + TSdvector btp1_sdv; + TSdvector etdata_sdv; + //=== Work arguments. + TSdmatrix *Wnzbynz_dm = CreateMatrix_lf(nz,nz); + //+ + TSdmatrix *Wnzbyny_dm = CreateMatrix_lf(nz,ny); + TSdmatrix *W2nzbynz_dm = CreateMatrix_lf(nz,nz); + TSdmatrix *Kt_tdata0_dm = CreateMatrix_lf(nz,ny); + TSdmatrix *Kt_tdata_dm = CreateMatrix_lf(nz,ny); + //=== For updating zt_tm1_dm and Pt_tm1. + TSdvector *ztp1_t_dv = CreateVector_lf(nz); + TSdmatrix *Ptp1_t_dm = CreateMatrix_lf(nz, nz); + TSdvector *ztp1_dv = CreateVector_lf(nz); + TSdmatrix *Ptp1_dm = CreateMatrix_lf(nz, nz); + + + //--- Critical checking. + if (kalfilmsinputs_1stapp_ps->ztm1_track < 0) + fn_DisplayError(".../kalman.c/Updatekalfilms_1stapp(): Make sure InitializeKalman_z10_P10() is called in the function RefreshEverthing()"); + + + z0_sdv.n = nz; + z0_sdv.flag = V_DEF; + btp1_sdv.n = nz; + btp1_sdv.flag = V_DEF; + //+ + etdata_sdv.n = ny; + etdata_sdv.flag = V_DEF; + + for (t_2=kalfilmsinputs_1stapp_ps->ztm1_track; t_2<t_1; t_2++) + { + //If t_1 <= ztm1_track, no updating. + //If t_1 > ztm1_track, updating z_{t|t-1} and P_{t|t-1} up to t-1 = t_1. + + zt_tm1_dc->C[t_2p1=t_2+1]->flag = M_GE; + for (stp1i=nst-1; stp1i>=0; stp1i--) + { + InitializeConstantVector_lf(ztp1_dv, 0.0); //To be summed over sti. + InitializeConstantMatrix_lf(Ptp1_dm, 0.0); //To be summed over sti. + + for (sti=nst-1; sti>=0; sti--) + { + //=== Updating for next period by integrating out sti.. + //--- Ktp1_t = (F_tp1*PHtran_t+G(:,:,t))/Dt; + //--- Kt_tdata = (Ft*PHtran_tdata+G(:,:,tdata))/Dtdata where t=tp1 and tdata=t. + CopyMatrix0(Kt_tdata0_dm, Gt_dc->C[sti]); + MatrixTimesMatrix(Kt_tdata0_dm, Ft_dc->C[stp1i], PHtran_tdata_d4->F[t_2]->C[sti], 1.0, 1.0, 'N', 'N'); + BdivA_rrect(Kt_tdata_dm, Kt_tdata0_dm, '/', Dtdata_d4->F[t_2]->C[sti]); + //+ zt_tm1(:,t) = b(:,t) + Ft*zt_tm1(:,tdata) + Kt_tdata*etdata where t=tp1 and tm1=t. + etdata_sdv.v = etdata_dc->C[t_2]->M + ny*sti; + z0_sdv.v = zt_tm1_dc->C[t_2]->M + nz*sti; //sti: regime at time t_2. + MatrixTimesVector(ztp1_t_dv, Ft_dc->C[stp1i], &z0_sdv, 1.0, 0.0, 'N'); + MatrixTimesVector(ztp1_t_dv, Kt_tdata_dm, &etdata_sdv, 1.0, 1.0, 'N'); + btp1_sdv.v = bt_dm->M + stp1i*btp1_sdv.n; + VectorPlusMinusVectorUpdate(ztp1_t_dv, &btp1_sdv, 1.0); + //+ Pt_tm1(:,:,t) = Ft*Ptdata*Fttran - Kt_tdata*Dtdata*Kt_tdatatran + V(:,:,t); + CopyMatrix0(Ptp1_t_dm, Vt_dc->C[stp1i]); + MatrixTimesMatrix(Wnzbyny_dm, Kt_tdata_dm, Dtdata_d4->F[t_2]->C[sti], 1.0, 0.0, 'N', 'N'); + MatrixTimesMatrix(Wnzbynz_dm, Wnzbyny_dm, Kt_tdata_dm, 1.0, 0.0, 'N', 'T'); + MatrixPlusMinusMatrixUpdate(Ptp1_t_dm, Wnzbynz_dm, -1.0); + //Done with all W*_dm. + MatrixTimesMatrix(Wnzbynz_dm, Ft_dc->C[stp1i], Pt_tm1_d4->F[t_2]->C[sti], 1.0, 0.0, 'N', 'N'); + MatrixTimesMatrix(W2nzbynz_dm, Wnzbynz_dm, Ft_dc->C[stp1i], 1.0, 0.0, 'N', 'T'); + MatrixPlusMatrixUpdate(Ptp1_t_dm, W2nzbynz_dm); + //Done with all W*_dm. + + + //--- Integrating out the state at t_2 using + //--- P(s_t_2|Y_{t_2}, theta) = ProbabilityStateConditionalCurrent(sti, t_2, smodel_ps); + //--- One can also access to P(s_t_2|Y_{t_2}, theta) by using ElementV(smodel_ps->V[t_2],s_{t_2}i), + //--- but this access will not call my function logTimetCondLH(), thus no updating for + //--- P(s_t_2|Y_{t_2}, and thus leading to incorrect results. + prob_previous_regimes = ProbabilityStateConditionalCurrent(sti, t_2, smodel_ps); + ScalarTimesVectorUpdate(ztp1_dv, prob_previous_regimes, ztp1_t_dv); + ScalarTimesMatrix(Ptp1_dm, prob_previous_regimes, Ptp1_t_dm, 1.0); + Ptp1_dm->flag = M_GE | M_SU | M_SL; + //Done with ztp1_t_dv and Ptp1_t_dm. + } + //--- Filling zt_tm1 and Pt_tm1 for next period. + z0_sdv.v = zt_tm1_dc->C[t_2p1]->M + z0_sdv.n*stp1i; //stp1i: regime at time tp1. + CopyVector0(&z0_sdv, ztp1_dv); + CopyMatrix0(Pt_tm1_d4->F[t_2p1]->C[stp1i], Ptp1_dm); //stp1i: regime at time tp1. + //Done with ztp1_dv, z0_sdv, Ptp1_dm. + } + //--- $$$ The following is important because it tells ProbabilityStateConditionalCurrent(), which calls + //--- $$$ logTimetCondLH_kalfilms_1stapp(), which calls recursively this function again, that there is no + //--- $$$ need to update Kalman filter for the period before kalfilmsinputs_1stapp_ps->ztm1_track. + kalfilmsinputs_1stapp_ps->ztm1_track = t_2p1; //Means that z_{t_2p1+1|t_2p1} and P_{t_2p1+1|t_2p1} are done. + + //--- $$$ This function must be called after all the above computations are done. + Update_et_Dt_1stapp(t_2p1, kalfilmsinputs_1stapp_ps); + } + + + //=== + DestroyMatrix_lf(Wnzbynz_dm); + // + DestroyMatrix_lf(Wnzbyny_dm); + DestroyMatrix_lf(W2nzbynz_dm); + DestroyMatrix_lf(Kt_tdata0_dm); + DestroyMatrix_lf(Kt_tdata_dm); + // + DestroyVector_lf(ztp1_t_dv); + DestroyMatrix_lf(Ptp1_t_dm); + DestroyVector_lf(ztp1_dv); + DestroyMatrix_lf(Ptp1_dm); + + return (kalfilmsinputs_1stapp_ps->ztm1_track); +} +//====================================================== +//= Computes etdata and Dtdata for all grand regimes st at tbase0=inpt-1 or dtm1_track +//= to prevent recomputing this object for different st at given tbase0. +//====================================================== +static int Update_et_Dt_1stapp(int t_1, struct TSkalfilmsinputs_1stapp_tag *kalfilmsinputs_1stapp_ps) +{ + //Output: + // dtm1_track is updated in this function. + // PHtran_tdata_d4->F[t-1] + // etdata_dc->C[t-1] + // Dtdata_d4->F[t-1] + //Input: + // t_1=inpt-1: base-0 timing for et and Dt before the likelihood at time inpt is computed. + + //--- Local variables + int sti, tbase0; + //-- Output arguments + TSdfourth *PHtran_tdata_d4 = kalfilmsinputs_1stapp_ps->PHtran_tdata_d4; //nz-by-ny-by-nst-T, saved only for updating Kalman filter Updatekalfilms_1stapp(). + TSdcell *etdata_dc = kalfilmsinputs_1stapp_ps->etdata_dc; //ny-by-nst-by-T, save for computing the likelihood. + TSdcell *yt_tm1_dc = kalfilmsinputs_1stapp_ps->yt_tm1_dc; //ny-by-nst-by-T, one-step forecast y_{t|t-1} for t=0 to T-1 (base-0). + TSdfourth *Dtdata_d4 = kalfilmsinputs_1stapp_ps->Dtdata_d4; //ny-by-ny-nst-by-T, save for computing the likelihood and updating Kalman filter Updatekalfilms_1stapp(). + //--- input arguments + TSdcell *zt_tm1_dc = kalfilmsinputs_1stapp_ps->zt_tm1_dc; //nz-by-nst-by-T. + TSdfourth *Pt_tm1_d4 = kalfilmsinputs_1stapp_ps->Pt_tm1_d4; //nz-by-nz-by-nst-by-T. + //+ + TSdmatrix *yt_dm = kalfilmsinputs_1stapp_ps->yt_dm; //ny-by-T. + TSdmatrix *at_dm = kalfilmsinputs_1stapp_ps->at_dm; //ny-by-nst. + TSdcell *Ht_dc = kalfilmsinputs_1stapp_ps->Ht_dc; //ny-by-nz-by-nst. + TSdcell *Rt_dc = kalfilmsinputs_1stapp_ps->Rt_dc; //ny-by-ny-by-nst. Covariance matrix for the measurement equation. + //--- Accessible variables + int ny = kalfilmsinputs_1stapp_ps->ny; + int nz = kalfilmsinputs_1stapp_ps->nz; + int nst = kalfilmsinputs_1stapp_ps->nst; + TSdvector z0_sdv; + TSdvector yt_sdv, at_sdv; + TSdvector etdata_sdv, yt_tm1_sdv; + //=== Work arguments. + TSdmatrix *PHtran_tdata_dm = CreateMatrix_lf(nz,ny); + TSdmatrix *Dtdata_dm = CreateMatrix_lf(ny,ny); + + + z0_sdv.n = nz; + z0_sdv.flag = V_DEF; + at_sdv.n = yt_sdv.n = ny; + at_sdv.flag = yt_sdv.flag = V_DEF; + etdata_sdv.n = yt_tm1_sdv.n = ny; + etdata_sdv.flag = yt_tm1_sdv.flag = V_DEF; + + for (tbase0=(kalfilmsinputs_1stapp_ps->dtm1_track+1); tbase0<=t_1; tbase0++) + { + //Note tbase0<=t_1, NOT tbase0<t_1. + //If t_1 < (dtm1_track+1), no updating. + //If t_1 >= (dtm1_track+1), updating etdata_dc->C[t-1] and Dtdata_d4->F[t-1] up to t-1=t_1. + + for (sti=nst-1; sti>=0; sti--) + { + //--- Setup. + MatrixTimesMatrix(PHtran_tdata_dm, Pt_tm1_d4->F[tbase0]->C[sti], Ht_dc->C[sti], 1.0, 0.0, 'N', 'T'); + CopyMatrix0(kalfilmsinputs_1stapp_ps->PHtran_tdata_d4->F[tbase0]->C[sti], PHtran_tdata_dm); + + + //--- Data. + //- etdata = Y_T(:,tdata) - a(:,tdata) - Htdata*ztdata where tdata = tbase0 = inpt-1. + yt_sdv.v = yt_dm->M + tbase0*yt_dm->nrows; + at_sdv.v = at_dm->M + sti*at_dm->nrows; //grand regime at time tbase0. + z0_sdv.v = zt_tm1_dc->C[tbase0]->M + z0_sdv.n*sti; //sti: regime at time tbase0. + etdata_sdv.v = etdata_dc->C[tbase0]->M + etdata_sdv.n*sti; + yt_tm1_sdv.v = etdata_dc->C[tbase0]->M + yt_tm1_sdv.n*sti; + CopyVector0(&yt_tm1_sdv, &at_sdv); + MatrixTimesVector(&yt_tm1_sdv, Ht_dc->C[sti], &z0_sdv, 1.0, 1.0, 'N'); //a + H*z_{t|t-1}. + VectorMinusVector(&etdata_sdv, &yt_sdv, &yt_tm1_sdv); //y_t - a - H*z_{t|t-1}. + //+ Dtdata = Htdata*PHtran_tdata + R(:,:,tbase0); + CopyMatrix0(Dtdata_dm, Rt_dc->C[sti]); + MatrixTimesMatrix(Dtdata_dm, Ht_dc->C[sti], PHtran_tdata_dm, 1.0, 1.0, 'N', 'N'); + //Done with z0_sdv.v. + ScalarTimesMatrixSquare(Dtdata_dm, 0.5, Dtdata_dm, 'T', 0.5); //Making it symmetric against some rounding errors. + //This making-symmetric is very IMPORTANT; otherwise, we will get the matrix being singular message + // and eigenvalues being negative for the SPD matrix, etc. Then the likelihood becomes either + // a bad number or a complex number. + Dtdata_dm->flag = Dtdata_dm->flag | M_SU | M_SL; + CopyMatrix0(Dtdata_d4->F[tbase0]->C[sti], Dtdata_dm); //Saved to be used for logTimetCondLH_kalfilms_1stapp(). + } + + //--- $$$ This tracker functions the same way as kalfilmsinputs_1stapp_ps->ztm1_track. + kalfilmsinputs_1stapp_ps->dtm1_track = tbase0; + } + + //=== + DestroyMatrix_lf(PHtran_tdata_dm); + DestroyMatrix_lf(Dtdata_dm); + + return (kalfilmsinputs_1stapp_ps->dtm1_track); +} + + + + + + +//----------------------------------------------------- +//------------ OLD Code -------------------------- +//- Updating or refreshing all Kalman filter at time t for Markov-switching DSGE model. +//- WARNING: make sure to call the following functions +// RunningGensys_const7varionly(lwzmodel_ps); +// Refresh_kalfilms_*(lwzmodel_ps); //Creates or refreshes kalfilmsinputs_ps at new parameter values. +//- before using tz_Refresh_z_T7P_T_in_kalfilms_1st_approx(). +// +//- IMPORTANT NOTE: in the Markov-switching input file datainp_markov*.prn, it MUST be that +//- the coefficient regime is the 1st state variable, and +//- the volatility regime is the 2nd state variable. +//----------------------------------------------------- +#if defined (NEWVERSIONofDW_SWITCH) +double tz_logTimetCondLH_kalfilms_1st_approx(int st, int inpt, struct TSkalfilmsinputs_tag *kalfilmsinputs_ps, struct TStateModel_tag *smodel_ps) +{ + //st, st_c, and st_v: base-0: deals with the cross-section values at time t where + // st is a grand regime, st_c is an encoded coefficient regime, and st_c is an encoded volatility regime. + //inpt: base-1 in the sense that inpt>=1 to deal with the time series situation where S_T is (T+1)-by-1 and Y_T is T+nlags_max-by-1. + // The 1st element for S_T is S_T[1] while S_T[0] is s_0 (initial condition). + // The 1st element for Y_T, however, is Y_T[nlags_max+1-1]. + //See (42.3) on p.42 in the SWZII NOTES. + + + //--- Local variables + int comst_c; //composite (s_tc, s_{t-1}c) + int st_c, stm1_c, st_v; + int comsti_c; //composite (s_tc, s_{t-1}c) + int sti, sti_c, stm1i_c, sti_v; + int comstp1i_c; //composite (s_{t+1}c, s_tc) + int stp1i, stp1i_c, stp1i_v; + int tbase0, tp1; + double logdet_Dtdata, loglh_timet; + static int record_tbase1_or_inpt_or_tp1 = 0; + static int passonce; + double prob_previous_regimes; + //=== Accessible variables + int ny = kalfilmsinputs_ps->ny; + int nz = kalfilmsinputs_ps->nz; + int nRc = kalfilmsinputs_ps->nRc; + int nRstc = kalfilmsinputs_ps->nRstc; + int nRv = kalfilmsinputs_ps->nRv; + int T = kalfilmsinputs_ps->T; + int indxIndRegimes = kalfilmsinputs_ps->indxIndRegimes; + int **Index = smodel_ps->sv->index; //Regime-switching states. + //smodel_ps->sv->index is for our new code. + // For old code (before 9 April 08 and before dsge_switch is created), use smodel_ps->sv->Index; + TSdvector z0_sdv; + //+ input arguments. + TSdmatrix *yt_dm = kalfilmsinputs_ps->yt_dm; //ny-by-T. + TSdmatrix *at_dm = kalfilmsinputs_ps->at_dm; //ny-by-nRc. + TSdcell *Ht_dc = kalfilmsinputs_ps->Ht_dc; //ny-by-nz-by-nRc. + TSdcell *Rt_dc = kalfilmsinputs_ps->Rt_dc; //ny-by-ny-by-nRv. Covariance matrix for the measurement equation. + TSdcell *Gt_dc = kalfilmsinputs_ps->Gt_dc; //nz-by-ny-by-nRv. Cross-covariance. + // + TSdmatrix *bt_dm = kalfilmsinputs_ps->bt_dm; //nz-by-nRc. + TSdcell *Ft_dc = kalfilmsinputs_ps->Ft_dc; //nz-by-nz-by-nRc. + TSdcell *Vt_dc = kalfilmsinputs_ps->Vt_dc; //nz-by-nz-by-nRv. Covariance matrix for the state equation. + // + TSdmatrix *z0_dm = kalfilmsinputs_ps->z0_dm; //nz-by-nRc*nRv or nz-by-nRv, depending on indxIndRegimes. + TSdcell *P0_dc = kalfilmsinputs_ps->P0_dc; //nz-by-nz-by-nRc*nRv or nz-by-nRv, depending on indxIndRegimes. + //+ Output arguments. + TSdcell *zt_tm1_dc = kalfilmsinputs_ps->zt_tm1_dc; //nz-by-nRc*nRv-by-T if indxIndRegimes==1, nz-by-nRv-by-T if indxIndRegimes==0 where nRc=nRv. + TSdfourth *Pt_tm1_d4 = kalfilmsinputs_ps->Pt_tm1_d4; //nz-by-nz-by-nRc*nRv-T if indxIndRegimes==1, nz-by-nz-by-nRv-by-T if indxIndRegimes==0 where nRc=nRv. + //=== Work arguments. + int nz2 = square(nz); + TSdmatrix *Wnzbynz_dm = CreateMatrix_lf(nz,nz); + TSdmatrix *Wnz2bynz2_dm = CreateMatrix_lf(nz2,nz2); + TSdmatrix *W2nz2bynz2_dm = CreateMatrix_lf(nz2,nz2); + TSdvector *wP0_dv = CreateVector_lf(nz2); + //+ + TSdvector yt_sdv, at_sdv, btp1_sdv; //zt_tm1_sdv, ztp1_t_sdv, + TSdvector *wny_dv = CreateVector_lf(ny); + TSdmatrix *Wnzbyny_dm = CreateMatrix_lf(nz,ny); + TSdmatrix *W2nzbynz_dm = CreateMatrix_lf(nz,nz); + TSdmatrix *PHtran_tdata_dm = CreateMatrix_lf(nz,ny); + TSdvector *etdata_dv = CreateVector_lf(ny); + TSdmatrix *Dtdata_dm = CreateMatrix_lf(ny,ny); + TSdmatrix *Kt_tdata0_dm = CreateMatrix_lf(nz,ny); + TSdmatrix *Kt_tdata_dm = CreateMatrix_lf(nz,ny); + //--- For eigenvalue decompositions + int ki; + int errflag; + double eigmax; + TSdzvector *evals_dzv = evals_dzv = CreateVector_dz(nz); + TSdvector *evals_abs_dv = CreateVector_lf(nz); //Absolute eigenvalues. + //--- For updating zt_tm1_dm and Pt_tm1. + TSdvector *ztp1_t_dv = CreateVector_lf(z0_dm->nrows); + TSdmatrix *Ptp1_t_dm = CreateMatrix_lf(nz, nz); + TSdvector *ztp1_dv = CreateVector_lf(z0_dm->nrows); + TSdmatrix *Ptp1_dm = CreateMatrix_lf(nz, nz); + + + + if (smodel_ps->sv->nstates != z0_dm->ncols) fn_DisplayError("kalman.c/tz_logTimetLH_kalfilms_1st_approx():\n" + " Make sure that the column dimension of z0_dm is the same as smodel_ps->sv->nstates"); + if (indxIndRegimes && (nRc>1) && (nRv>1)) + if (smodel_ps->sv->n_state_variables != 2) fn_DisplayError("kalman.c/tz_Refresh_z_T7P_T_in_kalfilms_1st_approx():\n" + " Number of state variables must be coincide with indxIndRegimes"); + + tbase0 = (tp1=inpt) - 1; + + z0_sdv.n = z0_dm->nrows; + z0_sdv.flag = V_DEF; + // + at_sdv.n = yt_sdv.n = yt_dm->nrows; + at_sdv.flag = yt_sdv.flag = V_DEF; + btp1_sdv.n = bt_dm->nrows; + btp1_sdv.flag = V_DEF; + + + //======= Initial condition. ======= + if (tbase0==0) + { + for (sti=smodel_ps->sv->nstates-1; sti>=0; sti--) + { + if (indxIndRegimes) + { + if (nRc==1) //Volatility. + { + comsti_c = sti_c = 0; + sti_v = sti; + } + else if ((nRv>1) && (nRc>nRstc)) //Trend inflation, both sc_t and sc_{t-1} enters coefficient regime. + { + comsti_c = Index[sti][0]; //composite (s_tc, s_{t-1}c) + sti_v = Index[sti][1]; //volatility state s_tv + sti_c = smodel_ps->sv->state_variable[0]->lag_index[comsti_c][0]; //coefficient regime at t. + stm1i_c = smodel_ps->sv->state_variable[0]->lag_index[comsti_c][1]; //coefficient regime at t-1: tm1: t-1; + } + else if ((nRv==1) && (nRc>nRstc)) + { + comsti_c = Index[sti][0]; //composite (s_tc, s_{t-1}c) + sti_c = smodel_ps->sv->state_variable[0]->lag_index[comsti_c][0]; //coefficient regime at t. + stm1i_c = smodel_ps->sv->state_variable[0]->lag_index[comsti_c][1]; //coefficient regime at t-1: tm1: t-1; + sti_v = 0; + } + else if ((nRv==1) && (nRc==nRstc)) + { + comsti_c = sti_c = sti; + sti_v = 0; + } + else if ((nRv>1) && (nRc==nRstc)) //only sc_t enters coefficient regime. + { + comsti_c = sti_c = Index[sti][0]; + sti_v = Index[sti][1]; + } + } + else //Syncronized regimes. + { + if (nRc>nRstc) + { + comsti_c = Index[sti][0]; //composite (s_tc, s_{t-1}c) + sti_c = smodel_ps->sv->state_variable[0]->lag_index[comsti_c][0]; //coefficient regime at t. + stm1i_c = smodel_ps->sv->state_variable[0]->lag_index[comsti_c][1]; //coefficient regime at t-1: tm1: t-1; + sti_v = sti_c; + } + else + comsti_c = sti_c = sti_v = sti; + } + + + if (!kalfilmsinputs_ps->indxIni) + { + InitializeDiagonalMatrix_lf(Wnzbynz_dm, 1.0); //To be used for I(nz) - + InitializeDiagonalMatrix_lf(Wnz2bynz2_dm, 1.0); //To be used for I(nz2) - + + //=== Eigenanalysis to determine the roots to ensure boundedness. + errflag = eigrgen(evals_dzv, (TSdzmatrix *)NULL, (TSdzmatrix *)NULL, Ft_dc->C[comsti_c]); + if (errflag) fn_DisplayError("kalman.c/tz_Refresh_z_T7P_T_in_kalfilms_1st_approx(): eigen decomposition failed"); + for (ki=nz-1; ki>=0; ki--) evals_abs_dv->v[ki] = sqrt(square(evals_dzv->real->v[ki]) + square(evals_dzv->imag->v[ki])); + evals_abs_dv->flag = V_DEF; + eigmax = MaxVector(evals_abs_dv); + if (eigmax < (1.0+1.0e-14)) + { + //--- Getting z0_dv: zt_tm1(:,1) = (eye(n_z)-F(:,:,1))\b(:,1); + MatrixMinusMatrix(Wnzbynz_dm, Wnzbynz_dm, Ft_dc->C[comsti_c]); + z0_sdv.v = z0_dm->M + z0_sdv.n*sti; + CopySubmatrix2vector(&z0_sdv, 0, bt_dm, 0, comsti_c, bt_dm->nrows); + bdivA_rgens(&z0_sdv, &z0_sdv, '\\', Wnzbynz_dm); + //Done with Wnzbynz_dm. + //--- Getting P0_dm: Pt_tm1(:,:,1) = reshape((eye(n_z^2)-kron(F(:,:,1),F(:,:,1)))\V1(:),n_z,n_z); + tz_kron(W2nz2bynz2_dm, Ft_dc->C[comsti_c], Ft_dc->C[comsti_c]); + MatrixMinusMatrix(Wnz2bynz2_dm, Wnz2bynz2_dm, W2nz2bynz2_dm); + CopySubmatrix2vector(wP0_dv, 0, Vt_dc->C[sti_v], 0, 0, nz2); +//=== ???????? For debugging purpose. +//if ((inpt<2) && (st==0)) +//{ +// fprintf(FPTR_DEBUG, "%%st=%d, inpt=%d, and sti=%d\n", st, inpt, sti); + +// fprintf(FPTR_DEBUG, "wP0_dv:\n"); +// WriteVector(FPTR_DEBUG, wP0_dv, " %10.5f "); +// fprintf(FPTR_DEBUG, "Vt_dc->C[sti_v=%d]:\n", sti_v); +// WriteMatrix(FPTR_DEBUG, Vt_dc->C[sti_v], " %10.5f "); + +// fflush(FPTR_DEBUG); + +//} + bdivA_rgens(wP0_dv, wP0_dv, '\\', Wnz2bynz2_dm); + CopySubvector2matrix_unr(P0_dc->C[sti], 0, 0, wP0_dv, 0, nz2); + //Done with all w*_dv and W*_dm. + } + else + { + fprintf(stdout, "\n-----------------\n"); + fprintf(stdout, "\nIn regime comsti_c=%d and sti_v=%d and at time=%d\n", comsti_c, sti_v, 0); + fn_DisplayError("kalman.c/tz_Refresh_z_T7P_T_in_kalfilms_1st_approx(): the system is non-stationary solutions\n" + " and the initial conditions must be supplied by, say, input arguments"); + fflush(stdout); + } + } + } + z0_dm->flag = M_GE; + CopyMatrix0(zt_tm1_dc->C[0], z0_dm); //At time t=0. + CopyCell0(Pt_tm1_d4->F[0], P0_dc); //At time t=0. + } + + + //====================================================== + //= Getting the logLH at time tbase0 or time inpt. + //====================================================== + if (indxIndRegimes ) + { + if (nRc==1) //Volatility. + { + comst_c = st_c = 0; + st_v = st; + } + else if ((nRv>1) && (nRc>nRstc)) //Trend inflation, both sc_t and sc_{t-1} enters coefficient regime. + { + if (smodel_ps->sv->n_state_variables != 2) fn_DisplayError("kalman.c/kalfilms_timet_1st_approx():\n" + " Number of state variables must be coincide with indxIndRegimes"); + + comst_c = Index[st][0]; //composite (s_tc, s_{t-1}c) + st_v = Index[st][1]; //volatility state s_tv + st_c = smodel_ps->sv->state_variable[0]->lag_index[comst_c][0]; //coefficient regime at t. + stm1_c = smodel_ps->sv->state_variable[0]->lag_index[comst_c][1]; //coefficient regime at t-1: tm1: t-1; + } + else if ((nRv==1) && (nRc>nRstc)) + { + comst_c = Index[st][0]; //composite (s_tc, s_{t-1}c) + st_c = smodel_ps->sv->state_variable[0]->lag_index[comst_c][0]; //coefficient regime at t. + stm1_c = smodel_ps->sv->state_variable[0]->lag_index[comst_c][1]; //coefficient regime at t-1: tm1: t-1; + st_v = 0; + } + else if ((nRv==1) && (nRc==nRstc)) + { + comst_c = st_c = st; + st_v = 0; + } + else if ((nRv>1) && (nRc==nRstc)) //only sc_t enters coefficient regime. + { + if (smodel_ps->sv->n_state_variables != 2) fn_DisplayError("kalman.c/kalfilms_timet_1st_approx():\n" + " Number of state variables must be coincide with indxIndRegimes"); + + comst_c = st_c = Index[st][0]; + st_v = Index[st][1]; + } + } + else //Syncronized regimes + { + if (nRc>nRstc) + { + comst_c = Index[st][0]; //composite (s_tc, s_{t-1}c) + st_c = smodel_ps->sv->state_variable[0]->lag_index[comst_c][0]; //coefficient regime at t. + stm1_c = smodel_ps->sv->state_variable[0]->lag_index[comst_c][1]; //coefficient regime at t-1: tm1: t-1; + st_v = st_c; + } + else + comst_c = st_c = st_v = st; + } + + + z0_sdv.n = zt_tm1_dc->C[0]->nrows; + z0_sdv.flag = V_DEF; + // + at_sdv.n = yt_sdv.n = yt_dm->nrows; + at_sdv.flag = yt_sdv.flag = V_DEF; + + //====== Computing the conditional LH at time t. ====== + //--- Setup. + MatrixTimesMatrix(PHtran_tdata_dm, Pt_tm1_d4->F[tbase0]->C[st], Ht_dc->C[comst_c], 1.0, 0.0, 'N', 'T'); + + //--- Data. + //- etdata = Y_T(:,tdata) - a(:,tdata) - Htdata*ztdata where tdata = tbase0 = inpt-1. + yt_sdv.v = yt_dm->M + tbase0*yt_dm->nrows; + at_sdv.v = at_dm->M + comst_c*at_dm->nrows; //comst_c: coefficient regime at time tbase0. + z0_sdv.v = zt_tm1_dc->C[tbase0]->M + z0_sdv.n*st; //st: regime at time tbase0 for zt_tm1. + VectorMinusVector(etdata_dv, &yt_sdv, &at_sdv); + MatrixTimesVector(etdata_dv, Ht_dc->C[comst_c], &z0_sdv, -1.0, 1.0, 'N'); + //+ Dtdata = Htdata*PHtran_tdata + R(:,:,tbase0); + CopyMatrix0(Dtdata_dm, Rt_dc->C[st_v]); + MatrixTimesMatrix(Dtdata_dm, Ht_dc->C[comst_c], PHtran_tdata_dm, 1.0, 1.0, 'N', 'N'); + ScalarTimesMatrixSquare(Dtdata_dm, 0.5, Dtdata_dm, 'T', 0.5); //Making it symmetric against some rounding errors. + //This making-symmetric is very IMPORTANT; otherwise, we will get the matrix being singular message + // and eigenvalues being negative for the SPD matrix, etc. Then the likelihood becomes either + // a bad number or a complex number. + Dtdata_dm->flag = Dtdata_dm->flag | M_SU | M_SL; + + + //--- Forming the log conditional likelihood at t. + if (!isfinite(logdet_Dtdata=logdetspd(Dtdata_dm))) return (loglh_timet = -NEARINFINITY); + bdivA_rgens(wny_dv, etdata_dv, '/', Dtdata_dm); +//if ((inpt>82) && (inpt<86) ) +//{ +// //Must be declared at the top of this "if" block. +// int kip1; +// double tmp_Dtdata; +// double tmp_expterm; + +// fprintf(FPTR_DEBUG, "%%------------------------\n"); +// fprintf(FPTR_DEBUG, "%%st=%d and inpt=%d\n", st, inpt); +// fprintf(FPTR_DEBUG, "loglh_timet = %10.5f;\n", loglh_timet); + + +// fprintf(FPTR_DEBUG, "wny_dv:\n"); +// WriteVector(FPTR_DEBUG, wny_dv, " %10.5f "); +// fprintf(FPTR_DEBUG, "etdata_dv:\n"); +// WriteVector(FPTR_DEBUG, etdata_dv, " %10.5f "); +// fprintf(FPTR_DEBUG, "Dtdata_dm:\n"); +// WriteMatrix(FPTR_DEBUG, Dtdata_dm, " %.16e "); + +// fflush(FPTR_DEBUG); +//} + loglh_timet = -(0.5*ny)*LOG2PI - 0.5*logdet_Dtdata - 0.5*VectorDotVector(wny_dv, etdata_dv); + //Done with all w*_dv. + + + + +//=== ???????? For debugging purpose. +if (inpt==1) +{ + double wk1, wk2; + + wk1 = logdet_Dtdata; + wk2 = VectorDotVector(wny_dv, etdata_dv); + fprintf(FPTR_DEBUG, "logdet_Dtdata = %10.5f\n", wk1); + fprintf(FPTR_DEBUG, "VectorDotVector(wny_dv, etdata_dv) = %10.5f\n", wk2); + fprintf(FPTR_DEBUG, "----- etdata_dv: \n"); + WriteVector(FPTR_DEBUG, etdata_dv, " %10.5f "); + fprintf(FPTR_DEBUG, "----- yt_dv: \n"); + WriteVector(FPTR_DEBUG, &yt_sdv, " %10.5f "); + fprintf(FPTR_DEBUG, "----- at_dv: \n"); + WriteVector(FPTR_DEBUG, &at_sdv, " %10.5f "); + fprintf(FPTR_DEBUG, "----- z0_dv: \n"); + WriteVector(FPTR_DEBUG, &z0_sdv, " %10.5f "); + fprintf(FPTR_DEBUG, "----- Ht_dc->C[comst_c=%d]:\n", comst_c); + WriteMatrix(FPTR_DEBUG, Ht_dc->C[comst_c], " %10.5f "); + + fprintf(FPTR_DEBUG, "\n\n"); + +} +// +fprintf(FPTR_DEBUG, " %10.5f\n", loglh_timet); +fflush(FPTR_DEBUG); + + +//=== ???????? For debugging purpose. +//fprintf(FPTR_DEBUG, "------------------------\n"); +//fprintf(FPTR_DEBUG, "st=%d and inpt=%d\n", st, inpt); +//fprintf(FPTR_DEBUG, "loglh_timet = %10.5f\n", loglh_timet); +//fprintf(FPTR_DEBUG, "&yt_sdv:\n"); +//WriteVector(FPTR_DEBUG, &yt_sdv, " %10.5f "); +////WriteVector(FPTR_DEBUG, etdata_dv, " %10.5f "); +////fprintf(FPTR_DEBUG, "\n"); +////WriteMatrix(FPTR_DEBUG, Dtdata_dm, " %10.5f "); +//fflush(FPTR_DEBUG); + + +//=== ???????? For debugging purpose. +//if ((inpt>82) && (inpt<86) ) +//if (inpt<2) +//{ +// //Must be declared at the top of this "if" block. +// int kip1; +// double tmp_Dtdata; +// double tmp_expterm; + +// fprintf(FPTR_DEBUG, "%%------------------------\n"); +// fprintf(FPTR_DEBUG, "%%st=%d and inpt=%d\n", st, inpt); +// fprintf(FPTR_DEBUG, "loglh_timet = %10.5f;\n", loglh_timet); + + +// tmp_Dtdata = logdeterminant(Dtdata_dm); +// tmp_expterm = VectorDotVector(wny_dv, etdata_dv); +// fprintf(FPTR_DEBUG, "logdeterminant(Dtdata_dm) = %10.5f;\n", tmp_Dtdata); +// fprintf(FPTR_DEBUG, "VectorDotVector(wny_dv, etdata_dv) = %10.5f;\n", tmp_expterm); +// fprintf(FPTR_DEBUG, "wny_dv:\n"); +// WriteVector(FPTR_DEBUG, wny_dv, " %10.5f "); +// fprintf(FPTR_DEBUG, "etdata_dv:\n"); +// WriteVector(FPTR_DEBUG, etdata_dv, " %10.5f "); +// fprintf(FPTR_DEBUG, "&yt_sdv:\n"); +// WriteVector(FPTR_DEBUG, &yt_sdv, " %10.5f "); +// fprintf(FPTR_DEBUG, "&at_sdv:\n"); +// WriteVector(FPTR_DEBUG, &at_sdv, " %10.5f "); +// fprintf(FPTR_DEBUG, "&z0_sdv:\n"); +// WriteVector(FPTR_DEBUG, &z0_sdv, " %10.5f "); +// fprintf(FPTR_DEBUG, "Ht_dc->C[comst_c=%d]:\n",comst_c); +// WriteMatrix(FPTR_DEBUG, Ht_dc->C[comst_c], " %10.5f "); +// fprintf(FPTR_DEBUG, "Rt_dc->C[st_v=%d]:\n", st_v); +// WriteMatrix(FPTR_DEBUG, Rt_dc->C[st_v], " %10.5f "); +// fprintf(FPTR_DEBUG, "Pt_tm1_d4->F[tbase0]->C[st = %d]:\n",st); +// WriteMatrix(FPTR_DEBUG, Pt_tm1_d4->F[tbase0]->C[st], " %10.5f "); +// fprintf(FPTR_DEBUG, "Dtdata_dm:\n"); +// WriteMatrix(FPTR_DEBUG, Dtdata_dm, " %10.5f "); + + + + +//// WriteMatrix(FPTR_DEBUG, Dtdata_dm, " %10.5f "); +//// fprintf(FPTR_DEBUG, "zt_tm1_dc->C[tbase0]:\n"); +//// WriteMatrix(FPTR_DEBUG, zt_tm1_dc->C[tbase0], " %10.5f "); +//// //WriteVector(FPTR_DEBUG, &z0_sdv, " %10.5f "); +//// //fprintf(FPTR_DEBUG, "\n"); +//// fprintf(FPTR_DEBUG, "bt_dm = [\n"); +//// WriteMatrix(FPTR_DEBUG, bt_dm, " %10.5f "); +//// fprintf(FPTR_DEBUG, "];\n"); + +//// fprintf(FPTR_DEBUG, "et:\n"); +//// WriteVector(FPTR_DEBUG, etdata_dv, " %10.5f "); +//// fprintf(FPTR_DEBUG, "yt_dv=[\n"); +//// WriteVector(FPTR_DEBUG, &yt_sdv, " %10.5f "); +//// fprintf(FPTR_DEBUG, "]';\n"); + +//// fprintf(FPTR_DEBUG, "at_dv=[\n"); +//// WriteVector(FPTR_DEBUG, &at_sdv, " %10.5f "); +//// fprintf(FPTR_DEBUG, "]';\n"); + + +//// for (ki=0; ki<Ht_dc->ncells; ki++) +//// { +//// kip1 = ki+1; +//// fprintf(FPTR_DEBUG, "Ht_dc(:,:,%d)=[\n", kip1); +//// WriteMatrix(FPTR_DEBUG, Ht_dc->C[ki], " %10.5f "); +//// fprintf(FPTR_DEBUG, "];\n"); +//// } +//// for (ki=0; ki<Ft_dc->ncells; ki++) +//// { +//// kip1 = ki+1; +//// fprintf(FPTR_DEBUG, "Ft_dc(:,:,%d)=[\n", kip1); +//// WriteMatrix(FPTR_DEBUG, Ft_dc->C[ki], " %10.5f "); +//// fprintf(FPTR_DEBUG, "];\n"); +//// } +//// for (ki=0; ki<Vt_dc->ncells; ki++) +//// { +//// kip1 = ki+1; +//// fprintf(FPTR_DEBUG, "Vt_dc(:,:,%d)=[\n", kip1); +//// WriteMatrix(FPTR_DEBUG, Vt_dc->C[ki], " %10.5f "); +//// fprintf(FPTR_DEBUG, "];\n"); +//// } +// fflush(FPTR_DEBUG); +//} + + + //====================================================== + //= Updating zt_tm1 and Pt_tm1 for next perid tp1. + //= tdata = tbase0 is base-0 timing. + //====================================================== + if (inpt > record_tbase1_or_inpt_or_tp1) //This condition always satisfies at the 1st period (which is inpt=1). + { + passonce = 0; + record_tbase1_or_inpt_or_tp1 = inpt; + } + if (!passonce) + { + for (stp1i=smodel_ps->sv->nstates-1; stp1i>=0; stp1i--) + { + if (indxIndRegimes) + { + if (nRc==1) //Volatility. + { + comstp1i_c = stp1i_c = 0; + stp1i_v = stp1i; + } + else if ((nRv>1) && (nRc>nRstc)) //Trend inflation, both sc_t and sc_{t-1} enters coefficient regime. + { + comstp1i_c = Index[stp1i][0]; //composite (s_tc, s_{t-1}c) + stp1i_v = Index[stp1i][1]; //volatility state s_tv + stp1i_c = smodel_ps->sv->state_variable[0]->lag_index[comstp1i_c][0]; //coefficient regime at t. + //sti_c = smodel_ps->sv->state_variable[0]->lag_index[comstp1i_c][1]; //coefficient regime at t-1: tm1: t-1; + } + else if ((nRv==1) && (nRc>nRstc)) + { + comstp1i_c = Index[stp1i][0]; //composite (s_tc, s_{t-1}c) + stp1i_c = smodel_ps->sv->state_variable[0]->lag_index[comstp1i_c][0]; //coefficient regime at t. + //sti_c = smodel_ps->sv->state_variable[0]->lag_index[comstp1i_c][1]; //coefficient regime at t-1: tm1: t-1; + stp1i_v = 0; + } + else if ((nRv==1) && (nRc==nRstc)) + { + comstp1i_c = stp1i_c = stp1i; + stp1i_v = 0; + } + else if ((nRv>1) && (nRc==nRstc)) //only sc_t enters coefficient regime. + { + comstp1i_c = stp1i_c = Index[stp1i][0]; + stp1i_v = Index[stp1i][1]; + } + } + else //Syncronized regimes. + { + if (nRc>nRstc) + { + comstp1i_c = Index[stp1i][0]; //composite (s_tc, s_{t-1}c) + stp1i_c = smodel_ps->sv->state_variable[0]->lag_index[comstp1i_c][0]; //coefficient regime at t. + //sti_c = smodel_ps->sv->state_variable[0]->lag_index[comstp1i_c][1]; //coefficient regime at t-1: tm1: t-1; + stp1i_v = stp1i_c; + } + else + comstp1i_c = stp1i_c = stp1i_v = stp1i; + } + + + InitializeConstantVector_lf(ztp1_dv, 0.0); //To be summed over sti. + InitializeConstantMatrix_lf(Ptp1_dm, 0.0); //To be summed over sti. + + for (sti=smodel_ps->sv->nstates-1; sti>=0; sti--) + { + if (indxIndRegimes) + { + if (nRc==1) //Volatility. + { + comsti_c = sti_c = 0; + sti_v = sti; + } + else if ((nRv>1) && (nRc>nRstc)) //Trend inflation, both sc_t and sc_{t-1} enters coefficient regime. + { + comsti_c = Index[sti][0]; //composite (s_tc, s_{t-1}c) + sti_v = Index[sti][1]; //volatility state s_tv + sti_c = smodel_ps->sv->state_variable[0]->lag_index[comsti_c][0]; //coefficient regime at t. + stm1i_c = smodel_ps->sv->state_variable[0]->lag_index[comsti_c][1]; //coefficient regime at t-1: tm1: t-1; + } + else if ((nRv==1) && (nRc>nRstc)) + { + comsti_c = Index[sti][0]; //composite (s_tc, s_{t-1}c) + sti_c = smodel_ps->sv->state_variable[0]->lag_index[comsti_c][0]; //coefficient regime at t. + stm1i_c = smodel_ps->sv->state_variable[0]->lag_index[comsti_c][1]; //coefficient regime at t-1: tm1: t-1; + sti_v = 0; + } + else if ((nRv==1) && (nRc==nRstc)) + { + comsti_c = sti_c = sti; + sti_v = 0; + } + else if ((nRv>1) && (nRc==nRstc)) //only sc_t enters coefficient regime. + { + comsti_c = sti_c = Index[sti][0]; + sti_v = Index[sti][1]; + } + } + else //Syncronized regimes. + { + if (nRc>nRstc) + { + comsti_c = Index[sti][0]; //composite (s_tc, s_{t-1}c) + sti_c = smodel_ps->sv->state_variable[0]->lag_index[comsti_c][0]; //coefficient regime at t. + stm1i_c = smodel_ps->sv->state_variable[0]->lag_index[comsti_c][1]; //coefficient regime at t-1: tm1: t-1; + sti_v = sti_c; + } + else + comsti_c = sti_c = sti_v = sti; + } + + + //--- Setup. + MatrixTimesMatrix(PHtran_tdata_dm, Pt_tm1_d4->F[tbase0]->C[sti], Ht_dc->C[comsti_c], 1.0, 0.0, 'N', 'T'); + + //--- Data. + //- etdata = Y_T(:,tdata) - a(:,tdata) - Htdata*ztdata where tdata = tbase0 = inpt-1. + yt_sdv.v = yt_dm->M + tbase0*yt_dm->nrows; + at_sdv.v = at_dm->M + comsti_c*at_dm->nrows; //comsti_c: coefficient regime at time tbase0. + z0_sdv.v = zt_tm1_dc->C[tbase0]->M + z0_sdv.n*sti; //sti: regime at time tbase0. + VectorMinusVector(etdata_dv, &yt_sdv, &at_sdv); + MatrixTimesVector(etdata_dv, Ht_dc->C[comsti_c], &z0_sdv, -1.0, 1.0, 'N'); + //+ Dtdata = Htdata*PHtran_tdata + R(:,:,tbase0); + CopyMatrix0(Dtdata_dm, Rt_dc->C[sti_v]); + MatrixTimesMatrix(Dtdata_dm, Ht_dc->C[comsti_c], PHtran_tdata_dm, 1.0, 1.0, 'N', 'N'); + //Done with z0_sdv.v. + ScalarTimesMatrixSquare(Dtdata_dm, 0.5, Dtdata_dm, 'T', 0.5); //Making it symmetric against some rounding errors. + //This making-symmetric is very IMPORTANT; otherwise, we will get the matrix being singular message + // and eigenvalues being negative for the SPD matrix, etc. Then the likelihood becomes either + // a bad number or a complex number. + Dtdata_dm->flag = Dtdata_dm->flag | M_SU | M_SL; + + + //=== Updating for next period by integrating out sti.. + if (tp1<T) + { + //Updating only up to tbase0=T-2. The values at tp1=T or tbase0=T-1 will not be used in the likelihood function. + + //--- Ktp1_t = (F_tp1*PHtran_t+G(:,:,t))/Dt; + //--- Kt_tdata = (Ft*PHtran_tdata+G(:,:,tdata))/Dtdata where t=tp1 and tdata=t. + CopyMatrix0(Kt_tdata0_dm, Gt_dc->C[sti_v]); + MatrixTimesMatrix(Kt_tdata0_dm, Ft_dc->C[stp1i_c], PHtran_tdata_dm, 1.0, 1.0, 'N', 'N'); + BdivA_rrect(Kt_tdata_dm, Kt_tdata0_dm, '/', Dtdata_dm); + //+ zt_tm1(:,t) = b(:,t) + Ft*zt_tm1(:,tdata) + Kt_tdata*etdata where t=tp1 and tm1=t. + MatrixTimesVector(ztp1_t_dv, Ft_dc->C[stp1i_c], &z0_sdv, 1.0, 0.0, 'N'); + MatrixTimesVector(ztp1_t_dv, Kt_tdata_dm, etdata_dv, 1.0, 1.0, 'N'); + btp1_sdv.v = bt_dm->M + stp1i_c*btp1_sdv.n; + VectorPlusMinusVectorUpdate(ztp1_t_dv, &btp1_sdv, 1.0); + //+ Pt_tm1(:,:,t) = Ft*Ptdata*Fttran - Kt_tdata*Dtdata*Kt_tdatatran + V(:,:,t); + CopyMatrix0(Ptp1_t_dm, Vt_dc->C[stp1i_v]); + MatrixTimesMatrix(Wnzbyny_dm, Kt_tdata_dm, Dtdata_dm, 1.0, 0.0, 'N', 'N'); + MatrixTimesMatrix(Wnzbynz_dm, Wnzbyny_dm, Kt_tdata_dm, 1.0, 0.0, 'N', 'T'); + MatrixPlusMinusMatrixUpdate(Ptp1_t_dm, Wnzbynz_dm, -1.0); + //Done with all W*_dm. + MatrixTimesMatrix(Wnzbynz_dm, Ft_dc->C[stp1i_c], Pt_tm1_d4->F[tbase0]->C[sti], 1.0, 0.0, 'N', 'N'); + MatrixTimesMatrix(W2nzbynz_dm, Wnzbynz_dm, Ft_dc->C[stp1i_c], 1.0, 0.0, 'N', 'T'); + MatrixPlusMatrixUpdate(Ptp1_t_dm, W2nzbynz_dm); + //Done with all W*_dm. + + //--- Integrating out the state at tbase0 using P(s_t|Y_{t-1}, theta) = ElementV(smodel_ps->Z[inpt],s_{inpt}_i). + //--- Note tbase0 = inpt-1 because the data in DW code (ElementV) is base-1. + //--- Note at this point, we cannot access to P(s_t|Y_t, theta) = ElementV(smodel_ps->V[inpt],s_{inpt}_i) + //--- through DW's code. But we can modify my own code to do this later. + prob_previous_regimes = ElementV(smodel_ps->Z[inpt],sti); + ScalarTimesVectorUpdate(ztp1_dv, prob_previous_regimes, ztp1_t_dv); + ScalarTimesMatrix(Ptp1_dm, prob_previous_regimes, Ptp1_t_dm, 1.0); + Ptp1_dm->flag = M_GE | M_SU | M_SL; + //Done with ztp1_t_dv and Ptp1_t_dm. + } + } + //--- Filling zt_tm1 and Pt_tm1 for next period + if (tp1<T) + { + z0_sdv.v = zt_tm1_dc->C[tp1]->M + z0_sdv.n*stp1i; //stp1i: regime at time tp1. + CopyVector0(&z0_sdv, ztp1_dv); + CopyMatrix0(Pt_tm1_d4->F[tp1]->C[stp1i], Ptp1_dm); //stp1i: regime at time tp1. + //Done with ztp1_dv, z0_sdv, Ptp1_dm. + } + } + if (tp1<T) + zt_tm1_dc->C[tp1]->flag = M_GE; + } + + +//=== ???????? For debugging purpose. +//if ((inpt>60) && (inpt<65) ) //if (inpt<5) +//{ +// int kip1; //Must be declared at the top of this "if" block. + +// fprintf(FPTR_DEBUG, "zt_tm1t=[\n"); +// WriteMatrix(FPTR_DEBUG, zt_tm1_dc->C[tbase0], " %10.5f "); +// fprintf(FPTR_DEBUG, "];\n"); + +// for (ki=0; ki<Pt_tm1_d4->F[tbase0]->ncells; ki++) +// { +// kip1 = ki+1; +// fprintf(FPTR_DEBUG, "Pt_tm1_d4t(:,:,%d)=[\n", kip1); +// WriteMatrix(FPTR_DEBUG, Pt_tm1_d4->F[tbase0]->C[ki], " %10.5f "); +// fprintf(FPTR_DEBUG, "];\n"); +// } + +// fflush(FPTR_DEBUG); +//} + + +//=== ???????? For debugging purpose. +fprintf(FPTR_DEBUG, " loglh_timet = %10.5f\n", loglh_timet); +fflush(FPTR_DEBUG); + + + //=== + DestroyVector_dz(evals_dzv); + DestroyVector_lf(evals_abs_dv); + DestroyMatrix_lf(Wnzbynz_dm); + DestroyMatrix_lf(Wnz2bynz2_dm); + DestroyMatrix_lf(W2nz2bynz2_dm); + DestroyVector_lf(wP0_dv); + // + DestroyVector_lf(wny_dv); + DestroyMatrix_lf(Wnzbyny_dm); + DestroyMatrix_lf(W2nzbynz_dm); + DestroyMatrix_lf(PHtran_tdata_dm); + DestroyVector_lf(etdata_dv); + DestroyMatrix_lf(Dtdata_dm); + DestroyMatrix_lf(Kt_tdata0_dm); + DestroyMatrix_lf(Kt_tdata_dm); + // + DestroyVector_lf(ztp1_t_dv); + DestroyMatrix_lf(Ptp1_t_dm); + DestroyVector_lf(ztp1_dv); + DestroyMatrix_lf(Ptp1_dm); + + return (loglh_timet); +} +#undef LOG2PI +#endif + + +/** +//---------------------------------------------------------------- +//-- Tested OK, but has not use because tz_Refresh_z_T7P_T_in_kalfilms_1st_approx() +//-- cannot access to ElementV(smodel_ps->V[tp1],sti) or ElementV(smodel_ps->V[tbase0],sti) +//-- because no likelihood has been formed at all before this function is called. +//---------------------------------------------------------------- +#define LOG2PI (1.837877066409345e+000) //log(2*pi) +//----------------------------------------------------- +//- Updating or refreshing all Kalman filter at time t for Markov-switching DSGE model. +//- WARNING: make sure to call the following functions +// RunningGensys_const7varionly(lwzmodel_ps); +// Refresh_kalfilms_*(lwzmodel_ps); //Creates or refreshes kalfilmsinputs_ps at new parameter values. +//- before using tz_Refresh_z_T7P_T_in_kalfilms_1st_approx(). +//----------------------------------------------------- +void tz_Refresh_z_T7P_T_in_kalfilms_1st_approx(struct TSkalfilmsinputs_tag *kalfilmsinputs_ps, struct TStateModel_tag *smodel_ps) +{ + double debug1; + //--- Local variables + int stp1i, stp1i_c, stp1i_v, sti, sti_c, sti_v, tbase0, tp1; + //=== Accessible variables + int ny = kalfilmsinputs_ps->ny; + int nz = kalfilmsinputs_ps->nz; + int nRc = kalfilmsinputs_ps->nRc; + int nRv = kalfilmsinputs_ps->nRv; + int T = kalfilmsinputs_ps->T; + int indxIndRegimes = kalfilmsinputs_ps->indxIndRegimes; + TSdvector z0_sdv; + //+ input arguments. + TSdmatrix *yt_dm = kalfilmsinputs_ps->yt_dm; //ny-by-T. + TSdmatrix *at_dm = kalfilmsinputs_ps->at_dm; //ny-by-nRc. + TSdcell *Ht_dc = kalfilmsinputs_ps->Ht_dc; //ny-by-nz-by-nRc. + TSdcell *Rt_dc = kalfilmsinputs_ps->Rt_dc; //ny-by-ny-by-nRv. Covariance matrix for the measurement equation. + TSdcell *Gt_dc = kalfilmsinputs_ps->Gt_dc; //nz-by-ny-by-nRv. Cross-covariance. + // + TSdmatrix *bt_dm = kalfilmsinputs_ps->bt_dm; //nz-by-nRc. + TSdcell *Ft_dc = kalfilmsinputs_ps->Ft_dc; //nz-by-nz-by-nRc. + TSdcell *Vt_dc = kalfilmsinputs_ps->Vt_dc; //nz-by-nz-by-nRv. Covariance matrix for the state equation. + // + TSdmatrix *z0_dm = kalfilmsinputs_ps->z0_dm; //nz-by-nRc*nRv or nz-by-nRv, depending on indxIndRegimes. + TSdcell *P0_dc = kalfilmsinputs_ps->P0_dc; //nz-by-nz-by-nRc*nRv or nz-by-nRv, depending on indxIndRegimes. + //+ Output arguments. + TSdcell *zt_tm1_dc = kalfilmsinputs_ps->zt_tm1_dc; //nz-by-nRc*nRv-by-T if indxIndRegimes==1, nz-by-nRv-by-T if indxIndRegimes==0 where nRc=nRv. + TSdfourth *Pt_tm1_d4 = kalfilmsinputs_ps->Pt_tm1_d4; //nz-by-nz-by-nRc*nRv-T if indxIndRegimes==1, nz-by-nz-by-nRv-by-T if indxIndRegimes==0 where nRc=nRv. + //=== Work arguments. + int nz2 = square(nz); + TSdmatrix *Wnzbynz_dm = CreateMatrix_lf(nz,nz); + TSdmatrix *Wnz2bynz2_dm = CreateMatrix_lf(nz2,nz2); + TSdmatrix *W2nz2bynz2_dm = CreateMatrix_lf(nz2,nz2); + TSdvector *wP0_dv = CreateVector_lf(nz2); + //+ + TSdvector yt_sdv, at_sdv, btp1_sdv; //zt_tm1_sdv, ztp1_t_sdv, + TSdvector *wny_dv = CreateVector_lf(ny); + TSdmatrix *Wnzbyny_dm = CreateMatrix_lf(nz,ny); + TSdmatrix *W2nzbynz_dm = CreateMatrix_lf(nz,nz); + TSdmatrix *PHtran_tdata_dm = CreateMatrix_lf(nz,ny); + TSdvector *etdata_dv = CreateVector_lf(ny); + TSdmatrix *Dtdata_dm = CreateMatrix_lf(ny,ny); + TSdmatrix *Kt_tdata0_dm = CreateMatrix_lf(nz,ny); + TSdmatrix *Kt_tdata_dm = CreateMatrix_lf(nz,ny); + //--- For eigenvalue decompositions + int ki; + int errflag; + double eigmax; + TSdzvector *evals_dzv = evals_dzv = CreateVector_dz(nz); + TSdvector *evals_abs_dv = CreateVector_lf(nz); //Absolute eigenvalues. + //--- For updating zt_tm1_dm and Pt_tm1. + TSdvector *ztp1_t_dv = CreateVector_lf(z0_dm->nrows); + TSdmatrix *Ptp1_t_dm = CreateMatrix_lf(nz, nz); + TSdvector *ztp1_dv = CreateVector_lf(z0_dm->nrows); + TSdmatrix *Ptp1_dm = CreateMatrix_lf(nz, nz); + + + if (smodel_ps->sv->nstates != z0_dm->ncols) fn_DisplayError("kalman.c/tz_Refresh_z_T7P_T_in_kalfilms_1st_approx():\n" + " Make sure that the column dimension of z0_dm is the same as smodel_ps->sv->nstates"); + if (indxIndRegimes && (nRc>1) && (nRv>1)) + if (smodel_ps->sv->n_state_variables != 2) fn_DisplayError("kalman.c/tz_Refresh_z_T7P_T_in_kalfilms_1st_approx():\n" + " Number of state variables must be coincide with indxIndRegimes"); + + + z0_sdv.n = z0_dm->nrows; + z0_sdv.flag = V_DEF; + // + at_sdv.n = yt_sdv.n = yt_dm->nrows; + at_sdv.flag = yt_sdv.flag = V_DEF; + btp1_sdv.n = bt_dm->nrows; + btp1_sdv.flag = V_DEF; + + + //======= Initial condition. ======= + for (sti=smodel_ps->sv->nstates-1; sti>=0; sti--) + { + if (indxIndRegimes && (nRc==1)) + { + sti_c = 0; + sti_v = sti; + } + else if (indxIndRegimes && (nRv==1)) + { + sti_c = sti; + sti_v = 0; + } + else if (indxIndRegimes) + { + sti_c = smodel_ps->sv->Index[sti][0]; + sti_v = smodel_ps->sv->Index[sti][1]; + } + else + { + sti_c = sti_v = sti; + } + + + if (!kalfilmsinputs_ps->indxIni) + { + InitializeDiagonalMatrix_lf(Wnzbynz_dm, 1.0); //To be used for I(nz) - + InitializeDiagonalMatrix_lf(Wnz2bynz2_dm, 1.0); //To be used for I(nz2) - + + //=== Eigenanalysis to determine the roots to ensure boundedness. + errflag = eigrgen(evals_dzv, (TSdzmatrix *)NULL, (TSdzmatrix *)NULL, Ft_dc->C[sti_c]); + if (errflag) fn_DisplayError("kalman.c/tz_Refresh_z_T7P_T_in_kalfilms_1st_approx(): eigen decomposition failed"); + for (ki=nz-1; ki>=0; ki--) evals_abs_dv->v[ki] = sqrt(square(evals_dzv->real->v[ki]) + square(evals_dzv->imag->v[ki])); + evals_abs_dv->flag = V_DEF; + eigmax = MaxVector(evals_abs_dv); + if (eigmax < (1.0+1.0e-14)) + { + //--- Getting z0_dv: zt_tm1(:,1) = (eye(n_z)-F(:,:,1))\b(:,1); + MatrixMinusMatrix(Wnzbynz_dm, Wnzbynz_dm, Ft_dc->C[sti_c]); + z0_sdv.v = z0_dm->M + z0_sdv.n*sti; + CopySubmatrix2vector(&z0_sdv, 0, bt_dm, 0, sti_c, bt_dm->nrows); + bdivA_rgens(&z0_sdv, &z0_sdv, '\\', Wnzbynz_dm); + //Done with Wnzbynz_dm. + //--- Getting P0_dm: Pt_tm1(:,:,1) = reshape((eye(n_z^2)-kron(F(:,:,1),F(:,:,1)))\V1(:),n_z,n_z); + tz_kron(W2nz2bynz2_dm, Ft_dc->C[sti_c], Ft_dc->C[sti_c]); + MatrixMinusMatrix(Wnz2bynz2_dm, Wnz2bynz2_dm, W2nz2bynz2_dm); + CopySubmatrix2vector(wP0_dv, 0, Vt_dc->C[sti_v], 0, 0, nz2); + bdivA_rgens(wP0_dv, wP0_dv, '\\', Wnz2bynz2_dm); + CopySubvector2matrix_unr(P0_dc->C[sti], 0, 0, wP0_dv, 0, nz2); + //Done with all w*_dv and W*_dm. + } + else + { + fprintf(stdout, "\n-----------------\n"); + fprintf(stdout, "\nIn regime sti_c=%d and sti_v=%d and at time=%d\n", sti_c, sti_v, 0); + fn_DisplayError("kalman.c/tz_Refresh_z_T7P_T_in_kalfilms_1st_approx(): the system is non-stationary solutions\n" + " and the initial conditions must be supplied by, say, input arguments"); + fflush(stdout); + } + } + } + z0_dm->flag = M_GE; + CopyMatrix0(zt_tm1_dc->C[0], z0_dm); //At time t=0. + CopyCell0(Pt_tm1_d4->F[0], P0_dc); //At time t=0. + + +// fprintf(FPTR_DEBUG, "\n zt_tm1_dc->C[0]:\n"); +// WriteMatrix(FPTR_DEBUG, zt_tm1_dc->C[0], " %.16e "); +// fprintf(FPTR_DEBUG, "\n"); +// fprintf(FPTR_DEBUG, "\n Pt_tm1_d4->F[0]->C[0]:\n"); +// WriteMatrix(FPTR_DEBUG, Pt_tm1_d4->F[0]->C[0], " %.16e "); + + + //============== Updating zt_tm1 and Pt_tm1. ================== + for (tbase0=0; tbase0<T; tbase0++ ) + { + //tdata = tbase0 is base-0 timing. + tp1 = tbase0 + 1; //Next period. + + for (stp1i=smodel_ps->sv->nstates-1; stp1i>=0; stp1i--) + { + if (indxIndRegimes && (nRc==1)) + { + stp1i_c = 0; + stp1i_v = stp1i; + } + else if (indxIndRegimes && (nRv==1)) + { + stp1i_c = stp1i; + stp1i_v = 0; + } + else if (indxIndRegimes) + { + stp1i_c = smodel_ps->sv->Index[stp1i][0]; + stp1i_v = smodel_ps->sv->Index[stp1i][1]; + } + else + { + stp1i_c = stp1i_v = stp1i; + } + + + InitializeConstantVector_lf(ztp1_dv, 0.0); //To be summed over sti. + InitializeConstantMatrix_lf(Ptp1_dm, 0.0); //To be summed over sti. + for (sti=smodel_ps->sv->nstates-1; sti>=0; sti--) + { + if (indxIndRegimes && (nRc==1)) + { + sti_c = 0; + sti_v = sti; + } + else if (indxIndRegimes && (nRv==1)) + { + sti_c = sti; + sti_v = 0; + } + else if (indxIndRegimes) + { + sti_c = smodel_ps->sv->Index[sti][0]; + sti_v = smodel_ps->sv->Index[sti][1]; + } + else + { + sti_c = sti_v = sti; + } + + //--- Setup. + MatrixTimesMatrix(PHtran_tdata_dm, Pt_tm1_d4->F[tbase0]->C[sti], Ht_dc->C[sti_c], 1.0, 0.0, 'N', 'T'); + + //--- Data. + //- etdata = Y_T(:,tdata) - a(:,tdata) - Htdata*ztdata where tdata = tbase0 = inpt-1. + yt_sdv.v = yt_dm->M + tbase0*yt_dm->nrows; + at_sdv.v = at_dm->M + sti_c*at_dm->nrows; //sti_c: coefficient regime at time tbase0. + z0_sdv.v = zt_tm1_dc->C[tbase0]->M + z0_sdv.n*sti; //sti: regime at time tbase0. + VectorMinusVector(etdata_dv, &yt_sdv, &at_sdv); + MatrixTimesVector(etdata_dv, Ht_dc->C[sti_c], &z0_sdv, -1.0, 1.0, 'N'); + //+ Dtdata = Htdata*PHtran_tdata + R(:,:,tbase0); + CopyMatrix0(Dtdata_dm, Rt_dc->C[sti_v]); + MatrixTimesMatrix(Dtdata_dm, Ht_dc->C[sti_c], PHtran_tdata_dm, 1.0, 1.0, 'N', 'N'); + //Done with z0_sdv.v. + + + //=== Updating for next period by integrating out sti.. + if (tp1<T) + { + //Updating only up to tbase0=T-2. The values at tp1=T or tbase0=T-1 will not be used in the likelihood function. + + //--- Ktp1_t = (F_tp1*PHtran_t+G(:,:,t))/Dt; + //--- Kt_tdata = (Ft*PHtran_tdata+G(:,:,tdata))/Dtdata where t=tp1 and tdata=t. + CopyMatrix0(Kt_tdata0_dm, Gt_dc->C[sti_v]); + MatrixTimesMatrix(Kt_tdata0_dm, Ft_dc->C[stp1i_c], PHtran_tdata_dm, 1.0, 1.0, 'N', 'N'); + BdivA_rrect(Kt_tdata_dm, Kt_tdata0_dm, '/', Dtdata_dm); + //+ zt_tm1(:,t) = b(:,t) + Ft*zt_tm1(:,tdata) + Kt_tdata*etdata where t=tp1 and tm1=t. + MatrixTimesVector(ztp1_t_dv, Ft_dc->C[stp1i_c], &z0_sdv, 1.0, 0.0, 'N'); + MatrixTimesVector(ztp1_t_dv, Kt_tdata_dm, etdata_dv, 1.0, 1.0, 'N'); + btp1_sdv.v = bt_dm->M + stp1i_c*btp1_sdv.n; + VectorPlusMinusVectorUpdate(ztp1_t_dv, &btp1_sdv, 1.0); + //+ Pt_tm1(:,:,t) = Ft*Ptdata*Fttran - Kt_tdata*Dtdata*Kt_tdatatran + V(:,:,t); + CopyMatrix0(Ptp1_t_dm, Vt_dc->C[stp1i]); + MatrixTimesMatrix(Wnzbyny_dm, Kt_tdata_dm, Dtdata_dm, 1.0, 0.0, 'N', 'N'); + MatrixTimesMatrix(Wnzbynz_dm, Wnzbyny_dm, Kt_tdata_dm, 1.0, 0.0, 'N', 'T'); + MatrixPlusMinusMatrixUpdate(Ptp1_t_dm, Wnzbynz_dm, -1.0); + //Done with all W*_dm. + MatrixTimesMatrix(Wnzbynz_dm, Ft_dc->C[stp1i_c], Pt_tm1_d4->F[tbase0]->C[sti], 1.0, 0.0, 'N', 'N'); + MatrixTimesMatrix(W2nzbynz_dm, Wnzbynz_dm, Ft_dc->C[stp1i_c], 1.0, 0.0, 'N', 'T'); + MatrixPlusMatrixUpdate(Ptp1_t_dm, W2nzbynz_dm); + //Done with all W*_dm. + + //--- Integrating out the state at tbase0 using P(s_t|Y_t, theta) = ElementV(smodel_ps->V[t+1],s_{t+1}_i). + //--- Note because the data in DW code (ElementV) is base-1, t+1 is actually tbase0. + debug1 = ElementV(smodel_ps->V[tp1],sti); //?????? Debug. + //ScalarTimesVectorUpdate(ztp1_dv, ElementV(smodel_ps->V[tp1],sti), ztp1_t_dv); + //ScalarTimesMatrix(Ptp1_dm, ElementV(smodel_ps->V[tp1],sti), Ptp1_t_dm, 1.0); + ScalarTimesVectorUpdate(ztp1_dv, 0.5, ztp1_t_dv); + ScalarTimesMatrix(Ptp1_dm, 0.5, Ptp1_t_dm, 1.0); + Ptp1_dm->flag = M_GE | M_SU | M_SL; + //Done with ztp1_t_dv and Ptp1_t_dm. + } + } + //--- Filling zt_tm1 and Pt_tm1 for next period + if (tp1<T) + { + z0_sdv.v = zt_tm1_dc->C[tp1]->M + z0_sdv.n*stp1i; //stp1i: regime at time tp1. + CopyVector0(&z0_sdv, ztp1_dv); + CopyMatrix0(Pt_tm1_d4->F[tp1]->C[stp1i], Ptp1_dm); //stp1i: regime at time tp1. + //Done with ztp1_dv, z0_sdv, Ptp1_dm. + } + } + if (tp1<T) + zt_tm1_dc->C[tp1]->flag = M_GE; + +// fprintf(FPTR_DEBUG, "\n &yt_sdv:\n"); +// WriteMatrix(FPTR_DEBUG, &yt_sdv, " %.16e "); +// fprintf(FPTR_DEBUG, "\n zt_tm1_dc->C[tp1]:\n"); +// WriteMatrix(FPTR_DEBUG, zt_tm1_dc->C[tp1], " %.16e "); +// fprintf(FPTR_DEBUG, "\n"); +// fprintf(FPTR_DEBUG, "\n Pt_tm1_d4->F[tp1]->C[0]:\n"); +// WriteMatrix(FPTR_DEBUG, Pt_tm1_d4->F[tp1]->C[0], " %.16e "); +// fprintf(FPTR_DEBUG, "\n"); +// fflush(FPTR_DEBUG); + + + } + + //=== + DestroyVector_dz(evals_dzv); + DestroyVector_lf(evals_abs_dv); + DestroyMatrix_lf(Wnzbynz_dm); + DestroyMatrix_lf(Wnz2bynz2_dm); + DestroyMatrix_lf(W2nz2bynz2_dm); + DestroyVector_lf(wP0_dv); + // + DestroyVector_lf(wny_dv); + DestroyMatrix_lf(Wnzbyny_dm); + DestroyMatrix_lf(W2nzbynz_dm); + DestroyMatrix_lf(PHtran_tdata_dm); + DestroyVector_lf(etdata_dv); + DestroyMatrix_lf(Dtdata_dm); + DestroyMatrix_lf(Kt_tdata0_dm); + DestroyMatrix_lf(Kt_tdata_dm); + // + DestroyVector_lf(ztp1_t_dv); + DestroyMatrix_lf(Ptp1_t_dm); + DestroyVector_lf(ztp1_dv); + DestroyMatrix_lf(Ptp1_dm); +} +//----------------------------------------------------- +//- Kalman filter at time t for Markov-switching DSGE model. +//- WARNING: make sure to call the following functions +// (1) RunningGensys_const7varionly(lwzmodel_ps); +// (2) Refresh_kalfilms_*(lwzmodel_ps); //Creates or refreshes kalfilmsinputs_ps at new parameter values. +// (3) tz_Refresh_z_T7P_T_in_kalfilms_1st_approx(); +//- before using kalfilms_timet_1st_approx(). +//----------------------------------------------------- +double tz_kalfilms_timet_1st_approx(int st, int inpt, struct TSkalfilmsinputs_tag *kalfilmsinputs_ps, struct TStateModel_tag *smodel_ps) +{ + //st, st_c, and st_v: base-0: deals with the cross-section values at time t where + // st is a grand regime, st_c is an encoded coefficient regime, and st_c is an encoded volatility regime. + //inpt: base-1 in the sense that inpt>=1 to deal with the time series situation where S_T is (T+1)-by-1 and Y_T is T+nlags_max-by-1. + // The 1st element for S_T is S_T[1] while S_T[0] is s_0. The same for (T+1)-by-1 gbeta_dv and nlcoefs-by-(T+1) galpha_dm. + // The 1st element for Y_T, however, is Y_T[nlags_max+1-1]. + //See (42.3) on p.42 in the SWZII NOTES. + + + //--- Local variables + int st_c, st_v, tbase0; + double loglh_timet; + //--- Accessible variables + int ny = kalfilmsinputs_ps->ny; + int nz = kalfilmsinputs_ps->nz; + int nRc = kalfilmsinputs_ps->nRc; + int nRv = kalfilmsinputs_ps->nRv; + int indxIndRegimes = kalfilmsinputs_ps->indxIndRegimes; + TSdvector z0_sdv; + //+ input arguments. + TSdmatrix *yt_dm = kalfilmsinputs_ps->yt_dm; //ny-by-T. + TSdmatrix *at_dm = kalfilmsinputs_ps->at_dm; //ny-by-nRc. + TSdcell *Ht_dc = kalfilmsinputs_ps->Ht_dc; //ny-by-nz-by-nRc. + TSdcell *Rt_dc = kalfilmsinputs_ps->Rt_dc; //ny-by-ny-by-nRv. Covariance matrix for the measurement equation. + //+ Output arguments. + TSdcell *zt_tm1_dc = kalfilmsinputs_ps->zt_tm1_dc; //nz-by-nRc*nRv-by-T if indxIndRegimes==1, nz-by-nRv-by-T if indxIndRegimes==0 where nRc=nRv. + TSdfourth *Pt_tm1_d4 = kalfilmsinputs_ps->Pt_tm1_d4; //nz-by-nz-by-nRc*nRv-T if indxIndRegimes==1, nz-by-nz-by-nRv-by-T if indxIndRegimes==0 where nRc=nRv. + //=== Work arguments. + TSdvector yt_sdv, at_sdv; + TSdvector *wny_dv = CreateVector_lf(ny); + TSdmatrix *PHtran_tdata_dm = CreateMatrix_lf(nz,ny); + TSdvector *etdata_dv = CreateVector_lf(ny); + TSdmatrix *Dtdata_dm = CreateMatrix_lf(ny,ny); + + + if (smodel_ps->sv->nstates != zt_tm1_dc->C[0]->ncols) fn_DisplayError("kalman.c/kalfilms_timet_1st_approx():\n" + " Make sure that the column dimension of zt_tm1_dc->C is the same as smodel_ps->sv->nstates"); + + tbase0 = inpt - 1; //base-0 time t. + + if (indxIndRegimes && (nRc==1)) + { + st_c = 0; + st_v = st; + } + else if (indxIndRegimes && (nRv==1)) + { + st_c = st; + st_v = 0; + } + else if (indxIndRegimes) + { + if (smodel_ps->sv->n_state_variables != 2) fn_DisplayError("kalman.c/kalfilms_timet_1st_approx():\n" + " Number of state variables must be coincide with indxIndRegimes"); + st_c = smodel_ps->sv->Index[st][0]; + st_v = smodel_ps->sv->Index[st][1]; + } + else + { + st_c = st_v = st; + } + + + z0_sdv.n = zt_tm1_dc->C[0]->nrows; + z0_sdv.flag = V_DEF; + // + at_sdv.n = yt_sdv.n = yt_dm->nrows; + at_sdv.flag = yt_sdv.flag = V_DEF; + + //====== Computing the conditional LH at time t. ====== + //--- Setup. + MatrixTimesMatrix(PHtran_tdata_dm, Pt_tm1_d4->F[tbase0]->C[st], Ht_dc->C[st_c], 1.0, 0.0, 'N', 'T'); + + //--- Data. + //- etdata = Y_T(:,tdata) - a(:,tdata) - Htdata*ztdata where tdata = tbase0 = inpt-1. + yt_sdv.v = yt_dm->M + tbase0*yt_dm->nrows; + at_sdv.v = at_dm->M + st_c*at_dm->nrows; //st_c: coefficient regime at time tbase0. + z0_sdv.v = zt_tm1_dc->C[tbase0]->M + z0_sdv.n*st; //st: regime at time tbase0 for zt_tm1. + VectorMinusVector(etdata_dv, &yt_sdv, &at_sdv); + MatrixTimesVector(etdata_dv, Ht_dc->C[st_c], &z0_sdv, -1.0, 1.0, 'N'); + //+ Dtdata = Htdata*PHtran_tdata + R(:,:,tbase0); + CopyMatrix0(Dtdata_dm, Rt_dc->C[st_v]); + MatrixTimesMatrix(Dtdata_dm, Ht_dc->C[st_c], PHtran_tdata_dm, 1.0, 1.0, 'N', 'N'); + + //--- Forming the log conditional likelihood at t. + bdivA_rgens(wny_dv, etdata_dv, '/', Dtdata_dm); + loglh_timet = -(0.5*ny)*LOG2PI - 0.5*logdeterminant(Dtdata_dm) - 0.5*VectorDotVector(wny_dv, etdata_dv); + //Done with all w*_dv. + + + //=== + DestroyVector_lf(wny_dv); + DestroyMatrix_lf(PHtran_tdata_dm); + DestroyVector_lf(etdata_dv); + DestroyMatrix_lf(Dtdata_dm); + + return (loglh_timet); +} +#undef LOG2PI +/**/ + + + + diff --git a/CFiles/kalmanOldWorks2.h b/CFiles/kalmanOldWorks2.h new file mode 100755 index 0000000..df661b5 --- /dev/null +++ b/CFiles/kalmanOldWorks2.h @@ -0,0 +1,314 @@ +#ifndef __KALMAN_H__ + #define __KALMAN_H__ + + #include "tzmatlab.h" + #include "mathlib.h" + #include "switch.h" + #include "fn_filesetup.h" //Used to call WriteMatrix(FPTR_DEBUG,....). + + + typedef struct TSkalcvfurw_tag { + //urw: univariate random walk kalman filter. Desigend specially for the 2006 AER SWZ paper. + + //=== Input arguments. + int indx_tvsigmasq; //0: constant siqmasq in Kalman updating (default); + //1: Keyensian (project-specific) type of time-varying sigmasq in Kalman updating; See pp.37 and 37a in SWZ Learning NOTES; + //2: project-specific type; + //3: another project-specific type. + double sigmasq; //Variance for the residual eps(t) of the measurement equation. + int fss; //T: effective sample size (excluding lags). + int kx; //dimension for x(t). + TSdmatrix *V_dm; //kx-by-kx. Covariance (symmetric and positive definite) matrix for the residual eta(t) of the transition equation. + TSdvector *ylhtran_dv; //1-by-T of y(t). The term lh means lelf hand side and tran means transpose. + TSdmatrix *Xrhtran_dm; //kx-by-T of x(t). The term rh means right hand side and tran means transpose. + TSdvector *z10_dv; //kx-by-1. Initial condition for prediction: z_{1|0}. + TSdmatrix *P10_dm; //kx-by-kx symmetric matrix. Initial condition for the variance of the prediction: P_{1|0}. + + //=== Output arguments. + TSdvector *zupdate_dv; //kx-by-1. z_{T+1|T}. + TSdmatrix *Zpredtran_dm; //kx-by-T matrix of one-step predicted values of z(t). [z_{2|1}, ..., z_{t+1|t}, ..., z_{T+1|T}]. + //Set to NULL (no output) if storeZ = 0; + TSdcell *Ppred_dc; //T cells and kx-by-kx symmetric and positive definite matrix for each cell. Mean square errors of predicted state variables. + //{P_{2|1}, ..., P{t+1|t}, ..., P{T+1|T}. Set to NULL (no output if storeV = 0). + TSdvector *ylhtranpred_dv; //1-by-T one-step prediction of y(t) or ylhtran_dv. Added 03/17/05. + + //=== Function itself. + void (*learning_fnc)(struct TSkalcvfurw_tag *, void *); + } TSkalcvfurw; //urw: univariate random walk. + // + typedef void TFlearninguni(struct TSkalcvfurw_tag *, void *); //For linear rational expectations models. + + + //=== Better version is TSkalfilmsinputs_1stapp_tag. Kalman filter for constant or known-time-varying DSGE models. + typedef struct TSkalfiltv_tag + { + //General (known-time-varying) Kalman filter for DSGE models. + // It computes a sequence of one-step predictions and their covariance matrices, and the log likelihood. + // The function uses a forward recursion algorithm. See also the Matlab function fn_kalfil_tv.m + // + // State space model is defined as follows: + // y(t) = a(t) + H(t)*z(t) + eps(t) (observation or measurement equation) + // z(t) = b(t) + F(t)*z(t) + eta(t) (state or transition equation) + // where a(t), H(t), b(t), and F(t) depend on s_t that follows a Markov-chain process and are taken as given. + // + // Inputs are as follows: + // Y_T is a n_y-by-T matrix containing data [y(1), ... , y(T)]. + // a is an n_y-by-T matrix of time-varying input vectors in the measurement equation. + // H is an n_y-by-n_z-by-T 3-D of time-varying matrices in the measurement equation. + // R is an n_y-by-n_y-by-T 3-D of time-varying covariance matrices for the error in the measurement equation. + // G is an n_z-by-n_y-by-T 3-D of time-varying E(eta_t * eps_t'). + // ------ + // b is an n_z-by-T matrix of time-varying input vectors in the state equation with b(:,1) as an initial condition. + // F is an n_z-by-n_z-by-T 3-D of time-varying transition matrices in the state equation with F(:,:,1) as an initial condition. + // V is an n_z-by-n_z-by-T 3-D of time-varying covariance matrices for the error in the state equation with V(:,:,1) as an initial condition. + // ------ + // indxIni: 1: using the initial condition with zt_tm1(:,1)=z0 and Pt_tm1(:,:,1)=P0; + // 0: using the unconditional mean for any given regime at time 0. + // z0 is an n_z-by-1 vector of initial condition when indxIni=1. (Not used if indxIni=0.) + // P0 is an n_z-by-n_z matrix of initial condition when indxIni=1. (Not used if indxIni=0.) + // + // Outputs are as follows: + // loglh is a value of the log likelihood function of the state-space model + // under the assumption that errors are multivariate Gaussian. + // zt_tm1 is an n_z-by-T matrices of one-step predicted state vectors with z0_0m1 as a initial condition + // and with z_{t+1|t} as the last element. Thus, we can use it as a base-1 vector. + // Pt_tm1 is an n_z-by-n_z-by-T 3-D of covariance matrices of zt_tm1 with P0_0m1 as a initial condition + // and with P_{t+1|t} as the last element. Thus, we can use it as a base-1 cell. + // + // The initial state vector and its covariance matrix are computed under the bounded (stationary) condition: + // z0_0m1 = (I-F(:,:,1))\b(:,1) + // vec(P0_0m1) = (I-kron(F(:,:,1),F(:,:,1)))\vec(V(:,:,1)) + // Note that all eigenvalues of the matrix F(:,:,1) are inside the unit circle when the state-space model is bounded (stationary). + // + // March 2007, written by Tao Zha + // See Hamilton's book ([13.2.13] -- [13.2.22]), Harvey (pp.100-106), and LiuWZ Model I NOTES pp.001-003. + + //=== Input arguments. + int ny; //number of observables. + int nz; //number of state variables. + int T; //sample size. + int indxIni; //1: using the initial condition with zt_tm1(:,1)=z0 and Pt_tm1(:,:,1)=P0; + //0: using the unconditional mean for any given regime at time 0. (Default value) + TSdmatrix *yt_dm; //ny-by-T. + TSdmatrix *at_dm; //ny-by-T. + TSdcell *Ht_dc; //ny-by-nz-by-T. + TSdcell *Rt_dc; //ny-by-ny-by-T. Covariance matrix for the measurement equation. + TSdcell *Gt_dc; //nz-by-ny-by-T. Cross-covariance. + // + TSdmatrix *bt_dm; //nz-by-T. + TSdcell *Ft_dc; //nz-by-nz-by-T. + TSdcell *Vt_dc; //nz-by-nz-by-T. Covariance matrix for the state equation. + // + TSdvector *z0_dv; //nz-by-1; + TSdmatrix *P0_dm; //nz-by-nz. + + //=== Output arguments. + double loglh; //log likelihood. + TSdmatrix *zt_tm1_dm; //nz-by-T. + TSdcell *Pt_tm1_dc; //nz-by-nz-T. + } TSkalfiltv; + + + + //=== Inputs for filter for Markov-switching DSGE models at any time t. + typedef struct TSkalfilmsinputs_1stapp_tag + { + //Inputs Markov-switching Kalman filter for DSGE models (conditional on all the regimes at time t). + // It computes a sequence of one-step predictions and their covariance matrices, and the log likelihood. + // The function uses a forward recursion algorithm. See also the Matlab function fn_kalfil_tv.m + // + // State space model is defined as follows: + // y(t) = a(t) + H(t)*z(t) + eps(t) (observation or measurement equation) + // z(t) = b(t) + F(t)*z(t) + eta(t) (state or transition equation) + // where a(t), H(t), b(t), and F(t) depend on the grand regime s_t that follows a Markov-chain process + // and is taken as given, and + // eps(t) = Psi_u(t)*u(t), where Psi_u(t) is n_y-by-n_u and u(t) is n_u-by-1; + // eta(t) = Psi_e(t)*e(t), where Psi_e(t) is n_z-by-n_e and e(t) is n_e-by-1. + // + // Inputs at time t are as follows where nst is number of grand regimes (including lagged regime + // and coefficients and shock variances): + // Y_T is a n_y-by-T matrix containing data [y(1), ... , y(T)]. + // a is an n_y-by-nst matrix of Markov-switching input vectors in the measurement equation. + // H is an n_y-by-n_z-by-nst 3-D of Markov-switching matrices in the measurement equation. + // Psi_u is an n_y-by-n_u-by-nst 3-D Markov-switching matrices. + // R is an n_y-by-n_y-by-nst 3-D of Markov-switching covariance matrices, + // E(eps(t) * eps(t)') = Psi_u(t)*Psi_u(t)', for the error in the measurement equation. + // G is an n_z-by-n_y-by-nst 3-D of Markov-switching E(eta_t * eps_t') = Psi_e(t)*Psi_u(t)'. + // ------ + // b is an n_z-by-nst matrix of Markov-switching input vectors in the state equation with b(:,st) as an initial condition. + // (alternatively, with the ergodic weighted b(:,st) as an initial condition). + // F is an n_z-by-n_z-by-nst 3-D of Markov-switching transition matrices in the state equation with F(:,:,st) + // as an initial condition (alternatively, with the ergodic weighted F(:,:,st) as an initial condition). + // Psi_e is an n_z-by-n_e-by-nst 3-D Markov-switching matrices. + // V is an n_z-by-n_z-by-nRv 3-D of Markov-switching covariance matrices, + // E(eta(t)*eta(t)') = Psi_e(t)*Psi_e(t)', for the error in the state equation + // with V(:,:,st) as an initial condition (alternatively, with the ergodic weighted V(:,:,st) as an initial condition). + // ------ + // indxIni: 1: using the initial condition with zt_tm1(:,1)=z0 and Pt_tm1(:,:,1)=P0; + // 0: using the unconditional mean for any given regime at time 0. + // z0 is an n_z-by-nst matrix of initial condition (Not used if indxIni=0). + // P0 is an n_z-by-n_z-by-nst 3-D of initial condition (Not used if indxIni=0). + // + // The initial state vector and its covariance matrix are computed under the bounded (stationary) condition: + // z0_0m1 = (I-F(:,:,st))\b(:,st) + // vec(P0_0m1) = (I-kron(F(:,:,st),F(:,:,st)))\vec(V(:,:,st)) + // Note that all eigenvalues of the matrix F(:,:,st) are inside the unit circle when the state-space model is bounded (stationary). + // + // November 2007, written by Tao Zha. Revised, April 2008. + // See Hamilton's book ([13.2.13] -- [13.2.22]), Harvey (pp.100-106), and LiuWZ Model I NOTES pp.001-003. + + //=== Input arguments. + int ny; //number of observables. + int nz; //number of state variables. + int nu; //number of measurement errors. + int ne; //number of fundamental errors. + int nst; //number of grand composite regimes (current and past regimes, coefficient and volatility regimes). + int T; //sample size. + int indxIni; //1: using the initial condition with zt_tm1(:,1)=z0 and Pt_tm1(:,:,1)=P0, + //0: using the unconditional momnets for any given regime at time 0 (default when indxDiffuse = 0). + int indxDiffuse; //1: using the diffuse condition for z_{1|0} and P_{1|0} (default option), according to Koopman and Durbin, "Filtering and Smoothing of State Vector for Diffuse State-Space Models," J. of Time Series Analysis, Vol 24(1), pp.85-99. + //0: using the unconditional moments. + double DiffuseScale; //A large (infinity) number when indxDiffuse = 1. + int ztm1_track; //t-1 = -1: no initial conditions z_{1|0} and P_{1|0} has been computed yet, but will be using InitializeKalman_z10_P10(), + //t-1 >= 0:T-1: z_{t|t-1} and P_{t|t-1} are updated up to t-1. + int dtm1_track; //t-1 = -1: no etdata_dc->C[0] or Dtdata_d4->F[0] has been computed yet. + //t-1 >= 0:T-1: etdata_dc->C[t-1] and Dtdata_d4->F[t-1] are updated up to t-1. + + TSdmatrix *yt_dm; //ny-by-T. + TSdmatrix *at_dm; //ny-by-nst. + TSdcell *Ht_dc; //ny-by-nz-by-nst. + TSdcell *Psiut_dc; //ny-by-nu-by-nst. Measurement error coefficient matrix. + TSdcell *Rt_dc; //ny-by-ny-by-nst. Covariance matrix for the measurement equation. + TSdcell *Gt_dc; //nz-by-ny-by-nst. Cross-covariance. + // + TSdmatrix *bt_dm; //nz-by-nst. + TSdcell *Ft_dc; //nz-by-nz-by-nst. + TSdcell *Psiet_dc; //nz-by-ne-by-nst. Impact matrix in the state equation. + TSdcell *Vt_dc; //nz-by-nz-by-nst. Covariance matrix for the state equation. + // + TSdmatrix *z0_0_dm; //nz-by-nst. z_{0|0}. + TSdmatrix *z0_dm; //nz-by-nst. z_{1|0}. + TSdcell *P0_dc; //nz-by-nz-by-nst. P_{1|0} + + + //=== Output arguments only used for 1st order approximation to zt and Pt depending on infinite past regimes. + TSdcell *zt_tm1_dc; //nz-by-nst-by-(T+1), where z_{1|0} is an initial condition (1st element with t-1=0 or t=1 for base-1) and + // the terminal condition z_{T+1|T} using Updatekalfilms_1stapp(T, ...) is not computed + // when the likelihood logTimetCondLH_kalfilms_1stapp() is computed. Thus, z_{T+1|T} + // has not legal value computed in most applications unless in out-of-sample forecasting problems. + TSdfourth *Pt_tm1_d4; //nz-by-nz-by-nst-by-(T+1), where P_{1|0} is an initial condition (1st element with t-1=0) and + // the terminal condition P_{T+1|T} using Updatekalfilms_1stapp(T, ...) is not computed + // when the likelihood logTimetCondLH_kalfilms_1stapp() is computed. Thus, P_{T+1|T} + // has not legal value computed in most applications unless in out-of-sample forecasting problems. + //+ Will be save for updating likelihood and Kalman filter Updatekalfilms_1stapp(), so save time to recompute these objects again. + TSdfourth *PHtran_tdata_d4; //nz-by-ny-by-nst-T, P_{t|t-1}*H_t'. Saved only for updating Kalman filter Updatekalfilms_1stapp(). + TSdcell *etdata_dc; //ny-by-nst-by-T (with base-0 T), forecast errors e_t in the likelihood. + TSdcell *yt_tm1_dc; //ny-by-nst-by-T, one-step forecast y_{t|t-1} for t=0 to T-1 (base-0). Incorrect now (Used to back out structural shocks). + TSdfourth *Dtdata_d4; //ny-by-ny-nst-by-T, forecast covariance D_t in the likelihood. Saved for updating Kalman filter Updatekalfilms_1stapp(). + } TSkalfilmsinputs_1stapp; + + + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + //~~~ OLD Code: Inputs for filter for Markov-switching DSGE models at any time t. + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + typedef struct TSkalfilmsinputs_tag + { + //Inputs Markov-switching Kalman filter for DSGE models (conditional on all the regimes at time t). + // It computes a sequence of one-step predictions and their covariance matrices, and the log likelihood. + // The function uses a forward recursion algorithm. See also the Matlab function fn_kalfil_tv.m + // + // State space model is defined as follows: + // y(t) = a(t) + H(t)*z(t) + eps(t) (observation or measurement equation) + // z(t) = b(t) + F(t)*z(t) + eta(t) (state or transition equation) + // where a(t), H(t), b(t), and F(t) depend on s_t that follows a Markov-chain process and are taken as given. + // + // Inputs at time t are as follows where nRc is number of regimes for coefficients + // nRv is number of regimes for volatility (shock variances): + // Y_T is a n_y-by-T matrix containing data [y(1), ... , y(T)]. + // a is an n_y-by-nRc matrix of Markov-switching input vectors in the measurement equation. + // H is an n_y-by-n_z-by-nRc 3-D of Markov-switching matrices in the measurement equation. + // R is an n_y-by-n_y-by-nRv 3-D of Markov-switching covariance matrices for the error in the measurement equation. + // G is an n_z-by-n_y-by-nRv 3-D of Markov-switching E(eta_t * eps_t'). + // ------ + // b is an n_z-by-nRc matrix of Markov-switching input vectors in the state equation with b(:,1) as an initial condition. + // F is an n_z-by-n_z-by-nRc 3-D of Markov-switching transition matrices in the state equation with F(:,:,1) as an initial condition. + // V is an n_z-by-n_z-by-nRv 3-D of Markov-switching covariance matrices for the error in the state equation with V(:,:,1) as an initial condition. + // ------ + // indxIndRegimes: 1: coefficient regime and volatility regime are independent; 0: these two regimes are synchronized completely. + // indxIni: 1: using the initial condition with zt_tm1(:,1)=z0 and Pt_tm1(:,:,1)=P0; + // 0: using the unconditional mean for any given regime at time 0. + // z0 is an n_z-by-nRc*nRv matrix of initial condition when indxIni=1 and indxIndRegimes=1. (Not used if indxIni=0.) + // z0 is an n_z-by-nRv matrix of initial condition when indxIni=1 and indxIndRegimes=0. (Not used if indxIni=0.) + // P0 is an n_z-by-n_z-by-nRc*nRv 3-D of initial condition when indxIni=1 and indxIndRegimes=1. (Not used if indxIni=0.) + // P0 is an n_z-by-n_z-by-nRv 3-D of initial condition when indxIni=1 and indxIndRegimes=0. (Not used if indxIni=0.) + // + // The initial state vector and its covariance matrix are computed under the bounded (stationary) condition: + // z0_0m1 = (I-F(:,:,1))\b(:,1) + // vec(P0_0m1) = (I-kron(F(:,:,1),F(:,:,1)))\vec(V(:,:,1)) + // Note that all eigenvalues of the matrix F(:,:,1) are inside the unit circle when the state-space model is bounded (stationary). + // + // November 2007, written by Tao Zha + // See Hamilton's book ([13.2.13] -- [13.2.22]), Harvey (pp.100-106), and LiuWZ Model I NOTES pp.001-003. + + //=== Input arguments. + int ny; //number of observables. + int nz; //number of state variables. + int nRc; //number of composite regimes (current and past regimes) for coefficients. + int nRstc; //number of coefficient regimes at time t. + int nRv; //number of regimes for volatility (shock variances). + int indxIndRegimes; //1: coefficient regime and volatility regime are independent; 0: these two regimes are synchronized completely. + int T; //sample size. + int indxIni; //1: using the initial condition with zt_tm1(:,1)=z0 and Pt_tm1(:,:,1)=P0; + //0: using the unconditional mean for any given regime at time 0. (Default value) + TSdmatrix *yt_dm; //ny-by-T. + TSdmatrix *at_dm; //ny-by-nRc. + TSdcell *Ht_dc; //ny-by-nz-by-nRc. + TSdcell *Rt_dc; //ny-by-ny-by-nRv. Covariance matrix for the measurement equation. + TSdcell *Gt_dc; //nz-by-ny-by-nRv. Cross-covariance. + // + TSdmatrix *bt_dm; //nz-by-nRc. + TSdcell *Ft_dc; //nz-by-nz-by-nRc. + TSdcell *Vt_dc; //nz-by-nz-by-nRv. Covariance matrix for the state equation. + // + TSdmatrix *z0_dm; //nz-by-nRc*nRv if indxIndRegimes == 1 or nz-by-nRv if indxIndRegimes == 0. + TSdcell *P0_dc; //nz-by-nz-by-nRc*nRv if indxIndRegimes == 1 or nz-by-nz-by-nRv if indxIndRegimes == 0. + + + //=== Output arguments only used for 1st order approximation to zt and Pt depending on infinite past regimes. + TSdcell *zt_tm1_dc; //nz-by-nRc*nRv-by-T if indxIndRegimes==1, nz-by-nRv-by-T if indxIndRegimes==0 where nRc=nRv. + TSdfourth *Pt_tm1_d4; //nz-by-nz-by-nRc*nRv-T if indxIndRegimes==1, nz-by-nz-by-nRv-by-T if indxIndRegimes==0 where nRc=nRv. + } TSkalfilmsinputs; + + + + + //--- Functions for univariate random walk kalman filter. + TSkalcvfurw *CreateTSkalcvfurw(TFlearninguni *func, int T, int k, int tv); //, int storeZ, int storeV); + TSkalcvfurw *DestroyTSkalcvfurw(TSkalcvfurw *kalcvfurw_ps); + void kalcvf_urw(TSkalcvfurw *kalcvfurw_ps, void *dummy_ps); + + //--- New Code: Functions for Markov-switching Kalman filter. + struct TSkalfilmsinputs_1stapp_tag *CreateTSkalfilmsinputs_1stapp2(int ny, int nz, int nu, int ne, int nst, int T); + struct TSkalfilmsinputs_1stapp_tag *DestroyTSkalfilmsinputs_1stapp2(struct TSkalfilmsinputs_1stapp_tag *kalfilmsinputs_1stapp_ps); + struct TSkalfilmsinputs_1stapp_tag *CreateTSkalfilmsinputs_1stapp(int ny, int nz, int nst, int T); + struct TSkalfilmsinputs_1stapp_tag *DestroyTSkalfilmsinputs_1stapp(struct TSkalfilmsinputs_1stapp_tag *kalfilmsinputs_1stapp_ps); + int InitializeKalman_z10_P10(struct TSkalfilmsinputs_1stapp_tag *kalfilmsinputs_1stapp_ps, TSdmatrix *z10_dm, TSdcell *P10_dc); + double logTimetCondLH_kalfilms_1stapp(int st, int inpt, struct TSkalfilmsinputs_1stapp_tag *kalfilmsinputs_1stapp_ps, struct TStateModel_tag *smodel_ps); + + + + //--- OLD Code: Functions for general constant Kalman filter. + struct TSkalfiltv_tag *CreateTSkalfiltv(int ny, int nz, int T); + struct TSkalfiltv_tag *DestroyTSkalfiltv(struct TSkalfiltv_tag *kalfiltv_ps); + //Used to test tz_logTimetCondLH_kalfiltv(). (Done April 08). double tz_kalfiltv(struct TSkalfiltv_tag *kalfiltv_ps); + double tz_logTimetCondLH_kalfiltv(int st, int inpt, struct TSkalfiltv_tag *kalfiltv_ps); + + //--- OLD Code: Functions for Markov-switching Kalman filter. + struct TSkalfilmsinputs_tag *CreateTSkalfilmsinputs(int ny, int nz, int nRc, int nRstc, int nRv, int indxIndRegimes, int T); + struct TSkalfilmsinputs_tag *DestroyTSkalfilmsinputs(struct TSkalfilmsinputs_tag *kalfilmsinputs_ps); + double tz_logTimetCondLH_kalfilms_1st_approx(int st, int inpt, struct TSkalfilmsinputs_tag *kalfilmsinputs_ps, struct TStateModel_tag *smodel_ps); + //IMPORTANT NOTE: in the Markov-switching input file datainp_markov*.prn, it MUST be that + // the coefficient regime is the 1st state variable, and + // the volatility regime is the 2nd state variable. +#endif + diff --git a/CFiles/mathlib.c b/CFiles/mathlib.c new file mode 100755 index 0000000..8bf1c40 --- /dev/null +++ b/CFiles/mathlib.c @@ -0,0 +1,5506 @@ +#include "mathlib.h" + +//======================================================= +// LAPACK routines -- all based on Intel MKL (or IMSL C Math library) +//======================================================= +#if defined (INTELCMATHLIBRARY) +int lurgen(TSdmatrix *lu_dm, TSivector *pivot_dv, TSdmatrix *x_dm) { + // PLU = x_dm from the LU decomposition of the input matrix x_dm where P is a permutation matrix, L is lower triangular with unit + // diagonal elements (lower trapezoidal if nrows>ncols) and U is upper triangular (upper trapezoidal if nrows<ncols). + // L: (1) If nrows <= ncols, nrows-by-nrows . + // (2) If nrows > ncols, nrows-by-ncols (lower trapezoidal). + // U: (1) If nrows <= ncols, nrows-by-ncols (upper trapezoidal). + // (2) If nrows > ncols, ncols-by-ncols. + // + //Outputs: + // lu_dm: Stack L and U in this nrows-by-ncols matrix where the unit diagonal elements of L are not stored. + // pivot_dv: Optional. An min(nrows, ncols) vector of index integers such that row i was interchanged with row pivot_dv->v[i]. + // When NULL, this output argument is not exported (but computed anyway by the MKL hard-coded function). + //Inputs: + // x_dm: nrows-by-ncols general real matrix. + + int nrows, ncols, mindim, + errflag=2; //errflag=0 implies a successful execution. But we start with 2 so as to let dgetrf export a correct flag. + int *pivot_p=NULL; + double *LU; + + //=== Checking dimensions and memory allocation. + if ( !lu_dm || !x_dm ) fn_DisplayError(".../mathlib.c/lurgen(): The input arguments lu_dm and x_dm must be cretaed (memory-allocated)"); + else if ( ( (nrows=x_dm->nrows) != lu_dm->nrows) || ( (ncols=x_dm->ncols) != lu_dm->ncols) ) + fn_DisplayError(".../mathlib.c/lurgen(): Make sure the dimensions of the input matricies lu_dm and x_dm are the same"); + + if ( !(x_dm->flag & M_GE) ) + { + if (x_dm->flag & M_SU) SUtoGE(x_dm); + else if (x_dm->flag & M_SL) SLtoGE(x_dm); + else fn_DisplayError(".../mathlib.c/lurgen(): Haven't got time to make M_UT, M_LT, and other to a general matrix M_GE"); + } + //else if ( !(x_dm->flag & M_GE) ) fn_DisplayError(".../mathlib.c/lurgen(): The input arguments x_dm must be a general real matrix with the flag M_GE"); + + + mindim = _min(nrows, ncols); + memcpy((LU=lu_dm->M), x_dm->M, nrows*ncols*sizeof(double)); + lu_dm->flag = M_UT; //To make the lower part of lu_dm available, one must create another matrix and explicitly make it a unit lower matrix. + + //=== Calling the MKL function. + if (!pivot_dv) { + pivot_p = tzMalloc(mindim, int); + dgetrf(&nrows, &ncols, LU, &nrows, pivot_p, &errflag); + free(pivot_p); //Frees the memory belonging to this function. + } + else { + if ( pivot_dv->n != mindim) fn_DisplayError("Make sure the dimension of the input vector pivot_dv is the minimum number of row number and column number of the input matrix x_dm"); + dgetrf(&nrows, &ncols, LU, &nrows, pivot_dv->v, &errflag); + } + + + return( errflag ); //(1) If errflag = 0, success. (2) If errorflag = -i, the ith parameter has an illegal value. + //(3) If errflag = i, u_{ii}=0.0. The factorization is completed, but U is exactly singular. Dividing + // by 0.0 will occur if you use the factor U for solving a system of linear equations. +} +#else +//No default routine yet. +#endif + + +#if defined (INTELCMATHLIBRARY) +int eigrsym(TSdvector *eval_dv, TSdmatrix *eVec_dm, const TSdmatrix *S_dm) +{ + // Outputs (dependent on Intel MKL): + // eval_dv: _n-by-1 eigenvalues in ascending order; + // eVec_dm: _n-by-_n eigenvalues -- if (eVec_m==NULL), no eigenvectors are computed; otherwise, S_dm = eVec_dm*diag(eval_dv)*inv(eVec_dm). + // errflag: error flag. + //------------ + // Inputs: + // S_dm: _n-by_n real symmetric matrix. + // + // Eigenanalysis of real symmetric square matrix with all eigenvalues and, optionally, eigenvectors. + // Experts' opinion: do NOT use Cuppen's divide-and-conquer algorithm; instead, use QR algorithm, which I guess this algorithm uses. + + int n1, _n, errflag=2, //errflat=0 implies successful decomposition. But we start with 2 so as to let dsyev export a correct flag. + lwork; + double *tmpd0_m = NULL, + *work_p = NULL; + + if ( !S_dm || !(S_dm->flag & (M_SU | M_SL)) ) fn_DisplayError(".../mathlib.c/eigrsym(): input matrix (1) must be created (memory-alloacted) and (2) must be symmetric (either M_SU or M_SL)"); + if ( !eval_dv ) fn_DisplayError(".../mathlib.c/eigrsym(): input eigenvalue vector must be created (memory-allocated)"); + lwork = (n1=_n=S_dm->nrows)*BLOCKSIZE_FOR_INTEL_MKL; + + + //=== Memory allocated for this function. + tmpd0_m = tzMalloc(square(_n), double), + work_p = tzMalloc(lwork, double); + + + //--------------------------- + // Obtains eigenvalues and, optionally, eigenvectors. + //--------------------------- + memcpy(tmpd0_m, S_dm->M, square(_n)*sizeof(double)); + dsyev( (eVec_dm) ? "V" : "N", (S_dm->flag & M_SU) ? "U" : "L", &n1, tmpd0_m, &n1, eval_dv->v, work_p, &lwork, &errflag); + if (work_p[0]>lwork) printf("Warning for /mathlib.c/eigrsym(): needs at least %d workspace for good performance " + "but lwork is allocated with only %d space!\n", (int)work_p[0], lwork); + eval_dv->flag = V_DEF; + if (eVec_dm) { + memcpy(eVec_dm->M, tmpd0_m, square(_n)*sizeof(double)); + eVec_dm->flag = M_GE; + } + + + //--------------------------- + // Frees the allocated memory. + //--------------------------- + tzDestroy(tmpd0_m); + tzDestroy(work_p); + + //if (errflag<0) fn_DisplayError("/Subfolder: Calling eigrsym_decomp -- some element in input matrix has an illegal value"); + //else if (errflag>0) fn_DisplayError("/Subfolder: Calling eigrsym_decomp -- the factor U is exactly singular, so the solution cannot be computed"); + return (errflag); +} +#else +//Not default routine yet. +#endif + + + +#if defined (INTELCMATHLIBRARY) +int eigrgen(TSdzvector *vals_dzv, TSdzmatrix *rights_dzm, TSdzmatrix *lefts_dzm, const TSdmatrix *x_dm) +{ + //--- Eigenanalysis of real general (non-symmetric) square matrix with all eigenvalues and, optionally, eigenvectors. --- + // + //Outputs (dependent on Intel MKL): + // vals_dzv->real->v: _n-by-1 real parts of eigenvalues; + // vals_dzv->imag->v: _n-by-1 imaginary parts of eigenvalues -- must be *initialized to zero* in this function; + // rights_dzm->real->M: if (rights_dzm==NULL), no right eigenvectors are computed; otherwise, _n-by-_n corresponding *real* parts of right eigenvectors column by column: A*v(j)=lambda(j)*v(j); + // if (rights_dzm!=NULL), lefts_dzm->Mi must be *initialized to zero* in this function to get _n-by-_n *imaginary* parts of left eigenvectors corresponding to vals_dzv. + // lefts_dzm->imag->M: if (lefts_dzm==NULL), no left eigenvectors are computed; otherwise, n-by-n corresponding *real* parts of left eigenvectors column by column: u(j)^H*A=lambda(j)*u(j)^H, where H means conjugate transpose; + // if (lefts_dzm!=NULL), lefts_dzm->Mi must be *initialized to zero* in this function to get _n-by-_n *imaginary* parts of right eigenvectors corresponding to vals_dzv. + // returned errflag: error flag. If errflag<0, some element in input matrix has an illegal value. + // If errflag>0, the QR algorithm failed to compute all the eigenvalues and no eigenvectors have been computed. + // if errflag=0, we have a successful decomposition. + //------------ + // Inputs: + // x_dm: _n-by_n real general (non-symmetric) matrix. + + int errflag=2, //errflag=0 implies successful decomposition. But we start with 2 so as to let dgeev export a correct flag. + _n, lwork, n1, _i, _j; + double *tmpd0_m=NULL, + *work_p=NULL, + *x_m=NULL, + *evalr_v=NULL, + *evali_v=NULL, + *revecr_m=NULL, *reveci_m=NULL, //NULL means that by default we dont' compute eigenvectors. + *levecr_m=NULL, *leveci_m=NULL; + + //--------------------------- + // Checking dimensions, etc. + //--------------------------- + if ( !x_dm || !vals_dzv ) + fn_DisplayError(".../mathlib.c/eigrgen(): Input square matrix x_dm and eigen value vectors vals_dzv must be created (memory allocated) before the call to this function"); + else { + _n = x_dm->nrows; + lwork = _n*BLOCKSIZE_FOR_INTEL_MKL; + n1 = _n; + tmpd0_m = tzMalloc(square(_n), double), //@@Must be freed in this function.@@ + work_p = tzMalloc(lwork, double), //@@Must be freed in this function.@@ + InitializeConstantVector_lf(vals_dzv->imag, 0.0); //Imaginary part must be initialized to 0.0 to testing purposes later on. + // + x_m = x_dm->M; + evalr_v = vals_dzv->real->v; + evali_v = vals_dzv->imag->v; + } + if ( _n!=vals_dzv->real->n || _n!=x_dm->ncols ) fn_DisplayError(".../mathlib.c/eigrgen(): (1)input real matrix x_dm must be square; (2) the length of vals_dzv must match the dimension of x_dm"); + if (rights_dzm) { + if ( _n!=rights_dzm->real->nrows || _n!=rights_dzm->real->ncols ) fn_DisplayError(".../mathlib.c/eigrgen(): rights_dzm must have the same dimension as the input square matrix"); + revecr_m = rights_dzm->real->M; // (rights_dzm) ? rights_dzm->real->M : NULL, + rights_dzm->real->flag = M_GE; + InitializeConstantMatrix_lf(rights_dzm->imag, 0.0); + reveci_m = rights_dzm->imag->M; + } + if (lefts_dzm) { + if ( _n!=lefts_dzm->real->nrows || _n!=lefts_dzm->real->ncols ) fn_DisplayError(".../mathlib.c/eigrgen(): lefts_dzm must have the same dimension as the input square matrix"); + levecr_m = lefts_dzm->real->M; // (lefts_dzm) ? lefts_dzm->real->M : NULL, + lefts_dzm->real->flag = M_GE; + InitializeConstantMatrix_lf(lefts_dzm->imag, 0.0); + leveci_m = lefts_dzm->imag->M; + } + + + + //--------------------------- + // Starts with x_m -- the matrix to be decomposed. + //--------------------------- + memcpy(tmpd0_m, x_m, square(_n)*sizeof(double)); + + //--------------------------- + // Obtains eigenvalues and, optionally, eigenvectors. + //--------------------------- + dgeev( (levecr_m) ? "V" : "N", (revecr_m) ? "V" : "N", &n1, tmpd0_m, &n1, evalr_v, evali_v, + levecr_m, &n1, revecr_m, &n1, work_p, &lwork, &errflag); + vals_dzv->real->flag = V_DEF; + + //--------------------------- + // Frees the allocated memory. + //--------------------------- + if (work_p[0]>lwork) printf("Warning for /mathlib.c/eigrgen(): needs at least %d workspace for good performance " + "but lwork is allocated with only %d space!\n", (int)work_p[0], lwork); + tzDestroy(work_p); + tzDestroy(tmpd0_m); + + //--------------------------- + // Checks error conditions. + // Exports final results. + //--------------------------- + if (errflag) return( errflag ); + else { + if (revecr_m) { //Tested against Matlab output. Works! 10/13/02. + for (_j=0; _j<_n-1; _j++) + if (evali_v[_j] && (evali_v[_j] == -evali_v[_j+1])) + for (_i=0; _i<_n; _i++) { + reveci_m[_i+(_j+1)*_n] = -(reveci_m[_i+_j*_n]=revecr_m[_i+(_j+1)*_n]); + revecr_m[_i+(_j+1)*_n] = revecr_m[_i+_j*_n]; + } + } + if (levecr_m) { //!!WARNINGS!!: Hasn't tested against any other established program, but it seems working. 10/13/02. + for (_j=0; _j<_n-1; _j++) + if (evali_v[_j] && (evali_v[_j] == -evali_v[_j+1])) + for (_i=0; _i<_n; _i++) { + leveci_m[_i+(_j+1)*_n] = -(leveci_m[_i+_j*_n]=levecr_m[_i+(_j+1)*_n]); + levecr_m[_i+(_j+1)*_n] = levecr_m[_i+_j*_n]; + } + } + return( errflag ); + } +} +#else +//Not default routine yet. +#endif + +#if defined (INTELCMATHLIBRARY) +int chol(TSdmatrix *D_dm, TSdmatrix *S_dm, const char ul) { + //?????????? Some of options are NOT tested yet. + // Choleski decomposition of a symmetric, positive definite matrix S. Intel MKL Lapack dependent code. + // The fastest way for chol() is to let D = S, but D will be replaced by the Choleski factor. + // + //Outputs: + // D: _n-by_n -- if ul=='U' or 'u', D'*D = S where D is stored only in the upper triangular part; + // if ul=='L' or 'l', D*D' = S where D is stored only in the lower triangular part. + // If D_dm->M == S_dm->M, D_dm->M (and S_dm->M) will be replaced by the triangular Choleski factor after the call to this function. + // errflag: error flag: 0: successful; + // -6: not symmetric (see mklman.pdf for other error return codes on ?potrf(). + //-------- + //Inputs: + // S: _n-by-_n symmetric, positive definite matrix (whose only triangular part is used by dpotrf). + // ul: if =='U' or 'u', D (NOT necessarily S unless D == S) is upper triangular; if =='L' or 'l', D (NOT necessarily S unless D == S) is lower triangular. + + int errflag=2, loc, nrows, _m, _i, _j; //errflat=0 implies successful decomposition. But we start with 2 so as to let dpotrf export a correct flag. + double *D, *S; + + + if ( !D_dm || !S_dm ) fn_DisplayError(".../mathlib.c/chol(): L and R input square matricies must be created (memory allocated)"); + else { + nrows = S_dm->nrows; + _m = nrows; //Used by Lapack. + D = D_dm->M; + S = S_dm->M; + } + if ( (nrows != D_dm->ncols) || (nrows != S_dm->nrows) || (nrows != S_dm->ncols) ) fn_DisplayError(".../mathlib.c/chol(): Make sure both R and L input matricies are square and have the same dimension"); + + + //=== Fills the triangular part that is used for Choleski decomposition. + if ( D != S) { + switch (ul) { + case 'U': case 'u': + if (S_dm->flag & M_SU) { + for (_j=0; _j<nrows; _j++) + for (_i=0; _i<=_j; _i++) { + loc=mos(_i,_j,nrows); + D[loc] = S[loc]; + } + D_dm->flag = M_UT; + } + else if (S_dm->flag & M_SL) { + for (_j=0; _j<nrows; _j++) + for (_i=0; _i<=_j; _i++) + D[mos(_i,_j,nrows)] = S[mos(_j,_i,nrows)]; + D_dm->flag = M_UT; + } + else + { + //fn_DisplayError(".../mathlib.c/chol(): R input square matrix must be symmetric (and positive definite)"); + printf("\n ------- .../mathlib.c/chol(): R input square matrix must be symmetric!-------\n"); + return (-6); + } + dpotrf("U", &_m, D, &_m, &errflag); + break; + case 'L': case 'l': + if (S_dm->flag & M_SL) { + for (_j=0; _j<nrows; _j++) { + //for (_i=0; _i<_j; _i++) D[_i+_j*nrows] = 0.0; //Initializes the other part of D to zero so as to make it visible and readable. + for (_i=_j; _i<nrows; _i++) { + loc=mos(_i,_j,nrows); + D[loc] = S[loc]; + } + } + D_dm->flag = M_LT; + } + else if (S_dm->flag & M_SU) { + //????????????? NOT teste yet for this option. + for (_j=0; _j<nrows; _j++) + for (_i=_j; _i<nrows; _i++) + D[mos(_i,_j,nrows)] = S[mos(_j,_i,nrows)]; + D_dm->flag = M_LT; + } + else + { + //fn_DisplayError(".../mathlib.c/chol(): R input square matrix must be symmetric (and positive definite)"); + printf("\n ------- .../mathlib.c/chol(): R input square matrix must be symmetric!-------\n"); + return (-6); + } + //??????NOT tested yet. + dpotrf("L", &_m, D, &_m, &errflag); + break; + default: + fn_DisplayError(".../mathlib.c/chol(): Input ul must be either 'U' or 'L'"); + } + } + else { + if ( (ul=='U' || ul=='u') && (D_dm->flag & M_SU) ) { + dpotrf("U", &_m, D, &_m, &errflag); + D_dm->flag = M_UT; + } + else if ( (ul=='L' || ul=='l') && (D_dm->flag & M_SL) ) { + //Tested. It works! + dpotrf("L", &_m, D, &_m, &errflag); + D_dm->flag = M_LT; + } + else { + printf("\nFatal Error: The input ul is %c and the flag D_dm->flag is %d", ul, D_dm->flag); + fn_DisplayError(".../mathlib.c/chol(): When D==S, upper or lower triangular output must be consistent with upper or lower symmetric input; otherwise, use the option with D != S"); + } + } + //=== Choleski decomposition. + // dpotrf(((ul=='u') || (ul=='U')) ? "U" : "L", &_m, D, &_m, &errflag); + //--- + // if (errflag<0) fn_DisplayError("Some element has an illegal value"); + // else if (errflag>0) fn_DisplayError("The leadding minor of some order, hence the entire matrix, is not positive definite"); + return (errflag); +} +#else +//No default routine yet. +#endif + + +#if defined (INTELCMATHLIBRARY) +int invrtri(TSdmatrix *X_dm, TSdmatrix *A_dm, const char un) +{ + //Inverse of a real triangular matrix A. + //The fastest way is to let X=A and A (and X) will be replaced by inv(A). + // + //Outputs: + // X: _n-by_n inverse of A; + // errflag: error flag (=0 means successful). + //-------- + //Inputs: + // A: _n-by-_n real triangular matrix. + // un: if un=='U' or 'u', A is unit triangular; otherwise (un=='N' or 'n', A is not a unit triangular matrix. + + int _n, errflag=2; //errflat=0 implies successful decomposition. But we start with 2 so as to let dgetri export a correct flag. + double *X, *A; + + + if ( !X_dm || !A_dm ) fn_DisplayError(".../mathlib.c/invrtri(): Both input matrices must be created (memory-allocated)"); + else if ( !(A_dm->flag & (M_UT | M_LT)) ) fn_DisplayError(".../mathlib.c/invrtri(): (1) R input matrix A must be given legal values; (2) A must be a real triangular matrix, i.e., M_UT or M_LT"); + else { + X = X_dm->M; + A = A_dm->M; + _n=A_dm->nrows; + } + if ( (_n != A_dm->ncols) || (_n != X_dm->nrows) || (_n != X_dm->ncols) ) + fn_DisplayError(".../mathlib.c/invrtri(): both input and output matrices (1) must be square and (2) must have the same dimension"); + + + if (X==A) { + dtrtri((A_dm->flag & M_UT) ? "U" : "L", (un=='U' || un=='u') ? "U" : "N", &_n, X, &_n, &errflag); + if (errflag) return (errflag); + } + else { + memcpy(X, A, _n*_n*sizeof(double)); + dtrtri((A_dm->flag & M_UT) ? "U" : "L", (un=='U' || un=='u') ? "U" : "N", &_n, X, &_n, &errflag); + if (errflag) return (errflag); + else X_dm->flag = A_dm->flag; + } + + return errflag; //(1) If errflag = 0, success. (2) If errorflag = -i, the ith parameter has an illegal value. + //(3) If errflag = i, the ith diagonal element of A is zero, A is singular, and the inversion + // could not be completed. +} +#else +//No default routine yet. +#endif + + +#if defined (INTELCMATHLIBRARY) +int invspd(TSdmatrix *X_dm, TSdmatrix *A_dm, const char ul) +{ + //Inverse of a symmetric positive matrix A. + //Fastest way: let X=A. Then, A (and X) will be replaced by inv(A). + // + //Outputs: + // X: _n-by_n inverse of A; + // errflag: error flag (=0 means successful). + //-------- + //Inputs: + // A: _n-by-_n symmetric positive matrix. + // ul: if ul=='U' or 'u', only upper part of A is used; otherwise (un=='L' or 'l', only lower part of A is used. + + int _n, errflag=2; //errflat=0 implies successful decomposition. But we start with 2 so as to let dgetri export a correct flag. + double *X, *A; + + + if ( !X_dm || !A_dm ) fn_DisplayError(".../mathlib.c/invspd(): Both input matrices must be created (memory-allocated)"); + else if ( !(A_dm->flag & (M_SU | M_SL)) ) fn_DisplayError(".../mathlib.c/invspd(): (1) R input matrix A must be given legal values; (2) A must be symmetric, positive-definite, i.e., M_SU or M_SL"); + else { + X = X_dm->M; + A = A_dm->M; + _n=A_dm->nrows; + } + + + if (X==A) { + if ( (_n != A_dm->ncols) ) + fn_DisplayError(".../mathlib.c/invspd(): input matrix (1) must be square and (2) must have the same dimension"); + //=== Choleski decomposition. + dpotrf(((ul=='U') || (ul=='u')) ? "U" : "L", &_n, X, &_n, &errflag); + if (errflag) return (errflag); + //=== Takes inverse. + dpotri(((ul=='U') || (ul=='u')) ? "U" : "L", &_n, X, &_n, &errflag); + A_dm->flag = ((ul=='U') || (ul=='u')) ? M_SU : M_SL; + return (errflag); + //--- + // if (errflag<0) fn_DisplayError("Some element has an illegal value"); + // else if (errflag>0) fn_DisplayError("Not symmetric positive definite or matrix inversion cannot be computed"); + } + else { + if ( (_n != A_dm->ncols) || (_n != X_dm->nrows) || (_n != X_dm->ncols) ) + fn_DisplayError(".../mathlib.c/invspd(): both input and output matrices (1) must be square and (2) must have the same dimension"); + memcpy(X, A, _n*_n*sizeof(double)); + //=== Choleski decomposition. + dpotrf(((ul=='U') || (ul=='u')) ? "U" : "L", &_n, X, &_n, &errflag); + if (errflag) return (errflag); + //=== Takes inverse. + dpotri(((ul=='U') || (ul=='u')) ? "U" : "L", &_n, X, &_n, &errflag); + X_dm->flag = ((ul=='U') || (ul=='u')) ? M_SU : M_SL; + return (errflag); + //--- + // if (errflag<0) fn_DisplayError("Some element has an illegal value"); + // else if (errflag>0) fn_DisplayError("Not symmetric positive definite or matrix inversion cannot be computed"); + } +} +#else +//No default routine yet. +#endif + + + +#if defined (INTELCMATHLIBRARY) +int invrgen(TSdmatrix *X_dm, TSdmatrix *A_dm) +{ + //Inverse of a general real matrix A. + //If X=A, A (and X) will be replaced by inv(A). + // + //Outputs: + // X: _n-by_n inverse of A; + // errflag: error flag (=0 means successful). + //-------- + //Inputs: + // A: _n-by-_n real general matrix. + int _n, errflag=2, //errflat=0 implies successful decomposition. But we start with 2 so as to let dgetri export a correct flag. + lwork, *ipivot; //Used when calling LAPACK. + double *X, *A, + *work; //Used when calling LAPACK. + + + if ( !X_dm || !A_dm ) fn_DisplayError(".../mathlib.c/invrgen(): Both input matrices must be created (memory-allocated)"); + else if ( !(A_dm->flag & M_GE) ) fn_DisplayError(".../mathlib.c/invrgen(): (1) R input matrix A must be given legal values; (2) A must be a general matrix, i.e., M_GE"); + else { + X = X_dm->M; + A = A_dm->M; + ipivot = tzMalloc((_n=A_dm->nrows), int); + work = tzMalloc((lwork=_n*BLOCKSIZE_FOR_INTEL_MKL), double); + } + if ( (_n != A_dm->ncols) || (_n != X_dm->nrows) || (_n != X_dm->ncols) ) + fn_DisplayError(".../mathlib.c/invrgen(): both input and output matrices (1) must be square and (2) have the same dimension"); + + + if (X==A) { + dgetrf(&_n, &_n, A, &_n, ipivot, &errflag); + if (errflag) { +// A_dm->flag = M_UNDEF; + free(ipivot); + free(work); + return errflag; + } + dgetri(&_n, A, &_n, ipivot, work, &lwork, &errflag); + if (work[0]>lwork) printf("Warning for /mathlib.c/invrgen(); when calling MKL dgetri(), we need at least %d workspace for good performance " + "but lwork is allocated with only %d space!\n", (int)work[0], lwork); + if (errflag) { + free(ipivot); + free(work); + return (errflag); //A_dm->flag = M_UNDEF; + } + } + else { + memcpy(X, A, _n*_n*sizeof(double)); + dgetrf(&_n, &_n, X, &_n, ipivot, &errflag); + if (errflag) { +// X_dm->flag = M_UNDEF; + free(ipivot); + free(work); + return errflag; + } + dgetri(&_n, X, &_n, ipivot, work, &lwork, &errflag); + if (work[0]>lwork) printf("Warning for /mathlib.c/invrgen(); when calling MKL dgetri(), we need at least %d workspace for good performance " + "but lwork is allocated with only %d space!\n", (int)work[0], lwork); + if (errflag) { + free(ipivot); + free(work); + return (errflag); //X_dm->flag = M_UNDEF; + } + else X_dm->flag = A_dm->flag; + } + //=== Frees memory allocated in this function. + free(ipivot); + free(work); + + return errflag; //(1) If errflag = 0, success. (2) If errorflag = -i, the ith parameter has an illegal value. + //(3) If errflag = i, U_{ii}=0.0. The LU factorization U is literally singular and the inversion + // could not be completed. +} +#else +//No default routine yet. +#endif + + + +#if defined (INTELCMATHLIBRARY) +int BdivA_rrect(TSdmatrix *X_dm, const TSdmatrix *B_dm, const char lr, const TSdmatrix *A_dm) +{ + //This routine solves left division (\) problme AX=B (X=A\B). For XA=B (right division problem: X=B/A), we first transpose + // it to A'*X'=B', then solve out X' = A'\B' as a left-division problem, and finally transpose X' back to X. + //It handles cases with _m>=_n. For _n>_m, we have an infinite solution. To get one solution, take the _m-by-_m nonsigular + // part of A_dm and get the solution for the _m-by-_r part of X with \ or the _r-by-_m part of X with /. The (_n-_m)-by-_r part + // or _r-by-(_n-_m) part of X can simply be filled with 0.0. + // + //Outputs: + // X = A\B or B/A where X is _n-by_r if \ (AX=B) or _r-by-_n if / (XA=B). + // Returns info (if info==0, the execution is successful; if info == -i, the ith parameter has an illegal value.) + //-------- + //Inputs: + // A: _m-by-_n real rectangular (rrect) matrix if \ (AX=B) or + // _n-by-_m real rectangular (rrect) matrix if / (XA=B). + // B: _m-by-_r real rectangular (rrect) matrix if \ (AX=B) or + // _r-by-_m real rectangular (rrect) matrix if / (XA=B). + // lr: if lr='\\', left division \ is performed; if lr='/', right division / is performed. + + int _m, _n, _r, //mn_max, mn_min, + lwork, _i, info = -2, + *jpvt_p = NULL; + double *A, *B, *X, + *qra_p = NULL, //QR decomposion for A_dm. + *qrb_p = NULL, //QR decomposion for B_dm. + *tau_p = NULL, + *work_p = NULL; + + if (!A_dm || !(A_dm->flag & M_GE) || !B_dm || !(B_dm->flag &M_GE)) fn_DisplayError(".../mathlib.c/BdivA_rrect(): both input matricies A_dm and B_dm must be (a) created (allocated memory) and (b) given legal values for all elements (in other words, the flag M_GE must exist)"); + if (!X_dm) fn_DisplayError(".../mathlib.c/BdivA_rrect(): output matrix X_dm must be created (allocated memory)"); + if (lr=='/') { + if ( (_n=A_dm->nrows) != X_dm->ncols ) fn_DisplayError(".../mathlib.c/BdivA_rrect(): 1st dim of A_dm and 2nd dim of X_dm must exactly match for / (right division)"); + if ( (_m=A_dm->ncols) != B_dm->ncols ) fn_DisplayError(".../mathlib.c/BdivA_rrect(): 2nd dim of A_dm and 2nd dim of B_dm must exactly match for / (right division)"); + if ( (_r=B_dm->nrows) != X_dm->nrows ) fn_DisplayError(".../mathlib.c/BdivA_rrect(): 1st dim of B_dm and 1st dim of X_dm must exactly match for / (right division)"); + if ( _m < _n) fn_DisplayError(".../mathlib.c/BdivA_rrect(): A_dm->nrows must be <= A_dm->ncols for / (right division). Otherwise, take the nonsigular square part of A_dm and use BdivA_rrect()"); + } + else if (lr=='\\') { + if ( (_m=A_dm->nrows) != B_dm->nrows ) fn_DisplayError(".../mathlib.c/BdivA_rrect(): 1st dim of A_dm and 1st dim of B_dm must exactly match for \\ (left division)"); + if ( (_n=A_dm->ncols) != X_dm->nrows ) fn_DisplayError(".../mathlib.c/BdivA_rrect(): 2nd dim of A_dm and 1st dim of X_dm must exactly match for \\ (left division)"); + if ( (_r=B_dm->ncols) != X_dm->ncols ) fn_DisplayError(".../mathlib.c/BdivA_rrect(): 2nd dim of B_dm and 2nd dim of X_dm must exactly match for \\ (left division)"); + if ( _m < _n) fn_DisplayError(".../mathlib.c/BdivA_rrect(): A_dm->nrows must be >= A_dm->ncols for \\ (left division). Otherwise, take the nonsigular square part of A_dm and use BdivA_rrect()"); + } + else fn_DisplayError(".../mathlib.c/BdivA_rrect(): input character lr must be / (right division) or \\\\ (left division)"); + A = A_dm->M; + B = B_dm->M; + X = X_dm->M; + + +// lwork = ((mn_max = _m>_n ? _m : _n)>_r ? nm_max : _r)*BLOCKSIZE_FOR_INTEL_MKL; +// mn_min = _m<_n ? _m : _n; + + + //=== Memory allocation for this function only. + qra_p = tzMalloc(_m*_n, double); +// qrb_p = tzMalloc((mn_max = _m>_n?_m:_n)*_r, double); //DDDDebug: seems requiring _m>_n, but this may not be the case. + qrb_p = tzMalloc(_m*_r, double); //Note that _m>=_n. + jpvt_p = tzMalloc(_n, int); + tau_p = tzMalloc(_n, double); +// work_p = tzMalloc(lwork, double); + + + //=== Making copies of input matrices A and B */ + if (lr=='/') //Right division. In this case, qra_p is _m-by-_n (transpose of A_dm), and qrb_p is max(_m,_n)-by-_r (transpose of B_dm). + for (_i=0; _i<_m; _i++) { + cblas_dcopy(_n, &A[_i*_n], 1, &qra_p[_i], _m); + cblas_dcopy(_r, &B[_i*_r], 1, &qrb_p[_i], _m); + } + else { + memcpy(qra_p, A, _m*_n*sizeof(double)); //qra_p is _m-by-_n. + memcpy(qrb_p, B, _m*_r*sizeof(double)); //qrb_p is _m-by-_r. +// for (_i=0; _i<_r; _i++) cblas_dcopy(_m, B+_i*_m, 1, qrb_p+_i*mn_max, 1); //qrb_p is max(_m,_n)-by-_r. + } + + + //=== Computes the QR factorization of a general m by n matrix with column pivoting using Level 3 BLAS. + work_p = tzMalloc(lwork=_n*BLOCKSIZE_FOR_INTEL_MKL, double); + dgeqp3(&_m,&_n,qra_p,&_m,jpvt_p,tau_p,work_p,&lwork,&info); + if (work_p[0]>lwork) printf("Warning for /mathlib.c/BdivA_rrect(); when calling MKL dgeqp3(), we need at least %d workspace for good performance " + "but lwork is allocated with only %d space!\n", (int)work_p[0], lwork); + tzDestroy(work_p); + if (info) return (info); //If info==0, the execution is successful; if info == -i, the ith parameter has an illegal value. + + //=== Multiplies a real matrix by the orthogonal matrix Q of the QR factorization formed by dgeqp3. + work_p = tzMalloc(lwork=_r*BLOCKSIZE_FOR_INTEL_MKL, double); + dormqr("L","T",&_m,&_r,&_n,qra_p,&_m,tau_p,qrb_p,&_m,work_p,&lwork,&info); + if (work_p[0]>lwork) printf("Warning for /mathlib.c/BdivA_rrect(); when calling MKL dormqr(), we need at least %d workspace for good performance " + "but lwork is allocated with only %d space!\n", (int)work_p[0], lwork); + //dormqr("L","T",&_m,&_r,&mn_min,qra_p,&_m,tau_p,qrb_p,&mn_max,work_p,&lwork,&info); + tzDestroy(work_p) + if (info) return (info); //If info==0, the execution is successful; if info == -i, the ith parameter has an illegal value. + + + //=== Solves a matrix equation R*x = C (one matrix operand is triangular). Note that the dim of X is n-by-r for \ or r-by-n for / + cblas_dtrsm(CblasColMajor,CblasLeft,CblasUpper,CblasNoTrans,CblasNonUnit,_n,_r,1.0,qra_p,_m,qrb_p,_m); + if (lr=='/') //Right division. In this case, qra_p is _m-by-_n (transpose of A_dm), and qrb_p is max(_m, _n)-by-_r (transpose of B_dm). + for (_i=0; _i<_n; _i++) cblas_dcopy(_r, &qrb_p[_i], _m, &X[(jpvt_p[_i]-1)*_r], 1); //Copying the transpose of the _n-by-_r leading part of qrb_p. +// cblas_dcopy(_r, &qrb_p[_i], mn_max, &X[(jpvt_p[_i]-1)*_r], 1); //Copying the transpose of the _n-by-_r leading part of qrb_p. + + else //qrb_p is max(_m, _n)-by-_r. + for (_i=0; _i<_n; _i++) cblas_dcopy(_r, &qrb_p[_i], _m, &X[jpvt_p[_i]-1], _n); +// cblas_dcopy(_r, &qrb_p[_i], mn_max, &X[jpvt_p[_i]-1], _n); + X_dm->flag = M_GE; + + //=== Destroyes memory allocated for this function only. + tzDestroy(qra_p); + tzDestroy(qrb_p); + tzDestroy(jpvt_p); + tzDestroy(tau_p); +// tzDestroy(work_p); + + return (0); +} +#else +//No default routine yet. 7 Oct 2003 +#endif + + + + +#if defined (INTELCMATHLIBRARY) +int BdivA_rgens(TSdmatrix *X_dm, const TSdmatrix *B_dm, const char lr, const TSdmatrix *A_dm) +{ + //Unlike BdivA_rrect(), this routine deals with only the general square matrix A_dm. It solves left division (\) problme + // AX=B (X=A\B). For XA=B (right division problem: X=B/A), we first transpose it to A'*X'=B', then solve out X' = A'\B' + // as a left-division problem, and finally transpose X' back to X. + // + //Outputs: + // X = A\B or B/A where X is _m-by_r if \ (AX=B) or _r-by-_m if / (XA=B). + // Returns info (if info==0, the execution is successful; if info == -i, the ith parameter has an illegal value.) + //-------- + //Inputs: + // A: _m-by-_m real general square (rgens) matrix. + // B: _m-by-_r real general square (rgens) matrix if \ (AX=B) or + // _r-by-_m real general square (rgens) matrix if / (XA=B). + // lr: if lr='\\', left division \ is performed; if lr='/', right division / is performed. + + int _m, _r, m2, + _i, info = -2, + *ipiv_p = NULL; + double *A, *B, *X, + *Atran_p = NULL, //Transpose of A if right division / takes place. + *Btran_p = NULL, //Transpose of B if right division / takes place. + *W = NULL; //Duplicate copy of A when left division \ is used. This will be replaced by LU decomposition. +// *tau_p = NULL, +// *work_p = NULL; + + if (!A_dm || !(A_dm->flag & M_GE) || !B_dm || !(B_dm->flag & M_GE)) fn_DisplayError(".../mathlib.c/BdivA_rgens(): both input matricies A_dm and B_dm must be (a) created (allocated memory) and (b) given legal values for all elements (in other words, the flag M_GE must exist)"); + if (!X_dm) fn_DisplayError(".../mathlib.c/BdivA_rgens(): output matrix X_dm must be created (allocated memory)"); + if (lr=='/') { + if ( (_m=A_dm->nrows) != X_dm->ncols ) fn_DisplayError(".../mathlib.c/BdivA_rgens(): 1st dim of A_dm and 2nd dim of X_dm must exactly match for / (right division)"); + if ( _m != A_dm->ncols ) fn_DisplayError(".../mathlib.c/BdivA_rgens(): input matrix A_dm must be square. For a nonsqaure matrix, use BdivA_rrect()"); + if ( _m != B_dm->ncols ) fn_DisplayError(".../mathlib.c/BdivA_rgens(): 2nd dim of A_dm and 2nd dim of B_dm must exactly match for / (right division)"); + if ( (_r=B_dm->nrows) != X_dm->nrows ) fn_DisplayError(".../mathlib.c/BdivA_rgens(): 1st dim of B_dm and 1st dim of X_dm must exactly match for / (right division)"); + + } + else if (lr=='\\') { + if ( (_m=A_dm->nrows) != B_dm->nrows ) fn_DisplayError(".../mathlib.c/BdivA_rgens(): 1st dim of A_dm and 1st dim of B_dm must exactly match for \\ (left division)"); + if ( _m != A_dm->ncols ) fn_DisplayError(".../mathlib.c/BdivA_rgens(): input matrix A_dm must be square. For a nonsqaure matrix, use BdivA_rrect()"); + if ( _m != X_dm->nrows ) fn_DisplayError(".../mathlib.c/BdivA_rgens(): 2nd dim of A_dm and 1st dim of X_dm must exactly match for \\ (left division)"); + if ( (_r=B_dm->ncols) != X_dm->ncols ) fn_DisplayError(".../mathlib.c/BdivA_rgens(): 2nd dim of B_dm and 2nd dim of X_dm must exactly match for \\ (left division)"); + } + else fn_DisplayError(".../mathlib.c/BdivA_rgens(): input character lr must be / (right division) or \\\\ (left division)"); + A = A_dm->M; + B = B_dm->M; + X = X_dm->M; + + + + if (lr=='/') { + //Right divistion /. + //=== Memory allocation for this function only. + ipiv_p = tzMalloc(_m, int); + Atran_p = tzMalloc(square(_m), double); + Btran_p = tzMalloc(_m*_r, double); + + for (_i=0; _i<_m; _i++) { + cblas_dcopy(_m, A+_i*_m, 1, Atran_p+_i, _m); //Copying the transpose of A to Atran. + cblas_dcopy(_r, B+_i*_r, 1, Btran_p+_i, _m); //Copying the transpose of B (_r-by-_m) to Btran (_m-by-_r); + } + dgesv(&_m, &_r, Atran_p, &_m, ipiv_p, Btran_p, &_m, &info); + for (_i=0; _i<_r; _i++) cblas_dcopy(_m, Btran_p+_i*_m, 1, X+_i, _r); //Copying the transpose of Btran(_m-by-_r) to X (_r-by-_m); + X_dm->flag = M_GE; + + //=== Destroyes memory allocated for this function only. + tzDestroy(ipiv_p); + tzDestroy(Atran_p); + tzDestroy(Btran_p); + + return (info); + } + else { + //Left division \. + //=== Memory allocation for this function only. + ipiv_p = tzMalloc(_m, int); + W = tzMalloc(m2=square(_m), double); + + memcpy(X, B, _m*_r*sizeof(double)); + memcpy(W, A, m2*sizeof(double)); + dgesv(&_m, &_r, W, &_m, ipiv_p, X, &_m, &info); + X_dm->flag = M_GE; + + //=== Destroyes memory allocated for this function only. + tzDestroy(ipiv_p); + tzDestroy(W); + + return (info); //If info==0, the execution is successful; if info == -i, the ith parameter has an illegal value; + // if info==i, U(i,i) in LU decomposition is exactly zero. The factorization has been completed, but + // the factor U is exactly singular, so the solution could not be computed. + } +} +//--- +int bdivA_rgens(TSdvector *x_dv, const TSdvector *b_dv, const char lr, const TSdmatrix *A_dm) +{ + //Use bdivA_rgens() where x_dv and b_dv are now both vectors and A_dm is a square matrix. + //Unlike bdivA_rrect(), this routine deals with only the general square matrix A_dm. It solves left division (\) problme + // Ax=b (x=A\b). For xA=b (right division problem: x=B/b), we first transpose it to A'*x'=b', then solve out x' = A'\b' + // as a left-division problem, and finally transpose x' back to x. + // + //If x_dv->v = b_dv->v. Then, x_dv->v will be replaced by new values. + // + //Outputs: Solving Ax = b or xA = b. + // x = A\b or b/A where x is _m-by-1 if \ (Ax=b) or 1-by-_m if / (xA=b). + // Returns info (if info==0, the execution is successful; if info == -i, the ith parameter has an illegal value.) + //-------- + //Inputs: + // A: _m-by-_m real general square (rgens) matrix. + // b: _m-by-1 vector if \ (Ax=b) or + // 1-by-_m vector if / (xA=b). + // lr: if lr='\\', left division \ is performed; if lr='/', right division / is performed. + + int _m, m2, + _r = 1, + _i, info = -2, + *ipiv_p = NULL; + double *A, *b, *x, + *Atran_p = NULL, //Transpose of A if right division / takes place. + *W = NULL; //Duplicate copy of A when left division \ is used. This will be replaced by LU decomposition. + + if (!A_dm || !(A_dm->flag & M_GE) || !b_dv || !b_dv->flag) fn_DisplayError("mathlib.c/bdivA_rgens(): Both A_dm and b_dv must be (a) created (allocated memory) and (b) given legal values for all elements (in other words, the flag M_GE must exist)"); + if (!x_dv) fn_DisplayError("mathlib.c/bdivA_rgens(): output vector x_dv must be created (allocated memory)"); + if ( b_dv->n != x_dv->n ) fn_DisplayError("mathlib.c/bdivA_rgens(): The dim of b_dv and the dim of x_dv must exactly match"); + if ( (_m=A_dm->nrows) != x_dv->n ) fn_DisplayError("mathlib.c/bdivA_rgens(): Number of rows of A_dm and the dim of x_dv must exactly match"); + if ( _m != A_dm->ncols ) fn_DisplayError("mathlib.c/bdivA_rgens(): Input matrix A_dm must be square"); + + A = A_dm->M; + b = b_dv->v; + x = x_dv->v; + + if (lr=='/') { + //Right divistion /. + //=== Memory allocation for this function only. + ipiv_p = tzMalloc(_m, int); + Atran_p = tzMalloc(square(_m), double); + + for (_i=0; _i<_m; _i++) + cblas_dcopy(_m, A+_i*_m, 1, Atran_p+_i, _m); //Copying the transpose of A to Atran. + if (x_dv != b_dv ) memcpy(x, b, _m*sizeof(double)); + dgesv(&_m, &_r, Atran_p, &_m, ipiv_p, x, &_m, &info); + x_dv->flag = V_DEF; + + //=== Destroyes memory allocated for this function only. + tzDestroy(ipiv_p); + tzDestroy(Atran_p); + + return (info); + } + else { + //Left division \. + //=== Memory allocation for this function only. + ipiv_p = tzMalloc(_m, int); + W = tzMalloc(m2=square(_m), double); + + if (x_dv != b_dv ) memcpy(x, b, _m*sizeof(double)); + memcpy(W, A, m2*sizeof(double)); + dgesv(&_m, &_r, W, &_m, ipiv_p, x, &_m, &info); + x_dv->flag = V_DEF; + + //=== Destroyes memory allocated for this function only. + tzDestroy(ipiv_p); + tzDestroy(W); + + return (info); //If info==0, the execution is successful; if info == -i, the ith parameter has an illegal value; + // if info==i, U(i,i) in LU decomposition is exactly zero. The factorization has been completed, but + // the factor U is exactly singular, so the solution could not be computed. + } +} +#else +//No default routine yet. 7 Oct 2003 +#endif + + + +#if defined (INTELCMATHLIBRARY) +void Aldivb_spd(TSdvector *x_dv, TSdmatrix *A_dm, TSdvector *b_dv, char an) { + //??????? Some options (e.g., whe A_dm is M_SL) are NOT tested yet. + //Output x = A\b where x_dv is an _n-by-1 vector. + // Fastest way is to let x_dv->v = b_dv->v. Then, x_dv->v will be replaced by new values. + //-------- + //Inputs: + // A: _n-by-_n symmetric, positive definite matrix. + // b: _n-by-1 vector. + // an: 'N' or 'n': A_dm will NOT be altered and another matrix will be allocated and destroyed in this function. + // Otherwise ('A' or 'a'): A_dm will be altered and A_dm = U if A_dm->flag = M_SU where U is an upper triagular Choleski such that U'*U = A; + // or A_dm = L if A_dm->flag = M_SL (but != M_SU) where L is a lower triangular Choleski such that L*L' = A. + // + // Note I: Intel MLK cblas_dtrsv() does not test for singularity or near-singulariy of the system. + // Such tests must be performed before calling this BLAS routine. + // Note II: If x_dv->v = b_dv->v, x_dv->v will be replaced by new values. + // Note III: If an != 'N' or 'n', A_dm will be replaced by U if A_dm->M_SU where U'*U = A or by L if A_dm->M_SL (but != M_SU) where L*L'=A. + + int errflag=2, nrows, nels; //errflat=0 implies successful decomposition. But we start with 2 so as to let dpotrf export a correct flag. + double *A, *W=NULL, *x, *b; + + if ( !A_dm || !b_dv || !x_dv ) fn_DisplayError(".../mathlib.c/Aldivb_spd(): All input matrices or vectors must be created (memory allocated)"); + nrows = A_dm->nrows; + nels = square(nrows); + A = A_dm->M; + x = x_dv->v; + b= b_dv->v; + if ( nrows != A_dm->ncols ) fn_DisplayError(".../mathlib.c/Aldivb_spd(): L input matrix must be square"); + if ( !A_dm->flag || !b_dv->flag ) fn_DisplayError(".../mathlib.c/Aldivb_spd(): L input matrix and vector must be given legal values"); + if ( (an=='N') || (an=='n') ) { + W = tzMalloc(nels, double); + memcpy(W, A, nels*sizeof(double)); + } + else if ( (an=='A') || (an=='a') ) W = A; + else fn_DisplayError(".../mathlib.c/Aldivb_spd(): passing charecter an must be A, a, N, or n"); + + + if (A_dm->flag & M_SU) { + dpotrf("U", &nrows, W, &nrows, &errflag); //Choleski. U'*U = W where W will be replaced by upper triangular U. + if (errflag) fn_DisplayError(".../mathlib.c/Aldivb_spd(): Error when calling Choleski dpotrf(). Check if the L input matrix A_dm is positive definite or has legal values"); + if (x==b) { + //=== Solving for A*x=b. + cblas_dtrsv(CblasColMajor, CblasUpper, CblasTrans, CblasNonUnit, nrows, W, nrows, x, 1); + cblas_dtrsv(CblasColMajor, CblasUpper, CblasNoTrans, CblasNonUnit, nrows, W, nrows, x, 1); + } + else { + memcpy(x, b, nrows*sizeof(double)); + cblas_dtrsv(CblasColMajor, CblasUpper, CblasTrans, CblasNonUnit, nrows, W, nrows, x, 1); + cblas_dtrsv(CblasColMajor, CblasUpper, CblasNoTrans, CblasNonUnit, nrows, W, nrows, x, 1); + x_dv->flag = V_DEF; + } + if ( (an!='N') && (an!='n') ) A_dm->flag = M_UT; + } + else if (A_dm->flag & M_SL) { //?????????? Not tested yet. + dpotrf("L", &nrows, W, &nrows, &errflag); //Choleski. L*L' = W where W will be replaced by lower triangular L. + if (errflag) fn_DisplayError(".../mathlib.c/Aldivb_spd(): Error when calling Choleski dpotrf(). Check if the L input matrix A_dm is positive definite or has legal values"); + if (x==b) { + //=== Solving for A*x=b. + cblas_dtrsv(CblasColMajor, CblasLower, CblasNoTrans, CblasNonUnit, nrows, W, nrows, x, 1); + cblas_dtrsv(CblasColMajor, CblasLower, CblasTrans, CblasNonUnit, nrows, W, nrows, x, 1); + } + else { + memcpy(x, b, nrows*sizeof(double)); + cblas_dtrsv(CblasColMajor, CblasLower, CblasNoTrans, CblasNonUnit, nrows, W, nrows, x, 1); + cblas_dtrsv(CblasColMajor, CblasLower, CblasTrans, CblasNonUnit, nrows, W, nrows, x, 1); + x_dv->flag = V_DEF; + } + if ( (an!='N') && (an!='n') ) A_dm->flag = M_LT; + } + else fn_DisplayError(".../mathlib.c/Aldivb_spd(): L input matrix A_dm must be symmetric"); + //dpotrf((A_dm->flag & M_SU) ? "U" : "L", &nrows, A, &nrows, &errflag); //Choleski. If "U", U'*U = A where A will be replaced by upper triangular U. + // if (errflag<0) fn_DisplayError("Some element has an illegal value"); + // else if (errflag>0) fn_DisplayError("The leadding minor of some order, hence the entire matrix, is not positive definite"); + + if ( (an=='N') || (an=='n') ) free(W); +} +#else +//No default routine yet. +#endif + + + +#if defined (INTELCMATHLIBRARY) +double detspd(TSdmatrix *S_dm) +{ + //Determinant of symmetric positive definite (SPD) matrix must be positive. + //We set the return value to be -1 if this matrix is NOT SPD. + double valuedet; + int _n, _i; + int errflag; + //=== + TSdmatrix *Work_dm = NULL; + + if (S_dm) { + _n = S_dm->nrows; + Work_dm = CreateMatrix_lf(_n, _n); + } + else fn_DisplayError(".../mathlib.c/detspd(): Input matrix must be (1) created, (2) symmetric, (3) positive definite"); + + if (S_dm->flag & M_SU) errflag=chol(Work_dm, S_dm, 'U'); + else if (S_dm->flag & M_SL) errflag=chol(Work_dm, S_dm, 'L'); + else fn_DisplayError(".../mathlib.c/detpdf(): Input matrix S_dm must be either M_SU or M_SL"); + + if (errflag) { + //printf("\nFatal Error in .../mathlib.c/detspd() when calling chol() with error flag %d\n", errflag); + //exit(EXIT_FAILURE); + DestroyMatrix_lf(Work_dm); + return (-1.0); + } + else + { + for (valuedet=1.0, _i=square(_n)-1; _i>=0; _i -= _n+1) valuedet *= Work_dm->M[_i]; + //log(fabs(M[_i])); + if (!isfinite(valuedet)) fn_DisplayError(".../mathlib.c/detspd(): the determinant is overflow. Use logdetspd() instead"); + //Done with Work* arrays. + DestroyMatrix_lf(Work_dm); + return (square(valuedet)); //square() because Work_dm is a square root of S_dm. + } +} +#else +//No default routine yet. +#endif +//--- +#if defined (INTELCMATHLIBRARY) +double logdetspd(TSdmatrix *S_dm) +{ + //Determinant of symmetric positive definite (SPD) matrix must be positive. + //We set the return value to be log(-1.0) (becomeing NaN) if this matrix is NOT SPD. + double logvaluedet; + int _n, _i; + int errflag; + //=== + TSdmatrix *Work_dm = NULL; + + if (S_dm) { + _n = S_dm->nrows; + Work_dm = CreateMatrix_lf(_n, _n); + } + else fn_DisplayError(".../mathlib.c/detspd(): Input matrix must be (1) created, (2) symmetric, (3) positive definite"); + + if (S_dm->flag & M_SU) errflag=chol(Work_dm, S_dm, 'U'); + else if (S_dm->flag & M_SL) errflag=chol(Work_dm, S_dm, 'L'); + else fn_DisplayError(".../mathlib.c/logdetspd(): Input matrix S_dm must be either M_SU or M_SL"); + + + if (errflag) { + //printf("\nFatal Error in .../mathlib.c/logdetspd() when calling chol() with error flag %d\n", errflag); + //exit(EXIT_FAILURE); + DestroyMatrix_lf(Work_dm); + printf("\n----- errflag for chol() when calling logdetspd() in mathlib.c = %d -----\n", errflag); + return (log(-1.0)); + } + else + { + for (logvaluedet=0.0, _i=square(_n)-1; _i>=0; _i -= _n+1) logvaluedet += log(Work_dm->M[_i]); + //Done with Work* arrays. + DestroyMatrix_lf(Work_dm); + return (2.0*logvaluedet); //2.0* because Work_dm is a square root of S_dm. + } +} +#else +//No default routine yet. +#endif + + + +#if defined (INTELCMATHLIBRARY) +double logdeterminant(TSdmatrix *A_dm) { + //Outputs: log|A|. + //------ + //Inputs: + // A_dm: m-by-n real general matrix. + + double retval; + int _m, _n, + errflag = -2; + TSdmatrix *U_dm; + + if (!A_dm) fn_DisplayError(".../logdeterminant(): Input matrix must be memory allocated (and make sure it has legal values with the flag M_GE)"); + //NOTE: all properties of A_dm will be double checked again by lurgen() below. + + //=== Allocates memory used only in this function. + U_dm = CreateMatrix_lf(_m=A_dm->nrows, _n=A_dm->ncols); + + errflag = lurgen(U_dm, (TSivector *)NULL, A_dm); //Gets only the upper part of U_dm. + if (errflag) fn_DisplayError(".../logdeterminant(): Error occurs when calling lurgen()"); + retval = tracelogfabs(U_dm); //tracelogfabs(U) = trace(log(diag(U))). + + //=== Frees memory allocated only for this function. + DestroyMatrix_lf(U_dm); + + return ( retval ); +} +#else +//No default routine yet. +#endif + + +int eigrsym_decomp(double *eval_v, double *evec_m, const double *s_m, const int _n, const char ul) { //, const char revec_yn, const char levec_yn) { + // Outputs (dependent on Intel MKL): + // eval_v: _n-by-1 eigenvalues in ascending order; + // evec_m: _n-by-_n eigenvalues -- if (evec_m==NULL), no eigenvectors are computed; otherwise, x_m = evec_m*diag(eval_v)*inv(evec_m). + // errflag: error flag. + //------------ + // Inputs: + // s_m: _n-by_n real symmetric matrix. + // ul: if =='u' or 'U', s_m is upper triangular; if =='l' or 'L', s_m is lower triangular. + // + // Eigenanalysis of real symmetric square matrix with all eigenvalues and, optionally, eigenvectors. + // Experts' opinion: do NOT use Cuppen's divide-and-conquer algorithm; instead, use QR algorithm, which I guess this algorithm uses. + + int n1=_n, errflag=2, //errflat=0 implies successful decomposition. But we start with 2 so as to let dsyev export a correct flag. + lwork=_n*BLOCKSIZE_FOR_INTEL_MKL; + double *tmpd0_m=tzMalloc(square(_n), double), + *work_p=tzMalloc(lwork, double); + + + //--------------------------- + // Obtains eigenvalues and, optionally, eigenvectors. + //--------------------------- + memcpy(tmpd0_m, s_m, square(_n)*sizeof(double)); + dsyev( (evec_m) ? "V" : "N", ((ul=='u') || (ul=='U')) ? "U" : "L", &n1, tmpd0_m, &n1, eval_v, work_p, &lwork, &errflag); + if (evec_m) memcpy(evec_m, tmpd0_m, square(_n)*sizeof(double)); + + + //--------------------------- + // Frees the allocated memory. + //--------------------------- + if (work_p[0]>lwork) printf("Warning for /mathlib.c/eigrsym_decomp(): needs at least %d workspace for good performance " + "but lwork is allocated with only %d space!\n", (int)work_p[0], lwork); + tzDestroy(tmpd0_m); + tzDestroy(work_p); + + //if (errflag<0) fn_DisplayError("/Subfolder: Calling eigrsym_decomp -- some element in input matrix has an illegal value"); + //else if (errflag>0) fn_DisplayError("/Subfolder: Calling eigrsym_decomp -- the factor U is exactly singular, so the solution cannot be computed"); + return (errflag); +} + +int eigrgen_decomp(double *evalr_v, double *evali_v, double *revecr_m, double *reveci_m, double *levecr_m, double *leveci_m, const double *x_m, const int _n) { //, const char revec_yn, const char levec_yn) { + // Outputs (dependent on Intel MKL): + // evalr_v: _n-by-1 real parts of eigenvalues; + // evali_v: _n-by-1 imaginary parts of eigenvalues; + // revecr_m: if (revecr_m==NULL), no right eigenvectors are computed; otherwise, _n-by-_n corresponding *real* parts of right eigenvectors column by column: A*v(j)=lambda(j)*v(j); + // reveci_m: if (revecr_m!=NULL) -- must be initialized to zero, _n-by-_n *imaginary* parts of right eigenvectors corresponding to revecr_m; + // levecr_m: if (levecr_m==NULL), no left eigenvectors are computed; otherwise, n-by-n corresponding *real* parts of left eigenvectors column by column: u(j)^H*A=lambda(j)*u(j)^H, where H means conjugate transpose; + // leveci_m: if (levecr_m!=NULL) -- must be initialized to zero, _n-by-_n *imaginary* parts of left eigenvectors corresponding to revecr_m; + // errflag: error flag. + //------------ + // Inputs: + // x_m: _n-by_n real general (non-symmetric) matrix. + // + // Eigenanalysis of real general (non-symmetric) square matrix with all eigenvalues and, optionally, eigenvectors. + + int n1=_n, errflag=2, //errflat=0 implies successful decomposition. But we start with 2 so as to let dgeev export a correct flag. + lwork=_n*BLOCKSIZE_FOR_INTEL_MKL, + _i, _j; + double *tmpd0_m=tzMalloc(square(_n), double), //@@Must be freed in this function.@@ + *work_p=tzMalloc(lwork, double); //@@Must be freed in this function.@@ + + //--------------------------- + // Starts with x_m -- the matrix to be decomposed. + //--------------------------- + memcpy(tmpd0_m, x_m, square(_n)*sizeof(double)); + + //--------------------------- + // Obtains eigenvalues and, optionally, eigenvectors. + //--------------------------- + dgeev( (levecr_m) ? "V" : "N", (revecr_m) ? "V" : "N", &n1, tmpd0_m, &n1, evalr_v, evali_v, + levecr_m, &n1, revecr_m, &n1, work_p, &lwork, &errflag); + + //--------------------------- + // Frees the allocated memory. + //--------------------------- + if (work_p[0]>lwork) printf("Warning for /mathlib.c/eigrgen_decomp(): needs at least %d workspace for good performance " + "but lwork is allocated with only %d space!\n", (int)work_p[0], lwork); + if (work_p) free(work_p); + if (tmpd0_m) free(tmpd0_m); + + //--------------------------- + // Checks error conditions. + // Exports final results. + //--------------------------- + //if (errflag<0) fn_DisplayError("/Subfolder: Calling eigrgen_decomp -- some element in input matrix has an illegal value"); + //else if (errflag>0) fn_DisplayError("/Subfolder: Calling eigrgen_decomp -- the QR algorithm failed to compute all the eigenvalues and no eigenvectors have been computed"); + if (errflag) return (errflag); + else { + if (revecr_m) { // Tested against Matlab output. Works! 10/13/02. + for (_j=0; _j<_n-1; _j++) + if (evali_v[_j] && (evali_v[_j] == -evali_v[_j+1])) + for (_i=0; _i<_n; _i++) { + reveci_m[_i+(_j+1)*_n] = -(reveci_m[_i+_j*_n]=revecr_m[_i+(_j+1)*_n]); + revecr_m[_i+(_j+1)*_n] = revecr_m[_i+_j*_n]; + } + } + if (levecr_m) { //Hasn't tested against any other established program, but it seems working. 10/13/02. + for (_j=0; _j<_n-1; _j++) + if (evali_v[_j] && (evali_v[_j] == -evali_v[_j+1])) + for (_i=0; _i<_n; _i++) { + leveci_m[_i+(_j+1)*_n] = -(leveci_m[_i+_j*_n]=levecr_m[_i+(_j+1)*_n]); + levecr_m[_i+(_j+1)*_n] = levecr_m[_i+_j*_n]; + } + } + return (errflag); + } +} + + + +int chol_decomp(double *D, const double *s_m, const int _n, const char ul) { + //Outputs: + // D: _n-by_n -- if ul='u' or 'U', D'*D = s_m where D is stored only at the upper triangular part; + // if ul='l' or 'L', D*D' = s_m where D is stored only at the lower triangular part. + // errflag: error flag (=0 means successful). + //-------- + //Inputs: + // s_m: _n-by-_n symmetric, positive definite matrix (whose only triangular part is used by dpotrf). + // ul: if =='u' or 'U', D (as well as s_m) is upper triangular; if =='l' or 'L', D (as well as s_m) is lower triangular. + // + // Choleski decomposition of s_m. + // For the MATLAB libriary, ul doest not apply and chol_decomp always takes the 'U' form. + // And Matlab 6.5 (R13) has a different number of inputs for mlfChol(). + // See ...\extern\include\libmatlbm.h (included by matlab.h) for the definition of mlfChol(). + // So R12 version must be used if one chooses to use the MATLAB libriary. + + #ifdef INTELCMATHLIBRARY //Intel MKL Lapack dependent code. + int errflag=2, _m=_n, _i, _j, tmpi0; //errflat=0 implies successful decomposition. But we start with 2 so as to let dpotrf export a correct flag. + + //=== Fills the triangular part that is used for Choleski decomposition. + + switch (ul) { + case 'u': case 'U': + for (_j=0; _j<_n; _j++) { + for (_i=0; _i<=_j; _i++) { + tmpi0 = _i+_j*_n; + D[tmpi0] = s_m[tmpi0]; + } + for (; _i<_n; _i++) D[_i+_j*_n] = 0.0; //Initializes the other part of D to zero so as to make it visible and readable. + } + break; + case 'l': case 'L': + for (_j=0; _j<_n; _j++) { + for (_i=0; _i<_j; _i++) D[_i+_j*_n] = 0.0; //Initializes the other part of D to zero so as to make it visible and readable. + for (; _i<_n; _i++) { + tmpi0 = _i+_j*_n; + D[tmpi0] = s_m[tmpi0]; + } + } + default: + return (-1); + } + //=== Choleski decomposition. + dpotrf(((ul=='u') || (ul=='U')) ? "U" : "L", &_m, D, &_m, &errflag); + //--- + // if (errflag<0) fn_DisplayError("Some element has an illegal value"); + // else if (errflag>0) fn_DisplayError("The leadding minor of some order, hence the entire matrix, is not positive definite"); + return (errflag); + #endif + #ifdef MATLABCMATHLIBRARY //Matlab dependent code. + mxArray *ms_m=mlfDoubleMatrix(_n, _n, s_m, NULL), //@@Must be freed in this function.@@ mx version of s_m. + *mxD=NULL, //@@Must be freed in this function.@@ mx version of D. + *mxflag; + int errflag; + + mxD = mlfChol(&mxflag, ms_m); + errflag = (int)mxGetScalar(mxflag); + //if (errflag) fn_DisplayError("Function mathlib.c\\chol_decomp(): matrix must be positive definite for choleski decomposition"); + memcpy(D, mxGetPr(mxD), square(_n)*sizeof(double)); + + //=== Frees up allocated mxArray. + mxDestroyArray(mxD); + mxDestroyArray(ms_m); + mxDestroyArray(mxflag); + + return errflag; + #endif +} + +int inv_spd(double *D, const double *s_m, const int _n, const char ul) { + // Inverse of symmetric, positive-definite matrix s_m. + // + //Outputs: + // D: _n-by_n inverse of s_m. + // errflag: error flag (=0 means successful). + //-------- + //Inputs: + // s_m: _n-by-_n symmetric, positive definite matrix (whose only triangular part is used by dpotrf). + // ul: if =='u' or 'U', D (as well as s_m) is upper triangular; if =='l' or 'L', D (as well as s_m) is lower triangular. + + int errflag=2, _m=_n, _i, _j, tmpi0; //errflat=0 implies successful decomposition. But we start with 2 so as to let dpotrf export a correct flag. + + //=== Fills the triangular part that is used for Choleski decomposition. + switch (ul) { + case 'u': case 'U': + for (_j=0; _j<_n; _j++) { + for (_i=0; _i<=_j; _i++) { + tmpi0 = _i+_j*_n; + D[tmpi0] = s_m[tmpi0]; + } + for (; _i<_n; _i++) D[_i+_j*_n] = 0.0; //Initializes the other part of D to zero so as to make it visible and readable. + } + break; + case 'l': case 'L': + for (_j=0; _j<_n; _j++) { + for (_i=0; _i<_j; _i++) D[_i+_j*_n] = 0.0; //Initializes the other part of D to zero so as to make it visible and readable. + for (; _i<_n; _i++) { + tmpi0 = _i+_j*_n; + D[tmpi0] = s_m[tmpi0]; + } + } + break; + default: + return (-1); + } + //=== Choleski decomposition. + dpotrf(((ul=='u') || (ul=='U')) ? "U" : "L", &_m, D, &_m, &errflag); + if (errflag) return (errflag); + //=== Takes inverse. + dpotri(((ul=='u') || (ul=='U')) ? "U" : "L", &_m, D, &_m, &errflag); + return (errflag); + //--- + // if (errflag<0) fn_DisplayError("Some element has an illegal value"); + // else if (errflag>0) fn_DisplayError("Not symmetric positive definite or matrix inversion cannot be computed"); +} + + + + +//======================================================= +// BLAS routines -- all based on Intel MKL (or IMSL C Math library). +//======================================================= +//void ScalingVectorUpdate(const double _alpha, TSdvector *x_dv) { +// //Output: x = alpha*x; +// // +// call dscal (n, da, DX, incx) +//} +//Use the scaling vector MKL routine. + +double VectorDotVector(TSdvector *x1_dv, TSdvector *x2_dv) { + //Output: Return sum(x1[i] * x2[i]) over i=1, ..., n. + // Allows the case x1_dv = x2_dv. + //Inputs: + // x1_dv: _n-by-1 double vector. + // x2_dv: _n-by-1 double vector. + int _n, _i; + double *x1, *x2, + sum2 = 0.0; //Cumulative: must be set to 0.0. + + if ( !x1_dv || !x2_dv ) fn_DisplayError(".../mathlib.c/VectorDotVector(): All input vectors must be created (memory-allocated)"); + + if ( (x1=x1_dv->v) == (x2=x2_dv->v) ) { + if ( !x1_dv->flag ) fn_DisplayError(".../mathlib.c/VectorDotVector(): Input vectors must be given legal values"); + for (_i=x1_dv->n-1; _i>=0; _i--) sum2 += square(x1[_i]); + } + else { + if ( (_n=x1_dv->n) != x2_dv->n ) fn_DisplayError(".../mathlib.c/VectorDotVector(): Dimensions of the two input vectors must be same"); + else if ( !x1_dv->flag || !x2_dv->flag ) fn_DisplayError(".../mathlib.c/VectorDotVector(): Both input vectors must be given legal values"); + for (_i=_n-1; _i>=0; _i--) sum2 += x1[_i]*x2[_i]; + } + + return ( sum2 ); + //return cblas_ddot(_n, x1_dv->v, 1, x2_dv->v, 1); +} + + +void ScalarTimesVectorUpdate(TSdvector *x2_dv, const double _alpha, TSdvector *x1_dv) { + //Output: x2 = alpha * x1 + x2; + //Inputs: + // alpha: a double scalar; + // x1: n-by-1 double vector. + int _n; + + if ( !x1_dv || !x2_dv ) fn_DisplayError(".../mathlib.c/ScalarTimesVectorUpdate(): All input vectors must be created (memory-allocated)"); + else _n = x1_dv->n; + + if (_n != x2_dv->n) fn_DisplayError(".../mathlib.c/ScalarTimesVectorUpdate(): All input vectors must have the same length"); + else if ( !x1_dv->flag ) fn_DisplayError(".../mathlib.c/ScalarTimesVectorUpdate(): R input vector must be given values"); + else { + if ( x1_dv->v == x2_dv->v ) fn_DisplayError(".../mathlib.c/ScalarTimesVectorUpdate(): Two input vectors cannot be the same. Instead, use SclarTimesVector() for this option if you are sure this is what you want"); + cblas_daxpy(_n, _alpha, x1_dv->v, 1, x2_dv->v, 1); + x2_dv->flag = V_DEF; + } +} + +void ScalarTimesVector(TSdvector *x_dv, const double _alpha, TSdvector *a_dv, const double _beta) { + //Output: x_dv = alpha*a_dv + beta*x_dv where x_dv is n-by-1. + // When beta=0.0 and x_dv->v = a_dv->v, x_dv->v will be replaced by new values. + //Inputs: + // a_dv: n-by-1. + // _alpha: a double scalar. + // _beta: a double scalar. + int _i, _n; + double *x, *a; + + if ( !x_dv || !a_dv ) fn_DisplayError(".../mathlib.c/ScalarTimesVector(): All input vectors must be created (memory-allocated)"); + else if ( !a_dv->flag ) fn_DisplayError(".../mathlib.c/ScalarTimesVector(): R input vector must be given values"); + else { + _n = x_dv->n; + x = x_dv->v; + a = a_dv->v; + } + + if ( _n != a_dv->n ) fn_DisplayError(".../mathlib.c/ScalarTimesVector(): Two input vectors must have the same length"); + if (_beta == 0.0) { + #if defined (INTELCMATHLIBRARY) // define: use Intek MKL LAPACK library; undef: use others. + if ( x == a ) cblas_dscal(_n, _alpha, x, 1); + else { + memcpy(x_dv->v, a_dv->v, _n*sizeof(double)); + x_dv->flag = V_DEF; + cblas_dscal(_n, _alpha, x, 1); + } + #else //SWITCHTOTZCMATH: use my own C math library (which is faster than MKL sometimes); undef: use others. + for (_i=_n-1; _i>=0; _i--) x[_i] = _alpha*a[_i]; + x_dv->flag = V_DEF; + #endif + } + else if (_beta == 1.0) { + if ( x == a ) fn_DisplayError(".../mathlib.c/ScalarTimesVector(): Two input vectors must be different, i.e., pointing to different memory places"); + cblas_daxpy(_n, _alpha, a, 1, x, 1); + x_dv->flag = V_DEF; + } + else { + if ( x == a ) fn_DisplayError(".../mathlib.c/ScalarTimesVector(): Two input vectors must be different, i.e., pointing to different memory places"); + for (_i=_n-1; _i>=0; _i--) x[_i] = _alpha*a[_i] + _beta*x[_i]; + x_dv->flag = V_DEF; + } +} + +void VectorPlusMinusVectorUpdate(TSdvector *x_dv, const TSdvector *b_dv, double _alpha) +{ + //Output: x_dv =_alpha * b_dv + x_dv where x_dv is _n-by-1. + //Inputs: + // b_dv: _n-by-1 double vector. + // _alpha: double scalar. + int _n; + + + if ( !x_dv || !b_dv ) fn_DisplayError(".../mathlib.c/VectorPlusMinusVectorUpdate(): All input vectors must be created (memory-allocated)"); + else if ( !b_dv->flag || !x_dv->flag ) fn_DisplayError(".../mathlib.c/VectorPlusMinusVectorUpdate(): All input vectors must be given values"); + else { + _n = x_dv->n; + } + if ( _n != b_dv->n ) fn_DisplayError(".../mathlib.c/VectorPlusMinusVectorUpdate(): Dimensions of all input vectors must be same"); + + cblas_daxpy(_n, _alpha, b_dv->v, 1, x_dv->v, 1); +} + +void VectorPlusMinusVector(TSdvector *x_dv, const TSdvector *a_dv, const TSdvector *b_dv, double _alpha) +{ + //???????? Use tz_VectorPlusMinusVector() or VectorPlusVector() or VectorMinusVector(). + //????????? NOT finished yet. + //????????Must add _beta for x_dv = alpha*a_dv + beta*b_dv. If x_dv=b_dv, update. + //??????????? NOT fully tested yet. + //Output: x_dv = a_dv + _alpha * b_dv where x_dv is _n-by-1. + //Inputs: + // a_dv: _n-by-1 double vector. + // b_dv: _n-by-1 double vector. + // _alpha: double scalar. + int _n; + + + if ( !x_dv || !a_dv || !b_dv ) fn_DisplayError(".../mathlib.c/VectorPlusMinusVector(): All input vectors must be created (memory-allocated)"); + else if ( !a_dv->flag || !b_dv->flag ) fn_DisplayError(".../mathlib.c/VectorPlusMinusVector(): All input vectors must be given values"); + else { + _n = x_dv->n; + } + if ( (_n != a_dv->n) || (_n != b_dv->n) ) fn_DisplayError(".../mathlib.c/VectorPlusMinusVector(): Dimensions of all input vectors must be same"); + + memcpy(x_dv->v, a_dv->v, _n*sizeof(double)); + cblas_daxpy(_n, _alpha, b_dv->v, 1, x_dv->v, 1); +} + +void VectorTimesSelf(TSdmatrix *C_dm, const TSdvector *a_dv, const double _alpha, const double _beta, const char ul) +{ + //Computes C = alpah*a*a' + beta*C where + // Output: + // the symmetric matrix C. + // Inputs: + // a is m-by-1, + // C is m-by-m symmetric matrix, + // alpha: a double scalar, + // beta: a double scalar. + // ul: if=='U' or 'u', only the upper triangular part of C is to be referenced; otherwise, only the lower triangular part of C is to be referenced; + int _m, _n; + int _i, _j; + double *v, *M; + + if ( !C_dm || !a_dv ) fn_DisplayError(".../mathlib.c/VectorTimesSelf(): At least one of the pointer arguments is not created (memory-allocated)"); + else if (!a_dv->flag) fn_DisplayError(".../mathlib.c/VectorTimesSelf(): Input vector must have legal values"); + else { + _m = C_dm->nrows; + _n = C_dm->ncols; + } + + if ( (_m != a_dv->n) || (_m !=_n) ) fn_DisplayError(".../mathlib.c/VectorTimesSelf(): (1) Size of the input matrix and dimensions of the two input vectors do not match. (2) Output matrix must be square"); + else { + if ( _beta == 1.0 ) { + #if defined (INTELCMATHLIBRARY) // define: use Intek MKL LAPACK library; undef: use others. + //$$$$ cblas_dsyrk is much slower than the following line. cblas_dsyrk(CblasColMajor, ((ul=='u') || (ul=='U')) ? CblasUpper : CblasLower, CblasNoTrans, _m, 1, _alpha, a_dv->v, _m, _beta, C_dm->M, _m); + cblas_dsyr(CblasColMajor, ((ul=='U') || (ul=='u')) ? CblasUpper : CblasLower, _m, _alpha, a_dv->v, 1, C_dm->M, _m); + C_dm->flag = ((ul=='U') || (ul=='u')) ? M_SU : M_SL; + #else //Corresponds to the default: SWITCHTOTZCMATH -- use my own C math library, which is faster than cblas_dsyrk(). + v = a_dv->v; + M = C_dm->M; + if ( (ul == 'U') || (ul == 'u') ) { + C_dm->flag = M_SU; + if ( _alpha==1.0 ) { + for ( _j=0; _j<_m; _j++ ) { + for ( _i=0; _i<=_j; _i++ ) { + M[mos(_i, _j, _m)] += v[_i] * v[_j]; + } + } + } + else { + for ( _j=0; _j<_m; _j++ ) { + for ( _i=0; _i<=_j; _i++ ) { + M[mos(_i, _j, _m)] += _alpha * v[_i] * v[_j]; + } + } + } + } + else { + C_dm->flag = M_SL; + if ( _alpha==1.0 ) { + for ( _j=0; _j<_m; _j++ ) { + for ( _i=_j; _i<_m; _i++ ) { + M[mos(_i, _j, _m)] += v[_i] * v[_j]; + } + } + } + else { + for ( _j=0; _j<_m; _j++ ) { + for ( _i=_j; _i<_m; _i++ ) { + M[mos(_i, _j, _m)] += _alpha * v[_i] * v[_j]; + } + } + } + } + #endif + } + else { + //Corresponds to the default: SWITCHTOTZCMATH -- use my own C math library (which is faster than MKL sometimes). + v = a_dv->v; + M = C_dm->M; + if ( (ul == 'U') || (ul == 'u') ) { + C_dm->flag = M_SU; + if ( _alpha==1.0 ) { + for ( _j=0; _j<_m; _j++ ) { + for ( _i=0; _i<=_j; _i++ ) { + M[mos(_i, _j, _m)] = v[_i] * v[_j] + _beta*M[mos(_i, _j, _m)]; + } + } + } + else { + if ( _beta==0.0 ) { + for ( _j=0; _j<_m; _j++ ) { + for ( _i=0; _i<=_j; _i++ ) { + M[mos(_i, _j, _m)] = _alpha * v[_i] * v[_j]; + } + } + } + else { + for ( _j=0; _j<_m; _j++ ) { + for ( _i=0; _i<=_j; _i++ ) { + M[mos(_i, _j, _m)] = _alpha* v[_i] * v[_j] + _beta*M[mos(_i, _j, _m)]; + } + } + } + } + } + else { + C_dm->flag = M_SL; + if ( _alpha==1.0 ) { + if ( _beta==0.0 ) { + for ( _j=0; _j<_m; _j++ ) { + for ( _i=_j; _i<_m; _i++ ) { + M[mos(_i, _j, _m)] = v[_i] * v[_j]; + } + } + } + else { + for ( _j=0; _j<_m; _j++ ) { + for ( _i=_j; _i<_m; _i++ ) { + M[mos(_i, _j, _m)] = v[_i] * v[_j] + _beta*M[mos(_i, _j, _m)]; + } + } + } + } + else { + if ( _beta==0.0 ) { + for ( _j=0; _j<_m; _j++ ) { + for ( _i=_j; _i<_m; _i++ ) { + M[mos(_i, _j, _m)] = _alpha * v[_i] * v[_j]; + } + } + } + else { + for ( _j=0; _j<_m; _j++ ) { + for ( _i=_j; _i<_m; _i++ ) { + M[mos(_i, _j, _m)] = _alpha* v[_i] * v[_j] + _beta*M[mos(_i, _j, _m)]; + } + } + } + } + } + } + } +} + +#if defined (INTELCMATHLIBRARY) +void VectorTimesVector(TSdmatrix *C_dm, const TSdvector *a_dv, const TSdvector *b_dv, const double _alpha, const double _beta) { + //?????? NOT tested for _beta != 1.0. + //Output is the matrix C and all other arguments are inputs. + //If beta != 0, always converting C (if symmetric or trianuglar) to a general matrix before the operation. + //The fastest way is to let _beta = 1.0. + //Computes C = alpah*a*b' + beta*C where + // a is m-by-1, + // b is n-by-1, + // C is m-by-n general matrix, + // alpha: a double scalar, + // beta: a double scalar. + int _m, _n; + + if ( !C_dm || !a_dv || !b_dv ) fn_DisplayError(".../mathlib.c/VectorTimesVector(): At least one of the pointer arguments is not created (memory-allocated)"); + else if ( !a_dv->flag || !b_dv->flag ) fn_DisplayError(".../mathlib.c/VectorTimesVector(): Both input R vectors must be given values"); + else { + _m = C_dm->nrows; + _n = C_dm->ncols; + } + if (_beta != 0.0) { + if ( !(C_dm->flag & M_GE) && (_m = _n) ) { + if (C_dm->flag & M_SU) SUtoGE(C_dm); + else if (C_dm->flag & M_SL) SLtoGE(C_dm); + else fn_DisplayError(".../mathlib.c/VectorTimesVector(): (a) make sure C_dm has legal values; (b) for M_UT and M_LT, I have not got time to convert it to a general matrix"); + } + } + + + + if ( (_m != a_dv->n) || (_n != b_dv->n) ) fn_DisplayError(".../mathlib.c/VectorTimesVector(): Size of the input matrix and dimensions of the two input vectors do not match"); + else { + if (_beta==1.0) { + cblas_dger(CblasColMajor, _m, _n, _alpha, a_dv->v, 1, b_dv->v, 1, C_dm->M, _m); + C_dm->flag = M_GE; + } + else { + cblas_dgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, _m, _n, 1, _alpha, a_dv->v, _m, b_dv->v, 1, _beta, C_dm->M, _m); + //???????????The above is probably too slow. Try the following two lines instead. 3/10/03. + //????? Test to make sure this works for beta=0. + //cblas_dscal(_m*_n, _beta, C_dm->M, 1); + //cblas_dger(CblasColMajor, _m, _n, _alpha, a_dv->v, 1, b_dv->v, 1, C_dm->M, _m); + C_dm->flag = M_GE; + } + } +} +#else +//No default routine yet. +#endif + + +void MatrixPlusMinusMatrixUpdate(TSdmatrix *X_dm, TSdmatrix *A_dm, double _alpha) +{ + //$$$$$ If A_dm or X_dm is only upper or lower symmetric, it will be always converted to a general (and symmetric) matrix. $$$$$$ + //Output: X =_alpha * A + X where X_dm is an m-by-n general (and possibly symmetric) matrix. + //Inputs: + // A_dm: m-by-n general or symmetric matrix. + // _alpha: double scalar. + int _m, _n, nels; + + + if ( !X_dm || !A_dm ) fn_DisplayError(".../mathlib.c/MatrixPlusMinusMatrixUpdate(): All input matrices must be created (memory-allocated)"); + else if ( !X_dm->flag || !A_dm->flag ) fn_DisplayError(".../mathlib.c/MatrixPlusMinusMatrixUpdate(): Both input matrices must be given values"); + else { + _m = X_dm->nrows; + _n = X_dm->ncols; + nels = _m * _n; + } + + if ( (_m != A_dm->nrows) || (_n != A_dm->ncols) ) fn_DisplayError(".../mathlib.c/MatrixPlusMinusMatrixUpdate(): Dimensions of all input matrices must be same"); + + //=== Making both X_dm and A_dm general if not yet. + if ( !(X_dm->flag & M_GE) ) { + if (X_dm->flag & M_SU) SUtoGE(X_dm); + else if (X_dm->flag & M_SL) SLtoGE(X_dm); + else fn_DisplayError(".../mathlib.c/MatrixPlusMinusMatrixUpdate(): Haven't got time to deal with the M_UT and M_LT cases for X_dm"); + } + if ( !(A_dm->flag & M_GE) ) { + if (A_dm->flag & M_SU) SUtoGE(A_dm); + else if (A_dm->flag & M_SL) SLtoGE(A_dm); + else fn_DisplayError(".../mathlib.c/MatrixPlusMinusMatrixUpdate(): Haven't got time to deal with the M_UT and M_LT cases for A_dm"); + } + + cblas_daxpy(nels, _alpha, A_dm->M, 1, X_dm->M, 1); //This operation may be much cheaper than explicitly using SU or SL operations with two for loops and integer multiplications for matrix offsets. + + if ( X_dm->flag != A_dm->flag ) { + //printf("WARNING for .../mathlib.c/MatrixPlusMinusMatrixUpdate(): the two input matrices do not have the same matrix type (or flag), so the output matrix is reset to M_GE"); + X_dm->flag = M_GE; //Reset to a general matrix only; otherwise, keep the original X_dm->flag. + } + //if ( X_dm->flag != A_dm->flag ) fn_DisplayError(".../mathlib.c/MatrixPlusMinusMatrixUpdate(): both input matrices must have the same matrix type (or flag)"); +} + +void MatrixTimesVector(TSdvector *x_dv, TSdmatrix *A_dm, const TSdvector *b_dv, const double _alpha, const double _beta, const char tn) +{ + //WARNING: x_dv must NOT be the same as b_dv! + // + //Output: x_dv = _alpha*A_dm'*b_dv + _beta*x_dv for tn=='T'; x_dv = _alpha*A_dm*b_dv + _beta*x_dv for tn=='N' + // where x_dv->v is ncols-by-1 or nrows-by-1 and needs not be initialized outside this function if _beta is set to 0.0. + //Inputs: + // A_dm->M: nrows-by-ncols; + // b_dv->v: nrows-by-1 or ncols-by-1; + // _alpha: double scalar; + // _beta: double scalar; + // tn: if =='T' or 't', transpose of A_dm is used; otherwise, A_dm itself (no transpose) is used. + + if ( !x_dv || !A_dm || !b_dv) fn_DisplayError(".../mathlib.c/MatrixTimesVector(): At least one of the pointer arguments is not created (memory-allocated)"); + else if ( !A_dm->flag || !b_dv->flag ) fn_DisplayError(".../mathlib.c/MatrixTimesVector(): R input matrix or vector must be given values"); + if ( !(A_dm->flag & M_GE) ) { + if (A_dm->flag & M_SU) SUtoGE(A_dm); + else if (A_dm->flag & M_SL) SLtoGE(A_dm); + else fn_DisplayError(".../mathlib.c/MatrixTimesVector(): For M_UT and M_LT, use TrimatrixTimesVector() instead"); + } + + + if ((tn=='T' || tn=='t') && (A_dm->nrows==b_dv->n) && (A_dm->ncols==x_dv->n)) { + cblas_dgemv(CblasColMajor, CblasTrans, A_dm->nrows, A_dm->ncols, _alpha, A_dm->M, A_dm->nrows, b_dv->v, 1, _beta, x_dv->v, 1); + x_dv->flag = V_DEF; + } + else if ( (A_dm->ncols==b_dv->n) && (A_dm->nrows==x_dv->n) ) { + cblas_dgemv(CblasColMajor, CblasNoTrans, A_dm->nrows, A_dm->ncols, _alpha, A_dm->M, A_dm->nrows, b_dv->v, 1, _beta, x_dv->v, 1); + x_dv->flag = V_DEF; + } +//--- The following if clause is wrong because, when tn=='N', A_dm->ncols == b_dv->n, NOT A_dm->nraws==b_dv_>n. +// if ((A_dm->nrows==b_dv->n) && (A_dm->ncols==x_dv->n)) { +// cblas_dgemv(CblasColMajor, (tn=='T' || tn=='t') ? CblasTrans : CblasNoTrans, A_dm->nrows, A_dm->ncols, _alpha, A_dm->M, A_dm->nrows, b_dv->v, 1, _beta, x_dv->v, 1); +// x_dv->flag = V_DEF; +// } + else fn_DisplayError(".../mathlib.c/MatrixTimesVector(): Size of the input matrix and dimensions of the two input vectors do not match"); +} + + +#if defined (INTELCMATHLIBRARY) +void TrimatrixTimesVector(TSdvector *x_dv, TSdmatrix *A_dm, TSdvector *b_dv, const char tn, const char un) +{ + //Output: x_dv = A_dm'*b_dv for tn=='T'; x_dv = A_dm*b_dv for tn=='N' where x_dv->v is _n-by-1. + // If x_dv = b_dv (which gives the fastest return, so try to use this option when possible), x_dv will be relaced by A*b or A'*b. + //Inputs: + // A_dm->M: _n-by-_n triangular matrix. + // b_dv->v: _n-by-1 vector. + // tn: if =='T' or 't', transpose of A_dm is used; otherwise, A_dm itself (no transpose) is used. + // un: if =='U' or 'u', A_dm is unit triangular; otherwise, A_dm is non-unit triangular (i.e., a regular triangular matrix). + + int _n; +// double *x, *b; + + if ( !x_dv || !A_dm || !b_dv) fn_DisplayError(".../mathlib.c/TrimatrixTimesVector(): At least one of the pointer arguments is not created (memory-allocated)"); + else if ( !A_dm->flag || !b_dv->flag ) fn_DisplayError(".../mathlib.c/TrimatrixTimesVector(): R input matrix or vector must be given values"); + else if ( ((_n = A_dm->nrows) != x_dv->n) ) fn_DisplayError(".../mathlib.c/TrimatrixTimesVector(): Size of input matrix and dimension of input vector must match"); + else if ( !(A_dm->flag & (M_UT | M_LT) ) ) fn_DisplayError(".../mathlib.c/TrimatrixTimesVector(): Make sure R matrix is triangular (i.e., M_UT or M_LT)"); + +// if ( (x = x_dv->v) == (b = b_dv->v) ) //Commented out on 22 Oct 03. + if ( x_dv == b_dv ) + cblas_dtrmv(CblasColMajor, (A_dm->flag & M_UT) ? CblasUpper : CblasLower, (tn=='T' || tn=='t') ? CblasTrans : CblasNoTrans, (un=='U' || un=='u') ? CblasUnit : CblasNonUnit, A_dm->nrows, A_dm->M, A_dm->nrows, x_dv->v, 1); + else { + if ( _n != b_dv->n ) fn_DisplayError(".../mathlib.c/TrimatrixTimesVector(): Two vectors must have the same length"); + memcpy(x_dv->v, b_dv->v, _n*sizeof(double)); + cblas_dtrmv(CblasColMajor, (A_dm->flag & M_UT) ? CblasUpper : CblasLower, (tn=='T' || tn=='t') ? CblasTrans : CblasNoTrans, (un=='U' || un=='u') ? CblasUnit : CblasNonUnit, A_dm->nrows, A_dm->M, A_dm->nrows, x_dv->v, 1); + x_dv->flag = V_DEF; + } +} +#else +//No default routine yet. +#endif + + +#if defined (INTELCMATHLIBRARY) +void SymmatrixTimesVector(TSdvector *x_dv, TSdmatrix *A_dm, TSdvector *b_dv, const double _alpha, const double _beta) +{ + //????? This is NOT checked yet: If x_dv = b_dv, x_dv or b_dv will be relaced by alpha*A*x + beta*x. + //Output: + // x_dv = alpha*A_dm*b_dv + beta*x_dv where x_dv->v is _n-by-1. + // When beta=0, there is no need to initialize the value of x_dv. + //Inputs: + // A_dm->M: _n-by-_n triangular matrix. + // b_dv->v: _n-by-1 vector. + // _alpha: double scalar; + // _beta: double scalar; + + int _n; + + if ( !x_dv || !A_dm || !b_dv) fn_DisplayError(".../mathlib.c/SymmatrixTimesVector(): all input and output arguments must be created (memory-allocated)"); + else if ( !A_dm->flag || !b_dv->flag ) fn_DisplayError(".../mathlib.c/SymmatrixTimesVector(): R input matrix or vector must be given values"); + else if ( ((_n = A_dm->nrows) != x_dv->n) || (_n != b_dv->n) ) fn_DisplayError(".../mathlib.c/SymmatrixTimesVector(): Size of input matrix and dimensions of input and output vectors must all match"); + else if ( !(A_dm->flag & (M_SU | M_SL) ) ) fn_DisplayError(".../mathlib.c/SymmatrixTimesVector(): Make sure R input matrix is symmetric (i.e., M_SU or M_SL)"); + + cblas_dsymv(CblasColMajor, (A_dm->flag & M_SU) ? CblasUpper : CblasLower, _n, _alpha, A_dm->M, _n, b_dv->v, 1, _beta, x_dv->v, 1); + x_dv->flag = V_DEF; +} +#else +//No default routine yet. +#endif + + + +void VectorTimesMatrix(TSdvector *x_dv, const TSdvector *b_dv, TSdmatrix *A_dm, const double _alpha, const double _beta, const char tn) { + //Note this function is exactly the opposite of MatrixTimeVector (which is based on the MKL default). + // + //Output: x_dv->v = _alpha*b_dv*A_dm + _beta*x_dv for tn=='N'; x_dv = _alpha*b_dv*A_dm' + _beta*x_dv for tn=='T' + // where x_dv->v is 1-by-ncols or 1-by-nrows and needs not be initialized outside this function if _beta is set to 0.0. + //Inputs: + // A_dm->M: nrows-by-ncols; + // b_dv->v: 1-by-nrows or 1-by-ncols; + // _alpha: double scalar; + // _beta: double scalar; + // tn: if =='T' or 't', transpose of A_dm is used; otherwise (=='N' or 'n'), A_dm itself (no transpose) is used. + + if ( !x_dv || !A_dm || !b_dv) fn_DisplayError(".../mathlib.c/VectorTimesMatrix(): At least one of the pointer arguments is not created (memory-allocated)"); + else if ( !A_dm->flag || !b_dv->flag ) fn_DisplayError(".../mathlib.c/VectorTimesMatrix(): R input matrix or vector must be given values"); + + if ( !(A_dm->flag & M_GE) ) { + if (A_dm->flag & M_SU) SUtoGE(A_dm); + else if (A_dm->flag & M_SL) SLtoGE(A_dm); + else fn_DisplayError(".../mathlib.c/VectorTimesMatrix(): Haven't got time to deal with the M_UT and M_LT cases for A_dm"); + } + + + if ( ((tn=='T') || (tn=='t')) && (A_dm->ncols==b_dv->n) && (A_dm->nrows==x_dv->n)) { + cblas_dgemv(CblasColMajor, CblasNoTrans, A_dm->nrows, A_dm->ncols, _alpha, A_dm->M, A_dm->nrows, b_dv->v, 1, _beta, x_dv->v, 1); + x_dv->flag = V_DEF; + } + else if ( (A_dm->nrows==b_dv->n) && (A_dm->ncols==x_dv->n) ) { + cblas_dgemv(CblasColMajor, CblasTrans, A_dm->nrows, A_dm->ncols, _alpha, A_dm->M, A_dm->nrows, b_dv->v, 1, _beta, x_dv->v, 1); + x_dv->flag = V_DEF; + } + else { + fn_DisplayError(".../mathlib.c/VectorTimesMatrix(): Size of the matrix and dimensions of the two vectors do not match"); + } +} + +void ScalarTimesMatrix(TSdmatrix *x_dm, const double _alpha, TSdmatrix *a_dm, const double _beta) +{ + //$$$$$ If a_dm or x_dm (when _beta!=0) is only upper or lower symmetric, it will be always converted to a general (and symmetric) matrix. $$$$$$ + //Output: x_dm = alpha*a_dm + beta*x_dm where x_dm is m-by-n. + // Fastest way is to let beta=0.0 and x_dm->M = a_dm->M. Then x_dm->M will be replaced by new values. + // However, with beta=0.0, x_dm and a_dm can be different. + //Inputs: + // a_dm: m-by-n. + // _alpha: a double scalar. + // _beta: a double scalar. + int _i, _m, _n, nels; + double *X, *A; + + if ( !x_dm || !a_dm ) fn_DisplayError(".../mathlib.c/ScalarTimesMatrix(): All input matrices must be created (memory-allocated)"); + else if ( _beta != 0 && !x_dm->flag ) fn_DisplayError(".../mathlib.c/ScalarTimesMatrix(): Input and output matrix must be given legal values because beta != 0"); + else if ( !a_dm->flag ) fn_DisplayError(".../mathlib.c/ScalarTimesMatrix(): R input matrix must be given legal values"); + else { + _m = x_dm->nrows; + _n = x_dm->ncols; + nels = _m*_n; + X = x_dm->M; + A = a_dm->M; + } + + if ( !(a_dm->flag & M_GE) ) { + if (a_dm->flag & M_SU) SUtoGE(a_dm); + else if (a_dm->flag & M_SL) SLtoGE(a_dm); + else fn_DisplayError(".../mathlib.c/ScalarTimesMatrix(): Haven't got time to deal with the M_UT or M_LT cases for a_dm"); + } + if ( _beta && !(x_dm->flag & M_GE) ) { + if (x_dm->flag & M_SU) SUtoGE(x_dm); + else if (x_dm->flag & M_SL) SLtoGE(x_dm); + else fn_DisplayError(".../mathlib.c/ScalarTimesMatrix(): Haven't got time to deal with the M_UT or M_LT cases for x_dm"); + } + + if ( (_m != a_dm->nrows) || (_n != a_dm->ncols) ) fn_DisplayError(".../mathlib.c/ScalarTimesMatrix(): Two input matrices must have the same dimension"); + if (_beta == 0.0) { + #if defined( SWITCHTOINTELCMATH ) // define: use Intek MKL LAPACK library; undef: use others. + if ( X == A ) cblas_dscal(nels, _alpha, X, 1); + else { + memcpy(X, A, nels*sizeof(double)); + x_dm->flag = a_dm->flag; + cblas_dscal(nels, _alpha, X, 1); + } + #else //My own C math library (which is faster than MKL sometimes); undef: use others. + for (_i=nels-1; _i>=0; _i--) X[_i] = _alpha*A[_i]; + x_dm->flag = a_dm->flag; + #endif + } + else if (_beta == 1.0) { + #if defined( SWITCHTOINTELCMATH ) // define: use Intek MKL LAPACK library; undef: use others. + if ( X == A ) for (_i=nels-1; _i>=0; _i--) X[_i] += _alpha*A[_i]; //fn_DisplayError(".../mathlib.c/ScalarTimesMatrix(): to use cblas_daxpy(), the two input matrices must be different, i.e., pointing to different memory places"); + else cblas_daxpy(nels, _alpha, A, 1, X, 1); + #else + for (_i=nels-1; _i>=0; _i--) X[_i] += _alpha*A[_i]; + #endif + if ( x_dm->flag != a_dm->flag ) x_dm->flag = M_GE; + } + else if (_alpha == _beta) { + //if ( X == A ) fn_DisplayError(".../mathlib.c/ScalarTimesMatrix(): Two input matrices must be different, i.e., pointing to different memory places"); + //=== Intel library is at least twice as slow as my own loop for a large matarix like 100-by-100 and can be 20 times slower for a small matrix like 15-by-15. + //=== So I don't use Intel library for this. + // #ifdef SWITCHTOINTELCMATH // define: use Intek MKL LAPACK library; undef: use others. + // cblas_daxpy(nels, 1.0, A, 1, X, 1); + // cblas_dscal(nels, _alpha, X, 1); + // #endif + // #ifdef SWITCHTOTZCMATH // define: use my own C math library (which is faster than MKL sometimes); undef: use others. + // for (_i=nels-1; _i>=0; _i--) X[_i] = _alpha*(A[_i] + X[_i]); + // #endif + if (!(x_dm->flag & M_GE)) fn_DisplayError(".../mathlib.c/ScalarTimesMatrix(): x_dm must be M_GE" + " -- have not got time to convert other matrices to a general matrix"); + for (_i=nels-1; _i>=0; _i--) X[_i] = _alpha*(A[_i] + X[_i]); + if ( x_dm->flag != a_dm->flag ) x_dm->flag = M_GE; + } + else { + //if ( X == A ) fn_DisplayError(".../mathlib.c/ScalarTimesMatrix(): Two input matrices must be different, i.e., pointing to different memory places"); + if (!(x_dm->flag & M_GE)) fn_DisplayError(".../mathlib.c/ScalarTimesMatrix(): x_dm must be M_GE" + " -- have not got time to convert other matrices to a general matrix"); + for (_i=nels-1; _i>=0; _i--) X[_i] = _alpha*A[_i] + _beta*X[_i]; + if ( x_dm->flag != a_dm->flag ) x_dm->flag = M_GE; + } +} +//--- +void ScalarTimesMatrixSquare(TSdmatrix *B_dm, const double _alpha, TSdmatrix *A_dm, const char tn, const double _beta) +{ + //Outputs: + // B = alpha*o(A) + beta*B, where o(A) = A' if tn=='T' or 't' or A if tn=='N' or 'n'. + // If A=B, then A is replaced by alpha*o(A) + beta*A. + //Inputs: + // A_dm: n-by-n square matrix. + // B_dm: n-by-n square matrix. + // tn: 'T' (transpose of A) or 'N' (no transpose). + // alpha, beta: double scalars. + + int _n = A_dm->nrows; + TSdmatrix *Atran_dm = NULL; + + if (!A_dm || !B_dm) fn_DisplayError(".../mathlib.c/ScalarTimesMatrixSquare(): A_dm and B_dm must be created (memory-allocated)"); + if (A_dm->nrows != A_dm->ncols) fn_DisplayError(".../mathlib.c/ScalarTimesMatrixSquare(): A_dm must be square"); + + if (A_dm->M == B_dm->M) + { + if ((tn == 'T') || (tn == 't')) + { + Atran_dm = CreateMatrix_lf(_n,_n); + TransposeSquare(Atran_dm, A_dm); + ScalarTimesMatrix(A_dm, _alpha, Atran_dm, _beta); + } + else + { + ScalarTimesMatrix(A_dm, _alpha, A_dm, _beta); + } + } + else + { + if ((B_dm->nrows != B_dm->ncols) || (B_dm->nrows != A_dm->nrows)) fn_DisplayError(".../mathlib.c/ScalarTimesMatrixSquare(): B_dm must be square and B_dm=A_dm"); + if ((tn == 'T') || (tn == 't')) + { + Atran_dm = CreateMatrix_lf(_n,_n); + TransposeSquare(Atran_dm, A_dm); + ScalarTimesMatrix(B_dm, _alpha, Atran_dm, _beta); + } + else + { + ScalarTimesMatrix(B_dm, _alpha, A_dm, _beta); + } + } + + //=== + DestroyMatrix_lf(Atran_dm); +} + + + +void MatrixTimesSelf(TSdmatrix *C_dm, const char ul, TSdmatrix *A_dm, const char tn, const double _alpha, const double _beta) +{ + //If tn=='N' or 'n', C = alpha*A*A' + beta*C. + //If tn=='T' or 't', C = alpha*A'*A + beta*C. + //If ul=='U' or 'u', C_dm->flag = M_SU; + //If ul=='L' or 'l', C_dm->flag = M_SL; + // C must be different from A. + // C is n-by-n; + // A is n-by-k if tn=='N'; + // k-by-n if tn=='T'; + // alpha is a double scalar, + // beta is a double scalar. + int _n, _k, lda; + + if ( !C_dm || !A_dm ) fn_DisplayError(".../mathlib.c/MatrixTimesSelf): All input and output matrices must be created (memory-allocated)"); + else if ( !A_dm->flag ) fn_DisplayError(".../mathlib.c/MatrixTimesSelf): Both R input matrices must be given values"); + //=== Making this matrix general if not yet. + if ( !(A_dm->flag & M_GE) ) { + if (A_dm->flag & M_SU) SUtoGE(A_dm); + else if (A_dm->flag & M_SL) SLtoGE(A_dm); + else fn_DisplayError(".../mathlib.c/MatrixTimesSelf): Haven't got time to deal with the M_UT or M_LT cases for A_dm"); + } + + + if ((tn=='T') || (tn=='t')) { + if (((_n=C_dm->nrows) != A_dm->ncols)) fn_DisplayError(".../mathlib.c/MatrixTimesSelf): Dimensions of A and C do not match where C = alpha*A'*A + beta*C"); + else if (_n != C_dm->ncols) fn_DisplayError(".../mathlib.c/MatrixTimesSelf): Output matrix C must be a square matrix"); + lda = _k = A_dm->nrows; + } + else { + if ((_n=C_dm->nrows) != (lda=A_dm->nrows)) fn_DisplayError(".../mathlib.c/MatrixTimesSelf): Dimensions of A and C do not match where C = alpha*A*A' + beta*C"); + else if (_n != C_dm->ncols) fn_DisplayError(".../mathlib.c/MatrixTimesSelf): Output matrix C must be a square matrix"); + _k = A_dm->ncols; + } + + cblas_dsyrk(CblasColMajor, ((ul=='U') || (ul=='u')) ? CblasUpper : CblasLower, ((tn=='T') || (tn=='t')) ? CblasTrans : CblasNoTrans, _n, _k, _alpha, A_dm->M, lda, _beta, C_dm->M, _n); + C_dm->flag = ((ul=='U') || (ul=='u')) ? M_SU : M_SL; +} + + +void MatrixTimesMatrix(TSdmatrix *C_dm, TSdmatrix *A_dm, TSdmatrix *B_dm, const double _alpha, const double _beta, const char tn1, const char tn2) { + //Output is C and all other arguments are inputs. + //Computes C = alpah*op(A)*op(B) + beta*C where op() is either transpose or not, depending on 't' or 'n', + // op(A) is m-by-k, + // op(B) is k-by-n, + // C is m-by-n, + // C must be different from A and from B. + // A and B can be the same, however. + // alpha is a double scalar, + // beta is a double scalar. + // tn1: if == 'T' or 't', the transpose of A is used; otherwise (== 'N' or 'n'), A itself (no transpose) is used. + // tn2: if == 'T' or 't', the transpose of B is used; otherwise (== 'N' or 'n'), B itself (no transpose) is used. + int m1, n1, m2, n2, m3, n3; + + if ( !C_dm || !A_dm || !B_dm ) fn_DisplayError(".../mathlib.c/MatrixTimesMatrix(): All input and output matrices must be created (memory-allocated)"); + else if ( !A_dm->flag || !B_dm->flag ) fn_DisplayError(".../mathlib.c/MatrixTimesMatrix(): Both R input matrices must be given values"); + else { + m1 = A_dm->nrows; + n1 = A_dm->ncols; + m2 = B_dm->nrows; + n2 = B_dm->ncols; + m3 = C_dm->nrows; + n3 = C_dm->ncols; + } + if ( (_beta != 0.0) && !(C_dm->flag) ) fn_DisplayError(".../mathlib.c/MatrixTimesMatrix(): L input matrix C_dm must be given values when beta !=0.0 (i.e., when C_dm is to be particially updated)"); + + + //=== Making these matrices general if not yet. For complete symmetric matrix multiplications, do use this function. + if ( !(A_dm->flag & M_GE) ) { + if (A_dm->flag & M_SU) SUtoGE(A_dm); + else if (A_dm->flag & M_SL) SLtoGE(A_dm); + else fn_DisplayError(".../mathlib.c/MatrixTimesMatrix(): Haven't got time to deal with the M_UT or M_LT cases for A_dm"); + } + if ( !(B_dm->flag & M_GE) ) { + if (B_dm->flag & M_SU) SUtoGE(B_dm); + else if (B_dm->flag & M_SL) SLtoGE(B_dm); + else fn_DisplayError(".../mathlib.c/MatrixTimesMatrix(): Haven't got time to deal with the M_UT or M_LT cases for B_dm"); + } + + + + if ( ((tn1=='N') || (tn1=='n')) && ((tn2=='N') || (tn2=='n')) && (n1 == m2) && (m3 == m1) && (n3 == n2) ) { + cblas_dgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, m3, n3, n1, _alpha, A_dm->M, m1, B_dm->M, m2, _beta, C_dm->M, m3); + C_dm->flag = M_GE; + } + else if ( ((tn1=='T') || (tn1=='t')) && ((tn2=='N') || (tn2=='n')) && (m1 == m2) && (m3 == n1) && (n3 == n2) ) { + cblas_dgemm(CblasColMajor, CblasTrans, CblasNoTrans, m3, n3, m1, _alpha, A_dm->M, m1, B_dm->M, m2, _beta, C_dm->M, m3); + C_dm->flag = M_GE; + } + else if ( ((tn1=='T') || (tn1=='t')) && ((tn2=='T') || (tn2=='t')) && (m1 == n2) && (m3 == n1) && (n3 == m2) ) { + cblas_dgemm(CblasColMajor, CblasTrans, CblasTrans, m3, n3, m1, _alpha, A_dm->M, m1, B_dm->M, m2, _beta, C_dm->M, m3); + C_dm->flag = M_GE; + } + else if ( ((tn1=='N') || (tn1=='n')) && ((tn2=='T') || (tn2=='t')) && (n1 == n2) && (m3 == m1) && (n3 == m2) ) { + cblas_dgemm(CblasColMajor, CblasNoTrans, CblasTrans, m3, n3, n1, _alpha, A_dm->M, m1, B_dm->M, m2, _beta, C_dm->M, m3); + C_dm->flag = M_GE; + } + else fn_DisplayError(".../mathlib.c/MatrixTimesMatrix(): (1) Dimensions of both R input matrices must match. (2) Dimension of L input matrix must compatible with the multiplication of the two R input matrices"); +} + +void SolveTriSysVector(TSdvector *x_dv, const TSdmatrix *T_dm, TSdvector *b_dv, const char tn, const char un) +{ + //Output: computes x_dv = inv(T_dm)*b_dv by solving a triangular system of equation T_dm * x_dv = b_dv. + // x_dv(_n-by-1) = inv(T_dm)*b_v if tn=='N'; = inv(T_dm')*b_v if tn=='T'. + // Fastest way is to let x_dv->v = b_dv->v. Then, x_dv->v will be replaced by new values. + //------- + //Inputs: + // T_dm: _n-by-_n upper or lower triangular matrix; + // b_dv: _n-by-1 vector. + // tn: if =='T' or 't', T_dm->M' (transpose), instead of T_m, will be used; otherwise (i.e., =='n' or 'N'), T_dm->M itself (no transpose) will be used. + // un: if =='U' or 'u', T_dm is a unit upper triangular (i.e., the diagonal being 1); + // otherwise (i.e., if =='N' or 'n'), T_dm is a non-unit upper triangular. + // + // Note I: Intel MLK cblas_dtrsv() does not test for singularity or near-singulariy of the system. + // Such tests must be performed before calling this BLAS routine. + // Note II: if x_dv->v = b_dv->v, x_dv->v will be replaced by new values. + int _n, _i; + double *x, *b; + + if ( !T_dm || !b_dv || !x_dv ) fn_DisplayError(".../mathlib.c/SolveTriSysVector(): All input pointers must be created (memory-allocated)"); + else if ( !( T_dm->flag & (M_UT | M_LT) ) || !b_dv->flag ) fn_DisplayError(".../mathlib.c/SolveTriSysVector(): (1) R input matrix must be triangular. (2) R input vector must be given legal values"); + else { + _n = T_dm->nrows; + x = x_dv->v; + b = b_dv->v; + } + + for (_i=square(_n)-1; _i>=0; _i -= _n+1) + if (fabs(T_dm->M[_i])<=MACHINEZERO) + fn_DisplayError(".../mathlib.c/SolveTriSysVector(): The input triangular matrix is singular"); + + + if ( (_n != T_dm->ncols) || (_n != b_dv->n) || (_n != x_dv->n) ) fn_DisplayError(".../mathlib.c/SolveTriSysVector(): (1) R input matrix must be square. (2) Input vectors and the square matrix must have the same dimension"); + else if ( x == b) { + cblas_dtrsv(CblasColMajor, ( T_dm->flag & M_UT ) ? CblasUpper : CblasLower, + ((tn=='T') || (tn=='t')) ? CblasTrans : CblasNoTrans, + ((un=='U') || (tn=='u')) ? CblasUnit : CblasNonUnit, + _n, T_dm->M, _n, x, 1); + } + else { + memcpy(x, b, _n*sizeof(double)); + cblas_dtrsv(CblasColMajor, ( T_dm->flag & M_UT ) ? CblasUpper : CblasLower, + ((tn=='T') || (tn=='t')) ? CblasTrans : CblasNoTrans, + ((un=='U') || (tn=='u')) ? CblasUnit : CblasNonUnit, + _n, T_dm->M, _n, x, 1); + x_dv->flag = V_DEF; + } +} + + + + + + +void SymmetricMatrixTimesVector(double *x_v, const double a, const double *A_m, const double *a_v, const double b, const int _n, const char ul) { + //Output: x_v = a*A_m*a_v + b*X_m where x_v (_n-by-1) must be allocated (but needs not be initialized). + //Inputs: X_m?????????????????????? + // A_m: _n-by-_n symmetric matrix; + // a_v: _n-by-1; + // a, b: scalars; + // ul: if =='u' or 'U', upper triangular elements in A_m are filled; if =='l' or 'L', lower triangular elements in A_m are filled. + + cblas_dsymv(CblasColMajor, ((ul=='u') || (ul=='U')) ? CblasUpper : CblasLower, _n, a, A_m, _n, a_v, 1, b, x_v, 1); +} + + +void SolveTriangularSystemVector(double *x_v, const double *A_m, const double *b_v, const int _n, const char ul, const char tn, const char un) { + //Outputs: + // x_v(_n-by-1) = inv(A_m)*b_v. If x_v=b_v, b_v will be overwritten by x_v. + //------- + //Inputs: + // A_m: _n-by-_n upper or lower triangular matrix; + // b_v: _n-by-1 vector. + // ul: if =='u' or 'U', A_m is upper triangular; if =='l' or 'L', A_m is lower triangular. + // tn: if =='t' or 'T', A_m' (transpose), instead of A_m, will be used; if =='n', A_m itself (no transpose) will be used. + // un: if =='u' or 'U', A_m is a unit upper triangular (i.e., the diagonal being 1); + // if =='n' or 'N', A_m is a non-unit upper triangular. + // + // Computes x_v = inv(A_m)*b_v by solving a triangular system of equation A_m * x_v = b_v. + // Note I: Intel MLK cblas_dtrsv() does not test for singularity or near-singulariy of the system. + // Such tests must be performed before calling this BLAS routine. + // Note II: if x_v=b_v, b_v will be overwritten by x_v. + + if (x_v != b_v) memcpy(x_v, b_v, _n*sizeof(double)); + cblas_dtrsv(CblasColMajor, ((ul=='u') || (ul=='U')) ? CblasUpper : CblasLower, + ((tn=='t') || (tn=='T')) ? CblasTrans : CblasNoTrans, + ((un=='u') || (tn=='U')) ? CblasNonUnit : CblasNonUnit, + _n, A_m, _n, x_v, 1); +} + + + + + +//======================================================= +// MKL Vector Mathematical Library with default using my own routines. +//======================================================= +void VectorDotDivByVector(TSdvector *x_dv, const TSdvector *a_dv, const TSdvector *b_dv) { + //????????? NOT tested yet. 06/13/03. + //Output: x_dv = a_dv ./ b_dv (division element by elment) where x_dv, a_dv, and b_dv are all _n-by-1. + // The fastest way is to use MKL VML with x != a and x != b. + // If x_dv = a_dv, x_dv will be replaced by x_dv ./ b_dv. + // If x_dv = b_dv, x_dv will be replaced by a_dv ./ x_dv. + //Inputs: + // a_dv: _n-by-1 double vector. + // b_dv: _n-by-1 double vector. + int _i, _n; + double *x, *a, *b; + + + if ( !x_dv || !a_dv || !b_dv) fn_DisplayError(".../mathlib.c/VectorDotDivideVector(): All input vectors must be created (memory-allocated)"); + else if ( !a_dv->flag || !b_dv->flag ) fn_DisplayError(".../mathlib.c/VectorDotDivideVector(): R input vectors must be given legal values"); + else if ( ((_n=x_dv->n) != a_dv->n) || (_n != b_dv->n) ) fn_DisplayError(".../mathlib.c/VectorDotDivideVector(): Dimensions of all input vectors must be same"); + else { + x = x_dv->v; + a = a_dv->v; + b = b_dv->v; + } + + + #if defined (INTELCMATHLIBRARY) + if ( (x != a) && (x != b) ) { + vdDiv (_n, a, b, x); + x_dv->flag = V_DEF; + } + else + for (_i=_n-1; _i>=0; _i--) x[_i] = a[_i]/b[_i]; + #else //Default to my own routine. + for (_i=_n-1; _i>=0; _i--) x[_i] = a[_i]/b[_i]; + x_dv->flag = V_DEF; + #endif +} + +void ElementwiseVectorDivideVector(TSdvector *x_dv, const TSdvector *a_dv, const TSdvector *b_dv) +{ + //The fastest way is to use MKL VML with x != a and x != b. + //Output: x_dv = a_dv ./ b_dv (division element by elment) where x_dv, a_dv, and b_dv are all _n-by-1. + // If x_dv = a_dv, x_dv will be replaced by x_dv ./ b_dv. + // If x_dv = b_dv, x_dv will be replaced by a_dv ./ x_dv. + //Inputs: + // a_dv: _n-by-1 double vector. + // b_dv: _n-by-1 double vector. + int _i, _n; + double *x, *a, *b; + + if ( !x_dv || !a_dv || !b_dv) fn_DisplayError("mathlib.c/ElementwiseVectorDivideVector(): All input vectors must be created (memory-allocated)"); + else if ( !a_dv->flag || !b_dv->flag ) fn_DisplayError("mathlib.c/ElementwiseVectorDivideVector(): R input vectors must be given legal values"); + else if ( ((_n=x_dv->n) != a_dv->n) || (_n != b_dv->n) ) fn_DisplayError("mathlib.c/ElementwiseVectorDivideVector(): Dimensions of all input vectors must be same"); + else { + x = x_dv->v; + a = a_dv->v; + b = b_dv->v; + } + + + #if defined (INTELCMATHLIBRARY) + if ( (x != a) && (x != b) ) { + vdDiv (_n, a, b, x); + x_dv->flag = V_DEF; + } + else + for (_i=_n-1; _i>=0; _i--) x[_i] = a[_i]/b[_i]; + #else //Default to my own routine. + for (_i=_n-1; _i>=0; _i--) x[_i] = a[_i]/b[_i]; + x_dv->flag = V_DEF; + #endif +} + +void ElementwiseInverseofVector(TSdvector *y_dv, TSdvector *x_dv) { + //The fastest way is to use MKL VML with y_dv != x_dv; + //Outputs: + // If y_dv!=x_dv, y_dv = 1 ./ x_dv; + // If y_dv=x_dv, x_dv = 1 ./ x_dv. + + int _i; + #if !defined( INTELCMATHLIBRARY ) + int _n; + double *y; + #endif + double *x; + + if ( !x_dv || !x_dv->flag ) fn_DisplayError(".../mathlib.c/ElementwiseInverseofVector(): (1) Input vector must be memory-allocated; (2) Legal values must be given"); + + #if defined( INTELCMATHLIBRARY ) + if ( y_dv == x_dv ) { + x = x_dv->v; + for (_i=x_dv->n-1; _i>=0; _i--) x[_i] = 1.0/x[_i]; + } + else { + if ( !y_dv ) fn_DisplayError(".../mathlib.c/ElementwiseInverseofVector(): Output vector must be memory-allocated (but no need for legal values)"); + if ( x_dv->n != y_dv->n) fn_DisplayError(".../mathlib.c/ElementwiseInverseofVector(): Lengths of both input and output vectors must be same"); + vdInv (x_dv->n, x_dv->v, y_dv->v); + y_dv->flag = V_DEF; + } + #else + if ( y_dv == x_dv ) { + x = x_dv->v; + for (_i=x_dv->n-1; _i>=0; _i--) x[_i] = 1.0/x[_i]; + } + else { + if ( !y_dv ) fn_DisplayError(".../mathlib.c/ElementwiseInverseofVector(): Output vector must be memory-allocated (but no need for legal values)"); + if ( (_n=x_dv->n) != y_dv->n) fn_DisplayError(".../mathlib.c/ElementwiseInverseofVector(): Lengths of both input and output vectors must be same"); + x = x_dv->v; + y = y_dv->v; + for (_i=_n-1; _i>=0; _i--) y[_i] = 1.0/x[_i]; + y_dv->flag = V_DEF; + } + #endif +} + +void ElementwiseSqrtofVector(TSdvector *y_dv, TSdvector *x_dv) +{ + //The fastest way is to use MKL VML with y_dv != x_dv; + //Outputs: + // If y_dv!=x_dv, y_dv = sqrt(x_dv); + // If y_dv=x_dv, x_dv = sqrt(x_dv); + + int _i; + #if !defined( INTELCMATHLIBRARY ) + int _n; + double *y; + #endif + double *x; + + if ( !x_dv || !x_dv->flag ) fn_DisplayError("mathlib.c/ElementwiseSqrtofVector(): (1) Input vector must be memory-allocated; (2) Legal values must be given"); + + #if defined( INTELCMATHLIBRARY ) + if ( y_dv == x_dv ) { + x = x_dv->v; + for (_i=x_dv->n-1; _i>=0; _i--) x[_i] = sqrt(x[_i]); + } + else { + if ( !y_dv ) fn_DisplayError("mathlib.c/ElementwiseSqrtofVector(): Output vector must be memory-allocated (but no need for legal values)"); + if ( x_dv->n != y_dv->n) fn_DisplayError("mathlib.c/ElementwiseSqrtofVector(): Lengths of both input and output vectors must be same"); + vdSqrt(x_dv->n, x_dv->v, y_dv->v); + y_dv->flag = V_DEF; + } + #else + if ( y_dv == x_dv ) { + x = x_dv->v; + for (_i=x_dv->n-1; _i>=0; _i--) x[_i] = sqrt(x[_i]); + } + else { + if ( !y_dv ) fn_DisplayError("mathlib.c/ElementwiseSqrtofVector(): Output vector must be memory-allocated (but no need for legal values)"); + if ( (_n=x_dv->n) != y_dv->n) fn_DisplayError("mathlib.c/ElementwiseSqrtofVector(): Lengths of both input and output vectors must be same"); + x = x_dv->v; + y = y_dv->v; + for (_i=_n-1; _i>=0; _i--) y[_i] = sqrt(x[_i]); + y_dv->flag = V_DEF; + } + #endif +} + +void ElementwiseLogofVector(TSdvector *y_dv, TSdvector *x_dv) +{ + //The fastest way is to use MKL VML with y_dv != x_dv; + //Outputs: + // If y_dv!=x_dv, y_dv = log(x_dv); + // If y_dv=x_dv, x_dv = log(x_dv); + + int _i; + #if !defined( INTELCMATHLIBRARY ) + int _n; + double *y; + #endif + double *x; + + if ( !x_dv || !x_dv->flag ) fn_DisplayError("mathlib.c/ElementwiseLogofVector(): (1) Input vector must be memory-allocated; (2) Legal values must be given"); + + #if defined( INTELCMATHLIBRARY ) + if ( y_dv == x_dv ) { + x = x_dv->v; + for (_i=x_dv->n-1; _i>=0; _i--) x[_i] = log(x[_i]); + } + else { + if ( !y_dv ) fn_DisplayError("mathlib.c/ElementwiseLogofVector(): Output vector must be memory-allocated (but no need for legal values)"); + if ( x_dv->n != y_dv->n) fn_DisplayError("mathlib.c/ElementwiseLogofVector(): Lengths of both input and output vectors must be same"); + vdLn(x_dv->n, x_dv->v, y_dv->v); + y_dv->flag = V_DEF; + } + #else + if ( y_dv == x_dv ) { + x = x_dv->v; + for (_i=x_dv->n-1; _i>=0; _i--) x[_i] = log(x[_i]); + } + else { + if ( !y_dv ) fn_DisplayError("mathlib.c/ElementwiseLogofVector(): Output vector must be memory-allocated (but no need for legal values)"); + if ( (_n=x_dv->n) != y_dv->n) fn_DisplayError("mathlib.c/ElementwiseLogofVector(): Lengths of both input and output vectors must be same"); + x = x_dv->v; + y = y_dv->v; + for (_i=_n-1; _i>=0; _i--) y[_i] = log(x[_i]); + y_dv->flag = V_DEF; + } + #endif +} + + +void ElementwiseInverseofMatrix(TSdmatrix *Y_dm, TSdmatrix *X_dm) +{ + //The fastest way is to use MKL VML with Y_dm != X_dm; + //Outputs: + // If Y_dm!=X_dm, Y_dm = 1 ./ X_dm; + // If Y_dm=X_dm, X_dm = 1 ./ X_dm. + + int _i, + nrows, ncols; + double *X; + #if !defined( INTELCMATHLIBRARY ) + double *Y; + #endif + + + + if ( !X_dm || !X_dm->flag ) fn_DisplayError(".../mathlib.c/ElementwiseInverseofMatrix(): (1) Input matrix must be memory-allocated; (2) Legal values must be given"); + + #if defined( INTELCMATHLIBRARY ) + if ( Y_dm == X_dm ) { + X = X_dm->M; + for (_i=X_dm->nrows*X_dm->ncols-1; _i>=0; _i--) X[_i] = 1.0/X[_i]; + } + else { + if ( !Y_dm ) fn_DisplayError(".../mathlib.c/ElementwiseInverseofMatrix(): Output matrix must be memory-allocated (but no need for legal values)"); + if ( ((nrows=X_dm->nrows) != Y_dm->nrows) || ((ncols=X_dm->ncols) != Y_dm->ncols) ) fn_DisplayError(".../mathlib.c/ElementwiseInverseofMatrix(): Dimensions of both input and output matrices must be same"); + vdInv (nrows*ncols, X_dm->M, Y_dm->M); + Y_dm->flag = M_GE; + } + #else //Default to my own routine. + if ( Y_dm == X_dm ) { + X = X_dm->M; + for (_i=X_dm->nrows*X_dm->ncols-1; _i>=0; _i--) X[_i] = 1.0/X[_i]; + } + else { + if ( !Y_dm ) fn_DisplayError(".../mathlib.c/ElementwiseInverseofMatrix(): Output matrix must be memory-allocated (but no need for legal values)"); + if ( ((nrows=X_dm->nrows) != Y_dm->nrows) || ((ncols=X_dm->ncols) != Y_dm->ncols) ) fn_DisplayError(".../mathlib.c/ElementwiseInverseofMatrix(): Dimensions of both input and output matrices must be same"); + X = X_dm->M; + Y = Y_dm->M; + for (_i=_nrows*ncols-1; _i>=0; _i--) Y[_i] = 1.0/X[_i]; + Y_dm->flag = M_GE; + } + #endif +} + + + +//======================================================= +// Matrix routines (my own). +//======================================================= +void tz_VectorPlusMinusVector(TSdvector *x_dv, const TSdvector *a_dv, const double _alpha, const TSdvector *b_dv, const double _beta) +{ + //Output: x_dv = alpha*a_dv + beta*b_dv where x_dv is _n-by-1. + //Inputs: + // a_dv: _n-by-1 double vector. + // _alpha: double constant. + // b_dv: _n-by-1 double vector. + // _beta: double constant. + int _i, _n; + double *x, *a, *b; + + + if ( !x_dv || !a_dv || !b_dv) fn_DisplayError("mathlib.c/tz_VectorPlusMinusVector(): All input vectors must be created (memory-allocated)"); + else if ( !a_dv->flag || !b_dv->flag ) fn_DisplayError("mathlib.c/tz_VectorPlusMinusVector(): R input vectors must be given values"); + else { + _n = x_dv->n; + x = x_dv->v; + a = a_dv->v; + b = b_dv->v; + } + if ( (_n != a_dv->n) || (_n != b_dv->n) ) fn_DisplayError("mathlib.c/tz_VectorPlusMinusVector(): Dimensions of all input vectors must be same"); + else { + for (_i=_n-1; _i>=0; _i--) x[_i] = _alpha*a[_i] + _beta*b[_i]; + x_dv->flag = V_DEF; + } +} +void VectorPlusVector(TSdvector *x_dv, const TSdvector *a_dv, const TSdvector *b_dv) { + //Output: x_dv = a_dv + b_dv where x_dv is _n-by-1. + // If x_dv = a_dv, a_dv will be replaced by x_dv. + // If x_dv = b_dv, b_dv will be replaced by x_dv, + //Inputs: + // a_dv: _n-by-1 double vector. + // b_dv: _n-by-1 double vector. + int _i, _n; + double *x, *a, *b; + + + if ( !x_dv || !a_dv || !b_dv) fn_DisplayError(".../mathlib.c/VectorPlusVector(): All input vectors must be created (memory-allocated)"); + else if ( !a_dv->flag || !b_dv->flag ) fn_DisplayError(".../mathlib.c/VectorPlusVector(): R input vectors must be given values"); + else { + _n = x_dv->n; + x = x_dv->v; + a = a_dv->v; + b = b_dv->v; + } + if ( (_n != a_dv->n) || (_n != b_dv->n) ) fn_DisplayError(".../mathlib.c/VectorPlusVector(): Dimensions of all input vectors must be same"); + else { + for (_i=_n-1; _i>=0; _i--) x[_i] = a[_i] + b[_i]; + x_dv->flag = V_DEF; + } +} +void VectorMinusVector(TSdvector *x_dv, const TSdvector *a_dv, const TSdvector *b_dv) +{ + //Output: x_dv = a_dv - b_dv where x_dv is _n-by-1. + // If x_dv = a_dv, x_dv will be replaced by x_dv - b_dv. + // If x_dv = b_dv, x_dv will be replaced by a_dv - x_dv. + //Inputs: + // a_dv: _n-by-1 double vector. + // b_dv: _n-by-1 double vector. + int _i, _n; + double *x, *a, *b; + + + if ( !x_dv || !a_dv || !b_dv) fn_DisplayError(".../mathlib.c/VectorMinusVector(): All input vectors must be created (memory-allocated)"); + else if ( !a_dv->flag || !b_dv->flag ) fn_DisplayError(".../mathlib.c/VectorMinusVector(): R input vectors must be given values"); + else { + x = x_dv->v; + a = a_dv->v; + b = b_dv->v; + } + if ( ((_n = x_dv->n) != a_dv->n) || (_n != b_dv->n) ) fn_DisplayError(".../mathlib.c/VectorMinusVector(): Dimensions of all input vectors must be same"); + else { + for (_i=_n-1; _i>=0; _i--) x[_i] = a[_i] - b[_i]; + x_dv->flag = V_DEF; + } +} + + +void VectorPlusVectorUpdate(TSdvector *x_dv, const TSdvector *b_dv) { + //Output: x_dv = b_dv + x_dv where x_dv is _n-by-1. + //Inputs: + // b_dv: _n-by-1 double vector. + int _n, _i; + double *x, *b; + + + if ( !x_dv || !b_dv ) fn_DisplayError(".../mathlib.c/VectorPlusVectorUpdate(): All input vectors must be created (memory-allocated)"); + if ( !b_dv->flag || !x_dv->flag ) fn_DisplayError(".../mathlib.c/VectorPlusVectorUpdate(): All input vectors must be given values"); + if ( (_n=x_dv->n) != b_dv->n ) fn_DisplayError(".../mathlib.c/VectorPlusVectorUpdate(): Dimensions of all input vectors must be same"); + + x = x_dv->v; + b = b_dv->v; + for (_i=_n-1; _i>=0; _i--) x[_i] += b[_i]; +} + + +void VectorDotTimesVector(TSdvector *x_dv, const TSdvector *a_dv, TSdvector *b_dv, const double _alpha, const double _beta) { + //Output: + // x_dv is _n-by-1. + // x_dv = _alpha * a_dv .* b_dv + _beta * x_dv if x_dv != b_dv. + // x_dv = _alpha * a_dv .* x_dv + _beta * x_dv if x_dv = b_dv. + //Inputs: + // a_dv: _n-by-1 double vector. + // b_dv: _n-by-1 double vector. + // _alpha: double scalar. + // _beta: a double scalar. + int _i, _n; + double *x, *a, *b; + + + if ( !x_dv || !a_dv || !b_dv) fn_DisplayError(".../mathlib.c/VectorDotTimesVector(): All input vectors must be created (memory-allocated)"); + else if ( !a_dv->flag || !b_dv->flag ) fn_DisplayError(".../mathlib.c/VectorDotTimesVector(): Both R input vectors must be given values"); + else { + _n = x_dv->n; + x = x_dv->v; + a = a_dv->v; + b = b_dv->v; + } + if ( (_n != a_dv->n) || (_n != b_dv->n) ) fn_DisplayError(".../mathlib.c/VectorDotTimesVector(): Dimensions of all input vectors must be same"); + + + if ( _alpha==1.0 ) { + if ( _beta==0.0 ) { + for (_i=_n-1; _i>=0; _i--) x[_i] = a[_i] * b[_i]; + if (!x_dv->flag) x_dv->flag = V_DEF; + } + else if ( _beta==1.0 ) { + for (_i=_n-1; _i>=0; _i--) x[_i] += a[_i] * b[_i]; + if (!x_dv->flag) x_dv->flag = V_DEF; + } + else { + for (_i=_n-1; _i>=0; _i--) x[_i] = a[_i] * b[_i] + _beta * x[_i]; + if (!x_dv->flag) x_dv->flag = V_DEF; + } + } + else { + if ( _beta==0.0 ) { + for (_i=_n-1; _i>=0; _i--) x[_i] = _alpha * a[_i] * b[_i]; + if (!x_dv->flag) x_dv->flag = V_DEF; + } + else if ( _beta==1.0 ) { + for (_i=_n-1; _i>=0; _i--) x[_i] += _alpha * a[_i] * b[_i]; + if (!x_dv->flag) x_dv->flag = V_DEF; + } + else { + for (_i=_n-1; _i>=0; _i--) x[_i] = _alpha * a[_i] * b[_i] + _beta * x[_i]; + if (!x_dv->flag) x_dv->flag = V_DEF; + } + } +} + +void SwapColsofMatrix(TSdmatrix *X_dm, int j1, int j2) +{ + //??????? NOT tested yet. + //Ouputs: + // The j1_th column of X_dm is swapped with the j2_th column of X_dm. + //Inputs: + // X_dm: Memory allocated and legal values given already. + // j1: The j1_th column of X_dm. + // j2: The j2_th column of X_dm. + + int nrows; + double *M1, *M2; + + if ( !X_dm || !X_dm->flag ) fn_DisplayError(".../mathlib.c/SwapColsofMatrix(): (1) Input matrix X must be created (memory-allocated); (2) Legal values must be given"); + if (j1 >= X_dm->ncols) fn_DisplayError(".../mathlib.c/SwapColsofMatrix(): The j1_th column specified for the input matrix X exceeds its column dimension"); + if (j2 >= X_dm->ncols) fn_DisplayError(".../mathlib.c/SwapColsofMatrix(): The j2_th column specified for the input matrix X exceeds its column dimension"); + if (j1 == j2) fn_DisplayError(".../mathlib.c/SwapColsofMatrix(): The two columns for swapping must be different"); + + #if defined( INTELCMATHLIBRARY ) + M1 = X_dm->M + j1*(nrows=X_dm->nrows); //Points to the beginning of the j1_th column. + M2 = X_dm->M + j2*nrows; //Points to the beginning of the j2_th column. + cblas_dswap(nrows, M1, 1, M2, 1); + #else + fn_DisplayError(".../mathlib.c/SwapColsofMatrix(): Haven't got time to write my own for-loop routine to swap two columns"); + #endif +} +void SwapColsofMatrices(TSdmatrix *X1_dm, int j1, TSdmatrix *X2_dm, int j2) +{ + //Ouputs: + // The j1_th column of X1_dm is swapped with the j2_th column of X2_dm. + //Inputs: + // X1_dm: Memory allocated and legal values given already. + // X2_dm: Memory allocated and legal values given already. + // j1: The j1_th column of X1_dm. + // j2: The j2_th column of X2_dm. + + int nrows; + double *M1, *M2; + + if ( !X1_dm || !X1_dm->flag ) fn_DisplayError(".../mathlib.c/SwapColsofMatrices(): (1) Input matrix X1 must be created (memory-allocated); (2) Legal values must be given"); + if ( !X2_dm || !X2_dm->flag ) fn_DisplayError(".../mathlib.c/SwapColsofMatrices(): (1) Input matrix X2 must be created (memory-allocated); (2) Legal values must be given"); + if ( X1_dm == X2_dm ) fn_DisplayError(".../mathlib.c/SwapColsofMatrices(): The two input matrices must be different"); + if (j1 >= X1_dm->ncols) fn_DisplayError(".../mathlib.c/SwapColsofMatrices(): The jth column specified for the input matrix X1 exceeds its column dimension"); + if (j2 >= X2_dm->ncols) fn_DisplayError(".../mathlib.c/SwapColsofMatrices(): The jth column specified for the input matrix X1 exceeds its column dimension"); + if ( (nrows=X1_dm->nrows) != X2_dm->nrows ) fn_DisplayError(".../mathlib.c/SwapColsofMatrices(): The number of rows for both input matrices must be the same"); + + + #if defined (INTELCMATHLIBRARY) + M1 = X1_dm->M + j1*nrows; //Points to the beginning of the j1_th column. + M2 = X2_dm->M + j2*nrows; //Points to the beginning of the j2_th column. + cblas_dswap(nrows, M1, 1, M2, 1); + #else + fn_DisplayError(".../mathlib.c/SwapColsofMatrices(): Haven't got time to write my own for-loop routine to swap two columns"); + #endif +} +void SwapPositionsofMatrix(TSdmatrix *X_dm, int j1, int j2) { + //Ouputs: + // Column operation: first, the j1_th column of X_dm is swapped with the j2_th column of X_dm. + // Row operation: second, the j1_th row of X_dm is swapped with the j2_th row of X_dm. + //Inputs: + // X_dm: Memory allocated and legal values given already. + // j1: The j1_th column and row of X_dm. + // j2: The j2_th column and row of X_dm. + + int nrows, ncols; + double *M1, *M2; + + if ( !X_dm || !X_dm->flag ) fn_DisplayError(".../mathlib.c/SwapColsofMatrix(): (1) Input matrix X must be created (memory-allocated); (2) Legal values must be given"); + if (j1 >= (ncols=X_dm->ncols) || j1 >= (nrows=X_dm->nrows) ) fn_DisplayError(".../mathlib.c/SwapColsofMatrix(): The j1_th column or row specified for the input matrix X exceeds its column or row dimension"); + if (j2 >= X_dm->ncols || j2 >= X_dm->ncols ) fn_DisplayError(".../mathlib.c/SwapColsofMatrix(): The j2_th column or row specified for the input matrix X exceeds its column or row dimension"); + if (j1 == j2) fn_DisplayError(".../mathlib.c/SwapColsofMatrix(): The two columns for swapping must be different"); + + #if defined( INTELCMATHLIBRARY ) + M1 = X_dm->M + j1*nrows; //Points to the beginning of the j1_th column. + M2 = X_dm->M + j2*nrows; //Points to the beginning of the j2_th column. + cblas_dswap(nrows, M1, 1, M2, 1); //Swaps columns. + // + M1 = X_dm->M + j1; //Points to the beginning of the j1_th row. + M2 = X_dm->M + j2; //Points to the beginning of the j2_th row. + cblas_dswap(ncols, M1, nrows, M2, nrows); //Swaps corresponding rows. + #else + fn_DisplayError(".../mathlib.c/SwapPositionsofMatrix(): Haven't got time to write my own for-loop routine to swap two columns and then two corresponding rows"); + #endif +} + +void SwapMatricesofCell(TSdcell *A_dc, int c1, int c2) +{ + //Ouputs: + // A_dc->C[c1] and A_dc->C[c2] are swapped. + //Inputs: + // A_dc: Memory allocated and legal values given already. + // c1, c2: Positions of cells. + + int _n; + TSdmatrix *tpnter2dm = NULL; + + if ( !A_dc ) fn_DisplayError(".../mathlib.c/SwapMatricesofCell(): Input cell A_dc must be created (memory-allocated)"); + _n = A_dc->ncells; + if ( (c1>=_n) || (c1<0) || (c2>=_n) || (c2<0) ) fn_DisplayError(".../mathlib.c/SwapMatricesofCell(): c1 and c2 must be between 0 and A_dc->ncells inclusive"); + + tpnter2dm = A_dc->C[c1]; + A_dc->C[c1] = A_dc->C[c2]; + A_dc->C[c2] = tpnter2dm; +} + +void SwapVectorsofCellvec(TSdcellvec *x_dcv, int c1, int c2) +{ + //Ouputs: + // x_dcv->C[c1] and x_dcv->C[2] are swapped. + //Inputs: + // x_dcv: Memory allocated and legal values given already. + // c1, c2: Positions of cells. + + int _n; + TSdvector *tpnter2dv = NULL; + + if ( !x_dcv ) fn_DisplayError(".../mathlib.c/SwapVectorsofCellvec(): Input cell vector x_dcv must be created (memory-allocated)"); + _n = x_dcv->ncells; + if ( (c1>=_n) || (c1<0) || (c2>=_n) || (c2<0) ) fn_DisplayError(".../mathlib.c/SwapVectorsofCellvec(): c1 and c2 must be between 0 and x_dcv->ncells inclusive"); + + tpnter2dv = x_dcv->C[c1]; + x_dcv->C[c1] = x_dcv->C[c2]; + x_dcv->C[c2] = tpnter2dv; +} +//-- +void SwapVectorsofCellvec_int(TSicellvec *x_icv, int c1, int c2) +{ + //Ouputs: + // x_icv->C[c1] and x_icv->C[2] are swapped. + //Inputs: + // x_icv: Memory allocated and legal values given already. + // c1, c2: Positions of cells. + + int _n; + TSivector *tpnter2iv = NULL; + + if ( !x_icv ) fn_DisplayError(".../mathlib.c/SwapVectorsofCellvec_int(): Input cell vector x_icv must be created (memory-allocated)"); + _n = x_icv->ncells; + if ( (c1>=_n) || (c1<0) || (c2>=_n) || (c2<0) ) fn_DisplayError(".../mathlib.c/SwapVectorsofCellvec_int(): c1 and c2 must be between 0 and x_icv->ncells inclusive"); + + tpnter2iv = x_icv->C[c1]; + x_icv->C[c1] = x_icv->C[c2]; + x_icv->C[c2] = tpnter2iv; +} + + +//=== The following is NOT efficient. +//#if defined( INTELCMATHLIBRARY ) +//void SwapMatricesofCell(TSdcell *X_dc, int c1, int c2) +//{ +// //??????? NOT tested yet. +// //Ouputs: +// // The c1_th matrix of X_dc is swapped with the c2_th matrix of X_dc. +// //Inputs: +// // X_dc: Memory allocated and legal values given already. +// // c1: The c1_th matrix of X_dc. +// // c2: The c2_th matrix of X_dc. + +// int dim; + + +// if ( !X_dc ) fn_DisplayError(".../mathlib.c/SwapMatricesofCell(): input cell X_dc must be created (memory-allocated)"); +// if ( c1 >= X_dc->ncells || c2 >= X_dc->ncells ) fn_DisplayError(".../mathlib.c/SwapMatricesofCell(): the c1_th or c2_th cell exceeds the cell dimension"); +// if ( c1 == c2 ) fn_DisplayError(".../mathlib.c/MatricesofCell(): the two matrices for swapping must be different"); +// if ( !X_dc->C[c1]->flag || !X_dc->C[c2]->flag ) fn_DisplayError(".../mathlib.c/MatricesofCell(): both matrices for swapping must have legal values"); +// if ( (dim=X_dc->C[c1]->nrows*X_dc->C[c1]->ncols) != (X_dc->C[c2]->nrows*X_dc->C[c2]->ncols) ) +// fn_DisplayError(".../mathlib.c/MatricesofCell(): the two matrices for swapping must have the same dimension"); + + +// cblas_dswap(dim, X_dc->C[c1]->M, 1, X_dc->C[c2]->M, 1); +//} +//#else +////.../mathlib.c/SwapColsofMatrix(): Haven't got time to write my own for-loop routine to swap two columns. 19 Oct. 03 +//#endif + + +//=== Do NOT know what the following is. 20 Oct. 03. +//void SwapPositionsofCell(TSdcell *X_dc, const int c1, const int c2) +//{ +// //???? Not tested yet. +// int dim; + + +// if ( !X_dc ) fn_DisplayError(".../mathlib.c/SwapMatricesofCell(): input cell A_dc must be created (memory-allocated)"); +// if ( c1 >= X_dc->ncells || c2 >= X_dc->ncells ) fn_DisplayError(".../mathlib.c/SwapMatricesofCell(): the c1_th or c2_th cell exceeds the cell dimension"); +// if ( c1 == c2 ) fn_DisplayError(".../mathlib.c/MatricesofCell(): the two matrices for swapping must be different"); +// if ( !X_dc->C[c1]->flag || !X_dc->C[c2]->flag ) fn_DisplayError(".../mathlib.c/MatricesofCell(): both matrices for swapping must have legal values"); +// if ( (dim=X_dc->C[c1]->nrows*X_dc->C[c1]->ncols) != (X_dc->C[c2]->nrows*X_dc->C[c2]->ncols) ) +// fn_DisplayError(".../mathlib.c/MatricesofCell(): the two matrices for swapping must have the same dimension"); + + +// cblas_dswap(dim, X_dc->C[c1]->M, 1, X_dc->C[c2]->M, 1); +//} + + +void PermuteColsofMatrix(TSdmatrix *A_dm, const TSivector *indx_iv) +{ + //Ouputs: + // A_dm (m-by-n) is replaced by permuted columns only, according to indx_iv. + //Inputs: + // A_dm (m-by-n): Memory allocated and legal values given already. + // indx_iv (n-by-1): index for columns and rows of A_dm to exchanged simultaneously. Example: indx_-v->v = {2 0 1} (base 0) for the 3-by-3 matrix + // means that original column 2 is column 0, original column 0 is column 1, etc. + + double *B_pd = NULL, + *A; + int _j, _n, _m, mn, + *indx; + + if ( !A_dm || !A_dm->flag ) fn_DisplayError(".../mathlib.c/PermuteColsofMatrix(): input matrix A_dm must (1) be created (memory allocated) and (2) have legal values"); + if ( !indx_iv->flag || (_n=A_dm->ncols) != indx_iv->n ) fn_DisplayError(".../mathlib.c/PermuteColsofMatrix(): (1) sorted index vector, indx_iv, must have legal values; (2) its length must match the number of columns of the input matrix A_dm"); + + + //=== Memory allocated for this function. + B_pd = tzMalloc(mn=_n*(_m=A_dm->nrows), double); + + indx = indx_iv->v; + memcpy(B_pd, A = A_dm->M, mn*sizeof(double)); + for (_j=_n-1; _j>=0; _j--) + memcpy(A+_j*_m, B_pd+indx[_j]*_m, _m*sizeof(double)); + + //=== Destroys memory allocated for this function. + tzDestroy(B_pd); +} + +void PermuteRowsofMatrix(TSdmatrix *A_dm, const TSivector *indx_iv) +{ + //Ouputs: + // A_dm (n-by-m) is replaced by permuted rows only, according to indx_iv. + //Inputs: + // A_dm (n-by-m): Memory allocated and legal values given already. + // indx_iv (n-by-1): index for columns and rows of A_dm to exchanged simultaneously. Example: indx_-v->v = {2 0 1} (base 0) for the 3-by-3 matrix + // means that original column 2 is column 0, original column 0 is column 1, etc. + + double *B_pd = NULL, + *A; + int _i, _n, _m, mn, + *indx; + #if !defined( INTELCMATHLIBRARY ) + int _j; + #endif + + if ( !A_dm || !A_dm->flag ) fn_DisplayError(".../mathlib.c/PermuteRowsMatrix(): input matrix A_dm must (1) be created (memory allocated) and (2) have legal values"); + if ( !indx_iv->flag || (_n=A_dm->nrows) != indx_iv->n ) fn_DisplayError(".../mathlib.c/PermuteRowsMatrix(): (1) indx_iv must have legal values; (2) number of rows in A_dm must match the length of indx_iv"); + + + //=== Memory allocated for this function. + B_pd = tzMalloc(mn=_n*(_m=A_dm->ncols), double); + + indx = indx_iv->v; + memcpy(B_pd, A = A_dm->M, mn*sizeof(double)); + #if defined( INTELCMATHLIBRARY ) + for (_i=_n-1; _i>=0; _i--) + cblas_dcopy(_m, B_pd+indx[_i], _n, A+_i, _n); + #else //Default to my own routine. + _m = A_dm->ncols; + for (_j=_m-1; _j>=0; _j--) + for (_i=_n-1; _i>=0; _i--) + A[mos(_i, _j, _n)] = B_pd[mos(indx[_i], _j, _n)]; + #endif + + //=== Destroys memory allocated for this function. + tzDestroy(B_pd); +} + +void PermuteMatrix(TSdmatrix *A_dm, const TSivector *indx_iv) +{ + //Ouputs: + // A_dm (n-by-n) is replaced by permuted columns and rows simultaneously. The permutation is dicated by indx_iv. + //Inputs: + // A_dm (n-by-n): Memory allocated and legal values given already. + // indx_iv (n-by-1): index for columns and rows of A_dm to exchanged simultaneously. Example: indx_-v->v = {2 0 1} (base 0) for the 3-by-3 matrix + // means that original column 2 and row 2 are column 0 and row 0, original column 0 and row 0 are column 1 and row 1, etc. + + double *B_pd = NULL, + *A; + int _i, _j, _n, n2, + *indx; + + if ( !A_dm || !A_dm->flag ) fn_DisplayError(".../mathlib.c/PermuteMatrix(): input matrix A_dm must (1) be created (memory allocated) and (2) have legal values"); + if ( !indx_iv->flag || (_n=A_dm->nrows) != A_dm->ncols || _n != indx_iv->n ) fn_DisplayError(".../mathlib.c/PermuteMatrix(): (1) indx_iv must have legal values; (2) input matrix A_dm must be square; (3) it dimension must coincide with the length of indx_iv"); + + + //=== Memory allocated for this function. + B_pd = tzMalloc(n2=_n*_n, double); + + indx = indx_iv->v; + memcpy(B_pd, A = A_dm->M, n2*sizeof(double)); + for (_j=_n-1; _j>=0; _j--) + for (_i=_n-1; _i>=0; _i--) + A[mos(_i, _j, _n)] = B_pd[mos(indx[_i], indx[_j], _n)]; + + + //=== Destroys memory allocated for this function. + tzDestroy(B_pd); +} +//=== The following works but may be less efficient and definitely hard to understand. +// void PermuteMatrix(TSdmatrix *A_dm, const TSivector *indx_iv) +// { +// //Ouputs: +// // A_dm is replaced by permuted columns and rows simultaneously. The permutation is dicated by indx_iv. +// //Inputs: +// // A_dm: Memory allocated and legal values given already. +// // indx_iv: index for columns and rows of A_dm to exchanged simultaneously. Example: indx_-v->v = {2 0 1} (base 0) for the 3-by-3 matrix +// // means that original column 2 and row 2 are column 0 and row 0, original column 0 and row 0 are column 1 and row 1, etc. +// +// double *B_pd = NULL, +// *A; +// int _i, _n, n2, +// *indx; +// +// if ( !A_dm || !A_dm->flag ) fn_DisplayError(".../mathlib.c/PermuteMatrix(): input matrix A_dm must (1) be created (memory allocated) and (2) have legal values"); +// if ( (_n=A_dm->nrows) != A_dm->ncols || _n != indx_iv->n ) fn_DisplayError(".../mathlib.c/PermuteMatrix(): (1) input matrix A_dm must be square; (2) it dimension must coincide with the length of indx_iv"); +// +// +// //=== Memory allocated for this function. +// B_pd = tzMalloc(n2=_n*_n, double); +// +// indx = indx_iv->v; +// memcpy(B_pd, A = A_dm->M, n2*sizeof(double)); +// for (_i=0; _i<n2; _i++) A[_i] = B_pd[indx[_i%_n]+indx[_i/_n]*_n]; +// +// //=== Destroys memory allocated for this function. +// tzDestroy(B_pd); +// } + + +void PermuteMatricesofCell(TSdcell *A_dc, const TSivector *indx_iv) +{ + //Ouputs: + // A_dc is replaced by permuted matrices. The permutation is dicated by indx_iv. + //Inputs: + // A_dc: Memory allocated and legal values given already. + // indx_iv: index for matrices of A_dc to exchanged simultaneously. Example: indx_-v->v = {2 0 1} (base 0) for the 3-by-1 cell + // means that original matrix 2 is matrix 0, original matrix 0 is matrix 1, etc. + + int _i, _n, + *indx_p; + TSdmatrix **tA_p2dm = NULL; + + if ( !A_dc || !indx_iv || !indx_iv->flag ) fn_DisplayError(".../mathlib.c/PermuteMatricesofCell(): (1) input cell A_dc must be created (memory-allocated); (2) index vector indx_iv must be created and have legal values"); + if ( (_n=A_dc->ncells) != indx_iv->n ) fn_DisplayError(".../mathlib.c/PermuteMatricesofCell(): number of cells must match the length of indx_iv"); + indx_p = indx_iv->v; + + + //=== Memory allocated for this function. + tA_p2dm = tzMalloc(_n, TSdmatrix *); + + for (_i=_n-1; _i>=0; _i--) tA_p2dm[_i] = A_dc->C[indx_p[_i]]; + //=== This one is less efficient than the following: for (_i=_n-1; _i>=0; _i--) A_dc->C[_i] = tA_p2dm[_i]; + memcpy(A_dc->C, tA_p2dm, _n*sizeof(TSdmatrix *)); + + //=== Destroys memory allocated for this function. + tzDestroy(tA_p2dm); +} + + +void ScalarTimesColofMatrix(TSdvector *y_dv, double _alpha, TSdmatrix *X_dm, int _j) +{ + //????????? Default option, in the #else, has NOT been tested yet! + //Ouputs: + // If y_dv!=NULL, y_dv is the jth column of X_dm is multiplied by _alpha. + // If !y_dv, the jth column of X_dm is replaced by the new value, which will be multiplied by _alpha. + //Inputs: + // _alpha: Scalar. + // X_dm: Memory allocated and legal values given already. + // _j: The jth column of X_dm. + + #if !defined( INTELCMATHLIBRARY ) + int _i; + #endif + int nrows; + double *M, *v; + + if ( !X_dm || !X_dm->flag ) fn_DisplayError(".../mathlib.c/ScalarTimesColofMatrix(): (1) Input matrix must be created (memory-allocated); (2) Legal values must be given"); + if (_j >= X_dm->ncols) fn_DisplayError(".../mathlib.c/ScalarTimesColofMatrix(): The jth column specified for the input matrix exceeds the column dimension"); + + #if defined( INTELCMATHLIBRARY ) + M = X_dm->M + _j*(nrows=X_dm->nrows); //Points to the beginning of the jth column. + if (!y_dv) cblas_dscal(nrows, _alpha, M, 1); + else { + memcpy(v=y_dv->v, M, nrows*sizeof(double)); + cblas_dscal(nrows, _alpha, v, 1); + y_dv->flag = V_DEF; + } + #else + Need to be tested for the following. + // + // M = X_dm->M + (_j+1)*(nrows=X_dm->nrows) - 1; //Points to the end of the jth column. + // if (!y_dv) + // for (_i=nrows-1; _i>=0; _i--, M--) *M = _alpha * (*M); + // else { + // v = y_dv->v; + // for (_i=nrows-1; _i>=0; _i--, M--) v[_i] = _alpha * (*M); + // y_dv->flag = V_DEF; + // } + #endif +} +void ScalarTimesColofMatrix2ColofMatrix(TSdmatrix *Y_dm, int jy, double _alpha, TSdmatrix *X_dm, int jx) +{ + //Ouputs: + // If Y_dm!=NULL, the jy_th column of Y_dm is the jx_th column of X_dm multiplied by _alpha. + // If !Y_dm, the jx_th column of X_dm is replaced by the new value, which will be multiplied by _alpha. + //Inputs: + // _alpha: Scalar. + // X_dm: Memory allocated and legal values given already. + // jy: The jy_th column of Y_dm. + // yx: The jx_th column of X_dm. + + #if !defined( INTELCMATHLIBRARY ) + int _i; + #endif + int nrows_x; + double *Mx, *My; + + if ( !X_dm || !X_dm->flag ) fn_DisplayError(".../mathlib.c/ScalarTimesColofMatrix2ColofMatrix(): (1) Input matrix must be created (memory-allocated); (2) Legal values must be given"); + if (jx >= X_dm->ncols) fn_DisplayError(".../mathlib.c/ScalarTimesColofMatrix2ColofMatrix(): The jth column specified for the input matrix exceeds the column dimension"); + + #if defined( INTELCMATHLIBRARY ) + Mx = X_dm->M + jx*(nrows_x=X_dm->nrows); //Points to the beginning of the jth column. + if (!Y_dm) cblas_dscal(nrows_x, _alpha, Mx, 1); + else { + if (jy >= Y_dm->ncols) fn_DisplayError(".../mathlib.c/ScalarTimesColofMatrix2ColofMatrix(): The jth column specified for the output matrix exceeds the column dimension"); + if ( nrows_x != Y_dm->nrows ) fn_DisplayError(".../mathlib.c/ScalarTimesColofMatrix2ColofMatrix(): The number of rows for both input and output matrices must be the same"); + + My = Y_dm->M + jy*nrows_x; //Points to the beginning of the jth column. + memcpy(My, Mx, nrows_x*sizeof(double)); + cblas_dscal(nrows_x, _alpha, My, 1); + } + #else + Mx = X_dm->M + (jx+1)*(nrows_x=X_dm->nrows) - 1; //Points to the end of the jth column. + if (!Y_dm) + for (_i=nrows_x-1; _i>=0; _i--, Mx--) *Mx = _alpha * (*Mx); + else { + if (jy >= Y_dm->ncols) fn_DisplayError(".../mathlib.c/ScalarTimesColofMatrix2ColofMatrix(): The jth column specified for the output matrix exceeds the column dimension"); + if ( nrows_x != Y_dm->nrows ) fn_DisplayError(".../mathlib.c/ScalarTimesColofMatrix2ColofMatrix(): The number of rows for both input and output matrices must be the same"); + + My = Y_dm->M + (jy+1)*nrows_x - 1; //Points to the end of the jth column. + for (_i=nrows_x-1; _i>=0; _i--, Mx--, My--) *My = _alpha * (*Mx); + } + #endif +} + + +void ScalarTimesColofMatrixPlusVector2ColofMatrix(TSdmatrix *Y_dm, int jy, double _alpha, TSdmatrix *X_dm, int jx, double _beta, TSdvector *x_dv) { + //Ouputs: + // If Y_dm!=NULL, Y(:,jy) = alpha*X(:,jx) + beta*x. + // If !Y_dm, X(:,jx) = alpha*X(:,jx) + beta*x. + //Inputs: + // _alpha: Scalar. + // _beta: Scalar. + // X_dm: Memory allocated and legal values given already. + // jy: The jy_th column of Y_dm. + // yx: The jx_th column of X_dm. + + int _i, nrows_x; + double *Mx, *My, *v; + + if ( !X_dm || !X_dm->flag ) fn_DisplayError(".../mathlib.c/ScalarTimesColofMatrixPlusVector2ColofMatrix(): (1) Input matrix must be created (memory-allocated); (2) Legal values must be given"); + if (jx >= X_dm->ncols) fn_DisplayError(".../mathlib.c/ScalarTimesColofMatrixPlusVector2ColofMatrix(): The jth column specified for the input matrix exceeds the column dimension"); + if ( !x_dv || !x_dv->flag ) fn_DisplayError(".../mathlib.c/ScalarTimesColofMatrixPlusVector2ColofMatrix(): (1) input vectr must be created (memory-allocated); (2) legal values must be given"); + + if (_beta == 0.0) { + #if defined( INTELCMATHLIBRARY ) + Mx = X_dm->M + jx*(nrows_x=X_dm->nrows); //Points to the beginning of the jth column. + if (!Y_dm) cblas_dscal(nrows_x, _alpha, Mx, 1); + else { + if (jy >= Y_dm->ncols) fn_DisplayError(".../mathlib.c/ScalarTimesColofMatrix2ColofMatrix(): The jth column specified for the output matrix exceeds the column dimension"); + if ( nrows_x != Y_dm->nrows ) fn_DisplayError(".../mathlib.c/ScalarTimesColofMatrix2ColofMatrix(): The number of rows for both input and output matrices must be the same"); + + My = Y_dm->M + jy*nrows_x; //Points to the beginning of the jth column. + memcpy(My, Mx, nrows_x*sizeof(double)); + cblas_dscal(nrows_x, _alpha, My, 1); + } + #else + Mx = X_dm->M + (jx+1)*(nrows_x=X_dm->nrows) - 1; //Points to the end of the jth column. + if (!Y_dm) + for (_i=nrows_x-1; _i>=0; _i--, Mx--) *Mx = _alpha * (*Mx); + else { + if (jy >= Y_dm->ncols) fn_DisplayError(".../mathlib.c/ScalarTimesColofMatrix2ColofMatrix(): The jth column specified for the output matrix exceeds the column dimension"); + if ( nrows_x != Y_dm->nrows ) fn_DisplayError(".../mathlib.c/ScalarTimesColofMatrix2ColofMatrix(): The number of rows for both input and output matrices must be the same"); + + My = Y_dm->M + (jy+1)*nrows_x - 1; //Points to the end of the jth column. + for (_i=nrows_x-1; _i>=0; _i--, Mx--, My--) *My = _alpha * (*Mx); + } + #endif + } + else { + Mx = X_dm->M + (jx+1)*(nrows_x=X_dm->nrows) - 1; //Points to the end of the jth column. + if ( nrows_x != x_dv->n ) fn_DisplayError(".../mathlib.c/ScalarTimesColofMatrixPlusVector2ColofMatrix(): The length of the input vector must match the number of rows in the input matrix"); + + if (!Y_dm) { + if ( _alpha == 1.0 && _beta == 1.0 ) + for (_i=nrows_x-1, v=x_dv->v+_i; _i>=0; _i--, Mx--, v--) *Mx = *Mx + *v; + else if ( _alpha == 1.0 ) + for (_i=nrows_x-1, v=x_dv->v+_i; _i>=0; _i--, Mx--, v--) *Mx = _alpha * (*Mx) + *v; + else + for (_i=nrows_x-1, v=x_dv->v+_i; _i>=0; _i--, Mx--, v--) *Mx = _alpha * (*Mx) + _beta * (*v); + } + else { + if (jy >= Y_dm->ncols) fn_DisplayError(".../mathlib.c/ScalarTimesColofMatrixPlusVector2ColofMatrix(): The jth column specified for the output matrix exceeds the column dimension"); + if ( nrows_x != Y_dm->nrows ) fn_DisplayError(".../mathlib.c/ScalarTimesColofMatrixPlusVector2ColofMatrix(): The number of rows for both input and output matrices must be the same"); + + My = Y_dm->M + (jy+1)*nrows_x - 1; //Points to the end of the jth column. + if ( _alpha == 1.0 && _beta == 1.0 ) + for (_i=nrows_x-1, v=x_dv->v+_i; _i>=0; _i--, Mx--, My--, v--) *My = *Mx + *v; + else if ( _alpha == 1.0 ) + for (_i=nrows_x-1, v=x_dv->v+_i; _i>=0; _i--, Mx--, My--, v--) *My = _alpha * (*Mx) + *v; + else + for (_i=nrows_x-1, v=x_dv->v+_i; _i>=0; _i--, Mx--, My--, v--) *My = _alpha * (*Mx) + _beta * (*v); + } + } +} + + +void MatrixDotDivideVector_row(TSdmatrix *Y_dm, TSdmatrix *X_dm, TSdvector *x_dv, double _alpha, double _beta) +{ + //Outputs: + // If (Y_dm != X_dm), Y_dm(ix, :) = _alpha * X_dm(ix, :) ./ x_dv + _beta * X_dm(ix, :), for all ix. + // If (Y_dm = X_dm), X_dm(ix, :) = _alpha * X_dm(ix, :) ./ x_dv + _beta * X_dm(ix, :), for all ix. + //Inputs: + // _alpha: double scalar. + // _beta: double scalar. + + int _i, cnt, ncols_x, nrows_x, nrows_xm1, ix; + double *X, *x, *Y, xinv; + + if ( !X_dm || !X_dm->flag ) fn_DisplayError(".../mathlib.c/MatrixDotDivideVector(): (1) Input matrix must be created (memory-allocated); (2) Legal values must be given"); + if ( !x_dv || !x_dv->flag ) fn_DisplayError(".../mathlib.c/MatrixDotDivideVector(): (1) Input vector must be created (memory-allocated); (2) Legal values must be given"); + if ( (ncols_x=X_dm->ncols) != x_dv->n ) fn_DisplayError(".../mathlib.c/MatrixDotDivideVector(): Number of columns in the input matrix must match the length of the input vector"); + X = X_dm->M; + x = x_dv->v; + nrows_xm1 = (nrows_x=X_dm->nrows)-1; + + + if ( _beta==0.0 ) { + if ( Y_dm == X_dm ) { + for (ix=nrows_x*ncols_x-1, cnt=ncols_x-1; ix>=nrows_xm1; ix -= nrows_x, cnt--) { + //Last row of X_dm + xinv = _alpha/x[cnt]; + for (_i=ix-nrows_x+1; _i<=ix; _i++) X[_i] *= xinv; //Must _i<=ix, not _i<ix. For each column at time. + } + } + else { + Y = Y_dm->M; + if ( ncols_x != Y_dm->ncols || nrows_x != Y_dm->nrows ) fn_DisplayError(".../mathlib.c/MatrixDotDivideVector(): Dimension of output matrix Y_dm must be the same as that of input matrix X_dm"); + for (ix=nrows_x*ncols_x-1, cnt=ncols_x-1; ix>=nrows_xm1; ix -= nrows_x, cnt--) { + //Last row of X_dm + xinv = _alpha/x[cnt]; + for (_i=ix-nrows_x+1, cnt=0; _i<=ix; _i++, cnt++) Y[_i] = X[_i] * xinv; //Must _i<=ix, not _i<ix. For each column at time. + } + Y_dm->flag = M_GE; + } + } + else { + if ( Y_dm == X_dm ) { + for (ix=nrows_x*ncols_x-1, cnt=ncols_x-1; ix>=nrows_xm1; ix -= nrows_x, cnt--) { + //Last row of X_dm + xinv = _alpha/x[cnt] + _beta; + for (_i=ix-nrows_x+1; _i<=ix; _i++) X[_i] *= xinv; //Must _i<=ix, not _i<ix. For each column at time. + } + } + else { + Y = Y_dm->M; + if ( ncols_x != Y_dm->ncols || nrows_x != Y_dm->nrows ) fn_DisplayError(".../mathlib.c/MatrixDotDivideVector(): Dimension of output matrix Y_dm must be the same as that of input matrix X_dm"); + for (ix=nrows_x*ncols_x-1, cnt=ncols_x-1; ix>=nrows_xm1; ix -= nrows_x, cnt--) { + //Last row of X_dm + xinv = _alpha/x[cnt] + _beta; + for (_i=ix-nrows_x+1, cnt=0; _i<=ix; _i++, cnt++) Y[_i] = X[_i] * xinv; //Must _i<=ix, not _i<ix. For each column at time. + } + Y_dm->flag = M_GE; + } + } +} + + +void RowofMatrixDotDivideVector(TSdvector *y_dv, TSdmatrix *X_dm, int ix, TSdvector *x_dv, double _alpha, double _beta) +{ + //??????? NOT tested yet, 01/02/04. + //Outputs: + // If (y_dv), y_dv = _alpha * X_dm(ix, :) ./ x_dv + _beta * X_dm(ix, :). + // If (!y_dv), X_dm(ix, :) = _alpha * X_dm(ix, :) ./ x_dv + _beta * X_dm(ix, :). + //Inputs: + // _alpha: double scalar. + // _beta: double scalar. + + int _i, cnt, ncols_x, nrows_x; + double *X, *x, *y; + + if ( !X_dm || !X_dm->flag ) fn_DisplayError(".../mathlib.c/RowofMatrixDotDivideVector(): (1) Input matrix must be created (memory-allocated); (2) Legal values must be given"); + if ( !x_dv || !x_dv->flag ) fn_DisplayError(".../mathlib.c/RowofMatrixDotDivideVector(): (1) Input vector must be created (memory-allocated); (2) Legal values must be given"); + if ( (ncols_x=X_dm->ncols) != x_dv->n ) fn_DisplayError(".../mathlib.c/RowofMatrixDotDivideVector(): Number of columns in the input matrix must match the length of the input vector"); + if ( ix >= (nrows_x=X_dm->nrows) ) fn_DisplayError(".../mathlib.c/RowofMatrixDotDivideVector(): The specified ix_th row of the input matrix exceeds its row dimension"); + X = X_dm->M; + x = x_dv->v; + + + if ( _alpha==1.0 ) { + if ( _beta==0.0 ) { + if ( !y_dv ) + for (_i=ix + (ncols_x-1)*nrows_x, cnt=ncols_x-1; _i>=ix; _i -= nrows_x, cnt--) X[_i] /= x[cnt]; + else { + y = y_dv->v; + if ( ncols_x != y_dv->n ) fn_DisplayError(".../mathlib.c/RowofMatrixDotDivideVector(): Number of columns in the input matrix must match the length of the output vector"); + for (_i=ix + (ncols_x-1)*nrows_x, cnt=ncols_x-1; _i>=ix; _i -= nrows_x, cnt--) y[cnt] = X[_i] / x[cnt]; + y_dv->flag = V_DEF; + } + } +// else if ( _beta==1.0 ) { +// if ( !y_dv ) +// for (_i=ix + (ncols_x-1)*nrows_x, cnt=ncols_x-1; _i>=ix; _i -= nrows_x, cnt--) X[_i] *= ( 1.0 / x[cnt] + 1.0); +// else { +// y = y_dv->v; +// if ( ncols_x != y_dv->n ) fn_DisplayError(".../mathlib.c/RowofMatrixDotDivideVector(): Number of columns in the input matrix must match the length of the output vector"); +// for (_i=ix + (ncols_x-1)*nrows_x, cnt=ncols_x-1; _i>=ix; _i -= nrows_x, cnt--) y[cnt] = X[_i] * ( 1.0 / x[cnt] + 1.0 ); +// y_dv->flag = V_DEF; +// } +// } + else { + if ( !y_dv ) + for (_i=ix + (ncols_x-1)*nrows_x, cnt=ncols_x-1; _i>=ix; _i -= nrows_x, cnt--) X[_i] *= 1.0 / x[cnt] + _beta; + else { + y = y_dv->v; + if ( ncols_x != y_dv->n ) fn_DisplayError(".../mathlib.c/RowofMatrixDotDivideVector(): Number of columns in the input matrix must match the length of the output vector"); + for (_i=ix + (ncols_x-1)*nrows_x, cnt=ncols_x-1; _i>=ix; _i -= nrows_x, cnt--) y[cnt] = X[_i] * ( 1.0 / x[cnt] + _beta ); + y_dv->flag = V_DEF; + } + } + } + else { + if ( _beta==0.0 ) { + if ( !y_dv ) + for (_i=ix + (ncols_x-1)*nrows_x, cnt=ncols_x-1; _i>=ix; _i -= nrows_x, cnt--) X[_i] *= _alpha / x[cnt]; + else { + y = y_dv->v; + if ( ncols_x != y_dv->n ) fn_DisplayError(".../mathlib.c/RowofMatrixDotDivideVector(): Number of columns in the input matrix must match the length of the output vector"); + for (_i=ix + (ncols_x-1)*nrows_x, cnt=ncols_x-1; _i>=ix; _i -= nrows_x, cnt--) y[cnt] = (_alpha * X[_i]) / x[cnt]; + y_dv->flag = V_DEF; + } + } +// else if ( _beta==1.0 ) { +// if ( !y_dv ) +// for (_i=ix + (ncols_x-1)*nrows_x, cnt=ncols_x-1; _i>=ix; _i -= nrows_x, cnt--) X[_i] *= _alpha / x[cnt] + 1.0; +// else { +// y = y_dv->v; +// if ( ncols_x != y_dv->n ) fn_DisplayError(".../mathlib.c/RowofMatrixDotDivideVector(): Number of columns in the input matrix must match the length of the output vector"); +// for (_i=ix + (ncols_x-1)*nrows_x, cnt=ncols_x-1; _i>=ix; _i -= nrows_x, cnt--) y[cnt] = X[_i] * (_alpha / x[cnt] + 1.0); +// y_dv->flag = V_DEF; +// } +// } + else { + if ( !y_dv ) + for (_i=ix + (ncols_x-1)*nrows_x, cnt=ncols_x-1; _i>=ix; _i -= nrows_x, cnt--) X[_i] *= _alpha / x[cnt] + _beta; + else { + y = y_dv->v; + if ( ncols_x != y_dv->n ) fn_DisplayError(".../mathlib.c/RowofMatrixDotDivideVector(): Number of columns in the input matrix must match the length of the output vector"); + for (_i=ix + (ncols_x-1)*nrows_x, cnt=ncols_x-1; _i>=ix; _i -= nrows_x, cnt--) y[cnt] = X[_i] * (_alpha / x[cnt] + _beta); + y_dv->flag = V_DEF; + } + } + } +} + +void ColofMatrixDotTimesVector(TSdvector *y_dv, TSdmatrix *X_dm, int jx, TSdvector *x_dv, double _alpha, double _beta) { + //Outputs: + // If (y_dv), y_dv = _alpha * X_dm(:,jx) .* x_dv + _beta * X_dm(:,jx). + // If (!y_dv), X_dm(:,jx) = _alpha * X_dm(:,jx) .* x_dv + _beta * X_dm(:,jx). + //Inputs: + // _alpha: double scalar. + // _beta: double scalar. + + int _i, nrows_x; + double *X, *x, *y; + + if ( !X_dm || !X_dm->flag ) fn_DisplayError(".../mathlib.c/ColofMatrixDotTimesVector(): (1) Input matrix must be created (memory-allocated); (2) Legal values must be given"); + if ( !x_dv || !x_dv->flag ) fn_DisplayError(".../mathlib.c/ColofMatrixDotTimesVector(): (1) Input vector must be created (memory-allocated); (2) Legal values must be given"); + if ( (nrows_x=X_dm->nrows) != x_dv->n ) fn_DisplayError(".../mathlib.c/ColofMatrixDotTimesVector(): Number of rows in the input matrix must match the length of the input vector"); + if ( jx >= X_dm->ncols ) fn_DisplayError(".../mathlib.c/ColofMatrixDotTimesVector(): The specified jx_th column of the input matrix exceeds its column dimension"); + + + X = X_dm->M + (jx+1)*nrows_x - 1; //Points to the end of the jx_th column. + x = x_dv->v + nrows_x - 1; //Points to the end of the vector. + if ( _alpha==1.0 ) { + if ( _beta==0.0 ) { + if ( !y_dv ) + for (_i=nrows_x-1; _i>=0; _i--, X--, x--) *X = (*X) * (*x); + else { + if ( nrows_x != y_dv->n ) fn_DisplayError(".../mathlib.c/ColofMatrixDotTimesVector(): Number of rows in the input matrix must match the length of the output vector"); + for (_i=nrows_x-1, y=y_dv->v+_i; _i>=0; _i--, X--, x--, y--) *y = (*X) * (*x); + y_dv->flag = V_DEF; + } + } + else if ( _beta==1.0 ) { + if ( !y_dv ) + for (_i=nrows_x-1; _i>=0; _i--, X--, x--) *X = (*X) * (*x) + (*X); + else { + if ( nrows_x != y_dv->n ) fn_DisplayError(".../mathlib.c/ColofMatrixDotTimesVector(): Number of rows in the input matrix must match the length of the output vector"); + for (_i=nrows_x-1, y=y_dv->v+_i; _i>=0; _i--, X--, x--, y--) *y = (*X) * (*x) + (*X); + y_dv->flag = V_DEF; + } + } + else { + if ( !y_dv ) + for (_i=nrows_x-1; _i>=0; _i--, X--, x--) *X = (*X) * (*x) + _beta * (*X); + else { + if ( nrows_x != y_dv->n ) fn_DisplayError(".../mathlib.c/ColofMatrixDotTimesVector(): Number of rows in the input matrix must match the length of the output vector"); + for (_i=nrows_x-1, y=y_dv->v+_i; _i>=0; _i--, X--, x--, y--) *y = (*X) * (*x) + _beta * (*X); + y_dv->flag = V_DEF; + } + } + } + else { + if ( _beta==0.0 ) { + if ( !y_dv ) + for (_i=nrows_x-1; _i>=0; _i--, X--, x--) *X = _alpha * (*X) * (*x); + else { + if ( nrows_x != y_dv->n ) fn_DisplayError(".../mathlib.c/ColofMatrixDotTimesVector(): Number of rows in the input matrix must match the length of the output vector"); + for (_i=nrows_x-1, y=y_dv->v+_i; _i>=0; _i--, X--, x--, y--) *y = _alpha * (*X) * (*x); + y_dv->flag = V_DEF; + } + } + else if ( _beta==1.0 ) { + if ( !y_dv ) + for (_i=nrows_x-1; _i>=0; _i--, X--, x--) *X = _alpha * (*X) * (*x) + (*X); + else { + if ( nrows_x != y_dv->n ) fn_DisplayError(".../mathlib.c/ColofMatrixDotTimesVector(): Number of rows in the input matrix must match the length of the output vector"); + for (_i=nrows_x-1, y=y_dv->v+_i; _i>=0; _i--, X--, x--, y--) *y = _alpha * (*X) * (*x) + (*X); + y_dv->flag = V_DEF; + } + } + else { + if ( !y_dv ) + for (_i=nrows_x-1; _i>=0; _i--, X--, x--) *X = _alpha * (*X) * (*x) + _beta * (*X); + else { + if ( nrows_x != y_dv->n ) fn_DisplayError(".../mathlib.c/ColofMatrixDotTimesVector(): Number of rows in the input matrix must match the length of the output vector"); + for (_i=nrows_x-1, y=y_dv->v+_i; _i>=0; _i--, X--, x--, y--) *y = _alpha * (*X) * (*x) + _beta * (*X); + y_dv->flag = V_DEF; + } + } + } +} +void ColofMatrixDotTimesColofMatrix(TSdvector *y_dv, TSdmatrix *X1_dm, int jx1, TSdmatrix *X2_dm, int jx2, double _alpha, double _beta) { + //????????? NOT tested yet. + //Outputs: + // If y_dv!=NULL, y_dv = _alpha * X1_dm(:,jx1) .* X2_dm(:,jx2) + _beta * X1_dm(:,jx1). + // If !y_dv, X1_dm(:,jx1) = _alpha * X1_dm(:,jx1) .* X2_dm(:,jx2) + _beta * X1_dm(:,jx2). + //Inputs: + // _alpha: double scalar. + // _beta: double scalar. + + int _i, nrows1; + double *X1, *X2, *y; + + if ( !X1_dm || !X1_dm->flag ) fn_DisplayError(".../mathlib.c/ColofMatrixDotTimesColofMatrix(): (1) Input matrix X1 must be created (memory-allocated); (2) Legal values must be given"); + if ( !X2_dm || !X2_dm->flag ) fn_DisplayError(".../mathlib.c/ColofMatrixDotTimesColofMatrix(): (1) Input matrix X2 must be created (memory-allocated); (2) Legal values must be given"); + if ( (nrows1=X1_dm->nrows) != X2_dm->nrows ) fn_DisplayError(".../mathlib.c/ColofMatrixDotTimesColofMatrix(): Numbers of rows in both input matrices must be the same"); + if ( jx1 >= X1_dm->ncols ) fn_DisplayError(".../mathlib.c/ColofMatrixDotTimesVector(): The specified jx1_th column of input matrix X1 exceeds its column dimension"); + if ( jx2 >= X2_dm->ncols ) fn_DisplayError(".../mathlib.c/ColofMatrixDotTimesVector(): The specified jx2_th column of input matrix X2 exceeds its column dimension"); + + X1 = X1_dm->M + (jx1+1)*nrows1 - 1; //Points to the end of the jx1_th column. + X2 = X2_dm->M + (jx2+1)*nrows1 - 1; //Points to the end of the jx2_th column. + if ( _alpha==1.0 ) { + if ( _beta==0.0 ) { + if ( !y_dv ) + for (_i=nrows1-1; _i>=0; _i--, X1--, X2--) *X1 = (*X1) * (*X2); + else { + if ( nrows1 != y_dv->n ) fn_DisplayError(".../mathlib.c/ColofMatrixDotTimesVector(): Number of rows in the input matrix must match the length of the output vector"); + for (_i=nrows1-1, y=y_dv->v+_i; _i>=0; _i--, X1--, X2--, y--) *y = (*X1) * (*X2); + y_dv->flag = V_DEF; + } + } + else if ( _beta==1.0 ) { + if ( !y_dv ) + for (_i=nrows1-1; _i>=0; _i--, X1--, X2--) *X1 = (*X1) * (*X2) + (*X1); + else { + if ( nrows1 != y_dv->n ) fn_DisplayError(".../mathlib.c/ColofMatrixDotTimesVector(): Number of rows in the input matrix must match the length of the output vector"); + for (_i=nrows1-1, y=y_dv->v+_i; _i>=0; _i--, X1--, X2--, y--) *y = (*X1) * (*X2) + (*X1); + y_dv->flag = V_DEF; + } + } + else { + if ( !y_dv ) + for (_i=nrows1-1; _i>=0; _i--, X1--, X2--) *X1 = (*X1) * (*X2) + _beta * (*X1); + else { + if ( nrows1 != y_dv->n ) fn_DisplayError(".../mathlib.c/ColofMatrixDotTimesVector(): Number of rows in the input matrix must match the length of the output vector"); + for (_i=nrows1-1, y=y_dv->v+_i; _i>=0; _i--, X1--, X2--, y--) *y = (*X1) * (*X2) + _beta * (*X1); + y_dv->flag = V_DEF; + } + } + } + else { + if ( _beta==0.0 ) { + if ( !y_dv ) + for (_i=nrows1-1; _i>=0; _i--, X1--, X2--) *X1 = _alpha * (*X1) * (*X2); + else { + if ( nrows1 != y_dv->n ) fn_DisplayError(".../mathlib.c/ColofMatrixDotTimesVector(): Number of rows in the input matrix must match the length of the output vector"); + for (_i=nrows1-1, y=y_dv->v+_i; _i>=0; _i--, X1--, X2--, y--) *y = _alpha * (*X1) * (*X2); + y_dv->flag = V_DEF; + } + } + else if ( _beta==1.0 ) { + if ( !y_dv ) + for (_i=nrows1-1; _i>=0; _i--, X1--, X2--) *X1 = _alpha * (*X1) * (*X2) + (*X1); + else { + if ( nrows1 != y_dv->n ) fn_DisplayError(".../mathlib.c/ColofMatrixDotTimesVector(): Number of rows in the input matrix must match the length of the output vector"); + for (_i=nrows1-1, y=y_dv->v+_i; _i>=0; _i--, X1--, X2--, y--) *y = _alpha * (*X1) * (*X2) + (*X1); + y_dv->flag = V_DEF; + } + } + else { + if ( !y_dv ) + for (_i=nrows1-1; _i>=0; _i--, X1--, X2--) *X1 = _alpha * (*X1) * (*X2) + _beta * (*X1); + else { + if ( nrows1 != y_dv->n ) fn_DisplayError(".../mathlib.c/ColofMatrixDotTimesVector(): Number of rows in the input matrix must match the length of the output vector"); + for (_i=nrows1-1, y=y_dv->v+_i; _i>=0; _i--, X1--, X2--, y--) *y = _alpha * (*X1) * (*X2) + _beta * (*X1); + y_dv->flag = V_DEF; + } + } + } +} +void ColofMatrixDotTimesColofMatrix2ColofMatrix(TSdmatrix *Y_dm, int jy, TSdmatrix *X1_dm, int jx1, TSdmatrix *X2_dm, int jx2, double _alpha, double _beta) { + //Outputs: + // If Y_dm!=NULL, Y_dm(:,jy) = _alpha * X1_dm(:,jx1) .* X2_dm(:,jx2) + _beta * X1_dm(:,jx1). + // If !Y_dm, X1_dm(:,jx1) = _alpha * X1_dm(:,jx1) .* X2_dm(:,jx2) + _beta * X1_dm(:,jx2). + //Inputs: + // _alpha: double scalar. + // _beta: double scalar. + + int _i, nrows1; + double *X1, *X2, *Y; + + if ( !X1_dm || !X1_dm->flag ) fn_DisplayError(".../mathlib.c/ColofMatrixDotTimesColofMatrix(): (1) Input matrix X1 must be created (memory-allocated); (2) Legal values must be given"); + if ( !X2_dm || !X2_dm->flag ) fn_DisplayError(".../mathlib.c/ColofMatrixDotTimesColofMatrix(): (1) Input matrix X2 must be created (memory-allocated); (2) Legal values must be given"); + if ( (nrows1=X1_dm->nrows) != X2_dm->nrows ) fn_DisplayError(".../mathlib.c/ColofMatrixDotTimesColofMatrix(): Numbers of rows in both input matrices must be the same"); + if ( jx1 >= X1_dm->ncols ) fn_DisplayError(".../mathlib.c/ColofMatrixDotTimesVector(): The specified jx1_th column of input matrix X1 exceeds its column dimension"); + if ( jx2 >= X2_dm->ncols ) fn_DisplayError(".../mathlib.c/ColofMatrixDotTimesVector(): The specified jx2_th column of input matrix X2 exceeds its column dimension"); + + X1 = X1_dm->M + (jx1+1)*nrows1 - 1; //Points to the end of the jx1_th column. + X2 = X2_dm->M + (jx2+1)*nrows1 - 1; //Points to the end of the jx2_th column. + if ( _alpha==1.0 ) { + if ( _beta==0.0 ) { + if ( !Y_dm ) + for (_i=nrows1-1; _i>=0; _i--, X1--, X2--) *X1 = (*X1) * (*X2); + else { + if ( nrows1 != Y_dm->nrows ) fn_DisplayError(".../mathlib.c/ColofMatrixDotTimesVector(): Number of rows in input matrices must match that of the output matrix"); + if ( jy >= Y_dm->ncols ) fn_DisplayError(".../mathlib.c/ColofMatrixDotTimesVector(): The specified jy_th column of output matrix Y exceeds its column dimension"); + Y = Y_dm->M + (jy+1)*nrows1 - 1; //Points to the end of the jy_th column. + + for (_i=nrows1-1; _i>=0; _i--, X1--, X2--, Y--) *Y = (*X1) * (*X2); + } + } + else if ( _beta==1.0 ) { + if ( !Y_dm ) + for (_i=nrows1-1; _i>=0; _i--, X1--, X2--) *X1 = (*X1) * (*X2) + (*X1); + else { + if ( nrows1 != Y_dm->nrows ) fn_DisplayError(".../mathlib.c/ColofMatrixDotTimesVector(): Number of rows in input matrices must match that of the output matrix"); + if ( jy >= Y_dm->ncols ) fn_DisplayError(".../mathlib.c/ColofMatrixDotTimesVector(): The specified jy_th column of output matrix Y exceeds its column dimension"); + Y = Y_dm->M + (jy+1)*nrows1 - 1; //Points to the end of the jy_th column. + + for (_i=nrows1-1; _i>=0; _i--, X1--, X2--, Y--) *Y = (*X1) * (*X2) + (*X1); + } + } + else { + if ( !Y_dm ) + for (_i=nrows1-1; _i>=0; _i--, X1--, X2--) *X1 = (*X1) * (*X2) + _beta * (*X1); + else { + if ( nrows1 != Y_dm->nrows ) fn_DisplayError(".../mathlib.c/ColofMatrixDotTimesVector(): Number of rows in input matrices must match that of the output matrix"); + if ( jy >= Y_dm->ncols ) fn_DisplayError(".../mathlib.c/ColofMatrixDotTimesVector(): The specified jy_th column of output matrix Y exceeds its column dimension"); + Y = Y_dm->M + (jy+1)*nrows1 - 1; //Points to the end of the jy_th column. + + for (_i=nrows1-1; _i>=0; _i--, X1--, X2--, Y--) *Y = (*X1) * (*X2) + _beta * (*X1); + } + } + } + else { + if ( _beta==0.0 ) { + if ( !Y_dm ) + for (_i=nrows1-1; _i>=0; _i--, X1--, X2--) *X1 = _alpha * (*X1) * (*X2); + else { + if ( nrows1 != Y_dm->nrows ) fn_DisplayError(".../mathlib.c/ColofMatrixDotTimesVector(): Number of rows in input matrices must match that of the output matrix"); + if ( jy >= Y_dm->ncols ) fn_DisplayError(".../mathlib.c/ColofMatrixDotTimesVector(): The specified jy_th column of output matrix Y exceeds its column dimension"); + Y = Y_dm->M + (jy+1)*nrows1 - 1; //Points to the end of the jy_th column. + + for (_i=nrows1-1; _i>=0; _i--, X1--, X2--, Y--) *Y = _alpha * (*X1) * (*X2); + } + } + else if ( _beta==1.0 ) { + if ( !Y_dm ) + for (_i=nrows1-1; _i>=0; _i--, X1--, X2--) *X1 = _alpha * (*X1) * (*X2) + (*X1); + else { + if ( nrows1 != Y_dm->nrows ) fn_DisplayError(".../mathlib.c/ColofMatrixDotTimesVector(): Number of rows in input matrices must match that of the output matrix"); + if ( jy >= Y_dm->ncols ) fn_DisplayError(".../mathlib.c/ColofMatrixDotTimesVector(): The specified jy_th column of output matrix Y exceeds its column dimension"); + Y = Y_dm->M + (jy+1)*nrows1 - 1; //Points to the end of the jy_th column. + + for (_i=nrows1-1; _i>=0; _i--, X1--, X2--, Y--) *Y = _alpha * (*X1) * (*X2) + (*X1); + } + } + else { + if ( !Y_dm ) + for (_i=nrows1-1; _i>=0; _i--, X1--, X2--) *X1 = _alpha * (*X1) * (*X2) + _beta * (*X1); + else { + if ( nrows1 != Y_dm->nrows ) fn_DisplayError(".../mathlib.c/ColofMatrixDotTimesVector(): Number of rows in input matrices must match that of the output matrix"); + if ( jy >= Y_dm->ncols ) fn_DisplayError(".../mathlib.c/ColofMatrixDotTimesVector(): The specified jy_th column of output matrix Y exceeds its column dimension"); + Y = Y_dm->M + (jy+1)*nrows1 - 1; //Points to the end of the jy_th column. + + for (_i=nrows1-1; _i>=0; _i--, X1--, X2--, Y--) *Y = _alpha * (*X1) * (*X2) + _beta * (*X1); + } + } + } +} + + +void MatrixPlusMatrixUpdate(TSdmatrix *X_dm, TSdmatrix *A_dm) { + //Output: X = A + X where X_dm is an m-by-n general (and possibly symmetric) matrix. + // If X = A, then X will be replaced by 2*A; + //Inputs: + // A_dm: m-by-n general or symmetric matrix. + int _i, _m, _n, nels; + double *X, *A; + + + if ( !X_dm || !A_dm ) fn_DisplayError(".../mathlib.c/MatrixPlusMatrixUpdate(): All input matrices must be created (memory-allocated)"); + else if ( !X_dm->flag || !A_dm->flag ) fn_DisplayError(".../mathlib.c/MatrixPlusMatrixUpdate(): Both input matrices must be given values"); + else { + _m = X_dm->nrows; + _n = X_dm->ncols; + nels = _m * _n; + X = X_dm->M; + A = A_dm->M; + } + + if ( (_m != A_dm->nrows) || (_n != A_dm->ncols) ) fn_DisplayError(".../mathlib.c/MatrixPlusMatrixUpdate(): Dimensions of all input matrices must be same"); + + //=== Making both X_dm and A_dm general if not yet. + if ( !(X_dm->flag & M_GE) ) { + if (X_dm->flag & M_SU) SUtoGE(X_dm); + else if (X_dm->flag & M_SL) SLtoGE(X_dm); + else fn_DisplayError(".../mathlib.c/MatrixPlusMatrixUpdate(): Haven't got time to deal with the M_UT and M_LT cases for X_dm"); + } + if ( !(A_dm->flag & M_GE) ) { + if (A_dm->flag & M_SU) SUtoGE(A_dm); + else if (A_dm->flag & M_SL) SLtoGE(A_dm); + else fn_DisplayError(".../mathlib.c/MatrixPlusMatrixUpdate(): Haven't got time to deal with the M_UT and M_LT cases for A_dm"); + } + for (_i=nels-1; _i>=0; _i--) X[_i] += A[_i]; //This operation may be much cheaper than explicitly using SU or SL operations with two for loops and integer multiplications for matrix offsets. + + if ( X_dm->flag != A_dm->flag ) X_dm->flag = M_GE; //Reset to a general matrix only; otherwise, keep the original X_dm->flag. +} + +void MatrixPlusMatrix(TSdmatrix *X_dm, TSdmatrix *A_dm, TSdmatrix *B_dm) { + //Output: X = A + B where X_dm is an m-by-n general matrix. + // If X=A, A will be replaced by X; if X=B, B will be replaced by X. + //Inputs: + // A_dm: m-by-n general matrix. + // B_dm: m-by-n general matrix. + int _i, _m, _n, nels; + double *X, *A, *B; + + + if ( !X_dm || !A_dm || !B_dm ) fn_DisplayError(".../mathlib.c/MatrixPlusMatrix(): All input matrices must be created (memory-allocated)"); + else if ( !A_dm->flag || !B_dm->flag ) fn_DisplayError(".../mathlib.c/MatrixPlusMatrix(): Two R input matrices must be given values"); + else { + _m = X_dm->nrows; + _n = X_dm->ncols; + nels = _m * _n; + X = X_dm->M; + A = A_dm->M; + B = B_dm->M; + } + + + if ( (_m != A_dm->nrows) || (_m != B_dm->nrows) || (_n != A_dm->ncols) || (_n != B_dm->ncols) ) + fn_DisplayError(".../mathlib.c/MatrixPlusMatrix(): Dimensions of all input matrices must be same"); + else { + if ( !(A_dm->flag & M_GE) ) { + if (A_dm->flag & M_SU) SUtoGE(A_dm); + else if (A_dm->flag & M_SL) SLtoGE(A_dm); + else fn_DisplayError(".../mathlib.c/MatrixPlusMatrix(): Haven't got time to deal with the M_UT and M_LT cases for A_dm"); + } + if ( !(B_dm->flag & M_GE) ) { + if (B_dm->flag & M_SU) SUtoGE(B_dm); + else if (B_dm->flag & M_SL) SLtoGE(B_dm); + else fn_DisplayError(".../mathlib.c/MatrixPlusMatrix(): Haven't got time to deal with the M_UT and M_LT cases for B_dm"); + } + + for (_i=nels-1; _i>=0; _i--) X[_i] = A[_i] + B[_i]; + if (A_dm->flag == B_dm->flag) X_dm->flag = A_dm->flag; + else X_dm->flag = M_GE; + } +} + +void MatrixMinusMatrix(TSdmatrix *X_dm, TSdmatrix *A_dm, TSdmatrix *B_dm) { + //Output: X = A - B where X_dm is an m-by-n general matrix. + // If X=A, A will be replaced by X; if X=B, B will be replaced by X. + //Inputs: + // A_dm: m-by-n general matrix. + // B_dm: m-by-n general matrix. + int _i, _m, _n, nels; + double *X, *A, *B; + + + if ( !X_dm || !A_dm || !B_dm ) fn_DisplayError(".../mathlib.c/MatrixMinusMatrix(): All input matrices must be created (memory-allocated)"); + else if ( !A_dm->flag || !B_dm->flag ) fn_DisplayError(".../mathlib.c/MatrixMinusMatrix(): Two R input matrices must be given values"); + else { + _m = X_dm->nrows; + _n = X_dm->ncols; + nels = _m * _n; + X = X_dm->M; + A = A_dm->M; + B = B_dm->M; + } + + + if ( (_m != A_dm->nrows) || (_m != B_dm->nrows) || (_n != A_dm->ncols) || (_n != B_dm->ncols) ) + fn_DisplayError(".../mathlib.c/MatrixMinusMatrix(): Dimensions of all input matrices must be same"); + else { + if ( !(A_dm->flag & M_GE) ) { + if (A_dm->flag & M_SU) SUtoGE(A_dm); + else if (A_dm->flag & M_SL) SLtoGE(A_dm); + else fn_DisplayError(".../mathlib.c/MatrixMinusMatrix(): Haven't got time to deal with the M_UT and M_LT cases for A_dm"); + } + if ( !(B_dm->flag & M_GE) ) { + if (B_dm->flag & M_SU) SUtoGE(B_dm); + else if (B_dm->flag & M_SL) SLtoGE(B_dm); + else fn_DisplayError(".../mathlib.c/MatrixMinusMatrix(): Haven't got time to deal with the M_UT and M_LT cases for B_dm"); + } + + for (_i=nels-1; _i>=0; _i--) X[_i] = A[_i] - B[_i]; + if (A_dm->flag == B_dm->flag) X_dm->flag = A_dm->flag; + else X_dm->flag = M_GE; + } +} + +void Matrix2PlusMinusMatrix(TSdmatrix *X_dm, TSdmatrix *A_dm, TSdmatrix *B_dm, TSdmatrix *C_dm, const double _alpha, const double _beta, const double _gamma) { + //????? Not yet exhaust all possibilities of alpha, beta, and gamma to get most efficiency. Add more as required. 10 February 2003. + //Output: X = alpha*A + beta*B + gamma*C where X_dm is an m-by-n general matrix. + //Inputs: + // A_dm: m-by-n general matrix. + // B_dm: m-by-n general matrix. + // C_dm: m-by-n general matrix. + // _alpha: a double scalar for A_dm. + // _beta: a double scalar for B_dm. + // _gamma: a double scalar for C_dm. + int _i, _m, _n, nels; + double *X, *A, *B, *C; + + + if ( !X_dm || !A_dm || !B_dm || !C_dm ) fn_DisplayError(".../mathlib.c/Matrix2PlusMinusMatrix(): All input matrices must be created (memory-allocated)"); + else if ( !A_dm->flag || !B_dm->flag || !C_dm->flag ) fn_DisplayError(".../mathlib.c/Matrix2PlusMinusMatrix(): Some of R input matrices are not given values"); + else { + _m = X_dm->nrows; + _n = X_dm->ncols; + nels = _m * _n; + X = X_dm->M; + A = A_dm->M; + B = B_dm->M; + C = C_dm->M; + } + + + if ( (_m != A_dm->nrows) || (_m != B_dm->nrows) || (_m != C_dm->nrows) || (_n != A_dm->ncols) || (_n != B_dm->ncols) || (_n != C_dm->ncols) ) + fn_DisplayError(".../mathlib.c/Matrix2PlusMinusMatrix(): Dimensions of all L and R input matrices must be same"); + else { + if ( !(A_dm->flag & M_GE) ) { + if (A_dm->flag & M_SU) SUtoGE(A_dm); + else if (A_dm->flag & M_SL) SLtoGE(A_dm); + else fn_DisplayError(".../mathlib.c/Matrix2PlusMinusMatrix(): Haven't got time to deal with the M_UT and M_LT cases for A_dm"); + } + if ( !(B_dm->flag & M_GE) ) { + if (B_dm->flag & M_SU) SUtoGE(B_dm); + else if (B_dm->flag & M_SL) SLtoGE(B_dm); + else fn_DisplayError(".../mathlib.c/Matrix2PlusMinusMatrix(): Haven't got time to deal with the M_UT and M_LT cases for B_dm"); + } + if ( !(C_dm->flag & M_GE) ) { + if (C_dm->flag & M_SU) SUtoGE(C_dm); + else if (C_dm->flag & M_SL) SLtoGE(C_dm); + else fn_DisplayError(".../mathlib.c/Matrix2PlusMinusMatrix(): Haven't got time to deal with the M_UT and M_LT cases for C_dm"); + } + + + if ( (_alpha==1.0) && (_beta==1.0) && (_gamma==1.0) ) { + for (_i=nels-1; _i>=0; _i--) X[_i] = A[_i] + B[_i] + C[_i]; + if ( (A_dm->flag == B_dm->flag) && (A_dm->flag == C_dm->flag) ) X_dm->flag = A_dm->flag; + else X_dm->flag = M_GE; + } + else if ( (_alpha==1.0) && (_beta==1.0) && (_gamma==-1.0) ) { + for (_i=nels-1; _i>=0; _i--) X[_i] = A[_i] + B[_i] - C[_i]; + if ( (A_dm->flag == B_dm->flag) && (A_dm->flag == C_dm->flag) ) X_dm->flag = A_dm->flag; + else X_dm->flag = M_GE; + } + else if ( (_alpha==1.0) && (_gamma==1.0) ) { + for (_i=nels-1; _i>=0; _i--) X[_i] = A[_i] + _beta*B[_i] + C[_i]; + if ( (A_dm->flag == B_dm->flag) && (A_dm->flag == C_dm->flag) ) X_dm->flag = A_dm->flag; + else X_dm->flag = M_GE; + } + else { + //Default for all cases (thus, may be most inefficient at this point.). + for (_i=nels-1; _i>=0; _i--) X[_i] = _alpha*A[_i] + _beta*B[_i] + _gamma*C[_i]; + if ( (A_dm->flag == B_dm->flag) && (A_dm->flag == C_dm->flag) ) X_dm->flag = A_dm->flag; + else X_dm->flag = M_GE; + } + } +} + +void MatrixPlusConstantDiagUpdate(TSdmatrix *X_dm, const double _alpha) { + //Output: X = X + diag([_alpha, ..., _alpha]) where X is an n-by-n square real matrix. + int _i, nrows; + double *M; + + if (!X_dm) fn_DisplayError(".../mathlib.c/MatrixPlusConstantDiagUpdate(): Input matrix must be created (memory-allocated)"); + else if (!X_dm->flag) fn_DisplayError(".../mathlib.c/MatrixPlusConstantDiagUpdate(): R input matrix must be given values"); + + M = X_dm->M; + nrows = X_dm->nrows; + for (_i=square(nrows)-1; _i>=0; _i -= nrows+1) M[_i] += _alpha; +} + + +void MatrixDotTimesMatrix(TSdmatrix *X_dm, TSdmatrix *A_dm, TSdmatrix *B_dm, const double _alpha, const double _beta) +{ + //$$$$$ If A_dm or B_dm or X_dm (when _beta!=0) is only upper or lower symmetric, it will be always converted to a general (and symmetric) matrix. $$$$$$ + //Output: + // X_dm is m-by-n. + // X_dm = _alpha * A_dm .* B_dm + _beta * X_dm if X_dm != B_dm. + // X_dm = _alpha * A_dm .* X_dm + _beta * X_dm if X_dm = B_dm. + //Inputs: + // A_dm: m-by-n double vector. + // B_dm: m-by-n double vector. + // _alpha: double scalar. + // _beta: a double scalar. + int _i, nrows, ncols; + double *X, *A, *B; + + + if ( !X_dm || !A_dm || !B_dm) fn_DisplayError(".../mathlib.c/MatrixDotTimesMatrix(): All input matrices must be created (memory-allocated)"); + else if ( !A_dm->flag || !B_dm->flag ) fn_DisplayError(".../mathlib.c/MatrixDotTimesMatrix(): Both R input matrices must be given legal values"); + else if ( _beta && !X_dm->flag ) fn_DisplayError(".../mathlib.c/MatrixDotTimesMatrix(): L output matrix, X_dm, must be given legal values"); + else { + nrows = X_dm->nrows; + ncols = X_dm->ncols; + X = X_dm->M; + A = A_dm->M; + B = B_dm->M; + } + if ( (nrows != A_dm->nrows) || (nrows != B_dm->nrows) || (ncols != A_dm->ncols) || (ncols != B_dm->ncols) ) + fn_DisplayError(".../mathlib.c/MatrixDotTimesMatrix(): Dimensions of all input matrices must be same"); + if ( !(A_dm->flag & M_GE) ) { + if (A_dm->flag & M_SU) SUtoGE(A_dm); + else if (A_dm->flag & M_SL) SLtoGE(A_dm); + else fn_DisplayError(".../mathlib.c/MatrixDotTimesMatrix(): Haven't got time to deal with the M_UT or M_LT cases for A_dm"); + } + if ( !(B_dm->flag & M_GE) ) { + if (B_dm->flag & M_SU) SUtoGE(B_dm); + else if (B_dm->flag & M_SL) SLtoGE(B_dm); + else fn_DisplayError(".../mathlib.c/MatrixDotTimesMatrix(): Haven't got time to deal with the M_UT or M_LT cases for B_dm"); + } + if ( _beta && !(X_dm->flag & M_GE) ) { + if (X_dm->flag & M_SU) SUtoGE(X_dm); + else if (X_dm->flag & M_SL) SLtoGE(X_dm); + else fn_DisplayError(".../mathlib.c/MatrixDotTimesMatrix(): Haven't got time to deal with the M_UT or M_LT cases for X_dm"); + } + + + + if ( _alpha==1.0 ) { + if ( _beta==0.0 ) { + for (_i=nrows*ncols-1; _i>=0; _i--) X[_i] = A[_i] * B[_i]; + if (B_dm->flag != A_dm->flag) X_dm->flag = M_GE; + else X_dm->flag = A_dm->flag; + } + else if ( _beta==1.0 ) { + for (_i=nrows*ncols-1; _i>=0; _i--) X[_i] += A[_i] * B[_i]; + if (X_dm->flag != A_dm->flag || X_dm->flag != B_dm->flag) X_dm->flag = M_GE; + } + else { + for (_i=nrows*ncols-1; _i>=0; _i--) X[_i] = A[_i] * B[_i] + _beta * X[_i]; + if (X_dm->flag != A_dm->flag || X_dm->flag != B_dm->flag) X_dm->flag = M_GE; + } + } + else { + if ( _beta==0.0 ) { + for (_i=nrows*ncols-1; _i>=0; _i--) X[_i] = _alpha * A[_i] * B[_i]; + if (B_dm->flag != A_dm->flag) X_dm->flag = M_GE; + else X_dm->flag = A_dm->flag; + } + else if ( _beta==1.0 ) { + for (_i=nrows*ncols-1; _i>=0; _i--) X[_i] += _alpha * A[_i] * B[_i]; + if (X_dm->flag != A_dm->flag || X_dm->flag != B_dm->flag) X_dm->flag = M_GE; + } + else { + for (_i=nrows*ncols-1; _i>=0; _i--) X[_i] = _alpha * A[_i] * B[_i] + _beta * X[_i]; + if (X_dm->flag != A_dm->flag || X_dm->flag != B_dm->flag) X_dm->flag = M_GE; + } + } +} + + + +void CopyVector0(TSdvector *x1_dv, const TSdvector *x2_dv) { + //Ouputs: + // x1_dv, whose elements are copied from from x2_dv. + //Inputs: + // Copying elements from x2_dv->v to x1_dv. + int _n; + + if ( !x1_dv || !x2_dv || (x1_dv->n != x2_dv->n) ) + fn_DisplayError(".../mathlib.c/CopyVector0(): (1) all input pointers must be created (memory-allocated) and (2) dimensions of x1_dv and x2_dv must be compatible"); + else if ( !x2_dv->flag ) { + // printf("x2_dv->flag is %d, and length is %d, and the vector is: \n", x2_dv->flag, x2_dv->n); + // PrintVector(x2_dv, " %g "); + fn_DisplayError(".../mathlib.c/CopyVector0(): R input vector must be given values"); + } + else _n = x2_dv->n; + + if ( _n != x1_dv->n ) fn_DisplayError(".../mathlib.c/CopyVector0(): Both L and R input vectors must have the same length"); + memcpy(x1_dv->v, x2_dv->v, _n*sizeof(double)); + x1_dv->flag = V_DEF; +} + + +void CopyMatrix0(TSdmatrix *x1_dm, TSdmatrix *x2_dm) { + //Deals with double matrices. + //Copies the entire matrix x2_dm to x1_dm. + int nrows1, ncols1, nrows2, ncols2; + + if ( !x1_dm || !x2_dm ) fn_DisplayError(".../mathlib.c/CopyMatrix0(): All input matrices must be created (memory-allocated)"); + else if ( !x2_dm->flag ) fn_DisplayError(".../mathlib.c/CopyMatrix0(): R input matrix must be given values"); + else { + nrows1=x1_dm->nrows; + ncols1=x1_dm->ncols; + nrows2=x2_dm->nrows; + ncols2=x2_dm->ncols; + } + + + if (nrows2 == nrows1 && ncols2 == ncols1) { + //$$$$$$$$$$ 5/15/2003. At some point, the following if command should be got rid of completely. For now, we keep this for maintaining the backward compatibility. + if ( !(x2_dm->flag & M_GE) ) { + if (x2_dm->flag & M_SU) SUtoGE(x2_dm); + else if (x2_dm->flag & M_SL) SLtoGE(x2_dm); +// else fn_DisplayError(".../mathlib.c/CopyMatrix0(): Haven't got time to deal with the M_UT and M_LT cases for x2_dm"); + } + //Both matrices have the same size. + memcpy(x1_dm->M, x2_dm->M, nrows1 * ncols1 * sizeof(double)); + x1_dm->flag = x2_dm->flag; + +// #ifdef SWITCHTOTZCMATH // define: use my own C math library ; undef: use others. +// memcpy(x1_dm->M, x2_dm->M, nrows1 * ncols1 * sizeof(double)); +// #endif +// #ifdef SWITCHTOINTELCMATH // define: use Intek MKL LAPACK library; undef: use others. +// cblas_dcopy(nrows1*ncols1, x2_dm->M, 1, x1_dm->M, 1); +// #endif +// x1_dm->flag = x2_dm->flag; + } + else fn_DisplayError(".../mathlib.c/CopyMatrix0(): Copying matrix (x2_m) and copied matrix (x1_dm) must have the same size"); + +//?????????? The following is good, but should be used in CopySubmatrix0(), which might have already taken this into account. +// else if (nrows2 <= nrows1 && ncols2 <= ncols1) { +// if ( !(x2_dm->flag & M_GE) ) fn_DisplayError(".../mathlib.c/CopyMatrix0(): Haven't got time to deal with the M_UT and M_LT cases for x2_dm"); +// //Size of x2_dm is smaller than that of x1_dm. +// for (_i=0; _i<ncols2; _i++) { +// loc1 = _i*nrows1; //Points to the top of the column in x1_dm. +// loc2 = _i*nrows2; //Points to the top of the column in x2_dm. +// memcpy((x1_dm->M+loc1), (x2_dm->M+loc2), x2_dm->nrows*sizeof(double)); +// } +// x1_dm->flag = M_GE; +// } +// else fn_DisplayError(".../mathlib.c/CopyMatrix0(): number of rows (columns) of the copying matrix (x2) must be no greater than that of the copied matrix (x1)"); +} + +void CopyCellvec0(TSdcellvec *x1_dcv, TSdcellvec *x2_dcv) +{ + //Deals with double vectors. + //Copies the entire cellvector x2_dcv to x1_dcv. + int _i, ncells; + if (!x1_dcv || !x2_dcv) fn_DisplayError(".../mathlib.c/CopyCellvec0(): Both input cellvectors must be created (memory-allocated)"); + else if ( (ncells=x2_dcv->ncells) != x1_dcv->ncells ) fn_DisplayError(".../mathlib.c/CopyCellvec0(): Both input cellvectors must have exactly the same size"); + for (_i=ncells-1; _i>=0; _i--) CopyVector0(x1_dcv->C[_i], x2_dcv->C[_i]); +} + +void CopyCell0(TSdcell *x1_dc, TSdcell *x2_dc) +{ + //Deals with double matrices. + //Copies the entire cell x2_dc to x1_dc. + int _i, ncells; + if (!x1_dc || !x2_dc) fn_DisplayError(".../mathlib.c/CopyCell0(): Both input cells must be created (memory-allocated)"); + else if ( (ncells=x2_dc->ncells) != x1_dc->ncells ) fn_DisplayError(".../mathlib.c/CopyCell0(): Both input cells must have exactly the same size"); + for (_i=ncells-1; _i>=0; _i--) CopyMatrix0(x1_dc->C[_i], x2_dc->C[_i]); +} + + +void CopySubmatrix0(TSdmatrix *x1_dm, TSdmatrix *x2_dm, const int br, const int bc, const int nrs, const int ncs) +{ + //Copies the nrs-by-ncs submatrix of x2_dm to the most left corner of x1_dm (i.e., at 0). + //Note: br means the beginning of the row (*must* be 0 based) for this submatrix of x2_dm, inclusive; + // bc means the beginning of the column (*must* be 0 based) for this submatrix of x2_dm, inclusive. + int _j, loc1, loc2, + nrows1, ncols1, nrows2, ncols2; + + if ( !x1_dm || !x2_dm ) fn_DisplayError(".../mathlib.c/CopySubmatrix0(): All input matrices must be created (memory-allocated)"); + else if ( !x2_dm->flag ) fn_DisplayError(".../mathlib.c/CopySubmatrix0(): R input matrix must be given values"); + else { + nrows1=x1_dm->nrows; + ncols1=x1_dm->ncols; + nrows2=x2_dm->nrows; + ncols2=x2_dm->ncols; + } + + if ( !(x2_dm->flag & M_GE) ) { + if (x2_dm->flag & M_SU) SUtoGE(x2_dm); + else if (x2_dm->flag & M_SL) SLtoGE(x2_dm); + else fn_DisplayError(".../mathlib.c/CopySubmatrix0(): Haven't got time to deal with the M_UT and M_LT cases for x2_dm"); + } + + //=== Performs the operation. + if ( (bc+ncs)<=ncols2 && (br+nrs)<=nrows2 && ncs<=ncols1 && nrs<=nrows1 ) { + for (_j=ncs-1; _j>=0; _j--) { + loc1 = _j*nrows1; //Points to the top of the column in x1_dm. + loc2 = mos(br, bc+_j, nrows2); //Points to the top of the column in the submatrix of x2_dm. + #ifdef SWITCHTOTZCMATH // define: use my own C math library ; undef: use others. + memcpy(x1_dm->M+loc1, x2_dm->M+loc2, nrs*sizeof(double)); + #endif + #ifdef SWITCHTOINTELCMATH // define: use Intek MKL LAPACK library; undef: use others. + cblas_dcopy(nrs, x2_dm->M+loc2, 1, x1_dm->M+loc1, 1); + #endif + } + x1_dm->flag = M_GE; + } + else fn_DisplayError(".../mathlib.c/CopySubmatrix0(): the submatrix of x2_dm must be within the ranges of both x1_dm and x2_dm"); +} + +void CopySubmatrix(TSdmatrix *x1_dm, const int br1, const int bc1, TSdmatrix *x2_dm, const int br2, const int bc2, const int nrs, const int ncs) { + //Copies the nrs-by-ncs submatrix of x2_dm to x1_dm at the specified location (br1, bc1). + //Note: br1 means the beginning of the row (*must* be 0 based) for x1_dm, inclusive. + // bc1 means the beginning of the column (*must* be 0 based) for x1_dm, inclusive. + // br2 means the beginning of the row (*must* be 0 based) for this submatrix of x2_dm, inclusive. + // bc2 means the beginning of the column (*must* be 0 based) for this submatrix of x2_dm, inclusive. + int _j, loc1, loc2, + nrows1, ncols1, nrows2, ncols2; + + if ( !x1_dm || !x2_dm ) fn_DisplayError(".../mathlib.c/CopySubmatrix(): All input matrices must be created (memory-allocated)"); + else if ( !x2_dm->flag ) fn_DisplayError(".../mathlib.c/CopySubmatrix(): R input matrix must be given values"); + else { + nrows1=x1_dm->nrows; + ncols1=x1_dm->ncols; + nrows2=x2_dm->nrows; + ncols2=x2_dm->ncols; + } + + if ( (bc2+ncs)<=ncols2 && (br2+nrs)<=nrows2 && (bc1+ncs)<=ncols1 && (br1+nrs)<=nrows1 ) { + for (_j=ncs-1; _j>=0; _j--) { + loc1 = mos(br1, bc1+_j, nrows1); //Points to the top of the column in the submatrix of x1_dm. + loc2 = mos(br2, bc2+_j, nrows2); //Points to the top of the column in the submatrix of x2_dm. + memcpy((x1_dm->M+loc1), (x2_dm->M+loc2), nrs*sizeof(double)); + } + x1_dm->flag = M_GE; + } + else fn_DisplayError(".../mathlib.c/CopySubmatrix(): the submatrix of x2_dm must be within the ranges of both x1_dm and x2_dm"); +} + +#if defined( INTELCMATHLIBRARY ) +void CopySubrowmatrix(TSdmatrix *x1_dm, const int br1, const int bc1, TSdmatrix *x2_dm, const int br2, const int bc2, const int nrs, const int ncs) +{ + //??????? NOT tested yet. + //Copies the nrs-by-ncs submatrix of x2_dm to x1_dm at the specified location (br1, bc1). + //Note: br1 means the beginning of the row (*must* be 0 based) for x1_dm, inclusive. + // bc1 means the beginning of the column (*must* be 0 based) for x1_dm, inclusive. + // br2 means the beginning of the row (*must* be 0 based) for this submatrix of x2_dm, inclusive. + // bc2 means the beginning of the column (*must* be 0 based) for this submatrix of x2_dm, inclusive. + int _i, loc1, loc2, + nrows1, ncols1, nrows2, ncols2; + + if ( !x1_dm || !x2_dm ) fn_DisplayError(".../mathlib.c/CopySubrowmatrix(): All input matrices must be created (memory-allocated)"); + else if ( !x2_dm->flag ) fn_DisplayError(".../mathlib.c/CopySubrowmatrix(): R input matrix must be given values"); + else { + nrows1=x1_dm->nrows; + ncols1=x1_dm->ncols; + nrows2=x2_dm->nrows; + ncols2=x2_dm->ncols; + } + + if ( (bc2+ncs)<=ncols2 && (br2+nrs)<=nrows2 && (bc1+ncs)<=ncols1 && (br1+nrs)<=nrows1 ) { + for (_i=nrs-1; _i>=0; _i--) { + loc1 = mos(br1+_i, bc1, nrows1); //Points to the beginning of the row in the submatrix of x1_dm. + loc2 = mos(br2+_i, bc2, nrows2); //Points to the beginning of the row in the submatrix of x2_dm. + cblas_dcopy(ncs, x2_dm->M+loc2, nrows2, x1_dm->M+loc1, nrows1); + } + } + else fn_DisplayError(".../mathlib.c/CopySubrowmatrix(): the submatrix of x2_dm must be within the range of itself as well as x1_dm"); +} +#else + Haven't got time to code up the default using Linux BLAS. +#endif + + +#if defined( INTELCMATHLIBRARY ) +void CopySubmatrix2rowmatrix(TSdmatrix *x1_dm, const int br1, const int bc1, TSdmatrix *x2_dm, const int br2, const int bc2, const int nrs, const int ncs) +{ + //Column by column operation on x2_dm: coping the transpose of the nrs-by-ncs submatrix of x2_dm to x1_dm at the specified location (br1, bc1). + //Note: br1 means the beginning of the row (*must* be 0 based) for x1_dm, inclusive. + // bc1 means the beginning of the column (*must* be 0 based) for x1_dm, inclusive. + // br2 means the beginning of the row (*must* be 0 based) for this submatrix of x2_dm, inclusive. + // bc2 means the beginning of the column (*must* be 0 based) for this submatrix of x2_dm, inclusive. + int _j, loc1, loc2, + nrows1, ncols1, nrows2, ncols2; + + if ( !x1_dm || !x2_dm ) fn_DisplayError(".../mathlib.c/CopySubmatrix2rowmatrix(): All input matrices must be created (memory-allocated)"); + else if ( !x2_dm->flag ) fn_DisplayError(".../mathlib.c/CopySubmatrix2rowmatrix(): R input matrix must be given values"); + else { + nrows1=x1_dm->nrows; + ncols1=x1_dm->ncols; + nrows2=x2_dm->nrows; + ncols2=x2_dm->ncols; + } + + if ( (bc2+ncs)<=ncols2 && (br2+nrs)<=nrows2 && (bc1+nrs)<=ncols1 && (br1+ncs)<=nrows1 ) { + for (_j=ncs-1; _j>=0; _j--) { + loc1 = mos(br1+_j, bc1, nrows1); //Points to the beginning of the row in the submatrix of x1_dm. + loc2 = mos(br2, bc2+_j, nrows2); //Points to the top of the column in the submatrix of x2_dm. + cblas_dcopy(nrs, x2_dm->M+loc2, 1, x1_dm->M+loc1, nrows1); + } + } + else fn_DisplayError(".../mathlib.c/CopySubmatrix2rowmatrix(): the submatrix of x2_dm must be within the range of x2_dm and its transpose must be within the range of x1_dm"); +} +#else + Haven't got time to code up the default using Linux BLAS. +#endif + + +#if defined( INTELCMATHLIBRARY ) +void CopySubrowmatrix2matrix(TSdmatrix *x1_dm, const int br1, const int bc1, TSdmatrix *x2_dm, const int br2, const int bc2, const int nrs, const int ncs) +{ + //??????? NOT tested yet. + //Row by row operation on x2_dm: coping the transpose of the nrs-by-ncs submatrix of x2_dm to x1_dm at the specified location (br1, bc1). + //Note: br1 means the beginning of the row (*must* be 0 based) for x1_dm, inclusive. + // bc1 means the beginning of the column (*must* be 0 based) for x1_dm, inclusive. + // br2 means the beginning of the row (*must* be 0 based) for this submatrix of x2_dm, inclusive. + // bc2 means the beginning of the column (*must* be 0 based) for this submatrix of x2_dm, inclusive. + int _i, loc1, loc2, + nrows1, ncols1, nrows2, ncols2; + + if ( !x1_dm || !x2_dm ) fn_DisplayError(".../mathlib.c/CopySubrowmatrix2matrix(): All input matrices must be created (memory-allocated)"); + else if ( !x2_dm->flag ) fn_DisplayError(".../mathlib.c/CopySubrowmatrix2matrix(): R input matrix must be given values"); + else { + nrows1=x1_dm->nrows; + ncols1=x1_dm->ncols; + nrows2=x2_dm->nrows; + ncols2=x2_dm->ncols; + } + + if ( (bc2+ncs)<=ncols2 && (br2+nrs)<=nrows2 && (bc1+nrs)<=ncols1 && (br1+ncs)<=nrows1 ) { + for (_i=nrs-1; _i>=0; _i--) { + loc1 = mos(br1, bc1+_i, nrows1); //Points to the top of the column in the submatrix of x1_dm. + loc2 = mos(br2+_i, bc2, nrows2); //Points to the beginning of the row in the submatrix of x2_dm. + cblas_dcopy(ncs, x2_dm->M+loc2, nrows2, x1_dm->M+loc1, 1); + } + } + else fn_DisplayError(".../mathlib.c/CopySubrowmatrix2matrix(): the submatrix of x2_dm must be within the range of itself as well as x1_dm"); +} +#else + Haven't got time to code up the default using Linux BLAS. +#endif + + +void CopySubvector(TSdvector *x1_dv, const int ptrloc1, const TSdvector *x2_dv, const int ptrloc2, const int nels) { + //Ouputs: + // x1_dv, whose elements from x1_dv->v+ptrloc1 to x1_dv->v+ptrloc1+nels-1 are copied from from x2_dv->v. + //Inputs: + // Copying elements from x2_dv->v+ptrloc2 to x2_dv->v+ptrloc2+nels-1 (to x1_dv->v). + // nels: number of elements to be copied. + // ptrloc1: pointer location for x1_dv->v where the copy begins, inclusive. + // ptrloc2: pointer location for x2_dv->v where the copy begins, inclusive. + + if ( !x1_dv || !x2_dv ) fn_DisplayError(".../mathlib.c/CopySubvector(): All input vectors must be created (memory-allocated)"); + else if (!x2_dv->flag) fn_DisplayError(".../mathlib.c/CopySubvector(): R input vector must be given values"); + + if ( (ptrloc2+nels)<=x2_dv->n && (ptrloc1+nels)<=x1_dv->n) { + memcpy(x1_dv->v+ptrloc1, x2_dv->v+ptrloc2, nels*sizeof(double)); + x1_dv->flag = V_DEF; + } + else fn_DisplayError(".../mathlib.c/CopySubvector(): Copying (copied) elements are outside the dimension of the copying vector x2_dv (the copied vector x1_dv)"); +} +//--- +void CopySubvector_int(TSivector *x1_iv, const int ptrloc1, const TSivector *x2_iv, const int ptrloc2, const int nels) +{ + //Ouputs: + // x1_iv, whose elements from x1_iv->v+ptrloc1 to x1_iv->v+ptrloc1+nels-1 are copied from from x2_iv->v. + //Inputs: + // Copying elements from x2_iv->v+ptrloc2 to x2_iv->v+ptrloc2+nels-1 (to x1_iv->v). + // nels: number of elements to be copied. + // ptrloc1: pointer location for x1_iv->v where the copy begins, inclusive. + // ptrloc2: pointer location for x2_iv->v where the copy begins, inclusive. + + if ( !x1_iv || !x2_iv ) fn_DisplayError(".../mathlib.c/CopySubvector_int(): All input vectors must be created (memory-allocated)"); + else if (!x2_iv->flag) fn_DisplayError(".../mathlib.c/CopySubvector_int(): R input vector must be given values"); + + if ( (ptrloc2+nels)<=x2_iv->n && (ptrloc1+nels)<=x1_iv->n) { + memcpy(x1_iv->v+ptrloc1, x2_iv->v+ptrloc2, nels*sizeof(int)); + x1_iv->flag = V_DEF; + } + else fn_DisplayError(".../mathlib.c/CopySubvector_int(): Copying (copied) elements are outside the dimension of the copying vector x2_iv (the copied vector x1_iv)"); +} + +void CopySubmatrix2vector(TSdvector *x1_dv, const int ptrloc1, TSdmatrix *x2_dm, const int br, const int bc, const int nels) +{ + //Ouputs: + // x1_dv whose elements from x1_dv->v+ptrloc1 to x1_dv->v+ptrloc1+nels-1 are copied from x2_dm->M[br,bc] onward (inclusive) + // where copied elements can run column by column all the way to the end of x2_dm->M[end,end]. Thus, this function + // can be used as the Matlab reshape command. + //Inputs: Copying elements from x2_dm->M+ptrloc2 to x2_dm->M+ptrloc2+nels-1 (to x1_dv->v). + // ptrloc1: pointer location for x1_dv->v where the copy begins, inclusive. + // br: beginning of the row (*must* be 0 based) for x2_dm, inclusive. + // bc: beginning of the column (*must* be 0 based) for x2_dm, inclusive. + // nels: number of elements to be copied. + int ptrloc2; //pointer location for x2_dm->M where the copy begins. + + if ( !x1_dv || !x2_dm ) fn_DisplayError(".../mathlib.c/CopySubmatrix2vector(): All input pointers must be created (memory-allocated)"); + else if ( !x2_dm->flag ) fn_DisplayError(".../mathlib.c/CopySubmatrix2vector(): R input matrix must be given values"); + else ptrloc2 = mos(br,bc,x2_dm->nrows); // ptrloc2: pointer location for x2_dm->M where the copy begins. + + if ( !(x2_dm->flag & M_GE) ) { + if (x2_dm->flag & M_SU) SUtoGE(x2_dm); + else if (x2_dm->flag & M_SL) SLtoGE(x2_dm); + else fn_DisplayError(".../mathlib.c/CopySubmatrix2vector(): Haven't got time to deal with the M_UT and M_LT cases for x2_dm"); + } + + + + if ( (ptrloc2+nels)<=(x2_dm->nrows*x2_dm->ncols) && (ptrloc1+nels)<=x1_dv->n) { + memcpy(x1_dv->v+ptrloc1, x2_dm->M+ptrloc2, nels*sizeof(double)); + x1_dv->flag = V_DEF; + } + else fn_DisplayError(".../mathlib.c/CopySubmatrix2vector(): Copying (copied) elements are outside the dimension of the copying matrix x2_dm (the copied vector x1_dv)"); +} + +void CopySubmatrix2vector_sub(TSdvector *x1_dv, const int ptrloc1, TSdmatrix *x2_dm, const int br, const int bc, const int nrs, const int ncs) { + //Ouputs: Unlike CopySubmatrix2vector, _sub means a submatrix, NOT just one column, of the copying matrix x2_dm. + // The copying submatrix must start at (br, bc) ane end at (br+nrs-1, bc+ncs-1). + // Copying is done column by column. + // x1_dv, whose elements from x1_dv->v+ptrloc1 to x1_dv->v+ptrloc1+nrs*ncs-1 are copied from the submatrix of of x2_dm->m. + //Inputs: The copying submatrix of x2_dm->M. + // ptrloc1: inclusive pointer location for x1_dv->v where the copy begins. + // br: beginning of the row (*must* be 0 based) for x2_dm, inclusive. + // bc: beginning of the column (*must* be 0 based) for x2_dm, inclusive. + // nrs: number of rows to be copied. + // ncs: number of colums to be copied. + int nrows, ncols, _j, loc1; + double *v, *M; + + if ( !x1_dv || !x2_dm ) fn_DisplayError(".../mathlib.c/CopySubmatrix2vector_sub(): All input pointers must be created (memory-allocated)"); + else if ( !x2_dm->flag ) fn_DisplayError(".../mathlib.c/CopySubmatrix2vector_sub(): R input matrix must be given values"); + else { + v = x1_dv->v; + M = x2_dm->M; + nrows = x2_dm->nrows; + ncols = x2_dm->ncols; + } + + if ( !(x2_dm->flag & M_GE) ) { + if (x2_dm->flag & M_SU) SUtoGE(x2_dm); + else if (x2_dm->flag & M_SL) SLtoGE(x2_dm); + else fn_DisplayError(".../mathlib.c/CopySubmatrix2vector_sub(): Haven't got time to deal with the M_UT and M_LT cases for x2_dm"); + } + + if ( (bc+ncs)<=ncols && (br+nrs)<=nrows && (ptrloc1+ncs*nrs)<=x1_dv->n ) { + loc1 = ptrloc1; + for (_j=0; _j<ncs; _j++) { + memcpy(v+loc1, M+mos(br, bc+_j, nrows), nrs*sizeof(double)); //mos(br, bc+_j, nrows): Points to the top of the column in the submatrix of x2_dm. + loc1 += nrs; //Must be after memcpy(). + } + x1_dv->flag = V_DEF; + } + else fn_DisplayError(".../mathlib.c/CopySubmatrix2vector_sub(): the submatrix of x2_dm must be within the ranges of both x1_dv and x2_dm"); +} + +void CopySubmatrix2vector_int(TSivector *x1_iv, const int ptrloc1, TSimatrix *x2_im, const int br, const int bc, const int nels) { + //Ouputs: + // x1_iv, whose elements from x1_iv->v+ptrloc1 to x1_iv->v+ptrloc1+nels-1 are copied from a column of x2_im->m. + //Inputs: Copying elements from x2_im->M+ptrloc2 to x2_im->M+ptrloc2+nels-1 (to x1_iv->v). + // ptrloc1: pointer location for x1_iv->v where the copy begins, inclusive. + // br: beginning of the row (*must* be 0 based) for x2_im, inclusive. + // bc: beginning of the column (*must* be 0 based) for x2_im, inclusive. + // nels: number of elements to be copied. + int ptrloc2; //pointer location for x2_im->M where the copy begins. + + if ( !x1_iv || !x2_im ) fn_DisplayError(".../mathlib.c/CopySubmatrix2vector_int(): All input pointers must be created (memory-allocated)"); + else ptrloc2 = mos(br,bc,x2_im->nrows); // ptrloc2: pointer location for x2_im->M where the copy begins. + + + + if ( (ptrloc2+nels)<=(x2_im->nrows*x2_im->ncols) && (ptrloc1+nels)<=x1_iv->n) { + memcpy(x1_iv->v+ptrloc1, x2_im->M+ptrloc2, nels*sizeof(int)); + x1_iv->flag = V_DEF; + } + else fn_DisplayError(".../mathlib.c/CopySubmatrix2vector_int(): Copying (copied) elements are outside the dimension of the copying matrix x2_im (the copied vector x1_iv)"); +} + +void CopySubmatrix2vector_row(TSdvector *x1_dv, const int ptrloc1, TSdmatrix *x2_dm, const int br, const int bc, const int nels) { + //This is much less efficient because we copy a row of x2_dm where x2_dm is a column-major matrix. But sometimes, + // transposing x2_dm and then using CopySubmatrix2vector() proves more costly if the transpose has to be done in each iteration. + //If SWITCHINTELCMATH is activated, it may achieve efficiency. + // + //Ouputs: copying a row of x2_dm to a vector. + // x1_dv, whose elements from x1_dv->v+ptrloc1 to x1_dv->v+ptrloc1+nels-1 are copied from a row of x2_dm->m. + //Inputs: Copying elements from x2_dm->M(br, bc) to x2_dm->M(br, bc+nels-1) (to x1_dv->v). + // ptrloc1: inclusive pointer location for x1_dv->v where the copy begins. + // br: beginning of the row (*must* be 0 based) for x2_dm, inclusive. + // bc: beginning of the column (*must* be 0 based) for x2_dm, inclusive. + // nels: number of elements to be copied. + int nrows; + #if !defined(SWITCHTOINTELCMATH) // define: use my own C math library ; undef: use others. + int _i; + #endif + double *v, *M; + + if ( !x1_dv || !x2_dm ) fn_DisplayError(".../mathlib.c/CopySubmatrix2vector_row(): All input pointers must be created (memory-allocated)"); + else if ( !x2_dm->flag ) fn_DisplayError(".../mathlib.c/CopySubmatrix2vector_row(): R input matrix must be given values"); + else { + v = x1_dv->v; + M = x2_dm->M; + nrows = x2_dm->nrows; + } + + if ( !(x2_dm->flag & M_GE) ) { + if (x2_dm->flag & M_SU) SUtoGE(x2_dm); + else if (x2_dm->flag & M_SL) SLtoGE(x2_dm); + else fn_DisplayError(".../mathlib.c/CopySubmatrix2vector_row(): Haven't got time to deal with the M_UT and M_LT cases for x2_dm"); + } + + + if ( (bc+nels)<=x2_dm->ncols && (ptrloc1+nels)<=x1_dv->n) { + #if defined (INTELCMATHLIBRARY) // define: use Intek MKL LAPACK library; undef: use others. + cblas_dcopy(nels, M+mos(br, bc, nrows), nrows, v+ptrloc1, 1); //mos(): inclusive pointer location for x2_dm where the copy begins. + #else //Default to SWITCHTOTZCMATH // define: use my own C math library ; undef: use others. + //for (_i=0; _i<nels; _i++) v[ptrloc1+_i] = M[mos(br, bc+_i, nrows)]; + for (_i=nels-1; _i>=0; _i--) v[ptrloc1+_i] = M[mos(br, bc+_i, nrows)]; //Changed above to this. 9/2/03. + #endif + x1_dv->flag = V_DEF; + } + else fn_DisplayError(".../mathlib.c/CopySubmatrix2vector_row(): Copying (copied) elements are outside the dimension of the copying matrix x2_dm (the copied vector x1_dv)"); +} + +void CopySubvector2matrix(TSdmatrix *x1_dm, const int br, const int bc, const TSdvector *x2_dv, const int ptrloc2, const int nels) { + //Ouputs: only the ``bc''th column of the matrix is copied. If this is too restrictive, see CopySubvector2matrix_unr(). + // Copied elements (x1_dm->M+ptrloc1 to x1_dv->M+ptrloc1+nels-1) from x2_dv->v. + // Always sets x1_dm->flag = M_GE after the call to this function. + //Inputs: + // Copying elements from x2_dv->v+ptrloc2 to x2_dv->v+ptrloc2+nels-1 (to x1_dm->M). + // nels: number of elements to be copied. + // br: beginning of the row (*must* be 0 based) for x2_dm, inclusive. + // bc: beginning of the column (*must* be 0 based) for x2_dm, inclusive. + // ptrloc2: pointer location for x2_dv->v where the copy begins, inclusive. + int ptrloc1, nrows, ncols; + + if ( !x1_dm || !x2_dv ) fn_DisplayError(".../mathlib.c/CopySubvector2matrix(): All input pointers must be created (memory-allocated)"); + else if (!x2_dv->flag) fn_DisplayError(".../mathlib.c/CopySubvector2matrix(): R input vector must be given values"); + else { + nrows = x1_dm->nrows; + ncols = x1_dm->ncols; + ptrloc1 = mos(br, bc, x1_dm->nrows); //ptrloc1: pointer location for x1_dm->M where the copy begins. + } + + + if ( (ptrloc2+nels)<=x2_dv->n && (br+nels)<=nrows ) { + memcpy(x1_dm->M+ptrloc1, x2_dv->v+ptrloc2, nels*sizeof(double)); + x1_dm->flag = M_GE; //Always reset to a general matrix because it will almost surely break, say, the original symmetry of the matrix x1_dm if x1_dm->flag exists in the first place. + //-------if (!x1_dm->flag) x1_dm->flag = M_GE; //Set to a general matrix if this matrix is not set yet. + } + else fn_DisplayError(".../mathlib.c/CopySubvector2matrix(): Copying (copied) elements are outside the (row) dimension of the copying vector x2_dv (the copied matrix x1_dm)"); +} + + +#if defined( INTELCMATHLIBRARY ) +void CopySubvector2rowmatrix(TSdmatrix *x1_dm, const int br, const int bc, const TSdvector *x2_dv, const int ptrloc2, const int nels) +{ + //Ouputs: + // Only the ``br''th row of the matrix x1_dm (starting from the ``bc''th column) is copied from x2_dv->v. + // Always sets x1_dm->flag = M_GE after the call to this function. + //Inputs: + // Copying elements from x2_dv->v+ptrloc2 to x2_dv->v+ptrloc2+nels-1 (to x1_dm). + // nels: number of elements to be copied. + // br: beginning of the row (*must* be 0 based) for x2_dm, inclusive. + // bc: beginning of the column (*must* be 0 based) for x2_dm, inclusive. + // ptrloc2: pointer location for x2_dv->v where the copy begins, inclusive. + int ptrloc1, nrows, ncols; + + if ( !x1_dm || !x2_dv ) fn_DisplayError(".../mathlib.c/CopySubvector2rowmatrix(): All input pointers must be created (memory-allocated)"); + else if (!x2_dv->flag) fn_DisplayError(".../mathlib.c/CopySubvector2rowmatrix(): R input vector must be given values"); + else { + nrows = x1_dm->nrows; + ncols = x1_dm->ncols; + ptrloc1 = mos(br, bc, x1_dm->nrows); //ptrloc1: pointer location for x1_dm->M where the copy begins. + } + + + if ( (ptrloc2+nels)<=x2_dv->n && (bc+nels)<=ncols ) { + cblas_dcopy(nels, x2_dv->v+ptrloc2, 1, x1_dm->M+ptrloc1, nrows); + x1_dm->flag = M_GE; //Always reset to a general matrix because it will almost surely break, say, the original symmetry of the matrix x1_dm if x1_dm->flag exists in the first place. + //-------if (!x1_dm->flag) x1_dm->flag = M_GE; //Set to a general matrix if this matrix is not set yet. + } + else fn_DisplayError(".../mathlib.c/CopySubvector2rowmatrix(): Copying (copied) elements are outside the (row) dimension of the copying vector x2_dv (the copied matrix x1_dm)"); +} +#else + Haven't got time to code up the default using Linux BLAS. +#endif + + +void CopySubvector2matrix_sub(TSdmatrix *x1_dm, const int br, const int bc, const int nrs, const int ncs, TSdvector *x2_dv, const int ptrloc2) { + //Ouputs: Unlike CopySubvector2matrix, _sub means a submatrix, NOT just one column, of the copied matrix x1_dm. + // The copyed submatrix must start at (br, bc) ane end at (br+nrs-1, bc+ncs-1). + // x1_dm: The copyed submatrix of x2_dm->M. + + //Inputs: + // x2_dv: whose elements from x2_dv->v+ptrloc2 to x2_dv->v+ptrloc2+nrs*ncs-1 are copied to the submatrix of of x1_dm->m. + // ptrloc2: inclusive pointer location for x2_dv->v where the copy begins. + // br: beginning of the row (*must* be 0 based) for x1_dm, inclusive. + // bc: beginning of the column (*must* be 0 based) for x1_dm, inclusive. + // nrs: number of rows to be copied. + // ncs: number of colums to be copied. + int nrows, ncols, _j, loc2; + double *v, *M; + + if ( !x1_dm || !x2_dv ) fn_DisplayError(".../mathlib.c/CopySubvector2matrix_sub(): All input pointers must be created (memory-allocated)"); + else if ( !x2_dv->flag ) fn_DisplayError(".../mathlib.c/CopySubvector2matrix_sub(): R input vector must be given values"); + else { + v = x2_dv->v; + M = x1_dm->M; + nrows = x1_dm->nrows; + ncols = x1_dm->ncols; + } + + if ( (bc+ncs)<=ncols && (br+nrs)<=nrows && (ncs*nrs)<=(x2_dv->n-ptrloc2) ) { + loc2 = ptrloc2; + for (_j=0; _j<ncs; _j++) { + memcpy(M+mos(br, bc+_j, nrows), v+loc2, nrs*sizeof(double)); //mos(br, bc+_j, nrows): Points to the top of the column in the submatrix of x2_dm. + loc2 += nrs; //Must be after memcpy(). + } + x1_dm->flag = M_GE; + } + else fn_DisplayError(".../mathlib.c/CopySubvector2matrix_sub(): the submatrix of x1_dm must be within the ranges of both x1_dm and x2_dv"); +} + +void CopySubvector2matrix_unr(TSdmatrix *x1_dm, const int br, const int bc, const TSdvector *x2_dv, const int ptrloc2, const int nels) { + //Ouputs: _unr means that there is no such a restriction that only the ``bc''th column to be copied in the matrix. Copied + // elements can affect several columns of the matrix other than the ``bc'' column, but one must be aware + // that the bc+1 column may start before the specified br. Thus, this function can be used as the Matlab reshape function. + // Copied elements (x1_dm->M+ptrloc1 to x1_dv->M+ptrloc1+nels-1) from x2_dv->v. + // Always sets x1_dm->flag = M_GE after the call to this function. + //Inputs: + // Copying elements from x2_dv->v+ptrloc2 to x2_dv->v+ptrloc2+nels-1 (to x1_dm->M). + // nels: number of elements to be copied. + // br: beginning of the row (*must* be 0 based) for x2_dm, inclusive. + // bc: beginning of the column (*must* be 0 based) for x2_dm, inclusive. + // ptrloc2: pointer location for x2_dv->v where the copy begins, inclusive. + int ptrloc1, nrows, ncols; + + if ( !x1_dm || !x2_dv ) fn_DisplayError(".../mathlib.c/CopySubvector2matrix_unr(): All input pointers must be created (memory-allocated)"); + else if (!x2_dv->flag) fn_DisplayError(".../mathlib.c/CopySubvector2matrix_unr(): R input vector must be given values"); + else { + nrows = x1_dm->nrows; + ncols = x1_dm->ncols; + ptrloc1 = mos(br, bc, x1_dm->nrows); //ptrloc1: pointer location for x1_dm->M where the copy begins. + } + + + if ( (ptrloc2+nels)<=x2_dv->n && (ptrloc1+nels)<=(nrows*ncols) ) { + memcpy(x1_dm->M+ptrloc1, x2_dv->v+ptrloc2, nels*sizeof(double)); + x1_dm->flag = M_GE; //Always reset to a general matrix because it will almost surely break, say, the original symmetry of the matrix x1_dm if x1_dm->flag exists in the first place. + //-------if (!x1_dm->flag) x1_dm->flag = M_GE; //Set to a general matrix if this matrix is not set yet. + } + else fn_DisplayError(".../mathlib.c/CopySubvector2matrix_unr(): Copying (copied) elements are outside the dimension of the copying vector x2_dv (the copied matrix x1_dm)"); +} + +void TransposeSquare(TSdmatrix *B_dm, TSdmatrix *A_dm) { + //???????? Some options are NOT test yet. 5/27/03. ??????????? + // Transposes the n-by-n matrix A_dm to the n-by-n matrix B_dm. + // If A_dm = B_dm, B_dm will be replaced by transposed values. + // + //Outputs: + // B_dm: n-by-n matrix (memory already allocated outside this function). + //Inputs: + // A_dm: n-by-n matrix to be transposed. + int _i, _j, _n, Aflag; + double *A, *B, tmpd; + + //=== Checking dimensions and memory allocation. + if ( !B_dm || !A_dm ) fn_DisplayError(".../mathlib.c/TransposeSquare(): Input matrices must be created (memory-allocated)"); + if ( ((_n=A_dm->nrows) != B_dm->ncols) || (_n != B_dm->nrows) || (_n != A_dm->ncols) ) + fn_DisplayError(".../mathlib.c/TransposeSquare(): Both input matrices must be square"); + //This is too tough by killing the program. if ( ((Aflag=A_dm->flag) & M_SU) && (Aflag & M_SL) ) fn_DisplayError(".../mathlib.c/TransposeSquare(): Matrix is already both SU and SL, so there is no need to transpose. Check a possible bug in your program"); + //The above checking is very important even though it takes about 4 clock cycles, because + // (1) one may make a mistake to mis-use this matrix over and over again; + // (2) if there is no mistake, then no need to transpose this matrix. + if ( ((Aflag=A_dm->flag) & M_SU) && (Aflag & M_SL) ) + { + #if defined (USE_DEBUG_FILE) + fprintf(FPTR_DEBUG, "\nWARNING: .../mathlib.c/TransposeSquare(): the matrix is already both SU and SL, so there is no need to transpose.\n"); + fflush(FPTR_DEBUG); + #else + fprintf(stdout, "\nWARNING: .../mathlib.c/TransposeSquare(): the matrix is already both SU and SL, so there is no need to transpose.\n"); + fflush(stdout); + #endif + + if ( (A=A_dm->M) != (B=B_dm->M) ) + { + CopyMatrix0(B_dm, A_dm); + return; + } + else return; + } + + + + //=== Transposing the square matrix A_dm. + if ( (A=A_dm->M) != (B=B_dm->M) ) { + if (Aflag & M_GE) { + for (_j=0; _j<_n; _j++) + for (_i=_j+1; _i<_n; _i++) { + //Off-diagonal elements. + B[_i*_n+_j] = A[_j*_n+_i]; + B[_j*_n+_i] = A[_i*_n+_j]; + } + for (_i=square(_n)-1; _i>=0; _i -= _n+1) B[_i] = A[_i]; //Diagonal elements. + switch (Aflag) { + case (M_GE | M_UT): + B_dm->flag = M_GE | M_LT; + break; + case (M_GE | M_LT): + B_dm->flag = M_GE | M_UT; + break; + default: + B_dm->flag = M_GE; + } + } + else if (Aflag & M_SU) { + for (_j=0; _j<_n; _j++) + for (_i=_j+1; _i<_n; _i++) + B[mos(_i, _j, _n)] = A[mos(_j, _i, _n)]; //Off-diagonal elements. + for (_i=square(_n)-1; _i>=0; _i -= _n+1) + B[_i] = A[_i]; //Diagonal elements. + B_dm->flag = M_SL; + } + else if (Aflag & M_SL) { + for (_j=0; _j<_n; _j++) + for (_i=_j+1; _i<_n; _i++) + B[mos(_j, _i, _n)] = A[mos(_i, _j, _n)]; //Off-diagonal elements. + for (_i=square(_n)-1; _i>=0; _i -= _n+1) + B[_i] = A[_i]; //Diagonal elements. + B_dm->flag = M_SU; + } + else if (Aflag & M_UT) { + for (_j=0; _j<_n; _j++) + for (_i=_j+1; _i<_n; _i++) + B[mos(_i, _j, _n)] = A[mos(_j, _i, _n)]; //Off-diagonal elements. + for (_i=square(_n)-1; _i>=0; _i -= _n+1) + B[_i] = A[_i]; //Diagonal elements. + B_dm->flag = M_LT; + } + else if (Aflag & M_LT) { + for (_j=0; _j<_n; _j++) + for (_i=_j+1; _i<_n; _i++) + B[mos(_j, _i, _n)] = A[mos(_i, _j, _n)]; //Off-diagonal elements. + for (_i=square(_n)-1; _i>=0; _i -= _n+1) + B[_i] = A[_i]; //Diagonal elements. + B_dm->flag = M_UT; + } + } + else { + // ????? NOT tested yet. 5/27/03. ???????????? + if ( (Aflag & M_GE) && (Aflag & M_UT) ) { + for (_j=0; _j<_n; _j++) + for (_i=_j+1; _i<_n; _i++) { + //Off-diagonal elements. + A[mos(_i, _j, _n)] = A[mos(_j, _i, _n)]; + A[mos(_j, _i, _n)] = 0.0; + } + A_dm->flag = M_GE | M_LT; + } + else if ( (Aflag & M_GE) && (Aflag & M_LT) ) { + for (_j=0; _j<_n; _j++) + for (_i=_j+1; _i<_n; _i++) { + //Off-diagonal elements. + A[mos(_j, _i, _n)] = A[mos(_i, _j, _n)]; + A[mos(_i, _j, _n)] = 0.0; + } + A_dm->flag = M_GE | M_UT; + } + else if (Aflag & M_GE) { + //Tested. Fine. 10 Oct. 03. + for (_j=0; _j<_n; _j++) + for (_i=_j+1; _i<_n; _i++) + swap(A[mos(_i,_j,_n)], A[mos(_j,_i,_n)], tmpd); //Off-diagonal elements. + A_dm->flag = M_GE; + } + else if (Aflag & M_SU) { + for (_j=0; _j<_n; _j++) + for (_i=_j+1; _i<_n; _i++) + A[mos(_i, _j, _n)] = A[mos(_j, _i, _n)]; //Off-diagonal elements. + A_dm->flag = M_GE | M_SU | M_SL; + } + else if (Aflag & M_SL) { + for (_j=0; _j<_n; _j++) + for (_i=_j+1; _i<_n; _i++) + A[mos(_j, _i, _n)] = A[mos(_i, _j, _n)]; //Off-diagonal elements. + A_dm->flag = M_GE | M_SU | M_SL; + } + else if (Aflag & M_UT) { + for (_j=0; _j<_n; _j++) + for (_i=_j+1; _i<_n; _i++) + A[mos(_i, _j, _n)] = A[mos(_j, _i, _n)]; //Off-diagonal elements. + A_dm->flag = M_LT; + } + else if (Aflag & M_LT) { + for (_j=0; _j<_n; _j++) + for (_i=_j+1; _i<_n; _i++) + A[mos(_j, _i, _n)] = A[mos(_i, _j, _n)]; //Off-diagonal elements. + A_dm->flag = M_UT; + } + else fn_DisplayError(".../mathlib.c/TransposeSquare(): Input matrix is not M_GE, M_SU, M_SL, M_UT, or M_LT. Check the matrix to see why transpose is still required"); + } + + + /** OLD code, which has some errors, I belive. 5/28/03. + //=== Transposing the square matrix A_dm. + if ( (A=A_dm->M) != (B=B_dm->M) ) { + for (_j=0; _j<_n; _j++) + for (_i=_j+1; _i<_n; _i++) { + //Off-diagonal elements. + B[_i*_n+_j] = A[_j*_n+_i]; + B[_j*_n+_i] = A[_i*_n+_j]; + } + for (_i=square(_n)-1; _i>=0; _i -= _n+1) + B[_i] = A[_i]; //Diagonal elements. + + switch (A_dm->flag) { + case (M_GE | M_UT): + B_dm->flag = M_GE | M_LT; + break; + case (M_GE | M_LT): + B_dm->flag = M_GE | M_UT; + break; + case M_GE: + B_dm->flag = M_GE; + break; + default: + fn_DisplayError(".../mathlib.c/TransposeSquare(): (1) If the R input matrix is symmetric, no transpose is needed. (2) If triangular, it may be unnecessary so that no code is written for a triangular case"); + } + } + else { + // ????? NOT tested yet. 2/27/03. ???????????? + for (_j=0; _j<_n; _j++) + for (_i=_j+1; _i<_n; _i++) { + //Off-diagonal elements. + tmpd = A[_j*_n+_i]; + A[_j*_n+_i] = A[_i*_n+_j]; + A[_i*_n+_j] = tmpd; + } + + switch (A_dm->flag) { + case (M_GE | M_UT): + B_dm->flag = M_GE | M_LT; + break; + case (M_GE | M_LT): + B_dm->flag = M_GE | M_UT; + break; + case M_GE: + B_dm->flag = M_GE; + break; + default: + fn_DisplayError(".../mathlib.c/TransposeSquare(): (1) If the R input matrix is symmetric, no transpose is needed. (2) If triangular, it may be unnecessary so that no code is written for a triangular case"); + } + } + /**/ +} + +void TransposeRegular(TSdmatrix *B_dm, const TSdmatrix *A_dm) { + // Transposes the m-by-n matrix A_dm to the n-by-m matrix B_dm. + // + //Outputs: + // B_dm: n-by-m general matrix (memory already allocated outside this function). + //Inputs: + // A_dm: m-by-n general matrix to be transposed. + int _i, _j, _m, _n; + double *A, *B; + + + //=== Checking dimensions and memory allocation. + if ( !B_dm || !A_dm ) fn_DisplayError(".../mathlib.c/TransposeRegular(): Input matrices must be created (memory-allocated)"); + else if ( !(A_dm->flag & M_GE) ) fn_DisplayError(".../mathlib.c/TransposeRegular(): (1) Input matrix A_dm must be given values. (2) A_dm must be a general (M_GE) matrix"); + else { + _m = A_dm->nrows; + _n = A_dm->ncols; + A = A_dm->M; + B = B_dm->M; + } + if ( (_m != B_dm->ncols) || (_n != B_dm->nrows) ) fn_DisplayError(".../mathlib.c/TransposeRegular(): Dimension of B_dm must be compatible with those of tranposed A_dm"); + + + //=== Transposing the regular matrix A_dm + if (_m<_n) { + for (_j=0; _j<_m; _j++) + for (_i=_j+1; _i<_m; _i++) { + //Off-diagonal elements in the square part. + B[mos(_j, _i, _n)] = A[mos(_i, _j, _m)]; + B[mos(_i, _j, _n)] = A[mos(_j, _i, _m)]; + } + + for (_i=_m-1; _i>=0; _i--) + B[mos(_i,_i,_n)] = A[mos(_i, _i, _m)]; //Diagonal elements. + + for (_j=_m; _j<_n; _j++) + for (_i=0; _i<_m; _i++) + B[_i*_n+_j] = A[_j*_m+_i]; //Off-diagonal elements in the trapozoidal part. + + B_dm->flag = M_GE; + } + else { + for (_j=0; _j<_n; _j++) + for (_i=_j+1; _i<_n; _i++) { + //Off-diagonal elements in the square part. + B[_i*_n+_j] = A[_j*_m+_i]; + B[_j*_n+_i] = A[_i*_m+_j]; + } + + for (_i=0; _i<_n; _i++) + B[mos(_i,_i,_n)] = A[mos(_i,_i,_m)]; //Diagonal elements. + + for (_i=_n; _i<_m; _i++) + for (_j=0; _j<_n; _j++) + B[_i*_n+_j] = A[_j*_m+_i]; //Off-diagonal elements in the trapozoidal part. + + B_dm->flag = M_GE; + } +} +//--- +TSdmatrix *tz_TransposeRegular(TSdmatrix *B_dm, const TSdmatrix *A_dm) +{ + // Transposes the m-by-n matrix A_dm to the n-by-m matrix B_dm. + // + //Outputs: + // If B_dm==NULL, B_dm (n-by-m general matrix) is created (memory allocated) and returned (thus, the memory must be destroyed outside this function). + // If B_dm!=NULL, B_dm (n-by-m general matrix)'s memory has already been allocated outside this function and the same B_dm will be returned. + //Inputs: + // A_dm: m-by-n general matrix to be transposed. + int _i, _j, _m, _n; + double *A, *B; + + + //=== Checking dimensions and memory allocation. + if (!A_dm) fn_DisplayError(".../mathlib.c/TransposeRegular(): Input matrix A_dm must be created (memory-allocated)"); + if ( !(A_dm->flag & M_GE) ) fn_DisplayError(".../mathlib.c/TransposeRegular(): (1) Input matrix A_dm must be given values. (2) A_dm must be a general (M_GE) matrix"); + _m = A_dm->nrows; + _n = A_dm->ncols; + A = A_dm->M; + // + if (!B_dm) B_dm = CreateMatrix_lf(_n, _m); + else + if ( (_m != B_dm->ncols) || (_n != B_dm->nrows) ) fn_DisplayError(".../mathlib.c/TransposeRegular(): Dimension of B_dm must be compatible with those of tranposed A_dm"); + B = B_dm->M; + + //=== Transposing the regular matrix A_dm + if (_m<_n) { + for (_j=0; _j<_m; _j++) + for (_i=_j+1; _i<_m; _i++) { + //Off-diagonal elements in the square part. + B[mos(_j, _i, _n)] = A[mos(_i, _j, _m)]; + B[mos(_i, _j, _n)] = A[mos(_j, _i, _m)]; + } + + for (_i=_m-1; _i>=0; _i--) + B[mos(_i,_i,_n)] = A[mos(_i, _i, _m)]; //Diagonal elements. + + for (_j=_m; _j<_n; _j++) + for (_i=0; _i<_m; _i++) + B[_i*_n+_j] = A[_j*_m+_i]; //Off-diagonal elements in the trapozoidal part. + + B_dm->flag = M_GE; + } + else { + for (_j=0; _j<_n; _j++) + for (_i=_j+1; _i<_n; _i++) { + //Off-diagonal elements in the square part. + B[_i*_n+_j] = A[_j*_m+_i]; + B[_j*_n+_i] = A[_i*_m+_j]; + } + + for (_i=0; _i<_n; _i++) + B[mos(_i,_i,_n)] = A[mos(_i,_i,_m)]; //Diagonal elements. + + for (_i=_n; _i<_m; _i++) + for (_j=0; _j<_n; _j++) + B[_i*_n+_j] = A[_j*_m+_i]; //Off-diagonal elements in the trapozoidal part. + + B_dm->flag = M_GE; + } + + return (B_dm); +} + + +void SUtoGE(TSdmatrix *x_dm) { + //Output: x_dm (nrows<=ncols) becomes a general matrix in addition to being upper symmetric. + //Input: x_dm (nrows<=ncols) is upper symmetric. + // We do not check if x_dm is upper symmetric because we assume the calling function checks this before this function is called. + int nrows, ncols, _i, _j; + if (!x_dm) fn_DisplayError(".../mathlib.c/SUtoGE(): Input upper symmetric matrix must be created (memory-allocated)"); + else if ( !(x_dm->flag & M_SU) ) fn_DisplayError(".../mathlib.c/SUtoGE(): Input matrix must be (1) upper symmetric and (2) given legal values"); + else if ( (nrows=x_dm->nrows) != (ncols=x_dm->ncols) ) fn_DisplayError(".../mathlib.c/SUtoGE(): Upper symmetric matrix must be square."); + else { + for (_j=0; _j<nrows; _j++) + for (_i=_j+1; _i<nrows; _i++) + x_dm->M[mos(_i, _j, nrows)] = x_dm->M[mos(_j, _i, nrows)]; //Off-diagonal elements in the square part. + x_dm->flag = M_GE | M_SL | M_SU; + } +} + +void SLtoGE(TSdmatrix *x_dm) { + //Output: x_dm becomes a general square matrix in addition to being lower symmetric. + //Input: x_dm is lower symmetric. + // We do not check if x_dm is upper symmetric because we assume the calling function checks this before this function is called. + int nrows, ncols, _i, _j; + if (!x_dm) fn_DisplayError(".../mathlib.c/SLtoGE(): Input lower symmetric matrix must be created (memory-allocated)"); + else if ( !(x_dm->flag & M_SL) ) fn_DisplayError(".../mathlib.c/SLtoGE(): Input matrix must be (1) lower symmetric and (2) given legal values"); + else if ( (nrows=x_dm->nrows) != (ncols=x_dm->ncols) ) fn_DisplayError(".../mathlib.c/SLtoGE(): The lower symmetric matrix must be sqaure"); + else { + for (_j=0; _j<nrows; _j++) + for (_i=_j+1; _i<nrows; _i++) + x_dm->M[mos(_j, _i, nrows)] = x_dm->M[mos(_i, _j, nrows)]; //Off-diagonal elements in the square part. + x_dm->flag = M_GE | M_SU | M_SL; + } +} + +double SumVector(TSdvector *x_dv) { + int _i; + double sum = 0.0, //Cumulative. + *v; + //double *ptrcnt, *endptr; + + //=== This option may not speed up. + // if ( !x_dv ) fn_DisplayError(".../mathlib.c/SumVector(): Input vector must be created (memory-allocated)"); + // else endptr = (ptrcnt = x_dv->v) + x_dv->n; + // for ( ; ptrcnt<endptr; ptrcnt++ ) sum += *ptrcnt; + + if ( !x_dv || !x_dv->flag ) fn_DisplayError(".../mathlib.c/SumVector(): input vector must be (a) created (memory-allocated) and (b) assigned legal values"); + for (_i=x_dv->n-1, v=x_dv->v; _i>=0; _i--) sum += v[_i]; + + return( sum ); +} + +//double SumVector(TSdvector *x_dv) { +// int _i, _n; +// double sum; +// double *v; + +// if ( !x_dv ) fn_DisplayError(".../mathlib.c/SumVector(): Input vector must be created (memory-allocated)"); +// else { +// v = x_dv->v; +// _n = x_dv->n; +// } + +// sum = v[0]; +// for ( _i=1; _i<_n; _i++ ) sum += v[_i]; +// return( sum ); +//} + + +double MinVector(TSdvector *x_dv) +{ + //Input: no change for x_dv in this function. + int _i, n; + double minvalue; + double *v; + + if (!x_dv || !x_dv->flag) fn_DisplayError(".../cstz.c/MinVector_lf(): Input vector x_dv must be (1) allocated memory and (2) assigned legal values"); + n = x_dv->n; + v = x_dv->v; + + minvalue = v[0]; + for (_i=n-1; _i>0; _i--) + if (v[_i]<minvalue) minvalue = v[_i]; + + return( minvalue ); +} + +double MaxVector(TSdvector *x_dv) +{ + //Input: no change for x_dv in this function. + int _i, n; + double maxvalue; + double *v; + + if (!x_dv || !x_dv->flag) fn_DisplayError(".../cstz.c/MaxVector_lf(): Input vector x_dv must be (1) allocated memory and (2) assigned legal values"); + n = x_dv->n; + v = x_dv->v; + + maxvalue = v[0]; + for (_i=n-1; _i>0; _i--) + if (v[_i]>maxvalue) maxvalue = v[_i]; + + return( maxvalue ); +} + +int MaxVector_int(TSivector *x_iv) +{ + //Input: no change for x_iv in this function. + int _i; + int maxvalue; + int *v; + + if (!x_iv || !x_iv->flag) fn_DisplayError(".../cstz.c/MaxVector_int(): Input vector x_iv must be (1) allocated memory and (2) assigned legal values"); + v = x_iv->v; + + maxvalue = v[0]; + for (_i=x_iv->n-1; _i>0; _i--) + if (v[_i]>maxvalue) maxvalue = v[_i]; + + return( maxvalue ); +} + + +void SumMatrix(TSdvector *x_dv, const TSdmatrix *X_dm, const char rc) +{ + //Outputs: + // x_dv: if rc=='R' or 'r', x_dv = sum of X_dm across rows; else or if rc=='C' or 'c', x_dv = sum of X_dm across columns. + int _i, _n, _k, nrows, ncols, last; + double sum; + double *v, *M; + + + if ( !x_dv || !X_dm || !X_dm->flag ) fn_DisplayError(".../mathlib.c/SumMatrix(): (a) output vector must be created (memory-allocated) and (b) input matrix must be created and assigned legal values"); + + + if (rc=='R' || rc=='r') { + if ((_n=x_dv->n) != X_dm->ncols) fn_DisplayError(".../mathlib.c/SumMatrix(): length of the output vector must match the number of columns of the input matrix when summing it across rows"); + v = x_dv->v; + M = X_dm->M; + for (_i=_n-1; _i>=0; _i--) { + sum = 0.0; + last = (_i+1)*(nrows=X_dm->nrows); + for (_k=_i*nrows; _k<last; _k++) sum +=M[_k]; + v[_i] = sum; + } + } + else { + if ((_n=x_dv->n) != X_dm->nrows) fn_DisplayError(".../mathlib.c/SumMatrix(): length of the output vector must match the number of rows of the input matrix when summing it across columns"); + v = x_dv->v; + M = X_dm->M; + for (_i=_n-1; _i>=0; _i--) { + sum = 0.0; + last = _i + ((ncols=X_dm->ncols)-1)*_n; + for (_k=_i; _k<=last; _k += _n) sum +=M[_k]; //Must _k<=, NOT, _k<. + v[_i] = sum; + } + } + + x_dv->flag = V_DEF; +} + + +void diagdv(TSdvector *x_dv, TSdmatrix *x_dm) +{ + //Extract the diagonal elements of x_dm to a vector. + // + //Outputs: + // x_dv: nrows-by-1 vector. + //Inputs: + // x_dm: nrows-by-ncols matrix. + int _i, _n; + double *v, *M; + + + //=== Checking dimensions and memory allocation. + if ( !x_dv || !x_dm ) fn_DisplayError(".../mathlib.c/diagdv(): Both the input vector and output matrix must be created (memory-allocated)"); + else { + if (x_dm->nrows < x_dm->ncols) _n = x_dm->nrows; + else _n = x_dm->ncols; + v = x_dv->v; + M = x_dm->M; + } + if ( _n != x_dv->n ) fn_DisplayError(".../mathlib.c/diagdv(): Dimensions of input vector and matrix must match"); + + + for (_i=0; _i<_n; _i++) v[_i] = M[mos(_i,_i,_n)]; + x_dv->flag = V_DEF; +} +//--- +TSdmatrix *tz_DiagMatrix(TSdmatrix *X_dm, TSdvector *x_dv) +{ + //Converts a vector to a diagonal matrix with the diagonal elements being the input vector. + // + //Outputs: + // X_dm: _n-by-_n diagonal matrix. + // If X_dm = NULL, then Xout_dm is allocated memory and exported (therefore, its memory will be freed outside this function0. + //Inputs: + // x_dv: _n-by-1 vector. + int _i, _n; + double *v, *M; + TSdmatrix *Xout_dm; + + + //=== Checking dimensions and memory allocation. + if ( !x_dv || !x_dv->flag) fn_DisplayError(".../mathlib.c/tz_DiagMatrix(): the input vector must be (1) created (memory-allocated) and (2) given legal values"); + _n = x_dv->n; + + if (X_dm) + { + if ((_n != X_dm->nrows) || (_n != X_dm->ncols)) fn_DisplayError(".../mathlib.c/tz_DiagMatrix(): (1) the input matrix must be square; (2) dimensions of input vector and matrix must match"); + if (isdiagonalmatrix(X_dm)) Xout_dm = X_dm; + else fn_DisplayError(".../mathlib.c/tz_DiagMatrix(): the input matrix must be diagonal (M_UT | M_LT)"); + } + else Xout_dm = CreateConstantMatrix_lf(_n, _n, 0.0); + + M = Xout_dm->M; + v = x_dv->v; + + for (_i=0; _i<_n; _i++) M[mos(_i,_i,_n)] = v[_i]; + if ( !X_dm ) Xout_dm->flag = (M_GE | M_UT | M_LT); //Diagonal (i.e., both lower and upper triangular). + + return (Xout_dm); +} + + +double tracefabs(TSdmatrix *x_dm) +{ + //Sum of absolute values of the diagonal elements of x_dm. + // + //Outputs: + // y: double value. + //Inputs: + // x_dm: nrows-by-ncols matrix. + int _i, _n; + double traceval=0.0, //Cumulative. + *M; + + + //=== Checking dimensions and memory allocation. + if (!x_dm) fn_DisplayError(".../mathlib.c/tracefabs(): The input matrix must be created (memory-allocated)"); + else { + if (x_dm->nrows < x_dm->ncols) _n = x_dm->nrows; + else _n = x_dm->ncols; + M = x_dm->M; + } + + + for (_i=0; _i<_n; _i++) traceval += fabs(M[mos(_i,_i,_n)]); + return( traceval ); +} +double tracelogfabs(TSdmatrix *x_dm) +{ + //Sum of logs of absolute values of the diagonal elements of the square x_dm or sum(log(diag(abs(x_dm)))). + // + //Outputs: + // y: double value. + //Inputs: + // x_dm: nrows-by-ncols matrix. + int _i, _n; + double traceval=0.0, //Cumulative. + *M; + + //=== Checking dimensions and memory allocation. + if (!x_dm || !x_dm->flag) fn_DisplayError(".../mathlib.c/tracelogfabs(): The input matrix must be (1) created (memory-allocated) and (2) gvein legal values"); + else M = x_dm->M; + if ((_n = x_dm->nrows) != x_dm->ncols) fn_DisplayError(".../mathlib.c/tracelogfabs(): The input matrix must be square"); + for (_i=square(_n)-1; _i>=0; _i -= _n+1) traceval += log(fabs(M[_i])); + +// if (!x_dm) fn_DisplayError(".../mathlib.c/tracelogfabs(): The input matrix must be created (memory-allocated)"); +// else if ( !x_dm->flag ) fn_DisplayError(".../mathlib.c/tracelogfabs(): The input matrix must be given legal values"); +// else { +// if (x_dm->nrows < x_dm->ncols) _n = x_dm->nrows; +// else _n = x_dm->ncols; +// M = x_dm->M; +// } +// for (_i=0; _i<_n; _i++) traceval += log(fabs(M[mos(_i,_i,_n)])); + + return( traceval ); +} +double tracelog(TSdmatrix *x_dm) +{ + //Sum of logs of the diagonal elements of the square x_dm or sum(log(diag(x_dm))). + // + //Outputs: + // y: double value. + //Inputs: + // x_dm: nrows-by-ncols matrix. + int _i, _n; + double traceval=0.0, //Cumulative. + *M; + + //=== Checking dimensions and memory allocation. + if (!x_dm || !x_dm->flag) fn_DisplayError(".../mathlib.c/tracelogfabs(): The input matrix must be (1) created (memory-allocated) and (2) gvein legal values"); + else M = x_dm->M; + if ((_n = x_dm->nrows) != x_dm->ncols) fn_DisplayError(".../mathlib.c/tracelogfabs(): The input matrix must be square"); + for (_i=square(_n)-1; _i>=0; _i -= _n+1) traceval += log(M[_i]); + + return( traceval ); +} +//--- +double sumoflogvector(TSdvector *x_dv) +{ + //Output: sum(log(x_dv)). + int _i; + double sumlog = 0.0; + double *v; + + if ( !x_dv || !x_dv->flag ) fn_DisplayError("mathlib.c/sumoflogvector(): Input vector x_dv must be (1) created and (2) given legal values"); + v = x_dv->v; + for (_i=x_dv->n-1; _i>=0; _i--) sumlog += log(v[_i]); + + return( sumlog ); +} + + +TSdmatrix *tz_kron(TSdmatrix *C_dm, TSdmatrix *A_dm, TSdmatrix *B_dm) +{ + //C = kron(A, B), compatible with Matlab notation. + //Inputs: + // A_dm and B_dm: two real general matrices. + //Outputs: + // If C_dm == NULL, C_dm is created (memory allocated) and returned (thus, the memory must be destroyed outside this function). + // If C_dm != NULL, C_dm's memory has already been allocated outside this function and the same C_dm will be returned. + int _i, _j, ma, na, mb, nb, ki, kj; + TSdmatrix *Wmb_nb_dm = NULL; + + //=== Checking dimensions and memory allocation. + if (!A_dm || !B_dm) fn_DisplayError("mathlib.c/tz_kron(): Input matrices A_dm and B_dm must be created (memory-allocated)"); + if ( !(A_dm->flag & M_GE) || !(B_dm->flag & M_GE)) fn_DisplayError("mathlib.c/tz_kron(): " + " (1) Input matrices A_dm and B_dm must be given values." + " (2) A_dm and B_dm must be general (M_GE) matrices"); + ma = A_dm->nrows; + na = A_dm->ncols; + mb = B_dm->nrows; + nb = B_dm->ncols; + Wmb_nb_dm = CreateMatrix_lf(mb,nb); + // + if (!C_dm) C_dm = CreateZeroMatrix_lf(ma*mb, na*nb); + else + if ( (C_dm->nrows != (ma*mb)) || (C_dm->ncols != (na*nb)) ) + fn_DisplayError("mathlib.c/tz_kron(): Dimension of C_dm must be compatible with those of A_dm and B_dm"); + + for (_i=ma-1; _i>=0; _i--) + for (_j=na-1; _j>=0; _j--) + { + ki = _i*mb; + kj = _j*nb; + ScalarTimesMatrix(Wmb_nb_dm, A_dm->M[mos(_i,_j,ma)], B_dm, 0.0); + CopySubmatrix(C_dm, ki, kj, Wmb_nb_dm, 0, 0, mb, nb); + } + + //=== + DestroyMatrix_lf(Wmb_nb_dm); + + + return (C_dm); +} + + + + + + + +//======================================================= +// Self-written routines. +//======================================================= +void ergodicp(TSdvector *p_dv, TSdmatrix *P_dm) { + // Computes the ergodic probabilities. See Hamilton p.681. + // + //Outputs: + // p_dv: n-by-1 vector filled by ergodic probabilities p. + //------------ + //Inputs: + // P_dm: n-by-n Markovian transition matrix. Elements in each column sum up to 1.0. + + int eigmaxindx, // Index of the column corresponding to the max eigenvalue. + _i, _j, _n, errflag; + double gpisum=0.0, + eigmax, tmpd0; + double *p_v=NULL, + *absval_v=NULL, + *evalr_v=NULL, + *evali_v=NULL, + *revecr_m=NULL, + *reveci_m=NULL, + *levecr_m=NULL, + *leveci_m=NULL; + TSdvector *absvals_dv=NULL; + TSdzvector *vals_dzv=NULL; + TSdzmatrix *rights_dzm=NULL, *lefts_dzm=NULL; + + + if ( !p_dv || !P_dm || (p_dv->n != P_dm->nrows) || (P_dm->nrows != P_dm->ncols) ) fn_DisplayError(".../mathlib.c/ergodicp(): One of the two pointer arguments is not created (memory-allocated) or sizes of two pointer arguments do not match or input matrix P_dm is not square"); + else if ( !P_dm->flag || !(P_dm->flag & M_GE) ) fn_DisplayError(".../mathlib.c/ergodicp(): (1) R square input matrix (P_dm) must be given values. (2) P_dm must be a general (M_GE) matrix"); + else { + _n = p_dv->n; + absvals_dv = CreateVector_lf(_n); + vals_dzv = CreateVector_dz(_n); + rights_dzm = CreateMatrix_dz(_n, _n); + InitializeConstantMatrix_lf(rights_dzm->imag, 0.0); //Imaginary part must be initialized to zero. + } + + + //=== Obtains eigen values and vectors. + //errflag = eigrgen_decomp(evalr_v, evali_v, revecr_m, reveci_m, levecr_m, leveci_m, cp_m, _n); + errflag = eigrgen(vals_dzv, rights_dzm, lefts_dzm, P_dm); + if (errflag<0) fn_DisplayError("/mathlib.c/eigrgen(): some element in input matrix P_dm has an illegal value"); + else if (errflag>0) fn_DisplayError("/mathlib.c/eigrgen(): the QR algorithm failed to compute all the eigenvalues and no eigenvectors have been computed"); + + //=== Utilizes old notations because I have no time to polish this function. + p_v = p_dv->v; + absval_v = absvals_dv->v; + evalr_v = vals_dzv->real->v; + evali_v = vals_dzv->imag->v; + revecr_m = rights_dzm->real->M; + reveci_m = rights_dzm->imag->M; //Imaginary part must be initialized to zero. + + + for (_j=0; _j<_n; _j++) { + if (!(evali_v[_j])) { //No imaginary part (in other words, real solutions). + eigmax = evalr_v[_j]; + eigmaxindx = _j; + break; + } + else { + eigmax = sqrt(square(evalr_v[_j])+square(evali_v[_j])); + eigmaxindx = _j; + break; + } + } + //+ + for (_j++; _j<_n; _j++) { + if (!(evali_v[_j]) && (evalr_v[_j] > eigmax)) { + eigmax = evalr_v[_j]; + eigmaxindx = _j; + } + else if (evali_v[_j]) { + tmpd0 = sqrt(square(evalr_v[_j])+square(evali_v[_j])); + if (tmpd0 > eigmax) { + eigmax = tmpd0; + eigmaxindx = _j; + } + } + } + + if (!(evali_v[eigmaxindx])) { + for (_i=0;_i<_n;_i++) { + absval_v[_i] = fabs(revecr_m[_i+_n*eigmaxindx]); + gpisum += absval_v[_i]; // Sum over the eigmaxindx_th column. + } + tmpd0 = 1.0/gpisum; + for (_i=0;_i<_n;_i++) p_v[_i] = absval_v[_i]*tmpd0; // Normalized eigmaxindx_th column as ergodic probabilities. + } + else { + for (_i=0;_i<_n;_i++) { + absval_v[_i] = sqrt(square(revecr_m[_i+_n*eigmaxindx])+square(reveci_m[_i+_n*eigmaxindx])); + gpisum += absval_v[_i]; // Sum over the eigmaxindx_th column. + } + tmpd0 = 1.0/gpisum; + for (_i=0;_i<_n;_i++) p_v[_i] = absval_v[_i]*tmpd0; // Normalized eigmaxindx_th column as ergodic probabilities. + } + + + p_dv->flag = V_DEF; + //=== Frees up allocated memory belonging to this function. + DestroyVector_lf(absvals_dv); + DestroyVector_dz(vals_dzv); + DestroyMatrix_dz(rights_dzm); +} + + + +double *alloc_ergodp2(const double *cp_m, const int _n) { + // Output: + // p_v: n-by-1 vector of ergodic probabilities p. + //------------ + // cp_m: n-by-n Markovian transition matrix. + // _n: the order of cp_m. + // + // Compute the ergodic probabilities. See Hamilton p.681. + + int eigmaxindx, // Index of the column corresponding to the max eigenvalue. + _i, _j, errflag; + double gpisum=0.0, + eigmax, tmpd0; + double *p_v=NULL, //@@Will be freed outside this function.@@ D: n-by-1. Erogodic probabilties. + *absval_v=NULL, + *evalr_v=NULL, + *evali_v=NULL, + *revecr_m=NULL, + *reveci_m=NULL, + *levecr_m=NULL, + *leveci_m=NULL; + + //=== Allocates memory. + p_v = tzMalloc(_n, double); + absval_v = tzMalloc(_n, double); + evalr_v = tzMalloc(_n, double); + evali_v = tzCalloc(_n, double); //Imaginary part must be initialized to zero. + revecr_m = tzMalloc(square(_n), double); + reveci_m = tzCalloc(square(_n), double); //Imaginary part must be initialized to zero. + + //=== Obtains eigen values and vectors. + errflag = eigrgen_decomp(evalr_v, evali_v, revecr_m, reveci_m, levecr_m, leveci_m, cp_m, _n); + if (errflag<0) fn_DisplayError("/mathlib.c/eigrgen_decomp(): some element in input matrix has an illegal value"); + else if (errflag>0) fn_DisplayError("/mathlib.c/eigrgen_decomp(): the QR algorithm failed to compute all the eigenvalues and no eigenvectors have been computed"); + + for (_j=0; _j<_n; _j++) { + if (!(evali_v[_j])) { //No imaginary part (in other words, real solutions). + eigmax = evalr_v[_j]; + eigmaxindx = _j; + break; + } + else { + eigmax = sqrt(square(evalr_v[_j])+square(evali_v[_j])); + eigmaxindx = _j; + break; + } + } + //+ + for (_j++; _j<_n; _j++) { + if (!(evali_v[_j]) && (evalr_v[_j] > eigmax)) { + eigmax = evalr_v[_j]; + eigmaxindx = _j; + break; + } + else if (evali_v[_j]) { + tmpd0 = sqrt(square(evalr_v[_j])+square(evali_v[_j])); + if (tmpd0 > eigmax) { + eigmax = tmpd0; + eigmaxindx = _j; + break; + } + } + } + + if (!(evali_v[eigmaxindx])) { + for (_i=0;_i<_n;_i++) { + absval_v[_i] = fabs(revecr_m[_i+_n*eigmaxindx]); + gpisum += absval_v[_i]; // Sum over the eigmaxindx_th column. + } + tmpd0 = 1.0/gpisum; + for (_i=0;_i<_n;_i++) p_v[_i] = absval_v[_i]*tmpd0; // Normalized eigmaxindx_th column as ergodic probabilities. + } + else { + for (_i=0;_i<_n;_i++) { + absval_v[_i] = sqrt(square(revecr_m[_i+_n*eigmaxindx])+square(reveci_m[_i+_n*eigmaxindx])); + gpisum += absval_v[_i]; // Sum over the eigmaxindx_th column. + } + tmpd0 = 1.0/gpisum; + for (_i=0;_i<_n;_i++) p_v[_i] = absval_v[_i]*tmpd0; // Normalized eigmaxindx_th column as ergodic probabilities. + } + + + //=== Frees up allocated memory. + if (absval_v) free(absval_v); + if (evalr_v) free(evalr_v); + if (evali_v) free(evali_v); + if (revecr_m) free(revecr_m); + if (reveci_m) free(reveci_m); + if (levecr_m) free(levecr_m); + if (leveci_m) free(leveci_m); + + return (p_v); +} + + + + +/** +void eig_rgen_all(double *eval_v, double *evec_m, const double *x_m, const int _n) { + // Outputs (dependent on MATLAB C math library): NEED to be fixed about eval_v or mxval_d, which may be *complex*. 10/13/02 + // eval_v: n-by-1 eigenvalues; + // evec_m: n-by-n corresponding eigenvectors column by column. + //------------ + // Inputs: + // x_m: _n-by_n real general (non-symmetric) matrix. + // + // Eigenanalysis of real general (non-symmetric) square matrix with all eigenvalues and eigenvectors. + + #ifdef MATLABCMATHLIBRARY //Matlab dependent code. + mxArray *mxval_d=NULL, *mxvec_m=NULL, // @@Must be freed in this function.@@ m: n-by-n eigvector matrix; d: n-by-n eigvalue diagonal. + *mx_m=NULL; // @@Must be freed in this function.@@ + double *mxval_d_p; // _p: pointer to the corresponding mxArray whose name occurs before _p. + int ki; + + + mx_m = mlfDoubleMatrix(_n, _n, x_m, NULL); + mxvec_m = mlfEig(&mxval_d, mx_m, NULL, NULL); + + memcpy(evec_m, mxGetPr(mxvec_m), square(_n)*sizeof(double)); + //+ + mxval_d_p = mxGetPr(mxval_d); + for (ki=0; ki<_n; ki++) eval_v[ki] = mxval_d_p[_n*ki+ki]; // Note that n*ki+ki refers to a diagonal location in the n-by-n matrix. + + //=== Frees up allocated mxArray. + mxDestroyArray(mxval_d); + mxDestroyArray(mxvec_m); + mxDestroyArray(mx_m); + #endif +} + + +double *fn_ergodp2(const double *cp_m, const int _n) { + // Output: + // p_v: n-by-1 vector of ergodic probabilities p. + //------------ + // cp_m: n-by-n Markovian transition matrix. + // _n: the order of cp_m. + // + // Compute the ergodic probabilities. See Hamilton p.681. + + int eigmaxindx, // Index of the column corresponding to the max eigenvalue. + ki; + double gpisum=0.0, + eigmax, tmpd0, + *p_v, // @@Will be freed outside this function.@@ D: n-by-1. Erogodic probabilties. + *eval_v, *evec_m; // @@Must be freed in this function.@@ D: n-by-1 and n-by-n. Eigenvalues and eigenvectors. + + //=== Allocates memory. + p_v = tzMalloc(_n, double); + eval_v = tzMalloc(_n, double); + evec_m = tzMalloc(square(_n), double); + + + eig_rgen_all(eval_v, evec_m, cp_m, _n); + eigmax = *eval_v; + eigmaxindx = 0; + if (_n>1) { + for (ki=1;ki<_n;ki++) { + if (eval_v[ki] > eigmax) { + eigmax=eval_v[ki]; + eigmaxindx=ki; + } // Note that n*ki+ki refers to a diagonal location in the n-by-n matrix. + } + } + for (ki=0;ki<_n;ki++) gpisum += evec_m[_n*eigmaxindx+ki]; // Sum over the eigmaxindx_th column. + tmpd0 = 1.0/gpisum; + for (ki=0;ki<_n;ki++) p_v[ki] = evec_m[_n*eigmaxindx+ki]*tmpd0; // Normalized eigmaxindx_th column as ergodic probabilities. + + //=== Frees up allocated memory. + free(eval_v); + free(evec_m); + + + return p_v; +} +/**/ + + +/** //Iskander's code. +int eiggen(double *a, int n, double *dr, double *di, double *vr, double *vi) { + unsigned char msg[101]; + int lwork = -1, info = 0; + double *work, work1; + char *jobvr = vr?"V":"N"; + register int i, j; + + // Query dsyev on the value of lwork + dgeev("N",jobvr,&n,a,&n,dr,di,NULL,&n,vr,&n,&work1,&lwork,&info); + + if (info < 0) { + sprintf(msg, "Input %d to dgeev had an illegal value",-info); + mexWarnMsgTxt(msg); + return(info); + } + + lwork = (int)(work1); + work = mxCalloc(lwork,sizeof(double)); + dgeev("N",jobvr,&n,a,&n,dr,di,NULL,&n,vr,&n,work,&lwork,&info); + mxFree(work); + + if (info < 0) { + sprintf(msg, "Input %d to dgeev had an illegal value",-info); + mexWarnMsgTxt(msg); + return(info); + } + + for (i=0; i<n-1; i++) + if (di[i] && (di[i]==-di[i+1])) + for (j=0; j<n; j++) { + vi[(i+1)*n+j] = -(vi[i*n+j]=vr[(i+1)*n+j]); + vr[(i+1)*n+j] = vr[i*n+j]; + } + + if (info > 0) { + sprintf(msg,"The QR algorithm failed to compute all the eigenvalues,\n" + "and no eigenvectors have been computed, but elements D(%d:N) contain\n" + "those eigenvalues which have converged.",info+1); + mexWarnMsgTxt(msg); + return(info); + } + + return(info); +} +/**/ + + +/** SAVE (Dan's code). Transpose the square matrix. +for (_i=0: _i<_n; _i++) + for (_j=i+1; _j<_n; _j++) { + tmp=A[_i+_j*_n]; + A[i+j*n]=A[j+i*n]; + A[j+i*n] = tmp; + } +/**/ + +/** SAVE (Dan's code). Transpose the regular matrix. +memcpy(tmp, A, ....); +for (_i=0: _i<_n; _i++) + for (_j=i+1; _j<m; _j++) { + A[i+j*..] = tmp[j+i*..]; + } +/**/ + + + + +/** +void VectorTimesSelf(TSdmatrix *C_dm, const TSdvector *a_dv, const double _alpha, const double _beta, const char ul) { + //No Lapack -- my own function. + //Output is C and all other arguments are inputs. + //Computes C = alpah*a*a' + beta*C where + // a is m-by-1, + // C is m-by-m symmetric matrix, + // alpha: a double scalar, + // beta: a double scalar, + // ul: if == 'u' or 'U', elements in C are stored only in the upper part; otherwise, C is stored only in the lower part. + int _i, _j, _m, _n; + double *v, *M; + + if ( !C_dm || !a_dv ) fn_DisplayError(".../mathlib.c/VectorTimesSelf(): At least one of the pointer arguments is not created (memory-allocated)"); + else { + v = a_dv->v; + M = C_dm->M; + _m = C_dm->nrows; + _n = C_dm->ncols; + } + + if ( (_m != a_dv->n) || (_m != _n) ) fn_DisplayError(".../mathlib.c/VectorTimesSelf(): (1) Input matrix must square and (2) its size must match the dimension of the input vector"); + else { + if ( (ul == 'u') || (ul == 'U') ) { + if ( _alpha==1.0 ) { + if ( _beta==1.0 ) { + for ( _j=0; _j<_m; _j++ ) { + for ( _i=0; _i<=_j; _i++ ) { + M[mos(_i, _j, _m)] += v[_i] * v[_j]; + } + } + } + else if ( _beta==0.0 ) { + for ( _j=0; _j<_m; _j++ ) { + for ( _i=0; _i<=_j; _i++ ) { + M[mos(_i, _j, _m)] = v[_i] * v[_j]; + } + } + } + else { + for ( _j=0; _j<_m; _j++ ) { + for ( _i=0; _i<=_j; _i++ ) { + M[mos(_i, _j, _m)] = v[_i] * v[_j] + _beta*M[mos(_i, _j, _m)]; + } + } + } + } + else { + if ( _beta==1.0 ) { + for ( _j=0; _j<_m; _j++ ) { + for ( _i=0; _i<=_j; _i++ ) { + M[mos(_i, _j, _m)] += _alpha * v[_i] * v[_j]; + } + } + } + else if ( _beta==0.0 ) { + for ( _j=0; _j<_m; _j++ ) { + for ( _i=0; _i<=_j; _i++ ) { + M[mos(_i, _j, _m)] = _alpha * v[_i] * v[_j]; + } + } + } + else { + for ( _j=0; _j<_m; _j++ ) { + for ( _i=0; _i<=_j; _i++ ) { + M[mos(_i, _j, _m)] = _alpha* v[_i] * v[_j] + _beta*M[mos(_i, _j, _m)]; + } + } + } + } + } + else { + if ( _alpha==1.0 ) { + if ( _beta==1.0 ) { + for ( _j=0; _j<_m; _j++ ) { + for ( _i=_j; _i<_m; _i++ ) { + M[mos(_i, _j, _m)] += v[_i] * v[_j]; + } + } + } + else if ( _beta==0.0 ) { + for ( _j=0; _j<_m; _j++ ) { + for ( _i=_j; _i<_m; _i++ ) { + M[mos(_i, _j, _m)] = v[_i] * v[_j]; + } + } + } + else { + for ( _j=0; _j<_m; _j++ ) { + for ( _i=_j; _i<_m; _i++ ) { + M[mos(_i, _j, _m)] = v[_i] * v[_j] + _beta*M[mos(_i, _j, _m)]; + } + } + } + } + else { + if ( _beta==1.0 ) { + for ( _j=0; _j<_m; _j++ ) { + for ( _i=_j; _i<_m; _i++ ) { + M[mos(_i, _j, _m)] += _alpha * v[_i] * v[_j]; + } + } + } + else if ( _beta==0.0 ) { + for ( _j=0; _j<_m; _j++ ) { + for ( _i=_j; _i<_m; _i++ ) { + M[mos(_i, _j, _m)] = _alpha * v[_i] * v[_j]; + } + } + } + else { + for ( _j=0; _j<_m; _j++ ) { + for ( _i=_j; _i<_m; _i++ ) { + M[mos(_i, _j, _m)] = _alpha* v[_i] * v[_j] + _beta*M[mos(_i, _j, _m)]; + } + } + } + } + } + } +} +/**/ + + + + + +/** +void swap_lf(double *a, double *b) { + double tmpd0; + + tmpd0 = *a; + *a = *b; + *b = tmpd0; +} +/**/ + +/** Creates zeros of the matrix of a given size. +TSdmatrix *CreateZeros_lf(int nrows, int ncols) { + int _i; + TSdmatrix *x_im=CreateMatrix_lf(nrows, ncols); + for (_i=nrows*ncols-1; _i>=0; _i--) + x_im->M[_i] = 0.0; + return(x_im); +} +TSdmatrix *CreateIdentity_lf(int nrows, int ncols) { + int _i; + TSdmatrix *x_im=CreateMatrix_lf(nrows, ncols); + for (_i=nrows*ncols-1; _i>=0; _i--) + x_im->M[_i] = 0.0; + if (nrows<=ncols) + for (_i=square(nrows)-1; _i>=0; _i -= nrows+1) + x_im->M[_i] = 1.0; + else + for (_i=(ncols-1)*(nrows+1); _i>=0; _i -= nrows+1) + x_im->M[_i] = 1.0; + return(x_im); +} +/**/ + + + +/** +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +void permute_matrix(double *a, int n, int *indx) { + double *b; + int nn=n*n; + register int i; + b = calloc(nn,sizeof(double)); + memcpy(b, a, nn*sizeof(double)); + for (i=0; i<nn; i++, a++) + *a = b[indx[i%n]+indx[i/n]*n]; +} + +int main() { + double a[9]={1,2,3,4,5,6,7,8,9}; + int indx[3]={1,2,0}; + permute_matrix(a,3,indx); + return 0; +} +/**/ diff --git a/CFiles/mathlib.h b/CFiles/mathlib.h new file mode 100755 index 0000000..fc53718 --- /dev/null +++ b/CFiles/mathlib.h @@ -0,0 +1,395 @@ +#ifndef __MATHLIB_H__ +#define __MATHLIB_H__ + #include "tzmatlab.h" + #include "fn_filesetup.h" //Used to call WriteMatrix(FPTR_DEBUG,....). + + //------------------------------------------------------ + // LAPACK routines -- all based on Intel MKL (or IMSL C Math library). + //------------------------------------------------------ + int lurgen(TSdmatrix *lu_dm, TSivector *pivot_dv, TSdmatrix *x_dm); + int eigrsym(TSdvector *eval_dv, TSdmatrix *eVec_dm, const TSdmatrix *S_dm); + int invrtri(TSdmatrix *X_dm, TSdmatrix *A_dm, const char un); + //The fastest way is to let X=A and A (and X) will be replaced by inv(A). + int invspd(TSdmatrix *X_dm, TSdmatrix *A_dm, const char ul); + //Inverse of a symmetric positive matrix A. + //Fastest way: let X=A. Then, A (and X) will be replaced by inv(A). + int invrgen(TSdmatrix *X_dm, TSdmatrix *A_dm); + //Inverse of a general real matrix A. + //If X=A, A (and X) will be replaced by inv(A). + int eigrgen(TSdzvector *vals_dzv, TSdzmatrix *rights_dzm, TSdzmatrix *lefts_dzm, const TSdmatrix *x_dm); + int chol(TSdmatrix *D_dm, TSdmatrix *S_dm, const char ul); + // The fastest way for chol() is to let D = S, but D will be replaced by the Choleski factor. + int BdivA_rrect(TSdmatrix *X_dm, const TSdmatrix *B_dm, const char lr, const TSdmatrix *A_dm); + int BdivA_rgens(TSdmatrix *X_dm, const TSdmatrix *B_dm, const char lr, const TSdmatrix *A_dm); + int bdivA_rgens(TSdvector *x_dv, const TSdvector *b_dv, const char lr, const TSdmatrix *A_dm); + //If x_dv->v = b_dv->v. Then, x_dv->v will be replaced by new values. + // x = A\b or b/A if lr='\\' or lr='/' where A is a real general square matrix. + void Aldivb_spd(TSdvector *x_dv, TSdmatrix *A_dm, TSdvector *b_dv, char an); + // Fastest way is to let x_dv->v = b_dv->v. Then, x_dv->v will be replaced by new values. + double detspd(TSdmatrix *S_dm); + //Determinant of symmetric positive definite (SPD) matrix must be positive. + //We set the return value to be -1 if this matrix is NOT SPD. + double logdetspd(TSdmatrix *S_dm); + //Determinant of symmetric positive definite (SPD) matrix must be positive. + //We set the return value to be log(-1.0) (becomeing NaN) if this matrix is NOT SPD. + double logdeterminant(TSdmatrix *A_dm); + // + //void eig_rgen_all(double *eval_v, double *evec_m, const double *x_m, const int _n); + int chol_decomp(double *D, const double *x_m, const int _n, const char ul); + int eigrgen_decomp(double *evalr_v, double *evali_v, double *revecr_m, double *reveci_m, double *levecr_m, double *leveci_m, const double *x_m, const int _n); + int eigrsym_decomp(double *eval_v, double *evec_m, const double *s_m, const int _n, const char ul); + int inv_spd(double *D, const double *s_m, const int _n, const char ul); + + + + //------------------------------------------------------ + // BLAS routines -- all based on Intel MKL (or IMSL C Math library). + //------------------------------------------------------ + double VectorDotVector(TSdvector *x1_dv, TSdvector *x2_dv); + //Output: Return sum(x1[i] * x2[i]) over i=1, ..., n. + // Allows the case x1_dv = x2_dv. + void ScalarTimesVectorUpdate(TSdvector *x2_dv, const double _alpha, TSdvector *x1_dv); + //Output: x2 = alpha * x1 + x2; + //Inputs: + // alpha: a double scalar; + // x1: n-by-1 double vector. + void ScalarTimesVector(TSdvector *x_dv, const double _alpha, TSdvector *a_dv, const double _beta); + //Output: x_dv = alpha*a_dv + beta*x_dv where x_dv is n-by-1. + // When beta=0.0 and x_dv->v = a_dv->v, x_dv->v will be replaced by new values. + //Inputs: + // a_dv: n-by-1. + // _alpha: a double scalar. + // _beta: a double scalar. + void VectorPlusMinusVectorUpdate(TSdvector *x_dv, const TSdvector *b_dv, double _alpha); + //Output: x_dv = _alpha * b_dv + x_dv where x_dv is _n-by-1. + //Inputs: + // b_dv: _n-by-1 double vector. + // _alpha: double scalar. + void VectorPlusMinusVector(TSdvector *x_dv, const TSdvector *a_dv, const TSdvector *b_dv, double _alpha); + //???????? Use tz_VectorPlusMinusVector() or VectorPlusVector() or VectorMinusVector(). + //???????? NOT finished yet. + //????????Must add _beta for x_dv = alpha*a_dv + beta*b_dv. + //??????????? NOT fully tested yet. + //Output: x_dv = a_dv + _alpha * b_dv where x_dv is _n-by-1. + //Inputs: + // a_dv: _n-by-1 double vector. + // b_dv: _n-by-1 double vector. + // _alpha: double scalar. + void VectorTimesSelf(TSdmatrix *C_dm, const TSdvector *a_dv, const double _alpha, const double _beta, const char ul); + //Using MKL with a default to my own C code. + //Output is the matrix C and all other arguments are inputs. + //Computes C = alpah*a*a' + beta*C where + // a is m-by-1, + // C is m-by-m symmetric matrix, + // alpha: a double scalar, + // beta: a double scalar. + // ul: if=='u' or 'U', only the upper triangular part of C is to be referenced; otherwise, only the lower triangular part of C is to be referenced; + void VectorTimesVector(TSdmatrix *C_dm, const TSdvector *a_dv, const TSdvector *b_dv, const double _alpha, const double _beta); + //?????? NOT tested for _beta != 1.0. + //Output is the matrix C and all other arguments are inputs. + //If beta != 0, always converting C (if symmetric or trianuglar) to a general matrix before the operation. + //The fastest way is to let _beta = 1.0. + //Computes C = alpah*a*b' + beta*C where + // a is m-by-1, + // b is n-by-1, + // C is m-by-n general matrix, + // alpha: a double scalar, + // beta: a double scalar. + void MatrixPlusMinusMatrixUpdate(TSdmatrix *X_dm, TSdmatrix *A_dm, double _alpha); + //$$$$$ If A_dm or X_dm is only upper or lower symmetric, it will be always converted to a general (and symmetric) matrix. $$$$$$ + //Output: X =_alpha * A + X where X_dm is an m-by-n general (and possibly symmetric) matrix. + //Inputs: + // A_dm: m-by-n general or symmetric matrix. + // _alpha: double scalar. + void MatrixTimesVector(TSdvector *x_dv, TSdmatrix *A_dm, const TSdvector *b_dv, const double _alpha, const double _beta, const char tn); + //WARNING: x_dv must NOT be the same as b_dv! + //Output: x_dv->v = _alpha*A_dm'*b_dv + _beta*x_dv for tn=='T'; x_dv = _alpha*A_dm*b_dv + _beta*x_dv for tn=='N' + // where x_dv->v is ncols-by-1 or nrows-by-1 and needs not be initialized if _beta is set to 0.0. + //Inputs: + // A_dm->M: nrows-by-ncols; + // b_dv->v: nrows-by-1 or ncols-by-1; + // _alpha: double scalar; + // _beta: double scalar; + // tn: if =='t' or 'T', transpose of A_dm is used; otherwise, A_dm itself (no transpose) is used. + void TrimatrixTimesVector(TSdvector *x_dv, TSdmatrix *A_dm, TSdvector *b_dv, const char tn, const char un); + //Output: x_dv = A_dm'*b_dv for tn=='T'; x_dv = A_dm*b_dv for tn=='N' where x_dv->v is _n-by-1. + // If x_dv = b_dv (which gives the fastest return, so try to use this option), x_dv will be relaced by A*b or A'*b. + //Inputs: + // A_dm->M: _n-by-_n triangular matrix. + // b_dv->v: _n-by-1 vector. + // tn: if =='T' or 't', transpose of A_dm is used; otherwise, A_dm itself (no transpose) is used. + // un: if =='U' or 'u', A_dm is unit triangular; otherwise, A_dm is non-unit triangular (i.e., a regular triangular matrix). + void SymmatrixTimesVector(TSdvector *x_dv, TSdmatrix *A_dm, TSdvector *b_dv, const double _alpha, const double _beta); + //????? This is NOT checked yet: If x_dv = b_dv, x_dv or b_dv will be relaced by alpha*A*x + beta*x. + //Output: + // x_dv = alpha*A_dm*b_dv + beta*x_dv where x_dv->v is _n-by-1. + // When beta=0, there is no need to initialize the value of x_dv. + //Inputs: + // A_dm->M: _n-by-_n triangular matrix. + // b_dv->v: _n-by-1 vector. + // _alpha: double scalar; + // _beta: double scalar; + void VectorTimesMatrix(TSdvector *x_dv, const TSdvector *b_dv, TSdmatrix *A_dm, const double _alpha, const double _beta, const char tn); + //Output: x_dv->v = _alpha*b_dv*A_dm + _beta*x_dv for tn=='N'; x_dv = _alpha*b_dv*A_dm' + _beta*x_dv for tn=='T' + // where x_dv->v is 1-by-ncols or 1-by-nrows and needs not be initialized if _beta is set to 0.0. + //Inputs: + // A_dm->M: nrows-by-ncols; + // b_dv->v: 1-by-nrows or 1-by-ncols; + // _alpha: double scalar; + // _beta: double scalar; + // tn: if =='T' or 't', transpose of A_dm is used; otherwise (=='N' or 'n'), A_dm itself (no transpose) is used. + void ScalarTimesMatrix(TSdmatrix *x_dm, const double _alpha, TSdmatrix *a_dm, const double _beta); + //$$$$$ If a_dm or x_dm (when _beta!=0) is only upper or lower symmetric, it will be always converted to a general (and symmetric) matrix. $$$$$$ + //Output: x_dm = alpha*a_dm + beta*x_dm where x_dm is m-by-n. + // Fastest way is to let beta=0.0 and x_dm->M = a_dm->M. Then x_dm->M will be replaced by new values. + // However, with beta=0.0, x_dm and a_dm can be different. + //Inputs: + // a_dm: m-by-n. + // _alpha: a double scalar. + // _beta: a double scalar. + void ScalarTimesMatrixSquare(TSdmatrix *B_dm, const double _alpha, TSdmatrix *A_dm, const char tn, const double _beta); + //Outputs: + // B = alpha*o(A) + beta*B, where o(A) = A' if tn=='T' or 't' or A if tn=='N' or 'n'. + // If A=B, then A is replaced by alpha*o(A) + beta*A. + //Inputs: + // A_dm: n-by-n square matrix. + // B_dm: n-by-n square matrix. + // tn: 'T' (transpose of A) or 'N' (no transpose). + // alpha, beta: double scalars. + void MatrixTimesSelf(TSdmatrix *C_dm, const char ul, TSdmatrix *A_dm, const char tn, const double _alpha, const double _beta); + //If tn=='N' or 'n', C = alpha*A*A' + beta*C. + //If tn=='T' or 't', C = alpha*A'*A + beta*C. + //If ul=='U' or 'u', C_dm->flag = M_SU; + //If ul=='L' or 'l', C_dm->flag = M_SL; + // C must be different from A. + // C is n-by-n; + // A is n-by-k if tn=='N'; + // k-by-n if tn=='T'; + // alpha is a double scalar, + // beta is a double scalar. + void MatrixTimesMatrix(TSdmatrix *C_dm, TSdmatrix *A_dm, TSdmatrix *B_dm, const double _alpha, const double _beta, const char tn1, const char tn2); + //Output is C and all other arguments are inputs. + //Computes C = alpah*op(A)*op(B) + beta*C where op() is either transpose or not, depending on 't' or 'n', + // op(A) is m-by-k, + // op(B) is k-by-n, + // C is m-by-n, + // C must be different from A and from B. + // A and B can be the same, however. + // alpha is a double scalar, + // beta is a double scalar. + // tn1: if == 'T' or 't', the transpose of A is used; otherwise (== 'N' or 'n"), A itself (no transpose) is used. + // tn2: if == 'T' or 't', the transpose of B is used; otherwise (== 'N' or 'n"), B itself (no transpose) is used. + void SolveTriSysVector(TSdvector *x_dv, const TSdmatrix *T_dm, TSdvector *b_dv, const char tn, const char un); + //Output --- computes x_dv = inv(T_dm)*b_dv by solving a triangular system of equation T_dm * x_dv = b_dv. + // x_dv(_n-by-1) = inv(T_dm)*b_v if tn=='N'; = inv(T_dm')*b_v if tn=='T'. + // Fastest way is to let x_dv->v = b_dv->v. Then, x_dv->v will be replaced by new values. + + + + +// #define ScalarTimesVector(x_v, a, b_v, _n) cblas_daxpy(_n, a, b_v, 1, x_v, 1) +// //Output: x_v = a * b_v + x_v where double *x_v (_n-by-1) must be initialized. +// //Inputs: a -- double scalar; b_v -- pointer (_n-by-1) to double. +// #define VectorDotVector(a_v, b_v, _n) cblas_ddot(_n, a_v, 1, b_v, 1) +// //Output: x=a_v'*b_v: double scalar. +// //Inputs: a_v, b_v: pointer (_n-by-1) to double. + + void SymmetricMatrixTimesVector(double *x_v, const double a, const double *A_m, const double *a_v, const double b, const int _n, const char ul); + //Output: x_v = a*A_m*a_v + b*X_m where x_v (_n-by-1) must be allocated (but needs not be initialized). + //Inputs: + // A_m: _n-by-_n symmetric matrix; + // a_v: _n-by-1; + // a, b: scalars; + // ul: if =='u' or 'U', upper triangular elements in A_m are filled; if =='l' or 'L', lower triangular elements in A_m are filled. + void SolveTriangularSystemVector(double *x_v, const double *A_m, const double *b_v, const int _n, const char ul, const char tn, const char un); + //Outputs: + // x_v(_n-by-1) = inv(A_m)*b_v. If x_v=b_v, b_v will be overwritten by x_v. + //------- + //Inputs: + // A_m: _n-by-_n upper or lower triangular matrix; + // b_v: _n-by-1 vector. + // ul: if =='u' or 'U', A_m is upper triangular; if =='l' or 'L', A_m is lower triangular. + // tn: if =='t' or 'T', A_m' (transpose), instead of A_m, will be used; if =='n', A_m itself (no transpose) will be used. + // un: if =='u' or 'U', A_m is a unit upper triangular (i.e., the diagonal being 1); + // if =='n' or 'N', A_m is a non-unit upper triangular. + // + // Computes x_v = inv(A_m)*b_v by solving a triangular system of equation A_m * x_v = b_v. + // Note I: Intel MLK cblas_dtrsv() does not test for singularity or near-singulariy of the system. + // Such tests must be performed before calling this BLAS routine. + // Note II: if x_v=b_v, b_v will be overwritten by x_v. + + + + + + + //------------------------------------------------------ + // MKL Vector Mathematical Library with default using my own routines. + //------------------------------------------------------ + void VectorDotDivByVector(TSdvector *x_dv, const TSdvector *a_dv, const TSdvector *b_dv); + //????????? NOT tested yet. 06/13/03. + //--- The faster way is to use MKL VML with x_dv != a_dv and x_dv != b_dv; x = a./b; + void ElementwiseVectorDivideVector(TSdvector *x_dv, const TSdvector *a_dv, const TSdvector *b_dv); + //--- The faster way is to use MKL VML with y_dv != x_dv; + void ElementwiseInverseofVector(TSdvector *y_dv, TSdvector *x_dv); + void ElementwiseSqrtofVector(TSdvector *y_dv, TSdvector *x_dv); + void ElementwiseLogtofVector(TSdvector *y_dv, TSdvector *x_dv); + //--- The faster way is to use MKL VML with Y_dm != X_dm; + void ElementwiseInverseofMatrix(TSdmatrix *Y_dm, TSdmatrix *X_dm); + + + + //------------------------------------------------------ + // Matrix routines (my own). + //------------------------------------------------------ + void tz_VectorPlusMinusVector(TSdvector *x_dv, const TSdvector *a_dv, const double _alpha, const TSdvector *b_dv, const double _beta); + //Output: x_dv = alpha*a_dv + beta*b_dv where x_dv is _n-by-1. + //Inputs: + // a_dv: _n-by-1 double vector. + // _alpha: double constant. + // b_dv: _n-by-1 double vector. + // _beta: double constant. + void VectorPlusVector(TSdvector *x_dv, const TSdvector *a_dv, const TSdvector *b_dv); + //Output: x_dv = a_dv + b_dv where x_dv is _n-by-1. + // If x_dv = a_dv, a_dv will be replaced by x_dv. + // If x_dv = b_dv, b_dv will be replaced by x_dv, + //Inputs: + // a_dv: _n-by-1 double vector. + // b_dv: _n-by-1 double vector. + void VectorMinusVector(TSdvector *x_dv, const TSdvector *a_dv, const TSdvector *b_dv); + //Output: x_dv = a_dv - b_dv where x_dv is _n-by-1. + // If x_dv = a_dv, x_dv will be replaced by x_dv - b_dv. + // If x_dv = b_dv, x_dv will be replaced by a_dv - x_dv. + //Inputs: + // a_dv: _n-by-1 double vector. + // b_dv: _n-by-1 double vector. + void VectorPlusVectorUpdate(TSdvector *x_dv, const TSdvector *b_dv); + //Output: x_dv = b_dv + x_dv where x_dv is _n-by-1. + //Inputs: + // b_dv: _n-by-1 double vector. + void VectorDotTimesVector(TSdvector *x_dv, const TSdvector *a_dv, TSdvector *b_dv, const double _alpha, const double _beta); + //Output: + // x_dv is _n-by-1. + // x_dv = _alpha * a_dv .* b_dv + _beta * x_dv if x_dv != b_dv. + // x_dv = _alpha * a_dv .* x_dv + _beta * x_dv if x_dv = b_dv. + //Inputs: + // a_dv: _n-by-1 double vector. + // b_dv: _n-by-1 double vector. + // _alpha: double scalar. + // _beta: a double scalar. + void SwapColsofMatrix(TSdmatrix *X_dm, int j1, int j2); + //??????? NOT tested yet. + void SwapColsofMatrices(TSdmatrix *X1_dm, int j1, TSdmatrix *X2_dm, int j2); + void SwapPositionsofMatrix(TSdmatrix *X_dm, int j1, int j2); + void SwapMatricesofCell(TSdcell *A_dc, int c1, int c2); + void SwapVectorsofCellvec(TSdcellvec *x_dcv, int c1, int c2); + void SwapVectorsofCellvec_int(TSicellvec *x_icv, int c1, int c2); + void PermuteColsofMatrix(TSdmatrix *A_dm, const TSivector *indx_iv); + void PermuteRowsofMatrix(TSdmatrix *A_dm, const TSivector *indx_iv); + void PermuteMatrix(TSdmatrix *A_dm, const TSivector *indx_iv); + void PermuteMatricesofCell(TSdcell *A_dc, const TSivector *indx_iv); + void ScalarTimesColofMatrix(TSdvector *y_dv, double _alpha, TSdmatrix *x_dm, int _j); + //????????? Default option, in the #else, has NOT been tested yet! + void ScalarTimesColofMatrix2ColofMatrix(TSdmatrix *y_dm, int jy, double _alpha, TSdmatrix *x_dm, int jx); + void ScalarTimesColofMatrixPlusVector2ColofMatrix(TSdmatrix *Y_dm, int jy, double _alpha, TSdmatrix *X_dm, int jx, double _beta, TSdvector *x_dv); +// void ColofMatrixDotTimesVector(TSdvector *y_dv, TSdmatrix *X_dm, int jx, TSdvector *x_dv, double _alpha, double _beta); + void MatrixDotDivideVector_row(TSdmatrix *Y_dm, TSdmatrix *X_dm, TSdvector *x_dv, double _alpha, double _beta); + void RowofMatrixDotDivideVector(TSdvector *y_dv, TSdmatrix *X_dm, int ix, TSdvector *x_dv, double _alpha, double _beta); + //??????? NOT tested yet, 01/02/04. + void ColofMatrixDotTimesVector(TSdvector *y_dv, TSdmatrix *X_dm, int jx, TSdvector *x_dv, double _alpha, double _beta); + void ColofMatrixDotTimesColofMatrix(TSdvector *y_dv, TSdmatrix *X1_dm, int jx1, TSdmatrix *X2_dm, int jx2, double _alpha, double _beta); + void ColofMatrixDotTimesColofMatrix2ColofMatrix(TSdmatrix *Y_dm, int jy, TSdmatrix *X1_dm, int jx1, TSdmatrix *X2_dm, int jx2, double _alpha, double _beta); + void MatrixPlusMatrixUpdate(TSdmatrix *X_dm, TSdmatrix *A_dm); + //Output: X = X + A where X_dm is an m-by-n general matrix. + //Inputs: + // A_dm: m-by-n general matrix. + void MatrixPlusMatrix(TSdmatrix *X_dm, TSdmatrix *A_dm, TSdmatrix *B_dm); + //Output: X = A + B where X_dm is an m-by-n general matrix. + // If X=A, A will be replaced by X; if X=B, B will be replaced by X. + //Inputs: + // A_dm: m-by-n general matrix. + // B_dm: m-by-n general matrix. + void MatrixMinusMatrix(TSdmatrix *X_dm, TSdmatrix *A_dm, TSdmatrix *B_dm); + //Output: X = A - B where X_dm is an m-by-n general matrix. + // If X=A, A will be replaced by X; if X=B, B will be replaced by X. + //Inputs: + // A_dm: m-by-n general matrix. + // B_dm: m-by-n general matrix. + void Matrix2PlusMinusMatrix(TSdmatrix *X_dm, TSdmatrix *A_dm, TSdmatrix *B_dm, TSdmatrix *C_dm, const double _alpha, const double _beta, const double _gamma); + //????? Not yet exhaust all possibilities of alpha, beta, and gamma to get most efficiency. Add more as required. 10 February 2003. + //Output: X = alpha*A + beta*B + gamma*C where X_dm is an m-by-n general matrix. + //Inputs: + // A_dm: m-by-n general matrix. + // B_dm: m-by-n general matrix. + // C_dm: m-by-n general matrix. + // _alpha: a double scalar for A_dm. + // _beta: a double scalar for B_dm. + // _gamma: a double scalar for C_dm. + void MatrixPlusConstantDiagUpdate(TSdmatrix *X_dm, const double _alpha); + //Output: X = X + diag([_alpha, ..., _alpha]) where X is an n-by-n square real matrix. + void MatrixDotTimesMatrix(TSdmatrix *X_dm, TSdmatrix *A_dm, TSdmatrix *B_dm, const double _alpha, const double _beta); + //$$$$$ If A_dm or B_dm or X_dm (when _beta!=0) is only upper or lower symmetric, it will be always converted to a general (and symmetric) matrix. $$$$$$ + //Output: + // X_dm is m-by-n. + // X_dm = _alpha * A_dm .* B_dm + _beta * X_dm if X_dm != B_dm. + // X_dm = _alpha * A_dm .* X_dm + _beta * X_dm if X_dm = B_dm. + void CopyVector0(TSdvector *x1_dv, const TSdvector *x2_dv); + void CopyMatrix0(TSdmatrix *x1_dm, TSdmatrix *x2_dm); + void CopyCellvec0(TSdcellvec *x1_dcv, TSdcellvec *x2_dcv); + void CopyCell0(TSdcell *x1_dc, TSdcell *x2_dc); + void CopySubmatrix0(TSdmatrix *x1_dm, TSdmatrix *x2_dm, const int br, const int bc, const int nrs, const int ncs); + void CopySubmatrix(TSdmatrix *x1_dm, const int br1, const int bc1, TSdmatrix *x2_dm, const int br2, const int bc2, const int nrs, const int ncs); + void CopySubrowmatrix(TSdmatrix *x1_dm, const int br1, const int bc1, TSdmatrix *x2_dm, const int br2, const int bc2, const int nrs, const int ncs); + //??????? NOT tested yet. + void CopySubmatrix2rowmatrix(TSdmatrix *x1_dm, const int br1, const int bc1, TSdmatrix *x2_dm, const int br2, const int bc2, const int nrs, const int ncs); + void CopySubrowmatrix2matrix(TSdmatrix *x1_dm, const int br1, const int bc1, TSdmatrix *x2_dm, const int br2, const int bc2, const int nrs, const int ncs); + //??????? NOT tested yet. + void CopySubvector(TSdvector *x1_dv, const int ptrloc1, const TSdvector *x2_dv, const int ptrloc2, const int nels); + void CopySubvector_int(TSivector *x1_iv, const int ptrloc1, const TSivector *x2_iv, const int ptrloc2, const int nels); + void CopySubmatrix2vector(TSdvector *x1_dv, const int ptrloc1, TSdmatrix *x2_dm, const int br, const int bc, const int nels); + void CopySubmatrix2vector_sub(TSdvector *x1_dv, const int ptrloc1, TSdmatrix *x2_dm, const int br, const int bc, const int nrs, const int ncs); + void CopySubmatrix2vector_int(TSivector *x1_iv, const int ptrloc1, TSimatrix *x2_im, const int br, const int bc, const int nels); + void CopySubmatrix2vector_row(TSdvector *x1_dv, const int ptrloc1, TSdmatrix *x2_dm, const int br, const int bc, const int nels); + void CopySubvector2matrix(TSdmatrix *x1_dm, const int br, const int bc, const TSdvector *x2_dv, const int ptrloc2, const int nels); + void CopySubvector2rowmatrix(TSdmatrix *x1_dm, const int br, const int bc, const TSdvector *x2_dv, const int ptrloc2, const int nels); + void CopySubvector2matrix_sub(TSdmatrix *x1_dm, const int br, const int bc, const int nrs, const int ncs, TSdvector *x2_dv, const int ptrloc2); + void CopySubvector2matrix_unr(TSdmatrix *x1_dm, const int br, const int bc, const TSdvector *x2_dv, const int ptrloc2, const int nels); + void TransposeSquare(TSdmatrix *B_dm, TSdmatrix *A_dm); + //???????? Some options are NOT test yet. 2/27/03. ??????????? + void TransposeRegular(TSdmatrix *B_dm, const TSdmatrix *A_dm); + TSdmatrix *tz_TransposeRegular(TSdmatrix *B_dm, const TSdmatrix *A_dm); + void SUtoGE(TSdmatrix *x_dm); + //Output: x_dm (nrows<=ncols) becomes a general matrix in addition to being upper symmetric. + //Input: x_dm (nrows<=ncols) is upper symmetric. + void SLtoGE(TSdmatrix *x_dm); + //Output: x_dm (nrows>=ncols) becomes a general matrix in addition to being lower symmetric. + //Input: x_dm (nrows>=ncols) is lower symmetric. + double SumVector(TSdvector *x_dv); + double MaxVector(TSdvector *x_dv); + double MinVector(TSdvector *x_dv); + int MaxVector_int(TSivector *x_iv); + void SumMatrix(TSdvector *x_dv, const TSdmatrix *X_dm, const char rc); + //+ + void diagdv(TSdvector *x_dv, TSdmatrix *x_dm); + TSdmatrix *tz_DiagMatrix(TSdmatrix *X_dm, TSdvector *x_dv); + double tracefabs(TSdmatrix *x_dm); + double tracelogfabs(TSdmatrix *x_dm); + double tracelog(TSdmatrix *x_dm); + double sumoflogvector(TSdvector *x_dv); + // + TSdmatrix *tz_kron(TSdmatrix *C_dm, TSdmatrix *A_dm, TSdmatrix *B_dm); + //C = kron(A, B), compatible with Matlab notation. + //Inputs: + // A_dm and B_dm: two real general matrices. + //Outputs: + // If C_dm == NULL, C_dm is created (memory allocated) and returned (thus, the memory must be destroyed outside this function). + // If C_dm != NULL, C_dm's memory has already been allocated outside this function and the same C_dm will be returned. + + + + + //=== Self-written routines. + void ergodicp(TSdvector *p_dv, TSdmatrix *P_dm); + //double *fn_ergodp2(const double *cp_m, const int _n); + double *alloc_ergodp2(const double *cp_m, const int _n); +#endif diff --git a/CFiles/numgradgenTemplate.c b/CFiles/numgradgenTemplate.c new file mode 100755 index 0000000..31130c3 --- /dev/null +++ b/CFiles/numgradgenTemplate.c @@ -0,0 +1,83 @@ +/* For the general purpose numerical gradient.This source file (function) must be *manually* copied to a specific subdirectory (another source file). + * Before copying this file, there are a few lines that must be *manually* changed, marked by CCCCCCCCC: + * (1) The .h file to be included. + * (2) T_tag in the typedef. + * (3) T_tag in the declaration of the structure. +*/ +#include "swz_comfuns.h" //CCCCCCCCC. + + +typedef double TFgradfcn(struct T_tag *); //CCCCCCCCC. +//------------------------------- +// Modified from gradcd_gen() in cstz.c for the general purpose. +//------------------------------- +#define STPS 1.0e-04 // 6.0554544523933391e-6 step size = pow(DBL_EPSILON,1.0/3) +void numgrad_cd(void *Snotype_ps) +{ + /* The no-type structure Snotype_ps must contain the output and input arguments with the *exact* names. */ + //Outputs: + // grad_dv: the gradient n-by-1 g (no need to be initialized). + //Inputs: + // xg_dv: the n-by-1 vector point at which the gradient is evaluated. No change in the end although will be added or substracted by dh during the function (but in the end the original value will be put back). + // fcn_grad(struct T_tag *): the function for which the gradient is evaluated + // grdh: step size. If 0.0, then dh is set automatically; otherwise, grdh is taken as a step size, often set as 1.0e-004. + // fatx: the value of (*fcn_grad)(xg_dv). NOT used in this function except dealing with the boundary (NEARINFINITY) for the + // minimization problem, but to be compatible with a genral function call where, say, a forward-difference method or cubic + // interpolation of central difference method will use f0. + + //double *g, double *x, int n, double (*fcn)(double *x, int n), double *grdh, double f0) + + //--- Essential elments from the structure S_ps. + struct T_tag *S_ps = (T_tag *)Snotype_ps; //CCCCCCCCC. + int n = S_ps->grad_dv->n; + double *g = S_ps->grad_dv->v; + double *x = S_ps->xg_dv->v; + TFgradfcn *fcn = S_ps->fcn_grad; + double grdh = S_ps->grdh; + double f0 = S_ps->fatx; //At the original point x. + //--- Local to this function only. + int i; + double dh, dhi, dh2i, fp, fm, tmp, *xp; + + + if (grdh != 0.0) { + dh2i = (dhi=1.0/(dh=grdh))/2.0; + for (i=0, xp=x; i<n; i++, xp++, g++) { + tmp = *xp; + *xp += dh; + //The following statement is bad because dh does not get reset at the beginning of the loop and thus may get changed continually within the loop. + // dh = *xp - tmp; // This increases the precision slightly. + fp = fcn(S_ps); //At the point x+dh. + *xp = tmp - dh; + fm = fcn(S_ps); //At the point x-dh. + + //=== Checking the boundary condition for the minimization problem. + if (fp >= NEARINFINITY) *g = (f0-fm)*dhi; + else if (fm >= NEARINFINITY) *g = (fp-f0)*dhi; + else *g = (fp-fm)*dh2i; + + *xp = tmp; // Put the original value of x[i] back to x[i] so that the content x[i] is still unaltered. + } + + } + else { + for (i=0, xp=x; i<n; i++, xp++, g++) { + dh = fabs(*xp)<=1 ? STPS : STPS*(*xp); + tmp = *xp; + *xp += dh; + dh = *xp - tmp; // This increases the precision slightly. + fp = fcn(S_ps); //At the point x+dh. + *xp = tmp - dh; + fm = fcn(S_ps); //At the point x-dh. + + //=== Checking the boundary condition for the minimization problem. + if (fp >= NEARINFINITY) *g = (f0-fm)/dh; + else if (fm >= NEARINFINITY) *g = (fp-f0)/dh; + else *g = (fp-fm)/(2.0*dh); + + *xp = tmp; // Put the original value of x[i] back to x[i] so that the content x[i] is still unaltered. + } + } +} +#undef STPS + diff --git a/CFiles/optpackage.c b/CFiles/optpackage.c new file mode 100755 index 0000000..e52975e --- /dev/null +++ b/CFiles/optpackage.c @@ -0,0 +1,1109 @@ +/*========================================================= + * Optimization package for different third-party routines, including csminwel. + * +=========================================================*/ +#include "optpackage.h" + +#define STRLEN 256 +static char filename_sp_vec_minproj[STRLEN]; + +static struct TSetc_csminwel_tag *CreateTSetc_csminwel(FILE *fptr_input1, const int n, const int q, const int k); //Used by CreateTSminpack() only. +static struct TSetc_csminwel_tag *DestroyTSetc_csminwel(struct TSetc_csminwel_tag *etc_csminwel_ps); //Used by DestroyTSminpack() only. +//------- For csminwel only. ------- +static TSminpack *SetMincsminwelGlobal(TSminpack *minpack_csminwel_ps); +static double minobj_csminwelwrap(double *x, int n, double **dummy1, int *dummy2); +static int mingrad_csminwelwrap(double *x, int n, double *g, double **dummy1, int *dummy2); +//------- For IMSL linearly constrainted optimization only. ------- +static double GLB_FVALMIN = NEARINFINITY; //Must be initialized to ba a very big number. +static int GLB_DISPLAY = 1; //Print out intermediate results on screen. +static TSdvector *XIMSL_DV = NULL; //To save the minimized value in case the IMSL quits with a higher value. +static struct TStateModel_tag *SetModelGlobalForIMSLconlin(struct TStateModel_tag *smodel_ps); +static void ObjFuncForModel_imslconlin(int d_x0, double *x0_p, double *fret_p); +static void imslconlin_SetPrintFile(char *filename); +static double opt_logOverallPosteriorKernal(struct TStateModel_tag *smodel_ps, TSdvector *xchange_dv); +static void gradcd_imslconlin(int n, double *x, double *g); +static double ObjFuncForModel_congrad(double *x0_p, int d_x0); + + + +////TSminpack *CreateTSminpack(TFminpackage *minfinder_func, TFminobj *minobj_func, TFmingrad *mingrad_func, TFSetPrintFile *printinterresults_func, const int n, const int package) //, const int indxAnag) +////TSminpack *CreateTSminpack(TFminfinder *minfinder_func, TFminobj *minobj_func, TFmingrad *mingrad_func, char *filename_printout, const int n, const int package) //, const int indxAnag) +TSminpack *CreateTSminpack(TFminobj *minobj_func, void **etc_project_pps, TFmindestroy_etcproject *etcproject_func, TFmingrad *mingrad_func, char *filename_printout, const int n, const int package) +{ + TSminpack *minpack_ps = tzMalloc(1, TSminpack); + + //$$$$WARNING: Note the vector xtemp_dv->v or gtemp_dv-v itself is not allocated memory, but only the POINTER. + //$$$$ Within the minimization routine like csminwel(), the temporary array x enters as the argument in + //$$$$ the objective function to compare with other values. If we use minpack_ps->x_dv->v = x + //$$$$ in a wrapper function like minobj_csminwelwrap() where x is a temporay array in csminwel(), + //$$$$ this tempoary array (e.g., x[0] in csminwel()) within the csminwel minimization routine + //$$$$ will be freed after the csminwel minimization is done. Consequently, minpack_ps->x_dv-v, which + //$$$$ which was re-pointed to this tempoary array, will freed as well. Thus, no minimization results + //$$$$ would be stored and trying to access to minpack_ps->x_dv would cause memory leak. + //$$$$ We don't need, however, to create another temporary pointer within the objective function itself, + //$$$$ but we must use minpack_ps->xtemp_dv for a *wrapper* function instead and at the end of + //$$$$ minimization, minpack_ps->x_dv will have the value of minpack_ps->xtemp_dv, which is automatically + //$$$$ taken care of by csminwel with the lines such as + //$$$$ memcpy(xh,x[3],n*sizeof(double)); + //$$$$ where xh and minpack_ps->x_dv->v point to the same memory space. + + + minpack_ps->xtemp_dv = tzMalloc(1, TSdvector); + minpack_ps->gtemp_dv = tzMalloc(1, TSdvector); + minpack_ps->xtemp_dv->flag = minpack_ps->gtemp_dv->flag = V_DEF; //Set the flag first but will be assigned legal values in minobj_csminwelwrap(). + minpack_ps->xtemp_dv->n = minpack_ps->gtemp_dv->n = n; + + + minpack_ps->x_dv = CreateVector_lf(n); + minpack_ps->g_dv = CreateVector_lf(n); + minpack_ps->x0_dv = CreateVector_lf(n); + // + minpack_ps->etc_project_ps = (void *)*etc_project_pps; + minpack_ps->DestroyTSetc_project = etcproject_func; + if (etcproject_func) *etc_project_pps = NULL; //If destroy function makes this structure responsible to free memory of the passing pointer, reset this passing pointer to NULL to avoid double destroying actions and cause memory problem. + // + minpack_ps->etc_package_ps = NULL; + minpack_ps->minobj = minobj_func; + minpack_ps->mingrad = mingrad_func; + minpack_ps->filename_printout = filename_printout; +// minpack_ps->SetPrintFile = printinterresults_func; + + if ( (minpack_ps->package=package) & MIN_CSMINWEL ) { + minpack_ps->etc_package_ps = (void *)CreateTSetc_csminwel(((struct TSetc_minproj_tag *)minpack_ps->etc_project_ps)->args_blockcsminwel_ps->fptr_input1, n, 0, 0); +// if (minpack_ps->mingrad) fn_DisplayError(".../optpackage.c/CreateTSminpack(): Have not got time to deal with analytical gradient situation"); +// if (minpack_ps->indxAnag=indxAnag) fn_DisplayError(".../optpackage.c/CreateTSminpack(): Have not got time to deal with analytical gradient situation"); + } + else fn_DisplayError(".../optpackage.c/CreateTSminpack(): Have not got time to specify other minimization packages than csminwel"); + + return (minpack_ps); +} +//--- +TSminpack *DestroyTSminpack(TSminpack *minpack_ps) +{ + if (minpack_ps) { + //$$$$WARNING: Note the following vectors themselves are NOT allocated memory, but only the POINTERs. Used within the minimization problem. + //$$$$ See minobj_csminwelwrap() as an example. + free(minpack_ps->xtemp_dv); + free(minpack_ps->gtemp_dv); + + + DestroyVector_lf(minpack_ps->x_dv); + DestroyVector_lf(minpack_ps->g_dv); + DestroyVector_lf(minpack_ps->x0_dv); + if (minpack_ps->DestroyTSetc_project) minpack_ps->DestroyTSetc_project(minpack_ps->etc_project_ps); //If destroy function is active, destroy it here; ohterwise, it will be destroyed somewhere else. + if ( minpack_ps->package & MIN_CSMINWEL ) DestroyTSetc_csminwel((TSetc_csminwel *)minpack_ps->etc_package_ps); + + //=== + free(minpack_ps); + return ((TSminpack *)NULL); + } + else return (minpack_ps); +} + + + +//----------------------------------------------------------------------- +// Unconstrained BFGS csminwel package. +//----------------------------------------------------------------------- +static TSetc_csminwel *CreateTSetc_csminwel(FILE *fptr_input1, const int n, const int q, const int k) +{ + //If fptr_input1==NULL or no no values supplied when fptr_input1 != NULL, default values are taken. + int _i; + //=== + TSetc_csminwel *etc_csminwel_ps = tzMalloc(1, TSetc_csminwel); + + etc_csminwel_ps->_k = k; + if (!k) { + etc_csminwel_ps->args = (double **)NULL; + etc_csminwel_ps->dims = (int *)NULL; + } + else { + etc_csminwel_ps->dims = tzMalloc(k, int); + etc_csminwel_ps->args = tzMalloc(k, double *); + for (_i=k-1; _i>=0; _i--) *(etc_csminwel_ps->args + _i) = tzMalloc(q, double); + } + + //=== Default values of input arguments. + etc_csminwel_ps->Hx_dm = CreateMatrix_lf(n, n); //n-by-n inverse Hessian. + //+ + etc_csminwel_ps->badg = 1; //1: numerical gradient will be used. + etc_csminwel_ps->indxnumgrad_csminwel = INDXNUMGRAD_CSMINWEL; //Method of the numerical gradient. + + //=== Reads doubles. + if ( !fptr_input1 || !fn_SetFilePosition(fptr_input1, "//== crit ==//") || fscanf(fptr_input1, " %lf ", &etc_csminwel_ps->crit) != 1 ) + etc_csminwel_ps->crit = CRIT_CSMINWEL; //Defaut for overall convergence criterion for the function value. + if ( !fptr_input1 || !fn_SetFilePosition(fptr_input1, "//== ini_h_csminwel ==//") || fscanf(fptr_input1, " %lf ", &etc_csminwel_ps->ini_h_csminwel) != 1 ) + etc_csminwel_ps->ini_h_csminwel = INI_H_CSMINWEL; //Defaut + if ( !fptr_input1 || !fn_SetFilePosition(fptr_input1, "//== gradstps_csminwel ==//") || fscanf(fptr_input1, " %lf ", &etc_csminwel_ps->gradstps_csminwel) != 1 ) + etc_csminwel_ps->gradstps_csminwel = GRADSTPS_CSMINWEL; //Default for step size of the numerical gradient. + + //=== Reads integers. + if ( !fptr_input1 || !fn_SetFilePosition(fptr_input1, "//== itmax ==//") || fscanf(fptr_input1, " %d ", &etc_csminwel_ps->itmax) != 1 ) + etc_csminwel_ps->itmax = ITMAX_CSMINWEL; //Default for maximum number of iterations. + + + return (etc_csminwel_ps); +} +//#undef CRIT_CSMINWEL +//#undef ITMAX_CSMINWEL +//--- +static TSetc_csminwel *DestroyTSetc_csminwel(TSetc_csminwel *etc_csminwel_ps) +{ + int _i; + + if (etc_csminwel_ps) { + for (_i=etc_csminwel_ps->_k-1; _i>=0; _i--) tzDestroy(etc_csminwel_ps->args[_i]); + tzDestroy(etc_csminwel_ps->args); + tzDestroy(etc_csminwel_ps->dims); + //--- + DestroyMatrix_lf(etc_csminwel_ps->Hx_dm); + + //=== + free(etc_csminwel_ps); + return ((TSetc_csminwel *)NULL); + } + else return (etc_csminwel_ps); +} + + + +/********************************************* + * WARNING: All the following data structures are declared global because + * (1) the minimization package takes only global variables; + * (2) these global structures make the existing functions reusable; + * (3) modifying the exisiting functions to keep global variables at minimum is NOT really worth the time. +*********************************************/ +//--------------------------------- +// Begin: This wrapper function makes it conformable to the call of the csminwel package. +//--------------------------------- +static struct TSminpack_tag *MINPACK_CSMINWEL_PS = NULL; //Minimization to find the MLE or posterior peak. +static TSminpack *SetMincsminwelGlobal(TSminpack *minpack_csminwel_ps) +{ + //Returns the old pointer in order to preserve the previous value. + TSminpack *tmp_ps = MINPACK_CSMINWEL_PS; + MINPACK_CSMINWEL_PS = minpack_csminwel_ps; + return (tmp_ps); +} +static double minobj_csminwelwrap(double *x, int n, double **dummy1, int *dummy2) +{ + if (!MINPACK_CSMINWEL_PS || !MINPACK_CSMINWEL_PS->minobj) fn_DisplayError(".../optpackage.c/minobj_csminwelwrap(): (1) MINPACK_CSMINWEL_PS must be created and (2) there exists an objective function assigned to MINPACK_CSMINWEL_PS->minobj"); + // if (MINPACK_CSMINWEL_PS->x_dv->n != n) fn_DisplayError(".../optpackage.c/minobj_csminwelwrap(): Length of passing vector must match minpack_ps->x_dv"); + MINPACK_CSMINWEL_PS->xtemp_dv->v = x; + return (MINPACK_CSMINWEL_PS->minobj(MINPACK_CSMINWEL_PS)); //This function is specified in the main program. +} +//--- +static int mingrad_csminwelwrap(double *x, int n, double *g, double **dummy1, int *dummy2) +{ + if (!MINPACK_CSMINWEL_PS || !MINPACK_CSMINWEL_PS->mingrad) fn_DisplayError(".../optpackage.c/mingrad_csminwelwrap(): (1) MINPACK_CSMINWEL_PS must be created and (2) there exists an objective function assigned to MINPACK_CSMINWEL_PS->minobj"); + // if (MINPACK_CSMINWEL_PS->x_dv->n != n) fn_DisplayError(".../optpackage.c/mingrad_csminwelwrap(): Length of passing vector must match minpack_ps->x_dv"); + MINPACK_CSMINWEL_PS->xtemp_dv->v = x; + MINPACK_CSMINWEL_PS->gtemp_dv->v = g; + //>>>>>>>> Inside the following function, make sure to set MINPACK_CSMINWEL_PS->etc_csminwel_ps->badg = 0; //1: numerical gradient will be used. + MINPACK_CSMINWEL_PS->mingrad(MINPACK_CSMINWEL_PS); + //<<<<<<<< + + return (0); +} +//--------------------------------- +// End: This wrapper function makes it conformable to the call of the csminwel package. +//--------------------------------- + + +//---------------------------------------------------------------// +//--- New ways to set up the minimization problems. 03/10/06. ---// +//---------------------------------------------------------------// +//------- Step 1. ------- +//=== +//=== Using blockwise csminwel minimization package. +struct TSargs_blockcsminwel_tag *CreateTSargs_blockcsminwel(FILE *fptr_input1) +{ + //If fptr_input1==NULL or no no values supplied when fptr_input1 != NULL, default values are taken. + + int nvec; + struct TSargs_blockcsminwel_tag *args_blockcsminwel_ps = tzMalloc(1, struct TSargs_blockcsminwel_tag); + + + //=== Reads doubles. + if ( !fptr_input1 || !fn_SetFilePosition(fptr_input1, "//== criterion_start ==//") || fscanf(fptr_input1, " %lf ", &args_blockcsminwel_ps->criterion_start) != 1 ) + args_blockcsminwel_ps->criterion_start = 1.0e-3; //Default. + if ( !fptr_input1 || !fn_SetFilePosition(fptr_input1, "//== criterion_end ==//") || fscanf(fptr_input1, " %lf ", &args_blockcsminwel_ps->criterion_end) != 1 ) + args_blockcsminwel_ps->criterion_end = 1.0e-6; //Default. + if ( !fptr_input1 || !fn_SetFilePosition(fptr_input1, "//== criterion_increment ==//") || fscanf(fptr_input1, " %lf ", &args_blockcsminwel_ps->criterion_increment) != 1 ) + args_blockcsminwel_ps->criterion_increment = 0.1; //Default. + if ( !fptr_input1 || !fn_SetFilePosition(fptr_input1, "//== max_iterations_increment ==//") || fscanf(fptr_input1, " %lf ", &args_blockcsminwel_ps->max_iterations_increment) != 1 ) + args_blockcsminwel_ps->max_iterations_increment = 1.5; //Default. + if ( !fptr_input1 || !fn_SetFilePosition(fptr_input1, "//== ini_h_scale ==//") || fscanf(fptr_input1, " %lf ", &args_blockcsminwel_ps->ini_h_scale) != 1 ) + args_blockcsminwel_ps->ini_h_scale = 5.0e-4; //Default. + if ( !fptr_input1 || !fn_SetFilePosition(fptr_input1, "//== gradstps_csminwel_const ==//") || fscanf(fptr_input1, " %lf ", &args_blockcsminwel_ps->gradstps_csminwel_const) != 1 ) + args_blockcsminwel_ps->gradstps_csminwel_const = 1.0e-4; //Default. + + //=== Reads integers. + if ( !fptr_input1 || !fn_SetFilePosition(fptr_input1, "//== max_iterations_start ==//") || fscanf(fptr_input1, " %d ", &args_blockcsminwel_ps->max_iterations_start) != 1 ) + args_blockcsminwel_ps->max_iterations_start = 50; //Default. + if ( !fptr_input1 || !fn_SetFilePosition(fptr_input1, "//== max_block_iterations ==//") || fscanf(fptr_input1, " %d ", &args_blockcsminwel_ps->max_block_iterations) != 1 ) + args_blockcsminwel_ps->max_block_iterations = 70; //Default. + + //=== Reads vectors. + if (fptr_input1 && fn_SetFilePosition(fptr_input1, "//== gradstps_csminwel_dv ==//")) + { + if ( fscanf(fptr_input1, " %d ", &nvec) != 1) + fn_DisplayError(".../fwz_comfuns.c/CreateTSinput(): check the first integer in the first row below the line //== gradstps_csminwel_dv ==// in the input data file"); + args_blockcsminwel_ps->gradstps_csminwel_dv = CreateVector_lf(nvec); + if ( !ReadVector_lf(fptr_input1, args_blockcsminwel_ps->gradstps_csminwel_dv) ) + fn_DisplayError(".../fwz_comfuns.c/CreateTSinput(): check the data matrix or vector after the first row below the line //== gradstps_csminwel_dv ==// in the input data file"); + args_blockcsminwel_ps->gradstps_csminwel_dv->flag = V_DEF; + } + else //Default (hard-coded). fn_DisplayError(".../fwz_comfuns.c/CreateTSinput(): the line with //== gradstps_csminwel_dv ==// in the input data file does not exist"); + { + args_blockcsminwel_ps->gradstps_csminwel_dv = CreateVector_lf(3); + args_blockcsminwel_ps->gradstps_csminwel_dv->v[0] = 1.0e-02; + args_blockcsminwel_ps->gradstps_csminwel_dv->v[1] = 1.0e-03; + args_blockcsminwel_ps->gradstps_csminwel_dv->v[2] = 1.0e-03; + args_blockcsminwel_ps->gradstps_csminwel_dv->flag = V_DEF; + } + + + args_blockcsminwel_ps->fptr_input1 = fptr_input1; + + return (args_blockcsminwel_ps); +} +//--- +struct TSargs_blockcsminwel_tag *DestroyTSargs_blockcsminwel(struct TSargs_blockcsminwel_tag *args_blockcsminwel) +{ + if (args_blockcsminwel) + { + //=== + free(args_blockcsminwel); + return ((struct TSargs_blockcsminwel_tag *)NULL); + } + else + return (args_blockcsminwel); +} +//=== +//=== Sets up a project-specific structure. +struct TSetc_minproj_tag *CreateTSetc_minproj(struct TStateModel_tag **smodel_pps, TFDestroyTStateModel *DestroyTStateModel_func, + struct TSargs_blockcsminwel_tag **args_blockcsminwel_pps, struct TSargs_blockcsminwel_tag *(*DestroyTSargs_blockcsminwel)(struct TSargs_blockcsminwel_tag *)) +{ + struct TSetc_minproj_tag *etc_minproj_ps = tzMalloc(1, struct TSetc_minproj_tag); + + //=== Initialization. + etc_minproj_ps->smodel_ps = *smodel_pps; + etc_minproj_ps->DestroyTStateModel = DestroyTStateModel_func; + if (DestroyTStateModel_func) *smodel_pps = (struct TStateModel_tag *)NULL; + //If destroy function makes this structure responsible to free memory of the passing pointer, reset this passing pointer to NULL to avoid double destroying actions and cause memory problem. + // In this case, the original pointer *smodel_pps or smodel_ps is no longer valid, while etc_minproj_ps->smodel_ps. + // Note that we pass **smodel_pps only when we want to use DestroyTStateModel_func and let this structure take over smodel_ps. + // In many other cases, we do not need to pass **smodel_pps, but only *smodel_ps will do. + //+ + etc_minproj_ps->args_blockcsminwel_ps = *args_blockcsminwel_pps; + etc_minproj_ps->DestroyTSargs_blockcsminwel = DestroyTSargs_blockcsminwel; + if (DestroyTSargs_blockcsminwel) *args_blockcsminwel_pps = (struct TSargs_blockcsminwel_tag *)NULL; + //If destroy function makes this structure responsible to free memory of the passing pointer, reset this passing pointer to NULL to avoid double destroying actions and cause memory problem. + + return (etc_minproj_ps); +} +//--- +struct TSetc_minproj_tag *DestroyTSetc_minproj(struct TSetc_minproj_tag *etc_minproj_ps) +{ + if (etc_minproj_ps) + { + if (etc_minproj_ps->DestroyTStateModel) etc_minproj_ps->DestroyTStateModel(etc_minproj_ps->smodel_ps); + //If destroy function is active, destroy it here; ohterwise, it will be destroyed somewhere else. + if (etc_minproj_ps->DestroyTSargs_blockcsminwel) etc_minproj_ps->DestroyTSargs_blockcsminwel(etc_minproj_ps->args_blockcsminwel_ps); + //If destroy function is active, destroy it here; ohterwise, it will be destroyed somewhere else. + + //=== + free(etc_minproj_ps); + return ((struct TSetc_minproj_tag *)NULL); + } + else return (etc_minproj_ps); +} +//------- Step 2. ------- +//$$$$$$ 28/Oct/2007: I commented them out because it'd better left to be the user's function because of +//$$$$$$ (1) constant-parameter case without using DW's functions; +//$$$$$$ (2) allowing us to generate parameters randomly, which depends on the specific model. +//$$$$$$ See lwz_est.c in D:\ZhaData\WorkDisk\LiuWZ\Project2_empirical\EstimationOct07 +//$$$$$$ or ExamplesForC.prn in D:\ZhaData\CommonFiles\C_Examples_DebugTips. +/** +void InitializeForMinproblem(struct TSminpack_tag *minpack_ps, char *filename_sp, TSdvector *gphi_dv, int indxStartValuesForMin) +{ + //Outputs: + // minpack_ps->x_dv and minpack_ps->xtemp_dv: + // The 1st gphi_dv->n elements of x_dv are model parameters (excluding those in the transition matrices). + // The 2nd-part or rest of the elements of x_dv are the free parameters in the transition matrices. + //Inputs: + // gphi_dv: model free parameters (excluding those in the transition matrices); + // indxStartValuesForMin (corresponding to the command option /c in runprog.bat): + // 0: continuing from the last estimated results contained in filename_sp. + // 1: starts from the fixed values for gphi_dv, manually keyed in datainpu_setup.prn. + // 2: randomly or arbitarily selects the initial starting values for the MLE or posterior estimate. + FILE *fptr_sp = NULL; + int _n, _i; + int nqs; + TSdvector xphi_sdv, xqs_sdv; + TSdvector *x_dv = minpack_ps->x_dv; + TSdvector *x0_dv = minpack_ps->x0_dv; + //--- + struct TStateModel_tag *smodel_ps = (struct TStateModel_tag *)((struct TSetc_minproj_tag *)minpack_ps->etc_project_ps)->smodel_ps; + int nfreempars = smodel_ps->routines->pNumberFreeParametersTheta(smodel_ps); + + if ( nfreempars != gphi_dv->n ) + fn_DisplayError("optpackage.c/InitializeForMinproblem(): Input vector gphi_dv must be free model parameters only"); + if ( nqs=NumberFreeParametersQ(smodel_ps) != x_dv->n - nfreempars ) + fn_DisplayError("optpackage.c/InitializeForMinproblem(): Minimization vector must have length equal to # of free model parameters plus # of free transition matrix parameters"); + + xphi_sdv.flag = V_DEF; + xphi_sdv.n = nfreempars; + xphi_sdv.v = x_dv->v; + + xqs_sdv.flag = V_DEF; + xqs_sdv.n = nqs; + xqs_sdv.v = x_dv->v + xphi_sdv.n; + + if (indxStartValuesForMin == 1) + { + CopyVector0(&xphi_sdv, gphi_dv); + ConvertQToFreeParameters(smodel_ps, xqs_sdv.v); //Waggnoer's own function for the transition matrix. + x_dv->flag = V_DEF; + } + else if (!indxStartValuesForMin) + { + fptr_sp = tzFopen(filename_sp,"r"); + rewind(fptr_sp); //Must put the pointer at the beginning of the file. + + for (_n=x_dv->n, _i=0; _i<_n; _i++) + if (fscanf(fptr_sp, " %lf ", x_dv->v+_i) != 1) + { + printf("Error: optpackage.c/InitializeForMinproblem() -- cannot read the number from the file %s. Check the data file", filename_sp); + exit(EXIT_FAILURE); + } + x_dv->flag = V_DEF; + + tzFclose(fptr_sp); + } + else fn_DisplayError("optpackage.c/InitializeForMinproblem(): the case indxStartValuesForMin = 2 has not been programmed yet"); + + + //--- Initial or starting values of the parameters. + CopyVector0(x0_dv, x_dv); + SetupObjectiveFunction(smodel_ps, xphi_sdv.v, xqs_sdv.v, xphi_sdv.v); //Must before using PosteriorObjectiveFunction(); + minpack_ps->fret0 = minpack_ps->fret = PosteriorObjectiveFunction(xphi_sdv.v, xphi_sdv.n); +// minpack_ps->fret0 = minpack_ps->fret = -logOverallPosteriorKernal(smodel_ps, x0_dv); + if (minpack_ps->fret0 >= NEARINFINITY) + { + printf("\nFatal Error:\n"); + printf(" optpackage.c/InitializeForMinproblem(): Bad initialization. All parameters must be in the reasonable range.\n"); +// printf(" optpackage.c/InitializeForMinproblem(): Bad initialization. All parameters must be in the reasonable range.\n" +// " Most likely, the parameters get stuck in the following line in swz2_confuns.c:\n" +// " if ((tmpd1mPhi=1.0-fn_normalcdf(xid * (log(mt-boundthetamt_1) - logdbar))) <= 0.0) logvalue = -NEARINFINITY;\n"); +// exit(EXIT_FAILURE); + } +} +/**/ +//------- Step 3. ------- +#if defined (NEWVERSIONofDW_SWITCH) +void minfinder_blockcsminwel(struct TSminpack_tag *minpack_ps, int indx_findMLE) +{ + //Better version (November 2007) + //Inputs: + // indx_findMLE: 1: find MLE without a prior, 0: find posterior (with a prior). + + //--- Block-csminwel arguments. + struct TSargs_blockcsminwel_tag *args_blockcsminwel_ps = ((struct TSetc_minproj_tag *)minpack_ps->etc_project_ps)->args_blockcsminwel_ps; + //--- DW's Markov-switching structure. + struct TStateModel_tag *smodel_ps = ((struct TSetc_minproj_tag *)minpack_ps->etc_project_ps)->smodel_ps; + //--- TSminpack arguments. + TSdvector *x_dv = minpack_ps->x_dv; + TSdvector *g_dv = minpack_ps->g_dv; + char *filename_printout = minpack_ps->filename_printout; //Printing out the intermediate results of x_dv and g_dv. + double fret = minpack_ps->fret; //Returned value of the objective function. + struct TSetc_csminwel_tag *etc_csminwel_ps = (TSetc_csminwel *)minpack_ps->etc_package_ps; + //--- Blockwise arguments. + int n1, n2; + int _n = x_dv->n; + double *x1_pd, *x2_pd, *g1_pd, *g2_pd; + double fret_last, logvalue; + TSdvector *gradstps_csminwel_dv = args_blockcsminwel_ps->gradstps_csminwel_dv; + //--- Blockwise csminwel intput arguments. + double criterion_start = args_blockcsminwel_ps->criterion_start; + double criterion_end = args_blockcsminwel_ps->criterion_end; + double criterion_increment = args_blockcsminwel_ps->criterion_increment; + int max_iterations_start = args_blockcsminwel_ps->max_iterations_start; + double max_iterations_increment = args_blockcsminwel_ps->max_iterations_increment; + int max_block_iterations = args_blockcsminwel_ps->max_block_iterations; + double ini_h_csminwel = args_blockcsminwel_ps->ini_h_scale; + //+ Other csminwel arguments + int iteration, total_iteration; + int niters, fcount, retcodeh, max_niters; + double crit; + //=== Blockwise and overall memory creations. + TSdmatrix *H1_dm = NULL; + TSdmatrix *H2_dm = NULL; + TSdmatrix *H_dm = NULL; + // + FILE *fptr_interesults = (FILE *)NULL; //Printing intermediate results to a file. + + + + if (!x_dv || !x_dv->flag) fn_DisplayError("swz2_comfuns.c/ minfinder_blockcsminwel(): free parameters x_dv must be initialized"); + + n1 = NumberFreeParametersTheta(smodel_ps); //Number of free model parameters. + n2 = NumberFreeParametersQ(smodel_ps); //Number of free transition matrix elements. + if (_n != (n1 + n2)) fn_DisplayError("optpackage.c/minfinder_blockcsminwel(): total number of free parameters" + " must be equal to number of free model parameters + number of free q's"); + H1_dm = CreateMatrix_lf(n1, n1); + H2_dm = CreateMatrix_lf(n2, n2); + H_dm = CreateMatrix_lf(_n, _n); + // + x1_pd = x_dv->v; + x2_pd = x_dv->v+n1; + g1_pd = g_dv->v; + g2_pd = g_dv->v+n1; + + //---- Refreshing the parameters outside this function. TZ October 2007. + SetupObjectiveFunction(smodel_ps, x1_pd, x2_pd, x_dv->v); + //--- minpack_ps->fret0 has to be initialized using InitializeForMinproblem() in the main function. + logvalue = -( minpack_ps->fret = PosteriorObjectiveFunction(x_dv->v, x_dv->n) ); //Refreshing. logPosterirPdf. DW function. + fprintf(FPTR_OPT, "\n=========== Beginning Blockwise and Overall csminwel Minimizations =======================\nLog Peak Value: %.16e\n", logvalue); + fflush(FPTR_OPT); + + + //======= Minimizing using csminwel ======= + //--- Set up a printout file to record x_dv and g_dv. + csminwel_SetPrintFile(filename_printout); //Set the print-out file outputsp_mle_tag.prn. + for (total_iteration=1, crit=criterion_start, max_niters=max_iterations_start; + crit >= criterion_end; + crit*=criterion_increment, max_niters=(int)(max_niters*max_iterations_increment)) + { + for (iteration=1; iteration <= max_block_iterations; total_iteration++, iteration++) + { + fret_last = fret; + //=== Minimizing the objective function w.r.t. the 1st block of parameters (model parameters). + printf("\nMinimizing user's specific model parameters at iteration %d\n",iteration); + InitializeDiagonalMatrix_lf(H1_dm, ini_h_csminwel); + H1_dm->flag = M_GE | M_SU | M_SL; //Hessian is symmetric. + //+ + SetupObjectiveFunction(smodel_ps, x1_pd, x2_pd, x_dv->v); + GRADSTPS_CSMINWEL = gradstps_csminwel_dv->v[0]; + if (indx_findMLE) + csminwel(MLEObjectiveFunction_csminwel, x1_pd, n1, H1_dm->M, g1_pd, NULL, + &fret, crit, &niters, max_niters, &fcount, &retcodeh, + (double **)NULL, (int *)NULL); + else + csminwel(PosteriorObjectiveFunction_csminwel, x1_pd, n1, H1_dm->M, g1_pd, NULL, + &fret, crit, &niters, max_niters, &fcount, &retcodeh, + (double **)NULL, (int *)NULL); + + ConvertFreeParametersToQ(smodel_ps,x2_pd); + ConvertFreeParametersToTheta(smodel_ps,x1_pd); + + //+ + logvalue = -fret; + fprintf(FPTR_OPT, "\n=========== Block iteration %d for block 1 at total iteration %d =======================\nLog Peak Value: %.16e\n", iteration, total_iteration, logvalue); + fflush(FPTR_OPT); + + + + //=== Minimizing the objective function w.r.t. the 2nd block of parameters (transition matrix). + printf("\nMinimizing transitiona matrix Q at iteration %d\n",iteration); + InitializeDiagonalMatrix_lf(H2_dm, ini_h_csminwel); + H2_dm->flag = M_GE | M_SU | M_SL; //Hessian is symmetric. + //+ + SetupObjectiveFunction(smodel_ps, x2_pd, x2_pd, x_dv->v); + GRADSTPS_CSMINWEL = gradstps_csminwel_dv->v[1]; + if (indx_findMLE) + csminwel(MLEObjectiveFunction_csminwel, x2_pd, n2, H2_dm->M, g2_pd, NULL, + &fret, crit, &niters, max_niters, &fcount, &retcodeh, + (double **)NULL, (int *)NULL); + else + csminwel(PosteriorObjectiveFunction_csminwel, x2_pd, n2, H2_dm->M, g2_pd, NULL, + &fret, crit, &niters, max_niters, &fcount, &retcodeh, + (double **)NULL, (int *)NULL); + + ConvertFreeParametersToQ(smodel_ps,x2_pd); + ConvertFreeParametersToTheta(smodel_ps,x1_pd); + + //+ + logvalue = -fret; + fprintf(FPTR_OPT, "\n=========== Block iteration %d for block 2 at total iteration %d =======================\nLog Peak Value: %.16e\n", iteration, total_iteration, logvalue); + fprintf(FPTR_OPT, "--------Numerical gradient---------\n"); + WriteVector(FPTR_OPT, g_dv, " %0.16e "); + fprintf(FPTR_OPT, "--------Restarting point---------\n"); + WriteVector(FPTR_OPT, x_dv, " %0.16e "); + fflush(FPTR_OPT); + + + if (fabs(fret - fret_last) <= crit) break; + } + + //=== Minimizing the overall likelihood or posterior kernel. + logvalue = -fret; + fprintf(FPTR_OPT,"\n\n=========== Total iteration %d ===========\n",++total_iteration); + fprintf(FPTR_OPT,"Criterion/Max_Numer_Iterations: %le %d\n",crit,max_niters); + fprintf(FPTR_OPT,"Log peak value before overall minimization: %.16e\n", logvalue); + fflush(FPTR_OPT); + //--- + InitializeDiagonalMatrix_lf(H_dm, ini_h_csminwel); + H_dm->flag = M_GE | M_SU | M_SL; //Hessian is symmetric. + //+ + SetupObjectiveFunction(smodel_ps, x_dv->v, x2_pd, x_dv->v); + GRADSTPS_CSMINWEL = gradstps_csminwel_dv->v[2]; + if (indx_findMLE) + csminwel(MLEObjectiveFunction_csminwel, x_dv->v, _n, H_dm->M, g_dv->v, NULL, + &fret, crit, &niters, max_niters, &fcount, &retcodeh, + (double **)NULL, (int *)NULL); + else + csminwel(PosteriorObjectiveFunction_csminwel, x_dv->v, _n, H_dm->M, g_dv->v, NULL, + &fret, crit, &niters, max_niters, &fcount, &retcodeh, + (double **)NULL, (int *)NULL); + + + //--- + logvalue = -fret; + fprintf(FPTR_OPT,"Log peak value after overall minimization: %.16e\n", logvalue); + fprintf(FPTR_OPT, "--------Numerical gradient---------\n"); + WriteVector(FPTR_OPT, g_dv, " %0.16e "); + fprintf(FPTR_OPT, "--------Restarting point---------\n"); + WriteVector(FPTR_OPT, x_dv, " %0.16e "); + fflush(FPTR_OPT); + + //--- Write to the intermediate results file. + if ( !(fptr_interesults = fopen(filename_printout,"w")) ) { + printf("\n\nUnable to open the starting point data file %s in minfinder_blockcsminwel() in optpackage.c!\n", filename_printout); + getchar(); + exit(EXIT_FAILURE); + } + fprintf(fptr_interesults, "========= All blocks are reported here. ========== \n"); + fprintf(fptr_interesults, "--------Numerical gradient---------\n"); + WriteVector(fptr_interesults, g_dv, " %0.16e "); + fprintf(fptr_interesults, "--------Restarting point---------\n"); + WriteVector(fptr_interesults, x_dv, " %0.16e "); + fflush(fptr_interesults); + tzFclose(fptr_interesults); + + + ConvertFreeParametersToQ(smodel_ps,x2_pd); + ConvertFreeParametersToTheta(smodel_ps,x1_pd); + } + + etc_csminwel_ps->niter = niters; //Number of iterations taken by csminwel. + etc_csminwel_ps->fcount = fcount; //Number of function evaluations used by csminwel. + etc_csminwel_ps->retcode = retcodeh; //Return code for the terminating condition. + // 0, normal step (converged). 1, zero gradient (converged). + // 4,2, back and forth adjustment of stepsize didn't finish. + // 3, smallest stepsize still improves too slow. 5, largest step still improves too fast. + // 6, no improvement found. + + DestroyMatrix_lf(H1_dm); + DestroyMatrix_lf(H2_dm); + DestroyMatrix_lf(H_dm); +} +#endif + +//----------------------------------------------------- +// Minimization csminwel for the constant parameter model only. 5/24/04. +//----------------------------------------------------- +//------- Step 2. ------- +//--- 28/Oct/07: This function has NOT been used even for the constant-parameter model. +//--- For examples, see lwz_est.c in D:\ZhaData\WorkDisk\LiuWZ\Project2_empirical\EstimationOct07 +//--- or ExamplesForC.prn under D:\ZhaData\CommonFiles\C_Examples_DebugTips. +/** +void InitializeForMinproblem_const(struct TSminpack_tag *minpack_ps, char *filename_sp, TSdvector *gphi_dv, int indxStartValuesForMin) +{ + //Outputs: + // minpack_ps->x_dv and minpack_ps->xtemp_dv: + // The 1st gphi_dv->n elements of x_dv are model parameters (excluding those in the transition matrices). + // The 2nd-part or rest of the elements of x_dv are the free parameters in the transition matrices. + //Inputs: + // gphi_dv: model free parameters (excluding those in the transition matrices); + // indxStartValuesForMin (corresponding to the command option /c in runprog.bat): + // 0: continuing from the last estimated results contained in filename_sp. + // 1: starts from the fixed values for gphi_dv, manually keyed in datainpu_setup.prn. + // 2: randomly or arbitarily selects the initial starting values for the MLE or posterior estimate. + FILE *fptr_sp = NULL; + int _n, _i; + TSdvector xphi_sdv; + TSdvector *x_dv = minpack_ps->x_dv; + TSdvector *x0_dv = minpack_ps->x0_dv; + //--- + struct TStateModel_tag *smodel_ps = (struct TStateModel_tag *)((struct TSetc_minproj_tag *)minpack_ps->etc_project_ps)->smodel_ps; + int nfreempars = smodel_ps->routines->pNumberFreeParametersTheta(smodel_ps); + + if ( nfreempars != gphi_dv->n ) + fn_DisplayError("optpackage.c/InitializeForMinproblem_const(): Input vector gphi_dv must be free model parameters only"); + + xphi_sdv.flag = V_DEF; + xphi_sdv.n = nfreempars; + xphi_sdv.v = x_dv->v; + + if (indxStartValuesForMin == 1) + { + CopyVector0(&xphi_sdv, gphi_dv); + x_dv->flag = V_DEF; + } + else if (!indxStartValuesForMin) + { + fptr_sp = tzFopen(filename_sp,"r"); + rewind(fptr_sp); //Must put the pointer at the beginning of the file. + + for (_n=x_dv->n, _i=0; _i<_n; _i++) + if (fscanf(fptr_sp, " %lf ", x_dv->v+_i) != 1) + { + printf("Error: optpackage.c/InitializeForMinproblem_const() -- cannot read the number from the file %s. Check the data file", filename_sp); + exit(EXIT_FAILURE); + } + x_dv->flag = V_DEF; + + tzFclose(fptr_sp); + } + else fn_DisplayError("optpackage.c/InitializeForMinproblem_const(): the case indxStartValuesForMin = 2 has not been programmed yet"); + + + //--- Initial or starting values of the parameters. + CopyVector0(x0_dv, x_dv); + //The following line does not work because minpack_ps->xtemp_ps will be used in minneglogpost_const(), which has not be initialized. + //Use instead minpack_ps->fret0 = minpack_ps->fret = logOverallPosteriorKernal_const(smodel_ps, minpack_ps->x0_dv); + //minpack_ps->fret0 = minpack_ps->fret = minpack_ps->minobj(minpack_ps); This will not work because +} +/**/ + +//------- Step 3. ------- +void minfinder(TSminpack *minpack_ps) +{ + TSdvector *x_dv = minpack_ps->x_dv; + //--- For MIN_CSMINWEL only. + TSdmatrix *Hx_dm; + TSetc_csminwel *etc_csminwel_ps; + + if (minpack_ps->package & MIN_CSMINWEL) { + if (!x_dv->flag) fn_DisplayError("optpackage.c/ minfinder(): Parameter x_dv must be initialized"); + else { + //=== BFGS (csminwel) method. + etc_csminwel_ps = (TSetc_csminwel *)minpack_ps->etc_package_ps; + Hx_dm = etc_csminwel_ps->Hx_dm; + //Alternative: Hx_dm = ((TSetc_csminwel *)minpack_ps->etc_package_ps)->Hx_dm; + if (!Hx_dm->flag) { + InitializeDiagonalMatrix_lf(Hx_dm, INI_H_CSMINWEL); + Hx_dm->flag = M_GE | M_SU | M_SL; //Hessian is symmetric. + } + //if (minpack_ps->filename_printout) csminwel_SetPrintFile(minpack_ps->filename_printout); + csminwel_SetPrintFile(minpack_ps->filename_printout); + SetMincsminwelGlobal(minpack_ps); + GRADSTPS_CSMINWEL = etc_csminwel_ps->gradstps_csminwel; + csminwel(minobj_csminwelwrap, x_dv->v, x_dv->n, Hx_dm->M, minpack_ps->g_dv->v, minpack_ps->mingrad ? mingrad_csminwelwrap : NULL, + &minpack_ps->fret, etc_csminwel_ps->crit, &etc_csminwel_ps->niter, etc_csminwel_ps->itmax, + &etc_csminwel_ps->fcount, &etc_csminwel_ps->retcode, (double **)NULL, (int *)NULL); + } + } + else fn_DisplayError("optpackage.c/minfinder(): (1) minpack_ps must be created and (2) I have not got time to specify other minimization packages such as ISML"); +} + + + +//----------------------------------------------------------------------- +// Linearly-constrained IMSL minimization package. +//----------------------------------------------------------------------- +struct TSpackage_imslconlin_tag *CreateTSpackagae_imslconlin(const int npars_tot, const int neqs, const int ncons) +{ + //npars_tot: total number of variables (e.g., all the model variables plus free parameters in transition matrix). + //ncons: total number of constraints (excluding simple bounds) which include the linear equality constraints. + //neqs: number of linear equality constrains. Thus, ncons >= neqs. + //lh_coefs_dv: ncons*npars_tot-by-1 left-hand-side constraint cofficients with the first neqs rows dealing with equality constraints. + //rh_constraints_dv: ncons-by-1 right-hand-side the values for all the constraints. + //lowbounds_dv: npars_tot-by-1 simple lower bounds. + //upperbounds_dv: npars_tot-by-1 simple upper bounds. + //=== + struct TSpackage_imslconlin_tag *package_imslconlin_ps = tzMalloc(1, struct TSpackage_imslconlin_tag); + + if (neqs > ncons || npars_tot<=0) + fn_DisplayError("CreateTSpackage_imslconlin(): make sure (1) # of equality constraints no greater than total # of constraints" + "\t and (2) number of free parameters must be greater than 0"); + package_imslconlin_ps->npars_tot = npars_tot; + package_imslconlin_ps->neqs = neqs; + package_imslconlin_ps->ncons = ncons; + + + if (ncons<=0) + { + package_imslconlin_ps->lh_coefs_dv = NULL; + package_imslconlin_ps->rh_constraints_dv = NULL; + } + else + { + package_imslconlin_ps->lh_coefs_dv = CreateConstantVector_lf(ncons*npars_tot, 0.0); + package_imslconlin_ps->rh_constraints_dv = CreateVector_lf(ncons); + } + package_imslconlin_ps->lowbounds_dv = CreateConstantVector_lf(npars_tot, -BIGREALNUMBER); + package_imslconlin_ps->upperbounds_dv = CreateConstantVector_lf(npars_tot, BIGREALNUMBER); + //- + package_imslconlin_ps->xsaved_dv = CreateVector_lf(package_imslconlin_ps->npars_tot); + XIMSL_DV = CreateVector_lf(package_imslconlin_ps->npars_tot); //Used in ObjFuncForModel_imslconlin() to save the minimized value in case the IMSL quits with a higher value. + + package_imslconlin_ps->crit = CRIT_IMSLCONLIN; + package_imslconlin_ps->itmax = ITMAX_IMSLCONLIN; + + + return (package_imslconlin_ps); +} +//--- +struct TSpackage_imslconlin_tag *DestroyTSpackagae_imslconlin(struct TSpackage_imslconlin_tag *package_imslconlin_ps) +{ + if (package_imslconlin_ps) + { + DestroyVector_lf(package_imslconlin_ps->lh_coefs_dv); + DestroyVector_lf(package_imslconlin_ps->rh_constraints_dv); + DestroyVector_lf(package_imslconlin_ps->lowbounds_dv); + DestroyVector_lf(package_imslconlin_ps->upperbounds_dv); + // + DestroyVector_lf(package_imslconlin_ps->xsaved_dv); + DestroyVector_lf(XIMSL_DV); + + //=== + free(package_imslconlin_ps); + return ((struct TSpackage_imslconlin_tag *)NULL); + } + else return (package_imslconlin_ps); +} +//----------------------------------------------------------------------- +// Using Linearly-constrained IMSL minimization package. +//----------------------------------------------------------------------- +void minfinder_noblockimslconlin(struct TSpackage_imslconlin_tag *package_imslconlin_ps, struct TSminpack_tag *minpack_ps, char *filename_printout, int ntheta) +{ + //ntheta: number of free model parameters (NOT including free transition matrix Q parameters). + //filename_printout: the file that stores the intermediate results. + + //--- Model or project specific structure. + struct TStateModel_tag *smodel_ps = ((struct TSetc_minproj_tag *)minpack_ps->etc_project_ps)->smodel_ps; + //--- + TSdvector *x_dv = minpack_ps->x_dv; + TSdvector *g_dv = minpack_ps->g_dv; + double *x1_pd, *x2_pd; + //=== + TSdvector *xguess_dv = CreateVector_lf(x_dv->n); + + x1_pd = x_dv->v; + x2_pd = x_dv->v + ntheta; //In the constant parameter model, this will point to invalid, + // but will be taken care of automatically by DW's function ConvertFreeParametersToQ(). + + CopyVector0(xguess_dv, x_dv); + + + //======= IMSL linearly-constrained optimization, which makes sure that the boundary condition is met. + imslconlin_SetPrintFile(filename_printout); //Set the print-out file outputsp_min_tag.prn. + printf("\n\n======= Starting the IMSL constrained optimization======= \n\n"); + fflush(stdout); + //====== The following linearly-constrained minimization works well for this kind of model but has a bugger of returning a higher value of the objective function. + CopyVector0(XIMSL_DV, x_dv); //This is absolutely necessary because once imsl_d_min_con_gen_lin() is called, x_dv will be + // changed before ObjFuncForModel_imslconlin() is evaluated. It is possible that x_dv is changed + // so much that bad objective is returned and thus XIMSL_DV would be bad from the start, thus + // giving 1.eE+3000 from beginning to end. + GLB_FVALMIN = -LogPosterior_StatesIntegratedOut(smodel_ps); + CopyVector0(package_imslconlin_ps->xsaved_dv, XIMSL_DV); + //+ + SetModelGlobalForIMSLconlin(smodel_ps); + if (imsl_d_min_con_gen_lin(ObjFuncForModel_imslconlin, x_dv->n, package_imslconlin_ps->ncons, package_imslconlin_ps->neqs, + package_imslconlin_ps->ncons ? package_imslconlin_ps->lh_coefs_dv->v : NULL, + package_imslconlin_ps->ncons ? package_imslconlin_ps->rh_constraints_dv->v : NULL, + package_imslconlin_ps->lowbounds_dv->v, package_imslconlin_ps->upperbounds_dv->v, + IMSL_XGUESS, xguess_dv->v, IMSL_GRADIENT, gradcd_imslconlin, + IMSL_MAX_FCN, package_imslconlin_ps->itmax, IMSL_OBJ, &minpack_ps->fret, + IMSL_TOLERANCE, package_imslconlin_ps->crit, IMSL_RETURN_USER, x_dv->v, 0)) + { + printf("\nFinished: IMSL linearly-constrained optimization is successfully finished with the value of obj. fun.: %.16e\n", minpack_ps->fret); + } + else printf("\nWarning: IMSL linearly-constrained optimization fails, so the results from csminwel and congramin are used.\n"); + printf("\n===Ending the IMSL constrained optimization===\n"); + + //=== Printing out messages indicating that IMSL has bugs. + if (minpack_ps->fret > GLB_FVALMIN) + { + //IMSL linearly-constrained optimization returns a higher obj. func. (a bug). + printf("\n----------IMSL linearly-constrained minimization finished but with a higher objective function value!----------\n"); + printf("The improperly-returned value is %.10f while the lowest value of the objective function is %.16e.\n\n", minpack_ps->fret, GLB_FVALMIN); + fflush(stdout); + fprintf(FPTR_DEBUG, "\n----------IMSL linearly-constrained minimization finished but with a higher objective function value!----------\n"); + fprintf(FPTR_DEBUG, "The improperly-returned value is %.16e while the lowest value of the objective function is %.16e.\n\n", minpack_ps->fret, GLB_FVALMIN); + fflush(FPTR_DEBUG); + } + + ConvertFreeParametersToQ(smodel_ps,x2_pd); + //DW's function, which takes care of the degenerate case where x2_pd points to an + // invalid place as in the constant parameter case. + ConvertFreeParametersToTheta(smodel_ps,x1_pd); //DW's function, which calls TZ's function. So essentially it's TZ's function. + + //Saved the last best results in case the IMSL quits with a bug. + CopyVector0(package_imslconlin_ps->xsaved_dv, XIMSL_DV); + + + //=== + DestroyVector_lf(xguess_dv); +} +//=== +static struct TStateModel_tag *SMODEL_PS = NULL; //Minimization to find the MLE or posterior peak. +static struct TStateModel_tag *SetModelGlobalForIMSLconlin(struct TStateModel_tag *smodel_ps) +{ + //Returns the old pointer in order to preserve the previous value. + struct TStateModel_tag *tmp_ps = SMODEL_PS; + SMODEL_PS = smodel_ps; + return (tmp_ps); +} +static void ObjFuncForModel_imslconlin(int d_x0, double *x0_p, double *fret_p) +{ + TSdvector x0_sdv; + // + FILE *fptr_startingpoint_vec = NULL; + static int ncnt_fevals = -1; + + // printf("\n----- Entering the objective function. ------"); + // fflush(stdout); + x0_sdv.v = x0_p; + x0_sdv.n = d_x0; + x0_sdv.flag = V_DEF; + + *fret_p = -opt_logOverallPosteriorKernal(SMODEL_PS, &x0_sdv); + if ( GLB_DISPLAY) { + printf("\nValue of objective function at the %dth evaluation: %.16e\n", ++ncnt_fevals, *fret_p); + fflush(stdout); + } + if (*fret_p < GLB_FVALMIN) { + //=== Resets GLB_FVALMIN at *fret_p and then prints the intermediate point to a file. + fptr_startingpoint_vec = tzFopen(filename_sp_vec_minproj,"w"); + fprintf(fptr_startingpoint_vec, "================= Output from IMSC linear constrained optimization ====================\n"); + fprintf(fptr_startingpoint_vec, "IMSL: Value of objective miminization function at the %dth iteration: %.15f\n", ncnt_fevals, GLB_FVALMIN=*fret_p); + fprintf(fptr_startingpoint_vec, "--------Restarting point---------\n"); + WriteVector(fptr_startingpoint_vec, &x0_sdv, " %0.16e "); + CopyVector0(XIMSL_DV, &x0_sdv); //Saved in case the IMSL quits with a bug. + //=== Must print this results because imsl_d_min_con_gen_lin() has a bug and quits with a higher value. The printed-out results in the debug file may be used for imsl_d_min_con_nonlin() to continue. + fprintf(FPTR_DEBUG, "\nIMSL: Value of objective miminization function at the %dth iteration: %.15f\n", ncnt_fevals, GLB_FVALMIN=*fret_p); + fprintf(FPTR_DEBUG, "--------Restarting point---------\n"); + WriteVector(FPTR_DEBUG, &x0_sdv, " %0.16e "); + fflush(FPTR_DEBUG); + } + + // printf("\n----- Leaving the objective function. ------\n"); + // fflush(stdout); + + tzFclose(fptr_startingpoint_vec); +} +//------------------------ +// Overall posterior kernal for calling Waggoner's regime-switching procedure. +//------------------------ +static double opt_logOverallPosteriorKernal(struct TStateModel_tag *smodel_ps, TSdvector *xchange_dv) +{ + double *x1_pd, *x2_pd; + + x1_pd = xchange_dv->v; + x2_pd = xchange_dv->v + NumberFreeParametersTheta(smodel_ps); + //Note that NumberFreeParametersTheta() is DW's function, which points to TZ's function. + //In the constant parameter model, this will point to invalid, + // but will be taken care of automatically by DW's function ConvertFreeParametersToQ(). + + //======= This is a must step to refresh the value at the new point. ======= + ConvertFreeParametersToTheta(smodel_ps, x1_pd); //Waggoner's function, which calls TZ's Convertphi2*(). + ConvertFreeParametersToQ(smodel_ps, x2_pd); //Waggoner's function, which automatically takes care of the constant-parameter situition + ThetaChanged(smodel_ps); //DW's function, which will also call my function to set a flag for refreshing everything under these new parameters. + if (1) //Posterior function. + return ( LogPosterior_StatesIntegratedOut(smodel_ps) ); //DW's function. + else //Likelihood (with no prior) + return ( LogLikelihood_StatesIntegratedOut(smodel_ps) ); //DW's function. +} +//--- +static void imslconlin_SetPrintFile(char *filename) { + if (!filename) sprintf(filename_sp_vec_minproj, "outdata5imslconlin.prn"); //Default filename. + else if (STRLEN-1 < strlen(filename)) fn_DisplayError(".../optpackage.c: the allocated length STRLEN for filename_sp_vec_minproj is too short. Must increase the string length"); + else strcpy(filename_sp_vec_minproj, filename); +} +//--- +static void gradcd_imslconlin(int n, double *x, double *g) +{ + //Outputs: + // g: the gradient n-by-1 g (no need to be initialized). + //Inputs: + // x: the vector point at which the gradient is evaluated. No change in the end although will be added or + // substracted by dh during the function (but in the end the original value will be put back). + // n: the dimension of g or x. + //int _i; + FILE *fptr_startingpoint_vec = NULL; + + // printf("\n=== Entering the gradient function. ===\n"); + // fflush(stdout); + GLB_DISPLAY = 0; //This guarantees that the objective function printouts will not show when the gradient is computed. + gradcd_gen(g, x, n, ObjFuncForModel_congrad, (double *)NULL, ObjFuncForModel_congrad(x, n)); + + //=== Prints the intermediate gradient to a file. + // fptr_startingpoint_vec = tzFopen(filename_sp_vec_minproj,"r"); + // fprintf(fptr_startingpoint_vec, "--------Numerical gradient---------\n"); + // for (_i=0; _i<n; _i++) fprintf(fptr_startingpoint_vec, " %0.16e ", g[_i]); + // tzFclose(fptr_startingpoint_vec); + + GLB_DISPLAY = 1; + // printf("\n=== Leaving the gradient function. ===\n"); + // fflush(stdout); +} +//--- For conjugate gradient minimization as well. +static double ObjFuncForModel_congrad(double *x0_p, int d_x0) +{ + TSdvector x0_sdv; + x0_sdv.v = x0_p; + x0_sdv.n = d_x0; + x0_sdv.flag = V_DEF; + + return ( -opt_logOverallPosteriorKernal(SMODEL_PS, &x0_sdv) ); +} + + + + + + + +//----------------------------------------------------------------------- +// Conjugate gradient method I minimization package. +//----------------------------------------------------------------------- +struct TSpackage_congrad1_tag *CreateTSpackage_congrad1(void) +{ + //=== + struct TSpackage_congrad1_tag *package_congrad1_ps = tzMalloc(1, struct TSpackage_congrad1_tag); + + package_congrad1_ps->crit = CRIT_CONGRAD1; + package_congrad1_ps->itmax = ITMAX_CONGRAD1; + + return (package_congrad1_ps); +} +//--- +struct TSpackage_congrad1_tag *DestroyTSpackage_congrad1(struct TSpackage_congrad1_tag *package_congrad1_ps) +{ + if (package_congrad1_ps) + { + //=== + free(package_congrad1_ps); + return ((struct TSpackage_congrad1_tag *)NULL); + } + else return (package_congrad1_ps); +} + + +/** +static void imslconlin_gradcd(int n, double *x, double *g) { + //Outputs: + // g: the gradient n-by-1 g (no need to be initialized). + //Inputs: + // x: the vector point at which the gradient is evaluated. No change in the end although will be added or substracted by dh during the function (but in the end the original value will be put back). + // n: the dimension of g or x. + int _i; + + // printf("\n=== Entering the gradient function. ===\n"); + // fflush(stdout); + GLB_DISPLAY = 0; //This guarantees so that the objective function printouts will not show when the gradient is computed. + gradcd_gen(g, x, n, congrad_ObjFuncForTVBVAR, (double *)NULL, congrad_ObjFuncForTVBVAR(x, n)); + //=== Prints the intermediate gradient to a file. + fptr_startingpoint_grad = tzFopen(filename_spgrad,"w"); + fprintf(fptr_startingpoint_grad, "--------Numerical gradient---------\n"); + for (_i=0; _i<n; _i++) fprintf(fptr_startingpoint_grad, " %0.16e ", g[_i]); + tzFclose(fptr_startingpoint_grad); + GLB_DISPLAY = 1; + // printf("\n=== Leaving the gradient function. ===\n"); + // fflush(stdout); +} +/**/ + + + +/** + //=== Conjugate gradient method, which works too slowly but is reliable. Thus, it is used to finish it up. + congradmin_SetPrintFile(filename_spvec); + frprmn(x0_dv->v, x0_dv->n, &niter, &fret, congrad_ObjFuncForTVBVAR, gradcd_gen, &ftol, &itmax, (double *)NULL, (int *)NULL, (double *)NULL); + + +void frprmn(double p[], int n, int *iter, double *fret, + double (*func)(double [], int), void (*dfunc)(double [], double [], int, double (*func)(double [], int), double *, double), + double *ftol_p, int *itmax_p, double *tol_brent_p, int *itmax_brent_p, double *grdh_p) { + //Outputs: + // p[0, ..., n-1]: the location of the minimum if it converges, which replaces the starting value. + // iter: pointer to the number of iterations that were performed. + // fret: pointer to the minimum value of the function. + //Inputs: + // p[0, ..., n-1]: a starting point for the minimization. + // n: the dimension of p. + // ftol_p: pointer to the convergence tolerance on the objective function value. Default: 1.0e-4 if NULL. + // itmax_p: pointer to the maximum number of iterations in the main minimization program frprmn(). Default: 2000 if NULL. + // tol_brent_p: pointer to the convergence tolerance for the line minimization in brent(). Default: 2.0e-4 if NULL. + // itmax_brent_p: pointer to the maximum number of iterations for the line minimization in brent(). Default: 100 if NULL. + // grdh: pointer to the user's specified step size for a numerical gradient. If NULL, dfunc() (i.e., gradcd_gen()) will select grdh automatically. + // func(): the objective function. + // dfunc(): the gradient function computing the numerical gradient. In the form of gradcd_gen() in cstz.c. + + +//------- For csminwel only. ------- +typedef struct TSetc_congrad1_tag { + //=== Optional input arguments, often NOT used, so we set to NULL at this point. + double **args; //k-by-q. + int *dims; //k-by-1; + int _k; + + //=== Mandatory input arguments. + TSdmatrix *Hx_dm; //n-by-n inverse Hessian. Output as well, when csminwel is done. + double crit; //Overall convergence criterion for the function value. + int itmax; //Maximum number of iterations. +// double grdh; //Step size for the numerical gradient if no analytical gradient is available. + + //=== Some reported input arguments. + double ini_h_csminwel; + int indxnumgrad_csminwel; + double gradstps_csminwel; + + + //=== Output arguments. + int badg; //If (badg==0), analytical gradient is used; otherwise, numerical gradient will be produced. + int niter; //Number of iterations taken by csminwel. + int fcount; //Number of function evaluations used by csminwel. + int retcode; //Return code for the terminating condition. + // 0, normal step (converged). 1, zero gradient (converged). + // 4,2, back and forth adjustment of stepsize didn't finish. + // 3, smallest stepsize still improves too slow. 5, largest step still improves too fast. + // 6, no improvement found. +} TSetc_csminwel; + + +/**/ + + + +/** +//------- For IMSL multivariate linearly-constrained minimizaiton package only. ------- +typedef struct TSetc_imslconlin_tag { + //=== Non-trivial constraint arguments, whose arrays will point to the constraints specified in the specific project minpack->etc_project_ps. + int nvars; //Total number of free parameters for the optimaization. + int neqs; //Number of linear equality constrains. Must be no greater than ncons. + int ncons; //Total number of linear equality and non-equality constrains (excluding simple bounds). + double *lh_coefs_pd; //ncons*nvars-by-1. Left-hand coefficients in the linear constrains (excluding simple bounds). + //lh_coefs_pd stacks the neqs rows first, followed by the inequality constraints. + //Set to NULL if ncons=0; + double *rh_constraints_pd; //ncons-by-1. Right-hand constrains in the equality and non-equality constrains (excluding simple bounds). + //Set to NULL if ncons=0; + + //=== Trivial or simple bounds. + double *lowbounds_pd; //nvars-by-1. Simple lower bounds. If a component is unbounded, choose a very negative large value (e.g., -BIGREALNUMBER). + double *upperbounds_pd; //nvars-by-1. Simple upper bounds. If a component is unbounded, choose a very positive large value (e.g., BIGREALNUMBER). + + //=== Other inputs. + int itmax; //Maximum number of iterations. + double crit; //Overall convergence criterion on the first-order conditions. +} TSetc_imslconlin; + + +//----------------------------------------------------------------------- +// Linearly-constrained IMSL minimization package. +//----------------------------------------------------------------------- +static struct TSetc_imslconlin_tag *CreateTSetc_imslconlin(struct TSminpack_tag *minpack_psconst int nvars, const int neqs, const int ncons) +{ + //=== + struct TSetc_imslconlin *etc_imslconlin_ps = tzMalloc(1, struct TSetc_imslconlin_tag); + + if (neqs.ncons) fn_DisplayErrors("optpackage.c/CreateTSetc_imslconlin: make sure # of equality constraints no greater than total # of constraints"); + + + return (etc_imslconlin_ps); +} + +/**/ diff --git a/CFiles/optpackage.h b/CFiles/optpackage.h new file mode 100755 index 0000000..5215390 --- /dev/null +++ b/CFiles/optpackage.h @@ -0,0 +1,497 @@ +/************ 3 steps to find minimization solution. ***************** + * See details at the bottom of this file. + * or lwz_est.c in D:\ZhaData\WorkDisk\LiuWZ\Project2_empirical\EstimationOct07 + * or ExamplesForC.prn in D:\ZhaData\CommonFiles\C_Examples_DebugTips + * + * + * 1. minpack_csminwel_ps = CreateTSminpack(); + * 2. InitializeForMinproblem(minpack_csminwel_ps, ..., indxRanIniForMin); + * //This is a local, project-specific function that initializes minpack_csminwel_ps->x_dv (note, NOT xtemp_dv) + * // according to indxStartValuesForMin. + * 3. minfinder(minpack_csminwel_ps); +/*********************************************************************/ + + +#ifndef __OPTPACKAGE_H__ +#define __OPTPACKAGE_H__ + +#include "tzmatlab.h" +#include "csminwel.h" +#include "congradmin.h" +#include "fn_filesetup.h" //fn_SetFilePosition(), etc. +#include "mathlib.h" //CopyVector0(), etc. +#include "switch_opt.h" //DW's optimization routines for Markov-switching models. +#include "cstz.h" //Used for gradcd_gen() only in the IMSL linear constrainted problem. + +//-------------- Attributes for selecting optimization packages. -------------- +#define MIN_DEFAULT 0 //0 or NULL: default or no minimization package. +#define MIN_CSMINWEL 0x0001 //1: csminwel unconstrained minimization package. +#define MIN_IMSL 0x0002 //2: IMSL unconstrained minimization package. +#define MIN_IMSL_LNCONS 0x0004 //4: IMSL linearly constrained minimization package. +#define MIN_IMSL_NLNCONS 0x0008 //8: IMSL nonlinearly constrained minimization package. +#define MIN_CONGRADI 0x0010 //16: unconstrained conjugate gradient minimization method 1. Polak-Ribiere conjugate gradient method without using derivative information in performing the line minimization. +#define MIN_CONGRADII 0x0020 //2*16=32: unconstrained conjugate gradient minimization method 2. NOT available yet! Pletcher-Reeves conjugate gradient method using derivative information in performing the line minimization. +//#define MIN_CONGRADII 0x0040 //4*16=2^6: unconstrained conjugate gradient minimization method 2. +//#define MIN_CONGRADII 0x0080 //8*16=2^7: unconstrained conjugate gradient minimization method 2. +//#define MIN_CONGRADII 0x0100 //16^2=2^8: unconstrained conjugate gradient minimization method 2. + + +//-------------- Minimization package: unconstrained BFGS csminwel. -------------- +//--- The following three macros will be void if the input data file specifies the values of these macros. +//--- The following three are used for the constant-parameter model only. +#define CRIT_CSMINWEL 1.0e-09 //1.5e-08 (for monthly TVBVAR) //Overall convergence criterion for the function value. +#define ITMAX_CSMINWEL 100000 //Maximum number of iterations. +#define INI_H_CSMINWEL 1.0e-005 //Initial value for the diagonal of inverse Hessian in the quasi-Newton search. + //1.0e-05 (sometimes used for SargentWZ USinflation project I) + //5.0e-04 (for monthly TVBAR) +//--- The following macros are used in csminwel.c. Have not got time to make them void by input values. +#define INDXNUMGRAD_CSMINWEL 2 //Index for choosing the numerical gradient. 1, forward difference; 2, central difference. + //central difference method is twice as slower as forward difference. + + +//-------------- Minimization package: linearly-nconstrained IMSL. -------------- +#define CRIT_IMSLCONLIN 1.0e-09 //Overall convergence criterion on the first-order conditions. +#define ITMAX_IMSLCONLIN 100000 //Maximum number of iterations. + +//-------------- Minimization package: conjugate gradient method I. -------------- +#define CRIT_CONGRAD1 1.0e-09 //Overall convergence criterion on the first-order conditions. +#define ITMAX_CONGRAD1 100000 //Maximum number of iterations. + + +//struct TSminpack_tag; + +// extern struct TSminpack_tag *MINPACK_PS; + + +//typedef void TFminfinder(struct TSminpack_tag *, const int ipackage); //If ipackage = MIN_CWMINWEL, uses csminwel; etc. +//int n, double *x_ptr, double g_ptr); //, void *mingrad_etc_ptr); +//typedef void TFmingrad_imsl(struct TSminpack_tag *); //NOT used yet. +//typedef void TFmingrad(void); //int n, double *x_ptr, double g_ptr); //, void *mingrad_etc_ptr); + +//====================================================== +// Old way of using cwminwel. No longer used in my new code. 11/01/05. +//====================================================== +//------- For unconstrained BFGS csminwel only. ------- +typedef struct TSetc_csminwel_tag { + //=== Optional input arguments (originally set up by Iskander), often or no longer NOT used, so we set to NULL at this point. + double **args; //k-by-q. + int *dims; //k-by-1; + int _k; + + //=== Mandatory input arguments. + TSdmatrix *Hx_dm; //n-by-n inverse Hessian. Output as well, when csminwel is done. + double crit; //Overall convergence criterion for the function value. + int itmax; //Maximum number of iterations. + + //=== Some reported input arguments. + double ini_h_csminwel; + int indxnumgrad_csminwel; + double gradstps_csminwel; //Step size for the numerical gradient if no analytical gradient is available. + + + //=== Output arguments. + int badg; //If (badg==0), analytical gradient is used; otherwise, numerical gradient will be produced. + int niter; //Number of iterations taken by csminwel. + int fcount; //Number of function evaluations used by csminwel. + int retcode; //Return code for the terminating condition. + // 0, normal step (converged). 1, zero gradient (converged). + // 4,2, back and forth adjustment of stepsize didn't finish. + // 3, smallest stepsize still improves too slow. 5, largest step still improves too fast. + // 6, no improvement found. +} TSetc_csminwel; + + +//============================================================= +// New ways of making optimization packages. +//============================================================= +typedef struct TSminpack_tag { + //=== Input arguments. + int package; //Minimization package or routine. + TSdvector *x_dv; //n-by-1 of estimated parameters. + TSdvector *g_dv; //n-by-1 of gradient. When no analytical gradient is provided, it returns the numerical one. + //$$$$ The x_dv and g_dv are only used minfinder(). In the wrapper function like minobj_csminwelwrap(), we must + //$$$$ use xtemp_dv and gtemp_dv to be repointed to the temporary array created in csminwel() itself. See below. + + TSdvector *xtemp_dv; //$$$$Used within the minimization problem. + TSdvector *gtemp_dv; //$$$$Used within the minimization problem. + //$$$$WARNING: Note the vector xtemp_dv->v or gtemp_dv-v itself is not allocated memory, but only the POINTER. + //$$$$ Within the minimization routine like csminwel(), the temporary array x enters as the argument in + //$$$$ the objective function to compare with other values. If we use minpack_ps->x_dv->v = x + //$$$$ in a wrapper function like minobj_csminwelwrap() where x is a temporay array in csminwel(), + //$$$$ this tempoary array (e.g., x[0] in csminwel()) within the csminwel minimization routine + //$$$$ will be freed after the csminwel minimization is done. Consequently, minpack_ps->x_dv-v, which + //$$$$ which was re-pointed to this tempoary array, will freed as well. Thus, no minimization results + //$$$$ would be stored and trying to access to minpack_ps->x_dv would cause memory leak. + //$$$$ We don't need, however, to create another temporary pointer within the objective function itself, + //$$$$ but we must use minpack_ps->xtemp_dv for a *wrapper* function instead and at the end of + //$$$$ minimization, minpack_ps->x_dv will have the value of minpack_ps->xtemp_dv, which is automatically + //$$$$ taken care of by csminwel with the lines such as + //$$$$ memcpy(xh,x[3],n*sizeof(double)); + //$$$$ where xh and minpack_ps->x_dv->v point to the same memory space. + + TSdvector *x0_dv; //n-by-1 of initial or starting values of the estimated parameters. + + + //--- Created here. Contains csminwel arguments iter, retcodeh, etc. or those that are essential to minimization package. + void *etc_package_ps; + + //--- Created outside of this structure. Including, say, csminwel input arguments such as convergence criteria + //--- or block-wise csminwel input arguments. + void *etc_project_ps; + void *(*DestroyTSetc_project)(void *); + //--- Optional. + char *filename_printout; + + //--- Minimization function for objective function. + //--- May *NOT* be needed for swithcing model because DW's switch_opt.c takes care of things. + double (*minobj)(struct TSminpack_tag *); ////From the input argument of CreateTSminpack(). + /*** This function is used only for the constant-parameter case, NOT for DW's Markov-swtiching case. ***/ + //--- Optional: Minimization function for analytical gradient. Often NOT available. + void (*mingrad)(struct TSminpack_tag *); //From the input argument of CreateTSminpack(). + + //=== Output arguments. + double fret; //Returned value of the objective function. + double fret0; //Returned value of the objective function at the initial or starting values x0. + +} TSminpack; + +typedef double TFminobj(struct TSminpack_tag *); //int n, double *x_ptr); //, void *minobj_etc_ptr); +typedef void TFmingrad(struct TSminpack_tag *); +typedef void *TFmindestroy_etcproject(void *); +typedef void TFSetPrintFile(char *); + +//======= Function prototypes. =======// +TSminpack *CreateTSminpack(TFminobj *minobj_func, void **etc_project_pps, TFmindestroy_etcproject *etcproject_func, TFmingrad *mingrad_func, char *filename_printout, const int n, const int package); +TSminpack *DestroyTSminpack(TSminpack *); + + +//=== Used for the constant-parameter model. +//--- 28/Oct/07: The function InitializeForMinproblem_const() has not been used even for the constant-parameter model. +//--- For examples, see lwz_est.c in D:\ZhaData\WorkDisk\LiuWZ\Project2_empirical\EstimationOct07 +//--- or ExamplesForC.prn under D:\ZhaData\CommonFiles\C_Examples_DebugTips. +//NOT used: void InitializeForMinproblem_const(struct TSminpack_tag *minpack_ps, char *filename_sp, TSdvector *gphi_dv, int indxStartValuesForMin); +//--- +void minfinder(TSminpack *minpack_ps); + + +//------------------------------------------------------------------------------// +//---------- New ways of making optimization packages. 03/10/06. -------// +//------------------------------------------------------------------------------// +//================ For the csminwel minimization problem. ================// +//=== Step 1. +typedef struct TSargs_blockcsminwel_tag +{ + //Arguments for blockwise minimization. + + //=== Within the block: sequence of convergence criteria. + double criterion_start; //Default: 1.0e-3; + double criterion_end; //Default: 1.0e-6; + double criterion_increment; //Default: 0.1; + int max_iterations_start; //Default: 50; Max # of iterations for csminwel. The starting value is small because criterion_start + // is coarse at the start. As the convergence criterion is getting tighter, the max # of + // iteration increases as it is multiplied by max_iterations_increment. + double max_iterations_increment; //Default: 2.0; Used to multiply the max # of iterations in csminwel as the convergence + // criterion tightens. + double ini_h_scale; //Default: 5.0e-4; 1.0e-05 (sometimes used for SargentWZ USinflation project I) + // 5.0e-04 (for monthly TVBAR) + //=== Outside the blocks. + int max_block_iterations; //Default: 100; + + //------------------------------------------------------------ + //Step size for numerical gradient only when the value of x is less than 1.0 in absolute value. + //If abs(x)>1.0, the step size is GRADSTPS_CSMINWEL*x. + // + //For the time-varying-parameter model, GRADSTPS_CSMINWEL takes the values of gradstps_csminwel_dv: + // 1st element: gradient step for the model parameters (tends to be large; the default value is 1.0e-02). + // 2nd element: gradient step for the transition probability matrix (tends to be smaller; the default value is 1.0e-03) + // 3rd element: gradient step for all the parameters (tends to be smaller; the default value is 1.0e-03 or 1.0e-04). + //For the constant-parameter model: + // GRADSTPS_CSMINWEL takes the value of gradstps_csminwel_const. The default value is 1.0e-04 (for monthly TBVAR) + //------------------------------------------------------------ + TSdvector *gradstps_csminwel_dv; //3-by-1. For the time-varying-parameter model only. + double gradstps_csminwel_const; //For the constant-parameter model. + + //--- pointer to the input data file that contains all the data on convergence, max iterations, etc. + FILE *fptr_input1; +} TSargs_blockcsminwel; +struct TSargs_blockcsminwel_tag *CreateTSargs_blockcsminwel(FILE *fptr_input1); + //If fptr_input1==NULL or no no values supplied when fptr_input1 != NULL, default values are taken. +struct TSargs_blockcsminwel_tag *DestroyTSargs_blockcsminwel(struct TSargs_blockcsminwel_tag *args_blockcsminwel_ps); +//+ +typedef struct TStateModel_tag *TFDestroyTStateModel(struct TStateModel_tag *); +typedef struct TSetc_minproj_tag +{ + //For optimization of the posterior or likelihood function. + struct TStateModel_tag *smodel_ps; + struct TStateModel_tag *(*DestroyTStateModel)(struct TStateModel_tag *); + // + struct TSargs_blockcsminwel_tag *args_blockcsminwel_ps; + struct TSargs_blockcsminwel_tag *(*DestroyTSargs_blockcsminwel)(struct TSargs_blockcsminwel_tag *); +} TSetc_minproj; +// +struct TSetc_minproj_tag *CreateTSetc_minproj(struct TStateModel_tag **smodel_pps, TFDestroyTStateModel *DestroyTStateModel_func, + struct TSargs_blockcsminwel_tag **args_blockcsminwel_pps, struct TSargs_blockcsminwel_tag *(*DestroyTSargs_blockcsminwel)(struct TSargs_blockcsminwel_tag *)); +struct TSetc_minproj_tag *DestroyTSetc_minproj(struct TSetc_minproj_tag *); +//And creates the following user's function. +//static double minneglogpost(struct TSminpack_tag *minpack_ps); //For the constant-parameter only. +//=== Step 2. Belongs to the user's responsibility because this function must be able to deal with +// (1) constant-parameter case without using DW's functions; +// (2) allowing us to generate parameters randomly, which depends on the specific model. +// See lwz_est.c in D:\ZhaData\WorkDisk\LiuWZ\Project2_empirical\EstimationOct07 +// or ExamplesForC.prn in D:\ZhaData\CommonFiles\C_Examples_DebugTips. +//--- +//void InitializeForMinproblem(struct TSminpack_tag *minpack_ps, char *filename_sp, TSdvector *gphi_dv, int indxStartValuesForMin); +//=== Step 3. +#if defined (NEWVERSIONofDW_SWITCH) +void minfinder_blockcsminwel(struct TSminpack_tag *minpack_ps, int indx_findMLE); //Blockwise minimization. + //indx_findMLE: 1: find MLE without a prior, 0: find posterior (with a prior). +#endif + + + +//================ For IMSL multivariate linearly-constrained minimizaiton package only. ================// +typedef struct TSpackage_imslconlin_tag +{ + //=== Non-simple constraints. + int npars_tot; //Total number of free parameters for the optimaization. + //For example, model free parameters + free transition matrix parameters in the regime-switching case. + int neqs; //Number of equality constraints, excluding simple bound constraints. Must be no greater than ncons. + //IMSL dictates that equality constraints come always BEFORE inequality constrains. + int ncons; //Total number of constrains, including equality and inequality constraints, but excluding simple bounds. + TSdvector *lh_coefs_dv; //ncons*npars_tot-by-1. ALWAYS initialized to be 0.0. + //Left-hand coefficients in the linear constrains (excluding simple bounds). + //IMSL rule: lh_coefs_dv stacks the neqs rows of equality constraints first, followed by the inequality constraints. + //Set to NULL if ncons=0; + TSdvector *rh_constraints_dv; //ncons-by-1. Set to NULL if ncons=0. + //Right-hand constraints in the equality and non-equality constrains (excluding simple bounds). + + + //=== Simple bounds. + TSdvector *lowbounds_dv; //npars_tot-by-1. ALWAYS initialized to -BIGREALNUMBER for thes simple lower bounds. + //If a component is unbounded, choose a very negative large value (e.g., -BIGREALNUMBER). + TSdvector *upperbounds_dv; //npars_tot-by-1. ALWAYS initialized to +BIGREALNUMBER for thes simple lower bounds. + //If a component is unbounded, choose a very positive large value (e.g., BIGREALNUMBER). + + //=== Other output. + TSdvector *xsaved_dv; //npars_tot-by-1. Saved the parameters that give the minimal value of the objective function. + + //=== Other inputs. + double crit; //Overall convergence criterion on the first-order conditions. + int itmax; //Maximum number of iterations. +} TSpackage_imslconlin; +//+ +struct TSpackage_imslconlin_tag *CreateTSpackagae_imslconlin(const int npars_tot, const int neqs, const int ncons); +struct TSpackage_imslconlin_tag *DestroyTSpackagae_imslconlin(struct TSpackage_imslconlin_tag *package_imslconlin_ps); +void minfinder_noblockimslconlin(struct TSpackage_imslconlin_tag *package_imslconlin_ps, struct TSminpack_tag *minpack_ps, char *filename_printout, int ntheta); + + + + + +//================ For conjugate gradient method I only. ================// +typedef struct TSpackage_congrad1_tag +{ + //=== Input arguments. + double crit; //Overall convergence criterion on the function value. + int itmax; //Maximum number of iterations. + + //=== Output arguments. + int niters; //Number of iterations. +} TSpackage_congrad1; +//+ +struct TSpackage_congrad1_tag *CreateTSpackage_congrad1(void); +struct TSpackage_congrad1_tag *DestroyTSpackage_congrad1(struct TSpackage_congrad1_tag *package_congrad1_ps); + + + + +/** +//------- For unconstrained BFGS csminwel only. ------- +typedef struct TSminpack_csminwel_tag { + //=== Optional input arguments, often NOT used, so we set to NULL at this point. + double **args; //k-by-q. + int *dims; //k-by-1; + int _k; + + //=== Mandatory input arguments. + TSdmatrix *Hx_dm; //n-by-n inverse Hessian. Output as well, when csminwel is done. + double crit; //Overall convergence criterion for the function value. + int itmax; //Maximum number of iterations. +// double grdh; //Step size for the numerical gradient if no analytical gradient is available. + + //=== Initial input arguments. + double ini_h_csminwel; + int indxnumgrad_csminwel; + double gradstps_csminwel; + + + //=== Output arguments. + int badg; //If (badg==0), analytical gradient is used; otherwise, numerical gradient will be produced. + int niter; //Number of iterations taken by csminwel. + int fcount; //Number of function evaluations used by csminwel. + int retcode; //Return code for the terminating condition. + // 0, normal step (converged). 1, zero gradient (converged). + // 4,2, back and forth adjustment of stepsize didn't finish. + // 3, smallest stepsize still improves too slow. 5, largest step still improves too fast. + // 6, no improvement found. +} TSminpack_csminwel; +/**/ + + + +#endif + + +/*************** 3 steps to find minimization solution. ***************** +//--------------------------------- +//-- For concrete examples, see +//-- lwz_est.c in D:\ZhaData\WorkDisk\LiuWZ\Project2_empirical\EstimationOct07 +//-- ExamplesForC.prn in D:\ZhaData\CommonFiles\C_Examples_DebugTips +//--------------------------------- + +//------ For the csminwel minimization problem. ------- +//--- Step 1. Creats a number of csminwel structures for both Markov-switching and constant-parameter models. +static double minobj(struct TSminpack_tag *minpack_ps); //This function is for the constant-parameter model only. +//--- Step 2. +static void InitializeForMinproblem(struct TSminpack_tag *minpack_ps, char *filename_sp); +//--- Step 3. +//For the constant-parameter model, run minfinder(minpack_ps); //Constant-parameter case. +//For the regime-switching model, run minfinder_blockcsminwel(minpack_ps); //Time-varying case. + * + * + * + + +//=== main.c + +int indxInitializeTransitionMatrix; +//--- My model structure. +struct TSlwzmodel_tag *lwzmodel_ps = NULL; +//--- Waggoner's Markov switching package. +struct TMarkovStateVariable_tag *sv_ps = NULL; +ThetaRoutines *sroutines_ps = NULL; +struct TStateModel_tag *smodel_ps = NULL; +//--- General (csminwel) minimization for constant-parameter. +struct TSetc_minproj_tag *etc_minproj_ps = NULL; +struct TSminpack_tag *minpack_ps = NULL; +//--- Blockwise (csminwel) minimization for regime-switching model. +struct TSargs_blockcsminwel_tag *args_blockcsminwel_ps = NULL; + + +//----------------- +// Reads from the command line the user-specified input file and the most-often-used integer arguments such as sample size. +//----------------- +cl_modeltag = fn_ParseCommandLine_String(n_arg,args_cl,'t',(char *)NULL); // Tag for different models. +if (!cl_modeltag) fn_DisplayError(".../main(): No model tag is specified yet"); +//--- Type of the model: (0) const, (1) varionly, (2) trendinf, (3) policyonly, and (4) firmspolicy. +if (!strncmp("const", cl_modeltag, 5)) indx_tvmodel = 0; +else if (!strncmp("varionly", cl_modeltag, 5)) indx_tvmodel = 1; +else if (!strncmp("trendinf", cl_modeltag, 5)) indx_tvmodel = 2; +else if (!strncmp("policyonly", cl_modeltag, 5)) indx_tvmodel = 3; +else if (!strncmp("firmspolicy", cl_modeltag, 5)) indx_tvmodel = 4; +else fn_DisplayError("main(): the model tag is NOT properly selected"); +indxStartValuesForMin = fn_ParseCommandLine_Integer(n_arg,args_cl,'c',1); +sprintf(filename_sp_vec_minproj, "outdatasp_min_%s.prn", cl_modeltag); +//+ +sprintf(filenamebuffer, "dataraw.prn"); +cl_filename_rawdata = fn_ParseCommandLine_String(n_arg,args_cl,'r',filenamebuffer); //Raw data input file. +fptr_rawdata = tzFopen(cl_filename_rawdata,"r"); +//+ +sprintf(filenamebuffer, "datainp_common.prn"); +cl_filename_input1 = fn_ParseCommandLine_String(n_arg,args_cl,'i',filenamebuffer); //Common setup input data file. +fptr_input1 = tzFopen(cl_filename_input1,"r"); +//+ +sprintf(filenamebuffer, "datainp_%s.prn", cl_modeltag); +cl_filename_input2 = fn_ParseCommandLine_String(n_arg,args_cl,'s',filenamebuffer); //Model-specific setupt input data file. +fptr_input2 = tzFopen(cl_filename_input2,"r"); +//+ +sprintf(filenamebuffer, "datainp_markov_%s.prn", cl_modeltag); +cl_filename_markov = fn_ParseCommandLine_String(n_arg,args_cl,'m',filenamebuffer); //Markov-switching setup input data file. +fptr_markov = tzFopen(cl_filename_markov,"r"); +//--- Output data files. +sprintf(filenamebuffer, "outdata_debug_%s.prn", cl_modeltag); +FPTR_DEBUG = tzFopen(filenamebuffer,"w"); //Debug output file. +//+ +sprintf(filenamebuffer, "outdataout_%s.prn", cl_modeltag); +fptr_output = tzFopen(filenamebuffer,"w"); //Final output file. +//+ +sprintf(filenamebuffer, "outdatainp_matlab_%s.prn", cl_modeltag); +fptr_matlab = tzFopen(filenamebuffer, "w"); +//+ +sprintf(filenamebuffer, "outdatainp_matlab1_%s.prn", cl_modeltag); +fptr_matlab1 = tzFopen(filenamebuffer, "w"); +//+ +sprintf(filenamebuffer, "outdatainp_matlab2_%s.prn", cl_modeltag); +fptr_matlab2 = tzFopen(filenamebuffer, "w"); +//+ +sprintf(filenamebuffer, "outdatainp_matlab3_%s.prn", cl_modeltag); +fptr_matlab3 = tzFopen(filenamebuffer, "w"); + + +//---------------------------------------------- +//--- Memory allocation and structure creation. +//--- The order matters! +//---------------------------------------------- +//--- Model structure. --- +lwzmodel_ps = CreateTSlwzmodel(fptr_rawdata, fptr_input1, fptr_input2, fptr_markov, indx_tvmodel, indxStartValuesForMin); +sprintf(lwzmodel_ps->tag_modeltype_cv->v, cl_modeltag); +lwzmodel_ps->tag_modeltype_cv->flag = V_DEF; + + +//====== Waggoner's Markov switching variables. ====== +sv_ps = CreateMarkovStateVariable_File(fptr_markov, (char *)NULL, lwzmodel_ps->fss); + //In this case, fptr_markov points to datainp_markov_const.prn, which can be found in D:\ZhaData\CommonFiles\C_Examples_DebugTips\DW_MarkovInputFiles. +sroutines_ps = CreateThetaRoutines_empty(); +sroutines_ps->pLogConditionalLikelihood = logTimetCondLH; //User's: logTimetCondLH +sroutines_ps->pLogPrior = logpriordensity_usingDW; //User's: pLogPrior +sroutines_ps->pNumberFreeParametersTheta = NumberOfFreeModelSpecificParameters; //User's: NumberOfFreeModelSpecificParameters, +sroutines_ps->pConvertFreeParametersToTheta = ConvertFreeParameters2ModelSpecificParameters; //User's: ConvertFreeParameters2ModelSpecificParameters, +sroutines_ps->pConvertThetaToFreeParameters = ConvertModelSpecificParameters2FreeParameters; //User's: ConvertModelSpecificParameters2FreeParameters, +sroutines_ps->pThetaChanged = tz_thetaChanged; //User's: Notification routine (need to refresh everything given new parameters?) +sroutines_ps->pTransitionMatrixChanged = tz_TransitionMatrixChanged; //User's: Notification routine (need to refresh everything given new parameters?) +smodel_ps = CreateStateModel_new(sv_ps, sroutines_ps, (void *)lwzmodel_ps); +//--- Optional. +if (!indx_tvmodel && fn_SetFilePosition(fptr_markov, "//== indxInitializeTransitionMatrix ==//")) + if ((fscanf(fptr_markov, " %d ", &indxInitializeTransitionMatrix) == 1) && indxInitializeTransitionMatrix) + ReadTransitionMatrices(fptr_markov, (char*)NULL, "Initial: ", smodel_ps); //Waggoner's function. + + +//--- Minimization problem: Step 1. --- +args_blockcsminwel_ps = CreateTSargs_blockcsminwel(fptr_input1); + //Blockwise (csminwel) minimization arguments, reading convergence criteria or using default values if fptr_input1 is set to NULL. + //fptr_input1 contains parameters for both constant-parameter and Markov-switching models. +etc_minproj_ps = CreateTSetc_minproj(&smodel_ps, (TFDestroyTStateModel *)NULL, &args_blockcsminwel_ps, DestroyTSargs_blockcsminwel); + //Taking convergence criteria and my model structure smodel_ps into minpack_ps. +minpack_ps = CreateTSminpack((TFminobj *)minobj, (void **)&etc_minproj_ps, (TFmindestroy_etcproject *)NULL, (TFmingrad *)NULL, + filename_sp_vec_minproj, + lwzmodel_ps->xphi_dv->n+NumberFreeParametersQ(smodel_ps), + MIN_CSMINWEL); + //minobj is for the constant-parameter model only in which case, NumberFreeParametersQ(smodel_ps) will be 0. + + +//----------------- +// Main matter. +//----------------- +time(&lwzmodel_ps->prog_begtime); //Beginning time of the whole program. +InitializeGlobleSeed(lwzmodel_ps->randomseed = 0); //2764 If seednumber==0, a value is computed using the system clock. +csminwel_randomseedChanged(lwzmodel_ps->randomseed); //Using the same (or different) seednumber to reset csminwel seednumber for random perturbation. +//=== Finding the peak value of the logLH or logPosterior +if (lwzmodel_ps->indxEstFinder) +{ + //Minimization problem: Steps 2 and 3. + + InitializeForMinproblem(minpack_ps, filename_sp_vec_minproj); //Initialization for minimization. + //======= 1st round of minimization. ======= + //-------------------------- + //-- csminwel minimization where + //-- minpack_ps->x_dv contains the minimizing vector of parameters. + //-- minpack_ps->fret contains the minimized value. + //-------------------------- + + if (!lwzmodel_ps->indx_tvmodel) minfinder(minpack_ps); //Constant-parameter case. + else minfinder_blockcsminwel(minpack_ps); //Time-varying case. +} +else InitializeForMinproblem(minpack_ps, filename_sp_vec_minproj); +time(&lwzmodel_ps->prog_endtime); //Ending time of the whole program. +/*************************************************************************/ + diff --git a/CFiles/rand.c b/CFiles/rand.c new file mode 100755 index 0000000..397fbbe --- /dev/null +++ b/CFiles/rand.c @@ -0,0 +1,499 @@ + +#include "rand.h" + + +//========================================================== +// I. My own library +//========================================================== +static long idum=-1; + +long initialize_generator(long init) { + //=== init can be a positive or negative integer. + if (init > 0) + idum=-init; + else + if (init < 0) + idum=init; + else // when init=0. + idum=-(long)time((time_t *)NULL); + return idum; +} + + + +/* + Returns a uniform variate, adapted from Numerical Recipes in C + (C) Copr. 1986-92 Numerical Recipes Software $=|''1`2. + Ran2() in Numerical Recipes in C. The cycle period is + about 2.3*10^18 -- practically infinite. +*/ +#define IM1 2147483563 +#define IM2 2147483399 +#define AM (1.0/IM1) +#define IMM1 (IM1-1) +#define IA1 40014 +#define IA2 40692 +#define IQ1 53668 +#define IQ2 52774 +#define IR1 12211 +#define IR2 3791 +#define NTAB 32 +#define NDIV (1+IMM1/NTAB) +#define EPS 1.2e-7 +#define RNMX (1.0-EPS) + +double unirnd(void) +{ + int j; + long k; + static long idum2=123456789; + static long iy=0; + static long iv[NTAB]; + double temp; + + if (idum <= 0) { + if (-(idum) < 1) idum=1; + else idum = -(idum); + idum2=(idum); + for (j=NTAB+7;j>=0;j--) { + k=(idum)/IQ1; + idum=IA1*(idum-k*IQ1)-k*IR1; + if (idum < 0) idum += IM1; + if (j < NTAB) iv[j] = idum; + } + iy=iv[0]; + } + k=(idum)/IQ1; + idum=IA1*(idum-k*IQ1)-k*IR1; + if (idum < 0) idum += IM1; + k=idum2/IQ2; + idum2=IA2*(idum2-k*IQ2)-k*IR2; + if (idum2 < 0) idum2 += IM2; + j=iy/NDIV; + iy=iv[j]-idum2; + iv[j] = idum; + if (iy < 1) iy += IMM1; + if ((temp=AM*iy) > RNMX) return RNMX; + else return temp; +} +#undef IM1 +#undef IM2 +#undef AM +#undef IMM1 +#undef IA1 +#undef IA2 +#undef IQ1 +#undef IQ2 +#undef IR1 +#undef IR2 +#undef NTAB +#undef NDIV +#undef EPS +#undef RNMX + + +/* + Returns a standard gaussian variate. The density function for the + standard gaussian is + + 1 + ----------- exp(-0.5*x^2) + sqrt(2*Pi) + +*/ +double gaussrnd(void) +{ + static long iset=0; + static double gset; + double fac,r,v1,v2; + + if (iset == 0) + { + do + { + v1=(double)(2.0*unirnd()-1.0); + v2=(double)(2.0*unirnd()-1.0); + r=v1*v1+v2*v2; + } + while (r >= 1.0); + fac=(double)sqrt(-2.0*log(r)/r); + gset=v1*fac; + iset=1; + return v2*fac; + } + else + { + iset=0; + return gset; + } +} + +/* + Returns a standard gamma variate. The density function for a standard gamma + distribution is + + 1 + p(x) = --------- x^(a-1) exp(-x). + gamma(a) + + where a>0 and gamma denotes the gamma function, which is defined as the + integral with respect to t from 0 to infinity of exp(-t)*t^(z-1). + + When a==1.0, then gamma is exponential. (Devroye, page 405). + When a<1.0, Johnk's generator (Devroye, page 418). + When a>1.0, a rejection method or Best's algorithm (Devroye, page 410). + + A general gamma variate can be obtained as follows. Let z=b*x. Then, + z is drawn from a general gamma distribution whose density is + + 1 + p(z) = -------------- z^(a-1) exp(-z/b). + gamma(a) b^a + + Uses algorithm translated by Iskander Karibzhanov from the Matlab function + gamrnd.m, which follows Johnk's generator in Devroye ("Non-Uniform Random + Variate Generation", Springer-Verlag, 1986, page 418). +*/ +double gammrnd(double a) { + double b = a-1.0, + u, v, w, x, y, z; + + if (a <= 0.0) { + //** When used with a C MEX-file for MATLAB. + printf("\nThe input argument x for gammrnd(x) in rand.c must be a positive double."); + #ifdef WIN_MATLABAPI + mexErrMsgTxt("Error! ???."); // This terminates the entire Matlab program. + #else + //@ When used entirely with C. + getchar(); + exit(1); // This exits the entire C program. + #endif + } + if (a==1.0) + return -log(unirnd()); + if (a < 1.0) { + for (;;) { + x = pow(unirnd(), 1.0/a), + y = pow(unirnd(), 1.0/(1.0-a)); + if (x+y <= 1.0) + return -log(unirnd())*x/(x+y); + } + } + else { + for (;;) { + u = unirnd(); + v = unirnd(); + w = u*(1.0-u); + y = sqrt((3.0*a-0.75)/w)*(u-0.5); + x = b+y; + if (x >= 0.0) { + z = 64.0*w*w*w*v*v; + if (z <= (1.0-2.0*y*y/x)) + return x; + else if (log(z) <= (2.0*(b*log(x/b)-y))) + return x; + } + } + } +} + + + +/* + Returns the integral from -infinity to x of 1/sqrt(2*PI)*exp(-y^2/2). + Routine adapted from Numerical Recipes in C. +*/ +double cumulative_normal(double x) +{ + double z=fabs(0.7071067811865*x), t=2.0/(2.0+z); + + return (x > 0) ? + 1.0-0.5*t*exp(-z*z-1.26551223+t*(1.00002368+t*(0.37409196+ + t*(0.09678418+t*(-0.18628806+t*(0.27886807+t*(-1.13520398+ + t*(1.48851587+t*(-0.82215223+t*0.17087277))))))))) + : + 0.5*t*exp(-z*z-1.26551223+t*(1.00002368+t*(0.37409196+ + t*(0.09678418+t*(-0.18628806+t*(0.27886807+t*(-1.13520398+ + t*(1.48851587+t*(-0.82215223+t*0.17087277))))))))); + +} + + + +//========================================================== +// II. IMSL Library +//========================================================== +void InitializeGlobleSeed(int seednumber) { + #ifdef IMSL_RANDOMNUMBERGENERATOR // IMSL optimization routines. + imsls_random_option( 7 ); //Selects a random number generator from 1 to 7. When 7, the GFSR algorithm is used. + imsls_random_seed_set( seednumber ); //Initializes a random seed from 0 to 2147483646 inclusive. + //If seednumber==0, a value is computed using the system clock. + #else //Default to CASE2_RANDOMNUMBERGENERATOR: imported from the C recipe book -- Case 2 and my own (Iskander) code for generating a gamma distribution. + initialize_generator(seednumber); //If seednumber==0, a value is computed using the system clock. + #endif +} + +#ifdef IMSL_RANDOMNUMBERGENERATOR // IMSL optimization routines. +//**** WARNING:**** DO NOT allocate memory to itable outside this function. +int GetSeedTableGFSR_IMSL(int **ads_itable) +{ + //Output: + // iseed: seednumber; + // ads_itable: the address of itable where itable is seed table with pointer being set, whose memory is allocated by the IMSL, so do NOT allocate memory to itable outside this function. + //Input: itable, just a pointer and NO memory shall be allocated outside this function -- the IMSL will take care of it. + int iseed; + + iseed = imsls_random_seed_get(); + imsls_random_GFSR_table_get(ads_itable, 0); + + return (iseed); +} +// +void SetSeedTableGFSR_IMSL(int iseed, int *itable) +{ + //Input (also becomes output): + // iseed: seednumber; + // itable: seed table with pointer being set, whose memory is allocated by the IMSL, so do NOT allocate memory to itable outside this function. + imsls_random_seed_set(iseed); + imsls_random_GFSR_table_set(itable); +} +#endif + +double UniformDouble(void) { + #ifdef IMSL_RANDOMNUMBERGENERATOR // IMSL optimization routines. + //The GFSR algorithm to generate random numbers. + double x; + imsls_d_random_uniform(1, IMSLS_RETURN_USER, &x, 0); + return x; + #else //Default to CASE2_RANDOMNUMBERGENERATOR: imported from the C recipe book -- Case 2 and my own (Iskander) code for generating a gamma distribution. + return unirnd(); + #endif +} + +double StandardNormalDouble(void) { + #ifdef IMSL_RANDOMNUMBERGENERATOR // IMSL optimization routines. + //The GFSR algorithm to generate random numbers. + double x; + imsls_d_random_normal(1, IMSLS_RETURN_USER, &x, 0); + return x; + #else CASE2_RANDOMNUMBERGENERATOR //Imported from the C recipe book -- Case 2 and my own (Iskander) code for generating a gamma distribution. + return gaussrnd(); + #endif +} + +double LogNormalDouble(double mean, double std) +{ + //Return x where log(x) is normal(mean, std^2). + #ifdef IMSL_RANDOMNUMBERGENERATOR // IMSL optimization routines. + //The GFSR algorithm to generate random numbers. + double x; + imsls_d_random_lognormal(1, mean, std, IMSLS_RETURN_USER, &x, 0); + return x; + #else CASE2_RANDOMNUMBERGENERATOR //Imported from the C recipe book -- Case 2 and my own (Iskander) code for generating a gamma distribution. + fn_DisplayError(".../rand.c/LogNormalDouble(): NO defaul available for log normal draws"); + return (0); + #endif +} + + +double GammaDouble(const double a, const double b) { + //The probability density of x is of the form: ( x^(a-1) exp(-x/b) )/( Gamma(a) * b^a ). + //The same form as in the MATLAB (not Gelman et al's) notation. + #ifdef IMSL_RANDOMNUMBERGENERATOR // IMSL optimization routines. + //The GFSR algorithm to generate random numbers. + double x; + imsls_d_random_gamma(1, a, IMSLS_RETURN_USER, &x, 0); + if (b != 1.0) x *= b; + return x; + #else CASE2_RANDOMNUMBERGENERATOR //Imported from the C recipe book -- Case 2 and my own (Iskander) code for generating a gamma distribution. + return ( (b==1.0) ? gammrnd(a) : b*gammrnd(a) ); + #endif +} + + +void UniformVector(TSdvector *x_dv) +{ + #if !defined( IMSL_RANDOMNUMBERGENERATOR ) //Default to CASE2_RANDOMNUMBERGENERATOR: imported from the C recipe book -- Case 2 and my own (Iskander) code for generating a gamma distribution. + int _i; + double *v; + #endif + + + if ( !x_dv ) fn_DisplayError(".../rand.c/UniformVector(): Input vector must be created (memory-allocated)"); + #ifdef IMSL_RANDOMNUMBERGENERATOR // IMSL optimization routines. + //The GFSR algorithm to generate random numbers. + imsls_d_random_uniform(x_dv->n, IMSLS_RETURN_USER, x_dv->v, 0); + x_dv->flag = V_DEF; + #else //CASE2_RANDOMNUMBERGENERATOR //Imported from the C recipe book -- Case 2 and my own (Iskander) code for generating a gamma distribution. + v = x_dv->v; + for (_i=x_dv->n-1; _i>=0; _i--) v[_i] = unirnd(); + x_dv->flag = V_DEF; + #endif +} + +void StandardNormalVector(TSdvector *x_dv) { + #if !defined( IMSL_RANDOMNUMBERGENERATOR ) //Default to CASE2_RANDOMNUMBERGENERATOR: imported from the C recipe book -- Case 2 and my own (Iskander) code for generating a gamma distribution. + int _i; + #endif + double *v; + + if ( !x_dv ) fn_DisplayError(".../rand.c/StandardNormalVector(): Input vector must be created (memory-allocated)"); + else v = x_dv->v; + + #if defined (IMSL_RANDOMNUMBERGENERATOR) // IMSL optimization routines. + //The GFSR algorithm to generate random numbers. + imsls_d_random_normal(x_dv->n, IMSLS_RETURN_USER, v, 0); + x_dv->flag = V_DEF; + #else //Default to CASE2_RANDOMNUMBERGENERATOR, imported from the C recipe book -- Case 2 and my own (Iskander) code for generating a gamma distribution. + for (_i=x_dv->n-1; _i>=0; _i--) v[_i] = gaussrnd(); + x_dv->flag = V_DEF; + #endif +} + + +void StandardNormalMatrix(TSdmatrix *X_dm) { + #ifndef IMSL_RANDOMNUMBERGENERATOR //Default to the C recipe book -- Case 2 and my own (Iskander) code for generating a gamma distribution. + int _i; + #endif + double *M; + + if ( !X_dm ) fn_DisplayError(".../rand.c/StandardNormalMatrix(): Input matrix must be created (memory-allocated)"); + M = X_dm->M; + + #if defined (IMSL_RANDOMNUMBERGENERATOR) // IMSL optimization routines. + //The GFSR algorithm to generate random numbers. + imsls_d_random_normal(X_dm->nrows*X_dm->ncols, IMSLS_RETURN_USER, M, 0); + X_dm->flag = M_GE; + #else //Default to CASE2_RANDOMNUMBERGENERATOR, imported from the C recipe book -- Case 2 and my own (Iskander) code for generating a gamma distribution. + for (_i=X_dm->nrows*X_dm->ncols-1; _i>=0; _i--) M[_i] = gaussrnd(); + X_dm->flag = M_GE; + #endif +} + + +void GammaMatrix(TSdmatrix *X_dm, TSdmatrix *A_dm, TSdmatrix *B_dm) { + //The probability density of each element of X_dm is of the form: ( x^(a-1) exp(-x/b) )/( Gamma(a) * b^a ). + //The same form as in the MATLAB (not Gelman et al's) notation. + #ifdef IMSL_RANDOMNUMBERGENERATOR // IMSL optimization routines. + //The GFSR algorithm to generate random numbers. + int _i, nels, nrows, ncols; + double *X, *A, *B, a, b; + + if ( !X_dm || !A_dm || !B_dm ) fn_DisplayError(".../rand.c/GammaMatrix(): All input matrices must be created (memory-allocated)"); + else if ( !A_dm->flag || !B_dm->flag ) fn_DisplayError(".../rand.c/GammaMatrix(): Two R input matrices must be given values"); + else { + nrows = X_dm->nrows; + ncols = X_dm->ncols; + nels = nrows*ncols; + X = X_dm->M; + A = A_dm->M; + B = B_dm->M; + } + + if ( (nrows != A_dm->nrows) || (nrows != B_dm->nrows) || (ncols != A_dm->ncols) || (ncols != B_dm->ncols) ) + fn_DisplayError(".../rand.c/GammaMatrix(): Dimensions of all input matrices must match"); + + + if ( A_dm->flag & M_CN ) { + imsls_d_random_gamma(nels, a=A[0], IMSLS_RETURN_USER, X, 0); //Same for all elements of A_dm->M. + if ( B_dm->flag & M_CN ) { + if ( !((b = B[0])==1.0) ) cblas_dscal(nels, b, X, 1); //Same for all elements of B_dm->M. + } + else { + for (_i=nels-1; _i>=0; _i--) X[_i] *= B[_i]; + } + } + else { + for (_i=nels-1; _i>=0; _i--) { + if (A[_i]!=0) //Added 02/23/05. To take account of exclusion restrictions. + { + imsls_d_random_gamma(1, A[_i], IMSLS_RETURN_USER, &X[_i], 0); + X[_i] *= B[_i]; + } + else + X[_i] = 0.0; + } + } + + X_dm->flag = M_GE; + #else CASE2_RANDOMNUMBERGENERATOR //Imported from the C recipe book -- Case 2 and my own (Iskander) code for generating a gamma distribution. + int _i, nels, nrows, ncols; + double *X, *A, *B; + + if ( !X_dm || !A_dm || !B_dm ) fn_DisplayError(".../rand.c/GammaMatrix(): All input matrices must be created (memory-allocated)"); + else if ( !A_dm->flag || !B_dm->flag ) fn_DisplayError(".../rand.c/GammaMatrix(): Two R input matrices must be given values"); + else { + nrows = X_dm->nrows; + ncols = X_dm->ncols; + nels = nrows*ncols; + X = X_dm->M; + A = A_dm->M; + B = B_dm->M; + } + + if ( (nrows != A_dm->nrows) || (nrows != B_dm->nrows) || (ncols != A_dm->ncols) || (ncols != B_dm->ncols) ) + fn_DisplayError(".../rand.c/GammaMatrix(): Dimensions of all input matrices must match"); + + for (_i=nels-1; _i>=0; _i--) + if (A[_i]!=0) //Added 02/23/05. To take account of exclusion restrictions. + X[_i] = B[_i]*gammrnd(A[_i]); + else + X[_i] = 0.0; + X_dm->flag = M_GE; + #endif +} + + +double ChisquareDouble(const double v) { + //The probability density of x is of the form: ( x^(v/2-1) exp(-x/2) )/( Gamma(v/2) * 2^(v/2) ). + //= GammaDouble(v/2.0, 2.0). + #ifdef IMSL_RANDOMNUMBERGENERATOR // IMSL optimization routines. + //The GFSR algorithm to generate random numbers. + double x; + imsls_d_random_chi_squared(1, v, IMSLS_RETURN_USER, &x, 0); + return x; + #else CASE2_RANDOMNUMBERGENERATOR //Imported from the C recipe book -- Case 2 and my own (Iskander) code for generating a gamma distribution. + return ( 2.0*gammrnd(0.5*v) ); + #endif +} + + + +//-------------------------------------- +int tz_DrawState(TSdvector *qs_dv) +{ + //Randomly generate states, given the probabilties qs_dv where sum(qs_dv)=1. + //Output: sindx is 0, 1, ..., or nStates, randomly drawn according the uniform distribution. + // + //Users are responsible to make sure sum(qs_dv)=1. + int si, sindx, nStates=qs_dv->n; + double tmpd1, tmpd2; + double *v=qs_dv->v; + + if ( (tmpd2=UniformDouble()) <= v[0] ) sindx = 0; + else { + tmpd1 = v[0]; // Cumulative sum of qs_dv. + for (si=1; si<nStates; si++) { + if ( tmpd2 <= (tmpd1 += v[si]) ) { + sindx = si; + break; + } + } + if (tmpd2 > tmpd1) fn_DisplayError(".../rand.c/tz_DrawState(): the sum of probabilities must be 1.0"); + } + + return( sindx ); +} + + +/** +//void UniformDouble(double *x) { +// #ifdef IMSL_RANDOMNUMBERGENERATOR // IMSL optimization routines. +// //The GFSR algorithm to generate random numbers. +// imsls_d_random_uniform(1, IMSLS_RETURN_USER, x, 0); +// #endif +// #ifdef CASE2_RANDOMNUMBERGENERATOR //Imported from the C recipe book -- Case 2 and my own (Iskander) code for generating a gamma distribution. +// *x = unirnd(); +// #endif +//} +/**/ diff --git a/CFiles/rand.h b/CFiles/rand.h new file mode 100755 index 0000000..a12c28e --- /dev/null +++ b/CFiles/rand.h @@ -0,0 +1,44 @@ + +#ifndef __RANDOM__ +#define __RANDOM__ + #include "tzmatlab.h" // Only when used with the MATLAB interface in gammrnd(). + + #include <time.h> + + //========================================================== + // I. My own library + //========================================================== +// long initialize_generator(long init); + long initialize_generator(long init); + double unirnd(void); + double gaussrnd(void); + double gammrnd(double a); + double cumulative_normal(double x); + + + + //========================================================== + // II. IMSL Library + //========================================================== +// #define SetGlobleSeed(seed) imsls_random_seed_set( seed ) +// //Initializes a random seed for the IMSL random number generator. +// //seed: an integer number from 0 to 2147483646 inclusive. If seed==0, a value is computed using the system clock. +// #define SetGenerator(indicator) imsls_random_option( indicator ) +// //Select a random number generator from the IMSL. +// //indicator: an integer number from 1 to 7. If indicator==7, the GFSR algorithm is used. + + void InitializeGlobleSeed(int seednumber); //If seednumber==0, a value is computed using the system clock. + int GetSeedTableGFSR_IMSL(int **itable); + void SetSeedTableGFSR_IMSL(int iseed, int *itable); + double UniformDouble(void); + double StandardNormalDouble(void); + double LogNormalDouble(double mean, double std); + double GammaDouble(const double a, const double b); + double ChisquareDouble(const double v); + void UniformVector(TSdvector *x_dv); + void StandardNormalVector(TSdvector *x_dv); + void StandardNormalMatrix(TSdmatrix *X_dm); + void GammaMatrix(TSdmatrix *X_dm, TSdmatrix *A_dm, TSdmatrix *B_dm); + //------------ + int tz_DrawState(TSdvector *qs_dv); +#endif diff --git a/CFiles/template_proj.vcproj b/CFiles/template_proj.vcproj new file mode 100755 index 0000000..ab4cb30 --- /dev/null +++ b/CFiles/template_proj.vcproj @@ -0,0 +1,376 @@ +<?xml version="1.0" encoding="Windows-1252"?> +<VisualStudioProject + ProjectType="Visual C++" + Version="8.00" + Name="template_proj" + ProjectGUID="{30EA1610-6051-4681-A29C-9D29389FE60F}" + Keyword="Win32Proj" + > + <Platforms> + <Platform + Name="Win32" + /> + </Platforms> + <ToolFiles> + </ToolFiles> + <Configurations> + <Configuration + Name="Debug|Win32" + OutputDirectory="Debug" + IntermediateDirectory="Debug" + ConfigurationType="1" + InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC70.vsprops" + CharacterSet="2" + > + <Tool + Name="VCPreBuildEventTool" + /> + <Tool + Name="VCCustomBuildTool" + /> + <Tool + Name="VCXMLDataGeneratorTool" + /> + <Tool + Name="VCWebServiceProxyGeneratorTool" + /> + <Tool + Name="VCMIDLTool" + /> + <Tool + Name="VCCLCompilerTool" + Optimization="0" + PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE" + MinimalRebuild="true" + BasicRuntimeChecks="3" + RuntimeLibrary="1" + UsePrecompiledHeader="0" + WarningLevel="3" + Detect64BitPortabilityProblems="true" + DebugInformationFormat="4" + CompileAs="1" + DisableSpecificWarnings="4996" + /> + <Tool + Name="VCManagedResourceCompilerTool" + /> + <Tool + Name="VCResourceCompilerTool" + /> + <Tool + Name="VCPreLinkEventTool" + /> + <Tool + Name="VCLinkerTool" + AdditionalDependencies="netapi32.lib advapi32.lib gdi32.lib comdlg32.lib comctl32.lib wsock32.lib" + LinkIncremental="2" + IgnoreAllDefaultLibraries="false" + IgnoreDefaultLibraryNames="libcd.lib;libc.lib;libcmtd.lib" + GenerateDebugInformation="true" + SubSystem="1" + TargetMachine="1" + /> + <Tool + Name="VCALinkTool" + /> + <Tool + Name="VCManifestTool" + /> + <Tool + Name="VCXDCMakeTool" + /> + <Tool + Name="VCBscMakeTool" + /> + <Tool + Name="VCFxCopTool" + /> + <Tool + Name="VCAppVerifierTool" + /> + <Tool + Name="VCWebDeploymentTool" + /> + <Tool + Name="VCPostBuildEventTool" + /> + </Configuration> + <Configuration + Name="Release|Win32" + OutputDirectory="Release" + IntermediateDirectory="Release" + ConfigurationType="1" + InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC70.vsprops" + CharacterSet="2" + > + <Tool + Name="VCPreBuildEventTool" + /> + <Tool + Name="VCCustomBuildTool" + /> + <Tool + Name="VCXMLDataGeneratorTool" + /> + <Tool + Name="VCWebServiceProxyGeneratorTool" + /> + <Tool + Name="VCMIDLTool" + /> + <Tool + Name="VCCLCompilerTool" + Optimization="2" + InlineFunctionExpansion="2" + EnableIntrinsicFunctions="true" + FavorSizeOrSpeed="1" + OmitFramePointers="true" + EnableFiberSafeOptimizations="false" + WholeProgramOptimization="false" + PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE" + StringPooling="true" + RuntimeLibrary="0" + EnableFunctionLevelLinking="true" + UsePrecompiledHeader="0" + WarningLevel="3" + Detect64BitPortabilityProblems="true" + DebugInformationFormat="3" + CompileAs="1" + DisableSpecificWarnings="4996" + /> + <Tool + Name="VCManagedResourceCompilerTool" + /> + <Tool + Name="VCResourceCompilerTool" + /> + <Tool + Name="VCPreLinkEventTool" + /> + <Tool + Name="VCLinkerTool" + AdditionalDependencies="netapi32.lib advapi32.lib gdi32.lib comdlg32.lib comctl32.lib wsock32.lib" + LinkIncremental="1" + IgnoreDefaultLibraryNames="libcd.lib;libc.lib" + GenerateDebugInformation="false" + SubSystem="1" + OptimizeReferences="2" + EnableCOMDATFolding="2" + TargetMachine="1" + /> + <Tool + Name="VCALinkTool" + /> + <Tool + Name="VCManifestTool" + /> + <Tool + Name="VCXDCMakeTool" + /> + <Tool + Name="VCBscMakeTool" + /> + <Tool + Name="VCFxCopTool" + /> + <Tool + Name="VCAppVerifierTool" + /> + <Tool + Name="VCWebDeploymentTool" + /> + <Tool + Name="VCPostBuildEventTool" + /> + </Configuration> + </Configurations> + <References> + </References> + <Files> + <Filter + Name="Source Files" + Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm" + > + <File + RelativePath="..\..\..\TZCcode\csminwel.c" + > + <FileConfiguration + Name="Debug|Win32" + > + <Tool + Name="VCCLCompilerTool" + ObjectFile="$(IntDir)/$(InputName)1.obj" + /> + </FileConfiguration> + <FileConfiguration + Name="Release|Win32" + > + <Tool + Name="VCCLCompilerTool" + ObjectFile="$(IntDir)/$(InputName)1.obj" + /> + </FileConfiguration> + </File> + <File + RelativePath="..\..\..\TZCcode\cstz.c" + > + <FileConfiguration + Name="Debug|Win32" + > + <Tool + Name="VCCLCompilerTool" + ObjectFile="$(IntDir)/$(InputName)1.obj" + /> + </FileConfiguration> + <FileConfiguration + Name="Release|Win32" + > + <Tool + Name="VCCLCompilerTool" + ObjectFile="$(IntDir)/$(InputName)1.obj" + /> + </FileConfiguration> + </File> + <File + RelativePath="..\..\..\TZCcode\DWMatrixCode\switch\estimate.c" + > + </File> + <File + RelativePath="..\..\..\TZCcode\DWMatrixCode\extern_dw_switch_var_est.c" + > + </File> + <File + RelativePath="..\..\..\TZCcode\fn_filesetup.c" + > + <FileConfiguration + Name="Debug|Win32" + > + <Tool + Name="VCCLCompilerTool" + ObjectFile="$(IntDir)/$(InputName)1.obj" + /> + </FileConfiguration> + <FileConfiguration + Name="Release|Win32" + > + <Tool + Name="VCCLCompilerTool" + ObjectFile="$(IntDir)/$(InputName)1.obj" + /> + </FileConfiguration> + </File> + <File + RelativePath="..\..\..\TZCcode\mathlib.c" + > + <FileConfiguration + Name="Debug|Win32" + > + <Tool + Name="VCCLCompilerTool" + ObjectFile="$(IntDir)/$(InputName)1.obj" + /> + </FileConfiguration> + <FileConfiguration + Name="Release|Win32" + > + <Tool + Name="VCCLCompilerTool" + ObjectFile="$(IntDir)/$(InputName)1.obj" + /> + </FileConfiguration> + </File> + <File + RelativePath="..\..\..\TZCcode\rand.c" + > + <FileConfiguration + Name="Debug|Win32" + > + <Tool + Name="VCCLCompilerTool" + ObjectFile="$(IntDir)/$(InputName)1.obj" + /> + </FileConfiguration> + <FileConfiguration + Name="Release|Win32" + > + <Tool + Name="VCCLCompilerTool" + ObjectFile="$(IntDir)/$(InputName)1.obj" + /> + </FileConfiguration> + </File> + <File + RelativePath="..\..\..\TZCcode\tzmatlab.c" + > + <FileConfiguration + Name="Debug|Win32" + > + <Tool + Name="VCCLCompilerTool" + ObjectFile="$(IntDir)/$(InputName)1.obj" + /> + </FileConfiguration> + <FileConfiguration + Name="Release|Win32" + > + <Tool + Name="VCCLCompilerTool" + ObjectFile="$(IntDir)/$(InputName)1.obj" + /> + </FileConfiguration> + </File> + </Filter> + <Filter + Name="Header Files" + Filter="h;hpp;hxx;hm;inl;inc" + > + <File + RelativePath=".\resource.h" + > + </File> + </Filter> + <Filter + Name="Resource Files" + Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" + > + </Filter> + <File + RelativePath="C:\Program Files\VNI\imsl\cnl600\vs05pc\lib\imslcmath.lib" + > + </File> + <File + RelativePath="C:\Program Files\VNI\imsl\cnl600\vs05pc\lib\imslcmath_iblas.lib" + > + </File> + <File + RelativePath="C:\Program Files\VNI\imsl\cnl600\vs05pc\lib\imslcmath_scalar.lib" + > + </File> + <File + RelativePath="C:\Program Files\VNI\imsl\cnl600\vs05pc\lib\imslcstat.lib" + > + </File> + <File + RelativePath="C:\Program Files\VNI\imsl\cnl600\vs05pc\lib\imslcstat_iblas.lib" + > + </File> + <File + RelativePath="..\..\..\..\Program Files\Microsoft Visual Studio 8\VC\lib\libcmt.lib" + > + </File> + <File + RelativePath="..\..\Program Files\Microsoft Visual Studio 8\VC\lib\libcmtd.lib" + > + </File> + <File + RelativePath="C:\Program Files\Intel\MKL\8.1\ia32\lib\libguide40.lib" + > + </File> + <File + RelativePath="C:\Program Files\Intel\MKL\8.1\ia32\lib\mkl_c.lib" + > + </File> + </Files> + <Globals> + </Globals> +</VisualStudioProject> diff --git a/CFiles/template_proj2.vcproj b/CFiles/template_proj2.vcproj new file mode 100755 index 0000000..4f4a33c --- /dev/null +++ b/CFiles/template_proj2.vcproj @@ -0,0 +1,291 @@ +<?xml version="1.0" encoding="Windows-1252"?> +<VisualStudioProject + ProjectType="Visual C++" + Version="9.00" + Name="template_proj2" + ProjectGUID="{30EA1610-6051-4681-A29C-9D29389FE60F}" + Keyword="Win32Proj" + TargetFrameworkVersion="131072" + > + <Platforms> + <Platform + Name="Win32" + /> + </Platforms> + <ToolFiles> + </ToolFiles> + <Configurations> + <Configuration + Name="Debug|Win32" + OutputDirectory="Debug" + IntermediateDirectory="Debug" + ConfigurationType="1" + InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC70.vsprops" + CharacterSet="2" + > + <Tool + Name="VCPreBuildEventTool" + /> + <Tool + Name="VCCustomBuildTool" + /> + <Tool + Name="VCXMLDataGeneratorTool" + /> + <Tool + Name="VCWebServiceProxyGeneratorTool" + /> + <Tool + Name="VCMIDLTool" + /> + <Tool + Name="VCCLCompilerTool" + Optimization="0" + PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE" + MinimalRebuild="true" + BasicRuntimeChecks="3" + RuntimeLibrary="1" + UsePrecompiledHeader="0" + WarningLevel="3" + Detect64BitPortabilityProblems="false" + DebugInformationFormat="4" + CompileAs="1" + DisableSpecificWarnings="4996" + /> + <Tool + Name="VCManagedResourceCompilerTool" + /> + <Tool + Name="VCResourceCompilerTool" + /> + <Tool + Name="VCPreLinkEventTool" + /> + <Tool + Name="VCLinkerTool" + AdditionalDependencies="netapi32.lib advapi32.lib gdi32.lib comdlg32.lib comctl32.lib wsock32.lib" + LinkIncremental="2" + IgnoreAllDefaultLibraries="false" + IgnoreDefaultLibraryNames="libcd.lib;libc.lib;libcmtd.lib" + GenerateDebugInformation="true" + SubSystem="1" + RandomizedBaseAddress="1" + DataExecutionPrevention="0" + TargetMachine="1" + /> + <Tool + Name="VCALinkTool" + /> + <Tool + Name="VCManifestTool" + /> + <Tool + Name="VCXDCMakeTool" + /> + <Tool + Name="VCBscMakeTool" + /> + <Tool + Name="VCFxCopTool" + /> + <Tool + Name="VCAppVerifierTool" + /> + <Tool + Name="VCPostBuildEventTool" + /> + </Configuration> + <Configuration + Name="Release|Win32" + OutputDirectory="Release" + IntermediateDirectory="Release" + ConfigurationType="1" + InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC70.vsprops" + CharacterSet="2" + > + <Tool + Name="VCPreBuildEventTool" + /> + <Tool + Name="VCCustomBuildTool" + /> + <Tool + Name="VCXMLDataGeneratorTool" + /> + <Tool + Name="VCWebServiceProxyGeneratorTool" + /> + <Tool + Name="VCMIDLTool" + /> + <Tool + Name="VCCLCompilerTool" + Optimization="2" + InlineFunctionExpansion="2" + EnableIntrinsicFunctions="true" + FavorSizeOrSpeed="1" + OmitFramePointers="true" + EnableFiberSafeOptimizations="true" + WholeProgramOptimization="false" + PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE" + StringPooling="true" + RuntimeLibrary="0" + EnableFunctionLevelLinking="true" + UsePrecompiledHeader="0" + WarningLevel="3" + Detect64BitPortabilityProblems="false" + DebugInformationFormat="3" + CompileAs="1" + DisableSpecificWarnings="4996" + /> + <Tool + Name="VCManagedResourceCompilerTool" + /> + <Tool + Name="VCResourceCompilerTool" + /> + <Tool + Name="VCPreLinkEventTool" + /> + <Tool + Name="VCLinkerTool" + AdditionalDependencies="netapi32.lib advapi32.lib gdi32.lib comdlg32.lib comctl32.lib wsock32.lib" + LinkIncremental="1" + IgnoreDefaultLibraryNames="libcd.lib;libc.lib" + GenerateDebugInformation="false" + SubSystem="1" + OptimizeReferences="2" + EnableCOMDATFolding="2" + RandomizedBaseAddress="1" + DataExecutionPrevention="0" + TargetMachine="1" + /> + <Tool + Name="VCALinkTool" + /> + <Tool + Name="VCManifestTool" + /> + <Tool + Name="VCXDCMakeTool" + /> + <Tool + Name="VCBscMakeTool" + /> + <Tool + Name="VCFxCopTool" + /> + <Tool + Name="VCAppVerifierTool" + /> + <Tool + Name="VCPostBuildEventTool" + /> + </Configuration> + </Configurations> + <References> + </References> + <Files> + <Filter + Name="Source Files" + Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm" + > + <File + RelativePath="D:\ZhaData\TZCcode\congradmin.c" + > + </File> + <File + RelativePath="D:\ZhaData\TZCcode\csminwel.c" + > + </File> + <File + RelativePath="D:\ZhaData\TZCcode\cstz.c" + > + </File> + <File + RelativePath="D:\ZhaData\TZCcode\DWMatrixCode\extern_dw_switch.c" + > + </File> + <File + RelativePath="D:\ZhaData\TZCcode\fn_filesetup.c" + > + </File> + <File + RelativePath="D:\ZhaData\TZCcode\gensys.c" + > + </File> + <File + RelativePath="D:\ZhaData\TZCcode\gradcd_switch.c" + > + </File> + <File + RelativePath="D:\ZhaData\TZCcode\kalman.c" + > + </File> + <File + RelativePath="D:\ZhaData\TZCcode\mathlib.c" + > + </File> + <File + RelativePath="D:\ZhaData\TZCcode\optpackage.c" + > + </File> + <File + RelativePath="D:\ZhaData\TZCcode\rand.c" + > + </File> + <File + RelativePath="D:\ZhaData\TZCcode\tzmatlab.c" + > + </File> + </Filter> + <Filter + Name="Header Files" + Filter="h;hpp;hxx;hm;inl;inc" + > + </Filter> + <Filter + Name="Resource Files" + Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" + > + </Filter> + <File + RelativePath="C:\Program Files\VNI\imsl\cnl600\vs05pc\lib\imslcmath.lib" + > + </File> + <File + RelativePath="C:\Program Files\VNI\imsl\cnl600\vs05pc\lib\imslcmath_iblas.lib" + > + </File> + <File + RelativePath="C:\Program Files\VNI\imsl\cnl600\vs05pc\lib\imslcmath_scalar.lib" + > + </File> + <File + RelativePath="C:\Program Files\VNI\imsl\cnl600\vs05pc\lib\imslcstat.lib" + > + </File> + <File + RelativePath="C:\Program Files\VNI\imsl\cnl600\vs05pc\lib\imslcstat_iblas.lib" + > + </File> + <File + RelativePath="C:\Program Files\Microsoft Visual Studio 9.0\VC\lib\libcmt.lib" + > + </File> + <File + RelativePath="C:\Program Files\Microsoft Visual Studio 9.0\VC\lib\libcmtd.lib" + > + </File> + <File + RelativePath="C:\Program Files\Intel\MKL\9.0\ia32\lib\libguide.lib" + > + </File> + <File + RelativePath="C:\Program Files\Intel\MKL\9.0\ia32\lib\mkl_c.lib" + > + </File> + </Files> + <Globals> + </Globals> +</VisualStudioProject> diff --git a/CFiles/template_proj2_MKL8.0.vcproj b/CFiles/template_proj2_MKL8.0.vcproj new file mode 100755 index 0000000..14d59cc --- /dev/null +++ b/CFiles/template_proj2_MKL8.0.vcproj @@ -0,0 +1,296 @@ +<?xml version="1.0" encoding="Windows-1252"?> +<VisualStudioProject + ProjectType="Visual C++" + Version="8.00" + Name="template_proj2" + ProjectGUID="{30EA1610-6051-4681-A29C-9D29389FE60F}" + Keyword="Win32Proj" + > + <Platforms> + <Platform + Name="Win32" + /> + </Platforms> + <ToolFiles> + </ToolFiles> + <Configurations> + <Configuration + Name="Debug|Win32" + OutputDirectory="Debug" + IntermediateDirectory="Debug" + ConfigurationType="1" + InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC70.vsprops" + CharacterSet="2" + > + <Tool + Name="VCPreBuildEventTool" + /> + <Tool + Name="VCCustomBuildTool" + /> + <Tool + Name="VCXMLDataGeneratorTool" + /> + <Tool + Name="VCWebServiceProxyGeneratorTool" + /> + <Tool + Name="VCMIDLTool" + /> + <Tool + Name="VCCLCompilerTool" + Optimization="0" + PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE" + MinimalRebuild="true" + BasicRuntimeChecks="3" + RuntimeLibrary="1" + UsePrecompiledHeader="0" + WarningLevel="3" + Detect64BitPortabilityProblems="true" + DebugInformationFormat="4" + CompileAs="1" + DisableSpecificWarnings="4996" + /> + <Tool + Name="VCManagedResourceCompilerTool" + /> + <Tool + Name="VCResourceCompilerTool" + /> + <Tool + Name="VCPreLinkEventTool" + /> + <Tool + Name="VCLinkerTool" + AdditionalDependencies="netapi32.lib advapi32.lib gdi32.lib comdlg32.lib comctl32.lib wsock32.lib" + LinkIncremental="2" + IgnoreAllDefaultLibraries="false" + IgnoreDefaultLibraryNames="libcd.lib;libc.lib;libcmtd.lib" + GenerateDebugInformation="true" + SubSystem="1" + TargetMachine="1" + /> + <Tool + Name="VCALinkTool" + /> + <Tool + Name="VCManifestTool" + /> + <Tool + Name="VCXDCMakeTool" + /> + <Tool + Name="VCBscMakeTool" + /> + <Tool + Name="VCFxCopTool" + /> + <Tool + Name="VCAppVerifierTool" + /> + <Tool + Name="VCWebDeploymentTool" + /> + <Tool + Name="VCPostBuildEventTool" + /> + </Configuration> + <Configuration + Name="Release|Win32" + OutputDirectory="Release" + IntermediateDirectory="Release" + ConfigurationType="1" + InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC70.vsprops" + CharacterSet="2" + > + <Tool + Name="VCPreBuildEventTool" + /> + <Tool + Name="VCCustomBuildTool" + /> + <Tool + Name="VCXMLDataGeneratorTool" + /> + <Tool + Name="VCWebServiceProxyGeneratorTool" + /> + <Tool + Name="VCMIDLTool" + /> + <Tool + Name="VCCLCompilerTool" + Optimization="2" + InlineFunctionExpansion="2" + EnableIntrinsicFunctions="true" + FavorSizeOrSpeed="1" + OmitFramePointers="true" + EnableFiberSafeOptimizations="false" + WholeProgramOptimization="false" + PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE" + StringPooling="true" + RuntimeLibrary="0" + EnableFunctionLevelLinking="true" + UsePrecompiledHeader="0" + WarningLevel="3" + Detect64BitPortabilityProblems="true" + DebugInformationFormat="3" + CompileAs="1" + DisableSpecificWarnings="4996" + /> + <Tool + Name="VCManagedResourceCompilerTool" + /> + <Tool + Name="VCResourceCompilerTool" + /> + <Tool + Name="VCPreLinkEventTool" + /> + <Tool + Name="VCLinkerTool" + AdditionalDependencies="netapi32.lib advapi32.lib gdi32.lib comdlg32.lib comctl32.lib wsock32.lib" + LinkIncremental="1" + IgnoreDefaultLibraryNames="libcd.lib;libc.lib" + GenerateDebugInformation="false" + SubSystem="1" + OptimizeReferences="2" + EnableCOMDATFolding="2" + TargetMachine="1" + /> + <Tool + Name="VCALinkTool" + /> + <Tool + Name="VCManifestTool" + /> + <Tool + Name="VCXDCMakeTool" + /> + <Tool + Name="VCBscMakeTool" + /> + <Tool + Name="VCFxCopTool" + /> + <Tool + Name="VCAppVerifierTool" + /> + <Tool + Name="VCWebDeploymentTool" + /> + <Tool + Name="VCPostBuildEventTool" + /> + </Configuration> + </Configurations> + <References> + </References> + <Files> + <Filter + Name="Source Files" + Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm" + > + <File + RelativePath="D:\ZhaData\TZCcode\congradmin.c" + > + </File> + <File + RelativePath="D:\ZhaData\TZCcode\csminwel.c" + > + </File> + <File + RelativePath="D:\ZhaData\TZCcode\cstz.c" + > + </File> + <File + RelativePath="D:\ZhaData\TZCcode\DWMatrixCode\extern_dw_switch.c" + > + </File> + <File + RelativePath="D:\ZhaData\TZCcode\fn_filesetup.c" + > + </File> + <File + RelativePath="D:\ZhaData\\TZCcode\gradcd_switch.c" + > + </File> + <File + RelativePath=".\hyper_est.c" + > + </File> + <File + RelativePath="D:\ZhaData\\TZCcode\kalman.c" + > + </File> + <File + RelativePath="D:\ZhaData\\TZCcode\mathlib.c" + > + </File> + <File + RelativePath="D:\ZhaData\\TZCcode\optpackage.c" + > + </File> + <File + RelativePath="D:\ZhaData\TZCcode\rand.c" + > + </File> + <File + RelativePath="..\swz2_comfuns.c" + > + </File> + <File + RelativePath="D:\ZhaData\TZCcode\tzmatlab.c" + > + </File> + </Filter> + <Filter + Name="Header Files" + Filter="h;hpp;hxx;hm;inl;inc" + > + </Filter> + <Filter + Name="Resource Files" + Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" + > + </Filter> + <File + RelativePath="C:\Program Files\VNI\imsl\cnl600\vs05pc\lib\imslcmath.lib" + > + </File> + <File + RelativePath="C:\Program Files\VNI\imsl\cnl600\vs05pc\lib\imslcmath_iblas.lib" + > + </File> + <File + RelativePath="C:\Program Files\VNI\imsl\cnl600\vs05pc\lib\imslcmath_scalar.lib" + > + </File> + <File + RelativePath="C:\Program Files\VNI\imsl\cnl600\vs05pc\lib\imslcstat.lib" + > + </File> + <File + RelativePath="C:\Program Files\VNI\imsl\cnl600\vs05pc\lib\imslcstat_iblas.lib" + > + </File> + <File + RelativePath="D:\Program Files\Microsoft Visual Studio 8\VC\lib\libcmt.lib" + > + </File> + <File + RelativePath="D:\Program Files\Microsoft Visual Studio 8\VC\lib\libcmtd.lib" + > + </File> + <File + RelativePath="C:\Program Files\Intel\MKL\8.1\ia32\lib\libguide40.lib" + > + </File> + <File + RelativePath="C:\Program Files\Intel\MKL\8.1\ia32\lib\mkl_c.lib" + > + </File> + </Files> + <Globals> + </Globals> +</VisualStudioProject> diff --git a/CFiles/template_proj2_MSV2005_MKL9.0.vcproj b/CFiles/template_proj2_MSV2005_MKL9.0.vcproj new file mode 100755 index 0000000..3b7f01c --- /dev/null +++ b/CFiles/template_proj2_MSV2005_MKL9.0.vcproj @@ -0,0 +1,292 @@ +<?xml version="1.0" encoding="Windows-1252"?> +<VisualStudioProject + ProjectType="Visual C++" + Version="8.00" + Name="template_proj2" + ProjectGUID="{30EA1610-6051-4681-A29C-9D29389FE60F}" + Keyword="Win32Proj" + > + <Platforms> + <Platform + Name="Win32" + /> + </Platforms> + <ToolFiles> + </ToolFiles> + <Configurations> + <Configuration + Name="Debug|Win32" + OutputDirectory="Debug" + IntermediateDirectory="Debug" + ConfigurationType="1" + InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC70.vsprops" + CharacterSet="2" + > + <Tool + Name="VCPreBuildEventTool" + /> + <Tool + Name="VCCustomBuildTool" + /> + <Tool + Name="VCXMLDataGeneratorTool" + /> + <Tool + Name="VCWebServiceProxyGeneratorTool" + /> + <Tool + Name="VCMIDLTool" + /> + <Tool + Name="VCCLCompilerTool" + Optimization="0" + PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE" + MinimalRebuild="true" + BasicRuntimeChecks="3" + RuntimeLibrary="1" + UsePrecompiledHeader="0" + WarningLevel="3" + Detect64BitPortabilityProblems="true" + DebugInformationFormat="4" + CompileAs="1" + DisableSpecificWarnings="4996" + /> + <Tool + Name="VCManagedResourceCompilerTool" + /> + <Tool + Name="VCResourceCompilerTool" + /> + <Tool + Name="VCPreLinkEventTool" + /> + <Tool + Name="VCLinkerTool" + AdditionalDependencies="netapi32.lib advapi32.lib gdi32.lib comdlg32.lib comctl32.lib wsock32.lib" + LinkIncremental="2" + IgnoreAllDefaultLibraries="false" + IgnoreDefaultLibraryNames="libcd.lib;libc.lib;libcmtd.lib" + GenerateDebugInformation="true" + SubSystem="1" + TargetMachine="1" + /> + <Tool + Name="VCALinkTool" + /> + <Tool + Name="VCManifestTool" + /> + <Tool + Name="VCXDCMakeTool" + /> + <Tool + Name="VCBscMakeTool" + /> + <Tool + Name="VCFxCopTool" + /> + <Tool + Name="VCAppVerifierTool" + /> + <Tool + Name="VCWebDeploymentTool" + /> + <Tool + Name="VCPostBuildEventTool" + /> + </Configuration> + <Configuration + Name="Release|Win32" + OutputDirectory="Release" + IntermediateDirectory="Release" + ConfigurationType="1" + InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC70.vsprops" + CharacterSet="2" + > + <Tool + Name="VCPreBuildEventTool" + /> + <Tool + Name="VCCustomBuildTool" + /> + <Tool + Name="VCXMLDataGeneratorTool" + /> + <Tool + Name="VCWebServiceProxyGeneratorTool" + /> + <Tool + Name="VCMIDLTool" + /> + <Tool + Name="VCCLCompilerTool" + Optimization="2" + InlineFunctionExpansion="2" + EnableIntrinsicFunctions="true" + FavorSizeOrSpeed="1" + OmitFramePointers="true" + EnableFiberSafeOptimizations="false" + WholeProgramOptimization="false" + PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE" + StringPooling="true" + RuntimeLibrary="0" + EnableFunctionLevelLinking="true" + UsePrecompiledHeader="0" + WarningLevel="3" + Detect64BitPortabilityProblems="true" + DebugInformationFormat="3" + CompileAs="1" + DisableSpecificWarnings="4996" + /> + <Tool + Name="VCManagedResourceCompilerTool" + /> + <Tool + Name="VCResourceCompilerTool" + /> + <Tool + Name="VCPreLinkEventTool" + /> + <Tool + Name="VCLinkerTool" + AdditionalDependencies="netapi32.lib advapi32.lib gdi32.lib comdlg32.lib comctl32.lib wsock32.lib" + LinkIncremental="1" + IgnoreDefaultLibraryNames="libcd.lib;libc.lib" + GenerateDebugInformation="false" + SubSystem="1" + OptimizeReferences="2" + EnableCOMDATFolding="2" + TargetMachine="1" + /> + <Tool + Name="VCALinkTool" + /> + <Tool + Name="VCManifestTool" + /> + <Tool + Name="VCXDCMakeTool" + /> + <Tool + Name="VCBscMakeTool" + /> + <Tool + Name="VCFxCopTool" + /> + <Tool + Name="VCAppVerifierTool" + /> + <Tool + Name="VCWebDeploymentTool" + /> + <Tool + Name="VCPostBuildEventTool" + /> + </Configuration> + </Configurations> + <References> + </References> + <Files> + <Filter + Name="Source Files" + Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm" + > + <File + RelativePath="D:\ZhaData\TZCcode\congradmin.c" + > + </File> + <File + RelativePath="D:\ZhaData\TZCcode\csminwel.c" + > + </File> + <File + RelativePath="D:\ZhaData\TZCcode\cstz.c" + > + </File> + <File + RelativePath="D:\ZhaData\TZCcode\DWMatrixCode\extern_dw_switch.c" + > + </File> + <File + RelativePath="D:\ZhaData\TZCcode\fn_filesetup.c" + > + </File> + <File + RelativePath="D:\ZhaData\TZCcode\gradcd_switch.c" + > + </File> + <File + RelativePath="D:\ZhaData\TZCcode\gensys.c" + > + </File> + <File + RelativePath="D:\ZhaData\TZCcode\kalman.c" + > + </File> + <File + RelativePath="D:\ZhaData\TZCcode\mathlib.c" + > + </File> + <File + RelativePath="D:\ZhaData\TZCcode\optpackage.c" + > + </File> + <File + RelativePath="D:\ZhaData\TZCcode\rand.c" + > + </File> + <File + RelativePath="D:\ZhaData\TZCcode\tzmatlab.c" + > + </File> + </Filter> + <Filter + Name="Header Files" + Filter="h;hpp;hxx;hm;inl;inc" + > + </Filter> + <Filter + Name="Resource Files" + Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" + > + </Filter> + <File + RelativePath="C:\Program Files\VNI\imsl\cnl600\vs05pc\lib\imslcmath.lib" + > + </File> + <File + RelativePath="C:\Program Files\VNI\imsl\cnl600\vs05pc\lib\imslcmath_iblas.lib" + > + </File> + <File + RelativePath="C:\Program Files\VNI\imsl\cnl600\vs05pc\lib\imslcmath_scalar.lib" + > + </File> + <File + RelativePath="C:\Program Files\VNI\imsl\cnl600\vs05pc\lib\imslcstat.lib" + > + </File> + <File + RelativePath="C:\Program Files\VNI\imsl\cnl600\vs05pc\lib\imslcstat_iblas.lib" + > + </File> + <File + RelativePath="D:\Program Files\Microsoft Visual Studio 8\VC\lib\libcmt.lib" + > + </File> + <File + RelativePath="D:\Program Files\Microsoft Visual Studio 8\VC\lib\libcmtd.lib" + > + </File> + <File + RelativePath="C:\Program Files\Intel\MKL\9.0\ia32\lib\libguide40.lib" + > + </File> + <File + RelativePath="C:\Program Files\Intel\MKL\9.0\ia32\lib\mkl_c.lib" + > + </File> + </Files> + <Globals> + </Globals> +</VisualStudioProject> diff --git a/CFiles/tzmatlab.c b/CFiles/tzmatlab.c new file mode 100755 index 0000000..b6c59d4 --- /dev/null +++ b/CFiles/tzmatlab.c @@ -0,0 +1,831 @@ +/** Example: + #if defined (USE_DEBUG_FILE) + fprintf(FPTR_DEBUG, "\nWARNING: .../mathlib.c/TransposeSquare(): the matrix is already both SU and SL, so there is no need to transpose.\n"); + fflush(FPTR_DEBUG); + #else + fprintf(stdout, "\nWARNING: .../mathlib.c/TransposeSquare(): the matrix is already both SU and SL, so there is no need to transpose.\n"); + fflush(stdout); + #endif +/**/ + + +#include "tzmatlab.h" + + +FILE *FPTR_DEBUG = (FILE *)NULL; //Debug output file, to be opened by main.c. +FILE *FPTR_OPT = (FILE *)NULL; //Optimization output file, to be opened by main.c. + +//----------------- +// Some high-level functions. +//----------------- +int fn_locofyearqm(int q_m, int yrstart, int qmstart, int yrend, int qmend) +{ + //Returns the (base 0) location of a specified year and month (quarter) for the time series. + //All the other inputs take the usual (base-1) numbers, I guess 01/17/05. For example, yrstart = 1960 means the year 1960. + int tmpi, loc; + + if ( q_m != 12 ) + if ( q_m != 4 ) fn_DisplayError(".../tzmatlab.c/fn_locofyearqm(): This function only works for monthly or quarterly data"); + + if ( (tmpi=yrend - yrstart) < 0 ) + fn_DisplayError(".../cstz.c/fn_locofyearqm(): the end year must be greater than or equal to the start year"); + else if ( (loc = (tmpi==0) ? qmend-qmstart : tmpi*q_m+qmend-qmstart) < 0 ) + fn_DisplayError(".../tzmatlab.c/fn_locofyearqm(): the end month or quarter must be greater than or equal to the start month or quarter for the given year"); + + return (loc); +} + + + +//----------------- +// Function to display errors. +//----------------- +void fn_DisplayError(char *msg_s) +{ + #if defined (USE_DEBUG_FILE) + fprintf(FPTR_DEBUG, "\nFatal Error:\n" + " %s!\n", msg_s); + fflush(FPTR_DEBUG); + #else + fprintf(stdout, "\nFatal Error:\n" + "\t %s!\n", msg_s); + fflush(stdout); + #endif + + #ifdef WIN_MATLABAPI + mexErrMsgTxt("."); + #else + //getchar(); + exit( EXIT_FAILURE ); // This exits the entire C program. + #endif +} + + +//----------------- +// Error-checking memory allocators +//----------------- +void *m_alloc(size_t size) { + void *new_mem; + if ( (new_mem = malloc(size)) == NULL ) fn_DisplayError("Out of Memory!"); + return(new_mem); +} +//+ +void *c_alloc(size_t elt_count, size_t elt_size) { + void *new_mem; + if ( (new_mem = calloc(elt_count, elt_size)) == NULL ) fn_DisplayError("Out of Memory!"); + return(new_mem); +} + + +//----------------- +// Creat and destroy vectors, matrices, and cells. +//----------------- +/** +TSvoidvector *CreateVector_void(int _n) +{ + TSvoidvector *x_voidv = tzMalloc(1, TSvoidvector); + x_voidv->flag = V_UNDEF; + x_voidv->n = _n; + x_voidv->v = tzMalloc(_n, void); + return(x_voidv); +} +TSvoidvector *DestroyVector_void(TSvoidvector *x_voidv) +{ + if (x_voidv) { + free(x_voidv->v); + free(x_voidv); + return ((TSvoidvector *)NULL); + } + else return (x_voidv); +} +/**/ + + +TScvector *CreateVector_c(int _n) +{ + TScvector *x_cv = tzMalloc(1, TScvector); + x_cv->flag = V_UNDEF; + x_cv->n = _n; + if (_n<1) fn_DisplayError(".../tzmatlab.c/CreateVector_c(): dimension input _n must be a positive integer"); + x_cv->v = tzMalloc(_n, char); + return( x_cv ); +} +TScvector *DestroyVector_c(TScvector *x_cv) +{ + if (x_cv) { + free(x_cv->v); + free(x_cv); + return ((TScvector *)NULL); + } + else return (x_cv); +} + +TSivector *CreateVector_int(int _n) +{ + TSivector *x_iv=tzMalloc(1, TSivector); + x_iv->flag = V_UNDEF; + x_iv->n = _n; + if (_n<1) fn_DisplayError(".../tzmatlab.c/CreateVector_int(): dimension input _n must be a positive integer"); + x_iv->v = tzMalloc(_n, int); + return(x_iv); +} +TSivector *DestroyVector_int(TSivector *x_iv) +{ + if (x_iv) { + free(x_iv->v); + free(x_iv); + return ((TSivector *)NULL); + } + else return (x_iv); +} + +TSimatrix *CreateMatrix_int(int nrows, int ncols) +{ + TSimatrix *x_im=tzMalloc(1, TSimatrix); + x_im->nrows = nrows; + x_im->ncols = ncols; + if (nrows<1 || ncols<1) fn_DisplayError(".../tzmatlab.c/CreateMatrix_int(): dimension inputs nrows and ncols must both be positive integers"); + x_im->M = tzMalloc(nrows*ncols, int); + return (x_im); +} +TSimatrix *DestroyMatrix_int(TSimatrix *x_im) +{ + if (x_im) { + free(x_im->M); + free(x_im); + return ((TSimatrix *)NULL); + } + else return (x_im); +} + +TSicellvec *CreateCellvec_int(TSivector *n_iv) +{ + int _i, + ncells; + TSicellvec *x_icv = tzMalloc(1, TSicellvec); + + if (!n_iv || !n_iv->flag) fn_DisplayError(".../CreateCellvec_int( ): Dimension vector n_iv must (1) created and (2) assigned legal values"); + x_icv->ncells = ncells = n_iv->n; + x_icv->C = tzMalloc(ncells, TSivector *); + for (_i=ncells-1; _i>-0; _i--) *(x_icv->C + _i) = CreateVector_int(n_iv->v[_i]); + return(x_icv); +} +TSicellvec *DestroyCellvec_int(TSicellvec *x_icv) +{ + int _i; + if (x_icv) { + for (_i=0; _i<x_icv->ncells; _i++) DestroyVector_int(x_icv->C[_i]); + free(x_icv->C); + free(x_icv); + return ((TSicellvec *)NULL); + } + else return (x_icv); +} + +TSicell *CreateCell_int(TSivector *row_iv, TSivector *col_iv) +{ + int _i, + ncells; + TSicell *x_ic=NULL; + if (!row_iv || !col_iv || !row_iv->flag || !col_iv->flag) fn_DisplayError(".../CreateCell_int( ): Dimension vectors row_iv and col_iv must (1) created and (2) assigned legal values"); + if ((ncells = row_iv->n) != col_iv->n) fn_DisplayError(".../CreateCell_int( ): the lengths of row_iv and col_iv (i.e., numbers of cells) must be the same"); + x_ic = tzMalloc(1, TSicell); + x_ic->ncells = ncells; + x_ic->C = tzMalloc(ncells, TSimatrix *); + for (_i=ncells-1; _i>=0; _i--) { + *(x_ic->C + _i) = CreateMatrix_int(row_iv->v[_i], col_iv->v[_i]); + } + return(x_ic); +} +TSicell *DestroyCell_int(TSicell *x_ic) +{ + int _i; + if (x_ic) { + for (_i=x_ic->ncells-1; _i>=0; _i--) x_ic->C[_i] = DestroyMatrix_int(x_ic->C[_i]); + tzDestroy(x_ic->C); + free(x_ic); + return ((TSicell *)NULL); + } + else return (x_ic); +} + + + + +TSdvector *CreateVector_lf(int _n) +{ + TSdvector *x_dv=tzMalloc(1, TSdvector); + x_dv->flag = V_UNDEF; + x_dv->n = _n; + if (_n<1) fn_DisplayError(".../tzmatlab.c/CreateVector_lf(): dimension input _n must be a positive integers"); + x_dv->v = tzMalloc(_n, double); + return(x_dv); +} +TSdvector *DestroyVector_lf(TSdvector *x_dv) +{ + if (x_dv) { + free(x_dv->v); + free(x_dv); + return ((TSdvector *)NULL); + } + else return (x_dv); +} + +TSdmatrix *CreateMatrix_lf(int nrows, int ncols) +{ + TSdmatrix *x_dm=tzMalloc(1, TSdmatrix); + x_dm->flag = M_UNDEF; + x_dm->nrows = nrows; + x_dm->ncols = ncols; + if (nrows<1 || ncols<1) fn_DisplayError(".../tzmatlab.c/CreateMatrix_lf(): dimension inputs nrows and ncols must both be positive integers"); + x_dm->M = tzMalloc(nrows*ncols, double); + return(x_dm); +} +TSdmatrix *DestroyMatrix_lf(TSdmatrix *x_dm) +{ + if (x_dm) { + free(x_dm->M); + free(x_dm); + return ((TSdmatrix *)NULL); + } + else return (x_dm); +} + +TSdcell *CreateCell_lf(TSivector *row_iv, TSivector *col_iv) +{ + int _i, + ncells; + TSdcell *x_dc=NULL; + //-------------- The following line must be enacted when we produce new code in the future. --------------------- + //-------------- In old code I forgot to set the flags for row_iv and col_iv but change them in all places are too time-consuming at this point. --------------------- + //if (!row_iv || !col_iv || !row_iv->flag || !col_iv->flag) fn_DisplayError(".../CreateCell_lf( ): Dimension vectors row_iv and col_iv must (1) created and (2) assigned legal values"); + if ((ncells = row_iv->n) != col_iv->n) fn_DisplayError(".../CreateCell_lf( ): the lengths of row_iv and col_iv (i.e., numbers of cells) must be the same"); + x_dc = tzMalloc(1, TSdcell); + x_dc->ncells = ncells; + x_dc->C = tzMalloc(ncells, TSdmatrix *); + for (_i=ncells-1; _i>=0; _i--) { + *(x_dc->C + _i) = CreateMatrix_lf(row_iv->v[_i], col_iv->v[_i]); + } + return(x_dc); +} +TSdcell *DestroyCell_lf(TSdcell *x_dc) +{ + int _i; + if (x_dc) { + for (_i=x_dc->ncells-1; _i>=0; _i--) x_dc->C[_i] = DestroyMatrix_lf(x_dc->C[_i]); + tzDestroy(x_dc->C); + free(x_dc); + return ((TSdcell *)NULL); + } + else return (x_dc); +} + +TSdcellvec *CreateCellvec_lf(TSivector *n_iv) { + TSdcellvec *x_dcv = tzMalloc(1, TSdcellvec); + int _i, + ncells; + //-------------- The following line must be enacted when we produce new code in the future. --------------------- + //-------------- In old code I forgot to set the flag for n_iv but change it in all places are too time-consuming at this point. --------------------- + //if (!n_iv || !n_iv->flag) fn_DisplayError(".../CreateCellvec_lf( ): Dimension vector n_iv must (1) created and (2) assigned legal values"); + x_dcv->ncells = ncells = n_iv->n; + x_dcv->C = tzMalloc(ncells, TSdvector *); + for (_i=0; _i<ncells; _i++) *(x_dcv->C + _i) = CreateVector_lf(n_iv->v[_i]); + return(x_dcv); +} +TSdcellvec *DestroyCellvec_lf(TSdcellvec *x_dcv) { + int _i; + if (x_dcv) { + for (_i=x_dcv->ncells-1; _i>=0; _i--) DestroyVector_lf(x_dcv->C[_i]); + free(x_dcv->C); + free(x_dcv); + return ((TSdcellvec *)NULL); + } + else return (x_dcv); +} + +TSdfourth *CreateFourth_lf(int ndims, TSivector *row_iv, TSivector *col_iv) { + int _i; + TSdfourth *x_d4 = NULL; + //if (row_iv->n != col_iv->n) fn_DisplayError(".../CreateFourth_lf( ): the lengths of row_iv and col_iv (i.e., sizes of dimensions) must be the same"); + + x_d4 = tzMalloc(1, TSdfourth); + x_d4->ndims = ndims; + x_d4->F = tzMalloc(ndims, TSdcell *); + for (_i=ndims-1; _i>=0; _i--) { + *(x_d4->F + _i) = CreateCell_lf(row_iv, col_iv); + } + return(x_d4); +} +TSdfourth *DestroyFourth_lf(TSdfourth *x_d4) { + int _i; + if (x_d4) { + for (_i=x_d4->ndims-1; _i>=0; _i--) DestroyCell_lf(x_d4->F[_i]); + free(x_d4->F); + free(x_d4); + return ((TSdfourth *)NULL); + } + else return (x_d4); +} + +TSdfourthvec *CreateFourthvec_lf(int ndims, TSivector *n_iv) +{ + int _i; + TSdfourthvec *x_d4v = NULL; + //if (n_iv->n != col_iv->n) fn_DisplayError(".../CreateFourth_lf( ): the lengths of n_iv and col_iv (i.e., sizes of dimensions) must be the same"); + + x_d4v = tzMalloc(1, TSdfourthvec); + x_d4v->ndims = ndims; + x_d4v->F = tzMalloc(ndims, TSdcellvec *); + for (_i=ndims-1; _i>=0; _i--) { + *(x_d4v->F + _i) = CreateCellvec_lf(n_iv); + } + return(x_d4v); +} +TSdfourthvec *DestroyFourthvec_lf(TSdfourthvec *x_d4v) +{ + int _i; + if (x_d4v) { + for (_i=x_d4v->ndims-1; _i>=0; _i--) DestroyCellvec_lf(x_d4v->F[_i]); + free(x_d4v->F); + free(x_d4v); + return ((TSdfourthvec *)NULL); + } + else return (x_d4v); +} + +TSdzvector *CreateVector_dz(int _n) +{ + TSdzvector *x_dzv=tzMalloc(1, TSdzvector); + x_dzv->real = CreateVector_lf(_n); + x_dzv->imag = CreateVector_lf(_n); + return( x_dzv ); +} +TSdzvector *DestroyVector_dz(TSdzvector *x_dzv) +{ + if (x_dzv) { + DestroyVector_lf(x_dzv->real); + DestroyVector_lf(x_dzv->imag); + free(x_dzv); + return ((TSdzvector *)NULL); + } + else return (x_dzv); +} + +TSdzmatrix *CreateMatrix_dz(int nrows, int ncols) { + TSdzmatrix *x_dzm=tzMalloc(1, TSdzmatrix); + x_dzm->real = CreateMatrix_lf(nrows, ncols); + x_dzm->imag = CreateMatrix_lf(nrows, ncols); + return( x_dzm ); +} +TSdzmatrix *DestroyMatrix_dz(TSdzmatrix *x_dzm) +{ + if (x_dzm) { + DestroyMatrix_lf(x_dzm->real); + DestroyMatrix_lf(x_dzm->imag); + free(x_dzm); + return ((TSdzmatrix *)NULL); + } + else return (x_dzm); +} + + + +//----------------- +// Creates special vectors, matrices, and cells but uses the same destroy utilities as above. +//----------------- +//=== Creates two special matrices: zeros and identity. Use DestroyMatrix_lf to free the memory allocated to these functions. +TSdmatrix *CreateZeroMatrix_lf(const int nrows, const int ncols) { + int _i; + TSdmatrix *x_dm=CreateMatrix_lf(nrows, ncols); + //x_dm->flag = M_GE | M_SU | M_SL | M_UT | M_LT; + x_dm->flag = M_GE; + for (_i=nrows*ncols-1; _i>=0; _i--) + x_dm->M[_i] = 0.0; + return(x_dm); +} +TSdmatrix *CreateIdentityMatrix_lf(const int nrows, const int ncols) { + int _i; + TSdmatrix *x_dm=CreateZeroMatrix_lf(nrows, ncols); + if (nrows==ncols) { + //x_dm->flag = M_GE | M_SU | M_SL | M_UT | M_LT; + //x_dm->flag = M_GE; + for (_i=square(nrows)-1; _i>=0; _i -= nrows+1) x_dm->M[_i] = 1.0; + x_dm->flag = M_GE | M_SU | M_SL | M_UT | M_LT; + } + else if (nrows<ncols) { + //x_dm->flag = M_GE | M_SU | M_UT; + //x_dm->flag = M_GE; + for (_i=square(nrows)-1; _i>=0; _i -= nrows+1) x_dm->M[_i] = 1.0; + x_dm->flag = M_GE | M_UT | M_LT; + } + else { + //x_dm->flag = M_GE | M_SL | M_LT; + //x_dm->flag = M_GE; + for (_i=(ncols-1)*(nrows+1); _i>=0; _i -= nrows+1) x_dm->M[_i] = 1.0; + x_dm->flag = M_GE | M_UT | M_LT; + } + return(x_dm); +} + +//=== Other speicial matrices. +TSivector *CreateConstantVector_int(const int _n, const int _k) { + //Inputs: + // _k: Integer constant; + // _n: Dimension of the vector. + int _i; + TSivector *x_iv=CreateVector_int(_n); + for (_i=_n-1; _i>=0; _i--) + x_iv->v[_i] = _k; + x_iv->flag = V_DEF; + return(x_iv); +} + +TSimatrix *CreateConstantMatrix_int(const int nrows, const int ncols, const int _n) +{ + int _i; + TSimatrix *x_im=CreateMatrix_int(nrows, ncols); + + for (_i=nrows*ncols-1; _i>=0; _i--) x_im->M[_i] = _n; + if ( nrows==ncols ) x_im->flag = M_GE | M_SU | M_SL | M_CN; + else x_im->flag = M_GE | M_CN; + return(x_im); +} + +TSicellvec *CreateConstantCellvec_int(TSivector *n_iv, const int _n) +{ + int _i, + ncells; + TSicellvec *x_icv = tzMalloc(1, TSicellvec); + + if (!n_iv || !n_iv->flag) fn_DisplayError(".../CreateCellvec_int( ): Dimension vector n_iv must (1) created and (2) assigned legal values"); + x_icv->ncells = ncells = n_iv->n; + x_icv->C = tzMalloc(ncells, TSivector *); + for (_i=ncells-1; _i>=0; _i--) *(x_icv->C + _i) = CreateConstantVector_int(n_iv->v[_i], _n); + return(x_icv); +} + +TSicell *CreateConstantCell_int(TSivector *row_iv, TSivector *col_iv, const int _n) +{ + int _i, + ncells; + TSicell *x_ic=NULL; + if (!row_iv || !col_iv || !row_iv->flag || !col_iv->flag) fn_DisplayError(".../CreateConstantCell_int( ): Dimension vectors row_iv and col_iv must (1) created and (2) assigned legal values"); + if ((ncells = row_iv->n) != col_iv->n) fn_DisplayError(".../CreateCell_int( ): the lengths of row_iv and col_iv (i.e., numbers of cells) must be the same"); + + x_ic = tzMalloc(1, TSicell); + x_ic->ncells = ncells; + x_ic->C = tzMalloc(ncells, TSimatrix *); + for (_i=ncells-1; _i>=0; _i--) *(x_ic->C + _i) = CreateConstantMatrix_int(row_iv->v[_i], col_iv->v[_i], _n); + return(x_ic); +} + + +TSdvector *CreateConstantVector_lf(const int _n, const double _alpha) { + int _i; + TSdvector *x_dv=CreateVector_lf(_n); + for (_i=_n-1; _i>=0; _i--) x_dv->v[_i] = _alpha; + x_dv->flag = V_DEF; + return(x_dv); +} + +TSdmatrix *CreateConstantMatrix_lf(const int nrows, const int ncols, const double _alpha) { + //Inputs: + // _alpha: Double constant; + // nrows and ncols: Dimensions of the matrix. + int _i; + TSdmatrix *x_dm=CreateMatrix_lf(nrows, ncols); + + for (_i=nrows*ncols-1; _i>=0; _i--) x_dm->M[_i] = _alpha; + if ( nrows==ncols ) x_dm->flag = M_GE | M_SU | M_SL | M_CN; + else x_dm->flag = M_GE | M_CN; + return(x_dm); +} + +TSdcellvec *CreateConstantCellvec_lf(TSivector *n_iv, const double _alpha) { + //Inputs: + // _alpha: Double constant; + // _n: Length (dimension) of the vector. + int _i, + ncells; + TSdcellvec *x_dcv = tzMalloc(1, TSdcellvec); + //-------------- The following line must be enacted when we produce new code in the future. --------------------- + //-------------- In old code I forgot to set the flag for n_iv but change it in all places are too time-consuming at this point. --------------------- + //if (!n_iv || !n_iv->flag) fn_DisplayError(".../CreateConstantCellvec_lf( ): Dimension vector n_iv must (1) created and (2) assigned legal values"); + x_dcv->ncells = ncells = n_iv->n; + x_dcv->C = tzMalloc(ncells, TSdvector *); + for (_i=ncells-1; _i>=0; _i--) *(x_dcv->C + _i) = CreateConstantVector_lf(n_iv->v[_i], _alpha); + return(x_dcv); +} + +TSdcell *CreateConstantCell_lf(TSivector *row_iv, TSivector *col_iv, const double _alpha) { + //Inputs: + // _alpha: Double constant; + // nrows: Number of rows; + // ncols: Number of columns. + int _i, + ncells; + TSdcell *x_dc=NULL; + //-------------- The following line must be enacted when we produce new code in the future. --------------------- + //-------------- In old code I forgot to set the flags for row_iv and col_iv but change them in all places are too time-consuming at this point. --------------------- + //if (!row_iv || !col_iv || !row_iv->flag || !col_iv->flag) fn_DisplayError(".../CreateConstantCell_lf( ): Dimension vectors row_iv and col_iv must (1) created and (2) assigned legal values"); + if ((ncells = row_iv->n) != col_iv->n) fn_DisplayError(".../CreateCell_lf( ): the lengths of row_iv and col_iv (i.e., numbers of cells) must be the same"); + + x_dc = tzMalloc(1, TSdcell); + x_dc->ncells = ncells; + x_dc->C = tzMalloc(ncells, TSdmatrix *); + for (_i=ncells-1; _i>=0; _i--) *(x_dc->C + _i) = CreateConstantMatrix_lf(row_iv->v[_i], col_iv->v[_i], _alpha); + return(x_dc); +} + + +TSdvector *CreateDatesVector_lf(int nq_m, int yrstart, int qmstart, int yrend, int qmend) +{ + //If nq_m==4, quarterly data; nq_m==12, monthly data. + //All the other inputs take the usual (base-1) numbers, I guess 01/17/05. For example, yrstart = 1960 means the year 1960. + int _t; + int samplesize = 1+fn_locofyearqm(nq_m, yrstart, qmstart, yrend, qmend); //1+ because fn_locofyearqm() returns a 0-based integer. + // + TSdvector *dates_dv = tzMalloc(1, TSdvector); + dates_dv->n = samplesize; + dates_dv->v = tzMalloc(samplesize, double); + + if (nq_m==4 || nq_m==12) { + for (_t=samplesize-1; _t>=0; _t--) dates_dv->v[_t] = (double)yrstart + (double)(qmstart+_t-1)/(double)nq_m; + dates_dv->flag = V_DEF; + } + else fn_DisplayError(".../tzmatlab.c/CreateDatesVector_lf(): Dates have to be either monthly or quarterly"); + + + return (dates_dv); +} + + + +//----------------- +// Initializes already-created special vectors, matrices, and cells. +//----------------- +void InitializeConstantVector_lf(TSdvector *x_dv, const double _alpha) +{ + //Ouputs: + // x_dv: Initialized to a constant value _alpha for all elements. + //Inputs: + // x_dv: Memory allocated already. + // _alpha: Double constant; + int _i, _n; + + if (!x_dv) fn_DisplayError(".../tzmatlab.c/InitializeConstantVector_lf(): Input vector must be created (memory-allocated)"); + else { + _n=x_dv->n; + } + for (_i=_n-1; _i>=0; _i--) x_dv->v[_i] = _alpha; + x_dv->flag = V_DEF; +} + +void InitializeConstantVector_int(TSivector *x_iv, const int _k) +{ + //Ouputs: + // x_iv: Initialized to a constant value _alpha for all elements. + //Inputs: + // x_iv: Memory allocated already. + // _alpha: Integer constant; + int _i, _n; + + if (!x_iv) fn_DisplayError(".../tzmatlab.c/InitializeConstantVector_int(): Input vector must be created (memory-allocated)"); + else { + _n=x_iv->n; + } + for (_i=_n-1; _i>=0; _i--) x_iv->v[_i] = _k; + x_iv->flag = V_DEF; +} + +void InitializeConstantMatrix_lf(TSdmatrix *x_dm, const double _alpha) +{ + //Ouputs: + // x_dm: Initialized to a constant value _alpha for all elements. + //Inputs: + // x_dm: Memory allocated already. + // _alpha: Double constant; + //See Kenneth Reek, pp.202-212. + +// int _i; +// for (_i=x_dm->nrows*x_dm->ncols-1; _i>=0; _i--) +// x_dm->M[_i] = _alpha; +// int nrows, ncols; + double *ptrcnt, *lastptr; + + if ( !x_dm) fn_DisplayError(".../tzmathlab.c/InitializeConstantMatrix_int(): Input matrix must be created (memory-allocated)"); + else { +// nrows = x_dm->nrows; +// ncols = x_dm->ncols; + lastptr = (ptrcnt = x_dm->M) + x_dm->nrows * x_dm->ncols; + } + +// if (nrows==ncols) x_dm->flag = M_GE | M_SU | M_SL; +// else if (nrows<ncols) x_dm->flag = M_GE | M_SU; +// else x_dm->flag = M_GE | M_SL; + x_dm->flag = M_GE | M_CN; + for ( ; ptrcnt<lastptr; ptrcnt++ ) *ptrcnt = _alpha; +} + +void InitializeDiagonalMatrix_lf(TSdmatrix *x_dm, const double _alpha) { + int _i, n2, nrows, ncols; + double *M; + + if ( !x_dm ) fn_DisplayError(".../tzmathlab.c/InitializeIdentiyMatrix_lf(): (1) Input matrix must be created (memory-allocated)"); + else { + nrows = x_dm->nrows; + ncols = x_dm->ncols; + M = x_dm->M; + } + + if (nrows==ncols) { + for (_i=(n2=square(nrows))-1; _i>=0; _i--) M[_i] = 0.0; + for (_i=n2-1; _i>=0; _i -= nrows+1) M[_i] = _alpha; + x_dm->flag = M_GE | M_SU | M_SL | M_UT | M_LT; + } + else if (nrows<ncols) { + for (_i=nrows*ncols-1; _i>=0; _i--) M[_i] = 0.0; + for (_i=square(nrows)-1; _i>=0; _i -= nrows+1) M[_i] = _alpha; + x_dm->flag = M_GE | M_UT | M_LT; + } + else { + for (_i=nrows*ncols-1; _i>=0; _i--) M[_i] = 0.0; + for (_i=(ncols-1)*(nrows+1); _i>=0; _i -= nrows+1) M[_i] = _alpha; + x_dm->flag = M_GE | M_UT | M_LT; + } +} + +void InitializeConstantMatrix_int(TSimatrix *x_im, const int _alpha) { + //Ouputs: + // x_im: Initialized to a constant value _alpha for all elements. + //Inputs: + // x_im: Memory allocated already. + // _alpha: Integer constant; + // + //See Kenneth Reek, pp.202-212. + + +// int _i; +// for (_i=x_im->nrows*x_im->ncols-1; _i>=0; _i--) +// x_im->M[_i] = _alpha; + + int *ptrcnt, *lastptr; + + if ( !x_im) fn_DisplayError(".../tzmathlab.c/InitializeConstantMatrix_int(): Input matrix must be created (memory-allocated)"); + else lastptr = (ptrcnt = x_im->M) + x_im->nrows * x_im->ncols; + + for ( ; ptrcnt<lastptr; ptrcnt++ ) *ptrcnt = _alpha; +} + +void InitializeConstantCellvec_lf(TSdcellvec *x_dcv, const double _alpha) { + //Ouputs: + // x_dcv: Initialized to a constant value _alpha for all elements. + //Inputs: + // x_dcv: Memory allocated already. + // _alpha: Double constant; + int _i, _k, _n; + double *v; + + if ( !x_dcv ) fn_DisplayError(".../tzmatlab.c/InitializeConstantCellvec_lf(): Input cell vector must be created (memory-allocated)"); + + + for (_i=x_dcv->ncells-1; _i>=0; _i--) { + v = x_dcv->C[_i]->v; + _n = x_dcv->C[_i]->n; + for (_k=_n-1; _k>=0; _k--) v[_k] = _alpha; + x_dcv->C[_i]->flag = V_DEF; + } +} + +void InitializeConstantCell_lf(TSdcell *x_dc, const double _alpha) +{ + //Ouputs: + // x_dc: Initialized to a constant value _alpha for all elements. + //Inputs: + // x_dc: Memory allocated already. + // _alpha: Double constant; + int _i, _k, nrows, ncols; + double *M; + + if ( !x_dc ) fn_DisplayError(".../tzmatlab.c/InitializeConstantCell_lf(): Input cell must be created (memory-allocated)"); + + + for (_i=x_dc->ncells-1; _i>=0; _i--) { + M = x_dc->C[_i]->M; + nrows = x_dc->C[_i]->nrows; + ncols = x_dc->C[_i]->ncols; +// if (nrows==ncols) x_dc->C[_i]->flag = M_GE | M_SU | M_SL; +// else if (nrows<ncols) x_dc->C[_i]->flag = M_GE | M_SU; +// else x_dc->C[_i]->flag = M_GE | M_SL; + for (_k=nrows*ncols-1; _k>=0; _k--) M[_k] = _alpha; + x_dc->C[_i]->flag = M_GE | M_CN; + } +} + + + +void InitializeConstantFourthvec_lf(TSdfourthvec *x_d4v, const double _alpha) { + //Ouputs: + // x_d4v: Initialized to a constant value _alpha for all elements. + //Inputs: + // x_d4v: Memory allocated already. + // _alpha: Double constant; + int _j, _i, _k; + double *v; + + if ( !x_d4v ) fn_DisplayError(".../tzmatlab.c/InitializeConstantFourthvec_lf(): Input fourth must be created (memory-allocated)"); + + for (_j=x_d4v->ndims-1; _j>=0; _j--) { + for (_i=x_d4v->F[_j]->ncells-1; _i>=0; _i--) { + v = x_d4v->F[_j]->C[_i]->v; + for (_k=x_d4v->F[_j]->C[_i]->n-1; _k>=0; _k--) v[_k] = _alpha; + x_d4v->F[_j]->C[_i]->flag = V_DEF; + } + } +} +void InitializeConstantFourth_lf(TSdfourth *x_d4, const double _alpha) { + //Ouputs: + // x_d4: Initialized to a constant value _alpha for all elements. + //Inputs: + // x_d4: Memory allocated already. + // _alpha: Double constant; + int _j, _i, _k, nrows, ncols; + double *M; + + if ( !x_d4 ) fn_DisplayError(".../tzmatlab.c/InitializeConstantFourth_lf(): Input fourth must be created (memory-allocated)"); + + for (_j=x_d4->ndims-1; _j>=0; _j--) { + for (_i=x_d4->F[_j]->ncells-1; _i>=0; _i--) { + M = x_d4->F[_j]->C[_i]->M; + nrows = x_d4->F[_j]->C[_i]->nrows; + ncols = x_d4->F[_j]->C[_i]->ncols; + for (_k=nrows*ncols-1; _k>=0; _k--) M[_k] = _alpha; + x_d4->F[_j]->C[_i]->flag = M_GE | M_CN; + } + } +} + + +void NegateColofMatrix_lf(TSdvector *y_dv, TSdmatrix *X_dm, int jx) { + //Ouputs: + // If y_dv!=NULL, y_dv is the negative of the jx_th column of X_dm (i.e., multiplied by -1.0). + // If !y_dv, the jx_th column of X_dm is replaced by its negated value (i.e., multiplied by -1.0). + //Inputs: + // X_dm: Memory allocated and legal values given already. + // jx: The jx_th column of X_dm. + + int _i, nrows_x; + double *M, *v; + + if ( !X_dm || !X_dm->flag ) fn_DisplayError(".../tzmathlab.c/NegateColumnofMatrix_lf(): (1) input matrix must be created (memory-allocated); (2) legal values must be given"); + if (jx >= X_dm->ncols) fn_DisplayError(".../tzmathlab.c/NegateColumnofMatrix_lf(): The jx_th column specified exceeds the column dimension of the input matrix"); + + M = X_dm->M + (jx+1)*(nrows_x=X_dm->nrows) - 1; //Points to the end of the jx_th column. + if ( !y_dv ) + for (_i=nrows_x-1; _i>=0; _i--, M--) *M = -(*M); + else { + for (_i=nrows_x-1, v=y_dv->v+_i; _i>=0; _i--, M--, v--) *v = -(*M); + y_dv->flag = V_DEF; + } +} + + +void InitializeConstantColofMatrix_lf(TSdmatrix *X_dm, int jx, double _alpha) { + //Ouputs: + // The jx_th column of X_dm is replaced by its original value multiplied by _alpha. + //Inputs: + // X_dm: Memory allocated and legal values given already. + // jx: The jx_th column of X_dm. + // _alpha: A double constant. + + int _i, nrows_x; + double *M; + + if ( !X_dm || !X_dm->flag ) fn_DisplayError(".../tzmathlab.c/NegateColumnofMatrix_lf(): (1) input matrix must be created (memory-allocated); (2) legal values must be given"); + if (jx >= X_dm->ncols) fn_DisplayError(".../tzmathlab.c/NegateColumnofMatrix_lf(): The jx_th column specified exceeds the column dimension of the input matrix"); + + M = X_dm->M + (jx+1)*(nrows_x=X_dm->nrows) - 1; //Points to the end of the jx_th column. + for (_i=nrows_x-1; _i>=0; _i--, M--) *M = _alpha; +} + + + + +//----------------- +// Open files. +//----------------- +FILE *tzFopen(char *filename, char *mode) { + FILE *fptr_dummy; + + if (filename) + { + if ( !(fptr_dummy = fopen(filename,mode)) ) { + printf("\n\n...tzmatlab.c/tzFopen(): Fatal Error -- unable to write, read, or append the file %s!\n", filename); + //getchar(); + exit(EXIT_FAILURE); + } + } + else fn_DisplayError(".../tzmatlab.c/tzFopen(): the input filename must exit"); + + return (fptr_dummy); +} diff --git a/CFiles/tzmatlab.h b/CFiles/tzmatlab.h new file mode 100755 index 0000000..5c7c2d2 --- /dev/null +++ b/CFiles/tzmatlab.h @@ -0,0 +1,326 @@ +/********* + * _cv: Pointer to TScvector (character vector). + * _iv: Pointer to TSivector (integer vector). + * _im: Pointer to TSimatrix (integer matrix). + * _dv: Pointer to TSdvector (double vector). + * _dm: Pointer to TSdmatrix (double matrix). + * _dc: Pointer to TSdcell (double cell -- pointer to pointer to a matrix). + * _dcv: Pointer to TSdcellvec (double cell -- pointer to pointer to a vector). + * _d4: Pointer to TSdfourth (double fourth dimension -- pointer to pointer to pointer to a matrix). + * _dzv: Pointer to TSdzvector (double complex vector). + * _dzm: Pointer to TSdzmatrix (double complex matrix). + * + * _s: structure variable. + * _ps: pointer to a structure. + * _sv: an array of structures. + * + * _sdv: structure (NOT pointer to structure) that contains TSdvector. + * _sdm: structure (NOT pointer to structure) that contains TSdmatrix. + * + * ???????? OLD NOTATIONS ?????????? + * _v: C row or column vector pointer. + * _vint: C row or column vector pointer to integer. + * _m: C matrix pointer. + * _mint: C matrix pointer to integer. + * _m3: C 3-D matrix pointer. + * _ppm: C pointer to pointer to a matrix. + * d_???_ppm: the number of pointers that are pointed to by _ppm. + * rv_???_ppm: a vector (with dimension d_???_ppm) pointer of numbers of rows, each of the numbers coresponding to a pointed matrix. + * cv_???_ppm: a vector (with dimension d_???_ppm) pointer of numbers of columns, each of the numbers coresponding to a pointed matrix. + * d_???_v: dimension size. + * r_???_m: numbers of rows. + * c_???_m: number of columns. + * r_???_m3: number of rows. + * c_???_m3: number of columns. + * t_???_m3: number of a third dimension. +*********/ + + +#ifndef __TZMATLAB__ +#define __TZMATLAB__ + #define _ISOC99_SOURCE //Using C99 features for gcc or icc on Linux. Must be placed as the first line above all #include lines. + + #include <stdio.h> + #include <stdlib.h> // For rand(), size_t, exit, malloc, free, qsort, EXIT_FAILURE. + #include <memory.h> //For memcpy, etc. Alternative: string.h + #include <math.h> //For isfinite. + #include <float.h> //For DBL_MIN, etc. + #include <time.h> //For time(), etc. + + + + //#include "mkl_cblas.h" // Intel MKL C Blas library. + #include "mkl.h" //This includes mkl_cblas.h and mkl_lapack.h. + #include <imsl.h> //IMSL math package. + #include <imsls.h> //IMSL statistical package. + + #define USE_DEBUG_FILE //When defined, one must use tzFopen to give the file name in the main .c file. + extern FILE *FPTR_DEBUG; //For debugging. Applied to all functions and all .c files that call tzmatlab.h. + //Initiated to NULL in tzmatlab.c. + //Must use tzFopen to give the file name in the main .c file. + extern FILE *FPTR_OPT; //For recording the optimization intermediate results. + //Applied to minfinder_blockcsminwel() in optpackage.c. + //Initiated to NULL in tzmatlab.c. + //Must use tzFopen to give the file name in the main .c file. + + #define NEWVERSIONofDW_SWITCH //If defined, using DW's new switch program (implemented in 2008), + // which may be incompatible with previous programs, such as ...\SargentWZ2\EstProbModel\EstimationJuly07USED + //If undef, using the old, working switch program for, say, ...\SargentWZ2\EstProbModel\EstimationJuly07USED. + //Files that are affected are: cstz.c, kalman.c, optpackage.c, + + + #define SWITCHTOIMSLCMATH // define: use IMSL special functions like gammlog; undef: use my own default code if it exists. + + //-------Only one of the following for math library.-------- + #define INTELCMATHLIBRARY // define: use Intel MKL LAPACK library; undef: use others. + //#define IMSLCMATHLIBRARY // define: use IMSL C Math library; undef: use others. + //#define MATLABCMATHLIBRARY // define: use Matlab C math library; undef: use others. + + //-------Only one of the following for math library.-------- + #define SWITCHTOINTELCMATH // define: use Intel MKL LAPACK library; undef: use others. + //#define SWITCHTOTZCMATH // define: use my own C math library; undef: use others. + + //-------Only one of the following for optimization routines except that CG?_ and CSMINWEL_ can be chosen together.-------- + //#define IMSL_OPTIMIZATION // IMSL optimization routines. + #define CSMINWEL_OPTIMIZATION //Sims's optimization routine. + #define CGI_OPTIMIZATION //Polak-Ribiere conjugate gradient method without using derivative information in performing the line minimization. + //NOT available yet! #define CGII_OPTIMIZATION //NOT available yet! Pletcher-Reeves conjugate gradient method using derivative information in performing the line minimization. + + //-------Only one of the following for random number generating routines.-------- + #define IMSL_RANDOMNUMBERGENERATOR // IMSL random number generator. + //#define CASE2_RANDOMNUMBERGENERATOR //Imported from the C recipe book -- case 2 and my own (Iskander) code for generating a gamma distribution. + + //-------Only one of the following statistical packages.-------- + #define IMSL_STATISTICSTOOLBOX // IMSL statistical package. + + + + //-------If define: use matlab API interface; otherwise (undef), use C console. + #undef WIN_MATLABAPI // define: use matlab API interface; undef: use C dos console. + + + //--------------- + #ifdef MATLABCMATHLIBRARY + #include "matlab.h" // For all mlf???? functions. + #include "matrix.h" // For mxGetM, mxCreatDoubleMatrix, etc. + #endif + #ifdef WIN_MATLABAPI // define: use matlab API interface; undef: use C dos console. + #include "mex.h" // For all mex??? calls. Matlab API (application program interface or external interface). + #define printf mexPrintf + #define malloc mxMalloc + #define calloc mxCalloc + #define free mxFree + #endif + + + //-------------- Attributes for the real double matrix type TSdmatrix. -------------- + //-------------- Whenever a matrix is initialized, the default is M_GE, but nothing else. -------------- + #define M_UNDEF 0 //0 or NULL: No attribute will be given when memory is allocated but no values are initialized. + #define M_GE 0x0001 //1: A general matrix. + #define M_SU 0x0002 //2: A symmetric (must be square) matrix but only the upper triangular part is referenced. + #define M_SL 0x0004 //4: A symmetric (must be square) matrix but only the lower triangular part is referenced. + #define M_UT 0x0008 //8: A upper triangular (trapezoidal if nrows < ncols) matrix but only the upper triangular part is referenced. + #define M_LT 0x0010 //16: A lower triangular (trapezoidal if nrows > ncols) matrix but only the lower triangular part is referenced. + #define M_CN 0x0020 //32: A constant (CN) matrix (All elements are the same or no (N) change from one to another). +// #define M_UTU 0x0040 //2^6: An unit upper triangular matrix. +// #define M_LTU 0x0080 //2^7: An unit lower triangular matrix. + //-------------- Attributes for the real double vector type TSdvector or the character vector type TScvector. -------------- + #define V_UNDEF 0 //Zero or NULL: No values have been assigned to the double vector. + #define V_DEF 1 //True: Values have been assigned to the double vector. + + + //-------------- Other macro definitions. -------------- + #define BLOCKSIZE_FOR_INTEL_MKL 128 //A machine-dependent value (typically, 16 to 64) required for optimum performance of the blocked algorithm in Intel MKL. + #define NEARINFINITY 1.0E+300 + #define BIGREALNUMBER 1.0E+30 + #define MACHINEZERO DBL_MIN + #define EPSILON DBL_EPSILON //1.0E-015. In Standard C, DBL_EPSILON = 2.2204460492503131 + #define SQRTEPSILON 1.490116119384766E-008 //1.0E-15. In Standard C, DBL_EPSILON = 2.2204460492503131E-016 + #define SQRTMACHINEZERO 1.490116119384766E-008 + //This is really not correct, because this number is sqrt(epsion), where DBL_MIN is around 1.0e-300. + #define MACHINEINFINITY DBL_MAX + #define MACHINE_EXP_INFINITY DBL_MAX_EXP + #define EXP_NEARINFINITY 1000 + //=== + #define TZ_TRUE 1 + #define TZ_FALSE 0 + + + + //--------------- + #define tzMalloc(elt_count, type) (type *)m_alloc((elt_count)*sizeof(type)) + #define tzCalloc(elt_count, type) (type *)c_alloc((elt_count), sizeof(type)) + #define tzDestroy(x) {if ((x)) { \ + free((x)); \ + (x) = NULL; \ + }} + #define tzFclose(x) {if ((x)) { \ + fclose((x)); \ + (x) = (FILE *)NULL; \ + }} + #define mos(i, j, nrows) ((j)*(nrows)+(i)) //i: ith row; j: jth column; nrows: number of rows for the matrix. + //Offset(os) for a matrix(m) in column major order and with base 0. See Reek pp.241-242. + #define square(x) ((x) * (x)) //Must be careful to avoid using, say, square(tmpd=2) or square(++x). + #define _max(a, b) ((a)>(b) ? (a) : (b)) // Macro max or __max is already defined in stdlib.h in MS visual C++, but mex.h may overwrite the max macro so we use _max. + #define _min(a, b) ((a)>(b) ? (b) : (a)) + #define swap(a, b, stemp) {(stemp)=(a); (a)=(b); (b)=(stemp);} + // + #ifndef isfinite + #define isfinite(x) _finite(x) //_finite is for Microsoft C++ compiler only (in float.h, which strangely is not ANSI compible), + // All these Microsoft functions are not yet C99 compatible. + #endif + //--- The following does not work. + // #ifndef FP_NAN + // #define FP_NAN _FPCLASS_SNAN //_FPCLASS_SNAN is for Microsoft C++ compiler only (in float.h, which strangely is not ANSI compible), + // // All these Microsoft functions are not yet C99 compatible. + // #endif + #define isdiagonalmatrix(x) (((x)->flag & (M_UT | M_LT)) == (M_UT | M_LT)) //x is the tz type of matrix. + // + #define DestroyDatesVector_lf(x) DestroyVector_lf(x) + + + //--------------- + typedef struct TScvector_tag + { + char *v; //v: vector. + int n; + int flag; //flag: no legal values are assigned if 0 and legal values are assigned if 1. + } TScvector; + typedef struct TSvoidvector_tag + { + void *v; //v: vector. + int n; + int flag; //flag: no legal values are assigned if 0 and legal values are assigned if 1. + } TSvoidvector; + typedef struct { + int *v; //v: vector. + int n; + int flag; //flag: no legal values are assigned if 0 and legal values are assigned if 1. + } TSivector; + typedef struct { + int *M; //M: matrix. + int nrows, ncols; + int flag; //flag: Refers to M_GE, M_SU, M_SL, M_UT, and M_LT in tzmatlab.h. + } TSimatrix; + typedef struct { + TSivector **C; //ncells-by-1 cells (C) and a ponter to vector in each cell. + int ncells; //Number of pointers (cells) to pointer. + } TSicellvec; + typedef struct { + TSimatrix **C; //ncells-by-1 cells (C) and a ponter to vector in each cell. + int ncells; //Number of pointers (cells) to pointer. + } TSicell; + //=== Real types. + typedef struct { + double *v; //v: vector. + int n; + int flag; //flag: no legal values are assigned if 0 and legal values are assigned if 1. + } TSdvector; + typedef struct { + double *M; //M: matrix. + int nrows, ncols; + int flag; //flag: Refers to M_GE, M_SU, M_SL, M_UT, and M_LT in tzmatlab.h. + } TSdmatrix; + typedef struct { + TSdmatrix **C; //ncells-by-1 cells (C) and a pointer to matrix in each cell. + int ncells; //Number of pointers (cells) to pointer. + } TSdcell; + typedef struct { + TSdvector **C; //ncells-by-1 cells (C) and a ponter to vector in each cell. + int ncells; //Number of pointers (cells) to pointer. + } TSdcellvec; + typedef struct { + TSdcell **F; //ndims-by-1 fourths (F) and a pointer to cell in each fourth. + int ndims; //Number of pointers (fourth dimensions) to pointer. + } TSdfourth; + typedef struct { + TSdcellvec **F; //ndims-by-1 fourths (F) and a pointer to cellvec in each fourth. + int ndims; //Number of pointers (fourth dimensions) to pointer. + } TSdfourthvec; + //=== Complex types. + typedef struct { + TSdvector *real; //Real part. + TSdvector *imag; //Imaginary part. + } TSdzvector; + typedef struct { + TSdmatrix *real; //Real part. + TSdmatrix *imag; //Imaginary part. + } TSdzmatrix; + + + + //----------------- Some high-level functions. ----------------- + int fn_locofyearqm(int q_m, int yrstart, int qmstart, int yrend, int qmend); + + + + + //--------------- + void fn_DisplayError(char *msg_s); + void *m_alloc(size_t size); + void *c_alloc(size_t elt_count, size_t elt_size); + + /** + TSvoidvector *CreateVector_void(int _n); + TSvoidvector *DestroyVector_void(TSvoidvector *x_voidv); + /**/ + + TScvector *CreateVector_c(int _n); + TScvector *DestroyVector_c(TScvector *x_s); + TSivector *CreateVector_int(int _n); + TSivector *DestroyVector_int(TSivector *x_iv); + TSimatrix *CreateMatrix_int(int nrows, int ncols); + TSimatrix *DestroyMatrix_int(TSimatrix *x_im); + TSicellvec *CreateCellvec_int(TSivector *n_iv); + TSicellvec *DestroyCellvec_int(TSicellvec *x_icv); + TSicell *CreateCell_int(TSivector *row_iv, TSivector *col_iv); + TSicell *DestroyCell_int(TSicell *x_ic); + + TSdvector *CreateVector_lf(int _n); + TSdvector *DestroyVector_lf(TSdvector *x_iv); + TSdmatrix *CreateMatrix_lf(int nrows, int ncols); + TSdmatrix *DestroyMatrix_lf(TSdmatrix *x_im); + TSdcell *CreateCell_lf(TSivector *row_iv, TSivector *col_iv); + TSdcell *DestroyCell_lf(TSdcell *x_dc); + TSdcellvec *CreateCellvec_lf(TSivector *n_iv); + TSdcellvec *DestroyCellvec_lf(TSdcellvec *x_dcv); + TSdfourth *CreateFourth_lf(int ndims, TSivector *row_iv, TSivector *col_iv); + TSdfourth *DestroyFourth_lf(TSdfourth *x_d4); + TSdfourthvec *CreateFourthvec_lf(int ndims, TSivector *n_iv); + TSdfourthvec *DestroyFourthvec_lf(TSdfourthvec *x_d4v); + + TSdzvector *CreateVector_dz(int _n); + TSdzvector *DestroyVector_dz(TSdzvector *x_dzv); + TSdzmatrix *CreateMatrix_dz(int nrows, int ncols); + TSdzmatrix *DestroyMatrix_dz(TSdzmatrix *x_dzm); + + //+ + TSdmatrix *CreateZeroMatrix_lf(const int nrows, const int ncols); + TSdmatrix *CreateIdentityMatrix_lf(const int nrows, const int ncols); + //TSdvector *CreateZerosVector_lf(int _n); + TSivector *CreateConstantVector_int( const int _n, const int _k); + TSimatrix *CreateConstantMatrix_int(const int nrows, const int ncols, const int _n); + TSicellvec *CreateConstantCellvec_int(TSivector *n_iv, const int _n); + TSicell *CreateConstantCell_int(TSivector *row_iv, TSivector *col_iv, const int _n); + TSdvector *CreateConstantVector_lf(const int _n, const double _alpha); + TSdmatrix *CreateConstantMatrix_lf(const int nrows, const int ncols, const double _alpha); + TSdcellvec *CreateConstantCellvec_lf(TSivector *n_iv, const double _alpha); + TSdcell *CreateConstantCell_lf(TSivector *row_iv, TSivector *col_iv, const double _alpha); + TSdvector *CreateDatesVector_lf(int nq_m, int yrstart, int qmstart, int yrend, int qmend); + //+ + void InitializeConstantVector_lf(TSdvector *x_dv, const double _alpha); + void InitializeConstantVector_int(TSivector *x_iv, const int _k); + void InitializeConstantMatrix_lf(TSdmatrix *x_dm, const double _alpha); + void InitializeDiagonalMatrix_lf(TSdmatrix *x_dm, const double _alpha); + void InitializeConstantMatrix_int(TSimatrix *x_dm, const int _alpha); + void InitializeConstantCellvec_lf(TSdcellvec *x_dcv, const double _alpha); + void InitializeConstantCell_lf(TSdcell *x_dc, const double _alpha); + void InitializeConstantFourthvec_lf(TSdfourthvec *x_d4v, const double _alpha); + void InitializeConstantFourth_lf(TSdfourth *x_d4, const double _alpha); + + + void NegateColofMatrix_lf(TSdvector *y_dv, TSdmatrix *x_dm, int _j); + void InitializeConstantColofMatrix_lf(TSdmatrix *X_dm, int jx, double _alpha); + + FILE *tzFopen(char *filename, char *mode); +#endif diff --git a/MathematicaFiles/Applications/BayesianDistributions.m b/MathematicaFiles/Applications/BayesianDistributions.m new file mode 100755 index 0000000..74e6c87 --- /dev/null +++ b/MathematicaFiles/Applications/BayesianDistributions.m @@ -0,0 +1,259 @@ +(* Additional distributions for Bayesian analysis. *) + +(* :Reference: + Bayesian Data Analysis (BDA) + by Gelman, Carlin, Stern, and Rubin, 2nd ed., 2003, Chapman & Hall/CRC. + + Notes: + BDA Gamma(a, b) is equivalent to GammaDistribution[a, 1/b]. + BDA Neg-bin(a, b) is equivalent to NegativeBinomial[a, b/(1+b)]. +*) + +(* two useful definitions *) +Logit[x_] := Log[x/(1 - x)] +InverseLogit[z_] := E^z/(1 + E^z) + +Needs["MultivariateStatistics`"] + +GammaDistributionBDA /: + f_[GammaDistributionBDA[a_, b_], x___] := f[GammaDistribution[a, 1/b], x] + +NegativeBinomialDistributionBDA /: + f_[NegativeBinomialDistributionBDA[a_, b_], x___] := + f[NegativeBinomialDistribution[a, b/(1 + b)], x] + +InverseGammaDistributionBDA /: + f_[InverseGammaDistributionBDA[a_, b_], x___] := + f[InverseGammaDistribution[a, 1/b], x] + +(* InverseGammaDistribution *) +InverseGammaDistribution /: + PDF[InverseGammaDistribution[a_, b_], x_] := + x^(-1 - a)/(b^a * E^(1/(b * x)) * Gamma[a]) + +InverseGammaDistribution /: + CDF[InverseGammaDistribution[a_, b_], x_] := Gamma[a, 1/(b*x)]/Gamma[a] + +InverseGammaDistribution /: + Mean[InverseGammaDistribution[a_, b_]] := 1/((a - 1) * b) + +InverseGammaDistribution /: + Variance[InverseGammaDistribution[a_, b_]] := 1/((a - 2)*(a - 1)^2 * b^2) + +InverseGammaDistribution /: + RandomReal[InverseGammaDistribution[a_, b_]] := + 1/RandomReal[GammaDistribution[a, b]] + +InverseGammaDistribution /: + RandomReal[InverseGammaDistribution[a_, b_], n_] := + 1/RandomReal[GammaDistribution[a, b], n] + +(* InverseChiSquareDistribution *) + +InverseChiSquareDistribution /: + PDF[InverseChiSquareDistribution[n_], x_] := + x^(-1 - n/2)/(2^(n/2) * E^(1/(2*x))*Gamma[n/2]) + +InverseChiSquareDistribution /: + CDF[InverseChiSquareDistribution[n_], x_] := + Gamma[n/2, 1/(2*x)]/Gamma[n/2] + +InverseChiSquareDistribution /: + Mean[InverseChiSquareDistribution[n_]] := 1/(n - 2) + +InverseChiSquareDistribution /: + Variance[InverseChiSquareDistribution[n_]] := 2/((n - 2)^2 * (n - 4)) + + +InverseChiSquareDistribution /: + RandomReal[InverseChiSquareDistribution[n_]] := + 1/RandomReal[ChiSquareDistribution[n]] + +InverseChiSquareDistribution /: + RandomReal[InverseChiSquareDistribution[nu_], n_] := + 1/RandomReal[ChiSquareDistribution[nu], n] + +(* InverseChiSquareScaledDistributionBDA *) +InverseChiSquareScaledDistributionBDA /: + f_[InverseChiSquareScaledDistributionBDA[n_, v_], x___] := + f[InverseGammaDistributionBDA[n/2, (n/2) * v], x] + +(* InverseChiSquareScaledDistribution *) +InverseChiSquareScaledDistribution /: + f_[InverseChiSquareScaledDistribution[n_, v_], x___] := + f[InverseGammaDistribution[n/2, 1/((n/2) * v)], x] + +InverseWishartDistribution /: + RandomReal[InverseWishartDistribution[args__]] := + 1/RandomReal[WishartDistribution[args]]; + +InverseWishartDistribution /: + RandomReal[InverseWishartDistribution[args__], n_] := + 1/RandomReal[WishartDistribution[args], n] + +WishartDistributionBDA::usage = "WishartDistributionBDA[sigma, n] +represents the Wishart distribution for Random and RandomArray." + +WishartDistributionBDA /: + RandomReal[WishartDistributionBDA[S_, n_Integer]] := + Transpose[#].# & @ + RandomReal[MultinormalDistribution[Table[0, {Length[S]}], S], n] + +WishartDistributionBDA /: + RandomReal[WishartDistributionBDA[S_, n_Integer], num_Integer] := + Transpose[#].# & /@ + RandomReal[MultinormalDistribution[Table[0, {Length[S]}], S], {num, n}] + +InverseWishartDistributionBDA::usage = +"InverseWishartDistributionBDA[sigma, n] represents the inverse +Wishart distribution for Random and RandomArray." + +InverseWishartDistributionBDA /: + RandomReal[InverseWishartDistributionBDA[S_, n_Integer]] := + 1/RandomReal[WishartDistributionBDA[S, n]] + +InverseWishartDistributionBDA /: + RandomReal[InverseWishartDistributionBDA[S_, n_Integer], num_Integer] := + 1/RandomReal[WishartDistributionBDA[S, n], num] + +(* multivariate t distribution + Gary Koop (2003) Bayesian Econometrics by (p. 328) *) +MultiTDistribution /: + PDF[MultiTDistribution[mu_?VectorQ, sigma_?MatrixQ, nu_], y_?VectorQ] /; + Length[mu] == Length[y] == Length[sigma] := + With[{k = Length[y]}, + (nu^(nu/2) * (nu + (y - mu).Inverse[sigma].(y - mu))^((-k - nu)/2) * + Gamma[(k + nu)/2])/(Pi^(k/2) * Sqrt[Det[sigma]] * Gamma[nu/2]) + ] + +(* Borrowed from Dan Waggoner. + gamma density for x|a: x^(a-1) * Exp[-x]/Gamma[a] + + a = 1, exponential + a < 1, Johnk's generator (Devroye, page 418) + a > 1, Beta's algorithm (Devroye, page 410) + + Devroye (1986) "Non-uniform random variate generation", Springer-Verlag. + + Use b*x to obtain general gamma deviate (i.e., GammaDistribution[a, b]). +*) + +(* +GammaDeviateFunction = + Function[a, + Module[{u, v, x, y, b, w, z}, + Catch[ + If[a == 1, Throw[-Log[Random[]]]]; + If[a < 1, + u = 1/a; + v = 1/(1 - a); + While[True, + x = Random[]^u; + y = Random[]^v; + If[x + y <= 1, + Throw[-Log[Random[]] * x/(x + y)] + ] + ] + ]; + While[True, + b = a - 1; + u = Random[]; + w = u(1 - u); + y = Sqrt[(3a - .75)/w](u - .5); + x = b + y; + If[x > 0, + v = Random[]; + z = 64 w^3 * v^2; + If[(z <= 1 - 2 * y^2/x) || (Log[z] <= 2(b * Log[x/b] - y)), + Throw[x] + ] + ] + ] (* end While *) + ]]] (* end Catch, Module, and Function *) + +GammaDeviateCompiled = + With[{f = GammaDeviateFunction}, + Compile[{a, b}, + b * f[a] + ] + ] + +DirichletCompiled = + With[{f = GammaDeviateFunction}, + Compile[{{a, _Real, 1}}, + #/(Plus @@ #)&[f /@ a] + ] + ]; + +DirichletArrayCompiled = + With[{f = GammaDeviateFunction}, + Compile[{{a, _Real, 1}, {n, _Integer, 0}}, + Table[#/(Plus @@ #)&[f /@ a], {n}] + ] + ]; + +(* more artful stuff: Compiling generating student t vectors with integer + degrees of freedom with the "option" of just Gaussian *) +CompileNormalizedFunction[ + n_Integer?Positive, (* length of random vector *) + df_Integer (* degrees of freedom for t distribution *) + ] := + + With[{fun = + If[df == 0, (* determine which function to use *) + (* then: do "nothing" *) + 1 &, + (* else: normalized chi-square *) + 1/Sqrt[(#.#)&[Table[Sqrt[-2 Log[Random[]]] Cos[2 Pi Random[]], {#}]]/#]& + ]}, + + Compile[{}, + fun[df] * (* use the function *) + Table[Table[Sqrt[-2 Log[Random[]]] Cos[2 Pi Random[]], {n}]] + ]] + +erfc[x_] := + Module[{z = Abs[x], t=1.,ans=1.}, + t= 1/(1+.5*z); + ans=t*Exp[-z*z-1.26551223+t*(1.00002368+t*(.37409196+t*(.09678418+ + t*(-.18628806+t*(.27886807+t*(-1.13520398+t*(1.48851587+t*(-.82215223+t*.\ + 17087277))))))))]; + If[x >= 0, ans, 2-ans] + ] + +cdfnorm[x_]:= + Module[{z = Abs[x/Sqrt[2.]], t=1., ans=1.}, + t = 1/(1+.5*z); + ans = t * Exp[-z*z - + 1.26551223 + + t*( 1.00002368 + + t*( 0.37409196 + + t*( 0.09678418 + + t*(-0.18628806 + + t*( 0.27886807 + + t*(-1.13520398 + + t*( 1.48851587 + + t*(-0.82215223 + + t* 0.17087277))))))))]; + If[x >= 0, 1 - ans/2, ans/2] + ] + +cdffun = Function[x, + Module[{z = Abs[x/Sqrt[2.]], t=1., ans=1.}, + t = 1/(1+.5*z); + ans = t * Exp[-z*z - + 1.26551223 + + t*( 1.00002368 + + t*( 0.37409196 + + t*( 0.09678418 + + t*(-0.18628806 + + t*( 0.27886807 + + t*(-1.13520398 + + t*( 1.48851587 + + t*(-0.82215223 + + t* 0.17087277))))))))]; + If[x >= 0, 1 - ans/2, ans/2] + ]]; + +*) + diff --git a/MathematicaFiles/Applications/BinnedKernelDensity.m b/MathematicaFiles/Applications/BinnedKernelDensity.m new file mode 100755 index 0000000..3f444a7 --- /dev/null +++ b/MathematicaFiles/Applications/BinnedKernelDensity.m @@ -0,0 +1,1110 @@ +(* :Title: Binned Kernel Density *) + +(* :Author: Mark Fisher *) + +(* :Mathematica Version: 5.1 *) + +(* :Context: BinnedKernelDensity` *) + +(* :Package Version: + 1.0 July 1999 + 1.1 September 2002 + 1.2 January 2005 + Modified to take advantage of SparseArray in SimpleBinning +*) + +(* :Summary: This package combines a modified version of BinCounts +(from Statistics`DataManipulation`) along with ListCorrelate (new in version +4.0) to compute binned kernel density (and regression) estimators. +These are also known as WARP-ed estimators (Weighted Average of +Rounded Points). Two binning rules and six kernels are implemented. +The binned kernel density is designed to work with multi-dimensional +data. + +I prefer this to the Histogram function introduced in version 4.0 in +Graphics`Graphics`. +*) + +(* :Discussion: +The binned kernel density (and regression) estimators have the +following structure: (1) bin the data, (2) weight the bins, and (3) +interpolate. + +The two binning rules are simple binning and linear binning. For +simple binning, the function SimpleBinning (defined in this package) +is used rather than BinCounts (defined in the standard package +Statistics`DataManipulation`). SimpleBinning is a modification to +BinCounts that speeds it up for high dimensional cases +where the density of non-zero bins is low. The modification involves +directly Scan-ing the Split list of indexes, combining the in-bounds +test with the updating of the bin counts. As a result, only non-zero +bins are visited. The function LinearBinning works similarly to +SimpleBinning, except that a fraction of each observation is binned +in adjacent bins. + +Five kernels are implemented for weighting the bins: uniform, +triange, Epanechnikov, quartic, triweight, and cosinus. The bin weighting +relies on ListCorrelate, which was introduced in version 4.0. +*) + +(* :Sources: +Wolfgang Hardle (1990), Smoothing techniques with implementation in S, + Springer-Verlag. + +Peter Hall and M.P. Wand (1994), "On the accuracy of binned kernel + density estimators," University of New South Wales, Australian + Graduate School of Management, Working Paper 93-003. +*) + +(* :Requirements: This package imports the following standard packages: + Graphics`Graphics`, Graphics`Colors`, Graphics`ContourPlot3D`, + Utilities`FilterOptions`, and Statistics`DescriptiveStatistics`. *) + +(* :Warning: This package overrides the definition of Histogram in +Graphics`Graphics that was introduced in version 4.0. *) + +BeginPackage["BinnedKernelDensity`", {(*"Graphics`Graphics`", + "Graphics`Colors`", "Graphics`ContourPlot3D`", + "Statistics`DescriptiveStatistics`",*) + "Utilities`FilterOptions`", "DotPlot`"}] + +Remove[Histogram] (* eliminate Version 4 Histogram in Graphics`Graphics` *) + +Histogram::usage = "Histogram[data, {min, max, h}] plots a histogram of the +data with bin width h, where min and max are the midpoints of the lowest +and highest bins. Values x \[Element] data are included if (min - h/2) <= x +< (max + h/2). Histogram[data, n] plots a histogram with n bins, where min += Min[data] and max = Max[data]. Histogram[data] plots a histogram with 20 +bins. Histogram[data, {h, x0}] plots a histogram with bin width h and bin +\"origin\" x0. Histogram[data, {h}] plots a histogram with bin width h and +\"origin\" 0. Histogram[data, {{min, max}, n}] plots a histogram with n +bins and a minimum of min and a maximum of max. Histogram takes the options +PlotFrequencies, which specifies whether to plot relative frequencies of +the data, and Outline, which specifies whether to draw the ouline of the +histogram instead of the bars. The default settings are PlotFrequencies -> +True and Outline -> True." + +ConditionalPlot::usage = "ConditionalPlot[data, {min, max, h}] takes +a list of {x,y} pairs, bins the x-coordinates and produces a line plot +of the mean of the y-coordinates for each of the bins. ConditionalPlot +take the option Function. The default setting is Function -> Mean." + +BinnedDensityPlot::usage = "BinnedDensityPlot[data,{n, m}] produces a + density plot of the data binned into n by m bins. + BinnedDensityPlot[data, n] uses n by n bins. + BinnedDensityPlot[data] uses 20 by 20 bins." + +PlotFrequencies::usage = "PlotFrequencies is an option for Histogram and + BinnedDensityPlot. The default setting PlotFrequencies -> True specifies + that relative frequencies should be used." + +BinnedSurfacePlot::usage = "BinnedSurfacePlot[data,{n, m}] produces a + surface plot of the data binned into n by m bins. + BinnedSurfacePlot[data, n] uses n by n bins. + BinnedSurfacePlot[data] uses 20 by 20 bins." + +BinnedContourPlot::usage = "BinnedContourPlot[data,{n, m}] produces a + surface plot of the data binned into n by m bins. + BinnedContourPlot[data, n] uses n by n bins. + BinnedContourPlot[data] uses 20 by 20 bins." + +Outline::usage = "Outline is an option for Histogram which specifies +whether to draw only the outline instead of the bars." + +RuleOfThumbBinwidth::usage = "RuleOfThumbBinwidth[data] returns the +rule-of-thumb binwidth for the data based on the sample size and the +minimum of the estimated standard deviation and the adjusted interquartile +range." + +BinwidthFactor::usage = "BinwidthFactor is an option of BinnedKernelDensity +and related functions which specifies how to scale the RuleOfThumbBinWidth. +The default setting is BinwidthFactor -> 1." + +DefaultBins::usage = "DefaultBins[data]." + +BinnedKernelDensity::usage = "BinnedKernelDensity[data, {h, M}...] + computes the Binned density estimator where h is the bandwidth + (binwidth) and M is the number of subdivisions. (BinnedKernelDesity + approaches a kernel density estimate as M increases.) A separate {h, M} + pair must be specified for each dimension of the data. + If no {h, M} pairs are specified, default values derived from + RuleOfThumbBinwidth with M = 5 are used. + BinnedKernelDensity returns an InterpolatingFunction." + +Normalize::usage = "Normalize is an option for BinnedKernelDensity and + related functions. The default setting Normalize -> True specifies + that relative frequencies should be used." + +BinningRule::usage = "BinningRule is an option for BinnedKernelDensity + and related functions that specifies which binning rule to use. + Valid binning rules are SimpleBinning and LinearBinning." + +SimpleBinning::usage = "SimpleBinning[data, {min, max, dx}] returns a +SparseArray object containing the bin counts. The left-hand edge of the +smallest bin is located at min and the number of bins equals Round[(max- +min)/dx]. Values x \[Element] data are included if min <= x < min + +dx \[Times] Round[(max - min)/dx], where dx is the bin width." + +LinearBinning::usage = "LinearBinning[data, {min, max, dx}]." + +BinArray::usage = "BinArray is an object that contains a +SparseArray and mesh information. BinArray is also an option +for SimpleBinning and LinearBinning that specifies whether +to produce a BinArray." + +KernelArray::usage = "KernelArray is an object that contains +a normalized SparseArray, mesh information, and a kernel." + +MakeKernelArray::usage = "MakeKernelArray[data, {h, M}..] returns +a KernelArray object." + +WeightedBinning::usage = "WeightedBinning[data, weights, {min, max, dx}] +returns a list of bin counts using the weights. Also, +WeightedBinning[weights][data, {min, max, dx}], which allows +BinningRule -> WeightedBinning[weights] to be used." + +Kernel::usage = "Kernel is an option for BinnedKernelDensity and + BinnedKernelRegression. The default setting is Kernel -> + TriangleKernel. Other valid weighting functions are + UniformKernel, TriangleKernel, EpanechnikovKernel, + QuarticKernel, and CosinusKernel." + +UniformKernel::usage = "UniformKernel is a weighting function for + BinnedKernelDensity and BinnedKernelRegression. For integer M, + UniformKernel[M] returns a list of 2M+1 weights normalized to sum + to M." + +TriangleKernel::usage = "TriangleKernel is a weighting function for + BinnedKernelDensity and BinnedKernelRegression. For integer M, + TriangleKernel[M] returns a list of 2M+1 weights normalized to sum + to M." + +EpanechnikovKernel::usage = "EpanechnikovKernel is a weighting + function for BinnedKernelDensity and BinnedKernelRegression. For + integer M, EpanechnikovKernel[M] returns a list of 2M+1 weights + normalized to sum to M." + +QuarticKernel::usage = "QuarticKernel is a weighting function for + BinnedKernelDensity and BinnedKernelRegression. For integer M, + QuarticKernel[M] returns a list of 2M+1 weights normalized to sum + to M." + +TriweightKernel::usage = "TriweightKernel is a weighting function for + BinnedKernelDensity and BinnedKernelRegression. For integer M, + TriweightKernel[M] returns a list of 2M+1 weights normalized to + sum to M." + +CosinusKernel::usage = "CosinusKernel is a weighting function for + BinnedKernelDensity and BinnedKernelRegression. For integer M, + CosinusKernel[M] returns a list of 2M+1 weights normalized to + sum to M." + +BinnedKernelRegression::usage = "BinnedKernelRegression[data, {h, M}]." + +BinnedKernelDensityPlot::usage = "BinnedKernelDensityPlot[data, {h, M}] + calls BinnedKernelDensity (which see). BinnedKernelDensityPlot takes + the option PlotType. The default setting is PlotType -> Plot3D. + Other valid types are ContourPlot and DensityPlot." + + +AverageShiftedHistogram::usage = "AverageShiftedHistogram[data] produces +an average shifted histogram." + +PlotType::usage = "PlotType is an option for BinnedKernelDensityPlot + that specifies the type of plot for two dimensional data. Valid + types are Plot3D, ContourPlot, and DensityPlot." + +BinnedKernelRegressionPlot::usage = "BinnedKernelRegressionPlot[data, + {h, M}]." + +InterpolatingFunctionPlot::usage = "InterpolatingFunctionPlot[ifun[args], + x] plots the interpolatign function over its range. A 2-dimensional + interpolating function can be plotted over 1 dimension by fixing one + argument numerically, as in ifun[2, x]." + +InterpolatingFunctionPlot3D::usage = + "InterpolatingFunctionPlot3D[ifun[args], x, y] plots the + InterpolationFunction over its range. A 3-dimensional interpolating + function can be plotted over 2 dimensions by fixing one argument + numerically, as in ifun[x, 2, y]." + +InterpolatingFunctionContourPlot::usage = + "InterpolatingFunctionContourPlot[ifun[args], x, y] plots the + InterpolationFunction over its range. A 3-dimensional interpolating + function can be plotted over 2 dimensions by fixing one argument + numerically, as in ifun[x, 2, y]." + +InterpolatingFunctionDensityPlot::usage = + "InterpolatingFunctionDensityPlot[ifun[args], x, y] plots the + InterpolationFunction over its range. A 3-dimensional interpolating + function can be plotted over 2 dimensions by fixing one argument + numerically, as in ifun[x, 2, y]." + +InterpolatingFunctionContourPlot3D::usage = + "InterpolatingFunctionContourPlot3D[ifun[args], x, y, z] plots + 3-dimensional contours of the InterpolationFunction over its range. A + 4-dimensional interpolating function can be plotted over 3 dimensions + by fixing one argument numerically, as in ifun[x, 2, y, z]." + +Begin["`Private`"] + +Histogram::baddata = "The data are not a list of two or more numbers." +ConditionalPlot::baddata = "The data are not a list of two or more pairs of numbers." + +Options[Histogram] = {PlotFrequencies -> True, Outline -> True, + BinningRule -> SimpleBinning} + +Histogram[data_, ___] := (Message[Histogram::baddata]; $Failed) + +ConditionalPlot[data_, ___] := (Message[ConditionalPlot::baddata]; $Failed) + +Histogram[data_?(VectorQ[#, NumericQ]&), {{min_, max_}, nbins_Integer}, + opts___?OptionQ] := + With[{h = (max - min)/nbins}, + Histogram[data, {min + h/2, max - h/2, h}, opts] + ] + +ConditionalPlot[data_?(MatrixQ[#, NumericQ]&), {{min_, max_}, nbins_Integer}, + opts___?OptionQ] := + With[{h = (max - min)/nbins}, + ConditionalPlot[data, {min + h/2, max - h/2, h}, opts] + ] + +Histogram[data_?(VectorQ[#, NumericQ]&), opts___?OptionQ] := + Histogram[data, 20, opts] + +ConditionalPlot[data_?(MatrixQ[#, NumericQ]&), opts___?OptionQ] := + ConditionalPlot[data, 20, opts] + +(* +Histogram[data_?(VectorQ[#, NumericQ]&), nbins_Integer?Positive, + opts___?OptionQ] := + Module[{min = Min[data], max = Max[data], h}, + h = (max - min)/(nbins - 1); + Histogram[data, {min - h/2, max + h/2, h}, opts] + ] /; nbins > 1 +*) + +Histogram[data_?(VectorQ[#, NumericQ]&), nbins_Integer?Positive, + opts___?OptionQ] := + Module[{min = Min[data], max = Max[data], h}, + h = (max - min)/(nbins - 1); + Histogram[data, {min, max, h}, opts] + ] /; nbins > 1 + +ConditionalPlot[data_?(MatrixQ[#, NumericQ]&), nbins_Integer?Positive, + opts___?OptionQ] := + Module[{min = Min[data], max = Max[data], h}, + h = (max - min)/(nbins - 1); + ConditionalPlot[data, {min, max, h}, opts] + ] /; nbins > 1 + +(* h is the bin width and x0 is the "origin" *) +Histogram[data_?(VectorQ[#, NumericQ]&), {h_, x0_}, opts___?OptionQ] := + Module[{min = Min[data], max = Max[data], first, last}, + {first, last} = x0 + h/2 + Floor[(# - x0)/h]*h & /@ {min, max}; + Histogram[data, {first, last, h}, opts] + ] /; h > 0 + +ConditionalPlot[data_?(MatrixQ[#, NumericQ]&), {h_, x0_}, opts___?OptionQ] := + Module[{min = Min[data], max = Max[data], first, last}, + {first, last} = x0 + h/2 + Floor[(# - x0)/h]*h & /@ {min, max}; + ConditionalPlot[data, {first, last, h}, opts] + ] /; h > 0 + +(* h is the bin width *) +Histogram[data_?(VectorQ[#, NumericQ]&), {h_}, opts___?OptionQ] := + Histogram[data, {h, 0}, opts] + +ConditionalPlot[data_?(MatrixQ[#, NumericQ]&), {h_}, opts___?OptionQ] := + ConditionalPlot[data, {h, 0}, opts] + +(* +Histogram[data_?(VectorQ[#, NumericQ]&), {min_, max_, h_}, + opts___?OptionQ] := + Module[{freq, brule, height, max1, gopts, ds, ps, line, width, pos, pts}, + {freq, brule} = {PlotFrequencies, BinningRule} /. {opts} /. + Options[Histogram]; + height = brule[data, {min, max, h}]; +(* these next two lines need some thought *) + If[Max[data] == max, height[[-1]]++]; (* for discrete data *) + max1 = min + h * Length[height]; + (*If[Last[height] == 0, height = Drop[height, -1]]; (* last bin empty *)*) + If[TrueQ[freq], height = height/(h Length[data])]; + If[TrueQ[Outline /. {opts} /. Options[Histogram]], + (* then *) + gopts = FilterOptions[Graphics, opts]; + ds = Sequence @@ Cases[{gopts}, f_[DisplayFunction, _]]; + ps = PlotStyle /. {opts}; + Which[Head[ps] === List, ps = Sequence @@ ps, + ps === PlotStyle, ps = Sequence[]]; + If[TrueQ[FrequencyPolygon /. {opts} /. Options[Histogram]], + line = Transpose[ + {Range[min-h/2, max1+h/2, h], Join[{0}, height, {0}]}], + line = Join[ + {{min, 0}}, + Flatten[Thread /@ + Transpose[{Partition[Range[min, max1, h], 2, 1], height}], + 1], + {{max, 0}}] + ]; + line = Flatten[Union /@ Split[line, #1[[2]] == #2[[2]] &][[All, {1, -1}]], 1]; + Show[Graphics[{ps, Line[line]}], gopts, + Frame -> {True, True, False, False}, + DisplayFunction -> $DisplayFunction], + (* else *) + width = Table[h, {Length[height]}]; + pos = Range[min + h/2, max1 - h/2, h]; + pts = Transpose[{pos, height, width}]; + GeneralizedBarChart[pts, Evaluate[FilterOptions[Plot, opts]], + AxesOrigin -> {min, 0}, PlotRange -> All, BarStyle -> {White}] + ] + ] /; max > min && h > 0 +*) + +Options[ConditionalPlot] = {Function -> Mean} + +ConditionalPlot[data:{{_?NumericQ,_?NumericQ}..}, {min_, max_, h_}, + opts___?OptionQ] := + Module[{gopts, ps, min1, max1, index, groups, fun, fg, uindex, + midpoints, hends, hlines, vpos, irules, ipos, vlines}, + gopts = FilterOptions[Graphics, opts]; + ps = PlotStyle /. {opts}; + Which[Head[ps] === List, ps = Sequence @@ ps, + ps === PlotStyle, ps = Sequence[]]; + min1 = min - h/2; + max1 = max + h/2; + index = Floor[(data[[All, 1]] - min1)/h] + 1; + groups = #[[All, 2]]& /@ + Split[Sort[Transpose[{index, data[[All, 2]]}]], #1[[1]] == #2[[1]] &]; + fun = Function /. {opts} /. Options[ConditionalPlot]; + fg = fun /@ groups; + uindex = Union[index]; + midpoints = min + h(uindex - 1); + hends = Transpose[{midpoints - h/2, midpoints + h/2}]; + hlines = Line /@ (Thread /@ Transpose[{hends, fg}]); + vpos = Flatten[Partition[#, 2, 1] & /@ + Select[Split[uindex, #1 + 1 == #2 &], Length[#] >= 2 &], 1]; + irules = Rule @@@ Transpose[{uindex, fg}]; + ipos = Flatten[Position[uindex, Alternatives @@ vpos[[All, 1]]]]; + vlines = Line /@ (Thread /@ Transpose[{midpoints[[ipos]] + h/2, vpos /. irules}]); + Show[Graphics[{ps, hlines, vlines}], gopts] + ] + +(* main engine *) +(* min and max are the midpoints of the bottom and top bins *) +Histogram[data_?(VectorQ[#, NumericQ]&), {min_, max_, h_}, + opts___?OptionQ] := + Module[{freq, brule, gopts, ps, min1, max1, height, + ar, z1, z2, v1, w1, w2, line0, outline, droplines, bottomline}, + {freq, brule} = {PlotFrequencies, BinningRule} /. {opts} /. + Options[Histogram]; + gopts = FilterOptions[Graphics, opts]; + ps = PlotStyle /. {opts}; + Which[Head[ps] === List, ps = Sequence @@ ps, + ps === PlotStyle, ps = Sequence[]]; + min1 = min - h/2; + max1 = max + h/2; + height = brule[data, {min1, max1, h}]; + If[TrueQ[freq], height = height/(h Length[data])]; + ar = Most[ArrayRules[height]]; + z1 = Split[ar[[All, 1, 1]], #1 + 1 == #2 &][[All, {1, -1}]]; + z2 = {Union[{1, -1} + #], 0} & /@ Partition[Take[Flatten[z1], {2, -2}], 2]; + v1 = {Union[#[[1, {1, -1}]]], #[[2, 1]]} & /@ + (Transpose /@ Split[ar /. ({x_} -> y_) -> {x, y}, #1 + {1, 0} == #2 &]); + w1 = Sort[Join[v1, z2], #1[[1, 1]] < #2[[1, 1]] &]; + w2 = {min1 + (#[[1]] - 1) h, min1 + #[[-1]] h} & /@ w1[[All, 1]]; + line0 = Flatten[MapThread[Thread[{##}] &, {w2, w1[[All, 2]]}], 1]; + outline = Line[Join[{{line0[[1, 1]], 0}}, line0, {{line0[[-1, 1]], 0}}]]; + If[TrueQ[Outline /. {opts} /. Options[Histogram]], + droplines = bottomline = {}, + (* else *) + droplines = Line[{{min1 + (#[[1, 1]] - 1)h, #[[2]]}, + {min1 + (#[[1, 1]] - 1)h, 0}}] & /@ Rest[ar]; + bottomline = Line[{{min1 + (ar[[1, 1, 1]] - 1)h, 0}, + {min1 + ar[[-1, 1, 1]]h, 0}}] + ]; + Show[Graphics[{ps, outline, droplines, bottomline}], + gopts, + AspectRatio -> 1/GoldenRatio, + Frame -> {True, True, False, False}, + DisplayFunction -> $DisplayFunction] + ] /; max > min && h > 0 + +Options[BinnedDensityPlot] = { + PlotFrequencies -> True, + BinningRule -> SimpleBinning} + +BinnedDensityPlot[data_?(MatrixQ[#, NumericQ]&), opts___?OptionQ] := + BinnedDensityPlot[data, 20, opts] + +BinnedDensityPlot[data_?(MatrixQ[#, NumericQ]&), nbins_Integer, + opts___?OptionQ] := + BinnedDensityPlot[data, Table[nbins, {Length[First[data]]}], opts] + +BinnedDensityPlot[data_?(MatrixQ[#, NumericQ]&), + nbins:{_Integer ..}, opts___?OptionQ] := + Module[{freq, brule, popts, tdata, min, max, h, height, mesh}, + {freq, brule} = {PlotFrequencies, BinningRule} /. {opts} /. + Options[BinnedDensityPlot]; + popts = FilterOptions[ListDensityPlot, opts]; + tdata = Transpose[data]; + min = Min /@ tdata; + max = Max /@ tdata; + h = (max - min)/(nbins - 1); + height = brule[data, Sequence @@ Transpose[{min-h/2, max+h/2, h}]]; + If[TrueQ[freq], height = height/((Times@@h) Length[data])]; + mesh = Transpose[{min-h/2, max+h/2}]; + mesh = Transpose[{min, max}]; + ListDensityPlot[Transpose[height], Evaluate[popts], + InterpolationOrder -> 0, + DataRange -> mesh, + Mesh -> False, + PlotRange -> All, + ColorFunction -> (GrayLevel[1-#^.5]&) + ] + ] /; Length[First[data]] == Length[nbins] + +BinnedSurfacePlot[data_?(MatrixQ[#, NumericQ]&), opts___?OptionQ] := + SurfaceShow[{data}, opts] + +BinnedSurfacePlot[data_?(MatrixQ[#, NumericQ]&), nbins_Integer, + opts___?OptionQ] := + SurfaceShow[{data, nbins}, opts] + +BinnedSurfacePlot[data_?(MatrixQ[#, NumericQ]&), + nbins:{_Integer ..}, opts___?OptionQ] := + SurfaceShow[{data, nbins}, opts] /; Length[First[data]] == Length[nbins] + +BinnedContourPlot[data_?(MatrixQ[#, NumericQ]&), opts___?OptionQ] := + ContourShow[{data}, opts] + +BinnedContourPlot[data_?(MatrixQ[#, NumericQ]&), nbins_Integer, + opts___?OptionQ] := + ContourShow[{data, nbins}, opts] + +BinnedContourPlot[data_?(MatrixQ[#, NumericQ]&), + nbins:{_Integer ..}, opts___?OptionQ] := + ContourShow[{data, nbins}, opts] /; Length[First[data]] == Length[nbins] + +(* private helper functions *) +SurfaceShow[{x__}, opts___?OptionQ] := + Show[SurfaceGraphics[ + Block[{$DisplayFunction = Identity}, + BinnedDensityPlot[x, opts] /. a : HoldPattern[SparseArray[__]] :> Normal[a] + ]], + FilterOptions[SurfaceGraphics, opts], + DisplayFunction -> $DisplayFunction, Axes -> True, + BoxRatios -> {1, 1, .4}] + +ContourShow[{x__}, opts___?OptionQ] := + Show[ContourGraphics[ + Block[{$DisplayFunction = Identity}, + BinnedDensityPlot[x, opts] /. a : HoldPattern[SparseArray[__]] :> Normal[a] + ]], + FilterOptions[ContourGraphics, opts], + DisplayFunction -> $DisplayFunction, AspectRatio -> 1, + PlotRange -> All, ContourShading -> False] + + +RuleOfThumbBinwidth[data_] := + 1.06 * Length[data]^(-1/5) * + Min[StandardDeviation[data], + (Quantile[data, .75] - Quantile[data, .25])/1.34] + +(* doesn't appear to be used *) +DefaultBins[data_] := DefaultBins[data, 20] + +DefaultBins[data_, n_Integer] := + With[{pdata = If[MatrixQ[data], data, Partition[data, 1]]}, + DefaultBins[pdata, Array[n&, Length[First[pdata]]]] + ] + +DefaultBins[data_, nbins:{_Integer ..}] := + Module[{tdata, min, max, h}, + tdata = Transpose[data]; + min = Min /@ tdata; + max = Max /@ tdata; + h = (max - min)/(nbins - 1); + Transpose[{min-h/2, max+h/2, h}] + ] + +(****** binned kernel density estimate ******) + +Options[BinnedKernelDensity] = {Kernel :> TriangleKernel, + BinningRule -> SimpleBinning, BinwidthFactor -> 2} + +(*BinnedKernelDensity[data_?VectorQ, hM:{_, _}, opts___?OptionQ] := + BinnedKernelDensity[Transpose[{data}], hM, opts]*) + +(* default versions use RuleOfThumbBinwidth *) + +BinnedKernelDensity[data_?VectorQ, opts___?OptionQ] := + With[{factor = BinwidthFactor /. {opts} /. Options[BinnedKernelDensity]}, + BinnedKernelDensity[ + data, + {factor * RuleOfThumbBinwidth[data], 5}, + opts] + ] + +BinnedKernelDensity[data_List, opts___?OptionQ] := + With[{factor = BinwidthFactor /. {opts} /. Options[BinnedKernelDensity]}, + BinnedKernelDensity[ + data, + Sequence @@ + Thread[{factor * (RuleOfThumbBinwidth /@ Transpose[data]), 5}], + opts] + ] + +(* +BinnedKernelDensity[data_?VectorQ, {h_, M_}, opts___?OptionQ] := + Module[{norm, weights, brule, liopts, dx, min, max, left, + right, height, adj, mesh}, + {norm, weights, brule} = {Normalize, Kernel, BinningRule} /. + {opts} /. Options[BinnedKernelDensity]; + liopts = FilterOptions[ListInterpolation, opts]; + dx = h/M; + min = Min[data]; + max = Max[data]; + {left, right} = dx {Floor[min/dx], Ceiling[max/dx] + 1}; + height = brule[data, {left, right, dx}]; + If[TrueQ[norm], height = height/(h Length[data])]; + height = ListCorrelate[weights[M], height, {-1, 1}, 0]; + adj = dx/2 - (M-1)dx; +(* height = ListCorrelate[weights[M], height, {-M, M}]; *) +(* adj = 0; *) + mesh = {left + adj, right - adj}; + ListInterpolation[height, {mesh}, liopts] + ] +*) + +(* +BinnedKernelDensity[data_List, hM:({_, _} ..), opts___?OptionQ] := + Module[{norm, weights, brule, liopts, h, M, dx, minmax, ends, + height, ker, adj, mesh}, + {norm, weights, brule} = {Normalize, Kernel, BinningRule} /. + {opts} /. Options[BinnedKernelDensity]; + liopts = FilterOptions[ListInterpolation, opts]; + {h, M} = N @ Transpose[{hM}]; + dx = h/M; + minmax = Through[{Min, Max}[#]] & /@ Transpose[data]; + ends = MapThread[#2{Floor[First[#1]/#2], Ceiling[Last[#1]/#2] + 1}&, + {minmax, dx}]; + height = brule[data, Sequence @@ MapThread[Append, {ends, dx}]]; + If[TrueQ[norm], height = height/((Times@@h) Length[data])]; + ker = Outer[Times, Sequence @@ (weights /@ M)]; + height = ListCorrelate[ker, height, {-1, 1}, 0]; + adj = MapThread[#1/2 - (#2-1)#1&, {dx, M}]; +(* height = ListCorrelate[ + Outer[Times, Sequence @@ (weights /@ M)], height, {-M, M}]; *) + mesh = MapThread[#1 + #2{1, -1}&, {ends, adj}]; + ListInterpolation[height, mesh, liopts] + ] +*) + +(* univariate *) +BinnedKernelDensity[data_?VectorQ, {h_, M_}, opts___?OptionQ] := + Module[{weights, brule, liopts, dx, min, max, + height, smooth}, + {weights, brule} = {Kernel, BinningRule} /. + {opts} /. Options[BinnedKernelDensity]; + liopts = FilterOptions[ListInterpolation, opts]; + dx = h/M; + min = Min[data]; + max = Max[data]; + height = brule[data, {min - dx/2, max + dx/2, dx}]; + height = height/(h Length[data]); + smooth = ListCorrelate[weights[M], height, {-1, 1}, 0]; + ListInterpolation[smooth, {{min - dx (M-1), max + dx (M-1)}}, liopts] + ] + +(* multivariate *) +BinnedKernelDensity[data_List, hM:({_, _} ..), opts___?OptionQ] := + Module[{weights, brule, liopts, h, M, dx, minmax, + height, ker, smooth}, + {weights, brule} = {Kernel, BinningRule} /. + {opts} /. Options[BinnedKernelDensity]; + liopts = FilterOptions[ListInterpolation, opts]; + {h, M} = N @ Transpose[{hM}]; + dx = h/M; + minmax = Through[{Min, Max}[#]] & /@ Transpose[data]; + height = brule[data, Sequence @@ MapThread[Append, {minmax, dx}]]; + height = height/((Times @@ h) Length[data]); + ker = Outer[Times, Sequence @@ (weights /@ M)]; + smooth = ListCorrelate[ker, height, {-1, 1}, 0]; + ListInterpolation[smooth, + Transpose[{minmax[[All,1]] - dx(M-1), minmax[[All,2]] + dx(M-1)}], + liopts] + ] + + +(****** kernels ******) + +UniformKernel = Compile[{n}, 2n/(2n - 1)Table[1/2, {i, 1 - n, n - 1}]] +TriangleKernel = Compile[{n}, Table[1 - Abs[i]/n, {i, 1 - n, n - 1}]] +EpanechnikovKernel = Compile[{n}, + (3n^2)/(4n^2-1)Table[1 - (i/n)^2, {i, 1 - n, n - 1}]] +QuarticKernel = Compile[{n}, + (15n^4)/(16n^4-1)Table[(1 - (i/n)^2)^2, {i, 1 - n, n - 1}]] +TriweightKernel = Compile[{n}, + (105n^6)/(14n^2+96n^6-5)Table[(1 - (i/n)^2)^3, {i, 1 - n, n - 1}]] +CosinusKernel = Compile[{n}, + n * Tan[Pi/(4*n)] * Table[Cos[(Pi/2)*(i/n)], {i, 1 - n, n - 1}]] + +(* work in progress: Covariance matrix {{s1, c}, {c, s2}} +EpanechnikovKernel2D[n_, s1_, s2_, c_] := + n^2 * + Table[Max[0, 1 - (s1(i/n)^2 - 2c (i/n)(j/n) + s2(j/n)^2)/(s1 s2 - c^2)], + {i, 1 - n, n - 1}, {j, 1 - n, n - 1}]/ + Sum[ Max[0, 1 - (s1(i/n)^2 - 2c (i/n)(j/n) + s2(j/n)^2)/(s1 s2 - c^2)], + {i, 1 - n, n - 1}, {j, 1 - n, n - 1}] +*) + +BinArray[mesh_List, sp_SparseArray][args__] := + Module[{rescaled, index, frac, box}, + dims = Dimensions[sp]; + rescaled = MapThread[Rescale[#1, #2, {1, #3}] &, {{args}, mesh, dims}]; + (* boundary issues *) + {index, frac} = Transpose @ + MapThread[Which[#1 < 1, {1, 0}, #1 > #2, {#2, 1}, True, {#1, #3}]&, + {IntegerPart[rescaled], dims - 1, FractionalPart[rescaled]}]; + box = Take[sp, Sequence @@ Transpose[{index, index + 1}]]; + ListInterpolation[Normal[box], Table[{0, 1}, {Length[{args}]}], + InterpolationOrder -> 1] @@ frac + ] + +MakeKernelArray[data_List, hM:({_, _} ..), opts___?OptionQ] := + Module[{weights, brule, h, M, dx, minmax, + height, ker, smooth}, + {weights, brule} = {Kernel, BinningRule} /. + {opts} /. Options[BinnedKernelDensity]; + {h, M} = N @ Transpose[{hM}]; + dx = h/M; + minmax = Through[{Min, Max}[#]] & /@ Transpose[data]; + height = brule[data, Sequence @@ MapThread[Append, {minmax, dx}]]; + height = height/((Times @@ h) Length[data]); + ker = Outer[Times, Sequence @@ (weights /@ M)]; + mesh = Transpose[{minmax[[All,1]] - dx(M-1), minmax[[All,2]] + dx(M-1)}]; + ] + +KernelArray[mesh_List, sp_SparseArray, ker_List][args___] := + Module[{rescaled, index, frac, bigbox, box}, + dims = Dimensions[sp]; + M = (Dimensions[ker]-1)/2 + 1; + rescaled = MapThread[Rescale[#1, #2, {1, #3}] &, {{args}, mesh, dims}]; + (* boundary issues *) + {index, frac} = Transpose @ + MapThread[Which[#1 < 1, {1, 0}, #1 > #2, {#2, 1}, True, {#1, #3}]&, + {IntegerPart[rescaled], dims - 1, FractionalPart[rescaled]}]; + bigbox = Take[sp, Sequence @@ Transpose[{index - M + 1, index + M}]]; + box = ListCorrelate[ker, bigbox]; + Print[{Normal@bigbox,box}]; + ListInterpolation[box, Table[{0, 1}, {Length[{args}]}], + InterpolationOrder -> 1] @@ frac + ] + +(****** binning rules ******) + +(****** simple binning ******) +(* SimpleBinning is modified from BinCounts in Statistics`DataManipulation *) + +(* older version: +(* this version is faster for univariate data *) +SimpleBinning[data_?(VectorQ[#, NumericQ]&), {min_, max_, h_}] := + Module[{nbins, count, index, split}, + nbins = Ceiling[(max - min)/h]; + index = Floor[(data - min)/h] + 1; (* include min *) + split = Split[Sort[index]]; + count = Array[0&, nbins]; + Scan[If[1 <= First[#] <= nbins, count[[ First[#] ]] = Length[#]]&, split]; + count + ] /; max > min && h > 0 + +SimpleBinning[data_?(MatrixQ[#, NumericQ]&), bins:({_, _, _}..)] := + Module[{min, max, h, nbins, index, split, count, unit}, + {min, max, h} = Transpose[{bins}]; + nbins = Ceiling[(max - min)/h]; + index = Floor[(# - min)/h& /@ data] + 1; (* include min *) + split = Split[Sort[index]]; + count = Array[0&, nbins]; + unit = Array[1&, Length[nbins]]; + Scan[If[And @@ Thread[unit <= First[#] <= nbins], + count[[ Sequence @@ First[#] ]] = Length[#]]&, split]; + count + ] /; Dimensions[data][[2]] == Length[{bins}] && MatrixQ[{bins}, NumericQ] +*) + +Options[SimpleBinning] = {BinArray -> False} + +(* this version is faster for univariate data *) +SimpleBinning[data_?(VectorQ[#, NumericQ]&), {min_, max_, h_}, + opts___?OptionQ] := + Module[{nbins, index, pairs, inbounds, sp}, + nbins = Round[(max - min)/h]; + index = Floor[(data - min)/h] + 1; (* include min *) + pairs = {First[#], Length[#]}& /@ Split[Sort[index]]; + inbounds = Pick[pairs, (1 <= # <= nbins)& /@ pairs[[All, 1]] ]; + sp = SparseArray[Rule @@@ inbounds, nbins]; + If[TrueQ[BinArray /. {opts} /. Options[SimpleBinning]], + BinArray[{{min, max}}, sp], + sp] + ] /; max > min && h > 0 + +SimpleBinning[data_?(MatrixQ[#, NumericQ]&), bins:({_, _, _}..), + opts___?OptionQ] := + Module[{min, max, h, nbins, index, pairs, inbounds, sp}, + {min, max, h} = Transpose[{bins}]; + nbins = Round[(max - min)/h]; + index = Floor[(# - min)/h& /@ data] + 1; (* include min *) + pairs = {First[#], Length[#]}& /@ Split[Sort[index]]; + inbounds = Pick[pairs, (And @@ Thread[(1 <= # <= nbins)])& /@ pairs[[All, 1]] ]; + sp = SparseArray[Rule @@@ inbounds, nbins]; + If[TrueQ[BinArray /. {opts} /. Options[SimpleBinning]], + BinArray[Transpose[{min, max}], sp], + sp] + ] /; Dimensions[data][[2]] == Length[{bins}] && MatrixQ[{bins}, NumericQ] + +SimpleBinning[data_, opts___] := + SimpleBinning[data, Sequence @@ DefaultBins[data], opts] + +SimpleBinning[data_, n_Integer, opts___] := + SimpleBinning[data, Sequence @@ DefaultBins[data, n], opts] + +SimpleBinning[data_?MatrixQ, nbins:{_Integer ..}, opts___] := + SimpleBinning[data, Sequence @@ DefaultBins[data, nbins], opts] + +(****** linear binning ******) + +Options[LinearBinning] = {BinArray -> False} + +(* this version is faster for univariate data *) +LinearBinning[data_?(VectorQ[#, NumericQ]&), {min_, max_, h_}, + opts___?OptionQ] := + Module[{nbins, scaled, index, frac, assigned, split, count}, + nbins = Round[(max - min)/h]; + scaled = (data - (min + h/2))/h; + index = Floor[scaled]; (* include min *) + frac = scaled - index; + assigned = Flatten[Transpose[{{index + 1, index + 2}, {1 - frac, frac}}, + {3, 1, 2}], 1]; + + inbounds = Select[assigned, 1 <= #[[1]] <= nbins &]; + split = Split[Sort[inbounds], First[#1] == First[#2] &]; + SparseArray[Rule@@Transpose[{#[[1,1]], Tr[#[[All,2]]]}& /@ split], nbins] + + (* + split = Split[Sort[assigned], First[#1] == First[#2]&]; + count = Array[0&, nbins]; + Scan[If[1 <= #[[1,1]] <= nbins, + count[[ #[[1,1]] ]] = Plus @@ (Last /@ #)]&, split]; + count + *) + ] /; max > min && h > 0 + +LinearBinning[data_:(MatrixQ[#, NumericQ]&), bins:({_, _, _}..), + opts___?OptionQ] := + Module[{min, max, h, nbins, d, scaled, index, frac, fracfun, + indexfun, ofrac, oindex, assigned, inbounds, split, count, unit}, + {min, max, h} = Transpose[{bins}]; + nbins = Round[(max - min)/h]; + d = Length[nbins]; + scaled = (# - (min + h/2))/h& /@ data; + index = Floor[scaled]; (* include min *) + indexfun = MakeIndexer[d]; + oindex = Flatten[indexfun @@@ index, 1]; + frac = scaled - index; + fracfun = MakeAssigner[d]; + ofrac = Flatten[fracfun @@@ frac]; + assigned = Transpose[{oindex, ofrac}]; + + inbounds = Select[assigned, And @@ Thread[1 <= #[[1]] <= nbins] &]; + split = Split[Sort[inbounds], First[#1] == First[#2]&]; + SparseArray[Rule@@Transpose[{#[[1,1]], Tr[#[[All, 2]]]}& /@ split], nbins] + (* + split = Split[Sort[assigned], First[#1] == First[#2]&]; + count = Array[0&, nbins]; + unit = Array[1&, d]; + Scan[If[And @@ Thread[unit <= #[[1,1]] <= nbins], + count[[ Sequence @@ #[[1,1]] ]] = Plus @@ Flatten[Last /@ #]]&, + split]; + count + *) + ] /; Dimensions[data][[2]] == Length[{bins}] && MatrixQ[{bins}, NumericQ] + +LinearBinning[data_, opts___] := + LinearBinning[data, Sequence @@ DefaultBins[data], opts] + +LinearBinning[data_, n_Integer, opts___] := + LinearBinning[data, Sequence @@ DefaultBins[data, n], opts] + +LinearBinning[data_?MatrixQ, nbins:{_Integer ..}, opts___] := + LinearBinning[data, Sequence @@ DefaultBins[data, nbins], opts] + +(* helper functions *) +MakeAssigner[d_] := MakeAssigner[d] = + Compile @@ {Array[x, d], + Flatten[Outer[Times, ##]& @@ Transpose[{1 - Array[x, d], Array[x, d]}]]} + +MakeIndexer[d_] := MakeIndexer[d] = + Compile @@ {Array[{x[#], _Integer}&, d], + Flatten[Outer[Plus, {Array[x, d] + 1}, UnitVertices[d], 1], 1]} + +UnitVertices[d_] := IntegerDigits[Range[0, 2^d - 1], 2, d] +(* 5.1 can use Tuples[{0, 1}, d] *) + +(* weighted binning *) +(* +WeightedBinCounts[data_?(MatrixQ[#, NumericQ] &), + {min_, max_, h_}] /; Dimensions[data][[2]] == 2 := + Module[{nbins, count, index, split}, + nbins = Ceiling[(max - min)/h]; + index = Floor[(data[[All, 1]] - min)/h] + 1; + split = Split[Sort[Transpose[{index, data[[All, 2]]}]], + #1[[1]] == #2[[1]] &]; + split1 = {#[[1, 1]], Tr[#[[2]]]} & /@ (Transpose /@ split); + count = Array[0 &, nbins]; + Scan[If[1 = First[#] = nbins, count[[First[#]]] = Last[#]] &, split1]; + count] /; max > min && h > 0 +*) + +WeightedBinning[weights_?(VectorQ[#, NumericQ] &)][ + data_, {min_, max_, h_}] := + WeightedBinning[data, weights, {min, max, h}] + +WeightedBinning[weights_?(VectorQ[#, NumericQ] &)][ + data_, bins:({_, _, _}..)] := + WeightedBinning[data, weights, bins] + +WeightedBinning[data_?(VectorQ[#, NumericQ] &), + weights_?(VectorQ[#, NumericQ] &), + {min_, max_, h_}] := + Module[{nbins, count, index, split}, + nbins = Ceiling[(max - min)/h]; + index = Floor[(data - min)/h] + 1; + split = Split[Sort[Transpose[{index, weights}]], + #1[[1]] == #2[[1]] &]; + split = {#[[1, 1]], Tr[#[[2]]]} & /@ (Transpose /@ split); + count = Array[0 &, nbins]; + Scan[If[1 <= First[#] <= nbins, count[[First[#]]] = Last[#]] &, split]; + count + ] /; max > min && h > 0 && Length[data] == Length[weights] + +WeightedBinning[data_?(MatrixQ[#, NumericQ]&), + weights_?(VectorQ[#, NumericQ] &), + bins:({_, _, _}..)] := + Module[{min, max, h, nbins, index, split, count, unit}, + {min, max, h} = Transpose[{bins}]; + nbins = Ceiling[(max - min)/h]; + index = Floor[(# - min)/h& /@ data] + 1; (* include min *) +(* split = Split[Sort[index]];*) + split = Split[Sort[Transpose[{index, weights}]], + #1[[1]] == #2[[1]] &]; + split = {#[[1, 1]], Tr[#[[2]]]} & /@ (Transpose /@ split); + count = Array[0&, nbins]; + unit = Array[1&, Length[nbins]]; + Scan[If[And @@ Thread[unit <= First[#] <= nbins], + count[[ Sequence @@ First[#] ]] = Length[#]]&, split]; + count + ] /; (Dimensions[data][[2]] == Length[{bins}] && + MatrixQ[{bins}, NumericQ] && + Length[data] == Length[weights]) + + +(***** binned kernel regression estimator ******) + +Options[BinnedKernelRegression] = {Kernel -> TriangleKernel} + +BinnedKernelRegression[data_List, opts___?OptionQ] := + With[{factor = BinwidthFactor /. {opts} /. Options[BinnedKernelDensity]}, + BinnedKernelRegression[ + data, + {factor * RuleOfThumbBinwidth[ data[[All,1]] ], 5}, + opts] + ] + +BinnedKernelRegression[data_List, {h_, M_}, opts___?OptionQ] := + Module[{weights, liopts, dx, x, min, max, first, last, + bl, counts, ysum, num, den, ratio, mesh}, + weights = Kernel /. {opts} /. Options[BinnedKernelRegression]; + liopts = FilterOptions[ListInterpolation, opts]; + dx = N[h/M]; + x = First /@ data; + {min, max} = Through[{Min, Max}[x]]; + {first, last} = dx {Floor[min/dx], Ceiling[max/dx]}; + bl = binlists[data, {first, last, dx}]; + counts = Length /@ bl; + ysum = Apply[Plus, Map[Last, bl, {2}], {1}]; + {num, den} = ListCorrelate[weights[M], #, M, 0]& /@ {ysum, counts}; + ratio = MapThread[If[#1 == 0, 0, #1/#2]&, {num, den}]; + mesh = {first + dx/2, last - dx/2}; + ListInterpolation[ratio, {mesh}, liopts] + ] + +(* binlists is modified from BinLists in Statistics`DataManipulation *) +(* binlists bins a list of {x,y} pairs according to the value of x. *) +binlists[data:{{_,_}..}, {xmin_, xmax_, dx_}] := + Module[{nbins, index}, + nbins = Ceiling[(xmax - xmin)/dx]; + index = Ceiling[((First /@ data) - xmin)/dx]; + Table[data[[ Flatten[Position[index, i]] ]], {i, nbins}] + ] /; xmax > xmin && dx > 0 + + +(****** plotting routines ******) + +AverageShiftedHistogram[data_?(VectorQ[#, NumericQ]&), opts___?OptionQ] := + With[{factor = BinwidthFactor /. {opts} /. Options[BinnedKernelDensity], + h = RuleOfThumbBinwidth[data]}, + BinnedKernelDensityPlot[ + data, + {factor * h, 5}, + opts, InterpolationOrder -> 0, + PlotPoints -> Ceiling[(Max[data]-Min[data]) 5/(factor * h) + 20] + ] + ] + +Options[BinnedKernelDensityPlot] = {PlotType -> Plot3D} + +BinnedKernelDensityPlot::toomany = "Cannot plot more than two dimensions." + +BinnedKernelDensityPlot[data_?VectorQ, opts___?OptionQ] := + With[{factor = BinwidthFactor /. {opts} /. Options[BinnedKernelDensity]}, + BinnedKernelDensityPlot[ + data, + {factor * RuleOfThumbBinwidth[data], 5}, + opts] + ] + +BinnedKernelDensityPlot[data_List, opts___?OptionQ] := + With[{factor = BinwidthFactor /. {opts} /. Options[BinnedKernelDensity]}, + BinnedKernelDensityPlot[ + data, + Sequence @@ + Thread[{factor * (RuleOfThumbBinwidth /@ Transpose[data]), 5}], + opts] + ] + +(* +BinnedKernelDensityPlot[data_?(VectorQ[#, NumericQ]&), opts___?OptionQ] := + BinnedKernelDensityPlot[data, {RuleOfThumbBinwidth[data], 5}, opts] + +BinnedKernelDensityPlot[data_List, opts___?OptionQ] := + BinnedKernelDensityPlot[ + data, + Sequence @@ Thread[{RuleOfThumbBinwidth /@ Transpose[data], 5}], + opts] +*) + +BinnedKernelDensityPlot[data_?(VectorQ[#, NumericQ]&), hM:{_, _}, + opts___?OptionQ] := + Module[{bkd, popts, x}, + bkd = BinnedKernelDensity[data, hM, opts]; + popts = FilterOptions[Plot, opts]; + InterpolatingFunctionPlot[bkd[x], x, popts, PlotRange -> All, + AxesOrigin -> {bkd[[1,1,1]], 0}] + ] + +BinnedKernelDensityPlot[data_?(MatrixQ[#, NumericQ]&), hM:({_, _} ..), + opts___?OptionQ] := + Module[{dkd, popts, x, y}, + If[Length[First[data]] > 2, Message[BinnedKernelDensityPlot::toomany]; + Return[$Failed]]; + bkd = BinnedKernelDensity[data, hM, opts]; + type = PlotType /. {opts} /. Options[BinnedKernelDensityPlot]; + popts = FilterOptions[type, opts]; + Switch[type, + Plot3D, + InterpolatingFunctionPlot3D[bkd[x,y], x, y, popts, PlotRange -> All, + PlotPoints -> 45], + ContourPlot, + InterpolatingFunctionContourPlot[bkd[x,y], x, y, popts, + PlotRange -> All, PlotPoints -> 45], + DensityPlot, + InterpolatingFunctionDensityPlot[bkd[x,y], x, y, popts, + PlotRange -> All, PlotPoints -> 45], + _, Message[BinnedKernelDensityPlot::badtype, type]; Return[$Failed] + ] + ] + +BinnedKernelRegressionPlot[data_List, opts___?OptionQ] := + With[{factor = BinwidthFactor /. {opts} /. Options[BinnedKernelDensity]}, + BinnedKernelRegressionPlot[ + data, + {factor * RuleOfThumbBinwidth[ data[[All, 1]] ], 5}, + opts] + ] + +BinnedKernelRegressionPlot[data_List, {h_, M_}, opts___?OptionQ] := + Module[{popts, bkr, x}, + popts = FilterOptions[Plot, opts]; + bkr = BinnedKernelRegression[data, {h, M}, opts]; + InterpolatingFunctionPlot[bkr[x], x, popts, PlotRange -> All] + ] + +InterpolatingFunctionPlot[ifun_InterpolatingFunction[args__], x_Symbol, + opts___?OptionQ] := + Module[{pos}, + pos = Position[{args}, x][[1, 1]]; + Plot[ifun[args], + Evaluate[Prepend[First[ifun][[pos]], x]], opts] + ] + +InterpolatingFunctionPlot3D[ifun_InterpolatingFunction[args__], + x_Symbol, y_Symbol, opts___?OptionQ] := + Module[{pos}, + pos = Flatten[Position[{args}, #]& /@ {x, y}]; + Plot3D[ifun[args], + Evaluate[ + Sequence @@ MapThread[Prepend, {First[ifun][[pos]], {x, y}}] + ], opts] + ] + +InterpolatingFunctionContourPlot[ifun_InterpolatingFunction[args__], + x_Symbol, y_Symbol, opts___?OptionQ] := + Module[{pos}, + pos = Flatten[Position[{args}, #]& /@ {x, y}]; + ContourPlot[ifun[args], + Evaluate[ + Sequence @@ MapThread[Prepend, {First[ifun][[pos]], {x, y}}] + ], opts] + ] + +InterpolatingFunctionDensityPlot[ifun_InterpolatingFunction[args__], + x_Symbol, y_Symbol, opts___?OptionQ] := + Module[{pos}, + pos = Flatten[Position[{args}, #]& /@ {x, y}]; + DensityPlot[ifun[args], + Evaluate[ + Sequence @@ MapThread[Prepend, {First[ifun][[pos]], {x, y}}] + ], opts] + ] + +InterpolatingFunctionContourPlot3D[ifun_InterpolatingFunction[args__], + x_Symbol, y_Symbol, z_Symbol, opts___?OptionQ] := + Module[{pos}, + pos = Flatten[Position[{args}, #]& /@ {x, y, z}]; + ContourPlot3D[ifun[args], + Evaluate[ + Sequence @@ MapThread[Prepend, {First[ifun][[pos]], {x, y, z}}] + ], opts] + ] + + + +(****** not used ******) +(* This is borrowed from Hardle. It's designed to make the interval + begin nearly at Min[data] - h and end nearly at Max[data] + h. + I don't use it: It extends the edges too far for my taste. *) +MinMax[data_, {h_, M_}] := + Module[{step, nbins, start, origin}, + dx = h/M; + nbins = Floor[(Max[data] - Min[data])/dx] + 2(M + 1 + Ceiling[M/10]); + start = Min[data] - h - .1 dx; + origin = dx Floor[(start/dx) - .5]; + {origin, origin + dx (nbins + 1)} + ] + +End[] +EndPackage[] + + diff --git a/MathematicaFiles/Applications/DateFunctions.m b/MathematicaFiles/Applications/DateFunctions.m new file mode 100755 index 0000000..56fbbf1 --- /dev/null +++ b/MathematicaFiles/Applications/DateFunctions.m @@ -0,0 +1,206 @@ +(* :Title: DateFunctions *) + +(* :Author: Mark Fisher *) + +(* :Date: July 2005 *) + +(* :Package Version: 0.2 *) + +(* :Mathematica Version: 6.0 *) + +(* :Summary: +A number of functions to convert dates between list, string, and integer +representations. The options have the same form as ConversionOptions for +Import for "CSV" files. +*) + +BeginPackage["DateFunctions`"] + +DateToIndex::usage = "DateToIndex[{year, month, day}] converts the date to +an integer using {1900, 1, 1} as the base day. DateToIndex[{year, month}] +converts the date to an integer using {1900, 1} as the base month. In +either case, a different base can be specified as a second argument." + +DayIndexToDate::usage = "DayIndexToDate[index] converts the integer index +to {year, month, day} using {1900, 1, 1} as the base day. A different base +can be specified as a second argument." + +MonthIndexToDate::usage = "MonthIndexToDate[index] converts the integer +index to {year, month} using {1900, 1} as the base month. A different base +can be specified as a second argument." + +StringDateToListDate::usage = "StringDateToListDate[date, opts] returns a +date of the form {y, m, d} given the string of the form \"yyyy/mm/dd\". +StringDateToListDate takes three options. \"DateStyle\" has settings +\"Scientific\" (the default), \"American\" (\"mm/dd/yyyy\"), or +\"European\" (\"dd/mm/yyyy\"). \"DateSeparator\" has default setting \"/\". +\"TwoDigitYearFunction\" has default None (and has not yet been +implemented). StringDateToListDate also works with dates of the form +\"yyyy/mm\" and \"mm/yyyy\", etc." + +StringDateToIntegerDate::usage = "StringDateToIntegerDate[date, opts] +returns an integer of the form yyyymmdd given the string of the form +\"yyyy/mm/dd\". StringDateToListDate takes three options. \"DateStyle\" has +settings \"Scientific\" (the default), \"American\" (\"mm/dd/yyyy\"), or +\"European\" (\"dd/mm/yyyy\"). \"DateSeparator\" has default setting \"/\". +\"TwoDigitYearFunction\" has default None (and has not yet been +implemented)." + +ListDateToStringDate::usage = "ListDateToStringDate[{y, m, d}, opts] +returns a date of the form \"yyyy/mm/dd\". StringDateToListDate takes three +options. \"DateStyle\" has settings \"Scientific\" (the default), +\"American\" (\"mm/dd/yyyy\"), or \"European\" (\"dd/mm/yyyy\"). +\"DateSeparator\" has default setting \"/\". \"TwoDigitYear\" has +default False." + +IntegerDateToStringDate::usage = "IntegerDateToStringDate[int] take an +integer of the form yyyymmdd and returns a string date of the +\"Scientific\" form \"yyyy/mm/dd\". IntegerDateToStringDate takes three +options. \"DateStyle\" has settings \"Scientific\" (the default), +\"American\" (\"mm/dd/yyyy\"), or \"European\" (\"dd/mm/yyyy\"). +\"DateSeparator\" has default setting \"/\". \"TwoDigitYear\" has +default False (and has not yet been implemented)." + +ListDateToIntegerDate::usage = "ListDateToIntegerDate[{year, month, day}] +returns an integer of the form yyyymmdd. ListDateToIntegerDate[{year, month}] +returns an integer of the form yyyymm." + +IntegerDateToListDate::usage "IntegerDateToListDate[int] returns +a list of the form {yyyy, mm, dd} or {yyyy, mm} depending on the +magnitude of the integer." + +Begin["Private`"] + +(***** code starts here *****) + +DateToIndex[date : {y_, m_}, base_:{1900, 1}] := {12, 1}.(date - base) + +DateToIndex[date : {y_, m_, d_}, base_:{1900, 1, 1}] := DateDifference[base, date] + +DayIndexToDate[i_Integer, base_:{1900, 1, 1}] := DatePlus[base, i] + +MonthIndexToDate[i_Integer, base_:{1900, 1}] := monthindextodate[i, base] + +monthindextodate = + Compile[{{i, _Integer}, {base, _Integer, 1}}, + With[{q = base[[1]] + Quotient[i, 12], m = base[[2]] + Mod[i, 12]}, + {q + Quotient[m, 12, 1], Mod[m, 12, 1]} + ]] + +Options[StringDateToListDate] = + {"DateStyle" -> "Scientific", + "DateSeparator" -> "/", + "TwoDigitYearFunction" -> None} + +StringDateToListDate[date_String, opts___?OptionQ] := + Module[{separator, style, fun, split, order}, + {separator, style, fun} = + {"DateSeparator", "DateStyle", "TwoDigitYearFunction"} /. + {opts} /. Options[StringDateToListDate]; + split = StringSplit[date, separator]; + order = If[Length[split] == 3, + (* then *) + Switch[style, + "Scientific", {1, 2, 3}, + "American", {3, 1, 2}, + "European", {3, 2, 1}, + _, {1, 2, 3}], + (* else *) + Switch[style, + "Scientific", {1, 2}, + "American" | "European", {2, 1}, + _, {1, 2}] + ]; + ToExpression[split][[ order ]] + ] + +StringDateToIntegerDate[date_String, opts___?OptionQ] := + ListDateToIntegerDate[StringDateToListDate[date, opts]] + +Options[ListDateToStringDate] = + {"DateStyle" -> "Scientific", + "DateSeparator" -> "/", + "TwoDigitYear" -> False} + +ListDateToStringDate[{y_Integer, m_Integer, d_Integer}, opts___?OptionQ] := + Module[{separator, style, y2, order}, + {separator, style, y2} = + {"DateSeparator", "DateStyle", "TwoDigitYear"} /. + {opts} /. Options[ListDateToStringDate]; + order = Switch[style, + "Scientific", {1, 2, 3}, + "American", {2, 3, 1}, + "European", {3, 2, 1}, + _, {1, 2, 3}]; + StringJoin[ + Insert[ + {If[TrueQ[y2], StringDrop[#, 2], #]& @ ToString[y], + StringJoin @@ (ToString /@ IntegerDigits[m, 10, 2]), + StringJoin @@ (ToString /@ IntegerDigits[d, 10, 2])}[[order]], + separator, {{2}, {3}} + ] + ] + ] + +ListDateToStringDate[{y_Integer, m_Integer}, opts___?OptionQ] := + Module[{separator, style, fun, order}, + {separator, style, y2} = + {"DateSeparator", "DateStyle", "TwoDigitYear"} /. + {opts} /. Options[ListDateToStringDate]; + order = Switch[style, + "Scientific", {1, 2}, + "American" | "European", {2, 1}, + _, {1, 2}]; + StringJoin[ + Insert[ + {If[TrueQ[y2], StringDrop[#, 2], #]& @ ToString[y], + StringJoin @@ (ToString /@ IntegerDigits[m, 10, 2])}[[order]], + separator, {{2}} + ] + ] + ] + +Options[IntegerDateToStringDate] = + {"DateStyle" -> "Scientific", + "DateSeparator" -> "/", + "TwoDigitYear" -> False} + +IntegerDateToStringDate[i_Integer /; i >= 10^6, opts___?OptionQ] := + Module[{separator, style, y2, order, list}, + {separator, style, y2} = + {"DateSeparator", "DateStyle", "TwoDigitYear"} /. + {opts} /. Options[ListDateToStringDate]; + order = Switch[style, + "Scientific", {1, 2, 3}, + "American", {3, 1, 2}, + "European", {3, 2, 1}, + _, {1, 2, 3}]; + list = StringSplit[StringInsert[ToString[i], " ", {5, 7}]][[ order ]]; + StringJoin @@ Most[Flatten[Transpose[{list, {separator, separator, ""}}]]] + ] + +IntegerDateToStringDate[i_Integer /; i < 10^6, opts___?OptionQ] := + Module[{separator, style, y2, order, list}, + {separator, style, y2} = + {"DateSeparator", "DateStyle", "TwoDigitYear"} /. + {opts} /. Options[ListDateToStringDate]; + order = Switch[style, + "Scientific", {1, 2}, + "American" | "European", {2, 1}, + _, {1, 2}]; + list = StringSplit[StringInsert[ToString[i], " ", {5}]][[ order ]]; + StringJoin @@ Most[Flatten[Transpose[{list, {separator, ""}}]]] + ] + +ListDateToIntegerDate[date : {y_Integer, m_Integer, d_Integer}] := + date.{10000, 100, 1} + +ListDateToIntegerDate[date : {y_Integer, m_Integer}] := date.{100, 1} + +IntegerDateToListDate[i_Integer] := + ToExpression @ StringSplit[ + StringInsert[ToString[i], " ", If[i < 10^6, {5}, {5, 7}]] + ] + +End[] +EndPackage[] diff --git a/MathematicaFiles/Applications/Difference.m b/MathematicaFiles/Applications/Difference.m new file mode 100755 index 0000000..990e0a2 --- /dev/null +++ b/MathematicaFiles/Applications/Difference.m @@ -0,0 +1,58 @@ +(* :Title: Difference *) + +(* :Author: Mark Fisher *) + +(* :Summary: Code for differencing vectors (and higher order tensors). *) + +(* :Discussion: + Difference is implemented using polynomials in the lag operator to + compute the kernel for ListConvolve. +*) + +Difference::usage = "Difference[list] returns the first differnce of + the list. Difference[list, d] returns the d-th difference of the + list (d >= 0). (For negative d, Difference returns the accumulated + sum.) Difference[list, d, s] returns the d-th difference of the + list with a span of s (s >= 1). The list can be a matrix or a + tensor. Difference[list, polyfun] takes a polynominal function as + a second argument to specify the differencing kernel symbolically. + In fact, Difference[list, d, s] calls Difference[list, (1-#^s)^d + &]. For another example, Difference[list, (1-#^s)^d (1-#)^n &] + performs d-th seasonal differencing at span s and n-th + differencing at span 1." + +FractionalDifference::usage = "FractionalDifference[list, polyfun, maxlag] + returns the fractionally differenced list computed from the polyfun and + truncating at maxlag. A typical example of polyfun is (1-#)^(-2/3)&." + +Difference[list_List, d_Integer:1, s_Integer:1] /; Positive[s] := + Switch[{d, s}, + {1, 1}, Rest[list] - Drop[list, -1], + {0, _}, list, + {_?Negative, _}, Nest[Rest @ FoldList[Plus, 0, #] &, list, -d], + {_, _}, Difference[list, (1 - #^s)^d &] + ] + +Difference[list_List, poly_, var_] := + Difference[list, Function[var, poly]] + +(* # is used purely as a dummy variable in p[#] *) +Difference[list_List, p_Function] /; PolynomialQ[p[#], #] := + ListConvolve[DifferenceKernel[p, TensorRank[list]], list] + +DifferenceKernel[poly_, var_Symbol, rank_Intger:1] := + DifferenceKernel[Function[var, poly], rank] + +DifferenceKernel[p_Function, rank_Integer:1] := + With[{ker = CoefficientList[p[#], #]}, + If[rank > 1, + (Composition @@ Table[List, {rank - 1}]) /@ ker, + ker] + ] + +FractionalDifference[list_List, fun_Function, maxlag_:Automatic] := + Module[{ml}, + ml = If[TrueQ[maxlag == Automatic], Floor[Length[list]/2], maxlag]; + Difference[list, + Block[{L}, Function @@ {{L}, Normal[Series[fun[L], {L, 0, ml}]]}]] + ] \ No newline at end of file diff --git a/MathematicaFiles/Applications/DirichletDistribution.m b/MathematicaFiles/Applications/DirichletDistribution.m new file mode 100755 index 0000000..9a2c39d --- /dev/null +++ b/MathematicaFiles/Applications/DirichletDistribution.m @@ -0,0 +1,141 @@ +(* code for Random by Rob Knapp *) + +(* Dirichlet distribution *) +DirichletDistribution::usage = "DirichletDistribution[\[Alpha]] \ +represents a Dirichlet distribution with parameter vector \[Alpha] \ +(a list of positive reals). DirichletDistribution[d] (where d is \ +a positive integer) represents the \"flat\" Dirichlet distribution \ +with \[Alpha] = Table[1, {d}]." + +DirichletDistribution /: + Random`DistributionVector[ + DirichletDistribution[a_?(VectorQ[#, Positive] &)], + n_, prec_ + ] := + Transpose[#]/Total[#]& @ + Map[RandomReal[GammaDistribution[#, 1], n, + WorkingPrecision -> prec]&, a] + +(* +DirichletDistribution /: + Random`DistributionVector[ + DirichletDistribution[d_Integer?Positive], + n_, prec_ + ] := + Transpose[#]/Total[#]& @ + Map[RandomReal[GammaDistribution[#, 1], n, + WorkingPrecision -> prec]&, + Table[1, {d}]] +*) + +DirichletDistribution /: + Random`DistributionVector[ + DirichletDistribution[d_Integer?Positive], + n_, prec_ + ] := + Random`DistributionVector[DirichletDistribution[Table[1, {d}]], n, prec] + +DirichletDistribution /: + PDF[DirichletDistribution[parms_List], w_List] /; + Length[parms] == Length[w] := + Gamma[Tr[parms]]/Times@@(Gamma /@ parms) Times @@ (w^(parms - 1)) + +BayesianBootstrapFunction::usage = "BayesianBootstrapFunction[moms, \ +vars, parms, data] returns a function that takes a positive integer n \ +as an argument and returns n Bayesian bootstrap draws for the specified \ +moments, variable names, parameter names, and data." + +(* +Options[BayesianBootstrapFunction] = {StartingValues -> Automatic} + +BayesianBootstrapFunction[moms_List, vars_List, parms_List, data_List, + opts___?OptionQ] := + Module[{ + sv = StartingValues /. {opts} /. Options[BayesianBootstrapFunction] + }, + If[sv === Automatic, sv = Table[0, {Length[parms]}]]; + With[{ + fropts = FilterOptions[FindRoot, opts], + nmoms = (Function @@ {vars, moms}) @@ Transpose[data], + parmseq = Sequence @@ Transpose[{parms, sv}], + len = Length[data] + }, + Function[{n}, + (parms /. FindRoot[Expand /@ (nmoms.#), parmseq, fropts])& /@ + RandomReal[DirichletDistribution[len], n] + ] + ]] +*) +(* +BayesianBootstrapFunction[moms_List, vars_List, parms:{__Symbol}, data_List, + opts___?OptionQ] := + With[{ + fropts = FilterOptions[FindRoot, opts], + nmoms = (Function @@ {vars, moms}) @@ Transpose[data], + parmseq = Sequence @@ Transpose[{parms, Table[0, {Length[parms]}]}], + len = Length[data] + }, + Function[{n}, + (parms /. FindRoot[Expand /@ (nmoms.#), parmseq, fropts])& /@ + RandomReal[DirichletDistribution[len], n] + ] + ] +*) + +BayesianBootstrapFunction[moms_List, vars_List, parms:{__Symbol}, data_List, + opts___?OptionQ] := + BayesianBootstrapFunction[moms, vars, + Transpose[{parms, Table[0, {Length[parms]}]}], data, opts] + +BayesianBootstrapFunction[moms_List, vars_List, parms:{{_Symbol, _?NumericQ} ..}, + data_List, opts___?OptionQ] := + With[{ + fropts = FilterOptions[FindRoot, opts], + nmoms = (Function @@ {vars, moms}) @@ Transpose[data], + parmseq = Sequence @@ parms, + len = Length[data] + }, + Function[{n}, + (parms /. FindRoot[Expand /@ (nmoms.#), parmseq, fropts])& /@ + RandomReal[DirichletDistribution[len], n] + ] + ] + +BayesianBootstrapMean::usage = "BayesianBootstrapMean[data, n] returns n \ +Bayesian bootstrap draws of the mean(s) of the specified data." + +BayesianBootstrapMean[data_List, n_Integer?Positive] := + RandomReal[DirichletDistribution[Length[data]], n].data + +BayesianBootstrapLinearRegress::usage = +"BayesianBootstrapLinearRegress[data, n] returns n Bayesian bootstrap draws of \ +the coefficients of the specified data where each row of the data represents \ +an observation of the form (x1, x2, ..., xn, y). BayesianBootstrapLinearRegress \ +takes the option IncludeConstant. The default is IncludeIntercept -> True." + +(* use IncludeIntercept to avoid conflict with IncludeConstant from + LinearRegression context *) +IncludeIntercept::usage = "IncludeIntercept is an option for \ +BayesianBootstrapLinearRegress. It is used to specify whether a constant \ +is to be added to the data matrix." + +Options[BayesianBootstrapLinearRegress] = {IncludeIntercept -> True} + +BayesianBootstrapLinearRegress[data_?MatrixQ, n_Integer, opts___?OptionQ] := + With[{ + d = If[TrueQ[IncludeIntercept /. {opts} /. + Options[BayesianBootstrapLinearRegress]], + Prepend[#, 1]& /@ data, + data], + len = Length[data] + }, + With[{ + X = Most /@ d, + y = Last /@ d + }, + Function[w, + With[{t = Transpose[X].DiagonalMatrix[w]}, LinearSolve[t.X, t.y]] + ] /@ RandomReal[DirichletDistribution[len], n] + ]] + + diff --git a/MathematicaFiles/Applications/DotPlot.m b/MathematicaFiles/Applications/DotPlot.m new file mode 100755 index 0000000..e060304 --- /dev/null +++ b/MathematicaFiles/Applications/DotPlot.m @@ -0,0 +1,179 @@ +(* :Title: DotPlot *) + +(* :Author: Mark Fisher *) + +(* :Context: DotPlot` *) + +(* :Package Version: 3.0 April 2006 *) + +(* :Mathematica Version: 5.2 *) + +(* :Summary: + DotPlot is an enhnaced version of ListPlot combining points with + "connecting" lines that leave a gap near the points. DotPlot + effectively replicates the kind of plot used in Edward R. Tufte's <The + visual display of quantitative information> (1983, Graphics Press: + Cheshire, Connecticut) on pages 74-75 and elsewhere. + + Also included is CirclePlot, another enhanced version of ListPlot that + plots the points as circles. CirclePlot has the option Jitter which + specifies whether to add random jitter to the data points. +*) + +(* :History: + The original version of DotPlot created the gaps by laying down + oversized white points to mask the lines near the points. The current + version computes the end points of the connecting lines using a + transformation involving PlotRange and AspectRatio. + + October 2006, modified to accomodate Version 6. In particular, + Point[{pt1, ..., ptn}] instead of {Point[pt1], ..., Point[ptn]}. +*) + +(* :Notes: + There is some slightly tricky stuff regarding the default PointSize for + DotPlot. The idea is to set the default PointSize in such a way that if + the user passes a PlotStyle option to change the color (for example), + the default PointSize remains intact, while at the same time allowing a + user-specified PointSize to control. + + Also, the FullOptions[] values for PlotRange and AspectRatio are + imposed on both DotPlot and CirclePlot in order to prevent the default + algorithms to reshape and resize the plot after the lines or circles + have been added when the settings are Automatic. This may require the + user to give an explicit PlotRange instead of All to avoid trimming + some circles. + + The use of DeleteCases regarding the lists of options is not necessary: + I'm just being neat and tidy, avoiding redundancies and the expense of + a small amount of speed. + + The lines in DotPlot are computed as follows. Let {a, b} denote an + adjacent pair of points. Then {A, B} = T.#& /@ {a, b} is the pair in + standardized coordinates, where + T = {{1/xr, 0}, {0, ar/yr}} + and where ar is the aspect ration, xr is the horizontal range, and yr + is the vertical range. The distance d = Sqrt[#.#]&[A - B] is computed, + and if d > 2 r (where r is the circle radius) then {A, B} are moved + toward each other and returned to the original coordinates: + Inverse[T].#& /@ ({A, B} + {B - A, A - B}(r/d)) + If d <= 2 r, then the line length should be zero and consequently the + pair is discarded. +*) + +BeginPackage["DotPlot`", {"Utilities`FilterOptions`"}] + +DotPlot::usage = "DotPlot[data] is an enhanced version of ListPlot +combining dots and lines. The radius of the line gaps are controlled by the +option DotPlotGap. The default setting is DotPlotGap -> .015. The line gaps +are computed via a transformation using PlotRange and AspectRatio. +Redisplaying the plot with different settings of these options may produce +undesirable results. Instead, recreate the plot with the desired settings." + +CirclePlot::usage = "CirclePlot[data] is an enhanced version of ListPlot +using circles to indicate the points. CirclePlot takes the option +CirclePlotRadius. The default setting is CirclePlotRadius -> .01. The +circles are computed via a transformation using PlotRange and AspectRatio. +Redisplaying the plot with different settings of these options may produce +undesirable results. Instead, recreate the plot with the desired settings. +CirclePlot also takes the options Jitter and JitterFactor. If Jitter -> True, +then random jitter is added to the plotted points. The amount of jitter is +controlled by JitterFactor." + +DotPlotGap::usage = "DotPlotGap is an option for DotPlot which specifies +the radius of the line gaps around the data points." + +CirclePlotRadius::usage = "CirclePlotRadius is an option for CirclePlot which +specifies the radius of the circles that represent the data points." + +Jitter::usage = "Jitter is an option for CirclePlot which specifies whether +to add jitter to the data points. The default setting is Jitter -> False." + +JitterFactor::usage = "JitterFactor controls the amount of jitter when Jitter -> True. +The default setting is JitterFactor -> 1." + +Begin["`Private`"] + +Options[DotPlot] = {DotPlotGap -> .02} + +DefaultPointSize = .012 + +DotPlot[data : ({__?NumericQ} | {{_?NumericQ, _?NumericQ} ..}), + opts___?OptionQ] := + Module[{plotopts, ps, r, g, ar, pr, xr, yr, pts, ptpairs, cf, + shrunk, lines, gp}, + plotopts = {FilterOptions[ListPlot, opts]} /. + f_[PlotStyle, ps_] /; FreeQ[{ps}, PointSize[_]] :> + f[PlotStyle, Flatten[{PointSize[DefaultPointSize], ps}]]; + plotopts = Sequence @@ + Append[plotopts, PlotStyle -> PointSize[DefaultPointSize]]; + ps = DeleteCases[PlotStyle /. {plotopts}, PointSize[_], {0, Infinity}]; + If[ps === Automatic, ps = {}]; + r = DotPlotGap /. {opts} /. Options[DotPlot]; + g = Block[{$DisplayFunction = Identity}, + ListPlot[data, PlotJoined -> False, Evaluate[plotopts]]]; + {ar, pr} = {AspectRatio, PlotRange} /. AbsoluteOptions[g]; + {xr, yr} = pr[[All, 2]] - pr[[All, 1]]; + pts = Cases[g[[1]], Point[p_] :> p, Infinity]; + If[$VersionNumber >= 6, pts = Flatten[pts, 1]]; (* Version 6 changes *) + ptpairs = Partition[pts, 2, 1]; + cf = MakeLineGapFunction[{r, ar, xr, yr}]; + shrunk = DeleteCases[cf @@@ (Flatten /@ ptpairs), {{0.,0.}, {0.,0.}}]; + lines = Graphics[Flatten @ {ps, Line /@ shrunk}]; + gp = DeleteCases[g, (PlotRange -> _) | (AspectRatio -> _), Infinity]; + Show[gp, lines, PlotRange -> pr, AspectRatio -> ar] + ] + +(* helper function *) +MakeLineGapFunction[{r_, ar_, xr_, yr_}] := + Compile[{x1, y1, x2, y2}, + With[{d = Sqrt[ar^2*xr^2*(y1 - y2)^2 + (x1 - x2)^2*yr^2]/(xr*yr)}, + If[d <= 2*r, + {{0, 0}, {0, 0}}, (* to be discarded *) + {{(d*x1 + r*(-x1 + x2))/d, (d*y1 + r*(-y1 + y2))/d}, + {(r*(x1 - x2) + d*x2)/d, (r*(y1 - y2) + d*y2)/d}} + ] + ]] + +Options[CirclePlot] = {CirclePlotRadius -> .01, + Jitter -> False, JitterFactor -> 1} + +CirclePlot[data : ({__?NumericQ} | {{_?NumericQ, _?NumericQ} ..}), + opts___?OptionQ] := + Module[{plotopts, r, g, ar, pr, xr, yr, gp, j, jfactor, jfun, + pts2circles, pts}, + plotopts = FilterOptions[ListPlot, opts]; + r = CirclePlotRadius /. {opts} /. Options[CirclePlot]; + {j, jfactor} = {Jitter, JitterFactor} /. {opts} /. Options[CirclePlot]; + g = Block[{$DisplayFunction = Identity}, + ListPlot[data, PlotJoined -> False, plotopts]]; + {ar, pr} = {AspectRatio, PlotRange} /. AbsoluteOptions[g]; + {xr, yr} = pr[[All, 2]] - pr[[All, 1]]; + gp = DeleteCases[g, (PlotRange -> _) | (AspectRatio -> _), Infinity]; + If[TrueQ[j], + jfun = MakeJitterFunction[{xr, yr}, jfactor], + jfun = Identity + ]; + pts2circles = If[ + $VersionNumber >= 6, (* Version 6 changes *) + (* then *) + gp /. Point[pts:{{_, _}..}] :> (Circle[jfun[#], r * {xr, yr/ar}]& /@ pts), + (* else *) + gp /. Point[{x_, y_}] :> Circle[jfun[{x, y}], r * {xr, yr/ar}] + ]; + Show[pts2circles, PlotRange -> pr, AspectRatio -> ar] + ] + +(* helper function *) +MakeJitterFunction[{xr_, yr_}, factor_:1] := + With[{a = xr/50, b = yr/50}, + Compile[{{pt, _Real, 1}}, + pt + factor * {Random[Real, {-a, a}], Random[Real, {-b, b}]} + ] + ] + +End[] +EndPackage[] + + + diff --git a/MathematicaFiles/Applications/EulerSimulate.m b/MathematicaFiles/Applications/EulerSimulate.m new file mode 100755 index 0000000..d53f6ca --- /dev/null +++ b/MathematicaFiles/Applications/EulerSimulate.m @@ -0,0 +1,146 @@ +(* :Title: EulerSimulate *) + +(* :Author: Mark Fisher *) + +(* :Context: EulerSimulate` *) + +(* :Mathematica Version: 6.0 *) + +(* :History: + Version 1.0 February 1999. + Version 1.1 September 1999. + Use RandomArray instead of StandardNormal. + Version 1.2 June 2000. + Improved compiling. + Modified argument list. + Added option InitialTime. + Added scalar verion. + Version 2.0 Changed Random to RandomReal for Version 6 +*) + +(* :Keywords: Ito's lemma, stochastic calculus, random walk, brownian +motion, option pricing, Black-Scholes *) + +(* :Summary: simulate SDEs via Euler approximation *) + +(* :Discussion: +This package impliments first-order Euler simulation for any number of Ito +processes with any number of arbitrarily-correlated Brownian motions. The +sole function is EulerSimulate. +*) + +(* :Requirements: This package imports the package + Statistics`NormalDistribution.m *) + +(* :Examples: + +Example 1 +Geometric brownian motion: + +sim = EulerSimulate[.2 s, .1 s, {s, 100}, {1, 10^3}]; +ListPlot[sim, PlotJoined -> True] + +Example 2 +To let time play an active role, model time explicitly as an Ito process: + +sim = EulerSimulate[{1, x - t}, {{0}, {1}}, {t, 0}, {x, 0}, {1, 10^3}, + IncludeTime -> False]; +ListPlot[sim, PlotJoined -> True] + +Example 3 +Three "affine" state variables: + +mu = {5(m - r), .1( .05 - m), 1( .01 - v)}; +sig = Re @ {{Sqrt[v], 0, 0}, {0, .1 Sqrt[m], 0}, {0, 0, .1 Sqrt[v]}}; +sim = EulerSimulate[mu, sig, {r, .05}, {m, .05}, {v, .01}, {1, 10^3}]; +Show @ GraphicsArray @ + Table[ListPlot[sim[[All, {1, i}]], PlotJoined -> True, + DisplayFunction -> Identity, Frame -> True, Axes -> False], + {i, 2, 4}] + +*) + +BeginPackage["EulerSimulate`"] + +EulerSimulate::usage = "EulerSimulate[drift, diffusion, {x, x0}, {duration, \ +nsteps}] returns a list of simulated values for the Ito process determined \ +by the arguments. The arguments specify the drift and diffusion, the \ +symbolic name and initial value {x, x0}, and the length of time and the \ +number of time steps,{duration, nsteps}. The default settings for the \ +options are Compiled -> True, IncludeTime -> True, InitialTime -> 0, and \ +IntermediateValues -> True. A system of Ito processes can be simulated by \ +specifying the drift as a vector and the the diffusion as a matrix, and by \ +providing a {x, x0} pair for each process in a sequence. By default, \ +EulerSimulate generates a matrix of orthogonal standard normal deviates; \ +alternatively, the vector form of EulerSimulate allows the user to supply a \ +matrix of shocks as a final optional argument." + +IncludeTime::usage = "IncludeTime is an option for EulerSimulate. The \ +default setting is IncludeTime -> True." + +InitialTime::usage = "InitialTime is an option for Eulersimulate. The \ +default setting is InitialTime -> 0." + +IntermediateValues::usage = "IntermediateValues is an option for \ +EulerSimulate. The default setting is IntermediateValues -> True." + +Begin["`Private`"] + +Options[EulerSimulate] = {Compiled -> True, IncludeTime -> True, + InitialTime -> 0, IntermediateValues -> True} + +(* main engine: vector version, takes shocks as argument *) + +EulerSimulate[drift_?VectorQ, diffusion_?MatrixQ, + x:{_Symbol, _?NumericQ}.., + {duration_?NumericQ, nsteps_Integer}, + devs_?(MatrixQ[#, NumberQ]&), opts___?OptionQ] /; + (Length[drift] == Length[diffusion] == Length[{x}] && + Dimensions[devs][[2]] == Dimensions[diffusion][[2]]) := + Module[{compile, time, t0, list, dt, sqrtdt, args0, args, + errargs, fun, sim}, + {compile, time, t0, list} = + {Compiled, IncludeTime, InitialTime, IntermediateValues} /. + {opts} /. Options[EulerSimulate]; + sqrtdt = Sqrt[ dt = N[duration/nsteps] ]; + {args, args0} = Transpose[{x}]; + errargs = Unique[]& /@ Range[Last @ Dimensions[diffusion]]; + fun = If[TrueQ[compile], Compile, Function] @@ + {Join[args, errargs], args + drift dt + (diffusion.errargs) sqrtdt}; + sim = If[TrueQ[list], FoldList, Fold] + [fun @@ Join[#1, #2]&, N[args0], devs]; + If[TrueQ[time] && TrueQ[list], + Flatten /@ Transpose[ + {N @ Range[t0, t0 + duration, duration/nsteps], sim}], + sim + ] + ] + +(* vector version, constructs shocks and calls main engine *) + +EulerSimulate[drift_?VectorQ, diffusion_?MatrixQ, + x:{_Symbol, _?NumericQ}.., + {duration_?NumericQ, nsteps_Integer}, opts___?OptionQ] /; + (Length[drift] == Length[diffusion] == Length[{x}]) := + EulerSimulate[drift, diffusion, x, {duration, nsteps}, + (* make the random number matrix *) + RandomReal[NormalDistribution[], + {nsteps, Last @ Dimensions[diffusion]}], + opts] + +(* scalar version, calls vector version *) + +EulerSimulate[drift_, diffusion_, {x_Symbol, x0_?NumericQ}, + {duration_?NumericQ, nsteps_Integer}, opts___?OptionQ] := + If[TrueQ[IncludeTime /. {opts} /. Options[EulerSimulate]], + (* then do nothing *) + Identity, + (* else flatten the result *) + Flatten] @ + EulerSimulate[{drift}, + If[VectorQ[diffusion], {diffusion}, {{diffusion}}], + {x, x0}, {duration, nsteps}, opts] + +End[] +EndPackage[] + diff --git a/MathematicaFiles/Applications/Eurodollar Data.nb b/MathematicaFiles/Applications/Eurodollar Data.nb new file mode 100755 index 0000000..bbc7aa8 --- /dev/null +++ b/MathematicaFiles/Applications/Eurodollar Data.nb @@ -0,0 +1,21433 @@ +(* Content-type: application/mathematica *) + +(*** Wolfram Notebook File ***) +(* http://www.wolfram.com/nb *) + +(* CreatedBy='Mathematica 6.0' *) + +(*CacheID: 234*) +(* Internal cache information: +NotebookFileLineBreakTest +NotebookFileLineBreakTest +NotebookDataPosition[ 145, 7] +NotebookDataLength[ 1086959, 21424] +NotebookOptionsPosition[ 1081746, 21252] +NotebookOutlinePosition[ 1082112, 21268] +CellTagsIndexPosition[ 1082069, 21265] +WindowFrame->Normal +ContainsDynamic->True *) + +(* Beginning of Notebook Content *) +Notebook[{ + +Cell[CellGroupData[{ +Cell["Eurodollar Data", "Title", + CellChangeTimes->{{3.4114804836839523`*^9, 3.411480486271228*^9}}], + +Cell["Download, update, and extract", "Subtitle", + CellChangeTimes->{{3.4114804983971357`*^9, 3.41148050601869*^9}}], + +Cell[CellGroupData[{ + +Cell["Setup", "Section", + CellChangeTimes->{{3.4114805148559523`*^9, 3.411480515479392*^9}}], + +Cell[BoxData[ + RowBox[{"<<", "EuroDollarDataFunctions`"}]], "Input"], + +Cell[BoxData[ + RowBox[{"<<", "PagePrint`"}]], "Input", + CellChangeTimes->{{3.411484665140573*^9, 3.411484669154913*^9}}], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{"$CMEEuroDollarDataDirectory", "=", + RowBox[{"ToFileName", "[", + RowBox[{"{", + RowBox[{"myWorkingDrive", ",", "\"\<projects\\\\eurodollar\>\""}], "}"}], + "]"}]}]], "Input", + CellChangeTimes->{{3.411480872710512*^9, 3.411480873053404*^9}}], + +Cell[BoxData["\<\"d:\\\\data\\\\projects\\\\eurodollar\\\\\"\>"], "Output", + CellChangeTimes->{3.411480552885792*^9, 3.4114808743158703`*^9}] +}, Open ]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{"$CMEEuroDollarDataDirectory", "=", + "\"\<O:\\\\cme_pdfs\\\\\>\""}]], "Input", + CellChangeTimes->{{3.411480963265172*^9, 3.411480973785722*^9}}], + +Cell[BoxData["\<\"O:\\\\cme_pdfs\\\\\"\>"], "Output", + CellChangeTimes->{{3.411480969343712*^9, 3.411480973925996*^9}}] +}, Open ]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{"$CMEEuroDollarSection09Directory", "=", + "\"\<O:\\\\cme_pdfs\\\\Section09\\\\\>\""}]], "Input", + CellChangeTimes->{{3.411480814169496*^9, 3.41148085888573*^9}, { + 3.41148107373874*^9, 3.411481076263672*^9}}], + +Cell[BoxData["\<\"O:\\\\cme_pdfs\\\\Section09\\\\\"\>"], "Output", + CellChangeTimes->{3.41148085950917*^9, 3.4114810770273857`*^9}] +}, Open ]], + +Cell[BoxData[ + RowBox[{"Get", "[", + RowBox[{ + "myWorkingDrive", "<>", + "\"\<\\\\projects\\\\eurodollar\\\\eurodollar_new.m\>\""}], "]"}]], "Input",\ + + Evaluatable->False] +}, Open ]], + +Cell[CellGroupData[{ + +Cell["Read database", "Section", + CellChangeTimes->{{3.4114805736307583`*^9, 3.4114805855852203`*^9}}], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{ + RowBox[{ + RowBox[{ + RowBox[{"{", + RowBox[{"desc", ",", "headings", ",", "cmedata"}], "}"}], "=", + RowBox[{"ImportFuturesRates", "[", + RowBox[{"ToFileName", "[", + RowBox[{ + RowBox[{"{", "$CMEEuroDollarDataDirectory", "}"}], ",", + "\"\<eurodollardata.mef\>\""}], "]"}], "]"}]}], ";"}], "//", + "Timing"}]], "Input", + CellChangeTimes->{{3.410781051453125*^9, 3.410781072359375*^9}, { + 3.4112205638706045`*^9, 3.411220566681611*^9}, {3.411480615058346*^9, + 3.411480616071436*^9}, {3.411480878165612*^9, 3.411480878508504*^9}}], + +Cell[BoxData[ + RowBox[{"{", + RowBox[{"1.4209999999999994`", ",", "Null"}], "}"}]], "Output", + CellChangeTimes->{3.4114806179261703`*^9, 3.411480980659148*^9, + 3.411481723176188*^9, 3.41148380564649*^9, 3.4114841023153334`*^9}] +}, Open ]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{ + RowBox[{ + RowBox[{"daymat", "=", + RowBox[{"MaturityInDays", "[", "cmedata", "]"}]}], ";"}], "//", + "Timing"}]], "Input", + CellChangeTimes->{{3.411213286573807*^9, 3.4112133323810606`*^9}, + 3.411215433966129*^9, {3.4112203638335147`*^9, 3.4112203800273685`*^9}}], + +Cell[BoxData[ + RowBox[{"{", + RowBox[{"1.6880000000000024`", ",", "Null"}], "}"}]], "Output", + CellChangeTimes->{{3.4112133226865687`*^9, 3.411213334251381*^9}, { + 3.4112154197984548`*^9, 3.4112154358676205`*^9}, {3.4112203732162867`*^9, + 3.411220382599059*^9}, 3.411220997939823*^9, 3.41123570653125*^9, + 3.4112997742372847`*^9, {3.4113650889375*^9, 3.4113651109375*^9}, + 3.411371699546875*^9, 3.411480622586384*^9, 3.4114809847894382`*^9, + 3.4114817264024897`*^9, 3.411483809900298*^9, 3.411484104973096*^9}] +}, Open ]], + +Cell[BoxData[ + RowBox[{ + RowBox[{"dateDay", "=", + RowBox[{"Flatten", "/@", + RowBox[{"Union", "[", + RowBox[{"cmedata", "[", + RowBox[{"[", + RowBox[{"All", ",", + RowBox[{"{", + RowBox[{"1", ",", "2"}], "}"}]}], "]"}], "]"}], "]"}]}]}], + ";"}]], "Input", + CellChangeTimes->{{3.411482476525498*^9, 3.41148250009153*^9}}], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{"CMEHeaderReport", "[", + RowBox[{"desc", ",", "headings"}], "]"}]], "Input", + CellChangeTimes->{{3.411221268526948*^9, 3.411221278840025*^9}}], + +Cell[BoxData[ + FrameBox[ + TagBox[GridBox[{ + {"\<\"Eurodollar Futures Rates: Daily\"\>"}, + { + InterpretationBox[ + RowBox[{ + TagBox[GridBox[{ + {"\<\"Quote date: Year\"\>"}, + {"\<\"Quote date: Month\"\>"}, + {"\<\"Quote date: Day\"\>"} + }, + ColumnsEqual->False, + GridBoxAlignment->{"Columns" -> {{Left}}}, + + GridBoxItemSize->{ + "Columns" -> {{Automatic}}, "Rows" -> {{Automatic}}}, + RowsEqual->False], + "Column"], + InterpretationBox[ + StyleBox[ + GraphicsBox[{}, + BaselinePosition->Baseline, + ImageSize->{12, 0}], + CacheGraphics->False], + Spacer[12]], "\<\"CME day number\"\>", + InterpretationBox[ + StyleBox[ + GraphicsBox[{}, + BaselinePosition->Baseline, + ImageSize->{12, 0}], + CacheGraphics->False], + Spacer[12]], + TagBox[GridBox[{ + {"\<\"Maturity date: Year\"\>"}, + {"\<\"Maturity date: Month\"\>"}, + {"\<\"Maturity date: Day\"\>"} + }, + ColumnsEqual->False, + GridBoxAlignment->{"Columns" -> {{Left}}}, + + GridBoxItemSize->{ + "Columns" -> {{Automatic}}, "Rows" -> {{Automatic}}}, + RowsEqual->False], + "Column"], + InterpretationBox[ + StyleBox[ + GraphicsBox[{}, + BaselinePosition->Baseline, + ImageSize->{12, 0}], + CacheGraphics->False], + Spacer[12]], "\<\"Futures rate\"\>"}], + Row[{ + Column[{"Quote date: Year", "Quote date: Month", "Quote date: Day"}], + "CME day number", + Column[{ + "Maturity date: Year", "Maturity date: Month", + "Maturity date: Day"}], "Futures rate"}, + Spacer[12]]]} + }, + ColumnsEqual->False, + GridBoxAlignment->{"Columns" -> {{Left}}}, + GridBoxDividers->{ + "Columns" -> {False, {True}, False}, "Rows" -> {False, {True}, False}}, + GridBoxItemSize->{"Columns" -> {{Automatic}}, "Rows" -> {{Automatic}}}, + RowsEqual->False], + "Column"], + StripOnInput->False]], "Output", + CellChangeTimes->{ + 3.4112212792994404`*^9, 3.411235708296875*^9, 3.411299775611387*^9, { + 3.41136508896875*^9, 3.41136511334375*^9}, 3.41137172825*^9, + 3.411480624565806*^9, 3.41148098559991*^9, 3.4114817275870256`*^9, + 3.411483812121036*^9, 3.4114841070993066`*^9}] +}, Open ]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{"MissingCMEDays", "[", "cmedata", "]"}]], "Input", + CellChangeTimes->{{3.411165992796875*^9, 3.411165997453125*^9}, { + 3.411215218645539*^9, 3.411215220328827*^9}}], + +Cell[BoxData[ + InterpretationBox[GridBox[{ + { + TagBox["\<\"Missing CME Days (by year)\"\>", + "Labeled", + Editable->True, + Selectable->True]}, + { + TagBox[ + TagBox[ + FrameBox[ + TagBox[GridBox[{ + {"1999", "", "", "", "", "", "", "", ""}, + {"2000", "", "", "", "", "", "", "", ""}, + {"2001", "162", "173", "175", "176", "188", "197", "216", "219"}, + {"2002", "56", "127", "198", "201", "218", "", "", ""}, + {"2003", "130", "", "", "", "", "", "", ""}, + {"2004", "26", "112", "", "", "", "", "", ""}, + {"2005", "133", "135", "153", "162", "186", "187", "195", "219"}, + {"2006", "", "", "", "", "", "", "", ""}, + {"2007", "68", "", "", "", "", "", "", ""}, + {"2008", "16", "22", "", "", "", "", "", ""} + }, + ColumnsEqual->False, + GridBoxAlignment->{"Columns" -> {{Right}}}, + + GridBoxDividers->{ + "Columns" -> {False, True, False}, "Rows" -> {{None}}}, + + GridBoxItemSize->{ + "Columns" -> {{Automatic}}, "Rows" -> {{Automatic}}}, + RowsEqual->False], + "Grid"], + StripOnInput->False], + "Labeled", + Editable->True, + Selectable->True], + "SkipImageSizeLevel"]} + }, + BaselinePosition->{2, 1}, + GridBoxAlignment->{ + "Columns" -> {{Center}}, "ColumnsIndexed" -> {}, "Rows" -> {{Center}}, + "RowsIndexed" -> {}}, + GridBoxItemSize->{ + "Columns" -> {{Automatic}}, "ColumnsIndexed" -> {}, "Rows" -> {{1.}}, + "RowsIndexed" -> {}}], + Labeled[ + Framed[ + Grid[{{1999}, {2000}, {2001, 162, 173, 175, 176, 188, 197, 216, 219}, { + 2002, 56, 127, 198, 201, 218}, {2003, 130}, {2004, 26, 112}, {2005, 133, + 135, 153, 162, 186, 187, 195, 219}, {2006}, {2007, 68}, {2008, 16, + 22}}, Dividers -> {{False, True, False}, None}, Alignment -> Right]], + "Missing CME Days (by year)", Top], + Editable->False, + Selectable->False]], "Output", + CellChangeTimes->{ + 3.411165997859375*^9, 3.41116619728125*^9, 3.411215167398771*^9, { + 3.4112152137203627`*^9, 3.4112152640787287`*^9}, 3.4112210091373863`*^9, + 3.411235725515625*^9, 3.411299777844303*^9, {3.411365089*^9, + 3.41136511575*^9}, 3.411371730578125*^9, 3.411480626404954*^9, + 3.411480987345542*^9, 3.41148172936383*^9, 3.411483814185384*^9, + 3.4114841086939645`*^9}] +}, Open ]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{"MostRecentDay", "[", "cmedata", "]"}]], "Input", + CellChangeTimes->{{3.411165939890625*^9, 3.41116594234375*^9}, { + 3.4112153423672066`*^9, 3.411215343723189*^9}}], + +Cell[BoxData[ + InterpretationBox[ + RowBox[{"\<\"Most Recent Day:\"\>", " ", "\<\"07 Feb 2008\"\>", + " ", "\<\"Day\"\>", " ", "26"}], + Row[{"Most Recent Day:", "07 Feb 2008", "Day", 26}, " "]]], "Output", + CellChangeTimes->{ + 3.411165942765625*^9, 3.411166199328125*^9, 3.411214482440829*^9, + 3.411215273336813*^9, 3.4112153441907687`*^9, 3.4112210113672037`*^9, + 3.411235727890625*^9, {3.411365089046875*^9, 3.411365117765625*^9}, + 3.411371735578125*^9, 3.4114806292416058`*^9, 3.411480989761372*^9, + 3.411481731592628*^9, 3.411483817422657*^9, 3.4114841108514423`*^9}] +}, Open ]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{"DateToCMEDay", "[", "]"}]], "Input", + CellChangeTimes->{{3.41116636015625*^9, 3.411166365203125*^9}, { + 3.411166405296875*^9, 3.41116640853125*^9}, 3.411195914640625*^9}], + +Cell[BoxData["27"], "Output", + CellChangeTimes->{3.411166408890625*^9, 3.411194748046875*^9, + 3.411195915078125*^9, 3.4112154644991026`*^9, 3.4112210169579067`*^9, + 3.41123573084375*^9, 3.411365089140625*^9, 3.4113651213125*^9, + 3.41148063616179*^9, 3.411484120935308*^9}] +}, Open ]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{"ListAnimate", "[", + RowBox[{ + RowBox[{ + RowBox[{ + RowBox[{"DateListPlot", "[", + RowBox[{ + RowBox[{"#", "[", + RowBox[{"[", + RowBox[{"All", ",", + RowBox[{ + RowBox[{"-", "2"}], ";;"}]}], "]"}], "]"}], ",", + RowBox[{"Joined", "\[Rule]", "True"}], ",", + RowBox[{"PlotRange", "\[Rule]", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2007", ",", "5", ",", "1"}], "}"}], ",", + RowBox[{"{", + RowBox[{"2018", ",", "3", ",", "1"}], "}"}]}], "}"}], ",", + RowBox[{"{", + RowBox[{"2.5", ",", "6.5"}], "}"}]}], "}"}]}], ",", + RowBox[{"PlotLabel", "\[Rule]", + RowBox[{"Style", "[", + RowBox[{ + RowBox[{"DateString", "[", + RowBox[{ + RowBox[{"#", "[", + RowBox[{"[", + RowBox[{"1", ",", "1"}], "]"}], "]"}], ",", + RowBox[{"{", + RowBox[{ + "\"\<Day\>\"", ",", "\"\< \>\"", ",", "\"\<MonthNameShort\>\"", + ",", "\"\< \>\"", ",", "\"\<Year\>\""}], "}"}]}], "]"}], ",", + RowBox[{"FontFamily", "->", "\"\<Courier\>\""}], ",", "Bold", ",", + "Italic"}], "]"}]}], ",", + RowBox[{"Frame", "\[Rule]", + RowBox[{"{", + RowBox[{"True", ",", "True", ",", "False", ",", "False"}], "}"}]}]}], + "]"}], "&"}], "/@", + RowBox[{"Split", "[", + RowBox[{ + RowBox[{"Cases", "[", + RowBox[{"cmedata", ",", + RowBox[{"{", + RowBox[{ + RowBox[{ + RowBox[{"{", + RowBox[{"2007", ",", + RowBox[{ + "6", "|", "7", "|", "8", "|", "9", "|", "10", "|", "11", "|", + "12"}], ",", "_"}], "}"}], "|", + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "_"}], "}"}]}], ",", "__"}], + "}"}]}], "]"}], ",", + RowBox[{ + RowBox[{ + RowBox[{"#1", "[", + RowBox[{"[", "1", "]"}], "]"}], "\[Equal]", + RowBox[{"#2", "[", + RowBox[{"[", "1", "]"}], "]"}]}], "&"}]}], "]"}]}], ",", + RowBox[{"DefaultDuration", "\[Rule]", "20"}]}], "]"}]], "Input", + CellChangeTimes->{{3.41123739590625*^9, 3.411237539046875*^9}, + 3.41123763965625*^9, {3.411237774296875*^9, 3.4112378513125*^9}, { + 3.41123788228125*^9, 3.41123794934375*^9}, {3.411238013734375*^9, + 3.411238036828125*^9}}], + +Cell[BoxData[ + TagBox[ + StyleBox[ + DynamicModuleBox[{$CellContext`i3$$ = 72, Typeset`show$$ = True, + Typeset`bookmarkList$$ = {}, Typeset`bookmarkMode$$ = "Menu", + Typeset`animator$$, Typeset`animvar$$ = 1, Typeset`name$$ = + "\"untitled\"", Typeset`specs$$ = {{{ + Hold[$CellContext`i3$$], 1, ""}, 1, 161, 1}}, Typeset`size$$ = + Automatic, Typeset`update$$ = 0, Typeset`initDone$$, + Typeset`skipInitDone$$ = True, $CellContext`i3$19001$$ = 0}, + PaneBox[ + PanelBox[ + DynamicWrapperBox[ + TagBox[GridBox[{ + { + ItemBox[ + ItemBox[ + StyleBox[ + TagBox[GridBox[{ + {"\<\"\\!\\(\\*TagBox[\\\"\\\\\\\"\\\\\\\"\\\", HoldForm]\\)\ +\"\>", + AnimatorBox[Dynamic[$CellContext`i3$$], {1, 161, 1}, + AnimationRate->Automatic, + + AppearanceElements->{ + "ProgressSlider", "PlayPauseButton", + "FasterSlowerButtons", "DirectionButton"}, + AutoAction->False, + ContinuousAction->True, + DefaultDuration->20, + DisplayAllSteps->True, + PausedTime->9.008708000183105]} + }, + ColumnsEqual->False, + + GridBoxAlignment->{ + "Columns" -> {Right, {Left}}, "ColumnsIndexed" -> {}, + "Rows" -> {{Baseline}}, "RowsIndexed" -> {}}, + + GridBoxItemSize->{ + "Columns" -> {{Automatic}}, "Rows" -> {{Automatic}}}, + RowsEqual->False], + "Grid"], "ManipulateLabel", + StripOnInput->False], + Alignment->{Automatic, Inherited}, + StripOnInput->False], + Background->None, + StripOnInput->False]}, + { + ItemBox[ + TagBox[ + StyleBox[ + PaneBox[Cell[BoxData[ + TagBox[ + PaneSelectorBox[{1-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.3911136*^9, 5.36}, {3.3935328*^9, 5.36}, { + 3.395952*^9, 5.36}, {3.398976*^9, 5.35}, {3.4068384*^9, + 5.33}, {3.4147008*^9, 5.29}, {3.4225632*^9, 5.24}, { + 3.4304256*^9, 5.22}, {3.438288*^9, 5.22}, {3.4461504*^9, + 5.22}, {3.4540128*^9, 5.23}, {3.4618752*^9, 5.26}, { + 3.4697376*^9, 5.29}, {3.4776*^9, 5.3}, {3.4854624*^9, + 5.33}, {3.4933248*^9, 5.35}, {3.5011872*^9, 5.39}, { + 3.5090496*^9, 5.4}, {3.516912*^9, 5.43}, {3.5253792*^9, + 5.45}, {3.5332416*^9, 5.49}, {3.541104*^9, 5.5}, { + 3.5489664*^9, 5.53}, {3.5568288*^9, 5.55}, {3.5646912*^9, + 5.58}, {3.5725536*^9, 5.6}, {3.580416*^9, 5.62}, { + 3.5882784*^9, 5.64}, {3.5961408*^9, 5.67}, {3.6040032*^9, + 5.69}, {3.6118656*^9, 5.71}, {3.619728*^9, 5.73}, { + 3.6275904*^9, 5.76}, {3.6354528*^9, 5.78}, {3.6433152*^9, + 5.8}, {3.6511776*^9, 5.82}, {3.65904*^9, 5.85}, { + 3.6669024*^9, 5.87}, {3.6747648*^9, 5.89}, {3.683232*^9, + 5.91}, {3.6910944*^9, 5.94}, {3.698352*^9, 5.95}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"01 Jun 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 2-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.3911136*^9, 5.36}, {3.3935328*^9, 5.36}, { + 3.395952*^9, 5.35}, {3.398976*^9, 5.34}, {3.4068384*^9, + 5.33}, {3.4147008*^9, 5.28}, {3.4225632*^9, 5.23}, { + 3.4304256*^9, 5.21}, {3.438288*^9, 5.21}, {3.4461504*^9, + 5.21}, {3.4540128*^9, 5.22}, {3.4618752*^9, 5.24}, { + 3.4697376*^9, 5.27}, {3.4776*^9, 5.28}, {3.4854624*^9, + 5.3}, {3.4933248*^9, 5.33}, {3.5011872*^9, 5.36}, { + 3.5090496*^9, 5.38}, {3.516912*^9, 5.4}, {3.5253792*^9, + 5.42}, {3.5332416*^9, 5.46}, {3.541104*^9, 5.47}, { + 3.5489664*^9, 5.5}, {3.5568288*^9, 5.52}, {3.5646912*^9, + 5.55}, {3.5725536*^9, 5.57}, {3.580416*^9, 5.59}, { + 3.5882784*^9, 5.61}, {3.5961408*^9, 5.64}, {3.6040032*^9, + 5.66}, {3.6118656*^9, 5.68}, {3.619728*^9, 5.7}, { + 3.6275904*^9, 5.73}, {3.6354528*^9, 5.75}, {3.6433152*^9, + 5.77}, {3.6511776*^9, 5.79}, {3.65904*^9, 5.82}, { + 3.6669024*^9, 5.84}, {3.6747648*^9, 5.86}, {3.683232*^9, + 5.88}, {3.6910944*^9, 5.91}, {3.698352*^9, 5.92}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"04 Jun 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 3-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.3911136*^9, 5.36}, {3.3935328*^9, 5.36}, { + 3.395952*^9, 5.36}, {3.398976*^9, 5.35}, {3.4068384*^9, + 5.34}, {3.4147008*^9, 5.3}, {3.4225632*^9, 5.27}, { + 3.4304256*^9, 5.25}, {3.438288*^9, 5.26}, {3.4461504*^9, + 5.26}, {3.4540128*^9, 5.27}, {3.4618752*^9, 5.29}, { + 3.4697376*^9, 5.33}, {3.4776*^9, 5.34}, {3.4854624*^9, + 5.36}, {3.4933248*^9, 5.39}, {3.5011872*^9, 5.42}, { + 3.5090496*^9, 5.44}, {3.516912*^9, 5.46}, {3.5253792*^9, + 5.48}, {3.5332416*^9, 5.52}, {3.541104*^9, 5.53}, { + 3.5489664*^9, 5.56}, {3.5568288*^9, 5.58}, {3.5646912*^9, + 5.61}, {3.5725536*^9, 5.63}, {3.580416*^9, 5.65}, { + 3.5882784*^9, 5.67}, {3.5961408*^9, 5.7}, {3.6040032*^9, + 5.72}, {3.6118656*^9, 5.74}, {3.619728*^9, 5.76}, { + 3.6275904*^9, 5.79}, {3.6354528*^9, 5.81}, {3.6433152*^9, + 5.83}, {3.6511776*^9, 5.85}, {3.65904*^9, 5.88}, { + 3.6669024*^9, 5.9}, {3.6747648*^9, 5.92}, {3.683232*^9, + 5.94}, {3.6910944*^9, 5.97}, {3.698352*^9, 5.98}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"05 Jun 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 4-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.3911136*^9, 5.36}, {3.3935328*^9, 5.36}, { + 3.395952*^9, 5.35}, {3.398976*^9, 5.34}, {3.4068384*^9, + 5.32}, {3.4147008*^9, 5.26}, {3.4225632*^9, 5.22}, { + 3.4304256*^9, 5.2}, {3.438288*^9, 5.21}, {3.4461504*^9, + 5.22}, {3.4540128*^9, 5.25}, {3.4618752*^9, 5.27}, { + 3.4697376*^9, 5.31}, {3.4776*^9, 5.32}, {3.4854624*^9, + 5.35}, {3.4933248*^9, 5.38}, {3.5011872*^9, 5.42}, { + 3.5090496*^9, 5.44}, {3.516912*^9, 5.46}, {3.5253792*^9, + 5.49}, {3.5332416*^9, 5.52}, {3.541104*^9, 5.54}, { + 3.5489664*^9, 5.57}, {3.5568288*^9, 5.59}, {3.5646912*^9, + 5.62}, {3.5725536*^9, 5.64}, {3.580416*^9, 5.66}, { + 3.5882784*^9, 5.68}, {3.5961408*^9, 5.71}, {3.6040032*^9, + 5.73}, {3.6118656*^9, 5.75}, {3.619728*^9, 5.77}, { + 3.6275904*^9, 5.81}, {3.6354528*^9, 5.82}, {3.6433152*^9, + 5.84}, {3.6511776*^9, 5.86}, {3.65904*^9, 5.89}, { + 3.6669024*^9, 5.91}, {3.6747648*^9, 5.94}, {3.683232*^9, + 5.96}, {3.6910944*^9, 5.99}, {3.698352*^9, 6.}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"06 Jun 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 5-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.3911136*^9, 5.36}, {3.3935328*^9, 5.36}, { + 3.395952*^9, 5.36}, {3.398976*^9, 5.35}, {3.4068384*^9, + 5.35}, {3.4147008*^9, 5.31}, {3.4225632*^9, 5.29}, { + 3.4304256*^9, 5.3}, {3.438288*^9, 5.33}, {3.4461504*^9, + 5.35}, {3.4540128*^9, 5.39}, {3.4618752*^9, 5.43}, { + 3.4697376*^9, 5.46}, {3.4776*^9, 5.48}, {3.4854624*^9, + 5.51}, {3.4933248*^9, 5.54}, {3.5011872*^9, 5.58}, { + 3.5090496*^9, 5.61}, {3.516912*^9, 5.63}, {3.5253792*^9, + 5.66}, {3.5332416*^9, 5.7}, {3.541104*^9, 5.72}, { + 3.5489664*^9, 5.74}, {3.5568288*^9, 5.77}, {3.5646912*^9, + 5.8}, {3.5725536*^9, 5.82}, {3.580416*^9, 5.84}, { + 3.5882784*^9, 5.86}, {3.5961408*^9, 5.89}, {3.6040032*^9, + 5.91}, {3.6118656*^9, 5.93}, {3.619728*^9, 5.95}, { + 3.6275904*^9, 5.99}, {3.6354528*^9, 6.}, {3.6433152*^9, + 6.02}, {3.6511776*^9, 6.04}, {3.65904*^9, 6.07}, { + 3.6669024*^9, 6.09}, {3.6747648*^9, 6.12}, {3.683232*^9, + 6.14}, {3.6910944*^9, 6.17}, {3.698352*^9, 6.18}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"07 Jun 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 6-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.3911136*^9, 5.36}, {3.3935328*^9, 5.36}, { + 3.395952*^9, 5.36}, {3.398976*^9, 5.35}, {3.4068384*^9, + 5.35}, {3.4147008*^9, 5.32}, {3.4225632*^9, 5.3}, { + 3.4304256*^9, 5.31}, {3.438288*^9, 5.33}, {3.4461504*^9, + 5.36}, {3.4540128*^9, 5.41}, {3.4618752*^9, 5.45}, { + 3.4697376*^9, 5.49}, {3.4776*^9, 5.52}, {3.4854624*^9, + 5.55}, {3.4933248*^9, 5.58}, {3.5011872*^9, 5.63}, { + 3.5090496*^9, 5.65}, {3.516912*^9, 5.68}, {3.5253792*^9, + 5.71}, {3.5332416*^9, 5.75}, {3.541104*^9, 5.77}, { + 3.5489664*^9, 5.79}, {3.5568288*^9, 5.82}, {3.5646912*^9, + 5.85}, {3.5725536*^9, 5.87}, {3.580416*^9, 5.89}, { + 3.5882784*^9, 5.92}, {3.5961408*^9, 5.95}, {3.6040032*^9, + 5.97}, {3.6118656*^9, 5.99}, {3.619728*^9, 6.01}, { + 3.6275904*^9, 6.04}, {3.6354528*^9, 6.06}, {3.6433152*^9, + 6.08}, {3.6511776*^9, 6.1}, {3.65904*^9, 6.13}, { + 3.6669024*^9, 6.15}, {3.6747648*^9, 6.17}, {3.683232*^9, + 6.19}, {3.6910944*^9, 6.22}, {3.698352*^9, 6.24}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"08 Jun 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 7-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.3911136*^9, 5.36}, {3.3935328*^9, 5.36}, { + 3.395952*^9, 5.36}, {3.398976*^9, 5.35}, {3.4068384*^9, + 5.35}, {3.4147008*^9, 5.32}, {3.4225632*^9, 5.29}, { + 3.4304256*^9, 5.3}, {3.438288*^9, 5.33}, {3.4461504*^9, + 5.36}, {3.4540128*^9, 5.41}, {3.4618752*^9, 5.46}, { + 3.4697376*^9, 5.5}, {3.4776*^9, 5.53}, {3.4854624*^9, + 5.56}, {3.4933248*^9, 5.59}, {3.5011872*^9, 5.64}, { + 3.5090496*^9, 5.66}, {3.516912*^9, 5.69}, {3.5253792*^9, + 5.72}, {3.5332416*^9, 5.76}, {3.541104*^9, 5.78}, { + 3.5489664*^9, 5.8}, {3.5568288*^9, 5.83}, {3.5646912*^9, + 5.86}, {3.5725536*^9, 5.88}, {3.580416*^9, 5.9}, { + 3.5882784*^9, 5.93}, {3.5961408*^9, 5.96}, {3.6040032*^9, + 5.98}, {3.6118656*^9, 6.}, {3.619728*^9, 6.02}, { + 3.6275904*^9, 6.05}, {3.6354528*^9, 6.07}, {3.6433152*^9, + 6.09}, {3.6511776*^9, 6.11}, {3.65904*^9, 6.14}, { + 3.6669024*^9, 6.16}, {3.6747648*^9, 6.18}, {3.683232*^9, + 6.2}, {3.6910944*^9, 6.23}, {3.698352*^9, 6.25}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"11 Jun 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 8-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.3911136*^9, 5.36}, {3.3935328*^9, 5.36}, { + 3.395952*^9, 5.36}, {3.398976*^9, 5.36}, {3.4068384*^9, + 5.39}, {3.4147008*^9, 5.37}, {3.4225632*^9, 5.37}, { + 3.4304256*^9, 5.39}, {3.438288*^9, 5.44}, {3.4461504*^9, + 5.48}, {3.4540128*^9, 5.54}, {3.4618752*^9, 5.58}, { + 3.4697376*^9, 5.63}, {3.4776*^9, 5.66}, {3.4854624*^9, + 5.7}, {3.4933248*^9, 5.74}, {3.5011872*^9, 5.78}, { + 3.5090496*^9, 5.81}, {3.516912*^9, 5.83}, {3.5253792*^9, + 5.87}, {3.5332416*^9, 5.91}, {3.541104*^9, 5.93}, { + 3.5489664*^9, 5.95}, {3.5568288*^9, 5.98}, {3.5646912*^9, + 6.01}, {3.5725536*^9, 6.03}, {3.580416*^9, 6.06}, { + 3.5882784*^9, 6.09}, {3.5961408*^9, 6.12}, {3.6040032*^9, + 6.14}, {3.6118656*^9, 6.17}, {3.619728*^9, 6.19}, { + 3.6275904*^9, 6.22}, {3.6354528*^9, 6.24}, {3.6433152*^9, + 6.26}, {3.6511776*^9, 6.28}, {3.65904*^9, 6.31}, { + 3.6669024*^9, 6.33}, {3.6747648*^9, 6.35}, {3.683232*^9, + 6.37}, {3.6910944*^9, 6.4}, {3.698352*^9, 6.42}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"12 Jun 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 9-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.3911136*^9, 5.36}, {3.3935328*^9, 5.36}, { + 3.395952*^9, 5.37}, {3.398976*^9, 5.37}, {3.4068384*^9, + 5.4}, {3.4147008*^9, 5.38}, {3.4225632*^9, 5.38}, { + 3.4304256*^9, 5.4}, {3.438288*^9, 5.44}, {3.4461504*^9, + 5.47}, {3.4540128*^9, 5.51}, {3.4618752*^9, 5.55}, { + 3.4697376*^9, 5.59}, {3.4776*^9, 5.61}, {3.4854624*^9, + 5.65}, {3.4933248*^9, 5.68}, {3.5011872*^9, 5.72}, { + 3.5090496*^9, 5.74}, {3.516912*^9, 5.76}, {3.5253792*^9, + 5.79}, {3.5332416*^9, 5.83}, {3.541104*^9, 5.84}, { + 3.5489664*^9, 5.87}, {3.5568288*^9, 5.89}, {3.5646912*^9, + 5.93}, {3.5725536*^9, 5.95}, {3.580416*^9, 5.98}, { + 3.5882784*^9, 6.}, {3.5961408*^9, 6.04}, {3.6040032*^9, + 6.06}, {3.6118656*^9, 6.07}, {3.619728*^9, 6.09}, { + 3.6275904*^9, 6.13}, {3.6354528*^9, 6.14}, {3.6433152*^9, + 6.15}, {3.6511776*^9, 6.17}, {3.65904*^9, 6.2}, { + 3.6669024*^9, 6.22}, {3.6747648*^9, 6.24}, {3.683232*^9, + 6.26}, {3.6910944*^9, 6.29}, {3.698352*^9, 6.3}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"13 Jun 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 10-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.3911136*^9, 5.36}, {3.3935328*^9, 5.36}, { + 3.395952*^9, 5.37}, {3.398976*^9, 5.37}, {3.4068384*^9, + 5.4}, {3.4147008*^9, 5.39}, {3.4225632*^9, 5.39}, { + 3.4304256*^9, 5.42}, {3.438288*^9, 5.45}, {3.4461504*^9, + 5.49}, {3.4540128*^9, 5.53}, {3.4618752*^9, 5.56}, { + 3.4697376*^9, 5.6}, {3.4776*^9, 5.62}, {3.4854624*^9, + 5.65}, {3.4933248*^9, 5.68}, {3.5011872*^9, 5.72}, { + 3.5090496*^9, 5.74}, {3.516912*^9, 5.76}, {3.5253792*^9, + 5.79}, {3.5332416*^9, 5.83}, {3.541104*^9, 5.84}, { + 3.5489664*^9, 5.87}, {3.5568288*^9, 5.89}, {3.5646912*^9, + 5.93}, {3.5725536*^9, 5.95}, {3.580416*^9, 5.97}, { + 3.5882784*^9, 6.}, {3.5961408*^9, 6.03}, {3.6040032*^9, + 6.05}, {3.6118656*^9, 6.06}, {3.619728*^9, 6.08}, { + 3.6275904*^9, 6.12}, {3.6354528*^9, 6.13}, {3.6433152*^9, + 6.14}, {3.6511776*^9, 6.16}, {3.65904*^9, 6.19}, { + 3.6669024*^9, 6.2}, {3.6747648*^9, 6.21}, {3.683232*^9, + 6.23}, {3.6910944*^9, 6.26}, {3.698352*^9, 6.28}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"14 Jun 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 11-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.3911136*^9, 5.36}, {3.3935328*^9, 5.36}, { + 3.395952*^9, 5.36}, {3.398976*^9, 5.36}, {3.4068384*^9, + 5.38}, {3.4147008*^9, 5.36}, {3.4225632*^9, 5.34}, { + 3.4304256*^9, 5.36}, {3.438288*^9, 5.38}, {3.4461504*^9, + 5.41}, {3.4540128*^9, 5.45}, {3.4618752*^9, 5.48}, { + 3.4697376*^9, 5.52}, {3.4776*^9, 5.54}, {3.4854624*^9, + 5.57}, {3.4933248*^9, 5.6}, {3.5011872*^9, 5.64}, { + 3.5090496*^9, 5.66}, {3.516912*^9, 5.68}, {3.5253792*^9, + 5.71}, {3.5332416*^9, 5.75}, {3.541104*^9, 5.76}, { + 3.5489664*^9, 5.79}, {3.5568288*^9, 5.81}, {3.5646912*^9, + 5.85}, {3.5725536*^9, 5.87}, {3.580416*^9, 5.89}, { + 3.5882784*^9, 5.92}, {3.5961408*^9, 5.95}, {3.6040032*^9, + 5.97}, {3.6118656*^9, 5.99}, {3.619728*^9, 6.01}, { + 3.6275904*^9, 6.04}, {3.6354528*^9, 6.05}, {3.6433152*^9, + 6.06}, {3.6511776*^9, 6.08}, {3.65904*^9, 6.11}, { + 3.6669024*^9, 6.13}, {3.6747648*^9, 6.14}, {3.683232*^9, + 6.16}, {3.6910944*^9, 6.2}, {3.698352*^9, 6.21}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"15 Jun 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 12-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.3935328*^9, 5.36}, {3.395952*^9, 5.36}, { + 3.398976*^9, 5.36}, {3.4068384*^9, 5.36}, {3.4147008*^9, + 5.33}, {3.4225632*^9, 5.3}, {3.4304256*^9, 5.31}, { + 3.438288*^9, 5.34}, {3.4461504*^9, 5.37}, {3.4540128*^9, + 5.4}, {3.4618752*^9, 5.44}, {3.4697376*^9, 5.48}, { + 3.4776*^9, 5.5}, {3.4854624*^9, 5.53}, {3.4933248*^9, + 5.56}, {3.5011872*^9, 5.61}, {3.5090496*^9, 5.63}, { + 3.516912*^9, 5.65}, {3.5253792*^9, 5.68}, {3.5332416*^9, + 5.72}, {3.541104*^9, 5.73}, {3.5489664*^9, 5.76}, { + 3.5568288*^9, 5.79}, {3.5646912*^9, 5.82}, {3.5725536*^9, + 5.84}, {3.580416*^9, 5.87}, {3.5882784*^9, 5.9}, { + 3.5961408*^9, 5.94}, {3.6040032*^9, 5.95}, {3.6118656*^9, + 5.98}, {3.619728*^9, 6.}, {3.6275904*^9, 6.03}, { + 3.6354528*^9, 6.04}, {3.6433152*^9, 6.05}, {3.6511776*^9, + 6.07}, {3.65904*^9, 6.1}, {3.6669024*^9, 6.12}, { + 3.6747648*^9, 6.13}, {3.683232*^9, 6.15}, {3.6910944*^9, + 6.19}, {3.698352*^9, 6.2}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"18 Jun 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 13-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.3935328*^9, 5.35}, {3.395952*^9, 5.35}, { + 3.398976*^9, 5.35}, {3.4068384*^9, 5.32}, {3.4147008*^9, + 5.27}, {3.4225632*^9, 5.24}, {3.4304256*^9, 5.24}, { + 3.438288*^9, 5.26}, {3.4461504*^9, 5.28}, {3.4540128*^9, + 5.31}, {3.4618752*^9, 5.35}, {3.4697376*^9, 5.4}, { + 3.4776*^9, 5.42}, {3.4854624*^9, 5.45}, {3.4933248*^9, + 5.48}, {3.5011872*^9, 5.53}, {3.5090496*^9, 5.55}, { + 3.516912*^9, 5.58}, {3.5253792*^9, 5.61}, {3.5332416*^9, + 5.64}, {3.541104*^9, 5.66}, {3.5489664*^9, 5.69}, { + 3.5568288*^9, 5.72}, {3.5646912*^9, 5.75}, {3.5725536*^9, + 5.77}, {3.580416*^9, 5.8}, {3.5882784*^9, 5.83}, { + 3.5961408*^9, 5.87}, {3.6040032*^9, 5.89}, {3.6118656*^9, + 5.91}, {3.619728*^9, 5.93}, {3.6275904*^9, 5.97}, { + 3.6354528*^9, 5.98}, {3.6433152*^9, 6.}, {3.6511776*^9, + 6.02}, {3.65904*^9, 6.05}, {3.6669024*^9, 6.06}, { + 3.6747648*^9, 6.08}, {3.683232*^9, 6.1}, {3.6910944*^9, + 6.13}, {3.698352*^9, 6.15}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"19 Jun 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 14-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.3935328*^9, 5.35}, {3.395952*^9, 5.35}, { + 3.398976*^9, 5.35}, {3.4068384*^9, 5.34}, {3.4147008*^9, + 5.31}, {3.4225632*^9, 5.28}, {3.4304256*^9, 5.28}, { + 3.438288*^9, 5.31}, {3.4461504*^9, 5.33}, {3.4540128*^9, + 5.37}, {3.4618752*^9, 5.42}, {3.4697376*^9, 5.46}, { + 3.4776*^9, 5.49}, {3.4854624*^9, 5.52}, {3.4933248*^9, + 5.56}, {3.5011872*^9, 5.6}, {3.5090496*^9, 5.62}, { + 3.516912*^9, 5.65}, {3.5253792*^9, 5.68}, {3.5332416*^9, + 5.72}, {3.541104*^9, 5.74}, {3.5489664*^9, 5.76}, { + 3.5568288*^9, 5.79}, {3.5646912*^9, 5.83}, {3.5725536*^9, + 5.85}, {3.580416*^9, 5.88}, {3.5882784*^9, 5.91}, { + 3.5961408*^9, 5.94}, {3.6040032*^9, 5.96}, {3.6118656*^9, + 5.99}, {3.619728*^9, 6.01}, {3.6275904*^9, 6.04}, { + 3.6354528*^9, 6.06}, {3.6433152*^9, 6.07}, {3.6511776*^9, + 6.09}, {3.65904*^9, 6.12}, {3.6669024*^9, 6.14}, { + 3.6747648*^9, 6.15}, {3.683232*^9, 6.17}, {3.6910944*^9, + 6.21}, {3.698352*^9, 6.22}, {3.7068192*^9, 6.24}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"20 Jun 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 15-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.3935328*^9, 5.35}, {3.395952*^9, 5.35}, { + 3.398976*^9, 5.34}, {3.4068384*^9, 5.33}, {3.4147008*^9, + 5.3}, {3.4225632*^9, 5.29}, {3.4304256*^9, 5.3}, { + 3.438288*^9, 5.33}, {3.4461504*^9, 5.37}, {3.4540128*^9, + 5.41}, {3.4618752*^9, 5.46}, {3.4697376*^9, 5.51}, { + 3.4776*^9, 5.55}, {3.4854624*^9, 5.59}, {3.4933248*^9, + 5.63}, {3.5011872*^9, 5.68}, {3.5090496*^9, 5.7}, { + 3.516912*^9, 5.74}, {3.5253792*^9, 5.77}, {3.5332416*^9, + 5.81}, {3.541104*^9, 5.83}, {3.5489664*^9, 5.85}, { + 3.5568288*^9, 5.88}, {3.5646912*^9, 5.92}, {3.5725536*^9, + 5.94}, {3.580416*^9, 5.97}, {3.5882784*^9, 6.}, { + 3.5961408*^9, 6.03}, {3.6040032*^9, 6.05}, {3.6118656*^9, + 6.08}, {3.619728*^9, 6.1}, {3.6275904*^9, 6.13}, { + 3.6354528*^9, 6.15}, {3.6433152*^9, 6.16}, {3.6511776*^9, + 6.18}, {3.65904*^9, 6.21}, {3.6669024*^9, 6.23}, { + 3.6747648*^9, 6.24}, {3.683232*^9, 6.26}, {3.6910944*^9, + 6.3}, {3.698352*^9, 6.31}, {3.7068192*^9, 6.33}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"21 Jun 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 16-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.3935328*^9, 5.35}, {3.395952*^9, 5.34}, { + 3.398976*^9, 5.33}, {3.4068384*^9, 5.29}, {3.4147008*^9, + 5.25}, {3.4225632*^9, 5.23}, {3.4304256*^9, 5.25}, { + 3.438288*^9, 5.29}, {3.4461504*^9, 5.33}, {3.4540128*^9, + 5.38}, {3.4618752*^9, 5.43}, {3.4697376*^9, 5.49}, { + 3.4776*^9, 5.52}, {3.4854624*^9, 5.57}, {3.4933248*^9, + 5.6}, {3.5011872*^9, 5.65}, {3.5090496*^9, 5.68}, { + 3.516912*^9, 5.71}, {3.5253792*^9, 5.74}, {3.5332416*^9, + 5.78}, {3.541104*^9, 5.8}, {3.5489664*^9, 5.83}, { + 3.5568288*^9, 5.86}, {3.5646912*^9, 5.89}, {3.5725536*^9, + 5.91}, {3.580416*^9, 5.94}, {3.5882784*^9, 5.98}, { + 3.5961408*^9, 6.01}, {3.6040032*^9, 6.03}, {3.6118656*^9, + 6.06}, {3.619728*^9, 6.08}, {3.6275904*^9, 6.11}, { + 3.6354528*^9, 6.13}, {3.6433152*^9, 6.14}, {3.6511776*^9, + 6.16}, {3.65904*^9, 6.19}, {3.6669024*^9, 6.21}, { + 3.6747648*^9, 6.23}, {3.683232*^9, 6.25}, {3.6910944*^9, + 6.28}, {3.698352*^9, 6.3}, {3.7068192*^9, 6.31}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"22 Jun 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 17-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.3935328*^9, 5.35}, {3.395952*^9, 5.33}, { + 3.398976*^9, 5.32}, {3.4068384*^9, 5.26}, {3.4147008*^9, + 5.2}, {3.4225632*^9, 5.17}, {3.4304256*^9, 5.18}, { + 3.438288*^9, 5.22}, {3.4461504*^9, 5.26}, {3.4540128*^9, + 5.31}, {3.4618752*^9, 5.36}, {3.4697376*^9, 5.41}, { + 3.4776*^9, 5.45}, {3.4854624*^9, 5.49}, {3.4933248*^9, + 5.53}, {3.5011872*^9, 5.58}, {3.5090496*^9, 5.6}, { + 3.516912*^9, 5.64}, {3.5253792*^9, 5.67}, {3.5332416*^9, + 5.71}, {3.541104*^9, 5.73}, {3.5489664*^9, 5.76}, { + 3.5568288*^9, 5.79}, {3.5646912*^9, 5.83}, {3.5725536*^9, + 5.85}, {3.580416*^9, 5.88}, {3.5882784*^9, 5.91}, { + 3.5961408*^9, 5.95}, {3.6040032*^9, 5.97}, {3.6118656*^9, + 6.}, {3.619728*^9, 6.02}, {3.6275904*^9, 6.05}, { + 3.6354528*^9, 6.07}, {3.6433152*^9, 6.08}, {3.6511776*^9, + 6.1}, {3.65904*^9, 6.13}, {3.6669024*^9, 6.15}, { + 3.6747648*^9, 6.17}, {3.683232*^9, 6.19}, {3.6910944*^9, + 6.23}, {3.698352*^9, 6.24}, {3.7068192*^9, 6.26}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"25 Jun 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 18-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.3935328*^9, 5.35}, {3.395952*^9, 5.34}, { + 3.398976*^9, 5.33}, {3.4068384*^9, 5.28}, {3.4147008*^9, + 5.21}, {3.4225632*^9, 5.19}, {3.4304256*^9, 5.21}, { + 3.438288*^9, 5.25}, {3.4461504*^9, 5.29}, {3.4540128*^9, + 5.34}, {3.4618752*^9, 5.39}, {3.4697376*^9, 5.44}, { + 3.4776*^9, 5.48}, {3.4854624*^9, 5.52}, {3.4933248*^9, + 5.55}, {3.5011872*^9, 5.6}, {3.5090496*^9, 5.63}, { + 3.516912*^9, 5.66}, {3.5253792*^9, 5.69}, {3.5332416*^9, + 5.73}, {3.541104*^9, 5.75}, {3.5489664*^9, 5.78}, { + 3.5568288*^9, 5.81}, {3.5646912*^9, 5.85}, {3.5725536*^9, + 5.87}, {3.580416*^9, 5.9}, {3.5882784*^9, 5.93}, { + 3.5961408*^9, 5.97}, {3.6040032*^9, 5.99}, {3.6118656*^9, + 6.01}, {3.619728*^9, 6.03}, {3.6275904*^9, 6.07}, { + 3.6354528*^9, 6.08}, {3.6433152*^9, 6.1}, {3.6511776*^9, + 6.12}, {3.65904*^9, 6.15}, {3.6669024*^9, 6.17}, { + 3.6747648*^9, 6.19}, {3.683232*^9, 6.21}, {3.6910944*^9, + 6.24}, {3.698352*^9, 6.26}, {3.7068192*^9, 6.27}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"26 Jun 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 19-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.3935328*^9, 5.35}, {3.395952*^9, 5.34}, { + 3.398976*^9, 5.32}, {3.4068384*^9, 5.27}, {3.4147008*^9, + 5.2}, {3.4225632*^9, 5.17}, {3.4304256*^9, 5.19}, { + 3.438288*^9, 5.22}, {3.4461504*^9, 5.26}, {3.4540128*^9, + 5.31}, {3.4618752*^9, 5.36}, {3.4697376*^9, 5.41}, { + 3.4776*^9, 5.45}, {3.4854624*^9, 5.49}, {3.4933248*^9, + 5.52}, {3.5011872*^9, 5.57}, {3.5090496*^9, 5.6}, { + 3.516912*^9, 5.63}, {3.5253792*^9, 5.66}, {3.5332416*^9, + 5.7}, {3.541104*^9, 5.72}, {3.5489664*^9, 5.75}, { + 3.5568288*^9, 5.78}, {3.5646912*^9, 5.82}, {3.5725536*^9, + 5.84}, {3.580416*^9, 5.87}, {3.5882784*^9, 5.9}, { + 3.5961408*^9, 5.94}, {3.6040032*^9, 5.96}, {3.6118656*^9, + 5.98}, {3.619728*^9, 6.}, {3.6275904*^9, 6.04}, { + 3.6354528*^9, 6.05}, {3.6433152*^9, 6.07}, {3.6511776*^9, + 6.09}, {3.65904*^9, 6.12}, {3.6669024*^9, 6.14}, { + 3.6747648*^9, 6.16}, {3.683232*^9, 6.18}, {3.6910944*^9, + 6.21}, {3.698352*^9, 6.23}, {3.7068192*^9, 6.24}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"27 Jun 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 20-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.3935328*^9, 5.35}, {3.395952*^9, 5.35}, { + 3.398976*^9, 5.34}, {3.4068384*^9, 5.32}, {3.4147008*^9, + 5.28}, {3.4225632*^9, 5.26}, {3.4304256*^9, 5.28}, { + 3.438288*^9, 5.31}, {3.4461504*^9, 5.34}, {3.4540128*^9, + 5.38}, {3.4618752*^9, 5.43}, {3.4697376*^9, 5.47}, { + 3.4776*^9, 5.5}, {3.4854624*^9, 5.54}, {3.4933248*^9, + 5.57}, {3.5011872*^9, 5.62}, {3.5090496*^9, 5.64}, { + 3.516912*^9, 5.67}, {3.5253792*^9, 5.7}, {3.5332416*^9, + 5.74}, {3.541104*^9, 5.76}, {3.5489664*^9, 5.79}, { + 3.5568288*^9, 5.82}, {3.5646912*^9, 5.85}, {3.5725536*^9, + 5.87}, {3.580416*^9, 5.9}, {3.5882784*^9, 5.93}, { + 3.5961408*^9, 5.97}, {3.6040032*^9, 5.99}, {3.6118656*^9, + 6.01}, {3.619728*^9, 6.03}, {3.6275904*^9, 6.07}, { + 3.6354528*^9, 6.08}, {3.6433152*^9, 6.1}, {3.6511776*^9, + 6.12}, {3.65904*^9, 6.15}, {3.6669024*^9, 6.17}, { + 3.6747648*^9, 6.19}, {3.683232*^9, 6.21}, {3.6910944*^9, + 6.24}, {3.698352*^9, 6.26}, {3.7068192*^9, 6.27}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"28 Jun 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 21-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.3935328*^9, 5.35}, {3.395952*^9, 5.34}, { + 3.398976*^9, 5.33}, {3.4068384*^9, 5.28}, {3.4147008*^9, + 5.21}, {3.4225632*^9, 5.17}, {3.4304256*^9, 5.18}, { + 3.438288*^9, 5.22}, {3.4461504*^9, 5.26}, {3.4540128*^9, + 5.31}, {3.4618752*^9, 5.35}, {3.4697376*^9, 5.4}, { + 3.4776*^9, 5.43}, {3.4854624*^9, 5.47}, {3.4933248*^9, + 5.5}, {3.5011872*^9, 5.55}, {3.5090496*^9, 5.57}, { + 3.516912*^9, 5.6}, {3.5253792*^9, 5.63}, {3.5332416*^9, + 5.67}, {3.541104*^9, 5.69}, {3.5489664*^9, 5.72}, { + 3.5568288*^9, 5.75}, {3.5646912*^9, 5.79}, {3.5725536*^9, + 5.81}, {3.580416*^9, 5.84}, {3.5882784*^9, 5.87}, { + 3.5961408*^9, 5.91}, {3.6040032*^9, 5.93}, {3.6118656*^9, + 5.95}, {3.619728*^9, 5.98}, {3.6275904*^9, 6.01}, { + 3.6354528*^9, 6.03}, {3.6433152*^9, 6.04}, {3.6511776*^9, + 6.06}, {3.65904*^9, 6.09}, {3.6669024*^9, 6.11}, { + 3.6747648*^9, 6.13}, {3.683232*^9, 6.15}, {3.6910944*^9, + 6.19}, {3.698352*^9, 6.2}, {3.7068192*^9, 6.22}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"29 Jun 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 22-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.3935328*^9, 5.35}, {3.395952*^9, 5.34}, { + 3.398976*^9, 5.33}, {3.4068384*^9, 5.28}, {3.4147008*^9, + 5.19}, {3.4225632*^9, 5.14}, {3.4304256*^9, 5.13}, { + 3.438288*^9, 5.16}, {3.4461504*^9, 5.2}, {3.4540128*^9, + 5.25}, {3.4618752*^9, 5.3}, {3.4697376*^9, 5.35}, { + 3.4776*^9, 5.38}, {3.4854624*^9, 5.41}, {3.4933248*^9, + 5.45}, {3.5011872*^9, 5.5}, {3.5090496*^9, 5.52}, { + 3.516912*^9, 5.55}, {3.5253792*^9, 5.58}, {3.5332416*^9, + 5.62}, {3.541104*^9, 5.64}, {3.5489664*^9, 5.67}, { + 3.5568288*^9, 5.7}, {3.5646912*^9, 5.74}, {3.5725536*^9, + 5.76}, {3.580416*^9, 5.79}, {3.5882784*^9, 5.82}, { + 3.5961408*^9, 5.86}, {3.6040032*^9, 5.88}, {3.6118656*^9, + 5.9}, {3.619728*^9, 5.93}, {3.6275904*^9, 5.96}, { + 3.6354528*^9, 5.98}, {3.6433152*^9, 5.99}, {3.6511776*^9, + 6.01}, {3.65904*^9, 6.04}, {3.6669024*^9, 6.06}, { + 3.6747648*^9, 6.08}, {3.683232*^9, 6.1}, {3.6910944*^9, + 6.14}, {3.698352*^9, 6.15}, {3.7068192*^9, 6.17}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"02 Jul 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 23-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.3935328*^9, 5.35}, {3.395952*^9, 5.34}, { + 3.398976*^9, 5.33}, {3.4068384*^9, 5.3}, {3.4147008*^9, + 5.23}, {3.4225632*^9, 5.18}, {3.4304256*^9, 5.18}, { + 3.438288*^9, 5.21}, {3.4461504*^9, 5.25}, {3.4540128*^9, + 5.3}, {3.4618752*^9, 5.35}, {3.4697376*^9, 5.4}, { + 3.4776*^9, 5.43}, {3.4854624*^9, 5.46}, {3.4933248*^9, + 5.5}, {3.5011872*^9, 5.55}, {3.5090496*^9, 5.57}, { + 3.516912*^9, 5.6}, {3.5253792*^9, 5.63}, {3.5332416*^9, + 5.67}, {3.541104*^9, 5.69}, {3.5489664*^9, 5.72}, { + 3.5568288*^9, 5.75}, {3.5646912*^9, 5.79}, {3.5725536*^9, + 5.81}, {3.580416*^9, 5.84}, {3.5882784*^9, 5.87}, { + 3.5961408*^9, 5.91}, {3.6040032*^9, 5.93}, {3.6118656*^9, + 5.95}, {3.619728*^9, 5.98}, {3.6275904*^9, 6.01}, { + 3.6354528*^9, 6.03}, {3.6433152*^9, 6.04}, {3.6511776*^9, + 6.06}, {3.65904*^9, 6.09}, {3.6669024*^9, 6.11}, { + 3.6747648*^9, 6.13}, {3.683232*^9, 6.15}, {3.6910944*^9, + 6.19}, {3.698352*^9, 6.2}, {3.7068192*^9, 6.22}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"03 Jul 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 24-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.3935328*^9, 5.36}, {3.395952*^9, 5.35}, { + 3.398976*^9, 5.34}, {3.4013952*^9, 5.35}, {3.4068384*^9, + 5.35}, {3.4147008*^9, 5.32}, {3.4225632*^9, 5.29}, { + 3.4304256*^9, 5.3}, {3.438288*^9, 5.32}, {3.4461504*^9, + 5.36}, {3.4540128*^9, 5.41}, {3.4618752*^9, 5.46}, { + 3.4697376*^9, 5.51}, {3.4776*^9, 5.54}, {3.4854624*^9, + 5.58}, {3.4933248*^9, 5.62}, {3.5011872*^9, 5.66}, { + 3.5090496*^9, 5.69}, {3.516912*^9, 5.72}, {3.5253792*^9, + 5.75}, {3.5332416*^9, 5.79}, {3.541104*^9, 5.81}, { + 3.5489664*^9, 5.84}, {3.5568288*^9, 5.87}, {3.5646912*^9, + 5.9}, {3.5725536*^9, 5.92}, {3.580416*^9, 5.95}, { + 3.5882784*^9, 5.98}, {3.5961408*^9, 6.02}, {3.6040032*^9, + 6.04}, {3.6118656*^9, 6.07}, {3.619728*^9, 6.09}, { + 3.6275904*^9, 6.13}, {3.6354528*^9, 6.14}, {3.6433152*^9, + 6.16}, {3.6511776*^9, 6.18}, {3.65904*^9, 6.21}, { + 3.6669024*^9, 6.23}, {3.6747648*^9, 6.25}, {3.683232*^9, + 6.27}, {3.6910944*^9, 6.3}, {3.698352*^9, 6.32}, { + 3.7068192*^9, 6.33}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"05 Jul 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 25-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.3935328*^9, 5.36}, {3.395952*^9, 5.35}, { + 3.398976*^9, 5.35}, {3.4013952*^9, 5.36}, {3.4068384*^9, + 5.36}, {3.4147008*^9, 5.34}, {3.4225632*^9, 5.32}, { + 3.4304256*^9, 5.33}, {3.438288*^9, 5.36}, {3.4461504*^9, + 5.41}, {3.4540128*^9, 5.47}, {3.4618752*^9, 5.52}, { + 3.4697376*^9, 5.57}, {3.4776*^9, 5.61}, {3.4854624*^9, + 5.65}, {3.4933248*^9, 5.69}, {3.5011872*^9, 5.74}, { + 3.5090496*^9, 5.76}, {3.516912*^9, 5.79}, {3.5253792*^9, + 5.82}, {3.5332416*^9, 5.86}, {3.541104*^9, 5.88}, { + 3.5489664*^9, 5.91}, {3.5568288*^9, 5.94}, {3.5646912*^9, + 5.98}, {3.5725536*^9, 6.}, {3.580416*^9, 6.03}, { + 3.5882784*^9, 6.06}, {3.5961408*^9, 6.1}, {3.6040032*^9, + 6.12}, {3.6118656*^9, 6.14}, {3.619728*^9, 6.17}, { + 3.6275904*^9, 6.2}, {3.6354528*^9, 6.22}, {3.6433152*^9, + 6.23}, {3.6511776*^9, 6.25}, {3.65904*^9, 6.28}, { + 3.6669024*^9, 6.3}, {3.6747648*^9, 6.32}, {3.683232*^9, + 6.34}, {3.6910944*^9, 6.38}, {3.698352*^9, 6.39}, { + 3.7068192*^9, 6.41}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"06 Jul 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 26-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.3935328*^9, 5.36}, {3.395952*^9, 5.35}, { + 3.398976*^9, 5.35}, {3.4013952*^9, 5.36}, {3.4068384*^9, + 5.36}, {3.4147008*^9, 5.33}, {3.4225632*^9, 5.3}, { + 3.4304256*^9, 5.3}, {3.438288*^9, 5.33}, {3.4461504*^9, + 5.38}, {3.4540128*^9, 5.44}, {3.4618752*^9, 5.49}, { + 3.4697376*^9, 5.54}, {3.4776*^9, 5.58}, {3.4854624*^9, + 5.62}, {3.4933248*^9, 5.65}, {3.5011872*^9, 5.7}, { + 3.5090496*^9, 5.73}, {3.516912*^9, 5.76}, {3.5253792*^9, + 5.79}, {3.5332416*^9, 5.83}, {3.541104*^9, 5.85}, { + 3.5489664*^9, 5.88}, {3.5568288*^9, 5.9}, {3.5646912*^9, + 5.94}, {3.5725536*^9, 5.96}, {3.580416*^9, 5.99}, { + 3.5882784*^9, 6.02}, {3.5961408*^9, 6.06}, {3.6040032*^9, + 6.08}, {3.6118656*^9, 6.1}, {3.619728*^9, 6.13}, { + 3.6275904*^9, 6.16}, {3.6354528*^9, 6.18}, {3.6433152*^9, + 6.19}, {3.6511776*^9, 6.21}, {3.65904*^9, 6.24}, { + 3.6669024*^9, 6.26}, {3.6747648*^9, 6.28}, {3.683232*^9, + 6.3}, {3.6910944*^9, 6.34}, {3.698352*^9, 6.35}, { + 3.7068192*^9, 6.37}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"09 Jul 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 27-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.3935328*^9, 5.35}, {3.395952*^9, 5.34}, { + 3.398976*^9, 5.34}, {3.4013952*^9, 5.34}, {3.4068384*^9, + 5.3}, {3.4147008*^9, 5.23}, {3.4225632*^9, 5.18}, { + 3.4304256*^9, 5.17}, {3.438288*^9, 5.19}, {3.4461504*^9, + 5.24}, {3.4540128*^9, 5.31}, {3.4618752*^9, 5.36}, { + 3.4697376*^9, 5.42}, {3.4776*^9, 5.45}, {3.4854624*^9, + 5.5}, {3.4933248*^9, 5.54}, {3.5011872*^9, 5.59}, { + 3.5090496*^9, 5.61}, {3.516912*^9, 5.64}, {3.5253792*^9, + 5.67}, {3.5332416*^9, 5.71}, {3.541104*^9, 5.73}, { + 3.5489664*^9, 5.76}, {3.5568288*^9, 5.79}, {3.5646912*^9, + 5.83}, {3.5725536*^9, 5.85}, {3.580416*^9, 5.88}, { + 3.5882784*^9, 5.91}, {3.5961408*^9, 5.95}, {3.6040032*^9, + 5.97}, {3.6118656*^9, 5.99}, {3.619728*^9, 6.02}, { + 3.6275904*^9, 6.06}, {3.6354528*^9, 6.07}, {3.6433152*^9, + 6.09}, {3.6511776*^9, 6.11}, {3.65904*^9, 6.14}, { + 3.6669024*^9, 6.16}, {3.6747648*^9, 6.18}, {3.683232*^9, + 6.2}, {3.6910944*^9, 6.24}, {3.698352*^9, 6.25}, { + 3.7068192*^9, 6.27}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"10 Jul 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 28-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.3935328*^9, 5.35}, {3.395952*^9, 5.34}, { + 3.398976*^9, 5.34}, {3.4013952*^9, 5.36}, {3.4068384*^9, + 5.32}, {3.4147008*^9, 5.26}, {3.4225632*^9, 5.2}, { + 3.4304256*^9, 5.19}, {3.438288*^9, 5.21}, {3.4461504*^9, + 5.27}, {3.4540128*^9, 5.34}, {3.4618752*^9, 5.4}, { + 3.4697376*^9, 5.46}, {3.4776*^9, 5.5}, {3.4854624*^9, + 5.54}, {3.4933248*^9, 5.58}, {3.5011872*^9, 5.63}, { + 3.5090496*^9, 5.66}, {3.516912*^9, 5.69}, {3.5253792*^9, + 5.72}, {3.5332416*^9, 5.76}, {3.541104*^9, 5.78}, { + 3.5489664*^9, 5.81}, {3.5568288*^9, 5.84}, {3.5646912*^9, + 5.88}, {3.5725536*^9, 5.9}, {3.580416*^9, 5.93}, { + 3.5882784*^9, 5.96}, {3.5961408*^9, 6.}, {3.6040032*^9, + 6.02}, {3.6118656*^9, 6.04}, {3.619728*^9, 6.07}, { + 3.6275904*^9, 6.11}, {3.6354528*^9, 6.13}, {3.6433152*^9, + 6.14}, {3.6511776*^9, 6.17}, {3.65904*^9, 6.2}, { + 3.6669024*^9, 6.22}, {3.6747648*^9, 6.24}, {3.683232*^9, + 6.26}, {3.6910944*^9, 6.29}, {3.698352*^9, 6.31}, { + 3.7068192*^9, 6.32}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"11 Jul 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 29-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.3935328*^9, 5.35}, {3.395952*^9, 5.35}, { + 3.398976*^9, 5.34}, {3.4013952*^9, 5.34}, {3.4068384*^9, + 5.33}, {3.4147008*^9, 5.29}, {3.4225632*^9, 5.25}, { + 3.4304256*^9, 5.25}, {3.438288*^9, 5.27}, {3.4461504*^9, + 5.31}, {3.4540128*^9, 5.38}, {3.4618752*^9, 5.44}, { + 3.4697376*^9, 5.5}, {3.4776*^9, 5.54}, {3.4854624*^9, + 5.58}, {3.4933248*^9, 5.62}, {3.5011872*^9, 5.66}, { + 3.5090496*^9, 5.69}, {3.516912*^9, 5.72}, {3.5253792*^9, + 5.75}, {3.5332416*^9, 5.79}, {3.541104*^9, 5.81}, { + 3.5489664*^9, 5.84}, {3.5568288*^9, 5.87}, {3.5646912*^9, + 5.91}, {3.5725536*^9, 5.93}, {3.580416*^9, 5.96}, { + 3.5882784*^9, 5.99}, {3.5961408*^9, 6.03}, {3.6040032*^9, + 6.05}, {3.6118656*^9, 6.07}, {3.619728*^9, 6.1}, { + 3.6275904*^9, 6.14}, {3.6354528*^9, 6.16}, {3.6433152*^9, + 6.17}, {3.6511776*^9, 6.2}, {3.65904*^9, 6.23}, { + 3.6669024*^9, 6.25}, {3.6747648*^9, 6.27}, {3.683232*^9, + 6.29}, {3.6910944*^9, 6.32}, {3.698352*^9, 6.34}, { + 3.7068192*^9, 6.35}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"12 Jul 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 30-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.3935328*^9, 5.35}, {3.395952*^9, 5.35}, { + 3.398976*^9, 5.34}, {3.4013952*^9, 5.34}, {3.4068384*^9, + 5.33}, {3.4147008*^9, 5.29}, {3.4225632*^9, 5.25}, { + 3.4304256*^9, 5.25}, {3.438288*^9, 5.27}, {3.4461504*^9, + 5.31}, {3.4540128*^9, 5.37}, {3.4618752*^9, 5.43}, { + 3.4697376*^9, 5.49}, {3.4776*^9, 5.52}, {3.4854624*^9, + 5.56}, {3.4933248*^9, 5.6}, {3.5011872*^9, 5.64}, { + 3.5090496*^9, 5.67}, {3.516912*^9, 5.7}, {3.5253792*^9, + 5.73}, {3.5332416*^9, 5.77}, {3.541104*^9, 5.79}, { + 3.5489664*^9, 5.82}, {3.5568288*^9, 5.85}, {3.5646912*^9, + 5.89}, {3.5725536*^9, 5.91}, {3.580416*^9, 5.94}, { + 3.5882784*^9, 5.97}, {3.5961408*^9, 6.01}, {3.6040032*^9, + 6.03}, {3.6118656*^9, 6.05}, {3.619728*^9, 6.08}, { + 3.6275904*^9, 6.12}, {3.6354528*^9, 6.13}, {3.6433152*^9, + 6.15}, {3.6511776*^9, 6.17}, {3.65904*^9, 6.2}, { + 3.6669024*^9, 6.21}, {3.6747648*^9, 6.23}, {3.683232*^9, + 6.25}, {3.6910944*^9, 6.28}, {3.698352*^9, 6.3}, { + 3.7068192*^9, 6.31}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"13 Jul 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 31-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.395952*^9, 5.35}, {3.398976*^9, 5.34}, { + 3.4013952*^9, 5.33}, {3.4068384*^9, 5.31}, {3.4147008*^9, + 5.23}, {3.4225632*^9, 5.18}, {3.4304256*^9, 5.17}, { + 3.438288*^9, 5.19}, {3.4461504*^9, 5.23}, {3.4540128*^9, + 5.28}, {3.4618752*^9, 5.34}, {3.4697376*^9, 5.41}, { + 3.4776*^9, 5.46}, {3.4854624*^9, 5.5}, {3.4933248*^9, + 5.54}, {3.5011872*^9, 5.59}, {3.5090496*^9, 5.61}, { + 3.516912*^9, 5.65}, {3.5253792*^9, 5.68}, {3.5332416*^9, + 5.72}, {3.541104*^9, 5.74}, {3.5489664*^9, 5.77}, { + 3.5568288*^9, 5.79}, {3.5646912*^9, 5.83}, {3.5725536*^9, + 5.85}, {3.580416*^9, 5.88}, {3.5882784*^9, 5.91}, { + 3.5961408*^9, 5.95}, {3.6040032*^9, 5.97}, {3.6118656*^9, + 6.}, {3.619728*^9, 6.03}, {3.6275904*^9, 6.06}, { + 3.6354528*^9, 6.08}, {3.6433152*^9, 6.09}, {3.6511776*^9, + 6.11}, {3.65904*^9, 6.14}, {3.6669024*^9, 6.16}, { + 3.6747648*^9, 6.18}, {3.683232*^9, 6.19}, {3.6910944*^9, + 6.23}, {3.698352*^9, 6.24}, {3.7068192*^9, 6.26}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"16 Jul 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 32-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.395952*^9, 5.35}, {3.398976*^9, 5.34}, { + 3.4013952*^9, 5.34}, {3.4068384*^9, 5.33}, {3.4147008*^9, + 5.28}, {3.4225632*^9, 5.24}, {3.4304256*^9, 5.23}, { + 3.438288*^9, 5.25}, {3.4461504*^9, 5.29}, {3.4540128*^9, + 5.35}, {3.4618752*^9, 5.41}, {3.4697376*^9, 5.47}, { + 3.4776*^9, 5.51}, {3.4854624*^9, 5.56}, {3.4933248*^9, + 5.59}, {3.5011872*^9, 5.64}, {3.5090496*^9, 5.66}, { + 3.516912*^9, 5.7}, {3.5253792*^9, 5.73}, {3.5332416*^9, + 5.77}, {3.541104*^9, 5.79}, {3.5489664*^9, 5.81}, { + 3.5568288*^9, 5.83}, {3.5646912*^9, 5.87}, {3.5725536*^9, + 5.89}, {3.580416*^9, 5.91}, {3.5882784*^9, 5.94}, { + 3.5961408*^9, 5.98}, {3.6040032*^9, 5.99}, {3.6118656*^9, + 6.02}, {3.619728*^9, 6.05}, {3.6275904*^9, 6.08}, { + 3.6354528*^9, 6.1}, {3.6433152*^9, 6.12}, {3.6511776*^9, + 6.14}, {3.65904*^9, 6.17}, {3.6669024*^9, 6.18}, { + 3.6747648*^9, 6.2}, {3.683232*^9, 6.22}, {3.6910944*^9, + 6.25}, {3.698352*^9, 6.27}, {3.7068192*^9, 6.28}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"17 Jul 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 33-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.395952*^9, 5.35}, {3.398976*^9, 5.34}, { + 3.4013952*^9, 5.33}, {3.4068384*^9, 5.3}, {3.4147008*^9, + 5.22}, {3.4225632*^9, 5.16}, {3.4304256*^9, 5.14}, { + 3.438288*^9, 5.16}, {3.4461504*^9, 5.2}, {3.4540128*^9, + 5.26}, {3.4618752*^9, 5.32}, {3.4697376*^9, 5.39}, { + 3.4776*^9, 5.44}, {3.4854624*^9, 5.48}, {3.4933248*^9, + 5.52}, {3.5011872*^9, 5.57}, {3.5090496*^9, 5.6}, { + 3.516912*^9, 5.63}, {3.5253792*^9, 5.66}, {3.5332416*^9, + 5.7}, {3.541104*^9, 5.72}, {3.5489664*^9, 5.75}, { + 3.5568288*^9, 5.77}, {3.5646912*^9, 5.8}, {3.5725536*^9, + 5.82}, {3.580416*^9, 5.85}, {3.5882784*^9, 5.87}, { + 3.5961408*^9, 5.91}, {3.6040032*^9, 5.93}, {3.6118656*^9, + 5.95}, {3.619728*^9, 5.98}, {3.6275904*^9, 6.02}, { + 3.6354528*^9, 6.03}, {3.6433152*^9, 6.05}, {3.6511776*^9, + 6.07}, {3.65904*^9, 6.1}, {3.6669024*^9, 6.12}, { + 3.6747648*^9, 6.14}, {3.683232*^9, 6.15}, {3.6910944*^9, + 6.19}, {3.698352*^9, 6.21}, {3.7068192*^9, 6.22}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"18 Jul 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 34-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.395952*^9, 5.35}, {3.398976*^9, 5.34}, { + 3.4013952*^9, 5.34}, {3.4068384*^9, 5.3}, {3.4147008*^9, + 5.23}, {3.4225632*^9, 5.17}, {3.4304256*^9, 5.15}, { + 3.438288*^9, 5.17}, {3.4461504*^9, 5.21}, {3.4540128*^9, + 5.27}, {3.4618752*^9, 5.33}, {3.4697376*^9, 5.4}, { + 3.4776*^9, 5.45}, {3.4854624*^9, 5.49}, {3.4933248*^9, + 5.53}, {3.5011872*^9, 5.58}, {3.5090496*^9, 5.61}, { + 3.516912*^9, 5.64}, {3.5253792*^9, 5.67}, {3.5332416*^9, + 5.71}, {3.541104*^9, 5.73}, {3.5489664*^9, 5.75}, { + 3.5568288*^9, 5.77}, {3.5646912*^9, 5.81}, {3.5725536*^9, + 5.82}, {3.580416*^9, 5.85}, {3.5882784*^9, 5.87}, { + 3.5961408*^9, 5.91}, {3.6040032*^9, 5.92}, {3.6118656*^9, + 5.94}, {3.619728*^9, 5.97}, {3.6275904*^9, 6.01}, { + 3.6354528*^9, 6.02}, {3.6433152*^9, 6.04}, {3.6511776*^9, + 6.07}, {3.65904*^9, 6.1}, {3.6669024*^9, 6.11}, { + 3.6747648*^9, 6.13}, {3.683232*^9, 6.15}, {3.6910944*^9, + 6.18}, {3.698352*^9, 6.2}, {3.7068192*^9, 6.22}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"19 Jul 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 35-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.395952*^9, 5.34}, {3.398976*^9, 5.33}, { + 3.4013952*^9, 5.32}, {3.4068384*^9, 5.26}, {3.4147008*^9, + 5.17}, {3.4225632*^9, 5.1}, {3.4304256*^9, 5.08}, { + 3.438288*^9, 5.1}, {3.4461504*^9, 5.14}, {3.4540128*^9, + 5.21}, {3.4618752*^9, 5.27}, {3.4697376*^9, 5.34}, { + 3.4776*^9, 5.39}, {3.4854624*^9, 5.44}, {3.4933248*^9, + 5.48}, {3.5011872*^9, 5.53}, {3.5090496*^9, 5.55}, { + 3.516912*^9, 5.59}, {3.5253792*^9, 5.62}, {3.5332416*^9, + 5.66}, {3.541104*^9, 5.68}, {3.5489664*^9, 5.7}, { + 3.5568288*^9, 5.72}, {3.5646912*^9, 5.76}, {3.5725536*^9, + 5.77}, {3.580416*^9, 5.8}, {3.5882784*^9, 5.82}, { + 3.5961408*^9, 5.86}, {3.6040032*^9, 5.87}, {3.6118656*^9, + 5.89}, {3.619728*^9, 5.92}, {3.6275904*^9, 5.96}, { + 3.6354528*^9, 5.97}, {3.6433152*^9, 5.99}, {3.6511776*^9, + 6.02}, {3.65904*^9, 6.05}, {3.6669024*^9, 6.06}, { + 3.6747648*^9, 6.08}, {3.683232*^9, 6.1}, {3.6910944*^9, + 6.13}, {3.698352*^9, 6.15}, {3.7068192*^9, 6.17}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"20 Jul 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 36-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.395952*^9, 5.35}, {3.398976*^9, 5.33}, { + 3.4013952*^9, 5.33}, {3.4068384*^9, 5.29}, {3.4147008*^9, + 5.2}, {3.4225632*^9, 5.13}, {3.4304256*^9, 5.11}, { + 3.438288*^9, 5.13}, {3.4461504*^9, 5.17}, {3.4540128*^9, + 5.23}, {3.4618752*^9, 5.29}, {3.4697376*^9, 5.35}, { + 3.4776*^9, 5.4}, {3.4854624*^9, 5.44}, {3.4933248*^9, + 5.48}, {3.5011872*^9, 5.53}, {3.5090496*^9, 5.55}, { + 3.516912*^9, 5.58}, {3.5253792*^9, 5.61}, {3.5332416*^9, + 5.65}, {3.541104*^9, 5.67}, {3.5489664*^9, 5.7}, { + 3.5568288*^9, 5.72}, {3.5646912*^9, 5.75}, {3.5725536*^9, + 5.77}, {3.580416*^9, 5.79}, {3.5882784*^9, 5.81}, { + 3.5961408*^9, 5.85}, {3.6040032*^9, 5.86}, {3.6118656*^9, + 5.88}, {3.619728*^9, 5.91}, {3.6275904*^9, 5.95}, { + 3.6354528*^9, 5.96}, {3.6433152*^9, 5.98}, {3.6511776*^9, + 6.01}, {3.65904*^9, 6.04}, {3.6669024*^9, 6.05}, { + 3.6747648*^9, 6.07}, {3.683232*^9, 6.09}, {3.6910944*^9, + 6.12}, {3.698352*^9, 6.14}, {3.7068192*^9, 6.16}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"23 Jul 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 37-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.395952*^9, 5.35}, {3.398976*^9, 5.33}, { + 3.4013952*^9, 5.32}, {3.4068384*^9, 5.28}, {3.4147008*^9, + 5.17}, {3.4225632*^9, 5.09}, {3.4304256*^9, 5.07}, { + 3.438288*^9, 5.09}, {3.4461504*^9, 5.14}, {3.4540128*^9, + 5.2}, {3.4618752*^9, 5.27}, {3.4697376*^9, 5.33}, { + 3.4776*^9, 5.38}, {3.4854624*^9, 5.43}, {3.4933248*^9, + 5.47}, {3.5011872*^9, 5.52}, {3.5090496*^9, 5.54}, { + 3.516912*^9, 5.58}, {3.5253792*^9, 5.61}, {3.5332416*^9, + 5.65}, {3.541104*^9, 5.67}, {3.5489664*^9, 5.69}, { + 3.5568288*^9, 5.72}, {3.5646912*^9, 5.75}, {3.5725536*^9, + 5.77}, {3.580416*^9, 5.79}, {3.5882784*^9, 5.82}, { + 3.5961408*^9, 5.85}, {3.6040032*^9, 5.87}, {3.6118656*^9, + 5.89}, {3.619728*^9, 5.92}, {3.6275904*^9, 5.95}, { + 3.6354528*^9, 5.97}, {3.6433152*^9, 5.99}, {3.6511776*^9, + 6.02}, {3.65904*^9, 6.05}, {3.6669024*^9, 6.06}, { + 3.6747648*^9, 6.08}, {3.683232*^9, 6.1}, {3.6910944*^9, + 6.13}, {3.698352*^9, 6.15}, {3.7068192*^9, 6.17}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"24 Jul 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 38-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.395952*^9, 5.35}, {3.398976*^9, 5.33}, { + 3.4013952*^9, 5.31}, {3.4068384*^9, 5.25}, {3.4147008*^9, + 5.14}, {3.4225632*^9, 5.05}, {3.4304256*^9, 5.03}, { + 3.438288*^9, 5.04}, {3.4461504*^9, 5.09}, {3.4540128*^9, + 5.15}, {3.4618752*^9, 5.22}, {3.4697376*^9, 5.29}, { + 3.4776*^9, 5.34}, {3.4854624*^9, 5.39}, {3.4933248*^9, + 5.43}, {3.5011872*^9, 5.48}, {3.5090496*^9, 5.51}, { + 3.516912*^9, 5.55}, {3.5253792*^9, 5.58}, {3.5332416*^9, + 5.62}, {3.541104*^9, 5.64}, {3.5489664*^9, 5.67}, { + 3.5568288*^9, 5.7}, {3.5646912*^9, 5.73}, {3.5725536*^9, + 5.75}, {3.580416*^9, 5.78}, {3.5882784*^9, 5.8}, { + 3.5961408*^9, 5.84}, {3.6040032*^9, 5.85}, {3.6118656*^9, + 5.88}, {3.619728*^9, 5.91}, {3.6275904*^9, 5.94}, { + 3.6354528*^9, 5.96}, {3.6433152*^9, 5.98}, {3.6511776*^9, + 6.01}, {3.65904*^9, 6.04}, {3.6669024*^9, 6.05}, { + 3.6747648*^9, 6.07}, {3.683232*^9, 6.09}, {3.6910944*^9, + 6.13}, {3.698352*^9, 6.15}, {3.7068192*^9, 6.16}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"25 Jul 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 39-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.395952*^9, 5.29}, {3.398976*^9, 5.25}, { + 3.4013952*^9, 5.22}, {3.4068384*^9, 5.12}, {3.4147008*^9, + 4.98}, {3.4225632*^9, 4.88}, {3.4304256*^9, 4.85}, { + 3.438288*^9, 4.87}, {3.4461504*^9, 4.91}, {3.4540128*^9, + 4.98}, {3.4618752*^9, 5.06}, {3.4697376*^9, 5.14}, { + 3.4776*^9, 5.2}, {3.4854624*^9, 5.26}, {3.4933248*^9, + 5.31}, {3.5011872*^9, 5.37}, {3.5090496*^9, 5.41}, { + 3.516912*^9, 5.45}, {3.5253792*^9, 5.49}, {3.5332416*^9, + 5.54}, {3.541104*^9, 5.57}, {3.5489664*^9, 5.6}, { + 3.5568288*^9, 5.63}, {3.5646912*^9, 5.67}, {3.5725536*^9, + 5.7}, {3.580416*^9, 5.73}, {3.5882784*^9, 5.76}, { + 3.5961408*^9, 5.8}, {3.6040032*^9, 5.82}, {3.6118656*^9, + 5.85}, {3.619728*^9, 5.88}, {3.6275904*^9, 5.92}, { + 3.6354528*^9, 5.94}, {3.6433152*^9, 5.96}, {3.6511776*^9, + 5.99}, {3.65904*^9, 6.02}, {3.6669024*^9, 6.04}, { + 3.6747648*^9, 6.06}, {3.683232*^9, 6.08}, {3.6910944*^9, + 6.11}, {3.698352*^9, 6.13}, {3.7068192*^9, 6.15}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"26 Jul 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 40-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.395952*^9, 5.3}, {3.398976*^9, 5.25}, { + 3.4013952*^9, 5.21}, {3.4068384*^9, 5.1}, {3.4147008*^9, + 4.95}, {3.4225632*^9, 4.86}, {3.4304256*^9, 4.83}, { + 3.438288*^9, 4.85}, {3.4461504*^9, 4.89}, {3.4540128*^9, + 4.97}, {3.4618752*^9, 5.06}, {3.4697376*^9, 5.16}, { + 3.4776*^9, 5.23}, {3.4854624*^9, 5.3}, {3.4933248*^9, + 5.36}, {3.5011872*^9, 5.42}, {3.5090496*^9, 5.47}, { + 3.516912*^9, 5.51}, {3.5253792*^9, 5.56}, {3.5332416*^9, + 5.61}, {3.541104*^9, 5.64}, {3.5489664*^9, 5.68}, { + 3.5568288*^9, 5.72}, {3.5646912*^9, 5.76}, {3.5725536*^9, + 5.78}, {3.580416*^9, 5.81}, {3.5882784*^9, 5.85}, { + 3.5961408*^9, 5.89}, {3.6040032*^9, 5.91}, {3.6118656*^9, + 5.94}, {3.619728*^9, 5.98}, {3.6275904*^9, 6.02}, { + 3.6354528*^9, 6.04}, {3.6433152*^9, 6.06}, {3.6511776*^9, + 6.09}, {3.65904*^9, 6.13}, {3.6669024*^9, 6.14}, { + 3.6747648*^9, 6.16}, {3.683232*^9, 6.18}, {3.6910944*^9, + 6.22}, {3.698352*^9, 6.24}, {3.7068192*^9, 6.25}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"27 Jul 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 41-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.395952*^9, 5.32}, {3.398976*^9, 5.27}, { + 3.4013952*^9, 5.21}, {3.4068384*^9, 5.1}, {3.4147008*^9, + 4.95}, {3.4225632*^9, 4.87}, {3.4304256*^9, 4.85}, { + 3.438288*^9, 4.87}, {3.4461504*^9, 4.91}, {3.4540128*^9, + 4.99}, {3.4618752*^9, 5.08}, {3.4697376*^9, 5.17}, { + 3.4776*^9, 5.24}, {3.4854624*^9, 5.31}, {3.4933248*^9, + 5.37}, {3.5011872*^9, 5.43}, {3.5090496*^9, 5.47}, { + 3.516912*^9, 5.52}, {3.5253792*^9, 5.56}, {3.5332416*^9, + 5.61}, {3.541104*^9, 5.65}, {3.5489664*^9, 5.68}, { + 3.5568288*^9, 5.72}, {3.5646912*^9, 5.76}, {3.5725536*^9, + 5.79}, {3.580416*^9, 5.82}, {3.5882784*^9, 5.85}, { + 3.5961408*^9, 5.89}, {3.6040032*^9, 5.91}, {3.6118656*^9, + 5.94}, {3.619728*^9, 5.98}, {3.6275904*^9, 6.02}, { + 3.6354528*^9, 6.04}, {3.6433152*^9, 6.06}, {3.6511776*^9, + 6.1}, {3.65904*^9, 6.13}, {3.6669024*^9, 6.15}, { + 3.6747648*^9, 6.17}, {3.683232*^9, 6.19}, {3.6910944*^9, + 6.22}, {3.698352*^9, 6.24}, {3.7068192*^9, 6.26}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"30 Jul 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 42-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.395952*^9, 5.32}, {3.398976*^9, 5.27}, { + 3.4013952*^9, 5.21}, {3.4068384*^9, 5.09}, {3.4147008*^9, + 4.94}, {3.4225632*^9, 4.85}, {3.4304256*^9, 4.83}, { + 3.438288*^9, 4.85}, {3.4461504*^9, 4.9}, {3.4540128*^9, + 4.97}, {3.4618752*^9, 5.05}, {3.4697376*^9, 5.13}, { + 3.4776*^9, 5.2}, {3.4854624*^9, 5.26}, {3.4933248*^9, + 5.32}, {3.5011872*^9, 5.38}, {3.5090496*^9, 5.42}, { + 3.516912*^9, 5.46}, {3.5253792*^9, 5.5}, {3.5332416*^9, + 5.55}, {3.541104*^9, 5.59}, {3.5489664*^9, 5.62}, { + 3.5568288*^9, 5.66}, {3.5646912*^9, 5.7}, {3.5725536*^9, + 5.72}, {3.580416*^9, 5.75}, {3.5882784*^9, 5.79}, { + 3.5961408*^9, 5.83}, {3.6040032*^9, 5.85}, {3.6118656*^9, + 5.88}, {3.619728*^9, 5.92}, {3.6275904*^9, 5.96}, { + 3.6354528*^9, 5.98}, {3.6433152*^9, 6.}, {3.6511776*^9, + 6.03}, {3.65904*^9, 6.07}, {3.6669024*^9, 6.08}, { + 3.6747648*^9, 6.1}, {3.683232*^9, 6.12}, {3.6910944*^9, + 6.16}, {3.698352*^9, 6.18}, {3.7068192*^9, 6.19}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"31 Jul 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 43-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.395952*^9, 5.32}, {3.398976*^9, 5.25}, { + 3.4013952*^9, 5.2}, {3.4068384*^9, 5.06}, {3.4147008*^9, + 4.91}, {3.4225632*^9, 4.84}, {3.4304256*^9, 4.83}, { + 3.438288*^9, 4.85}, {3.4461504*^9, 4.89}, {3.4540128*^9, + 4.96}, {3.4618752*^9, 5.04}, {3.4697376*^9, 5.12}, { + 3.4776*^9, 5.19}, {3.4854624*^9, 5.25}, {3.4933248*^9, + 5.31}, {3.5011872*^9, 5.36}, {3.5090496*^9, 5.4}, { + 3.516912*^9, 5.45}, {3.5253792*^9, 5.49}, {3.5332416*^9, + 5.54}, {3.541104*^9, 5.57}, {3.5489664*^9, 5.61}, { + 3.5568288*^9, 5.64}, {3.5646912*^9, 5.68}, {3.5725536*^9, + 5.71}, {3.580416*^9, 5.74}, {3.5882784*^9, 5.77}, { + 3.5961408*^9, 5.81}, {3.6040032*^9, 5.83}, {3.6118656*^9, + 5.86}, {3.619728*^9, 5.9}, {3.6275904*^9, 5.94}, { + 3.6354528*^9, 5.96}, {3.6433152*^9, 5.98}, {3.6511776*^9, + 6.02}, {3.65904*^9, 6.05}, {3.6669024*^9, 6.07}, { + 3.6747648*^9, 6.09}, {3.683232*^9, 6.11}, {3.6910944*^9, + 6.14}, {3.698352*^9, 6.16}, {3.7068192*^9, 6.18}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"01 Aug 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 44-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.395952*^9, 5.33}, {3.398976*^9, 5.26}, { + 3.4013952*^9, 5.2}, {3.4068384*^9, 5.07}, {3.4147008*^9, + 4.92}, {3.4225632*^9, 4.86}, {3.4304256*^9, 4.85}, { + 3.438288*^9, 4.88}, {3.4461504*^9, 4.92}, {3.4540128*^9, + 4.99}, {3.4618752*^9, 5.06}, {3.4697376*^9, 5.13}, { + 3.4776*^9, 5.19}, {3.4854624*^9, 5.24}, {3.4933248*^9, + 5.29}, {3.5011872*^9, 5.34}, {3.5090496*^9, 5.38}, { + 3.516912*^9, 5.43}, {3.5253792*^9, 5.47}, {3.5332416*^9, + 5.51}, {3.541104*^9, 5.54}, {3.5489664*^9, 5.58}, { + 3.5568288*^9, 5.61}, {3.5646912*^9, 5.65}, {3.5725536*^9, + 5.68}, {3.580416*^9, 5.71}, {3.5882784*^9, 5.74}, { + 3.5961408*^9, 5.78}, {3.6040032*^9, 5.8}, {3.6118656*^9, + 5.83}, {3.619728*^9, 5.87}, {3.6275904*^9, 5.91}, { + 3.6354528*^9, 5.93}, {3.6433152*^9, 5.95}, {3.6511776*^9, + 5.98}, {3.65904*^9, 6.02}, {3.6669024*^9, 6.03}, { + 3.6747648*^9, 6.05}, {3.683232*^9, 6.07}, {3.6910944*^9, + 6.11}, {3.698352*^9, 6.13}, {3.7068192*^9, 6.14}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"02 Aug 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 45-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.395952*^9, 5.31}, {3.398976*^9, 5.22}, { + 3.4013952*^9, 5.13}, {3.4068384*^9, 4.98}, {3.4147008*^9, + 4.82}, {3.4225632*^9, 4.75}, {3.4304256*^9, 4.75}, { + 3.438288*^9, 4.78}, {3.4461504*^9, 4.83}, {3.4540128*^9, + 4.89}, {3.4618752*^9, 4.96}, {3.4697376*^9, 5.04}, { + 3.4776*^9, 5.1}, {3.4854624*^9, 5.16}, {3.4933248*^9, + 5.22}, {3.5011872*^9, 5.28}, {3.5090496*^9, 5.32}, { + 3.516912*^9, 5.37}, {3.5253792*^9, 5.41}, {3.5332416*^9, + 5.47}, {3.541104*^9, 5.5}, {3.5489664*^9, 5.54}, { + 3.5568288*^9, 5.58}, {3.5646912*^9, 5.62}, {3.5725536*^9, + 5.64}, {3.580416*^9, 5.67}, {3.5882784*^9, 5.71}, { + 3.5961408*^9, 5.75}, {3.6040032*^9, 5.77}, {3.6118656*^9, + 5.8}, {3.619728*^9, 5.84}, {3.6275904*^9, 5.88}, { + 3.6354528*^9, 5.9}, {3.6433152*^9, 5.92}, {3.6511776*^9, + 5.96}, {3.65904*^9, 5.99}, {3.6669024*^9, 6.01}, { + 3.6747648*^9, 6.03}, {3.683232*^9, 6.05}, {3.6910944*^9, + 6.08}, {3.698352*^9, 6.1}, {3.7068192*^9, 6.12}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"03 Aug 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 46-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.395952*^9, 5.32}, {3.398976*^9, 5.23}, { + 3.4013952*^9, 5.13}, {3.4068384*^9, 4.99}, {3.4147008*^9, + 4.83}, {3.4225632*^9, 4.78}, {3.4304256*^9, 4.79}, { + 3.438288*^9, 4.83}, {3.4461504*^9, 4.88}, {3.4540128*^9, + 4.94}, {3.4618752*^9, 5.01}, {3.4697376*^9, 5.08}, { + 3.4776*^9, 5.13}, {3.4854624*^9, 5.19}, {3.4933248*^9, + 5.24}, {3.5011872*^9, 5.3}, {3.5090496*^9, 5.34}, { + 3.516912*^9, 5.39}, {3.5253792*^9, 5.43}, {3.5332416*^9, + 5.48}, {3.541104*^9, 5.52}, {3.5489664*^9, 5.56}, { + 3.5568288*^9, 5.59}, {3.5646912*^9, 5.63}, {3.5725536*^9, + 5.66}, {3.580416*^9, 5.69}, {3.5882784*^9, 5.74}, { + 3.5961408*^9, 5.78}, {3.6040032*^9, 5.8}, {3.6118656*^9, + 5.83}, {3.619728*^9, 5.87}, {3.6275904*^9, 5.91}, { + 3.6354528*^9, 5.93}, {3.6433152*^9, 5.95}, {3.6511776*^9, + 5.99}, {3.65904*^9, 6.02}, {3.6669024*^9, 6.04}, { + 3.6747648*^9, 6.06}, {3.683232*^9, 6.08}, {3.6910944*^9, + 6.11}, {3.698352*^9, 6.13}, {3.7068192*^9, 6.15}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"06 Aug 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 47-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.395952*^9, 5.35}, {3.398976*^9, 5.29}, { + 3.4013952*^9, 5.19}, {3.4068384*^9, 5.06}, {3.4147008*^9, + 4.87}, {3.4225632*^9, 4.8}, {3.4304256*^9, 4.8}, { + 3.438288*^9, 4.84}, {3.4461504*^9, 4.89}, {3.4540128*^9, + 4.95}, {3.4618752*^9, 5.02}, {3.4697376*^9, 5.09}, { + 3.4776*^9, 5.14}, {3.4854624*^9, 5.19}, {3.4933248*^9, + 5.24}, {3.5011872*^9, 5.3}, {3.5090496*^9, 5.34}, { + 3.516912*^9, 5.39}, {3.5253792*^9, 5.43}, {3.5332416*^9, + 5.48}, {3.541104*^9, 5.52}, {3.5489664*^9, 5.56}, { + 3.5568288*^9, 5.59}, {3.5646912*^9, 5.63}, {3.5725536*^9, + 5.66}, {3.580416*^9, 5.69}, {3.5882784*^9, 5.74}, { + 3.5961408*^9, 5.78}, {3.6040032*^9, 5.8}, {3.6118656*^9, + 5.83}, {3.619728*^9, 5.87}, {3.6275904*^9, 5.91}, { + 3.6354528*^9, 5.93}, {3.6433152*^9, 5.95}, {3.6511776*^9, + 5.99}, {3.65904*^9, 6.02}, {3.6669024*^9, 6.04}, { + 3.6747648*^9, 6.06}, {3.683232*^9, 6.08}, {3.6910944*^9, + 6.11}, {3.698352*^9, 6.13}, {3.7068192*^9, 6.15}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"07 Aug 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 48-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.395952*^9, 5.39}, {3.398976*^9, 5.33}, { + 3.4013952*^9, 5.27}, {3.4044192*^9, 5.2}, {3.4068384*^9, + 5.12}, {3.4147008*^9, 4.96}, {3.4225632*^9, 4.9}, { + 3.4304256*^9, 4.9}, {3.438288*^9, 4.93}, {3.4461504*^9, + 4.98}, {3.4540128*^9, 5.03}, {3.4618752*^9, 5.09}, { + 3.4697376*^9, 5.16}, {3.4776*^9, 5.21}, {3.4854624*^9, + 5.26}, {3.4933248*^9, 5.3}, {3.5011872*^9, 5.36}, { + 3.5090496*^9, 5.4}, {3.516912*^9, 5.44}, {3.5253792*^9, + 5.48}, {3.5332416*^9, 5.53}, {3.541104*^9, 5.57}, { + 3.5489664*^9, 5.61}, {3.5568288*^9, 5.64}, {3.5646912*^9, + 5.68}, {3.5725536*^9, 5.71}, {3.580416*^9, 5.74}, { + 3.5882784*^9, 5.79}, {3.5961408*^9, 5.83}, {3.6040032*^9, + 5.85}, {3.6118656*^9, 5.88}, {3.619728*^9, 5.92}, { + 3.6275904*^9, 5.96}, {3.6354528*^9, 5.98}, {3.6433152*^9, + 6.}, {3.6511776*^9, 6.04}, {3.65904*^9, 6.07}, { + 3.6669024*^9, 6.09}, {3.6747648*^9, 6.11}, {3.683232*^9, + 6.13}, {3.6910944*^9, 6.16}, {3.698352*^9, 6.18}, { + 3.7068192*^9, 6.2}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"08 Aug 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 49-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.395952*^9, 5.4}, {3.398976*^9, 5.24}, { + 3.4013952*^9, 5.13}, {3.4044192*^9, 5.03}, {3.4068384*^9, + 4.96}, {3.4147008*^9, 4.77}, {3.4225632*^9, 4.73}, { + 3.4304256*^9, 4.76}, {3.438288*^9, 4.82}, {3.4461504*^9, + 4.89}, {3.4540128*^9, 4.96}, {3.4618752*^9, 5.03}, { + 3.4697376*^9, 5.1}, {3.4776*^9, 5.16}, {3.4854624*^9, + 5.21}, {3.4933248*^9, 5.26}, {3.5011872*^9, 5.32}, { + 3.5090496*^9, 5.36}, {3.516912*^9, 5.41}, {3.5253792*^9, + 5.45}, {3.5332416*^9, 5.51}, {3.541104*^9, 5.54}, { + 3.5489664*^9, 5.58}, {3.5568288*^9, 5.62}, {3.5646912*^9, + 5.66}, {3.5725536*^9, 5.69}, {3.580416*^9, 5.73}, { + 3.5882784*^9, 5.78}, {3.5961408*^9, 5.82}, {3.6040032*^9, + 5.85}, {3.6118656*^9, 5.88}, {3.619728*^9, 5.92}, { + 3.6275904*^9, 5.96}, {3.6354528*^9, 5.99}, {3.6433152*^9, + 6.01}, {3.6511776*^9, 6.05}, {3.65904*^9, 6.08}, { + 3.6669024*^9, 6.1}, {3.6747648*^9, 6.12}, {3.683232*^9, + 6.14}, {3.6910944*^9, 6.18}, {3.698352*^9, 6.2}, { + 3.7068192*^9, 6.21}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"09 Aug 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 50-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.395952*^9, 5.5}, {3.398976*^9, 5.23}, { + 3.4013952*^9, 5.08}, {3.4044192*^9, 4.99}, {3.4068384*^9, + 4.91}, {3.4147008*^9, 4.75}, {3.4225632*^9, 4.72}, { + 3.4304256*^9, 4.76}, {3.438288*^9, 4.82}, {3.4461504*^9, + 4.89}, {3.4540128*^9, 4.96}, {3.4618752*^9, 5.03}, { + 3.4697376*^9, 5.1}, {3.4776*^9, 5.15}, {3.4854624*^9, + 5.21}, {3.4933248*^9, 5.26}, {3.5011872*^9, 5.32}, { + 3.5090496*^9, 5.36}, {3.516912*^9, 5.4}, {3.5253792*^9, + 5.45}, {3.5332416*^9, 5.5}, {3.541104*^9, 5.54}, { + 3.5489664*^9, 5.58}, {3.5568288*^9, 5.62}, {3.5646912*^9, + 5.66}, {3.5725536*^9, 5.69}, {3.580416*^9, 5.73}, { + 3.5882784*^9, 5.78}, {3.5961408*^9, 5.82}, {3.6040032*^9, + 5.85}, {3.6118656*^9, 5.88}, {3.619728*^9, 5.92}, { + 3.6275904*^9, 5.96}, {3.6354528*^9, 5.99}, {3.6433152*^9, + 6.01}, {3.6511776*^9, 6.05}, {3.65904*^9, 6.08}, { + 3.6669024*^9, 6.1}, {3.6747648*^9, 6.12}, {3.683232*^9, + 6.15}, {3.6910944*^9, 6.18}, {3.698352*^9, 6.2}, { + 3.7068192*^9, 6.22}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"10 Aug 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 51-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.398976*^9, 5.26}, {3.4013952*^9, 5.14}, { + 3.4044192*^9, 5.05}, {3.4068384*^9, 4.96}, {3.4147008*^9, + 4.76}, {3.4225632*^9, 4.72}, {3.4304256*^9, 4.76}, { + 3.438288*^9, 4.83}, {3.4461504*^9, 4.9}, {3.4540128*^9, + 4.97}, {3.4618752*^9, 5.04}, {3.4697376*^9, 5.12}, { + 3.4776*^9, 5.18}, {3.4854624*^9, 5.24}, {3.4933248*^9, + 5.29}, {3.5011872*^9, 5.36}, {3.5090496*^9, 5.4}, { + 3.516912*^9, 5.44}, {3.5253792*^9, 5.49}, {3.5332416*^9, + 5.54}, {3.541104*^9, 5.58}, {3.5489664*^9, 5.62}, { + 3.5568288*^9, 5.66}, {3.5646912*^9, 5.7}, {3.5725536*^9, + 5.73}, {3.580416*^9, 5.77}, {3.5882784*^9, 5.82}, { + 3.5961408*^9, 5.86}, {3.6040032*^9, 5.89}, {3.6118656*^9, + 5.92}, {3.619728*^9, 5.96}, {3.6275904*^9, 6.}, { + 3.6354528*^9, 6.03}, {3.6433152*^9, 6.05}, {3.6511776*^9, + 6.09}, {3.65904*^9, 6.12}, {3.6669024*^9, 6.14}, { + 3.6747648*^9, 6.16}, {3.683232*^9, 6.19}, {3.6910944*^9, + 6.22}, {3.698352*^9, 6.24}, {3.7068192*^9, 6.26}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"13 Aug 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 52-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.398976*^9, 5.27}, {3.4013952*^9, 5.15}, { + 3.4044192*^9, 5.04}, {3.4068384*^9, 4.94}, {3.4147008*^9, + 4.71}, {3.4225632*^9, 4.67}, {3.4304256*^9, 4.71}, { + 3.438288*^9, 4.78}, {3.4461504*^9, 4.85}, {3.4540128*^9, + 4.92}, {3.4618752*^9, 5.}, {3.4697376*^9, 5.08}, { + 3.4776*^9, 5.15}, {3.4854624*^9, 5.21}, {3.4933248*^9, + 5.26}, {3.5011872*^9, 5.33}, {3.5090496*^9, 5.37}, { + 3.516912*^9, 5.42}, {3.5253792*^9, 5.46}, {3.5332416*^9, + 5.52}, {3.541104*^9, 5.55}, {3.5489664*^9, 5.59}, { + 3.5568288*^9, 5.63}, {3.5646912*^9, 5.68}, {3.5725536*^9, + 5.71}, {3.580416*^9, 5.74}, {3.5882784*^9, 5.79}, { + 3.5961408*^9, 5.84}, {3.6040032*^9, 5.86}, {3.6118656*^9, + 5.89}, {3.619728*^9, 5.94}, {3.6275904*^9, 5.98}, { + 3.6354528*^9, 6.}, {3.6433152*^9, 6.03}, {3.6511776*^9, + 6.06}, {3.65904*^9, 6.1}, {3.6669024*^9, 6.12}, { + 3.6747648*^9, 6.14}, {3.683232*^9, 6.16}, {3.6910944*^9, + 6.2}, {3.698352*^9, 6.22}, {3.7068192*^9, 6.23}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"14 Aug 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 53-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.398976*^9, 5.26}, {3.4013952*^9, 5.15}, { + 3.4044192*^9, 4.98}, {3.4068384*^9, 4.87}, {3.4147008*^9, + 4.62}, {3.4225632*^9, 4.59}, {3.4304256*^9, 4.65}, { + 3.438288*^9, 4.73}, {3.4461504*^9, 4.8}, {3.4540128*^9, + 4.87}, {3.4618752*^9, 4.94}, {3.4697376*^9, 5.03}, { + 3.4776*^9, 5.09}, {3.4854624*^9, 5.15}, {3.4933248*^9, + 5.21}, {3.5011872*^9, 5.28}, {3.5090496*^9, 5.33}, { + 3.516912*^9, 5.38}, {3.5253792*^9, 5.43}, {3.5332416*^9, + 5.49}, {3.541104*^9, 5.53}, {3.5489664*^9, 5.57}, { + 3.5568288*^9, 5.62}, {3.5646912*^9, 5.67}, {3.5725536*^9, + 5.7}, {3.580416*^9, 5.74}, {3.5882784*^9, 5.79}, { + 3.5961408*^9, 5.84}, {3.6040032*^9, 5.86}, {3.6118656*^9, + 5.89}, {3.619728*^9, 5.94}, {3.6275904*^9, 5.98}, { + 3.6354528*^9, 6.01}, {3.6433152*^9, 6.03}, {3.6511776*^9, + 6.07}, {3.65904*^9, 6.11}, {3.6669024*^9, 6.13}, { + 3.6747648*^9, 6.15}, {3.683232*^9, 6.17}, {3.6910944*^9, + 6.21}, {3.698352*^9, 6.23}, {3.7068192*^9, 6.25}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"15 Aug 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 54-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.398976*^9, 5.19}, {3.4013952*^9, 5.07}, { + 3.4044192*^9, 4.87}, {3.4068384*^9, 4.74}, {3.4147008*^9, + 4.4}, {3.4225632*^9, 4.38}, {3.4304256*^9, 4.49}, { + 3.438288*^9, 4.6}, {3.4461504*^9, 4.69}, {3.4540128*^9, + 4.76}, {3.4618752*^9, 4.84}, {3.4697376*^9, 4.92}, { + 3.4776*^9, 4.98}, {3.4854624*^9, 5.05}, {3.4933248*^9, + 5.11}, {3.5011872*^9, 5.19}, {3.5090496*^9, 5.24}, { + 3.516912*^9, 5.3}, {3.5253792*^9, 5.36}, {3.5332416*^9, + 5.42}, {3.541104*^9, 5.46}, {3.5489664*^9, 5.51}, { + 3.5568288*^9, 5.57}, {3.5646912*^9, 5.62}, {3.5725536*^9, + 5.65}, {3.580416*^9, 5.7}, {3.5882784*^9, 5.75}, { + 3.5961408*^9, 5.8}, {3.6040032*^9, 5.83}, {3.6118656*^9, + 5.87}, {3.619728*^9, 5.91}, {3.6275904*^9, 5.96}, { + 3.6354528*^9, 5.99}, {3.6433152*^9, 6.01}, {3.6511776*^9, + 6.05}, {3.65904*^9, 6.09}, {3.6669024*^9, 6.11}, { + 3.6747648*^9, 6.13}, {3.683232*^9, 6.16}, {3.6910944*^9, + 6.2}, {3.698352*^9, 6.22}, {3.7068192*^9, 6.24}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"16 Aug 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 55-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.398976*^9, 5.11}, {3.4013952*^9, 5.}, { + 3.4044192*^9, 4.85}, {3.4068384*^9, 4.71}, {3.4147008*^9, + 4.47}, {3.4225632*^9, 4.46}, {3.4304256*^9, 4.57}, { + 3.438288*^9, 4.68}, {3.4461504*^9, 4.76}, {3.4540128*^9, + 4.83}, {3.4618752*^9, 4.91}, {3.4697376*^9, 4.99}, { + 3.4776*^9, 5.05}, {3.4854624*^9, 5.11}, {3.4933248*^9, + 5.17}, {3.5011872*^9, 5.25}, {3.5090496*^9, 5.3}, { + 3.516912*^9, 5.36}, {3.5253792*^9, 5.42}, {3.5332416*^9, + 5.48}, {3.541104*^9, 5.53}, {3.5489664*^9, 5.58}, { + 3.5568288*^9, 5.63}, {3.5646912*^9, 5.69}, {3.5725536*^9, + 5.72}, {3.580416*^9, 5.77}, {3.5882784*^9, 5.83}, { + 3.5961408*^9, 5.88}, {3.6040032*^9, 5.91}, {3.6118656*^9, + 5.94}, {3.619728*^9, 5.99}, {3.6275904*^9, 6.03}, { + 3.6354528*^9, 6.06}, {3.6433152*^9, 6.09}, {3.6511776*^9, + 6.12}, {3.65904*^9, 6.16}, {3.6669024*^9, 6.18}, { + 3.6747648*^9, 6.2}, {3.683232*^9, 6.23}, {3.6910944*^9, + 6.27}, {3.698352*^9, 6.3}, {3.7068192*^9, 6.31}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"17 Aug 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 56-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.398976*^9, 5.09}, {3.4013952*^9, 4.97}, { + 3.4044192*^9, 4.81}, {3.4068384*^9, 4.7}, {3.4147008*^9, + 4.47}, {3.4225632*^9, 4.46}, {3.4304256*^9, 4.55}, { + 3.438288*^9, 4.65}, {3.4461504*^9, 4.73}, {3.4540128*^9, + 4.8}, {3.4618752*^9, 4.87}, {3.4697376*^9, 4.95}, { + 3.4776*^9, 5.01}, {3.4854624*^9, 5.08}, {3.4933248*^9, + 5.14}, {3.5011872*^9, 5.21}, {3.5090496*^9, 5.27}, { + 3.516912*^9, 5.33}, {3.5253792*^9, 5.38}, {3.5332416*^9, + 5.45}, {3.541104*^9, 5.49}, {3.5489664*^9, 5.54}, { + 3.5568288*^9, 5.6}, {3.5646912*^9, 5.65}, {3.5725536*^9, + 5.69}, {3.580416*^9, 5.74}, {3.5882784*^9, 5.79}, { + 3.5961408*^9, 5.85}, {3.6040032*^9, 5.88}, {3.6118656*^9, + 5.91}, {3.619728*^9, 5.96}, {3.6275904*^9, 6.01}, { + 3.6354528*^9, 6.04}, {3.6433152*^9, 6.06}, {3.6511776*^9, + 6.1}, {3.65904*^9, 6.14}, {3.6669024*^9, 6.16}, { + 3.6747648*^9, 6.18}, {3.683232*^9, 6.22}, {3.6910944*^9, + 6.26}, {3.698352*^9, 6.28}, {3.7068192*^9, 6.3}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"20 Aug 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 57-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.398976*^9, 5.12}, {3.4013952*^9, 4.96}, { + 3.4044192*^9, 4.77}, {3.4068384*^9, 4.65}, {3.4147008*^9, + 4.43}, {3.4225632*^9, 4.43}, {3.4304256*^9, 4.53}, { + 3.438288*^9, 4.61}, {3.4461504*^9, 4.68}, {3.4540128*^9, + 4.74}, {3.4618752*^9, 4.81}, {3.4697376*^9, 4.88}, { + 3.4776*^9, 4.94}, {3.4854624*^9, 5.}, {3.4933248*^9, + 5.06}, {3.5011872*^9, 5.13}, {3.5090496*^9, 5.19}, { + 3.516912*^9, 5.25}, {3.5253792*^9, 5.3}, {3.5332416*^9, + 5.37}, {3.541104*^9, 5.41}, {3.5489664*^9, 5.46}, { + 3.5568288*^9, 5.52}, {3.5646912*^9, 5.57}, {3.5725536*^9, + 5.61}, {3.580416*^9, 5.66}, {3.5882784*^9, 5.71}, { + 3.5961408*^9, 5.77}, {3.6040032*^9, 5.8}, {3.6118656*^9, + 5.83}, {3.619728*^9, 5.88}, {3.6275904*^9, 5.93}, { + 3.6354528*^9, 5.96}, {3.6433152*^9, 5.98}, {3.6511776*^9, + 6.02}, {3.65904*^9, 6.06}, {3.6669024*^9, 6.08}, { + 3.6747648*^9, 6.1}, {3.683232*^9, 6.14}, {3.6910944*^9, + 6.18}, {3.698352*^9, 6.2}, {3.7068192*^9, 6.22}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"21 Aug 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 58-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.398976*^9, 5.21}, {3.4013952*^9, 5.07}, { + 3.4044192*^9, 4.9}, {3.4068384*^9, 4.78}, {3.4147008*^9, + 4.56}, {3.4225632*^9, 4.54}, {3.4304256*^9, 4.62}, { + 3.438288*^9, 4.69}, {3.4461504*^9, 4.75}, {3.4540128*^9, + 4.81}, {3.4618752*^9, 4.86}, {3.4697376*^9, 4.93}, { + 3.4776*^9, 4.97}, {3.4854624*^9, 5.03}, {3.4933248*^9, + 5.08}, {3.5011872*^9, 5.15}, {3.5090496*^9, 5.19}, { + 3.516912*^9, 5.25}, {3.5253792*^9, 5.3}, {3.5332416*^9, + 5.36}, {3.541104*^9, 5.4}, {3.5489664*^9, 5.45}, { + 3.5568288*^9, 5.5}, {3.5646912*^9, 5.55}, {3.5725536*^9, + 5.58}, {3.580416*^9, 5.63}, {3.5882784*^9, 5.68}, { + 3.5961408*^9, 5.73}, {3.6040032*^9, 5.76}, {3.6118656*^9, + 5.79}, {3.619728*^9, 5.83}, {3.6275904*^9, 5.88}, { + 3.6354528*^9, 5.9}, {3.6433152*^9, 5.92}, {3.6511776*^9, + 5.96}, {3.65904*^9, 5.99}, {3.6669024*^9, 6.01}, { + 3.6747648*^9, 6.03}, {3.683232*^9, 6.06}, {3.6910944*^9, + 6.09}, {3.698352*^9, 6.11}, {3.7068192*^9, 6.13}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"22 Aug 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 59-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.398976*^9, 5.29}, {3.4013952*^9, 5.16}, { + 3.4044192*^9, 4.97}, {3.4068384*^9, 4.86}, {3.4147008*^9, + 4.64}, {3.4225632*^9, 4.6}, {3.4304256*^9, 4.66}, { + 3.438288*^9, 4.73}, {3.4461504*^9, 4.78}, {3.4540128*^9, + 4.84}, {3.4618752*^9, 4.89}, {3.4697376*^9, 4.95}, { + 3.4776*^9, 4.98}, {3.4854624*^9, 5.03}, {3.4933248*^9, + 5.08}, {3.5011872*^9, 5.14}, {3.5090496*^9, 5.18}, { + 3.516912*^9, 5.23}, {3.5253792*^9, 5.28}, {3.5332416*^9, + 5.33}, {3.541104*^9, 5.37}, {3.5489664*^9, 5.42}, { + 3.5568288*^9, 5.46}, {3.5646912*^9, 5.51}, {3.5725536*^9, + 5.54}, {3.580416*^9, 5.58}, {3.5882784*^9, 5.62}, { + 3.5961408*^9, 5.67}, {3.6040032*^9, 5.7}, {3.6118656*^9, + 5.73}, {3.619728*^9, 5.77}, {3.6275904*^9, 5.82}, { + 3.6354528*^9, 5.84}, {3.6433152*^9, 5.86}, {3.6511776*^9, + 5.89}, {3.65904*^9, 5.93}, {3.6669024*^9, 5.94}, { + 3.6747648*^9, 5.96}, {3.683232*^9, 5.99}, {3.6910944*^9, + 6.02}, {3.698352*^9, 6.04}, {3.7068192*^9, 6.05}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"23 Aug 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 60-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.398976*^9, 5.33}, {3.4013952*^9, 5.22}, { + 3.4044192*^9, 5.06}, {3.4068384*^9, 4.97}, {3.4147008*^9, + 4.74}, {3.4225632*^9, 4.69}, {3.4304256*^9, 4.72}, { + 3.438288*^9, 4.77}, {3.4461504*^9, 4.82}, {3.4540128*^9, + 4.87}, {3.4618752*^9, 4.91}, {3.4697376*^9, 4.96}, { + 3.4776*^9, 4.99}, {3.4854624*^9, 5.03}, {3.4933248*^9, + 5.07}, {3.5011872*^9, 5.13}, {3.5090496*^9, 5.16}, { + 3.516912*^9, 5.21}, {3.5253792*^9, 5.25}, {3.5332416*^9, + 5.3}, {3.541104*^9, 5.34}, {3.5489664*^9, 5.38}, { + 3.5568288*^9, 5.42}, {3.5646912*^9, 5.46}, {3.5725536*^9, + 5.49}, {3.580416*^9, 5.52}, {3.5882784*^9, 5.56}, { + 3.5961408*^9, 5.6}, {3.6040032*^9, 5.63}, {3.6118656*^9, + 5.65}, {3.619728*^9, 5.69}, {3.6275904*^9, 5.73}, { + 3.6354528*^9, 5.75}, {3.6433152*^9, 5.77}, {3.6511776*^9, + 5.8}, {3.65904*^9, 5.84}, {3.6669024*^9, 5.85}, { + 3.6747648*^9, 5.87}, {3.683232*^9, 5.89}, {3.6910944*^9, + 5.93}, {3.698352*^9, 5.94}, {3.7068192*^9, 5.96}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"24 Aug 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 61-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.398976*^9, 5.32}, {3.4013952*^9, 5.19}, { + 3.4044192*^9, 5.03}, {3.4068384*^9, 4.91}, {3.4147008*^9, + 4.66}, {3.4225632*^9, 4.61}, {3.4304256*^9, 4.65}, { + 3.438288*^9, 4.7}, {3.4461504*^9, 4.74}, {3.4540128*^9, + 4.8}, {3.4618752*^9, 4.85}, {3.4697376*^9, 4.91}, { + 3.4776*^9, 4.94}, {3.4854624*^9, 4.98}, {3.4933248*^9, + 5.03}, {3.5011872*^9, 5.08}, {3.5090496*^9, 5.12}, { + 3.516912*^9, 5.17}, {3.5253792*^9, 5.21}, {3.5332416*^9, + 5.26}, {3.541104*^9, 5.3}, {3.5489664*^9, 5.34}, { + 3.5568288*^9, 5.38}, {3.5646912*^9, 5.43}, {3.5725536*^9, + 5.45}, {3.580416*^9, 5.49}, {3.5882784*^9, 5.52}, { + 3.5961408*^9, 5.57}, {3.6040032*^9, 5.59}, {3.6118656*^9, + 5.62}, {3.619728*^9, 5.65}, {3.6275904*^9, 5.7}, { + 3.6354528*^9, 5.72}, {3.6433152*^9, 5.74}, {3.6511776*^9, + 5.77}, {3.65904*^9, 5.8}, {3.6669024*^9, 5.82}, { + 3.6747648*^9, 5.83}, {3.683232*^9, 5.86}, {3.6910944*^9, + 5.89}, {3.698352*^9, 5.91}, {3.7068192*^9, 5.92}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"27 Aug 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 62-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.398976*^9, 5.32}, {3.4013952*^9, 5.17}, { + 3.4044192*^9, 4.97}, {3.4068384*^9, 4.81}, {3.4147008*^9, + 4.56}, {3.4225632*^9, 4.51}, {3.4304256*^9, 4.54}, { + 3.438288*^9, 4.58}, {3.4461504*^9, 4.63}, {3.4540128*^9, + 4.69}, {3.4618752*^9, 4.75}, {3.4697376*^9, 4.82}, { + 3.4776*^9, 4.86}, {3.4854624*^9, 4.91}, {3.4933248*^9, + 4.96}, {3.5011872*^9, 5.02}, {3.5090496*^9, 5.07}, { + 3.516912*^9, 5.12}, {3.5253792*^9, 5.17}, {3.5332416*^9, + 5.22}, {3.541104*^9, 5.26}, {3.5489664*^9, 5.31}, { + 3.5568288*^9, 5.36}, {3.5646912*^9, 5.41}, {3.5725536*^9, + 5.44}, {3.580416*^9, 5.48}, {3.5882784*^9, 5.52}, { + 3.5961408*^9, 5.57}, {3.6040032*^9, 5.59}, {3.6118656*^9, + 5.62}, {3.619728*^9, 5.66}, {3.6275904*^9, 5.71}, { + 3.6354528*^9, 5.73}, {3.6433152*^9, 5.75}, {3.6511776*^9, + 5.79}, {3.65904*^9, 5.82}, {3.6669024*^9, 5.84}, { + 3.6747648*^9, 5.86}, {3.683232*^9, 5.89}, {3.6910944*^9, + 5.92}, {3.698352*^9, 5.94}, {3.7068192*^9, 5.96}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"28 Aug 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 63-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.398976*^9, 5.39}, {3.4013952*^9, 5.23}, { + 3.4044192*^9, 5.04}, {3.4068384*^9, 4.88}, {3.4147008*^9, + 4.62}, {3.4225632*^9, 4.54}, {3.4304256*^9, 4.55}, { + 3.438288*^9, 4.59}, {3.4461504*^9, 4.64}, {3.4540128*^9, + 4.71}, {3.4618752*^9, 4.76}, {3.4697376*^9, 4.83}, { + 3.4776*^9, 4.87}, {3.4854624*^9, 4.92}, {3.4933248*^9, + 4.98}, {3.5011872*^9, 5.05}, {3.5090496*^9, 5.09}, { + 3.516912*^9, 5.15}, {3.5253792*^9, 5.2}, {3.5332416*^9, + 5.26}, {3.541104*^9, 5.31}, {3.5489664*^9, 5.36}, { + 3.5568288*^9, 5.4}, {3.5646912*^9, 5.45}, {3.5725536*^9, + 5.48}, {3.580416*^9, 5.52}, {3.5882784*^9, 5.56}, { + 3.5961408*^9, 5.61}, {3.6040032*^9, 5.64}, {3.6118656*^9, + 5.67}, {3.619728*^9, 5.71}, {3.6275904*^9, 5.75}, { + 3.6354528*^9, 5.77}, {3.6433152*^9, 5.8}, {3.6511776*^9, + 5.83}, {3.65904*^9, 5.87}, {3.6669024*^9, 5.88}, { + 3.6747648*^9, 5.9}, {3.683232*^9, 5.93}, {3.6910944*^9, + 5.97}, {3.698352*^9, 5.98}, {3.7068192*^9, 6.}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"29 Aug 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 64-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.398976*^9, 5.45}, {3.4013952*^9, 5.29}, { + 3.4044192*^9, 5.07}, {3.4068384*^9, 4.89}, {3.4147008*^9, + 4.56}, {3.4225632*^9, 4.46}, {3.4304256*^9, 4.47}, { + 3.438288*^9, 4.51}, {3.4461504*^9, 4.57}, {3.4540128*^9, + 4.63}, {3.4618752*^9, 4.69}, {3.4697376*^9, 4.76}, { + 3.4776*^9, 4.81}, {3.4854624*^9, 4.87}, {3.4933248*^9, + 4.93}, {3.5011872*^9, 5.}, {3.5090496*^9, 5.05}, { + 3.516912*^9, 5.11}, {3.5253792*^9, 5.16}, {3.5332416*^9, + 5.22}, {3.541104*^9, 5.27}, {3.5489664*^9, 5.32}, { + 3.5568288*^9, 5.36}, {3.5646912*^9, 5.42}, {3.5725536*^9, + 5.45}, {3.580416*^9, 5.49}, {3.5882784*^9, 5.54}, { + 3.5961408*^9, 5.59}, {3.6040032*^9, 5.62}, {3.6118656*^9, + 5.65}, {3.619728*^9, 5.69}, {3.6275904*^9, 5.74}, { + 3.6354528*^9, 5.76}, {3.6433152*^9, 5.79}, {3.6511776*^9, + 5.83}, {3.65904*^9, 5.86}, {3.6669024*^9, 5.88}, { + 3.6747648*^9, 5.91}, {3.683232*^9, 5.94}, {3.6910944*^9, + 5.97}, {3.698352*^9, 5.99}, {3.7068192*^9, 6.01}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"30 Aug 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 65-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.398976*^9, 5.5}, {3.4013952*^9, 5.34}, { + 3.4044192*^9, 5.1}, {3.4068384*^9, 4.93}, {3.4147008*^9, + 4.64}, {3.4225632*^9, 4.55}, {3.4304256*^9, 4.56}, { + 3.438288*^9, 4.6}, {3.4461504*^9, 4.65}, {3.4540128*^9, + 4.71}, {3.4618752*^9, 4.75}, {3.4697376*^9, 4.81}, { + 3.4776*^9, 4.85}, {3.4854624*^9, 4.9}, {3.4933248*^9, + 4.95}, {3.5011872*^9, 5.01}, {3.5090496*^9, 5.06}, { + 3.516912*^9, 5.11}, {3.5253792*^9, 5.16}, {3.5332416*^9, + 5.22}, {3.541104*^9, 5.27}, {3.5489664*^9, 5.31}, { + 3.5568288*^9, 5.36}, {3.5646912*^9, 5.41}, {3.5725536*^9, + 5.45}, {3.580416*^9, 5.49}, {3.5882784*^9, 5.53}, { + 3.5961408*^9, 5.58}, {3.6040032*^9, 5.61}, {3.6118656*^9, + 5.65}, {3.619728*^9, 5.69}, {3.6275904*^9, 5.73}, { + 3.6354528*^9, 5.76}, {3.6433152*^9, 5.79}, {3.6511776*^9, + 5.82}, {3.65904*^9, 5.86}, {3.6669024*^9, 5.88}, { + 3.6747648*^9, 5.9}, {3.683232*^9, 5.93}, {3.6910944*^9, + 5.97}, {3.698352*^9, 5.98}, {3.7068192*^9, 6.}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"31 Aug 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 66-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.398976*^9, 5.6}, {3.4013952*^9, 5.4}, { + 3.4044192*^9, 5.16}, {3.4068384*^9, 4.97}, {3.4147008*^9, + 4.64}, {3.4225632*^9, 4.55}, {3.4304256*^9, 4.55}, { + 3.438288*^9, 4.59}, {3.4461504*^9, 4.64}, {3.4540128*^9, + 4.7}, {3.4618752*^9, 4.75}, {3.4697376*^9, 4.81}, { + 3.4776*^9, 4.85}, {3.4854624*^9, 4.9}, {3.4933248*^9, + 4.95}, {3.5011872*^9, 5.01}, {3.5090496*^9, 5.06}, { + 3.516912*^9, 5.11}, {3.5253792*^9, 5.16}, {3.5332416*^9, + 5.22}, {3.541104*^9, 5.27}, {3.5489664*^9, 5.31}, { + 3.5568288*^9, 5.36}, {3.5646912*^9, 5.41}, {3.5725536*^9, + 5.45}, {3.580416*^9, 5.49}, {3.5882784*^9, 5.53}, { + 3.5961408*^9, 5.58}, {3.6040032*^9, 5.61}, {3.6118656*^9, + 5.65}, {3.619728*^9, 5.69}, {3.6275904*^9, 5.73}, { + 3.6354528*^9, 5.76}, {3.6433152*^9, 5.79}, {3.6511776*^9, + 5.82}, {3.65904*^9, 5.86}, {3.6669024*^9, 5.88}, { + 3.6747648*^9, 5.9}, {3.683232*^9, 5.93}, {3.6910944*^9, + 5.97}, {3.698352*^9, 5.98}, {3.7068192*^9, 6.}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"04 Sep 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 67-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.398976*^9, 5.55}, {3.4013952*^9, 5.36}, { + 3.4044192*^9, 5.08}, {3.4068384*^9, 4.9}, {3.4147008*^9, + 4.51}, {3.4225632*^9, 4.41}, {3.4304256*^9, 4.42}, { + 3.438288*^9, 4.46}, {3.4461504*^9, 4.52}, {3.4540128*^9, + 4.58}, {3.4618752*^9, 4.64}, {3.4697376*^9, 4.71}, { + 3.4776*^9, 4.75}, {3.4854624*^9, 4.8}, {3.4933248*^9, + 4.86}, {3.5011872*^9, 4.92}, {3.5090496*^9, 4.97}, { + 3.516912*^9, 5.03}, {3.5253792*^9, 5.08}, {3.5332416*^9, + 5.14}, {3.541104*^9, 5.18}, {3.5489664*^9, 5.23}, { + 3.5568288*^9, 5.28}, {3.5646912*^9, 5.34}, {3.5725536*^9, + 5.38}, {3.580416*^9, 5.42}, {3.5882784*^9, 5.46}, { + 3.5961408*^9, 5.51}, {3.6040032*^9, 5.54}, {3.6118656*^9, + 5.58}, {3.619728*^9, 5.62}, {3.6275904*^9, 5.67}, { + 3.6354528*^9, 5.69}, {3.6433152*^9, 5.72}, {3.6511776*^9, + 5.76}, {3.65904*^9, 5.79}, {3.6669024*^9, 5.81}, { + 3.6747648*^9, 5.84}, {3.683232*^9, 5.87}, {3.6910944*^9, + 5.9}, {3.698352*^9, 5.92}, {3.7068192*^9, 5.94}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"05 Sep 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 68-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.398976*^9, 5.59}, {3.4013952*^9, 5.41}, { + 3.4044192*^9, 5.13}, {3.4068384*^9, 4.94}, {3.4147008*^9, + 4.56}, {3.4225632*^9, 4.46}, {3.4304256*^9, 4.45}, { + 3.438288*^9, 4.49}, {3.4461504*^9, 4.55}, {3.4540128*^9, + 4.62}, {3.4618752*^9, 4.67}, {3.4697376*^9, 4.73}, { + 3.4776*^9, 4.76}, {3.4854624*^9, 4.81}, {3.4933248*^9, + 4.86}, {3.5011872*^9, 4.92}, {3.5090496*^9, 4.97}, { + 3.516912*^9, 5.02}, {3.5253792*^9, 5.07}, {3.5332416*^9, + 5.13}, {3.541104*^9, 5.18}, {3.5489664*^9, 5.23}, { + 3.5568288*^9, 5.27}, {3.5646912*^9, 5.33}, {3.5725536*^9, + 5.37}, {3.580416*^9, 5.41}, {3.5882784*^9, 5.45}, { + 3.5961408*^9, 5.5}, {3.6040032*^9, 5.53}, {3.6118656*^9, + 5.57}, {3.619728*^9, 5.61}, {3.6275904*^9, 5.66}, { + 3.6354528*^9, 5.68}, {3.6433152*^9, 5.71}, {3.6511776*^9, + 5.75}, {3.65904*^9, 5.78}, {3.6669024*^9, 5.8}, { + 3.6747648*^9, 5.83}, {3.683232*^9, 5.86}, {3.6910944*^9, + 5.89}, {3.698352*^9, 5.91}, {3.7068192*^9, 5.93}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"06 Sep 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 69-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.398976*^9, 5.56}, {3.4013952*^9, 5.28}, { + 3.4044192*^9, 4.98}, {3.4068384*^9, 4.74}, {3.4147008*^9, + 4.31}, {3.4225632*^9, 4.23}, {3.4304256*^9, 4.24}, { + 3.438288*^9, 4.29}, {3.4461504*^9, 4.36}, {3.4540128*^9, + 4.42}, {3.4618752*^9, 4.47}, {3.4697376*^9, 4.53}, { + 3.4776*^9, 4.57}, {3.4854624*^9, 4.62}, {3.4933248*^9, + 4.67}, {3.5011872*^9, 4.73}, {3.5090496*^9, 4.77}, { + 3.516912*^9, 4.83}, {3.5253792*^9, 4.87}, {3.5332416*^9, + 4.93}, {3.541104*^9, 4.98}, {3.5489664*^9, 5.03}, { + 3.5568288*^9, 5.08}, {3.5646912*^9, 5.14}, {3.5725536*^9, + 5.18}, {3.580416*^9, 5.23}, {3.5882784*^9, 5.28}, { + 3.5961408*^9, 5.33}, {3.6040032*^9, 5.36}, {3.6118656*^9, + 5.4}, {3.619728*^9, 5.45}, {3.6275904*^9, 5.5}, { + 3.6354528*^9, 5.53}, {3.6433152*^9, 5.56}, {3.6511776*^9, + 5.6}, {3.65904*^9, 5.64}, {3.6669024*^9, 5.66}, { + 3.6747648*^9, 5.69}, {3.683232*^9, 5.73}, {3.6910944*^9, + 5.77}, {3.698352*^9, 5.79}, {3.7068192*^9, 5.81}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"07 Sep 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 70-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.398976*^9, 5.62}, {3.4013952*^9, 5.33}, { + 3.4044192*^9, 5.01}, {3.4068384*^9, 4.78}, {3.4147008*^9, + 4.31}, {3.4225632*^9, 4.21}, {3.4304256*^9, 4.2}, { + 3.438288*^9, 4.24}, {3.4461504*^9, 4.29}, {3.4540128*^9, + 4.36}, {3.4618752*^9, 4.41}, {3.4697376*^9, 4.47}, { + 3.4776*^9, 4.51}, {3.4854624*^9, 4.56}, {3.4933248*^9, + 4.61}, {3.5011872*^9, 4.67}, {3.5090496*^9, 4.72}, { + 3.516912*^9, 4.77}, {3.5253792*^9, 4.82}, {3.5332416*^9, + 4.88}, {3.541104*^9, 4.92}, {3.5489664*^9, 4.98}, { + 3.5568288*^9, 5.03}, {3.5646912*^9, 5.08}, {3.5725536*^9, + 5.12}, {3.580416*^9, 5.17}, {3.5882784*^9, 5.22}, { + 3.5961408*^9, 5.27}, {3.6040032*^9, 5.3}, {3.6118656*^9, + 5.34}, {3.619728*^9, 5.39}, {3.6275904*^9, 5.44}, { + 3.6354528*^9, 5.47}, {3.6433152*^9, 5.5}, {3.6511776*^9, + 5.54}, {3.65904*^9, 5.58}, {3.6669024*^9, 5.61}, { + 3.6747648*^9, 5.64}, {3.683232*^9, 5.68}, {3.6910944*^9, + 5.72}, {3.698352*^9, 5.74}, {3.7068192*^9, 5.76}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"10 Sep 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 71-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.398976*^9, 5.66}, {3.4013952*^9, 5.43}, { + 3.4044192*^9, 5.12}, {3.4068384*^9, 4.93}, {3.4147008*^9, + 4.45}, {3.4225632*^9, 4.33}, {3.4304256*^9, 4.3}, { + 3.438288*^9, 4.31}, {3.4461504*^9, 4.36}, {3.4540128*^9, + 4.43}, {3.4618752*^9, 4.49}, {3.4697376*^9, 4.55}, { + 3.4776*^9, 4.59}, {3.4854624*^9, 4.64}, {3.4933248*^9, + 4.69}, {3.5011872*^9, 4.75}, {3.5090496*^9, 4.79}, { + 3.516912*^9, 4.84}, {3.5253792*^9, 4.89}, {3.5332416*^9, + 4.95}, {3.541104*^9, 4.99}, {3.5489664*^9, 5.05}, { + 3.5568288*^9, 5.1}, {3.5646912*^9, 5.15}, {3.5725536*^9, + 5.19}, {3.580416*^9, 5.24}, {3.5882784*^9, 5.29}, { + 3.5961408*^9, 5.35}, {3.6040032*^9, 5.38}, {3.6118656*^9, + 5.42}, {3.619728*^9, 5.47}, {3.6275904*^9, 5.52}, { + 3.6354528*^9, 5.55}, {3.6433152*^9, 5.58}, {3.6511776*^9, + 5.62}, {3.65904*^9, 5.66}, {3.6669024*^9, 5.69}, { + 3.6747648*^9, 5.72}, {3.683232*^9, 5.76}, {3.6910944*^9, + 5.8}, {3.698352*^9, 5.82}, {3.7068192*^9, 5.84}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"11 Sep 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 72-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.398976*^9, 5.68}, {3.4013952*^9, 5.48}, { + 3.4044192*^9, 5.18}, {3.4068384*^9, 4.97}, {3.4147008*^9, + 4.51}, {3.4225632*^9, 4.34}, {3.4304256*^9, 4.3}, { + 3.438288*^9, 4.31}, {3.4461504*^9, 4.36}, {3.4540128*^9, + 4.44}, {3.4618752*^9, 4.5}, {3.4697376*^9, 4.57}, { + 3.4776*^9, 4.61}, {3.4854624*^9, 4.67}, {3.4933248*^9, + 4.72}, {3.5011872*^9, 4.79}, {3.5090496*^9, 4.83}, { + 3.516912*^9, 4.89}, {3.5253792*^9, 4.94}, {3.5332416*^9, + 5.01}, {3.541104*^9, 5.06}, {3.5489664*^9, 5.11}, { + 3.5568288*^9, 5.17}, {3.5646912*^9, 5.23}, {3.5725536*^9, + 5.27}, {3.580416*^9, 5.31}, {3.5882784*^9, 5.37}, { + 3.5961408*^9, 5.43}, {3.6040032*^9, 5.46}, {3.6118656*^9, + 5.5}, {3.619728*^9, 5.55}, {3.6275904*^9, 5.6}, { + 3.6354528*^9, 5.63}, {3.6433152*^9, 5.66}, {3.6511776*^9, + 5.7}, {3.65904*^9, 5.74}, {3.6669024*^9, 5.77}, { + 3.6747648*^9, 5.8}, {3.683232*^9, 5.84}, {3.6910944*^9, + 5.88}, {3.698352*^9, 5.9}, {3.7068192*^9, 5.92}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"12 Sep 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 73-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.398976*^9, 5.63}, {3.4013952*^9, 5.4}, { + 3.4044192*^9, 5.13}, {3.4068384*^9, 4.94}, {3.4147008*^9, + 4.54}, {3.4225632*^9, 4.42}, {3.4304256*^9, 4.4}, { + 3.438288*^9, 4.42}, {3.4461504*^9, 4.47}, {3.4540128*^9, + 4.54}, {3.4618752*^9, 4.61}, {3.4697376*^9, 4.68}, { + 3.4776*^9, 4.73}, {3.4854624*^9, 4.78}, {3.4933248*^9, + 4.83}, {3.5011872*^9, 4.9}, {3.5090496*^9, 4.94}, { + 3.516912*^9, 5.}, {3.5253792*^9, 5.05}, {3.5332416*^9, + 5.11}, {3.541104*^9, 5.16}, {3.5489664*^9, 5.22}, { + 3.5568288*^9, 5.27}, {3.5646912*^9, 5.33}, {3.5725536*^9, + 5.37}, {3.580416*^9, 5.41}, {3.5882784*^9, 5.46}, { + 3.5961408*^9, 5.52}, {3.6040032*^9, 5.55}, {3.6118656*^9, + 5.59}, {3.619728*^9, 5.64}, {3.6275904*^9, 5.69}, { + 3.6354528*^9, 5.72}, {3.6433152*^9, 5.75}, {3.6511776*^9, + 5.79}, {3.65904*^9, 5.83}, {3.6669024*^9, 5.85}, { + 3.6747648*^9, 5.89}, {3.683232*^9, 5.92}, {3.6910944*^9, + 5.96}, {3.698352*^9, 5.98}, {3.7068192*^9, 6.01}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"13 Sep 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 74-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.398976*^9, 5.59}, {3.4013952*^9, 5.28}, { + 3.4044192*^9, 5.05}, {3.4068384*^9, 4.89}, {3.4147008*^9, + 4.52}, {3.4225632*^9, 4.4}, {3.4304256*^9, 4.36}, { + 3.438288*^9, 4.38}, {3.4461504*^9, 4.43}, {3.4540128*^9, + 4.51}, {3.4618752*^9, 4.59}, {3.4697376*^9, 4.66}, { + 3.4776*^9, 4.71}, {3.4854624*^9, 4.77}, {3.4933248*^9, + 4.83}, {3.5011872*^9, 4.89}, {3.5090496*^9, 4.94}, { + 3.516912*^9, 5.}, {3.5253792*^9, 5.05}, {3.5332416*^9, + 5.11}, {3.541104*^9, 5.16}, {3.5489664*^9, 5.22}, { + 3.5568288*^9, 5.27}, {3.5646912*^9, 5.33}, {3.5725536*^9, + 5.37}, {3.580416*^9, 5.41}, {3.5882784*^9, 5.46}, { + 3.5961408*^9, 5.52}, {3.6040032*^9, 5.55}, {3.6118656*^9, + 5.59}, {3.619728*^9, 5.64}, {3.6275904*^9, 5.69}, { + 3.6354528*^9, 5.72}, {3.6433152*^9, 5.75}, {3.6511776*^9, + 5.79}, {3.65904*^9, 5.83}, {3.6669024*^9, 5.85}, { + 3.6747648*^9, 5.89}, {3.683232*^9, 5.92}, {3.6910944*^9, + 5.96}, {3.698352*^9, 5.98}, {3.7068192*^9, 6.01}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"14 Sep 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 75-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.4013952*^9, 5.29}, {3.4044192*^9, 5.05}, { + 3.4068384*^9, 4.91}, {3.4147008*^9, 4.56}, {3.4225632*^9, + 4.43}, {3.4304256*^9, 4.39}, {3.438288*^9, 4.4}, { + 3.4461504*^9, 4.46}, {3.4540128*^9, 4.54}, {3.4618752*^9, + 4.62}, {3.4697376*^9, 4.7}, {3.4776*^9, 4.75}, { + 3.4854624*^9, 4.81}, {3.4933248*^9, 4.86}, {3.5011872*^9, + 4.93}, {3.5090496*^9, 4.97}, {3.516912*^9, 5.03}, { + 3.5253792*^9, 5.08}, {3.5332416*^9, 5.15}, {3.541104*^9, + 5.2}, {3.5489664*^9, 5.25}, {3.5568288*^9, 5.3}, { + 3.5646912*^9, 5.36}, {3.5725536*^9, 5.4}, {3.580416*^9, + 5.44}, {3.5882784*^9, 5.49}, {3.5961408*^9, 5.55}, { + 3.6040032*^9, 5.58}, {3.6118656*^9, 5.62}, {3.619728*^9, + 5.66}, {3.6275904*^9, 5.7}, {3.6354528*^9, 5.73}, { + 3.6433152*^9, 5.76}, {3.6511776*^9, 5.8}, {3.65904*^9, + 5.83}, {3.6669024*^9, 5.86}, {3.6747648*^9, 5.89}, { + 3.683232*^9, 5.92}, {3.6910944*^9, 5.96}, {3.698352*^9, + 5.98}, {3.7068192*^9, 6.}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"17 Sep 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 76-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.4013952*^9, 5.16}, {3.4044192*^9, 4.88}, { + 3.4068384*^9, 4.71}, {3.4147008*^9, 4.39}, {3.4225632*^9, + 4.28}, {3.4304256*^9, 4.26}, {3.438288*^9, 4.3}, { + 3.4461504*^9, 4.38}, {3.4540128*^9, 4.47}, {3.4618752*^9, + 4.56}, {3.4697376*^9, 4.65}, {3.4776*^9, 4.71}, { + 3.4854624*^9, 4.78}, {3.4933248*^9, 4.84}, {3.5011872*^9, + 4.91}, {3.5090496*^9, 4.96}, {3.516912*^9, 5.02}, { + 3.5253792*^9, 5.08}, {3.5332416*^9, 5.14}, {3.541104*^9, + 5.19}, {3.5489664*^9, 5.25}, {3.5568288*^9, 5.3}, { + 3.5646912*^9, 5.36}, {3.5725536*^9, 5.41}, {3.580416*^9, + 5.45}, {3.5882784*^9, 5.5}, {3.5961408*^9, 5.56}, { + 3.6040032*^9, 5.6}, {3.6118656*^9, 5.64}, {3.619728*^9, + 5.68}, {3.6275904*^9, 5.72}, {3.6354528*^9, 5.75}, { + 3.6433152*^9, 5.79}, {3.6511776*^9, 5.82}, {3.65904*^9, + 5.86}, {3.6669024*^9, 5.89}, {3.6747648*^9, 5.92}, { + 3.683232*^9, 5.95}, {3.6910944*^9, 5.99}, {3.698352*^9, + 6.02}, {3.7068192*^9, 6.04}, {3.7146816*^9, 6.08}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"18 Sep 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 77-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.4013952*^9, 5.06}, {3.4044192*^9, 4.82}, { + 3.4068384*^9, 4.65}, {3.4147008*^9, 4.37}, {3.4225632*^9, + 4.3}, {3.4304256*^9, 4.28}, {3.438288*^9, 4.32}, { + 3.4461504*^9, 4.39}, {3.4540128*^9, 4.48}, {3.4618752*^9, + 4.56}, {3.4697376*^9, 4.65}, {3.4776*^9, 4.71}, { + 3.4854624*^9, 4.78}, {3.4933248*^9, 4.85}, {3.5011872*^9, + 4.92}, {3.5090496*^9, 4.97}, {3.516912*^9, 5.03}, { + 3.5253792*^9, 5.09}, {3.5332416*^9, 5.15}, {3.541104*^9, + 5.2}, {3.5489664*^9, 5.26}, {3.5568288*^9, 5.31}, { + 3.5646912*^9, 5.37}, {3.5725536*^9, 5.42}, {3.580416*^9, + 5.46}, {3.5882784*^9, 5.51}, {3.5961408*^9, 5.57}, { + 3.6040032*^9, 5.61}, {3.6118656*^9, 5.65}, {3.619728*^9, + 5.69}, {3.6275904*^9, 5.74}, {3.6354528*^9, 5.77}, { + 3.6433152*^9, 5.8}, {3.6511776*^9, 5.84}, {3.65904*^9, + 5.88}, {3.6669024*^9, 5.91}, {3.6747648*^9, 5.94}, { + 3.683232*^9, 5.97}, {3.6910944*^9, 6.01}, {3.698352*^9, + 6.04}, {3.7068192*^9, 6.06}, {3.7146816*^9, 6.1}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"19 Sep 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 78-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.4013952*^9, 5.09}, {3.4044192*^9, 4.88}, { + 3.4068384*^9, 4.73}, {3.4147008*^9, 4.48}, {3.4225632*^9, + 4.43}, {3.4304256*^9, 4.43}, {3.438288*^9, 4.47}, { + 3.4461504*^9, 4.56}, {3.4540128*^9, 4.65}, {3.4618752*^9, + 4.74}, {3.4697376*^9, 4.83}, {3.4776*^9, 4.9}, { + 3.4854624*^9, 4.97}, {3.4933248*^9, 5.04}, {3.5011872*^9, + 5.12}, {3.5090496*^9, 5.17}, {3.516912*^9, 5.23}, { + 3.5253792*^9, 5.29}, {3.5332416*^9, 5.35}, {3.541104*^9, + 5.4}, {3.5489664*^9, 5.46}, {3.5568288*^9, 5.51}, { + 3.5646912*^9, 5.57}, {3.5725536*^9, 5.61}, {3.580416*^9, + 5.65}, {3.5882784*^9, 5.7}, {3.5961408*^9, 5.75}, { + 3.6040032*^9, 5.79}, {3.6118656*^9, 5.82}, {3.619728*^9, + 5.86}, {3.6275904*^9, 5.91}, {3.6354528*^9, 5.93}, { + 3.6433152*^9, 5.96}, {3.6511776*^9, 5.99}, {3.65904*^9, + 6.03}, {3.6669024*^9, 6.06}, {3.6747648*^9, 6.09}, { + 3.683232*^9, 6.12}, {3.6910944*^9, 6.16}, {3.698352*^9, + 6.18}, {3.7068192*^9, 6.2}, {3.7146816*^9, 6.23}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"20 Sep 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 79-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.4013952*^9, 5.1}, {3.4044192*^9, 4.89}, { + 3.4068384*^9, 4.74}, {3.4147008*^9, 4.47}, {3.4225632*^9, + 4.39}, {3.4304256*^9, 4.37}, {3.438288*^9, 4.41}, { + 3.4461504*^9, 4.51}, {3.4540128*^9, 4.62}, {3.4618752*^9, + 4.72}, {3.4697376*^9, 4.81}, {3.4776*^9, 4.87}, { + 3.4854624*^9, 4.95}, {3.4933248*^9, 5.02}, {3.5011872*^9, + 5.09}, {3.5090496*^9, 5.14}, {3.516912*^9, 5.2}, { + 3.5253792*^9, 5.26}, {3.5332416*^9, 5.32}, {3.541104*^9, + 5.36}, {3.5489664*^9, 5.42}, {3.5568288*^9, 5.47}, { + 3.5646912*^9, 5.53}, {3.5725536*^9, 5.57}, {3.580416*^9, + 5.61}, {3.5882784*^9, 5.66}, {3.5961408*^9, 5.71}, { + 3.6040032*^9, 5.75}, {3.6118656*^9, 5.78}, {3.619728*^9, + 5.82}, {3.6275904*^9, 5.87}, {3.6354528*^9, 5.89}, { + 3.6433152*^9, 5.92}, {3.6511776*^9, 5.95}, {3.65904*^9, + 5.99}, {3.6669024*^9, 6.02}, {3.6747648*^9, 6.05}, { + 3.683232*^9, 6.08}, {3.6910944*^9, 6.12}, {3.698352*^9, + 6.14}, {3.7068192*^9, 6.16}, {3.7146816*^9, 6.19}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"21 Sep 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 80-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.4013952*^9, 5.16}, {3.4044192*^9, 4.98}, { + 3.4068384*^9, 4.85}, {3.4147008*^9, 4.51}, {3.4225632*^9, + 4.4}, {3.4304256*^9, 4.37}, {3.438288*^9, 4.4}, { + 3.4461504*^9, 4.49}, {3.4540128*^9, 4.6}, {3.4618752*^9, + 4.7}, {3.4697376*^9, 4.79}, {3.4776*^9, 4.86}, { + 3.4854624*^9, 4.94}, {3.4933248*^9, 5.01}, {3.5011872*^9, + 5.09}, {3.5090496*^9, 5.14}, {3.516912*^9, 5.2}, { + 3.5253792*^9, 5.26}, {3.5332416*^9, 5.32}, {3.541104*^9, + 5.37}, {3.5489664*^9, 5.42}, {3.5568288*^9, 5.47}, { + 3.5646912*^9, 5.52}, {3.5725536*^9, 5.56}, {3.580416*^9, + 5.6}, {3.5882784*^9, 5.64}, {3.5961408*^9, 5.7}, { + 3.6040032*^9, 5.73}, {3.6118656*^9, 5.76}, {3.619728*^9, + 5.8}, {3.6275904*^9, 5.84}, {3.6354528*^9, 5.87}, { + 3.6433152*^9, 5.89}, {3.6511776*^9, 5.92}, {3.65904*^9, + 5.96}, {3.6669024*^9, 5.99}, {3.6747648*^9, 6.01}, { + 3.683232*^9, 6.04}, {3.6910944*^9, 6.08}, {3.698352*^9, + 6.1}, {3.7068192*^9, 6.12}, {3.7146816*^9, 6.16}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"24 Sep 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 81-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.4013952*^9, 5.2}, {3.4044192*^9, 5.02}, { + 3.4068384*^9, 4.87}, {3.4147008*^9, 4.5}, {3.4225632*^9, + 4.39}, {3.4304256*^9, 4.35}, {3.438288*^9, 4.37}, { + 3.4461504*^9, 4.45}, {3.4540128*^9, 4.57}, {3.4618752*^9, + 4.67}, {3.4697376*^9, 4.77}, {3.4776*^9, 4.85}, { + 3.4854624*^9, 4.93}, {3.4933248*^9, 5.}, {3.5011872*^9, + 5.08}, {3.5090496*^9, 5.13}, {3.516912*^9, 5.2}, { + 3.5253792*^9, 5.26}, {3.5332416*^9, 5.32}, {3.541104*^9, + 5.36}, {3.5489664*^9, 5.42}, {3.5568288*^9, 5.47}, { + 3.5646912*^9, 5.52}, {3.5725536*^9, 5.56}, {3.580416*^9, + 5.6}, {3.5882784*^9, 5.64}, {3.5961408*^9, 5.7}, { + 3.6040032*^9, 5.73}, {3.6118656*^9, 5.77}, {3.619728*^9, + 5.81}, {3.6275904*^9, 5.85}, {3.6354528*^9, 5.87}, { + 3.6433152*^9, 5.9}, {3.6511776*^9, 5.93}, {3.65904*^9, + 5.97}, {3.6669024*^9, 6.}, {3.6747648*^9, 6.03}, { + 3.683232*^9, 6.06}, {3.6910944*^9, 6.1}, {3.698352*^9, + 6.12}, {3.7068192*^9, 6.14}, {3.7146816*^9, 6.17}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"25 Sep 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 82-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.4013952*^9, 5.18}, {3.4044192*^9, 4.98}, { + 3.4068384*^9, 4.83}, {3.4147008*^9, 4.48}, {3.4225632*^9, + 4.36}, {3.4304256*^9, 4.31}, {3.438288*^9, 4.34}, { + 3.4461504*^9, 4.42}, {3.4540128*^9, 4.53}, {3.4618752*^9, + 4.64}, {3.4697376*^9, 4.74}, {3.4776*^9, 4.82}, { + 3.4854624*^9, 4.91}, {3.4933248*^9, 4.98}, {3.5011872*^9, + 5.06}, {3.5090496*^9, 5.12}, {3.516912*^9, 5.19}, { + 3.5253792*^9, 5.25}, {3.5332416*^9, 5.32}, {3.541104*^9, + 5.37}, {3.5489664*^9, 5.42}, {3.5568288*^9, 5.48}, { + 3.5646912*^9, 5.54}, {3.5725536*^9, 5.57}, {3.580416*^9, + 5.62}, {3.5882784*^9, 5.66}, {3.5961408*^9, 5.72}, { + 3.6040032*^9, 5.75}, {3.6118656*^9, 5.79}, {3.619728*^9, + 5.83}, {3.6275904*^9, 5.87}, {3.6354528*^9, 5.9}, { + 3.6433152*^9, 5.93}, {3.6511776*^9, 5.96}, {3.65904*^9, + 6.}, {3.6669024*^9, 6.02}, {3.6747648*^9, 6.05}, { + 3.683232*^9, 6.08}, {3.6910944*^9, 6.12}, {3.698352*^9, + 6.15}, {3.7068192*^9, 6.17}, {3.7146816*^9, 6.2}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"26 Sep 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 83-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.4013952*^9, 5.16}, {3.4044192*^9, 4.95}, { + 3.4068384*^9, 4.8}, {3.4147008*^9, 4.45}, {3.4225632*^9, + 4.31}, {3.4304256*^9, 4.25}, {3.438288*^9, 4.27}, { + 3.4461504*^9, 4.34}, {3.4540128*^9, 4.46}, {3.4618752*^9, + 4.57}, {3.4697376*^9, 4.67}, {3.4776*^9, 4.76}, { + 3.4854624*^9, 4.84}, {3.4933248*^9, 4.92}, {3.5011872*^9, + 5.}, {3.5090496*^9, 5.06}, {3.516912*^9, 5.12}, { + 3.5253792*^9, 5.19}, {3.5332416*^9, 5.25}, {3.541104*^9, + 5.3}, {3.5489664*^9, 5.36}, {3.5568288*^9, 5.41}, { + 3.5646912*^9, 5.47}, {3.5725536*^9, 5.51}, {3.580416*^9, + 5.55}, {3.5882784*^9, 5.6}, {3.5961408*^9, 5.65}, { + 3.6040032*^9, 5.69}, {3.6118656*^9, 5.72}, {3.619728*^9, + 5.76}, {3.6275904*^9, 5.8}, {3.6354528*^9, 5.83}, { + 3.6433152*^9, 5.86}, {3.6511776*^9, 5.89}, {3.65904*^9, + 5.93}, {3.6669024*^9, 5.95}, {3.6747648*^9, 5.98}, { + 3.683232*^9, 6.01}, {3.6910944*^9, 6.05}, {3.698352*^9, + 6.07}, {3.7068192*^9, 6.09}, {3.7146816*^9, 6.12}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"27 Sep 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 84-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.4013952*^9, 5.17}, {3.4044192*^9, 4.97}, { + 3.4068384*^9, 4.84}, {3.4147008*^9, 4.52}, {3.4225632*^9, + 4.37}, {3.4304256*^9, 4.31}, {3.438288*^9, 4.31}, { + 3.4461504*^9, 4.38}, {3.4540128*^9, 4.5}, {3.4618752*^9, + 4.6}, {3.4697376*^9, 4.7}, {3.4776*^9, 4.77}, { + 3.4854624*^9, 4.84}, {3.4933248*^9, 4.91}, {3.5011872*^9, + 4.99}, {3.5090496*^9, 5.05}, {3.516912*^9, 5.12}, { + 3.5253792*^9, 5.18}, {3.5332416*^9, 5.24}, {3.541104*^9, + 5.29}, {3.5489664*^9, 5.34}, {3.5568288*^9, 5.4}, { + 3.5646912*^9, 5.46}, {3.5725536*^9, 5.49}, {3.580416*^9, + 5.54}, {3.5882784*^9, 5.58}, {3.5961408*^9, 5.64}, { + 3.6040032*^9, 5.67}, {3.6118656*^9, 5.71}, {3.619728*^9, + 5.74}, {3.6275904*^9, 5.79}, {3.6354528*^9, 5.81}, { + 3.6433152*^9, 5.84}, {3.6511776*^9, 5.87}, {3.65904*^9, + 5.91}, {3.6669024*^9, 5.94}, {3.6747648*^9, 5.97}, { + 3.683232*^9, 6.}, {3.6910944*^9, 6.04}, {3.698352*^9, + 6.06}, {3.7068192*^9, 6.08}, {3.7146816*^9, 6.11}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"28 Sep 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 85-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.4013952*^9, 5.2}, {3.4044192*^9, 5.04}, { + 3.4068384*^9, 4.89}, {3.4147008*^9, 4.58}, {3.4225632*^9, + 4.42}, {3.4304256*^9, 4.35}, {3.438288*^9, 4.36}, { + 3.4461504*^9, 4.43}, {3.4540128*^9, 4.54}, {3.4618752*^9, + 4.64}, {3.4697376*^9, 4.73}, {3.4776*^9, 4.8}, { + 3.4854624*^9, 4.86}, {3.4933248*^9, 4.93}, {3.5011872*^9, + 5.}, {3.5090496*^9, 5.06}, {3.516912*^9, 5.12}, { + 3.5253792*^9, 5.17}, {3.5332416*^9, 5.23}, {3.541104*^9, + 5.27}, {3.5489664*^9, 5.33}, {3.5568288*^9, 5.38}, { + 3.5646912*^9, 5.43}, {3.5725536*^9, 5.47}, {3.580416*^9, + 5.51}, {3.5882784*^9, 5.55}, {3.5961408*^9, 5.6}, { + 3.6040032*^9, 5.63}, {3.6118656*^9, 5.67}, {3.619728*^9, + 5.7}, {3.6275904*^9, 5.74}, {3.6354528*^9, 5.76}, { + 3.6433152*^9, 5.79}, {3.6511776*^9, 5.82}, {3.65904*^9, + 5.85}, {3.6669024*^9, 5.87}, {3.6747648*^9, 5.9}, { + 3.683232*^9, 5.93}, {3.6910944*^9, 5.96}, {3.698352*^9, + 5.98}, {3.7068192*^9, 6.}, {3.7146816*^9, 6.03}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"01 Oct 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 86-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.4013952*^9, 5.22}, {3.4044192*^9, 5.05}, { + 3.4068384*^9, 4.92}, {3.4147008*^9, 4.58}, {3.4225632*^9, + 4.4}, {3.4304256*^9, 4.31}, {3.438288*^9, 4.31}, { + 3.4461504*^9, 4.38}, {3.4540128*^9, 4.48}, {3.4618752*^9, + 4.58}, {3.4697376*^9, 4.67}, {3.4776*^9, 4.73}, { + 3.4854624*^9, 4.8}, {3.4933248*^9, 4.87}, {3.5011872*^9, + 4.95}, {3.5090496*^9, 5.}, {3.516912*^9, 5.06}, { + 3.5253792*^9, 5.12}, {3.5332416*^9, 5.18}, {3.541104*^9, + 5.23}, {3.5489664*^9, 5.28}, {3.5568288*^9, 5.33}, { + 3.5646912*^9, 5.39}, {3.5725536*^9, 5.42}, {3.580416*^9, + 5.46}, {3.5882784*^9, 5.51}, {3.5961408*^9, 5.55}, { + 3.6040032*^9, 5.58}, {3.6118656*^9, 5.62}, {3.619728*^9, + 5.65}, {3.6275904*^9, 5.69}, {3.6354528*^9, 5.71}, { + 3.6433152*^9, 5.74}, {3.6511776*^9, 5.77}, {3.65904*^9, + 5.8}, {3.6669024*^9, 5.82}, {3.6747648*^9, 5.85}, { + 3.683232*^9, 5.88}, {3.6910944*^9, 5.91}, {3.698352*^9, + 5.93}, {3.7068192*^9, 5.95}, {3.7146816*^9, 5.98}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"02 Oct 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 87-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.4013952*^9, 5.22}, {3.4044192*^9, 5.08}, { + 3.4068384*^9, 4.95}, {3.4147008*^9, 4.62}, {3.4225632*^9, + 4.44}, {3.4304256*^9, 4.36}, {3.438288*^9, 4.36}, { + 3.4461504*^9, 4.42}, {3.4540128*^9, 4.52}, {3.4618752*^9, + 4.61}, {3.4697376*^9, 4.69}, {3.4776*^9, 4.76}, { + 3.4854624*^9, 4.83}, {3.4933248*^9, 4.89}, {3.5011872*^9, + 4.96}, {3.5090496*^9, 5.01}, {3.516912*^9, 5.07}, { + 3.5253792*^9, 5.13}, {3.5332416*^9, 5.19}, {3.541104*^9, + 5.23}, {3.5489664*^9, 5.28}, {3.5568288*^9, 5.32}, { + 3.5646912*^9, 5.37}, {3.5725536*^9, 5.41}, {3.580416*^9, + 5.45}, {3.5882784*^9, 5.49}, {3.5961408*^9, 5.53}, { + 3.6040032*^9, 5.56}, {3.6118656*^9, 5.59}, {3.619728*^9, + 5.62}, {3.6275904*^9, 5.66}, {3.6354528*^9, 5.68}, { + 3.6433152*^9, 5.71}, {3.6511776*^9, 5.74}, {3.65904*^9, + 5.77}, {3.6669024*^9, 5.79}, {3.6747648*^9, 5.82}, { + 3.683232*^9, 5.85}, {3.6910944*^9, 5.88}, {3.698352*^9, + 5.9}, {3.7068192*^9, 5.92}, {3.7146816*^9, 5.95}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"03 Oct 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 88-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.4013952*^9, 5.22}, {3.4044192*^9, 5.07}, { + 3.4068384*^9, 4.95}, {3.4147008*^9, 4.62}, {3.4225632*^9, + 4.44}, {3.4304256*^9, 4.36}, {3.438288*^9, 4.35}, { + 3.4461504*^9, 4.4}, {3.4540128*^9, 4.5}, {3.4618752*^9, + 4.6}, {3.4697376*^9, 4.69}, {3.4776*^9, 4.76}, { + 3.4854624*^9, 4.83}, {3.4933248*^9, 4.89}, {3.5011872*^9, + 4.96}, {3.5090496*^9, 5.01}, {3.516912*^9, 5.07}, { + 3.5253792*^9, 5.12}, {3.5332416*^9, 5.18}, {3.541104*^9, + 5.22}, {3.5489664*^9, 5.27}, {3.5568288*^9, 5.31}, { + 3.5646912*^9, 5.36}, {3.5725536*^9, 5.39}, {3.580416*^9, + 5.42}, {3.5882784*^9, 5.46}, {3.5961408*^9, 5.5}, { + 3.6040032*^9, 5.53}, {3.6118656*^9, 5.56}, {3.619728*^9, + 5.59}, {3.6275904*^9, 5.63}, {3.6354528*^9, 5.65}, { + 3.6433152*^9, 5.68}, {3.6511776*^9, 5.71}, {3.65904*^9, + 5.74}, {3.6669024*^9, 5.76}, {3.6747648*^9, 5.79}, { + 3.683232*^9, 5.82}, {3.6910944*^9, 5.85}, {3.698352*^9, + 5.87}, {3.7068192*^9, 5.89}, {3.7146816*^9, 5.92}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"04 Oct 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 89-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.4013952*^9, 5.24}, {3.4044192*^9, 5.13}, { + 3.4068384*^9, 5.02}, {3.4147008*^9, 4.73}, {3.4225632*^9, + 4.57}, {3.4304256*^9, 4.48}, {3.438288*^9, 4.47}, { + 3.4461504*^9, 4.52}, {3.4540128*^9, 4.62}, {3.4618752*^9, + 4.72}, {3.4697376*^9, 4.82}, {3.4776*^9, 4.9}, { + 3.4854624*^9, 4.97}, {3.4933248*^9, 5.03}, {3.5011872*^9, + 5.11}, {3.5090496*^9, 5.16}, {3.516912*^9, 5.21}, { + 3.5253792*^9, 5.27}, {3.5332416*^9, 5.33}, {3.541104*^9, + 5.37}, {3.5489664*^9, 5.42}, {3.5568288*^9, 5.47}, { + 3.5646912*^9, 5.51}, {3.5725536*^9, 5.55}, {3.580416*^9, + 5.58}, {3.5882784*^9, 5.62}, {3.5961408*^9, 5.66}, { + 3.6040032*^9, 5.69}, {3.6118656*^9, 5.72}, {3.619728*^9, + 5.75}, {3.6275904*^9, 5.79}, {3.6354528*^9, 5.81}, { + 3.6433152*^9, 5.84}, {3.6511776*^9, 5.87}, {3.65904*^9, + 5.9}, {3.6669024*^9, 5.92}, {3.6747648*^9, 5.95}, { + 3.683232*^9, 5.98}, {3.6910944*^9, 6.01}, {3.698352*^9, + 6.03}, {3.7068192*^9, 6.05}, {3.7146816*^9, 6.08}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"05 Oct 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 90-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.4013952*^9, 5.24}, {3.4044192*^9, 5.13}, { + 3.4068384*^9, 5.02}, {3.4147008*^9, 4.73}, {3.4225632*^9, + 4.57}, {3.4304256*^9, 4.48}, {3.438288*^9, 4.47}, { + 3.4461504*^9, 4.52}, {3.4540128*^9, 4.62}, {3.4618752*^9, + 4.72}, {3.4697376*^9, 4.82}, {3.4776*^9, 4.9}, { + 3.4854624*^9, 4.97}, {3.4933248*^9, 5.03}, {3.5011872*^9, + 5.11}, {3.5090496*^9, 5.16}, {3.516912*^9, 5.21}, { + 3.5253792*^9, 5.27}, {3.5332416*^9, 5.33}, {3.541104*^9, + 5.37}, {3.5489664*^9, 5.42}, {3.5568288*^9, 5.47}, { + 3.5646912*^9, 5.51}, {3.5725536*^9, 5.55}, {3.580416*^9, + 5.58}, {3.5882784*^9, 5.62}, {3.5961408*^9, 5.66}, { + 3.6040032*^9, 5.69}, {3.6118656*^9, 5.72}, {3.619728*^9, + 5.75}, {3.6275904*^9, 5.79}, {3.6354528*^9, 5.81}, { + 3.6433152*^9, 5.84}, {3.6511776*^9, 5.87}, {3.65904*^9, + 5.9}, {3.6669024*^9, 5.92}, {3.6747648*^9, 5.95}, { + 3.683232*^9, 5.98}, {3.6910944*^9, 6.01}, {3.698352*^9, + 6.03}, {3.7068192*^9, 6.05}, {3.7146816*^9, 6.08}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"08 Oct 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 91-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.4013952*^9, 5.24}, {3.4044192*^9, 5.15}, { + 3.4068384*^9, 5.05}, {3.4147008*^9, 4.79}, {3.4225632*^9, + 4.62}, {3.4304256*^9, 4.54}, {3.438288*^9, 4.53}, { + 3.4461504*^9, 4.57}, {3.4540128*^9, 4.66}, {3.4618752*^9, + 4.76}, {3.4697376*^9, 4.85}, {3.4776*^9, 4.92}, { + 3.4854624*^9, 4.99}, {3.4933248*^9, 5.05}, {3.5011872*^9, + 5.12}, {3.5090496*^9, 5.17}, {3.516912*^9, 5.22}, { + 3.5253792*^9, 5.27}, {3.5332416*^9, 5.32}, {3.541104*^9, + 5.37}, {3.5489664*^9, 5.41}, {3.5568288*^9, 5.46}, { + 3.5646912*^9, 5.5}, {3.5725536*^9, 5.53}, {3.580416*^9, + 5.57}, {3.5882784*^9, 5.6}, {3.5961408*^9, 5.64}, { + 3.6040032*^9, 5.67}, {3.6118656*^9, 5.7}, {3.619728*^9, + 5.72}, {3.6275904*^9, 5.76}, {3.6354528*^9, 5.78}, { + 3.6433152*^9, 5.8}, {3.6511776*^9, 5.83}, {3.65904*^9, + 5.86}, {3.6669024*^9, 5.88}, {3.6747648*^9, 5.9}, { + 3.683232*^9, 5.93}, {3.6910944*^9, 5.96}, {3.698352*^9, + 5.97}, {3.7068192*^9, 5.99}, {3.7146816*^9, 6.01}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"09 Oct 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 92-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.4013952*^9, 5.23}, {3.4044192*^9, 5.13}, { + 3.4068384*^9, 5.05}, {3.4147008*^9, 4.79}, {3.4225632*^9, + 4.62}, {3.4304256*^9, 4.54}, {3.438288*^9, 4.53}, { + 3.4461504*^9, 4.57}, {3.4540128*^9, 4.66}, {3.4618752*^9, + 4.75}, {3.4697376*^9, 4.84}, {3.4776*^9, 4.91}, { + 3.4854624*^9, 4.98}, {3.4933248*^9, 5.04}, {3.5011872*^9, + 5.1}, {3.5090496*^9, 5.15}, {3.516912*^9, 5.2}, { + 3.5253792*^9, 5.25}, {3.5332416*^9, 5.31}, {3.541104*^9, + 5.35}, {3.5489664*^9, 5.4}, {3.5568288*^9, 5.44}, { + 3.5646912*^9, 5.48}, {3.5725536*^9, 5.51}, {3.580416*^9, + 5.55}, {3.5882784*^9, 5.58}, {3.5961408*^9, 5.62}, { + 3.6040032*^9, 5.65}, {3.6118656*^9, 5.68}, {3.619728*^9, + 5.7}, {3.6275904*^9, 5.73}, {3.6354528*^9, 5.75}, { + 3.6433152*^9, 5.78}, {3.6511776*^9, 5.8}, {3.65904*^9, + 5.83}, {3.6669024*^9, 5.85}, {3.6747648*^9, 5.88}, { + 3.683232*^9, 5.9}, {3.6910944*^9, 5.93}, {3.698352*^9, + 5.95}, {3.7068192*^9, 5.96}, {3.7146816*^9, 5.98}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"10 Oct 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 93-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.4013952*^9, 5.2}, {3.4044192*^9, 5.06}, { + 3.4068384*^9, 4.96}, {3.4147008*^9, 4.7}, {3.4225632*^9, + 4.55}, {3.4304256*^9, 4.49}, {3.438288*^9, 4.5}, { + 3.4461504*^9, 4.56}, {3.4540128*^9, 4.66}, {3.4618752*^9, + 4.75}, {3.4697376*^9, 4.84}, {3.4776*^9, 4.91}, { + 3.4854624*^9, 4.97}, {3.4933248*^9, 5.03}, {3.5011872*^9, + 5.1}, {3.5090496*^9, 5.14}, {3.516912*^9, 5.19}, { + 3.5253792*^9, 5.24}, {3.5332416*^9, 5.3}, {3.541104*^9, + 5.34}, {3.5489664*^9, 5.38}, {3.5568288*^9, 5.42}, { + 3.5646912*^9, 5.46}, {3.5725536*^9, 5.49}, {3.580416*^9, + 5.53}, {3.5882784*^9, 5.56}, {3.5961408*^9, 5.6}, { + 3.6040032*^9, 5.63}, {3.6118656*^9, 5.66}, {3.619728*^9, + 5.68}, {3.6275904*^9, 5.71}, {3.6354528*^9, 5.73}, { + 3.6433152*^9, 5.76}, {3.6511776*^9, 5.78}, {3.65904*^9, + 5.81}, {3.6669024*^9, 5.83}, {3.6747648*^9, 5.86}, { + 3.683232*^9, 5.88}, {3.6910944*^9, 5.91}, {3.698352*^9, + 5.93}, {3.7068192*^9, 5.94}, {3.7146816*^9, 5.96}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"11 Oct 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 94-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.4013952*^9, 5.21}, {3.4044192*^9, 5.06}, { + 3.4068384*^9, 4.96}, {3.4092576*^9, 4.84}, {3.4147008*^9, + 4.76}, {3.4225632*^9, 4.63}, {3.4304256*^9, 4.57}, { + 3.438288*^9, 4.58}, {3.4461504*^9, 4.64}, {3.4540128*^9, + 4.73}, {3.4618752*^9, 4.81}, {3.4697376*^9, 4.89}, { + 3.4776*^9, 4.95}, {3.4854624*^9, 5.01}, {3.4933248*^9, + 5.07}, {3.5011872*^9, 5.14}, {3.5090496*^9, 5.18}, { + 3.516912*^9, 5.23}, {3.5253792*^9, 5.28}, {3.5332416*^9, + 5.33}, {3.541104*^9, 5.37}, {3.5489664*^9, 5.41}, { + 3.5568288*^9, 5.45}, {3.5646912*^9, 5.49}, {3.5725536*^9, + 5.52}, {3.580416*^9, 5.55}, {3.5882784*^9, 5.58}, { + 3.5961408*^9, 5.62}, {3.6040032*^9, 5.65}, {3.6118656*^9, + 5.68}, {3.619728*^9, 5.7}, {3.6275904*^9, 5.73}, { + 3.6354528*^9, 5.75}, {3.6433152*^9, 5.78}, {3.6511776*^9, + 5.8}, {3.65904*^9, 5.83}, {3.6669024*^9, 5.85}, { + 3.6747648*^9, 5.87}, {3.683232*^9, 5.9}, {3.6910944*^9, + 5.93}, {3.698352*^9, 5.94}, {3.7068192*^9, 5.96}, { + 3.7146816*^9, 5.97}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"12 Oct 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 95-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.4044192*^9, 5.05}, {3.4068384*^9, 4.95}, { + 3.4092576*^9, 4.84}, {3.4147008*^9, 4.75}, {3.4225632*^9, + 4.61}, {3.4304256*^9, 4.54}, {3.438288*^9, 4.55}, { + 3.4461504*^9, 4.61}, {3.4540128*^9, 4.7}, {3.4618752*^9, + 4.79}, {3.4697376*^9, 4.87}, {3.4776*^9, 4.93}, { + 3.4854624*^9, 5.}, {3.4933248*^9, 5.06}, {3.5011872*^9, + 5.12}, {3.5090496*^9, 5.17}, {3.516912*^9, 5.22}, { + 3.5253792*^9, 5.27}, {3.5332416*^9, 5.32}, {3.541104*^9, + 5.36}, {3.5489664*^9, 5.4}, {3.5568288*^9, 5.44}, { + 3.5646912*^9, 5.49}, {3.5725536*^9, 5.52}, {3.580416*^9, + 5.55}, {3.5882784*^9, 5.59}, {3.5961408*^9, 5.63}, { + 3.6040032*^9, 5.65}, {3.6118656*^9, 5.68}, {3.619728*^9, + 5.71}, {3.6275904*^9, 5.74}, {3.6354528*^9, 5.76}, { + 3.6433152*^9, 5.79}, {3.6511776*^9, 5.81}, {3.65904*^9, + 5.84}, {3.6669024*^9, 5.86}, {3.6747648*^9, 5.88}, { + 3.683232*^9, 5.91}, {3.6910944*^9, 5.94}, {3.698352*^9, + 5.96}, {3.7068192*^9, 5.97}, {3.7146816*^9, 5.99}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"15 Oct 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 96-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.4044192*^9, 5.04}, {3.4068384*^9, 4.92}, { + 3.4092576*^9, 4.81}, {3.4147008*^9, 4.68}, {3.4225632*^9, + 4.54}, {3.4304256*^9, 4.47}, {3.438288*^9, 4.48}, { + 3.4461504*^9, 4.54}, {3.4540128*^9, 4.64}, {3.4618752*^9, + 4.73}, {3.4697376*^9, 4.82}, {3.4776*^9, 4.88}, { + 3.4854624*^9, 4.95}, {3.4933248*^9, 5.01}, {3.5011872*^9, + 5.08}, {3.5090496*^9, 5.12}, {3.516912*^9, 5.18}, { + 3.5253792*^9, 5.23}, {3.5332416*^9, 5.29}, {3.541104*^9, + 5.33}, {3.5489664*^9, 5.37}, {3.5568288*^9, 5.41}, { + 3.5646912*^9, 5.46}, {3.5725536*^9, 5.5}, {3.580416*^9, + 5.54}, {3.5882784*^9, 5.57}, {3.5961408*^9, 5.61}, { + 3.6040032*^9, 5.64}, {3.6118656*^9, 5.67}, {3.619728*^9, + 5.7}, {3.6275904*^9, 5.74}, {3.6354528*^9, 5.77}, { + 3.6433152*^9, 5.79}, {3.6511776*^9, 5.82}, {3.65904*^9, + 5.85}, {3.6669024*^9, 5.87}, {3.6747648*^9, 5.9}, { + 3.683232*^9, 5.92}, {3.6910944*^9, 5.96}, {3.698352*^9, + 5.97}, {3.7068192*^9, 5.99}, {3.7146816*^9, 6.}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"16 Oct 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 97-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.4044192*^9, 5.01}, {3.4068384*^9, 4.87}, { + 3.4092576*^9, 4.73}, {3.4147008*^9, 4.57}, {3.4225632*^9, + 4.41}, {3.4304256*^9, 4.34}, {3.438288*^9, 4.35}, { + 3.4461504*^9, 4.41}, {3.4540128*^9, 4.51}, {3.4618752*^9, + 4.61}, {3.4697376*^9, 4.7}, {3.4776*^9, 4.77}, { + 3.4854624*^9, 4.84}, {3.4933248*^9, 4.91}, {3.5011872*^9, + 4.98}, {3.5090496*^9, 5.02}, {3.516912*^9, 5.08}, { + 3.5253792*^9, 5.14}, {3.5332416*^9, 5.19}, {3.541104*^9, + 5.24}, {3.5489664*^9, 5.28}, {3.5568288*^9, 5.33}, { + 3.5646912*^9, 5.38}, {3.5725536*^9, 5.42}, {3.580416*^9, + 5.46}, {3.5882784*^9, 5.5}, {3.5961408*^9, 5.54}, { + 3.6040032*^9, 5.57}, {3.6118656*^9, 5.6}, {3.619728*^9, + 5.63}, {3.6275904*^9, 5.67}, {3.6354528*^9, 5.7}, { + 3.6433152*^9, 5.72}, {3.6511776*^9, 5.75}, {3.65904*^9, + 5.78}, {3.6669024*^9, 5.8}, {3.6747648*^9, 5.83}, { + 3.683232*^9, 5.85}, {3.6910944*^9, 5.89}, {3.698352*^9, + 5.9}, {3.7068192*^9, 5.92}, {3.7146816*^9, 5.93}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"17 Oct 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 98-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.4044192*^9, 4.96}, {3.4068384*^9, 4.81}, { + 3.4092576*^9, 4.68}, {3.4147008*^9, 4.52}, {3.4225632*^9, + 4.36}, {3.4304256*^9, 4.28}, {3.438288*^9, 4.29}, { + 3.4461504*^9, 4.36}, {3.4540128*^9, 4.46}, {3.4618752*^9, + 4.56}, {3.4697376*^9, 4.65}, {3.4776*^9, 4.72}, { + 3.4854624*^9, 4.8}, {3.4933248*^9, 4.86}, {3.5011872*^9, + 4.93}, {3.5090496*^9, 4.98}, {3.516912*^9, 5.04}, { + 3.5253792*^9, 5.1}, {3.5332416*^9, 5.16}, {3.541104*^9, + 5.2}, {3.5489664*^9, 5.25}, {3.5568288*^9, 5.29}, { + 3.5646912*^9, 5.35}, {3.5725536*^9, 5.38}, {3.580416*^9, + 5.43}, {3.5882784*^9, 5.47}, {3.5961408*^9, 5.52}, { + 3.6040032*^9, 5.54}, {3.6118656*^9, 5.58}, {3.619728*^9, + 5.61}, {3.6275904*^9, 5.65}, {3.6354528*^9, 5.68}, { + 3.6433152*^9, 5.71}, {3.6511776*^9, 5.73}, {3.65904*^9, + 5.77}, {3.6669024*^9, 5.79}, {3.6747648*^9, 5.82}, { + 3.683232*^9, 5.84}, {3.6910944*^9, 5.88}, {3.698352*^9, + 5.89}, {3.7068192*^9, 5.91}, {3.7146816*^9, 5.92}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"18 Oct 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 99-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.4044192*^9, 4.88}, {3.4068384*^9, 4.7}, { + 3.4092576*^9, 4.56}, {3.4147008*^9, 4.4}, {3.4225632*^9, + 4.24}, {3.4304256*^9, 4.16}, {3.438288*^9, 4.17}, { + 3.4461504*^9, 4.24}, {3.4540128*^9, 4.35}, {3.4618752*^9, + 4.45}, {3.4697376*^9, 4.54}, {3.4776*^9, 4.61}, { + 3.4854624*^9, 4.68}, {3.4933248*^9, 4.75}, {3.5011872*^9, + 4.82}, {3.5090496*^9, 4.87}, {3.516912*^9, 4.93}, { + 3.5253792*^9, 4.98}, {3.5332416*^9, 5.04}, {3.541104*^9, + 5.09}, {3.5489664*^9, 5.14}, {3.5568288*^9, 5.18}, { + 3.5646912*^9, 5.24}, {3.5725536*^9, 5.27}, {3.580416*^9, + 5.32}, {3.5882784*^9, 5.36}, {3.5961408*^9, 5.41}, { + 3.6040032*^9, 5.44}, {3.6118656*^9, 5.47}, {3.619728*^9, + 5.51}, {3.6275904*^9, 5.55}, {3.6354528*^9, 5.57}, { + 3.6433152*^9, 5.6}, {3.6511776*^9, 5.63}, {3.65904*^9, + 5.66}, {3.6669024*^9, 5.68}, {3.6747648*^9, 5.71}, { + 3.683232*^9, 5.74}, {3.6910944*^9, 5.77}, {3.698352*^9, + 5.79}, {3.7068192*^9, 5.8}, {3.7146816*^9, 5.82}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"19 Oct 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 100-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.4044192*^9, 4.88}, {3.4068384*^9, 4.71}, { + 3.4092576*^9, 4.57}, {3.4147008*^9, 4.41}, {3.4225632*^9, + 4.26}, {3.4304256*^9, 4.17}, {3.438288*^9, 4.17}, { + 3.4461504*^9, 4.24}, {3.4540128*^9, 4.34}, {3.4618752*^9, + 4.44}, {3.4697376*^9, 4.53}, {3.4776*^9, 4.61}, { + 3.4854624*^9, 4.68}, {3.4933248*^9, 4.75}, {3.5011872*^9, + 4.82}, {3.5090496*^9, 4.88}, {3.516912*^9, 4.94}, { + 3.5253792*^9, 4.99}, {3.5332416*^9, 5.05}, {3.541104*^9, + 5.1}, {3.5489664*^9, 5.15}, {3.5568288*^9, 5.19}, { + 3.5646912*^9, 5.24}, {3.5725536*^9, 5.28}, {3.580416*^9, + 5.32}, {3.5882784*^9, 5.36}, {3.5961408*^9, 5.41}, { + 3.6040032*^9, 5.44}, {3.6118656*^9, 5.47}, {3.619728*^9, + 5.51}, {3.6275904*^9, 5.55}, {3.6354528*^9, 5.57}, { + 3.6433152*^9, 5.6}, {3.6511776*^9, 5.63}, {3.65904*^9, + 5.66}, {3.6669024*^9, 5.68}, {3.6747648*^9, 5.71}, { + 3.683232*^9, 5.74}, {3.6910944*^9, 5.77}, {3.698352*^9, + 5.79}, {3.7068192*^9, 5.8}, {3.7146816*^9, 5.82}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"22 Oct 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 101-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.4044192*^9, 4.87}, {3.4068384*^9, 4.71}, { + 3.4092576*^9, 4.57}, {3.4147008*^9, 4.41}, {3.4225632*^9, + 4.26}, {3.4304256*^9, 4.16}, {3.438288*^9, 4.15}, { + 3.4461504*^9, 4.21}, {3.4540128*^9, 4.31}, {3.4618752*^9, + 4.41}, {3.4697376*^9, 4.51}, {3.4776*^9, 4.59}, { + 3.4854624*^9, 4.66}, {3.4933248*^9, 4.74}, {3.5011872*^9, + 4.81}, {3.5090496*^9, 4.87}, {3.516912*^9, 4.93}, { + 3.5253792*^9, 4.99}, {3.5332416*^9, 5.05}, {3.541104*^9, + 5.1}, {3.5489664*^9, 5.15}, {3.5568288*^9, 5.2}, { + 3.5646912*^9, 5.25}, {3.5725536*^9, 5.29}, {3.580416*^9, + 5.33}, {3.5882784*^9, 5.37}, {3.5961408*^9, 5.42}, { + 3.6040032*^9, 5.45}, {3.6118656*^9, 5.48}, {3.619728*^9, + 5.52}, {3.6275904*^9, 5.56}, {3.6354528*^9, 5.58}, { + 3.6433152*^9, 5.61}, {3.6511776*^9, 5.64}, {3.65904*^9, + 5.67}, {3.6669024*^9, 5.69}, {3.6747648*^9, 5.72}, { + 3.683232*^9, 5.75}, {3.6910944*^9, 5.78}, {3.698352*^9, + 5.8}, {3.7068192*^9, 5.81}, {3.7146816*^9, 5.83}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"23 Oct 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 102-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.4044192*^9, 4.8}, {3.4068384*^9, 4.63}, { + 3.4092576*^9, 4.48}, {3.4147008*^9, 4.31}, {3.4225632*^9, + 4.15}, {3.4304256*^9, 4.06}, {3.438288*^9, 4.05}, { + 3.4461504*^9, 4.11}, {3.4540128*^9, 4.21}, {3.4618752*^9, + 4.31}, {3.4697376*^9, 4.41}, {3.4776*^9, 4.49}, { + 3.4854624*^9, 4.57}, {3.4933248*^9, 4.65}, {3.5011872*^9, + 4.73}, {3.5090496*^9, 4.79}, {3.516912*^9, 4.86}, { + 3.5253792*^9, 4.92}, {3.5332416*^9, 4.98}, {3.541104*^9, + 5.03}, {3.5489664*^9, 5.09}, {3.5568288*^9, 5.14}, { + 3.5646912*^9, 5.19}, {3.5725536*^9, 5.23}, {3.580416*^9, + 5.27}, {3.5882784*^9, 5.31}, {3.5961408*^9, 5.36}, { + 3.6040032*^9, 5.39}, {3.6118656*^9, 5.43}, {3.619728*^9, + 5.46}, {3.6275904*^9, 5.51}, {3.6354528*^9, 5.53}, { + 3.6433152*^9, 5.56}, {3.6511776*^9, 5.59}, {3.65904*^9, + 5.62}, {3.6669024*^9, 5.64}, {3.6747648*^9, 5.67}, { + 3.683232*^9, 5.7}, {3.6910944*^9, 5.73}, {3.698352*^9, + 5.75}, {3.7068192*^9, 5.76}, {3.7146816*^9, 5.78}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"24 Oct 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 103-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.4044192*^9, 4.8}, {3.4068384*^9, 4.64}, { + 3.4092576*^9, 4.5}, {3.4147008*^9, 4.3}, {3.4225632*^9, + 4.15}, {3.4304256*^9, 4.07}, {3.438288*^9, 4.06}, { + 3.4461504*^9, 4.12}, {3.4540128*^9, 4.23}, {3.4618752*^9, + 4.33}, {3.4697376*^9, 4.44}, {3.4776*^9, 4.52}, { + 3.4854624*^9, 4.6}, {3.4933248*^9, 4.68}, {3.5011872*^9, + 4.76}, {3.5090496*^9, 4.83}, {3.516912*^9, 4.89}, { + 3.5253792*^9, 4.96}, {3.5332416*^9, 5.02}, {3.541104*^9, + 5.07}, {3.5489664*^9, 5.13}, {3.5568288*^9, 5.18}, { + 3.5646912*^9, 5.23}, {3.5725536*^9, 5.27}, {3.580416*^9, + 5.32}, {3.5882784*^9, 5.36}, {3.5961408*^9, 5.41}, { + 3.6040032*^9, 5.44}, {3.6118656*^9, 5.48}, {3.619728*^9, + 5.51}, {3.6275904*^9, 5.55}, {3.6354528*^9, 5.58}, { + 3.6433152*^9, 5.61}, {3.6511776*^9, 5.63}, {3.65904*^9, + 5.67}, {3.6669024*^9, 5.69}, {3.6747648*^9, 5.72}, { + 3.683232*^9, 5.74}, {3.6910944*^9, 5.78}, {3.698352*^9, + 5.79}, {3.7068192*^9, 5.81}, {3.7146816*^9, 5.82}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"25 Oct 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 104-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.4044192*^9, 4.77}, {3.4068384*^9, 4.64}, { + 3.4092576*^9, 4.5}, {3.4147008*^9, 4.32}, {3.4225632*^9, + 4.19}, {3.4304256*^9, 4.11}, {3.438288*^9, 4.1}, { + 3.4461504*^9, 4.16}, {3.4540128*^9, 4.27}, {3.4618752*^9, + 4.38}, {3.4697376*^9, 4.49}, {3.4776*^9, 4.58}, { + 3.4854624*^9, 4.67}, {3.4933248*^9, 4.75}, {3.5011872*^9, + 4.84}, {3.5090496*^9, 4.9}, {3.516912*^9, 4.97}, { + 3.5253792*^9, 5.03}, {3.5332416*^9, 5.1}, {3.541104*^9, + 5.15}, {3.5489664*^9, 5.21}, {3.5568288*^9, 5.26}, { + 3.5646912*^9, 5.31}, {3.5725536*^9, 5.35}, {3.580416*^9, + 5.4}, {3.5882784*^9, 5.44}, {3.5961408*^9, 5.49}, { + 3.6040032*^9, 5.52}, {3.6118656*^9, 5.56}, {3.619728*^9, + 5.59}, {3.6275904*^9, 5.63}, {3.6354528*^9, 5.66}, { + 3.6433152*^9, 5.69}, {3.6511776*^9, 5.71}, {3.65904*^9, + 5.75}, {3.6669024*^9, 5.77}, {3.6747648*^9, 5.8}, { + 3.683232*^9, 5.82}, {3.6910944*^9, 5.86}, {3.698352*^9, + 5.87}, {3.7068192*^9, 5.89}, {3.7146816*^9, 5.9}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"26 Oct 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 105-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.4044192*^9, 4.78}, {3.4068384*^9, 4.68}, { + 3.4092576*^9, 4.53}, {3.4147008*^9, 4.36}, {3.4225632*^9, + 4.23}, {3.4304256*^9, 4.15}, {3.438288*^9, 4.15}, { + 3.4461504*^9, 4.2}, {3.4540128*^9, 4.31}, {3.4618752*^9, + 4.41}, {3.4697376*^9, 4.52}, {3.4776*^9, 4.6}, { + 3.4854624*^9, 4.68}, {3.4933248*^9, 4.76}, {3.5011872*^9, + 4.84}, {3.5090496*^9, 4.9}, {3.516912*^9, 4.97}, { + 3.5253792*^9, 5.03}, {3.5332416*^9, 5.09}, {3.541104*^9, + 5.14}, {3.5489664*^9, 5.19}, {3.5568288*^9, 5.24}, { + 3.5646912*^9, 5.29}, {3.5725536*^9, 5.33}, {3.580416*^9, + 5.37}, {3.5882784*^9, 5.41}, {3.5961408*^9, 5.46}, { + 3.6040032*^9, 5.49}, {3.6118656*^9, 5.52}, {3.619728*^9, + 5.56}, {3.6275904*^9, 5.6}, {3.6354528*^9, 5.62}, { + 3.6433152*^9, 5.65}, {3.6511776*^9, 5.67}, {3.65904*^9, + 5.71}, {3.6669024*^9, 5.73}, {3.6747648*^9, 5.75}, { + 3.683232*^9, 5.78}, {3.6910944*^9, 5.81}, {3.698352*^9, + 5.82}, {3.7068192*^9, 5.84}, {3.7146816*^9, 5.85}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"29 Oct 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 106-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.4044192*^9, 4.78}, {3.4068384*^9, 4.7}, { + 3.4092576*^9, 4.56}, {3.4147008*^9, 4.38}, {3.4225632*^9, + 4.25}, {3.4304256*^9, 4.17}, {3.438288*^9, 4.16}, { + 3.4461504*^9, 4.21}, {3.4540128*^9, 4.3}, {3.4618752*^9, + 4.41}, {3.4697376*^9, 4.51}, {3.4776*^9, 4.6}, { + 3.4854624*^9, 4.68}, {3.4933248*^9, 4.76}, {3.5011872*^9, + 4.84}, {3.5090496*^9, 4.89}, {3.516912*^9, 4.96}, { + 3.5253792*^9, 5.02}, {3.5332416*^9, 5.08}, {3.541104*^9, + 5.13}, {3.5489664*^9, 5.18}, {3.5568288*^9, 5.23}, { + 3.5646912*^9, 5.28}, {3.5725536*^9, 5.32}, {3.580416*^9, + 5.36}, {3.5882784*^9, 5.4}, {3.5961408*^9, 5.45}, { + 3.6040032*^9, 5.48}, {3.6118656*^9, 5.51}, {3.619728*^9, + 5.54}, {3.6275904*^9, 5.58}, {3.6354528*^9, 5.61}, { + 3.6433152*^9, 5.63}, {3.6511776*^9, 5.66}, {3.65904*^9, + 5.69}, {3.6669024*^9, 5.71}, {3.6747648*^9, 5.74}, { + 3.683232*^9, 5.76}, {3.6910944*^9, 5.79}, {3.698352*^9, + 5.8}, {3.7068192*^9, 5.82}, {3.7146816*^9, 5.83}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"30 Oct 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 107-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.4044192*^9, 4.83}, {3.4068384*^9, 4.75}, { + 3.4092576*^9, 4.63}, {3.4147008*^9, 4.49}, {3.4225632*^9, + 4.38}, {3.4304256*^9, 4.31}, {3.438288*^9, 4.3}, { + 3.4461504*^9, 4.34}, {3.4540128*^9, 4.44}, {3.4618752*^9, + 4.54}, {3.4697376*^9, 4.64}, {3.4776*^9, 4.72}, { + 3.4854624*^9, 4.79}, {3.4933248*^9, 4.86}, {3.5011872*^9, + 4.94}, {3.5090496*^9, 4.99}, {3.516912*^9, 5.05}, { + 3.5253792*^9, 5.11}, {3.5332416*^9, 5.17}, {3.541104*^9, + 5.21}, {3.5489664*^9, 5.26}, {3.5568288*^9, 5.31}, { + 3.5646912*^9, 5.36}, {3.5725536*^9, 5.39}, {3.580416*^9, + 5.43}, {3.5882784*^9, 5.46}, {3.5961408*^9, 5.51}, { + 3.6040032*^9, 5.54}, {3.6118656*^9, 5.57}, {3.619728*^9, + 5.6}, {3.6275904*^9, 5.64}, {3.6354528*^9, 5.66}, { + 3.6433152*^9, 5.68}, {3.6511776*^9, 5.71}, {3.65904*^9, + 5.74}, {3.6669024*^9, 5.76}, {3.6747648*^9, 5.78}, { + 3.683232*^9, 5.8}, {3.6910944*^9, 5.83}, {3.698352*^9, + 5.84}, {3.7068192*^9, 5.86}, {3.7146816*^9, 5.87}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"31 Oct 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 108-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.4044192*^9, 4.82}, {3.4068384*^9, 4.74}, { + 3.4092576*^9, 4.6}, {3.4147008*^9, 4.42}, {3.4225632*^9, + 4.26}, {3.4304256*^9, 4.17}, {3.438288*^9, 4.17}, { + 3.4461504*^9, 4.22}, {3.4540128*^9, 4.32}, {3.4618752*^9, + 4.42}, {3.4697376*^9, 4.52}, {3.4776*^9, 4.6}, { + 3.4854624*^9, 4.68}, {3.4933248*^9, 4.75}, {3.5011872*^9, + 4.82}, {3.5090496*^9, 4.88}, {3.516912*^9, 4.94}, { + 3.5253792*^9, 5.}, {3.5332416*^9, 5.06}, {3.541104*^9, + 5.1}, {3.5489664*^9, 5.15}, {3.5568288*^9, 5.19}, { + 3.5646912*^9, 5.24}, {3.5725536*^9, 5.27}, {3.580416*^9, + 5.31}, {3.5882784*^9, 5.35}, {3.5961408*^9, 5.4}, { + 3.6040032*^9, 5.42}, {3.6118656*^9, 5.46}, {3.619728*^9, + 5.49}, {3.6275904*^9, 5.52}, {3.6354528*^9, 5.54}, { + 3.6433152*^9, 5.57}, {3.6511776*^9, 5.59}, {3.65904*^9, + 5.62}, {3.6669024*^9, 5.64}, {3.6747648*^9, 5.66}, { + 3.683232*^9, 5.68}, {3.6910944*^9, 5.71}, {3.698352*^9, + 5.73}, {3.7068192*^9, 5.74}, {3.7146816*^9, 5.75}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"01 Nov 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 109-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.4044192*^9, 4.84}, {3.4068384*^9, 4.77}, { + 3.4092576*^9, 4.6}, {3.4147008*^9, 4.32}, {3.4225632*^9, + 4.13}, {3.4304256*^9, 4.04}, {3.438288*^9, 4.03}, { + 3.4461504*^9, 4.09}, {3.4540128*^9, 4.19}, {3.4618752*^9, + 4.3}, {3.4697376*^9, 4.41}, {3.4776*^9, 4.5}, { + 3.4854624*^9, 4.59}, {3.4933248*^9, 4.67}, {3.5011872*^9, + 4.75}, {3.5090496*^9, 4.81}, {3.516912*^9, 4.88}, { + 3.5253792*^9, 4.95}, {3.5332416*^9, 5.01}, {3.541104*^9, + 5.06}, {3.5489664*^9, 5.11}, {3.5568288*^9, 5.16}, { + 3.5646912*^9, 5.22}, {3.5725536*^9, 5.25}, {3.580416*^9, + 5.29}, {3.5882784*^9, 5.33}, {3.5961408*^9, 5.38}, { + 3.6040032*^9, 5.41}, {3.6118656*^9, 5.45}, {3.619728*^9, + 5.48}, {3.6275904*^9, 5.52}, {3.6354528*^9, 5.54}, { + 3.6433152*^9, 5.57}, {3.6511776*^9, 5.6}, {3.65904*^9, + 5.63}, {3.6669024*^9, 5.65}, {3.6747648*^9, 5.67}, { + 3.683232*^9, 5.69}, {3.6910944*^9, 5.72}, {3.698352*^9, + 5.74}, {3.7068192*^9, 5.75}, {3.7146816*^9, 5.76}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"02 Nov 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 110-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.4044192*^9, 4.91}, {3.4068384*^9, 4.85}, { + 3.4092576*^9, 4.65}, {3.4147008*^9, 4.39}, {3.4225632*^9, + 4.2}, {3.4304256*^9, 4.1}, {3.438288*^9, 4.09}, { + 3.4461504*^9, 4.14}, {3.4540128*^9, 4.25}, {3.4618752*^9, + 4.36}, {3.4697376*^9, 4.47}, {3.4776*^9, 4.56}, { + 3.4854624*^9, 4.64}, {3.4933248*^9, 4.72}, {3.5011872*^9, + 4.8}, {3.5090496*^9, 4.86}, {3.516912*^9, 4.93}, { + 3.5253792*^9, 5.}, {3.5332416*^9, 5.06}, {3.541104*^9, + 5.11}, {3.5489664*^9, 5.16}, {3.5568288*^9, 5.21}, { + 3.5646912*^9, 5.27}, {3.5725536*^9, 5.3}, {3.580416*^9, + 5.34}, {3.5882784*^9, 5.38}, {3.5961408*^9, 5.43}, { + 3.6040032*^9, 5.46}, {3.6118656*^9, 5.5}, {3.619728*^9, + 5.53}, {3.6275904*^9, 5.57}, {3.6354528*^9, 5.59}, { + 3.6433152*^9, 5.62}, {3.6511776*^9, 5.65}, {3.65904*^9, + 5.68}, {3.6669024*^9, 5.7}, {3.6747648*^9, 5.72}, { + 3.683232*^9, 5.74}, {3.6910944*^9, 5.77}, {3.698352*^9, + 5.79}, {3.7068192*^9, 5.8}, {3.7146816*^9, 5.81}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"05 Nov 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 111-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.4044192*^9, 4.91}, {3.4068384*^9, 4.86}, { + 3.4092576*^9, 4.66}, {3.4147008*^9, 4.41}, {3.4225632*^9, + 4.22}, {3.4304256*^9, 4.12}, {3.438288*^9, 4.1}, { + 3.4461504*^9, 4.16}, {3.4540128*^9, 4.27}, {3.4618752*^9, + 4.39}, {3.4697376*^9, 4.51}, {3.4776*^9, 4.61}, { + 3.4854624*^9, 4.7}, {3.4933248*^9, 4.78}, {3.5011872*^9, + 4.86}, {3.5090496*^9, 4.93}, {3.516912*^9, 5.}, { + 3.5253792*^9, 5.06}, {3.5332416*^9, 5.13}, {3.541104*^9, + 5.18}, {3.5489664*^9, 5.23}, {3.5568288*^9, 5.28}, { + 3.5646912*^9, 5.34}, {3.5725536*^9, 5.37}, {3.580416*^9, + 5.41}, {3.5882784*^9, 5.45}, {3.5961408*^9, 5.5}, { + 3.6040032*^9, 5.53}, {3.6118656*^9, 5.57}, {3.619728*^9, + 5.6}, {3.6275904*^9, 5.64}, {3.6354528*^9, 5.66}, { + 3.6433152*^9, 5.69}, {3.6511776*^9, 5.72}, {3.65904*^9, + 5.75}, {3.6669024*^9, 5.77}, {3.6747648*^9, 5.79}, { + 3.683232*^9, 5.81}, {3.6910944*^9, 5.84}, {3.698352*^9, + 5.86}, {3.7068192*^9, 5.87}, {3.7146816*^9, 5.88}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"06 Nov 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 112-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.4044192*^9, 4.87}, {3.4068384*^9, 4.82}, { + 3.4092576*^9, 4.62}, {3.4147008*^9, 4.38}, {3.4225632*^9, + 4.17}, {3.4304256*^9, 4.07}, {3.438288*^9, 4.05}, { + 3.4461504*^9, 4.11}, {3.4540128*^9, 4.23}, {3.4618752*^9, + 4.36}, {3.4697376*^9, 4.48}, {3.4776*^9, 4.58}, { + 3.4854624*^9, 4.68}, {3.4933248*^9, 4.76}, {3.5011872*^9, + 4.85}, {3.5090496*^9, 4.92}, {3.516912*^9, 4.99}, { + 3.5253792*^9, 5.06}, {3.5332416*^9, 5.13}, {3.541104*^9, + 5.18}, {3.5489664*^9, 5.23}, {3.5568288*^9, 5.29}, { + 3.5646912*^9, 5.34}, {3.5725536*^9, 5.38}, {3.580416*^9, + 5.42}, {3.5882784*^9, 5.46}, {3.5961408*^9, 5.51}, { + 3.6040032*^9, 5.54}, {3.6118656*^9, 5.58}, {3.619728*^9, + 5.61}, {3.6275904*^9, 5.65}, {3.6354528*^9, 5.67}, { + 3.6433152*^9, 5.7}, {3.6511776*^9, 5.73}, {3.65904*^9, + 5.76}, {3.6669024*^9, 5.78}, {3.6747648*^9, 5.81}, { + 3.683232*^9, 5.83}, {3.6910944*^9, 5.86}, {3.698352*^9, + 5.88}, {3.7068192*^9, 5.89}, {3.7146816*^9, 5.9}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"07 Nov 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 113-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.4044192*^9, 4.82}, {3.4068384*^9, 4.75}, { + 3.4092576*^9, 4.55}, {3.4147008*^9, 4.28}, {3.4225632*^9, + 4.03}, {3.4304256*^9, 3.92}, {3.438288*^9, 3.92}, { + 3.4461504*^9, 4.}, {3.4540128*^9, 4.13}, {3.4618752*^9, + 4.26}, {3.4697376*^9, 4.39}, {3.4776*^9, 4.5}, { + 3.4854624*^9, 4.6}, {3.4933248*^9, 4.69}, {3.5011872*^9, + 4.79}, {3.5090496*^9, 4.87}, {3.516912*^9, 4.95}, { + 3.5253792*^9, 5.03}, {3.5332416*^9, 5.1}, {3.541104*^9, + 5.16}, {3.5489664*^9, 5.22}, {3.5568288*^9, 5.28}, { + 3.5646912*^9, 5.34}, {3.5725536*^9, 5.38}, {3.580416*^9, + 5.42}, {3.5882784*^9, 5.47}, {3.5961408*^9, 5.53}, { + 3.6040032*^9, 5.56}, {3.6118656*^9, 5.6}, {3.619728*^9, + 5.64}, {3.6275904*^9, 5.68}, {3.6354528*^9, 5.7}, { + 3.6433152*^9, 5.73}, {3.6511776*^9, 5.76}, {3.65904*^9, + 5.79}, {3.6669024*^9, 5.82}, {3.6747648*^9, 5.84}, { + 3.683232*^9, 5.87}, {3.6910944*^9, 5.9}, {3.698352*^9, + 5.92}, {3.7068192*^9, 5.93}, {3.7146816*^9, 5.94}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"08 Nov 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 114-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.4044192*^9, 4.84}, {3.4068384*^9, 4.73}, { + 3.4092576*^9, 4.53}, {3.4122816*^9, 4.34}, {3.4147008*^9, + 4.23}, {3.4225632*^9, 4.}, {3.4304256*^9, 3.89}, { + 3.438288*^9, 3.9}, {3.4461504*^9, 3.98}, {3.4540128*^9, + 4.11}, {3.4618752*^9, 4.24}, {3.4697376*^9, 4.36}, { + 3.4776*^9, 4.46}, {3.4854624*^9, 4.55}, {3.4933248*^9, + 4.64}, {3.5011872*^9, 4.74}, {3.5090496*^9, 4.81}, { + 3.516912*^9, 4.89}, {3.5253792*^9, 4.96}, {3.5332416*^9, + 5.03}, {3.541104*^9, 5.09}, {3.5489664*^9, 5.15}, { + 3.5568288*^9, 5.21}, {3.5646912*^9, 5.27}, {3.5725536*^9, + 5.31}, {3.580416*^9, 5.35}, {3.5882784*^9, 5.4}, { + 3.5961408*^9, 5.46}, {3.6040032*^9, 5.49}, {3.6118656*^9, + 5.53}, {3.619728*^9, 5.57}, {3.6275904*^9, 5.61}, { + 3.6354528*^9, 5.63}, {3.6433152*^9, 5.66}, {3.6511776*^9, + 5.69}, {3.65904*^9, 5.72}, {3.6669024*^9, 5.75}, { + 3.6747648*^9, 5.77}, {3.683232*^9, 5.8}, {3.6910944*^9, + 5.83}, {3.698352*^9, 5.85}, {3.7068192*^9, 5.86}, { + 3.7146816*^9, 5.87}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"09 Nov 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 115-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.4044192*^9, 4.84}, {3.4068384*^9, 4.73}, { + 3.4092576*^9, 4.53}, {3.4122816*^9, 4.34}, {3.4147008*^9, + 4.23}, {3.4225632*^9, 4.}, {3.4304256*^9, 3.89}, { + 3.438288*^9, 3.9}, {3.4461504*^9, 3.98}, {3.4540128*^9, + 4.11}, {3.4618752*^9, 4.24}, {3.4697376*^9, 4.36}, { + 3.4776*^9, 4.46}, {3.4854624*^9, 4.55}, {3.4933248*^9, + 4.64}, {3.5011872*^9, 4.74}, {3.5090496*^9, 4.81}, { + 3.516912*^9, 4.89}, {3.5253792*^9, 4.96}, {3.5332416*^9, + 5.03}, {3.541104*^9, 5.09}, {3.5489664*^9, 5.15}, { + 3.5568288*^9, 5.21}, {3.5646912*^9, 5.27}, {3.5725536*^9, + 5.31}, {3.580416*^9, 5.35}, {3.5882784*^9, 5.4}, { + 3.5961408*^9, 5.46}, {3.6040032*^9, 5.49}, {3.6118656*^9, + 5.53}, {3.619728*^9, 5.57}, {3.6275904*^9, 5.61}, { + 3.6354528*^9, 5.63}, {3.6433152*^9, 5.66}, {3.6511776*^9, + 5.69}, {3.65904*^9, 5.72}, {3.6669024*^9, 5.75}, { + 3.6747648*^9, 5.77}, {3.683232*^9, 5.8}, {3.6910944*^9, + 5.83}, {3.698352*^9, 5.85}, {3.7068192*^9, 5.86}, { + 3.7146816*^9, 5.87}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"12 Nov 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 116-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.4044192*^9, 4.85}, {3.4068384*^9, 4.77}, { + 3.4092576*^9, 4.58}, {3.4122816*^9, 4.41}, {3.4147008*^9, + 4.29}, {3.41712*^9, 4.2}, {3.4225632*^9, 4.07}, { + 3.4304256*^9, 3.96}, {3.438288*^9, 3.96}, {3.4461504*^9, + 4.03}, {3.4540128*^9, 4.16}, {3.4618752*^9, 4.28}, { + 3.4697376*^9, 4.4}, {3.4776*^9, 4.49}, {3.4854624*^9, + 4.59}, {3.4933248*^9, 4.68}, {3.5011872*^9, 4.77}, { + 3.5090496*^9, 4.84}, {3.516912*^9, 4.92}, {3.5253792*^9, + 4.99}, {3.5332416*^9, 5.06}, {3.541104*^9, 5.12}, { + 3.5489664*^9, 5.18}, {3.5568288*^9, 5.24}, {3.5646912*^9, + 5.3}, {3.5725536*^9, 5.34}, {3.580416*^9, 5.38}, { + 3.5882784*^9, 5.43}, {3.5961408*^9, 5.49}, {3.6040032*^9, + 5.52}, {3.6118656*^9, 5.56}, {3.619728*^9, 5.6}, { + 3.6275904*^9, 5.64}, {3.6354528*^9, 5.66}, {3.6433152*^9, + 5.69}, {3.6511776*^9, 5.72}, {3.65904*^9, 5.75}, { + 3.6669024*^9, 5.77}, {3.6747648*^9, 5.79}, {3.683232*^9, + 5.82}, {3.6910944*^9, 5.85}, {3.698352*^9, 5.87}, { + 3.7068192*^9, 5.88}, {3.7146816*^9, 5.89}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"13 Nov 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 117-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.4044192*^9, 4.89}, {3.4068384*^9, 4.81}, { + 3.4092576*^9, 4.61}, {3.4122816*^9, 4.44}, {3.4147008*^9, + 4.32}, {3.41712*^9, 4.21}, {3.4225632*^9, 4.08}, { + 3.4304256*^9, 3.97}, {3.438288*^9, 3.97}, {3.4461504*^9, + 4.05}, {3.4540128*^9, 4.18}, {3.4618752*^9, 4.3}, { + 3.4697376*^9, 4.42}, {3.4776*^9, 4.51}, {3.4854624*^9, + 4.6}, {3.4933248*^9, 4.69}, {3.5011872*^9, 4.78}, { + 3.5090496*^9, 4.85}, {3.516912*^9, 4.92}, {3.5253792*^9, + 4.99}, {3.5332416*^9, 5.06}, {3.541104*^9, 5.11}, { + 3.5489664*^9, 5.17}, {3.5568288*^9, 5.23}, {3.5646912*^9, + 5.28}, {3.5725536*^9, 5.32}, {3.580416*^9, 5.37}, { + 3.5882784*^9, 5.41}, {3.5961408*^9, 5.47}, {3.6040032*^9, + 5.5}, {3.6118656*^9, 5.54}, {3.619728*^9, 5.58}, { + 3.6275904*^9, 5.62}, {3.6354528*^9, 5.64}, {3.6433152*^9, + 5.67}, {3.6511776*^9, 5.7}, {3.65904*^9, 5.73}, { + 3.6669024*^9, 5.75}, {3.6747648*^9, 5.77}, {3.683232*^9, + 5.8}, {3.6910944*^9, 5.83}, {3.698352*^9, 5.85}, { + 3.7068192*^9, 5.86}, {3.7146816*^9, 5.87}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"14 Nov 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 118-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.4044192*^9, 4.95}, {3.4068384*^9, 4.88}, { + 3.4092576*^9, 4.62}, {3.4122816*^9, 4.41}, {3.4147008*^9, + 4.23}, {3.41712*^9, 4.05}, {3.4225632*^9, 3.92}, { + 3.4304256*^9, 3.79}, {3.438288*^9, 3.77}, {3.4461504*^9, + 3.85}, {3.4540128*^9, 3.98}, {3.4618752*^9, 4.11}, { + 3.4697376*^9, 4.24}, {3.4776*^9, 4.35}, {3.4854624*^9, + 4.45}, {3.4933248*^9, 4.55}, {3.5011872*^9, 4.65}, { + 3.5090496*^9, 4.73}, {3.516912*^9, 4.81}, {3.5253792*^9, + 4.88}, {3.5332416*^9, 4.95}, {3.541104*^9, 5.01}, { + 3.5489664*^9, 5.07}, {3.5568288*^9, 5.13}, {3.5646912*^9, + 5.19}, {3.5725536*^9, 5.23}, {3.580416*^9, 5.28}, { + 3.5882784*^9, 5.33}, {3.5961408*^9, 5.39}, {3.6040032*^9, + 5.42}, {3.6118656*^9, 5.46}, {3.619728*^9, 5.5}, { + 3.6275904*^9, 5.54}, {3.6354528*^9, 5.57}, {3.6433152*^9, + 5.6}, {3.6511776*^9, 5.62}, {3.65904*^9, 5.65}, { + 3.6669024*^9, 5.67}, {3.6747648*^9, 5.7}, {3.683232*^9, + 5.72}, {3.6910944*^9, 5.75}, {3.698352*^9, 5.77}, { + 3.7068192*^9, 5.79}, {3.7146816*^9, 5.8}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"15 Nov 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 119-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.4044192*^9, 4.97}, {3.4068384*^9, 4.88}, { + 3.4092576*^9, 4.63}, {3.4122816*^9, 4.43}, {3.4147008*^9, + 4.26}, {3.41712*^9, 4.05}, {3.4225632*^9, 3.92}, { + 3.4304256*^9, 3.77}, {3.438288*^9, 3.75}, {3.4461504*^9, + 3.83}, {3.4540128*^9, 3.97}, {3.4618752*^9, 4.1}, { + 3.4697376*^9, 4.23}, {3.4776*^9, 4.34}, {3.4854624*^9, + 4.45}, {3.4933248*^9, 4.54}, {3.5011872*^9, 4.64}, { + 3.5090496*^9, 4.72}, {3.516912*^9, 4.81}, {3.5253792*^9, + 4.88}, {3.5332416*^9, 4.96}, {3.541104*^9, 5.01}, { + 3.5489664*^9, 5.07}, {3.5568288*^9, 5.13}, {3.5646912*^9, + 5.19}, {3.5725536*^9, 5.24}, {3.580416*^9, 5.29}, { + 3.5882784*^9, 5.33}, {3.5961408*^9, 5.39}, {3.6040032*^9, + 5.43}, {3.6118656*^9, 5.47}, {3.619728*^9, 5.5}, { + 3.6275904*^9, 5.55}, {3.6354528*^9, 5.57}, {3.6433152*^9, + 5.6}, {3.6511776*^9, 5.63}, {3.65904*^9, 5.66}, { + 3.6669024*^9, 5.68}, {3.6747648*^9, 5.7}, {3.683232*^9, + 5.73}, {3.6910944*^9, 5.76}, {3.698352*^9, 5.78}, { + 3.7068192*^9, 5.79}, {3.7146816*^9, 5.8}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"16 Nov 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 120-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.4068384*^9, 4.89}, {3.4092576*^9, 4.65}, { + 3.4122816*^9, 4.45}, {3.4147008*^9, 4.29}, {3.41712*^9, + 4.16}, {3.4225632*^9, 3.92}, {3.4304256*^9, 3.73}, { + 3.438288*^9, 3.68}, {3.4461504*^9, 3.74}, {3.4540128*^9, + 3.87}, {3.4618752*^9, 4.}, {3.4697376*^9, 4.14}, { + 3.4776*^9, 4.26}, {3.4854624*^9, 4.37}, {3.4933248*^9, + 4.47}, {3.5011872*^9, 4.57}, {3.5090496*^9, 4.66}, { + 3.516912*^9, 4.75}, {3.5253792*^9, 4.83}, {3.5332416*^9, + 4.91}, {3.541104*^9, 4.97}, {3.5489664*^9, 5.03}, { + 3.5568288*^9, 5.09}, {3.5646912*^9, 5.16}, {3.5725536*^9, + 5.21}, {3.580416*^9, 5.26}, {3.5882784*^9, 5.31}, { + 3.5961408*^9, 5.37}, {3.6040032*^9, 5.41}, {3.6118656*^9, + 5.45}, {3.619728*^9, 5.48}, {3.6275904*^9, 5.53}, { + 3.6354528*^9, 5.56}, {3.6433152*^9, 5.59}, {3.6511776*^9, + 5.61}, {3.65904*^9, 5.64}, {3.6669024*^9, 5.67}, { + 3.6747648*^9, 5.69}, {3.683232*^9, 5.72}, {3.6910944*^9, + 5.75}, {3.698352*^9, 5.77}, {3.7068192*^9, 5.78}, { + 3.7146816*^9, 5.79}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"19 Nov 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 121-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.4068384*^9, 4.86}, {3.4092576*^9, 4.62}, { + 3.4122816*^9, 4.45}, {3.4147008*^9, 4.3}, {3.41712*^9, + 4.17}, {3.4225632*^9, 3.93}, {3.4304256*^9, 3.73}, { + 3.438288*^9, 3.67}, {3.4461504*^9, 3.73}, {3.4540128*^9, + 3.86}, {3.4618752*^9, 4.}, {3.4697376*^9, 4.14}, { + 3.4776*^9, 4.27}, {3.4854624*^9, 4.38}, {3.4933248*^9, + 4.49}, {3.5011872*^9, 4.6}, {3.5090496*^9, 4.68}, { + 3.516912*^9, 4.78}, {3.5253792*^9, 4.86}, {3.5332416*^9, + 4.95}, {3.541104*^9, 5.01}, {3.5489664*^9, 5.08}, { + 3.5568288*^9, 5.14}, {3.5646912*^9, 5.2}, {3.5725536*^9, + 5.25}, {3.580416*^9, 5.31}, {3.5882784*^9, 5.35}, { + 3.5961408*^9, 5.41}, {3.6040032*^9, 5.45}, {3.6118656*^9, + 5.49}, {3.619728*^9, 5.53}, {3.6275904*^9, 5.57}, { + 3.6354528*^9, 5.6}, {3.6433152*^9, 5.63}, {3.6511776*^9, + 5.66}, {3.65904*^9, 5.69}, {3.6669024*^9, 5.71}, { + 3.6747648*^9, 5.74}, {3.683232*^9, 5.76}, {3.6910944*^9, + 5.79}, {3.698352*^9, 5.81}, {3.7068192*^9, 5.83}, { + 3.7146816*^9, 5.84}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"20 Nov 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 122-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.4068384*^9, 4.79}, {3.4092576*^9, 4.54}, { + 3.4122816*^9, 4.34}, {3.4147008*^9, 4.17}, {3.41712*^9, + 4.05}, {3.4225632*^9, 3.81}, {3.4304256*^9, 3.62}, { + 3.438288*^9, 3.58}, {3.4461504*^9, 3.64}, {3.4540128*^9, + 3.76}, {3.4618752*^9, 3.91}, {3.4697376*^9, 4.06}, { + 3.4776*^9, 4.2}, {3.4854624*^9, 4.32}, {3.4933248*^9, + 4.44}, {3.5011872*^9, 4.56}, {3.5090496*^9, 4.65}, { + 3.516912*^9, 4.75}, {3.5253792*^9, 4.84}, {3.5332416*^9, + 4.93}, {3.541104*^9, 5.}, {3.5489664*^9, 5.07}, { + 3.5568288*^9, 5.14}, {3.5646912*^9, 5.21}, {3.5725536*^9, + 5.26}, {3.580416*^9, 5.32}, {3.5882784*^9, 5.37}, { + 3.5961408*^9, 5.43}, {3.6040032*^9, 5.47}, {3.6118656*^9, + 5.51}, {3.619728*^9, 5.54}, {3.6275904*^9, 5.59}, { + 3.6354528*^9, 5.62}, {3.6433152*^9, 5.65}, {3.6511776*^9, + 5.67}, {3.65904*^9, 5.71}, {3.6669024*^9, 5.73}, { + 3.6747648*^9, 5.76}, {3.683232*^9, 5.78}, {3.6910944*^9, + 5.81}, {3.698352*^9, 5.83}, {3.7068192*^9, 5.85}, { + 3.7146816*^9, 5.86}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"21 Nov 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 123-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.4068384*^9, 4.81}, {3.4092576*^9, 4.55}, { + 3.4122816*^9, 4.35}, {3.4147008*^9, 4.18}, {3.41712*^9, + 4.05}, {3.4225632*^9, 3.81}, {3.4304256*^9, 3.62}, { + 3.438288*^9, 3.58}, {3.4461504*^9, 3.63}, {3.4540128*^9, + 3.75}, {3.4618752*^9, 3.88}, {3.4697376*^9, 4.03}, { + 3.4776*^9, 4.16}, {3.4854624*^9, 4.28}, {3.4933248*^9, + 4.39}, {3.5011872*^9, 4.5}, {3.5090496*^9, 4.59}, { + 3.516912*^9, 4.69}, {3.5253792*^9, 4.77}, {3.5332416*^9, + 4.86}, {3.541104*^9, 4.92}, {3.5489664*^9, 4.99}, { + 3.5568288*^9, 5.06}, {3.5646912*^9, 5.13}, {3.5725536*^9, + 5.18}, {3.580416*^9, 5.24}, {3.5882784*^9, 5.29}, { + 3.5961408*^9, 5.34}, {3.6040032*^9, 5.38}, {3.6118656*^9, + 5.42}, {3.619728*^9, 5.46}, {3.6275904*^9, 5.5}, { + 3.6354528*^9, 5.53}, {3.6433152*^9, 5.56}, {3.6511776*^9, + 5.59}, {3.65904*^9, 5.62}, {3.6669024*^9, 5.65}, { + 3.6747648*^9, 5.67}, {3.683232*^9, 5.7}, {3.6910944*^9, + 5.73}, {3.698352*^9, 5.75}, {3.7068192*^9, 5.76}, { + 3.7146816*^9, 5.77}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"23 Nov 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 124-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.4068384*^9, 4.82}, {3.4092576*^9, 4.52}, { + 3.4122816*^9, 4.29}, {3.4147008*^9, 4.12}, {3.41712*^9, + 3.9}, {3.4225632*^9, 3.66}, {3.4304256*^9, 3.44}, { + 3.438288*^9, 3.38}, {3.4461504*^9, 3.42}, {3.4540128*^9, + 3.53}, {3.4618752*^9, 3.67}, {3.4697376*^9, 3.81}, { + 3.4776*^9, 3.94}, {3.4854624*^9, 4.06}, {3.4933248*^9, + 4.17}, {3.5011872*^9, 4.28}, {3.5090496*^9, 4.37}, { + 3.516912*^9, 4.46}, {3.5253792*^9, 4.54}, {3.5332416*^9, + 4.63}, {3.541104*^9, 4.69}, {3.5489664*^9, 4.76}, { + 3.5568288*^9, 4.82}, {3.5646912*^9, 4.89}, {3.5725536*^9, + 4.94}, {3.580416*^9, 5.}, {3.5882784*^9, 5.04}, { + 3.5961408*^9, 5.1}, {3.6040032*^9, 5.14}, {3.6118656*^9, + 5.18}, {3.619728*^9, 5.21}, {3.6275904*^9, 5.25}, { + 3.6354528*^9, 5.28}, {3.6433152*^9, 5.31}, {3.6511776*^9, + 5.34}, {3.65904*^9, 5.37}, {3.6669024*^9, 5.4}, { + 3.6747648*^9, 5.42}, {3.683232*^9, 5.44}, {3.6910944*^9, + 5.47}, {3.698352*^9, 5.49}, {3.7068192*^9, 5.51}, { + 3.7146816*^9, 5.52}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"26 Nov 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 125-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.4068384*^9, 4.86}, {3.4092576*^9, 4.59}, { + 3.4122816*^9, 4.37}, {3.4147008*^9, 4.22}, {3.41712*^9, + 4.03}, {3.4225632*^9, 3.79}, {3.4304256*^9, 3.56}, { + 3.438288*^9, 3.49}, {3.4461504*^9, 3.52}, {3.4540128*^9, + 3.63}, {3.4618752*^9, 3.76}, {3.4697376*^9, 3.9}, { + 3.4776*^9, 4.03}, {3.4854624*^9, 4.15}, {3.4933248*^9, + 4.25}, {3.5011872*^9, 4.36}, {3.5090496*^9, 4.44}, { + 3.516912*^9, 4.53}, {3.5253792*^9, 4.61}, {3.5332416*^9, + 4.69}, {3.541104*^9, 4.75}, {3.5489664*^9, 4.82}, { + 3.5568288*^9, 4.89}, {3.5646912*^9, 4.96}, {3.5725536*^9, + 5.01}, {3.580416*^9, 5.06}, {3.5882784*^9, 5.11}, { + 3.5961408*^9, 5.17}, {3.6040032*^9, 5.21}, {3.6118656*^9, + 5.25}, {3.619728*^9, 5.28}, {3.6275904*^9, 5.33}, { + 3.6354528*^9, 5.36}, {3.6433152*^9, 5.39}, {3.6511776*^9, + 5.41}, {3.65904*^9, 5.45}, {3.6669024*^9, 5.48}, { + 3.6747648*^9, 5.5}, {3.683232*^9, 5.52}, {3.6910944*^9, + 5.55}, {3.698352*^9, 5.57}, {3.7068192*^9, 5.59}, { + 3.7146816*^9, 5.6}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"27 Nov 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 126-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.4068384*^9, 4.86}, {3.4092576*^9, 4.61}, { + 3.4122816*^9, 4.4}, {3.4147008*^9, 4.25}, {3.41712*^9, + 4.11}, {3.420144*^9, 3.96}, {3.4225632*^9, 3.84}, { + 3.4304256*^9, 3.63}, {3.438288*^9, 3.56}, {3.4461504*^9, + 3.59}, {3.4540128*^9, 3.69}, {3.4618752*^9, 3.82}, { + 3.4697376*^9, 3.96}, {3.4776*^9, 4.09}, {3.4854624*^9, + 4.21}, {3.4933248*^9, 4.32}, {3.5011872*^9, 4.42}, { + 3.5090496*^9, 4.51}, {3.516912*^9, 4.6}, {3.5253792*^9, + 4.68}, {3.5332416*^9, 4.76}, {3.541104*^9, 4.82}, { + 3.5489664*^9, 4.88}, {3.5568288*^9, 4.94}, {3.5646912*^9, + 5.}, {3.5725536*^9, 5.05}, {3.580416*^9, 5.1}, { + 3.5882784*^9, 5.14}, {3.5961408*^9, 5.2}, {3.6040032*^9, + 5.24}, {3.6118656*^9, 5.28}, {3.619728*^9, 5.32}, { + 3.6275904*^9, 5.37}, {3.6354528*^9, 5.4}, {3.6433152*^9, + 5.43}, {3.6511776*^9, 5.46}, {3.65904*^9, 5.5}, { + 3.6669024*^9, 5.53}, {3.6747648*^9, 5.55}, {3.683232*^9, + 5.57}, {3.6910944*^9, 5.61}, {3.698352*^9, 5.63}, { + 3.7068192*^9, 5.64}, {3.7146816*^9, 5.66}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"28 Nov 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 127-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.4068384*^9, 4.85}, {3.4092576*^9, 4.58}, { + 3.4122816*^9, 4.36}, {3.4147008*^9, 4.19}, {3.41712*^9, + 4.01}, {3.420144*^9, 3.86}, {3.4225632*^9, 3.74}, { + 3.4304256*^9, 3.52}, {3.438288*^9, 3.45}, {3.4461504*^9, + 3.48}, {3.4540128*^9, 3.59}, {3.4618752*^9, 3.73}, { + 3.4697376*^9, 3.87}, {3.4776*^9, 4.}, {3.4854624*^9, + 4.12}, {3.4933248*^9, 4.23}, {3.5011872*^9, 4.33}, { + 3.5090496*^9, 4.41}, {3.516912*^9, 4.5}, {3.5253792*^9, + 4.58}, {3.5332416*^9, 4.65}, {3.541104*^9, 4.71}, { + 3.5489664*^9, 4.78}, {3.5568288*^9, 4.84}, {3.5646912*^9, + 4.9}, {3.5725536*^9, 4.94}, {3.580416*^9, 5.}, { + 3.5882784*^9, 5.04}, {3.5961408*^9, 5.1}, {3.6040032*^9, + 5.14}, {3.6118656*^9, 5.19}, {3.619728*^9, 5.22}, { + 3.6275904*^9, 5.27}, {3.6354528*^9, 5.3}, {3.6433152*^9, + 5.34}, {3.6511776*^9, 5.36}, {3.65904*^9, 5.4}, { + 3.6669024*^9, 5.43}, {3.6747648*^9, 5.46}, {3.683232*^9, + 5.48}, {3.6910944*^9, 5.51}, {3.698352*^9, 5.53}, { + 3.7068192*^9, 5.55}, {3.7146816*^9, 5.56}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"29 Nov 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 128-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.4068384*^9, 4.84}, {3.4092576*^9, 4.57}, { + 3.4122816*^9, 4.33}, {3.4147008*^9, 4.17}, {3.41712*^9, + 4.}, {3.420144*^9, 3.85}, {3.4225632*^9, 3.73}, { + 3.4304256*^9, 3.5}, {3.438288*^9, 3.43}, {3.4461504*^9, + 3.46}, {3.4540128*^9, 3.57}, {3.4618752*^9, 3.7}, { + 3.4697376*^9, 3.85}, {3.4776*^9, 3.98}, {3.4854624*^9, + 4.1}, {3.4933248*^9, 4.21}, {3.5011872*^9, 4.32}, { + 3.5090496*^9, 4.4}, {3.516912*^9, 4.49}, {3.5253792*^9, + 4.57}, {3.5332416*^9, 4.65}, {3.541104*^9, 4.72}, { + 3.5489664*^9, 4.79}, {3.5568288*^9, 4.85}, {3.5646912*^9, + 4.92}, {3.5725536*^9, 4.97}, {3.580416*^9, 5.02}, { + 3.5882784*^9, 5.07}, {3.5961408*^9, 5.13}, {3.6040032*^9, + 5.17}, {3.6118656*^9, 5.22}, {3.619728*^9, 5.25}, { + 3.6275904*^9, 5.3}, {3.6354528*^9, 5.33}, {3.6433152*^9, + 5.37}, {3.6511776*^9, 5.39}, {3.65904*^9, 5.44}, { + 3.6669024*^9, 5.47}, {3.6747648*^9, 5.49}, {3.683232*^9, + 5.51}, {3.6910944*^9, 5.55}, {3.698352*^9, 5.57}, { + 3.7068192*^9, 5.59}, {3.7146816*^9, 5.6}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"30 Nov 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 129-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.4068384*^9, 4.91}, {3.4092576*^9, 4.62}, { + 3.4122816*^9, 4.38}, {3.4147008*^9, 4.2}, {3.41712*^9, + 4.03}, {3.420144*^9, 3.84}, {3.4225632*^9, 3.72}, { + 3.4304256*^9, 3.46}, {3.438288*^9, 3.36}, {3.4461504*^9, + 3.36}, {3.4540128*^9, 3.45}, {3.4618752*^9, 3.58}, { + 3.4697376*^9, 3.73}, {3.4776*^9, 3.86}, {3.4854624*^9, + 3.99}, {3.4933248*^9, 4.1}, {3.5011872*^9, 4.21}, { + 3.5090496*^9, 4.29}, {3.516912*^9, 4.39}, {3.5253792*^9, + 4.47}, {3.5332416*^9, 4.55}, {3.541104*^9, 4.62}, { + 3.5489664*^9, 4.69}, {3.5568288*^9, 4.75}, {3.5646912*^9, + 4.83}, {3.5725536*^9, 4.88}, {3.580416*^9, 4.94}, { + 3.5882784*^9, 4.99}, {3.5961408*^9, 5.06}, {3.6040032*^9, + 5.1}, {3.6118656*^9, 5.14}, {3.619728*^9, 5.18}, { + 3.6275904*^9, 5.23}, {3.6354528*^9, 5.26}, {3.6433152*^9, + 5.3}, {3.6511776*^9, 5.33}, {3.65904*^9, 5.37}, { + 3.6669024*^9, 5.4}, {3.6747648*^9, 5.43}, {3.683232*^9, + 5.45}, {3.6910944*^9, 5.49}, {3.698352*^9, 5.51}, { + 3.7068192*^9, 5.53}, {3.7146816*^9, 5.55}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"03 Dec 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 130-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.4068384*^9, 4.9}, {3.4092576*^9, 4.61}, { + 3.4122816*^9, 4.36}, {3.4147008*^9, 4.18}, {3.41712*^9, + 4.03}, {3.420144*^9, 3.84}, {3.4225632*^9, 3.72}, { + 3.4304256*^9, 3.46}, {3.438288*^9, 3.35}, {3.4461504*^9, + 3.35}, {3.4540128*^9, 3.45}, {3.4618752*^9, 3.58}, { + 3.4697376*^9, 3.74}, {3.4776*^9, 3.87}, {3.4854624*^9, + 4.01}, {3.4933248*^9, 4.11}, {3.5011872*^9, 4.22}, { + 3.5090496*^9, 4.31}, {3.516912*^9, 4.41}, {3.5253792*^9, + 4.49}, {3.5332416*^9, 4.58}, {3.541104*^9, 4.65}, { + 3.5489664*^9, 4.72}, {3.5568288*^9, 4.79}, {3.5646912*^9, + 4.87}, {3.5725536*^9, 4.93}, {3.580416*^9, 4.99}, { + 3.5882784*^9, 5.04}, {3.5961408*^9, 5.1}, {3.6040032*^9, + 5.15}, {3.6118656*^9, 5.2}, {3.619728*^9, 5.24}, { + 3.6275904*^9, 5.29}, {3.6354528*^9, 5.33}, {3.6433152*^9, + 5.36}, {3.6511776*^9, 5.39}, {3.65904*^9, 5.44}, { + 3.6669024*^9, 5.47}, {3.6747648*^9, 5.5}, {3.683232*^9, + 5.52}, {3.6910944*^9, 5.56}, {3.698352*^9, 5.58}, { + 3.7068192*^9, 5.6}, {3.7146816*^9, 5.62}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"04 Dec 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 131-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.4068384*^9, 4.9}, {3.4092576*^9, 4.61}, { + 3.4122816*^9, 4.37}, {3.4147008*^9, 4.2}, {3.41712*^9, + 4.03}, {3.420144*^9, 3.84}, {3.4225632*^9, 3.72}, { + 3.4304256*^9, 3.46}, {3.438288*^9, 3.35}, {3.4461504*^9, + 3.34}, {3.4540128*^9, 3.44}, {3.4618752*^9, 3.57}, { + 3.4697376*^9, 3.72}, {3.4776*^9, 3.86}, {3.4854624*^9, + 3.99}, {3.4933248*^9, 4.1}, {3.5011872*^9, 4.21}, { + 3.5090496*^9, 4.3}, {3.516912*^9, 4.4}, {3.5253792*^9, + 4.49}, {3.5332416*^9, 4.58}, {3.541104*^9, 4.65}, { + 3.5489664*^9, 4.72}, {3.5568288*^9, 4.79}, {3.5646912*^9, + 4.87}, {3.5725536*^9, 4.93}, {3.580416*^9, 5.}, { + 3.5882784*^9, 5.05}, {3.5961408*^9, 5.12}, {3.6040032*^9, + 5.16}, {3.6118656*^9, 5.21}, {3.619728*^9, 5.25}, { + 3.6275904*^9, 5.31}, {3.6354528*^9, 5.34}, {3.6433152*^9, + 5.38}, {3.6511776*^9, 5.41}, {3.65904*^9, 5.47}, { + 3.6669024*^9, 5.5}, {3.6747648*^9, 5.53}, {3.683232*^9, + 5.55}, {3.6910944*^9, 5.59}, {3.698352*^9, 5.61}, { + 3.7068192*^9, 5.63}, {3.7146816*^9, 5.65}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"05 Dec 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 132-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.4068384*^9, 4.94}, {3.4092576*^9, 4.66}, { + 3.4122816*^9, 4.44}, {3.4147008*^9, 4.29}, {3.41712*^9, + 4.12}, {3.420144*^9, 3.93}, {3.4225632*^9, 3.81}, { + 3.4304256*^9, 3.56}, {3.438288*^9, 3.47}, {3.4461504*^9, + 3.47}, {3.4540128*^9, 3.56}, {3.4618752*^9, 3.69}, { + 3.4697376*^9, 3.83}, {3.4776*^9, 3.96}, {3.4854624*^9, + 4.1}, {3.4933248*^9, 4.2}, {3.5011872*^9, 4.31}, { + 3.5090496*^9, 4.39}, {3.516912*^9, 4.49}, {3.5253792*^9, + 4.57}, {3.5332416*^9, 4.66}, {3.541104*^9, 4.73}, { + 3.5489664*^9, 4.8}, {3.5568288*^9, 4.87}, {3.5646912*^9, + 4.95}, {3.5725536*^9, 5.01}, {3.580416*^9, 5.08}, { + 3.5882784*^9, 5.13}, {3.5961408*^9, 5.2}, {3.6040032*^9, + 5.24}, {3.6118656*^9, 5.29}, {3.619728*^9, 5.33}, { + 3.6275904*^9, 5.39}, {3.6354528*^9, 5.42}, {3.6433152*^9, + 5.46}, {3.6511776*^9, 5.49}, {3.65904*^9, 5.55}, { + 3.6669024*^9, 5.58}, {3.6747648*^9, 5.61}, {3.683232*^9, + 5.63}, {3.6910944*^9, 5.67}, {3.698352*^9, 5.69}, { + 3.7068192*^9, 5.71}, {3.7146816*^9, 5.73}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"06 Dec 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 133-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.4068384*^9, 4.98}, {3.4092576*^9, 4.72}, { + 3.4122816*^9, 4.52}, {3.4147008*^9, 4.4}, {3.41712*^9, + 4.26}, {3.420144*^9, 4.06}, {3.4225632*^9, 3.94}, { + 3.4304256*^9, 3.71}, {3.438288*^9, 3.62}, {3.4461504*^9, + 3.63}, {3.4540128*^9, 3.73}, {3.4618752*^9, 3.86}, { + 3.4697376*^9, 4.01}, {3.4776*^9, 4.14}, {3.4854624*^9, + 4.28}, {3.4933248*^9, 4.39}, {3.5011872*^9, 4.5}, { + 3.5090496*^9, 4.59}, {3.516912*^9, 4.69}, {3.5253792*^9, + 4.78}, {3.5332416*^9, 4.87}, {3.541104*^9, 4.94}, { + 3.5489664*^9, 5.01}, {3.5568288*^9, 5.08}, {3.5646912*^9, + 5.16}, {3.5725536*^9, 5.22}, {3.580416*^9, 5.29}, { + 3.5882784*^9, 5.34}, {3.5961408*^9, 5.41}, {3.6040032*^9, + 5.45}, {3.6118656*^9, 5.5}, {3.619728*^9, 5.54}, { + 3.6275904*^9, 5.6}, {3.6354528*^9, 5.63}, {3.6433152*^9, + 5.67}, {3.6511776*^9, 5.7}, {3.65904*^9, 5.76}, { + 3.6669024*^9, 5.79}, {3.6747648*^9, 5.82}, {3.683232*^9, + 5.84}, {3.6910944*^9, 5.88}, {3.698352*^9, 5.9}, { + 3.7068192*^9, 5.92}, {3.7146816*^9, 5.94}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"07 Dec 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 134-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.4068384*^9, 4.96}, {3.4092576*^9, 4.72}, { + 3.4122816*^9, 4.53}, {3.4147008*^9, 4.42}, {3.41712*^9, + 4.27}, {3.420144*^9, 4.1}, {3.4225632*^9, 3.98}, { + 3.4304256*^9, 3.75}, {3.438288*^9, 3.67}, {3.4461504*^9, + 3.69}, {3.4540128*^9, 3.8}, {3.4618752*^9, 3.94}, { + 3.4697376*^9, 4.08}, {3.4776*^9, 4.21}, {3.4854624*^9, + 4.35}, {3.4933248*^9, 4.46}, {3.5011872*^9, 4.56}, { + 3.5090496*^9, 4.65}, {3.516912*^9, 4.74}, {3.5253792*^9, + 4.83}, {3.5332416*^9, 4.92}, {3.541104*^9, 4.98}, { + 3.5489664*^9, 5.06}, {3.5568288*^9, 5.13}, {3.5646912*^9, + 5.2}, {3.5725536*^9, 5.26}, {3.580416*^9, 5.33}, { + 3.5882784*^9, 5.38}, {3.5961408*^9, 5.45}, {3.6040032*^9, + 5.49}, {3.6118656*^9, 5.54}, {3.619728*^9, 5.58}, { + 3.6275904*^9, 5.64}, {3.6354528*^9, 5.67}, {3.6433152*^9, + 5.71}, {3.6511776*^9, 5.74}, {3.65904*^9, 5.8}, { + 3.6669024*^9, 5.83}, {3.6747648*^9, 5.86}, {3.683232*^9, + 5.88}, {3.6910944*^9, 5.92}, {3.698352*^9, 5.94}, { + 3.7068192*^9, 5.96}, {3.7146816*^9, 5.98}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"10 Dec 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 135-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.4068384*^9, 5.07}, {3.4092576*^9, 4.79}, { + 3.4122816*^9, 4.57}, {3.4147008*^9, 4.44}, {3.41712*^9, + 4.29}, {3.420144*^9, 4.04}, {3.4225632*^9, 3.92}, { + 3.4304256*^9, 3.62}, {3.438288*^9, 3.49}, {3.4461504*^9, + 3.49}, {3.4540128*^9, 3.59}, {3.4618752*^9, 3.73}, { + 3.4697376*^9, 3.88}, {3.4776*^9, 4.02}, {3.4854624*^9, + 4.16}, {3.4933248*^9, 4.27}, {3.5011872*^9, 4.38}, { + 3.5090496*^9, 4.47}, {3.516912*^9, 4.57}, {3.5253792*^9, + 4.66}, {3.5332416*^9, 4.75}, {3.541104*^9, 4.82}, { + 3.5489664*^9, 4.9}, {3.5568288*^9, 4.97}, {3.5646912*^9, + 5.04}, {3.5725536*^9, 5.1}, {3.580416*^9, 5.17}, { + 3.5882784*^9, 5.22}, {3.5961408*^9, 5.29}, {3.6040032*^9, + 5.33}, {3.6118656*^9, 5.38}, {3.619728*^9, 5.42}, { + 3.6275904*^9, 5.48}, {3.6354528*^9, 5.51}, {3.6433152*^9, + 5.55}, {3.6511776*^9, 5.58}, {3.65904*^9, 5.64}, { + 3.6669024*^9, 5.67}, {3.6747648*^9, 5.7}, {3.683232*^9, + 5.72}, {3.6910944*^9, 5.76}, {3.698352*^9, 5.78}, { + 3.7068192*^9, 5.8}, {3.7146816*^9, 5.82}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"11 Dec 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 136-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.4068384*^9, 4.93}, {3.4092576*^9, 4.68}, { + 3.4122816*^9, 4.44}, {3.4147008*^9, 4.33}, {3.41712*^9, + 4.19}, {3.420144*^9, 4.04}, {3.4225632*^9, 3.89}, { + 3.4304256*^9, 3.65}, {3.438288*^9, 3.56}, {3.4461504*^9, + 3.57}, {3.4540128*^9, 3.67}, {3.4618752*^9, 3.81}, { + 3.4697376*^9, 3.94}, {3.4776*^9, 4.07}, {3.4854624*^9, + 4.2}, {3.4933248*^9, 4.31}, {3.5011872*^9, 4.42}, { + 3.5090496*^9, 4.5}, {3.516912*^9, 4.6}, {3.5253792*^9, + 4.68}, {3.5332416*^9, 4.77}, {3.541104*^9, 4.83}, { + 3.5489664*^9, 4.91}, {3.5568288*^9, 4.98}, {3.5646912*^9, + 5.05}, {3.5725536*^9, 5.11}, {3.580416*^9, 5.18}, { + 3.5882784*^9, 5.23}, {3.5961408*^9, 5.3}, {3.6040032*^9, + 5.34}, {3.6118656*^9, 5.39}, {3.619728*^9, 5.43}, { + 3.6275904*^9, 5.49}, {3.6354528*^9, 5.52}, {3.6433152*^9, + 5.56}, {3.6511776*^9, 5.59}, {3.65904*^9, 5.64}, { + 3.6669024*^9, 5.67}, {3.6747648*^9, 5.7}, {3.683232*^9, + 5.73}, {3.6910944*^9, 5.77}, {3.698352*^9, 5.79}, { + 3.7068192*^9, 5.81}, {3.7146816*^9, 5.83}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"12 Dec 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 137-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.4068384*^9, 4.95}, {3.4092576*^9, 4.71}, { + 3.4122816*^9, 4.48}, {3.4147008*^9, 4.39}, {3.41712*^9, + 4.26}, {3.420144*^9, 4.11}, {3.4225632*^9, 3.97}, { + 3.4304256*^9, 3.74}, {3.438288*^9, 3.65}, {3.4461504*^9, + 3.66}, {3.4540128*^9, 3.76}, {3.4618752*^9, 3.89}, { + 3.4697376*^9, 4.02}, {3.4776*^9, 4.14}, {3.4854624*^9, + 4.28}, {3.4933248*^9, 4.39}, {3.5011872*^9, 4.49}, { + 3.5090496*^9, 4.58}, {3.516912*^9, 4.67}, {3.5253792*^9, + 4.76}, {3.5332416*^9, 4.84}, {3.541104*^9, 4.91}, { + 3.5489664*^9, 4.98}, {3.5568288*^9, 5.05}, {3.5646912*^9, + 5.13}, {3.5725536*^9, 5.19}, {3.580416*^9, 5.25}, { + 3.5882784*^9, 5.3}, {3.5961408*^9, 5.37}, {3.6040032*^9, + 5.42}, {3.6118656*^9, 5.47}, {3.619728*^9, 5.51}, { + 3.6275904*^9, 5.56}, {3.6354528*^9, 5.6}, {3.6433152*^9, + 5.64}, {3.6511776*^9, 5.67}, {3.65904*^9, 5.72}, { + 3.6669024*^9, 5.75}, {3.6747648*^9, 5.78}, {3.683232*^9, + 5.8}, {3.6910944*^9, 5.84}, {3.698352*^9, 5.86}, { + 3.7068192*^9, 5.88}, {3.7146816*^9, 5.9}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"13 Dec 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 138-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.4068384*^9, 4.93}, {3.4092576*^9, 4.7}, { + 3.4122816*^9, 4.52}, {3.4147008*^9, 4.43}, {3.41712*^9, + 4.36}, {3.420144*^9, 4.21}, {3.4225632*^9, 4.06}, { + 3.4304256*^9, 3.85}, {3.438288*^9, 3.76}, {3.4461504*^9, + 3.77}, {3.4540128*^9, 3.88}, {3.4618752*^9, 4.01}, { + 3.4697376*^9, 4.14}, {3.4776*^9, 4.26}, {3.4854624*^9, + 4.39}, {3.4933248*^9, 4.5}, {3.5011872*^9, 4.6}, { + 3.5090496*^9, 4.68}, {3.516912*^9, 4.77}, {3.5253792*^9, + 4.86}, {3.5332416*^9, 4.94}, {3.541104*^9, 5.}, { + 3.5489664*^9, 5.08}, {3.5568288*^9, 5.15}, {3.5646912*^9, + 5.22}, {3.5725536*^9, 5.27}, {3.580416*^9, 5.33}, { + 3.5882784*^9, 5.38}, {3.5961408*^9, 5.45}, {3.6040032*^9, + 5.49}, {3.6118656*^9, 5.54}, {3.619728*^9, 5.58}, { + 3.6275904*^9, 5.63}, {3.6354528*^9, 5.66}, {3.6433152*^9, + 5.7}, {3.6511776*^9, 5.73}, {3.65904*^9, 5.77}, { + 3.6669024*^9, 5.8}, {3.6747648*^9, 5.83}, {3.683232*^9, + 5.86}, {3.6910944*^9, 5.89}, {3.698352*^9, 5.91}, { + 3.7068192*^9, 5.93}, {3.7146816*^9, 5.95}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"14 Dec 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 139-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.4092576*^9, 4.72}, {3.4122816*^9, 4.52}, { + 3.4147008*^9, 4.42}, {3.41712*^9, 4.3}, {3.420144*^9, + 4.16}, {3.4225632*^9, 4.04}, {3.4304256*^9, 3.8}, { + 3.438288*^9, 3.69}, {3.4461504*^9, 3.7}, {3.4540128*^9, + 3.81}, {3.4618752*^9, 3.94}, {3.4697376*^9, 4.07}, { + 3.4776*^9, 4.2}, {3.4854624*^9, 4.33}, {3.4933248*^9, + 4.44}, {3.5011872*^9, 4.55}, {3.5090496*^9, 4.63}, { + 3.516912*^9, 4.72}, {3.5253792*^9, 4.8}, {3.5332416*^9, + 4.88}, {3.541104*^9, 4.95}, {3.5489664*^9, 5.02}, { + 3.5568288*^9, 5.09}, {3.5646912*^9, 5.16}, {3.5725536*^9, + 5.22}, {3.580416*^9, 5.28}, {3.5882784*^9, 5.33}, { + 3.5961408*^9, 5.39}, {3.6040032*^9, 5.44}, {3.6118656*^9, + 5.48}, {3.619728*^9, 5.52}, {3.6275904*^9, 5.57}, { + 3.6354528*^9, 5.61}, {3.6433152*^9, 5.64}, {3.6511776*^9, + 5.67}, {3.65904*^9, 5.72}, {3.6669024*^9, 5.75}, { + 3.6747648*^9, 5.78}, {3.683232*^9, 5.8}, {3.6910944*^9, + 5.84}, {3.698352*^9, 5.86}, {3.7068192*^9, 5.88}, { + 3.7146816*^9, 5.9}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"17 Dec 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 140-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.4092576*^9, 4.67}, {3.4122816*^9, 4.45}, { + 3.4147008*^9, 4.34}, {3.41712*^9, 4.21}, {3.420144*^9, + 4.05}, {3.4225632*^9, 3.93}, {3.4304256*^9, 3.69}, { + 3.438288*^9, 3.59}, {3.4461504*^9, 3.6}, {3.4540128*^9, + 3.7}, {3.4618752*^9, 3.84}, {3.4697376*^9, 3.97}, { + 3.4776*^9, 4.09}, {3.4854624*^9, 4.23}, {3.4933248*^9, + 4.34}, {3.5011872*^9, 4.44}, {3.5090496*^9, 4.52}, { + 3.516912*^9, 4.61}, {3.5253792*^9, 4.69}, {3.5332416*^9, + 4.77}, {3.541104*^9, 4.83}, {3.5489664*^9, 4.91}, { + 3.5568288*^9, 4.97}, {3.5646912*^9, 5.04}, {3.5725536*^9, + 5.1}, {3.580416*^9, 5.16}, {3.5882784*^9, 5.21}, { + 3.5961408*^9, 5.27}, {3.6040032*^9, 5.32}, {3.6118656*^9, + 5.36}, {3.619728*^9, 5.4}, {3.6275904*^9, 5.45}, { + 3.6354528*^9, 5.48}, {3.6433152*^9, 5.52}, {3.6511776*^9, + 5.55}, {3.65904*^9, 5.59}, {3.6669024*^9, 5.62}, { + 3.6747648*^9, 5.65}, {3.683232*^9, 5.68}, {3.6910944*^9, + 5.71}, {3.698352*^9, 5.73}, {3.7068192*^9, 5.75}, { + 3.7146816*^9, 5.77}, {3.722544*^9, 5.81}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"18 Dec 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 141-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.4068384*^9, 4.94}, {3.4092576*^9, 4.66}, { + 3.4122816*^9, 4.43}, {3.4147008*^9, 4.31}, {3.41712*^9, + 4.15}, {3.420144*^9, 3.98}, {3.4225632*^9, 3.85}, { + 3.4304256*^9, 3.61}, {3.438288*^9, 3.5}, {3.4461504*^9, + 3.51}, {3.4540128*^9, 3.62}, {3.4618752*^9, 3.75}, { + 3.4697376*^9, 3.88}, {3.4776*^9, 4.01}, {3.4854624*^9, + 4.15}, {3.4933248*^9, 4.26}, {3.5011872*^9, 4.37}, { + 3.5090496*^9, 4.45}, {3.516912*^9, 4.54}, {3.5253792*^9, + 4.63}, {3.5332416*^9, 4.71}, {3.541104*^9, 4.77}, { + 3.5489664*^9, 4.84}, {3.5568288*^9, 4.91}, {3.5646912*^9, + 4.98}, {3.5725536*^9, 5.03}, {3.580416*^9, 5.09}, { + 3.5882784*^9, 5.14}, {3.5961408*^9, 5.21}, {3.6040032*^9, + 5.25}, {3.6118656*^9, 5.3}, {3.619728*^9, 5.34}, { + 3.6275904*^9, 5.39}, {3.6354528*^9, 5.42}, {3.6433152*^9, + 5.45}, {3.6511776*^9, 5.48}, {3.65904*^9, 5.53}, { + 3.6669024*^9, 5.56}, {3.6747648*^9, 5.59}, {3.683232*^9, + 5.61}, {3.6910944*^9, 5.65}, {3.698352*^9, 5.67}, { + 3.7068192*^9, 5.69}, {3.7146816*^9, 5.71}, {3.722544*^9, + 5.74}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"19 Dec 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 142-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.4092576*^9, 4.65}, {3.4122816*^9, 4.42}, { + 3.4147008*^9, 4.29}, {3.41712*^9, 4.13}, {3.420144*^9, + 3.94}, {3.4225632*^9, 3.8}, {3.4304256*^9, 3.54}, { + 3.438288*^9, 3.42}, {3.4461504*^9, 3.43}, {3.4540128*^9, + 3.54}, {3.4618752*^9, 3.67}, {3.4697376*^9, 3.81}, { + 3.4776*^9, 3.94}, {3.4854624*^9, 4.09}, {3.4933248*^9, + 4.21}, {3.5011872*^9, 4.32}, {3.5090496*^9, 4.41}, { + 3.516912*^9, 4.51}, {3.5253792*^9, 4.59}, {3.5332416*^9, + 4.68}, {3.541104*^9, 4.74}, {3.5489664*^9, 4.82}, { + 3.5568288*^9, 4.89}, {3.5646912*^9, 4.96}, {3.5725536*^9, + 5.02}, {3.580416*^9, 5.08}, {3.5882784*^9, 5.14}, { + 3.5961408*^9, 5.21}, {3.6040032*^9, 5.26}, {3.6118656*^9, + 5.3}, {3.619728*^9, 5.34}, {3.6275904*^9, 5.39}, { + 3.6354528*^9, 5.42}, {3.6433152*^9, 5.46}, {3.6511776*^9, + 5.49}, {3.65904*^9, 5.53}, {3.6669024*^9, 5.56}, { + 3.6747648*^9, 5.59}, {3.683232*^9, 5.62}, {3.6910944*^9, + 5.65}, {3.698352*^9, 5.67}, {3.7068192*^9, 5.69}, { + 3.7146816*^9, 5.71}, {3.722544*^9, 5.75}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"20 Dec 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 143-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.4092576*^9, 4.67}, {3.4122816*^9, 4.45}, { + 3.4147008*^9, 4.33}, {3.41712*^9, 4.17}, {3.420144*^9, + 4.01}, {3.4225632*^9, 3.87}, {3.4304256*^9, 3.65}, { + 3.438288*^9, 3.56}, {3.4461504*^9, 3.59}, {3.4540128*^9, + 3.72}, {3.4618752*^9, 3.86}, {3.4697376*^9, 4.}, { + 3.4776*^9, 4.13}, {3.4854624*^9, 4.27}, {3.4933248*^9, + 4.39}, {3.5011872*^9, 4.5}, {3.5090496*^9, 4.59}, { + 3.516912*^9, 4.69}, {3.5253792*^9, 4.77}, {3.5332416*^9, + 4.86}, {3.541104*^9, 4.92}, {3.5489664*^9, 5.}, { + 3.5568288*^9, 5.07}, {3.5646912*^9, 5.14}, {3.5725536*^9, + 5.2}, {3.580416*^9, 5.26}, {3.5882784*^9, 5.32}, { + 3.5961408*^9, 5.39}, {3.6040032*^9, 5.44}, {3.6118656*^9, + 5.48}, {3.619728*^9, 5.52}, {3.6275904*^9, 5.57}, { + 3.6354528*^9, 5.6}, {3.6433152*^9, 5.64}, {3.6511776*^9, + 5.67}, {3.65904*^9, 5.71}, {3.6669024*^9, 5.74}, { + 3.6747648*^9, 5.77}, {3.683232*^9, 5.8}, {3.6910944*^9, + 5.83}, {3.698352*^9, 5.85}, {3.7068192*^9, 5.87}, { + 3.7146816*^9, 5.89}, {3.722544*^9, 5.93}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"21 Dec 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 144-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.4092576*^9, 4.68}, {3.4122816*^9, 4.46}, { + 3.4147008*^9, 4.34}, {3.41712*^9, 4.19}, {3.420144*^9, + 4.02}, {3.4225632*^9, 3.89}, {3.4304256*^9, 3.67}, { + 3.438288*^9, 3.59}, {3.4461504*^9, 3.63}, {3.4540128*^9, + 3.77}, {3.4618752*^9, 3.92}, {3.4697376*^9, 4.08}, { + 3.4776*^9, 4.21}, {3.4854624*^9, 4.35}, {3.4933248*^9, + 4.48}, {3.5011872*^9, 4.59}, {3.5090496*^9, 4.68}, { + 3.516912*^9, 4.77}, {3.5253792*^9, 4.86}, {3.5332416*^9, + 4.94}, {3.541104*^9, 5.01}, {3.5489664*^9, 5.08}, { + 3.5568288*^9, 5.15}, {3.5646912*^9, 5.23}, {3.5725536*^9, + 5.29}, {3.580416*^9, 5.35}, {3.5882784*^9, 5.41}, { + 3.5961408*^9, 5.47}, {3.6040032*^9, 5.52}, {3.6118656*^9, + 5.57}, {3.619728*^9, 5.61}, {3.6275904*^9, 5.66}, { + 3.6354528*^9, 5.69}, {3.6433152*^9, 5.72}, {3.6511776*^9, + 5.75}, {3.65904*^9, 5.8}, {3.6669024*^9, 5.83}, { + 3.6747648*^9, 5.86}, {3.683232*^9, 5.88}, {3.6910944*^9, + 5.92}, {3.698352*^9, 5.94}, {3.7068192*^9, 5.96}, { + 3.7146816*^9, 5.98}, {3.722544*^9, 6.01}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"24 Dec 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 145-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.4092576*^9, 4.67}, {3.4122816*^9, 4.45}, { + 3.4147008*^9, 4.37}, {3.41712*^9, 4.22}, {3.420144*^9, + 4.05}, {3.4225632*^9, 3.93}, {3.4304256*^9, 3.71}, { + 3.438288*^9, 3.63}, {3.4461504*^9, 3.68}, {3.4540128*^9, + 3.83}, {3.4618752*^9, 4.}, {3.4697376*^9, 4.16}, { + 3.4776*^9, 4.29}, {3.4854624*^9, 4.43}, {3.4933248*^9, + 4.55}, {3.5011872*^9, 4.66}, {3.5090496*^9, 4.75}, { + 3.516912*^9, 4.85}, {3.5253792*^9, 4.93}, {3.5332416*^9, + 5.01}, {3.541104*^9, 5.07}, {3.5489664*^9, 5.15}, { + 3.5568288*^9, 5.22}, {3.5646912*^9, 5.29}, {3.5725536*^9, + 5.35}, {3.580416*^9, 5.41}, {3.5882784*^9, 5.47}, { + 3.5961408*^9, 5.53}, {3.6040032*^9, 5.58}, {3.6118656*^9, + 5.62}, {3.619728*^9, 5.66}, {3.6275904*^9, 5.71}, { + 3.6354528*^9, 5.74}, {3.6433152*^9, 5.77}, {3.6511776*^9, + 5.8}, {3.65904*^9, 5.84}, {3.6669024*^9, 5.87}, { + 3.6747648*^9, 5.9}, {3.683232*^9, 5.92}, {3.6910944*^9, + 5.96}, {3.698352*^9, 5.97}, {3.7068192*^9, 5.99}, { + 3.7146816*^9, 6.01}, {3.722544*^9, 6.04}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"26 Dec 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 146-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.4092576*^9, 4.65}, {3.4122816*^9, 4.44}, { + 3.4147008*^9, 4.34}, {3.41712*^9, 4.19}, {3.420144*^9, + 4.03}, {3.4225632*^9, 3.9}, {3.4304256*^9, 3.67}, { + 3.438288*^9, 3.57}, {3.4461504*^9, 3.6}, {3.4540128*^9, + 3.73}, {3.4618752*^9, 3.89}, {3.4697376*^9, 4.06}, { + 3.4776*^9, 4.21}, {3.4854624*^9, 4.36}, {3.4933248*^9, + 4.48}, {3.5011872*^9, 4.6}, {3.5090496*^9, 4.69}, { + 3.516912*^9, 4.78}, {3.5253792*^9, 4.86}, {3.5332416*^9, + 4.95}, {3.541104*^9, 5.01}, {3.5489664*^9, 5.08}, { + 3.5568288*^9, 5.15}, {3.5646912*^9, 5.22}, {3.5725536*^9, + 5.28}, {3.580416*^9, 5.34}, {3.5882784*^9, 5.4}, { + 3.5961408*^9, 5.47}, {3.6040032*^9, 5.51}, {3.6118656*^9, + 5.55}, {3.619728*^9, 5.59}, {3.6275904*^9, 5.64}, { + 3.6354528*^9, 5.67}, {3.6433152*^9, 5.7}, {3.6511776*^9, + 5.73}, {3.65904*^9, 5.77}, {3.6669024*^9, 5.8}, { + 3.6747648*^9, 5.83}, {3.683232*^9, 5.85}, {3.6910944*^9, + 5.89}, {3.698352*^9, 5.9}, {3.7068192*^9, 5.92}, { + 3.7146816*^9, 5.94}, {3.722544*^9, 5.97}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"27 Dec 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 147-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.4092576*^9, 4.6}, {3.4122816*^9, 4.38}, { + 3.4147008*^9, 4.27}, {3.41712*^9, 4.11}, {3.420144*^9, + 3.94}, {3.4225632*^9, 3.8}, {3.4304256*^9, 3.55}, { + 3.438288*^9, 3.43}, {3.4461504*^9, 3.44}, {3.4540128*^9, + 3.56}, {3.4618752*^9, 3.73}, {3.4697376*^9, 3.9}, { + 3.4776*^9, 4.06}, {3.4854624*^9, 4.21}, {3.4933248*^9, + 4.34}, {3.5011872*^9, 4.45}, {3.5090496*^9, 4.54}, { + 3.516912*^9, 4.63}, {3.5253792*^9, 4.7}, {3.5332416*^9, + 4.78}, {3.541104*^9, 4.84}, {3.5489664*^9, 4.91}, { + 3.5568288*^9, 4.98}, {3.5646912*^9, 5.06}, {3.5725536*^9, + 5.12}, {3.580416*^9, 5.18}, {3.5882784*^9, 5.24}, { + 3.5961408*^9, 5.3}, {3.6040032*^9, 5.35}, {3.6118656*^9, + 5.39}, {3.619728*^9, 5.42}, {3.6275904*^9, 5.47}, { + 3.6354528*^9, 5.51}, {3.6433152*^9, 5.54}, {3.6511776*^9, + 5.57}, {3.65904*^9, 5.61}, {3.6669024*^9, 5.64}, { + 3.6747648*^9, 5.67}, {3.683232*^9, 5.7}, {3.6910944*^9, + 5.73}, {3.698352*^9, 5.75}, {3.7068192*^9, 5.77}, { + 3.7146816*^9, 5.78}, {3.722544*^9, 5.82}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"28 Dec 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 148-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.4092576*^9, 4.59}, {3.4122816*^9, 4.36}, { + 3.4147008*^9, 4.23}, {3.41712*^9, 4.06}, {3.420144*^9, + 3.88}, {3.4225632*^9, 3.74}, {3.4304256*^9, 3.49}, { + 3.438288*^9, 3.37}, {3.4461504*^9, 3.37}, {3.4540128*^9, + 3.49}, {3.4618752*^9, 3.65}, {3.4697376*^9, 3.82}, { + 3.4776*^9, 3.97}, {3.4854624*^9, 4.13}, {3.4933248*^9, + 4.26}, {3.5011872*^9, 4.37}, {3.5090496*^9, 4.45}, { + 3.516912*^9, 4.54}, {3.5253792*^9, 4.62}, {3.5332416*^9, + 4.7}, {3.541104*^9, 4.76}, {3.5489664*^9, 4.83}, { + 3.5568288*^9, 4.9}, {3.5646912*^9, 4.97}, {3.5725536*^9, + 5.03}, {3.580416*^9, 5.09}, {3.5882784*^9, 5.15}, { + 3.5961408*^9, 5.22}, {3.6040032*^9, 5.26}, {3.6118656*^9, + 5.31}, {3.619728*^9, 5.34}, {3.6275904*^9, 5.4}, { + 3.6354528*^9, 5.43}, {3.6433152*^9, 5.47}, {3.6511776*^9, + 5.5}, {3.65904*^9, 5.54}, {3.6669024*^9, 5.57}, { + 3.6747648*^9, 5.6}, {3.683232*^9, 5.63}, {3.6910944*^9, + 5.66}, {3.698352*^9, 5.68}, {3.7068192*^9, 5.7}, { + 3.7146816*^9, 5.72}, {3.722544*^9, 5.75}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"31 Dec 2007\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 149-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.4092576*^9, 4.54}, {3.4122816*^9, 4.27}, { + 3.4147008*^9, 4.1}, {3.41712*^9, 3.94}, {3.420144*^9, + 3.75}, {3.4225632*^9, 3.6}, {3.4304256*^9, 3.32}, { + 3.438288*^9, 3.2}, {3.4461504*^9, 3.19}, {3.4540128*^9, + 3.3}, {3.4618752*^9, 3.44}, {3.4697376*^9, 3.61}, { + 3.4776*^9, 3.78}, {3.4854624*^9, 3.95}, {3.4933248*^9, + 4.09}, {3.5011872*^9, 4.21}, {3.5090496*^9, 4.3}, { + 3.516912*^9, 4.39}, {3.5253792*^9, 4.47}, {3.5332416*^9, + 4.55}, {3.541104*^9, 4.62}, {3.5489664*^9, 4.69}, { + 3.5568288*^9, 4.76}, {3.5646912*^9, 4.84}, {3.5725536*^9, + 4.91}, {3.580416*^9, 4.98}, {3.5882784*^9, 5.04}, { + 3.5961408*^9, 5.11}, {3.6040032*^9, 5.16}, {3.6118656*^9, + 5.21}, {3.619728*^9, 5.26}, {3.6275904*^9, 5.32}, { + 3.6354528*^9, 5.36}, {3.6433152*^9, 5.4}, {3.6511776*^9, + 5.44}, {3.65904*^9, 5.49}, {3.6669024*^9, 5.52}, { + 3.6747648*^9, 5.56}, {3.683232*^9, 5.59}, {3.6910944*^9, + 5.63}, {3.698352*^9, 5.65}, {3.7068192*^9, 5.68}, { + 3.7146816*^9, 5.7}, {3.722544*^9, 5.74}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"02 Jan 2008\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 150-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.4092576*^9, 4.52}, {3.4122816*^9, 4.24}, { + 3.4147008*^9, 4.09}, {3.41712*^9, 3.91}, {3.420144*^9, + 3.72}, {3.4225632*^9, 3.57}, {3.4304256*^9, 3.31}, { + 3.438288*^9, 3.18}, {3.4461504*^9, 3.17}, {3.4540128*^9, + 3.27}, {3.4618752*^9, 3.41}, {3.4697376*^9, 3.57}, { + 3.4776*^9, 3.73}, {3.4854624*^9, 3.91}, {3.4933248*^9, + 4.06}, {3.5011872*^9, 4.19}, {3.5090496*^9, 4.28}, { + 3.516912*^9, 4.38}, {3.5253792*^9, 4.46}, {3.5332416*^9, + 4.55}, {3.541104*^9, 4.62}, {3.5489664*^9, 4.7}, { + 3.5568288*^9, 4.78}, {3.5646912*^9, 4.86}, {3.5725536*^9, + 4.93}, {3.580416*^9, 5.01}, {3.5882784*^9, 5.08}, { + 3.5961408*^9, 5.15}, {3.6040032*^9, 5.21}, {3.6118656*^9, + 5.26}, {3.619728*^9, 5.31}, {3.6275904*^9, 5.38}, { + 3.6354528*^9, 5.42}, {3.6433152*^9, 5.47}, {3.6511776*^9, + 5.51}, {3.65904*^9, 5.56}, {3.6669024*^9, 5.6}, { + 3.6747648*^9, 5.64}, {3.683232*^9, 5.67}, {3.6910944*^9, + 5.71}, {3.698352*^9, 5.73}, {3.7068192*^9, 5.76}, { + 3.7146816*^9, 5.78}, {3.722544*^9, 5.82}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"03 Jan 2008\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 151-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.4092576*^9, 4.46}, {3.4122816*^9, 4.16}, { + 3.4147008*^9, 3.97}, {3.41712*^9, 3.8}, {3.420144*^9, + 3.62}, {3.4225632*^9, 3.48}, {3.4304256*^9, 3.21}, { + 3.438288*^9, 3.08}, {3.4461504*^9, 3.06}, {3.4540128*^9, + 3.13}, {3.4618752*^9, 3.26}, {3.4697376*^9, 3.41}, { + 3.4776*^9, 3.58}, {3.4854624*^9, 3.76}, {3.4933248*^9, + 3.92}, {3.5011872*^9, 4.06}, {3.5090496*^9, 4.17}, { + 3.516912*^9, 4.27}, {3.5253792*^9, 4.37}, {3.5332416*^9, + 4.47}, {3.541104*^9, 4.55}, {3.5489664*^9, 4.64}, { + 3.5568288*^9, 4.72}, {3.5646912*^9, 4.82}, {3.5725536*^9, + 4.89}, {3.580416*^9, 4.97}, {3.5882784*^9, 5.04}, { + 3.5961408*^9, 5.12}, {3.6040032*^9, 5.18}, {3.6118656*^9, + 5.24}, {3.619728*^9, 5.29}, {3.6275904*^9, 5.35}, { + 3.6354528*^9, 5.4}, {3.6433152*^9, 5.44}, {3.6511776*^9, + 5.48}, {3.65904*^9, 5.54}, {3.6669024*^9, 5.58}, { + 3.6747648*^9, 5.62}, {3.683232*^9, 5.65}, {3.6910944*^9, + 5.69}, {3.698352*^9, 5.72}, {3.7068192*^9, 5.74}, { + 3.7146816*^9, 5.77}, {3.722544*^9, 5.81}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"04 Jan 2008\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 152-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.4092576*^9, 4.43}, {3.4122816*^9, 4.1}, { + 3.4147008*^9, 3.94}, {3.41712*^9, 3.78}, {3.420144*^9, + 3.61}, {3.4225632*^9, 3.48}, {3.4304256*^9, 3.23}, { + 3.438288*^9, 3.11}, {3.4461504*^9, 3.09}, {3.4540128*^9, + 3.16}, {3.4618752*^9, 3.27}, {3.4697376*^9, 3.41}, { + 3.4776*^9, 3.56}, {3.4854624*^9, 3.74}, {3.4933248*^9, + 3.89}, {3.5011872*^9, 4.03}, {3.5090496*^9, 4.13}, { + 3.516912*^9, 4.24}, {3.5253792*^9, 4.34}, {3.5332416*^9, + 4.44}, {3.541104*^9, 4.52}, {3.5489664*^9, 4.61}, { + 3.5568288*^9, 4.69}, {3.5646912*^9, 4.79}, {3.5725536*^9, + 4.86}, {3.580416*^9, 4.94}, {3.5882784*^9, 5.01}, { + 3.5961408*^9, 5.09}, {3.6040032*^9, 5.15}, {3.6118656*^9, + 5.21}, {3.619728*^9, 5.26}, {3.6275904*^9, 5.32}, { + 3.6354528*^9, 5.37}, {3.6433152*^9, 5.41}, {3.6511776*^9, + 5.45}, {3.65904*^9, 5.51}, {3.6669024*^9, 5.55}, { + 3.6747648*^9, 5.58}, {3.683232*^9, 5.61}, {3.6910944*^9, + 5.66}, {3.698352*^9, 5.68}, {3.7068192*^9, 5.7}, { + 3.7146816*^9, 5.73}, {3.722544*^9, 5.77}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"07 Jan 2008\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 153-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.4092576*^9, 4.4}, {3.4122816*^9, 4.09}, { + 3.4147008*^9, 3.92}, {3.41712*^9, 3.77}, {3.420144*^9, + 3.59}, {3.4225632*^9, 3.46}, {3.4304256*^9, 3.22}, { + 3.438288*^9, 3.11}, {3.4461504*^9, 3.1}, {3.4540128*^9, + 3.17}, {3.4618752*^9, 3.28}, {3.4697376*^9, 3.41}, { + 3.4776*^9, 3.55}, {3.4854624*^9, 3.72}, {3.4933248*^9, + 3.87}, {3.5011872*^9, 4.}, {3.5090496*^9, 4.11}, { + 3.516912*^9, 4.22}, {3.5253792*^9, 4.32}, {3.5332416*^9, + 4.42}, {3.541104*^9, 4.5}, {3.5489664*^9, 4.59}, { + 3.5568288*^9, 4.67}, {3.5646912*^9, 4.77}, {3.5725536*^9, + 4.84}, {3.580416*^9, 4.92}, {3.5882784*^9, 4.99}, { + 3.5961408*^9, 5.07}, {3.6040032*^9, 5.13}, {3.6118656*^9, + 5.19}, {3.619728*^9, 5.24}, {3.6275904*^9, 5.31}, { + 3.6354528*^9, 5.35}, {3.6433152*^9, 5.4}, {3.6511776*^9, + 5.44}, {3.65904*^9, 5.49}, {3.6669024*^9, 5.53}, { + 3.6747648*^9, 5.57}, {3.683232*^9, 5.6}, {3.6910944*^9, + 5.65}, {3.698352*^9, 5.67}, {3.7068192*^9, 5.69}, { + 3.7146816*^9, 5.72}, {3.722544*^9, 5.76}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"08 Jan 2008\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 154-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.4092576*^9, 4.33}, {3.4122816*^9, 4.02}, { + 3.4147008*^9, 3.83}, {3.41712*^9, 3.67}, {3.420144*^9, + 3.49}, {3.4225632*^9, 3.37}, {3.4304256*^9, 3.15}, { + 3.438288*^9, 3.06}, {3.4461504*^9, 3.06}, {3.4540128*^9, + 3.13}, {3.4618752*^9, 3.24}, {3.4697376*^9, 3.37}, { + 3.4776*^9, 3.5}, {3.4854624*^9, 3.67}, {3.4933248*^9, + 3.81}, {3.5011872*^9, 3.95}, {3.5090496*^9, 4.06}, { + 3.516912*^9, 4.17}, {3.5253792*^9, 4.27}, {3.5332416*^9, + 4.37}, {3.541104*^9, 4.45}, {3.5489664*^9, 4.54}, { + 3.5568288*^9, 4.63}, {3.5646912*^9, 4.73}, {3.5725536*^9, + 4.8}, {3.580416*^9, 4.88}, {3.5882784*^9, 4.95}, { + 3.5961408*^9, 5.04}, {3.6040032*^9, 5.1}, {3.6118656*^9, + 5.16}, {3.619728*^9, 5.21}, {3.6275904*^9, 5.28}, { + 3.6354528*^9, 5.33}, {3.6433152*^9, 5.37}, {3.6511776*^9, + 5.42}, {3.65904*^9, 5.47}, {3.6669024*^9, 5.51}, { + 3.6747648*^9, 5.55}, {3.683232*^9, 5.59}, {3.6910944*^9, + 5.63}, {3.698352*^9, 5.66}, {3.7068192*^9, 5.68}, { + 3.7146816*^9, 5.7}, {3.722544*^9, 5.74}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"09 Jan 2008\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 155-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.4092576*^9, 4.29}, {3.4122816*^9, 3.96}, { + 3.4147008*^9, 3.76}, {3.41712*^9, 3.6}, {3.420144*^9, + 3.43}, {3.4225632*^9, 3.31}, {3.4304256*^9, 3.12}, { + 3.438288*^9, 3.06}, {3.4461504*^9, 3.08}, {3.4540128*^9, + 3.17}, {3.4618752*^9, 3.29}, {3.4697376*^9, 3.42}, { + 3.4776*^9, 3.56}, {3.4854624*^9, 3.73}, {3.4933248*^9, + 3.88}, {3.5011872*^9, 4.02}, {3.5090496*^9, 4.13}, { + 3.516912*^9, 4.25}, {3.5253792*^9, 4.35}, {3.5332416*^9, + 4.46}, {3.541104*^9, 4.55}, {3.5489664*^9, 4.64}, { + 3.5568288*^9, 4.74}, {3.5646912*^9, 4.84}, {3.5725536*^9, + 4.91}, {3.580416*^9, 5.}, {3.5882784*^9, 5.07}, { + 3.5961408*^9, 5.16}, {3.6040032*^9, 5.22}, {3.6118656*^9, + 5.29}, {3.619728*^9, 5.35}, {3.6275904*^9, 5.42}, { + 3.6354528*^9, 5.47}, {3.6433152*^9, 5.52}, {3.6511776*^9, + 5.56}, {3.65904*^9, 5.62}, {3.6669024*^9, 5.67}, { + 3.6747648*^9, 5.71}, {3.683232*^9, 5.74}, {3.6910944*^9, + 5.79}, {3.698352*^9, 5.82}, {3.7068192*^9, 5.84}, { + 3.7146816*^9, 5.86}, {3.722544*^9, 5.9}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"10 Jan 2008\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 156-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.4092576*^9, 4.16}, {3.4122816*^9, 3.78}, { + 3.4147008*^9, 3.57}, {3.41712*^9, 3.42}, {3.420144*^9, + 3.26}, {3.4225632*^9, 3.14}, {3.4304256*^9, 2.95}, { + 3.438288*^9, 2.9}, {3.4461504*^9, 2.92}, {3.4540128*^9, + 3.02}, {3.4618752*^9, 3.15}, {3.4697376*^9, 3.3}, { + 3.4776*^9, 3.46}, {3.4854624*^9, 3.63}, {3.4933248*^9, + 3.79}, {3.5011872*^9, 3.92}, {3.5090496*^9, 4.04}, { + 3.516912*^9, 4.16}, {3.5253792*^9, 4.27}, {3.5332416*^9, + 4.38}, {3.541104*^9, 4.47}, {3.5489664*^9, 4.56}, { + 3.5568288*^9, 4.66}, {3.5646912*^9, 4.77}, {3.5725536*^9, + 4.85}, {3.580416*^9, 4.94}, {3.5882784*^9, 5.02}, { + 3.5961408*^9, 5.11}, {3.6040032*^9, 5.18}, {3.6118656*^9, + 5.24}, {3.619728*^9, 5.31}, {3.6275904*^9, 5.39}, { + 3.6354528*^9, 5.44}, {3.6433152*^9, 5.48}, {3.6511776*^9, + 5.53}, {3.65904*^9, 5.59}, {3.6669024*^9, 5.64}, { + 3.6747648*^9, 5.68}, {3.683232*^9, 5.71}, {3.6910944*^9, + 5.76}, {3.698352*^9, 5.79}, {3.7068192*^9, 5.81}, { + 3.7146816*^9, 5.83}, {3.722544*^9, 5.87}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"11 Jan 2008\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 157-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.4122816*^9, 3.69}, {3.4147008*^9, 3.53}, { + 3.41712*^9, 3.37}, {3.420144*^9, 3.2}, {3.4225632*^9, + 3.08}, {3.4304256*^9, 2.91}, {3.438288*^9, 2.86}, { + 3.4461504*^9, 2.89}, {3.4540128*^9, 3.}, {3.4618752*^9, + 3.15}, {3.4697376*^9, 3.3}, {3.4776*^9, 3.46}, { + 3.4854624*^9, 3.63}, {3.4933248*^9, 3.79}, {3.5011872*^9, + 3.92}, {3.5090496*^9, 4.03}, {3.516912*^9, 4.15}, { + 3.5253792*^9, 4.26}, {3.5332416*^9, 4.37}, {3.541104*^9, + 4.46}, {3.5489664*^9, 4.55}, {3.5568288*^9, 4.65}, { + 3.5646912*^9, 4.75}, {3.5725536*^9, 4.83}, {3.580416*^9, + 4.92}, {3.5882784*^9, 5.}, {3.5961408*^9, 5.1}, { + 3.6040032*^9, 5.16}, {3.6118656*^9, 5.23}, {3.619728*^9, + 5.29}, {3.6275904*^9, 5.37}, {3.6354528*^9, 5.42}, { + 3.6433152*^9, 5.47}, {3.6511776*^9, 5.51}, {3.65904*^9, + 5.57}, {3.6669024*^9, 5.62}, {3.6747648*^9, 5.66}, { + 3.683232*^9, 5.69}, {3.6910944*^9, 5.74}, {3.698352*^9, + 5.77}, {3.7068192*^9, 5.79}, {3.7146816*^9, 5.81}, { + 3.722544*^9, 5.85}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"14 Jan 2008\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 158-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.4122816*^9, 3.73}, {3.4147008*^9, 3.57}, { + 3.41712*^9, 3.41}, {3.420144*^9, 3.2}, {3.4225632*^9, + 3.08}, {3.4304256*^9, 2.89}, {3.438288*^9, 2.82}, { + 3.4461504*^9, 2.83}, {3.4540128*^9, 2.92}, {3.4618752*^9, + 3.05}, {3.4697376*^9, 3.21}, {3.4776*^9, 3.35}, { + 3.4854624*^9, 3.52}, {3.4933248*^9, 3.67}, {3.5011872*^9, + 3.8}, {3.5090496*^9, 3.91}, {3.516912*^9, 4.03}, { + 3.5253792*^9, 4.14}, {3.5332416*^9, 4.25}, {3.541104*^9, + 4.34}, {3.5489664*^9, 4.43}, {3.5568288*^9, 4.53}, { + 3.5646912*^9, 4.63}, {3.5725536*^9, 4.71}, {3.580416*^9, + 4.8}, {3.5882784*^9, 4.88}, {3.5961408*^9, 4.98}, { + 3.6040032*^9, 5.04}, {3.6118656*^9, 5.11}, {3.619728*^9, + 5.17}, {3.6275904*^9, 5.25}, {3.6354528*^9, 5.3}, { + 3.6433152*^9, 5.35}, {3.6511776*^9, 5.39}, {3.65904*^9, + 5.45}, {3.6669024*^9, 5.5}, {3.6747648*^9, 5.54}, { + 3.683232*^9, 5.57}, {3.6910944*^9, 5.62}, {3.698352*^9, + 5.65}, {3.7068192*^9, 5.67}, {3.7146816*^9, 5.7}, { + 3.722544*^9, 5.74}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"15 Jan 2008\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 159-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.4122816*^9, 3.72}, {3.4147008*^9, 3.58}, { + 3.41712*^9, 3.43}, {3.420144*^9, 3.23}, {3.4225632*^9, + 3.09}, {3.4304256*^9, 2.89}, {3.438288*^9, 2.82}, { + 3.4461504*^9, 2.81}, {3.4540128*^9, 2.89}, {3.4618752*^9, + 3.02}, {3.4697376*^9, 3.17}, {3.4776*^9, 3.33}, { + 3.4854624*^9, 3.51}, {3.4933248*^9, 3.67}, {3.5011872*^9, + 3.82}, {3.5090496*^9, 3.94}, {3.516912*^9, 4.07}, { + 3.5253792*^9, 4.19}, {3.5332416*^9, 4.31}, {3.541104*^9, + 4.41}, {3.5489664*^9, 4.51}, {3.5568288*^9, 4.61}, { + 3.5646912*^9, 4.72}, {3.5725536*^9, 4.8}, {3.580416*^9, + 4.89}, {3.5882784*^9, 4.97}, {3.5961408*^9, 5.06}, { + 3.6040032*^9, 5.13}, {3.6118656*^9, 5.19}, {3.619728*^9, + 5.26}, {3.6275904*^9, 5.33}, {3.6354528*^9, 5.38}, { + 3.6433152*^9, 5.43}, {3.6511776*^9, 5.47}, {3.65904*^9, + 5.53}, {3.6669024*^9, 5.58}, {3.6747648*^9, 5.62}, { + 3.683232*^9, 5.65}, {3.6910944*^9, 5.7}, {3.698352*^9, + 5.73}, {3.7068192*^9, 5.75}, {3.7146816*^9, 5.78}, { + 3.722544*^9, 5.81}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"16 Jan 2008\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 160-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.4122816*^9, 3.71}, {3.4147008*^9, 3.55}, { + 3.41712*^9, 3.37}, {3.420144*^9, 3.15}, {3.4225632*^9, + 3.}, {3.4304256*^9, 2.79}, {3.438288*^9, 2.72}, { + 3.4461504*^9, 2.72}, {3.4540128*^9, 2.81}, {3.4618752*^9, + 2.95}, {3.4697376*^9, 3.11}, {3.4776*^9, 3.26}, { + 3.4854624*^9, 3.44}, {3.4933248*^9, 3.6}, {3.5011872*^9, + 3.74}, {3.5090496*^9, 3.86}, {3.516912*^9, 3.99}, { + 3.5253792*^9, 4.11}, {3.5332416*^9, 4.23}, {3.541104*^9, + 4.32}, {3.5489664*^9, 4.42}, {3.5568288*^9, 4.52}, { + 3.5646912*^9, 4.62}, {3.5725536*^9, 4.7}, {3.580416*^9, + 4.79}, {3.5882784*^9, 4.87}, {3.5961408*^9, 4.97}, { + 3.6040032*^9, 5.03}, {3.6118656*^9, 5.1}, {3.619728*^9, + 5.16}, {3.6275904*^9, 5.24}, {3.6354528*^9, 5.29}, { + 3.6433152*^9, 5.33}, {3.6511776*^9, 5.38}, {3.65904*^9, + 5.44}, {3.6669024*^9, 5.48}, {3.6747648*^9, 5.52}, { + 3.683232*^9, 5.55}, {3.6910944*^9, 5.6}, {3.698352*^9, + 5.63}, {3.7068192*^9, 5.65}, {3.7146816*^9, 5.68}, { + 3.722544*^9, 5.71}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"17 Jan 2008\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None], 161-> + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.4122816*^9, 3.66}, {3.4147008*^9, 3.49}, { + 3.41712*^9, 3.28}, {3.420144*^9, 3.07}, {3.4225632*^9, + 2.92}, {3.4304256*^9, 2.71}, {3.438288*^9, 2.66}, { + 3.4461504*^9, 2.68}, {3.4540128*^9, 2.77}, {3.4618752*^9, + 2.91}, {3.4697376*^9, 3.06}, {3.4776*^9, 3.22}, { + 3.4854624*^9, 3.4}, {3.4933248*^9, 3.57}, {3.5011872*^9, + 3.72}, {3.5090496*^9, 3.85}, {3.516912*^9, 3.99}, { + 3.5253792*^9, 4.11}, {3.5332416*^9, 4.24}, {3.541104*^9, + 4.34}, {3.5489664*^9, 4.44}, {3.5568288*^9, 4.55}, { + 3.5646912*^9, 4.66}, {3.5725536*^9, 4.74}, {3.580416*^9, + 4.83}, {3.5882784*^9, 4.92}, {3.5961408*^9, 5.01}, { + 3.6040032*^9, 5.08}, {3.6118656*^9, 5.15}, {3.619728*^9, + 5.21}, {3.6275904*^9, 5.29}, {3.6354528*^9, 5.34}, { + 3.6433152*^9, 5.39}, {3.6511776*^9, 5.44}, {3.65904*^9, + 5.5}, {3.6669024*^9, 5.54}, {3.6747648*^9, 5.58}, { + 3.683232*^9, 5.61}, {3.6910944*^9, 5.66}, {3.698352*^9, + 5.69}, {3.7068192*^9, 5.71}, {3.7146816*^9, 5.74}, { + 3.722544*^9, 5.77}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3386966400, 3.}, {3.3869664*^9, 3.}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox[ + StyleBox[ + "\"18 Jan 2008\"", FontFamily -> "Courier", Bold, Italic, + StripOnInput -> False], TraditionalForm], + + PlotRange-> + NCache[{{3386966400, 3728851200}, {2.5, 6.5}}, {{ + 3.3869664*^9, 3.7288512*^9}, {2.5, 6.5}}], + PlotRangeClipping->True, + PlotRangePadding->{Automatic, Automatic}, + Ticks->None]}, Dynamic[$CellContext`i3$$], + Alignment->Automatic, + ImageSize->All], + Identity, + Editable->True, + Selectable->True]], + ScriptLevel->0, + Background->GrayLevel[1]], + ImageMargins->10], + Deployed->False, + StripOnInput->False, + GraphicsBoxOptions->{PreserveImageOptions->True}, + Graphics3DBoxOptions->{PreserveImageOptions->True}], + Identity, + Editable->False, + Selectable->False], + Alignment->{Left, Center}, + Background->GrayLevel[1], + Frame->1, + FrameStyle->GrayLevel[0, 0.2], + StripOnInput->False]} + }, + ColumnsEqual->False, + GridBoxAlignment->{ + "Columns" -> {{Left}}, "ColumnsIndexed" -> {}, "Rows" -> {{Top}}, + "RowsIndexed" -> {}}, + GridBoxDividers->{ + "Columns" -> {{False}}, "ColumnsIndexed" -> {}, "Rows" -> {{False}}, + "RowsIndexed" -> {}}, + GridBoxItemSize->{ + "Columns" -> {{Automatic}}, "Rows" -> {{Automatic}}}, + GridBoxSpacings->{"Columns" -> { + Offset[0.7], { + Offset[0.5599999999999999]}, + Offset[0.7]}, "ColumnsIndexed" -> {}, "Rows" -> { + Offset[0.4], { + Offset[0.8]}, + Offset[0.4]}, "RowsIndexed" -> {}}, + RowsEqual->False], + "Grid"], If[ + CurrentValue["SelectionOver"], + Manipulate`Dump`ReadControllerState[ + Map[Manipulate`Dump`updateOneVar[#, + CurrentValue["PreviousFormatTime"], + CurrentValue["CurrentFormatTime"]]& , { + + Manipulate`Dump`controllerLink[{$CellContext`i3$$, \ +$CellContext`i3$19001$$}, "X1", + If["DefaultAbsolute", True, "JB1"], False, {1, 161, 1}, 161, + 1.]}], + CurrentValue[{ + "ControllerData", { + "Gamepad", "Joystick", "Multi-Axis Controller"}}], {}]], + ImageSizeCache->{480., {183.5, 190.5}}], + DefaultBaseStyle->{}, + FrameMargins->{{5, 5}, {5, 5}}], + BaselinePosition->Automatic, + ImageMargins->0], + Deinitialization:>None, + DynamicModuleValues:>{}, + SynchronousInitialization->True, + UnsavedVariables:>{Typeset`initDone$$}, + UntrackedVariables:>{Typeset`size$$}], "Manipulate", + Deployed->True, + StripOnInput->False], + Manipulate`InterpretManipulate[1]]], "Output", + CellChangeTimes->{{3.4112375431875*^9, 3.411237549640625*^9}, { + 3.41123764946875*^9, 3.411237653484375*^9}, {3.41123778334375*^9, + 3.4112377916875*^9}, {3.4112378274375*^9, 3.411237832*^9}, { + 3.41123791025*^9, 3.411237918171875*^9}, {3.4112379524375*^9, + 3.411237967015625*^9}, {3.411238021328125*^9, 3.411238083609375*^9}, { + 3.41123990209375*^9, 3.41123993071875*^9}, {3.411249538609375*^9, + 3.411249546359375*^9}, 3.41124962440625*^9, 3.41124965965625*^9, { + 3.41124971146875*^9, 3.41124972628125*^9}, {3.411250103375*^9, + 3.411250127859375*^9}, {3.41125018640625*^9, 3.411250187453125*^9}, { + 3.411250388296875*^9, 3.4112504060625*^9}, {3.411252900203125*^9, + 3.4112529018125*^9}, 3.4112814265625*^9, 3.411281469375*^9, { + 3.4112815370625*^9, 3.411281561953125*^9}, {3.411286607875*^9, + 3.4112866103125*^9}, {3.4112886257385283`*^9, 3.4112886454756355`*^9}, + 3.4113650891875*^9, {3.411365125484375*^9, 3.411365128515625*^9}, { + 3.4114806050833063`*^9, 3.411480606330186*^9}, {3.4114817432821283`*^9, + 3.411481750841338*^9}}] +}, Open ]] +}, Open ]], + +Cell[CellGroupData[{ + +Cell["Export database", "Section", + CellChangeTimes->{{3.41148166164266*^9, 3.411481664697516*^9}}], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{"ExportFuturesRates", "[", + RowBox[{ + RowBox[{"ToFileName", "[", + RowBox[{ + RowBox[{"{", "$CMEEuroDollarDataDirectory", "}"}], ",", + "\"\<eurodollardata.mef\>\""}], "]"}], ",", "tempdata1"}], + "]"}]], "Input", + CellChangeTimes->{{3.4114816668795557`*^9, 3.411481711377586*^9}, { + 3.4114817615956783`*^9, 3.411481767845664*^9}, {3.411483782375658*^9, + 3.411483797811351*^9}}], + +Cell[BoxData["\<\"O:\\\\cme_pdfs\\\\eurodollardata.mef\"\>"], "Output", + CellChangeTimes->{3.411481714525958*^9, 3.4114837999538937`*^9, + 3.4114840926223154`*^9}] +}, Open ]] +}, Open ]], + +Cell[CellGroupData[{ + +Cell["Download PDFs from CME website", "Section", + CellChangeTimes->{{3.410366690859375*^9, 3.41036669496875*^9}, { + 3.4114817861124563`*^9, 3.411481794793858*^9}}], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{"MostRecentDay", "[", "cmedata", "]"}]], "Input", + CellChangeTimes->{{3.411165939890625*^9, 3.41116594234375*^9}, { + 3.4112153423672066`*^9, 3.411215343723189*^9}}], + +Cell[BoxData[ + InterpretationBox[ + RowBox[{"\<\"Most Recent Day:\"\>", " ", "\<\"25 Jan 2008\"\>", + " ", "\<\"Day\"\>", " ", "17"}], + Row[{"Most Recent Day:", "25 Jan 2008", "Day", 17}, " "]]], "Output", + CellChangeTimes->{ + 3.411165942765625*^9, 3.411166199328125*^9, 3.411214482440829*^9, + 3.411215273336813*^9, 3.4112153441907687`*^9, 3.4112210113672037`*^9, + 3.411235727890625*^9, {3.411365089046875*^9, 3.411365117765625*^9}, + 3.411371735578125*^9, 3.4114806292416058`*^9, 3.411480989761372*^9, + 3.411481731592628*^9, 3.4114818451366377`*^9, 3.411483825539298*^9}] +}, Open ]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{"DateToCMEDay", "[", "]"}]], "Input", + CellChangeTimes->{{3.411481821617364*^9, 3.411481826043788*^9}}], + +Cell[BoxData["27"], "Output", + CellChangeTimes->{3.411481826168476*^9, 3.4114838271344757`*^9}] +}, Open ]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{"days2008", "=", + RowBox[{"Range", "[", + RowBox[{ + RowBox[{ + RowBox[{"cmedata", "[", + RowBox[{"[", + RowBox[{ + RowBox[{"-", "1"}], ",", "2"}], "]"}], "]"}], "+", "1"}], ",", + RowBox[{ + RowBox[{"DateToCMEDay", "[", "]"}], "-", "1"}]}], "]"}]}]], "Input", + CellChangeTimes->{{3.41036811121875*^9, 3.410368145046875*^9}, { + 3.4103682569375*^9, 3.410368261453125*^9}, {3.411481853475148*^9, + 3.411481896476922*^9}, {3.4114820337895823`*^9, 3.4114820341792316`*^9}}], + +Cell[BoxData[ + RowBox[{"{", + RowBox[{ + "18", ",", "19", ",", "20", ",", "21", ",", "22", ",", "23", ",", "24", ",", + "25", ",", "26"}], "}"}]], "Output", + CellChangeTimes->{ + 3.41036856228125*^9, {3.41148186215655*^9, 3.411481897053604*^9}, + 3.411482034397436*^9, 3.41148382879221*^9}] +}, Open ]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{ + RowBox[{"temp", "=", + RowBox[{"Monitor", "[", + RowBox[{ + RowBox[{"Table", "[", "\[IndentingNewLine]", + RowBox[{ + RowBox[{"With", "[", + RowBox[{ + RowBox[{"{", + RowBox[{"url", "=", + RowBox[{"URLforPDFfromCME", "[", + RowBox[{"52", ",", + RowBox[{"{", + RowBox[{"2008", ",", "day"}], "}"}]}], "]"}]}], "}"}], ",", + "\[IndentingNewLine]", + RowBox[{"Export", "[", + RowBox[{ + RowBox[{ + RowBox[{"StringSplit", "[", + RowBox[{"url", ",", "\"\</\>\""}], "]"}], "[", + RowBox[{"[", + RowBox[{"-", "1"}], "]"}], "]"}], ",", + RowBox[{"Import", "[", + RowBox[{"url", ",", "\"\<Binary\>\""}], "]"}], ",", + "\"\<Binary\>\""}], "]"}]}], "]"}], ",", "\[IndentingNewLine]", + RowBox[{"{", + RowBox[{"day", ",", "days2008"}], "}"}]}], "]"}], ",", "day"}], + "]"}]}], ";"}]], "Input", + CellChangeTimes->{{3.410366723515625*^9, 3.4103667253125*^9}, { + 3.4103669039375*^9, 3.410366929109375*^9}, {3.410367131640625*^9, + 3.410367132515625*^9}, {3.410367192796875*^9, 3.410367193640625*^9}, { + 3.410367246546875*^9, 3.410367334734375*^9}, {3.410367364828125*^9, + 3.410367406828125*^9}, {3.41036743975*^9, 3.4103674706875*^9}, { + 3.410367583859375*^9, 3.4103676405*^9}, {3.410367672875*^9, + 3.410367679046875*^9}, {3.41036815334375*^9, 3.4103681778125*^9}, { + 3.41036855815625*^9, 3.410368568328125*^9}, {3.410368949015625*^9, + 3.410368952703125*^9}, {3.410369223484375*^9, 3.41036922371875*^9}, { + 3.4114819198715076`*^9, 3.4114819281320877`*^9}}], + +Cell[BoxData[ + RowBox[{ + RowBox[{"FetchURL", "::", "\<\"conopen\"\>"}], ":", + " ", "\<\"The connection to URL \ +\\!\\(\\\"http://www.cmegroup.com/daily_bulletin/Section52_Euro_Dollar_Put_\ +Options_2007253.pdf\\\"\\) cannot be opened. If the URL is correct, you might \ +need to configure your firewall program, or you might need to set a proxy in \ +the Internet Connectivity tab of the Preferences dialog (or by calling \ +SetInternetProxy).\"\>"}]], "Message", "MSG", + CellChangeTimes->{3.4103691716875*^9, 3.41036952459375*^9}], + +Cell[BoxData[ + RowBox[{ + RowBox[{"BinaryWrite", "::", "\<\"nocoerce\"\>"}], ":", + " ", "\<\"\\!\\($Failed\\) cannot be coerced to the specified format. \ +\\!\\(\\*ButtonBox[\\\"\[RightSkeleton]\\\", ButtonStyle->\\\"Link\\\", \ +ButtonFrame->None, ButtonData:>\\\"paclet:ref/BinaryWrite\\\", ButtonNote -> \ +\\\"BinaryWrite::nocoerce\\\"]\\)\"\>"}]], "Message", "MSG", + CellChangeTimes->{3.4103691716875*^9, 3.410369524625*^9}] +}, Open ]], + +Cell[BoxData[ + RowBox[{ + RowBox[{"WritePDFToDirectory", "[", + RowBox[{"section_", ",", + RowBox[{"{", + RowBox[{"year_", ",", "day_"}], "}"}]}], "]"}], ":=", + "\[IndentingNewLine]", + RowBox[{"With", "[", + RowBox[{ + RowBox[{"{", + RowBox[{"url", "=", + RowBox[{"URLforPDFfromCME", "[", + RowBox[{"9", ",", + RowBox[{"{", + RowBox[{"year", ",", "day"}], "}"}]}], "]"}]}], "}"}], ",", + "\[IndentingNewLine]", + RowBox[{"Export", "[", + RowBox[{ + RowBox[{"ToFileName", "[", + RowBox[{ + RowBox[{"{", "$CMEEuroDollarSection09Directory", "}"}], ",", + RowBox[{ + RowBox[{"StringSplit", "[", + RowBox[{"url", ",", "\"\</\>\""}], "]"}], "[", + RowBox[{"[", + RowBox[{"-", "1"}], "]"}], "]"}]}], "]"}], ",", + RowBox[{"Import", "[", + RowBox[{"url", ",", "\"\<Binary\>\""}], "]"}], ",", "\"\<Binary\>\""}], + "]"}]}], "]"}]}]], "Input", + CellChangeTimes->{{3.411482053490286*^9, 3.411482152648418*^9}, { + 3.411482198330984*^9, 3.411482205578474*^9}}], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{"Table", "[", + RowBox[{ + RowBox[{"WritePDFToDirectory", "[", + RowBox[{"9", ",", + RowBox[{"{", + RowBox[{"2008", ",", "day"}], "}"}]}], "]"}], ",", + RowBox[{"{", + RowBox[{"day", ",", "days2008"}], "}"}]}], "]"}]], "Input", + CellChangeTimes->{{3.411482134256938*^9, 3.4114821556253443`*^9}, { + 3.4114835487431593`*^9, 3.4114835494015684`*^9}, {3.4114839526676426`*^9, + 3.4114839684735155`*^9}}], + +Cell[BoxData[ + RowBox[{"{", + RowBox[{"\<\"O:\\\\cme_pdfs\\\\Section09\\\\Section09_Interest_Rate_And_\ +Energy_Futures_2008018.pdf\"\>", + ",", "\<\"O:\\\\cme_pdfs\\\\Section09\\\\Section09_Interest_Rate_And_\ +Energy_Futures_2008019.pdf\"\>", + ",", "\<\"O:\\\\cme_pdfs\\\\Section09\\\\Section09_Interest_Rate_And_\ +Energy_Futures_2008020.pdf\"\>", + ",", "\<\"O:\\\\cme_pdfs\\\\Section09\\\\Section09_Interest_Rate_And_\ +Energy_Futures_2008021.pdf\"\>", + ",", "\<\"O:\\\\cme_pdfs\\\\Section09\\\\Section09_Interest_Rate_And_\ +Energy_Futures_2008022.pdf\"\>", + ",", "\<\"O:\\\\cme_pdfs\\\\Section09\\\\Section09_Interest_Rate_And_\ +Energy_Futures_2008023.pdf\"\>", + ",", "\<\"O:\\\\cme_pdfs\\\\Section09\\\\Section09_Interest_Rate_And_\ +Energy_Futures_2008024.pdf\"\>", + ",", "\<\"O:\\\\cme_pdfs\\\\Section09\\\\Section09_Interest_Rate_And_\ +Energy_Futures_2008025.pdf\"\>", + ",", "\<\"O:\\\\cme_pdfs\\\\Section09\\\\Section09_Interest_Rate_And_\ +Energy_Futures_2008026.pdf\"\>"}], "}"}]], "Output", + CellChangeTimes->{3.411482156685192*^9, 3.411482231420062*^9, + 3.411483550138359*^9, 3.4114839742424245`*^9}] +}, Open ]] +}, Open ]], + +Cell[CellGroupData[{ + +Cell["Find PDFs not in database", "Section", + CellChangeTimes->{{3.411482302289604*^9, 3.411482308742208*^9}}], + +Cell[BoxData[ + RowBox[{ + RowBox[{"CMEPDFFileName", "[", + RowBox[{"section_", ",", + RowBox[{"{", + RowBox[{"year_", ",", "day_"}], "}"}]}], "]"}], ":=", + RowBox[{ + RowBox[{"StringSplit", "[", + RowBox[{ + RowBox[{"URLforPDFfromCME", "[", + RowBox[{"9", ",", + RowBox[{"{", + RowBox[{"year", ",", "day"}], "}"}]}], "]"}], ",", "\"\</\>\""}], + "]"}], "[", + RowBox[{"[", + RowBox[{"-", "1"}], "]"}], "]"}]}]], "Input", + CellChangeTimes->{{3.4114826862039557`*^9, 3.411482792422546*^9}}], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{"Complement", "[", + RowBox[{ + RowBox[{"CMEEurodollarSection09PDFs", "[", "]"}], ",", " ", + RowBox[{"Union", "[", + RowBox[{"dateDay", "[", + RowBox[{"[", + RowBox[{"All", ",", + RowBox[{"{", + RowBox[{"1", ",", + RowBox[{"-", "1"}]}], "}"}]}], "]"}], "]"}], "]"}]}], "]"}]], "Input",\ + + CellChangeTimes->{{3.41148234165984*^9, 3.4114823644154*^9}, { + 3.41148253001665*^9, 3.411482546600154*^9}}], + +Cell[BoxData[ + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "16"}], "}"}], ",", + RowBox[{"{", + RowBox[{"2008", ",", "18"}], "}"}], ",", + RowBox[{"{", + RowBox[{"2008", ",", "19"}], "}"}], ",", + RowBox[{"{", + RowBox[{"2008", ",", "20"}], "}"}], ",", + RowBox[{"{", + RowBox[{"2008", ",", "21"}], "}"}], ",", + RowBox[{"{", + RowBox[{"2008", ",", "22"}], "}"}], ",", + RowBox[{"{", + RowBox[{"2008", ",", "23"}], "}"}], ",", + RowBox[{"{", + RowBox[{"2008", ",", "24"}], "}"}], ",", + RowBox[{"{", + RowBox[{"2008", ",", "25"}], "}"}], ",", + RowBox[{"{", + RowBox[{"2008", ",", "26"}], "}"}]}], "}"}]], "Output", + CellChangeTimes->{ + 3.411482321803276*^9, {3.4114825328065443`*^9, 3.41148254700539*^9}, + 3.4114839816059914`*^9}] +}, Open ]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{ + RowBox[{ + RowBox[{"CMEPDFFileName", "[", + RowBox[{"9", ",", "#"}], "]"}], "&"}], "/@", "%"}]], "Input", + CellChangeTimes->{{3.4114827702748404`*^9, 3.41148278282157*^9}, { + 3.4114839850454493`*^9, 3.4114839853268595`*^9}}], + +Cell[BoxData[ + RowBox[{"{", + RowBox[{"\<\"Section09_Interest_Rate_And_Energy_Futures_2008016.pdf\"\>", + ",", "\<\"Section09_Interest_Rate_And_Energy_Futures_2008018.pdf\"\>", + ",", "\<\"Section09_Interest_Rate_And_Energy_Futures_2008019.pdf\"\>", + ",", "\<\"Section09_Interest_Rate_And_Energy_Futures_2008020.pdf\"\>", + ",", "\<\"Section09_Interest_Rate_And_Energy_Futures_2008021.pdf\"\>", + ",", "\<\"Section09_Interest_Rate_And_Energy_Futures_2008022.pdf\"\>", + ",", "\<\"Section09_Interest_Rate_And_Energy_Futures_2008023.pdf\"\>", + ",", "\<\"Section09_Interest_Rate_And_Energy_Futures_2008024.pdf\"\>", + ",", "\<\"Section09_Interest_Rate_And_Energy_Futures_2008025.pdf\"\>", + ",", "\<\"Section09_Interest_Rate_And_Energy_Futures_2008026.pdf\"\>"}], + "}"}]], "Output", + CellChangeTimes->{{3.411482776758616*^9, 3.411482794963064*^9}, + 3.411483201548436*^9, 3.4114839859365816`*^9}] +}, Open ]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{"Flatten", "[", + RowBox[{ + RowBox[{ + RowBox[{ + RowBox[{"Section09DataForDataBase", "[", + RowBox[{"ToFileName", "[", + RowBox[{ + RowBox[{"{", "$CMEEuroDollarSection09Directory", "}"}], ",", "#"}], + "]"}], "]"}], "&"}], "/@", "%"}], ",", "1"}], "]"}]], "Input", + CellChangeTimes->{{3.411483181822936*^9, 3.4114831847738714`*^9}, { + 3.411483302148486*^9, 3.411483332462635*^9}, {3.4114837135178003`*^9, + 3.4114837170136375`*^9}, {3.411483991893098*^9, 3.411483999850753*^9}}], + +Cell[BoxData[ + RowBox[{ + RowBox[{"Import", "::", "\<\"general\"\>"}], + RowBox[{ + ":", " "}], "\<\"\\!\\(\\\"Expected PDF object\\\"\\) \\!\\(\\*ButtonBox[\\\ +\"\[RightSkeleton]\\\", ButtonStyle->\\\"Link\\\", ButtonFrame->None, \ +ButtonData:>\\\"paclet:ref/Import\\\", ButtonNote -> \\\"Import::general\\\"]\ +\\)\"\>"}]], "Message", "MSG", + CellChangeTimes->{3.4114840006949835`*^9}], + +Cell[BoxData[ + RowBox[{ + RowBox[{"Import", "::", "\<\"general\"\>"}], + RowBox[{ + ":", " "}], "\<\"\\!\\(\\\"Exepcted array operator argument\\\"\\) \ +\\!\\(\\*ButtonBox[\\\"\[RightSkeleton]\\\", ButtonStyle->\\\"Link\\\", \ +ButtonFrame->None, ButtonData:>\\\"paclet:ref/Import\\\", ButtonNote -> \ +\\\"Import::general\\\"]\\)\"\>"}]], "Message", "MSG", + CellChangeTimes->{3.4114840006949835`*^9}], + +Cell[BoxData[ + RowBox[{ + RowBox[{"Import", "::", "\<\"general\"\>"}], + RowBox[{ + ":", " "}], "\<\"\\!\\(\\\"Could not draw page 1 stream 7\\\"\\) \ +\\!\\(\\*ButtonBox[\\\"\[RightSkeleton]\\\", ButtonStyle->\\\"Link\\\", \ +ButtonFrame->None, ButtonData:>\\\"paclet:ref/Import\\\", ButtonNote -> \ +\\\"Import::general\\\"]\\)\"\>"}]], "Message", "MSG", + CellChangeTimes->{3.4114840006949835`*^9}], + +Cell[BoxData[ + RowBox[{ + RowBox[{"General", "::", "\<\"stop\"\>"}], + RowBox[{ + ":", " "}], "\<\"Further output of \\!\\(Import :: \\\"general\\\"\\) will \ +be suppressed during this calculation. \ +\\!\\(\\*ButtonBox[\\\"\[RightSkeleton]\\\", ButtonStyle->\\\"Link\\\", \ +ButtonFrame->None, ButtonData:>\\\"paclet:ref/message/General/stop\\\", \ +ButtonNote -> \\\"General::stop\\\"]\\)\"\>"}]], "Message", "MSG", + CellChangeTimes->{3.4114840006949835`*^9}], + +Cell[BoxData[ + RowBox[{ + RowBox[{"Part", "::", "\<\"partw\"\>"}], + RowBox[{ + ":", " "}], "\<\"Part \\!\\(2\\) of \\!\\(ExtractDataFromCMEString[$Failed]\ +\\) does not exist. \\!\\(\\*ButtonBox[\\\"\[RightSkeleton]\\\", \ +ButtonStyle->\\\"Link\\\", ButtonFrame->None, \ +ButtonData:>\\\"paclet:ref/message/General/partw\\\", ButtonNote -> \ +\\\"Part::partw\\\"]\\)\"\>"}]], "Message", "MSG", + CellChangeTimes->{3.4114840006949835`*^9}], + +Cell[BoxData[ + RowBox[{ + RowBox[{"Part", "::", "\<\"partd\"\>"}], + RowBox[{ + ":", " "}], "\<\"Part specification \ +\\!\\(\\(\\(ExtractDataFromCMEString[$Failed]\\)\\) \[LeftDoubleBracket] \ +\\(\\(1, \\(\\({3, 2}\\)\\)\\)\\) \[RightDoubleBracket]\\) is longer than \ +depth of object. \\!\\(\\*ButtonBox[\\\"\[RightSkeleton]\\\", ButtonStyle->\\\ +\"Link\\\", ButtonFrame->None, \ +ButtonData:>\\\"paclet:ref/message/General/partd\\\", ButtonNote -> \ +\\\"Part::partd\\\"]\\)\"\>"}]], "Message", "MSG", + CellChangeTimes->{3.4114840006949835`*^9}], + +Cell[BoxData[ + RowBox[{ + RowBox[{"Join", "::", "\<\"heads\"\>"}], + RowBox[{ + ":", " "}], "\<\"Heads \\!\\(Part\\) and \\!\\(ExtractDataFromCMEString\\) \ +at positions \\!\\(1\\) and \\!\\(2\\) are expected to be the same. \ +\\!\\(\\*ButtonBox[\\\"\[RightSkeleton]\\\", ButtonStyle->\\\"Link\\\", \ +ButtonFrame->None, ButtonData:>\\\"paclet:ref/message/General/heads\\\", \ +ButtonNote -> \\\"Join::heads\\\"]\\)\"\>"}]], "Message", "MSG", + CellChangeTimes->{3.4114840006949835`*^9}], + +Cell[BoxData[ + RowBox[{ + RowBox[{"Join", "::", "\<\"headsd\"\>"}], + RowBox[{ + ":", " "}], "\<\"Expression \ +\\!\\(\\(\\(ExtractDataFromCMEString[$Failed]\\)\\) \[LeftDoubleBracket] \ +\\(\\(1, \\(\\({3, 2}\\)\\)\\)\\) \[RightDoubleBracket]\\) at position \ +\\!\\(1\\) is expected to have head \\!\\(Part\\) for all subexpressions \ +through level \\!\\(2\\). \\!\\(\\*ButtonBox[\\\"\[RightSkeleton]\\\", \ +ButtonStyle->\\\"Link\\\", ButtonFrame->None, ButtonData:>\\\"paclet:ref/Join\ +\\\", ButtonNote -> \\\"Join::headsd\\\"]\\)\"\>"}]], "Message", "MSG", + CellChangeTimes->{3.4114840006949835`*^9}], + +Cell[BoxData[ + RowBox[{ + RowBox[{"Part", "::", "\<\"pspec\"\>"}], + RowBox[{ + ":", " "}], "\<\"Part specification \ +\\!\\(Join[\\(\\(\\(\\(\\(\\(ExtractDataFromCMEString[$Failed]\\)\\) \ +\[LeftDoubleBracket] \\(\\(1, \\(\\({3, 2}\\)\\)\\)\\) \ +\[RightDoubleBracket]\\)\\), 2\\)\\)]\\) is neither an integer nor a list of \ +integers. \\!\\(\\*ButtonBox[\\\"\[RightSkeleton]\\\", \ +ButtonStyle->\\\"Link\\\", ButtonFrame->None, \ +ButtonData:>\\\"paclet:ref/message/General/pspec\\\", ButtonNote -> \ +\\\"Part::pspec\\\"]\\)\"\>"}]], "Message", "MSG", + CellChangeTimes->{3.4114840006949835`*^9}], + +Cell[BoxData[ + RowBox[{ + RowBox[{"LinkObject", "::", "\<\"linkd\"\>"}], + RowBox[{ + ":", " "}], "\<\"Unable to communicate with closed link \ +\\!\\(LinkObject[\\(\\(\\(\\(\\\"\\\\\\\"C:\\\\\\\\Program \ +Files\\\\\\\\Wolfram Research\\\\\\\\Mat\\\" \[Ellipsis] \ +\\\"es\\\\\\\\Converters\\\\\\\\Binaries\\\\\\\\Windows\\\\\\\\PDF.exe\\\\\\\"\ +\\\"\\)\\), 19, 7\\)\\)]\\). \\!\\(\\*ButtonBox[\\\"\[RightSkeleton]\\\", \ +ButtonStyle->\\\"Link\\\", ButtonFrame->None, \ +ButtonData:>\\\"paclet:ref/message/LinkObject/linkd\\\", ButtonNote -> \ +\\\"LinkObject::linkd\\\"]\\)\"\>"}]], "Message", "MSG", + CellChangeTimes->{3.411484015406483*^9}], + +Cell[BoxData[ + RowBox[{ + RowBox[{"Part", "::", "\<\"partw\"\>"}], + RowBox[{ + ":", " "}], "\<\"Part \\!\\(2\\) of \\!\\(ExtractDataFromCMEString[$Failed]\ +\\) does not exist. \\!\\(\\*ButtonBox[\\\"\[RightSkeleton]\\\", \ +ButtonStyle->\\\"Link\\\", ButtonFrame->None, \ +ButtonData:>\\\"paclet:ref/message/General/partw\\\", ButtonNote -> \ +\\\"Part::partw\\\"]\\)\"\>"}]], "Message", "MSG", + CellChangeTimes->{3.411484015453385*^9}], + +Cell[BoxData[ + RowBox[{ + RowBox[{"Part", "::", "\<\"partd\"\>"}], + RowBox[{ + ":", " "}], "\<\"Part specification \ +\\!\\(\\(\\(ExtractDataFromCMEString[$Failed]\\)\\) \[LeftDoubleBracket] \ +\\(\\(1, \\(\\({3, 2}\\)\\)\\)\\) \[RightDoubleBracket]\\) is longer than \ +depth of object. \\!\\(\\*ButtonBox[\\\"\[RightSkeleton]\\\", ButtonStyle->\\\ +\"Link\\\", ButtonFrame->None, \ +ButtonData:>\\\"paclet:ref/message/General/partd\\\", ButtonNote -> \ +\\\"Part::partd\\\"]\\)\"\>"}]], "Message", "MSG", + CellChangeTimes->{3.4114840154846525`*^9}], + +Cell[BoxData[ + RowBox[{ + RowBox[{"Join", "::", "\<\"heads\"\>"}], + RowBox[{ + ":", " "}], "\<\"Heads \\!\\(Part\\) and \\!\\(ExtractDataFromCMEString\\) \ +at positions \\!\\(1\\) and \\!\\(2\\) are expected to be the same. \ +\\!\\(\\*ButtonBox[\\\"\[RightSkeleton]\\\", ButtonStyle->\\\"Link\\\", \ +ButtonFrame->None, ButtonData:>\\\"paclet:ref/message/General/heads\\\", \ +ButtonNote -> \\\"Join::heads\\\"]\\)\"\>"}]], "Message", "MSG", + CellChangeTimes->{3.411484015531554*^9}], + +Cell[BoxData[ + RowBox[{ + RowBox[{"Join", "::", "\<\"headsd\"\>"}], + RowBox[{ + ":", " "}], "\<\"Expression \ +\\!\\(\\(\\(ExtractDataFromCMEString[$Failed]\\)\\) \[LeftDoubleBracket] \ +\\(\\(1, \\(\\({3, 2}\\)\\)\\)\\) \[RightDoubleBracket]\\) at position \ +\\!\\(1\\) is expected to have head \\!\\(Part\\) for all subexpressions \ +through level \\!\\(2\\). \\!\\(\\*ButtonBox[\\\"\[RightSkeleton]\\\", \ +ButtonStyle->\\\"Link\\\", ButtonFrame->None, ButtonData:>\\\"paclet:ref/Join\ +\\\", ButtonNote -> \\\"Join::headsd\\\"]\\)\"\>"}]], "Message", "MSG", + CellChangeTimes->{3.411484015578456*^9}], + +Cell[BoxData[ + RowBox[{ + RowBox[{"Part", "::", "\<\"pspec\"\>"}], + RowBox[{ + ":", " "}], "\<\"Part specification \ +\\!\\(Join[\\(\\(\\(\\(\\(\\(ExtractDataFromCMEString[$Failed]\\)\\) \ +\[LeftDoubleBracket] \\(\\(1, \\(\\({3, 2}\\)\\)\\)\\) \ +\[RightDoubleBracket]\\)\\), 2\\)\\)]\\) is neither an integer nor a list of \ +integers. \\!\\(\\*ButtonBox[\\\"\[RightSkeleton]\\\", \ +ButtonStyle->\\\"Link\\\", ButtonFrame->None, \ +ButtonData:>\\\"paclet:ref/message/General/pspec\\\", ButtonNote -> \ +\\\"Part::pspec\\\"]\\)\"\>"}]], "Message", "MSG", + CellChangeTimes->{3.4114840156253576`*^9}], + +Cell[BoxData[ + RowBox[{"{", + RowBox[{ + RowBox[{ + RowBox[{"Join", "[", + RowBox[{ + RowBox[{ + RowBox[{"ExtractDataFromCMEString", "[", "$Failed", "]"}], + "\[LeftDoubleBracket]", + RowBox[{"1", ",", + RowBox[{"{", + RowBox[{"3", ",", "2"}], "}"}]}], "\[RightDoubleBracket]"}], ",", + RowBox[{"ExtractDataFromCMEString", "[", "$Failed", "]"}]}], "]"}], + "\[LeftDoubleBracket]", + RowBox[{"Join", "[", + RowBox[{ + RowBox[{ + RowBox[{"ExtractDataFromCMEString", "[", "$Failed", "]"}], + "\[LeftDoubleBracket]", + RowBox[{"1", ",", + RowBox[{"{", + RowBox[{"3", ",", "2"}], "}"}]}], "\[RightDoubleBracket]"}], ",", + "2"}], "]"}], "\[RightDoubleBracket]"}], ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "28"}], "}"}], ",", "18", ",", + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "18"}], "}"}], ",", "3.1`"}], "}"}], ",", + + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "28"}], "}"}], ",", "18", ",", + RowBox[{"{", + RowBox[{"2008", ",", "3", ",", "17"}], "}"}], ",", "3.`"}], "}"}], ",", + + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "28"}], "}"}], ",", "18", ",", + RowBox[{"{", + RowBox[{"2008", ",", "4", ",", "14"}], "}"}], ",", "2.87`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "28"}], "}"}], ",", "18", ",", + RowBox[{"{", + RowBox[{"2008", ",", "5", ",", "19"}], "}"}], ",", "2.69`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "28"}], "}"}], ",", "18", ",", + RowBox[{"{", + RowBox[{"2008", ",", "6", ",", "16"}], "}"}], ",", "2.57`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "28"}], "}"}], ",", "18", ",", + RowBox[{"{", + RowBox[{"2008", ",", "9", ",", "15"}], "}"}], ",", "2.51`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "28"}], "}"}], ",", "18", ",", + RowBox[{"{", + RowBox[{"2008", ",", "12", ",", "15"}], "}"}], ",", "2.58`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "28"}], "}"}], ",", "18", ",", + RowBox[{"{", + RowBox[{"2009", ",", "3", ",", "16"}], "}"}], ",", "2.69`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "28"}], "}"}], ",", "18", ",", + RowBox[{"{", + RowBox[{"2009", ",", "6", ",", "15"}], "}"}], ",", "2.85`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "28"}], "}"}], ",", "18", ",", + RowBox[{"{", + RowBox[{"2009", ",", "9", ",", "14"}], "}"}], ",", "3.01`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "28"}], "}"}], ",", "18", ",", + RowBox[{"{", + RowBox[{"2009", ",", "12", ",", "14"}], "}"}], ",", "3.16`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "28"}], "}"}], ",", "18", ",", + RowBox[{"{", + RowBox[{"2010", ",", "3", ",", "15"}], "}"}], ",", "3.3`"}], "}"}], ",", + + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "28"}], "}"}], ",", "18", ",", + RowBox[{"{", + RowBox[{"2010", ",", "6", ",", "14"}], "}"}], ",", "3.46`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "28"}], "}"}], ",", "18", ",", + RowBox[{"{", + RowBox[{"2010", ",", "9", ",", "13"}], "}"}], ",", "3.61`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "28"}], "}"}], ",", "18", ",", + RowBox[{"{", + RowBox[{"2010", ",", "12", ",", "13"}], "}"}], ",", "3.74`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "28"}], "}"}], ",", "18", ",", + RowBox[{"{", + RowBox[{"2011", ",", "3", ",", "14"}], "}"}], ",", "3.87`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "28"}], "}"}], ",", "18", ",", + RowBox[{"{", + RowBox[{"2011", ",", "6", ",", "13"}], "}"}], ",", "4.`"}], "}"}], ",", + + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "28"}], "}"}], ",", "18", ",", + RowBox[{"{", + RowBox[{"2011", ",", "9", ",", "19"}], "}"}], ",", "4.13`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "28"}], "}"}], ",", "18", ",", + RowBox[{"{", + RowBox[{"2011", ",", "12", ",", "19"}], "}"}], ",", "4.25`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "28"}], "}"}], ",", "18", ",", + RowBox[{"{", + RowBox[{"2012", ",", "3", ",", "19"}], "}"}], ",", "4.35`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "28"}], "}"}], ",", "18", ",", + RowBox[{"{", + RowBox[{"2012", ",", "6", ",", "18"}], "}"}], ",", "4.46`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "28"}], "}"}], ",", "18", ",", + RowBox[{"{", + RowBox[{"2012", ",", "9", ",", "17"}], "}"}], ",", "4.57`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "28"}], "}"}], ",", "18", ",", + RowBox[{"{", + RowBox[{"2012", ",", "12", ",", "17"}], "}"}], ",", "4.68`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "28"}], "}"}], ",", "18", ",", + RowBox[{"{", + RowBox[{"2013", ",", "3", ",", "18"}], "}"}], ",", "4.76`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "28"}], "}"}], ",", "18", ",", + RowBox[{"{", + RowBox[{"2013", ",", "6", ",", "17"}], "}"}], ",", "4.85`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "28"}], "}"}], ",", "18", ",", + RowBox[{"{", + RowBox[{"2013", ",", "9", ",", "16"}], "}"}], ",", "4.94`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "28"}], "}"}], ",", "18", ",", + RowBox[{"{", + RowBox[{"2013", ",", "12", ",", "16"}], "}"}], ",", "5.04`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "28"}], "}"}], ",", "18", ",", + RowBox[{"{", + RowBox[{"2014", ",", "3", ",", "17"}], "}"}], ",", "5.11`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "28"}], "}"}], ",", "18", ",", + RowBox[{"{", + RowBox[{"2014", ",", "6", ",", "16"}], "}"}], ",", "5.19`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "28"}], "}"}], ",", "18", ",", + RowBox[{"{", + RowBox[{"2014", ",", "9", ",", "15"}], "}"}], ",", "5.25`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "28"}], "}"}], ",", "18", ",", + RowBox[{"{", + RowBox[{"2014", ",", "12", ",", "15"}], "}"}], ",", "5.33`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "28"}], "}"}], ",", "18", ",", + RowBox[{"{", + RowBox[{"2015", ",", "3", ",", "16"}], "}"}], ",", "5.38`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "28"}], "}"}], ",", "18", ",", + RowBox[{"{", + RowBox[{"2015", ",", "6", ",", "15"}], "}"}], ",", "5.43`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "28"}], "}"}], ",", "18", ",", + RowBox[{"{", + RowBox[{"2015", ",", "9", ",", "14"}], "}"}], ",", "5.48`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "28"}], "}"}], ",", "18", ",", + RowBox[{"{", + RowBox[{"2015", ",", "12", ",", "14"}], "}"}], ",", "5.54`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "28"}], "}"}], ",", "18", ",", + RowBox[{"{", + RowBox[{"2016", ",", "3", ",", "14"}], "}"}], ",", "5.58`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "28"}], "}"}], ",", "18", ",", + RowBox[{"{", + RowBox[{"2016", ",", "6", ",", "13"}], "}"}], ",", "5.62`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "28"}], "}"}], ",", "18", ",", + RowBox[{"{", + RowBox[{"2016", ",", "9", ",", "19"}], "}"}], ",", "5.66`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "28"}], "}"}], ",", "18", ",", + RowBox[{"{", + RowBox[{"2016", ",", "12", ",", "19"}], "}"}], ",", "5.71`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "28"}], "}"}], ",", "18", ",", + RowBox[{"{", + RowBox[{"2017", ",", "3", ",", "13"}], "}"}], ",", "5.73`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "28"}], "}"}], ",", "18", ",", + RowBox[{"{", + RowBox[{"2017", ",", "6", ",", "19"}], "}"}], ",", "5.75`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "28"}], "}"}], ",", "18", ",", + RowBox[{"{", + RowBox[{"2017", ",", "9", ",", "18"}], "}"}], ",", "5.78`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "28"}], "}"}], ",", "18", ",", + RowBox[{"{", + RowBox[{"2017", ",", "12", ",", "18"}], "}"}], ",", "5.82`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "29"}], "}"}], ",", "19", ",", + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "18"}], "}"}], ",", "3.14`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "29"}], "}"}], ",", "19", ",", + RowBox[{"{", + RowBox[{"2008", ",", "3", ",", "17"}], "}"}], ",", "3.03`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "29"}], "}"}], ",", "19", ",", + RowBox[{"{", + RowBox[{"2008", ",", "4", ",", "14"}], "}"}], ",", "2.89`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "29"}], "}"}], ",", "19", ",", + RowBox[{"{", + RowBox[{"2008", ",", "5", ",", "19"}], "}"}], ",", "2.73`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "29"}], "}"}], ",", "19", ",", + RowBox[{"{", + RowBox[{"2008", ",", "6", ",", "16"}], "}"}], ",", "2.62`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "29"}], "}"}], ",", "19", ",", + RowBox[{"{", + RowBox[{"2008", ",", "9", ",", "15"}], "}"}], ",", "2.59`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "29"}], "}"}], ",", "19", ",", + RowBox[{"{", + RowBox[{"2008", ",", "12", ",", "15"}], "}"}], ",", "2.67`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "29"}], "}"}], ",", "19", ",", + RowBox[{"{", + RowBox[{"2009", ",", "3", ",", "16"}], "}"}], ",", "2.79`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "29"}], "}"}], ",", "19", ",", + RowBox[{"{", + RowBox[{"2009", ",", "6", ",", "15"}], "}"}], ",", "2.95`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "29"}], "}"}], ",", "19", ",", + RowBox[{"{", + RowBox[{"2009", ",", "9", ",", "14"}], "}"}], ",", "3.1`"}], "}"}], ",", + + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "29"}], "}"}], ",", "19", ",", + RowBox[{"{", + RowBox[{"2009", ",", "12", ",", "14"}], "}"}], ",", "3.24`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "29"}], "}"}], ",", "19", ",", + RowBox[{"{", + RowBox[{"2010", ",", "3", ",", "15"}], "}"}], ",", "3.37`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "29"}], "}"}], ",", "19", ",", + RowBox[{"{", + RowBox[{"2010", ",", "6", ",", "14"}], "}"}], ",", "3.52`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "29"}], "}"}], ",", "19", ",", + RowBox[{"{", + RowBox[{"2010", ",", "9", ",", "13"}], "}"}], ",", "3.67`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "29"}], "}"}], ",", "19", ",", + RowBox[{"{", + RowBox[{"2010", ",", "12", ",", "13"}], "}"}], ",", "3.8`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "29"}], "}"}], ",", "19", ",", + RowBox[{"{", + RowBox[{"2011", ",", "3", ",", "14"}], "}"}], ",", "3.91`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "29"}], "}"}], ",", "19", ",", + RowBox[{"{", + RowBox[{"2011", ",", "6", ",", "13"}], "}"}], ",", "4.04`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "29"}], "}"}], ",", "19", ",", + RowBox[{"{", + RowBox[{"2011", ",", "9", ",", "19"}], "}"}], ",", "4.17`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "29"}], "}"}], ",", "19", ",", + RowBox[{"{", + RowBox[{"2011", ",", "12", ",", "19"}], "}"}], ",", "4.29`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "29"}], "}"}], ",", "19", ",", + RowBox[{"{", + RowBox[{"2012", ",", "3", ",", "19"}], "}"}], ",", "4.39`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "29"}], "}"}], ",", "19", ",", + RowBox[{"{", + RowBox[{"2012", ",", "6", ",", "18"}], "}"}], ",", "4.49`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "29"}], "}"}], ",", "19", ",", + RowBox[{"{", + RowBox[{"2012", ",", "9", ",", "17"}], "}"}], ",", "4.6`"}], "}"}], ",", + + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "29"}], "}"}], ",", "19", ",", + RowBox[{"{", + RowBox[{"2012", ",", "12", ",", "17"}], "}"}], ",", "4.7`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "29"}], "}"}], ",", "19", ",", + RowBox[{"{", + RowBox[{"2013", ",", "3", ",", "18"}], "}"}], ",", "4.78`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "29"}], "}"}], ",", "19", ",", + RowBox[{"{", + RowBox[{"2013", ",", "6", ",", "17"}], "}"}], ",", "4.88`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "29"}], "}"}], ",", "19", ",", + RowBox[{"{", + RowBox[{"2013", ",", "9", ",", "16"}], "}"}], ",", "4.97`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "29"}], "}"}], ",", "19", ",", + RowBox[{"{", + RowBox[{"2013", ",", "12", ",", "16"}], "}"}], ",", "5.06`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "29"}], "}"}], ",", "19", ",", + RowBox[{"{", + RowBox[{"2014", ",", "3", ",", "17"}], "}"}], ",", "5.13`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "29"}], "}"}], ",", "19", ",", + RowBox[{"{", + RowBox[{"2014", ",", "6", ",", "16"}], "}"}], ",", "5.21`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "29"}], "}"}], ",", "19", ",", + RowBox[{"{", + RowBox[{"2014", ",", "9", ",", "15"}], "}"}], ",", "5.27`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "29"}], "}"}], ",", "19", ",", + RowBox[{"{", + RowBox[{"2014", ",", "12", ",", "15"}], "}"}], ",", "5.35`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "29"}], "}"}], ",", "19", ",", + RowBox[{"{", + RowBox[{"2015", ",", "3", ",", "16"}], "}"}], ",", "5.4`"}], "}"}], ",", + + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "29"}], "}"}], ",", "19", ",", + RowBox[{"{", + RowBox[{"2015", ",", "6", ",", "15"}], "}"}], ",", "5.45`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "29"}], "}"}], ",", "19", ",", + RowBox[{"{", + RowBox[{"2015", ",", "9", ",", "14"}], "}"}], ",", "5.5`"}], "}"}], ",", + + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "29"}], "}"}], ",", "19", ",", + RowBox[{"{", + RowBox[{"2015", ",", "12", ",", "14"}], "}"}], ",", "5.56`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "29"}], "}"}], ",", "19", ",", + RowBox[{"{", + RowBox[{"2016", ",", "3", ",", "14"}], "}"}], ",", "5.59`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "29"}], "}"}], ",", "19", ",", + RowBox[{"{", + RowBox[{"2016", ",", "6", ",", "13"}], "}"}], ",", "5.63`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "29"}], "}"}], ",", "19", ",", + RowBox[{"{", + RowBox[{"2016", ",", "9", ",", "19"}], "}"}], ",", "5.67`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "29"}], "}"}], ",", "19", ",", + RowBox[{"{", + RowBox[{"2016", ",", "12", ",", "19"}], "}"}], ",", "5.72`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "29"}], "}"}], ",", "19", ",", + RowBox[{"{", + RowBox[{"2017", ",", "3", ",", "13"}], "}"}], ",", "5.74`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "29"}], "}"}], ",", "19", ",", + RowBox[{"{", + RowBox[{"2017", ",", "6", ",", "19"}], "}"}], ",", "5.76`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "29"}], "}"}], ",", "19", ",", + RowBox[{"{", + RowBox[{"2017", ",", "9", ",", "18"}], "}"}], ",", "5.79`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "29"}], "}"}], ",", "19", ",", + RowBox[{"{", + RowBox[{"2017", ",", "12", ",", "18"}], "}"}], ",", "5.83`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "30"}], "}"}], ",", "20", ",", + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "18"}], "}"}], ",", "3.06`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "30"}], "}"}], ",", "20", ",", + RowBox[{"{", + RowBox[{"2008", ",", "3", ",", "17"}], "}"}], ",", "2.95`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "30"}], "}"}], ",", "20", ",", + RowBox[{"{", + RowBox[{"2008", ",", "4", ",", "14"}], "}"}], ",", "2.81`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "30"}], "}"}], ",", "20", ",", + RowBox[{"{", + RowBox[{"2008", ",", "5", ",", "19"}], "}"}], ",", "2.65`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "30"}], "}"}], ",", "20", ",", + RowBox[{"{", + RowBox[{"2008", ",", "6", ",", "16"}], "}"}], ",", "2.55`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "30"}], "}"}], ",", "20", ",", + RowBox[{"{", + RowBox[{"2008", ",", "9", ",", "15"}], "}"}], ",", "2.53`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "30"}], "}"}], ",", "20", ",", + RowBox[{"{", + RowBox[{"2008", ",", "12", ",", "15"}], "}"}], ",", "2.65`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "30"}], "}"}], ",", "20", ",", + RowBox[{"{", + RowBox[{"2009", ",", "3", ",", "16"}], "}"}], ",", "2.82`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "30"}], "}"}], ",", "20", ",", + RowBox[{"{", + RowBox[{"2009", ",", "6", ",", "15"}], "}"}], ",", "3.01`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "30"}], "}"}], ",", "20", ",", + RowBox[{"{", + RowBox[{"2009", ",", "9", ",", "14"}], "}"}], ",", "3.18`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "30"}], "}"}], ",", "20", ",", + RowBox[{"{", + RowBox[{"2009", ",", "12", ",", "14"}], "}"}], ",", "3.34`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "30"}], "}"}], ",", "20", ",", + RowBox[{"{", + RowBox[{"2010", ",", "3", ",", "15"}], "}"}], ",", "3.49`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "30"}], "}"}], ",", "20", ",", + RowBox[{"{", + RowBox[{"2010", ",", "6", ",", "14"}], "}"}], ",", "3.65`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "30"}], "}"}], ",", "20", ",", + RowBox[{"{", + RowBox[{"2010", ",", "9", ",", "13"}], "}"}], ",", "3.8`"}], "}"}], ",", + + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "30"}], "}"}], ",", "20", ",", + RowBox[{"{", + RowBox[{"2010", ",", "12", ",", "13"}], "}"}], ",", "3.94`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "30"}], "}"}], ",", "20", ",", + RowBox[{"{", + RowBox[{"2011", ",", "3", ",", "14"}], "}"}], ",", "4.05`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "30"}], "}"}], ",", "20", ",", + RowBox[{"{", + RowBox[{"2011", ",", "6", ",", "13"}], "}"}], ",", "4.18`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "30"}], "}"}], ",", "20", ",", + RowBox[{"{", + RowBox[{"2011", ",", "9", ",", "19"}], "}"}], ",", "4.31`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "30"}], "}"}], ",", "20", ",", + RowBox[{"{", + RowBox[{"2011", ",", "12", ",", "19"}], "}"}], ",", "4.43`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "30"}], "}"}], ",", "20", ",", + RowBox[{"{", + RowBox[{"2012", ",", "3", ",", "19"}], "}"}], ",", "4.53`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "30"}], "}"}], ",", "20", ",", + RowBox[{"{", + RowBox[{"2012", ",", "6", ",", "18"}], "}"}], ",", "4.63`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "30"}], "}"}], ",", "20", ",", + RowBox[{"{", + RowBox[{"2012", ",", "9", ",", "17"}], "}"}], ",", "4.74`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "30"}], "}"}], ",", "20", ",", + RowBox[{"{", + RowBox[{"2012", ",", "12", ",", "17"}], "}"}], ",", "4.84`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "30"}], "}"}], ",", "20", ",", + RowBox[{"{", + RowBox[{"2013", ",", "3", ",", "18"}], "}"}], ",", "4.92`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "30"}], "}"}], ",", "20", ",", + RowBox[{"{", + RowBox[{"2013", ",", "6", ",", "17"}], "}"}], ",", "5.02`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "30"}], "}"}], ",", "20", ",", + RowBox[{"{", + RowBox[{"2013", ",", "9", ",", "16"}], "}"}], ",", "5.11`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "30"}], "}"}], ",", "20", ",", + RowBox[{"{", + RowBox[{"2013", ",", "12", ",", "16"}], "}"}], ",", "5.2`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "30"}], "}"}], ",", "20", ",", + RowBox[{"{", + RowBox[{"2014", ",", "3", ",", "17"}], "}"}], ",", "5.27`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "30"}], "}"}], ",", "20", ",", + RowBox[{"{", + RowBox[{"2014", ",", "6", ",", "16"}], "}"}], ",", "5.35`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "30"}], "}"}], ",", "20", ",", + RowBox[{"{", + RowBox[{"2014", ",", "9", ",", "15"}], "}"}], ",", "5.41`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "30"}], "}"}], ",", "20", ",", + RowBox[{"{", + RowBox[{"2014", ",", "12", ",", "15"}], "}"}], ",", "5.49`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "30"}], "}"}], ",", "20", ",", + RowBox[{"{", + RowBox[{"2015", ",", "3", ",", "16"}], "}"}], ",", "5.54`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "30"}], "}"}], ",", "20", ",", + RowBox[{"{", + RowBox[{"2015", ",", "6", ",", "15"}], "}"}], ",", "5.59`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "30"}], "}"}], ",", "20", ",", + RowBox[{"{", + RowBox[{"2015", ",", "9", ",", "14"}], "}"}], ",", "5.64`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "30"}], "}"}], ",", "20", ",", + RowBox[{"{", + RowBox[{"2015", ",", "12", ",", "14"}], "}"}], ",", "5.7`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "30"}], "}"}], ",", "20", ",", + RowBox[{"{", + RowBox[{"2016", ",", "3", ",", "14"}], "}"}], ",", "5.73`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "30"}], "}"}], ",", "20", ",", + RowBox[{"{", + RowBox[{"2016", ",", "6", ",", "13"}], "}"}], ",", "5.77`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "30"}], "}"}], ",", "20", ",", + RowBox[{"{", + RowBox[{"2016", ",", "9", ",", "19"}], "}"}], ",", "5.81`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "30"}], "}"}], ",", "20", ",", + RowBox[{"{", + RowBox[{"2016", ",", "12", ",", "19"}], "}"}], ",", "5.86`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "30"}], "}"}], ",", "20", ",", + RowBox[{"{", + RowBox[{"2017", ",", "3", ",", "13"}], "}"}], ",", "5.88`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "30"}], "}"}], ",", "20", ",", + RowBox[{"{", + RowBox[{"2017", ",", "6", ",", "19"}], "}"}], ",", "5.9`"}], "}"}], ",", + + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "30"}], "}"}], ",", "20", ",", + RowBox[{"{", + RowBox[{"2017", ",", "9", ",", "18"}], "}"}], ",", "5.93`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "30"}], "}"}], ",", "20", ",", + RowBox[{"{", + RowBox[{"2017", ",", "12", ",", "18"}], "}"}], ",", "5.97`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "31"}], "}"}], ",", "21", ",", + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "18"}], "}"}], ",", "3.03`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "31"}], "}"}], ",", "21", ",", + RowBox[{"{", + RowBox[{"2008", ",", "3", ",", "17"}], "}"}], ",", "2.9`"}], "}"}], ",", + + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "31"}], "}"}], ",", "21", ",", + RowBox[{"{", + RowBox[{"2008", ",", "4", ",", "14"}], "}"}], ",", "2.76`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "31"}], "}"}], ",", "21", ",", + RowBox[{"{", + RowBox[{"2008", ",", "5", ",", "19"}], "}"}], ",", "2.6`"}], "}"}], ",", + + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "31"}], "}"}], ",", "21", ",", + RowBox[{"{", + RowBox[{"2008", ",", "6", ",", "16"}], "}"}], ",", "2.49`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "31"}], "}"}], ",", "21", ",", + RowBox[{"{", + RowBox[{"2008", ",", "9", ",", "15"}], "}"}], ",", "2.44`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "31"}], "}"}], ",", "21", ",", + RowBox[{"{", + RowBox[{"2008", ",", "12", ",", "15"}], "}"}], ",", "2.56`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "31"}], "}"}], ",", "21", ",", + RowBox[{"{", + RowBox[{"2009", ",", "3", ",", "16"}], "}"}], ",", "2.73`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "31"}], "}"}], ",", "21", ",", + RowBox[{"{", + RowBox[{"2009", ",", "6", ",", "15"}], "}"}], ",", "2.93`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "31"}], "}"}], ",", "21", ",", + RowBox[{"{", + RowBox[{"2009", ",", "9", ",", "14"}], "}"}], ",", "3.1`"}], "}"}], ",", + + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "31"}], "}"}], ",", "21", ",", + RowBox[{"{", + RowBox[{"2009", ",", "12", ",", "14"}], "}"}], ",", "3.26`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "31"}], "}"}], ",", "21", ",", + RowBox[{"{", + RowBox[{"2010", ",", "3", ",", "15"}], "}"}], ",", "3.41`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "31"}], "}"}], ",", "21", ",", + RowBox[{"{", + RowBox[{"2010", ",", "6", ",", "14"}], "}"}], ",", "3.57`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "31"}], "}"}], ",", "21", ",", + RowBox[{"{", + RowBox[{"2010", ",", "9", ",", "13"}], "}"}], ",", "3.71`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "31"}], "}"}], ",", "21", ",", + RowBox[{"{", + RowBox[{"2010", ",", "12", ",", "13"}], "}"}], ",", "3.84`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "31"}], "}"}], ",", "21", ",", + RowBox[{"{", + RowBox[{"2011", ",", "3", ",", "14"}], "}"}], ",", "3.95`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "31"}], "}"}], ",", "21", ",", + RowBox[{"{", + RowBox[{"2011", ",", "6", ",", "13"}], "}"}], ",", "4.07`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "31"}], "}"}], ",", "21", ",", + RowBox[{"{", + RowBox[{"2011", ",", "9", ",", "19"}], "}"}], ",", "4.2`"}], "}"}], ",", + + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "31"}], "}"}], ",", "21", ",", + RowBox[{"{", + RowBox[{"2011", ",", "12", ",", "19"}], "}"}], ",", "4.32`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "31"}], "}"}], ",", "21", ",", + RowBox[{"{", + RowBox[{"2012", ",", "3", ",", "19"}], "}"}], ",", "4.41`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "31"}], "}"}], ",", "21", ",", + RowBox[{"{", + RowBox[{"2012", ",", "6", ",", "18"}], "}"}], ",", "4.51`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "31"}], "}"}], ",", "21", ",", + RowBox[{"{", + RowBox[{"2012", ",", "9", ",", "17"}], "}"}], ",", "4.62`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "31"}], "}"}], ",", "21", ",", + RowBox[{"{", + RowBox[{"2012", ",", "12", ",", "17"}], "}"}], ",", "4.72`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "31"}], "}"}], ",", "21", ",", + RowBox[{"{", + RowBox[{"2013", ",", "3", ",", "18"}], "}"}], ",", "4.8`"}], "}"}], ",", + + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "31"}], "}"}], ",", "21", ",", + RowBox[{"{", + RowBox[{"2013", ",", "6", ",", "17"}], "}"}], ",", "4.9`"}], "}"}], ",", + + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "31"}], "}"}], ",", "21", ",", + RowBox[{"{", + RowBox[{"2013", ",", "9", ",", "16"}], "}"}], ",", "4.99`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "31"}], "}"}], ",", "21", ",", + RowBox[{"{", + RowBox[{"2013", ",", "12", ",", "16"}], "}"}], ",", "5.08`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "31"}], "}"}], ",", "21", ",", + RowBox[{"{", + RowBox[{"2014", ",", "3", ",", "17"}], "}"}], ",", "5.15`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "31"}], "}"}], ",", "21", ",", + RowBox[{"{", + RowBox[{"2014", ",", "6", ",", "16"}], "}"}], ",", "5.23`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "31"}], "}"}], ",", "21", ",", + RowBox[{"{", + RowBox[{"2014", ",", "9", ",", "15"}], "}"}], ",", "5.29`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "31"}], "}"}], ",", "21", ",", + RowBox[{"{", + RowBox[{"2014", ",", "12", ",", "15"}], "}"}], ",", "5.37`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "31"}], "}"}], ",", "21", ",", + RowBox[{"{", + RowBox[{"2015", ",", "3", ",", "16"}], "}"}], ",", "5.42`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "31"}], "}"}], ",", "21", ",", + RowBox[{"{", + RowBox[{"2015", ",", "6", ",", "15"}], "}"}], ",", "5.47`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "31"}], "}"}], ",", "21", ",", + RowBox[{"{", + RowBox[{"2015", ",", "9", ",", "14"}], "}"}], ",", "5.52`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "31"}], "}"}], ",", "21", ",", + RowBox[{"{", + RowBox[{"2015", ",", "12", ",", "14"}], "}"}], ",", "5.58`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "31"}], "}"}], ",", "21", ",", + RowBox[{"{", + RowBox[{"2016", ",", "3", ",", "14"}], "}"}], ",", "5.61`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "31"}], "}"}], ",", "21", ",", + RowBox[{"{", + RowBox[{"2016", ",", "6", ",", "13"}], "}"}], ",", "5.65`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "31"}], "}"}], ",", "21", ",", + RowBox[{"{", + RowBox[{"2016", ",", "9", ",", "19"}], "}"}], ",", "5.69`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "31"}], "}"}], ",", "21", ",", + RowBox[{"{", + RowBox[{"2016", ",", "12", ",", "19"}], "}"}], ",", "5.74`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "31"}], "}"}], ",", "21", ",", + RowBox[{"{", + RowBox[{"2017", ",", "3", ",", "13"}], "}"}], ",", "5.76`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "31"}], "}"}], ",", "21", ",", + RowBox[{"{", + RowBox[{"2017", ",", "6", ",", "19"}], "}"}], ",", "5.78`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "31"}], "}"}], ",", "21", ",", + RowBox[{"{", + RowBox[{"2017", ",", "9", ",", "18"}], "}"}], ",", "5.81`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "31"}], "}"}], ",", "21", ",", + RowBox[{"{", + RowBox[{"2017", ",", "12", ",", "18"}], "}"}], ",", "5.85`"}], "}"}], + ",", + RowBox[{ + RowBox[{"Join", "[", + RowBox[{ + RowBox[{ + RowBox[{"ExtractDataFromCMEString", "[", "$Failed", "]"}], + "\[LeftDoubleBracket]", + RowBox[{"1", ",", + RowBox[{"{", + RowBox[{"3", ",", "2"}], "}"}]}], "\[RightDoubleBracket]"}], ",", + RowBox[{"ExtractDataFromCMEString", "[", "$Failed", "]"}]}], "]"}], + "\[LeftDoubleBracket]", + RowBox[{"Join", "[", + RowBox[{ + RowBox[{ + RowBox[{"ExtractDataFromCMEString", "[", "$Failed", "]"}], + "\[LeftDoubleBracket]", + RowBox[{"1", ",", + RowBox[{"{", + RowBox[{"3", ",", "2"}], "}"}]}], "\[RightDoubleBracket]"}], ",", + "2"}], "]"}], "\[RightDoubleBracket]"}], ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "4"}], "}"}], ",", "23", ",", + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "18"}], "}"}], ",", "3.12`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "4"}], "}"}], ",", "23", ",", + RowBox[{"{", + RowBox[{"2008", ",", "3", ",", "17"}], "}"}], ",", "2.99`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "4"}], "}"}], ",", "23", ",", + RowBox[{"{", + RowBox[{"2008", ",", "4", ",", "14"}], "}"}], ",", "2.85`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "4"}], "}"}], ",", "23", ",", + RowBox[{"{", + RowBox[{"2008", ",", "5", ",", "19"}], "}"}], ",", "2.69`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "4"}], "}"}], ",", "23", ",", + RowBox[{"{", + RowBox[{"2008", ",", "6", ",", "16"}], "}"}], ",", "2.58`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "4"}], "}"}], ",", "23", ",", + RowBox[{"{", + RowBox[{"2008", ",", "9", ",", "15"}], "}"}], ",", "2.47`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "4"}], "}"}], ",", "23", ",", + RowBox[{"{", + RowBox[{"2008", ",", "12", ",", "15"}], "}"}], ",", "2.5`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "4"}], "}"}], ",", "23", ",", + RowBox[{"{", + RowBox[{"2009", ",", "3", ",", "16"}], "}"}], ",", "2.6`"}], "}"}], ",", + + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "4"}], "}"}], ",", "23", ",", + RowBox[{"{", + RowBox[{"2009", ",", "6", ",", "15"}], "}"}], ",", "2.78`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "4"}], "}"}], ",", "23", ",", + RowBox[{"{", + RowBox[{"2009", ",", "9", ",", "14"}], "}"}], ",", "2.96`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "4"}], "}"}], ",", "23", ",", + RowBox[{"{", + RowBox[{"2009", ",", "12", ",", "14"}], "}"}], ",", "3.15`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "4"}], "}"}], ",", "23", ",", + RowBox[{"{", + RowBox[{"2010", ",", "3", ",", "15"}], "}"}], ",", "3.32`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "4"}], "}"}], ",", "23", ",", + RowBox[{"{", + RowBox[{"2010", ",", "6", ",", "14"}], "}"}], ",", "3.49`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "4"}], "}"}], ",", "23", ",", + RowBox[{"{", + RowBox[{"2010", ",", "9", ",", "13"}], "}"}], ",", "3.66`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "4"}], "}"}], ",", "23", ",", + RowBox[{"{", + RowBox[{"2010", ",", "12", ",", "13"}], "}"}], ",", "3.81`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "4"}], "}"}], ",", "23", ",", + RowBox[{"{", + RowBox[{"2011", ",", "3", ",", "14"}], "}"}], ",", "3.93`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "4"}], "}"}], ",", "23", ",", + RowBox[{"{", + RowBox[{"2011", ",", "6", ",", "13"}], "}"}], ",", "4.07`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "4"}], "}"}], ",", "23", ",", + RowBox[{"{", + RowBox[{"2011", ",", "9", ",", "19"}], "}"}], ",", "4.2`"}], "}"}], ",", + + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "4"}], "}"}], ",", "23", ",", + RowBox[{"{", + RowBox[{"2011", ",", "12", ",", "19"}], "}"}], ",", "4.32`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "4"}], "}"}], ",", "23", ",", + RowBox[{"{", + RowBox[{"2012", ",", "3", ",", "19"}], "}"}], ",", "4.42`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "4"}], "}"}], ",", "23", ",", + RowBox[{"{", + RowBox[{"2012", ",", "6", ",", "18"}], "}"}], ",", "4.54`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "4"}], "}"}], ",", "23", ",", + RowBox[{"{", + RowBox[{"2012", ",", "9", ",", "17"}], "}"}], ",", "4.66`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "4"}], "}"}], ",", "23", ",", + RowBox[{"{", + RowBox[{"2012", ",", "12", ",", "17"}], "}"}], ",", "4.77`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "4"}], "}"}], ",", "23", ",", + RowBox[{"{", + RowBox[{"2013", ",", "3", ",", "18"}], "}"}], ",", "4.86`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "4"}], "}"}], ",", "23", ",", + RowBox[{"{", + RowBox[{"2013", ",", "6", ",", "17"}], "}"}], ",", "4.95`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "4"}], "}"}], ",", "23", ",", + RowBox[{"{", + RowBox[{"2013", ",", "9", ",", "16"}], "}"}], ",", "5.04`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "4"}], "}"}], ",", "23", ",", + RowBox[{"{", + RowBox[{"2013", ",", "12", ",", "16"}], "}"}], ",", "5.14`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "4"}], "}"}], ",", "23", ",", + RowBox[{"{", + RowBox[{"2014", ",", "3", ",", "17"}], "}"}], ",", "5.21`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "4"}], "}"}], ",", "23", ",", + RowBox[{"{", + RowBox[{"2014", ",", "6", ",", "16"}], "}"}], ",", "5.29`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "4"}], "}"}], ",", "23", ",", + RowBox[{"{", + RowBox[{"2014", ",", "9", ",", "15"}], "}"}], ",", "5.35`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "4"}], "}"}], ",", "23", ",", + RowBox[{"{", + RowBox[{"2014", ",", "12", ",", "15"}], "}"}], ",", "5.43`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "4"}], "}"}], ",", "23", ",", + RowBox[{"{", + RowBox[{"2015", ",", "3", ",", "16"}], "}"}], ",", "5.48`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "4"}], "}"}], ",", "23", ",", + RowBox[{"{", + RowBox[{"2015", ",", "6", ",", "15"}], "}"}], ",", "5.54`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "4"}], "}"}], ",", "23", ",", + RowBox[{"{", + RowBox[{"2015", ",", "9", ",", "14"}], "}"}], ",", "5.59`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "4"}], "}"}], ",", "23", ",", + RowBox[{"{", + RowBox[{"2015", ",", "12", ",", "14"}], "}"}], ",", "5.65`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "4"}], "}"}], ",", "23", ",", + RowBox[{"{", + RowBox[{"2016", ",", "3", ",", "14"}], "}"}], ",", "5.68`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "4"}], "}"}], ",", "23", ",", + RowBox[{"{", + RowBox[{"2016", ",", "6", ",", "13"}], "}"}], ",", "5.72`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "4"}], "}"}], ",", "23", ",", + RowBox[{"{", + RowBox[{"2016", ",", "9", ",", "19"}], "}"}], ",", "5.76`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "4"}], "}"}], ",", "23", ",", + RowBox[{"{", + RowBox[{"2016", ",", "12", ",", "19"}], "}"}], ",", "5.81`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "4"}], "}"}], ",", "23", ",", + RowBox[{"{", + RowBox[{"2017", ",", "3", ",", "13"}], "}"}], ",", "5.83`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "4"}], "}"}], ",", "23", ",", + RowBox[{"{", + RowBox[{"2017", ",", "6", ",", "19"}], "}"}], ",", "5.85`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "4"}], "}"}], ",", "23", ",", + RowBox[{"{", + RowBox[{"2017", ",", "9", ",", "18"}], "}"}], ",", "5.88`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "4"}], "}"}], ",", "23", ",", + RowBox[{"{", + RowBox[{"2017", ",", "12", ",", "18"}], "}"}], ",", "5.92`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "5"}], "}"}], ",", "24", ",", + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "18"}], "}"}], ",", "3.09`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "5"}], "}"}], ",", "24", ",", + RowBox[{"{", + RowBox[{"2008", ",", "3", ",", "17"}], "}"}], ",", "2.92`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "5"}], "}"}], ",", "24", ",", + RowBox[{"{", + RowBox[{"2008", ",", "4", ",", "14"}], "}"}], ",", "2.76`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "5"}], "}"}], ",", "24", ",", + RowBox[{"{", + RowBox[{"2008", ",", "5", ",", "19"}], "}"}], ",", "2.57`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "5"}], "}"}], ",", "24", ",", + RowBox[{"{", + RowBox[{"2008", ",", "6", ",", "16"}], "}"}], ",", "2.44`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "5"}], "}"}], ",", "24", ",", + RowBox[{"{", + RowBox[{"2008", ",", "9", ",", "15"}], "}"}], ",", "2.33`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "5"}], "}"}], ",", "24", ",", + RowBox[{"{", + RowBox[{"2008", ",", "12", ",", "15"}], "}"}], ",", "2.37`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "5"}], "}"}], ",", "24", ",", + RowBox[{"{", + RowBox[{"2009", ",", "3", ",", "16"}], "}"}], ",", "2.49`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "5"}], "}"}], ",", "24", ",", + RowBox[{"{", + RowBox[{"2009", ",", "6", ",", "15"}], "}"}], ",", "2.69`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "5"}], "}"}], ",", "24", ",", + RowBox[{"{", + RowBox[{"2009", ",", "9", ",", "14"}], "}"}], ",", "2.89`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "5"}], "}"}], ",", "24", ",", + RowBox[{"{", + RowBox[{"2009", ",", "12", ",", "14"}], "}"}], ",", "3.08`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "5"}], "}"}], ",", "24", ",", + RowBox[{"{", + RowBox[{"2010", ",", "3", ",", "15"}], "}"}], ",", "3.26`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "5"}], "}"}], ",", "24", ",", + RowBox[{"{", + RowBox[{"2010", ",", "6", ",", "14"}], "}"}], ",", "3.43`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "5"}], "}"}], ",", "24", ",", + RowBox[{"{", + RowBox[{"2010", ",", "9", ",", "13"}], "}"}], ",", "3.6`"}], "}"}], ",", + + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "5"}], "}"}], ",", "24", ",", + RowBox[{"{", + RowBox[{"2010", ",", "12", ",", "13"}], "}"}], ",", "3.75`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "5"}], "}"}], ",", "24", ",", + RowBox[{"{", + RowBox[{"2011", ",", "3", ",", "14"}], "}"}], ",", "3.88`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "5"}], "}"}], ",", "24", ",", + RowBox[{"{", + RowBox[{"2011", ",", "6", ",", "13"}], "}"}], ",", "4.01`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "5"}], "}"}], ",", "24", ",", + RowBox[{"{", + RowBox[{"2011", ",", "9", ",", "19"}], "}"}], ",", "4.14`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "5"}], "}"}], ",", "24", ",", + RowBox[{"{", + RowBox[{"2011", ",", "12", ",", "19"}], "}"}], ",", "4.27`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "5"}], "}"}], ",", "24", ",", + RowBox[{"{", + RowBox[{"2012", ",", "3", ",", "19"}], "}"}], ",", "4.37`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "5"}], "}"}], ",", "24", ",", + RowBox[{"{", + RowBox[{"2012", ",", "6", ",", "18"}], "}"}], ",", "4.49`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "5"}], "}"}], ",", "24", ",", + RowBox[{"{", + RowBox[{"2012", ",", "9", ",", "17"}], "}"}], ",", "4.61`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "5"}], "}"}], ",", "24", ",", + RowBox[{"{", + RowBox[{"2012", ",", "12", ",", "17"}], "}"}], ",", "4.72`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "5"}], "}"}], ",", "24", ",", + RowBox[{"{", + RowBox[{"2013", ",", "3", ",", "18"}], "}"}], ",", "4.81`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "5"}], "}"}], ",", "24", ",", + RowBox[{"{", + RowBox[{"2013", ",", "6", ",", "17"}], "}"}], ",", "4.91`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "5"}], "}"}], ",", "24", ",", + RowBox[{"{", + RowBox[{"2013", ",", "9", ",", "16"}], "}"}], ",", "5.`"}], "}"}], ",", + + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "5"}], "}"}], ",", "24", ",", + RowBox[{"{", + RowBox[{"2013", ",", "12", ",", "16"}], "}"}], ",", "5.09`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "5"}], "}"}], ",", "24", ",", + RowBox[{"{", + RowBox[{"2014", ",", "3", ",", "17"}], "}"}], ",", "5.17`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "5"}], "}"}], ",", "24", ",", + RowBox[{"{", + RowBox[{"2014", ",", "6", ",", "16"}], "}"}], ",", "5.24`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "5"}], "}"}], ",", "24", ",", + RowBox[{"{", + RowBox[{"2014", ",", "9", ",", "15"}], "}"}], ",", "5.31`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "5"}], "}"}], ",", "24", ",", + RowBox[{"{", + RowBox[{"2014", ",", "12", ",", "15"}], "}"}], ",", "5.38`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "5"}], "}"}], ",", "24", ",", + RowBox[{"{", + RowBox[{"2015", ",", "3", ",", "16"}], "}"}], ",", "5.44`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "5"}], "}"}], ",", "24", ",", + RowBox[{"{", + RowBox[{"2015", ",", "6", ",", "15"}], "}"}], ",", "5.5`"}], "}"}], ",", + + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "5"}], "}"}], ",", "24", ",", + RowBox[{"{", + RowBox[{"2015", ",", "9", ",", "14"}], "}"}], ",", "5.55`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "5"}], "}"}], ",", "24", ",", + RowBox[{"{", + RowBox[{"2015", ",", "12", ",", "14"}], "}"}], ",", "5.61`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "5"}], "}"}], ",", "24", ",", + RowBox[{"{", + RowBox[{"2016", ",", "3", ",", "14"}], "}"}], ",", "5.64`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "5"}], "}"}], ",", "24", ",", + RowBox[{"{", + RowBox[{"2016", ",", "6", ",", "13"}], "}"}], ",", "5.68`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "5"}], "}"}], ",", "24", ",", + RowBox[{"{", + RowBox[{"2016", ",", "9", ",", "19"}], "}"}], ",", "5.72`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "5"}], "}"}], ",", "24", ",", + RowBox[{"{", + RowBox[{"2016", ",", "12", ",", "19"}], "}"}], ",", "5.77`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "5"}], "}"}], ",", "24", ",", + RowBox[{"{", + RowBox[{"2017", ",", "3", ",", "13"}], "}"}], ",", "5.79`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "5"}], "}"}], ",", "24", ",", + RowBox[{"{", + RowBox[{"2017", ",", "6", ",", "19"}], "}"}], ",", "5.81`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "5"}], "}"}], ",", "24", ",", + RowBox[{"{", + RowBox[{"2017", ",", "9", ",", "18"}], "}"}], ",", "5.84`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "5"}], "}"}], ",", "24", ",", + RowBox[{"{", + RowBox[{"2017", ",", "12", ",", "18"}], "}"}], ",", "5.88`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "6"}], "}"}], ",", "25", ",", + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "18"}], "}"}], ",", "3.03`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "6"}], "}"}], ",", "25", ",", + RowBox[{"{", + RowBox[{"2008", ",", "3", ",", "17"}], "}"}], ",", "2.88`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "6"}], "}"}], ",", "25", ",", + RowBox[{"{", + RowBox[{"2008", ",", "4", ",", "14"}], "}"}], ",", "2.73`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "6"}], "}"}], ",", "25", ",", + RowBox[{"{", + RowBox[{"2008", ",", "5", ",", "19"}], "}"}], ",", "2.56`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "6"}], "}"}], ",", "25", ",", + RowBox[{"{", + RowBox[{"2008", ",", "6", ",", "16"}], "}"}], ",", "2.44`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "6"}], "}"}], ",", "25", ",", + RowBox[{"{", + RowBox[{"2008", ",", "9", ",", "15"}], "}"}], ",", "2.33`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "6"}], "}"}], ",", "25", ",", + RowBox[{"{", + RowBox[{"2008", ",", "12", ",", "15"}], "}"}], ",", "2.37`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "6"}], "}"}], ",", "25", ",", + RowBox[{"{", + RowBox[{"2009", ",", "3", ",", "16"}], "}"}], ",", "2.5`"}], "}"}], ",", + + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "6"}], "}"}], ",", "25", ",", + RowBox[{"{", + RowBox[{"2009", ",", "6", ",", "15"}], "}"}], ",", "2.7`"}], "}"}], ",", + + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "6"}], "}"}], ",", "25", ",", + RowBox[{"{", + RowBox[{"2009", ",", "9", ",", "14"}], "}"}], ",", "2.9`"}], "}"}], ",", + + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "6"}], "}"}], ",", "25", ",", + RowBox[{"{", + RowBox[{"2009", ",", "12", ",", "14"}], "}"}], ",", "3.09`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "6"}], "}"}], ",", "25", ",", + RowBox[{"{", + RowBox[{"2010", ",", "3", ",", "15"}], "}"}], ",", "3.26`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "6"}], "}"}], ",", "25", ",", + RowBox[{"{", + RowBox[{"2010", ",", "6", ",", "14"}], "}"}], ",", "3.44`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "6"}], "}"}], ",", "25", ",", + RowBox[{"{", + RowBox[{"2010", ",", "9", ",", "13"}], "}"}], ",", "3.61`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "6"}], "}"}], ",", "25", ",", + RowBox[{"{", + RowBox[{"2010", ",", "12", ",", "13"}], "}"}], ",", "3.76`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "6"}], "}"}], ",", "25", ",", + RowBox[{"{", + RowBox[{"2011", ",", "3", ",", "14"}], "}"}], ",", "3.9`"}], "}"}], ",", + + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "6"}], "}"}], ",", "25", ",", + RowBox[{"{", + RowBox[{"2011", ",", "6", ",", "13"}], "}"}], ",", "4.04`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "6"}], "}"}], ",", "25", ",", + RowBox[{"{", + RowBox[{"2011", ",", "9", ",", "19"}], "}"}], ",", "4.17`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "6"}], "}"}], ",", "25", ",", + RowBox[{"{", + RowBox[{"2011", ",", "12", ",", "19"}], "}"}], ",", "4.3`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "6"}], "}"}], ",", "25", ",", + RowBox[{"{", + RowBox[{"2012", ",", "3", ",", "19"}], "}"}], ",", "4.41`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "6"}], "}"}], ",", "25", ",", + RowBox[{"{", + RowBox[{"2012", ",", "6", ",", "18"}], "}"}], ",", "4.53`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "6"}], "}"}], ",", "25", ",", + RowBox[{"{", + RowBox[{"2012", ",", "9", ",", "17"}], "}"}], ",", "4.64`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "6"}], "}"}], ",", "25", ",", + RowBox[{"{", + RowBox[{"2012", ",", "12", ",", "17"}], "}"}], ",", "4.76`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "6"}], "}"}], ",", "25", ",", + RowBox[{"{", + RowBox[{"2013", ",", "3", ",", "18"}], "}"}], ",", "4.85`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "6"}], "}"}], ",", "25", ",", + RowBox[{"{", + RowBox[{"2013", ",", "6", ",", "17"}], "}"}], ",", "4.95`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "6"}], "}"}], ",", "25", ",", + RowBox[{"{", + RowBox[{"2013", ",", "9", ",", "16"}], "}"}], ",", "5.04`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "6"}], "}"}], ",", "25", ",", + RowBox[{"{", + RowBox[{"2013", ",", "12", ",", "16"}], "}"}], ",", "5.13`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "6"}], "}"}], ",", "25", ",", + RowBox[{"{", + RowBox[{"2014", ",", "3", ",", "17"}], "}"}], ",", "5.21`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "6"}], "}"}], ",", "25", ",", + RowBox[{"{", + RowBox[{"2014", ",", "6", ",", "16"}], "}"}], ",", "5.28`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "6"}], "}"}], ",", "25", ",", + RowBox[{"{", + RowBox[{"2014", ",", "9", ",", "15"}], "}"}], ",", "5.35`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "6"}], "}"}], ",", "25", ",", + RowBox[{"{", + RowBox[{"2014", ",", "12", ",", "15"}], "}"}], ",", "5.42`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "6"}], "}"}], ",", "25", ",", + RowBox[{"{", + RowBox[{"2015", ",", "3", ",", "16"}], "}"}], ",", "5.48`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "6"}], "}"}], ",", "25", ",", + RowBox[{"{", + RowBox[{"2015", ",", "6", ",", "15"}], "}"}], ",", "5.54`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "6"}], "}"}], ",", "25", ",", + RowBox[{"{", + RowBox[{"2015", ",", "9", ",", "14"}], "}"}], ",", "5.59`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "6"}], "}"}], ",", "25", ",", + RowBox[{"{", + RowBox[{"2015", ",", "12", ",", "14"}], "}"}], ",", "5.65`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "6"}], "}"}], ",", "25", ",", + RowBox[{"{", + RowBox[{"2016", ",", "3", ",", "14"}], "}"}], ",", "5.69`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "6"}], "}"}], ",", "25", ",", + RowBox[{"{", + RowBox[{"2016", ",", "6", ",", "13"}], "}"}], ",", "5.73`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "6"}], "}"}], ",", "25", ",", + RowBox[{"{", + RowBox[{"2016", ",", "9", ",", "19"}], "}"}], ",", "5.77`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "6"}], "}"}], ",", "25", ",", + RowBox[{"{", + RowBox[{"2016", ",", "12", ",", "19"}], "}"}], ",", "5.82`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "6"}], "}"}], ",", "25", ",", + RowBox[{"{", + RowBox[{"2017", ",", "3", ",", "13"}], "}"}], ",", "5.84`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "6"}], "}"}], ",", "25", ",", + RowBox[{"{", + RowBox[{"2017", ",", "6", ",", "19"}], "}"}], ",", "5.86`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "6"}], "}"}], ",", "25", ",", + RowBox[{"{", + RowBox[{"2017", ",", "9", ",", "18"}], "}"}], ",", "5.88`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "6"}], "}"}], ",", "25", ",", + RowBox[{"{", + RowBox[{"2017", ",", "12", ",", "18"}], "}"}], ",", "5.93`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "7"}], "}"}], ",", "26", ",", + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "18"}], "}"}], ",", "3.02`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "7"}], "}"}], ",", "26", ",", + RowBox[{"{", + RowBox[{"2008", ",", "3", ",", "17"}], "}"}], ",", "2.88`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "7"}], "}"}], ",", "26", ",", + RowBox[{"{", + RowBox[{"2008", ",", "4", ",", "14"}], "}"}], ",", "2.73`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "7"}], "}"}], ",", "26", ",", + RowBox[{"{", + RowBox[{"2008", ",", "5", ",", "19"}], "}"}], ",", "2.56`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "7"}], "}"}], ",", "26", ",", + RowBox[{"{", + RowBox[{"2008", ",", "6", ",", "16"}], "}"}], ",", "2.45`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "7"}], "}"}], ",", "26", ",", + RowBox[{"{", + RowBox[{"2008", ",", "9", ",", "15"}], "}"}], ",", "2.35`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "7"}], "}"}], ",", "26", ",", + RowBox[{"{", + RowBox[{"2008", ",", "12", ",", "15"}], "}"}], ",", "2.4`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "7"}], "}"}], ",", "26", ",", + RowBox[{"{", + RowBox[{"2009", ",", "3", ",", "16"}], "}"}], ",", "2.54`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "7"}], "}"}], ",", "26", ",", + RowBox[{"{", + RowBox[{"2009", ",", "6", ",", "15"}], "}"}], ",", "2.77`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "7"}], "}"}], ",", "26", ",", + RowBox[{"{", + RowBox[{"2009", ",", "9", ",", "14"}], "}"}], ",", "3.`"}], "}"}], ",", + + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "7"}], "}"}], ",", "26", ",", + RowBox[{"{", + RowBox[{"2009", ",", "12", ",", "14"}], "}"}], ",", "3.21`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "7"}], "}"}], ",", "26", ",", + RowBox[{"{", + RowBox[{"2010", ",", "3", ",", "15"}], "}"}], ",", "3.39`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "7"}], "}"}], ",", "26", ",", + RowBox[{"{", + RowBox[{"2010", ",", "6", ",", "14"}], "}"}], ",", "3.58`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "7"}], "}"}], ",", "26", ",", + RowBox[{"{", + RowBox[{"2010", ",", "9", ",", "13"}], "}"}], ",", "3.75`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "7"}], "}"}], ",", "26", ",", + RowBox[{"{", + RowBox[{"2010", ",", "12", ",", "13"}], "}"}], ",", "3.91`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "7"}], "}"}], ",", "26", ",", + RowBox[{"{", + RowBox[{"2011", ",", "3", ",", "14"}], "}"}], ",", "4.05`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "7"}], "}"}], ",", "26", ",", + RowBox[{"{", + RowBox[{"2011", ",", "6", ",", "13"}], "}"}], ",", "4.19`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "7"}], "}"}], ",", "26", ",", + RowBox[{"{", + RowBox[{"2011", ",", "9", ",", "19"}], "}"}], ",", "4.33`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "7"}], "}"}], ",", "26", ",", + RowBox[{"{", + RowBox[{"2011", ",", "12", ",", "19"}], "}"}], ",", "4.46`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "7"}], "}"}], ",", "26", ",", + RowBox[{"{", + RowBox[{"2012", ",", "3", ",", "19"}], "}"}], ",", "4.57`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "7"}], "}"}], ",", "26", ",", + RowBox[{"{", + RowBox[{"2012", ",", "6", ",", "18"}], "}"}], ",", "4.69`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "7"}], "}"}], ",", "26", ",", + RowBox[{"{", + RowBox[{"2012", ",", "9", ",", "17"}], "}"}], ",", "4.81`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "7"}], "}"}], ",", "26", ",", + RowBox[{"{", + RowBox[{"2012", ",", "12", ",", "17"}], "}"}], ",", "4.92`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "7"}], "}"}], ",", "26", ",", + RowBox[{"{", + RowBox[{"2013", ",", "3", ",", "18"}], "}"}], ",", "5.02`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "7"}], "}"}], ",", "26", ",", + RowBox[{"{", + RowBox[{"2013", ",", "6", ",", "17"}], "}"}], ",", "5.11`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "7"}], "}"}], ",", "26", ",", + RowBox[{"{", + RowBox[{"2013", ",", "9", ",", "16"}], "}"}], ",", "5.2`"}], "}"}], ",", + + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "7"}], "}"}], ",", "26", ",", + RowBox[{"{", + RowBox[{"2013", ",", "12", ",", "16"}], "}"}], ",", "5.3`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "7"}], "}"}], ",", "26", ",", + RowBox[{"{", + RowBox[{"2014", ",", "3", ",", "17"}], "}"}], ",", "5.37`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "7"}], "}"}], ",", "26", ",", + RowBox[{"{", + RowBox[{"2014", ",", "6", ",", "16"}], "}"}], ",", "5.45`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "7"}], "}"}], ",", "26", ",", + RowBox[{"{", + RowBox[{"2014", ",", "9", ",", "15"}], "}"}], ",", "5.51`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "7"}], "}"}], ",", "26", ",", + RowBox[{"{", + RowBox[{"2014", ",", "12", ",", "15"}], "}"}], ",", "5.59`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "7"}], "}"}], ",", "26", ",", + RowBox[{"{", + RowBox[{"2015", ",", "3", ",", "16"}], "}"}], ",", "5.65`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "7"}], "}"}], ",", "26", ",", + RowBox[{"{", + RowBox[{"2015", ",", "6", ",", "15"}], "}"}], ",", "5.7`"}], "}"}], ",", + + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "7"}], "}"}], ",", "26", ",", + RowBox[{"{", + RowBox[{"2015", ",", "9", ",", "14"}], "}"}], ",", "5.75`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "7"}], "}"}], ",", "26", ",", + RowBox[{"{", + RowBox[{"2015", ",", "12", ",", "14"}], "}"}], ",", "5.81`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "7"}], "}"}], ",", "26", ",", + RowBox[{"{", + RowBox[{"2016", ",", "3", ",", "14"}], "}"}], ",", "5.85`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "7"}], "}"}], ",", "26", ",", + RowBox[{"{", + RowBox[{"2016", ",", "6", ",", "13"}], "}"}], ",", "5.89`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "7"}], "}"}], ",", "26", ",", + RowBox[{"{", + RowBox[{"2016", ",", "9", ",", "19"}], "}"}], ",", "5.93`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "7"}], "}"}], ",", "26", ",", + RowBox[{"{", + RowBox[{"2016", ",", "12", ",", "19"}], "}"}], ",", "5.98`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "7"}], "}"}], ",", "26", ",", + RowBox[{"{", + RowBox[{"2017", ",", "3", ",", "13"}], "}"}], ",", "6.`"}], "}"}], ",", + + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "7"}], "}"}], ",", "26", ",", + RowBox[{"{", + RowBox[{"2017", ",", "6", ",", "19"}], "}"}], ",", "6.02`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "7"}], "}"}], ",", "26", ",", + RowBox[{"{", + RowBox[{"2017", ",", "9", ",", "18"}], "}"}], ",", "6.05`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "7"}], "}"}], ",", "26", ",", + RowBox[{"{", + RowBox[{"2017", ",", "12", ",", "18"}], "}"}], ",", "6.09`"}], "}"}]}], + "}"}]], "Output", + CellChangeTimes->{ + 3.4114831880246334`*^9, {3.411483319727852*^9, 3.4114833361552486`*^9}, + 3.411483718738041*^9, 3.411484017345087*^9}] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{"Cases", "[", + RowBox[{"%", ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"_", ",", "_", ",", "_"}], "}"}], ",", "__"}], "}"}]}], + "]"}]], "Input", + CellChangeTimes->{{3.411484051239382*^9, 3.4114840603695793`*^9}}], + +Cell[BoxData[ + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "28"}], "}"}], ",", "18", ",", + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "18"}], "}"}], ",", "3.1`"}], "}"}], ",", + + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "28"}], "}"}], ",", "18", ",", + RowBox[{"{", + RowBox[{"2008", ",", "3", ",", "17"}], "}"}], ",", "3.`"}], "}"}], ",", + + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "28"}], "}"}], ",", "18", ",", + RowBox[{"{", + RowBox[{"2008", ",", "4", ",", "14"}], "}"}], ",", "2.87`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "28"}], "}"}], ",", "18", ",", + RowBox[{"{", + RowBox[{"2008", ",", "5", ",", "19"}], "}"}], ",", "2.69`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "28"}], "}"}], ",", "18", ",", + RowBox[{"{", + RowBox[{"2008", ",", "6", ",", "16"}], "}"}], ",", "2.57`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "28"}], "}"}], ",", "18", ",", + RowBox[{"{", + RowBox[{"2008", ",", "9", ",", "15"}], "}"}], ",", "2.51`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "28"}], "}"}], ",", "18", ",", + RowBox[{"{", + RowBox[{"2008", ",", "12", ",", "15"}], "}"}], ",", "2.58`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "28"}], "}"}], ",", "18", ",", + RowBox[{"{", + RowBox[{"2009", ",", "3", ",", "16"}], "}"}], ",", "2.69`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "28"}], "}"}], ",", "18", ",", + RowBox[{"{", + RowBox[{"2009", ",", "6", ",", "15"}], "}"}], ",", "2.85`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "28"}], "}"}], ",", "18", ",", + RowBox[{"{", + RowBox[{"2009", ",", "9", ",", "14"}], "}"}], ",", "3.01`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "28"}], "}"}], ",", "18", ",", + RowBox[{"{", + RowBox[{"2009", ",", "12", ",", "14"}], "}"}], ",", "3.16`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "28"}], "}"}], ",", "18", ",", + RowBox[{"{", + RowBox[{"2010", ",", "3", ",", "15"}], "}"}], ",", "3.3`"}], "}"}], ",", + + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "28"}], "}"}], ",", "18", ",", + RowBox[{"{", + RowBox[{"2010", ",", "6", ",", "14"}], "}"}], ",", "3.46`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "28"}], "}"}], ",", "18", ",", + RowBox[{"{", + RowBox[{"2010", ",", "9", ",", "13"}], "}"}], ",", "3.61`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "28"}], "}"}], ",", "18", ",", + RowBox[{"{", + RowBox[{"2010", ",", "12", ",", "13"}], "}"}], ",", "3.74`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "28"}], "}"}], ",", "18", ",", + RowBox[{"{", + RowBox[{"2011", ",", "3", ",", "14"}], "}"}], ",", "3.87`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "28"}], "}"}], ",", "18", ",", + RowBox[{"{", + RowBox[{"2011", ",", "6", ",", "13"}], "}"}], ",", "4.`"}], "}"}], ",", + + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "28"}], "}"}], ",", "18", ",", + RowBox[{"{", + RowBox[{"2011", ",", "9", ",", "19"}], "}"}], ",", "4.13`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "28"}], "}"}], ",", "18", ",", + RowBox[{"{", + RowBox[{"2011", ",", "12", ",", "19"}], "}"}], ",", "4.25`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "28"}], "}"}], ",", "18", ",", + RowBox[{"{", + RowBox[{"2012", ",", "3", ",", "19"}], "}"}], ",", "4.35`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "28"}], "}"}], ",", "18", ",", + RowBox[{"{", + RowBox[{"2012", ",", "6", ",", "18"}], "}"}], ",", "4.46`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "28"}], "}"}], ",", "18", ",", + RowBox[{"{", + RowBox[{"2012", ",", "9", ",", "17"}], "}"}], ",", "4.57`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "28"}], "}"}], ",", "18", ",", + RowBox[{"{", + RowBox[{"2012", ",", "12", ",", "17"}], "}"}], ",", "4.68`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "28"}], "}"}], ",", "18", ",", + RowBox[{"{", + RowBox[{"2013", ",", "3", ",", "18"}], "}"}], ",", "4.76`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "28"}], "}"}], ",", "18", ",", + RowBox[{"{", + RowBox[{"2013", ",", "6", ",", "17"}], "}"}], ",", "4.85`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "28"}], "}"}], ",", "18", ",", + RowBox[{"{", + RowBox[{"2013", ",", "9", ",", "16"}], "}"}], ",", "4.94`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "28"}], "}"}], ",", "18", ",", + RowBox[{"{", + RowBox[{"2013", ",", "12", ",", "16"}], "}"}], ",", "5.04`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "28"}], "}"}], ",", "18", ",", + RowBox[{"{", + RowBox[{"2014", ",", "3", ",", "17"}], "}"}], ",", "5.11`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "28"}], "}"}], ",", "18", ",", + RowBox[{"{", + RowBox[{"2014", ",", "6", ",", "16"}], "}"}], ",", "5.19`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "28"}], "}"}], ",", "18", ",", + RowBox[{"{", + RowBox[{"2014", ",", "9", ",", "15"}], "}"}], ",", "5.25`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "28"}], "}"}], ",", "18", ",", + RowBox[{"{", + RowBox[{"2014", ",", "12", ",", "15"}], "}"}], ",", "5.33`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "28"}], "}"}], ",", "18", ",", + RowBox[{"{", + RowBox[{"2015", ",", "3", ",", "16"}], "}"}], ",", "5.38`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "28"}], "}"}], ",", "18", ",", + RowBox[{"{", + RowBox[{"2015", ",", "6", ",", "15"}], "}"}], ",", "5.43`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "28"}], "}"}], ",", "18", ",", + RowBox[{"{", + RowBox[{"2015", ",", "9", ",", "14"}], "}"}], ",", "5.48`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "28"}], "}"}], ",", "18", ",", + RowBox[{"{", + RowBox[{"2015", ",", "12", ",", "14"}], "}"}], ",", "5.54`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "28"}], "}"}], ",", "18", ",", + RowBox[{"{", + RowBox[{"2016", ",", "3", ",", "14"}], "}"}], ",", "5.58`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "28"}], "}"}], ",", "18", ",", + RowBox[{"{", + RowBox[{"2016", ",", "6", ",", "13"}], "}"}], ",", "5.62`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "28"}], "}"}], ",", "18", ",", + RowBox[{"{", + RowBox[{"2016", ",", "9", ",", "19"}], "}"}], ",", "5.66`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "28"}], "}"}], ",", "18", ",", + RowBox[{"{", + RowBox[{"2016", ",", "12", ",", "19"}], "}"}], ",", "5.71`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "28"}], "}"}], ",", "18", ",", + RowBox[{"{", + RowBox[{"2017", ",", "3", ",", "13"}], "}"}], ",", "5.73`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "28"}], "}"}], ",", "18", ",", + RowBox[{"{", + RowBox[{"2017", ",", "6", ",", "19"}], "}"}], ",", "5.75`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "28"}], "}"}], ",", "18", ",", + RowBox[{"{", + RowBox[{"2017", ",", "9", ",", "18"}], "}"}], ",", "5.78`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "28"}], "}"}], ",", "18", ",", + RowBox[{"{", + RowBox[{"2017", ",", "12", ",", "18"}], "}"}], ",", "5.82`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "29"}], "}"}], ",", "19", ",", + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "18"}], "}"}], ",", "3.14`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "29"}], "}"}], ",", "19", ",", + RowBox[{"{", + RowBox[{"2008", ",", "3", ",", "17"}], "}"}], ",", "3.03`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "29"}], "}"}], ",", "19", ",", + RowBox[{"{", + RowBox[{"2008", ",", "4", ",", "14"}], "}"}], ",", "2.89`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "29"}], "}"}], ",", "19", ",", + RowBox[{"{", + RowBox[{"2008", ",", "5", ",", "19"}], "}"}], ",", "2.73`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "29"}], "}"}], ",", "19", ",", + RowBox[{"{", + RowBox[{"2008", ",", "6", ",", "16"}], "}"}], ",", "2.62`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "29"}], "}"}], ",", "19", ",", + RowBox[{"{", + RowBox[{"2008", ",", "9", ",", "15"}], "}"}], ",", "2.59`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "29"}], "}"}], ",", "19", ",", + RowBox[{"{", + RowBox[{"2008", ",", "12", ",", "15"}], "}"}], ",", "2.67`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "29"}], "}"}], ",", "19", ",", + RowBox[{"{", + RowBox[{"2009", ",", "3", ",", "16"}], "}"}], ",", "2.79`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "29"}], "}"}], ",", "19", ",", + RowBox[{"{", + RowBox[{"2009", ",", "6", ",", "15"}], "}"}], ",", "2.95`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "29"}], "}"}], ",", "19", ",", + RowBox[{"{", + RowBox[{"2009", ",", "9", ",", "14"}], "}"}], ",", "3.1`"}], "}"}], ",", + + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "29"}], "}"}], ",", "19", ",", + RowBox[{"{", + RowBox[{"2009", ",", "12", ",", "14"}], "}"}], ",", "3.24`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "29"}], "}"}], ",", "19", ",", + RowBox[{"{", + RowBox[{"2010", ",", "3", ",", "15"}], "}"}], ",", "3.37`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "29"}], "}"}], ",", "19", ",", + RowBox[{"{", + RowBox[{"2010", ",", "6", ",", "14"}], "}"}], ",", "3.52`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "29"}], "}"}], ",", "19", ",", + RowBox[{"{", + RowBox[{"2010", ",", "9", ",", "13"}], "}"}], ",", "3.67`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "29"}], "}"}], ",", "19", ",", + RowBox[{"{", + RowBox[{"2010", ",", "12", ",", "13"}], "}"}], ",", "3.8`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "29"}], "}"}], ",", "19", ",", + RowBox[{"{", + RowBox[{"2011", ",", "3", ",", "14"}], "}"}], ",", "3.91`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "29"}], "}"}], ",", "19", ",", + RowBox[{"{", + RowBox[{"2011", ",", "6", ",", "13"}], "}"}], ",", "4.04`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "29"}], "}"}], ",", "19", ",", + RowBox[{"{", + RowBox[{"2011", ",", "9", ",", "19"}], "}"}], ",", "4.17`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "29"}], "}"}], ",", "19", ",", + RowBox[{"{", + RowBox[{"2011", ",", "12", ",", "19"}], "}"}], ",", "4.29`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "29"}], "}"}], ",", "19", ",", + RowBox[{"{", + RowBox[{"2012", ",", "3", ",", "19"}], "}"}], ",", "4.39`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "29"}], "}"}], ",", "19", ",", + RowBox[{"{", + RowBox[{"2012", ",", "6", ",", "18"}], "}"}], ",", "4.49`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "29"}], "}"}], ",", "19", ",", + RowBox[{"{", + RowBox[{"2012", ",", "9", ",", "17"}], "}"}], ",", "4.6`"}], "}"}], ",", + + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "29"}], "}"}], ",", "19", ",", + RowBox[{"{", + RowBox[{"2012", ",", "12", ",", "17"}], "}"}], ",", "4.7`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "29"}], "}"}], ",", "19", ",", + RowBox[{"{", + RowBox[{"2013", ",", "3", ",", "18"}], "}"}], ",", "4.78`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "29"}], "}"}], ",", "19", ",", + RowBox[{"{", + RowBox[{"2013", ",", "6", ",", "17"}], "}"}], ",", "4.88`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "29"}], "}"}], ",", "19", ",", + RowBox[{"{", + RowBox[{"2013", ",", "9", ",", "16"}], "}"}], ",", "4.97`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "29"}], "}"}], ",", "19", ",", + RowBox[{"{", + RowBox[{"2013", ",", "12", ",", "16"}], "}"}], ",", "5.06`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "29"}], "}"}], ",", "19", ",", + RowBox[{"{", + RowBox[{"2014", ",", "3", ",", "17"}], "}"}], ",", "5.13`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "29"}], "}"}], ",", "19", ",", + RowBox[{"{", + RowBox[{"2014", ",", "6", ",", "16"}], "}"}], ",", "5.21`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "29"}], "}"}], ",", "19", ",", + RowBox[{"{", + RowBox[{"2014", ",", "9", ",", "15"}], "}"}], ",", "5.27`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "29"}], "}"}], ",", "19", ",", + RowBox[{"{", + RowBox[{"2014", ",", "12", ",", "15"}], "}"}], ",", "5.35`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "29"}], "}"}], ",", "19", ",", + RowBox[{"{", + RowBox[{"2015", ",", "3", ",", "16"}], "}"}], ",", "5.4`"}], "}"}], ",", + + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "29"}], "}"}], ",", "19", ",", + RowBox[{"{", + RowBox[{"2015", ",", "6", ",", "15"}], "}"}], ",", "5.45`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "29"}], "}"}], ",", "19", ",", + RowBox[{"{", + RowBox[{"2015", ",", "9", ",", "14"}], "}"}], ",", "5.5`"}], "}"}], ",", + + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "29"}], "}"}], ",", "19", ",", + RowBox[{"{", + RowBox[{"2015", ",", "12", ",", "14"}], "}"}], ",", "5.56`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "29"}], "}"}], ",", "19", ",", + RowBox[{"{", + RowBox[{"2016", ",", "3", ",", "14"}], "}"}], ",", "5.59`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "29"}], "}"}], ",", "19", ",", + RowBox[{"{", + RowBox[{"2016", ",", "6", ",", "13"}], "}"}], ",", "5.63`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "29"}], "}"}], ",", "19", ",", + RowBox[{"{", + RowBox[{"2016", ",", "9", ",", "19"}], "}"}], ",", "5.67`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "29"}], "}"}], ",", "19", ",", + RowBox[{"{", + RowBox[{"2016", ",", "12", ",", "19"}], "}"}], ",", "5.72`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "29"}], "}"}], ",", "19", ",", + RowBox[{"{", + RowBox[{"2017", ",", "3", ",", "13"}], "}"}], ",", "5.74`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "29"}], "}"}], ",", "19", ",", + RowBox[{"{", + RowBox[{"2017", ",", "6", ",", "19"}], "}"}], ",", "5.76`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "29"}], "}"}], ",", "19", ",", + RowBox[{"{", + RowBox[{"2017", ",", "9", ",", "18"}], "}"}], ",", "5.79`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "29"}], "}"}], ",", "19", ",", + RowBox[{"{", + RowBox[{"2017", ",", "12", ",", "18"}], "}"}], ",", "5.83`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "30"}], "}"}], ",", "20", ",", + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "18"}], "}"}], ",", "3.06`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "30"}], "}"}], ",", "20", ",", + RowBox[{"{", + RowBox[{"2008", ",", "3", ",", "17"}], "}"}], ",", "2.95`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "30"}], "}"}], ",", "20", ",", + RowBox[{"{", + RowBox[{"2008", ",", "4", ",", "14"}], "}"}], ",", "2.81`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "30"}], "}"}], ",", "20", ",", + RowBox[{"{", + RowBox[{"2008", ",", "5", ",", "19"}], "}"}], ",", "2.65`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "30"}], "}"}], ",", "20", ",", + RowBox[{"{", + RowBox[{"2008", ",", "6", ",", "16"}], "}"}], ",", "2.55`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "30"}], "}"}], ",", "20", ",", + RowBox[{"{", + RowBox[{"2008", ",", "9", ",", "15"}], "}"}], ",", "2.53`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "30"}], "}"}], ",", "20", ",", + RowBox[{"{", + RowBox[{"2008", ",", "12", ",", "15"}], "}"}], ",", "2.65`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "30"}], "}"}], ",", "20", ",", + RowBox[{"{", + RowBox[{"2009", ",", "3", ",", "16"}], "}"}], ",", "2.82`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "30"}], "}"}], ",", "20", ",", + RowBox[{"{", + RowBox[{"2009", ",", "6", ",", "15"}], "}"}], ",", "3.01`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "30"}], "}"}], ",", "20", ",", + RowBox[{"{", + RowBox[{"2009", ",", "9", ",", "14"}], "}"}], ",", "3.18`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "30"}], "}"}], ",", "20", ",", + RowBox[{"{", + RowBox[{"2009", ",", "12", ",", "14"}], "}"}], ",", "3.34`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "30"}], "}"}], ",", "20", ",", + RowBox[{"{", + RowBox[{"2010", ",", "3", ",", "15"}], "}"}], ",", "3.49`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "30"}], "}"}], ",", "20", ",", + RowBox[{"{", + RowBox[{"2010", ",", "6", ",", "14"}], "}"}], ",", "3.65`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "30"}], "}"}], ",", "20", ",", + RowBox[{"{", + RowBox[{"2010", ",", "9", ",", "13"}], "}"}], ",", "3.8`"}], "}"}], ",", + + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "30"}], "}"}], ",", "20", ",", + RowBox[{"{", + RowBox[{"2010", ",", "12", ",", "13"}], "}"}], ",", "3.94`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "30"}], "}"}], ",", "20", ",", + RowBox[{"{", + RowBox[{"2011", ",", "3", ",", "14"}], "}"}], ",", "4.05`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "30"}], "}"}], ",", "20", ",", + RowBox[{"{", + RowBox[{"2011", ",", "6", ",", "13"}], "}"}], ",", "4.18`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "30"}], "}"}], ",", "20", ",", + RowBox[{"{", + RowBox[{"2011", ",", "9", ",", "19"}], "}"}], ",", "4.31`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "30"}], "}"}], ",", "20", ",", + RowBox[{"{", + RowBox[{"2011", ",", "12", ",", "19"}], "}"}], ",", "4.43`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "30"}], "}"}], ",", "20", ",", + RowBox[{"{", + RowBox[{"2012", ",", "3", ",", "19"}], "}"}], ",", "4.53`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "30"}], "}"}], ",", "20", ",", + RowBox[{"{", + RowBox[{"2012", ",", "6", ",", "18"}], "}"}], ",", "4.63`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "30"}], "}"}], ",", "20", ",", + RowBox[{"{", + RowBox[{"2012", ",", "9", ",", "17"}], "}"}], ",", "4.74`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "30"}], "}"}], ",", "20", ",", + RowBox[{"{", + RowBox[{"2012", ",", "12", ",", "17"}], "}"}], ",", "4.84`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "30"}], "}"}], ",", "20", ",", + RowBox[{"{", + RowBox[{"2013", ",", "3", ",", "18"}], "}"}], ",", "4.92`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "30"}], "}"}], ",", "20", ",", + RowBox[{"{", + RowBox[{"2013", ",", "6", ",", "17"}], "}"}], ",", "5.02`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "30"}], "}"}], ",", "20", ",", + RowBox[{"{", + RowBox[{"2013", ",", "9", ",", "16"}], "}"}], ",", "5.11`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "30"}], "}"}], ",", "20", ",", + RowBox[{"{", + RowBox[{"2013", ",", "12", ",", "16"}], "}"}], ",", "5.2`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "30"}], "}"}], ",", "20", ",", + RowBox[{"{", + RowBox[{"2014", ",", "3", ",", "17"}], "}"}], ",", "5.27`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "30"}], "}"}], ",", "20", ",", + RowBox[{"{", + RowBox[{"2014", ",", "6", ",", "16"}], "}"}], ",", "5.35`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "30"}], "}"}], ",", "20", ",", + RowBox[{"{", + RowBox[{"2014", ",", "9", ",", "15"}], "}"}], ",", "5.41`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "30"}], "}"}], ",", "20", ",", + RowBox[{"{", + RowBox[{"2014", ",", "12", ",", "15"}], "}"}], ",", "5.49`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "30"}], "}"}], ",", "20", ",", + RowBox[{"{", + RowBox[{"2015", ",", "3", ",", "16"}], "}"}], ",", "5.54`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "30"}], "}"}], ",", "20", ",", + RowBox[{"{", + RowBox[{"2015", ",", "6", ",", "15"}], "}"}], ",", "5.59`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "30"}], "}"}], ",", "20", ",", + RowBox[{"{", + RowBox[{"2015", ",", "9", ",", "14"}], "}"}], ",", "5.64`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "30"}], "}"}], ",", "20", ",", + RowBox[{"{", + RowBox[{"2015", ",", "12", ",", "14"}], "}"}], ",", "5.7`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "30"}], "}"}], ",", "20", ",", + RowBox[{"{", + RowBox[{"2016", ",", "3", ",", "14"}], "}"}], ",", "5.73`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "30"}], "}"}], ",", "20", ",", + RowBox[{"{", + RowBox[{"2016", ",", "6", ",", "13"}], "}"}], ",", "5.77`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "30"}], "}"}], ",", "20", ",", + RowBox[{"{", + RowBox[{"2016", ",", "9", ",", "19"}], "}"}], ",", "5.81`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "30"}], "}"}], ",", "20", ",", + RowBox[{"{", + RowBox[{"2016", ",", "12", ",", "19"}], "}"}], ",", "5.86`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "30"}], "}"}], ",", "20", ",", + RowBox[{"{", + RowBox[{"2017", ",", "3", ",", "13"}], "}"}], ",", "5.88`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "30"}], "}"}], ",", "20", ",", + RowBox[{"{", + RowBox[{"2017", ",", "6", ",", "19"}], "}"}], ",", "5.9`"}], "}"}], ",", + + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "30"}], "}"}], ",", "20", ",", + RowBox[{"{", + RowBox[{"2017", ",", "9", ",", "18"}], "}"}], ",", "5.93`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "30"}], "}"}], ",", "20", ",", + RowBox[{"{", + RowBox[{"2017", ",", "12", ",", "18"}], "}"}], ",", "5.97`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "31"}], "}"}], ",", "21", ",", + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "18"}], "}"}], ",", "3.03`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "31"}], "}"}], ",", "21", ",", + RowBox[{"{", + RowBox[{"2008", ",", "3", ",", "17"}], "}"}], ",", "2.9`"}], "}"}], ",", + + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "31"}], "}"}], ",", "21", ",", + RowBox[{"{", + RowBox[{"2008", ",", "4", ",", "14"}], "}"}], ",", "2.76`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "31"}], "}"}], ",", "21", ",", + RowBox[{"{", + RowBox[{"2008", ",", "5", ",", "19"}], "}"}], ",", "2.6`"}], "}"}], ",", + + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "31"}], "}"}], ",", "21", ",", + RowBox[{"{", + RowBox[{"2008", ",", "6", ",", "16"}], "}"}], ",", "2.49`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "31"}], "}"}], ",", "21", ",", + RowBox[{"{", + RowBox[{"2008", ",", "9", ",", "15"}], "}"}], ",", "2.44`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "31"}], "}"}], ",", "21", ",", + RowBox[{"{", + RowBox[{"2008", ",", "12", ",", "15"}], "}"}], ",", "2.56`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "31"}], "}"}], ",", "21", ",", + RowBox[{"{", + RowBox[{"2009", ",", "3", ",", "16"}], "}"}], ",", "2.73`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "31"}], "}"}], ",", "21", ",", + RowBox[{"{", + RowBox[{"2009", ",", "6", ",", "15"}], "}"}], ",", "2.93`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "31"}], "}"}], ",", "21", ",", + RowBox[{"{", + RowBox[{"2009", ",", "9", ",", "14"}], "}"}], ",", "3.1`"}], "}"}], ",", + + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "31"}], "}"}], ",", "21", ",", + RowBox[{"{", + RowBox[{"2009", ",", "12", ",", "14"}], "}"}], ",", "3.26`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "31"}], "}"}], ",", "21", ",", + RowBox[{"{", + RowBox[{"2010", ",", "3", ",", "15"}], "}"}], ",", "3.41`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "31"}], "}"}], ",", "21", ",", + RowBox[{"{", + RowBox[{"2010", ",", "6", ",", "14"}], "}"}], ",", "3.57`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "31"}], "}"}], ",", "21", ",", + RowBox[{"{", + RowBox[{"2010", ",", "9", ",", "13"}], "}"}], ",", "3.71`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "31"}], "}"}], ",", "21", ",", + RowBox[{"{", + RowBox[{"2010", ",", "12", ",", "13"}], "}"}], ",", "3.84`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "31"}], "}"}], ",", "21", ",", + RowBox[{"{", + RowBox[{"2011", ",", "3", ",", "14"}], "}"}], ",", "3.95`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "31"}], "}"}], ",", "21", ",", + RowBox[{"{", + RowBox[{"2011", ",", "6", ",", "13"}], "}"}], ",", "4.07`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "31"}], "}"}], ",", "21", ",", + RowBox[{"{", + RowBox[{"2011", ",", "9", ",", "19"}], "}"}], ",", "4.2`"}], "}"}], ",", + + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "31"}], "}"}], ",", "21", ",", + RowBox[{"{", + RowBox[{"2011", ",", "12", ",", "19"}], "}"}], ",", "4.32`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "31"}], "}"}], ",", "21", ",", + RowBox[{"{", + RowBox[{"2012", ",", "3", ",", "19"}], "}"}], ",", "4.41`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "31"}], "}"}], ",", "21", ",", + RowBox[{"{", + RowBox[{"2012", ",", "6", ",", "18"}], "}"}], ",", "4.51`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "31"}], "}"}], ",", "21", ",", + RowBox[{"{", + RowBox[{"2012", ",", "9", ",", "17"}], "}"}], ",", "4.62`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "31"}], "}"}], ",", "21", ",", + RowBox[{"{", + RowBox[{"2012", ",", "12", ",", "17"}], "}"}], ",", "4.72`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "31"}], "}"}], ",", "21", ",", + RowBox[{"{", + RowBox[{"2013", ",", "3", ",", "18"}], "}"}], ",", "4.8`"}], "}"}], ",", + + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "31"}], "}"}], ",", "21", ",", + RowBox[{"{", + RowBox[{"2013", ",", "6", ",", "17"}], "}"}], ",", "4.9`"}], "}"}], ",", + + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "31"}], "}"}], ",", "21", ",", + RowBox[{"{", + RowBox[{"2013", ",", "9", ",", "16"}], "}"}], ",", "4.99`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "31"}], "}"}], ",", "21", ",", + RowBox[{"{", + RowBox[{"2013", ",", "12", ",", "16"}], "}"}], ",", "5.08`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "31"}], "}"}], ",", "21", ",", + RowBox[{"{", + RowBox[{"2014", ",", "3", ",", "17"}], "}"}], ",", "5.15`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "31"}], "}"}], ",", "21", ",", + RowBox[{"{", + RowBox[{"2014", ",", "6", ",", "16"}], "}"}], ",", "5.23`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "31"}], "}"}], ",", "21", ",", + RowBox[{"{", + RowBox[{"2014", ",", "9", ",", "15"}], "}"}], ",", "5.29`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "31"}], "}"}], ",", "21", ",", + RowBox[{"{", + RowBox[{"2014", ",", "12", ",", "15"}], "}"}], ",", "5.37`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "31"}], "}"}], ",", "21", ",", + RowBox[{"{", + RowBox[{"2015", ",", "3", ",", "16"}], "}"}], ",", "5.42`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "31"}], "}"}], ",", "21", ",", + RowBox[{"{", + RowBox[{"2015", ",", "6", ",", "15"}], "}"}], ",", "5.47`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "31"}], "}"}], ",", "21", ",", + RowBox[{"{", + RowBox[{"2015", ",", "9", ",", "14"}], "}"}], ",", "5.52`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "31"}], "}"}], ",", "21", ",", + RowBox[{"{", + RowBox[{"2015", ",", "12", ",", "14"}], "}"}], ",", "5.58`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "31"}], "}"}], ",", "21", ",", + RowBox[{"{", + RowBox[{"2016", ",", "3", ",", "14"}], "}"}], ",", "5.61`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "31"}], "}"}], ",", "21", ",", + RowBox[{"{", + RowBox[{"2016", ",", "6", ",", "13"}], "}"}], ",", "5.65`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "31"}], "}"}], ",", "21", ",", + RowBox[{"{", + RowBox[{"2016", ",", "9", ",", "19"}], "}"}], ",", "5.69`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "31"}], "}"}], ",", "21", ",", + RowBox[{"{", + RowBox[{"2016", ",", "12", ",", "19"}], "}"}], ",", "5.74`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "31"}], "}"}], ",", "21", ",", + RowBox[{"{", + RowBox[{"2017", ",", "3", ",", "13"}], "}"}], ",", "5.76`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "31"}], "}"}], ",", "21", ",", + RowBox[{"{", + RowBox[{"2017", ",", "6", ",", "19"}], "}"}], ",", "5.78`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "31"}], "}"}], ",", "21", ",", + RowBox[{"{", + RowBox[{"2017", ",", "9", ",", "18"}], "}"}], ",", "5.81`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "31"}], "}"}], ",", "21", ",", + RowBox[{"{", + RowBox[{"2017", ",", "12", ",", "18"}], "}"}], ",", "5.85`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "4"}], "}"}], ",", "23", ",", + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "18"}], "}"}], ",", "3.12`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "4"}], "}"}], ",", "23", ",", + RowBox[{"{", + RowBox[{"2008", ",", "3", ",", "17"}], "}"}], ",", "2.99`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "4"}], "}"}], ",", "23", ",", + RowBox[{"{", + RowBox[{"2008", ",", "4", ",", "14"}], "}"}], ",", "2.85`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "4"}], "}"}], ",", "23", ",", + RowBox[{"{", + RowBox[{"2008", ",", "5", ",", "19"}], "}"}], ",", "2.69`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "4"}], "}"}], ",", "23", ",", + RowBox[{"{", + RowBox[{"2008", ",", "6", ",", "16"}], "}"}], ",", "2.58`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "4"}], "}"}], ",", "23", ",", + RowBox[{"{", + RowBox[{"2008", ",", "9", ",", "15"}], "}"}], ",", "2.47`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "4"}], "}"}], ",", "23", ",", + RowBox[{"{", + RowBox[{"2008", ",", "12", ",", "15"}], "}"}], ",", "2.5`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "4"}], "}"}], ",", "23", ",", + RowBox[{"{", + RowBox[{"2009", ",", "3", ",", "16"}], "}"}], ",", "2.6`"}], "}"}], ",", + + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "4"}], "}"}], ",", "23", ",", + RowBox[{"{", + RowBox[{"2009", ",", "6", ",", "15"}], "}"}], ",", "2.78`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "4"}], "}"}], ",", "23", ",", + RowBox[{"{", + RowBox[{"2009", ",", "9", ",", "14"}], "}"}], ",", "2.96`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "4"}], "}"}], ",", "23", ",", + RowBox[{"{", + RowBox[{"2009", ",", "12", ",", "14"}], "}"}], ",", "3.15`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "4"}], "}"}], ",", "23", ",", + RowBox[{"{", + RowBox[{"2010", ",", "3", ",", "15"}], "}"}], ",", "3.32`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "4"}], "}"}], ",", "23", ",", + RowBox[{"{", + RowBox[{"2010", ",", "6", ",", "14"}], "}"}], ",", "3.49`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "4"}], "}"}], ",", "23", ",", + RowBox[{"{", + RowBox[{"2010", ",", "9", ",", "13"}], "}"}], ",", "3.66`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "4"}], "}"}], ",", "23", ",", + RowBox[{"{", + RowBox[{"2010", ",", "12", ",", "13"}], "}"}], ",", "3.81`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "4"}], "}"}], ",", "23", ",", + RowBox[{"{", + RowBox[{"2011", ",", "3", ",", "14"}], "}"}], ",", "3.93`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "4"}], "}"}], ",", "23", ",", + RowBox[{"{", + RowBox[{"2011", ",", "6", ",", "13"}], "}"}], ",", "4.07`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "4"}], "}"}], ",", "23", ",", + RowBox[{"{", + RowBox[{"2011", ",", "9", ",", "19"}], "}"}], ",", "4.2`"}], "}"}], ",", + + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "4"}], "}"}], ",", "23", ",", + RowBox[{"{", + RowBox[{"2011", ",", "12", ",", "19"}], "}"}], ",", "4.32`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "4"}], "}"}], ",", "23", ",", + RowBox[{"{", + RowBox[{"2012", ",", "3", ",", "19"}], "}"}], ",", "4.42`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "4"}], "}"}], ",", "23", ",", + RowBox[{"{", + RowBox[{"2012", ",", "6", ",", "18"}], "}"}], ",", "4.54`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "4"}], "}"}], ",", "23", ",", + RowBox[{"{", + RowBox[{"2012", ",", "9", ",", "17"}], "}"}], ",", "4.66`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "4"}], "}"}], ",", "23", ",", + RowBox[{"{", + RowBox[{"2012", ",", "12", ",", "17"}], "}"}], ",", "4.77`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "4"}], "}"}], ",", "23", ",", + RowBox[{"{", + RowBox[{"2013", ",", "3", ",", "18"}], "}"}], ",", "4.86`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "4"}], "}"}], ",", "23", ",", + RowBox[{"{", + RowBox[{"2013", ",", "6", ",", "17"}], "}"}], ",", "4.95`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "4"}], "}"}], ",", "23", ",", + RowBox[{"{", + RowBox[{"2013", ",", "9", ",", "16"}], "}"}], ",", "5.04`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "4"}], "}"}], ",", "23", ",", + RowBox[{"{", + RowBox[{"2013", ",", "12", ",", "16"}], "}"}], ",", "5.14`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "4"}], "}"}], ",", "23", ",", + RowBox[{"{", + RowBox[{"2014", ",", "3", ",", "17"}], "}"}], ",", "5.21`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "4"}], "}"}], ",", "23", ",", + RowBox[{"{", + RowBox[{"2014", ",", "6", ",", "16"}], "}"}], ",", "5.29`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "4"}], "}"}], ",", "23", ",", + RowBox[{"{", + RowBox[{"2014", ",", "9", ",", "15"}], "}"}], ",", "5.35`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "4"}], "}"}], ",", "23", ",", + RowBox[{"{", + RowBox[{"2014", ",", "12", ",", "15"}], "}"}], ",", "5.43`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "4"}], "}"}], ",", "23", ",", + RowBox[{"{", + RowBox[{"2015", ",", "3", ",", "16"}], "}"}], ",", "5.48`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "4"}], "}"}], ",", "23", ",", + RowBox[{"{", + RowBox[{"2015", ",", "6", ",", "15"}], "}"}], ",", "5.54`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "4"}], "}"}], ",", "23", ",", + RowBox[{"{", + RowBox[{"2015", ",", "9", ",", "14"}], "}"}], ",", "5.59`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "4"}], "}"}], ",", "23", ",", + RowBox[{"{", + RowBox[{"2015", ",", "12", ",", "14"}], "}"}], ",", "5.65`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "4"}], "}"}], ",", "23", ",", + RowBox[{"{", + RowBox[{"2016", ",", "3", ",", "14"}], "}"}], ",", "5.68`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "4"}], "}"}], ",", "23", ",", + RowBox[{"{", + RowBox[{"2016", ",", "6", ",", "13"}], "}"}], ",", "5.72`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "4"}], "}"}], ",", "23", ",", + RowBox[{"{", + RowBox[{"2016", ",", "9", ",", "19"}], "}"}], ",", "5.76`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "4"}], "}"}], ",", "23", ",", + RowBox[{"{", + RowBox[{"2016", ",", "12", ",", "19"}], "}"}], ",", "5.81`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "4"}], "}"}], ",", "23", ",", + RowBox[{"{", + RowBox[{"2017", ",", "3", ",", "13"}], "}"}], ",", "5.83`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "4"}], "}"}], ",", "23", ",", + RowBox[{"{", + RowBox[{"2017", ",", "6", ",", "19"}], "}"}], ",", "5.85`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "4"}], "}"}], ",", "23", ",", + RowBox[{"{", + RowBox[{"2017", ",", "9", ",", "18"}], "}"}], ",", "5.88`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "4"}], "}"}], ",", "23", ",", + RowBox[{"{", + RowBox[{"2017", ",", "12", ",", "18"}], "}"}], ",", "5.92`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "5"}], "}"}], ",", "24", ",", + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "18"}], "}"}], ",", "3.09`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "5"}], "}"}], ",", "24", ",", + RowBox[{"{", + RowBox[{"2008", ",", "3", ",", "17"}], "}"}], ",", "2.92`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "5"}], "}"}], ",", "24", ",", + RowBox[{"{", + RowBox[{"2008", ",", "4", ",", "14"}], "}"}], ",", "2.76`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "5"}], "}"}], ",", "24", ",", + RowBox[{"{", + RowBox[{"2008", ",", "5", ",", "19"}], "}"}], ",", "2.57`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "5"}], "}"}], ",", "24", ",", + RowBox[{"{", + RowBox[{"2008", ",", "6", ",", "16"}], "}"}], ",", "2.44`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "5"}], "}"}], ",", "24", ",", + RowBox[{"{", + RowBox[{"2008", ",", "9", ",", "15"}], "}"}], ",", "2.33`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "5"}], "}"}], ",", "24", ",", + RowBox[{"{", + RowBox[{"2008", ",", "12", ",", "15"}], "}"}], ",", "2.37`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "5"}], "}"}], ",", "24", ",", + RowBox[{"{", + RowBox[{"2009", ",", "3", ",", "16"}], "}"}], ",", "2.49`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "5"}], "}"}], ",", "24", ",", + RowBox[{"{", + RowBox[{"2009", ",", "6", ",", "15"}], "}"}], ",", "2.69`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "5"}], "}"}], ",", "24", ",", + RowBox[{"{", + RowBox[{"2009", ",", "9", ",", "14"}], "}"}], ",", "2.89`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "5"}], "}"}], ",", "24", ",", + RowBox[{"{", + RowBox[{"2009", ",", "12", ",", "14"}], "}"}], ",", "3.08`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "5"}], "}"}], ",", "24", ",", + RowBox[{"{", + RowBox[{"2010", ",", "3", ",", "15"}], "}"}], ",", "3.26`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "5"}], "}"}], ",", "24", ",", + RowBox[{"{", + RowBox[{"2010", ",", "6", ",", "14"}], "}"}], ",", "3.43`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "5"}], "}"}], ",", "24", ",", + RowBox[{"{", + RowBox[{"2010", ",", "9", ",", "13"}], "}"}], ",", "3.6`"}], "}"}], ",", + + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "5"}], "}"}], ",", "24", ",", + RowBox[{"{", + RowBox[{"2010", ",", "12", ",", "13"}], "}"}], ",", "3.75`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "5"}], "}"}], ",", "24", ",", + RowBox[{"{", + RowBox[{"2011", ",", "3", ",", "14"}], "}"}], ",", "3.88`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "5"}], "}"}], ",", "24", ",", + RowBox[{"{", + RowBox[{"2011", ",", "6", ",", "13"}], "}"}], ",", "4.01`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "5"}], "}"}], ",", "24", ",", + RowBox[{"{", + RowBox[{"2011", ",", "9", ",", "19"}], "}"}], ",", "4.14`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "5"}], "}"}], ",", "24", ",", + RowBox[{"{", + RowBox[{"2011", ",", "12", ",", "19"}], "}"}], ",", "4.27`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "5"}], "}"}], ",", "24", ",", + RowBox[{"{", + RowBox[{"2012", ",", "3", ",", "19"}], "}"}], ",", "4.37`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "5"}], "}"}], ",", "24", ",", + RowBox[{"{", + RowBox[{"2012", ",", "6", ",", "18"}], "}"}], ",", "4.49`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "5"}], "}"}], ",", "24", ",", + RowBox[{"{", + RowBox[{"2012", ",", "9", ",", "17"}], "}"}], ",", "4.61`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "5"}], "}"}], ",", "24", ",", + RowBox[{"{", + RowBox[{"2012", ",", "12", ",", "17"}], "}"}], ",", "4.72`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "5"}], "}"}], ",", "24", ",", + RowBox[{"{", + RowBox[{"2013", ",", "3", ",", "18"}], "}"}], ",", "4.81`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "5"}], "}"}], ",", "24", ",", + RowBox[{"{", + RowBox[{"2013", ",", "6", ",", "17"}], "}"}], ",", "4.91`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "5"}], "}"}], ",", "24", ",", + RowBox[{"{", + RowBox[{"2013", ",", "9", ",", "16"}], "}"}], ",", "5.`"}], "}"}], ",", + + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "5"}], "}"}], ",", "24", ",", + RowBox[{"{", + RowBox[{"2013", ",", "12", ",", "16"}], "}"}], ",", "5.09`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "5"}], "}"}], ",", "24", ",", + RowBox[{"{", + RowBox[{"2014", ",", "3", ",", "17"}], "}"}], ",", "5.17`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "5"}], "}"}], ",", "24", ",", + RowBox[{"{", + RowBox[{"2014", ",", "6", ",", "16"}], "}"}], ",", "5.24`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "5"}], "}"}], ",", "24", ",", + RowBox[{"{", + RowBox[{"2014", ",", "9", ",", "15"}], "}"}], ",", "5.31`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "5"}], "}"}], ",", "24", ",", + RowBox[{"{", + RowBox[{"2014", ",", "12", ",", "15"}], "}"}], ",", "5.38`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "5"}], "}"}], ",", "24", ",", + RowBox[{"{", + RowBox[{"2015", ",", "3", ",", "16"}], "}"}], ",", "5.44`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "5"}], "}"}], ",", "24", ",", + RowBox[{"{", + RowBox[{"2015", ",", "6", ",", "15"}], "}"}], ",", "5.5`"}], "}"}], ",", + + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "5"}], "}"}], ",", "24", ",", + RowBox[{"{", + RowBox[{"2015", ",", "9", ",", "14"}], "}"}], ",", "5.55`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "5"}], "}"}], ",", "24", ",", + RowBox[{"{", + RowBox[{"2015", ",", "12", ",", "14"}], "}"}], ",", "5.61`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "5"}], "}"}], ",", "24", ",", + RowBox[{"{", + RowBox[{"2016", ",", "3", ",", "14"}], "}"}], ",", "5.64`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "5"}], "}"}], ",", "24", ",", + RowBox[{"{", + RowBox[{"2016", ",", "6", ",", "13"}], "}"}], ",", "5.68`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "5"}], "}"}], ",", "24", ",", + RowBox[{"{", + RowBox[{"2016", ",", "9", ",", "19"}], "}"}], ",", "5.72`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "5"}], "}"}], ",", "24", ",", + RowBox[{"{", + RowBox[{"2016", ",", "12", ",", "19"}], "}"}], ",", "5.77`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "5"}], "}"}], ",", "24", ",", + RowBox[{"{", + RowBox[{"2017", ",", "3", ",", "13"}], "}"}], ",", "5.79`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "5"}], "}"}], ",", "24", ",", + RowBox[{"{", + RowBox[{"2017", ",", "6", ",", "19"}], "}"}], ",", "5.81`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "5"}], "}"}], ",", "24", ",", + RowBox[{"{", + RowBox[{"2017", ",", "9", ",", "18"}], "}"}], ",", "5.84`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "5"}], "}"}], ",", "24", ",", + RowBox[{"{", + RowBox[{"2017", ",", "12", ",", "18"}], "}"}], ",", "5.88`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "6"}], "}"}], ",", "25", ",", + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "18"}], "}"}], ",", "3.03`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "6"}], "}"}], ",", "25", ",", + RowBox[{"{", + RowBox[{"2008", ",", "3", ",", "17"}], "}"}], ",", "2.88`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "6"}], "}"}], ",", "25", ",", + RowBox[{"{", + RowBox[{"2008", ",", "4", ",", "14"}], "}"}], ",", "2.73`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "6"}], "}"}], ",", "25", ",", + RowBox[{"{", + RowBox[{"2008", ",", "5", ",", "19"}], "}"}], ",", "2.56`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "6"}], "}"}], ",", "25", ",", + RowBox[{"{", + RowBox[{"2008", ",", "6", ",", "16"}], "}"}], ",", "2.44`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "6"}], "}"}], ",", "25", ",", + RowBox[{"{", + RowBox[{"2008", ",", "9", ",", "15"}], "}"}], ",", "2.33`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "6"}], "}"}], ",", "25", ",", + RowBox[{"{", + RowBox[{"2008", ",", "12", ",", "15"}], "}"}], ",", "2.37`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "6"}], "}"}], ",", "25", ",", + RowBox[{"{", + RowBox[{"2009", ",", "3", ",", "16"}], "}"}], ",", "2.5`"}], "}"}], ",", + + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "6"}], "}"}], ",", "25", ",", + RowBox[{"{", + RowBox[{"2009", ",", "6", ",", "15"}], "}"}], ",", "2.7`"}], "}"}], ",", + + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "6"}], "}"}], ",", "25", ",", + RowBox[{"{", + RowBox[{"2009", ",", "9", ",", "14"}], "}"}], ",", "2.9`"}], "}"}], ",", + + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "6"}], "}"}], ",", "25", ",", + RowBox[{"{", + RowBox[{"2009", ",", "12", ",", "14"}], "}"}], ",", "3.09`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "6"}], "}"}], ",", "25", ",", + RowBox[{"{", + RowBox[{"2010", ",", "3", ",", "15"}], "}"}], ",", "3.26`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "6"}], "}"}], ",", "25", ",", + RowBox[{"{", + RowBox[{"2010", ",", "6", ",", "14"}], "}"}], ",", "3.44`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "6"}], "}"}], ",", "25", ",", + RowBox[{"{", + RowBox[{"2010", ",", "9", ",", "13"}], "}"}], ",", "3.61`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "6"}], "}"}], ",", "25", ",", + RowBox[{"{", + RowBox[{"2010", ",", "12", ",", "13"}], "}"}], ",", "3.76`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "6"}], "}"}], ",", "25", ",", + RowBox[{"{", + RowBox[{"2011", ",", "3", ",", "14"}], "}"}], ",", "3.9`"}], "}"}], ",", + + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "6"}], "}"}], ",", "25", ",", + RowBox[{"{", + RowBox[{"2011", ",", "6", ",", "13"}], "}"}], ",", "4.04`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "6"}], "}"}], ",", "25", ",", + RowBox[{"{", + RowBox[{"2011", ",", "9", ",", "19"}], "}"}], ",", "4.17`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "6"}], "}"}], ",", "25", ",", + RowBox[{"{", + RowBox[{"2011", ",", "12", ",", "19"}], "}"}], ",", "4.3`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "6"}], "}"}], ",", "25", ",", + RowBox[{"{", + RowBox[{"2012", ",", "3", ",", "19"}], "}"}], ",", "4.41`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "6"}], "}"}], ",", "25", ",", + RowBox[{"{", + RowBox[{"2012", ",", "6", ",", "18"}], "}"}], ",", "4.53`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "6"}], "}"}], ",", "25", ",", + RowBox[{"{", + RowBox[{"2012", ",", "9", ",", "17"}], "}"}], ",", "4.64`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "6"}], "}"}], ",", "25", ",", + RowBox[{"{", + RowBox[{"2012", ",", "12", ",", "17"}], "}"}], ",", "4.76`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "6"}], "}"}], ",", "25", ",", + RowBox[{"{", + RowBox[{"2013", ",", "3", ",", "18"}], "}"}], ",", "4.85`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "6"}], "}"}], ",", "25", ",", + RowBox[{"{", + RowBox[{"2013", ",", "6", ",", "17"}], "}"}], ",", "4.95`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "6"}], "}"}], ",", "25", ",", + RowBox[{"{", + RowBox[{"2013", ",", "9", ",", "16"}], "}"}], ",", "5.04`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "6"}], "}"}], ",", "25", ",", + RowBox[{"{", + RowBox[{"2013", ",", "12", ",", "16"}], "}"}], ",", "5.13`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "6"}], "}"}], ",", "25", ",", + RowBox[{"{", + RowBox[{"2014", ",", "3", ",", "17"}], "}"}], ",", "5.21`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "6"}], "}"}], ",", "25", ",", + RowBox[{"{", + RowBox[{"2014", ",", "6", ",", "16"}], "}"}], ",", "5.28`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "6"}], "}"}], ",", "25", ",", + RowBox[{"{", + RowBox[{"2014", ",", "9", ",", "15"}], "}"}], ",", "5.35`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "6"}], "}"}], ",", "25", ",", + RowBox[{"{", + RowBox[{"2014", ",", "12", ",", "15"}], "}"}], ",", "5.42`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "6"}], "}"}], ",", "25", ",", + RowBox[{"{", + RowBox[{"2015", ",", "3", ",", "16"}], "}"}], ",", "5.48`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "6"}], "}"}], ",", "25", ",", + RowBox[{"{", + RowBox[{"2015", ",", "6", ",", "15"}], "}"}], ",", "5.54`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "6"}], "}"}], ",", "25", ",", + RowBox[{"{", + RowBox[{"2015", ",", "9", ",", "14"}], "}"}], ",", "5.59`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "6"}], "}"}], ",", "25", ",", + RowBox[{"{", + RowBox[{"2015", ",", "12", ",", "14"}], "}"}], ",", "5.65`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "6"}], "}"}], ",", "25", ",", + RowBox[{"{", + RowBox[{"2016", ",", "3", ",", "14"}], "}"}], ",", "5.69`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "6"}], "}"}], ",", "25", ",", + RowBox[{"{", + RowBox[{"2016", ",", "6", ",", "13"}], "}"}], ",", "5.73`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "6"}], "}"}], ",", "25", ",", + RowBox[{"{", + RowBox[{"2016", ",", "9", ",", "19"}], "}"}], ",", "5.77`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "6"}], "}"}], ",", "25", ",", + RowBox[{"{", + RowBox[{"2016", ",", "12", ",", "19"}], "}"}], ",", "5.82`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "6"}], "}"}], ",", "25", ",", + RowBox[{"{", + RowBox[{"2017", ",", "3", ",", "13"}], "}"}], ",", "5.84`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "6"}], "}"}], ",", "25", ",", + RowBox[{"{", + RowBox[{"2017", ",", "6", ",", "19"}], "}"}], ",", "5.86`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "6"}], "}"}], ",", "25", ",", + RowBox[{"{", + RowBox[{"2017", ",", "9", ",", "18"}], "}"}], ",", "5.88`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "6"}], "}"}], ",", "25", ",", + RowBox[{"{", + RowBox[{"2017", ",", "12", ",", "18"}], "}"}], ",", "5.93`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "7"}], "}"}], ",", "26", ",", + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "18"}], "}"}], ",", "3.02`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "7"}], "}"}], ",", "26", ",", + RowBox[{"{", + RowBox[{"2008", ",", "3", ",", "17"}], "}"}], ",", "2.88`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "7"}], "}"}], ",", "26", ",", + RowBox[{"{", + RowBox[{"2008", ",", "4", ",", "14"}], "}"}], ",", "2.73`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "7"}], "}"}], ",", "26", ",", + RowBox[{"{", + RowBox[{"2008", ",", "5", ",", "19"}], "}"}], ",", "2.56`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "7"}], "}"}], ",", "26", ",", + RowBox[{"{", + RowBox[{"2008", ",", "6", ",", "16"}], "}"}], ",", "2.45`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "7"}], "}"}], ",", "26", ",", + RowBox[{"{", + RowBox[{"2008", ",", "9", ",", "15"}], "}"}], ",", "2.35`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "7"}], "}"}], ",", "26", ",", + RowBox[{"{", + RowBox[{"2008", ",", "12", ",", "15"}], "}"}], ",", "2.4`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "7"}], "}"}], ",", "26", ",", + RowBox[{"{", + RowBox[{"2009", ",", "3", ",", "16"}], "}"}], ",", "2.54`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "7"}], "}"}], ",", "26", ",", + RowBox[{"{", + RowBox[{"2009", ",", "6", ",", "15"}], "}"}], ",", "2.77`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "7"}], "}"}], ",", "26", ",", + RowBox[{"{", + RowBox[{"2009", ",", "9", ",", "14"}], "}"}], ",", "3.`"}], "}"}], ",", + + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "7"}], "}"}], ",", "26", ",", + RowBox[{"{", + RowBox[{"2009", ",", "12", ",", "14"}], "}"}], ",", "3.21`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "7"}], "}"}], ",", "26", ",", + RowBox[{"{", + RowBox[{"2010", ",", "3", ",", "15"}], "}"}], ",", "3.39`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "7"}], "}"}], ",", "26", ",", + RowBox[{"{", + RowBox[{"2010", ",", "6", ",", "14"}], "}"}], ",", "3.58`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "7"}], "}"}], ",", "26", ",", + RowBox[{"{", + RowBox[{"2010", ",", "9", ",", "13"}], "}"}], ",", "3.75`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "7"}], "}"}], ",", "26", ",", + RowBox[{"{", + RowBox[{"2010", ",", "12", ",", "13"}], "}"}], ",", "3.91`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "7"}], "}"}], ",", "26", ",", + RowBox[{"{", + RowBox[{"2011", ",", "3", ",", "14"}], "}"}], ",", "4.05`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "7"}], "}"}], ",", "26", ",", + RowBox[{"{", + RowBox[{"2011", ",", "6", ",", "13"}], "}"}], ",", "4.19`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "7"}], "}"}], ",", "26", ",", + RowBox[{"{", + RowBox[{"2011", ",", "9", ",", "19"}], "}"}], ",", "4.33`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "7"}], "}"}], ",", "26", ",", + RowBox[{"{", + RowBox[{"2011", ",", "12", ",", "19"}], "}"}], ",", "4.46`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "7"}], "}"}], ",", "26", ",", + RowBox[{"{", + RowBox[{"2012", ",", "3", ",", "19"}], "}"}], ",", "4.57`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "7"}], "}"}], ",", "26", ",", + RowBox[{"{", + RowBox[{"2012", ",", "6", ",", "18"}], "}"}], ",", "4.69`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "7"}], "}"}], ",", "26", ",", + RowBox[{"{", + RowBox[{"2012", ",", "9", ",", "17"}], "}"}], ",", "4.81`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "7"}], "}"}], ",", "26", ",", + RowBox[{"{", + RowBox[{"2012", ",", "12", ",", "17"}], "}"}], ",", "4.92`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "7"}], "}"}], ",", "26", ",", + RowBox[{"{", + RowBox[{"2013", ",", "3", ",", "18"}], "}"}], ",", "5.02`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "7"}], "}"}], ",", "26", ",", + RowBox[{"{", + RowBox[{"2013", ",", "6", ",", "17"}], "}"}], ",", "5.11`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "7"}], "}"}], ",", "26", ",", + RowBox[{"{", + RowBox[{"2013", ",", "9", ",", "16"}], "}"}], ",", "5.2`"}], "}"}], ",", + + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "7"}], "}"}], ",", "26", ",", + RowBox[{"{", + RowBox[{"2013", ",", "12", ",", "16"}], "}"}], ",", "5.3`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "7"}], "}"}], ",", "26", ",", + RowBox[{"{", + RowBox[{"2014", ",", "3", ",", "17"}], "}"}], ",", "5.37`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "7"}], "}"}], ",", "26", ",", + RowBox[{"{", + RowBox[{"2014", ",", "6", ",", "16"}], "}"}], ",", "5.45`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "7"}], "}"}], ",", "26", ",", + RowBox[{"{", + RowBox[{"2014", ",", "9", ",", "15"}], "}"}], ",", "5.51`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "7"}], "}"}], ",", "26", ",", + RowBox[{"{", + RowBox[{"2014", ",", "12", ",", "15"}], "}"}], ",", "5.59`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "7"}], "}"}], ",", "26", ",", + RowBox[{"{", + RowBox[{"2015", ",", "3", ",", "16"}], "}"}], ",", "5.65`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "7"}], "}"}], ",", "26", ",", + RowBox[{"{", + RowBox[{"2015", ",", "6", ",", "15"}], "}"}], ",", "5.7`"}], "}"}], ",", + + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "7"}], "}"}], ",", "26", ",", + RowBox[{"{", + RowBox[{"2015", ",", "9", ",", "14"}], "}"}], ",", "5.75`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "7"}], "}"}], ",", "26", ",", + RowBox[{"{", + RowBox[{"2015", ",", "12", ",", "14"}], "}"}], ",", "5.81`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "7"}], "}"}], ",", "26", ",", + RowBox[{"{", + RowBox[{"2016", ",", "3", ",", "14"}], "}"}], ",", "5.85`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "7"}], "}"}], ",", "26", ",", + RowBox[{"{", + RowBox[{"2016", ",", "6", ",", "13"}], "}"}], ",", "5.89`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "7"}], "}"}], ",", "26", ",", + RowBox[{"{", + RowBox[{"2016", ",", "9", ",", "19"}], "}"}], ",", "5.93`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "7"}], "}"}], ",", "26", ",", + RowBox[{"{", + RowBox[{"2016", ",", "12", ",", "19"}], "}"}], ",", "5.98`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "7"}], "}"}], ",", "26", ",", + RowBox[{"{", + RowBox[{"2017", ",", "3", ",", "13"}], "}"}], ",", "6.`"}], "}"}], ",", + + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "7"}], "}"}], ",", "26", ",", + RowBox[{"{", + RowBox[{"2017", ",", "6", ",", "19"}], "}"}], ",", "6.02`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "7"}], "}"}], ",", "26", ",", + RowBox[{"{", + RowBox[{"2017", ",", "9", ",", "18"}], "}"}], ",", "6.05`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "7"}], "}"}], ",", "26", ",", + RowBox[{"{", + RowBox[{"2017", ",", "12", ",", "18"}], "}"}], ",", "6.09`"}], "}"}]}], + "}"}]], "Output", + CellChangeTimes->{3.411484060963668*^9}] +}, Closed]], + +Cell[BoxData[ + RowBox[{ + RowBox[{"tempdata1", "=", + RowBox[{"Join", "[", + RowBox[{"cmedata", ",", "%"}], "]"}]}], ";"}]], "Input", + CellChangeTimes->{{3.411483743231241*^9, 3.411483761137896*^9}, + 3.4114840826009855`*^9}], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{"tempdata1", "\[Equal]", + RowBox[{"Union", "[", "tempdata1", "]"}]}]], "Input", + CellChangeTimes->{{3.4114837629051027`*^9, 3.411483771616026*^9}}], + +Cell[BoxData["True"], "Output", + CellChangeTimes->{3.411483772194669*^9, 3.4114840853838196`*^9}] +}, Open ]] +}, Open ]], + +Cell[CellGroupData[{ + +Cell["Extract data for use", "Section", + CellChangeTimes->{{3.4114841709523654`*^9, 3.4114841766081085`*^9}}], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{"CurrentDate", "=", + RowBox[{"cmedata", "[", + RowBox[{"[", + RowBox[{ + RowBox[{"-", "1"}], ",", "1"}], "]"}], "]"}]}]], "Input", + CellChangeTimes->{{3.4114844976160727`*^9, 3.4114845084875927`*^9}, { + 3.411484719576273*^9, 3.4114847234812727`*^9}}], + +Cell[BoxData[ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "7"}], "}"}]], "Output", + CellChangeTimes->{ + 3.411484508878093*^9, {3.411484720216693*^9, 3.4114847238405333`*^9}}] +}, Open ]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{"LastFOMCDate", "=", + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "31"}], "}"}]}]], "Input", + CellChangeTimes->{{3.411484306283989*^9, 3.4114843312348776`*^9}}], + +Cell[BoxData[ + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "31"}], "}"}]], "Output", + CellChangeTimes->{3.41148433215667*^9}] +}, Open ]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{"legend", "=", + RowBox[{"ColorLegendGrid", "[", + RowBox[{ + RowBox[{"Date2String", "/@", + RowBox[{"{", + RowBox[{"CurrentDate", ",", "LastFOMCDate"}], "}"}]}], ",", + RowBox[{"Table", "[", + RowBox[{ + RowBox[{ + RowBox[{"ColorData", "[", "1", "]"}], "[", "i", "]"}], ",", + RowBox[{"{", + RowBox[{"i", ",", "2"}], "}"}]}], "]"}]}], "]"}]}]], "Input", + CellChangeTimes->{{3.411484467078973*^9, 3.411484488697053*^9}, { + 3.4114845243106527`*^9, 3.4114845687495527`*^9}}], + +Cell[BoxData[ + TagBox[GridBox[{ + { + GraphicsBox[ + {RGBColor[0.24720000000000014`, 0.24, 0.6], + StyleBox[InsetBox["\<\"\[FilledSquare]\"\>", {0, 0}], + StripOnInput->False, + FontSize->12]}, + ImageSize->12], + StyleBox[ + InterpretationBox[Cell[BoxData["\<\"2008-02-07\"\>"], "Text", "TR"], + Text["2008-02-07"]], + StripOnInput->False, + FontSize->12]}, + { + GraphicsBox[ + {RGBColor[0.6, 0.24, 0.4428931686004542], + StyleBox[InsetBox["\<\"\[FilledSquare]\"\>", {0, 0}], + StripOnInput->False, + FontSize->12]}, + ImageSize->12], + StyleBox[ + InterpretationBox[Cell[BoxData["\<\"2008-01-31\"\>"], "Text", "TR"], + Text["2008-01-31"]], + StripOnInput->False, + FontSize->12]} + }, + ColumnsEqual->False, + GridBoxAlignment->{"Columns" -> {{Left}}}, + GridBoxFrame->{"ColumnsIndexed" -> {{{1, -1}, {1, -1}} -> True}}, + GridBoxItemSize->{"Columns" -> {{Automatic}}, "Rows" -> {{Automatic}}}, + RowsEqual->False], + "Grid"]], "Output", + CellChangeTimes->{{3.4114845399150333`*^9, 3.4114845692650127`*^9}}] +}, Open ]], + +Cell[BoxData[ + RowBox[{ + RowBox[{"CurrentData", "=", + RowBox[{"Cases", "[", + RowBox[{"cmedata", ",", + RowBox[{ + RowBox[{"{", + RowBox[{ + RowBox[{"d", ":", "CurrentDate"}], ",", "_", ",", "m_", ",", "r_"}], + "}"}], "\[RuleDelayed]", + RowBox[{"{", + RowBox[{"d", ",", "m", ",", "r"}], "}"}]}]}], "]"}]}], ";"}]], "Input",\ + + CellChangeTimes->{{3.4114841897319326`*^9, 3.411484277911531*^9}, + 3.411484456379273*^9, {3.411484514610633*^9, 3.411484516969253*^9}, { + 3.411484731478713*^9, 3.411484734087253*^9}}], + +Cell[BoxData[ + RowBox[{ + RowBox[{"LastFOMCData", "=", + RowBox[{"Cases", "[", + RowBox[{"cmedata", ",", + RowBox[{ + RowBox[{"{", + RowBox[{ + RowBox[{"d", ":", "LastFOMCDate"}], ",", "_", ",", "m_", ",", "r_"}], + "}"}], "\[RuleDelayed]", + RowBox[{"{", + RowBox[{"d", ",", "m", ",", "r"}], "}"}]}]}], "]"}]}], ";"}]], "Input",\ + + CellChangeTimes->{{3.411484262850381*^9, 3.411484303534235*^9}, + 3.411484445865231*^9, {3.411484736399013*^9, 3.411484739116893*^9}}], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{"DateListPlot", "[", + RowBox[{ + RowBox[{"{", + RowBox[{ + RowBox[{"CurrentData", "[", + RowBox[{"[", + RowBox[{"All", ",", + RowBox[{"{", + RowBox[{"2", ",", "3"}], "}"}]}], "]"}], "]"}], ",", + RowBox[{"LastFOMCData", "[", + RowBox[{"[", + RowBox[{"All", ",", + RowBox[{"{", + RowBox[{"2", ",", "3"}], "}"}]}], "]"}], "]"}]}], "}"}], ",", + RowBox[{"Joined", "\[Rule]", "True"}], ",", + RowBox[{"Frame", "\[Rule]", + RowBox[{"{", + RowBox[{"True", ",", "True", ",", "False", ",", "False"}], "}"}]}], ",", + + RowBox[{"Epilog", "\[Rule]", + RowBox[{"Inset", "[", + RowBox[{"legend", ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2016", ",", "1", ",", "1"}], "}"}], ",", "4"}], "}"}], ",", + + RowBox[{"Background", "\[Rule]", "White"}]}], "]"}]}], ",", + RowBox[{"PlotLabel", "\[Rule]", "\"\<Eurodollar Futures Rates\>\""}]}], + "]"}]], "Input", + CellChangeTimes->{{3.4114843460929213`*^9, 3.411484381417881*^9}, { + 3.4114844214455442`*^9, 3.411484430038524*^9}, {3.4114845727326527`*^9, + 3.411484649161313*^9}, {3.411484743381153*^9, 3.411484750269573*^9}}], + +Cell[BoxData[ + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.4122816*^9, 3.02}, {3.4147008*^9, 2.88}, {3.41712*^9, 2.73}, { + 3.420144*^9, 2.56}, {3.4225632*^9, 2.45}, {3.4304256*^9, 2.35}, { + 3.438288*^9, 2.4}, {3.4461504*^9, 2.54}, {3.4540128*^9, 2.77}, { + 3.4618752*^9, 3.}, {3.4697376*^9, 3.21}, {3.4776*^9, 3.39}, { + 3.4854624*^9, 3.58}, {3.4933248*^9, 3.75}, {3.5011872*^9, 3.91}, { + 3.5090496*^9, 4.05}, {3.516912*^9, 4.19}, {3.5253792*^9, 4.33}, { + 3.5332416*^9, 4.46}, {3.541104*^9, 4.57}, {3.5489664*^9, 4.69}, { + 3.5568288*^9, 4.81}, {3.5646912*^9, 4.92}, {3.5725536*^9, 5.02}, { + 3.580416*^9, 5.11}, {3.5882784*^9, 5.2}, {3.5961408*^9, 5.3}, { + 3.6040032*^9, 5.37}, {3.6118656*^9, 5.45}, {3.619728*^9, 5.51}, { + 3.6275904*^9, 5.59}, {3.6354528*^9, 5.65}, {3.6433152*^9, 5.7}, { + 3.6511776*^9, 5.75}, {3.65904*^9, 5.81}, {3.6669024*^9, 5.85}, { + 3.6747648*^9, 5.89}, {3.683232*^9, 5.93}, {3.6910944*^9, 5.98}, { + 3.698352*^9, 6.}, {3.7068192*^9, 6.02}, {3.7146816*^9, 6.05}, { + 3.722544*^9, 6.09}}]}, + {Hue[0.9060679774997897, 0.6, 0.6], + LineBox[{{3.4122816*^9, 3.03}, {3.4147008*^9, 2.9}, {3.41712*^9, 2.76}, { + 3.420144*^9, 2.6}, {3.4225632*^9, 2.49}, {3.4304256*^9, 2.44}, { + 3.438288*^9, 2.56}, {3.4461504*^9, 2.73}, {3.4540128*^9, 2.93}, { + 3.4618752*^9, 3.1}, {3.4697376*^9, 3.26}, {3.4776*^9, 3.41}, { + 3.4854624*^9, 3.57}, {3.4933248*^9, 3.71}, {3.5011872*^9, 3.84}, { + 3.5090496*^9, 3.95}, {3.516912*^9, 4.07}, {3.5253792*^9, 4.2}, { + 3.5332416*^9, 4.32}, {3.541104*^9, 4.41}, {3.5489664*^9, 4.51}, { + 3.5568288*^9, 4.62}, {3.5646912*^9, 4.72}, {3.5725536*^9, 4.8}, { + 3.580416*^9, 4.9}, {3.5882784*^9, 4.99}, {3.5961408*^9, 5.08}, { + 3.6040032*^9, 5.15}, {3.6118656*^9, 5.23}, {3.619728*^9, 5.29}, { + 3.6275904*^9, 5.37}, {3.6354528*^9, 5.42}, {3.6433152*^9, 5.47}, { + 3.6511776*^9, 5.52}, {3.65904*^9, 5.58}, {3.6669024*^9, 5.61}, { + 3.6747648*^9, 5.65}, {3.683232*^9, 5.69}, {3.6910944*^9, 5.74}, { + 3.698352*^9, 5.76}, {3.7068192*^9, 5.78}, {3.7146816*^9, 5.81}, { + 3.722544*^9, 5.85}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3412281600, 2.5}, {3.4122816*^9, 2.5}], + Epilog->InsetBox[ + BoxData[ + FormBox[ + TagBox[ + GridBox[{{ + GraphicsBox[{ + RGBColor[0.24720000000000014`, 0.24, 0.6], + StyleBox[ + InsetBox[ + FormBox["\"\[FilledSquare]\"", TraditionalForm], {0, 0}], 12, + StripOnInput -> False]}, ImageSize -> 12], + StyleBox[ + InterpretationBox[ + Cell[ + BoxData[ + FormBox["\"2008-02-07\"", TraditionalForm]], "Text", "TR"], + Text["2008-02-07"]], 12, StripOnInput -> False]}, { + GraphicsBox[{ + RGBColor[0.6, 0.24, 0.4428931686004542], + StyleBox[ + InsetBox[ + FormBox["\"\[FilledSquare]\"", TraditionalForm], {0, 0}], 12, + StripOnInput -> False]}, ImageSize -> 12], + StyleBox[ + InterpretationBox[ + Cell[ + BoxData[ + FormBox["\"2008-01-31\"", TraditionalForm]], "Text", "TR"], + Text["2008-01-31"]], 12, StripOnInput -> False]}}, + GridBoxAlignment -> {"Columns" -> {{Left}}}, + GridBoxFrame -> {"ColumnsIndexed" -> {{{1, -1}, {1, -1}} -> True}}, + GridBoxItemSize -> { + "Columns" -> {{Automatic}}, "Rows" -> {{Automatic}}}, ColumnsEqual -> + False, RowsEqual -> False], "Grid"], TraditionalForm]], + NCache[{3660595200, 4}, {3.6605952*^9, 4}], Background -> GrayLevel[1]], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotLabel->FormBox["\"Eurodollar Futures Rates\"", TraditionalForm], + PlotRange->{{3.4122816*^9, 3.722544*^9}, {2.35, 6.09}}, + PlotRangeClipping->True, + PlotRangePadding->{ + Scaled[0.02], + Scaled[0.02]}, + Ticks->None]], "Output", + CellChangeTimes->{{3.41148435676384*^9, 3.4114843819022126`*^9}, + 3.4114844305228558`*^9, {3.411484615859473*^9, 3.411484649676773*^9}, + 3.411484750785033*^9}] +}, Open ]], + +Cell[BoxData[ + RowBox[{"PagePrint", "[", "%348", "]"}]], "Input", + CellChangeTimes->{{3.411484658345873*^9, 3.411484687430313*^9}}], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{"CommonContracts", "=", + RowBox[{"Intersection", "[", + RowBox[{ + RowBox[{"CurrentData", "[", + RowBox[{"[", + RowBox[{"All", ",", "2"}], "]"}], "]"}], ",", + RowBox[{"LastFOMCData", "[", + RowBox[{"[", + RowBox[{"All", ",", "2"}], "]"}], "]"}]}], "]"}]}]], "Input", + CellChangeTimes->{{3.411484709485753*^9, 3.411484715218293*^9}, { + 3.4114847647014494`*^9, 3.411484794392408*^9}}], + +Cell[BoxData[ + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "18"}], "}"}], ",", + RowBox[{"{", + RowBox[{"2008", ",", "3", ",", "17"}], "}"}], ",", + RowBox[{"{", + RowBox[{"2008", ",", "4", ",", "14"}], "}"}], ",", + RowBox[{"{", + RowBox[{"2008", ",", "5", ",", "19"}], "}"}], ",", + RowBox[{"{", + RowBox[{"2008", ",", "6", ",", "16"}], "}"}], ",", + RowBox[{"{", + RowBox[{"2008", ",", "9", ",", "15"}], "}"}], ",", + RowBox[{"{", + RowBox[{"2008", ",", "12", ",", "15"}], "}"}], ",", + RowBox[{"{", + RowBox[{"2009", ",", "3", ",", "16"}], "}"}], ",", + RowBox[{"{", + RowBox[{"2009", ",", "6", ",", "15"}], "}"}], ",", + RowBox[{"{", + RowBox[{"2009", ",", "9", ",", "14"}], "}"}], ",", + RowBox[{"{", + RowBox[{"2009", ",", "12", ",", "14"}], "}"}], ",", + RowBox[{"{", + RowBox[{"2010", ",", "3", ",", "15"}], "}"}], ",", + RowBox[{"{", + RowBox[{"2010", ",", "6", ",", "14"}], "}"}], ",", + RowBox[{"{", + RowBox[{"2010", ",", "9", ",", "13"}], "}"}], ",", + RowBox[{"{", + RowBox[{"2010", ",", "12", ",", "13"}], "}"}], ",", + RowBox[{"{", + RowBox[{"2011", ",", "3", ",", "14"}], "}"}], ",", + RowBox[{"{", + RowBox[{"2011", ",", "6", ",", "13"}], "}"}], ",", + RowBox[{"{", + RowBox[{"2011", ",", "9", ",", "19"}], "}"}], ",", + RowBox[{"{", + RowBox[{"2011", ",", "12", ",", "19"}], "}"}], ",", + RowBox[{"{", + RowBox[{"2012", ",", "3", ",", "19"}], "}"}], ",", + RowBox[{"{", + RowBox[{"2012", ",", "6", ",", "18"}], "}"}], ",", + RowBox[{"{", + RowBox[{"2012", ",", "9", ",", "17"}], "}"}], ",", + RowBox[{"{", + RowBox[{"2012", ",", "12", ",", "17"}], "}"}], ",", + RowBox[{"{", + RowBox[{"2013", ",", "3", ",", "18"}], "}"}], ",", + RowBox[{"{", + RowBox[{"2013", ",", "6", ",", "17"}], "}"}], ",", + RowBox[{"{", + RowBox[{"2013", ",", "9", ",", "16"}], "}"}], ",", + RowBox[{"{", + RowBox[{"2013", ",", "12", ",", "16"}], "}"}], ",", + RowBox[{"{", + RowBox[{"2014", ",", "3", ",", "17"}], "}"}], ",", + RowBox[{"{", + RowBox[{"2014", ",", "6", ",", "16"}], "}"}], ",", + RowBox[{"{", + RowBox[{"2014", ",", "9", ",", "15"}], "}"}], ",", + RowBox[{"{", + RowBox[{"2014", ",", "12", ",", "15"}], "}"}], ",", + RowBox[{"{", + RowBox[{"2015", ",", "3", ",", "16"}], "}"}], ",", + RowBox[{"{", + RowBox[{"2015", ",", "6", ",", "15"}], "}"}], ",", + RowBox[{"{", + RowBox[{"2015", ",", "9", ",", "14"}], "}"}], ",", + RowBox[{"{", + RowBox[{"2015", ",", "12", ",", "14"}], "}"}], ",", + RowBox[{"{", + RowBox[{"2016", ",", "3", ",", "14"}], "}"}], ",", + RowBox[{"{", + RowBox[{"2016", ",", "6", ",", "13"}], "}"}], ",", + RowBox[{"{", + RowBox[{"2016", ",", "9", ",", "19"}], "}"}], ",", + RowBox[{"{", + RowBox[{"2016", ",", "12", ",", "19"}], "}"}], ",", + RowBox[{"{", + RowBox[{"2017", ",", "3", ",", "13"}], "}"}], ",", + RowBox[{"{", + RowBox[{"2017", ",", "6", ",", "19"}], "}"}], ",", + RowBox[{"{", + RowBox[{"2017", ",", "9", ",", "18"}], "}"}], ",", + RowBox[{"{", + RowBox[{"2017", ",", "12", ",", "18"}], "}"}]}], "}"}]], "Output", + CellChangeTimes->{{3.411484713312653*^9, 3.4114847156087933`*^9}, { + 3.4114847549710617`*^9, 3.41148479492344*^9}}] +}, Open ]], + +Cell[BoxData[ + RowBox[{ + RowBox[{"DifferenceData", "=", + RowBox[{"Transpose", "[", + RowBox[{"{", + RowBox[{"CommonContracts", ",", + RowBox[{ + RowBox[{ + RowBox[{"Cases", "[", + RowBox[{"CurrentData", ",", + RowBox[{"{", + RowBox[{"_", ",", + RowBox[{"Alternatives", "@@", "CommonContracts"}], ",", "_"}], + "}"}]}], "]"}], "[", + RowBox[{"[", + RowBox[{"All", ",", "3"}], "]"}], "]"}], "-", + RowBox[{ + RowBox[{"Cases", "[", + RowBox[{"LastFOMCData", ",", + RowBox[{"{", + RowBox[{"_", ",", + RowBox[{"Alternatives", "@@", "CommonContracts"}], ",", "_"}], + "}"}]}], "]"}], "[", + RowBox[{"[", + RowBox[{"All", ",", "3"}], "]"}], "]"}]}]}], "}"}], "]"}]}], + ";"}]], "Input", + CellChangeTimes->{{3.411484799140462*^9, 3.4114849196595335`*^9}}], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{"DateListPlot", "[", + RowBox[{"DifferenceData", ",", + RowBox[{"Joined", "\[Rule]", "True"}], ",", + RowBox[{"Frame", "\[Rule]", + RowBox[{"{", + RowBox[{"True", ",", "True", ",", "False", ",", "False"}], "}"}]}], ",", + + RowBox[{"GridLines", "\[Rule]", + RowBox[{"{", + RowBox[{"Automatic", ",", + RowBox[{"Range", "[", + RowBox[{ + RowBox[{"-", ".25"}], ",", ".25", ",", ".25"}], "]"}]}], "}"}]}], ",", + + RowBox[{"PlotRange", "\[Rule]", + RowBox[{"{", + RowBox[{"Automatic", ",", + RowBox[{"{", + RowBox[{ + RowBox[{"-", ".25"}], ",", ".25"}], "}"}]}], "}"}]}], ",", + RowBox[{"PlotRangePadding", "\[Rule]", + RowBox[{"{", + RowBox[{ + RowBox[{"Scaled", "[", ".01", "]"}], ",", + RowBox[{"Scaled", "[", ".05", "]"}]}], "}"}]}], ",", + RowBox[{ + "PlotLabel", "\[Rule]", + "\"\<Change in Eurodollar Futures Rates Since Last FOMC\>\""}]}], + "]"}]], "Input", + CellChangeTimes->{{3.4114848926160593`*^9, 3.4114850629930954`*^9}}], + +Cell[BoxData[ + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.4122816*^9, -0.009999999999999787}, { + 3.4147008*^9, -0.020000000000000018`}, { + 3.41712*^9, -0.029999999999999805`}, { + 3.420144*^9, -0.040000000000000036`}, { + 3.4225632*^9, -0.040000000000000036`}, { + 3.4304256*^9, -0.08999999999999986}, { + 3.438288*^9, -0.16000000000000014`}, { + 3.4461504*^9, -0.18999999999999995`}, { + 3.4540128*^9, -0.16000000000000014`}, { + 3.4618752*^9, -0.10000000000000009`}, { + 3.4697376*^9, -0.04999999999999982}, { + 3.4776*^9, -0.020000000000000018`}, {3.4854624*^9, + 0.010000000000000231`}, {3.4933248*^9, 0.040000000000000036`}, { + 3.5011872*^9, 0.07000000000000028}, {3.5090496*^9, + 0.09999999999999964}, {3.516912*^9, 0.1200000000000001}, {3.5253792*^9, + 0.1299999999999999}, {3.5332416*^9, 0.13999999999999968`}, {3.541104*^9, + 0.16000000000000014`}, {3.5489664*^9, 0.1800000000000006}, {3.5568288*^9, + 0.1899999999999995}, {3.5646912*^9, 0.20000000000000018`}, { + 3.5725536*^9, 0.21999999999999975`}, {3.580416*^9, + 0.20999999999999996`}, {3.5882784*^9, 0.20999999999999996`}, { + 3.5961408*^9, 0.21999999999999975`}, {3.6040032*^9, + 0.21999999999999975`}, {3.6118656*^9, 0.21999999999999975`}, { + 3.619728*^9, 0.21999999999999975`}, {3.6275904*^9, + 0.21999999999999975`}, {3.6354528*^9, 0.23000000000000043`}, { + 3.6433152*^9, 0.23000000000000043`}, {3.6511776*^9, + 0.23000000000000043`}, {3.65904*^9, 0.22999999999999954`}, {3.6669024*^9, + 0.23999999999999932`}, {3.6747648*^9, 0.23999999999999932`}, { + 3.683232*^9, 0.23999999999999932`}, {3.6910944*^9, 0.2400000000000002}, { + 3.698352*^9, 0.2400000000000002}, {3.7068192*^9, 0.23999999999999932`}, { + 3.7146816*^9, 0.2400000000000002}, {3.722544*^9, 0.2400000000000002}}]}}, + + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3412281600, 0}, {3.4122816*^9, 0}], + Frame->{True, True, False, False}, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, {-0.25, 0., 0.25}}, {{{3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, {-0.25, 0., 0.25}}], + PlotLabel->FormBox[ + "\"Change in Eurodollar Futures Rates Since Last FOMC\"", TraditionalForm], + + PlotRange->{{3.4122816*^9, 3.722544*^9}, {-0.25, 0.25}}, + PlotRangeClipping->True, + PlotRangePadding->{ + Scaled[0.01], + Scaled[0.05]}, + Ticks->None]], "Output", + CellChangeTimes->{{3.4114849844157295`*^9, 3.4114850183776674`*^9}, { + 3.411485055790958*^9, 3.4114850635446815`*^9}}] +}, Open ]], + +Cell[BoxData[ + RowBox[{"PagePrint", "[", "%", "]"}]], "Input", + CellChangeTimes->{{3.411485068824147*^9, 3.4114850705892224`*^9}}] +}, Open ]] +}, Open ]] +}, +WindowSize->{890, 843}, +WindowMargins->{{Automatic, -1272}, {Automatic, -32}}, +ShowSelection->True, +FrontEndVersion->"6.0 for Microsoft Windows (32-bit) (June 19, 2007)", +StyleDefinitions->"Default.nb" +] +(* End of Notebook Content *) + +(* Internal cache information *) +(*CellTagsOutline +CellTagsIndex->{} +*) +(*CellTagsIndex +CellTagsIndex->{} +*) +(*NotebookFileOutline +Notebook[{ +Cell[CellGroupData[{ +Cell[590, 23, 100, 1, 103, "Title"], +Cell[693, 26, 116, 1, 62, "Subtitle"], +Cell[CellGroupData[{ +Cell[834, 31, 92, 1, 88, "Section"], +Cell[929, 34, 68, 1, 35, "Input"], +Cell[1000, 37, 120, 2, 52, "Input"], +Cell[CellGroupData[{ +Cell[1145, 43, 273, 6, 52, "Input"], +Cell[1421, 51, 141, 1, 52, "Output"] +}, Open ]], +Cell[CellGroupData[{ +Cell[1599, 57, 169, 3, 52, "Input"], +Cell[1771, 62, 119, 1, 52, "Output"] +}, Open ]], +Cell[CellGroupData[{ +Cell[1927, 68, 234, 4, 52, "Input"], +Cell[2164, 74, 131, 1, 52, "Output"] +}, Open ]], +Cell[2310, 78, 176, 6, 35, "Input", + Evaluatable->False] +}, Open ]], +Cell[CellGroupData[{ +Cell[2523, 89, 102, 1, 88, "Section"], +Cell[CellGroupData[{ +Cell[2650, 94, 590, 14, 97, "Input"], +Cell[3243, 110, 230, 4, 52, "Output"] +}, Open ]], +Cell[CellGroupData[{ +Cell[3510, 119, 298, 7, 52, "Input"], +Cell[3811, 128, 525, 8, 52, "Output"] +}, Open ]], +Cell[4351, 139, 359, 11, 52, "Input"], +Cell[CellGroupData[{ +Cell[4735, 154, 167, 3, 52, "Input"], +Cell[4905, 159, 2473, 72, 116, "Output"] +}, Open ]], +Cell[CellGroupData[{ +Cell[7415, 236, 188, 3, 52, "Input"], +Cell[7606, 241, 2427, 61, 230, "Output"] +}, Open ]], +Cell[CellGroupData[{ +Cell[10070, 307, 188, 3, 52, "Input"], +Cell[10261, 312, 591, 10, 52, "Output"] +}, Open ]], +Cell[CellGroupData[{ +Cell[10889, 327, 196, 3, 52, "Input"], +Cell[11088, 332, 278, 4, 52, "Output"] +}, Open ]], +Cell[CellGroupData[{ +Cell[11403, 341, 2489, 67, 207, "Input"], +Cell[13895, 410, 870605, 14838, 430, "Output"] +}, Open ]] +}, Open ]], +Cell[CellGroupData[{ +Cell[884549, 15254, 99, 1, 88, "Section"], +Cell[CellGroupData[{ +Cell[884673, 15259, 419, 10, 75, "Input"], +Cell[885095, 15271, 164, 2, 52, "Output"] +}, Open ]] +}, Open ]], +Cell[CellGroupData[{ +Cell[885308, 15279, 165, 2, 88, "Section"], +Cell[CellGroupData[{ +Cell[885498, 15285, 188, 3, 52, "Input"], +Cell[885689, 15290, 591, 10, 52, "Output"] +}, Open ]], +Cell[CellGroupData[{ +Cell[886317, 15305, 126, 2, 52, "Input"], +Cell[886446, 15309, 95, 1, 52, "Output"] +}, Open ]], +Cell[CellGroupData[{ +Cell[886578, 15315, 526, 13, 52, "Input"], +Cell[887107, 15330, 295, 7, 52, "Output"] +}, Open ]], +Cell[CellGroupData[{ +Cell[887439, 15342, 1691, 38, 102, "Input"], +Cell[889133, 15382, 530, 9, 94, "Message"], +Cell[889666, 15393, 429, 7, 27, "Message"] +}, Open ]], +Cell[890110, 15403, 1076, 30, 119, "Input"], +Cell[CellGroupData[{ +Cell[891211, 15437, 443, 11, 52, "Input"], +Cell[891657, 15450, 1134, 21, 229, "Output"] +}, Open ]] +}, Open ]], +Cell[CellGroupData[{ +Cell[892840, 15477, 110, 1, 88, "Section"], +Cell[892953, 15480, 532, 16, 75, "Input"], +Cell[CellGroupData[{ +Cell[893510, 15500, 459, 13, 52, "Input"], +Cell[893972, 15515, 803, 25, 75, "Output"] +}, Open ]], +Cell[CellGroupData[{ +Cell[894812, 15545, 255, 6, 52, "Input"], +Cell[895070, 15553, 918, 14, 251, "Output"] +}, Open ]], +Cell[CellGroupData[{ +Cell[896025, 15572, 535, 12, 97, "Input"], +Cell[896563, 15586, 387, 8, 27, "Message"], +Cell[896953, 15596, 400, 8, 27, "Message"], +Cell[897356, 15606, 398, 8, 27, "Message"], +Cell[897757, 15616, 459, 9, 27, "Message"], +Cell[898219, 15627, 437, 9, 27, "Message"], +Cell[898659, 15638, 546, 11, 27, "Message"], +Cell[899208, 15651, 485, 9, 27, "Message"], +Cell[899696, 15662, 602, 11, 50, "Message"], +Cell[900301, 15675, 595, 12, 50, "Message"], +Cell[900899, 15689, 640, 12, 50, "Message"], +Cell[901542, 15703, 435, 9, 27, "Message"], +Cell[901980, 15714, 546, 11, 27, "Message"], +Cell[902529, 15727, 483, 9, 27, "Message"], +Cell[903015, 15738, 600, 11, 50, "Message"], +Cell[903618, 15751, 595, 12, 50, "Message"], +Cell[904216, 15765, 77879, 2453, 3947, "Output"] +}, Closed]], +Cell[CellGroupData[{ +Cell[982132, 18223, 265, 8, 44, "Input"], +Cell[982400, 18233, 76328, 2411, 3815, "Output"] +}, Closed]], +Cell[1058743, 20647, 232, 6, 44, "Input"], +Cell[CellGroupData[{ +Cell[1059000, 20657, 172, 3, 52, "Input"], +Cell[1059175, 20662, 97, 1, 52, "Output"] +}, Open ]] +}, Open ]], +Cell[CellGroupData[{ +Cell[1059321, 20669, 109, 1, 88, "Section"], +Cell[CellGroupData[{ +Cell[1059455, 20674, 284, 7, 52, "Input"], +Cell[1059742, 20683, 179, 4, 52, "Output"] +}, Open ]], +Cell[CellGroupData[{ +Cell[1059958, 20692, 189, 4, 52, "Input"], +Cell[1060150, 20698, 128, 3, 52, "Output"] +}, Open ]], +Cell[CellGroupData[{ +Cell[1060315, 20706, 537, 14, 75, "Input"], +Cell[1060855, 20722, 1120, 33, 84, "Output"] +}, Open ]], +Cell[1061990, 20758, 561, 15, 52, "Input"], +Cell[1062554, 20775, 511, 14, 52, "Input"], +Cell[CellGroupData[{ +Cell[1063090, 20793, 1221, 33, 119, "Input"], +Cell[1064314, 20828, 6642, 139, 340, "Output"] +}, Open ]], +Cell[1070971, 20970, 131, 2, 52, "Input"], +Cell[CellGroupData[{ +Cell[1071127, 20976, 434, 11, 52, "Input"], +Cell[1071564, 20989, 3320, 90, 229, "Output"] +}, Open ]], +Cell[1074899, 21082, 913, 26, 141, "Input"], +Cell[CellGroupData[{ +Cell[1075837, 21112, 1048, 30, 119, "Input"], +Cell[1076888, 21144, 4685, 99, 331, "Output"] +}, Open ]], +Cell[1081588, 21246, 130, 2, 52, "Input"] +}, Open ]] +}, Open ]] +} +] +*) + +(* End of internal cache information *) diff --git a/MathematicaFiles/Applications/EurodollarDataFunctions.m b/MathematicaFiles/Applications/EurodollarDataFunctions.m new file mode 100755 index 0000000..c37a26c --- /dev/null +++ b/MathematicaFiles/Applications/EurodollarDataFunctions.m @@ -0,0 +1,281 @@ +(* wolfram packages *) +<<Calendar` +(* my packages *) +<<ImportExportBinary` +<<OddsandEnds` + +(* In order for DateToCMEDay to work properly for a given year, + we need Holidays[year] to be properly defined. So far, this has + only been done for 2008. *) + +ExportFuturesRates::usage = "ExportFuturesRates[filename, \ +data] exports the data using ExportBinary with $Description \ +and $ColumnHeadings." + +ImportFuturesRates::usage = "ImportFuturesRates[filename] \ +uses ImportBinary and returns {description, headings, data}." + +GetFuturesRates::usage = "GetFuturesRates[filename] \ +imports the legacy version of the eurodollar future rates \ +file." + +EurodollarExpirationDate::usage = +"EurodollarExpirationDate[{year, month}] returns the expiration \ +date {year, month, day} for the given contract." + +MissingCMEDays::usage = +"MissingCMEDays[database] returns a report of the days missing from the \ +database." + +MostRecentDay::usage = +"MostRecentDay[database] returns a report of the most recent day in the \ +database." + +CMEDayToDate::usage = +"CMEDayToDate[year, dayNumber] returns the corresponding date." + +DateToCMEDay::usage = +"DateToCMEDay[{year,month,day}] returns the corresponding CME day number. \ +DateToCMEDay[] returns today's CME day number." + +DateToCMEDay::baddate = "Not a valid EuroDollar date." + +CMEDayToDate::badday = "Not a valid EuroDollar day." + +URLforPDFfromCME::usage = +"URLforPDFfromCME[section, {year, day}] generates the URL for the Section \ +data for the date specified. The arguments section, year, and day should \ +all be integers." + +ImportSectionPDFfromCME::usage = +"ImportSectionPDFfromCME[section, {year, day}] imports the section \ +data from the CME website and returns a string. The \ +arguments section, year, and day should all be integers." + +ImportSectionPDFfromCMEandWriteToFile::usage = +"ImportSectionPDFfromCMEandWriteToFile[section, {year, day}] \ +imports the section data from the CME website and writes a .txt \ +file to the current directory. The arguments section, year, and \ +day should all be integers." + +ExtractDataFromCMEString::usage = +"ExtractDataFromCMEString[instring] extracts the data from the given \ +input string, itself obtained from a CME pdf." + +ReadDataFromCMEPDF::usage = +"ReadDataFromCMEPDF[filename] returns the data extracted from the CME pdf \ +with the given filename."; + + +$Description = "Eurodollar Futures Rates: Daily" + +$ColumnHeadings = { + "Quote date: Year", + "Quote date: Month", + "Quote date: Day", + "CME day number", + "Maturity date: Year", + "Maturity date: Month", + "Maturity date: Day", + "Futures rate" + } + +Holidays[2008] = { + {2008, 1, 1}, {2008, 1, 21}, {2008, 2, 18}, {2008, 3, 21}, + {2008, 5, 26}, {2008, 7, 4}, {2008, 9, 1}, {2008, 10, 13}, + {2008, 11, 11}, {2008, 11, 27}, {2008, 12, 25} + } + +ExportFuturesRates[filename_String, data_] := + ExportBinary[filename, + Flatten /@ Union[data], + Description -> $Description, + ColumnHeadings -> $ColumnHeadings + ] + +ImportFuturesRates[filename_String] := + Module[{desc, headings, data, group}, + {desc, headings, data} = ImportBinary[filename]; + group = {#[[{1,2,3}]], #[[4]], #[[{5,6,7}]], #[[8]]}&; + {desc, group[headings], group /@ data} + ] + +GetFuturesRates[filename_String] := { + ToExpression[StringSplit[#1, "/"]], #2, + ToExpression[StringSplit[#3, "/"]], #4, #5, #6, #7 + } & @@@ Import[filename] + +EurodollarExpirationDate[{year_, month_}] := + {year, month, + Switch[DayOfWeek[{year, month, 15}], + Wednesday, 13, + Tuesday, 14, + Monday, 15, + Sunday, 16, + Saturday, 17, + Friday, 18, + Thursday, 19]} + +MissingCMEDays[cmedata_] := + Module[{ + dateDay = Flatten /@ Union[cmedata[[All,{1, 2}]]], + missinglist + }, + missinglist = + MapThread[Prepend, { + With[{split = Split[dateDay[[All,-1]], #1 < #2 & ]}, + MapThread[Complement, {Apply[Range, split[[All,{1, -1}]], {1}], split}]], + Union[dateDay[[All, 1]]] + } + ]; + Labeled[Framed[ + Grid[missinglist, Dividers -> {{False, True, False}, None}, Alignment -> Right]], + "Missing CME Days (by year)", Top] + ] + +MostRecentDay[cmedata_] := + Row[{ + "Most Recent Day:", + DateString[cmedata[[-1,1]], {"Day", " ", "MonthNameShort", " ", "Year"}], + "Day", + cmedata[[-1,2]] + }, " "] + +Weekdays[year_] := Weekdays[year] = + Pick[#1, DayOfWeek /@ #1, Monday | Tuesday |Wednesday | Thursday | Friday]& @ + Table[DatePlus[{year - 1, 12, 31}, i], {i, If[LeapYearQ[year], 366, 365]}] + +CMEDays[year_] := CMEDays[year] = + DeleteCases[Weekdays[year], Alternatives @@ Holidays[year]] + +DateToCMEDay[{year_, month_, day_, ___}] := + Module[{pos = Position[CMEDays[year], {year, month, day}]}, + If[pos === {}, + Message[DateToCMEDay::baddate]; $Failed, + pos[[1,1]]] + ] + +DateToCMEDay[] := DateToCMEDay[Date[]] + +CMEDayToDate[year_, day_] := + If[0 < day < Length[CMEDays[year]], + CMEDays[year][[day]], + Message[CMEDayToDate::badday]; $Failed + ] + +myDateDifference[d1:{_, _, _}, d2:{_, _, _}] := + (AbsoluteTime[d2] - AbsoluteTime[d1])/86400 + +MaturityInDays[cmedata_] := + Apply[myDateDifference, cmedata[[All,{1, 3}]], {1}] + +CMEHeaderReport[desc_, headings_] := + Framed[Column[{desc, Row[headings /. d:{_, _, _} :> Column[d], Spacer[12]]}, + Dividers -> Center] + ] + +GetEuroDollarData[date:{_Integer, _Integer, _Integer, ___}] := + Cases[cmedata, {date, _, m_, v_} :> {myDateDifference[date, m]/365.25, v}] + +SectionList = {9, 51, 52} + +SectionLookupTable = + {{9, "_Interest_Rate_And_Energy_Futures_"}, + {51, "_Euro_Dollar_Call_Options_"}, + {52, "_Euro_Dollar_Put_Options_"}} + +URLforPDFfromCME[ + section_Integer /; MemberQ[SectionList, section], + {year_Integer, day_Integer} + ] := + StringJoin[ + "http://www.cmegroup.com/daily_bulletin/Section", + IntegerString[section, 10, 2], + Cases[SectionLookupTable, {section, string_} -> string][[1]], + IntegerString[year, 10, 4], + IntegerString[day, 10, 3], + ".pdf" + ] + +URLforPDFfromCME[section_, {year_, month_, day_}] := + With[{cmeday = DateToCMEDay[{year, month, day}]}, + If[cmeday === $Failed, + $Failed, + URLforPDFfromCME[section, {year, cmeday}] + ] + ] + +URLforPDFfromCME[__] := $Failed + +ImportSectionPDFfromCME[section_Integer, {year_Integer, day_Integer}] := + With[{url = URLforPDFfromCME[section, {year, day}]}, + Switch[url, + $Failed, $Failed, + _, Import[url, "Plaintext"] + ] + ] + +ImportSectionPDFfromCMEandWriteToFile[ + section_Integer, + {year_Integer, day_Integer} + ] := + With[{url = URLforPDFfromCME[section, {year, day}]}, + Switch[url, + $Failed, $Failed, + _, Export[ + StringJoin[StringSplit[url, {"/", "."}][[-2]], ".txt"], + Import[url, "Plaintext"] + ] + ] + ] + +LineNumber[startString_String, lines_] := + Position[Length /@ + StringCases[lines, StringExpression[StartOfString, startString]], 1][[1,1]] + +ExtractDataFromCMEString[instring_String] := + Module[{lines, dateline, quotedate, pagenumber, daynumber, fixline, + bbafix, datalines, contracts, contractmonths, contractmaturities}, + lines = DeleteCases[ImportString[instring, "Lines"], ""]; + dateline = lines[[LineNumber["PG", lines]]]; + quotedate = DateList[StringTake[dateline, {118, 129}]][[1 ;; 3]]; + {pagenumber, daynumber} = + ToExpression[StringCases[dateline, NumberString][[{1, 2}]]]; + fixline = lines[[LineNumber["U.S.", lines]]]; + bbafix = ToExpression[StringCases[fixline, NumberString][[-1]]]; + datalines = lines[[ + LineNumber["EURO DLR FUT", lines] + 1 ;; LineNumber["TOTAL", lines] - 1 + ]]; + contracts = StringTake[datalines, 5]; + contractmonths = + (DateList[{StringInsert[#1, " ", 4], {"MonthName", "YearShort"}}]& /@ + contracts)[[All,{1, 2}]]; + contractmaturities = EurodollarExpirationDate /@ contractmonths; + rates = Flatten[ + StringCases[datalines, StringExpression[r:NumberString, ")"] :> ToExpression[r]]]; + { + {pagenumber, daynumber, quotedate, bbafix}, + Sort[Transpose[{contractmaturities, rates}]] + } + ] + +ReadDataFromCMEPDF[filename_String] := + ExtractDataFromCMEString[Import[filename, "Plaintext"]] + +Section09DataForDatabase[filename_String] := + With[{data = ExtractDataFromCMEString[Import[filename, "Plaintext"]]}, + (Join[data[[1,{3, 2}]], #1] & ) /@ data[[2]] + ] + +Section09DataForDatabase[{year_, cmeday_}] := {} + + +CMEEurodollarSection09PDFs[] := + ToExpression[ + StringTake[#, {{1, 4}, {5, 7}}] & /@ + StringTake[ + StringSplit[FileNames["*.pdf", $CMEEuroDollarSection09Directory], + {"\\", "."}][[All, -2]], -7] + ] + + diff --git a/MathematicaFiles/Applications/GaussianKernel.m b/MathematicaFiles/Applications/GaussianKernel.m new file mode 100755 index 0000000..0050470 --- /dev/null +++ b/MathematicaFiles/Applications/GaussianKernel.m @@ -0,0 +1,118 @@ +(* Gaussian kernel density and regression *) + +(* wrapper functions *) + +GaussianDensity::usage = "GaussianDensity[data][h][x] returns the the +Gaussian kernel density evaluated at x (given the bandwidth h). If x +is a vector, a list of pairs is returned. GaussianDensity[data][h1, +h2][{x1, x2}] returns the Gaussian kernel density evaluated at {x1, +x2} (given the bandwidths h1 and h2). An optional h12 can be used to +control the correlation between the two dimensions. If x1 and x2 are +vectors then a list of triples is returned." + +GaussianRegress::usage = "GaussianRegress[data][h][x] returns the +value of the kernel regression at x given the bandwidth h. If x is a +vector, a list of pairs is returned." + +GaussianDensity[data_?(VectorQ[#, NumericQ] &)][h_?NumericQ][z_?NumericQ] := + $GaussKernel1[h, z, data] + +GaussianDensity[data_?(MatrixQ[#, NumericQ] &)][ + h1_?NumericQ, h2_?NumericQ, h12_:0][{z1_?NumericQ, z2_?NumericQ}] := + $GaussKernel2[h1, h2, h12, z1, z2, data] + +GaussianDensity[data_?(MatrixQ[#, NumericQ] &)][ + h1_?NumericQ, h2_?NumericQ, h12_:0][z1_?NumericQ, z2_?NumericQ] := + $GaussKernel2[h1, h2, h12, z1, z2, data] + +GaussianRegress[data_?(MatrixQ[#, NumericQ] &)][h_?NumericQ][z_?NumericQ] := + $GaussKernelRegress[h, z, data] + +(* "listable" versions *) +GaussianDensity[data_?(VectorQ[#, NumericQ] &)][h_?NumericQ][ + z_?(VectorQ[#, NumericQ] &)] := $ListGaussKernel1[h, z, data] + +GaussianDensity[data_?(MatrixQ[#, NumericQ] &)][ + h1_?NumericQ, h2_?NumericQ, h12_:0][ + {z1_?(VectorQ[#, NumericQ]&), z2_?(VectorQ[#, NumericQ]&)}] := + With[{z = Transpose[Flatten[Outer[List, z1, z2], 1]]}, + $ListGaussKernel2[h1, h2, h12, z[[1]], z[[2]], data] + ] + +GaussianDensity[data_?(MatrixQ[#, NumericQ] &)][ + {h1_?NumericQ, h2_?NumericQ}][ + {z1_?(VectorQ[#, NumericQ]&), z2_?(VectorQ[#, NumericQ]&)}] := + GaussianDensity[data][h1, h2][{z1, z2}] + +GaussianDensity[data_?(MatrixQ[#, NumericQ] &)][ + {h1_?NumericQ, h2_?NumericQ, h3_?NumericQ}][ + {z1_?(VectorQ[#, NumericQ]&), z2_?(VectorQ[#, NumericQ]&), + z3_?(VectorQ[#, NumericQ]&)}] := + With[{z = Transpose[Flatten[Outer[List, z1, z2, z3], 2]]}, + $ListGaussKernel3[h1, h2, h3, z[[1]], z[[2]], z[[3]], data] + ] + +GaussianRegress[data_?(MatrixQ[#, NumericQ] &)][h_?NumericQ][ + z_?(VectorQ[#, NumericQ] &)] := + $ListGaussKernelRegress[h, z, data] + +(* compile the guts *) + +(* 1-dimensional density kernel *) +$GaussKernel1 = + Compile[{h, z, {d, _Real, 1}}, + Tr[1/(E^((d - z)^2/(2*h^2))*(h*Sqrt[2*Pi]))]/Length[d] + ]; + +(* "listable" version *) +$ListGaussKernel1 = + Compile[{h, {z, _Real, 1}, {d, _Real, 1}}, + ({#1, Tr[1/(E^((d - #1)^2/(2*h^2))*(h*Sqrt[2*Pi]))]/Length[d]} &) /@ z + ]; + +(* 2-dimensional density kernel *) +$GaussKernel2 = + Compile[{h1, h2, h12, z1, z2, {d, _Real, 2}}, + Tr[E^((h2*(d[[All, 1]] - z1)^2 - + 2*h12*(d[[All, 1]] - z1)*(d[[All, 2]] - z2) + + h1*(d[[All, 2]] - z2)^2)/(2*h12^2 - 2*h1*h2))/(2* + Sqrt[-h12^2 + h1*h2]*Pi)]/Length[d] + ]; + +(* "listable" version *) +$ListGaussKernel2 = + Compile[{h1, h2, h12, {z1, _Real, 1}, {z2, _Real, 1}, {d, _Real, 2}}, + MapThread[ + {#1, #2, + Tr[E^((h2*(d[[All, 1]] - #1)^2 - + 2*h12*(d[[All, 1]] - #1)*(d[[All, 2]] - #2) + + h1*(d[[All, 2]] - #2)^2)/(2*h12^2 - 2*h1*h2))/(2* + Sqrt[-h12^2 + h1*h2]*Pi)]/Length[d]}&, + {z1, z2}] + ]; + +(* "listable" 3-d gaussian density *) +$ListGaussKernel3 = + Compile[{h1, h2, h3, {z1, _Real, 1}, {z2, _Real, 1}, {z3, _Real, 1}, + {d, _Real, 2}}, + MapThread[ + {#1, #2, #3, + Tr[E^((-((d[[All,1]] - #1)^2/h1) - (d[[All,2]] - #2)^2/h2 - + (d[[All,3]] - #3)^2/h3)/2)/(2*Sqrt[2*h1*h2*h3]*Pi^(3/2))]/Length[d]}&, + {z1, z2, z3}] + ]; + +(* regression kernel *) +$GaussKernelRegress = + Compile[{h, z, {d, _Real, 2}}, + With[{v = 1/(E^((d[[All, 1]] - z)^2/(2*h^2))*(h*Sqrt[2*Pi]))}, + v.d[[All, 2]]/Tr[v]] + ]; + +(* "listable" regression version *) +$ListGaussKernelRegress = + Compile[{h, {z, _Real, 1}, {d, _Real, 2}}, + {#, With[{v = 1/(E^((d[[All, 1]] - #)^2/(2*h^2))*(h*Sqrt[2*Pi]))}, + v.d[[All, 2]]/Tr[v]]}& /@ z + ]; + diff --git a/MathematicaFiles/Applications/GenSys.m b/MathematicaFiles/Applications/GenSys.m new file mode 100755 index 0000000..f40e69c --- /dev/null +++ b/MathematicaFiles/Applications/GenSys.m @@ -0,0 +1,358 @@ +(* :Author: (of Mathematica code) Mark Fisher *) + +(* :Date: January 2006 + November 2008 (updated for Version 7) +*) + +(* :Mathematica Version: 7.0 + Required for generalized SchurDecomposition *) + +(* :References: + QZSwitch and GenSys is transcribed from Chris Sims' matlab and R code, + available at: http://sims.princeton.edu/yftp/gensys/ + *) + +(* :Discussion: + +*) + + +(* usage messages *) +QZSwitch::usage = "QZSwitch[i, {A,B,Q,Z}] takes upper triangular matrices A \ +and B, orthonormal matrices Q and Z, interchanges diagonal elements i and \ +i+1 of both A and B while maintaining Q.A.Z\[HermitianConjugate] and \ +Q.B.Z\[HermitianConjugate] unchanged." + +QZDecomposition::usage = "QZDecomposition[{a,b}] returns {A,B,Q,Z} where A \ +and B are upper triangular, Q and Z are unitary, a = \ +Q\[HermitianConjugate].A.Z\[HermitianConjugate] and b = \ +Q\[HermitianConjugate].B.Z\[HermitianConjugate]. (Note Q is in \"matlab\" \ +form.)" + +QZSort::usage = "QZSort[{A,B,Q,Z}] takes upper triangular \ +matrices A and B, orthonormal matrices Q and Z, and returns same sorted by \ +the generalized eigenvalues of {A,B}." + +GeneralizedEigenvalues::usage = "GeneralizedEigenvalues[{A,B}] takes \ +upper triangular matrices {A,B} and returns the generalized eigenvalues \ +Abs[Transpose[B, {1,1}]/Transpose[A, {1,1}]]." + +GenSys::usage = "GenSys[{g0, g1, c, psi, pi}] implements Chris Sims' code \ +and returns {a, b0, b, Cs}. Parameters that do not appear in neither g0 nor \ +g1 may be symbolic." + +CanonicalForm::usage = "CanonicalForm[equations, y0, z0, eta, (t)] takes a \ +list of equations and three lists of symbols, the contemporaneous \ +endogenous variables y0, the contemporaneous exogenous variables z0, and \ +the endogenous forcast errors eta, and returns the model in canonical form: \ +{{g0, g1, c, psi, pi}, {y0, y1, z, eta} }}, where y1 is the list of lagged \ +endogenous variables and z includes lagged exogenous variables. A final \ +argument to CanonicalForm is the symbol to use for time in the equations. \ +When the argument is omitted, it defaults to the Global symbol t. \ +CanonicalForm takes the option SolveForReducedForm which is set to True by \ +default." + +ProcessCanonicalForm::usage = "ProcessCanonicalForm[{g0, g1, c, psi, pi}, \ +k] takes the output from CanonicalForm and an integer k that specifies the \ +number of rows in the first block and sets a number of global variables: \ +{P, \[CapitalOmega], Q, Q1} and more." + +CanonicalSolutions::usage = "CanonicalSolutions[{A, B0, B}, {y0, y1, z}, \ +(t)] computes global variables soln and soln1 and returns a tabular \ +representation of the solution (all of which exclude the forward \ +component)." + +PermutationMatrix::usage = "PermutationMatrix[rules, n] take a list of \ +rules that indicate which positions of a diagonal matrix to swap and \ +an interger that indicates the size of the matrix." + +(* code starts here *) + +realform = RealBlockDiagonalForm + +Which[ + $VersionNumber < 5.0, + Print["Warning: Version 5.0 or greater is required."], + $VersionNumber < 7.0, + realform = RealBlockForm + ] + +PermutationMatrix[r : {__Rule}, n_Integer?Positive] := + Module[{one, two}, + one = Thread[Flatten[r /. (x_ -> y_) :> {{x, y}, {y, x}}, 1] -> 1]; + two = {#, #} -> 1 & /@ Complement[Range[n], r /. Rule -> Sequence]; + Normal @ SparseArray[Join[one, two]] + ] + +GeneralizedEigenvalues[{A_, B_}] := Transpose[B, {1,1}]/Transpose[A, {1,1}] + +(* Q is in matlab form *) +QZDecomposition[{a_, b_}] := + MapAt[ConjugateTranspose, + SchurDecomposition[{a, b}//N, realform -> False][[{2,4,1,3}]], + 3] + +QZSort[{Ap_, Bp_, Qp_, Zp_}] := + Module[{A = Ap, B = Bp, Q = Qp, Z = Zp, roots}, + roots = Abs @ GeneralizedEigenvalues[{A, B}]; + (* bubble sort the roots *) + For[i = Length[roots], i >= 1, i--, + For[j = 1, j <= i - 1, j++, + If[roots[[j]] > roots[[j + 1]], + (* then swap *) + roots[[{j, j + 1}]] = roots[[{j + 1, j}]]; + {A, B, Q, Z} = QZSwitch[j, {A, B, Q, Z}] + ] + ] + ]; + {A, B, Q, Z} + ] + +Options[QZSwitch] = {Tolerance -> 1. * 10^(-12)} + +QZSwitch[i_Integer?Positive, {Ap_, Bp_, Qp_, Zp_}, opts___?OptionQ] /; + i <= (Length[Ap] - 1) := + Module[{A = Ap, B = Bp, Q = Qp, Z = Zp, + a, b, c, d, e, f, wz, xy, n, m, realsmall}, + a = A[[i,i]]; + b = A[[i,i+1]]; + c = A[[i+1,i+1]]; + d = B[[i,i]]; + e = B[[i,i+1]]; + f = B[[i+1,i+1]]; + (* special cases involve coincident zeros *) + (* I'm not sure what the implications are for QZSort + of the output produced by the special cases *) + (* Sims uses 10^(-7) here *) + realsmall = Tolerance /. {opts} /. Options[QZSwitch]; + Which[ + Abs[c] < realsmall && Abs[f] < realsmall, + If[Abs[a] < realsmall, + (* l.r. coincident zeros with u.l. of A=0; do nothing *) + Return[{A, B, Q, Z}], + (* l.r. coincident zeros; put 0 in u.l. of A *) + wz = {b, -a}; + wz = wz/Norm[wz]; + wz = {wz, {Conjugate[wz[[2]]], -Conjugate[wz[[1]]]}}; + xy = IdentityMatrix[2] + ], + Abs[a] < realsmall && Abs[d] < realsmall, + If[Abs[c] < realsmall, + (* u.l. coincident zeros with l.r. of A=0; do nothing *) + Return[{A, B, Q, Z}], + (* u.l. coincident zeros; put 0 in l.r. of A *) + wz = IdentityMatrix[2]; + xy = {c, -b}; + xy = xy/Norm[xy]; + xy = {{Conjugate[xy[[2]]], -Conjugate[xy[[1]]]}, xy}; + ], + True, + (* usual case *) + wz = {c*e-f*b, Conjugate[c*d-f*a]}; + xy = {Conjugate[b*d-e*a], Conjugate[c*d-f*a]}; + n = Norm[wz]; + m = Norm[xy]; + If[m < realsmall, (* Sims uses 10^(-10) here *) + (* all elements of A and B are proportional *) + Return[{A, B, Q, Z}]]; + wz = wz/n; + xy = xy/m; + wz = {wz, {-Conjugate[wz[[2]]], Conjugate[wz[[1]]]}}; + xy = {xy, {-Conjugate[xy[[2]]], Conjugate[xy[[1]]]}} + ]; + A[[{i,i+1}]] = xy.A[[{i,i+1}]]; + B[[{i,i+1}]] = xy.B[[{i,i+1}]]; + Q[[{i,i+1}]] = xy.Q[[{i,i+1}]]; + A[[All,{i,i+1}]] = A[[All,{i,i+1}]].wz; + B[[All,{i,i+1}]] = B[[All,{i,i+1}]].wz; + Z[[All,{i,i+1}]] = Z[[All,{i,i+1}]].wz; + {A, B, Q, Z} + ] + +(* no error checking yet *) +GenSys[{g0_, g1_, c_, psi_, pi_}, div_:1, s_:s] := + Module[{A, B, Q, Z, gev, agev, k, n, r1, r2, Q1, Q2, Z1, + A11, A12, A22, B11, B12, B22, phi, invAll, invB22, + H, a, b0, b, Cy, Cf, Cz, X, R, W}, + {A, B, Q, Z} = QZSort @ QZDecomposition[{g0, g1}]; + gev = GeneralizedEigenvalues[{A, B}]//Chop; + agev = Abs[gev]; + Print[StringForm["Absolute value of generalized eigenvalues: ``", + agev]]; + If[agev[[-1]] <= div, Return[gev]]; + k = Position[Thread[agev > div], True, 1, 1][[1, 1]] - 1; + n = Length[g0]; + r1 = Range[1, k]; + r2 = Range[k + 1, n]; + Q1 = Q[[ r1 ]]; + Q2 = Q[[ r2 ]]; + Z1 = Z[[ All, r1 ]]; + A11 = A[[ r1, r1 ]]; + A12 = A[[ r1, r2 ]]; + A22 = A[[ r2, r2 ]]; + B11 = B[[ r1, r1 ]]; + B12 = B[[ r1, r2 ]]; + B22 = B[[ r2, r2 ]]; + invA11 = Inverse[A11]; + invB22 = Inverse[B22]; + X = Q2.pi; + R = (IdentityMatrix[n-k] - X.PseudoInverse[X]); + (* + rank = MatrixRank[X]; + dim = Dimensions[X]; + svd = SingularValueDecomposition[X]//Chop; + Print[{dim, rank}]; + Print[svd]; + *) + (* + If[Union[Flatten[Chop[R.Q2.psi]]] != {0}, + Print["No solutions exist."]; + Return[Chop[R.Q2.psi]] + ]; + *) + W = Table[B22.MatrixPower[invB22.A22, s-1].invB22.Q2.psi, {s, 1, n - k}]; + W = Transpose[Join @@ (Transpose /@ W)]; + If[Union[Flatten[Chop[R.W]]] != {0}, + Print["No solutions exist."]; + Return[Chop[R.W]] + ]; + If[Dimensions[R][[2]] == Dimensions[Q1.pi][[2]], + If[Union[Flatten[Chop[R.Transpose[Q1.pi]]]] != {0}, + Print["The solution is not unique."]; + Print[Chop[R.Transpose[Q1.pi]]] + ], + Print["The solution is not unique."] + ]; + (* existence *) + (* + eu = {0, 0}; + nunstab = n - k; + etawt = Q2.pi; + neta = Dimensions[pi][[2]]; + ndeta = Min[nunstab, neta]; + If[ndeta == 0, + (* then *) + ueta = Table[]; + (* else *) + + ]; + *) + (* uniqueness *) + + + phi = Q1.pi.PseudoInverse[Q2.pi]; + H = Z.Join[ + MapThread[Join, {invA11, -invA11.(A12 - phi.A22)}], + MapThread[Join, {Table[0, {n-k}, {k}], IdentityMatrix[n - k]}] + ]; + a = Z1.invA11.MapThread[Join, {B11, B12 - phi.B22}]. + ConjugateTranspose[Z]; + b0 = H.Join[Q1 - phi.Q2, Inverse[B22 - A22].Q2].c; + b = H.Join[Q1 - phi.Q2, Table[0, {n - k}, {n}]].psi; + Cy = -H[[ All, r2 ]]; + Cf = invB22.A22; + Cz = invB22.Q2.psi; + Cs = Cy.MatrixPower[Cf, s-1].Cz // Simplify; + {a, b0, b, Cs} // Chop + ] + +Options[CanonicalForm] = {SolveForReducedForm -> True} + +CanonicalForm[equations:{__Equal}, y0_List, z0_List, eta_List, + t_:t, opts___?OptionQ] := + Module[{solve, y1, z1, z, eqns, resid, g0, g1, psi, pi, c}, + solve = SolveForReducedForm /. {opts} /. Options[CanonicalForm]; + y1 = y0 /. t -> t-1; + z1 = Union[Cases[equations, Alternatives @@ (z0 /. t -> t - 1), Infinity]]; + z = Join[z0, z1]; + If[solve, + eqns = Thread[y0 == (y0 /. Solve[equations, y0][[1]])], + eqns = equations + ]; + {resid, g0} = Normal[CoefficientArrays[eqns, y0]]; + resid = -resid; + {g1, psi, pi} = Normal[CoefficientArrays[resid, #][[2]] & /@ {y1, z, eta}]; + c = resid - (g1.y1 + psi.z + pi.eta) // Simplify; + {{g0, g1, c, psi, pi}, {y0, y1, z, eta}} + ] + +ProcessCanonicalForm[{g0_, g1_, c_, psi_, pi_}, k_Integer?Positive, + permList:{__Rule}] := + Module[{n, pmat, R1, R2, G, H, AB}, + {P, \[CapitalOmega]} = JordanDecomposition[g1] // Simplify; + n = Length[g1]; + pmat = PermutationMatrix[permList,n]; + \[CapitalOmega] = pmat.\[CapitalOmega].Transpose[pmat]; + P = P.Transpose[pmat]; + Q = Inverse[P] // Simplify; + R1 = Range[1, k]; + R2 = Range[k + 1, n]; + Q1 = Q[[R1]]; + Q2 = Q[[R2]]; + \[CapitalOmega]11 = \[CapitalOmega][[R1, R1]]; + \[CapitalOmega]12 = \[CapitalOmega][[R1, R2]]; + \[CapitalOmega]21 = \[CapitalOmega][[R2, R1]]; + \[CapitalOmega]22 = \[CapitalOmega][[R2, R2]]; + P1 = P[[All, R1]]; + P2 = P[[All, R2]]; + X = Q2.pi // Simplify; + pseudoinv = Inverse[Transpose[X].X].Transpose[X] // Simplify; + \[CapitalPhi] = Q1.pi.pseudoinv // Simplify; + G = P1.(Q1 - \[CapitalPhi].Q2) // Simplify; + H = (P1.\[CapitalPhi] + P2) // Simplify; + AB = {P1.(\[CapitalOmega]11.Q1 - \[CapitalPhi].\[CapitalOmega]22.Q2), + G.psi}; + {A, B} = Map[FullSimplify, AB, {3}]; + Cs = -H.MatrixPower[\[CapitalOmega]22, -s].Q2.psi // PowerExpand + // Simplify; + B0 = (G + H.Inverse[IdentityMatrix[n - k] - \[CapitalOmega]22].Q2).c + // Simplify; + {A, B0, B, Cs} + ] + +ProcessCanonicalForm[{g0_, g1_, c_, psi_, pi_}, k_Integer?Positive, + sym_:\[Phi]] := + Module[{n, pmat, R1, R2, G, H, AB}, + {P, \[CapitalOmega]} = JordanDecomposition[g1] // Simplify; + n = Length[g1]; + If[!FreeQ[\[CapitalOmega], sym], + sympos = Position[Transpose[\[CapitalOmega], {1, 1}], sym][[1, 1]]; + If[sympos != n, + pmat = SparseArray[Thread[Table[Which[i == sympos, {sympos, n}, + i == n, {n, sympos}, True, {i, i}], {i, n}] -> Table[1, {n}]]]; + \[CapitalOmega] = pmat.\[CapitalOmega].Transpose[pmat]; + P = P.Transpose[pmat] + ] + ]; + Q = Inverse[P] // Simplify; + R1 = Range[1, k]; + R2 = Range[k + 1, n]; + Q1 = Q[[R1]]; + Q2 = Q[[R2]]; + \[CapitalOmega]11 = \[CapitalOmega][[R1, R1]]; + \[CapitalOmega]12 = \[CapitalOmega][[R1, R2]]; + \[CapitalOmega]21 = \[CapitalOmega][[R2, R1]]; + \[CapitalOmega]22 = \[CapitalOmega][[R2, R2]]; + P1 = P[[All, R1]]; + P2 = P[[All, R2]]; + X = Q2.pi // Simplify; + pseudoinv = Inverse[Transpose[X].X].Transpose[X] // Simplify; + \[CapitalPhi] = Q1.pi.pseudoinv // Simplify; + G = P1.(Q1 - \[CapitalPhi].Q2) // Simplify; + H = (P1.\[CapitalPhi] + P2) // Simplify; + AB = {P1.(\[CapitalOmega]11.Q1 - \[CapitalPhi].\[CapitalOmega]22.Q2), + G.psi}; + {A, B} = Map[FullSimplify, AB, {3}]; + Cs = -H.MatrixPower[\[CapitalOmega]22, -s].Q2.psi // PowerExpand + // Simplify; + B0 = (G + H.Inverse[IdentityMatrix[n - k] - \[CapitalOmega]22].Q2).c + // Simplify; + {A, B0, B, Cs} + ] + +CanonicalSolutions[{A_, B0_, B_}, {y0_, y1_, z_}, t_:t] := + Module[{}, + soln = Thread[y0 -> A.y1 + B0 + B.z]; + soln1 = soln /. t -> t - 1; + TableForm[Thread[y0 == (A.y1 + B0 + B.z // Simplify)]] + ] \ No newline at end of file diff --git a/MathematicaFiles/Applications/HierarchicalMetropolis.m b/MathematicaFiles/Applications/HierarchicalMetropolis.m new file mode 100755 index 0000000..f6a08d9 --- /dev/null +++ b/MathematicaFiles/Applications/HierarchicalMetropolis.m @@ -0,0 +1,94 @@ +(* HierarchicalMetropolis *) + +HierarchicalMetropolis::usage = "HierarchicalMetropolis[HyperPriorFunction, \ +EntityPriorFunction, LikelihoodFunctions, hyperStart, entityStart, hyperCovMat, \ +entityCovMat, nreps, (opts)]. HyperPriorFunction is a function of the \ +hyperparameters, EntityPriorFunction is a function of the (joined sequence \ +of) entity parameters and hyparameters, while the LikelihoodFunctions are \ +functions on the (sequence of) entity parameters only. Starting values are \ +given by the vector hyperStart and the matrix entityStart. (All of \ +HyperPriorFunction, \ +EntityPriorFunction and LikelihoodFunctions must return log values.) The scale of \ +the random normal draws is controlled by hyperCovMat and entityCovMat. The \ +number of repetitions is given by nrep. The options \ +EntityParametersInBoundsQ and HyperParametersInBoundsQ are used to specify \ +the relavant support. The option ReturnEntityParameterHistory can \ +be used to return the history of the entity parameters in addition to the \ +history of the hyperparameters." + +Options[HierarchicalMetropolis] = { + EntityParametersInBoundsQ -> (True&), + HyperParametersInBoundsQ -> (True&), + ReturnEntityParameterHistory -> False, + ReportProgress -> True, + HyperParameterSkipNumber -> 0} + +HierarchicalMetropolis[ + HyperPriorFunction_, + EntityPriorFunction_, + LikelihoodFunctions_List, + hyperStart_?(VectorQ[#, NumericQ]&), + entityStart_?(MatrixQ[#, NumericQ]&), + hyperCovMat_, + entityCovMat_, + nreps_Integer?Positive, + opts___?OptionQ + ] := + Module[{entityInBoundsQ, hyperInBoundsQ, return, report, entityNum, + entityparmsNum, hyperparmsNum, hyperparms, entityparms, + Lvals, Pvals, PHval, entitychol, hyperchol, entityshocks, x1, + L1, P1, z1, Pz, PHz}, + {entityInBoundsQ, hyperInBoundsQ, return, report} = + {EntityParametersInBoundsQ, HyperParametersInBoundsQ, + ReturnEntityParameterHistory, ReportProgress} /. {opts} /. + Options[HierarchicalMetropolis]; + {entityNum, entityparmsNum} = Dimensions[entityStart]; + hyperparmsNum = Length[hyperStart]; + hyperparms = hyperStart; + entityparms = entityStart; + Lvals = MapThread[Apply, {LikelihoodFunctions, entityparms}]; + Pvals = (EntityPriorFunction @@ Join[#1, hyperparms])& /@ entityparms; + PHval = HyperPriorFunction @@ hyperparms; + {entitychol, hyperchol} = CholeskyDecomposition[(Transpose[#]+#)/2]& /@ + {entityCovMat, hyperCovMat}; + If[report, + Function[{x}, Monitor[x, ProgressIndicator[j, {0, nreps}]], HoldAll], + Identity] @ + Table[ (* hyperparameter loop *) + x1 = entityparms + Transpose[RandomReal[NormalDistribution[0,1], + {entityparmsNum, entityNum}].entitychol]; + Table[ (* entity subloop *) + If[entityInBoundsQ @@ x1[[i]], + (* then *) + L1 = LikelihoodFunctions[[i]] @@ x1[[i]]; + P1 = EntityPriorFunction @@ Join[x1[[i]], hyperparms]; + If[L1 + P1 >= Lvals[[i]] + Pvals[[i]] + Log[RandomReal[]], + (* then, update *) + entityparms[[i]] = x1[[i]]; + Lvals[[i]] = L1; + Pvals[[i]] = P1 + (* else, do nothing *) + ] + (* else, do nothing *) + ], + {i, entityNum}]; (* end of subloop *) + z1 = hyperparms + + RandomReal[NormalDistribution[0,1], hyperparmsNum].hyperchol; + If[hyperInBoundsQ @@ z1, + (* then *) + Pz = (EntityPriorFunction @@ Join[#1, z1])& /@ entityparms; + PHz = HyperPriorFunction @@ z1; + If[Tr[Pz] + PHz >= Tr[Pvals] + PHval + Log[RandomReal[]], + Pvals = Pz; + PHval = PHz; + hyperparms = z1 + (* else, do nothing *) + ] + (* else, do nothing *) + ]; + If[return, {hyperparms, entityparms}, hyperparms], + {j, nreps}] (* end of hyperparameter loop *) + ] + + + diff --git a/MathematicaFiles/Applications/ImportExportBinary.m b/MathematicaFiles/Applications/ImportExportBinary.m new file mode 100755 index 0000000..30e9fe2 --- /dev/null +++ b/MathematicaFiles/Applications/ImportExportBinary.m @@ -0,0 +1,138 @@ +(* export and import binary files *) + +ExportBinary::usage = +"ExportBinary[file, data] or ExportBinary[file, data, typelist]. \ +ExportBinary takes the options ColumnHeads (a list of strings) \ +and Description (a string). If the typelist is not specified, \ +a typelist composed from \"Integer64\", \"Real64\", and \"TerminatedString\" \ +is inferred from the first row of the data"; + +ImportBinary::usage = "ImportBinary[file] imports a binary file\ +written via ExportBinary."; + +ExportBinary::baddim = "The length of the typelist does not match\ +the number of columns of the data."; + +ExportBinary::badtype = "The typelist includes an invalid type. \ +Valid types are given by $BinaryTypes."; + +Options[ExportBinary] = {ColumnHeadings -> None, Description -> None} + +ExportBinary[file_String, data_, typelist:{__String}, opts:OptionsPattern[]] := + Module[{n, d, desc, m, headings, h, str}, + {n, d} = Dimensions[data]; + If[d != Length[typelist], + Message[ExportBinary::baddim]; + Return[$Failed] + ]; + If[Complement[typelist, $BinaryTypes] != {}, + Message[ExportBinary::badtype]; + Return[$Failed] + ]; + desc = OptionValue[Description]; + m = If[desc === None || Not[StringQ[desc]], 0, 1]; + headings = OptionValue[ColumnHeadings]; + h = If[headings === None, 0, Length[headings]]; + str = OpenWrite[file, BinaryFormat -> True]; + BinaryWrite[str, $ImportExportBinaryHeader, "TerminatedString"]; + BinaryWrite[str, {n, d, m, h}, "Integer32"]; + BinaryWrite[str, typelist, "TerminatedString"]; + If[m == 1, BinaryWrite[str, desc, "TerminatedString"]]; + If[h > 0, BinaryWrite[str, headings, "TerminatedString"]]; + MapThread[BinaryWrite[str, #1, #2]&, {Transpose[data], typelist}]; + Close[str] + ] + +ExportBinary[file_String, data_, opts:OptionsPattern[]] := + Module[{typelist}, + mat = If[VectorQ[data], Partition[data, 1], data]; + typelist = (Head /@ First[mat]) /. + {Integer -> "Integer64", Real -> "Real64", String -> "TerminatedString"}; + ExportBinary[file, mat, typelist, opts] + ] + +ImportBinary[file_String] := + Module[{str, n, d, m, h, typelist, desc, headings, data}, + str = Check[OpenRead[file, BinaryFormat -> True], Return[$Failed]]; + BinaryRead[str, "TerminatedString"]; + {n, d, m, h} = BinaryReadList[str, "Integer32", 4]; + typelist = BinaryReadList[str, "TerminatedString", d]; + If[m == 1, desc = BinaryRead[str, "TerminatedString"]]; + If[h > 0, headings = BinaryReadList[str, "TerminatedString", h]]; + data = Transpose[BinaryReadList[str, #, n] & /@ typelist]; + Close[str]; + Switch[{m, h}, + {0, 0}, data, + {0, _}, {headings, data}, + {1, 0}, {desc, data}, + {1, _}, {desc, headings, data} + ] + ] + +(* check against this list for valid types *) +$BinaryTypes = { + "Byte", + "Character8", + "Character16", + "Complex64", + "Complex128", + "Complex256", + "Integer8", + "Integer16", + "Integer24", + "Integer32", + "Integer64", + "Integer128", + "Real32", + "Real64", + "Real128", + "TerminatedString", + "UnsignedInteger8", + "UnsignedInteger16", + "UnsignedInteger24", + "UnsignedInteger32", + "UnsignedInteger64", + "UnsignedInteger128" + }; + +(* put this at the start of the file *) +$ImportExportBinaryHeader = +"This is a binary file. Following the header information,\n\ +a data matrix of n rows and d columns is stored by columns:\n\ + n of the 1st data type, followed by n of the 2nd data type, etc.\n\ +Here is the format of the header information:\n\ + 1 \"TerminatedString\" (this message)\n\ + 4 \"Integer32\" (n, d, m, h)\n\ + d \"TerminatedString\" (data types, d>=1)\n\ + m \"TerminatedString\" (description, m=0 or m=1)\n\ + h \"TerminatedString\" (column headings, h>=0)\n"; + +(* +ExportBinary[file_String, data_, typelist:{__String}, opts:OptionsPattern[]] := + Module[{n, d, str}, + {n, d} = Dimensions[data]; + If[d != Length[typelist], + Message[ExportBinary::baddim]; + Return[$Failed] + ]; + If[Complement[typelist, $BinaryTypes] != {}, + Message[ExportBinary::badtype]; + Return[$Failed] + ]; + str = OpenWrite[file, BinaryFormat -> True]; + BinaryWrite[str, {n, d}, "Integer32"]; + BinaryWrite[str, typelist, "TerminatedString"]; + MapThread[BinaryWrite[str, #1, #2]&, {Transpose[data], typelist}]; + Close[str] + ] + +ImportBinary[file_String] := + Module[{str, n, d, typelist, data}, + str = OpenRead[file, BinaryFormat -> True]; + {n, d} = Table[BinaryRead[str, "Integer32"], {2}]; + typelist = Table[BinaryRead[str, "TerminatedString"], {d}]; + data = Transpose[BinaryReadList[str, #, n] & /@ typelist]; + Close[str]; + If[d == 1, Flatten[data], data] + ] +*) diff --git a/MathematicaFiles/Applications/ItosLemma.m b/MathematicaFiles/Applications/ItosLemma.m new file mode 100755 index 0000000..9a341c3 --- /dev/null +++ b/MathematicaFiles/Applications/ItosLemma.m @@ -0,0 +1,365 @@ +(* :Title: Ito's Lemma *) + +(* :Author: Mark Fisher *) + +(* :Context: ItosLemma` *) + +(* :Mathematica Version: 3.0 *) + +(* :History: Version 1.0, June 1999. + Version 1.1, June 2000. + Simplified ItoD. + Added option Scalarize to Diffusion. + Added new versions of ItoMake for simplified entry that + use new global symbols DriftSymbol and DiffusionSymbol. + Version 1.1.1, April 2003. Minor changes. + October 2006. Fix OverTilde for Version 6. + (OverTilde moved from Global` to System` context.) +*) + +(* :Sources: +A preliminary version was inspired by the package "Diffusion" written +by Steele and Stine (described in "Mathematica and Diffusions", +chapter 9 of "Economic and Financial Modeling with Mathematica", 1993, +Springer-Verlag, edited by Hal R. Varian). + +For an introduction to stochastic differential equations and Ito's lemma, +see Bernt �ksendal, Stochastic Differential Equations: An Introduction with +Applications, Springer-Verlag (currently in its 5th edition). +*) + +(* :Keywords: Ito's lemma, stochastic calculus, stochastic differential +equations, Brownian motion *) + +(* :Summary: +This package implements Ito's lemma for any number of Ito processes +with any number of arbitrarily-correlated Brownian motions. + +There are two main functions in this package: ItoMake and ItoD. ItoMake +should be used to declare an Ito process prior to using ItoD to compute the +stochastic derivative. For example (assuming the global symbols have been +set as in the housekeeping example below), ItoMake[x[t], \[Mu], \[Sigma]] +creates the global rule x[t + dt] -> x[t] + \[Mu] dt + \[Sigma] Subscript[dB, 1]. +ItoD[f[x[t], t]] constructs a Taylor series for f[x[t + dt], t + dt] around +dt = 0 and Subscript[dB, 1] = 0. The series is first-order in dt and +second-order in Subscript[dB, 1], where "Ito multiplication rules" are +applied to the second-order term. + +The functions Drift and Diffusion can be used to extract the drift and +diffusion from the output of ItoD. + +(***** Housekeeping Notice *****) + +The package relies on six global symbols: TimeSymbol, TimeIncrement, +BrownianIncrement, CorrelationSymbol, DriftSymbol, and DiffusionSymbol. +They can be set at the beginning of each session (after loading ItosLemma) +to more convenient symbols. Here is an example: + +Clear[t, dt, dB, \[Rho], \[Mu], \[Sigma]] +{TimeSymbol, TimeIncrement, BrownianIncrement, + CorrelationSymbol, DriftSymbol, DiffusionSymbol} = + {t, dt, dB, \[Rho], \[Mu], \[Sigma]} + +One way to make these assignments automatic is to copy the preceding +code to the bottom of this file, after the EndPackage[] statement. + +There is a "brief explanation to the code" in the Notebook ItosLemma.nb. + +*) + +(* :Examples: Supplied in the Notebook ItosLemma.nb. *) + +BeginPackage["ItosLemma`"] + +ItosLemma::usage = "ItosLemma.m is a package that implements Ito's Lemma. +The package uses six global symbols: TimeSymbol, TimeIncrement, +BrownianIncrement, CorrelationSymbol, DriftSymbol, and DiffusionSymbol. +They can be defined in terms of more convenient symbols.\n +Example:\n +Clear[t, dt, dB, \[Rho], \[Mu], \[Sigma]];\n +{TimeSymbol, TimeIncrement, BrownianIncrement, CorrelationSymbol, + DriftSymbol, DiffusionSymbol} = {t, dt, dB, \[Rho], \[Mu], \[Sigma]}" + +TimeSymbol::usage = "TimeSymbol is the symbol that represents time." + +TimeIncrement::usage = "TimeIncrement is the symbol that represents an +infinitesimal change in time." + +BrownianIncrement::usage = "BrownianIncrement is the symbol that +represents an infinitesimal change in a Brownian motion." + +CorrelationSymbol::usage = "CorrelationSymbol is the symbol that +represents the correlation between Brownian motions." + +DriftSymbol::usage = "DriftSymbol is the symbol that represents the +drift." + +DiffusionSymbol::usage = "DiffusionSymbol is the symbol that represents +the diffusion." + +ItoD::usage = "ItoD[expr] applies Ito's lemma to expr. ItoD takes the +option OrthogonalBrownians." + +RelativeItoD::usage = "RelativeItoD[expr] computes ItoD[expr]/expr." + +OrthogonalBrownians::usage = "OrthogonalBrownians is an option for ItoD. The +default setting is OrthogonalBrownians -> True." + +SuppressTime::usage = "SuppressTime is an option for ItoD that specifies +whether to suppress the dependence on time in the output. The default +setting is SuppressTime -> True." + +ItoMake::usage = "ItoMake[x[args], mu, sigma] associates a rule with the +(ultimate) head of the x[args]. The TimeSymbol should be one of the +arguments; for example, ItoMake[x[t], \[Mu], \[Sigma]]. For multiple +Brownians, sigma may be a list." + +ItoMakeFromItoD::usage = "ItoMakeFromItoD[name, expr] calls +ItoMake[x[args], Drift[dx], Diffusion[dx]], where dx is the output from +ItoD. ItoMakeFromItoD passes the option BrownianList to Diffusion." + +IncludeArguments::usage = "IncludeArguments is an option for ItoMake (and +related functions) that specifies whether to include the arguments in the +drift and diffusion specifications. IncludeArguments is only used in +vector versions of ItoMake-related functions." + +RelativeItoMake::usage = "RelativeItoMake[name, mu, sigma] calls +ItoMake[name, name mu, name sigma]." + +RelativeItoMakeFromItoD::usage = "RelativeItoMakeFromItoD[name, expr] calls +ItoMake[name, name Drift[expr], name Diffusion[expr]]. RelativeItoMakeFromItoD +passes the option BrownianList to Diffusion." + +ExponentialItoMake::usage = "ExponentialItoMake[name, mu, sigma] calls +ItoMake[name, name (mu + sigma^2/2), name sigma]." + +ExponentialItoMakeFromItoD::usage = "ExponentialItoMakeFromItoD[name, expr] +calls ItoMake[name (Drift[expr] + (1/2)Diffusion[expr].Diffusion[expr]), +Diffusion[expr]]. ExponentialItoMakeFromItoD passes the option BrownianList +to Diffusion." + +VectorItoMake::usage = "VectorItoMake[name, n] makes a vector of n Ito +processes." + +Drift::usage = "Drift[expr] returns the drift of an Ito process." + +Diffusion::usage = "Diffusion[expr] returns the diffusion of an Ito +process. Diffusion takes the options BrownianList and Scalarize." + +BrownianList::usage = "BrownianList is an option for Diffusion. The default +setting is BrownianList -> Automatic." + +Scalarize::usage = "Scalarize is an option for Diffusion. The default +setting is Scalarize -> True, which specifies that a length-one Diffusion +should be returned as a scalar." + +(* Version 6 fix: + Put OverTilde in ItosLemma` context if not in System` context. *) +OverTilde + +Begin["`Private`"] +(***************** code starts here **********************) + +(***** main engine *****) + +Options[ItoD] = {OrthogonalBrownians -> True, SuppressTime -> True} + +SetAttributes[ItoD, Listable] + +ItoD[expr_, opts___?OptionQ] := + Module[{t, dt, dB, rho, suppress, ortho, zerorule, + dtexpr, brownians, dtime, dbrown, d2brown, timedrift, + diffusion, jensen}, + (* get the global values for these symbols *) + {t, dt, dB, rho} = {TimeSymbol, TimeIncrement, BrownianIncrement, + CorrelationSymbol}; + {suppress, ortho} = {SuppressTime, OrthogonalBrownians} /. + {opts} /. Options[ItoD]; + zerorule = Subscript[dB, _] | dt -> 0; + (* identify the Ito processes *) + dtexpr = expr /. t -> t + dt; + (* find the brownians *) + (* if there are no brownians, make one up *) + brownians = Union[Cases[dtexpr, Subscript[dB, _], {0, Infinity}]]; + If[brownians === {}, brownians = {Subscript[dB, 1]}]; + (* compute the derivatives *) + dtime = D[dtexpr, dt]; + dbrown = D[dtexpr, #]& /@ brownians; + d2brown = D[dbrown, #]& /@ brownians; + (* compute the "ito-taylor series" *) + timedrift = (dtime /. zerorule) dt; + diffusion = (dbrown /. zerorule) . brownians; + jensen = (1/2) * + Expand[brownians . (d2brown /. zerorule) . brownians] /. + {Subscript[dB, _]^2 -> dt, + Subscript[dB, i_] Subscript[dB, j_] -> + If[TrueQ[ortho], + 0, + Subscript[rho, i, j] dt]}; + (* assemble the parts *) + (diffusion + Collect[timedrift + jensen, dt]) /. + If[TrueQ[suppress], f_[t] -> f, {}] + ] + +(* related function to simplify output in special cases *) + +RelativeItoD[expr_, opts___?OptionQ] := + Collect[ItoD[expr, opts]/expr /. + If[TrueQ[SuppressTime /. {opts} /. Options[ItoD]], + (* then *) + f_[TimeSymbol] -> f, + (* else *) + {}], + TimeIncrement, Simplify] + +(***** extractors *****) + +Drift[expr_] := Coefficient[expr, TimeIncrement] + +Diffusion::lost = "BrownianList omitted ``." + +Options[Diffusion] = {BrownianList -> Automatic, Scalarize -> True} + +Diffusion[expr_, opts___?OptionQ] := + Module[{dB, blist, scalar, found, brownians, lost}, + (* get the global value for this symbol *) + dB = BrownianIncrement; + {blist, scalar} = {BrownianList, Scalarize} /. {opts} /. + Options[Diffusion]; + found = Union[Cases[expr, Subscript[dB, _], {0, Infinity}]]; + If[TrueQ[blist === Automatic], + (* then *) + brownians = found, + (* else *) + brownians = blist; + lost = Complement[found, blist]; + If[lost =!= {}, Message[Diffusion::lost, lost]]]; + If[TrueQ[scalar] && Length[brownians] === 1, + (* then *) + Coefficient[expr, First @ brownians], + (* else *) + Coefficient[expr, #]& /@ brownians] + ] + +(***** constructor *****) + +ItoMake::notime = "TimeSymbol `1` does not appear as an argument in `2`." +ItoMake::badhead = "The Head of `1` matches one of `2`, `3`, or `4`." +ItoMake::badarg = "One or more arguments of `1` matches either `2` or `3`." + +(* only used in vector functions (see below) *) +Options[ItoMake] = {IncludeArguments -> False} + +ItoMake[x_[args__], mu_, sig_] := + Module[{t, dt, dB, diffusion, head, lhs}, + (* get the global values for these symbols *) + {t, dt, dB} = {TimeSymbol, TimeIncrement, BrownianIncrement}; + If[FreeQ[{args}, t], + Message[ItoMake::notime, t, x[args]]; Return[$Failed]]; + If[MatchQ[x, t | dt | dB], + Message[ItoMake::badhead, x[args], t, dt, dB]; Return[$Failed]]; + If[MemberQ[{args}, dt | dB, Infinity], + Message[ItoMake::badarg, x[args], dt, dB]; Return[$Failed]]; + diffusion = Switch[sig, + _List, sig . Array[Subscript[dB, #]&, Length[sig]], + _, sig Subscript[dB, 1]]; + (* find the ultimate Head *) + head = FixedPointList[Head, x][[-3]]; + lhs = Block[Evaluate[{head}], + (* construct the pattern and Hold it *) + Hold @ Evaluate[ + If[# === t, # + dt, Pattern[#, Blank[]]]& /@ x[args] + ]]; + (* define the rule and return the SDE *) + (Set @@ Append[lhs, x[args] + mu dt + diffusion]) - x[args] + ] + +(*****************************************************************) +(* ItoMake-related functions to simplify input for special cases *) +(*****************************************************************) + +RelativeItoMake[x_[args__], mu_, sig_] := + ItoMake[x[args], x[args] mu, x[args] sig] + +ExponentialItoMake[x_[args__], mu_, sig_]:= + ItoMake[x[args], x[args] (mu + sig.sig/2) /. Dot -> Times, x[args] sig] + +(* make Ito process from output of ItoD *) + +ItoMakeFromItoD[x_[args__], expr_, opts___?OptionQ] := + With[{diff = Diffusion[expr, opts]}, + ItoMake[x[args], Drift[expr], If[diff === {}, {0}, diff]] + ] + +RelativeItoMakeFromItoD[x_[args__], expr_, opts___?OptionQ] := + ItoMake[x[args], x[args] Drift[expr], + x[args] Diffusion[expr, opts]] + +ExponentialItoMakeFromItoD[x_[args__], expr_, opts___?OptionQ] := + With[{diff = Diffusion[expr, Scalarize -> False, opts]}, + ItoMake[x[args], x[args] (Drift[expr] + (1/2) diff.diff), + x[args] diff] + ] + +(* scalar process with vector browians *) + +ItoMake[x_[args__], mu_, sig_, n_Integer, opts___?OptionQ] := + ItoMake[x[args], ##]& @@ makeargs[x[args], mu, sig, n, opts] + +RelativeItoMake[x_[args__], mu_, sig_, n_Integer, opts___?OptionQ] := + RelativeItoMake[x[args], ##]& @@ makeargs[x[args], mu, sig, n, opts] + +ExponentialItoMake[x_[args__], mu_, sig_, n_Integer, opts___?OptionQ] := + ExponentialItoMake[x[args], ##]& @@ makeargs[x[args], mu, sig, n, opts] + +(* auxiliary function *) +makeargs[x_[args__], mu_, sig_, n_, opts___?OptionQ] := + {mu[x][args], Array[Subscript[sig, #][x][args]&, n]} /. + If[TrueQ[IncludeArguments /. {opts} /. Options[ItoMake]], {}, + f_[x][args] :> f[x]] + +(* vector Ito processes *) + +(* n Brownian motion processes *) +VectorItoMake[x_[args__], 0, 1, n_Integer] := + Table[ItoMake[Subscript[x, i][args], 0, + Table[If[i == j, 1, 0], {j, n}]], {i, n}] + +(* n Ito processes, n Brownians *) +VectorItoMake[x_[args__], mu_, sig_, n_Integer, opts___?OptionQ] := + Table[ItoMake[Subscript[x, i][args], mu, sig, n, opts], {i, n}] + +(* m Ito processes, n Brownians *) +VectorItoMake[x_[args__], mu_, sig_, {m_Integer, n_Integer}, + opts___?OptionQ] := + Table[ItoMake[Subscript[x, i][args], mu, sig, n, opts], {i, m}] + +(* use default symbols for drift and diffusion *) + +(#[x_[args__]] := #[x[args], + Subscript[DriftSymbol, x], Subscript[DiffusionSymbol, x]])& /@ + {ItoMake, RelativeItoMake} + +Options[ExponentialItoMake] = {OverTilde -> True} + +ExponentialItoMake[x_[args__], opts___?OptionQ] := + Module[{tilde, fun}, + tilde = OverTilde /. {opts} /. Options[ExponentialItoMake]; + fun = If[TrueQ[tilde], OverTilde, Identity]; + ExponentialItoMake[x[args], + Subscript[fun[DriftSymbol], x], + Subscript[DiffusionSymbol, x]] + ] + +(#[x_[args__], n_Integer, opts___?OptionQ] := #[x[args], + DriftSymbol, DiffusionSymbol, n, opts])& /@ + {ItoMake, RelativeItoMake, ExponentialItoMake} + +VectorItoMake[x_[args__], n_Integer, opts___?OptionQ] := + VectorItoMake[x[args], DriftSymbol, DiffusionSymbol, n, opts] + +VectorItoMake[x_[args__], {m_Integer, n_Integer}, opts___?OptionQ] := + VectorItoMake[x[args], DriftSymbol, DiffusionSymbol, {m, n}, opts] + +End[] +EndPackage[] diff --git a/MathematicaFiles/Applications/KalmanFilter.m b/MathematicaFiles/Applications/KalmanFilter.m new file mode 100755 index 0000000..7555e8b --- /dev/null +++ b/MathematicaFiles/Applications/KalmanFilter.m @@ -0,0 +1,65 @@ +(* Kalman Filter *) + +(* + transition and measurement equations: + x10 = a + F.x0 + w, where w \sim N(0, Q) + y = b + H.x10 + v, where v \sim N(0, R) + + initialize with prior mean, covariance, and loglikelihood: (m0, P0, LL0) + + predict: + m10 = a + F.m0; + P10 = F.P0.Transpose[F] + Q; + + update: + z = y - (b + H.m10); + Sinv = Inverse[H.P10.Transpose[H] + R]; + K = P10.H.Sinv; + m11 = m10 + K.z; + P11 = P10 - K.(H.P10); + + loglikelihood: + LL1 = LL0 -.5(1/Det[Sinv] + z.Sinv.z) + + *) + +KalmanFilter::usage = "KalmanFilter[{m0, P0}, y, \ +{{a,F},{b,H}}, {Q,R}] returns the list {{m0,P0}, {m1, P1}, ...} \ +with the default setting ComputeLogLikelihood -> False, where \ +{mi, Pi} are the mean (vector) and covariance (matrix) of the \ +state conditional on the data y (a matrix; the list of observations) \ +up through yi. By setting ComputeLogLikelihood -> True, KalmanFilter \ +returns the loglikelihood." + +Options[KalmanFilter] = {ComputeLogLikelihood -> False} + +KalmanFilter[ + {m0_, P0_}, + y_?MatrixQ, + {{a_, F_}, {b_, H_}}, + {Q_, R_}, + opts:OptionsPattern[]] := + If[OptionValue[ComputeLogLikelihood], + Fold[KalmanFilter[##, {{a, F}, {b, H}}, {Q, R}]&, {m0, P0, 0}, y][[-1]] - + (1/2) * Log[2 Pi] * (Times @@ Dimensions[y]), + FoldList[KalmanFilter[##, {{a, F}, {b, H}}, {Q, R}]&, {m0, P0}, y] + ] + +KalmanFilter[{m0_, P0_, LL0_}, y_?VectorQ, {{a_, F_}, {b_, H_}}, {Q_, R_}] := + Module[{m10, P10, z, Sinv, K}, + m10 = a + F.m0; + P10 = F.P0.Transpose[F] + Q; + z = y - (b + H.m10); + Sinv = Inverse[H.P10.Transpose[H] + R]; + K = P10.H.Sinv; + {m10, P10, LL0} + {K.z, -K.(H.P10), (1/2) * (Log[Det[Sinv]] - z.Sinv.z)} + ] + +KalmanFilter[{m0_, P0_}, y_?VectorQ, {{a_, F_}, {b_, H_}}, {Q_, R_}] := + Module[{m10, P10, K}, + m10 = a + F.m0; + P10 = F.P0.Transpose[F] + Q; + K = P10.H.Inverse[H.P10.Transpose[H] + R]; + {m10 + K.(y - (b + H.m10)), P10 - K.(H.P10)} + ] + diff --git a/MathematicaFiles/Applications/Kernel Configuration.nb b/MathematicaFiles/Applications/Kernel Configuration.nb new file mode 100755 index 0000000..92c9318 --- /dev/null +++ b/MathematicaFiles/Applications/Kernel Configuration.nb @@ -0,0 +1,542 @@ +(* Content-type: application/mathematica *) + +(*** Wolfram Notebook File ***) +(* http://www.wolfram.com/nb *) + +(* CreatedBy='Mathematica 6.0' *) + +(*CacheID: 234*) +(* Internal cache information: +NotebookFileLineBreakTest +NotebookFileLineBreakTest +NotebookDataPosition[ 145, 7] +NotebookDataLength[ 18827, 533] +NotebookOptionsPosition[ 17579, 485] +NotebookOutlinePosition[ 17939, 501] +CellTagsIndexPosition[ 17896, 498] +WindowFrame->Normal +ContainsDynamic->False*) + +(* Beginning of Notebook Content *) +Notebook[{ + +Cell[CellGroupData[{ +Cell["Setup", "Section", + CellChangeTimes->{{3.411637868640625*^9, 3.41163786978125*^9}}], + +Cell[BoxData[ + RowBox[{ + RowBox[{"RemoteKernel", "[", + RowBox[{ + RowBox[{"node_Integer", "?", "Positive"}], ",", + RowBox[{"number_:", "1"}]}], "]"}], ":=", "\[IndentingNewLine]", + RowBox[{"With", "[", + RowBox[{ + RowBox[{"{", + RowBox[{"n", "=", + RowBox[{"ToString", "[", "node", "]"}]}], "}"}], ",", + "\[IndentingNewLine]", + RowBox[{ + RowBox[{"\"\<Remote-\>\"", " ", "<>", "n", "<>", "\"\<-\>\"", "<>", + RowBox[{"ToString", "[", "number", "]"}]}], "\[Rule]", + RowBox[{"{", "\[IndentingNewLine]", + RowBox[{ + RowBox[{"\"\<AppendNameToCellLabel\>\"", "\[Rule]", "True"}], ",", + "\[IndentingNewLine]", + RowBox[{"\"\<AutoStartOnLaunch\>\"", "\[Rule]", "False"}], ",", + RowBox[{ + "\"\<MLOpenArguments\>\"", "\[Rule]", + "\"\<-LinkMode Listen -LinkProtocol TCPIP -LinkOptions MLDontInteract\ +\>\""}], ",", "\[IndentingNewLine]", + RowBox[{"\"\<LoginScript\>\"", "\[Rule]", + RowBox[{ + "\"\<\\\"`java`\\\" -jar \\\"`mathssh`\\\" f1mef14@192.168.2.\>\"", "<>", + "n", "<>", + "\"\< math -mathlink -LinkMode Connect -LinkProtocol TCPIP -LinkName \ +\\\"`linkname`\\\" -LinkHost `ipaddress`\>\""}]}]}], "\[IndentingNewLine]", + "}"}]}]}], "]"}]}]], "Input", + CellChangeTimes->{{3.411634633125*^9, 3.411634807734375*^9}, { + 3.41163483990625*^9, 3.41163487059375*^9}, {3.4116349413125*^9, + 3.411635052734375*^9}, {3.411636412890625*^9, 3.411636523328125*^9}, { + 3.411637914078125*^9, 3.411637927171875*^9}, {3.41164245039625*^9, + 3.41164245189625*^9}, {3.411642779786875*^9, 3.411642802911875*^9}, { + 3.4117211805754924`*^9, 3.4117211839433427`*^9}}], + +Cell[BoxData[ + RowBox[{ + RowBox[{"RemoteKernel", "[", "___", "]"}], ":=", + RowBox[{"{", "}"}]}]], "Input", + CellChangeTimes->{{3.411636201078125*^9, 3.411636216515625*^9}}] +}, Open ]], + +Cell[CellGroupData[{ + +Cell["Execute", "Section", + CellChangeTimes->{{3.41163787425*^9, 3.41163787621875*^9}}], + +Cell[BoxData[{ + RowBox[{ + RowBox[{"With", "[", + RowBox[{ + RowBox[{"{", + RowBox[{"n", "=", "4"}], "}"}], ",", + RowBox[{"(*", " ", + RowBox[{ + "set", " ", "this", " ", "for", " ", "the", " ", "number", " ", "of", + " ", "local", " ", "kernels"}], " ", "*)"}], "\[IndentingNewLine]", + RowBox[{"$LocalEvaluatorNames", "=", "\[IndentingNewLine]", + RowBox[{"Table", "[", + RowBox[{ + RowBox[{ + RowBox[{"\"\<Local-\>\"", "<>", + RowBox[{"ToString", "[", "i", "]"}]}], "\[Rule]", + RowBox[{"{", + RowBox[{ + RowBox[{"\"\<AppendNameToCellLabel\>\"", "\[Rule]", "True"}], ",", + RowBox[{"\"\<AutoStartOnLaunch\>\"", "\[Rule]", + RowBox[{"If", "[", + RowBox[{ + RowBox[{"i", "\[Equal]", "1"}], ",", "True", ",", "False"}], + "]"}]}]}], "}"}]}], ",", + RowBox[{"{", + RowBox[{"i", ",", "n"}], "}"}]}], "]"}]}]}], "]"}], ";"}], "\n", + RowBox[{ + RowBox[{"$RemoteEvaluatorNames", "=", + RowBox[{"Table", "[", + RowBox[{ + RowBox[{"RemoteKernel", "[", "n", "]"}], ",", + RowBox[{"{", + RowBox[{"n", ",", + RowBox[{"{", + RowBox[{"3", ",", "4", ",", "5", ",", "7", ",", "9", ",", "10"}], + "}"}]}], "}"}]}], "]"}]}], ";"}], "\n", + RowBox[{ + RowBox[{"$EvaluatorNames", "=", + RowBox[{"Join", "[", + RowBox[{"$LocalEvaluatorNames", ",", "$RemoteEvaluatorNames"}], "]"}]}], + ";"}]}], "Input", + CellChangeTimes->{{3.4116353105*^9, 3.411635337125*^9}, + 3.41163537509375*^9, {3.411637895125*^9, 3.41163790490625*^9}, + 3.411638998828125*^9, {3.41164218077125*^9, 3.411642186615*^9}, { + 3.4117199701068263`*^9, 3.411720120001479*^9}, {3.4117211680707884`*^9, + 3.4117211684138107`*^9}, {3.4132829865224905`*^9, 3.4132829997768354`*^9}}],\ + + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{"Labeled", "[", + RowBox[{ + RowBox[{"Framed", "[", + RowBox[{"Column", "[", + RowBox[{ + RowBox[{"{", + RowBox[{ + RowBox[{"Column", "[", + RowBox[{"$LocalEvaluatorNames", "[", + RowBox[{"[", + RowBox[{"All", ",", "1"}], "]"}], "]"}], "]"}], ",", + RowBox[{"Column", "[", + RowBox[{"$RemoteEvaluatorNames", "[", + RowBox[{"[", + RowBox[{"All", ",", "1"}], "]"}], "]"}], "]"}]}], "}"}], ",", + RowBox[{"Dividers", "\[Rule]", "Center"}]}], "]"}], "]"}], ",", + "\"\<kernels\>\"", ",", "Top"}], "]"}]], "Input", + CellChangeTimes->{{3.411711718984375*^9, 3.4117117889375*^9}}], + +Cell[BoxData[ + InterpretationBox[GridBox[{ + { + TagBox["\<\"kernels\"\>", + "Labeled", + Editable->True, + Selectable->True]}, + { + TagBox[ + TagBox[ + FrameBox[ + TagBox[GridBox[{ + { + TagBox[GridBox[{ + {"\<\"Local-1\"\>"}, + {"\<\"Local-2\"\>"}, + {"\<\"Local-3\"\>"}, + {"\<\"Local-4\"\>"} + }, + ColumnsEqual->False, + GridBoxAlignment->{"Columns" -> {{Left}}}, + + GridBoxItemSize->{ + "Columns" -> {{Automatic}}, "Rows" -> {{Automatic}}}, + RowsEqual->False], + "Column"]}, + { + TagBox[GridBox[{ + {"\<\"Remote-3-1\"\>"}, + {"\<\"Remote-4-1\"\>"}, + {"\<\"Remote-5-1\"\>"}, + {"\<\"Remote-7-1\"\>"}, + {"\<\"Remote-9-1\"\>"}, + {"\<\"Remote-10-1\"\>"} + }, + ColumnsEqual->False, + GridBoxAlignment->{"Columns" -> {{Left}}}, + + GridBoxItemSize->{ + "Columns" -> {{Automatic}}, "Rows" -> {{Automatic}}}, + RowsEqual->False], + "Column"]} + }, + ColumnsEqual->False, + GridBoxAlignment->{"Columns" -> {{Left}}}, + + GridBoxDividers->{ + "Columns" -> {False, {True}, False}, + "Rows" -> {False, {True}, False}}, + + GridBoxItemSize->{ + "Columns" -> {{Automatic}}, "Rows" -> {{Automatic}}}, + RowsEqual->False], + "Column"], + StripOnInput->False], + "Labeled", + Editable->True, + Selectable->True], + "SkipImageSizeLevel"]} + }, + BaselinePosition->{2, 1}, + GridBoxAlignment->{ + "Columns" -> {{Center}}, "ColumnsIndexed" -> {}, "Rows" -> {{Center}}, + "RowsIndexed" -> {}}, + GridBoxItemSize->{ + "Columns" -> {{Automatic}}, "ColumnsIndexed" -> {}, "Rows" -> {{1.}}, + "RowsIndexed" -> {}}], + Labeled[ + Framed[ + Column[{ + Column[{"Local-1", "Local-2", "Local-3", "Local-4"}], + Column[{ + "Remote-3-1", "Remote-4-1", "Remote-5-1", "Remote-7-1", "Remote-9-1", + "Remote-10-1"}]}, Dividers -> Center]], "kernels", Top], + Editable->False, + Selectable->False]], "Output", + CellChangeTimes->{{3.41171172759375*^9, 3.411711789359375*^9}, + 3.4117197073189096`*^9, 3.4117201430453815`*^9, 3.4117211894628754`*^9, + 3.4132830024779577`*^9}] +}, Open ]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{"$LocalEvaluatorNames", "[", + RowBox[{"[", + RowBox[{"1", ",", "1"}], "]"}], "]"}]], "Input", + CellChangeTimes->{{3.4117213327756743`*^9, 3.4117213419316416`*^9}}], + +Cell[BoxData["\<\"Local-1\"\>"], "Output", + CellChangeTimes->{{3.411721338250537*^9, 3.411721342305991*^9}, + 3.413283010220128*^9}] +}, Open ]], + +Cell[BoxData[ + RowBox[{"SetOptions", "[", + RowBox[{"$FrontEnd", ",", + RowBox[{"EvaluatorNames", "\[Rule]", "$EvaluatorNames"}], ",", + RowBox[{"Evaluator", "\[Rule]", + RowBox[{"$LocalEvaluatorNames", "[", + RowBox[{"[", + RowBox[{"1", ",", "1"}], "]"}], "]"}]}]}], "]"}]], "Input", + CellChangeTimes->{{3.41163507884375*^9, 3.411635098296875*^9}, { + 3.4116353820625*^9, 3.411635392546875*^9}, {3.4116389860625*^9, + 3.411638987765625*^9}, {3.411719686944728*^9, 3.4117196930647883`*^9}, + 3.411721348560749*^9}], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{"Row", "[", + RowBox[{"{", + RowBox[{"\"\<Default kernel: \>\"", ",", + RowBox[{"Evaluator", "/.", + RowBox[{"Options", "[", + RowBox[{"$FrontEnd", ",", "Evaluator"}], "]"}]}]}], "}"}], + "]"}]], "Input", + CellChangeTimes->{{3.411711404875*^9, 3.411711409171875*^9}, { + 3.411711819984375*^9, 3.411711851078125*^9}}], + +Cell[BoxData[ + InterpretationBox[ + RowBox[{"\<\"Default kernel: \"\>", + "\[InvisibleSpace]", "\<\"Local-1\"\>"}], + Row[{"Default kernel: ", "Local-1"}]]], "Output", + CellChangeTimes->{ + 3.411711409671875*^9, {3.411711833890625*^9, 3.411711851625*^9}, + 3.4117197177948303`*^9, 3.4117201658082604`*^9, 3.4117213544255595`*^9, + 3.4117214639852095`*^9, 3.4132830147743464`*^9}] +}, Open ]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{"Column", "[", + RowBox[{ + RowBox[{"EvaluatorNames", "/.", + RowBox[{"Options", "[", + RowBox[{"$FrontEnd", ",", "EvaluatorNames"}], "]"}]}], ",", + RowBox[{"Dividers", "\[Rule]", "All"}], ",", + RowBox[{"Spacings", "\[Rule]", "2"}]}], "]"}]], "Input", + CellChangeTimes->{{3.411721517938345*^9, 3.4117215356575594`*^9}}], + +Cell[BoxData[ + TagBox[GridBox[{ + { + RowBox[{"\<\"Local-1\"\>", "\[Rule]", + RowBox[{"{", + RowBox[{ + RowBox[{"\<\"AppendNameToCellLabel\"\>", "\[Rule]", "True"}], ",", + RowBox[{"\<\"AutoStartOnLaunch\"\>", "\[Rule]", "True"}]}], "}"}]}]}, + { + RowBox[{"\<\"Local-2\"\>", "\[Rule]", + RowBox[{"{", + RowBox[{ + RowBox[{"\<\"AppendNameToCellLabel\"\>", "\[Rule]", "True"}], ",", + RowBox[{"\<\"AutoStartOnLaunch\"\>", "\[Rule]", "False"}]}], + "}"}]}]}, + { + RowBox[{"\<\"Local-3\"\>", "\[Rule]", + RowBox[{"{", + RowBox[{ + RowBox[{"\<\"AppendNameToCellLabel\"\>", "\[Rule]", "True"}], ",", + RowBox[{"\<\"AutoStartOnLaunch\"\>", "\[Rule]", "False"}]}], + "}"}]}]}, + { + RowBox[{"\<\"Local-4\"\>", "\[Rule]", + RowBox[{"{", + RowBox[{ + RowBox[{"\<\"AppendNameToCellLabel\"\>", "\[Rule]", "True"}], ",", + RowBox[{"\<\"AutoStartOnLaunch\"\>", "\[Rule]", "False"}]}], + "}"}]}]}, + { + RowBox[{"\<\"Remote-3-1\"\>", "\[Rule]", + RowBox[{"{", + RowBox[{ + RowBox[{"\<\"AppendNameToCellLabel\"\>", "\[Rule]", "True"}], ",", + RowBox[{"\<\"AutoStartOnLaunch\"\>", "\[Rule]", "False"}], ",", + RowBox[{"\<\"MLOpenArguments\"\>", + "\[Rule]", "\<\"-LinkMode Listen -LinkProtocol TCPIP -LinkOptions \ +MLDontInteract\"\>"}], ",", + RowBox[{"\<\"LoginScript\"\>", + "\[Rule]", "\<\"\\\"`java`\\\" -jar \\\"`mathssh`\\\" \ +f1mef14@192.168.2.3 math -mathlink -LinkMode Connect -LinkProtocol TCPIP \ +-LinkName \\\"`linkname`\\\" -LinkHost `ipaddress`\"\>"}]}], "}"}]}]}, + { + RowBox[{"\<\"Remote-4-1\"\>", "\[Rule]", + RowBox[{"{", + RowBox[{ + RowBox[{"\<\"AppendNameToCellLabel\"\>", "\[Rule]", "True"}], ",", + RowBox[{"\<\"AutoStartOnLaunch\"\>", "\[Rule]", "False"}], ",", + RowBox[{"\<\"MLOpenArguments\"\>", + "\[Rule]", "\<\"-LinkMode Listen -LinkProtocol TCPIP -LinkOptions \ +MLDontInteract\"\>"}], ",", + RowBox[{"\<\"LoginScript\"\>", + "\[Rule]", "\<\"\\\"`java`\\\" -jar \\\"`mathssh`\\\" \ +f1mef14@192.168.2.4 math -mathlink -LinkMode Connect -LinkProtocol TCPIP \ +-LinkName \\\"`linkname`\\\" -LinkHost `ipaddress`\"\>"}]}], "}"}]}]}, + { + RowBox[{"\<\"Remote-5-1\"\>", "\[Rule]", + RowBox[{"{", + RowBox[{ + RowBox[{"\<\"AppendNameToCellLabel\"\>", "\[Rule]", "True"}], ",", + RowBox[{"\<\"AutoStartOnLaunch\"\>", "\[Rule]", "False"}], ",", + RowBox[{"\<\"MLOpenArguments\"\>", + "\[Rule]", "\<\"-LinkMode Listen -LinkProtocol TCPIP -LinkOptions \ +MLDontInteract\"\>"}], ",", + RowBox[{"\<\"LoginScript\"\>", + "\[Rule]", "\<\"\\\"`java`\\\" -jar \\\"`mathssh`\\\" \ +f1mef14@192.168.2.5 math -mathlink -LinkMode Connect -LinkProtocol TCPIP \ +-LinkName \\\"`linkname`\\\" -LinkHost `ipaddress`\"\>"}]}], "}"}]}]}, + { + RowBox[{"\<\"Remote-7-1\"\>", "\[Rule]", + RowBox[{"{", + RowBox[{ + RowBox[{"\<\"AppendNameToCellLabel\"\>", "\[Rule]", "True"}], ",", + RowBox[{"\<\"AutoStartOnLaunch\"\>", "\[Rule]", "False"}], ",", + RowBox[{"\<\"MLOpenArguments\"\>", + "\[Rule]", "\<\"-LinkMode Listen -LinkProtocol TCPIP -LinkOptions \ +MLDontInteract\"\>"}], ",", + RowBox[{"\<\"LoginScript\"\>", + "\[Rule]", "\<\"\\\"`java`\\\" -jar \\\"`mathssh`\\\" \ +f1mef14@192.168.2.7 math -mathlink -LinkMode Connect -LinkProtocol TCPIP \ +-LinkName \\\"`linkname`\\\" -LinkHost `ipaddress`\"\>"}]}], "}"}]}]}, + { + RowBox[{"\<\"Remote-9-1\"\>", "\[Rule]", + RowBox[{"{", + RowBox[{ + RowBox[{"\<\"AppendNameToCellLabel\"\>", "\[Rule]", "True"}], ",", + RowBox[{"\<\"AutoStartOnLaunch\"\>", "\[Rule]", "False"}], ",", + RowBox[{"\<\"MLOpenArguments\"\>", + "\[Rule]", "\<\"-LinkMode Listen -LinkProtocol TCPIP -LinkOptions \ +MLDontInteract\"\>"}], ",", + RowBox[{"\<\"LoginScript\"\>", + "\[Rule]", "\<\"\\\"`java`\\\" -jar \\\"`mathssh`\\\" \ +f1mef14@192.168.2.9 math -mathlink -LinkMode Connect -LinkProtocol TCPIP \ +-LinkName \\\"`linkname`\\\" -LinkHost `ipaddress`\"\>"}]}], "}"}]}]}, + { + RowBox[{"\<\"Remote-10-1\"\>", "\[Rule]", + RowBox[{"{", + RowBox[{ + RowBox[{"\<\"AppendNameToCellLabel\"\>", "\[Rule]", "True"}], ",", + RowBox[{"\<\"AutoStartOnLaunch\"\>", "\[Rule]", "False"}], ",", + RowBox[{"\<\"MLOpenArguments\"\>", + "\[Rule]", "\<\"-LinkMode Listen -LinkProtocol TCPIP -LinkOptions \ +MLDontInteract\"\>"}], ",", + RowBox[{"\<\"LoginScript\"\>", + "\[Rule]", "\<\"\\\"`java`\\\" -jar \\\"`mathssh`\\\" \ +f1mef14@192.168.2.10 math -mathlink -LinkMode Connect -LinkProtocol TCPIP \ +-LinkName \\\"`linkname`\\\" -LinkHost `ipaddress`\"\>"}]}], "}"}]}]} + }, + ColumnsEqual->False, + GridBoxAlignment->{"Columns" -> {{Left}}}, + GridBoxDividers->{"Columns" -> {{True}}, "Rows" -> {{True}}}, + GridBoxItemSize->{"Columns" -> {{Automatic}}, "Rows" -> {{Automatic}}}, + GridBoxSpacings->{"Columns" -> {{Automatic}}, "Rows" -> {{2}}}, + RowsEqual->False], + "Column"]], "Output", + CellChangeTimes->{{3.411721523615981*^9, 3.411721547215604*^9}, + 3.413283016501808*^9}] +}, Open ]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{"Column", "[", + RowBox[{ + RowBox[{"Options", "[", + RowBox[{"EvaluationNotebook", "[", "]"}], "]"}], ",", + RowBox[{"Dividers", "\[Rule]", "All"}], ",", + RowBox[{"Spacings", "\[Rule]", "2"}]}], "]"}]], "Input", + CellChangeTimes->{{3.4117209304315224`*^9, 3.411720938955881*^9}, { + 3.411721003806344*^9, 3.4117210062329865`*^9}}], + +Cell[BoxData[ + TagBox[GridBox[{ + { + RowBox[{ + "FrontEndVersion", + "\[Rule]", "\<\"6.0 for Microsoft Windows (32-bit) (June 19, \ +2007)\"\>"}]}, + { + RowBox[{"ShowSelection", "\[Rule]", "True"}]}, + { + RowBox[{"StyleDefinitions", "\[Rule]", "\<\"Default.nb\"\>"}]}, + { + RowBox[{"WindowMargins", "\[Rule]", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"0", ",", "Automatic"}], "}"}], ",", + RowBox[{"{", + RowBox[{"Automatic", ",", "0"}], "}"}]}], "}"}]}]}, + { + RowBox[{"WindowSize", "\[Rule]", + RowBox[{"{", + RowBox[{"869", ",", "885"}], "}"}]}]} + }, + ColumnsEqual->False, + GridBoxAlignment->{"Columns" -> {{Left}}}, + GridBoxDividers->{"Columns" -> {{True}}, "Rows" -> {{True}}}, + GridBoxItemSize->{"Columns" -> {{Automatic}}, "Rows" -> {{Automatic}}}, + GridBoxSpacings->{"Columns" -> {{Automatic}}, "Rows" -> {{2}}}, + RowsEqual->False], + "Column"]], "Output", + CellChangeTimes->{{3.4117209255782375`*^9, 3.411720939484765*^9}, + 3.4117210063263187`*^9, 3.4117213576855206`*^9, 3.4117215494149075`*^9, + 3.41328302099321*^9}] +}, Open ]], + +Cell[CellGroupData[{ + +Cell["Example: Create notebook with given kernel", "Subsection", + CellChangeTimes->{{3.4116379764375*^9, 3.41163799096875*^9}}], + +Cell[BoxData[ + RowBox[{ + RowBox[{"CreateDocument", "[", + RowBox[{ + RowBox[{"{", "}"}], ",", + RowBox[{"Evaluator", "\[Rule]", "\"\<Remote-3-1\>\""}]}], "]"}], + ";"}]], "Input", + CellChangeTimes->{{3.4116428281775*^9, 3.411642831724375*^9}, + 3.4117116316875*^9, 3.4117208425435123`*^9, {3.411721424101379*^9, + 3.4117214260043225`*^9}, {3.4132830347500887`*^9, 3.413283035299736*^9}}], + +Cell[BoxData[ + RowBox[{ + RowBox[{"CreateDocument", "[", + RowBox[{ + RowBox[{"{", "}"}], ",", + RowBox[{"Evaluator", "\[Rule]", "\"\<Local-1\>\""}]}], "]"}], + ";"}]], "Input", + CellChangeTimes->{{3.4116428281775*^9, 3.411642831724375*^9}, { + 3.4117116316875*^9, 3.411711652359375*^9}, {3.4117214288119445`*^9, + 3.4117214291706963`*^9}}] +}, Open ]] +}, Open ]] +}, +WindowSize->{869, 885}, +WindowMargins->{{0, Automatic}, {Automatic, 0}}, +ShowSelection->True, +FrontEndVersion->"6.0 for Microsoft Windows (32-bit) (June 19, 2007)", +StyleDefinitions->"Default.nb" +] +(* End of Notebook Content *) + +(* Internal cache information *) +(*CellTagsOutline +CellTagsIndex->{} +*) +(*CellTagsIndex +CellTagsIndex->{} +*) +(*NotebookFileOutline +Notebook[{ +Cell[CellGroupData[{ +Cell[590, 23, 89, 1, 88, "Section"], +Cell[682, 26, 1682, 36, 295, "Input"], +Cell[2367, 64, 175, 4, 52, "Input"] +}, Open ]], +Cell[CellGroupData[{ +Cell[2579, 73, 87, 1, 88, "Section"], +Cell[2669, 76, 1820, 45, 185, "Input"], +Cell[CellGroupData[{ +Cell[4516, 126, 689, 18, 119, "Input"], +Cell[5208, 146, 2521, 78, 231, "Output"] +}, Open ]], +Cell[CellGroupData[{ +Cell[7766, 229, 190, 4, 52, "Input"], +Cell[7959, 235, 134, 2, 52, "Output"] +}, Open ]], +Cell[8108, 240, 536, 11, 75, "Input"], +Cell[CellGroupData[{ +Cell[8669, 255, 355, 9, 52, "Input"], +Cell[9027, 266, 385, 8, 52, "Output"] +}, Open ]], +Cell[CellGroupData[{ +Cell[9449, 279, 357, 8, 75, "Input"], +Cell[9809, 289, 5274, 116, 1090, "Output"] +}, Open ]], +Cell[CellGroupData[{ +Cell[15120, 410, 364, 8, 52, "Input"], +Cell[15487, 420, 1145, 33, 224, "Output"] +}, Open ]], +Cell[CellGroupData[{ +Cell[16669, 458, 127, 1, 46, "Subsection"], +Cell[16799, 461, 400, 9, 52, "Input"], +Cell[17202, 472, 349, 9, 35, "Input"] +}, Open ]] +}, Open ]] +} +] +*) + +(* End of internal cache information *) diff --git a/MathematicaFiles/Applications/MaxEntSimplexDistribution.m b/MathematicaFiles/Applications/MaxEntSimplexDistribution.m new file mode 100755 index 0000000..15b4cc2 --- /dev/null +++ b/MathematicaFiles/Applications/MaxEntSimplexDistribution.m @@ -0,0 +1,350 @@ +(* :Title: MaxEntSimplexDistribution *) + +(* :Author: Mark Fisher *) + +(* :Version: 0.1 November 2005 *) + +(* :Mathematica Version: 5.0 + I use "f @@@ expr" syntax for "Apply[f, expr, {1}]". + Maybe other things as well. *) + +(* :Summary: Maximum entropy distribution on a simplex *) + +(* :References: + Mark Fisher (2005) Maximum Entropy on a Simplex: An Expository Note. + Unpublished + E. T. Jaynes (2003) Probability Theory: The Logic of Science. + Cambridge University Press. +*) + +(* :Notes: + There are a few tricky issues regarding LambdaOK and LambdaLimit dealing + with precision. As a consequence, PartitionFunction[{1, 1.}] returns an + infinite-precision result while PartitionFunction[{1., 1}] a machine- + precision result. + + At some point I might try to compile + Mean[MaxEntSimplexDistribution[lambda]] for cases that fail LambdaOK. + *) + +BeginPackage["MaxEntSimplexDistribution`", { + "Utilities`FilterOptions`"}] + +MaxEntSimplexDistribution::usage = "MaxEntSimplexDistribution[\[Lambda]] +represents the maximum entropy distribution on a simplex given the +parameter vector \[Lambda]. PDF[MaxEntSimplexDistribution[\[Lambda]], x] +returns the PDF, where x is a vector of the same length as \[Lambda]. +PDF[MaxEntSimplexDistribution[\[Lambda]], x, pos] returns the marginal PDF +for x[[pos]], where pos is a list of positions and \[Lambda] and x are from +the joint distribution. PDF[MaxEntSimplexDistribution[\[Lambda]], x, sum] +returns the conditional PDF for x (and its associated \[Lambda]), given the +sum of conditioning variables. Mean, Covariance, Variance, +StandardDeviation, and Entropy are defined for +MaxEntSimplexDistribution[\[Lambda]], as are Random and RandomArray. If +Length[\[Lambda]] > 1, then Random calls MaxEntSimplexGibbs[\[Lambda], 2 * +Length[\[Lambda]]] and returns the last draw; otherwise, Random computes +iid draws directly." + +PartitionFunction::usage = "PartitionFunction[\[Lambda]] returns the +partition function given the vector lambda. PartitionFunction[b][\[Lambda]] +computes the partition function with an upper bound of b. PartitionFunction +is the normalization factor for PDF[MaxEntSimplexDistribution[\[Lambda]], +x]." + +MaxEntSimplexGibbs::usage = "MaxEntSimplexGibbs[\[Lambda], n] returns n +draws from the Gibbs sampler for the maximum entropy distribution on a +simplex given the vector lambda. The sampler is initialized with +Mean[MaxEntSimplexDistribution[\[Lambda]]]. If Length[\[Lambda]] == 1, then +the draws are iid from the univariate distribution." + +MaxEntSimplexInvertMean::usage = "MaxEntSimplexInvertMean[mean] returns the +\[Lambda] vector associated with the given mean. Options can be passed to +FindRoot, which MaxEntSimplexInvertMean calls. In addition, +MaxEntSimplexInvertMean takes the option StartingValues which can be used +to pass a list of starting values to FindRoot. The default setting is +StartingValues -> Automatic." + +Entropy::usage = "Entropy[MaxEntSimplexDistribution[\[Lambda]]] returns the +entropy of the given distribution, where \[Lambda] is a vector." + +LambdaOK::usage = "LambdaOK[\[Lambda]] returns True if no component of +\[Lambda] is zero and if no two components are equal. LambdaOK is used to +trap arguments to a number of functions related to maximum entropy." + +LambdaLimit::usage = "LambdaLimit[\[Lambda], fun] computes the limit for +fun[\[Lambda]], where fun is typically PartitionFunction or its gradient or +Hessian." + +MeanOK::usage = "MeanOK[mean] returns True if no component of mean equals +(1 - Tr[mean]) and if no two components are equal. MeanOK is used to trap +arguments to MaxEntSimplexInvertMean." + +MeanLimit::usage = "MeanLimit[mean] computes the limit for when mean fails +MeanOK. MeanLimit is called by MaxEntSimplexInvertMean." + +StartingValues::usage = "StartingValues is an option for +MaxEntSimplexInvertMean. The default value is StartingValues -> Automatic, +which produces Range[Length[num]] where num is the number of paramters to +estimated." + +Begin["`Private`"] + +(* PartitionFunction, LambdaOK, and LambdaLimit *) + +PartitionFunction[b_][lambda_List?LambdaOK] := + With[{n = Length[lambda]}, + 1/Product[lambda[[i]], {i, n}] - + Sum[Exp[-b lambda[[i]]]/ + (lambda[[i]] * + Product[If[j==i, 1, (lambda[[j]] - lambda[[i]])], {j, n}]), + {i, n}] + ] + +PartitionFunction[b_][lambda:{0 ..}] := + With[{n = Length[lambda]}, + b^n/n! + ] + +PartitionFunction[b_][lambda_List] := + LambdaLimit[lambda, PartitionFunction[b]] + +PartitionFunction[lambda_List] := PartitionFunction[1][lambda] + +PartitionFunction[_][__] := $Failed + +LambdaOK[lambda_] := + With[{u = Union[lambda, SameTest -> Equal]}, + Length[u] == Length[lambda] && + FreeQ[Thread[u == 0], True] + ] + +(* this function takes care of LambdaOK exceptions *) +LambdaLimit[lambda_List, fun_] := + Module[{lam, x, ulam, upos, groups, rules, zpos}, + lam = Array[x, Length[lambda]]; + ulam = Union[lambda, SameTest -> Equal]; + upos = Function[u, Flatten[Position[lambda, _?(#==u&)]]] /@ ulam; + groups = Map[x, DeleteCases[{Rest[#], First[#]} & /@ upos, {_, {}}], {-1}]; + rules = (Rule @@@ Flatten[(Thread /@ groups), 1]); + zpos = Position[ulam, _?(# == 0&)]; + If[zpos != {}, AppendTo[rules, lam[[ upos[[ zpos[[1, 1]] ]][[1]] ]] -> 0]]; + Fold[Limit[#1, #2] &, fun[lam], rules] /. Thread[lam -> lambda] + ] + +(* PDF: joint, conditional, and marginal *) + +MaxEntSimplexDistribution /: +PDF[MaxEntSimplexDistribution[lambda_List], x_List] /; + Length[lambda] == Length[x] := + Exp[-lambda.x]/PartitionFunction[lambda] + +(* marginal distribution of x[[pos]] *) +MaxEntSimplexDistribution /: +PDF[MaxEntSimplexDistribution[lambda_List?LambdaOK], x_List, pos_List] /; + Length[lambda] == Length[x] := + Exp[-lambda[[pos]].x[[pos]]] * + PartitionFunction[1 - Tr[x[[pos]]]][ Complement[lambda, lambda[[pos]]] ] / + PartitionFunction[lambda] + +MaxEntSimplexDistribution /: +PDF[MaxEntSimplexDistribution[lambda_List], x_List, pos_List] /; + Length[lambda] == Length[x] := + Exp[-lambda[[pos]].x[[pos]]] * + LambdaLimit[lambda, + PartitionFunction[1 - Tr[x[[pos]]]][ Complement[#, #[[pos]]] ] / + PartitionFunction[#]&] + +(* conditional on the sum of the conditioning variables *) +MaxEntSimplexDistribution /: +PDF[MaxEntSimplexDistribution[lambda_List], x_List, sum_] /; + Length[lambda] == Length[x] := + Exp[-lambda.x]/PartitionFunction[1 - sum][lambda] + +MaxEntSimplexDistribution /: +PDF[MaxEntSimplexDistribution[__], __] := $Failed + + +(* Mean, Covariance, Variance, StandardDeviation, Entropy *) + +MaxEntSimplexDistribution /: +Mean[MaxEntSimplexDistribution[{}]] := {} + +MaxEntSimplexDistribution /: +Mean[MaxEntSimplexDistribution[lambda_List?LambdaOK]] := + Module[{lam, x}, + lam = Array[x, Length[lambda]]; + -D[Log[PartitionFunction[lam]], {lam}] /. Thread[lam -> lambda] + ] + +MaxEntSimplexDistribution /: +Mean[MaxEntSimplexDistribution[lambda_List]] := + LambdaLimit[lambda, -D[Log[PartitionFunction[#]], {#}]&] + +(* compiled for machine precision lambda *) +MaxEntSimplexDistribution /: +Mean[MaxEntSimplexDistribution[lambda_List?LambdaOK]] /; + VectorQ[lambda, NumericQ] && + Precision[lambda] == MachinePrecision := + compiledmean[Length[lambda]] @@ lambda + +MaxEntSimplexDistribution /: +Covariance[MaxEntSimplexDistribution[lambda_List?LambdaOK]] := + Module[{lam, x}, + lam = Array[x, Length[lambda]]; + D[Log[PartitionFunction[lam]], {lam}, {lam}] /. Thread[lam -> lambda] + ] + +MaxEntSimplexDistribution /: +Covariance[MaxEntSimplexDistribution[lambda_List]] := + LambdaLimit[lambda, D[Log[PartitionFunction[#]], {#}, {#}]&] + +MaxEntSimplexDistribution /: +Variance[MaxEntSimplexDistribution[lambda_List]] := + Transpose[Covariance[MaxEntSimplexDistribution[lambda]], {1,1}] + +MaxEntSimplexDistribution /: +StandardDeviation[MaxEntSimplexDistribution[lambda_List]] := + Sqrt[Variance[MaxEntSimplexDistribution[lambda]]] + +MaxEntSimplexDistribution /: +Entropy[MaxEntSimplexDistribution[lambda_List]] := + lambda.Mean[MaxEntSimplexDistribution[lambda]] + + Log[PartitionFunction[lambda]] + +MaxEntSimplexDistribution /: +(Mean | Covariance | Variance | StandardDeviation | + Entropy)[MaxEntSimplexDistribution[__]] := $Failed + +(* MaxEntSimplexInvertMean *) + +(* numerically solve for lambda given the mean vector *) +Options[MaxEntSimplexInvertMean] = {StartingValues -> Automatic} + +MaxEntSimplexInvertMean[{}, ___] := {} + +MaxEntSimplexInvertMean[mean_?(VectorQ[#, NumericQ]&), opts___?OptionQ] /; + MeanOK[mean] := + Module[{len = Length[mean], lam, x, fropts, start}, + fropts = FilterOptions[FindRoot, opts]; + start = StartingValues /. {opts} /. Options[MaxEntSimplexInvertMean]; + If[start == Automatic, start = Range[len]]; + If[Length[start] != len, Return[$Failed]]; + lam = Array[x, len]; + lam /. FindRoot[ + Mean[MaxEntSimplexDistribution[lam]] - mean, + Evaluate[Sequence @@ Transpose[{lam, start}], fropts] + ] + ] + +MaxEntSimplexInvertMean[mean_?(VectorQ[#, NumericQ]&), opts___?OptionQ] := + MeanLimit[mean, opts] + +MeanLimit[mean_List, opts___?OptionQ] := + Module[{lam, x, umean, upos, groups, rules, zpos, temp, + utemp, frpos, len, fropts, start, meanexpr, meandiff}, + lam = Array[x, Length[mean]]; + umean = Union[mean, SameTest -> Equal]; + upos = Function[u, Flatten[Position[mean, _?(#==u&)]]] /@ umean; + groups = Map[x, DeleteCases[{Rest[#], First[#]} & /@ upos, {_, {}}], {-1}]; + rules = (Rule @@@ Flatten[(Thread /@ groups), 1]); + zpos = Position[umean, _?(# == 1-Tr[mean]&)]; + If[zpos != {}, AppendTo[rules, lam[[ upos[[ zpos[[1, 1]] ]][[1]] ]] -> 0]]; + temp = lam //. rules; + utemp = Union[DeleteCases[temp, 0]]; + frpos = utemp /. x[i_] -> i; + If[frpos == {}, + (* then *) + temp, + (* else *) + len = Length[utemp]; + fropts = FilterOptions[FindRoot, opts]; + start = StartingValues /. {opts} /. Options[MaxEntSimplexInvertMean]; + If[start == Automatic, start = Range[len]]; + If[Length[start] != len, Return[$Failed]]; + meanexpr = Fold[Limit[#1, #2] &, + -D[Log[PartitionFunction[lam]], {lam}], rules]/. Thread[lam -> temp]; + meandiff = meanexpr - mean; + temp /. FindRoot[Evaluate @ meandiff[[frpos]], + Evaluate @ Transpose[{utemp, start}], Evaluate @ fropts] + ] + ] + +MaxEntSimplexInvertMean[__] := $Failed + +MeanOK[mean_] := + With[{u = Union[mean, SameTest -> Equal]}, + Length[u] == Length[mean] && + FreeQ[Thread[u == (1 - Tr[mean])], True] + ] + +(* RandomReal, Gibbs sampler *) + +(* univariate *) +MaxEntSimplexGibbs[{lambda_?NumericQ}, n_Integer?Positive] := + Table[maxent[lambda], {n}] + +MaxEntSimplexDistribution /: +RandomReal[MaxEntSimplexDistribution[{lambda_?NumericQ}]] := + maxent[lambda] + +MaxEntSimplexDistribution /: +RandomReal[MaxEntSimplexDistribution[{lambda_?NumericQ}], b_] := + maxentb[lambda, 1-b] + +MaxEntSimplexDistribution /: +RandomReal[MaxEntSimplexDistribution[{lambda_?NumericQ}], n_Integer?Positive] := + Table[maxent[lambda], {n}] + +(* multivariate; initialized with + Mean[MaxEntSimplexDistribution[lambda]] *) +MaxEntSimplexGibbs[lambda_?(VectorQ[#, NumericQ]&), n_Integer?Positive] /; + LambdaOK[lambda] := + Module[{slist, rmat, len}, + len = Length[lambda]; + (* used compiled version for efficiency *) + slist = compiledmean[len] @@ lambda; + rmat = Table[If[i == j, 0, 1], {i, len}, {j, len}]; + Table[ + slist[[i]] = maxentb[lambda[[i]], 1 - slist . rmat[[i]]], + {n}, {i, len}] + ] /; Length[lambda] > 1 + +MaxEntSimplexGibbs[__] := $Failed + +(* calls MaxEntSimplexGibbs 2* Length[lambda] times + and returns the last one *) +MaxEntSimplexDistribution /: +RandomReal[MaxEntSimplexDistribution[lambda_?(VectorQ[#, NumericQ]&)]] := + Last @ MaxEntSimplexGibbs[lambda, 2 * Length[lambda]] + +MaxEntSimplexDistribution /: +RandomReal[MaxEntSimplexDistribution[lambda_?(VectorQ[#, NumericQ]&)], + n_Integer?Positive] := + Table[Last @ MaxEntSimplexGibbs[lambda, 2 * Length[lambda]], {n}] + +maxent = Compile[{lam}, + With[{u = Random[]}, + If[Abs[lam] < 0.0001, + u - 0.5 * u * (1 - u) * lam, + -(Log[1 + (E^(-lam) - 1) * u]/lam) + ] + ]] + +maxentb = Compile[{lam, b}, + With[{u = Random[]}, + If[Abs[lam] < 0.0001, + b * u - 0.5 * b^2 * u * (1 - u) * lam, + -(Log[1 + (E^(-b * lam) - 1) * u]/lam) + ] + ]] + +(* for numerical efficiency *) +compiledmean[i_Integer?Positive] := + compiledmean[i] = (* memoize *) + Block[{x}, + Compile @@ {Array[x, i], + Mean[MaxEntSimplexDistribution[Array[x, i]]]} + ] + +End[] +EndPackage[] diff --git a/MathematicaFiles/Applications/Metropolis.m b/MathematicaFiles/Applications/Metropolis.m new file mode 100755 index 0000000..60e4413 --- /dev/null +++ b/MathematicaFiles/Applications/Metropolis.m @@ -0,0 +1,69 @@ +(* :Mathematica Version: 6 *) + +(* need UnevenPartition *) +<<Version6`OddsandEnds` + +(* this allows for earlier versions *) +If[$VersionNumber >= 6, + (* then *) + randomNormal[n_] := RandomReal[NormalDistribution[], n]; + randomUniform[] := RandomReal[], + (* else *) + randomNormal[n_] := RandomArray[NormalDistribution[0,1], n]; + randomUniform[] := Random[] + ] + +Options[Metropolis] = { + RegionFunction -> (True &), + LogLikelihood -> True, + DiscardValues -> True + } + +Metropolis::badblocks = "The dimensions of the covariance \ +blocks are not consistent with the length of the argument vector." + +Metropolis::usage = "Metropolis[kernelfun, x0, covarianceblocks, n]. \ +Options include RegionFunction, Loglikelihood, and DiscardValues." + +Metropolis[ + kernelfun_, + x_List, + covarianceblocks:{__List}, + n_Integer?Positive, + opts___?OptionQ + ] := + Module[{blocklengths, x0, v0, choleskyblocks, + regionfun, notloglike, discard, x1, v1, fx1}, + blocklengths = Length /@ covarianceblocks; + If[Length[x] != Plus @@ blocklengths, + Message[Metropolis::badblocks]; Return[$Failed] + ]; + x0 = UnevenPartition[x, blocklengths]; + v0 = kernelfun[x]; + choleskyblocks = CholeskyDecomposition[(Transpose[#]+#)/2]& /@ + covarianceblocks; + regionfun = RegionFunction /. {opts} /. Options[Metropolis]; + notloglike = ! TrueQ[LogLikelihood /. {opts} /. Options[Metropolis]]; + discard = TrueQ[DiscardValues /. {opts} /. Options[Metropolis]]; + Table[ + Table[ + x1 = x0; + x1[[j]] += (randomNormal[blocklengths[[j]]].choleskyblocks[[j]]); + fx1 = Flatten[x1]; + If[TrueQ[regionfun[fx1]], + (* then inbounds *) + v1 = kernelfun[fx1]; + If[notloglike, v1 = Log[v1]]; + If[v1 >= Log[randomUniform[]] + v0, + (* then accept new point *) + x0 = x1; v0 = v1 + ] + ], + {j, Length[choleskyblocks]}]; + If[discard, Flatten[x0], {Flatten[x0], v0}], + {n}] + ] + +AcceptanceRates[mc_?MatrixQ] := + N[ (Length[Split[#1]]& /@ Transpose[mc])/Length[mc] ] + diff --git a/MathematicaFiles/Applications/MetropolisMCMC.m b/MathematicaFiles/Applications/MetropolisMCMC.m new file mode 100755 index 0000000..10130b7 --- /dev/null +++ b/MathematicaFiles/Applications/MetropolisMCMC.m @@ -0,0 +1,545 @@ +(* :Title: RandomWalkMetropolis *) + +(* :Author: Mark Fisher *) + +(* :Date: June 2007 *) + +(* :Mathematica Version: 6 *) + +(* :Package Version: 2.0 + Modified for Version 6.0 June 2007, completely revamped. +*) + +(* :Summary: +This package implements the (random-walk) Metropolis version of the Markov +Chain Monte Carlo (MCMC) algorithm. MCMC algorithms are used to draw from +probability distributions. The function BridgeEstimate can be used to compute +the normalizing constant. +*) + +(* :Discussion: +The Markov Chain is implemented via NestList. The "state" vector is the +parameter vector with the function value appended. The iterated function +generates a proposal and returns the proposal (and its value) if its value +is greater than a random fraction of the current state value. Otherwise +the current state is returned. Proposals are generated by random-walk +Gaussian or T-distributions. +*) + +(* :References: + RandomWalkMetropolis implements Agorithm A.29 (p. 288) in + Robert, Christian P. and George Casella (2004) Monte Carlo + Statistical Methods, Second Edition, Springer. + + For the Gelfand-Dey method of marginal likelihood estimation, see + Koop, Gary (2003) Bayesian Econometrics, John Wiley & Sons, + pp. 104-106. + For additional details, Koop refers the reader to + Geweke, John (1999) Using Simulation Methods for Bayesian Econometric + Models: Inference, Development, and Communication (with discussion + and rejoinder), Econometric Reviews, 18, pp. 1-126. +*) + +BeginPackage["RandomWalkMetropolis`", + {"Utilities`FilterOptions`", "MultivariateStatistics`"}] + +RandomWalkMetropolis::usage = +"RandomWalkMetropolis[f, x0, step, nDraws, nThin, nBurn] \ +returns nDraws steps of a Markov Chain Monte Carlo (MCMC) simulation from \ +the function f computed via the random-walk Metropolis algorithm, \ +beginning at the vector x0 of starting values, where step is a scalar or \ +vector (with the same dimension as start) that represents standard \ +deviations. Alternatively, step can be a covariance matrix. \ +nThin specifies the amount of \"thinning\" to do, outputing every \ +nThin-th draw. nBurn specifies the number of draws to discard \ +from the beginning during the \"burn-in\" period. (Thus the total number \ +of function evaluations is nBurn + nThin * nDraws.) The function \ +f must have the head Function and take a single vector argument; \ +in addition, it should return the log of the kernel value unless the \ +option LogLikelihood is set to False. MetropolisMCMC also takes the \ +options DiscardValues and BooleanFunction. (See the usage notes.)" + +LogLikelihood::usage = +"LogLikelihood is an option for RandomWalkMetropolis that \ +specifies whether the function returns values proportional to the \ +likelihood or to the loglikelihood. The default setting is \ +LogLikelihood -> True." + +BooleanFunction::usage = +"BooleanFunction is an option for RandomWalkMetropolis \ +that specifies a function that returns True of False to be applied to the \ +proposal prior to evaluating the likelihood function. For example, \ +BooleanFunction -> (And@@Thread[#>=0]&). The default setting is \ +BooleanFunction -> (True&). The option BooleanFunction is provided for \ +use with LogLikelihood -> True, in order to avoid taking the log of zero." + +RegroupOutput::usage = +"RegroupOutput is an option for RandomWalkMetropolis \ +which specifies whether to regroup each row of the output from {x__, v_} \ +to {{x}, v}. The default is RegroupOutput -> True." + +DiscardValues::usage = +"DiscardValues is an option for RandomWalkMetropolis \ +which specifies whether to discard the appended values. The default \ +setting is DiscardValues -> True." + +CompilePatterns::usage = +"CompilePatterns is an option for \ +RandomWalkMetropolis which specifies the list of patterns supplied to \ +Compile (as its third argument). These patterns specify the return types \ +of external calls. The default setting is CompilePatterns -> {}." + +DegreesOfFreedom::usage = +"DegreesOfFreedom is an option for \ +RandomWalkMetropolis which specifies the number of degrees of freedom for \ +the proposal distribution. The default setting is DegreesOfFreedom -> \ +\[Infinity] which specifies the Gaussian distribution. Additional valid \ +settings are any positive integer. For example, DegreesOfFreedom -> 1 \ +specifies the Cauchy distribtuion (i.e., t distribtion with 1 degree of \ +freedom)." + +AcceptanceRate::usage = +"AcceptanceRate[mc] computes, the fraction of times \ +the proposal is accepted; namely, N[Length[Split[mc]]/Length[mc]]." + +MHMFunction::usage = +"MHMFunction[mean, cov, p] returns a function that \ +can be used to compute the normalization constant where mean is the \ +vector of means of the MCMC parameter matrix from a \ +Markov Chain Monte Carlo simulation and cov is the covariance matrix. \ +The third argument p specifies \ +the truncation for the Gaussian in terms of a p-value. Alternatively, one \ +may specify MHMFunction[mcmc, p], where mcmc is the MCMC parameter matrix \ +of parameters." + +MHMEstimate::usage = +"MHMEstimate[mcmcdata, p] returns the Gelfand-Dey estimate of the \ +normalization constant given the Markov Chain Monte Carlo simulation, \ +where mcmcdata is produced by MetropolisMCMC with the option \ +DiscardValues -> False and where the truncation point is controlled \ +by the \"p-value\" p. MHMEsitmate takes the option LogLikelihood, \ +which specifies whether the likelihood values are in logs. \ +The default value is LogLikelihood -> False. If the option is \ +specified the value for p must also be specified." + +MarginalLikelihoodMuller::usage = "MarginalLikelihoodMuller[mc, fun, {m, \ +V}, n (,opts)] computes the log of the marginal likelihood from the MCMC \ +output mc generated from the kernel fun using n draws from a Gaussian \ +weighting distribution with mean m and covariance matrix V. (The method is \ +due to Ulrich K. M�ller.) Since the draws from the Gaussian distribution \ +are independent, n can be substantially less than the length of mc. Each \ +row of mc output contains the draw and the associated kernel value. (The \ +kernel values are assumed to be in logs unless the option LogLikelihood -> \ +False is specified.) A function (returning True|False) that determines the \ +bounds of the parameter space can be specified via the option \ +BooleanFunction." + +MullerFunction::usage = "MullerFunction[rf, rg][logC] is a helper function \ +called by MarginalLikelihoodMuller. MullerFunction calls the compiled \ +ComputeListSum." + +MarginalLikelihoodMuller::badbounds = "The interval `1` does not contain +zero. Returning the value closest to zero. Try using a larger number of +draws from the weighting distribution." + +MarginalLikelihoodCJ::usage = "MarginalLikelihoodCJ[mc, f, V, xstar, n] \ +computes the log of the marginal likelihood of the data given the \ +Metropolis output mc according to Chib-Jeliazkov method, where f is the \ +kernel of the posterior, V is the covariance matrix of the random-walk \ +Gaussian proposal density, xstar is the point at which to estimate the \ +density of the poseterior, and n is the number of draws of the Gaussian \ +weighting function." + +BridgeEstimate::usage = "BridgeEstimate[{f1, f2}, {draws1, draws2}, psi] \ +computes the bridge estimate of Log[c1/c2] where ci is the normalizing \ +constant for the kernel Exp[fi] given the draws from the two distributions. \ +The parameter psi should be set the the ratio of the number of \ +\"independent\" draws in draws1 relative to the number of independent draws \ +in draws2. (When in doubt, set it to 1.) BridgeEstimate[mc, fun, {m, V}, \ +{n, psi}] computes the bridge estimate of the log of the marginal \ +likelihood given the posterior kernel fun using the MCMC output mc; n draws \ +are made from the Gaussian weighting function which is centered at m with \ +covariance matrix V." + +BridgeEstimate::badbounds = "The interval `1` does not contain zero. +Returning the value closest to zero. Try using a larger number of draws +from the weighting distribution." + +BridgeEstimate::nodraws = "There are no draws from test distribution in +bounds." + +BridgeEstimate::ndraws = "There are `1` draws from test distribution in +bounds." + +BridgeEstimatePowerFamily::usage = "BridgeEstimatePowerFamily[{z1, z2}, {k, \ +A}] returns the bridge estimate of the log of the ratio of normalizing \ +constants given the lists of log differences z1 and z2 and the power family \ +parameters k and A." + +BridgeEstimateFromMetropolis::usage = "BridgeEstimateFromMetropolis[{fun, \ +start, stepsize, mcsteps}, {m, V}, {n, psi} (, opts)]." + +ForceDraws::usage = "ForceDraws is an option for BridgeEstimate which \ +specifies whether to enforce the number of draws from the Gaussian \ +to equal the number specified. This is an issue if draws can be \ +discarded as out-of-bounds. With the default setting ForceDraws -> \ +True, successive draws are made until the number specified are obtained." + +Begin["Private`"] + +AcceptanceRate[mc_List] := N[Length[Split[mc]]/Length[mc]] + +RandomWalkMetropolis::baddf = "DegreesOfFreedom must be either a positive \ +integer or \[Infinity]." + +Options[RandomWalkMetropolis] = { + LogLikelihood -> True, + BooleanFunction -> (True&), + DiscardValues -> True, + RegroupOutput -> True, + DegreesOfFreedom -> \[Infinity], + CompilePatterns -> {} + } + +RandomWalkMetropolis[ + fun_Function, + start_?(VectorQ[#, NumericQ]&), + stepSize_, + nDraws_Integer?Positive, + nThin_Integer:1, + nBurn_Integer:0, + opts___?OptionQ] := + Module[{log, discard, regroup, patt, df, boole, + k, chol, logfun, sfun, nfun, sv, mc}, + {log, discard, regroup, patt, df, boole} = {LogLikelihood, DiscardValues, + RegroupOutput, CompilePatterns, DegreesOfFreedom, BooleanFunction} /. + {opts} /. Options[RandomWalkMetropolis]; + If[Not[(IntegerQ[df] && df > 0) || df === Infinity], + Message[RandomWalkMetropolis::baddf, df]; Return[$Failed]]; + k = Length[start]; + chol = CholeskyDecomposition[ + Switch[ + TensorRank[stepSize], + 0, stepSize^2 * IdentityMatrix[k], + 1, DiagonalMatrix[stepSize^2], + 2, stepsize (* covariance matrix *) + ]]; + sfun = AssembleStepFunction[chol, k, df]; + logfun = If[TrueQ[log], fun, Log[fun[#]]&]; + nfun = AssembleNestFunction[logfun, boole, sfun]; + sv = Append[start, logfun[start]]; + mc = CompileNestFunction[nfun, sv, nDraws, nThin, nBurn, patt][]; + If[TrueQ[discard], mc[[All, ;;-2]], + If[TrueQ[regroup], Through[{Most, Last}[#]] & /@ mc, mc] + ] + ] + +RandomWalkMetropolis[__] := $Failed + +AssembleStepFunction[chol_, k_, df_] := + Switch[df, + Infinity, (* normal proposal *) + Function[{}, + Table[Sqrt[-2 Log[RandomReal[]]] Cos[2 Pi RandomReal[]], {k}].chol + ], + _, (* t proposal *) + Function[{}, + (1/Sqrt[(#.#)&[ + Table[Sqrt[-2 Log[RandomReal[]]] Cos[2 Pi RandomReal[]], {df}]]/df] * + Table[Sqrt[-2 Log[RandomReal[]]] Cos[2 Pi RandomReal[]], {k}]).chol + ] + ] + +AssembleNestFunction[vfun_, bfun_, sfun_] := + Function[sv, + Module[{p, pval}, + p = Most[sv] + sfun[]; + If[bfun[p], + pval = vfun[p]; + If[pval >= Last[sv] + Log[RandomReal[]], + Append[p, pval], + sv], + sv] + ]] + +CompileNestFunction[nfun_, start_, nDraws_, nThin_, nBurn_, patt_] := + Compile[{}, (* no args *) + Rest @ + NestList[ + Nest[nfun, #, nThin]&, + Nest[nfun, start, nBurn], + nDraws], + patt] + + +(***** BridgeEstimate *****) + +Options[BridgeEstimate] = { + BooleanFunction -> (True &), + LogLikelihood -> True, + ForceDraws -> True + } + +BridgeEstimate[mc_, fun_, {m_List, V_List}, {n_Integer, psi_?NumericQ}, + opts___?OptionQ] /; + (Dimensions[mc][[-1]] == 2 && + MatrixQ[mc[[All, 1]], NumericQ] && + VectorQ[mc[[All, 2]], NumericQ]) := + Module[{bfun, loglike, force, k, t, ran, logf, logg, + fOnMC, gOnMC, fOnRan, gOnRan, z1, z2}, + bfun = BooleanFunction /. {opts} /. Options[BridgeEstimate]; + loglike = TrueQ[LogLikelihood /. {opts} /. Options[BridgeEstimate]]; + force = TrueQ[ForceDraws /. {opts} /. Options[BridgeEstimate]]; + If[force, + (* then *) + ran = Table[ + While[ + t = RandomReal[MultinormalDistribution[m, V]]; + !bfun[t]]; + t, + {n}], + (* else *) + ran = Select[RandomReal[MultinormalDistribution[m, V], n], bfun[#]&]; + If[Length[ran] == 0, Message[BridgeEstimate::nodraws]; Return[$Failed]]; + Message[BridgeEstimate::ndraws, Length[ran]]; + ]; + logf = If[loglike, fun, Log[fun[#]] &]; + k = Length[m]; + logg = With[{S = Inverse[V], const = -Log[(2Pi)^(k/2)Sqrt[Det[V]]]}, + Compile[{{z, _Real, 1}}, const - (z - m).S.(z - m)/2] + ]; + fOnMC = If[loglike, mc[[All, 2]], Log[mc[[All, 2]]]]; + gOnMC = logg /@ mc[[All, 1]]; + fOnRan = If[bfun @ #, logf @ #, -$MaxMachineNumber] & /@ ran; + gOnRan = logg /@ ran; + z1 = fOnMC - gOnMC; + z2 = gOnRan - fOnRan; + BridgeEstimate[{z1, z2}, psi, opts] + ] + +BridgeEstimate[{f1_, f2_}, {draws1_List, draws2_List}, psi_?NumericQ, + opts___?OptionQ] := + With[{ + z1 = (f1[#] - f2[#])& /@ draws1, + z2 = (f2[#] - f1[#])& /@ draws2 + }, + BridgeEstimate[{z1, z2}, psi, opts] + ] + +BridgeEstimate[{z1_List, z2_List}, psi_?NumericQ, opts___?OptionQ] := + Block[{x}, + {w1, w2} = {z1, z2}; + (* Print[StringForm["Starting value: `1`", + NumberForm[LogRatioStartingValue[z1, z2], {6,4}]]]; *) + x /. FindRoot[ + BridgeFunction[z1, z2, psi][x], + {x, LogRatioStartingValue[z1, z2]}, + FilterOptions[FindRoot, opts] // Evaluate] + ] + +BridgeFunction[z1_, z2_, psi_][x_?NumericQ] := + BridgeFunctionCompiled[x, psi, z1, z2] + +(* trap for non machine precsion numbers *) +BridgeFunctionCompiled = + With[{max = Log[$MaxMachineNumber]}, + Compile[{ + {x, _Real, 0}, + {psi, _Real, 0}, + {z1, _Real, 1}, + {z2, _Real, 1}}, + Module[{ + len1 = Length[z1], + len2 = Length[z2], + t = 0. + }, + Sum[ + t = z2[[j]] - x; + If[t < max, + 1/(psi + Exp[t]), + 0], + {j, len2}]/len2 - + Sum[ + t = z1[[j]] + x; + If[t < max, + 1/(1 + psi * Exp[t]), + 0], + {j, len1}]/len1 + ]]] + +(* provide starting value for FindRoot *) +LogRatioStartingValue[z1_, z2_] := + BridgeEstimatePowerFamily[{z1, z2}, {1, 1}] + +BridgeEstimatePowerFamily[{z1_, z2_}, {k_, A_}] := + With[{t = A^(1/k)}, + Log[Mean[(t + Exp[#/k])^(-k)& /@ z1]/ + Mean[(1 + t * Exp[#/k])^(-k)& /@ z2]] + ] + +BridgeEstimateFromMetropolis[ + {fun_, start_, stepsize_, mcsteps_}, + {m_, V_}, {n_, psi_}, opts___] := + Module[{mc}, + mc = MetropolisMCMC[fun, start, stepsize, mcsteps, opts, + LogLikelihood -> True, ReturnValues -> True]; + (* Print[StringForm["Acceptance Rate: `1`", + NumberForm[AcceptanceRate[mc], {3,3}]]]; *) + BridgeEstimate[mc, fun, {m, V}, {n, psi}, opts, LogLikelihood -> True] + ] + +(* Modified Harnomonic Mean (a.k.a. Gelfand-Dey) *) + +MHMEstimate[mc_, p_:(.01)] /; + (Dimensions[mc][[-1]] == 2 && + MatrixQ[mc[[All, 1]], NumericQ] && (* parameters *) + VectorQ[mc[[All, 2]], NumericQ]) := (* values *) + 1/Mean[ + (MHMFunction[mc[[All, 1]], p] /@ mc[[All, 1]])/mc[[All, 2]] + ] + +Options[MHMEstimate] = {LogLikelihood -> False} + +MHMEstimate[mc_, p_:(.01), opts___?OptionQ] /; + (Dimensions[mc][[-1]] == 2 && + MatrixQ[mc[[All, 1]], NumericQ] && (* parameters *) + VectorQ[mc[[All, 2]], NumericQ]) := (* values *) + With[{vals = If[ + TrueQ[LogLikelihood /. {opts} /. Options[MHMEstimate]], + Exp[mc[[All, 2]]], + mc[[All, 2]]]}, + 1/Mean[ + (MHMFunction[mc[[All, 1]], p] /@ mc[[All, 1]])/vals + ] + ] + +MHMFunction[mc_?(MatrixQ[#, NumericQ]&), p_:(.01)] := + MakeMHMFunction[##, p]& @@ MCMeanAndCovariance[mc] + +MHMFunction[___] := $Failed + +MHMEstimate[___] := $Failed + +MCMeanAndCovariance[mc_?(MatrixQ[#, NumericQ]&)] := + {First[#], Rest[#]}& @ MCMeanCov[mc] + +MCMeanCov = Compile[{{mc, _Real, 2}}, + Module[{ + len = Length[mc], + data = Transpose[mc], + mean = {1.}, + centered = {{1.}}, + cov = {{1.}} + }, + mean = (Plus @@@ data)/len; + centered = data - mean; + cov = (centered.Transpose[centered])/len; + cov = (cov + Transpose[cov])/2; + Prepend[cov, mean] + ]]; + +MakeMHMFunction[mean_, cov_, p_:(.01)] := + With[{ + n = Length[mean], + inv = Inverse[cov] + }, + With[{ + const = N @ 1/(Sqrt[(2*Pi)^n * Det[cov]] * (1-p)), + invGamma = N @ 2*InverseGammaRegularized[n/2, 0, 1 - p] + }, + Compile[{{vec, _Real, 1}}, + With[{ + quad = (mean - vec).inv.(mean - vec) + }, + If[quad <= invGamma, Exp[-quad/2]const, 0] + ]]]] + +(***** MarginalLikelihoodMuller *****) +(* Ulrich K. M�ller's method for computing the constant of integration *) + +Options[MarginalLikelihoodMuller] = + {BooleanFunction -> (True &), LogLikelihood -> True} + +MarginalLikelihoodMuller[mc_, fun_, {m_, V_}, n_Integer, opts___?OptionQ] /; + (Dimensions[mc][[-1]] == 2 && + MatrixQ[mc[[All, 1]], NumericQ] && + VectorQ[mc[[All, 2]], NumericQ]) := + Module[{fropts, bfun, loglike, k, ran, logf, logg, + fOnMC, gOnMC, fOnRan, gOnRan, rf, rg, lo, hi, mlo, mhi, cf}, + fropts = FilterOptions[FindRoot, opts]; + bfun = BooleanFunction /. {opts} /. Options[MarginalLikelihoodMuller]; + loglike = TrueQ[LogLikelihood /. {opts} /. Options[MarginalLikelihoodMuller]]; + k = Length[m]; + ran = RandomArray[MultinormalDistribution[m, V], n]; + logf = If[loglike, fun, Log[fun[#]] &]; + logg = With[{S = Inverse[V], const = -Log[(2Pi)^(k/2)Sqrt[Det[V]]]}, + Compile[{{z, _Real, 1}}, const - (z - m).S.(z - m)/2] + ]; + fOnMC = If[loglike, mc[[All, 2]], Log[mc[[All, 2]]]]; + gOnMC = logg /@ mc[[All, 1]]; + fOnRan = If[bfun @ #, logf @ #, -$MaxMachineNumber] & /@ ran; + gOnRan = logg /@ ran; + rf = Sort[gOnMC - fOnMC]; + rg = Sort[fOnRan - gOnRan]; + lo = -rf[[-1]]; + hi = rg[[-1]]; + {mlo, mhi} = MullerFunction[rf, rg] /@ {lo, hi}; + If[mlo <= 0 <= mhi, + (* then: zero is in bounds *) + Block[{x}, x /. FindRoot[ + MullerFunction[rf, rg][x], + {x, .45*lo + .55*hi, .55*lo + .45*hi, lo, hi}, + fropts // Evaluate]], + (* else: zero is out of bounds *) + Message[MarginalLikelihoodMuller::badbounds, {mlo, mhi}]; + If[mlo > 0, lo, hi]] + ] + +(* rf and rg are sorted logs of ratios *) +MullerFunction[rf_, rg_][x_?NumericQ] := + ComputeListSum[-x, rg] - ComputeListSum[x, rf] + +(* the list is in logs and has been sorted *) +ComputeListSum = + Compile[{ + {x, _Real, 0}, + {list, _Real, 1}}, + Module[{ + t = 0., + sum = 0., + len = Length[list] + }, + Catch[ + Do[ + t = list[[i]] + x; + If[t < 0, + sum += 1 - Exp[t], + Throw[sum/len] + ], + {i, len}]; + sum/len] + ]]; + + +(***** Chib-Jeliazkov method *****) + +MarginalLikelihoodCJ[mc_, fun_, V_, xstar_, n_] := + Module[{ran, valstar, alphavals, qfun, qvals, num, den}, + ran = RandomArray[MultinormalDistribution[xstar, V], n]; + valstar = fun[xstar]; + alphavals = Min[0, valstar - #] & /@ mc[[All, 2]]; + qfun = With[{ + m = xstar, + S = Inverse[V], + const = -Log[(2Pi)^(Length[xstar]/2)Sqrt[Det[V]]]}, + Compile[{{z, _Real, 1}}, const - (z - m).S.(z - m)/2] + ]; + qvals = qfun /@ mc[[All, 1]]; + num = Mean[Exp[alphavals + qvals]]; + den = Mean[Exp[Min[0, fun[#] - valstar] & /@ ran]]; + valstar - Log[num/den] + ] + + +End[] +EndPackage[] \ No newline at end of file diff --git a/MathematicaFiles/Applications/MetropolisStep.nb b/MathematicaFiles/Applications/MetropolisStep.nb new file mode 100755 index 0000000..2a4a17e --- /dev/null +++ b/MathematicaFiles/Applications/MetropolisStep.nb @@ -0,0 +1,1221 @@ +(* Content-type: application/mathematica *) + +(*** Wolfram Notebook File ***) +(* http://www.wolfram.com/nb *) + +(* CreatedBy='Mathematica 6.0' *) + +(*CacheID: 234*) +(* Internal cache information: +NotebookFileLineBreakTest +NotebookFileLineBreakTest +NotebookDataPosition[ 145, 7] +NotebookDataLength[ 54664, 1212] +NotebookOptionsPosition[ 52862, 1148] +NotebookOutlinePosition[ 53379, 1170] +CellTagsIndexPosition[ 53293, 1165] +WindowFrame->Normal +ContainsDynamic->False*) + +(* Beginning of Notebook Content *) +Notebook[{ +Cell[BoxData[ + RowBox[{"<<", "Version6`Metropolis`"}]], "Input", + CellChangeTimes->{{3.37616950425*^9, 3.376169514546875*^9}}], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{"?", "Metropolis"}]], "Input", + CellChangeTimes->{{3.37616951653125*^9, 3.37616951925*^9}}], + +Cell[BoxData[ + RowBox[{ + StyleBox["\<\"Metropolis[kernelfun, x0, covarianceblocks, n]. Options \ +include RegionFunction, Loglikelihood, and DiscardValues.\"\>", "MSG"], " ", + ButtonBox[ + StyleBox["\[RightSkeleton]", "SR"], + Active->True, + BaseStyle->"Link", + ButtonData->"paclet:Global/ref/Metropolis"]}]], "Print", "PrintUsage", + CellChangeTimes->{3.376249446046875*^9}, + CellTags->"Info3376231445-5207814"] +}, Open ]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{"<<", "BinnedKernelDensity`"}]], "Input", + CellChangeTimes->{{3.37613255946875*^9, 3.37613256584375*^9}}], + +Cell[BoxData[ + RowBox[{ + RowBox[{"General", "::", "\<\"obspkg\"\>"}], + RowBox[{ + ":", " "}], "\<\"\\!\\(\\\"Statistics`DataManipulation`\\\"\\) is now \ +obsolete. The legacy version being loaded may conflict with current \ +Mathematica functionality. See the Compatibility Guide for updating \ +information. \\!\\(\\*ButtonBox[\\\"\[RightSkeleton]\\\", \ +ButtonStyle->\\\"MessageLink\\\", ButtonFrame->None, ButtonData:>{\\\"System`\ +\\\", \\\"General\\\", \\\"obspkg\\\"}, ButtonNote -> \ +\\\"General::obspkg\\\"]\\)\"\>"}]], "Message", "MSG", + CellChangeTimes->{3.376132566234375*^9, 3.376137028421875*^9, + 3.3762935423125*^9}], + +Cell[BoxData[ + RowBox[{ + RowBox[{"Graphics", "::", "\<\"obspkg\"\>"}], + RowBox[{ + ":", " "}], "\<\"\\!\\(\\\"Graphics`Graphics`\\\"\\) is now obsolete. The \ +legacy version being loaded may conflict with current Mathematica \ +functionality. See the Compatibility Guide for updating information. \ +\\!\\(\\*ButtonBox[\\\"\[RightSkeleton]\\\", \ +ButtonStyle->\\\"MessageLink\\\", ButtonFrame->None, ButtonData:>{\\\"System`\ +\\\", \\\"Graphics\\\", \\\"obspkg\\\"}, ButtonNote -> \\\"Graphics::obspkg\\\ +\"]\\)\"\>"}]], "Message", "MSG", + CellChangeTimes->{3.376132566234375*^9, 3.376137028421875*^9, + 3.376293542328125*^9}], + +Cell[BoxData[ + RowBox[{ + RowBox[{"Colors", "::", "\<\"obspkg\"\>"}], + RowBox[{ + ":", " "}], "\<\"\\!\\(\\\"Graphics`Colors`\\\"\\) is now obsolete. The \ +legacy version being loaded may conflict with current Mathematica \ +functionality. See the Compatibility Guide for updating information. \ +\\!\\(\\*ButtonBox[\\\"\[RightSkeleton]\\\", \ +ButtonStyle->\\\"MessageLink\\\", ButtonFrame->None, \ +ButtonData:>{\\\"Graphics`Colors`\\\", \\\"Colors\\\", \\\"obspkg\\\"}, \ +ButtonNote -> \\\"Graphics`Colors`Colors::obspkg\\\"]\\)\"\>"}]], "Message", \ +"MSG", + CellChangeTimes->{3.376132566234375*^9, 3.376137028421875*^9, + 3.3762935425625*^9}], + +Cell[BoxData[ + RowBox[{ + RowBox[{"ContourPlot3D", "::", "\<\"obslt\"\>"}], + RowBox[{ + ":", " "}], "\<\"The functionality previously provided by ContourPlot3D.m \ +is now superseded by the ContourPlot3D and ListContourPlot3D kernel \ +functions. The package Graphics`ContourPlot3D` is obsolete. Note the use of \ +DataRange in the place of old MeshRange functionality and the new default \ +setting of Contours -> 3. \\!\\(\\*ButtonBox[\\\"\[RightSkeleton]\\\", \ +ButtonStyle->\\\"MessageLink\\\", ButtonFrame->None, \ +ButtonData:>{\\\"System`.`\\\", \\\"ContourPlot3D\\\", \\\"obslt\\\"}, \ +ButtonNote -> \\\"ContourPlot3D::obslt\\\"]\\)\"\>"}]], "Message", "MSG", + CellChangeTimes->{3.376132566234375*^9, 3.376137028421875*^9, + 3.37629354315625*^9}], + +Cell[BoxData[ + RowBox[{ + RowBox[{"General", "::", "\<\"obspkg\"\>"}], + RowBox[{ + ":", " "}], "\<\"\\!\\(\\\"Statistics`DescriptiveStatistics`\\\"\\) is now \ +obsolete. The legacy version being loaded may conflict with current \ +Mathematica functionality. See the Compatibility Guide for updating \ +information. \\!\\(\\*ButtonBox[\\\"\[RightSkeleton]\\\", \ +ButtonStyle->\\\"MessageLink\\\", ButtonFrame->None, ButtonData:>{\\\"System`\ +\\\", \\\"General\\\", \\\"obspkg\\\"}, ButtonNote -> \ +\\\"General::obspkg\\\"]\\)\"\>"}]], "Message", "MSG", + CellChangeTimes->{3.376132566234375*^9, 3.376137028421875*^9, + 3.376293543171875*^9}], + +Cell[BoxData[ + RowBox[{ + RowBox[{"CoefficientOfVariation", "::", "\<\"shdw\"\>"}], + RowBox[{ + ":", " "}], "\<\"Symbol \\!\\(\\\"CoefficientOfVariation\\\"\\) appears in \ +multiple contexts \\!\\({\\\"Statistics`DescriptiveStatistics`\\\", \ +\\\"RegressionCommon`\\\"}\\); definitions in context \ +\\!\\(\\\"Statistics`DescriptiveStatistics`\\\"\\) may shadow or be shadowed \ +by other definitions. \\!\\(\\*ButtonBox[\\\"\[RightSkeleton]\\\", \ +ButtonStyle->\\\"MessageLink\\\", ButtonFrame->None, \ +ButtonData:>{\\\"Statistics`DescriptiveStatistics`\\\", \ +\\\"CoefficientOfVariation\\\", \\\"shdw\\\"}, ButtonNote -> \ +\\\"Statistics`DescriptiveStatistics`CoefficientOfVariation::shdw\\\"]\\)\"\>\ +"}]], "Message", "MSG", + CellChangeTimes->{3.376132566234375*^9, 3.376137028421875*^9, + 3.3762935431875*^9}] +}, Closed]], + +Cell[BoxData[ + RowBox[{"<<", "MultivariateStatistics`"}]], "Input", + CellChangeTimes->{{3.376091144421875*^9, 3.376091246734375*^9}, { + 3.376091312703125*^9, 3.376091316515625*^9}}], + +Cell[BoxData[ + RowBox[{"Clear", "[", "kernelfun", "]"}]], "Input", + CellChangeTimes->{{3.376249915984375*^9, 3.376249919375*^9}}], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{"kernelfun", "=", + RowBox[{ + RowBox[{ + RowBox[{"-", + RowBox[{"#", ".", "#"}]}], "/", "2"}], "&"}]}]], "Input", + CellChangeTimes->{{3.376131080796875*^9, 3.3761311766875*^9}, { + 3.376132495921875*^9, 3.376132503140625*^9}, {3.376132941046875*^9, + 3.3761329428125*^9}, {3.37613317390625*^9, 3.376133186546875*^9}, { + 3.376150801765625*^9, 3.37615080340625*^9}, {3.376151587375*^9, + 3.3761515888125*^9}, {3.376249913859375*^9, 3.376249924984375*^9}}], + +Cell[BoxData[ + RowBox[{ + RowBox[{"-", + FractionBox[ + RowBox[{"#1", ".", "#1"}], "2"]}], "&"}]], "Output", + CellChangeTimes->{{3.376131134359375*^9, 3.376131177203125*^9}, { + 3.376132498625*^9, 3.376132503546875*^9}, 3.376132943453125*^9, + 3.376133190890625*^9, 3.376137030578125*^9, 3.376150804*^9, + 3.376151589203125*^9, 3.376249450265625*^9, {3.376249923484375*^9, + 3.376249925421875*^9}}] +}, Open ]], + +Cell[BoxData[ + RowBox[{ + RowBox[{"covblocks", "=", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"1", ",", ".5"}], "}"}], ",", + RowBox[{"{", + RowBox[{".5", ",", "1"}], "}"}]}], "}"}], ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2", ",", + RowBox[{"-", ".8"}]}], "}"}], ",", + RowBox[{"{", + RowBox[{ + RowBox[{"-", ".8"}], ",", "1"}], "}"}]}], "}"}], ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"1", ",", "0", ",", ".2"}], "}"}], ",", + RowBox[{"{", + RowBox[{"0", ",", "2", ",", "0"}], "}"}], ",", + RowBox[{"{", + RowBox[{".2", ",", "0", ",", "2"}], "}"}]}], "}"}]}], "}"}]}], + ";"}]], "Input", + CellChangeTimes->{{3.37613371434375*^9, 3.376133728140625*^9}}], + +Cell[BoxData[ + RowBox[{ + RowBox[{"covblocks", "=", + RowBox[{"Table", "[", + RowBox[{ + RowBox[{"{", + RowBox[{"{", "1", "}"}], "}"}], ",", + RowBox[{"{", "100", "}"}]}], "]"}]}], ";"}]], "Input", + CellChangeTimes->{{3.376166568328125*^9, 3.376166601828125*^9}, { + 3.376167701125*^9, 3.37616770203125*^9}, {3.376292527390625*^9, + 3.376292539171875*^9}}], + +Cell[BoxData[ + RowBox[{ + RowBox[{"covblocks", "=", + RowBox[{"{", + RowBox[{"IdentityMatrix", "[", "100", "]"}], "}"}]}], ";"}]], "Input", + CellChangeTimes->{{3.37629254075*^9, 3.376292555203125*^9}, { + 3.376308788796875*^9, 3.37630878909375*^9}}], + +Cell[CellGroupData[{ + +Cell[BoxData[{ + RowBox[{ + RowBox[{"blocklengths", "=", + RowBox[{"Length", "/@", "covblocks"}]}], ";"}], "\n", + RowBox[{ + RowBox[{"x0", "=", + RowBox[{"RandomReal", "[", + RowBox[{ + RowBox[{"NormalDistribution", "[", "]"}], ",", + RowBox[{"Tr", "[", "blocklengths", "]"}]}], "]"}]}], ";"}], "\n", + RowBox[{ + RowBox[{"v0", "=", + RowBox[{"kernelfun", "[", "x0", "]"}]}], ";"}], "\[IndentingNewLine]", + RowBox[{ + RowBox[{"regionfun", "=", + RowBox[{"True", "&"}]}], ";"}], "\[IndentingNewLine]", + RowBox[{"regionfun", "[", "x0", "]"}]}], "Input", + CellChangeTimes->{{3.3761312244375*^9, 3.376131241328125*^9}, { + 3.3761316039375*^9, 3.37613160959375*^9}, {3.376131646203125*^9, + 3.376131652734375*^9}, 3.376131730890625*^9, {3.376132097703125*^9, + 3.376132113640625*^9}, {3.376132257859375*^9, 3.376132266078125*^9}, { + 3.37613234153125*^9, 3.37613236353125*^9}, {3.37613240096875*^9, + 3.3761324093125*^9}, 3.37613315446875*^9, {3.376133215765625*^9, + 3.376133251375*^9}, {3.376133721828125*^9, 3.376133723765625*^9}, { + 3.376148188625*^9, 3.376148200703125*^9}, {3.376148647890625*^9, + 3.376148654890625*^9}, {3.376150807203125*^9, 3.37615080803125*^9}, { + 3.37615155334375*^9, 3.37615159128125*^9}, 3.37615163178125*^9, { + 3.376167743375*^9, 3.3761677551875*^9}, {3.376234604203125*^9, + 3.37623460940625*^9}, {3.376234945734375*^9, 3.376234948640625*^9}, { + 3.376249417421875*^9, 3.376249424328125*^9}}], + +Cell[BoxData["True"], "Output", + CellChangeTimes->{ + 3.376148655796875*^9, 3.3761500781875*^9, {3.376150366953125*^9, + 3.376150384*^9}, 3.3761508095625*^9, 3.37615159353125*^9, + 3.376151636703125*^9, {3.376166595421875*^9, 3.37616660390625*^9}, + 3.376167704765625*^9, 3.37616775575*^9, 3.376234579203125*^9, + 3.376234612734375*^9, 3.376234949*^9, 3.376249454328125*^9, + 3.376249928265625*^9, 3.376250030625*^9, 3.37629255734375*^9, + 3.376308770421875*^9}] +}, Open ]], + +Cell[CellGroupData[{ + +Cell[BoxData[{ + RowBox[{ + RowBox[{"(", + RowBox[{ + RowBox[{"mc", "=", + RowBox[{"Metropolis", "[", + RowBox[{"kernelfun", ",", "x0", ",", "covblocks", ",", + SuperscriptBox["10", "3"]}], "]"}]}], ";"}], ")"}], "//", + "Timing"}], "\[IndentingNewLine]", + RowBox[{"AcceptanceRates", "[", "mc", "]"}]}], "Input", + CellChangeTimes->{{3.376154138734375*^9, 3.376154157328125*^9}, { + 3.37615421221875*^9, 3.376154214828125*^9}, {3.376154311390625*^9, + 3.376154322875*^9}, {3.376154671890625*^9, 3.3761548241875*^9}, { + 3.376165173375*^9, 3.37616517709375*^9}, {3.376165279390625*^9, + 3.376165282796875*^9}, {3.3761664210625*^9, 3.376166431484375*^9}, { + 3.376166498375*^9, 3.376166509453125*^9}, {3.376166613546875*^9, + 3.376166613875*^9}, {3.3761670356875*^9, 3.37616704278125*^9}, + 3.376167715390625*^9, {3.37616777903125*^9, 3.37616778225*^9}, { + 3.376167819625*^9, 3.376167827984375*^9}, {3.37623462365625*^9, + 3.376234645859375*^9}, {3.376234911765625*^9, 3.376234912765625*^9}, { + 3.376235233671875*^9, 3.376235235171875*^9}, {3.376249412703125*^9, + 3.3762494133125*^9}, 3.376249560171875*^9, 3.376249779734375*^9, + 3.3762499426875*^9, 3.3762502816875*^9, {3.37625031396875*^9, + 3.376250322578125*^9}, 3.376308935265625*^9}], + +Cell[BoxData[ + RowBox[{"{", + RowBox[{"4.297000000000004`", ",", "Null"}], "}"}]], "Output", + CellChangeTimes->{ + 3.37616528346875*^9, {3.3761664268125*^9, 3.376166433046875*^9}, + 3.376166511328125*^9, 3.376166617609375*^9, {3.37616703975*^9, + 3.37616704621875*^9}, 3.376167715703125*^9, {3.3761677685*^9, + 3.37616778725*^9}, 3.37616787496875*^9, 3.376234582203125*^9, { + 3.376234617359375*^9, 3.376234648046875*^9}, 3.3762349145625*^9, + 3.376234954609375*^9, {3.376235237*^9, 3.376235243328125*^9}, + 3.376249460890625*^9, 3.376249506640625*^9, 3.3762495603125*^9, + 3.37624959778125*^9, 3.376249719625*^9, 3.37624978015625*^9, + 3.376249855078125*^9, {3.376249936671875*^9, 3.376249960296875*^9}, { + 3.3762500325625*^9, 3.376250052296875*^9}, {3.376250246453125*^9, + 3.376250324203125*^9}, 3.376292560125*^9, {3.37629264896875*^9, + 3.37629265128125*^9}, 3.3763088188125*^9, {3.376308935796875*^9, + 3.376308945390625*^9}}], + +Cell[BoxData[ + RowBox[{"{", + RowBox[{ + "0.713`", ",", "0.702`", ",", "0.728`", ",", "0.718`", ",", "0.702`", ",", + "0.674`", ",", "0.686`", ",", "0.712`", ",", "0.711`", ",", "0.704`", ",", + "0.727`", ",", "0.691`", ",", "0.698`", ",", "0.7`", ",", "0.705`", ",", + "0.717`", ",", "0.706`", ",", "0.707`", ",", "0.697`", ",", "0.692`", ",", + "0.715`", ",", "0.695`", ",", "0.688`", ",", "0.712`", ",", "0.698`", ",", + "0.685`", ",", "0.696`", ",", "0.704`", ",", "0.692`", ",", "0.716`", ",", + "0.701`", ",", "0.707`", ",", "0.714`", ",", "0.692`", ",", "0.722`", ",", + "0.719`", ",", "0.725`", ",", "0.708`", ",", "0.709`", ",", "0.704`", ",", + "0.7`", ",", "0.69`", ",", "0.706`", ",", "0.696`", ",", "0.697`", ",", + "0.71`", ",", "0.701`", ",", "0.702`", ",", "0.707`", ",", "0.695`", ",", + "0.697`", ",", "0.709`", ",", "0.708`", ",", "0.714`", ",", "0.683`", ",", + "0.709`", ",", "0.705`", ",", "0.701`", ",", "0.698`", ",", "0.704`", ",", + "0.71`", ",", "0.698`", ",", "0.701`", ",", "0.689`", ",", "0.718`", ",", + "0.718`", ",", "0.707`", ",", "0.71`", ",", "0.73`", ",", "0.723`", ",", + "0.687`", ",", "0.72`", ",", "0.709`", ",", "0.7`", ",", "0.73`", ",", + "0.686`", ",", "0.686`", ",", "0.708`", ",", "0.72`", ",", "0.728`", ",", + "0.689`", ",", "0.712`", ",", "0.704`", ",", "0.699`", ",", "0.699`", ",", + "0.727`", ",", "0.706`", ",", "0.701`", ",", "0.697`", ",", "0.721`", ",", + "0.726`", ",", "0.729`", ",", "0.711`", ",", "0.692`", ",", "0.729`", ",", + "0.717`", ",", "0.706`", ",", "0.728`", ",", "0.713`", ",", "0.704`"}], + "}"}]], "Output", + CellChangeTimes->{ + 3.37616528346875*^9, {3.3761664268125*^9, 3.376166433046875*^9}, + 3.376166511328125*^9, 3.376166617609375*^9, {3.37616703975*^9, + 3.37616704621875*^9}, 3.376167715703125*^9, {3.3761677685*^9, + 3.37616778725*^9}, 3.37616787496875*^9, 3.376234582203125*^9, { + 3.376234617359375*^9, 3.376234648046875*^9}, 3.3762349145625*^9, + 3.376234954609375*^9, {3.376235237*^9, 3.376235243328125*^9}, + 3.376249460890625*^9, 3.376249506640625*^9, 3.3762495603125*^9, + 3.37624959778125*^9, 3.376249719625*^9, 3.37624978015625*^9, + 3.376249855078125*^9, {3.376249936671875*^9, 3.376249960296875*^9}, { + 3.3762500325625*^9, 3.376250052296875*^9}, {3.376250246453125*^9, + 3.376250324203125*^9}, 3.376292560125*^9, {3.37629264896875*^9, + 3.37629265128125*^9}, 3.3763088188125*^9, {3.376308935796875*^9, + 3.3763089454375*^9}}] +}, Open ]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{"Show", "[", + RowBox[{"Table", "[", + RowBox[{ + RowBox[{"Histogram", "[", + RowBox[{ + RowBox[{"mc", "[", + RowBox[{"[", + RowBox[{"All", ",", "i"}], "]"}], "]"}], ",", "40", ",", + RowBox[{"AspectRatio", "\[Rule]", ".6"}]}], "]"}], ",", + RowBox[{"{", + RowBox[{"i", ",", + RowBox[{"Length", "[", "x0", "]"}]}], "}"}]}], "]"}], "]"}]], "Input", + CellChangeTimes->{{3.376166629796875*^9, 3.376166684734375*^9}, { + 3.376167062078125*^9, 3.376167067890625*^9}, {3.37616788184375*^9, + 3.376167888640625*^9}, {3.37623465378125*^9, 3.376234661671875*^9}, + 3.376235247671875*^9, {3.376235362046875*^9, 3.376235380546875*^9}}], + +Cell[BoxData[ + GraphicsBox[{{ + LineBox[{{-3.1989984901846467`, 0}, {-3.1989984901846467`, + 0.008957038432445741}, {-3.042712456072324, + 0.008957038432445741}, {-3.042712456072324, + 0.0019193653783812303`}, {-2.8864264219600013`, + 0.0019193653783812303`}, {-2.8864264219600013`, + 0.012155980729747792`}, {-2.730140387847679, + 0.012155980729747792`}, {-2.730140387847679, + 0.010876403810826971`}, {-2.573854353735356, + 0.010876403810826971`}, {-2.573854353735356, + 0.023032384540574765`}, {-2.4175683196230335`, + 0.023032384540574765`}, {-2.4175683196230335`, + 0.028150692216258044`}, {-2.2612822855107106`, + 0.028150692216258044`}, {-2.2612822855107106`, + 0.04862392291899117}, {-2.104996251398388, + 0.04862392291899117}, {-2.104996251398388, + 0.03966688448654543}, {-1.9487102172860655`, + 0.03966688448654543}, {-1.9487102172860655`, + 0.09148974970283864}, {-1.7924241831737429`, + 0.09148974970283864}, {-1.7924241831737429`, + 0.09276932662175946}, {-1.6361381490614202`, + 0.09276932662175946}, {-1.6361381490614202`, + 0.1202802303785571}, {-1.4798521149490975`, + 0.1202802303785571}, {-1.4798521149490975`, + 0.18489886478405854`}, {-1.323566080836775, + 0.18489886478405854`}, {-1.323566080836775, + 0.15674817256780046`}, {-1.1672800467244522`, + 0.15674817256780046`}, {-1.1672800467244522`, + 0.19449569167596467`}, {-1.0109940126121297`, + 0.19449569167596467`}, {-1.0109940126121297`, + 0.3045393067031552}, {-0.8547079784998068, + 0.3045393067031552}, {-0.8547079784998068, + 0.3813139218384044}, {-0.6984219443874844, + 0.3813139218384044}, {-0.6984219443874844, + 0.32629211432480915`}, {-0.542135910275162, + 0.32629211432480915`}, {-0.542135910275162, + 0.3346093642977945}, {-0.38584987616283906`, + 0.3346093642977945}, {-0.38584987616283906`, + 0.3544428065410672}, {-0.2295638420505166, + 0.3544428065410672}, {-0.2295638420505166, + 0.46256705618987654`}, {-0.07327780793819372, + 0.46256705618987654`}, {-0.07327780793819372, 0.41522271018980617`}, { + 0.08300822617412873, 0.41522271018980617`}, {0.08300822617412873, + 0.37107730648703785`}, {0.23929426028645162`, 0.37107730648703785`}, { + 0.23929426028645162`, 0.42481953708171233`}, {0.39558029439877407`, + 0.42481953708171233`}, {0.39558029439877407`, 0.35764174883836924`}, { + 0.5518663285110965, 0.35764174883836924`}, {0.5518663285110965, + 0.20281294164895}, {0.7081523626234194, 0.20281294164895}, { + 0.7081523626234194, 0.26743157605445145`}, {0.8644383967357423, + 0.26743157605445145`}, {0.8644383967357423, 0.3090178259193781}, { + 1.0207244308480647`, 0.3090178259193781}, {1.0207244308480647`, + 0.22456574927060394`}, {1.1770104649603872`, 0.22456574927060394`}, { + 1.1770104649603872`, 0.1951354801354251}, {1.3332964990727096`, + 0.1951354801354251}, {1.3332964990727096`, 0.15035028797319638`}, { + 1.489582533185033, 0.15035028797319638`}, {1.489582533185033, + 0.08573165356769495}, {1.6458685672973554`, 0.08573165356769495}, { + 1.6458685672973554`, 0.05118307675683281}, {1.8021546014096779`, + 0.05118307675683281}, {1.8021546014096779`, 0.058220749810897324`}, { + 1.9584406355220003`, 0.058220749810897324`}, {1.9584406355220003`, + 0.008957038432445741}, {2.1147266696343228`, 0.008957038432445741}, { + 2.1147266696343228`, 0.03326899989194133}, {2.271012703746646, + 0.03326899989194133}, {2.271012703746646, 0.030709846054099686`}, { + 2.4272987378589685`, 0.030709846054099686`}, {2.4272987378589685`, + 0.015994711486510254`}, {2.583584771971291, 0.015994711486510254`}, { + 2.583584771971291, 0.005758096135143691}, {2.7398708060836134`, + 0.005758096135143691}, {2.7398708060836134`, 0.010876403810826971`}, { + 2.8961568401959368`, 0.010876403810826971`}, {2.8961568401959368`, + 0.0019193653783812303`}, {3.0524428743082592`, + 0.0019193653783812303`}, {3.0524428743082592`, 0}}], {}, {}}, { + LineBox[{{-3.209364762882553, 0}, {-3.209364762882553, + 0.0011671518676348125`}, {-3.0380245906691017`, + 0.0011671518676348125`}, {-3.0380245906691017`, + 0.010504366808713313`}, {-2.8666844184556504`, + 0.010504366808713313`}, {-2.8666844184556504`, + 0.0040850315367218434`}, {-2.6953442462421995`, + 0.0040850315367218434`}, {-2.6953442462421995`, + 0.01108794274253072}, {-2.524004074028748, + 0.01108794274253072}, {-2.524004074028748, + 0.04260104316867065}, {-2.1813237296018455`, + 0.04260104316867065}, {-2.1813237296018455`, + 0.03909958756576622}, {-2.009983557388394, + 0.03909958756576622}, {-2.009983557388394, + 0.06360977678609728}, {-1.838643385174943, + 0.06360977678609728}, {-1.838643385174943, + 0.09745718094750684}, {-1.6673032129614918`, + 0.09745718094750684}, {-1.6673032129614918`, + 0.093372149410785}, {-1.4959630407480407`, + 0.093372149410785}, {-1.4959630407480407`, + 0.15231331872634302`}, {-1.3246228685345893`, + 0.15231331872634302`}, {-1.3246228685345893`, + 0.24685262000476285`}, {-1.153282696321138, + 0.24685262000476285`}, {-1.153282696321138, + 0.24568546813712802`}, {-0.9819425241076867, + 0.24568546813712802`}, {-0.9819425241076867, + 0.26786135362218944`}, {-0.8106023518942358, + 0.26786135362218944`}, {-0.8106023518942358, + 0.2964565743792424}, {-0.6392621796807845, + 0.2964565743792424}, {-0.6392621796807845, + 0.36123350303297447`}, {-0.46792200746733315`, + 0.36123350303297447`}, {-0.46792200746733315`, + 0.30287590965123384`}, {-0.2965818352538818, + 0.30287590965123384`}, {-0.2965818352538818, + 0.3180488839304864}, {-0.1252416630404305, + 0.3180488839304864}, {-0.1252416630404305, 0.3851601163194881}, { + 0.046098509173020386`, 0.3851601163194881}, {0.046098509173020386`, + 0.3355561619450086}, {0.2174386813864717, 0.3355561619450086}, { + 0.2174386813864717, 0.4219254001499847}, {0.38877885359992304`, + 0.4219254001499847}, {0.38877885359992304`, 0.35014556029044375`}, { + 0.5601190258133744, 0.35014556029044375`}, {0.5601190258133744, + 0.3594827752315222}, {0.7314591980268257, 0.3594827752315222}, { + 0.7314591980268257, 0.26552704988691983`}, {0.902799370240277, + 0.26552704988691983`}, {0.902799370240277, 0.23926613286513657`}, { + 1.0741395424537283`, 0.23926613286513657`}, {1.0741395424537283`, + 0.22234243078443178`}, {1.2454797146671797`, 0.22234243078443178`}, { + 1.2454797146671797`, 0.19258005815974405`}, {1.41681988688063, + 0.19258005815974405`}, {1.41681988688063, 0.1587326539983345}, { + 1.5881600590940814`, 0.1587326539983345}, {1.5881600590940814`, + 0.07644844733008022}, {1.7595002313075327`, 0.07644844733008022}, { + 1.7595002313075327`, 0.06594408052136691}, {1.930840403520984, + 0.06594408052136691}, {1.930840403520984, 0.03559813196286178}, { + 2.1021805757344354`, 0.03559813196286178}, {2.1021805757344354`, + 0.04785322657302731}, {2.2735207479478867`, 0.04785322657302731}, { + 2.2735207479478867`, 0.02626091702178328}, {2.444860920161338, + 0.02626091702178328}, {2.444860920161338, 0.02451018922033106}, { + 2.6162010923747894`, 0.02451018922033106}, {2.6162010923747894`, + 0.01400582241161775}, {2.7875412645882407`, 0.01400582241161775}, { + 2.7875412645882407`, 0.00466860747053925}, {2.958881436801692, + 0.00466860747053925}, {2.958881436801692, 0.007586487139626281}, { + 3.1302216090151433`, 0.007586487139626281}, {3.1302216090151433`, + 0.0035014556029044374`}, {3.301561781228594, 0.0035014556029044374`}, { + 3.301561781228594, 0.0017507278014522187`}, {3.472901953442045, + 0.0017507278014522187`}, {3.472901953442045, 0.0005835759338174062}, { + 3.6442421256554964`, 0.0005835759338174062}, { + 3.6442421256554964`, 0}}], {}, {}}, { + LineBox[{{-4.175888454996922, 0}, {-4.175888454996922, + 0.0009209772376074258}, {-3.9587495357774625`, + 0.0009209772376074258}, {-3.9587495357774625`, 0}, {-3.524471697338543, + 0}, {-3.524471697338543, 0.009670260994877972}, {-3.3073327781190835`, + 0.009670260994877972}, {-3.3073327781190835`, + 0.005525863425644555}, {-3.0901938588996236`, + 0.005525863425644555}, {-3.0901938588996236`, + 0.0004604886188037129}, {-2.8730549396801637`, + 0.0004604886188037129}, {-2.8730549396801637`, + 0.010130749613681683`}, {-2.655916020460704, + 0.010130749613681683`}, {-2.655916020460704, + 0.008749283757270545}, {-2.4387771012412447`, + 0.008749283757270545}, {-2.4387771012412447`, + 0.030852737459848765`}, {-2.2216381820217848`, + 0.030852737459848765`}, {-2.2216381820217848`, + 0.04604886188037129}, {-2.004499262802325, + 0.04604886188037129}, {-2.004499262802325, + 0.06124498630089382}, {-1.7873603435828653`, + 0.06124498630089382}, {-1.7873603435828653`, + 0.07736208795902377}, {-1.5702214243634054`, + 0.07736208795902377}, {-1.5702214243634054`, + 0.11650362055733937`}, {-1.353082505143946, + 0.11650362055733937`}, {-1.353082505143946, + 0.16301297105651438`}, {-1.135943585924486, + 0.16301297105651438`}, {-1.135943585924486, + 0.20629890122406339`}, {-0.9188046667050265, + 0.20629890122406339`}, {-0.9188046667050265, + 0.25879460376768665`}, {-0.7016657474855665, + 0.25879460376768665`}, {-0.7016657474855665, + 0.3186581242121693}, {-0.4845268282661066, + 0.3186581242121693}, {-0.4845268282661066, + 0.39325728045837083`}, {-0.2673879090466471, + 0.39325728045837083`}, {-0.2673879090466471, + 0.3918758146019597}, {-0.050248989827187174`, + 0.3918758146019597}, {-0.050248989827187174`, 0.503774548971262}, { + 0.16688992939227276`, 0.503774548971262}, {0.16688992939227276`, + 0.40338803007205254`}, {0.3840288486117318, 0.40338803007205254`}, { + 0.3840288486117318, 0.3089878632172914}, {0.6011677678311917, + 0.3089878632172914}, {0.6011677678311917, 0.3697723608993815}, { + 0.8183066870506517, 0.3697723608993815}, {0.8183066870506517, + 0.25557118343606067`}, {1.0354456062701116`, 0.25557118343606067`}, { + 1.0354456062701116`, 0.18097202718985916`}, {1.2525845254895716`, + 0.18097202718985916`}, {1.2525845254895716`, 0.1178850864137505}, { + 1.4697234447090306`, 0.1178850864137505}, {1.4697234447090306`, + 0.09486065547356486}, {1.6868623639284905`, 0.09486065547356486}, { + 1.6868623639284905`, 0.08703234895390174}, {1.9040012831479505`, + 0.08703234895390174}, {1.9040012831479505`, 0.07966453105304233}, { + 2.1211402023674104`, 0.07966453105304233}, {2.1211402023674104`, + 0.0428254415487453}, {2.3382791215868695`, 0.0428254415487453}, { + 2.3382791215868695`, 0.013814658564111387`}, {2.5554180408063294`, + 0.013814658564111387`}, {2.5554180408063294`, 0.01611710165812995}, { + 2.7725569600257893`, 0.01611710165812995}, {2.7725569600257893`, + 0.010130749613681683`}, {2.9896958792452493`, 0.010130749613681683`}, { + 2.9896958792452493`, 0.008749283757270545}, {3.206834798464709, + 0.008749283757270545}, {3.206834798464709, 0.0023024430940185646`}, { + 3.4239737176841682`, 0.0023024430940185646`}, {3.4239737176841682`, + 0.0032234203316259904`}, {3.641112636903628, 0.0032234203316259904`}, { + 3.641112636903628, 0.0004604886188037129}, {3.858251556123088, + 0.0004604886188037129}, {3.858251556123088, 0.0013814658564111387`}, { + 4.075390475342548, 0.0013814658564111387`}, {4.075390475342548, + 0.0018419544752148517`}, {4.292529394562008, 0.0018419544752148517`}, { + 4.292529394562008, 0.0032234203316259904`}, {4.509668313781468, + 0.0032234203316259904`}, {4.509668313781468, 0}}], {}, {}}, { + LineBox[{{-3.7406783318115058`, 0}, {-3.7406783318115058`, + 0.0042794405491938465`}, {-3.5537567006300916`, + 0.0042794405491938465`}, {-3.5537567006300916`, + 0.002674650343246154}, {-3.179913438267264, + 0.002674650343246154}, {-3.179913438267264, + 0.008558881098387693}, {-2.9929918070858497`, + 0.008558881098387693}, {-2.9929918070858497`, + 0.01925748247137231}, {-2.8060701759044355`, + 0.01925748247137231}, {-2.8060701759044355`, + 0.005349300686492308}, {-2.6191485447230214`, + 0.005349300686492308}, {-2.6191485447230214`, + 0.03798003487409539}, {-2.4322269135416077`, + 0.03798003487409539}, {-2.4322269135416077`, + 0.011768461510283077`}, {-2.2453052823601936`, + 0.011768461510283077`}, {-2.2453052823601936`, + 0.03904989501139385}, {-2.0583836511787794`, + 0.03904989501139385}, {-2.0583836511787794`, + 0.05830737748276616}, {-1.8714620199973655`, + 0.05830737748276616}, {-1.8714620199973655`, + 0.07756485995413846}, {-1.6845403888159516`, + 0.07756485995413846}, {-1.6845403888159516`, + 0.09521755221956309}, {-1.4976187576345374`, + 0.09521755221956309}, {-1.4976187576345374`, + 0.18508580375263387`}, {-1.3106971264531233`, + 0.18508580375263387`}, {-1.3106971264531233`, + 0.14871055908448616`}, {-1.1237754952717096`, + 0.14871055908448616`}, {-1.1237754952717096`, + 0.18936524430182772`}, {-0.9368538640902955, + 0.18936524430182772`}, {-0.9368538640902955, + 0.2824430762467939}, {-0.7499322329088813, + 0.2824430762467939}, {-0.7499322329088813, + 0.2797684259035477}, {-0.5630106017274672, + 0.2797684259035477}, {-0.5630106017274672, + 0.3921037403198862}, {-0.37608897054605306`, + 0.3921037403198862}, {-0.37608897054605306`, + 0.3370059432490154}, {-0.18916733936463936`, + 0.3370059432490154}, {-0.18916733936463936`, + 0.3910338801825877}, {-0.0022457081832252257`, + 0.3910338801825877}, {-0.0022457081832252257`, 0.32684227194468}, { + 0.1846759229981889, 0.32684227194468}, {0.1846759229981889, + 0.4552254884204954}, {0.3715975541796026, 0.4552254884204954}, { + 0.3715975541796026, 0.34823947469064925`}, {0.5585191853610172, + 0.34823947469064925`}, {0.5585191853610172, 0.29153688741383077`}, { + 0.7454408165424309, 0.29153688741383077`}, {0.7454408165424309, + 0.2781636356976}, {0.9323624477238446, 0.2781636356976}, { + 0.9323624477238446, 0.2856526566586893}, {1.1192840789052592`, + 0.2856526566586893}, {1.1192840789052592`, 0.22039118828348309`}, { + 1.3062057100866729`, 0.22039118828348309`}, {1.3062057100866729`, + 0.16208381080071693`}, {1.4931273412680865`, 0.16208381080071693`}, { + 1.4931273412680865`, 0.12303391578932309`}, {1.6800489724495011`, + 0.12303391578932309`}, {1.6800489724495011`, 0.09468262215091386}, { + 1.8669706036309148`, 0.09468262215091386}, {1.8669706036309148`, + 0.06900597885575077}, {2.0538922348123294`, 0.06900597885575077}, { + 2.0538922348123294`, 0.05884230755141539}, {2.240813865993743, + 0.05884230755141539}, {2.240813865993743, 0.01979241254002154}, { + 2.427735497175157, 0.01979241254002154}, {2.427735497175157, + 0.02621157336381231}, {2.6146571283565714`, 0.02621157336381231}, { + 2.6146571283565714`, 0.006954090892440001}, {2.801578759537985, + 0.006954090892440001}, {2.801578759537985, 0.003209580411895385}, { + 2.9885003907193997`, 0.003209580411895385}, {2.9885003907193997`, + 0.004814370617843077}, {3.362343653082227, 0.004814370617843077}, { + 3.362343653082227, 0}, {3.5492652842636416`, 0}, {3.5492652842636416`, + 0.0021397202745969232`}, {3.7361869154450553`, + 0.0021397202745969232`}, {3.7361869154450553`, 0}}], {}, {}}, { + LineBox[{{-3.7693124213145928`, 0}, {-3.7693124213145928`, + 0.008253688035461944}, {-3.575479069590528, + 0.008253688035461944}, {-3.575479069590528, + 0.001031711004432743}, {-3.3816457178664634`, + 0.001031711004432743}, {-3.3816457178664634`, + 0.0005158555022163715}, {-3.1878123661423983`, + 0.0005158555022163715}, {-3.1878123661423983`, + 0.007221977031029201}, {-2.9939790144183336`, + 0.007221977031029201}, {-2.9939790144183336`, + 0.003095133013298229}, {-2.800145662694269, + 0.003095133013298229}, {-2.800145662694269, + 0.022181786595303975`}, {-2.606312310970204, + 0.022181786595303975`}, {-2.606312310970204, + 0.02011836458643849}, {-2.4124789592461395`, + 0.02011836458643849}, {-2.4124789592461395`, + 0.03610988515514601}, {-2.218645607522075, + 0.03610988515514601}, {-2.218645607522075, + 0.05725996074601724}, {-2.02481225579801, + 0.05725996074601724}, {-2.02481225579801, + 0.08408444686126856}, {-1.830978904073945, + 0.08408444686126856}, {-1.830978904073945, + 0.08924300188343227}, {-1.6371455523498804`, + 0.08924300188343227}, {-1.6371455523498804`, + 0.130511442060742}, {-1.4433122006258157`, + 0.130511442060742}, {-1.4433122006258157`, + 0.1537249396604787}, {-1.249478848901751, + 0.1537249396604787}, {-1.249478848901751, + 0.22697642097520349`}, {-1.0556454971776859`, + 0.22697642097520349`}, {-1.0556454971776859`, + 0.23626182001509816`}, {-0.8618121454536212, + 0.23626182001509816`}, {-0.8618121454536212, + 0.3244731108940977}, {-0.6679787937295565, + 0.3244731108940977}, {-0.6679787937295565, + 0.34975003050269987`}, {-0.4741454420054918, + 0.34975003050269987`}, {-0.4741454420054918, + 0.4111368352664481}, {-0.2803120902814271, + 0.4111368352664481}, {-0.2803120902814271, + 0.4023672917287698}, {-0.08647873855736199, + 0.4023672917287698}, {-0.08647873855736199, 0.3641939845647583}, { + 0.1073546131667027, 0.3641939845647583}, {0.1073546131667027, + 0.47974561706122554`}, {0.3011879648907674, 0.47974561706122554`}, { + 0.3011879648907674, 0.337369498449507}, {0.49502131661483206`, + 0.337369498449507}, {0.49502131661483206`, 0.2620545951259167}, { + 0.6888546683388967, 0.2620545951259167}, {0.6888546683388967, + 0.22491299896633798`}, {0.8826880200629614, 0.22491299896633798`}, { + 0.8826880200629614, 0.21717516643309243`}, {1.0765213717870261`, + 0.21717516643309243`}, {1.0765213717870261`, 0.20685805638876498`}, { + 1.2703547235110908`, 0.20685805638876498`}, {1.2703547235110908`, + 0.1470188181316659}, {1.4641880752351564`, 0.1470188181316659}, { + 1.4641880752351564`, 0.09027471288786502}, {1.658021426959221, + 0.09027471288786502}, {1.658021426959221, 0.08769543537678316}, { + 1.8518547786832857`, 0.08769543537678316}, {1.8518547786832857`, + 0.043331862186175206`}, {2.0456881304073504`, 0.043331862186175206`}, { + 2.0456881304073504`, 0.06241851576818096}, {2.239521482131415, + 0.06241851576818096}, {2.239521482131415, 0.038689162666227864`}, { + 2.43335483385548, 0.038689162666227864`}, {2.43335483385548, + 0.01650737607092389}, {2.6271881855795445`, 0.01650737607092389}, { + 2.6271881855795445`, 0.004642699519947344}, {3.014854889027674, + 0.004642699519947344}, {3.014854889027674, 0.0005158555022163715}, { + 3.2086882407517385`, 0.0005158555022163715}, {3.2086882407517385`, + 0.004642699519947344}, {3.402521592475803, 0.004642699519947344}, { + 3.402521592475803, 0.0005158555022163715}, {3.596354944199869, + 0.0005158555022163715}, {3.596354944199869, 0}, { + 3.7901882959239335`, 0}, {3.7901882959239335`, + 0.0015475665066491146`}, {3.984021647647998, 0.0015475665066491146`}, { + 3.984021647647998, 0}}], {}, {}}, { + LineBox[{{-3.383177766523831, 0}, {-3.383177766523831, + 0.0011589865912617786`}, {-3.2106304708885265`, + 0.0011589865912617786`}, {-3.2106304708885265`, + 0.002317973182523557}, {-3.038083175253222, + 0.002317973182523557}, {-3.038083175253222, + 0.009851386025725118}, {-2.865535879617917, + 0.009851386025725118}, {-2.865535879617917, + 0.011589865912617785`}, {-2.6929885839826126`, + 0.011589865912617785`}, {-2.6929885839826126`, + 0.01506682568640312}, {-2.520441288347308, + 0.01506682568640312}, {-2.520441288347308, + 0.02433871841649735}, {-2.3478939927120033`, + 0.02433871841649735}, {-2.3478939927120033`, + 0.028974664781544465`}, {-2.175346697076699, + 0.028974664781544465`}, {-2.175346697076699, + 0.06722122229318316}, {-2.0027994014413943`, + 0.06722122229318316}, {-2.0027994014413943`, + 0.03592858432911514}, {-1.8302521058060899`, + 0.03592858432911514}, {-1.8302521058060899`, + 0.054472369789303594`}, {-1.6577048101707852`, + 0.054472369789303594`}, {-1.6577048101707852`, + 0.09329842059657317}, {-1.4851575145354805`, + 0.09329842059657317}, {-1.4851575145354805`, + 0.141396364133937}, {-1.312610218900176, + 0.141396364133937}, {-1.312610218900176, + 0.19644822721887145`}, {-1.1400629232648716`, + 0.19644822721887145`}, {-1.1400629232648716`, + 0.25207958359943683`}, {-0.9675156276295667, + 0.25207958359943683`}, {-0.9675156276295667, + 0.3181418193013582}, {-0.7949683319942622, + 0.3181418193013582}, {-0.7949683319942622, + 0.3001775271368006}, {-0.6224210363589577, + 0.3001775271368006}, {-0.6224210363589577, + 0.329731685213976}, {-0.44987374072365327`, + 0.329731685213976}, {-0.44987374072365327`, + 0.3384240846484393}, {-0.2773264450883488, + 0.3384240846484393}, {-0.2773264450883488, + 0.361024323178044}, {-0.1047791494530439, + 0.361024323178044}, {-0.1047791494530439, 0.4154966929673476}, { + 0.06776814618226057, 0.4154966929673476}, {0.06776814618226057, + 0.3581268566998896}, {0.24031544181756503`, 0.3581268566998896}, { + 0.24031544181756503`, 0.4485278108183083}, {0.41286273745286994`, + 0.4485278108183083}, {0.41286273745286994`, 0.3830450684120178}, { + 0.5854100330881744, 0.3830450684120178}, {0.5854100330881744, + 0.26714640928583994`}, {0.7579573287234789, 0.26714640928583994`}, { + 0.7579573287234789, 0.314085366231942}, {0.9305046243587833, + 0.314085366231942}, {0.9305046243587833, 0.24512566405186617`}, { + 1.1030519199940878`, 0.24512566405186617`}, {1.1030519199940878`, + 0.19876620040139503`}, {1.2755992156293923`, 0.19876620040139503`}, { + 1.2755992156293923`, 0.1721095088023741}, {1.4481465112646976`, + 0.1721095088023741}, {1.4481465112646976`, 0.1344424445863663}, { + 1.620693806900002, 0.1344424445863663}, {1.620693806900002, + 0.06953919547570671}, {1.7932411025353066`, 0.06953919547570671}, { + 1.7932411025353066`, 0.0915599407096805}, {1.965788398170611, + 0.0915599407096805}, {1.965788398170611, 0.049836423424256475`}, { + 2.1383356938059155`, 0.049836423424256475`}, {2.1383356938059155`, + 0.017384798868926677`}, {2.31088298944122, 0.017384798868926677`}, { + 2.31088298944122, 0.027236184894651797`}, {2.4834302850765244`, + 0.027236184894651797`}, {2.4834302850765244`, 0.014487332390772233`}, { + 2.655977580711829, 0.014487332390772233`}, {2.655977580711829, + 0.002317973182523557}, {2.8285248763471333`, 0.002317973182523557}, { + 2.8285248763471333`, 0.0005794932956308893}, {3.0010721719824387`, + 0.0005794932956308893}, {3.0010721719824387`, 0.002317973182523557}, { + 3.173619467617743, 0.002317973182523557}, {3.173619467617743, 0}, { + 3.3461667632530476`, 0}, {3.3461667632530476`, + 0.0017384798868926678`}, {3.518714058888352, 0.0017384798868926678`}, { + 3.518714058888352, 0}}], {}, {}}, { + LineBox[{{-3.131715315237866, 0}, {-3.131715315237866, + 0.0017701613132522867`}, {-2.9622561813420005`, + 0.0017701613132522867`}, {-2.9622561813420005`, + 0.0029502688554204778`}, {-2.792797047446135, + 0.0029502688554204778`}, {-2.792797047446135, + 0.020651881987943346`}, {-2.62333791355027, + 0.020651881987943346`}, {-2.62333791355027, + 0.007670699024093243}, {-2.4538787796544046`, + 0.007670699024093243}, {-2.4538787796544046`, + 0.023602150843363822`}, {-2.2844196457585393`, + 0.023602150843363822`}, {-2.2844196457585393`, + 0.04425403283130717}, {-2.114960511862674, + 0.04425403283130717}, {-2.114960511862674, + 0.03658333380721392}, {-1.9455013779668087`, + 0.03658333380721392}, {-1.9455013779668087`, + 0.05605510825298908}, {-1.7760422440709434`, + 0.05605510825298908}, {-1.7760422440709434`, + 0.0672661299035869}, {-1.606583110175078, + 0.0672661299035869}, {-1.606583110175078, + 0.10089919485538033`}, {-1.4371239762792127`, + 0.10089919485538033`}, {-1.4371239762792127`, + 0.12568145324091234`}, {-1.2676648423833474`, + 0.12568145324091234`}, {-1.2676648423833474`, + 0.16521505590354676`}, {-1.0982057084874821`, + 0.16521505590354676`}, {-1.0982057084874821`, + 0.22068011038545174`}, {-0.9287465745916168, + 0.22068011038545174`}, {-0.9287465745916168, + 0.22717070186737678`}, {-0.7592874406957515, + 0.22717070186737678`}, {-0.7592874406957515, + 0.2537231215661611}, {-0.5898283067998862, + 0.2537231215661611}, {-0.5898283067998862, + 0.35226210133720504`}, {-0.42036917290402087`, + 0.35226210133720504`}, {-0.42036917290402087`, + 0.3959260803974281}, {-0.25091003900815556`, + 0.3959260803974281}, {-0.25091003900815556`, + 0.4372298443733148}, {-0.08145090511229025, + 0.4372298443733148}, {-0.08145090511229025, 0.42955914534922157`}, { + 0.08800822878357506, 0.42955914534922157`}, {0.08800822878357506, + 0.32334946655408436`}, {0.25746736267944037`, 0.32334946655408436`}, { + 0.25746736267944037`, 0.41716801615645555`}, {0.4269264965753057, + 0.41716801615645555`}, {0.4269264965753057, 0.41834812369862373`}, { + 0.596385630471171, 0.41834812369862373`}, {0.596385630471171, + 0.28912634783120683`}, {0.7658447643670363, 0.28912634783120683`}, { + 0.7658447643670363, 0.30269758456614104`}, {0.9353038982629016, + 0.30269758456614104`}, {0.9353038982629016, 0.21536962644569488`}, { + 1.1047630321587665`, 0.21536962644569488`}, {1.1047630321587665`, + 0.22894086318062906`}, {1.2742221660546322`, 0.22894086318062906`}, { + 1.2742221660546322`, 0.22835080940954497`}, {1.443681299950498, + 0.22835080940954497`}, {1.443681299950498, 0.12509139946982825`}, { + 1.6131404338463629`, 0.12509139946982825`}, {1.6131404338463629`, + 0.12273118438549188`}, {1.7825995677422277`, 0.12273118438549188`}, { + 1.7825995677422277`, 0.0654959685903346}, {1.9520587016380935`, + 0.0654959685903346}, {1.9520587016380935`, 0.07080645253009146}, { + 2.1215178355339592`, 0.07080645253009146}, {2.1215178355339592`, + 0.04543414037347536}, {2.290976969429824, 0.04543414037347536}, { + 2.290976969429824, 0.03835349512046621}, {2.460436103325689, + 0.03835349512046621}, {2.460436103325689, 0.019471774445775154`}, { + 2.6298952372215547`, 0.019471774445775154`}, {2.6298952372215547`, + 0.011801075421681911`}, {2.7993543711174205`, 0.011801075421681911`}, { + 2.7993543711174205`, 0.0005900537710840956}, {2.9688135050132853`, + 0.0005900537710840956}, {2.9688135050132853`, 0.00531048393975686}, { + 3.13827263890915, 0.00531048393975686}, {3.13827263890915, + 0.001180107542168191}, {3.307731772805016, 0.001180107542168191}, { + 3.307731772805016, 0.0017701613132522867`}, {3.4771909067008817`, + 0.0017701613132522867`}, {3.4771909067008817`, 0.0005900537710840956}, { + 3.6466500405967466`, 0.0005900537710840956}, { + 3.6466500405967466`, 0}}], {}, {}}}, + AspectRatio->0.6, + DisplayFunction->Identity, + Frame->{True, True, False, False}]], "Output", + CellChangeTimes->{ + 3.376235381140625*^9, {3.376293522296875*^9, 3.37629354728125*^9}}] +}, Open ]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{"Mean", "[", "mc", "]"}]], "Input", + CellChangeTimes->{{3.37623527084375*^9, 3.376235272203125*^9}}], + +Cell[BoxData[ + RowBox[{"{", + RowBox[{ + RowBox[{"-", "0.003783856351946682`"}], ",", + RowBox[{"-", "0.07611147780847509`"}], ",", + RowBox[{"-", "0.024903464284182695`"}], ",", "0.030710327732062625`", ",", + "0.004799504733268179`", ",", + RowBox[{"-", "0.024149933377163944`"}], ",", + RowBox[{"-", "0.06361185419632617`"}]}], "}"}]], "Output", + CellChangeTimes->{3.376235272578125*^9}] +}, Open ]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{"MatrixForm", "@", + RowBox[{"Map", "[", + RowBox[{ + RowBox[{ + RowBox[{"PaddedForm", "[", + RowBox[{"#", ",", + RowBox[{"{", + RowBox[{"3", ",", "2"}], "}"}]}], "]"}], "&"}], ",", + RowBox[{"Covariance", "[", "mc", "]"}], ",", + RowBox[{"{", "2", "}"}]}], "]"}]}]], "Input", + CellChangeTimes->{{3.37623527509375*^9, 3.37623534*^9}}], + +Cell[BoxData[ + TagBox[ + RowBox[{"(", "\[NoBreak]", GridBox[{ + { + TagBox[ + InterpretationBox["\<\" 0.95\"\>", + 0.9537032729616703, + AutoDelete->True], + PaddedForm[#, {3, 2}]& ], + TagBox[ + InterpretationBox["\<\"-0.04\"\>", + -0.04218458874966183, + AutoDelete->True], + PaddedForm[#, {3, 2}]& ], + TagBox[ + InterpretationBox["\<\"-0.02\"\>", + -0.018135375467144554`, + AutoDelete->True], + PaddedForm[#, {3, 2}]& ], + TagBox[ + InterpretationBox["\<\" 0.01\"\>", + 0.00857840732473738, + AutoDelete->True], + PaddedForm[#, {3, 2}]& ], + TagBox[ + InterpretationBox["\<\"-0.00\"\>", + -0.004443378873864716, + AutoDelete->True], + PaddedForm[#, {3, 2}]& ], + TagBox[ + InterpretationBox["\<\" 0.02\"\>", + 0.02265469892070173, + AutoDelete->True], + PaddedForm[#, {3, 2}]& ], + TagBox[ + InterpretationBox["\<\" 0.04\"\>", + 0.03829626532080443, + AutoDelete->True], + PaddedForm[#, {3, 2}]& ]}, + { + TagBox[ + InterpretationBox["\<\"-0.04\"\>", + -0.04218458874966183, + AutoDelete->True], + PaddedForm[#, {3, 2}]& ], + TagBox[ + InterpretationBox["\<\" 1.06\"\>", + 1.0558308870327595`, + AutoDelete->True], + PaddedForm[#, {3, 2}]& ], + TagBox[ + InterpretationBox["\<\"-0.06\"\>", + -0.05514977178294164, + AutoDelete->True], + PaddedForm[#, {3, 2}]& ], + TagBox[ + InterpretationBox["\<\" 0.07\"\>", + 0.06517808013110833, + AutoDelete->True], + PaddedForm[#, {3, 2}]& ], + TagBox[ + InterpretationBox["\<\" 0.10\"\>", + 0.09904157554935408, + AutoDelete->True], + PaddedForm[#, {3, 2}]& ], + TagBox[ + InterpretationBox["\<\" 0.00\"\>", + 0.00268539712147848, + AutoDelete->True], + PaddedForm[#, {3, 2}]& ], + TagBox[ + InterpretationBox["\<\"-0.03\"\>", + -0.0262222119921313, + AutoDelete->True], + PaddedForm[#, {3, 2}]& ]}, + { + TagBox[ + InterpretationBox["\<\"-0.02\"\>", + -0.018135375467144554`, + AutoDelete->True], + PaddedForm[#, {3, 2}]& ], + TagBox[ + InterpretationBox["\<\"-0.06\"\>", + -0.05514977178294164, + AutoDelete->True], + PaddedForm[#, {3, 2}]& ], + TagBox[ + InterpretationBox["\<\" 1.04\"\>", + 1.0375350649343276`, + AutoDelete->True], + PaddedForm[#, {3, 2}]& ], + TagBox[ + InterpretationBox["\<\" 0.02\"\>", + 0.019781296009935497`, + AutoDelete->True], + PaddedForm[#, {3, 2}]& ], + TagBox[ + InterpretationBox["\<\"-0.06\"\>", + -0.05618054541427067, + AutoDelete->True], + PaddedForm[#, {3, 2}]& ], + TagBox[ + InterpretationBox["\<\" 0.03\"\>", + 0.03139845838514928, + AutoDelete->True], + PaddedForm[#, {3, 2}]& ], + TagBox[ + InterpretationBox["\<\" 0.02\"\>", + 0.017878519632569333`, + AutoDelete->True], + PaddedForm[#, {3, 2}]& ]}, + { + TagBox[ + InterpretationBox["\<\" 0.01\"\>", + 0.00857840732473738, + AutoDelete->True], + PaddedForm[#, {3, 2}]& ], + TagBox[ + InterpretationBox["\<\" 0.07\"\>", + 0.06517808013110833, + AutoDelete->True], + PaddedForm[#, {3, 2}]& ], + TagBox[ + InterpretationBox["\<\" 0.02\"\>", + 0.019781296009935497`, + AutoDelete->True], + PaddedForm[#, {3, 2}]& ], + TagBox[ + InterpretationBox["\<\" 1.08\"\>", + 1.0838280887242027`, + AutoDelete->True], + PaddedForm[#, {3, 2}]& ], + TagBox[ + InterpretationBox["\<\" 0.02\"\>", + 0.01899393818193987, + AutoDelete->True], + PaddedForm[#, {3, 2}]& ], + TagBox[ + InterpretationBox["\<\"-0.00\"\>", + -0.0014255670624039284`, + AutoDelete->True], + PaddedForm[#, {3, 2}]& ], + TagBox[ + InterpretationBox["\<\" 0.06\"\>", + 0.059347629057403754`, + AutoDelete->True], + PaddedForm[#, {3, 2}]& ]}, + { + TagBox[ + InterpretationBox["\<\"-0.00\"\>", + -0.004443378873864716, + AutoDelete->True], + PaddedForm[#, {3, 2}]& ], + TagBox[ + InterpretationBox["\<\" 0.10\"\>", + 0.09904157554935408, + AutoDelete->True], + PaddedForm[#, {3, 2}]& ], + TagBox[ + InterpretationBox["\<\"-0.06\"\>", + -0.05618054541427067, + AutoDelete->True], + PaddedForm[#, {3, 2}]& ], + TagBox[ + InterpretationBox["\<\" 0.02\"\>", + 0.01899393818193987, + AutoDelete->True], + PaddedForm[#, {3, 2}]& ], + TagBox[ + InterpretationBox["\<\" 1.06\"\>", + 1.0628823961568872`, + AutoDelete->True], + PaddedForm[#, {3, 2}]& ], + TagBox[ + InterpretationBox["\<\" 0.02\"\>", + 0.020889024403563255`, + AutoDelete->True], + PaddedForm[#, {3, 2}]& ], + TagBox[ + InterpretationBox["\<\" 0.00\"\>", + 0.0025342730516941603`, + AutoDelete->True], + PaddedForm[#, {3, 2}]& ]}, + { + TagBox[ + InterpretationBox["\<\" 0.02\"\>", + 0.02265469892070173, + AutoDelete->True], + PaddedForm[#, {3, 2}]& ], + TagBox[ + InterpretationBox["\<\" 0.00\"\>", + 0.00268539712147848, + AutoDelete->True], + PaddedForm[#, {3, 2}]& ], + TagBox[ + InterpretationBox["\<\" 0.03\"\>", + 0.03139845838514928, + AutoDelete->True], + PaddedForm[#, {3, 2}]& ], + TagBox[ + InterpretationBox["\<\"-0.00\"\>", + -0.0014255670624039284`, + AutoDelete->True], + PaddedForm[#, {3, 2}]& ], + TagBox[ + InterpretationBox["\<\" 0.02\"\>", + 0.020889024403563255`, + AutoDelete->True], + PaddedForm[#, {3, 2}]& ], + TagBox[ + InterpretationBox["\<\" 0.97\"\>", + 0.9669643789988037, + AutoDelete->True], + PaddedForm[#, {3, 2}]& ], + TagBox[ + InterpretationBox["\<\" 0.01\"\>", + 0.010467714020067942`, + AutoDelete->True], + PaddedForm[#, {3, 2}]& ]}, + { + TagBox[ + InterpretationBox["\<\" 0.04\"\>", + 0.03829626532080443, + AutoDelete->True], + PaddedForm[#, {3, 2}]& ], + TagBox[ + InterpretationBox["\<\"-0.03\"\>", + -0.0262222119921313, + AutoDelete->True], + PaddedForm[#, {3, 2}]& ], + TagBox[ + InterpretationBox["\<\" 0.02\"\>", + 0.017878519632569333`, + AutoDelete->True], + PaddedForm[#, {3, 2}]& ], + TagBox[ + InterpretationBox["\<\" 0.06\"\>", + 0.059347629057403754`, + AutoDelete->True], + PaddedForm[#, {3, 2}]& ], + TagBox[ + InterpretationBox["\<\" 0.00\"\>", + 0.0025342730516941603`, + AutoDelete->True], + PaddedForm[#, {3, 2}]& ], + TagBox[ + InterpretationBox["\<\" 0.01\"\>", + 0.010467714020067942`, + AutoDelete->True], + PaddedForm[#, {3, 2}]& ], + TagBox[ + InterpretationBox["\<\" 0.98\"\>", + 0.982820578061231, + AutoDelete->True], + PaddedForm[#, {3, 2}]& ]} + }, + GridBoxAlignment->{ + "Columns" -> {{Left}}, "ColumnsIndexed" -> {}, "Rows" -> {{Baseline}}, + "RowsIndexed" -> {}}, + GridBoxSpacings->{"Columns" -> { + Offset[0.27999999999999997`], { + Offset[0.7]}, + Offset[0.27999999999999997`]}, "ColumnsIndexed" -> {}, "Rows" -> { + Offset[0.2], { + Offset[0.4]}, + Offset[0.2]}, "RowsIndexed" -> {}}], "\[NoBreak]", ")"}], + Function[BoxForm`e$, + MatrixForm[BoxForm`e$]]]], "Output", + CellChangeTimes->{{3.37623527984375*^9, 3.37623534046875*^9}, + 3.3762935506875*^9}] +}, Open ]] +}, +WindowSize->{1098, 1002}, +WindowMargins->{{0, Automatic}, {Automatic, 0}}, +ShowSelection->True, +FrontEndVersion->"6.0 for Microsoft Windows (32-bit) (October 10, 2006)", +StyleDefinitions->"Default.nb" +] +(* End of Notebook Content *) + +(* Internal cache information *) +(*CellTagsOutline +CellTagsIndex->{ + "Info3376231445-5207814"->{ + Cell[836, 31, 419, 10, 60, "Print", + CellTags->"Info3376231445-5207814"]} + } +*) +(*CellTagsIndex +CellTagsIndex->{ + {"Info3376231445-5207814", 53191, 1159} + } +*) +(*NotebookFileOutline +Notebook[{ +Cell[568, 21, 126, 2, 39, "Input"], +Cell[CellGroupData[{ +Cell[719, 27, 114, 2, 39, "Input"], +Cell[836, 31, 419, 10, 60, "Print", + CellTags->"Info3376231445-5207814"] +}, Open ]], +Cell[CellGroupData[{ +Cell[1292, 46, 128, 2, 39, "Input"], +Cell[1423, 50, 633, 12, 82, "Message"], +Cell[2059, 64, 628, 12, 82, "Message"], +Cell[2690, 78, 645, 13, 57, "Message"], +Cell[3338, 93, 752, 13, 107, "Message"], +Cell[4093, 108, 640, 12, 82, "Message"], +Cell[4736, 122, 814, 15, 82, "Message"] +}, Closed]], +Cell[5565, 140, 182, 3, 32, "Input"], +Cell[5750, 145, 129, 2, 39, "Input"], +Cell[CellGroupData[{ +Cell[5904, 151, 488, 10, 39, "Input"], +Cell[6395, 163, 409, 9, 54, "Output"] +}, Open ]], +Cell[6819, 175, 856, 28, 39, "Input"], +Cell[7678, 205, 374, 10, 39, "Input"], +Cell[8055, 217, 254, 6, 39, "Input"], +Cell[CellGroupData[{ +Cell[8334, 227, 1460, 29, 147, "Input"], +Cell[9797, 258, 474, 8, 38, "Output"] +}, Open ]], +Cell[CellGroupData[{ +Cell[10308, 271, 1281, 23, 69, "Input"], +Cell[11592, 296, 956, 16, 38, "Output"], +Cell[12551, 314, 2482, 37, 238, "Output"] +}, Open ]], +Cell[CellGroupData[{ +Cell[15070, 356, 695, 16, 39, "Input"], +Cell[15768, 374, 28198, 466, 350, "Output"] +}, Open ]], +Cell[CellGroupData[{ +Cell[44003, 845, 123, 2, 39, "Input"], +Cell[44129, 849, 402, 9, 38, "Output"] +}, Open ]], +Cell[CellGroupData[{ +Cell[44568, 863, 389, 11, 39, "Input"], +Cell[44960, 876, 7886, 269, 166, "Output"] +}, Open ]] +} +] +*) + +(* End of internal cache information *) diff --git a/MathematicaFiles/Applications/Metropolis_working.m b/MathematicaFiles/Applications/Metropolis_working.m new file mode 100755 index 0000000..2eb2540 --- /dev/null +++ b/MathematicaFiles/Applications/Metropolis_working.m @@ -0,0 +1,68 @@ +With[{ + bfun = (Min[#] > -1 &), + vfun = (-#.#/2 &), + k = 1, + chol = {{1}} + }, + metFun = Compile[{ + {start, _Real, 1}, + {nOuter, _Integer, 0}, + {nInner, _Integer, 0}, + {nDrop, _Integer, 0} + }, + Drop[ + NestList[ + Nest[ + Function[sv, + Module[{p, pval}, + p = Most[sv] + + Table[Sqrt[-2 Log[RandomReal[]]] Cos[2 Pi RandomReal[]], {k}].chol; + If[bfun[p], + (* then *) + pval = vfun[p]; + If[pval >= Last[sv] + Log[RandomReal[]], + Append[p, pval], + sv] + , + (* else *) + sv] + ]], #, nInner] &, + start, nOuter + nDrop], + nDrop + 1] + ] + ]; + +cholfun = Function[{v, k}, + CholeskyDecomposition[ + Switch[ + TensorRank[v], + 0, v * IdentityMatrix[k], + 1, DiagonalMatrix[v], + 2, v + ]]] + +CompileNestFunction[vfun_, bfun_, chol_] := + With[{k = Length[chol]}, + Compile[{ + {start, _Real, 1}, + {nOuter, _Integer, 0}, + {nInner, _Integer, 0}, + {nDrop, _Integer, 0} + }, + Drop[ + NestList[ + Nest[ + Function[sv, + Module[{p, pval}, + p = Most[sv] + + Table[Sqrt[-2 Log[RandomReal[]]] Cos[2 Pi RandomReal[]], {k}].chol; + If[bfun[p], + pval = vfun[p]; + If[pval >= Last[sv] + Log[RandomReal[]], + Append[p, pval], + sv], + sv] + ]], #, nInner] &, + start, nOuter + nDrop], + nDrop + 1] + ]] diff --git a/MathematicaFiles/Applications/OddsandEnds.m b/MathematicaFiles/Applications/OddsandEnds.m new file mode 100755 index 0000000..67803c7 --- /dev/null +++ b/MathematicaFiles/Applications/OddsandEnds.m @@ -0,0 +1,1298 @@ +MoveFilesToDateBasedDirectories::usage = +"MoveFilesToDateBasedDirectories[holdingdirectory, \ +newparentdirectory]. The holdingdirectory is where the JPEGs and AVIs are \ +currently located and the newparentdirectory is where the date-based \ +subdirectories should be located. If only one directory is provided, \ +it is used for both directories." + +MoveFilesToDateBasedDirectories::nofiles = "There are no JPEGs or AVIs in `1`." + +MoveFilesToDateBasedDirectories[ + holdingdirectory_String, + newparentdirectory_String + ] := +Module[{oldnames, dates, newsubdirs, newnames}, + oldnames = FileNames[ + __ ~~ "." ~~ ("jpg" | "jpeg" | "avi"), + {holdingdirectory}, + IgnoreCase -> True]; + If[oldnames === {}, + Message[MoveJPEGsToDateBasedDirectories::nojpegs, holdingdirectory]; + Return[$Failed] + ]; + dates = (DateList /@ (Date /. FileInformation /@ oldnames))[[All, ;; 3]]; + newsubdirs = ToFileName[{ + newparentdirectory, + DateString[#, Riffle[{"Year", "Month", "Day"}, "-"]] + }] & /@ dates; + CreateDirectory /@ Union[newsubdirs]; + newnames = MapThread[ + ToFileName[{#1}, #2] &, + { + newsubdirs, + StringSplit[oldnames, "\\"][[All, -1]] + }]; + MapThread[RenameFile, {oldnames, newnames}] + ] + +MoveFilesToDateBasedDirectories[holdingdirectory_String] := + MoveFilesToDateBasedDirectories[holdingdirectory, holdingdirectory] + +ChineseRestaurantProcess::usage = "ChineseRestaurantProcess[\[Alpha], n] returns \ +a list of n patrons distributed among a random number of tables where the number \ +of tables is controlled by \[Alpha]. ChineseRestaurantProcess[\[Alpha], list] \ +returns a new list updated by one draw from the process." + +ChineseRestaurantProcess[ + a_ /; 0 <= a <= 1, + n_Integer?Positive + ] := + Module[{m, vec, r}, + m = 1; + vec[1] = 1; + Table[ + If[ + RandomReal[] < a, + (* then *) + vec[++m] = 1, + (* else *) + r = RandomInteger[{1, m}]; + ++vec[r] + ], + {n - 1} + ]; + Array[vec, m] + ] + +ChineseRestaurantProcess[a_, list:{}] := {1} + +(* +ChineseRestaurantProcess[a_, list:{__}] := + Module[{list1 = list, r}, + If[RandomReal[] < a, + (* then *) + Append[list1, 1], + (* else *) + r = RandomInteger[{1, Length[list]}]; + list1[[r]]++; + list1 + ] + ] +*) + +ChineseRestaurantProcess[a_, list:{__}] := + If[ + RandomReal[] < a, + Append[list, 1], + With[{r = RandomInteger[{1, Length[list]}]}, + ReplacePart[list, r -> list[[r]] + 1] + ] + ] + +RotateMatrix::usage = "RotateMatrix[matrix] rotates the matrix 90 degrees \ +clockwise. RotateMatrix[matrix, n] rotates the matrix n times. Negative n \ +produces counter-clockwise rotation." + +RotateMatrix[matrix_] := Table[Reverse@matrix[[All, i]], {i, Dimensions[matrix][[2]]}] + +RotateMatrix[matrix_, 1] := RotateMatrix[matrix] + +RotateMatrix[matrix_, -1] := Table[matrix[[All, i]], {i, Dimensions[matrix][[2]], 1, -1}] + +RotateMatrix[matrix_, n_Integer?Positive] := Nest[RotateMatrix, matrix, n] + +RotateMatrix[matrix_, n_Integer?Negative] := Nest[RotateMatrix[#, -1] &, matrix, -n] + +RotateMatrix[matrix_, 0] := matrix + +OpenURL::usage = "OpenURL[url] opens the url in the default browser." + +OpenURL[url_String] := NotebookLocate[{URL[url], None}] + +MinimumVarianceSampling::usage = +"MinimumVarianceSampling[weights -> x, n] returns a sample of size n \ +from x using the given weights (which need not be \ +normalized). It does so with a minimum of Monte Carlo \ +variance. For example, if the weights are all the same and \ +n == Length[weights], then x is returned. If n is omitted, \ +then a sample of Length[w] is returned. If x is omitted, then \ +Range[n] is used instead." + +MinimumVarianceSampling[w_List /; (Min[w] >= 0), n_Integer?Positive] := + mvsCompiled[w, n] + +MinimumVarianceSampling[w_List] := MinimumVarianceSampling[w, Length[w]] + +MinimumVarianceSampling[ + (w_List -> x_List) /; (Length[w]==Length[x] && Min[w] >= 0), + n_Integer?Positive] := x[[ mvsCompiled[w, n] ]] + +MinimumVarianceSampling[(w_List -> x_List)] := + MinimumVarianceSampling[w -> x, Length[w]] + +MinimumVarianceSampling[___] := $Failed + +(* c[[i]] is the number of children of the i-th parent + p[[j]] is the position of the parent of the j-th child + w is the list of nonnegative weights (need not be normalized) + M is the desired number of children + *) +mvsCompiled = Compile[{{w, _Real, 1}, {M, _Integer, 0}}, + Module[{ + c = (Rest[#] - Most[#])& @ + Floor[FoldList[Plus, 0, M * w/(Plus@@w)] - RandomReal[]], + p = Table[0, {M}], + j = 1}, + Do[ + Do[p[[j]] = i; j++, {c[[i]]}], + {i, Length[w]}]; + p + ]] + +LeapYearQ::usage = "LeapYearQ[year] returns True if the year is \ +a leap year and False otherwise." + +LeapYearQ[year_Integer|{year_Integer, ___}] := lyqCompiled[year] + +lyqCompiled = Compile[{{year, _Integer, 0}}, + Which[ + Mod[year, 400] == 0, True, + Mod[year, 100] == 0, False, + Mod[year, 4] == 0, True, + True,(* otherwise *) False + ] + ] + +DuplicateDittos::usage = "DuplicateDittos[data, dittomark] replaces \ +the dittomarks with values from \"above\". DuplicateDittos works on \ +vectors and matrices." + +DuplicateDittos[data_?VectorQ, ditto_] := + Rest@FoldList[If[#2 === ditto, #1, #2] &, 0, data] +DuplicateDittos[data_?MatrixQ, ditto_] := + Transpose[ DuplicateDittos[#, ditto] & /@ Transpose[data]] + +NormalizeSum::usage = "NormalizeSum[x] returns x/Plus@@x." + +NormalizeSum[x_] := x/(Plus @@ x) + +RunningMean::usage = "RunningMean[data] returns a list of \ +running means for the given data. RunningMean[data, k] \ +drops the first k values from the output." + +RunningMean[data_?(VectorQ[#, NumericQ] &), drop_:0] := + runningMeanCompiled[data, drop] + +runningMeanCompiled = Compile[{{data, _Real, 1}, {drop, _Integer, 0}}, + Module[{m = If[drop == 0, 0., Plus @@ Take[data, drop]/drop]}, + Table[ + m = (m (i - 1) + data[[i]])/i, + {i, drop + 1, Length[data]}] + ]]; + +MathematicaBook[] := + NotebookOpen[ + ToFileName[{$UserAddOnsDirectory, "Applications"}, + "The Virtual Mathematica Book (v6).nb"] + ] + +GetArguments::usage = "GetArguments[f] returns the list of dummy \ +arguments used in the definition of f." + +GetArguments[f_] := + Block[{x}, (* has no rules *) + Cases[DownValues[f] /. f -> x, x[args___] :> {args}[[All, 1]], Infinity] + ] + +StringHash::usage = "StringHash[string] returns the \"MD5\" hash \ +of the string without hashing the enclosing quotes. Other hash \ +types may be specified." + +StringHash[string_String, type_:"MD5"] := + Module[{stream, file, hash}, + stream = OpenWrite[]; + WriteString[stream, string]; + file = Close[stream]; + hash = FileHash[file, type]; + DeleteFile[file]; + hash + ] + +CheckSum::usage = "CheckSum[filename] prompts you for the MD5 checksum \ +in hexidecimal and returns True or False." + +CheckSum[file_String] := + IntegerString[FileHash[file, "MD5"], 16] === + InputString["Enter the hexidecimal MD5 checksum:"] + +FRBTextPoints::usage = "FRBTextPoints[list of strings]." + +FRBTextPoints[points:{__String}, opts:OptionsPattern[]] := + Graphics[ + {Inset[Text[Style[Grid[ + Transpose[{ + ConstantArray["\[FilledSmallCircle]", Length[points]], + points}], + Alignment -> Left, + ItemSize -> {{1, 15}, {1}}, + Spacings -> {0, 2}], 10]]] + }, + Frame -> {{True, True}, {True, True}}, + FrameTicks -> None, ImagePadding -> 20, + FrameStyle -> {{{}, {}}, {{Dashing[{0.1, 0.8, 0.1}]}, {Dashing[{0.1, 0.8, 0.1}]}}}, + opts + ] + +FRB::usage = "FRB[plotfun][args, opts] produces a plot that apes the \ +plots of the Federal Reserve Board. FRB takes the options FRBPlotLabel, \ +FRBPlotComment, and FRBPlotNote." + +Options[FRB] = { + FRBPlotLabel -> None, + FRBPlotComment -> None, + FRBPlotNote -> None + } + +FRB /: FRB[f_][args__, opts : OptionsPattern[]] := + Module[{plot, label, comment, note}, + {label, comment, note} = {FRBPlotLabel, FRBPlotComment, FRBPlotNote} /. + {opts} /. Options[FRB]; + plot = f[args, + Frame -> True, + FrameStyle -> {{}, {{}, {Dashing[{0.025, 0.95, 0.025}]}}}, + FrameTicks -> {{Automatic, Automatic}, {Automatic, None}}, + PlotRangeClipping -> False, + Evaluate[FilterRules[{opts}, Options[f]]] + ]; + Graphics[ + {plot[[1]], + If[label === None, {}, + Inset[Text[Style[label, 12]], Scaled[{0, 1}], {Left, Bottom}]], + If[comment === None, {}, + Inset[Text[Style[comment, 10]], Scaled[{1, 1}], {Right, Bottom}]], + If[note === None, {}, + Inset[Text[Style[Column[{"", "", note}], 8]], Scaled[{0, 0}], {Left, Top}]] + }, + PlotRange -> All, + plot[[2]] + ] + ] + +NormalizeOnObservation::usage = "NormalizeOnObservation[data, n] takes \ +a list of pairs and normalizes the second column using data[[2,n]]. If n \ +is omitted, then the first observation is used." + +NormalizeOnObservation[data : {{_, _} ..}, n_: 1] := + Transpose[{data[[All, 1]], data[[All, 2]]/data[[n, 2]]}] + +MapAtColumn::usage = "MapAtColumn[f, data, col] Maps f on data[[All, col]], \ +where col can be an integer or a list of integers. If f is a list and col is \ +a list of lists, then MapAtColumn Maps f[[1]] on columns col[[1]], etc." + +MapAtColumn[f_, data_, col_Integer] := + Transpose[MapAt[f /@ # &, Transpose[data], col]] + +MapAtColumn[f_, data_, cols:{__Integer}] := + Transpose[MapAt[f /@ # &, Transpose[data], Partition[cols, 1]]] + +MapAtColumn[f_List, data_, cols:{{__Integer}..}] := + Fold[MapAtColumn[ #2[[1]], #1, #2[[2]] ]&, data, Transpose[{f, cols}]] + +TicksFormat::usage = "TicksFormat[ticks, format] take a list \ +of ticks and a format function and returns an object suitable \ +for Ticks or FrameTicks. For example, \ +TicksFormat[Range[.03, .05, .0025], PaddedForm[100#, {3,2}]&]" + +TicksFormat[ticks_, format_] := Transpose[{ticks, format /@ ticks}] + +InnerJoin::usage = "InnerJoin[dataMain, dataAux, n] fills out the \ +dataMain with values from dataAux using the first n colums as the key." + +InnerJoin[dataMain_, dataAux_, n_] := + With[{i = Range[n]}, + Flatten[ + MapThread[ + Function[{x, y}, Join[#, x] & /@ y], + {SortBy[dataAux, #[[i]] &][[All, n + 1 ;;]], + Split[SortBy[dataMain, #[[i]] &], #1[[i]] == #2[[i]] &]} + ], + 1] + ] + +MergeByKey::usage = "MergeByKey[{data1, data2, ...}, n] merges \ +the datasets treating the first n columns of each dataset \ +as the key. If n is omitted, the first column is used as the key. \ +MergeByKey[datasets, list] uses the list of column numbers to \ +specify the key columns which are placed first in the merged dataset. \ +Only rows that have matching keys in all datasets appear in the \ +merged dataset. MergeByKey assumes there are no duplicate keys \ +in each of the datasets." + +MergeByKey[datalist:{__List}, n_:1] := + Module[{i, keylist, ikeys, poslist, dlist}, + i = Range[n]; + keylist = #[[All, i]] & /@ datalist; + ikeys = Intersection @@ keylist; + poslist = SubsetPosition[#, ikeys]& /@ keylist; + dlist = MapThread[#1[[#2, n + 1 ;;]] &, {datalist, poslist}]; + Join @@@ Transpose[Prepend[dlist, ikeys]] + ] + +MergeByKey[datalist:{__List}, index_List] := + Module[{orderlist}, + orderlist = + Flatten[Join[index, Complement[Range[Length[#[[1]]]], index]]]& /@ + datalist; + MergeByKey[MapThread[#1[[All, #2]]&, {datalist, orderlist}], Length[index]] + ] + +SubsetPosition::usage = "SubsetPosition[set, subset] returns the \ +positions of subset in the set, assuming both set and subset are \ +sorted and have no duplicates." + +SubsetPosition[superset:{__Integer}, subset:{__Integer}] := sspCompiled[superset, subset] + +SubsetPosition[superset_, subset_] := + Module[{i = 1}, + (While[superset[[i]] != #, i++]; i++) & /@ subset + ] + +sspCompiled = Compile[{ + {superset, _Integer, 1}, + {subset, _Integer, 1}}, + Module[{i = 1}, + (While[superset[[i]] != #, i++]; i++) & /@ subset + ]] + +SetSubtract::usage = "SetSubtract[s1, s2] removes elements of s2 \ +from s1, where s1 and s2 are lists." + +(* this is better than the rule-based version below *) +SetSubtract[s1_List, s2_List] := + Module[{t1, t2, n1, n2, i1, i2}, + {t1, t2} = Sort[Tally[#]] & /@ {s1, s2}; + {n1, n2} = Length /@ {t1, t2}; + i1 = i2 = 1; + While[ + i1 <= n1 && i2 <= n2, + Which[ + t1[[i1, 1]] === t2[[i2, 1]], + t1[[i1, 2]] -= t2[[i2, 2]]; + i1++; i2++, + OrderedQ[{t1[[i1, 1]], t2[[i2, 1]]}], + i1++, + True, + i2++ + ] + ]; + Flatten[Table[#[[1]], {#[[2]]}] & /@ Select[t1, #[[2]] > 0 &], 1] + ] + +(* modified code from Daniel, + using Tally which is very fast on integers + and with a different rule (Dan's didn't produce the correct result +SetSubtract1[a_List, b_List] := + Flatten@(Table[#[[1]], {#[[2]]}] & /@ + Select[ + ((Tally /@ {a, b}) //. + {{x1___, {x2_, x3_}, x4___}, {x5___, {x2_, x6_}, x7___}} :> + {{x1, {x2, x3 - x6}, x4}, {x5, x7}})[[1]], + #[[2]] > 0 &]) +*) + +HighestDensityRegion::usage = "HighestDensityRegion[distribution, p] \ +where distribution is a continuous univariate distribution and 0 <= p <= 1." + +HighestDensityRegion[distribution_, p_] := + Module[{x, y, x0, y0, min, max, mincond, maxcond}, + x0 = Quantile[distribution, 1/8]; + y0 = Quantile[distribution, 7/8]; + {min, max} = DistributionDomain[distribution][[1]]; + mincond = If[min == -Infinity, True, min <= x]; + maxcond = If[max == Infinity, True, y <= max]; + {x, y} /. FindMinimum[{ + y - x, + y - x > 0, + CDF[distribution, y] - CDF[distribution, x] == p, + mincond, + maxcond}, + {x, x0}, {y, y0}][[2]] + ] + +PickHighest::usage = "PickHighest[counts, fraction] takes a list of \ +bin counts and a fraction value between 0 and 1 and returns \ +the highest counts whose total equals the fraction." + +PickHighest[counts_, fraction_] := + Module[{v, c, o, r}, + v = counts[[All, -1]]; + c = fraction * Total[v]; + o = Ordering[v, All, Greater]; (* indices for reverse-order sort *) + r = Ordering[o]; (* indices to restore original order *) + Pick[counts, Thread[Accumulate[ v[[ o ]] ][[ r ]] <= c]] + ] + +Date2String::usage = "Date2String[{y, m, d}] or \ +Date2String[{{y1, m1, d1}, {y2, m2, d2}, ...}]." +String2Date::usage = "String2Date[\"yyyy-dd-mm\"] or \ +String2Date[{\"yyyy-dd-mm\", ...}]." + +Date2String[date:{_,_,_}] := + StringInsert[ToString @ (date.{10000, 100, 1}), "-", {5, 7}] + +Date2String[dates:{{_,_,_}..}] := + StringInsert[ToString /@ (dates.{10000, 100, 1}), "-", {5, 7}] + +String2Date[date_] := ToExpression @ StringSplit[date, "-"] + +String2Date[dates_] := ToExpression @ StringSplit[dates, "-"] + +ExportLines::usage = "ExportLines[filename, data] saves data to \ +an ASCII file. The data can be read with ImportLines[filename]." +ImportLines::usage = "ImportLines[filename] imports data saved \ +with ExportLines[filename, data]." + +ExportLines[filename_String, data_] := Export[filename, data, "Lines"] +ImportLines[filename_] := ToExpression[Import[filename, "Lines"]] + +SymmetricMatrixToVector::usage = "SymmetricMatrixToVector[mat] returns a \ +vector constructuced from the lower triangular part of the symmetric matrix \ +mat. See also VectorToSymmetricMatrix." + +VectorToSymmetricMatrix::usage = "VectorToSymmetricMatrix[vec] \ +returns a symmetric matrix constructed from the lower triangular \ +part stored in vec. See also SymmetricMatrixToVector." + +SymmetricMatrixToVector[mat_] := + Flatten[MapIndexed[Take[#1, #2[[1]]] &, mat]] + +(* the indexing trick is due to Ray Koopman *) +VectorToSymmetricMatrix[vec_] := + Module[{i, j, n}, + n = (Sqrt[1 + 8*Length[vec]] - 1)/2; + Table[ + vec[[ # (# - 1)/2 & @ Max[i, j] + Min[i, j] ]], + {i, n}, {j, n}] + ] + + +ColorLegendGrid::usage = "ColorLegendGrid[textlist, colorlist, (opts)] \ +returns a grid of colors and text which can be placed as a legend \ +in a graphic using Inset. ColorLegendGrid takes the options \ +FontSize and ColorPatchSize in addition to options to Grid." + +Options[ColorLegendGrid] := + Join[{FontSize -> 12, ColorPatchSize -> 12}, Options[Grid]] + + +ColorLegendGrid[textlist_, colorlist_, opts:OptionsPattern[]] := + With[{cps = OptionValue[ColorPatchSize]}, + Grid[ + MapThread[ + {Graphics[ + {#2, Style[Text["\[FilledSquare]"], cps]}, ImageSize -> cps + ], + Style[Text[#1], OptionValue[FontSize]]} & , + {textlist, colorlist} + ], + FilterRules[{opts}, Options[Grid]], + {Frame -> True, Alignment -> Left} + ]] + +PartsList::usage = "PartsList[z,n] takes a Symbol z and a positive \ +Integer n and returns of list of the form {z\[LeftDoubleBracket]1\ +\[RightDoubleBracket], ..., z\[LeftDoubleBracket]n\[RightDoubleBracket]}." + +PartsList[z_Symbol, n_Integer?Positive] := Quiet[Part[z, #] & /@ Range[n]] + +ArrayToParts::usage = "ArrayToParts[x, n] constructs Array[x, n] \ +and converts x[i] to x[[i]], where n is an integer or list of \ +integers." + +ArrayToParts[x_, n_] := Array[x, n] /. x[i__] :> x[[i]] //Quiet + +NestListNest::usage = "NestListNest[f, x0, nOuter, nInner] computes \ +NestList[f, x0, nInner * nOuter] and returns every nInner-th value." +FoldListFold::usage = "FoldListFold[f, x0, list, nInner] computes \ +FoldList[f, x0, list] and returns every nInner-th value." + +NestListNest[f_, x0_, nOuter_, nInner_] := + NestList[Nest[f, #, nInner] &, x0, nOuter] + +FoldListFold[f_, x0_, list_, nInner_] := + FoldList[Fold[f, ##] &, x0, Partition[list, nInner]] + +BrowseForFileName::usage = "BrowseForFileName[] opens a file browser \ +and returns the name of the selected file. BrowseForFileName[init] \ +uses init as the initial setting in the dialog." + +BrowseForDirectoryName::usage = "BrowseForDirectoryName[] opens a \ +directory browser and returns the name of the selected directory. \ +BrowseForDirectoryName[init] uses init as the initial setting in the \ +dialog." + +BrowseForDirectoryNameOfFile::usage = "BrowseForDirectoryNameOfFile[] \ +opens a file browser and returns the directory name of the selected file. \ +BrowseForDirectoryNameOfFile[init] uses init as the initial setting in the \ +dialog." + +BrowseForFileName[init___String] := + If[# === $Canceled, $Canceled, #]& @ SystemDialogInput["FileOpen", init] + +BrowseForDirectoryName[init___String] := + If[# === $Canceled, $Canceled, #]& @ SystemDialogInput["Directory", init] + +BrowseForDirectoryNameOfFile[init___String] := + If[# === $Canceled, $Canceled, DirectoryName[#]]& @ + SystemDialogInput["FileOpen", init] + +DaysInMonth::usage = "DaysInMonth[{year, month}] and \ +DaysInMonth[{year, month, day}] return the number of days in the \ +given month." + +DaysInMonth[{year_Integer?Positive, month_Integer?Positive, ___}] := + DateDifference[{year, month}, DatePlus[{year, month}, {1, "Month"}]] + +DaysInMonth[__] := $Failed + +randomChoice::usage = "randomChoice works the same as the built-in \ +function RandomChoice except that it allows for non-positive weights." + +randomChoice[w:{__?Positive} -> x_, n___] := RandomChoice[w -> x, n] + +randomChoice[w_ -> x_, n___] := + RandomChoice[Rule @@ Transpose[Pick[Transpose[{w, x}], w, _?Positive]], n] + +randomChoice[x___] := RandomChoice[x] + +BlockDiagonalMatrix::usage = "BlockDiagonalMatrix[listOfBlocks] returns a \ +block-diagonal matrix constructed from the given list of matrices." + +BlockDiagonalMatrix[blocks:{__?MatrixQ}] := + ArrayFlatten[ + MapThread[#1 /. #2 &, + {IdentityMatrix[Length[blocks]], Thread[1 -> blocks]} + ] + ] + +BlockDiagonalMatrix[___] := $Failed + +binnedDensityPlot::usage = "binnedDensityPlot[data, xbins, ybins]." + +Clear[binnedDensityPlot] + +binnedDensityPlot[ + data:{{_?NumericQ, _?NumericQ} ..}, + xbins:{{_?NumberQ ..}}, + ybins:{{_?NumberQ ..}}, + opts___?OptionQ + ] := + ListDensityPlot[ + Transpose[BinCounts[data, xbins, ybins]], + opts, + ColorFunction -> (GrayLevel[1 - #1^0.5] & ), + DataRange -> {xbins[[1,{1,-1}]], ybins[[1,{1,-1}]]}, + PlotRange -> All, + InterpolationOrder -> 0, + AspectRatio -> Automatic + ] + +binnedDensityPlot[ + data : {{_?NumericQ, _?NumericQ} ..}, + dx_?NumericQ, + dy_?NumericQ, + opts___?OptionQ + ] := + binnedDensityPlot[data, ##, opts]& @@ MapThread[ + {Range[Ceiling[Min[#1] - #2, #2], Floor[Max[#1] + #2, #2], #2]}&, + {Transpose[data], {dx, dy}} + ] + +binnedDensityPlot[ + data : {{_?NumericQ, _?NumericQ} ..}, + dx_?NumericQ, + opts___?OptionQ + ] := + binnedDensityPlot[data, dx, dx, opts] + +binnedDensityPlot[ + data : {{_?NumericQ, _?NumericQ} ..}, + xbins:{xmin_, xmax_, dx_}, + ybins:{ymin_, ymax_, dy_}, + opts___?OptionQ + ] := + binnedDensityPlot[data, {Range@@xbins}, {Range@@ybins}, opts] + +binnedDensityPlot[ + data : {{_?NumericQ, _?NumericQ} ..}, + xbins:{xmin_, xmax_, dx_}, + opts___?OptionQ + ] := + binnedDensityPlot[data, xbins, xbins, opts] + +binnedDensityPlot[ + data : {{_?NumericQ, _?NumericQ} ..}, + {nxbins_Integer?Positive}, + {nybins_Integer?Positive}, + opts___?OptionQ + ] := + binnedDensityPlot[data, ##, opts]& @@ MapThread[ + ((Max[#1] - Min[#1])/#2)&, + {Transpose[data], {nxbins, nybins}} + ] + +binnedDensityPlot[ + data : {{_?NumericQ, _?NumericQ} ..}, + {nxbins_Integer?Positive}, + opts___?OptionQ + ] := + binnedDensityPlot[data, {nxbins}, {nxbins}, opts] + +SequentialIntegerStrings::usage = +"SequentialIntegerStrings[n, start, digits] produces a list of n \ +sequential integers as strings. The starting number is 1 unless \ +otherwise specified by start. The total number of digits is determined \ +automatically unless specified by digits." + +SequentialIntegerStrings[n_Integer?Positive, start_:1, digits_:1] := + With[{ + len = Max[IntegerLength[n + start - 1], digits] + }, + Table[IntegerString[i, 10, len], {i, start, n + start - 1}] + ] + +SequentialFileNames::usage = +"SequentialFileNames[base, ext, n, start, digits] produces a list \ +of n sequential files names of the form baseXXX.ext, where base \ +and ext are Strings. The starting number is 1 unless otherwise \ +specified by start. The total number of digits is determined \ +automatically unless more digits are specified by digits." + +SequentialFileNames[base_String, extension_String, n_Integer?Positive, + start_:1, digits_:1] := + (base <> # <> "." <> extension & /@ SequentialIntegerStrings[n, start, digits]) + +SequentialSymbols::usage = "SequentialSymbols[x, n, start, digits] where x is a \ +symbol or a string and n is an integer returns a list of symbols of the form \ +{x1, x2, ..., xn}. The arguments start and digits are optional." + +SequentialSymbols[base_Symbol, n_Integer?Positive, start_:1, digits_:1] := + (Symbol[SymbolName[base] <> #]& /@ SequentialIntegerStrings[n, start, digits]) + +SequentialSymbols[base_String, n_Integer?Positive, start_:1, digits_:1] := + (Symbol[base <> #]& /@ SequentialIntegerStrings[n, start, digits]) + +SequentialSymbols[_, 0, ___] := {} + +$StandardPackages::usage = "$StandardPackages is a list of standard packages." + +$LegacyPackages::usage = "$LegacyPackages is a list of legacy packages." + +$StandardPackages := # <> "`" & /@ + StringSplit[ + FileNames["*", + ToFileName[{$InstallationDirectory, "AddOns", "Packages"}]], + $PathnameSeparator][[All, -1]] + +$LegacyPackages := (#1 <> "`" <> #2 <> "`") & @@@ + StringSplit[ + FileNames["*.m", + ToFileName[{$InstallationDirectory, "AddOns", "LegacyPackages"}], + 2], + {$PathnameSeparator, "."}][[All, {-3, -2}]] + +Ghost::usage = "Ghost[string] returns a list of letters that will \ +not form a word and the associated longer words." + +Ghost::wordalready = "`1` already contains a word with four or more characters." + +Ghost[str_String]:= + Module[{len, found, next, groups}, + len = StringLength[str]; + If[len > 3 && DictionaryLookup[Table[StringTake[str,i], {i,4,len}]] != {}, + Message[Ghost::wordalready, str]]; + found = DictionaryLookup[str~~a:_~~__ /; (a != "-" && DictionaryLookup[str<>a] == {})]; + next = StringCases[found, str~~a:_~~__ :> a][[All,1]]; + groups=Split[Transpose[{next,found}], #1[[1]]==#2[[1]]&][[All,All,2]]; + (* eliminate words with valid substrings *) + groups = Function[group, + With[{chars = Characters /@ group}, + Pick[group, + Function[word, Or @@ + ((Length[word] > Length[#] && Take[word, Length[#]] == #) & /@ chars)] /@ chars, + False]]] /@ groups; + If[next == {}, + words = DictionaryLookup[str~~_]; + If[words == {}, + Print["There are no valid words."], + Print["The only valid words are:"]; + Column[words] + ], + Grid[{Union[next], Column /@ groups}, Dividers->All, Alignment->Top] + ] + ] + +FixUsageMessages::usage = "FixUsageMessages[package] reads in the \ +package, appends \" \\\" to the ends on the lines of the usage \ +statements, and writes the package back out." + +FixUsageMessages[package_String] := + Module[{in, patts, newpatts}, + in = Import[package, "String"]; + patts = Flatten[ + StringCases[ + StringCases[in, Shortest["::usage" ~~ __ ~~ "\n\n"]], + Longest["\"" ~~ __ ~~ "\""]] + ]; + newpatts = StringReplace[patts, "\n" -> " \\\n"]; + Export[package, + StringReplace[in, Thread[patts -> newpatts]], + "String"] + ] + +GetStringsWithinText::usage = "GetStringsWithinText[text] extracts the \ +strings with the given text (string), ignoring quoted strings." + +RemoveEndLineSlashes::usage = "RemoveEndLineSlashes[text] removes \ +slashes at the ends of strings within the given text." + +InsertEndLineSlashes::usage = "InsertEndLineSlashes[text] inserts \ +slashes at the ends of strings within the given text." + +GetStringsWithinText[text_String] := + StringTake[text, + Partition[Complement[ + StringPosition[text, "\""][[All, 1]], StringPosition[text, "\\\""][[All, 2]]], + 2]] + +RemoveEndLineSlashes[text_String] := + With[{strings = GetStringsWithinText[text]}, + StringReplace[text, + Table[strings[[i]] -> StringReplace[strings[[i]], "\\\n" -> "\n"], + {i, Length[strings]}]] + ] + +InsertEndLineSlashes[text_String] := + With[{strings = GetStringsWithinText[text]}, + StringReplace[text, + Table[strings[[i]] -> StringReplace[strings[[i]], "\n" -> "\\\n"], + {i, Length[strings]}]] + ] + +IrregularTranspose::usage = "IrregularTranspose[lists] takes a list \ +of lists of possibly different lengths and \"transposes\" them. \ +As an example try IrregularTranspose[{{1},{2,3},{4,5,6}}]. \ +IrregularTranspose takes an optional second argument to change the \ +\"padding symbol\" from Null to something else if necessary." + +IrregularTranspose[lists_, null_: Null] := + DeleteCases[Transpose[PadRight[lists, Automatic, null]], null, {2}] + +(* try to fix windows path names *) +FixWindowsPathName::usage = "FixWindowsPathName[pathname] replaces \"\\x\" +with \"\\\\x\" everywhere in pathname. To use, paste a pathname between the +quotes in FixWindowsPathName[\"\"]. (If the last character in the pathname to +be pasted is \"\\\", remove it.) It may not work for \"\\.nn\" where nn is an +integer or other such sequences." + +FixWindowsPathName[pathname_String] := + StringReplace[pathname, + {"\b" -> "\\b", "\f" -> "\\f", "\n" -> "\\n", "\r" -> "\\r", "\t" -> "\\t"} + ] + +NProtect::usage = "NProtect[f[args]] returns f[args] if all the arguments \ +are numeric and otherwise returns unevaluated. NProtect[f[{args}]] works \ +similarly. This is useful in conjunction with functions like FindMaximum \ +and FindRoot." + +SetAttributes[NProtect, HoldAll] +NProtect[f_[{args__}]] := f[{args}] /; And @@ (NumericQ /@ {args}) +NProtect[f_[args__]] := f[args] /; And @@ (NumericQ /@ {args}) + +CheckCompiledFunction::usage = "CheckCompiledFunction[cf] returns a list of \ +non-numerical values in Flatten[cf[[4]]]." + +CheckCompiledFunction[cf_CompiledFunction] := + Cases[cf[[4]] // Flatten, _?(!NumericQ[#] &)] + +(* from Todd Gayley on mathgroup *) +(* give an explicit format to keep Import from getting confused *) +HttpImport[url_String, format_String] := + Module[{tempFile, result}, + tempFile = Utilities`URLTools`FetchURL[url, Close[OpenTemporary[]]]; + result = Import[tempFile, format]; + DeleteFile[tempFile]; + result + ] + +InterpolatingFunctionToPiecewiseFunction::usage = +"InterpolatingFunctionToPiecewiseFunction[ifun] returns a Piecewise wrapped \ +in a Function that evaluates to 0 outside the range of the (univariate) \ +InterpolatingFunction." + +InterpolatingFunctionToPiecewiseFunction[ + ifun : InterpolatingFunction[{{min_, max_}},__], val_:0] := + Block[{x}, Function @@ {x, Piecewise[{{ifun[x], min <= x <= max}, {val, True}}]}] + +FindBoundary::usage = "FindBoundary[tensor] takes a tensor of zeros and \ +ones (a List or a SparseArray), where the ones represent a region, and \ +returns a list of boundary points. Setting the option ReturnSparseArray -> \ +True causes FindBoundary to return a SparseArray object instead. To convert \ +a list of indices into tensor (for input), use SparseArray[Thread[indices \ +-> 1], dimensions]." + +ReturnSparseArray::usage = "ReturnSparseArray is an option for FindBoundary \ +that specifies whether to return a SparseArray tensor representation of the +boundary instead of the indices." + +Options[FindBoundary] = {ReturnSparseArray -> False} + +FindBoundary[tensor_List, opts___?OptionQ] := + FindBoundary[SparseArray[tensor], opts] + +FindBoundary[tensor_SparseArray, opts___?OptionQ] := + Module[{rank, adj, indices, order, rules}, + rank = TensorRank[tensor]; + adj = Table[If[i == 1, 1, 0], {i, rank}]; + indices = Union @@ + Table[ + order = RotateLeft[Range[rank], i - 1]; + rules = Most @ + ArrayRules[(Rest[#] - Most[#])&[Transpose[tensor, order]]]; + Join[ Cases[rules, (x_ -> -1) :> x], + Cases[rules, (x_ -> 1) :> x + adj] ][[All, order]], + {i, rank}]; + If[TrueQ[ReturnSparseArray /. {opts} /. Options[FindBoundary]], + SparseArray[Thread[indices -> 1], Dimensions[tensor]], + indices] + ] /; (Union[ArrayRules[tensor][[All, 2]]] === {0, 1} && + Min[Dimensions[tensor]] > 1) + +FindBoundary[__] := $Failed + +SplitToWeights::usage = "SplitToWeights[x] computes Split[x] \ +and returns the first element in each group paired with its \"weight\" \ +(the length of the group divided by Length[x])." + +SplitToWeights[x_] := + With[{s = Split[x], n = N[Length[x]]}, + Transpose[{s[[All, 1]], (Length /@ s)/n}] + ] + +TallyToWeights::usage = "TallyToWeights[list] computes Tally[list] \ +but returns the counts normalized by Length[list]." + +TallyToWeights[list_] := + Transpose[MapAt[#/Length[list]&, Transpose[Tally[list]], 2]] + +ShowStatus::usage = "ShowStatus[expr] prints expr in the status line of \ +the notebook. (Note expr may be a sequence.)" +ShowStatus[x__] := + If[$FrontEnd === Null, + (* then: no front end, do nothing *) + Null, + (* else *) + LinkWrite[$ParentLink, + SetNotebookStatusLine[EvaluationNotebook[], + StringJoin @@ Map[ToString, {x}]] + ] + ] + +UnevenPartition::usage = "UnevenPartition[list, lengths] returns the list \ +partitioned into groups with the specified successive lengths." +UnevenPartition[list_List, lengths : {__Integer?Positive}] := + Take[list, {1, 0} + #] & /@ + Partition[ + TakeWhile[FoldList[Plus, 0, lengths], # <= Length[list]&], + 2, 1] + +(* older verion: +UnevenPartition[list_, lengths_] := First@Fold[Regroup, {{}, list}, lengths] + +Regroup[{a_, b_}, n_] := {Append[a, Take[b, n]], Drop[b, n]} +*) + +PartitionWithTail::usage = "PartitionWithTail[expr, n] partitions expr into subsets \ +of length n, expect possibly for the last subset, which can be less than n. \ +PartitionWithTail[expr, {n, m}] partitions expr into submatrices of \ +dimension n \[Times] m, except for the bottom-most and right-most blocks, \ +which may be smaller. To partition into blocks of m columns, use \ +PartitionWithTail[expr, {n, m}][[1]] where n is the number of rows in expr." + +PartitionWithOverhang::usage = "PartitionWithOverhang is the same as \ +PartitionWithTail (which see)." + +PartitionWithOverhang[x__] := PartitionWithTail[x] + +PartitionWithTail[expr_, n_Integer?Positive] := + Partition[expr, n, n, 1, {}] + +PartitionWithTail[expr_, {n_Integer?Positive, m_Integer?Positive}] := + (Transpose /@ PartitionWithTail[Transpose[#], m])& /@ + PartitionWithTail[expr, n] + +ExtendInterpolatingFunction::usage = +"ExtendInterpolatingFunction[ifun, val:0] returns a pure function that \ +extends to domain of the InterpolatingFunction ifun. The second \ +argument determines the value returned outside the original domain." + +ExtendInterpolatingFunction[ifun_, val_:0] := + With[{a = ifun[[1, All, 1]], b = ifun[[1, All, 2]]}, + Piecewise[{{ifun[##1], And @@ Thread[a <= {##1} <= b]}}, val]& + ] + +Duplicates::usage = "Duplicates[list] returns a sorted list of elements \ +that appear more than once in the given list." + +Duplicates[list_] := + Flatten[ + Reap[ + Scan[ + If[Length[#] > 1, Sow[First@#]]&, + Split[Sort[list]] + ] + ][[2]] + ] + +PointInPolygonQ::usage = "PointInPolygonQ[pt, poly] returns True \ +if the specified point is in the specified (closed) polygon and \ +False otherwise." + +PointInPolygonQ[pt:{x0_, y0_}, poly_?ClosedLineQ] := + Module[{poly1, one, two, dpp, Mx, my, d, dp}, + poly1 = Drop[poly, -1]; + one = Subtract @@@ Partition[poly, 2, 1]; + two = # - pt & /@ poly1; + dpp = Det /@ Transpose[{one, two}]; + Mx = Max[Abs[ poly1[[All, 1]] - x0 ]]; + my = Min[Select[ Abs[ poly1[[All, 2]] - y0], Positive]]; + {d, dp} = Map[Det[{{2 * Mx, my}, #}]&, {one, two}, {2}]; + OddQ @ Count[Transpose[{dp * (d - dp), dp * dpp}], + {_?Positive, _?Positive}] + ] + +PointInPolygonQ[pt:{x0_, y0_}, poly_?ClosedLineQ] := + If[poly === {{}}, False, pipQ[pt, poly]] + +pipQ = Compile[{{pt, _Real, 1}, {poly, _Real, 2}}, + Module[{poly1, ppoly, one, two, dpp, Mx, my, d, dp, vals}, + poly1 = Drop[poly, -1]; + ppoly = Partition[poly, 2, 1]; + one = #[[1]] - #[[2]] & /@ ppoly; + two = # - pt & /@ poly1; + dpp = #[[1, 1]]#[[2, 2]] - #[[1, 2]]#[[2, 1]] & /@ Transpose[{one, two}]; + Mx = Max[Abs[poly1[[All, 1]] - pt[[1]]]]; + my = Min[Select[Abs[poly1[[All, 2]] - pt[[2]]], Positive]]; + {d, dp} = Map[#[[1, 1]]#[[2, 2]] - #[[1, 2]]#[[2, 1]]& [{{2*Mx, my}, #}] &, + {one, two}, {2}]; + vals = Transpose[{dp*(d - dp), dp*dpp}]; + OddQ @ Tr[If[#[[1]] > 0 && #[[2]] > 0, 1, 0]& /@ vals] + ]] + +ClosedLineQ[line_] := + TrueQ[MatchQ[line, {{_,_}...} | {{}}] && line[[1]] == line[[-1]]] + +(* from Alan Hayes *) +ClosedLineArea[pts_] := + (#1.RotateLeft[#2] - RotateLeft[#1].#2)& @@ Transpose[pts]/2 + +GetContourLines::usage = "GetContourLines[g] returns a list of the closed +contour lines from the ContourGraphics object g." + +GetContourLines[g_ContourGraphics] := + Cases[Graphics[g], Line[x_?ClosedLineQ] -> x, Infinity] + +GroupContourLines::usage = "GroupContourLines[lines] takes a list of closed \ +contour lines (as produced by GetContourLines) and groups them by elevation. \ +For example, a bimodal distribution may produce two distinct contour \ +lines for the same elevation. The groups are sorted from smallest to largest \ +in area." + +GroupContourLines[g_ContourGraphics] := GroupContourLines[GetContourLines[g]] + +GroupContourLines[lines_] := + Module[{nullpoly, inlist, outlist, i}, + nullpoly = {{}}; + inlist = Reverse[ + Sort[Transpose[{ClosedLineArea /@ lines, lines}]][[All, 2]]]; + outlist = {{nullpoly}}; + While[Length[inlist] > 0, + i = 1; + While[ + Or @@ (PointInPolygonQ[First[inlist[[1]]], #] & /@ outlist[[i]]), + i++ + ]; + outlist = ReplacePart[outlist, Prepend[outlist[[i]], inlist[[1]]], i]; + If[Last[outlist] =!= {nullpoly}, + outlist = Append[outlist, {nullpoly}]]; + inlist = Rest[inlist] + ]; + Reverse[ Drop[Drop[#, -1]& /@ outlist, -1] ] (* smallest first *) + ] + +SelectPointsByContourGroups::usage = +"SelectPointsByContourGroups[points, groups] takes a list of points and +a list of grouped contour lines and returns the points grouped by the +contour regions." + +SelectPointsByContourGroups[pts_, groups_] := + Append[#1, #2]& @@ + Fold[ + Function[s, {Append[#1[[1]], s], Complement[#1[[2]], s]}] @ + Select[#1[[2]], Function[x, Or @@ (pipQ[x, #]& /@ #2)]]&, + {{}, pts}, + groups] + +CountPointsByContourGroups::usage = +"CountPointsByContourGroups[points, groups] takes a list of points and +a list of grouped contour lines and returns the number of points in each +contour region." + +CountPointsByContourGroups[pts_, groups_] := + Length /@ SelectPointsByContourGroups[pts, groups] + +SampleFromContourGroups::usage = "SampleFromContourGroups[points, groups, n] +samples from the specified points and returns a frequency list of the contours +the sampled points fall in." + +SampleFromContourGroups[pts_?MatrixQ, groups_List, n_Integer] := + Module[{len = Length[pts], tab}, + tab = Table[ + pt = pts[[ Random[Integer, {1, len}] ]]; + i = 1; + While[ + i <= Length[groups] && + Not[Or @@ (pipQ[pt, #] & /@ groups[[i]])], + i++]; + i, + {n}]; + RelativeFrequency[tab] + ] + +(* these assume one per group, flattened: +SelectPointsInContours[pts_, polys_] /; And@@(ClosedLineQ /@ polys) := + FoldList[ + Select[#1, Function[x, pipQ[x, #2]]]&, + pts, + Reverse[Sort[Transpose[{ClosedLineArea/@#, #}]][[All,2]]]& @ polys + ] + +CountPointsInContours[pts_, polys_] /; And@@(ClosedLineQ /@ polys) := + Length /@ SelectPointsInContours[pts, polys] +*) + +(* example: (requires Histogram) + +ran = RandomArray[MultinormalDistribution[{0, 0}, {{2, 1}, {1, 1}}], 10^4]; +bcp = BinnedContourPlot[ran, 12, Contours -> 9]; +groups = GroupContourLines[GetContourLines[bcp]]; +sel = SelectPointsByContourGroups[ran, groups]; +DotPlot[Length[#]/10^4 & /@ sel]; +Show[bcp, Graphics[Point /@ #], + PlotRange -> {Through[{Min, Max}[ran[[All, 1]]]], + Through[{Min, Max}[ran[[All, 2]]]]}] & /@ sel; + +*) + +(***** end of point in polygon stuff *****) + +(* PlayList usage: + ran = RandomArray[LogNormalDistribution[1, .2], 50]; + PlayList[ran,.1]; + *) + +PlayTone[tone_?NumericQ, duration_?NumericQ, opts___?OptionQ] := + Play[Sin[2 * Pi * tone * 256 * t], {t, 0, duration}, opts] + +PlayList[tones_List, duration_?NumericQ, opts___?OptionQ] := + Show[PlayTone[#, duration, opts, DisplayFunction -> Identity] & /@ tones, + DisplayFunction -> $SoundDisplayFunction] + +PlayList[tones_List, durations_List, opts___?OptionQ] := + Show[MapThread[PlayTone[#1, #2, opts, DisplayFunction -> Identity]&, + {tones, durations}], DisplayFunction -> $SoundDisplayFunction] + +NearestNeighborDensity::usage = "NearestNeighborDensity[x, data, k] +returns the value of the k-th nearest neighbor density estimate +of the data at x. Larger values of k produce smoother density estimates +(as a function of x). If k is omitted, the default value +Floor[Sqrt[Length[data]]] is used." + +NearestNeighborDensity[x_?NumericQ, data_List, k_Integer?Positive] := + k/(2Length[data]Sort[Abs[data - x]][[k]]) + +NearestNeighborDensity[x_?NumericQ, data_List] := + NearestNeighborDensity[x, data, Floor[Sqrt[Length[data]]]] + +NRound::usage = "NRound[x, n] returns N[Round[x, 10^-n]]. The \ +default value for n is 5." + +NRound[x_, n_:5] := N[Round[x * 10^n]/10^n] + +NRound[x_, n_:5] := N[Round[x, 10^-n]] + +(* An absolute value function that has a derivative, which equals + the sign function except at 0 where abs'[0] = 1 rather than 0. + After simplification, the derivative is (2 UnitStep[x] - 1). *) +abs[x_] := x * (2 UnitStep[x] - 1) +(* this imposes the simplification *) +Derivative[1][abs] = 2 UnitStep[#1] - 1 & + +(* +FindMaximum[f_, x__] := {-1, 1} * FindMinimum[-f, x] +*) + +GoldenString = (* a.k.a. Fibonacci String and Rabbit Sequence *) + Compile[{{n, _Integer}}, + Module[{i = 1}, + If[Length[#] > n, Drop[#, -1], #] & @ + NestWhile[ + Join[#, If[#[[ ++i ]] == 0, {1}, {1, 0}]] &, + {1, 0}, + Length[#] < n & + ] + ]] + +rab[0] := 0 +rab[1] := 1 +rab[n_] := {rab[n - 1], rab[n - 2]} +RabbitString[n_Integer /; n >= 2] := Flatten[rab[n]] + +(* Usage: NestPlot[4#(1-#)&, N[1/7, 100], 10, {x, 0, 1}] *) + +NestPlot[fun_, x0_, n_, {x_Symbol, xmin_:0, xmax_:1}, opts___OptionQ] := + Module[{list, s, path, pathplot, baseplot}, + list = Partition[Take[Flatten[Partition[NestList[fun, x0, n], 2, 1] /. + {a_, b_} -> {a, a, b, b}], {2, -2}], 2]; + s = list[[1, 1]]; + path = Join[{{s, s}}, list]; + pathplot = ListPlot[path, PlotJoined -> True, PlotStyle -> Red, + DisplayFunction -> Identity]; + baseplot = Plot[{x, fun[x]}, {x, xmin, xmax}, AspectRatio -> Automatic, + DisplayFunction -> Identity]; + Show[baseplot, pathplot, DisplayFunction -> $DisplayFunction] + ] + +UltimateHead[expr_] := NestWhile[Head, expr, # =!= Symbol &, 1, Infinity, -1] + +ListNest::usage = "ListNest[x] returns {x[[{1}]], x[[{1, 2}]], + x[[{1, 2, 3}]], ..., x}." + +ListNest[x_] := Table[Take[x, i], {i, Length[x]}] + +mySeries[expr_, ranges : {_, _, _} .., opts___?OptionQ] := + Module[{args, n, f}, + args = First /@ {ranges}; + n = Min[Last /@ {ranges}]; + Series[f @@ args, ranges, opts] /. + Derivative[d__][f] /; Plus[d] > n -> (0&) /. + f -> Function @@ {args, expr} + ] + +mySeriesCoefficients[expr_, ranges : {_, _, _} .., opts___?OptionQ] := + Module[{i, n, indices}, + n = Min[Last /@ {ranges}]; + indices = Array[i, Length[{ranges}]]; + Table[SeriesCoefficient[mySeries[expr, ranges, opts], indices], + Evaluate[Sequence@@Thread[{indices, 0, n}]]] + ] + +series[f_, v_List, v0_List, order_] := + Module[{t}, + Normal[Series[f /. Thread[v -> t*v + v0], {t, 0, order}]] /. + t -> 1 /. Thread[v -> v - v0] + ] + +(* this is due to someone else *) +(* replaces each occurence of a given value after the first with Sequence[] *) +UnsortedUnion[x_] := Module[{f}, f[y_] := (f[y] = Sequence[]; y); f /@ x] + +(* to combine and separate RGB triples *) +RGBCombine[rgb : {rMat_, gMat_, bMat_}] := Transpose[rgb, {3, 1, 2}] +RGBSeparate[rgbRaster_] := Transpose[rgbRaster, {2, 3, 1}] + + +(* NInvert and Invert adapted from Carl Woll's NInverse *) + +NInvert::usage = "Given f[x[y]] == y, what is x? Simply differentiate with +respect to the dependent variable (y) yielding f'[x[y]]x'[y] == 1. +NInvert[f, {x0, y0}, x, {y, ymin, ymax}] returns the output from NDSolve." + +NInvert[f_, {x0_?NumericQ, y0_?NumericQ}, x_Symbol, + {y_Symbol, ymin_?NumericQ, ymax_?NumericQ}, opts___?OptionQ] := + NDSolve[{f'[x[y]]x'[y] == 1, x[y0] == x0}, x, {y, ymin, ymax}, opts] + +Invert::usage = "Given f[x[y]] == y, what is x? Simply differentiate with +respect to the dependent variable (y) yielding f'[x[y]]x'[y] == 1. +Invert[f, {x0, y0}, x, y] returns the output from DSolve." + +Invert[f_, {x0_, y0_}, x_Symbol, y_Symbol] := + DSolve[{f'[x[y]]x'[y] == 1, x[y0] == x0}, x, y] + +(* to format TeXForm: +Unprotect[Times] +Format[a_*E^(b_),TeXForm]:= a HoldForm[e^b] +Protect[Times] +*) + +ConvertCPI::usage = "ConvertCPI[fromYear, toYear] returns how much a +fromYear dollar would be worth in the the toYear (according to the CPI)." + +ConvertCPI[fromYear_, toYear_] := + Cases[annualCPI, {toYear, cpi_} -> cpi][[1]]/ + Cases[annualCPI, {fromYear, cpi_} -> cpi][[1]] + +InflationRate[fromYear_, toYear_] := + Log[ConvertCPI[fromYear, toYear]]/(toYear - fromYear) + +InflationRate[year_] := InflationRate[year-1, year] + +annualCPI = +{{1947, 22.458}, {1948, 24.179}, {1949, 23.942}, + {1950, 24.197}, {1951, 26.122}, {1952, 26.717}, + {1953, 26.922}, {1954, 27.017}, {1955, 26.946}, + {1956, 27.346}, {1957, 28.272}, {1958, 29.046}, + {1959, 29.312}, {1960, 29.753}, {1961, 30.072}, + {1962, 30.424}, {1963, 30.805}, {1964, 31.213}, + {1965, 31.706}, {1966, 32.652}, {1967, 33.558}, + {1968, 34.983}, {1969, 36.883}, {1970, 39.042}, + {1971, 40.725}, {1972, 42.058}, {1973, 44.667}, + {1974, 49.583}, {1975, 54.125}, {1976, 57.25}, + {1977, 60.958}, {1978, 65.55}, {1979, 73.05}, + {1980, 82.9}, {1981, 91.4}, {1982, 96.883}, + {1983, 99.825}, {1984, 103.283}, {1985, 106.908}, + {1986, 108.575}, {1987, 112.492}, {1988, 116.95}, + {1989, 122.608}, {1990, 129.05}, {1991, 134.258}, + {1992, 138.15}, {1993, 142.067}, {1994, 145.642}, + {1995, 149.75}, {1996, 154.142}, {1997, 157.558}, + {1998, 159.667}, {1999, 163.225}, {2000, 168.892}, + {2001, 173.492}, {2002, 175.378}}; + +(* for PhotoShop Elements *) +PSEMargin::usage = "PSEMargin[d] returns the correct margin to use for +the HP DeskJet 720C when printing from PhotoShop Elements, where d is +measured in inches. In portrait orientation d is the height and the +margin is the top; in landscape orientation d is the width and the +margin is the left." + +PSEMargin[d_] := NRound[5.46 - .5d + 1/32, 2] + +RecursiveSolve[list_] := + Fold[Join[#1, First@Solve[#2 /. #1]] &, {}, list] +RecursiveSolve[list_, soln0:{Rule[_, _] ..}] := + Fold[Join[#1, First@Solve[#2 /. #1]] &, soln0, list] +RecursiveNSolve[list_] := + Fold[Join[#1, First@NSolve[#2 /. #1]] &, {}, list] +RecursiveNSolve[list_, soln0:{Rule[_, _] ..}] := + Fold[Join[#1, First@NSolve[#2 /. #1]] &, soln0, list] + +ResizeImage::usage = "ResizeImage[existingFileName, resizedFileName, size] +calls ImageMagick's convert routine." + +ResizeImage[originalFileName_, newFileName_, size_:600] := + Run[ToString[ + StringForm["convert `1` -resize `2` `3`", + originalFileName, size, newFileName] + ] + ] + diff --git a/MathematicaFiles/Applications/PagePrint.m b/MathematicaFiles/Applications/PagePrint.m new file mode 100755 index 0000000..406d7a8 --- /dev/null +++ b/MathematicaFiles/Applications/PagePrint.m @@ -0,0 +1,143 @@ +(* :Title: PagePrint *) + +(* :Author: Mark Fisher *) + +(* :Mathematica Version: 6.0 *) + +(* :History: Original version, December 2004 + June 2007 Updated for Version 6 with help from John Fultz +*) + +(* :References: Adapted from code written at my request by +John Fultz, jfultz@wolfram.com *) + +PagePrint::usage = +"PagePrint[graphic, opts] prints the graphic on a blank \ +page. The option LandscapeOrientation can be either True or False \ +(default). Run PagePrint[] to select which printer to use (if not \ +the default printer). The page orientation of the printer should be \ +portrait even if landscape orientation is desired. The \ +option PageMargins specifies the page margins in inches. The default is 1. \ +Horizontal and vertical page margins may be specified separately. \ +The image is resized to fill the space within the margins. The \ +option ImageDimensions is ignored with the default setting Automatic. \ +Setting ImageDimensions -> {w, h} overrides the PageMargins option and \ +places the image in a centered rectangle (w \[Times] h) inches. Setting \ +ImageDimensions -> w effectively specifies {w, w * ar}, where ar is the \ +aspect ratio of the graphic. The option PaperDimensions can be \ +used to specify the dimensions of the paper (in inches). The default is \ +PaperDimensions -> {8.5, 11}. The default behavior of opening the \ +print dialog box can be changed using OpenPrintDialog -> False. \ +The option MarginAdjustments may be used to correct for the fact that a \ +printer's margins are not the same left and right or bottom and top. The \ +default setting is MarginAdjustments -> {0, 0}. For example, setting \ +MarginAdjustments -> {1/8, 0} will shift the graphic 1/8 inch to the \ +right on the virtual page." + +PaperDimensions::usage = "PaperDimensions is an option for \ +PagePrint that specifies the dimensions of the paper in inches \ +(in portrait orientation). The default is PaperDimensions -> {8.5, 11}." + +LandscapeOrientation::usage = "LandscapeOrientation is an option for \ +PagePrint." + +PageMargins::usage = "PageMargins is an option for \ +PagePrint that specifies the page margins in inches. \ +Horizontal and vertical page margins may be specified separately. \ +The default is PageMargins -> 1." + +ImageDimensions::usage = "ImageDimensions is an option for \ +PagePrint. ImageDimensions specifies the dimensions of the \ +image in the page units (which is inches by default)." + +MarginAdjustments::usage = "MarginAdjustment is an Option for PagePrint \ +that can take account of the printer's margins by shifting the image on \ +the virtual page. The default is MarginAdjustments -> {0, 0}." + +OpenPrintDialog::usage = "OpenPrintDialog is an option for PagePrint \ +that specifies whether to open the print dialog box. The default \ +setting is OpenPrintDialog -> True." + +PrintFileName::usage = "PrintFileName is an option for \ +PagePrint that specifies a file to print to. to direct the page. The \ +default is PrintFileName -> None which directs the page to the \ +printer." + +PrintDirectory::usage = "PrintDirectory is an option \ +for PagePrint that specifies the directory in which to put the file when \ +printing to a file. The default setting is PrintDirectory :> \ +$UserDocumentsDirectory. To put the file in the current (working) \ +directory, use PrintDirectory -> Directory[]." + +PagePrintScale::usage = "PagePrintScale is an option for PagePrint \ +that determines the units used. The default setting is PagePrintScale \ +-> 72, which specifies inches. To convert to millimeters, use \ +PagePrintScale -> 72/25.4 and then specify the PaperDimensions, \ +PageMargins, MarginAdjustments in millimeters." + +Options[PagePrint] = { + PagePrintScale -> 72, + PaperDimensions -> {8.5, 11}, + PageMargins -> 1, + MarginAdjustments -> {0, 0}, + LandscapeOrientation -> False, + ImageDimensions -> Automatic, + OpenPrintDialog -> True, + PrintFileName -> None, + PrintDirectory :> $UserDocumentsDirectory + } + +PagePrint[] := FrontEndTokenExecute["SystemPrintOptionsDialog"] + +PagePrint[x_, OptionsPattern[]] := + Module[{scale, pdim, marg, madj, land, idim, opd, fn, dir, + orient, size, xOnPage, nb}, + + {scale, pdim, marg, madj, land, imdim, opd, fn, dir} = + OptionValue[{PagePrintScale, PaperDimensions, PageMargins, + MarginAdjustments, LandscapeOrientation, ImageDimensions, + OpenPrintDialog, PrintFileName, PrintDirectory}]; + + (* setup the page *) + land = TrueQ[land]; + orient = If[land, {0, -1}, {1, 0}]; + If[imdim === Automatic, + size = If[land, Reverse[pdim], pdim] - 2 * marg * {1, 1}, + (* else use ImageDimensions *) + size = imdim {1, AspectRatio /. AbsoluteOptions[x, AspectRatio]} + ]; + xOnPage = Graphics[ + {White, + Rectangle[{0, 0}, pdim], + Inset[x, pdim/2 + madj, ImageScaled[{.5, .5}], size, orient] + }, + ImageSize -> scale * pdim, + PlotRangePadding -> 0 (* this is crucial *) + ]; + + (* setup the notebook *) + nb = NotebookCreate[ + Visible -> False, + PrintingOptions -> { + "FirstPageHeader" -> False, + "FirstPageFooter" -> False, + "RestPagesHeader" -> False, + "RestPagesFooter" -> False, + "PrintingMargins" -> {{0,0},{0,0}} + }]; + NotebookWrite[nb, + Cell[ + BoxData[ToBoxes[xOnPage]], (* thanks to John *) + "Graphics", + Magnification -> 1, (* this fixes the 80% problem *) + ImageMargins -> {{0,0},{0,0}}, + CellMargins -> {{0,0},{0,0}} + ] + ]; + If[fn === None, + NotebookPrint[nb, Interactive -> TrueQ[opd]], + NotebookPrint[nb, ToFileName[dir, fn]] + ]; + NotebookClose[nb] + ] + diff --git a/MathematicaFiles/Applications/Parallel Test.nb b/MathematicaFiles/Applications/Parallel Test.nb new file mode 100755 index 0000000..4273a9a --- /dev/null +++ b/MathematicaFiles/Applications/Parallel Test.nb @@ -0,0 +1,591 @@ +(* Content-type: application/mathematica *) + +(*** Wolfram Notebook File ***) +(* http://www.wolfram.com/nb *) + +(* CreatedBy='Mathematica 6.0' *) + +(*CacheID: 234*) +(* Internal cache information: +NotebookFileLineBreakTest +NotebookFileLineBreakTest +NotebookDataPosition[ 145, 7] +NotebookDataLength[ 19822, 582] +NotebookOptionsPosition[ 17456, 495] +NotebookOutlinePosition[ 17992, 516] +CellTagsIndexPosition[ 17949, 513] +WindowFrame->Normal +ContainsDynamic->False*) + +(* Beginning of Notebook Content *) +Notebook[{ + +Cell[CellGroupData[{ +Cell["Setup and launching", "Section"], + +Cell["Be sure to start OpenVPN before running LaunchSlave.", "Text"], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{"<<", "Parallel`"}]], "Input"], + +Cell[CellGroupData[{ + +Cell[BoxData["\<\"Parallel Computing Toolkit 2.1 (April 27, 2007)\"\>"], \ +"Print", + CellChangeTimes->{ + 3.396611101884366*^9, 3.3966111924945*^9, 3.398009752156452*^9, { + 3.403620104183251*^9, 3.403620119099053*^9}}], + +Cell[BoxData["\<\"Created by Roman E. Maeder\"\>"], "Print", + CellChangeTimes->{ + 3.396611101884366*^9, 3.3966111924945*^9, 3.398009752156452*^9, { + 3.403620104183251*^9, 3.403620119099053*^9}}] +}, Open ]] +}, Open ]], + +Cell["Use to ignore init.m", "Text"], + +Cell[BoxData[ + RowBox[{ + RowBox[{ + "$RemoteCommand", "=", + "\"\<ssh `1` -x -f -l `3` \\\"math -mathlink -linkmode Connect `4` \ +-linkname `2` -noinit </dev/null >& /dev/null &\\\"\>\""}], ";"}]], "Input"], + +Cell["Use to read init.m", "Text"], + +Cell[BoxData[ + RowBox[{ + RowBox[{ + "$RemoteCommand", "=", "\[IndentingNewLine]", + "\"\<ssh `1` -x -f -l `3` \\\"math -mathlink -linkmode Connect `4` \ +-linkname `2` </dev/null >& /dev/null &\\\"\>\""}], ";"}]], "Input"], + +Cell[BoxData[{ + RowBox[{ + RowBox[{"workingnodenumbers", "=", + RowBox[{"Complement", "[", + RowBox[{ + RowBox[{"Range", "[", "18", "]"}], ",", + RowBox[{"Range", "[", + RowBox[{"1", ",", "6"}], "]"}]}], "]"}]}], ";"}], "\n", + RowBox[{ + RowBox[{"nodes", "=", + RowBox[{ + RowBox[{ + RowBox[{"ToString", "[", + RowBox[{"StringForm", "[", + RowBox[{"\"\<192.168.2.`1`\>\"", ",", "#"}], "]"}], "]"}], "&"}], "/@", + "workingnodenumbers"}]}], ";"}], "\n", + RowBox[{ + RowBox[{"$AvailableMachines", "=", + RowBox[{"RemoteMachine", "/@", "nodes"}]}], ";"}]}], "Input", + CellChangeTimes->{{3.3966111255221453`*^9, 3.396611129784439*^9}, { + 3.403620662800846*^9, 3.4036206766684494`*^9}}], + +Cell[CellGroupData[{ + +Cell[BoxData["$AvailableMachines"], "Input"], + +Cell[BoxData[ + RowBox[{"{", + RowBox[{ + RowBox[{"RemoteMachine", "[", "\<\"192.168.2.7\"\>", "]"}], ",", + RowBox[{"RemoteMachine", "[", "\<\"192.168.2.8\"\>", "]"}], ",", + RowBox[{"RemoteMachine", "[", "\<\"192.168.2.9\"\>", "]"}], ",", + RowBox[{"RemoteMachine", "[", "\<\"192.168.2.10\"\>", "]"}], ",", + RowBox[{"RemoteMachine", "[", "\<\"192.168.2.11\"\>", "]"}], ",", + RowBox[{"RemoteMachine", "[", "\<\"192.168.2.12\"\>", "]"}], ",", + RowBox[{"RemoteMachine", "[", "\<\"192.168.2.13\"\>", "]"}], ",", + RowBox[{"RemoteMachine", "[", "\<\"192.168.2.14\"\>", "]"}], ",", + RowBox[{"RemoteMachine", "[", "\<\"192.168.2.15\"\>", "]"}], ",", + RowBox[{"RemoteMachine", "[", "\<\"192.168.2.16\"\>", "]"}], ",", + RowBox[{"RemoteMachine", "[", "\<\"192.168.2.17\"\>", "]"}], ",", + RowBox[{"RemoteMachine", "[", "\<\"192.168.2.18\"\>", "]"}]}], + "}"}]], "Output", + CellChangeTimes->{{3.3966111160451756`*^9, 3.396611132704033*^9}, + 3.396611209336292*^9, 3.398009782346534*^9, 3.4036201262062693`*^9, + 3.4036206810030565`*^9}] +}, Open ]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{"LaunchSlaves", "[", + RowBox[{"Take", "[", + RowBox[{"$AvailableMachines", ",", "18"}], "]"}], "]"}]], "Input"], + +Cell[BoxData[ + RowBox[{"{", + RowBox[{ + RowBox[{ + SubscriptBox["\<\"slave\"\>", "1"], "[", "\<\"192.168.2.1\"\>", "]"}], + ",", + RowBox[{ + SubscriptBox["\<\"slave\"\>", "2"], "[", "\<\"192.168.2.2\"\>", "]"}], + ",", + RowBox[{ + SubscriptBox["\<\"slave\"\>", "3"], "[", "\<\"192.168.2.3\"\>", "]"}], + ",", + RowBox[{ + SubscriptBox["\<\"slave\"\>", "4"], "[", "\<\"192.168.2.4\"\>", "]"}], + ",", + RowBox[{ + SubscriptBox["\<\"slave\"\>", "5"], "[", "\<\"192.168.2.5\"\>", "]"}], + ",", + RowBox[{ + SubscriptBox["\<\"slave\"\>", "6"], "[", "\<\"192.168.2.6\"\>", "]"}], + ",", + RowBox[{ + SubscriptBox["\<\"slave\"\>", "7"], "[", "\<\"192.168.2.7\"\>", "]"}], + ",", + RowBox[{ + SubscriptBox["\<\"slave\"\>", "8"], "[", "\<\"192.168.2.8\"\>", "]"}], + ",", + RowBox[{ + SubscriptBox["\<\"slave\"\>", "9"], "[", "\<\"192.168.2.9\"\>", "]"}], + ",", + RowBox[{ + SubscriptBox["\<\"slave\"\>", "10"], "[", "\<\"192.168.2.10\"\>", "]"}], + ",", + RowBox[{ + SubscriptBox["\<\"slave\"\>", "11"], "[", "\<\"192.168.2.11\"\>", "]"}], + ",", + RowBox[{ + SubscriptBox["\<\"slave\"\>", "12"], "[", "\<\"192.168.2.12\"\>", "]"}], + ",", + RowBox[{ + SubscriptBox["\<\"slave\"\>", "13"], "[", "\<\"192.168.2.13\"\>", "]"}], + ",", + RowBox[{ + SubscriptBox["\<\"slave\"\>", "14"], "[", "\<\"192.168.2.14\"\>", "]"}], + ",", + RowBox[{ + SubscriptBox["\<\"slave\"\>", "15"], "[", "\<\"192.168.2.15\"\>", "]"}], + ",", + RowBox[{ + SubscriptBox["\<\"slave\"\>", "16"], "[", "\<\"192.168.2.16\"\>", "]"}], + ",", + RowBox[{ + SubscriptBox["\<\"slave\"\>", "17"], "[", "\<\"192.168.2.17\"\>", "]"}], + ",", + RowBox[{ + SubscriptBox["\<\"slave\"\>", "18"], "[", "\<\"192.168.2.18\"\>", "]"}]}], + "}"}]], "Output", + CellChangeTimes->{3.396611156466715*^9, 3.396611290943405*^9}] +}, Open ]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{"Length", "[", "$Slaves", "]"}]], "Input"], + +Cell[BoxData["17"], "Output", + CellChangeTimes->{3.39661130107178*^9, 3.398010544350068*^9}] +}, Open ]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{"CloseSlaves", "[", "]"}]], "Input"], + +Cell[BoxData[ + RowBox[{"{", + RowBox[{ + RowBox[{"\<\"zombie\"\>", "[", "\<\"192.168.2.1\"\>", "]"}], ",", + RowBox[{"\<\"zombie\"\>", "[", "\<\"192.168.2.2\"\>", "]"}], ",", + RowBox[{"\<\"zombie\"\>", "[", "\<\"192.168.2.3\"\>", "]"}], ",", + RowBox[{"\<\"zombie\"\>", "[", "\<\"192.168.2.4\"\>", "]"}], ",", + RowBox[{"\<\"zombie\"\>", "[", "\<\"192.168.2.5\"\>", "]"}], ",", + RowBox[{"\<\"zombie\"\>", "[", "\<\"192.168.2.6\"\>", "]"}], ",", + RowBox[{"\<\"zombie\"\>", "[", "\<\"192.168.2.7\"\>", "]"}], ",", + RowBox[{"\<\"zombie\"\>", "[", "\<\"192.168.2.8\"\>", "]"}], ",", + RowBox[{"\<\"zombie\"\>", "[", "\<\"192.168.2.9\"\>", "]"}], ",", + RowBox[{"\<\"zombie\"\>", "[", "\<\"192.168.2.10\"\>", "]"}], ",", + RowBox[{"\<\"zombie\"\>", "[", "\<\"192.168.2.11\"\>", "]"}], ",", + RowBox[{"\<\"zombie\"\>", "[", "\<\"192.168.2.12\"\>", "]"}], ",", + RowBox[{"\<\"zombie\"\>", "[", "\<\"192.168.2.13\"\>", "]"}], ",", + RowBox[{"\<\"zombie\"\>", "[", "\<\"192.168.2.14\"\>", "]"}], ",", + RowBox[{"\<\"zombie\"\>", "[", "\<\"192.168.2.15\"\>", "]"}], ",", + RowBox[{"\<\"zombie\"\>", "[", "\<\"192.168.2.16\"\>", "]"}], ",", + RowBox[{"\<\"zombie\"\>", "[", "\<\"192.168.2.17\"\>", "]"}], ",", + RowBox[{"\<\"zombie\"\>", "[", "\<\"192.168.2.18\"\>", "]"}]}], + "}"}]], "Output", + CellChangeTimes->{3.3966114012893915`*^9}] +}, Open ]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{"TableForm", "[", + RowBox[{ + RowBox[{"RemoteEvaluate", "[", + RowBox[{"{", + RowBox[{ + "$ProcessorID", ",", "$MachineName", ",", "$SystemID", ",", "$ProcessID", + ",", "$Version"}], "\[IndentingNewLine]", "}"}], "]"}], ",", " ", + RowBox[{"TableHeadings", "\[Rule]", + RowBox[{"{", + RowBox[{"None", ",", + RowBox[{"{", + RowBox[{ + "\"\<ID\>\"", ",", "\"\<host\>\"", ",", "\"\<OS\>\"", ",", + "\"\<process\>\"", ",", "\"\<Mathematica Version\>\""}], "}"}]}], + "}"}]}]}], "]"}]], "Input"], + +Cell[BoxData[ + TagBox[ + TagBox[GridBox[{ + { + TagBox["\<\"ID\"\>", + HoldForm], + TagBox["\<\"host\"\>", + HoldForm], + TagBox["\<\"OS\"\>", + HoldForm], + TagBox["\<\"process\"\>", + HoldForm], + TagBox["\<\"Mathematica Version\"\>", + HoldForm]}, + {"1", "\<\"n1-wulf\"\>", "\<\"Linux\"\>", + "3736", "\<\"6.0 for Linux x86 (32-bit) (June 19, 2007)\"\>"}, + {"2", "\<\"n7-wulf\"\>", "\<\"Linux-x86-64\"\>", + "10185", "\<\"6.0 for Linux x86 (64-bit) (June 19, 2007)\"\>"}, + {"3", "\<\"n8-wulf\"\>", "\<\"Linux-x86-64\"\>", + "9447", "\<\"6.0 for Linux x86 (64-bit) (June 19, 2007)\"\>"}, + {"4", "\<\"n9-wulf\"\>", "\<\"Linux-x86-64\"\>", + "7129", "\<\"6.0 for Linux x86 (64-bit) (June 19, 2007)\"\>"}, + {"5", "\<\"n10-wulf\"\>", "\<\"Linux-x86-64\"\>", + "20964", "\<\"6.0 for Linux x86 (64-bit) (June 19, 2007)\"\>"}, + {"6", "\<\"n11-wulf\"\>", "\<\"Linux\"\>", + "10214", "\<\"6.0 for Linux x86 (32-bit) (June 19, 2007)\"\>"}, + {"7", "\<\"n12-wulf\"\>", "\<\"Linux\"\>", + "1230", "\<\"6.0 for Linux x86 (32-bit) (June 19, 2007)\"\>"}, + {"8", "\<\"n13-wulf\"\>", "\<\"Linux\"\>", + "3106", "\<\"6.0 for Linux x86 (32-bit) (June 19, 2007)\"\>"}, + {"9", "\<\"n14-wulf\"\>", "\<\"Linux\"\>", + "3367", "\<\"6.0 for Linux x86 (32-bit) (June 19, 2007)\"\>"}, + {"10", "\<\"n15-wulf\"\>", "\<\"Linux-x86-64\"\>", + "26254", "\<\"6.0 for Linux x86 (64-bit) (June 19, 2007)\"\>"}, + {"11", "\<\"n16-wulf\"\>", "\<\"Linux-x86-64\"\>", + "22106", "\<\"6.0 for Linux x86 (64-bit) (June 19, 2007)\"\>"}, + {"12", "\<\"n17-wulf\"\>", "\<\"Linux-x86-64\"\>", + "12604", "\<\"6.0 for Linux x86 (64-bit) (June 19, 2007)\"\>"}, + {"13", "\<\"n18-wulf\"\>", "\<\"Linux-x86-64\"\>", + "11501", "\<\"6.0 for Linux x86 (64-bit) (June 19, 2007)\"\>"} + }, + GridBoxAlignment->{ + "Columns" -> {{Left}}, "ColumnsIndexed" -> {}, "Rows" -> {{Baseline}}, + "RowsIndexed" -> {}}, + GridBoxDividers->{ + "Columns" -> {{False}}, "ColumnsIndexed" -> {}, + "Rows" -> {False, True, {False}, False}, "RowsIndexed" -> {}}, + GridBoxSpacings->{"Columns" -> { + Offset[0.27999999999999997`], { + Offset[0.7]}, + Offset[0.27999999999999997`]}, "ColumnsIndexed" -> {}, "Rows" -> { + Offset[0.2], { + Offset[0.4]}, + Offset[0.2]}, "RowsIndexed" -> {}}], + {None, OutputFormsDump`HeadedColumns}], + Function[BoxForm`e$, + TableForm[ + BoxForm`e$, + TableHeadings -> { + None, {"ID", "host", "OS", "process", + "Mathematica Version"}}]]]], "Output", + CellChangeTimes->{3.396611303172713*^9, 3.398009982342003*^9, + 3.3980105759152946`*^9, 3.4036207198574743`*^9}] +}, Open ]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{"CloseSlaves", "[", "]"}]], "Input"], + +Cell[BoxData[ + RowBox[{"{", + RowBox[{ + RowBox[{"\<\"zombie\"\>", "[", "\<\"192.168.2.1\"\>", "]"}], ",", + RowBox[{"\<\"zombie\"\>", "[", "\<\"192.168.2.2\"\>", "]"}], ",", + RowBox[{"\<\"zombie\"\>", "[", "\<\"192.168.2.3\"\>", "]"}], ",", + RowBox[{"\<\"zombie\"\>", "[", "\<\"192.168.2.4\"\>", "]"}], ",", + RowBox[{"\<\"zombie\"\>", "[", "\<\"192.168.2.6\"\>", "]"}], ",", + RowBox[{"\<\"zombie\"\>", "[", "\<\"192.168.2.7\"\>", "]"}], ",", + RowBox[{"\<\"zombie\"\>", "[", "\<\"192.168.2.8\"\>", "]"}], ",", + RowBox[{"\<\"zombie\"\>", "[", "\<\"192.168.2.9\"\>", "]"}], ",", + RowBox[{"\<\"zombie\"\>", "[", "\<\"192.168.2.10\"\>", "]"}], ",", + RowBox[{"\<\"zombie\"\>", "[", "\<\"192.168.2.11\"\>", "]"}], ",", + RowBox[{"\<\"zombie\"\>", "[", "\<\"192.168.2.12\"\>", "]"}], ",", + RowBox[{"\<\"zombie\"\>", "[", "\<\"192.168.2.13\"\>", "]"}], ",", + RowBox[{"\<\"zombie\"\>", "[", "\<\"192.168.2.14\"\>", "]"}], ",", + RowBox[{"\<\"zombie\"\>", "[", "\<\"192.168.2.15\"\>", "]"}], ",", + RowBox[{"\<\"zombie\"\>", "[", "\<\"192.168.2.16\"\>", "]"}], ",", + RowBox[{"\<\"zombie\"\>", "[", "\<\"192.168.2.17\"\>", "]"}], ",", + RowBox[{"\<\"zombie\"\>", "[", "\<\"192.168.2.18\"\>", "]"}]}], + "}"}]], "Output", + CellChangeTimes->{3.398010624657355*^9}] +}, Open ]], + +Cell[CellGroupData[{ + +Cell[BoxData["$InitCode"], "Input"], + +Cell[BoxData[ + RowBox[{"Hold", "[", + RowBox[{ + RowBox[{"$DisplayFunction", "=", "Identity"}], ";"}], "]"}]], "Output"] +}, Open ]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{"processorindex", "=", + RowBox[{ + RowBox[{ + FractionBox["#", + RowBox[{"Min", "[", "#", "]"}]], "&"}], "@", + RowBox[{ + RowBox[{"RemoteEvaluate", "[", + RowBox[{ + RowBox[{"mat", "=", + RowBox[{"RandomReal", "[", + RowBox[{ + RowBox[{"{", + RowBox[{"0", ",", "1"}], "}"}], ",", + RowBox[{"{", + RowBox[{"500", ",", "500"}], "}"}]}], "]"}]}], ";", + RowBox[{"Timing", "[", + RowBox[{ + RowBox[{"Eigensystem", "[", "mat", "]"}], ";"}], "]"}]}], "]"}], "[", + + RowBox[{"[", + RowBox[{"All", ",", "1"}], "]"}], "]"}]}]}]], "Input", + CellChangeTimes->{{3.3980101343498015`*^9, 3.3980101709031076`*^9}}], + +Cell[BoxData[ + RowBox[{"{", + RowBox[{ + "4.823835393365411`", ",", "1.0487255191565739`", ",", + "1.2053969191736678`", ",", "0.9999999999999999`", ",", + "1.1949013268875797`", ",", "3.890553142229933`", ",", + "3.6244356341814874`", ",", "3.600446994222513`", ",", + "3.5029967056480813`", ",", "2.2871056936657572`", ",", + "2.308094629021786`", ",", "2.2803580452212406`", ",", + "2.3095933567151845`"}], "}"}]], "Output", + CellChangeTimes->{{3.3980101386624837`*^9, 3.3980101808203773`*^9}, + 3.4036207529795303`*^9}] +}, Open ]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{"ListPlot", "[", "%", "]"}]], "Input", + CellChangeTimes->{{3.3980101439060974`*^9, 3.39801014645191*^9}}], + +Cell[BoxData[ + GraphicsBox[ + {Hue[0.67, 0.6, 0.6], + PointBox[{{1., 4.823835393365411}, {2., 1.0487255191565739`}, {3., + 1.2053969191736678`}, {4., 0.9999999999999999}, {5., + 1.1949013268875797`}, {6., 3.890553142229933}, {7., + 3.6244356341814874`}, {8., 3.600446994222513}, {9., + 3.5029967056480813`}, {10., 2.2871056936657572`}, {11., + 2.308094629021786}, {12., 2.2803580452212406`}, {13., + 2.3095933567151845`}}]}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + Frame->{True, True, False, False}, + PlotRange->Automatic, + PlotRangeClipping->True]], "Output", + CellChangeTimes->{{3.398010147059865*^9, 3.398010180896372*^9}, + 3.403620753058056*^9}] +}, Open ]] +}, Open ]], + +Cell[CellGroupData[{ + +Cell["Using", "Section"], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{"RemoteEvaluate", "[", + RowBox[{"RandomReal", "[", + RowBox[{"NormalDistribution", "[", + RowBox[{"0", ",", "1"}], "]"}], "]"}], "]"}]], "Input", + CellChangeTimes->{{3.3980101953353076`*^9, 3.3980101972161694`*^9}}], + +Cell[BoxData[ + RowBox[{"{", + RowBox[{"1.0479788433903476`", ",", + RowBox[{"-", "1.7505149527774304`"}], ",", + RowBox[{"-", "0.5714992623515238`"}], ",", "0.9294308031610482`", ",", + RowBox[{"-", "0.08305441915167111`"}], ",", + RowBox[{"-", "0.4496085084095134`"}], ",", "1.7525031160071871`", ",", + "0.40303779494381126`", ",", "0.3143361014879913`", ",", + "0.4691141521604678`", ",", + RowBox[{"-", "0.0383159135795778`"}], ",", "0.014614071424194916`", ",", + RowBox[{"-", "0.6821805440481848`"}]}], "}"}]], "Output", + CellChangeTimes->{3.398010198109103*^9, 3.403620765308034*^9}] +}, Open ]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{"SetDirectory", "[", "\"\<x:\>\"", "]"}]], "Input"], + +Cell[BoxData[ + RowBox[{ + RowBox[{"SetDirectory", "::", "\<\"cdir\"\>"}], + RowBox[{ + ":", " "}], "\<\"Cannot set current directory to \\!\\(\\\"x:\\\"\\). \ +\\!\\(\\*ButtonBox[\\\"\[RightSkeleton]\\\", ButtonStyle->\\\"Link\\\", \ +ButtonFrame->None, ButtonData:>\\\"paclet:ref/message/General/cdir\\\", \ +ButtonNote -> \\\"SetDirectory::cdir\\\"]\\)\"\>"}]], "Message", "MSG", + CellChangeTimes->{3.398010205898529*^9}], + +Cell[BoxData["$Failed"], "Output", + CellChangeTimes->{3.398010205898529*^9}] +}, Open ]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{ + RowBox[{"StringCases", "[", + RowBox[{ + RowBox[{"Flatten", "[", + RowBox[{ + RowBox[{ + RowBox[{"Pick", "[", + RowBox[{"#", ",", + RowBox[{"StringMatchQ", "[", + RowBox[{"#", ",", + RowBox[{"__", "~~", + RowBox[{"\"\<Mathematica\>\"", "~~", "__"}]}]}], "]"}]}], "]"}], + "&"}], "/@", + RowBox[{"RemoteEvaluate", "[", + RowBox[{"Import", "[", + RowBox[{"\"\<!ps -ef\>\"", ",", "\"\<Lines\>\""}], "]"}], "]"}]}], + "]"}], ",", "NumberString"}], "]"}], "[", + RowBox[{"[", + RowBox[{"All", ",", "3"}], "]"}], "]"}]], "Input"], + +Cell[BoxData[ + RowBox[{"{", + RowBox[{"\<\"17848\"\>", ",", "\<\"19309\"\>", ",", "\<\"17696\"\>", + ",", "\<\"20055\"\>", ",", "\<\"15549\"\>", ",", "\<\"31585\"\>", + ",", "\<\"25914\"\>", ",", "\<\"14197\"\>", ",", "\<\"30340\"\>", + ",", "\<\"25210\"\>", ",", "\<\"15678\"\>", ",", "\<\"14508\"\>", + ",", "\<\"15016\"\>", ",", "\<\"662\"\>", ",", "\<\"28928\"\>", + ",", "\<\"21292\"\>", ",", "\<\"28066\"\>"}], "}"}]], "Output", + CellChangeTimes->{3.398010216176772*^9}] +}, Open ]], + +Cell[BoxData[ + RowBox[{ + RowBox[{"back", "=", + RowBox[{"RemoteEvaluate", "[", + RowBox[{"Import", "[", + RowBox[{"\"\<!free -m\>\"", ",", " ", "\"\<Lines\>\""}], "]"}], "]"}]}], + ";"}]], "Input"] +}, Open ]] +}, +WindowSize->{1184, 876}, +WindowMargins->{{Automatic, 22}, {Automatic, 13}}, +DockedCells->(FrontEndExecute[{ + FrontEnd`NotebookApply[ + FrontEnd`InputNotebook[], #, Placeholder]}]& ), +PrintingCopies->1, +PrintingPageRange->{Automatic, Automatic}, +ShowSelection->True, +FrontEndVersion->"6.0 for Microsoft Windows (32-bit) (June 19, 2007)", +StyleDefinitions->"Default.nb" +] +(* End of Notebook Content *) + +(* Internal cache information *) +(*CellTagsOutline +CellTagsIndex->{} +*) +(*CellTagsIndex +CellTagsIndex->{} +*) +(*NotebookFileOutline +Notebook[{ +Cell[CellGroupData[{ +Cell[590, 23, 38, 0, 88, "Section"], +Cell[631, 25, 68, 0, 34, "Text"], +Cell[CellGroupData[{ +Cell[724, 29, 53, 1, 52, "Input"], +Cell[CellGroupData[{ +Cell[802, 34, 220, 4, 27, "Print"], +Cell[1025, 40, 197, 3, 27, "Print"] +}, Open ]] +}, Open ]], +Cell[1249, 47, 36, 0, 34, "Text"], +Cell[1288, 49, 210, 5, 58, "Input"], +Cell[1501, 56, 34, 0, 34, "Text"], +Cell[1538, 58, 225, 5, 75, "Input"], +Cell[1766, 65, 724, 20, 97, "Input"], +Cell[CellGroupData[{ +Cell[2515, 89, 44, 0, 52, "Input"], +Cell[2562, 91, 1061, 18, 97, "Output"] +}, Open ]], +Cell[CellGroupData[{ +Cell[3660, 114, 138, 3, 35, "Input"], +Cell[3801, 119, 1880, 57, 102, "Output"] +}, Open ]], +Cell[CellGroupData[{ +Cell[5718, 181, 65, 1, 35, "Input"], +Cell[5786, 184, 92, 1, 35, "Output"] +}, Open ]], +Cell[CellGroupData[{ +Cell[5915, 190, 59, 1, 35, "Input"], +Cell[5977, 193, 1369, 22, 102, "Output"] +}, Open ]], +Cell[CellGroupData[{ +Cell[7383, 220, 568, 15, 75, "Input"], +Cell[7954, 237, 2773, 62, 286, "Output"] +}, Open ]], +Cell[CellGroupData[{ +Cell[10764, 304, 59, 1, 35, "Input"], +Cell[10826, 307, 1297, 21, 102, "Output"] +}, Open ]], +Cell[CellGroupData[{ +Cell[12160, 333, 35, 0, 35, "Input"], +Cell[12198, 335, 122, 3, 35, "Output"] +}, Open ]], +Cell[CellGroupData[{ +Cell[12357, 343, 718, 22, 70, "Input"], +Cell[13078, 367, 538, 11, 52, "Output"] +}, Open ]], +Cell[CellGroupData[{ +Cell[13653, 383, 128, 2, 52, "Input"], +Cell[13784, 387, 697, 15, 326, "Output"] +}, Open ]] +}, Open ]], +Cell[CellGroupData[{ +Cell[14530, 408, 24, 0, 88, "Section"], +Cell[CellGroupData[{ +Cell[14579, 412, 245, 5, 52, "Input"], +Cell[14827, 419, 607, 11, 75, "Output"] +}, Open ]], +Cell[CellGroupData[{ +Cell[15471, 435, 74, 1, 35, "Input"], +Cell[15548, 438, 421, 8, 27, "Message"], +Cell[15972, 448, 76, 1, 35, "Output"] +}, Open ]], +Cell[CellGroupData[{ +Cell[16085, 454, 642, 19, 80, "Input"], +Cell[16730, 475, 487, 8, 35, "Output"] +}, Open ]], +Cell[17232, 486, 208, 6, 35, "Input"] +}, Open ]] +} +] +*) + +(* End of internal cache information *) diff --git a/MathematicaFiles/Applications/Parse Eurodollar Data from PDF.nb b/MathematicaFiles/Applications/Parse Eurodollar Data from PDF.nb new file mode 100755 index 0000000..e422c19 --- /dev/null +++ b/MathematicaFiles/Applications/Parse Eurodollar Data from PDF.nb @@ -0,0 +1,1700 @@ +(* Content-type: application/mathematica *) + +(*** Wolfram Notebook File ***) +(* http://www.wolfram.com/nb *) + +(* CreatedBy='Mathematica 6.0' *) + +(*CacheID: 234*) +(* Internal cache information: +NotebookFileLineBreakTest +NotebookFileLineBreakTest +NotebookDataPosition[ 145, 7] +NotebookDataLength[ 61052, 1691] +NotebookOptionsPosition[ 56916, 1553] +NotebookOutlinePosition[ 57948, 1589] +CellTagsIndexPosition[ 57736, 1581] +WindowFrame->Normal +ContainsDynamic->False*) + +(* Beginning of Notebook Content *) +Notebook[{ + +Cell[CellGroupData[{ +Cell["Setup", "Section", + CellChangeTimes->{{3.4102666123667607`*^9, 3.410266614053548*^9}}], + +Cell[BoxData[ + RowBox[{ + RowBox[{"SectionList", "=", + RowBox[{"{", + RowBox[{"9", ",", "51", ",", "52"}], "}"}]}], ";"}]], "Input", + CellChangeTimes->{{3.410266255108037*^9, 3.4102662634171324`*^9}}], + +Cell[BoxData[ + RowBox[{ + RowBox[{"SectionLookupTable", "=", + RowBox[{"{", "\[IndentingNewLine]", + RowBox[{ + RowBox[{"{", + RowBox[{"9", ",", "\"\<_Interest_Rate_And_Energy_Futures_\>\""}], "}"}], + ",", "\[IndentingNewLine]", + RowBox[{"{", + RowBox[{"51", ",", "\"\<_Euro_Dollar_Call_Options_\>\""}], "}"}], ",", + "\[IndentingNewLine]", + RowBox[{"{", + RowBox[{"52", ",", "\"\<_Euro_Dollar_Put_Options_\>\""}], "}"}]}], + "\[IndentingNewLine]", "}"}]}], ";"}]], "Input", + CellChangeTimes->{{3.410265885907361*^9, 3.410265933000059*^9}, { + 3.4102659745931897`*^9, 3.4102660289625807`*^9}, {3.410266117537362*^9, + 3.4102661247689133`*^9}}], + +Cell[BoxData[{ + RowBox[{ + RowBox[{ + RowBox[{"URLforPDFfromCME", "[", + RowBox[{ + RowBox[{"section_Integer", "/;", + RowBox[{"MemberQ", "[", + RowBox[{"SectionList", ",", "section"}], "]"}]}], ",", + RowBox[{"{", + RowBox[{"year_Integer", ",", "day_Integer"}], "}"}]}], "]"}], ":=", + RowBox[{"\"\<http://www.cmegroup.com/daily_bulletin/Section\>\"", "<>", + RowBox[{"IntegerString", "[", + RowBox[{"section", ",", "10", ",", "2"}], "]"}], "<>", + RowBox[{ + RowBox[{"Cases", "[", + RowBox[{"SectionLookupTable", ",", + RowBox[{ + RowBox[{"{", + RowBox[{"section", ",", "string_"}], "}"}], "\[Rule]", "string"}]}], + "]"}], "[", + RowBox[{"[", "1", "]"}], "]"}], "<>", " ", + RowBox[{"IntegerString", "[", + RowBox[{"year", ",", "10", ",", "4"}], "]"}], "<>", + RowBox[{"IntegerString", "[", + RowBox[{"day", ",", "10", ",", "3"}], "]"}], "<>", "\"\<.pdf\>\""}]}], + "\[IndentingNewLine]"}], "\n", + RowBox[{ + RowBox[{"URLforPDFfromCME", "[", "__", "]"}], ":=", "$Failed"}]}], "Input", + CellChangeTimes->{{3.410264626101692*^9, 3.4102648373632183`*^9}, { + 3.410265141575918*^9, 3.4102651417634964`*^9}, {3.410265945276514*^9, + 3.4102659623011155`*^9}, {3.4102660405049477`*^9, 3.4102660780215454`*^9}, { + 3.41026626700941*^9, 3.4102662713201437`*^9}, {3.410266602183564*^9, + 3.410266604213956*^9}}], + +Cell[BoxData[ + RowBox[{ + RowBox[{"ImportSectionPDFfromCME", "[", + RowBox[{"section_Integer", ",", + RowBox[{"{", + RowBox[{"year_Integer", ",", "day_Integer"}], "}"}]}], "]"}], ":=", + "\[IndentingNewLine]", + RowBox[{"With", "[", + RowBox[{ + RowBox[{"{", + RowBox[{"url", "=", + RowBox[{"URLforPDFfromCME", "[", + RowBox[{"section", ",", + RowBox[{"{", + RowBox[{"year", ",", "day"}], "}"}]}], "]"}]}], "}"}], ",", + "\[IndentingNewLine]", + RowBox[{"Switch", "[", + RowBox[{ + "url", ",", "\[IndentingNewLine]", "$Failed", ",", "\[IndentingNewLine]", + "$Failed", ",", "\[IndentingNewLine]", "_", ",", "\[IndentingNewLine]", + + RowBox[{"Import", "[", + RowBox[{"url", ",", "\"\<Plaintext\>\""}], "]"}]}], + "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}]], "Input",\ + + CellChangeTimes->{{3.4102648684223413`*^9, 3.410264919405409*^9}, { + 3.4102663319359303`*^9, 3.41026646536563*^9}}], + +Cell[BoxData[ + RowBox[{ + RowBox[{"ImportSectionPDFfromCMEandWriteToFile", "[", + RowBox[{"section_Integer", ",", + RowBox[{"{", + RowBox[{"year_Integer", ",", "day_Integer"}], "}"}]}], "]"}], ":=", + "\[IndentingNewLine]", + RowBox[{"With", "[", + RowBox[{ + RowBox[{"{", + RowBox[{"url", "=", + RowBox[{"URLforPDFfromCME", "[", + RowBox[{"section", ",", + RowBox[{"{", + RowBox[{"year", ",", "day"}], "}"}]}], "]"}]}], "}"}], ",", + "\[IndentingNewLine]", + RowBox[{"Switch", "[", + RowBox[{ + "url", ",", "\[IndentingNewLine]", "$Failed", ",", "\[IndentingNewLine]", + "$Failed", ",", "\[IndentingNewLine]", "_", ",", "\[IndentingNewLine]", + + RowBox[{"Export", "[", + RowBox[{ + RowBox[{ + RowBox[{ + RowBox[{"StringSplit", "[", + RowBox[{"url", ",", + RowBox[{"{", + RowBox[{"\"\</\>\"", ",", "\"\<.\>\""}], "}"}]}], "]"}], "[", + RowBox[{"[", + RowBox[{"-", "2"}], "]"}], "]"}], "<>", "\"\<.txt\>\""}], ",", + "\[IndentingNewLine]", + RowBox[{"Import", "[", + RowBox[{"url", ",", "\"\<Plaintext\>\""}], "]"}]}], "]"}]}], + "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}]], "Input",\ + + CellChangeTimes->{{3.4102652424888577`*^9, 3.4102653915019855`*^9}, { + 3.4102655995836835`*^9, 3.4102656150007224`*^9}, {3.4102664716755447`*^9, + 3.4102665574368477`*^9}}], + +Cell[BoxData[ + RowBox[{ + RowBox[{ + RowBox[{"URLforPDFfromCME", "::", "usage"}], "=", + "\"\<URLforPDFfromCME[section, {year, day}] generates the URL for the \ +Section data for the date specified. The arguments section, year, and day \ +should all be integers.\>\""}], ";"}]], "Input", + CellChangeTimes->{{3.4102668503911767`*^9, 3.4102668712417407`*^9}, { + 3.4102669381353483`*^9, 3.410267003107892*^9}}], + +Cell[BoxData[ + RowBox[{ + RowBox[{ + RowBox[{"ImportSectionPDFfromCME", "::", "usage"}], "=", + "\"\<ImportSectionPDFfromCME[section, {year, day}] imports the section \ +data from the CME website and returns a string. The arguments section, year, \ +and day should all be integers.\>\""}], ";"}]], "Input", + CellChangeTimes->{{3.4102667664578953`*^9, 3.410266802255268*^9}, { + 3.410267018898094*^9, 3.4102670457461243`*^9}}], + +Cell[BoxData[ + RowBox[{ + RowBox[{ + RowBox[{"ImportSectionPDFfromCMEandWriteToFile", "::", "usage"}], "=", + "\"\<ImportSectionPDFfromCMEandWriteToFile[section, {year, day}] imports \ +the section data from the CME website and writes a .txt file to the current \ +directory. The arguments section, year, and day should all be \ +integers.\>\""}], ";"}]], "Input", + CellChangeTimes->{{3.4102667851375017`*^9, 3.4102668043481336`*^9}, { + 3.4102670569601355`*^9, 3.4102670754679394`*^9}}], + +Cell[BoxData[ + RowBox[{ + RowBox[{"LineNumber", "[", + RowBox[{"startString_String", ",", "lines_"}], "]"}], ":=", + RowBox[{ + RowBox[{"Position", "[", + RowBox[{ + RowBox[{"Length", "/@", + RowBox[{"StringCases", "[", + RowBox[{"lines", ",", + RowBox[{"StartOfString", "~~", "startString"}]}], "]"}]}], ",", "1"}], + "]"}], "[", + RowBox[{"[", + RowBox[{"1", ",", "1"}], "]"}], "]"}]}]], "Input", + CellChangeTimes->{{3.41032811828125*^9, 3.410328169484375*^9}, { + 3.41037084940625*^9, 3.4103708543125*^9}}], + +Cell[BoxData[ + RowBox[{ + RowBox[{ + RowBox[{"ExtractDataFromCMEString", "::", "usage"}], "=", + "\"\<ExtractDataFromCMEString[instring] extracts the data from the given \ +input string, itself obtained from a CME pdf.\>\""}], ";"}]], "Input", + CellChangeTimes->{{3.4112982130539656`*^9, 3.411298270422741*^9}}], + +Cell[BoxData[ + RowBox[{ + RowBox[{"ExtractDataFromCMEString", "[", "instring_String", "]"}], ":=", + "\[IndentingNewLine]", + RowBox[{"Module", "[", + RowBox[{ + RowBox[{"{", + RowBox[{ + "lines", ",", "dateline", ",", "quotedate", ",", "pagenumber", ",", + "daynumber", ",", "fixline", ",", "bbafix", ",", "datalines", ",", + "contracts", ",", "contractmonths", ",", "contractmaturities"}], "}"}], + ",", "\[IndentingNewLine]", + RowBox[{ + RowBox[{"lines", "=", + RowBox[{"DeleteCases", "[", + RowBox[{ + RowBox[{"ImportString", "[", + RowBox[{"instring", ",", "\"\<Lines\>\""}], "]"}], ",", "\"\<\>\""}], + "]"}]}], ";", "\[IndentingNewLine]", + RowBox[{"dateline", "=", + RowBox[{"lines", "[", + RowBox[{"[", + RowBox[{"LineNumber", "[", + RowBox[{"\"\<PG\>\"", ",", "lines"}], "]"}], "]"}], "]"}]}], ";", + "\[IndentingNewLine]", + RowBox[{"quotedate", "=", + RowBox[{ + RowBox[{"DateList", "[", + RowBox[{"StringTake", "[", + RowBox[{"dateline", ",", + RowBox[{"{", + RowBox[{"118", ",", "129"}], "}"}]}], "]"}], "]"}], "[", + RowBox[{"[", + RowBox[{";;", "3"}], "]"}], "]"}]}], ";", "\[IndentingNewLine]", + RowBox[{ + RowBox[{"{", + RowBox[{"pagenumber", ",", "daynumber"}], "}"}], "=", + RowBox[{ + RowBox[{ + RowBox[{"StringCases", "[", + RowBox[{"dateline", ",", "NumberString"}], "]"}], "[", + RowBox[{"[", + RowBox[{"{", + RowBox[{"1", ",", "2"}], "}"}], "]"}], "]"}], "//", + "ToExpression"}]}], ";", "\[IndentingNewLine]", + RowBox[{"fixline", "=", + RowBox[{"lines", "[", + RowBox[{"[", + RowBox[{"LineNumber", "[", + RowBox[{"\"\<U.S.\>\"", ",", "lines"}], "]"}], "]"}], "]"}]}], ";", + "\[IndentingNewLine]", + RowBox[{"bbafix", "=", + RowBox[{ + RowBox[{ + RowBox[{"StringCases", "[", + RowBox[{"fixline", ",", "NumberString"}], "]"}], "[", + RowBox[{"[", + RowBox[{"-", "1"}], "]"}], "]"}], "//", "ToExpression"}]}], ";", + "\[IndentingNewLine]", + RowBox[{"datalines", "=", + RowBox[{"lines", "[", + RowBox[{"[", + RowBox[{ + RowBox[{ + RowBox[{"LineNumber", "[", + RowBox[{"\"\<EURO DLR FUT\>\"", ",", "lines"}], "]"}], "+", "1"}], + ";;", + RowBox[{ + RowBox[{"LineNumber", "[", + RowBox[{"\"\<TOTAL\>\"", ",", "lines"}], "]"}], "-", "1"}]}], + "]"}], "]"}]}], ";", "\[IndentingNewLine]", + RowBox[{"contracts", "=", + RowBox[{"StringTake", "[", + RowBox[{"datalines", ",", "5"}], "]"}]}], ";", "\[IndentingNewLine]", + RowBox[{"contractmonths", "=", + RowBox[{ + RowBox[{"(", + RowBox[{ + RowBox[{ + RowBox[{"DateList", "[", + RowBox[{"{", + RowBox[{ + RowBox[{"StringInsert", "[", + RowBox[{"#", ",", "\"\< \>\"", ",", "4"}], "]"}], ",", + RowBox[{"{", + RowBox[{"\"\<MonthName\>\"", ",", "\"\<YearShort\>\""}], + "}"}]}], "}"}], "]"}], "&"}], "/@", "contracts"}], ")"}], "[", + RowBox[{"[", + RowBox[{"All", ",", + RowBox[{"{", + RowBox[{"1", ",", "2"}], "}"}]}], "]"}], "]"}]}], ";", + "\[IndentingNewLine]", + RowBox[{"contractmaturities", "=", + RowBox[{"EurodollarExpirationDate", "/@", "contractmonths"}]}], ";", + "\[IndentingNewLine]", + RowBox[{"rates", "=", + RowBox[{"Flatten", "[", + RowBox[{"StringCases", "[", + RowBox[{"datalines", ",", + RowBox[{ + RowBox[{ + RowBox[{"r", ":", "NumberString"}], "~~", "\"\<)\>\""}], ":>", + RowBox[{"ToExpression", "[", "r", "]"}]}]}], "]"}], "]"}]}], ";", + "\[IndentingNewLine]", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{ + "pagenumber", ",", "daynumber", ",", "quotedate", ",", "bbafix"}], + "}"}], ",", + RowBox[{"Sort", "[", + RowBox[{"Transpose", "[", + RowBox[{"{", + RowBox[{"contractmaturities", ",", "rates"}], "}"}], "]"}], "]"}]}], + "}"}]}]}], "\[IndentingNewLine]", "]"}]}]], "Input", + CellChangeTimes->{{3.410361469578125*^9, 3.410361712953125*^9}, { + 3.410361756484375*^9, 3.410361796140625*^9}, {3.41036202865625*^9, + 3.41036211640625*^9}, {3.410370209546875*^9, 3.410370212890625*^9}, { + 3.41037046303125*^9, 3.41037046621875*^9}, {3.410370732890625*^9, + 3.410370771625*^9}, {3.41037080821875*^9, 3.41037081425*^9}, { + 3.410370867671875*^9, 3.410370899140625*^9}, {3.411298198204291*^9, + 3.4112982005465107`*^9}, {3.4112983089756823`*^9, 3.411298336738796*^9}, { + 3.411298393467365*^9, 3.4112984288348866`*^9}, {3.4112984626409287`*^9, + 3.4112984639369574`*^9}}], + +Cell[BoxData[ + RowBox[{ + RowBox[{ + RowBox[{"ReadDataFromCMEPDF", "::", "usage"}], " ", "=", " ", + "\"\<ReadDataFromCMEPDF[filename] returns the data extracted from the CME \ +pdf with the given filename.\>\""}], ";"}]], "Input", + CellChangeTimes->{{3.411298740178384*^9, 3.4112987755771356`*^9}}], + +Cell[BoxData[ + RowBox[{ + RowBox[{"ReadDataFromCMEPDF", "[", "filename_String", "]"}], ":=", + RowBox[{"ExtractDataFromCMEString", "[", + RowBox[{"Import", "[", + RowBox[{"filename", ",", "\"\<Plaintext\>\""}], "]"}], "]"}]}]], "Input", + CellChangeTimes->{{3.411298612355631*^9, 3.411298640462271*^9}, { + 3.4112987193638554`*^9, 3.411298727780233*^9}, 3.411298802840576*^9, { + 3.411299363927185*^9, 3.411299364551777*^9}}], + +Cell[BoxData[ + RowBox[{ + RowBox[{"Section09DataForDataBase", "[", "filename_String", "]"}], ":=", + "\[IndentingNewLine]", + RowBox[{"With", "[", + RowBox[{ + RowBox[{"{", + RowBox[{"data", "=", + RowBox[{"ExtractDataFromCMEString", "[", + RowBox[{"Import", "[", + RowBox[{"filename", ",", "\"\<Plaintext\>\""}], "]"}], "]"}]}], "}"}], + ",", "\[IndentingNewLine]", + RowBox[{ + RowBox[{ + RowBox[{"Join", "[", + RowBox[{ + RowBox[{"data", "[", + RowBox[{"[", + RowBox[{"1", ",", + RowBox[{"{", + RowBox[{"3", ",", "2"}], "}"}]}], "]"}], "]"}], ",", "#"}], "]"}], + "&"}], "/@", + RowBox[{"data", "[", + RowBox[{"[", "2", "]"}], "]"}]}]}], "\[IndentingNewLine]", + "]"}]}]], "Input", + CellChangeTimes->{{3.411299294753621*^9, 3.411299331526475*^9}, { + 3.4112993680963364`*^9, 3.4112994113493323`*^9}}] +}, Open ]], + +Cell[CellGroupData[{ + +Cell["Usage", "Section", + CellChangeTimes->{{3.4102666250489016`*^9, 3.410266625658019*^9}}], + +Cell["\<\ +Download eurodollar data from \"www.cmegroup.com\". Currently only set up for \ +Sections 9, 51, 52. Others can be added. (Add to SectionList and \ +SectionLookupTable.)\ +\>", "Text", + CellChangeTimes->{{3.410266645399677*^9, 3.4102667434832287`*^9}}], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{"?", "URLforPDFfromCME"}]], "Input", + CellChangeTimes->{{3.410266881237517*^9, 3.4102668845017624`*^9}}], + +Cell[BoxData[ + StyleBox["\<\"URLforPDFfromCME[section, {year, day}] generates the URL for \ +the Section data for the date specified. The arguments section, year, and day \ +should all be integers.\"\>", "MSG"]], "Print", "PrintUsage", + CellChangeTimes->{3.411298078751071*^9}, + CellTags->"Info3411280078-7196149"] +}, Open ]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{"?", "ImportSectionPDFfromCME"}]], "Input", + CellChangeTimes->{{3.4102668075967607`*^9, 3.41026681092348*^9}}], + +Cell[BoxData[ + StyleBox["\<\"ImportSectionPDFfromCME[section, {year, day}] imports the \ +section data from the CME website and returns a string. The arguments \ +section, year, and day should all be integers.\"\>", "MSG"]], "Print", \ +"PrintUsage", + CellChangeTimes->{3.411298081249439*^9}, + CellTags->"Info3411280081-2015869"] +}, Open ]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{"?", "ImportSectionPDFfromCMEandWriteToFile"}]], "Input", + CellChangeTimes->{{3.410266817061511*^9, 3.410266820450704*^9}}], + +Cell[BoxData[ + StyleBox["\<\"ImportSectionPDFfromCMEandWriteToFile[section, {year, day}] \ +imports the section data from the CME website and writes a .txt file to the \ +current directory. The arguments section, year, and day should all be \ +integers.\"\>", "MSG"]], "Print", "PrintUsage", + CellChangeTimes->{3.4112980836228886`*^9}, + CellTags->"Info3411280083-4726061"] +}, Open ]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{"URLforPDFfromCME", "[", + RowBox[{"9", ",", + RowBox[{"{", + RowBox[{"2008", ",", "15"}], "}"}]}], "]"}]], "Input", + CellChangeTimes->{{3.4102669047744455`*^9, 3.4102669123806067`*^9}, { + 3.4102985694375*^9, 3.41029857*^9}}], + +Cell[BoxData["\<\"http://www.cmegroup.com/daily_bulletin/Section09_Interest_\ +Rate_And_Energy_Futures_2008015.pdf\"\>"], "Output", + CellChangeTimes->{3.4102669128491583`*^9, 3.410298570140625*^9, + 3.411298085715272*^9}] +}, Open ]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{"ImportSectionPDFfromCMEandWriteToFile", "[", + RowBox[{"9", ",", + RowBox[{"{", + RowBox[{"2008", ",", "15"}], "}"}]}], "]"}]], "Input", + CellChangeTimes->{{3.410265334383932*^9, 3.410265343132868*^9}, { + 3.41029860440625*^9, 3.41029860471875*^9}}], + +Cell[BoxData["\<\"Section09_Interest_Rate_And_Energy_Futures_2008015.txt\"\>"]\ +, "Output", + CellChangeTimes->{3.4102653442889776`*^9, 3.4102653945172443`*^9, + 3.410265535728715*^9, 3.410298607109375*^9}] +}, Open ]] +}, Open ]], + +Cell[CellGroupData[{ + +Cell["download pdfs", "Section", + CellChangeTimes->{{3.410366690859375*^9, 3.41036669496875*^9}}], + +Cell[BoxData[ + RowBox[{ + RowBox[{"fn", "=", + RowBox[{"FileNames", "[", "]"}]}], ";"}]], "Input", + CellChangeTimes->{{3.410367909890625*^9, 3.41036793384375*^9}}], + +Cell[BoxData[ + RowBox[{ + RowBox[{"yeardays", "=", + RowBox[{"ToExpression", "[", + RowBox[{"StringTake", "[", + RowBox[{"fn", ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"44", ",", "47"}], "}"}], ",", + RowBox[{"{", + RowBox[{"48", ",", "50"}], "}"}]}], "}"}]}], "]"}], "]"}]}], + ";"}]], "Input", + CellChangeTimes->{{3.410367930640625*^9, 3.41036794590625*^9}, { + 3.410367977671875*^9, 3.410368029296875*^9}}], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{"days2007", "=", + RowBox[{"Cases", "[", + RowBox[{"yeardays", ",", + RowBox[{ + RowBox[{"{", + RowBox[{"2007", ",", "d_"}], "}"}], "\[Rule]", "d"}]}], + "]"}]}]], "Input", + CellChangeTimes->{{3.41036811121875*^9, 3.410368145046875*^9}}], + +Cell[BoxData[ + RowBox[{"{", + RowBox[{ + "113", ",", "114", ",", "115", ",", "116", ",", "117", ",", "118", ",", + "119", ",", "120", ",", "121", ",", "122", ",", "123", ",", "124", ",", + "125", ",", "126", ",", "127", ",", "128", ",", "129", ",", "130", ",", + "131", ",", "132", ",", "133", ",", "134", ",", "135", ",", "136", ",", + "137", ",", "138", ",", "139", ",", "140", ",", "141", ",", "142", ",", + "143", ",", "144", ",", "145", ",", "146", ",", "147", ",", "148", ",", + "149", ",", "150", ",", "151", ",", "152", ",", "153", ",", "154", ",", + "155", ",", "156", ",", "157", ",", "158", ",", "159", ",", "160", ",", + "161", ",", "162", ",", "163", ",", "164", ",", "165", ",", "166", ",", + "167", ",", "168", ",", "169", ",", "170", ",", "171", ",", "172", ",", + "173", ",", "174", ",", "175", ",", "176", ",", "177", ",", "178", ",", + "179", ",", "180", ",", "181", ",", "182", ",", "183", ",", "184", ",", + "185", ",", "186", ",", "187", ",", "188", ",", "189", ",", "190", ",", + "191", ",", "192", ",", "193", ",", "194", ",", "195", ",", "196", ",", + "197", ",", "198", ",", "199", ",", "200", ",", "201", ",", "202", ",", + "203", ",", "204", ",", "205", ",", "206", ",", "207", ",", "208", ",", + "209", ",", "210", ",", "211", ",", "212", ",", "213", ",", "214", ",", + "215", ",", "216", ",", "217", ",", "218", ",", "219", ",", "220", ",", + "221", ",", "222", ",", "223", ",", "224", ",", "225", ",", "226", ",", + "227", ",", "228", ",", "229", ",", "230", ",", "231", ",", "232", ",", + "233", ",", "234", ",", "235", ",", "236", ",", "237", ",", "238", ",", + "239", ",", "240", ",", "241", ",", "242", ",", "243", ",", "244", ",", + "245", ",", "246", ",", "247", ",", "248", ",", "249", ",", "250", ",", + "251", ",", "252", ",", "253"}], "}"}]], "Output", + CellChangeTimes->{{3.410368112890625*^9, 3.41036814546875*^9}}] +}, Open ]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{"days2008", "=", + RowBox[{"Cases", "[", + RowBox[{"yeardays", ",", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "d_"}], "}"}], "\[Rule]", "d"}]}], + "]"}]}]], "Input", + CellChangeTimes->{{3.41036811121875*^9, 3.410368145046875*^9}, { + 3.4103682569375*^9, 3.410368261453125*^9}}], + +Cell[BoxData[ + RowBox[{"{", + RowBox[{ + "1", ",", "2", ",", "3", ",", "4", ",", "5", ",", "6", ",", "7", ",", "8", + ",", "9", ",", "10", ",", "11", ",", "12", ",", "13", ",", "14", ",", "15", + ",", "16", ",", "17"}], "}"}]], "Output", + CellChangeTimes->{3.41036856228125*^9}] +}, Open ]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{"SetDirectory", "[", + RowBox[{ + "myWorkingDrive", "<>", + "\"\<\\\\projects\\\\eurodollar\\\\cme_pdfs\\\\Section52\>\""}], + "]"}]], "Input", + CellChangeTimes->{{3.41036670809375*^9, 3.41036671134375*^9}, { + 3.410367901921875*^9, 3.410367904421875*^9}, {3.410368199703125*^9, + 3.410368201625*^9}, {3.41036894453125*^9, 3.41036894596875*^9}}], + +Cell[BoxData["\<\"c:\\\\data\\\\projects\\\\eurodollar\\\\cme_pdfs\\\\\ +Section52\"\>"], "Output", + CellChangeTimes->{3.41036671271875*^9, 3.410367904890625*^9, + 3.410368201796875*^9, 3.410368946390625*^9}] +}, Open ]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{ + RowBox[{"temp", "=", + RowBox[{"Monitor", "[", + RowBox[{ + RowBox[{"Table", "[", "\[IndentingNewLine]", + RowBox[{ + RowBox[{"With", "[", + RowBox[{ + RowBox[{"{", + RowBox[{"url", "=", + RowBox[{"URLforPDFfromCME", "[", + RowBox[{"52", ",", + RowBox[{"{", + RowBox[{"2007", ",", "day"}], "}"}]}], "]"}]}], "}"}], ",", + "\[IndentingNewLine]", + RowBox[{"Export", "[", + RowBox[{ + RowBox[{ + RowBox[{"StringSplit", "[", + RowBox[{"url", ",", "\"\</\>\""}], "]"}], "[", + RowBox[{"[", + RowBox[{"-", "1"}], "]"}], "]"}], ",", + RowBox[{"Import", "[", + RowBox[{"url", ",", "\"\<Binary\>\""}], "]"}], ",", + "\"\<Binary\>\""}], "]"}]}], "]"}], ",", "\[IndentingNewLine]", + RowBox[{"{", + RowBox[{"day", ",", "days2007"}], "}"}]}], "]"}], ",", "day"}], + "]"}]}], ";"}]], "Input", + CellChangeTimes->{{3.410366723515625*^9, 3.4103667253125*^9}, { + 3.4103669039375*^9, 3.410366929109375*^9}, {3.410367131640625*^9, + 3.410367132515625*^9}, {3.410367192796875*^9, 3.410367193640625*^9}, { + 3.410367246546875*^9, 3.410367334734375*^9}, {3.410367364828125*^9, + 3.410367406828125*^9}, {3.41036743975*^9, 3.4103674706875*^9}, { + 3.410367583859375*^9, 3.4103676405*^9}, {3.410367672875*^9, + 3.410367679046875*^9}, {3.41036815334375*^9, 3.4103681778125*^9}, { + 3.41036855815625*^9, 3.410368568328125*^9}, {3.410368949015625*^9, + 3.410368952703125*^9}, {3.410369223484375*^9, 3.41036922371875*^9}}], + +Cell[BoxData[ + RowBox[{ + RowBox[{"FetchURL", "::", "\<\"conopen\"\>"}], + RowBox[{ + ":", " "}], "\<\"The connection to URL \ +\\!\\(\\\"http://www.cmegroup.com/daily_bulletin/Section52_Euro_Dollar_Put_\ +Options_2007253.pdf\\\"\\) cannot be opened. If the URL is correct, you might \ +need to configure your firewall program, or you might need to set a proxy in \ +the Internet Connectivity tab of the Preferences dialog (or by calling \ +SetInternetProxy).\"\>"}]], "Message", "MSG", + CellChangeTimes->{3.4103691716875*^9, 3.41036952459375*^9}], + +Cell[BoxData[ + RowBox[{ + RowBox[{"BinaryWrite", "::", "\<\"nocoerce\"\>"}], + RowBox[{ + ":", " "}], "\<\"\\!\\($Failed\\) cannot be coerced to the specified \ +format. \\!\\(\\*ButtonBox[\\\"\[RightSkeleton]\\\", \ +ButtonStyle->\\\"Link\\\", ButtonFrame->None, \ +ButtonData:>\\\"paclet:ref/BinaryWrite\\\", ButtonNote -> \ +\\\"BinaryWrite::nocoerce\\\"]\\)\"\>"}]], "Message", "MSG", + CellChangeTimes->{3.4103691716875*^9, 3.410369524625*^9}] +}, Open ]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{"With", "[", + RowBox[{ + RowBox[{"{", + RowBox[{"url", "=", + RowBox[{"URLforPDFfromCME", "[", + RowBox[{"52", ",", + RowBox[{"{", + RowBox[{"2008", ",", "253"}], "}"}]}], "]"}]}], "}"}], ",", + "\[IndentingNewLine]", + RowBox[{"Export", "[", + RowBox[{ + RowBox[{ + RowBox[{"StringSplit", "[", + RowBox[{"url", ",", "\"\</\>\""}], "]"}], "[", + RowBox[{"[", + RowBox[{"-", "1"}], "]"}], "]"}], ",", + RowBox[{"Import", "[", + RowBox[{"url", ",", "\"\<Binary\>\""}], "]"}], ",", "\"\<Binary\>\""}], + "]"}]}], "]"}]], "Input", + CellChangeTimes->{{3.410368513703125*^9, 3.410368517484375*^9}, { + 3.41036923846875*^9, 3.41036923871875*^9}}], + +Cell[BoxData["\<\"Section52_Euro_Dollar_Put_Options_2008253.pdf\"\>"], \ +"Output", + CellChangeTimes->{3.410368519578125*^9, 3.410369557265625*^9}] +}, Open ]] +}, Closed]], + +Cell[CellGroupData[{ + +Cell["Write code", "Section", + CellChangeTimes->{{3.41032851565625*^9, 3.410328518171875*^9}}], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{"SetDirectory", "[", + RowBox[{ + "myWorkingDrive", "<>", + "\"\<\\\\projects\\\\eurodollar\\\\cme_pdfs\\\\Section09\>\""}], + "]"}]], "Input", + CellChangeTimes->{{3.41036670809375*^9, 3.41036671134375*^9}, { + 3.410367901921875*^9, 3.410367904421875*^9}, {3.410368199703125*^9, + 3.410368201625*^9}, {3.41036894453125*^9, 3.41036894596875*^9}, { + 3.41036991040625*^9, 3.41036991178125*^9}}], + +Cell[BoxData["\<\"d:\\\\data\\\\projects\\\\eurodollar\\\\cme_pdfs\\\\\ +Section09\"\>"], "Output", + CellChangeTimes->{3.41036671271875*^9, 3.410367904890625*^9, + 3.410368201796875*^9, 3.410368946390625*^9, 3.41036991225*^9, + 3.410370529609375*^9, 3.4112980976762085`*^9}] +}, Open ]], + +Cell[BoxData[ + RowBox[{ + RowBox[{"fn", "=", + RowBox[{"FileNames", "[", "]"}]}], ";"}]], "Input", + CellChangeTimes->{{3.4103699136875*^9, 3.410369919453125*^9}}], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{"?", "ExtractDataFromCMEString"}]], "Input", + CellChangeTimes->{{3.4112981245336647`*^9, 3.4112981281562977`*^9}, + 3.4112983447179594`*^9}], + +Cell[BoxData[ + StyleBox["\<\"ExtractDataFromCMEString[instring] extracts the data from the \ +given input string, itself obtained from a CME pdf.\"\>", "MSG"]], "Print", \ +"PrintUsage", + CellChangeTimes->{3.4112983453581657`*^9}, + CellTags->"Info3411280345-6648233"] +}, Open ]], + +Cell[BoxData["Extract"], "Input", + CellChangeTimes->{{3.411298148065168*^9, 3.4112981496422625`*^9}}], + +Cell[BoxData[ + RowBox[{ + RowBox[{"instring", "=", + RowBox[{"ImportSectionPDFfromCME", "[", + RowBox[{"9", ",", + RowBox[{"{", + RowBox[{"2008", ",", "14"}], "}"}]}], "]"}]}], ";"}]], "Input", + CellChangeTimes->{{3.410330596390625*^9, 3.41033062196875*^9}}], + +Cell[BoxData["instring"], "Input", + CellChangeTimes->{{3.4112981734079885`*^9, 3.4112981777020583`*^9}}], + +Cell[BoxData[ + RowBox[{ + RowBox[{ + "file", "=", + "\"\<Section09_Interest_Rate_And_Energy_Futures_2008015.txt\>\""}], + ";"}]], "Input", + CellChangeTimes->{ + 3.4102653442889776`*^9, 3.4102653945172443`*^9, 3.410265535728715*^9, + 3.410298607109375*^9, {3.410298852875*^9, 3.410298857765625*^9}}], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{"filename", "=", + RowBox[{"fn", "[", + RowBox[{"[", "4", "]"}], "]"}]}]], "Input", + CellChangeTimes->{{3.410369930203125*^9, 3.410369935328125*^9}, + 3.41037048921875*^9, {3.41037094071875*^9, 3.410370968578125*^9}, + 3.41037100975*^9}], + +Cell[BoxData["\<\"Section09_Interest_Rate_And_Energy_Futures_2007116.pdf\"\>"]\ +, "Output", + CellChangeTimes->{ + 3.4103699356875*^9, 3.410370489390625*^9, 3.410370534921875*^9, { + 3.410370940890625*^9, 3.410370968765625*^9}, 3.410371009921875*^9, + 3.411298819282961*^9}] +}, Open ]], + +Cell[BoxData[ + RowBox[{ + RowBox[{"instring", "=", + RowBox[{"Import", "[", + RowBox[{"filename", ",", "\"\<Plaintext\>\""}], "]"}]}], ";"}]], "Input", + CellChangeTimes->{{3.410330501203125*^9, 3.410330515828125*^9}, { + 3.410369947484375*^9, 3.4103699574375*^9}, {3.410370006421875*^9, + 3.410370012546875*^9}}], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{"ReadDataFromCMEPDF", "[", "filename", "]"}]], "Input", + CellChangeTimes->{{3.410361731375*^9, 3.410361734625*^9}, { + 3.410361776953125*^9, 3.410361779578125*^9}, 3.410369979953125*^9, + 3.41037059221875*^9, 3.410370911390625*^9, {3.411298352447285*^9, + 3.4112983531187215`*^9}, {3.411298822530839*^9, 3.411298827043516*^9}}], + +Cell[BoxData[ + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"9", ",", "116", ",", + RowBox[{"{", + RowBox[{"2007", ",", "6", ",", "15"}], "}"}], ",", "5.36`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2007", ",", "6", ",", "18"}], "}"}], ",", "5.36`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2007", ",", "7", ",", "16"}], "}"}], ",", "5.36`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2007", ",", "8", ",", "13"}], "}"}], ",", "5.36`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2007", ",", "9", ",", "17"}], "}"}], ",", "5.36`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2007", ",", "12", ",", "17"}], "}"}], ",", "5.38`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "3", ",", "17"}], "}"}], ",", "5.36`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "6", ",", "16"}], "}"}], ",", "5.34`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "9", ",", "15"}], "}"}], ",", "5.36`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2008", ",", "12", ",", "15"}], "}"}], ",", "5.38`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2009", ",", "3", ",", "16"}], "}"}], ",", "5.41`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2009", ",", "6", ",", "15"}], "}"}], ",", "5.45`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2009", ",", "9", ",", "14"}], "}"}], ",", "5.48`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2009", ",", "12", ",", "14"}], "}"}], ",", "5.52`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2010", ",", "3", ",", "15"}], "}"}], ",", "5.54`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2010", ",", "6", ",", "14"}], "}"}], ",", "5.57`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2010", ",", "9", ",", "13"}], "}"}], ",", "5.6`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2010", ",", "12", ",", "13"}], "}"}], ",", "5.64`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2011", ",", "3", ",", "14"}], "}"}], ",", "5.66`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2011", ",", "6", ",", "13"}], "}"}], ",", "5.68`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2011", ",", "9", ",", "19"}], "}"}], ",", "5.71`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2011", ",", "12", ",", "19"}], "}"}], ",", "5.75`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2012", ",", "3", ",", "19"}], "}"}], ",", "5.76`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2012", ",", "6", ",", "18"}], "}"}], ",", "5.79`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2012", ",", "9", ",", "17"}], "}"}], ",", "5.81`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2012", ",", "12", ",", "17"}], "}"}], ",", "5.85`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2013", ",", "3", ",", "18"}], "}"}], ",", "5.87`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2013", ",", "6", ",", "17"}], "}"}], ",", "5.89`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2013", ",", "9", ",", "16"}], "}"}], ",", "5.92`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2013", ",", "12", ",", "16"}], "}"}], ",", "5.95`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2014", ",", "3", ",", "17"}], "}"}], ",", "5.97`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2014", ",", "6", ",", "16"}], "}"}], ",", "5.99`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2014", ",", "9", ",", "15"}], "}"}], ",", "6.01`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2014", ",", "12", ",", "15"}], "}"}], ",", "6.04`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2015", ",", "3", ",", "16"}], "}"}], ",", "6.05`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2015", ",", "6", ",", "15"}], "}"}], ",", "6.06`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2015", ",", "9", ",", "14"}], "}"}], ",", "6.08`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2015", ",", "12", ",", "14"}], "}"}], ",", "6.11`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2016", ",", "3", ",", "14"}], "}"}], ",", "6.13`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2016", ",", "6", ",", "13"}], "}"}], ",", "6.14`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2016", ",", "9", ",", "19"}], "}"}], ",", "6.16`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2016", ",", "12", ",", "19"}], "}"}], ",", "6.2`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2017", ",", "3", ",", "13"}], "}"}], ",", "6.21`"}], "}"}]}], + "}"}]}], "}"}]], "Output", + CellChangeTimes->{3.4103709123125*^9, 3.410370965453125*^9, + 3.410371014140625*^9, 3.411298187804834*^9, 3.4112983539619207`*^9, + 3.4112983982611084`*^9, 3.4112984330196533`*^9, 3.4112985810479574`*^9, + 3.411298828199012*^9}] +}, Open ]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{"Section09DataForDataBase", "[", + "\"\<O:\\\\CME PDF\\\\B2007248PG9.pdf\>\"", "]"}]], "Input"], + +Cell[BoxData[ + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2007", ",", "12", ",", "21"}], "}"}], ",", "248", ",", + RowBox[{"{", + RowBox[{"2008", ",", "1", ",", "14"}], "}"}], ",", "4.67`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2007", ",", "12", ",", "21"}], "}"}], ",", "248", ",", + RowBox[{"{", + RowBox[{"2008", ",", "2", ",", "18"}], "}"}], ",", "4.45`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2007", ",", "12", ",", "21"}], "}"}], ",", "248", ",", + RowBox[{"{", + RowBox[{"2008", ",", "3", ",", "17"}], "}"}], ",", "4.33`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2007", ",", "12", ",", "21"}], "}"}], ",", "248", ",", + RowBox[{"{", + RowBox[{"2008", ",", "4", ",", "14"}], "}"}], ",", "4.17`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2007", ",", "12", ",", "21"}], "}"}], ",", "248", ",", + RowBox[{"{", + RowBox[{"2008", ",", "5", ",", "19"}], "}"}], ",", "4.01`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2007", ",", "12", ",", "21"}], "}"}], ",", "248", ",", + RowBox[{"{", + RowBox[{"2008", ",", "6", ",", "16"}], "}"}], ",", "3.87`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2007", ",", "12", ",", "21"}], "}"}], ",", "248", ",", + RowBox[{"{", + RowBox[{"2008", ",", "9", ",", "15"}], "}"}], ",", "3.65`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2007", ",", "12", ",", "21"}], "}"}], ",", "248", ",", + RowBox[{"{", + RowBox[{"2008", ",", "12", ",", "15"}], "}"}], ",", "3.56`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2007", ",", "12", ",", "21"}], "}"}], ",", "248", ",", + RowBox[{"{", + RowBox[{"2009", ",", "3", ",", "16"}], "}"}], ",", "3.59`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2007", ",", "12", ",", "21"}], "}"}], ",", "248", ",", + RowBox[{"{", + RowBox[{"2009", ",", "6", ",", "15"}], "}"}], ",", "3.72`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2007", ",", "12", ",", "21"}], "}"}], ",", "248", ",", + RowBox[{"{", + RowBox[{"2009", ",", "9", ",", "14"}], "}"}], ",", "3.86`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2007", ",", "12", ",", "21"}], "}"}], ",", "248", ",", + RowBox[{"{", + RowBox[{"2009", ",", "12", ",", "14"}], "}"}], ",", "4.`"}], "}"}], ",", + + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2007", ",", "12", ",", "21"}], "}"}], ",", "248", ",", + RowBox[{"{", + RowBox[{"2010", ",", "3", ",", "15"}], "}"}], ",", "4.13`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2007", ",", "12", ",", "21"}], "}"}], ",", "248", ",", + RowBox[{"{", + RowBox[{"2010", ",", "6", ",", "14"}], "}"}], ",", "4.27`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2007", ",", "12", ",", "21"}], "}"}], ",", "248", ",", + RowBox[{"{", + RowBox[{"2010", ",", "9", ",", "13"}], "}"}], ",", "4.39`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2007", ",", "12", ",", "21"}], "}"}], ",", "248", ",", + RowBox[{"{", + RowBox[{"2010", ",", "12", ",", "13"}], "}"}], ",", "4.5`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2007", ",", "12", ",", "21"}], "}"}], ",", "248", ",", + RowBox[{"{", + RowBox[{"2011", ",", "3", ",", "14"}], "}"}], ",", "4.59`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2007", ",", "12", ",", "21"}], "}"}], ",", "248", ",", + RowBox[{"{", + RowBox[{"2011", ",", "6", ",", "13"}], "}"}], ",", "4.69`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2007", ",", "12", ",", "21"}], "}"}], ",", "248", ",", + RowBox[{"{", + RowBox[{"2011", ",", "9", ",", "19"}], "}"}], ",", "4.77`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2007", ",", "12", ",", "21"}], "}"}], ",", "248", ",", + RowBox[{"{", + RowBox[{"2011", ",", "12", ",", "19"}], "}"}], ",", "4.86`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2007", ",", "12", ",", "21"}], "}"}], ",", "248", ",", + RowBox[{"{", + RowBox[{"2012", ",", "3", ",", "19"}], "}"}], ",", "4.92`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2007", ",", "12", ",", "21"}], "}"}], ",", "248", ",", + RowBox[{"{", + RowBox[{"2012", ",", "6", ",", "18"}], "}"}], ",", "5.`"}], "}"}], ",", + + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2007", ",", "12", ",", "21"}], "}"}], ",", "248", ",", + RowBox[{"{", + RowBox[{"2012", ",", "9", ",", "17"}], "}"}], ",", "5.07`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2007", ",", "12", ",", "21"}], "}"}], ",", "248", ",", + RowBox[{"{", + RowBox[{"2012", ",", "12", ",", "17"}], "}"}], ",", "5.14`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2007", ",", "12", ",", "21"}], "}"}], ",", "248", ",", + RowBox[{"{", + RowBox[{"2013", ",", "3", ",", "18"}], "}"}], ",", "5.2`"}], "}"}], ",", + + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2007", ",", "12", ",", "21"}], "}"}], ",", "248", ",", + RowBox[{"{", + RowBox[{"2013", ",", "6", ",", "17"}], "}"}], ",", "5.26`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2007", ",", "12", ",", "21"}], "}"}], ",", "248", ",", + RowBox[{"{", + RowBox[{"2013", ",", "9", ",", "16"}], "}"}], ",", "5.32`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2007", ",", "12", ",", "21"}], "}"}], ",", "248", ",", + RowBox[{"{", + RowBox[{"2013", ",", "12", ",", "16"}], "}"}], ",", "5.39`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2007", ",", "12", ",", "21"}], "}"}], ",", "248", ",", + RowBox[{"{", + RowBox[{"2014", ",", "3", ",", "17"}], "}"}], ",", "5.44`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2007", ",", "12", ",", "21"}], "}"}], ",", "248", ",", + RowBox[{"{", + RowBox[{"2014", ",", "6", ",", "16"}], "}"}], ",", "5.48`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2007", ",", "12", ",", "21"}], "}"}], ",", "248", ",", + RowBox[{"{", + RowBox[{"2014", ",", "9", ",", "15"}], "}"}], ",", "5.52`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2007", ",", "12", ",", "21"}], "}"}], ",", "248", ",", + RowBox[{"{", + RowBox[{"2014", ",", "12", ",", "15"}], "}"}], ",", "5.57`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2007", ",", "12", ",", "21"}], "}"}], ",", "248", ",", + RowBox[{"{", + RowBox[{"2015", ",", "3", ",", "16"}], "}"}], ",", "5.6`"}], "}"}], ",", + + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2007", ",", "12", ",", "21"}], "}"}], ",", "248", ",", + RowBox[{"{", + RowBox[{"2015", ",", "6", ",", "15"}], "}"}], ",", "5.64`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2007", ",", "12", ",", "21"}], "}"}], ",", "248", ",", + RowBox[{"{", + RowBox[{"2015", ",", "9", ",", "14"}], "}"}], ",", "5.67`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2007", ",", "12", ",", "21"}], "}"}], ",", "248", ",", + RowBox[{"{", + RowBox[{"2015", ",", "12", ",", "14"}], "}"}], ",", "5.71`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2007", ",", "12", ",", "21"}], "}"}], ",", "248", ",", + RowBox[{"{", + RowBox[{"2016", ",", "3", ",", "14"}], "}"}], ",", "5.74`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2007", ",", "12", ",", "21"}], "}"}], ",", "248", ",", + RowBox[{"{", + RowBox[{"2016", ",", "6", ",", "13"}], "}"}], ",", "5.77`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2007", ",", "12", ",", "21"}], "}"}], ",", "248", ",", + RowBox[{"{", + RowBox[{"2016", ",", "9", ",", "19"}], "}"}], ",", "5.8`"}], "}"}], ",", + + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2007", ",", "12", ",", "21"}], "}"}], ",", "248", ",", + RowBox[{"{", + RowBox[{"2016", ",", "12", ",", "19"}], "}"}], ",", "5.83`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2007", ",", "12", ",", "21"}], "}"}], ",", "248", ",", + RowBox[{"{", + RowBox[{"2017", ",", "3", ",", "13"}], "}"}], ",", "5.85`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2007", ",", "12", ",", "21"}], "}"}], ",", "248", ",", + RowBox[{"{", + RowBox[{"2017", ",", "6", ",", "19"}], "}"}], ",", "5.87`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2007", ",", "12", ",", "21"}], "}"}], ",", "248", ",", + RowBox[{"{", + RowBox[{"2017", ",", "9", ",", "18"}], "}"}], ",", "5.89`"}], "}"}], + ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"2007", ",", "12", ",", "21"}], "}"}], ",", "248", ",", + RowBox[{"{", + RowBox[{"2017", ",", "12", ",", "18"}], "}"}], ",", "5.93`"}], "}"}]}], + "}"}]], "Output", + CellChangeTimes->{3.4112995531785607`*^9}] +}, Open ]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{"DateListPlot", "[", + RowBox[{ + RowBox[{"%", "[", + RowBox[{"[", + RowBox[{"All", ",", + RowBox[{"{", + RowBox[{"3", ",", "4"}], "}"}]}], "]"}], "]"}], ",", + RowBox[{"Joined", "\[Rule]", "True"}]}], "]"}]], "Input", + CellChangeTimes->{{3.410371060625*^9, 3.410371073796875*^9}, { + 3.4112988332894363`*^9, 3.41129883339874*^9}, {3.4112995632344923`*^9, + 3.4112995675910215`*^9}}], + +Cell[BoxData[ + GraphicsBox[{{}, {}, + {Hue[0.67, 0.6, 0.6], + LineBox[{{3.4092576*^9, 4.67}, {3.4122816*^9, 4.45}, {3.4147008*^9, + 4.33}, {3.41712*^9, 4.17}, {3.420144*^9, 4.01}, {3.4225632*^9, 3.87}, { + 3.4304256*^9, 3.65}, {3.438288*^9, 3.56}, {3.4461504*^9, 3.59}, { + 3.4540128*^9, 3.72}, {3.4618752*^9, 3.86}, {3.4697376*^9, 4.}, { + 3.4776*^9, 4.13}, {3.4854624*^9, 4.27}, {3.4933248*^9, 4.39}, { + 3.5011872*^9, 4.5}, {3.5090496*^9, 4.59}, {3.516912*^9, 4.69}, { + 3.5253792*^9, 4.77}, {3.5332416*^9, 4.86}, {3.541104*^9, 4.92}, { + 3.5489664*^9, 5.}, {3.5568288*^9, 5.07}, {3.5646912*^9, 5.14}, { + 3.5725536*^9, 5.2}, {3.580416*^9, 5.26}, {3.5882784*^9, 5.32}, { + 3.5961408*^9, 5.39}, {3.6040032*^9, 5.44}, {3.6118656*^9, 5.48}, { + 3.619728*^9, 5.52}, {3.6275904*^9, 5.57}, {3.6354528*^9, 5.6}, { + 3.6433152*^9, 5.64}, {3.6511776*^9, 5.67}, {3.65904*^9, 5.71}, { + 3.6669024*^9, 5.74}, {3.6747648*^9, 5.77}, {3.683232*^9, 5.8}, { + 3.6910944*^9, 5.83}, {3.698352*^9, 5.85}, {3.7068192*^9, 5.87}, { + 3.7146816*^9, 5.89}, {3.722544*^9, 5.93}}]}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + AxesOrigin->NCache[{3409257600, 4.}, {3.4092576*^9, 4.}], + Frame->True, + FrameTicks->{{Automatic, Automatic}, {{{ + NCache[3408134400, 3.4081344*^9], + FormBox["\"2008\"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\"2010\"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\"2012\"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\"2014\"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\"2016\"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\"2018\"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}, {{ + NCache[3408134400, 3.4081344*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3471292800, 3.4712928*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3534364800, 3.5343648*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3597523200, 3.5975232*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3660595200, 3.6605952*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3723753600, 3.7237536*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3439756800, 3.4397568*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3502828800, 3.5028288*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3565987200, 3.5659872*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3629059200, 3.6290592*^9], + FormBox["\" \"", TraditionalForm]}, { + NCache[3692217600, 3.6922176*^9], + FormBox["\" \"", TraditionalForm]}}}}, + GridLines->NCache[{{{3408134400, + GrayLevel[0.8]}, {3471292800, + GrayLevel[0.8]}, {3534364800, + GrayLevel[0.8]}, {3597523200, + GrayLevel[0.8]}, {3660595200, + GrayLevel[0.8]}, {3723753600, + GrayLevel[0.8]}}, None}, {{{3.4081344*^9, + GrayLevel[0.8]}, {3.4712928*^9, + GrayLevel[0.8]}, {3.5343648*^9, + GrayLevel[0.8]}, {3.5975232*^9, + GrayLevel[0.8]}, {3.6605952*^9, + GrayLevel[0.8]}, {3.7237536*^9, + GrayLevel[0.8]}}, None}], + PlotRange->{{3.4092576*^9, 3.722544*^9}, {3.56, 5.93}}, + PlotRangeClipping->True, + PlotRangePadding->{ + Scaled[0.02], + Scaled[0.02]}, + Ticks->None]], "Output", + CellChangeTimes->{3.410371074203125*^9, 3.4112988339608727`*^9, + 3.4112995683717613`*^9}, + ImageCache->GraphicsData["CompressedBitmap", "\<\ +eJztXVuMXVUZPp1zmbYUWsCWysUOtFAuhZZyKRTKtOVWpFgwMWKMiZWo5UEh +OCZGX/BBeNGY6IOSTCwRVBATMSYQCWQMjReSRhIj0ajJBBODDxISiTEkJuP5 +/sva65/598w+5+yz99qmTeey1+yz9v+t9d/Xv9a+5+jMsU9/7ujMgw8cnbrz +kaMPH3vwgS9M3fHQI/2m9qpWa9Wr/a8rp1r4faHV0m8L/f8LJ/ANLSv/fjr9 +OK01N9Na9O9Qa3ae7mwtzM/2r7K2CWrtLG7X5vnZQ1kns/M3j/KE+EMzczkP +vmnoJ/QWP4Fa+01tum6bLm4sD0iHmtvU1cwcf3TvGMYpau4/ZgwzsWiuubl1 +Bv04h/6q8NDxzOx8//e51ow+EA87NNuaJ7bNaSeCZlpz4R4eMgUzyDOYvLVM +tUz2Qv6zbxr6EW3zCG7ruv2U9QyPo4bv2xkimgblk/DZUmfBn+lVzFPr6cem +PkC9Q74YsVzPt7jTZdoNz4X2fUJUwe5zMfi33zxM73aC22GCsy6GIrq7hGjc +3RGFd4gmLtZIA3bfW9K9XE8EAK3wlKHGJYdzls6p4Zwe81S4i+kKOqsT6DLN +qw2587MzfW7m/lvc074infdML0vGpKd3mxkJpnPYzlUlxJ8ug9xuf3pmg8FQ +hTPWgRit83bg+yXT1xIe2RCQzUSzzbQsyyCLH8pqq//Q/Sv2ONpgDNVzV1ki ++ugI3QV+gMzNzhl+uKUc/C1ohrmF4Jf0ux6hZ1Wi0TyJYs04INIlqmc8Dgh0 +TkYPE96CahLiplfstuAwWHUds8HgPQc2iD46QndtGR5gxtQLC9wyKvRucAlm +ZoLnOfqIdt2JmojZYKN1RoZxMYwjw04QD8iaQn0P6GDsG7hr332MPz9qn8Fj +me1bC6MVBulz0vHW+R7M2oEyhtSfLrEMHCBvFuORSWArL25xJn759iiG3TDE +YxayICzTGTm37y33KTndlPQUy5M8hyUNk2cH9o17BpZyVaSJvJDbT68MknUZ +6AE6KEtD15yMyxC9r8mV5riLobtfOSbeW07XweRF3fQfURLhy2dXCMgAKb68 +38/GD/zSeg7fulFrqy3ZxIV4IE3bJRW0ba/gGR629qmhODUUwwzFyZMnQ9s2 +brv0zTff2fz22/+m+y917jvitN1b8L4j4yF9K33v3f/Ky399/YFP/eSt+448 +hZ9f+sHTrwPOJWNCEbeVgOIi+r72ky++8KcfffXRl1e/995/0bLrL3/+5+NP +fPe1P37i48/Of/QjP/zmt7/16xve+MM/tjYD1YXchrk4/vhjv6QrVt29qbfe ++tfDz/3497958NjzmDP8/dBrv/3bVDOQCZmPHv/eScwPXa3huyFAmMe5hz7/ +cyDfkgAi+ouHQ4jD6AMLXbG/1wb9+1//3d/p6oKxgOiYtv5Xp6Bxjz8mpEFk +AANDL2nUNqYCygA/xwShdM46P4Pz0698+RcE50xuw2xgVuL7UodzHrdtePfd +91784swLEHH+7AT4rSEgzs1ABKnY6EjJuc2A8/5MOqB+YWRam7I2GBtAbRgc +6Nqgi8/htntPvDoPKYrvSx3OZm6DAoDJJ90lpMP8w2jG9zUEDvwzeDbxTAAi +5AceTcPgwKqQ3OBK5AQuDdpJds5pBhwhEzMAVUBX5zuysykBOLlOjIAAsSCa +ri5wJGZjBSAmAqUDujGRAoY/TFcfcOSkChAlMNYmZ/zF2URYBjmhIOd9zYCz +MZsJzA6JuEQ3gAeYdHV2o+AY0jkEtQ7NWY2CA8cFzBXDMUq5IXBEJowClgwN +woEQSp/ZKDjB/cfVxdxmVPaGZsCR+2D9wVh0JVkmE282C853vvH1E8d+9vwb +dLXdYcD1CcDJ9QDOysYfPjNZlsu4LeQEcHVGBSCG9gAEhIljBAS0FxgL2qwS +ECUwlmgnE8dcwW0mkXF6o+CYOGYHtxknZ12j4Jg4Zkc2Y2gnU9oQOKJsTRxz +ldN2WqPgGPO4E98pa9YQEFESNkQ0uzIWC6mntY2CY3zmq7nNRDRrGgXHsNhu +B+LqRsGBpSEjiatruM1ENJMJwMl1Y8Syw9q/c/ddx+nqWm4zcUwVIIZ2YwSE +cR6v4zYTvfQSmImicEjt7nEkptsgEItCsOu5zcQszYIDGSF5wNUeh+28zyYI +RzxgiDj0F13xBj4bvbQbBcd4ygLHxDHNgmOcfK7Ms3HMRL1w+MdppoAwrkaN +r7XMrzvYEBhDKuWDZlj6X/S5+6qGbesmuc0pa+XqWK+3ZVD/5/ZbZ7UeR1Gb +EKkG1AJY/03Q97VmGwF9+dXlRQdAYj+T6eLK4w7a4MBjIPCZKrH7e7o6Muk5 +G5Hozx0eulykSIAhEUZXXP4fnOGxTHE38q9y9iYVwVV8Lo09meY2mMuFJ4+/ +nItmjBMpTBrtxDGAna1EAwI2awICmEocP3b/98nlqRBw2FUabTJRtCOKqqQE +TORwQO579pm5YKQqNEiKNjZCAa2/P2FAtMbXO5DdB2edqtkqN7/WDnX0uzW7 +Ra2uoDQWllGGujm1yB+qDmhRt0moNz4DU9/V+0zocU96ECQxBRsHoSIn4KCF +gK/gBaYLwTiqBy0P6RfFuIeThWCSUged+yYchvtgxXByMzsCwuQOlgFhsj1l +gxg6syMgTNjtgRBdaNTzXekxliRq4R3AS6CrW/MfZfTwoWThmBzbMnBMUVG6 +cIzD6sHpZrMYUvB3JgvHuKMeHMmKmkjkjvTgyKqA8Tdvc+6TTLVRyrcnC8do +rGXgmCrpdOGgigDVBLlw5D6jMrz70oBjjKdHpsgYko5IPubKWBpwsCZKnu8K +cIyXXDWcXIdGJMEoAE8S1jqS5fkMtTg0AsJ4xx4IiWWMLTpQMogSGEvgGE95 +GTgmGZ8uHDPqHpx1zizuTxaOqbjx4HjrDdPJwjHZ8WXgmIx5gnDE7zK5bs/v +kqVHeM1gNoJ+S7JwzBqcB4fKJijyTxeEkQQPhFRLmdXtm5OFY8hcBo5Rz+nC +MW6MB0cqDU2AdlPFcHLdGIkeTY2aFz1Kba5xY/aWDGJoN0ZAgKnAXLkgsn23 +ZZNeAjsJCOO8eCBkN4EJBm5IFo4hcxk4EHasp5J5TBeOSf15cGQnDmAADt27 +Jz040masvZcDk11sRuyvTxaOkR0PjmyUNDsMrksWjpEdD85m575rk4VjZGcZ +OMZTThBO25EdL7svm7zNUsY1FcPJtfttR2I8ELK127j7u0sGMbTdbzv874GQ +MzhMMHB1soxl5MSDI/vTjRbblR6cCUdOvKU82aluNuDtTBaOkRgPjuxZN1HO +VcnCMbKzDBw9+oUyN+nCMctLHpwt3AalDDgUW16ZApye6aL/BVWL5NJh5wlT +mWgBBWmLHdWh4B+T+aW2/T9wSWbbVLDllzctQa9aw0Mv5w6YcO+KqtHbSqee +3hAdcz4AWrVMHlrZx28WRC+vDq1baWtfPdEJ96Nsjw/aHQC8rtJ54OWcP7OQ +d1mF4P1S29WBA7JThekTVM464cNUTevB3MZtyPSHRJ93/OSYS20nAxJUJw48 +kap8PYRy3gEsZzhnb3vJCAcvtQ1iK8oLXJ1fnWiK3sLCn1f0JschAGmQWe8g +zsrrbDutcIo2w+0VQxv2EHtoZR6hocIq+sXVo40tkL40IT4fvCDUoGg9qCKU +WI6D6aFwaFt1UPOLbLtmYlsrCq+BHBYYPMiibmFtocLI19haHeR8j8lACO62 +B+HyDEJwly5KDkJYSPAgiH+jHh/5rRemACGU0apC9EqxdzjUTyVFvSo4j3qJ +D0zMsKVi6qNETqBZNZVH81UOzR8omeYB8jaBZlU1Hs07HZq9Q2vr4xLVMh71 +uxzqveNd66NeFYxHfXSQQ1i3OC8F6qmL4Gx53Uo60gTD3smt9ZAePCev22sc +0r1TWushPXhCXrfXZqTrPkj3CNN6SA8ejdetrPioR0Oke8eV1kM6fEtSHl63 +1zuke0eT1pyN87rd45DuneWZIOmyHo0sDXidnDTv3M5aVnK8zuS0AegeBOVU +ee6dzFnLqo3XmdRjaJaZUgTeYZUJModUJoFkuAekw72jDxMkfV8mksi10k6Y +9c0gXar11NuihSPvXMAESZ/mu6EAYV31dSfrmkG91Enr62ZoscU7jy1B0qXs +Xn1cShd4Z68lSLpse4ByCS/F8M5ZS5D027jNvJ7EO1MtQdKlmhNkh9UH79Su +ZOy+VKRhuSRk2b0jrZKx+1IGZBLl3mcTZA6pzDBZb+9olQRJl4Vxk8X2Tm9K +kPS7madNFNFvoXs+nB65h/lukKtpFfw9QUol6Yx4HiHDwtNPvZLigHLuit4x +tvDZzzwDHsDvCXIqt1HyDcu+GFQYkaJUVU5pWM4Fk8KCgGEREnjLEbVYN25b +bdoWstQ9aAbtd49Ab6nGzWsTCwFOAEdQ6ZVXp5QES3iPItGD2OlioFfJmyD1 +4rdhwMEslGHzCvgTJF3KMnQDEWVzvI1GCZIeHZMAT4PCdG+TZIKkS3ilYTrV +fN7WDNIlHkcCPKSkvD3nJZCOv8X1YfpO9dUrnb1Z9BCwojSu4zb1tHL3dJeA +Wasw4mI/bhv5yM2i1MmmYqMS9o8ZbVTdF9COdmhfUeqiY8HBz5RCmB4PWq1l +jEv7pKBv2RMoo8q/4WjivGtH0yT4At59I3QZV/xls5iV9rUL4CpxFmUfLGZP +XUt3W28Js7i4JAzoOhHaEY7VLErdWZmE6ouQ3V2/JelgW9XXrVY+z854F044 +ZBRe4o1jgss/tbSvp1hHO1KzKGGyZKlrJpRE9varlgG0Jy1LCvtCMed4bSqv +LJPHjznF3GKOvQ2gCXpBUo0AyYME0kqFt9kzQdKlBkQjWzJ43k7IBEnnypsO +bFdsx7w9gwlSLwVbxkZ5OwUTJF0q5dTgUPWLtyuwxtSNbeNyRLIaCK40UvE2 +lyWTvpGiVWj9UFjhbR9LkD+kWhjKHPxBO0d3NIN0KTeHJg/1N94WqARJ38Zt +UCR4tQm5gd4GpgRJvziTTzCLVoh4u3YSpJ7JDO9pgIaBdvH2pSRIvbAIlDj0 +DJ3muK0ZpLNgktOI0haodSRjvP0WCVIvGlEVPMmrt88iGSt6pZVSEA0p3TJC +l2O3oju5By3EUR/Rq/VPkEXEH4SPiNEm59wr9E+Q9N2ZbGLQIZuYBK9aPkHq +OQLqaOiNohGwvVd1niD112WCCso1besVnidIPVdvdzS6APeAi7wC7gSpl0yU +EVmvgDtB0rkyOsTTekaaVxydIPWc3+3AIoHhNYNU9NXwNVMv7/oCxbpgD+Wz +fozUj+wPTPNj4HJBvcMFg6AWfcl4Lf5AVFOMMaZV4nXNYJGDmXhilRi6EcNd +9JXONVMv69mwQ8rchV/fXDPpt2cDDz5HfAc5Lfpm4Jqpl8oTxHfh1Mui7wOu +mXSp99EDesiWFn1tbs2kc8luWGOFbgT/eFW7CVIvdW2684Jy06OsOFdI+mH6 +3oVRArvD/9VSWPeVkjWTK0WmIBNJu4XHvkZbc4sWmY7dxnNbl4awTxtohCah +Ymhvc3ctRp1Hi6pKQSgUdEzo4fSmnSmejNtgy0F5iBqKFpdWTrYzu+wFQtNh +4EG+d5pkgtRzf12lHucWQBYp71+08LFmCGzMuyAZpAMCzA0p7aJVhDVDYEew +q7ueVQRIyxStrBuicrCz+CjBwU4SLA8/V1F24ZspF0IVUGXh9Oj4vSrCwY4R +LA8qR4dkUKCfoS7CgUpFK9AGLCHsOW1VQOXUQ1cPj9RFOaqR9d4KMCBUr36w +57TR7bmv4x4FIGeGSHki3QK2BfuS5ilaqLRS5WDPaati8jhn14MK0hINrY9B +W9HqngErBwc7JbA8tJwa7mLmYjOYe5D4EArYKxtc0px/cF55WLniiTSQut3B +pS1agFO8ZlAPuix2PGB5KM/LUC72h90jrwdFuULB4KCHBJYHnJf2Oovd6aK1 +PjV7Qlu419ibhle0oxnU8/I1GQS4oJq0ITVStBSlZghcANRDzgkTgKPAdDsR +YHlHqyaIgsnswfVArhhspOuYcDK3NgPFZdlcgHKIMpBArGGppkpCMXKSxKOd +JbYHntHUqy44DFKAUFHuxLaxfaBwBNwDbwA/KXXsndSXIOuwIe/C3GHIMfSY +Aqpu8o69SxAC1yCQTwZlilmAl01BoXcQW4IQuHy/B1uMyAfCi1mAQICZvHPC +EkTBS/o9TIR6FPjCZEA1FV1hrhkFr4/3MO6YC5gDFWzsVC66alsziumMoyDX +2BkOEw1TDWRFF0NrRsFLuT0YAi0UiYPLoiuLNaPgddEQNEK6g4IqukxXMwRe +HO3GCgosRdmootmSWtwLPsihB8nV3JI6d7jPW+mqxZU4zHSCJ9SFW7jvyJPQ +oygFSJAl+L7JhZde+hXsFMosNLGF0aYA2luaSYLstXEbuBoqRZWkHueWd5RG +EghsGz9+EoOOwdeITHcdkarxDnlIEAor9R64XhMykAZIBbwI79CEBFGwgSUv +QktLgQReBJTmdDNQsLMzCfaBFwENCraCmw0BodU/bwd1glDY+5yETCO40ewt +JgYWjV6i5uXiE4TCKfdJkKy7gGIPlTSvtzW1FgPs3cdZ9MnYOcVr1VTvElt5 +GeZaLLN3Hwf3PVW1GP04XvNyqAnyEe/2zI3XvPe3JYiCc6mTi+M1zAuYiwTb +2yCXIJRt9H2N+iMQaMCBbOgR3DAeuS/LSRASv51pDXQSLLoeyQ0rAl4DREgN +7dr1XoaSICTe3rUWDAcGg+hgdham9z0BSDCOgAlImClvL0yCqHZnqGAfgQCo +MFFaexDzn5eSShAV75FZCwcGlMfspzEslAbmCizqHVeeICpOUa0BKpggKGzM +FfQEOFDfWUh21Mv0JAiJq5fIX4bqg1DFZRLe6dTJuDOS39HyB12+ID/My+8k +48ZIVsddv/CyOgnyDZdPkluv6xcQBVq/6P+F7vXKCGom+zA/CXoH9gI/8fch +KY3bLimhbRhERZ8xJA+VDXGltu0VPOPUUJwaisGHAr+0nousB91y4v/799aq +/wGpzok+\ +\>"]] +}, Open ]] +}, Open ]] +}, +WindowSize->{971, 935}, +WindowMargins->{{4, Automatic}, {Automatic, 3}}, +PrintingCopies->1, +PrintingPageRange->{Automatic, Automatic}, +ShowSelection->True, +FrontEndVersion->"6.0 for Microsoft Windows (32-bit) (June 19, 2007)", +StyleDefinitions->"Default.nb" +] +(* End of Notebook Content *) + +(* Internal cache information *) +(*CellTagsOutline +CellTagsIndex->{ + "Info3411280078-7196149"->{ + Cell[14716, 399, 312, 5, 73, "Print", + CellTags->"Info3411280078-7196149"]}, + "Info3411280081-2015869"->{ + Cell[15201, 413, 326, 6, 73, "Print", + CellTags->"Info3411280081-2015869"]}, + "Info3411280083-4726061"->{ + Cell[15713, 428, 369, 6, 73, "Print", + CellTags->"Info3411280083-4726061"]}, + "Info3411280345-6648233"->{ + Cell[26215, 713, 265, 5, 50, "Print", + CellTags->"Info3411280345-6648233"]} + } +*) +(*CellTagsIndex +CellTagsIndex->{ + {"Info3411280078-7196149", 57302, 1566}, + {"Info3411280081-2015869", 57412, 1569}, + {"Info3411280083-4726061", 57522, 1572}, + {"Info3411280345-6648233", 57632, 1575} + } +*) +(*NotebookFileOutline +Notebook[{ +Cell[CellGroupData[{ +Cell[590, 23, 92, 1, 88, "Section"], +Cell[685, 26, 206, 5, 52, "Input"], +Cell[894, 33, 689, 16, 141, "Input"], +Cell[1586, 51, 1398, 32, 185, "Input"], +Cell[2987, 85, 989, 26, 229, "Input"], +Cell[3979, 113, 1459, 38, 251, "Input"], +Cell[5441, 153, 409, 8, 97, "Input"], +Cell[5853, 163, 426, 8, 119, "Input"], +Cell[6282, 173, 487, 9, 119, "Input"], +Cell[6772, 184, 545, 15, 75, "Input"], +Cell[7320, 201, 313, 6, 97, "Input"], +Cell[7636, 209, 4882, 123, 427, "Input"], +Cell[12521, 334, 301, 6, 97, "Input"], +Cell[12825, 342, 432, 8, 35, "Input"], +Cell[13260, 352, 910, 26, 119, "Input"] +}, Open ]], +Cell[CellGroupData[{ +Cell[14207, 383, 92, 1, 88, "Section"], +Cell[14302, 386, 259, 5, 55, "Text"], +Cell[CellGroupData[{ +Cell[14586, 395, 127, 2, 52, "Input"], +Cell[14716, 399, 312, 5, 73, "Print", + CellTags->"Info3411280078-7196149"] +}, Open ]], +Cell[CellGroupData[{ +Cell[15065, 409, 133, 2, 52, "Input"], +Cell[15201, 413, 326, 6, 73, "Print", + CellTags->"Info3411280081-2015869"] +}, Open ]], +Cell[CellGroupData[{ +Cell[15564, 424, 146, 2, 52, "Input"], +Cell[15713, 428, 369, 6, 73, "Print", + CellTags->"Info3411280083-4726061"] +}, Open ]], +Cell[CellGroupData[{ +Cell[16119, 439, 255, 6, 52, "Input"], +Cell[16377, 447, 221, 3, 75, "Output"] +}, Open ]], +Cell[CellGroupData[{ +Cell[16635, 455, 279, 6, 35, "Input"], +Cell[16917, 463, 206, 3, 35, "Output"] +}, Open ]] +}, Open ]], +Cell[CellGroupData[{ +Cell[17172, 472, 97, 1, 88, "Section"], +Cell[17272, 475, 165, 4, 35, "Input"], +Cell[17440, 481, 474, 14, 35, "Input"], +Cell[CellGroupData[{ +Cell[17939, 499, 276, 8, 35, "Input"], +Cell[18218, 509, 1905, 27, 190, "Output"] +}, Open ]], +Cell[CellGroupData[{ +Cell[20160, 541, 323, 9, 35, "Input"], +Cell[20486, 552, 283, 6, 35, "Output"] +}, Open ]], +Cell[CellGroupData[{ +Cell[20806, 563, 373, 8, 35, "Input"], +Cell[21182, 573, 208, 3, 35, "Output"] +}, Open ]], +Cell[CellGroupData[{ +Cell[21427, 581, 1638, 37, 102, "Input"], +Cell[23068, 620, 543, 10, 94, "Message"], +Cell[23614, 632, 444, 9, 27, "Message"] +}, Open ]], +Cell[CellGroupData[{ +Cell[24095, 646, 733, 21, 58, "Input"], +Cell[24831, 669, 146, 2, 35, "Output"] +}, Open ]] +}, Closed]], +Cell[CellGroupData[{ +Cell[25026, 677, 94, 1, 50, "Section"], +Cell[CellGroupData[{ +Cell[25145, 682, 420, 9, 52, "Input"], +Cell[25568, 693, 275, 4, 52, "Output"] +}, Open ]], +Cell[25858, 700, 164, 4, 52, "Input"], +Cell[CellGroupData[{ +Cell[26047, 708, 165, 3, 52, "Input"], +Cell[26215, 713, 265, 5, 50, "Print", + CellTags->"Info3411280345-6648233"] +}, Open ]], +Cell[26495, 721, 101, 1, 35, "Input"], +Cell[26599, 724, 272, 7, 52, "Input"], +Cell[26874, 733, 104, 1, 52, "Input"], +Cell[26981, 736, 303, 8, 35, "Input"], +Cell[CellGroupData[{ +Cell[27309, 748, 267, 6, 52, "Input"], +Cell[27579, 756, 276, 5, 52, "Output"] +}, Open ]], +Cell[27870, 764, 318, 7, 35, "Input"], +Cell[CellGroupData[{ +Cell[28213, 775, 355, 5, 52, "Input"], +Cell[28571, 782, 6536, 223, 295, "Output"] +}, Open ]], +Cell[CellGroupData[{ +Cell[35144, 1010, 119, 2, 52, "Input"], +Cell[35266, 1014, 9954, 311, 515, "Output"] +}, Open ]], +Cell[CellGroupData[{ +Cell[45257, 1330, 429, 11, 52, "Input"], +Cell[45689, 1343, 11199, 206, 336, 3902, 84, "CachedBoxData", "BoxData", \ +"Output"] +}, Open ]] +}, Open ]] +} +] +*) + +(* End of internal cache information *) diff --git a/MathematicaFiles/Applications/ParticleFilter.m b/MathematicaFiles/Applications/ParticleFilter.m new file mode 100755 index 0000000..06cb395 --- /dev/null +++ b/MathematicaFiles/Applications/ParticleFilter.m @@ -0,0 +1,306 @@ +(* :Title: Particle Filter *) + +(* :Author: Mark Fisher *) + +(* :Context: ParticleFilter` *) + +(* :Mathematica Version: 6.0 *) + +(* :History: + Version 0.0 April 2005 + Version 0.1 May 2007 update for Version 6. + Use built-in RandomChoice (in addition to changing + Random and RandomArray to RandomReal) +*) + +(* :Summary: + SIR (Sampling Importance Resampling) particle filter and + backward simulation particle smoother +*) + +(* :Discussion: + This package implements ParticleFilter (an SIR particle filter) + and ParticleSmoother (a backward simulation particle smoother that + takes the output from ParticleFilter as input). In particular, given + {loglikelihood, states} = + ParticleFilter[data, {x0, w0}, f, gp, IncludeStates -> True]; + the marginal loglikelihood of the parameters (implicit in f and gp) is + given by loglikelihood. To compute n draws of paths from the smoothed + distribution, use + collected = CollectStates[states]; + smoothed = ParticleSmoother[collected, fp, n]; + +*) + +(* :References: + Doucet, de Freitas, and Gordon (editors), + "Sequenctial Monte Carlo Methods in Practice", + Springer, 2001. + + Arulampalam, Maskell, Gordon, and Clapp, + "A tutorial on particle filters for online nonlinear/non-Gaussian + Bayesian tracking", + IEEE Transactions on Signal Processing, vol. 50, no. 2, February 2002. + + Godsill, Doucet, and West, + "Monte Carlo smoothing for nonlinear time series", + Journal of the American Statistical Association, vol. 99, no. 465, + pp. 156-168, March 2004. +*) + +(* :Example: +(* +This is the now classic nonlinear example. +The functions are compiled for speed. +The parameters are accessible via the functions. +*) + +Clear[signal, data, f, fCompiled, gp, gpCompiled, fp, fpCompiled, + swarmsize, prior, loglikelihood, states, collected, smoothed] + +signal = Rest @ FoldList[ + {.5#1[[1]] + 25#1[[1]]/(1 + #1[[1]]^2) + 8 Cos[1.2#1[[2]]] + #2, #1[[2]] + 1} &, + {RandomReal[NormalDistribution[0, Sqrt[10]]], 0}, + RandomReal[NormalDistribution[0, Sqrt[10]], 100]]; + +data = Partition[signal[[All, 1]]^2/20, 1] + + RandomReal[NormalDistribution[], 100]; + +f[x_, {a_, b_, c_, s2v_}] := + fCompiled[ + x[[All, 1]], + x[[1, 2]], + RandomReal[NormalDistribution[0, Sqrt[s2v]], Length[x]], + a, b, c + ] + +fCompiled = Compile[ + {{x, _Real, 1}, {t, _Real, 0}, {v, _Real, 1}, + {a, _Real, 0}, {b, _Real, 0}, {c, _Real, 0}}, + MapThread[{a #1 + b #1/(1 + #1^2) + c*Cos[1.2t] + #2, t + 1} &, + {x, v}]]; + +gp[x_, y_, {d_, s2w_}] := gpCompiled[x[[All, 1]], y[[1]], d, s2w] + +gpCompiled = Compile[ + {{x, _Real, 1}, {y, _Real, 0}, {d, _Real, 0}, {s2w, _Real, 0}}, + E^-((y - d*#1^2)^2/(2*s2w^2))/(Sqrt[2*Pi]*s2w) & /@ x + ]; + +fp[x1_, x0_, {a_, b_, c_, s2v_}] := + fpCompiled[x1[[1]], x0[[All, 1]], x0[[1, 2]], a, b, c, s2v] + +fpCompiled = Compile[ + {{x1, _Real, 0}, {x0, _Real, 1}, {t, _Real, 0}, + {a, _Real, 0}, {b, _Real, 0}, {c, _Real, 0}, {s2v, _Real, 0}}, + 1/(E^((x1 - c*Cos[1.2*t] - a*#1 - (b*#1)/(1 + #1^2))^2/(2*s2v^2))*s2v) & /@ x0 + ]; + +swarmsize = 10^4; +prior = Thread[{RandomReal[NormalDistribution[0, Sqrt[10]], swarmsize], 0}]; + +{loglikelihood, states} = + ParticleFilter[data, prior, f[#, {.5, 25, 8, 10}]&, gp[##, {.05, 1}]&, + IncludeStates -> True]; + +collected = CollectStates[states]; + +smoothed = ParticleSmoother[collected, fp[##, {.5, 25, 8, 10}] &, 10]; + +*) + +BeginPackage["ParticleFilter`"] + +ParticleFilter::usage = "ParticleFilter[data, x0, f, gp] takes a list of \ +data vectors, a list of state vectors x0 that represent the prior \ +information (the particle swarm), a transition function f that takes the \ +list state vectors as an argument and returns the list of predictions for \ +the new state vectors, and a function gp that takes two arguments, the list \ +of state vectors and the current a single data point, that returns \ +likelihood of the data given the state from the measurement equation. \ +ParticleFilter returns the log of the marginal likelihood of the (implicit) \ +parameters. By setting the option IncludeStates -> True, ParticleFilter \ +also returns the list of states, suitable as input to ParticleSmoother. \ +ParticleFilter also takes the option MCMCSmooth." + +IncludeStates::usage = "IncludeStates is an option for ParticleFilter, \ +which specifies whether to include the filtered particle swarms in \ +the output. The default setting is IncludeStates -> False." + +ParticleSmoother::usage = "ParticleSmoother[states, fp, n] takes the list \ +of states produced by ParticleFilter and a function fp that takes two \ +arguments (the first of which is a single current state vector and the \ +second of which is a list of previous state vectors) and returns a list of \ +likelihoods of the previous states given the value of the current state. \ +ParticleSmoother returns n paths from the joint smoothed distribution of \ +the state vectors." + +FilterStep::usage = "FilterStep[{x0, loglike0}, y, f, gp] is called by \ +ParticleFilter and returns {x1, loglike1}." + +SmootherStep::usage = "SmootherStep[x1, {x0, w0}, fp] is called by \ +ParticleSmoother. SmootherStep returns a list of previous states sampled \ +from x0 corresponding to the list of current states x1." + +Resample::usage = "Resample[{x, w}, n] returns a list of n samples drawn \ +with replacement from x with probabilities proportional to the nonnegative \ +weights w (made with SystematicResampling). Resample[{x, w}] returns a \ +single draw (made with BinarySerach). Resample is called by ParticleFilter \ +and ParticleSmoother." + +SystematicResampling::usage = "SystematicResampling[weights, n] returns a \ +list of n positions computed from the nonnegative weights according to \ +systematic resampling. SystematicResampling is called by FilterStep (within \ +ParticleFilter)." + +BinarySearch::usage = "BinarySearch[weights] returns a single position \ +computed from the nonnegative weights using binary search. BinarySearch is \ +called by SmootherStep (within ParticleSmoother)." + +CollectStates::usage = "CollectStates is an option for ParticleSmoother \ +that specifies whether to run the function CollectStates on the input. \ +CollectStates[states] take a list of states (as repreented by particle \ +swarms such as can be produced by ParticleFilter) and returns a list of the \ +union of the particles paired with their weights. The output is suitable as \ +input for ParticleSmoother." + +MCMCSmooth::usage = "MCMCSmooth is an option for ParticleFilter that \ +specifies whether to run the function MCMCSmooth at the end of FilterStep \ +after resampling. The default setting is MCMCSmooth -> False. \ +MCMCSmooth[{x1, w}, y, x0, f, gp] compares the likelihood each element of \ +x1 with a draw from f[x0] and replaces it with the draw according to the \ +ususal Metropolis criterion. The purpose is to obtain more distinct values \ +while maintaining the same distribution." + +PriorToPosterior::usage = "PriorToPosterior[prior, likelihood] takes a list \ +of points that represent a prior distribution and a likelihood function and \ +returns a list of points that represents the posterior distribution." + +Begin["`Private`"] + +PriorToPosterior[prior_, Lfun_] := + prior[[ SystematicResampling[Lfun /@ prior, Length[prior]] ]] + +(***** filtering *****) + +Options[ParticleFilter] = {IncludeStates -> False, MCMCSmooth -> False} + +ParticleFilter[data_, x0_, f_, gp_, opts___?OptionQ] := + If[TrueQ[IncludeStates /. {opts} /. Options[ParticleFilter]], + (* then *) + {#[[-1, -1]], #[[All, 1]]}& @ + Rest[FoldList[FilterStep[##, f, gp, opts]&, {x0, 0}, data]], + (* else *) + Fold[FilterStep[##, f, gp, opts]&, {x0, 0}, data][[2]] + ] + +FilterStep[{x0_, loglike_}, y_, f_, gp_, opts___] := + Module[{x1, w, pos}, + x1 = f[x0]; + w = gp[x1, y]; + pos = SystematicResampling[w, Length[w]]; + {If[TrueQ[MCMCSmooth /. {opts} /. Options[ParticleFilter]], + (* then *) +(* MCMCSmooth[{x1[[ pos ]], w[[ pos ]]}, y, x0, f, gp], *) + MCMCChoose[x1[[ pos ]], w[[ pos ]], x1, w], + (* else *) + x1[[ pos ]] + ], + Log[Mean[w]] + loglike} + ] + +(* streamlined version *) +Clear[ParticleFilter, FilterStep] + +Options[ParticleFilter] = {IncludeStates -> False} + +ParticleFilter[data_, x0_, f_, gp_, opts___?OptionQ] := + If[TrueQ[IncludeStates /. {opts} /. Options[ParticleFilter]], + (* then *) + {#[[-1, 1, 1]], #[[All, 2;;]]}& @ + Rest[FoldList[FilterStep[##, f, gp]&, + Prepend[x0, Table[0,{Dimensions[x0][[2]]}]], data]], + (* else *) + Fold[FilterStep[##, f, gp]&, + Prepend[x0, Table[0,{Dimensions[x0][[2]]}]], data][[1, 1]] + ] + +FilterStep[x0loglike_, y_, f_, gp_] := + Module[{x1, w}, + x1 = f[Rest[x0loglike]]; + w = gp[x1, y]; + Prepend[ + RandomChoice[w -> x1, Length[x1]], + Log[Mean[w]] + First[x0loglike] + ] + ] + +(* c[[i]] is the number of children of the i-th parent + p[[j]] is the position of the parent of the j-th child + w is the list of nonnegative weights (need not be normalized) + M is the desired number of children + *) +SystematicResampling = Compile[{{w, _Real, 1}, {M, _Integer, 0}}, + Module[{ + c = (Rest[#] - Most[#])& @ + Floor[FoldList[Plus, 0, M * w/(Plus@@w)] - RandomReal[]], + p = Table[0, {M}], + j = 1}, + Do[ + Do[p[[j]] = i; j++, {c[[i]]}], + {i, Length[w]}]; + p + ]] + +(* use {x1[[ pos ]], w[[ pos ]]} as first argument, + where pos = SystematicResampling[w, Length[w]] *) +MCMCSmooth[{x1_, w_}, y_, x0_, f_, gp_] := + With[{proposal = f[x0]}, + MCMCChoose[x1, w, proposal, gp[proposal, y]] + ] + +MCMCChoose = Compile[ + {{x1, _Real, 2}, {w, _Real, 1}, {xp, _Real, 2}, {wp, _Real, 1}}, + With[{alpha = + If[# >= 0, 1, 0] & /@ (wp - w * RandomReal[1, Length[w]])}, + alpha * xp + (1 - alpha) * x1 + ]] + +(***** smoothing *****) + +Options[ParticleSmoother] = {CollectStates -> False} + +ParticleSmoother[states_, fp_, n_Integer:1, opts___?OptionQ] := + Module[{ + collected = Reverse @ + If[TrueQ[CollectStates /. {opts} /. Options[ParticleSmoother]], + (* then *) + CollectStates[states], + (* else *) + states], + result}, + result = Transpose @ Reverse @ + FoldList[ + SmootherStep[##, fp]&, + Resample[First[collected], n], + Rest[collected] + ]; + If[n == 1, result[[1]], result] + ] + +SmootherStep[x1_, {x0_, w0_}, fp_] := + x0[[ BinarySearch[w0 * fp[#, x0]] ]]& /@ x1 + +SmootherStep[x1_, {x0_, w0_}, fp_] := + RandomChoice[(w0 * fp[#, x0]) -> x0]& /@ x1 + + +CollectStates[states_] := + Transpose[{First[#], Length[#]}& /@ Split[Sort[#]]]& /@ states + +Resample[{x_, w_}] := RandomChoice[w -> x] + +Resample[{x_, w_}, n_] := RandomChoice[w -> x, n] + +End[] +EndPackage[] diff --git a/MathematicaFiles/Applications/ParticleFilter.old b/MathematicaFiles/Applications/ParticleFilter.old new file mode 100755 index 0000000..4088351 --- /dev/null +++ b/MathematicaFiles/Applications/ParticleFilter.old @@ -0,0 +1,280 @@ +(* :Title: Particle Filter *) + +(* :Author: Mark Fisher *) + +(* :Context: ParticleFilter` *) + +(* :Mathematica Version: 6.0 *) + +(* :History: + Version 0.0 April 2005 + Version 0.1 May 2007 update for Version 6. + Use built-in RandomChoice (in addition to changing + Random and RandomArray to RandomReal) +*) + +(* :Summary: + SIR (Sampling Importance Resampling) particle filter and + backward simulation particle smoother +*) + +(* :Discussion: + This package implements ParticleFilter (an SIR particle filter) + and ParticleSmoother (a backward simulation particle smoother that + takes the output from ParticleFilter as input). In particular, given + {loglikelihood, states} = + ParticleFilter[data, {x0, w0}, f, gp, IncludeStates -> True]; + the marginal loglikelihood of the parameters (implicit in f and gp) is + given by loglikelihood. To compute n draws of paths from the smoothed + distribution, use + collected = CollectStates[states]; + smoothed = ParticleSmoother[collected, fp, n]; + +*) + +(* :References: + Doucet, de Freitas, and Gordon (editors), + "Sequenctial Monte Carlo Methods in Practice", + Springer, 2001. + + Arulampalam, Maskell, Gordon, and Clapp, + "A tutorial on particle filters for online nonlinear/non-Gaussian + Bayesian tracking", + IEEE Transactions on Signal Processing, vol. 50, no. 2, February 2002. + + Godsill, Doucet, and West, + "Monte Carlo smoothing for nonlinear time series", + Journal of the American Statistical Association, vol. 99, no. 465, + pp. 156-168, March 2004. +*) + +(* :Example: +(* +This is the now classic nonlinear example. +The functions are compiled for speed. +The parameters are accessible via the functions. +*) + +Clear[signal, data, f, fCompiled, gp, gpCompiled, fp, fpCompiled, + swarmsize, prior, loglikelihood, states, collected, smoothed] + +signal = Rest @ FoldList[ + {.5#1[[1]] + 25#1[[1]]/(1 + #1[[1]]^2) + 8 Cos[1.2#1[[2]]] + #2, #1[[2]] + 1} &, + {RandomReal[NormalDistribution[0, Sqrt[10]]], 0}, + RandomReal[NormalDistribution[0, Sqrt[10]], 100]]; + +data = Partition[signal[[All, 1]]^2/20, 1] + + RandomReal[NormalDistribution[], 100]; + +f[x_, {a_, b_, c_, s2v_}] := + fCompiled[ + x[[All, 1]], + x[[1, 2]], + RandomReal[NormalDistribution[0, Sqrt[s2v]], Length[x]], + a, b, c + ] + +fCompiled = Compile[ + {{x, _Real, 1}, {t, _Real, 0}, {v, _Real, 1}, + {a, _Real, 0}, {b, _Real, 0}, {c, _Real, 0}}, + MapThread[{a #1 + b #1/(1 + #1^2) + c*Cos[1.2t] + #2, t + 1} &, + {x, v}]]; + +gp[x_, y_, {d_, s2w_}] := gpCompiled[x[[All, 1]], y[[1]], d, s2w] + +gpCompiled = Compile[ + {{x, _Real, 1}, {y, _Real, 0}, {d, _Real, 0}, {s2w, _Real, 0}}, + E^-((y - d*#1^2)^2/(2*s2w^2))/(Sqrt[2*Pi]*s2w) & /@ x + ]; + +fp[x1_, x0_, {a_, b_, c_, s2v_}] := + fpCompiled[x1[[1]], x0[[All, 1]], x0[[1, 2]], a, b, c, s2v] + +fpCompiled = Compile[ + {{x1, _Real, 0}, {x0, _Real, 1}, {t, _Real, 0}, + {a, _Real, 0}, {b, _Real, 0}, {c, _Real, 0}, {s2v, _Real, 0}}, + 1/(E^((x1 - c*Cos[1.2*t] - a*#1 - (b*#1)/(1 + #1^2))^2/(2*s2v^2))*s2v) & /@ x0 + ]; + +swarmsize = 10^4; +prior = Thread[{RandomReal[NormalDistribution[0, Sqrt[10]], swarmsize], 0}]; + +{loglikelihood, states} = + ParticleFilter[data, prior, f[#, {.5, 25, 8, 10}]&, gp[##, {.05, 1}]&, + IncludeStates -> True]; + +collected = CollectStates[states]; + +smoothed = ParticleSmoother[collected, fp[##, {.5, 25, 8, 10}] &, 10]; + +*) + +BeginPackage["ParticleFilter`"] + +ParticleFilter::usage = "ParticleFilter[data, x0, f, gp] takes a list of +data vectors, a list of state vectors x0 that represent the prior +information (the particle swarm), a transition function f that takes the +list state vectors as an argument and returns the list of predictions for +the new state vectors, and a function gp that takes two arguments, the list +of state vectors and the current a single data point, that returns +likelihood of the data given the state from the measurement equation. +ParticleFilter returns the log of the marginal likelihood of the (implicit) +parameters. By setting the option IncludeStates -> True, ParticleFilter +also returns the list of states, suitable as input to ParticleSmoother. +ParticleFilter also takes the option MCMCSmooth." + +IncludeStates::usage = "IncludeStates is an option for ParticleFilter, +which specifies whether to include the filtered particle swarms in +the output. The default setting is IncludeStates -> False." + +ParticleSmoother::usage = "ParticleSmoother[states, fp, n] takes the list +of states produced by ParticleFilter and a function fp that takes two +arguments (the first of which is a single current state vector and the +second of which is a list of previous state vectors) and returns a list of +likelihoods of the previous states given the value of the current state. +ParticleSmoother returns n paths from the joint smoothed distribution of +the state vectors." + +FilterStep::usage = "FilterStep[{x0, loglike0}, y, f, gp] is called by +ParticleFilter and returns {x1, loglike1}." + +SmootherStep::usage = "SmootherStep[x1, {x0, w0}, fp] is called by +ParticleSmoother. SmootherStep returns a list of previous states sampled +from x0 corresponding to the list of current states x1." + +Resample::usage = "Resample[{x, w}, n] returns a list of n samples drawn +with replacement from x with probabilities proportional to the nonnegative +weights w (made with SystematicResampling). Resample[{x, w}] returns a +single draw (made with BinarySerach). Resample is called by ParticleFilter +and ParticleSmoother." + +SystematicResampling::usage = "SystematicResampling[weights, n] returns a +list of n positions computed from the nonnegative weights according to +systematic resampling. SystematicResampling is called by FilterStep (within +ParticleFilter)." + +BinarySearch::usage = "BinarySearch[weights] returns a single position +computed from the nonnegative weights using binary search. BinarySearch is +called by SmootherStep (within ParticleSmoother)." + +CollectStates::usage = "CollectStates is an option for ParticleSmoother +that specifies whether to run the function CollectStates on the input. +CollectStates[states] take a list of states (as repreented by particle +swarms such as can be produced by ParticleFilter) and returns a list of the +union of the particles paired with their weights. The output is suitable as +input for ParticleSmoother." + +MCMCSmooth::usage = "MCMCSmooth is an option for ParticleFilter that +specifies whether to run the function MCMCSmooth at the end of FilterStep +after resampling. The default setting is MCMCSmooth -> False. +MCMCSmooth[{x1, w}, y, x0, f, gp] compares the likelihood each element of +x1 with a draw from f[x0] and replaces it with the draw according to the +ususal Metropolis criterion. The purpose is to obtain more distinct values +while maintaining the same distribution." + +PriorToPosterior::usage = "PriorToPosterior[prior, likelihood] takes a list +of points that represent a prior distribution and a likelihood function and +returns a list of points that represents the posterior distribution." + +Begin["`Private`"] + +PriorToPosterior[prior_, Lfun_] := + prior[[ SystematicResampling[Lfun /@ prior, Length[prior]] ]] + +(***** filtering *****) + +Options[ParticleFilter] = {IncludeStates -> False, MCMCSmooth -> False} + +ParticleFilter[data_, x0_, f_, gp_, opts___?OptionQ] := + If[TrueQ[IncludeStates /. {opts} /. Options[ParticleFilter]], + (* then *) + {#[[-1, -1]], #[[All, 1]]}& @ + Rest[FoldList[FilterStep[##, f, gp, opts]&, {x0, 0}, data]], + (* else *) + Fold[FilterStep[##, f, gp, opts]&, {x0, 0}, data][[2]] + ] + +FilterStep[{x0_, loglike_}, y_, f_, gp_, opts___] := + Module[{x1, w, pos}, + x1 = f[x0]; + w = gp[x1, y]; + pos = SystematicResampling[w, Length[w]]; + {If[TrueQ[MCMCSmooth /. {opts} /. Options[ParticleFilter]], + (* then *) +(* MCMCSmooth[{x1[[ pos ]], w[[ pos ]]}, y, x0, f, gp], *) + MCMCChoose[x1[[ pos ]], w[[ pos ]], x1, w], + (* else *) + x1[[ pos ]] + ], + Log[Mean[w]] + loglike} + ] + +(* c[[i]] is the number of children of the i-th parent + p[[j]] is the position of the parent of the j-th child + w is the list of nonnegative weights (need not be normalized) + M is the desired number of children + *) +SystematicResampling = Compile[{{w, _Real, 1}, {M, _Integer, 0}}, + Module[{ + c = (Rest[#] - Most[#])& @ + Floor[FoldList[Plus, 0, M * w/(Plus@@w)] - Random[]], + p = Table[0, {M}], + j = 1}, + Do[ + Do[p[[j]] = i; j++, {c[[i]]}], + {i, Length[w]}]; + p + ]] + +(* use {x1[[ pos ]], w[[ pos ]]} as first argument, + where pos = SystematicResampling[w, Length[w]] *) +MCMCSmooth[{x1_, w_}, y_, x0_, f_, gp_] := + With[{proposal = f[x0]}, + MCMCChoose[x1, w, proposal, gp[proposal, y]] + ] + +MCMCChoose = Compile[ + {{x1, _Real, 2}, {w, _Real, 1}, {xp, _Real, 2}, {wp, _Real, 1}}, + With[{alpha = + If[# >= 0, 1, 0] & /@ (wp - w * RandomReal[{0,1} Length[w]])}, + alpha * xp + (1 - alpha) * x1 + ]] + +(***** smoothing *****) + +Options[ParticleSmoother] = {CollectStates -> False} + +ParticleSmoother[states_, fp_, n_Integer:1, opts___?OptionQ] := + Module[{ + collected = Reverse @ + If[TrueQ[CollectStates /. {opts} /. Options[ParticleSmoother]], + (* then *) + CollectStates[states], + (* else *) + states], + result}, + result = Transpose @ Reverse @ + FoldList[ + SmootherStep[##, fp]&, + Resample[First[collected], n], + Rest[collected] + ]; + If[n == 1, result[[1]], result] + ] + +SmootherStep[x1_, {x0_, w0_}, fp_] := + x0[[ BinarySearch[w0 * fp[#, x0]] ]]& /@ x1 + +SmootherStep[x1_, {x0_, w0_}, fp_] := + RandomChoice[(w0 * fp[#, x0]) -> x0]& /@ x1 + + +CollectStates[states_] := + Transpose[{First[#], Length[#]}& /@ Split[Sort[#]]]& /@ states + +Resample[{x_, w_}] := RandomChoice[w -> x] + +Resample[{x_, w_}, n_] := RandomChoice[w -> x, n] + +End[] +EndPackage[] diff --git a/MathematicaFiles/Applications/PenalizedSmooth.m b/MathematicaFiles/Applications/PenalizedSmooth.m new file mode 100755 index 0000000..cf02319 --- /dev/null +++ b/MathematicaFiles/Applications/PenalizedSmooth.m @@ -0,0 +1,76 @@ +(* penalized smoothing spline *) + +(* Get[myWorkingDrive <> "/mma_applications/FRB/BSplineBasis3.m"] *) + +Needs["FRB`BSplineBasis`"] + +PenalizedSmooth::usage = "PenalizedSmooth[data, ({\[Lambda]0,\[Lambda]1})] returns a +penalized smoothing spline (as an InterpolationFunction). The data must be a +list of {x,y} pairs with no duplicate x values. The cubic spline has a knot +point at each x value; the weight on the penalty function (the integrated +squared second derivative) is determined via generalized cross validation. +The optional second argument specifies two starting values for the +minimization involved. The default values are {\[Lambda]0,\[Lambda]1}={.1,1}." + +PenalizedSmooth[data_] := PenalizedSmooth[data, {.1, 1}] + +PenalizedSmooth[data_, {lam0_, lam1_}] := + Module[{xvals, yvals, mat, pmat, minlam, fitted}, + xvals = data[[All, 1]]; + yvals = data[[All, 2]]; + mat = SplineMatrix[xvals, xvals, 3]; + pmat = PenaltyMatrix[xvals]; + minlam = Block[{lam}, + lam /. FindMinimum[GCV[lam, {mat, pmat}, yvals], {lam, lam0, lam1}][[2]]]; + fitted = Amatrix[minlam, {mat, pmat}] . + yvals; Interpolation[Transpose[{xvals, fitted}], InterpolationOrder -> 3] + ] + +Amatrix[lam_?NumericQ, {mat_, pmat_}] := + mat.Inverse[Transpose[mat].mat + lam * pmat].Transpose[mat] + +GCV[lam_?NumericQ, {mat_, pmat_}, yvals_] := + With[{A = Amatrix[lam, {mat, pmat}]}, + (#.#)&[yvals - A.yvals]/(1 - Tr[A]/Length[yvals])^2 + ] + +SmoothingSpline3D::usage = "SmoothingSpline3D[data, n] returns an \ +InterpolatingFunction that represents a cubic smoothing spline surface \ +given the data, a list of 3D points, and the nonnegative integer n, the \ +number of (internal) knot points. The number of knot points can be given \ +as {nx, ny} or as two explicit lists of points." + +SmoothingSpline3D[data_, n_Integer] := SmoothingSpline3D[data, {n, n}] + +SmoothingSpline3D[data_, {nx_Integer, ny_Integer}] := + Module[{}, + minx = Min[data[[All, 1]]]; + maxx = Max[data[[All, 1]]]; + miny = Min[data[[All, 2]]]; + maxy = Max[data[[All, 2]]]; + xknots = Range[minx, maxx, (maxx-minx)/(nx+1)]; + yknots = Range[miny, maxy, (maxy-miny)/(ny+1)]; + SmoothingSpline3D[data, xknots, yknots] + ] + +SmoothingSpline3D[ + data_?(MatrixQ[#, NumericQ]&), + xknots_?(VectorQ[#, NumericQ]&), + yknots_?(VectorQ[#, NumericQ]&) + ] /; Dimensions[data][[2]] == 3 := + Module[{splines, fun, mat, coeffs, x, y}, + splines = Flatten[Outer[Times, + Through[MakeBSplineBasis[xknots, 3][x]], + Through[MakeBSplineBasis[yknots, 3][y]] + ]]; + fun = Function @@ {{x, y}, splines}; + mat = Chop[fun @@@ data[[All, {1, 2}]]]; + coeffs = Inverse[Transpose[mat].mat].Transpose[mat].data[[All, 3]]; + fun = Function @@ {{x, y}, splines.coeffs}; + FunctionInterpolation[ + fun[x, y], + {x, xknots[[1]], xknots[[-1]]}, + {y, yknots[[1]], yknots[[-1]]}, + InterpolationPoints -> Ceiling[(5/2) (Length[xknots] + Length[yknots])]] + ] + diff --git a/MathematicaFiles/Applications/PlotEnhancements.m b/MathematicaFiles/Applications/PlotEnhancements.m new file mode 100755 index 0000000..0bf376d --- /dev/null +++ b/MathematicaFiles/Applications/PlotEnhancements.m @@ -0,0 +1,23 @@ +ListLineDotPlot::usage = "ListLineDotPlot[list] produces a \ +ListLinePlot with lines nears the data points." + +Options[ListLineDotPlot] = { + DotMaskStyle -> {White, PointSize[0.025]}, + DotStyle -> Automatic, + LineStyle -> Automatic + } + +ListLineDotPlot[list_List, opts___OptionQ] := + Module[{maskstyle, linestyle, dotstyle, gropts}, + {maskstyle, linestyle, dotstyle} = + {DotMaskStyle, LineStyle, DotStyle} /. {opts} /. Options[ListLineDotPlot]; + gropts = FilterOptions[Graphics, opts]; + Show[ + ListLinePlot[list, Mesh -> All, MeshStyle -> maskstyle, PlotStyle -> linestyle], + ListPlot[list, Joined -> False, PlotStyle -> dotstyle], + gropts + ] + ] + +GetPlotRange[g_, opts___?OptionQ] := + AbsoluteOptions[Show[g, opts, PlotRange -> All], PlotRange][[1]] diff --git a/MathematicaFiles/Applications/RandomNumberGenerators.nb b/MathematicaFiles/Applications/RandomNumberGenerators.nb new file mode 100755 index 0000000..482e640 --- /dev/null +++ b/MathematicaFiles/Applications/RandomNumberGenerators.nb @@ -0,0 +1,1004 @@ +(* Content-type: application/mathematica *) + +(*** Wolfram Notebook File ***) +(* http://www.wolfram.com/nb *) + +(* CreatedBy='Mathematica 6.0' *) + +(*CacheID: 234*) +(* Internal cache information: +NotebookFileLineBreakTest +NotebookFileLineBreakTest +NotebookDataPosition[ 145, 7] +NotebookDataLength[ 38665, 995] +NotebookOptionsPosition[ 35725, 891] +NotebookOutlinePosition[ 36087, 907] +CellTagsIndexPosition[ 36044, 904] +WindowFrame->Normal +ContainsDynamic->False*) + +(* Beginning of Notebook Content *) +Notebook[{ +Cell["Example from tutorial/RandomNumberGeneration", "Text", + CellChangeTimes->{{3.3886625868125*^9, 3.388662605953125*^9}}], + +Cell[BoxData[ + RowBox[{ + RowBox[{ + RowBox[{"Options", "[", "MultiplicativeCongruential", "]"}], " ", "=", " ", + + RowBox[{"{", + RowBox[{ + RowBox[{"\"\<Multiplier\>\"", "\[Rule]", "123456789"}], ",", " ", + RowBox[{"\"\<Modulus\>\"", "\[Rule]", + RowBox[{ + RowBox[{"2", "^", "35"}], "-", "1"}]}]}], "}"}]}], ";"}]], "Input", + CellID->207931436], + +Cell[BoxData[ + RowBox[{ + RowBox[{"MultiplicativeCongruential", " ", "/:", " ", + RowBox[{"Random`InitializeGenerator", "[", + RowBox[{"MultiplicativeCongruential", ",", " ", "opts___"}], "]"}], " ", ":=", + " ", + RowBox[{"Module", "[", + RowBox[{ + RowBox[{"{", + RowBox[{"mult", ",", " ", "mod", ",", " ", + RowBox[{"flops", " ", "=", " ", + RowBox[{"Flatten", "[", + RowBox[{"{", + RowBox[{"opts", ",", " ", + RowBox[{"Options", "[", "MultiplicativeCongruential", "]"}]}], + "}"}], "]"}]}]}], "}"}], ",", "\[IndentingNewLine]", + RowBox[{ + RowBox[{"mult", " ", "=", " ", + RowBox[{"\"\<Multiplier\>\"", " ", "/.", " ", "flops"}]}], ";", + "\[IndentingNewLine]", + RowBox[{"If", "[", + RowBox[{ + RowBox[{"!", + RowBox[{"(", + RowBox[{ + RowBox[{"IntegerQ", "[", "mult", "]"}], "&&", + RowBox[{"Positive", "[", "mult", "]"}]}], ")"}]}], ",", + "\[IndentingNewLine]", + RowBox[{"Throw", "[", "$Failed", "]"}]}], "\[IndentingNewLine]", + "]"}], ";", "\[IndentingNewLine]", + RowBox[{"mod", " ", "=", " ", + RowBox[{"\"\<Modulus\>\"", " ", "/.", " ", "flops"}]}], ";", + "\[IndentingNewLine]", + RowBox[{"If", "[", + RowBox[{ + RowBox[{"!", + RowBox[{"(", + RowBox[{ + RowBox[{"IntegerQ", "[", "mod", "]"}], "&&", + RowBox[{"Positive", "[", "mult", "]"}]}], ")"}]}], ",", + "\[IndentingNewLine]", + RowBox[{"Throw", "[", "$Failed", "]"}]}], "\[IndentingNewLine]", + "]"}], ";", "\[IndentingNewLine]", + RowBox[{"MultiplicativeCongruential", "[", + RowBox[{"mult", ",", " ", "mod", ",", "1"}], "]"}]}]}], "]"}]}], + ";"}]], "Input", + CellID->15261556], + +Cell[BoxData[ + RowBox[{ + RowBox[{ + RowBox[{ + RowBox[{"MultiplicativeCongruential", "[", "___", "]"}], "[", + "\"\<GeneratesRealsQ\>\"", "]"}], " ", ":=", " ", "True"}], + ";"}]], "Input", + CellID->413732366], + +Cell[BoxData[ + RowBox[{ + RowBox[{ + RowBox[{ + RowBox[{"MultiplicativeCongruential", "[", + RowBox[{"mult_", ",", "mod_", ",", " ", "___"}], "]"}], "[", + RowBox[{"\"\<SeedGenerator\>\"", "[", "seed_", "]"}], "]"}], " ", ":=", + " ", "\[IndentingNewLine]", + RowBox[{"MultiplicativeCongruential", "[", + RowBox[{"mult", ",", "mod", ",", " ", + RowBox[{"Mod", "[", + RowBox[{ + RowBox[{"(", + RowBox[{"mult", "*", "seed"}], ")"}], ",", "mod"}], "]"}]}], "]"}]}], + ";"}]], "Input", + CellID->7906412], + +Cell[BoxData[ + RowBox[{ + RowBox[{ + RowBox[{"MultiplicativeCongruential", "[", + RowBox[{"mult_", ",", "mod_", ",", " ", "s_"}], "]"}], "[", + RowBox[{"\"\<GenerateReals\>\"", "[", + RowBox[{"n_", ",", + RowBox[{"{", + RowBox[{"a_", ",", "b_"}], "}"}], ",", "prec_"}], "]"}], "]"}], " ", ":=", + " ", "\[IndentingNewLine]", + RowBox[{"Module", "[", + RowBox[{ + RowBox[{"{", + RowBox[{"x", "=", "s"}], "}"}], ",", "\[IndentingNewLine]", + RowBox[{"{", + RowBox[{ + RowBox[{"a", "+", + RowBox[{ + RowBox[{"(", + RowBox[{"b", "-", "a"}], ")"}], + RowBox[{ + RowBox[{"Table", "[", + RowBox[{ + RowBox[{ + RowBox[{"x", "=", + RowBox[{"mult", "*", "x"}]}], ";", + RowBox[{"Mod", "[", + RowBox[{"x", ",", "mod"}], "]"}]}], ",", + RowBox[{"{", "n", "}"}]}], "]"}], "/", "mod"}]}]}], ",", + RowBox[{"MultiplicativeCongruential", "[", + RowBox[{"mult", ",", "mod", ",", " ", "x"}], "]"}]}], "}"}]}], + "\[IndentingNewLine]", "]"}]}]], "Input", + CellID->216655639], + +Cell[BoxData[ + RowBox[{"SeedRandom", "[", + RowBox[{"Method", "->", "MultiplicativeCongruential"}], "]"}]], "Input", + CellChangeTimes->{{3.388662637984375*^9, 3.388662708765625*^9}}], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{"Table", "[", + RowBox[{ + RowBox[{"RandomReal", "[", "]"}], ",", + RowBox[{"{", + SuperscriptBox["10", "2"], "}"}]}], "]"}]], "Input", + CellChangeTimes->{{3.388735209545604*^9, 3.3887352112330394`*^9}, { + 3.3887353042294683`*^9, 3.388735349180867*^9}}], + +Cell[BoxData[ + RowBox[{"{", + RowBox[{ + "0.03125000000727596`", ",", "7.629394533026357`*^-6", ",", + "1.862645149230957`*^-9", ",", "0.0019531250004547474`", ",", + "4.76837158203125`*^-7", ",", "0.5000000001164153`", ",", + "0.0001220703125284217`", ",", "2.9802322387695312`*^-8", ",", + "0.03125000000727596`", ",", "7.629394533026357`*^-6", ",", + "1.862645149230957`*^-9", ",", "0.0019531250004547474`", ",", + "4.76837158203125`*^-7", ",", "0.5000000001164153`", ",", + "0.0001220703125284217`", ",", "2.9802322387695312`*^-8", ",", + "0.03125000000727596`", ",", "7.629394533026357`*^-6", ",", + "1.862645149230957`*^-9", ",", "0.0019531250004547474`", ",", + "4.76837158203125`*^-7", ",", "0.5000000001164153`", ",", + "0.0001220703125284217`", ",", "2.9802322387695312`*^-8", ",", + "0.03125000000727596`", ",", "7.629394533026357`*^-6", ",", + "1.862645149230957`*^-9", ",", "0.0019531250004547474`", ",", + "4.76837158203125`*^-7", ",", "0.5000000001164153`", ",", + "0.0001220703125284217`", ",", "2.9802322387695312`*^-8", ",", + "0.03125000000727596`", ",", "7.629394533026357`*^-6", ",", + "1.862645149230957`*^-9", ",", "0.0019531250004547474`", ",", + "4.76837158203125`*^-7", ",", "0.5000000001164153`", ",", + "0.0001220703125284217`", ",", "2.9802322387695312`*^-8", ",", + "0.03125000000727596`", ",", "7.629394533026357`*^-6", ",", + "1.862645149230957`*^-9", ",", "0.0019531250004547474`", ",", + "4.76837158203125`*^-7", ",", "0.5000000001164153`", ",", + "0.0001220703125284217`", ",", "2.9802322387695312`*^-8", ",", + "0.03125000000727596`", ",", "7.629394533026357`*^-6", ",", + "1.862645149230957`*^-9", ",", "0.0019531250004547474`", ",", + "4.76837158203125`*^-7", ",", "0.5000000001164153`", ",", + "0.0001220703125284217`", ",", "2.9802322387695312`*^-8", ",", + "0.03125000000727596`", ",", "7.629394533026357`*^-6", ",", + "1.862645149230957`*^-9", ",", "0.0019531250004547474`", ",", + "4.76837158203125`*^-7", ",", "0.5000000001164153`", ",", + "0.0001220703125284217`", ",", "2.9802322387695312`*^-8", ",", + "0.03125000000727596`", ",", "7.629394533026357`*^-6", ",", + "1.862645149230957`*^-9", ",", "0.0019531250004547474`", ",", + "4.76837158203125`*^-7", ",", "0.5000000001164153`", ",", + "0.0001220703125284217`", ",", "2.9802322387695312`*^-8", ",", + "0.03125000000727596`", ",", "7.629394533026357`*^-6", ",", + "1.862645149230957`*^-9", ",", "0.0019531250004547474`", ",", + "4.76837158203125`*^-7", ",", "0.5000000001164153`", ",", + "0.0001220703125284217`", ",", "2.9802322387695312`*^-8", ",", + "0.03125000000727596`", ",", "7.629394533026357`*^-6", ",", + "1.862645149230957`*^-9", ",", "0.0019531250004547474`", ",", + "4.76837158203125`*^-7", ",", "0.5000000001164153`", ",", + "0.0001220703125284217`", ",", "2.9802322387695312`*^-8", ",", + "0.03125000000727596`", ",", "7.629394533026357`*^-6", ",", + "1.862645149230957`*^-9", ",", "0.0019531250004547474`", ",", + "4.76837158203125`*^-7", ",", "0.5000000001164153`", ",", + "0.0001220703125284217`", ",", "2.9802322387695312`*^-8", ",", + "0.03125000000727596`", ",", "7.629394533026357`*^-6", ",", + "1.862645149230957`*^-9", ",", "0.0019531250004547474`"}], "}"}]], "Output",\ + + CellChangeTimes->{ + 3.3887352114674053`*^9, {3.38873530508881*^9, 3.3887353493058624`*^9}}] +}, Open ]], + +Cell[CellGroupData[{ + +Cell["BasicRandom", "Section", + CellChangeTimes->{{3.3886627944375*^9, 3.388662801109375*^9}}], + +Cell["\<\ +Basic RNG Stephen K.Park and Keith W.Miller,\"Random Number Generators: Good \ +Ones Are Hard to Find,\" Communications of the ACM,31:10 \ +(October,1988),1192-1201.\ +\>", "Text", + CellChangeTimes->{{3.38866323003125*^9, 3.388663233296875*^9}}], + +Cell[CellGroupData[{ + +Cell["Code for Verion 5.2", "Subsection", + CellChangeTimes->{{3.388665796328125*^9, 3.388665800375*^9}}], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{ + RowBox[{ + SuperscriptBox["2", "31"], "-", "1"}], "==", "2147483647"}]], "Input", + CellChangeTimes->{{3.388663244546875*^9, 3.388663245828125*^9}}], + +Cell[BoxData["True"], "Output", + CellChangeTimes->{3.388663246546875*^9}] +}, Open ]], + +Cell[BoxData[{ + RowBox[{ + RowBox[{ + RowBox[{"BasicRandomSeed", "=", + RowBox[{"Mod", "[", + RowBox[{ + RowBox[{"Round", "[", + RowBox[{"AbsoluteTime", "[", "]"}], "]"}], ",", "2147483647"}], + "]"}]}], ";"}], "\n"}], "\[IndentingNewLine]", + RowBox[{ + RowBox[{ + RowBox[{"BasicRandomInteger", "[", "]"}], ":=", + RowBox[{"BasicRandomSeed", "=", + RowBox[{"Mod", "[", + RowBox[{ + RowBox[{"16807", "*", "BasicRandomSeed"}], ",", "2147483647"}], + "]"}]}]}], "\n"}], "\[IndentingNewLine]", + RowBox[{ + RowBox[{ + RowBox[{"BasicRandomInteger", "[", + RowBox[{"n_Integer", "?", "Positive"}], "]"}], ":=", + RowBox[{"Table", "[", + RowBox[{ + RowBox[{"BasicRandomInteger", "[", "]"}], ",", + RowBox[{"{", "n", "}"}]}], "]"}]}], "\n"}], "\[IndentingNewLine]", + RowBox[{ + RowBox[{ + RowBox[{"BasicRandomReal", "[", "]"}], ":=", + RowBox[{ + RowBox[{"BasicRandomInteger", "[", "]"}], "/", "2147483647."}]}], + "\n"}], "\[IndentingNewLine]", + RowBox[{ + RowBox[{"BasicRandomReal", "[", "n_Integer", "]"}], ":=", + RowBox[{ + RowBox[{"BasicRandomInteger", "[", "n", "]"}], "/", + "2147483647."}]}]}], "Input", + Evaluatable->False, + CellChangeTimes->{{3.38866320775*^9, 3.388663217015625*^9}}] +}, Open ]], + +Cell[CellGroupData[{ + +Cell["Setup for Version 6", "Subsection", + CellChangeTimes->{{3.388663631296875*^9, 3.388663632046875*^9}, { + 3.388665783859375*^9, 3.38866579034375*^9}}], + +Cell[BoxData[ + RowBox[{"Clear", "[", "BasicRandom", "]"}]], "Input", + CellChangeTimes->{{3.388663583921875*^9, 3.388663587328125*^9}, { + 3.388665510875*^9, 3.3886655134375*^9}}], + +Cell[BoxData[ + RowBox[{ + RowBox[{ + RowBox[{"BasicRandom", "[", "___", "]"}], "[", "\"\<GeneratesRealsQ\>\"", + "]"}], " ", ":=", " ", "True"}]], "Input", + CellChangeTimes->{{3.3886631375*^9, 3.388663138640625*^9}, + 3.388663175671875*^9, 3.388664005296875*^9, 3.388664360609375*^9, + 3.38866552575*^9}], + +Cell[BoxData[ + RowBox[{ + RowBox[{ + RowBox[{"BasicRandom", "[", "s_", "]"}], "[", + RowBox[{"\"\<GenerateReals\>\"", "[", + RowBox[{"n_", ",", + RowBox[{"{", + RowBox[{"a_", ",", "b_"}], "}"}], ",", "prec_"}], "]"}], "]"}], " ", ":=", + " ", "\[IndentingNewLine]", + RowBox[{"Module", "[", + RowBox[{ + RowBox[{"{", + RowBox[{"x", "=", "s"}], "}"}], ",", "\[IndentingNewLine]", + RowBox[{"{", + RowBox[{ + RowBox[{"a", "+", + RowBox[{ + RowBox[{"(", + RowBox[{"b", "-", "a"}], ")"}], + RowBox[{"(", + RowBox[{ + RowBox[{"Table", "[", + RowBox[{ + RowBox[{"x", "=", + RowBox[{"Mod", "[", + RowBox[{ + RowBox[{"16807", "*", "x"}], ",", "2147483647"}], "]"}]}], ",", + + RowBox[{"{", "n", "}"}]}], "]"}], "/", "2147483647"}], ")"}]}]}], + ",", + RowBox[{"BasicRandom", "[", "x", "]"}]}], "}"}]}], + "\[IndentingNewLine]", "]"}]}]], "Input", + CellChangeTimes->{{3.388663362234375*^9, 3.388663395734375*^9}, { + 3.3886635138125*^9, 3.388663520625*^9}, {3.38866401546875*^9, + 3.388664018625*^9}, {3.3886641531875*^9, 3.388664155859375*^9}, { + 3.388664201171875*^9, 3.388664201484375*^9}, {3.3886644155*^9, + 3.388664418796875*^9}, {3.3886655335*^9, 3.388665536109375*^9}}], + +Cell[BoxData[ + RowBox[{"BasicRandom", " ", "/:", " ", + RowBox[{"Random`InitializeGenerator", "[", + RowBox[{"BasicRandom", ",", "___"}], "]"}], " ", ":=", " ", + RowBox[{"BasicRandom", "[", + RowBox[{"Mod", "[", + RowBox[{ + RowBox[{"Round", "[", + RowBox[{"AbsoluteTime", "[", "]"}], "]"}], ",", "2147483647"}], "]"}], + "]"}]}]], "Input", + CellChangeTimes->{{3.388663082375*^9, 3.388663109234375*^9}, { + 3.388663144171875*^9, 3.38866314690625*^9}, {3.388663456953125*^9, + 3.388663471484375*^9}, {3.388663836765625*^9, 3.388663845390625*^9}, { + 3.3886639966875*^9, 3.3886639994375*^9}, {3.388664583109375*^9, + 3.388664583890625*^9}, {3.38866551728125*^9, 3.388665523140625*^9}}], + +Cell[BoxData[ + RowBox[{ + RowBox[{ + RowBox[{"BasicRandom", "[", "___", "]"}], "[", + RowBox[{"\"\<SeedGenerator\>\"", "[", "seed_", "]"}], "]"}], " ", ":=", + " ", "\[IndentingNewLine]", + RowBox[{"BasicRandom", "[", + RowBox[{"Mod", "[", + RowBox[{"seed", ",", "2147483647"}], "]"}], "]"}]}]], "Input", + CellChangeTimes->{ + 3.38866317365625*^9, {3.38866331184375*^9, 3.388663336734375*^9}, { + 3.388663401421875*^9, 3.388663439796875*^9}, {3.3886636635625*^9, + 3.388663669359375*^9}, {3.388664010296875*^9, 3.388664012859375*^9}, { + 3.38866552853125*^9, 3.388665530984375*^9}}] +}, Open ]], + +Cell[CellGroupData[{ + +Cell["Run in Version 6", "Subsection", + CellChangeTimes->{{3.38866881534375*^9, 3.38866881965625*^9}}], + +Cell[BoxData[ + RowBox[{"SeedRandom", "[", + RowBox[{"Method", "\[Rule]", "BasicRandom"}], "]"}]], "Input", + CellChangeTimes->{{3.388735263012301*^9, 3.3887352736368933`*^9}}], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{"Table", "[", + RowBox[{ + RowBox[{"RandomReal", "[", "]"}], ",", + RowBox[{"{", "100", "}"}]}], "]"}]], "Input", + CellChangeTimes->{{3.3887352750587134`*^9, 3.3887352843396072`*^9}, { + 3.3887353654614916`*^9, 3.3887353698519483`*^9}}], + +Cell[BoxData[ + RowBox[{"{", + RowBox[{ + "4.76837158203125`*^-7", ",", "0.5000000001164153`", ",", + "0.0001220703125284217`", ",", "2.9802322387695312`*^-8", ",", + "0.03125000000727596`", ",", "7.629394533026357`*^-6", ",", + "1.862645149230957`*^-9", ",", "0.0019531250004547474`", ",", + "4.76837158203125`*^-7", ",", "0.5000000001164153`", ",", + "0.0001220703125284217`", ",", "2.9802322387695312`*^-8", ",", + "0.03125000000727596`", ",", "7.629394533026357`*^-6", ",", + "1.862645149230957`*^-9", ",", "0.0019531250004547474`", ",", + "4.76837158203125`*^-7", ",", "0.5000000001164153`", ",", + "0.0001220703125284217`", ",", "2.9802322387695312`*^-8", ",", + "0.03125000000727596`", ",", "7.629394533026357`*^-6", ",", + "1.862645149230957`*^-9", ",", "0.0019531250004547474`", ",", + "4.76837158203125`*^-7", ",", "0.5000000001164153`", ",", + "0.0001220703125284217`", ",", "2.9802322387695312`*^-8", ",", + "0.03125000000727596`", ",", "7.629394533026357`*^-6", ",", + "1.862645149230957`*^-9", ",", "0.0019531250004547474`", ",", + "4.76837158203125`*^-7", ",", "0.5000000001164153`", ",", + "0.0001220703125284217`", ",", "2.9802322387695312`*^-8", ",", + "0.03125000000727596`", ",", "7.629394533026357`*^-6", ",", + "1.862645149230957`*^-9", ",", "0.0019531250004547474`", ",", + "4.76837158203125`*^-7", ",", "0.5000000001164153`", ",", + "0.0001220703125284217`", ",", "2.9802322387695312`*^-8", ",", + "0.03125000000727596`", ",", "7.629394533026357`*^-6", ",", + "1.862645149230957`*^-9", ",", "0.0019531250004547474`", ",", + "4.76837158203125`*^-7", ",", "0.5000000001164153`", ",", + "0.0001220703125284217`", ",", "2.9802322387695312`*^-8", ",", + "0.03125000000727596`", ",", "7.629394533026357`*^-6", ",", + "1.862645149230957`*^-9", ",", "0.0019531250004547474`", ",", + "4.76837158203125`*^-7", ",", "0.5000000001164153`", ",", + "0.0001220703125284217`", ",", "2.9802322387695312`*^-8", ",", + "0.03125000000727596`", ",", "7.629394533026357`*^-6", ",", + "1.862645149230957`*^-9", ",", "0.0019531250004547474`", ",", + "4.76837158203125`*^-7", ",", "0.5000000001164153`", ",", + "0.0001220703125284217`", ",", "2.9802322387695312`*^-8", ",", + "0.03125000000727596`", ",", "7.629394533026357`*^-6", ",", + "1.862645149230957`*^-9", ",", "0.0019531250004547474`", ",", + "4.76837158203125`*^-7", ",", "0.5000000001164153`", ",", + "0.0001220703125284217`", ",", "2.9802322387695312`*^-8", ",", + "0.03125000000727596`", ",", "7.629394533026357`*^-6", ",", + "1.862645149230957`*^-9", ",", "0.0019531250004547474`", ",", + "4.76837158203125`*^-7", ",", "0.5000000001164153`", ",", + "0.0001220703125284217`", ",", "2.9802322387695312`*^-8", ",", + "0.03125000000727596`", ",", "7.629394533026357`*^-6", ",", + "1.862645149230957`*^-9", ",", "0.0019531250004547474`", ",", + "4.76837158203125`*^-7", ",", "0.5000000001164153`", ",", + "0.0001220703125284217`", ",", "2.9802322387695312`*^-8", ",", + "0.03125000000727596`", ",", "7.629394533026357`*^-6", ",", + "1.862645149230957`*^-9", ",", "0.0019531250004547474`", ",", + "4.76837158203125`*^-7", ",", "0.5000000001164153`", ",", + "0.0001220703125284217`", ",", "2.9802322387695312`*^-8"}], + "}"}]], "Output", + CellChangeTimes->{{3.3887352780585985`*^9, 3.38873529102685*^9}, + 3.3887353702894316`*^9}] +}, Open ]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{"abstime", "=", + RowBox[{"Round", "[", + RowBox[{"AbsoluteTime", "[", "]"}], "]"}]}]], "Input", + CellChangeTimes->{{3.3886656094375*^9, 3.388665636*^9}}], + +Cell[BoxData["3388651236"], "Output", + CellChangeTimes->{{3.388665617046875*^9, 3.388665636421875*^9}}] +}, Open ]], + +Cell[BoxData[ + RowBox[{"SeedRandom", "[", + RowBox[{"abstime", ",", + RowBox[{"Method", "\[Rule]", "BasicRandom"}]}], "]"}]], "Input", + CellChangeTimes->{{3.388663485015625*^9, 3.38866349353125*^9}, + 3.38866402109375*^9, {3.3886644980625*^9, 3.388664501171875*^9}, { + 3.388664613625*^9, 3.38866461390625*^9}, {3.3886648165*^9, + 3.388664828046875*^9}, {3.388665548640625*^9, 3.388665549859375*^9}, { + 3.388665601296875*^9, 3.388665601546875*^9}, {3.388665639078125*^9, + 3.388665642*^9}}], + +Cell[BoxData[ + RowBox[{"SeedRandom", "[", + RowBox[{"Method", "\[Rule]", "\"\<MersenneTwister\>\""}], "]"}]], "Input", + CellChangeTimes->{{3.388665422265625*^9, 3.388665433234375*^9}}], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{"RandomReal", "[", "1", "]"}]], "Input", + CellChangeTimes->{{3.388664801984375*^9, 3.38866484571875*^9}, { + 3.388664970953125*^9, 3.388665010828125*^9}, 3.388665484484375*^9}], + +Cell[BoxData["0.8358643450009936`"], "Output", + CellChangeTimes->{{3.38866480390625*^9, 3.388664848875*^9}, { + 3.38866498315625*^9, 3.388665013421875*^9}, {3.388665435109375*^9, + 3.388665439328125*^9}, {3.388665477984375*^9, 3.38866548603125*^9}, + 3.388665552765625*^9, {3.388665589484375*^9, 3.3886656075625*^9}, + 3.388665644171875*^9, 3.388665922015625*^9}] +}, Open ]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{ + RowBox[{ + RowBox[{"RandomReal", "[", + RowBox[{ + RowBox[{"NormalDistribution", "[", "]"}], ",", + SuperscriptBox["10", "5"]}], "]"}], ";"}], "//", "Timing"}]], "Input", + CellChangeTimes->{{3.388664889890625*^9, 3.388664941921875*^9}, { + 3.38866544403125*^9, 3.38866544859375*^9}, {3.388665561828125*^9, + 3.388665565765625*^9}, {3.38866566871875*^9, 3.38866567646875*^9}, { + 3.388665924375*^9, 3.388665927625*^9}}], + +Cell[BoxData[ + RowBox[{"{", + RowBox[{"0.6559999999999997`", ",", "Null"}], "}"}]], "Output", + CellChangeTimes->{3.388665928578125*^9}] +}, Open ]] +}, Open ]] +}, Open ]], + +Cell[CellGroupData[{ + +Cell["Jerry Dwyer's portable RNG", "Section", + CellChangeTimes->{{3.38866575984375*^9, 3.388665763890625*^9}, { + 3.388665939515625*^9, 3.388665949359375*^9}}], + +Cell[CellGroupData[{ + +Cell["Code for Version 5.2", "Subsection", + CellChangeTimes->{{3.388665808265625*^9, 3.388665811953125*^9}}], + +Cell[BoxData[{ + RowBox[{ + RowBox[{ + RowBox[{"SeedPortableRNG", "[", "n_Integer", "]"}], ":=", + RowBox[{"(", + RowBox[{ + RowBox[{"$randomY", "=", "n"}], ";", "\[IndentingNewLine]", + RowBox[{"$randomZ", "=", + RowBox[{"Mod", "[", + RowBox[{ + RowBox[{"64155", "*", "$randomY"}], ",", "214783629"}], "]"}]}], + ";"}], ")"}]}], "\n"}], "\[IndentingNewLine]", + RowBox[{ + RowBox[{ + RowBox[{"SeedPortableRNG", "[", "]"}], ":=", + RowBox[{"SeedPortableRNG", "[", + RowBox[{"Random", "[", + RowBox[{"Integer", ",", + RowBox[{"{", + RowBox[{"1", ",", "214783629"}], "}"}]}], "]"}], "]"}]}], + "\[IndentingNewLine]", "\[IndentingNewLine]", + RowBox[{"(*", "initialize", "*)"}]}], "\n", + RowBox[{ + RowBox[{"SeedPortableRNG", "[", "]"}], "\n"}], "\[IndentingNewLine]", + RowBox[{ + RowBox[{ + RowBox[{"PortableRNGInteger", "[", "]"}], ":=", + RowBox[{"Mod", "[", + RowBox[{ + RowBox[{ + RowBox[{"(", + RowBox[{"$randomY", "=", + RowBox[{"Mod", "[", + RowBox[{ + RowBox[{"64155", "*", "$randomY"}], ",", "214783629"}], "]"}]}], + ")"}], "-", + RowBox[{"(", + RowBox[{"$randomZ", "=", + RowBox[{"Mod", "[", + RowBox[{ + RowBox[{"10064", "*", "$randomZ"}], ",", "2147483543"}], "]"}]}], + ")"}]}], ",", "214783629"}], "]"}]}], "\n"}], "\[IndentingNewLine]", + RowBox[{ + RowBox[{ + RowBox[{"PortableRNGInteger", "[", + RowBox[{"n_Integer", "?", "Positive"}], "]"}], ":=", + RowBox[{"Table", "[", + RowBox[{ + RowBox[{"PortableRNGInteger", "[", "]"}], ",", + RowBox[{"{", "n", "}"}]}], "]"}]}], "\n"}], "\[IndentingNewLine]", + RowBox[{ + RowBox[{ + RowBox[{"PortableRNG", "[", "]"}], ":=", + RowBox[{ + RowBox[{"(", + RowBox[{ + RowBox[{"PortableRNGInteger", "[", "]"}], "-", "1."}], ")"}], "/", + "214783629"}]}], "\n"}], "\[IndentingNewLine]", + RowBox[{ + RowBox[{"PortableRNG", "[", + RowBox[{"n_Integer", "?", "Positive"}], "]"}], ":=", + RowBox[{ + RowBox[{"(", + RowBox[{ + RowBox[{"Table", "[", + RowBox[{ + RowBox[{"PortableRNGInteger", "[", "]"}], ",", + RowBox[{"{", "n", "}"}]}], "]"}], "-", "1."}], ")"}], "/", + "214783629"}]}], "\n"}], "Input", + Evaluatable->False, + CellChangeTimes->{3.388665952796875*^9}] +}, Open ]], + +Cell[CellGroupData[{ + +Cell["Setup for Version 6", "Subsection", + CellChangeTimes->{{3.388665821359375*^9, 3.388665825203125*^9}}], + +Cell[BoxData[ + RowBox[{"Clear", "[", "PortableRandom", "]"}]], "Input", + CellChangeTimes->{{3.388663583921875*^9, 3.388663587328125*^9}, { + 3.388665510875*^9, 3.3886655134375*^9}, {3.388667134453125*^9, + 3.38866713890625*^9}}], + +Cell[BoxData[ + RowBox[{ + RowBox[{ + RowBox[{"PortableRandom", "[", "___", "]"}], "[", + "\"\<GeneratesRealsQ\>\"", "]"}], " ", ":=", " ", "True"}]], "Input", + CellChangeTimes->{{3.3886631375*^9, 3.388663138640625*^9}, + 3.388663175671875*^9, 3.388664005296875*^9, 3.388664360609375*^9, + 3.38866552575*^9, 3.3886671536875*^9}], + +Cell[BoxData[ + RowBox[{ + RowBox[{ + RowBox[{"PortableRandom", "[", + RowBox[{"s1_", ",", "s2_"}], "]"}], "[", + RowBox[{"\"\<GenerateReals\>\"", "[", + RowBox[{"n_", ",", + RowBox[{"{", + RowBox[{"a_", ",", "b_"}], "}"}], ",", "prec_"}], "]"}], "]"}], " ", ":=", + " ", "\[IndentingNewLine]", + RowBox[{"Module", "[", + RowBox[{ + RowBox[{"{", + RowBox[{ + RowBox[{"x1", "=", "s1"}], ",", + RowBox[{"x2", "=", "s2"}]}], "}"}], ",", "\[IndentingNewLine]", + RowBox[{"{", + RowBox[{ + RowBox[{"a", "+", + RowBox[{ + RowBox[{"(", + RowBox[{"b", "-", "a"}], ")"}], + RowBox[{"(", + RowBox[{ + RowBox[{"Table", "[", + RowBox[{ + RowBox[{ + RowBox[{"Mod", "[", + RowBox[{ + RowBox[{ + RowBox[{"(", + RowBox[{"x1", "=", + RowBox[{"Mod", "[", + RowBox[{ + RowBox[{"64155", "*", "x1"}], ",", "214783629"}], "]"}]}], + ")"}], "-", + RowBox[{"(", + RowBox[{"x2", "=", + RowBox[{"Mod", "[", + RowBox[{ + RowBox[{"10064", "*", "x2"}], ",", "2147483543"}], + "]"}]}], ")"}]}], ",", "214783629"}], "]"}], "-", "1"}], + ",", + RowBox[{"{", "n", "}"}]}], "]"}], "/", "214783629"}], ")"}]}]}], + ",", + RowBox[{"PortableRandom", "[", + RowBox[{"x1", ",", "x2"}], "]"}]}], "}"}]}], "\[IndentingNewLine]", + "]"}]}]], "Input", + CellChangeTimes->{{3.388663362234375*^9, 3.388663395734375*^9}, { + 3.3886635138125*^9, 3.388663520625*^9}, {3.38866401546875*^9, + 3.388664018625*^9}, {3.3886641531875*^9, 3.388664155859375*^9}, { + 3.388664201171875*^9, 3.388664201484375*^9}, {3.3886644155*^9, + 3.388664418796875*^9}, {3.3886655335*^9, 3.388665536109375*^9}, { + 3.388667162*^9, 3.388667164109375*^9}, {3.38866721584375*^9, + 3.388667235265625*^9}, {3.3886673793125*^9, 3.388667388953125*^9}, { + 3.3886682429375*^9, 3.388668246296875*^9}, {3.388668304109375*^9, + 3.38866831221875*^9}}], + +Cell[BoxData[ + RowBox[{ + RowBox[{ + RowBox[{"PortableRandom", "[", "___", "]"}], "[", + RowBox[{"\"\<SeedGenerator\>\"", "[", "seed_", "]"}], "]"}], " ", ":=", + " ", "\[IndentingNewLine]", + RowBox[{"With", "[", + RowBox[{ + RowBox[{"{", + RowBox[{"x", "=", + RowBox[{"Mod", "[", + RowBox[{"seed", ",", "214783629"}], "]"}]}], "}"}], ",", + RowBox[{"PortableRandom", "[", + RowBox[{"x", ",", + RowBox[{"Mod", "[", + RowBox[{ + RowBox[{"64155", "*", "x"}], ",", "214783629"}], "]"}]}], "]"}]}], + "]"}]}]], "Input", + CellChangeTimes->{ + 3.38866317365625*^9, {3.38866331184375*^9, 3.388663336734375*^9}, { + 3.388663401421875*^9, 3.388663439796875*^9}, {3.3886636635625*^9, + 3.388663669359375*^9}, {3.388664010296875*^9, 3.388664012859375*^9}, { + 3.38866552853125*^9, 3.388665530984375*^9}, {3.388667156734375*^9, + 3.38866715903125*^9}, {3.38866759378125*^9, 3.38866764028125*^9}}], + +Cell[BoxData[ + RowBox[{"PortableRandom", " ", "/:", " ", + RowBox[{"Random`InitializeGenerator", "[", + RowBox[{"PortableRandom", ",", "___"}], "]"}], " ", ":=", " ", + RowBox[{"With", "[", + RowBox[{ + RowBox[{"{", + RowBox[{"x", "=", + RowBox[{"Mod", "[", + RowBox[{ + RowBox[{"Round", "[", + RowBox[{"AbsoluteTime", "[", "]"}], "]"}], ",", "214783629"}], + "]"}]}], "}"}], ",", + RowBox[{"PortableRandom", "[", + RowBox[{"x", ",", + RowBox[{"Mod", "[", + RowBox[{ + RowBox[{"64155", "*", "x"}], ",", "214783629"}], "]"}]}], "]"}]}], + "]"}]}]], "Input", + CellChangeTimes->{{3.388663082375*^9, 3.388663109234375*^9}, { + 3.388663144171875*^9, 3.38866314690625*^9}, {3.388663456953125*^9, + 3.388663471484375*^9}, {3.388663836765625*^9, 3.388663845390625*^9}, { + 3.3886639966875*^9, 3.3886639994375*^9}, {3.388664583109375*^9, + 3.388664583890625*^9}, {3.38866551728125*^9, 3.388665523140625*^9}, { + 3.388667144515625*^9, 3.38866715075*^9}, {3.38866766728125*^9, + 3.388667702234375*^9}}] +}, Open ]], + +Cell[CellGroupData[{ + +Cell["Run in Version 6", "Subsection", + CellChangeTimes->{{3.388668828125*^9, 3.388668832015625*^9}}], + +Cell[BoxData[ + RowBox[{"SeedRandom", "[", + RowBox[{"Method", "\[Rule]", "PortableRandom"}], "]"}]], "Input", + CellChangeTimes->{{3.388667721171875*^9, 3.38866773025*^9}, { + 3.38866798259375*^9, 3.388667982859375*^9}, {3.3887355270057297`*^9, + 3.388735532786906*^9}}], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{"Table", "[", + RowBox[{ + RowBox[{"RandomReal", "[", "]"}], ",", + RowBox[{"{", "100", "}"}]}], "]"}]], "Input", + CellChangeTimes->{{3.3886679846875*^9, 3.388668042453125*^9}, { + 3.3887355125059156`*^9, 3.38873551528713*^9}}], + +Cell[BoxData[ + RowBox[{"{", + RowBox[{ + "0.`", ",", "0.`", ",", "0.`", ",", "0.`", ",", "0.`", ",", "0.`", ",", + "0.`", ",", "0.`", ",", "0.`", ",", "0.`", ",", "0.`", ",", "0.`", ",", + "0.`", ",", "0.`", ",", "0.`", ",", "0.`", ",", "0.`", ",", "0.`", ",", + "0.`", ",", "0.`", ",", "0.`", ",", "0.`", ",", "0.`", ",", "0.`", ",", + "0.`", ",", "0.`", ",", "0.`", ",", "0.`", ",", "0.`", ",", "0.`", ",", + "0.`", ",", "0.`", ",", "0.`", ",", "0.`", ",", "0.`", ",", "0.`", ",", + "0.`", ",", "0.`", ",", "0.`", ",", "0.`", ",", "0.`", ",", "0.`", ",", + "0.`", ",", "0.`", ",", "0.`", ",", "0.`", ",", "0.`", ",", "0.`", ",", + "0.`", ",", "0.`", ",", "0.`", ",", "0.`", ",", "0.`", ",", "0.`", ",", + "0.`", ",", "0.`", ",", "0.`", ",", "0.`", ",", "0.`", ",", "0.`", ",", + "0.`", ",", "0.`", ",", "0.`", ",", "0.`", ",", "0.`", ",", "0.`", ",", + "0.`", ",", "0.`", ",", "0.`", ",", "0.`", ",", "0.`", ",", "0.`", ",", + "0.`", ",", "0.`", ",", "0.`", ",", "0.`", ",", "0.`", ",", "0.`", ",", + "0.`", ",", "0.`", ",", "0.`", ",", "0.`", ",", "0.`", ",", "0.`", ",", + "0.`", ",", "0.`", ",", "0.`", ",", "0.`", ",", "0.`", ",", "0.`", ",", + "0.`", ",", "0.`", ",", "0.`", ",", "0.`", ",", "0.`", ",", "0.`", ",", + "0.`", ",", "0.`", ",", "0.`", ",", "0.`"}], "}"}]], "Output", + CellChangeTimes->{{3.388667987359375*^9, 3.388668042765625*^9}, { + 3.388735504881013*^9, 3.3887355350837517`*^9}}] +}, Open ]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{ + RowBox[{ + RowBox[{"RandomReal", "[", + RowBox[{"1", ",", + SuperscriptBox["10", "5"]}], "]"}], ";"}], "//", "Timing"}]], "Input", + CellChangeTimes->{{3.38866773296875*^9, 3.388667761375*^9}}], + +Cell[BoxData[ + RowBox[{"{", + RowBox[{"0.875`", ",", "Null"}], "}"}]], "Output", + CellChangeTimes->{{3.3886677343125*^9, 3.388667762640625*^9}, + 3.3887355391930737`*^9}] +}, Open ]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{"Histogram", "[", + RowBox[{ + RowBox[{"RandomReal", "[", + RowBox[{"1", ",", + SuperscriptBox["10", "5"]}], "]"}], ",", + RowBox[{"{", + RowBox[{".01", ",", "0"}], "}"}], ",", + RowBox[{"GridLines", "\[Rule]", + RowBox[{"{", + RowBox[{ + RowBox[{"{", "}"}], ",", + RowBox[{"{", + RowBox[{"0", ",", "1"}], "}"}]}], "}"}]}]}], "]"}]], "Input", + CellChangeTimes->{{3.388667768734375*^9, 3.388667781125*^9}, { + 3.388735571614534*^9, 3.3887355880986977`*^9}}], + +Cell[BoxData[ + GraphicsBox[{ + LineBox[{{0., 0}, {0., 1.022}, {0.01, 1.022}, {0.01, 0.967}, {0.02, + 0.967}, {0.02, 0.98}, {0.03, 0.98}, {0.03, 1.028}, {0.04, 1.028}, {0.04, + 0.974}, {0.05, 0.974}, {0.05, 0.9480000000000001}, {0.06, + 0.9480000000000001}, {0.06, 0.962}, {0.07, 0.962}, {0.07, 1.041}, {0.08, + 1.041}, {0.08, 1.026}, {0.09, 1.026}, {0.09, 0.996}, {0.1, 0.996}, {0.1, + 0.96}, {0.11, 0.96}, {0.11, 1.029}, {0.12, 1.029}, {0.12, 0.969}, {0.13, + 0.969}, {0.13, 0.994}, {0.14, 0.994}, {0.14, 0.985}, {0.15, 0.985}, { + 0.15, 1.01}, {0.16, 1.01}, {0.16, 1.0210000000000001`}, {0.17, + 1.0210000000000001`}, {0.17, 0.9410000000000001}, {0.18, + 0.9410000000000001}, {0.18, 1.031}, {0.19, 1.031}, {0.19, 1.052}, {0.2, + 1.052}, {0.2, 1.02}, {0.21, 1.02}, {0.21, 1.032}, {0.22, 1.032}, {0.22, + 0.962}, {0.23, 0.962}, {0.23, 1.049}, {0.24, 1.049}, {0.24, + 1.0090000000000001`}, {0.25, 1.0090000000000001`}, {0.25, 0.991}, {0.26, + 0.991}, {0.26, 1.0190000000000001`}, {0.27, 1.0190000000000001`}, {0.27, + 0.996}, {0.28, 0.996}, {0.28, 1.0090000000000001`}, {0.29, + 1.0090000000000001`}, {0.29, 0.994}, {0.3, 0.994}, {0.3, 1.026}, {0.31, + 1.026}, {0.31, 0.999}, {0.32, 0.999}, {0.32, 1.0190000000000001`}, {0.33, + 1.0190000000000001`}, {0.33, 0.971}, {0.34, 0.971}, {0.34, 1.028}, { + 0.35000000000000003`, 1.028}, {0.35000000000000003`, 0.99}, {0.36, + 0.99}, {0.36, 1.045}, {0.37, 1.045}, {0.37, 1.035}, {0.38, 1.035}, {0.38, + 1.}, {0.39, 1.}, {0.39, 0.992}, {0.4, 0.992}, {0.4, 1.068}, { + 0.41000000000000003`, 1.068}, {0.41000000000000003`, 0.978}, {0.42, + 0.978}, {0.42, 0.987}, {0.43, 0.987}, {0.43, 1.038}, {0.44, 1.038}, { + 0.44, 0.9500000000000001}, {0.45, 0.9500000000000001}, {0.45, 1.075}, { + 0.46, 1.075}, {0.46, 1.048}, {0.47000000000000003`, 1.048}, { + 0.47000000000000003`, 0.979}, {0.48, 0.979}, {0.48, + 0.9420000000000001}, {0.49, 0.9420000000000001}, {0.49, 0.976}, {0.5, + 0.976}, {0.5, 0.973}, {0.51, 0.973}, {0.51, 0.987}, {0.52, 0.987}, {0.52, + 0.99}, {0.53, 0.99}, {0.53, 0.9510000000000001}, {0.54, + 0.9510000000000001}, {0.54, 1.0210000000000001`}, {0.55, + 1.0210000000000001`}, {0.55, 0.989}, {0.56, 0.989}, {0.56, + 1.0130000000000001`}, {0.5700000000000001, 1.0130000000000001`}, { + 0.5700000000000001, 0.983}, {0.58, 0.983}, {0.58, 1.0130000000000001`}, { + 0.59, 1.0130000000000001`}, {0.59, 0.9520000000000001}, {0.6, + 0.9520000000000001}, {0.6, 0.9540000000000001}, {0.61, + 0.9540000000000001}, {0.61, 1.0230000000000001`}, {0.62, + 1.0230000000000001`}, {0.62, 1.039}, {0.63, 1.039}, {0.63, + 0.9560000000000001}, {0.64, 0.9560000000000001}, {0.64, 1.01}, {0.65, + 1.01}, {0.65, 1.0090000000000001`}, {0.66, 1.0090000000000001`}, {0.66, + 0.988}, {0.67, 0.988}, {0.67, 1.0070000000000001`}, {0.68, + 1.0070000000000001`}, {0.68, 0.972}, {0.6900000000000001, 0.972}, { + 0.6900000000000001, 0.9520000000000001}, {0.7000000000000001, + 0.9520000000000001}, {0.7000000000000001, 1.09}, {0.71, 1.09}, {0.71, + 1.016}, {0.72, 1.016}, {0.72, 0.987}, {0.73, 0.987}, {0.73, 1.014}, { + 0.74, 1.014}, {0.74, 0.961}, {0.75, 0.961}, {0.75, 1.014}, {0.76, + 1.014}, {0.76, 1.022}, {0.77, 1.022}, {0.77, 1.0070000000000001`}, {0.78, + 1.0070000000000001`}, {0.78, 0.968}, {0.79, 0.968}, {0.79, + 1.0010000000000001`}, {0.8, 1.0010000000000001`}, {0.8, 1.002}, {0.81, + 1.002}, {0.81, 0.992}, {0.8200000000000001, 0.992}, {0.8200000000000001, + 0.9380000000000001}, {0.8300000000000001, 0.9380000000000001}, { + 0.8300000000000001, 0.983}, {0.84, 0.983}, {0.84, 0.9540000000000001}, { + 0.85, 0.9540000000000001}, {0.85, 1.03}, {0.86, 1.03}, {0.86, 1.004}, { + 0.87, 1.004}, {0.87, 0.9400000000000001}, {0.88, 0.9400000000000001}, { + 0.88, 1.0150000000000001`}, {0.89, 1.0150000000000001`}, {0.89, 1.033}, { + 0.9, 1.033}, {0.9, 0.99}, {0.91, 0.99}, {0.91, 0.97}, {0.92, 0.97}, { + 0.92, 1.}, {0.93, 1.}, {0.93, 1.002}, {0.9400000000000001, 1.002}, { + 0.9400000000000001, 1.0130000000000001`}, {0.9500000000000001, + 1.0130000000000001`}, {0.9500000000000001, 0.976}, {0.96, 0.976}, {0.96, + 0.989}, {0.97, 0.989}, {0.97, 1.028}, {0.98, 1.028}, {0.98, 1.051}, { + 0.99, 1.051}, {0.99, 1.065}, {1., 1.065}, {1., 0}}], {}, {}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + DisplayFunction->Identity, + Frame->{True, True, False, False}, + GridLines->{{}, {0, 1}}]], "Output", + CellChangeTimes->{ + 3.388667782625*^9, 3.388668377640625*^9, 3.3887355428024025`*^9, { + 3.388735579270686*^9, 3.388735607067205*^9}}] +}, Open ]] +}, Open ]] +}, Open ]] +}, +WindowSize->{1044, 881}, +WindowMargins->{{0, Automatic}, {Automatic, 0}}, +ShowSelection->True, +FrontEndVersion->"6.0 for Microsoft Windows (32-bit) (March 26, 2007)", +StyleDefinitions->"Default.nb" +] +(* End of Notebook Content *) + +(* Internal cache information *) +(*CellTagsOutline +CellTagsIndex->{} +*) +(*CellTagsIndex +CellTagsIndex->{} +*) +(*NotebookFileOutline +Notebook[{ +Cell[568, 21, 124, 1, 34, "Text"], +Cell[695, 24, 374, 11, 49, "Input", + CellID->207931436], +Cell[1072, 37, 1813, 46, 269, "Input", + CellID->15261556], +Cell[2888, 85, 217, 7, 49, "Input", + CellID->413732366], +Cell[3108, 94, 538, 15, 71, "Input", + CellID->7906412], +Cell[3649, 111, 1114, 32, 115, "Input", + CellID->216655639], +Cell[4766, 145, 183, 3, 49, "Input"], +Cell[CellGroupData[{ +Cell[4974, 152, 284, 7, 51, "Input"], +Cell[5261, 161, 3386, 55, 317, "Output"] +}, Open ]], +Cell[CellGroupData[{ +Cell[8684, 221, 94, 1, 88, "Section"], +Cell[8781, 224, 252, 5, 55, "Text"], +Cell[CellGroupData[{ +Cell[9058, 233, 104, 1, 46, "Subsection"], +Cell[CellGroupData[{ +Cell[9187, 238, 174, 4, 33, "Input"], +Cell[9364, 244, 73, 1, 32, "Output"] +}, Open ]], +Cell[9452, 248, 1255, 37, 208, "Input", + Evaluatable->False] +}, Open ]], +Cell[CellGroupData[{ +Cell[10744, 290, 155, 2, 46, "Subsection"], +Cell[10902, 294, 178, 3, 49, "Input"], +Cell[11083, 299, 311, 7, 49, "Input"], +Cell[11397, 308, 1342, 36, 115, "Input"], +Cell[12742, 346, 705, 14, 71, "Input"], +Cell[13450, 362, 596, 13, 71, "Input"] +}, Open ]], +Cell[CellGroupData[{ +Cell[14083, 380, 102, 1, 46, "Subsection"], +Cell[14188, 383, 175, 3, 49, "Input"], +Cell[CellGroupData[{ +Cell[14388, 390, 263, 6, 49, "Input"], +Cell[14654, 398, 3387, 55, 317, "Output"] +}, Open ]], +Cell[CellGroupData[{ +Cell[18078, 458, 180, 4, 32, "Input"], +Cell[18261, 464, 103, 1, 32, "Output"] +}, Open ]], +Cell[18379, 468, 502, 9, 32, "Input"], +Cell[18884, 479, 185, 3, 32, "Input"], +Cell[CellGroupData[{ +Cell[19094, 486, 200, 3, 32, "Input"], +Cell[19297, 491, 370, 5, 32, "Output"] +}, Open ]], +Cell[CellGroupData[{ +Cell[19704, 501, 456, 10, 34, "Input"], +Cell[20163, 513, 136, 3, 32, "Output"] +}, Open ]] +}, Open ]] +}, Open ]], +Cell[CellGroupData[{ +Cell[20360, 523, 159, 2, 88, "Section"], +Cell[CellGroupData[{ +Cell[20544, 529, 108, 1, 46, "Subsection"], +Cell[20655, 532, 2321, 70, 406, "Input", + Evaluatable->False] +}, Open ]], +Cell[CellGroupData[{ +Cell[23013, 607, 107, 1, 46, "Subsection"], +Cell[23123, 610, 229, 4, 49, "Input"], +Cell[23355, 616, 334, 7, 49, "Input"], +Cell[23692, 625, 2159, 56, 181, "Input"], +Cell[25854, 683, 941, 23, 71, "Input"], +Cell[26798, 708, 1063, 25, 71, "Input"] +}, Open ]], +Cell[CellGroupData[{ +Cell[27898, 738, 101, 1, 46, "Subsection"], +Cell[28002, 741, 271, 5, 49, "Input"], +Cell[CellGroupData[{ +Cell[28298, 750, 254, 6, 49, "Input"], +Cell[28555, 758, 1437, 21, 115, "Output"] +}, Open ]], +Cell[CellGroupData[{ +Cell[30029, 784, 226, 6, 51, "Input"], +Cell[30258, 792, 173, 4, 49, "Output"] +}, Open ]], +Cell[CellGroupData[{ +Cell[30468, 801, 517, 15, 51, "Input"], +Cell[30988, 818, 4697, 68, 318, "Output"] +}, Open ]] +}, Open ]] +}, Open ]] +} +] +*) + +(* End of internal cache information *) diff --git a/MathematicaFiles/Applications/RecursivePreferencesPDE.m b/MathematicaFiles/Applications/RecursivePreferencesPDE.m new file mode 100755 index 0000000..9241e48 --- /dev/null +++ b/MathematicaFiles/Applications/RecursivePreferencesPDE.m @@ -0,0 +1,169 @@ +(* :Title: RecursivePreferencesPDE *) +(* :Author: Mark Fisher *) +(* :Date: July 2006 *) + +(* :Summary: + Setup and solve PDEs associated with homogeneous recursive preferences. + *) + +Needs["ItosLemma`"] +Needs["DifferentialEquations`InterpolatingFunctionAnatomy`"] +Needs["Utilities`FilterOptions`"] +(* Needs["Graphics`Graphics`"] *) + +(* Turn off inapplicable message *) +Off[NDSolve::bcart] + +(* Global variables used *) +Clear[a, u, \[Beta], \[Eta], \[Gamma]] + +u[1 | 1.][x_] := Log[x] +u[\[Eta]_?NumericQ][x_] := (-1 + x^(1 - \[Eta]^(-1)))/(1 - \[Eta]^(-1)) + +ConsumptionRules = {Subscript[a, 0] -> 0, Subscript[a, 1] -> 1, + Subscript[a, 2] -> 1 - \[Gamma]}; +CapitalAccountRules = {Subscript[a, 0] -> -\[Beta] * \[Eta], + Subscript[a, 1] -> \[Eta], Subscript[a, 2] -> (1 - \[Gamma])/\[Eta]}; +DeflatorAssetRules = {Subscript[a, 0] -> -\[Beta] * \[Eta], + Subscript[a, 1] -> \[Eta], Subscript[a, 2] -> (1 - \[Gamma])/(\[Eta] \[Gamma])}; + +AssemblePDE::usage = "AssemblePDE[drifts, diffusions, termcond, f, Xnames, \ +t] returns the PDE for the \"information variable\" given the dynamics for \ +(the log of) the \"forcing variable\" (either the rate of consumption, the \ +capital accont, or the deflator asset). The user provides the vector of \ +drifts and the matrix of diffusions, where the first element of each is \ +that of the forcing variable and the rest of each are those of the state \ +variables. In addition, a terminal condition (termcond) must be specified \ +and symbols for the unknown function f, the names of the state variables, \ +and time symbol must be provided. AssemblePDE takes the option \ +ForcingVariable; valid settings are Consumption, CapitalAccount, or \ +DeflatorAsset. Any other setting produces generic coefficients." + +SolvePDE::usage = "SolvePDE[{pde, termcond}, f, Xranges, {t, Tstep}, opts] \ +returns a numerical solution to the PDE (given the terminal condition \ +termcond) computed iteratively backward by Tstep until the time derivative \ +is effectively zero. (Note Xranges is a sequence of ranges for the state \ +variables.) SolvePDE takes the options TimeDerivativeTolerance, \ +MaxIterations, and SteadyStateSolutionOnly. In addition, appropriate \ +options will be passed to NDSolve`MethodOfLines and \ +NDSolve`MetheOfLines`TensorProductGrid. As a side-effect, SolvePDE produces \ +an NDSolve`StateData object named $PDEState." + +$PDEState::usage = "$PDEState gives the most recent NDSolve`StateData \ +object computed by NDSolve`Iterate via SolvePDE." + +TimeDerivativeTolerance::usage = "TimeDerivativeTolerance is an option for \ +SolvePDE which specifies the tolerance to use in determining when the time \ +derivative is effectively zero (i.e., when the steady-state solution is \ +reached). The specified tolerance is comparted with \ +Norm[$PDEState@\"SolutionDerivativeVector\"[\"Backward\"], \[Infinity]]. \ +The default setting is TimeDerivativeTolerance -> 10^(-12)." + +SteadyStateSolutionOnly::usage = "SteadyStateSolutionOnly is an option for \ +SolvePDE which specifies whether to return the steady-state solution only. \ +The default setting is SteadyStateSolutionOnly -> True." + +ConsumptionRules::usage = "ConsumptionRules is a list of replacement rules \ +intended to be used with the output of AssemblePDE." + +CapitalAccountRules::usage = "CapitalAccountRules is a list of replacement \ +rules intended to be used with the output of AssemblePDE." + +DeflatorAssetRules::usage = "DeflatorAssetRules is a list of replacement \ +rules intended to be used with the output of AssemblePDE." + +PlotTimeDerivative::usage = "PlotTimeDerivative[NDSolve`StateData] produces \ +a LogPlot of the \!\(L\^\[Infinity]\) norm of the time derivative." + +ForcingVariable::usage = "ForcingVariable is an option for AssemblePDE that \ +specifies the intended parameterization. Valid settings are Consumption, \ +CapitalAccount, or DeflatorAsset." + +Consumption::usage = "Consumption is a setting for the ForcingVariable \ +option for AssemblePDE." + +CapitalAccount::usage = "CapitalAccount is a setting for the \ +ForcingVariable option for AssemblePDE." + +DeflatorAsset::usage = "DeflatorAsset is a setting for the ForcingVariable \ +option for AssemblePDE." + +Options[AssemblePDE] = {ForcingVariable -> Consumption} + +AssemblePDE[drifts_List, diffusions:{__List}, terminal_, f_, + Xnames:{__Symbol}, t_Symbol, opts___?OptionQ] := + Module[{Xt, nbrownians, dxi, xidrift, xidiffusion}, + Xt = Through[Xnames[t]]; + nbrownians = Dimensions[diffusions][[-1]]; + MapThread[ItoMake, {Xt, Rest[drifts], Rest[diffusions]}]; + dxi = ItoD[f @@ Append[Xt, t], SuppressTime -> False] /. Thread[Xt -> Xnames]; + xidrift = Drift[dxi]; + xidiffusion = Diffusion[dxi, + Scalarize -> False, + BrownianList -> Table[Subscript[dB, i], {i, Max[1, nbrownians]}]]; + {Subscript[a, 0] + xidrift + Subscript[a, 1] * First[drifts] + + Subscript[a, 2]/2 * (#.#) &[Subscript[a, 1] * First[diffusions] + xidiffusion] + + \[Beta] * u[\[Eta]][Exp[-f @@ Append[Xnames, t]]] == 0, + f @@ Append[Xnames, 0] == terminal} /. + (* Substitute out generic parameters given the forcing variable *) + Switch[ForcingVariable /. {opts} /. Options[AssemblePDE], + Consumption, ConsumptionRules, + CapitalAccount, CapitalAccountRules, + DeflatorAsset, DeflatorAssetRules, + _, {} (* use no rules *) + ] + ] + +Options[SolvePDE] = { + MaxIterations -> 100, + TimeDerivativeTolerance -> 10^(-12.), + SteadyStateSolutionOnly -> True + } + +SolvePDE::noconv = + "Warning: the time derivative did not converge by time = `1` (`2` iterations)." + +SolvePDE[eqns_List, f_Symbol, Xranges:{_Symbol, _?NumericQ, _?NumericQ}.., + {t_Symbol, Tstep_?NumericQ}, opts___?OptionQ] := + Module[{methodopts, gridopts, maxiters, tol, steady, count}, + methodopts = FilterOptions[NDSolve`MethodOfLines, opts]; + gridopts = FilterOptions[NDSolve`MethodOfLines`TensorProductGrid, opts]; + maxiters = MaxIterations /. {opts} /. Options[SolvePDE]; + tol = TimeDerivativeTolerance /. {opts} /. Options[SolvePDE]; + steady = TrueQ[SteadyStateSolutionOnly /. {opts} /. Options[SolvePDE]]; + count = 0; + (* Initialize *) + $PDEState = NDSolve`ProcessEquations[eqns, f, Xranges, t, + Method -> { + "MethodOfLines", methodopts, + "SpatialDiscretization" -> {"TensorProductGrid", gridopts} + } + ][[1]]; + (* Solve PDE backwards by Tstep until time derivative is less than the + tolerance. *) + While[Norm[$PDEState@"SolutionDerivativeVector"["Backward"], Infinity] > tol + && (count++) < maxiters, + NDSolve`Iterate[$PDEState, $PDEState@"CurrentTime"["Backward"] - Tstep]]; + If[count > maxiters > 1, Message[SolvePDE::noconv, -maxiters * Tstep, maxiters]]; + If[steady, + (* Steady-state solution *) + NDSolve`ProcessSolutions[$PDEState, "Backward"][[1, 2, 0]], + (* Entire solution *) + NDSolve`ProcessSolutions[$PDEState][[1, 2]] + ] + ] + +PlotTimeDerivative[state_NDSolve`StateData, opts___?OptionQ] := + Module[{baseline, plotopts, ifun0, n, ifun, normfun, t}, + baseline = TimeDerivativeTolerance /. {opts} /. Options[SolvePDE]; + plotopts = FilterOptions[LogPlot, opts]; + ifun0 = NDSolve`ProcessSolutions[state][[1, 2]]; + n = Length[InterpolatingFunctionDomain[ifun0]] - 1; + ifun = Operate[Derivative @@ # &, Append[Table[0, {n}], 1][ifun0]]; + normfun = Norm[ + ifun[##, t] & @@@ Transpose[Most[InterpolatingFunctionCoordinates[ifun]]], + Infinity]; + LogPlot[normfun, {t, state@"CurrentTime"["Backward"], 0}, opts, + PlotRange -> All, GridLines -> {{}, {baseline}}] + ] + diff --git a/MathematicaFiles/Applications/Remaining/TempFiles/Thumbs.db b/MathematicaFiles/Applications/Remaining/TempFiles/Thumbs.db new file mode 100755 index 0000000000000000000000000000000000000000..cf047f1c01370d9fdd3ad77849a9f011172c97b7 GIT binary patch literal 5120 zcmca`Uhu)fjZzO8(10BSGsD0CoD6J8;*1Oo3?K{^5@29pg7W|U|NkE>#=yYve-sR< z5cvE5|9?>YfiMdL0|P4q131pv85kHi7#J8p;zP<qqmCsh1cDgy8S)uQ7!(*>8S)rP z7>XDwVOg0dT8x1ep6B6Z0}h=I6ZULA-F}jhnSp_!feWI@5JHhnvM?|)f;<c=i$FB7 z23bPwcV<XrC}Bus$YIE5NGDb^k~#qfCb<8JwO^Bgfx!gH3`&_GdtsPVvp{hM3Oi7o zV9WoU3=9mQpyFm=VBle3VBlq7VBlk5VBlw9U=UznU=U<rU=U(pU=U_tU=U$oU=U?s zU=U+qU=U|uV31&7V31^BV31;9V31~DV31*8V31{CV31>AV322EU{GLSU{GXWU{GRU zU{GdYU{GOTU{GaXU{GUVU{GgZV9<b;Kci(3EOx0+gW?pF26VX?82;b*|A0Zj%gxh` zfsv7sp@N};f#Lsc24@ClCMFPKW@ct#W@cgKU}a@tVdY|HXXD`E;^E=u;^yY%6B6L% z6XfIO77!B<6c!N`73JX<mk<+?5E2m;0U5%`%)-LT!ph0Y$|=Ij%_~AO_<w*wkb@zC zA%U4uiGfLwky()O{}E6+Vq|3m16a~$WMXDvWn<^y<l_E+gkh@y0}~@NGZPCl$khxC zjJ1qR%nU4otU`*0j%>n#iR?;+B1Vl97jh^&Z9FI%bn%0VaZ*teCzqJGgrt<Jn!1Lj zmWipExrL>bvx}>nyN9P&a7buactm7Wa!P7idPZheaY<=ec|~Pab4zPmdq-#2q{&mJ zPMbbs=B!1Fmn>bje8tLDn>KIRx^4T8ox2VlK63Qf@e?OcUAlbb>b2`PZr*zM=<$=M z&z`?{`Re1R&tJZN`~KtSFOa_&8JNMo0ud0Oq4`UYfr*icg@u`got1@!fsv`4fsu(> zkcCyzkWI)jkUg<bSjni7L&Ry~!i@(xm5qZwh$a<X<PuXcd8qmk<TbF*i1SzzSw4e% z4B@X^3_Q$?3`~N|f(-Tye}mU?2V7kIQT@o=sB51-hxFaL?zv%-M$T66*)Dva<JglF zCpxOQHLKf~gjdH*?f)~?UZDPlwC{h0i{HO6M*b7eT=V8|*hekq9*vKp-`Fo3J^#;e z)%}mwUvvKd48r+Be~v5v)6#xF{YKsQpU<X8e0biuzI67=H+$0UW-s?*J8kjhL~4dd zfL)}7Op~LEfqg}TyF~5w_R<%<2d5ts-#pXo&3}f@+FczRcg$g!^JK&8d4knXX71j1 zJY>b?9?PpC_w%d%%{r=Un|tdq|6yK}6L0^ne&isLp#MiD{6>7??>GNSHvTcZEcjhE z_{b!l<m`&B-|}&4Y`d}zK193AT=p#1>M=Phcj?{}#{N^wKD#fjzpu99sb&9<uwVXv z{#7*pXW+7R{?E{V@jnCCeb4_4^Un*^KXhMF|MAz$KNnxz|9*1uS-IZ-3^lVDo-X~7 zx%8y8)+;%s&W;16ALSNK{VqA9|4eY=kJM#uY;V1f6g^1Rf294d_Q#Cy@MryQ{~7lA zYVF9I`NvU&@zfvN#x?nSViUHTPdB?(waK0RcHYyS6&G$sod~g6bGG-~bIE_ovAsog zT>lv+wjYoGCfWa=!S`F~wE#x62>E*Lx@z)&237wf^557l*MF(~%TV%F_VkRmPfJ-g ztyJLKdDJuH>q;?MsekU0A=@W*eB;Vs{=E9o{0{;C-C}k!U8ln?nyhs`T7KCzT{!;M z-X&qil?zpjj;&ed;Pyr%<!94_xi{9we?0$o?aCkZ2kIC;wisrHX;v>gz2Zl+%TA@t zWI=Bp<KrydN)Oibt4U7Xo@9E<{GI%qZBlV-mv3ucSb1IQdbhrqtk-j|X-}M&ui4<1 zr_g%3)rciD?Lfj#-_^Sl62I`bugiJ9Wzys0at!UcM+#TPW=eIqPKy2gJ~1uhM8fGO zPqemOV!XF>_2Fq+OO#i~*Z;BJ?%SUw;o*7f{JT#-wby>P+jZSObHDhFAJ?uQo_6h@ z$oA>Kjks6lnQG7MNu4X_Ho3&QYeh)n=0w$Ip-{K%#UI>{%N8H6`p?if>E3U*HtC(q zwq0BEwsCsSs_CjOMVmEP_e@Ecp~q0Of??v%!%JW9`reUO>d4oc&AQ}PXSUeBT~oRv zu1swWStYD=WO?(Bd<&i;iTUn-r`vchU;nmxQN+s^zZ!R5SF65iEt;FpHrrxS07H^z zz^cO<qPG+7i8Ee0a&@ks_t*an`mcXEt!-WECvz`$*XzIaK7T_Ob!p$WNuK#3{7;Xa z)qjQ!XX=0DZ(g@)r#)-^iNlZA|K>UVpJCZ=tJfL~>%5Nt^P1mb|Au$je})&of4$D0 zwDCW~q~(wJe=}$9|7G{D!K!NI8kf&6%{RI&eNrJC>RuG`Aat_UN`-luJSQs7zjToA zxxZQe&EJptUK{3?p69(c+dA4MmhW3+uBvz11fx40%kD%l**P`5Jy>VNxW3}jKDnCg z%YU?&-;Vub(jM)p>V1Fn$!wYKT%De7&7icG8<n4{PfaqM6aHdLRM~6>N7=c15-kEY zG;V)+T-N`2SaQW8R~JS>hk#WE3|~YK>L|_myY$VUwV!{Vce2>d@kzDx()axne>&<P zu<zRVW0iL2AMVwe8)9D1YCU^~TSw5@%2U~EQ?60E^j&w^BF6KgQ-AaRJ6SJiBl$b- zrJUNw@V2kE+^(1N*1gkBEo*X_JCAds^P`ylNxnC^jyx%0nf15q^W^Ja7N7HvzqD?e zWKf>x-uiRTN;m3l>WK;3{)hjQysI%tZmOy$C)drRWisjJ57z&bs44x=kT~N%!<YN% zv8m+c!{|L9N_)S)`5v_Q_)LStjGDJE%kW+0{vqsJ+LOO4wt;b5l2x+g*O#%PB8=zj z4{<MhYM0%kS77tFfm2=L%af1qYBS{6F4vby+_744AZ*5$pF6((Q;y{oVLUgV@#T_9 zaZj4&MamVv?BTi?&!2fX(`=#`i|p-66&|L-ds{LV@Lc<FZ^kR;$YTx+4DJgKtW{uY zV0Sz!62NXuCEt~N33O!;LBhp$=!I3dI)+^gq9-H%Gn@?m$o{u+%l*Id^|84HQEi*$ z+y1G%x*k5QYRR<gQNAsOzNt&^++A2Q>%*?eJUNU^E*2KQ4>ed<X-||F-g4-OtnrZs zCO7}~{0&vb|CaxGG^NJ((y8XZvmY6FD$9T9yZ@y4KSN9g^V&r_zW!LaY<fV+e4!N< zr{($XCzSqYSQdAG#rH$UKRWx?yt}l=Th4y(!`tubHTr*=FkZhHQ!`(r<ch;#kB{2( z->q-Y-+W=-$K-AHg73ZV3xBzAhHdI2Cq@RrhqvEV71<ZxwqN*d0pGr^CyRf~U1q&& zuJMr!af!4KZ~sa6-DtPF^JvkwAIq2fYb(Flr@lSFNM-Wj>r4H&pBA+IqrvpNY5$YN zkJtaUCI4r*TsyaP>hT)ex$D>OiLKjqecH9_vo?9M-_BLtRw)n}bu2<<)!N<@k1hTQ z$M!PR|Gx=olQ0M{u!F~h5*Qd5Kp5192el^|<c|o&x1MD5W5{O!VLgTdh7^W0sIF0J Hu!H~rAzuF3 literal 0 HcmV?d00001 diff --git a/MathematicaFiles/Applications/ReversibleJumpMetropolis.m b/MathematicaFiles/Applications/ReversibleJumpMetropolis.m new file mode 100755 index 0000000..0b2dd1d --- /dev/null +++ b/MathematicaFiles/Applications/ReversibleJumpMetropolis.m @@ -0,0 +1,311 @@ +(* :Author: Mark Fisher *) +(* :Date: April 2006 *) +(* :References: Mark Fisher (2006) "Bayesian estimation of probabilities + of target rates using fed funds futures options", Working Paper. *) + +(* :Discussion: + Create y and X via AssembleFedFundsData in fedfunds.m. + Use MaxEntSimplexInvertMean to compute lambda for prior. + Use MakePriorMatrix to compute the prior matrix. + + To allow for unequal prior model probabilities, multiply + the prior matrix by the prior model probabilities. +*) + +(* :Notes: + Compiling NestList with the function in it is much faster than + compiling the function and running it within an uncompiled NestList. +*) + +Get["MaxEntSimplexDistribution`"] + +ReversibleJumpMetropolis::usage = "ReversibleJumpMetropolis[state, data, +prior, parms, {n, n0}] returns n draws from the posterior after discarding +the first n0 draws. The last argument can be given as n, in which case no +draws are discarded, or omitted entirely in which case a single draw +returned. The other arguments have the following structure: state = {{i, +j}, value, beta}, data = {y, X}, prior = {lambda, matrix}, and parms = {p, +s}. In particular, in the state argument, the pair {i, j} indexes the +current model with coefficient k-vector beta and its value. The beta vector +must have nonzero values in positions i through j and 0 elsewhere. The data +argument is composed of the dependent variable vector y and the matrix of +independent variables X. The prior argument is composed of the k-vector +lambda that characterizes the maximum entropy prior and a (k\[Times]k) +upper-triangular matrix of the inverse of the PartitionFunction values. +(Use MakePriorMatrix to construct it. To allow for unequal prior model +probabilities, multiply the prior matrix by the prior model probabilities.) +The parms argument is composed of the probability p of staying within the +current model and the standard deviation s of the Gaussian proposal +distribution for within model Metropolis-Hastings draws." + +MakePriorMatrix::usage = "MakePriorMatrix[lambda] returns an upper- +triangular matrix of the inverse of the PartitionFunction for each model +{i, j} where i <= j given the k-vector lambda (which includes a final +zero). To allow for unequal prior model probabilities, multiply the prior +matrix by the prior model probabilities." + +PriorModelMatrix::usage = "PriorModelMatrix[models, k] returns an +upper-triangular matrix of model probabilities computed from +the given list of models and the number of states k." + +PostProcess::usage = "PostProcess is an option for ReversibleJumpMetropolis +which specifies whether to process the output, rationalizing the model +indices and collecting the beta coefficients into its own vector." + +UseGLS::usage = "UseGLS is an option for ReversibleJumpMetropolis which +specifies whether to use the GLS variance structure to reduce the out-of- +bounds probability of posterior predictive draws. The default setting is +UseGLS -> False." + +ReformatMC::usage = "ReformatMC[mc] reformats the output from +ReversibleJumpMetropolis, rationalizing the model indices and collecting +the beta coefficients into its own vector." + +MakePriorMatrix[lambda_?VectorQ] := + With[{n = Length[lambda]}, + Table[ + Which[ + i == j, 1, + i > j, 0, + i < j, + 1/PartitionFunction[ lambda[[ Range[i, j - 1] ]] - lambda[[j]] ]], + {i, n}, {j, n}] + ] + +PriorModelMatrix[models:{{_Integer,_Integer}..}, k_Integer] := + N[Table[If[i > j, 0, Count[models, {i, j}]], {i, k}, {j, k}]/ + Length[models]] + +ReformatMC[mc_] := + Transpose[{ + Rationalize[mc[[All, {1, 2}]]], + mc[[All, 3]], + mc[[All, Range[4, Dimensions[#][[2]]]]] + }] + +Options[ReversibleJumpMetropolis] = {PostProcess -> False, + UseGLS -> False} + +ReversibleJumpMetropolis[state_, data_, prior_, parms_, opts___?OptionQ] := + ReversibleJumpMetropolis[state, data, prior, parms, {1, 0}, opts] + +ReversibleJumpMetropolis[state_, data_, prior_, parms_, n_Integer, + opts___?OptionQ] := + ReversibleJumpMetropolis[state, data, prior, parms, {n, 0}, opts] + +ReversibleJumpMetropolis[state:{{i_, j_}, v_, {b__}}, + {y_, X_}, {lam_, mat_}, {p_, s_}, {n_, n0_}, opts___?OptionQ] := + CompileRJM[{y, X}, {lam, mat}][Flatten[state], p, s, n, n0, + TrueQ[UseGLS /. {opts} /. Options[ReversibleJumpMetropolis]]] // + If[TrueQ[PostProcess /. {opts} /. Options[ReversibleJumpMetropolis]], + ReformatMC, + Identity] + +CompileRJM[{y_, X_}, {lam_, mat_}] := + With[{ (* inject these *) + n = Dimensions[X][[1]], + k = Dimensions[X][[2]] + }, + Compile[{ (* arguments *) + {state, _Real, 1}, + {p, _Real, 0}, (* probability of staying within model *) + {s, _Real, 0}, (* std dev of within-model proposals *) + {its, _Integer, 0}, (* number of iterations *) + {its0, _Integer, 0},(* number of burn-in iterations *) + {gls, True|False, 0} (* use GLS? *) + }, + Module[{ (* typing variables *) + r = {1}, + step = {1.}, + factor = 1., + u = 1., + kp = 1, + prior = 1., + like = 1., + Xb = {1.}, + dev = {1.}, + sd = {1.}, + val = 1. + }, + Drop[NestList[ + (* anonymous function to be iterated *) + Module[{ (* initial values *) + movetype = If[RandomReal[] < p, 0, RandomInteger[{1, 4}]], + i = Round[#[[1]]], (* lower model index *) + j = Round[#[[2]]], (* upper model index *) + beta = Drop[#, 3] (* coefficients *) + }, + Catch[ (* catch the state: for bad jumps, etc *) + Which[ + movetype == 0, (* within model move *) + If[i == j, Throw[#]]; (* nothing to do *) + r = Range[i, j-1]; + step = (* standard normal deviates *) + Table[Sqrt[-2 Log[RandomReal[]]] Cos[2 Pi RandomReal[]], {j-i}]; + beta[[r]] += s * step; + beta[[j]] = 1 - Plus @@ beta[[r]]; + If[Min[beta[[ Range[i, j] ]]] <= 0, + Throw[#]], (* out-of-bounds *) + movetype == 1, (* birth of i-1 *) + If[i == 1, Throw[#]]; (* bad jump *) + factor = beta[[i]]; + u = Random[]; + beta[[{i-1, i}]] = beta[[i]] * {1-u, u}; + i--; + r = Range[i, j-1], + movetype == 2, (* birth of j+1 *) + If[j == k, Throw[#]]; (* bad jump *) + factor = beta[[j]]; + u = Random[]; + beta[[{j, j+1}]] = beta[[j]] * {u, 1-u}; + j++; + r = Range[i, j-1], + movetype == 3, (* death of i *) + If[i == j, Throw[#]]; (* bad jump *) + beta[[i+1]] += beta[[i]]; + beta[[i]] = 0; + i++; + factor = 1/beta[[i]]; + r = Range[i, j-1], + movetype == 4, (* death of j *) + If[i == j, Throw[#]]; (* bad jump *) + beta[[j-1]] += beta[[j]]; + beta[[j]] = 0; + j--; + factor = 1/beta[[j]]; + r = Range[i, j-1] + ]; + prior = (* it's OK: it's -lambda *) + If[i == j, 1, Exp[(lam[[j]] - lam[[r]]).beta[[r]]]] * mat[[i,j]]; + Xb = X.beta; + dev = y - Xb; + like = If[gls, + (* then *) + sd = Sqrt[.01 + (Xb * (1 - Xb))]; (* xi = .01 *) + (#.#)^(-n/2)&[dev/sd]/(Times @@ sd), + (* else ols *) + (#.#)^(-n/2)&[dev] + ]; + val = prior * like; (* common constant omitted *) + If[val * factor > Random[] * #[[3]], + Join[{i}, {j}, {val}, beta], + # + ] + ]]&, (* end of Function, Module, and Catch *) + state, its + its0], (* end of NestList *) + its0 + 1] (* drop these, end of Drop *) + ]]] (* end of With, Compile, and Module *) + + +ReversibleJumpMetropolis[state:{{{i0_, j0_}, {i1_, j1_}}, v_, B:{{__}...}}, + {y_, X_}, {lam_, mat_}, {p_, s_}, {n_, n0_}, opts___?OptionQ] := + CompileRJM2[{y, X}, Dimensions[B]][Flatten[state], p, s, n, n0, + TrueQ[UseGLS /. {opts} /. Options[ReversibleJumpMetropolis]]] // + If[TrueQ[PostProcess /. {opts} /. Options[ReversibleJumpMetropolis]], + ReformatMC, + Identity] + +(* flat prior over joint probabilities *) +CompileRJM2[{y_, X_}, {nrows_, ncols_}] := + With[{ (* inject these *) + n = Dimensions[X][[1]], + k = Dimensions[X][[2]], + priorvec = Table[i!, {i, (nrows * ncols) - 1}] + }, + Compile[{ (* arguments *) + {state, _Real, 1}, + {p, _Real, 0}, (* probability of staying within model *) + {s, _Real, 0}, (* std dev of within-model proposals *) + {its, _Integer, 0}, (* number of iterations *) + {its0, _Integer, 0},(* number of burn-in iterations *) + {gls, True|False, 0} (* use GLS? *) + }, + Module[{ (* typing variables *) + r0 = {1}, + r1 = {1}, + step = {1.}, + current = {1.}, + factor = 1., + u = 1., + kp = 1, + prior = 1., + like = 1., + Xb = {1.}, + dev = {1.}, + sd = {1.}, + val = 1. + }, + Drop[NestList[ + (* anonymous function to be iterated *) + Module[{ (* initial values *) + movetype = If[RandomReal[] < p, 0, RandomInteger[{1, 4}]], + i0 = Round[#[[1]]], (* lower model index 0 *) + j0 = Round[#[[2]]], (* upper model index 0 *) + i1 = Round[#[[3]]], (* lower model index 1 *) + j1 = Round[#[[4]]], (* upper model index 1 *) + beta = Partition[Drop[#, 5], ncols] (* coefficients *) + }, + Catch[ (* catch the state: for bad jumps, etc *) + Which[ + movetype == 0, (* within model move *) + If[i0 == j0 && i1 == j1, Throw[#]]; (* nothing to do *) + r0 = Range[i0, j0]; + r1 = Range[i1, j1]; + step = (* standard normal deviates *) + Table[Sqrt[-2 Log[RandomReal[]]] Cos[2 Pi RandomReal[]], + {(j0-i0+1)(j1-i1+1) - 1}]; + current = Most[Flatten[beta[[ r0, r1 ]]]]; + current += s * step; + AppendTo[current, 1 - Plus @@ current]; + beta[[ r0, r1 ]] = Partition[current, j1-i1+1]; + If[Min[beta[[ r0, r1 ]]] <= 0, + Throw[#]], (* out-of-bounds *) + movetype == 1, (* birth of i-1 *) + If[i == 1, Throw[#]]; (* bad jump *) + factor = beta[[i]]; + u = Random[]; + beta[[{i-1, i}]] = beta[[i]] * {1-u, u}; + i--; + r = Range[i, j-1], + movetype == 2, (* birth of j+1 *) + If[j == k, Throw[#]]; (* bad jump *) + factor = beta[[j]]; + u = Random[]; + beta[[{j, j+1}]] = beta[[j]] * {u, 1-u}; + j++; + r = Range[i, j-1], + movetype == 3, (* death of i *) + If[i == j, Throw[#]]; (* bad jump *) + beta[[i+1]] += beta[[i]]; + beta[[i]] = 0; + i++; + factor = 1/beta[[i]]; + r = Range[i, j-1], + movetype == 4, (* death of j *) + If[i == j, Throw[#]]; (* bad jump *) + beta[[j-1]] += beta[[j]]; + beta[[j]] = 0; + j--; + factor = 1/beta[[j]]; + r = Range[i, j-1] + ]; + prior = priorvec[[(j0 - i0 + 1)(j1 - i1 + 1)]]; + Xb = X.beta; + dev = y - Xb; + like = If[gls, + (* then *) + sd = Sqrt[.01 + (Xb * (1 - Xb))]; (* xi = .01 *) + (#.#)^(-n/2)&[dev/sd]/(Times @@ sd), + (* else ols *) + (#.#)^(-n/2)&[dev] + ]; + val = prior * like; (* common constant omitted *) + If[val * factor > Random[] * #[[5]], + Join[{i0, j0, i1, j1}, {val}, beta], + # + ] + ]]&, (* end of Function, Module, and Catch *) + state, its + its0], (* end of NestList *) + its0 + 1] (* drop these, end of Drop *) + ]]] (* end of With, Compile, and Module *) + diff --git a/MathematicaFiles/Applications/SmoothedHistogram.m b/MathematicaFiles/Applications/SmoothedHistogram.m new file mode 100755 index 0000000..2af689b --- /dev/null +++ b/MathematicaFiles/Applications/SmoothedHistogram.m @@ -0,0 +1,288 @@ +(* :Author: Mark Fisher *) + +(* :Date: August 2007 *) + +(* :Mathematica Verion: 6 *) + +Needs["BinnedKernelDensity`"] + +SmoothedHistogram::usage = +"SmoothedHistogram[data, {min,max,dx}, n, (opts)] \ +produces a normalized \ +smoothed histogram from the data by averaging \ +over adjacent bins. The bin width is dx and one \ +may simply specify dx instead of {min,max,dx}.) \ +The \"width\" of the smoothing kernel is given by \ +n, with n=1 specifying no smoothing. The option \ +Kernel can be used to specify the form of the \ +kernel. The option Overhang specifies \ +the number of bins to add to each end. The \ +default is Overhang -> None." + +SmoothedHistogramFunction::usage = +"SmoothedHistogramFunction[data, {min,max,dx}, n, (opts)] \ +produces an InterpolatingFunction of a normalized \ +smoothed histogram from the data by averaging \ +over adjacent bins. The bin width is dx and one \ +may simply specify dx instead of {min,max,dx}.) \ +The \"width\" of the smoothing kernel is given by \ +n, with n=1 specifying no smoothing. The option \ +Kernel can be used to specify the form of the \ +kernel. The option Overhang specifies \ +the number of bins to add to each end. The \ +default is Overhang -> None." + +Overhang::usage = +"Overhang is an option for \ +SmoothedHistogram and related functions that specifies the number of \ +bins to add to each end. The default is Overhang \ +-> None, which specifies no overhang at either end and \ +produces a \"hard\" bound. The maximum overhang \ +at either end is n-1 (where n is the specified \ +\"width\" of the kernel) which can be specfied by All. \ +One may use different settings each end, such as \ +Overhang -> {None, All}. In addition one may use integers \ +between 1 and n-1 (inclusive)." + +PlotCounts::usage = +"PlotCounts is an option for SmoothedHistogram that specifies \ +whether to plot the (smoothed) bin counts instead of the \"density\". \ +The default setting is PlotCounts -> False." + +SmoothedHistogram::badoh = "Bad Overhang specification; using None." + +binCounts::usage = "binCounts[data, {min, max, dx}]" + +GeneralizedMovingAverage::usage = "GeneralizedMovingAverage[data, \ +n, (opts)] computes a moving average of the data." + +Options[SmoothedHistogramFunction] = + {Overhang -> All, Kernel -> TriweightKernel} + +Options[SmoothedHistogram] = + Join[ + Options[SmoothedHistogramFunction], + {PlotCounts -> False, PlotStyle -> Automatic}, + Options[Graphics] + ] + +SmoothedHistogram[data_?VectorQ, {nbins_Integer}, n_Integer, + opts:OptionsPattern[]] := + Module[{dx, min, max}, + dx = (Max[data] - Min[data])/(nbins-1); + min = Ceiling[Min[data] - dx, dx]; + max = Floor[Max[data] + dx, dx]; + SmoothedHistogram[data, {min, max, dx}, n, opts] + ] + +SmoothedHistogram[data_?VectorQ, {nbins_Integer}, + opts:OptionsPattern[]] := + Module[{dx, min, max}, + dx = (Max[data] - Min[data])/(nbins-1); + min = Ceiling[Min[data] - dx, dx]; + max = Floor[Max[data] + dx, dx]; + SmoothedHistogram[data, {min, max, dx}, 1, opts] + ] + +SmoothedHistogram[data_?VectorQ, opts:OptionsPattern[]] := + Module[{dx, min, max}, + dx = (Max[data] - Min[data])/19; + min = Ceiling[Min[data] - dx, dx]; + max = Floor[Max[data] + dx, dx]; + SmoothedHistogram[data, {min, max, dx}, 1, opts] + ] + +SmoothedHistogram[data_?VectorQ, {min_, max_, dx_}, n_Integer, + opts:OptionsPattern[]] := + Module[{olo, ohi, kernel, style, counts, padding, smoothed}, + {olo, ohi} = + Switch[ + over = OptionValue[Overhang] /. {None -> 0, All -> n-1}, + 0, {0, 0}, + n-1, {n-1, n-1}, + {_Integer, _Integer}, Min[Max[#1, 0], n-1] & /@ over, + _, Message[SmoothedHistogram::badoh]; {0, 0} + ]; + kernel = OptionValue[Kernel][n]/n; + style = OptionValue[PlotStyle]; + counts = binCounts[data, {min, max, dx}]; + If[!OptionValue[PlotCounts], counts = counts/(dx * Length[data])]; + padding = ConstantArray[0, Length[counts]]; + If[olo == 0, padding[[-(n - 1) ;; All]] = Reverse[counts[[1 ;; n - 1]]]]; + If[ohi == 0, padding[[1 ;; n - 1]] = Reverse[counts[[-(n - 1) ;; All]]]]; + smoothed = ListConvolve[kernel, counts, {n - olo, ohi - n}, padding]; + Graphics[{ + If[style === Automatic, {}, style], + Line[Transpose[{ + Flatten[({#1, #1} & ) /@ Range[min - olo*dx, max + ohi*dx, dx]], + Join[{0}, Flatten[({#1, #1} & ) /@ smoothed], {0}] + }]] + }, + FilterRules[{opts}, Options[Graphics]], + Frame -> {True, True, False, False}, + AspectRatio -> 1/GoldenRatio, + PlotRange -> All, + PlotRangePadding -> Scaled[0.025] + ] + ] + +SmoothedHistogram[data_?VectorQ, dx_?NumericQ, n_Integer, + opts:OptionsPattern[]] := + Module[{min, max}, + min = Ceiling[Min[data] - dx, dx]; + max = Floor[Max[data] + dx, dx]; + SmoothedHistogram[data, {min, max, dx}, n, opts] + ] + +SmoothedHistogram[data_?VectorQ, dx_?NumericQ, opts:OptionsPattern[]] := + Module[{min, max}, + min = Ceiling[Min[data] - dx, dx]; + max = Floor[Max[data] + dx, dx]; + SmoothedHistogram[data, {min, max, dx}, 1, opts] + ] + +SmoothedHistogramFunction[data_?VectorQ, {min_, max_, dx_}, n_Integer, + opts:OptionsPattern[]] := + Module[{olo, ohi, kernel, counts, padding, smoothed}, + {olo, ohi} = + Switch[ + over = OptionValue[Overhang] /. {None -> 0, All -> n-1}, + 0, {0, 0}, + n - 1, {n-1, n-1}, + {_Integer, _Integer}, Min[Max[#1, 0], n - 1] & /@ over, + _, Message[SmoothedHistogram::badoh]; {0, 0} + ]; + kernel = OptionValue[Kernel][n]/n; + counts = binCounts[data, {min, max, dx}]/(dx * Length[data]); + padding = ConstantArray[0, Length[counts]]; + If[olo == 0, padding[[-(n - 1) ;; All]] = Reverse[counts[[1 ;; n - 1]]]]; + If[ohi == 0, padding[[1 ;; n - 1]] = Reverse[counts[[-(n - 1) ;; All]]]]; + smoothed = ListConvolve[kernel, counts, {n - olo, ohi - n}, padding]; + Interpolation[ + Join[ + {{min - olo*dx, 0}}, + Transpose[{Range[min - olo*dx + dx, max + ohi*dx, dx], smoothed}] + ], + InterpolationOrder -> 0 + ] + ] + +SmoothedHistogramFunction[data_?VectorQ, dx_?NumericQ, n_Integer, + opts:OptionsPattern[]] := + Module[{min, max}, + min = Ceiling[Min[data] - dx, dx]; + max = Floor[Max[data] + dx, dx]; + SmoothedHistogramFunction[data, {min, max, dx}, n, opts] + ] + +(* there is a bug in BinCounts[data, {min, max, dx}] version 6.0.1 *) +(* anyway this is faster *) +binCounts[data_?VectorQ, dx_] := + binCounts[data, { + Ceiling[Min[data] - dx, dx], + Floor[Max[data] + dx, dx], + dx + }] + +binCounts[data_?VectorQ, {min_, max_, dx_}] := + TallyToBinCounts[ + Tally[Floor[(data - min)/dx] + 1], + Length[Range[min, max, dx]] - 1 + ] + +TallyToBinCounts = + Compile[{ + {tally, _Integer, 2}, + {nbins, _Integer, 0} + }, + Module[{counts = Table[0, {nbins}]}, + Do[If[1 <= tally[[i, 1]] <= nbins, + counts[[ tally[[i, 1]] ]] = tally[[i, 2]]], + {i, Length[tally]}]; + counts + ]] + +(* +binCounts[data_, {min_, max_, dx_}] := + Module[{tally, nbins, counts}, + tally = Tally[Floor[(data - min)/dx] + 1]; + nbins = Length[Range[min, max, dx]] - 1; + counts = ConstantArray[0, nbins]; + Do[ + If[1 <= tally[[i, 1]] <= nbins, + counts[[ tally[[i, 1]] ]] = tally[[i, 2]]], + {i, Length[tally]}]; + counts + ] +*) + +binCounts[data_?MatrixQ, {min1_, max1_, dx1_}, {min2_, max2_, dx2_}] := + Module[{nbins, index, tally, counts}, + nbins = MapThread[Length[Range[#1, #2, #3]]& , + {{min1, min2}, {max1, max2}, {dx1, dx2}}] - 1; + index = Transpose[Floor[MapThread[(#1 - #2)/#3&, + {Transpose[data], {min1, min2}, {dx1, dx2}}]] + 1]; + tally = {First[#], Length[#]}& /@ Split[Sort[index]]; + counts = ConstantArray[0, nbins]; + Do[If[Min[tally[[i, 1]]] > 0 && Min[nbins - tally[[i, 1]]] >= 0, + counts[[ Sequence @@ tally[[i, 1]] ]] = tally[[i, 2]]], + {i, Length[tally]}]; + counts + ] + +binCounts[data_?MatrixQ, dx1_?NumericQ, dx2_?NumericQ] := + Module[{tdata, min1, min2, max1, max2}, + tdata = Transpose[data]; + {min1, min2} = MapThread[Ceiling[Min[#1] - #2, #2]&, {tdata, {dx1, dx2}}]; + {max1, max2} = MapThread[Floor[Max[#1] + #2, #2]&, {tdata, {dx1, dx2}}]; + binCounts[data, {min1, max1, dx1}, {min2, max2, dx2}] + ] + +binCounts[data_?MatrixQ, dx_?NumericQ] := binCounts[data, dx, dx] + +SmoothedHistogram[data_?MatrixQ, dx1_?NumericQ, dx2_?NumericQ, + opts:OptionsPattern[]] := + Module[{tdata, min1, min2, max1, max2}, + tdata = Transpose[data]; + {min1, min2} = MapThread[Ceiling[Min[#1] - #2, #2]&, {tdata, {dx1, dx2}}]; + {max1, max2} = MapThread[Floor[Max[#1] + #2, #2]&, {tdata, {dx1, dx2}}]; + SmoothedHistogram[data, {min1, max1, dx1}, {min2, max2, dx2}, opts] + ] + +SmoothedHistogram[data_?MatrixQ, dx_?NumericQ, opts:OptionsPattern[]] := + SmoothedHistogram[data, dx, dx, opts] + +(* Options[SmoothedHistogram] = Options[ListDensityPlot] *) + +SmoothedHistogram[data_?MatrixQ, {min1_, max1_, dx1_}, {min2_, max2_, dx2_}, + opts:OptionsPattern[]] := +ListDensityPlot[ + Transpose[binCounts[data, {min1, max1, dx1}, {min2, max2, dx2}]], + opts, + ColorFunction -> (GrayLevel[1 - #1^0.5] & ), + InterpolationOrder -> 0, + PlotRange -> All, + AspectRatio -> Automatic, + DataRange -> {{min1 + dx1/2, max1 - dx1/2}, {min2 + dx2/2, max2 - dx2/2}} + ] + +Options[GeneralizedMovingAverage] = + {Overhang -> None, Kernel -> TriweightKernel} + +GeneralizedMovingAverage[data_?VectorQ, n_, + opts:OptionsPattern[]] := + Module[{olo, ohi, kernel, padding}, + {olo, ohi} = + Switch[ + over = OptionValue[Overhang] /. {None -> 0, All -> n-1}, + 0, {0, 0}, + n-1, {n-1, n-1}, + {_Integer, _Integer}, Min[Max[#1, 0], n-1] & /@ over, + _, Message[SmoothedHistogram::badoh]; {0, 0} + ]; + kernel = OptionValue[Kernel][n]/n; + padding = ConstantArray[0, Length[data]]; + If[olo == 0, padding[[-(n - 1) ;; All]] = Reverse[data[[1 ;; n - 1]]]]; + If[ohi == 0, padding[[1 ;; n - 1]] = Reverse[data[[-(n - 1) ;; All]]]]; + ListConvolve[kernel, data, {n - olo, ohi - n}, padding] + ] diff --git a/MathematicaFiles/Applications/StandardNormal.m b/MathematicaFiles/Applications/StandardNormal.m new file mode 100755 index 0000000..7ae81f0 --- /dev/null +++ b/MathematicaFiles/Applications/StandardNormal.m @@ -0,0 +1,114 @@ +(* :Title: Standard Normal *) + +(* :Author: Mark Fisher *) + +(* :Mathematica Version: 6.0 *) + +(* :Context: `StandardNormal *) + +(* :Summary: Calculate standard normal deviates. *) + +(* :Discussion: +The current version of Mathematica (i.e. 3.0) does not compute normal +random variables efficiently. This package improves the efficiency +somewhat. The ideas used in this package are adopted from two guys from +California in a developer's workshop at Wolfram's headquarters in the fall +of 1997. Thanks guys. + +Updated for Version 5.0. Added StandardCauchy. + +Updated for Version 6.0. Replace Random[] with RandomReal[]. +*) + + +(* :Comment: +In Version 5.0, these uncompiled versions are almost as fast: + +StandardNormal[] := Sqrt[-2 Log[RandomReal[]]] * Cos[2 Pi RandomReal[]] +StandardNormal[n_Integer] := Table[StandardNormal[], {n}] +StandardNormal[n_Integer, m_Integer] := Table[StandardNormal[], {n}, {m}] +StandardNormal[n_Integer, cov_?MatrixQ] := + sn[n, Length[cov]].CholeskyDecomposition[cov] +StandardNormal[n_Integer, mean_?VectorQ, cov_?MatrixQ] := + Transpose[mean + Transpose[StandardNormal[n, cov]]] +*) + +(* :Requirements: For Mathematica versions prior to 5.0, +this package imports the standard package LinearAlgebra`Cholesky` *) + +BeginPackage["StandardNormal`"] + + +StandardNormal::usage = "StandardNormal[] returns a single \ +standard normal deviate. StandardNormal[n] returns a list of n \ +independent deviates. StandardNormal[n, m] returns an n by m matrix of \ +independent deviates. StandardNormal[n, cov] returns a list of n \ +standard normal deviates drawn from a multivariate standard normal \ +distribution with covariance matrix cov, where cov is a d-by-d \ +symetric matrix. StandardNormal[n, mean, cov] returns a list of n \ +normal deviates drawn from a multivariate normal distribution with \ +mean vector meam and covaraince matrix cov, where cov is a d-by-d \ +symetric, positive- definite matrix." + +StandardCauchy::usage = "StandardCauchy[] returns a single standard \ +Cauchy deviate. StandardCauchy[n] returns a list of n independent \ +deviates. To obtain draws from CauchyDistribution[a, b], multiply the \ +output of StandardCauchy by b and then add a." + +Begin["`Private`"] + +norm0 = Compile[{}, Sqrt[-2 Log[RandomReal[]]] Cos[2 Pi RandomReal[]]] + +norm1 = Compile[{{n, _Integer}}, + Table[Sqrt[-2 Log[RandomReal[]]] Cos[2 Pi RandomReal[]], {n}]] + +norm2 = Compile[{{n, _Integer}, {m, _Integer}}, + Table[Sqrt[-2 Log[RandomReal[]]] Cos[2 Pi RandomReal[]], {n}, {m}]] + +StandardNormal[] := norm0[] + +StandardNormal[n_Integer?Positive] := norm1[n] + +StandardNormal[n_Integer?Positive, m_Integer?Positive] := norm2[n, m] + +StandardNormal[n_Integer?Positive, cov_?(MatrixQ[#, NumericQ]&) /; + Transpose[cov] == cov && + And @@ (Positive /@ Eigenvalues[cov])] := + norm2[n, Length[cov]].CholeskyDecomposition[.5(cov + Transpose[cov])] + +StandardNormal[n_, mean_, cov_] := + Transpose[mean + Transpose[StandardNormal[n, cov]]] + +StandardCauchy[] := Tan[(Pi /2)(2 RandomReal[] - 1)] +StandardCauchy[n_Integer] := Table[StandardCauchy[], {n}] + + +(***** newer version that uses both deviates *****) +stdnorm1 = Compile[{{n, _Integer}}, + Take[#, n]& @ Flatten[ + Table[ + With[{x1 = Sqrt[-2*Log[RandomReal[]]], x2 = 2*Pi*RandomReal[]}, + {x1*Cos[x2], x1*Sin[x2]} + ], + {Ceiling[n/2]} + ] + ] + ] + +(* redefinitions *) +StandardNormal[1] := {norm0[]} + +StandardNormal[n_Integer?Positive] := stdnorm1[n] + +StandardNormal[n_Integer?Positive, m_Integer?Positive] := + Partition[stdnorm1[n * m], m] + +StandardNormal[n_Integer?Positive, cov_?(MatrixQ[#, NumericQ]&) /; + Transpose[cov] == cov && + And @@ (Positive /@ Eigenvalues[cov])] := + StandardNormal[n, Length[cov]]. + CholeskyDecomposition[.5(cov + Transpose[cov])] + + +End[] +EndPackage[] diff --git a/MathematicaFiles/Applications/StatisticalStuff.m b/MathematicaFiles/Applications/StatisticalStuff.m new file mode 100755 index 0000000..078977f --- /dev/null +++ b/MathematicaFiles/Applications/StatisticalStuff.m @@ -0,0 +1,82 @@ +(* This will generate random covariance matrix for which the variances +have mean 1 and the covariances have mean 0. This can be used as a proposal +distribution for a Metropolis sampler. *) + +rancov[n_] := + With[{u = Table[ + If[i > j, 0, RandomReal[NormalDistribution[0, 1/i^2]]], {i, n}, {j, n}]}, + Transpose[u].u + ] + +MultivariateGaussianLikelihood::usage = "MultivariateGaussianLikelihood[data, \ +mu, sigma] take a matrix of data, a vector parameter mu, and a matrix \ +parameter sigma and returns the likelihood." + +MultivariateGaussianLikelihood::baddim = "There is an inconsistency among \ +the dimensions of the data and the parameters." +MultivariateGaussianLikelihood::badsym = "The covariance matrix is not symmetric." + +MultivariateGaussianLikelihood[ + data_?MatrixQ, + mu_?VectorQ, + Sigma_?MatrixQ + ] := + Module[{n, d, S0}, + {n, d} = Dimensions[data]; + If[Length[mu] != d || Dimensions[Sigma] != {d, d}, + Message[MultivariateGaussianLikelihood::baddim]; Return[$Failed]]; + If[!TrueQ[Sigma == Transpose[Sigma]], + Message[MultivariateGaussianLikelihood::badsym]; Return[$Failed]]; + S0 = Sum[Outer[Times, data[[i]] - mu, data[[i]] - mu], {i, n}]; + Exp[-Tr[Inverse[Sigma].S0]/2]/((2*Pi)^d*Det[Sigma])^(n/2) + ] + +GaussianRegressionLikelihood::usage = "GaussianRegressionLikelihood[data, \ +beta, sigma] takes a matrix of data, a vector of regression coefficients, \ +and a residual variance matrix and returns the likelihood. The residual \ +variance can be given as a vector (specifying a diagonal matrix) or as a \ +scalar (specifying a diagonal matrix with a constant on the diagonal)." + +GaussianRegressionLikelihood::badbeta = "There is an inconsistency \ +between the length of the beta vector and the dimensions of the data." + +GaussianRegressionLikelihood[ + data_?MatrixQ, + beta_?VectorQ, + sigma_?MatrixQ + ] := + Module[{n, d, beta0, beta1, data1}, + {n, d} = Dimensions[data]; + If[!(d-1 <= Length[beta] <= d), + Message[GaussianRegressionLikelihood::badbeta]; Return[$Failed] + ]; + If[Length[beta] == d, + beta0 = First[beta]; beta1 = Rest[beta], + beta0 = 0; beta1 = beta + ]; + mu = beta0 * Table[1, {n}]; + data1 = DiagonalMatrix[data.Append[-beta1, 1]]; + MultivariateGaussianLikelihood[data1, mu, sigma] + ] + +GaussianRegressionLikelihood[ + data_?MatrixQ, + beta_?VectorQ, + sigma_?VectorQ + ] := + GaussianRegressionLikelihood[ + data, + beta, + DiagonalMatrix[sigma] + ] + +GaussianRegressionLikelihood[ + data_?MatrixQ, + beta_?VectorQ, + sigma_ + ] := + GaussianRegressionLikelihood[ + data, + beta, + sigma * IdentityMatrix[Length[data]] + ] diff --git a/MathematicaFiles/Applications/StatisticsEnhancements.m b/MathematicaFiles/Applications/StatisticsEnhancements.m new file mode 100755 index 0000000..e7025b0 --- /dev/null +++ b/MathematicaFiles/Applications/StatisticsEnhancements.m @@ -0,0 +1,429 @@ +(* enhancements for statistics/random stuff *) + +(* Needs["Statistics`"] *) + +Benford::usage = "Benford[n] = Log[10,(n+1)/n] for positive integer n. \ +Benford[{d1, d2, ..., dn}] computes the probability of the (base 10) \ +digits according Benford's distribution." + +Benford[d_] := Log[10, (d + 1)/d] + +Benford[(d_)?(VectorQ[#1, Function[x, MemberQ[Range[0, 9], x]]] & ) /; + First[d] >= 1] := + Benford[FromDigits[d]] + +(* extend CDF and PDF for location and scale *) +Unprotect[CDF,PDF] +CDF[dist_, var_, {loc_, scale_}] := CDF[dist, (var - loc)/scale] +PDF[dist_, var_, {loc_, scale_}] := PDF[dist, (var - loc)/scale]/scale +PDF[dist_, var_?VectorQ, {loc_?VectorQ, scale_?MatrixQ}] := + PDF[dist, Inverse[scale].(var - loc)]/Det[scale] +PDF[dist_, var_?VectorQ, {loc_, scale_}] := + With[{n = Length[var]}, + PDF[dist, (var - loc)/Table[scale, {n}]]/scale^n + ] +Protect[CDF,PDF] + +GaussianLikelihood::usage = "GaussianLikelihood[data, {mu, sigma}] returns the \ +likelihood of mu and sigma using the Gaussian distribution assuming independent \ +data." +GaussianLikelihood[data_, {m_, s_}] := + With[{n = Length[data], sum = Plus @@ data, sumsq = Plus @@ (data^2)}, + Exp[-(n m^2 - 2 m sum + sumsq)/(2s^2)]/(Sqrt[2]^n Pi^(n/2)s^n) + ] + +(* to pass distribution to KolmogorovSmirnov *) +Off[StudentTDistribution::argx] +Unprotect[StudentTDistribution] + +StudentTDistribution /: + PDF[StudentTDistribution[n_, location_, scale_], x_] := + PDF[StudentTDistribution[n], (x - location)/scale]/scale + +StudentTDistribution /: + CDF[StudentTDistribution[n_, location_, scale_], x_] := + CDF[StudentTDistribution[n], (x - location)/scale] + +Protect[StudentTDistribution] +On[StudentTDistribution::argx] + + +(* random shuffle by Daniel Lichtblau; + returns a random permutation of the first n natural numbers *) +shuffleC = Compile[{{n, _Integer}}, + Module[{res = Range[n], tmp, rand}, + Do[ + rand = Random[Integer, {j, n}]; + tmp = res[[j]]; + res[[j]] = res[[rand]]; + res[[rand]] = tmp, + {j, n}]; + res]] + +(* modification that returns the first m values *) +RandomIntegerWithoutReplacement::usage = +"RandomIntegerWithoutReplacement[m, n] returns m distinct random integers \ +<= n. RandomIntegerWithoutReplacement[n] returns a random permutation \ +of the the first n positive integers." + +RandomIntegerWithoutReplacement[m_Integer?Positive, n_Integer?Positive] /; + (m <= n) := randomIntegerWithoutReplacement[m, n] +RandomIntegerWithoutReplacement[n_Integer?Positive] := shuffleC[n] +RandomIntegerWithoutReplacement[___] := $Failed + + +randomIntegerWithoutReplacement = + Compile[{{m, _Integer}, {n, _Integer}}, + Module[{res = Range[n], tmp, rand}, + Do[rand = Random[Integer, {j, n}]; + tmp = res[[j]]; + res[[j]] = res[[rand]]; + res[[rand]] = tmp, + {j, m}]; + Take[res, m]] + ] + +(* Random draws without replacement; + usage: RandomWithoutReplacement[Random[Integer, {1, 10}], 5] +*) + +RandomWithoutReplacement::usage = +"RandomWithoutReplacement[ran, n] returns n draws without \ +replacement using ran. For example, \ +RandomWithoutReplacement[Random[Integer, {1, 10}], 5]" + +SetAttributes[RandomWithoutReplacement, HoldFirst] + +RandomWithoutReplacement[ran_, n_Integer?Positive] := + Module[{list = {}, r}, + While[Length[list] < n, If[FreeQ[list, r = ran], AppendTo[list, r]]]; + list + ] + +(***** + Basic RNG + Stephen K. Park and Keith W. Miller, + "Random Number Generators: Good Ones Are Hard to Find," + Communications of the ACM, 31:10 (October, 1988), 1192-1201. +*****) +BasicRandomSeed = Mod[Round[AbsoluteTime[]], 2147483647]; + +BasicRandomInteger[] := + BasicRandomSeed = Mod[16807 * BasicRandomSeed, 2147483647] + +BasicRandomInteger[n_Integer?Positive] := Table[BasicRandomInteger[], {n}] + +BasicRandomReal[] := BasicRandomInteger[]/2147483647. + +BasicRandomReal[n_Integer] := BasicRandomInteger[n]/2147483647. + +(***** portable RNG; Jerry Dwyer's random number generator *****) + +SeedPortableRNG[n_Integer] := + ($randomY = n; + $randomZ = Mod[64155 * $randomY, 214783629];) + +SeedPortableRNG[] := SeedPortableRNG[Random[Integer, {1, 214783629}]] + +(* initialize *) +SeedPortableRNG[] + +PortableRNGInteger[] := + Mod[($randomY = Mod[64155 * $randomY, 214783629]) - + ($randomZ = Mod[10064 * $randomZ, 2147483543]), + 214783629] + +PortableRNGInteger[n_Integer?Positive] := Table[PortableRNGInteger[], {n}] + +PortableRNG[] := (PortableRNGInteger[] - 1.)/214783629 + +PortableRNG[n_Integer?Positive] := (Table[PortableRNGInteger[], {n}] - 1.)/214783629 + +(* +{$multiplierY, $modulusY, $multiplierZ, $modulusZ} = + {64155, 214783629, 10064, 2147483543}; + +SeedPortableRNG[n_Integer] := + ($randomY = n; + $randomZ = Mod[$multiplierY * $randomY, $modulusY];) + +SeedPortableRNG[] := SeedPortableRNG[Random[Integer, {1, $modulusY}]] + +PortableRNGInteger[] := + Mod[($randomY = Mod[$multiplierY * $randomY, $modulusY]) - + ($randomZ = Mod[$multiplierZ * $randomZ, $modulusZ]), + $modulusY] + +PortableRNG[n_Integer?Positive] := (PortableRNGInteger[n]-1.)/$modulusY + +PortableRNG[] := (PortableRNGInteger[]-1.)/$modulusY + +*) +(***** end portable RNG *****) + +(* next function compiles Piecewise to compute discrete random deviates *) + +MakeDiscreteRandomFunction::usage = "MakeDiscreteRandomFunction[probs, \ +vals] returns a compiled function that generates a list of n discrete \ +random numbers. For example, let ranfun = MakeDiscreteRandomFunction[{.25, \ +.25, .5}, {1, 2, 3}]. Then ranfun[10] returns 10 draws of 1, 2, and 3 with \ +the appropriate frequencies. If omitted, the default the list of values is \ +Range[Length[probs]]. The probs need not be normalized. (Requires Version \ +5.1.)" + +MakeDiscreteRandomFunction[probs_, vals_] := + With[{ + fun = Block[{x}, + Function @@ {x, Piecewise @ + Transpose[{vals, + x <= # & /@ (Rest @ FoldList[Plus, 0, probs/Tr[probs]])}]} + ]}, + Compile[{{n, _Integer}}, + fun /@ Table[Random[], {n}] + ] + ] + +MakeDiscreteRandomFunction[probs_] := + MakeDiscreteRandomFunction[probs, Range[Length[probs]]] + + +(* +MakeDiscreteRandomFunction[probs_, vals_] := + Block[{x}, Compile @@ {x, + Piecewise @ Transpose[{vals, x <= # & /@ (Rest @ FoldList[Plus, 0, probs])}] + } + ] + +MakeDiscreteRandomFunction[probs_, vals_] := + Block[{x, Random}, + With[{fun = Function @@ {x, Piecewise@Transpose[{vals, + x <= # & /@ (Rest@FoldList[Plus, 0, probs])}]}}, + Compile[{}, fun[Random[]]] + ]] + +MakeDiscreteRandomFunction[probs_, vals_] := + Block[{x, Random}, + With[{fun = Function @@ {x, Piecewise@Transpose[{vals, + x <= # & /@ (Rest@FoldList[Plus, 0, probs])}]}}, + Compile[{{n,_Integer}}, fun/@Table[Random[],{n}]] + ]] +*) + +(* Make inverse of cdf function for RNG from discrete pdf function; + adapted from Rose and Smith + usage: cf = MakeInverseCDF[f[#]&] + cf[Random[]] +*) +Options[MakeInverseCDF] = {MinimumValue -> 1, TailCutoff -> 10^-6} + +MakeInverseCDF[pdf_Function, opts___?OptionQ] := + With[{ + start = MinimumValue /. {opts} /. Options[MakeInverseCDF], + tail = TailCutoff /. {opts} /. Options[MakeInverseCDF]}, + With[{ + F = Block[{i = start}, + FixedPointList[ + N[ # + pdf[i++] ]&, 0, SameTest -> (1 - #2 < tail &)]] + }, + Block[{j = start}, + Compile[u, + Evaluate[ + Which @@ Flatten[Append[ + MapThread[{#1 < u < #2, j++} &, {Drop[F, -1], Rest[F]}], + {True, j - 1}]] + ] + ] + ] + ]] + +(* work arounds for bugs in earlier versions *) +If[$VersionNumber < 5.0, + +(* work around a bug in Random[] to generate geometric deviates; + the default method relies on absence of conditional serial + correlation for Random[] *) +Needs["Statistics`DiscreteDistributions`"]; +Statistics`DiscreteDistributions`Private`geometric = + Compile[{p}, Floor[Log[1 - Random[]]/Log[1 - p]]]; + +(* work around a bug in Random[Integer, n] for some large values of n *) +RandomInteger[n_] := + Round[n * Random[Real, 1, Max[$MachinePrecision + 1, Log[10, n]]]] + ] + +HighestDensityInterval::usage = "HighestDensityInterval[data, \ +percentIncluded] returns a pair of numbers that represent the lower and \ +upper bounds of the highest density region for one-dimensional data \ +(assuming the density is unimodal). A third optional argument is the number \ +of grid steps to take is determining the minimum interval length." + +HighestDensityInterval[data_List, percentIncluded_:.9, steps_Integer:100]:= + Module[{dx, quantiles, len, pos}, + dx = (1 - percentIncluded)/steps; + quantiles = Table[Quantile[data, {i*dx, percentIncluded + i*dx}], {i, 0, steps}]; + len = -Subtract @@@ quantiles; + pos = Floor[Median[Flatten[Position[len, Min[len]]]]]; + quantiles[[ pos ]] + ] + +CountPositions::usage = "CountPositions[poslist, n] is a compiled version \ +of Table[Count[poslist, i], {i, n}] where poslist is a list of integers \ +(that could represent positions). CountPositions is the inverse of \ +PositionCounts." + +CountPositions[poslist_List, n_Integer?Positive] := + countPositionsC[poslist, n] + +countPositionsC = + Compile[{{poslist, _Integer, 1}, {n, _Integer, 0}}, + Table[Count[poslist, i], {i, n}] + ] + +PositionCounts::usage = "PositionCounts[counts] returns the positions \ +represented by the list of counts. PositionCounts is the inverse of \ +CountPositions." + +PositionCounts[counts_?(VectorQ[#, IntegerQ]&)] := + Flatten[MapIndexed[Table[#2[[1]], {#1}]&, counts]] + +CountIntegerList::usage = "CountIntegerList[data, list] returns a list of \ +counts of the elements of data with respect to each element of list, where \ +both data and list are lists of integers. CountIntegerList[data, n] \ +computes CountIntegerList[data, Range[n]]." + +CountIntegerList[data:{__Integer}, list:{__Integer}] := + countIntegerListC[data, list] + +CountIntegerList[data:{__Integer}, n_Integer?Positive] := + countIntegerListC[data, Range[n]] + +countIntegerListC = Compile[{{data, _Integer, 1}, {list, _Integer, 1}}, + Count[data, #] & /@ list + ] + +(* +RandomMultinomial::usage = "RandomMultinomial[n, w] returns a draw from +MultinomialDistribution[n, w]." + +RandomMultinomial[n_, w_] := + countPositionsC[MakeDiscreteRandomFunction[w][n], n] + +RandomArrayMultinomial::usage = "RandomArrayMultinomial[n, w, reps] return +reps draws from MultinomialDistribution[n, w]." + +RandomArrayMultinomial[n_, w_, reps_] := + With[{ + fun = MakeDiscreteRandomFunction[w] + }, + Table[ + countPositionsC[fun[n], n], + {reps} + ] + ] + +*) + +(* obsolete +RandomArrayMultinomial[n_, w_, reps_] := + With[{ + zero = Table[0, {Length[w]}], + fun = MakeDiscreteRandomFunction[w]}, + Module[{list}, + Table[ + list = zero; + list[[#]]++ & /@ fun[n]; + list, + {reps}] + ]] +*) +(* obsolete +RandomMultinomial[n_, w_] := + Module[{list = Table[0, {Length[w]}]}, + list[[#]]++ & /@ MakeDiscreteRandomFunction[w][n]; + list + ] +*) + + +(* there is a problem with the built in Random(Array)[Multinominal[ ... ]] *) + +MultiNomialDistribution::usage = "MultiNomialDistribution[n, w] is a \ +replacement for MultinomialDistribtion[n, w] in Random and RandomArray. \ +(There is a problem with MultinomialDistribtution in these applications." + +MultiNomialDistribution /: + Random[MultiNomialDistribution[n_Integer?Positive, w_?VectorQ]] := + countIntegerListC[MakeDiscreteRandomFunction[w][n], Range[Length[w]]] + +MultiNomialDistribution /: + RandomArray[MultiNomialDistribution[n_Integer?Positive, w_?VectorQ], + reps_Integer?Positive] := + With[{ + fun = MakeDiscreteRandomFunction[w], + list = Range[Length[w]] + }, + Table[ + countIntegerListC[fun[n], list], + {reps} + ] + ] + + +Autocorrelations::usage = "Autocorrelations[data, maxlag] returns a list of \ +autocorrelations of the data beginning with lag 1 and ending with maxlag." + +Autocorrelations::lag2long = "Too many lags. Reduce maxlag to `` or less." + +Autocorrelations[data_?VectorQ, maxlag_Integer?Positive] := + Table[Correlation[Take[data, {1 + i, -1}], Take[data, {1, -(1 + i)}]], + {i, 1, maxlag}] /; maxlag <= Length[data] - 3 + +Autocorrelations[data_?VectorQ, _Integer?Positive] := + (Message[Autocorrelations::lag2long, Length[data] - 3]; + $Failed) + +PlotAutocorrelations[data_?VectorQ, maxlag_Integer?Positive, opts___?OptionQ] := + With[{auto = Autocorrelations[data, maxlag]}, + If[auto === $Failed, + $Failed, + ListPlot[auto, opts, PlotJoined -> True] + ] + ] + +(* incorporated into StandardNormal *) +(* +StdNorm[n_Integer?Positive] := stdnorm1[n] + +StdNorm[n_Integer?Positive, m_Integer?Positive] := + Partition[stdnorm1[n * m], m] + +stdnorm1 = Compile[{{n, _Integer}}, + If[OddQ[n], Rest[#], #]& @ Flatten[ + Table[ + With[{x1 = Sqrt[-2*Log[Random[]]], x2 = 2*Pi*Random[]}, + {x1*Cos[x2], x1*Sin[x2]} + ], + {Ceiling[n/2]} + ] + ] + ] +*) + +(* +stdnorm2 = Function[{n, m}, Partition[stdnorm1[n * m], m]] + +stdnorm2 = Compile[{{n, _Integer}, {m, _Integer}}, + Partition[ + If[OddQ[n * m], Rest[#], #]& @ Flatten[ + Table[ + With[{x1 = Sqrt[-2*Log[Random[]]], x2 = 2*Pi*Random[]}, + {x1 *Cos[x2], x1*Sin[x2]} + ], + {Ceiling[(n * m)/2]} + ] + ], + m] + ] +*) + + diff --git a/MathematicaFiles/Applications/The Virtual Mathematica Book (v6).nb b/MathematicaFiles/Applications/The Virtual Mathematica Book (v6).nb new file mode 100755 index 0000000..ce81d2c --- /dev/null +++ b/MathematicaFiles/Applications/The Virtual Mathematica Book (v6).nb @@ -0,0 +1,13110 @@ +(* Content-type: application/mathematica *) + +(*** Wolfram Notebook File ***) +(* http://www.wolfram.com/nb *) + +(* CreatedBy='Mathematica 6.0' *) + +(*CacheID: 234*) +(* Internal cache information: +NotebookFileLineBreakTest +NotebookFileLineBreakTest +NotebookDataPosition[ 145, 7] +NotebookDataLength[ 428471, 13100] +NotebookOptionsPosition[ 373437, 11745] +NotebookOutlinePosition[ 373849, 11761] +CellTagsIndexPosition[ 373806, 11758] +WindowFrame->Normal +ContainsDynamic->False*) + +(* Beginning of Notebook Content *) +Notebook[{ + +Cell[CellGroupData[{ +Cell["The Virtual Mathematica Book (v6)", "Title"], + +Cell["\<\ +A collection of links to the tutorials present in the Mathematica 6.0 \ +Documentation Center, arranged in the order of chapters in \"The Mathematica \ +Book\".\ +\>", "Author"], + +Cell[CellGroupData[{ + +Cell["A practical introduction to Mathematica", "Subtitle", + ShowGroupOpener->True, + CellMargins->{{Inherited, Inherited}, {15, 30}}], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Running Mathematica\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/RunningMathematicaOverview"], + Evaluator->Automatic, + Method->"Preemptive"]], "Section", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Notebook Interfaces\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NotebookInterfaces"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Text\[Hyphen]Based Interfaces\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/TextBasedInterfaces"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Basic Editing Techniques\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/BasicEditingTechniquesOverview"], + Evaluator->Automatic, + Method->"Preemptive"]], "Section", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Moving through Expressions\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/MovingThroughExpressions"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Selecting and Deleting in Expressions\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/SelectingAndDeletingInExpressions"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Entering Two-Dimensional Expressions\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/EnteringTwoDimensionalExpressionsOverview"], + Evaluator->Automatic, + Method->"Preemptive"]], "Section", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Typing Fractions\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup["paclet:tutorial/TypingFractions"], + + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Typing Powers\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup["paclet:tutorial/TypingPowers"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Typing Square Roots\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/TypingSquareRoots"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Typing Radicals\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup["paclet:tutorial/TypingRadicals"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Typing Vectors\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup["paclet:tutorial/TypingVectors"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Typing Matrices\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup["paclet:tutorial/TypingMatrices"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Typing Superscripts\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/TypingSuperscripts"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Typing Subscripts\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/TypingSubscripts"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Typing Overscripts\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/TypingOverscripts"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Typing Underscripts\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/TypingUnderscripts"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Numerical Calculations\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NumericalCalculationsOverview"], + Evaluator->Automatic, + Method->"Preemptive"]], "Section", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Arithmetic\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup["paclet:tutorial/Arithmetic"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Exact and Approximate Results\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ExactAndApproximateResults"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Some Mathematical Functions\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/SomeMathematicalFunctions"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Arbitrary\[Hyphen]Precision Calculations\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ArbitraryPrecisionCalculations"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Complex Numbers\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup["paclet:tutorial/ComplexNumbers"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Getting Used to Mathematica\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/GettingUsedToMathematica"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Mathematical Notation in Notebooks\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/MathematicalNotationInNotebooks-NumericalCalculations"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Building Up Calculations\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/BuildingUpCalculationsOverview"], + Evaluator->Automatic, + Method->"Preemptive"]], "Section", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Using Previous Results\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/UsingPreviousResults"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Defining Variables\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/DefiningVariables"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Making Lists of Objects\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/MakingListsOfObjects"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Manipulating Elements of Lists\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ManipulatingElementsOfLists"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"The Four Kinds of Bracketing in Mathematica\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/TheFourKindsOfBracketingInMathematica"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Sequences of Operations\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/SequencesOfOperations"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Using the Mathematica System\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/UsingTheMathematicaSystemOverview"], + Evaluator->Automatic, + Method->"Preemptive"]], "Section", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"The Structure of Mathematica\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/TheStructureOfMathematica"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Differences between Computer Systems\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/DifferencesBetweenComputerSystems"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Using a Text\[Hyphen]Based Interface\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/UsingATextBasedInterface"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Doing Computations in Notebooks\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/DoingComputationsInNotebooks"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Notebooks as Documents\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NotebooksAsDocuments"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Hyperlinks and Active Text\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/HyperlinksAndActiveText"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Getting Help with a Text\[Hyphen]Based Interface\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/GettingHelpWithATextBasedInterface"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Mathematica Packages\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/MathematicaPackages"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Warnings and Messages\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/WarningsAndMessages"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Interrupting Calculations\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/InterruptingCalculations"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Algebraic Calculations\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/AlgebraicCalculationsOverview"], + Evaluator->Automatic, + Method->"Preemptive"]], "Section", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Symbolic Computation\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/SymbolicComputation"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Values for Symbols\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ValuesForSymbols"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Transforming Algebraic Expressions\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/TransformingAlgebraicExpressions"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Simplifying Algebraic Expressions\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/SimplifyingAlgebraicExpressions"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Putting Expressions into Different Forms\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/PuttingExpressionsIntoDifferentForms"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Simplifying with Assumptions\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/SimplifyingWithAssumptions"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Picking Out Pieces of Algebraic Expressions\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/PickingOutPiecesOfAlgebraicExpressions"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Controlling the Display of Large Expressions\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ControllingTheDisplayOfLargeExpressions"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"The Limits of Mathematica\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/TheLimitsOfMathematica"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Using Symbols to Tag Objects\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/UsingSymbolsToTagObjects"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Symbolic Mathematics\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/SymbolicMathematicsOverview"], + Evaluator->Automatic, + Method->"Preemptive"]], "Section", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Basic Operations\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/SymbolicMathematics-BasicOperations"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Integration\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup["paclet:tutorial/Integration"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Sums and Products\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup["paclet:tutorial/SumsAndProducts"], + + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Equations\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup["paclet:tutorial/Equations"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Relational and Logical Operators\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/RelationalAndLogicalOperators"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Solving Equations\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/SolvingEquations"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Inequalities\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/Inequalities-SymbolicMathematics"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Differential Equations\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/DifferentialEquations-Basics"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Power Series\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup["paclet:tutorial/PowerSeries"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Limits\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup["paclet:tutorial/Limits"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Integral Transforms\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/IntegralTransforms"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Generic and Non\[Hyphen]Generic Cases\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/GenericAndNonGenericCases"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Mathematical Notation in Notebooks\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/MathematicalNotationInNotebooks-SymbolicMathematics"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Numerical Mathematics\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NumericalMathematicsOverview"], + Evaluator->Automatic, + Method->"Preemptive"]], "Section", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Basic Operations\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NumericalMathematics-BasicOperations"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Numerical Sums, Products and Integrals\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NumericalSumsProductsAndIntegrals"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Numerical Equation Solving\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NumericalEquationSolving"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Numerical Differential Equations\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NumericalDifferentialEquations"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Manipulating Numerical Data\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ManipulatingNumericalData"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Functions and Programs\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/FunctionsAndProgramsOverview"], + Evaluator->Automatic, + Method->"Preemptive"]], "Section", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Defining Functions\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/DefiningFunctions"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Functions as Procedures\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/FunctionsAsProcedures"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Repetitive Operations\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/RepetitiveOperations"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Transformation Rules for Functions\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/TransformationRulesForFunctions"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Lists\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup["paclet:tutorial/ListsOverview"], + Evaluator->Automatic, + Method->"Preemptive"]], "Section", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Collecting Objects Together\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/CollectingObjectsTogether"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Making Tables of Values\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/MakingTablesOfValues"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Vectors and Matrices\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/VectorsAndMatrices"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Getting Pieces of Lists\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/GettingPiecesOfLists"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Testing and Searching List Elements\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/TestingAndSearchingListElements"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Adding, Removing and Modifying List Elements\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/AddingRemovingAndModifyingListElements"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Combining Lists\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup["paclet:tutorial/CombiningLists"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Lists as Sets\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup["paclet:tutorial/ListsAsSets"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Rearranging Lists\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/RearrangingLists"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Grouping and Combining Elements of Lists\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/GroupingAndCombiningElementsOfLists"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Ordering in Lists\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup["paclet:tutorial/OrderingInLists"], + + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Rearranging Nested Lists\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/RearrangingNestedLists"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Graphics and Sound\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/GraphicsAndSoundOverview"], + Evaluator->Automatic, + Method->"Preemptive"]], "Section", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Basic Plotting\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup["paclet:tutorial/BasicPlotting"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Options for Graphics\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup["paclet:tutorial/Options"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Redrawing and Combining Plots\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/RedrawingAndCombiningPlots"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Manipulating Options\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ManipulatingOptions"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Three\[Hyphen]Dimensional Surface Plots\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ThreeDimensionalSurfacePlots"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Plotting Lists of Data\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/PlottingListsOfData"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Parametric Plots\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup["paclet:tutorial/ParametricPlots"], + + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Some Special Plots\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/SomeSpecialPlots"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Sound\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup["paclet:tutorial/Sound"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Editing Mathematica Graphics\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/InteractiveGraphicsOverview"], + Evaluator->Automatic, + Method->"Preemptive"]], "Section", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Introduction\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/IntroductionToInteractiveGraphics"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Drawing Tools\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/InteractiveGraphicsPalette"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Selecting Graphics Objects\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/InteractiveGraphicsSelecting"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Selecting an Object\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/InteractiveGraphicsSelecting#19275731"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Selecting Multiple Objects\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/InteractiveGraphicsSelecting#425631810"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Copy and Paste\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/InteractiveGraphicsSelecting#69452175"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Inset Objects\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/InteractiveGraphicsSelecting#22436782"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Reshaping Graphics Objects\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/InteractiveGraphicsReshaping"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Pointers\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/InteractiveGraphicsReshaping#377569141"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Vertices and Circle Points\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/InteractiveGraphicsReshaping#304872873"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Line Segments\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/InteractiveGraphicsReshaping#183967963"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Primitives\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/InteractiveGraphicsReshaping#622918205"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Reshaping Overlapping Objects\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/InteractiveGraphicsReshaping#223368799"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Multiple Objects\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/InteractiveGraphicsReshaping#158252894"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Resizing, Cropping, and Adding Margins to Graphics\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/InteractiveGraphicsLayout"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Changing the AspectRatio\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/InteractiveGraphicsLayout#13473268"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Cropping\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/InteractiveGraphicsLayout#657801144"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Setting Margins\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/InteractiveGraphicsLayout#27684169"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[BoxData[ + ButtonBox["\<\"Graphics as Input\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/InteractiveGraphicsDirectOutput"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Interacting with 3D Graphics\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/InteractiveGraphics3DInteraction"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Rotate\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/InteractiveGraphics3DInteraction#181090781"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Rotate about the axis perpendicular to the screen\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/InteractiveGraphics3DInteraction#403348457"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Zoom in and out with \[AltKey]\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/InteractiveGraphics3DInteraction#194874130"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Pan with \[ShiftKey]\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/InteractiveGraphics3DInteraction#48613871"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True] +}, Closed]] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Input and Output in Notebooks\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/InputAndOutputInNotebooksOverview"], + Evaluator->Automatic, + Method->"Preemptive"]], "Section", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Entering Greek Letters\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/EnteringGreekLetters"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Entering Two\[Hyphen]Dimensional Input\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/EnteringTwoDimensionalInput"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Editing and Evaluating Two\[Hyphen]Dimensional \ +Expressions\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/EditingAndEvaluatingTwoDimensionalExpressions"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Entering Formulas\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/EnteringFormulas"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Entering Tables and Matrices\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/EnteringTablesAndMatrices"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Subscripts, Bars and Other Modifiers\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/SubscriptsBarsAndOtherModifiers"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Non\[Hyphen]English Characters and Keyboards\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NonEnglishCharactersAndKeyboards"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Other Mathematical Notation\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/OtherMathematicalNotation"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Mixing Text and Formulas\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/MixingTextAndFormulas"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Displaying and Printing Mathematica Notebooks\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/DisplayingAndPrintingMathematicaNotebooks"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Setting Up Hyperlinks\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/SettingUpHyperlinks"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Automatic Numbering\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/AutomaticNumbering"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Exposition in Mathematica Notebooks\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ExpositionInMathematicaNotebooks"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Files and External Operations\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/FilesAndExternalOperationsOverview"], + Evaluator->Automatic, + Method->"Preemptive"]], "Section", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Reading and Writing Mathematica Files: Basics\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ReadingAndWritingMathematicaFiles-Basics"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Finding and Manipulating Files\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/FindingAndManipulatingFiles"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Importing and Exporting Data\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ImportingAndExportingData"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Exporting Graphics and Sounds\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ExportingGraphicsAndSounds"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Generating and Importing TeX\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/GeneratingAndImportingTeX"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Exchanging Material with the Web\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ExchangingMaterialWithTheWeb"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Generating C and Fortran Expressions\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/GeneratingCAndFortranExpressions"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Splicing Mathematica Output into External Files\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/SplicingMathematicaOutputIntoExternalFiles"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Running External Programs\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/RunningExternalPrograms"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"MathLink\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup["paclet:tutorial/MathLink"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"The Internals of Mathematica\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/TheInternalsOfMathematicaOverview"], + Evaluator->Automatic, + Method->"Preemptive"]], "Section", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Why You Do Not Usually Need to Know about Internals\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/WhyYouDoNotUsuallyNeedToKnowAboutInternals"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Basic Internal Architecture\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/BasicInternalArchitecture"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"The Algorithms of Mathematica\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/TheAlgorithmsOfMathematica"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"The Software Engineering of Mathematica\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/TheSoftwareEngineeringOfMathematica"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Testing and Verification\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/TestingAndVerification"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True] +}, Closed]] +}, Closed]], + +Cell[CellGroupData[{ + +Cell["Principles of Mathematica", "Subtitle", + ShowGroupOpener->True, + CellMargins->{{Inherited, Inherited}, {15, 30}}], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Expressions\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ExpressionsOverview"], + Evaluator->Automatic, + Method->"Preemptive"]], "Section", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Everything Is an Expression\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/EverythingIsAnExpression"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"The Meaning of Expressions\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/TheMeaningOfExpressions"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Special Ways to Input Expressions\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/SpecialWaysToInputExpressions"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Parts of Expressions\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/PartsOfExpressions"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Manipulating Expressions like Lists\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ManipulatingExpressionsLikeLists"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Expressions as Trees\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ExpressionsAsTrees"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Levels in Expressions\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LevelsInExpressions"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Functional Operations\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/FunctionalOperationsOverview"], + Evaluator->Automatic, + Method->"Preemptive"]], "Section", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Function Names as Expressions\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/FunctionNamesAsExpressions"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Applying Functions Repeatedly\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ApplyingFunctionsRepeatedly"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Applying Functions to Lists and Other Expressions\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ApplyingFunctionsToListsAndOtherExpressions"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Applying Functions to Parts of Expressions\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ApplyingFunctionsToPartsOfExpressions"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Pure Functions\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup["paclet:tutorial/PureFunctions"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Building Lists from Functions\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/BuildingListsFromFunctions"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Selecting Parts of Expressions with Functions\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/SelectingPartsOfExpressionsWithFunctions"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Expressions with Heads That Are Not Symbols\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ExpressionsWithHeadsThatAreNotSymbols"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Working with Operators\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/WorkingWithOperators"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Structural Operations\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/StructuralOperations"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Sequences\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup["paclet:tutorial/Sequences"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Patterns\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/PatternsOverview"], + Evaluator->Automatic, + Method->"Preemptive"]], "Section", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Introduction\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/Introduction-Patterns"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Finding Expressions That Match a Pattern\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/FindingExpressionsThatMatchAPattern"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Naming Pieces of Patterns\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NamingPiecesOfPatterns"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Specifying Types of Expression in Patterns\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/SpecifyingTypesOfExpressionInPatterns"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Putting Constraints on Patterns\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/PuttingConstraintsOnPatterns"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Patterns Involving Alternatives\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/PatternsInvolvingAlternatives"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Pattern Sequences\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/PatternSequences"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Flat and Orderless Functions\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/FlatAndOrderlessFunctions"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Functions with Variable Numbers of Arguments\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/FunctionsWithVariableNumbersOfArguments"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Optional and Default Arguments\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/OptionalAndDefaultArguments"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Setting Up Functions with Optional Arguments\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/SettingUpFunctionsWithOptionalArguments"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Repeated Patterns\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/RepeatedPatterns"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Verbatim Patterns\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/VerbatimPatterns"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Patterns for Some Common Types of Expression\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/PatternsForSomeCommonTypesOfExpression"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"An Example: Defining Your Own Integration Function\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/AnExampleDefiningYourOwnIntegrationFunction"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Working with String Patterns\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/WorkingWithStringPatternsOverview"], + Evaluator->Automatic, + Method->"Preemptive"]], "Section", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Introduction\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/WorkingWithStringPatterns#6475218"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"General String Patterns\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/WorkingWithStringPatterns#316252289"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Regular Expressions\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/WorkingWithStringPatterns#274403895"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"RegularExpression versus StringExpression\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/WorkingWithStringPatterns#182364929"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"String Manipulation Functions\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/WorkingWithStringPatterns#393353162"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"StringMatchQ\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/WorkingWithStringPatterns#115748480"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"StringFreeQ\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/WorkingWithStringPatterns#221687989"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"StringCases\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/WorkingWithStringPatterns#3968257"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"The Overlaps Option\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/WorkingWithStringPatterns#351610464"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"StringPosition\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/WorkingWithStringPatterns#363493082"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"StringCount\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/WorkingWithStringPatterns#401719377"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"StringReplace\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/WorkingWithStringPatterns#1274428"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"StringReplaceList\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/WorkingWithStringPatterns#239124212"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"StringSplit\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/WorkingWithStringPatterns#343107939"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"For Perl Users\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/WorkingWithStringPatterns#759470019"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Overview\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/WorkingWithStringPatterns#20697950"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"m/.../\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/WorkingWithStringPatterns#120637313"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"s/.../.../\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/WorkingWithStringPatterns#163295011"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"split(...)\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/WorkingWithStringPatterns#45791734"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"tr/.../.../\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/WorkingWithStringPatterns#627179989"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Some Examples\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/WorkingWithStringPatterns#2083974"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Dictionary Lookup\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/WorkingWithStringPatterns#123236071"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Highlight Patterns\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/WorkingWithStringPatterns#738873845"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"HTML Parsing\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/WorkingWithStringPatterns#146223979"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Find Money\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/WorkingWithStringPatterns#263221749"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Find Text in Files\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/WorkingWithStringPatterns#355263806"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Tips and Tricks for Efficient Matching\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/WorkingWithStringPatterns#319138910"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"StringExpression versus RegularExpression\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/WorkingWithStringPatterns#571253149"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Conditions and PatternTests\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/WorkingWithStringPatterns#11710184"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Avoid Nested Quantifiers\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/WorkingWithStringPatterns#39608680"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Avoid Many Calls to a Function\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/WorkingWithStringPatterns#73358011"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Rewrite General Expression Searches as String Searches\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/WorkingWithStringPatterns#148652143"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[BoxData[ + ButtonBox["\<\"Implementation Details\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/WorkingWithStringPatterns#337819047"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Manipulating Lists\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ManipulatingListsOverview"], + Evaluator->Automatic, + Method->"Preemptive"]], "Section", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Constructing Lists\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ConstructingLists"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Manipulating Lists by Their Indices\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ManipulatingListsByTheirIndices"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Nested Lists\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup["paclet:tutorial/NestedLists"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Partitioning and Padding Lists\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/PartitioningAndPaddingLists"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Sparse Arrays\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/SparseArrays-ManipulatingLists"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Transformation Rules and Definitions\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/TransformationRulesAndDefinitionsOverview"], + Evaluator->Automatic, + Method->"Preemptive"]], "Section", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Applying Transformation Rules\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ApplyingTransformationRules"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Manipulating Sets of Transformation Rules\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ManipulatingSetsOfTransformationRules"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Making Definitions\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/MakingDefinitions"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Special Forms of Assignment\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/SpecialFormsOfAssignment"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Making Definitions for Indexed Objects\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/MakingDefinitionsForIndexedObjects"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Making Definitions for Functions\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/MakingDefinitionsForFunctions"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"The Ordering of Definitions\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/TheOrderingOfDefinitions"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Immediate and Delayed Definitions\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ImmediateAndDelayedDefinitions"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Functions That Remember Values They Have Found\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/FunctionsThatRememberValuesTheyHaveFound"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Associating Definitions with Different Symbols\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/AssociatingDefinitionsWithDifferentSymbols"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Defining Numerical Values\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/DefiningNumericalValues"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Modifying Built\[Hyphen]in Functions\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ModifyingBuiltInFunctions"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Manipulating Value Lists\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ManipulatingValueLists"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Evaluation of Expressions\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/EvaluationOfExpressionsOverview"], + Evaluator->Automatic, + Method->"Preemptive"]], "Section", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Principles of Evaluation\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/PrinciplesOfEvaluation"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Reducing Expressions to Their Standard Form\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ReducingExpressionsToTheirStandardForm"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Attributes\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup["paclet:tutorial/Attributes"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"The Standard Evaluation Procedure\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/TheStandardEvaluationProcedure"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Nonstandard Evaluation\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NonStandardEvaluation"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Evaluation in Patterns, Rules and Definitions\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/EvaluationInPatternsRulesAndDefinitions"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Evaluation in Iteration Functions\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/EvaluationInIterationFunctions"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Conditionals\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup["paclet:tutorial/Conditionals"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Loops and Control Structures\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LoopsAndControlStructures"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Collecting Expressions During Evaluation\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/CollectingExpressionsDuringEvaluation"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Tracing Evaluation\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/TracingEvaluation"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"The Evaluation Stack\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/TheEvaluationStack"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Controlling Infinite Evaluation\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ControllingInfiniteEvaluation"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Interrupts and Aborts\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/InterruptsAndAborts"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Compiling Mathematica Expressions\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/CompilingMathematicaExpressions"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Manipulating Compiled Code\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ManipulatingCompiledCode"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Modularity and the Naming of Things\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ModularityAndTheNamingOfThingsOverview"], + Evaluator->Automatic, + Method->"Preemptive"]], "Section", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Modules and Local Variables\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ModulesAndLocalVariables"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Local Constants\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup["paclet:tutorial/LocalConstants"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"How Modules Work\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup["paclet:tutorial/HowModulesWork"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Variables in Pure Functions and Rules\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/VariablesInPureFunctionsAndRules"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Dummy Variables in Mathematics\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/DummyVariablesInMathematics"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Blocks and Local Values\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/BlocksAndLocalValues"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Blocks Compared with Modules\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/BlocksComparedWithModules"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Contexts\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup["paclet:tutorial/Contexts"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Contexts and Packages\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ContextsAndPackages"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Setting Up Mathematica Packages\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/SettingUpMathematicaPackages"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Automatic Loading of Packages\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/AutomaticLoadingOfPackages"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Manipulating Symbols and Contexts by Name\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ManipulatingSymbolsAndContextsByName"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Intercepting the Creation of New Symbols\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/InterceptingTheCreationOfNewSymbols"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Strings and Characters\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/StringsAndCharactersOverview"], + Evaluator->Automatic, + Method->"Preemptive"]], "Section", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Properties of Strings\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/PropertiesOfStrings"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Operations on Strings\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/OperationsOnStrings"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Characters in Strings\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/CharactersInStrings"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"String Patterns\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup["paclet:tutorial/StringPatterns"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Regular Expressions\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/RegularExpressions"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Special Characters\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/SpecialCharacters-StringsAndCharacters"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Newlines and Tabs in Strings\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NewlinesAndTabsInStrings"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Character Codes\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup["paclet:tutorial/CharacterCodes"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Raw Character Encodings\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/RawCharacterEncodings"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Textual Input and Output\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/TextualInputAndOutputOverview"], + Evaluator->Automatic, + Method->"Preemptive"]], "Section", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Forms of Input and Output\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/FormsOfInputAndOutput"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"How Input and Output Work\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/HowInputAndOutputWork"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"The Representation of Textual Forms\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/TheRepresentationOfTextualForms"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"The Interpretation of Textual Forms\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/TheInterpretationOfTextualForms"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Short and Shallow Output\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ShortAndShallowOutput"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"String\[Hyphen]Oriented Output Formats\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/StringOrientedOutputFormats"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Output Formats for Numbers\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/OutputFormatsForNumbers"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Tables and Matrices\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/TablesAndMatrices"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Formatting Higher-Dimensional Data\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/TablesAndMatrices"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[BoxData[ + ButtonBox["\<\"Styles and Fonts in Output\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/StylesAndFontsInOutput"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Representing Textual Forms by Boxes\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/RepresentingTextualFormsByBoxes"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Converting between Strings, Boxes and Expressions\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ConvertingBetweenStringsBoxesAndExpressions"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"The Syntax of the Mathematica Language\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/TheSyntaxOfTheMathematicaLanguage"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Operators without Built\[Hyphen]in Meanings\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/OperatorsWithoutBuiltInMeanings"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Defining Output Formats\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/DefiningOutputFormats"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Low\[Hyphen]Level Input and Output Rules\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LowLevelInputAndOutputRules"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Generating Unstructured Output\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/GeneratingUnstructuredOutput"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Requesting Input\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup["paclet:tutorial/RequestingInput"], + + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Messages\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup["paclet:tutorial/Messages"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"International Messages\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/InternationalMessages"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Documentation Constructs\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/DocumentationConstructs"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"The Structure of Graphics and Sound\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/TheStructureOfGraphicsAndSoundOverview"], + Evaluator->Automatic, + Method->"Preemptive"]], "Section", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"The Structure of Graphics\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/TheStructureOfGraphics"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Two-Dimensional Graphics Elements\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/TwoDimensionalGraphicsElements"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Graphics Directives and Options\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/GraphicsDirectivesAndOptions"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Coordinate Systems for Two-Dimensional Graphics\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/CoordinateSystemsForTwoDimensionalGraphics"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Labeling Two-Dimensional Graphics\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LabelingTwoDimensionalGraphics"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Insetting Objects in Graphics\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/InsettingObjectsInGraphics"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Density and Contour Plots\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/DensityAndContourPlots"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Three-Dimensional Graphics Primitives\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ThreeDimensionalGraphicsPrimitives"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Three-Dimensional Graphics Directives\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ThreeDimensionalGraphicsDirectives"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Coordinate Systems for Three-Dimensional Graphics\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/CoordinateSystemsForThreeDimensionalGraphics"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Lighting and Surface Properties\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LightingAndSurfaceProperties"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Labeling Three-Dimensional Graphics\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LabelingThreeDimensionalGraphics"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Efficient Representation of Many Primitives\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/EfficientRepresentationOfManyPrimitives"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Formats for Text in Graphics\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/FormatsForTextInGraphics"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Graphics Primitives for Text\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/GraphicsPrimitivesForText"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"The Representation of Sound\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/TheRepresentationOfSound"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Exporting Graphics and Sounds\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ExportingGraphicsAndSounds"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Importing Graphics and Sounds\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ImportingGraphicsAndSounds"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Manipulating Notebooks\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ManipulatingNotebooksOverview"], + Evaluator->Automatic, + Method->"Preemptive"]], "Section", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Cells as Mathematica Expressions\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/CellsAsMathematicaExpressions"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Notebooks as Mathematica Expressions\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NotebooksAsMathematicaExpressions"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Manipulating Notebooks from the Kernel\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ManipulatingNotebooksFromTheKernel"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Manipulating the Front End from the Kernel\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ManipulatingTheFrontEndFromTheKernel"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Executing Notebook Commands Directly in the Front End\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ExecutingNotebookCommandsDirectlyInTheFrontEnd"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"The Structure of Cells\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/TheStructureOfCells"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Styles and the Inheritance of Option Settings\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/StylesAndTheInheritanceOfOptionSettings"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Options for Cells\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup["paclet:tutorial/OptionsForCells"], + + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Text and Font Options\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/TextAndFontOptions"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Options for Expression Input and Output\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/OptionsForExpressionInputAndOutput"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Options for Notebooks\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/OptionsForNotebooks"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Global Options for the Front End\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/GlobalOptionsForTheFrontEnd"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Files and Streams\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/FilesAndStreamsOverview"], + Evaluator->Automatic, + Method->"Preemptive"]], "Section", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Reading and Writing Mathematica Files\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ReadingAndWritingMathematicaFiles"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"External Programs\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ExternalPrograms"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Streams and Low\[Hyphen]Level Input and Output\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/StreamsAndLowLevelInputAndOutput"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Naming and Finding Files\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NamingAndFindingFiles"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Files for Packages\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/FilesForPackages"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Manipulating Files and Directories\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ManipulatingFilesAndDirectories"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Importing and Exporting Files\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ImportingAndExportingFiles"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Reading Textual Data\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ReadingTextualData"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Searching Files\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup["paclet:tutorial/SearchingFiles"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Searching and Reading Strings\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/SearchingAndReadingStrings"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"MathLink and External Program Communication\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/MathLinkAndExternalProgramCommunicationOverview"], + Evaluator->Automatic, + Method->"Preemptive"]], "Section", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"How MathLink Is Used\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/HowMathLinkIsUsed"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Installing Existing MathLink\[Hyphen]Compatible Programs\"\>", + + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/InstallingExistingMathLinkCompatiblePrograms"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Setting Up External Functions to Be Called from Mathematica\"\ +\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/SettingUpExternalFunctionsToBeCalledFromMathematica"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Handling Lists, Arrays and Other Expressions\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/HandlingListsArraysAndOtherExpressions"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Portability of MathLink Programs\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/PortabilityOfMathLinkPrograms"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Using MathLink to Communicate between Mathematica \ +Sessions\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/UsingMathLinkToCommunicateBetweenMathematicaSessions"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Calling Subsidiary Mathematica Processes\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/CallingSubsidiaryMathematicaProcesses"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Two\[Hyphen]Way Communication with External Programs\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/TwoWayCommunicationWithExternalPrograms"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Running Programs on Remote Computers\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/RunningProgramsOnRemoteComputers"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Running External Programs under a Debugger\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/RunningExternalProgramsUnderADebugger"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Manipulating Expressions in External Programs\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ManipulatingExpressionsInExternalPrograms"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Error and Interrupt Handling\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ErrorAndInterruptHandling"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Running Mathematica from Within an External Program\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/RunningMathematicaFromWithinAnExternalProgram"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Global Aspects of Mathematica Sessions\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/GlobalAspectsOfMathematicaSessionsOverview"], + Evaluator->Automatic, + Method->"Preemptive"]], "Section", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"The Main Loop\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup["paclet:tutorial/TheMainLoop"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Dialogs\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup["paclet:tutorial/Dialogs"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Memory Management\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/MemoryManagement"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Global System Information\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/GlobalSystemInformation"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Mathematica Sessions\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/MathematicaSessions"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"System Administration for Network Licenses\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/SystemAdministrationForNetworkLicensesOverview"], + Evaluator->Automatic, + Method->"Preemptive"]], "Section", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"What is MathLM?\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup["paclet:tutorial/WhatIsMathLM"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Installing MathLM\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/InstallingMathLM"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Launching MathLM\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup["paclet:tutorial/LaunchingMathLM"], + + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Logging MathLM\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup["paclet:tutorial/LoggingMathLM"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Monitoring MathLM\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/MonitoringMathLM"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Restricting and Reserving Licenses\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/RestrictingAndReservingLicenses"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Troubleshooting MathLM\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/TroubleshootingMathLM"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Installing Mathematica on Windows\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/InstallingMathematicaOnWindows"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Launching Mathematica on Windows\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LaunchingMathematicaOnWindows"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Testing the Installation on Windows\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/TestingTheInstallationOnWindows"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Configuration Files on Windows\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ConfigurationFilesOnWindows"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Systemwide Defaults on Windows\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/SystemwideDefaultsOnWindows"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Troubleshooting on Windows\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/TroubleshootingOnWindows"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Installing Mathematica on Unix and Linux\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/InstallingMathematicaOnUnixAndLinux"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Launching Mathematica on Unix and Linux\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LaunchingMathematicaOnUnixAndLinux"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Testing the Installation on Unix and Linux\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/TestingTheInstallationOnUnixAndLinux"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Configuration Files on Unix and Linux\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ConfigurationFilesOnUnixAndLinux"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Systemwide Defaults on Unix and Linux\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/SystemwideDefaultsOnUnixAndLinux"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Fonts on Unix and Linux\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/FontsOnUnixAndLinux"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Troubleshooting on Unix and Linux\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/TroubleshootingOnUnixAndLinux"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Installing Mathematica on Mac OS X\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/InstallingMathematicaOnMacOSX"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Launching Mathematica on Mac OS X\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LaunchingMathematicaOnMacOSX"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Testing the Installation on Mac OS X\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/TestingTheInstallationOnMacOSX"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Configuration Files on Mac OS X\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ConfigurationFilesOnMacOSX"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Systemwide Defaults on Mac OS X\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/SystemwideDefaultsOnMacOSX"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Troubleshooting on Mac OS X\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/TroubleshootingOnMacOSX"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True] +}, Closed]] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"System Administration for Single-User Licenses\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/SystemAdministrationForSingleUserLicensesOverview"], + Evaluator->Automatic, + Method->"Preemptive"]], "Section", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Installing Mathematica on Windows\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/InstallingMathematicaOnWindows"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Launching Mathematica on Windows\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LaunchingMathematicaOnWindows"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Testing the Installation on Windows\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/TestingTheInstallationOnWindows"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Configuration Files on Windows\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ConfigurationFilesOnWindows"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Systemwide Defaults on Windows\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/SystemwideDefaultsOnWindows"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Troubleshooting on Windows\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/TroubleshootingOnWindows"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Installing Mathematica on Unix and Linux\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/InstallingMathematicaOnUnixAndLinux"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Launching Mathematica on Unix and Linux\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LaunchingMathematicaOnUnixAndLinux"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Testing the Installation on Unix and Linux\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/TestingTheInstallationOnUnixAndLinux"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Configuration Files on Unix and Linux\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ConfigurationFilesOnUnixAndLinux"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Systemwide Defaults on Unix and Linux\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/SystemwideDefaultsOnUnixAndLinux"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Fonts on Unix and Linux\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/FontsOnUnixAndLinux"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Troubleshooting on Unix and Linux\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/TroubleshootingOnUnixAndLinux"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Installing Mathematica on Mac OS X\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/InstallingMathematicaOnMacOSX"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Launching Mathematica on Mac OS X\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LaunchingMathematicaOnMacOSX"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Testing the Installation on Mac OS X\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/TestingTheInstallationOnMacOSX"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Configuration Files on Mac OS X\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ConfigurationFilesOnMacOSX"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Systemwide Defaults on Mac OS X\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/SystemwideDefaultsOnMacOSX"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Troubleshooting on Mac OS X\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/TroubleshootingOnMacOSX"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True] +}, Closed]] +}, Closed]], + +Cell[CellGroupData[{ + +Cell["Advanced Mathematics in Mathematica", "Subtitle", + ShowGroupOpener->True, + CellMargins->{{Inherited, Inherited}, {15, 30}}], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Numbers\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup["paclet:tutorial/NumbersOverview"], + + Evaluator->Automatic, + Method->"Preemptive"]], "Section", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Types of Numbers\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup["paclet:tutorial/TypesOfNumbers"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Numeric Quantities\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NumericQuantities"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Digits in Numbers\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup["paclet:tutorial/DigitsInNumbers"], + + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Numerical Precision\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NumericalPrecision"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Arbitrary\[Hyphen]Precision Numbers\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ArbitraryPrecisionNumbers"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Machine\[Hyphen]Precision Numbers\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/MachinePrecisionNumbers"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Interval Arithmetic\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/IntervalArithmetic"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Indeterminate and Infinite Results\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/IndeterminateAndInfiniteResults"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Controlling Numerical Evaluation\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ControllingNumericalEvaluation"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Mathematical Functions\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/MathematicalFunctionsOverview"], + Evaluator->Automatic, + Method->"Preemptive"]], "Section", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Naming Conventions\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NamingConventions"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Numerical Functions\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NumericalFunctions"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Piecewise Functions\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/PiecewiseFunctions"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Pseudorandom Numbers\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/PseudorandomNumbers"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Integer and Number Theoretic Functions\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/IntegerAndNumberTheoreticalFunctions"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Combinatorial Functions\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/CombinatorialFunctions"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Elementary Transcendental Functions\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ElementaryTranscendentalFunctions"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Functions That Do Not Have Unique Values\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/FunctionsThatDoNotHaveUniqueValues"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Mathematical Constants\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/MathematicalConstants"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Orthogonal Polynomials\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/OrthogonalPolynomials"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Special Functions\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/SpecialFunctions"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Gamma and Related Functions\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/SpecialFunctions"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Zeta and Related Functions\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/SpecialFunctions"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Exponential Integral and Related Functions\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/SpecialFunctions"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Error Function and Related Functions\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/SpecialFunctions"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Bessel and Related Functions\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/SpecialFunctions"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Legendre and Related Functions\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/SpecialFunctions"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Confluent Hypergeometric Functions\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/SpecialFunctions"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Hypergeometric Functions and Generalizations\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/SpecialFunctions"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"The Product Log Function\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/SpecialFunctions"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Elliptic Integrals and Elliptic Functions\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/EllipticIntegralsAndEllipticFunctions"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Elliptic Integrals\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/EllipticIntegralsAndEllipticFunctions"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Elliptic Functions\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/EllipticIntegralsAndEllipticFunctions"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Elliptic Modular Functions\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/EllipticIntegralsAndEllipticFunctions"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Generalized Elliptic Integrals and Functions\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/EllipticIntegralsAndEllipticFunctions"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[BoxData[ + ButtonBox["\<\"Mathieu and Related Functions\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/MathieuAndRelatedFunctions"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Algebraic Manipulation\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/AlgebraicManipulationOverview"], + Evaluator->Automatic, + Method->"Preemptive"]], "Section", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Structural Operations on Polynomials\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/StructuralOperationsOnPolynomials"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Finding the Structure of a Polynomial\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/FindingTheStructureOfAPolynomial"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Structural Operations on Rational Expressions\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/StructuralOperationsOnRationalExpressions"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Algebraic Operations on Polynomials\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/AlgebraicOperationsOnPolynomials"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Polynomials Modulo Primes\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/PolynomialsModuloPrimes"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Polynomials over Algebraic Number Fields\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/PolynomialsOverAlgebraicNumberFields"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Trigonometric Expressions\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/TrigonometricExpressions"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Expressions Involving Complex Variables\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ExpressionsInvolvingComplexVariables"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Logical and Piecewise Functions\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LogicalAndPiecewiseFunctions"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Simplification\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup["paclet:tutorial/Simplification"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Using Assumptions\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/UsingAssumptions"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Manipulating Equations and Inequalities\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ManipulatingEquationsAndInequalitiesOverview"], + Evaluator->Automatic, + Method->"Preemptive"]], "Section", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"The Representation of Equations and Solutions\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/TheRepresentationOfEquationsAndSolutions"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Equations in One Variable\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/EquationsInOneVariable"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Algebraic Numbers\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/AlgebraicNumbers"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Simultaneous Equations\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/SimultaneousEquations"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Generic and Non\[Hyphen]Generic Solutions\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/GenericAndNonGenericSolutions"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Eliminating Variables\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/EliminatingVariables"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Solving Logical Combinations of Equations\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/SolvingLogicalCombinationsOfEquations"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Inequalities\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/Inequalities-ManipulatingEquationsAndInequalities"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Equations and Inequalities over Domains\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/EquationsAndInequalitiesOverDomains"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"The Representation of Solution Sets\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/TheRepresentationOfSolutionSets"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Quantifiers\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup["paclet:tutorial/Quantifiers"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Minimization and Maximization\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/MinimizationAndMaximization"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Calculus\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/CalculusOverview"], + Evaluator->Automatic, + Method->"Preemptive"]], "Section", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Differentiation\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup["paclet:tutorial/Differentiation"], + + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Total Derivatives\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/TotalDerivatives"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Derivatives of Unknown Functions\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/DerivativesOfUnknownFunctions"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"The Representation of Derivatives\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/TheRepresentationOfDerivatives"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Defining Derivatives\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/DefiningDerivatives"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Indefinite Integrals\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/IndefiniteIntegrals"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Integrals That Can and Cannot Be Done\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/IntegralsThatCanAndCannotBeDone"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Definite Integrals\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/DefiniteIntegrals"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Integrals over Regions\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/IntegralsOverRegions"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Manipulating Integrals in Symbolic Form\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ManipulatingIntegralsInSymbolicForm"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Differential Equations\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/DifferentialEquations"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Integral Transforms and Related Operations\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/IntegralTransformsAndRelatedOperations"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Laplace Transforms\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/IntegralTransformsAndRelatedOperations"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Fourier Transforms\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/IntegralTransformsAndRelatedOperations"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Z Transforms\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/IntegralTransformsAndRelatedOperations"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[BoxData[ + ButtonBox["\<\"Generalized Functions and Related Objects\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/GeneralizedFunctionsAndRelatedObjects"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Differential Equation Solving with DSolve\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup["paclet:tutorial/DSolveOverview"], + Evaluator->Automatic, + Method->"Preemptive"]], "Section", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Introduction to Differential Equation Solving with \ +DSolve\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/DSolveIntroduction"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Classification of Differential Equations\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/DSolveClassificationOfDifferentialEquations"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Overview of ODEs\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/DSolveIntroductionToODEs"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Straight Integration\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/DSolveStraightIntegration"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Separable Equations\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/DSolveSeparableEquations"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Homogeneous Equations\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/DSolveHomogeneousEquations"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Linear Equations\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/DSolveLinearFirstOrderEquations"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Inverse Linear Equations\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/DSolveInverseLinearEquations"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Bernoulli Equations\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/DSolveBernoulliEquations"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Riccati Equations\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/DSolveRiccatiEquations"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Exact Equations\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/DSolveExactEquations"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Clairaut Equations\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/DSolveClairautEquations"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Abel Equations\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/DSolveAbelEquations"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Chini Equations\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/DSolveChiniEquations"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Overview of Linear Second-Order ODEs\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/DSolveIntroductionToLinearSecondOrderODEs"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Equations with Constant Coefficients\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/DSolveLinearSecondOrderEquationsWithConstantCoefficients"]\ +, + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Euler and Legendre Equations\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/DSolveSecondOrderEulerAndLegendreEquations"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Exact Linear Second-Order Equations\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/DSolveExactLinearSecondOrderODEs"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Equations with Solutions Involving Special Functions\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/DSolveLinearSecondOrderSpecialFunctionODEs"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Equations with Rational Coefficients\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/DSolveLinearSecondOrderODEsWithRationalCoefficients"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Equations with Non-Rational Coefficients\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/DSolveLinearSecondOrderODEsWithNonRationalCoefficients"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Inhomogeneous Linear Second-Order Equations\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/DSolveLinearSecondOrderInhomogeneousEquations"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Nonlinear Second-Order ODEs \"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/DSolveNonlinearSecondOrderODEs"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Overview of Higher-Order ODEs\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/DSolveIntroductionToHigherOrderODEs"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Equations with Constant Coefficients\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/DSolveHigherOrderODEsWithConstantCoefficients"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Euler and Legendre Equations\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/DSolveHigherOrderEulerAndLegendreEquations"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Exact Equations\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/DSolveHigherOrderExactEquations"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Other Types of Higher-Order ODEs\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/DSolveFurtherHigherOrderODEs"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Introduction to Systems of ODEs\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/DSolveIntroductionToSystemsOfODEs"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Linear Systems of ODEs\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/DSolveSystemsOfLinearODEs"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Nonlinear Systems of ODEs\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/DSolveSystemsOfNonlinearODEs"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[BoxData[ + ButtonBox["\<\"Nonlinear ODEs with Lie Symmetries\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/DSolveLieSymmetryMethods"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Introduction to PDEs\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/DSolveIntroductionToPDEs"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Linear and Quasi-Linear PDEs\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/DSolveLinearAndQuasiLinearFirstOrderPDEs"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Nonlinear PDEs\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/DSolveNonlinearFirstOrderPDEs"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[BoxData[ + ButtonBox["\<\"Second-Order PDEs\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/DSolveSecondOrderPDEs"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Introduction to DAEs\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/DSolveIntroductionToDAEs"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Examples of DAEs\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/DSolveExamplesOfDAEs"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Introduction to Initial and Boundary Value Problems\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/DSolveIntroductionToBVPs"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Linear IVPs and BVPs\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/DSolveLinearBVPs"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Nonlinear IVPs and BVPs\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/DSolveNonlinearBVPs"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"IVPs with Piecewise Coefficients\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/DSolvePiecewiseBVPs"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Introduction\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/WorkingWithDSolveIntroduction"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Setting Up the Problem\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/DSolveSettingUpTheProblem"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Verification of the Solution\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/DSolveSolutionVerification"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Plotting the Solution\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/DSolvePlottingTheSolution"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Generated Parameters\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/DSolveGeneratedParametersOption"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Symbolic Parameters and Inexact Quantities\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/DSolveSymbolicAndInexactQuantities"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Is the Problem Well-Posed?\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/DSolveWellPosedness"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[BoxData[ + ButtonBox["\<\"References\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/DSolveReferences"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Series, Limits and Residues\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/SeriesLimitsAndResiduesOverview"], + Evaluator->Automatic, + Method->"Preemptive"]], "Section", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Making Power Series Expansions\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/MakingPowerSeriesExpansions"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"The Representation of Power Series\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/TheRepresentationOfPowerSeries"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Operations on Power Series\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/OperationsOnPowerSeries"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Composition and Inversion of Power Series\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/CompositionAndInversionOfPowerSeries"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Converting Power Series to Normal Expressions\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ConvertingPowerSeriesToNormalExpressions"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Solving Equations Involving Power Series\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/SolvingEquationsInvolvingPowerSeries"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Summation of Series\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/SummationOfSeries"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Solving Recurrence Equations\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/SolvingRecurrenceEquations"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Finding Limits\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup["paclet:tutorial/FindingLimits"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Residues\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup["paclet:tutorial/Residues"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Linear Algebra in Mathematica\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraOverview"], + Evaluator->Automatic, + Method->"Preemptive"]], "Section", + ShowGroupOpener->True], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Introduction\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraIntroduction#509267359"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Tensors and Arrays\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraIntroduction#374996618"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Matrices as Mathematica Expressions\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraIntroduction#1127257628"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Expression Input and Output\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraIntroduction#1564598842"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Design Principles of Mathematica\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraIntroduction#207795216"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Matrix and Tensor Operations\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraMatrixAndTensorOperations#1023128168"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Building Matrices\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraMatrixAndTensorOperations#441715480"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Special Matrices\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraMatrixAndTensorOperations#1887778180"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Structural Operations\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraMatrixAndTensorOperations#223720584"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Getting Pieces of Matrices\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraMatrixAndTensorOperations#1678167046"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Getting Multiple Pieces\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraMatrixAndTensorOperations#288135948"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Setting Pieces of Matrices\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraMatrixAndTensorOperations#1626148827"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Setting Multiple Pieces\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraMatrixAndTensorOperations#289617502"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Extracting Submatrices\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraMatrixAndTensorOperations#849568979"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Deleting Rows and Columns\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraMatrixAndTensorOperations#2028205186"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Inserting Rows and Columns\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraMatrixAndTensorOperations#964961827"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Extending Matrices\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraMatrixAndTensorOperations#782554218"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Transpose\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraMatrixAndTensorOperations#11316850"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Rotating Elements\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraMatrixAndTensorOperations#654023951"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Testing Matrices\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraMatrixAndTensorOperations#1736222906"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Further Structural Operations\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraMatrixAndTensorOperations#528156332"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Element-wise Operations\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraMatrixAndTensorOperations#1701521313"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Listability\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraMatrixAndTensorOperations#540401315"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Map\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraMatrixAndTensorOperations#188079645"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Vectors and Tensors\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraMatrixAndTensorOperations#112899229"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Testing Vectors and Tensors\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraMatrixAndTensorOperations#1062677296"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Visualization of Matrices\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraMatrixAndTensorOperations#1361817013"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Formatting Matrices\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraMatrixAndTensorOperations#1886656195"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Plotting Matrices\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraMatrixAndTensorOperations#1336717728"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[BoxData[ + ButtonBox["\<\"Import and Export of Matrices\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraMatrixAndTensorOperations#2053293398"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Matrix Multiplication\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraMatrixAndTensorOperations#1896011669"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Outer Product\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraMatrixAndTensorOperations#520172951"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Visualization of the Outer Product\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraMatrixAndTensorOperations#1814519952"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Generalized Inner Product\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraMatrixAndTensorOperations#1622139970"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Matrix Permutations\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraMatrixAndTensorOperations#1318022893"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Permutation Matrices\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraMatrixAndTensorOperations#384051338"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True] +}, Closed]] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Working with Sparse Arrays\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraSparseArrays#1619024906"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Basic Operations\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraSparseArrays#1588951893"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"SparseArray\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraSparseArrays#1458825321"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Rule Inputs for SparseArray\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraSparseArrays#1126881263"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Banded Sparse Matrices\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraSparseArrays#69082539"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Identity and Diagonal Sparse Matrices\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraSparseArrays#386554746"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Normal\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraSparseArrays#1483534657"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"ArrayRules\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraSparseArrays#1554122061"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Structural Operations\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraSparseArrays#382555551"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Getting Pieces of Matrices\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraSparseArrays#43873582"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Getting Multiple Pieces\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraSparseArrays#980139236"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Setting Pieces of Matrices\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraSparseArrays#1033045979"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Setting Multiple Pieces\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraSparseArrays#1718872299"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Extracting Submatrices\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraSparseArrays#2116455801"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Deleting Rows and Columns\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraSparseArrays#503342974"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Inserting Rows and Columns\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraSparseArrays#812208252"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Extending Matrices\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraSparseArrays#1326060419"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Transpose\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraSparseArrays#1525842641"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Rotating Elements\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraSparseArrays#877282493"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Testing Matrices\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraSparseArrays#1013005059"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Further Structural Operations\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraSparseArrays#1896109973"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Element-wise Operations\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraSparseArrays#430873687"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Listability\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraSparseArrays#1542041473"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Map\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraSparseArrays#2077369385"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Visualization of Sparse Matrices\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraSparseArrays#1853380947"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Formatting Sparse Matrices\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraSparseArrays#1305822102"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Plotting Sparse Matrices\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraSparseArrays#1191044059"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[BoxData[ + ButtonBox["\<\"Import and Export of Sparse Matrices\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraSparseArrays#212323487"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Matrix Multiplication\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraSparseArrays#243730537"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Outer Product\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraSparseArrays#1885795684"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[BoxData[ + ButtonBox["\<\"Matrix Permutations\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraSparseArrays#1180395712"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Converting Equations to Sparse Arrays\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraSparseArrays#139087150"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"SparseArray Data Format\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraSparseArrays#483612173"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Matrix Computations\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraMatrixComputations#1927833614"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Basic Operations\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraMatrixComputations#1060011943"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Norms\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraMatrixComputations#832278785"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"NullSpace\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraMatrixComputations#478394165"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Rank\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraMatrixComputations#2035970465"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Reduced Row Echelon Form\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraMatrixComputations#2032866165"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Inverse\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraMatrixComputations#1798152178"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"PseudoInverse\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraMatrixComputations#1120972426"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Determinant\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraMatrixComputations#1665558708"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Minors\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraMatrixComputations#1595477023"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Solving Linear Systems\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraMatrixComputations#81663253"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Singular Matrices\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraMatrixComputations#438728183"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Homogeneous Equations\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraMatrixComputations#534320490"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Estimating and Calculating Accuracy\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraMatrixComputations#1668277829"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Symbolic and Exact Matrices\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraMatrixComputations#1644685080"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Row Reduction\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraMatrixComputations#644279649"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Saving the Factorization\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraMatrixComputations#1974718471"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Methods\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraMatrixComputations#834729047"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"LAPACK\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraMatrixComputations#1131477137"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Multifrontal\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraMatrixComputations#1415618539"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Krylov\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraMatrixComputations#1643755774"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Cholesky\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraMatrixComputations#1549309818"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Symbolic Methods\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraMatrixComputations#1813753518"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Least Squares Solutions\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraMatrixComputations#563250646"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Data Fitting\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraMatrixComputations#1737956870"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Eigensystem Computations\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraMatrixComputations#1705931980"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Eigensystem Properties\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraMatrixComputations#723589929"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Diagonalizing a Matrix\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraMatrixComputations#1770480598"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Symbolic and Exact Matrices\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraMatrixComputations#1937669982"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Generalized Eigenvalues\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraMatrixComputations#524353415"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Methods\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraMatrixComputations#905279933"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"LAPACK\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraMatrixComputations#1499161194"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Arnoldi\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraMatrixComputations#1833787992"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Symbolic Methods\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraMatrixComputations#344887306"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Matrix Decompositions\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraMatrixComputations#837293883"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"LU Decomposition\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraMatrixComputations#849593972"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Cholesky Decomposition\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraMatrixComputations#1567526616"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Cholesky and LU Factorizations\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraMatrixComputations#966681026"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Orthogonalization\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraMatrixComputations#464885506"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"QR Decomposition\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraMatrixComputations#1662286926"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Solving Systems of Equations\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraMatrixComputations#841776984"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Singular Value Decomposition\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraMatrixComputations#315998326"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Generalized Singular Values\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraMatrixComputations#915032469"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Options\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraMatrixComputations#2106677120"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Schur Decomposition\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraMatrixComputations#225662794"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Generalized Schur Decomposition\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraMatrixComputations#811895271"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Options\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraMatrixComputations#35657259"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Jordan Decomposition\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraMatrixComputations#1994258536"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[BoxData[ + ButtonBox["\<\"Functions of Matrices\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraMatrixComputations#1131563790"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Matrix Types\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraMatrixTypes#1880892864"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Numbers in Mathematica\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraMatrixTypes#139211047"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Exact versus Approximate Numbers\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraMatrixTypes#1831846039"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Mixed Mode Arithmetic\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraMatrixTypes#1284345793"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Matrices in Mathematica\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraMatrixTypes#77896732"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Standard Numerical Techniques\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraMatrixTypes#963685160"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Arbitrary-Precision Numerical Techniques\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraMatrixTypes#1753145835"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Symbolic Algebra Techniques\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraMatrixTypes#1095335974"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Mixed Mode Matrices\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraMatrixTypes#1172699025"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[BoxData[ + ButtonBox["\<\"Complex Matrices\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraMatrixTypes#411747335"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Arbitrary-Precision Matrices\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraMatrixTypes#2139022291"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Performance of Linear Algebra Computation\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraPerformance#195254286"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Packed Arrays\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraPerformance#1945433762"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Packed Array Functions\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraPerformance#995975105"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Packed Array Operations\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraPerformance#41338579"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Packed Array Summary\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraPerformance#169320987"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Programming Efficiency\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraPerformance#1030559832"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Measuring Performance\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraPerformance#1826376848"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Vectorizing Loops\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraPerformance#1352766973"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"List Creation\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraPerformance#1048970201"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"List Updating\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraPerformance#291032650"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Using Built-in Support\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraPerformance#1145089169"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"A Slow Way\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraPerformance#1855711455"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"A Faster Way\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraPerformance#460055094"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Also Fast but Neater\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraPerformance#663127012"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Matrix Contents\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraPerformance#478605279"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Mixed Symbolic/Numerical Matrices\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraPerformance#92425055"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Mixed Numerical Type Matrices\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraPerformance#1705346414"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Integer Matrices\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraPerformance#535763928"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Expression Efficiency\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraPerformance#1857660297"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Updating of Matrices\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraPerformance#1264346631"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Appending to Matrices\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraPerformance#1750402393"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True] +}, Closed]] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Linear Algebra Examples\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraExamples#349852864"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Matrix Ordering\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraExamples#1945860599"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Full Rank Least Squares Solutions\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraExamples#967762464"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Least Squares Cholesky\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraExamples#899751076"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Least Squares QR\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraExamples#701643607"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Minimization of 1 and Infinity Norms\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraExamples#601898483"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"One-Norm Minimization\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraExamples#526704053"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Infinity-Norm Minimization\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraExamples#1503089771"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[BoxData[ + ButtonBox["\<\"Finite Difference Solutions\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraExamples#1711482715"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Mesh Partitioning\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraExamples#1370044451"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Data\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraExamples#1594202747"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Plotting the Mesh\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraExamples#846283239"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"The Laplacian\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraExamples#455167669"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"The Fiedler Vector\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraExamples#1726888774"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Partitioning the Nodes\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraExamples#1327004163"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[BoxData[ + ButtonBox["\<\"Matrix Functions with NDSolve\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraExamples#747736829"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"References\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraAppendix#342426796"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Software References\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraAppendix#2058470059"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"ARPACK\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraAppendix#744728443"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"ATLAS\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraAppendix#342575303"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Harwell-Boeing\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraAppendix#1350971188"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Matrix Market\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraAppendix#1964229445"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"METIS\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraAppendix#1290592593"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"TAUCS\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraAppendix#165728992"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"UMFPACK\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraAppendix#83486633"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[BoxData[ + ButtonBox["\<\"Other References\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LinearAlgebraAppendix#95220008"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True] +}, Closed]] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Numerical Operations on Data\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NumericalOperationsOnDataOverview"], + Evaluator->Automatic, + Method->"Preemptive"]], "Section", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Basic Statistics\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup["paclet:tutorial/BasicStatistics"], + + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Curve Fitting\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup["paclet:tutorial/CurveFitting"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Approximate Functions and Interpolation\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ApproximateFunctionsAndInterpolation"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Discrete Fourier Transforms\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/FourierTransforms"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Convolutions and Correlations\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ConvolutionsAndCorrelations"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Cellular Automata\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/CellularAutomata"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Numerical Operations on Functions\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NumericalOperationsOnFunctionsOverview"], + Evaluator->Automatic, + Method->"Preemptive"]], "Section", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Numerical Mathematics in Mathematica\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NumericalMathematicsInMathematica"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"The Uncertainties of Numerical Mathematics\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/TheUncertaintiesOfNumericalMathematics"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Numerical Integration\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NumericalIntegration"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Numerical Evaluation of Sums and Products\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NumericalEvaluationOfSumsAndProducts"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Numerical Solution of Polynomial Equations\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NumericalSolutionOfPolynomialEquations"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Numerical Root Finding\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NumericalRootFinding"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Numerical Solution of Differential Equations\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NumericalSolutionOfDifferentialEquations"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Numerical Optimization\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NumericalOptimization"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Controlling the Precision of Results\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ControllingThePrecisionOfResults"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Monitoring and Selecting Algorithms\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/MonitoringAndSelectingAlgorithms"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Functions with Sensitive Dependence on Their Input\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/FunctionsWithSensitiveDependenceOnTheirInput"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Advanced Numerical Differential Equation Solving in \ +Mathematica\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup["paclet:tutorial/NDSolveOverview"], + + Evaluator->Automatic, + Method->"Preemptive"]], "Section", + ShowGroupOpener->True], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Introduction\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NDSolveIntroductoryTutorial"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Overview\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NDSolveIntroductoryTutorial"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"The Design of the NDSolve Framework\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup["paclet:tutorial/NDSolveDesign"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Features\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NDSolveDesign#75354863"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Common time stepping\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NDSolveDesign#1791028983"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Data encapsulation\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NDSolveDesign#587411179"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Method hierarchy\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NDSolveDesign#154961554"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"User extensibility\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NDSolveDesign#1518443729"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Method classes\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NDSolveDesign#74982980"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Automatic selection and user controllability\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NDSolveDesign#2101685400"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Shared features\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NDSolveDesign#1332704694"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Some basic methods\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NDSolveDesign#958103344"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Acknowledgements\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NDSolveDesign#590065589"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"ExplicitRungeKutta\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NDSolveExplicitRungeKutta"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"ImplicitRungeKutta\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NDSolveImplicitRungeKutta"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"SymplecticPartitionedRungeKutta\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup["paclet:tutorial/NDSolveSPRK"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Composition and Splitting\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NDSolveSplitting"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"DoubleStep\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NDSolveDoubleStep"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"EventLocator\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NDSolveEventLocator"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Extrapolation\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NDSolveExtrapolation"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"FixedStep\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NDSolveFixedStep"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"OrthogonalProjection\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NDSolveOrthogonalProjection"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Projection\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NDSolveProjection"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"StiffnessSwitching\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NDSolveStiffnessSwitching"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"ExplicitEuler\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NDSolveExtrapolation#1712532361"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"ExplicitMidpoint\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NDSolveExtrapolation#1712532361"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"ExplicitModifiedMidpoint\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NDSolveExtrapolation#1712532361"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"LinearlyImplicitEuler\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NDSolveExtrapolation#1712532361"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"LinearlyImplicitMidpoint\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NDSolveExtrapolation#1712532361"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"LinearlyImplicitModifiedMidpoint\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NDSolveExtrapolation#1712532361"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"LocallyExact\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NDSolveLocallyExact"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Method Plug-in Framework\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup["paclet:tutorial/NDSolvePlugIns"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True] +}, Closed]] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Partial Differential Equations\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup["paclet:tutorial/NDSolvePDE"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"The Numerical Method of Lines\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup["paclet:tutorial/NDSolvePDE"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Introduction\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NDSolvePDE#1699661144"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Spatial Derivative Approximations\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NDSolvePDE#1106740037"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Boundary Conditions\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NDSolvePDE#1306392612"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Spatial Error Estimates\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NDSolvePDE#2081642391"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True] +}, Closed]] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Boundary Value Problems\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup["paclet:tutorial/NDSolveBVP"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Shooting Method\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NDSolveBVP#659822336"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Chasing Method\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NDSolveBVP#948663323"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Boundary Value Problems with Parameters\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NDSolveBVP#3518691"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Differential-Algebraic Equations\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NDSolveIntroductoryTutorialDAEs"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Introduction\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NDSolveIntroductoryTutorialDAEs"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"IDA Method\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NDSolveIDAMethod"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Components and Data Structures\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NDSolveIntroductoryTutorialStateData"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Introduction\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NDSolveIntroductoryTutorialStateData#2125957807"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Example\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NDSolveIntroductoryTutorialStateData#580655648"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Creating NDSolve`StateData Objects\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NDSolveStateData"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"ProcessEquations\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NDSolveStateData#1805463009"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Reinitialize\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NDSolveStateData#568926686"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[BoxData[ + ButtonBox["\<\"Iterating Solutions\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NDSolveStateData#1408385626"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Getting Solution Functions\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NDSolveStateData#1284231932"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"NDSolve`StateData methods\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NDSolveStateData#93858351"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"DifferentialEquations Utility Packages\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup["paclet:tutorial/NDSolvePackages"], + + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"InterpolatingFunctionAnatomy\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NDSolvePackages#120436095"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"NDSolveUtilities\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NDSolvePackages#287875440"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[BoxData[ + ButtonBox["\<\"References\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NDSolveReferences"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Advanced Numerical Integration in Mathematica\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateOverview"], + Evaluator->Automatic, + Method->"Preemptive"]], "Section", + ShowGroupOpener->True], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"NIntegrate Introduction\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntroduction"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Overview\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntroduction#32344101"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Design\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntroduction#951840905"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Features\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntroduction#540272418"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Strategies, rules, and preprocessors\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntroduction#118305364"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"User extensibility\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntroduction#2713904"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Acknowledgements\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntroduction#425413732"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True] +}, Closed]] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"NIntegrate Integration Strategies\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationStrategies"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Introduction\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationStrategies#235955634"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Adaptive Strategies\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationStrategies#155948475"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Global Adaptive Strategy\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationStrategies#137878679"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"MinRecursion and MaxRecursion\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationStrategies#280704764"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"\\\"MaxErrorIncreases\\\"\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationStrategies#285388386"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Example implementation of a global adaptive strategy\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationStrategies#16672882"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Local Adaptive Strategy\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationStrategies#19475523"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"MinRecursion and MaxRecursion\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationStrategies#270286642"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"\\\"InitialEstimateRelaxation\\\"\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationStrategies#64704670"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"\\\"Partitioning\\\"\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationStrategies#526467531"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Reuse of integrand values\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationStrategies#214095646"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Example implementation of a local adaptive strategy\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationStrategies#715598439"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[BoxData[ + ButtonBox["\<\"\\\"GlobalAdaptive\\\" versus \\\"LocalAdaptive\\\"\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationStrategies#290792217"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Singularity Handling\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationStrategies#122144792"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"User specified singularities\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationStrategies#112801667"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"\\\"SingularityHandler\\\" and \\\"SingularityDepth\\\"\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationStrategies#31583791"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Use of the IMT variable transformation\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationStrategies#150310618"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"IMT transformation by example\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationStrategies#107913531"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Use of double exponential quadrature\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationStrategies#225088061"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"IMT \\\"DoubleExponential\\\" no singularity handling for \ +one-dimensional integrals\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationStrategies#23700706"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"IMT multidimensional singularity handling\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationStrategies#159907828"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Duffy's coordinates for multidimensional singularity handling\ +\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationStrategies#738848244"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Duffy's coordinates strategy\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationStrategies#66551248"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Duffy's coordinates generalization and example implementation\ +\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationStrategies#354695682"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Ignoring the singularity\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationStrategies#74051012"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Automatic singularity handling \"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationStrategies#4135167"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Cauchy principal value integration\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationStrategies#295594003"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Double-Exponential Strategy\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationStrategies#526196975"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"MinRecursion and MaxRecursion\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationStrategies#168459464"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Comparison of double-exponential and Gaussian quadrature\"\>", + + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationStrategies#140889501"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Convergence rate\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationStrategies#175923852"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Example implementation of double-exponential quadrature\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationStrategies#5698822"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[BoxData[ + ButtonBox["\<\"\\\"Trapezoidal\\\" Strategy\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationStrategies#403370786"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Oscillatory Strategies\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationStrategies#775797877"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Finite Region Oscillatory Integration\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationStrategies#144042466"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Extrapolating Oscillatory Strategy \"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationStrategies#50593814"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Double-Exponential Oscillatory Integration\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationStrategies#48895312"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Generalized integrals\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationStrategies#188549426"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Non-algebraic multiplicand\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationStrategies#662597729"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Crude Monte Carlo and Quasi Monte Carlo Strategies\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationStrategies#20795380"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"AccuracyGoal and PrecisionGoal\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationStrategies#35773270"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"MaxPoints\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationStrategies#1551213"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"\\\"RandomSeed\\\"\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationStrategies#605699968"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Stratified crude Monte Carlo integration\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationStrategies#473354685"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Convergence speed up of the stratified Monte Carlo \ +integration\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationStrategies#40464370"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Global Adaptive Monte Carlo and Quasi Monte Carlo \ +Strategies\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationStrategies#65285686"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"MinRecursion and MaxRecursion\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationStrategies#61206936"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"\\\"Partitioning\\\"\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationStrategies#574188911"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"\\\"BisectionDithering\\\"\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationStrategies#193092152"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Choice of bisection axis\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationStrategies#744911582"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Example: Comparison with crude Monte Carlo\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationStrategies#718032232"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"\\\"MultiPeriodic\\\"\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationStrategies#107447537"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Comparison with \\\"MultiDimensionalRule\\\"\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationStrategies#161179452"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Preprocessors\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationStrategies#12996145"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"\\\"SymbolicPiecewiseSubdivision\\\"\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationStrategies#440163298"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"\\\"EvenOddSubdivision\\\"\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationStrategies#172715735"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"\\\"OscillatorySelection\\\"\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationStrategies#52803663"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"\\\"UnitCubeRescaling\\\"\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationStrategies#46192878"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"\\\"SymbolicPreprocessing\\\"\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationStrategies#188031681"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Examples and Applications\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationStrategies#31617981"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Closed-contour integrals\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationStrategies#184932443"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Fourier series calculation\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationStrategies#5688699"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True] +}, Closed]] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"NIntegrate Integration Rules\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationRules"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Introduction\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationRules#235359397"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Integration Rule Specification\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationRules#135207409"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"\\\"TrapezoidalRule\\\"\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationRules#618158740"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Romberg quadrature\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationRules#101738258"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"\\\"TrapezoidalRule\\\" sampling points and weights\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationRules#12731638"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"\\\"NewtonCotesRule\\\"\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationRules#81663330"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"\\\"NewtonCotesRule\\\" sampling points and weights\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationRules#617627612"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"\\\"GaussBerntsenEspelidRule\\\"\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationRules#141675390"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"\\\"GaussBerntsenEspelidRule\\\" sampling points and \ +weights\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationRules#165210023"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"\\\"GaussKronrodRule\\\"\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationRules#381359375"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"\\\"GaussKronrodRule\\\" sampling points and weights\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationRules#360328261"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"\\\"LobattoKronrodRule\\\"\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationRules#210486704"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"\\\"LobattoKronrodRule\\\" sampling points and weights\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationRules#49911002"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"\\\"ClenshawCurtisRule\\\"\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationRules#486402291"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"\\\"ClenshawCurtisRule\\\" sampling points and weights\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationRules#123359709"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"\\\"MultiPanelRule\\\"\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationRules#106389821"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"\\\"MultiPanelRule\\\" sampling points and weights\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationRules#362787930"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"\\\"CartesianRule\\\"\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationRules#650745857"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"\\\"CartesianRule\\\" sampling points and weights\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationRules#643860566"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"\\\"MultiDimensionalRule\\\"\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationRules#89177434"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"\\\"MultiDimensionalRule\\\" sampling points and weights\"\>", + + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationRules#810793694"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"\\\"MonteCarloRule\\\"\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationRules#430697921"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"\\\"AxisSelector\\\"\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationRules#364207621"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Comparisons of the Rules\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationRules#233261223"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Number of points in a rule\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationRules#6741536"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Rule comparison\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationRules#870846129"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Examples of Pathological Behavior\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationRules#8354729"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Tricking the error estimator\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationRules#81420002"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Phase errors \"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationRules#599865576"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[BoxData[ + ButtonBox["\<\"Index of Technical Terms\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateIntegrationRules#17191326"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[BoxData[ + ButtonBox["\<\"NIntegrate References\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NIntegrateReferences"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Constrained Optimization\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ConstrainedOptimizationOverview"], + Evaluator->Automatic, + Method->"Preemptive"]], "Section", + ShowGroupOpener->True], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Introduction\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ConstrainedOptimizationIntroduction#248488806"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Optimization Problems\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ConstrainedOptimizationIntroduction#248488806"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Global Optimization\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ConstrainedOptimizationIntroduction#170940268"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Local Optimization\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ConstrainedOptimizationIntroduction#171458460"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Solving Optimization Problems\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ConstrainedOptimizationIntroduction#32353590"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Linear Optimization\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ConstrainedOptimizationLinearProgramming#100661346"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Introduction\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ConstrainedOptimizationLinearProgramming#430238072"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"The LinearProgramming Function\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ConstrainedOptimizationLinearProgramming#113426546"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Options for LinearProgramming\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ConstrainedOptimizationLinearProgramming#40914068"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Examples\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ConstrainedOptimizationLinearProgramming#414335858"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Difference Between Interior Point and Simplex and/or Revised \ +Simplex\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ConstrainedOptimizationLinearProgramming#589526112"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Finding Dual Variables\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ConstrainedOptimizationLinearProgramming#224700240"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Dealing with Infeasibility and Unboundedness in the Interior \ +Point Method\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ConstrainedOptimizationLinearProgramming#512388034"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"The Method Options of \\\"InteriorPoint\\\"\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ConstrainedOptimizationLinearProgramming#605660219"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Importing Large Data Sets and Solving Large-Scale \ +Problems\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ConstrainedOptimizationLinearProgramming#9813130"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Importing MPS Formatted Files in Equation Form\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ConstrainedOptimizationLinearProgramming#208553956"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Large-Scale Problems: Importing in Matrix and Vector \ +Form\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ConstrainedOptimizationLinearProgramming#445507631"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Free Formatted MPS Files\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ConstrainedOptimizationLinearProgramming#298767088"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Application Examples of Linear Programming\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ConstrainedOptimizationLinearProgramming#261990371"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"L1 Norm Minimization\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ConstrainedOptimizationLinearProgramming#293106634"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Design of an Optimal Anchor\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ConstrainedOptimizationLinearProgramming#326994842"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Algorithms for Linear Programming\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ConstrainedOptimizationLinearProgramming#38991160"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Simplex and Revised Simplex Algorithms\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ConstrainedOptimizationLinearProgramming#160402625"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Interior Point Algorithm\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ConstrainedOptimizationLinearProgramming#155201634"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True] +}, Closed]] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Numerical Nonlinear Local Optimization\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ConstrainedOptimizationLocalNumerical#85183321"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Introduction\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ConstrainedOptimizationLocalNumerical#469184158"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"The FindMinimum Function\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ConstrainedOptimizationLocalNumerical#73716527"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Options for FindMinimum\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ConstrainedOptimizationLocalNumerical#396232162"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Examples of FindMinimum\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ConstrainedOptimizationLocalNumerical#804055587"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Finding a Global Minimum\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ConstrainedOptimizationLocalNumerical#92384034"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"An Application Example\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ConstrainedOptimizationLocalNumerical#609426104"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Limitations of Interior Point Method\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ConstrainedOptimizationLocalNumerical#417182119"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Numerical Algorithms for Constrained Local Optimization\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ConstrainedOptimizationLocalNumerical#442312913"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"The Interior Point Algorithm\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ConstrainedOptimizationLocalNumerical#2552526"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True] +}, Closed]] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Numerical Nonlinear Global Optimization\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ConstrainedOptimizationGlobalNumerical#85183321"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Introduction\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ConstrainedOptimizationGlobalNumerical#469184158"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"The NMinimize Function\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ConstrainedOptimizationGlobalNumerical#217856200"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Numerical Algorithms for Constrained Global Optimization\"\>", + + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ConstrainedOptimizationGlobalNumerical#252245038"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Nelder\[Dash]Mead\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ConstrainedOptimizationGlobalNumerical#323477034"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Differential Evolution\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ConstrainedOptimizationGlobalNumerical#24713453"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Simulated Annealing\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ConstrainedOptimizationGlobalNumerical#7062708"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Random Search\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ConstrainedOptimizationGlobalNumerical#155930577"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True] +}, Closed]] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Exact Global Optimization\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ConstrainedOptimizationExact#509267359"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Introduction\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ConstrainedOptimizationExact#412364824"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Algorithms\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ConstrainedOptimizationExact#248466559"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Optimization by Cylindrical Algebraic Decomposition\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ConstrainedOptimizationExact#828680012"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Examples\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ConstrainedOptimizationExact#370765765"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Customized CAD Algorithm for Optimization\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ConstrainedOptimizationExact#4979907"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Reduction to Minimizing a Coordinate Function\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ConstrainedOptimizationExact#211764667"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"The Projection Phase of CAD\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ConstrainedOptimizationExact#215663124"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"The Lifting Phase of CAD\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ConstrainedOptimizationExact#431999683"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Strict Inequality Constraints\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ConstrainedOptimizationExact#289075302"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[BoxData[ + ButtonBox["\<\"Linear Optimization\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ConstrainedOptimizationExact#765665707"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Univariate Optimization\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ConstrainedOptimizationExact#132591628"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Optimization by Finding Stationary and Singular Points\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ConstrainedOptimizationExact#60567692"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Optimization over the Integers\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ConstrainedOptimizationExact#7488435"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Integer Linear Programming\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ConstrainedOptimizationExact#683534434"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Optimization over the Reals Combined with Integer Solution \ +Finding\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ConstrainedOptimizationExact#544345886"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True] +}, Closed]] +}, Closed]], + +Cell[BoxData[ + ButtonBox["\<\"Comparison of Constrained Optimization Functions\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ConstrainedOptimizationComparison#85183321"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Constrained Optimization References\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/ConstrainedOptimizationReferences"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Unconstrained Optimization\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/UnconstrainedOptimizationOverview"], + Evaluator->Automatic, + Method->"Preemptive"]], "Section", + ShowGroupOpener->True], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Introduction\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/UnconstrainedOptimizationIntroduction#509267359"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Introduction\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/UnconstrainedOptimizationIntroductionLocalMinimization#\ +509267359"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Newton's Method\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/UnconstrainedOptimizationNewtonsMethodMinimum#509267359"], + + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Quasi-Newton Methods\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/UnconstrainedOptimizationQuasiNewtonMethods#509267359"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Gauss-Newton Methods\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/UnconstrainedOptimizationGaussNewtonMethods#509267359"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Nonlinear Conjugate Gradient Methods\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/UnconstrainedOptimizationConjugateGradientMethods#\ +509267359"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Principal Axis Method\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/UnconstrainedOptimizationPrincipalAxisMethod#509267359"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Introduction\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/UnconstrainedOptimizationIntroductionNonlinearEquations#\ +771134545"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Newton\[CloseCurlyQuote]s Method\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/UnconstrainedOptimizationNewtonsMethodRoot#456855863"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"The Secant Method\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/UnconstrainedOptimizationSecantMethod#798406094"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Brent\[CloseCurlyQuote]s Method\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/UnconstrainedOptimizationBrentsMethod#1562437747"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Introduction\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/UnconstrainedOptimizationIntroductionStepControl#\ +1034146184"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Line Search Methods\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/UnconstrainedOptimizationLineSearchMethods#1542627801"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Trust Region Methods\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/UnconstrainedOptimizationTrustRegionMethods#2058254571"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Specifying Derivatives\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/UnconstrainedOptimizationSpecifyingDerivatives#562305099"]\ +, + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Variables and Starting Conditions\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/UnconstrainedOptimizationVariablesAndStartingConditions#\ +1302289373"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Termination Conditions\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/UnconstrainedOptimizationTerminationConditions#\ +1953968666"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Symbolic Evaluation\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/UnconstrainedOptimizationSymbolicEvaluation#147397427"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Plotting Search Data\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/UnconstrainedOptimizationPlottingSearchData#982979262"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Test Problems\"\>", + Appearance->None, + BaseStyle->{"Subsubsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/UnconstrainedOptimizationTestProblems#1407764050"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsubsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[BoxData[ + ButtonBox["\<\"References\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/UnconstrainedOptimizationReferences"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Mathematical and Other Notation\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/MathematicalAndOtherNotationOverview"], + Evaluator->Automatic, + Method->"Preemptive"]], "Section", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Special Characters\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/SpecialCharacters-MathematicalAndOtherNotation"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Names of Symbols and Mathematical Objects\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/NamesOfSymbolsAndMathematicalObjects"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Letters and Letter\[Hyphen]like Forms\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LettersAndLetterLikeForms"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Greek Letters\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LettersAndLetterLikeForms"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Variants of English Letters\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LettersAndLetterLikeForms#15689"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Hebrew Letters\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LettersAndLetterLikeForms#15174"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Units and Letter\[Hyphen]like Mathematical Symbols\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LettersAndLetterLikeForms#10882"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Shapes, Icons and Geometrical Constructs\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LettersAndLetterLikeForms#5485"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Textual Elements\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LettersAndLetterLikeForms#28815"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Extended Latin Letters\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/LettersAndLetterLikeForms#6089"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + ButtonBox["\<\"Operators\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup["paclet:tutorial/Operators"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Basic Mathematical Operators\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup["paclet:tutorial/Operators"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Operators in Calculus and Algebra\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup["paclet:tutorial/Operators#29358"], + + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Logical and Other Connectives\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup["paclet:tutorial/Operators#23281"], + + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Operators Used to Represent Actions\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup["paclet:tutorial/Operators#292"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Bracketing Operators\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup["paclet:tutorial/Operators#14771"], + + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Operators Used to Represent Relations\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup["paclet:tutorial/Operators#26299"], + + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True], + +Cell[BoxData[ + ButtonBox["\<\"Operators Based on Arrows and Vectors\"\>", + Appearance->None, + BaseStyle->{"Subsubsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup["paclet:tutorial/Operators#27644"], + + Evaluator->Automatic, + Method->"Preemptive"]], "Subsubsection", + ShowGroupOpener->True] +}, Closed]], + +Cell[BoxData[ + ButtonBox["\<\"Structural Elements and Keyboard Characters\"\>", + Appearance->None, + BaseStyle->{"Subsection", ShowStringCharacters -> False}, + ButtonFrame->None, + ButtonFunction:>Documentation`HelpLookup[ + "paclet:tutorial/StructuralElementsAndKeyboardCharacters"], + Evaluator->Automatic, + Method->"Preemptive"]], "Subsection", + ShowGroupOpener->True] +}, Closed]] +}, Closed]] +}, Open ]] +}, +WindowSize->{810, 774}, +WindowMargins->{{Automatic, 292}, {158, Automatic}}, +FrontEndVersion->"6.0 for Microsoft Windows (32-bit) (June 19, 2007)", +StyleDefinitions->FrontEnd`FileName[{"Book"}, "Textbook.nb", + CharacterEncoding -> "WindowsANSI"] +] +(* End of Notebook Content *) + +(* Internal cache information *) +(*CellTagsOutline +CellTagsIndex->{} +*) +(*CellTagsIndex +CellTagsIndex->{} +*) +(*NotebookFileOutline +Notebook[{ +Cell[CellGroupData[{ +Cell[590, 23, 50, 0, 203, "Title"], +Cell[643, 25, 184, 4, 102, "Author"], +Cell[CellGroupData[{ +Cell[852, 33, 133, 2, 108, "Subtitle"], +Cell[CellGroupData[{ +Cell[1010, 39, 335, 9, 81, "Section"], +Cell[1348, 50, 330, 9, 51, "Subsection"], +Cell[1681, 61, 341, 9, 36, "Subsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[2059, 75, 344, 9, 81, "Section"], +Cell[2406, 86, 343, 9, 51, "Subsection"], +Cell[2752, 97, 363, 9, 36, "Subsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[3152, 111, 367, 9, 81, "Section"], +Cell[3522, 122, 323, 9, 51, "Subsection"], +Cell[3848, 133, 314, 8, 36, "Subsection"], +Cell[4165, 143, 329, 9, 36, "Subsection"], +Cell[4497, 154, 318, 8, 36, "Subsection"], +Cell[4818, 164, 316, 8, 36, "Subsection"], +Cell[5137, 174, 318, 8, 36, "Subsection"], +Cell[5458, 184, 330, 9, 36, "Subsection"], +Cell[5791, 195, 326, 9, 36, "Subsection"], +Cell[6120, 206, 328, 9, 36, "Subsection"], +Cell[6451, 217, 330, 9, 36, "Subsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[6818, 231, 341, 9, 81, "Section"], +Cell[7162, 242, 309, 8, 51, "Subsection"], +Cell[7474, 252, 348, 9, 36, "Subsection"], +Cell[7825, 263, 345, 9, 36, "Subsection"], +Cell[8173, 274, 363, 9, 36, "Subsection"], +Cell[8539, 285, 318, 8, 36, "Subsection"], +Cell[8860, 295, 344, 9, 36, "Subsection"], +Cell[9207, 306, 380, 9, 36, "Subsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[9624, 320, 344, 9, 81, "Section"], +Cell[9971, 331, 335, 9, 51, "Subsection"], +Cell[10309, 342, 328, 9, 36, "Subsection"], +Cell[10640, 353, 336, 9, 36, "Subsection"], +Cell[10979, 364, 350, 9, 36, "Subsection"], +Cell[11332, 375, 373, 9, 36, "Subsection"], +Cell[11708, 386, 337, 9, 36, "Subsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[12082, 400, 351, 9, 81, "Section"], +Cell[12436, 411, 346, 9, 51, "Subsection"], +Cell[12785, 422, 362, 9, 36, "Subsection"], +Cell[13150, 433, 353, 9, 36, "Subsection"], +Cell[13506, 444, 352, 9, 36, "Subsection"], +Cell[13861, 455, 335, 9, 36, "Subsection"], +Cell[14199, 466, 342, 9, 36, "Subsection"], +Cell[14544, 477, 375, 9, 36, "Subsection"], +Cell[14922, 488, 332, 9, 36, "Subsection"], +Cell[15257, 499, 333, 9, 36, "Subsection"], +Cell[15593, 510, 342, 9, 36, "Subsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[15972, 524, 341, 9, 81, "Section"], +Cell[16316, 535, 332, 9, 51, "Subsection"], +Cell[16651, 546, 327, 9, 36, "Subsection"], +Cell[16981, 557, 359, 9, 36, "Subsection"], +Cell[17343, 568, 357, 9, 36, "Subsection"], +Cell[17703, 579, 369, 9, 36, "Subsection"], +Cell[18075, 590, 347, 9, 36, "Subsection"], +Cell[18425, 601, 374, 9, 36, "Subsection"], +Cell[18802, 612, 376, 9, 36, "Subsection"], +Cell[19181, 623, 340, 9, 36, "Subsection"], +Cell[19524, 634, 345, 9, 36, "Subsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[19906, 648, 337, 9, 81, "Section"], +Cell[20246, 659, 344, 9, 51, "Subsection"], +Cell[20593, 670, 311, 8, 36, "Subsection"], +Cell[20907, 680, 324, 9, 36, "Subsection"], +Cell[21234, 691, 307, 8, 36, "Subsection"], +Cell[21544, 701, 354, 9, 36, "Subsection"], +Cell[21901, 712, 326, 9, 36, "Subsection"], +Cell[22230, 723, 337, 9, 36, "Subsection"], +Cell[22570, 734, 343, 9, 36, "Subsection"], +Cell[22916, 745, 312, 8, 36, "Subsection"], +Cell[23231, 755, 301, 8, 36, "Subsection"], +Cell[23535, 765, 330, 9, 36, "Subsection"], +Cell[23868, 776, 355, 9, 36, "Subsection"], +Cell[24226, 787, 378, 9, 36, "Subsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[24641, 801, 339, 9, 81, "Section"], +Cell[24983, 812, 345, 9, 51, "Subsection"], +Cell[25331, 823, 364, 9, 36, "Subsection"], +Cell[25698, 834, 343, 9, 36, "Subsection"], +Cell[26044, 845, 355, 9, 36, "Subsection"], +Cell[26402, 856, 345, 9, 36, "Subsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[26784, 870, 340, 9, 81, "Section"], +Cell[27127, 881, 328, 9, 51, "Subsection"], +Cell[27458, 892, 337, 9, 36, "Subsection"], +Cell[27798, 903, 334, 9, 36, "Subsection"], +Cell[28135, 914, 358, 9, 36, "Subsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[28530, 928, 304, 8, 81, "Section"], +Cell[28837, 938, 345, 9, 51, "Subsection"], +Cell[29185, 949, 336, 9, 36, "Subsection"], +Cell[29524, 960, 331, 9, 36, "Subsection"], +Cell[29858, 971, 336, 9, 36, "Subsection"], +Cell[30197, 982, 359, 9, 36, "Subsection"], +Cell[30559, 993, 375, 9, 36, "Subsection"], +Cell[30937, 1004, 318, 8, 36, "Subsection"], +Cell[31258, 1014, 313, 8, 36, "Subsection"], +Cell[31574, 1024, 326, 9, 36, "Subsection"], +Cell[31903, 1035, 368, 9, 36, "Subsection"], +Cell[32274, 1046, 324, 9, 36, "Subsection"], +Cell[32601, 1057, 339, 9, 36, "Subsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[32977, 1071, 332, 9, 81, "Section"], +Cell[33312, 1082, 316, 8, 51, "Subsection"], +Cell[33631, 1092, 316, 8, 36, "Subsection"], +Cell[33950, 1102, 348, 9, 36, "Subsection"], +Cell[34301, 1113, 332, 9, 36, "Subsection"], +Cell[34636, 1124, 360, 9, 36, "Subsection"], +Cell[34999, 1135, 334, 9, 36, "Subsection"], +Cell[35336, 1146, 323, 9, 36, "Subsection"], +Cell[35662, 1157, 327, 9, 36, "Subsection"], +Cell[35992, 1168, 299, 8, 36, "Subsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[36328, 1181, 345, 9, 81, "Section"], +Cell[36676, 1192, 338, 9, 51, "Subsection"], +Cell[37017, 1203, 332, 9, 36, "Subsection"], +Cell[CellGroupData[{ +Cell[37374, 1216, 347, 9, 36, "Subsection"], +Cell[37724, 1227, 355, 9, 31, "Subsubsection"], +Cell[38082, 1238, 363, 9, 31, "Subsubsection"], +Cell[38448, 1249, 350, 9, 31, "Subsubsection"], +Cell[38801, 1260, 349, 9, 31, "Subsubsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[39187, 1274, 347, 9, 51, "Subsection"], +Cell[39537, 1285, 345, 9, 31, "Subsubsection"], +Cell[39885, 1296, 363, 9, 31, "Subsubsection"], +Cell[40251, 1307, 350, 9, 31, "Subsubsection"], +Cell[40604, 1318, 347, 9, 31, "Subsubsection"], +Cell[40954, 1329, 366, 9, 31, "Subsubsection"], +Cell[41323, 1340, 353, 9, 31, "Subsubsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[41713, 1354, 368, 9, 51, "Subsection"], +Cell[42084, 1365, 357, 9, 31, "Subsubsection"], +Cell[42444, 1376, 342, 9, 31, "Subsubsection"], +Cell[42789, 1387, 348, 9, 31, "Subsubsection"] +}, Closed]], +Cell[43152, 1399, 341, 9, 51, "Subsection"], +Cell[CellGroupData[{ +Cell[43518, 1412, 353, 9, 36, "Subsection"], +Cell[43874, 1423, 347, 9, 31, "Subsubsection"], +Cell[44224, 1434, 390, 9, 31, "Subsubsection"], +Cell[44617, 1445, 371, 9, 31, "Subsubsection"], +Cell[44991, 1456, 360, 9, 31, "Subsubsection"] +}, Closed]] +}, Closed]], +Cell[CellGroupData[{ +Cell[45400, 1471, 352, 9, 81, "Section"], +Cell[45755, 1482, 335, 9, 51, "Subsection"], +Cell[46093, 1493, 358, 9, 36, "Subsection"], +Cell[46454, 1504, 398, 10, 36, "Subsection"], +Cell[46855, 1516, 326, 9, 36, "Subsection"], +Cell[47184, 1527, 346, 9, 36, "Subsection"], +Cell[47533, 1538, 360, 9, 36, "Subsection"], +Cell[47896, 1549, 369, 9, 36, "Subsection"], +Cell[48268, 1560, 345, 9, 36, "Subsection"], +Cell[48616, 1571, 338, 9, 36, "Subsection"], +Cell[48957, 1582, 379, 9, 36, "Subsection"], +Cell[49339, 1593, 333, 9, 36, "Subsection"], +Cell[49675, 1604, 330, 9, 36, "Subsection"], +Cell[50008, 1615, 360, 9, 36, "Subsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[50405, 1629, 353, 9, 81, "Section"], +Cell[50761, 1640, 378, 9, 51, "Subsection"], +Cell[51142, 1651, 350, 9, 36, "Subsection"], +Cell[51495, 1662, 346, 9, 36, "Subsection"], +Cell[51844, 1673, 348, 9, 36, "Subsection"], +Cell[52195, 1684, 346, 9, 36, "Subsection"], +Cell[52544, 1695, 353, 9, 36, "Subsection"], +Cell[52900, 1706, 361, 9, 36, "Subsection"], +Cell[53264, 1717, 382, 9, 36, "Subsection"], +Cell[53649, 1728, 341, 9, 36, "Subsection"], +Cell[53993, 1739, 305, 8, 36, "Subsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[54335, 1752, 351, 9, 81, "Section"], +Cell[54689, 1763, 386, 9, 51, "Subsection"], +Cell[55078, 1774, 345, 9, 36, "Subsection"], +Cell[55426, 1785, 348, 9, 36, "Subsection"], +Cell[55777, 1796, 367, 9, 36, "Subsection"], +Cell[56147, 1807, 339, 9, 36, "Subsection"] +}, Closed]] +}, Closed]], +Cell[CellGroupData[{ +Cell[56535, 1822, 119, 2, 67, "Subtitle"], +Cell[CellGroupData[{ +Cell[56679, 1828, 320, 9, 81, "Section"], +Cell[57002, 1839, 344, 9, 51, "Subsection"], +Cell[57349, 1850, 342, 9, 36, "Subsection"], +Cell[57694, 1861, 355, 9, 36, "Subsection"], +Cell[58052, 1872, 331, 9, 36, "Subsection"], +Cell[58386, 1883, 360, 9, 36, "Subsection"], +Cell[58749, 1894, 331, 9, 36, "Subsection"], +Cell[59083, 1905, 333, 9, 36, "Subsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[59453, 1919, 339, 9, 81, "Section"], +Cell[59795, 1930, 348, 9, 51, "Subsection"], +Cell[60146, 1941, 349, 9, 36, "Subsection"], +Cell[60498, 1952, 385, 9, 36, "Subsection"], +Cell[60886, 1963, 372, 9, 36, "Subsection"], +Cell[61261, 1974, 316, 8, 36, "Subsection"], +Cell[61580, 1984, 348, 9, 36, "Subsection"], +Cell[61931, 1995, 378, 9, 36, "Subsection"], +Cell[62312, 2006, 373, 9, 36, "Subsection"], +Cell[62688, 2017, 335, 9, 36, "Subsection"], +Cell[63026, 2028, 334, 9, 36, "Subsection"], +Cell[63363, 2039, 307, 8, 36, "Subsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[63707, 2052, 314, 9, 81, "Section"], +Cell[64024, 2063, 326, 9, 51, "Subsection"], +Cell[64353, 2074, 368, 9, 36, "Subsection"], +Cell[64724, 2085, 340, 9, 36, "Subsection"], +Cell[65067, 2096, 372, 9, 36, "Subsection"], +Cell[65442, 2107, 352, 9, 36, "Subsection"], +Cell[65797, 2118, 353, 9, 36, "Subsection"], +Cell[66153, 2129, 326, 9, 36, "Subsection"], +Cell[66482, 2140, 346, 9, 36, "Subsection"], +Cell[66831, 2151, 376, 9, 36, "Subsection"], +Cell[67210, 2162, 350, 9, 36, "Subsection"], +Cell[67563, 2173, 376, 9, 36, "Subsection"], +Cell[67942, 2184, 326, 9, 36, "Subsection"], +Cell[68271, 2195, 326, 9, 36, "Subsection"], +Cell[68600, 2206, 375, 9, 36, "Subsection"], +Cell[68978, 2217, 386, 9, 36, "Subsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[69401, 2231, 351, 9, 81, "Section"], +Cell[69755, 2242, 338, 9, 51, "Subsection"], +Cell[70096, 2253, 351, 9, 36, "Subsection"], +Cell[70450, 2264, 347, 9, 36, "Subsection"], +Cell[70800, 2275, 369, 9, 36, "Subsection"], +Cell[CellGroupData[{ +Cell[71194, 2288, 357, 9, 36, "Subsection"], +Cell[71554, 2299, 346, 9, 31, "Subsubsection"], +Cell[71903, 2310, 345, 9, 31, "Subsubsection"], +Cell[72251, 2321, 343, 9, 31, "Subsubsection"], +Cell[72597, 2332, 353, 9, 31, "Subsubsection"], +Cell[72953, 2343, 348, 9, 31, "Subsubsection"], +Cell[73304, 2354, 345, 9, 31, "Subsubsection"], +Cell[73652, 2365, 345, 9, 31, "Subsubsection"], +Cell[74000, 2376, 351, 9, 31, "Subsubsection"], +Cell[74354, 2387, 345, 9, 31, "Subsubsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[74736, 2401, 342, 9, 51, "Subsection"], +Cell[75081, 2412, 341, 9, 31, "Subsubsection"], +Cell[75425, 2423, 340, 9, 31, "Subsubsection"], +Cell[75768, 2434, 344, 9, 31, "Subsubsection"], +Cell[76115, 2445, 343, 9, 31, "Subsubsection"], +Cell[76461, 2456, 345, 9, 31, "Subsubsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[76843, 2470, 339, 9, 51, "Subsection"], +Cell[77185, 2481, 351, 9, 31, "Subsubsection"], +Cell[77539, 2492, 352, 9, 31, "Subsubsection"], +Cell[77894, 2503, 346, 9, 31, "Subsubsection"], +Cell[78243, 2514, 344, 9, 31, "Subsubsection"], +Cell[78590, 2525, 352, 9, 31, "Subsubsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[78979, 2539, 366, 9, 51, "Subsection"], +Cell[79348, 2550, 375, 9, 31, "Subsubsection"], +Cell[79726, 2561, 360, 9, 31, "Subsubsection"], +Cell[80089, 2572, 357, 9, 31, "Subsubsection"], +Cell[80449, 2583, 363, 9, 31, "Subsubsection"], +Cell[80815, 2594, 388, 9, 31, "Subsubsection"] +}, Closed]], +Cell[81218, 2606, 350, 9, 51, "Subsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[81605, 2620, 333, 9, 81, "Section"], +Cell[81941, 2631, 328, 9, 51, "Subsection"], +Cell[82272, 2642, 359, 9, 36, "Subsection"], +Cell[82634, 2653, 312, 8, 36, "Subsection"], +Cell[82949, 2663, 350, 9, 36, "Subsection"], +Cell[83302, 2674, 336, 9, 36, "Subsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[83675, 2688, 367, 9, 81, "Section"], +Cell[84045, 2699, 349, 9, 51, "Subsection"], +Cell[84397, 2710, 371, 9, 36, "Subsection"], +Cell[84771, 2721, 328, 9, 36, "Subsection"], +Cell[85102, 2732, 344, 9, 36, "Subsection"], +Cell[85449, 2743, 365, 9, 36, "Subsection"], +Cell[85817, 2754, 354, 9, 36, "Subsection"], +Cell[86174, 2765, 344, 9, 36, "Subsection"], +Cell[86521, 2776, 356, 9, 36, "Subsection"], +Cell[86880, 2787, 379, 9, 36, "Subsection"], +Cell[87262, 2798, 381, 9, 36, "Subsection"], +Cell[87646, 2809, 341, 9, 36, "Subsection"], +Cell[87990, 2820, 354, 9, 36, "Subsection"], +Cell[88347, 2831, 339, 9, 36, "Subsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[88723, 2845, 346, 9, 81, "Section"], +Cell[89072, 2856, 339, 9, 51, "Subsection"], +Cell[89414, 2867, 374, 9, 36, "Subsection"], +Cell[89791, 2878, 309, 8, 36, "Subsection"], +Cell[90103, 2888, 356, 9, 36, "Subsection"], +Cell[90462, 2899, 336, 9, 36, "Subsection"], +Cell[90801, 2910, 377, 9, 36, "Subsection"], +Cell[91181, 2921, 356, 9, 36, "Subsection"], +Cell[91540, 2932, 313, 8, 36, "Subsection"], +Cell[91856, 2942, 346, 9, 36, "Subsection"], +Cell[92205, 2953, 370, 9, 36, "Subsection"], +Cell[92578, 2964, 328, 9, 36, "Subsection"], +Cell[92909, 2975, 331, 9, 36, "Subsection"], +Cell[93243, 2986, 353, 9, 36, "Subsection"], +Cell[93599, 2997, 333, 9, 36, "Subsection"], +Cell[93935, 3008, 357, 9, 36, "Subsection"], +Cell[94295, 3019, 343, 9, 36, "Subsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[94675, 3033, 363, 9, 81, "Section"], +Cell[95041, 3044, 344, 9, 51, "Subsection"], +Cell[95388, 3055, 318, 8, 36, "Subsection"], +Cell[95709, 3065, 319, 8, 36, "Subsection"], +Cell[96031, 3075, 362, 9, 36, "Subsection"], +Cell[96396, 3086, 350, 9, 36, "Subsection"], +Cell[96749, 3097, 336, 9, 36, "Subsection"], +Cell[97088, 3108, 346, 9, 36, "Subsection"], +Cell[97437, 3119, 305, 8, 36, "Subsection"], +Cell[97745, 3129, 333, 9, 36, "Subsection"], +Cell[98081, 3140, 352, 9, 36, "Subsection"], +Cell[98436, 3151, 348, 9, 36, "Subsection"], +Cell[98787, 3162, 370, 9, 36, "Subsection"], +Cell[99160, 3173, 368, 9, 36, "Subsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[99565, 3187, 340, 9, 81, "Section"], +Cell[99908, 3198, 333, 9, 51, "Subsection"], +Cell[100244, 3209, 333, 9, 36, "Subsection"], +Cell[100580, 3220, 333, 9, 36, "Subsection"], +Cell[100916, 3231, 318, 8, 36, "Subsection"], +Cell[101237, 3241, 330, 9, 36, "Subsection"], +Cell[101570, 3252, 349, 9, 36, "Subsection"], +Cell[101922, 3263, 345, 9, 36, "Subsection"], +Cell[102270, 3274, 318, 8, 36, "Subsection"], +Cell[102591, 3284, 337, 9, 36, "Subsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[102965, 3298, 343, 9, 81, "Section"], +Cell[103311, 3309, 339, 9, 51, "Subsection"], +Cell[103653, 3320, 339, 9, 36, "Subsection"], +Cell[103995, 3331, 359, 9, 36, "Subsection"], +Cell[104357, 3342, 359, 9, 36, "Subsection"], +Cell[104719, 3353, 338, 9, 36, "Subsection"], +Cell[105060, 3364, 358, 9, 36, "Subsection"], +Cell[105421, 3375, 342, 9, 36, "Subsection"], +Cell[CellGroupData[{ +Cell[105788, 3388, 329, 9, 36, "Subsection"], +Cell[106120, 3399, 350, 9, 31, "Subsubsection"] +}, Closed]], +Cell[106485, 3411, 341, 9, 51, "Subsection"], +Cell[106829, 3422, 359, 9, 36, "Subsection"], +Cell[107191, 3433, 385, 9, 36, "Subsection"], +Cell[107579, 3444, 364, 9, 36, "Subsection"], +Cell[107946, 3455, 367, 9, 36, "Subsection"], +Cell[108316, 3466, 337, 9, 36, "Subsection"], +Cell[108656, 3477, 360, 9, 36, "Subsection"], +Cell[109019, 3488, 351, 9, 36, "Subsection"], +Cell[109373, 3499, 323, 9, 36, "Subsection"], +Cell[109699, 3510, 305, 8, 36, "Subsection"], +Cell[110007, 3520, 336, 9, 36, "Subsection"], +Cell[110346, 3531, 340, 9, 36, "Subsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[110723, 3545, 363, 9, 81, "Section"], +Cell[111089, 3556, 340, 9, 51, "Subsection"], +Cell[111432, 3567, 356, 9, 36, "Subsection"], +Cell[111791, 3578, 352, 9, 36, "Subsection"], +Cell[112146, 3589, 382, 9, 36, "Subsection"], +Cell[112531, 3600, 356, 9, 36, "Subsection"], +Cell[112890, 3611, 348, 9, 36, "Subsection"], +Cell[113241, 3622, 340, 9, 36, "Subsection"], +Cell[113584, 3633, 364, 9, 36, "Subsection"], +Cell[113951, 3644, 364, 9, 36, "Subsection"], +Cell[114318, 3655, 386, 9, 36, "Subsection"], +Cell[114707, 3666, 352, 9, 36, "Subsection"], +Cell[115062, 3677, 360, 9, 36, "Subsection"], +Cell[115425, 3688, 375, 9, 36, "Subsection"], +Cell[115803, 3699, 345, 9, 36, "Subsection"], +Cell[116151, 3710, 346, 9, 36, "Subsection"], +Cell[116500, 3721, 344, 9, 36, "Subsection"], +Cell[116847, 3732, 348, 9, 36, "Subsection"], +Cell[117198, 3743, 348, 9, 36, "Subsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[117583, 3757, 341, 9, 81, "Section"], +Cell[117927, 3768, 354, 9, 51, "Subsection"], +Cell[118284, 3779, 362, 9, 36, "Subsection"], +Cell[118649, 3790, 365, 9, 36, "Subsection"], +Cell[119017, 3801, 371, 9, 36, "Subsection"], +Cell[119391, 3812, 392, 9, 36, "Subsection"], +Cell[119786, 3823, 334, 9, 36, "Subsection"], +Cell[120123, 3834, 377, 9, 36, "Subsection"], +Cell[120503, 3845, 324, 9, 36, "Subsection"], +Cell[120830, 3856, 332, 9, 36, "Subsection"], +Cell[121165, 3867, 366, 9, 36, "Subsection"], +Cell[121534, 3878, 333, 9, 36, "Subsection"], +Cell[121870, 3889, 352, 9, 36, "Subsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[122259, 3903, 330, 9, 81, "Section"], +Cell[122592, 3914, 363, 9, 51, "Subsection"], +Cell[122958, 3925, 326, 9, 36, "Subsection"], +Cell[123287, 3936, 371, 9, 36, "Subsection"], +Cell[123661, 3947, 338, 9, 36, "Subsection"], +Cell[124002, 3958, 327, 9, 36, "Subsection"], +Cell[124332, 3969, 358, 9, 36, "Subsection"], +Cell[124693, 3980, 348, 9, 36, "Subsection"], +Cell[125044, 3991, 331, 9, 36, "Subsection"], +Cell[125378, 4002, 318, 8, 36, "Subsection"], +Cell[125699, 4012, 348, 9, 36, "Subsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[126084, 4026, 380, 9, 81, "Section"], +Cell[126467, 4037, 330, 9, 51, "Subsection"], +Cell[126800, 4048, 396, 10, 36, "Subsection"], +Cell[127199, 4060, 405, 10, 36, "Subsection"], +Cell[127607, 4072, 375, 9, 36, "Subsection"], +Cell[127985, 4083, 354, 9, 36, "Subsection"], +Cell[128342, 4094, 405, 10, 36, "Subsection"], +Cell[128750, 4106, 370, 9, 36, "Subsection"], +Cell[129123, 4117, 384, 9, 36, "Subsection"], +Cell[129510, 4128, 361, 9, 36, "Subsection"], +Cell[129874, 4139, 372, 9, 36, "Subsection"], +Cell[130249, 4150, 379, 9, 36, "Subsection"], +Cell[130631, 4161, 346, 9, 36, "Subsection"], +Cell[130980, 4172, 389, 9, 36, "Subsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[131406, 4186, 370, 9, 81, "Section"], +Cell[131779, 4197, 313, 8, 51, "Subsection"], +Cell[132095, 4207, 303, 8, 36, "Subsection"], +Cell[132401, 4217, 326, 9, 36, "Subsection"], +Cell[132730, 4228, 341, 9, 36, "Subsection"], +Cell[133074, 4239, 332, 9, 36, "Subsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[133443, 4253, 378, 9, 81, "Section"], +Cell[133824, 4264, 322, 8, 31, "Subsubsection"], +Cell[134149, 4274, 332, 9, 31, "Subsubsection"], +Cell[134484, 4285, 329, 9, 31, "Subsubsection"], +Cell[134816, 4296, 322, 8, 31, "Subsubsection"], +Cell[135141, 4306, 332, 9, 31, "Subsubsection"], +Cell[135476, 4317, 364, 9, 31, "Subsubsection"], +Cell[CellGroupData[{ +Cell[135865, 4330, 342, 9, 31, "Subsubsection"], +Cell[136210, 4341, 368, 9, 31, "Subsubsubsection"], +Cell[136581, 4352, 366, 9, 26, "Subsubsubsection"], +Cell[136950, 4363, 371, 9, 26, "Subsubsubsection"], +Cell[137324, 4374, 362, 9, 26, "Subsubsubsection"], +Cell[137689, 4385, 362, 9, 26, "Subsubsubsection"], +Cell[138054, 4396, 355, 9, 26, "Subsubsubsection"], +Cell[138412, 4407, 380, 9, 26, "Subsubsubsection"], +Cell[138795, 4418, 378, 9, 26, "Subsubsubsection"], +Cell[139176, 4429, 383, 9, 26, "Subsubsubsection"], +Cell[139562, 4440, 374, 9, 26, "Subsubsubsection"], +Cell[139939, 4451, 374, 9, 26, "Subsubsubsection"], +Cell[140316, 4462, 347, 9, 26, "Subsubsubsection"], +Cell[140666, 4473, 367, 9, 26, "Subsubsubsection"], +Cell[141036, 4484, 368, 9, 26, "Subsubsubsection"], +Cell[141407, 4495, 366, 9, 26, "Subsubsubsection"], +Cell[141776, 4506, 371, 9, 26, "Subsubsubsection"], +Cell[142150, 4517, 362, 9, 26, "Subsubsubsection"], +Cell[142515, 4528, 362, 9, 26, "Subsubsubsection"], +Cell[142880, 4539, 355, 9, 26, "Subsubsubsection"] +}, Closed]] +}, Closed]], +Cell[CellGroupData[{ +Cell[143284, 4554, 385, 9, 81, "Section"], +Cell[143672, 4565, 368, 9, 31, "Subsubsubsection"], +Cell[144043, 4576, 366, 9, 26, "Subsubsubsection"], +Cell[144412, 4587, 371, 9, 26, "Subsubsubsection"], +Cell[144786, 4598, 362, 9, 26, "Subsubsubsection"], +Cell[145151, 4609, 362, 9, 26, "Subsubsubsection"], +Cell[145516, 4620, 355, 9, 26, "Subsubsubsection"], +Cell[145874, 4631, 380, 9, 26, "Subsubsubsection"], +Cell[146257, 4642, 378, 9, 26, "Subsubsubsection"], +Cell[146638, 4653, 383, 9, 26, "Subsubsubsection"], +Cell[147024, 4664, 374, 9, 26, "Subsubsubsection"], +Cell[147401, 4675, 374, 9, 26, "Subsubsubsection"], +Cell[147778, 4686, 347, 9, 26, "Subsubsubsection"], +Cell[148128, 4697, 367, 9, 26, "Subsubsubsection"], +Cell[148498, 4708, 368, 9, 26, "Subsubsubsection"], +Cell[148869, 4719, 366, 9, 26, "Subsubsubsection"], +Cell[149238, 4730, 371, 9, 26, "Subsubsubsection"], +Cell[149612, 4741, 362, 9, 26, "Subsubsubsection"], +Cell[149977, 4752, 362, 9, 26, "Subsubsubsection"], +Cell[150342, 4763, 355, 9, 26, "Subsubsubsection"] +}, Closed]] +}, Closed]], +Cell[CellGroupData[{ +Cell[150746, 4778, 129, 2, 67, "Subtitle"], +Cell[CellGroupData[{ +Cell[150900, 4784, 311, 9, 81, "Section"], +Cell[151214, 4795, 319, 8, 51, "Subsection"], +Cell[151536, 4805, 328, 9, 36, "Subsection"], +Cell[151867, 4816, 324, 9, 36, "Subsection"], +Cell[152194, 4827, 330, 9, 36, "Subsection"], +Cell[152527, 4838, 353, 9, 36, "Subsection"], +Cell[152883, 4849, 349, 9, 36, "Subsection"], +Cell[153235, 4860, 330, 9, 36, "Subsection"], +Cell[153568, 4871, 358, 9, 36, "Subsection"], +Cell[153929, 4882, 355, 9, 36, "Subsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[154321, 4896, 341, 9, 49, "Section"], +Cell[154665, 4907, 328, 9, 51, "Subsection"], +Cell[154996, 4918, 330, 9, 36, "Subsection"], +Cell[155329, 4929, 330, 9, 36, "Subsection"], +Cell[155662, 4940, 332, 9, 36, "Subsection"], +Cell[155997, 4951, 367, 9, 36, "Subsection"], +Cell[156367, 4962, 338, 9, 36, "Subsection"], +Cell[156708, 4973, 361, 9, 36, "Subsection"], +Cell[157072, 4984, 367, 9, 36, "Subsection"], +Cell[157442, 4995, 336, 9, 36, "Subsection"], +Cell[157781, 5006, 336, 9, 36, "Subsection"], +Cell[CellGroupData[{ +Cell[158142, 5019, 326, 9, 36, "Subsection"], +Cell[158471, 5030, 342, 9, 31, "Subsubsection"], +Cell[158816, 5041, 341, 9, 31, "Subsubsection"], +Cell[159160, 5052, 357, 9, 31, "Subsubsection"], +Cell[159520, 5063, 351, 9, 31, "Subsubsection"], +Cell[159874, 5074, 343, 9, 31, "Subsubsection"], +Cell[160220, 5085, 345, 9, 31, "Subsubsection"], +Cell[160568, 5096, 349, 9, 31, "Subsubsection"], +Cell[160920, 5107, 359, 9, 31, "Subsubsection"], +Cell[161282, 5118, 339, 9, 31, "Subsubsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[161658, 5132, 371, 9, 51, "Subsection"], +Cell[162032, 5143, 354, 9, 31, "Subsubsection"], +Cell[162389, 5154, 354, 9, 31, "Subsubsection"], +Cell[162746, 5165, 362, 9, 31, "Subsubsection"], +Cell[163111, 5176, 380, 9, 31, "Subsubsection"] +}, Closed]], +Cell[163506, 5188, 348, 9, 51, "Subsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[163891, 5202, 341, 9, 49, "Section"], +Cell[164235, 5213, 362, 9, 51, "Subsection"], +Cell[164600, 5224, 362, 9, 36, "Subsection"], +Cell[164965, 5235, 379, 9, 36, "Subsection"], +Cell[165347, 5246, 360, 9, 36, "Subsection"], +Cell[165710, 5257, 341, 9, 36, "Subsection"], +Cell[166054, 5268, 369, 9, 36, "Subsection"], +Cell[166426, 5279, 342, 9, 36, "Subsection"], +Cell[166771, 5290, 368, 9, 36, "Subsection"], +Cell[167142, 5301, 352, 9, 36, "Subsection"], +Cell[167497, 5312, 317, 8, 36, "Subsection"], +Cell[167817, 5322, 326, 9, 36, "Subsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[168180, 5336, 373, 9, 49, "Section"], +Cell[168556, 5347, 378, 9, 51, "Subsection"], +Cell[168937, 5358, 340, 9, 36, "Subsection"], +Cell[169280, 5369, 326, 9, 36, "Subsection"], +Cell[169609, 5380, 336, 9, 36, "Subsection"], +Cell[169948, 5391, 363, 9, 36, "Subsection"], +Cell[170314, 5402, 334, 9, 36, "Subsection"], +Cell[170651, 5413, 371, 9, 36, "Subsection"], +Cell[171025, 5424, 354, 9, 36, "Subsection"], +Cell[171382, 5435, 367, 9, 36, "Subsection"], +Cell[171752, 5446, 359, 9, 36, "Subsection"], +Cell[172114, 5457, 311, 8, 36, "Subsection"], +Cell[172428, 5467, 349, 9, 36, "Subsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[172814, 5481, 314, 9, 49, "Section"], +Cell[173131, 5492, 322, 9, 51, "Subsection"], +Cell[173456, 5503, 326, 9, 36, "Subsection"], +Cell[173785, 5514, 354, 9, 36, "Subsection"], +Cell[174142, 5525, 356, 9, 36, "Subsection"], +Cell[174501, 5536, 332, 9, 36, "Subsection"], +Cell[174836, 5547, 332, 9, 36, "Subsection"], +Cell[175171, 5558, 361, 9, 36, "Subsection"], +Cell[175535, 5569, 328, 9, 36, "Subsection"], +Cell[175866, 5580, 335, 9, 36, "Subsection"], +Cell[176204, 5591, 367, 9, 36, "Subsection"], +Cell[176574, 5602, 336, 9, 36, "Subsection"], +Cell[CellGroupData[{ +Cell[176935, 5615, 373, 9, 36, "Subsection"], +Cell[177311, 5626, 355, 9, 31, "Subsubsection"], +Cell[177669, 5637, 355, 9, 31, "Subsubsection"], +Cell[178027, 5648, 349, 9, 31, "Subsubsection"] +}, Closed]], +Cell[178391, 5660, 371, 9, 51, "Subsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[178799, 5674, 341, 8, 49, "Section"], +Cell[179143, 5684, 370, 10, 51, "Subsection"], +Cell[CellGroupData[{ +Cell[179538, 5698, 376, 9, 36, "Subsection"], +Cell[CellGroupData[{ +Cell[179939, 5711, 339, 9, 31, "Subsubsection"], +Cell[180281, 5722, 350, 9, 31, "Subsubsubsection"], +Cell[180634, 5733, 348, 9, 26, "Subsubsubsection"], +Cell[180985, 5744, 352, 9, 26, "Subsubsubsection"], +Cell[181340, 5755, 352, 9, 26, "Subsubsubsection"], +Cell[181695, 5766, 357, 9, 26, "Subsubsubsection"], +Cell[182055, 5777, 348, 9, 26, "Subsubsubsection"], +Cell[182406, 5788, 344, 9, 26, "Subsubsubsection"], +Cell[182753, 5799, 340, 9, 26, "Subsubsubsection"], +Cell[183096, 5810, 346, 9, 26, "Subsubsubsection"], +Cell[183445, 5821, 338, 9, 26, "Subsubsubsection"], +Cell[183786, 5832, 340, 9, 26, "Subsubsubsection"], +Cell[184129, 5843, 382, 9, 26, "Subsubsubsection"], +Cell[184514, 5854, 399, 10, 26, "Subsubsubsection"], +Cell[184916, 5866, 375, 9, 26, "Subsubsubsection"], +Cell[185294, 5877, 372, 9, 26, "Subsubsubsection"], +Cell[185669, 5888, 399, 9, 26, "Subsubsubsection"], +Cell[186071, 5899, 392, 9, 26, "Subsubsubsection"], +Cell[186466, 5910, 399, 9, 26, "Subsubsubsection"], +Cell[186868, 5921, 393, 9, 26, "Subsubsubsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[187298, 5935, 357, 9, 31, "Subsubsection"], +Cell[187658, 5946, 369, 9, 31, "Subsubsubsection"], +Cell[188030, 5957, 386, 9, 26, "Subsubsubsection"], +Cell[188419, 5968, 375, 9, 26, "Subsubsubsection"], +Cell[188797, 5979, 351, 9, 26, "Subsubsubsection"], +Cell[189151, 5990, 365, 9, 26, "Subsubsubsection"], +Cell[189519, 6001, 369, 9, 26, "Subsubsubsection"], +Cell[189891, 6012, 352, 9, 26, "Subsubsubsection"], +Cell[190246, 6023, 358, 9, 26, "Subsubsubsection"] +}, Closed]], +Cell[190619, 6035, 357, 9, 31, "Subsubsection"], +Cell[CellGroupData[{ +Cell[191001, 6048, 343, 9, 31, "Subsubsection"], +Cell[191347, 6059, 373, 9, 31, "Subsubsubsection"], +Cell[191723, 6070, 348, 9, 26, "Subsubsubsection"] +}, Closed]], +Cell[192086, 6082, 337, 9, 31, "Subsubsection"], +Cell[192426, 6093, 343, 9, 31, "Subsubsection"], +Cell[192772, 6104, 335, 9, 31, "Subsubsection"], +Cell[193110, 6115, 374, 9, 31, "Subsubsection"], +Cell[193487, 6126, 335, 9, 31, "Subsubsection"], +Cell[193825, 6137, 341, 9, 31, "Subsubsection"], +Cell[194169, 6148, 350, 9, 31, "Subsubsection"], +Cell[194522, 6159, 340, 9, 31, "Subsubsection"], +Cell[194865, 6170, 346, 9, 31, "Subsubsection"], +Cell[195214, 6181, 353, 9, 31, "Subsubsection"], +Cell[195570, 6192, 345, 9, 31, "Subsubsection"], +Cell[195918, 6203, 350, 9, 31, "Subsubsection"], +Cell[196271, 6214, 375, 9, 31, "Subsubsection"], +Cell[196649, 6225, 344, 9, 31, "Subsubsection"] +}, Closed]], +Cell[197008, 6237, 319, 9, 51, "Subsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[197364, 6251, 348, 9, 49, "Section"], +Cell[197715, 6262, 350, 9, 51, "Subsection"], +Cell[198068, 6273, 357, 9, 36, "Subsection"], +Cell[198428, 6284, 342, 9, 36, "Subsection"], +Cell[198773, 6295, 370, 9, 36, "Subsection"], +Cell[199146, 6306, 378, 9, 36, "Subsection"], +Cell[199527, 6317, 369, 9, 36, "Subsection"], +Cell[199899, 6328, 329, 9, 36, "Subsection"], +Cell[200231, 6339, 347, 9, 36, "Subsection"], +Cell[200581, 6350, 316, 8, 36, "Subsection"], +Cell[200900, 6360, 305, 8, 36, "Subsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[201242, 6373, 340, 9, 81, "Section"], +Cell[CellGroupData[{ +Cell[201607, 6386, 340, 9, 51, "Subsection"], +Cell[201950, 6397, 352, 9, 31, "Subsubsection"], +Cell[202305, 6408, 370, 9, 31, "Subsubsection"], +Cell[202678, 6419, 362, 9, 31, "Subsubsection"], +Cell[203043, 6430, 366, 9, 31, "Subsubsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[203446, 6444, 370, 9, 51, "Subsection"], +Cell[CellGroupData[{ +Cell[203841, 6457, 364, 9, 31, "Subsubsection"], +Cell[204208, 6468, 370, 9, 31, "Subsubsubsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[204615, 6482, 368, 9, 31, "Subsubsection"], +Cell[204986, 6493, 380, 9, 31, "Subsubsubsection"], +Cell[205369, 6504, 376, 9, 26, "Subsubsubsection"], +Cell[205748, 6515, 380, 9, 26, "Subsubsubsection"], +Cell[206131, 6526, 376, 9, 26, "Subsubsubsection"], +Cell[206510, 6537, 375, 9, 26, "Subsubsubsection"], +Cell[206888, 6548, 379, 9, 26, "Subsubsubsection"], +Cell[207270, 6559, 379, 9, 26, "Subsubsubsection"], +Cell[207652, 6570, 371, 9, 26, "Subsubsubsection"], +Cell[208026, 6581, 361, 9, 26, "Subsubsubsection"], +Cell[208390, 6592, 370, 9, 26, "Subsubsubsection"], +Cell[208763, 6603, 370, 9, 26, "Subsubsubsection"], +Cell[209136, 6614, 382, 9, 26, "Subsubsubsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[209555, 6628, 371, 9, 31, "Subsubsection"], +Cell[209929, 6639, 364, 9, 31, "Subsubsubsection"], +Cell[210296, 6650, 356, 9, 26, "Subsubsubsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[210689, 6664, 366, 9, 31, "Subsubsection"], +Cell[211058, 6675, 381, 9, 31, "Subsubsubsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[211476, 6689, 373, 9, 31, "Subsubsection"], +Cell[211852, 6700, 373, 9, 31, "Subsubsubsection"], +Cell[212228, 6711, 371, 9, 26, "Subsubsubsection"] +}, Closed]], +Cell[212614, 6723, 377, 9, 31, "Subsubsection"], +Cell[CellGroupData[{ +Cell[213016, 6736, 369, 9, 31, "Subsubsection"], +Cell[213388, 6747, 366, 9, 31, "Subsubsubsection"], +Cell[213757, 6758, 388, 9, 26, "Subsubsubsection"], +Cell[214148, 6769, 379, 9, 26, "Subsubsubsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[214564, 6783, 367, 9, 31, "Subsubsection"], +Cell[214934, 6794, 373, 9, 31, "Subsubsubsection"] +}, Closed]] +}, Closed]], +Cell[CellGroupData[{ +Cell[215356, 6809, 355, 9, 51, "Subsection"], +Cell[CellGroupData[{ +Cell[215736, 6822, 351, 9, 31, "Subsubsection"], +Cell[216090, 6833, 352, 9, 31, "Subsubsubsection"], +Cell[216445, 6844, 368, 9, 26, "Subsubsubsection"], +Cell[216816, 6855, 361, 9, 26, "Subsubsubsection"], +Cell[217180, 6866, 377, 9, 26, "Subsubsubsection"], +Cell[217560, 6877, 347, 9, 26, "Subsubsubsection"], +Cell[217910, 6888, 351, 9, 26, "Subsubsubsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[218298, 6902, 355, 9, 31, "Subsubsection"], +Cell[218656, 6913, 365, 9, 31, "Subsubsubsection"], +Cell[219024, 6924, 363, 9, 26, "Subsubsubsection"], +Cell[219390, 6935, 367, 9, 26, "Subsubsubsection"], +Cell[219760, 6946, 364, 9, 26, "Subsubsubsection"], +Cell[220127, 6957, 363, 9, 26, "Subsubsubsection"], +Cell[220493, 6968, 365, 9, 26, "Subsubsubsection"], +Cell[220861, 6979, 366, 9, 26, "Subsubsubsection"], +Cell[221230, 6990, 359, 9, 26, "Subsubsubsection"], +Cell[221592, 7001, 350, 9, 26, "Subsubsubsection"], +Cell[221945, 7012, 357, 9, 26, "Subsubsubsection"], +Cell[222305, 7023, 357, 9, 26, "Subsubsubsection"], +Cell[222665, 7034, 370, 9, 26, "Subsubsubsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[223072, 7048, 357, 9, 31, "Subsubsection"], +Cell[223432, 7059, 352, 9, 31, "Subsubsubsection"], +Cell[223787, 7070, 344, 9, 26, "Subsubsubsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[224168, 7084, 367, 9, 31, "Subsubsection"], +Cell[224538, 7095, 367, 9, 31, "Subsubsubsection"], +Cell[224908, 7106, 365, 9, 26, "Subsubsubsection"] +}, Closed]], +Cell[225288, 7118, 370, 9, 31, "Subsubsection"], +Cell[CellGroupData[{ +Cell[225683, 7131, 355, 9, 31, "Subsubsection"], +Cell[226041, 7142, 354, 9, 31, "Subsubsubsection"] +}, Closed]], +Cell[226410, 7154, 354, 9, 31, "Subsubsection"], +Cell[226767, 7165, 371, 9, 31, "Subsubsection"], +Cell[227141, 7176, 357, 9, 31, "Subsubsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[227535, 7190, 354, 9, 51, "Subsection"], +Cell[CellGroupData[{ +Cell[227914, 7203, 357, 9, 31, "Subsubsection"], +Cell[228274, 7214, 351, 9, 31, "Subsubsubsection"], +Cell[228628, 7225, 355, 9, 26, "Subsubsubsection"], +Cell[228986, 7236, 351, 9, 26, "Subsubsubsection"], +Cell[229340, 7247, 371, 9, 26, "Subsubsubsection"], +Cell[229714, 7258, 354, 9, 26, "Subsubsubsection"], +Cell[230071, 7269, 360, 9, 26, "Subsubsubsection"], +Cell[230434, 7280, 358, 9, 26, "Subsubsubsection"], +Cell[230795, 7291, 353, 9, 26, "Subsubsubsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[231185, 7305, 361, 9, 31, "Subsubsection"], +Cell[231549, 7316, 363, 9, 31, "Subsubsubsection"], +Cell[231915, 7327, 367, 9, 26, "Subsubsubsection"], +Cell[232285, 7338, 382, 9, 26, "Subsubsubsection"], +Cell[232670, 7349, 374, 9, 26, "Subsubsubsection"], +Cell[233047, 7360, 359, 9, 26, "Subsubsubsection"], +Cell[233409, 7371, 371, 9, 26, "Subsubsubsection"], +Cell[233783, 7382, 353, 9, 26, "Subsubsubsection"], +Cell[234139, 7393, 353, 9, 26, "Subsubsubsection"], +Cell[234495, 7404, 359, 9, 26, "Subsubsubsection"], +Cell[234857, 7415, 353, 9, 26, "Subsubsubsection"], +Cell[235213, 7426, 355, 9, 26, "Subsubsubsection"], +Cell[235571, 7437, 363, 9, 26, "Subsubsubsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[235971, 7451, 363, 9, 31, "Subsubsection"], +Cell[236337, 7462, 359, 9, 31, "Subsubsubsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[236733, 7476, 365, 9, 31, "Subsubsection"], +Cell[237101, 7487, 368, 9, 31, "Subsubsubsection"], +Cell[237472, 7498, 369, 9, 26, "Subsubsubsection"], +Cell[237844, 7509, 374, 9, 26, "Subsubsubsection"], +Cell[238221, 7520, 369, 9, 26, "Subsubsubsection"], +Cell[238593, 7531, 353, 9, 26, "Subsubsubsection"], +Cell[238949, 7542, 353, 9, 26, "Subsubsubsection"], +Cell[239305, 7553, 354, 9, 26, "Subsubsubsection"], +Cell[239662, 7564, 362, 9, 26, "Subsubsubsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[240061, 7578, 361, 9, 31, "Subsubsection"], +Cell[240425, 7589, 362, 9, 31, "Subsubsubsection"], +Cell[240790, 7600, 369, 9, 26, "Subsubsubsection"], +Cell[241162, 7611, 376, 9, 26, "Subsubsubsection"], +Cell[241541, 7622, 363, 9, 26, "Subsubsubsection"], +Cell[241907, 7633, 363, 9, 26, "Subsubsubsection"], +Cell[242273, 7644, 374, 9, 26, "Subsubsubsection"], +Cell[242650, 7655, 374, 9, 26, "Subsubsubsection"], +Cell[243027, 7666, 373, 9, 26, "Subsubsubsection"], +Cell[243403, 7677, 354, 9, 26, "Subsubsubsection"], +Cell[243760, 7688, 365, 9, 26, "Subsubsubsection"], +Cell[244128, 7699, 377, 9, 26, "Subsubsubsection"], +Cell[244508, 7710, 352, 9, 26, "Subsubsubsection"], +Cell[244863, 7721, 367, 9, 26, "Subsubsubsection"] +}, Closed]], +Cell[245245, 7733, 362, 9, 31, "Subsubsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[245644, 7747, 340, 9, 51, "Subsection"], +Cell[CellGroupData[{ +Cell[246009, 7760, 355, 9, 31, "Subsubsection"], +Cell[246367, 7771, 372, 9, 31, "Subsubsubsection"], +Cell[246742, 7782, 361, 9, 26, "Subsubsubsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[247140, 7796, 355, 9, 31, "Subsubsection"], +Cell[247498, 7807, 368, 9, 31, "Subsubsubsection"], +Cell[247869, 7818, 380, 9, 26, "Subsubsubsection"], +Cell[248252, 7829, 367, 9, 26, "Subsubsubsection"], +Cell[248622, 7840, 359, 9, 26, "Subsubsubsection"] +}, Closed]], +Cell[248996, 7852, 349, 9, 31, "Subsubsection"], +Cell[249348, 7863, 362, 9, 31, "Subsubsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[249747, 7877, 368, 9, 51, "Subsection"], +Cell[CellGroupData[{ +Cell[250140, 7890, 347, 9, 31, "Subsubsection"], +Cell[250490, 7901, 361, 9, 31, "Subsubsubsection"], +Cell[250854, 7912, 361, 9, 26, "Subsubsubsection"], +Cell[251218, 7923, 359, 9, 26, "Subsubsubsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[251614, 7937, 356, 9, 31, "Subsubsection"], +Cell[251973, 7948, 361, 9, 31, "Subsubsubsection"], +Cell[252337, 7959, 357, 9, 26, "Subsubsubsection"], +Cell[252697, 7970, 353, 9, 26, "Subsubsubsection"], +Cell[253053, 7981, 352, 9, 26, "Subsubsubsection"], +Cell[253408, 7992, 362, 9, 26, "Subsubsubsection"], +Cell[253773, 8003, 350, 9, 26, "Subsubsubsection"], +Cell[254126, 8014, 351, 9, 26, "Subsubsubsection"], +Cell[254480, 8025, 359, 9, 26, "Subsubsubsection"], +Cell[254842, 8036, 354, 9, 26, "Subsubsubsection"], +Cell[255199, 8047, 371, 9, 26, "Subsubsubsection"], +Cell[255573, 8058, 369, 9, 26, "Subsubsubsection"], +Cell[255945, 8069, 355, 9, 26, "Subsubsubsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[256337, 8083, 355, 9, 31, "Subsubsection"], +Cell[256695, 8094, 360, 9, 31, "Subsubsubsection"], +Cell[257058, 8105, 361, 9, 26, "Subsubsubsection"] +}, Closed]] +}, Closed]], +Cell[CellGroupData[{ +Cell[257468, 8120, 347, 9, 51, "Subsection"], +Cell[257818, 8131, 346, 9, 31, "Subsubsection"], +Cell[CellGroupData[{ +Cell[258189, 8144, 363, 9, 31, "Subsubsection"], +Cell[258555, 8155, 358, 9, 31, "Subsubsubsection"], +Cell[258916, 8166, 352, 9, 26, "Subsubsubsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[259305, 8180, 366, 9, 31, "Subsubsection"], +Cell[259674, 8191, 357, 9, 31, "Subsubsubsection"], +Cell[260034, 8202, 363, 9, 26, "Subsubsubsection"] +}, Closed]], +Cell[260412, 8214, 358, 9, 31, "Subsubsection"], +Cell[CellGroupData[{ +Cell[260795, 8227, 348, 9, 31, "Subsubsection"], +Cell[261146, 8238, 341, 9, 31, "Subsubsubsection"], +Cell[261490, 8249, 353, 9, 26, "Subsubsubsection"], +Cell[261846, 8260, 349, 9, 26, "Subsubsubsection"], +Cell[262198, 8271, 355, 9, 26, "Subsubsubsection"], +Cell[262556, 8282, 359, 9, 26, "Subsubsubsection"] +}, Closed]], +Cell[262930, 8294, 359, 9, 31, "Subsubsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[263326, 8308, 334, 9, 51, "Subsection"], +Cell[CellGroupData[{ +Cell[263685, 8321, 350, 9, 31, "Subsubsection"], +Cell[264038, 8332, 342, 9, 31, "Subsubsubsection"], +Cell[264383, 8343, 341, 9, 26, "Subsubsubsection"], +Cell[264727, 8354, 351, 9, 26, "Subsubsubsection"], +Cell[265081, 8365, 350, 9, 26, "Subsubsubsection"], +Cell[265434, 8376, 342, 9, 26, "Subsubsubsection"], +Cell[265779, 8387, 341, 9, 26, "Subsubsubsection"], +Cell[266123, 8398, 342, 9, 26, "Subsubsubsection"] +}, Closed]], +Cell[266480, 8410, 345, 9, 31, "Subsubsection"] +}, Closed]] +}, Closed]], +Cell[CellGroupData[{ +Cell[266874, 8425, 351, 9, 81, "Section"], +Cell[267228, 8436, 323, 9, 51, "Subsection"], +Cell[267554, 8447, 314, 8, 36, "Subsection"], +Cell[267871, 8457, 368, 9, 36, "Subsection"], +Cell[268242, 8468, 337, 9, 36, "Subsection"], +Cell[268582, 8479, 349, 9, 36, "Subsection"], +Cell[268934, 8490, 326, 9, 36, "Subsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[269297, 8504, 361, 9, 81, "Section"], +Cell[269661, 8515, 362, 9, 51, "Subsection"], +Cell[270026, 8526, 373, 9, 36, "Subsection"], +Cell[270402, 8537, 334, 9, 36, "Subsection"], +Cell[270739, 8548, 370, 9, 36, "Subsection"], +Cell[271112, 8559, 373, 9, 36, "Subsection"], +Cell[271488, 8570, 335, 9, 36, "Subsection"], +Cell[271826, 8581, 377, 9, 36, "Subsection"], +Cell[272206, 8592, 336, 9, 36, "Subsection"], +Cell[272545, 8603, 361, 9, 36, "Subsection"], +Cell[272909, 8614, 360, 9, 36, "Subsection"], +Cell[273272, 8625, 387, 9, 36, "Subsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[273696, 8639, 369, 10, 81, "Section"], +Cell[CellGroupData[{ +Cell[274090, 8653, 332, 9, 51, "Subsection"], +Cell[274425, 8664, 334, 9, 31, "Subsubsection"], +Cell[CellGroupData[{ +Cell[274784, 8677, 343, 8, 31, "Subsubsection"], +Cell[275130, 8687, 335, 9, 31, "Subsubsubsection"], +Cell[275468, 8698, 349, 9, 26, "Subsubsubsection"], +Cell[275820, 8709, 346, 9, 26, "Subsubsubsection"], +Cell[276169, 8720, 344, 9, 26, "Subsubsubsection"], +Cell[276516, 8731, 347, 9, 26, "Subsubsubsection"], +Cell[276866, 8742, 341, 9, 26, "Subsubsubsection"], +Cell[277210, 8753, 373, 9, 26, "Subsubsubsection"], +Cell[277586, 8764, 344, 9, 26, "Subsubsubsection"], +Cell[277933, 8775, 346, 9, 26, "Subsubsubsection"], +Cell[278282, 8786, 344, 9, 26, "Subsubsubsection"], +Cell[278629, 8797, 348, 9, 26, "Subsubsubsection"], +Cell[278980, 8808, 348, 9, 26, "Subsubsubsection"], +Cell[279331, 8819, 343, 8, 26, "Subsubsubsection"], +Cell[279677, 8829, 346, 9, 26, "Subsubsubsection"], +Cell[280026, 8840, 332, 9, 26, "Subsubsubsection"], +Cell[280361, 8851, 336, 9, 26, "Subsubsubsection"], +Cell[280700, 8862, 338, 9, 26, "Subsubsubsection"], +Cell[281041, 8873, 330, 9, 26, "Subsubsubsection"], +Cell[281374, 8884, 352, 9, 26, "Subsubsubsection"], +Cell[281729, 8895, 332, 9, 26, "Subsubsubsection"], +Cell[282064, 8906, 348, 9, 26, "Subsubsubsection"], +Cell[282415, 8917, 349, 9, 26, "Subsubsubsection"], +Cell[282767, 8928, 352, 9, 26, "Subsubsubsection"], +Cell[283122, 8939, 360, 9, 26, "Subsubsubsection"], +Cell[283485, 8950, 357, 9, 26, "Subsubsubsection"], +Cell[283845, 8961, 360, 9, 26, "Subsubsubsection"], +Cell[284208, 8972, 368, 9, 26, "Subsubsubsection"], +Cell[284579, 8983, 336, 9, 26, "Subsubsubsection"], +Cell[284918, 8994, 339, 8, 26, "Subsubsubsection"] +}, Closed]] +}, Closed]], +Cell[CellGroupData[{ +Cell[285306, 9008, 329, 8, 51, "Subsection"], +Cell[CellGroupData[{ +Cell[285660, 9020, 334, 8, 31, "Subsubsection"], +Cell[285997, 9030, 338, 9, 31, "Subsubsubsection"], +Cell[286338, 9041, 359, 9, 26, "Subsubsubsection"], +Cell[286700, 9052, 345, 9, 26, "Subsubsubsection"], +Cell[287048, 9063, 349, 9, 26, "Subsubsubsection"] +}, Closed]] +}, Closed]], +Cell[CellGroupData[{ +Cell[287446, 9078, 322, 8, 51, "Subsection"], +Cell[287771, 9088, 334, 9, 31, "Subsubsection"], +Cell[288108, 9099, 333, 9, 31, "Subsubsection"], +Cell[288444, 9110, 356, 9, 31, "Subsubsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[288837, 9124, 356, 9, 51, "Subsection"], +Cell[289196, 9135, 342, 9, 31, "Subsubsection"], +Cell[289541, 9146, 325, 9, 31, "Subsubsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[289903, 9160, 359, 9, 51, "Subsection"], +Cell[290265, 9171, 358, 9, 31, "Subsubsection"], +Cell[290626, 9182, 352, 9, 31, "Subsubsection"], +Cell[CellGroupData[{ +Cell[291003, 9195, 349, 9, 31, "Subsubsection"], +Cell[291355, 9206, 348, 9, 31, "Subsubsubsection"], +Cell[291706, 9217, 343, 9, 26, "Subsubsubsection"] +}, Closed]], +Cell[292064, 9229, 345, 9, 31, "Subsubsection"], +Cell[292412, 9240, 352, 9, 31, "Subsubsection"], +Cell[292767, 9251, 349, 9, 31, "Subsubsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[293153, 9265, 345, 9, 51, "Subsection"], +Cell[293501, 9276, 352, 9, 31, "Subsubsection"], +Cell[293856, 9287, 340, 9, 31, "Subsubsection"] +}, Closed]], +Cell[294211, 9299, 320, 9, 51, "Subsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[294568, 9313, 353, 9, 81, "Section"], +Cell[CellGroupData[{ +Cell[294946, 9326, 338, 9, 51, "Subsection"], +Cell[295287, 9337, 338, 9, 31, "Subsubsection"], +Cell[CellGroupData[{ +Cell[295650, 9350, 337, 9, 31, "Subsubsection"], +Cell[295990, 9361, 345, 9, 31, "Subsubsubsection"], +Cell[296338, 9372, 373, 9, 26, "Subsubsubsection"], +Cell[296714, 9383, 353, 9, 26, "Subsubsubsection"], +Cell[297070, 9394, 353, 9, 26, "Subsubsubsection"] +}, Closed]] +}, Closed]], +Cell[CellGroupData[{ +Cell[297472, 9409, 357, 9, 51, "Subsection"], +Cell[297832, 9420, 352, 9, 31, "Subsubsection"], +Cell[298187, 9431, 359, 9, 31, "Subsubsection"], +Cell[CellGroupData[{ +Cell[298571, 9444, 364, 9, 31, "Subsubsection"], +Cell[298938, 9455, 375, 9, 31, "Subsubsubsection"], +Cell[299316, 9466, 371, 9, 26, "Subsubsubsection"], +Cell[299690, 9477, 397, 9, 26, "Subsubsubsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[300124, 9491, 362, 9, 31, "Subsubsection"], +Cell[300489, 9502, 375, 9, 31, "Subsubsubsection"], +Cell[300867, 9513, 378, 9, 26, "Subsubsubsection"], +Cell[301248, 9524, 366, 9, 26, "Subsubsubsection"], +Cell[301617, 9535, 371, 9, 26, "Subsubsubsection"], +Cell[301991, 9546, 397, 9, 26, "Subsubsubsection"] +}, Closed]], +Cell[302403, 9558, 391, 9, 31, "Subsubsection"], +Cell[CellGroupData[{ +Cell[302819, 9571, 360, 9, 31, "Subsubsection"], +Cell[303182, 9582, 374, 9, 31, "Subsubsubsection"], +Cell[303559, 9593, 400, 9, 26, "Subsubsubsection"], +Cell[303962, 9604, 384, 9, 26, "Subsubsubsection"], +Cell[304349, 9615, 375, 9, 26, "Subsubsubsection"], +Cell[304727, 9626, 382, 9, 26, "Subsubsubsection"], +Cell[305112, 9637, 432, 10, 26, "Subsubsubsection"], +Cell[305547, 9649, 387, 9, 26, "Subsubsubsection"], +Cell[305937, 9660, 409, 10, 26, "Subsubsubsection"], +Cell[306349, 9672, 373, 9, 26, "Subsubsubsection"], +Cell[306725, 9683, 409, 10, 26, "Subsubsubsection"], +Cell[307137, 9695, 369, 9, 26, "Subsubsubsection"], +Cell[307509, 9706, 375, 9, 26, "Subsubsubsection"], +Cell[307887, 9717, 380, 9, 26, "Subsubsubsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[308304, 9731, 367, 9, 31, "Subsubsection"], +Cell[308674, 9742, 375, 9, 31, "Subsubsubsection"], +Cell[309052, 9753, 405, 10, 26, "Subsubsubsection"], +Cell[309460, 9765, 362, 9, 26, "Subsubsubsection"], +Cell[309825, 9776, 399, 9, 26, "Subsubsubsection"] +}, Closed]], +Cell[310239, 9788, 368, 9, 31, "Subsubsection"], +Cell[310610, 9799, 362, 9, 31, "Subsubsection"], +Cell[310975, 9810, 377, 9, 31, "Subsubsection"], +Cell[311355, 9821, 374, 9, 31, "Subsubsection"], +Cell[CellGroupData[{ +Cell[311754, 9834, 381, 9, 31, "Subsubsection"], +Cell[312138, 9845, 367, 9, 31, "Subsubsubsection"], +Cell[312508, 9856, 372, 9, 26, "Subsubsubsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[312917, 9870, 389, 9, 31, "Subsubsection"], +Cell[313309, 9881, 375, 9, 31, "Subsubsubsection"], +Cell[313687, 9892, 353, 9, 26, "Subsubsubsection"], +Cell[314043, 9903, 364, 9, 26, "Subsubsubsection"], +Cell[314410, 9914, 386, 9, 26, "Subsubsubsection"], +Cell[314799, 9925, 409, 10, 26, "Subsubsubsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[315245, 9940, 401, 10, 31, "Subsubsection"], +Cell[315649, 9952, 374, 9, 31, "Subsubsubsection"], +Cell[316026, 9963, 366, 9, 26, "Subsubsubsection"], +Cell[316395, 9974, 372, 9, 26, "Subsubsubsection"], +Cell[316770, 9985, 370, 9, 26, "Subsubsubsection"], +Cell[317143, 9996, 388, 9, 26, "Subsubsubsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[317568, 10010, 361, 9, 31, "Subsubsection"], +Cell[317932, 10021, 390, 9, 31, "Subsubsubsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[318359, 10035, 352, 9, 31, "Subsubsection"], +Cell[318714, 10046, 382, 9, 31, "Subsubsubsection"], +Cell[319099, 10057, 372, 9, 26, "Subsubsubsection"], +Cell[319474, 10068, 373, 9, 26, "Subsubsubsection"], +Cell[319850, 10079, 370, 9, 26, "Subsubsubsection"], +Cell[320223, 10090, 375, 9, 26, "Subsubsubsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[320635, 10104, 364, 9, 31, "Subsubsection"], +Cell[321002, 10115, 370, 9, 31, "Subsubsubsection"], +Cell[321375, 10126, 370, 9, 26, "Subsubsubsection"] +}, Closed]] +}, Closed]], +Cell[CellGroupData[{ +Cell[321794, 10141, 347, 9, 51, "Subsection"], +Cell[322144, 10152, 347, 9, 31, "Subsubsection"], +Cell[322494, 10163, 365, 9, 31, "Subsubsection"], +Cell[CellGroupData[{ +Cell[322884, 10176, 358, 9, 31, "Subsubsection"], +Cell[323245, 10187, 359, 9, 31, "Subsubsubsection"], +Cell[323607, 10198, 391, 9, 26, "Subsubsubsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[324035, 10212, 357, 9, 31, "Subsubsection"], +Cell[324395, 10223, 392, 9, 31, "Subsubsubsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[324824, 10237, 367, 9, 31, "Subsubsection"], +Cell[325194, 10248, 403, 10, 31, "Subsubsubsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[325634, 10263, 359, 9, 31, "Subsubsection"], +Cell[325996, 10274, 393, 9, 31, "Subsubsubsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[326426, 10288, 361, 9, 31, "Subsubsection"], +Cell[326790, 10299, 394, 9, 31, "Subsubsubsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[327221, 10313, 361, 9, 31, "Subsubsection"], +Cell[327585, 10324, 395, 9, 31, "Subsubsubsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[328017, 10338, 357, 9, 31, "Subsubsection"], +Cell[328377, 10349, 391, 9, 31, "Subsubsubsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[328805, 10363, 356, 9, 31, "Subsubsection"], +Cell[329164, 10374, 390, 9, 31, "Subsubsubsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[329591, 10388, 362, 9, 31, "Subsubsection"], +Cell[329956, 10399, 400, 10, 31, "Subsubsubsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[330393, 10414, 357, 9, 31, "Subsubsection"], +Cell[330753, 10425, 361, 9, 31, "Subsubsubsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[331151, 10439, 359, 9, 31, "Subsubsection"], +Cell[331513, 10450, 365, 9, 31, "Subsubsubsection"], +Cell[331881, 10461, 356, 9, 26, "Subsubsubsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[332274, 10475, 366, 9, 31, "Subsubsection"], +Cell[332643, 10486, 368, 9, 31, "Subsubsubsection"], +Cell[333014, 10497, 354, 9, 26, "Subsubsubsection"] +}, Closed]], +Cell[333383, 10509, 358, 9, 31, "Subsubsection"] +}, Closed]], +Cell[333756, 10521, 334, 9, 51, "Subsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[334127, 10535, 345, 9, 81, "Section"], +Cell[CellGroupData[{ +Cell[334497, 10548, 350, 9, 51, "Subsection"], +Cell[334850, 10559, 365, 9, 31, "Subsubsection"], +Cell[335218, 10570, 363, 9, 31, "Subsubsection"], +Cell[335584, 10581, 362, 9, 31, "Subsubsection"], +Cell[335949, 10592, 372, 9, 31, "Subsubsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[336358, 10606, 362, 9, 51, "Subsection"], +Cell[336723, 10617, 361, 9, 31, "Subsubsection"], +Cell[CellGroupData[{ +Cell[337109, 10630, 379, 9, 31, "Subsubsection"], +Cell[337491, 10641, 383, 9, 31, "Subsubsubsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[337911, 10655, 357, 9, 31, "Subsubsection"], +Cell[338271, 10666, 425, 10, 31, "Subsubsubsection"], +Cell[338699, 10678, 377, 9, 26, "Subsubsubsection"], +Cell[339079, 10689, 430, 10, 26, "Subsubsubsection"], +Cell[339512, 10701, 398, 9, 26, "Subsubsubsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[339947, 10715, 407, 10, 31, "Subsubsection"], +Cell[340357, 10727, 401, 9, 31, "Subsubsubsection"], +Cell[340761, 10738, 414, 10, 26, "Subsubsubsection"], +Cell[341178, 10750, 379, 9, 26, "Subsubsubsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[341594, 10764, 391, 9, 31, "Subsubsection"], +Cell[341988, 10775, 375, 9, 31, "Subsubsubsection"], +Cell[342366, 10786, 382, 9, 26, "Subsubsubsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[342785, 10800, 381, 9, 31, "Subsubsection"], +Cell[343169, 10811, 393, 9, 31, "Subsubsubsection"], +Cell[343565, 10822, 379, 9, 26, "Subsubsubsection"] +}, Closed]] +}, Closed]], +Cell[CellGroupData[{ +Cell[343993, 10837, 377, 9, 51, "Subsection"], +Cell[344373, 10848, 358, 9, 31, "Subsubsection"], +Cell[CellGroupData[{ +Cell[344756, 10861, 369, 9, 31, "Subsubsection"], +Cell[345128, 10872, 375, 9, 31, "Subsubsubsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[345540, 10886, 369, 9, 31, "Subsubsection"], +Cell[345912, 10897, 375, 9, 31, "Subsubsubsection"], +Cell[346290, 10908, 374, 9, 26, "Subsubsubsection"], +Cell[346667, 10919, 388, 9, 26, "Subsubsubsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[347092, 10933, 401, 9, 31, "Subsubsection"], +Cell[347496, 10944, 378, 9, 31, "Subsubsubsection"] +}, Closed]] +}, Closed]], +Cell[CellGroupData[{ +Cell[347923, 10959, 379, 9, 51, "Subsection"], +Cell[348305, 10970, 359, 9, 31, "Subsubsection"], +Cell[348667, 10981, 369, 9, 31, "Subsubsection"], +Cell[CellGroupData[{ +Cell[349061, 10994, 406, 10, 31, "Subsubsection"], +Cell[349470, 11006, 370, 9, 31, "Subsubsubsection"], +Cell[349843, 11017, 374, 9, 26, "Subsubsubsection"], +Cell[350220, 11028, 370, 9, 26, "Subsubsubsection"], +Cell[350593, 11039, 366, 9, 26, "Subsubsubsection"] +}, Closed]] +}, Closed]], +Cell[CellGroupData[{ +Cell[351008, 11054, 356, 9, 51, "Subsection"], +Cell[351367, 11065, 349, 9, 31, "Subsubsection"], +Cell[351719, 11076, 347, 9, 31, "Subsubsection"], +Cell[CellGroupData[{ +Cell[352091, 11089, 388, 9, 31, "Subsubsection"], +Cell[352482, 11100, 351, 9, 31, "Subsubsubsection"], +Cell[352836, 11111, 382, 9, 26, "Subsubsubsection"], +Cell[353221, 11122, 388, 9, 26, "Subsubsubsection"], +Cell[353612, 11133, 370, 9, 26, "Subsubsubsection"], +Cell[353985, 11144, 367, 9, 26, "Subsubsubsection"], +Cell[354355, 11155, 372, 9, 26, "Subsubsubsection"] +}, Closed]], +Cell[354742, 11167, 356, 9, 31, "Subsubsection"], +Cell[355101, 11178, 360, 9, 31, "Subsubsection"], +Cell[355464, 11189, 390, 9, 31, "Subsubsection"], +Cell[CellGroupData[{ +Cell[355879, 11202, 365, 9, 31, "Subsubsection"], +Cell[356247, 11213, 369, 9, 31, "Subsubsubsection"], +Cell[356619, 11224, 411, 10, 26, "Subsubsubsection"] +}, Closed]] +}, Closed]], +Cell[357057, 11238, 383, 9, 51, "Subsection"], +Cell[357443, 11249, 361, 9, 36, "Subsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[357841, 11263, 349, 9, 81, "Section"], +Cell[CellGroupData[{ +Cell[358215, 11276, 352, 9, 51, "Subsection"], +Cell[358570, 11287, 383, 10, 31, "Subsubsubsection"], +Cell[358956, 11299, 378, 10, 26, "Subsubsubsection"], +Cell[359337, 11311, 378, 9, 26, "Subsubsubsection"], +Cell[359718, 11322, 378, 9, 26, "Subsubsubsection"], +Cell[360099, 11333, 402, 10, 26, "Subsubsubsection"], +Cell[360504, 11345, 380, 9, 26, "Subsubsubsection"], +Cell[360887, 11356, 384, 10, 26, "Subsubsubsection"], +Cell[361274, 11368, 389, 9, 26, "Subsubsubsection"], +Cell[361666, 11379, 369, 9, 26, "Subsubsubsection"], +Cell[362038, 11390, 384, 9, 26, "Subsubsubsection"], +Cell[362425, 11401, 378, 10, 26, "Subsubsubsection"], +Cell[362806, 11413, 377, 9, 26, "Subsubsubsection"], +Cell[363186, 11424, 379, 9, 26, "Subsubsubsection"], +Cell[363568, 11435, 385, 10, 26, "Subsubsubsection"], +Cell[363956, 11447, 406, 10, 26, "Subsubsubsection"], +Cell[364365, 11459, 386, 10, 26, "Subsubsubsection"], +Cell[364754, 11471, 377, 9, 26, "Subsubsubsection"], +Cell[365134, 11482, 378, 9, 26, "Subsubsubsection"], +Cell[365515, 11493, 366, 9, 26, "Subsubsubsection"] +}, Closed]], +Cell[365896, 11505, 338, 9, 51, "Subsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[366271, 11519, 357, 9, 81, "Section"], +Cell[366631, 11530, 357, 9, 51, "Subsection"], +Cell[366991, 11541, 370, 9, 36, "Subsection"], +Cell[CellGroupData[{ +Cell[367386, 11554, 355, 9, 36, "Subsection"], +Cell[367744, 11565, 337, 9, 31, "Subsubsection"], +Cell[368084, 11576, 357, 9, 31, "Subsubsection"], +Cell[368444, 11587, 344, 9, 31, "Subsubsection"], +Cell[368791, 11598, 380, 9, 31, "Subsubsection"], +Cell[369174, 11609, 369, 9, 31, "Subsubsection"], +Cell[369546, 11620, 346, 9, 31, "Subsubsection"], +Cell[369895, 11631, 351, 9, 31, "Subsubsection"] +}, Closed]], +Cell[CellGroupData[{ +Cell[370283, 11645, 307, 8, 51, "Subsection"], +Cell[370593, 11655, 332, 8, 31, "Subsubsection"], +Cell[370928, 11665, 346, 9, 31, "Subsubsection"], +Cell[371277, 11676, 342, 9, 31, "Subsubsection"], +Cell[371622, 11687, 343, 8, 31, "Subsubsection"], +Cell[371968, 11697, 333, 9, 31, "Subsubsection"], +Cell[372304, 11708, 350, 9, 31, "Subsubsection"], +Cell[372657, 11719, 350, 9, 31, "Subsubsection"] +}, Closed]], +Cell[373022, 11731, 375, 9, 51, "Subsection"] +}, Closed]] +}, Closed]] +}, Open ]] +} +] +*) + +(* End of internal cache information *) + diff --git a/MathematicaFiles/Applications/WriteBriefingFilesWithHeaders.m b/MathematicaFiles/Applications/WriteBriefingFilesWithHeaders.m new file mode 100755 index 0000000..fc6d11b --- /dev/null +++ b/MathematicaFiles/Applications/WriteBriefingFilesWithHeaders.m @@ -0,0 +1,212 @@ +<<DateFunctions` +<<OddsandEnds` + +WriteStripsFileWithHeader::usage = "WriteStripsFileWithHeader[filename, \ +{lastdate, lastFOMC}, stripsdata] writes the data to the specified file \ +in XLS format \ +with a header that reflects specified dates. The first column of the data \ +matrix should be the maturity in years, the second column should be the \ +yields from the most recent day in percent, and the third column should \ +be the yields from the previous FOMC date." + +WriteEurodollarsCurrentFileWithHeader::usage = +"WriteEurodollarsCurrentFileWithHeader[filename, lastdate, currentdata]." + +WriteEurodollarsAdjustedFileWithHeader::usage = +"WriteEurodollarsAdjustedFileWithHeader[filename, lastdate, currentdata]." + +WriteEurodollarsPreviousFileWithHeader::usage = +"WriteEurodollarsPreviousFileWithHeader[filename, \ +{lastdate, lastFOMCdate}, previousdata]." + +WriteEurodollarsChangeFileWithHeader::usage = +"WriteEurodollarsChangeFileWithHeader[filename, \ +{lastdate, lastFOMCdate}, changedata]." + +WriteEurodollarsFileWithHeader::usage = +"WriteEurodollarsFileWithHeader[filename, \ +{lastdate, lastFOMCdate}, \ +{currentdata, previousdata, changedata}]." + +ExportStripsDataToXLS = WriteStripsFileWithHeader + +ExportEurodollarDataToXLS = WriteEurodollarsFileWithHeader + + +WriteStripsFileWithHeader[ + filename_String, + {lastdate_List, lastFOMC_List}, + stripsdata_?MatrixQ + ] := + Module[{header}, + header = Partition[#,1]&@{ + "Strips data: smoothed zero-coupon yields", "col 1: maturity in years", + ToString[StringForm["col 2: yield (percent) as of ``", + ListDateToStringDate[lastFOMC]]], + ToString[StringForm["col 3: yield (percent) as of ``", + ListDateToStringDate[lastdate]]], + "" + }; + Export[filename <> ".xls", Join[header, stripsdata], {"Sheets", "STRIPs Data"}] + ] + + +WriteEurodollarsCurrentFileWithHeader[ + filename_String, + lastdate_List, + currentdata_List + ] := + Module[{header, currentstrdate}, + currentstrdate = ListDateToStringDate[lastdate]; + header = Partition[#,1]&@{ + ToString@StringForm["Eurodollar futures rates as of ``", currentstrdate], + ToString@StringForm["col 1: maturity in years relative to ``", currentstrdate], + "col 2: rate in percent", + ""}; + Export[filename <> ".xls", Join[header, currentdata], {"Sheets", "Current"}] + ] + +WriteEurodollarsPreviousFileWithHeader[ + filename_String, + {lastdate_List, lastFOMC_List}, + previousdata_List + ] := + Module[{header, currentstrdate, previousstrdate}, + currentstrdate = ListDateToStringDate[lastdate]; + previousstrdate = ListDateToStringDate[lastFOMC]; + header = Partition[#,1]&@{ + ToString[StringForm[ + "Eurodollar futures rates as of ``", previousstrdate]], + ToString[StringForm[ + "col 1: maturity in years relative to ``", currentstrdate]], + "col 2: rate in percent", + "" + }; + Export[filename <> ".xls", Join[header, previousdata], {"Sheets", "Previous"}] + ] + +WriteEurodollarsChangeFileWithHeader[ + filename_String, + {lastdate_List, lastFOMC_List}, + changedata_List + ] := + Module[{header, currentstrdate, previousstrdate}, + currentstrdate = ListDateToStringDate[lastdate]; + previousstrdate = ListDateToStringDate[lastFOMC]; + header = Partition[#,1]&@{ + ToString[StringForm[ + "Change in Eurodollar futures rates from `1` to `2`", + previousstrdate, currentstrdate]], + ToString[StringForm[ + "col 1: maturity in years relative to ``", currentstrdate]], + "col 2: change in rate (percent)", + "" + }; + Export[filename <> ".xls", Join[header, changedata], {"Sheets", "Change"}] + ] + +WriteEurodollarsAdjustedFileWithHeader[ + filename_String, + lastdate_List, + adjusteddata_List + ] := + Module[{header, currentstrdate}, + currentstrdate = ListDateToStringDate[lastdate]; + header = Partition[#,1]&@{ + ToString[StringForm[ + "Adjusted Eurodollar rates as of ``", currentstrdate]], + "(slope of curve from 3 years to 9 years removed)", + "col 1: maturity in years", + "col 2: adj rate in percent", + "" + }; + Export[filename <> ".xls", Join[header, adjusteddata], {"Sheets", "Adjusted"}] + ] + + +WriteEurodollarsFileWithHeader[ + filename_String, + {lastdate_List, lastFOMC_List}, + {currentdata_List, previousdata_List, changedata_List} + ] := + Module[{header1, header2, header3, currentstrdate, previousstrdate}, + currentstrdate = ListDateToStringDate[lastdate]; + previousstrdate = ListDateToStringDate[lastFOMC]; + header1 = Partition[#,1]&@{ + ToString@StringForm["Eurodollar futures rates as of ``", currentstrdate], + ToString@StringForm["col 1: maturity in years relative to ``", currentstrdate], + "col 2: rate in percent", + ""}; + header2 = Partition[#,1]&@{ + ToString[StringForm[ + "Eurodollar futures rates as of ``", previousstrdate]], + ToString[StringForm[ + "col 1: maturity in years relative to ``", currentstrdate]], + "col 2: rate in percent", + "" + }; + header3 = Partition[#,1]&@{ + ToString[StringForm[ + "Change in Eurodollar futures rates from `1` to `2`", + previousstrdate, currentstrdate]], + ToString[StringForm[ + "col 1: maturity in years relative to ``", currentstrdate]], + "col 2: change in rate (percent)", + "" + }; + Export[filename <> ".xls", + {Join[header1, currentdata], + Join[header2, previousdata], + Join[header3, changedata]}, + {"Sheets", {"Current", "Previous", "Change"}}] + ] + +WriteEurodollarsFileWithHeader[ + filename_String, + {lastdate_List, lastFOMC_List}, + {currentdata_List, previousdata_List, changedata_List, + adjusteddata_List} + ] := + Module[{header1, header2, header3, header4, currentstrdate, previousstrdate}, + currentstrdate = ListDateToStringDate[lastdate]; + previousstrdate = ListDateToStringDate[lastFOMC]; + header1 = Partition[#,1]&@{ + ToString@StringForm["Eurodollar futures rates as of ``", currentstrdate], + ToString@StringForm["col 1: maturity in years relative to ``", currentstrdate], + "col 2: rate in percent", + ""}; + header2 = Partition[#,1]&@{ + ToString[StringForm[ + "Eurodollar futures rates as of ``", previousstrdate]], + ToString[StringForm[ + "col 1: maturity in years relative to ``", currentstrdate]], + "col 2: rate in percent", + "" + }; + header3 = Partition[#,1]&@{ + ToString[StringForm[ + "Change in Eurodollar futures rates from `1` to `2`", + previousstrdate, currentstrdate]], + ToString[StringForm[ + "col 1: maturity in years relative to ``", currentstrdate]], + "col 2: change in rate (percent)", + "" + }; + header4 = Partition[#,1]&@{ + ToString[StringForm[ + "Adjusted Eurodollar rates as of ``", currentstrdate]], + "(slope of curve from 3 years to 9 years removed)", + "col 1: maturity in years", + "col 2: adj rate in percent", + "" + }; + Export[filename <> ".xls", + {Join[header1, currentdata], + Join[header2, previousdata], + Join[header3, changedata], + Join[header4, adjusteddata]}, + {"Sheets", {"Current", "Previous", "Change", "Adjusted"}}] + ] + + + diff --git a/MathematicaFiles/Applications/WulfGanglia.m b/MathematicaFiles/Applications/WulfGanglia.m new file mode 100755 index 0000000..1fdeb47 --- /dev/null +++ b/MathematicaFiles/Applications/WulfGanglia.m @@ -0,0 +1,53 @@ +(* produce a report of features of nodes on Atlanta Fed Wulf cluster *) + +ReadWulfGangia::usage = "ReadWulfGangia[characteristic] returns of \ +list of node numbers paired with the values of the characteristic. \ +Valid values for characteristic include \"cpu_speed\", \"cpu_num\", \ +and \"machine_type\"." + +WulfGangliaNodeReport::usage = "WulfGangliaNodeReport[] returns a \ +report of various features for each node." + +ReadWulfGangia[characteristic_String] := + Module[{url, instring, reportstring}, + url = ToString[ + StringForm[ + "http://wulf.frbatlanta.org/ganglia/?m=`1`&r=hour&s=descending&c=Wulf&h=&sh=1&hc=4", + characteristic]]; + instring = Import[url]; + reportstring = StringDrop[instring, + StringPosition[instring, "n" ~~ NumberString][[-18, 1]] - 1]; + Sort[ + StringCases[reportstring, + Shortest["n" ~~ n : NumberString ~~ __ ~~ characteristic ~~ ":" ~~ + Whitespace ~~ x__ ~~ WordBoundary] :> {ToExpression[n], x}] + ] + ] + +WulfGangliaReportFeatures = { + "machine_type", + "cpu_num", + "cpu_speed", + "mem_total" + } + + +WulfGangliaNodeReport[] := + Module[{subreports, headings}, + subreports = ReadWulfGangia /@ WulfGangliaReportFeatures; + headings = Prepend[Column[#, Alignment -> Center] & /@ + StringSplit[WulfGangliaReportFeatures, "_"], "node"]; + Labeled[ + Framed[ + Grid[ + Prepend[ + Transpose[ + Prepend[subreports[[All, All, 2]], subreports[[1, All, 1]]] + ], + headings + ], + Alignment -> Right, + Dividers -> {False, {False, True, False}}, + Spacings -> {2, .5}] + ], StringDrop[DateString[], -3], Top] + ] diff --git a/MathematicaFiles/Applications/ZhaMathematicaLibrary.m b/MathematicaFiles/Applications/ZhaMathematicaLibrary.m new file mode 100755 index 0000000..a0e2462 --- /dev/null +++ b/MathematicaFiles/Applications/ZhaMathematicaLibrary.m @@ -0,0 +1,168 @@ +(* Tao Zha's Mathematica Library *) + +FormatMatlabForMatrixOutput[mat_?MatrixQ, ArrayName_String] := + Module[{m, n}, + {m, n} = Dimensions[mat]; + Flatten[Table[ + ArrayName <> ToString[StringForm[ + "(`1`,`2`) = `3`;", + i, + j, + mat[[i, j]] // N // CForm + ]], + {i, m}, + {j, n}] + ] + ] + +FormatMatlabForVectorOutput[vec_?VectorQ, ArrayName_String] := + Table[ + ArrayName <> ToString[StringForm[ + "(`1`) = `2`;", + i, + vec[[i]] // N // CForm + ]], + {i, Length[vec]} + ] + +FormatMatlabForOutput[vec_?VectorQ, ArrayName_String] := + Table[ + ArrayName <> ToString[StringForm[ + "(`1`) = `2`;", + i, + vec[[i]] // N // CForm + ]], + {i, Length[vec]} + ] + +FormatCForOutput[mat_?MatrixQ, ArrayName_String] := + Module[{m, n}, + {m, n} = Dimensions[mat]; + Flatten[Table[ + ArrayName <> ToString[StringForm[ + "[`1`,`2`] = `3`;", + i - 1, + j - 1, + mat[[i, j]] // N // CForm + ]], + {i, m}, + {j, n}] + ] + ] +FormatCForOutput[vec_?VectorQ, ArrayName_String] := + Table[ + ArrayName <> ToString[StringForm[ + "[`1`] = `2`;", + i - 1, + vec[[i]] // N // CForm + ]], + {i, Length[vec]} + ] + +(* ----------------------------------------------------- *) +FormatForGreekLettersOutput[vec_?VectorQ] := + Table[ + ToString[StringForm[ + "`1` = ;", + vec[[i]] // N // CForm + ]], + {i, Length[vec]}] + +FormatCMatlabForEqualityOutput[LeftHandList_, RightHandList_] := + Table[ToString[StringForm[ + "`1` = `2`;", + LeftHandList[[i]], + RightHandList[[i]] // N // CForm + ]], + {i, Length[LeftHandList]} + ]; + + +(* ----------------------------------------------------- *) +(* Outputs are all strings. *) +TranslatingToNoSubscript[coef_, rules_] := + coef /. rules /. + Subscript[x_, y_] :> ToExpression[ToString[x] <> ToString[y]] + +MatlabStringReplace[str_] := + StringReplace[ + str, {Shortest["Power(" ~~ x__ ~~ "," ~~ y__ ~~ ")"] :> + "(" ~~ x ~~ ")" ~~ "^" ~~ "(" ~~ y ~~ ")"}] + +CStringReplace[str_] := + StringReplace[str, {"Power(" -> "pow(", "Sqrt" -> "sqrt"}] + +(* ------------------------ Append string to the file ---------------------------------- *) +ExportMatlabStringAppend::usage = + "ExportMatlabStringAppend[filename, data] imports Lines from \ +filename and joins the data (a list of strings) and exports to \ +filename. ExportAppend creates the file if filename does not exist."; + +ExportMatlabStringAppend[filename_String, data_] := + Module[{divider0 = {"\n%-------------------\n"}}, + Export[filename, + Join[ + Quiet[Check[Import[filename, "Lines"], {}]], + divider0, + data], + "Text"]; + ] + + + +(* ------------------- Arranging the measurement equations into matrix measurement form. See the project example with Marvin Goodfriend. ---------------- *) +tzMeasurementForm[equations:{__Equal}, xstatet_List, xut_List] := + Module[{a, H, Psiu}, + {resid, H} = Normal[CoefficientArrays[equations[[All, 2]], xstatet]]; + {a, Psiu} = Normal[CoefficientArrays[resid, xut]]; + (* All means all the rows; [All, 2] means right-hand equations for all the rows. *) + {a, H, Psiu} + ] + +tzMeasurementFormNoMeasureErrors[equations:{__Equal}, xstatet_List] := +Module[{a, H}, + {a, H} = Normal[ + CoefficientArrays[equations[[All, 2]], xstatet]]; + (* All means all the rows; [All, 2] means right-hand equations for all the rows. *) + {a, H} +] + + +tzMeasurementForm4HOnly[equations:{__Equal}, xstatet_List] := +Module[{H}, + H = Normal[ + CoefficientArrays[equations[[All, 2]], xstatet][[2]]]; + (* All means all the rows; [All, 2] means right-hand equations for all the rows. *) + {H} +] + + +(* ------------------- Arranging the state equations into matrix state form ---------------- *) +tzStateForm[equations:{__Equal}, y0_List, \[CurlyEpsilon]0_List, t_: t] := + Module[{y1, \[CurlyEpsilon]1, \[CurlyEpsilon], resid, g0, g1, psi, c}, + y1 = y0 /. t -> t - 1; + \[CurlyEpsilon]1 = + Union[Cases[equations, + Alternatives @@ (\[CurlyEpsilon]0 /. t -> t - 1), Infinity]]; + \[CurlyEpsilon] = Join[\[CurlyEpsilon]0, \[CurlyEpsilon]1]; + {resid, g0} = Normal[CoefficientArrays[equations, y0]]; + resid = -resid; + {g1, psi} = + Normal[CoefficientArrays[resid, #][[2]] & /@ {y1, \[CurlyEpsilon]}]; + c = resid - (g1.y1 + psi.\[CurlyEpsilon]) // Simplify; + {{g0, g1, c, psi}, {y0, y1, \[CurlyEpsilon]}} + ] + + + +(* ------------------- Exporting Greek symbols to ascii symbols used by C or Matlab ---------------- *) +(* ------------------- Calling example: BaseParsOuput = ExportSymbols[BasePars,"tz"] ---------------- *) +ExportSymbols[parmlist_List, initial_: ""] := + ToExpression[initial <> # & /@ StringReplace[(ToString[FullForm[#]] & /@ parmlist), + {"Subscript" -> "", "\\[" -> "", "]" -> "","[" -> "", "," -> "", " " -> ""}] + ] + +(* ------------------- Rules for exporting Greek symbols to ascii symbols used by C or Matlab ---------------- *) +(* ------------------- Calling example: BaseParsOuput = ExportSymbolsRules[BasePars,"tz"] ---------------- *) +ExportSymbolsRules[parmlist_List, initial_: ""] := + Thread[parmlist -> ExportSymbols[parmlist, initial]] \ No newline at end of file diff --git a/MatlabFiles/A0LHFUN.M b/MatlabFiles/A0LHFUN.M new file mode 100755 index 0000000..93e3fd3 --- /dev/null +++ b/MatlabFiles/A0LHFUN.M @@ -0,0 +1,38 @@ +function of = a0lhfun(x,s,nobs,nvar,a0indx) +% of = a0lhfun(x,s,nobs,nvar,a0indx) -- negative logLH +% Note: columns correpond to equations +% general program to setup A0 matrix and compute the likelihood +% requires +% x (parameter vector), +% s (covariance matrix of innovations): note already divided by "nobs" +% nobs (no of obs), +% nvar (no of variables), +% a0indx (matrix indicating the free parameters in A0, and each column in A0 corresponds +% to an equation) +% written by Eric Leeper + +a0 = zeros(nvar); +a0(a0indx) = x; +% Note: each column in a0 corresponds to an equation!! +% +%%ada = chol(a0'*a0); +%%ada = log(abs(diag(ada))); +%%ada = sum(ada); +% ** TZ, 10/15/96, the above two lines can be improved by the following three lines +[a0l,a0u] = lu(a0); +%ada=diag(abs(a0u)); +%ada=sum(log(ada)); +ada = sum(log(abs(diag(a0u)))); + +% +%tra = trace(a0'*s*a0); +tra = reshape(s,nvar*nvar,1)'*reshape(a0*a0',nvar*nvar,1); +%if ada == 0 +% of = 1.0; +% else +% of = -nobs*ada + nobs*.5*tra; +%end +% commented out by T.Z. for there appears no sense of using "if-end" + + +of = -nobs*ada + nobs*.5*tra; \ No newline at end of file diff --git a/MatlabFiles/A0LHGRAD.M b/MatlabFiles/A0LHGRAD.M new file mode 100755 index 0000000..5bf5859 --- /dev/null +++ b/MatlabFiles/A0LHGRAD.M @@ -0,0 +1,21 @@ +function [g,badg] = a0lhgrad(x0,s,nobs,nvar,a0indx); +%function [g,badg] = a0lhgrad(x0,s,nobs,nvar,a0indx); +% computes analytical gradient for use in csminwel.m +% x0 (parameter vector), +% s (covariance matrix of innovations): note divided by "nobs" +% nobs (no of obs), +% nvar (no of variables), +% a0indx (matrix indicating the free parameters in A0, and each column in A0 corresponds +% to an equation) +% +% Written by Tao Zha + + +%%a = zeros(nvar*nvar,1); +a = zeros(nvar); +%%g = zeros(nvar*nvar,1); % 4/27/97: not necessary. TAZ +badg = 0; +a(a0indx) = x0; +b = -nobs*inv(a') + nobs*s*a; +b = reshape(b,nvar*nvar,1); +g = b(a0indx); diff --git a/MatlabFiles/A0lhgh.m b/MatlabFiles/A0lhgh.m new file mode 100755 index 0000000..4fa7e40 --- /dev/null +++ b/MatlabFiles/A0lhgh.m @@ -0,0 +1,19 @@ +function g = a0lhgh(x0,s,nobs,nvar,a0indx); +%function g = a0lhgh(x0,s,nobs,nvar,a0indx); +% computes the hessian with analytical gradient provided +% x0 (parameter vector), +% s (covariance matrix of innovations): note divided by "nobs" +% nobs (no of obs), +% nvar (no of variables), +% a0indx (matrix indicating the free parameters in A0, and each column in A0 corresponds +% to an equation) + + +%%a = zeros(nvar*nvar,1); +a = zeros(nvar); +g = zeros(nvar*nvar,1); +badg = 0; +a(a0indx) = x0; +b = -nobs*inv(a') + nobs*s*a; +b = reshape(b,nvar*nvar,1); +g = b(a0indx); \ No newline at end of file diff --git a/MatlabFiles/BinRead.m b/MatlabFiles/BinRead.m new file mode 100755 index 0000000..1f5d1fa --- /dev/null +++ b/MatlabFiles/BinRead.m @@ -0,0 +1,15 @@ +nbuffer = 10; +ndraws=3*nbuffer; + +n=3; +yhatw = zeros(n^2,ndraws); +seldraw = [3 7]; + +[fid,message]=fopen('outyhat.bin') +%[xd,count]=fread(fid,[n^2,length(seldraw)],'double'); % (1) working +[xd,count]=fread(fid,inf,'single'); % (2) working. with 'single' or 'double' +fid +message +count +%xdd=reshape(xd,n^2,length(seldraw)) % (1) working +xdd=reshape(xd,n^2,ndraws) % (2) working \ No newline at end of file diff --git a/MatlabFiles/BinWrite.m b/MatlabFiles/BinWrite.m new file mode 100755 index 0000000..9912e5f --- /dev/null +++ b/MatlabFiles/BinWrite.m @@ -0,0 +1,20 @@ +nbuffer = 10; +ndraws=3*nbuffer; + +n=3; +yhatw = zeros(n^2,nbuffer); + +wdraws=0; +for draws=1:ndraws + tmp = draws*ones(n); + yhatw(:,draws-wdraws) = tmp(:); + + if ~mod(draws,nbuffer) + wdraws=draws + + fwriteid = fopen('outyhat.bin','a'); + count = fwrite(fwriteid,yhatw,'single'); % 'single' or 'double' + status = fclose('all'); + end +end + diff --git a/MatlabFiles/CONTENTS.M b/MatlabFiles/CONTENTS.M new file mode 100755 index 0000000..f5531d6 --- /dev/null +++ b/MatlabFiles/CONTENTS.M @@ -0,0 +1,5 @@ +% Chris Sims and Tao Zha's .m files. +% Vertion 1.1 March 1998 +% optimization, impulse, forecast, hessian, gradient +% +% Copyright (c) by Sims and Zha \ No newline at end of file diff --git a/MatlabFiles/CSMINWEL.M0 b/MatlabFiles/CSMINWEL.M0 new file mode 100755 index 0000000..d3e8005 --- /dev/null +++ b/MatlabFiles/CSMINWEL.M0 @@ -0,0 +1,271 @@ +function [fh,xh,gh,H,itct,fcount,retcodeh] = csminwel(fcn,x0,H0,grad,crit,nit, ... + P1,P2,P3,P4,P5,P6,P7,P8,P9,P10,P11,P12,P13,P14,P15,P16,P17,... + P18,P19,P20) +% [fhat,xhat,ghat,Hhat,itct,fcount,retcodehat] = csminwel(fcn,x0,H0,grad,crit,nit, ... +% P1,P2,P3,P4) +% +% x0(estimated parameter) SHOULD BE A ROW VECTOR. +% +% fcn and grad are strings naming functions. If grad is null, numerical +% derivatives are used. The P parameters need not be present. They are passed +% to fcn as additional arguments. +% +% Reindented and modified to allow compilation (comment out use of tailstr, eval) by CAS, +% 7/22/96 +% +[nx,no]=size(x0); +nx=max(nx,no); +Verbose=1; +NumGrad= ( ~isstr(grad) | length(grad)==0); +done=0; +itct=0; +fcount=0; +snit=100; +tailstr = ')'; +stailstr = []; +% Lines below make the number of Pi's optional. This is inefficient, though, and precludes +% use of the matlab compiler. Without them, we use feval and the number of Pi's must be +% changed with the editor for each application. Places where this is required are marked +% with ARGLIST comments +%for i=nargin-6:-1:1 +% tailstr=[ ',P' num2str(i) tailstr]; +% stailstr=[' P' num2str(i) stailstr]; +%end +%f0 = eval([fcn '(x0' tailstr]); +%ARGLIST +f0 = feval(fcn,x0,P1,P2,P3,P4,P5,P6,P7,P8,P9,P10,P11,P12,P13); +% disp('first fcn in csminwel.m ----------------') % Jinill on 9/5/95 +if f0 > 1e50, disp('Bad initial parameter.'), return, end +if NumGrad + if length(grad)==0 + %[g badg] = eval(['numgrad(fcn, x0' tailstr]); + %ARGLIST + [g badg] = numgrad(fcn,x0,P1,P2,P3,P4,P5,P6,P7,P8,P9,P10,P11,P12,P13); + else + badg=any(find(grad==0)); + g=grad; + end + %numgrad(fcn,x0,P1,P2,P3,P4); +else + %[g badg] = eval([grad '(x0' tailstr]); + %ARGLIST + [g badg] = feval(grad,x0,P1,P2,P3,P4,P5,P6,P7,P8,P9,P10,P11,P12,P13); +end +x=x0; +f=f0; +H=H0; +cliff=0; +while ~done + g1=[]; g2=[]; g3=[]; + %addition fj. 7/6/94 for control + disp('-----------------') + disp('-----------------') + %disp('f and x at the beginning of new iteration') + disp('f at the beginning of new iteration') + f + %if size(x,1)>size(x,2) + % x' + %else + % x + %end + %------------------------- + itct=itct+1; + disp(' going to start csminit.m to produce f1') + %[f1 x1 fc retcode1] = eval(['csminit(fcn,x,f,g,badg,H' tailstr]); + %ARGLIST + [f1 x1 fc retcode1] = csminit(fcn,x,f,g,badg,H,P1,P2,P3,P4,P5,P6,P7,... + P8,P9,P10,P11,P12,P13); + % itct=itct+1; + fcount = fcount+fc; + % erased on 8/4/94 + % if (retcode == 1) | (abs(f1-f) < crit) + % done=1; + % end + % if itct > nit + % done = 1; + % retcode = -retcode; + % end + if retcode1 ~= 1 + if retcode1==2 | retcode1==4 + wall1=1; badg1=1; + else + if NumGrad + %[g1 badg1] = eval(['numgrad(fcn, x1' tailstr]); + %ARGLIST + [g1 badg1] = numgrad(fcn, x1,P1,P2,P3,P4,P5,P6,P7,P8,P9,... + P10,P11,P12,P13); + else + %[g1 badg1] = eval([grad '(x1' tailstr]); + %ARGLIST + [g1 badg1] = feval(grad, x1,P1,P2,P3,P4,P5,P6,P7,P8,P9,... + P10,P11,P12,P13); + end + wall1=badg1; + % g1 + badg1; + %eval(['save g1 g1 x1 f1 ' stailstr]); + %ARGLIST + save g1 g1 x1 f1 P1 P2 P3 P4 P5 P6 P7 P8 P9 P10 P11 P12 P13; + end + if wall1 % & (~done) by Jinill + % Bad gradient or back and forth on step length. Possibly at + % cliff edge. Try perturbing search direction. + % + %fcliff=fh;xcliff=xh; + Hcliff=H+diag(diag(H).*rand(nx,1)); + disp('Cliff. Perturbing search direction.') + %[f2 x2 fc retcode2] = eval(['csminit(fcn,x,f,g,badg,Hcliff' tailstr]); + %ARGLIST + [f2 x2 fc retcode2] = csminit(fcn,x,f,g,badg,Hcliff,P1,P2,P3,P4,... + P5,P6,P7,P8,P9,P10,P11,P12,P13); + fcount = fcount+fc; % put by Jinill + if f2 < f + if retcode2==2 | retcode2==4 + wall2=1; badg2=1; + else + if NumGrad + %[g2 badg2] = eval(['numgrad(fcn, x2' tailstr]); + %ARGLIST + [g2 badg2] = numgrad(fcn, x2,P1,P2,P3,P4,P5,P6,P7,P8,... + P9,P10,P11,P12,P13); + else + %[g2 badg2] = eval([grad '(x2' tailstr]); + %ARGLIST + [g2 badg2] = feval(grad,x2,P1,P2,P3,P4,P5,P6,P7,P8,... + P9,P10,P11,P12,P13); + end + wall2=badg2; + % g2 + badg2 + %eval(['save g2 g2 x2 f2 ' stailstr]); + %ARGLIST + save g2 g2 x2 f2 P1 P2 P3 P4 P5 P6 P7 P8 P9 P10 P11 P12 P13; + end + if wall2 + disp('Cliff again. Try traversing') + if norm(x2-x1) < 1e-13 + f3=f; x3=x; badg3=1; + else + gcliff=((f2-f1)/((norm(x2-x1))^2))*(x2-x1)'; + %[f3 x3 fc retcode3] = eval(['csminit(fcn,x,f,gcliff,0,eye(nx)' tailstr]); + %ARGLIST + [f3 x3 fc retcode3] = csminit(fcn,x,f,gcliff,0,eye(nx),P1,P2,P3,... + P4,P5,P6,P7,P8,... + P9,P10,P11,P12,P13); + fcount = fcount+fc; % put by Jinill + if retcode3==2 | retcode3==4 + wall3=1; badg3=1; + else + if NumGrad + %[g3 badg3] = eval(['numgrad(fcn, x3' tailstr]); + %ARGLIST + [g3 badg3] = numgrad(fcn, x3,P1,P2,P3,P4,P5,P6,P7,P8,... + P9,P10,P11,P12,P13); + else + %[g3 badg3] = eval([grad '(x3' tailstr]); + %ARGLIST + [g3 badg3] = feval(grad,x3,P1,P2,P3,P4,P5,P6,P7,P8,... + P9,P10,P11,P12,P13); + end + wall3=badg3; + % g3 + badg3 + %eval(['save g3 g3 x3 f3 ' stailstr]); + %ARGLIST + save g3 g3 x3 f3 P1 P2 P3 P4 P5 P6 P7 P8 P9 P10 P11 P12 P13; + end + end + else + f3=f; x3=x; badg3=1; + end + else + f3=f; x3=x; badg3=1; + end + else + % normal iteration, no walls, or else we're finished here. + f2=f; f3=f; badg2=1; badg3=1; + end + end + %how to pick gh and xh + if f3<f & badg3==0 + ih=3 + fh=f3;xh=x3;gh=g3;badgh=badg3;retcodeh=retcode3; + elseif f2<f & badg2==0 + ih=2 + fh=f2;xh=x2;gh=g2;badgh=badg2;retcodeh=retcode2; + elseif f1<f & badg1==0 + ih=1 + fh=f1;xh=x1;gh=g1;badgh=badg1;retcodeh=retcode1; + else + [fh,ih] = min([f1,f2,f3]); + ih + %eval(['xh=x' num2str(ih) ';']) + if size(x1,2)>1 + xi=[x1;x2;x3]; + xh=xi(ih,:); + else + xi=[x1 x2 x3]; + xh=xi(:,ih); + end + %eval(['gh=g' num2str(ih) ';']) + %eval(['retcodeh=retcode' num2str(ih) ';']) + retcodei=[retcode1,retcode2,rectode3]; + retcodeh=retcodei(ih); + if gh==[] + if NumGrad + %[gh badgh] = eval(['numgrad(fcn, xh' tailstr]); + %ARGLIST + [gh badgh] = numgrad(fcn,xh,P1,P2,P3,P4,P5,P6,P7,P8,... + P9,P10,P11,P12,P13); + else + %[gh badgh] = eval([grad '(xh' tailstr]); + %ARGLIST + [gh badgh] = feval(grad,xh,P1,P2,P3,P4,P5,P6,P7,P8,... + P9,P10,P11,P12,P13); + end + end + badgh=1; + end + %end of picking + %ih + %fh + %xh + %gh + %badgh + stuck = (abs(fh-f) < crit); + if (~badg)&(~badgh)&(~stuck) + H = bfgsi(H,gh-g,xh-x); + end + if Verbose + disp('----') + disp(['Improvement on iteration ' int2str(itct) ' = ' num2str(f-fh)]) + end + if Verbose + if itct > nit + disp('iteration count termination') + done = 1; + elseif stuck + disp('improvement < crit termination') + done = 1; + end + rc=retcodeh; + if rc == 1 + disp('zero gradient') + elseif rc == 6 + disp('smallest step still improving too slow, reversed gradient') + elseif rc == 5 + disp('largest step still improving too fast') + elseif (rc == 4) | (rc==2) + disp('back and forth on step length never finished') + elseif rc == 3 + disp('smallest step still improving too slow') + end + end + f=fh; + x=xh; + g=gh; + badg=badgh; +end +% what about making an m-file of 10 lines including numgrad.m +% since it appears three times in csminwel.m + \ No newline at end of file diff --git a/MatlabFiles/ERRORS.M b/MatlabFiles/ERRORS.M new file mode 100755 index 0000000..b06b8f7 --- /dev/null +++ b/MatlabFiles/ERRORS.M @@ -0,0 +1,86 @@ +function [vd,str,imf] = errors(Bh,swish,nn) +% Computing variance decompositions and impulse functions with +% [vd,str,imf] = errors(Bh,swish,nn) +% where imf and vd is of the same format as in RATS, that is to say: +% Column: nvar responses to 1st shock, +% nvar responses to 2nd shock, and so on. +% Row: steps of impulse responses. +% vd: variance decompositions +% str: standard errors of each variable, steps-by-nvar +% imf: impulse response functions +% Bh is the estimated reduced form coefficient in the form +% Y(T*nvar) = XB + U, X: T*k, B: k*nvar. The matrix +% form or dimension is the same as "Bh" from the function "sye"; +% swish is the inv(A0) in the structural model A(L)y(t) = e(t). +% nn is the numbers of inputs [nvar,lags,# of impulse responses]. + +nvar = nn(1); +lags = nn(2); +imstep = nn(3); % number of steps for impulse responses + +Ah = Bh'; +% Row: nvar equations +% Column: 1st lag (with nvar variables) to lags (with nvar variables) + const = k. + +imf = zeros(imstep,nvar*nvar); +vd = imf; +% Column: nvar responses to 1st shock, nvar responses to 2nd shock, and so on. +% Row: steps of impulse responses. +str = zeros(imstep,nvar); % initializing standard errors of each equation +M = zeros(nvar*(lags+1),nvar); +% Stack lags M's in the order of, e.g., [Mlags, ..., M2,M1;M0] +M(1:nvar,:) = swish'; +Mtem = M(1:nvar,:); % temporary M -- impulse responses. +% +Mvd = Mtem.^2; % saved for the cumulative sum later +Mvds = (sum(Mvd'))'; +str(1,:) = sqrt(Mvds'); % standard errors of each equation +Mvds = Mvds(:,ones(size(Mvds,1),1)); +Mvdtem = (100.0*Mvd) ./ Mvds; % tempoary Mvd -- variance decompositions +% first or initial responses to +% one standard deviation shock (or forecast errors). +% Row: responses; Column: shocks +% +% * put in the form of "imf" +imf(1,:) = Mtem(:)'; +vd(1,:) = Mvdtem(:)'; + +t = 1; +ims1 = min([imstep-1 lags]); +while t <= ims1 + Mtem = Ah(:,1:nvar*t)*M(1:nvar*t,:); + % Row: nvar equations, each for the nvar variables at tth lag + M(nvar+1:nvar*(t+1),:)=M(1:nvar*t,:); + M(1:nvar,:) = Mtem; + % ** impulse response functions + imf(t+1,:) = Mtem(:)'; + % stack imf with each step, Row: 6 var to 1st shock, 6 var to 2nd shock, etc. + % ** variance decompositions + Mvd = Mvd + Mtem.^2; % saved for the cumulative sum later + Mvds = (sum(Mvd'))'; + str(t+1,:) = sqrt(Mvds'); % standard errors of each equation + Mvds = Mvds(:,ones(size(Mvds,1),1)); + Mvdtem = (100.0*Mvd) ./ Mvds; % tempoary Mvd -- variance decompositions + vd(t+1,:) = Mvdtem(:)'; + % stack vd with each step, Row: 6 var to 1st shock, 6 var to 2nd shock, etc. + t= t+1; +end + +for t = lags+1:imstep-1 + Mtem = Ah(:,1:nvar*lags)*M(1:nvar*lags,:); + % Row: nvar equations, each for the nvar variables at tth lag + M(nvar+1:nvar*(t+1),:) = M(1:nvar*t,:); + M(1:nvar,:)=Mtem; + % ** impulse response functions + imf(t+1,:) = Mtem(:)'; + % stack imf with each step, Row: 6 var to 1st shock, 6 var to 2nd shock, etc. + % ** variance decompositions + Mvd = Mvd + Mtem.^2; % saved for the cumulative sum later + Mvds = (sum(Mvd'))'; + str(t+1,:) = sqrt(Mvds'); % standard errors of each equation + Mvds = Mvds(:,ones(size(Mvds,1),1)); + Mvdtem = (100.0*Mvd) ./ Mvds; % tempoary Mvd -- variance decompositions + vd(t+1,:) = Mvdtem(:)'; + % stack vd with each step, Row: 6 var to 1st shock, 6 var to 2nd shock, etc. +end + diff --git a/MatlabFiles/ERRORS.OLD b/MatlabFiles/ERRORS.OLD new file mode 100755 index 0000000..19e06be --- /dev/null +++ b/MatlabFiles/ERRORS.OLD @@ -0,0 +1,91 @@ +function [vd,str,imf] = errors(Bh,swish,nn) +% Computing variance decompositions and impulse functions with +% [vd,str,imf] = errors(Bh,swish,nn) +% where imf and vd is of the same format as in RATS, that is to say: +% Column: nvar responses to 1st shock, +% nvar responses to 2nd shock, and so on. +% Row: steps of impulse responses. +% vd: variance decompositions +% str: standard errors of each variable, steps-by-nvar +% imf: impulse response functions +% Bh is the estimated reduced form coefficient in the form +% Y(T*nvar) = XB + U, X: T*k, B: k*nvar. The matrix +% form or dimension is the same as "Bh" from the function "sye"; +% swish is the inv(A0) in the structural model A(L)y(t) = e(t). +% nn is the numbers of inputs [nvar,lags,# of impulse responses]. + +nvar = nn(1); +lags = nn(2); +imstep = nn(3); % number of steps for impulse responses + +Ah = Bh'; +% Row: nvar equations +% Column: 1st lag (with nvar variables) to lags (with nvar variables) + const = k. + +imf = zeros(imstep,nvar*nvar); +vd = imf; +% Column: nvar responses to 1st shock, nvar responses to 2nd shock, and so on. +% Row: steps of impulse responses. +str = zeros(imstep,nvar); % initializing standard errors of each equation +M = zeros(nvar*(lags+1),nvar); +% Stack M0;M1;M2;...;Mlags +M(1:nvar,:) = swish; +Mtem = M(1:nvar,:); % temporary M -- impulse responses. +% +Mvd = Mtem.^2; % saved for the cumulative sum later +Mvds = (sum(Mvd'))'; +str(1,:) = sqrt(Mvds'); % standard errors of each equation +Mvds = Mvds(:,ones(size(Mvds,1),1)); +Mvdtem = (100.0*Mvd) ./ Mvds; % tempoary Mvd -- variance decompositions +% first or initial responses to +% one standard deviation shock (or forecast errors). +% Row: responses; Column: shocks +% +% * put in the form of "imf" +imf(1,:) = Mtem(:)'; +vd(1,:) = Mvdtem(:)'; + +t = 1; +ims1 = min([imstep-1 lags]); +while t <= ims1 + Mtem = zeros(nvar,nvar); + for k = 1:t + Mtem = Ah(:,nvar*(k-1)+1:nvar*k)*M(nvar*(t-k)+1:nvar*(t-k+1),:) + Mtem; + % Row: nvar equations, each for the nvar variables at tth lag + end + % ** impulse response functions + M(nvar*t+1:nvar*(t+1),:) = Mtem; + imf(t+1,:) = Mtem(:)'; + % stack imf with each step, Row: 6 var to 1st shock, 6 var to 2nd shock, etc. + % ** variance decompositions + Mvd = Mvd + Mtem.^2; % saved for the cumulative sum later + Mvds = (sum(Mvd'))'; + str(t+1,:) = sqrt(Mvds'); % standard errors of each equation + Mvds = Mvds(:,ones(size(Mvds,1),1)); + Mvdtem = (100.0*Mvd) ./ Mvds; % tempoary Mvd -- variance decompositions + vd(t+1,:) = Mvdtem(:)'; + % stack vd with each step, Row: 6 var to 1st shock, 6 var to 2nd shock, etc. + t= t+1; +end + +for t = lags+1:imstep-1 + M(1:nvar*lags,:) = M(nvar+1:nvar*(lags+1),:); + Mtem = zeros(nvar,nvar); + for k = 1:lags + Mtem = Ah(:,nvar*(k-1)+1:nvar*k)*M(nvar*(lags-k)+1:nvar*(lags-k+1),:) + Mtem; + % Row: nvar equations, each for the nvar variables at tth lag + end + % ** impulse response functions + M(nvar*lags+1:nvar*(lags+1),:) = Mtem; + imf(t+1,:) = Mtem(:)'; + % stack imf with each step, Row: 6 var to 1st shock, 6 var to 2nd shock, etc. + % ** variance decompositions + Mvd = Mvd + Mtem.^2; % saved for the cumulative sum later + Mvds = (sum(Mvd'))'; + str(t+1,:) = sqrt(Mvds'); % standard errors of each equation + Mvds = Mvds(:,ones(size(Mvds,1),1)); + Mvdtem = (100.0*Mvd) ./ Mvds; % tempoary Mvd -- variance decompositions + vd(t+1,:) = Mvdtem(:)'; + % stack vd with each step, Row: 6 var to 1st shock, 6 var to 2nd shock, etc. +end + \ No newline at end of file diff --git a/MatlabFiles/ERRORS.m1 b/MatlabFiles/ERRORS.m1 new file mode 100755 index 0000000..19e06be --- /dev/null +++ b/MatlabFiles/ERRORS.m1 @@ -0,0 +1,91 @@ +function [vd,str,imf] = errors(Bh,swish,nn) +% Computing variance decompositions and impulse functions with +% [vd,str,imf] = errors(Bh,swish,nn) +% where imf and vd is of the same format as in RATS, that is to say: +% Column: nvar responses to 1st shock, +% nvar responses to 2nd shock, and so on. +% Row: steps of impulse responses. +% vd: variance decompositions +% str: standard errors of each variable, steps-by-nvar +% imf: impulse response functions +% Bh is the estimated reduced form coefficient in the form +% Y(T*nvar) = XB + U, X: T*k, B: k*nvar. The matrix +% form or dimension is the same as "Bh" from the function "sye"; +% swish is the inv(A0) in the structural model A(L)y(t) = e(t). +% nn is the numbers of inputs [nvar,lags,# of impulse responses]. + +nvar = nn(1); +lags = nn(2); +imstep = nn(3); % number of steps for impulse responses + +Ah = Bh'; +% Row: nvar equations +% Column: 1st lag (with nvar variables) to lags (with nvar variables) + const = k. + +imf = zeros(imstep,nvar*nvar); +vd = imf; +% Column: nvar responses to 1st shock, nvar responses to 2nd shock, and so on. +% Row: steps of impulse responses. +str = zeros(imstep,nvar); % initializing standard errors of each equation +M = zeros(nvar*(lags+1),nvar); +% Stack M0;M1;M2;...;Mlags +M(1:nvar,:) = swish; +Mtem = M(1:nvar,:); % temporary M -- impulse responses. +% +Mvd = Mtem.^2; % saved for the cumulative sum later +Mvds = (sum(Mvd'))'; +str(1,:) = sqrt(Mvds'); % standard errors of each equation +Mvds = Mvds(:,ones(size(Mvds,1),1)); +Mvdtem = (100.0*Mvd) ./ Mvds; % tempoary Mvd -- variance decompositions +% first or initial responses to +% one standard deviation shock (or forecast errors). +% Row: responses; Column: shocks +% +% * put in the form of "imf" +imf(1,:) = Mtem(:)'; +vd(1,:) = Mvdtem(:)'; + +t = 1; +ims1 = min([imstep-1 lags]); +while t <= ims1 + Mtem = zeros(nvar,nvar); + for k = 1:t + Mtem = Ah(:,nvar*(k-1)+1:nvar*k)*M(nvar*(t-k)+1:nvar*(t-k+1),:) + Mtem; + % Row: nvar equations, each for the nvar variables at tth lag + end + % ** impulse response functions + M(nvar*t+1:nvar*(t+1),:) = Mtem; + imf(t+1,:) = Mtem(:)'; + % stack imf with each step, Row: 6 var to 1st shock, 6 var to 2nd shock, etc. + % ** variance decompositions + Mvd = Mvd + Mtem.^2; % saved for the cumulative sum later + Mvds = (sum(Mvd'))'; + str(t+1,:) = sqrt(Mvds'); % standard errors of each equation + Mvds = Mvds(:,ones(size(Mvds,1),1)); + Mvdtem = (100.0*Mvd) ./ Mvds; % tempoary Mvd -- variance decompositions + vd(t+1,:) = Mvdtem(:)'; + % stack vd with each step, Row: 6 var to 1st shock, 6 var to 2nd shock, etc. + t= t+1; +end + +for t = lags+1:imstep-1 + M(1:nvar*lags,:) = M(nvar+1:nvar*(lags+1),:); + Mtem = zeros(nvar,nvar); + for k = 1:lags + Mtem = Ah(:,nvar*(k-1)+1:nvar*k)*M(nvar*(lags-k)+1:nvar*(lags-k+1),:) + Mtem; + % Row: nvar equations, each for the nvar variables at tth lag + end + % ** impulse response functions + M(nvar*lags+1:nvar*(lags+1),:) = Mtem; + imf(t+1,:) = Mtem(:)'; + % stack imf with each step, Row: 6 var to 1st shock, 6 var to 2nd shock, etc. + % ** variance decompositions + Mvd = Mvd + Mtem.^2; % saved for the cumulative sum later + Mvds = (sum(Mvd'))'; + str(t+1,:) = sqrt(Mvds'); % standard errors of each equation + Mvds = Mvds(:,ones(size(Mvds,1),1)); + Mvdtem = (100.0*Mvd) ./ Mvds; % tempoary Mvd -- variance decompositions + vd(t+1,:) = Mvdtem(:)'; + % stack vd with each step, Row: 6 var to 1st shock, 6 var to 2nd shock, etc. +end + \ No newline at end of file diff --git a/MatlabFiles/ERRORS.sav b/MatlabFiles/ERRORS.sav new file mode 100755 index 0000000..7103d6f --- /dev/null +++ b/MatlabFiles/ERRORS.sav @@ -0,0 +1,86 @@ +function [vd,str,imf] = errors(Bh,swish,nn) +% Computing variance decompositions and impulse functions with +% [vd,str,imf] = errors(Bh,swish,nn) +% where imf and vd is of the same format as in RATS, that is to say: +% Column: nvar responses to 1st shock, +% nvar responses to 2nd shock, and so on. +% Row: steps of impulse responses. +% vd: variance decompositions +% str: standard errors of each variable, steps-by-nvar +% imf: impulse response functions +% Bh is the estimated reduced form coefficient in the form +% Y(T*nvar) = XB + U, X: T*k, B: k*nvar. The matrix +% form or dimension is the same as "Bh" from the function "sye"; +% swish is the inv(A0) in the structural model A(L)y(t) = e(t). +% nn is the numbers of inputs [nvar,lags,# of impulse responses]. + +nvar = nn(1); +lags = nn(2); +imstep = nn(3); % number of steps for impulse responses + +Ah = Bh'; +% Row: nvar equations +% Column: 1st lag (with nvar variables) to lags (with nvar variables) + const = k. + +imf = zeros(imstep,nvar*nvar); +vd = imf; +% Column: nvar responses to 1st shock, nvar responses to 2nd shock, and so on. +% Row: steps of impulse responses. +str = zeros(imstep,nvar); % initializing standard errors of each equation +M = zeros(nvar*(lags+1),nvar); +% Stack lags M's in the order of, e.g., [Mlags, ..., M2,M1;M0] +M(1:nvar,:) = swish; +Mtem = M(1:nvar,:); % temporary M -- impulse responses. +% +Mvd = Mtem.^2; % saved for the cumulative sum later +Mvds = (sum(Mvd'))'; +str(1,:) = sqrt(Mvds'); % standard errors of each equation +Mvds = Mvds(:,ones(size(Mvds,1),1)); +Mvdtem = (100.0*Mvd) ./ Mvds; % tempoary Mvd -- variance decompositions +% first or initial responses to +% one standard deviation shock (or forecast errors). +% Row: responses; Column: shocks +% +% * put in the form of "imf" +imf(1,:) = Mtem(:)'; +vd(1,:) = Mvdtem(:)'; + +t = 1; +ims1 = min([imstep-1 lags]); +while t <= ims1 + Mtem = Ah(:,1:nvar*t)*M(1:nvar*t,:); + % Row: nvar equations, each for the nvar variables at tth lag + M(nvar+1:nvar*(t+1),:)=M(1:nvar*t,:); + M(1:nvar,:) = Mtem; + % ** impulse response functions + imf(t+1,:) = Mtem(:)'; + % stack imf with each step, Row: 6 var to 1st shock, 6 var to 2nd shock, etc. + % ** variance decompositions + Mvd = Mvd + Mtem.^2; % saved for the cumulative sum later + Mvds = (sum(Mvd'))'; + str(t+1,:) = sqrt(Mvds'); % standard errors of each equation + Mvds = Mvds(:,ones(size(Mvds,1),1)); + Mvdtem = (100.0*Mvd) ./ Mvds; % tempoary Mvd -- variance decompositions + vd(t+1,:) = Mvdtem(:)'; + % stack vd with each step, Row: 6 var to 1st shock, 6 var to 2nd shock, etc. + t= t+1; +end + +for t = lags+1:imstep-1 + Mtem = Ah(:,1:nvar*lags)*M(1:nvar*lags,:); + % Row: nvar equations, each for the nvar variables at tth lag + M(nvar+1:nvar*(t+1),:) = M(1:nvar*t,:); + M(1:nvar,:)=Mtem; + % ** impulse response functions + imf(t+1,:) = Mtem(:)'; + % stack imf with each step, Row: 6 var to 1st shock, 6 var to 2nd shock, etc. + % ** variance decompositions + Mvd = Mvd + Mtem.^2; % saved for the cumulative sum later + Mvds = (sum(Mvd'))'; + str(t+1,:) = sqrt(Mvds'); % standard errors of each equation + Mvds = Mvds(:,ones(size(Mvds,1),1)); + Mvdtem = (100.0*Mvd) ./ Mvds; % tempoary Mvd -- variance decompositions + vd(t+1,:) = Mvdtem(:)'; + % stack vd with each step, Row: 6 var to 1st shock, 6 var to 2nd shock, etc. +end + \ No newline at end of file diff --git a/MatlabFiles/FORECAST.M b/MatlabFiles/FORECAST.M new file mode 100755 index 0000000..96f0680 --- /dev/null +++ b/MatlabFiles/FORECAST.M @@ -0,0 +1,25 @@ +function yhat = forecast(Bh,phi,nn) +% yhat = forecast(Bh,phi,nn) +% +% Forecast: unconditional forecating: yhat = forecast(Bh,phi,nn) +% y_hat(t+h) = c + x_hat(t+h-1)*Bh, X: 1*k; Bh: k*nvar; y_hat: 1*nvar +% where Bh: the (posterior) estimate of B; +% phi: the 1-by-(nvar*lags+1) data matrix where k=nvar*lags+1 +% (last period plus lags before the beginning of forecast); +% nn: [nvar,lags,forep], forep: forecast periods; +% yhat: forep*nvar. + +% ** setup +nvar = nn(1); +lags = nn(2); +forep = nn(3); +tcwc = nvar*lags; % total coefficients without constant + +% ** reconstruct x(t) for y(t+h) = x(t+h-1)*B +% ** where phi = x(t+h-1) with last column being constant +yhat = zeros(forep,nvar); +for k=1:forep + yhat(k,:) = phi*Bh; + phi(1,nvar+1:tcwc) = phi(1,1:tcwc-nvar); + phi(1,1:nvar) = yhat(k,:); +end diff --git a/MatlabFiles/Forecasterr.m b/MatlabFiles/Forecasterr.m new file mode 100755 index 0000000..dca4c3d --- /dev/null +++ b/MatlabFiles/Forecasterr.m @@ -0,0 +1,28 @@ +function yhat = forecasterr(A0hin,Bh,phi,nn) +% forecast: unconditional forecating: yhat = forecast(Bh,phi,nn) +% y_hat(t+h) = x_hat(t+h-1)*Bh, X: 1*k; Bh: k*nvar; y_hat: 1*nvar +% where A0hin: inv(A0h) where columns correspond to equations +% Bh: the (posterior) estimate of B; +% phi: the 1-by-(nvar*lags+1) data matrix where k=nvar*lags+1 +% (last period plus lags before the beginning of forecast); +% nn: [nvar,lags,forep], forep: forecast periods; +% yhat: forep*nvar. +% +% See fsim.m when A0h (rather than A0hin) is used. + +% ** setup +nvar = nn(1); +lags = nn(2); +forep = nn(3); +tcwc = nvar*lags; % total coefficients without constant + +% ** reconstruct x(t) for y(t+h) = x(t+h-1)*B +% ** where phi = x(t+h-1) with last column being constant +Estr = randn(forep,nvar); +Ures = Estr*A0hin; +yhat = zeros(forep,nvar); +for k=1:forep + yhat(k,:) = phi*Bh + Ures(k,:); + phi(1,nvar+1:tcwc) = phi(1,1:tcwc-nvar); + phi(1,1:nvar) = yhat(k,:); +end diff --git a/MatlabFiles/GENSYSCT.M b/MatlabFiles/GENSYSCT.M new file mode 100755 index 0000000..52c28ba --- /dev/null +++ b/MatlabFiles/GENSYSCT.M @@ -0,0 +1,180 @@ +function [G1,C,impact,q,a,b,z,eu]=gensysct(g0,g1,c,psi,pi,div) +%function [G1,C,impact,q,a,b,z,eu]=gensysct(g0,g1,c,psi,pi,div) +%System given as +% g0*Dy(t)=g1*y(t)+c+psi*epsilon(t)+pi*eta(t), +%with epsilon an exogenous variable process and eta being endogenously determined +%white noise expectational errors. Returned system is +% Dy(t)=G1*y(t)+C+impact*epsilon(t). +% epsilon(t) is assumed to be white noise. +% If div is omitted from argument list, a div>0 is calculated. +% Also returned is the qz decomposition, q'az'=g0, q'bz'=g1, with a and b +% upper triangular and the system ordered so that all zeros on the diagonal of b are in +% the lower right corner, all cases where the real part of bii/aii is greater than or +% equal to div appear in the next block above the zeros, and the remaining bii/aii's +% all have bii/aii<div . These elements can be used to construct the full backward and +% forward solution. See the paper "Solving Linear Rational Expectations Models", +% http://eco-072399b.princeton.edu/yftp/gensys . Note that if one simply wants the backward +% and forward projection of y on epsilon, ignoring existence and uniqueness questions, the +% projection can be computed by Fourier methods. +% eu(1)=(existence); eu(2)=(uniqueness). Else eu=[-2,2] => indeterminacy via singularity +% in the equation system. Else eu(1)=-1 => existence only for white noise epsilon. +% realsmall=sqrt(eps)*10; +realsmall=sqrt(eps)*10; +%realsmall=1e-3; +eu=[0;0]; +fixdiv=(nargin==6) +n=size(g0,1); +[a b q z v]=qz(g0,g1); +if ~fixdiv, div=.001; end +nunstab=0; +nzero=0; +zxz=0; +for i=1:n + %------------------div calc------------ + if ~fixdiv + if abs(a(i,i)) > realsmall + divhat=real(b(i,i)/a(i,i)); + if realsmall<divhat & divhat<div + div=.5*divhat; + end + end + end + %---------------------------------------- + if abs(a(i,i))<realsmall + nzero=nzero+1; + nunstab=nunstab+1; + if abs(b(i,i))<realsmall + zxz=1; + end + else + nunstab=nunstab+ (real(b(i,i)/a(i,i))>div); + end +end +div +nunstab +nzero +% Note that qzdivct first puts all singularities in a in lower right, then puts unstable +% roots on top of those. +[a b q z]=qzdivct(div,a,b,q,z); +gev=[diag(a) diag(b)]; +if zxz + %disp('Coincident zeros. Indeterminacy and/or nonexistence.') + eu=[-2;-2]; + return +end +q1=q(1:n-nunstab,:); +q2=q(n-nunstab+1:n,:); +z1=z(:,1:n-nunstab)'; +z2=z(:,n-nunstab+1:n)'; +a2=a(n-nunstab+1:n,n-nunstab+1:n); +b2=b(n-nunstab+1:n,n-nunstab+1:n); +etawt=q2*pi; +zwt=q2*psi; +[ueta,deta,veta]=svd(etawt); +md=min(size(deta)); +bigev=find(diag(deta(1:md,1:md))>realsmall); +ueta=ueta(:,bigev); +veta=veta(:,bigev); +deta=deta(bigev,bigev); +[uz,dz,vz]=svd(zwt); +md=min(size(dz)); +bigev=find(diag(dz(1:md,1:md))>realsmall); +uz=uz(:,bigev); +vz=vz(:,bigev); +dz=dz(bigev,bigev); +if isempty(bigev) + exist=1; +else + exist=norm(uz-ueta*ueta'*uz,'fro') < realsmall*n; +end +if ~isempty(bigev) + zwtx0=b2\zwt; + zwtx=zwtx0; + M=b2\a2; + M=M/norm(M); + for i=2:nunstab + zwtx=[M*zwtx zwtx0]; + end + zwtx=b2*zwtx; + [ux,dx,vx]=svd(zwtx); + md=min(size(dx)); + bigev=find(diag(dx(1:md,1:md))>realsmall); + ux=ux(:,bigev); + vx=vx(:,bigev); + dx=dx(bigev,bigev); + existx=norm(ux-ueta*ueta'*ux,'fro') < realsmall*n; +else + existx=1; +end +%---------------------------------------------------- +% Note that existence and uniqueness are not just matters of comparing +% numbers of roots and numbers of endogenous errors. These counts are +% reported below because usually they point to the source of the problem. +%------------------------------------------------------ +[ueta1,deta1,veta1]=svd(q1*pi); +md=min(size(deta1)); +bigev=find(diag(deta1(1:md,1:md))>realsmall); +ueta1=ueta1(:,bigev); +veta1=veta1(:,bigev); +deta1=deta1(bigev,bigev); +if existx | nunstab==0 + %disp('solution exists'); + eu(1)=1; +else + if exist + %disp('solution exists for unforecastable z only'); + eu(1)=-1; + %else + %fprintf(1,'No solution. %d unstable roots. %d endog errors.\n',nunstab,size(ueta1,2)); + end + %disp('Generalized eigenvalues') + %disp(gev); + %md=abs(diag(a))>realsmall; + %ev=diag(md.*diag(a)+(1-md).*diag(b))\ev; + %disp(ev) +% return; +end +%disp('Generalized eigenvalues') +%disp(gev); +%md=abs(diag(a))>realsmall; +%ev=diag(md.*diag(a)+(1-md).*diag(b))\ev; +%disp(ev) +% return; +if isempty(veta1) + unique=1; +else + unique=norm(veta1-veta*veta'*veta1,'fro')<realsmall*n; +end +if unique + %disp('solution unique'); + eu(2)=1; +%else + %fprintf(1,'Indeterminacy. %d loose endog errors.\n',size(veta1,2)-size(veta,2)); + %disp('Generalized eigenvalues') + %disp(gev); + %disp(ev) +% return; +end +tmat = [eye(n-nunstab) -ueta1*deta1*veta1'*veta*(deta\ueta')]; +G0= [tmat*a; zeros(nunstab,n-nunstab) eye(nunstab)]; +G1= [tmat*b; zeros(nunstab,n)]; +%---------------------- +% G0 is always non-singular because by construction there are no zeros on +% the diagonal of a(1:n-nunstab,1:n-nunstab), which forms G0's ul corner. +%----------------------- +G0I=inv(G0); +G1=G0I*G1; +usix=n-nunstab+1:n; +C=G0I*[tmat*q*c;(a(usix,usix)-b(usix,usix))\q2*c]; +impact=G0I*[tmat*q*psi;zeros(nunstab,size(psi,2))]; +%-------------------- above are output for system in terms of z'y ------- +G1=z*G1*z'; +if max(max(abs(imag(G1))))>100*realsmall + disp('Inaccuracy in G1:') + s1=svd(G1); + s2=svd(real(G1)); + disp(max((s1-s2)./(1/12+s1))) % this is reasonable scaling for monthly time unit +end +G1=real(G1); +C=real(z*C); +impact=real(z*impact); diff --git a/MatlabFiles/GIBBSGLB.M b/MatlabFiles/GIBBSGLB.M new file mode 100755 index 0000000..7d22384 --- /dev/null +++ b/MatlabFiles/GIBBSGLB.M @@ -0,0 +1,57 @@ +function [cT,vR,kdf] = gibbsglb(Sbd,idmat0,nvar,fss) +% [cT,vR,kdf] = gibbsglb(Sbd,idmat0,nvar,fss) +% Global setup outside the Gibbs loop -- c.f. gibbsvar +% Ref.: D.F. Waggoner and T.A. Zha: "Does Normalization Matter for Inference?" +% See Note Forecast (2) pp. 44-51 +% +% Sbd: cell(nvar,1). Sbd=diag(S(1), ..., S(m)). Already divided by 'fss' for the +% posterior of a0 or A0(:) in Waggoner and Zha when one has asymmetric prior. +% Note,"bd" stands for block diagonal. +% idmat0: identification matrix for A0 with asymmetric prior; column -- equation. +% nvar: rank of A0 or # of variables +% fss: effective sample size (in the exponential term) -- +% # of observations + # of dummy observations +% (or nSample - lags + # of dummy observations) +%------------- +% cT{i}: nvar-by-nvar where T'*T=Sbd{i} which is kind of covariance martrix +% divided by fss already +% vR{i}: nvar-by-q{i} -- orthonormral basis for T*R, which is obtained through +% single value decomposition of Q*inv(T) +% kdf: the polynomial power in the Gamma or 1d Wishart distribution, used in +% "gibbsvar.m" +% +% Written by Tao Zha; Copyright (c) 1999 by Waggoner and Zha + + +kdf = fss; %2; %fss; + +cT = cell(nvar,1); +for k=1:nvar + cT{k} = chol(Sbd{k}); % upper triangular but lower triangular Choleski +end + +Q = cell(nvar,1); + % Q{i}: nvar-by-nvar with rank nvar-q(i) with ith equation a and + % q(i) which is # of non-zero elements in a. Note: Q*a=0. + +vR = cell(nvar,1); +for k=1:nvar + Q{k} = diag(idmat0(:,k)==0); % constructing Q{k} + % + [jnk1,d1,v1] = svd(Q{k}/cT{k}); + d1max=max(diag(d1)); + if d1max==0 + Idxk=1:nvar; + else + Idxk = find(diag(d1)<eps*d1max); + end + lenk = length(find(idmat0(:,k))); + if ( length(Idxk)<lenk ) + warning('Dimension of non-zero A0(:,k) is different from svd(Q*inv(T))') + disp('Press ctrl-c to abort') + pause + else + jnk1 = v1(:,Idxk); + vR{k} = jnk1(:,1:lenk); % orthonormal basis for T*R + end +end diff --git a/MatlabFiles/GIBBSVAR.M b/MatlabFiles/GIBBSVAR.M new file mode 100755 index 0000000..10aa8c3 --- /dev/null +++ b/MatlabFiles/GIBBSVAR.M @@ -0,0 +1,77 @@ +function A0gbs = gibbsvar(A0gbs,cT,vR,nvar,fss,kdf,Indxcol) +% A0gbs = gibbsvar(A0gbs,cT,vR,nvar,fss,kdf) +% One-step Gibbs sampler for structural VARs -- simultaneous equations approach +% Ref.: D.F. Waggoner and T. Zha: "Does Normalization Matter for Inference?" +% See Note Forecast (2) pp. 44-51 +% +% A0gbs: the last draw of A0 matrix +% cT{i}: nvar-by-nvar where T'*T=Sbd{i} which is kind of covariance martrix +% divided by fss already +% vR{i}: nvar-by-q{i} -- orthonormral basis for T*R, which is obtained through +% single value decomposition of Q*inv(T). See gibbsglb.m +% nvar: rank of A0 or # of variables +% fss: effective sample size == nSample (T)-lags+# of dummy observations +% kdf: polynomial power in the Gamma or 1d Wishart distribution +% Indxcol: a vector of random columns this Gibbs draws. +% When this input is not supplied, the Gibbs draws all columns +%------------------ +% A0bgs: new draw of A0 matrix in this Gibbs step +% +% Written by Tao Zha; Copyright (c) 1999 by Waggoner and Zha +% NOTE: Added Indxcol on 2/13/00 so that previous programs may not be compatible. + +if (nargin==6), Indxcol=[1:nvar]; end + +%---------------- Local loop for Gibbs given last A0gbs ---------- +%* uR{i}: nvar-by-q{i} -- orthonormal with first q(i)-1 vectors lies in the +% span(T*a(j)|j~=i) +%*** Constructing u(1),...,u(q{i}) at each Gibbs step +% +sw0 = zeros(nvar,1); +for k=Indxcol % given last A0gbs and general new A0bgs + X = cT{k}*A0gbs; % given the latest updated A0gbs + X(:,k) = 0; % want to find non-zero sw s.t., X'*sw=0 + [jL,Ux] = lu(X'); + jIx0 = min(find(abs(diag(Ux))<eps)); % if isempty(jIx0), then something is wrong here + % + sw0(jIx0+1:end) = 0; + sw0(jIx0) = 1; + jA = Ux(1:jIx0-1,1:jIx0-1); + jb = Ux(1:jIx0-1,jIx0); + jy = -jA\jb; + sw0(1:jIx0-1) = jy; + sw = sw0/sqrt(sum(sw0.^2)); + % + lenk = length(vR{k}(1,:)); + gkb = zeros(lenk,1); % greek beta's + uR = zeros(nvar,lenk); + sx = zeros(nvar,lenk); + sx(:,1) = vR{k}(:,1); + for ki = 1:lenk-1 + wxv = [sw'*sx(:,ki);sw'*vR{k}(:,ki+1)]; % w'*x and w'*v(+1) + dwxv = sqrt(sum(wxv.^2)); + if (dwxv<eps) + uR(:,ki)=sx(:,ki); sx(:,ki+1)=vR{k}(:,ki+1); + else + wxv = wxv/dwxv; + uR(:,ki) = wxv(1)*vR{k}(:,ki+1) - wxv(2)*sx(:,ki); + sx(:,ki+1) = wxv(2)*vR{k}(:,ki+1) + wxv(1)*sx(:,ki); + end + end + uR(:,lenk) = sx(:,lenk); % uR now constructed + % + %--------- Gibbs loop ---------- + %*** draw independently beta's that combine uR to form a's (columns of A0) + jcon = sqrt(1/fss); + gkb(1:lenk-1) = jcon*randn(lenk-1,1); + %* gamma or 1-d Wishart draw + jnk = jcon*randn(kdf+1,1); + if rand(1)<0.5 + gkb(lenk) = sqrt(jnk'*jnk); + else + gkb(lenk) = -sqrt(jnk'*jnk); + end + % + %*** form new a(i) - ith column of A0 + A0gbs(:,k) = (cT{k}\uR)*gkb; +end diff --git a/MatlabFiles/GRADCD.M b/MatlabFiles/GRADCD.M new file mode 100755 index 0000000..7dbffd5 --- /dev/null +++ b/MatlabFiles/GRADCD.M @@ -0,0 +1,66 @@ +function grdd = gradcd(fcn,x0,grdh,P1,P2,P3,P4,P5,P6,P7,P8,P9,... + P10,P11,P12,P13,P14,P15,P16,P17,P18,P19,P20) +%function grdd = gradcd(fcn,x0,grdh,P1,P2,P3,P4,P5,P6,P7,P8,P9,... +% P10,P11,P12,P13,P14,P15,P16,P17,P18,P19,P20) +% computes numerical gradient of a single-valued function or Jacobian +% matrix of a vector-valued function using a central difference with +% function grdd = gradcd(fcn,x0,grdh) +% +% fcn: a string naming a vector-valued function (f:n*1 -> k*1). +% x0: a column vector n*1, at which point the hessian is evaluated. +% grdh: step size, n*1. Set as follows +% step = eps^(1/3); +% %step = 1e-04; +% grdh = step * (max([abs(x) ones(length(x),1)]'))' .* (abs(x) ./ x); +% grdd: Jacobian matrix, k*n. + +stps = eps^(1/3); +% eps: floating point relative accuracy or machine precision: 2.22e-16 +% stps: step size recommended by Dennis and Schnabel: 6.006e-6 + +x0 = x0(:); +tailstr = ')'; +for i=nargin-3:-1:1 + tailstr=[ ',P' num2str(i) tailstr]; +end +f0 = eval([fcn '(x0' tailstr]); + +% ** initializations +n = length(x0); +k = length(f0); % dimension of "fcn" + +% ** Computation of stepsize (dh) +if all(grdh) + dh = grdh; +else + ax0 = abs(x0); + if all(x0) + dax0 = x0 ./ ax0; + else + dax0 = 1; + end + dh = stps * (max([ax0 ones(n,1)]'))' .* dax0; +end + +xdh = x0 + dh; +dh = xdh - x0; % This increases precision slightly +% +argplus = x0(:,ones(n,1)); +argminus = argplus; +dnum = 1:n+1:n^2; % positions of diagonals in vec(argplus). +argplus(dnum) = xdh; % replace the diagonals of "argplus" by "xdh". +argminus(dnum) = x0-dh; % replace the diagonals of "argplus" by "xdh". + +grdd = zeros(k,n); % preallocate to speed the loop. +i = 0; +while i ~= n + i = i+1; + fp = eval([fcn '(argplus(:,i)' tailstr]); + fm = eval([fcn '(argminus(:,i)' tailstr]); + grdd(:,i) = fp - fm; +end +dhm = dh(:,ones(k,1)); +dhm = dhm'; % k*n +grdd = grdd ./ (2*dhm); + + diff --git a/MatlabFiles/Gibbsvar.bak b/MatlabFiles/Gibbsvar.bak new file mode 100755 index 0000000..fb5e8c6 --- /dev/null +++ b/MatlabFiles/Gibbsvar.bak @@ -0,0 +1,74 @@ +function A0gbs = gibbsvar(A0gbs,cT,vR,nvar,fss,kdf) +% A0gbs = gibbsvar(A0gbs,cT,vR,nvar,fss,kdf) +% One-step Gibbs sampler for structural VARs -- simultaneous equations approach +% Ref.: D.F. Waggoner and T.A. Zha: "Does Normalization Matter for Inference?" +% See Note Forecast (2) pp. 44-51 +% +% A0gbs: the last draw of A0 matrix +% cT{i}: nvar-by-nvar where T'*T=Sbd{i} which is kind of covariance martrix +% divided by fss already +% vR{i}: nvar-by-q{i} -- orthonormral basis for T*R, which is obtained through +% single value decomposition of Q*inv(T). See gibbsglb.m +% nvar: rank of A0 or # of variables +% fss: effective sample size == nSample (T)-lags+# of dummy observations +% kdf: polynomial power in the Gamma or 1d Wishart distribution +%------------------ +% A0bgs: new draw of A0 matrix in this Gibbs step +% +% Written by Tao Zha; Copyright (c) 1999 by Waggoner and Zha + + +%---------------- Local loop for Gibbs given last A0gbs ---------- +%* uR{i}: nvar-by-q{i} -- orthonormal with first q(i)-1 vectors lies in the +% span(T*a(j)|j~=i) +%*** Constructing u(1),...,u(q{i}) at each Gibbs step +% +uR = cell(nvar,1); +sw0 = zeros(nvar,1); +for k=1:nvar % given last A0gbs and general new A0bgs + X = cT{k}*A0gbs; % given the latest updated A0gbs + X(:,k) = 0; % want to find non-zero sw s.t., X'*sw=0 + [jL,Ux,Px] = lu(X'); + jIx0 = min(find(abs(diag(Ux))<eps)); % if isempty(jIx0), then something is wrong here + % + sw0(jIx0+1:end) = 0; + sw0(jIx0) = 1; + jA = Ux(1:jIx0-1,1:jIx0-1); + jb = Ux(1:jIx0-1,jIx0); + jy = -jA\jb; + sw0(1:jIx0-1) = jy; + sw = sw0/sqrt(sum(sw0.^2)); + % + lenk = length(vR{k}(1,:)); + gkb = zeros(lenk,1); % greek beta's + uR{k} = zeros(nvar,lenk); + sx = zeros(nvar,lenk); + sx(:,1) = vR{k}(:,1); + for ki = 1:lenk-1 + wxv = [sw'*sx(:,ki);sw'*vR{k}(:,ki+1)]; % w'*x and w'*v(+1) + dwxv = sqrt(sum(wxv.^2)); + if (dwxv<eps) + uR{k}(:,ki)=sx(:,ki); sx(:,ki+1)=vR{k}(:,ki+1); + else + wxv = wxv/dwxv; + uR{k}(:,ki) = wxv(1)*vR{k}(:,ki+1) - wxv(2)*sx(:,ki); + sx(:,ki+1) = wxv(2)*vR{k}(:,ki+1) + wxv(1)*sx(:,ki); + end + end + uR{k}(:,lenk) = sx(:,lenk); % uR now constructed + % + %--------- Gibbs loop ---------- + %*** draw independently beta's that combine uR to form a's (columns of A0) + jcon = sqrt(1/fss); + gkb(1:lenk-1) = jcon*randn(lenk-1,1); + %* gamma or 1-d Wishart draw + jnk = jcon*randn(kdf+1,1); + if rand(1)<0.5 + gkb(lenk) = sqrt(jnk'*jnk); + else + gkb(lenk) = -sqrt(jnk'*jnk); + end + % + %*** form new a(i) - ith column of A0 + A0gbs(:,k) = (cT{k}\uR{k})*gkb; +end diff --git a/MatlabFiles/HESSCD.M b/MatlabFiles/HESSCD.M new file mode 100755 index 0000000..45c59df --- /dev/null +++ b/MatlabFiles/HESSCD.M @@ -0,0 +1,63 @@ +function grdd = hesscd(fcn,x0,grdh,P1,P2,P3,P4,P5,P6,P7,P8,P9,... + P10,P11,P12,P13,P14,P15,P16,P17,P18,P19,P20) +% computing numerical hessian using a central difference with +% function grdd = hesscd(fcn,x0,grdh,Passed variables1) +% +% fcn: a string naming the objective function. +% x0: a column vector n*1, at which point the hessian is evaluated. +% grdh: step size. +% grdd: hessian matrix (second derivative), n*n. + +stps = eps^(1/3); +% eps: floating point relative accuracy or machine precision: 2.22e-16 +% stps: step size recommended by Dennis and Schnabel: 6.006e-6 + +x0 = x0(:); +tailstr = ')'; +for i=nargin-3:-1:1 + tailstr=[ ',P' num2str(i) tailstr]; +end +f0 = eval([fcn '(x0' tailstr]); + +% ** initializations +k = length(x0); +grdd = zeros(k); + +% ** Computation of stepsize (dh) +if all(grdh) + dh = grdh; +else + ax0 = abs(x0); + if all(x0) + dax0 = x0 ./ ax0; + else + dax0 = 1; + end + dh = stps * (max([ax0 (1e-2)*ones(k,1)]'))' .* dax0; +end + +xdh = x0 + dh; +dh = xdh - x0; % This increases precision slightly +dhm = dh(:,ones(k,1)); +ee = eye(k) .* dhm; + +i = 1; +while i <= k + j = i; + while j <= k + + fune1 = eval([fcn '(x0 + ee(:,i) + ee(:,j)' tailstr]); + fune2 = eval([fcn '(x0 - ee(:,i) + ee(:,j)' tailstr]); + fune3 = eval([fcn '(x0 + ee(:,i) - ee(:,j)' tailstr]); + fune4 = eval([fcn '(x0 - ee(:,i) - ee(:,j)' tailstr]); + grdd(i,j) = (fune1 - fune2 - fune3 + fune4) / (4 * dh(i) * dh(j)); + + if i ~= j + grdd(j,i) = grdd(i,j); + end + + j = j+1; + end + i = i+1; +end + diff --git a/MatlabFiles/HESSCD.M1 b/MatlabFiles/HESSCD.M1 new file mode 100755 index 0000000..017db98 --- /dev/null +++ b/MatlabFiles/HESSCD.M1 @@ -0,0 +1,55 @@ +function grdd = hesscd(fcn,x0,grdh) +% computing numerical hessian using a central difference with +% function grdd = hesscd(fcn,x0,grdh) +% +% fcn: a string naming the objective function. +% x0: a column vector n*1, at which point the hessian is evaluated. +% grdh: step size. +% grdd: hessian matrix (second derivative), n*n. + +stps = eps^(1/3); +% eps: floating point relative accuracy or machine precision: 2.22e-16 +% stps: step size recommended by Dennis and Schnabel: 6.006e-6 + +% ** initializations +k = size(x0,1); +grdd = zeros(k); + +% ** Computation of stepsize (dh) +if all(grdh) + dh = grdh; +else + ax0 = abs(x0); + if all(x0) + dax0 = x0 ./ ax0; + else + dax0 = 1; + end + dh = stps * (max([ax0 (1e-2)*ones(k,1)]'))' .* dax0; +end + +xdh = x0 + dh; +dh = xdh - x0; % This increases precision slightly +dhm = dh(:,ones(k,1)); +ee = eye(k) .* dhm; + +i = 1; +while i <= k + j = i; + while j <= k + + grdd(i,j) = (feval(fcn,x0 + ee(:,i) + ee(:,j)) - ... + feval(fcn,x0 - ee(:,i) + ee(:,j)) - ... + feval(fcn,x0 + ee(:,i) - ee(:,j)) + ... + feval(fcn,x0 - ee(:,i) - ee(:,j))) ... + / (4 * dh(i) * dh(j)); + + if i ~= j + grdd(j,i) = grdd(i,j); + end + + j = j+1; + end + i = i+1; +end + diff --git a/MatlabFiles/HISTORY.M b/MatlabFiles/HISTORY.M new file mode 100755 index 0000000..43c002e --- /dev/null +++ b/MatlabFiles/HISTORY.M @@ -0,0 +1,108 @@ +function [hd,ehat] = history(uhat,Bh,A0,nn) +% Computing historical decompositions with +% [hd,ehat] = history(uhat,Bh,A0,nn) +% where hd: historical decompositions, dstp-by-nvar^2 matrix. +% Column: 1st variable decompositions attributed to nvar +% (cumulative) shocks, 2nd variable decompositions +% attributed to nvar (cumulative) shocks, and so on. +% Row: steps of decompositions "dstp". +% ehat: structural one-step forecast errors +% of each variable, dstp-by-nvar. +% uhat: dstp-by-nvar reduced form one-step forecast errors +% begining with the decomposition period. +% Bh: the estimated reduced form coefficient in the form +% Y(T*nvar) = XB + U, X: T*k, B: k*nvar. The matrix +% form or dimension is the same as "Bh" from the function "sye". +% A0: comtemporaneous A in the structural model A(L)y(t) = e(t). +% nn: # of inputs -- [nvar,lags,dstp (steps of decompositions)]. +% ===== Note: this function can be easily modified to get variance +% ===== decompositions and impulse responses. + +nvar = nn(1); +lags = nn(2); +dstp = nn(3); % number of steps for decompositions +imstep = dstp; % steps of impulse responses +tcwc = nvar*lags; % total coefficients without constant +swish = inv(A0); + + +Ah = Bh'; +% Row: nvar equations +% Column: 1st lag (with nvar variables) to +% lags (with nvar variables) + const = k. +ehat = uhat*A0'; +% dstp-by-nvar matrix: structural one-step forecast errors. + +hd = zeros(dstp,nvar*nvar); +% Column: 1st varaible to nvar shocks, 2nd variables to nvar shock, and so on. +% Row: steps of decompositions. +imf = zeros(dstp,nvar*nvar); % impulse responses +% different format from "hd", i.e., nvar variables to 1st shock, +% nvar variables to 2nd shock, etc. To make the format the same +% as "hd", just change Mtem to Mtem' right before stacking "imf". +% See also "impulseo.m" in \toolbox\cstz +M = zeros(nvar*(lags+1),nvar); % stacked matrices for impulse responses +% Stack M0;M1;M2;...;Mlags +MH = zeros(nvar*dstp,nvar); +% same as M, but stacked in a different fashion after t > lags so that +% all the cumulations are recorded for historical decompositions. +M(1:nvar,:) = swish; +Mtem = M(1:nvar,:); % temporary M -- impulse responses. +% +Hdc = M(1:nvar,:)*diag(ehat(1,:)); +% first period historical decompositions. +% * put in the form of "hd", as well as "imf" +Hdc = Hdc'; +hd(1,:) = Hdc(:)'; +imf(1,:) = Mtem(:)'; + + +% +% ** beginning with the second period. Note, 1st period is t=0 +% +t = 1; +ims1 = min([dstp-1 lags]); +while t <= ims1 + % ** impulse response functions + Mtem = zeros(nvar,nvar); + for k = 1:t + Mtem = Ah(:,nvar*(k-1)+1:nvar*k)*M(nvar*(t-k)+1:nvar*(t-k+1),:) + Mtem; + % Row: nvar equations, each for the nvar variables at tth lag + end + M(nvar*t+1:nvar*(t+1),:) = Mtem; + imf(t+1,:) = Mtem(:)'; + % stack imf with each step, Row: 6 var to 1st shock, 6 var to 2nd shock, etc. + % ** historical decompositions + Hdc = M(1:nvar,:)*diag(ehat(t+1,:)); + for k = 1:t + Hdc = Hdc + M(nvar*k+1:nvar*(k+1),:)*diag(ehat(t+1-k,:)); + % Row: nvar variables; Column: nvar shocks + end + Hdc = Hdc'; + hd(t+1,:) = Hdc(:)'; + t= t+1; +end + +MH(1:nvar*(lags+1),:) = M; +for t = lags+1:imstep-1 + % ** impulse response functions + M(1:nvar*lags,:) = M(nvar+1:nvar*(lags+1),:); + Mtem = zeros(nvar,nvar); + for k = 1:lags + Mtem = Ah(:,nvar*(k-1)+1:nvar*k)*M(nvar*(lags-k)+1:nvar*(lags-k+1),:) + Mtem; + % Row: nvar equations, each for the nvar variables at tth lag + end + M(nvar*lags+1:nvar*(lags+1),:) = Mtem; + imf(t+1,:) = Mtem(:)'; + % stack imf with each step, Row: 6 var to 1st shock, 6 var to 2nd shock, etc. + % ** historical decompositions + MH(nvar*t+1:nvar*(t+1),:) = Mtem; + Hdc = MH(1:nvar,:)*diag(ehat(t+1,:)); + for k = 1:t + Hdc = Hdc + MH(nvar*k+1:nvar*(k+1),:)*diag(ehat(t+1-k,:)); + % Row: nvar variables; Column: nvar shocks + end + Hdc = Hdc'; + hd(t+1,:) = Hdc(:)'; +end + \ No newline at end of file diff --git a/MatlabFiles/IMPULSE.OLD b/MatlabFiles/IMPULSE.OLD new file mode 100755 index 0000000..bc8490a --- /dev/null +++ b/MatlabFiles/IMPULSE.OLD @@ -0,0 +1,58 @@ +function imf = impulse(Bh,swish,nn) +% Computing impulse functions with +% imf = impulse(Bh,swish,nn) +% where imf is in a format that is the SAME as in RATS. +% Column: nvar responses to 1st shock, +% nvar responses to 2nd shock, and so on. +% Row: steps of impulse responses. +% Bh is the estimated reduced form coefficient in the form +% Y(T*nvar) = XB + U, X: T*k, B: k*nvar. The matrix +% form or dimension is the same as "Bh" from the function "sye"; +% swish is the inv(A0) in the structural model A(L)y(t) = e(t). +% nn is the numbers of inputs [nvar,lags,# of impulse responses]. + +nvar = nn(1); +lags = nn(2); +imstep = nn(3); % number of steps for impulse responses + +Ah = Bh'; +% Row: nvar equations +% Column: 1st lag (with nvar variables) to lags (with nvar variables) + const = k. + +imf = zeros(imstep,nvar*nvar); +% Column: nvar responses to 1st shock, nvar responses to 2nd shock, and so on. +% Row: steps of impulse responses. +M = zeros(nvar*(lags+1),nvar); +% Stack M0;M1;M2;...;Mlags +M(1:nvar,:) = swish; +Mtem = M(1:nvar,:); % temporary M. +% first (initial) responses to 1 standard deviation shock. Row: responses; Column: shocks +% * put in the form of "imf" +imf(1,:) = Mtem(:)'; + +t = 1; +ims1 = min([imstep-1 lags]); +while t <= ims1 + Mtem = zeros(nvar,nvar); + for k = 1:t + Mtem = Ah(:,nvar*(k-1)+1:nvar*k)*M(nvar*(t-k)+1:nvar*(t-k+1),:) + Mtem; + % Row: nvar equations, each for the nvar variables at tth lag + end + M(nvar*t+1:nvar*(t+1),:) = Mtem; + imf(t+1,:) = Mtem(:)'; + % stack imf with each step, Row: 6 var to 1st shock, 6 var to 2nd shock, etc. + t= t+1; +end + +for t = lags+1:imstep-1 + M(1:nvar*lags,:) = M(nvar+1:nvar*(lags+1),:); + Mtem = zeros(nvar,nvar); + for k = 1:lags + Mtem = Ah(:,nvar*(k-1)+1:nvar*k)*M(nvar*(lags-k)+1:nvar*(lags-k+1),:) + Mtem; + % Row: nvar equations, each for the nvar variables at tth lag + end + M(nvar*lags+1:nvar*(lags+1),:) = Mtem; + imf(t+1,:) = Mtem(:)'; + % stack imf with each step, Row: 6 var to 1st shock, 6 var to 2nd shock, etc. +end + \ No newline at end of file diff --git a/MatlabFiles/IMPULSE.m1 b/MatlabFiles/IMPULSE.m1 new file mode 100755 index 0000000..bc8490a --- /dev/null +++ b/MatlabFiles/IMPULSE.m1 @@ -0,0 +1,58 @@ +function imf = impulse(Bh,swish,nn) +% Computing impulse functions with +% imf = impulse(Bh,swish,nn) +% where imf is in a format that is the SAME as in RATS. +% Column: nvar responses to 1st shock, +% nvar responses to 2nd shock, and so on. +% Row: steps of impulse responses. +% Bh is the estimated reduced form coefficient in the form +% Y(T*nvar) = XB + U, X: T*k, B: k*nvar. The matrix +% form or dimension is the same as "Bh" from the function "sye"; +% swish is the inv(A0) in the structural model A(L)y(t) = e(t). +% nn is the numbers of inputs [nvar,lags,# of impulse responses]. + +nvar = nn(1); +lags = nn(2); +imstep = nn(3); % number of steps for impulse responses + +Ah = Bh'; +% Row: nvar equations +% Column: 1st lag (with nvar variables) to lags (with nvar variables) + const = k. + +imf = zeros(imstep,nvar*nvar); +% Column: nvar responses to 1st shock, nvar responses to 2nd shock, and so on. +% Row: steps of impulse responses. +M = zeros(nvar*(lags+1),nvar); +% Stack M0;M1;M2;...;Mlags +M(1:nvar,:) = swish; +Mtem = M(1:nvar,:); % temporary M. +% first (initial) responses to 1 standard deviation shock. Row: responses; Column: shocks +% * put in the form of "imf" +imf(1,:) = Mtem(:)'; + +t = 1; +ims1 = min([imstep-1 lags]); +while t <= ims1 + Mtem = zeros(nvar,nvar); + for k = 1:t + Mtem = Ah(:,nvar*(k-1)+1:nvar*k)*M(nvar*(t-k)+1:nvar*(t-k+1),:) + Mtem; + % Row: nvar equations, each for the nvar variables at tth lag + end + M(nvar*t+1:nvar*(t+1),:) = Mtem; + imf(t+1,:) = Mtem(:)'; + % stack imf with each step, Row: 6 var to 1st shock, 6 var to 2nd shock, etc. + t= t+1; +end + +for t = lags+1:imstep-1 + M(1:nvar*lags,:) = M(nvar+1:nvar*(lags+1),:); + Mtem = zeros(nvar,nvar); + for k = 1:lags + Mtem = Ah(:,nvar*(k-1)+1:nvar*k)*M(nvar*(lags-k)+1:nvar*(lags-k+1),:) + Mtem; + % Row: nvar equations, each for the nvar variables at tth lag + end + M(nvar*lags+1:nvar*(lags+1),:) = Mtem; + imf(t+1,:) = Mtem(:)'; + % stack imf with each step, Row: 6 var to 1st shock, 6 var to 2nd shock, etc. +end + \ No newline at end of file diff --git a/MatlabFiles/IMPULSEO.M b/MatlabFiles/IMPULSEO.M new file mode 100755 index 0000000..ae162ce --- /dev/null +++ b/MatlabFiles/IMPULSEO.M @@ -0,0 +1,61 @@ +function imf = impulseo(Bh,swish,nn) +% impulse: computing impulse functions with +% imf = impulseo(Bh,swish) +% where imf is in a format that is conveninet to generate the RATS graphics; +% Bh is the estimated reduced form coefficient in the form +% Y(T*nvar) = XB + U, X: T*k, B: k*nvar. The matrix +% form or dimension is the same as "Bh" from the function "sye"; +% swish is the inv(A0) in the structural model A(L)y(t) = e(t). +% nn is the numbers of inputs [nvar,lags,# of impulse responses]. + +nvar = nn(1); +lags = nn(2); +imstep = nn(3); % number of steps for impulse responses + +Ah = Bh'; +% Row: nvar equations +% Column: 1st lag (with nvar variables) to lags (with nvar variables) + const = k. + +imf = zeros(imstep,nvar*nvar); +% Column: 1st variable response to nvar shocks, 2nd variable response to +% nvar shocks, and so on. +% Row: steps of impulse responses. +M = zeros(nvar*(lags+1),nvar); +% Stack M0;M1;M2:...;Mlags +M(1:nvar,:) = swish; +Mtem = M(1:nvar,:); % temporary M. +% first (initial) responses to 1 standard deviation shock. Row: responses; Column: shocks +% * put in the form of "imf" +Mtem = Mtem'; +imf(1,:) = Mtem(:)'; + +t = 1; +ims1 = min([imstep-1 lags]); +while t <= ims1 + Mtem = zeros(nvar,nvar); + for k = 1:t + Mtem = Ah(:,nvar*(k-1)+1:nvar*k)*M(nvar*(t-k)+1:nvar*(t-k+1),:) + Mtem; + % Row: nvar equations, each for the nvar variables at tth lag + end + M(nvar*t+1:nvar*(t+1),:) = Mtem; + Mtem = Mtem'; + imf(t+1,:) = Mtem(:)'; + % stack imf with each step, Row: 1st variable to nvar shocks, + % 2nd variable to nvar shocks, etc. + t= t+1; +end + +for t = lags+1:imstep-1 + M(1:nvar*lags,:) = M(nvar+1:nvar*(lags+1),:); + Mtem = zeros(nvar,nvar); + for k = 1:lags + Mtem = Ah(:,nvar*(k-1)+1:nvar*k)*M(nvar*(lags-k)+1:nvar*(lags-k+1),:) + Mtem; + % Row: nvar equations, each for the nvar variables at tth lag + end + M(nvar*lags+1:nvar*(lags+1),:) = Mtem; + Mtem = Mtem'; + imf(t+1,:) = Mtem(:)'; + % stack imf with each step, Row: 1st variable to nvar shocks, + % 2nd variable to nvar shocks, etc. +end + \ No newline at end of file diff --git a/MatlabFiles/MFORMD.M b/MatlabFiles/MFORMD.M new file mode 100755 index 0000000..fa9b2eb --- /dev/null +++ b/MatlabFiles/MFORMD.M @@ -0,0 +1,33 @@ +function [phi,YtY] = mformd(z,nn) +% mformd: arrange matrix form data: [Y,YtY] = mformd(z,nn) as structural form +% YA = E, Y: T*(nvar*lags+nvar+1) +% +% where z is the (T+lags)-by-(nvar+1) raw data matrix (nvar of variables + constant); +% nn is the numbers of inputs [nvar,lags,sample period (total)]; +% phi: Y as in the structural form YA = E, Y: T*(nvar*lags+nvar+1) +% YtY: Y'Y: (nvar*lags+nvar+1)*(nvar*lags+nvar+1) + +% ** setup of orders and lengths ** +nvar = nn(1); +lags = nn(2); +sp = nn(3); % sample period + +ess = sp-lags; % effective sample size +sb = lags+1; % sample beginning +sl = sp; % sample last period +ncoe = nvar*lags + nvar + 1; % with constant and contemporaneous data + +% ** construct Y as in YA = E where phi = Y ** +x = z(:,1:nvar); +C = z(:,nvar+1); +phi = zeros(ess,ncoe); +phi(:,1:nvar) = x(sb:sl,:); +phi(:,ncoe) = C(1:ess); +for k=1:lags, phi(:,nvar*k+1:nvar*(k+1)) = x(sb-k:sl-k,:); end +% column: T; row: [nvar for 0th lag, nvar for 1st lag, +% ..., nvar for last lag, const] +% Thus, # of columns is nvar*lags+nvar+1 = ncoef. +% ** YtY, residuals ** +[u d v]=svd(phi,0); %trial +vd=v.*(ones(size(v,2),1)*diag(d)'); %trial +YtY=vd*vd'; % YtY = phi'*phi; % X'X, k*k (ncoe*ncoe) \ No newline at end of file diff --git a/MatlabFiles/MSV/MSV_Newton.m b/MatlabFiles/MSV/MSV_Newton.m new file mode 100755 index 0000000..dd8d0ea --- /dev/null +++ b/MatlabFiles/MSV/MSV_Newton.m @@ -0,0 +1,109 @@ +function [ F1 F2 G1 G2 V ] = MSV_Newton(P, A, B, Psi, s, x) +% +% Computes MSV solution of +% +% A(s(t) x(t) = B(s(t) x(t-1) + Psi(s(t)) epsilon(t) + Pi eta(t) +% +% using Newton's Method. Assumes that Pi' = [zeros(s,n-s) eye(s)] +% +% Assumes that A{i} is invertable for 1 <= i <= h + +max_count=1000; +tol=1e-5; + +h=size(P,1); +n=size(A{1},1); +r=size(Psi{1},2); + +if nargin <= 5 + x=zeros(h*s*(n-s),1); +end +f=zeros(h*s*(n-s),1); + +Is=eye(s); +I=eye(n-s); + +% The following code would be used if Pi were passed instead of the +% assumption that Pi' = [zeros(s,n-s) eye(s)]. +% for i=1:h +% [Q,R] = qr(Pi{i}); +% W=[zeros(n-s,s) I; inv(R(1:s,1:s)); zeros(s,n-s)]*Q'; +% A{i}=W*A{i}; +% B{i}=W*B{i}; +% Psi{i}=W*Psi{i}; +% end + +U=cell(h,1); +for i=1:h + U{i}=inv(A{i}); +end +C=cell(h,h); +for i=1:h + for j=1:h + C{i,j}=P(i,j)*B{j}*U{i}; + end +end + +cont=true; +count=1; +D=zeros(h*s*(n-s),h*s*(n-s)); +X=cell(h,1); +for i=1:h + X{i}=reshape(x((i-1)*s*(n-s)+1:i*s*(n-s)),s,n-s); +end +while cont + for i=1:h + for j=1:h + W1=C{i,j}*[I; -X{i}]; + W2=W1(1:n-s,:); + D((i-1)*s*(n-s)+1:i*s*(n-s),(j-1)*s*(n-s)+1:j*s*(n-s)) = kron(W2',Is); + if i == j + W1=zeros(s,n); + for k=1:h + W1=W1+[X{k} Is]*C{i,k}; + end + W2=-W1(:,n-s+1:end); + D((i-1)*s*(n-s)+1:i*s*(n-s),(j-1)*s*(n-s)+1:j*s*(n-s)) = D((i-1)*s*(n-s)+1:i*s*(n-s),(j-1)*s*(n-s)+1:j*s*(n-s)) + kron(I,W2); + end + end + end + + for i=1:h + mf=zeros(s,n-s); + for j=1:h + mf=mf+[X{j} Is]*C{i,j}*[I; -X{i}]; + end + f((i-1)*s*(n-s)+1:i*s*(n-s))=reshape(mf,s*(n-s),1); + end + + y=D\f; + x=x - y; + + if (count > max_count) || (norm(y) < tol) + cont=false; + end + + count=count+1; + for i=1:h + X{i}=reshape(x((i-1)*s*(n-s)+1:i*s*(n-s)),s,n-s); + end +end + +F1=cell(h,1); +F2=cell(h,1); +G1=cell(h,1); +G2=cell(h,1); +V=cell(h,1); +pi=[zeros(n-s,s); Is]; +for i=1:h + X=reshape(x((i-1)*s*(n-s)+1:i*s*(n-s)),s,n-s); + V{i}=U{i}*[I; -X]; + W=[A{i}*V{i} pi]; + F=W\B{i}; + F1{i}=F(1:n-s,:); + F2{i}=F(n-s+1:end,:); + G=W\Psi{i}; + G1{i}=G(1:n-s,:); + G2{i}=G(n-s+1:end,:); +end + \ No newline at end of file diff --git a/MatlabFiles/MSV/dw_gensys.m b/MatlabFiles/MSV/dw_gensys.m new file mode 100755 index 0000000..cd95932 --- /dev/null +++ b/MatlabFiles/MSV/dw_gensys.m @@ -0,0 +1,46 @@ +function [G1,impact,gev,eu]=dw_gensys(g0,g1,psi,pi,div) +% function [G1,impact,gev,eu]=gensys(g0,g1,c,psi,pi,div) +% System given as +% g0*y(t)=g1*y(t-1)+psi*e(t)+pi*eta(t), +% with e an exogenous variable process and eta being endogenously determined +% one-step-ahead expectational errors. Returned system is +% y(t)=G1*y(t-1)+impact*e(t). +% If div is omitted from argument list, a div>1 is calculated. +% eu(1)=1 for existence, eu(2)=1 for uniqueness. eu(1)=-1 for +% existence only with not-s.c. z; eu=[-2,-2] for coincident zeros. +% By Daniel Waggoner + +realsmall=1e-8; + +G1=[]; +impact=[]; +gev=[]; + +n=size(pi,1); + +if nargin == 4 + div=1.0; +end + +[a b q z]=qz(g0,g1); + +for i=1:n + if (abs(a(i,i)) < realsmall) & (abs(b(i,i)) < realsmall) + disp('Coincident zeros.') + eu=[-2;-2]; + gev=[diag(a) diag(b)]; + return + end +end + +[a b q z]=qzsort(a,b,q,z); + +suppress=0; +i=n; +while (i > 0) & (abs(b(i,i)) > abs(a(i,i)*div)) + suppress=suppress+1; + i=i-1; +end + +[G1,impact,eu]=qzcomputesolution(a,b,q,z,psi,pi,suppress); + diff --git a/MatlabFiles/MSV/gensys.m b/MatlabFiles/MSV/gensys.m new file mode 100755 index 0000000..705b2c1 --- /dev/null +++ b/MatlabFiles/MSV/gensys.m @@ -0,0 +1,177 @@ +function [G1,C,impact,fmat,fwt,ywt,gev,eu]=gensys(g0,g1,c,psi,pi,div) +% function [G1,C,impact,fmat,fwt,ywt,gev,eu]=gensys(g0,g1,c,psi,pi,div) +% System given as +% g0*y(t)=g1*y(t-1)+c+psi*z(t)+pi*eta(t), +% with z an exogenous variable process and eta being endogenously determined +% one-step-ahead expectational errors. Returned system is +% y(t)=G1*y(t-1)+C+impact*z(t)+ywt*inv(I-fmat*inv(L))*fwt*z(t+1) . +% If z(t) is i.i.d., the last term drops out. +% If div is omitted from argument list, a div>1 is calculated. +% eu(1)=1 for existence, eu(2)=1 for uniqueness. eu(1)=-1 for +% existence only with not-s.c. z; eu=[-2,-2] for coincident zeros. +% By Christopher A. Sims +% Corrected 10/28/96 by CAS + +eu=[0;0]; +realsmall=1e-7; +fixdiv=(nargin==6); +n=size(g0,1); +[a b q z v]=qz(g0,g1); +if ~fixdiv, div=1.01; end +nunstab=0; +zxz=0; +for i=1:n +% ------------------div calc------------ + if ~fixdiv + if abs(a(i,i)) > 0 + divhat=abs(b(i,i))/abs(a(i,i)); + % bug detected by Vasco Curdia and Daria Finocchiaro, 2/25/2004 A root of + % exactly 1.01 and no root between 1 and 1.02, led to div being stuck at 1.01 + % and the 1.01 root being misclassified as stable. Changing < to <= below fixes this. + if 1+realsmall<divhat & divhat<=div + div=.5*(1+divhat); + end + end + end +% ---------------------------------------- + nunstab=nunstab+(abs(b(i,i))>div*abs(a(i,i))); + if abs(a(i,i))<realsmall & abs(b(i,i))<realsmall + zxz=1; + end +end +div ; +nunstab; +if ~zxz + [a b q z]=qzdiv(div,a,b,q,z); +end +gev=[diag(a) diag(b)]; +if zxz + disp('Coincident zeros. Indeterminacy and/or nonexistence.') + eu=[-2;-2]; + % correction added 7/29/2003. Otherwise the failure to set output + % arguments leads to an error message and no output (including eu). + G1=[];C=[];impact=[];fmat=[];fwt=[];ywt=[];gev=[]; + return +end +q1=q(1:n-nunstab,:); +q2=q(n-nunstab+1:n,:); +z1=z(:,1:n-nunstab)'; +z2=z(:,n-nunstab+1:n)'; +a2=a(n-nunstab+1:n,n-nunstab+1:n); +b2=b(n-nunstab+1:n,n-nunstab+1:n); +etawt=q2*pi; +% zwt=q2*psi; +[ueta,deta,veta]=svd(etawt); +md=min(size(deta)); +bigev=find(diag(deta(1:md,1:md))>realsmall); +ueta=ueta(:,bigev); +veta=veta(:,bigev); +deta=deta(bigev,bigev); +% ------ corrected code, 3/10/04 +eu(1) = length(bigev)>=nunstab; +length(bigev); +nunstab; +% ------ Code below allowed "existence" in cases where the initial lagged state was free to take on values +% ------ inconsistent with existence, so long as the state could w.p.1 remain consistent with a stable solution +% ------ if its initial lagged value was consistent with a stable solution. This is a mistake, though perhaps there +% ------ are situations where we would like to know that this "existence for restricted initial state" situation holds. +%% [uz,dz,vz]=svd(zwt); +%% md=min(size(dz)); +%% bigev=find(diag(dz(1:md,1:md))>realsmall); +%% uz=uz(:,bigev); +%% vz=vz(:,bigev); +%% dz=dz(bigev,bigev); +%% if isempty(bigev) +%% exist=1; +%% else +%% exist=norm(uz-ueta*ueta'*uz) < realsmall*n; +%% end +%% if ~isempty(bigev) +%% zwtx0=b2\zwt; +%% zwtx=zwtx0; +%% M=b2\a2; +%% for i=2:nunstab +%% zwtx=[M*zwtx zwtx0]; +%% end +%% zwtx=b2*zwtx; +%% [ux,dx,vx]=svd(zwtx); +%% md=min(size(dx)); +%% bigev=find(diag(dx(1:md,1:md))>realsmall); +%% ux=ux(:,bigev); +%% vx=vx(:,bigev); +%% dx=dx(bigev,bigev); +%% existx=norm(ux-ueta*ueta'*ux) < realsmall*n; +%% else +%% existx=1; +%% end +% ---------------------------------------------------- +% Note that existence and uniqueness are not just matters of comparing +% numbers of roots and numbers of endogenous errors. These counts are +% reported below because usually they point to the source of the problem. +% ------------------------------------------------------ +[ueta1,deta1,veta1]=svd(q1*pi); +md=min(size(deta1)); +bigev=find(diag(deta1(1:md,1:md))>realsmall); +ueta1=ueta1(:,bigev); +veta1=veta1(:,bigev); +deta1=deta1(bigev,bigev); +%% if existx | nunstab==0 +%% %disp('solution exists'); +%% eu(1)=1; +%% else +%% if exist +%% %disp('solution exists for unforecastable z only'); +%% eu(1)=-1; +%% %else +%% %fprintf(1,'No solution. %d unstable roots. %d endog errors.\n',nunstab,size(ueta1,2)); +%% end +%% %disp('Generalized eigenvalues') +%% %disp(gev); +%% %md=abs(diag(a))>realsmall; +%% %ev=diag(md.*diag(a)+(1-md).*diag(b))\ev; +%% %disp(ev) +%% % return; +%% end +if isempty(veta1) + unique=1; +else + unique=norm(veta1-veta*veta'*veta1)<realsmall*n; +end + +veta1; +veta; +norm(veta1-veta*veta'*veta1); + +if unique + %disp('solution unique'); + eu(2)=1; +else + fprintf(1,'Indeterminacy. %d loose endog errors.\n',size(veta1,2)-size(veta,2)); + %disp('Generalized eigenvalues') + %disp(gev); + %md=abs(diag(a))>realsmall; + %ev=diag(md.*diag(a)+(1-md).*diag(b))\ev; + %disp(ev) +% return; +end +tmat = [eye(n-nunstab) -(ueta*(deta\veta')*veta1*deta1*ueta1')']; +G0= [tmat*a; zeros(nunstab,n-nunstab) eye(nunstab)]; +G1= [tmat*b; zeros(nunstab,n)]; +% ---------------------- +% G0 is always non-singular because by construction there are no zeros on +% the diagonal of a(1:n-nunstab,1:n-nunstab), which forms G0's ul corner. +% ----------------------- +G0I=inv(G0); +G1=G0I*G1; +usix=n-nunstab+1:n; +C=G0I*[tmat*q*c;(a(usix,usix)-b(usix,usix))\q2*c]; +impact=G0I*[tmat*q*psi;zeros(nunstab,size(psi,2))]; +fmat=b(usix,usix)\a(usix,usix); +fwt=-b(usix,usix)\q2*psi; +ywt=G0I(:,usix); +% -------------------- above are output for system in terms of z'y ------- +G1=real(z*G1*z'); +C=real(z*C); +impact=real(z*impact); +% Correction 10/28/96: formerly line below had real(z*ywt) on rhs, an error. +ywt=z*ywt; diff --git a/MatlabFiles/MSV/msv_all.m b/MatlabFiles/MSV/msv_all.m new file mode 100755 index 0000000..22affc9 --- /dev/null +++ b/MatlabFiles/MSV/msv_all.m @@ -0,0 +1,150 @@ +function [G1,impact,gev,eu]=msv_all(g0,g1,psi,pi) +% function [G1,C,impact,gev,eu]=msv_all(g0,g1,psi,pi) +% System given as +% g0*y(t)=g1*y(t-1)+psi*z(t)+pi*eta(t), +% with z an exogenous variable process and eta being endogenously determined +% one-step-ahead expectational errors. Returned system is +% y(t)=G1*y(t-1)+impact*z(t). +% eu(1)=1 for existence, eu(2)=1 for uniqueness. +% eu=[-2,-2] for coincident zeros. +% Attempts all possible ordering such that all explosive roots are +% suppressed and no complex conjugate pairs are split +% By Daniel Waggoner -- Based on code by Christopher A. Sims + +realsmall=1e-10; + +n=size(pi,1); +s=size(pi,2); +ii=1; + +[a b q z]=qz(g0,g1); +eu{ii}=[0;0]; +gev{ii}=[diag(a) diag(b)]; +G1{ii}=[] +impact{ii}=[] + +for i=1:n + if (abs(a(i,i)) < realsmall) & (abs(b(i,i)) < realsmall) + disp('Coincident zeros.') + eu{ii}=[-2;-2]; + gev{ii}=[diag(a) diag(b)]; + G1{ii}=[] + impact{ii}=[] + return + end +end + +[a b q z]=qzsort(a,b,q,z); + +% determine complex conjugate pairs +pairs=zeros(n,1); +i=1; +while i < n + if abs(b(i+1,i+1)*conj(a(i,i)) - a(i+1,i+1)*conj(b(i,i))) < realsmall + pairs(i)=1; + pairs(i+1)=-1; + i=i+2; + else + i=i+1; + end +end + +% determine number unstable roots +nunstable=0; +i=1; +while i <= n + if pairs(i) == 0 + if (abs(b(i,i)) > abs(a(i,i))) + nunstable=n-i+1; + break; + else + i=i+1; + end + else + if (abs(b(i,i)) > abs(a(i,i))) | (abs(b(i+1,i+1)) > abs(a(i+1,i+1))) + nunstable=n-i+1; + break; + else + i=i+2; + end + end +end + +% No bounded MSV solutions? +if nunstable > s + disp('No bounded MSV solutions') + eu{ii}=[0;0]; + gev{ii}=[diag(a) diag(b)]; + G1{ii}=[] + impact{ii}=[] + return; +end + +disp('Beginning*************') +% Multiple bounded MSV solutions? +if nunstable < s + disp('Multiple bounded MSV solutions should exist'); + + % Get roots to suppress + idx=zeros(n,1); + idx_size=zeros(n,1); + k=1; + idx(1)=n-nunstable; + cont=1; + while cont > 0 + if (pairs(idx(k)) == -1) + idx_size=2; + else + idx_size=1; + end + + d=nunstable; + for i=1:k + d=d+idx_size(i); + end + + d + size(pi,2) + if (d == size(pi,2)) + cont=cont+1; + [an bn qn zn]=qzmoveindex(a,b,q,z,pairs,idx,k,n-nunstable); + [G1{ii},impact{ii},eu{ii}]=qzcomputesolution(an,bn,qn,zn,psi,pi,s); + gev{ii}=[diag(an) diag(bn)]; + ii=ii+1 + end + + if (d >= s) + if idx(k) > idx_size(k) + idx(k)=idx(k)-idx_size(k); + else + if k > 1 + k=k-1; + idx(k)=idx(k)-idx_size(k); + else + return; + end + end + else + if idx(k) > idx_size(k) + k=k+1; + idx(k)=idx(k-1)-idx_size(k); + else + if k > 1 + k=k-1; + idx(k)=idx(k)-idx_size(k); + else + return; + end + end + end + end +end + +disp('End*************') +% Unique MSV solution? +disp('Unique bounded MVS solution'); +[G1{ii},impact{ii},eu{ii}]=qzcomputesolution(a,b,q,z,psi,pi,s); +gev{ii}=[diag(a) diag(b)]; + + + diff --git a/MatlabFiles/MSV/msv_all_complex.m b/MatlabFiles/MSV/msv_all_complex.m new file mode 100755 index 0000000..607f572 --- /dev/null +++ b/MatlabFiles/MSV/msv_all_complex.m @@ -0,0 +1,177 @@ +function [Gamma,Omega]=msv_all_complex(A1,A2,A3,B1,B2,B3,C1) +% System given as +% +% E_t[y(t+1)] = A1*u(t) + A2*z(t) + A3*y(t) +% +% z(t+1) = B1*u(t) + B2*z(t) + B3*y(t) +% +% u(t+1) = C1*u(t) + epsilon(t+1) +% +% for t >= 0. The dimension of u(t) is r, the dimension of z(t) is k, and +% the dimension of y(t) is s. E_t[epsilon(t+1)]=0. +% +% Solution technique: +% +% Assume a solution of the form y(t) = Gamma*u(t) + Omega*z(t). This +% implies that +% +% Gamma*C1*u(t) + Omega*(B1*u(t) + B2*z(t) + B3*(Gamma*u(t) + Omega*z(t))) +% = A1*u(t) + A2*z(t) + A3*(Gamma*u(t) + Omega*z(t)) +% +% Gathering terms, we have that +% +% (1) (Omega*B2 + Omega*B3*Omega - A2 - A3*Omega)*z(t) = 0 +% +% (2) (Gamma*C1 + Omega*B1 + Omega*B3*Gamma - A1 - A3*Gamma)*u(t) = 0 +% +% Let +% +% X = [ -B2 -B3 +% -A2 -A3 ] +% +% and let X = U*T*U' be a Schur decomposition of X, where U is unitary, T +% is upper triangular, and ' denotes the conjugate transpose. If +% +% U = [ U11 U12 +% U21 U22 ] +% +% and U11 is invertiable, then +% +% (3) Omega = U21*inv(U11) +% +% will be a solution of (1) for any value of z(t) in k-dimensional +% euclidean space. On the other hand, if Omega is a solution of (1) for +% all z(t) in k-dimensional euclidean space, then Omega is of the form of +% (3) for some Schur decomposition of X. +% +% Given Omega, the solution of the second equation is +% +% vec(Gamma) = inv(kron(C1',eye(s)) + kron(eye(r),Omega*B3 - A3)) +% *vec(A1 - Omega*B1) +% +% The solution Omega of (1) depends only on the column space +% +% [ U11 +% U21 ] +% +% which we denote by V. It is well known that the eigenvalues of X appear +% along the diagonal of T. If the eigenvalues of X are distinct, then the +% ordering of the eigenvalues uniquely determines U. However, when the +% dimension of the eigenspace of some eigenvalue is greater than one, this +% is no longer true and reordering the Schur decomposition is no longer +% sufficient to capture all possible solutions. +% +% By Daniel Waggoner + +realsmall=sqrt(eps); + +r=size(A1,2); +k=size(A2,2); +s=size(A3,2); +kk=k+s; + +Gamma=cell(0,1); +Omega=cell(0,1); + +if k == 0 + Y=kron(C1',eye(s)) + kron(eye(r),-A3); + if rank(Y) == size(Y,1) + Omega{1,1}=zeros(s,k); + Gamma{1,1}=reshape(inv(Y)*reshape(A1,s*r,1),s,r); + + %------------------------------------------------------------------ + % Check if solution - comment out for production runs + % E_t[y(t+1)] = E_t[Gamma*u(t+1) + Omega*z(t+1)] + % = Gamma*C1*u(t) + Omega*(B1*u(t) + B2*z(t) + % + B3*(Gamma*u(t) + Omega*z(t))) + % = A1*u(t) + A2*z(t) + A3*(Gamma*u(t) + Omega*z(t)) + %------------------------------------------------------------------ + n1=norm(Gamma*C1 - (A1 + A3*Gamma)); + if n1 > realsmall + disp('Should be zero - press any key to continue'); + disp('Gamma*C1 - (A1 + A3*Gamma)'); + disp(n1); + pause; + end + %------------------------------------------------------------------ + + end +else + % get and order Schur decomposition + X=[ -B2 -B3 + -A2 -A3 + ]; + + [U,T]=schur(X,'complex'); + [d,id]=sort(abs(diag(T)),'descend'); + [id,idx]=sort(id); + [U,T]=ordschur(U,T,idx); + u=U; t=T; + + idx=ones(s+k,1); + for i=0:s-1 + idx(s+k-i)=0; + end + + ii=1; + cont=1; + while cont == 1 + + u11=u(1:k,1:k); + u21=u(k+1:k+s,1:k); + + if rank(u11) == k + omega=u21/u11; + Y=kron(C1',eye(s)) + kron(eye(r),omega*B3 - A3); + if rank(Y) == size(Y,1) + Omega{ii,1}=omega; + Gamma{ii,1}=reshape(Y\reshape(A1 - omega*B1,s*r,1),s,r); + ii=ii+1; + + %---------------------------------------------------------- + % Check if solution - comment out for production runs + % E_t[y(t+1)] = E_t[Gamma*u(t+1) + Omega*z(t+1)] + % = Gamma*C1*u(t) + Omega*(B1*u(t) + B2*z(t) + % + B3*(Gamma*u(t) + Omega*z(t))) + % = A1*u(t) + A2*z(t) + A3*(Gamma*u(t) + % + Omega*z(t)) + %---------------------------------------------------------- + n1=norm(Gamma{ii-1,1}*C1 + Omega{ii-1,1}*(B1 + B3*Gamma{ii-1,1}) - (A1 + A3*Gamma{ii-1,1})); + n2=norm(Omega{ii-1,1}*(B2 + B3*Omega{ii-1,1}) - (A2 + A3*Omega{ii-1,1})); + if (n1 > realsmall) || (n2 > realsmall) + i + idx + disp('Both should be zero - press any key to continue'); + disp('Gamma*C1 + Omega*(B1 + B3*Gamma) - (A1 + A3*Gamma)'); + disp(n1); + disp('Omega*(B2 + B3*Omega) - (A2 + A3*Omega)'); + disp(n2); + pause + end + %---------------------------------------------------------- + end + end + + % increment idx + cont=0; + jj=1; + while (jj < kk) & (idx(jj) == 0) + idx(jj)=1; + jj=jj+1; + end + for j=jj+1:kk + if idx(j) == 0 + idx(j)=1; + cont=1; + break; + end + end + for i=1:jj + idx(j-i)=0; + end + + [u,t]=ordschur(U,T,idx); + end +end + + diff --git a/MatlabFiles/MSV/msv_complex_AR.m b/MatlabFiles/MSV/msv_complex_AR.m new file mode 100755 index 0000000..ae9c5c1 --- /dev/null +++ b/MatlabFiles/MSV/msv_complex_AR.m @@ -0,0 +1,69 @@ +function [g1,impact,gev,z2,err]=msv_complex_AR(A,B,Psi,Pi) +% System given as +% +% A*y(t) = B*y(t-1) + psi*epsilon(t) + pi*eta(t), +% +% with epsilon(t) an exogenous process and eta(t) endogenously determined +% one-step-ahead expectational errors. Returned solutions are +% +% y(t)=G1{i}*y(t-1)+Impact{i}*epsilon(t). +% +% The span of the each of the solutions returned will be n-s and the +% solution will be uniquely determined by its span. gev returns the +% generalized eigenvalues, of which the last s were suppressed. z2 is the +% subspace that is perpendicular to the span of the solution. +% +% err is the error return. +% err = [2;2] -- degenerate system +% err = [1;1] -- success, unique msv solution found. +% err = [1;0] -- multiple msv solutions +% err = [3;?] -- msv solutions are unbounded +% +% Solutions are obtained via calls to msv_all_complex_AR(). +% +% By Daniel Waggoner + +realsmall=sqrt(eps); + +% find all msv type solutions +[G1,Impact,Gev,Z2,err]=msv_all_complex_AR(A,B,Psi,Pi); + +if err ~= 0 + % no solution exists + g1=[]; + impact=[]; + gev=Gev{1,1}; + z2=[]; + if err == 2 + err=[-2;-2]; + else + err=[0;0]; + end +else + % solution exists + g1=G1{1}; + impact=Impact{1,1}; + gev=Gev{1,1}; + z2=Z2{1,1}; + + % uniqueness + if size(G1,1) == 1 + err=[1,1]; + else + n=size(Pi,1); + m=n-size(Pi,2)+1; + x1=min(abs(gev(m:n,2)./gev(m:n,1))); + x2=min(abs(Gev{2,1}(m:n,2)./Gev{2,1}(m:n,1))); + if abs(x1 - x2) > realsmall + err=[1,1]; + else + err=[1,0]; + end + end + + % boundedness + m=size(Pi,1)-size(Pi,2); + if max(abs(gev(1:m,2)./gev(1:m,1))) > 1+1.0e-9 + err(1)=3 + end +end diff --git a/MatlabFiles/MSV/msv_one.m b/MatlabFiles/MSV/msv_one.m new file mode 100755 index 0000000..7d68e5a --- /dev/null +++ b/MatlabFiles/MSV/msv_one.m @@ -0,0 +1,143 @@ +function [G1,impact,gev,eu]=msv_one(g0,g1,psi,pi) +% function [G1,C,impact,gev,eu]=msv_one(g0,g1,psi,pi) +% System given as +% g0*y(t)=g1*y(t-1)+psi*z(t)+pi*eta(t), +% with z an exogenous variable process and eta being endogenously determined +% one-step-ahead expectational errors. Returned system is +% y(t)=G1*y(t-1)+impact*z(t). +% eu(1)=1 for existence, eu(2)=1 for uniqueness. eu(1)=-1 for +% existence only with not-s.c. z; eu=[-2,-2] for coincident zeros. +% By Daniel Waggoner -- Based on code by Christopher A. Sims + +realsmall=1e-10; + +G1=[]; +impact=[]; +gev=[]; + +n=size(pi,1); + +[a b q z]=qz(g0,g1); + +for i=1:n + if (abs(a(i,i)) < realsmall) & (abs(b(i,i)) < realsmall) + disp('Coincident zeros.') + eu=[-2;-2]; + gev=[diag(a) diag(b)]; + return + end +end + +[a b q z]=qzsort(a,b,q,z); + +% determine complex conjugate pairs +pairs=zeros(n,1); +i=1; +while i < n + if abs(b(i+1,i+1)*conj(a(i,i)) - a(i+1,i+1)*conj(b(i,i))) < realsmall + pairs(i)=1; + pairs(i+1)=-1; + i=i+2; + else + i=i+1; + end +end + +% determine number unstable roots +nunstable=0; +i=1; +while i <= n + if pairs(i) == 0 + if (abs(b(i,i)) > abs(a(i,i))) + nunstable=n-i+1; + break; + else + i=i+1; + end + else + if (abs(b(i,i)) > abs(a(i,i))) | (abs(b(i+1,i+1)) > abs(a(i+1,i+1))) + nunstable=n-i+1; + break; + else + i=i+2; + end + end +end + +eu=[0;0]; +gev=[diag(a) diag(b)]; + +% No bounded MSV solutions? +if nunstable > size(pi,2) + disp('No bounded MSV solutions') + return; +end + +% Multiple bounded MSV solutions? +if nunstable < size(pi,2) + disp('Multiple bounded MSV solutions should exist'); + + % Get roots to suppress + idx=zeros(n,1); + idx_size=zeros(n,1); + k=1; + idx(1)=n-nunstable; + cont=1; + while cont > 0 + if (pairs(idx(k)) == -1) + idx_size=2; + else + idx_size=1; + end + + d=nunstable; + for i=1:k + d=d+idx_size(i); + end + + if (d == size(pi,2)) + cont=cont+1; + [an bn qn zn]=qzmoveindex(a,b,q,z,pairs,idx,k,n-nunstable); + [G1,impact,eu]=qzcomputesolution(an,bn,qn,zn,psi,pi,size(pi,2)); + if (eu(1) == 1) & (eu(2) == 1) + gev=[diag(an) diag(bn)]; + return; + else + disp('MSV solution does not exist for the ordering:'); + abs(diag(bn)./diag(an)) + eu + end + end + + if (d >= size(pi,2)) + if idx(k) > idx_size(k) + idx(k)=idx(k)-idx_size(k); + else + if k > 1 + k=k-1; + idx(k)=idx(k)-idx_size(k); + else + disp('No MSV solutions exist'); + return; + end + end + else + if idx(k) > idx_size(k) + k=k+1; + idx(k)=idx(k-1)-idx_size(k); + else + if k > 1 + k=k-1; + idx(k)=idx(k)-idx_size(k); + else + disp('No MSV solutions exist'); + return; + end + end + end + end +end + +% Unique MSV solution? +disp('Unique bounded MVS solution'); +[G1,impact,eu]=qzcomputesolution(a,b,q,z,psi,pi,size(pi,2)); diff --git a/MatlabFiles/MSV/msv_simple.m b/MatlabFiles/MSV/msv_simple.m new file mode 100755 index 0000000..c37148f --- /dev/null +++ b/MatlabFiles/MSV/msv_simple.m @@ -0,0 +1,62 @@ +function [G1,impact,gev,eu]=msv_simple(g0,g1,psi,pi) +% function [G1,C,impact,gev,eu]=msv_one(g0,g1,psi,pi) +% System given as +% g0*y(t)=g1*y(t-1)+psi*z(t)+pi*eta(t), +% with z an exogenous variable process and eta being endogenously determined +% one-step-ahead expectational errors. Returned system is +% y(t)=G1*y(t-1)+impact*z(t). +% eu(1)=1 for existence, eu(2)=1 for uniqueness. +% eu=[-2,-2] for coincident zeros. +% By Daniel Waggoner -- Based on code by Christopher A. Sims + +realsmall=1e-10; + +G1=[]; +impact=[]; +gev=[]; + +n=size(pi,1); +s=size(pi,2); + +[a b q z]=qz(g0,g1); + +for i=1:n + if (abs(a(i,i)) < realsmall) & (abs(b(i,i)) < realsmall) + disp('Coincident zeros.') + eu=[-2;-2]; + gev=[diag(a) diag(b)]; + return + end +end + +[a b q z]=qzsort(a,b,q,z); + +% determine number unstable roots +nunstable=0; +i=n; +while i > 0 + if (abs(b(i,i)) > abs(a(i,i))) + nunstable=nunstable+1; + i=i-1; + else + break; + end +end + +eu=[0;0]; +gev=[diag(a) diag(b)]; + +% No bounded MSV solutions? +if nunstable > s + disp('No bounded MSV solutions') + return; +end + +% Multiple or unique bounded MSV solutions? +if nunstable < s + disp('Multiple bounded MSV solutions should exist'); +else + disp('Unique bounded MVS solution'); +end + +[G1,impact,eu]=qzcomputesolution(a,b,q,z,psi,pi,s); diff --git a/MatlabFiles/MSV/qzcomputesolution.m b/MatlabFiles/MSV/qzcomputesolution.m new file mode 100755 index 0000000..4c5dcdb --- /dev/null +++ b/MatlabFiles/MSV/qzcomputesolution.m @@ -0,0 +1,120 @@ +function [G1,impact,eu]=qzcomputesolution(a,b,q,z,psi,pi,suppress) +% System given as +% +% (q'*a*z')*y(t) = (q'*b*z')*y(t-1) + psi*epsilon(t) + pi*eta(t), +% +% with epsilon(t) an exogenous process and eta(t) an endogenously +% determined one-step-ahead expectational error. The matrices q and z are +% unitary and a and b are upper triangular. Furthermore, it is assumed +% that if a11 is the upper (n-suppress) x (n-suppress) block of a, then a11 +% is non-singular. +% +% The span of the returned solution is equal to the span of the first +% (n-suppress) columns of z. +% +% If t +% It is assumed that the ordering of +% the system is such that complex conjugate pairs are together. If a +% complex conjugate pair is split, then G1 and impact will be complex. +% +% Returned solution is +% +% y(t) = G1*y(t-1) + impact*z(t). +% +% eu(1)=1 for existence, eu(2)=1 for uniqueness. +% +% The last suppress roots are suppressed. +% +% By Daniel Waggoner -- Based on code by Christopher A. Sims + +realsmall=sqrt(eps); + +eu=[0;0]; +G1=[]; +impact=[]; + +n=size(pi,1); +s=size(pi,2); + +q1=q(1:n-suppress,:); +q2=q(n-suppress+1:n,:); + +[u1 d1 v1]=svd(q2*pi,'econ'); + +% find the dimension of the column space of q2*pi +if suppress > 0 + % all singular values small - q2*pi is the zero matrix + if d1(1,1) < realsmall + m=0; + else + % exclude the small singular values relative to largest + m=sum(diag(d1) > realsmall*d1(1,1)); + end +else + m=0; +end +u1=u1(:,1:m); +d1=d1(1:m,1:m); +v1=v1(:,1:m); + +if (m == suppress) + eu(2)=1; +end + +% find othogonal basis for span of q2*psi +[u2 d2 v2]=svd(q2*psi,'econ'); +if suppress > 0 + % all singular values small - q2*psi is the zero matrix + if d2(1,1) < realsmall + m=0; + else + % exclude the small singular values relative to largest + m=sum(diag(d2) > realsmall*d2(1,1)); + end +else + m=0; +end +u2=u2(:,1:m); +d2=d2(1:m,1:m); +v2=v2(:,1:m); + +% is the projection of the column space of q2*psi on to the column space of +% the column space of q2*pi the identity mapping? +if norm((eye(suppress) - u1*u1')*u2) > realsmall + return +end + +eu(1)=1; + +% Compute impact and G0 +a11_inv=inv(a(1:n-suppress,1:n-suppress)); +x=a11_inv*q1*pi*v1*diag(1./diag(d1))*u1'; +impact=[a11_inv*q1*psi - x*q2*psi; zeros(suppress,size(psi,2))]; + +G1=zeros(n,n); + +G1(1:n-suppress,1:n-suppress)=a11_inv*b(1:n-suppress,1:n-suppress); + +% Uncomment the line below to make the answer agree with gensys - this +% piece does not effect the answer, at least after the initial period. +G1(1:n-suppress,n-suppress+1:n)=a11_inv*b(1:n-suppress,n-suppress+1:n) - x*b(n-suppress+1:n,n-suppress+1:n); + +% Convert back to y +impact=z*impact; +G1=z*G1*z'; + +% Is the solution real? +% if (suppress == 0) | (suppress == n) | (abs(b(n-suppress+1,n-suppress+1)*conj(a(n-suppress,n-suppress)) - a(n-suppress+1,n-suppress+1)*conj(b(n-suppress,n-suppress))) > realsmall) +% impact=real(impact); +% G1=real(G1); +% end + +%-------------------------------------------------------------------------- +% The code below check that a solution is obtained with stable manifold +% z1. Should be commented out for production runs. +%-------------------------------------------------------------------------- +z2=z(:,n-suppress+1:n); +z1=null(z2'); +%if check_solution_AR(G1,impact,q'*a*z',q'*b*z',psi,pi,z1) == 1 +% eu(1)=3; +%end diff --git a/MatlabFiles/MSV/qzdiv.m b/MatlabFiles/MSV/qzdiv.m new file mode 100755 index 0000000..b04068f --- /dev/null +++ b/MatlabFiles/MSV/qzdiv.m @@ -0,0 +1,40 @@ +function [A,B,Q,Z,v] = qzdiv(stake,A,B,Q,Z,v) +%function [A,B,Q,Z,v] = qzdiv(stake,A,B,Q,Z,v) +% +% Takes U.T. matrices A, B, orthonormal matrices Q,Z, rearranges them +% so that all cases of abs(B(i,i)/A(i,i))>stake are in lower right +% corner, while preserving U.T. and orthonormal properties and Q'AZ' and +% Q'BZ'. The columns of v are sorted correspondingly. +% +% by Christopher A. Sims +% modified (to add v to input and output) 7/27/00 +vin = nargin==6; +%if ~vin, v=[], end; +if ~vin, v=[]; end; +[n jnk] = size(A); +root = abs([diag(A) diag(B)]); +root(:,1) = root(:,1)-(root(:,1)<1.e-13).*(root(:,1)+root(:,2)); +root(:,2) = root(:,2)./root(:,1); +for i = n:-1:1 + m=0; + for j=i:-1:1 + if (root(j,2) > stake | root(j,2) < -.1) + m=j; + break + end + end + if (m==0) + return + end + for k=m:1:i-1 + [A B Q Z] = qzswitch(k,A,B,Q,Z); + tmp = root(k,2); + root(k,2) = root(k+1,2); + root(k+1,2) = tmp; + if vin + tmp=v(:,k); + v(:,k)=v(:,k+1); + v(:,k+1)=tmp; + end + end +end diff --git a/MatlabFiles/MSV/qzmoveindex.m b/MatlabFiles/MSV/qzmoveindex.m new file mode 100755 index 0000000..57bd9c9 --- /dev/null +++ b/MatlabFiles/MSV/qzmoveindex.m @@ -0,0 +1,18 @@ +function [a,b,q,z] = qzmoveindex(a,b,q,z,pairs,idx,k,j) +% function [a,b,q,z] = qzmoveindex(a,b,q,z,pairs,idx,k,j) +% +% Takes U.T. matrices a, b, orthonormal matrices q,z, rearranges them +% so that the indices in idx are moved up to the jth position, while +% preserving U.T. and orthogonal properties and q'az' and q'bz'. +% +% by Daniel Waggoner based on code by Christopher A. Sims + +while k > 0 + [a b q z pairs]=qzslide(a,b,q,z,pairs,idx(k),j); + if (pairs(j) == -1) + j=j-2; + else + j=j-1; + end + k=k-1; +end \ No newline at end of file diff --git a/MatlabFiles/MSV/qzslide.m b/MatlabFiles/MSV/qzslide.m new file mode 100755 index 0000000..f9bbcb4 --- /dev/null +++ b/MatlabFiles/MSV/qzslide.m @@ -0,0 +1,80 @@ +function [a,b,q,z,pairs] = qzslide(a,b,q,z,pairs,i,j) +% function [a,b,q,z,pairs] = qzslide(a,b,q,z,pairs,i,j) +% +% Takes U.T. matrices A, B, orthonormal matrices Q,Z, rearranges them +% so that the ith diagonal element is moved to the jth position, while +% preserving U.T. and orthogonal properties and Q'AZ' and Q'BZ'. +% +% The array pairs is also rearranged. Complex conjugate pairs are kept +% adjacent. If pairs(i)=1, then position i and i+1 are complex +% conjugate pairs. If pairs(i)=-1, then position i and i-1 are complex +% conjugate pairs. If pairs(i)=0, then position i is real. +% +% +% by Daniel Waggoner based on code by Christopher A. Sims + +n=size(a,1); + +if i == j + return; +end + +if i < j + if pairs(j) == 1 + j=j+1; + end + if pairs(i) == -1 + j=j-1; + i=i-1; + else + if (pairs(i) == 1) & (j == n) + if (i == n-1) + return; + end + j=n-1; + end + end + while i < j + if (pairs(i) == 1) + [a b q z]=qzswitch(i+1,a,b,q,z); + [a b q z]=qzswitch(i,a,b,q,z); + pairs(i)=pairs(i+2); + pairs(i+1)=1; + pairs(i+2)=-1; + else + [a b q z]=qzswitch(i,a,b,q,z); + pairs(i)=pairs(i+1); + pairs(i+1)=0; + end + i=i+1; + end +else + if pairs(j) == -1 + j=j-1; + end + if pairs(i) == 1 + j=j+1; + i=i+1; + else + if (pairs(i) == -1) & (j == 1) + if (i == 2) + return; + end + j=2; + end + end + while i > j + if (pairs(i) == -1) + [a b q z]=qzswitch(i-2,a,b,q,z); + [a b q z]=qzswitch(i-1,a,b,q,z); + pairs(i)=pairs(i-2); + pairs(i-2)=1; + pairs(i-1)=-1; + else + [a b q z]=qzswitch(i-1,a,b,q,z); + pairs(i)=pairs(i-1); + pairs(i-1)=0; + end + i=i-1; + end +end diff --git a/MatlabFiles/MSV/qzsort.m b/MatlabFiles/MSV/qzsort.m new file mode 100755 index 0000000..7f24331 --- /dev/null +++ b/MatlabFiles/MSV/qzsort.m @@ -0,0 +1,21 @@ +function [A,B,Q,Z] = qzsort(A,B,Q,Z) +%function [A,B,Q,Z] = qzsort(stake,A,B,Q,Z) +% +% Takes U.T. matrices A, B, orthonormal matrices Q,Z, rearranges them +% so that abs(B(i,i)/A(i,i)) are increasing, while preserving U.T. and +% orthonormal properties and Q'AZ' and % Q'BZ'. +% +% by Daniel Waggoner based on code by Christopher A. Sims + +n=size(A,1); + +for i=2:n + for j=i:-1:2 + if abs(A(j,j)*B(j-1,j-1)) > abs(A(j-1,j-1)*B(j,j)) + [A B Q Z]=qzswitch(j-1,A,B,Q,Z); + else + break; + end + end +end + diff --git a/MatlabFiles/MSV/qzswitch.m b/MatlabFiles/MSV/qzswitch.m new file mode 100755 index 0000000..93c3664 --- /dev/null +++ b/MatlabFiles/MSV/qzswitch.m @@ -0,0 +1,60 @@ +function [A,B,Q,Z] = qzswitch(i,A,B,Q,Z) +%function [A,B,Q,Z] = qzswitch(i,A,B,Q,Z) +% +% Takes U.T. matrices A, B, orthonormal matrices Q,Z, interchanges +% diagonal elements i and i+1 of both A and B, while maintaining +% Q'AZ' and Q'BZ' unchanged. If diagonal elements of A and B +% are zero at matching positions, the returned A will have zeros at both +% positions on the diagonal. This is natural behavior if this routine is used +% to drive all zeros on the diagonal of A to the lower right, but in this case +% the qz transformation is not unique and it is not possible simply to switch +% the positions of the diagonal elements of both A and B. + realsmall=sqrt(eps)*10; +%realsmall=1e-3; +a = A(i,i); d = B(i,i); b = A(i,i+1); e = B(i,i+1); +c = A(i+1,i+1); f = B(i+1,i+1); + % A(i:i+1,i:i+1)=[a b; 0 c]; + % B(i:i+1,i:i+1)=[d e; 0 f]; +if (abs(c)<realsmall & abs(f)<realsmall) + if abs(a)<realsmall + % l.r. coincident 0's with u.l. of A=0; do nothing + return + else + % l.r. coincident zeros; put 0 in u.l. of a + wz=[b; -a]; + wz=wz/sqrt(wz'*wz); + wz=[wz [wz(2)';-wz(1)'] ]; + xy=eye(2); + end +elseif (abs(a)<realsmall & abs(d)<realsmall) + if abs(c)<realsmall + % u.l. coincident zeros with l.r. of A=0; do nothing + return + else + % u.l. coincident zeros; put 0 in l.r. of A + wz=eye(2); + xy=[c -b]; + xy=xy/sqrt(xy*xy'); + xy=[[xy(2)' -xy(1)'];xy]; + end +else + % usual case + wz = [c*e-f*b, (c*d-f*a)']; + xy = [(b*d-e*a)', (c*d-f*a)']; + n = sqrt(wz*wz'); + m = sqrt(xy*xy'); + if m<eps*100 + % all elements of A and B proportional + return + end + wz = n\wz; + xy = m\xy; + wz = [wz; -wz(2)', wz(1)']; + xy = [xy;-xy(2)', xy(1)']; +end +A(i:i+1,:) = xy*A(i:i+1,:); +B(i:i+1,:) = xy*B(i:i+1,:); +A(:,i:i+1) = A(:,i:i+1)*wz; +B(:,i:i+1) = B(:,i:i+1)*wz; +Z(:,i:i+1) = Z(:,i:i+1)*wz; +Q(i:i+1,:) = xy*Q(i:i+1,:); \ No newline at end of file diff --git a/MatlabFiles/MSV/test_gensys.m b/MatlabFiles/MSV/test_gensys.m new file mode 100755 index 0000000..64a7af3 --- /dev/null +++ b/MatlabFiles/MSV/test_gensys.m @@ -0,0 +1,30 @@ +r=2; +s=2; +n=6; +explosive=n; + +div=1.0; + +a=rand(n,n); +b=rand(n,n); +[a b q z]=qz(a,b); +a=q*diag(ones(n,1)+rand(n,1))*z; +d=rand(n,1); +d(1:explosive)=d(1:explosive)+ones(explosive,1); +b=q*diag(d)*z; + +psi=rand(n,r); +pi=rand(n,s); +c=zeros(n,1); + +[G1,C,impact,fmat,fwt,ywt,gev,eu]=gensys(a,b,c,psi,pi,div); +[dwG1,dwimpact,dwgev,dweu]=dw_gensys(a,b,psi,pi,div); + +G1 +dwG1 + +impact +dwimpact + +eu +dweu \ No newline at end of file diff --git a/MatlabFiles/PHG233.M b/MatlabFiles/PHG233.M new file mode 100755 index 0000000..106c6e2 --- /dev/null +++ b/MatlabFiles/PHG233.M @@ -0,0 +1,254 @@ +function g = phg233(x,idmat0,idmat1,fss,nvar,ncoef,phi, ... + y,A0b,sg0bid,sgpbid) +%function of = pmddf232(x,idmat,fss,nvar,ncoef,phi, ... +% y,A0b,sg0bid,sgpbid) +% Leeper-Sims-Zha BVAR setup +% general program to setup A0 matrix and compute the likelihood +% requires +% x (parameter vector) +% a0indx (matrix indicating the free parameters in A0) +% fss (forecast sample size) +% nvar (number of variables) +% ncoef (number of coefficients in a single equation in A+) +% phi (r.h.s. observations in the system for A+) +% y (l.h.s. observations for A0) +% A0b (initial prior mean on A0) +% sg0bid (diagonal of Sigma0_bar, unweighted prior vcv on the parameters in i-th equation in A0) +% sgpbid (diagonal of Sigma+_bar, unweighted prior vcv on the parameters in i-th equation in A+) +% +% Revisions by CAS 9/27/96: If we transmit idmat, rather than a0indx, we can scale the elements of +% idmat so that it carries information about relative prior variances. +global vaya0 vaha0 vaxah vahad vbiga GlbAph FRESHFUNCTION +% FRESHFUNCTION added 8/20/90 by CAS. It signals the pmddg23 whether the global variables +% it uses have been refreshed by a new pmddf231 call since the last gradient call. +a0indx=find(idmat0); +% pre-allocate GlbAph to be zeros(nvar,lags*nvar+1=ncoef) + +nhp = 0; % <<>> 4 hyperparameters +na0p = length(a0indx); % <<>> number of A0 parameters +nfp = na0p+nhp; + +% *** initializing +vaya0 = zeros(na0p,1); +vaha0 = zeros(na0p,1); +vaxah = zeros(na0p,1); +vahad = zeros(na0p,1); +vbiga = zeros(na0p,1); + + +A0h = zeros(nvar,nvar); +A0h(a0indx) = x(1:na0p); +%A0h = reshape(a0,nvar,nvar); CAS 9/24/96. The reshape is not necessary if a0 starts as nvar x nvar + % restrictions on A0 + +[A0hl,A0hu] = lu(A0h); + +% ** hyperparameters +%%mu = x(na0p+1:nfp); +mu = ones(5,1); +mu(1) = 1; +%mu(1) = 2; +mu(2) = 0.2; +mu(3) = 1; +%mu(4)=1; +mu(4)=1; +mu(5) =1; +%mu(5) = 40; +% results from ...\dummy1\foreh\pmdd6.out +% +% mu(1): overall tightness and also for A0; +% mu(2): relative tightness for A+; +% mu(3): relative tightness for the constant term; +% mu(4): weight on single dummy initial observation including constant; +% mu(5): weight on nvar sums of coeffs dummy observations. + +% ** weight prior dummy observations +%phi(1:nvar,:) = (mu(5)^2/mu(1)^2)*phi(1:nvar,:); +%y(1:nvar,:) = (mu(5)^2/mu(1)^2)*y(1:nvar,:); +%phi(ndobs,:) = mu +% modified by CAS 8/6/96. The dummy obs weights are naturally in std units, not var units. +phi(1:nvar,:) = mu(5)*phi(1:nvar,:); +y(1:nvar,:) = mu(5)*y(1:nvar,:); +phi(nvar+1,:) = mu(4)*phi(nvar+1,:); +y(nvar+1,:) = mu(4)*y(nvar+1,:); + +% ** set up the conditional prior variance sg0bi and sgpbi. +sg0bida = mu(1)^2*sg0bid; +sgpbida = mu(1)^2*mu(2)^2*sgpbid; +sgpbida(ncoef) = mu(1)^2*mu(3)^2; +sgppbd = sgpbida(nvar+1:ncoef); % corresponding to A++, in a SZ paper +sgppb = diag(sgppbd); + +% +% ** some common terms +[u d v]=svd(phi,0); %trial +% xtx = phi'*phi; %trial +vd=v.*(ones(size(v,2),1)*diag(d)'); %trial +xtx=vd*vd'; +% M = eye(fss) - phi*(xtx\phi'); % not used except in line below %trial +yu = y'*u; %trial +cxyxx=yu*yu'; %trial +ymy=y'*y-cxyxx; %trial +%ymy = y'*M*y; +%cxy = phi'*y; %trial +cxy = vd*yu'; %trial +%cxpy = xtx\cxy; %not used further except in line below +%cxyxx = cxy'*cxpy; + +% ** estimate A+_hat conditional on A0, ncoef*nvar, but not using full prior +%GlbAph = cxpy*A0h; + + +%%%%%%% +%%% build the analytical gradient +%%%%%%% +% +disp(sprintf('Starting loop (of): %g',toc)) + +stril = 0; +Hp0p = zeros(ncoef); +% initializing Htd_+0*inv(Htd_00)*Htd_0+: conditional prior covariance +for i = 1:nvar + stri = find(idmat0(:,i)); %CAS change 9/24/96, to avoid slim chance of an exact zero in x vector + %at some point during an optimization. + strm = length(stri); + + A0hb = A0h(stri,i)-A0b(stri,i); + Hp0 = zeros(ncoef,strm); + % initializing Htd_+0*inv(Htd_00)*Htd_0 + + % ** set up the conditional prior variance sg0bi and sgpbi. + % sg0bd = zeros(stri,1); Commented out by CAS, 9/24/96. Looks like this meant to have + % strm where it has stri, and in any case it is "overwritten" below. + %------------------------------ + % Introduce prior information on which variables "belong" in various equations. + % In this first trial, we just introduce this information here, in a model-specific way. + % Eventually this info has to be passed parametricly. In our first shot, we just damp down + % all coefficients except those on the diagonal. + factor0=idmat0(:,i); + sg0bd = sg0bida(stri).*factor0(stri); + sg0b = diag(sg0bd); + % + factor1=idmat1(:,i); + sg1bd = sgpbida(1:nvar).*factor1; + sg1b = diag(sg1bd); + + % ** set up the unconditional prior variance on A0i and A+i + XX = zeros(nvar,strm); + XX(stri,:) = eye(strm); % XX in Gelman, etel, on p479 + % + Hb = zeros(strm+ncoef); % including A0i and A+i + Hb(1:strm,1:strm) = sg0b; + sg0bxx = sg0b*XX'; + Hb(1:strm,strm+1:strm+nvar) = sg0bxx; + %Hb(strm+1:strm+nvar,1:strm) = XX*sg0b; CAS 9/24/96. Saves a little multiplication by using line below. + Hb(strm+1:strm+nvar,1:strm) = sg0bxx'; + Hb(strm+1:strm+nvar,strm+1:strm+nvar) = XX*sg0bxx+sg1b; + Hb(strm+nvar+1:strm+ncoef,strm+nvar+1:strm+ncoef) = sgppb; + + % ** set up the final prior variance on A0i and A+i, i =1,..,6 separately. + % ** using dummy initial observations + %zs1 = [ys1(:,stri) -xd0]; % z*1 for the 1st equation + + % * final unconditional prior variance on A0i and A+i + %Hbzs1=Hb*zs1'; + %Htd = Hb - Hbzs1*((zs1*Hbzs1+mu(1)^2*mu(4)^2*eye(nvar))\Hbzs1'); + % CAS mod 8/7/96: Hope is that dropping above two lines in favor of the one below + % removes double-counting of dummy observations and a possible scale sensitivity. + Htd = Hb; + % H_~: td: tilde for ~ + + % * final conditional prior variance on A+i give that on A0i, and + % * unconditional variance on A0+ + H0td = Htd(1:strm,1:strm); % unconditional + % ** inverse and chol decomp + H0tdi = inv(H0td); + + % + Hptd10 = Htd(strm+1:strm+nvar,1:strm); + % top matrix of nvar in Htd_+0 + Hptd100 = Hptd10*H0tdi; + Hp0(1:nvar,:) = Hptd100; + Hptd101 = Hptd100*Hptd10'; + Hp0p(1:nvar,1:nvar) = Hptd101; + Hptd = Htd(strm+1:strm+ncoef,strm+1:strm+ncoef) - Hp0p; + % condtional on A0i, H_plus_tilde + + % ** inverse + Hptdi = inv(Hptd); + chhh = Hptdi*Hp0; % <<>> the term not used for "of" + + % common term + xxhp = xtx+Hptdi; + + % ** final conditional prior mean on A+i + alptd = zeros(ncoef,1); + alptd(1:nvar) = XX*A0b(stri,i); + %alptd = alptd + Hptdf*(H0tdi*A0hb); CAS efficiency improvement 8/8/96 + alptd = alptd + Hp0*A0hb; + % conditional on A0i, alpha-plus-tilde + + % * alpha_plus_* for the ith equation, ncoef*1 + % *alps = xxhp\(phi'*y*A0h(:,i)+HptdDinalptd); + HptdDinalptd=Hptdi*alptd; + xaha = cxy*A0h(:,i)+HptdDinalptd; %CAS 8/7/96. Replaced phi'*y with cxy + alpst = xaha'/xxhp; + GlbAph(i,:)=alpst; + % alpst': transpose of alps. + + A0hy = A0h(:,i)'*ymy; + A0hbH = A0hb'*H0tdi; + A0hcxyxx = A0h(:,i)'*cxyxx; + + %%%% + % *** passing the gradient to "pmdg6.m" (analytical gradient) + %%%% + % ** d1aya0 = d(alpha0'*Y'MY*alpha0)/d(a0??) + daya0 = 2.0*A0hy; + daya0 = daya0(:); + vaya0(stril+1:stril+strm) = daya0(stri); + + % ** daha0 = d((alpha0-alpha0_tilde)'*inv(H_0_tilde)* + % ** (alpha0-alpha0_tilde))/d(a0??) + daha0 = 2.0*A0hbH; + vaha0(stril+1:stril+strm) = daha0(:); + + % ** daxah = d(alpha_+^'*X'X*alpha_+^)/d(a0??) + % ** daxah = d(alpha_+^'*X'X*alpha_+^)/d(a0??) + %% daxah = 2*(Aph(:,i)'*xtx) * cxpy(:,stri); + %% vaxah(stril+1:stril+strm) = daxah'; + daxah = 2*A0hcxyxx; + daxah = daxah(:); + vaxah(stril+1:stril+strm) = daxah(stri); + + + % ** dahad = d(alpha_+~'*inv(H_+~)*alpha_+~)/d(a0??) + dahad = 2*HptdDinalptd' * Hp0; + % <<>> multiplications not used in "of" + vahad(stril+1:stril+strm) = dahad'; + + % ** dbiga = d((X'X*alpha_+^+inv(H_+~)*alpha_+*)'*a_+_*)/d(a0??) + dbiga = 2*alpst*(cxy(:,stri)+chhh); + % <<>> multiplications not used in "of" + vbiga(stril+1:stril+strm) = dbiga'; + + stril = stril + strm; +end + +%disp(sprintf('Loop %d end: %g', i, toc)) +disp(sprintf('Loop end (of): %g', toc)) + +g = zeros(nfp,1); + +%%%%%%% +%%% analytical gradient for A0 below +%%%%%%% +% +% ** dla0 = dlog|A0|/d(a0??) +vdla0 = zeros(na0p,1); +dla0 = inv(A0h)'; +dla0 = dla0(:); +vdla0 = dla0(a0indx); + +g = -fss*vdla0 + 0.5*vaya0 + 0.5*vaha0 + 0.5*vaxah + 0.5*vahad - 0.5*vbiga; + \ No newline at end of file diff --git a/MatlabFiles/PMDDF233.M b/MatlabFiles/PMDDF233.M new file mode 100755 index 0000000..c8a79fd --- /dev/null +++ b/MatlabFiles/PMDDF233.M @@ -0,0 +1,260 @@ +function of = pmddf233(x,idmat0,idmat1,fss,nvar,ncoef,phi, ... + y,A0b,sg0bid,sgpbid) +%function of = pmddf232(x,idmat,fss,nvar,ncoef,phi, ... +% y,A0b,sg0bid,sgpbid) +% Leeper-Sims-Zha BVAR setup +% general program to setup A0 matrix and compute the likelihood +% requires +% x (parameter vector) +% a0indx (matrix indicating the free parameters in A0) +% fss (forecast sample size) +% nvar (number of variables) +% ncoef (number of coefficients in a single equation in A+) +% phi (r.h.s. observations in the system for A+) +% y (l.h.s. observations for A0) +% A0b (initial prior mean on A0) +% sg0bid (diagonal of Sigma0_bar, unweighted prior vcv on the parameters in i-th equation in A0) +% sgpbid (diagonal of Sigma+_bar, unweighted prior vcv on the parameters in i-th equation in A+) +% +% Revisions by CAS 9/27/96: If we transmit idmat, rather than a0indx, we can scale the elements of +% idmat so that it carries information about relative prior variances. +global vaya0 vaha0 vaxah vahad vbiga GlbAph FRESHFUNCTION +% FRESHFUNCTION added 8/20/90 by CAS. It signals the pmddg23 whether the global variables +% it uses have been refreshed by a new pmddf231 call since the last gradient call. +a0indx=find(idmat0); +% pre-allocate GlbAph to be zeros(nvar,lags*nvar+1=ncoef) + +nhp = 0; % <<>> 4 hyperparameters +na0p = length(a0indx); % <<>> number of A0 parameters +nfp = na0p+nhp; + +% *** initializing +vaya0 = zeros(na0p,1); +vaha0 = zeros(na0p,1); +vaxah = zeros(na0p,1); +vahad = zeros(na0p,1); +vbiga = zeros(na0p,1); + + +A0h = zeros(nvar,nvar); +A0h(a0indx) = x(1:na0p); +%A0h = reshape(a0,nvar,nvar); CAS 9/24/96. The reshape is not necessary if a0 starts as nvar x nvar + % restrictions on A0 + +[A0hl,A0hu] = lu(A0h); + +% ** hyperparameters +%%mu = x(na0p+1:nfp); +mu = ones(5,1); +mu(1) = 1; +%mu(1) = 2; +mu(2) = 0.2; +mu(3) = 1; +%mu(4)=1; +mu(4)=1; +mu(5) =1; +%mu(5) = 40; +% results from ...\dummy1\foreh\pmdd6.out +% +% mu(1): overall tightness and also for A0; +% mu(2): relative tightness for A+; +% mu(3): relative tightness for the constant term; +% mu(4): weight on single dummy initial observation including constant; +% mu(5): weight on nvar sums of coeffs dummy observations. + +% ** weight prior dummy observations +%phi(1:nvar,:) = (mu(5)^2/mu(1)^2)*phi(1:nvar,:); +%y(1:nvar,:) = (mu(5)^2/mu(1)^2)*y(1:nvar,:); +%phi(ndobs,:) = mu +% modified by CAS 8/6/96. The dummy obs weights are naturally in std units, not var units. +phi(1:nvar,:) = mu(5)*phi(1:nvar,:); +y(1:nvar,:) = mu(5)*y(1:nvar,:); +phi(nvar+1,:) = mu(4)*phi(nvar+1,:); +y(nvar+1,:) = mu(4)*y(nvar+1,:); + +% ** set up the conditional prior variance sg0bi and sgpbi. +sg0bida = mu(1)^2*sg0bid; +sgpbida = mu(1)^2*mu(2)^2*sgpbid; +sgpbida(ncoef) = mu(1)^2*mu(3)^2; +sgppbd = sgpbida(nvar+1:ncoef); % corresponding to A++, in a SZ paper +sgppb = diag(sgppbd); + +% +% ** some common terms +[u d v]=svd(phi,0); %trial +% xtx = phi'*phi; %trial +vd=v.*(ones(size(v,2),1)*diag(d)'); %trial +xtx=vd*vd'; +% M = eye(fss) - phi*(xtx\phi'); % not used except in line below %trial +yu = y'*u; %trial +cxyxx=yu*yu'; %trial +ymy=y'*y-cxyxx; %trial +%ymy = y'*M*y; +%cxy = phi'*y; %trial +cxy = vd*yu'; %trial +%cxpy = xtx\cxy; %not used further except in line below +%cxyxx = cxy'*cxpy; + +% ** estimate A+_hat conditional on A0, ncoef*nvar, but not using full prior +%GlbAph = cxpy*A0h; + + +%%%%%%% +%%% build the objective function below +%%%%%%% +% +t1f = diag(abs(A0hu)); +t1f = log(t1f); +tt1 = (-1.0)*fss*sum(t1f); +% Commented out by TZ, 10/3/96, to allow the prior |A0|^k +%%tt1 = (-1.0)*(fss+ncoef)*sum(t1f); + +tt3 = 0; +tt4 = 0; + +disp(sprintf('Starting loop (of): %g',toc)) + +stril = 0; +Hp0p = zeros(ncoef); +% initializing Htd_+0*inv(Htd_00)*Htd_0+: conditional prior covariance +for i = 1:nvar + stri = find(idmat0(:,i)); %CAS change 9/24/96, to avoid slim chance of an exact zero in x vector + %at some point during an optimization. + strm = length(stri); + + A0hb = A0h(stri,i)-A0b(stri,i); + Hp0 = zeros(ncoef,strm); + % initializing Htd_+0*inv(Htd_00)*Htd_0 + + % ** set up the conditional prior variance sg0bi and sgpbi. + % sg0bd = zeros(stri,1); Commented out by CAS, 9/24/96. Looks like this meant to have + % strm where it has stri, and in any case it is "overwritten" below. + %------------------------------ + % Introduce prior information on which variables "belong" in various equations. + % In this first trial, we just introduce this information here, in a model-specific way. + % Eventually this info has to be passed parametricly. In our first shot, we just damp down + % all coefficients except those on the diagonal. + factor0=idmat0(:,i); + sg0bd = sg0bida(stri).*factor0(stri); + sg0b = diag(sg0bd); + % + factor1=idmat1(:,i); + sg1bd = sgpbida(1:nvar).*factor1; + sg1b = diag(sg1bd); + + % ** set up the unconditional prior variance on A0i and A+i + XX = zeros(nvar,strm); + XX(stri,:) = eye(strm); % XX in Gelman, etel, on p479 + % + Hb = zeros(strm+ncoef); % including A0i and A+i + Hb(1:strm,1:strm) = sg0b; + sg0bxx = sg0b*XX'; + Hb(1:strm,strm+1:strm+nvar) = sg0bxx; + %Hb(strm+1:strm+nvar,1:strm) = XX*sg0b; CAS 9/24/96. Saves a little multiplication by using line below. + Hb(strm+1:strm+nvar,1:strm) = sg0bxx'; + Hb(strm+1:strm+nvar,strm+1:strm+nvar) = XX*sg0bxx+sg1b; + Hb(strm+nvar+1:strm+ncoef,strm+nvar+1:strm+ncoef) = sgppb; + + % ** set up the final prior variance on A0i and A+i, i =1,..,6 separately. + % ** using dummy initial observations + %zs1 = [ys1(:,stri) -xd0]; % z*1 for the 1st equation + + % * final unconditional prior variance on A0i and A+i + %Hbzs1=Hb*zs1'; + %Htd = Hb - Hbzs1*((zs1*Hbzs1+mu(1)^2*mu(4)^2*eye(nvar))\Hbzs1'); + % CAS mod 8/7/96: Hope is that dropping above two lines in favor of the one below + % removes double-counting of dummy observations and a possible scale sensitivity. + Htd = Hb; + % H_~: td: tilde for ~ + + % * final conditional prior variance on A+i give that on A0i, and + % * unconditional variance on A0+ + H0td = Htd(1:strm,1:strm); % unconditional + % ** inverse and chol decomp + H0tdi = inv(H0td); + + % + Hptd10 = Htd(strm+1:strm+nvar,1:strm); + % top matrix of nvar in Htd_+0 + Hptd100 = Hptd10*H0tdi; + Hp0(1:nvar,:) = Hptd100; + Hptd101 = Hptd100*Hptd10'; + Hp0p(1:nvar,1:nvar) = Hptd101; + Hptd = Htd(strm+1:strm+ncoef,strm+1:strm+ncoef) - Hp0p; + % condtional on A0i, H_plus_tilde + + % ** inverse + Hptdi = inv(Hptd); + chhh = Hptdi*Hp0; % <<>> the term not used for "of" + + % common term + xxhp = xtx+Hptdi; + + % ** final conditional prior mean on A+i + alptd = zeros(ncoef,1); + alptd(1:nvar) = XX*A0b(stri,i); + %alptd = alptd + Hptdf*(H0tdi*A0hb); CAS efficiency improvement 8/8/96 + alptd = alptd + Hp0*A0hb; + % conditional on A0i, alpha-plus-tilde + + % * alpha_plus_* for the ith equation, ncoef*1 + % *alps = xxhp\(phi'*y*A0h(:,i)+HptdDinalptd); + HptdDinalptd=Hptdi*alptd; + xaha = cxy*A0h(:,i)+HptdDinalptd; %CAS 8/7/96. Replaced phi'*y with cxy + alpst = xaha'/xxhp; + GlbAph(i,:)=alpst; + % alpst': transpose of alps. + + % ** 3rd bid term in i-th equation, + % ** with all other 3rd big terms prior to i-th + A0hy = A0h(:,i)'*ymy; + A0hbH = A0hb'*H0tdi; + tt3 = tt3 + A0hy*A0h(:,i) + A0hbH*A0hb; + % ** 4th bid term in i-th equation, + % ** with all other 4th big terms prior to i-th + A0hcxyxx = A0h(:,i)'*cxyxx; + atdHatd = alptd'*HptdDinalptd; + tt4 = tt4 + A0hcxyxx*A0h(:,i)+atdHatd-alpst*xaha; + + %%%% + % *** passing the gradient to "pmdg6.m" (analytical gradient) + %%%% + % ** d1aya0 = d(alpha0'*Y'MY*alpha0)/d(a0??) + daya0 = 2.0*A0hy; + daya0 = daya0(:); + vaya0(stril+1:stril+strm) = daya0(stri); + + % ** daha0 = d((alpha0-alpha0_tilde)'*inv(H_0_tilde)* + % ** (alpha0-alpha0_tilde))/d(a0??) + daha0 = 2.0*A0hbH; + vaha0(stril+1:stril+strm) = daha0(:); + + % ** daxah = d(alpha_+^'*X'X*alpha_+^)/d(a0??) + % ** daxah = d(alpha_+^'*X'X*alpha_+^)/d(a0??) + %% daxah = 2*(Aph(:,i)'*xtx) * cxpy(:,stri); + %% vaxah(stril+1:stril+strm) = daxah'; + daxah = 2*A0hcxyxx; + daxah = daxah(:); + vaxah(stril+1:stril+strm) = daxah(stri); + + + % ** dahad = d(alpha_+~'*inv(H_+~)*alpha_+~)/d(a0??) + dahad = 2*HptdDinalptd' * Hp0; + % <<>> multiplications not used in "of" + vahad(stril+1:stril+strm) = dahad'; + + % ** dbiga = d((X'X*alpha_+^+inv(H_+~)*alpha_+*)'*a_+_*)/d(a0??) + dbiga = 2*alpst*(cxy(:,stri)+chhh); + % <<>> multiplications not used in "of" + vbiga(stril+1:stril+strm) = dbiga'; + + stril = stril + strm; +end + +%disp(sprintf('Loop %d end: %g', i, toc)) +disp(sprintf('Loop end (of): %g', toc)) + +%e_tfat = toc + +of = tt1 + 0.5*tt3 + 0.5*tt4; +FRESHFUNCTION=1; diff --git a/MatlabFiles/PMDDF234.M b/MatlabFiles/PMDDF234.M new file mode 100755 index 0000000..0a560d1 --- /dev/null +++ b/MatlabFiles/PMDDF234.M @@ -0,0 +1,243 @@ +function of = pmddf234(x,idmat0,idmat1,fss,nvar,ncoef,phi, ... + y,A0b,sg0bid,sgpbid) +%function of = pmddf232(x,idmat,fss,nvar,ncoef,phi, ... +% y,A0b,sg0bid,sgpbid) +% Leeper-Sims-Zha BVAR setup +% general program to setup A0 matrix and compute the likelihood +% requires +% x (parameter vector) +% a0indx (matrix indicating the free parameters in A0) +% fss (forecast sample size) +% nvar (number of variables) +% ncoef (number of coefficients in a single equation in A+) +% phi (r.h.s. observations in the system for A+) +% y (l.h.s. observations for A0) +% A0b (initial prior mean on A0) +% sg0bid (diagonal of Sigma0_bar, unweighted prior vcv on the parameters in i-th equation in A0) +% sgpbid (diagonal of Sigma+_bar, unweighted prior vcv on the parameters in i-th equation in A+) +% +% Revisions by CAS 9/27/96: If we transmit idmat, rather than a0indx, we can scale the elements of +% idmat so that it carries information about relative prior variances. +% +% Revsions by TZ, 10/12/96: efficiency improvement by streamlining the previous code +% according to the general setup in Sims and Zha "Bayesian Methods for ...". +% +global vaya0 vaha0 vaxah vahad vbiga GlbAph FRESHFUNCTION +% FRESHFUNCTION added 8/20/90 by CAS. It signals the pmddg23 whether the global variables +% it uses have been refreshed by a new pmddf231 call since the last gradient call. +a0indx=find(idmat0); +% pre-allocate GlbAph to be zeros(nvar,lags*nvar+1=ncoef) + +nhp = 0; % <<>> 4 hyperparameters +na0p = length(a0indx); % <<>> number of A0 parameters +nfp = na0p+nhp; + +% *** initializing +vaya0 = zeros(na0p,1); +vaha0 = zeros(na0p,1); +vaxah = zeros(na0p,1); +vahad = zeros(na0p,1); +vbiga = zeros(na0p,1); + + +A0h = zeros(nvar,nvar); +A0h(a0indx) = x(1:na0p); +%A0h = reshape(a0,nvar,nvar); CAS 9/24/96. The reshape is not necessary if a0 starts as nvar x nvar + % restrictions on A0 + +[A0hl,A0hu] = lu(A0h); + +% ** hyperparameters +%%mu = x(na0p+1:nfp); +mu = ones(5,1); +mu(1) = 1; +%mu(1) = 2; +mu(2) = 0.3; +mu(3) = 25; +%mu(4)=1; +mu(4)=1; +mu(5) =1; +%mu(5) = 40; +% results from ...\dummy1\foreh\pmdd6.out +% +% mu(1): overall tightness and also for A0; +% mu(2): relative tightness for A+; +% mu(3): relative tightness for the constant term; +% mu(4): weight on single dummy initial observation including constant; +% mu(5): weight on nvar sums of coeffs dummy observations. + +% ** weight prior dummy observations +%phi(1:nvar,:) = (mu(5)^2/mu(1)^2)*phi(1:nvar,:); +%y(1:nvar,:) = (mu(5)^2/mu(1)^2)*y(1:nvar,:); +%phi(ndobs,:) = mu +% modified by CAS 8/6/96. The dummy obs weights are naturally in std units, not var units. +%%phi(1:nvar,:) = mu(5)*phi(1:nvar,:); +%%y(1:nvar,:) = mu(5)*y(1:nvar,:); +%%phi(nvar+1,:) = mu(4)*phi(nvar+1,:); +%%y(nvar+1,:) = mu(4)*y(nvar+1,:); + +% ** set up the conditional prior variance sg0bi and sgpbi. +%%sg0bida = mu(1)^2*sg0bid; +sgpbida = mu(1)^2*mu(2)^2*sgpbid; +sgpbida(ncoef) = mu(1)^2*mu(3)^2; +sgppbd = sgpbida(nvar+1:ncoef); % corresponding to A++, in an SZ paper +sgppb = diag(sgppbd); + +% +% ** some common terms +[u d v]=svd(phi,0); %trial +% xtx = phi'*phi; %trial +vd=v.*(ones(size(v,2),1)*diag(d)'); %trial +xtx=vd*vd'; +% M = eye(fss) - phi*(xtx\phi'); % not used except in line below %trial +yu = y'*u; %trial +cxyxx=yu*yu'; %trial +ymy=y'*y-cxyxx; %trial +%ymy = y'*M*y; +%cxy = phi'*y; %trial +cxy = vd*yu'; %trial +%cxpy = xtx\cxy; %not used further except in line below +%cxyxx = cxy'*cxpy; + +% ** estimate A+_hat conditional on A0, ncoef*nvar, but not using full prior +%GlbAph = cxpy*A0h; + + +%%%%%%% +%%% build the objective function below +%%%%%%% +% +t1f = diag(abs(A0hu)); +t1f = log(t1f); +% * without the prior |A0|^k +tt1 = (-1.0)*fss*sum(t1f); + +tt3 = 0; +tt4 = 0; + +disp(sprintf('Starting loop (of): %g',toc)) + +stril = 0; +Hp0p = zeros(ncoef); +% initializing Htd_+0*inv(Htd_00)*Htd_0+: conditional prior covariance +for i = 1:nvar + stri = find(idmat0(:,i)); %CAS change 9/24/96, to avoid slim chance of an exact zero in x vector + %at some point during an optimization. + strm = length(stri); + + %%A0hb = A0h(stri,i)-A0b(stri,i); + + % ** set up the conditional prior variance sg0bi and sgpbi. + % sg0bd = zeros(stri,1); Commented out by CAS, 9/24/96. Looks like this meant to have + % strm where it has stri, and in any case it is "overwritten" below. + %------------------------------ + % Introduce prior information on which variables "belong" in various equations. + % In this first trial, we just introduce this information here, in a model-specific way. + % Eventually this info has to be passed parametricly. In our first shot, we just damp down + % all coefficients except those on the diagonal. + %%factor0=idmat0(:,i); + %%sg0bd = sg0bida(stri).*factor0(stri); + %%sg0b = diag(sg0bd); + % + factor1=idmat1(:,i); + sg1bd = sgpbida(1:nvar).*factor1; + sg1b = diag(sg1bd); + + % ** set up the unconditional prior variance on A0i and A+i + XX = zeros(nvar,strm); + XX(stri,:) = eye(strm); % XX in Gelman, etel, on p479 + % + % * final conditional prior variance on A+i give that on A0i, and + % * unconditional variance on A0+ + %%H0td = sg0b; % unconditional + % H_~: td: tilde for ~ + % ** inverse and chol decomp + %%H0tdi = inv(H0td); + + % + Hptd = zeros(ncoef); + Hptd(1:nvar,1:nvar)=sg1b; + Hptd(nvar+1:ncoef,nvar+1:ncoef)=sgppb; + % condtional on A0i, H_plus_tilde + + % ** inverse + Hptdi = inv(Hptd); + %%chhh=Hptdi*Hp0; + chhh = zeros(ncoef,strm); % <<>> the term not used for "of"\ + chhh(1:nvar,:) = Hptdi(1:nvar,1:nvar)*XX; + chhh1 = XX'*chhh(1:nvar,:); + + % common term + xxhp = xtx+Hptdi; + + % ** final conditional prior mean on A+i + alptd = zeros(ncoef,1); + alptd(1:nvar) = XX*A0h(stri,i); + % conditional on A0i, alpha-plus-tilde + + % * alpha_plus_* for the ith equation, ncoef*1 + % *alps = xxhp\(phi'*y*A0h(:,i)+HptdDinalptd); + %%HptdDinalptd=Hptdi*alptd; + HptdDinalptd=zeros(ncoef,1); + HptdDinalptd(1:nvar) = Hptdi(1:nvar,1:nvar)*alptd(1:nvar); + xaha = cxy*A0h(:,i)+HptdDinalptd; %CAS 8/7/96. Replaced phi'*y with cxy + alpst = xaha'/xxhp; + GlbAph(i,:)=alpst; + % alpst': transpose of alps. + + % ** 3rd bid term in i-th equation, + % ** with all other 3rd big terms prior to i-th + A0hy = A0h(:,i)'*ymy; + %%A0hbH = A0hb'*H0tdi; + %%tt3 = tt3 + A0hy*A0h(:,i) + A0hbH*A0hb; + tt3 = tt3 + A0hy*A0h(:,i); + % ** 4th bid term in i-th equation, + % ** with all other 4th big terms prior to i-th + A0hcxyxx = A0h(:,i)'*cxyxx; + %%atdHatd = alptd'*HptdDinalptd; % efficiency improvement + atdHatd = alptd(1:nvar)'*HptdDinalptd(1:nvar); + tt4 = tt4 + A0hcxyxx*A0h(:,i)+atdHatd-alpst*xaha; + + %%%% + % *** passing the gradient to "pmdg6.m" (analytical gradient) + %%%% + % ** d1aya0 = d(alpha0'*Y'MY*alpha0)/d(a0??) + daya0 = 2.0*A0hy; + daya0 = daya0(:); + vaya0(stril+1:stril+strm) = daya0(stri); + + % ** daha0 = d((alpha0-alpha0_tilde)'*inv(H_0_tilde)* + % ** (alpha0-alpha0_tilde))/d(a0??) + %%daha0 = 2.0*A0hbH; + %%vaha0(stril+1:stril+strm) = daha0(:); + + % ** daxah = d(alpha_+^'*X'X*alpha_+^)/d(a0??) + % ** daxah = d(alpha_+^'*X'X*alpha_+^)/d(a0??) + %% daxah = 2*(Aph(:,i)'*xtx) * cxpy(:,stri); + %% vaxah(stril+1:stril+strm) = daxah'; + daxah = 2*A0hcxyxx; + daxah = daxah(:); + vaxah(stril+1:stril+strm) = daxah(stri); + + + % ** dahad = d(alpha_+~'*inv(H_+~)*alpha_+~)/d(a0??) + dahad = 2*A0h(stri,i)'*chhh1; + % <<>> multiplications not used in "of" + vahad(stril+1:stril+strm) = dahad(:); + + + % ** dbiga = d((X'X*alpha_+^+inv(H_+~)*alpha_+*)'*a_+_*)/d(a0??) + dbiga = 2*alpst*(cxy(:,stri)+chhh); + % <<>> multiplications not used in "of" + vbiga(stril+1:stril+strm) = dbiga'; + + stril = stril + strm; +end + +%disp(sprintf('Loop %d end: %g', i, toc)) +disp(sprintf('Loop end (of): %g', toc)) + +%e_tfat = toc + +of = tt1 + 0.5*tt3 + 0.5*tt4; +FRESHFUNCTION=1; \ No newline at end of file diff --git a/MatlabFiles/PMDDG233.M b/MatlabFiles/PMDDG233.M new file mode 100755 index 0000000..2c58c0e --- /dev/null +++ b/MatlabFiles/PMDDG233.M @@ -0,0 +1,50 @@ +function [g,badg] = pmddg233(x,idmat0,idmat1,fss,nvar, ... + ncoef,phi,y,A0b,sg0bid,sgpbid); +% Leeper-Sims-Zha BVAR setup, analytical gradient for "csminwel.m" +% general program to setup A0 matrix and compute the likelihood +% requires x (parameter vector), a0indx (matrix indicating the free +% parameters in A0), fss (forecast sample size), nvar (number of variables), +% ncoef (number of coefficients in a single equation in A+), phi (r.h.s. +% observations in the system for A+), y (l.h.s. observations for A0), +% ymy (Y'*M*Y), xd0 (X(0) for dummy observations y*(1)), ys1 (dummy initial +% observations y*(1)), xtx (X'X or phi'*phi), A0b (initial prior on A0), +% sg0bid (diagonal of Sigma0_bar on the parameters in i-th equation in A0, +% initial prior covariace matrix), sgpbid (diagonal of Sigma+_bar on the +% parameters in i-th equation in A0, initial prior covariance matrix). +% +global vaya0 vaha0 vaxah vahad vbiga FRESHFUNCTION +% CAS added FRESHFUNCTION 8/20/96 to allow use of pmddg23 in a numerical Hessian calculation, where +% it is invoked repeatedly without new function evaluations. +if ~FRESHFUNCTION + fjnk = pmddf233(x,idmat0,idmat1,fss,nvar,ncoef,phi,y,A0b,sg0bid,sgpbid); +end +FRESHFUNCTION=0; +badg = 0; +% +a0indx=find(idmat0); +nhp = 0; % <<>> 4 hyperparameters +na0p = length(a0indx); % <<>> number of A0 parameters +nfp = na0p+nhp; +g = zeros(nfp,1); +A0h= zeros(nvar); +A0h(a0indx) = x(1:na0p); + % restrictions on A0 + +%disp(sprintf('Starting loop (gradient): %g',toc)) + + +%%%%%%% +%%% analytical gradient for A0 below +%%%%%%% +% +% ** dla0 = dlog|A0|/d(a0??) +vdla0 = zeros(na0p,1); +dla0 = inv(A0h)'; +dla0 = dla0(:); +vdla0 = dla0(a0indx); + +g = -fss*vdla0 + 0.5*vaya0 + 0.5*vaha0 + 0.5*vaxah + 0.5*vahad - 0.5*vbiga; +% Commented out by TZ, 10/3/96, to allow the prior |A0|^k +%%g = -(fss+ncoef)*vdla0 + 0.5*vaya0 + 0.5*vaha0 + 0.5*vaxah + 0.5*vahad - 0.5*vbiga; + +%disp(sprintf('Loop end (gradient): %g', toc)) \ No newline at end of file diff --git a/MatlabFiles/PMDDG234.M b/MatlabFiles/PMDDG234.M new file mode 100755 index 0000000..578c46e --- /dev/null +++ b/MatlabFiles/PMDDG234.M @@ -0,0 +1,49 @@ +function [g,badg] = pmddg234(x,idmat0,idmat1,fss,nvar, ... + ncoef,phi,y,A0b,sg0bid,sgpbid); +% Leeper-Sims-Zha BVAR setup, analytical gradient for "csminwel.m" +% general program to setup A0 matrix and compute the likelihood +% requires x (parameter vector), a0indx (matrix indicating the free +% parameters in A0), fss (forecast sample size), nvar (number of variables), +% ncoef (number of coefficients in a single equation in A+), phi (r.h.s. +% observations in the system for A+), y (l.h.s. observations for A0), +% ymy (Y'*M*Y), xd0 (X(0) for dummy observations y*(1)), ys1 (dummy initial +% observations y*(1)), xtx (X'X or phi'*phi), A0b (initial prior on A0), +% sg0bid (diagonal of Sigma0_bar on the parameters in i-th equation in A0, +% initial prior covariace matrix), sgpbid (diagonal of Sigma+_bar on the +% parameters in i-th equation in A0, initial prior covariance matrix). +% +global vaya0 vaha0 vaxah vahad vbiga FRESHFUNCTION +% CAS added FRESHFUNCTION 8/20/96 to allow use of pmddg23 in a numerical Hessian calculation, where +% it is invoked repeatedly without new function evaluations. +if ~FRESHFUNCTION + fjnk = pmddf234(x,idmat0,idmat1,fss,nvar,ncoef,phi,y,A0b,sg0bid,sgpbid); +end +FRESHFUNCTION=0; +badg = 0; +% +a0indx=find(idmat0); +nhp = 0; % <<>> 4 hyperparameters +na0p = length(a0indx); % <<>> number of A0 parameters +nfp = na0p+nhp; +g = zeros(nfp,1); +A0h= zeros(nvar); +A0h(a0indx) = x(1:na0p); + % restrictions on A0 + +%disp(sprintf('Starting loop (gradient): %g',toc)) + + +%%%%%%% +%%% analytical gradient for A0 below +%%%%%%% +% +% ** dla0 = dlog|A0|/d(a0??) +vdla0 = zeros(na0p,1); +dla0 = inv(A0h)'; +dla0 = dla0(:); +vdla0 = dla0(a0indx); + +% without the prior |A0|^k +g = -fss*vdla0 + 0.5*vaya0 + 0.5*vaha0 + 0.5*vaxah + 0.5*vahad - 0.5*vbiga; + +%disp(sprintf('Loop end (gradient): %g', toc)) \ No newline at end of file diff --git a/MatlabFiles/PWF233.M b/MatlabFiles/PWF233.M new file mode 100755 index 0000000..ee1ea7e --- /dev/null +++ b/MatlabFiles/PWF233.M @@ -0,0 +1,224 @@ +function of = pwf233(x,idmat0,idmat1,fss,nvar,ncoef,phi, ... + y,A0b,sg0bid,sgpbid) +%function of = pmddf232(x,idmat,fss,nvar,ncoef,phi, ... +% y,A0b,sg0bid,sgpbid) +% Leeper-Sims-Zha BVAR setup +% general program to setup A0 matrix and compute the likelihood +% requires +% x (parameter vector) +% a0indx (matrix indicating the free parameters in A0) +% fss (forecast sample size) +% nvar (number of variables) +% ncoef (number of coefficients in a single equation in A+) +% phi (r.h.s. observations in the system for A+) +% y (l.h.s. observations for A0) +% A0b (initial prior mean on A0) +% sg0bid (diagonal of Sigma0_bar, unweighted prior vcv on the parameters in i-th equation in A0) +% sgpbid (diagonal of Sigma+_bar, unweighted prior vcv on the parameters in i-th equation in A+) +% +% Revisions by CAS 9/27/96: If we transmit idmat, rather than a0indx, we can scale the elements of +% idmat so that it carries information about relative prior variances. +global vaya0 vaha0 vaxah vahad vbiga GlbAph FRESHFUNCTION +% FRESHFUNCTION added 8/20/90 by CAS. It signals the pmddg23 whether the global variables +% it uses have been refreshed by a new pmddf231 call since the last gradient call. +a0indx=find(idmat0); +% pre-allocate GlbAph to be zeros(nvar,lags*nvar+1=ncoef) + +nhp = 0; % <<>> 4 hyperparameters +na0p = length(a0indx); % <<>> number of A0 parameters +nfp = na0p+nhp; + +% *** initializing +vaya0 = zeros(na0p,1); +vaha0 = zeros(na0p,1); +vaxah = zeros(na0p,1); +vahad = zeros(na0p,1); +vbiga = zeros(na0p,1); + + +A0h = zeros(nvar,nvar); +A0h(a0indx) = x(1:na0p); +%A0h = reshape(a0,nvar,nvar); CAS 9/24/96. The reshape is not necessary if a0 starts as nvar x nvar + % restrictions on A0 + +[A0hl,A0hu] = lu(A0h); + +% ** hyperparameters +%%mu = x(na0p+1:nfp); +mu = ones(5,1); +mu(1) = 1; +%mu(1) = 2; +mu(2) = 0.2; +mu(3) = 1; +%mu(4)=1; +mu(4)=1; +mu(5) =1; +%mu(5) = 40; +% results from ...\dummy1\foreh\pmdd6.out +% +% mu(1): overall tightness and also for A0; +% mu(2): relative tightness for A+; +% mu(3): relative tightness for the constant term; +% mu(4): weight on single dummy initial observation including constant; +% mu(5): weight on nvar sums of coeffs dummy observations. + +% ** weight prior dummy observations +%phi(1:nvar,:) = (mu(5)^2/mu(1)^2)*phi(1:nvar,:); +%y(1:nvar,:) = (mu(5)^2/mu(1)^2)*y(1:nvar,:); +%phi(ndobs,:) = mu +% modified by CAS 8/6/96. The dummy obs weights are naturally in std units, not var units. +phi(1:nvar,:) = mu(5)*phi(1:nvar,:); +y(1:nvar,:) = mu(5)*y(1:nvar,:); +phi(nvar+1,:) = mu(4)*phi(nvar+1,:); +y(nvar+1,:) = mu(4)*y(nvar+1,:); + +% ** set up the conditional prior variance sg0bi and sgpbi. +sg0bida = mu(1)^2*sg0bid; +sgpbida = mu(1)^2*mu(2)^2*sgpbid; +sgpbida(ncoef) = mu(1)^2*mu(3)^2; +sgppbd = sgpbida(nvar+1:ncoef); % corresponding to A++, in a SZ paper +sgppb = diag(sgppbd); + +% +% ** some common terms +[u d v]=svd(phi,0); %trial +% xtx = phi'*phi; %trial +vd=v.*(ones(size(v,2),1)*diag(d)'); %trial +xtx=vd*vd'; +% M = eye(fss) - phi*(xtx\phi'); % not used except in line below %trial +yu = y'*u; %trial +cxyxx=yu*yu'; %trial +ymy=y'*y-cxyxx; %trial +%ymy = y'*M*y; +%cxy = phi'*y; %trial +cxy = vd*yu'; %trial +%cxpy = xtx\cxy; %not used further except in line below +%cxyxx = cxy'*cxpy; + +% ** estimate A+_hat conditional on A0, ncoef*nvar, but not using full prior +%GlbAph = cxpy*A0h; + + +%%%%%%% +%%% build the objective function below +%%%%%%% +% +t1f = diag(abs(A0hu)); +t1f = log(t1f); +tt1 = (-1.0)*fss*sum(t1f); + +tt3 = 0; +tt4 = 0; + +stril = 0; +Hp0p = zeros(ncoef); +% initializing Htd_+0*inv(Htd_00)*Htd_0+: conditional prior covariance +for i = 1:nvar + stri = find(idmat0(:,i)); %CAS change 9/24/96, to avoid slim chance of an exact zero in x vector + %at some point during an optimization. + strm = length(stri); + + A0hb = A0h(stri,i)-A0b(stri,i); + Hp0 = zeros(ncoef,strm); + % initializing Htd_+0*inv(Htd_00)*Htd_0 + + % ** set up the conditional prior variance sg0bi and sgpbi. + % sg0bd = zeros(stri,1); Commented out by CAS, 9/24/96. Looks like this meant to have + % strm where it has stri, and in any case it is "overwritten" below. + %------------------------------ + % Introduce prior information on which variables "belong" in various equations. + % In this first trial, we just introduce this information here, in a model-specific way. + % Eventually this info has to be passed parametricly. In our first shot, we just damp down + % all coefficients except those on the diagonal. + factor0=idmat0(:,i); + sg0bd = sg0bida(stri).*factor0(stri); + sg0b = diag(sg0bd); + % + factor1=idmat1(:,i); + sg1bd = sgpbida(1:nvar).*factor1; + sg1b = diag(sg1bd); + + % ** set up the unconditional prior variance on A0i and A+i + XX = zeros(nvar,strm); + XX(stri,:) = eye(strm); % XX in Gelman, etel, on p479 + % + Hb = zeros(strm+ncoef); % including A0i and A+i + Hb(1:strm,1:strm) = sg0b; + sg0bxx = sg0b*XX'; + Hb(1:strm,strm+1:strm+nvar) = sg0bxx; + %Hb(strm+1:strm+nvar,1:strm) = XX*sg0b; CAS 9/24/96. Saves a little multiplication by using line below. + Hb(strm+1:strm+nvar,1:strm) = sg0bxx'; + Hb(strm+1:strm+nvar,strm+1:strm+nvar) = XX*sg0bxx+sg1b; + Hb(strm+nvar+1:strm+ncoef,strm+nvar+1:strm+ncoef) = sgppb; + + % ** set up the final prior variance on A0i and A+i, i =1,..,6 separately. + % ** using dummy initial observations + %zs1 = [ys1(:,stri) -xd0]; % z*1 for the 1st equation + + % * final unconditional prior variance on A0i and A+i + %Hbzs1=Hb*zs1'; + %Htd = Hb - Hbzs1*((zs1*Hbzs1+mu(1)^2*mu(4)^2*eye(nvar))\Hbzs1'); + % CAS mod 8/7/96: Hope is that dropping above two lines in favor of the one below + % removes double-counting of dummy observations and a possible scale sensitivity. + Htd = Hb; + % H_~: td: tilde for ~ + + % * final conditional prior variance on A+i give that on A0i, and + % * unconditional variance on A0+ + H0td = Htd(1:strm,1:strm); % unconditional + % ** inverse and chol decomp + H0tdi = inv(H0td); + + % + Hptd10 = Htd(strm+1:strm+nvar,1:strm); + % top matrix of nvar in Htd_+0 + Hptd100 = Hptd10*H0tdi; + Hp0(1:nvar,:) = Hptd100; + Hptd101 = Hptd100*Hptd10'; + Hp0p(1:nvar,1:nvar) = Hptd101; + Hptd = Htd(strm+1:strm+ncoef,strm+1:strm+ncoef) - Hp0p; + % condtional on A0i, H_plus_tilde + + % ** inverse + Hptdi = inv(Hptd); + chhh = Hptdi*Hp0; % <<>> the term not used for "of" + + % common term + xxhp = xtx+Hptdi; + + % ** final conditional prior mean on A+i + alptd = zeros(ncoef,1); + alptd(1:nvar) = XX*A0b(stri,i); + %alptd = alptd + Hptdf*(H0tdi*A0hb); CAS efficiency improvement 8/8/96 + alptd = alptd + Hp0*A0hb; + % conditional on A0i, alpha-plus-tilde + + % * alpha_plus_* for the ith equation, ncoef*1 + % *alps = xxhp\(phi'*y*A0h(:,i)+HptdDinalptd); + HptdDinalptd=Hptdi*alptd; + xaha = cxy*A0h(:,i)+HptdDinalptd; %CAS 8/7/96. Replaced phi'*y with cxy + alpst = xaha'/xxhp; + GlbAph(i,:)=alpst; + % alpst': transpose of alps. + + % ** 3rd bid term in i-th equation, + % ** with all other 3rd big terms prior to i-th + A0hy = A0h(:,i)'*ymy; + A0hbH = A0hb'*H0tdi; + tt3 = tt3 + A0hy*A0h(:,i) + A0hbH*A0hb; + % ** 4th bid term in i-th equation, + % ** with all other 4th big terms prior to i-th + A0hcxyxx = A0h(:,i)'*cxyxx; + atdHatd = alptd'*HptdDinalptd; + tt4 = tt4 + A0hcxyxx*A0h(:,i)+atdHatd-alpst*xaha; + + + stril = stril + strm; +end + +%disp(sprintf('Loop %d end: %g', i, toc)) +%e_tfat = toc + +of = tt1 + 0.5*tt3 + 0.5*tt4; +FRESHFUNCTION=1; + \ No newline at end of file diff --git a/MatlabFiles/SRestrictRWZalg.m b/MatlabFiles/SRestrictRWZalg.m new file mode 100755 index 0000000..e0aae5c --- /dev/null +++ b/MatlabFiles/SRestrictRWZalg.m @@ -0,0 +1,145 @@ +function Q = SRestrictRWZalg(A0hatinv,Bhat,nvar,lags,irs) +% Rubio-Waggoner-Zha (RWZ) method of sign restrictions. For related methods, see Canova, Faust, and Uhlig. +% The detailed theoretical foundation of this algorithm can be found in Theorem 3 of Rubio, Waggoner, and Zha (RWZ)'s article "Regime Changes in the Euro Area." +% Other M functions called by this function can be downloaded by clicking on Archived Matlab Library ZhaZippedCode on http://home.earthlink.net/~tzha02/programCode.html +% Strcutural VAR form: Y*A0hat = X*Aphat + E, X where Y is T-by-nvar, A0hat is nvar-by-nvar, X is T-by-k (including the constant term and all other exogenous terms), +% Aphat is k-by-nvar, and E is T-by-nvar. Rows are in the order of 1st lag (with nvar variables) to lags (with nvar variables) plus the exogenous terms. +% Note that columns of A0hat or Aphat correspond to equations. +% Inputs: +% A0hatinv = inv(A0hat). +% Bhat = Aphat*inv(A0hat). +% nvar = number of endogenous variables. +% lags = lag length. +% irs = maximum number of periods in which sign restrictions are imposed. +% Outputs: +% Q: orthogonal rotation matrix so that Q*A0hatinv or A0hat*Q' gives impulse responses that will satisfy +% sign restrictions of Canova, Faust, and Uhlig. +% +% Modified Nov 2004 by T. Zha to +% (1) correct the existing bugs; +% (2) make the signs explicit to avoid the normalization problem when computing error bands; +% (3) construct efficient way (i.e., earlier exit) to make all restrictions satisfied; +% (4) construct efficient way to normalize. +% In this example, we have +% Variables are in the following order: 1: y; 2: P; 3: R; 4: M3; 5: Exec (per $). +% Shocks are in the following order: 1: AS; 2: AD; 3: MP; 4: MD; 5: Exec. +% +% Copyright (c) Rubio, Waggoner, and Zha, 2005. + + +nn = [nvar lags irs]; +control=0; + + +Q=eye(nvar); + +while control==0 + newmatrix=normrnd(0,1,nvar,nvar); + [Q,R]=qr(newmatrix); + for i=1:nvar; + if R(i,i)<0 + Q(:,i)=-Q(:,i); + end + end + imfhat = fn_impulse(Bhat,Q*A0hatinv,nn); + %In the form that is congenial to RATS + imf3hat=reshape(imfhat,size(imfhat,1),nvar,nvar); + %imf3hat: row--steps, column--nvar responses, 3rd dimension--nvar shocks + + %=== Responses to a moneaty policy (MP) shock. + % R>0, M<0, y<0, and P<0 for the irs periods. + a = (imf3hat(1:irs,3,3) > 0) .* (imf3hat(1:irs,4,3) < 0) .* (imf3hat(1:irs,1,3) < 0) .* (imf3hat(1:irs,2,3) < 0); + if (max(a)==0) + %--- Swiching the sign of the shock. + am = (imf3hat(1:irs,3,3) < 0) .* (imf3hat(1:irs,4,3) > 0) .* (imf3hat(1:irs,1,3) > 0) .* (imf3hat(1:irs,2,3) > 0); + if (min(am)==0) + continue; %The restrictions are not satisfied. Go the beginning to redraw. + else + %--- Normalizing according to the switched sign. + Q(3,:) = -Q(3,:); + end + elseif (min(a)==0) + continue; %The restrictions are not satisfied. Go the beginning to redraw. + end + %--- R>0 and M<0 for the irs periods. + % a = (imf3hat(1:irs,3,3) > 0) .* (imf3hat(1:irs,4,3) < 0); + % if (max(a)==0) + % %--- Swiching the sign of the shock. + % am = (imf3hat(1:irs,3,3) < 0) .* (imf3hat(1:irs,4,3) > 0); + % if (min(am)==0) + % continue; %The restrictions are not satisfied. Go the beginning to redraw. + % else + % %--- Normalizing according to the switched sign. + % Q(3,:) = -Q(3,:); + % end + % elseif (min(a)==0) + % continue; %The restrictions are not satisfied. Go the beginning to redraw. + % end + + %=== Responses to an money demand (MD) shock. + % R>0 and M>0 for the irs periods. + a = (imf3hat(1:irs,3,4) > 0) .* (imf3hat(1:irs,4,4) > 0); + if (max(a)==0) + %--- Swiching the sign of the shock and normalize. + am = (imf3hat(1:irs,3,4) < 0) .* (imf3hat(1:irs,4,4) < 0); + if (min(am)==0) + continue; %The restrictions are not satisfied. Go the beginning to redraw. + else + %--- Normalizing according to the switched sign. + Q(4,:) = -Q(4,:); + end + elseif (min(a)==0) + continue; %The restrictions are not satisfied. Go the beginning to redraw. + end + + %=== Responses to an aggregate demand (AD) shock. + % P>0 and y>0 for the irs periods. + a = (imf3hat(1:irs,1,2) > 0) .* (imf3hat(1:irs,2,2) > 0); + if (max(a)==0) + %--- Swiching the sign of the shock and normalize. + am = (imf3hat(1:irs,1,2) < 0) .* (imf3hat(1:irs,2,2) < 0); + if (min(am)==0) + continue; %The restrictions are not satisfied. Go the beginning to redraw. + else + %--- Normalizing according to the switched sign. + Q(2,:) = -Q(2,:); + end + elseif (min(a)==0) + continue; %The restrictions are not satisfied. Go the beginning to redraw. + end + + %=== Responses to an aggregate supply (AS) shock. + % P>0 and y<0 for the irs periods. + a = (imf3hat(1:irs,1,1) < 0) .* (imf3hat(1:irs,2,1) > 0); + if (max(a)==0) + %--- Swiching the sign of the shock and normalize. + am = (imf3hat(1:irs,1,1) > 0) .* (imf3hat(1:irs,2,1) < 0); + if (min(am)==0) + continue; %The restrictions are not satisfied. Go the beginning to redraw. + else + %--- Normalizing according to the switched sign. + Q(1,:) = -Q(1,:); + end + elseif (min(a)==0) + continue; %The restrictions are not satisfied. Go the beginning to redraw. + end + + %=== Responses to an exchange-rate shock (depreciation ==> exports >0 ==> y>0); + % Ex>0 and y>0 for the irs periods. + a= (imf3hat(1:irs,1,5) > 0) .* (imf3hat(1:irs,5,5) > 0); + if (max(a)==0) + %--- Swiching the sign of the shock and normalize. + am = (imf3hat(1:irs,1,5) < 0) .* (imf3hat(1:irs,5,5) < 0); + if (min(am)==0) + continue; %The restrictions are not satisfied. Go the beginning to redraw. + else + %--- Normalizing according to the switched sign. + Q(5,:) = -Q(5,:); + end + elseif (min(a)==0) + continue; %The restrictions are not satisfied. Go the beginning to redraw. + end + + %--- Terminating condition: all restrictions are satisfied. + control=1; +end diff --git a/MatlabFiles/SYE.M b/MatlabFiles/SYE.M new file mode 100755 index 0000000..498ac9b --- /dev/null +++ b/MatlabFiles/SYE.M @@ -0,0 +1,84 @@ +function [Bh,e,xtx,xty,phi,y,ncoe,xr] = sye(z,lags) +% Now [Bh,e,xtx,xty,phi,y,ncoe,xr] = sye(z,lags) +% Old: [Bh,e,xtx,xty,phi,y,ncoe,Sigu,xtxinv] = sye(z,lags) +% +% Estimate a system of equations in the form of y(T*nvar) = XB + u, +% X--phi: T*k, B: k*nvar; where T=sp-lags, k=ncoe, +% +% z: (T+lags)-by-(nvar+1) raw data matrix (nvar of variables + constant). +% lags: number of lags +%-------------------- +% Bh: k-by-nvar estimated reduced-form parameter; column: nvar; +% row: k=ncoe=[nvar for 1st lag, ..., nvar for last lag, const] +% e: estimated residual e = y -xBh, T-by-nvar +% xtx: X'X: k-by-k +% xty: X'Y: k-by-nvar +% phi: X; T-by-k; column: [nvar for 1st lag, ..., nvar for last lag, const] +% y: Y: T-by-nvar +% ncoe: number of coeffcients per equation: nvar*lags + 1 +% xr: the economy size (k-by-k) in qr(phi) so that xr=chol(X'*X) +% Sigu: e'*e: nvar-by-nvar. Note, not divided (undivided) by "nobs" +% xtxinv: inv(X'X): k-by-k +% +% See also syed.m (allowing for more predetermined terms) which has not +% been yet updated as "sye.m". +% +% Note, "lags" is something I changed recently, so it may not be compatible +% with old programs, 10/15/98 by TAZ. +% +% Revised, 5/2/99. Replaced outputs Sigu and xtxinv with xr so that previous +% programs may be incompatible. + + +% ** setup of orders and lengths ** +[sp,nvar] = size(z); % sp: sample period T include lags +nvar = nvar-1; % -1: takes out the counting of constant + +ess = sp-lags; % effective sample size +sb = lags+1; % sample beginning +sl = sp; % sample last period +ncoe = nvar*lags + 1; % with constant + +% ** construct X for Y = X*B + U where phi = X ** +x = z(:,1:nvar); +C = z(:,nvar+1); +phi = zeros(ess,ncoe); +phi(:,ncoe) = C(1:ess); +for k=1:lags, phi(:,nvar*(k-1)+1:nvar*k) = x(sb-k:sl-k,:); end +% row: T-lags; column: [nvar for 1st lag, ..., nvar for last lag, const] +% Thus, # of columns is nvar*lags+1 = ncoef. +% ** estimate: B, XTX, residuals ** +y = x(sb:sl,:); +% +%**** The following, though stable, is too slow ***** +% [u d v]=svd(phi,0); %trial +% %xtx = phi'*phi; % X'X, k*k (ncoe*ncoe) +% vd=v.*(ones(size(v,2),1)*diag(d)'); %trial +% dinv = 1./diag(d); % inv(diag(d)) +% vdinv=v.*(ones(size(v,2),1)*dinv'); %trial +% xtx=vd*vd'; +% xtxinv = vdinv*vdinv'; +% %xty = phi'*y; % X'Y +% uy = u'*y; %trial +% xty = vd*uy; %trial +% %Bh = xtx\xty; %inv(X'X)*(X'Y), k*m (ncoe*nvar). +% Bh = xtxinv*xty; +% %e = y - phi*Bh; % from Y = XB + U, e: (T-lags)*nvar +% e = y - u*uy; +%**** The following, though stable, is too slow ***** + +%===== (Fast but perhaps less accurate) alternative to the above ========= +[xq,xr]=qr(phi,0); +xtx=xr'*xr; +xty=phi'*y; +Bh = xr\(xr'\xty); +e=y-phi*Bh; +%===== (Fast but perhaps less accurate) alternative to the above ========= + + +%* not numerically stable way of computing e'*e +%Sigu = y'*y-xty'*Bh; +%Sigu = y'*(eye(ess)-phi*xtxinv*phi')*y; % probablly better way, commented out + % by TZ, 2/28/98. See following +%Sigu = y'*(eye(ess)-u*u')*y; % I think this is the best, TZ, 2/28/98 + % Note, u*u'=x*inv(x'x)*x. diff --git a/MatlabFiles/SYED.M b/MatlabFiles/SYED.M new file mode 100755 index 0000000..dc6c276 --- /dev/null +++ b/MatlabFiles/SYED.M @@ -0,0 +1,68 @@ +function [Bh,e,xtx,phi,y] = syed(z,nn) +% syed: estimate a system of equations: [Bh,e,xtx,phi,y] = syed(z,nn) +% Y((T-lags)*nvar) = XB + u, X: (T-lags)*k, B: k*nvar. +% where z is the T*(nvar+ndt) raw data matrix (nvar of variables + +% ndt -- number of deterministic terms); +% nn is 5 inputs [auindx, ndt, nvar,lags,sample period (total)]; +% auindx = 0 (no autoregressive) and 1 (autoregressive); +% total -- including lags, etc. +% Bh: the estimated B; column: nvar; row: [nvar for 1st lag, ..., +% nvar for last lag, deterministic terms (ndt)] +% e: estimated residual e = y -xBh, (T-lags)*nvar +% xtx: X'X +% phi: X; column: [nvar for 1st lag, ..., +% nvar for last lag, deterministic terms (ndt)] +% y: Y +% +% See also "sye.m". + +% ** setup of orders and lengths ** +auindx = nn(1); +ndt = nn(2); % # of deterministic terms including constant +nvar = nn(3); % # of endogenous variables +lags = nn(4); +sp = nn(5); % sample period + +ess = sp-lags; % effective sample size +sb = lags+1; % sample beginning +sl = sp; % sample last period + +% ** construct X for Y = X*B + U where phi = X ** +x = z(:,1:nvar); +C = z(:,nvar+1:nvar+ndt); % C = [] when ndt=0 +% +if auindx == 0 + ncoe = ndt; % with deterministic terms + phi = zeros(sp,ncoe); % preallocating + y = x; +else + y = x(sb:sl,:); + ncoe = nvar*lags + ndt; % with deterministic terms + phi = zeros(ess,ncoe); % preallocating + for k=1:lags, phi(:,nvar*(k-1)+1:nvar*k) = x(sb-k:sl-k,:); end +end +% +if length(C) == 0 + phi(:,ncoe-ndt+1:ncoe) = C; +else + phi(:,ncoe-ndt+1:ncoe) = C(1:sp,:); % perhaps, it should have been be C(sb:sp,:). 2/24/00 +end +% +% row: T-lags; column: [nvar for 1st lag, ..., nvar for last lag, +% deterministic terms (ndt)] +% Thus, # of columns is nvar*lags+ndt = ncoe. +% ** estimate: B, XTX, residuals ** +[u d v]=svd(phi,0); %trial +%xtx = phi'*phi; % X'X, k*k (ncoe*ncoe) +vd=v.*(ones(size(v,2),1)*diag(d)'); %trial +dinv = 1./diag(d); % inv(diag(d)) +vdinv=v.*(ones(size(v,2),1)*dinv'); %trial +xtx=vd*vd'; +xtxinv = vdinv*vdinv'; +%xty = phi'*y; % X'Y +uy = u'*y; %trial +xty = vd*uy; %trial +%Bh = xtx\xty; %inv(X'X)*(X'Y), k*m (ncoe*nvar). +Bh = xtxinv*xty; +%e = y - phi*Bh; % from Y = XB + U, e: (T-lags)*nvar +e = y - u*uy; diff --git a/MatlabFiles/Smtplis2seq.m b/MatlabFiles/Smtplis2seq.m new file mode 100755 index 0000000..36a91f7 --- /dev/null +++ b/MatlabFiles/Smtplis2seq.m @@ -0,0 +1,99 @@ +function [Avhx,AvhxD,hAvhx,hAvhxD,cJump,hAvhh] = smtplis2seq(Avhx,AvhxD,hAvhx,hAvhxD,... + A0xhat,tdf,cJump,scf,H_sr,nfp,Sbd,fss,nvar,a0indx,hAvhh) +% [Avhx,AvhxD,hAvhx,hAvhxD,cJump,hAvhh] = smtplis2(Avhx,AvhxD,hAvhx,hAvhxD,... +% A0xhat,tdf,cJump,scf,H_sr,nfp,Sbd,fss,nvar,a0indx,hAvhh) +% Straight Metropolis Algorithm for identified VARs with 2 parallel sequences +% +% Avhx: previous draw of parameter x in 1st (kept) sequence +% AvhxD: previous draw of parameter x in 2nd (discarded) sequence +% hAvhx: lh value of previous draw in 1st (kept) sequence +% hAvhxD: lh vlaue of previous draw in 2nd (discarded) sequence +% A0xhat: ML estimate of A0 +% tdf: degrees of freedom of the jump t-distribution +% cJump: old count for times of jumping +% scf: scale down factor for stand. dev. -- square root of covariance matrix H +% H_sr: square root of covariance matrix H +% nfp: number of free parameters +% Sbd: S in block diagonal covariance matrix in asymmetric prior case +% fss: effective sample size +% nvar: number of variables +% a0indx: index of locations of free elements in A0 +% hAvhh: highest point of lh +%-------------- +% Avhx: new draw of parameter x in 1st (kept) sequence +% AvhxD: new draw of parameter x in 2nd (discarded) sequence +% hAvhx: lh value of new draw in 1st (kept) sequence +% AvhxD: lh vlaue of new draw in 2nd (discarded) sequence +% cJump: new count for times of jumping +% hAvhh: highest point of lh +% +% November 1998 by Tao Zha + +if ~(fix(tdf)-tdf==0) + warning('tdf in msstart.m must be integer for drawing chi^2 from normal') + disp('press ctrl-c to abort') + pause +end + +for k=1:2 % parallel sequences; 2nd to be discarded + %** draw free elements Avh in A0 and hyperparameters from t-dist + %gsg = gamrnd(ga,gb); % G-sigma from Gamma draw + %Avhz = (1/sqrt(gsg))*(scf*H_sr*randn(nfp,1)); + % scf is used to control the acceptance ratio -- countJump + Avhz1 = scf*H_sr*randn(nfp,1); % normal draws + %Avhz1 = 2*randn(nfp,1); % normal draws + csq=randn(tdf,1); + csq=sum(csq .* csq); + Avhz = Avhz1/sqrt(csq/tdf); + + if (k==1) + Avhy = Avhx + Avhz; % random walk chain -- Metropolis + else + Avhy = AvhxD + Avhz; % random walk chain -- Metropolis + end + + % ** actual density, having taken log + hAvhy = a0asfun(Avhy,Sbd,fss,nvar,a0indx); + hAvhy = -hAvhy; % converted to logLH + + if (k==1) + mphxy = exp(hAvhy-hAvhx); + else + mphxy = exp(hAvhy-hAvhxD); + end + + %** draw u from uniform(0,1) + u = rand(1); + Jump = min([mphxy 1]); + if u <= Jump + %** Normalization: get the point that is nearest to axhat or A0xhat + Atem=zeros(nvar); + Atem(a0indx) = Avhy; + Adiff = (Atem - A0xhat).^2; + % distance that may be far from axhat or A0xhat + Adiffn = (-Atem - A0xhat).^2; + % distance by chaning the sign of Atem + cAdiff = sum(Adiff); % each column summed up + cAdiffn = sum(Adiffn); % each column summed up + cAindx = find(cAdiffn<cAdiff); % index for shorter distance + Atemn = Atem; + Atemn(:,cAindx) = -Atem(:,cAindx); + % find the shortest or nearest distance + %** get the value of logPoster or logLH + Avhy = Atemn(a0indx); + % + + if (k==1) + Avhx = Avhy; + hAvhx = hAvhy; + if hAvhy > hAvhh + hAvhh = hAvhy; + Avhh = Avhy; + end + cJump = cJump+1; + else + AvhxD = Avhy; + hAvhxD = hAvhy; + end + end +end \ No newline at end of file diff --git a/MatlabFiles/ZIMPULSE.M b/MatlabFiles/ZIMPULSE.M new file mode 100755 index 0000000..a158474 --- /dev/null +++ b/MatlabFiles/ZIMPULSE.M @@ -0,0 +1,55 @@ +function imf = zimpulse(Bh,swish,nn) +% Computing impulse functions with +% imf = zimpulse(Bh,swish,nn) +% where imf is in a format that is the SAME as in RATS. +% Column: nvar responses to 1st shock, +% nvar responses to 2nd shock, and so on. +% Row: steps of impulse responses. +% Bh is the estimated reduced form coefficient in the form +% Y(T*nvar) = XB + U, X: T*k, B: k*nvar. The matrix +% form or dimension is the same as "Bh" from the function "sye"; +% swish is the inv(A0) in the structural model A(L)y(t) = e(t). +% nn is the numbers of inputs [nvar,lags,# of impulse responses]. +% Written by Tao Zha +% +% Copyright (c) 1994 by Tao Zha + +nvar = nn(1); +lags = nn(2); +imstep = nn(3); % number of steps for impulse responses + +Ah = Bh'; +% Row: nvar equations +% Column: 1st lag (with nvar variables) to lags (with nvar variables) + const = k. + +imf = zeros(imstep,nvar*nvar); +% Column: nvar responses to 1st shock, nvar responses to 2nd shock, and so on. +% Row: steps of impulse responses. +M = zeros(nvar*(lags+1),nvar); +% Stack lags M's in the order of, e.g., [Mlags, ..., M2,M1;M0] +M(1:nvar,:) = swish; +Mtem = M(1:nvar,:); % temporary M. +% first (initial) responses to 1 standard deviation shock. Row: responses; Column: shocks +% * put in the form of "imf" +imf(1,:) = Mtem(:)'; + +t = 1; +ims1 = min([imstep-1 lags]); +while t <= ims1 + Mtem = Ah(:,1:nvar*t)*M(1:nvar*t,:); + % Row: nvar equations, each for the nvar variables at tth lag + M(nvar+1:nvar*(t+1),:)=M(1:nvar*t,:); + M(1:nvar,:) = Mtem; + imf(t+1,:) = Mtem(:)'; + % stack imf with each step, Row: 6 var to 1st shock, 6 var to 2nd shock, etc. + t= t+1; +end + +for t = lags+1:imstep-1 + Mtem = Ah(:,1:nvar*lags)*M(1:nvar*lags,:); + % Row: nvar equations, each for the nvar variables at tth lag + M(nvar+1:nvar*(t+1),:) = M(1:nvar*t,:); + M(1:nvar,:)=Mtem; + imf(t+1,:) = Mtem(:)'; + % stack imf with each step, Row: 6 var to 1st shock, 6 var to 2nd shock, etc. +end \ No newline at end of file diff --git a/MatlabFiles/a0asfun.m b/MatlabFiles/a0asfun.m new file mode 100755 index 0000000..6d8cb55 --- /dev/null +++ b/MatlabFiles/a0asfun.m @@ -0,0 +1,35 @@ +function of = a0asfun(x,s,nobs,nvar,a0indx) +% General program to setup A0 matrix with asymmetric prior (as) and compute the posterior +% function of = a0asfun(x,s,nobs,nvar,a0indx) -- negative logPosterior +% Note: columns correspond to equations +% x (parameter vector), +% s (diag(S1,...,Sm)): note, as in "a0lhfun", already divided by "nobs" +% nobs (no of obs), +% nvar (no of variables), +% a0indx (matrix indicating the free parameters in A0, and each column in A0 corresponds +% to an equation) +% +% Copyright (c) December 1997 by Tao Zha +% + +a0 = zeros(nvar); +a0(a0indx) = x; +% Note: each column in a0 corresponds to an equation!! +% +%%ada = chol(a0'*a0); +%%ada = log(abs(diag(ada))); +%%ada = sum(ada); +% ** TZ, 10/15/96, the above two lines can be improved by the following three lines +[a0l,a0u] = lu(a0); +%ada=diag(abs(a0u)); +%ada=sum(log(ada)); +ada = sum(log(abs(diag(a0u)))); + +% +%tra = sum(i=1:m){a0(:,i)'*Si*a0(:,i)} +tra = 0.0; +for i=1:nvar + tra = tra + a0(:,i)'*s{i}*a0(:,i); +end + +of = -nobs*ada + nobs*.5*tra; \ No newline at end of file diff --git a/MatlabFiles/a0asgrad.m b/MatlabFiles/a0asgrad.m new file mode 100755 index 0000000..2d76d22 --- /dev/null +++ b/MatlabFiles/a0asgrad.m @@ -0,0 +1,27 @@ +function [g,badg] = a0asgrad(x,s,nobs,nvar,a0indx); +% Computes analytical gradient for use in csminwel.m +% function [g,badg] = a0asgrad(x,s,nobs,nvar,a0indx); +% +% x (parameter vector), +% s (diag(S1,...,Sm)): note, as in "a0lhfun", already divided by "nobs" +% nobs (no of obs), +% nvar (no of variables), +% a0indx (matrix indicating the free parameters in A0, and each column in A0 corresponds +% to an equation) + + +a0 = zeros(nvar); +%%g = zeros(nvar*nvar,1); % 4/27/97: not necessary. +badg = 0; + +a0(a0indx) = x; + +b1=-nobs*inv(a0'); +b2 = zeros(nvar,nvar); +for i=1:nvar + b2(:,i) = nobs*s{i}*a0(:,i); +end + +%b = -nobs*inv(a') + nobs*s*a; +b = b1(:)+b2(:); +g = b(a0indx); \ No newline at end of file diff --git a/MatlabFiles/a0freefun.m b/MatlabFiles/a0freefun.m new file mode 100755 index 0000000..8e322b9 --- /dev/null +++ b/MatlabFiles/a0freefun.m @@ -0,0 +1,45 @@ +function of = a0freefun(b,Ui,nvar,n0,fss,H0inv) +% of = a0freefun(b,Ui,nvar,n0,fss,H0inv) +% +% Negative logPosterior function for squeesed A0 free parameters, which are b's in the WZ notation +% Note: columns correspond to equations +% +% b: sum(n0)-by-1 vector of A0 free parameters +% Ui: nvar-by-1 cell. In each cell, nvar-by-qi orthonormal basis for the null of the ith +% equation contemporaneous restriction matrix where qi is the number of free parameters. +% With this transformation, we have ai = Ui*bi or Ui'*ai = bi where ai is a vector +% of total original parameters and bi is a vector of free parameters. When no +% restrictions are imposed, we have Ui = I. There must be at least one free +% parameter left for the ith equation. +% nvar: number of endogeous variables +% n0: nvar-by-1, ith element represents the number of free A0 parameters in ith equation +% fss: nSample-lags (plus ndobs if dummies are included) +% H0inv: cell(nvar,1). In each cell, posterior inverse of covariance inv(H0) for the ith equation, +% resembling old SpH in the exponent term in posterior of A0, but not divided by T yet. +%---------------- +% of: objective function (negative logPosterior) +% +% Tao Zha, February 2000 + +b=b(:); + +A0 = zeros(nvar); +n0cum = cumsum(n0); +tra = 0.0; +for kj = 1:nvar + if kj==1 + bj = b(1:n0(kj)); + A0(:,kj) = Ui{kj}*bj; + tra = tra + 0.5*bj'*H0inv{kj}*bj; % negative exponential term + else + bj = b(n0cum(kj-1)+1:n0cum(kj)); + A0(:,kj) = Ui{kj}*bj; + tra = tra + 0.5*bj'*H0inv{kj}*bj; % negative exponential term + end +end + +[A0l,A0u] = lu(A0); + +ada = -fss*sum(log(abs(diag(A0u)))); % negative log determinant of A0 raised to power T + +of = ada + tra; diff --git a/MatlabFiles/a0freegrad.m b/MatlabFiles/a0freegrad.m new file mode 100755 index 0000000..b807e78 --- /dev/null +++ b/MatlabFiles/a0freegrad.m @@ -0,0 +1,50 @@ +function [g,badg] = a0freegrad(b,Ui,nvar,n0,fss,H0inv) +% [g,badg] = a0freegrad(b,Ui,nvar,n0,fss,H0inv) +% +% Analytical gradient for a0freefun.m in use of csminwel.m +% b: sum(n0)-by-1 vector of A0 free parameters +% Ui: nvar-by-1 cell. In each cell, nvar-by-qi orthonormal basis for the null of the ith +% equation contemporaneous restriction matrix where qi is the number of free parameters. +% With this transformation, we have ai = Ui*bi or Ui'*ai = bi where ai is a vector +% of total original parameters and bi is a vector of free parameters. When no +% restrictions are imposed, we have Ui = I. There must be at least one free +% parameter left for the ith equation. +% nvar: number of endogeous variables +% n0: nvar-by-1, ith element represents the number of free A0 parameters in ith equation +% fss: nSample-lags (plus ndobs if dummies are included) +% H0inv: cell(nvar,1). In each cell, posterior inverse of covariance inv(H0) for the ith equation, +% resembling old SpH in the exponent term in posterior of A0, but not divided by T yet. +%--------------- +% g: sum(n0)-by-1 analytical gradient for a0freefun.m +% badg: 0, the value that is used in csminwel.m +% +% Tao Zha, February 2000 + +b=b(:); + +A0 = zeros(nvar); +n0cum = cumsum(n0); +g = zeros(n0cum(end),1); +badg = 0; + +for kj = 1:nvar + if kj==1 + bj = b(1:n0(kj)); + g(1:n0(kj)) = H0inv{kj}*bj; + A0(:,kj) = Ui{kj}*bj; + else + bj = b(n0cum(kj-1)+1:n0cum(kj)); + g(n0cum(kj-1)+1:n0cum(kj)) = H0inv{kj}*bj; + A0(:,kj) = Ui{kj}*bj; + end +end +B=inv(A0'); + +for ki = 1:sum(n0) + if ki<=n0(1) + g(ki) = g(ki) - fss*B(:,1)'*Ui{1}(:,ki); + else + n = max(find( (ki-n0cum)>0 ))+1; % note, 1<n<nvar + g(ki) = g(ki) - fss*B(:,n)'*Ui{n}(:,ki-n0cum(n-1)); + end +end diff --git a/MatlabFiles/a0impsmp.m b/MatlabFiles/a0impsmp.m new file mode 100755 index 0000000..6a3c06b --- /dev/null +++ b/MatlabFiles/a0impsmp.m @@ -0,0 +1,83 @@ +function [xdraw,mphv,sm,timeminutes] = a0impsmp(xinput) +% [xdraw,mphv,sm,timeminutes] = a0impsmp(xinput) +% Export the simulated pdfs of draws of only selected parameters +% with importance sampling techniques +% +% xinput{1}: nfp -- total number of free parameters +% xinput{2}: nvar -- number of variables +% xinput{3}: xhat -- ML estimate of free parameters in A0 +% xinput{4}: hess1 -- Hessian of -logLH for importance sampling +% xinput{5}:Indxv -- index for selected variables of interest; normall first 2 are of our interest +% to select variables, always check idmat0 to make sure. +% When Indxv=[], xdraw is empty as well. When IndxGgraph=1, it plots +% (1) pdf of 1st v for every buffer, (2) scattered plot of 1st and 2nd for every buffer, +% (3) pdf of 1st v for all sequences; (4) scattered plot of 3rd and 4th for all sequences +% (5) scattered plot of 1st and 2nd for al sequences. +% xinput{6}: imndraws=nstarts*ndraws2 +% xinput{7}: a0indx -- index number for non-zero elements in A0 +% xinput{8}: tdf -- degrees of freedom for t-distribution +% xinput{9}: nbuffer -- interval for printing, plotting, and saving +% xinput{10}: Sbd -- nvar-by-nvar S{1}, ..., S{n} -- kind of covariance matrix for each simultaneous equation +% Already divided by "fss." +% xinput{11}: scf -- reduction scale factor for Metropolis jumping kernel +% xinput{12}: Hsr1 -- square root of covariance matrix for free elements in A0 (nfp-by-nfp) +% for importance sampling. +% xinput{13}: fss -- effective sample size == nSample-lags+# of dummy observations +%------------------ +% xdraw: imndraws-by-length(Indxv) matrix of draws; +% empty if Indxv is empty. +% timeminutes: minutes used for this simulation +% mphv: imndraws-by-1 vector of unscaled weights +% sm: sum of the weights +% +% Written by Tao Zha 1999 + +nfp=xinput{1}; nvar=xinput{2}; xhat=xinput{3}; hess1=xinput{4}; Indxv=xinput{5}; +imndraws=xinput{6}; a0indx=xinput{7}; tdf=xinput{8}; nbuffer=xinput{9}; +Sbd=xinput{10}; scf=xinput{11}; Hsr1=xinput{12}; fss=xinput{13}; + + +sm = 0.0; +mphv=zeros(imndraws,1); +if isempty(Indxv) + xdraw=[]; +else + xdraw=zeros(imndraws,length(Indxv)); %<<>> draws of selected variables +end + +tic +for draws=1:imndraws + % + if ~mod(draws,nbuffer) + draws + % fwriteid = fopen('outA0.bin','a'); + % count = fwrite(fwriteid,A0hatw,'double'); + % status = fclose('all'); + end + + + %** draw free elements Avh in A0 and hyperparameters from t-dist + Avhz1 = Hsr1\randn(nfp,1); % normal draws + csq=randn(tdf,1); + csq=sum(csq .* csq); + Avhz = xhat+Avhz1/sqrt(csq/tdf); % Robert, p.382 + + % *** compute weights *** + % * t-dist density, having taken log + tdhz = -0.5*(length(Avhz)+tdf)*log(1+(Avhz-xhat)'*(hess1*(Avhz-xhat))/tdf); + % * actual density, having taken log + hAvhz = a0asfun(Avhz,Sbd,fss,nvar,a0indx); + hAvhz = -hAvhz; % converted to logLH + + % * mph: m prim hat in Kloek & van Dijk, p.5 + mph = exp(hAvhz-tdhz-scf); % scf: scaling factor to prevent overflow + mphv(draws) = mph; + + sm=sm+mph; + % * matrix of draws for selected variables + if ~isempty(Indxv) + xdraw(draws,:) = Avhz(Indxv)'; + end + % +end +timeminutes = toc/60 diff --git a/MatlabFiles/a0onlysim.m b/MatlabFiles/a0onlysim.m new file mode 100755 index 0000000..91c3e1b --- /dev/null +++ b/MatlabFiles/a0onlysim.m @@ -0,0 +1,270 @@ +function [xdraw,timeminutes,nswitch] = a0onlysim(xinput) +% [xdraw,timeminutes,nswitch] = a0onlysim(xinput) +% Export and plot the simulated pdfs of draws of only selected parameters; +% Print and save Gelman's measures of B and W for all parameters; +% Ref: Waggoner and Zha "Does Normalization Matter for Inference" +% See note Forecast (2) +% +% xinput{1}: nfp -- total number of free parameters +% xinput{2}: nvar -- number of variables +% xinput{3}: xhat -- ML estimate of free parameters in A0 +% xinput{4}: hess1 -- Hessian of -logLH +% xinput{5}:Indxv -- index for selected variables of interest; normall first 2 are of our interest +% to select variables, always check idmat0 to make sure. +% When Indxv=[], xdraw is empty as well. When IndxGgraph=1, it plots +% (1) pdf of 1st v for every buffer, (2) scattered plot of 1st and 2nd for every buffer, +% (3) pdf of 1st v for all sequences; (4) scattered plot of 3rd and 4th for all sequences +% (5) scattered plot of 1st and 2nd for al sequences. +% xinput{6}: IndxGraph - 1: plot graphs; 0: no graphs +% xinput{7}: idmat0 -- Index for non-zero elements in A0 with column to equation +% xinput{8}: nstarts -- # of starting points in Gibbs sampling +% xinput{9}: ndraws1 -- # of 1st loop to be discarded +% xinput{10}: ndraws2 -- # of 2nd loop for saving A0 draws +% xinput{11}: imndraws=nstarts*ndraws2 +% xinput{12}: a0indx -- index number for non-zero elements in A0 +% xinput{13}: tdf -- degrees of freedom for t-distribution +% xinput{14}: nbuffer -- interval for printing, plotting, and saving +% xinput{15}: Sbd -- nvar-by-nvar S{1}, ..., S{n} -- kind of covariance matrix for each simultaneous equation +% Already divided by "fss." +% xinput{16}: nSample -- the original sample size including lags +% xinput{17}: IndxNmlr -- index for which normalization rule to choose +% xinput{18}: IndxGibbs -- index for WZ Gibbs; 1; Gibbs; 0: Metropolis +% xinput{19}: scf -- reduction scale factor for Metropolis jumping kernel +% xinput{20}: H_sr -- square root of the inverse of the covariance matrix +% for free elements in A0 (nfp-by-nfp) +% xinput{21}: fss -- effective sample size == nSample-lags+# of dummy observations +%------------------ +% xdraw: nstarts*ndraws2-by-length(Indxv) matrix of draws; +% empty if Indxv=[] +% timeminutes: minutes used for this simulation +% +% Written by Tao Zha 1999 + +nfp=xinput{1}; nvar=xinput{2}; xhat=xinput{3}; hess=xinput{4}; Indxv=xinput{5}; +IndxGraph=xinput{6}; idmat0=xinput{7}; nstarts=xinput{8}; ndraws1=xinput{9}; ndraws2=xinput{10}; +imndraws=xinput{11}; a0indx=xinput{12}; tdf=xinput{13}; nbuffer=xinput{14}; Sbd=xinput{15}; +nSample = xinput{16}; IndxNmlr=xinput{17}; IndxGibbs=xinput{18}; scf=xinput{19}; H_sr=xinput{20}; +fss=xinput{21}; + +if IndxGraph>length(Indxv) + disp(' ') + warning('when IndxGraph=1, Indxv must have at least 1 elements') + disp('Press ctrl-c to abort') + pause +end + +Avhx_bs = zeros(nfp,1); +Avhx_bm = zeros(nfp,1); +Avhx_bj = zeros(nfp,1); +Avhx_cj = zeros(nfp,1); +Avhx_cm = zeros(nfp,1); +A0_h = zeros(nvar); +A0gbs = A0_h; % drawn A0 in Gibbs sampling +Avhxm = zeros(nfp,1); +Avhxs = Avhxm; +A0xhat = zeros(nvar); +A0xhat(a0indx) = xhat; +% A0hatw = zeros(nvar^2,nbuffer); + +countJump = zeros(nstarts,1); + + +%=================================== +% Here begins with the big loop +%=================================== +H1 = chol(hess); % upper triangular so that H1' is a lower triangular decomp +baseW = H_sr; %inv(H1); %H_sr; % covariance matrix without scaling +nswitch=0; %<<>> total number of sign switches +A0inxhat = inv(A0xhat); % inverse of ML estimate +a0indx0 = find(idmat0==0); % index for all zero's in A0; +if isempty(Indxv) + xdraw=[]; +else + xdraw=zeros(imndraws,length(Indxv)); %<<>> draws of selected variables +end + + +[cT,vR,kdf] = gibbsglb(Sbd,idmat0,nvar,fss); + +tic +for starts = 1:nstarts + starts + if starts == 1 + A0gbs(a0indx) = xhat; % from "load ..." + if ~IndxGibbs % Metropolist + Avhx = xhat; + hAvhx = a0asfun(Avhx,Sbd,fss,nvar,a0indx); + hAvhx = -hAvhx; % converted to logLH + end + else + Avhx = baseW*randn(nfp,1); %H_sr*randn(nfp,1); % D: discarded sequence + csq=randn(tdf,1); + csq=sum(csq .* csq); + Avhx = xhat+Avhx/sqrt(csq/tdf); + %** Normalization by the choice of IndxNmlr + A0gbs(a0indx) = Avhx; + if ~IndxNmlr(5) + [A0gbs,jnk] = nmlzvar(A0gbs,A0xhat,A0inxhat,IndxNmlr,nswitch,[]); + else + A0ingbs = inv(A0gbs); + [A0gbs,jnk,jnk1] = nmlzvar(A0gbs,A0xhat,A0inxhat,IndxNmlr,nswitch,A0ingbs); + end + % + if ~IndxGibbs % Metropolist + Avhx = A0gbs(a0indx); + hAvhx = a0asfun(Avhx,Sbd,fss,nvar,a0indx); + hAvhx = -hAvhx; % converted to logLH + end + end + % + Avhxmm = zeros(nfp,1); + Avhxss = zeros(nfp,1); + cJump = 0; + + for draws = 1:ndraws1 + if IndxGibbs + A0gbs = gibbsvar(A0gbs,cT,vR,nvar,fss,kdf); + else % Metropolis + [Avhx,hAvhx,cJump] = smtplis(Avhx,hAvhx,tdf,cJump,scf,... + baseW,nfp,Sbd,fss,nvar,a0indx); + end + end + + wdraws=(starts-1)*ndraws2+0; + for draws = 1:ndraws2 + drawsc = (starts-1)*ndraws2+draws; + if IndxGibbs + A0gbs = gibbsvar(A0gbs,cT,vR,nvar,fss,kdf); + A0gbs(a0indx0) = 0; % set all zeros in A0gbs clean to avoid possible cumulative round-off errors + else % Metropolis + [Avhx,hAvhx,cJump] = smtplis(Avhx,hAvhx,tdf,cJump,scf,... + baseW,nfp,Sbd,fss,nvar,a0indx); + A0gbs(a0indx) = Avhx; + end + + %*** call normalization so that A0_h is normalized + if ~IndxNmlr(5) + [A0_h,nswitch] = nmlzvar(A0gbs,A0xhat,A0inxhat,IndxNmlr,nswitch,[]); + else + A0ingbs = inv(A0gbs); + [A0_h,nswitch,A0_hin] = nmlzvar(A0gbs,A0xhat,A0inxhat,IndxNmlr,nswitch,A0ingbs); + end + Avhx_norm = A0_h(a0indx); + + Avhxm = Avhxm + Avhx_norm; % 1st step to overall mean of parameter + Avhxs = Avhxs + Avhx_norm.^2; % 1st step to overall 2nd moment of parameter + + %* compute the mean and 2nd moment + %** Getting average of variances W and variance of means B/n -- B_n + %* see Gelman, p.331, my Shock(0), 12-13, and my Forecast (2), 28-31 + if (nstarts>1) + Avhxmm = Avhxmm + Avhx_norm; % n*(phi_.j) + Avhxss = Avhxss + Avhx_norm.^2; % 1st step to (phi_ij) for fixed j + end + + if ~isempty(Indxv) + xdraw((starts-1)*ndraws2+draws,:) = Avhx_norm(Indxv)'; %<<>> + end + % A0hatw(:,drawsc-wdraws) = A0_h(:); + if ~mod(draws,nbuffer) + starts + draws + wdraws=drawsc + % fwriteid = fopen('outA0.bin','a'); + % count = fwrite(fwriteid,A0hatw,'double'); + % status = fclose('all'); + if IndxGraph + %** 1-d pdf plot + % figure(2) + % histpdfg(xdraw((starts-1)*ndraws2+(1:draws),1),50,[],[],[]); + % pause(1) + + %** 2-d scatterplot + figure(3) + plot(xdraw((starts-1)*ndraws2+(1:draws),1),... + xdraw((starts-1)*ndraws2+(1:draws),2),'.'); + drawnow + end + end + end + % + if ~IndxGibbs + countJump(starts,1) = cJump; + end + % + %** Getting average of variances W and variance of means B/n -- B_n + %** see Gelman, p.331, my Shock(0), pp.12-13, and my Forecast (2), pp.28-31 + if (nstarts>1) + Avhx_aj = Avhxmm/ndraws2; % (phi_.j) + Avhx_bs = Avhx_bs + Avhx_aj.^2; % 1st step to 2nd moment of (phi_.j) + Avhx_bm = Avhx_bm + Avhx_aj; % 1st step to (phi_..) + % + Avhx_bj = Avhxss/ndraws2; % 2nd moment of (phi_ij) for fixed j + Avhx_cj = Avhx_bj - Avhx_aj.^2; % ((n-1)/n)*S^2_j + Avhx_cm = Avhx_cm + Avhx_cj; % sum of ((n-1)/n)*S^2_j across j + end +end +timend = toc + +if ~IndxGibbs + countJump = countJump/ndraws2 +end + +Avhxm = Avhxm/(imndraws); +Avhxs = Avhxs/(imndraws); +Avhxv = Avhxs - Avhxm.^2; +Avhxs = sqrt(Avhxv); % stardard deviation +A0hm = zeros(nvar); +A0hm(a0indx) = Avhxm % mean +A0hv = zeros(nvar); +A0hv(a0indx) = Avhxv; % varaince matrix +A0hs = zeros(nvar); +A0hs(a0indx) = Avhxs; % standar deviation + +%**** Getting Within-Sequence W and Between-Sequence B_n +% see Gelman, p.331, my Shock(0), pp.12-13, and my Forecast (2), pp.28-31 +if (nstarts>1) + AvhxW = (ndraws2/(ndraws2-1))*Avhx_cm/nstarts; + % W: average of j within-sequence variances + AvhxB_n = (nstarts/(nstarts-1)) * ( Avhx_bs/nstarts - (Avhx_bm/nstarts).^2 ); + % B/n: variance of J within-sequence means + AvhxB = ndraws2*AvhxB_n; % B + % + B_W1 = AvhxB ./ AvhxW; + B1 = AvhxB; + W1 = AvhxW; + GR1 = sqrt((ndraws2-1)/ndraws2 + B_W1/ndraws2); + % measure of Gelman reduction; need not be 1 to be accurate, + % contrary to what Gelman claims + save outB_W B_W1 B1 W1 GR1 nstarts ndraws2 imndraws timend Avhxs ... + A0xhat A0hm A0hs A0hv IndxGibbs countJump nswitch + + titstr = ['J ' num2str(nstarts) ' n1 ' num2str(ndraws1) ... + ' n2 ' num2str(ndraws2) ' timend minutes ' num2str(timend/60)]; + disp(' ') + disp(titstr) + disp('B/W sqrt(B) sqrt(W) Std(A0) GR') + format short g + [B_W1 sqrt(B1) sqrt(W1) Avhxs GR1] +else + save outB_W nstarts ndraws2 imndraws timend Avhxs ... + A0xhat A0hm A0hs A0hv IndxGibbs countJump nswitch +end + +disp(' ') +disp('nswitch nswitch/imndraws -- # of sign switches') +[nswitch nswitch/imndraws] +disp(' ') +disp('timend/60 minutes') +timeminutes = timend/60 +nswitch=nswitch/imndraws; + +if IndxGraph + % + % figure(4) + % histpdfg(xdraw(:,1),50,[],[],[]); + % figure(5) + % plot(xdraw(:,3),xdraw(:,4),'.'); + % figure(6) + % plot(xdraw(:,1),xdraw(:,2),'.'); +end \ No newline at end of file diff --git a/MatlabFiles/adapt.m b/MatlabFiles/adapt.m new file mode 100755 index 0000000..1ea5a2e --- /dev/null +++ b/MatlabFiles/adapt.m @@ -0,0 +1,37 @@ +function Q = adapt(f,a,b,tol,trace,varargin) +%ADAPT Numerically evaluate integral using adaptive Simpson rule. +% +% Q = ADAPT('F',A,B) approximates the integral of F(X) from A to B +% to machine precision. 'F' is a string containing the name of the +% function. Function F must return a vector of output values if given +% a vector of input values. +% +% Q = ADAPT('F',A,B,TOL) integrates to a relative error of TOL. +% +% Q = ADAPT('F',A,B,TOL,TRACE) displays the left end point of the +% current interval, the interval length and the partial integral. +% +% Q = ADAPT('F',A,B,TOL,TRACE,P1,P2,...) allows coefficients P1, ... +% to be passed directly to function F: G = F(X,P1,P2,...). +% To use default values for TOL or TRACE, you may pass in the empty +% matrix ([]). +% +% See also QUAD, QUAD8, DBLQUAD. + +% Copyright (c) 1990-97 by The MathWorks, Inc. +% $Revision: 1.0 $ $Date: 1997/09/15 14:36:41 $ +% Author: Walter Gander 5-20-97 +% Reference: Computermathematik, Birkhaeuser, 1992. + +if (nargin < 4), tol = []; end; +if (nargin < 5), trace = []; end; +if (isempty(tol)), tol = 10*eps; end; +if (isempty(trace)), trace = 0; end; + +x = [a (a+b)/2 b]; +y = feval(f, x, varargin{:}); +fa = y(1); fm = y(2); fb = y(3); +is = (b - a)/6 * (fa + 4*fm + fb); +s = sign(is); if (s == 0), s = 1; end; +is = s*(abs(is) + b - a)/2*tol/eps; +Q = adaptstp(f, a, b, fa, fm, fb, is, trace, varargin{:}); \ No newline at end of file diff --git a/MatlabFiles/adaptstp.m b/MatlabFiles/adaptstp.m new file mode 100755 index 0000000..846750a --- /dev/null +++ b/MatlabFiles/adaptstp.m @@ -0,0 +1,27 @@ +function Q = adaptstp (f, a, b, fa, fm, fb, is, trace, varargin) +%ADAPTSTP Recursive function used by ADAPT. +% +% Q = ADAPTSTP('F',A,B,FA,FM,FB,IS,TRACE) tries to +% approximate the integral of f(x) from a to b to within a +% relative error of IS/int(..)*eps. F is a string containing +% the name of f. The remaining arguments are generated by adapt +% or by the recursion. +% +% See also ADAPT. + +% Author: Walter Gander, 05/20/97 + +m = (a + b)/2; h = (b - a)/4; +x = [a + h, b - h]; +y = feval(f, x, varargin{:}); +fml = y(1); fmr = y(2); +i1 = h/1.5 * (fa + 4*fm + fb); +i2 = h/3 * (fa + 4*(fml + fmr) + 2*fm + fb); +i1 = (16*i2 - i1)/15; +if (is + (i1-i2) == is), + Q = i1; + if (trace), disp([a b-a Q]), end; +else + Q = adaptstp (f, a, m, fa, fml, fm, is, trace, varargin{:}) + ... + adaptstp (f, m, b, fm, fmr, fb, is, trace, varargin{:}); +end; \ No newline at end of file diff --git a/MatlabFiles/betapar.m b/MatlabFiles/betapar.m new file mode 100755 index 0000000..200b3cb --- /dev/null +++ b/MatlabFiles/betapar.m @@ -0,0 +1,10 @@ +function f = betapar(ab, XLO, XUP, PLO, PUP); + +% The function takes as inputs the parameters ab=[a, b] of the Beta +% distribution, the bounds of the support [XLO, XUP], the the corresponding +% probability of the bounds [PLO, PUP] and returns the residual value f. + +a = ab(1); b = ab(2); +f1 = PLO - betacdf(XLO, a, b); +f2 = PUP - betacdf(XUP, a, b); +f = [f1, f2]; diff --git a/MatlabFiles/bfgsi.m b/MatlabFiles/bfgsi.m new file mode 100755 index 0000000..aa87285 --- /dev/null +++ b/MatlabFiles/bfgsi.m @@ -0,0 +1,29 @@ +function H = bfgsi(H0,dg,dx) +% H = bfgsi(H0,dg,dx) +% dg is previous change in gradient; dx is previous change in x; +% 6/8/93 version that updates inverse hessian instead of hessian +% itself. +% Copyright by Christopher Sims 1996. This material may be freely +% reproduced and modified. +dispIndx = 1; % 1: turn on all the diplays on the screen; 0: turn off (Added by T. Zha) + +if size(dg,2)>1 + dg=dg'; +end +if size(dx,2)>1 + dx=dx'; +end +Hdg = H0*dg; +dgdx = dg'*dx; +if (abs(dgdx) >1e-12) + H = H0 + (1+(dg'*Hdg)/dgdx)*(dx*dx')/dgdx - (dx*Hdg'+Hdg*dx')/dgdx; +else + if dispIndx + disp('bfgs update failed.') + disp(['|dg| = ' num2str(sqrt(dg'*dg)) '|dx| = ' num2str(sqrt(dx'*dx))]); + disp(['dg''*dx = ' num2str(dgdx)]) + disp(['|H*dg| = ' num2str(Hdg'*Hdg)]) + end + H=H0; +end +save H.dat H diff --git a/MatlabFiles/bfgsi.m0 b/MatlabFiles/bfgsi.m0 new file mode 100755 index 0000000..800fefa --- /dev/null +++ b/MatlabFiles/bfgsi.m0 @@ -0,0 +1,24 @@ +function H = bfgsi(H0,dg,dx) +% H = bfgsi(H0,dg,dx) +% dg is previous change in gradient; dx is previous change in x; +% 6/8/93 version that updates inverse hessian instead of hessian +% itself. +if size(dg,2)>1 + dg=dg'; +end +if size(dx,2)>1 + dx=dx'; +end +Hdg = H0*dg; +dgdx = dg'*dx; +if (abs(dgdx) >1e-12) + H = H0 + (1+(dg'*Hdg)/dgdx)*(dx*dx')/dgdx - (dx*Hdg'+Hdg*dx')/dgdx; +else + disp('bfgs update failed.') + disp(['|dg| = ' num2str(sqrt(dg'*dg)) '|dx| = ' num2str(sqrt(dx'*dx))]); + disp(['dg''*dx = ' num2str(dgdx)]) + disp(['|H*dg| = ' num2str(Hdg'*Hdg)]) + H=H0; +end +save H.dat H; + \ No newline at end of file diff --git a/MatlabFiles/bfgsi.m1 b/MatlabFiles/bfgsi.m1 new file mode 100755 index 0000000..8090b32 --- /dev/null +++ b/MatlabFiles/bfgsi.m1 @@ -0,0 +1,24 @@ +function H = bfgsi(H0,dg,dx) +% H = bfgsi(H0,dg,dx) +% dg is previous change in gradient; dx is previous change in x; +% 6/8/93 version that updates inverse hessian instead of hessian +% itself. +if size(dg,2)>1 + dg=dg'; +end +if size(dx,2)>1 + dx=dx'; +end +Hdg = H0*dg; +dgdx = dg'*dx; +if (abs(dgdx) >1e-12) + H = H0 + (1+(dg'*Hdg)/dgdx)*(dx*dx')/dgdx - (dx*Hdg'+Hdg*dx')/dgdx; +else + disp('bfgs update failed.') + disp(['|dg| = ' num2str(sqrt(dg'*dg)) '|dx| = ' num2str(sqrt(dx'*dx))]); + disp(['dg''*dx = ' num2str(dgdx)]) + disp(['|H*dg| = ' num2str(Hdg'*Hdg)]) + H=H0; +end +save H.dat H + diff --git a/MatlabFiles/calyrqm.m b/MatlabFiles/calyrqm.m new file mode 100755 index 0000000..2111991 --- /dev/null +++ b/MatlabFiles/calyrqm.m @@ -0,0 +1,58 @@ +function [Myrqm,nMyrqm] = calyrqm(q_m,Byrqm,Eyrqm) +% [Myrqm,nMyrqm] = calyrqm(q_m,Byrqm,Eyrqm) +% +% Given the beginning and end years and quarters (months), export a matrix of all years and +% quarters (months) for these years and in between +% +% q_m: 4 if quarterly and 12 if monthly +% Byrqm: [year quarter(month)] -- all integers, the begining year and quarter (month) +% Eyrqm: [year quarter(month)] -- all integers, the end year and quarter (month) +%------------------- +% Myrqm: matrix of all years and quarters (months) between and incl. Byrqm and Eyrqm +% nMyrqm: number of data points incl. Byrqm and Eyrqm +% +% Tao Zha, April 2000 + +if ~isempty(find(Byrqm-round(Byrqm))) | (q_m-round(q_m)) | ~isempty(find(Byrqm-round(Byrqm))) + error('argin qm, Byrqm, or Eyrqm must of integer') +elseif Byrqm(1)>Eyrqm(1) + error('Eyrqm(1) must be equal to or greater than Byrqm(1)') +elseif Byrqm(1)==Eyrqm(1) + if Byrqm(2)>Eyrqm(2) + error('Eyrqm(2) must be equal to or greater than Byrqm(2) because of the same year') + end +end + + +Yr = Byrqm(1)+[0:Eyrqm(1)-Byrqm(1)]'; + +if length(Yr)>=2 % there are years and quarters (months) between Byrqm and Eyrqm + n=length(Yr)-2; + C=zeros(n*q_m,2); + C(:,1) = kron(Yr(2:end-1),ones(q_m,1)); + C(:,2) = kron(ones(n,1),[1:q_m]'); + + %* initialize a matrix of years and quarters (months) including Byrqm and Eyrqm + Myrqm = zeros((q_m-Byrqm(2)+1)+Eyrqm(2)+n*q_m,2); + + %* Years in between + n1=q_m-Byrqm(2)+1; + n2=Eyrqm(2); + Myrqm(n1+1:end-n2,:) = C; + %* Beginning year + for k=1:n1 + Myrqm(k,:) = [Byrqm(1) Byrqm(2)+k-1]; + end + %* End year + for k=1:n2 + Myrqm(end-Eyrqm(2)+k,:) = [Eyrqm(1) k]; + end +else %* all the data are in the same calendar year + n1=Eyrqm(2)-Byrqm(2)+1; + Myrqm = zeros(n1,2); + for k=1:n1 + Myrqm(k,:) = [Byrqm(1) Byrqm(2)+k-1]; + end +end + +nMyrqm = size(Myrqm,1); diff --git a/MatlabFiles/cfore.m b/MatlabFiles/cfore.m new file mode 100755 index 0000000..b9fa1a1 --- /dev/null +++ b/MatlabFiles/cfore.m @@ -0,0 +1,466 @@ +% 10/24/97 +% Distance Method of Waggoner and Zha +% Modified from Sims and Zha's code +% Copyright (c) 1997 Tao Zha + + +% ** ONLY UNDER UNIX SYSTEM +%path(path,'/usr2/f1taz14/mymatlab') + + +%global xxhp Hm1t Hm1 Hm SpH FRESHFUNCTION +% +%* ================================================= +%* ====== Beginning of the script ================== +%* ================================================= +% +%* The available data considered +% +q_m = 12; % quarters or months +yrBin=59; % beginning of the year +qmBin=1; % begining of the quarter or month +yrFin=97; % final year +qmFin=12; % final quarter +%tnvar = 2; % total number of variables +nData=(yrFin-yrBin)*q_m + (qmFin-qmBin+1); +% total number of the available data -- this is all you have +% +%* Load data and series +% +load xd24a % the default name for the variable is "xdd". +[nt,ndv]=size(xdd); +if nt~=nData + warning(sprintf('nt=%d, Caution: not equal to the length in the data',nt)); + %disp(sprintf('nt=%d, Caution: not equal to the length in the data',nt)); + return +end +%1 CPI-U +%2 FFR +%3 T-bill3 +%4 Treasure note 10 +%5 M2 +%6 M1 +%7 Nominal PCE +%8 real PCE +%9 Unemployment Rate +%10 IMF Commodity Price Index +%11 Civilians Employed: 16 & over +%12 Nonfarm Payroll Employment +%13 IP +%14 Retail Sales (Nominal) +%15 NAPM Composit Index +%16 Total Reserves +%17 PPI-finished goods +%18 PPI-Crude materials +%19 PPI-Crude materials less energy +%20 CRB Spot Commodity Index -- all commodities +%21 CRB Spot Commodity Index -- raw industrials +%22 PCE price index +%23 rgdpmon Real GDP (monthly, chain $92) +%24 dgdpmon Deflator GDP (monthly, chain $92) + + +%1 IMF CP +%2 M2 +%3 FFR +%3 real GDP +%4 CPI-U +%5 U + +%>>>>>>>>>>>>>>>>>> +logindx = [1 5:8 10:14 16:24]; +xdd(:,logindx) = log(xdd(:,logindx)); +pctindx = [2:4 9 15]; +xdd(:,pctindx)=.01*xdd(:,pctindx); % make it a general term for the following use +% +vlist = [10 5 2 23 1 9]; % regarding "xdd", IMF-CP, M2, FFR, GDP, CPI, U +vlistlog = [1 2 4 5]; % subset of "vlist" +vlistper = [3 6]; % subset of "vlist" +%<<<<<<<<<<<<<<<<<<< + +idfile='iden6'; + +xlab = {'Inf' + 'MS' + 'FFR' + 'y' + 'P' + 'U'}; + +ylab = {'Pcm' + 'M2' + 'FFR' + 'y' + 'P' + 'U'}; + +xdd_per = xdd(:,vlist); + +x1 = 'Pcm'; +x2 = 'M2'; +x3 = 'FFR'; +x4 = 'GDP'; +x5 = 'CPI'; +x6 = 'U'; +x7 = 'R10'; + + +baddata = find(isnan(xdd_per)); +if ~isempty(baddata) + warning('Some data are actually unavailable.') + disp('Hit any key to continue, or ctrl-c to abort') + pause +end +% + +%* A specific sample is considered for estimation +%* Sample period 59:7-82:9, forecast period 82:10-84:9 +yrStart=59; +qmStart=1; +[yrEnd,qmEnd,forep,forepy,forelabel] = pararc; +nSample=(yrEnd-yrStart)*q_m + (qmEnd-qmStart+1); +if qmEnd == q_m % end of the year + nSampleCal=nSample; % Cal: calendar year +else + nSampleCal=(yrEnd-1-yrStart)*q_m + (q_m-qmStart+1); % Cal: calendar year +end + +%* More script variables +% +lags = 13; % <<>> +% automatic decay code (monthly data), only two options: lags = 6 or 13 +forepq = forep/3; % quarterly +actup = 5*48; % <<>> actual periods before forecasting (20 years) +%actup = 12*floor(nSample/12); % <<>> actual periods before forecasting (8 years) +actup = 48; % <<>> actual periods before forecasting (4 years) +actupq = actup/3; % quarterly +actupy = actup/12; % four years +imstp = 48; % <<>> impulse responses (4 years) +ninv = 1000; % the number of intervals for counting impulse responses +nhp = 6; % <<>> number of hyperparameters for estimation +%%scf = 2.4/sqrt(nvar); % scf^2*Sigma (covaraince) +scf = 0.25; % scf^2*Sigma (covaraince) +ndraws1=15; % 1500, 1st part of Monte Carlo draws +ndraws2=2*ndraws1; % 2nd part of Monte Carlo draws +ndraws=3*ndraws2 % a total number of Monte Carlo draws +nstarts=3; % number of starting points +imndraws = nstarts*ndraws2; +tdf = 3; % degrees of freedom for t-dist +ga = tdf/2; % asymmetry parameter in Gamma +gb = 2/tdf; % normalized parameter in Gamma +% +%* ================================================= +%* ====== End of the script ======================== +%* ================================================= + + +if (q_m==12) + nStart=(yrStart-yrBin)*12+qmStart-qmBin; % positive number of months at the start + nEnd=(yrEnd-yrFin)*12+qmEnd-qmFin; % negative number of months towards end +elseif (q_m==4) + nStart=(yrStart-yrBin)*4+qmStart-qmBin; % positive number of months at the start + nEnd=(yrEnd-yrFin)*4+qmEnd-qmFin; % negative number of months towards end +else + disp('Warning: this code is only good for monthly/quarterly data!!!') + return +end +% +if nEnd>0 | nStart<0 + disp('Warning: this particular sample consider is out of bounds of the data!!!') + return +end +% +xdgel=xdd(nStart+1:nData+nEnd,vlist); % gel: general term for selected xdd +xdata=xdd(nStart+1:nData,vlist); + +[Gb,Sbd,Bh,SpH,fss,ndobs,phi,y,nvar,ncoef,xxhpc,a0indx,na0p,... + idmat0,idmatpp] = szasbvar(idfile,q_m,lags,nSample,nhp,xdgel); + +% * the largest matrix in this file <<>> +yforew = zeros(ndraws,forep*nvar); % preallocating +yforeqgw = zeros(ndraws,forepq*nvar); % preallocating +yforeCalygw = zeros(ndraws,forepy*nvar); % preallocating +% * the largest matrix in this file <<>> +%%imfcnt = zeros(ninv+2,imstp*nvar^2); % cnt: count + +load idenml % xhat ghat fhat, etc. +%load outiden % xhat ghat fhat + +%================== +% Impulse responses first +%================== +%A0 = zeros(nvar); +%A0(a0indx)=xhat; +%A0(4,2) = -xhat(7); % output in MD +%A0(5,2)=-xhat(7); % price in MD +A0in = inv(A0); +swish = A0in'; % each row corresponds to an equation +%Bh = Hm1t; % no longer have Hm1t in this new szasbvar + +% ** impulse responses +nn = [nvar lags imstp]; +imf = zimpulse(Bh,swish,nn); % in the form that is congenial to RATS +%[vd,str,imf] = errors(Bh,swish,nn); + +scaleout = imcgraph(imf,nvar,imstp,xlab,ylab) + + +%%%% +%$$$ Out-of-sample forecasts. Note: Hm1t does not change with A0. +%%%% +% +% ** out-of-sample forecast, from 82:4 to 84:3 (flp+1:flp+forep) +% * updating the last row of X (phi) with the current (last row of) y. +phil = phi(size(phi,1),:); +phil(nvar+1:ncoef-1) = phil(1:ncoef-1-nvar); +phil(1:nvar) = y(size(y,1),:); +ylast = y(size(y,1),:); +indx12 = size(y,1)-q_m+1:size(y,1); +ylast12 = y(indx12,:); % last 12 months data +nn = [nvar lags forep]; +% +yfore = forecast(Bh,phil,nn); % forep-by-nvar + + +%>>>>>>>>>>>>>>> +yforel=yfore; +yforel(:,vlistlog) = exp(yfore(:,vlistlog)); +figure; +t2=1:forep; +for i = 1:nvar + subplot(nvar/2,2,i) + plot(t2,yforel(:,i),'--') + %title('solid-actual, dotted-forecast'); + %title(eval(['forelabel'])); + %ylabel(eval(['x' int2str(i)])); + ylabel(char(ylab(i))) +end +%<<<<<<<<<<<<<<< + +%%%%%%%% +% +%% See Zha's note "Forecast (1)" p. 5, RATS manual (some errors in RATS), etc. +% +%% Some notations: y(t+1) = y(t)B1 + e(t+1)inv(A0). e(t+1) is 1-by-n. +%% Let r(t+1)=e(t+1)inv(A0) + e(t+2)C + .... where inv(A0) is impulse +%% response at t=1, C at t=2, etc. The row of inv(A0) or C is +%% all responses to one shock. +%% Let r be q-by-1 (such as r(1) = r(t+1) +%% = y(t+1) (constrained) - y(t+1) (forecast)). +%% Use impulse responses to find out R (k-by-q) where k=nvar*nsteps +%% where nsteps the largest constrained step. The key of the program +%% is to creat R using impulse responses +%% Optimal solution for shock e where R'*e=r and e is k-by-1 is +%% e = R*inv(R'*R)*r. +% +%%%%%%%% + +nconstr=4; % q: 4 years -- 4*12 months +eq_ms = 2; % location of MS equation +%eq_ms = []; % all shocks +%*** initializing +stepcon=cell(nconstr,1); % initializing, value y conditioned +valuecon=zeros(nconstr,1); % initializing, value y conditioned +varcon=zeros(nconstr,1); % initializing, endogous variables conditioned +% +stepcon{1}=[1:12]'; % average over 12 months. +stepcon{2}=[13:24]'; % average over 12 months. +stepcon{3}=[25:36]'; % average over 12 months. +stepcon{4}=[37:48]'; % average over 12 months. +% +%for i=1:nconstr +% stepcon{i}=i; +%end +% +chk1 = mean(yfore(stepcon{1},3)) +chk2 = mean(yfore(stepcon{2},3)) +chk3 = mean(yfore(stepcon{3},3)) +chk4 = mean(yfore(stepcon{4},3)) +Ro=[chk1 chk2 chk3 chk4]; +% +chk1 = exp( (sum(yfore(stepcon{1},5))-sum(ylast12(:,5))) ./ q_m ) +chk2 = exp( (sum(yfore(stepcon{2},5))-sum(yfore(stepcon{1},5))) ./ q_m ) +chk3 = exp( (sum(yfore(stepcon{3},5))-sum(yfore(stepcon{2},5))) ./ q_m ) +chk4 = exp( (sum(yfore(stepcon{4},5))-sum(yfore(stepcon{3},5))) ./ q_m ) +% +%valuecon(:)=0.055; +% +%>>>>>>>>>>>>>>>>> E: Condition on funds rate path >>>>>>>>>>>>> Toggle +%delta=0.0010; +%valuecon(1) = mean(yfore(stepcon{1},3))+2*delta; +%valuecon(2) = mean(yfore(stepcon{2},3))+2*delta; +%valuecon(3) = mean(yfore(stepcon{3},3))-2*delta; +%valuecon(4) = mean(yfore(stepcon{4},3))-2*delta; +%valuecon(1) = 0.055; +%valuecon(2) = 0.050; +%valuecon(3) = 0.0475; +%valuecon(4) = 0.045; +%>>>>>>>>>>>>>>>>> E: Condition on funds rate path >>>>>>>>>>>>> +% +%<<<<<<<<<<<<<<<< B: Condition on inflation path <<<<<<<<<< Toggle +%delta=0.0010; +%valuecon(1)=mean(ylast12(:,5))+log(chk1-0*delta); +%valuecon(2)=valuecon(1)+log(chk2-2*delta); +%valuecon(3)=valuecon(2)+log(chk3-6*delta); +%valuecon(4)=valuecon(3)+log(chk4-12*delta); +% % 5: CPI; 2.5%: annual inflation over 12 months, geometric means +%$$$ very good results -- following +valuecon(1)=mean(ylast12(:,5))+log(chk1); +valuecon(2)=valuecon(1)+log(1.020); +valuecon(3)=valuecon(2)+log(1.02); +valuecon(4)=valuecon(3)+log(1.02); +% % 5: CPI; 2.5%: annual inflation over 12 months, geometric means +%<<<<<<<<<<<<<<<< E: Condition on inflation path <<<<<<<<<< + +nstepsm = 0; % initializing, the maximum step in all constraints +for i=1:nconstr + nstepsm = max([nstepsm max(stepcon{i})]); +end +varcon(:)=5; % 3: FFR; 5: CPI +% +imf3=reshape(imf,size(imf,1),nvar,nvar); + % imf3: row-steps, column-nvar responses, 3rd dimension-nvar shocks +imf3s=permute(imf3,[1 3 2]); + % imf3s: permuted so that row-steps, column-nvar shocks, + % 3rd dimension-nvar responses + +[yhat,Estr] = fidencond(valuecon,stepcon,varcon,nconstr,nstepsm,nvar,lags,... + yfore,imf3s,phil,Bh,eq_ms); + +chk1 = mean(yhat(stepcon{1},3)) +chk2 = mean(yhat(stepcon{2},3)) +chk3 = mean(yhat(stepcon{3},3)) +chk4 = mean(yhat(stepcon{4},3)) +Rh=[chk1 chk2 chk3 chk4]; + +chk1 = exp( (sum(yhat(stepcon{1},5))-sum(ylast12(:,5))) ./ q_m ) +chk2 = exp( (sum(yhat(stepcon{2},5))-sum(yhat(stepcon{1},5))) ./ q_m ) +chk3 = exp( (sum(yhat(stepcon{3},5))-sum(yhat(stepcon{2},5))) ./ q_m ) +chk4 = exp( (sum(yhat(stepcon{4},5))-sum(yhat(stepcon{3},5))) ./ q_m ) + +%chk1 = mean(yhat(1:12,3)) +%chk2 = mean(yhat(13:24,3)) +%chk3 = mean(yhat(25:36,3)) +%chk4 = mean(yhat(36:48,3)) +%Rh=[chk1 chk2 chk3 chk4]; + +%chk1 = exp( (sum(yhat(1:12,5))-sum(ylast12(:,5))) ./ q_m ) +%chk2 = exp( (sum(yhat(13:24,5))-sum(yhat(1:12,5))) ./ q_m ) +%chk3 = exp( (sum(yhat(25:36,5))-sum(yhat(13:24,5))) ./ q_m ) +%chk4 = exp( (sum(yhat(37:48,5))-sum(yhat(25:36,5))) ./ q_m ) + + +idiff=mean(yfore(:,3))-mean(yhat(:,3)) +mean(yfore(:,3)) +mean(yhat(:,3)) +figure +plot(1:48,yfore(:,3),1:48,yhat(:,3),':') +figure +plot(1:4,Ro,1:4,Rh,':') + +%>>>>>>>>>>>>>>> +yhatl=yhat; +yhatl(:,vlistlog) = exp(yhat(:,vlistlog)); +figure; +t2=1:forep; +for i = 1:nvar + subplot(nvar/2,2,i) + plot(t2,yhatl(:,i),'--') + %title('solid-actual, dotted-forecast'); + %title(eval(['forelabel'])); + %ylabel(eval(['x' int2str(i)])); + ylabel(char(ylab(i))) +end +%<<<<<<<<<<<<<<< + + +% inputs needed. +%yfore=yhat; + +%=================================================== +%%% Converting to calendar years and all at level +%=================================================== +[yforeml,yforeqgml,yforeCalygml] = fore_cal(yhat,xdata,nvar,nSample,... + nSampleCal,forep,forepq,forepy,q_m,qmEnd,vlist,vlistlog); + +%================== +% Note +%================= +% ? 1--median; l--lower bound; h--upper bound: between the bound: 2/3 probability +% yfore? % monthly, level +% yforeqg? % quarterly, growth rate +% yforeCalyg? % calendar year, growth rate + +%save outw ndraws yfore1 yforeqg1 yforeCalyg1 yforel yforeqgl yforeh yforeqgh ... +% yforeCalygl yforeCalygh IUbeta + +yforeCalygml + + +%---------------------------------------------------------------------- +%================= Graphics ===================== +%---------------------------------------------------------------------- +% + +%[yactCalyg,yforeCalygml,yAg,yFg] = fore_gh(xdata,nvar,nSample,nSampleCal,... +% yforeml,yforeqgml,yforeCalygml,actup,actupq,actupy,... +% vlist,vlistlog,vlistper,q_m,forep,ylab); + +xinput = cell(16,1); +xinput{1}=xdata; xinput{2}=nvar; xinput{3}=nSample; xinput{4}=nSampleCal; +xinput{5}=yforeml; xinput{6}=yforeqgml; xinput{7}=yforeCalygml; xinput{8}=actup; +xinput{9}=actupq; xinput{10}=actupy; xinput{11}=vlist; xinput{12}=vlistlog; +xinput{13}=vlistper; xinput{14}=q_m; xinput{15}=forep; xinput{16}=ylab; +[yactCalyg,yforeCalygml,yAg,yFg] = fore_gh(xinput); + + +% Key Macroeconomic Variables: GDP, CPI, U +%******* From Goldbook July 1-2, 1997 FOMC +yforeBlue = [ + 3.6 2.4 5.0 + 2.5 2.6 5.0 + ]; % real GDP, CPI-U, U, +yforeMacro = [ + 3.7 2.3 4.9 + 2.1 2.4 4.9 + ]; % real GDP, CPI-U, U +yforeGold = [ + 3.8 2.4 5.0 + 2.5 2.5 4.8 + 2.4 2.7 4.7 + ]; % real GDP, CPI-U, U +t3 = yAg+1:yAg+length(yforeBlue(:,1)); +t4 = yAg+1:yAg+length(yforeGold(:,1)); +% +keyindx = [4:nvar 3 2]; % GdP, CPI, U, FFR, M2 +count=0; +t1 = 1:yAg; +t2 = yAg:yAg+yFg; +for i = keyindx + count = count+1; + subplot(3,2,count) + %plot(t1,yactqg(:,i),t2,yforeqg(:,i),':') + if (i==3) | (i==2) + plot(t1,yactCalyg(:,i),t2,[yactCalyg(length(t1),i);yforeCalygml(:,i)],'--') + %title('solid-actual, dotted-forecast'); + %xlabel(eval(['forelabel'])); + %ylabel(eval(['x' int2str(i)])); + ylabel(char(ylab(i))) + else + plot(t1,yactCalyg(:,i),t2,[yactCalyg(length(t1),i);yforeCalygml(:,i)],'--',... + t3,yforeBlue(:,count),'o',t3,yforeMacro(:,count),'d',... + t4,yforeGold(:,count),'^') + %title('solid-actual, dotted-forecast'); + %xlabel(eval(['forelabel'])); + %ylabel(eval(['x' int2str(i)])); + ylabel(char(ylab(i))) + end +end + +actual=yactCalyg(:,keyindx) % GDP, CPI, U, M2 +mode=yforeCalygml(:,keyindx) % GDP, CPI, U, M2 +%low=yforeCalygl(:,keyindx) +%high=yforeCalygh(:,keyindx) +yforeBlue +yforeMacro +yforeGold \ No newline at end of file diff --git a/MatlabFiles/chol2.m b/MatlabFiles/chol2.m new file mode 100755 index 0000000..89395ba --- /dev/null +++ b/MatlabFiles/chol2.m @@ -0,0 +1,14 @@ +function R = chol2(A) +% R = chol2(A) +% +% Returns an upper triangular R such that % R * R' is a factorization of +% a symmetric, positive definite A +% +% Written by Tao Zha, July 1996 + +%* The following two lines give another expression of the same result +%%function [R,p] = chol2(A) +%%[R,p] = chol(fliplr(flipud(A))); + +R = chol(fliplr(flipud(A))); +R = fliplr(flipud(R))'; diff --git a/MatlabFiles/clgls.m b/MatlabFiles/clgls.m new file mode 100755 index 0000000..fa150e9 --- /dev/null +++ b/MatlabFiles/clgls.m @@ -0,0 +1,50 @@ +function [bhat,Vq,ACt,uqhat,q2] = clgls(a,yq,Xq,C,qm,mT,qT) +%function [bhat,Vq,ACt,uqhat,q2] = clgls(a,yq,Xq,C,qm,mT,qT) +% bhat = inv[Xq' * inv(Vq) * Xq] * Xq' * inv(Vq) * yq +% Vq = C*A*C' +% ACt = A*C' +% uqhat = yq - Xq * bhat +% +% Written by E.M. Leeper +% Modified by T. Zha, 5/6/97 + + +%*** The following creation of Ahat may be inefficient, T.Z., 5/7/97 +Ahat = eye(mT,mT); +i = 1; +arow = zeros(1,mT-1); +while i <= mT-1 + arow(1,i) = a^i; + i = i + 1; +end +i = 1; +while i <= mT-1 + Ahat(i,i+1:mT) = arow(1,1:mT-i); + i = i + 1; +end +Ahat = Ahat + Ahat' - eye(mT,mT); + + + +%*** GLS to estimate bhat +ACt = Ahat*C'; +Vq = C*ACt; +Xqt = Xq'; +%CACinv = inv(CAhatC); commented out by T.Z., not necessary +%XqCACinv = Xq' * CACinv; commented out by T.Z., not necessary +bhat = ((Xqt/Vq)*Xq)\(Xqt*(Vq\yq)); +uqhat = yq - Xq * bhat; + +%*** compute the new quarterly coefficeint "q2" +uqlag = zeros(qT-1,1); +uqlag = uqhat(1:qT-1,1); +uqc = uqhat(2:qT,1); +[u d v]=svd(uqlag,0); %trial +dinv = 1./diag(d); % inv(diag(d)) +vd=v.*(ones(size(v,2),1)*diag(d)'); %trial +vdinv=v.*(ones(size(v,2),1)*dinv'); %trial +xtxinv = vdinv*vdinv'; +uy = u'*uqc; %trial +xty = vd*uy; %trial +%Bh = xtx\xty; %inv(X'X)*(X'Y), k*m (ncoe*nvar). +q2 = xtxinv*xty; % initial q \ No newline at end of file diff --git a/MatlabFiles/clmonq.m b/MatlabFiles/clmonq.m new file mode 100755 index 0000000..45c9460 --- /dev/null +++ b/MatlabFiles/clmonq.m @@ -0,0 +1,25 @@ +function a = clmonq(q) +% function a = monq(q) +% Find the monthly AR coefficient for interpolated data given +% an estimate of the quarterly AR coefficient +% Written by E.M. Leeper +% +% First take the quarterly AR coefficient, q, and then +% seek the root, a, that solves +% q = (a^5 + 2 a^4 + 3 a^3 + 2 a^2 + a) / (2 a^2 + 4 a + 3) (1) + +% if n = numerator poly and d = denominator poly in (1) +n = [1 2 3 2 1 0]; +d = [2 4 3]; +ln = length(n); +ld = length(d); +pad = ln - ld; +dd = [zeros(1,pad) d]; +qdd = q.*dd; +newpol = n - qdd; +r = roots(newpol); +for i = 1:length(r) + if imag(r(i)) == 0 + a = r(i); + end +end diff --git a/MatlabFiles/csminit.m b/MatlabFiles/csminit.m new file mode 100755 index 0000000..b31acec --- /dev/null +++ b/MatlabFiles/csminit.m @@ -0,0 +1,199 @@ +function [fhat,xhat,fcount,retcode] = csminit(fcn,x0,f0,g0,badg,H0,varargin) +% [fhat,xhat,fcount,retcode] = csminit(fcn,x0,f0,g0,badg,H0,... +% P1,P2,P3,P4,P5,P6,P7,P8) +% retcodes: 0, normal step. 5, largest step still improves too fast. +% 4,2 back and forth adjustment of stepsize didn't finish. 3, smallest +% stepsize still improves too slow. 6, no improvement found. 1, zero +% gradient. +%--------------------- +% Modified 7/22/96 to omit variable-length P list, for efficiency and compilation. +% Places where the number of P's need to be altered or the code could be returned to +% its old form are marked with ARGLIST comments. +% +% Fixed 7/17/93 to use inverse-hessian instead of hessian itself in bfgs +% update. +% +% Fixed 7/19/93 to flip eigenvalues of H to get better performance when +% it's not psd. +% +% Fixed 02/19/05 to correct for low angle problems. +% +%tailstr = ')'; +%for i=nargin-6:-1:1 +% tailstr=[ ',P' num2str(i) tailstr]; +%end + +dispIndx = 1; % 1: turn on all the diplays on the screen; 0: turn off (Added by T. Zha) + + +%ANGLE = .03; % when output of this variable becomes negative, we have wrong analytical graident +ANGLE = .005; % works for identified VARs and OLS +%THETA = .03; +THETA = .3; %(0<THETA<.5) THETA near .5 makes long line searches, possibly fewer iterations. +FCHANGE = 1000; +MINLAMB = 1e-9; +% fixed 7/15/94 +% MINDX = .0001; +% MINDX = 1e-6; +MINDFAC = .01; +fcount=0; +lambda=1; +xhat=x0; +f=f0; +fhat=f0; +g = g0; +gnorm = norm(g); +% +if (gnorm < 1.e-12) & ~badg % put ~badg 8/4/94 + retcode =1; + dxnorm=0; + % gradient convergence +else + % with badg true, we don't try to match rate of improvement to directional + % derivative. We're satisfied just to get some improvement in f. + % + %if(badg) + % dx = -g*FCHANGE/(gnorm*gnorm); + % dxnorm = norm(dx); + % if dxnorm > 1e12 + % disp('Bad, small gradient problem.') + % dx = dx*FCHANGE/dxnorm; + % end + %else + % Gauss-Newton step; + %---------- Start of 7/19/93 mod --------------- + %[v d] = eig(H0); + %toc + %d=max(1e-10,abs(diag(d))); + %d=abs(diag(d)); + %dx = -(v.*(ones(size(v,1),1)*d'))*(v'*g); +% toc + dx = -H0*g; +% toc + dxnorm = norm(dx); + if dxnorm > 1e12 + if dispIndx, disp('Near-singular H problem.'), end + dx = dx*FCHANGE/dxnorm; + end + dfhat = dx'*g0; + %end + % + % + if ~badg + % test for alignment of dx with gradient and fix if necessary + a = -dfhat/(gnorm*dxnorm); + if a<ANGLE + dx = dx - (ANGLE*dxnorm/gnorm+dfhat/(gnorm*gnorm))*g; + % suggested alternate code: --------------------- + dx = dx*dxnorm/norm(dx); % Added 02/19/05 by CAS. This keeps scale invariant to the angle correction + % ------------------------------------------------ + dfhat = dx'*g; + % dxnorm = norm(dx); % Removed 02/19/05 by CAS. This line unnecessary with modification that keeps scale invariant + if dispIndx, disp(sprintf('Correct for low angle: %g',a)), end + end + end + if dispIndx, disp(sprintf('Predicted improvement: %18.9f',-dfhat/2)), end + % + % Have OK dx, now adjust length of step (lambda) until min and + % max improvement rate criteria are met. + done=0; + factor=3; + shrink=1; + lambdaMin=0; + lambdaMax=inf; + lambdaPeak=0; + fPeak=f0; + lambdahat=0; + while ~done + if size(x0,2)>1 + dxtest=x0+dx'*lambda; + else + dxtest=x0+dx*lambda; + end + % home + f = feval(fcn,dxtest,varargin{:}); + %ARGLIST + %f = feval(fcn,dxtest,P1,P2,P3,P4,P5,P6,P7,P8,P9,P10,P11,P12,P13); + % f = feval(fcn,x0+dx*lambda,P1,P2,P3,P4,P5,P6,P7,P8); + if dispIndx, disp(sprintf('lambda = %10.5g; f = %20.7f',lambda,f )), end + %debug + %disp(sprintf('Improvement too great? f0-f: %g, criterion: %g',f0-f,-(1-THETA)*dfhat*lambda)) + if f<fhat + fhat=f; + xhat=dxtest; + lambdahat = lambda; + end + fcount=fcount+1; + shrinkSignal = (~badg & (f0-f < max([-THETA*dfhat*lambda 0]))) | (badg & (f0-f) < 0) ; + growSignal = ~badg & ( (lambda > 0) & (f0-f > -(1-THETA)*dfhat*lambda) ); + if shrinkSignal & ( (lambda>lambdaPeak) | (lambda<0) ) + if (lambda>0) & ((~shrink) | (lambda/factor <= lambdaPeak)) + shrink=1; + factor=factor^.6; + while lambda/factor <= lambdaPeak + factor=factor^.6; + end + %if (abs(lambda)*(factor-1)*dxnorm < MINDX) | (abs(lambda)*(factor-1) < MINLAMB) + if abs(factor-1)<MINDFAC + if abs(lambda)<4 + retcode=2; + else + retcode=7; + end + done=1; + end + end + if (lambda<lambdaMax) & (lambda>lambdaPeak) + lambdaMax=lambda; + end + lambda=lambda/factor; + if abs(lambda) < MINLAMB + if (lambda > 0) & (f0 <= fhat) + % try going against gradient, which may be inaccurate + if dispIndx, lambda = -lambda*factor^6, end + else + if lambda < 0 + retcode = 6; + else + retcode = 3; + end + done = 1; + end + end + elseif (growSignal & lambda>0) | (shrinkSignal & ((lambda <= lambdaPeak) & (lambda>0))) + if shrink + shrink=0; + factor = factor^.6; + %if ( abs(lambda)*(factor-1)*dxnorm< MINDX ) | ( abs(lambda)*(factor-1)< MINLAMB) + if abs(factor-1)<MINDFAC + if abs(lambda)<4 + retcode=4; + else + retcode=7; + end + done=1; + end + end + if ( f<fPeak ) & (lambda>0) + fPeak=f; + lambdaPeak=lambda; + if lambdaMax<=lambdaPeak + lambdaMax=lambdaPeak*factor*factor; + end + end + lambda=lambda*factor; + if abs(lambda) > 1e20; + retcode = 5; + done =1; + end + else + done=1; + if factor < 1.2 + retcode=7; + else + retcode=0; + end + end + end +end +if dispIndx, disp(sprintf('Norm of dx %10.5g', dxnorm)), end diff --git a/MatlabFiles/csminit.m0 b/MatlabFiles/csminit.m0 new file mode 100755 index 0000000..1af99f8 --- /dev/null +++ b/MatlabFiles/csminit.m0 @@ -0,0 +1,163 @@ +function [fhat,xhat,fcount,retcode] = csminit(fcn,x0,f0,g0,badg,H0,... + P1,P2,P3,P4,P5,P6,P7,P8,P9,P10,P11,P12,P13,P14,P15,P16,P17,... + P18,P19,P20) +% [fhat,xhat,fcount,retcode] = csminit(fcn,x0,f0,g0,badg,H0,... +% P1,P2,P3,P4,P5,P6,P7,P8) +% retcodes: 0, normal step. 5, largest step still improves too fast. +% 4,2 back and forth adjustment of stepsize didn't finish. 3, smallest +% stepsize still improves too slow. 6, no improvement found. 1, zero +% gradient. +%--------------------- +% Modified 7/22/96 to omit variable-length P list, for efficiency and compilation. +% Places where the number of P's need to be altered or the code could be returned to +% its old form are marked with ARGLIST comments. +% +% Fixed 7/17/93 to use inverse-hessian instead of hessian itself in bfgs +% update. +% +% Fixed 7/19/93 to flip eigenvalues of H to get better performance when +% it's not psd. +% +tailstr = ')'; +for i=nargin-6:-1:1 + tailstr=[ ',P' num2str(i) tailstr]; +end +%ANGLE = .03; +ANGLE = .005; +%THETA = .03; +THETA = .1; +FCHANGE = 1000; +MINLAMB = 1e-9; +% fixed 7/15/94 +% MINDX = .0001; +% MINDX = 1e-6; +MINDFAC = .01; +fcount=0; +lambda=1; +lambdahat=1; +xhat=x0; +f=f0; +fhat=f0; +g = g0; +gnorm = norm(g); +% +if (gnorm < 1.e-12) & ~badg % put ~badg 8/4/94 + retcode =1; + % gradient convergence +else + % with badg true, we don't try to match rate of improvement to directional + % derivative. We're satisfied just to get some improvement in f. + % + %if(badg) + % dx = -g*FCHANGE/(gnorm*gnorm); + % dxnorm = norm(dx); + % if dxnorm > 1e12 + % disp('Bad, small gradient problem.') + % dx = dx*FCHANGE/dxnorm; + % end + %else + % Gauss-Newton step; + %---------- Start of 7/19/93 mod --------------- + %[v d] = eig(H0); + %toc + %d=max(1e-10,abs(diag(d))); + %d=abs(diag(d)); + %dx = -(v.*(ones(size(v,1),1)*d'))*(v'*g); +% toc + dx = -H0*g; +% toc + dxnorm = norm(dx); + if dxnorm > 1e12 + disp('Near-singular H problem.') + dx = dx*FCHANGE/dxnorm; + end + dfhat = dx'*g0; + %end + % + % + if ~badg + % test for alignment of dx with gradient and fix if necessary + a = -dfhat/(gnorm*dxnorm); + if a<ANGLE + dx = dx - (ANGLE*dxnorm/gnorm+dfhat/(gnorm*gnorm))*g; + dfhat = dx'*g; + dxnorm = norm(dx); + disp(sprintf('Correct for low angle: %g',a)) + end + end + end + disp(sprintf('Predicted improvement: %18.9f',-dfhat/2)) + % + % Have OK dx, now adjust length of step (lambda) until min and + % max improvement rate criteria are met. + done=0; + factor=3; + shrink=1; + while ~done + if size(x0,2)>1 + dxtest=x0+dx'*lambda; + else + dxtest=x0+dx*lambda; + end + % home + f = eval([fcn '(dxtest' tailstr]); + %ARGLIST + %f = feval(fcn,dxtest,P1,P2,P3,P4,P5,P6,P7,P8,P9,P10,P11,P12,P13); + % f = feval(fcn,x0+dx*lambda,P1,P2,P3,P4,P5,P6,P7,P8); + disp(sprintf('lambda = %10.5g; f = %20.7f',lambda,f )) + %debug + %disp(sprintf('Improvement too great? f0-f: %g, criterion: %g',f0-f,-(1-THETA)*dfhat*lambda)) + if f<fhat + fhat=f; + xhat=dxtest; + lambdahat = lambda; + end + fcount=fcount+1; + if (~badg & (f0-f < max([-THETA*dfhat*lambda 0]))) | ... + (badg & (f0-f) < 0) + if ~shrink + shrink=1; + factor=factor^.6; + %if (abs(lambda)*(factor-1)*dxnorm < MINDX) | (abs(lambda)*(factor-1) < MINLAMB) + if abs(factor-1)<MINDFAC + retcode=2; + done=1; + end + end + lambda=lambda/factor; + if abs(lambda) < MINLAMB + if (lambda > 0) & (f0 <= fhat) + % try going against gradient, which may be inaccurate + lambda = -lambda*factor^6 + else + if lambda < 0 + retcode = 6; + else + retcode = 3; + end + done = 1; + end + end + elseif ~badg & ( (lambda > 0) & (f0-f > -(1-THETA)*dfhat*lambda) ) + if shrink + shrink=0; + factor = factor^.6; + %if ( abs(lambda)*(factor-1)*dxnorm< MINDX ) | ( abs(lambda)*(factor-1)< MINLAMB) + if abs(factor-1) < MINDFAC + retcode = 4; + done=1; + end + end + lambda=lambda*factor; + if abs(lambda) > 1e20; + retcode = 5; + done =1; + end + else + done=1; + retcode=0; + end + end +end +disp(sprintf('Norm of dx %10.5g', dxnorm)) + \ No newline at end of file diff --git a/MatlabFiles/csminit.m1 b/MatlabFiles/csminit.m1 new file mode 100755 index 0000000..6990dc0 --- /dev/null +++ b/MatlabFiles/csminit.m1 @@ -0,0 +1,147 @@ +function [fhat,xhat,fcount,retcode] = csminit(fcn,x0,f0,g0,badg,H0,... + P1,P2,P3,P4,P5,P6,P7,P8,P9,P10,P11,P12,P13,P14,P15,P16,P17,... + P18,P19,P20) +% [fhat,xhat,fcount,retcode] = csminit(fcn,x0,f0,g0,badg,H0,... +% P1,P2,P3,P4,P5,P6,P7,P8) +% retcodes: 0, normal step. 5, largest step still improves too fast. +% 4,2 back and forth adjustment of stepsize didn't finish. 3, smallest +% stepsize still improves too slow. 6, no improvement found. 1, zero +% gradient. +%--------------------- +% Fixed 7/17/93 to use inverse-hessian instead of hessian itself in bfgs +% update. +% +% Fixed 7/19/93 to flip eigenvalues of H to get better performance when +% it's not psd. +% +tailstr = ')'; +for i=nargin-6:-1:1 + tailstr=[ ',P' num2str(i) tailstr]; +end +ANGLE = .03; +%%THETA = .03; +THETA = 0.1; % TZ, mod 8/11/96 +FCHANGE = 1000; +MINLAMB = 1e-9; +% fixed 7/15/94 +% MINDX = .0001; +MINDX = 1e-6; +fcount=0; +lambda=1; +lambdahat=1; +xhat=x0; +f=f0; +fhat=f0; +g = g0; +gnorm = norm(g); +% +if (gnorm < 1.e-12) & ~badg % put ~badg 8/4/94 + retcode =1; + % gradient convergence +else + % with badg true, we don't try to match rate of improvement to directional + % derivative. We're satisfied just to get some improvement in f. + % + %if(badg) + % dx = -g*FCHANGE/(gnorm*gnorm); + % dxnorm = norm(dx); + % if dxnorm > 1e12 + % disp('Bad, small gradient problem.') + % dx = dx*FCHANGE/dxnorm; + % end + %else + % Gauss-Newton step; + %---------- Start of 7/19/93 mod --------------- + [v d] = eig(H0); + %% 1e5*diag(d)'; % Tao Zha + d=max(1e-10,abs(diag(d))); + dx = -v*diag(d)*v'*g; + %dx = -H0*g; + dxnorm = norm(dx); + if dxnorm > 1e12 + disp('Near-singular H problem.') + dx = dx*FCHANGE/dxnorm; + end + dfhat = dx'*g0; + %end + % + % + if ~badg + % test for alignment of dx with gradient and fix if necessary + a = -dfhat/(gnorm*dxnorm); + if a<ANGLE + dx = dx - (ANGLE*dxnorm/gnorm+dfhat/(gnorm*gnorm))*g; + dfhat = dx'*g; + dxnorm = norm(dx); + end + end + % + % Have OK dx, now adjust length of step (lambda) until min and + % max improvement rate criteria are met. + done=0; + factor=3; + shrink=1; + while ~done + if size(x0,2)>1 + dxtest=x0+dx'*lambda; + else + dxtest=x0+dx*lambda; + end + % home + f = eval([fcn '(dxtest' tailstr]); + % f = feval(fcn,x0+dx*lambda,P1,P2,P3,P4,P5,P6,P7,P8); + fprintf('lambda = %12g; f = %12g\n',lambda,f ) + if f<fhat + fhat=f; + xhat=dxtest; + lambdahat = lambda; + end + fcount=fcount+1; + if (~badg & (f0-f < max([-THETA*dfhat*lambda 0]))) | ... + (badg & (f0-f) < 0) + if ~shrink + shrink=1; + factor=factor^.6; + %if abs(lambda)*(factor-1)*dxnorm < MINDX + if abs(lambda)*(factor-1) < MINLAMB + retcode=2; + done=1; + end + end + lambda=lambda/factor; + %if abs(lambda) < MINLAMB% + if abs(lambda)*dxnorm < MINDX + if (lambda > 0) & (f0 <= fhat) + % try going against gradient, which may be inaccurate + lambda = -lambda*factor^6 + else + if lambda < 0 + retcode = 6; + else + retcode = 3; + end + done = 1; + end + end + elseif ~badg & ( (lambda > 0) & (f0-f > -(1-THETA)*dfhat*lambda) ) + if shrink + shrink=0; + factor = factor^.6; + %if abs(lambda)*(factor-1)*dxnorm< MINDX + if abs(lambda)*(factor-1)< MINLAMB + retcode = 4; + done=1; + end + end + lambda=lambda*factor; + if abs(lambda) > 1e20; + retcode = 5; + done =1; + end + else + done=1; + retcode=0; + end + end +end + \ No newline at end of file diff --git a/MatlabFiles/csminit.m2 b/MatlabFiles/csminit.m2 new file mode 100755 index 0000000..eabf9af --- /dev/null +++ b/MatlabFiles/csminit.m2 @@ -0,0 +1,158 @@ +function [fhat,xhat,fcount,retcode] = csminit(fcn,x0,f0,g0,badg,H0,... + P1,P2,P3,P4,P5,P6,P7,P8,P9,P10,P11,P12,P13,P14,P15,P16,P17,... + P18,P19,P20) +% [fhat,xhat,fcount,retcode] = csminit(fcn,x0,f0,g0,badg,H0,... +% P1,P2,P3,P4,P5,P6,P7,P8) +% retcodes: 0, normal step. 5, largest step still improves too fast. +% 4,2 back and forth adjustment of stepsize didn't finish. 3, smallest +% stepsize still improves too slow. 6, no improvement found. 1, zero +% gradient. +%--------------------- +% Modified 7/22/96 to omit variable-length P list, for efficiency and compilation. +% Places where the number of P's need to be altered or the code could be returned to +% its old form are marked with ARGLIST comments. +% +% Fixed 7/17/93 to use inverse-hessian instead of hessian itself in bfgs +% update. +% +% Fixed 7/19/93 to flip eigenvalues of H to get better performance when +% it's not psd. +% +tailstr = ')'; +for i=nargin-6:-1:1 + tailstr=[ ',P' num2str(i) tailstr]; +end +ANGLE = 0.005; % mod 8/12/96 +%ANGLE = .03; +THETA = 0.1; % mod 8/12/96 +%THETA = .03; +FCHANGE = 1000; +MINLAMB = 1e-9; +% fixed 7/15/94 +% MINDX = .0001; +MINDX = 1e-6; +fcount=0; +lambda=1; +lambdahat=1; +xhat=x0; +f=f0; +fhat=f0; +g = g0; +gnorm = norm(g); +% +if (gnorm < 1.e-12) & ~badg % put ~badg 8/4/94 + retcode =1; + % gradient convergence +else + % with badg true, we don't try to match rate of improvement to directional + % derivative. We're satisfied just to get some improvement in f. + % + %if(badg) + % dx = -g*FCHANGE/(gnorm*gnorm); + % dxnorm = norm(dx); + % if dxnorm > 1e12 + % disp('Bad, small gradient problem.') + % dx = dx*FCHANGE/dxnorm; + % end + %else + % Gauss-Newton step; + %---------- Start of 7/19/93 mod --------------- + %[v d] = eig(H0); + %toc + %d=max(1e-10,abs(diag(d))); + %d=abs(diag(d)); + %dx = -(v.*(ones(size(v,1),1)*d'))*(v'*g); +% toc + dx = -H0*g; +% toc + dxnorm = norm(dx); + if dxnorm > 1e12 + disp('Near-singular H problem.') + dx = dx*FCHANGE/dxnorm; + end + dfhat = dx'*g0; + %end + % + % + if ~badg + % test for alignment of dx with gradient and fix if necessary + a = -dfhat/(gnorm*dxnorm); + if a<ANGLE + dx = dx - (ANGLE*dxnorm/gnorm+dfhat/(gnorm*gnorm))*g; + dfhat = dx'*g; + dxnorm = norm(dx); + end + end + % + % Have OK dx, now adjust length of step (lambda) until min and + % max improvement rate criteria are met. + done=0; + factor=3; + shrink=1; + while ~done + if size(x0,2)>1 + dxtest=x0+dx'*lambda; + else + dxtest=x0+dx*lambda; + end + % home + f = eval([fcn '(dxtest' tailstr]); + %ARGLIST + %f = feval(fcn,dxtest,P1,P2,P3,P4,P5,P6,P7,P8,P9,P10,P11,P12,P13); + % f = feval(fcn,x0+dx*lambda,P1,P2,P3,P4,P5,P6,P7,P8); + fprintf('lambda = %12g; f = %12g\n',lambda,f ) + if f<fhat + fhat=f; + xhat=dxtest; + lambdahat = lambda; + end + fcount=fcount+1; + if (~badg & (f0-f < max([-THETA*dfhat*lambda 0]))) | ... + (badg & (f0-f) < 0) + if ~shrink + shrink=1; + factor=factor^.6; + %if abs(lambda)*(factor-1)*dxnorm < MINDX + if abs(lambda)*(factor-1) < MINLAMB + retcode=2; + done=1; + end + end + lambda=lambda/factor; + %if abs(lambda) < MINLAMB% + if abs(lambda)*dxnorm < MINDX + if (lambda > 0) & (f0 <= fhat) + % try going against gradient, which may be inaccurate + lambda = -lambda*factor^6 + else + if lambda < 0 + retcode = 6; + else + retcode = 3; + end + done = 1; + end + end + elseif ~badg & ( (lambda > 0) & (f0-f > -(1-THETA)*dfhat*lambda) ) + if shrink + shrink=0; + factor = factor^.6; + %if abs(lambda)*(factor-1)*dxnorm< MINDX + if abs(lambda)*(factor-1)< MINLAMB + retcode = 4; + done=1; + end + end + lambda=lambda*factor; + if abs(lambda) > 1e20; + retcode = 5; + done =1; + end + else + done=1; + retcode=0; + end + end +end +disp(sprintf('Norm of dx %d', dxnorm)) + \ No newline at end of file diff --git a/MatlabFiles/csminitWorksUntiil0205.m b/MatlabFiles/csminitWorksUntiil0205.m new file mode 100755 index 0000000..54b5603 --- /dev/null +++ b/MatlabFiles/csminitWorksUntiil0205.m @@ -0,0 +1,197 @@ +function [fhat,xhat,fcount,retcode] = csminit(fcn,x0,f0,g0,badg,H0,varargin) +% [fhat,xhat,fcount,retcode] = csminit(fcn,x0,f0,g0,badg,H0,... +% P1,P2,P3,P4,P5,P6,P7,P8) +% retcodes: 0, normal step. 5, largest step still improves too fast. +% 4,2 back and forth adjustment of stepsize didn't finish. 3, smallest +% stepsize still improves too slow. 6, no improvement found. 1, zero +% gradient. +%--------------------- +% Modified 7/22/96 to omit variable-length P list, for efficiency and compilation. +% Places where the number of P's need to be altered or the code could be returned to +% its old form are marked with ARGLIST comments. +% +% Fixed 7/17/93 to use inverse-hessian instead of hessian itself in bfgs +% update. +% +% Fixed 7/19/93 to flip eigenvalues of H to get better performance when +% it's not psd. +% NOTE: The display on screen can be turned off by seeting dispIndx=0 in this +% function. This option is used for the loop operation. T. Zha, 2 May 2000 + +dispIndx = 0; % 1: turn on all the diplays on the screen; 0: turn off (Added by T. Zha) + +% +%tailstr = ')'; +%for i=nargin-6:-1:1 +% tailstr=[ ',P' num2str(i) tailstr]; +%end + +%ANGLE = .01; % when output of this variable becomes negative, we have wrong analytical graident +ANGLE = .005; % works for identified VARs and OLS +%THETA = .1; % works for OLS or other nonlinear functions +THETA = .3; %(0<THETA<.5) THETA near .5 makes long line searches, possibly fewer iterations. + % workds for identified VARs +FCHANGE = 1000; +MINLAMB = 1e-9; +% fixed 7/15/94 +% MINDX = .0001; +% MINDX = 1e-6; +MINDFAC = .01; +fcount=0; +lambda=1; +xhat=x0; +f=f0; +fhat=f0; +g = g0; +gnorm = norm(g); +% +if (gnorm < 1.e-12) & ~badg % put ~badg 8/4/94 + retcode =1; + dxnorm=0; + % gradient convergence +else + % with badg true, we don't try to match rate of improvement to directional + % derivative. We're satisfied just to get some improvement in f. + % + %if(badg) + % dx = -g*FCHANGE/(gnorm*gnorm); + % dxnorm = norm(dx); + % if dxnorm > 1e12 + % disp('Bad, small gradient problem.') + % dx = dx*FCHANGE/dxnorm; + % end + %else + % Gauss-Newton step; + %---------- Start of 7/19/93 mod --------------- + %[v d] = eig(H0); + %toc + %d=max(1e-10,abs(diag(d))); + %d=abs(diag(d)); + %dx = -(v.*(ones(size(v,1),1)*d'))*(v'*g); +% toc + dx = -H0*g; +% toc + dxnorm = norm(dx); + if dxnorm > 1e12 + if dispIndx, disp('Near-singular H problem.'), end + dx = dx*FCHANGE/dxnorm; + end + dfhat = dx'*g0; + %end + % + % + if ~badg + % test for alignment of dx with gradient and fix if necessary + a = -dfhat/(gnorm*dxnorm); + if a<ANGLE + dx = dx - (ANGLE*dxnorm/gnorm+dfhat/(gnorm*gnorm))*g; + dfhat = dx'*g; + dxnorm = norm(dx); + if dispIndx, disp(sprintf('Correct for low angle: %g',a)), end + end + end + if dispIndx, disp(sprintf('Predicted improvement: %18.9f',-dfhat/2)), end + % + % Have OK dx, now adjust length of step (lambda) until min and + % max improvement rate criteria are met. + done=0; + factor=3; + shrink=1; + lambdaMin=0; + lambdaMax=inf; + lambdaPeak=0; + fPeak=f0; + lambdahat=0; + while ~done + if size(x0,2)>1 + dxtest=x0+dx'*lambda; + else + dxtest=x0+dx*lambda; + end + % home + f = eval([fcn '(dxtest,varargin{:})']); + %ARGLIST + %f = feval(fcn,dxtest,P1,P2,P3,P4,P5,P6,P7,P8,P9,P10,P11,P12,P13); + % f = feval(fcn,x0+dx*lambda,P1,P2,P3,P4,P5,P6,P7,P8); + if dispIndx, disp(sprintf('lambda = %10.5g; f = %20.7f',lambda,f )), end + %debug + %disp(sprintf('Improvement too great? f0-f: %g, criterion: %g',f0-f,-(1-THETA)*dfhat*lambda)) + if f<fhat + fhat=f; + xhat=dxtest; + lambdahat = lambda; + end + fcount=fcount+1; + shrinkSignal = (~badg & (f0-f < max([-THETA*dfhat*lambda 0]))) | (badg & (f0-f) < 0) ; + growSignal = ~badg & ( (lambda > 0) & (f0-f > -(1-THETA)*dfhat*lambda) ); + if shrinkSignal & ( (lambda>lambdaPeak) | (lambda<0) ) + if (lambda>0) & ((~shrink) | (lambda/factor <= lambdaPeak)) + shrink=1; + factor=factor^.6; + while lambda/factor <= lambdaPeak + factor=factor^.6; + end + %if (abs(lambda)*(factor-1)*dxnorm < MINDX) | (abs(lambda)*(factor-1) < MINLAMB) + if abs(factor-1) < MINDFAC + if abs(lambda)<4 + retcode = 2; + else + retcode=7; + end + done=1; + end + end + if (lambda<lambdaMax) & (lambda>lambdaPeak) + lambdaMax=lambda; + end + lambda=lambda/factor; + if abs(lambda) < MINLAMB + if (lambda > 0) & (f0 <= fhat) + % try going against gradient, which may be inaccurate + lambda = -lambda*factor^6 + else + if lambda < 0 + retcode = 6; + else + retcode = 3; + end + done = 1; + end + end + elseif (growSignal & lambda>0) | (shrinkSignal & ((lambda <= lambdaPeak) & (lambda>0))) + if shrink + shrink=0; + factor = factor^.6; + %if ( abs(lambda)*(factor-1)*dxnorm< MINDX ) | ( abs(lambda)*(factor-1)< MINLAMB) + if abs(factor-1) < MINDFAC + if abs(lambda)<4 + retcode = 4; + else + retcode=7; + end + done=1; + end + end + if ( f<fPeak ) & (lambda>0) + fPeak=f; + lambdaPeak=lambda; + if lambdaMax<=lambdaPeak + lambdaMax=lambdaPeak*factor*factor; + end + end + lambda=lambda*factor; + if abs(lambda) > 1e20; + retcode = 5; + done =1; + end + else + done=1; + if factor < 1.2 + retcode=7; + else + retcode=0; + end + end + end +end +if dispIndx, disp(sprintf('Norm of dx %10.5g', dxnorm)), end diff --git a/MatlabFiles/csminwel.m b/MatlabFiles/csminwel.m new file mode 100755 index 0000000..fd4c78f --- /dev/null +++ b/MatlabFiles/csminwel.m @@ -0,0 +1,291 @@ +function [fh,xh,gh,H,itct,fcount,retcodeh] = csminwel(fcn,x0,H0,grad,crit,nit,varargin) +%[fhat,xhat,ghat,Hhat,itct,fcount,retcodehat] = csminwel(fcn,x0,H0,grad,crit,nit,varargin) +% fcn: string naming the objective function to be minimized +% x0: initial value of the parameter vector +% H0: initial value for the inverse Hessian. Must be positive definite. +% grad: Either a string naming a function that calculates the gradient, or the null matrix. +% If it's null, the program calculates a numerical gradient. In this case fcn must +% be written so that it can take a matrix argument and produce a row vector of values. +% crit: Convergence criterion. Iteration will cease when it proves impossible to improve the +% function value by more than crit. +% nit: Maximum number of iterations. +% varargin: A list of optional length of additional parameters that get handed off to fcn each +% time it is called. +% Note that if the program ends abnormally, it is possible to retrieve the current x, +% f, and H from the files g1.mat and H.mat that are written at each iteration and at each +% hessian update, respectively. (When the routine hits certain kinds of difficulty, it +% write g2.mat and g3.mat as well. If all were written at about the same time, any of them +% may be a decent starting point. One can also start from the one with best function value.) +% NOTE: The display on screen can be turned off by seeting dispIndx=0 in this +% function. This option is used for the loop operation. T. Zha, 2 May 2000 +% NOTE: You may want to change stps to 1.0e-02 or 1.0e-03 to get a better convergence. August, 2006 + +Verbose = 1; % 1: turn on all the diplays on the screen; 0: turn off (Added by T. Zha) +dispIndx = 1; % 1: turn on all the diplays on the screen; 0: turn off (Added by T. Zha) + +[nx,no]=size(x0); +nx=max(nx,no); +NumGrad= ( ~isstr(grad) | length(grad)==0); +done=0; +itct=0; +fcount=0; +snit=100; +%tailstr = ')'; +%stailstr = []; +% Lines below make the number of Pi's optional. This is inefficient, though, and precludes +% use of the matlab compiler. Without them, we use feval and the number of Pi's must be +% changed with the editor for each application. Places where this is required are marked +% with ARGLIST comments +%for i=nargin-6:-1:1 +% tailstr=[ ',P' num2str(i) tailstr]; +% stailstr=[' P' num2str(i) stailstr]; +%end +f0 = eval([fcn '(x0,varargin{:})']); +%ARGLIST +%f0 = feval(fcn,x0,P1,P2,P3,P4,P5,P6,P7,P8,P9,P10,P11,P12,P13); +% disp('first fcn in csminwel.m ----------------') % Jinill on 9/5/95 +if f0 > 1e50, disp('Bad initial parameter.'), return, end +if NumGrad + if length(grad)==0 + [g badg] = numgradcd(fcn,x0, varargin{:}); + %ARGLIST + %[g badg] = numgradcd(fcn,x0,P1,P2,P3,P4,P5,P6,P7,P8,P9,P10,P11,P12,P13); + else + badg=any(find(grad==0)); + g=grad; + end + %numgradcd(fcn,x0,P1,P2,P3,P4); +else + [g badg] = eval([grad '(x0,varargin{:})']); + %ARGLIST + %[g badg] = feval(grad,x0,P1,P2,P3,P4,P5,P6,P7,P8,P9,P10,P11,P12,P13); +end +retcode3=101; +x=x0; +f=f0; +H=H0; +cliff=0; +while ~done + g1=[]; g2=[]; g3=[]; + %addition fj. 7/6/94 for control + if dispIndx + disp('-----------------') + disp('-----------------') + %disp('f and x at the beginning of new iteration') + disp(sprintf('f at the beginning of new iteration, %20.10f',f)) + %-----------Comment out this line if the x vector is long---------------- + disp([sprintf('x = ') sprintf('%15.8g%15.8g%15.8g%15.8g%15.8g\n',x)]); + end + %------------------------- + itct=itct+1; + [f1 x1 fc retcode1] = csminit(fcn,x,f,g,badg,H,varargin{:}); + %ARGLIST + %[f1 x1 fc retcode1] = csminit(fcn,x,f,g,badg,H,P1,P2,P3,P4,P5,P6,P7,... + % P8,P9,P10,P11,P12,P13); + % itct=itct+1; + fcount = fcount+fc; + % erased on 8/4/94 + % if (retcode == 1) | (abs(f1-f) < crit) + % done=1; + % end + % if itct > nit + % done = 1; + % retcode = -retcode; + % end + if retcode1 ~= 1 + if retcode1==2 | retcode1==4 + wall1=1; badg1=1; + else + if NumGrad + [g1 badg1] = numgradcd(fcn, x1,varargin{:}); + %ARGLIST + %[g1 badg1] = numgradcd(fcn, x1,P1,P2,P3,P4,P5,P6,P7,P8,P9,... + % P10,P11,P12,P13); + else + [g1 badg1] = eval([grad '(x1,varargin{:})']); + %ARGLIST + %[g1 badg1] = feval(grad, x1,P1,P2,P3,P4,P5,P6,P7,P8,P9,... + % P10,P11,P12,P13); + end + wall1=badg1; + % g1 + save g1 g1 x1 f1 varargin; + %ARGLIST + %save g1 g1 x1 f1 P1 P2 P3 P4 P5 P6 P7 P8 P9 P10 P11 P12 P13; + end + if wall1 % & (~done) by Jinill + % Bad gradient or back and forth on step length. Possibly at + % cliff edge. Try perturbing search direction. + % + %fcliff=fh;xcliff=xh; + if dispIndx + disp(' ') + disp('************************* Random search. *****************************************') + disp('************************* Random search. *****************************************') + disp(' ') + pause(1.0) + end + Hcliff=H+diag(diag(H).*rand(nx,1)); + if dispIndx, disp('Cliff. Perturbing search direction.'), end + [f2 x2 fc retcode2] = csminit(fcn,x,f,g,badg,Hcliff,varargin{:}); + %ARGLIST + %[f2 x2 fc retcode2] = csminit(fcn,x,f,g,badg,Hcliff,P1,P2,P3,P4,... + % P5,P6,P7,P8,P9,P10,P11,P12,P13); + fcount = fcount+fc; % put by Jinill + if f2 < f + if retcode2==2 | retcode2==4 + wall2=1; badg2=1; + else + if NumGrad + [g2 badg2] = numgradcd(fcn, x2,varargin{:}); + %ARGLIST + %[g2 badg2] = numgradcd(fcn, x2,P1,P2,P3,P4,P5,P6,P7,P8,... + % P9,P10,P11,P12,P13); + else + [g2 badg2] = eval([grad '(x2,varargin{:})']); + %ARGLIST + %[g2 badg2] = feval(grad,x2,P1,P2,P3,P4,P5,P6,P7,P8,... + % P9,P10,P11,P12,P13); + end + wall2=badg2; + % g2 + if dispIndx, badg2, end + save g2 g2 x2 f2 varargin + %ARGLIST + %save g2 g2 x2 f2 P1 P2 P3 P4 P5 P6 P7 P8 P9 P10 P11 P12 P13; + end + if wall2 + if dispIndx, disp('Cliff again. Try traversing'), end + if norm(x2-x1) < 1e-13 + f3=f; x3=x; badg3=1;retcode3=101; + else + gcliff=((f2-f1)/((norm(x2-x1))^2))*(x2-x1); + [f3 x3 fc retcode3] = csminit(fcn,x,f,gcliff,0,eye(nx),varargin{:}); + %ARGLIST + %[f3 x3 fc retcode3] = csminit(fcn,x,f,gcliff,0,eye(nx),P1,P2,P3,... + % P4,P5,P6,P7,P8,... + % P9,P10,P11,P12,P13); + fcount = fcount+fc; % put by Jinill + if retcode3==2 | retcode3==4 + wall3=1; badg3=1; + else + if NumGrad + [g3 badg3] = numgradcd(fcn, x3,varargin{:}); + %ARGLIST + %[g3 badg3] = numgradcd(fcn, x3,P1,P2,P3,P4,P5,P6,P7,P8,... + % P9,P10,P11,P12,P13); + else + [g3 badg3] = eval([grad '(x3,varargin{:})']); + %ARGLIST + %[g3 badg3] = feval(grad,x3,P1,P2,P3,P4,P5,P6,P7,P8,... + % P9,P10,P11,P12,P13); + end + wall3=badg3; + % g3 + if dispIndx, badg3, end + save g3 g3 x3 f3 varargin; + %ARGLIST + %save g3 g3 x3 f3 P1 P2 P3 P4 P5 P6 P7 P8 P9 P10 P11 P12 P13; + end + end + else + f3=f; x3=x; badg3=1; retcode3=101; + end + else + f3=f; x3=x; badg3=1;retcode3=101; + end + else + % normal iteration, no walls, or else we're finished here. + f2=f; f3=f; badg2=1; badg3=1; retcode2=101; retcode3=101; + end + else + f1=f; f2=f; f3=f; retcode2=retcode1; retcode3=retcode1; + end + %how to pick gh and xh + if f3<f & badg3==0 + if dispIndx, ih=3, end + fh=f3;xh=x3;gh=g3;badgh=badg3;retcodeh=retcode3; + elseif f2<f & badg2==0 + if dispIndx, ih=2, end + fh=f2;xh=x2;gh=g2;badgh=badg2;retcodeh=retcode2; + elseif f1<f & badg1==0 + if dispIndx, ih=1, end + fh=f1;xh=x1;gh=g1;badgh=badg1;retcodeh=retcode1; + else + [fh,ih] = min([f1,f2,f3]); + if dispIndx, disp(sprintf('ih = %d',ih)), end + %eval(['xh=x' num2str(ih) ';']) + switch ih + case 1 + xh=x1; + case 2 + xh=x2; + case 3 + xh=x3; + end %case + %eval(['gh=g' num2str(ih) ';']) + %eval(['retcodeh=retcode' num2str(ih) ';']) + retcodei=[retcode1,retcode2,retcode3]; + retcodeh=retcodei(ih); + if exist('gh') + nogh=isempty(gh); + else + nogh=1; + end + if nogh + if NumGrad + [gh badgh] = numgradcd(fcn, xh,varargin{:}); %Pointed out by Junior Maih. + %[gh badgh] = feval('numgrad',fcn,xh,varargin{:}); + else + [gh badgh] = numgradcd(fcn, xh,varargin{:}); %Pointed out by Junior Maih. + %[gh badgh] = feval('grad', xh,varargin{:}); + end + end + badgh=1; + end + %end of picking + %ih + %fh + %xh + %gh + %badgh + stuck = (abs(fh-f) < crit); + if (~badg)&(~badgh)&(~stuck) + H = bfgsi(H,gh-g,xh-x); + end + if Verbose + if dispIndx + disp('----') + disp(sprintf('Improvement on iteration %d = %18.9f',itct,f-fh)) + end + end + + if itct > nit + if dispIndx, disp('iteration count termination'), end + done = 1; + elseif stuck + if dispIndx, disp('improvement < crit termination'), end + done = 1; + end + rc=retcodeh; + if rc == 1 + if dispIndx, disp('zero gradient'), end + elseif rc == 6 + if dispIndx, disp('smallest step still improving too slow, reversed gradient'), end + elseif rc == 5 + if dispIndx, disp('largest step still improving too fast'), end + elseif (rc == 4) | (rc==2) + if dispIndx, disp('back and forth on step length never finished'), end + elseif rc == 3 + if dispIndx, disp('smallest step still improving too slow'), end + elseif rc == 7 + if dispIndx, disp('warning: possible inaccuracy in H matrix'), end + end + + f=fh; + x=xh; + g=gh; + badg=badgh; +end +% what about making an m-file of 10 lines including numgrad.m +% since it appears three times in csminwel.m diff --git a/MatlabFiles/csminwel.m1 b/MatlabFiles/csminwel.m1 new file mode 100755 index 0000000..a4c2315 --- /dev/null +++ b/MatlabFiles/csminwel.m1 @@ -0,0 +1,206 @@ +function [fh,xh,gh,H,itct,fcount,retcodeh] = csminwel(fcn,x0,H0,grad,crit,nit, ... + P1,P2,P3,P4,P5,P6,P7,P8,P9,P10,P11,P12,P13,P14,P15,P16,P17,... + P18,P19,P20) +% [fhat,xhat,ghat,Hhat,itct,fcount,retcodehat] = csminwel(fcn,x0,H0,grad,crit,nit, ... +% P1,P2,P3,P4,P5,P6,P7,P8) +% +% x0(estimated parameter) SHOULD BE A ROW VECTOR. +% +% fcn and grad are strings naming functions. If grad is null, numerical +% derivatives are used. The P parameters need not be present. They are passed +% to fcn as additional arguments. +% +% +[nx,no]=size(x0); +nx=max(nx,no); +Verbose=1; +NumGrad= ( ~isstr(grad) | length(grad)==0); +done=0; +itct=0; +fcount=0; +snit=100; +tailstr = ')'; +stailstr = []; +for i=nargin-6:-1:1 + tailstr=[ ',P' num2str(i) tailstr]; + stailstr=[' P' num2str(i) stailstr]; +end +f0 = eval([fcn '(x0' tailstr]); +% disp('first fcn in csminwel.m ----------------') % Jinill on 9/5/95 +% f0 = feval(fcn,x0,P1,P2,P3,P4,P5,P6,P7,P8); +if f0 > 1e50, disp('Bad initial parameter.'), return, end +if NumGrad + if length(grad)==0 + [g badg] = eval(['numgrad(fcn, x0' tailstr]); + else + badg=any(find(grad==0)); + g=grad; + end + %numgrad(fcn,x0,P1,P2,P3,P4,P5,P6,P7,P8); +else + [g badg] = eval([grad '(x0' tailstr]); + % feval(grad,x0,P1,P2,P3,P4,P5,P6,P7,P8); +end +x=x0; +f=f0; +H=H0; +cliff=0; +while ~done +g1=[]; g2=[]; g3=[]; +%addition fj. 7/6/94 for control +disp('-----------------') +disp('-----------------') +disp('f and x at the beginning of new iteration') +f +if size(x,1)>size(x,2) + x' +else + x +end +%------------------------- + itct=itct+1; + disp(' going to start csminit.m to produce f1') + [f1 x1 fc retcode1] = eval(['csminit(fcn,x,f,g,badg,H' tailstr]); + % itct=itct+1; + fcount = fcount+fc; + % erased on 8/4/94 + % if (retcode == 1) | (abs(f1-f) < crit) + % done=1; + % end + % if itct > nit + % done = 1; + % retcode = -retcode; + % end + if retcode1 ~= 1 + if retcode1==2 | retcode1==4 + wall1=1; badg1=1; + else + if NumGrad, [g1 badg1] = eval(['numgrad(fcn, x1' tailstr]); + else, [g1 badg1] = eval([grad '(x1' tailstr]); + end + wall1=badg1; + % g1 + badg1 + eval(['save hxg.dat g1 x1 f1 ' stailstr]); + end + if wall1 % & (~done) by Jinill + % Bad gradient or back and forth on step length. Possibly at + % cliff edge. Try perturbing search direction. + % + %fcliff=fh;xcliff=xh; + Hcliff=H+diag(diag(H).*rand(nx,1)); + disp('Cliff. Perturbing search direction.') + [f2 x2 fc retcode2] = eval(['csminit(fcn,x,f,g,badg,Hcliff' tailstr]); + fcount = fcount+fc; % put by Jinill + if f2 < f + if retcode2==2 | retcode2==4 + wall2=1; badg2=1; + else + if NumGrad, [g2 badg2] = eval(['numgrad(fcn, x2' tailstr]); + else, [g2 badg2] = eval([grad '(x2' tailstr]); + end + wall2=badg2; + % g2 + badg2 + eval(['save g2 g2 x2 f2 ' stailstr]); + end + if wall2 + disp('Cliff again. Try traversing') + if norm(x2-x1) < 1e-13 + f3=f; x3=x; badg3=1; + else + gcliff=((f2-f1)/((norm(x2-x1))^2))*(x2-x1)'; + [f3 x3 fc retcode3] = eval(['csminit(fcn,x,f,gcliff,0,eye(nx)' tailstr]); + fcount = fcount+fc; % put by Jinill + if retcode3==2 | retcode3==4 + wall3=1; badg3=1; + else + if NumGrad, [g3 badg3] = eval(['numgrad(fcn, x3' tailstr]); + else, [g3 badg3] = eval([grad '(x3' tailstr]); + end + wall3=badg3; + % g3 + badg3 + eval(['save g3 g3 x3 f3 ' stailstr]); + end + end + else + f3=f; x3=x; badg3=1; + end + else + f3=f; x3=x; badg3=1; + end + + else + % normal iteration, no walls, or else we're finished here. + f2=f; f3=f; badg2=1; badg3=1; + end + end + + %how to pick gh and xh + if f3<f & badg3==0 + ih=3 + fh=f3;xh=x3;gh=g3;badgh=badg3;retcodeh=retcode3; + elseif f2<f & badg2==0 + ih=2 + fh=f2;xh=x2;gh=g2;badgh=badg2;retcodeh=retcode2; + elseif f1<f & badg1==0 + ih=1 + fh=f1;xh=x1;gh=g1;badgh=badg1;retcodeh=retcode1; + else + [fh,ih] = min([f1,f2,f3]); + ih + eval(['xh=x' num2str(ih) ';']) + eval(['gh=g' num2str(ih) ';']) + eval(['retcodeh=retcode' num2str(ih) ';']) + if gh==[] + if NumGrad, [gh badgh] = eval(['numgrad(fcn, xh' tailstr]); + else, [gh badgh] = eval([grad '(xh' tailstr]); + end + end + badgh=1; + end + %end of picking + %ih + %fh + %xh + %gh + %badgh + + stuck = (abs(fh-f) < crit); + if (~badg)&(~badgh)&(~stuck), H = bfgsi(H,gh-g,xh-x); end + if Verbose + disp('----') + disp(['Improvement on iteration ' int2str(itct) ' = ' num2str(f-fh)]) + end + if Verbose + if itct > nit + disp('iteration count termination') + done = 1; + elseif stuck + disp('improvement < crit termination') + done = 1; + end + rc=retcodeh; + if rc == 1 + disp('zero gradient') + elseif rc == 6 + disp('smallest step still improving too slow, reversed gradient') + elseif rc == 5 + disp('largest step still improving too fast') + elseif (rc == 4) | (rc==2) + disp('back and forth on step length never finished') + elseif rc == 3 + disp('smallest step still improving too slow') + end + end + +f=fh; +x=xh; +g=gh; +badg=badgh; +end + +% what about making an m-file of 10 lines including numgrad.m +% since it appears three times in csminwel.m + \ No newline at end of file diff --git a/MatlabFiles/csminwel.m2 b/MatlabFiles/csminwel.m2 new file mode 100755 index 0000000..0397abb --- /dev/null +++ b/MatlabFiles/csminwel.m2 @@ -0,0 +1,271 @@ +function [fh,xh,gh,H,itct,fcount,retcodeh] = csminwel(fcn,x0,H0,grad,crit,nit, ... + P1,P2,P3,P4,P5,P6,P7,P8,P9,P10,P11,P12,P13,P14,P15,P16,P17,... + P18,P19,P20) +% [fhat,xhat,ghat,Hhat,itct,fcount,retcodehat] = csminwel(fcn,x0,H0,grad,crit,nit, ... +% P1,P2,P3,P4) +% +% x0(estimated parameter) SHOULD BE A ROW VECTOR. +% +% fcn and grad are strings naming functions. If grad is null, numerical +% derivatives are used. The P parameters need not be present. They are passed +% to fcn as additional arguments. +% +% Reindented and modified to allow compilation (comment out use of tailstr, eval) by CAS, +% 7/22/96 +% +[nx,no]=size(x0); +nx=max(nx,no); +Verbose=1; +NumGrad= ( ~isstr(grad) | length(grad)==0); +done=0; +itct=0; +fcount=0; +snit=100; +tailstr = ')'; +stailstr = []; +% Lines below make the number of Pi's optional. This is inefficient, though, and precludes +% use of the matlab compiler. Without them, we use feval and the number of Pi's must be +% changed with the editor for each application. Places where this is required are marked +% with ARGLIST comments +for i=nargin-6:-1:1 + tailstr=[ ',P' num2str(i) tailstr]; + stailstr=[' P' num2str(i) stailstr]; +end +f0 = eval([fcn '(x0' tailstr]); +%ARGLIST +%f0 = feval(fcn,x0,P1,P2,P3,P4,P5,P6,P7,P8,P9,P10,P11,P12,P13); +% disp('first fcn in csminwel.m ----------------') % Jinill on 9/5/95 +if f0 > 1e50, disp('Bad initial parameter.'), return, end +if NumGrad + if length(grad)==0 + [g badg] = eval(['numgrad(fcn, x0' tailstr]); + %ARGLIST + %[g badg] = numgrad(fcn,x0,P1,P2,P3,P4,P5,P6,P7,P8,P9,P10,P11,P12,P13); + else + badg=any(find(grad==0)); + g=grad; + end + %numgrad(fcn,x0,P1,P2,P3,P4); +else + [g badg] = eval([grad '(x0' tailstr]); + %ARGLIST + %[g badg] = feval(grad,x0,P1,P2,P3,P4,P5,P6,P7,P8,P9,P10,P11,P12,P13); +end +x=x0; +f=f0; +H=H0; +cliff=0; +while ~done + g1=[]; g2=[]; g3=[]; + %addition fj. 7/6/94 for control + disp('-----------------') + disp('-----------------') + %disp('f and x at the beginning of new iteration') + disp('f at the beginning of new iteration') + f + %if size(x,1)>size(x,2) + % x' + %else + % x + %end + %------------------------- + itct=itct+1; + disp(' going to start csminit.m to produce f1') + [f1 x1 fc retcode1] = eval(['csminit(fcn,x,f,g,badg,H' tailstr]); + %ARGLIST + %[f1 x1 fc retcode1] = csminit(fcn,x,f,g,badg,H,P1,P2,P3,P4,P5,P6,P7,... + % P8,P9,P10,P11,P12,P13); + % itct=itct+1; + fcount = fcount+fc; + % erased on 8/4/94 + % if (retcode == 1) | (abs(f1-f) < crit) + % done=1; + % end + % if itct > nit + % done = 1; + % retcode = -retcode; + % end + if retcode1 ~= 1 + if retcode1==2 | retcode1==4 + wall1=1; badg1=1; + else + if NumGrad + [g1 badg1] = eval(['numgrad(fcn, x1' tailstr]); + %ARGLIST + %[g1 badg1] = numgrad(fcn, x1,P1,P2,P3,P4,P5,P6,P7,P8,P9,... + % P10,P11,P12,P13); + else + [g1 badg1] = eval([grad '(x1' tailstr]); + %ARGLIST + %[g1 badg1] = feval(grad, x1,P1,P2,P3,P4,P5,P6,P7,P8,P9,... + % P10,P11,P12,P13); + end + wall1=badg1; + % g1 + badg1; + eval(['save g1 g1 x1 f1 ' stailstr]); + %ARGLIST + %save g1 g1 x1 f1 P1 P2 P3 P4 P5 P6 P7 P8 P9 P10 P11 P12 P13; + end + if wall1 % & (~done) by Jinill + % Bad gradient or back and forth on step length. Possibly at + % cliff edge. Try perturbing search direction. + % + %fcliff=fh;xcliff=xh; + Hcliff=H+diag(diag(H).*rand(nx,1)); + disp('Cliff. Perturbing search direction.') + [f2 x2 fc retcode2] = eval(['csminit(fcn,x,f,g,badg,Hcliff' tailstr]); + %ARGLIST + %[f2 x2 fc retcode2] = csminit(fcn,x,f,g,badg,Hcliff,P1,P2,P3,P4,... + % P5,P6,P7,P8,P9,P10,P11,P12,P13); + fcount = fcount+fc; % put by Jinill + if f2 < f + if retcode2==2 | retcode2==4 + wall2=1; badg2=1; + else + if NumGrad + [g2 badg2] = eval(['numgrad(fcn, x2' tailstr]); + %ARGLIST + %[g2 badg2] = numgrad(fcn, x2,P1,P2,P3,P4,P5,P6,P7,P8,... + % P9,P10,P11,P12,P13); + else + [g2 badg2] = eval([grad '(x2' tailstr]); + %ARGLIST + %[g2 badg2] = feval(grad,x2,P1,P2,P3,P4,P5,P6,P7,P8,... + % P9,P10,P11,P12,P13); + end + wall2=badg2; + % g2 + badg2 + eval(['save g2 g2 x2 f2 ' stailstr]); + %ARGLIST + %save g2 g2 x2 f2 P1 P2 P3 P4 P5 P6 P7 P8 P9 P10 P11 P12 P13; + end + if wall2 + disp('Cliff again. Try traversing') + if norm(x2-x1) < 1e-13 + f3=f; x3=x; badg3=1; + else + gcliff=((f2-f1)/((norm(x2-x1))^2))*(x2-x1)'; + [f3 x3 fc retcode3] = eval(['csminit(fcn,x,f,gcliff,0,eye(nx)' tailstr]); + %ARGLIST + %[f3 x3 fc retcode3] = csminit(fcn,x,f,gcliff,0,eye(nx),P1,P2,P3,... + % P4,P5,P6,P7,P8,... + % P9,P10,P11,P12,P13); + fcount = fcount+fc; % put by Jinill + if retcode3==2 | retcode3==4 + wall3=1; badg3=1; + else + if NumGrad + [g3 badg3] = eval(['numgrad(fcn, x3' tailstr]); + %ARGLIST + %[g3 badg3] = numgrad(fcn, x3,P1,P2,P3,P4,P5,P6,P7,P8,... + % P9,P10,P11,P12,P13); + else + [g3 badg3] = eval([grad '(x3' tailstr]); + %ARGLIST + %[g3 badg3] = feval(grad,x3,P1,P2,P3,P4,P5,P6,P7,P8,... + % P9,P10,P11,P12,P13); + end + wall3=badg3; + % g3 + badg3 + eval(['save g3 g3 x3 f3 ' stailstr]); + %ARGLIST + %save g3 g3 x3 f3 P1 P2 P3 P4 P5 P6 P7 P8 P9 P10 P11 P12 P13; + end + end + else + f3=f; x3=x; badg3=1; + end + else + f3=f; x3=x; badg3=1; + end + else + % normal iteration, no walls, or else we're finished here. + f2=f; f3=f; badg2=1; badg3=1; + end + end + %how to pick gh and xh + if f3<f & badg3==0 + ih=3 + fh=f3;xh=x3;gh=g3;badgh=badg3;retcodeh=retcode3; + elseif f2<f & badg2==0 + ih=2 + fh=f2;xh=x2;gh=g2;badgh=badg2;retcodeh=retcode2; + elseif f1<f & badg1==0 + ih=1 + fh=f1;xh=x1;gh=g1;badgh=badg1;retcodeh=retcode1; + else + [fh,ih] = min([f1,f2,f3]); + ih + %eval(['xh=x' num2str(ih) ';']) + if size(x1,2)>1 + xi=[x1;x2;x3]; + xh=xi(ih,:); + else + xi=[x1 x2 x3]; + xh=xi(:,ih); + end + %eval(['gh=g' num2str(ih) ';']) + %eval(['retcodeh=retcode' num2str(ih) ';']) + retcodei=[retcode1,retcode2,retcode3]; + retcodeh=retcodei(ih); + if gh==[] + if NumGrad + [gh badgh] = eval(['numgrad(fcn, xh' tailstr]); + %ARGLIST + %[gh badgh] = numgrad(fcn,xh,P1,P2,P3,P4,P5,P6,P7,P8,... + % P9,P10,P11,P12,P13); + else + [gh badgh] = eval([grad '(xh' tailstr]); + %ARGLIST + %[gh badgh] = feval(grad,xh,P1,P2,P3,P4,P5,P6,P7,P8,... + % P9,P10,P11,P12,P13); + end + end + badgh=1; + end + %end of picking + %ih + %fh + %xh + %gh + %badgh + stuck = (abs(fh-f) < crit); + if (~badg)&(~badgh)&(~stuck) + H = bfgsi(H,gh-g,xh-x); + end + if Verbose + disp('----') + disp(['Improvement on iteration ' int2str(itct) ' = ' num2str(f-fh)]) + end + if Verbose + if itct > nit + disp('iteration count termination') + done = 1; + elseif stuck + disp('improvement < crit termination') + done = 1; + end + rc=retcodeh; + if rc == 1 + disp('zero gradient') + elseif rc == 6 + disp('smallest step still improving too slow, reversed gradient') + elseif rc == 5 + disp('largest step still improving too fast') + elseif (rc == 4) | (rc==2) + disp('back and forth on step length never finished') + elseif rc == 3 + disp('smallest step still improving too slow') + end + end + f=fh; + x=xh; + g=gh; + badg=badgh; +end +% what about making an m-file of 10 lines including numgrad.m +% since it appears three times in csminwel.m + \ No newline at end of file diff --git a/MatlabFiles/datactcon.m b/MatlabFiles/datactcon.m new file mode 100755 index 0000000..6525ce5 --- /dev/null +++ b/MatlabFiles/datactcon.m @@ -0,0 +1,117 @@ +function [yact,yactmg,yactqg,yactCalyg,yactCal] = datactcon(xinput) +% [yact,yactmg,yactqg,yactCalyg,yactCal] = datactcon(xinput) +% Data-actual-conditions. Take the raw data xdata to mlog, mg, qg, and yg. +% Note yact(mlog), yactqg, and yactCalyg corr. to myears, qyears, and yearsCal +% +% xdata=xinput{1}: data, all logged except R, U, etc. +% nSample=xinput{2}: sample size (including lags or initial periods) +% nSampleCal=xinput{3}: converting nSample to sample marked by calendar years; +% actup=xinput{4}: periods for actual data (monthly) +% actupq=xinput{5}: periods for actual data (quarterly) +% actupy=xinput{6}: periods for actual data (calendar yearly) +% vlist=xinput{7}: list of variables +% vlistlog=xinput{8}: sub list of variables that are in log +% vlistper=xinput{9}: sub list of variables that are in percent +% q_m=xinput{10}: month or quarter in the model +% forep=xinput{11}: forecast periods (monthly) +% forepq=xinput{12}: quarters in the forecast period +% forepy=xinput{13}: calendar years in the forecast period +% Psuedo=xinput{14}: 1: Psuedo out-of-sample; 0: real time out-of-sample +% qmEnd=xinput{15}: last month (or quarter) of the sample +%------------- +% yact: (actup+forep*Psuedo)-by-nvar; log(y) except R, ect. (monthly). +% Begin: nSample-actup+1; End: nSample+forep*Psuedo. Match dates myears +% yactmg: (size(yact,1)-1)-by-nvar; month-to-month annualized growth for actual data. +% Begin: nSample-actup+2; End: nSample+forep*Psuedo. Match dates "myears(2:end)" +% yactqg: prior-quarter annualized growth for actual data +% Match dates "qyears." +% yactCalyg: annual growth for actual data +% Match dates "yearsCal." +% yactCal: weirdo -- seldom used. Same as yact but ends at the end of the +% last calendar year. If Psuedo, it includes some actual data in +% the 1st forecast calendar year. I haven't found the use of this weirdo. +% +% Copyright (c) March 1998 by Tao Zha +% Revised, October 1998 + + +xdata=xinput{1}; nSample=xinput{2}; nSampleCal=xinput{3}; +actup=xinput{4}; actupq=xinput{5}; actupy=xinput{6}; vlist=xinput{7}; +vlistlog=xinput{8}; vlistper=xinput{9}; q_m=xinput{10}; forep=xinput{11}; +forepq=xinput{12}; forepy=xinput{13}; Psuedo=xinput{14}; qmEnd=xinput{15}; + +%-------------------------------------- +% Monthly log, acutal data +% yact the way it is and yactCal ends at the end of calendar year +%---------------------------------------- +yact = xdata(nSample-actup+1:nSample+forep*Psuedo,:); + % actup (not calendar) months + forep +yactCal = xdata(nSampleCal-actupy*q_m+1:nSampleCal+forepy*q_m*Psuedo,:); + % calendar years + + + + +%--------------------------------------------------------------- +% Actual monthly growth rate, Prior quarter, and calendar yearly change +%--------------------------------------------------------------- +% +%@@@ Monthly change (annaluized rate) +% +yactm = yact; +mT1 = length(yact(:,1)); +% +yactmg = yactm(2:mT1,:); % start at second month to get growth rate +yactmg(:,vlistlog) = (yactm(2:mT1,vlistlog) - yactm(1:mT1-1,vlistlog)) .* q_m; + % monthly, 12*log(1+growth rate), annualized growth rate +yactmg(:,vlistlog) = 100*(exp(yactmg(:,vlistlog))-1); +yactmg(:,vlistper) = 100*yactmg(:,vlistper); + +% +%@@@ Prior Quarter change (annaluized rate) +% +yactQ = xdata(nSample-mod(qmEnd,3)-actupq*3+1:nSample-mod(qmEnd,3)+forepq*3*Psuedo,:); +yactq = zeros(actupq+forepq*Psuedo,length(vlist)); +% +qT1 = length(yactQ(:,1))/3; +qT1a = length(yactq(:,1)); +if qT1 ~= qT1a + warning('line #') + error('qT1: Beginings or ends of monthly and quarterly series do not match!') +end +% +for i = 1:qT1 + i1 = 1+3*(i-1); + i2 = 3*i; + yactq(i,:) = sum(yactQ(i1:i2,:)) ./ 3; +end +% +yactqg = yactq(5:qT1,:); % 4+1=5 where 4 means 4 quarters +yactqg(:,vlistlog) = (yactq(5:qT1,vlistlog) - yactq(4:qT1-1,vlistlog)) .* 4; + % quarterly, 4*log(1+growth rate), annualized growth rate +yactqg(:,vlistlog) = 100*(exp(yactqg(:,vlistlog))-1); +yactqg(:,vlistper) = 100*yactqg(:,vlistper); + +% +%@@@ Calendar year-over-year change +% +yactCaly = zeros(actupy+forepy*Psuedo,length(vlist)); + % past "actupy" calendar years + forepy*Psuedo +yT1 = length(yactCal(:,1))/q_m; +yT1a = length(yactCaly(:,1)); +if yT1 ~= yT1a + warning('Line #') + error('yT1: Beginings or ends of monthly and quarterly series are not the same!') +end +% +for i = 1:yT1 + i1 = 1+q_m*(i-1); + i2 = q_m*i; + yactCaly(i,:) = sum(yactCal(i1:i2,:)) ./ q_m; +end +% +yactCalyg = yactCaly(2:yT1,:); % 1+1=2 where 1 means 1 year +yactCalyg(:,vlistlog) = (yactCaly(2:yT1,vlistlog) - yactCaly(1:yT1-1,vlistlog)); + % annual rate: log(1+growth rate) +yactCalyg(:,vlistlog) = 100*(exp(yactCalyg(:,vlistlog))-1); +yactCalyg(:,vlistper) = 100*yactCalyg(:,vlistper); diff --git a/MatlabFiles/dataext.m b/MatlabFiles/dataext.m new file mode 100755 index 0000000..b397a5a --- /dev/null +++ b/MatlabFiles/dataext.m @@ -0,0 +1,44 @@ +function [xdsube,Brow,Erow] = dataext(Byrqm,Eyrqm,xdatae) +% xdsube = dataext(Byrqm,Eyrqm,xdatae) +% +% Extract subset of xdatae, given Byrqm and Eyrqm +% +% Byrqm: [year quarter(month)]: beginning year and period. If Byqm(2)=0, we get annual data. +% Eyrqm: [year period]: end year and period. If Byrqm(2)=0, it must be Eyrqm(2)=0. +% xdatae: all data (some of which may be NaN) with the first 2 columns indicating years and periods. +%---------- +% xdsube: subset of xdatae. +% Brow: the row number in xdatee that marks the first row of xdsube. +% Erow: the row number in xdatee that marks the last row of xdsube. +% +% Tao Zha, April 2000 + +if (Byrqm(2)==0) & (Eyrqm(2)~=0) + error('If annual data, make sure both Byrqm(2) and Eyrqm(2) are zero') +end + +Brow = min(find(xdatae(:,1)==Byrqm(1))); +if isempty(Brow) + error('Byrqm is outside the date range indicated by xdatae(:,1:2)!') +end +if Byrqm(2)>0 + nadt=Byrqm(2)-xdatae(Brow,2); + if nadt<0 + error('Byrqm is outside the date range indicated by xdatae(:,1:2)!') + end + Brow=Brow+nadt; +end +% +Erow = min(find(xdatae(:,1)==Eyrqm(1))); +if isempty(Erow) + error('Eyrqm is outside the date range indicated by xdatae(:,1:2)!') +end +if Eyrqm(2)>0 + nadt2=Eyrqm(2)-xdatae(Erow,2); + if nadt<0 + error('Eyrqm is outside the date range indicated by xdatae(:,1:2)!') + end + Erow=Erow+nadt2; +end +% +xdsube = xdatae(Brow:Erow,:); % with dates \ No newline at end of file diff --git a/MatlabFiles/datana.m b/MatlabFiles/datana.m new file mode 100755 index 0000000..2f9b7c8 --- /dev/null +++ b/MatlabFiles/datana.m @@ -0,0 +1,96 @@ +function [yactyrge,yactyre,yactqmyge,yactqmge,yactqme] = datana(xdatae,q_m,vlistlog,vlistper,Byrqm,Eyrqm) +% [yactyrge,yactyre,yactqmyge,yactqmge,yactqme] = datana(Byrqm,Eyrqm,xdatae,q_m,vlistlog,vlistper) +% +% Generate prior period, period-to-period-in-last-year, and annual growth rates +% For annual rates, works for both calendar and any annual years, depending on Byrqm and Eyrqm +% If monthly data, we haven't got time to get quarterly growth rates yet. +% +% xdatae: all data (some of which may be NaN) with the first 2 columns indicating years and periods. +% q_m: quarter or month period +% vlistlog: sublist for logged variables +% vlistper: sublists for percent variables +% Byrqm: [year quarter(month)]: beginning year and period. If Byqm(2)~=1, we don't get +% calendar annual rates. In other words, the first column of yactyge (which +% indicates years) does not mean calendar years +% Eyrqm: [year period]: end year and period +% NOTE: if no inputs Byrqm and Eyrqm are specified, all growth rates begin at xdatae(1,1:2). +%---------- +% yactyrge: annual growth rates with dates in the first 2 columns. +% yactyre: annual average logged level with dates in the 1st 2 columns. +% yactqmyge: period-to-period-in-last-year annual growth rates with dates in the first 2 columns. +% yactqmge: prior-period annualized growth rates with dates in the first 2 columns. +% yactqme: logged data with dates in the first 2 columns. +% +% Tao Zha, April 2000 + +if size(xdatae,1)<2*q_m + error('We need at least two years of xdatae to get annual rates. Check xdatae!!') +end + +if nargin==4 + Brow=1; Erow=length(xdatae(:,1)); + nyr = floor((Erow-Brow+1)/q_m); + yrsg = [xdatae(q_m+1,1):xdatae(q_m+1,1)+nyr-2]'; % for annual growth later on +else + if Byrqm(2)<1 | Eyrqm(2)<1 + error('This function requires both years and months (quarters) in Byrqm and Eyrqm') + end + + Brow = min(find(xdatae(:,1)==Byrqm(1))); + if isempty(Brow) + error('Byrqm is outside the date range of xdatae(:,1:2)!') + end + nadt=Byrqm(2)-xdatae(Brow,2); + if nadt<0 + error('Byrqm is outside the date range indicated by xdatae(:,1:2)!') + end + Brow=Brow+nadt; + % + Erow = min(find(xdatae(:,1)==Eyrqm(1))); + if isempty(Brow) + error('Eyrqm is outside the date range of xdatae(:,1:2)!') + end + nadt2=Eyrqm(2)-xdatae(Erow,2); + if nadt<0 + error('Eyrqm is outside the date range indicated by xdatae(:,1:2)!') + end + Erow=Erow+nadt2; + + nyr = floor((Erow-Brow+1)/q_m); + yrsg = [Byrqm(1)+1:Byrqm(1)+nyr-1]'; % for annual growth later on, which will + % start at Byrqm(1) instead of Byrqm(1)+1 +end +% +yactqme = xdatae(Brow:Erow,:); % with dates +yactqm = yactqme(:,3:end); % only data + +%======== prior period change (annaluized rate) +yactqmg = yactqm(2:end,:); % start at second period to get growth rate +yactqmg(:,vlistlog) = (yactqm(2:end,vlistlog) - yactqm(1:end-1,vlistlog)) .* q_m; + % monthly, 12*log(1+growth rate), annualized growth rate +yactqmg(:,vlistlog) = 100*(exp(yactqmg(:,vlistlog))-1); +yactqmg(:,vlistper) = 100*yactqmg(:,vlistper); +yactqmge = [yactqme(2:end,1:2) yactqmg]; + +%======== change from the last year +yactqmyg = yactqm(q_m+1:end,:); % start at the last-year period to get growth rate +yactqmyg(:,vlistlog) = (yactqm(q_m+1:end,vlistlog) - yactqm(1:end-q_m,vlistlog)); +yactqmyg(:,vlistlog) = 100*(exp(yactqmyg(:,vlistlog))-1); +yactqmyg(:,vlistper) = 100*yactqmyg(:,vlistper); +yactqmyge = [yactqme(q_m+1:end,1:2) yactqmyg]; + +%======== annual growth rates +nvar = length(xdatae(1,3:end)); +ygmts = yactqm(1:nyr*q_m,:); % converted to the multiplication of q_m +ygmts1 = reshape(ygmts,q_m,nyr,nvar); +ygmts2 = sum(ygmts1,1) ./ q_m; +ygmts3 = reshape(ygmts2,nyr,nvar); % converted to annual average series +% +yactyrg = ygmts3(2:end,:); % start at the last-year period to get growth rate +yactyrg(:,vlistlog) = ygmts3(2:end,vlistlog) - ygmts3(1:end-1,vlistlog); + % annual rate: log(1+growth rate) +yactyrg(:,vlistlog) = 100*(exp(yactyrg(:,vlistlog))-1); +yactyrg(:,vlistper) = 100*yactyrg(:,vlistper); +yactyrge = [yrsg zeros(nyr-1,1) yactyrg]; +yrsg1=[yrsg(1)-1:yrsg(end)]'; +yactyre = [yrsg1 zeros(nyr,1) ygmts3]; \ No newline at end of file diff --git a/MatlabFiles/dataxy.m b/MatlabFiles/dataxy.m new file mode 100755 index 0000000..a373d87 --- /dev/null +++ b/MatlabFiles/dataxy.m @@ -0,0 +1,143 @@ +function [xtx,xty,yty,fss,phi,y,ncoef,xr,Bh,e] = dataxy(nvar,lags,z,mu,indxDummy,nexo) +% [xtx,xty,yty,fss,phi,y,ncoef,xr,Bh,e] = dataxy(nvar,lags,z,mu,indxDummy,nexo) +% +% Export arranged data matrices for future estimation for DM models. +% See Wagonner and Zha's Gibbs sampling paper. +% +% nvar: number of endogenous variables. +% lags: the maximum length of lag +% nhp: number of haperparameters +% z: T*(nvar+(nexo-1)) matrix of raw or original data (no manipulation involved) +% with sample size including lags. +% mu: 6-by-1 vector of hyperparameters (the following numbers for Atlanta Fed's forecast) +% mu(1): overall tightness and also for A0; (0.57) +% mu(2): relative tightness for A+; (0.13) +% mu(3): relative tightness for the constant term; (0.1) +% mu(4): tightness on lag decay; (1) +% mu(5): weight on nvar sums of coeffs dummy observations (unit roots); (5) +% mu(6): weight on single dummy initial observation including constant +% (cointegration, unit roots, and stationarity); (5) +% Here, only mu(5) and mu(6) are used for dummy observations +% indxDummy = 1; % 1: add dummy observations to the data; 0: no dummy added. +% nexo: number of exogenous variables. Besides constant terms, we have nexo-1 exogenous variables. +% ------------------- +% xtx: X'X: k-by-k where k=ncoef +% xty: X'Y: k-by-nvar +% yty: Y'Y: nvar-by-nvar +% fss: T: sample size excluding lags. With dummyies, fss=nSample-lags+ndobs. +% phi: X; T-by-k; column: [nvar for 1st lag, ..., nvar for last lag, const] +% y: Y: T-by-nvar where T=fss +% ncoef: number of coefficients in *each* equation. RHS coefficients only, nvar*lags+ncoef +% xr: the economy size (ncoef-by-ncoef) in qr(phi) so that xr=chol(X'*X) or xr'*xr=X'*X +% Bh: ncoef-by-nvar estimated reduced-form parameter; column: nvar; +% row: ncoef=[nvar for 1st lag, ..., nvar for last lag, exogenous variables, const] +% e: estimated residual e = y -x*Bh, T-by-nvar +% +% Tao Zha, February 2000 + +if nargin == 5 + nexo=1; % default for constant term +elseif nexo<1 + error('We need at least one exogenous term so nexo must >= 1') +end + +%*** original sample dimension without dummy prior +nSample = size(z,1); % the sample size (including lags, of course) +sb = lags+1; % original beginning without dummies +ncoef = nvar*lags+nexo; % number of coefficients in *each* equation, RHS coefficients only. + +if indxDummy % prior dummy prior + + %*** expanded sample dimension by dummy prior + ndobs=nvar+1; % number of dummy observations + fss = nSample+ndobs-lags; + + % + % **** nvar prior dummy observations with the sum of coefficients + % ** construct X for Y = X*B + U where phi = X: (T-lags)*k, Y: (T-lags)*nvar + % ** columns: k = # of [nvar for 1st lag, ..., nvar for last lag, exo var, const] + % ** Now, T=T+ndobs -- added with "ndobs" dummy observations + % + phi = zeros(fss,ncoef); + %* constant term + const = ones(fss,1); + const(1:nvar) = zeros(nvar,1); + phi(:,ncoef) = const; % the first nvar periods: no or zero constant! + %* other exogenous (than) constant term + phi(ndobs+1:end,ncoef-nexo+1:ncoef-1) = z(lags+1:end,nvar+1:nvar+nexo-1); + exox = zeros(ndobs,nexo); + phi(1:ndobs,ncoef-nexo+1:ncoef-1) = exox(:,1:nexo-1); + % this = [] when nexo=1 (no other exogenous than constant) + + xdgel = z(:,1:nvar); % endogenous variable matrix + xdgelint = mean(xdgel(1:lags,:),1); % mean of the first lags initial conditions + %* Dummies + for k=1:nvar + for m=1:lags + phi(ndobs,nvar*(m-1)+k) = xdgelint(k); + phi(k,nvar*(m-1)+k) = xdgelint(k); + % <<>> multiply hyperparameter later + end + end + %* True data + for k=1:lags + phi(ndobs+1:fss,nvar*(k-1)+1:nvar*k) = xdgel(sb-k:nSample-k,:); + % row: T-lags; column: [nvar for 1st lag, ..., nvar for last lag, exo var, const] + % Thus, # of columns is nvar*lags+nexo = ncoef. + end + % + % ** Y with "ndobs" dummies added + y = zeros(fss,nvar); + %* Dummies + for k=1:nvar + y(ndobs,k) = xdgelint(k); + y(k,k) = xdgelint(k); + % multiply hyperparameter later + end + %* True data + y(ndobs+1:fss,:) = xdgel(sb:nSample,:); + + phi(1:nvar,:) = 1*mu(5)*phi(1:nvar,:); % standard Sims and Zha prior + y(1:nvar,:) = mu(5)*y(1:nvar,:); % standard Sims and Zha prior + phi(nvar+1,:) = mu(6)*phi(nvar+1,:); + y(nvar+1,:) = mu(6)*y(nvar+1,:); + + [xq,xr]=qr(phi,0); + xtx=xr'*xr; + xty=phi'*y; + [yq,yr]=qr(y,0); + yty=yr'*yr; + Bh = xr\(xr'\xty); % xtx\xty where inv(X'X)*(X'Y) + e=y-phi*Bh; +else + fss = nSample-lags; + % + % ** construct X for Y = X*B + U where phi = X: (T-lags)*k, Y: (T-lags)*nvar + % ** columns: k = # of [nvar for 1st lag, ..., nvar for last lag, exo var, const] + % + phi = zeros(fss,ncoef); + %* constant term + const = ones(fss,1); + phi(:,ncoef) = const; % the first nvar periods: no or zero constant! + %* other exogenous (than) constant term + phi(:,ncoef-nexo+1:ncoef-1) = z(lags+1:end,nvar+1:nvar+nexo-1); + % this = [] when nexo=1 (no other exogenous than constant) + + xdgel = z(:,1:nvar); % endogenous variable matrix + %* True data + for k=1:lags + phi(:,nvar*(k-1)+1:nvar*k) = xdgel(sb-k:nSample-k,:); + % row: T-lags; column: [nvar for 1st lag, ..., nvar for last lag, exo var, const] + % Thus, # of columns is nvar*lags+nexo = ncoef. + end + % + y = xdgel(sb:nSample,:); + + [xq,xr]=qr(phi,0); + xtx=xr'*xr; + xty=phi'*y; + [yq,yr]=qr(y,0); + yty=yr'*yr; + Bh = xr\(xr'\xty); % xtx\xty where inv(X'X)*(X'Y) + e=y-phi*Bh; +end diff --git a/MatlabFiles/demarcate.m b/MatlabFiles/demarcate.m new file mode 100755 index 0000000..8c751dc --- /dev/null +++ b/MatlabFiles/demarcate.m @@ -0,0 +1,98 @@ +function [imfl,imfh,imfl1,imfh1] = demarcate(imfcnt,imndraws,forep,nvar,... + ninv,invc,Am) +% [imfl,imfh,imfl1,imfh1] = demarcate(imfcnt,imndraws,forep,nvar,... +% ninv,invc,Am) +% imfcnt: 2+ninv-by-forep*nvar. Counted logcnt, yhatqgcnt, or yhatCalygcnt. +% In the case of impulse responses, forep=imstp and nvar=nvar^2 +% imndraws: total number of draws allocated to "imfcnt" +% forep: the number of forecast periods (for both impulse responses and forecasting) +% nvar: the number of variables. +% ninv: the number of small interior intervals for sorting. +% invc: 1-by-forep*nvar. Whole inverval lenghth from min to max for one of +% (yhat, yhatqg, or yhatCalyg) +% Am: 1-by-forep*nvar. Range5{i}(:,:,1) is lowest range for for one of +% (yhat, yhatqg, or yhatCalyg) +%----------------- +% imfl: lower .95 bound, forep-by-nvar +% imfh: higher .95 bound, forep-by-nvar +% imfl1: lower .68 bound, forep-by-nvar +% imfh1: higher .68 bound, forep-by-nvar +% +% Copyright (c) March 1998 Tao Zha + + + +%$$$ .68 and .95 probability bands +imfl = zeros(forep*nvar,1); % preallocating +imfh = zeros(forep*nvar,1); % preallocating +imfl1 = zeros(forep*nvar,1); % preallocating +imfh1 = zeros(forep*nvar,1); % preallocating +imfpo = zeros(4,forep*nvar); % 4 positions: l,h,l1,h1. +% +%tic +tem = cumsum(imfcnt) ./ imndraws; % cumulative probability +tem = tem .* 100; +clear imfcnt + +uptail1=5; % 2.5, interval +lowtail1=95; % 97.5 + +%t_cum = toc +% +%tic +% +%@@@ the following operations are valid only because tem are increasing! +for k = 1:forep*nvar + % + %@@@ the following operations are valid only because tem are increasing! + %** 2.5% low tail + if isempty(max(find(tem(:,k)<uptail1))) + imfpo(1,k) = 1; + else + imfpo(1,k) = max(find(tem(:,k)<uptail1)); + end + %** 16% low tail + if isempty(max(find(tem(:,k)<16))) + imfpo(2,k) = 1; + else + imfpo(2,k) = max(find(tem(:,k)<16)); + end + %** 2.5% high tail + imfpo(3,k) = min(find(tem(:,k)>lowtail1)); + %** 16% low tail + imfpo(4,k) = min(find(tem(:,k)>84)); +end + +tem = imfpo'; +%save outprob.txt tem -ascii +% + +imfpo = imfpo - 2; % the first step to put back to original form +% * 2.5% low tail +imfs = ((imfpo(1,:) .* invc) ./ ninv) + Am; + % the final step to put back to original form of impulse responses +imfl = imfs'; +% * 16% low tail +imfs = ((imfpo(2,:) .* invc) ./ ninv) + Am; + % the final step to put back to original form of impulse responses +imfl1 = imfs'; +% * 2.5% high tail +imfs = ((imfpo(3,:) .* invc) ./ ninv) + Am; + % the final step to put back to original form of impulse responses +imfh = imfs'; +% * 16% high tail +imfs = ((imfpo(4,:) .* invc) ./ ninv) + Am; + % the final step to put back to original form of impulse responses +imfh1 = imfs'; +% +%e_t = toc + + +% *** write out final results +clear tem +imfl = reshape(imfl,forep,nvar); +imfh = reshape(imfh,forep,nvar); +imfl1 = reshape(imfl1,forep,nvar); +imfh1 = reshape(imfh1,forep,nvar); +% +% \ No newline at end of file diff --git a/MatlabFiles/demarw.m b/MatlabFiles/demarw.m new file mode 100755 index 0000000..0a12997 --- /dev/null +++ b/MatlabFiles/demarw.m @@ -0,0 +1,48 @@ +function [imfl,imfh,imfl1,imfh1] = demarw(xpo,xprob) +% [imfl,imfh,imfl1,imfh1] = demarw(xpo,xprob) +% Demarcate the .68 and .95 error bands given prob. (weights) and positions +% +% xpo: ndraws-by-nvar. Centered position +% xprob: ndraws-by-nvar. Properly scaled probabilities corresponding to xpo. +%----------------- +% imfl: lower .95 bound, nvar-by-1 +% imfh: higher .95 bound, nvar-by-1 +% imfl1: lower .68 bound, nvar-by-1 +% imfh1: higher .68 bound, nvar-by-1 +% +% Copyright (c) August 1999 Tao Zha + +[ndraws,nvar]=size(xpo); + +%$$$ .68 and .95 probability bands +imfl = zeros(nvar,1); % preallocating +imfh = zeros(nvar,1); % preallocating +imfl1 = zeros(nvar,1); % preallocating +imfh1 = zeros(nvar,1); % preallocating +imfpo = zeros(4,nvar); % 4 positions: l,h,l1,h1. +% +%tic +tem = cumsum(xprob); % cumulative probability +tem = tem .* 100; +% +%@@@ the following operations are valid only because tem are increasing! +for k = 1:nvar + % + %@@@ the following operations are valid only because tem are increasing! + %** 2.5% low tail + if isempty(max(find(tem(:,k)<2.5))) + imfl(k) = xpo(1,k); + else + imfl(k) = xpo(max(find(tem(:,k)<2.5)),k); + end + %** 16% low tail + if isempty(max(find(tem(:,k)<16))) + imfl1(k) = xpo(1,k); + else + imfl1(k) = xpo(max(find(tem(:,k)<16)),k); + end + %** 2.5% high tail + imfh(k) = xpo(min(find(tem(:,k)>97.5)),k); + %** 16% low tail + imfh1(k) = xpo(min(find(tem(:,k)>84)),k); +end diff --git a/MatlabFiles/dlrpostr.m b/MatlabFiles/dlrpostr.m new file mode 100755 index 0000000..fd17d78 --- /dev/null +++ b/MatlabFiles/dlrpostr.m @@ -0,0 +1,42 @@ +function [P,H0inv,Hpinv] = dlrpostr(xtx,xty,yty,Ui,Vi) +% [P,H0inv,Hpinv] = dlrpostr(xtx,xty,yty,Ui,Vi) +% +% Exporting deterministic (hard restrictions) Bayesian posterior matrices with linear restrictions +% See Waggoner and Zha's Gibbs sampling paper +% +% xtx: X'X: k-by-k where k=ncoef +% xty: X'Y: k-by-nvar +% yty: Y'Y: nvar-by-nvar +% Ui: nvar-by-1 cell. In each cell, nvar-by-qi orthonormal basis for the null of the ith +% equation contemporaneous restriction matrix where qi is the number of free parameters. +% With this transformation, we have ai = Ui*bi or Ui'*ai = bi where ai is a vector +% of total original parameters and bi is a vector of free parameters. When no +% restrictions are imposed, we have Ui = I. There must be at least one free +% parameter left for the ith equation. Imported from dnrprior.m. +% Vi: nvar-by-1 cell. In each cell, k-by-ri orthonormal basis for the null of the ith +% equation lagged restriction matrix where k (ncoef) is a total number of RHS variables and +% ri is the number of free parameters. With this transformation, we have fi = Vi*gi +% or Vi'*fi = gi where fi is a vector of total original parameters and gi is a +% vector of free parameters. There must be at least one free parameter left for +% the ith equation. Imported from dnrprior.m. +%----------------- +% P: cell(nvar,1). In each cell, posterior linear transformation for random walk prior for the ith equation % tld: tilda +% H0inv: cell(nvar,1). In each cell, posterior inverse of covariance inv(H0) for the ith equation, +% resembling old SpH in the exponent term in posterior of A0, but not divided by T yet. +% Hpinv: cell(nvar,1). In each cell, posterior inv(Hp) for the ith equation. +% +% Tao Zha, February 2000 + +nvar = size(yty,1); + +P = cell(nvar,1); % tld: tilda +H0inv = cell(nvar,1); % posterior inv(H0), resemble old SpH, but not divided by T yet. +Hpinv = cell(nvar,1); % posterior inv(Hp). + +for n=1:nvar % one for each equation + Hpinv{n} = Vi{n}'*xtx*Vi{n}; + P1 = Vi{n}'*xty*Ui{n}; + P{n} = Hpinv{n}\P1; + H0inv{n} = Ui{n}'*yty*Ui{n} - P1'*(Hpinv{n}\P1); +end + diff --git a/MatlabFiles/eigsort.m b/MatlabFiles/eigsort.m new file mode 100755 index 0000000..4a60b65 --- /dev/null +++ b/MatlabFiles/eigsort.m @@ -0,0 +1,30 @@ +function [vU2,dU2] = eigsort(U,desI) +% E = EIGSORT(X,desI) is a vector containing the eigenvalues of a square +% matrix X, where E is sorted descendingly if desI=1 or ascendingly otherwise +% +% [V,D] = EIG(X) produces a diagonal matrix D of eigenvalues and a +% full matrix V whose columns are the corresponding eigenvectors so +% that X*V = V*D. +% +% Written 9/6/98 by Tao Zha + +[vU,dU]=eig(U); +dUvec = diag(dU); % If dU is SPD, use "abs" in front of diag. This is because, + % even though dU is supposed to be positive, the numerical solution + % for a near-zero eigenvalue can be negative. + % ******************* + % Second thought: "abs" is not necessary, I think. If negative, it + % implies zero already -- thus the smallest number +[dUvec2,dUI2] = sort(dUvec); % ascending +if desI==1 % if descending is required + dUvec2 = flipud(dUvec2); + dUI2 = flipud(dUI2); +end + +if nargout==1 + vU2 = dUvec2; + dU2 = NaN; +else + vU2 = vU(:,dUI2); + dU2 = diag(dUvec2); % put it back to matrix form +end \ No newline at end of file diff --git a/MatlabFiles/ellipse.m b/MatlabFiles/ellipse.m new file mode 100755 index 0000000..ab1215f --- /dev/null +++ b/MatlabFiles/ellipse.m @@ -0,0 +1,70 @@ +function [x,y,z] = ellipse(sigma,mu,k) +%ELLIPSE Creates an ellipsoid +%[X,Y,Z] = ELLIPSE(SIGMA,MU,K) Creates an arbitrary +%ellipsoid in 2 or 3 dimensions. The ellipsoid represents +%the solutions to the quadratic equation: +% +% (x-MU)'*SIGMA*(x-MU) = K +% +%SIGMA is a positive definate matrix of size 2x2 or 3x3. +%SIGMA determines the shape of the ellipsoid. +%MU is a vector conformable with SIGMA; either 2x1 or 3x1. +%MU determines the location of the ellipsoid. +%K is a real constant. +%K determines the size of the ellipsoid. +%The vector x=[X;Y] in 2D or x=[X,Y,Z] in 3D. +% +%If no output aruments are specified, the resulting +%ellipsoid is plotted. One can create these plots manually +%using PLOT(X,Y) in the 2 dimensional case and +%using MESH(X,Y,Z) in the 3 dimensional case. + +% QPLOT was written by Clark A. Burdick of the research +% department of the Federal Reserve Bank of Atlanta. +% Original: August 19, 1997 +% Last Modified: August 19, 1997 + +% TO BE DONE: +% I'm open to suggestions. + +n=50; % <<>> +theta=pi*(-n:2:n)/n; +phi=(pi/2)*(-n:2:n)'/n; + +R=chol(sigma); +rho=sqrt(k); + +if length(mu) == 2 + X = rho*cos(theta); + Y = rho*sin(theta); + + for i = 1:length(theta) + circlevec = [X(i);Y(i)]; + ellipsevec = R\circlevec; % T.A. Zha, 8/16/98 + x(i) = mu(1) + ellipsevec(1); + y(i) = mu(2) + ellipsevec(2); + end + if nargout == 0 + plot(x,y) + end + z='This was only a 2 dimensional ellipse'; +end + +if length(mu) == 3 + X = rho*cos(phi)*cos(theta); + Y = rho*cos(phi)*sin(theta); + Z = rho*sin(phi)*ones(size(theta)); + + for i = 1:length(phi) + for j = 1:length(theta) + spherevec = [X(i,j); Y(i,j); Z(i,j)]; + ellipsevec = R\spherevec; % T.A. Zha, 8/16/98 + x(i,j) = mu(1) + ellipsevec(1); + y(i,j) = mu(2) + ellipsevec(2); + z(i,j) = mu(3) + ellipsevec(3); + end + end + if nargout == 0 + mesh(x,y,z) + end +end \ No newline at end of file diff --git a/MatlabFiles/empdfsort.m b/MatlabFiles/empdfsort.m new file mode 100755 index 0000000..3cb846a --- /dev/null +++ b/MatlabFiles/empdfsort.m @@ -0,0 +1,30 @@ +function imfcnt = empdfsort(imfcnt,imf_h,imfloor,hbin,ninv) +% imfcnt = empdfsort(imfcnt,imf_h,imfloor,hbin,ninv) +% Variablewise (but multivariate) empirical probability distribution with counts +% sorted into bins variablewise +% Note that since a particular draw (imf_h) can be below "imfloor" and above "imceiling" +% (=(imceiling-imfloor)*hbin), this function allows ninv+2 bins for each variable +% +% imfcnt: initial ninv+2-by-k matrix that records counts in each bin given a column in imfcnt +% if k==1, then only one variable is considered. +% imf_h: particular draw, needed not to be a 1-by-k row vector +% imfloor: the low value of imf but imf_h can be below "imfloor" and above "imceiling" +% hbin: bin size = (imceilling-imfloor)/ninv +% ninv: number of bins between "imfloor" and "imceiling" +%------------------ +% imfcnt: updated ninv+2-by-k matrix of counts (probability) +% +% January 1999 TAZ + +%** find the bin locations and arrange them to the order of 1, 2, ... +countInt = floor( (imf_h-imfloor) ./ hbin ); % imstp-by-nvar^2 + % bin locations from <0, 0, 1,..., ninv-1, >=ninv, a total of ninv+2 bins +countInt = 2+countInt(:)'; % row vector, 1-by-imstp*nvar^2, see my shock (1), pp.1 + % move everyting by 2 so as to take account of <0 + +countInt(find(countInt<2)) = 1; % set <0 or -infinity at 1 to start +countInt(find(countInt>=ninv+2)) = ninv+2; % set >=ninv+2 or +infinity at ninv+2 to end +countInt = countInt + (0:length(countInt)-1)*(ninv+2); % index to fill the matrix with prob. (counts) + % The term after "+": with every count, skip ninv+2 to keep + % each column in "imfcnt" with only one element (which is probability) +imfcnt(countInt) = imfcnt(countInt) + 1; diff --git a/MatlabFiles/fcstidcnd.m b/MatlabFiles/fcstidcnd.m new file mode 100755 index 0000000..3587f41 --- /dev/null +++ b/MatlabFiles/fcstidcnd.m @@ -0,0 +1,305 @@ +function [yhat,Estr,rcon,Rcon,u,v,d] = fcstidcnd(valuecon,stepcon,varcon,nstepsm,... + nconstr,eq_ms,nvar,lags,phil,Aband,Sband,yfore_h,imf3s_h,A0_h,Bh_h,... + forep,TLindx,TLnumber,nCms,eq_Cms) +% [yhat,Estr,rcon,Rcon,u,v,d] = fcstidcnd(valuecon,stepcon,varcon,nstepsm,... +% nconstr,eq_ms,nvar,lags,phil,Aband,Sband,yfore_h,imf3s_h,A0_h,Bh_h,... +% forep,TLindx,TLnumber,nCms,eq_Cms) +% +% Conditional forecasting in the identified model with or without error bands +% It handles conditions on average values as well, so "valuecon" must be +% expressed at average (NOT sum) level. +% Aband is used only once when nconstr>0 and Bband=1 where Gibbs sampler may be used +% Unconditional forecast when imf3s_h, etc is fixed and nconstr=0. +% +% valuecon: vector of values conditioned +% stepcon: sequence (cell) of steps conditioned; if length(stepcon{i}) > 1, the condition +% is then an arithmetic average of log(y) over the stepcon{i} period. +% varcon: vector of variables conditioned +% nconstr: number of DLS constraints +% nstepsm: maximum number of steps in all DLS constraints +% nvar: number of variables in the BVAR model +% lags: number of lags in the BVAR model +% phil: the 1-by-(nvar*lags+1) data matrix where k=nvar*lags+1 +% (last period plus lags before the beginning of forecast) +% Aband: 1: draws from A0 and Bh; 0: no draws +% Sband: 1: draws from random shocks E; 0: no random shocks +% yfore_h: uncondtional forecasts: forep-by-nvar. Never used when nconstr=0. +% In this case, set it to []; +% imf3s_h: 3-dimensional impulse responses matrix: impsteps-by-nvar shocks-by-nvar responses +% Never used when nconstr=0. In this case, set it to []; +% A0_h: A0 contemporaneous parameter matrix +% Bh_h: reduced-form parameter matrix: k-by-nvar, y(t) = X(t)*Bh+e(t) +% where X(t) is k-by-nvar and y(t) is 1-by-nvar +% forep: # of forecast periods (e.g., monthly for a monthly model) +% TLindx: 1-by-nCms vector of 1's and 0's, indicating tight or loose; 1: tighter, 0: looser +% Used only when /* (MS draws) is activated. Right now, MS shocks are deterministic. +% TLnumber: 1-by-nCms vector, lower bound for tight and upper bound for loose +% nCms: # of LZ conditions +% eq_Cms: equation location of MS shocks +% ------ +% yhat: conditional forecasts: forep-by-nvar +% Estr: backed-out structural shocks (from N(0,1)) +% rcon: vector - the difference between valuecon and log(yfore) (unconditional forecasts) +% Rcon: k-by-q (q constranits and k=nvar*max(nsteps)) so that +% Rcon'*e = rcon where e is k-by-1 +% [u,d,v]: svd(Rcon,0) +% +%% See Zha's note "Forecast (1)" p. 5, RATS manual (some errors in RATS), etc. +% +%% Some notations: y(t+1) = y(t)B1 + e(t+1)inv(A0). e(t+1) is 1-by-n. +%% Let r(t+1)=e(t+1)inv(A0) + e(t+2)C + .... where inv(A0) is impulse +%% response at t=1, C at t=2, etc. The row of inv(A0) or C is +%% all responses to one shock. +%% Let r be q-by-1 (such as r(1) = r(t+1) +%% = y(t+1) (constrained) - y(t+1) (forecast)). +%% Use impulse responses to find out R (k-by-q) where k=nvar*nsteps +%% where nsteps the largest constrained step. The key of the program +%% is to creat R using impulse responses +%% Optimal solution for shock e where R'*e=r and e is k-by-1 is +%% e = R*inv(R'*R)*r and k>=q +% +% Copyright (c) March 1998 by Tao Zha. Revised November 1998; +% 3/20/99 Disenabled draws of MS shcoks. To enable it, activate /* part +% 3/20/99 Added A0_h and forep and deleted Cms as input argument. Previous +% programs may not be compatible. + + +DLSIdShock = ~isempty(eq_ms); % if not empty, the MS shock is identified as in DLS + +impsteps=size(imf3s_h,1); +if (forep<nstepsm) | (impsteps<nstepsm) + disp('Increase # of forecast or impulse steps!!') + disp('Or decrease # of constraints (nconstr) or constrained steps (stepcon(i))!!') + error('Maximum of conditional steps > # of forecast or impulse steps!!') +end +kts = nvar*nstepsm; % k -- ts: total shocks some of which are restricted and others + % are free. +%*** initializing +Rcon = zeros(kts,nconstr); % R: k-by-q +Econ = zeros(kts,1); % E: k-by-1 +rcon = zeros(nconstr,1); % r: q-by-1 +%rcon=valuecon-diag(yfore(stepcon,varcon)); % another way is to use "loop" below. +tcwc = nvar*lags; % total coefficients without constant +phi=phil; + + + +%---------------------------------------------------- +% Form rcon, Rcon, and Econ (the mean of structural shocks) +%---------------------------------------------------- +if nconstr + A0in = reshape(imf3s_h(1,:,:),nvar,nvar); % nvar shocks-by-nvar responses + for i=1:nconstr + rcon(i)=length(stepcon{i})*valuecon(i) - ... + sum(yfore_h(stepcon{i},varcon(i)),1); %<<>> + Rmat = zeros(nstepsm,nvar); + r2mat = zeros(nstepsm,1); % simply one identified equation + % Must be here inside the loop because it's matrix of one column of Rcon + for j=1:length(stepcon{i}) + if DLSIdShock % Assuming the Fed can't see all other shocks within a month + Rmat(1:stepcon{i}(j),eq_ms) = Rmat(1:stepcon{i}(j),eq_ms) + ... + imf3s_h(stepcon{i}(j):-1:1,eq_ms,varcon(i)); + % Rmat: row--nstepsm, column--nvar shocks (here all shocks except + % the identified one are set to zero) for a particular + % endogenous variable 'varcon(i)'. See Zha Forcast (1), pp.6-7 + else % Rcon random with (A0,A+) + Rmat(1:stepcon{i}(j),:) = Rmat(1:stepcon{i}(j),:) + ... + imf3s_h(stepcon{i}(j):-1:1,:,varcon(i)); + % Rmat: row--nstepsm, column--nvar shocks (here all shocks are + % *not* set to zero) for a particular endogenous + % variable 'varcon(i)'. See Zha Forcast (1), pp.6-7 + end + end + Rmatt = Rmat'; % Now, nvar-by-nstepsm. I think here is where RATS has an error + % i.e. "OVERR" is not transposed when overlaid to "CAPR" + Rcon(:,i)=Rmatt(:); % Rcon: k-by-q where q=nconstr + end + + [u d v]=svd(Rcon,0); %trial + %???? Can we reduce the time by computing inv(R'*R) directly? + % rtr = Rcon'*Rcon; %trial + % rtrinv = inv(Rcon'*Rcon); %trial + vd=v.*(ones(size(v,2),1)*diag(d)'); %trial + dinv = 1./diag(d); % inv(diag(d)) + vdinv=v.*(ones(size(v,2),1)*dinv'); %trial + rtr=vd*vd'; % R'*R + rtrinv = vdinv*vdinv'; % inv(R'*R) + + Econ = Rcon*rtrinv*rcon; % E = R*inv(R'R)*r; the mean of structural shocks +else + Econ = zeros(kts,1); % the mean of shocks is zero under no variable condition + Rcon = NaN; + rcon = NaN; + u = NaN; + d = NaN; + v = NaN; +end + + + +%--------------------------------------- +% No uncertainty at all or only random (A0,A+) +% In other words, no future shocks +%--------------------------------------- +if (~Sband) %| (nconstr & (length(eq_ms)==1)) + % length(eq_ms)==1 implies one-one mapping between MS shocks and, say, FFR + % if nstepsm==nconstr. If this condition does not hold, this procedure + % is incorrect. I don't have time to fix it now (3/20/99). So I use + % this as a proximation + Estr = reshape(Econ,nvar,nstepsm); + Estr = Estr'; % transpose so that + % Estr: structural shocks. Row--steps, Column--n shocks + Estr = [Estr;zeros(forep-nstepsm,nvar)]; + % Now, forep-by-nvar -- ready for forecasts + Estr(1:nCms,eq_Cms) = TLnumber(:); + Ures = Estr/A0_h; % nstepsm-by-nvar + % Ures: reduced-form residuals. Row--steps; Column--n shocks + + % ** reconstruct x(t) for y(t+h) = x(t+h-1)*B + % ** where phi = x(t+h-1) with last column being constant + % + yhat = zeros(forep,nvar); + for k=1:forep + yhat(k,:) = phi*Bh_h + Ures(k,:); + phi(1,nvar+1:tcwc) = phi(1,1:tcwc-nvar); + phi(1,1:nvar) = yhat(k,:); + % + end + +%--------------------------------------- +% With random future shocks and possibly (A0,A+) depending +% on if imf3s_h is random +%--------------------------------------- +else + %-------------- + % Condition on variables and A random + %-------------- + if nconstr & Aband + warning(' ') + disp('This situation (both E and A random) is still under construction') + disp('It is closely related to Waggoner and Zha ReStat Gibbs sampling method') + disp('Please press ctrl-c to abort') + pause + elseif nconstr + %-------------- + % Condition on variables and DLS MS shock, no A random but S random + %-------------- + if DLSIdShock % other shocks are indepedent of the eq_ms shock + % 3/20/99 The following may be problematic because Osk should depend + % on u (A0_h and Bh_h) in general. I haven't worked out any good version + %/* + % Osk = randn(kts,1); % other shocks + % for j=1:nstepsm + % Osk(nvar*(j-1)+eq_ms)=0; % no shock to the MS or identified equation + % end + % Estr = Econ + Osk; % Econ is non zero only at position + % % eq_ms*j where j=1:nstepsm + % Estr = reshape(Estr,nvar,nstepsm); + % Estr = Estr'; % transpose so that + % % Estr: structural shocks. Row--steps, Column--n shocks + % Estr = [Estr;randn(forep-nstepsm,nvar)]; + % % Now, forep-by-nvar -- ready for forecasts + % + disp('DLS') + Ome = eye(kts) - u*u'; % note, I-u*u' = I - R*inv(R'*R)*R' + %[u1 d1 v1] = svd(Ome); % too slow + [u1 d1] = eig(Ome); + Stdcon = u1*diag(sqrt(diag(abs(d1)))); % lower triagular chol of conditional variance + % see Zha's forecast (1), p.17 + tmp1=zeros(nvar,nstepsm); + tmp1(eq_ms,:)=randn(1,nstepsm); + tmp2=tmp1(:); + %Estr1 = Econ + Stdcon*randn(kts,1); + %jnk = reshape(Stdcon*tmp2,nvar,nstepsm) + Estr1 = Econ + Stdcon*tmp2; + Estr2 = reshape(Estr1,nvar,nstepsm); + Estr2 = Estr2'; % transpose so that + % Estr2: structural shocks. Row--nstepsm, Column--n shocks + Estr = [Estr2;randn(forep-nstepsm,nvar)]; + % Now, forep-by-nvar -- ready for forecasts + else + Ome = eye(kts) - u*u'; % note, I-u*u' = I - R*inv(R'*R)*R' + %[u1 d1 v1] = svd(Ome); % too slow + [u1 d1] = eig(Ome); + Stdcon = u1*diag(sqrt(diag(abs(d1)))); % lower triagular chol of conditional variance + % see Zha's forecast (1), p.17 + %-------------- + % Condition on variables and LZ MS shock, no A random but S random + % This section has not be tested yet, 10/14/98 + %-------------- + if nCms + Estr1 = Econ + Stdcon*randn(kts,1); + Estr2 = reshape(Estr1,nvar,nstepsm); + Estr2 = Estr2'; % transpose so that + % Estr2: structural shocks. Row--nstepsm, Column--n shocks + Estr = [Estr2;randn(forep-nstepsm,nvar)]; + % Now, forep-by-nvar -- ready for forecasts + Estr(1:nCms,eq_Cms) = TLnumber(:); + + %/* draw MS shocks + % for k=1:nCms + % if TLindx(k) % tighter + % while (Estr(k,eq_Cms)<TLnumber(k)) + % Estr(k,eq_Cms) = randn(1,1); + % end + % else % looser + % while (Estr(k,eq_Cms)>TLnumber(k)) + % Estr(k,eq_Cms) = randn(1,1); + % end + % end + % end + %-------------- + % Condition on variables only, no A random but S random + %-------------- + else + Estr1 = Econ + Stdcon*randn(kts,1); + Estr2 = reshape(Estr1,nvar,nstepsm); + Estr2 = Estr2'; % transpose so that + % Estr2: structural shocks. Row--nstepsm, Column--n shocks + Estr = [Estr2;randn(forep-nstepsm,nvar)]; + % Now, forep-by-nvar -- ready for forecasts + end + end + %-------------- + % Condition on LZ MS shocks only, S random and possibly A random depending on + % if A0_h and Bh_h are random + %-------------- + else + if nCms + Estr = randn(forep,nvar); + % Now, forep-by-nvar -- ready for forecasts + Estr(1:nCms,eq_Cms) = TLnumber(:); + + %/* draw MS shocks + % for k=1:nCms + % if TLindx(k) % tighter + % while (Estr(k,eq_Cms)<TLnumber(k)) + % Estr(k,eq_Cms) = randn(1,1); + % end + % else % looser + % while (Estr(k,eq_Cms)>TLnumber(k)) + % Estr(k,eq_Cms) = randn(1,1); + % end + % end + % end + else + Estr = randn(forep,nvar); % Unconditional forecast + % Now, forep-by-nvar -- ready for forecasts + end + end + % + + + Ures = Estr/A0_h; % nstepsm-by-nvar + % Ures: reduced-form residuals. Row--steps; Column--n shocks + + % ** reconstruct x(t) for y(t+h) = x(t+h-1)*B + % ** where phi = x(t+h-1) with last column being constant + % + yhat = zeros(forep,nvar); + for k=1:forep + yhat(k,:) = phi*Bh_h + Ures(k,:); + phi(1,nvar+1:tcwc) = phi(1,1:tcwc-nvar); + phi(1,1:nvar) = yhat(k,:); + end +end diff --git a/MatlabFiles/fcstidcnd2.m b/MatlabFiles/fcstidcnd2.m new file mode 100755 index 0000000..6413189 --- /dev/null +++ b/MatlabFiles/fcstidcnd2.m @@ -0,0 +1,342 @@ +function [yhat,Estr,rcon,Rcon,u,v,d] = fcstidcnd2(valuecon,stepcon,varcon,nstepsm,... + nconstr,eq_ms,nvar,lags,phil,Aband,Sband,yfore_h,imf3s_h,A0_h,Bh_h,... + forep,TLindx,TLnumber,nCms,eq_Cms,nconadd,eq_oth,radd,Radd) +% [yhat,Estr,rcon,Rcon,u,v,d] = fcstidcnd2(valuecon,stepcon,varcon,nstepsm,... +% nconstr,eq_ms,nvar,lags,phil,Aband,Sband,yfore_h,imf3s_h,A0_h,Bh_h,... +% forep,TLindx,TLnumber,nCms,eq_Cms,nconadd,eq_oth,radd,Radd) +% +% 5/2/99: This one is much, much slower than fidcnderr.m when eq_ms=[] and +% nconstr>0 and length(eq_ms)*nstepsm>nconstr. Seems to me that fcstidcnd2.m +% is designed for the situation which eq_ms=2. The slow speed is due to +% "Radd" added. When I have time, I need to check to see if I can speed up +% this M file. +% +% Conditional forecasting in the identified model with or without error bands +% It handles conditions on average values as well, so "valuecon" must be +% expressed at average (NOT sum) level. Including unconditional forecasts +% when nconstr=nCms=0. Maybe slower than "fcstidcnd.m" when length(eq_ms)*nstepsm=nconstr +% because of Radd added. But "fsctidcnd.m" is incorrect when length(eq_ms) +% *nstepsm>nconstr (situations like the average annual FFR constraint). 3/22/99 +% Ref.: Zha Forecast (I), pp. 17-17c. +% +% valuecon: vector of values conditioned +% stepcon: sequence (cell) of steps conditioned; if length(stepcon{i}) > 1, the condition +% is then an arithmetic average of log(y) over the stepcon{i} period. +% varcon: vector of variables conditioned +% nconstr: number of DLS constraints +% nstepsm: maximum number of steps in all DLS constraints +% nvar: number of variables in the BVAR model +% lags: number of lags in the BVAR model +% phil: the 1-by-(nvar*lags+1) data matrix where k=nvar*lags+1 +% (last period plus lags before the beginning of forecast) +% eq_ms: identified equation or shock (in terms of number). If equ_ms=[], then "fidencond" or +% 'fcstidcond' is, similar to RATS, to compute forecasts with *all* shocks. +% Aband: 1: draws from A0 and Bh; 0: no draws +% Sband: 1: draws from random shocks E; 0: no random shocks +% yfore_h: uncondtional forecasts: forep-by-nvar. Never used when nconstr=0. +% In this case, set it to []; +% imf3s_h: 3-dimensional impulse responses matrix: impsteps-by-nvar shocks-by-nvar responses +% Never used when nconstr=0. In this case, set it to []; +% A0_h: A0 contemporaneous parameter matrix +% Bh_h: reduced-form parameter matrix: k-by-nvar, y(t) = X(t)*Bh+e(t) +% where X(t) is k-by-nvar and y(t) is 1-by-nvar +% forep: # of forecast periods (e.g., monthly for a monthly model) +% TLindx: 1-by-nCms vector of 1's and 0's, indicating tight or loose; 1: tighter, 0: looser +% Used only when /* (MS draws) is activated. Right now, MS shocks are deterministic. +% TLnumber: 1-by-nCms vector, lower bound for tight and upper bound for loose +% nCms: # of LZ conditions +% eq_Cms: equation location of MS shocks +% nconadd: number of DLS added constraints DIRECTLY on structural shocks +% for identified version where eq_ms is not empty. Note +% nconadd=0 when eq_ms is empty. +% eq_oth: index for other structural shocks than those in eq_ms. +% If eq_ms=[], eq_oth=[]. Note length(eq_oth)+length(eq_ms)=nvar +% radd: sparse nconadd-by-1; nconadd values added to rcon in the text later +% Radd: sparce nvar*nstepsm-by-nconadd; added to Rcon in the text later +% ------ +% yhat: conditional forecasts: forep-by-nvar +% Estr: backed-out structural shocks (from N(0,1)) +% rcon: vector - the difference between valuecon and log(yfore) (unconditional forecasts) +% Rcon: k-by-q (q constranits and k=nvar*max(nsteps)) so that +% Rcon'*e = rcon where e is k-by-1 +% [u,d,v]: svd(Rcon,0) +% +% Copyright (c) March 1998 by Tao Zha. Revised November 1998; +% 3/20/99 Disenabled draws of MS shcoks. To enable it, activate /* part +% 3/20/99 Added A0_h and forep and deleted Cms as input argument. +% 3/21/99 Added nconadd and eq_oth. +% Previous programs may not be compatible. + + + +% +%% See Zha's note "Forecast (1)" p. 5, RATS manual (some errors in RATS), etc. +%% See also Zha Forecast (I), pp. 17-17c. +% +%% Some notations: y(t+1) = y(t)B1 + e(t+1)inv(A0). e(t+1) is 1-by-n. +%% Let r(t+1)=e(t+1)inv(A0) + e(t+2)C + .... where inv(A0) is impulse +%% response at t=1, C at t=2, etc. The row of inv(A0) or C is +%% all responses to one shock. +%% Let r be q-by-1 (such as r(1) = r(t+1) +%% = y(t+1) (constrained) - y(t+1) (forecast)). +%% Use impulse responses to find out R (k-by-q) where k=nvar*nsteps +%% where nsteps the largest constrained step. The key of the program +%% is to creat R using impulse responses +%% Optimal solution for shock e where R'*e=r and e is k-by-1 is +%% e = R*inv(R'*R)*r and k>=q +% + + +DLSIdShock = ~isempty(eq_ms); % if not empty, the MS shock is identified as in DLS + +impsteps=size(imf3s_h,1); +if (forep<nstepsm) | (impsteps<nstepsm) + disp('Increase # of forecast or impulse steps!!') + disp('Or decrease # of constraints (nconstr) or constrained steps (stepcon(i))!!') + error('Maximum of conditional steps > # of forecast or impulse steps!!') +end +kts = nvar*nstepsm; % k -- ts: total shocks some of which are restricted and others + % are free. +%*** initializing +Rcon = zeros(kts,nconstr); % R: k-by-q where q include possible additional + % constraints directly on structural shocks for identified models. + % These addtional constraints will be added later. +Econ = sparse(zeros(kts,1)); % E: k-by-1 +rcon = zeros(nconstr,1); % r: q-by-1 +%rcon=valuecon-diag(yfore(stepcon,varcon)); % another way is to use "loop" below. +tcwc = nvar*lags; % total coefficients without constant +phi=phil; + + + +%---------------------------------------------------- +% Form rcon, Rcon, and Econ (the mean of structural shocks) +%---------------------------------------------------- +if nconstr + A0in = reshape(imf3s_h(1,:,:),nvar,nvar); % nvar shocks-by-nvar responses + for i=1:nconstr + rcon(i)=length(stepcon{i})*valuecon(i) - ... + sum(yfore_h(stepcon{i},varcon(i)),1); %<<>> + Rmat = zeros(nstepsm,nvar); + % Must be here inside the loop because it's matrix of one column of Rcon + for j=1:length(stepcon{i}) + if DLSIdShock % Assuming the Fed can't see all other shocks within a month + Rmat(1:stepcon{i}(j),:) = Rmat(1:stepcon{i}(j),:) + ... + imf3s_h(stepcon{i}(j):-1:1,:,varcon(i)); + % Rmat: row--nstepsm, column--nvar shocks (here all shocks except + % the identified one are set to zero) for a particular + % endogenous variable 'varcon(i)'. See Zha Forcast (1), pp.6-7 + else % Rcon random with (A0,A+) + Rmat(1:stepcon{i}(j),:) = Rmat(1:stepcon{i}(j),:) + ... + imf3s_h(stepcon{i}(j):-1:1,:,varcon(i)); + % Rmat: row--nstepsm, column--nvar shocks (here all shocks are + % *not* set to zero) for a particular endogenous + % variable 'varcon(i)'. See Zha Forcast (1), pp.6-7 + end + end + Rmatt = Rmat'; % Now, nvar-by-nstepsm. I think here is where RATS has an error + % i.e. "OVERR" is not transposed when overlaid to "CAPR" + Rcon(:,i)=Rmatt(:); % Rcon: k-by-q where q=nconstr + end + + rcon = [rcon;radd]; % added nconadd constrained values for identified model + % sparse because radd is sparse + Rcon = [Rcon Radd]; % added constraints on shocks for identified version + % sparse because Radd is sparse + Rcont=Rcon'; + rinvrtr=Rcon/(Rcont*Rcon); + Econ = rinvrtr*rcon; + + + %/* Too slow, I believe, when q is large. 3/21/99 + % [u d v]=svd(Rcon,0); %trial + % %???? Can we reduce the time by computing inv(R'*R) directly? + % % rtr = Rcon'*Rcon; %trial + % % rtrinv = inv(Rcon'*Rcon); %trial + % vd=v.*(ones(size(v,2),1)*diag(d)'); %trial + % dinv = 1./diag(d); % inv(diag(d)) + % vdinv=v.*(ones(size(v,2),1)*dinv'); %trial + % rtr=vd*vd'; % R'*R + % rtrinv = vdinv*vdinv'; % inv(R'*R) + % + % Econ = Rcon*rtrinv*rcon; % E = R*inv(R'R)*r; the mean of structural shocks +else + Econ = sparse(zeros(kts,1)); % the mean of shocks is zero under no variable condition + Rcon = NaN; + rcon = NaN; + u = NaN; + d = NaN; + v = NaN; +end + + + +%--------------------------------------- +% No uncertainty at all or only random (A0,A+) +% In other words, no future shocks +%--------------------------------------- +if (~Sband) | (nconstr & length(eq_ms)*nstepsm==nconstr) + % length(eq_ms)==1 implies one-one mapping between MS shocks and, say, FFR + % if nstepsm==nconstr. If this condition does not hold, this procedure + % is incorrect. I don't have time to fix it now (3/20/99). So I use + % this as a proximation + Estr = reshape(Econ,nvar,nstepsm); + Estr = Estr'; % transpose so that + % Estr: structural shocks. Row--steps, Column--n shocks + Estr = [Estr;zeros(forep-nstepsm,nvar)]; + % Now, forep-by-nvar -- ready for forecasts + Estr(1:nCms,eq_Cms) = TLnumber(:); + Ures = Estr/A0_h; % nstepsm-by-nvar + % Ures: reduced-form residuals. Row--steps; Column--n shocks + + % ** reconstruct x(t) for y(t+h) = x(t+h-1)*B + % ** where phi = x(t+h-1) with last column being constant + % + yhat = zeros(forep,nvar); + for k=1:forep + yhat(k,:) = phi*Bh_h + Ures(k,:); + phi(1,nvar+1:tcwc) = phi(1,1:tcwc-nvar); + phi(1,1:nvar) = yhat(k,:); + % + end + +%--------------------------------------- +% With random future shocks and possibly (A0,A+) depending +% on if imf3s_h is random +%--------------------------------------- +else + %-------------- + % Condition on variables and A random + %-------------- + if nconstr & Aband + warning(' ') + disp('This situation (both E and A random) is still under construction') + disp('It is closely related to Waggoner and Zha ReStat Gibbs sampling method') + disp('and related to "if DLSIdShock" in the following') + disp('Please press ctrl-c to abort') + pause + elseif nconstr + %-------------- + % Condition on variables and DLS MS shock, no A random but S random + %-------------- + if DLSIdShock % other shocks are indepedent of the eq_ms shock + Ome=speye(kts)-rinvrtr*Rcont; + Ome(find(abs(Ome)<1e-10))=0; % tighter the tolerance is, the longer it + % takes for svds to compute. E.g., size(Ome,1)*eps is perhaps very + % tight. After all, when the number in Ome is very small relative to + % 1 (which is the variance of structural shocks Estr), we can treat it + % as zero. + [u1 d1 v1] = svds(Ome,kts-nconstr-nconadd); + % We have exactly nconstr+nconadd zero singular values + Stdcon = u1*diag(sqrt(diag(abs(d1)))); % find a square root of Ome + % see Zha's forecast (1), p.17 + Stdcon = [Stdcon sparse(zeros(kts,kts-size(d1,1)))]; + Estr1 = Econ + Stdcon*randn(kts,1); % We must have rand(kts,1). Assigning + % some of randn(kts,1) to be zero according to Radd is WRONG. + % For this argument, see Zha Forecast (I) p.17a + Estr2 = reshape(Estr1,nvar,nstepsm); + % nvar-by-nstepsm; Needed to be transposed later + Estr = [Estr2';randn(forep-nstepsm,nvar)]; % transpose so that + % Estr2: structural shocks. Row--nstepsm, Column--n shocks + % Now, forep-by-nvar -- ready for forecasts + else + Ome=speye(kts)-rinvrtr*Rcont; + Ome(find(abs(Ome)<1e-10))=0; % tighter the tolerance is, the longer it + % takes for svds to compute. E.g., size(Ome,1)*eps is perhaps very + % tight. After all, when the number in Ome is very small relative to + % 1 (which is the variance of structural shocks Estr), we can treat it + % as zero. + [u1 d1 v1] = svds(Ome,kts-nconstr-nconadd); + % We have exactly nconstr+nconadd zero singular values + Stdcon = u1*diag(sqrt(diag(abs(d1)))); % find a square root of Ome + % see Zha's forecast (1), p.17 + Stdcon = [Stdcon sparse(zeros(kts,nconstr+nconadd))]; + + %*** The following very inefficient + % Ome = eye(kts) - u*u'; % note, I-u*u' = I - R*inv(R'*R)*R' + % %[u1 d1 v1] = svd(Ome); % too slow + % [u1 d1] = eig(Ome); + % Stdcon = u1*diag(sqrt(diag(abs(d1)))); % lower triagular chol of conditional variance + % % see Zha's forecast (1), p.17 + + %-------------- + % Condition on variables and LZ MS shock, no A random but S random + % This section has not be tested yet, 10/14/98 + %-------------- + if nCms + Estr1 = Econ + Stdcon*randn(kts,1); + Estr2 = reshape(Estr1,nvar,nstepsm); + Estr2 = Estr2'; % transpose so that + % Estr2: structural shocks. Row--nstepsm, Column--n shocks + Estr = [Estr2;randn(forep-nstepsm,nvar)]; + % Now, forep-by-nvar -- ready for forecasts + Estr(1:nCms,eq_Cms) = TLnumber(:); + + %/* draw MS shocks + % for k=1:nCms + % if TLindx(k) % tighter + % while (Estr(k,eq_Cms)<TLnumber(k)) + % Estr(k,eq_Cms) = randn(1,1); + % end + % else % looser + % while (Estr(k,eq_Cms)>TLnumber(k)) + % Estr(k,eq_Cms) = randn(1,1); + % end + % end + % end + %-------------- + % Condition on variables only, no A random but S random + %-------------- + else + Estr1 = Econ + Stdcon*randn(kts,1); + Estr2 = reshape(Estr1,nvar,nstepsm); + Estr2 = Estr2'; % transpose so that + % Estr2: structural shocks. Row--nstepsm, Column--n shocks + Estr = [Estr2;randn(forep-nstepsm,nvar)]; + % Now, forep-by-nvar -- ready for forecasts + end + end + %-------------- + % Condition on LZ MS shocks only, S random and possibly A random depending on + % if A0_h and Bh_h are random + %-------------- + else + if nCms + Estr = randn(forep,nvar); + % Now, forep-by-nvar -- ready for forecasts + Estr(:,eq_Cms)=0; + Estr(1:nCms,eq_Cms) = TLnumber(:); + + %/* draw MS shocks + % for k=1:nCms + % if TLindx(k) % tighter + % while (Estr(k,eq_Cms)<TLnumber(k)) + % Estr(k,eq_Cms) = randn(1,1); + % end + % else % looser + % while (Estr(k,eq_Cms)>TLnumber(k)) + % Estr(k,eq_Cms) = randn(1,1); + % end + % end + % end + else + Estr = randn(forep,nvar); % Unconditional forecast + % Now, forep-by-nvar -- ready for forecasts + end + end + % + + + Ures = Estr/A0_h; % nstepsm-by-nvar + % Ures: reduced-form residuals. Row--steps; Column--n shocks + + % ** reconstruct x(t) for y(t+h) = x(t+h-1)*B + % ** where phi = x(t+h-1) with last column being constant + % + yhat = zeros(forep,nvar); + for k=1:forep + yhat(k,:) = phi*Bh_h + Ures(k,:); + phi(1,nvar+1:tcwc) = phi(1,1:tcwc-nvar); + phi(1,1:nvar) = yhat(k,:); + end +end \ No newline at end of file diff --git a/MatlabFiles/fidcnderr.m b/MatlabFiles/fidcnderr.m new file mode 100755 index 0000000..c4dc950 --- /dev/null +++ b/MatlabFiles/fidcnderr.m @@ -0,0 +1,249 @@ +function [yhat,Estr,rcon,Rcon,u,v,d] = fidcnderr(valuecon,stepcon,varcon,nconstr,... + nstepsm,nvar,lags,phil,eq_iden,Aband,Sband,yforeml,imf3sml,Bhml,... + yfore_h,imf3s_h,Bh_h,Cms,TLindx,TLnumber,nCms,eq_Cms) +%function [yhat,Estr,rcon,Rcon,u,v,d] = fidcnderr(valuecon,stepcon,varcon,nconstr,... +% nstepsm,nvar,lags,phil,eq_iden,Aband,Sband,yforeml,imf3sml,Bhml,... +% yfore_h,imf3s_h,Bh_h,Cms,TLindx,TLnumber,nCms,eq_Cms) +% To be done (8/25/98): (1) yforeml, imf3sml, and Bhml should not be there. +% (2) MS stuff need to be generalized. +% (3) perhaps, imf3s_h needs to be re-examined. +% Conditional forecasting in the identified model with one draw for error bands +% +% valuecon: vector of values conditioned +% stepcon: sequence (cell) of steps conditioned; if length(stepcon{i}) > 1, the condition +% is then an arithmetic average of log(y) over the stepcon{i} period. +% varcon: vector of variables conditioned +% nconstr: number of constraints +% nstepsm: maximum number of steps in all constraints +% nvar: number of variables in the BVAR model +% lags: number of lags in the BVAR model +% phil: the 1-by-(nvar*lags+1) data matrix where k=nvar*lags+1 +% (last period plus lags before the beginning of forecast) +% eq_iden: identified equation or shock (in terms of number). If equ_iden=[], then +% 'fidencond' is, similar to RATS, to compute forecasts with *all* shocks. +% Sband: 1: generate error bands from random shocks E; 0: no random shocks +% yfore: uncondtional forecasts: forep-by-nvar +% imf3s: 3-dimensional impulse responses matrix: +% impsteps-by-nvar shocks-by-nvar responses +% Bh: reduced-form parameter matrix: k-by-nvar, y(t) = X(t)*Bh+e(t) +% where X(t) is k-by-nvar and y(t) is 1-by-nvar +% ------ +% yhat: conditional forecasts: forep-by-nvar +% Estr: backed-out structural shocks (from N(0,1)) +% rcon: vector - the difference between valuecon and log(yfore) (unconditional forecasts) +% Rcon: k-by-q (q constranits and k=nvar*max(nsteps)) so that +% Rcon'*e = rcon where e is k-by-1 +% [u,d,v]: svd(Rcon,0) +% +%% See Zha's note "Forecast (1)" p. 5, RATS manual (some errors in RATS), etc. +% +%% Some notations: y(t+1) = y(t)B1 + e(t+1)inv(A0). e(t+1) is 1-by-n. +%% Let r(t+1)=e(t+1)inv(A0) + e(t+2)C + .... where inv(A0) is impulse +%% response at t=1, C at t=2, etc. The row of inv(A0) or C is +%% all responses to one shock. +%% Let r be q-by-1 (such as r(1) = r(t+1) +%% = y(t+1) (constrained) - y(t+1) (forecast)). +%% Use impulse responses to find out R (k-by-q) where k=nvar*nsteps +%% where nsteps the largest constrained step. The key of the program +%% is to creat R using impulse responses +%% Optimal solution for shock e where R'*e=r and e is k-by-1 is +%% e = R*inv(R'*R)*r. +% +% Copyright (c) March 1998 by Tao Zha + + +IdenShock = ~isempty(eq_iden); % if not empty, the shock is identified + +forep=size(yfore_h,1); +impsteps=size(imf3s_h,1); +if (forep<nstepsm) | (impsteps<nstepsm) + disp('Increase # of forecast or impulse steps!!') + disp('Or decrease # of constraints (nconstr) or constrained steps (stepcon(i))!!') + error('Maximum of conditional steps > # of forecast or impulse steps!!') +end +kfs = nvar*nstepsm; % k -- fs: free shocks +%*** initializing +Rcon = zeros(kfs,nconstr); % R: k-by-q +Econ = zeros(kfs,1); % E: k-by-1 +rcon = zeros(nconstr,1); % r: q-by-1 +%rcon=valuecon-diag(yfore(stepcon,varcon)); % another way is to use "loop" below. +A0in = reshape(imf3s_h(1,:,:),nvar,nvar); % nvar shocks-by-nvar responses + + +for i=1:nconstr + if IdenShock + rcon(i)=length(stepcon{i})*valuecon(i) - ... + sum(yforeml(stepcon{i},varcon(i)),1); % <<>> + else + rcon(i)=length(stepcon{i})*valuecon(i) - ... + sum(yfore_h(stepcon{i},varcon(i)),1); %<<>> + end + Rmat = zeros(nstepsm,nvar); + r2mat = zeros(nstepsm,1); % simply one identified equation + % Must be here inside the loop because it's matrix of one column of Rcon + for j=1:length(stepcon{i}) + if IdenShock % Rcon only at ML; assuming the Fed can't see all other shocks + Rmat(1:stepcon{i}(j),eq_iden) = Rmat(1:stepcon{i}(j),eq_iden) + ... + imf3sml(stepcon{i}(j):-1:1,eq_iden,varcon(i)); + % Rmat: row--nstepsm, column--nvar shocks (here all shocks except + % the identified one are set to zero) for a particular + % endogenous variable 'varcon(i)'. See Zha Forcast (1), pp.6-7 + else % Rcon random with (A0,A+) + Rmat(1:stepcon{i}(j),:) = Rmat(1:stepcon{i}(j),:) + ... + imf3s_h(stepcon{i}(j):-1:1,:,varcon(i)); + % Rmat: row--nstepsm, column--nvar shocks (here all shocks are + % *not* set to zero) for a particular endogenous + % variable 'varcon(i)'. See Zha Forcast (1), pp.6-7 + end + end + Rmatt = Rmat'; % Now, nvar-by-nstepsm. I think here is where RATS has an error + % i.e. "OVERR" is not transposed when overlaid to "CAPR" + Rcon(:,i)=Rmatt(:); % Rcon: k-by-q where q=nconstr +end + +if nconstr + [u d v]=svd(Rcon,0); %trial + % rtr = Rcon'*Rcon; %trial + % rtrinv = inv(Rcon'*Rcon); %trial + vd=v.*(ones(size(v,2),1)*diag(d)'); %trial + dinv = 1./diag(d); % inv(diag(d)) + vdinv=v.*(ones(size(v,2),1)*dinv'); %trial + rtr=vd*vd'; % R'*R + rtrinv = vdinv*vdinv'; % inv(R'*R) + + Econ = Rcon*rtrinv*rcon; % E = R*inv(R'R)*r; mean +else + Econ = zeros(kfs,1); + Rcon = NaN; + rcon = NaN; + u = NaN; + d = NaN; + v = NaN; +end + + +tcwc = nvar*lags; % total coefficients without constant +phi=phil; +phis=phil; % for exact backed out shocks +% +if (Sband==0) % no random or random only from (A0,A+) + Estr = reshape(Econ,nvar,nstepsm); + Estr = Estr'; % transpose so that + % Estr: structural shocks. Row--steps, Column--n shocks + Estr = [Estr;randn(forep-nstepsm,nvar)]; + % Now, forep-by-nvar -- ready for forecasts + Ures = Estr*A0in; % nstepsm-by-nvar + % Ures: reduced-form residuals. Row--steps; Column--n shocks + + % ** reconstruct x(t) for y(t+h) = x(t+h-1)*B + % ** where phi = x(t+h-1) with last column being constant + % + yhat = zeros(forep,nvar); + for k=1:forep + yhat(k,:) = phi*Bh_h + Ures(k,:); + phi(1,nvar+1:tcwc) = phi(1,1:tcwc-nvar); + phi(1,1:nvar) = yhat(k,:); + % + end +else % random from shocks E and possibly (A0,A+) depending on if imf3s is random + if nconstr + if IdenShock % other shocks are indepedent of the eq_iden shock + Osk = randn(kfs,1); % other shocks + for j=1:nstepsm + Osk(nvar*(j-1)+eq_iden)=0; % no shock to the MS or identified equation + end + Estr = Econ + Osk; % Econ is non zero only at position + % eq_iden*j where j=1:nstepsm + else + Ome = eye(kfs) - u*u'; % note, I-u*u' = I - R*inv(R'*R)*R' + %[u1 d1 v1] = svd(Ome); % too slow + [u1 d1] = eig(Ome); + Stdcon = u1*diag(sqrt(diag(abs(d1)))); % lower triagular chol of conditional variance + % see Zha's forecast (1), p.17 + if Cms + if TLindx % tight + Estr1 = Econ + Stdcon*randn(kfs,1); + Estr2 = reshape(Estr1,nvar,nstepsm); + Estr2 = Estr2'; % transpose so that + % Estr2: structural shocks. Row--nstepsm, Column--n shocks + Estr = [Estr2;randn(forep-nstepsm,nvar)]; + % Now, forep-by-nvar -- ready for forecasts + Sindx = find(Estr(1:nCms,eq_Cms)<TLnumber); + while ~isempty(Sindx) + Estr1 = Econ + Stdcon*randn(kfs,1); + Estr2 = reshape(Estr1,nvar,nstepsm); + Estr2 = Estr2'; % transpose so that + % Estr2: structural shocks. Row--nstepsm, Column--n shocks + Estr = [Estr2;randn(forep-nstepsm,nvar)]; + % Now, forep-by-nvar -- ready for forecasts + Sindx = find(Estr(1:nCms,eq_Cms)<TLnumber); + end + else % loose + Estr1 = Econ + Stdcon*randn(kfs,1); + Estr2 = reshape(Estr1,nvar,nstepsm); + Estr2 = Estr2'; % transpose so that + % Estr2: structural shocks. Row--nstepsm, Column--n shocks + Estr = [Estr2;randn(forep-nstepsm,nvar)]; + % Now, forep-by-nvar -- ready for forecasts + Sindx = find(Estr(1:nCms,eq_Cms)>TLnumber); + while ~isempty(Sindx) + Estr1 = Econ + Stdcon*randn(kfs,1); + Estr2 = reshape(Estr1,nvar,nstepsm); + Estr2 = Estr2'; % transpose so that + % Estr2: structural shocks. Row--nstepsm, Column--n shocks + Estr = [Estr2;randn(forep-nstepsm,nvar)]; + % Now, forep-by-nvar -- ready for forecasts + Sindx = find(Estr(1:nCms,eq_Cms)>TLnumber); + end + end + else + Estr1 = Econ + Stdcon*randn(kfs,1); + Estr2 = reshape(Estr1,nvar,nstepsm); + Estr2 = Estr2'; % transpose so that + % Estr2: structural shocks. Row--nstepsm, Column--n shocks + Estr = [Estr2;randn(forep-nstepsm,nvar)]; + % Now, forep-by-nvar -- ready for forecasts + end + end + else + if Cms + if TLindx % tight + Estr = randn(forep,nvar); + % Now, forep-by-nvar -- ready for forecasts + Sindx = find(Estr(1:nCms,eq_Cms)<TLnumber); + while ~isempty(Sindx) + Estr = randn(forep,nvar); + % Now, forep-by-nvar -- ready for forecasts + Sindx = find(Estr(1:nCms,eq_Cms)<TLnumber); + end + else % loose + Estr = randn(forep,nvar); + % Now, forep-by-nvar -- ready for forecasts + Sindx = find(Estr(1:nCms,eq_Cms)>TLnumber); + while ~isempty(Sindx) + Estr = randn(forep,nvar); + % Now, forep-by-nvar -- ready for forecasts + Sindx = find(Estr(1:nCms,eq_Cms)>TLnumber); + end + end + else + Estr = randn(forep,nvar); + % Now, forep-by-nvar -- ready for forecasts + end + end + % + %disp('HERE') + + Ures = Estr*A0in; % nstepsm-by-nvar + % Ures: reduced-form residuals. Row--steps; Column--n shocks + + % ** reconstruct x(t) for y(t+h) = x(t+h-1)*B + % ** where phi = x(t+h-1) with last column being constant + % + yhat = zeros(forep,nvar); + for k=1:forep + yhat(k,:) = phi*Bh_h + Ures(k,:); + phi(1,nvar+1:tcwc) = phi(1,1:tcwc-nvar); + phi(1,1:nvar) = yhat(k,:); + end +end \ No newline at end of file diff --git a/MatlabFiles/fidcndexa.m b/MatlabFiles/fidcndexa.m new file mode 100755 index 0000000..93c8e51 --- /dev/null +++ b/MatlabFiles/fidcndexa.m @@ -0,0 +1,46 @@ +function Estrexa = fidcndexa(yexa,phil,A0_h,Bh_h,nvar,lags) +% Estrexa = fidcndexa(yexa,phil,A0_h,Bh_h,nvar,lags) +% Exact structural shocks e(t) (backed out by conditioning on the path "yexa") +% +% yexa: actup-by-nvar. Actual data (all log except R, U, etc.) begin +% at nSample-actup+1 and ends at nSample, where nSample is the period +% for actual data (excluding dummy observations) +% phil: the 1-by-(nvar*lags+1) data matrix where k=nvar*lags+1 +% (last period plus lags, prior to nSample-actup+1) +% A0_h: A0, column-equation; in the form of y(t)A0=X(t)A+ + e(t) +% Bh_h: reduced-form parameter matrix: k-by-nvar, y(t) = X(t)*Bh+u(t) +% where X(t) is k-by-nvar and y(t) is 1-by-nvar +% nvar: number of variables in the BVAR model +% lags: number of lags in the BVAR model +% ------ +% Estrexa: actup-by-nvar -- backed out exact shocks given parameter values +% where actup = length(yexa(:,1)). +% +%% See Zha's note "Forecast (2)" p.11 +% +%% Some notations: y(t+1) = y(t)B1 + e(t+1)inv(A0). e(t+1) is 1-by-n. +%% Let r(t+1)=e(t+1)inv(A0) + e(t+2)C + .... where inv(A0) is impulse +%% response at t=1, C at t=2, etc. The row of inv(A0) or C is +%% all responses to one shock. +%% Let r be q-by-1 (such as r(1) = r(t+1) +%% = y(t+1) (constrained) - y(t+1) (forecast)). +%% Use impulse responses to find out R (k-by-q) where k=nvar*nsteps +%% where nsteps the largest constrained step. The key of the program +%% is to creat R using impulse responses +%% Optimal solution for shock e where R'*e=r and e is k-by-1 is +%% e = R*inv(R'*R)*r. +% +% Copyright (c) April 1998 by Tao Zha +% Change the input arguments so that old programs may not be compatible, 03/19/98. + +tcwc = nvar*lags; % total coefficients without constant +actup = length(yexa(:,1)); % periods considered for structural shocks. +phis=phil; % for exact backed out shocks + +Estrsexa=zeros(actup,nvar); % backed out exact shocks + +for k=1:actup + Estrexa(k,:) = (yexa(k,:)-phis*Bh_h) * A0_h; + phis(nvar+1:tcwc) = phis(1:tcwc-nvar); + phis(1:nvar) = yexa(k,:); +end diff --git a/MatlabFiles/fidencond.m b/MatlabFiles/fidencond.m new file mode 100755 index 0000000..4bde082 --- /dev/null +++ b/MatlabFiles/fidencond.m @@ -0,0 +1,176 @@ +function [yhat,Estr,rcon,Ome,Rmat,u,v,d] = fidencond(valuecon,stepcon,varcon,nconstr,... + nstepsm,nvar,lags,yfore,imf3s,phil,Bh,eq_iden,steps_iden) +% Estimating conditional forecasting in the identified model +%function [yhat,Estr,rcon,Ome,Rmat,u,v,d] = fidencond(valuecon,stepcon,varcon,nconstr,... +% nstepsm,nvar,lags,yfore,imf3s,phil,Bh,eq_iden,steps_iden) +% +% valuecon: vector of values conditioned +% stepcon: sequence (cell) of steps conditioned; if length(stepcon{i}) > 1, the condition +% is then an arithmetic average of log(y) over the stepcon{i} period. +% varcon: vector of variables conditioned +% nconstr: number of constraints +% nstepsm: maximum number of steps in all constraints +% nvar: number of variables in the BVAR model +% lags: number of lags in the BVAR model +% yfore: uncondtional forecasts: forep-by-nvar +% imf3s: 3-dimensional impulse responses matrix: +% impsteps-by-nvar shocks-by-nvar responses +% phil: the 1-by-(nvar*lags+1) data matrix where k=nvar*lags+1 +% (last period plus lags before the beginning of forecast) +% Bh: reduced-form parameter matrix: k-by-nvar, y(t) = X(t)*Bh+e(t) +% where X(t) is k-by-nvar and y(t) is 1-by-nvar +% eq_iden: identified equation or shock (in terms of number). +% If eq_iden=[], then'fidencond' is, similar to RATS, to compute +% forecasts with *all* shocks. +% If length(eq_iden)=1, compute forecasts with only "MS" shocks. +% If eq_iden = [a b c], a is # of constraints for all shocks (<=nconstr), +% b is location of MS, and c is max steps for all shocks. +% My recall is that this option has never been tested 9/18/98 +% steps_iden: a vector (set) of steps for identified shocks. Valid only +% if length(eq_iden)=1. Note, length(steps_iden) must nconstr. +% ------ +% yhat: conditional forecasts: forep-by-nvar +% Estr: backed-out structural shocks (from N(0,1)) +% rcon: vector - the difference between valuecon and log(yfore) (unconditional forecasts) +% Rcon: k-by-q (q constranits and k=nvar*max(nsteps)) so that +% Rcon'*e = rcon where e is k-by-1, where k=nvar*nstepm +% Rmat: nstepsm-by-nvar (shocks), for only one constraint at a time. See Zha's +% Forecast (1), pp.5-6 +% Ome: k-by-k: covariance matrix of vectorized structural shocks vec(Estr) +% +% [u,d,v]: svd(Rcon,0) +% +%% See Zha's note "Forecast (1)" pp.5-7, RATS manual (some errors in RATS), etc. +% +%% Some notations: y(t+1) = y(t)B1 + e(t+1)inv(A0). e(t+1) is 1-by-n. +%% Let r(t+1)=e(t+1)inv(A0) + e(t+2)C + .... where inv(A0) is impulse +%% response at t=1, C at t=2, etc. The row of inv(A0) or C is +%% all responses to one shock. +%% Let r be q-by-1 (such as r(1) = r(t+1) +%% = y(t+1) (constrained) - y(t+1) (forecast)). +%% Use impulse responses to find out R (k-by-q) where k=nvar*nsteps +%% where nsteps the largest constrained step. The key of the program +%% is to creat R using impulse responses +%% Optimal solution for shock e where R'*e=r and e is k-by-1 is +%% e = R*inv(R'*R)*r. +% +% Copyright (c) February 1998 by Tao Zha +% NOTE: the code needs to be improved, 10/19/98 (use lzpaper/fcstidcnd.m for the time being). + + +%IdenShock = ~isempty(eq_iden); % if not empty, the shock is identified +forep=size(yfore,1); +impsteps=size(imf3s,1); +if (forep<nstepsm) | (impsteps<nstepsm) + disp('Increase # of forecast or impulse steps!!') + disp('Or decrease # of constraints (nconstr) or constrained steps (stepcon(i))!!') + error('Maximum of conditional steps > # of forecast or impulse steps!!') + %warning + %return +end +if max(steps_iden) < nconstr + disp('Increase # of identified steps or decrease # of constraints') + error('length(steps_iden) > nconstr') +end + +kfs = nvar*nstepsm; % k -- fs: free shocks +%*** initializing +Rcon = zeros(kfs,nconstr); % R: k-by-q +Econ = zeros(kfs,1); % E: k-by-1 +rcon = zeros(nconstr,1); % r: q-by-1 +%rcon=valuecon-diag(yfore(stepcon,varcon)); % another way is to use "loop" below. +A0in = reshape(imf3s(1,:,:),nvar,nvar); % nvar shocks-by-nvar responses + + +for i=1:nconstr + rcon(i)=valuecon(i)-mean(yfore(stepcon{i},varcon(i))); + %rcon(i)=valuecon(i)-sum(yfore(stepcon{i},varcon(i))); + Rmat = zeros(nstepsm,nvar); + % Rmat: row--nstepsm, column--nvar shocks (here all shocks except + % the identified one are set to zero) for a particular + % endogenous variable 'varcon(i)'. See Zha Forcast (1), pp.6-7 + r2mat = zeros(nstepsm,1); % simply one identified equation + % Must be here inside the loop because it's matrix of one column of Rcon + for j=1:length(stepcon{i}) + if (length(eq_iden)==1) + r2mat(1:stepcon{i}(j)) = r2mat(1:stepcon{i}(j)) + ... + imf3s(stepcon{i}(j):-1:1,eq_iden,varcon(i)); + elseif (length(eq_iden)>1) + if (i<=eq_iden(1)) + Rmat(1:stepcon{i}(j),:) = Rmat(1:stepcon{i}(j),:) + ... + imf3s(stepcon{i}(j):-1:1,:,varcon(i)); + else + Rmat(1:eq_iden(3),:) = Rmat(1:eq_iden(3),:) + ... + imf3s(stepcon{i}(j):-1:stepcon{i}(j)-eq_iden(3)+1,:,varcon(i)); + + Rmat(eq_iden(3)+1:stepcon{i}(j),eq_iden(2)) = ... + Rmat(eq_iden(3)+1:stepcon{i}(j),eq_iden(2)) + ... + imf3s(stepcon{i}(j)-eq_iden(3):-1:1,eq_iden(2),varcon(i)); + end + else + Rmat(1:stepcon{i}(j),:) = Rmat(1:stepcon{i}(j),:) + ... + imf3s(stepcon{i}(j):-1:1,:,varcon(i)); + % Rmat: row--nstepsm, column--nvar shocks (here all shocks are + % *not* set to zero) for a particular endogenous + % variable 'varcon(i)'. See Zha Forcast (1), pp.6-7 + end + end + % + if (length(eq_iden)==1) + Rmat(steps_iden,eq_iden) = r2mat(steps_iden); % for only one constraint at a time + end + Rmat=Rmat/length(stepcon{i}); % <<>> + Rmatt = Rmat'; % Now, nvar-by-nstepsm. I think here is where RATS has an error + % i.e. "OVERR" is not transposed when overlaid to "CAPR" + Rcon(:,i)=Rmatt(:); % Rcon: k-by-q where q=nconstr +end + +if nconstr + [u d v]=svd(Rcon,0); %trial. Rcon: k-by-q; u: k-by-q + % rtr = Rcon'*Rcon; %trial + % rtrinv = inv(Rcon'*Rcon); %trial + vd=v.*(ones(size(v,2),1)*diag(d)'); %trial + dinv = 1./diag(d); % inv(diag(d)) + vdinv=v.*(ones(size(v,2),1)*dinv'); %trial + rtr=vd*vd'; % R'*R + rtrinv = vdinv*vdinv'; % inv(R'*R) + Ome = eye(kfs) - u*u'; % note: I-u*u' = I - R*inv(R'*R)*R'; k-by-k + + Econ = Rcon*rtrinv*rcon; % E = R*inv(R'R)*r; mean +else + Econ = zeros(kfs,1); + Rcon = NaN; + rcon = NaN; + u = NaN; + d = NaN; + v = NaN; +end + + +Estr = reshape(Econ,nvar,nstepsm); +Estr = Estr'; % transpose so that + % Estr: structural shocks. Row--steps, Column--n shocks +Ures = Estr*A0in; % nstepsm-by-nvar + % Ures: reduced-form residuals. Row--steps; Column--n shocks +%Ures = Estr*A0in; + +% ** reconstruct x(t) for y(t+h) = x(t+h-1)*B +% ** where phi = x(t+h-1) with last column being constant +% +tcwc = nvar*lags; % total coefficients without constant +phi=phil; +% +yhat = zeros(forep,nvar); +for k=1:forep + if (k<=nstepsm) + epsl = Ures(k,:); + yhat(k,:) = phi*Bh + epsl; + %yhat(k,:) = phi*Bh; + phi(1,nvar+1:tcwc) = phi(1,1:tcwc-nvar); + phi(1,1:nvar) = yhat(k,:); + else + yhat(k,:) = phi*Bh; + phi(1,nvar+1:tcwc) = phi(1,1:tcwc-nvar); + phi(1,1:nvar) = yhat(k,:); + end +end diff --git a/MatlabFiles/find_betapar.m b/MatlabFiles/find_betapar.m new file mode 100755 index 0000000..f1b6ae6 --- /dev/null +++ b/MatlabFiles/find_betapar.m @@ -0,0 +1,41 @@ +function [a, b, XLO, XUP] = find_betapar(XLO, XUP, PLO, PUP, a0, b0); + +% This function takes as inputs the bounds [XLO, XUP] in the support of the +% Beta distribution (with unknown parameters a and b), the +% probabilities of the bounds [PLO, PUP], and the initial values for ab=[a0, b0] +% and returns the estimates of a and b (as well as XLO and XUP) +% by solving the non-linear functions in betapar(ab, XLO, XUP, PLO, PUP). + +%----------------------------------------------------------------------------------- +%------------------------------- Beta distribution --------------------------------% +%--- p(x) = ( Gamma(a+b)/(Gamma(a)*Gamma(b)) ) x^(a-1) (1-x)^(b-1) +% = (1/Beta(a, b))x^(a-1) (1-x)^(b-1) for a>0 and b>0, and +% 0<=x<=1. +%--- E(x) = a/(a+b); var(x) = a*b/( (a+b)^2*(a+b+1) ); +%--- The density is finite if a,b>=1. +%--- Noninformative density: (1) a=b=1; (2) a=b=0.5; or (3) a=b=0. +%----------------------------------------------------------------------------------- +if XLO >= XUP; + error('the lower bound needs to be smaller than the upper bound') +elseif XLO<=0 or XUP >=1; + error('the support for Beta distribution needs to be between 0 and 1'); +end; + +if a0 <= 0 || b0 <= 0; + error('the values for a and b need to be positive'); +end; + +disp(' ') +disp('*************** Convergence results for beta density ***************') +options = optimset('Display', 'on','TolFun', 1.0e-10, 'TolX', 1.0e-10); +ab_values = fsolve('betapar', [a0, b0], options, XLO, XUP, PLO, PUP); +a = ab_values(1); b = ab_values(2); + +% Alternatively, it is possible to constrain the search for the values of a +% and b in the positive range (with 0 being the explicit lower bound) by +% using the lsqnonlin function (see below) instead of the fsolve. The +% tradeoff is that lsqnonlin is typically slower than fsolve. +% LB_a = 0; LB_b = 0; UB_a = Inf; UB_b = Inf; +% ab_values = lsqnonlin('betapar', [a0, b0], [LB_a, LB_b], [UB_a, UB_b],... +% options, XLO, XUP, PLO, PUP); +% a = ab_values(1); b = ab_values(2); diff --git a/MatlabFiles/find_gampar.m b/MatlabFiles/find_gampar.m new file mode 100755 index 0000000..4967637 --- /dev/null +++ b/MatlabFiles/find_gampar.m @@ -0,0 +1,40 @@ +function [a, b, XLO, XUP] = find_gampar(XLO, XUP, PLO, PUP, a0, b0); + +% This function takes as inputs the bounds [XLO, XUP] in the support of the +% gamma distribution (with parameters a and b), the probabilities of the +% bounds [PLO, PUP], and the initial values for ab=[a0, b0] +% and returns the estimates of a and b (as well as XLO and XUP) +% by solving the non-linear functions in gampar(ab, XLO, XUP, PLO, PUP).\ + +%---------------------------- Gamma distribution ----------------------------------% +%--- p(x) = ( 1/(b^a Gamma(a) ) x^(a-1) exp(-x/b) for a>0, b>0, and x>=0. +%--- where a is the shape and b is the scale parameter. +%--- E(x) = a b; var(x) = a b^2; +%--- Noninformative distribution: a,b -> 0. +%--- The density function is finite if a >= 1. +%----------------------------------------------------------------------------------- + +if XLO >= XUP; + error('the lower bound needs to be smaller than the upper bound') +elseif XLO<= 0; + error('the support for Gamma distribution needs to be non-negative'); +end; + +if a0 <= 0 || b0 <= 0; + error('the values for a0 and b0 need to be positive'); +end; + +disp(' ') +disp('*************** Convergence results for gamma density ***************') +options = optimset('Display', 'on','TolFun', 1.0e-10, 'TolX', 1.0e-10); +ab_values = fsolve('gampar', [a0, b0], options, XLO, XUP, PLO, PUP); +a = ab_values(1); b = ab_values(2); + +% Alternatively, it is possible to constrain the search for the values of a +% and b in the positive range (with 0 being the explicit lower bound) by +% using the lsqnonlin function (see below) instead of the fsolve. The +% tradeoff is that lsqnonlin is typically slower than fsolve. +% LB_a = 0; LB_b = 0; UB_a = Inf; UB_b = Inf; +% ab_values = lsqnonlin('gampar', [a0, b0], [LB_a, LB_b], [UB_a, UB_b],... +% options, XLO, XUP, PLO, PUP); +% a = ab_values(1); b = ab_values(2); diff --git a/MatlabFiles/find_invgampar.m b/MatlabFiles/find_invgampar.m new file mode 100755 index 0000000..f546625 --- /dev/null +++ b/MatlabFiles/find_invgampar.m @@ -0,0 +1,41 @@ +function [a, b, XLO, XUP] = find_invgampar(XLO, XUP, PLO, PUP, a0, b0); + +% This function takes as inputs the bounds [XLO, XUP] in the support of the +% Inverse Gamma distribution (with parameters a and b), the probabilities of the +% bounds [PLO, PUP], and the initial values for ab=[a0, b0] +% and returns the estimates of a and b (as well as XLO and XUP) +% by solving the non-linear functions in invgampar(ab, XLO, XUP, PLO, PUP).\ + +%----------------------------------------------------------------------------------- +%------------------------ Inverse-Gamma distribution ------------------------------% +%--- p(x) = ( b^a/Gamma(a) ) x^(-a-1) exp(-b/x) for a>0 and b>0. +%--- where a is shape and b is scale parameter. +%--- E(x) = b/(a-1) for a>1; var(x) = b^2/( (a-1)^2*(a-2) ) for a>2; +%--- Noninformative distribution: a,b -> 0. +%--- How to draw: (1) draw z from Gamma(a,b); (2) let x=1/z. +%----------------------------------------------------------------------------------- + +if XLO >= XUP; + error('the lower bound needs to be smaller than the upper bound') +elseif XLO<= 0; + error('the support for Gamma distribution needs to be non-negative'); +end; + +if a0 <= 0 || b0 <= 0; + error('the values for a and b need to be positive'); +end; + +disp(' ') +disp('*************** Convergence results for inverse gamma density ***************') +options = optimset('Display', 'on','TolFun', 1.0e-10, 'TolX', 1.0e-10); +ab_values = fsolve('invgampar', [a0, b0], options, XLO, XUP, PLO, PUP); +a = ab_values(1); b = ab_values(2); + +% Alternatively, it is possible to constrain the search for the values of a +% and b in the positive range (with 0 being the explicit lower bound) by +% using the lsqnonlin function (see below) instead of the fsolve. The +% tradeoff is that lsqnonlin is typically slower than fsolve. +% LB_a = 0; LB_b = 0; UB_a = Inf; UB_b = Inf; +% ab_values = lsqnonlin('invgampar', [a0, b0], [LB_a, LB_b], [UB_a, UB_b],... +% options, XLO, XUP, PLO, PUP); +% a = ab_values(1); b = ab_values(2); diff --git a/MatlabFiles/find_normpar.m b/MatlabFiles/find_normpar.m new file mode 100755 index 0000000..761f7b7 --- /dev/null +++ b/MatlabFiles/find_normpar.m @@ -0,0 +1,31 @@ +function [a, b, XLO, XUP] = find_normpar(XLO, XUP, PLO, PUP, a0, b0); + +% This function takes as inputs the bounds [XLO, XUP] in the support of the +% Normal distribution (with unknown parameters a = mean and b=standard deviation), the +% probabilities of the bounds [PLO, PUP], and the initial values for ab=[a0, b0] +% and returns the estimates of a and b (as well as XLO and XUP) +% by solving the non-linear functions in normpar(ab, XLO, XUP, PLO, PUP). + +if XLO >= XUP; + error('the lower bound needs to be smaller than the upper bound') +end; + +if b0 <= 0; + error('the values for the standard deviation needs to be positive'); +end; + + +disp(' ') +disp('*************** Convergence results for normal density ***************') +options = optimset('Display', 'on','TolFun', 1.0e-10, 'TolX', 1.0e-10); +ab_values = fsolve('normpar', [a0, b0], options, XLO, XUP, PLO, PUP); +a = ab_values(1); b = ab_values(2); + +% Alternatively, it is possible to constrain the search for the values of a +% and b in the positive range (with 0 being the explicit lower bound) by +% using the lsqnonlin function (see below) instead of the fsolve. The +% tradeoff is that lsqnonlin is typically slower than fsolve. +% LB_a = 0; LB_b = 0; UB_a = Inf; UB_b = Inf; +% ab_values = lsqnonlin('normpar', [a0, b0], [LB_a, LB_b], [UB_a, UB_b],... +% options, XLO, XUP, PLO, PUP); +% a = ab_values(1); b = ab_values(2); diff --git a/MatlabFiles/fn_PlotRecessionShades57_01.m b/MatlabFiles/fn_PlotRecessionShades57_01.m new file mode 100755 index 0000000..e0008bc --- /dev/null +++ b/MatlabFiles/fn_PlotRecessionShades57_01.m @@ -0,0 +1,9 @@ +function fn_PlotRecessionShades57_01(rec_dates, AxisDat) +% Recession shades. For some reasons, Matlab code will only take pairs of rec_dates when using rectangle. +% Inputs: rec_dates -- must be in pairs for rectangle to work. +% AxisDat -- example: AxisDat=axis([1976 2010 -.2 .15]); +% 1976 will automatically cut off the dates before 1976 in the following lines. + +for RecessionNumber=1:length(rec_dates); + rectangle('Position', [rec_dates(RecessionNumber,1) AxisDat(3) (rec_dates(RecessionNumber,2)-rec_dates(RecessionNumber,1)) (AxisDat(4)-AxisDat(3))], 'FaceColor','y'); +end diff --git a/MatlabFiles/fn_PosteriorVarianceDecomposition.m b/MatlabFiles/fn_PosteriorVarianceDecomposition.m new file mode 100644 index 0000000..1d1cfc3 --- /dev/null +++ b/MatlabFiles/fn_PosteriorVarianceDecomposition.m @@ -0,0 +1,48 @@ +function [VarXAll, E_YVarXGivenY, Var_YEXGivenY] = fn_PosteriorVarianceDecomposition(xydraws,probs) +%--- Inputs: +% xydraws: a matrix with rows being x draws and columns being y draws (columns to be conditioned). +% probs: a vector of probabilities for y draws (length(probs) must be the same as size(xydraws,2)) +%--- Outputs: +% VarXAll: Var(X) -- overall variance +% E_YVarXGivenY: E_Y Var(X|Y) -- uncertainty of not knowing the correct true value of X for a given Y. +% Var_YEXGivenY: Var_Y E(X|Y) -- varianation in the estimator of X due to uncertainty about the choice of Y. +% +% Mathematically and numerically, it must be that VarXAll = E_YVarXGivenY + Var_YEXGivenY. +% +% Written by T. Zha, October 2009 + +n_ydraws = size(xydraws,2); +if (nargin==1), probs = (1/n_ydraws)*ones(n_ydraws,1); end + + +%---------------- Overall variance -------------------- +VarXAll1st = 0.0; +VarXAll2nd = 0.0; +xy1st = mean(mean(xydraws)); +xy2nd = mean(mean(xydraws.^2)); +for (yi=1:n_ydraws) + xGiveny1st = mean(xydraws(:,yi)); + xGiveny2nd = mean(xydraws(:,yi).^2); + VarXAll1st = VarXAll1st + probs(yi) * xGiveny1st; + VarXAll2nd = VarXAll2nd + probs(yi) * xGiveny2nd; +end +VarXAll = VarXAll2nd - VarXAll1st^2; + + +%-------------- The component E_YVarXGivenY -------------------- +E_YVarXGivenY = 0.0; +for (yi=1:n_ydraws) + VarXGivenY = mean(xydraws(:,yi).^2) - (mean(xydraws(:,yi)))^2; + E_YVarXGivenY = E_YVarXGivenY + probs(yi) * VarXGivenY; +end +E_YVarXGivenY = E_YVarXGivenY; + +%-------------- The component Var_YEXGivenY -------------------- +Var_YEXGivenY1st = 0.0; +Var_YEXGivenY2nd = 0.0; +for (yi=1:n_ydraws) + EXGivenY = mean(xydraws(:,yi)); + Var_YEXGivenY1st = Var_YEXGivenY1st + probs(yi) * EXGivenY; + Var_YEXGivenY2nd = Var_YEXGivenY2nd + probs(yi) * EXGivenY^2; +end +Var_YEXGivenY = Var_YEXGivenY2nd - Var_YEXGivenY1st^2; diff --git a/MatlabFiles/fn_ReadRecessionDates57_01.m b/MatlabFiles/fn_ReadRecessionDates57_01.m new file mode 100755 index 0000000..72fd1f9 --- /dev/null +++ b/MatlabFiles/fn_ReadRecessionDates57_01.m @@ -0,0 +1,16 @@ +function rec_dates = fn_ReadRecessionDates57_01() +% Recession dates. For some reasons, Matlab code will only take pairs of rec_dates when using rectangle. +% Note that -1 in the following is for the graph lie in the correct position. +% For example, 1961+(1-1)/12 means Jan 1961 plotted right at 1961. + +rec_dates=[ + 1957+(7-1)/12 1958+(3-1)/12 + 1960+(3-1)/12 1961+(1-1)/12 + 1969+(11-1)/12 1970+(10-1)/12 + 1973+(10-1)/12 1975+(2-1)/12 + 1980+(1-1)/12 1980+(6-1)/12 + 1981+(6-1)/12 1982+(10-1)/12 + 1990+(6-1)/12 1991+(2-1)/12 + 2001+(2-1)/12 2001+(10-1)/12 + 2007+(12-1)/12 2008+(12-1)/12]; + diff --git a/MatlabFiles/fn_a0cfreefun_tv.m b/MatlabFiles/fn_a0cfreefun_tv.m new file mode 100755 index 0000000..f9c0f2e --- /dev/null +++ b/MatlabFiles/fn_a0cfreefun_tv.m @@ -0,0 +1,60 @@ +function of = fn_a0cfreefun_tv(b,nvar,nStates,n0cumsum,Ui,Tkave,Del00invcell_ave,dpDelp0cell_ave) +% of = fn_a0cfreefun_tv(b,nvar,nStates,n0cumsum,Ui,Tkave,Del00invcell_ave,dpDelp0cell_ave) +% Negative logPosterior function for squeesed free A0 parameters (bar tv structural variances) in +% a new SZ time-varying model, which are vectorized as b's in the WZ notation. In other words, +% A0 parameters can be fully time varying, but the time varying structural variances will be +% excluded. It differs from fn_a0sfreefun*.m in several aspects: +% (a) can deal with equations with only structural variances time varying; +% (b) take care of lag restrictions; +% (c) conditional on the values of all other parameters including A+. +% Note: (1) columns correspond to equations; (2) c stands for constant or for an exclusion of +% time varying structural variances. +% See TBVAR NOTE p. 61. +% +% b: n0cumsum(end)-by-1 vector of free constant A0 parameters, vectorized from b_ihatcell. +% nvar: Number of endogeous variables. +% nStates: Number of states. +% n0cumsum: [0;cumsum(n0)] where n0 is nvar-by-1 and its ith element represents the number of +% free constant A0 parameters in ith equation for *all states*. +% Ui: nvar-by-1 cell. In each cell, nvar*nStates-by-(qi+si) orthonormal basis for the null of the ith +% equation contemporaneous restriction matrix where qi is the number of free parameters +% within the state and si is the number of free parameters across the states. +% With this transformation, we have ai = Ui*bi or Ui'*ai = bi where ai is a vector +% of total original parameters and bi is a vector of free parameters. When no +% restrictions are imposed, we have Ui = I. There must be at least one free +% parameter left for the ith equation. +% Tkave: nStates-by-1 of sample sizes (excluding lags but including dummies if provided) for different states k, +% averaged (ave) over E-step draws. For T_k. See p.61. In the Gibbs-Metropolis step, there is +% no need to make Tk the same as Tkave (See Chib and Jeliazkov 2001). +% Del00invcell_ave: Quardratic term for b0_j in each cell. See p.61. When fn_a0cfreegrad_tv.m is used, +% always make this systemetric by using (Del00invcell_ave'+Del00invcell_ave)/2. +% Also note that in the Gibbs-Metropolis step, there is no need to make Del00invcell the same +% as Del00invcell_ave (See Chib and Jeliazkov 2001). +% dpDelp0cell_ave: Cross d+_j and b0_j term in each cell. See p.61. In the Gibbs-Metropolis step, there is no need +% to make dpDelp0cell the same as dpDelp0cell_ave (See Chib and Jeliazkov 2001). +%---------------- +% of: Objective function (negative logPosterior). +% +% This function is called by szeml*.m which is a bettern program than tveml*.m. Thus, +% use this function in place of fn_a0sfreefun2.m if possible. +% See fn_a0cfreegrad_tv.m for analytical gradient for this function. +% +% Tao Zha, September 2001 + + +A0_shat=zeros(nvar,nvar,nStates); % Arranged A0 matrix across states. + +tra = 0.0; +for kj = 1:nvar + bj = b(n0cumsum(kj)+1:n0cumsum(kj+1)); + A0_shat(:,kj,:) = reshape(Ui{kj}*bj,nvar,nStates); + tra = tra+0.5*( (bj'*Del00invcell_ave{kj})*bj - 2*dpDelp0cell_ave{kj}*bj ); % Negative exponential term +end + +ada=0.0; +for si=1:nStates % See p.34a. + [A0l,A0u] = lu(A0_shat(:,:,si)); + ada = ada - Tkave(si)*sum(log(abs(diag(A0u)))); % Negative log determinant of A0 raised to power T +end + +of = ada + tra; diff --git a/MatlabFiles/fn_a0cfreegrad_tv.m b/MatlabFiles/fn_a0cfreegrad_tv.m new file mode 100755 index 0000000..40fd4f6 --- /dev/null +++ b/MatlabFiles/fn_a0cfreegrad_tv.m @@ -0,0 +1,56 @@ +function [g,badg] = fn_a0cfreegrad_tv(b,nvar,nStates,n0cumsum,Ui,Tkave,Del00invcell_ave,dpDelp0cell_ave) +% [g,badg] = fn_a0cfreegrad_tv(b,nvar,nStates,n0cumsum,Ui,Tkave,Del00invcell_ave,dpDelp0cell_ave) +% Analytical gradient for fn_a0cfreegrad_tv.m when using csminwel.m. +% Note: (1) columns correspond to equations; (2) c stands for constant. +% See TBVAR NOTE pp. 61-62, 34a-34c. +% +% b: n0cumsum(end)-by-1 vector of free constant A0 parameters, vectorized from b_ihatcell. +% nvar: Number of endogeous variables. +% nStates: Number of states. +% n0cumsum: [0;cumsum(n0)] where n0 is nvar-by-1 and its ith element represents the number of +% free constant A0 parameters in ith equation for *all states*. +% Ui: nvar-by-1 cell. In each cell, nvar*nStates-by-(qi+si) orthonormal basis for the null of the ith +% equation contemporaneous restriction matrix where qi is the number of free parameters +% within the state and si is the number of free parameters across the states. +% With this transformation, we have ai = Ui*bi or Ui'*ai = bi where ai is a vector +% of total original parameters and bi is a vector of free parameters. When no +% restrictions are imposed, we have Ui = I. There must be at least one free +% parameter left for the ith equation. +% Tkave: nStates-by-1 of sample sizes (excluding lags but including dummies if provided) for different states k, +% averaged (ave) over E-step draws. For T_k. See p.61. +% Del00invcell_ave: Quardratic term for b0_j in each cell. See p.61. +% dpDelp0cell_ave: Cross d+_j and b0_j term in each cell. See p.61. +%---------------- +% g: n0cumsum(end)-by-1 analytical gradient for fn_a0cfreegrad_tv.m. +% badg: 0, the value that is used in csminwel.m. +% +% Tao Zha, September 2001 + + +A0_shat=zeros(nvar,nvar,nStates); % Arranged A0 matrix across states. +B_shat=zeros(nvar,nvar,nStates); % inv(A0_shat); + +badg = 0; +g = zeros(size(b(:))); + +%**** The derivative of the exponential term w.r.t. each free constanta A0 paramater. See pp. 34a and 62. +for kj = 1:nvar + indxn0j = [n0cumsum(kj)+1:n0cumsum(kj+1)]; % Index for the parameters in the ith equation. + bj = b(indxn0j); + g(indxn0j) = Del00invcell_ave{kj}*bj - dpDelp0cell_ave{kj}'; + A0_shat(:,kj,:) = reshape(Ui{kj}*bj,nvar,nStates); +end + + +%for si=1:nStates % See p.34a. + +%end +%**** Add the derivative of -Tk_ave*log|A0(k)| w.r.t. each free constanta A0 paramater. See pp. 62 and 34a. +for kj = 1:nvar + indxn0j = [n0cumsum(kj)+1:n0cumsum(kj+1)]; % Index for the parameters in the ith equation. + for si=1:nStates % See p.34a. + B_shat(:,:,si)=inv(A0_shat(:,:,si)); % See p.62. + g(indxn0j) = g(indxn0j) - Tkave(si)*( B_shat(kj,:,si)*Ui{kj}((si-1)*nvar+1:si*nvar,:) )'; % See p.62. + end +end + diff --git a/MatlabFiles/fn_a0freefun.m b/MatlabFiles/fn_a0freefun.m new file mode 100755 index 0000000..44ed727 --- /dev/null +++ b/MatlabFiles/fn_a0freefun.m @@ -0,0 +1,39 @@ +function of = fn_a0freefun(b,Ui,nvar,n0,fss,H0inv) +% of = fn_a0freefun(b,Ui,nvar,n0,fss,H0inv) +% +% Negative logPosterior function for squeesed A0 free parameters, which are b's in the WZ notation +% Note: columns correspond to equations +% +% b: sum(n0)-by-1 vector of A0 free parameters +% Ui: nvar-by-1 cell. In each cell, nvar-by-qi orthonormal basis for the null of the ith +% equation contemporaneous restriction matrix where qi is the number of free parameters. +% With this transformation, we have ai = Ui*bi or Ui'*ai = bi where ai is a vector +% of total original parameters and bi is a vector of free parameters. When no +% restrictions are imposed, we have Ui = I. There must be at least one free +% parameter left for the ith equation. +% nvar: number of endogeous variables +% n0: nvar-by-1, ith element represents the number of free A0 parameters in ith equation +% fss: nSample-lags (plus ndobs if dummies are included) +% H0inv: cell(nvar,1). In each cell, posterior inverse of covariance inv(H0) for the ith equation, +% resembling old SpH in the exponent term in posterior of A0, but not divided by T yet. +%---------------- +% of: objective function (negative logPosterior) +% +% Tao Zha, February 2000 + +b=b(:); n0=n0(:); + +A0 = zeros(nvar); +n0cum = [0;cumsum(n0)]; +tra = 0.0; +for kj = 1:nvar + bj = b(n0cum(kj)+1:n0cum(kj+1)); + A0(:,kj) = Ui{kj}*bj; + tra = tra + 0.5*bj'*H0inv{kj}*bj; % negative exponential term +end + +[A0l,A0u] = lu(A0); + +ada = -fss*sum(log(abs(diag(A0u)))); % negative log determinant of A0 raised to power T + +of = ada + tra; diff --git a/MatlabFiles/fn_a0freegrad.m b/MatlabFiles/fn_a0freegrad.m new file mode 100755 index 0000000..a48bb38 --- /dev/null +++ b/MatlabFiles/fn_a0freegrad.m @@ -0,0 +1,42 @@ +function [g,badg] = fn_a0freegrad(b,Ui,nvar,n0,fss,H0inv) +% [g,badg] = a0freegrad(b,Ui,nvar,n0,fss,H0inv) +% Analytical gradient for a0freefun.m in use of csminwel.m. See Dhrymes's book. +% +% b: sum(n0)-by-1 vector of A0 free parameters +% Ui: nvar-by-1 cell. In each cell, nvar-by-qi orthonormal basis for the null of the ith +% equation contemporaneous restriction matrix where qi is the number of free parameters. +% With this transformation, we have ai = Ui*bi or Ui'*ai = bi where ai is a vector +% of total original parameters and bi is a vector of free parameters. When no +% restrictions are imposed, we have Ui = I. There must be at least one free +% parameter left for the ith equation. +% nvar: number of endogeous variables +% n0: nvar-by-1, ith element represents the number of free A0 parameters in ith equation +% fss: nSample-lags (plus ndobs if dummies are included) +% H0inv: cell(nvar,1). In each cell, posterior inverse of covariance inv(H0) for the ith equation, +% resembling old SpH in the exponent term in posterior of A0, but not divided by T yet. +%--------------- +% g: sum(n0)-by-1 analytical gradient for a0freefun.m +% badg: 0, the value that is used in csminwel.m +% +% Tao Zha, February 2000. Revised, August 2000 + +b=b(:); n0 = n0(:); + +A0 = zeros(nvar); +n0cum = [0;cumsum(n0)]; +g = zeros(n0cum(end),1); +badg = 0; + +%*** The derivative of the exponential term w.r.t. each free paramater +for kj = 1:nvar + bj = b(n0cum(kj)+1:n0cum(kj+1)); + g(n0cum(kj)+1:n0cum(kj+1)) = H0inv{kj}*bj; + A0(:,kj) = Ui{kj}*bj; +end +B=inv(A0'); + +%*** Add the derivative of -Tlog|A0| w.r.t. each free paramater +for ki = 1:sum(n0) + n = max(find( (ki-n0cum)>0 )); % note, 1<=n<=nvar + g(ki) = g(ki) - fss*B(:,n)'*Ui{n}(:,ki-n0cum(n)); +end diff --git a/MatlabFiles/fn_a0sfreefun.m b/MatlabFiles/fn_a0sfreefun.m new file mode 100755 index 0000000..881d991 --- /dev/null +++ b/MatlabFiles/fn_a0sfreefun.m @@ -0,0 +1,59 @@ +function of = fn_a0sfreefun(b,Uistar,Uibar,nvar,nStates,n0,Tkave,Sgm0tldinvave) +% of = fn_a0sfreefun(b,Uistar,Uibar,nvar,nStates,n0,Tkave,Sgm0tldinvave) +% Negative logPosterior function for regime-switching squeesed free A0 parameters, +% which are b's in the WZ notation. The case of no asymmetric prior and no lag restrictions. +% Note: (1) columns correspond to equations; s stands for state. +% See TBVAR NOTE pp.34-34a,38. +% +% b: sum(n0)*nStates-by-1 vector of free A0 parameters, vectorized from the sum(n0)-by-nStates matrix. +% Uistar: cell(nvar,1). In each cell, nvar*nSates-by-qi orthonormal basis for the null of the ith +% equation contemporaneous restriction matrix where qi is the number of free parameters. +% With this transformation, we have ai = Ui*bi or Ui'*ai = bi where ai is a vector +% of total original parameters and bi is a vector of free parameters. When no +% restrictions are imposed, we have Ui = I. There must be at least one free +% parameter left for the ith equation. See p.33. +% Uibar: cell(nvar,1). In each cell, we have nvar*nStates-by-qi*nStates, rearranged +% from Uistar or Ui. See p.33. This is NOT used for this function, but serves as an argument +% to keep it compatible with fn_a0sfreegrad.m which uses it. +% nvar: Number of endogeous variables. +% nStates: NUmber of states. +% n0: nvar-by-1, ith element represents the number of free A0 parameters in ith equation for each state. +% Tkave: nStates-by-1 of sample sizes (excluding lags but including dummies if provided) for different states k, +% averaged (ave) over E-step draws. For T_k. See p.38. +% Sgm0tldinvave: nvar*nStates-by-nvar*nStates. The matrix inv(\Sigma~_0) averaged (ave) +% over E-step draws. Same for all equations because of no asymmetric prior and no lag +% restrictions. Resembles old SpH in the exponent term in posterior of A0, +% but NOT divided by fss (T) yet. See p.38. +%---------------- +% of: Objective function (negative logPosterior). +% +% This function is a special case of fn_a0sfreefun2.m. +% Tao Zha, March 2001 + + +n0=n0(:); +A0=zeros(nvar,nvar,nStates); +n0cum = [0;cumsum(n0)]; +b=reshape(b,n0cum(end),nStates); + +tra = 0.0; +for kj = 1:nvar + lenbjs=length(n0cum(kj)+1:n0cum(kj+1)); + bj = zeros(nStates*lenbjs,1); + a0j = zeros(nStates*nvar,1); % See p.33. + for si=1:nStates + bj((si-1)*lenbjs+1:si*lenbjs) = b(n0cum(kj)+1:n0cum(kj+1),si); % bj(si). See p.34a. + A0(:,kj,si) = Uistar{kj}((si-1)*nvar+1:si*nvar,:)*b(n0cum(kj)+1:n0cum(kj+1),si); + a0j((si-1)*nvar+1:si*nvar) = A0(:,kj,si); % a0j(si). See p.33. + end + %tra = tra + 0.5*a0j'*Sgm0tldinvave*a0j; % negative exponential term + tra = tra+0.5*bj'*(Uibar{kj}'*Sgm0tldinvave*Uibar{kj})*bj; +end + +ada=0.0; +for si=1:nStates % See p.34a. + [A0l,A0u] = lu(A0(:,:,si)); + ada = ada - Tkave(si)*sum(log(abs(diag(A0u)))); % negative log determinant of A0 raised to power T +end + +of = ada + tra; diff --git a/MatlabFiles/fn_a0sfreefun2.m b/MatlabFiles/fn_a0sfreefun2.m new file mode 100755 index 0000000..ef19a48 --- /dev/null +++ b/MatlabFiles/fn_a0sfreefun2.m @@ -0,0 +1,81 @@ +function of = fn_a0sfreefun2(b,Uistar,Uibar,nvar,nStates,n0,n0cumsum,tvstate,tvtot,constot,... + tvinx,constinx,indxTV,indxConst,Tkave,Sgm0tldinvaveConst,Sgm0tldinvaveTV) +% Negative logPosterior function for regime-switching vectorized free A0 parameters, +% which are b's in the WZ notation. The case of no asymmetric prior and no lag restrictions. +% It improves fn_a0sfreefun2.m in several aspects: +% (a) allows some equations to have constant parameters. +% It differs from fn_a0cfreefun_tv.m in several aspects: +% (a) does not deal with equations with only structural variances time varying; +% (b) cannot deal with lag restrictions; +% (c) only deal with the marginal distribution of A0_s. +% Note: (1) columns correspond to equations; (2) s stands for state. +% See Time-Varying BVAR NOTE pp.34-34c,40. +% +% b: sum(n0)*nStates-by-1 vector of free A0 parameters, vectorized from the sum(n0)-by-nStates matrix. +% Uistar: cell(nvar,1). In each cell, nvar*nSates-by-qi orthonormal basis for the null of the ith +% equation contemporaneous restriction matrix where qi is the number of free parameters. +% With this transformation, we have ai = Ui*bi or Ui'*ai = bi where ai is a vector +% of total original parameters and bi is a vector of free parameters. When no +% restrictions are imposed, we have Ui = I. There must be at least one free +% parameter left for the ith equation. See p.33. +% Uibar: cell(nvar,1). In each cell, we have nvar*nStates-by-qi*nStates, rearranged +% from Uistar or Ui. See p.33. +% nvar: Number of endogeous variables. +% nStates: NUmber of states. +% n0: nvar-by-1, ith element represents the number of free A0 parameters in ith equation for each state. +% n0cumsum: Equal to [0;cumsum(n0)]; +% tvstate: Number of time-varying parameters for all equations for each state. +% tvtot: Total number of time-varying parameters. +% constot: Total number of constant parameters. +% tvinx: Vectorized index to include time-varying parameters for all equations under *each* state. +% constinx: Vectorized index to include constant parameters for all equations. +% indxTV: Index of acending order for equations with time-varying parameters. +% indxConst: Index of ascending order for equations with constant parameters. When [], all equations +% are time varying; when [1:nvar], all equations have constant parameters. +% Tkave: nStates-by-1 of sample sizes (excluding lags but including dummies if provided) for different states k, +% averaged (ave) over E-step draws. For T_k. See p.40. +% Sgm0tldinvaveConst +% Sgm0tldinvaveTV +% Sgm0tldinvave: nvar*nStates-by-nvar*nStates. The matrix inv(\Sigma~_0) averaged (ave) +% over E-step draws. Same for all equations because of no asymmetric prior and no lag +% restrictions. Resembles old SpH in the exponent term in posterior of A0, +% but NOT divided by fss (T) yet. See p.40. +%---------------- +% of: Objective function (negative logPosterior). +% +% This function is called by tveml*.m which is an old program compared with szeml*.m. Thus, +% use fn_a0cfreefun_tv.m if possible. +% Tao Zha, August 2001. + + +n0=n0(:); +A0=zeros(nvar,nvar,nStates); +b_shat = zeros(n0cumsum(end),nStates); +b_shat(tvinx,:) = reshape(b(1:tvtot),tvstate,nStates); % Time-varying parameter matrix. +b_shat(constinx,:) = repmat(b(tvtot+1:end), [1 nStates]); % Constant parameter matrix. + +tra = 0.0; +for kj = 1:nvar + lenbjs=length(n0cumsum(kj)+1:n0cumsum(kj+1)); + bj = zeros(nStates*lenbjs,1); + a0j = zeros(nStates*nvar,1); % See p.33. + for si=1:nStates + bj((si-1)*lenbjs+1:si*lenbjs) = b_shat(n0cumsum(kj)+1:n0cumsum(kj+1),si); % bj(si). See p.34a. + A0(:,kj,si) = Uistar{kj}((si-1)*nvar+1:si*nvar,:)*b_shat(n0cumsum(kj)+1:n0cumsum(kj+1),si); + a0j((si-1)*nvar+1:si*nvar) = A0(:,kj,si); % a0j(si). See p.33. + end + %tra = tra + 0.5*a0j'*Sgm0tldinvave*a0j; % negative exponential term + if find(kj==indxTV) % For time-varying equations. + tra = tra+0.5*bj'*(Uibar{kj}'*Sgm0tldinvaveTV*Uibar{kj})*bj; + else % % For constant parameter equations. + tra = tra+0.5*bj'*(Uibar{kj}'*Sgm0tldinvaveConst*Uibar{kj})*bj; + end +end + +ada=0.0; +for si=1:nStates % See p.34a. + [A0l,A0u] = lu(A0(:,:,si)); + ada = ada - Tkave(si)*sum(log(abs(diag(A0u)))); % negative log determinant of A0 raised to power T +end + +of = ada + tra; diff --git a/MatlabFiles/fn_a0sfreegrad.m b/MatlabFiles/fn_a0sfreegrad.m new file mode 100755 index 0000000..5dab96b --- /dev/null +++ b/MatlabFiles/fn_a0sfreegrad.m @@ -0,0 +1,65 @@ +function [g,badg] = fn_a0sfreegrad(b,Uistar,Uibar,nvar,nStates,n0,Tkave,Sgm0tldinvave) +% [g,badg] = fn_a0sfreegrad(b,Uistar,Uibar,nvar,nStates,n0,Tkave,Sgm0tldinvave) +% Analytical gradient for fn_a0sfreefun.m when using csminwel.m. +% The case of no asymmetric prior and no lag restrictions. +% Note: (1) columns correspond to equations; s stands for state. +% See TBVAR NOTE p.34a. +% +% b: sum(n0)*nStates-by-1 vector of free A0 parameters, vectorized from the sum(n0)-by-nStates matrix. +% Uistar: cell(nvar,1). In each cell, nvar*nStates-by-qi orthonormal basis for the null of the ith +% equation contemporaneous restriction matrix where qi is the number of free parameters. +% With this transformation, we have ai = Ui*bi or Ui'*ai = bi where ai is a vector +% of total original parameters and bi is a vector of free parameters. When no +% restrictions are imposed, we have Ui = I. There must be at least one free +% parameter left for the ith equation. See p.33. +% Uibar: cell(nvar,1). In each cell, we have nvar*nStates-by-qi*nStates, rearranged +% from Uistar or Ui. See p.33. +% nvar: Number of endogeous variables. +% nStates: NUmber of states. +% n0: nvar-by-1. n0(i)=qi where ith element represents the number of free A0 parameters in ith equation for each state. +% Tkave: nStates-by-1 of sample sizes (excluding lags but including dummies if provided) for different states k, +% averaged (ave) over E-step draws. For T_k. See p.38. +% Sgm0tldinvave: nvar*nStates-by-nvar*nStates. The matrix inv(\Sigma~_0) averaged (ave) +% over E-step draws. Same for all equations because of no asymmetric prior and no lag +% restrictions. Resembles old SpH in the exponent term in posterior of A0, +% but NOT divided by fss (T) yet. See p.38. +%---------------- +% g: sum(n0)*nStates-by-1 analytical gradient for fn_a0sfreefun.m. +% Vectorized frmo the sum(n0)-by-nStates matrix. +% badg: 0, the value that is used in csminwel.m. +% +% Tao Zha, March 2001 + + +n0=n0(:); +A0=zeros(nvar,nvar,nStates); +n0cum = [0;cumsum(n0)]; +b=reshape(b,n0cum(end),nStates); + +g = zeros(n0cum(end),nStates); % which will be vectorized later. +badg = 0; + + +%*** The derivative of the exponential term w.r.t. each free paramater +for kj = 1:nvar + lenbjs=length(n0cum(kj)+1:n0cum(kj+1)); + bj = zeros(nStates*lenbjs,1); + for si=1:nStates + bj((si-1)*lenbjs+1:si*lenbjs) = b(n0cum(kj)+1:n0cum(kj+1),si); % bj(si). See p.34a. + A0(:,kj,si) = Uistar{kj}((si-1)*nvar+1:si*nvar,:)*b(n0cum(kj)+1:n0cum(kj+1),si); + end + gj = (Uibar{kj}'*Sgm0tldinvave*Uibar{kj})*bj; + for si=1:nStates + g(n0cum(kj)+1:n0cum(kj+1),si) = gj((si-1)*lenbjs+1:si*lenbjs); + end +end + +%*** Add the derivative of -T_klog|A0(k)| w.r.t. each free paramater +for si=1:nStates % See p.34a. + B=inv(A0(:,:,si)'); + for ki = 1:n0cum(end) % from 1 to sum(q_i) + n = max(find( (ki-n0cum)>0 )); % note, 1<=n<=nvar equations. + g(ki,si) = g(ki,si) - Tkave(si)*B(:,n)'*Uistar{n}((si-1)*nvar+1:si*nvar,ki-n0cum(n)); % See p.34a. + end +end +g = g(:); % vectorized the same way as b is vectorized. diff --git a/MatlabFiles/fn_a0sfreegrad2.m b/MatlabFiles/fn_a0sfreegrad2.m new file mode 100755 index 0000000..f840ecb --- /dev/null +++ b/MatlabFiles/fn_a0sfreegrad2.m @@ -0,0 +1,125 @@ +function [g,badg] = fn_a0sfreegrad2(b,Uistar,Uibar,nvar,nStates,n0,n0cumsum,tvstate,tvtot,constot,... + tvinx,constinx,indxTV,indxConst,Tkave,Sgm0tldinvaveConst,Sgm0tldinvaveTV) +% Analytical gradient for both time-varying and constant parameters for fn_a0sfreefun2.m when using csminwel.m. +% The case of no asymmetric prior and no lag restrictions. +% Note: (1) columns correspond to equations; s stands for state. +% See Time-Varying BVAR NOTE pp.34a-34c. +% +% b: tvtot+constot-by-1 vector of free A0 parameters, vectorized from b_shat for both time-varying and constant parameter matrices. +% Uistar: cell(nvar,1). In each cell, nvar*nStates-by-qi orthonormal basis for the null of the ith +% equation contemporaneous restriction matrix where qi is the number of free parameters +% where in each state, nvar-by-qi is the same. With this transformation, we have +% ai = Ui*bi or Ui'*ai = bi where ai is a vector of total original parameters and +% bi is a vector of free parameters. When no restrictions are imposed, we have Ui = I. +% There must be at least one free parameter left for the ith equation. See p.33. +% Uibar: cell(nvar,1). In each cell, we have nvar*nStates-by-qi*nStates, rearranged +% from Uistar or Ui. See p.33. +% nvar: Number of endogenous variables. +% nStates: NUmber of states. +% n0: nvar-by-1. n0(i)=qi where ith element represents the number of free A0 parameters in ith equation for each state. +% n0cumsum=[0;cumsum(n0)]: nvar+1-by-1. Cumulative sums of n0 with zero added. +% tvstate=length(tvinx): Number of time-varying parameters for all equations under *each* state. +% constot=length(constinx): Total number of constant parameters for all equations. +% tvtot = tvstate*nStates: Total number of time-varying parameters for all equations under all states. +% tvinx: Vectorized index to include time-varying parameters for all equations under *each* state. +% constinx: Vectorized index to include constant parameters for all equations. +% indxTV: Index vector of ascending order for equations with time-varying parameters. +% indxConst: Index vector of ascending order for equations with constant parameters. When [], all equations +% are time varying; when [1:nvar], all equations have constant parameters. +% Tkave: nStates-by-1 of sample sizes (excluding lags but including dummies if provided) for different states k, +% averaged (ave) over E-step draws. For T_k. See p.40. +% Sgm0tldinvaveConst +% Sgm0tldinvaveTV +% Sgm0tldinvave: nvar*nStates-by-nvar*nStates. The matrix inv(\Sigma~_0) averaged (ave) +% over E-step draws. Same for all equations because of no asymmetric prior and no lag +% restrictions. Resembles old SpH in the exponent term in posterior of A0, +% but NOT divided by fss (T) yet. See p.40. +%---------------- +% g: tvtot+constot-by-1 analytical gradient for fn_a0sfreefun2.m. Vectorized first from the +% time-varying parameter matrix and then from constant parameter and constant parameter matrix. +% badg: Always 0 --- the value that is used in csminwel.m. +% +% Tao Zha, August 2001. + + +n0=n0(:); +A0=zeros(nvar,nvar,nStates); +B0=A0; +b_shat = zeros(n0cumsum(end),nStates); +b_shat(tvinx,:) = reshape(b(1:tvtot),tvstate,nStates); % Time-varying parameter matrix. +b_shat(constinx,:) = repmat(b(tvtot+1:end), [1 nStates]); % Constant parameter matrix. +% +gmix = zeros(n0cumsum(end),nStates); + % Gradient matrix mixing time-varying and constant parameters. + % Rows of gmix, indexed by constinx, will not be used but instead treated + % different under "for kj=indxConst." +gtv = zeros(tvstate,nStates); % Gradient wrt time-varying parameters, which will be vectorized later. +gconst1 = zeros(constot,1); % The first gradient wrt constant parameters for the exponetial term. +gconst2=zeros(constot,1); % The second gradient wrt constant parameters for -T_klog|A0(k)|. + + +%--------------------------------------------------- +% Time-varying situation. See p. 34a. +%--------------------------------------------------- +%*** The derivative of the exponential term w.r.t. each free time-varying paramater. +for kj = 1:nvar % For all equations + lenbjs=length(n0cumsum(kj)+1:n0cumsum(kj+1)); + bj = zeros(nStates*lenbjs,1); + for si=1:nStates + bj((si-1)*lenbjs+1:si*lenbjs) = b_shat(n0cumsum(kj)+1:n0cumsum(kj+1),si); % bj(si). See p.34a. + A0(:,kj,si) = Uistar{kj}((si-1)*nvar+1:si*nvar,:)*b_shat(n0cumsum(kj)+1:n0cumsum(kj+1),si); + end + gj = (Uibar{kj}'*Sgm0tldinvaveTV*Uibar{kj})*bj; + if find(kj==indxTV) % For time-varying equations. + for si=1:nStates + gmix(n0cumsum(kj)+1:n0cumsum(kj+1),si) = gj((si-1)*lenbjs+1:si*lenbjs); + end + end +end + +%*** Add the derivative of -T_klog|A0(k)| w.r.t. each free time-varying paramater. +for si=1:nStates % See p.34a. + B0(:,:,si)=inv(A0(:,:,si)'); + for ki = tvinx % Those from 1 to sum(q_i) that pertain to time-varying parameters. + n = max(find( (ki-n0cumsum)>0 )); % note, 1<=n<=nvar equations. + gmix(ki,si) = gmix(ki,si) - Tkave(si)*B0(:,n,si)'*Uistar{n}((si-1)*nvar+1:si*nvar,ki-n0cumsum(n)); % See p.34a. + end +end + +%--------------------------------------------------- +% Constant-parameter situation. See pp. 34b-34c. +%--------------------------------------------------- +kcount = 0; % Counts. +for kj = indxConst % Equations + klocat=kcount+n0(kj); % Losition for the last constant element in the jth equation. + Bbar = repmat(eye(n0(kj)),[1 nStates]); % See p.34b. + lenbjs=length(n0cumsum(kj)+1:n0cumsum(kj+1)); + bj = zeros(nStates*lenbjs,1); + for si=1:nStates + bj((si-1)*lenbjs+1:si*lenbjs) = b_shat(n0cumsum(kj)+1:n0cumsum(kj+1),si); % bj(si). See p.34a. + A0(:,kj,si) = Uistar{kj}((si-1)*nvar+1:si*nvar,:)*b_shat(n0cumsum(kj)+1:n0cumsum(kj+1),si); + end + gconst1(kcount+1:klocat) = Bbar*( (Uibar{kj}'*Sgm0tldinvaveConst*Uibar{kj})*bj ); + kcount=klocat; +end +%*** Add the derivative of -T_klog|A0(k)| w.r.t. each free time-varying paramater. +kcount = 0; % Counts. +for ki = constinx % Those from 1 to sum(q_i) that pertain to constant parameters. + kcount=kcount+1; + n = max(find( (ki-n0cumsum)>0 )); % note, 1<=n<=nvar equations. + gi=0; % Initializes a gradient summed across the states. See p. 34c. + for si=1:nStates % See p.34c. + gi = gi - Tkave(si)*B0(:,n,si)'*Uistar{n}((si-1)*nvar+1:si*nvar,ki-n0cumsum(n)); % See p. 34a. + end + gconst2(kcount)=gi; +end + + +%--------------------------------------------------- +% Conclusion. +%--------------------------------------------------- +gtv = gmix(tvinx,:); % Extract the gradient wrt time-varying parameters. +gconst = gconst1+gconst2; % Gradient wrt to constant parameters. +% +g = [gtv(:);gconst]; % Vectorized the same way as b is vectorized. +badg = 0; % This term is used for Sims's csminwel program. diff --git a/MatlabFiles/fn_calyrqm.m b/MatlabFiles/fn_calyrqm.m new file mode 100755 index 0000000..695c23d --- /dev/null +++ b/MatlabFiles/fn_calyrqm.m @@ -0,0 +1,58 @@ +function [Myrqm,nMyrqm] = fn_calyrqm(q_m,Byrqm,Eyrqm) +% [Myrqm,nMyrqm] = fn_calyrqm(q_m,Byrqm,Eyrqm) +% +% Given the beginning and end years and quarters (months), export a matrix of all years and +% quarters (months) for these years and in between +% +% q_m: 4 if quarterly and 12 if monthly +% Byrqm: [year quarter(month)] -- all integers, the begining year and quarter (month) +% Eyrqm: [year quarter(month)] -- all integers, the end year and quarter (month) +%------------------- +% Myrqm: matrix of all years and quarters (months) between and incl. Byrqm and Eyrqm +% nMyrqm: number of data points incl. Byrqm and Eyrqm +% +% Tao Zha, April 2000 + +if ~isempty(find(Byrqm-round(Byrqm))) | (q_m-round(q_m)) | ~isempty(find(Byrqm-round(Byrqm))) + error('argin qm, Byrqm, or Eyrqm must of integer') +elseif Byrqm(1)>Eyrqm(1) + error('Eyrqm(1) must be equal to or greater than Byrqm(1)') +elseif Byrqm(1)==Eyrqm(1) + if Byrqm(2)>Eyrqm(2) + error('Eyrqm(2) must be equal to or greater than Byrqm(2) because of the same year') + end +end + + +Yr = Byrqm(1)+[0:Eyrqm(1)-Byrqm(1)]'; + +if length(Yr)>=2 % there are years and quarters (months) between Byrqm and Eyrqm + n=length(Yr)-2; + C=zeros(n*q_m,2); + C(:,1) = kron(Yr(2:end-1),ones(q_m,1)); + C(:,2) = kron(ones(n,1),[1:q_m]'); + + %* initialize a matrix of years and quarters (months) including Byrqm and Eyrqm + Myrqm = zeros((q_m-Byrqm(2)+1)+Eyrqm(2)+n*q_m,2); + + %* Years in between + n1=q_m-Byrqm(2)+1; + n2=Eyrqm(2); + Myrqm(n1+1:end-n2,:) = C; + %* Beginning year + for k=1:n1 + Myrqm(k,:) = [Byrqm(1) Byrqm(2)+k-1]; + end + %* End year + for k=1:n2 + Myrqm(end-Eyrqm(2)+k,:) = [Eyrqm(1) k]; + end +else %* all the data are in the same calendar year + n1=Eyrqm(2)-Byrqm(2)+1; + Myrqm = zeros(n1,2); + for k=1:n1 + Myrqm(k,:) = [Byrqm(1) Byrqm(2)+k-1]; + end +end + +nMyrqm = size(Myrqm,1); diff --git a/MatlabFiles/fn_construct_cov.m b/MatlabFiles/fn_construct_cov.m new file mode 100755 index 0000000..cb3a592 --- /dev/null +++ b/MatlabFiles/fn_construct_cov.m @@ -0,0 +1,19 @@ +function covM = fn_construct_cov(diagcovM, corM) +% function corM = corr(covM) +% diagcovM: diag of covariance matrix (input) +% corM: correlation matrix (input) +% covM: covariance matrix (output) +% 9 May 2008 + +[nvar,jnk]=size(corM); +if nvar~=jnk + error('The input matrix must be square!!') +end +covM=zeros(nvar); + +for i=1:nvar + for j=1:nvar + covM(i,j)= corM(i,j) * sqrt( diagcovM(i) * diagcovM(j) ); + end +end + diff --git a/MatlabFiles/fn_corr.m b/MatlabFiles/fn_corr.m new file mode 100755 index 0000000..6464945 --- /dev/null +++ b/MatlabFiles/fn_corr.m @@ -0,0 +1,18 @@ +function corM = fn_corr(covM) +% function corM = fn_corr(covM) +% +% covM: covariance matrix (input) +% corM: correlation matrix (output) +% 6 September 1998 + +[nvar,jnk]=size(covM); +if nvar~=jnk + error('The input matrix must be square!!') +end +corM=zeros(nvar); +for i=1:nvar + for j=1:nvar + corM(i,j)=covM(i,j) / sqrt( covM(i,i) * covM(j,j)); + end +end + diff --git a/MatlabFiles/fn_dataext.m b/MatlabFiles/fn_dataext.m new file mode 100755 index 0000000..0eaa3ae --- /dev/null +++ b/MatlabFiles/fn_dataext.m @@ -0,0 +1,43 @@ +function [xdsube,Brow,Erow] = fn_dataext(Byrqm,Eyrqm,xdatae) +% xdsube = dataext(Byrqm,Eyrqm,xdatae) +% Extract subset of xdatae, given Byrqm and Eyrqm +% +% Byrqm: [year quarter(month)]: beginning year and period. If Byqm(2)=0, we get annual data. +% Eyrqm: [year period]: end year and period. If Byrqm(2)=0, it must be Eyrqm(2)=0. +% xdatae: all data (some of which may be NaN) with the first 2 columns indicating years and periods. +%---------- +% xdsube: subset of xdatae. +% Brow: the row number in xdatee that marks the first row of xdsube. +% Erow: the row number in xdatee that marks the last row of xdsube. +% +% Tao Zha, April 2000 + +if (Byrqm(2)==0) & (Eyrqm(2)~=0) + error('If annual data, make sure both Byrqm(2) and Eyrqm(2) are zero') +end + +Brow = min(find(xdatae(:,1)==Byrqm(1))); +if isempty(Brow) + error('Byrqm is outside the date range indicated by xdatae(:,1:2)!') +end +if Byrqm(2)>0 + nadt=Byrqm(2)-xdatae(Brow,2); + if nadt<0 + error('Byrqm is outside the date range indicated by xdatae(:,1:2)!') + end + Brow=Brow+nadt; +end +% +Erow = min(find(xdatae(:,1)==Eyrqm(1))); +if isempty(Erow) + error('Eyrqm is outside the date range indicated by xdatae(:,1:2)!') +end +if Eyrqm(2)>0 + nadt2=Eyrqm(2)-xdatae(Erow,2); + if nadt<0 + error('Eyrqm is outside the date range indicated by xdatae(:,1:2)!') + end + Erow=Erow+nadt2; +end +% +xdsube = xdatae(Brow:Erow,:); % with dates diff --git a/MatlabFiles/fn_dataext2.m b/MatlabFiles/fn_dataext2.m new file mode 100755 index 0000000..8a34b88 --- /dev/null +++ b/MatlabFiles/fn_dataext2.m @@ -0,0 +1,56 @@ +function [xdsube,Brow,Erow] = fn_dataext2(Byrqm,Eyrqm,xdatae) +% xdsube = dataext(Byrqm,Eyrqm,xdatae) +% Extract subset of xdatae, given Byrqm and Eyrqm +% +% Byrqm: [year quarter(month)]: beginning year and period. If Byqm(2)=0, we get annual data. +% Eyrqm: [year period]: end year and period. If Byrqm(2)=0, it must be Eyrqm(2)=0. +% xdatae: all data (some of which may be NaN) with the first 2 columns indicating years and periods. +%---------- +% xdsube: subset of xdatae. +% Brow: the row number in xdatee that marks the first row of xdsube. +% Erow: the row number in xdatee that marks the last row of xdsube. +% +% Tao Zha, April 2000 + +if (Byrqm(2)==0) + Eyrqm(2)=0; + q_m1=find(xdatae(:,2)==xdatae(1,2)); % Locating quarter or month + if length(q_m1)<2 + error('The matrix xdatae must at least have a cycle of q_m periods for possibly one calendar year') + end + q_m=q_m1(2)-1; +end + +Brow = min(find(xdatae(:,1)==Byrqm(1))); +if isempty(Brow) + error('Byrqm is outside the date range indicated by xdatae(:,1:2)!') +end +if Byrqm(2)>0 + nadt=Byrqm(2)-xdatae(Brow,2); + if nadt<0 + error('Byrqm is outside the date range indicated by xdatae(:,1:2)!') + end + Brow=Brow+nadt; +end +% +Erow = min(find(xdatae(:,1)==Eyrqm(1))); +if isempty(Erow) + error('Eyrqm is outside the date range indicated by xdatae(:,1:2)!') +end +if Eyrqm(2)>0 + nadt2=Eyrqm(2)-xdatae(Erow,2); + if nadt<0 + error('Eyrqm is outside the date range indicated by xdatae(:,1:2)!') + end + Erow=Erow+nadt2; +end +% + +if (Byrqm(2)==0) % By calendar years. + if (xdatae(Brow,2)~=1) | (xdatae(Erow,2)~=1) + error('Calendar years extracted here must have q_m periods') + end + Erow=Erow+q_m-1; +end + +xdsube = xdatae(Brow:Erow,:); % with dates diff --git a/MatlabFiles/fn_datana.m b/MatlabFiles/fn_datana.m new file mode 100755 index 0000000..91d5732 --- /dev/null +++ b/MatlabFiles/fn_datana.m @@ -0,0 +1,100 @@ +function [yactyrge,yactyre,yactqmyge,yactqmge,yactqme] = fn_datana(xdatae,q_m,vlistlog,vlistper,Byrqm,Eyrqm) +% [yactyrge,yactyre,yactqmyge,yactqmge,yactqme] = fn_datana(Byrqm,Eyrqm,xdatae,q_m,vlistlog,vlistper) +% +% Generate prior period, period-to-period-in-last-year, and annual growth rates +% For annual rates, works for both calendar and any annual years, depending on Byrqm and Eyrqm +% If monthly data, we haven't got time to get quarterly growth rates yet. +% +% xdatae: all data (logged levels or interest rates/100, some of which may be NaN) with the first +% 2 columns indicating years and periods. +% q_m: quarter or month period +% vlistlog: sublist for logged variables +% vlistper: sublists for percent variables +% Byrqm: [year quarter(month)]: beginning year and period. If Byqm(2)~=1, we don't get +% calendar annual rates. In other words, the first column of yactyge (which +% indicates years) does not mean calendar years. Byqm(2) must be specified; in other +% words, it must be not set to 0 as in, say, fn_dataext. +% Eyrqm: [year period]: end year and period. Eyqm(2) must be specified; in other words, it +% must be not set to 0 as in, say, fn_dataext. +% NOTE: if no inputs Byrqm and Eyrqm are specified, all growth rates begin at xdatae(1,1:2). +%---------- +% yactyrge: annual growth rates with dates in the first 2 columns. +% yactyre: annual average logged level with dates in the 1st 2 columns. +% yactqmyge: period-to-period-in-last-year annual growth rates with dates in the first 2 columns. +% yactqmge: prior-period annualized growth rates with dates in the first 2 columns. +% yactqme: data (logged levels or interest rates/100) with dates in the first 2 columns. +% Same as xdatae but with Brow:Erow. +% +% Tao Zha, April 2000. + +if size(xdatae,1)<2*q_m + error('We need at least two years of xdatae to get annual rates. Check xdatae!!') +end + +if nargin==4 + Brow=1; Erow=length(xdatae(:,1)); + nyr = floor((Erow-Brow+1)/q_m); + yrsg = [xdatae(q_m+1,1):xdatae(q_m+1,1)+nyr-2]'; % for annual growth later on +else + if Byrqm(2)<1 | Eyrqm(2)<1 + error('This function requires specifying both years and months (quarters) in Byrqm and Eyrqm') + end + + Brow = min(find(xdatae(:,1)==Byrqm(1))); + if isempty(Brow) + error('Byrqm is outside the date range of xdatae(:,1:2)!') + end + nadt=Byrqm(2)-xdatae(Brow,2); + if nadt<0 + error('Byrqm is outside the date range indicated by xdatae(:,1:2)!') + end + Brow=Brow+nadt; + % + Erow = min(find(xdatae(:,1)==Eyrqm(1))); + if isempty(Brow) + error('Eyrqm is outside the date range of xdatae(:,1:2)!') + end + nadt2=Eyrqm(2)-xdatae(Erow,2); + if nadt<0 + error('Eyrqm is outside the date range indicated by xdatae(:,1:2)!') + end + Erow=Erow+nadt2; + + nyr = floor((Erow-Brow+1)/q_m); + yrsg = [Byrqm(1)+1:Byrqm(1)+nyr-1]'; % for annual growth later on, which will + % start at Byrqm(1) instead of Byrqm(1)+1 +end +% +yactqme = xdatae(Brow:Erow,:); % with dates +yactqm = yactqme(:,3:end); % only data + +%======== prior period change (annaluized rate) +yactqmg = yactqm(2:end,:); % start at second period to get growth rate +yactqmg(:,vlistlog) = (yactqm(2:end,vlistlog) - yactqm(1:end-1,vlistlog)) .* q_m; + % monthly, 12*log(1+growth rate), annualized growth rate +yactqmg(:,vlistlog) = 100*(exp(yactqmg(:,vlistlog))-1); +yactqmg(:,vlistper) = 100*yactqmg(:,vlistper); +yactqmge = [yactqme(2:end,1:2) yactqmg]; + +%======== change from the last year +yactqmyg = yactqm(q_m+1:end,:); % start at the last-year period to get growth rate +yactqmyg(:,vlistlog) = (yactqm(q_m+1:end,vlistlog) - yactqm(1:end-q_m,vlistlog)); +yactqmyg(:,vlistlog) = 100*(exp(yactqmyg(:,vlistlog))-1); +yactqmyg(:,vlistper) = 100*yactqmyg(:,vlistper); +yactqmyge = [yactqme(q_m+1:end,1:2) yactqmyg]; + +%======== annual growth rates +nvar = length(xdatae(1,3:end)); +ygmts = yactqm(1:nyr*q_m,:); % converted to the multiplication of q_m +ygmts1 = reshape(ygmts,q_m,nyr,nvar); +ygmts2 = sum(ygmts1,1) ./ q_m; +ygmts3 = reshape(ygmts2,nyr,nvar); % converted to annual average series +% +yactyrg = ygmts3(2:end,:); % start at the last-year period to get growth rate +yactyrg(:,vlistlog) = ygmts3(2:end,vlistlog) - ygmts3(1:end-1,vlistlog); + % annual rate: log(1+growth rate) +yactyrg(:,vlistlog) = 100*(exp(yactyrg(:,vlistlog))-1); +yactyrg(:,vlistper) = 100*yactyrg(:,vlistper); +yactyrge = [yrsg zeros(nyr-1,1) yactyrg]; +yrsg1=[yrsg(1)-1:yrsg(end)]'; +yactyre = [yrsg1 zeros(nyr,1) ygmts3]; diff --git a/MatlabFiles/fn_datana2.m b/MatlabFiles/fn_datana2.m new file mode 100755 index 0000000..93b3d66 --- /dev/null +++ b/MatlabFiles/fn_datana2.m @@ -0,0 +1,177 @@ +function [yactyrge,yactyre,yactqmyge,yactqmge,yactqge,yacteoqyge,yactqme] = fn_datana2(xdatae,q_m,vlistlog,vlistper,Byrqm,Eyrqm) +% [yactyrge,yactyre,yactqmyge,yactqmge,yactqge,yacteoqyge,yactqme] = fn_datana2(xdatae,q_m,vlistlog,vlistper,Byrqm,Eyrqm) +% +% Generate prior period, period-this-year-to-period-last-year, and other growth rates. +% For annual rates, works for both calendar and any annual years, depending on Byrqm and Eyrqm +% +% xdatae: all data (logged levels or interest rates/100, some of which may be NaN) with the first +% 2 columns indicating years and periods. +% q_m: quarter or month period +% vlistlog: sublist for logged variables +% vlistper: sublists for percent variables +% Byrqm: [year quarter(month)] -- beginning year and period. Optional. If Byqm(2)~=1, we don't get +% calendar annual rates. In other words, the first column of yactyge (which +% indicates years) does not mean calendar years. Byqm(2) must be specified; in other +% words, it must be not set to 0 as in, say, fn_dataext. +% Eyrqm: [year period] -- end year and period. Optional. Eyqm(2) must be specified; in other words, it +% must be not set to 0 as in, say, fn_dataext. +% NOTE: if no inputs Byrqm and Eyrqm are specified, all growth rates begin at xdatae(1,1:2). +%---------- +% yactyrge: annual growth rates with dates in the first 2 columns. +% yactyre: annual average logged level with dates in the 1st 2 columns. +% yactqmyge: period-this-year-to-period-last-year annual growth rates with dates in the first 2 columns. +% yactqmge: prior-period annualized growth rates with dates in the first 2 columns. +% yactqge: if monthly data, prior-quarter annualized growth rate with dates in the first 2 columns; +% if not, yactqge = NaN. +% yacteoqyge: if monthly data, EOQ is last month of quarter. EOQ-this-year-to-EOQ-last-year annual growth rates with dates in first 2 columns. +% If not monthly data, yacteoqyge = NaN. +% Note that yacteoqyge(:,1:2) = yactqge(4:end,1:2). +% yactqme: data (logged levels or interest rates/100) with dates in the first 2 columns. +% Same as xdatae but with Brow:Erow. +% +% Tao Zha, April 2000. +% See the old but useful function fore_mqy.m. +% Added yactqge in February 2004. +% Added yacteoqyge in March 2004. + +if size(xdatae,1)<2*q_m + error('We need at least two years of xdatae to get annual rates. Check xdatae!!') +end + +if nargin==4 + Brow=1; Erow=length(xdatae(:,1)); + nyr = floor((Erow-Brow+1)/q_m); + yrsg = [xdatae(q_m+1,1):xdatae(q_m+1,1)+nyr-2]'; % for annual growth later on +else + if Byrqm(2)<1 | Eyrqm(2)<1 + error('This function requires specifying both years and months (quarters) in Byrqm and Eyrqm') + end + + Brow = min(find(xdatae(:,1)==Byrqm(1))); + if isempty(Brow) + error('Byrqm is outside the date range of xdatae(:,1:2)!') + end + nadt=Byrqm(2)-xdatae(Brow,2); + if nadt<0 + error('Byrqm is outside the date range indicated by xdatae(:,1:2)!') + end + Brow=Brow+nadt; + % + Erow = min(find(xdatae(:,1)==Eyrqm(1))); + if isempty(Brow) + error('Eyrqm is outside the date range of xdatae(:,1:2)!') + end + nadt2=Eyrqm(2)-xdatae(Erow,2); + if nadt<0 + error('Eyrqm is outside the date range indicated by xdatae(:,1:2)!') + end + Erow=Erow+nadt2; + + nyr = floor((Erow-Brow+1)/q_m); + yrsg = [Byrqm(1)+1:Byrqm(1)+nyr-1]'; % for annual growth later on, which will + % start at Byrqm(1) instead of Byrqm(1)+1 +end +% +yactqme = xdatae(Brow:Erow,:); % with dates +yactqm = yactqme(:,3:end); % only data + +%======== prior period change (annaluized rate) +yactqmg = yactqm(2:end,:); % start at second period to get growth rate +yactqmg(:,vlistlog) = (yactqm(2:end,vlistlog) - yactqm(1:end-1,vlistlog)) .* q_m; + % monthly, 12*log(1+growth rate), annualized growth rate +yactqmg(:,vlistlog) = 100*(exp(yactqmg(:,vlistlog))-1); +yactqmg(:,vlistper) = 100*yactqmg(:,vlistper); +yactqmge = [yactqme(2:end,1:2) yactqmg]; + +%======== change from the last year +yactqmyg = yactqm(q_m+1:end,:); % start at the last-year period to get growth rate +yactqmyg(:,vlistlog) = (yactqm(q_m+1:end,vlistlog) - yactqm(1:end-q_m,vlistlog)); +yactqmyg(:,vlistlog) = 100*(exp(yactqmyg(:,vlistlog))-1); +yactqmyg(:,vlistper) = 100*yactqmyg(:,vlistper); +yactqmyge = [yactqme(q_m+1:end,1:2) yactqmyg]; + +%======== annual growth rates +nvar = length(xdatae(1,3:end)); +ygmts = yactqm(1:nyr*q_m,:); % converted to the multiplication of q_m +ygmts1 = reshape(ygmts,q_m,nyr,nvar); +ygmts2 = sum(ygmts1,1) ./ q_m; +ygmts3 = reshape(ygmts2,nyr,nvar); % converted to annual average series +% +yactyrg = ygmts3(2:end,:); % start at the last-year period to get growth rate +yactyrg(:,vlistlog) = ygmts3(2:end,vlistlog) - ygmts3(1:end-1,vlistlog); + % annual rate: log(1+growth rate) +yactyrg(:,vlistlog) = 100*(exp(yactyrg(:,vlistlog))-1); +yactyrg(:,vlistper) = 100*yactyrg(:,vlistper); +yactyrge = [yrsg zeros(nyr-1,1) yactyrg]; +yrsg1=[yrsg(1)-1:yrsg(end)]'; +yactyre = [yrsg1 zeros(nyr,1) ygmts3]; + + +%======== Quarter-to-last quarter annualized growth rates. +if (q_m==12) + %=== Beginning row. + mcnt = mod(xdatae(1,2),3); %Begining month. + if (mcnt==0) + QrowBin = 2; % Reset the beginning month to match a quarter. + elseif (mcnt==1) + QrowBin = 1; % Reset the beginning month to match a quarter. + elseif (mcnt==2) + QrowBin = 3; % Reset the beginning month to match a quarter. + else + error('.../fn_datana2.m: Number for months in the dates must be between 1 and 12 inclusive'); + end + Qcnt = (xdatae(QrowBin,2)+2)/3; + if (xdatae(1,2)<11) % Up to October. + QyearBin = xdatae(1,1); + else % November and December. + QyearBin = xdatae(1,1) + 1; + end;%if + %=== Ending row. + QrowEnd = size(xdatae, 1) - mod(xdatae(end,2),3); % Reset the ending month to match a quarter. + nqs = (QrowEnd - QrowBin + 1)/3; + + + %=== Getting last month of the quarter (end of quarter: eoq). + yacteoq = xdatae(QrowBin:QrowEnd,3:end); % Without dates. + yacteoq1 = reshape(yacteoq, 3, nqs, nvar); + yacteoq2 = zeros(1, nqs, nvar); + yacteoq2(:,:,vlistper) = yacteoq1(3,:,vlistper); + yacteoq2(:,:,vlistlog) = yacteoq1(3,:,vlistlog); + yacteoq3 = reshape(yacteoq2, nqs, nvar); + %=== EOQ-this-year-to-EOQ-last-year annual growth rates. + yacteoqyg = yacteoq3(5:end,:); + yacteoqyg(:,vlistlog) = 100*(exp(yacteoq3(5:end, vlistlog) - yacteoq3(1:end-4, vlistlog))-1); + yacteoqyg(:,vlistper) = 100*yacteoqyg(:,vlistper); + + + %=== Getting quarterly averages. + yactq = xdatae(QrowBin:QrowEnd,3:end); % Without dates. + nqs = (QrowEnd - QrowBin + 1)/3; + yactq1 = reshape(yactq, 3, nqs, nvar); + yactq2 = zeros(1, nqs, nvar); + yactq2(:,:,vlistper) = sum(yactq1(:,:,vlistper), 1) ./ 3; + yactq2(:,:,vlistlog) = sum(exp(yactq1(:,:,vlistlog)), 1) ./ 3; + yactq3 = reshape(yactq2, nqs, nvar); + %=== Quarterly (to prior-quarter) annualized growth rates. + yactqg = yactq3(2:end,:); + yactqg(:,vlistlog) = 100*((yactq3(2:end, vlistlog) ./ yactq3(1:end-1, vlistlog)).^4-1); + yactqg(:,vlistper) = 100*yactqg(:,vlistper); + + + %======= Adding quarterly dates. ======= + qdates = zeros(nqs,2); + for k=1:nqs + qdates(k,1) = floor(QyearBin + (k+Qcnt-2)/4); + tmpi = mod(k+Qcnt-1, 4); + if (tmpi==0) + qdates(k,2) = 4; + else + qdates(k,2) = tmpi; + end + end + yacteoqyge = [qdates(5:end,:) yacteoqyg]; + yactqge = [qdates(2:end,:) yactqg]; +else + yacteoqyge = NaN; + yactqge = NaN; +end diff --git a/MatlabFiles/fn_dataxy.m b/MatlabFiles/fn_dataxy.m new file mode 100755 index 0000000..cd21674 --- /dev/null +++ b/MatlabFiles/fn_dataxy.m @@ -0,0 +1,147 @@ +function [xtx,xty,yty,fss,phi,y,ncoef,xr,Bh,e] = fn_dataxy(nvar,lags,z,mu,indxDummy,nexo) +% [xtx,xty,yty,fss,phi,y,ncoef,xr,Bh,e] = fn_dataxy(nvar,lags,z,mu,indxDummy,nexo) +% +% Export arranged data matrices for future estimation of the VAR. +% If indxDummy=0, no mu's are used at all and Bh is the OLS estimate. +% If indxDummy=1, only mu(5) and mu(6) as dummy observations. See fn_rnrprior*.m for using mu(1)-mu(4). +% See Wagonner and Zha's Gibbs sampling paper. +% +% nvar: number of endogenous variables. +% lags: the maximum length of lag +% z: T*(nvar+(nexo-1)) matrix of raw or original data (no manipulation involved) +% with sample size including lags and with exogenous variables other than a constant. +% Order of columns: (1) nvar endogenous variables; (2) (nexo-1) exogenous variables; +% (3) constants will be automatically put in the last column. +% mu: 6-by-1 vector of hyperparameters (the following numbers for Atlanta Fed's forecast), where +% only mu(5) and mu(6) are used for dummy observations in this function (i.e., +% mu(1)-mu(4) are irrelevant here). See fn_rnrprior*.m for using mu(1)-mu(4). +% mu(1): overall tightness and also for A0; (0.57) +% mu(2): relative tightness for A+; (0.13) +% mu(3): relative tightness for the constant term; (0.1) +% mu(4): tightness on lag decay; (1) +% mu(5): weight on nvar sums of coeffs dummy observations (unit roots); (5) +% mu(6): weight on single dummy initial observation including constant +% (cointegration, unit roots, and stationarity); (5) +% indxDummy: 1: add dummy observations to the data; 0: no dummy added. +% nexo: number of exogenous variables. The constant term is the default setting. Besides this term, +% we have nexo-1 exogenous variables. Optional. If left blank, nexo is set to 1. +% ------------------- +% xtx: X'X: k-by-k where k=ncoef +% xty: X'Y: k-by-nvar +% yty: Y'Y: nvar-by-nvar +% fss: T: sample size excluding lags. With dummyies, fss=nSample-lags+ndobs. +% phi: X; T-by-k; column: [nvar for 1st lag, ..., nvar for last lag, other exogenous terms, const term] +% y: Y: T-by-nvar where T=fss +% ncoef: number of coefficients in *each* equation. RHS coefficients only, nvar*lags+nexo +% xr: the economy size (ncoef-by-ncoef) in qr(phi) so that xr=chol(X'*X) or xr'*xr=X'*X +% Bh: ncoef-by-nvar estimated reduced-form parameter; column: nvar; +% row: ncoef=[nvar for 1st lag, ..., nvar for last lag, other exogenous terms, const term] +% e: estimated residual e = y -x*Bh, T-by-nvar +% +% Tao Zha, February 2000. + +if nargin == 5 + nexo=1; % default for constant term +elseif nexo<1 + error('We need at least one exogenous term so nexo must >= 1') +end + +%*** original sample dimension without dummy prior +nSample = size(z,1); % the sample size (including lags, of course) +sb = lags+1; % original beginning without dummies +ncoef = nvar*lags+nexo; % number of coefficients in *each* equation, RHS coefficients only. + +if indxDummy % prior dummy prior + %*** expanded sample dimension by dummy prior + ndobs=nvar+1; % number of dummy observations + fss = nSample+ndobs-lags; + + % + % **** nvar prior dummy observations with the sum of coefficients + % ** construct X for Y = X*B + U where phi = X: (T-lags)*k, Y: (T-lags)*nvar + % ** columns: k = # of [nvar for 1st lag, ..., nvar for last lag, exo var, const] + % ** Now, T=T+ndobs -- added with "ndobs" dummy observations + % + phi = zeros(fss,ncoef); + %* constant term + const = ones(fss,1); + const(1:nvar) = zeros(nvar,1); + phi(:,ncoef) = const; % the first nvar periods: no or zero constant! + %* other exogenous (than) constant term + phi(ndobs+1:end,ncoef-nexo+1:ncoef-1) = z(lags+1:end,nvar+1:nvar+nexo-1); + exox = zeros(ndobs,nexo); + phi(1:ndobs,ncoef-nexo+1:ncoef-1) = exox(:,1:nexo-1); + % this = [] when nexo=1 (no other exogenous than constant) + + xdgel = z(:,1:nvar); % endogenous variable matrix + xdgelint = mean(xdgel(1:lags,:),1); % mean of the first lags initial conditions + %* Dummies + for k=1:nvar + for m=1:lags + phi(ndobs,nvar*(m-1)+k) = xdgelint(k); + phi(k,nvar*(m-1)+k) = xdgelint(k); + % <<>> multiply hyperparameter later + end + end + %* True data + for k=1:lags + phi(ndobs+1:fss,nvar*(k-1)+1:nvar*k) = xdgel(sb-k:nSample-k,:); + % row: T-lags; column: [nvar for 1st lag, ..., nvar for last lag, exo var, const] + % Thus, # of columns is nvar*lags+nexo = ncoef. + end + % + % ** Y with "ndobs" dummies added + y = zeros(fss,nvar); + %* Dummies + for k=1:nvar + y(ndobs,k) = xdgelint(k); + y(k,k) = xdgelint(k); + % multiply hyperparameter later + end + %* True data + y(ndobs+1:fss,:) = xdgel(sb:nSample,:); + + phi(1:nvar,:) = 1*mu(5)*phi(1:nvar,:); % standard Sims and Zha prior + y(1:nvar,:) = mu(5)*y(1:nvar,:); % standard Sims and Zha prior + phi(nvar+1,:) = mu(6)*phi(nvar+1,:); + y(nvar+1,:) = mu(6)*y(nvar+1,:); + + [xq,xr]=qr(phi,0); + xtx=xr'*xr; + xty=phi'*y; + [yq,yr]=qr(y,0); + yty=yr'*yr; + Bh = xr\(xr'\xty); % xtx\xty where inv(X'X)*(X'Y) + e=y-phi*Bh; +else + fss = nSample-lags; + % + % ** construct X for Y = X*B + U where phi = X: (T-lags)*k, Y: (T-lags)*nvar + % ** columns: k = # of [nvar for 1st lag, ..., nvar for last lag, exo var, const] + % + phi = zeros(fss,ncoef); + %* constant term + const = ones(fss,1); + phi(:,ncoef) = const; % the first nvar periods: no or zero constant! + %* other exogenous (than) constant term + phi(:,ncoef-nexo+1:ncoef-1) = z(lags+1:end,nvar+1:nvar+nexo-1); + % this = [] when nexo=1 (no other exogenous than constant) + + xdgel = z(:,1:nvar); % endogenous variable matrix + %* True data + for k=1:lags + phi(:,nvar*(k-1)+1:nvar*k) = xdgel(sb-k:nSample-k,:); + % row: T-lags; column: [nvar for 1st lag, ..., nvar for last lag, exo var, const] + % Thus, # of columns is nvar*lags+nexo = ncoef. + end + % + y = xdgel(sb:nSample,:); + + [xq,xr]=qr(phi,0); + xtx=xr'*xr; + xty=phi'*y; + [yq,yr]=qr(y,0); + yty=yr'*yr; + Bh = xr\(xr'\xty); % xtx\xty where inv(X'X)*(X'Y) + e=y-phi*Bh; +end diff --git a/MatlabFiles/fn_dataxy7982.m b/MatlabFiles/fn_dataxy7982.m new file mode 100755 index 0000000..74de9b4 --- /dev/null +++ b/MatlabFiles/fn_dataxy7982.m @@ -0,0 +1,166 @@ +function [xtx,xty,yty,fss,phi,y,ncoef,xr,Bh,e] = fn_dataxy7982(nvar,lags,z,mu,indxDummy,... + q_m,SpBin,SkipBin,SkipFin,nexo) +% [xtx,xty,yty,fss,phi,y,ncoef,xr,Bh,e] = fn_dataxy7982(nvar,lags,z,mu,indxDummy,... +% q_m,SpBin,SkipBin,SkipFin,nexo) +% Export arranged data matrices for future estimation for DM models with the period from +% SkipBin to SkipFin to be skiped. +% See Wagonner and Zha's Gibbs sampling paper. +% +% nvar: number of endogenous variables. +% lags: the maximum length of lag +% z: T*(nvar+(nexo-1)) matrix of raw or original data (no manipulation involved) +% with sample size including lags and with exogenous variables other than a constant. +% Order of columns: (1) nvar endogenous variables; (2) (nexo-1) exogenous variables; +% (3) constants are automatically put in the last column. +% mu: 6-by-1 vector of hyperparameters (the following numbers for Atlanta Fed's forecast) +% mu(1): overall tightness and also for A0; (0.57) +% mu(2): relative tightness for A+; (0.13) +% mu(3): relative tightness for the constant term; (0.1) +% mu(4): tightness on lag decay; (1) +% mu(5): weight on nvar sums of coeffs dummy observations (unit roots); (5) +% mu(6): weight on single dummy initial observation including constant +% (cointegration, unit roots, and stationarity); (5) +% Here, only mu(5) and mu(6) are used for dummy observations +% indxDummy = 1; % 1: add dummy observations to the data; 0: no dummy added. +% q_m: 12 (monthly) or 4 (quarterly). +% SpBin: [year month] at the begining of the sample (including lags). +% SkipBin: [year month] at the begining of the skipped period. +% SkipFin: [year month] at the end of the skipped period. +% nexo: number of exogenous variables. The constant term is the default setting. Besides this term, +% we have nexo-1 exogenous variables. +% ------------------- +% xtx: X'X: k-by-k where k=ncoef +% xty: X'Y: k-by-nvar +% yty: Y'Y: nvar-by-nvar +% fss: T: sample size excluding lags. With dummyies, fss=nSample-lags+ndobs. +% phi: X; T-by-k; column: [nvar for 1st lag, ..., nvar for last lag, other exogenous terms, const term] +% y: Y: T-by-nvar where T=fss +% ncoef: number of coefficients in *each* equation. RHS coefficients only, nvar*lags+nexo +% xr: the economy size (ncoef-by-ncoef) in qr(phi) so that xr=chol(X'*X) or xr'*xr=X'*X +% Bh: ncoef-by-nvar estimated reduced-form parameter; column: nvar; +% row: ncoef=[nvar for 1st lag, ..., nvar for last lag, other exogenous terms, const term] +% e: estimated residual e = y -x*Bh, T-by-nvar +% +% Tao Zha, February 2000. Revised, May 2001. +% See fn_dataxy.m. + +if nargin == 9 + nexo=1; % default for constant term +elseif nexo<1 + error('We need at least one exogenous term so nexo must >= 1') +end + +%*** original sample dimension without dummy prior +nSample = size(z,1); % the sample size (including lags, of course) +sb = lags+1; % original beginning without dummies +ncoef = nvar*lags+nexo; % number of coefficients in *each* equation, RHS coefficients only. + +if indxDummy % prior dummy prior + + %*** expanded sample dimension by dummy prior + ndobs=nvar+1; % number of dummy observations + fss = nSample+ndobs-lags; + + % + % **** nvar prior dummy observations with the sum of coefficients + % ** construct X for Y = X*B + U where phi = X: (T-lags)*k, Y: (T-lags)*nvar + % ** columns: k = # of [nvar for 1st lag, ..., nvar for last lag, exo var, const] + % ** Now, T=T+ndobs -- added with "ndobs" dummy observations + % + phi = zeros(fss,ncoef); + %* constant term + const = ones(fss,1); + const(1:nvar) = zeros(nvar,1); + phi(:,ncoef) = const; % the first nvar periods: no or zero constant! + %* other exogenous (than) constant term + phi(ndobs+1:end,ncoef-nexo+1:ncoef-1) = z(lags+1:end,nvar+1:nvar+nexo-1); + exox = zeros(ndobs,nexo); + phi(1:ndobs,ncoef-nexo+1:ncoef-1) = exox(:,1:nexo-1); + % this = [] when nexo=1 (no other exogenous than constant) + + xdgel = z(:,1:nvar); % endogenous variable matrix + xdgelint = mean(xdgel(1:lags,:),1); % mean of the first lags initial conditions + %* Dummies + for k=1:nvar + for m=1:lags + phi(ndobs,nvar*(m-1)+k) = xdgelint(k); + phi(k,nvar*(m-1)+k) = xdgelint(k); + % <<>> multiply hyperparameter later + end + end + %* True data + for k=1:lags + phi(ndobs+1:fss,nvar*(k-1)+1:nvar*k) = xdgel(sb-k:nSample-k,:); + % row: T-lags; column: [nvar for 1st lag, ..., nvar for last lag, exo var, const] + % Thus, # of columns is nvar*lags+nexo = ncoef. + end + % + % ** Y with "ndobs" dummies added + y = zeros(fss,nvar); + %* Dummies + for k=1:nvar + y(ndobs,k) = xdgelint(k); + y(k,k) = xdgelint(k); + % multiply hyperparameter later + end + %* True data + y(ndobs+1:fss,:) = xdgel(sb:nSample,:); + + phi(1:nvar,:) = 1*mu(5)*phi(1:nvar,:); % standard Sims and Zha prior + y(1:nvar,:) = mu(5)*y(1:nvar,:); % standard Sims and Zha prior + phi(nvar+1,:) = mu(6)*phi(nvar+1,:); + y(nvar+1,:) = mu(6)*y(nvar+1,:); + + %-------------- Taking the 79:10-83:12 period out ---------------------- + outper1=(SkipBin(1)-SpBin(1))*q_m+(SkipBin(2)-SpBin(2)+1) + ndobs-lags; + outper2=(SkipFin(1)-SpBin(1))*q_m+(SkipFin(2)-SpBin(2)+1) + ndobs-lags; + phi(outper1:outper2,:)=[]; + y(outper1:outper2,:)=[]; + fss=size(phi,1); + + [xq,xr]=qr(phi,0); + xtx=xr'*xr; + xty=phi'*y; + [yq,yr]=qr(y,0); + yty=yr'*yr; + Bh = xr\(xr'\xty); % xtx\xty where inv(X'X)*(X'Y) + e=y-phi*Bh; +else + fss = nSample-lags; + % + % ** construct X for Y = X*B + U where phi = X: (T-lags)*k, Y: (T-lags)*nvar + % ** columns: k = # of [nvar for 1st lag, ..., nvar for last lag, exo var, const] + % + phi = zeros(fss,ncoef); + %* constant term + const = ones(fss,1); + phi(:,ncoef) = const; % the first nvar periods: no or zero constant! + %* other exogenous (than) constant term + phi(:,ncoef-nexo+1:ncoef-1) = z(lags+1:end,nvar+1:nvar+nexo-1); + % this = [] when nexo=1 (no other exogenous than constant) + + xdgel = z(:,1:nvar); % endogenous variable matrix + %* True data + for k=1:lags + phi(:,nvar*(k-1)+1:nvar*k) = xdgel(sb-k:nSample-k,:); + % row: T-lags; column: [nvar for 1st lag, ..., nvar for last lag, exo var, const] + % Thus, # of columns is nvar*lags+nexo = ncoef. + end + % + y = xdgel(sb:nSample,:); + + %-------------- Taking the 79:10-83:12 period out ---------------------- + outper1=(SkipBin(1)-SpBin(1))*q_m+(SkipBin(2)-SpBin(2)+1) - lags; + outper2=(SkipFin(1)-SpBin(1))*q_m+(SkipFin(2)-SpBin(2)+1) - lags; + phi(outper1:outper2,:)=[]; + y(outper1:outper2,:)=[]; + fss=size(phi,1); + + [xq,xr]=qr(phi,0); + xtx=xr'*xr; + xty=phi'*y; + [yq,yr]=qr(y,0); + yty=yr'*yr; + Bh = xr\(xr'\xty); % xtx\xty where inv(X'X)*(X'Y) + e=y-phi*Bh; +end diff --git a/MatlabFiles/fn_dataxyOldVer.m b/MatlabFiles/fn_dataxyOldVer.m new file mode 100755 index 0000000..0c532ff --- /dev/null +++ b/MatlabFiles/fn_dataxyOldVer.m @@ -0,0 +1,140 @@ +function [xtx,xty,yty,fss,phi,y,ncoef,xr,Bh,e] = fn_dataxyOldVer(nvar,lags,z,mu5,mu6,indxDummy,nexo) +% Export arranged data matrices (including dummy obs priors) for estimation for DM models. +% See Wagonner and Zha's Gibbs sampling paper. +% +% nvar: number of endogenous variables. +% lags: the maximum length of lag +% z: T*(nvar+(nexo-1)) matrix of raw or original data (no manipulation involved) +% with sample size including lags and with exogenous variables other than a constant. +% Order of columns: (1) nvar endogenous variables; (2) (nexo-1) exogenous variables; +% (3) constants are automatically put in the last column. +% mu5: nvar-by-1 weights on nvar sums of coeffs dummy observations (unit roots); (all equal 5--Atlanta model setting) +% mu6: weight on single dummy initial observation including constant +% (cointegration, unit roots, and stationarity); (5--Atlanta model number) +% indxDummy = 1; % 1: add dummy observations to the data; 0: no dummy added. +% nexo: number of exogenous variables. The constant term is the default setting. Besides this term, +% we have nexo-1 exogenous variables. +% ------------------- +% xtx: X'X: k-by-k where k=ncoef +% xty: X'Y: k-by-nvar +% yty: Y'Y: nvar-by-nvar +% fss: T: sample size excluding lags. With dummyies, fss=nSample-lags+ndobs. +% phi: X; T-by-k; column: [nvar for 1st lag, ..., nvar for last lag, other exogenous terms, const term] +% y: Y: T-by-nvar where T=fss +% ncoef: number of coefficients in *each* equation. RHS coefficients only, nvar*lags+nexo +% xr: the economy size (ncoef-by-ncoef) in qr(phi) so that xr=chol(X'*X) or xr'*xr=X'*X +% Bh: ncoef-by-nvar estimated reduced-form parameter; column: nvar; +% row: ncoef=[nvar for 1st lag, ..., nvar for last lag, other exogenous terms, const term] +% e: estimated residual e = y -x*Bh, T-by-nvar +% +% Tao Zha, February 2000 +% See fn_rnrprior2.m for the base prior. + +if nargin == 6 + nexo=1; % default for constant term +elseif nexo<1 + error('We need at least one exogenous term so nexo must >= 1') +end + +%*** original sample dimension without dummy prior +nSample = size(z,1); % the sample size (including lags, of course) +sb = lags+1; % original beginning without dummies +ncoef = nvar*lags+nexo; % number of coefficients in *each* equation, RHS coefficients only. + +if indxDummy % prior dummy prior + + %*** expanded sample dimension by dummy prior + ndobs=nvar+1; % number of dummy observations + fss = nSample+ndobs-lags; + + % + % **** nvar prior dummy observations with the sum of coefficients + % ** construct X for Y = X*B + U where phi = X: (T-lags)*k, Y: (T-lags)*nvar + % ** columns: k = # of [nvar for 1st lag, ..., nvar for last lag, exo var, const] + % ** Now, T=T+ndobs -- added with "ndobs" dummy observations + % + phi = zeros(fss,ncoef); + %* constant term + const = ones(fss,1); + const(1:nvar) = zeros(nvar,1); + phi(:,ncoef) = const; % the first nvar periods: no or zero constant! + %* other exogenous (than) constant term + phi(ndobs+1:end,ncoef-nexo+1:ncoef-1) = z(lags+1:end,nvar+1:nvar+nexo-1); + exox = zeros(ndobs,nexo); + phi(1:ndobs,ncoef-nexo+1:ncoef-1) = exox(:,1:nexo-1); + % this = [] when nexo=1 (no other exogenous than constant) + + xdgel = z(:,1:nvar); % endogenous variable matrix + xdgelint = mean(xdgel(1:lags,:),1); % mean of the first lags initial conditions + %* Dummies + for k=1:nvar + for m=1:lags + phi(ndobs,nvar*(m-1)+k) = xdgelint(k); + phi(k,nvar*(m-1)+k) = xdgelint(k); + % <<>> multiply hyperparameter later + end + end + %* True data + for k=1:lags + phi(ndobs+1:fss,nvar*(k-1)+1:nvar*k) = xdgel(sb-k:nSample-k,:); + % row: T-lags; column: [nvar for 1st lag, ..., nvar for last lag, exo var, const] + % Thus, # of columns is nvar*lags+nexo = ncoef. + end + % + % ** Y with "ndobs" dummies added + y = zeros(fss,nvar); + %* Dummies + for k=1:nvar + y(ndobs,k) = xdgelint(k); + y(k,k) = xdgelint(k); + % multiply hyperparameter later + end + %* True data + y(ndobs+1:fss,:) = xdgel(sb:nSample,:); + + for ki=1:nvar + phi(ki,:) = 1*mu5(ki)*phi(ki,:); % standard Sims and Zha prior + y(ki,:) = mu5(ki)*y(ki,:); % standard Sims and Zha prior + end + phi(nvar+1,:) = mu6*phi(nvar+1,:); + y(nvar+1,:) = mu6*y(nvar+1,:); + + [xq,xr]=qr(phi,0); + xtx=xr'*xr; + xty=phi'*y; + [yq,yr]=qr(y,0); + yty=yr'*yr; + Bh = xr\(xr'\xty); % xtx\xty where inv(X'X)*(X'Y) + e=y-phi*Bh; +else + fss = nSample-lags; + % + % ** construct X for Y = X*B + U where phi = X: (T-lags)*k, Y: (T-lags)*nvar + % ** columns: k = # of [nvar for 1st lag, ..., nvar for last lag, exo var, const] + % + phi = zeros(fss,ncoef); + %* constant term + const = ones(fss,1); + phi(:,ncoef) = const; % the first nvar periods: no or zero constant! + %* other exogenous (than) constant term + phi(:,ncoef-nexo+1:ncoef-1) = z(lags+1:end,nvar+1:nvar+nexo-1); + % this = [] when nexo=1 (no other exogenous than constant) + + xdgel = z(:,1:nvar); % endogenous variable matrix + %* True data + for k=1:lags + phi(:,nvar*(k-1)+1:nvar*k) = xdgel(sb-k:nSample-k,:); + % row: T-lags; column: [nvar for 1st lag, ..., nvar for last lag, exo var, const] + % Thus, # of columns is nvar*lags+nexo = ncoef. + end + % + y = xdgel(sb:nSample,:); + + [xq,xr]=qr(phi,0); + xtx=xr'*xr; + xty=phi'*y; + [yq,yr]=qr(y,0); + yty=yr'*yr; + Bh = xr\(xr'\xty); % xtx\xty where inv(X'X)*(X'Y) + e=y-phi*Bh; +end diff --git a/MatlabFiles/fn_demarw.m b/MatlabFiles/fn_demarw.m new file mode 100755 index 0000000..d536989 --- /dev/null +++ b/MatlabFiles/fn_demarw.m @@ -0,0 +1,58 @@ +function [imfl,imfh,imfl1,imfh1, imfmedian] = demarw(xpo,xprob) +% [imfl,imfh,imfl1,imfh1] = fn_demarw(xpo,xprob) +% Demarcate the .68 and .90 error bands given positions and properly scaled probabilities (weights). +% Calls fn_histwpdfg() first. +% +% xpo: ndraws-by-n. Centered position +% xprob: ndraws-by-n. Must be properly scaled probabilities corresponding to xpo. +%----------------- +% imfl: lower .90 bound, n-by-1 +% imfh: higher .90 bound, n-by-1 +% imfl1: lower .68 bound, n-by-1 +% imfh1: higher .68 bound, n-by-1 +% imfmedian: .50 estimate, n-by-1. +% +% Note: fn_histwpdfg() must be called first to get xpo and xprob. +% August 1999 Tao Zha; Revised, August 2000 + +[ndraws,n]=size(xpo); + +%$$$ .68 and .95 probability bands +imfl = zeros(n,1); % preallocating +imfh = zeros(n,1); % preallocating +imfl1 = zeros(n,1); % preallocating +imfh1 = zeros(n,1); % preallocating +imfmedian = zeros(n,1); % preallocating +imfpo = zeros(4,n); % 4 positions: l,h,l1,h1. +% +%tic +tem = cumsum(xprob); % cumulative probability +tem = tem .* 100; +% +%@@@ the following operations are valid only because tem are increasing! +for k = 1:n + % + %@@@ the following operations are valid only because tem are increasing! + %** 5% low tail + if isempty(max(find(tem(:,k)<5))) + imfl(k) = xpo(1,k); + else + imfl(k) = xpo(max(find(tem(:,k)<5)),k); + end + %** 16% low tail + if isempty(max(find(tem(:,k)<16))) + imfl1(k) = xpo(1,k); + else + imfl1(k) = xpo(max(find(tem(:,k)<16)),k); + end + %** 50% estimate + if isempty(max(find(tem(:,k)<50))) + imfmedian(k) = xpo(1,k); + else + imfmedian(k) = xpo(max(find(tem(:,k)<50)),k); + end + %** 5% high tail + imfh(k) = xpo(min(find(tem(:,k)>95)),k); + %** 16% low tail + imfh1(k) = xpo(min(find(tem(:,k)>84)),k); +end diff --git a/MatlabFiles/fn_dirichprior.m b/MatlabFiles/fn_dirichprior.m new file mode 100755 index 0000000..4dd76cd --- /dev/null +++ b/MatlabFiles/fn_dirichprior.m @@ -0,0 +1,78 @@ +function [Galpha,stdthe] = fn_dirichprior(Glamda,std_maxv) +% [Galpha,stdthe] = fn_dirichprior(Glamda,std_maxv) +% Setup of the Dirichlet prior on the transition matrix P. Given the mode of each random +% variable theta_j, solve for the (hyper)parameter \alpha where one of \alpha, say, \alpha_j +% is free for controlling the overall variance of \alpha consisdent with the given modes. +% +% Glamda: h-by-1 vector of prior modes for the random variables \theta. +% For each column of P (transitional matrix), Glamda'll be different with a large weight on a diaganol. +% std_maxv: prior standard deviation for the selected random variable +% (here the one with the maximum (largest) mode). +%---------- +% Galpha: h-by-1 vector of parameters' values for the Dirichlet distribtuion. If one of the +% elements in Galpha is Inf, we mean a degenerate case where stdthe is set to zeros. +% stdthe: h-by-1 vector of standard deviations for all random variables \theta. +% +% See Gelman, et al p. 476 and TVBvar Note pp. 24-31 +% Tao Zha, March 2001 + +Glamda = Glamda(:); % Column vector! Prior modes for the random variables \theta. +[maxlam,indxlam] = max(Glamda); % index for the selected hyperparameter that is freely set to match the variance of the corresponding random variable. +ndiri = length(Glamda); % the number of random variables in the Dirichlet distribution. +Galpha=zeros(ndiri,1); % \alpha's: hyperparameters that need to be choosen. Must be all greater than 1. +stdthe = zeros(ndiri,1); % Standard deviations for each \theta +if indxlam>ndiri + warning('Make sure indxlam is less than the total number of parameters in the Dirichlet') + error(' ') +end +if (maxlam==1) % We treat this as a degenerate case for convenient coding. + Galpha(indxlam)=Inf; % Note the use of Inf, NOT NaN. Because + % 0(or any finite number)/Inf=0 while 0/NaN gives a nonsense (i.e., NaN again). + % See tveml.m and pp. 27a-27b for more information. + return % The function stops here. +end + + +%*** Given std_maxv, find the corresponding hyperparameter Galpha_j by soloving +% a polynomial of order 3. See Note (*) page 30. +vj=std_maxv^2; % variance of the selected random variable \theta. +Gsi = (1-Glamda(indxlam))/Glamda(indxlam); % unchanged value, given Glamda. +coevec = zeros(4,1); % 4 because we're going to consider a polynomial of order 3 (+ constant). +coevec(1) = vj*(1+Gsi)^3; +coevec(2) = vj*(1+Gsi)^2*(3*(ndiri-Gsi)-2) - Gsi; +coevec(3) = (ndiri-Gsi-1)*(vj*(1+Gsi)*(3*(ndiri-Gsi)-1)-1); +coevec(4) = vj*(ndiri-Gsi)*(ndiri-Gsi-1)^2; + +Galphaj = max(roots(coevec)); % j: jth element, set to match the variance. Must be greater than 1. +if (Galphaj<=1) + disp(' ') + warning('Error! Make sure std_maxv is small enough to have a large Galphaj > 1') + error(' ') +end + +%*** Solve for the rest of \alpha's. See Note page 27. +A = eye(ndiri) - repmat(Glamda,[1 ndiri]); +C = ones(ndiri,1) + (Galphaj-ndiri)*Glamda; +A1=A; C1=C; +A1(indxlam,:)=[]; A1(:,indxlam)=[]; C1(indxlam)=[]; +indxrest=1:ndiri; indxrest(indxlam)=[]; +Galpha(indxrest) = A1\C1; +Galpha(indxlam) = Galphaj; + +%========= Debugging or checking the properties ========== +%disp(' ') +%disp('2nd-to-first-or-rest ratio: it should not change with the last element of \alpha') +%(Galpha(2)-1)/(Galpha(1)-1) +%(Galpha(2)-1)/(sum(Galpha([1 3]))-2) +%disp(' ') +%disp('Solution for \alpha') +%Galpha + +for k=1:ndiri + tmp=Galpha; + tmp(k)=[]; + stdthe(k)=sqrt( Galpha(k)*sum(tmp)/(sum(Galpha)^2*(sum(Galpha)+1)) ); +end +%disp(' ') +%disp('Standard deviations for each \theta') +%stdthe diff --git a/MatlabFiles/fn_dlrpostr.m b/MatlabFiles/fn_dlrpostr.m new file mode 100755 index 0000000..0334c1a --- /dev/null +++ b/MatlabFiles/fn_dlrpostr.m @@ -0,0 +1,44 @@ +function [P,H0inv,Hpinv] = fn_dlrpostr(xtx,xty,yty,Ui,Vi) +% [P,H0inv,Hpinv] = fn_dlrpostr(xtx,xty,yty,Ui,Vi) +% +% Exporting deterministic (no random prior) Bayesian posterior matrices with linear restrictions +% See Waggoner and Zha's Gibbs sampling paper +% +% xtx: X'X: k-by-k where k=ncoef +% xty: X'Y: k-by-nvar +% yty: Y'Y: nvar-by-nvar +% Ui: nvar-by-1 cell. In each cell, nvar-by-qi orthonormal basis for the null of the ith +% equation contemporaneous restriction matrix where qi is the number of free parameters. +% With this transformation, we have ai = Ui*bi or Ui'*ai = bi where ai is a vector +% of total original parameters and bi is a vector of free parameters. When no +% restrictions are imposed, we have Ui = I. There must be at least one free +% parameter left for the ith equation. Imported from dnrprior.m. +% Vi: nvar-by-1 cell. In each cell, k-by-ri orthonormal basis for the null of the ith +% equation lagged restriction matrix where k (ncoef) is a total number of RHS variables and +% ri is the number of free parameters. With this transformation, we have fi = Vi*gi +% or Vi'*fi = gi where fi is a vector of total original parameters and gi is a +% vector of free parameters. There must be at least one free parameter left for +% the ith equation. Imported from dnrprior.m. +%----------------- +% P: cell(nvar,1). In each cell, the transformation matrix that affects the posterior mean of A+ conditional on A0. +% H0inv: cell(nvar,1). In each cell, posterior inverse of covariance matrix (i.e., the exponential +% term is a_i'*H0*a_i) for the ith equation (not divided by T yet). It resembles +% old SpH in the exponent term in posterior of A0, but not divided by T yet. +% Hpinv: cell(nvar,1). In each cell, posterior inverse of covariance matrix Hp (A+) for the +% ith equation. +% +% Tao Zha, February 2000 + +nvar = size(yty,1); + +P = cell(nvar,1); % tld: tilda +H0inv = cell(nvar,1); % posterior inv(H0), resemble old SpH, but not divided by T yet. +Hpinv = cell(nvar,1); % posterior inv(Hp). + +for n=1:nvar % one for each equation + Hpinv{n} = Vi{n}'*xtx*Vi{n}; + P1 = Vi{n}'*xty*Ui{n}; + P{n} = Hpinv{n}\P1; + H0inv{n} = Ui{n}'*yty*Ui{n} - P1'*(Hpinv{n}\P1); +end + diff --git a/MatlabFiles/fn_empdfsort.m b/MatlabFiles/fn_empdfsort.m new file mode 100755 index 0000000..b4e8746 --- /dev/null +++ b/MatlabFiles/fn_empdfsort.m @@ -0,0 +1,32 @@ +function imfcnt = fn_empdfsort(imfcnt,imf_h,imfloor,hbin,ninv) +% imfcnt = fn_empdfsort(imfcnt,imf_h,imfloor,hbin,ninv) +% Variablewise (but multivariate) empirical probability distribution with counts +% sorted into bins variablewise +% Note that since a particular draw (imf_h) can be below "imfloor" and above "imceiling" +% (=(imceiling-imfloor)*hbin), this function allows ninv+2 bins for each variable +% +% imfcnt: initial ninv+2-by-k matrix that records counts in each bin given a column in imfcnt +% if k==1, then only one variable is considered. +% imf_h: k-element vector of particular draws. Need not be a 1-by-k row vector. +% imfloor: k-element vector of low values of imf but imf_h can be below "imfloor" and above "imceiling" +% hbin: k-element vector of bin lengths = (imceilling-imfloor)/ninv. +% ninv: number of bins between "imfloor" and "imceiling" +%------------------ +% imfcnt: updated ninv+2-by-k matrix of counts (probability) +% +% January 1999 TZ; Revised, August 2000. + +%** find the bin locations and arrange them to the order of 1, 2, ... +imf_h=imf_h(:); imfloor=imfloor(:); hbin=hbin(:); +countInt = floor( (imf_h-imfloor) ./ hbin ); % k-by-1 + % bin locations from <0, 0, 1,..., ninv-1, >=ninv, a total of ninv+2 bins +countInt = 2+countInt'; % 1-by-k row vector, see my shock (1), pp.1 + % move everyting by 2 so as to take account of <0 + +countInt(find(countInt<2)) = 1; % set <0 or -infinity at 1 to start +countInt(find(countInt>=ninv+2)) = ninv+2; % set >=ninv+2 or +infinity at ninv+2 to end +countInt = countInt + (0:length(countInt)-1)*(ninv+2); + % 1-by-k*(ninv+2) index vector to fill the matrix with prob. (counts) + % The term after "+" implies that with every count, we skip ninv+2 to keep + % each column in "imfcnt" with only one element (which is probability) +imfcnt(countInt) = imfcnt(countInt) + 1; diff --git a/MatlabFiles/fn_ergodp.m b/MatlabFiles/fn_ergodp.m new file mode 100755 index 0000000..8c32351 --- /dev/null +++ b/MatlabFiles/fn_ergodp.m @@ -0,0 +1,16 @@ +function gpi = fn_ergodp(P) +% gpi = fn_ergodp(P) +% Compute the ergodic probabilities. See Hamilton p.681. +% +% P: n-by-n matrix of transition matrix where all elements in each column sum up to 1. +%----- +% gpi: n-by-1 vector of ergodic probabilities. +% +% Tao Zha August 2000 + +[gpim,gpid] = eig(P); % m: matrix; d: diagonal +[gpidv,gpidvinx] = sort(diag(gpid)); +gpidv = fliplr(gpidv); +gpidvinx = flipud(gpidvinx); +gpim = gpim(:,gpidvinx); +gpi = gpim(:,1)/sum(gpim(:,1)); diff --git a/MatlabFiles/fn_fcstcnd.m b/MatlabFiles/fn_fcstcnd.m new file mode 100755 index 0000000..389c555 --- /dev/null +++ b/MatlabFiles/fn_fcstcnd.m @@ -0,0 +1,236 @@ +function [yhat,Estr,rcon,Rcon,u,v,d] = fn_fcstcnd(valuecon,stepcon,varcon,nstepsm,... + nconstr,eq_ms,nvar,lags,phil,Sband,yfore_h,imf3s_h,Bh_h,forep) +% ******* There are some BUG problems when calling this fucntion. ******* 3/15/2004. +% [yhat,Estr,rcon,Rcon,u,v,d] = fn_fcstcnd(valuecon,stepcon,varcon,nstepsm,... +% nconstr,eq_ms,nvar,lags,phil,Sband,yfore_h,imf3s_h,Bh_h,forep) +% +% Conditional forecasting in the identified model with or without error bands +% It handles conditions on average values as well, so "valuecon" must be +% expressed at average (NOT sum) levels (i.e., arithmetic averages of log(y) over +% the period of stepcon{i}. 5/22/01. +% Unconditional forecast when imf3s_h, etc is fixed and nconstr=0. +% Note that length(eq_ms)==1 implies one-one mapping between MS shocks and, say, FFR +% if nstepsm==nconstr. If this condition does not hold, this procedure is incorrect. +% I don't have time to fix it now (3/20/99). Meantime, consult or use the old code +% fidencond.m. +% +% valuecon: vector of values conditioned +% stepcon: sequence (cell) of steps conditioned; if length(stepcon{i}) > 1, the condition +% is then an arithmetic average of log(y) over the stepcon{i} period. +% varcon: vector of variables conditioned +% nstepsm: maximum number of steps in all DLS constraints +% nconstr: number of DLS constraints +% eq_ms: Equation location of MS shocks. If [], all shocks. +% nvar: number of variables in the BVAR model +% lags: number of lags in the BVAR model +% phil: the 1-by-(nvar*lags+1) data matrix where k=nvar*lags+1 +% (last period plus lags before the beginning of forecast) +% Sband: 1: draws from random shocks E; 0: no random shocks For now (4/27/01), no option +% for Aband because I don't think it works best to do both Aband and Sband in one function. +% yfore_h: uncondtional forecasts: forep-by-nvar. Never used when nconstr=0. +% In this case, may set it to []; +% imf3s_h: 3-dimensional impulse responses matrix: impsteps-by-nvar shocks-by-nvar responses +% Never used when nconstr=0. In this case, may set it to []; +% Bh_h: reduced-form parameter matrix: k-by-nvar, y(t) = X(t)*Bh+e(t) +% where X(t) is k-by-nvar and y(t) is 1-by-nvar +% forep: # of forecast periods (e.g., monthly for a monthly model) +% eq_Cms: equation location of MS shocks +% ------ +% yhat: conditional forecasts: forep-by-nvar +% Estr: backed-out structural shocks (from constrained Gaussians) +% rcon: vector - the difference between valuecon and log(yfore) (unconditional forecasts) +% Rcon: k-by-q (q constranits and k=nvar*max(nsteps)) so that +% Rcon'*e = rcon where e is k-by-1 +% [u,d,v]: svd(Rcon,0) +% +%% See Zha's note "Forecast (1)" p. 5, RATS manual (some errors in RATS), etc. +%% Some notations: y(t+1) = y(t)B1 + e(t+1)inv(A0). e(t+1) is 1-by-n. +%% Let r(t+1)=e(t+1)inv(A0) + e(t+2)C + .... where inv(A0) is impulse +%% response at t=1, C at t=2, etc. The row of inv(A0) or C is +%% all responses to one shock. +%% Let r be q-by-1 (such as r(1) = r(t+1) +%% = y(t+1) (constrained) - y(t+1) (forecast)). +%% Use impulse responses to find out R (k-by-q) where k=nvar*nsteps +%% where nsteps the largest constrained step. The key of the program +%% is to creat R using impulse responses +%% Optimal solution for shock e where R'*e=r and e is k-by-1 is +%% e = R*inv(R'*R)*r and k>=q +% +% See the old code fidencond.m. I wond't use fn_fcstidcnd?.m, 5/22/01. +% Copyright (c) March 1998 by Tao Zha. Revised November 1998, May 2001 (Delete A0_h as +% input arg so that previous programs may not be compatible). + + +DLSIdShock = ~isempty(eq_ms); % if not empty, the MS shock is identified as in DLS + +impsteps=size(imf3s_h,1); +if (forep<nstepsm) | (impsteps<nstepsm) + disp('Increase # of forecast or impulse steps!!') + disp('Or decrease # of constraints (nconstr) or constrained steps (stepcon(i))!!') + error('Maximum of conditional steps > # of forecast or impulse steps!!') +end +kts = nvar*nstepsm; % k -- ts: total shocks some of which are restricted and others + % are free. +%*** initializing +Rcon = zeros(kts,nconstr); % R: k-by-q +Econ = zeros(kts,1); % E: k-by-1 +rcon = zeros(nconstr,1); % r: q-by-1 +%rcon=valuecon-diag(yfore(stepcon,varcon)); % another way is to use "loop" below. +tcwc = nvar*lags; % total coefficients without constant +phi=phil; + + + +%---------------------------------------------------- +% Form rcon, Rcon, and Econ (the mean of structural shocks) +%---------------------------------------------------- +A0in = reshape(imf3s_h(1,:,:),nvar,nvar); % <<>>1 nvar shocks-by-nvar responses +if nconstr % Conditional forecasts. + for i=1:nconstr + rcon(i)=length(stepcon{i})*valuecon(i) - sum(yfore_h(stepcon{i},varcon(i)),1); + %<<>>2 Automatically taking care of average conditions. + Rmat = zeros(nstepsm,nvar); + r2mat = zeros(nstepsm,1); % simply one identified equation + % Must be here inside the loop because it's matrix of one column of Rcon + for j=1:length(stepcon{i}) + if DLSIdShock % Assuming the Fed can't see all other shocks within a month + Rmat(1:stepcon{i}(j),eq_ms) = Rmat(1:stepcon{i}(j),eq_ms) + ... + imf3s_h(stepcon{i}(j):-1:1,eq_ms,varcon(i)); + % Rmat: row--nstepsm, column--nvar shocks (here all shocks except + % the identified one are set to zero) for a particular + % endogenous variable 'varcon(i)'. See Zha Forcast (1), pp.6-7 + else % Rcon random with (A0,A+) + Rmat(1:stepcon{i}(j),:) = Rmat(1:stepcon{i}(j),:) + ... + imf3s_h(stepcon{i}(j):-1:1,:,varcon(i)); + % Rmat: row--nstepsm, column--nvar shocks (here all shocks are + % *not* set to zero) for a particular endogenous + % variable 'varcon(i)'. See Zha Forcast (1), pp.6-7 + end + end + Rmatt = Rmat'; % Now, nvar-by-nstepsm. I think here is where RATS has an error + % i.e. "OVERR" is not transposed when overlaid to "CAPR" + Rcon(:,i)=Rmatt(:); % Rcon: k-by-q where q=nconstr + end + % + [u d v]=svd(Rcon,0); %trial + vd=v.*(ones(size(v,2),1)*diag(d)'); %trial + dinv = 1./diag(d); % inv(diag(d)) + vdinv=v.*(ones(size(v,2),1)*dinv'); %trial + rtr=vd*vd'; % R'*R + rtrinv = vdinv*vdinv'; % inv(R'*R) + + Econ = Rcon*rtrinv*rcon; % E = R*inv(R'R)*r; the mean of structural shocks +else % Unconditional forecasts. + Econ = zeros(kts,1); % the mean of shocks is zero under no variable condition + Rcon = NaN; + rcon = NaN; + u = NaN; + d = NaN; + v = NaN; +end + + + +%--------------------------------------- +% No uncertainty at all. In other words, no future shocks. +%--------------------------------------- +if (~Sband) %| (nconstr & (length(eq_ms)==1)) + % length(eq_ms)==1 implies one-one mapping between MS shocks and, say, FFR + % if nstepsm==nconstr. If this condition does not hold, this procedure + % is incorrect. I don't have time to fix it now (3/20/99). So I use + % this as a proximation + Estr = reshape(Econ,nvar,nstepsm); + Estr = Estr'; % transpose so that + % Estr: structural shocks. Row--steps, Column--n shocks + Estr = [Estr;zeros(forep-nstepsm,nvar)]; + % Now, forep-by-nvar -- ready for forecasts + Ures = Estr*A0in; % <<>>1 nstepsm-by-nvar + % Ures: reduced-form residuals. Row--steps; Column--n shocks + % Note: We don't use /A0_h so as to eliminate small discrepancies to be + % completely compatible with the computation of Rmat and Estr, which uses A0in. + + % ** reconstruct x(t) for y(t+h) = x(t+h-1)*B + % ** where phi = x(t+h-1) with last column being constant + % + yhat = zeros(forep,nvar); + for k=1:forep + yhat(k,:) = phi*Bh_h + Ures(k,:); + phi(1,nvar+1:tcwc) = phi(1,1:tcwc-nvar); + phi(1,1:nvar) = yhat(k,:); + end +%--------------------------------------- +% With random future shocks. +%--------------------------------------- +else + if nconstr % Conditional forecasts. + %-------------- + % Condition on variables with all shocks backed out. Straight DLS forecasts. No A random but S random. + %-------------- + if ~DLSIdShock + Ome = eye(kts) - u*u'; % note, I-u*u' = I - R*inv(R'*R)*R' + %[u1 d1 v1] = svd(Ome); % too slow + [u1 d1] = eig(Ome); + Stdcon = u1*diag(sqrt(diag(abs(d1)))); % lower triagular chol of conditional variance + % see Zha's forecast (1), p.17 + Estr1 = Econ + Stdcon*randn(kts,1); % Draws of constrained (conditioned) shocks. + Estr2 = reshape(Estr1,nvar,nstepsm); + Estr2 = Estr2'; % transpose so that + % Estr2: structural shocks. Row--nstepsm, Column--n shocks + Estr = [Estr2;randn(forep-nstepsm,nvar)]; % Second concatenated part: draws of free shocks. + % Now, forep-by-nvar -- ready for forecasts + %-------------- + % Condition on variables with identified MS shocks backed out, no A random but S random. + %-------------- + else % other shocks are indepedent of the eq_ms shock + % 3/20/99 The following may be problematic because Osk should depend + % on u (A0_h and Bh_h) in general. I have NOT worked out any good version. + %/* + % Osk = randn(kts,1); % other shocks + % for j=1:nstepsm + % Osk(nvar*(j-1)+eq_ms)=0; % no shock to the MS or identified equation + % end + % Estr = Econ + Osk; % Econ is non zero only at position + % % eq_ms*j where j=1:nstepsm + % Estr = reshape(Estr,nvar,nstepsm); + % Estr = Estr'; % transpose so that + % % Estr: structural shocks. Row--steps, Column--n shocks + % Estr = [Estr;randn(forep-nstepsm,nvar)]; + % % Now, forep-by-nvar -- ready for forecasts + % + disp('DLS') + Ome = eye(kts) - u*u'; % note, I-u*u' = I - R*inv(R'*R)*R' + %[u1 d1 v1] = svd(Ome); % too slow + [u1 d1] = eig(Ome); + Stdcon = u1*diag(sqrt(diag(abs(d1)))); % lower triagular chol of conditional variance + % see Zha's forecast (1), p.17 + tmp1=zeros(nvar,nstepsm); + tmp1(eq_ms,:)=randn(1,nstepsm); + tmp2=tmp1(:); + %Estr1 = Econ + Stdcon*randn(kts,1); + %jnk = reshape(Stdcon*tmp2,nvar,nstepsm) + Estr1 = Econ + Stdcon*tmp2; + Estr2 = reshape(Estr1,nvar,nstepsm); + Estr2 = Estr2'; % transpose so that + % Estr2: structural shocks. Row--nstepsm, Column--n shocks + Estr = [Estr2;randn(forep-nstepsm,nvar)]; + % Now, forep-by-nvar -- ready for forecasts + end + else % Unconditional forecasts. + Estr = randn(forep,nvar); % Unconditional draws. + end + + Ures = Estr*A0in; % <<>>1 nstepsm-by-nvar + % Ures: reduced-form residuals. Row--steps; Column--n shocks + % Note: We don't use /A0_h so as to eliminate small discrepancies to be + % completely compatible with the computation of Rmat and Estr, which uses A0in. + + % ** reconstruct x(t) for y(t+h) = x(t+h-1)*B + % ** where phi = x(t+h-1) with last column being constant + % + yhat = zeros(forep,nvar); + for k=1:forep + yhat(k,:) = phi*Bh_h + Ures(k,:); + phi(1,nvar+1:tcwc) = phi(1,1:tcwc-nvar); + phi(1,1:nvar) = yhat(k,:); + end +end diff --git a/MatlabFiles/fn_fcstidcnd.m b/MatlabFiles/fn_fcstidcnd.m new file mode 100755 index 0000000..9e690b5 --- /dev/null +++ b/MatlabFiles/fn_fcstidcnd.m @@ -0,0 +1,310 @@ +function [yhat,Estr,rcon,Rcon,u,v,d] = fn_fcstidcnd(valuecon,stepcon,varcon,nstepsm,... + nconstr,eq_ms,nvar,lags,phil,Aband,Sband,yfore_h,imf3s_h,A0_h,Bh_h,... + forep,TLindx,TLnumber,nCms,eq_Cms) +% [yhat,Estr,rcon,Rcon,u,v,d] = fn_fcstidcnd(valuecon,stepcon,varcon,nstepsm,... +% nconstr,eq_ms,nvar,lags,phil,Aband,Sband,yfore_h,imf3s_h,A0_h,Bh_h,... +% forep,TLindx,TLnumber,nCms,eq_Cms) +% +% Note that the case Aband=1 is not finished yet. +% +% Conditional forecasting in the identified model with or without error bands +% It handles conditions on average values as well, so "valuecon" must be +% expressed at average (NOT sum) level. +% Aband is used only once when nconstr>0 and Aband=1, where Gibbs sampler may be used. NOT yet finished. +% Unconditional forecast when imf3s_h, etc is fixed and nconstr=0, where yfore_h must set to []. +% +% valuecon: vector of values conditioned +% stepcon: sequence (cell) of steps conditioned; if length(stepcon{i}) > 1, the condition +% is then an arithmetic average of log(y) over the stepcon{i} period. +% varcon: vector of variables conditioned +% nconstr: number of DLS constraints. If zero, it leads to unconditional forecasts. +% nstepsm: maximum number of steps in all DLS constraints +% nvar: number of variables in the BVAR model +% lags: number of lags in the BVAR model +% phil: the 1-by-(nvar*lags+1) data matrix where k=nvar*lags+1 +% (last period plus lags before the beginning of forecast) +% Aband: 1: draws from A0 and Bh; 0: no draws. The case Aband=1 and nconstr>0 has NOT been finished yet. +% Sband: 1: draws from random shocks E; 0: no random shocks +% yfore_h: uncondtional forecasts: forep-by-nvar. Never used when nconstr=0. +% In this case, set it to []; +% imf3s_h: 3-dimensional impulse responses matrix: impsteps-by-nvar shocks-by-nvar responses +% Never used when nconstr=0. In this case, set it to []; +% A0_h: A0 contemporaneous parameter matrix +% Bh_h: reduced-form parameter matrix: k-by-nvar, y(t) = X(t)*Bh+e(t) +% where X(t) is k-by-nvar and y(t) is 1-by-nvar +% forep: # of forecast periods (e.g., monthly for a monthly model) +% TLindx: 1-by-nCms vector of 1's and 0's, indicating tight or loose; 1: tighter, 0: looser +% Used only when /* (MS draws) is activated. Right now, MS shocks are deterministic. +% TLnumber: 1-by-nCms vector, lower bound for tight and upper bound for loose +% nCms: # of LZ conditions +% eq_Cms: equation location of MS shocks +% ------ +% yhat: conditional forecasts: forep-by-nvar +% Estr: backed-out structural shocks (from N(0,1)) +% rcon: vector - the difference between valuecon and log(yfore) (unconditional forecasts) +% Rcon: k-by-q (q constranits and k=nvar*max(nsteps)) so that +% Rcon'*e = rcon where e is k-by-1 +% [u,d,v]: svd(Rcon,0) +% +%% See Zha's note "Forecast (1)" p. 5, RATS manual (some errors in RATS), etc. +% +%% Some notations: y(t+1) = y(t)B1 + e(t+1)inv(A0). e(t+1) is 1-by-n. +%% Let r(t+1)=e(t+1)inv(A0) + e(t+2)C + .... where inv(A0) is impulse +%% response at t=1, C at t=2, etc. The row of inv(A0) or C is +%% all responses to one shock. +%% Let r be q-by-1 (such as r(1) = r(t+1) +%% = y(t+1) (constrained) - y(t+1) (forecast)). +%% Use impulse responses to find out R (k-by-q) where k=nvar*nsteps +%% where nsteps the largest constrained step. The key of the program +%% is to creat R using impulse responses +%% Optimal solution for shock e where R'*e=r and e is k-by-1 is +%% e = R*inv(R'*R)*r and k>=q +% +% Copyright (c) March 1998 by Tao Zha. Revised November 1998; +% 3/20/99 Disenabled draws of MS shcoks. To enable it, activate /* part +% 3/20/99 Added A0_h and forep and deleted Cms as input argument. Previous +% programs may not be compatible. +% 3/15/2004 There are some BUG problems when calling fn_fcstcnd.m(). +% +% Comparing with the version fn_fcstidcnd2.m, this is a better version. +% See the note in fn_fcstidcnd2.m for explanation. April, 2009. TZ. + +DLSIdShock = ~isempty(eq_ms); % if not empty, the MS shock is identified as in DLS + +impsteps=size(imf3s_h,1); +if (forep<nstepsm) | (impsteps<nstepsm) + disp('Increase # of forecast or impulse steps!!') + disp('Or decrease # of constraints (nconstr) or constrained steps (stepcon(i))!!') + error('Maximum of conditional steps > # of forecast or impulse steps!!') +end +kts = nvar*nstepsm; % k -- ts: total shocks some of which are restricted and others + % are free. +%*** initializing +Rcon = zeros(kts,nconstr); % R: k-by-q +Econ = zeros(kts,1); % E: k-by-1 +rcon = zeros(nconstr,1); % r: q-by-1 +%rcon=valuecon-diag(yfore(stepcon,varcon)); % another way is to use "loop" below. +tcwc = nvar*lags; % total coefficients without constant +phi=phil; + + + +%---------------------------------------------------- +% Form rcon, Rcon, and Econ (the mean of structural shocks) +%---------------------------------------------------- +if nconstr + A0in = reshape(imf3s_h(1,:,:),nvar,nvar); % nvar shocks-by-nvar responses + for i=1:nconstr + rcon(i)=length(stepcon{i})*valuecon(i) - ... + sum(yfore_h(stepcon{i},varcon(i)),1); %<<>> + Rmat = zeros(nstepsm,nvar); + r2mat = zeros(nstepsm,1); % simply one identified equation + % Must be here inside the loop because it's matrix of one column of Rcon + for j=1:length(stepcon{i}) + if DLSIdShock % Assuming the Fed can't see all other shocks within a month + Rmat(1:stepcon{i}(j),eq_ms) = Rmat(1:stepcon{i}(j),eq_ms) + ... + imf3s_h(stepcon{i}(j):-1:1,eq_ms,varcon(i)); + % Rmat: row--nstepsm, column--nvar shocks (here all shocks except + % the identified one are set to zero) for a particular + % endogenous variable 'varcon(i)'. See Zha Forcast (1), pp.6-7 + else % Rcon random with (A0,A+) + Rmat(1:stepcon{i}(j),:) = Rmat(1:stepcon{i}(j),:) + ... + imf3s_h(stepcon{i}(j):-1:1,:,varcon(i)); + % Rmat: row--nstepsm, column--nvar shocks (here all shocks are + % *not* set to zero) for a particular endogenous + % variable 'varcon(i)'. See Zha Forcast (1), pp.6-7 + end + end + Rmatt = Rmat'; % Now, nvar-by-nstepsm. I think here is where RATS has an error + % i.e. "OVERR" is not transposed when overlaid to "CAPR" + Rcon(:,i)=Rmatt(:); % Rcon: k-by-q where q=nconstr + end + + [u d v]=svd(Rcon,0); %trial + %???? Can we reduce the time by computing inv(R'*R) directly? + % rtr = Rcon'*Rcon; %trial + % rtrinv = inv(Rcon'*Rcon); %trial + vd=v.*(ones(size(v,2),1)*diag(d)'); %trial + dinv = 1./diag(d); % inv(diag(d)) + vdinv=v.*(ones(size(v,2),1)*dinv'); %trial + rtr=vd*vd'; % R'*R + rtrinv = vdinv*vdinv'; % inv(R'*R) + + Econ = Rcon*rtrinv*rcon; % E = R*inv(R'R)*r; the mean of structural shocks +else + Econ = zeros(kts,1); % the mean of shocks is zero under no variable condition + Rcon = NaN; + rcon = NaN; + u = NaN; + d = NaN; + v = NaN; +end + + + +%--------------------------------------- +% No uncertainty at all or only random (A0,A+) +% In other words, no future shocks +%--------------------------------------- +if (~Sband) %| (nconstr & (length(eq_ms)==1)) + % length(eq_ms)==1 implies one-one mapping between MS shocks and, say, FFR + % if nstepsm==nconstr. If this condition does not hold, this procedure + % is incorrect. I don't have time to fix it now (3/20/99). So I use + % this as a proximation + Estr = reshape(Econ,nvar,nstepsm); + Estr = Estr'; % transpose so that + % Estr: structural shocks. Row--steps, Column--n shocks + Estr = [Estr;zeros(forep-nstepsm,nvar)]; + % Now, forep-by-nvar -- ready for forecasts + Estr(1:nCms,eq_Cms) = TLnumber(:); + Ures = Estr/A0_h; % nstepsm-by-nvar + % Ures: reduced-form residuals. Row--steps; Column--n shocks + + % ** reconstruct x(t) for y(t+h) = x(t+h-1)*B + % ** where phi = x(t+h-1) with last column being constant + % + yhat = zeros(forep,nvar); + for k=1:forep + yhat(k,:) = phi*Bh_h + Ures(k,:); + phi(1,nvar+1:tcwc) = phi(1,1:tcwc-nvar); + phi(1,1:nvar) = yhat(k,:); + % + end + +%--------------------------------------- +% With random future shocks and possibly (A0,A+) depending +% on if imf3s_h is random +%--------------------------------------- +else + %-------------- + % Condition on variables and A random + %-------------- + if nconstr & Aband + warning(' ') + disp('This situation (both E and A random) is still under construction') + disp('It is closely related to Waggoner and Zha ReStat Gibbs sampling method') + disp('Please press ctrl-c to abort') + pause + elseif nconstr + %-------------- + % Condition on variables and DLS MS shock, no A random but S random + %-------------- + if DLSIdShock % other shocks are indepedent of the eq_ms shock + % 3/20/99 The following may be problematic because Osk should depend + % on u (A0_h and Bh_h) in general. I haven't worked out any good version + %/* + % Osk = randn(kts,1); % other shocks + % for j=1:nstepsm + % Osk(nvar*(j-1)+eq_ms)=0; % no shock to the MS or identified equation + % end + % Estr = Econ + Osk; % Econ is non zero only at position + % % eq_ms*j where j=1:nstepsm + % Estr = reshape(Estr,nvar,nstepsm); + % Estr = Estr'; % transpose so that + % % Estr: structural shocks. Row--steps, Column--n shocks + % Estr = [Estr;randn(forep-nstepsm,nvar)]; + % % Now, forep-by-nvar -- ready for forecasts + % + disp('DLS') + Ome = eye(kts) - u*u'; % note, I-u*u' = I - R*inv(R'*R)*R' + %[u1 d1 v1] = svd(Ome); % too slow + [u1 d1] = eig(Ome); + Stdcon = u1*diag(sqrt(diag(abs(d1)))); % lower triagular chol of conditional variance + % see Zha's forecast (1), p.17 + tmp1=zeros(nvar,nstepsm); + tmp1(eq_ms,:)=randn(1,nstepsm); + tmp2=tmp1(:); + %Estr1 = Econ + Stdcon*randn(kts,1); + %jnk = reshape(Stdcon*tmp2,nvar,nstepsm) + Estr1 = Econ + Stdcon*tmp2; + Estr2 = reshape(Estr1,nvar,nstepsm); + Estr2 = Estr2'; % transpose so that + % Estr2: structural shocks. Row--nstepsm, Column--n shocks + Estr = [Estr2;randn(forep-nstepsm,nvar)]; + % Now, forep-by-nvar -- ready for forecasts + else + Ome = eye(kts) - u*u'; % note, I-u*u' = I - R*inv(R'*R)*R' + %[u1 d1 v1] = svd(Ome); % too slow + [u1 d1] = eig(Ome); + Stdcon = u1*diag(sqrt(diag(abs(d1)))); % lower triagular chol of conditional variance + % see Zha's forecast (1), p.17 + %-------------- + % Condition on variables and LZ MS shock, no A random but S random + % This section has not be tested yet, 10/14/98 + %-------------- + if nCms + Estr1 = Econ + Stdcon*randn(kts,1); + Estr2 = reshape(Estr1,nvar,nstepsm); + Estr2 = Estr2'; % transpose so that + % Estr2: structural shocks. Row--nstepsm, Column--n shocks + Estr = [Estr2;randn(forep-nstepsm,nvar)]; + % Now, forep-by-nvar -- ready for forecasts + Estr(1:nCms,eq_Cms) = TLnumber(:); + + %/* draw MS shocks + % for k=1:nCms + % if TLindx(k) % tighter + % while (Estr(k,eq_Cms)<TLnumber(k)) + % Estr(k,eq_Cms) = randn(1,1); + % end + % else % looser + % while (Estr(k,eq_Cms)>TLnumber(k)) + % Estr(k,eq_Cms) = randn(1,1); + % end + % end + % end + %-------------- + % Condition on variables only, no A random but S random + %-------------- + else + Estr1 = Econ + Stdcon*randn(kts,1); + Estr2 = reshape(Estr1,nvar,nstepsm); + Estr2 = Estr2'; % transpose so that + % Estr2: structural shocks. Row--nstepsm, Column--n shocks + Estr = [Estr2;randn(forep-nstepsm,nvar)]; + % Now, forep-by-nvar -- ready for forecasts + end + end + %-------------- + % Condition on LZ MS shocks only, S random and possibly A random depending on + % if A0_h and Bh_h are random + %-------------- + else + if nCms + Estr = randn(forep,nvar); + % Now, forep-by-nvar -- ready for forecasts + Estr(1:nCms,eq_Cms) = TLnumber(:); + + %/* draw MS shocks + % for k=1:nCms + % if TLindx(k) % tighter + % while (Estr(k,eq_Cms)<TLnumber(k)) + % Estr(k,eq_Cms) = randn(1,1); + % end + % else % looser + % while (Estr(k,eq_Cms)>TLnumber(k)) + % Estr(k,eq_Cms) = randn(1,1); + % end + % end + % end + else + Estr = randn(forep,nvar); % Unconditional forecast + % Now, forep-by-nvar -- ready for forecasts + end + end + % + + + Ures = Estr/A0_h; % nstepsm-by-nvar + % Ures: reduced-form residuals. Row--steps; Column--n shocks + + % ** reconstruct x(t) for y(t+h) = x(t+h-1)*B + % ** where phi = x(t+h-1) with last column being constant + % + yhat = zeros(forep,nvar); + for k=1:forep + yhat(k,:) = phi*Bh_h + Ures(k,:); + phi(1,nvar+1:tcwc) = phi(1,1:tcwc-nvar); + phi(1,1:nvar) = yhat(k,:); + end +end diff --git a/MatlabFiles/fn_fcstidcnd2.m b/MatlabFiles/fn_fcstidcnd2.m new file mode 100755 index 0000000..17cb91f --- /dev/null +++ b/MatlabFiles/fn_fcstidcnd2.m @@ -0,0 +1,348 @@ +function [yhat,Estr,rcon,Rcon,u,v,d] = fn_fcstidcnd2(valuecon,stepcon,varcon,nstepsm,... + nconstr,eq_ms,nvar,lags,phil,Aband,Sband,yfore_h,imf3s_h,A0_h,Bh_h,... + forep,TLindx,TLnumber,nCms,eq_Cms,nconadd,eq_oth,radd,Radd) +% [yhat,Estr,rcon,Rcon,u,v,d] = fn_fcstidcnd2(valuecon,stepcon,varcon,nstepsm,... +% nconstr,eq_ms,nvar,lags,phil,Aband,Sband,yfore_h,imf3s_h,A0_h,Bh_h,... +% forep,TLindx,TLnumber,nCms,eq_Cms,nconadd,eq_oth,radd,Radd) +% +% 5/2/99: This one is much, much slower than fidcnderr.m when eq_ms=[] and +% nconstr>0 and length(eq_ms)*nstepsm>nconstr. Seems to me that fcstidcnd2.m +% is designed for the situation which eq_ms=2. The slow speed is due to +% "Radd" added. When I have time, I need to check to see if I can speed up +% this M file. +% +% Note that the case Aband=1 is not finished yet. +% +% Conditional forecasting in the identified model with or without error bands +% It handles conditions on average values as well, so "valuecon" must be +% expressed at average (NOT sum) level. Including unconditional forecasts +% when nconstr=nCms=0. Maybe slower than "fcstidcnd.m" when length(eq_ms)*nstepsm=nconstr +% because of Radd added. But "fsctidcnd.m" is incorrect when length(eq_ms) +% *nstepsm>nconstr (situations like the average annual FFR constraint). 3/22/99 +% Ref.: Zha Forecast (I), pp. 17-17c. +% +% valuecon: vector of values conditioned +% stepcon: sequence (cell) of steps conditioned; if length(stepcon{i}) > 1, the condition +% is then an arithmetic average of log(y) over the stepcon{i} period. +% varcon: vector of variables conditioned +% nconstr: number of DLS constraints +% nstepsm: maximum number of steps in all DLS constraints +% nvar: number of variables in the BVAR model +% lags: number of lags in the BVAR model +% phil: the 1-by-(nvar*lags+1) data matrix where k=nvar*lags+1 +% (last period plus lags before the beginning of forecast) +% eq_ms: identified equation or shock (in terms of number). If equ_ms=[], then "fidencond" or +% 'fcstidcond' is, similar to RATS, to compute forecasts with *all* shocks. +% Aband: 1: draws from A0 and Bh; 0: no draws +% Sband: 1: draws from random shocks E; 0: no random shocks +% yfore_h: uncondtional forecasts: forep-by-nvar. Never used when nconstr=0. +% In this case, set it to []; +% imf3s_h: 3-dimensional impulse responses matrix: impsteps-by-nvar shocks-by-nvar responses +% Never used when nconstr=0. In this case, set it to []; +% A0_h: A0 contemporaneous parameter matrix +% Bh_h: reduced-form parameter matrix: k-by-nvar, y(t) = X(t)*Bh+e(t) +% where X(t) is k-by-nvar and y(t) is 1-by-nvar +% forep: # of forecast periods (e.g., monthly for a monthly model) +% TLindx: 1-by-nCms vector of 1's and 0's, indicating tight or loose; 1: tighter, 0: looser +% Used only when /* (MS draws) is activated. Right now, MS shocks are deterministic. +% TLnumber: 1-by-nCms vector, lower bound for tight and upper bound for loose +% nCms: # of LZ conditions +% eq_Cms: equation location of MS shocks +% nconadd: number of DLS added constraints DIRECTLY on structural shocks +% for identified version where eq_ms is not empty. Note +% nconadd=0 when eq_ms is empty. +% eq_oth: index for other structural shocks than those in eq_ms. +% If eq_ms=[], eq_oth=[]. Note length(eq_oth)+length(eq_ms)=nvar +% radd: sparse nconadd-by-1; nconadd values added to rcon in the text later +% Radd: sparce nvar*nstepsm-by-nconadd; added to Rcon in the text later +% ------ +% yhat: conditional forecasts: forep-by-nvar +% Estr: backed-out structural shocks (from N(0,1)) +% rcon: vector - the difference between valuecon and log(yfore) (unconditional forecasts) +% Rcon: k-by-q (q constranits and k=nvar*max(nsteps)) so that +% Rcon'*e = rcon where e is k-by-1 +% [u,d,v]: svd(Rcon,0) +% +% Copyright (c) March 1998 by Tao Zha. Revised November 1998; +% 3/20/99 Disenabled draws of MS shcoks. To enable it, activate /* part +% 3/20/99 Added A0_h and forep and deleted Cms as input argument. +% 3/21/99 Added nconadd and eq_oth. +% Previous programs may not be compatible. +% +% This version differs from "fn_fcstidcnd.m" because nconadd, radd, and Radd are added to allow for +% both DLS-WZ conditions and structural-shock conditions to exist at the same time. My recognition +% is that it does not work well at all. So one should use the version "fn_fcstidcnd.m."" April, 2009 by TZ. + + + +% +%% See Zha's note "Forecast (1)" p. 5, RATS manual (some errors in RATS), etc. +%% See also Zha Forecast (I), pp. 17-17c. +% +%% Some notations: y(t+1) = y(t)B1 + e(t+1)inv(A0). e(t+1) is 1-by-n. +%% Let r(t+1)=e(t+1)inv(A0) + e(t+2)C + .... where inv(A0) is impulse +%% response at t=1, C at t=2, etc. The row of inv(A0) or C is +%% all responses to one shock. +%% Let r be q-by-1 (such as r(1) = r(t+1) +%% = y(t+1) (constrained) - y(t+1) (forecast)). +%% Use impulse responses to find out R (k-by-q) where k=nvar*nsteps +%% where nsteps the largest constrained step. The key of the program +%% is to creat R using impulse responses +%% Optimal solution for shock e where R'*e=r and e is k-by-1 is +%% e = R*inv(R'*R)*r and k>=q +% + + +DLSIdShock = ~isempty(eq_ms); % if not empty, the MS shock is identified as in DLS + +impsteps=size(imf3s_h,1); +if (forep<nstepsm) | (impsteps<nstepsm) + disp('Increase # of forecast or impulse steps!!') + disp('Or decrease # of constraints (nconstr) or constrained steps (stepcon(i))!!') + error('Maximum of conditional steps > # of forecast or impulse steps!!') +end +kts = nvar*nstepsm; % k -- ts: total shocks some of which are restricted and others + % are free. +%*** initializing +Rcon = zeros(kts,nconstr); % R: k-by-q where q include possible additional + % constraints directly on structural shocks for identified models. + % These addtional constraints will be added later. +Econ = sparse(zeros(kts,1)); % E: k-by-1 +rcon = zeros(nconstr,1); % r: q-by-1 +%rcon=valuecon-diag(yfore(stepcon,varcon)); % another way is to use "loop" below. +tcwc = nvar*lags; % total coefficients without constant +phi=phil; + + + +%---------------------------------------------------- +% Form rcon, Rcon, and Econ (the mean of structural shocks) +%---------------------------------------------------- +if nconstr + A0in = reshape(imf3s_h(1,:,:),nvar,nvar); % nvar shocks-by-nvar responses + for i=1:nconstr + rcon(i)=length(stepcon{i})*valuecon(i) - ... + sum(yfore_h(stepcon{i},varcon(i)),1); %<<>> + Rmat = zeros(nstepsm,nvar); + % Must be here inside the loop because it's matrix of one column of Rcon + for j=1:length(stepcon{i}) + if DLSIdShock % Assuming the Fed can't see all other shocks within a month + Rmat(1:stepcon{i}(j),:) = Rmat(1:stepcon{i}(j),:) + ... + imf3s_h(stepcon{i}(j):-1:1,:,varcon(i)); + % Rmat: row--nstepsm, column--nvar shocks (here all shocks except + % the identified one are set to zero) for a particular + % endogenous variable 'varcon(i)'. See Zha Forcast (1), pp.6-7 + else % Rcon random with (A0,A+) + Rmat(1:stepcon{i}(j),:) = Rmat(1:stepcon{i}(j),:) + ... + imf3s_h(stepcon{i}(j):-1:1,:,varcon(i)); + % Rmat: row--nstepsm, column--nvar shocks (here all shocks are + % *not* set to zero) for a particular endogenous + % variable 'varcon(i)'. See Zha Forcast (1), pp.6-7 + end + end + Rmatt = Rmat'; % Now, nvar-by-nstepsm. I think here is where RATS has an error + % i.e. "OVERR" is not transposed when overlaid to "CAPR" + Rcon(:,i)=Rmatt(:); % Rcon: k-by-q where q=nconstr + end + + rcon = [rcon;radd]; % added nconadd constrained values for identified model + % sparse because radd is sparse + Rcon = [Rcon Radd]; % added constraints on shocks for identified version + % sparse because Radd is sparse + Rcont=Rcon'; + rinvrtr=Rcon/(Rcont*Rcon); + Econ = rinvrtr*rcon; + + + %/* Too slow, I believe, when q is large. 3/21/99 + % [u d v]=svd(Rcon,0); %trial + % %???? Can we reduce the time by computing inv(R'*R) directly? + % % rtr = Rcon'*Rcon; %trial + % % rtrinv = inv(Rcon'*Rcon); %trial + % vd=v.*(ones(size(v,2),1)*diag(d)'); %trial + % dinv = 1./diag(d); % inv(diag(d)) + % vdinv=v.*(ones(size(v,2),1)*dinv'); %trial + % rtr=vd*vd'; % R'*R + % rtrinv = vdinv*vdinv'; % inv(R'*R) + % + % Econ = Rcon*rtrinv*rcon; % E = R*inv(R'R)*r; the mean of structural shocks +else + Econ = sparse(zeros(kts,1)); % the mean of shocks is zero under no variable condition + Rcon = NaN; + rcon = NaN; + u = NaN; + d = NaN; + v = NaN; +end + + + +%--------------------------------------- +% No uncertainty at all or only random (A0,A+) +% In other words, no future shocks +%--------------------------------------- +if (~Sband) | (nconstr & length(eq_ms)*nstepsm==nconstr) + % length(eq_ms)==1 implies one-one mapping between MS shocks and, say, FFR + % if nstepsm==nconstr. If this condition does not hold, this procedure + % is incorrect. I don't have time to fix it now (3/20/99). So I use + % this as a proximation + Estr = reshape(Econ,nvar,nstepsm); + Estr = Estr'; % transpose so that + % Estr: structural shocks. Row--steps, Column--n shocks + Estr = [Estr;zeros(forep-nstepsm,nvar)]; + % Now, forep-by-nvar -- ready for forecasts + Estr(1:nCms,eq_Cms) = TLnumber(:); + Ures = Estr/A0_h; % nstepsm-by-nvar + % Ures: reduced-form residuals. Row--steps; Column--n shocks + + % ** reconstruct x(t) for y(t+h) = x(t+h-1)*B + % ** where phi = x(t+h-1) with last column being constant + % + yhat = zeros(forep,nvar); + for k=1:forep + yhat(k,:) = phi*Bh_h + Ures(k,:); + phi(1,nvar+1:tcwc) = phi(1,1:tcwc-nvar); + phi(1,1:nvar) = yhat(k,:); + % + end + +%--------------------------------------- +% With random future shocks and possibly (A0,A+) depending +% on if imf3s_h is random +%--------------------------------------- +else + %-------------- + % Condition on variables and A random + %-------------- + if nconstr & Aband + warning(' ') + disp('This situation (both E and A random) is still under construction') + disp('It is closely related to Waggoner and Zha ReStat Gibbs sampling method') + disp('and related to "if DLSIdShock" in the following') + disp('Please press ctrl-c to abort') + pause + elseif nconstr + %-------------- + % Condition on variables and DLS MS shock, no A random but S random + %-------------- + if DLSIdShock % other shocks are indepedent of the eq_ms shock + Ome=speye(kts)-rinvrtr*Rcont; + Ome(find(abs(Ome)<1e-10))=0; % tighter the tolerance is, the longer it + % takes for svds to compute. E.g., size(Ome,1)*eps is perhaps very + % tight. After all, when the number in Ome is very small relative to + % 1 (which is the variance of structural shocks Estr), we can treat it + % as zero. + [u1 d1 v1] = svds(Ome,kts-nconstr-nconadd); + % We have exactly nconstr+nconadd zero singular values + Stdcon = u1*diag(sqrt(diag(abs(d1)))); % find a square root of Ome + % see Zha's forecast (1), p.17 + Stdcon = [Stdcon sparse(zeros(kts,kts-size(d1,1)))]; + Estr1 = Econ + Stdcon*randn(kts,1); % We must have rand(kts,1). Assigning + % some of randn(kts,1) to be zero according to Radd is WRONG. + % For this argument, see Zha Forecast (I) p.17a + Estr2 = reshape(Estr1,nvar,nstepsm); + % nvar-by-nstepsm; Needed to be transposed later + Estr = [Estr2';randn(forep-nstepsm,nvar)]; % transpose so that + % Estr2: structural shocks. Row--nstepsm, Column--n shocks + % Now, forep-by-nvar -- ready for forecasts + else + Ome=speye(kts)-rinvrtr*Rcont; + Ome(find(abs(Ome)<1e-10))=0; % tighter the tolerance is, the longer it + % takes for svds to compute. E.g., size(Ome,1)*eps is perhaps very + % tight. After all, when the number in Ome is very small relative to + % 1 (which is the variance of structural shocks Estr), we can treat it + % as zero. + [u1 d1 v1] = svds(Ome,kts-nconstr-nconadd); + % We have exactly nconstr+nconadd zero singular values + Stdcon = u1*diag(sqrt(diag(abs(d1)))); % find a square root of Ome + % see Zha's forecast (1), p.17 + Stdcon = [Stdcon sparse(zeros(kts,nconstr+nconadd))]; + + %*** The following very inefficient + % Ome = eye(kts) - u*u'; % note, I-u*u' = I - R*inv(R'*R)*R' + % %[u1 d1 v1] = svd(Ome); % too slow + % [u1 d1] = eig(Ome); + % Stdcon = u1*diag(sqrt(diag(abs(d1)))); % lower triagular chol of conditional variance + % % see Zha's forecast (1), p.17 + + %-------------- + % Condition on variables and LZ MS shock, no A random but S random + % This section has not be tested yet, 10/14/98 + %-------------- + if nCms + Estr1 = Econ + Stdcon*randn(kts,1); + Estr2 = reshape(Estr1,nvar,nstepsm); + Estr2 = Estr2'; % transpose so that + % Estr2: structural shocks. Row--nstepsm, Column--n shocks + Estr = [Estr2;randn(forep-nstepsm,nvar)]; + % Now, forep-by-nvar -- ready for forecasts + Estr(1:nCms,eq_Cms) = TLnumber(:); + + %/* draw MS shocks + % for k=1:nCms + % if TLindx(k) % tighter + % while (Estr(k,eq_Cms)<TLnumber(k)) + % Estr(k,eq_Cms) = randn(1,1); + % end + % else % looser + % while (Estr(k,eq_Cms)>TLnumber(k)) + % Estr(k,eq_Cms) = randn(1,1); + % end + % end + % end + %-------------- + % Condition on variables only, no A random but S random + %-------------- + else + Estr1 = Econ + Stdcon*randn(kts,1); + Estr2 = reshape(Estr1,nvar,nstepsm); + Estr2 = Estr2'; % transpose so that + % Estr2: structural shocks. Row--nstepsm, Column--n shocks + Estr = [Estr2;randn(forep-nstepsm,nvar)]; + % Now, forep-by-nvar -- ready for forecasts + end + end + %-------------- + % Condition on LZ MS shocks only, S random and possibly A random depending on + % if A0_h and Bh_h are random + %-------------- + else + if nCms + Estr = randn(forep,nvar); + % Now, forep-by-nvar -- ready for forecasts + Estr(:,eq_Cms)=0; + Estr(1:nCms,eq_Cms) = TLnumber(:); + + %/* draw MS shocks + % for k=1:nCms + % if TLindx(k) % tighter + % while (Estr(k,eq_Cms)<TLnumber(k)) + % Estr(k,eq_Cms) = randn(1,1); + % end + % else % looser + % while (Estr(k,eq_Cms)>TLnumber(k)) + % Estr(k,eq_Cms) = randn(1,1); + % end + % end + % end + else + Estr = randn(forep,nvar); % Unconditional forecast + % Now, forep-by-nvar -- ready for forecasts + end + end + % + + + Ures = Estr/A0_h; % nstepsm-by-nvar + % Ures: reduced-form residuals. Row--steps; Column--n shocks + + % ** reconstruct x(t) for y(t+h) = x(t+h-1)*B + % ** where phi = x(t+h-1) with last column being constant + % + yhat = zeros(forep,nvar); + for k=1:forep + yhat(k,:) = phi*Bh_h + Ures(k,:); + phi(1,nvar+1:tcwc) = phi(1,1:tcwc-nvar); + phi(1,1:nvar) = yhat(k,:); + end +end \ No newline at end of file diff --git a/MatlabFiles/fn_forecast.m b/MatlabFiles/fn_forecast.m new file mode 100755 index 0000000..a7e528f --- /dev/null +++ b/MatlabFiles/fn_forecast.m @@ -0,0 +1,57 @@ +function yhat = fn_forecast(Bh,phi,nn,nexo,Xfexo) +% yhat = fn_forecast(Bh,phi,nn,nexo,Xfexo) +% Unconditional forecating without shocks. +% y_hat(t+h) = c + x_hat(t+h-1)*Bh, X: 1*k; Bh: k*nvar; y_hat: 1*nvar +% +% Bh: k-by-nvar, the (posterior) estimate of B. +% phi: the 1-by-(nvar*lags+nexo) data matrix X where k=nvar*lags+1 +% (last period plus lags before the beginning of forecast). +% nn: [nvar,lags,nfqm], nfqm: forecast periods (months or quarters). +% nexo: number of exogenous variables. The constant term is the default setting. +% Besides this term, we have nexo-1 exogenous variables. +% Xfexo: nfqm-by-nexo-1 vector of exoenous variables in the forecast horizon where +% nfqm: number of forecast periods. +%----------- +% yhat: nfqm-by-nvar forecast. +% +% See fn_forecastsim.m with shocks; fn_forecaststre.m. + +if nargin == 3 + nexo=1; % default for constant term +elseif nexo<1 + error('We need at least one exogenous term so nexo must >= 1') +end + +% ** setup +nvar = nn(1); +lags = nn(2); +nfqm = nn(3); +tcwx = nvar*lags; % total coefficeint without exogenous variables + +if nexo>1 + if (nfqm > size(Xfexo,1)) + disp(' ') + warning('Make sure the forecast horizon in the exogenous variable matrix Xfexo > forecast periods') + disp('Press ctrl-c to abort') + pause + elseif ((nexo-1) ~= size(Xfexo,2)) + disp(' ') + warning('Make sure that nexo matchs the exogenous variable matrix Xfexo') + disp('Press ctrl-c to abort') + pause + end +end + +% ** reconstruct x(t) for y(t+h) = x(t+h-1)*B +% ** where phi = x(t+h-1) with last column being constant +yhat = zeros(nfqm,nvar); +for k=1:nfqm + yhat(k,:) = phi*Bh; + %*** lagged endogenous variables + phi(1,nvar+1:tcwx) = phi(1,1:tcwx-nvar); + phi(1,1:nvar) = yhat(k,:); + %*** exogenous variables excluding constant terms + if (nexo>1) + phi(1,tcwx+1:tcwx+nexo-1) = Xfexo(k,:); + end +end diff --git a/MatlabFiles/fn_forecastfixe.m b/MatlabFiles/fn_forecastfixe.m new file mode 100755 index 0000000..a07340d --- /dev/null +++ b/MatlabFiles/fn_forecastfixe.m @@ -0,0 +1,61 @@ +function yhat = fn_forecastfixe(Bh,A0h,phi,nn,Estr,nexo,Xfexo) +% yhat = fn_forecastfixe(Bh,A0h,phi,nn,Estr,nexo,Xfexo) +% Forecasts conditional on fixed structural shocks +% y_hat(t+h) = c + x_hat(t+h-1)*Bh + Estr(t+h,:), X: 1*k; Bh: k*nvar; y_hat: 1*nvar +% +% Bh: k-by-nvar, the (posterior) estimate of B; +% A0h: nvar-by-nvar, columns correponding to equations +% phi: the 1-by-(nvar*lags+1) data matrix where k=nvar*lags+1 +% (last period plus lags before the beginning of forecast). +% nn: [nvar,lags,nfqm], nfqm: forecast periods (months or quarters). +% Estr: nfqm-by-nvar, each column corresponds to strcutural shocks from a particular +% source such as MS; +% nexo: number of exogenous variables. The constant term is the default setting. +% Besides this term, we have nexo-1 exogenous variables. +% Xfexo: nfqm-by-nexo-1 vector of exoenous variables in the forecast horizon where +% nfqm: number of forecast periods. +%----------------- +% yhat: nfqm*nvar matrix of forecasts. +% +% See also fn_forecast.m and fn_forecastsim.m. + +if nargin == 5 + nexo=1; % default for constant term +elseif nexo<1 + error('We need at least one exogenous term so nexo must >= 1') +end + +% ** setup +nvar = nn(1); +lags = nn(2); +nfqm = nn(3); +tcwx = nvar*lags; % total coefficeint without exogenous variables + +if nexo>1 + if (nfqm > size(Xfexo,1)) + disp(' ') + warning('Make sure the forecast horizon in the exogenous variable matrix Xfexo > forecast periods') + disp('Press ctrl-c to abort') + pause + elseif ((nexo-1) ~= size(Xfexo,2)) + disp(' ') + warning('Make sure that nexo matchs the exogenous variable matrix Xfexo') + disp('Press ctrl-c to abort') + pause + end +end + +% ** reconstruct x(t) for y(t+h) = x(t+h-1)*B +% ** where phi = x(t+h-1) with last column being constant +Ures = Estr/A0h; +yhat = zeros(nfqm,nvar); +for k=1:nfqm + yhat(k,:) = phi*Bh + Ures(k,:); + %*** lagged endogenous variables + phi(1,nvar+1:tcwx) = phi(1,1:tcwx-nvar); + phi(1,1:nvar) = yhat(k,:); + %*** exogenous variables excluding constant terms + if (nexo>1) + phi(1,tcwx+1:tcwx+nexo-1) = Xfexo(k,:); + end +end diff --git a/MatlabFiles/fn_forecastsim.m b/MatlabFiles/fn_forecastsim.m new file mode 100755 index 0000000..b6d7931 --- /dev/null +++ b/MatlabFiles/fn_forecastsim.m @@ -0,0 +1,62 @@ +function yhat = fn_forecastsim(Bh,A0h,phi,nn,nexo,Xfexo) +% yhat = fn_forecastsim(Bh,A0h,phi,nn,nexo,Xfexo) +% Unconditional forecasts with simulated shocks, not depending on reduced-form or structural shocks. +% y_hat(t+h) = c + x_hat(t+h-1)*Bh + u, X: 1*k; Bh: k*nvar; y_hat: 1*nvar; u: simulated shocks. +% +% Bh: k-by-nvar, the (posterior) estimate of B; +% A0h: nvar-by-nvar, columns correponding to equations +% phi: the 1-by-(nvar*lags+1) data matrix where k=nvar*lags+1 +% (last period plus lags before the beginning of forecast). +% nn: [nvar,lags,nfqm], nfqm: forecast periods (months or quarters). +% nexo: number of exogenous variables. The constant term is the default setting. +% Besides this term, we have nexo-1 exogenous variables. +% Xfexo: nfqm-by-nexo-1 vector of exoenous variables in the forecast horizon where +% nfqm: number of forecast periods. +%----------------- +% yhat: nfqm*nvar matrix of forecasts. +% +% See fn_forecast.m without shocks and forecasterr.m when A0h_in (instead of A0h) is used; +% fn_forecaststre.m. + +if nargin == 4 + nexo=1; % default for constant term +elseif nexo<1 + error('We need at least one exogenous term so nexo must >= 1') +end + +% ** setup +nvar = nn(1); +lags = nn(2); +nfqm = nn(3); +tcwx = nvar*lags; % total coefficeint without exogenous variables + +if nexo>1 + if (nfqm > size(Xfexo,1)) + disp(' ') + warning('Make sure the forecast horizon in the exogenous variable matrix Xfexo > forecast periods') + disp('Press ctrl-c to abort') + pause + elseif ((nexo-1) ~= size(Xfexo,2)) + disp(' ') + warning('Make sure that nexo matchs the exogenous variable matrix Xfexo') + disp('Press ctrl-c to abort') + pause + end +end + +% ** reconstruct x(t) for y(t+h) = x(t+h-1)*B +% ** where phi = x(t+h-1) with last column being constant +Ures = randn(nfqm,nvar)/A0h; % Unconditional forecast + % Now, nfqm-by-nvar -- ready for forecasts + % Ures: reduced-form residuals. Row--steps; Column--n shocks +yhat = zeros(nfqm,nvar); +for k=1:nfqm + yhat(k,:) = phi*Bh + Ures(k,:);; + %*** lagged endogenous variables + phi(1,nvar+1:tcwx) = phi(1,1:tcwx-nvar); + phi(1,1:nvar) = yhat(k,:); + %*** exogenous variables excluding constant terms + if (nexo>1) + phi(1,tcwx+1:tcwx+nexo-1) = Xfexo(k,:); + end +end diff --git a/MatlabFiles/fn_foregraph.m b/MatlabFiles/fn_foregraph.m new file mode 100755 index 0000000..f786837 --- /dev/null +++ b/MatlabFiles/fn_foregraph.m @@ -0,0 +1,50 @@ +function fn_foregraph(yfore,yacte,keyindx,rnum,cnum,q_m,ylab,forelabel,conlab) +% +% Graph annual (or calendar year) forecasts vs actual (all data from "msstart.m") +% +% yfore: actual and forecast annual growth data with dates. +% yacte: actual annual growth data with dates. +% keyindx: index for the variables to be graphed +% rnum: number of rows in subplot +% cnum: number of columns in subplot +% q_m: if 4 or 12, quarterly or monthly data +% ylab: string array for the length(keyindx)-by-1 variables +% forelabel: title label for as of time of forecast +% conlab: label for what conditions imposed; e.g., conlab = 'All bar MS shocks inspl' +%------------- +% No output argument for this graph file +% See fn_seriesgraph.m, fn_forerrgraph.m. +% +% Tao Zha, March 2000 + + +vyrs = yfore(:,1); +hornum = cell(length(vyrs),1); % horizontal year (number) +count=0; +for k=vyrs' + count=count+1; + jnk=num2str(k); + hornum{count}=jnk(3:4); % e.g., with '1990', we have '90' +end + +count=0; +for i = keyindx + count = count+1; + subplot(rnum,cnum,count) + plot(yacte(:,1)+yacte(:,2)/q_m,yacte(:,2+i),yfore(:,1)+yfore(:,2)/q_m,yfore(:,2+i),'--') + + if (yfore(1,2)==0) % only for annual growth rates (not for, say, monthly annualized rates) + set(gca,'XLim',[vyrs(1) vyrs(end)]) + set(gca,'XTick',vyrs) + set(gca,'XTickLabel',char(hornum)) + end + + if i==keyindx(1) + title(forelabel) + elseif i>=length(keyindx) %i>=length(keyindx)-1 + xlabel(conlab) + end + % + grid + ylabel(char(ylab(i))) +end diff --git a/MatlabFiles/fn_forerrgraph.m b/MatlabFiles/fn_forerrgraph.m new file mode 100755 index 0000000..654a7a4 --- /dev/null +++ b/MatlabFiles/fn_forerrgraph.m @@ -0,0 +1,55 @@ +function fn_forerrgraph(yfore,yforel,yforeh,yacte,keyindx,rnum,cnum,q_m,ylab,forelabel,conlab) +% +% Graph annual (or calendar year) forecasts with one error band vs actual +% Import some data from "msstart.m" +% +% yfore: both actual and forecast annual growth data with dates in the first 2 columns +% in the order of year and month (or quarter). +% yforel: lower bound of the forecast. +% yforeh: high bound of the forecast. +% yacte: actual annual growth data with dates. +% keyindx: index for the variables to be graphed +% rnum: number of rows in subplot +% cnum: number of columns in subplot +% q_m: if 4 or 12, quarterly or monthly data. +% ylab: string array for the length(keyindx)-by-1 variables +% forelabel: title label for as of time of forecast +% conlab: x-axis label for what conditions imposed; e.g., conlab = 'All bar MS shocks inspl' +%------------- +% No output argument for this graph file. +% See fn_seriesgraph.m, fn_foregraph.m. +% +% Tao Zha, August 2000 + + +vyrs = yfore(:,1); % vectorized +hornum = cell(length(vyrs),1); % horizontal year (number) +count=0; +for k=vyrs' + count=count+1; + jnk=num2str(k); + hornum{count}=jnk(3:4); % e.g., with '1990', we have '90' +end + +count=0; +for i = keyindx + count = count+1; + subplot(rnum,cnum,count) + plot(yacte(:,1)+yacte(:,2)/q_m,yacte(:,2+i),yfore(:,1)+yfore(:,2)/q_m,yfore(:,2+i),'--',... + yforel(:,1)+yforel(:,2)/q_m,yforel(:,2+i),'-.',yforeh(:,1)+yforeh(:,2)/q_m,yforeh(:,2+i),'-.') + + if (yfore(1,2)==0) % only for annual growth rates (not for, say, monthly annualized rates) + set(gca,'XLim',[vyrs(1) vyrs(end)]) + set(gca,'XTick',vyrs) + set(gca,'XTickLabel',char(hornum)) + end + + if i==keyindx(1) + title(forelabel) + elseif i>=length(keyindx) %i>=length(keyindx)-1 + xlabel(conlab) + end + % + grid + ylabel(char(ylab(i))) +end diff --git a/MatlabFiles/fn_fprintmatrix.m b/MatlabFiles/fn_fprintmatrix.m new file mode 100755 index 0000000..c7e34f9 --- /dev/null +++ b/MatlabFiles/fn_fprintmatrix.m @@ -0,0 +1,38 @@ +function fn_fprintmatrix(fid, M, nrows, ncols, indxFloat) +% Prints the matrix to an ascii file indexed by fid. +% +% Inputs: +% fid: Ascii file id. Example: fid = fopen('outdatainp_3s_stv_tvms6lags.prn','a'); +% M: The matrix to be written to the file. +% nrows: Number of rows of M. +% ncols: Number of columns of M. +% indxFloat: 1 if double; +% 2 if single; +% 3 if only 3 significant digits +% 0 if integer. +% +if nrows~=size(M,1) + error('fn_fprintmatrix(): Make sure the row number supplied match that of the matrix'); +end +if ncols~=size(M,2) + error('fn_fprintmatrix(): Make sure the column number supplied match that of the matrix'); +end +for ki=1:nrows + for kj=1:ncols + if (indxFloat == 1) + fprintf(fid,' %.16e ',M((kj-1)*nrows+ki)); + elseif (indxFloat == 2) + fprintf(fid,' %.8e ',M((kj-1)*nrows+ki)); + elseif (indxFloat == 3) + fprintf(fid,' %.3e ',M((kj-1)*nrows+ki)); + else + fprintf(fid,' %d ',M((kj-1)*nrows+ki)); + end + if (kj==ncols) + fprintf(fid,'\n'); + end + end + if (ki==nrows) + fprintf(fid,'\n\n'); + end +end diff --git a/MatlabFiles/fn_fprintvector.m b/MatlabFiles/fn_fprintvector.m new file mode 100755 index 0000000..c82d98b --- /dev/null +++ b/MatlabFiles/fn_fprintvector.m @@ -0,0 +1,29 @@ +function fn_fprintvector(fid, vec, ncols, indxFloat) +% Prints a row vector to an ascii file indexed by fid without any spacing. +% +% Inputs: +% fid: Ascii file id. Example: fid = fopen('outdatainp_3s_stv_tvms6lags.prn','a'); +% vec: A row vector to be written to the file. +% ncols: Number of columns of vec. +% indxFloat: 1 if double; +% 2 if single; +% 0 if integer. +% +if size(vec,1)~=1 + error('fn_fprintvector(): The vector must be a row vector'); +end +if ncols~=size(vec,2) + error('fn_fprintvector(): The column number supplied match that of the vector'); +end +for kj=1:ncols + if (indxFloat == 1) + fprintf(fid,' %.16e ',vec(kj)); + elseif (indxFloat == 2) + fprintf(fid,' %.8e ',vec(kj)); + else + fprintf(fid,' %d ',vec(kj)); + end + if (kj==ncols) + fprintf(fid,'\n'); + end +end diff --git a/MatlabFiles/fn_gfmean.m b/MatlabFiles/fn_gfmean.m new file mode 100755 index 0000000..9991762 --- /dev/null +++ b/MatlabFiles/fn_gfmean.m @@ -0,0 +1,41 @@ +function [Fmat,gvec] = fn_gfmean(b,P,Vi,nvar,ncoef,n0,np) +% [Fmat,gvec] = fn_gfmean(b,P,Vi,nvar,ncoef,n0,np) +% +% Mean of free lagged parameters g and original lagged parameters F, conditional on comtemporaneous b's +% See Waggoner and Zha's Gibbs sampling +% +% b: sum(n0)-element vector of mean estimate of A0 free parameters +% P: cell(nvar,1). In each cell, the transformation matrix that affects the posterior mean of A+ conditional on A0. +% Vi: nvar-by-1 cell. In each cell, k-by-ri orthonormal basis for the null of the ith +% equation lagged restriction matrix where k is a total of exogenous variables and +% ri is the number of free parameters. With this transformation, we have fi = Vi*gi +% or Vi'*fi = gi where fi is a vector of total original parameters and gi is a +% vector of free parameters. There must be at least one free parameter left for +% the ith equation. +% nvar: number of endogeous variables +% ncoef: number of original lagged variables per equation +% n0: nvar-element vector, ith element represents the number of free A0 parameters in ith equation +% np: nvar-element vector, ith element represents the number of free A+ parameters in ith equation +%--------------- +% Fmat: ncoef-by-nvar matrix of original lagged parameters A+. Column corresponding to equation. +% gvec: sum(np)-by-1 stacked vector of all free lagged parameters A+. +% +% Tao Zha, February 2000. Revised, August 2000. + +b=b(:); n0=n0(:); np=np(:); + +n0cum = [0;cumsum(n0)]; +npcum = [0;cumsum(np)]; +gvec = zeros(npcum(end),1); +Fmat = zeros(ncoef,nvar); % ncoef: maximum original lagged parameters per equation + +if ~(length(b)==n0cum(end)) + error('Make inputs n0 and length(b) match exactly') +end + +for kj=1:nvar + bj = b(n0cum(kj)+1:n0cum(kj+1)); + gj = P{kj}*bj; + gvec(npcum(kj)+1:npcum(kj+1)) = gj; + Fmat(:,kj) = Vi{kj}*gj; +end diff --git a/MatlabFiles/fn_gibbsglb.m b/MatlabFiles/fn_gibbsglb.m new file mode 100755 index 0000000..d177127 --- /dev/null +++ b/MatlabFiles/fn_gibbsglb.m @@ -0,0 +1,57 @@ +function [cT,vR,kdf] = fn_gibbsglb(Sbd,idmat0,nvar,fss) +% [cT,vR,kdf] = gibbsglb(Sbd,idmat0,nvar,fss) +% Global setup outside the Gibbs loop -- c.f. gibbsvar +% Ref.: D.F. Waggoner and T.A. Zha: "Does Normalization Matter for Inference?" +% See Note Forecast (2) pp. 44-51 +% +% Sbd: cell(nvar,1). Sbd=diag(S(1), ..., S(m)). Already divided by 'fss' for the +% posterior of a0 or A0(:) in Waggoner and Zha when one has asymmetric prior. +% Note,"bd" stands for block diagonal. +% idmat0: identification matrix for A0 with asymmetric prior; column -- equation. +% nvar: rank of A0 or # of variables +% fss: effective sample size (in the exponential term) -- +% # of observations + # of dummy observations +% (or nSample - lags + # of dummy observations) +%------------- +% cT{i}: nvar-by-nvar where T'*T=Sbd{i} which is kind of covariance martrix +% divided by fss already +% vR{i}: nvar-by-q{i} -- orthonormral basis for T*R, which is obtained through +% single value decomposition of Q*inv(T) +% kdf: the polynomial power in the Gamma or 1d Wishart distribution, used in +% "gibbsvar.m" +% +% Written by Tao Zha; Copyright (c) 1999 by Waggoner and Zha + + +kdf = fss; %2; %fss; + +cT = cell(nvar,1); +for k=1:nvar + cT{k} = chol(Sbd{k}); % upper triangular but lower triangular Choleski +end + +Q = cell(nvar,1); + % Q{i}: nvar-by-nvar with rank nvar-q(i) with ith equation a and + % q(i) which is # of non-zero elements in a. Note: Q*a=0. + +vR = cell(nvar,1); +for k=1:nvar + Q{k} = diag(idmat0(:,k)==0); % constructing Q{k} + % + [jnk1,d1,v1] = svd(Q{k}/cT{k}); + d1max=max(diag(d1)); + if d1max==0 + Idxk=1:nvar; + else + Idxk = find(diag(d1)<eps*d1max); + end + lenk = length(find(idmat0(:,k))); + if ( length(Idxk)<lenk ) + warning('Dimension of non-zero A0(:,k) is different from svd(Q*inv(T))') + disp('Press ctrl-c to abort') + pause + else + jnk1 = v1(:,Idxk); + vR{k} = jnk1(:,1:lenk); % orthonormal basis for T*R + end +end diff --git a/MatlabFiles/fn_gibbsrvar.m b/MatlabFiles/fn_gibbsrvar.m new file mode 100755 index 0000000..1e3e865 --- /dev/null +++ b/MatlabFiles/fn_gibbsrvar.m @@ -0,0 +1,66 @@ +function [A0gbs, Wcell] = fn_gibbsrvar(A0gbs,UT,nvar,fss,n0,Indxcol) +% [A0gbs, Wcell] = fn_gibbsrvar(A0gbs,UT,nvar,fss,n0,Indxcol) +% One-step Gibbs sampler for restricted VARs in the structural form (including over-identified cases). +% Reference: "A Gibbs sampler for structural VARs" by D.F. Waggoner and T. Zha, `` +% Journal of Economic Dynamics & Control (JEDC) 28 (2003) 349-366. +% See Note Forecast (2) pp. 44-51, 70-71, and Theorem 1 and Section 3.1 in the WZ JEDC paper. +% +% A0gbs: the last draw of A0 matrix +% UT: cell(nvar,1) -- U_i*T_i in the proof of Theorem 1 where +% (1) a_i = U_i*b_i with b_i being a vector of free parameters +% (2) T_i (q_i-by-q_i) is from T_i*T_i'= S_i = inv(H0inv{i}/T) where H0inv is the inverse of +% the covariance martrix NOT divided by fss and S_i is defined in (14) on p.355 of the WZ JEDC paper. +% nvar: rank of A0 or # of variables +% fss: effective sample size == nSample (T)-lags+# of dummy observations +% n0: nvar-by-1, ith element represents the number of free A0 parameters in ith equation +% Indxcol: a row vector indicating random columns this Gibbs draws. +% When this input is not supplied, the Gibbs draws all columns +%------------------ +% A0bgs: nvar-by-nvar. New draw of A0 matrix in this Gibbs step +% Wcell: cell(nvar,1). In each cell, columns of Wcell{i} form an orthonormal basis w_1,...,w_qi in Section 3.1 in the WZ paper. Added 9/04. +% +% Written by Tao Zha, August 2000. Revised, September 2004. +% Copyright (c) by Waggoner and Zha + +if (nargin==5), Indxcol=[1:nvar]; end + +%---------------- Local loop for Gibbs given last A0gbs ---------- +Wcell = cell(length(Indxcol),1); +w = zeros(nvar,1); +for ki=Indxcol % given last A0gbs and generate new A0bgs + X = A0gbs; % WZ's Section 4.3 + X(:,ki) = 0; % want to find non-zero sw s.t., X'*w=0 + + + %*** Solving for w and getting an orthonormal basis. See Theorem 1 and also p.48 in Forecast II + [jL,Ux] = lu(X'); + jIx0 = min(find(abs(diag(Ux))<eps)); % if isempty(jIx0), then something is wrong here + w(jIx0+1:end) = 0; % if jIx0+1>end, no effect on w0 + w(jIx0) = 1; + jA = Ux(1:jIx0-1,1:jIx0-1); + jb = Ux(1:jIx0-1,jIx0); + jy = -jA\jb; + w(1:jIx0-1) = jy; + % Note: if jIx0=1 (which almost never happens for numerical stability reasons), no effect on w. + + %*** Constructing orthonormal basis w_1, ..., w_qi at each Gibbs step + w0 = UT{ki}'*w; + w1 = w0/sqrt(sum(w0.^2)); + [W,jnk] = qr(w1); % Columns of W form an orthonormal basis w_1,...,w_qi in Section 3.1 in the WZ paper + + %*** Draw beta's according to Theorem 1 in the WZ JEDC paper. + gkbeta = zeros(n0(ki),1); % qi-by-1: greak beta's + jstd = sqrt(1/fss); + gkbeta(2:end) = jstd*randn(n0(ki)-1,1); % for beta_2, ..., beta_qi + %--- Unnormalized (i.e., not normalized) gamma or 1-d Wishart draw of beta_1 in Theorem 1 of the WZ JEDC paper. + jr = jstd*randn(fss+1,1); + if rand(1)<0.5 + gkbeta(1) = sqrt(jr'*jr); + else + gkbeta(1) = -sqrt(jr'*jr); + end + + %*** Getting a new ki_th column in A0 + A0gbs(:,ki) = UT{ki}*(W*gkbeta); % n-by-1: U_i*T_i*W*beta; + Wcell{ki} = W; %q_i-by-1. +end diff --git a/MatlabFiles/fn_gibbsrvarOldWorks.m b/MatlabFiles/fn_gibbsrvarOldWorks.m new file mode 100755 index 0000000..35a2624 --- /dev/null +++ b/MatlabFiles/fn_gibbsrvarOldWorks.m @@ -0,0 +1,63 @@ +function A0gbs = fn_gibbsrvar(A0gbs,UT,nvar,fss,n0,Indxcol) +% A0gbs = fn_gibbsrvar(A0gbs,UT,nvar,fss,n0,Indxcol) +% One-step Gibbs sampler for restricted VARs in the structural form +% Ref.: D.F. Waggoner and T. Zha: ``A Gibbs sampler for structural VARs'' +% See Note Forecast (2) pp. 44-51 and Theorem 1 and Section 3 in the WZ paper. +% +% A0gbs: the last draw of A0 matrix +% UT: cell(nvar,1) -- U_i*T_i in the proof of Theorem 1 where +% (1) a_i = U_i*b_i with b_i being a vector of free parameters +% (2) T_i (q_i-by-q_i) is from T_i*T_i'=H0inv{i}/T. Note that H0inv is the inverse of +% the covariance martrix NOT divided by fss. See Theorem 1. +% nvar: rank of A0 or # of variables +% fss: effective sample size == nSample (T)-lags+# of dummy observations +% n0: nvar-by-1, ith element represents the number of free A0 parameters in ith equation +% Indxcol: a row vector indicating random columns this Gibbs draws. +% When this input is not supplied, the Gibbs draws all columns +%------------------ +% A0bgs: new draw of A0 matrix in this Gibbs step +% +% Written by Tao Zha, August 2000; Copyright (c) by Waggoner and Zha + +if (nargin==5), Indxcol=[1:nvar]; end + +%---------------- Local loop for Gibbs given last A0gbs ---------- +% +w = zeros(nvar,1); +for ki=Indxcol % given last A0gbs and generate new A0bgs + X = A0gbs; % WZ's Section 4.3 + X(:,ki) = 0; % want to find non-zero sw s.t., X'*w=0 + + + %*** Solving for w and getting an orthonormal basis. See Theorem 1 and also p.48 in Forecast II + [jL,Ux] = lu(X'); + jIx0 = min(find(abs(diag(Ux))<eps)); % if isempty(jIx0), then something is wrong here + w(jIx0+1:end) = 0; % if jIx0+1>end, no effect on w0 + w(jIx0) = 1; + jA = Ux(1:jIx0-1,1:jIx0-1); + jb = Ux(1:jIx0-1,jIx0); + jy = -jA\jb; + w(1:jIx0-1) = jy; + % Note: if jIx0=1 (which almost never happens for numerical stability reasons), no effect on w. + + %*** Constructing orthonormal basis w_1, ..., w_qi at each Gibbs step + w0 = UT{ki}'*w; + w1 = w0/sqrt(sum(w0.^2)); + [W,jnk] = qr(w1); % columns of W form an orthonormal basis w_1,...,w_qi in Section 4.2 in the WZ paper + + %*** Draw beta's in Theorem 1 + gkbeta = zeros(n0(ki),1); % qi-by-1: greak beta's + jstd = sqrt(1/fss); + gkbeta(2:end) = jstd*randn(n0(ki)-1,1); % for beta_2, ..., beta_qi + %--- Unnormalized (i.e., not normalized) gamma or 1-d Wishart draw of beta_1 in Theorem 1. + %* gamma or 1-d Wishart draw of beta_1 + jr = jstd*randn(fss+1,1); + if rand(1)<0.5 + gkbeta(1) = sqrt(jr'*jr); + else + gkbeta(1) = -sqrt(jr'*jr); + end + + %*** Getting a new ki_th column in A0 + A0gbs(:,ki) = UT{ki}*(W*gkbeta); % n-by-1 +end diff --git a/MatlabFiles/fn_gibbsrvar_setup.m b/MatlabFiles/fn_gibbsrvar_setup.m new file mode 100755 index 0000000..972f55e --- /dev/null +++ b/MatlabFiles/fn_gibbsrvar_setup.m @@ -0,0 +1,58 @@ +function [Tinv,UT,VHphalf,PU,VPU] = fn_gibbsrvar_setup(H0inv, Ui, Hpinv, Pmat, Vi, nvar, fss) +% [Tinv,UT,VHphalf,PU,VPU] = fn_gibbsrvar_setup.m(H0inv, Ui, Hpinv, Pmat, Vi, fss, nvar) +% Global setup outside the Gibbs loop to be used by fn_gibbsvar(). +% Reference: "A Gibbs sampler for structural VARs" by D.F. Waggoner and T. Zha, `` +% Journal of Economic Dynamics & Control (JEDC) 28 (2003) 349-366. +% See Note Forecast (2) pp. 44-51, 70-71, and Theorem 1 and Section 3.1 in the WZ JEDC paper. +% +% H0inv: cell(nvar,1). Not divided by T yet. In each cell, inverse of posterior covariance matrix H0. +% The exponential term is b_i'*inv(H0)*b_i for the ith equation where b_i = U_i*a0_i. +% It resembles old SpH or Sbd in the exponent term in posterior of A0, but not divided by T yet. +% Ui: nvar-by-1 cell. In each cell, nvar-by-qi orthonormal basis for the null of the ith +% equation contemporaneous restriction matrix where qi is the number of free parameters. +% With this transformation, we have ai = Ui*bi or Ui'*ai = bi where ai is a vector +% of total original parameters and bi is a vector of free parameters. When no +% restrictions are imposed, we have Ui = I. There must be at least one free +% parameter left for the ith equation. Imported from dnrprior.m. +% Hpinv: cell(nvar,1). In each cell, posterior inverse of covariance matrix Hp (A+) for the free parameters +% g_i = V_i*A+(:,i) in the ith equation. +% Pmat: cell(nvar,1). In each cell, the transformation matrix that affects the posterior mean of A+ conditional on A0. +% In other words, the posterior mean (of g_i) = Pmat{i}*b_i where g_i is a column vector of free parameters +% of A+(:,i)) given b_i (b_i is a column vector of free parameters of A0(:,i)). +% Vi: nvar-by-1 cell. In each cell, k-by-ri orthonormal basis for the null of the ith +% equation lagged restriction matrix where k (ncoef) is a total number of RHS variables and +% ri is the number of free parameters. With this transformation, we have fi = Vi*gi +% or Vi'*fi = gi where fi is a vector of total original parameters and gi is a +% vector of free parameters. There must be at least one free parameter left for +% the ith equation. Imported from dnrprior.m. +% nvar: number of endogenous variables or rank of A0. +% fss: effective sample size (in the exponential term) = nSample - lags + ndobs (ndobs = # of dummy observations +% is set to 0 when fn_rnrprior_covres_dobs() is used where dummy observations are included as part of the explicit prior. +%------------- +% Tinv: cell(nvar,1). In each cell, inv(T_i) for T_iT_i'=S_i where S_i is defined on p.355 of the WZ JEDC paper. +% UT: cell(nvar,1). In each cell, U_i*T_i. +% VHphalf: cell(nvar,1). In each cell, V_i*sqrt(Hp_i). +% PU: cell(nvar,1). In each cell, Pmat{i}*U_i where Pmat{i} = P_i defined in (13) on p.353 of the WZ JEDC paper. +% VPU: cell(nvar,1). In each cell, V_i*P_i*U_i +% +% Written by Tao Zha, September 2004. +% Copyright (c) 2004 by Waggoner and Zha + + +%--- For A0. +Tinv = cell(nvar,1); % in each cell, inv(T_i) for T_iT_i'=S_i where S_i is defined on p.355 of the WZ JEDC paper. +UT = cell(nvar,1); % in each cell, U_i*T_i. +%--- For A+. +VHphalf = cell(nvar,1); % in each cell, V_i*sqrt(Hp_i). +PU = cell(nvar,1); % in each cell, Pmat{i}*U_i where Pmat{i} = P_i defined in (13) on p.353 of the WZ JEDC paper. +VPU = cell(nvar,1); % in each cell, V_i*P_i*U_i +% +for ki=1:nvar + %--- For A0. + Tinv{ki} = chol(H0inv{ki}/fss); % Tinv_i'*Tinv_i = inv(S_i) ==> T_i*T_i' = S_i where S_i = H0inv{i}/fss is defined on p.355 of the WZ JEDC paper. + UT{ki} = Ui{ki}/Tinv{ki}; % n-by-qi: U_i*T_i in (14) on p. 255 of the WZ JEDC paper. + %--- For A+. + VHphalf{ki} = Vi{ki}/chol(Hpinv{ki}); % where chol(Hpinv_i)*chol(Hpinv_i)'=Hpinv_i. + PU{ki} = Pmat{ki}*Ui{ki}'; + VPU{ki} = Vi{ki}*PU{ki}; +end diff --git a/MatlabFiles/fn_gradcd.m b/MatlabFiles/fn_gradcd.m new file mode 100755 index 0000000..409fdf7 --- /dev/null +++ b/MatlabFiles/fn_gradcd.m @@ -0,0 +1,69 @@ +function grdd = fn_gradcd(fcn,x0,grdh,P1,P2,P3,P4,P5,P6,P7,P8,P9,... + P10,P11,P12,P13,P14,P15,P16,P17,P18,P19,P20) +%function grdd = fn_gradcd(fcn,x0,grdh,P1,P2,P3,P4,P5,P6,P7,P8,P9,... +% P10,P11,P12,P13,P14,P15,P16,P17,P18,P19,P20) +% computes numerical gradient of a single-valued function or Jacobian +% matrix of a vector-valued function using a central difference with +% function grdd = gradcd(fcn,x0,grdh) +% +% fcn: a string naming a vector-valued function (f:n-by-1 -> k-by-1). +% x0: a column vector n-by-1, at which point the hessian is evaluated. +% grdh: step size, n*1. Set as follows +% step = eps^(1/3); +% %step = 1e-04; +% grdh = step * (max([abs(x) ones(length(x),1)]'))' .* (abs(x) ./ x); +%-------------------- +% grdd: n-by-k Jacobian matrix (gradients). +% +% Written by Tao Zha, 2002. + +stps = eps^(1/3); +% eps: floating point relative accuracy or machine precision: 2.22e-16 +% stps: step size recommended by Dennis and Schnabel: 6.006e-6 + +x0 = x0(:); +tailstr = ')'; +for i=nargin-3:-1:1 + tailstr=[ ',P' num2str(i) tailstr]; +end +f0 = eval([fcn '(x0' tailstr]); + +% ** initializations +n = length(x0); +k = length(f0); % dimension of "fcn" + +% ** Computation of stepsize (dh) +if all(grdh) + dh = grdh; +else + ax0 = abs(x0); + if all(x0) + dax0 = x0 ./ ax0; + else + dax0 = 1; + end + dh = stps * (max([ax0 ones(n,1)]'))' .* dax0; +end + +xdh = x0 + dh; +dh = xdh - x0; % This increases precision slightly +% +argplus = x0(:,ones(n,1)); +argminus = argplus; +dnum = 1:n+1:n^2; % positions of diagonals in vec(argplus). +argplus(dnum) = xdh; % replace the diagonals of "argplus" by "xdh". +argminus(dnum) = x0-dh; % replace the diagonals of "argplus" by "xdh". + +grdd = zeros(k,n); % preallocate to speed the loop. +i = 0; +while i ~= n + i = i+1; + fp = eval([fcn '(argplus(:,i)' tailstr]); + fm = eval([fcn '(argminus(:,i)' tailstr]); + grdd(:,i) = fp - fm; +end +dhm = dh(:,ones(k,1)); +dhm = dhm'; % k*n +grdd = grdd ./ (2*dhm); % k-by-n. +grdd = grdd'; % n-by-k. + diff --git a/MatlabFiles/fn_gradcd2.m b/MatlabFiles/fn_gradcd2.m new file mode 100755 index 0000000..55a30d9 --- /dev/null +++ b/MatlabFiles/fn_gradcd2.m @@ -0,0 +1,82 @@ +function grdd = fn_gradcd2(fcn,x0,grdh,P1,P2,P3,P4,P5,P6,P7,P8,P9,... + P10,P11,P12,P13,P14,P15,P16,P17,P18,P19,P20) +%function grdd = fn_gradcd(fcn,x0,grdh,P1,P2,P3,P4,P5,P6,P7,P8,P9,... +% P10,P11,P12,P13,P14,P15,P16,P17,P18,P19,P20) +% computes numerical gradient of a single-valued function or Jacobian +% matrix of a vector-valued function using a central difference with +% function grdd = gradcd(fcn,x0,grdh) +% +% fcn: a string naming a vector-valued function (f:n-by-1 -> k-by-1). +% x0: a column vector n-by-1, at which point the hessian is evaluated. +% grdh: step size, n*1. Set as follows +% step = eps^(1/3); +% %step = 1e-04; +% grdh = step * (max([abs(x) ones(length(x),1)]'))' .* (abs(x) ./ x); +%-------------------- +% grdd: n-by-k Jacobian matrix (gradients). +% +% Written by Tao Zha, 2002. + +stps = eps^(1/3); +% eps: floating point relative accuracy or machine precision: 2.22e-16 +% stps: step size recommended by Dennis and Schnabel: 6.006e-6 + +NEARINFINITY = 1.0e+100; +GRADMANUAL = 0.0; %Arbitrarily (manually) set gradient. + + +x0 = x0(:); +tailstr = ')'; +for i=nargin-3:-1:1 + tailstr=[ ',P' num2str(i) tailstr]; +end +f0 = eval([fcn '(x0' tailstr]); + +% ** initializations +n = length(x0); +k = length(f0); % dimension of "fcn" + +% ** Computation of stepsize (dh) +if all(grdh) + dh = grdh; +else + ax0 = abs(x0); + if all(x0) + dax0 = x0 ./ ax0; + else + dax0 = 1; + end + dh = stps * (max([ax0 ones(n,1)]'))' .* dax0; +end + +xdh = x0 + dh; +dh = xdh - x0; % This increases precision slightly +% +argplus = x0(:,ones(n,1)); +argminus = argplus; +dnum = 1:n+1:n^2; % positions of diagonals in vec(argplus). +argplus(dnum) = xdh; % replace the diagonals of "argplus" by "xdh". +argminus(dnum) = x0-dh; % replace the diagonals of "argplus" by "xdh". + +grdd = zeros(k,n); % preallocate to speed the loop. +i = 0; +while i ~= n + i = i+1; + fp = eval([fcn '(argplus(:,i)' tailstr]); + fm = eval([fcn '(argminus(:,i)' tailstr]); + if ((fp < NEARINFINITY) && (fm < NEARINFINITY)) + grdd(:,i) = (fp - fm) ./ (2*dh(i)); + elseif (fp < NEARINFINITY) + grdd(:,i) = (fp - f0) ./ (dh(i)); + elseif (fm < NEARINFINITY) + grdd(:,i) = (f0 - fm) ./ (dh(i)); + else + grdd(:,i) = GRADMANUAL; %Arbitrarily (manually) set gradient. + end +end +%dhm = dh(:,ones(k,1)); +%dhm = dhm'; % k*n +%grdd = grdd ./ (2*dhm); % k-by-n. +grdd = grdd'; % n-by-k. + + diff --git a/MatlabFiles/fn_gyrfore.m b/MatlabFiles/fn_gyrfore.m new file mode 100755 index 0000000..ef230db --- /dev/null +++ b/MatlabFiles/fn_gyrfore.m @@ -0,0 +1,45 @@ +function fn_gyrfore(yfore,yacte,keyindx,rnum,cnum,ylab,forelabel,conlab) +% +% Graph annual (or calendar year) forecasts vs actual (all data from "msstart.m") +% +% yfore: actual and forecast annual growth data with dates. +% yacte: actual annual growth data with dates. +% keyindx: index for the variables to be graphed +% rnum: number of rows in subplot +% cnum: number of columns in subplot +% ylab: label for the variables +% forelabel: title label for as of time of forecast +% conlab: label for what conditions imposed; e.g., conlab = 'All bar MS shocks inspl' +%------------- +% No output argument for this graph file +% +% Tao Zha, March 2000 + + +vyrs = yfore(:,1); +hornum = cell(length(vyrs),1); % horizontal year (number) +count=0; +for k=vyrs' + count=count+1; + jnk=num2str(k); + hornum{count}=jnk(3:4); % e.g., with '1990', we have '90' +end + +count=0; +for i = keyindx + count = count+1; + subplot(rnum,cnum,count) + % + plot(yacte(:,1),yacte(:,2+i),vyrs,yfore(:,2+i),'--') + set(gca,'XLim',[vyrs(1) vyrs(end)]) + set(gca,'XTick',vyrs) + set(gca,'XTickLabel',char(hornum)) + if i==keyindx(1) + title(forelabel) + elseif i>=length(keyindx) %i>=length(keyindx)-1 + xlabel(conlab) + end + % + grid + ylabel(char(ylab(i))) +end diff --git a/MatlabFiles/fn_hesscd.m b/MatlabFiles/fn_hesscd.m new file mode 100755 index 0000000..ce5979e --- /dev/null +++ b/MatlabFiles/fn_hesscd.m @@ -0,0 +1,65 @@ +function grdd = fn_hesscd(fcn,x0,grdh,P1,P2,P3,P4,P5,P6,P7,P8,P9,... + P10,P11,P12,P13,P14,P15,P16,P17,P18,P19,P20) +% Computing numerical hessian using a central difference with +% function grdd = hesscd(fcn,x0,grdh,Passed variables1) +% +% fcn: a string naming the objective function. +% x0: a column vector n*1, at which point the hessian is evaluated. +% grdh: step size. +% grdd: hessian matrix (second derivative), n*n. +% +% Written by Tao Zha, May 1998. Revised June 1002. + +stps = eps^(1/3); +% eps: floating point relative accuracy or machine precision: 2.22e-16 +% stps: step size recommended by Dennis and Schnabel: 6.006e-6 + +x0 = x0(:); +tailstr = ')'; +for i=nargin-3:-1:1 + tailstr=[ ',P' num2str(i) tailstr]; +end +f0 = eval([fcn '(x0' tailstr]); + +% ** initializations +k = length(x0); +grdd = zeros(k); + +% ** Computation of stepsize (dh) +if all(grdh) + dh = grdh; +else + ax0 = abs(x0); + if all(x0) + dax0 = x0 ./ ax0; + else + dax0 = 1; + end + dh = stps * (max([ax0 (1e-2)*ones(k,1)]'))' .* dax0; +end + +xdh = x0 + dh; +dh = xdh - x0; % This increases precision slightly +dhm = dh(:,ones(k,1)); +ee = eye(k) .* dhm; + +i = 1; +while i <= k + j = i; + while j <= k + + fune1 = eval([fcn '(x0 + ee(:,i) + ee(:,j)' tailstr]); + fune2 = eval([fcn '(x0 - ee(:,i) + ee(:,j)' tailstr]); + fune3 = eval([fcn '(x0 + ee(:,i) - ee(:,j)' tailstr]); + fune4 = eval([fcn '(x0 - ee(:,i) - ee(:,j)' tailstr]); + grdd(i,j) = (fune1 - fune2 - fune3 + fune4) / (4 * dh(i) * dh(j)); + + if i ~= j + grdd(j,i) = grdd(i,j); + end + + j = j+1; + end + i = i+1; +end + diff --git a/MatlabFiles/fn_histpdfcnt.m b/MatlabFiles/fn_histpdfcnt.m new file mode 100755 index 0000000..2387d68 --- /dev/null +++ b/MatlabFiles/fn_histpdfcnt.m @@ -0,0 +1,78 @@ +function [imfpdf,imfpo,imfprob] = fn_histpdfcnt(imfcnt,ndrawscnt,imfloor,hbin,ninv,... + gIndx,ncom,kIndx,lval,hval) +% [imfpdf,imfpo,imfprob] = fn_histpdfcnt(imfcnt,ndrawscnt,imfloor,hbin,ninv,gIndx,ncom,kIndx,lval,hval) +% From already ordered and binned (cnt: count) series (not pdf yet). +% Produce (1) the dataset for generating p.d.f.; +% (2) the dataset for probability (NOT density) at each bin; +% (3) with option gIndx=1, graph density functions. +% +% imfcnt: 2+ninv-by-k. Counted structural parameters, qmygcnt, ygcnt, or impulse responses. +% ndrawscnt: a total number of draws used in imfcnt +% imfloor: k-element vector of low values of imf but imf_h can be below "imfloor" and above "imceiling" +% hbin: k-element vector of bin lengths = (imceilling-imfloor)/ninv. Need not be a 1-by-k row vector. +% ninv: the number of bins (small interior intervals) between ``imfloor'' and ``imfceiling'' +% gIndx: 1: plot graphs of pdf's; 0: no plot. +% If gIndx=0, ncom, kIndx, lval, and hval are irrelevant and no densities will be plotted. +% ncom: number of combined intervals. Large ncom implies large size of the bin. +% Must set ncom so that ninv can be divided +% kIndx: index for selected variables. Length(kIndx)<=k. +% If kIndx=[], lval and hval are irrelevant and no densities will be plotted. +% lval: length(kIndx)-element vector of the lowest values on the axis; +% The vector corresponds to kIndx. This option is disenabled by setting it to []. +% hval: length(kIndx)-element vector of the highest values on the axis; +% The vector corresponds to kIndx. This option is disenabled by setting it to []. +%----------------- +% imfpdf: 2+ninv-by-k. Density (NOT probability) +% imfpo: 2+ninv-by-k. Bin position (x-axis) in relation to imfs3 +% imfprob: 2+ninv-by-k. Probability (NOT density) at each bin +% +% 27 August 1998 Tao Zha +% Revised, October 1998, March 1999, August 2000. + +if (nargin==5), gIndx=0; end +if (nargin==8), lval=[]; hval=[]; end + +imfloor=imfloor(:); hbin=hbin(:); +k=size(imfcnt,2); +invlengthM = repmat(hbin',[2+ninv,1]); +%invlengthM([1 2+ninv],:) = 1; % August 2000. I comment this out because it leads to an extorted picture + % when the rest of invlengthM is much smaller or larger than 1. + % For the first interval (-inf, low bound) and last interval (high bound, +inf), + % the length is set at 1. Of course, theoretically, the interval length should be set + % to infinity. Adjust low and high bounds if 1 is not large enough compared with hbin. +imfprob = imfcnt ./ ndrawscnt; % probability (NOT density) +imfpdf = imfprob ./ invlengthM; % density + +imfpo = [1:2+ninv]'; % positions for each forecast +imfpo = imfpo - 2; % the first step to put back to original form +imfpo = repmat(imfpo,[1,k]); +imfloorM = repmat(imfloor',[2+ninv,1]); +imfpo = (imfpo .* invlengthM) + imfloorM; % 2+ninv-by-k + % the final step to put back to original form of impulse responses + +if gIndx + if mod(ninv,ncom) + warning('Set ncom so that ninv can be divided') + return + end + % + ninv2=ninv/ncom; + imfpdfn=zeros(2+ninv2,size(imfcnt,2)); %<<>> + imfpon=imfpdfn; + % + for ik=1:ninv2 % from 2 to 1+ninv2 for imfpdfn and imfpon + imfpdfn(1+ik,:) = sum(imfpdf(1+(ik-1)*ncom+1:1+ik*ncom,:))/ncom; + imfpon(1+ik,:) = mean(imfpo(1+(ik-1)*ncom+1:1+ik*ncom,:)); + end + + ck1=0; + for k1=kIndx + ck1=ck1+1; + figure + plot(imfpon(2:1+ninv2,k1),imfpdfn(2:1+ninv2,k1)) % do not plot the values at -infty and +infty + if ~isempty(lval) & ~isempty(hval) + set(gca,'XLim',[lval(ck1) hval(ck1)]) + end + grid + end +end diff --git a/MatlabFiles/fn_histwpdfg.m b/MatlabFiles/fn_histwpdfg.m new file mode 100755 index 0000000..665292d --- /dev/null +++ b/MatlabFiles/fn_histwpdfg.m @@ -0,0 +1,68 @@ +function [xpd,xc,xp,w,bw] = fn_histwpdfg(s,nbin,gIdx,w,xlabstr,ylabstr,titstr) +% [xpd,xc,xp,w,bw] = fn_histwpdfg(s,nbin,gIdx,w,xlabstr,ylabstr,titstr) +% Generate probabilities and plot scaled densitys, given the unsorted draws and weights +% +% s: ndraws-by-n draws where ndraws is # of draws and n is # of series +% nbin: the number of bins (the maximum is ndraws) +% gIdx: 1 if plotting the pdf; 0 if no graph +% w (optional): ndraws-by-n (unscaled) weights where ndraws is # of draws and n is # of series +% xlabstr (optional): xlabel string +% ylabstr (optional): ylabel string +% titstr (optional): title string +%------------- +% xpd: nbin-by-n: density or pdf (not probability) in the centered bin on x-axis. +% xc: nbin-by-n: the position of centered bin on x-axis, from top to bottom. +% All columns are identical +% xp: nbin-by-n: probability (not density) in the centered bin on x-axis. +% NOTE: sum(xp) must be 1 for each column +% w: ndraws-by-n scaled weights so that sum(w)=1 for each column +% bw: bandwidth +% +% August 1999 by Tao Zha +% July 18 2000. Place w after gIdx so that previous programs need modifications accordingly. +% Oct 1 2000. Change the order of xpd, xc, and xp so that previous programs need modifications accordingly. + +if (nargin<=4), titstr=[]; xlabstr=[]; ylabstr=[]; end +[m,n] = size(s); +if (nargin<=3) + w=ones(m,n)/m; +else + %** normalized to 1 for the probability + wsum = repmat(sum(w), [m 1]); + w = w ./ wsum; +end + +%if min(size(s))==1, s=s(:); w=w(:); end % making sure they are column vectors + +%*** the position of the center of the bin on the x-axis +mins = min(min(s)); +maxs = max(max(s)); +bw = (maxs-mins)/nbin; % binwidth for x-axis +x = mins + bw*(0:nbin); +x(end) = maxs; % in case nbin is not an integer +xc = x(1:end-1) + bw/2; % the position of the center of the x-bin +xc = xc'; % nbin-by-1 row vector: from top to bottom +xc = repmat(xc,[1 n]); % nbin-by-n, same for each column + + +%*** the probability at each bin on the x-axis +nbin = nbin+1; % + 1 to get the difference for getting probability xp +nn = zeros(nbin,n); +for i=2:nbin + for k=1:n + xidx = find(s(:,k) <= x(i)); % index for the positions + nn(i,k) = sum(w(xidx,k)); + end +end +xp = nn(2:nbin,:) - nn(1:nbin-1,:); +if (bw<eps) + xpd=Inf*ones(size(xp)); +else + xpd = xp/bw; % the density, NOT the probability as xp +end + +if gIdx + plot(xc,xpd) + %set(gca,'XLim',[-5 5]) % put the limit only on the y-axis + title(titstr), xlabel(xlabstr), ylabel(ylabstr); +end diff --git a/MatlabFiles/fn_histwpdfg2D.m b/MatlabFiles/fn_histwpdfg2D.m new file mode 100755 index 0000000..f7d5845 --- /dev/null +++ b/MatlabFiles/fn_histwpdfg2D.m @@ -0,0 +1,118 @@ +function [xc,yc,z,zn] = fn_histwpdfg2D(s,n,w,ditp,xlabstr,ylabstr) +% [xc,yc,z,zn] = histwpdfg2D(s,w,n,ditp,xlabstr,ylabstr) +% Given uneven weights and 2D draws, generate 2D pdf and probabilites by scaling 2D histogram +% +% s: ndraws-by-2 matrix where ndraws is # of draws and 2 variables +% n: 1-by-2 vector -- # of bins (integers in general) for both x-axis and y-axis +% w: ndraws-by-1 vector of (uneven) weights. Optional. If [] or no entry, even weights are given. +% ditp: Postive number -- degrees of bicubic interpolation. Bigger ditp is, more points for z with +% finer the (x,y) plance are interpolated. Optional. If [] or no entry, no interpolation. +% xlabstr: xlabel string. Optional. If [] or no entry, no x label. +% ylabstr: ylabel string. Optional. If [] or no entry, no y label. +%--------------------------------- +% xc: the position of centered bin on x-axis, from left to right. All rows are identical +% yc: the position of centered bin on y-axis, from top to bottom. All columns are identical +% z: size(xc,2)-by-size(yc,1) -- the pdf value in each rectangular cell +% zn: size(xc,2)-by-size(yc,1) -- the probability value in each rectangular cell +% if nargout==0, plot 2D p.d.f. graphics +% +% January 1999 by Tao Zha. Revised, March 2002. + +if (size(s,2)~=2) + error('The size of 1st argument must be *-by-2 (i.e., 2 columns)') +end + +if (nargin<3), w=[]; ditp=[]; xlabstr=[]; ylabstr=[]; end +if (nargin<4), ditp=[]; xlabstr=[]; ylabstr=[]; end +if (nargin<5), xlabstr=[]; ylabstr=[]; end +if (nargin<6), ylabstr=[]; end + +if (length(n(:))~=2) + error('2nd argument must have exactly 2 elements') +end + +if (min(n)<3) + error('2nd argument -- bin size -- must have at least 3 for each axis') +end + +ndraws=size(s,1); + +%** normalized to 1 for the probability +if isempty(w) + w = ones(ndraws,1)/ndraws; +else + w=w(:); % make sure it's a column vector + w = w/sum(w); +end + + +%*** x-axis +minx = min(min(s(:,1))); +maxx = max(max(s(:,1))); +h1 = (maxx-minx)/n(1); % binwidth for x-axis +x = minx + h1*(0:n(1)); +xlen = length(x); % n(1)+1 +x(xlen) = maxx; % in case n(1) is not an integer +xc = x(1:xlen-1) + h1/2; % the position of the center of the x-bin + % 1-by-n(1) row vector: from left to right +xc = repmat(xc,[n(2) 1]); + +%*** y-axis +miny = min(min(s(:,2))); +maxy = max(max(s(:,2))); +h2 = (maxy-miny)/n(2); % binwidth for y-axis +y = miny + h2*(0:n(2)); +ylen = length(y); +y(ylen) = maxy; % in case n(2) is not an integer +yc = y(1:ylen-1) + h2/2; % the position of the center of the y-bin +yc = yc(:); % n(2)-by-1 column vector: from top to bottom +yc = repmat(yc,[1 n(1)]); + + +zn = zeros(n(2),n(1)); % the reverse of x and y is designed for mesh. + % see meshgrid to understand this. +tic +for draws=1:ndraws + k1 = floor((s(draws,1)-minx)/h1)+1; + k2 = floor((s(draws,2)-miny)/h2)+1; + % + % if k1==0 + % k1=1; + % end + % if k2==0; + % k2=1; + % end + % + if k1>n(1) + k1=n(1); + end + if k2>n(2) + k2=n(2) + end + zn(k2,k1) = zn(k2,k1)+w(draws); % probability in each rectangular cell +end +timeloop=toc; +disp(['Loop time -- minutes ' num2str(timeloop/60)]) + +z=zn/(h1*h2); % converted to the height of the p.d.f. + + +%*** scaled 2D histogram or p.d.f. +%figure(1) +%*** interpolation +if isempty(ditp) + colormap(zeros(1,3)); % Set color to black + mesh(xc,yc,z) + title('Scaled histogram or p.d.f.') + xlabel(xlabstr) + ylabel(ylabstr) +else + [xi,yi]=meshgrid(minx:h1/ditp:maxx,miny:h2/ditp:maxy); + zi = interp2(xc,yc,z,xi,yi,'bicubic'); + figure(30) + colormap(zeros(1,3)); % Set color to black + mesh(xi,yi,zi) % or mesh + title('Interpolated p.d.f.') + xlabel(xlabstr) + ylabel(ylabstr) +end diff --git a/MatlabFiles/fn_histwpdfg_bound.m b/MatlabFiles/fn_histwpdfg_bound.m new file mode 100755 index 0000000..199cf85 --- /dev/null +++ b/MatlabFiles/fn_histwpdfg_bound.m @@ -0,0 +1,69 @@ +function [xpd,xc,xp,w,bw] = fn_histwpdfg_bound(s,nbin,gIdx,bound,w,xlabstr,ylabstr,titstr) +% [xpd,xc,xp,w,bw] = fn_histwpdfg_bound(s,nbin,gIdx,bound,w,xlabstr,ylabstr,titstr) +% Generate probabilities and plot scaled densitys, given the unsorted draws and weights +% +% s: ndraws-by-n draws where ndraws is # of draws and n is # of series +% nbin: the number of bins (the maximum is ndraws) +% gIdx: 1 if plotting the pdf; 0 if no graph +% bound: bounds for XLim. Example: bound = [-2 2]; +% w (optional): ndraws-by-n (unscaled) weights where ndraws is # of draws and n is # of series +% xlabstr (optional): xlabel string +% ylabstr (optional): ylabel string +% titstr (optional): title string +%------------- +% xpd: nbin-by-n: density or pdf (not probability) in the centered bin on x-axis. +% xc: nbin-by-n: the position of centered bin on x-axis, from top to bottom. +% All columns are identical +% xp: nbin-by-n: probability (not density) in the centered bin on x-axis. +% NOTE: sum(xp) must be 1 for each column +% w: ndraws-by-n scaled weights so that sum(w)=1 for each column +% bw: bandwidth +% +% August 1999 by Tao Zha +% July 18 2000. Place w after gIdx so that previous programs need modifications accordingly. +% Oct 1 2000. Change the order of xpd, xc, and xp so that previous programs need modifications accordingly. + +if (nargin<=5), titstr=[]; xlabstr=[]; ylabstr=[]; end +[m,n] = size(s); +if (nargin<=4) + w=ones(m,n)/m; +else + %** normalized to 1 for the probability + wsum = repmat(sum(w), [m 1]); + w = w ./ wsum; +end + +%if min(size(s))==1, s=s(:); w=w(:); end % making sure they are column vectors + +%*** the position of the center of the bin on the x-axis +mins = min(min(s)); +maxs = max(max(s)); +bw = (maxs-mins)/nbin; % binwidth for x-axis +x = mins + bw*(0:nbin); +x(end) = maxs; % in case nbin is not an integer +xc = x(1:end-1) + bw/2; % the position of the center of the x-bin +xc = xc'; % nbin-by-1 row vector: from top to bottom +xc = repmat(xc,[1 n]); % nbin-by-n, same for each column + + +%*** the probability at each bin on the x-axis +nbin = nbin+1; % + 1 to get the difference for getting probability xp +nn = zeros(nbin,n); +for i=2:nbin + for k=1:n + xidx = find(s(:,k) <= x(i)); % index for the positions + nn(i,k) = sum(w(xidx,k)); + end +end +xp = nn(2:nbin,:) - nn(1:nbin-1,:); +if (bw<eps) + xpd=Inf*ones(size(xp)); +else + xpd = xp/bw; % the density, NOT the probability as xp +end + +if gIdx + plot(xc,xpd) + set(gca,'XLim',bound) % put the limit only on the y-axis + title(titstr), xlabel(xlabstr), ylabel(ylabstr); +end diff --git a/MatlabFiles/fn_imc2errgraph.m b/MatlabFiles/fn_imc2errgraph.m new file mode 100755 index 0000000..47efaa0 --- /dev/null +++ b/MatlabFiles/fn_imc2errgraph.m @@ -0,0 +1,115 @@ +function scaleout = imc2errgraph(imf,firstl1,firsth1,... + firstl,firsth,nvar,imstp,xlab,ylab,indxGimfml,xTick) +% imc2errgraph: impulse, c (column: shock 1 to N), 2 error bands, graph +% +% imf: imstp-by-nvar^2 matrix of impulse responses. Column (responses to 1st shock, responses to 2nd shock +% etc), Row (impusle steps), +% firstl1: lower band, .68 +% highth1: high band, .68 +% firstl: lower band, .90 +% highth: high band, .90 +% nvar: number of variables +% imstp: number of steps of impulse responses +% xlab,ylab: labels +% indxGimfml: 1, graph; 0, no graph +% xTick: optional. Eg: [12 24 36]. +%--------------- +% scaleout: column 1 represents maximums; column 2 minimums. Rows: nvar variables. +% +% See imrgraph, fn_imcerrgraph, imrerrgraph + +if nargin < 11, xTick = []; end + +t = 1:imstp; +temp1=zeros(nvar,1); +temp2=zeros(nvar,1); +maxval=zeros(nvar,1); +minval=zeros(nvar,1); +for i = 1:nvar + for j = 1:nvar + jnk1=max(firsth(:,(j-1)*nvar+i)); + jnk2=max(firstl(:,(j-1)*nvar+i)); + jnk3=max(firsth1(:,(j-1)*nvar+i)); + jnk4=max(firstl1(:,(j-1)*nvar+i)); + jnk5=max(imf(:,(j-1)*nvar+i)); + + temp1(j)=max([jnk1 jnk2 jnk3 jnk4 jnk5]); + % + jnk1=min(firstl(:,(j-1)*nvar+i)); + jnk2=min(firsth(:,(j-1)*nvar+i)); + jnk3=min(firstl1(:,(j-1)*nvar+i)); + jnk4=min(firsth1(:,(j-1)*nvar+i)); + jnk5=min(imf(:,(j-1)*nvar+i)); + + temp2(j)=min([jnk1 jnk2 jnk3 jnk4 jnk5]); + end + maxval(i)=max(temp1); + minval(i)=min(temp2); +end + +scaleout = [maxval(:) minval(:)]; + +%-------------- +% Column j: Shock 1 to N; Row i: Responses to +%------------- +if indxGimfml + %figure + rowlabel = 1; + for i = 1:nvar + columnlabel = 1; + + if minval(i)<0 + if maxval(i)<=0 + yt=[minval(i) 0]; + else + yt=[minval(i) 0 maxval(i)]; + end + else % (minval(i) >=0) + if maxval(i) > 0 + yt=[0 maxval(i)]; + else % (identically zero responses) + yt=[-1 0 1]; + end + end + + scale=[1 imstp minval(i) maxval(i)]; + for j = 1:nvar + k1=(i-1)*nvar+j; + k2=(j-1)*nvar+i; + subplot(nvar,nvar,k1) + plot(t,imf(:,k2),t,[firstl1(:,k2) firsth1(:,k2)],'--',... + t,[firstl(:,k2) firsth(:,k2)],'-.',t,zeros(length(imf(:,k2)),1),'-'); + + set(gca,'XTick',xTick) + set(gca,'YTick',yt) + grid; + + axis(scale); % put limits on both axes. + %set(gca,'YLim',[minval(i) maxval(i)]) + if 1 % no numbers on axes + set(gca,'XTickLabel',' '); + set(gca,'YTickLabel',' '); + else % put numbers on both axes + if i<nvar + set(gca,'XTickLabelMode','manual','XTickLabel',[]) + end + if j>1 + set(gca,'YTickLabel',' '); + end + end + + if rowlabel == 1 + %title(['x' num2str(j)]) + %title(eval(['x' num2str(j)])) + title(char(xlab(j))) + end + if columnlabel == 1 + %ylabel(['x' num2str(i)]) + %ylabel(eval(['x' num2str(i)])) + ylabel(char(ylab(i))) + end + columnlabel = 0; + end + rowlabel = 0; + end +end diff --git a/MatlabFiles/fn_imcerrgraph.m b/MatlabFiles/fn_imcerrgraph.m new file mode 100755 index 0000000..a0c76d0 --- /dev/null +++ b/MatlabFiles/fn_imcerrgraph.m @@ -0,0 +1,106 @@ +function scaleout = fn_imcerrgraph(imf,firstl,firsth,nvar,imstp,xlab,ylab,indxGimfml,xTick,indx_num) +% scaleout = fn_imcerrgraph(imf,firstl,firsth,nvar,imstp,xlab,ylab,indxGimfml,xTick) +% imcerrgraph: impulse, c (column: shock 1 to N), 1 error band, graph +% +% imf: imstp-by-nvar^2 matrix of impulse responses. Column (responses to 1st shock, responses to 2nd shock +% etc), Row (impusle steps), +% firstl: lower band +% highth: high band +% nvar: number of variables +% imstp: number of steps of impulse responses +% xlab,ylab: labels +% indxGimfml: 1, graph; 0, no graph +% xTick: optional. Eg: [12 24 36]. +% indx_num: 0: no number on either axis (default), 1: number on both x-axis and y-axis. +%--------------- +% scaleout: column 1 represents maximums; column 2 minimums. Rows: nvar variables. +% +% See fn_imcgraph, fn_imc2errgraph, imrerrgraph + +if nargin < 9, xTick = []; end +if nargin < 10, indx_num = 0; end + +t = 1:imstp; +temp1=zeros(nvar,1); +temp2=zeros(nvar,1); +maxval=zeros(nvar,1); +minval=zeros(nvar,1); +for i = 1:nvar + for j = 1:nvar + temp1(j)=max(firsth(:,(j-1)*nvar+i)); + temp2(j)=min(firstl(:,(j-1)*nvar+i)); + end + maxval(i)=max(temp1); + minval(i)=min(temp2); +end + +scaleout = [maxval(:) minval(:)]; + +%-------------- +% Column j: Shock 1 to N; Row i: Responses to +%------------- +if indxGimfml + %figure + rowlabel = 1; + for i = 1:nvar + columnlabel = 1; + + if minval(i)<0 + if maxval(i)<=0 + yt=[minval(i) 0]; + else + yt=[minval(i) 0 maxval(i)]; + end + else % (minval(i) >=0) + if maxval(i) > 0 + yt=[0 maxval(i)]; + else % (identically zero responses) + yt=[-1 0 1]; + end + end + + scale=[1 imstp minval(i) maxval(i)]; + for j = 1:nvar + k1=(i-1)*nvar+j; + k2=(j-1)*nvar+i; + subplot(nvar,nvar,k1) + plot(t,imf(:,k2),t,[firstl(:,k2) firsth(:,k2)],'--',... + t,zeros(length(imf(:,k2)),1),'-'); + + set(gca,'XTick',xTick) + set(gca,'YTick',yt) + grid + + axis(scale); % put limits on both axes. + %set(gca,'YLim',[minval(i) maxval(i)]) + if (indx_num==0) % no numbers on axes + set(gca,'XTickLabel',' '); + set(gca,'YTickLabel',' '); +% elseif (indx_num==1) %numbers on x-axis. +% if i<nvar +% set(gca,'XTickLabelMode','manual','XTickLabel',[]) +% end + else % put numbers on both axes + if i<nvar + set(gca,'XTickLabelMode','manual','XTickLabel',[]) + end + if j>1 + set(gca,'YTickLabel',' '); + end + end + + if rowlabel == 1 + %title(['x' num2str(j)]) + %title(eval(['x' num2str(j)])) + title(char(xlab(j))) + end + if columnlabel == 1 + %ylabel(['x' num2str(i)]) + %ylabel(eval(['x' num2str(i)])) + ylabel(char(ylab(i))) + end + columnlabel = 0; + end + rowlabel = 0; + end +end diff --git a/MatlabFiles/fn_imcerrgraph_scl.m b/MatlabFiles/fn_imcerrgraph_scl.m new file mode 100755 index 0000000..3a35ac1 --- /dev/null +++ b/MatlabFiles/fn_imcerrgraph_scl.m @@ -0,0 +1,105 @@ +function scaleout = fn_imcerrgraph_scl(imf,firstl,firsth,nvar,imstp,scaleout,xlab,ylab,indxGimfml,xTick) +% scaleout = fn_imcerrgraph(imf,firstl,firsth,nvar,imstp,xlab,ylab,indxGimfml,xTick) +% imcerrgraph: impulse, c (column: shock 1 to N), 1 error band, graph +% +% imf: imstp-by-nvar^2 matrix of impulse responses. Column (responses to 1st shock, responses to 2nd shock +% etc), Row (impusle steps), +% firstl: lower band +% highth: high band +% nvar: number of variables +% imstp: number of steps of impulse responses +% xlab,ylab: labels +% indxGimfml: 1, graph; 0, no graph +% xTick: optional. Eg: [12 24 36]. +%--------------- +% scaleout: column 1 represents maximums; column 2 minimums. Rows: nvar variables. +% +% See fn_imcgraph, fn_imc2errgraph, imrerrgraph + +if nargin < 10, xTick = []; end + +t = 1:imstp; +if isempty(scaleout) + temp1=zeros(nvar,1); + temp2=zeros(nvar,1); + maxval=zeros(nvar,1); + minval=zeros(nvar,1); + for i = 1:nvar + for j = 1:nvar + temp1(j)=max(firsth(:,(j-1)*nvar+i)); + temp2(j)=min(firstl(:,(j-1)*nvar+i)); + end + maxval(i)=max(temp1); + minval(i)=min(temp2); + end + scaleout = [maxval(:) minval(:)]; +else + maxval = scaleout(:,1); + minval = scaleout(:,2); +end + + +%-------------- +% Column j: Shock 1 to N; Row i: Responses to +%------------- +if indxGimfml + %figure + rowlabel = 1; + for i = 1:nvar + columnlabel = 1; + + if minval(i)<0 + if maxval(i)<=0 + yt=[minval(i) 0]; + else + yt=[minval(i) 0 maxval(i)]; + end + else % (minval(i) >=0) + if maxval(i) > 0 + yt=[0 maxval(i)]; + else % (identically zero responses) + yt=[-1 0 1]; + end + end + + scale=[1 imstp minval(i) maxval(i)]; + for j = 1:nvar + k1=(i-1)*nvar+j; + k2=(j-1)*nvar+i; + subplot(nvar,nvar,k1) + plot(t,imf(:,k2),t,[firstl(:,k2) firsth(:,k2)],'--',... + t,zeros(length(imf(:,k2)),1),'-'); + + set(gca,'XTick',xTick) + set(gca,'YTick',yt) + grid + + axis(scale); % put limits on both axes. + %set(gca,'YLim',[minval(i) maxval(i)]) + if 1 % no numbers on axes + set(gca,'XTickLabel',' '); + set(gca,'YTickLabel',' '); + else % put numbers on both axes + if i<nvar + set(gca,'XTickLabelMode','manual','XTickLabel',[]) + end + if j>1 + set(gca,'YTickLabel',' '); + end + end + + if rowlabel == 1 + %title(['x' num2str(j)]) + %title(eval(['x' num2str(j)])) + title(char(xlab(j))) + end + if columnlabel == 1 + %ylabel(['x' num2str(i)]) + %ylabel(eval(['x' num2str(i)])) + ylabel(char(ylab(i))) + end + columnlabel = 0; + end + rowlabel = 0; + end +end diff --git a/MatlabFiles/fn_imcgraph.m b/MatlabFiles/fn_imcgraph.m new file mode 100755 index 0000000..dfb6cc2 --- /dev/null +++ b/MatlabFiles/fn_imcgraph.m @@ -0,0 +1,107 @@ +function scaleout = fn_imcgraph(imf,nvar,imstp,xlab,ylab,indxGimfml,xTick) +% scaleout = fn_imcgraph(imf,nvar,imstp,xlab,ylab,indxGimfml,xTick) +% imcgraph: impulse, c (column: shock 1 to N), graph the ML point impulse response +% +% imf: imstp-by-nvar^2 matrix of impulse responses, column (responses to 1st shock, responses to 2nd shock +% etc), row (impusle steps), +% nvar: number of variables +% imstp: number of steps of impulse responses +% xlab,ylab: labels +% indxGimfml: 1, graph; 0, no graph +% xTick: optional. Eg: [12 24 36]. +%--------------- +% scaleout: column 1 represents maximums; column 2 minimums. Rows: nvar variables. +% +% NOTE: I added "indxGimfml" so this function may not be compatible with programs +% older than 03/06/99, TZ +% +% See imrgraph, fn_imcerrgraph, fn_imc2errgraph, imrerrgraph, fn_gyrfore in RVARcode + +if nargin < 7, xTick = []; end + +t = 1:imstp; +temp1=zeros(nvar,1); +temp2=zeros(nvar,1); +maxval=zeros(nvar,1); +minval=zeros(nvar,1); +for i = 1:nvar + for j = 1:nvar + temp1(j)=max(imf(:,(j-1)*nvar+i)); + temp2(j)=min(imf(:,(j-1)*nvar+i)); + end + maxval(i)=max(temp1); + minval(i)=min(temp2); +end + +scaleout = [maxval(:) minval(:)]; + +%-------------- +% Column j: Shock 1 to N; Row i: Responses to +%------------- +if indxGimfml + %figure + rowlabel = 1; + for i = 1:nvar % Responses of + columnlabel = 1; + + if minval(i)<0 + if maxval(i)<=0 + yt=[minval(i) 0]; + else + yt=[minval(i) 0 maxval(i)]; + end + else % (minval(i) >=0) + if maxval(i) > 0 + yt=[0 maxval(i)]; + else % (identically zero responses) + yt=[-1 0 1]; + end + end + + + scale=[1 imstp minval(i) maxval(i)]; + for j = 1:nvar % To shocks + k1=(i-1)*nvar+j; + k2=(j-1)*nvar+i; + subplot(nvar,nvar,k1) + plot(t,imf(:,k2),t,zeros(length(imf(:,k2)),1),'r:'); + + set(gca,'XTick',xTick) + set(gca,'YTick',yt) + grid + + axis(scale); % put limits on both axes. + % + % if maxval(i)>minval(i) + % set(gca,'YLim',[minval(i) maxval(i)]) + % end + + + if isempty(xTick) %1 % No numbers on both axes + set(gca,'XTickLabel',' '); + set(gca,'YTickLabel',' '); + else % Put numbers on both axes + if i<nvar + set(gca,'XTickLabelMode','manual','XTickLabel',[]) + end + if j>1 + set(gca,'YTickLabel',' '); + end + end + + + if rowlabel == 1 + %title(['x' num2str(j)]) + %title(eval(['x' num2str(j)])) + title(char(xlab(j))) + end + if columnlabel == 1 + %ylabel(['x' num2str(i)]) + %ylabel(eval(['x' num2str(i)])) + ylabel(char(ylab(i))) + end + columnlabel = 0; + end + rowlabel = 0; + end +end diff --git a/MatlabFiles/fn_imcgraph_scl.m b/MatlabFiles/fn_imcgraph_scl.m new file mode 100755 index 0000000..0f7c99f --- /dev/null +++ b/MatlabFiles/fn_imcgraph_scl.m @@ -0,0 +1,112 @@ +function scaleout = fn_imcgraph_scl(imf,nvar,imstp,scaleout,xlab,ylab,indxGimfml,xTick) +% scaleout = fn_imcgraph(imf,nvar,imstp,xlab,ylab,indxGimfml,xTick) +% imcgraph: impulse, c (column: shock 1 to N), graph the ML point impulse response +% +% imf: imstp-by-nvar^2 matrix of impulse responses, column (responses to 1st shock, responses to 2nd shock +% etc), row (impusle steps), +% nvar: number of variables +% imstp: number of steps of impulse responses +% xlab,ylab: labels +% indxGimfml: 1, graph; 0, no graph +% xTick: optional. Eg: [12 24 36]. +%--------------- +% scaleout: column 1 represents maximums; column 2 minimums. Rows: nvar variables. +% +% NOTE: I added "indxGimfml" so this function may not be compatible with programs +% older than 03/06/99, TZ +% +% See imrgraph, fn_imcerrgraph, fn_imc2errgraph, imrerrgraph, fn_gyrfore in RVARcode + +if nargin < 7, xTick = []; end + +t = 1:imstp; +if isempty(scaleout) + temp1=zeros(nvar,1); + temp2=zeros(nvar,1); + maxval=zeros(nvar,1); + minval=zeros(nvar,1); + for i = 1:nvar + for j = 1:nvar + temp1(j)=max(imf(:,(j-1)*nvar+i)); + temp2(j)=min(imf(:,(j-1)*nvar+i)); + end + maxval(i)=max(temp1); + minval(i)=min(temp2); + end + scaleout = [maxval(:) minval(:)]; +else + maxval = scaleout(:,1); + minval = scaleout(:,2); +end + + +%-------------- +% Column j: Shock 1 to N; Row i: Responses to +%------------- +if indxGimfml + %figure + rowlabel = 1; + for i = 1:nvar % Responses of + columnlabel = 1; + + if minval(i)<0 + if maxval(i)<=0 + yt=[minval(i) 0]; + else + yt=[minval(i) 0 maxval(i)]; + end + else % (minval(i) >=0) + if maxval(i) > 0 + yt=[0 maxval(i)]; + else % (identically zero responses) + yt=[-1 0 1]; + end + end + + + scale=[1 imstp minval(i) maxval(i)]; + for j = 1:nvar % To shocks + k1=(i-1)*nvar+j; + k2=(j-1)*nvar+i; + subplot(nvar,nvar,k1) + plot(t,imf(:,k2),t,zeros(length(imf(:,k2)),1),'r:'); + + set(gca,'XTick',xTick) + set(gca,'YTick',yt) + grid + + axis(scale); % put limits on both axes. + % + % if maxval(i)>minval(i) + % set(gca,'YLim',[minval(i) maxval(i)]) + % end + + + if isempty(xTick) %1 % No numbers on both axes + set(gca,'XTickLabel',' '); + set(gca,'YTickLabel',' '); + else % Put numbers on both axes + if i<nvar + set(gca,'XTickLabelMode','manual','XTickLabel',[]) + end + if j>1 + set(gca,'YTickLabel',' '); + end + end + + + if rowlabel == 1 + %title(['x' num2str(j)]) + %title(eval(['x' num2str(j)])) + title(char(xlab(j))) + end + if columnlabel == 1 + %ylabel(['x' num2str(i)]) + %ylabel(eval(['x' num2str(i)])) + ylabel(char(ylab(i))) + end + columnlabel = 0; + end + rowlabel = 0; + end +end diff --git a/MatlabFiles/fn_impulse.m b/MatlabFiles/fn_impulse.m new file mode 100755 index 0000000..eca0c3e --- /dev/null +++ b/MatlabFiles/fn_impulse.m @@ -0,0 +1,59 @@ +function imf = fn_impulse(Bh,swish,nn) +% Computing impulse functions with +% imf = fn_impulse(Bh,swish,nn) +% imf is in a format that is the SAME as in RATS. +% Column: nvar responses to 1st shock, +% nvar responses to 2nd shock, and so on. +% Row: steps of impulse responses. +%----------------- +% Bh is the estimated reduced form coefficient in the form +% Y(T*nvar) = XB + U, X: T*k (may include all exogenous terms), B: k*nvar. +% The matrix form and dimension are the same as "Bh" from the function "sye.m"; +% Column: 1st lag (with nvar variables) to lags (with nvar variables) + const = k. +% Note: columns correspond to equations. +% swish is the inv(A0) in the structural model y'(t)*A0 = e'(t). +% Note: columns corresponding to equations. +% nn is the numbers of inputs [nvar,lags,# of steps of impulse responses]. +% +% Written by Tao Zha. +% Copyright (c) 1994 by Tao Zha + +nvar = nn(1); +lags = nn(2); +imstep = nn(3); % number of steps for impulse responses + +Ah = Bh'; +% Row: nvar equations +% Column: 1st lag (with nvar variables) to lags (with nvar variables) + const = k. + +imf = zeros(imstep,nvar*nvar); +% Column: nvar responses to 1st shock, nvar responses to 2nd shock, and so on. +% Row: steps of impulse responses. +M = zeros(nvar*(lags+1),nvar); +% Stack lags M's in the order of, e.g., [Mlags, ..., M2,M1;M0] +M(1:nvar,:) = swish'; +Mtem = M(1:nvar,:); % temporary M. +% first (initial) responses to 1 standard deviation shock. Row: responses; Column: shocks +% * put in the form of "imf" +imf(1,:) = Mtem(:)'; + +t = 1; +ims1 = min([imstep-1 lags]); +while t <= ims1 + Mtem = Ah(:,1:nvar*t)*M(1:nvar*t,:); + % Row: nvar equations, each for the nvar variables at tth lag + M(nvar+1:nvar*(t+1),:)=M(1:nvar*t,:); + M(1:nvar,:) = Mtem; + imf(t+1,:) = Mtem(:)'; + % stack imf with each step, Row: 6 var to 1st shock, 6 var to 2nd shock, etc. + t= t+1; +end + +for t = lags+1:imstep-1 + Mtem = Ah(:,1:nvar*lags)*M(1:nvar*lags,:); + % Row: nvar equations, each for the nvar variables at tth lag + M(nvar+1:nvar*(t+1),:) = M(1:nvar*t,:); + M(1:nvar,:)=Mtem; + imf(t+1,:) = Mtem(:)'; + % stack imf with each step, Row: 6 var to 1st shock, 6 var to 2nd shock, etc. +end diff --git a/MatlabFiles/fn_irf_var1.m b/MatlabFiles/fn_irf_var1.m new file mode 100755 index 0000000..3c42b68 --- /dev/null +++ b/MatlabFiles/fn_irf_var1.m @@ -0,0 +1,34 @@ +function irfs = fn_irf_var1(G1, impact, nsteps); +%irfs = fn_irf_var1(G1, impact,nsteps); +% Inputs: +% G1: n-by-n; +% impact: n-by-r; +% nsteps: number of steps for impulse responses. +%--- +% Outputs: +% irfs: nsteps-by-n-by-r. For each shock of r shocks, impulse responses are nsteps-by-n. +% +% See fn_vds.m and fn_uncondfcst_var1.m. + +[n,r] = size(impact); + +[n1,n2] = size(G1); +if (n1 ~= n2) || (n1 ~= n) + error('fn_irf_var1.m: make sure that (1) G1 is square and (2) size(G1,1) = size(impact,1)'); +end + +irfs = zeros(nsteps,n,r); + + +%---- Impuse responses at the first step. +M = impact; +for ri=1:r + irfs(1,:,ri) = M(:,ri)'; +end + +for ti = 2:nsteps + M = G1*M; + for ri=1:r + irfs(ti,:,ri) = M(:,ri)'; + end +end diff --git a/MatlabFiles/fn_kalfil_tv.m b/MatlabFiles/fn_kalfil_tv.m new file mode 100755 index 0000000..c8548c4 --- /dev/null +++ b/MatlabFiles/fn_kalfil_tv.m @@ -0,0 +1,138 @@ +function [loglh,zt_tm1,Pt_tm1, loglh_t_allvalues] = fn_kalfil_tv(Y_T, a, H, R, G, b, F, V, indxIni,z0,P0) +%[loglh,zt_tm1,Pt_tm1] = fn_kalfil_tv(Y_T, a, H, R, G, b, F, V, indxIni,z0,P0) +%Time-varying Kalman filter (conditional on all the regimes in a Markov-switching model). It computes +% a sequence of one-step predictions and their covariance matrices, and the log likelihood. +% The function uses a forward recursion algorithm. +% +% Note: for b, F, V, zt_tm1, and Pt_tm1, there is not need for the T+1 length because the values at T+1 have +% never been used in the likelihood function. See tz_kalfiltv() in kalman.c for an illustration. +% +% State space model is defined as follows: +% y(t) = a(t) + H(t)*z(t) + eps(t) (observation or measurement equation) +% z(t) = b(t) + F(t)*z(t) + eta(t) (state or transition equation) +% where a(t), H(t), b(t), and F(t) depend on s_t that follows a Markov-chain process and are taken as given. +% +% Inputs are as follows: +% Y_T is a n_y-by-T matrix containing data [y(1), ... , y(T)]. +% a is an n_y-by-T matrix of time-varying input vectors in the measurement equation. +% H is an n_y-by-n_z-by-T 3-D of time-varying matrices in the measurement equation. +% R is an n_y-by-n_y-by-T 3-D of time-varying covariance matrices for the error in the measurement equation. +% G is an n_z-by-n_y-by-T 3-D of time-varying E(eta_t * eps_t'). +% ------ +% b is an n_z-by-(T+1) matrix of time-varying input vectors in the state equation with b(:,1) as an initial condition. +% F is an n_z-by-n_z-by-(T+1) 3-D of time-varying transition matrices in the state equation with F(:,:,1) as an initial condition. +% V is an n_z-by-n_z-by-(T+1) 3-D of time-varying covariance matrices for the error in the state equation with V(:,:,1) as an initial condition. +% ------ +% indxIni: 1: using the initial condition with zt_tm1(:,1)=z0 and Pt_tm1(:,:,1)=P0; +% 0: using the unconditional mean for any given regime at time 0. +% z0 is an n_z-by-1 vector of initial condition when indxIni=1. (Do not enter if indxIni=0.) +% P0 is an n_z-by-n_z matrix of initial condition when indxIni=1. (Do not enter if indxIni=0.) +% +% Outputs are as follows: +% loglh is a value of the log likelihood function of the state-space model +% under the assumption that errors are multivariate Gaussian. +% zt_tm1 is an n_z-by-(T+1) matrices of one-step predicted state vectors with z0_0m1 as a initial condition. +% Pt_tm1 is an n_z-by-n_z-by-(T+1) 3-D of covariance matrices of zt_tm1 with P0_0m1 as a initial condition. +% loglh_t_allvalues is a T-by-1 vector of loglh at time t for t=1:T. +% +% The initial state vector and its covariance matrix are computed under the bounded (stationary) condition: +% z0_0m1 = (I-F(:,:,1))\b(:,1) +% vec(P0_0m1) = (I-kron(F(:,:,1),F(:,:,1)))\vec(V(:,:,1)) +% Note that all eigenvalues of the matrix F(:,:,1) are inside the unit circle when the state-space model is bounded (stationary). +% +% March 2007, written by Tao Zha +% See Hamilton's book ([13.2.13] -- [13.2.22]), Harvey (pp.100-106), and LiuWZ Model I NOTES pp.001-003. +%========================================================================== +% Revision history: +% +% +% +%========================================================================== + + +Tp1 = size(Y_T,2) + 1; %T+1; +n_y = size(a,1); +n_z = size(b,1); +%--- Checking input matrix dimensions +if (size(Y_T,1)~=n_y) + error('kalf_tv(): Y_T and a must have the same number of rows') +end +%--- Allocating memory. +zt_tm1 = zeros(n_z,Tp1); +Pt_tm1 = zeros(n_z,n_z,Tp1); +loglh_t_allvalues = zeros(Tp1-1,1); +%--- Initializing. +loglh = 0.0; +if (indxIni) + zt_tm1(:,1) = z0; + Pt_tm1(:,:,1) = P0; +else + eigmax4F = max(abs(eig(F(:,:,1)))); + format long e + eigmax4F + if (eigmax4F < 1.0) + zt_tm1(:,1) = (eye(n_z)-F(:,:,1))\b(:,1); + V1 = V(:,:,1); + Pt_tm1(:,:,1) = reshape((eye(n_z^2)-kron(F(:,:,1),F(:,:,1)))\V1(:) ,n_z,n_z); + else + %--- Do NOT use the following option. It turns out that this will often generate explosive conditional liklihood + %--- at the end of the sample, because Pt_tm1 shrinks to zero overtime due to the sigularity of the initila condition P_{1|0}. + % zt_tm1(:,1) = zeros(size(zt_tm1(:,1))); + % Pt_tm1(:,:,1) = V(:,:,1); %+eye(size(V(:,:,1))); + + nearinfinity = -1.0e+300 + loglh = nearinfinity; + return; %Eearly exit. + %error('kalf_tv(): For non-stationary solutions, the initial conditions must be supplied by, say, input arguments') + end +end + + +%====== See p.002 in LiuWZ. ====== +indx_badlh = 0; %1: bad likelihood with, say, -infinity of the LH value. +for t=2:Tp1 + tdata = t-1; + + %--- Setup. + Htdata = H(:,:,tdata); + Htdatatran = Htdata'; + ztdata = zt_tm1(:,tdata); + Ptdata = Pt_tm1(:,:,tdata); + PHtran_tdata = Ptdata*Htdatatran; + Ft = F(:,:,t); + Fttran = Ft'; + + %--- Data. + etdata = Y_T(:,tdata) - a(:,tdata) - Htdata*ztdata; + etdatatran = etdata'; + Dtdata = Htdata*PHtran_tdata + R(:,:,tdata); + Dtdata = 0.5*(Dtdata + Dtdata'); %Making it symmetric against some rounding errors. + %This making-symmetric is very IMPORTANT; otherwise, we will get the matrix being singular message + % and eigenvalues being negative for the SPD matrix, etc. Then the likelihood becomes either + % a bad number or a complex number. + + %--- State (updating). + Kt_tdata = (Ft*PHtran_tdata+G(:,:,tdata))/Dtdata; + Kt_tdatatran = Kt_tdata'; + zt_tm1(:,t) = b(:,t) + Ft*zt_tm1(:,tdata) + Kt_tdata*etdata; + Pt_tm1(:,:,t) = Ft*Ptdata*Fttran - Kt_tdata*Dtdata*Kt_tdatatran + V(:,:,t); + + %--- Forming the log likelihood. + detDtdata = det(Dtdata); + %if (~isfinite(detDtdata)) + if (detDtdata < realmin) + indx_badlh = 1; + break; + else + loglh_tdata = -(0.5*n_y)*log(2*pi) - 0.5*log(detDtdata) - 0.5*(etdatatran/Dtdata)*etdata; + loglh = loglh + loglh_tdata; + loglh_t_allvalues(tdata) = loglh_tdata; + end +end + +if (indx_badlh) + nearinfinity = -1.0e+300; + loglh = nearinfinity; + loglh_t_allvalues(tdata) = nearinfinity; +end + diff --git a/MatlabFiles/fn_kalfil_tv2.m b/MatlabFiles/fn_kalfil_tv2.m new file mode 100755 index 0000000..d81aa6f --- /dev/null +++ b/MatlabFiles/fn_kalfil_tv2.m @@ -0,0 +1,147 @@ +function [loglh,zt_tm1,Pt_tm1, loglh_t_allvalues] = fn_kalfil_tv(Y_T, a, H, R, G, b, F, V, indxIni, indxDiffuse, z0,P0) +%[loglh,zt_tm1,Pt_tm1, loglh_t_allvalues] = fn_kalfil_tv(Y_T, a, H, R, G, b, F, V, indxIni, indxDiffuse, z0,P0) +%Time-varying Kalman filter (conditional on all the regimes in a Markov-switching model). It computes +% a sequence of one-step predictions and their covariance matrices, and the log likelihood. +% The function uses a forward recursion algorithm. +% +% Note: for b, F, V, zt_tm1, and Pt_tm1, there is not need for the T+1 length because the values at T+1 have +% never been used in the likelihood function. See tz_kalfiltv() in kalman.c for an illustration. +% +% State space model is defined as follows: +% y(t) = a(t) + H(t)*z(t) + eps(t) (observation or measurement equation) +% z(t) = b(t) + F(t)*z(t) + eta(t) (state or transition equation) +% where a(t), H(t), b(t), and F(t) depend on s_t that follows a Markov-chain process and are taken as given. +% +% Inputs are as follows: +% Y_T is a n_y-by-T matrix containing data [y(1), ... , y(T)]. +% a is an n_y-by-T matrix of time-varying input vectors in the measurement equation. +% H is an n_y-by-n_z-by-T 3-D of time-varying matrices in the measurement equation. +% R is an n_y-by-n_y-by-T 3-D of time-varying covariance matrices for the error in the measurement equation. +% G is an n_z-by-n_y-by-T 3-D of time-varying E(eta_t * eps_t'). +% ------ +% b is an n_z-by-(T+1) matrix of time-varying input vectors in the state equation with b(:,1) as an initial condition. +% F is an n_z-by-n_z-by-(T+1) 3-D of time-varying transition matrices in the state equation with F(:,:,1) as an initial condition. +% V is an n_z-by-n_z-by-(T+1) 3-D of time-varying covariance matrices for the error in the state equation with V(:,:,1) as an initial condition. +% ------ +% indxIni: 1: using the initial condition with zt_tm1(:,1)=z0 and Pt_tm1(:,:,1)=P0 +% (thus, indxDiffuse is automatically not enativated).; +% 0: creating the initial condition depending on indxDiffuse (thus, indxDiffuse is active). +% indxDiffuse: 1: using the diffuse initial condition by setting P=100*I and z=0; +% 0: using the unconditional mean and variance for any given regime at time 0. +% z0 is an n_z-by-1 vector of initial condition when indxIni=1. (Do not enter if indxIni=0.) +% P0 is an n_z-by-n_z matrix of initial condition when indxIni=1. (Do not enter if indxIni=0.) +% +% Outputs are as follows: +% loglh is a value of the log likelihood function of the state-space model +% under the assumption that errors are multivariate Gaussian. +% zt_tm1 is an n_z-by-(T+1) matrices of one-step predicted state vectors with z0_0m1 as a initial condition. +% Pt_tm1 is an n_z-by-n_z-by-(T+1) 3-D of covariance matrices of zt_tm1 with P0_0m1 as a initial condition. +% loglh_t_allvalues is a T-by-1 vector of loglh at time t for t=1:T. +% +% The initial state vector and its covariance matrix are computed under the bounded (stationary) condition: +% z0_0m1 = (I-F(:,:,1))\b(:,1) +% vec(P0_0m1) = (I-kron(F(:,:,1),F(:,:,1)))\vec(V(:,:,1)) +% Note that all eigenvalues of the matrix F(:,:,1) are inside the unit circle when the state-space model is bounded (stationary). +% +% March 2007, written by Tao Zha +% See Hamilton's book ([13.2.13] -- [13.2.22]), Harvey (pp.100-106), and LiuWZ Model I NOTES pp.001-003. +%========================================================================== +% Revision history: +% +% +% +%========================================================================== + + +Tp1 = size(Y_T,2) + 1; %T+1; +n_y = size(a,1); +n_z = size(b,1); +%--- Checking input matrix dimensions +if (size(Y_T,1)~=n_y) + error('kalf_tv(): Y_T and a must have the same number of rows') +end +%--- Allocating memory. +zt_tm1 = zeros(n_z,Tp1); +Pt_tm1 = zeros(n_z,n_z,Tp1); +loglh_t_allvalues = zeros(Tp1-1,1); +%--- Initializing. +loglh = 0.0; +if (indxIni) + zt_tm1(:,1) = z0; + Pt_tm1(:,:,1) = P0; +else + if (indxDiffuse) + %See Koopman and Durbin, "Filtering and Smoothing of State Vector for Diffuse State-Space Models," J. of Time Series Analysis, Vol 24(1), pp.85-99. + zt_tm1(:,1) = zeros(n_z, 1); + Pt_tm1(:,:,1) = 100*eye(n_z); + else + eigmax4F = max(abs(eig(F(:,:,1)))); + format long e + eigmax4F + if (eigmax4F < 1.0) + zt_tm1(:,1) = (eye(n_z)-F(:,:,1))\b(:,1); + V1 = V(:,:,1); + Pt_tm1(:,:,1) = reshape((eye(n_z^2)-kron(F(:,:,1),F(:,:,1)))\V1(:) ,n_z,n_z); + else + %--- Do NOT use the following option. It turns out that this will often generate explosive conditional liklihood + %--- at the end of the sample, because Pt_tm1 shrinks to zero overtime due to the sigularity of the initila condition P_{1|0}. + % zt_tm1(:,1) = zeros(size(zt_tm1(:,1))); + % Pt_tm1(:,:,1) = V(:,:,1); %+eye(size(V(:,:,1))); + + nearinfinity = -1.0e+300 + loglh = nearinfinity; + return; %Eearly exit. + %error('kalf_tv(): For non-stationary solutions, the initial conditions must be supplied by, say, input arguments') + end + end +end + + +%====== See p.002 in LiuWZ. ====== +indx_badlh = 0; %1: bad likelihood with, say, -infinity of the LH value. +for t=2:Tp1 + tdata = t-1; + + %--- Setup. + Htdata = H(:,:,tdata); + Htdatatran = Htdata'; + ztdata = zt_tm1(:,tdata); + Ptdata = Pt_tm1(:,:,tdata); + PHtran_tdata = Ptdata*Htdatatran; + Ft = F(:,:,t); + Fttran = Ft'; + + %--- Data. + etdata = Y_T(:,tdata) - a(:,tdata) - Htdata*ztdata; + etdatatran = etdata'; + Dtdata = Htdata*PHtran_tdata + R(:,:,tdata); + Dtdata = 0.5*(Dtdata + Dtdata'); %Making it symmetric against some rounding errors. + %This making-symmetric is very IMPORTANT; otherwise, we will get the matrix being singular message + % and eigenvalues being negative for the SPD matrix, etc. Then the likelihood becomes either + % a bad number or a complex number. + + %--- State (updating). + Kt_tdata = (Ft*PHtran_tdata+G(:,:,tdata))/Dtdata; + Kt_tdatatran = Kt_tdata'; + zt_tm1(:,t) = b(:,t) + Ft*zt_tm1(:,tdata) + Kt_tdata*etdata; + Pt_tm1(:,:,t) = Ft*Ptdata*Fttran - Kt_tdata*Dtdata*Kt_tdatatran + V(:,:,t); + + %--- Forming the log likelihood. + detDtdata = det(Dtdata); + %if (~isfinite(detDtdata)) + if (detDtdata < realmin) + indx_badlh = 1; + break; + else + loglh_tdata = -(0.5*n_y)*log(2*pi) - 0.5*log(detDtdata) - 0.5*(etdatatran/Dtdata)*etdata; + loglh = loglh + loglh_tdata; + loglh_t_allvalues(tdata) = loglh_tdata; + end +end + +if (indx_badlh) + nearinfinity = -1.0e+300; + loglh = nearinfinity; + loglh_t_allvalues(tdata) = nearinfinity; +end + diff --git a/MatlabFiles/fn_logsum.m b/MatlabFiles/fn_logsum.m new file mode 100755 index 0000000..e640b94 --- /dev/null +++ b/MatlabFiles/fn_logsum.m @@ -0,0 +1,21 @@ +function [log_sum, log_max] = fn_logsum(log_sum, log_max, log_new) +% [log_sum, log_max] = fn_logsum(log_sum, log_max, log_new) +% +%Outputs: +% log_sum: updated log(sum of x_1, ..., x_{N+1}) +% log_max: updated max of log(x_1), ..., log(x_{N+1}). +%-------------- +%Inputs: +% log_sum: log(sum of x_1, ..., x_N) +% log_max: max of log(x_1), ..., log(x_N). +% log_new: log(x_{N+1}). +% +%Written by T. Zha; 12:20PM 06/28/2005 + +%=== Updates log_sumpdf with an additional pdf value. See TVBVAR Notes p.81a. +if (log_max>=log_new) + log_sum = log( exp(log_sum-log_max) + exp(log_new-log_max) ) + log_max; +else + log_sum = log( exp(log_sum-log_new) + 1.0 ) + log_new; + log_max = log_new; +end diff --git a/MatlabFiles/fn_mimfgraph.m b/MatlabFiles/fn_mimfgraph.m new file mode 100755 index 0000000..9a97509 --- /dev/null +++ b/MatlabFiles/fn_mimfgraph.m @@ -0,0 +1,135 @@ +function scaleout = fn_mimfgraph(imfe,nvar,q_m,imstp,xlab,ylab,tlab,xTick) +% mimfgraph: multiple impulse functions plotted in subplots put in one chart. +% +% imfe: imstp-by-n^2+2-by-h series data with dates in the first 2 columns in the order of year and month (or quarter). +% imstp: the number of impulse response steps. +% nvar^2+2: n series plus the first 2 columns indicating dates. For the last nvar^2 columns, +% the order is: nvar responses to the 1st shock, ..., nvar responses to the last shock. +% h: The number of sereies on the 3rd dimension, put in the same subplot as in each of the n series. +% The first 2 columns in the 3rd dimension can be NaN while some other columns +% are also allowed to be NaN if no data are available. +% The last 2 columns in the 3rd dimension must be used for error bands if "area" +% is used to plot these bands. +% nvar: number of variables +% q_m: monthly (12) or quarterly (4) +% imstp: number of steps of impulse responses +% xlab,ylab,tlab: x-axis, y-axis, and title labels +% xTick: optional. Eg: [12 24 36]. +%--------------- +% scaleout: column 1 represents maximums; column 2 minimums. Rows: nvar variables. +% +% See ftd_mseriesgraph.m and fn_mseriesgraph.m + +if nargin < 7, xTick = []; end + +if nvar^2~=size(imfe,2)-2 + disp(' ') + warning('The number of columns in imfe must be nvar^2+2 (columns of dates)') + disp('Press ctrl-c to abort') + pause +end + + + +t = 1:imstp; +temp1=zeros(nvar,1); +temp2=zeros(nvar,1); +minval=zeros(nvar,1); % for each variable to nvar shocks +maxval=zeros(nvar,1); % for each variable to nvar shocks +for i = 1:nvar % variable + for j = 1:nvar % shock + tmpimf = squeeze(imfe(:,2+(j-1)*nvar+i,:)); + temp1(j) = min(min(tmpimf)); + temp2(j) = max(max(tmpimf)); + end + minval(i)=min(temp1); + maxval(i)=max(temp2); +end + +scaleout = [minval(:) maxval(:)]; + +%-------------- +% Column j: Shocks 1 to N; Row i: Variable responses to +%------------- + +rowlabel = 1; +for i = 1:nvar % variable + columnlabel = 1; + + if minval(i)<0 + if maxval(i)<=0 + yt=[minval(i) 0]; + else + yt=[minval(i) 0 maxval(i)]; + end + else % (minval(i) >=0) + if maxval(i) > 0 + yt=[0 maxval(i)]; + else % (identically zero responses) + yt=[-1 0 1]; + end + end + + scale=[1 imstp minval(i) maxval(i)]; + for j = 1:nvar % shock + k1=(i-1)*nvar+j; + k2=(j-1)*nvar+i; + subplot(nvar,nvar,k1) + if 0 % Plot area for error bands at the last two 3-rd dimensions. + area(imfe(:,1)+imfe(:,2)/q_m,squeeze(imfe(:,2+k2,end)),-100,'EdgeColor','none','FaceColor','y') % yellow + hold on + area(imfe(:,1)+imfe(:,2)/q_m,squeeze(imfe(:,2+k2,end-1)),-100,'EdgeColor','none','FaceColor',[1 1 1]) % white + set(gca,'ColorOrder',[0 0 0]); % turn the color off and set it to black + set(gca,'LineStyleOrder', '-|-.|--|:'); % cycle through the newly defined LineSytleOrder + plot(t,squeeze(imfe(:,2+k2,1:end-2)),t,zeros(length(imfe(:,k2)),1),'-'); + set(gca,'Layer','top') + hold off + else % No error bands plotted + %=== set color to black and cycle through the newly defined LineSytleOrder + set(0,'DefaultAxesColorOrder',[0 0 0], ... + 'DefaultAxesLineStyleOrder','-|-.|--|:') + %set(gca,'ColorOrder',[0 0 0]); % turn the color off and set it to black + %set(gca,'LineStyleOrder', '-|-.|--|:'); % cycle through the newly defined LineSytleOrder + plot(t,squeeze(imfe(:,2+k2,1:end)),t,zeros(length(imfe(:,k2)),1),'-'); + end + if 1 % Get legends + if (i==2) & (j==3) % | (i==6) + legend('Const','S1','S2','S3',0) + % legend('Actual Data','Absent policy shocks',0) + end + end + + set(gca,'XTick',xTick) + set(gca,'YTick',yt) + grid + + axis(scale); % put limits on both axes. + %set(gca,'YLim',[minval(i) maxval(i)]) % put the limit only on the y-axis + if isempty(xTick) %1 % no numbers on axes + set(gca,'XTickLabel',' '); + set(gca,'YTickLabel',' '); + else % put numbers on both axes + if i<nvar + set(gca,'XTickLabelMode','manual','XTickLabel',[]) + end + if j>1 + set(gca,'YTickLabel',' '); + end + end + + if rowlabel == 1 + %title(['x' num2str(j)]) + %title(eval(['x' num2str(j)])) + title(char(xlab(j))) + end + if columnlabel == 1 + %ylabel(['x' num2str(i)]) + %ylabel(eval(['x' num2str(i)])) + ylabel(char(ylab(i))) + end + columnlabel = 0; + end + rowlabel = 0; +end + +subtitle(tlab) diff --git a/MatlabFiles/fn_mseriesgraph.m b/MatlabFiles/fn_mseriesgraph.m new file mode 100755 index 0000000..10afa65 --- /dev/null +++ b/MatlabFiles/fn_mseriesgraph.m @@ -0,0 +1,66 @@ +function fn_mseriesgraph(ydate,keyindx,rnum,cnum,q_m,xlab,ylab,tlab) +% fn_mseriesgraph(ydate,keyindx,rnum,cnum,q_m,xlab,ylab,tlab) +% Graph actual series or point forecasts or both (annual or monthly or quarterly) +% with multiple series in one subplot. +% +% ydate: T-by-n+2-by-h series data with dates in the first 2 columns in the order of year and month (or quarter). +% T: the length of an individual series. +% n+2: n series plus the first 2 columns indicating dates. +% h: the number of sereies on the 3rd dimension, put in the same subplot as in each of the n series. +% Thus, the first 2 columns in the 3rd dimension can be NaN while +% some elements are also allowed to be NaN if no data are available. +% keyindx: index for the variables to be graphed +% rnum: number of rows in subplot +% cnum: number of columns in subplot +% q_m: if 4 or 12, quarterly or monthly data +% xlab: 1-by-1 x-axis label for what conditions imposed; e.g., conlab = 'All bar MS shocks inspl' +% ylab: string array for the length(keyindx)-by-1 variables +% tlab: 1-by-1 title label for (e.g., as of time of forecast) +%------------- +% No output argument for this graph file +% See fn_foregraph.m, fn_forerrgraph.m. +% +% Tao Zha, September 2000 + +vyrs = ydate(:,1); % vector column +hornum = cell(length(vyrs),1); % horizontal year (number) +count=0; +for k=vyrs' + count=count+1; + jnk=num2str(k); + if length(jnk)==4 % years + hornum{count}=jnk(3:4); % e.g., with '1990', we have '90' + else + hornum{count}=jnk; % e.g., with '1', '2', ... + end +end + +if rnum*cnum<length(keyindx) + disp(' ') + warning('The total number of subplots must be greater that the number of selected series for graphing!') + disp('Press ctrl-c to abort') + pause +end + +count=0; +for i = keyindx + count = count+1; + subplot(rnum,cnum,count) + plot(ydate(:,1)+ydate(:,2)/q_m,squeeze(ydate(:,2+i,:)),... + ydate(:,1)+ydate(:,2)/q_m,zeros(length(vyrs),1),'-') + + if (ydate(1,2)==0) & (length(num2str(ydate(1,1)))==4) % only for annual growth rates (not for, say, monthly annualized rates) + set(gca,'XLim',[vyrs(1) vyrs(end)]) + set(gca,'XTick',vyrs) + set(gca,'XTickLabel',char(hornum)) + end + + if i==keyindx(1) + title(tlab) + elseif i>=length(keyindx) %i>=length(keyindx)-1 + xlabel(xlab) + end + % + grid + ylabel(char(ylab(i))) +end diff --git a/MatlabFiles/fn_msv_sw.m b/MatlabFiles/fn_msv_sw.m new file mode 100755 index 0000000..aa6c0ca --- /dev/null +++ b/MatlabFiles/fn_msv_sw.m @@ -0,0 +1,62 @@ +function [G1cell_sw, err] = fn_msv_sw(G1cell_0, A11cell, A12cell, A21cell, A22cell, Hcell, P) +%G1cell_sw = fn_msv_sw(G1cell_0, A11cell, A12cell, A21cell, A22cell, Hcell,P) +% +% Model: X_{t+1} = A11_{t+1} X_t + A12_{t+1} x_t + C_{t+1} episilon_{t+1} +% E_t(H_{t+1} x_{t+1}) = A21_t X_t + A22_t x_t +% Solution: x_t = G1_t X_t where G1_t is nx-by-nX. +% +%Output: +% G1cell_sw: solution. +% err: if the value > sqrt(eps), then not converged ==> no solution. +%Inputs: +% G1cell_0: initial guess (starting point) for the Svensson-William algorithm. +% If G1cell_0 is empty, G1_0 will be randomly selected. +% A11cell, A12cell, A21cell, A22cell, and Hcell are all ns-by-1 cells -- the model coefficients depending on regime. +% In each cell, the dimensions must be +% A11=zeros(nX,nX); A12=zeros(nX,nx); +% A21=zeros(nx,nX); A22=zeros(nx,nx); +% H=diag(ones(nx,1)); +% P: ns-by-ns transition matrix with each column summing up to 1. +% +% See ZhaNotes on FWZ MSV solution, p. AA.1. For the SW solution, see (7) on p. AA.1. + +%--- Convergence criteria +tol = 1.0e-09; +maxiter = 1e+04; + +%--- Dimensions. +ns = length(A11cell); %number of states (regimes) +nX = size(A11cell{1},1); +nx = size(A22cell{1},1); + +%--- Initialization. +if isempty(G1cell_0) + G1cell_0 = cell(ns,1); + for si=1:ns + G1cell_0{si} = 1000.0*randn(nx,nX); + end +end + +%====== Iterative procedure. ====== +Gerr = zeros(ns,1); +err = 1.0; +iter = 1; +while ( (iter<maxiter) && (err>tol) ) + for j=1:ns + M1 = zeros(nx,nx); + M2 = zeros(nx,nX); + for k=1:ns + HGk = Hcell{k}*G1cell_0{k}; + M1 = M1 + P(k,j)*HGk*A12cell{k}; + M2 = M2 + P(k,j)*HGk*A11cell{k}; + end % k loop + Mden = A22cell{j} - M1; + Mnum = M2 - A21cell{j}; + G1cell_sw{j} = Mden\Mnum; + Gerr(j)=norm(G1cell_sw{j} - G1cell_0{j}); + G1cell_0{j} = G1cell_sw{j}; % Updated for the next iteration. + end %j loop + err=sum(Gerr); + iter=iter+1; +end % err loop + diff --git a/MatlabFiles/fn_mtpdf.m b/MatlabFiles/fn_mtpdf.m new file mode 100755 index 0000000..289330d --- /dev/null +++ b/MatlabFiles/fn_mtpdf.m @@ -0,0 +1,38 @@ +function y = fn_mtpdf(x,xm,C,v,covIx,constIx) +% y = mtpdf(x,xm,C,v,covIx,constIx) +% The pdf value for multivariate Student t distribution allowing many values (draws) stored in columns. +% +% x: p-by-draws matrix of values evaluated at where p=size(x,1) is # of variables +% xm: p-by-draws matrix of the mean of x +% C: p-by-p Choleski square root of PDS S, which is the covariance matrix in the normal case +% so that S = C*C'. That is, C=chol(S)' (notice the transpose ' here). +% v (>0): A scalar value for the degrees of freedom. +% covIx: An index for a decomposition of the covariance matrix. If 1, C=chol(S)' (notice the transpose '); +% if 0, C=chol(inv(S)) (note that there is no transpose here). +% constIx: An index for the constant. 1: constant (normalized); 0: no constant (unnormalized) +%---------- +% y: p-by-draws matrix of pdf's for multivariate Student t distribution with v degrees of freedom +% +% Christian P. Robert, "The Bayesian Choice," Springer-Verlag, New York, 1994, +% p. 382. +% +% Tao Zha, December 1998; Revised, January 2002. + +[p,nx]=size(x); +if covIx + z = C\(x-xm); +else + z = C*(x-xm); +end + + +if constIx + dSh=sum(log(diag(C))); % (detSigma)^(1/2) + %* Use gammaln function to avoid overflows. + term = exp(gammaln((v + p) / 2) - gammaln(v/2) - dSh); + y = (term*(v*pi)^(-p/2)) * (1 + sum(z.*z,1)/v).^(-(v + p)/2); + y = y'; +else + y = (1 + sum(z.*z,1)/v).^(-(v + p)/2); + y = y'; +end diff --git a/MatlabFiles/fn_multigraph1.m b/MatlabFiles/fn_multigraph1.m new file mode 100755 index 0000000..cd75900 --- /dev/null +++ b/MatlabFiles/fn_multigraph1.m @@ -0,0 +1,109 @@ +function scaleout = fn_multigraph1(imf1,nrow,ncol,xlab,ylab,XTick,YTickIndx,scaleIndx) +%Plot only one set of impulse responses in one graph. See fn_multigraph2.m. +%imf1 -- each has 3 dimensions. Row: horizon; column: 'nrow' variables; 3rd dim: 'ncol' situations such as regimes 1 and 2. +% imf: row: "nstp" time horizon (in the graphics), column: "nrow "variables (row in +% the graphics), 3rd D: across "ncol" different situations (column in +% the graphics) +% nrow: # of rows for the graphics +% ncol: # of columns for the graphics +% YTickIndx: 1: enable YTick; 0: disable +% scaleIndx: 1: enable scale along Y-axis; 0: disable +% +% See imrgraph, imcerrgraph, imrerrgraph +nstp = size(imf1,1); +t = 1:nstp; +nrow; +ncol; + +temp1=zeros(ncol,1); +temp2=zeros(ncol,1); +maxval=zeros(nrow,1); +minval=zeros(nrow,1); +for i = 1:nrow + for j = 1:ncol + %jnk1=max(firsth(:,i,j)); + %jnk2=max(firstl(:,i,j)); + %jnk3=max(firsth1(:,i,j)); + %jnk4=max(imf2(:,i,j)); + jnk5=max(imf1(:,i,j)); + + temp1(j)=max([jnk5]); + % + %jnk1=min(firstl(:,i,j)); + %jnk2=min(firsth(:,i,j)); + %jnk3=min(firstl1(:,i,j)); + %jnk4=min(imf2(:,i,j)); + jnk5=min(imf1(:,i,j)); + + temp2(j)=min([jnk5]); + end + maxval(i)=max(temp1); + minval(i)=min(temp2); +end + +scaleout = [maxval(:) minval(:)]; + +%-------------- +% Column j: situation 1 to N; Row i: variables (ie responses to) +%------------- +%figure +rowlabel = 1; +for i = 1:nrow % column: from top to bottom + columnlabel = 1; + + if minval(i)<0 + if maxval(i)<=0 + yt=[minval(i) 0]; + else + yt=[minval(i) 0 maxval(i)]; + end + else % (minval(i) >=0) + if maxval(i) > 0 + yt=[0 maxval(i)]; + else % (identically zero responses) + yt=[-1 0 1]; + end + end + + + scale=[1 nstp minval(i) maxval(i)]; + for j = 1:ncol % row: from left to right + k1=(i-1)*ncol+j; + subplot(nrow,ncol,k1) + plot(t,imf1(:,i,j)) %,t,imf2(:,i,j),'--') + %t,[firstl(:,i,j) firsth(:,i,j)],':'); + grid; + if scaleIndx + axis(scale); + end + %set(gca,'YLim',[minval(i) maxval(i)]) + % + set(gca,'XTick',XTick) + if YTickIndx + set(gca,'YTick',yt) + end + + if i<nrow + set(gca,'XTickLabelMode','manual','XTickLabel',[]) + end + %set(gca,'XTickLabel',' '); + if j>1 + set(gca,'YTickLabel',' '); + end + if rowlabel == 1 + %title(['x' num2str(j)]) + %title(eval(['x' num2str(j)])) + title(char(xlab(j))) + end + if columnlabel == 1 + %ylabel(['x' num2str(i)]) + %ylabel(eval(['x' num2str(i)])) + ylabel(char(ylab(i))) + end + if i==nrow + xlabel('Quarters') + end + columnlabel = 0; + end + rowlabel = 0; +end diff --git a/MatlabFiles/fn_multigraph1_ver2.m b/MatlabFiles/fn_multigraph1_ver2.m new file mode 100755 index 0000000..d17c480 --- /dev/null +++ b/MatlabFiles/fn_multigraph1_ver2.m @@ -0,0 +1,122 @@ +function scaleout = fn_multigraph1_ver2(imf1,xlab,ylab,tstring,XTick,YTickIndx,scaleIndx,nrowg,ncolg) +%scaleout = fn_multigraph1_ver2(imf1,xlab,ylab,tstring,XTick,YTickIndx,scaleIndx,nrowg,ncolg) +% +% Version 2 for plotting only one set of impulse responses in one graph. See fn_multigraph2.m. +% imf1 -- each has 3 dimensions. Row: horizon; column: 'nrow' variables; 3rd dim: 'ncol' situations such as shocks or regimes. +% imf1: row: "nstp" time horizon (in the graphics), column: "nrow "variables (row in +% the graphics), 3rd D: across "ncol" different situations such as shocks or regimes (column in the graphics) +% xlab: x-axis labels on the top +% ylab: y-axis labels on the left +% tstring: string for time (e.g., month or quarter) -- x-axis labels at the bottom +% YTickIndx: 1: enable YTick; 0: disable; +% To get a better picture, it is sometimes better to set YtickIndx to zero. +% scaleIndx: 1: enable scale along Y-axis; 0: disable +% nrowg: number of rows in the graph +% ncolg: number of columns in the graph +% +% See imrgraph, imcerrgraph, imrerrgraph +nstp = size(imf1,1); +nrow = size(imf1,2); +ncol = size(imf1,3); +t = 1:nstp; + +if (nargin < 8) + nrowg = nrow; + ncolg = ncol; +end +if (nrowg*ncolg < nrow*ncol) + error('fn_multigraph1_ver2.m: nrowg*ncolg must equal to or less than nrow*ncol') +end + +temp1=zeros(ncol,1); +temp2=zeros(ncol,1); +maxval=zeros(nrow,1); +minval=zeros(nrow,1); +for i = 1:nrow + for j = 1:ncol + %jnk1=max(firsth(:,i,j)); + %jnk2=max(firstl(:,i,j)); + %jnk3=max(firsth1(:,i,j)); + %jnk4=max(imf2(:,i,j)); + jnk5=max(imf1(:,i,j)); + + temp1(j)=max([jnk5]); + % + %jnk1=min(firstl(:,i,j)); + %jnk2=min(firsth(:,i,j)); + %jnk3=min(firstl1(:,i,j)); + %jnk4=min(imf2(:,i,j)); + jnk5=min(imf1(:,i,j)); + + temp2(j)=min([jnk5]); + end + maxval(i)=max(temp1); + minval(i)=min(temp2); +end + +scaleout = [maxval(:) minval(:)]; + +%-------------- +% Column j: situation 1 to N; Row i: variables (ie responses to) +%------------- +%figure +rowlabel = 1; +for i = 1:nrow % column: from top to bottom + columnlabel = 1; + + if minval(i)<0 + if maxval(i)<=0 + yt=[minval(i) 0]; + else + yt=[minval(i) 0 maxval(i)]; + end + else % (minval(i) >=0) + if maxval(i) > 0 + yt=[0 maxval(i)]; + else % (identically zero responses) + yt=[-1 0 1]; + end + end + + + scale=[1 nstp minval(i) maxval(i)]; + for j = 1:ncol % row: from left to right + k1=(i-1)*ncol+j; + subplot(nrowg,ncolg,k1) + plot(t,imf1(:,i,j)) %,t,imf2(:,i,j),'--') + %t,[firstl(:,i,j) firsth(:,i,j)],':'); + grid; + if scaleIndx + axis(scale); + end + %set(gca,'YLim',[minval(i) maxval(i)]) + % + set(gca,'XTick',XTick) + if YTickIndx + set(gca,'YTick',yt) + end + + if i<nrow + set(gca,'XTickLabelMode','manual','XTickLabel',[]) + end + %set(gca,'XTickLabel',' '); + if (scaleIndx) && (j>1) + set(gca,'YTickLabel',' '); + end + if rowlabel == 1 + %title(['x' num2str(j)]) + %title(eval(['x' num2str(j)])) + title(char(xlab(j))) + end + if columnlabel == 1 + %ylabel(['x' num2str(i)]) + %ylabel(eval(['x' num2str(i)])) + ylabel(char(ylab(i))) + end + if i==nrow + xlabel(tstring) + end + columnlabel = 0; + end + rowlabel = 0; +end diff --git a/MatlabFiles/fn_multigraph1_ver2_all_labels.m b/MatlabFiles/fn_multigraph1_ver2_all_labels.m new file mode 100755 index 0000000..8fe25c3 --- /dev/null +++ b/MatlabFiles/fn_multigraph1_ver2_all_labels.m @@ -0,0 +1,127 @@ +function scaleout = fn_multigraph1_ver2_all_labels(imf1,xlab,ylab,tstring,XTick,YTickIndx,scaleIndx,nrowg,ncolg) +%scaleout = fn_multigraph1_ver2_all_labels(imf1,xlab,ylab,tstring,XTick,YTickIndx,scaleIndx,nrowg,ncolg) +% +% Version 2 for plotting only one set of impulse responses in one graph. See fn_multigraph1_ver2. +% imf1 -- each has 3 dimensions. Row: horizon; column: 'nrow' variables; 3rd dim: 'ncol' situations such as shocks or regimes. +% imf1: row: "nstp" time horizon (in the graphics), column: "nrow "variables (row in +% the graphics), 3rd D: across "ncol" different situations such as shocks or regimes (column in the graphics) +% xlab: x-axis labels on the top. Use [] if no label is needed. +% ylab: y-axis labels on the left. Use [] if no label is needed. +% tstring: string for time (e.g., month or quarter) -- x-axis labels at the bottom. Use [] if no label is needed. +% YTickIndx: 1: enable YTick; 0: disable. Often set to zero to get a better picture. +% scaleIndx: 1: enable scale along Y-axis; 0: disable +% nrowg: number of rows in the graph +% ncolg: number of columns in the graph +% +% See fn_multigraph1_ver2, imrgraph, imcerrgraph, imrerrgraph +nstp = size(imf1,1); +nrow = size(imf1,2); +ncol = size(imf1,3); +t = 1:nstp; + +if (nargin < 8) + nrowg = nrow; + ncolg = ncol; +end +if (nrowg*ncolg < nrow*ncol) + error('fn_multigraph1_ver2.m: nrowg*ncolg must equal to or greater than nrow*ncol') +end + +temp1=zeros(ncol,1); +temp2=zeros(ncol,1); +maxval=zeros(nrow,1); +minval=zeros(nrow,1); +for i = 1:nrow + for j = 1:ncol + %jnk1=max(firsth(:,i,j)); + %jnk2=max(firstl(:,i,j)); + %jnk3=max(firsth1(:,i,j)); + %jnk4=max(imf2(:,i,j)); + jnk5=max(imf1(:,i,j)); + + temp1(j)=max([jnk5]); + % + %jnk1=min(firstl(:,i,j)); + %jnk2=min(firsth(:,i,j)); + %jnk3=min(firstl1(:,i,j)); + %jnk4=min(imf2(:,i,j)); + jnk5=min(imf1(:,i,j)); + + temp2(j)=min([jnk5]); + end + maxval(i)=max(temp1); + minval(i)=min(temp2); +end + +scaleout = [maxval(:) minval(:)]; + +%-------------- +% Column j: situation 1 to N; Row i: variables (ie responses to) +%------------- +%figure +rowlabel = 1; +for i = 1:nrow % column: from top to bottom + columnlabel = 1; + + if minval(i)<0 + if maxval(i)<=0 + yt=[minval(i) 0]; + else + yt=[minval(i) 0 maxval(i)]; + end + else % (minval(i) >=0) + if maxval(i) > 0 + yt=[0 maxval(i)]; + else % (identically zero responses) + yt=[-1 0 1]; + end + end + + + scale=[1 nstp minval(i) maxval(i)]; + for j = 1:ncol % row: from left to right + k1=(i-1)*ncol+j; + subplot(nrowg,ncolg,k1) + plot(t,imf1(:,i,j)) %,t,imf2(:,i,j),'--') + %t,[firstl(:,i,j) firsth(:,i,j)],':'); + grid; + if scaleIndx + axis(scale); + end + %set(gca,'YLim',[minval(i) maxval(i)]) + % + set(gca,'XTick',XTick) + if YTickIndx + set(gca,'YTick',yt) + end + + % if i<nrow + % set(gca,'XTickLabelMode','manual','XTickLabel',[]) + % end + %set(gca,'XTickLabel',' '); + if (scaleIndx) && (j>1) + set(gca,'YTickLabel',' '); + end + %if rowlabel == 1 + % %title(['x' num2str(j)]) + % %title(eval(['x' num2str(j)])) + % title(char(xlab(j))) + %end + if (~isempty(xlab)) + title(char(xlab(i))) + end + %if columnlabel == 1 + % %ylabel(['x' num2str(i)]) + % %ylabel(eval(['x' num2str(i)])) + % ylabel(char(ylab(i))) + %end + if (~isempty(ylab)) + ylabel(char(ylab(i))) + end + if (i==nrow) && (~isempty(tstring)) + xlabel(tstring) + end + columnlabel = 0; + end + rowlabel = 0; +end diff --git a/MatlabFiles/fn_multigraph2.m b/MatlabFiles/fn_multigraph2.m new file mode 100755 index 0000000..4c2d574 --- /dev/null +++ b/MatlabFiles/fn_multigraph2.m @@ -0,0 +1,109 @@ +function scaleout = fn_multigraph2(imf1,imf2,... + nrow,ncol,nstp,xlab,ylab,XTick,YTickIndx,scaleIndx) +%Stacking two sets of impulse responses in one graph. See fn_multigraph1.m. +%imf1, imf2 -- each has 3 dimensions. Row: horizon; column: 'nrow' variables; 3rd dim: 'ncol' situations such as regimes 1 and 2. +% imf: row: "nstp" time horizon (in the graphics), column: "nrow "variables (row in +% the graphics), 3rd D: across "ncol" different situations (column in +% the graphics) +% nrow: # of rows for the graphics +% ncol: # of columns for the graphics +% YTickIndx: 1: enable YTick; 0: disable +% scaleIndx: 1: enable scale along Y-axis; 0: disable +% +% See imrgraph, imcerrgraph, imrerrgraph +t = 1:nstp; +nrow +ncol + +temp1=zeros(ncol,1); +temp2=zeros(ncol,1); +maxval=zeros(nrow,1); +minval=zeros(nrow,1); +for i = 1:nrow + for j = 1:ncol + %jnk1=max(firsth(:,i,j)); + %jnk2=max(firstl(:,i,j)); + %jnk3=max(firsth1(:,i,j)); + jnk4=max(imf2(:,i,j)); + jnk5=max(imf1(:,i,j)); + + temp1(j)=max([jnk4 jnk5]); + % + %jnk1=min(firstl(:,i,j)); + %jnk2=min(firsth(:,i,j)); + %jnk3=min(firstl1(:,i,j)); + jnk4=min(imf2(:,i,j)); + jnk5=min(imf1(:,i,j)); + + temp2(j)=min([jnk4 jnk5]); + end + maxval(i)=max(temp1); + minval(i)=min(temp2); +end + +scaleout = [maxval(:) minval(:)]; + +%-------------- +% Column j: Shock 1 to N; Row i: Responses to +%------------- +figure +rowlabel = 1; +for i = 1:nrow % column: from top to bottom + columnlabel = 1; + + if minval(i)<0 + if maxval(i)<=0 + yt=[minval(i) 0]; + else + yt=[minval(i) 0 maxval(i)]; + end + else % (minval(i) >=0) + if maxval(i) > 0 + yt=[0 maxval(i)]; + else % (identically zero responses) + yt=[-1 0 1]; + end + end + + + scale=[1 nstp minval(i) maxval(i)]; + for j = 1:ncol % row: from left to right + k1=(i-1)*ncol+j; + subplot(nrow,ncol,k1) + plot(t,imf1(:,i,j),t,imf2(:,i,j),'--') + %t,[firstl(:,i,j) firsth(:,i,j)],':'); + grid; + if scaleIndx + axis(scale); + end + %set(gca,'YLim',[minval(i) maxval(i)]) + % + set(gca,'XTick',XTick) + if YTickIndx + set(gca,'YTick',yt) + end + + if i<nrow + set(gca,'XTickLabelMode','manual','XTickLabel',[]) + end + %set(gca,'XTickLabel',' '); + if j>1 + set(gca,'YTickLabel',' '); + end + if rowlabel == 1 + %title(['x' num2str(j)]) + %title(eval(['x' num2str(j)])) + title(char(xlab(j))) + end + if columnlabel == 1 + %ylabel(['x' num2str(i)]) + %ylabel(eval(['x' num2str(i)])) + ylabel(char(ylab(i))) + end + if i==nrow + xlabel('Quarters') + end + columnlabel = 0; + end + rowlabel = 0; +end diff --git a/MatlabFiles/fn_multigraph2_ver2.m b/MatlabFiles/fn_multigraph2_ver2.m new file mode 100755 index 0000000..9c2d765 --- /dev/null +++ b/MatlabFiles/fn_multigraph2_ver2.m @@ -0,0 +1,122 @@ +function scaleout = fn_multigraph2(imf1,imf2,... + xlab,ylab,tstring,XTick,YTickIndx,scaleIndx,nrowg,ncolg) +%Stacking two sets of impulse responses in one graph. See fn_multigraph1_ver2.m. +%imf1, imf2 -- each has 3 dimensions. Row: horizon; column: 'nrow' variables; 3rd dim: 'ncol' situations such as shocks or regimes. +% imf#: row: "nstp" time horizon (in the graphics), column: "nrow "variables (row in +% the graphics), 3rd D: across "ncol" different situations (column in the graphics) +% xlab: x-axis labels on the top +% ylab: y-axis labels on the left +% tstring: string for time (e.g., month or quarter) -- x-axis labels at the bottom +% YTickIndx: 1: enable YTick; 0: disable; +% To get a better picture, it is sometimes better to set YtickIndx to zero. +% scaleIndx: 1: enable scale along Y-axis; 0: disable +% nrowg: number of rows in the graph +% ncolg: number of columns in the graph +% +% See imrgraph, imcerrgraph, imrerrgraph +nstp = size(imf1,1); +nrow = size(imf1,2); +ncol = size(imf1,3); +t = 1:nstp; + +if (nargin < 9) + nrowg = nrow; + ncolg = ncol; +end +if (nrowg*ncolg ~= nrow*ncol) + error('fn_multigraph2_ver2.m: nrowg*ncolg must equal nrow*ncol') +end + + +temp1=zeros(ncol,1); +temp2=zeros(ncol,1); +maxval=zeros(nrow,1); +minval=zeros(nrow,1); +for i = 1:nrow + for j = 1:ncol + %jnk1=max(firsth(:,i,j)); + %jnk2=max(firstl(:,i,j)); + %jnk3=max(firsth1(:,i,j)); + jnk4=max(imf2(:,i,j)); + jnk5=max(imf1(:,i,j)); + + temp1(j)=max([jnk4 jnk5]); + % + %jnk1=min(firstl(:,i,j)); + %jnk2=min(firsth(:,i,j)); + %jnk3=min(firstl1(:,i,j)); + jnk4=min(imf2(:,i,j)); + jnk5=min(imf1(:,i,j)); + + temp2(j)=min([jnk4 jnk5]); + end + maxval(i)=max(temp1); + minval(i)=min(temp2); +end + +scaleout = [maxval(:) minval(:)]; + +%-------------- +% Column j: Shock 1 to N; Row i: Responses to +%------------- +%figure +rowlabel = 1; +for i = 1:nrow % column: from top to bottom + columnlabel = 1; + + if minval(i)<0 + if maxval(i)<=0 + yt=[minval(i) 0]; + else + yt=[minval(i) 0 maxval(i)]; + end + else % (minval(i) >=0) + if maxval(i) > 0 + yt=[0 maxval(i)]; + else % (identically zero responses) + yt=[-1 0 1]; + end + end + + + scale=[1 nstp minval(i) maxval(i)]; + for j = 1:ncol % row: from left to right + k1=(i-1)*ncol+j; + subplot(nrowg,ncolg,k1) + plot(t,imf1(:,i,j),t,imf2(:,i,j),'--') + %t,[firstl(:,i,j) firsth(:,i,j)],':'); + grid; + if scaleIndx + axis(scale); + end + %set(gca,'YLim',[minval(i) maxval(i)]) + % + set(gca,'XTick',XTick) + if YTickIndx + set(gca,'YTick',yt) + end + + if i<nrow + set(gca,'XTickLabelMode','manual','XTickLabel',[]) + end + %set(gca,'XTickLabel',' '); + if (scaleIndx) && (j>1) + set(gca,'YTickLabel',' '); + end + if rowlabel == 1 + %title(['x' num2str(j)]) + %title(eval(['x' num2str(j)])) + title(char(xlab(j))) + end + if columnlabel == 1 + %ylabel(['x' num2str(i)]) + %ylabel(eval(['x' num2str(i)])) + ylabel(char(ylab(i))) + end + if i==nrow + xlabel(tstring) + end + columnlabel = 0; + end + rowlabel = 0; +end diff --git a/MatlabFiles/fn_multigraph2_ver2_all_labels.m b/MatlabFiles/fn_multigraph2_ver2_all_labels.m new file mode 100755 index 0000000..6ec46b7 --- /dev/null +++ b/MatlabFiles/fn_multigraph2_ver2_all_labels.m @@ -0,0 +1,133 @@ +function scaleout = fn_multigraph2_ver2_all_labels(imf1,imf2,... + xlab,ylab,tstring,XTick,YTickIndx,scaleIndx,nrowg,ncolg) +%scaleout = fn_multigraph2_ver2_all_labels(imf1,imf2,... +% xlab,ylab,tstring,XTick,YTickIndx,scaleIndx,nrowg,ncolg) +% +%Stacking two sets of impulse responses in one graph. See fn_multigraph2_ver2.m. +% imf1, imf2: row: "nstp" time horizon (in the graphics), +% column: "nrow "variables (row in the graphics), +% 3rd dim: across "ncol" different situations (column in the graphics, but may be overwritten by ncolg). +% If the 3rd D is only 1, then we can specifiy nrowg and ncolg. +% xlab: x-axis labels on the top. Use [] if no label is needed. +% ylab: y-axis labels on the left. Use [] if no label is needed. +% XTick: ticks on the x-axis with grids on. Set to [] if no x-ticks and no grids. +% tstring: string for time (e.g., month or quarter) -- x-axis labels at the bottom. Use [] if no label is needed. +% YTickIndx: 1: enable YTick; 0: disable. Often set to zero to get a better picture. +% scaleIndx: 1: enable scale along Y-axis; 0: disable +% nrowg: number of rows in the graph (valid when the 3rd D is one) +% ncolg: number of columns in the graph (valid when the 3rd D is one) +% +% See fn_multigraph2_ver2, imrgraph, imcerrgraph, imrerrgraph +nstp = size(imf1,1); +nrow = size(imf1,2); +ncol = size(imf1,3); +t = 1:nstp; + +if (nargin < 9) + nrowg = nrow; + ncolg = ncol; +end +if (nrowg*ncolg < nrow*ncol) + error('fn_multigraph2_ver2_all_labels.m: nrowg*ncolg must be greater or equal to nrow*ncol') +end + + +temp1=zeros(ncol,1); +temp2=zeros(ncol,1); +maxval=zeros(nrow,1); +minval=zeros(nrow,1); +for i = 1:nrow + for j = 1:ncol + %jnk1=max(firsth(:,i,j)); + %jnk2=max(firstl(:,i,j)); + %jnk3=max(firsth1(:,i,j)); + jnk4=max(imf2(:,i,j)); + jnk5=max(imf1(:,i,j)); + + temp1(j)=max([jnk4 jnk5]); + % + %jnk1=min(firstl(:,i,j)); + %jnk2=min(firsth(:,i,j)); + %jnk3=min(firstl1(:,i,j)); + jnk4=min(imf2(:,i,j)); + jnk5=min(imf1(:,i,j)); + + temp2(j)=min([jnk4 jnk5]); + end + maxval(i)=max(temp1); + minval(i)=min(temp2); +end + +scaleout = [maxval(:) minval(:)]; + +%-------------- +% Column j: Shock 1 to N; Row i: Responses to +%------------- +%figure +rowlabel = 1; +for i = 1:nrow % column: from top to bottom + columnlabel = 1; + + if minval(i)<0 + if maxval(i)<=0 + yt=[minval(i) 0]; + else + yt=[minval(i) 0 maxval(i)]; + end + else % (minval(i) >=0) + if maxval(i) > 0 + yt=[0 maxval(i)]; + else % (identically zero responses) + yt=[-1 0 1]; + end + end + + + scale=[1 nstp minval(i) maxval(i)]; + for j = 1:ncol % row: from left to right + k1=(i-1)*ncol+j; + subplot(nrowg,ncolg,k1) + plot(t,imf1(:,i,j),'k-',t,imf2(:,i,j),'k--') + %t,[firstl(:,i,j) firsth(:,i,j)],':'); + grid; + if scaleIndx + axis(scale); + end + %set(gca,'YLim',[minval(i) maxval(i)]) + % + set(gca,'XTick',XTick) + if YTickIndx + set(gca,'YTick',yt) + end + + % if i<nrow + % set(gca,'XTickLabelMode','manual','XTickLabel',[]) + % end + %set(gca,'XTickLabel',' '); + if (scaleIndx) && (j>1) + set(gca,'YTickLabel',' '); + end + % if rowlabel == 1 + % %title(['x' num2str(j)]) + % %title(eval(['x' num2str(j)])) + % title(char(xlab(j))) + % end + if (~isempty(xlab)) + title(char(xlab(i))) + end + % + % if columnlabel == 1 + % %ylabel(['x' num2str(i)]) + % %ylabel(eval(['x' num2str(i)])) + % ylabel(char(ylab(i))) + % end + if (~isempty(ylab)) + ylabel(char(ylab(i))) + end + if (i==nrow) && (~isempty(tstring)) + xlabel(tstring) + end + columnlabel = 0; + end + rowlabel = 0; +end diff --git a/MatlabFiles/fn_multigraph2_ver2_all_labels_dates.m b/MatlabFiles/fn_multigraph2_ver2_all_labels_dates.m new file mode 100755 index 0000000..1bcbeb0 --- /dev/null +++ b/MatlabFiles/fn_multigraph2_ver2_all_labels_dates.m @@ -0,0 +1,141 @@ +function scaleout = fn_multigraph2_ver2_all_labels_dates(dates,imf1,imf2,... + xlab,ylab,tstring,XTick,YTickIndx,scaleIndx,legend_inp, nrowg,ncolg) +%scaleout = fn_multigraph2_ver2_all_labels_dates(dates,imf1,imf2,... +% xlab,ylab,tstring,XTick,YTickIndx,scaleIndx,nrowg,ncolg) +% +%Stacking two sets of impulse responses in one graph. See fn_multigraph2_ver2_all_labels.m. +% dates: time horizon in the graphics, +% imf1, imf2: row: the same dimension as the dates (in the graphics), +% column: "nrow "variables (row in the graphics), +% 3rd dim: across "ncol" different situations (column in the graphics, but may be overwritten by ncolg). +% If the 3rd D is only 1, then we can specifiy nrowg and ncolg. +% xlab: x-axis labels on the top. Use [] if no label is needed. +% ylab: y-axis labels on the left. Use [] if no label is needed. +% tstring: string for time (e.g., month or quarter) -- x-axis labels at the bottom. Use [] if no label is needed. +% XTick: ticks on the x-axis with grids on. If [], no x-ticks and no grids. +% YTickIndx: 1: enable YTick; 0: disable. Often set to zero to get a better picture. +% scaleIndx: 1: enable scale along Y-axis; 0: disable +% legend_inp: legend inputs. If [], no legend. +% nrowg: number of rows in the graph (valid when the 3rd D is one) +% ncolg: number of columns in the graph (valid when the 3rd D is one) +% +% See fn_multigraph2_ver2_all_labels.m, fn_multigraph2_ver2, imrgraph, imcerrgraph, imrerrgraph +nstp = size(imf1,1); +nrow = size(imf1,2); +ncol = size(imf1,3); + +if (length(dates) ~= nstp) + error('.../fn_multigraph2_ver2_all_labels_dates: dates must have the dimension as the row number of imf1 and imf2!') +end + +if (nargin < 11) + nrowg = nrow; + ncolg = ncol; +end +if (nrowg*ncolg < nrow*ncol) + error('fn_multigraph2_ver2_all_labels_dates.m: nrowg*ncolg must be greater or equal to nrow*ncol') +end + + +temp1=zeros(ncol,1); +temp2=zeros(ncol,1); +maxval=zeros(nrow,1); +minval=zeros(nrow,1); +for i = 1:nrow + for j = 1:ncol + %jnk1=max(firsth(:,i,j)); + %jnk2=max(firstl(:,i,j)); + %jnk3=max(firsth1(:,i,j)); + jnk4=max(imf2(:,i,j)); + jnk5=max(imf1(:,i,j)); + + temp1(j)=max([jnk4 jnk5]); + % + %jnk1=min(firstl(:,i,j)); + %jnk2=min(firsth(:,i,j)); + %jnk3=min(firstl1(:,i,j)); + jnk4=min(imf2(:,i,j)); + jnk5=min(imf1(:,i,j)); + + temp2(j)=min([jnk4 jnk5]); + end + maxval(i)=max(temp1); + minval(i)=min(temp2); +end + +scaleout = [maxval(:) minval(:)]; + +%-------------- +% Column j: Shock 1 to N; Row i: Responses to +%------------- +%figure +rowlabel = 1; +for i = 1:nrow % column: from top to bottom + columnlabel = 1; + + if minval(i)<0 + if maxval(i)<=0 + yt=[minval(i) 0]; + else + yt=[minval(i) 0 maxval(i)]; + end + else % (minval(i) >=0) + if maxval(i) > 0 + yt=[0 maxval(i)]; + else % (identically zero responses) + yt=[-1 0 1]; + end + end + + + scale=[dates(1) dates(end) minval(i) maxval(i)]; + for j = 1:ncol % row: from left to right + k1=(i-1)*ncol+j; + subplot(nrowg,ncolg,k1) + plot(dates,imf1(:,i,j),'k-',dates,imf2(:,i,j),'k--') + %t,[firstl(:,i,j) firsth(:,i,j)],':'); + grid; + if (~isempty(legend_inp)) + legend(legend_inp) + end + if scaleIndx + axis(scale); + end + %set(gca,'YLim',[minval(i) maxval(i)]) + % + set(gca,'XTick',XTick) + if YTickIndx + set(gca,'YTick',yt) + end + + % if i<nrow + % set(gca,'XTickLabelMode','manual','XTickLabel',[]) + % end + %set(gca,'XTickLabel',' '); + if (scaleIndx) && (j>1) + set(gca,'YTickLabel',' '); + end + % if rowlabel == 1 + % %title(['x' num2str(j)]) + % %title(eval(['x' num2str(j)])) + % title(char(xlab(j))) + % end + if (~isempty(xlab)) + title(char(xlab(i))) + end + % + % if columnlabel == 1 + % %ylabel(['x' num2str(i)]) + % %ylabel(eval(['x' num2str(i)])) + % ylabel(char(ylab(i))) + % end + if (~isempty(ylab)) + ylabel(char(ylab(i))) + end + if (i==nrow) && (~isempty(tstring)) + xlabel(tstring) + end + columnlabel = 0; + end + rowlabel = 0; +end diff --git a/MatlabFiles/fn_multigraphn_ver2.m b/MatlabFiles/fn_multigraphn_ver2.m new file mode 100755 index 0000000..eb5cb59 --- /dev/null +++ b/MatlabFiles/fn_multigraphn_ver2.m @@ -0,0 +1,158 @@ +function scaleout = fn_multigraphn_ver2(imfn,... + xlab,ylab,tstring,XTick,YTickIndx,scaleIndx,nrowg,ncolg) +%Stacking n sets of impulse responses in one graph. See fn_multigraph2_ver2.m. +% imfn: row: "nstp" time horizon (in the graphics), +% column: "nrow "variables such as responses (row in the graphics), +% 3rd D: across "ncol" different situations such as shocks (column in the graphics), +% 4th D: across different scenarios such as error bands or different models (in each graph). +% xlab: x-axis labels on the top +% ylab: y-axis labels on the left +% tstring: string for time (e.g., month or quarter) -- x-axis labels at the bottom +% YTickIndx: 1: enable YTick; 0: disable; +% To get a better picture, it is sometimes better to set YtickIndx to zero. +% scaleIndx: 1: enable scale along Y-axis; 0: disable +% nrowg: number of rows in the graph +% ncolg: number of columns in the graph +% +% See imrgraph, imcerrgraph, imrerrgraph +nstp = size(imfn,1); +nrow = size(imfn,2); +ncol = size(imfn,3); +nmodels = size(imfn,4); +t = 1:nstp; + +if (nargin < 9) + nrowg = nrow; + ncolg = ncol; +end +if (nrowg*ncolg < nrow*ncol) + nrowg + ncolg + nrow + ncol + + error('fn_multigraphn_ver2.m: nrowg*ncolg must be greater than nrow*ncol') +end + + +tempmax=zeros(ncol,1); +tempmin=zeros(ncol,1); +maxval=zeros(nrow,1); +minval=zeros(nrow,1); +for i = 1:nrow + for j = 1:ncol + tempmax(j) = -realmax; + tempmin(j) = realmax; + for k=1:nmodels + jnk = max(imfn(:,i,j,k)); + tempmax(j) = max([jnk tempmax(j)]); + % + jnk = min(imfn(:,i,j,k)); + tempmin(j) = min([jnk tempmin(j)]); + end + end + maxval(i)=max(tempmax); + minval(i)=min(tempmin); +end + +scaleout = [maxval(:) minval(:)]; + +%-------------- +% Column j: Shock 1 to N; Row i: Responses to +%------------- +%figure + + +rowlabel = 1; +for i = 1:nrow % column: from top to bottom + columnlabel = 1; + + if minval(i)<0 + if maxval(i)<=0 + yt=[minval(i) 0]; + else + yt=[minval(i) 0 maxval(i)]; + end + else % (minval(i) >=0) + if maxval(i) > 0 + yt=[0 maxval(i)]; + else % (identically zero responses) + yt=[-1 0 1]; + end + end + + + scale=[1 nstp minval(i) maxval(i)]; + for j = 1:ncol % row: from left to right + k1=(i-1)*ncol+j; + subplot(nrowg,ncolg,k1) + + %set(0,'DefaultAxesColorOrder',[1 0 0;0 1 0;0 0 1],... + % 'DefaultAxesLineStyleOrder','-|--|:') + %set(0,'DefaultAxesLineStyleOrder','-|--|:|-.') + set(0,'DefaultAxesColorOrder',[0 0 0],... + 'DefaultAxesLineStyleOrder','-|--|--|:*|-.|-*|--o|:d') + + nseries = zeros(nstp, nmodels); + for k=1:nmodels + nseries(:,k) = imfn(:,i,j,k); + end + plot(t,nseries, 'LineWidth',1.7); %,'Color','k'); + %set(gca,'LineStyleOrder','-|--|:|-.') + %set(gca,'LineStyleOrder',{'-*',':','o'}) + grid; + if scaleIndx + axis(scale); + end + %set(gca,'YLim',[minval(i) maxval(i)]) + % + set(gca,'XTick',XTick) + if YTickIndx + set(gca,'YTick',yt) + end + + if i<nrow + set(gca,'XTickLabelMode','manual','XTickLabel',[]) + end + %set(gca,'XTickLabel',' '); + if (scaleIndx) && (j>1) + set(gca,'YTickLabel',' '); + end + if rowlabel == 1 + %title(['x' num2str(j)]) + %title(eval(['x' num2str(j)])) + title(char(xlab(j))) + end + if columnlabel == 1 + %ylabel(['x' num2str(i)]) + %ylabel(eval(['x' num2str(i)])) + ylabel(char(ylab(i))) + end + if i==nrow + xlabel(tstring) + end + columnlabel = 0; + end + rowlabel = 0; +end + + +%Order of line styles and markers used in a plot. +%This property specifies which line styles and markers to use and in what order +%when creating multiple-line plots. For example,set(gca,'LineStyleOrder', '-*|:|o')sets LineStyleOrder to solid line with asterisk +%marker, dotted line, and hollow circle marker. The default is (-), which specifies +%a solid line for all data plotted. Alternatively, you can create a cell array +%of character strings to define the line styles:set(gca,'LineStyleOrder',{'-*',':','o'})MATLAB supports four line styles, which you can specify any number of +%times in any order. MATLAB cycles through the line styles only after using +%all colors defined by the ColorOrder property. For example, +%the first eight lines plotted use the different colors defined by ColorOrder with +%the first line style. MATLAB then cycles through the colors again, using the +%second line style specified, and so on.You can also specify line style and color directly with the plot and plot3 functions +%or by altering the properties of theline or +%lineseries objects after creating the graph. High-Level Functions and LineStyleOrderNote that, if the axes NextPlot property is set +%to replace (the default), high-level functions like plot reset +%the LineStyleOrder property before determining the line +%style to use. If you want MATLAB to use a LineStyleOrder that +%is different from the default, set NextPlot to replacechildren. Specifying a Default LineStyleOrderYou can also specify your own default LineStyleOrder. +%For example, this statementset(0,'DefaultAxesLineStyleOrder',{'-*',':','o'}) +%creates a default value for diff --git a/MatlabFiles/fn_nmlzvar.m b/MatlabFiles/fn_nmlzvar.m new file mode 100755 index 0000000..09ca589 --- /dev/null +++ b/MatlabFiles/fn_nmlzvar.m @@ -0,0 +1,92 @@ +function [A0n,a0dpindx,nswitch,A0inn] = fn_nmlzvar(A0u,A0xhat,A0inxhat,IndxNmlr,nswitch,A0inu) +% [A0n,nswitch,A0inn] = nmlzvar(A0u,A0xhat,A0inxhat,IndxNmlr,nswitch,A0inu) +% Export normalized new draw A0 (and inv(A0) only if IndxNmlr(5)) and the number of sign switches +% Ref.: D.F. Waggoner and T.A. Zha: "Does Normalization Matter for Inference?" +% See Note Forecast (2) pp. 52-53 +% +% A0u: unnormalized A0; column--equation +% A0xhat: ML estimate or posterior mode of A0 +% A0inxhat: inv(A0xhat) +% IndxNmlr: index for which normalization rule to choose +% Only one of the elments in IndxNmlr can be non-zero +% IndxNmlr(1): ML A distance rule (supposed to be the best) +% IndxNmlr(2): ML Ahat distance rule (to approximate IndxNmlr(1)) +% IndxNmlr(3): ML Euclidean distance rule (not invariant to scale) +% IndxNmlr(4): Positive diagonal rule +% IndxNmlr(5): Positive inv(A) diagonal rule (if ~IndxNmlr(5), no need for A0inu, +% so we set A0inn=[]) +% IndxNmlr(6): Assigned postive rule (such as off-diagonal elements). Added 1/3/00 +% nswitch: # of sign switches +% A0inu: unnormalized inv(A0); used only if IndxNmlr(5) +%----------------- +% A0n: normalized new A0; column--equation +% a0dpindx: Index of the columns in A0 or A+ whose signs need to be switched. +% nswitch: updated # of sign switches +% A0inn: normalized inv(A0); used only if IndxNmlr(5) +% +% Written by Tao Zha +% 1/3/00: added IndxNmlr(6) so that previous programs may not be compatible. +% 10/11/01: added a0dpindx in front of nswitch as an output argument so that previous programs may not be compatible. + + + +A0inn = []; % no output for normalized A0in unless IndxNmlr(5) + +if (length(find(IndxNmlr))>1) + warning('You cannot choose more than one normalization rule at a time') + disp('Press ctrl-c to abort') + pause +elseif isempty(find(IndxNmlr)) % no normalization + A0n=A0u; nswitch=0; +elseif IndxNmlr(1) + a0dpindx = find(diag(A0u\A0xhat)<0); + A0n = A0u; + if ~isempty(a0dpindx) + A0n(:,a0dpindx) = -A0u(:,a0dpindx); % normalized new draws + nswitch = nswitch + 1; %<<>> # of sign switches + end +elseif IndxNmlr(2) + a0dpindx = find(diag(A0inxhat*A0u)<0); + A0n = A0u; + if ~isempty(a0dpindx) + A0n(:,a0dpindx) = -A0u(:,a0dpindx); % normalized new draws + nswitch = nswitch + 1; %<<>> # of sign switches + end +elseif IndxNmlr(3) + Adiff = (A0u - A0xhat).^2; % distance that may be far from axhat or A0xhat + Adiffn = (-A0u - A0xhat).^2; % distance by chaning the sign of Atem + cAdiff = sum(Adiff); % each column summed up + cAdiffn = sum(Adiffn); % each column summed up + cAindx = find(cAdiffn<cAdiff); % index for shorter distance + A0n = A0u; + if ~isempty(cAindx) + A0n(:,cAindx) = -A0u(:,cAindx); % find the shortest or nearest distance + nswitch = nswitch + 1; %<<>> # of sign switches + end +elseif IndxNmlr(4) + a0dpindx = find(diag(A0u)<0); + A0n = A0u; + if ~isempty(a0dpindx) + A0n(:,a0dpindx) = -A0u(:,a0dpindx); % normalized new draws + nswitch = nswitch + 1; %<<>> # of sign switches + end +elseif IndxNmlr(5) + a0dpindx = find(diag(A0inu)<0); + A0n = A0u; + A0inn = A0inu; + if ~isempty(a0dpindx) + A0n(:,a0dpindx) = -A0u(:,a0dpindx); + A0inn(a0dpindx,:) = -A0inu(a0dpindx,:); + nswitch = nswitch + 1; %<<>> # of sign switches + end +elseif IndxNmlr(6) %*** This one has to be MANUALLY handled + [jnk,nvar]=size(A0u); + A0dummy=A0u; + A0dummy(:,1:2)=-A0u(:,1:2); % keep it to a sign that coincide with Brooking paper + a0dpindx = find(A0dummy(nvar,:)<0); % the last row + A0n = A0u; + if ~isempty(a0dpindx) + A0n(:,a0dpindx) = -A0u(:,a0dpindx); % normalized new draws + nswitch = nswitch + 1; %<<>> # of sign switches + end +end diff --git a/MatlabFiles/fn_numstruct2numcell_nummatrix.m b/MatlabFiles/fn_numstruct2numcell_nummatrix.m new file mode 100644 index 0000000..b9485ae --- /dev/null +++ b/MatlabFiles/fn_numstruct2numcell_nummatrix.m @@ -0,0 +1,20 @@ +function [uniform_cell, uniform_matrix3D, names_fields] = fn_numstruct2numcell_nummatrix(uniform_ps) +%[uniform_cell, uniform_matrix3D, names_fields] = fn_numstruct2numcell_nummatrix(uniform_ps) +% +% Inputs: +% uniform_ps: a structure where each field has the same nrows-by-ncols matrix. This function does NOT work +% if each field has different data types. +% Outputs: +% uniform_cell: nfields cells where each cell has a nrows-by-ncols matrix. +% uniform_matrix3D: 3-D array: nrows-by-ncols-by-nfields + +names_fields = fieldnames(uniform_ps); +nfields = length(names_fields); +uniform_cell = struct2cell(uniform_ps); +nrows = size(uniform_cell{1},1); +ncols = size(uniform_cell{1},2); + +uniform_matrix3D = zeros(nrows,ncols,nfields); +for (ni=1:nfields) + uniform_matrix3D(:,:,ni) = uniform_cell{ni}; +end \ No newline at end of file diff --git a/MatlabFiles/fn_ols.m b/MatlabFiles/fn_ols.m new file mode 100755 index 0000000..fae2d87 --- /dev/null +++ b/MatlabFiles/fn_ols.m @@ -0,0 +1,29 @@ +function [Bh,e,xtx,xty] = fn_ols(y,phi) +% [Bh,e,xtx,xty] = fn_ols(y,phi) +% ols: estimate a system of equations: Y(T*nvar) = XB + u, X: T*k, B: k*nvar. +% +% y: Y: T-by-nvar +% phi: X; T-by-k; column: number of r.h.s. variables (including +%------------ +% Bh: the estimated B; column: nvar; row: number of r.h.s. variables. +% e: estimated residual e = y -xBh, T*nvar +% xtx: X'X: k-by-k +% xty: X'Y: k-by-nvar +% deterministic terms)% +% See also sye.m and syed.m + +% ** setup of orders and lengths ** +[u d v]=svd(phi,0); %trial +%xtx = phi'*phi; % X'X, k*k (ncoe*ncoe) +vd=v.*(ones(size(v,2),1)*diag(d)'); %trial +dinv = 1./diag(d); % inv(diag(d)) +vdinv=v.*(ones(size(v,2),1)*dinv'); %trial +xtx=vd*vd'; +xtxinv = vdinv*vdinv'; +%xty = phi'*y; % X'Y +uy = u'*y; %trial +xty = vd*uy; %trial +%Bh = xtx\xty; %inv(X'X)*(X'Y), k*m (ncoe*nvar). +Bh = xtxinv*xty; +%e = y - phi*Bh; % from Y = XB + U, e: (T-lags)*nvar +e = y - u*uy; diff --git a/MatlabFiles/fn_printmatrix4tex.m b/MatlabFiles/fn_printmatrix4tex.m new file mode 100755 index 0000000..d13ca19 --- /dev/null +++ b/MatlabFiles/fn_printmatrix4tex.m @@ -0,0 +1,38 @@ +function fn_printmatrix4tex(M, nrows, ncols, indxFloat) +% Prints the matrix to a screen for a tex file. +% +% Inputs: +% M: The matrix to be written to the file. +% nrows: Number of rows of M. +% ncols: Number of columns of M. +% indxFloat: 1 if double; +% 2 if single; +% 3 if only 2 significant digits +% 0 if integer. +% +if nrows~=size(M,1) + error('fn_fprintmatrix(): Make sure the row number supplied match that of the matrix'); +end +if ncols~=size(M,2) + error('fn_fprintmatrix(): Make sure the column number supplied match that of the matrix'); +end +for ki=1:nrows + for kj=1:ncols + fprintf(1,' & '); + if (indxFloat == 1) + fprintf(1,' %.16e ',M((kj-1)*nrows+ki)); + elseif (indxFloat == 2) + fprintf(1,' %.8e ',M((kj-1)*nrows+ki)); + elseif (indxFloat == 3) + fprintf(1,' %5.2f ',M((kj-1)*nrows+ki)); + else + fprintf(1,' %d ',M((kj-1)*nrows+ki)); + end + if (kj==ncols) + fprintf(1,'\\\\\n'); + end + end + if (ki==nrows) + fprintf(1,'\n\n'); + end +end diff --git a/MatlabFiles/fn_printmatrix4tex_ver2.m b/MatlabFiles/fn_printmatrix4tex_ver2.m new file mode 100755 index 0000000..21da908 --- /dev/null +++ b/MatlabFiles/fn_printmatrix4tex_ver2.m @@ -0,0 +1,48 @@ +function fn_printmatrix4tex_ver2(M, nrows, ncols, indxFloat) +%fn_printmatrix4tex_ver2(M, nrows, ncols, indxFloat) +% +% Prints the matrix to a screen for a tex file. +% Inputs: +% M: The matrix to be written to the file. +% nrows: Number of rows of M. +% ncols: Number of columns of M. +% indxFloat: 1 if only 1 digits after decimal point +% 2 if only 2 digits after decimal point +% 3 if only 3 digits after decimal point +% 4 if only 4 digits after decimal point +% 0 if integer. +% 1001 if double and %.16e +% 1002 if single and %.8e +% +if nrows~=size(M,1) + error('fn_fprintmatrix(): Make sure the row number supplied match that of the matrix'); +end +if ncols~=size(M,2) + error('fn_fprintmatrix(): Make sure the column number supplied match that of the matrix'); +end +for ki=1:nrows + for kj=1:ncols + fprintf(1,' & '); + if (indxFloat == 1001) + fprintf(1,' %.16e ',M((kj-1)*nrows+ki)); + elseif (indxFloat == 1002) + fprintf(1,' %.8e ',M((kj-1)*nrows+ki)); + elseif (indxFloat == 1) + fprintf(1,' %5.1f ',M((kj-1)*nrows+ki)); + elseif (indxFloat == 2) + fprintf(1,' %5.2f ',M((kj-1)*nrows+ki)); + elseif (indxFloat == 3) + fprintf(1,' %5.3f ',M((kj-1)*nrows+ki)); + elseif (indxFloat == 4) + fprintf(1,' %5.4f ',M((kj-1)*nrows+ki)); + else + fprintf(1,' %d ',M((kj-1)*nrows+ki)); + end + if (kj==ncols) + fprintf(1,'\\\\\n'); + end + end + if (ki==nrows) + fprintf(1,'\n\n'); + end +end diff --git a/MatlabFiles/fn_reset_ini_seed.m b/MatlabFiles/fn_reset_ini_seed.m new file mode 100755 index 0000000..dcba439 --- /dev/null +++ b/MatlabFiles/fn_reset_ini_seed.m @@ -0,0 +1,13 @@ +function fn_reset_ini_seed(seednumber) +%fn_reset_ini_seed(seednumber) +% +% After Matlab starts, run this function to reset the seed number; otherwise, Matlab automatically resets to the same initial seed. +% seednumber: 0 -- random state reset to the clock time; + +if seednumber + randn('state',seednumber); + rand('state',seednumber); +else + randn('state',fix(100*sum(clock))); + rand('state',fix(100*sum(clock))); +end diff --git a/MatlabFiles/fn_rlrpostr.m b/MatlabFiles/fn_rlrpostr.m new file mode 100755 index 0000000..a3ea1bf --- /dev/null +++ b/MatlabFiles/fn_rlrpostr.m @@ -0,0 +1,50 @@ +function [P,H0inv,Hpinv] = fn_rlrpostr(xtx,xty,yty,Ptld,H0invtld,Hpinvtld,Ui,Vi) +% [P,H0inv,Hpinv] = fn_rlrpostr(xtx,xty,yty,Ptld,H0tld,Hptld,Ui,Vi) +% +% Exporting random (i.e., random prior) Bayesian posterior matrices with linear restrictions +% See Waggoner and Zha's Gibbs sampling paper +% +% xtx: X'X: k-by-k where k=ncoef +% xty: X'Y: k-by-nvar +% yty: Y'Y: nvar-by-nvar +% Ptld: cell(nvar,1), transformation matrix that affects the (random walk) prior mean of A+ conditional on A0. +% H0invtld: cell(nvar,1), transformed inv covaraince for free parameters in A0(:,i). +% Hpinvtld: cell(nvar,1), transformed inv covaraince for free parameters in A+(:,i); +% Ui: nvar-by-1 cell. In each cell, nvar-by-qi orthonormal basis for the null of the ith +% equation contemporaneous restriction matrix where qi is the number of free parameters. +% With this transformation, we have ai = Ui*bi or Ui'*ai = bi where ai is a vector +% of total original parameters and bi is a vector of free parameters. When no +% restrictions are imposed, we have Ui = I. There must be at least one free +% parameter left for the ith equation. Imported from dnrprior.m. +% Vi: nvar-by-1 cell. In each cell, k-by-ri orthonormal basis for the null of the ith +% equation lagged restriction matrix where k (ncoef) is a total number of RHS variables and +% ri is the number of free parameters. With this transformation, we have fi = Vi*gi +% or Vi'*fi = gi where fi is a vector of total original parameters and gi is a +% vector of free parameters. There must be at least one free parameter left for +% the ith equation. Imported from dnrprior.m. +%----------------- +% P: cell(nvar,1). In each cell, the transformation matrix that affects the posterior mean of A+ conditional on A0. +% In other words, the posterior mean (of g_i) = P{i}*b_i where g_i is a column vector of free parameters +% of A+(:,i)) given b_i (b_i is a column vector of free parameters of A0(:,i)). +% H0inv: cell(nvar,1). Not divided by T yet. In each cell, inverse of posterior covariance matrix H0. +% The exponential term is b_i'*inv(H0)*b_i for the ith equation where b_i = U_i*a0_i. +% It resembles old SpH or Sbd in the exponent term in posterior of A0, but not divided by T yet. +% Hpinv: cell(nvar,1). In each cell, posterior inverse of covariance matrix Hp (A+) for the free parameters +% g_i = V_i*A+(:,i) in the ith equation. +% +% Tao Zha, February 2000 + +nvar = size(yty,1); + +P = cell(nvar,1); % tld: tilda +H0inv = cell(nvar,1); % posterior inv(H0), resemble old SpH, but not divided by T yet. +Hpinv = cell(nvar,1); % posterior inv(Hp). + + +for n=1:nvar % one for each equation + Hpinv{n} = Vi{n}'*xtx*Vi{n} + Hpinvtld{n}; + P1 = Vi{n}'*xty*Ui{n} + Hpinvtld{n}*Ptld{n}; + P{n} = Hpinv{n}\P1; + H0inv{n} = Ui{n}'*yty*Ui{n} + H0invtld{n} + Ptld{n}'*Hpinvtld{n}*Ptld{n} ... + - P1'*P{n}; %P{n} = (Hpinv{n}\P1); +end diff --git a/MatlabFiles/fn_rlrprior.m b/MatlabFiles/fn_rlrprior.m new file mode 100755 index 0000000..a6df3fc --- /dev/null +++ b/MatlabFiles/fn_rlrprior.m @@ -0,0 +1,39 @@ +function [Ptld,H0invtld,Hpinvtld] = fn_rlrprior(Ui,Vi,Pi,H0multi,Hpmulti,nvar) +% [Ptld,H0invtld,Hpinvtld] = fn_rlrprior(Ui,Vi,Pi,H0multi,Hpmulti,nvar) +% +% Exporting random Bayesian prior with linear restrictions +% See Waggoner and Zha's Gibbs sampling paper +% +% Ui: nvar-by-1 cell. In each cell, nvar-by-qi orthonormal basis for the null of the ith +% equation contemporaneous restriction matrix where qi is the number of free parameters. +% With this transformation, we have ai = Ui*bi or Ui'*ai = bi where ai is a vector +% of total original parameters and bi is a vector of free parameters. When no +% restrictions are imposed, we have Ui = I. There must be at least one free +% parameter left for the ith equation. Imported from dnrprior.m. +% Vi: nvar-by-1 cell. In each cell, k-by-ri orthonormal basis for the null of the ith +% equation lagged restriction matrix where k (ncoef) is a total number of RHS variables and +% ri is the number of free parameters. With this transformation, we have fi = Vi*gi +% or Vi'*fi = gi where fi is a vector of total original parameters and gi is a +% vector of free parameters. There must be at least one free parameter left for +% the ith equation. Imported from dnrprior.m. +% Pi: ncoef-by-nvar matrix for the ith equation under random walk. Same for all equations +% H0multi: nvar-by-nvar-by-nvar; H0 for different equations under asymmetric prior +% Hpmulti: ncoef-by-ncoef-by-nvar; H+ for different equations under asymmetric prior +% nvar: number of endogenous variables +% -------------------- +% Ptld: cell(nvar,1). The prior mean of g_i is Ptld{i}*b_i; +% H0invtld: cell(nvar,1). Transformed inv covaraince for b_i, the free parameters in A0(:,i); +% Hpinvtld: cell(nvar,1). Transformed inv covaraince for g_i, the free parameters in A+(:,i); +% +% Tao Zha, February 2000 + +Ptld = cell(nvar,1); % tld: tilda +H0invtld = cell(nvar,1); % H0 for different equations under linear restrictions +Hpinvtld = cell(nvar,1); % H+ for different equations under linear restrictions + +for n=1:nvar % one for each equation + Hpinvtld{n} = Vi{n}'*(Hpmulti(:,:,n)\Vi{n}); + Ptld{n} = (Hpinvtld{n}\Vi{n}')*(Hpmulti(:,:,n)\Pi)*Ui{n}; + H0invtld{n} = Ui{n}'*(H0multi(:,:,n)\Ui{n}) + Ui{n}'*Pi'*(Hpmulti(:,:,n)\Pi)*Ui{n} ... + - Ptld{n}'*Hpinvtld{n}*Ptld{n}; +end diff --git a/MatlabFiles/fn_rnrprior.m b/MatlabFiles/fn_rnrprior.m new file mode 100755 index 0000000..b039d28 --- /dev/null +++ b/MatlabFiles/fn_rnrprior.m @@ -0,0 +1,224 @@ +function [Pi,H0multi,Hpmulti,H0invmulti,Hpinvmulti] ... + = fn_rnrprior(nvar,q_m,lags,xdgel,mu,nexo,asym0,asymp) +% [Pi,H0multi,Hpmulti,H0invmulti,Hpinvmulti] ... +% = fn_rnrprior(nvar,q_m,lags,xdgel,mu,nexo,asym0,asymp) +% Exporting random Bayesian prior of Sims and Zha with asymmetric rior (but no linear restrictions) +% See Waggoner and Zha's Gibbs sampling paper +% +% nvar: number of endogenous variables +% q_m: quarter or month +% lags: the maximum length of lag +% xdgel: the general matrix of the original data (no manipulation involved) +% with sample size including lags. Used only to get variances of residuals for +% the scaling purpose; NOT used for mu(5) and mu(6). +% mu: 6-by-1 vector of hyperparameters (the following numbers for Atlanta Fed's forecast), where +% mu(5) and mu(6) are NOT used here. See fn_dataxy.m for using mu(5) and mu(6). +% mu(1): overall tightness and also for A0; (0.57) +% mu(2): relative tightness for A+; (0.13) +% mu(3): relative tightness for the constant term; (0.1). NOTE: for other +% exogenous terms, the variance of each exogenous term must be taken into +% acount to eliminate the scaling factor. +% mu(4): tightness on lag decay; (1) +% mu(5): weight on nvar sums of coeffs dummy observations (unit roots); (5) +% mu(6): weight on single dummy initial observation including constant +% (cointegration, unit roots, and stationarity); (5) +% NOTE: for this subdirectory, mu(5) and mu(6) are not used. +% asym0: nvar-by-nvar asymmetric prior on A0. Column -- equation. +% If ones(nvar,nvar), symmetric prior; if not, relative (asymmetric) tightness on A0. +% asymp: ncoef-1-by-nvar asymmetric prior on A+ bar constant. Column -- equation. +% If ones(ncoef-1,nvar), symmetric prior; if not, relative (asymmetric) tightness on A+. +% nexo: number of exogenous variables (if not specified, nexo=1 (constant) by default). +% The constant term is always put to the last of all endogenous and exogenous variables. +% -------------------- +% Pi: ncoef-by-nvar matrix for the ith equation under random walk. Same for all equations +% H0multi: nvar-by-nvar-by-nvar; H0 for different equations under asymmetric prior +% Hpmulti: ncoef-by-ncoef-by-nvar; H+ for different equations under asymmetric prior +% H0invmulti: nvar-by-nvar-by-nvar; inv(H0) for different equations under asymmetric prior +% Hpinvmulti: ncoef-by-ncoef-by-nvar; inv(H+) for different equations under asymmetric prior +% +% Tao Zha, February 2000. Revised, September 2000. +% See fn_dataxy.m for using mu(5) and mu(6). + + +if nargin==5, nexo=1; end +ncoef = nvar*lags+nexo; % number of coefficients in *each* equation, RHS coefficients only. + +H0multi=zeros(nvar,nvar,nvar); % H0 for different equations under asymmetric prior +Hpmulti=zeros(ncoef,ncoef,nvar); % H+ for different equations under asymmetric prior +H0invmulti=zeros(nvar,nvar,nvar); % inv(H0) for different equations under asymmetric prior +Hpinvmulti=zeros(ncoef,ncoef,nvar); % inv(H+) for different equations under asymmetric prior + +%*** Constructing Pi for the ith equation under the random walk assumption +Pi = zeros(ncoef,nvar); % same for all equations +Pi(1:nvar,1:nvar) = eye(nvar); % random walk + +% +%@@@ Prepared for Bayesian prior +% +% +% ** monthly lag decay in order to match quarterly decay: a*exp(bl) where +% ** l is the monthly lag. Suppose quarterly decay is 1/x where x=1,2,3,4. +% ** Let the decay of l1 (a*exp(b*l1)) match that of x1 (say, beginning: 1/1) +% ** and the decay of l2 (a*exp(b*l2)) match that of x2 (say, end: 1/5), +% ** we can solve for a and b which are +% ** b = (log_x1-log_x2)/(l1-l2), and a = x1*exp(-b*l1). +if q_m==12 + l1 = 1; % 1st month == 1st quarter + xx1 = 1; % 1st quarter + l2 = lags; % last month + xx2 = 1/((ceil(lags/3))^mu(4)); % last quarter + %xx2 = 1/6; % last quarter + % 3rd quarter: i.e., we intend to let decay of the 6th month match + % that of the 3rd quarter, so that the 6th month decays a little + % faster than the second quarter which is 1/2. + if lags==1 + b = 0; + else + b = (log(xx1)-log(xx2))/(l1-l2); + end + a = xx1*exp(-b*l1); +end + + + +% +% *** specify the prior for each equation separately, SZ method, +% ** get the residuals from univariate regressions. +% +sgh = zeros(nvar,1); % square root +sgsh = sgh; % square +nSample=size(xdgel,1); % sample size-lags +yu = xdgel; +C = ones(nSample,1); +for k=1:nvar + [Bk,ek,junk1,junk2,junk3,junk4] = sye([yu(:,k) C],lags); + clear Bk junk1 junk2 junk3 junk4; + sgsh(k) = ek'*ek/(nSample-lags); + sgh(k) = sqrt(sgsh(k)); +end +% ** prior variance for A0(:,1), same for all equations!!! +sg0bid = zeros(nvar,1); % Sigma0_bar diagonal only for the ith equation +for j=1:nvar + sg0bid(j) = 1/sgsh(j); % sgsh = sigmai^2 +end +% ** prior variance for lagged and exogeous variables, same for all equations +sgpbid = zeros(ncoef,1); % Sigma_plus_bar, diagonal, for the ith equation +for i = 1:lags + if (q_m==12) + lagdecay = a*exp(b*i*mu(4)); + end + % + for j = 1:nvar + if (q_m==12) + % exponential decay to match quarterly decay + sgpbid((i-1)*nvar+j) = lagdecay^2/sgsh(j); % ith equation + elseif (q_m==4) + sgpbid((i-1)*nvar+j) = (1/i^mu(4))^2/sgsh(j); % ith equation + else + error('Incompatibility with lags, check the possible errors!!!') + %warning('Incompatibility with lags, check the possible errors!!!') + %return + end + end +end +% + + +%================================================= +% Computing the (prior) covariance matrix for the posterior of A0, no data yet +%================================================= +% +% +% ** set up the conditional prior variance sg0bi and sgpbi. +sg0bida = mu(1)^2*sg0bid; % ith equation +sgpbida = mu(1)^2*mu(2)^2*sgpbid; +sgpbida(ncoef-nexo+1:ncoef) = mu(1)^2*mu(3)^2; + %<<>> No scaling adjustment has been made for exogenous terms other than constant +sgppbd = sgpbida(nvar+1:ncoef); % corresponding to A++, in a Sims-Zha paper + +Hptd = zeros(ncoef); +Hptdi=Hptd; +Hptd(ncoef,ncoef)=sgppbd(ncoef-nvar); +Hptdinv(ncoef,ncoef)=1./sgppbd(ncoef-nvar); + % condtional on A0i, H_plus_tilde + + +if nargin<7 % the default is no asymmetric information + asym0 = ones(nvar,nvar); % if not ones, then we have relative (asymmetric) tightness + asymp = ones(ncoef-1,nvar); % for A+. Column -- equation +end + +%**** Asymmetric Information +%asym0 = ones(nvar,nvar); % if not ones, then we have relative (asymmetric) tightness +%asymp = ones(ncoef-1,nvar); % pp: plus without constant. Column -- equation +%>>>>>> B: asymmetric prior variance for asymp <<<<<<<< +% +%for i = 1:lags +% rowif = (i-1)*nvar+1; +% rowil = i*nvar; +% idmatw0 = 0.5; % weight assigned to idmat0 in the formation of asymp +% if (i==1) +% asymp(rowif:rowil,:)=(1-idmatw0)*ones(nvar)+idmatw0*idmat0; % first lag +% % note: idmat1 is already transposed. Column -- equation +% else +% %asymp(rowif:rowil,1:nvar) = (1-idmatw0)*ones(nvar)+idmatw0*idmat0; +% % <<<<<<< toggle + +% % Note: already transposed, since idmat0 is transposed. +% % Meaning: column implies equation +% asymp(rowif:rowil,1:nvar) = ones(nvar); +% % >>>>>>> toggle - +% end +%end +% +%>>>>>> E: asymmetric prior variance for asymp <<<<<<<< + + +%================================================= +% Computing the final covariance matrix (S1,...,Sm) for the prior of A0, +% and final Gb=(G1,...,Gm) for A+ if asymmetric prior or for +% B if symmetric prior for A+ +%================================================= +% +for i = 1:nvar + %------------------------------ + % Introduce prior information on which variables "belong" in various equations. + % In this first trial, we just introduce this information here, in a model-specific way. + % Eventually this info has to be passed parametricly. In our first shot, we just damp down + % all coefficients except those on the diagonal. + + %*** For A0 + factor0=asym0(:,i); + sg0bd = sg0bida.*factor0; % Note, this only works for the prior variance Sg(i) + % of a0(i) being diagonal. If the prior variance Sg(i) is not + % diagonal, we have to work on inv(Sg(i)) or sg0bdinv directly. + sg0bdinv = 1./sg0bd; + % * unconditional variance on A0+ + H0td = diag(sg0bd); % unconditional + H0tdinv = diag(sg0bdinv); + % + H0multi(:,:,i)=H0td; + H0invmulti(:,:,i)=H0tdinv; + + + %*** For A+ + if ~(lags==0) % For A1 to remain random walk properties + factor1=asymp(1:nvar,i); + sg1bd = sgpbida(1:nvar).*factor1; + sg1bdinv = 1./sg1bd; + % + Hptd(1:nvar,1:nvar)=diag(sg1bd); + Hptdinv(1:nvar,1:nvar)=diag(sg1bdinv); + if lags>1 + factorpp=asymp(nvar+1:ncoef-1,i); + sgpp_cbd = sgppbd(1:ncoef-nvar-1) .* factorpp; + sgpp_cbdinv = 1./sgpp_cbd; + Hptd(nvar+1:ncoef-1,nvar+1:ncoef-1)=diag(sgpp_cbd); + Hptdinv(nvar+1:ncoef-1,nvar+1:ncoef-1)=diag(sgpp_cbdinv); + % condtional on A0i, H_plus_tilde + end + end + Hpmulti(:,:,i)=Hptd; + Hpinvmulti(:,:,i)=Hptdinv; +end + + diff --git a/MatlabFiles/fn_rnrprior2.m b/MatlabFiles/fn_rnrprior2.m new file mode 100755 index 0000000..ecb9a70 --- /dev/null +++ b/MatlabFiles/fn_rnrprior2.m @@ -0,0 +1,220 @@ +function [Pi,H0multi,Hpmulti,H0invmulti,Hpinvmulti] ... + = fn_rnrprior2(nvar,q_m,lags,xdgel,mu1_4,nexo,asym0,asymp) +% [Pi,H0multi,Hpmulti,H0invmulti,Hpinvmulti] ... +% = fn_rnrprior2(nvar,q_m,lags,xdgel,mu1_4,nexo,asym0,asymp) +% Exporting random Bayesian prior of Sims and Zha with asymmetric rior (but no linear restrictions) +% See Waggoner and Zha's Gibbs sampling paper +% +% nvar: number of endogenous variables +% q_m: quarter or month +% lags: the maximum length of lag +% xdgel: the general matrix of the original data (no manipulation involved) +% with sample size including lags. Used only to get variances of residuals for +% the scaling purpose; NOT used for hyperparameters on dummy observations. +% mu1_4: 4-by-1 vector of hyperparameters (the numbers for Atlanta Fed's forecast), where +% mu(5) and mu(6) are NOT used here. See fn_dataxy2.m for using mu(5) and mu(6). +% mu1_4(1): overall tightness and also for A0; (0.57) +% mu1_4(2): relative tightness for A+; (0.13) +% mu1_4(3): relative tightness for the constant term; (0.1). NOTE: for other +% exogenous terms, the variance of each exogenous term must be taken into +% acount to eliminate the scaling factor. +% mu1_4(4): tightness on lag decay; (1) +% asym0: nvar-by-nvar asymmetric prior on A0. Column -- equation. +% If ones(nvar,nvar), symmetric prior; if not, relative (asymmetric) tightness on A0. +% asymp: ncoef-1-by-nvar asymmetric prior on A+ bar constant. Column -- equation. +% If ones(ncoef-1,nvar), symmetric prior; if not, relative (asymmetric) tightness on A+. +% nexo: number of exogenous variables (if not specified, nexo=1 (constant) by default). +% The constant term is always put to the last of all endogenous and exogenous variables. +% -------------------- +% Pi: ncoef-by-nvar matrix for the ith equation under random walk. Same for all equations +% H0multi: nvar-by-nvar-by-nvar; H0 for different equations under asymmetric prior +% Hpmulti: ncoef-by-ncoef-by-nvar; H+ for different equations under asymmetric prior +% H0invmulti: nvar-by-nvar-by-nvar; inv(H0) for different equations under asymmetric prior +% Hpinvmulti: ncoef-by-ncoef-by-nvar; inv(H+) for different equations under asymmetric prior +% +% Tao Zha, February 2000. Revised, September 2000. +% See fn_dataxy2.m for using dummy hyperparameters mu5 and mu6. + + +if nargin==5, nexo=1; end +ncoef = nvar*lags+nexo; % number of coefficients in *each* equation, RHS coefficients only. + +H0multi=zeros(nvar,nvar,nvar); % H0 for different equations under asymmetric prior +Hpmulti=zeros(ncoef,ncoef,nvar); % H+ for different equations under asymmetric prior +H0invmulti=zeros(nvar,nvar,nvar); % inv(H0) for different equations under asymmetric prior +Hpinvmulti=zeros(ncoef,ncoef,nvar); % inv(H+) for different equations under asymmetric prior + +%*** Constructing Pi for the ith equation under the random walk assumption +Pi = zeros(ncoef,nvar); % same for all equations +Pi(1:nvar,1:nvar) = eye(nvar); % random walk + +% +%@@@ Prepared for Bayesian prior +% +% +% ** monthly lag decay in order to match quarterly decay: a*exp(bl) where +% ** l is the monthly lag. Suppose quarterly decay is 1/x where x=1,2,3,4. +% ** Let the decay of l1 (a*exp(b*l1)) match that of x1 (say, beginning: 1/1) +% ** and the decay of l2 (a*exp(b*l2)) match that of x2 (say, end: 1/5), +% ** we can solve for a and b which are +% ** b = (log_x1-log_x2)/(l1-l2), and a = x1*exp(-b*l1). +if q_m==12 + l1 = 1; % 1st month == 1st quarter + xx1 = 1; % 1st quarter + l2 = lags; % last month + xx2 = 1/((ceil(lags/3))^mu1_4(4)); % last quarter + %xx2 = 1/6; % last quarter + % 3rd quarter: i.e., we intend to let decay of the 6th month match + % that of the 3rd quarter, so that the 6th month decays a little + % faster than the second quarter which is 1/2. + if lags==1 + b = 0; + else + b = (log(xx1)-log(xx2))/(l1-l2); + end + a = xx1*exp(-b*l1); +end + + + +% +% *** specify the prior for each equation separately, SZ method, +% ** get the residuals from univariate regressions. +% +sgh = zeros(nvar,1); % square root +sgsh = sgh; % square +nSample=size(xdgel,1); % sample size-lags +yu = xdgel; +C = ones(nSample,1); +for k=1:nvar + [Bk,ek,junk1,junk2,junk3,junk4] = sye([yu(:,k) C],lags); + clear Bk junk1 junk2 junk3 junk4; + sgsh(k) = ek'*ek/(nSample-lags); + sgh(k) = sqrt(sgsh(k)); +end +% ** prior variance for A0(:,1), same for all equations!!! +sg0bid = zeros(nvar,1); % Sigma0_bar diagonal only for the ith equation +for j=1:nvar + sg0bid(j) = 1/sgsh(j); % sgsh = sigmai^2 +end +% ** prior variance for lagged and exogeous variables, same for all equations +sgpbid = zeros(ncoef,1); % Sigma_plus_bar, diagonal, for the ith equation +for i = 1:lags + if (q_m==12) + lagdecay = a*exp(b*i*mu1_4(4)); + end + % + for j = 1:nvar + if (q_m==12) + % exponential decay to match quarterly decay + sgpbid((i-1)*nvar+j) = lagdecay^2/sgsh(j); % ith equation + elseif (q_m==4) + sgpbid((i-1)*nvar+j) = (1/i^mu1_4(4))^2/sgsh(j); % ith equation + else + error('Incompatibility with lags, check the possible errors!!!') + %warning('Incompatibility with lags, check the possible errors!!!') + %return + end + end +end +% + + +%================================================= +% Computing the (prior) covariance matrix for the posterior of A0, no data yet +%================================================= +% +% +% ** set up the conditional prior variance sg0bi and sgpbi. +sg0bida = mu1_4(1)^2*sg0bid; % ith equation +sgpbida = mu1_4(1)^2*mu1_4(2)^2*sgpbid; +sgpbida(ncoef-nexo+1:ncoef) = mu1_4(1)^2*mu1_4(3)^2; + %<<>> No scaling adjustment has been made for exogenous terms other than constant +sgppbd = sgpbida(nvar+1:ncoef); % corresponding to A++, in a Sims-Zha paper + +Hptd = zeros(ncoef); +Hptdi=Hptd; +Hptd(ncoef,ncoef)=sgppbd(ncoef-nvar); +Hptdinv(ncoef,ncoef)=1./sgppbd(ncoef-nvar); + % condtional on A0i, H_plus_tilde + + +if nargin<7 % the default is no asymmetric information + asym0 = ones(nvar,nvar); % if not ones, then we have relative (asymmetric) tightness + asymp = ones(ncoef-1,nvar); % for A+. Column -- equation +end + +%**** Asymmetric Information +%asym0 = ones(nvar,nvar); % if not ones, then we have relative (asymmetric) tightness +%asymp = ones(ncoef-1,nvar); % pp: plus without constant. Column -- equation +%>>>>>> B: asymmetric prior variance for asymp <<<<<<<< +% +%for i = 1:lags +% rowif = (i-1)*nvar+1; +% rowil = i*nvar; +% idmatw0 = 0.5; % weight assigned to idmat0 in the formation of asymp +% if (i==1) +% asymp(rowif:rowil,:)=(1-idmatw0)*ones(nvar)+idmatw0*idmat0; % first lag +% % note: idmat1 is already transposed. Column -- equation +% else +% %asymp(rowif:rowil,1:nvar) = (1-idmatw0)*ones(nvar)+idmatw0*idmat0; +% % <<<<<<< toggle + +% % Note: already transposed, since idmat0 is transposed. +% % Meaning: column implies equation +% asymp(rowif:rowil,1:nvar) = ones(nvar); +% % >>>>>>> toggle - +% end +%end +% +%>>>>>> E: asymmetric prior variance for asymp <<<<<<<< + + +%================================================= +% Computing the final covariance matrix (S1,...,Sm) for the prior of A0, +% and final Gb=(G1,...,Gm) for A+ if asymmetric prior or for +% B if symmetric prior for A+ +%================================================= +% +for i = 1:nvar + %------------------------------ + % Introduce prior information on which variables "belong" in various equations. + % In this first trial, we just introduce this information here, in a model-specific way. + % Eventually this info has to be passed parametricly. In our first shot, we just damp down + % all coefficients except those on the diagonal. + + %*** For A0 + factor0=asym0(:,i); + sg0bd = sg0bida.*factor0; % Note, this only works for the prior variance Sg(i) + % of a0(i) being diagonal. If the prior variance Sg(i) is not + % diagonal, we have to work on inv(Sg(i)) or sg0bdinv directly. + sg0bdinv = 1./sg0bd; + % * unconditional variance on A0+ + H0td = diag(sg0bd); % unconditional + H0tdinv = diag(sg0bdinv); + % + H0multi(:,:,i)=H0td; + H0invmulti(:,:,i)=H0tdinv; + + + %*** For A+ + if ~(lags==0) % For A1 to remain random walk properties + factor1=asymp(1:nvar,i); + sg1bd = sgpbida(1:nvar).*factor1; + sg1bdinv = 1./sg1bd; + % + Hptd(1:nvar,1:nvar)=diag(sg1bd); + Hptdinv(1:nvar,1:nvar)=diag(sg1bdinv); + if lags>1 + factorpp=asymp(nvar+1:ncoef-1,i); + sgpp_cbd = sgppbd(1:ncoef-nvar-1) .* factorpp; + sgpp_cbdinv = 1./sgpp_cbd; + Hptd(nvar+1:ncoef-1,nvar+1:ncoef-1)=diag(sgpp_cbd); + Hptdinv(nvar+1:ncoef-1,nvar+1:ncoef-1)=diag(sgpp_cbdinv); + % condtional on A0i, H_plus_tilde + end + end + Hpmulti(:,:,i)=Hptd; + Hpinvmulti(:,:,i)=Hptdinv; +end + + diff --git a/MatlabFiles/fn_rnrprior_covres.m b/MatlabFiles/fn_rnrprior_covres.m new file mode 100755 index 0000000..9d7b6f5 --- /dev/null +++ b/MatlabFiles/fn_rnrprior_covres.m @@ -0,0 +1,243 @@ +function [Pi,H0multi,Hpmulti,H0invmulti,Hpinvmulti] ... + = fn_rnrprior_covres(nvar,q_m,lags,xdgel,mu,hpmsmd,indxmsmdeqn,nexo,asym0,asymp) +% [Pi,H0multi,Hpmulti,H0invmulti,Hpinvmulti] ... +% = fn_rnrprior_covres(nvar,q_m,lags,xdgel,mu,hpmsmd,indxmsmdeqn,nexo,asym0,asymp) +% +% More general than fn_rnrprior.m because when hpmsmd=0, fn_rnrprior_covres() is the same as fn_rnrprior(). +% Allows for prior covariances for the MS and MD equations to achieve liquidity effects. +% Exports random Bayesian prior of Sims and Zha with asymmetric rior (but no linear restrictions yet) +% See Waggoner and Zha's Gibbs sampling paper and TVBVAR NOTES p. 71k.0. +% +% nvar: number of endogenous variables +% q_m: quarter or month +% lags: the maximum length of lag +% xdgel: the general matrix of the original data (no manipulation involved) +% with sample size including lags. Used only to get variances of residuals for +% the scaling purpose; NOT used for mu(5) and mu(6). +% mu: 6-by-1 vector of hyperparameters (the following numbers for Atlanta Fed's forecast), where +% mu(5) and mu(6) are NOT used here. See fn_dataxy.m for using mu(5) and mu(6). +% mu(1): overall tightness and also for A0; (0.57) +% mu(2): relative tightness for A+; (0.13) +% mu(3): relative tightness for the constant term; (0.1). NOTE: for other +% exogenous terms, the variance of each exogenous term must be taken into +% acount to eliminate the scaling factor. +% mu(4): tightness on lag decay; (1) +% mu(5): weight on nvar sums of coeffs dummy observations (unit roots); (5) +% mu(6): weight on single dummy initial observation including constant +% (cointegration, unit roots, and stationarity); (5) +% NOTE: for this subdirectory, mu(5) and mu(6) are not used. See fn_dataxy.m for using mu(5) and mu(6). +% hpmsmd: 2-by-1 hyperparameters with -1<h1=hpmsmd(1)<=0 for the MS equation and 0<=h2=hpmsmd(2)<1 the MD equation. Consider a1*R + a2*M. +% The term h1*var(a1)*var(a2) is the prior covariance of a1 and a2 for MS, equivalent to penalizing the same sign of a1 and a2. +% The term h2*var(a1)*var(a2) is the prior covariance of a1 and a2 for MD, equivalent to penalizing opposite signs of a1 and a2. +% This will give us a liquidity effect. +% indxmsmdeqn: 4-by-1 index for the locations of the MS and MD equation and for the locations of M and R. +% indxmsmdeqn(1) for MS and indxmsmdeqn(2) for MD. +% indxmsmdeqn(3) for M and indxmsmdeqn(4) for R. +% nexo: number of exogenous variables (if not specified, nexo=1 (constant) by default). +% The constant term is always put to the last of all endogenous and exogenous variables. +% asym0: nvar-by-nvar asymmetric prior on A0. Column -- equation. +% If ones(nvar,nvar), symmetric prior; if not, relative (asymmetric) tightness on A0. +% asymp: ncoef-1-by-nvar asymmetric prior on A+ bar constant. Column -- equation. +% If ones(ncoef-1,nvar), symmetric prior; if not, relative (asymmetric) tightness on A+. +% -------------------- +% Pi: ncoef-by-nvar matrix for the ith equation under random walk. Same for all equations +% H0multi: nvar-by-nvar-by-nvar; H0 for different equations under asymmetric prior +% Hpmulti: ncoef-by-ncoef-by-nvar; H+ for different equations under asymmetric prior +% H0invmulti: nvar-by-nvar-by-nvar; inv(H0) for different equations under asymmetric prior +% Hpinvmulti: ncoef-by-ncoef-by-nvar; inv(H+) for different equations under asymmetric prior +% +% Tao Zha, February 2000. Revised, September 2000, February 2003. + + + +if nargin==7, nexo=1; end +ncoef = nvar*lags+nexo; % number of coefficients in *each* equation, RHS coefficients only. + +H0multi=zeros(nvar,nvar,nvar); % H0 for different equations under asymmetric prior +Hpmulti=zeros(ncoef,ncoef,nvar); % H+ for different equations under asymmetric prior +H0invmulti=zeros(nvar,nvar,nvar); % inv(H0) for different equations under asymmetric prior +Hpinvmulti=zeros(ncoef,ncoef,nvar); % inv(H+) for different equations under asymmetric prior + +%*** Constructing Pi for the ith equation under the random walk assumption +Pi = zeros(ncoef,nvar); % same for all equations +Pi(1:nvar,1:nvar) = eye(nvar); % random walk + +% +%@@@ Prepared for Bayesian prior +% +% +% ** monthly lag decay in order to match quarterly decay: a*exp(bl) where +% ** l is the monthly lag. Suppose quarterly decay is 1/x where x=1,2,3,4. +% ** Let the decay of l1 (a*exp(b*l1)) match that of x1 (say, beginning: 1/1) +% ** and the decay of l2 (a*exp(b*l2)) match that of x2 (say, end: 1/5), +% ** we can solve for a and b which are +% ** b = (log_x1-log_x2)/(l1-l2), and a = x1*exp(-b*l1). +if q_m==12 + l1 = 1; % 1st month == 1st quarter + xx1 = 1; % 1st quarter + l2 = lags; % last month + xx2 = 1/((ceil(lags/3))^mu(4)); % last quarter + %xx2 = 1/6; % last quarter + % 3rd quarter: i.e., we intend to let decay of the 6th month match + % that of the 3rd quarter, so that the 6th month decays a little + % faster than the second quarter which is 1/2. + if lags==1 + b = 0; + else + b = (log(xx1)-log(xx2))/(l1-l2); + end + a = xx1*exp(-b*l1); +end + + + +% +% *** specify the prior for each equation separately, SZ method, +% ** get the residuals from univariate regressions. +% +sgh = zeros(nvar,1); % square root +sgsh = sgh; % square +nSample=size(xdgel,1); % sample size-lags +yu = xdgel; +C = ones(nSample,1); +for k=1:nvar + [Bk,ek,junk1,junk2,junk3,junk4] = sye([yu(:,k) C],lags); + clear Bk junk1 junk2 junk3 junk4; + sgsh(k) = ek'*ek/(nSample-lags); + sgh(k) = sqrt(sgsh(k)); +end +% ** prior variance for A0(:,1), same for all equations!!! +sg0bid = zeros(nvar,1); % Sigma0_bar diagonal only for the ith equation +for j=1:nvar + sg0bid(j) = 1/sgsh(j); % sgsh = sigmai^2 +end +% ** prior variance for lagged and exogeous variables, same for all equations +sgpbid = zeros(ncoef,1); % Sigma_plus_bar, diagonal, for the ith equation +for i = 1:lags + if (q_m==12) + lagdecay = a*exp(b*i*mu(4)); + end + % + for j = 1:nvar + if (q_m==12) + % exponential decay to match quarterly decay + sgpbid((i-1)*nvar+j) = lagdecay^2/sgsh(j); % ith equation + elseif (q_m==4) + sgpbid((i-1)*nvar+j) = (1/i^mu(4))^2/sgsh(j); % ith equation + else + error('Incompatibility with lags, check the possible errors!!!') + %warning('Incompatibility with lags, check the possible errors!!!') + %return + end + end +end +% + + +%================================================= +% Computing the (prior) covariance matrix for the posterior of A0, no data yet +%================================================= +% +% +% ** set up the conditional prior variance sg0bi and sgpbi. +sg0bida = mu(1)^2*sg0bid; % ith equation +sgpbida = mu(1)^2*mu(2)^2*sgpbid; +sgpbida(ncoef-nexo+1:ncoef) = mu(1)^2*mu(3)^2; + %<<>> No scaling adjustment has been made for exogenous terms other than constant +sgppbd = sgpbida(nvar+1:ncoef); % corresponding to A++, in a Sims-Zha paper + +Hptd = zeros(ncoef); +Hptdi=Hptd; +Hptd(ncoef,ncoef)=sgppbd(ncoef-nvar); +Hptdinv(ncoef,ncoef)=1./sgppbd(ncoef-nvar); + % condtional on A0i, H_plus_tilde + + +if nargin<9 % the default is no asymmetric information + asym0 = ones(nvar,nvar); % if not ones, then we have relative (asymmetric) tightness + asymp = ones(ncoef-1,nvar); % for A+. Column -- equation +end + +%**** Asymmetric Information +%asym0 = ones(nvar,nvar); % if not ones, then we have relative (asymmetric) tightness +%asymp = ones(ncoef-1,nvar); % pp: plus without constant. Column -- equation +%>>>>>> B: asymmetric prior variance for asymp <<<<<<<< +% +%for i = 1:lags +% rowif = (i-1)*nvar+1; +% rowil = i*nvar; +% idmatw0 = 0.5; % weight assigned to idmat0 in the formation of asymp +% if (i==1) +% asymp(rowif:rowil,:)=(1-idmatw0)*ones(nvar)+idmatw0*idmat0; % first lag +% % note: idmat1 is already transposed. Column -- equation +% else +% %asymp(rowif:rowil,1:nvar) = (1-idmatw0)*ones(nvar)+idmatw0*idmat0; +% % <<<<<<< toggle + +% % Note: already transposed, since idmat0 is transposed. +% % Meaning: column implies equation +% asymp(rowif:rowil,1:nvar) = ones(nvar); +% % >>>>>>> toggle - +% end +%end +% +%>>>>>> E: asymmetric prior variance for asymp <<<<<<<< + + +%================================================= +% Computing the final covariance matrix (S1,...,Sm) for the prior of A0, +% and final Gb=(G1,...,Gm) for A+ if asymmetric prior or for +% B if symmetric prior for A+ +%================================================= +% +for i = 1:nvar + %------------------------------ + % Introduce prior information on which variables "belong" in various equations. + % In this first trial, we just introduce this information here, in a model-specific way. + % Eventually this info has to be passed parametricly. In our first shot, we just damp down + % all coefficients except those on the diagonal. + + %*** For A0 + factor0=asym0(:,i); + sg0bd = sg0bida.*factor0; % Note, this only works for the prior variance Sg(i) + % of a0(i) being diagonal. If the prior variance Sg(i) is not + % diagonal, we have to the inverse to get inv(Sg(i)). + %sg0bdinv = 1./sg0bd; + % * unconditional variance on A0+ + H0td = diag(sg0bd); % unconditional + %=== Correlation in the MS equation to get a liquidity effect. + if (i==indxmsmdeqn(1)) + H0td(indxmsmdeqn(3),indxmsmdeqn(4)) = hpmsmd(1)*sqrt(sg0bida(indxmsmdeqn(3))*sg0bida(indxmsmdeqn(4))); + H0td(indxmsmdeqn(4),indxmsmdeqn(3)) = hpmsmd(1)*sqrt(sg0bida(indxmsmdeqn(3))*sg0bida(indxmsmdeqn(4))); + else + H0td(indxmsmdeqn(3),indxmsmdeqn(4)) = hpmsmd(2)*sqrt(sg0bida(indxmsmdeqn(3))*sg0bida(indxmsmdeqn(4))); + H0td(indxmsmdeqn(4),indxmsmdeqn(3)) = hpmsmd(2)*sqrt(sg0bida(indxmsmdeqn(3))*sg0bida(indxmsmdeqn(4))); + end + H0tdinv = inv(H0td); + %H0tdinv = diag(sg0bdinv); + % + H0multi(:,:,i)=H0td; + H0invmulti(:,:,i)=H0tdinv; + + + %*** For A+ + if ~(lags==0) % For A1 to remain random walk properties + factor1=asymp(1:nvar,i); + sg1bd = sgpbida(1:nvar).*factor1; + sg1bdinv = 1./sg1bd; + % + Hptd(1:nvar,1:nvar)=diag(sg1bd); + Hptdinv(1:nvar,1:nvar)=diag(sg1bdinv); + if lags>1 + factorpp=asymp(nvar+1:ncoef-1,i); + sgpp_cbd = sgppbd(1:ncoef-nvar-1) .* factorpp; + sgpp_cbdinv = 1./sgpp_cbd; + Hptd(nvar+1:ncoef-1,nvar+1:ncoef-1)=diag(sgpp_cbd); + Hptdinv(nvar+1:ncoef-1,nvar+1:ncoef-1)=diag(sgpp_cbdinv); + % condtional on A0i, H_plus_tilde + end + end + Hpmulti(:,:,i)=Hptd; + Hpinvmulti(:,:,i)=Hptdinv; +end + + diff --git a/MatlabFiles/fn_rnrprior_covres_dobs.m b/MatlabFiles/fn_rnrprior_covres_dobs.m new file mode 100755 index 0000000..53a7213 --- /dev/null +++ b/MatlabFiles/fn_rnrprior_covres_dobs.m @@ -0,0 +1,281 @@ +function [Pi,H0multi,Hpmulti,H0invmulti,Hpinvmulti,sgh] ... + = fn_rnrprior_covres_dobs(nvar,q_m,lags,xdgel,mu,indxDummy,hpmsmd,indxmsmdeqn,nexo,asym0,asymp) +% Differs from fn_rnrprior_covres_dobs_tv(): no linear restrictions (Ui and Vi) have applied yet to this function, but +% linear restrictions are incorported in fn_rnrprior_covres_dobs_tv(). +% +% Only works for the nexo=1 (constant term) case. To extend this to other exogenous variables, see fn_dataxy.m. 01/14/03. +% Differs from fn_rnrprior_covres.m in that dummy observations are included as part of the explicit prior. See Forcast II, pp.68-69b. +% More general than fn_rnrprior.m because when hpmsmd=0, fn_rnrprior_covres() is the same as fn_rnrprior(). +% Allows for prior covariances for the MS and MD equations to achieve liquidity effects. +% Exports random Bayesian prior of Sims and Zha with asymmetric rior (but no linear restrictions yet) +% See Waggoner and Zha's Gibbs sampling paper and TVBVAR NOTES p. 71k.0. +% +% nvar: number of endogenous variables +% q_m: quarter or month +% lags: the maximum length of lag +% xdgel: T*nvar endogenous-variable matrix of raw or original data (no manipulation involved) with sample size including lags. +% Order of columns: (1) nvar endogenous variables; (2) constants will be automatically put in the last column. +% Used only to get variances of residuals for mu(1)-mu(5) and for dummy observations mu(5) and mu(6). +% mu: 6-by-1 vector of hyperparameters (the following numbers for Atlanta Fed's forecast), where +% mu(5) and mu(6) are NOT used here. See fn_dataxy.m for using mu(5) and mu(6). +% mu(1): overall tightness and also for A0; (0.57) +% mu(2): relative tightness for A+; (0.13) +% mu(3): relative tightness for the constant term; (0.1). NOTE: for other +% exogenous terms, the variance of each exogenous term must be taken into +% acount to eliminate the scaling factor. +% mu(4): tightness on lag decay; (1) +% mu(5): weight on nvar sums of coeffs dummy observations (unit roots); (5) +% mu(6): weight on single dummy initial observation including constant +% (cointegration, unit roots, and stationarity); (5) +% indxDummy: 1: uses dummy observations to form part of an explicit prior; 0: no dummy observations as part of the prior. +% hpmsmd: 2-by-1 hyperparameters with -1<h1=hpmsmd(1)<=0 for the MS equation and 0<=h2=hpmsmd(2)<1 the MD equation. Consider a1*R + a2*M. +% The term h1*var(a1)*var(a2) is the prior covariance of a1 and a2 for MS, equivalent to penalizing the same sign of a1 and a2. +% The term h2*var(a1)*var(a2) is the prior covariance of a1 and a2 for MD, equivalent to penalizing opposite signs of a1 and a2. +% This will give us a liquidity effect. +% indxmsmdeqn: 4-by-1 index for the locations of the MS and MD equation and for the locations of M and R. +% indxmsmdeqn(1) for MS and indxmsmdeqn(2) for MD. +% indxmsmdeqn(3) for M and indxmsmdeqn(4) for R. +% nexo: number of exogenous variables (if not specified, nexo=1 (constant) by default). +% The constant term is always put to the last of all endogenous and exogenous variables. +% asym0: nvar-by-nvar asymmetric prior on A0. Column -- equation. +% If ones(nvar,nvar), symmetric prior; if not, relative (asymmetric) tightness on A0. +% asymp: ncoef-1-by-nvar asymmetric prior on A+ bar constant. Column -- equation. +% If ones(ncoef-1,nvar), symmetric prior; if not, relative (asymmetric) tightness on A+. +% -------------------- +% Pi: ncoef-by-nvar matrix for the ith equation under random walk. Same for all equations +% H0multi: nvar-by-nvar-by-nvar; H0 for different equations under asymmetric prior +% Hpmulti: ncoef-by-ncoef-by-nvar; H+ for different equations under asymmetric prior +% H0invmulti: nvar-by-nvar-by-nvar; inv(H0) for different equations under asymmetric prior +% Hpinvmulti: ncoef-by-ncoef-by-nvar; inv(H+) for different equations under asymmetric prior +% sgh: nvar-by-1 standard deviations of residuals for each equation. +% +% Tao Zha, February 2000. Revised, September 2000, February, May 2003. + + + +if (nargin<=8), nexo=1; end +ncoef = nvar*lags+nexo; % number of coefficients in *each* equation, RHS coefficients only. + +H0multi=zeros(nvar,nvar,nvar); % H0 for different equations under asymmetric prior +Hpmulti=zeros(ncoef,ncoef,nvar); % H+ for different equations under asymmetric prior +H0invmulti=zeros(nvar,nvar,nvar); % inv(H0) for different equations under asymmetric prior +Hpinvmulti=zeros(ncoef,ncoef,nvar); % inv(H+) for different equations under asymmetric prior + +%*** Constructing Pi for the ith equation under the random walk assumption +Pi = zeros(ncoef,nvar); % same for all equations +Pi(1:nvar,1:nvar) = eye(nvar); % random walk + +% +%@@@ Prepared for Bayesian prior +% +% +% ** monthly lag decay in order to match quarterly decay: a*exp(bl) where +% ** l is the monthly lag. Suppose quarterly decay is 1/x where x=1,2,3,4. +% ** Let the decay of l1 (a*exp(b*l1)) match that of x1 (say, beginning: 1/1) +% ** and the decay of l2 (a*exp(b*l2)) match that of x2 (say, end: 1/5), +% ** we can solve for a and b which are +% ** b = (log_x1-log_x2)/(l1-l2), and a = x1*exp(-b*l1). +if q_m==12 + l1 = 1; % 1st month == 1st quarter + xx1 = 1; % 1st quarter + l2 = lags; % last month + xx2 = 1/((ceil(lags/3))^mu(4)); % last quarter + %xx2 = 1/6; % last quarter + % 3rd quarter: i.e., we intend to let decay of the 6th month match + % that of the 3rd quarter, so that the 6th month decays a little + % faster than the second quarter which is 1/2. + if lags==1 + b = 0; + else + b = (log(xx1)-log(xx2))/(l1-l2); + end + a = xx1*exp(-b*l1); +end + + + +% +% *** specify the prior for each equation separately, SZ method, +% ** get the residuals from univariate regressions. +% +sgh = zeros(nvar,1); % square root +sgsh = sgh; % square +nSample=size(xdgel,1); % sample size-lags +yu = xdgel; +C = ones(nSample,1); +for k=1:nvar + [Bk,ek,junk1,junk2,junk3,junk4] = sye([yu(:,k) C],lags); + clear Bk junk1 junk2 junk3 junk4; + sgsh(k) = ek'*ek/(nSample-lags); + sgh(k) = sqrt(sgsh(k)); +end +% ** prior variance for A0(:,1), same for all equations!!! +sg0bid = zeros(nvar,1); % Sigma0_bar diagonal only for the ith equation +for j=1:nvar + sg0bid(j) = 1/sgsh(j); % sgsh = sigmai^2 +end +% ** prior variance for lagged and exogeous variables, same for all equations +sgpbid = zeros(ncoef,1); % Sigma_plus_bar, diagonal, for the ith equation +for i = 1:lags + if (q_m==12) + lagdecay = a*exp(b*i*mu(4)); + end + % + for j = 1:nvar + if (q_m==12) + % exponential decay to match quarterly decay + sgpbid((i-1)*nvar+j) = lagdecay^2/sgsh(j); % ith equation + elseif (q_m==4) + sgpbid((i-1)*nvar+j) = (1/i^mu(4))^2/sgsh(j); % ith equation + else + error('Incompatibility with lags, check the possible errors!!!') + %warning('Incompatibility with lags, check the possible errors!!!') + %return + end + end +end +% + +if indxDummy % Dummy observations as part of the explicit prior. + ndobs=nvar+1; % Number of dummy observations: nvar unit roots and 1 cointegration prior. + phibar = zeros(ndobs,ncoef); + %* constant term + const = ones(nvar+1,1); + const(1:nvar) = 0.0; + phibar(:,ncoef) = const; % the first nvar periods: no or zero constant! + + xdgelint = mean(xdgel(1:lags,:),1); % mean of the first lags initial conditions + %* Dummies + for k=1:nvar + for m=1:lags + phibar(ndobs,nvar*(m-1)+k) = xdgelint(k); + phibar(k,nvar*(m-1)+k) = xdgelint(k); + % <<>> multiply hyperparameter later + end + end + phibar(1:nvar,:) = 1*mu(5)*phibar(1:nvar,:); % standard Sims and Zha prior + phibar(ndobs,:) = mu(6)*phibar(ndobs,:); + [phiq,phir]=qr(phibar,0); + xtxbar=phir'*phir; % phibar'*phibar. ncoef-by-ncoef. Reduced (not full) rank. See Forcast II, pp.69-69b. +end + +%================================================= +% Computing the (prior) covariance matrix for A0, no data yet. +% As proved in pp.69a-69b, Forecast II, the following prior covariance of A0 +% will remain the same after the dummy observations prior is incorporated. +% The dummy observation prior only affects the prior covariance of A+|A0. +% See pp.69a-69b for the proof. +%================================================= +% +% +% ** set up the conditional prior variance sg0bi and sgpbi. +sg0bida = mu(1)^2*sg0bid; % ith equation +sgpbida = mu(1)^2*mu(2)^2*sgpbid; +sgpbida(ncoef-nexo+1:ncoef) = mu(1)^2*mu(3)^2; + %<<>> No scaling adjustment has been made for exogenous terms other than constant +sgppbd = sgpbida(nvar+1:ncoef); % corresponding to A++, in a Sims-Zha paper + +Hptd = zeros(ncoef); +Hptdi=Hptd; +Hptd(ncoef,ncoef)=sgppbd(ncoef-nvar); +Hptdinv(ncoef,ncoef)=1./sgppbd(ncoef-nvar); + % condtional on A0i, H_plus_tilde + + +if nargin<10 % the default is no asymmetric information + asym0 = ones(nvar,nvar); % if not ones, then we have relative (asymmetric) tightness + asymp = ones(ncoef-1,nvar); % for A+. Column -- equation +end + +%**** Asymmetric Information +%asym0 = ones(nvar,nvar); % if not ones, then we have relative (asymmetric) tightness +%asymp = ones(ncoef-1,nvar); % pp: plus without constant. Column -- equation +%>>>>>> B: asymmetric prior variance for asymp <<<<<<<< +% +%for i = 1:lags +% rowif = (i-1)*nvar+1; +% rowil = i*nvar; +% idmatw0 = 0.5; % weight assigned to idmat0 in the formation of asymp +% if (i==1) +% asymp(rowif:rowil,:)=(1-idmatw0)*ones(nvar)+idmatw0*idmat0; % first lag +% % note: idmat1 is already transposed. Column -- equation +% else +% %asymp(rowif:rowil,1:nvar) = (1-idmatw0)*ones(nvar)+idmatw0*idmat0; +% % <<<<<<< toggle + +% % Note: already transposed, since idmat0 is transposed. +% % Meaning: column implies equation +% asymp(rowif:rowil,1:nvar) = ones(nvar); +% % >>>>>>> toggle - +% end +%end +% +%>>>>>> E: asymmetric prior variance for asymp <<<<<<<< + + +%================================================= +% Computing the final covariance matrix (S1,...,Sm) for the prior of A0, +% and final Gb=(G1,...,Gm) for A+ if asymmetric prior or for +% B if symmetric prior for A+ +%================================================= +% +for i = 1:nvar + %------------------------------ + % Introduce prior information on which variables "belong" in various equations. + % In this first trial, we just introduce this information here, in a model-specific way. + % Eventually this info has to be passed parametricly. In our first shot, we just damp down + % all coefficients except those on the diagonal. + + %*** For A0 + factor0=asym0(:,i); + sg0bd = sg0bida.*factor0; % Note, this only works for the prior variance Sg(i) + % of a0(i) being diagonal. If the prior variance Sg(i) is not + % diagonal, we have to the inverse to get inv(Sg(i)). + %sg0bdinv = 1./sg0bd; + % * unconditional variance on A0+ + H0td = diag(sg0bd); % unconditional + %=== Correlation in the MS equation to get a liquidity effect. + if (i==indxmsmdeqn(1)) + H0td(indxmsmdeqn(3),indxmsmdeqn(4)) = hpmsmd(1)*sqrt(sg0bida(indxmsmdeqn(3))*sg0bida(indxmsmdeqn(4))); + H0td(indxmsmdeqn(4),indxmsmdeqn(3)) = hpmsmd(1)*sqrt(sg0bida(indxmsmdeqn(3))*sg0bida(indxmsmdeqn(4))); + elseif (i==indxmsmdeqn(2)) + H0td(indxmsmdeqn(3),indxmsmdeqn(4)) = hpmsmd(2)*sqrt(sg0bida(indxmsmdeqn(3))*sg0bida(indxmsmdeqn(4))); + H0td(indxmsmdeqn(4),indxmsmdeqn(3)) = hpmsmd(2)*sqrt(sg0bida(indxmsmdeqn(3))*sg0bida(indxmsmdeqn(4))); + end + H0tdinv = inv(H0td); + %H0tdinv = diag(sg0bdinv); + % + H0multi(:,:,i)=H0td; + H0invmulti(:,:,i)=H0tdinv; + + + %*** For A+ + if ~(lags==0) % For A1 to remain random walk properties + factor1=asymp(1:nvar,i); + sg1bd = sgpbida(1:nvar).*factor1; + sg1bdinv = 1./sg1bd; + % + Hptd(1:nvar,1:nvar)=diag(sg1bd); + Hptdinv(1:nvar,1:nvar)=diag(sg1bdinv); + if lags>1 + factorpp=asymp(nvar+1:ncoef-1,i); + sgpp_cbd = sgppbd(1:ncoef-nvar-1) .* factorpp; + sgpp_cbdinv = 1./sgpp_cbd; + Hptd(nvar+1:ncoef-1,nvar+1:ncoef-1)=diag(sgpp_cbd); + Hptdinv(nvar+1:ncoef-1,nvar+1:ncoef-1)=diag(sgpp_cbdinv); + % condtional on A0i, H_plus_tilde + end + end + %--------------- + % The dummy observation prior affects only the prior covariance of A+|A0, + % but not the covariance of A0. See pp.69a-69b for the proof. + %--------------- + if indxDummy % Dummy observations as part of the explicit prior. + Hpinvmulti(:,:,i)=Hptdinv + xtxbar; + Hpmulti(:,:,i) = inv(Hpinvmulti(:,:,i)); + else + Hpmulti(:,:,i)=Hptd; + Hpinvmulti(:,:,i)=Hptdinv; + end +end + + diff --git a/MatlabFiles/fn_rnrprior_covres_dobs_tv.m b/MatlabFiles/fn_rnrprior_covres_dobs_tv.m new file mode 100755 index 0000000..6ac0695 --- /dev/null +++ b/MatlabFiles/fn_rnrprior_covres_dobs_tv.m @@ -0,0 +1,294 @@ +function [Pi_bar,H0tldcell_inv,Hptldcell_inv] ... + = fn_rnrprior_covres_dobs_tv(nvar,nStates,q_m,lags,xdgel,mu,indxDummy,Ui,Vi,hpmsmd,indxmsmdeqn,nexo,asym0,asymp) +% Differs from fn_rnrprior_covres_dobs_tv(): no linear restrictions (Ui and Vi) have applied yet to this function, but +% linear restrictions are incorported in fn_rnrprior_covres_dobs_tv(). +% +% Only works for the nexo=1 (constant term) case. To extend this to other exogenous variables, see fn_dataxy.m. 01/14/03. +% Differs from fn_rnrprior_covres_tv.m in that dummy observations are included as part of the explicit prior. See Forcast II, pp.68-69b. +% Exports random Bayesian prior of Sims and Zha with asymmetric rior with linear restrictions already applied +% and with dummy observations (i.e., mu(5) and mu(6)) used as part of an explicit prior. +% This function allows for prior covariances for the MS and MD equations to achieve liquidity effects. +% See Waggoner and Zha's Gibbs sampling paper and TVBVAR NOTES pp. 71k.0 and 50-61. +% +% nvar: number of endogenous variables +% nStates: Number of states. +% q_m: quarter or month +% lags: the maximum length of lag +% xdgel: T*nvar endogenous-variable matrix of raw or original data (no manipulation involved) with sample size including lags. +% Order of columns: (1) nvar endogenous variables; (2) constants will be automatically put in the last column. +% Used only to get variances of residuals for mu(1)-mu(5) and for dummy observations mu(5) and mu(6). +% mu: 6-by-1 vector of hyperparameters (the following numbers for Atlanta Fed's forecast), where +% mu(5) and mu(6) are NOT used here. See fn_dataxy.m for using mu(5) and mu(6). +% mu(1): overall tightness and also for A0; (0.57) +% mu(2): relative tightness for A+; (0.13) +% mu(3): relative tightness for the constant term; (0.1). NOTE: for other +% exogenous terms, the variance of each exogenous term must be taken into +% acount to eliminate the scaling factor. +% mu(4): tightness on lag decay; (1) +% mu(5): weight on nvar sums of coeffs dummy observations (unit roots); (5) +% mu(6): weight on single dummy initial observation including constant +% (cointegration, unit roots, and stationarity); (5) +% NOTE: for this function, mu(5) and mu(6) are not used. See fn_dataxy.m for using mu(5) and mu(6). +% indxDummy: 1: uses dummy observations to form part of an explicit prior; 0: no dummy observations as part of the prior. +% Ui: nvar-by-1 cell. In each cell, nvar-by-qi*si orthonormal basis for the null of the ith +% equation contemporaneous restriction matrix where qi is the number of free parameters +% within the state and si is the number of free states. +% With this transformation, we have ai = Ui*bi or Ui'*ai = bi where ai is a vector +% of total original parameters and bi is a vector of free parameters. When no +% restrictions are imposed, we have Ui = I. There must be at least one free +% parameter left for the ith equation in the order of [a_i for 1st state, ..., a_i for last state]. +% Vi: nvar-by-1 cell. In each cell, k-by-ri*ti orthonormal basis for the null of the ith +% equation lagged restriction matrix where k is a total of exogenous variables and +% ri is the number of free parameters within the state and ti is the number of free states. +% With this transformation, we have fi = Vi*gi +% or Vi'*fi = gi where fi is a vector of total original parameters and gi is a +% vector of free parameters. The ith equation is in the order of [nvar variables +% for 1st lag and 1st state, ..., nvar variables for last lag and 1st state, const for 1st state, nvar +% variables for 1st lag and 2nd state, nvar variables for last lag and 2nd state, const for 2nd state, and so on]. +% hpmsmd: 2-by-1 hyperparameters with -1<h1=hpmsmd(1)<=0 for the MS equation and 0<=h2=hpmsmd(2)<1 the MD equation. Consider a1*R + a2*M. +% The term h1*var(a1)*var(a2) is the prior covariance of a1 and a2 for MS, equivalent to penalizing the same sign of a1 and a2. +% The term h2*var(a1)*var(a2) is the prior covariance of a1 and a2 for MD, equivalent to penalizing opposite signs of a1 and a2. +% This will give us a liquidity effect. If hpmsmd=0, no such restrictions will be imposed. +% indxmsmdeqn: 4-by-1 index for the locations of the MS and MD equation and for the locations of M and R. +% indxmsmdeqn(1) for MS and indxmsmdeqn(2) for MD. +% indxmsmdeqn(3) for M and indxmsmdeqn(4) for R. +% nexo: number of exogenous variables (if not specified, nexo=1 (constant) by default). +% The constant term is always put to the last of all endogenous and exogenous variables. +% asym0: nvar-by-nvar asymmetric prior on A0. Column -- equation. +% If ones(nvar,nvar), symmetric prior; if not, relative (asymmetric) tightness on A0. +% asymp: ncoef-1-by-nvar asymmetric prior on A+ bar constant. Column -- equation. +% If ones(ncoef-1,nvar), symmetric prior; if not, relative (asymmetric) tightness on A+. +% -------------------- +% Pi_bar: ncoef-by-nvar matrix for the ith equation under random walk. Same for all equations +% H0tldcell_inv: cell(nvar,1). The ith cell represents the ith equation, where the dim is +% qi*si-by-qi*si. The inverse of H0tld on p.60. +% Hptldcell_inv: cell(nvar,1). The ith cell represents the ith equation, where the dim is +% ri*ti-by-ri*ti.The inverse of Hptld on p.60. +% +% Tao Zha, February 2000. Revised, September 2000, 2001, February, May 2003. + + +if nargin<=11, nexo=1; end % <<>>1 +ncoef = nvar*lags+nexo; % Number of coefficients in *each* equation for each state, RHS coefficients only. +ncoefsts = nStates*ncoef; % Number of coefficients in *each* equation in all states, RHS coefficients only. + +H0tldcell_inv=cell(nvar,1); % inv(H0tilde) for different equations under asymmetric prior. +Hptldcell_inv=cell(nvar,1); % inv(H+tilde) for different equations under asymmetric prior. + +%*** Constructing Pi_bar for the ith equation under the random walk assumption +Pi_bar = zeros(ncoef,nvar); % same for all equations +Pi_bar(1:nvar,1:nvar) = eye(nvar); % random walk + +% +%@@@ Prepared for Bayesian prior +% +% +% ** monthly lag decay in order to match quarterly decay: a*exp(bl) where +% ** l is the monthly lag. Suppose quarterly decay is 1/x where x=1,2,3,4. +% ** Let the decay of l1 (a*exp(b*l1)) match that of x1 (say, beginning: 1/1) +% ** and the decay of l2 (a*exp(b*l2)) match that of x2 (say, end: 1/5), +% ** we can solve for a and b which are +% ** b = (log_x1-log_x2)/(l1-l2), and a = x1*exp(-b*l1). +if q_m==12 + l1 = 1; % 1st month == 1st quarter + xx1 = 1; % 1st quarter + l2 = lags; % last month + xx2 = 1/((ceil(lags/3))^mu(4)); % last quarter + %xx2 = 1/6; % last quarter + % 3rd quarter: i.e., we intend to let decay of the 6th month match + % that of the 3rd quarter, so that the 6th month decays a little + % faster than the second quarter which is 1/2. + if lags==1 + b = 0; + else + b = (log(xx1)-log(xx2))/(l1-l2); + end + a = xx1*exp(-b*l1); +end + + + +% +% *** specify the prior for each equation separately, SZ method, +% ** get the residuals from univariate regressions. +% +sgh = zeros(nvar,1); % square root +sgsh = sgh; % square +nSample=size(xdgel,1); % sample size-lags +yu = xdgel; +C = ones(nSample,1); +for k=1:nvar + [Bk,ek,junk1,junk2,junk3,junk4] = sye([yu(:,k) C],lags); + clear Bk junk1 junk2 junk3 junk4; + sgsh(k) = ek'*ek/(nSample-lags); + sgh(k) = sqrt(sgsh(k)); +end +% ** prior variance for A0(:,1), same for all equations!!! +sg0bid = zeros(nvar,1); % Sigma0_bar diagonal only for the ith equation +for j=1:nvar + sg0bid(j) = 1/sgsh(j); % sgsh = sigmai^2 +end +% ** prior variance for lagged and exogeous variables, same for all equations +sgpbid = zeros(ncoef,1); % Sigma_plus_bar, diagonal, for the ith equation +for i = 1:lags + if (q_m==12) + lagdecay = a*exp(b*i*mu(4)); + end + % + for j = 1:nvar + if (q_m==12) + % exponential decay to match quarterly decay + sgpbid((i-1)*nvar+j) = lagdecay^2/sgsh(j); % ith equation + elseif (q_m==4) + sgpbid((i-1)*nvar+j) = (1/i^mu(4))^2/sgsh(j); % ith equation + else + error('Incompatibility with lags, check the possible errors!!!') + %warning('Incompatibility with lags, check the possible errors!!!') + %return + end + end +end +% +if indxDummy % Dummy observations as part of the explicit prior. + ndobs=nvar+1; % Number of dummy observations: nvar unit roots and 1 cointegration prior. + phibar = zeros(ndobs,ncoef); + %* constant term + const = ones(nvar+1,1); + const(1:nvar) = 0.0; + phibar(:,ncoef) = const; % the first nvar periods: no or zero constant! + + xdgelint = mean(xdgel(1:lags,:),1); % mean of the first lags initial conditions + %* Dummies + for k=1:nvar + for m=1:lags + phibar(ndobs,nvar*(m-1)+k) = xdgelint(k); + phibar(k,nvar*(m-1)+k) = xdgelint(k); + % <<>> multiply hyperparameter later + end + end + phibar(1:nvar,:) = 1*mu(5)*phibar(1:nvar,:); % standard Sims and Zha prior + phibar(ndobs,:) = mu(6)*phibar(ndobs,:); + [phiq,phir]=qr(phibar,0); + xtxbar=phir'*phir; % phibar'*phibar. ncoef-by-ncoef. Reduced (not full) rank. See Forcast II, pp.69-69b. +end + + + + + +%================================================= +% Computing the (prior) covariance matrix for the posterior of A0, no data yet +%================================================= +% +% +% ** set up the conditional prior variance sg0bi and sgpbi. +sg0bida = mu(1)^2*sg0bid; % ith equation +sgpbida = mu(1)^2*mu(2)^2*sgpbid; +sgpbida(ncoef-nexo+1:ncoef) = mu(1)^2*mu(3)^2; + %<<>> No scaling adjustment has been made for exogenous terms other than constant +sgppbd = sgpbida(nvar+1:ncoef); % corresponding to A++, in a Sims-Zha paper + +Hptd = zeros(ncoef); +Hptdi=Hptd; +Hptd(ncoef,ncoef)=sgppbd(ncoef-nvar); +Hptdinv(ncoef,ncoef)=1./sgppbd(ncoef-nvar); + % condtional on A0i, H_plus_tilde + + +if nargin<13 % <<>>1 Default is no asymmetric information + asym0 = ones(nvar,nvar); % if not ones, then we have relative (asymmetric) tightness + asymp = ones(ncoef-1,nvar); % for A+. Column -- equation +end + +%**** Asymmetric Information +%asym0 = ones(nvar,nvar); % if not ones, then we have relative (asymmetric) tightness +%asymp = ones(ncoef-1,nvar); % pp: plus without constant. Column -- equation +%>>>>>> B: asymmetric prior variance for asymp <<<<<<<< +% +%for i = 1:lags +% rowif = (i-1)*nvar+1; +% rowil = i*nvar; +% idmatw0 = 0.5; % weight assigned to idmat0 in the formation of asymp +% if (i==1) +% asymp(rowif:rowil,:)=(1-idmatw0)*ones(nvar)+idmatw0*idmat0; % first lag +% % note: idmat1 is already transposed. Column -- equation +% else +% %asymp(rowif:rowil,1:nvar) = (1-idmatw0)*ones(nvar)+idmatw0*idmat0; +% % <<<<<<< toggle + +% % Note: already transposed, since idmat0 is transposed. +% % Meaning: column implies equation +% asymp(rowif:rowil,1:nvar) = ones(nvar); +% % >>>>>>> toggle - +% end +%end +% +%>>>>>> E: asymmetric prior variance for asymp <<<<<<<< + + +%================================================= +% Computing the final covariance matrix (S1,...,Sm) for the prior of A0, +% and final Gb=(G1,...,Gm) for A+ if asymmetric prior or for +% B if symmetric prior for A+ +%================================================= +% +for i = 1:nvar + %------------------------------ + % Introduce prior information on which variables "belong" in various equations. + % In this first trial, we just introduce this information here, in a model-specific way. + % Eventually this info has to be passed parametricly. In our first shot, we just damp down + % all coefficients except those on the diagonal. + + %*** For A0 + factor0=asym0(:,i); + + sg0bd = sg0bida.*factor0; % Note, this only works for the prior variance Sg(i) + % of a0(i) being diagonal. If the prior variance Sg(i) is not + % diagonal, we have to the inverse to get inv(Sg(i)). + %sg0bdinv = 1./sg0bd; + % * unconditional variance on A0+ + H0td = diag(sg0bd); % unconditional + %=== Correlation in the MS equation to get a liquidity effect. + if (i==indxmsmdeqn(1)) + H0td(indxmsmdeqn(3),indxmsmdeqn(4)) = hpmsmd(1)*sqrt(sg0bida(indxmsmdeqn(3))*sg0bida(indxmsmdeqn(4))); + H0td(indxmsmdeqn(4),indxmsmdeqn(3)) = hpmsmd(1)*sqrt(sg0bida(indxmsmdeqn(3))*sg0bida(indxmsmdeqn(4))); + elseif (i==indxmsmdeqn(2)) + H0td(indxmsmdeqn(3),indxmsmdeqn(4)) = hpmsmd(2)*sqrt(sg0bida(indxmsmdeqn(3))*sg0bida(indxmsmdeqn(4))); + H0td(indxmsmdeqn(4),indxmsmdeqn(3)) = hpmsmd(2)*sqrt(sg0bida(indxmsmdeqn(3))*sg0bida(indxmsmdeqn(4))); + end + H0tdinv = inv(H0td); + %H0tdinv = diag(sg0bdinv); + % + H0tldcell_inv{i}=(Ui{i}'*kron(eye(nStates),H0tdinv/nStates))*Ui{i}; + + + %*** For A+ + if ~(lags==0) % For A1 to remain random walk properties + factor1=asymp(1:nvar,i); + sg1bd = sgpbida(1:nvar).*factor1; + sg1bdinv = 1./sg1bd; + % + Hptd(1:nvar,1:nvar)=diag(sg1bd); + Hptdinv(1:nvar,1:nvar)=diag(sg1bdinv); + if lags>1 + factorpp=asymp(nvar+1:ncoef-1,i); + sgpp_cbd = sgppbd(1:ncoef-nvar-1) .* factorpp; + sgpp_cbdinv = 1./sgpp_cbd; + Hptd(nvar+1:ncoef-1,nvar+1:ncoef-1)=diag(sgpp_cbd); + Hptdinv(nvar+1:ncoef-1,nvar+1:ncoef-1)=diag(sgpp_cbdinv); + % condtional on A0i, H_plus_tilde + end + end + %--------------- + % The dummy observation prior affects only the prior covariance of A+|A0, + % but not the covariance of A0. See pp.69a-69b for the proof. + %--------------- + if indxDummy % Dummy observations as part of the explicit prior. + Hptdinv2 = Hptdinv + xtxbar; % Rename Hptdinv to Hptdinv2 because we want to keep Hptdinv diagonal in the next loop of i. + else + Hptdinv2 = Hptdinv; + end + Hptldcell_inv{i}=(Vi{i}'*kron(eye(nStates),Hptdinv2/nStates))*Vi{i}; + %Hptdinv_3 = kron(eye(nStates),Hptdinv); % ????? +end + + diff --git a/MatlabFiles/fn_rnrprior_covres_dobs_tv2.m b/MatlabFiles/fn_rnrprior_covres_dobs_tv2.m new file mode 100755 index 0000000..88f5665 --- /dev/null +++ b/MatlabFiles/fn_rnrprior_covres_dobs_tv2.m @@ -0,0 +1,309 @@ +function [Pi_bar,H0tldcell_inv,Hptldcell_inv] ... + = fn_rnrprior_covres_dobs_tv2(nvar,nStates,indxScaleStates,q_m,lags,xdgel,mu,indxDummy,Ui,Vi,hpmsmd,indxmsmdeqn,nexo,asym0,asymp) +% Differs from fn_rnrprior_covres_dobs(): linear restrictions (Ui and Vi) have been incorported in fn_rnrprior_covres_dobs_tv?(). +% Differs from fn_rnrprior_covres_dobs_tv(): allows an option to scale up the prior variance by nStates or not scale at all, +% so that the prior value is the same as the constant VAR when the parameters in all states are the same. +% +% Only works for the nexo=1 (constant term) case. To extend this to other exogenous variables, see fn_dataxy.m. 01/14/03. +% Differs from fn_rnrprior_covres_tv.m in that dummy observations are included as part of the explicit prior. See Forcast II, pp.68-69b. +% Exports random Bayesian prior of Sims and Zha with asymmetric rior with linear restrictions already applied +% and with dummy observations (i.e., mu(5) and mu(6)) used as part of an explicit prior. +% This function allows for prior covariances for the MS and MD equations to achieve liquidity effects. +% See Waggoner and Zha's Gibbs sampling paper and TVBVAR NOTES pp. 71k.0 and 50-61. +% +% nvar: number of endogenous variables +% nStates: Number of states. +% indxScaleStates: if 0, no scale adjustment in the prior variance for the number of states in the function fn_rnrprior_covres_dobs_tv2(); +% if 1: allows a scale adjustment, marking the prior variance bigger by the number of states. +% q_m: quarter or month +% lags: the maximum length of lag +% xdgel: T*nvar endogenous-variable matrix of raw or original data (no manipulation involved) with sample size including lags. +% Order of columns: (1) nvar endogenous variables; (2) constants will be automatically put in the last column. +% Used only to get variances of residuals for mu(1)-mu(5) and for dummy observations mu(5) and mu(6). +% mu: 6-by-1 vector of hyperparameters (the following numbers for Atlanta Fed's forecast), where +% mu(5) and mu(6) are NOT used here. See fn_dataxy.m for using mu(5) and mu(6). +% mu(1): overall tightness and also for A0; (0.57) +% mu(2): relative tightness for A+; (0.13) +% mu(3): relative tightness for the constant term; (0.1). NOTE: for other +% exogenous terms, the variance of each exogenous term must be taken into +% acount to eliminate the scaling factor. +% mu(4): tightness on lag decay; (1) +% mu(5): weight on nvar sums of coeffs dummy observations (unit roots); (5) +% mu(6): weight on single dummy initial observation including constant +% (cointegration, unit roots, and stationarity); (5) +% NOTE: for this function, mu(5) and mu(6) are not used. See fn_dataxy.m for using mu(5) and mu(6). +% indxDummy: 1: uses dummy observations to form part of an explicit prior; 0: no dummy observations as part of the prior. +% Ui: nvar-by-1 cell. In each cell, nvar-by-qi*si orthonormal basis for the null of the ith +% equation contemporaneous restriction matrix where qi is the number of free parameters +% within the state and si is the number of free states. +% With this transformation, we have ai = Ui*bi or Ui'*ai = bi where ai is a vector +% of total original parameters and bi is a vector of free parameters. When no +% restrictions are imposed, we have Ui = I. There must be at least one free +% parameter left for the ith equation in the order of [a_i for 1st state, ..., a_i for last state]. +% Vi: nvar-by-1 cell. In each cell, k-by-ri*ti orthonormal basis for the null of the ith +% equation lagged restriction matrix where k is a total of exogenous variables and +% ri is the number of free parameters within the state and ti is the number of free states. +% With this transformation, we have fi = Vi*gi +% or Vi'*fi = gi where fi is a vector of total original parameters and gi is a +% vector of free parameters. The ith equation is in the order of [nvar variables +% for 1st lag and 1st state, ..., nvar variables for last lag and 1st state, const for 1st state, nvar +% variables for 1st lag and 2nd state, nvar variables for last lag and 2nd state, const for 2nd state, and so on]. +% hpmsmd: 2-by-1 hyperparameters with -1<h1=hpmsmd(1)<=0 for the MS equation and 0<=h2=hpmsmd(2)<1 the MD equation. Consider a1*R + a2*M. +% The term h1*var(a1)*var(a2) is the prior covariance of a1 and a2 for MS, equivalent to penalizing the same sign of a1 and a2. +% The term h2*var(a1)*var(a2) is the prior covariance of a1 and a2 for MD, equivalent to penalizing opposite signs of a1 and a2. +% This will give us a liquidity effect. If hpmsmd=0, no such restrictions will be imposed. +% indxmsmdeqn: 4-by-1 index for the locations of the MS and MD equation and for the locations of M and R. +% indxmsmdeqn(1) for MS and indxmsmdeqn(2) for MD. +% indxmsmdeqn(3) for M and indxmsmdeqn(4) for R. +% nexo: number of exogenous variables (if not specified, nexo=1 (constant) by default). +% The constant term is always put to the last of all endogenous and exogenous variables. +% asym0: nvar-by-nvar asymmetric prior on A0. Column -- equation. +% If ones(nvar,nvar), symmetric prior; if not, relative (asymmetric) tightness on A0. +% asymp: ncoef-1-by-nvar asymmetric prior on A+ bar constant. Column -- equation. +% If ones(ncoef-1,nvar), symmetric prior; if not, relative (asymmetric) tightness on A+. +% -------------------- +% Pi_bar: ncoef-by-nvar matrix for the ith equation under random walk. Same for all equations +% H0tldcell_inv: cell(nvar,1). The ith cell represents the ith equation, where the dim is +% qi*si-by-qi*si. The inverse of H0tld on p.60. +% Hptldcell_inv: cell(nvar,1). The ith cell represents the ith equation, where the dim is +% ri*ti-by-ri*ti.The inverse of Hptld on p.60. +% +% Differs from fn_rnrprior_covres_dobs(): linear restrictions (Ui and Vi) have been incorported in fn_rnrprior_covres_dobs_tv?(). +% Differs from fn_rnrprior_covres_dobs_tv(): allows an option to scale up the prior variance by nStates or not scale at all. +% so that the prior value is the same as the constant VAR when the parameters in all states are the same. +% Tao Zha, February 2000. Revised, September 2000, 2001, February, May 2003, May 2004. + + +if nargin<=12, nexo=1; end % <<>>1 +ncoef = nvar*lags+nexo; % Number of coefficients in *each* equation for each state, RHS coefficients only. +ncoefsts = nStates*ncoef; % Number of coefficients in *each* equation in all states, RHS coefficients only. + +H0tldcell_inv=cell(nvar,1); % inv(H0tilde) for different equations under asymmetric prior. +Hptldcell_inv=cell(nvar,1); % inv(H+tilde) for different equations under asymmetric prior. + +%*** Constructing Pi_bar for the ith equation under the random walk assumption +Pi_bar = zeros(ncoef,nvar); % same for all equations +Pi_bar(1:nvar,1:nvar) = eye(nvar); % random walk + +% +%@@@ Prepared for Bayesian prior +% +% +% ** monthly lag decay in order to match quarterly decay: a*exp(bl) where +% ** l is the monthly lag. Suppose quarterly decay is 1/x where x=1,2,3,4. +% ** Let the decay of l1 (a*exp(b*l1)) match that of x1 (say, beginning: 1/1) +% ** and the decay of l2 (a*exp(b*l2)) match that of x2 (say, end: 1/5), +% ** we can solve for a and b which are +% ** b = (log_x1-log_x2)/(l1-l2), and a = x1*exp(-b*l1). +if q_m==12 + l1 = 1; % 1st month == 1st quarter + xx1 = 1; % 1st quarter + l2 = lags; % last month + xx2 = 1/((ceil(lags/3))^mu(4)); % last quarter + %xx2 = 1/6; % last quarter + % 3rd quarter: i.e., we intend to let decay of the 6th month match + % that of the 3rd quarter, so that the 6th month decays a little + % faster than the second quarter which is 1/2. + if lags==1 + b = 0; + else + b = (log(xx1)-log(xx2))/(l1-l2); + end + a = xx1*exp(-b*l1); +end + + + +% +% *** specify the prior for each equation separately, SZ method, +% ** get the residuals from univariate regressions. +% +sgh = zeros(nvar,1); % square root +sgsh = sgh; % square +nSample=size(xdgel,1); % sample size-lags +yu = xdgel; +C = ones(nSample,1); +for k=1:nvar + [Bk,ek,junk1,junk2,junk3,junk4] = sye([yu(:,k) C],lags); + clear Bk junk1 junk2 junk3 junk4; + sgsh(k) = ek'*ek/(nSample-lags); + sgh(k) = sqrt(sgsh(k)); +end +% ** prior variance for A0(:,1), same for all equations!!! +sg0bid = zeros(nvar,1); % Sigma0_bar diagonal only for the ith equation +for j=1:nvar + sg0bid(j) = 1/sgsh(j); % sgsh = sigmai^2 +end +% ** prior variance for lagged and exogeous variables, same for all equations +sgpbid = zeros(ncoef,1); % Sigma_plus_bar, diagonal, for the ith equation +for i = 1:lags + if (q_m==12) + lagdecay = a*exp(b*i*mu(4)); + end + % + for j = 1:nvar + if (q_m==12) + % exponential decay to match quarterly decay + sgpbid((i-1)*nvar+j) = lagdecay^2/sgsh(j); % ith equation + elseif (q_m==4) + sgpbid((i-1)*nvar+j) = (1/i^mu(4))^2/sgsh(j); % ith equation + else + error('Incompatibility with lags, check the possible errors!!!') + %warning('Incompatibility with lags, check the possible errors!!!') + %return + end + end +end +% +if indxDummy % Dummy observations as part of the explicit prior. + ndobs=nvar+1; % Number of dummy observations: nvar unit roots and 1 cointegration prior. + phibar = zeros(ndobs,ncoef); + %* constant term + const = ones(nvar+1,1); + const(1:nvar) = 0.0; + phibar(:,ncoef) = const; % the first nvar periods: no or zero constant! + + xdgelint = mean(xdgel(1:lags,:),1); % mean of the first lags initial conditions + %* Dummies + for k=1:nvar + for m=1:lags + phibar(ndobs,nvar*(m-1)+k) = xdgelint(k); + phibar(k,nvar*(m-1)+k) = xdgelint(k); + % <<>> multiply hyperparameter later + end + end + phibar(1:nvar,:) = 1*mu(5)*phibar(1:nvar,:); % standard Sims and Zha prior + phibar(ndobs,:) = mu(6)*phibar(ndobs,:); + [phiq,phir]=qr(phibar,0); + xtxbar=phir'*phir; % phibar'*phibar. ncoef-by-ncoef. Reduced (not full) rank. See Forcast II, pp.69-69b. +end + + + + + +%================================================= +% Computing the (prior) covariance matrix for the posterior of A0, no data yet +%================================================= +% +% +% ** set up the conditional prior variance sg0bi and sgpbi. +sg0bida = mu(1)^2*sg0bid; % ith equation +sgpbida = mu(1)^2*mu(2)^2*sgpbid; +sgpbida(ncoef-nexo+1:ncoef) = mu(1)^2*mu(3)^2; + %<<>> No scaling adjustment has been made for exogenous terms other than constant +sgppbd = sgpbida(nvar+1:ncoef); % corresponding to A++, in a Sims-Zha paper + +Hptd = zeros(ncoef); +Hptdi=Hptd; +Hptd(ncoef,ncoef)=sgppbd(ncoef-nvar); +Hptdinv(ncoef,ncoef)=1./sgppbd(ncoef-nvar); + % condtional on A0i, H_plus_tilde + + +if nargin<14 % <<>>1 Default is no asymmetric information + asym0 = ones(nvar,nvar); % if not ones, then we have relative (asymmetric) tightness + asymp = ones(ncoef-1,nvar); % for A+. Column -- equation +end + +%**** Asymmetric Information +%asym0 = ones(nvar,nvar); % if not ones, then we have relative (asymmetric) tightness +%asymp = ones(ncoef-1,nvar); % pp: plus without constant. Column -- equation +%>>>>>> B: asymmetric prior variance for asymp <<<<<<<< +% +%for i = 1:lags +% rowif = (i-1)*nvar+1; +% rowil = i*nvar; +% idmatw0 = 0.5; % weight assigned to idmat0 in the formation of asymp +% if (i==1) +% asymp(rowif:rowil,:)=(1-idmatw0)*ones(nvar)+idmatw0*idmat0; % first lag +% % note: idmat1 is already transposed. Column -- equation +% else +% %asymp(rowif:rowil,1:nvar) = (1-idmatw0)*ones(nvar)+idmatw0*idmat0; +% % <<<<<<< toggle + +% % Note: already transposed, since idmat0 is transposed. +% % Meaning: column implies equation +% asymp(rowif:rowil,1:nvar) = ones(nvar); +% % >>>>>>> toggle - +% end +%end +% +%>>>>>> E: asymmetric prior variance for asymp <<<<<<<< + + +%================================================= +% Computing the final covariance matrix (S1,...,Sm) for the prior of A0, +% and final Gb=(G1,...,Gm) for A+ if asymmetric prior or for +% B if symmetric prior for A+ +%================================================= +% +for i = 1:nvar + %------------------------------ + % Introduce prior information on which variables "belong" in various equations. + % In this first trial, we just introduce this information here, in a model-specific way. + % Eventually this info has to be passed parametricly. In our first shot, we just damp down + % all coefficients except those on the diagonal. + + %*** For A0 + factor0=asym0(:,i); + + sg0bd = sg0bida.*factor0; % Note, this only works for the prior variance Sg(i) + % of a0(i) being diagonal. If the prior variance Sg(i) is not + % diagonal, we have to the inverse to get inv(Sg(i)). + %sg0bdinv = 1./sg0bd; + % * unconditional variance on A0+ + H0td = diag(sg0bd); % unconditional + %=== Correlation in the MS equation to get a liquidity effect. + if (i==indxmsmdeqn(1)) + H0td(indxmsmdeqn(3),indxmsmdeqn(4)) = hpmsmd(1)*sqrt(sg0bida(indxmsmdeqn(3))*sg0bida(indxmsmdeqn(4))); + H0td(indxmsmdeqn(4),indxmsmdeqn(3)) = hpmsmd(1)*sqrt(sg0bida(indxmsmdeqn(3))*sg0bida(indxmsmdeqn(4))); + elseif (i==indxmsmdeqn(2)) + H0td(indxmsmdeqn(3),indxmsmdeqn(4)) = hpmsmd(2)*sqrt(sg0bida(indxmsmdeqn(3))*sg0bida(indxmsmdeqn(4))); + H0td(indxmsmdeqn(4),indxmsmdeqn(3)) = hpmsmd(2)*sqrt(sg0bida(indxmsmdeqn(3))*sg0bida(indxmsmdeqn(4))); + end + H0tdinv = inv(H0td); + %H0tdinv = diag(sg0bdinv); + % + if indxScaleStates + H0tldcell_inv{i}=(Ui{i}'*kron(eye(nStates),H0tdinv/nStates))*Ui{i}; + else + H0tldcell_inv{i}=(Ui{i}'*kron(eye(nStates),H0tdinv))*Ui{i}; + end + + + + %*** For A+ + if ~(lags==0) % For A1 to remain random walk properties + factor1=asymp(1:nvar,i); + sg1bd = sgpbida(1:nvar).*factor1; + sg1bdinv = 1./sg1bd; + % + Hptd(1:nvar,1:nvar)=diag(sg1bd); + Hptdinv(1:nvar,1:nvar)=diag(sg1bdinv); + if lags>1 + factorpp=asymp(nvar+1:ncoef-1,i); + sgpp_cbd = sgppbd(1:ncoef-nvar-1) .* factorpp; + sgpp_cbdinv = 1./sgpp_cbd; + Hptd(nvar+1:ncoef-1,nvar+1:ncoef-1)=diag(sgpp_cbd); + Hptdinv(nvar+1:ncoef-1,nvar+1:ncoef-1)=diag(sgpp_cbdinv); + % condtional on A0i, H_plus_tilde + end + end + %--------------- + % The dummy observation prior affects only the prior covariance of A+|A0, + % but not the covariance of A0. See pp.69a-69b for the proof. + %--------------- + if indxDummy % Dummy observations as part of the explicit prior. + Hptdinv2 = Hptdinv + xtxbar; % Rename Hptdinv to Hptdinv2 because we want to keep Hptdinv diagonal in the next loop of i. + else + Hptdinv2 = Hptdinv; + end + if (indxScaleStates) + Hptldcell_inv{i}=(Vi{i}'*kron(eye(nStates),Hptdinv2/nStates))*Vi{i}; + else + Hptldcell_inv{i}=(Vi{i}'*kron(eye(nStates),Hptdinv2))*Vi{i}; + end + %Hptdinv_3 = kron(eye(nStates),Hptdinv); % ????? +end + + diff --git a/MatlabFiles/fn_rnrprior_covres_tv.m b/MatlabFiles/fn_rnrprior_covres_tv.m new file mode 100755 index 0000000..ae9033f --- /dev/null +++ b/MatlabFiles/fn_rnrprior_covres_tv.m @@ -0,0 +1,258 @@ +function [Pi_bar,H0tldcell_inv,Hptldcell_inv] ... + = fn_rnrprior_covres_tv(nvar,nStates,q_m,lags,xdgel,mu,Ui,Vi,hpmsmd,indxmsmdeqn,nexo,asym0,asymp) +% [Pi_bar,H0tldcell_inv,Hptldcell_inv] ... +% = fn_rnrprior_covres_tv(nvar,nStates,q_m,lags,xdgel,mu,Ui,Vi,hpmsmd,indxmsmdeqn,nexo,asym0,asymp) +% +% More general than fn_rnrprior_tv() because, when hpmsmd=0, fn_rnrprior_covres_tv() is the same as fn_rnrprior_tv(). +% Exports random Bayesian prior of Sims and Zha with asymmetric rior with linear restrictions already applied +% but without dummy observations (i.e., mu(5) and mu(6)) yet. +% This function allows for prior covariances for the MS and MD equations to achieve liquidity effects. +% See Waggoner and Zha's Gibbs sampling paper and TVBVAR NOTES pp. 71k.0 and 50-61. +% +% nvar: number of endogenous variables +% nStates: Number of states. +% q_m: quarter or month +% lags: the maximum length of lag +% xdgel: the general matrix of the original data (no manipulation involved) +% with sample size including lags. Used only to get variances of residuals for +% the scaling purpose; NOT used for mu(5) and mu(6). +% mu: 6-by-1 vector of hyperparameters (the following numbers for Atlanta Fed's forecast), where +% mu(5) and mu(6) are NOT used here. See fn_dataxy.m for using mu(5) and mu(6). +% mu(1): overall tightness and also for A0; (0.57) +% mu(2): relative tightness for A+; (0.13) +% mu(3): relative tightness for the constant term; (0.1). NOTE: for other +% exogenous terms, the variance of each exogenous term must be taken into +% acount to eliminate the scaling factor. +% mu(4): tightness on lag decay; (1) +% mu(5): weight on nvar sums of coeffs dummy observations (unit roots); (5) +% mu(6): weight on single dummy initial observation including constant +% (cointegration, unit roots, and stationarity); (5) +% NOTE: for this function, mu(5) and mu(6) are not used. See fn_dataxy.m for using mu(5) and mu(6). +% Ui: nvar-by-1 cell. In each cell, nvar-by-qi*si orthonormal basis for the null of the ith +% equation contemporaneous restriction matrix where qi is the number of free parameters +% within the state and si is the number of free states. +% With this transformation, we have ai = Ui*bi or Ui'*ai = bi where ai is a vector +% of total original parameters and bi is a vector of free parameters. When no +% restrictions are imposed, we have Ui = I. There must be at least one free +% parameter left for the ith equation in the order of [a_i for 1st state, ..., a_i for last state]. +% Vi: nvar-by-1 cell. In each cell, k-by-ri*ti orthonormal basis for the null of the ith +% equation lagged restriction matrix where k is a total of exogenous variables and +% ri is the number of free parameters within the state and ti is the number of free states. +% With this transformation, we have fi = Vi*gi +% or Vi'*fi = gi where fi is a vector of total original parameters and gi is a +% vector of free parameters. The ith equation is in the order of [nvar variables +% for 1st lag and 1st state, ..., nvar variables for last lag and 1st state, const for 1st state, nvar +% variables for 1st lag and 2nd state, nvar variables for last lag and 2nd state, const for 2nd state, and so on]. +% hpmsmd: 2-by-1 hyperparameters with -1<h1=hpmsmd(1)<=0 for the MS equation and 0<=h2=hpmsmd(2)<1 the MD equation. Consider a1*R + a2*M. +% The term h1*var(a1)*var(a2) is the prior covariance of a1 and a2 for MS, equivalent to penalizing the same sign of a1 and a2. +% The term h2*var(a1)*var(a2) is the prior covariance of a1 and a2 for MD, equivalent to penalizing opposite signs of a1 and a2. +% This will give us a liquidity effect. If hpmsmd=0, no such restrictions will be imposed. +% indxmsmdeqn: 4-by-1 index for the locations of the MS and MD equation and for the locations of M and R. +% indxmsmdeqn(1) for MS and indxmsmdeqn(2) for MD. +% indxmsmdeqn(3) for M and indxmsmdeqn(4) for R. +% nexo: number of exogenous variables (if not specified, nexo=1 (constant) by default). +% The constant term is always put to the last of all endogenous and exogenous variables. +% asym0: nvar-by-nvar asymmetric prior on A0. Column -- equation. +% If ones(nvar,nvar), symmetric prior; if not, relative (asymmetric) tightness on A0. +% asymp: ncoef-1-by-nvar asymmetric prior on A+ bar constant. Column -- equation. +% If ones(ncoef-1,nvar), symmetric prior; if not, relative (asymmetric) tightness on A+. +% -------------------- +% Pi_bar: ncoef-by-nvar matrix for the ith equation under random walk. Same for all equations +% H0tldcell_inv: cell(nvar,1). The ith cell represents the ith equation, where the dim is +% qi*si-by-qi*si. The inverse of H0tld on p.60. +% Hptldcell_inv: cell(nvar,1). The ith cell represents the ith equation, where the dim is +% ri*ti-by-ri*ti.The inverse of Hptld on p.60. +% +% Tao Zha, February 2000. Revised, September 2000, 2001, February, May 2003. + + +if nargin==10, nexo=1; end % <<>>1 +ncoef = nvar*lags+nexo; % Number of coefficients in *each* equation for each state, RHS coefficients only. +ncoefsts = nStates*ncoef; % Number of coefficients in *each* equation in all states, RHS coefficients only. + +H0tldcell_inv=cell(nvar,1); % inv(H0tilde) for different equations under asymmetric prior. +Hptldcell_inv=cell(nvar,1); % inv(H+tilde) for different equations under asymmetric prior. + +%*** Constructing Pi_bar for the ith equation under the random walk assumption +Pi_bar = zeros(ncoef,nvar); % same for all equations +Pi_bar(1:nvar,1:nvar) = eye(nvar); % random walk + +% +%@@@ Prepared for Bayesian prior +% +% +% ** monthly lag decay in order to match quarterly decay: a*exp(bl) where +% ** l is the monthly lag. Suppose quarterly decay is 1/x where x=1,2,3,4. +% ** Let the decay of l1 (a*exp(b*l1)) match that of x1 (say, beginning: 1/1) +% ** and the decay of l2 (a*exp(b*l2)) match that of x2 (say, end: 1/5), +% ** we can solve for a and b which are +% ** b = (log_x1-log_x2)/(l1-l2), and a = x1*exp(-b*l1). +if q_m==12 + l1 = 1; % 1st month == 1st quarter + xx1 = 1; % 1st quarter + l2 = lags; % last month + xx2 = 1/((ceil(lags/3))^mu(4)); % last quarter + %xx2 = 1/6; % last quarter + % 3rd quarter: i.e., we intend to let decay of the 6th month match + % that of the 3rd quarter, so that the 6th month decays a little + % faster than the second quarter which is 1/2. + if lags==1 + b = 0; + else + b = (log(xx1)-log(xx2))/(l1-l2); + end + a = xx1*exp(-b*l1); +end + + + +% +% *** specify the prior for each equation separately, SZ method, +% ** get the residuals from univariate regressions. +% +sgh = zeros(nvar,1); % square root +sgsh = sgh; % square +nSample=size(xdgel,1); % sample size-lags +yu = xdgel; +C = ones(nSample,1); +for k=1:nvar + [Bk,ek,junk1,junk2,junk3,junk4] = sye([yu(:,k) C],lags); + clear Bk junk1 junk2 junk3 junk4; + sgsh(k) = ek'*ek/(nSample-lags); + sgh(k) = sqrt(sgsh(k)); +end +% ** prior variance for A0(:,1), same for all equations!!! +sg0bid = zeros(nvar,1); % Sigma0_bar diagonal only for the ith equation +for j=1:nvar + sg0bid(j) = 1/sgsh(j); % sgsh = sigmai^2 +end +% ** prior variance for lagged and exogeous variables, same for all equations +sgpbid = zeros(ncoef,1); % Sigma_plus_bar, diagonal, for the ith equation +for i = 1:lags + if (q_m==12) + lagdecay = a*exp(b*i*mu(4)); + end + % + for j = 1:nvar + if (q_m==12) + % exponential decay to match quarterly decay + sgpbid((i-1)*nvar+j) = lagdecay^2/sgsh(j); % ith equation + elseif (q_m==4) + sgpbid((i-1)*nvar+j) = (1/i^mu(4))^2/sgsh(j); % ith equation + else + error('Incompatibility with lags, check the possible errors!!!') + %warning('Incompatibility with lags, check the possible errors!!!') + %return + end + end +end +% + + +%================================================= +% Computing the (prior) covariance matrix for the posterior of A0, no data yet +%================================================= +% +% +% ** set up the conditional prior variance sg0bi and sgpbi. +sg0bida = mu(1)^2*sg0bid; % ith equation +sgpbida = mu(1)^2*mu(2)^2*sgpbid; +sgpbida(ncoef-nexo+1:ncoef) = mu(1)^2*mu(3)^2; + %<<>> No scaling adjustment has been made for exogenous terms other than constant +sgppbd = sgpbida(nvar+1:ncoef); % corresponding to A++, in a Sims-Zha paper + +Hptd = zeros(ncoef); +Hptdi=Hptd; +Hptd(ncoef,ncoef)=sgppbd(ncoef-nvar); +Hptdinv(ncoef,ncoef)=1./sgppbd(ncoef-nvar); + % condtional on A0i, H_plus_tilde + + +if nargin<12 % <<>>1 Default is no asymmetric information + asym0 = ones(nvar,nvar); % if not ones, then we have relative (asymmetric) tightness + asymp = ones(ncoef-1,nvar); % for A+. Column -- equation +end + +%**** Asymmetric Information +%asym0 = ones(nvar,nvar); % if not ones, then we have relative (asymmetric) tightness +%asymp = ones(ncoef-1,nvar); % pp: plus without constant. Column -- equation +%>>>>>> B: asymmetric prior variance for asymp <<<<<<<< +% +%for i = 1:lags +% rowif = (i-1)*nvar+1; +% rowil = i*nvar; +% idmatw0 = 0.5; % weight assigned to idmat0 in the formation of asymp +% if (i==1) +% asymp(rowif:rowil,:)=(1-idmatw0)*ones(nvar)+idmatw0*idmat0; % first lag +% % note: idmat1 is already transposed. Column -- equation +% else +% %asymp(rowif:rowil,1:nvar) = (1-idmatw0)*ones(nvar)+idmatw0*idmat0; +% % <<<<<<< toggle + +% % Note: already transposed, since idmat0 is transposed. +% % Meaning: column implies equation +% asymp(rowif:rowil,1:nvar) = ones(nvar); +% % >>>>>>> toggle - +% end +%end +% +%>>>>>> E: asymmetric prior variance for asymp <<<<<<<< + + +%================================================= +% Computing the final covariance matrix (S1,...,Sm) for the prior of A0, +% and final Gb=(G1,...,Gm) for A+ if asymmetric prior or for +% B if symmetric prior for A+ +%================================================= +% +for i = 1:nvar + %------------------------------ + % Introduce prior information on which variables "belong" in various equations. + % In this first trial, we just introduce this information here, in a model-specific way. + % Eventually this info has to be passed parametricly. In our first shot, we just damp down + % all coefficients except those on the diagonal. + + %*** For A0 + factor0=asym0(:,i); + + sg0bd = sg0bida.*factor0; % Note, this only works for the prior variance Sg(i) + % of a0(i) being diagonal. If the prior variance Sg(i) is not + % diagonal, we have to the inverse to get inv(Sg(i)). + %sg0bdinv = 1./sg0bd; + % * unconditional variance on A0+ + H0td = diag(sg0bd); % unconditional + %=== Correlation in the MS equation to get a liquidity effect. + if (i==indxmsmdeqn(1)) + H0td(indxmsmdeqn(3),indxmsmdeqn(4)) = hpmsmd(1)*sqrt(sg0bida(indxmsmdeqn(3))*sg0bida(indxmsmdeqn(4))); + H0td(indxmsmdeqn(4),indxmsmdeqn(3)) = hpmsmd(1)*sqrt(sg0bida(indxmsmdeqn(3))*sg0bida(indxmsmdeqn(4))); + elseif (i==indxmsmdeqn(2)) + H0td(indxmsmdeqn(3),indxmsmdeqn(4)) = hpmsmd(2)*sqrt(sg0bida(indxmsmdeqn(3))*sg0bida(indxmsmdeqn(4))); + H0td(indxmsmdeqn(4),indxmsmdeqn(3)) = hpmsmd(2)*sqrt(sg0bida(indxmsmdeqn(3))*sg0bida(indxmsmdeqn(4))); + end + H0tdinv = inv(H0td); + %H0tdinv = diag(sg0bdinv); + % + H0tldcell_inv{i}=(Ui{i}'*kron(eye(nStates),H0tdinv/nStates))*Ui{i}; + + + %*** For A+ + if ~(lags==0) % For A1 to remain random walk properties + factor1=asymp(1:nvar,i); + sg1bd = sgpbida(1:nvar).*factor1; + sg1bdinv = 1./sg1bd; + % + Hptd(1:nvar,1:nvar)=diag(sg1bd); + Hptdinv(1:nvar,1:nvar)=diag(sg1bdinv); + if lags>1 + factorpp=asymp(nvar+1:ncoef-1,i); + sgpp_cbd = sgppbd(1:ncoef-nvar-1) .* factorpp; + sgpp_cbdinv = 1./sgpp_cbd; + Hptd(nvar+1:ncoef-1,nvar+1:ncoef-1)=diag(sgpp_cbd); + Hptdinv(nvar+1:ncoef-1,nvar+1:ncoef-1)=diag(sgpp_cbdinv); + % condtional on A0i, H_plus_tilde + end + end + Hptldcell_inv{i}=(Vi{i}'*kron(eye(nStates),Hptdinv/nStates))*Vi{i}; + %Hptdinv_3 = kron(eye(nStates),Hptdinv); % ????? +end + + diff --git a/MatlabFiles/fn_rnrprior_tv.m b/MatlabFiles/fn_rnrprior_tv.m new file mode 100755 index 0000000..0011420 --- /dev/null +++ b/MatlabFiles/fn_rnrprior_tv.m @@ -0,0 +1,236 @@ +function [Pi_bar,H0tldcell_inv,Hptldcell_inv] ... + = fn_rnrprior_tv(nvar,nStates,q_m,lags,xdgel,mu,Ui,Vi,nexo,asym0,asymp) +% Exports random Bayesian prior of Sims and Zha with linear restrictions applied, allowing for +% possibly with asymmetric prior. +% See Waggoner and Zha's Gibbs sampling paper and TVBVAR NOTE pp.50-61. +% +% nvar: number of endogenous variables +% nStates: Number of states. +% q_m: quarter or month +% lags: the maximum length of lag +% xdgel: the general matrix of the original data (no manipulation involved) +% with sample size including lags. Used only to get variances of residuals for +% the scaling purpose; NOT used for mu(5) and mu(6). +% mu: 6-by-1 vector of hyperparameters (the following numbers for Atlanta Fed's forecast), where +% mu(5) and mu(6) are NOT used here. See fn_dataxy.m for using mu(5) and mu(6). +% mu(1): overall tightness and also for A0; (0.57) +% mu(2): relative tightness for A+; (0.13) +% mu(3): relative tightness for the constant term; (0.1). NOTE: for other +% exogenous terms, the variance of each exogenous term must be taken into +% acount to eliminate the scaling factor. +% mu(4): tightness on lag decay; (1) +% mu(5): weight on nvar sums of coeffs dummy observations (unit roots); (5) +% mu(6): weight on single dummy initial observation including constant +% (cointegration, unit roots, and stationarity); (5) +% NOTE: for this function, mu(5) and mu(6) are not used. +% Ui: nvar-by-1 cell. In each cell, nvar-by-(qi+si) orthonormal basis for the null of the ith +% equation contemporaneous restriction matrix where qi is the number of free parameters +% within the state and si is the number of free parameters across the states. +% With this transformation, we have ai = Ui*bi or Ui'*ai = bi where ai is a vector +% of total original parameters and bi is a vector of free parameters. When no +% restrictions are imposed, we have Ui = I. There must be at least one free +% parameter left for the ith equation. +% Vi: nvar-by-1 cell. In each cell, k-by-(ri+ti) orthonormal basis for the null of the ith +% equation lagged restriction matrix where k is a total of exogenous variables and +% ri is the number of free parameters within the state and ti is the number of free +% parameters across the states. With this transformation, we have fi = Vi*gi +% or Vi'*fi = gi where fi is a vector of total original parameters and gi is a +% vector of free parameters. The ith equation is in the order of [nvar for 1st lag, +% ..., nvar for last lag, const]. +% nexo: number of exogenous variables (if not specified, nexo=1 (constant) by default). +% The constant term is always put to the last of all endogenous and exogenous variables. +% asym0: nvar-by-nvar asymmetric prior on A0. Column -- equation. +% If ones(nvar,nvar), symmetric prior; if not, relative (asymmetric) tightness on A0. +% asymp: ncoef-1-by-nvar asymmetric prior on A+ bar constant. Column -- equation. +% If ones(ncoef-1,nvar), symmetric prior; if not, relative (asymmetric) tightness on A+. +% -------------------- +% Pi_bar: ncoef-by-nvar matrix for the ith equation under random walk. Same for all equations +% H0tldcell_inv: cell(nvar,1). The ith cell represents the ith equation, where the dim is +% (qi+si)-by-(qi+si). The inverse of H0tld on p.60. +% Hptldcell_inv: cell(nvar,1). The ith cell represents the ith equation, where the dim is +% (ri+ti)-by-(ri+ti).The inverse of Hptld on p.60. +% +% Tao Zha, February 2000. Revised, September 2000, 2001. +% See fn_dataxy.m for using mu(5) and mu(6). + + +if nargin==8, nexo=1; end % <<>>1 +ncoef = nvar*lags+nexo; % Number of coefficients in *each* equation for each state, RHS coefficients only. +ncoefsts = nStates*ncoef; % Number of coefficients in *each* equation in all states, RHS coefficients only. + +H0tldcell_inv=cell(nvar,1); % inv(H0tilde) for different equations under asymmetric prior. +Hptldcell_inv=cell(nvar,1); % inv(H+tilde) for different equations under asymmetric prior. + +%*** Constructing Pi_bar for the ith equation under the random walk assumption +Pi_bar = zeros(ncoef,nvar); % same for all equations +Pi_bar(1:nvar,1:nvar) = eye(nvar); % random walk + +% +%@@@ Prepared for Bayesian prior +% +% +% ** monthly lag decay in order to match quarterly decay: a*exp(bl) where +% ** l is the monthly lag. Suppose quarterly decay is 1/x where x=1,2,3,4. +% ** Let the decay of l1 (a*exp(b*l1)) match that of x1 (say, beginning: 1/1) +% ** and the decay of l2 (a*exp(b*l2)) match that of x2 (say, end: 1/5), +% ** we can solve for a and b which are +% ** b = (log_x1-log_x2)/(l1-l2), and a = x1*exp(-b*l1). +if q_m==12 + l1 = 1; % 1st month == 1st quarter + xx1 = 1; % 1st quarter + l2 = lags; % last month + xx2 = 1/((ceil(lags/3))^mu(4)); % last quarter + %xx2 = 1/6; % last quarter + % 3rd quarter: i.e., we intend to let decay of the 6th month match + % that of the 3rd quarter, so that the 6th month decays a little + % faster than the second quarter which is 1/2. + if lags==1 + b = 0; + else + b = (log(xx1)-log(xx2))/(l1-l2); + end + a = xx1*exp(-b*l1); +end + + + +% +% *** specify the prior for each equation separately, SZ method, +% ** get the residuals from univariate regressions. +% +sgh = zeros(nvar,1); % square root +sgsh = sgh; % square +nSample=size(xdgel,1); % sample size-lags +yu = xdgel; +C = ones(nSample,1); +for k=1:nvar + [Bk,ek,junk1,junk2,junk3,junk4] = sye([yu(:,k) C],lags); + clear Bk junk1 junk2 junk3 junk4; + sgsh(k) = ek'*ek/(nSample-lags); + sgh(k) = sqrt(sgsh(k)); +end +% ** prior variance for A0(:,1), same for all equations!!! +sg0bid = zeros(nvar,1); % Sigma0_bar diagonal only for the ith equation +for j=1:nvar + sg0bid(j) = 1/sgsh(j); % sgsh = sigmai^2 +end +% ** prior variance for lagged and exogeous variables, same for all equations +sgpbid = zeros(ncoef,1); % Sigma_plus_bar, diagonal, for the ith equation +for i = 1:lags + if (q_m==12) + lagdecay = a*exp(b*i*mu(4)); + end + % + for j = 1:nvar + if (q_m==12) + % exponential decay to match quarterly decay + sgpbid((i-1)*nvar+j) = lagdecay^2/sgsh(j); % ith equation + elseif (q_m==4) + sgpbid((i-1)*nvar+j) = (1/i^mu(4))^2/sgsh(j); % ith equation + else + error('Incompatibility with lags, check the possible errors!!!') + %warning('Incompatibility with lags, check the possible errors!!!') + %return + end + end +end +% + + +%================================================= +% Computing the (prior) covariance matrix for the posterior of A0, no data yet +%================================================= +% +% +% ** set up the conditional prior variance sg0bi and sgpbi. +sg0bida = mu(1)^2*sg0bid; % ith equation +sgpbida = mu(1)^2*mu(2)^2*sgpbid; +sgpbida(ncoef-nexo+1:ncoef) = mu(1)^2*mu(3)^2; + %<<>> No scaling adjustment has been made for exogenous terms other than constant +sgppbd = sgpbida(nvar+1:ncoef); % corresponding to A++, in a Sims-Zha paper + +Hptd = zeros(ncoef); +Hptdi=Hptd; +Hptd(ncoef,ncoef)=sgppbd(ncoef-nvar); +Hptdinv(ncoef,ncoef)=1./sgppbd(ncoef-nvar); + % condtional on A0i, H_plus_tilde + + +if nargin<10 % <<>>1 Default is no asymmetric information + asym0 = ones(nvar,nvar); % if not ones, then we have relative (asymmetric) tightness + asymp = ones(ncoef-1,nvar); % for A+. Column -- equation +end + +%**** Asymmetric Information +%asym0 = ones(nvar,nvar); % if not ones, then we have relative (asymmetric) tightness +%asymp = ones(ncoef-1,nvar); % pp: plus without constant. Column -- equation +%>>>>>> B: asymmetric prior variance for asymp <<<<<<<< +% +%for i = 1:lags +% rowif = (i-1)*nvar+1; +% rowil = i*nvar; +% idmatw0 = 0.5; % weight assigned to idmat0 in the formation of asymp +% if (i==1) +% asymp(rowif:rowil,:)=(1-idmatw0)*ones(nvar)+idmatw0*idmat0; % first lag +% % note: idmat1 is already transposed. Column -- equation +% else +% %asymp(rowif:rowil,1:nvar) = (1-idmatw0)*ones(nvar)+idmatw0*idmat0; +% % <<<<<<< toggle + +% % Note: already transposed, since idmat0 is transposed. +% % Meaning: column implies equation +% asymp(rowif:rowil,1:nvar) = ones(nvar); +% % >>>>>>> toggle - +% end +%end +% +%>>>>>> E: asymmetric prior variance for asymp <<<<<<<< + + +%================================================= +% Computing the final covariance matrix (S1,...,Sm) for the prior of A0, +% and final Gb=(G1,...,Gm) for A+ if asymmetric prior or for +% B if symmetric prior for A+ +%================================================= +% +for i = 1:nvar + %------------------------------ + % Introduce prior information on which variables "belong" in various equations. + % In this first trial, we just introduce this information here, in a model-specific way. + % Eventually this info has to be passed parametricly. In our first shot, we just damp down + % all coefficients except those on the diagonal. + + %*** For A0 + factor0=asym0(:,i); + sg0bd = sg0bida.*factor0; % Note, this only works for the prior variance Sg(i) + % of a0(i) being diagonal. If the prior variance Sg(i) is not + % diagonal, we have to work on inv(Sg(i)) or sg0bdinv directly. + sg0bdinv = 1./sg0bd; + % * unconditional variance on A0+ + H0td = diag(sg0bd); % unconditional + H0tdinv = diag(sg0bdinv); + % + H0tldcell_inv{i}=(Ui{i}'*kron(eye(nStates),H0tdinv/nStates))*Ui{i}; + + + %*** For A+ + if ~(lags==0) % For A1 to remain random walk properties + factor1=asymp(1:nvar,i); + sg1bd = sgpbida(1:nvar).*factor1; + sg1bdinv = 1./sg1bd; + % + Hptd(1:nvar,1:nvar)=diag(sg1bd); + Hptdinv(1:nvar,1:nvar)=diag(sg1bdinv); + if lags>1 + factorpp=asymp(nvar+1:ncoef-1,i); + sgpp_cbd = sgppbd(1:ncoef-nvar-1) .* factorpp; + sgpp_cbdinv = 1./sgpp_cbd; + Hptd(nvar+1:ncoef-1,nvar+1:ncoef-1)=diag(sgpp_cbd); + Hptdinv(nvar+1:ncoef-1,nvar+1:ncoef-1)=diag(sgpp_cbdinv); + % condtional on A0i, H_plus_tilde + end + end + Hptldcell_inv{i}=(Vi{i}'*kron(eye(nStates),Hptdinv/nStates))*Vi{i}; + %Hptdinv_3 = kron(eye(nStates),Hptdinv); % ????? +end + + diff --git a/MatlabFiles/fn_seriesgraph.m b/MatlabFiles/fn_seriesgraph.m new file mode 100755 index 0000000..137fd5a --- /dev/null +++ b/MatlabFiles/fn_seriesgraph.m @@ -0,0 +1,49 @@ +function fn_seriesgraph(ydate,keyindx,rnum,cnum,q_m,xlab,ylab,tlab) +% +% Graph actual series or point forecasts or both (annual or monthly or quarterly) +% +% ydate: series data with dates in the first 2 columns in the order of year and month (or quarter). +% Some elements are allowed to be NaN if no data are available. +% keyindx: index for the variables to be graphed +% rnum: number of rows in subplot +% cnum: number of columns in subplot +% q_m: if 4 or 12, quarterly or monthly data +% xlab: x-axis label for what conditions imposed; e.g., conlab = 'All bar MS shocks inspl' +% ylab: string array for the length(keyindx)-by-1 variables +% tlab: title label for (e.g., as of time of forecast) +%------------- +% No output argument for this graph file +% See fn_foregraph.m, fn_forerrgraph.m. +% +% Tao Zha, September 2000 + +vyrs = ydate(:,1); % vectorized +hornum = cell(length(vyrs),1); % horizontal year (number) +count=0; +for k=vyrs' + count=count+1; + jnk=num2str(k); + hornum{count}=jnk(3:4); % e.g., with '1990', we have '90' +end + +count=0; +for i = keyindx + count = count+1; + subplot(rnum,cnum,count) + plot(ydate(:,1)+ydate(:,2)/q_m,ydate(:,2+i)) + + if (ydate(1,2)==0) % only for annual growth rates (not for, say, monthly annualized rates) + set(gca,'XLim',[vyrs(1) vyrs(end)]) + set(gca,'XTick',vyrs) + set(gca,'XTickLabel',char(hornum)) + end + + if i==keyindx(1) + title(tlab) + elseif i>=length(keyindx) %i>=length(keyindx)-1 + xlabel(xlab) + end + % + grid + ylabel(char(ylab(i))) +end diff --git a/MatlabFiles/fn_simul.m b/MatlabFiles/fn_simul.m new file mode 100755 index 0000000..92f9cb1 --- /dev/null +++ b/MatlabFiles/fn_simul.m @@ -0,0 +1,26 @@ +function simul = fn_simul(G1, impact, nsim, shocks, x0); +% Inputs: +% G1: n-by-n; +% impact: n-by-r; +% nsim: length of time series for simulation. +% shocks: r-by-nsim, exogenous driving processes +% x0: n-by-1, initial values for the variables of interest +%--- +% Outputs: +% simul: nsim-by-n. +% + +[n,r] = size(impact); + +[n1,n2] = size(G1); +if (n1 ~= n2) || (n1 ~= n) + error('fn_simul.m: make sure that (1) G1 is square and (2) size(G1,1) = size(impact,1)'); +end + +simul_tmp = zeros(n, nsim); + +simul_tmp(:, 1) = x0; +for ti = 2:nsim; + simul_tmp(:, ti) = G1*simul_tmp(:, ti-1) + impact*shocks(:, ti); +end; +simul = simul_tmp'; diff --git a/MatlabFiles/fn_tran_a2b.m b/MatlabFiles/fn_tran_a2b.m new file mode 100755 index 0000000..b1dec61 --- /dev/null +++ b/MatlabFiles/fn_tran_a2b.m @@ -0,0 +1,25 @@ +function b = fn_tran_a2b(A0,Ui,nvar,n0) +% b = fn_tran_a2b(A0,Ui,nvar,n0) +% Transform A0 to free parameters b's. Note: columns correspond to equations +% See Waggoner and Zha's ``A Gibbs sampler for structural VARs'' +% +% A0: nvar-by-nvar, contempareous matrix (columns correspond to equations) +% Ui: nvar-by-1 cell. In each cell, nvar-by-qi orthonormal basis for the null of the ith +% equation contemporaneous restriction matrix where qi is the number of free parameters. +% With this transformation, we have ai = Ui*bi or Ui'*ai = bi where ai is a vector +% of total original parameters and bi is a vector of free parameters. When no +% restrictions are imposed, we have Ui = I. There must be at least one free +% parameter left for the ith equation. +% nvar: number of endogeous variables +% n0: nvar-by-1, ith element represents the number of free A0 parameters in ith equation +%---------------- +% b: sum(n0)-by-1 vector of A0 free parameters +% +% Tao Zha, February 2000. Revised, August 2000 + +n0=n0(:); +n0cum = [0; cumsum(n0)]; +b=zeros(n0cum(end),1); +for kj = 1:nvar + b(n0cum(kj)+1:n0cum(kj+1))=Ui{kj}'*A0(:,kj); +end diff --git a/MatlabFiles/fn_tran_b2a.m b/MatlabFiles/fn_tran_b2a.m new file mode 100755 index 0000000..47bc8cf --- /dev/null +++ b/MatlabFiles/fn_tran_b2a.m @@ -0,0 +1,24 @@ +function A0 = fn_tran_b2a(b,Ui,nvar,n0) +% A0 = fn_tran_b2a(b,Ui,nvar,n0) +% Transform free parameters b's to A0. Note: columns correspond to equations +% +% b: sum(n0)-by-1 vector of A0 free parameters +% Ui: nvar-by-1 cell. In each cell, nvar-by-qi orthonormal basis for the null of the ith +% equation contemporaneous restriction matrix where qi is the number of free parameters. +% With this transformation, we have ai = Ui*bi or Ui'*ai = bi where ai is a vector +% of total original parameters and bi is a vector of free parameters. When no +% restrictions are imposed, we have Ui = I. There must be at least one free +% parameter left for the ith equation. +% nvar: number of endogeous variables +% n0: nvar-by-1, ith element represents the number of free A0 parameters in ith equation +%---------------- +% A0: nvar-by-nvar, contempareous matrix (columns correspond to equations) +% +% Tao Zha, February 2000. Revised, August 2000. + +b=b(:); n0=n0(:); +A0 = zeros(nvar); +n0cum = [0; cumsum(n0)]; +for kj = 1:nvar + A0(:,kj) = Ui{kj}*b(n0cum(kj)+1:n0cum(kj+1)); +end diff --git a/MatlabFiles/fn_tran_f2g.m b/MatlabFiles/fn_tran_f2g.m new file mode 100755 index 0000000..c90bec1 --- /dev/null +++ b/MatlabFiles/fn_tran_f2g.m @@ -0,0 +1,26 @@ +function g = fn_tran_f2g(F,Vi,nvar,np) +% g = fn_tran_f2g(F,Vi,nvar,np) +% Transform F (A+) to free parameters g's. Note: columns correspond to equations +% See Waggoner and Zha's ``A Gibbs sampler for structural VARs'' +% +% F: ncoef-by-nvar matrix of original lagged parameters A+. Column corresponding to equation. +% Note that ncoef is the number of original lagged variables per equation +% Vi: nvar-by-1 cell. In each cell, k-by-ri orthonormal basis for the null of the ith +% equation lagged restriction matrix where k is a total of exogenous variables and +% ri is the number of free parameters. With this transformation, we have fi = Vi*gi +% or Vi'*fi = gi where fi is a vector of total original parameters and gi is a +% vector of free parameters. There must be at least one free parameter left for +% the ith equation. +% nvar: number of endogeous variables +% np: nvar-element vector, ith element represents the number of free A+ parameters in ith equation +%--------------- +% g: sum(np)-by-1 stacked vector of all free lagged parameters A+. +% +% August 2000, Tao Zha + +np=np(:); +npcum = [0;cumsum(np)]; +g = zeros(npcum(end),1); +for kj=1:nvar + g(npcum(kj)+1:npcum(kj+1)) = Vi{kj}'*F(:,kj); +end diff --git a/MatlabFiles/fn_tran_g2f.m b/MatlabFiles/fn_tran_g2f.m new file mode 100755 index 0000000..c95d2fb --- /dev/null +++ b/MatlabFiles/fn_tran_g2f.m @@ -0,0 +1,25 @@ +function F = fn_tran_g2f(g,Vi,nvar,ncoef,np) +% Transform free parameters g's to F (A+). Note: columns correspond to equations +% See Waggoner and Zha's ``A Gibbs sampler for structural VARs'' +% +% g: sum(np)-by-1 stacked vector of all free lagged parameters A+. +% Vi: nvar-by-1 cell. In each cell, k-by-ri orthonormal basis for the null of the ith +% equation lagged restriction matrix where k is a total of exogenous variables and +% ri is the number of free parameters. With this transformation, we have fi = Vi*gi +% or Vi'*fi = gi where fi is a vector of total original parameters and gi is a +% vector of free parameters. There must be at least one free parameter left for +% the ith equation. +% nvar: number of endogeous variables +% ncoef: number of original lagged variables per equation +% np: nvar-element vector, ith element represents the number of free A+ parameters in ith equation +%--------------- +% F: ncoef-by-nvar matrix of original lagged parameters A+. Column corresponding to equation. +% +% August 2000, Tao Zha. + +g=g(:); np=np(:); +npcum = [0;cumsum(np)]; +F = zeros(ncoef,nvar); % ncoef: maximum original lagged parameters per equation +for kj=1:nvar + F(:,kj) = Vi{kj}*g(npcum(kj)+1:npcum(kj+1)); +end diff --git a/MatlabFiles/fn_uncondfcst_var1.m b/MatlabFiles/fn_uncondfcst_var1.m new file mode 100755 index 0000000..e8aa61d --- /dev/null +++ b/MatlabFiles/fn_uncondfcst_var1.m @@ -0,0 +1,28 @@ +function y = fn_uncondfcst_var1(G1, y0, nsteps); +%y = fn_irf_var1(G1,y0,nsteps); +% Inputs: +% G1: n-by-n; +% y0: n-by-1, initial condition; +% nsteps: number of forecasts steps. +%--- +% Outputs: +% y: nsteps-by-n unconditional forecasts. +% +% See fn_vds.m, fn_irf_var1.m. + +n = length(y0); + +[n1,n2] = size(G1); +if (n1 ~= n2) || (n1 ~= n) + error('fn_uncondfcst_var1.m: make sure that (1) G1 is square and (2) size(G1,1) = length(y0)'); +end + +y = zeros(nsteps,n); + + +%---- Forecast at the first step. +y(1,:) = (G1*y0)'; + +for ti = 2:nsteps + y(ti,:) = (G1*y(ti-1,:)')'; +end diff --git a/MatlabFiles/fn_varoots.m b/MatlabFiles/fn_varoots.m new file mode 100755 index 0000000..43410e3 --- /dev/null +++ b/MatlabFiles/fn_varoots.m @@ -0,0 +1,30 @@ +function rootsinv = fn_varoots(Bhat,nvar,lags) +% +% Using eigenvalues to find the inverse of all roots associated with the VAR proceess: +% y_t' = C + y_{t-1}'*B_1 + ... + Y_{t-p}'*B_p + u_t'. +% where columns correspond to equations. See also Judge (1), pp.753-755 where rows correspond to equations. +% Bhat: ncoef-by-nvar where ncoef=nvar*lags+nexo and nvar is the number of endogenous variables. +% Columns corresponds to equations with +% ncoef=[nvar for 1st lag, ..., nvar for last lag, other exogenous terms, const term] +% ..., nvar coef in the last lag, and nexo coefficients. +% Note that entries in the rows of Bhat that > nvar*lags are irrelevant. +% nvar: number of endogenous variables. +% lags: number of lags. +%------- +% rootsinv: a vector of nvar*lags inverse roots. When > 1, explosive. When all < 1, stationary. +% +% Tao Zha, September 2000 + + +if size(Bhat,1)<nvar*lags + disp(' ') + warning('Make sure that Bhat has at least nvar*lags rows') + return +end + +%--------- Strack the VAR(p) to the VAR(1) with z_t = Az_{t-1}. +% +A1 = diag(ones(nvar*(lags-1),1)); +A2 = [A1 zeros(nvar*(lags-1),nvar)]; +A = [Bhat(1:nvar*lags,:)'; A2]; +rootsinv=eig(A); diff --git a/MatlabFiles/fn_vds.m b/MatlabFiles/fn_vds.m new file mode 100755 index 0000000..5215f39 --- /dev/null +++ b/MatlabFiles/fn_vds.m @@ -0,0 +1,17 @@ +function vds = fn_vds(irfs); +%vds = fn_vds(irfs) +% +% Inputs: +% irfs: nsteps-by-n-by-r. For each shock of r shocks, impulse responses are nsteps-by-n. +%--- +% Outputs: +% vds: nsteps-by-n-by-r. For each shock of r shocks, variance decompositions (%) are nsteps-by-n. + +[nsteps, n,r] = size(irfs); + +vds = zeros(nsteps,n,r); + +vds_square_cum = cumsum(irfs.^2,1); +vds_square_sum = repmat(sum(vds_square_cum,3),[1 1 r]); +vds = (vds_square_cum ./ vds_square_sum) .* 100; + diff --git a/MatlabFiles/fn_vds_abs.m b/MatlabFiles/fn_vds_abs.m new file mode 100755 index 0000000..d5818e2 --- /dev/null +++ b/MatlabFiles/fn_vds_abs.m @@ -0,0 +1,17 @@ +function vds = fn_vds_abs(irfs); +%vds = fn_vds(irfs) +% +% Inputs: +% irfs: nsteps-by-n-by-r. For each shock of r shocks, impulse responses are nsteps-by-n. +%--- +% Outputs: +% vds: nsteps-by-n-by-r. For each shock of r shocks, variance decompositions (%) are nsteps-by-n. + +[nsteps, n,r] = size(irfs); + +vds = zeros(nsteps,n,r); + +vds_square_cum = cumsum(abs(irfs),1); +vds_square_sum = repmat(sum(vds_square_cum,3),[1 1 r]); +vds = (vds_square_cum ./ vds_square_sum) .* 100; + diff --git a/MatlabFiles/fore_cal.m b/MatlabFiles/fore_cal.m new file mode 100755 index 0000000..b65c576 --- /dev/null +++ b/MatlabFiles/fore_cal.m @@ -0,0 +1,251 @@ +function [yforelml,yforemgml,yforeqgml,yforeCalygml] = fore_cal(yfore,xdata,nvar,... + nSample,nSampleCal,forep,forepq,forepy,q_m,qmEnd,vlist,vlistlog,... + vlistper,lmqyIndx) +% Converting oringinal forecast "yfore" to series by calendar years and series +% with growth rates (annualized for monthly and quarterly series). +% +%function [yforelml,yforemgml,yforeqgml,yforeCalygml] = fore_cal(yfore,xdata,nvar,... +% nSample,nSampleCal,forep,forepq,forepy,q_m,qmEnd,vlist,vlistlog,... +% vlistper,mqyIndx) +% +% yfore: oringal forecast series, all logged except R, U, etc. +% xdata: oringal data set beyond the sample into forecast horizon +% until yrFin:qmFin, all logged except R, U, etc. +% nvar: number of variables +% nSample: sample size (including lags or initial periods) +% nSampleCal: sample size in terms of calendar years +% forep: forecast periods (monthly) +% forepq: forecast periods (quarterly) +% forepy: forecast periods (yearly) +% q_m: quarterly or monthly for the underlying model +% qmEnd: last q_m before out-of-sample forecasting +% vlist: a list of variables +% vlistlog: sub list of variables that are in log +% vlistper: sub list of variables that are in percent +% lmyqIndx: 4-by-1 1 or 0's. Index for level, mg, qg, and yg; 1: yes; 0: no +%---------------- +% yforelml: monthly level forecast (in percent for R, U, etc.) with the same size as "yfore" in log +% yforemgml: monthly growth (at annual rates), in percent +% yforeqgml: ML forecast: quarterly growth (at annual rates), in percent +% yforeCalygml: ML forecast: annual growth (by calendar years), in percent +% forepy-by-nvar +% +% Copyright (c) March 1998 by Tao Zha +% Revision, October 1998. Added lmyqIndx so previous programs may not be compatible. +% + +%================================================= +% Making everything presentable at FOMC +%================================================= +% +%%%% +%$$$ Monthly, prior quarter, and year-over-year change +%$$$ Out-of-sample forecasts +%%%% + + +if length(lmqyIndx)~=4 + warning('lmqyIndx must be a 4-by-1 vector containing 1 or 0') + return +end + + + +%--------------------- +% Actual data +%--------------------- +yact = xdata(nSample-q_m+1:nSample,:); % the latest (not calender) year +yactCal = xdata(nSampleCal-q_m+1:nSampleCal,:); % the lastest calendar year + + + +%----------------------------------------- +% Converted to monthly level +%----------------------------------------- +if lmqyIndx(1) + yforelml=yfore; + yforelml(:,vlistlog)=exp(yfore(:,vlistlog)); % mode, all levels + yforelml(:,vlistper)=100*yfore(:,vlistper); % mode, all levels +else + yforelml = NaN; +end + + + +%----------------------------------------- +% Converted to monthly growth +%----------------------------------------- +if lmqyIndx(2) + yactm = zeros(1,length(vlist)); % the latest month prior to forecasting + yforem = zeros(1+forep,length(vlist)); % including the 1 month prior to forecasting + % + yactm = yact(length(yact(:,1)),:); % last month prior to forecasting + yforem(1,:) = yactm; % last month prior to forecasting + yforem(2:forep+1,:) = yfore(1:forep,:); % monthly forecasts, all logged. + % + %@@ monthly growth rate (annualized) + yforemg = yforem(2:forep+1,:); + yforemg(:,vlistlog) = ... + ( yforem(2:forep+1,vlistlog) - yforem(1:forep,vlistlog) ) .* q_m; + % monthly change (annualized), 12*log(1+growth rate) + yforemgml=yforemg; + yforemgml(:,vlistlog) = 100*(exp(yforemg(:,vlistlog))-1); + % monthly growth rate (annualized) + yforemgml(:,vlistper) = 100*yforemg(:,vlistper); % monthly growth rate (annualized) +else + yforemgml=NaN; +end + + + +%----------------------------------------- +% Converted to quarterly +%----------------------------------------- +if lmqyIndx(3) + yactQ = xdata(nSample-mod(qmEnd,3)-q_m+1:nSample-mod(qmEnd,3),:); + % the latest actual quarter + yactq = zeros(4,length(vlist)); % the latest 4 quarters prior to forecasting + yforeq = zeros(4+forepq,length(vlist)); + % including the 4 quarters prior to forecasting + % + qT1 = length(yactQ(:,1))/3; + if qT1 ~= 4 + error('Must hae 4 actual quarters to compute quarterly change for forecasting!') + end + for i = 1:qT1 + i1 = 1+3*(i-1); + i2 = 3*i; + yactq(i,:) = sum(yact(i1:i2,:)) ./ 3; + end + yforeq(1:4,:) = yactq; + % + yforeq_1 = sum(xdata( nSample-mod(qmEnd,3)+1:nSample,:),1); + yforeq(5,:) = ( yforeq_1 + sum(yfore(1:3-mod(qmEnd,3),:),1) ) ./ 3; + % 1st quarterly forecast which may contain actual data within quarter + % note, dimension "1" in sum(ytem,1) is necessary because when + % qmEnd=1, sum(ytem,1) will give us a nomber, not a vector. But this + % is not what we want. + for i = 2:forepq + i1 = 3-mod(qmEnd,3) + 1+3*(i-2); + i2 = 3-mod(qmEnd,3) + 3*(i-1); + yforeq(4+i,:) = sum(yfore(i1:i2,:)) ./ 3; + end + % + %@@ prior quarter growth rate (annualized) + yforeqg = yforeq(5:forepq+4,:); + %yforeqg(:,vlistlog) = (100*(yforeq(5:qT2+4,vlistlog)-yforeq(1:qT2,vlistlog))) ... + % ./ yforeq(1:qT2,vlistlog); % year-over-year + %yforeqg(:,vlistlog) = 100*((yforeq(5:qT2+4,vlistlog)./yforeq(4:qT2+3,vlistlog)).^4 - 1 ); + % prior quarter + yforeqg(:,vlistlog) = ... + ( yforeq(5:forepq+4,vlistlog) - yforeq(4:forepq+3,vlistlog) ) .* 4; + % prior quarter, 4*log(1+growth rate) + yforeqgml=yforeqg; + yforeqgml(:,vlistlog) = 100*(exp(yforeqg(:,vlistlog))-1); + % quarterly growth rate (annualized) + yforeqgml(:,vlistper) = 100*yforeqg(:,vlistper); + % quarterly growth rate (annualized) +else + yforeqgml = NaN; +end + + + +%----------------------------------------- +% Converted to calendar years +%----------------------------------------- +if lmqyIndx(4) + yactCaly = zeros(1,length(vlist)); % the latest calendar year + yforeCaly = zeros(1+forepy,length(vlist)); + % including the calendar year prior to forecasting + % + yT1 = length(yactCal(:,1))/q_m; + if yT1 ~= 1 + error('yT1 Beginings or ends of monthly and calendar series are not the same!') + end + for i = 1:yT1 + i1 = 1+q_m*(i-1); + i2 = q_m*i; + yactCaly(i,:) = sum(yactCal(i1:i2,:)) ./ q_m; + end + yforeCaly(1,:) = yactCaly; + % + %@@ initial monthly actual data for calendar years + if qmEnd == q_m + yforeCaly_1 = 0; + else + ytem = xdata(nSampleCal+1:nSampleCal+qmEnd,:); + %ytem(:,vlistlog) = exp(ytem(:,vlistlog)); + yforeCaly_1 = sum(ytem,1); + % note, dimension "1" in sum(ytem,1) is necessary because when + % qmEnd=1, sum(ytem,1) will give us a nomber, not a vector. But this + % is not what we want. + end + % + if qmEnd == q_m + for i = 1:forepy + i1 = 1+q_m*(i-1); + i2 = q_m*i; + yforeCaly(1+i,:) = sum(yfore(i1:i2,:)) ./ q_m; + end + else + yforeCaly(2,:) = (yforeCaly_1+sum(yfore(1:q_m-qmEnd,:),1)) ./ q_m; + % note, dimension "1" in sum(yfore,1) is necessary because when + % q_m-qmEnd=1, sum(yfore) will give us a number, not a vector. But this + % is not what we want. + for i = 2:forepy + i1 = q_m-qmEnd+1+q_m*(i-2); + i2 = q_m-qmEnd+q_m*(i-1); + yforeCaly(1+i,:) = sum(yfore(i1:i2,:)) ./ q_m; + end + end + % + %@@ year-over-year growth rate + yforeCalyg = yforeCaly(2:forepy+1,:); + yforeCalyg(:,vlistlog) = ... + yforeCaly(2:forepy+1,vlistlog) - yforeCaly(1:forepy,vlistlog); + % year-over-year, log(1+growth rate) + yforeCalygml=yforeCalyg; + yforeCalygml(:,vlistlog) = 100*(exp(yforeCalyg(:,vlistlog))-1); + % annaul growth rate + yforeCalygml(:,vlistper) = 100*yforeCalyg(:,vlistper); % annaul growth rate +else + yforeCalygml = NaN; +end + + + +%ndraws +% +% posterior mean of out-of-sample forecasts +%yfore1 = (1.0/ndraws)*yfore1; % mean +%yforeqg1 = (1.0/ndraws)*yforeqg1; % mean +%yforeCalyg1 = (1.0/ndraws)*yforeCalyg1; % mean +% +%@@@ correlation of inflation and U +%IUcov = zeros(forepq,1); % forepq quarters +%IUbeta = zeros(forepq,2); % forepq quarters +%for i = 1:forepq +% indI = 4*forepq+i; +% indU = 5*forepq+i; +% %junk = corrcoef(yforeqgw(:,indI),yforeqgw(:,indU)); +% %IUcov(i,1) = junk(1,2); +% xjnk = [100*yforeqgw(:,indU) ones(ndraws,1)]; +% yjnk = yforeqgw(:,indI); +% junk = (xjnk'*xjnk)\(xjnk'*yjnk); +% IUbeta(i,:) = junk'; +%end + + +%% +% *** .68 and .90 probability bands of out-of-sample forecasts +%yforel = zeros(forep*nvar,1); % preallocating +%yforeh = zeros(forep*nvar,1); % preallocating +%yforeqgl = zeros(forepq*nvar,1); % preallocating +%yforeqgh = zeros(forepq*nvar,1); % preallocating + +%clear yfores yforepgs yforeCalygs +%*** write out final results +%yforeml = reshape(yforeml,forep,nvar); +%yforeqgml = reshape(yforeqgml,forepq,nvar); +%yforeCalygml = reshape(yforeCalygml,forepy,nvar); \ No newline at end of file diff --git a/MatlabFiles/fore_gh.m b/MatlabFiles/fore_gh.m new file mode 100755 index 0000000..bb808d2 --- /dev/null +++ b/MatlabFiles/fore_gh.m @@ -0,0 +1,241 @@ +function [yactCalyg,yforeCalygml,yAg,yFg,yactqg,yforeqgml,qAg,qFg,... + yactmg,yforemgml,mAg,mFg,yact,yactCal] = fore_gh(xinput) +% Plot graphics +% [yactCalyg,yforeCalygml,yAg,yFg,yactqg,yforeqgml,qAg,qFg,... +% yactmg,yforemgml,mAg,mFg,yact,yactCal] = fore_gh(xinput) +% +% xdata=xinput{1}: data, all logged except R, U, etc. +% nvar=xinput{2}: number of variables +% nSample=xinput{3}: sample size (including lags or initial periods) +% nSampleCal=xinput{4}: converting nSample of calendar years; +% yforelml=xinput{5}: monthly ML forecast, all in level, in percent +% yforemgml=xinput{6}: monthly growth -- annualized rate, in percent +% yforeqgml=xinput{7}: prior-quarter growth -- annualized rate, in percent +% yforeCalygml=xinput{8}: annual rate, expressed in percentage point, in percent +% actup=xinput{9}: periods for actual data (monthly) +% actupq=xinput{10}: periods for actual data (quarterly) +% actupy=xinput{11}: periods for actual data (calendar yearly) +% vlist=xinput{12}: list of variables +% vlistlog=xinput{13}: sub list of variables that are in log +% vlistper=xinput{14}: sub list of variables that are in percent +% q_m=xinput{15}: month or quarter in the model +% forep=xinput{16}: forecast periods (monthly) +% ylab=xinput{17}: labels for the y-axis +% forepq=xinput{18}: quarters in the forecast period +% forepy=xinput{19}: calendar years in the forecast period +% Psuedo=xinput{20}: 1: Psuedo out-of-sample; 0: real time out-of-sample +% Graphfore=xinput{21}: 1: graphics in this file; 0: no graphics in the execution. +% yearsCal=xinput{22}: calendar years matching output "yactCalyg" +% qmEnd=xinput{23}: last month (or quarter) of the sample +%------------- +% yactCalyg: annual growth for actual data +% yforeCalygml: annaul growth for ML forecasts, expressed in percent +% yAg: length of yactCalyg (actual data) +% yFg: lenght of yforeCalyg (forecasts) +% +% yactqg: prior-quarter annualized growth for actual data +% yforeqgml: prior-quarter annaulized growth for ML forecasts, expressed in percent +% qAg: length of yactqg (actual data) +% qFg: lenght of yforeqg (forecasts) +% +% yactmg: month-to-month annualized growth for actual data +% yforemgml: month-to-month annaulized growth for ML forecasts, expressed in percent +% mAg: length of yactqg (actual data) +% mFg: lenght of yforeqg (forecasts) +% +% yact: log(y) except R, ect. (monthly). If Psuedo, yact includes "forep" months. +% i.e., (actup+forep)-by-nvar +% yactCal: same as yact but ends at the end of the last calendar year. If Psuedo, +% (actup+forep)-by-nvar, which include some actual data in the 1st calendar year. +% +% Copyright (c) March 1998 by Tao Zha + + +xdata=xinput{1}; nvar=xinput{2}; nSample=xinput{3}; nSampleCal=xinput{4}; +yforelml=xinput{5}; yforemgml=xinput{6}; yforeqgml=xinput{7}; yforeCalygml=xinput{8}; +actup=xinput{9}; actupq=xinput{10}; actupy=xinput{11}; vlist=xinput{12}; +vlistlog=xinput{13}; vlistper=xinput{14}; q_m=xinput{15}; forep=xinput{16}; +ylab=xinput{17}; forepq=xinput{18}; forepy=xinput{19}; Psuedo=xinput{20}; +Graphfore=xinput{21}; yearsCal=xinput{22}; qmEnd=xinput{23}; + +% ========= plot the graphics with actural vs forecast vs Full Bayesian ========= +% +%*** actual data +if Psuedo + yact = xdata(nSample-actup+1:nSample+forep,:); % actup (not calendar) months + forep + yactCal = xdata(nSampleCal-actupy*q_m+1:nSampleCal+forepy*q_m,:); % calendar years +else + yact = xdata(nSample-actup+1:nSample,:); % actup (not calendar) months + yactCal = xdata(nSampleCal-actupy*q_m+1:nSampleCal,:); % caledar years +end +% + + + +%%%%--------------------------------------------------------------- +%$$$ Actual monthly growth rate, Prior quarter, and year-over-year change +%%%%--------------------------------------------------------------- + +% +%@@@ Monthly change (annaluized rate) +% +yactm = yact; +mT1 = length(yact(:,1)); +% +yactmg = yactm(2:mT1,:); % start at second month to get growth rate +yactmg(:,vlistlog) = (yactm(2:mT1,vlistlog) - yactm(1:mT1-1,vlistlog)) .* 12; + % monthly, 12*log(1+growth rate), annualized growth rate +yactmg(:,vlistlog) = 100*(exp(yactmg(:,vlistlog))-1); +yactmg(:,vlistper) = 100*yactmg(:,vlistper); +mAg = length(yactmg(:,1)); + + +% +%@@@ Prior Quarter change (annaluized rate) +% +if Psuedo + yactQ = xdata(nSample-mod(qmEnd,3)-actupq*3+1:nSample-mod(qmEnd,3)+forepq*3,:); + yactq = zeros(actupq+forepq,length(vlist)); +else + yactQ = xdata(nSample-mod(qmEnd,3)-actupq*3+1:nSample-mod(qmEnd,3),:); + yactq = zeros(actupq,length(vlist)); +end +% +qT1 = length(yactQ(:,1))/3; +qT1a = length(yactq(:,1)); +if qT1 ~= qT1a + warning('line #') + error('qT1: Beginings or ends of monthly and quarterly series do not match!') +end +% +for i = 1:qT1 + i1 = 1+3*(i-1); + i2 = 3*i; + yactq(i,:) = sum(yactQ(i1:i2,:)) ./ 3; +end +% +yactqg = yactq(5:qT1,:); % 4+1=5 where 4 means 4 quarters +yactqg(:,vlistlog) = (yactq(5:qT1,vlistlog) - yactq(4:qT1-1,vlistlog)) .* 4; + % quarterly, 4*log(1+growth rate), annualized growth rate +yactqg(:,vlistlog) = 100*(exp(yactqg(:,vlistlog))-1); +yactqg(:,vlistper) = 100*yactqg(:,vlistper); +qAg = length(yactqg(:,1)); + + +% +%@@@ Calendar year-over-year change +% +if Psuedo + yactCaly = zeros(actupy+forepy,length(vlist)); % past "actupy" calendar years + forepy +else + yactCaly = zeros(actupy,length(vlist)); % past "actupy" calendar years +end +yT1 = length(yactCal(:,1))/q_m; +yT1a = length(yactCaly(:,1)); +if yT1 ~= yT1a + error('yT1: Beginings or ends of monthly and quarterly series are not the same!') +end +% +for i = 1:yT1 + i1 = 1+q_m*(i-1); + i2 = q_m*i; + yactCaly(i,:) = sum(yactCal(i1:i2,:)) ./ q_m; +end +% +yactCalyg = yactCaly(2:yT1,:); % 1+1=2 where 1 means 1 year +yactCalyg(:,vlistlog) = (yactCaly(2:yT1,vlistlog) - yactCaly(1:yT1-1,vlistlog)); + % annual rate: log(1+growth rate) +yactCalyg(:,vlistlog) = 100*(exp(yactCalyg(:,vlistlog))-1); +yactCalyg(:,vlistper) = 100*yactCalyg(:,vlistper); +yAg = length(yactCalyg(:,1)); + + +%---------------------------------------------------------------------- +%================= Graphics of actual vs forecast =================== +%---------------------------------------------------------------------- +yactl(:,vlistlog)=exp(yact(:,vlistlog)); +yactl(:,vlistper)=100*yact(:,vlistper); % convert to levels, in percent +% +mFg = length(yforemgml(:,1)); +qFg = length(yforeqgml(:,1)); +yFg = length(yforeCalygml(:,1)); + +if Psuedo + t1=1:actup+forep; +else + t1=1:actup; +end +t2=actup+1:actup+forep; +% +if Graphfore + figure % The graphics below are expressed in level (monthly) + for i = 1:nvar + subplot(nvar/2,2,i) + plot(t1,yactl(:,i),t2,yforelml(:,i),'--') + %title('solid-actual, dotted-forecast'); + %title(eval(['forelabel'])); + %ylabel(eval(['x' int2str(i)])); + ylabel(char(ylab(i))) + end +end + +t1 = 1:mAg; +if Psuedo + t2 = mAg-mFg+1:mAg; +else + t2 = mAg+1:mAg+mFg; +end +% +if Graphfore + figure % The graphics below are monthly growth rates except R and U, at annualized rates + for i = 1:nvar + subplot(nvar/2,2,i) + plot(t1,yactmg(:,i),t2,yforemgml(:,i),'--') + %title('solid-actual, dotted-forecast'); + %xlabel(eval(['forelabel'])); + %ylabel(eval(['x' int2str(i)])); + ylabel(char(ylab(i))) + end +end + +t1 = 1:qAg; +if Psuedo + t2 = qAg-qFg+1:qAg; +else + t2 = qAg+1:qAg+qFg; +end +% +if Graphfore + figure % The graphics below are prior quarter growth rate except R and U, at annualized rates + for i = 1:nvar + subplot(nvar/2,2,i) + plot(t1,yactqg(:,i),t2,yforeqgml(:,i),'--') + %title('quarterly growth, unconditional'); + %xlabel(eval(['forelabel'])); + %ylabel(eval(['x' int2str(i)])); + ylabel(char(ylab(i))) + end +end + + +%t1 = 1:yAg; +t1 = yearsCal; +yAgCal=yearsCal(length(yearsCal)); +if Psuedo + t2 = yAgCal-yFg+1:yAgCal; +else + t2 = yAgCal+1:yAgCal+yFg; +end +% +if Graphfore + figure + % The graphics below are over-the-year growth rate except R and U, annually + for i = 1:nvar + subplot(nvar/2,2,i) + plot(t1,yactCalyg(:,i),t2,yforeCalygml(:,i),'--') + %title('solid-actual, dotted-forecast'); + %xlabel(eval(['forelabel'])); + %ylabel(eval(['x' int2str(i)])); + ylabel(char(ylab(i))) + end +end \ No newline at end of file diff --git a/MatlabFiles/fore_mqy.m b/MatlabFiles/fore_mqy.m new file mode 100755 index 0000000..9bbdbe1 --- /dev/null +++ b/MatlabFiles/fore_mqy.m @@ -0,0 +1,322 @@ +function [yforelml,yforemgml,yforeqgml,yforeCalygml,yactl,yactmg,yactqg,yactCalyg,yactlog] = ... + fore_mqy(yfore,xdata,nvar,nSample,nSampleCal,... + forep,forepq,forepy,q_m,qmEnd,vlist,vlistlog,vlistper,... + lmqyIndx,indxCal) +% [yforelml,yforemgml,yforeqgml,yforeCalygml,yactl,yactmg,yactqg,yactCalyg,yactlog] = ... +% fore_mqy(yfore,xdata,nvar,nSample,nSampleCal,... +% forep,forepq,forepy,q_m,qmEnd,vlist,vlistlog,vlistper,... +% lmqyIndx,indxCal) +% +% Converting oringinal forecast "yfore" to series by calendar years and series +% with growth rates (annualized for monthly and quarterly series) and +% with corresponding actual data (ONLY valid when we have actual data. +% Later should add an index to allow an option out 3/23/99). +% 3/23/99 I guess that this program is more general than fore_cal because it allows +% for non-Calendar annual growth rate calculation if nSample before "forep" and +% and q_m before "vlist" are used. +% +% yfore: oringal forecast series, all logged except R, U, etc. +% xdata: oringal data set, up to the period before (peudo-) out-of-sample forecasting, +% all logged except R, U, etc. +% nvar: number of variables +% nSample: sample size (including lags or initial periods) +% nSampleCal: sample size in terms of calendar years +% forep: forecast periods (monthly) +% forepq: forecast periods (quarterly) +% forepy: forecast periods (yearly) +% q_m: quarterly or monthly for the underlying model +% qmEnd: last q_m before out-of-sample forecasting +% vlist: a list of variables +% vlistlog: sub list of variables that are in log +% vlistper: sub list of variables that are in percent +% lmyqIndx: 4-by-1 1 or 0's. Index for level, mg, qg, and yg; 1: yes; 0: no +% indxCal: 1: calendar years; 0: (NOT calendar) years +%---------------- +% yforelml: forep-by-nvar, ymonthly ML forecast, all at level, in percent +% yforemgml: ML forecasts, monthly growth (at annual rates), in percent +% yforeqgml: ML forecast: quarterly growth (at annual rates), in percent +% yforeCalygml: forepq-by-nvar ML forecast: annual growth, in percent +% yactl: forep-by-nvar, actual, all at level, in percent +% yactmg: +% yactqg: +% yactCalyg: forepq-by-nvar, actual, annual growth, in percent +% yactlog: forep-by-nvar, actual, all log except R and U. +% +% Copyright (c) March 1998 by Tao Zha +% Revised, 3/23/99. Added "lmqyIndx" so that previous programs may not be compatible. +% Revised, 4/27/99. Added "indxCal" so that previous programs may not be compatible. + + +%================================================= +% Making everything presentable at FOMC +%================================================= +% +%%%% +%$$$ Monthly, prior quarter, and year-over-year change +%$$$ Out-of-sample forecasts +%%%% +% + +if length(lmqyIndx)~=4 + warning('lmqyIndx must be a 4-by-1 vector containing 1 or 0') + return +end + + + +%--------------------- +% Actual data +%--------------------- +yact = xdata(nSample-q_m+1:nSample,:); % the latest (not calender) year +yactCal = xdata(nSampleCal-q_m+1:nSampleCal,:); + % the lastest calendar year (always earlier than the lastest (not calendar) year + + + +%----------------------------------------- +% Converted to monthly level +%----------------------------------------- +if lmqyIndx(1) + yforelml=yfore; + yforelml(:,vlistlog)=exp(yfore(:,vlistlog)); % mode, all levels + yforelml(:,vlistper)=100*yfore(:,vlistper); % mode, all levels +else + yforelml = NaN; +end + + +%----------------------------------------- +% Converted to monthly growth +%----------------------------------------- +if lmqyIndx(2) + yactm = zeros(1,length(vlist)); % the latest month prior to forecasting + yforem = zeros(1+forep,length(vlist)); % including the 1 month prior to forecasting + % + yactm = yact(length(yact(:,1)),:); % last month prior to forecasting + yforem(1,:) = yactm; % last month prior to forecasting + yforem(2:forep+1,:) = yfore(1:forep,:); % monthly forecasts, all logged. + % + %@@ monthly growth rate (annualized) + yforemg = yforem(2:forep+1,:); + yforemg(:,vlistlog) = ( yforem(2:forep+1,vlistlog) - yforem(1:forep,vlistlog) ) .* q_m; + % monthly change (annualized), 12*log(1+growth rate) + yforemgml=yforemg; + yforemgml(:,vlistlog) = 100*(exp(yforemg(:,vlistlog))-1); % monthly growth rate (annualized) + yforemgml(:,vlistper) = 100*yforemg(:,vlistper); % monthly growth rate (annualized) +else + yforemgml=NaN; +end + + + +%----------------------------------------- +% Converted to quarterly +%----------------------------------------- +if lmqyIndx(3) + yactQ = xdata(nSample-mod(qmEnd,3)-q_m+1:nSample-mod(qmEnd,3),:); % the latest actual quarter + yactq = zeros(4,length(vlist)); % the latest 4 quarters prior to forecasting + yforeq = zeros(4+forepq,length(vlist)); % including the 4 quarters prior to forecasting + % + qT1 = length(yactQ(:,1))/3; + if qT1 ~= 4 + error('Must hae 4 actual quarters to compute quarterly change for forecasting!') + end + for i = 1:qT1 + i1 = 1+3*(i-1); + i2 = 3*i; + yactq(i,:) = sum(yact(i1:i2,:)) ./ 3; + end + yforeq(1:4,:) = yactq; + % + yforeq_1 = sum(xdata( nSample-mod(qmEnd,3)+1:nSample,:),1); + yforeq(5,:) = ( yforeq_1 + sum(yfore(1:3-mod(qmEnd,3),:),1) ) ./ 3; + % 1st quarterly forecast which may contain actual data within quarter + % note, dimension "1" in sum(ytem,1) is necessary because when + % qmEnd=1, sum(ytem,1) will give us a nomber, not a vector. But this + % is not what we want. + for i = 2:forepq + i1 = 3-mod(qmEnd,3) + 1+3*(i-2); + i2 = 3-mod(qmEnd,3) + 3*(i-1); + yforeq(4+i,:) = sum(yfore(i1:i2,:)) ./ 3; + end + % + %@@ prior quarter growth rate (annualized) + yforeqg = yforeq(5:forepq+4,:); + %yforeqg(:,vlistlog) = (100*(yforeq(5:qT2+4,vlistlog)-yforeq(1:qT2,vlistlog))) ... + % ./ yforeq(1:qT2,vlistlog); % year-over-year + %yforeqg(:,vlistlog) = 100*((yforeq(5:qT2+4,vlistlog)./yforeq(4:qT2+3,vlistlog)).^4 - 1 ); + % prior quarter + yforeqg(:,vlistlog) = ( yforeq(5:forepq+4,vlistlog) - yforeq(4:forepq+3,vlistlog) ) .* 4; + % prior quarter, 4*log(1+growth rate) + yforeqgml=yforeqg; + yforeqgml(:,vlistlog) = 100*(exp(yforeqg(:,vlistlog))-1); % quarterly growth rate (annualized) + yforeqgml(:,vlistper) = 100*yforeqg(:,vlistper); % quarterly growth rate (annualized) +else + yforeqgml = NaN; +end + + +%----------------------------------------- +% Converted to annual years (may not be calendar) +%----------------------------------------- +if lmqyIndx(4) + yactCaly = zeros(1,length(vlist)); % the latest calendar year + yforeCaly = zeros(1+forepy,length(vlist)); % including the calendar year prior to forecasting + % + yT1 = length(yactCal(:,1))/q_m; + if yT1 ~= 1 + error('yT1 Beginings or ends of monthly and calendar series are not the same!') + end + for i = 1:yT1 + i1 = 1+q_m*(i-1); + i2 = q_m*i; + yactCaly(i,:) = sum(yactCal(i1:i2,:)) ./ q_m; + end + yforeCaly(1,:) = yactCaly; + % + %@@ initial monthly actual data for calendar years + if qmEnd == q_m + yforeCaly_1 = 0; + else + ytem = xdata(nSampleCal+1:nSampleCal+qmEnd,:); + %ytem(:,vlistlog) = exp(ytem(:,vlistlog)); + yforeCaly_1 = sum(ytem,1); + % note, dimension "1" in sum(ytem,1) is necessary because when + % qmEnd=1, sum(ytem,1) will give us a nomber, not a vector. But this + % is not what we want. + end + % + if qmEnd == q_m + for i = 1:forepy + i1 = 1+q_m*(i-1); + i2 = q_m*i; + yforeCaly(1+i,:) = sum(yfore(i1:i2,:)) ./ q_m; + end + else + yforeCaly(2,:) = (yforeCaly_1+sum(yfore(1:q_m-qmEnd,:),1)) ./ q_m; + % note, dimension "1" in sum(yfore,1) is necessary because when + % q_m-qmEnd=1, sum(yfore) will give us a number, not a vector. But this + % is not what we want. + for i = 2:forepy + i1 = q_m-qmEnd+1+q_m*(i-2); + i2 = q_m-qmEnd+q_m*(i-1); + yforeCaly(1+i,:) = sum(yfore(i1:i2,:)) ./ q_m; + end + end + % + %@@ year-over-year growth rate + yforeCalyg = yforeCaly(2:forepy+1,:); + yforeCalyg(:,vlistlog) = yforeCaly(2:forepy+1,vlistlog) - yforeCaly(1:forepy,vlistlog); + % year-over-year, log(1+growth rate) + yforeCalygml=yforeCalyg; + yforeCalygml(:,vlistlog) = 100*(exp(yforeCalyg(:,vlistlog))-1); % annaul growth rate + yforeCalygml(:,vlistper) = 100*yforeCalyg(:,vlistper); % annaul growth rate +else + yforeCalygml = NaN; +end + + + +%---------------------------------------------------------------------- +% --------------------- Actual ----------------------------------------- +%---------------------------------------------------------------------- +if indxCal + Rem_qm = q_m-qmEnd; % remaining months within the first calendar year + Rem_y = floor((forep-Rem_qm)/q_m); % remaining calendar years after the first one + yact = xdata(nSample-2*q_m+1:nSample+Rem_qm+Rem_y*q_m,:); + % 2*q_m (not calendar) months + months ended at last calendar year +else + yact = xdata(nSample-q_m+1:nSample+forep,:); % q_m (not calendar) months + forep +end +mT1 = length(yact(:,1)); +yactlog = yact(q_m+1:mT1,:); + + +%----------------------------------------- +% Converted to monthly level +%----------------------------------------- +if lmqyIndx(1) + yactl=yactlog; + yactl(:,vlistlog)=exp(yactlog(:,vlistlog)); % mode, all levels + yactl(:,vlistper)=100*yactlog(:,vlistper); % mode, all levels +else + yactl=NaN; +end + +%----------------------------------------- +% Converted to monthly growth +%----------------------------------------- +if lmqyIndx(2) + yactmg = yactl; + yactmg(:,vlistlog) = (yact(q_m+1:mT1,vlistlog) - yact(q_m:mT1-1,vlistlog)) .* 12; + % monthly, 12*log(1+growth rate), annualized growth rate + yactmg(:,vlistlog) = 100*(exp(yactmg(:,vlistlog))-1); + yactmg(:,vlistper) = 100*yactmg(:,vlistper); +else + yactmg=NaN; +end + +%----------------------------------------- +% Converted to quarterly +%----------------------------------------- +if lmqyIndx(3) + warning(' ') + disp('Not worked out yet. 4/27/99') + disp('Press ctrl-c to abort!') + pause + + yactQ = yact(10:mT1,:); % October: beginning of the 4th quarter + yactq = zeros(1+forepq,length(vlist)); + qT1 = 1+forepq; + % + for i = 1:qT1 + i1 = 1+3*(i-1); + i2 = 3*i; + yactq(i,:) = sum(yactQ(i1:i2,:)) ./ 3; + end + % + yactqg = yactq(2:qT1,:); % 4+1=5 where 4 means 4 quarters + yactqg(:,vlistlog) = (yactq(2:qT1,vlistlog) - yactq(1:qT1-1,vlistlog)) .* 4; + % quarterly, 4*log(1+growth rate), annualized growth rate + yactqg(:,vlistlog) = 100*(exp(yactqg(:,vlistlog))-1); + yactqg(:,vlistper) = 100*yactqg(:,vlistper); +else + yactqg=NaN; +end + + +%----------------------------------------- +% Converted to annual years (may not be calendar) +%----------------------------------------- +if lmqyIndx(4) + if indxCal + yT1 = 1+forepy; + yactCaly = zeros(yT1,length(vlist)); % the latest 1+forepy calendar years + for i = 1:yT1 + i1 = ( Rem_qm+q_m*(qmEnd==q_m) ) + 1+q_m*(i-1); + i2 = ( Rem_qm+q_m*(qmEnd==q_m) ) + q_m*i; + yactCaly(i,:) = sum(yact(i1:i2,:)) ./ q_m; + end + % + yactCalyg = yactCaly(2:yT1,:); % 1+1=2 where 1 means 1 year + yactCalyg(:,vlistlog) = (yactCaly(2:yT1,vlistlog) - yactCaly(1:yT1-1,vlistlog)); + % annual rate: log(1+growth rate) + yactCalyg(:,vlistlog) = 100*(exp(yactCalyg(:,vlistlog))-1); + yactCalyg(:,vlistper) = 100*yactCalyg(:,vlistper); + else + yT1 = 1+forepy; + for i = 1:yT1 + i1 = 1+q_m*(i-1); + i2 = q_m*i; + yactCaly(i,:) = sum(yact(i1:i2,:)) ./ q_m; + end + % + yactCalyg = yactCaly(2:yT1,:); % 1+1=2 where 1 means 1 year + yactCalyg(:,vlistlog) = (yactCaly(2:yT1,vlistlog) - yactCaly(1:yT1-1,vlistlog)); + % annual rate: log(1+growth rate) + yactCalyg(:,vlistlog) = 100*(exp(yactCalyg(:,vlistlog))-1); + yactCalyg(:,vlistper) = 100*yactCalyg(:,vlistper); + end +else + yactCalyg=NaN; +end \ No newline at end of file diff --git a/MatlabFiles/forefixe.m b/MatlabFiles/forefixe.m new file mode 100755 index 0000000..71c9c8f --- /dev/null +++ b/MatlabFiles/forefixe.m @@ -0,0 +1,30 @@ +function yhat = forefixe(A0h,Bh,phi,nn,Estr) +% yhat = forefixe(A0h,Bh,phi,nn,Estr) +% Forecat conditional on particular structural shocks +% +% where A0h: column means equation +% Bh: the (posterior) estimate of B; +% phi: the 1-by-(nvar*lags+1) data matrix where k=nvar*lags+1 +% (last period plus lags before the beginning of forecast); +% nn: [nvar,lags,forep], forep: forecast periods; +% Estr: forep-by-nvar, each column corresponds to shocks from a particular +% source such as MS; +% yhat: forep*nvar; +% +% For reduced-form shocks, see fshock.m + +% ** setup +nvar = nn(1); +lags = nn(2); +forep = nn(3); +tcwc = nvar*lags; % total coefficients without constant + +% ** reconstruct x(t) for y(t+h) = x(t+h-1)*B +% ** where phi = x(t+h-1) with last column being constant +Ures = Estr/A0h; +yhat = zeros(forep,nvar); +for k=1:forep + yhat(k,:) = phi*Bh + Ures(k,:); + phi(1,nvar+1:tcwc) = phi(1,1:tcwc-nvar); + phi(1,1:nvar) = yhat(k,:); +end diff --git a/MatlabFiles/fshock.m b/MatlabFiles/fshock.m new file mode 100755 index 0000000..d3d4a0d --- /dev/null +++ b/MatlabFiles/fshock.m @@ -0,0 +1,28 @@ +function yhat = fshock(Bh,phi,shock,nn) +% fshock: unconditionally forecasts supplied with reduced-form shocks +% yhat = fshock(Bh,phi,shock,nn) +% +% y_hat(t+h) = c + x_hat(t+h-1)*Bh, X: 1*k; Bh: k*nvar; y_hat: 1*nvar +% where Bh: the (posterior) estimate of B; +% phi: the 1-by-(nvar*lags+1) initial data matrix where k=nvar*lags+1 +% (last period plus lags before the beginning of forecast); +% shock: forep-by-nvar reduced-form residuals, where forep: forecast periods; +% nn: [nvar,lags,forep]; +% yhat: forep-by-nvar. +% +% For structural shocks, see forefixe.m + +% ** setup +nvar = nn(1); +lags = nn(2); +forep = nn(3); +tcwc = nvar*lags; % total coefficients without constant + +% ** reconstruct x(t) for y(t+h) = x(t+h-1)*B +% ** where phi = x(t+h-1) with last column being constant +yhat = zeros(forep,nvar); +for k=1:forep + yhat(k,:) = phi*Bh + shock(k,:); + phi(1,nvar+1:tcwc) = phi(1,1:tcwc-nvar); + phi(1,1:nvar) = yhat(k,:); +end diff --git a/MatlabFiles/fsim.m b/MatlabFiles/fsim.m new file mode 100755 index 0000000..0b55d9f --- /dev/null +++ b/MatlabFiles/fsim.m @@ -0,0 +1,33 @@ +function yhat = fsim(Bh,A0h,phi,nn) +% yhat = fsim(Bh,A0h,phi,nn) +% Unconditional forecasts with simulated shocks (which do not depend on reduced-form or structural shocks). +% y_hat(t+h) = c + x_hat(t+h-1)*Bh, X: 1*k; Bh: k*nvar; y_hat: 1*nvar +% where Bh: the (posterior) estimate of B; +% A0h: has columns correpond to equations +% phi: the 1-by-(nvar*lags+1) data matrix where k=nvar*lags+1 +% (last period plus lags before the beginning of forecast); +% nn: [nvar,lags,forep], forep: forecast periods; +% yhat: forep*nvar. +% +% 3/22/99. Revised so that A0h has columns corr. to equations. Previous +% may use A0h' (papers before Sims and Zha IER paper). So please double +% check. +% +% See forecasterr.m when A0h_in (instead of A0h) is used. + +% ** setup +nvar = nn(1); +lags = nn(2); +forep = nn(3); +tcwc = nvar*lags; % total coefficients without constant + +Ures = randn(forep,nvar)/A0h; % Unconditional forecast + % Now, forep-by-nvar -- ready for forecasts + % Ures: reduced-form residuals. Row--steps; Column--n shocks + +yhat = zeros(forep,nvar); +for k=1:forep + yhat(k,:) = phi*Bh + Ures(k,:); + phi(1,nvar+1:tcwc) = phi(1,1:tcwc-nvar); + phi(1,1:nvar) = yhat(k,:); +end diff --git a/MatlabFiles/gactual.m b/MatlabFiles/gactual.m new file mode 100755 index 0000000..c9f3ffe --- /dev/null +++ b/MatlabFiles/gactual.m @@ -0,0 +1,181 @@ +function actual = gactual(begy,begm,begq,finy,finm,finq,ylab,mqyIndx,idfile) +% +% actual = gactual(begy,begm,begq,finy,finm,finq,ylab,mqyIndx,idfile) +% Actual data according to mqyIndx; graph if no output argument is specified. +% +% begy: the beginning year for the graph +% begm: the begiining month for the graph +% begq: the begiining quarter for the graph +% finy: the end year for the graph +% finm: the end month for the graph +% finq: the end quarter for the graph +% ylab: label for each variable +% mqyIndx: 1-by-3 index of monthly log, qg, and calendar yg. 1: yes; 0: no. +% Only one at a time +% idfile: import xinample.mat in the LZ paper under \condz +%-------------- +% actual: T-by-nvar+1; 1st column is the dates; 2nd-7th columns: actual data of +% of nvar variables with mlog, qg, or calendar yg, one at a time, +% depending on mqyIndx +% graph if no output argument is specified. +% +% +% When insampleg.m is run, xinsample.mat is loaded for a long +% history (e.g.,1960-1998) +% When mspoint.m is run, outxshock.mat from msstart is loaded, which varies +% with parac.m. +% +% October 1998 by Tao A. Zha + + +eval(['load ' idfile '.mat']); +% + +if length(find(mqyIndx))>1 + warning('To get the number (not graph) out, only one at a time') + disp('Make sure that mqyIndx has only 1 in a vector of 1 and 0s') + disp(' ') + disp('Press Enter to continue or Ctrl to abort') + pause +end + +if mqyIndx(1)==1 % monthly log + ibegy = find(myears==begy); + ifiny = find(myears==finy); + + ibegy1 = find(myears==begy+1); + % + if isempty(ibegy) & isempty(ibegy1) + warning('Either ibegy or begm is out of the range of myears in xinsample.mat') + disp('Print myears to see the range') + disp('Or change actuap to make the range longer and save new results to Xshock.mat') + disp('Press ctrl-c to abort now') + pause + elseif isempty(ibegy) & (begm<myears(1)) + warning('Either ibegy or begm is out of the range of myears in xinample.mat') + disp('Print myears to see the range') + disp('Or change actuap to make the range longer and save new results to Xshock.mat') + disp('Press ctrl-c to abort now') + pause + elseif isempty(ibegy) + ibegy = -myears(1)+2; % +2 is needed for the following -1 in + % bar(Estrexa(ibegy+begm-1:ifiny+finm-1,i)) + %so that it 2-1=1 so that +1 is what we want + end + % + if isempty(ifiny) + warning('Either ifiny or finm is out of the range of myears') + disp('Print myears to see the range') + disp('Or change actuap to make the range longer and save new results to Xshock.mat') + return + elseif (ifiny+finm-1>size(myears,1)) + warning('Either ifiny or finm is out of the range of myears') + disp('Print myears to see the range') + disp('Or change actuap to make the range longer and save new results to Xshock.mat') + return + end + + + if nargout==0 + t=length(yact(ibegy+begm-1:ifiny+finm-1,1)); + for i=1:size(yact,2) + figure + plot(1:t, yact(ibegy+begm-1:ifiny+finm-1,i),'*:'); + %bar(yact(ibegy+begm-1:ifiny+finm-1,i)) + title('Monthly Log') + ylabel(char(ylab(i))) + xlabel([ 'From ' num2str(begy) ':' num2str(begm) ' to ' ... + num2str(finy) ':' num2str(finm) ]) + grid + end + end + + actual = [myears(ibegy+begm-1:ifiny+finm-1) yact(ibegy+begm-1:ifiny+finm-1,:)]; +end + + +if mqyIndx(2)==1 % quarterly + ibegy = find(qyears==begy); + ifiny = find(qyears==finy); + + ibegy1 = find(qyears==begy+1); + % + if isempty(ibegy) & isempty(ibegy1) + warning('Either ibegy or begq is out of the range of qyears') + disp('Print qyears to see the range') + disp('Or change actuap to make the range longer and save new results to Xshock.mat') + return + elseif isempty(ibegy) & (begq<qyears(1)) + warning('Either ibegy or begq is out of the range of qyears') + disp('Print qyears to see the range') + disp('Or change actuap to make the range longer and save new results to Xshock.mat') + return + elseif isempty(ibegy) + ibegy = -qyears(1)+2; % +2 is needed for the following -1 in + % bar(Estrexa(ibegy+begq-1:ifiny+finm-1,i)) + %so that it 2-1=1 so that +1 is what we want + end + % + if isempty(ifiny) + warning('Either ifiny or finq is out of the range of qyears') + disp('Print qyears to see the range') + disp('Or change actuap to make the range longer and save new results to Xshock.mat') + return + elseif (ifiny+finq-1>size(qyears,1)) + warning('Either ifiny or finq is out of the range of qyears') + disp('Print qyears to see the range') + disp('Or change actuap to make the range longer and save new results to Xshock.mat') + return + end + + + if nargout==0 + t=length(yactqg(ibegy+begq-1:ifiny+finq-1,1)); + for i=1:size(yactqg,2) + figure + plot(1:t, yactqg(ibegy+begq-1:ifiny+finq-1,i),'*:'); + title('Quarter-to-quarter Growth Rate') + ylabel(char(ylab(i))) + xlabel([ 'From ' num2str(begy) ':' num2str(begq) ' to ' ... + num2str(finy) ':' num2str(finq) ]) + grid + end + end + + actual = [qyears(ibegy+begq-1:ifiny+finq-1) yactqg(ibegy+begq-1:ifiny+finq-1,:)]; +end + + +if mqyIndx(3)==1 % calendar year + ibegy = find(yearsCal==begy); + ifiny = find(yearsCal==finy); + % + if isempty(ibegy) + warning('Either ibegy or begq is out of the range of yearsCal') + disp('Print yearsCal to see the range') + disp('Or change actuap to make the range longer and save new results to Xshock.mat') + return + end + % + if isempty(ifiny) + warning('Either ifiny or finq is out of the range of yearsCal') + disp('Print yearsCal to see the range') + disp('Or change actuap to make the range longer and save new results to Xshock.mat') + return + end + + if nargout==0 + t=length(yactCalyg(ibegy:ifiny,1)); + for i=1:size(yactCalyg,2) + figure + plot(1:t, yactCalyg(ibegy:ifiny,i),'*:'); + title('Calendar Annual Average Growth Rate') + ylabel(char(ylab(i))) + xlabel([ 'From 19' num2str(begy) ' to 19' ... + num2str(finy) ]) + grid + end + end + + actual = [yearsCal(ibegy:ifiny) yactCalyg(ibegy:ifiny,:)]; +end diff --git a/MatlabFiles/gaf.m b/MatlabFiles/gaf.m new file mode 100755 index 0000000..73fb5b9 --- /dev/null +++ b/MatlabFiles/gaf.m @@ -0,0 +1,88 @@ +function gaf(yrEnd,qmEnd,q_m,yearsCal,yactCalyg,forepy,... + yhatCalygml,xlab,ylab,forelabel,conlab,keyindx,rnum,cnum) +% gaf(yrEnd,qmEnd,q_m,yearsCal,yactCalyg,forepy,... +% yhatCalygml,xlab,ylab,forelabel,conlab,keyindx,rnum,cnum) +% Graph (calendar year) forecasts vs actual (actual from "msstart.m") +% Make sure that actup in "msstart.m" is set at the length for visual graphs +% +% yrEnd: the end year for the sample +% qmEnd: last q_m before out-of-sample forecasting +% q_m: quarterly or monthly for the underlying model +% yearsCal: calendar years including actual and forecast data +% yactCalyg: actual calendar annual growth data +% yhatCalygml: conditional (calendar annual) forecasts on particular shocks +% forepy: forecast periods (yearly) +% xlab: label for structural equations +% ylab: label for the variables +% forelabel: title label for as of time of forecast +% conlab: label for what conditions imposed; e.g., conlab = 'All bar MS shocks inspl' +% keyindx: index for the variables to be graphed +% rnum: number of rows in subplot +% cnum: number of columns in subplot +%------------- +% No output argument for this graph file +% +% October 1998 Tao Zha; revised, 03/20/99 + + + + +%*** Begining forecast (actual) period +fbegm = qmEnd+1; % +1 because the first month out of sample +if fbegm > q_m % the first forecast month into the next year + fbegm = 1; + fbegy = yrEnd+1; % the first forecast year for the graph +else + fbegy = yrEnd; % the first forecast year for the graph +end +abegy = min(yearsCal); % the actual beginning year for the graph, NOT the same as + % the first forecast year +%abegm = 1; +ifbegy = find(yearsCal==fbegy-1); % index for the actual year in "yactCalyg" + % before the first forecast year + +%*** Final forecast (and actual) period +ffiny = fbegy+forepy-1; % the forecast final year +afiny = max(yearsCal); % the actual final year for the graph, coinciding with + + + +figure + +nvar = size(yhatCalygml,2); % Pcm,M2,FFR,GdP, CPI, U +%keyindx = 1:nvar; % Pcm,M2,FFR,GdP, CPI, U +%keyindx = [4:nvar 3 2]; % GdP, CPI, U, FFR, M2 + +hornum = cell(length(abegy:ffiny),1); % horizontal number +count=0; +for k=abegy:ffiny + count=count+1; + jnk=num2str(k); + hornum{count}=jnk(3:4); % e.g., with '1990', we have '90' +end + +count=0; +cnum = 2; +% +for i = keyindx + count = count+1; + subplot(rnum,cnum,count) + % + if abegy>fbegy-1 + plot(abegy:afiny,yactCalyg(:,i),fbegy:ffiny,yhatCalygml(:,i),'-.') + set(gca,'XTick',abegy:ffiny) + else + plot(abegy:afiny,yactCalyg(:,i),... + fbegy-1:ffiny,[yactCalyg(ifbegy,i);yhatCalygml(:,i)],'-.') + set(gca,'XTick',abegy:ffiny) + end + set(gca,'XTickLabel',char(hornum)) + if i<=cnum + title(forelabel) + elseif i>=nvar-1 + xlabel(conlab) + end + % + grid + ylabel(char(ylab(i))) +end \ No newline at end of file diff --git a/MatlabFiles/gaferr1.m b/MatlabFiles/gaferr1.m new file mode 100755 index 0000000..14c4006 --- /dev/null +++ b/MatlabFiles/gaferr1.m @@ -0,0 +1,90 @@ +function gaferr1(yrEnd,qmEnd,q_m,yearsCal,yactCalyg,forepy,yhatCalygml,yhatCalygl1,... + yhatCalygh1,xlab,ylab,forelabel,conlab,keyindx,rnum,cnum) + +% +% One (.68) error band: (calendar year) forecasts vs actual (actual from "msstart.m") +% Make sure that actup in "msstart.m" is set at the length for visual graphs +% +% yrEnd: the end year for the sample +% qmEnd: last q_m before out-of-sample forecasting +% q_m: quarterly or monthly for the underlying model +% yearsCal: calendar years including actual and forecast data +% yactCalyg: actual calendar annual growth data +% yhatCalygml: conditional (calendar annual) forecasts on particular shocks +% yhatCalygl1: 0.68 lower band +% yhatCalygh1: 0.68 upper band +% forepy: forecast periods (yearly) +% xlab: label for structural equations +% ylab: label for the variables +% forelabel: title label for as of time of forecast +% conlab: label for what conditions imposed; e.g., conlab = 'All bar MS shocks inspl' +% keyindx: index for the variables to be graphed +% rnum: number of rows in subplot +% cnum: number of columns in subplot +%------------- +% No output argument for this graph file +% +% 03/19/99 + + + +%*** Begining period +fbegm = qmEnd+1; % +1 because the first month out of sample +if fbegm > q_m % the first forecast month into the next year + fbegm = 1; + fbegy = yrEnd+1; % the first forecast year for the graph +else + fbegy = yrEnd; % the first forecast year for the graph +end +abegy = min(yearsCal); % the actual beginning year for the graph +abegm = 1; +ifbegy = find(yearsCal==fbegy-1); % index for the year before the first + % forecast first year in actual data "yactCalyg" + +%*** Final period +ffiny = fbegy+forepy-1; % the forecast final year +afiny = max(yearsCal); % the actual final year + + + +figure + +nvar = size(yhatCalygml,2); % Pcm,M2,FFR,GdP, CPI, U +%keyindx = 1:nvar; % Pcm,M2,FFR,GdP, CPI, U +%keyindx = [4:nvar 3 2]; % GdP, CPI, U, FFR, M2 + +hornum = cell(length(abegy:ffiny),1); % horizontal number +count=0; +for k=abegy:ffiny + count=count+1; + jnk=num2str(k); + hornum{count}=jnk(3:4); % e.g., with '1990', we have '90' +end + +count=0; +% +for i = keyindx + count = count+1; + subplot(rnum,cnum,count) + % + if abegy>fbegy-1 + plot(abegy:afiny,yactCalyg(:,i),fbegy:ffiny,yhatCalygml(:,i),'-.',... + fbegy:ffiny,yhatCalygl1,'--',fbegy:ffiny,yhatCalygh1,'--' ) + set(gca,'XTick',abegy:ffiny) + else + plot(abegy:afiny,yactCalyg(:,i),... + fbegy-1:ffiny,[yactCalyg(ifbegy,i);yhatCalygml(:,i)],'-.',... + fbegy-1:ffiny,[yactCalyg(ifbegy,i);yhatCalygl1(:,i)],'--',... + fbegy-1:ffiny,[yactCalyg(ifbegy,i);yhatCalygh1(:,i)],'--') + set(gca,'XTick',abegy:ffiny) + end + set(gca,'XTickLabel',char(hornum)) + if i<=cnum + title(forelabel) + elseif i>=nvar-1 + xlabel(conlab) + end + % + grid + ylabel(char(ylab(i))) +end diff --git a/MatlabFiles/gampar.m b/MatlabFiles/gampar.m new file mode 100755 index 0000000..bd0ab95 --- /dev/null +++ b/MatlabFiles/gampar.m @@ -0,0 +1,15 @@ +function f = gampar(ab, XLO, XUP, PLO, PUP); + +% The function takes as inputs the parameters ab=[a, b] of the gamma +% distribution, the bounds of the support [XLO, XUP], the the corresponding +% probability of the bounds [PLO, PUP] and returns the residual value f. + +a = abs(ab(1)); b = abs(ab(2)); % abs() is used to allow continuous search for the fsolve function find_gampar.m. +f1 = PLO - gamcdf(XLO, a, 1/b); %Note that in Matlab, it is 1/b, NOT b. +f2 = PUP - gamcdf(XUP, a, 1/b); %Note that in Matlab, it is 1/b, NOT b. +% Equivalently, one can use the gaminv function to define the zero +% conditions: +% f1 = XLO - gaminv(PLO, a, b); +% f2 = XUP - gaminv(PUP, a, b); + +f = [f1, f2]; diff --git a/MatlabFiles/gensys.m b/MatlabFiles/gensys.m new file mode 100755 index 0000000..c533a0e --- /dev/null +++ b/MatlabFiles/gensys.m @@ -0,0 +1,169 @@ +function [G1,C,impact,fmat,fwt,ywt,gev,eu]=gensys(g0,g1,c,psi,pi,div) +% function [G1,C,impact,fmat,fwt,ywt,gev,eu]=gensys(g0,g1,c,psi,pi,div) +% System given as +% g0*y(t)=g1*y(t-1)+c+psi*z(t)+pi*eta(t), +% with z an exogenous variable process and eta being endogenously determined +% one-step-ahead expectational errors. Returned system is +% y(t)=G1*y(t-1)+C+impact*z(t)+ywt*inv(I-fmat*inv(L))*fwt*z(t+1) . +% If z(t) is i.i.d., the last term drops out. +% If div is omitted from argument list, a div>1 is calculated. +% eu(1)=1 for existence, eu(2)=1 for uniqueness. eu(1)=-1 for +% existence only with not-s.c. z; eu=[-2,-2] for coincident zeros. +% By Christopher A. Sims +% Corrected 10/28/96 by CAS +eu=[0;0]; +realsmall=1e-6; +fixdiv=(nargin==6); +n=size(g0,1); +[a b q z v]=qz(g0,g1); +if ~fixdiv, div=1.01; end +nunstab=0; +zxz=0; +for i=1:n +% ------------------div calc------------ + if ~fixdiv + if abs(a(i,i)) > 0 + divhat=abs(b(i,i))/abs(a(i,i)); + % bug detected by Vasco Curdia and Daria Finocchiaro, 2/25/2004 A root of + % exactly 1.01 and no root between 1 and 1.02, led to div being stuck at 1.01 + % and the 1.01 root being misclassified as stable. Changing < to <= below fixes this. + if 1+realsmall<divhat & divhat<=div + div=.5*(1+divhat); + end + end + end +% ---------------------------------------- + nunstab=nunstab+(abs(b(i,i))>div*abs(a(i,i))); + if abs(a(i,i))<realsmall & abs(b(i,i))<realsmall + zxz=1; + end +end +div ; +nunstab; +if ~zxz + [a b q z]=qzdiv(div,a,b,q,z); +end +gev=[diag(a) diag(b)]; +if zxz + disp('Coincident zeros. Indeterminacy and/or nonexistence.') + eu=[-2;-2]; + % correction added 7/29/2003. Otherwise the failure to set output + % arguments leads to an error message and no output (including eu). + G1=[];C=[];impact=[];fmat=[];fwt=[];ywt=[];gev=[]; + return +end +q1=q(1:n-nunstab,:); +q2=q(n-nunstab+1:n,:); +z1=z(:,1:n-nunstab)'; +z2=z(:,n-nunstab+1:n)'; +a2=a(n-nunstab+1:n,n-nunstab+1:n); +b2=b(n-nunstab+1:n,n-nunstab+1:n); +etawt=q2*pi; +% zwt=q2*psi; +[ueta,deta,veta]=svd(etawt); +md=min(size(deta)); +bigev=find(diag(deta(1:md,1:md))>realsmall); +ueta=ueta(:,bigev); +veta=veta(:,bigev); +deta=deta(bigev,bigev); +% ------ corrected code, 3/10/04 +eu(1) = length(bigev)>=nunstab; +% ------ Code below allowed "existence" in cases where the initial lagged state was free to take on values +% ------ inconsistent with existence, so long as the state could w.p.1 remain consistent with a stable solution +% ------ if its initial lagged value was consistent with a stable solution. This is a mistake, though perhaps there +% ------ are situations where we would like to know that this "existence for restricted initial state" situation holds. +%% [uz,dz,vz]=svd(zwt); +%% md=min(size(dz)); +%% bigev=find(diag(dz(1:md,1:md))>realsmall); +%% uz=uz(:,bigev); +%% vz=vz(:,bigev); +%% dz=dz(bigev,bigev); +%% if isempty(bigev) +%% exist=1; +%% else +%% exist=norm(uz-ueta*ueta'*uz) < realsmall*n; +%% end +%% if ~isempty(bigev) +%% zwtx0=b2\zwt; +%% zwtx=zwtx0; +%% M=b2\a2; +%% for i=2:nunstab +%% zwtx=[M*zwtx zwtx0]; +%% end +%% zwtx=b2*zwtx; +%% [ux,dx,vx]=svd(zwtx); +%% md=min(size(dx)); +%% bigev=find(diag(dx(1:md,1:md))>realsmall); +%% ux=ux(:,bigev); +%% vx=vx(:,bigev); +%% dx=dx(bigev,bigev); +%% existx=norm(ux-ueta*ueta'*ux) < realsmall*n; +%% else +%% existx=1; +%% end +% ---------------------------------------------------- +% Note that existence and uniqueness are not just matters of comparing +% numbers of roots and numbers of endogenous errors. These counts are +% reported below because usually they point to the source of the problem. +% ------------------------------------------------------ +[ueta1,deta1,veta1]=svd(q1*pi); +md=min(size(deta1)); +bigev=find(diag(deta1(1:md,1:md))>realsmall); +ueta1=ueta1(:,bigev); +veta1=veta1(:,bigev); +deta1=deta1(bigev,bigev); +%% if existx | nunstab==0 +%% %disp('solution exists'); +%% eu(1)=1; +%% else +%% if exist +%% %disp('solution exists for unforecastable z only'); +%% eu(1)=-1; +%% %else +%% %fprintf(1,'No solution. %d unstable roots. %d endog errors.\n',nunstab,size(ueta1,2)); +%% end +%% %disp('Generalized eigenvalues') +%% %disp(gev); +%% %md=abs(diag(a))>realsmall; +%% %ev=diag(md.*diag(a)+(1-md).*diag(b))\ev; +%% %disp(ev) +%% % return; +%% end +if isempty(veta1) + unique=1; +else + unique=norm(veta1-veta*veta'*veta1)<realsmall*n; +end +if unique + %disp('solution unique'); + eu(2)=1; +else + fprintf(1,'Indeterminacy. %d loose endog errors.\n',size(veta1,2)-size(veta,2)); + %disp('Generalized eigenvalues') + %disp(gev); + %md=abs(diag(a))>realsmall; + %ev=diag(md.*diag(a)+(1-md).*diag(b))\ev; + %disp(ev) +% return; +end +tmat = [eye(n-nunstab) -(ueta*(deta\veta')*veta1*deta1*ueta1')']; +G0= [tmat*a; zeros(nunstab,n-nunstab) eye(nunstab)]; +G1= [tmat*b; zeros(nunstab,n)]; +% ---------------------- +% G0 is always non-singular because by construction there are no zeros on +% the diagonal of a(1:n-nunstab,1:n-nunstab), which forms G0's ul corner. +% ----------------------- +G0I=inv(G0); +G1=G0I*G1; +usix=n-nunstab+1:n; +C=G0I*[tmat*q*c;(a(usix,usix)-b(usix,usix))\q2*c]; +impact=G0I*[tmat*q*psi;zeros(nunstab,size(psi,2))]; +fmat=b(usix,usix)\a(usix,usix); +fwt=-b(usix,usix)\q2*psi; +ywt=G0I(:,usix); +% -------------------- above are output for system in terms of z'y ------- +G1=real(z*G1*z'); +C=real(z*C); +impact=real(z*impact); +% Correction 10/28/96: formerly line below had real(z*ywt) on rhs, an error. +ywt=z*ywt; diff --git a/MatlabFiles/gensysOldVersion.m b/MatlabFiles/gensysOldVersion.m new file mode 100755 index 0000000..2965337 --- /dev/null +++ b/MatlabFiles/gensysOldVersion.m @@ -0,0 +1,151 @@ +function [G1,C,impact,fmat,fwt,ywt,gev,eu]=gensys(g0,g1,c,psi,pi,div) +%function [G1,C,impact,fmat,fwt,ywt,gev,eu]=gensys(g0,g1,c,psi,pi,div) +%System given as +% g0*y(t)=g1*y(t-1)+c+psi*z(t)+pi*eta(t), +%with z an exogenous variable process and eta being endogenously determined +%one-step-ahead expectational errors. Returned system is +% y(t)=G1*y(t-1)+C+impact*z(t)+ywt*inv(I-fmat*inv(L))*fwt*z(t+1) . +% If z(t) is i.i.d., the last term drops out. +% If div is omitted from argument list, a div>1 is calculated. +% eu(1)=1 for existence, eu(2)=1 for uniqueness. eu(1)=-1 for +% existence only with not-s.c. z; eu=[-2,-2] for coincident zeros. +% By Christopher A. Sims +% Corrected 10/28/96 by CAS +eu=[0;0]; +realsmall=1e-6; +fixdiv=(nargin==6); +n=size(g0,1); +[a b q z]=qz(g0,g1); +if ~fixdiv, div=1.01; end +nunstab=0; +zxz=0; +for i=1:n +%------------------div calc------------ + if ~fixdiv + if abs(a(i,i)) > 0 + divhat=abs(b(i,i))/abs(a(i,i)); + if 1+realsmall<divhat & divhat<div + div=.5*(1+divhat); + end + end + end +%---------------------------------------- + nunstab=nunstab+(abs(b(i,i))>div*abs(a(i,i))); + if abs(a(i,i))<realsmall & abs(b(i,i))<realsmall + zxz=1; + end +end +if ~zxz + [a b q z]=qzdiv(div,a,b,q,z); +end +save d:\mex\gensysmkl\abqz.mat a b q z div +gev=[diag(a) diag(b)]; +if zxz + %disp('Coincident zeros. Indeterminacy and/or nonexistence.') + eu=[-2;-2]; + return +end +q1=q(1:n-nunstab,:); +q2=q(n-nunstab+1:n,:); +a2=a(n-nunstab+1:n,n-nunstab+1:n); +b2=b(n-nunstab+1:n,n-nunstab+1:n); +etawt=q2*pi; +zwt=q2*psi; +[ueta,deta,veta]=svd(etawt); +md=min(size(deta)); +bigev=find(diag(deta(1:md,1:md))>realsmall); +ueta=ueta(:,bigev); +veta=veta(:,bigev); +deta=deta(bigev,bigev); +[uz,dz,vz]=svd(zwt); +md=min(size(dz)); +bigev=find(diag(dz(1:md,1:md))>realsmall); +uz=uz(:,bigev); +vz=vz(:,bigev); +dz=dz(bigev,bigev); +if isempty(bigev) + exist=1; + existx=1; +else + exist=norm(uz-ueta*ueta'*uz) < realsmall*n; + zwtx0=b2\zwt; + zwtx=zwtx0; + M=b2\a2; + for i=2:nunstab + zwtx=[M*zwtx zwtx0]; + end + zwtx=b2*zwtx; + [ux,dx,vx]=svd(zwtx); + md=min(size(dx)); + bigev=find(diag(dx(1:md,1:md))>realsmall); + ux=ux(:,bigev); + vx=vx(:,bigev); + dx=dx(bigev,bigev); + existx=norm(ux-ueta*ueta'*ux) < realsmall*n; +end +%---------------------------------------------------- +% Note that existence and uniqueness are not just matters of comparing +% numbers of roots and numbers of endogenous errors. These counts are +% reported below because usually they point to the source of the problem. +%------------------------------------------------------ +[ueta1,deta1,veta1]=svd(q1*pi); +md=min(size(deta1)); +bigev=find(diag(deta1(1:md,1:md))>realsmall); +ueta1=ueta1(:,bigev); +veta1=veta1(:,bigev); +deta1=deta1(bigev,bigev); +if existx | nunstab==0 + %disp('solution exists'); + eu(1)=1; +else + if exist + %disp('solution exists for unforecastable z only'); + eu(1)=-1; + %else + %fprintf(1,'No solution. %d unstable roots. %d endog errors.\n',nunstab,size(ueta1,2)); + end + %disp('Generalized eigenvalues') + %disp(gev); + %md=abs(diag(a))>realsmall; + %ev=diag(md.*diag(a)+(1-md).*diag(b))\ev; + %disp(ev) +% return; +end +if isempty(veta1) + unique=1; +else + unique=norm(veta1-veta*veta'*veta1)<realsmall*n; +end +if unique + %disp('solution unique'); + eu(2)=1; +else + fprintf(1,'Indeterminacy. %d loose endog errors.\n',size(veta1,2)-size(veta,2)); + %disp('Generalized eigenvalues') + %disp(gev); + %md=abs(diag(a))>realsmall; + %ev=diag(md.*diag(a)+(1-md).*diag(b))\ev; + %disp(ev) +% return; +end +tmat = [eye(n-nunstab) -(ueta*(deta\veta')*veta1*deta1*ueta1')']; +G0= [tmat*a; zeros(nunstab,n-nunstab) eye(nunstab)]; +G1= [tmat*b; zeros(nunstab,n)]; +%---------------------- +% G0 is always non-singular because by construction there are no zeros on +% the diagonal of a(1:n-nunstab,1:n-nunstab), which forms G0's ul corner. +%----------------------- +G0I=inv(G0); +G1=G0I*G1; +usix=n-nunstab+1:n; +C=G0I*[tmat*q*c;(a(usix,usix)-b(usix,usix))\q2*c]; +impact=G0I*[tmat*q*psi;zeros(nunstab,size(psi,2))]; +fmat=b(usix,usix)\a(usix,usix); +fwt=-b(usix,usix)\q2*psi; +ywt=G0I(:,usix); +%-------------------- above are output for system in terms of z'y ------- +G1=real(z*G1*z'); +C=real(z*C); +impact=real(z*impact); +% Correction 10/28/96: formerly line below had real(z*ywt) on rhs, an error. +ywt=z*ywt; \ No newline at end of file diff --git a/MatlabFiles/gensys_z2.m b/MatlabFiles/gensys_z2.m new file mode 100755 index 0000000..dd53ef8 --- /dev/null +++ b/MatlabFiles/gensys_z2.m @@ -0,0 +1,68 @@ +function [z2,eu2]=gensys_z2(g0,g1,c,psi,gpi,div) +%[z2,eu2]=gensys_z2(g0,g1,c,psi,gpi,div) +% +% z2: n-by-k in general where k is the dimension of gpi or the number of expectational errors. +% System given as +% g0*y(t)=g1*y(t-1)+c+psi*z(t)+gpi*eta(t), +% with z an exogenous variable process and eta being endogenously determined +% one-step-ahead expectational errors. +% Space spanned by z2 is such that z2'*y_t = 0. +% If div is omitted from argument list, a div>1 is calculated. +% +% eu2 = [0, 0] if the rows in Z2 corresponding to the fixed points are zeros (which happens only in the greater-than-2 regime case). +% This value is set outside this function. +% eu2 = [-2,-2] for coincident zeros. +% By Christopher A. Sims +% Corrected 10/28/96 by CAS +eu2=NaN*ones(2,1); +realsmall=1e-6; +fixdiv=(nargin==6); +n=size(g0,1); +[a b q z v]=qz(g0,g1); +if ~fixdiv, div=1.01; end +nunstab=0; +zxz=0; +for i=1:n +% ------------------div calc------------ + if ~fixdiv + if abs(a(i,i)) > 0 + divhat=abs(b(i,i))/abs(a(i,i)); + % bug detected by Vasco Curdia and Daria Finocchiaro, 2/25/2004 A root of + % exactly 1.01 and no root between 1 and 1.02, led to div being stuck at 1.01 + % and the 1.01 root being misclassified as stable. Changing < to <= below fixes this. + if 1+realsmall<divhat & divhat<=div + div=.5*(1+divhat); + end + end + end +% ---------------------------------------- + nunstab=nunstab+(abs(b(i,i))>div*abs(a(i,i))); + if abs(a(i,i))<realsmall & abs(b(i,i))<realsmall + zxz=1; + end +end + +if ~zxz + [a b q z]=qzdiv(div,a,b,q,z); +end +%gev=[diag(a) diag(b)]; +if zxz + disp('Coincident zeros. Indeterminacy and/or nonexistence.') + eu2=[-2;-2]; + % correction added 7/29/2003. Otherwise the failure to set output + % arguments leads to an error message and no output (including eu2). + G1=[];C=[];impact=[];fmat=[];fwt=[];ywt=[];gev=[]; + z2=[]; + return +end +%q1=q(1:n-nunstab,:); +%q2=q(n-nunstab+1:n,:); +%z1=z(:,1:n-nunstab)'; + +%if (nunstab>0) +% z2=z(:,n-nunstab+1:n); +%else +% z2=z(:,n-rank(gpi)+1:n); +%end + +z2=z(:,n-rank(gpi)+1:n); diff --git a/MatlabFiles/gensys_z2new.m b/MatlabFiles/gensys_z2new.m new file mode 100755 index 0000000..c61c5df --- /dev/null +++ b/MatlabFiles/gensys_z2new.m @@ -0,0 +1,74 @@ +function [z2,eu2,div]=gensys_z2new(g0,g1,c,psi,gpi) +%[z2,eu2,div]=gensys_z2new(g0,g1,c,psi,gpi) +% +% z2: n-by-k in general where k is the dimension of gpi or the number of expectational errors. +% System given as +% g0*y(t)=g1*y(t-1)+c+psi*z(t)+gpi*eta(t), +% with z an exogenous variable process and eta being endogenously determined +% one-step-ahead expectational errors. +% Space spanned by z2 is such that z2'*y_t = 0. +% If div is omitted from argument list, a div>1 is calculated. +% +% eu2 = [0, 0] if the rows in Z2 corresponding to the fixed points are zeros (which happens only in the greater-than-2 regime case). +% This value is set outside this function. +% eu2 = [-2,-2] for coincident zeros. +% By Christopher A. Sims +% Corrected 10/28/96 by CAS + +eu2=NaN*ones(2,1); +n2 = size(gpi,2); %number of expectational errors. +realsmall=1e-9; +%fixdiv=(nargin==6); +n=size(g0,1); +[a b q z v]=qz(g0,g1); +%if ~fixdiv, div=1.01; end +%nunstab=0; +zxz=0; +for i=1:n +% ------------------div calc------------ +% if ~fixdiv +% if abs(a(i,i)) > 0 +% divhat=abs(b(i,i))/abs(a(i,i)); +% % bug detected by Vasco Curdia and Daria Finocchiaro, 2/25/2004 A root of +% % exactly 1.01 and no root between 1 and 1.02, led to div being stuck at 1.01 +% % and the 1.01 root being misclassified as stable. Changing < to <= below fixes this. +% if 1+realsmall<divhat & divhat<=div +% div=.5*(1+divhat); +% end +% end +% end +% ---------------------------------------- + %nunstab=nunstab+(abs(b(i,i))>div*abs(a(i,i))); + if abs(a(i,i))<realsmall & abs(b(i,i))<realsmall + zxz=1; + end +end + +gev=[diag(a) diag(b)]; +gevsort = sort(abs(gev(:,1)).\abs(gev(:,2))); +div = (gevsort(end-n2+1) + gevsort(end-n2))/2.0; +if ~zxz + [a b q z]=qzdiv(div,a,b,q,z); +end + + +if zxz + disp('Coincident zeros. Indeterminacy and/or nonexistence.') + eu2=[-2;-2]; + % correction added 7/29/2003. Otherwise the failure to set output + % arguments leads to an error message and no output (including eu2). + G1=[];C=[];impact=[];fmat=[];fwt=[];ywt=[];gev=[]; + z2=[]; + return +end +%q1=q(1:n-nunstab,:); +%q2=q(n-nunstab+1:n,:); +%z1=z(:,1:n-nunstab)'; + +%if (nunstab>0) +% z2=z(:,n-nunstab+1:n); +%else +% z2=z(:,n-n2+1:n); +%end + +z2=z(:,n-n2+1:n); diff --git a/MatlabFiles/gfmean.m b/MatlabFiles/gfmean.m new file mode 100755 index 0000000..ffc7c7a --- /dev/null +++ b/MatlabFiles/gfmean.m @@ -0,0 +1,49 @@ +function [Fmat,gvec] = gfmean(b,P,Vi,nvar,ncoef,n0,np) +% [Fmat,gvec] = gfmean(b,P,Vi,nvar,ncoef,n0,np) +% +% Mean of free lagged parameters g and original lagged parameters F, conditional on comtemporaneous b's +% See Waggoner and Zha's Gibbs sampling +% +% b: sum(n0)-by-1 vector of A0 free parameters +% P: cell(nvar,1). In each cell, posterior linear transformation for random walk prior for the ith equation % tld: tilda +% Vi: nvar-by-1 cell. In each cell, k-by-ri orthonormal basis for the null of the ith +% equation lagged restriction matrix where k is a total of exogenous variables and +% ri is the number of free parameters. With this transformation, we have fi = Vi*gi +% or Vi'*fi = gi where fi is a vector of total original parameters and gi is a +% vector of free parameters. There must be at least one free parameter left for +% the ith equation. +% nvar: number of endogeous variables +% ncoef: number of original lagged variables per equation +% n0: nvar-by-1, ith element represents the number of free A0 parameters in ith equation +% np: nvar-by-1, ith element represents the number of free A+ parameters in ith equation +%--------------- +% Fmat: 0, the value that is used in csminwel.m +% gvec: sum(n0)-by-1 analytical gradient for a0freefun.m +% +% Tao Zha, February 2000 + +b=b(:); + + +n0cum = cumsum(n0); +npcum = cumsum(np); +gvec = zeros(npcum(end),1); +Fmat = zeros(ncoef,nvar); % ncoef: maximum original lagged parameters per equation + +if ~(length(b)==n0cum(end)) + error('Make inputs n0 and length(b) match exactly') +end + +for kj=1:nvar + if kj==1 + bj = b(1:n0(kj)); + gj = P{kj}*bj; + gvec(1:np(kj)) = gj; + Fmat(:,kj) = Vi{kj}*gj; + else + bj = b(n0cum(kj-1)+1:n0cum(kj)); + gj = P{kj}*bj; + gvec(npcum(kj-1)+1:npcum(kj)) = gj; + Fmat(:,kj) = Vi{kj}*gj; + end +end diff --git a/MatlabFiles/gfore.m b/MatlabFiles/gfore.m new file mode 100755 index 0000000..c04d435 --- /dev/null +++ b/MatlabFiles/gfore.m @@ -0,0 +1,86 @@ +function gfore(yrEnd,qmEnd,q_m,yearsCal,yactCalyg,forepy,... + yhatCalygml,xlab,ylab,forelabel,conlab,keyindx,rnum,cnum) +% gfore(yrEnd,qmEnd,q_m,yearsCal,yactCalyg,forepy,... +% yhatCalygml,xlab,ylab,forelabel,conlab,keyindx,rnum,cnum) +% Graph (calendar year) forecasts vs actual (actual from "msstart.m") +% Make sure that actup in "msstart.m" is set at the length for visual graphs +% +% yrEnd: the end year for the sample +% qmEnd: last q_m before out-of-sample forecasting +% q_m: quarterly or monthly for the underlying model +% yearsCal: calendar years including actual and forecast data +% yactCalyg: actual calendar annual growth data +% yhatCalygml: conditional (calendar annual) forecasts on particular shocks +% forepy: forecast periods (yearly) +% xlab: label for structural equations +% ylab: label for the variables +% forelabel: title label for as of time of forecast +% conlab: label for what conditions imposed; e.g., conlab = 'All bar MS shocks inspl' +% keyindx: index for the variables to be graphed +% rnum: number of rows in subplot +% cnum: number of columns in subplot +%------------- +% No output argument for this graph file +% +% October 1998 Tao Zha; revised, 03/17/99 -- May not be compatible with previous programs + + + +%*** Begining period +fbegm = qmEnd+1; % +1 because the first month out of sample +if fbegm > q_m % the first forecast month into the next year + fbegm = 1; + fbegy = yrEnd+1; % the first forecast year for the graph +else + fbegy = yrEnd; % the first forecast year for the graph +end +abegy = min(yearsCal); % the actual beginning year for the graph +abegm = 1; +ifbegy = find(yearsCal==fbegy-1); % index for the year before the first + % forecast first year in actual data "yactCalyg" + +%*** Final period +ffiny = fbegy+forepy-1; % the forecast final year +afiny = max(yearsCal); % the actual final year + + + +figure + +nvar = size(yhatCalygml,2); % Pcm,M2,FFR,GdP, CPI, U +%keyindx = 1:nvar; % Pcm,M2,FFR,GdP, CPI, U +%keyindx = [4:nvar 3 2]; % GdP, CPI, U, FFR, M2 + +hornum = cell(length(abegy:ffiny),1); % horizontal number +count=0; +for k=abegy:ffiny + count=count+1; + jnk=num2str(k); + hornum{count}=jnk(3:4); % e.g., with '1990', we have '90' +end + +count=0; +cnum = 2; +% +for i = keyindx + count = count+1; + subplot(rnum,cnum,count) + % + if abegy>fbegy-1 + plot(abegy:afiny,yactCalyg(:,i),fbegy:ffiny,yhatCalygml(:,i),'-.') + set(gca,'XTick',abegy:ffiny) + else + plot(abegy:afiny,yactCalyg(:,i),... + fbegy-1:ffiny,[yactCalyg(ifbegy,i);yhatCalygml(:,i)],'-.') + set(gca,'XTick',abegy:ffiny) + end + set(gca,'XTickLabel',char(hornum)) + if i<=cnum + title(forelabel) + elseif i>=nvar-1 + xlabel(conlab) + end + % + grid + ylabel(char(ylab(i))) +end diff --git a/MatlabFiles/gforerr1.m b/MatlabFiles/gforerr1.m new file mode 100755 index 0000000..f15a200 --- /dev/null +++ b/MatlabFiles/gforerr1.m @@ -0,0 +1,82 @@ +function gforerr1(yrEnd,qmEnd,q_m,forepy,yhatCalygml,yhatCalygl1,... + yhatCalygh1,xlab,ylab,forelabel,conlab,keyindx,rnum,cnum) + +% +% One (.68) error band: (calendar year) forecasts only (no actual) +% +% yrEnd: the end year for the sample +% qmEnd: last q_m before out-of-sample forecasting +% q_m: quarterly or monthly for the underlying model +% yearsCal: calendar years including actual and forecast data +% yactCalyg: actual calendar annual growth data +% yhatCalygml: conditional (calendar annual) forecasts on particular shocks +% yhatCalygl1: 0.68 lower band +% yhatCalygh1: 0.68 upper band +% forepy: forecast periods (yearly) +% xlab: label for structural equations +% ylab: label for the variables +% forelabel: title label for as of time of forecast +% conlab: label for what conditions imposed; e.g., conlab = 'All bar MS shocks inspl' +% keyindx: index for the variables to be graphed +% rnum: number of rows in subplot +% cnum: number of columns in subplot +%------------- +% No output argument for this graph file +% +% 03/19/99 + + + +%*** Begining period +fbegm = qmEnd+1; % +1 because the first month out of sample +if fbegm > q_m % the first forecast month into the next year + fbegm = 1; + fbegy = yrEnd+1; % the first forecast year for the graph +else + fbegy = yrEnd; % the first forecast year for the graph +end +% +% abegy = min(yearsCal); % the actual beginning year for the graph +% abegm = 1; +% ifbegy = find(yearsCal==fbegy-1); % index for the year before the first +% % forecast first year in actual data "yactCalyg" + +%*** Final period +ffiny = fbegy+forepy-1; % the forecast final year +%afiny = max(yearsCal); % the actual final year + + + +figure + +nvar = size(yhatCalygml,2); % Pcm,M2,FFR,GdP, CPI, U +%keyindx = 1:nvar; % Pcm,M2,FFR,GdP, CPI, U +%keyindx = [4:nvar 3 2]; % GdP, CPI, U, FFR, M2 + +hornum = cell(length(fbegy:ffiny),1); % horizontal number +count=0; +for k=fbegy:ffiny + count=count+1; + jnk=num2str(k); + hornum{count}=jnk(3:4); % e.g., with '1990', we have '90' +end + +count=0; +% +for i = keyindx + count = count+1; + subplot(rnum,cnum,count) + % + plot(fbegy:ffiny,yhatCalygml(:,i),'-',... + fbegy:ffiny,yhatCalygl1(:,i),'--',fbegy:ffiny,yhatCalygh1(:,i),'--' ) + set(gca,'XTick',fbegy:ffiny) + set(gca,'XTickLabel',char(hornum)) + if i<=cnum + title(forelabel) + elseif i>=nvar-1 + xlabel(conlab) + end + % + grid + ylabel(char(ylab(i))) +end \ No newline at end of file diff --git a/MatlabFiles/ghistd.m b/MatlabFiles/ghistd.m new file mode 100755 index 0000000..6f03aac --- /dev/null +++ b/MatlabFiles/ghistd.m @@ -0,0 +1,77 @@ +function noargout = ghistd(qmEnd,yrEnd,forepy,q_m,HDv,lendlab,titlab,ylab,timelab,rnum,cnum) +% +% Plot historical decompositions (annually at this time), no argument out +% +% qmEnd: the end month before the forecast +% yrEnd: the end year before the forecast +% forepy: the number of forecast calendar years +% q_m: 12 or 4 (monthly or quarterly) +% HDv: nHD-by-1 cell where nHD is number of decompositions; +% each cell is forepy-by-nvar +% lendlab: label for the lengend +% titlab: label for the title +% ylab: label for the variables +% timelab: label for the time of forecast and indication of insample or out-of-sample +% rnum: row number for the subplot (e.g., 3) +% cnum: column number for the subplot (e.g., 2) +%--------------- +% no argument out +% +% October 1998 Tao Zha +% +% To be done: +% lengend does not work well +% colormap should be replaced by some non-color shading +% title: need to have only one. + +fbegm = qmEnd+1; % +1 because the first month out of sample +if fbegm > q_m % the first forecast month into the next year + fbegm = 1; % reset + fbegy = yrEnd+1; % the first forecast year for the graph +else + fbegy = yrEnd; % the first forecast year for the graph +end +ffiny = fbegy+forepy-1; % the forecast final year + +figure +%cnum = 2; +nvar = size(HDv{1},2); +rnum = nvar/cnum; +if ~(rnum==fix(rnum)) + warning('Make that subplot is divided properly') + disp('Check rnum as well as cnum') + return +end + +hornum = cell(length(fbegy:ffiny),1); % horizontal number +count=0; +for k=fbegy:ffiny + count=count+1; + jnk=num2str(k); + hornum{count}=jnk(3:4); % e.g., with '1990', we have '90' +end + + +for k=1:nvar + bardata = []; + for n=1:size(HDv,1) + bardata = [bardata HDv{n}(:,k)]; + end + + subplot(rnum,cnum,k) + bar(fbegy:ffiny,bardata,0.75,'group') + set(gca,'XTickLabel',char(hornum)) + if k==1 + legend(char(lendlab),1) + end + colormatrix = [0.2 0.2 0.2;0.8 0.8 0.8]; + colormap(colormatrix) + if k<=cnum + title(char(titlab)) + end + if k>((rnum-1)*cnum) + xlabel(timelab) + end + grid + ylabel(char(ylab{k})) +end \ No newline at end of file diff --git a/MatlabFiles/gradcd.m1 b/MatlabFiles/gradcd.m1 new file mode 100755 index 0000000..dc07b4a --- /dev/null +++ b/MatlabFiles/gradcd.m1 @@ -0,0 +1,53 @@ +function grdd = gradcd(fcn,x0,grdh) +% computes numerical gradient of a single-valued function or Jacobian +% matrix of a vector-valued function using a central difference with +% function grdd = gradcd(fcn,x0,grdh) +% +% fcn: a string naming a vector-valued function (f:n*1 -> k*1). +% x0: a column vector n*1, at which point the hessian is evaluated. +% grdh: step size, n*1. +% grdd: Jacobian matrix, k*n. + +stps = eps^(1/3); +% eps: floating point relative accuracy or machine precision: 2.22e-16 +% stps: step size recommended by Dennis and Schnabel: 6.006e-6 + +% ** initializations +n = size(x0,1); +k = size(feval(fcn,x0),1); % dimension of "fcn" + +% ** Computation of stepsize (dh) +if all(grdh) + dh = grdh; +else + ax0 = abs(x0); + if all(x0) + dax0 = x0 ./ ax0; + else + dax0 = 1; + end + dh = stps * (max([ax0 ones(n,1)]'))' .* dax0; +end + +xdh = x0 + dh; +dh = xdh - x0; % This increases precision slightly +% +argplus = x0(:,ones(n,1)); +dnum = 1:n+1:n^2; % positions of diagonals in vec(argplus). +argplus(dnum) = xdh; % replace the diagonals of "argplus" by "xdh". +% +argminus = x0(:,ones(n,1)); +argminus(dnum) = x0-dh; % replace the diagonals of "argplus" by "xdh". + +grdd = zeros(k,n); % preallocate to speed the loop. +i = 0; +while i ~= n + i = i+1; + grdd(:,i) = feval(fcn,argplus(:,i)) - feval(fcn,argminus(:,i)); +end +dhm = dh(:,ones(k,1)); +dhm = dhm'; % k*n +grdd = grdd ./ (2*dhm); + + + \ No newline at end of file diff --git a/MatlabFiles/gshock.m b/MatlabFiles/gshock.m new file mode 100755 index 0000000..abcd3af --- /dev/null +++ b/MatlabFiles/gshock.m @@ -0,0 +1,71 @@ +function ExactSmyear = gshock(begy,begm,finy,finm,xlab,idfile,tlinput) +% ExactSmyear = gshock(begy,begm,finy,finm,xlab) +% Plot the structural shocks for the range given by the inputs +% +% begy: the beginning year for the graph +% begm: the begiining month for the graph +% finy: the end year for the graph +% finm: the end month for the graph +% xlab: label for each structural equation +%----------- +% ExactSmyear: time (myears) and all structural shocks +% if no nargout, plot graphics. +% +% October 1998 by Tao A. Zha + + + +eval(['load ' idfile '.mat']); + +% +ibegy = find(myears==begy); +ifiny = find(myears==finy); + +ibegy1 = find(myears==begy+1); + +% +if isempty(ibegy) & isempty(ibegy1) + warning('Either ibegy or begm is out of the range of myears') + disp('Print myears to see the range') + disp('Or change actuap to make the range longer and save new results to Xshock.mat') + pause +elseif isempty(ibegy) & (begm<myears(1)) + warning('Either ibegy or begm is out of the range of myears') + disp('Print myears to see the range') + disp('Or change actuap to make the range longer and save new results to Xshock.mat') + pause +elseif isempty(ibegy) + ibegy = -myears(1)+2; % +2 is needed for the following -1 in + % bar(Estrexa(ibegy+begm-1:ifiny+finm-1,i)) + %so that it 2-1=1 so that +1 is what we want +end + +% +if isempty(ifiny) + warning('Either ifiny or finm is out of the range of myears') + disp('Print myears to see the range') + disp('Or change actuap to make the range longer and save new results to Xshock.mat') + pause +elseif (ifiny+finm-1>size(myears,1)) + warning('Either ifiny or finm is out of the range of myears') + disp('Print myears to see the range') + disp('Or change actuap to make the range longer and save new results to Xshock.mat') + pause +end + + +if nargout==0 + t=length(Estrexa(ibegy+begm-1:ifiny+finm-1,1)); + for i=1:size(Estrexa,2) + figure + %plot(1:t, Estrexa(ibegy+begm-1:ifiny+finm-1,i)); + bar(Estrexa(ibegy+begm-1:ifiny+finm-1,i)) + title([ tlinput ' Monthly Structural Shocks' ]) + ylabel(char(xlab(i))) + xlabel([ 'From ' num2str(begy) ':' num2str(begm) ' to ' ... + num2str(finy) ':' num2str(finm) ]) + grid + end +else + ExactSmyear = [myears(ibegy+begm-1:ifiny+finm-1) Estrexa(ibegy+begm-1:ifiny+finm-1,:)]; +end diff --git a/MatlabFiles/gstate.m b/MatlabFiles/gstate.m new file mode 100755 index 0000000..3a0aaea --- /dev/null +++ b/MatlabFiles/gstate.m @@ -0,0 +1,96 @@ +function [GS,pickn,ok,uis,uiu,vs]=gstate(G1,impact,pick) +%function [GS,pickn,ok,uis,vs]=gstate(G1,impact,pick) +% G1: the coefficient on lagged y from the output of gensys.m. +% impact:the coefficient on exogenous shocks from the output of gensys.m +% pick: an optional guess at a matrix of coefficients that extracts +% the state vector from y +% ok: 0 if pick matrix is just no good. +% 1 if pick matrix is usable forward, but loses initial date information +% 2 if pick matrix is not usable forward, is part of a correct state vector, but is not complete +% 3 if pick matrix is usable forward, is part of a correct state vector, but is not complete +% 4 if pick matrix is not usable forward, summarizes past, but is redundant +% 5 if pick matrix is usable forward, summarizes past, but is redundant +% 6 if pick matrix summarizes past and is not redundant, but is not usable forward +% 7 if pick matrix is perfect, both forward and as history summary +% pickn: a matrix of coefficients that extracts the state vector from y. Equal +% to pick if pick is supplied and ok=1; otherwise, an ok-maximizing pick matrix that +% is somewhat similar to pick. +% GS: the matrix of coefficients on the lagged state variable +% uis,vs: If uis'*vs is square and full rank, ok=7 is possible, otherwise not. If ok<2, an ok>2 can be found by trying +% a pick in the row space of vs'. Any pick with pick*uis full column rank will provide a foward state +% (i.e. ok an odd number). +% uiu: uiu'y(t)=0, and this is interpretable as the decision rule setting controls as functions of the states. +% The solution was in the form y(t)=G1*y(t-1)+impact*z(t). Now it's in the form y(t)=GS*pickn*y(t-1)+impact*z(t). +% In general, pickn is mxn with m<n. +REALSMALL=1e-9; +[nr,nc]=size(G1); +%if nr<nc +% G1=[G1;zeros(nc-nr,nc)]; +%end +[u d v]=svd(G1); +top=find(diag(d)>REALSMALL); +nd=top(end); +us=u(:,top); +uu=u(:,top+1:end); +d=d(top,top); +vs=v(:,top); +if nargin<=2 + pick=vs'; + vp=v; + vps=vs; + dp=eye(nd); + ups=eye(nr,nd); + ndp=nd; +else + [up dp vp]=svd(pick); + topp=find(diag(dp)>REALSMALL); + ndp=topp(end); + vps=vp(:,topp); + dp=dp(topp,topp); + ups=up(:,topp); +end + % If we were worried about efficiency, we'd skip some of this when pick=vs. + %Does pick summarize history? (pick in v' row space, v in vp' row space). + pinv=all(all((pick'-vs*vs'*pick').^2<REALSMALL)); + vinp=all(all((vs-vps*vps'*vs).^2<REALSMALL)); + okpast=pinv+vinp; + % Does pick summarize all current info? (impact in us column space, pick*uu full rank) + [ui,di,vi]=svd([impact us]); + topi=find(diag(di)>REALSMALL); + ndi=length(topi); + uis=ui(:,topi); + uiu=ui(:,ndi+1:size(ui,2)); + if ndi<size(G1,1) + if(size(pick,1)<size(uis,2)) + oknow=0; + else + [ut,dt,vt]=svd(pick*uis); + toppu=find(diag(dt)>REALSMALL); + if length(toppu)<size(us,2) + oknow=0; + else + oknow=1; + end + end + else + oknow=0; + end + if vinp + GS=G1/pick; + pickn=pick; + elseif pinv + r=vs-vps*vps'*vs; + [ur,dr,vr]=svd(r); + topr=find(dr>REALSMALL); + p2=ur(:,topr); + pickn=[pick;p2']; + GS=G1/pickn; + elseif oknow + GS=G1/[pick;uiu']; + GS=GS(:,1:size(pick,1)); + pickn=pick; + else + pickn=vs'; + GS=us*d; + end +ok=oknow+2*pinv+4*vinp; diff --git a/MatlabFiles/gyrfore.m b/MatlabFiles/gyrfore.m new file mode 100755 index 0000000..a175804 --- /dev/null +++ b/MatlabFiles/gyrfore.m @@ -0,0 +1,44 @@ +function gyrfore(yfore,yacte,keyindx,rnum,cnum,ylab,forelabel,conlab) +% +% Graph annual (or calendar year) forecasts vs actual (all data from "msstart.m") +% +% yfore: actual and forecast annual growth data with dates. +% yacte: actual annual growth data with dates. +% keyindx: index for the variables to be graphed +% rnum: number of rows in subplot +% cnum: number of columns in subplot +% ylab: label for the variables +% forelabel: title label for as of time of forecast +% conlab: label for what conditions imposed; e.g., conlab = 'All bar MS shocks inspl' +%------------- +% No output argument for this graph file +% +% Tao Zha, March 2000 + + +vyrs = yfore(:,1); +hornum = cell(length(vyrs),1); % horizontal year (number) +count=0; +for k=vyrs' + count=count+1; + jnk=num2str(k); + hornum{count}=jnk(3:4); % e.g., with '1990', we have '90' +end + +count=0; +for i = keyindx + count = count+1; + subplot(rnum,cnum,count) + % + plot(yacte(:,1),yacte(:,2+i),vyrs,yfore(:,2+i),'--') + set(gca,'XTick',vyrs) + set(gca,'XTickLabel',char(hornum)) + if i==keyindx(1) + title(forelabel) + elseif i>=length(keyindx)-1 + xlabel(conlab) + end + % + grid + ylabel(char(ylab(i))) +end diff --git a/MatlabFiles/hist2.m b/MatlabFiles/hist2.m new file mode 100755 index 0000000..1ad9471 --- /dev/null +++ b/MatlabFiles/hist2.m @@ -0,0 +1,68 @@ +function [no,xo,binwidth] = hist2(y,x) +%HIST2 Histogram. +% N = HIST2(Y) bins the elements of Y into 10 equally spaced containers +% and returns the number of elements in each container. If Y is a +% matrix, HIST2 works down the columns. +% +% N = HIST2(Y,M), where M is a scalar, uses M bins. +% +% N = HIST2(Y,X), where X is a vector, returns the distribution of Y +% among bins with centers specified by X. +% +% [N,X] = HIST2(...) also returns the position of the bin centers in X. +% +% [N,X,BW] = HIST2(...) also returns the position of the bin centers in X and the width of the bin. +% +% HIST2(...) without output arguments produces a histogram bar plot of +% the results. + +% J.N. Little 2-06-86 +% Revised 10-29-87, 12-29-88 LS +% Revised 8-13-91 by cmt, 2-3-92 by ls. +% Copyright (c) 1984-97 by The MathWorks, Inc. +% $Revision: 5.10 $ $Date: 1997/04/08 05:22:50 $ + +if nargin == 0 + error('Requires one or two input arguments.') +end +if nargin == 1 + x = 10; +end +if min(size(y))==1, y = y(:); end +if isstr(x) | isstr(y) + error('Input arguments must be numeric.') +end +[m,n] = size(y); +if length(x) == 1 + miny = min(min(y)); + maxy = max(max(y)); + binwidth = (maxy - miny) ./ x; + xx = miny + binwidth*(0:x); + xx(length(xx)) = maxy; + x = xx(1:length(xx)-1) + binwidth/2; +else + xx = x(:)'; + miny = min(min(y)); + maxy = max(max(y)); + binwidth = [diff(xx) 0]; + xx = [xx(1)-binwidth(1)/2 xx+binwidth/2]; + xx(1) = miny; + xx(length(xx)) = maxy; +end +nbin = length(xx); +nn = zeros(nbin,n); +for i=2:nbin + nn(i,:) = sum(y <= xx(i)); +end +nn = nn(2:nbin,:) - nn(1:nbin-1,:); +if nargout == 0 + bar(x,nn,'hist'); +else + if min(size(y))==1, % Return row vectors if possible. + no = nn'; + xo = x; + else + no = nn; + xo = x'; + end +end \ No newline at end of file diff --git a/MatlabFiles/history2.m b/MatlabFiles/history2.m new file mode 100755 index 0000000..acf86fb --- /dev/null +++ b/MatlabFiles/history2.m @@ -0,0 +1,144 @@ +function [HDratio,HDvalue,yhatn,yforen] = history2(HDindx,A0,Bhml,phil,nn,... + actup,Estrexa,xdata,nvar,nSample,nSampleCal,forep,forepq,forepy,q_m,... + qmEnd,vlist,vlistlog,vlistper,lmqyIndx) +% [HDratio,HDvalue,yhatn,yforen] = history2(HDindx,A0,Bhml,phil,nn,actup,... +% xdata,nvar,nSample,nSampleCal,forep,forepq,forepy,q_m,... +% qmEnd,vlist,vlistlog,vlistper,lmqyIndx) +% +% (Out-of-sample) historical decompostions: alternative approach to history.m in 3 aspects +% (1) compute the percentage (not the value itself) +% (2) NOT cumulative HD (THIS is NOT correct, TAZ, 03/17/99) +% (3) conditional on time t (not time 0). +% (4) condtional and uncondtional forecasts +% +% HDindx: k-by-1 cell where k groups of shocks; index number for particular shocks +% A0h: nvar-by-nvar for y(t)A0 = X*A+ + E, where column means equation +% Bh: the (posterior) estimate of B for y(t) = X*Bh + E*inv(A0) +% phil: the 1-by-(nvar*lags+1) data matrix where k=nvar*lags+1 +% (last period plus lags before the beginning of forecast) +% nn: [nvar,lags,forep], forep: forecast periods (monthly) +% actup: actual data periods (monthly) before the beginning of forecasts +% xdata: oringal data set, up to the period before (peudo-) out-of-sample forecasting, +% all logged except R, U, etc. +% Estrexa: forep-by-nvar -- backed out structural shocks for out-of-sample forecast +% nvar: number of variables +% nSample: sample size (including lags or initial periods) +% nSampleCal: sample size in terms of calendar years +% forep: forecast periods (monthly) +% forepq: forecast periods (quarterly) +% forepy: forecast periods (yearly) +% q_m: quarterly or monthly for the underlying model +% qmEnd: last q_m before out-of-sample forecasting +% vlist: a list of variables +% vlistlog: sub list of variables that are in log +% vlistper: sub list of variables that are in percent +% lmyqIndx: 4-by-1 1 or 0's. Index for m log, m level, qg, and yg; 1: yes; 0: no; +% if lmyqIndx(1)==1, both monthly log and monthly level are returned +%-------------- +% HDratio: 5-by-k cells, where k groups (see HDindx) of shocks associated with decomposition; +% 5: monthly log, monthly level, mg, qg, and calendar yg in this order; +% each cell is forep(q)(y)-by-nvar +% HDvalue: same dimension as HDratio but with the values (differences between +% conditional and unconditional forecasts +% yhatn: same dimension as HDratio but with conditional forecasts +% yforen: 5-by-1 cells and each cell is forep(q)(y)-by-nvar unconditional forecasts +% +% October 1998 by Tao Zha. +% Last change 3/19/99 on the dimension of "Estrexa" so that previous programs may not be +% compatible. + +nyout = 1+nargout('fore_cal'); + % +1 because we want the original logged variables as well. +[nHD,jnk] = size(HDindx); +yhat=cell(nHD,1); +yhatn = cell(nyout,nHD); + % row: output such as l, mg, qg, or yg; column: how many decomps + + + +%-------------------------------------------------------------------------- +% Unconditional point forecasts for log, monthly levle, mg, qg, and yg. +%-------------------------------------------------------------------------- +yforeml = forecast(Bhml,phil,nn); +yforen = cell(nyout,1); +yforen{1} = yforeml; +oputstr = '['; % output string +for n=2:nyout + if n<nyout + oputstr = [oputstr 'yforen{' num2str(n) '},']; + else + oputstr = [oputstr 'yforen{' num2str(n) '}']; + end +end +oputstr =[oputstr ']']; +% +eval([oputstr ' = fore_cal(yforeml,xdata,nvar,nSample,nSampleCal,forep,'... + 'forepq,forepy,q_m,qmEnd,vlist,vlistlog,vlistper,lmqyIndx);']); + + + +%-------------------------------------------------------------------------- +% Conditional forecasts on specified paths of shocks +% for log, monthly levle, mg, qg, and yg. +%-------------------------------------------------------------------------- +for k=1:nHD + Estr = zeros(forep,nvar); % out of sample + Estr(:,HDindx{k}) = Estrexa(:,HDindx{k}); % out of sample, MS + yhat{k} = forefixe(A0,Bhml,phil,nn,Estr); + yhatn{1,k} = yhat{k}; % original logged variables + % + oputstr = '['; % output string + for n=2:nyout + if n<nyout + oputstr = [oputstr 'yhatn{' num2str(n) ',k},']; + else + oputstr = [oputstr 'yhatn{' num2str(n) ',k}']; + end + end + oputstr =[oputstr ']']; + % + eval([oputstr ' = fore_cal(yhat{k},xdata,nvar,nSample,nSampleCal,forep,'... + 'forepq,forepy,q_m,qmEnd,vlist,vlistlog,vlistper,lmqyIndx);']); +end + + + +%-------------------------------------------------------------------------- +% Historical decompositions: both values and raitos (%) +%-------------------------------------------------------------------------- +HDratio=cell(nyout,nHD); +HDvalue=HDratio; +for n=2:nyout + if lmqyIndx(n-1) + if (n-1==1) + yhatotal = zeros(size(yhatn{1,k})); + for k=1:nHD + HDvalue{1,k} = yhatn{1,k}-yforen{1}; + yhatotal = yhatotal + abs(HDvalue{1,k}); + % a sum of absolute values. One can also use square + end + % + for k=1:nHD + HDratio{1,k} = abs(HDvalue{1,k})*100 ./ yhatotal; + end + end + % + yhatotal = zeros(size(yhatn{n,k})); + for k=1:nHD + HDvalue{n,k} = yhatn{n,k}-yforen{n}; + yhatotal = yhatotal + abs(HDvalue{n,k}); + % a sum of absolute values. One can also use square + end + % + for k=1:nHD + HDratio{n,k} = abs(HDvalue{n,k})*100 ./ yhatotal; + end + end +end + + +%** check. This first may not be zeros, but the second (monthly log) must be zeros. +%HDvalue{5,1}+HDvalue{5,2}-... +% (yactCalyg(size(yactCalyg,1)-3:size(yactCalyg,1),:)-yforeCalygml) +%HDvalue{1,1}+HDvalue{1,2}-... +% (yact(size(yact,1)-forep+1:size(yact,1),:)-yforen{1,1}) \ No newline at end of file diff --git a/MatlabFiles/histpdfcnt.m b/MatlabFiles/histpdfcnt.m new file mode 100755 index 0000000..623a349 --- /dev/null +++ b/MatlabFiles/histpdfcnt.m @@ -0,0 +1,118 @@ +function [imfpdf,imfpo,imfprob] = histpdfcnt(imfcnt,ndrawscnt,forep,shockp,nvar,ninv,invc,Am,... + ixdeng,findex,sindex,vindex,idxuniscl,lval,hval,ncom,gIndx) +% [imfpdf,imfpo,imfprob] = histpdfcnt(imfcnt,ndrawscnt,forep,shockp,nvar,ninv,invc,Am,... +% ixdeng,findex,sindex,vindex,idxuniscl,lval,hval,ncom,gIndx) +% From already ordered and binned (cnt: count) series (not pdf yet). +% Produce (1) the dataset for generating p.d.f., (2) the dataset for +% probability (NOT density) at each bin, (3) with option ixdeng=1, +% graphs of density functions +% +% imfcnt: 2+ninv-by-forep*shockp*nvar. Counted logcnt, yhatqgcnt, or yhatCalygcnt. +% In the case of impulse responses, forep=imstp and shockp=nvar. +% In case of of A0(Avhx), forep=1, shockp=1, nvar=nfp +% In case of forecasts, shockp=1 +% ndrawscnt: a total number of draws used in imfcnt +% forep: forecast periods -- 1st dim (must be compatible with findex) +% shockp: number of shocks -- 2nd dim (must be compatible with sindex) +% nvar: number of responses (variables) -- 3rd dim (must be compatible with vindex) +% ninv: the number of small interior intervals for sorting. +% invc: 1-by-forep*shockp*nvar. Whole inverval lenghth from min to max for one of +% (yhat, yhatqg, or yhatCalyg) +% Am: 1-by-forep*shockp*nvar. Range5{i}(:,:,1) is lowest range for for one of +% (yhat, yhatqg, or yhatCalyg) +% ixdeng: index for density graphs. 1: enable; 0: disenable +% findex: index for selected forecast periods, 1st dim (c.f., forep) +% sindex: index for selected shocks, 2nd dim (c.f., shockp) +% vindex: variable index, 3rd dim (c.f., nvar) +% idxuniscl: 1: scale on each graph by using lval and hval; 0: disenable this +% lval: (length(findex),length(sindex),length(vindex)); lowest point on the axis; +% The number matches a total of findex, sindex, and vindex +% hval: (length(findex),length(sindex),length(vindex)); highest point on the axis; +% The number matches a total of findex, sindex, and vindex +% ncom: number of combined intervals. Large ncom implies large size of the bin. +% Must set ncom so that ninv can be divided +% gIndx: 1: plot graphs of pdf's; 0: no plot +%----------------- +% imfpdf: 2+ninv-by-forep*shockp*nvar. Density +% imfpo: 2+ninv-by-forep*shockp*nvar. Bin position (x-axis) in relation to imfs3 +% imfprob: 2+ninv-by-forep*shockp*nvar. Probability (NOT density) at each bin +% +% 27 August 1998 Tao Zha +% Revised, October 1998, March 1999 +% 3/24/99, added gIndx so that the previous programs may not be compatible. + +invlength = invc ./ ninv; +invlengthM = repmat(invlength,[2+ninv,1]); +invlengthM([1 2+ninv],:) = 1; + % first (-inf, low bound) and last (high bound, +inf), the interval is set + % to be 1. Of course, theoretically, the interval length should be set + % to infinity, but 1 is large enough compared with invlength. +imfprob = imfcnt ./ ndrawscnt; % probability (NOT density) +imfpdf = imfprob ./ invlengthM; % density + +imfpo = [1:2+ninv]'; % positions for each forecast +imfpo = imfpo - 2; % the first step to put back to original form +imfpo = repmat(imfpo,[1,forep*shockp*nvar]); +invcM = repmat(invc,[2+ninv,1]); +AmM = repmat(Am,[2+ninv,1]); +imfpo = ((imfpo .* invcM) ./ ninv) + AmM; % 2+ninv-by-forep*shockp*nvar + % the final step to put back to original form of impulse responses + + +if mod(ninv,ncom) + warning('Set ncom so that ninv can be divided') + return +end +% +ninv2=ninv/ncom; +imfpdfn=zeros(2+ninv2,forep*shockp*nvar); %<<>> +imfpon=imfpdfn; +% +for ik=1:ninv2 % from 2 to 1+ninv2 for imfpdfn and imfpon + imfpdfn(1+ik,:) = sum(imfpdf(1+(ik-1)*ncom+1:1+ik*ncom,:))/ncom; + imfpon(1+ik,:) = mean(imfpo(1+(ik-1)*ncom+1:1+ik*ncom,:)); +end + +imfpdf4 = reshape(imfpdfn,2+ninv2,forep,nvar,shockp); +% imfpdf3: row--bin numbers, column--steps, 3rd dim--variables(responses), 4rd dime--shocks +imfpdf4s = permute(imfpdf4,[1 2 4 3]); + % imf3pdfs: permuted so that + % row--bin numbers, column--steps, 3rd dim--shocks, 4rd dime--variables (responses) +imfpo4 = reshape(imfpon,2+ninv2,forep,nvar,shockp); +imfpo4s = permute(imfpo4,[1 2 4 3]); + + +if gIndx + ck1=0; + for k1=findex + ck1=ck1+1; + ck2=0; + for k2=sindex + ck2=ck2+1; + ck3=0; + for k3=vindex + ck3=ck3+1; + %figure + if idxuniscl + lpos = min(find(imfpo4s(2:1+ninv2,k1,k2,k3)>lval(ck1,ck2,ck3))); % low position + hpos = max(find(imfpo4s(2:1+ninv2,k1,k2,k3)<hval(ck1,ck2,ck3))); % high position + plot(imfpo4s(lpos+1:hpos+1,k1,k2,k3),imfpdf4s(lpos+1:hpos+1,k1,k2,k3)) % + % push everything forward by 1 because lpos and hpos start at 2 + set(gca,'XLim',[lval(ck1,ck2,ck3) hval(ck1,ck2,ck3)]) + grid + else + plot(imfpo4s(2:1+ninv2,k1,k2,k3),imfpdf4s(2:1+ninv2,k1,k2,k3)) % + grid + end + end + end + end +end + +%xlabel('The 1984 U Forecast') %The 1982 GDP Growth Forecast') +%set(gca,'XLim',[lval hval]) +%xact = [7.508 7.508]; %[-2.13 -2.13]; +%yact = [0 0.5]; %[0 0.5]; +%set(line(xact,yact),'Linestyle','-') +%title('Figure 8') +%line([-2 -2],[0 400]) \ No newline at end of file diff --git a/MatlabFiles/histpdfg.m b/MatlabFiles/histpdfg.m new file mode 100755 index 0000000..3148f43 --- /dev/null +++ b/MatlabFiles/histpdfg.m @@ -0,0 +1,32 @@ +function [n,z] = histpdfg(seqdraws,binnum,titstr,xlabstr,ylabstr) +% [n,z] = histpdfg(seqdraws,binnum,titstr,xlabstr,ylabstr) +% Plot (if no nargout) and export (if nargout) pdf by scaling histogram +% of an unsorted sequence of draws +% +% seqdraws: an unordered sequence of draws +% binnum: the total number of bins in histogram, with 10 being a starting value +% titstr: title string; if [], no title +% xlabstr: xlabel string; if [], no xlab +% ylabstr: ylabel string; if [], no ylab +%-------- +% n: a vector of the number of elements in each bin or container +% z: a vector of the position of the center of the bin +% plot p.d.f. graph if no nargout +% +% October 1998 Tao Zha + +if (nargin==2), titstr=[]; xlabstr=[]; ylabstr=[]; end + +[n,z,bw]=hist2(seqdraws,binnum); +n=(n/length(seqdraws))/bw; % make it p.d.f. +%bar(z,n) +if nargout + z=z'; + n=n'; +else + %figure + plot(z,n) + title(titstr) + xlabel(xlabstr) + ylabel(ylabstr) +end diff --git a/MatlabFiles/histpdfg2D.m b/MatlabFiles/histpdfg2D.m new file mode 100755 index 0000000..d9dab9e --- /dev/null +++ b/MatlabFiles/histpdfg2D.m @@ -0,0 +1,108 @@ +function [xc,yc,z,zn] = histpdfg2D(w,n,ditp,xlabstr,ylabstr) +% histpdfg2D(w,n,ditp,xlabstr,ylabstr) +% Given 2D draws, generate 2D pdf by scaling 2D histogram +% +% w: ndraws-by-2 matrix where ndraws is # of draws and 2 variables +% n: 1-by-2 vector -- # of bins (integers in general) for both x-axis and y-axis +% ditp: number -- degrees of bicubic interpolation +% xlabstr: xlabel string; if [], no xlab +% ylabstr: ylabel string; if [], no ylab +%--------------------------------- +% xc: the position of centered bin on x-axis, from left to right. All rows are identical +% yc: the position of centered bin on y-axis, from top to bottom. All columns are identical +% z: size(xc,2)-by-size(yc,1) -- the pdf value in each rectangular cell +% zn: size(xc,2)-by-size(yc,1) -- the probability value in each rectangular cell +% if nargout==0, plot 2D p.d.f. graphics +% +% January 1999 by Tao Zha + +if (size(w,2)~=2) + error('The size of 1st argument must be *-by-2 (i.e., 2 columns)') +end + +if (nargin==3), xlabstr=[]; ylabstr=[]; end + +if (length(n(:))~=2) + error('2nd argument must have exactly 2 elements') +end + +if (min(n)<3) + error('2nd argument -- bin size -- must have at least 3 for each axis') +end + +ndraws=size(w,1); + +%*** x-axis +minx = min(min(w(:,1))); +maxx = max(max(w(:,1))); +h1 = (maxx-minx)/n(1); % binwidth for x-axis +x = minx + h1*(0:n(1)); +xlen = length(x); % n(1)+1 +x(xlen) = maxx; % in case n(1) is not an integer +xc = x(1:xlen-1) + h1/2; % the position of the center of the x-bin + % 1-by-n(1) row vector: from left to right +xc = repmat(xc,[n(2) 1]); + +%*** y-axis +miny = min(min(w(:,2))); +maxy = max(max(w(:,2))); +h2 = (maxy-miny)/n(2); % binwidth for y-axis +y = miny + h2*(0:n(2)); +ylen = length(y); +y(ylen) = maxy; % in case n(2) is not an integer +yc = y(1:ylen-1) + h2/2; % the position of the center of the y-bin +yc = yc(:); % n(2)-by-1 column vector: from top to bottom +yc = repmat(yc,[1 n(1)]); + + +zn = zeros(n(2),n(1)); % the reverse of x and y is designed for mesh. + % see meshgrid to understand this. +tic +for draws=1:ndraws + k1 = floor((w(draws,1)-minx)/h1)+1; + k2 = floor((w(draws,2)-miny)/h2)+1; + % + % if k1==0 + % k1=1; + % end + % if k2==0; + % k2=1; + % end + % + if k1>n(1) + k1=n(1); + end + if k2>n(2) + k2=n(2) + end + zn(k2,k1) = zn(k2,k1)+1; +end +timeloop=toc; +disp(['Loop time -- minutes ' num2str(timeloop/60)]) + +zn = zn/ndraws; % probability in each rectangular cell + +z=zn/(h1*h2); % converted to the height of the p.d.f. + + +%*** scaled 2D histogram or p.d.f. +if (nargout==0) + %figure(1) + colormap(zeros(1,3)); % set color to black + mesh(xc,yc,z) + title('Scaled histogram or p.d.f.') + xlabel(xlabstr) + ylabel(ylabstr) +end + +%*** interpolation +if (ditp & nargout==0) + [xi,yi]=meshgrid(minx:h1/ditp:maxx,miny:h2/ditp:maxy); + zi = interp2(xc,yc,z,xi,yi,'bicubic'); + figure(30) + colormap(zeros(1,3)); % set color to black + mesh(xi,yi,zi) + title('Interpolated p.d.f.') + xlabel(xlabstr) + ylabel(ylabstr) +end \ No newline at end of file diff --git a/MatlabFiles/histwpdfg.m b/MatlabFiles/histwpdfg.m new file mode 100755 index 0000000..bc218bb --- /dev/null +++ b/MatlabFiles/histwpdfg.m @@ -0,0 +1,62 @@ +function [xp,xpd,xc,w,bw] = histwpdfg(s,nbin,gIdx,w,xlabstr,ylabstr,titstr) +% [xp,xpd,xc,w,bw] = histwpdfg(s,nbin,gIdx,w,xlabstr,ylabstr,titstr) +% Generate probabilities and plot scaled densitys, given the unsorted draws and weights +% +% s: ndraws-by-n draws where ndraws is # of draws and n is # of series +% nbin: the number of bins (the maximum is ndraws) +% gIdx: 1 if plotting the pdf; 0 if no graph +% w (optional): ndraws-by-n (unscaled) weights where ndraws is # of draws and n is # of series +% xlabstr (optional): xlabel string +% ylabstr (optional): ylabel string +% titstr (optional): title string +%------------- +% xp: nbin-by-n: probability (not density) in the centered bin on x-axis. +% NOTE: sum(xp) must be 1 for each column +% xpd: nbin-by-n: density (not probability) in the centered bin on x-axis. +% xc: nbin-by-n: the position of centered bin on x-axis, from top to bottom. +% All columns are identical +% w: ndraws-by-n scaled weights so that sum(w)=1 for each column +% bw: bandwidth +% +% August 1999 by Tao Zha +% July 18 2000. Place w after gIdx so that previous programs need modifications accordingly. + +if (nargin<=4), titstr=[]; xlabstr=[]; ylabstr=[]; end +[m,n] = size(s); +if (nargin<=3) + w=ones(m,n)/m; +else + %** normalized to 1 for the probability + wsum = repmat(sum(w), [m 1]); + w = w ./ wsum; +end + +%if min(size(s))==1, s=s(:); w=w(:); end % making sure they are column vectors + +%*** the position of the center of the bin on the x-axis +mins = min(min(s)); +maxs = max(max(s)); +bw = (maxs-mins)/nbin; % binwidth for x-axis +x = mins + bw*(0:nbin); +x(end) = maxs; % in case nbin is not an integer +xc = x(1:end-1) + bw/2; % the position of the center of the x-bin +xc = xc'; % nbin-by-1 row vector: from top to bottom +xc = repmat(xc,[1 n]); % nbin-by-n, same for each column + + +%*** the probability at each bin on the x-axis +nbin = nbin+1; % + 1 to get the difference for getting probability xp +nn = zeros(nbin,n); +for i=2:nbin + for k=1:n + xidx = find(s(:,k) <= x(i)); % index for the positions + nn(i,k) = sum(w(xidx,k)); + end +end +xp = nn(2:nbin,:) - nn(1:nbin-1,:); +xpd = xp/bw; % the density, NOT the probability as xp + +if gIdx + plot(xc,xpd) + title(titstr), xlabel(xlabstr), ylabel(ylabstr); +end diff --git a/MatlabFiles/histwpdfg2D.m b/MatlabFiles/histwpdfg2D.m new file mode 100755 index 0000000..249be4f --- /dev/null +++ b/MatlabFiles/histwpdfg2D.m @@ -0,0 +1,111 @@ +function [xc,yc,z,zn] = histwpdfg2D(s,w,n,ditp,xlabstr,ylabstr) +% [xc,yc,z,zn] = histwpdfg2D(s,w,n,ditp,xlabstr,ylabstr) +% Given uneven weights and 2D draws, generate 2D pdf and probabilites by scaling 2D histogram +% +% s: ndraws-by-2 matrix where ndraws is # of draws and 2 variables +% w: ndraws-by-1 vector of (uneven) weights +% n: 1-by-2 vector -- # of bins (integers in general) for both x-axis and y-axis +% ditp: number -- degrees of bicubic interpolation +% xlabstr: xlabel string; if [], no xlab +% ylabstr: ylabel string; if [], no ylab +%--------------------------------- +% xc: the position of centered bin on x-axis, from left to right. All rows are identical +% yc: the position of centered bin on y-axis, from top to bottom. All columns are identical +% z: size(xc,2)-by-size(yc,1) -- the pdf value in each rectangular cell +% zn: size(xc,2)-by-size(yc,1) -- the probability value in each rectangular cell +% if nargout==0, plot 2D p.d.f. graphics +% +% January 1999 by Tao Zha + +if (size(s,2)~=2) + error('The size of 1st argument must be *-by-2 (i.e., 2 columns)') +end + +if (nargin==3), xlabstr=[]; ylabstr=[]; end + +if (length(n(:))~=2) + error('2nd argument must have exactly 2 elements') +end + +if (min(n)<3) + error('2nd argument -- bin size -- must have at least 3 for each axis') +end + +ndraws=size(s,1); + +%** normalized to 1 for the probability +w=w(:); % make sure it's a column vector +w = w/sum(w); + +%*** x-axis +minx = min(min(s(:,1))); +maxx = max(max(s(:,1))); +h1 = (maxx-minx)/n(1); % binwidth for x-axis +x = minx + h1*(0:n(1)); +xlen = length(x); % n(1)+1 +x(xlen) = maxx; % in case n(1) is not an integer +xc = x(1:xlen-1) + h1/2; % the position of the center of the x-bin + % 1-by-n(1) row vector: from left to right +xc = repmat(xc,[n(2) 1]); + +%*** y-axis +miny = min(min(s(:,2))); +maxy = max(max(s(:,2))); +h2 = (maxy-miny)/n(2); % binwidth for y-axis +y = miny + h2*(0:n(2)); +ylen = length(y); +y(ylen) = maxy; % in case n(2) is not an integer +yc = y(1:ylen-1) + h2/2; % the position of the center of the y-bin +yc = yc(:); % n(2)-by-1 column vector: from top to bottom +yc = repmat(yc,[1 n(1)]); + + +zn = zeros(n(2),n(1)); % the reverse of x and y is designed for mesh. + % see meshgrid to understand this. +tic +for draws=1:ndraws + k1 = floor((s(draws,1)-minx)/h1)+1; + k2 = floor((s(draws,2)-miny)/h2)+1; + % + % if k1==0 + % k1=1; + % end + % if k2==0; + % k2=1; + % end + % + if k1>n(1) + k1=n(1); + end + if k2>n(2) + k2=n(2) + end + zn(k2,k1) = zn(k2,k1)+w(draws); % probability in each rectangular cell +end +timeloop=toc; +disp(['Loop time -- minutes ' num2str(timeloop/60)]) + +z=zn/(h1*h2); % converted to the height of the p.d.f. + + +%*** scaled 2D histogram or p.d.f. +if (nargout==0) + %figure(1) + colormap(zeros(1,3)); % set color to black + mesh(xc,yc,z) + title('Scaled histogram or p.d.f.') + xlabel(xlabstr) + ylabel(ylabstr) +end + +%*** interpolation +if (ditp & nargout==0) + [xi,yi]=meshgrid(minx:h1/ditp:maxx,miny:h2/ditp:maxy); + zi = interp2(xc,yc,z,xi,yi,'bicubic'); + figure(30) + colormap(zeros(1,3)); % set color to black + mesh(xi,yi,zi) % or mesh + title('Interpolated p.d.f.') + xlabel(xlabstr) + ylabel(ylabstr) +end \ No newline at end of file diff --git a/MatlabFiles/imc2errgraph.m b/MatlabFiles/imc2errgraph.m new file mode 100755 index 0000000..a66255c --- /dev/null +++ b/MatlabFiles/imc2errgraph.m @@ -0,0 +1,103 @@ +function scaleout = imc2errgraph(imf,firstl1,firsth1,... + firstl,firsth,nvar,imstp,xlab,ylab,XTick) +% scaleout = imc2errgraph(imf,firstl1,firsth1,... +% firstl,firsth,nvar,imstp,xlab,ylab,XTick) +% imc2errgraph: impulse, c (column: shock 1 to N), 2 error bands, graph +% imf: impulse responses, column (responses to 1st shock, responses to 2nd shock +% etc), row (impusle steps), +% firstl1: lower band, .68 +% highth1: high band, .68 +% firstl: lower band, .90 +% highth: high band, .90 +% nvar: number of variables +% imstp: step of impulse responses +% xlab,ylab: labels +% Xtick: tick on x-axis; e.g., [1 12 36]; if [], no ticks +%----------------------- +% scaleout: gives out max and min for each row of graphs +% +% See imrgraph, imcerrgraph, imrerrgraph +t = 1:imstp; +temp1=zeros(nvar,1); +temp2=zeros(nvar,1); +maxval=zeros(nvar,1); +minval=zeros(nvar,1); +for i = 1:nvar + for j = 1:nvar + jnk1=max(firsth(:,(j-1)*nvar+i)); + jnk2=max(firstl(:,(j-1)*nvar+i)); + jnk3=max(firsth1(:,(j-1)*nvar+i)); + jnk4=max(firstl1(:,(j-1)*nvar+i)); + jnk5=max(imf(:,(j-1)*nvar+i)); + + temp1(j)=max([jnk1 jnk2 jnk3 jnk4 jnk5]); + % + jnk1=min(firstl(:,(j-1)*nvar+i)); + jnk2=min(firsth(:,(j-1)*nvar+i)); + jnk3=min(firstl1(:,(j-1)*nvar+i)); + jnk4=min(firsth1(:,(j-1)*nvar+i)); + jnk5=min(imf(:,(j-1)*nvar+i)); + + temp2(j)=min([jnk1 jnk2 jnk3 jnk4 jnk5]); + end + maxval(i)=max(temp1); + minval(i)=min(temp2); +end + +scaleout = [maxval(:) minval(:)]; + +%-------------- +% Column j: Shock 1 to N; Row i: Responses to +%------------- +%figure +rowlabel = 1; +for i = 1:nvar + columnlabel = 1; + + if minval(i)<0 + if maxval(i)<=0 + yt=[minval(i) 0]; + else + yt=[minval(i) 0 maxval(i)]; + end + else % (minval(i) >=0) + if maxval(i) > 0 + yt=[0 maxval(i)]; + else % (identically zero responses) + yt=[-1 0 1]; + end + end + scale=[1 imstp minval(i) maxval(i)]; + for j = 1:nvar + k1=(i-1)*nvar+j; + k2=(j-1)*nvar+i; + subplot(nvar,nvar,k1) + plot(t,imf(:,k2),t,[firstl1(:,k2) firsth1(:,k2)],'--',... + t,[firstl(:,k2) firsth(:,k2)],'-.',t,zeros(length(imf(:,k2)),1),'-'); + grid; + axis(scale); + %set(gca,'YLim',[minval(i) maxval(i)]) + % + set(gca,'XTick',XTick) + set(gca,'YTick',yt) + if i<nvar + set(gca,'XTickLabelMode','manual','XTickLabel',[]) + end + %set(gca,'XTickLabel',' '); + if j>1 + set(gca,'YTickLabel',' '); + end + if rowlabel == 1 + %title(['x' num2str(j)]) + %title(eval(['x' num2str(j)])) + title(char(xlab(j))) + end + if columnlabel == 1 + %ylabel(['x' num2str(i)]) + %ylabel(eval(['x' num2str(i)])) + ylabel(char(ylab(i))) + end + columnlabel = 0; + end + rowlabel = 0; +end \ No newline at end of file diff --git a/MatlabFiles/imcerrgraph.m b/MatlabFiles/imcerrgraph.m new file mode 100755 index 0000000..49924fd --- /dev/null +++ b/MatlabFiles/imcerrgraph.m @@ -0,0 +1,59 @@ +function scaleout = imcerrgraph(imf,firstl,firsth,nvar,imstp,xlab,ylab) +% function scaleout = imcerrgraph(imf,firstl,firsth,nvar,imstp,xlab,ylab) +% imcerrgraph: impulse, c (column: shock 1 to N), error bands, graph +% imf: impulse responses, column (responses to 1st shock, responses to 2nd shock +% etc), row (impusle steps), +% firstl: lower band +% highth: high band +% nvar: number of variables +% imstp: step of impulse responses +% xlab,ylab: labels +% +% See imrgraph, imcerrgraph, imrerrgraph + +t = 1:imstp; +temp1=zeros(nvar,1); +temp2=zeros(nvar,1); +maxval=zeros(nvar,1); +minval=zeros(nvar,1); +for i = 1:nvar + for j = 1:nvar + temp1(j)=max(firsth(:,(j-1)*nvar+i)); + temp2(j)=min(firstl(:,(j-1)*nvar+i)); + end + maxval(i)=max(temp1); + minval(i)=min(temp2); +end + +scaleout = [maxval(:) minval(:)]; + +%-------------- +% Column j: Shock 1 to N; Row i: Responses to +%------------- +figure +rowlabel = 1; +for i = 1:nvar + columnlabel = 1; + for j = 1:nvar + k1=(i-1)*nvar+j; + k2=(j-1)*nvar+i; + subplot(nvar,nvar,k1) + plot(t,imf(:,k2),t,[firstl(:,k2) firsth(:,k2)],':',... + t,zeros(length(imf(:,k2)),1),'-'); + set(gca,'YLim',[minval(i) maxval(i)]) + set(gca,'XTickLabel',' '); + set(gca,'YTickLabel',' '); + if rowlabel == 1 + %title(['x' num2str(j)]) + %title(eval(['x' num2str(j)])) + title(char(xlab(j))) + end + if columnlabel == 1 + %ylabel(['x' num2str(i)]) + %ylabel(eval(['x' num2str(i)])) + ylabel(char(ylab(i))) + end + columnlabel = 0; + end + rowlabel = 0; +end \ No newline at end of file diff --git a/MatlabFiles/imcgraph.m b/MatlabFiles/imcgraph.m new file mode 100755 index 0000000..8ecebbf --- /dev/null +++ b/MatlabFiles/imcgraph.m @@ -0,0 +1,64 @@ +function scaleout = imcgraph(imf,nvar,imstp,xlab,ylab,indxGimfml) +% scaleout = imcgraph(imf,nvar,imstp,xlab,ylab,indxGimfml) +% imcgraph: impulse, c (column: shock 1 to N), graph +% Graph the ML point impulse response +% +% imf: impulse responses, column (responses to 1st shock, responses to 2nd shock +% etc), row (impusle steps), +% nvar: number of variables +% imstp: step of impulse responses +% xlab,ylab: labels +% indxGimfml: 1, graph; 0, no graph +% +% NOTE: I added "indxGimfml" so this function may not be compatible with programs +% older than 03/06/99, TZ +% +% See imrgraph, imcerrgraph, imrerrgraph + +t = 1:imstp; +temp1=zeros(nvar,1); +temp2=zeros(nvar,1); +maxval=zeros(nvar,1); +minval=zeros(nvar,1); +for i = 1:nvar + for j = 1:nvar + temp1(j)=max(imf(:,(j-1)*nvar+i)); + temp2(j)=min(imf(:,(j-1)*nvar+i)); + end + maxval(i)=max(temp1); + minval(i)=min(temp2); +end + +scaleout = [maxval(:) minval(:)]; + +%-------------- +% Column j: Shock 1 to N; Row i: Responses to +%------------- +if indxGimfml + figure(1) + rowlabel = 1; + for i = 1:nvar + columnlabel = 1; + for j = 1:nvar + k1=(i-1)*nvar+j; + k2=(j-1)*nvar+i; + subplot(nvar,nvar,k1) + plot(t,imf(:,k2),t,zeros(length(imf(:,k2)),1),':'); + set(gca,'YLim',[minval(i) maxval(i)]) + set(gca,'XTickLabel',' '); + set(gca,'YTickLabel',' '); + if rowlabel == 1 + %title(['x' num2str(j)]) + %title(eval(['x' num2str(j)])) + title(char(xlab(j))) + end + if columnlabel == 1 + %ylabel(['x' num2str(i)]) + %ylabel(eval(['x' num2str(i)])) + ylabel(char(ylab(i))) + end + columnlabel = 0; + end + rowlabel = 0; + end +end \ No newline at end of file diff --git a/MatlabFiles/imfsim.m b/MatlabFiles/imfsim.m new file mode 100755 index 0000000..f4c0b15 --- /dev/null +++ b/MatlabFiles/imfsim.m @@ -0,0 +1,330 @@ +function imfsim(xinput) +% imfsim(xinput) +% Save the simulated pdfs of impulse responses; +% Print and save Gelman's measures of B and W for A0's, +% only when nstarts (# of starting points) >1. +% Ref: Waggoner and Zha "Does Normalization Matter for Inference" +% See note Forecast (2) +% +% xinput{1}: nfp -- total number of free parameters +% xinput{2}: nvar -- number of variables +% xinput{3}: xhat -- ML estimate of free parameters in A0 +% xinput{4}: hess -- Hessian of -logLH +% xinput{5}:Indxv -- index for selected variables of interest; normall first 2 are of our interest +% to select variables, always check idmat0 to make sure +% it plots: (1) pdf of 1st v for every buffer, (2) scattered plot of 1st and 2nd for every buffer, +% (2) pdf of 1st v for all sequences; (4) scattered plot of 3rd and 4th for all sequences +% (5) scattered plot of 1st and 2nd for al sequences. +% xinput{6}: IndxGraph - 1: plot graphs; 0: no graphs +% xinput{7}: idmat0 -- Index for non-zero elements in A0 with column to equation +% xinput{8}: nstarts -- # of starting points in Gibbs sampling +% xinput{9}: ndraws1 -- # of 1st loop to be discarded +% xinput{10}: ndraws2 -- # of 2nd loop for saving A0 draws +% xinput{11}: imndraws=nstarts*ndraws2 +% xinput{12}: a0indx -- index number for non-zero elements in A0 +% xinput{13}: tdf -- degrees of freedom for t-distribution +% xinput{14}: nbuffer -- interval for printing, plotting, and saving +% xinput{15}: Sbd -- nvar-by-nvar S{1}, ..., S{n} -- kind of covariance matrix for each simultaneous equation +% Already divided by "fss." +% xinput{16}: nSample -- the original sample size including lags +% xinput{17}: IndxNmlr -- index for which normalization rule to choose +% xinput{18}: IndxGibbs -- index for WZ Gibbs; 1; Gibbs; 0: Metropolis +% xinput{19}: scf -- reduction scale factor for Metropolis jumping kernel +% xinput{20}: H_sr -- square root of the inverse of the covariance matrix +% for free elements in A0 (nfp-by-nfp) +% xinput{21}: fss -- effective sample size == nSample-lags+# of dummy observations +% xinput{22}: idfile1 -- calls "iden6std." Save stds. of both data and impulse responses in idfile1 +% xinput{23}: xxhpc -- chol(X'X+inv(H_p_tilde)): upper triangular but its transpose +% is lower triagular Choleski +% xinput{24}: ImfErr -- if 1, impulse response simulation; if 0, disable this simulation +% xinput{25}: ninv -- number of bins pre-specified to put each draw of impulse response +% into a proper bin (or small interval) +% xinput{26}: imstp -- # of steps for impulse responses +% xinput{27}: forep -- forecast periods (# of steps) +% xinput{28}: yact -- actual data (in log except R, U, etc.) +% xinput{29}: yactqg -- quarterly annualized growth in actual data +% xinput{30}: yactCalyg -- calendar annual growth in actual data +% xinput{31}: imfml -- imstp-by-nvar^2 ML impulse responses +% xinput{32}: forepq -- forecast periods for quarterly growth +% xinput{33}: forepy -- forecast periods for annual growth +% xinput{34}: ncoef -- k: # of coeffients per equation +% xinput{35}: Bhml -- ML reduced form parameter B (nvar-by-k) +% xinput{36}: lags -- # of lags +%------------------ +% imfcntmulti: (ninv+2,imstp*nvar^2,nstarts) matrix +% cnt: count; for impulse responses; multi (nstarts) sequences +% All output is saved in outB_W, including Range5, invc, ninv, and imfcntmulti +% +% Written by T. Zha 1999 + +nfp=xinput{1}; nvar=xinput{2}; xhat=xinput{3}; hess=xinput{4}; Indxv=xinput{5}; +IndxGraph=xinput{6}; idmat0=xinput{7}; nstarts=xinput{8}; ndraws1=xinput{9}; ndraws2=xinput{10}; +imndraws=xinput{11}; a0indx=xinput{12}; tdf=xinput{13}; nbuffer=xinput{14}; Sbd=xinput{15}; +nSample = xinput{16}; IndxNmlr=xinput{17}; IndxGibbs=xinput{18}; scf=xinput{19}; H_sr=xinput{20}; +fss=xinput{21}; idfile1=xinput{22}; xxhpc=xinput{23}; ImfErr=xinput{24}; ninv=xinput{25}; +imstp=xinput{26}; forep=xinput{27}; yact=xinput{28}; yactqg=xinput{29}; yactCalyg=xinput{30}; +imfml=xinput{31}; forepq=xinput{32}; forepy=xinput{33}; ncoef=xinput{34}; Bhml=xinput{35}; +lags=xinput{36}; + +Avhx_bs = zeros(nfp,1); +Avhx_bm = zeros(nfp,1); +Avhx_bj = zeros(nfp,1); +Avhx_cj = zeros(nfp,1); +Avhx_cm = zeros(nfp,1); +A0_h = zeros(nvar); +A0gbs = A0_h; % drawn A0 in Gibbs sampling +Avhxm = zeros(nfp,1); +Avhxs = Avhxm; +A0xhat = zeros(nvar); +A0xhat(a0indx) = xhat; +% A0hatw = zeros(nvar^2,nbuffer); + +countJump = zeros(nstarts,1); + +imfmean = zeros(imstp,nvar^2); +imfcntmulti = zeros(ninv+2,imstp*nvar^2,nstarts); + % cnt: count; for impulse responses; multi (nstarts) sequences + + +%--------------------------------------------------- +% Specify the range for counting the empirical distribution +% +%** load the standard deviations of 6 variables, one for log(y), one for gq, and +%** the third one for yg +eval(['load ' idfile1 '.prn -ascii']); +eval(['ABstd=' idfile1 ';']); +Range5 = cell(4,1); % 4: log, qg, yg, and imf + +%@@@ Tony's trick to expand the matrix +% +%** In order of log(y), qg, and yg for Range5{i} for i=1:3 +Range5{1} =zeros(forep,nvar,2); % 2: min and max +Range5{1}(:,:,1) = repmat(yact(length(yact(:,1)),:)-10*ABstd(1,:),[forep 1]); % min, 30 std. +Range5{1}(:,:,2) = repmat(yact(length(yact(:,1)),:)+10*ABstd(1,:),[forep 1]); % max, 30 std. +% +Range5{2} =zeros(forepq,nvar,2); % 2: min and max +Range5{2}(:,:,1) = repmat(yactqg(length(yactqg(:,1)),:)-10*ABstd(2,:),[forepq 1]); % min, 30 std. +Range5{2}(:,:,2) = repmat(yactqg(length(yactqg(:,1)),:)+10*ABstd(2,:),[forepq 1]); % max, 30 std. +% +Range5{3} =zeros(forepy,nvar,2); % 2: min and max +Range5{3}(:,:,1) = repmat(yactCalyg(length(yactCalyg(:,1)),:)-10*ABstd(3,:),[forepy 1]); % min, 30 std. +Range5{3}(:,:,2) = repmat(yactCalyg(length(yactCalyg(:,1)),:)+10*ABstd(3,:),[forepy 1]); % max, 30 std. +% +Range5{4} =zeros(imstp,nvar^2,2); % 2: min and max +imfscale = repmat(ABstd(4,:),[1 nvar]); % because nvar variables to 1, ..., nvar shocks +Range5{4}(:,:,1) = repmat(imfml(1,:)-5*imfscale,[imstp 1]); % min, 5 std. +Range5{4}(:,:,2) = repmat(imfml(1,:)+5*imfscale,[imstp 1]); % max, 5 std. + % Range5(4)(:,:,1): imstp-by-nvar^2. Column: nvar responses to 1st shock, + % nvar responses to 2nd shock, ... +%** +invc = cell(4,1); % interval length (used for counting later). 1st 3 cells have each + % forep-by-nvar, and 4th has imstp-by-nvar^2. +for i=1:4 + invc{i} = Range5{i}(:,:,2) - Range5{i}(:,:,1); +end +hbin = invc{4} ./ ninv; % bin size for each point of impulse responses kkdf +imfloor = Range5{4}(:,:,1); + + + +%=================================== +% Here begins with the big loop +%=================================== +H1 = chol(hess); % upper triangular so that H1' is a lower triangular decomp +baseW = H_sr; %inv(H1); %H_sr; % covariance matrix without scaling +nswitch=0; %<<>> total number of sign switches +A0inxhat = inv(A0xhat); % inverse of ML estimate +a0indx0 = find(idmat0==0); % index for all zero's in A0; +nn=[nvar lags imstp]; + +[cT,vR,kdf] = gibbsglb(Sbd,idmat0,nvar,fss); + +tic +for starts = 1:nstarts + starts + if starts == 1 + A0gbs(a0indx) = xhat; % from "load ..." + if ~IndxGibbs % Metropolist + Avhx = xhat; + hAvhx = a0asfun(Avhx,Sbd,fss,nvar,a0indx); + hAvhx = -hAvhx; % converted to logLH + end + else + Avhx = baseW*randn(nfp,1); %H_sr*randn(nfp,1); % D: discarded sequence + csq=randn(tdf,1); + csq=sum(csq .* csq); + Avhx = xhat+Avhx/sqrt(csq/tdf); + %** Normalization by the choice of IndxNmlr + A0gbs(a0indx) = Avhx; + if ~IndxNmlr(5) + [A0gbs,jnk] = nmlzvar(A0gbs,A0xhat,A0inxhat,IndxNmlr,nswitch,[]); + else + A0ingbs = inv(A0gbs); + [A0gbs,jnk,jnk1] = nmlzvar(A0gbs,A0xhat,A0inxhat,IndxNmlr,nswitch,A0ingbs); + end + % + if ~IndxGibbs % Metropolist + Avhx = A0gbs(a0indx); + hAvhx = a0asfun(Avhx,Sbd,fss,nvar,a0indx); + hAvhx = -hAvhx; % converted to logLH + end + end + % + Avhxmm = zeros(nfp,1); + Avhxss = zeros(nfp,1); + cJump = 0; + imfcnt = zeros(ninv+2,imstp*nvar^2); % cnt: count; for impulse responses + + for draws = 1:ndraws1 + if IndxGibbs + A0gbs = gibbsvar(A0gbs,cT,vR,nvar,fss,kdf); + else % Metropolis + [Avhx,hAvhx,cJump] = smtplis(Avhx,hAvhx,tdf,cJump,scf,... + baseW,nfp,Sbd,fss,nvar,a0indx); + end + end + + wdraws=(starts-1)*ndraws2+0; + for draws = 1:ndraws2 + drawsc = (starts-1)*ndraws2+draws; + if IndxGibbs + A0gbs = gibbsvar(A0gbs,cT,vR,nvar,fss,kdf); + A0gbs(a0indx0) = 0; % set all zeros in A0gbs clean to avoid possible cumulative round-off errors + else % Metropolis + [Avhx,hAvhx,cJump] = smtplis(Avhx,hAvhx,tdf,cJump,scf,... + baseW,nfp,Sbd,fss,nvar,a0indx); + A0gbs(a0indx) = Avhx; + end + + %*** call normalization so that A0_h is normalized + if ~IndxNmlr(5) + [A0_h,nswitch] = nmlzvar(A0gbs,A0xhat,A0inxhat,IndxNmlr,nswitch,[]); + A0_hin = inv(A0_h); + else + A0ingbs = inv(A0gbs); + [A0_h,nswitch,A0_hin] = nmlzvar(A0gbs,A0xhat,A0inxhat,IndxNmlr,nswitch,A0ingbs); + end + Avhx_norm = A0_h(a0indx); + + % + % *** normal draws for posterior Aplus conditional on A0h + % + %** the mean is Aplushm, and the covariance is inv(xxhp)=Lxxhpc*Lxxhpc' + Apindm = randn(ncoef,nvar); + % + if ~all(all(finite(Bhml))) + Aplushm=zeros(ncoef,nvar); + for i=1:nvar + Aplushm(:,i)=Gb{i}*A0_h(:,i); % see Zha's forecast (1) p.9 + % Here, Gb is used to compute A+ where A+(i) = Gb(i)*a0(i) + end + Bh_h = (Aplushm + xxhpc\Apindm)*A0_hin; + else + Bh_h = Bhml + (xxhpc\Apindm)*A0_hin; + end + + if ImfErr + swish_h = A0_hin'; % Switching back to the form A0*y(t) = e(t) + imf_h = zimpulse(Bh_h,swish_h,nn); % in the form that is congenial to RATS + % imf3_h=reshape(imf_h,size(imf_h,1),nvar,nvar); + % % imf3: row--steps, column--nvar responses, 3rd dimension--nvar shocks + imfmean = imfmean + imf_h; % posterior mean + imfcnt = empdfsort(imfcnt,imf_h,imfloor,hbin,ninv); + % sorted counts (prob.) in bins + end + + Avhxm = Avhxm + Avhx_norm; % 1st step to overall mean of parameter + Avhxs = Avhxs + Avhx_norm.^2; % 1st step to overall 2nd moment of parameter + + %* compute the mean and 2nd moment + %** Getting average of variances W and variance of means B/n -- B_n + %* see Gelman, p.331, my Shock(0), 12-13, and my Forecast (2), 28-31 + if (nstarts>1) + Avhxmm = Avhxmm + Avhx_norm; % n*(phi_.j) + Avhxss = Avhxss + Avhx_norm.^2; % 1st step to (phi_ij) for fixed j + end + + % A0hatw(:,drawsc-wdraws) = A0_h(:); + if ~mod(draws,nbuffer) + starts + draws + wdraws=drawsc + % fwriteid = fopen('outA0.bin','a'); + % count = fwrite(fwriteid,A0hatw,'double'); + % status = fclose('all'); + end + end + % + imfcntmulti(:,:,starts) = imfcnt; + + if ~IndxGibbs + countJump(starts,1) = cJump; + end + % + %** Getting average of variances W and variance of means B/n -- B_n + %** see Gelman, p.331, my Shock(0), pp.12-13, and my Forecast (2), pp.28-31 + if (nstarts>1) + Avhx_aj = Avhxmm/ndraws2; % (phi_.j) + Avhx_bs = Avhx_bs + Avhx_aj.^2; % 1st step to 2nd moment of (phi_.j) + Avhx_bm = Avhx_bm + Avhx_aj; % 1st step to (phi_..) + % + Avhx_bj = Avhxss/ndraws2; % 2nd moment of (phi_ij) for fixed j + Avhx_cj = Avhx_bj - Avhx_aj.^2; % ((n-1)/n)*S^2_j + Avhx_cm = Avhx_cm + Avhx_cj; % sum of ((n-1)/n)*S^2_j across j + end +end +timend = toc +timeminutes=timend/60 + +if ~IndxGibbs + countJump = countJump/ndraws2 +end + +Avhxm = Avhxm/(imndraws); +Avhxs = Avhxs/(imndraws); +Avhxv = Avhxs - Avhxm.^2; +Avhxs = sqrt(Avhxv); % stardard deviation +A0hm = zeros(nvar); +A0hm(a0indx) = Avhxm % mean +A0hv = zeros(nvar); +A0hv(a0indx) = Avhxv; % varaince matrix +A0hs = zeros(nvar); +A0hs(a0indx) = Avhxs; % standar deviation + +imfmean = imfmean/(imndraws); + +%**** Getting Within-Sequence W and Between-Sequence B_n +% see Gelman, p.331, my Shock(0), pp.12-13, and my Forecast (2), pp.28-31 +if (nstarts>1) + AvhxW = (ndraws2/(ndraws2-1))*Avhx_cm/nstarts; + % W: average of j within-sequence variances + AvhxB_n = (nstarts/(nstarts-1)) * ( Avhx_bs/nstarts - (Avhx_bm/nstarts).^2 ); + % B/n: variance of J within-sequence means + AvhxB = ndraws2*AvhxB_n; % B + % + B_W1 = AvhxB ./ AvhxW; + B1 = AvhxB; + W1 = AvhxW; + GR1 = sqrt((ndraws2-1)/ndraws2 + B_W1/ndraws2); + % measure of Gelman reduction; need not be 1 to be accurate, + % contrary to what Gelman claims + save outB_W B_W1 B1 W1 GR1 nstarts ndraws2 imndraws timeminutes Avhxs ... + A0xhat A0hm A0hs A0hv IndxGibbs countJump + if ImfErr + save outB_W nswitch imfml imfmean imfcntmulti Range5 ninv invc imstp nvar -append + end + + titstr = ['J ' num2str(nstarts) ' n1 ' num2str(ndraws1) ... + ' n2 ' num2str(ndraws2) ' timend minutes ' num2str(timend/60)]; + disp(' ') + disp(titstr) + disp('B/W sqrt(B) sqrt(W) Std(A0) GR') + format short g + [B_W1 sqrt(B1) sqrt(W1) Avhxs GR1] +else + save outB_W nstarts ndraws1 ndraws2 imndraws timeminutes Avhxs ... + A0xhat A0hm A0hs A0hv IndxGibbs countJump + if ImfErr + save outB_W nswitch imfml imfmean imfcntmulti Range5 ninv invc imstp nvar -append + end +end diff --git a/MatlabFiles/imfvdscksim.m b/MatlabFiles/imfvdscksim.m new file mode 100755 index 0000000..879115a --- /dev/null +++ b/MatlabFiles/imfvdscksim.m @@ -0,0 +1,536 @@ +function imfvdscksim(xinput,sa0indx,simfindx) +% imfvdscksim(xinput,sa0indx,simfindx) +% Save the simulated pdfs of impulse responses, vd, shocks, and A0's; +% Ref: Waggoner and Zha "Does Normalization Matter for Inference" +% See note Forecast (2) +% +% xinput{1}: nfp -- total number of free parameters +% xinput{2}: nvar -- number of variables +% xinput{3}: xhat -- ML estimate of free parameters in A0 +% xinput{4}: hess -- Hessian of -logLH +% xinput{5}:Indxv -- index for selected variables of interest; normall first 2 are of our interest +% to select variables, always check idmat0 to make sure +% it plots: (1) pdf of 1st v for every buffer, (2) scattered plot of 1st and 2nd for every buffer, +% (2) pdf of 1st v for all sequences; (4) scattered plot of 3rd and 4th for all sequences +% (5) scattered plot of 1st and 2nd for al sequences. +% xinput{6}: IndxGraph - 1: plot graphs; 0: no graphs +% xinput{7}: idmat0 -- Index for non-zero elements in A0 with column to equation +% xinput{8}: nstarts -- # of starting points in Gibbs sampling +% xinput{9}: ndraws1 -- # of 1st loop to be discarded +% xinput{10}: ndraws2 -- # of 2nd loop for saving A0 draws +% xinput{11}: imndraws=nstarts*ndraws2 +% xinput{12}: a0indx -- index number for non-zero elements in A0 +% xinput{13}: tdf -- degrees of freedom for t-distribution +% xinput{14}: nbuffer -- interval for printing, plotting, and saving +% xinput{15}: Sbd -- nvar-by-nvar S{1}, ..., S{n} -- kind of covariance matrix for each simultaneous equation +% xinput{16}: nSample -- the original sample size including lags +% xinput{17}: IndxNmlr -- index for which normalization rule to choose +% xinput{18}: IndxGibbs -- index for WZ Gibbs; 1; Gibbs; 0: Metropolis +% xinput{19}: scf -- reduction scale factor for Metropolis jumping kernel +% xinput{20}: H_sr -- covariance matrix for free elements in A0 (nfp-by-nfp) +% xinput{21}: fss -- effective sample size == nSample-lags+# of dummy observations +% xinput{22}: idfile1 -- calls "iden6std." Save stds. of both data and impulse responses in idfile1 +% xinput{23}: xxhpc -- chol(X'X+inv(H_p_tilde)): upper triangular but its transpose +% is lower triagular Choleski +% xinput{24}: ImfErr -- if 1, impulse response simulation; if 0, disable this simulation +% xinput{25}: ninv -- number of bins pre-specified to put each draw of impulse response +% into a proper bin (or small interval) +% xinput{26}: imstp -- # of steps for impulse responses +% xinput{27}: forep -- forecast periods (# of steps) +% xinput{28}: yact -- actual data (in log except R, U, etc.) +% xinput{29}: yactqg -- quarterly annualized growth in actual data +% xinput{30}: yactCalyg -- calendar annual growth in actual data +% xinput{31}: imfml -- imstp-by-nvar^2 ML impulse responses +% xinput{32}: forepq -- forecast periods for quarterly growth +% xinput{33}: forepy -- forecast periods for annual growth +% xinput{34}: ncoef -- k: # of coeffients per equation +% xinput{35}: Bhml -- ML reduced form parameter B (nvar-by-k) +% xinput{36}: lags -- # of lags +% xinput{37}: Psuedo -- 1: for Pseudo out-of-sample; 0: for in-sample (or real-time out-of-sample) +% xinput{38}: q_m = 4 or 12 -- quarterly (4) or monthly (12) +% xinput{39}: imf3ml -- ML impulse responses with row--steps, column--nvar responses, +% 3rd dimension--nvar shocks +% xinput{40}: vlistlog -- sub index for log in vlist +% xinput{41}: vlistper -- sub index for percent in vlist +% xinput{42}: phi -- X in the form of y = X*B+U. Row: nSmaple-lags+ndobs. Column: ncoef +% xinput{43}: actup -- acutal periods for backing out structural shocks +% xinput{44}: A0ml -- ML A0; column-equation +% xinput{45}: Bhml -- ML Bh (k-by-nvar) +% xinput{46}: yrEnd -- the end year for the estimation period +% xinput{47}: qmEnd -- the end month or quarter for the estimation period +% xinput{48}: yrStart -- the start year for the estimation period +% xinput{49}: qmStart -- the start month or quarter for the estimation period +% sa0indx: special a0 index. 1: use this; 0: disenable +% simfindx: special impulse response index. 1: use it; 0: disenable +%------------------ +% E.G.: imfcntmulti: (ninv+2,imstp*nvar^2,nstarts) matrix +% cnt: count; for impulse responses; multi (nstarts) sequences +% All output is saved in outB_W, including Range5, invc, ninv, imfcntmulti, +% sckcorcntmulti, Avhxcntmulti, lzvdcntmulti +% +% Written by TAZ 1999 + +nfp=xinput{1}; nvar=xinput{2}; xhat=xinput{3}; hess=xinput{4}; Indxv=xinput{5}; +IndxGraph=xinput{6}; idmat0=xinput{7}; nstarts=xinput{8}; ndraws1=xinput{9}; ndraws2=xinput{10}; +imndraws=xinput{11}; a0indx=xinput{12}; tdf=xinput{13}; nbuffer=xinput{14}; Sbd=xinput{15}; +nSample = xinput{16}; IndxNmlr=xinput{17}; IndxGibbs=xinput{18}; scf=xinput{19}; H_sr=xinput{20}; +fss=xinput{21}; idfile1=xinput{22}; xxhpc=xinput{23}; ImfErr=xinput{24}; ninv=xinput{25}; +imstp=xinput{26}; forep=xinput{27}; yact=xinput{28}; yactqg=xinput{29}; yactCalyg=xinput{30}; +imfml=xinput{31}; forepq=xinput{32}; forepy=xinput{33}; ncoef=xinput{34}; Bhml=xinput{35}; +lags=xinput{36}; Psuedo=xinput{37}; q_m=xinput{38}; imf3ml=xinput{39}; vlistlog=xinput{40}; +vlistper=xinput{41}; phi=xinput{42}; actup=xinput{43}; A0ml=xinput{44}; Bhml=xinput{45}; +yrEnd=xinput{46}; qmEnd=xinput{47}; yrStart=xinput{48}; qmStart=xinput{49}; + + +if Psuedo + disp('Make sure (1) Psuedo=0 in msstart.m and (2) "actuap=nSample-lags" for strucutral shocks') + disp('Press ctrl-c to abort now') +end + +A0_h = zeros(nvar); +A0gbs = A0_h; % drawn A0 in Gibbs sampling +Avhxml = xhat; % ML estimate +Avhxmean = zeros(nfp,1); +Avhxs = Avhxmean; + +A0xhat = zeros(nvar); +A0xhat(a0indx) = xhat; +% A0hatw = zeros(nvar^2,nbuffer); + +countJump = zeros(nstarts,1); +imstpyer = floor(imstp/q_m); % yearly + +imfmean = zeros(imstp,nvar^2); +imfs = imfmean; +imfyermean = zeros(imstpyer,nvar^2); +imfyers = imfyermean; +imfyer3ml = zeros(imstpyer,nvar,nvar); +imfyer3_h = zeros(imstpyer,nvar,nvar); + + +imfcntmulti = zeros(ninv+2,imstp*nvar^2,nstarts); + % cnt: count; for impulse responses; multi (nstarts) sequences +Avhxcntmulti = zeros(ninv+2,nfp,nstarts); + % cnt: count; for A0; multi (nstarts) sequences +imfyercntmulti = zeros(ninv+2,imstpyer*nvar^2,nstarts); + % cnt: count; for impulse responses; multi (nstarts) sequences +lzvdcntmulti = zeros(ninv+2,imstp*nvar^2,nstarts); + % cnt: count; for lz vd; multi (nstarts) sequences +lzvdyercntmulti = zeros(ninv+2,imstpyer*nvar^2,nstarts); + % cnt: count; for lz vd; multi (nstarts) sequences +sckcorcntmulti = zeros(ninv+2,nvar^2,nstarts); + +%--------------------------------------------------- +% Specify the range for counting the empirical distribution +% +%** load the standard deviations of 6 variables, one for log(y), one for gq, and +%** the third one for yg +eval(['load ' idfile1 '.prn -ascii']); +eval(['ABstd=' idfile1 ';']); +Range5 = cell(9,1); % 8: log, qg, yg, imf, Avhx, imfyer (yearly), lzvd, + % lzvdyer, sckcorv, + +%@@@ Tony's trick to expand the matrix +% +%** In order of log(y), qg, and yg for Range5{i} for i=1:3 +Range5{1} =zeros(forep,nvar,2); % 2: min and max +Range5{1}(:,:,1) = repmat(yact(length(yact(:,1)),:)-10*ABstd(1,:),[forep 1]); % min, 30 std. +Range5{1}(:,:,2) = repmat(yact(length(yact(:,1)),:)+10*ABstd(1,:),[forep 1]); % max, 30 std. +% +Range5{2} =zeros(forepq,nvar,2); % 2: min and max +Range5{2}(:,:,1) = repmat(yactqg(length(yactqg(:,1)),:)-10*ABstd(2,:),[forepq 1]); % min, 30 std. +Range5{2}(:,:,2) = repmat(yactqg(length(yactqg(:,1)),:)+10*ABstd(2,:),[forepq 1]); % max, 30 std. +% +Range5{3} =zeros(forepy,nvar,2); % 2: min and max +Range5{3}(:,:,1) = repmat(yactCalyg(length(yactCalyg(:,1)),:)-10*ABstd(3,:),[forepy 1]); % min, 30 std. +Range5{3}(:,:,2) = repmat(yactCalyg(length(yactCalyg(:,1)),:)+10*ABstd(3,:),[forepy 1]); % max, 30 std. +% +Range5{4} =zeros(imstp,nvar^2,2); % 2: min and max +imfscale = repmat(ABstd(4,:),[1 nvar]); % because nvar variables to 1, ..., nvar shocks +Range5{4}(:,:,1) = repmat(imfml(1,:)-5*imfscale,[imstp 1]); % min, 5 std. +Range5{4}(:,:,2) = repmat(imfml(1,:)+5*imfscale,[imstp 1]); % max, 5 std. + % Range5(4)(:,:,1): imstp-by-nvar^2. Column: nvar responses to 1st shock, + % nvar responses to 2nd shock, ... +% +%*** for parameters A0's +Range5{5} =zeros(nfp,2); % 2: min and max +Avhxscale = abs(Avhxml); +Range5{5}(:,1) = Avhxml-5*Avhxscale; % min, 5 std. +Range5{5}(:,2) = Avhxml+5*Avhxscale; % max, 5 std. + +% +%*** for yearly impulse responses +yer3 = zeros(1+imstpyer,nvar,nvar); +for k=1:imstpyer + yer3(k+1,:,:) = mean(imf3ml(1+q_m*(k-1):q_m*k,:,:),1); % annual average + % yer3: row--steps, column--nvar responses, 3rd dimension--nvar shocks +end +imfyer3ml(:,vlistlog,:) = ( exp(yer3(2:1+imstpyer,vlistlog,:)-yer3(1:imstpyer,vlistlog,:)) - 1 ).*100; +imfyer3ml(:,vlistper,:) = yer3(2:1+imstpyer,vlistper,:) .* 100; + % imfyer3ml: row--steps, column--nvar responses, 3rd dimension--nvar shocks +tmp = max(squeeze(max(imfyer3ml,[],1)),[],2); % nvar-by-1 +tmp = tmp'; % 1-by-nvar (variables) +imfyerml = reshape(imfyer3ml,imstpyer,nvar^2); +imfyermlmax = max(abs(imfyerml)); % for error bands (imfyercnt) later +%*** for annual impulse responses +Range5{6} =zeros(imstpyer,nvar^2,2); % 2: min and max +tmp = repmat(tmp,[1 nvar]); % because nvar variables to 1, ..., nvar shocks +imfyerscl = repmat(tmp,[imstpyer,1]); % imstpyer-by-nvar^2 +Range5{6}(:,:,1) = imfyerml-5*imfyerscl; % min, 5 std. +Range5{6}(:,:,2) = imfyerml+5*imfyerscl; % max, 5 std. + % Range5(6)(:,:,1): imstpyer-by-nvar^2. Column: nvar responses to 1st shock, + % nvar responses to 2nd shock, ... + +%*** lz variance decomposition (nunlike the traditional, non-cumulative). +tmp0=abs(imf3ml); +tmp1 = repmat(sum(tmp0,3),[1 1 nvar]); % imstp-by-nvar^2 + % imf3: row--steps, column--nvar responses, 3rd dimension--nvar shocks +lzvd3ml = 100*(tmp0./tmp1); +lzvdml = reshape(lzvd3ml,imstp,nvar^2); +%** for lz vd (non-cumulative) +Range5{7} =zeros(imstp,nvar^2,2); % 2: min and max +Range5{7}(:,:,1) = zeros(imstp,nvar^2); % min, 5 std. +Range5{7}(:,:,2) = 100*ones(imstp,nvar^2); % max, 5 std. + % Range5(7)(:,:,1): imstp-by-nvar^2. Column: nvar responses to 1st shock, + % nvar responses to 2nd shock, ... + +%*** lz annual variance decomposition (nunlike the traditional, non-cumulative). +tmp0=abs(imfyer3ml); +tmp1 = repmat(sum(tmp0,3),[1 1 nvar]); % imstp-by-nvar^2 + % imf3: row--steps, column--nvar responses, 3rd dimension--nvar shocks +lzvdyer3ml = 100*(tmp0./tmp1); +lzvdyerml = reshape(lzvdyer3ml,imstpyer,nvar^2); +%** for lz annual vd +Range5{8} =zeros(imstpyer,nvar^2,2); % 2: min and max +Range5{8}(:,:,1) = zeros(imstpyer,nvar^2); % min, 5 std. +Range5{8}(:,:,2) = 100*ones(imstpyer,nvar^2); % max, 5 std. + % Range5(8)(:,:,1): imstpyer-by-nvar^2. Column: nvar responses to 1st shock, + % nvar responses to 2nd shock, ... + +%**** Correlations among structural shocks +philr = phi(size(phi,1)-actup+1,:); % +1 is absolutely needed +yexa = yact(1:actup,:); +Estrexaml = fidcndexa(yexa,philr,A0ml,Bhml,nvar,lags,actup); % actup-by-nvar +sckvarml = (Estrexaml'*Estrexaml)/actup; +sckcorml = corr(sckvarml); +%** for shock correlation sckcor +Range5{9} =zeros(nvar,nvar,2); % 2: min and max +Range5{9}(:,:,1) = (-1)*ones(nvar,nvar); % min, 5 std. +Range5{9}(:,:,2) = ones(nvar,nvar); % max, 5 std. + % Range5(9)(:,:,1): nvar^2. Correlation among structural shocks + + + + +%** +invc = cell(9,1); % interval length (used for counting later). +for i=[1:4 6:9] + invc{i} = Range5{i}(:,:,2) - Range5{i}(:,:,1); +end +invc{5} = Range5{5}(:,2) - Range5{5}(:,1); +% +imfhbin = invc{4} ./ ninv; % bin size for each point of impulse responses +imfloor = Range5{4}(:,:,1); % lowest point next to -infinity +Avhxhbin = invc{5} ./ ninv; % bin size for each point of A0 +Avhxfloor = Range5{5}(:,1); % lowest point next to -infinity +imfyerhbin = invc{6} ./ ninv; % bin size for each point of annual impulse responses +imfyerfloor = Range5{6}(:,:,1); % lowest point next to -infinity +lzvdhbin = invc{7} ./ ninv; % bin size for each point of variance decompositions +lzvdfloor = Range5{7}(:,:,1); % lowest point next to -infinity +lzvdyerhbin = invc{8} ./ ninv; % bin size for each point of annul variance decompositions +lzvdyerfloor = Range5{8}(:,:,1); % lowest point next to -infinity +sckcorhbin = invc{9} ./ ninv; % bin size for each point of shock correlations +sckcorfloor = Range5{9}(:,:,1); % lowest point next to -infinity + + + + +%*** <<>> Specific requests +%*** compute prob(parameter>0) or joint prob. of sign matches in MP and MD +if sa0indx + csix1a0 = [-1 -1 1 1 1 -1 1]'; % for 7 parameters in MP and MD + % from 7th to 13th in Avhx_norm + nspeca0 = 7+3; % number of specific requests + % additional 3: 1 for all MP parameters; 2 for all MD parameters; + % 3 for all paramters in MP and MD + cspeca0 = zeros(nspeca0,1); +end +% +if simfindx + csix1imf = [-1 -1 1 -1 -1 1]'; % for 6 variables to MP shock + % maybe at different horizons (esp. for inflation) + csix1pimf = [1 1 1 24 36 24]'; % the periods for the 6 varialbes to MP shock + % Pcm, M2, FFR, y, P, U. + nspecimf = nvar+2; % number of specific requests + % additional 1: 1 for opposite signs of M2 and R + cspecimf = zeros(nspecimf,1); +end + + + + +%=================================== +% Here begins with the big loop +%=================================== +H1 = chol(hess); % upper triangular so that H1' is a lower triangular decomp +baseW = H_sr; %inv(H1); %H_sr; % covariance matrix without scaling +nswitch=0; %<<>> total number of sign switches +A0inxhat = inv(A0xhat); % inverse of ML estimate +a0indx0 = find(idmat0==0); % index for all zero's in A0; +nn=[nvar lags imstp]; + +[cT,vR,kdf] = gibbsglb(Sbd,idmat0,nvar,fss); + +tic +for starts = 1:nstarts + starts + if starts == 1 + A0gbs(a0indx) = xhat; % from "load ..." + if ~IndxGibbs % Metropolist + Avhx = xhat; + hAvhx = a0asfun(Avhx,Sbd,fss,nvar,a0indx); + hAvhx = -hAvhx; % converted to logLH + end + else + Avhx = baseW*randn(nfp,1); %H_sr*randn(nfp,1); % D: discarded sequence + csq=randn(tdf,1); + csq=sum(csq .* csq); + Avhx = xhat+Avhx/sqrt(csq/tdf); + %** Normalization by the choice of IndxNmlr + A0gbs(a0indx) = Avhx; + if ~IndxNmlr(5) + [A0gbs,jnk] = nmlzvar(A0gbs,A0xhat,A0inxhat,IndxNmlr,nswitch,[]); + else + A0ingbs = inv(A0gbs); + [A0gbs,jnk,jnk1] = nmlzvar(A0gbs,A0xhat,A0inxhat,IndxNmlr,nswitch,A0ingbs); + end + % + if ~IndxGibbs % Metropolist + Avhx = A0gbs(a0indx); + hAvhx = a0asfun(Avhx,Sbd,fss,nvar,a0indx); + hAvhx = -hAvhx; % converted to logLH + end + end + % + cJump = 0; + + imfcnt = zeros(ninv+2,imstp*nvar^2); % cnt: count; for impulse responses + Avhxcnt = zeros(ninv+2,nfp); % cnt: count; for A0's + imfyercnt = zeros(ninv+2,imstpyer*nvar^2); % cnt: count; for impulse responses + lzvdcnt = zeros(ninv+2,imstp*nvar^2); % cnt: count; for lz vd (non-cumulative) + lzvdyercnt = zeros(ninv+2,imstpyer*nvar^2); % cnt: count; for lz annual vd (non-cumulative) + sckcorcnt = zeros(ninv+2,nvar^2); % cnt: count; for shock correlations + + for draws = 1:ndraws1 + if IndxGibbs + A0gbs = gibbsvar(A0gbs,cT,vR,nvar,fss,kdf); + else % Metropolis + [Avhx,hAvhx,cJump] = smtplis(Avhx,hAvhx,tdf,cJump,scf,... + baseW,nfp,Sbd,fss,nvar,a0indx); + end + end + + wdraws=(starts-1)*ndraws2+0; + for draws = 1:ndraws2 + drawsc = (starts-1)*ndraws2+draws; + if IndxGibbs + A0gbs = gibbsvar(A0gbs,cT,vR,nvar,fss,kdf); + A0gbs(a0indx0) = 0; % set all zeros in A0gbs clean to avoid possible cumulative round-off errors + else % Metropolis + [Avhx,hAvhx,cJump] = smtplis(Avhx,hAvhx,tdf,cJump,scf,... + baseW,nfp,Sbd,fss,nvar,a0indx); + A0gbs(a0indx) = Avhx; + end + + %*** call normalization so that A0_h is normalized + if ~IndxNmlr(5) + [A0_h,nswitch] = nmlzvar(A0gbs,A0xhat,A0inxhat,IndxNmlr,nswitch,[]); + A0_hin = inv(A0_h); + else + A0ingbs = inv(A0gbs); + [A0_h,nswitch,A0_hin] = nmlzvar(A0gbs,A0xhat,A0inxhat,IndxNmlr,nswitch,A0ingbs); + end + Avhx_norm = A0_h(a0indx); + + if sa0indx + for k=1:7 + cspeca0(k) = cspeca0(k) + ((csix1a0(k)*Avhx_norm(6+k))>0); + end + %*** Joint tests + j1=csix1a0; + j2=Avhx_norm; + %** MP equation + mpall = ((j1(2)*j2(8))/(j1(3)*j2(9)))<0; % & ((j1(1)*j2(7))/(j1(3)*j2(9)))<0; + + cspeca0(8) = cspeca0(8) + mpall; + %** MD equation + mdall = ((j1(4)*j2(10))/(j1(5)*j2(11)))<0; %& ((j1(4)*j2(10))/(j1(6)*j2(12)))<0; + cspeca0(9) = cspeca0(9) + mdall; + mpdall = mpall & mdall; + cspeca0(10) = cspeca0(10) + mpdall; + end + + % + % *** normal draws for posterior Aplus conditional on A0h + % + %** the mean is Aplushm, and the covariance is inv(xxhp)=Lxxhpc*Lxxhpc' + Apindm = randn(ncoef,nvar); + % + if ~all(all(finite(Bhml))) + Aplushm=zeros(ncoef,nvar); + for i=1:nvar + Aplushm(:,i)=Gb{i}*A0_h(:,i); % see Zha's forecast (1) p.9 + % Here, Gb is used to compute A+ where A+(i) = Gb(i)*a0(i) + end + Bh_h = (Aplushm + xxhpc\Apindm)*A0_hin; + else + Bh_h = Bhml + (xxhpc\Apindm)*A0_hin; + end + + if ImfErr + swish_h = A0_hin'; % Switching back to the form A0*y(t) = e(t) + imf_h = zimpulse(Bh_h,swish_h,nn); % in the form that is congenial to RATS + imf3_h=reshape(imf_h,size(imf_h,1),nvar,nvar); + % imf3: row--steps, column--nvar responses, 3rd dimension--nvar shocks + imfmean = imfmean + imf_h; % posterior mean + imfs = imfs + imf_h.^2; % posterior 2nd moment + imfcnt = empdfsort(imfcnt,imf_h,imfloor,imfhbin,ninv); + % sorted counts (prob.) in bins + + %**** annula impulse responses + for k=1:imstpyer + yer3(k+1,:,:) = mean(imf3_h(1+q_m*(k-1):q_m*k,:,:),1); % annual average + % yer3: initialized earlier already + % yer3: row--steps, column--nvar responses, 3rd dimension--nvar shocks + end + imfyer3_h(:,vlistlog,:) = ( exp(yer3(2:1+imstpyer,vlistlog,:)-yer3(1:imstpyer,vlistlog,:)) - 1 ).*100; + imfyer3_h(:,vlistper,:) = yer3(2:1+imstpyer,vlistper,:) .* 100; + % imfyer3_h: row--steps, column--nvar responses, 3rd dimension--nvar shocks + imfyer_h = reshape(imfyer3_h,imstpyer,nvar^2); + imfyermean = imfyermean + imfyer_h; % posterior mean + imfyers = imfyers + imfyer_h.^2; % posterior 2nd moment + imfyercnt = empdfsort(imfyercnt,imfyer_h,imfyerfloor,imfyerhbin,ninv); + % sorted counts (prob.) in bins + + %**** Leeper-Zha variance decomposition (non-cumulative) + tmp0=abs(imf3_h); + tmp = repmat(sum(tmp0,3),[1 1 nvar]); % imstp-by-nvar^2 + % imf3: row--steps, column--nvar responses, 3rd dimension--nvar shocks + lzvd3_h = 100*(tmp0./tmp); + lzvd_h = reshape(lzvd3_h,imstp,nvar^2); + lzvdcnt = empdfsort(lzvdcnt,lzvd_h,lzvdfloor,lzvdhbin,ninv); + % sorted counts (prob.) in bins + + %**** Leeper-Zha annual variance decomposition (non-cumulative) + tmp0=abs(imfyer3_h); + tmp = repmat(sum(tmp0,3),[1 1 nvar]); % imstp-by-nvar^2 + % imf3: row--steps, column--nvar responses, 3rd dimension--nvar shocks + lzvdyer3_h = 100*(tmp0./tmp); + lzvdyer_h = reshape(lzvdyer3_h,imstpyer,nvar^2); + lzvdyercnt = empdfsort(lzvdyercnt,lzvdyer_h,lzvdyerfloor,lzvdyerhbin,ninv); + % sorted counts (prob.) in bins + + %**** Correlations among structural shocks + Estrexa_h = fidcndexa(yexa,philr,A0_h,Bh_h,nvar,lags,actup); % actup-by-nvar + sckvar_h = (Estrexa_h'*Estrexa_h)/actup; + sckcor_h = corr(sckvar_h); + sckcorcnt = empdfsort(sckcorcnt,sckcor_h,sckcorfloor,sckcorhbin,ninv); + + if simfindx + for k=1:6 + cspecimf(k) = cspecimf(k) + ((csix1a0(k)*imf_h(1,nvar+k))>0); + % 1st dim in imf_h: periods + end + %*** Joint tests + j1=csix1imf; + j2=imf_h; + j3=csix1pimf; + %** M2 and R in MP equation + mpall = ((j1(2)*j2(j3(2),nvar+2))/(j1(3)*j2(j3(3),nvar+3)))>0; % & ((j1(1)*j2(7))/(j1(3)*j2(9)))<0; + % 1st dim in j2: periods + cspecimf(nvar+1) = cspecimf(nvar+1) + mpall; + %** R and P in MP equation + mpall = ((j1(3)*j2(j3(3),nvar+3))/(j1(5)*j2(j3(5),nvar+5)))>0; % + % 1st dim in j2: periods + cspecimf(nvar+2) = cspecimf(nvar+2) + mpall; + % + % %** MD equation + % mdall = ((j1(4)*j2(10))/(j1(5)*j2(11)))<0; %& ((j1(4)*j2(10))/(j1(6)*j2(12)))<0; + % cspeca0(9) = cspeca0(9) + mdall; + % mpdall = mpall & mdall; + % cspeca0(10) = cspeca0(10) + mpdall; + end + end + + Avhxmean = Avhxmean + Avhx_norm; % 1st step to overall mean of parameter + Avhxs = Avhxs + Avhx_norm.^2; % 1st step to overall 2nd moment of parameter + Avhxcnt = empdfsort(Avhxcnt,Avhx_norm,Avhxfloor,Avhxhbin,ninv); + + + % A0hatw(:,drawsc-wdraws) = A0_h(:); + if ~mod(draws,nbuffer) + starts + draws + wdraws=drawsc + % fwriteid = fopen('outA0.bin','a'); + % count = fwrite(fwriteid,A0hatw,'double'); + % status = fclose('all'); + end + end + % + imfcntmulti(:,:,starts) = imfcnt; + Avhxcntmulti(:,:,starts) = Avhxcnt; + imfyercntmulti(:,:,starts) = imfyercnt; + lzvdcntmulti(:,:,starts) = lzvdcnt; + lzvdyercntmulti(:,:,starts) = lzvdyercnt; + sckcorcntmulti(:,:,starts) = sckcorcnt; + + if ~IndxGibbs + countJump(starts,1) = cJump; + end +end +timend = toc +timeminutes=timend/60 + +if ~IndxGibbs + countJump = countJump/ndraws2 +end + +Avhxmean = Avhxmean/(imndraws); +Avhxs = Avhxs/(imndraws); +Avhxs = sqrt(Avhxs - Avhxmean.^2); % stardard deviation +A0hm = zeros(nvar); +A0hm(a0indx) = Avhxmean % mean +A0hs = zeros(nvar); +A0hs(a0indx) = Avhxs; % standar deviation + +imfmean = imfmean/(imndraws); +imfs = imfs/imndraws; +imfs = sqrt(imfs - imfmean.^2); % standard deviation + +imfyermean = imfyermean/(imndraws); +imfyers = imfyers/imndraws; +imfyers = sqrt(imfyers - imfyermean.^2); % standard deviation + + +save outB_W nstarts ndraws1 ndraws2 imndraws timeminutes Avhxml Avhxmean Avhxs ... + Avhxcntmulti A0xhat A0hm A0hs IndxGibbs countJump nvar Range5 ... + ninv invc nfp a0indx nswitch actup nSample lags yrEnd qmEnd ... + yrStart qmStart q_m sckcorml sckcorcntmulti + +if ImfErr + if simfindx + cspecimf = cspecimf/imndraws; + save outB_W cspecimf -append + end + save outB_W imfml imfmean imfs imfcntmulti imstp cspecimf ... + imfyerml imfyermean imfyers imfyercntmulti imstpyer ... + lzvdml lzvdcntmulti lzvdyerml lzvdyercntmulti -append +end +% +if sa0indx + cspeca0 = cspeca0/imndraws; + save outB_W cspeca0 -append +end + + diff --git a/MatlabFiles/impgraphs.m b/MatlabFiles/impgraphs.m new file mode 100755 index 0000000..7c8239d --- /dev/null +++ b/MatlabFiles/impgraphs.m @@ -0,0 +1,56 @@ +function impgraphs(response,collabel,rowlabel) +%function impgraphs(response,collabel,rowlabel) +% collabel and rowlabel are cell arrays with string contents +XTick=[12 24 36 48]; %modify this line for other time units. +%XTickLabel=[] % Use this to suppress labeling. +[nrow,ncol,nt]=size(response); +for irow=1:nrow + smin=min(min(response(irow,:,:))); + smax=max(max(response(irow,:,:))); + if smin<0 + if smax<=0 + yt=[smin 0]; + else + yt=[smin 0 smax]; + end + else % (smin >=0) + if smax > 0 + yt=[0 smax]; + else % (identically zero responses) + yt=[-1 0 1]; + end + end + for i=1:length(yt) + if yt(i)==0.0 + if length(yt)==3 & -yt(1)<.2*yt(3) + ytc(i)={''}; + else + ytc(i)={' 0'}; + end + else + ytc(i)={sprintf('%2.4f',yt(i))}; + end + end + scale=[1 nt smin smax]; + for icol=1:ncol + subplot(nrow,ncol,(irow-1)*ncol+icol); + plot(squeeze(response(irow,icol,:)));grid + axis(scale); + if irow==1 + title(collabel{icol}); + end + if icol==1 + ylabel(rowlabel{irow}); + end + set(gca,'XTick',XTick) + set(gca,'YTick',yt) + if irow<nrow + set(gca,'XTickLabelMode','manual','XTickLabel',[]) + end + if icol>1 + set(gca,'YTickLabelMode','manual','YTickLabel',[]) + else + set(gca,'YTickLabelMode','manual','YTickLabel',char(ytc)) + end + end +end \ No newline at end of file diff --git a/MatlabFiles/imrgraph.m b/MatlabFiles/imrgraph.m new file mode 100755 index 0000000..b81a757 --- /dev/null +++ b/MatlabFiles/imrgraph.m @@ -0,0 +1,55 @@ +function scaleout = imrgraph(imf,nvar,imstp,xlab,ylab) +% function scaleout = imrgraph(imf,nvar,imstp,xlab,ylab) +% imcgraph: impulse, r (row: shock 1 to N), graph +% imf: impulse responses, column (responses to 1st shock, responses to 2nd shock +% etc), row (impusle steps), +% nvar: number of variables +% imstp: step of impulse responses +% xlab,ylab: labels +% +% See imcgraph, imcerrgraph, imrerrgraph + +t = 1:imstp; +temp1=zeros(nvar,1); +temp2=zeros(nvar,1); +maxval=zeros(nvar,1); +minval=zeros(nvar,1); +for i = 1:nvar + for j = 1:nvar + temp1(j)=max(imf(:,(j-1)*nvar+i)); + temp2(j)=min(imf(:,(j-1)*nvar+i)); + end + maxval(i)=max(temp1); + minval(i)=min(temp2); +end + +scaleout = [maxval(:) minval(:)]; + +%-------------- +% Column j: Reponses; Row i: Shock 1 to N +%------------- +figure +rowlabel = 1; +for i = 1:nvar + columnlabel = 1; + for j = 1:nvar + k=(i-1)*nvar+j; + subplot(nvar,nvar,k) + plot(t,imf(:,k),t,zeros(length(imf(:,k)),1),':' ); + set(gca,'YLim',[minval(j) maxval(j)]) + set(gca,'XTickLabel',' '); + set(gca,'YTickLabel',' '); + if rowlabel == 1 + %title(['X' num2str(j)]) + %title(eval(['x' num2str(j)])) + title(char(xlab(j))) + end + if columnlabel == 1 + %ylabel(['X' num2str(i)]) + %ylabel(eval(['x' num2str(i)])) + ylabel(char(ylab(i))) + end + columnlabel = 0; + end + rowlabel = 0; +end \ No newline at end of file diff --git a/MatlabFiles/invgamcdf.m b/MatlabFiles/invgamcdf.m new file mode 100755 index 0000000..975c340 --- /dev/null +++ b/MatlabFiles/invgamcdf.m @@ -0,0 +1,27 @@ +function P = invgamcdf(X, a, b); + +% This function computes the cumulative density for the inverse gamma +% distribution with shape parameter a and scale parameter b. It uses the +% following closed-form solution for the cdf of the inverse gamma +% distribution: +% ---------Cumulative density function for Inverse-Gamma distribution------- +% --- P(x; a, b) = G(b/x, a)/G(a), where G(b/x, a) is the upper incomplete +% gamma function and G(a) is the gamma function defined as +% G(b/x, a) = int_{b/x}^{\infty} t^{a-1} e^{-t} dt. +% The Matlab definition is different, which is +% gammainc(b/x, a) = (1.0/Gamma(a)) int_{0}^{b/x} t^{a-1} e^{-t} dt. +% Thus, we have +% G(b/x, a)/G(a) = (1-gammainc(b./X, a)). + +% First, check for input errors +if X<=0; + error('the support for the inverse gamma function needs to be positive') +end; +if a<= 0 || b <=0; + a = abs(a); + b = abs(b); + % abs() is used to allow continuous search for the fsolve function find_invgampar.m. + %error('parameter requirements: a>0, b>0'); +end; + +P = (1-gammainc(b./X, a)); diff --git a/MatlabFiles/invgampar.m b/MatlabFiles/invgampar.m new file mode 100755 index 0000000..dfb81dc --- /dev/null +++ b/MatlabFiles/invgampar.m @@ -0,0 +1,11 @@ +function f = invgampar(ab, XLO, XUP, PLO, PUP); + +% The function takes as inputs the parameters ab=[a, b] of the Inverse gamma +% distribution, the bounds of the support [XLO, XUP], the the corresponding +% probability of the bounds [PLO, PUP] and returns the residual value f. + +a = ab(1); b = ab(2); +f1 = PLO - invgamcdf(XLO, a, b); +f2 = PUP - invgamcdf(XUP, a, b); + +f = [f1, f2]; diff --git a/MatlabFiles/lcnmean.m b/MatlabFiles/lcnmean.m new file mode 100755 index 0000000..ef6ef06 --- /dev/null +++ b/MatlabFiles/lcnmean.m @@ -0,0 +1,19 @@ +function cutmean = lcnmean(x,pnIndx) +% +% cutmean = lcnmean(x,pnIndx) +% +% The mean of the truncated normal with the lower bound x if pnIndx>0 +% or the upper bound x if pnIndx<0. Zha Forecast (2) p.27 +% +% x: the lower bound x if pnIndx > 0; the upper bound x if pnIndx < 0 +% pnIndx: 1: truncated for posivie mean (tight); 0 truncated for negative mean (loose) +%------------ +% cutmean: the backed-out mean for the truncated normal +% +% October 1998 Tao Zha + +if pnIndx + cutmean = exp(-x^2/2)/(sqrt(2*pi)*(1-cdf('norm',x,0,1))); +else + cutmean = -exp(-x^2/2)/(sqrt(2*pi)*cdf('norm',x,0,1)); +end diff --git a/MatlabFiles/mformd1.m b/MatlabFiles/mformd1.m new file mode 100755 index 0000000..81d86ae --- /dev/null +++ b/MatlabFiles/mformd1.m @@ -0,0 +1,54 @@ +function [phi,y,ncoe] = mformd1(z,lags) +% +% [phi,y,ncoe] = mformd1(z,lags) where size(z,1)=T+lags. +% This file is a subset of sye.m, but only designed to arrange matrix form data as +% y(T*nvar) = XB + u, X--phi: T*k, B: k*nvar; where T=sp-lags, k=ncoe. +% Note T>=0. If T=0, y is empty, but phi (X) is still well defined. +% +% z: (T+lags)-by-(nvar+1) raw data matrix (nvar of variables + constant). +% e.g., C = ones(nSample,1); z=[xdget C]; +% lags: number of lags +% phi: (T-lags)-by-k X; where k=ncoe=[nvar for 1st lag, ..., nvar for last lag, const] +% y: Y: (T-lags)-by-nvar +% ncoe: number of coeffcients per equation: k=nvar*lags + 1 +% +% See also sye.m +% +% October 1998 Tao Zha. Revised, 03/13/99 + + +% ** setup of orders and lengths ** +[sp,nvar] = size(z); % sp: sample period T include lags +nvar = nvar-1; % -1: takes out the counting of constant + +ess = sp-lags; % effective sample size +sb = lags+1; % sample beginning +sl = sp; % sample last period +ncoe = nvar*lags + 1; % with constant + +% ** construct X for Y = X*B + U where phi = X ** +if ess<0 + warning('The length of the data must be >= lags') + disp('Check yrEnd and qmEnd in parac.m to make sure') + disp('Press ctrl-c to abort') + disp(' ') + pause +elseif ess==0 + x = z(:,1:nvar); + C = z(:,nvar+1); + phi = zeros(1,ncoe); + phi(1,ncoe) = C(1); + for k=1:lags, phi(1,nvar*(k-1)+1:nvar*k) = x(sb-k:sl-k+1,:); end + % row: T-lags; column: [nvar for 1st lag, ..., nvar for last lag, const] + % Thus, # of columns is nvar*lags+1 = ncoef. + y = x(sb:sl,:); +else + x = z(:,1:nvar); + C = z(:,nvar+1); + phi = zeros(ess,ncoe); + phi(:,ncoe) = C(1:ess); + for k=1:lags, phi(:,nvar*(k-1)+1:nvar*k) = x(sb-k:sl-k,:); end + % row: T-lags; column: [nvar for 1st lag, ..., nvar for last lag, const] + % Thus, # of columns is nvar*lags+1 = ncoef. + y = x(sb:sl,:); +end \ No newline at end of file diff --git a/MatlabFiles/mnpdf.m b/MatlabFiles/mnpdf.m new file mode 100755 index 0000000..07462fd --- /dev/null +++ b/MatlabFiles/mnpdf.m @@ -0,0 +1,28 @@ +function y = mnpdf(x,xm,C,constIx) +% y = mnpdf(x,xm,C,constIx) +% The pdf value for multivariate normal distribution +% +% x: p-by-draws matrix of values evaluated at where p=size(x,1) is # of variables +% xm: p-by-draws matrix of the mean of x +% C: p-by-p Choleski square root of PDS S -- the covariance matrix so that S = C*C' +% constIx: index for the constant. 1: constant (normalized); 0: no constant (unnormalized) +%---------- +% y: p-by-draws matrix of pdf's for multivariate normal distribution +% +% Christian P. Robert, "The Bayesian Choice," Springer-Verlag, New York, 1994, +% p. 381. +% +% November 1998 by Tao Zha +% rewritten by CAS 12/98 to take matrix x, return vector y + +[p,nx]=size(x); +z = C\(x-xm); + +if constIx + dSh=sum(log(diag(C))); % (detSigma)^(1/2) + y = exp(-dSh-sum(z.*z,1)/2) / ((2*pi)^(p/2)); + y = y'; +else + y = exp(-sum(z.*z,1)/2); + y = y'; +end diff --git a/MatlabFiles/mtpdf.m b/MatlabFiles/mtpdf.m new file mode 100755 index 0000000..1b3dee0 --- /dev/null +++ b/MatlabFiles/mtpdf.m @@ -0,0 +1,32 @@ +function y = mtpdf(x,xm,C,v,constIx) +% y = mtpdf(x,xm,C,v) +% The pdf value for multivariate Student t distribution +% +% x: p-by-draws matrix of values evaluated at where p=size(x,1) is # of variables +% xm: p-by-draws matrix of the mean of x +% C: p-by-p Choleski square root of PDS S, which is the covariance matrix +% in the normal case so that S = C*C' +% v (>0): scaler -- the degrees of freedom +% constIx: index for the constant. 1: constant (normalized); 0: no constant (unnormalized) +%---------- +% y: p-by-draws matrix of pdf's for multivariate Student t distribution with v degrees of freedom +% +% Christian P. Robert, "The Bayesian Choice," Springer-Verlag, New York, 1994, +% p. 382. +% +% December 1998 by Tao Zha + +[p,nx]=size(x); +z = C\(x-xm); + + +if constIx + dSh=sum(log(diag(C))); % (detSigma)^(1/2) + %* Use gammaln function to avoid overflows. + term = exp(gammaln((v + p) / 2) - gammaln(v/2) - dSh); + y = (term*(v*pi)^(-p/2)) * (1 + sum(z.*z,1)/v).^(-(v + p)/2); + y = y'; +else + y = (1 + sum(z.*z,1)/v).^(-(v + p)/2); + y = y'; +end diff --git a/MatlabFiles/nmlzvar.m b/MatlabFiles/nmlzvar.m new file mode 100755 index 0000000..b591a70 --- /dev/null +++ b/MatlabFiles/nmlzvar.m @@ -0,0 +1,105 @@ +function [A0n,nswitch,A0inn] = nmlzvar(A0u,A0xhat,A0inxhat,IndxNmlr,nswitch,A0inu) +% [A0n,nswitch,A0inn] = nmlzvar(A0u,A0xhat,A0inxhat,IndxNmlr,nswitch,A0inu) +% Export normalized new draw A0 (and inv(A0) only if IndxNmlr(5)) and the number of sign switches +% Ref.: D.F. Waggoner and T.A. Zha: "Does Normalization Matter for Inference?" +% See Note Forecast (2) pp. 52-53 +% +% A0u: unnormalized A0; column--equation +% A0xhat: ML estimate or posterior mode of A0 +% A0inxhat: inv(A0xhat) +% IndxNmlr: index for which normalization rule to choose +% Only one of the elments in IndxNmlr can be non-zero +% IndxNmlr(1): ML A distance rule (supposed to be the best) +% IndxNmlr(2): ML Ahat distance rule (to approximate IndxNmlr(1)) +% IndxNmlr(3): ML Euclidean distance rule (not invariant to scale) +% IndxNmlr(4): Positive diagonal rule +% IndxNmlr(5): Positive inv(A) diagonal rule (if ~IndxNmlr(5), no need for A0inu, +% so we set A0inn=[]) +% Or Euclidean distance rule for A0inv (not invariant to scale) +% IndxNmlr(6): Assigned postive rule (such as off-diagonal elements). Added 1/3/00 +% nswitch: # of sign switches +% A0inu: unnormalized inv(A0); used only if IndxNmlr(5) +%----------------- +% A0n: normalized new A0; column--equation +% nswitch: updated # of sign switches +% A0inn: normalized inv(A0); used only if IndxNmlr(5) +% +% Written by Tao Zha +% 1/3/00: added IndxNmlr(6) so that previous programs may not be compatible. + + + +A0inn = []; % no output for normalized A0in unless IndxNmlr(5) + +if (length(find(IndxNmlr))>1) + warning('You cannot choose more than one normalization rule at a time') + disp('Press ctrl-c to abort') + pause +elseif isempty(find(IndxNmlr)) % no normalization + A0n=A0u; nswitch=0; +elseif IndxNmlr(1) + a0dpindx = find(diag(A0u\A0xhat)<0); + A0n = A0u; + if ~isempty(a0dpindx) + A0n(:,a0dpindx) = -A0u(:,a0dpindx); % normalized new draws + nswitch = nswitch + 1; %<<>> # of sign switches + end +elseif IndxNmlr(2) + a0dpindx = find(diag(A0inxhat*A0u)<0); + A0n = A0u; + if ~isempty(a0dpindx) + A0n(:,a0dpindx) = -A0u(:,a0dpindx); % normalized new draws + nswitch = nswitch + 1; %<<>> # of sign switches + end +elseif IndxNmlr(3) + Adiff = (A0u - A0xhat).^2; % distance that may be far from axhat or A0xhat + Adiffn = (-A0u - A0xhat).^2; % distance by chaning the sign of Atem + cAdiff = sum(Adiff); % each column summed up + cAdiffn = sum(Adiffn); % each column summed up + cAindx = find(cAdiffn<cAdiff); % index for shorter distance + A0n = A0u; + if ~isempty(cAindx) + A0n(:,cAindx) = -A0u(:,cAindx); % find the shortest or nearest distance + nswitch = nswitch + 1; %<<>> # of sign switches + end +elseif IndxNmlr(4) + a0dpindx = find(diag(A0u)<0); + A0n = A0u; + if ~isempty(a0dpindx) + A0n(:,a0dpindx) = -A0u(:,a0dpindx); % normalized new draws + nswitch = nswitch + 1; %<<>> # of sign switches + end +elseif IndxNmlr(5) + if (0) + a0dpindx = find(diag(A0inu)<0); + A0n = A0u; + A0inn = A0inu; + if ~isempty(a0dpindx) + A0n(:,a0dpindx) = -A0u(:,a0dpindx); + A0inn(a0dpindx,:) = -A0inu(a0dpindx,:); + nswitch = nswitch + 1; %<<>> # of sign switches + end + else + A0n = []; + Aindiff = (A0inu - A0inxhat).^2; % distance that may be far from A0inxhat + Aindiffn = (-A0inu - A0inxhat).^2; % distance by chaning the sign of A0inu + cAindiff = sum(Aindiff,2); % each row summed up + cAindiffn = sum(Aindiffn, 2); % each row summed up + cAinindx = find(cAindiffn<cAindiff); % index for shorter distance + A0inn = A0inu; + if ~isempty(cAinindx) + A0inn(:,cAinindx) = -A0inu(:,cAinindx); % find the shortest or nearest distance + nswitch = nswitch + 1; %<<>> # of sign switches + end + end +elseif IndxNmlr(6) %*** This one has to be MANUALLY handled + [jnk,nvar]=size(A0u); + A0dummy=A0u; + A0dummy(:,1:2)=-A0u(:,1:2); % keep it to a sign that coincide with Brooking paper + a0dpindx = find(A0dummy(nvar,:)<0); % the last row + A0n = A0u; + if ~isempty(a0dpindx) + A0n(:,a0dpindx) = -A0u(:,a0dpindx); % normalized new draws + nswitch = nswitch + 1; %<<>> # of sign switches + end +end diff --git a/MatlabFiles/normpar.m b/MatlabFiles/normpar.m new file mode 100755 index 0000000..7e22857 --- /dev/null +++ b/MatlabFiles/normpar.m @@ -0,0 +1,12 @@ +function f = normpar(ab, XLO, XUP, PLO, PUP); + +% The function takes as inputs the parameters ab=[a, b] of the Normal +% distribution (a = mean, b = standard deviation), the bounds of the +% support [XLO, XUP], the the corresponding probabilities of the bounds +% [PLO, PUP] and returns the residual value f. + +a = ab(1); b = abs(ab(2)); +f1 = PLO - normcdf(XLO, a, b); +f2 = PUP - normcdf(XUP, a, b); + +f = [f1, f2]; diff --git a/MatlabFiles/nqzdiv.m b/MatlabFiles/nqzdiv.m new file mode 100755 index 0000000..e1d505f --- /dev/null +++ b/MatlabFiles/nqzdiv.m @@ -0,0 +1,44 @@ +function [A,B,P,R] = nqzdiv(stake,A,B,V,P) +%function [A,B,Q,Z] = nqzdiv(stake,A,B,V,P) +% +% Takes U.T. matrices A, B, V, and P and rearranges them +% so that all cases of abs(B(i,i)/A(i,i))>stake are in lower right +% corner, while the output A and B are diagonal, and P*A*R=G0, P*B*R=G1. +% Note: the input A and B are U.T.; the output A and B are diagonal. +% +% Modified by T.Zha, 5/26/97 + +[n jnk] = size(A); + +ald = diag(diag(A)); % d: diagoanl +bed = diag(diag(B)); +R = inv(V); + +root = abs([diag(ald) diag(bed)]); +root(:,1) = root(:,1)-(root(:,1)<1.e-13).*(root(:,1)+root(:,2)); +root(:,2) = root(:,2)./root(:,1); +for i = n:-1:1 + m=0; + for j=i:-1:1 + if (root(j,2) > stake | root(j,2) < -.1) + m=j; + break + end + end + if (m==0) + return + elseif (m<i-1) + pindx = 1:n; % T.Z., 5/26/97 + pindx(m)=i-1; + pindx(i-1)=m; + %*** permutation begins + ald = ald(pindx,pindx); + bed = bed(pindx,pindx); + P = P(:,pindx); % column permutation, T.Z., 5/26/97 + R = R(pindx,:); % row permutation + end +end + +%*** return the new Q, Z, A, B +A = diag(1./diag(bed)); +B = diag(1./diag(ald)); \ No newline at end of file diff --git a/MatlabFiles/numgrad.m b/MatlabFiles/numgrad.m new file mode 100755 index 0000000..1a03798 --- /dev/null +++ b/MatlabFiles/numgrad.m @@ -0,0 +1,86 @@ +function [grdd, badg] = numgrad(fcn,x0,varargin) +%function grdd = fn_gradcd(fcn,x0,varargin) +% computes numerical gradient of a single-valued function or Jacobian +% matrix of a vector-valued function using a central difference with +% function grdd = gradcd(fcn,x0,grdh) +% +% fcn: a string naming a vector-valued function (f:n-by-1 -> k-by-1). +% x0: a column vector n-by-1, at which point the hessian is evaluated. +% grdh: step size, n*1. Set as follows +% step = eps^(1/3); +% %step = 1e-04; +% grdh = step * (max([abs(x) ones(length(x),1)]'))' .* (abs(x) ./ x); +%-------------------- +% grdd: n-by-k Jacobian matrix (gradients). +% +% Written by Tao Zha, 2002. + + +stps = eps^(1/3); +% eps: floating point relative accuracy or machine precision: 2.22e-16 +% stps: step size recommended by Dennis and Schnabel: 6.006e-6 + +x0 = x0(:); +%tailstr = ')'; +%for i=nargin-3:-1:1 +% tailstr=[ ',P' num2str(i) tailstr]; +%end +f0 = eval([fcn '(x0,varargin{:})']); +%f0 = eval([fcn '(x0' tailstr]); + +% ** initializations +n = length(x0); +k = length(f0); % dimension of "fcn" + +% ** Computation of stepsize (dh) +if (0) + dh = 1.0e-06; %grdh; +else + ax0 = abs(x0); + if all(x0) + dax0 = x0 ./ ax0; + else + dax0 = 1; + end + dh = stps * (max([ax0 ones(n,1)]'))' .* dax0; +end + +xdh = x0 + dh; +dh = xdh - x0; % This increases precision slightly +% +argplus = x0(:,ones(n,1)); +argminus = argplus; +dnum = 1:n+1:n^2; % positions of diagonals in vec(argplus). +argplus(dnum) = xdh; % replace the diagonals of "argplus" by "xdh". +argminus(dnum) = x0-dh; % replace the diagonals of "argplus" by "xdh". + +grdd = zeros(k,n); % preallocate to speed the loop. +badg=0; +i = 0; +while i ~= n + i = i+1; + fp = eval([fcn '(argplus(:,i),varargin{:})']); + fm = eval([fcn '(argminus(:,i),varargin{:})']); +% fp = eval([fcn '(argplus(:,i)' tailstr]); +% fm = eval([fcn '(argminus(:,i)' tailstr]); + g0 = fp - fm; + + if abs(g0)< 1e15 + grdd(:,i)=g0; + % disp('good gradient') + else + disp('bad gradient ------------------------') + % fprintf('Gradient w.r.t. %3d: %10g\n',i,g0) %see above + grdd(:,i)=0; + badg=1; + % return + % can return here to save time if the gradient will never be + % used when badg returns as true. + end + +end +dhm = dh(:,ones(k,1)); +dhm = dhm'; % k*n +grdd = grdd ./ (2*dhm); % k-by-n. +grdd = grdd'; % n-by-k. + diff --git a/MatlabFiles/numgradOrig.m b/MatlabFiles/numgradOrig.m new file mode 100755 index 0000000..36fb0b1 --- /dev/null +++ b/MatlabFiles/numgradOrig.m @@ -0,0 +1,99 @@ +function [g, badg] = numgrad(fcn,x,varargin) +% function [g badg] = numgrad(fcn,xvarargin) +% +delta = 1e-6; % works for a general case +%delta = 1e-2; % bigger step -- works for a flat peak +%delta=1e-04; + +n=length(x); +tvec=delta*eye(n); +g=zeros(n,1); +%--------------------old way to deal with variable # of P's-------------- +%tailstr = ')'; +%stailstr = []; +%for i=nargin-2:-1:1 +% tailstr=[ ',P' num2str(i) tailstr]; +% stailstr=[' P' num2str(i) stailstr]; +%end +%f0 = eval([fcn '(x' tailstr]); % Is there a way not to do this? +%---------------------------------------------------------------^yes +f0 = eval([fcn '(x,varargin{:})']); +% disp(' first fcn in numgrad.m ------------------') +%home +% disp('numgrad.m is working. ----') % Jiinil on 9/5/95 +% sizex=size(x),sizetvec=size(tvec),x, % Jinill on 9/6/95 +badg=0; +for i=1:n + scale=1; % originally 1 + % i,tveci=tvec(:,i)% ,plus=x+scale*tvec(:,i) % Jinill Kim on 9/6/95 + if size(x,1)>size(x,2) + tvecv=tvec(i,:); + else + tvecv=tvec(:,i); + end + g0 = (eval([fcn '(x+scale*tvecv'', varargin{:})']) - f0) ... + /(scale*delta); + % disp(' fcn in the i=1:n loop of numgrad.m ------------------')% Jinill 9/6/95 + % disp(' and i is') % Jinill + % i % Jinill + % fprintf('Gradient w.r.t. %3d: %10g\n',i,g0) %see below Jinill 9/6/95 +% -------------------------- special code to essentially quit here + % absg0=abs(g0) % Jinill on 9/6/95 + if abs(g0)< 1e15 + g(i)=g0; + % disp('good gradient') % Jinill Kim + else + disp('bad gradient ------------------------') % Jinill Kim + % fprintf('Gradient w.r.t. %3d: %10g\n',i,g0) %see above + g(i)=0; + badg=1; + % return + % can return here to save time if the gradient will never be + % used when badg returns as true. + end +end +%------------------------------------------------------------- +% if g0 > 0 +% sided=2; +% g1 = -(eval([fcn '(x-scale*tvec(:,i)''' tailstr]) - f0) ... +% /(scale*delta); +% if g1<0 +% scale = scale/10; +% else +% break +% end +% else +% sided=1; +% break +% end +% end +% if sided==1 +% g(i)=g0; +% else +% if (g0<1e20) +% if (g1>-1e20) +% g(i)=(g0+g1)/2; +% else +% g(i)=0; +% badg=1; +% disp( ['Banging against wall, parameter ' int2str(i)] ); +% end +% else +% if g1>-1e20 +% if g1<0 +% g(i)=0; +% badg=1; +% disp( ['Banging against wall, parameter ' int2str(i)] ); +% else +% g(i)=g1; +% end +% else +% g(i)=0; +% badg=1; +% disp(['Valley around parameter ' int2str(i)]) +% end +% end +% end +%end +%save g.dat g x f0 +%eval(['save g g x f0 ' stailstr]); diff --git a/MatlabFiles/numgradcd.m b/MatlabFiles/numgradcd.m new file mode 100755 index 0000000..a7b6439 --- /dev/null +++ b/MatlabFiles/numgradcd.m @@ -0,0 +1,87 @@ +function [grdd, badg] = numgradcd(fcn,x0,varargin) +%function grdd = fn_gradcd(fcn,x0,varargin) +% computes numerical gradient of a single-valued function or Jacobian +% matrix of a vector-valued function using a central difference with +% function grdd = gradcd(fcn,x0,grdh) +% +% fcn: a string naming a vector-valued function (f:n-by-1 -> k-by-1). +% x0: a column vector n-by-1, at which point the hessian is evaluated. +% grdh: step size, n*1. Set as follows +% step = eps^(1/3); +% %step = 1e-04; +% grdh = step * (max([abs(x) ones(length(x),1)]'))' .* (abs(x) ./ x); +%-------------------- +% grdd: n-by-k Jacobian matrix (gradients). +% +% Written by Tao Zha, 2002. + + +stps = eps^(1/3); +%stps = 1.0e-02; +% eps: floating point relative accuracy or machine precision: 2.22e-16 +% stps: step size recommended by Dennis and Schnabel: 6.006e-6 + +x0 = x0(:); +%tailstr = ')'; +%for i=nargin-3:-1:1 +% tailstr=[ ',P' num2str(i) tailstr]; +%end +f0 = eval([fcn '(x0,varargin{:})']); +%f0 = eval([fcn '(x0' tailstr]); + +% ** initializations +n = length(x0); +k = length(f0); % dimension of "fcn" + +% ** Computation of stepsize (dh) +if (0) + dh = 1.0e-06; %grdh; +else + ax0 = abs(x0); + if all(x0) + dax0 = x0 ./ ax0; + else + dax0 = 1; + end + dh = stps * (max([ax0 ones(n,1)]'))' .* dax0; +end + +xdh = x0 + dh; +dh = xdh - x0; % This increases precision slightly +% +argplus = x0(:,ones(n,1)); +argminus = argplus; +dnum = 1:n+1:n^2; % positions of diagonals in vec(argplus). +argplus(dnum) = xdh; % replace the diagonals of "argplus" by "xdh". +argminus(dnum) = x0-dh; % replace the diagonals of "argplus" by "xdh". + +grdd = zeros(k,n); % preallocate to speed the loop. +badg=0; +i = 0; +while i ~= n + i = i+1; + fp = eval([fcn '(argplus(:,i),varargin{:})']); + fm = eval([fcn '(argminus(:,i),varargin{:})']); +% fp = eval([fcn '(argplus(:,i)' tailstr]); +% fm = eval([fcn '(argminus(:,i)' tailstr]); + g0 = fp - fm; + + if abs(g0)< 1e15 + grdd(:,i)=g0; + % disp('good gradient') + else + disp('bad gradient ------------------------') + % fprintf('Gradient w.r.t. %3d: %10g\n',i,g0) %see above + grdd(:,i)=0; + badg=1; + % return + % can return here to save time if the gradient will never be + % used when badg returns as true. + end + +end +dhm = dh(:,ones(k,1)); +dhm = dhm'; % k*n +grdd = grdd ./ (2*dhm); % k-by-n. +grdd = grdd'; % n-by-k. + diff --git a/MatlabFiles/ols.m b/MatlabFiles/ols.m new file mode 100755 index 0000000..a265d58 --- /dev/null +++ b/MatlabFiles/ols.m @@ -0,0 +1,28 @@ +function [Bh,e,xtx,xty] = ols(y,phi) +% ols: estimate a system of equations: [Bh,e,xtx,xty] = ols(y,phi) +% Y(T*nvar) = XB + u, X: T*k, B: k*nvar. +% where Bh: the estimated B; column: nvar; row: number of r.h.s. variables. +% e: estimated residual e = y -xBh, T*nvar +% xtx: X'X: k-by-k +% xty: X'Y: k-by-nvar +% phi: X; T-by-k; column: number of r.h.s. variables (including +% deterministic terms) +% y: Y: T-by-nvar +% +% See also sye.m and syed.m + +% ** setup of orders and lengths ** +[u d v]=svd(phi,0); %trial +%xtx = phi'*phi; % X'X, k*k (ncoe*ncoe) +vd=v.*(ones(size(v,2),1)*diag(d)'); %trial +dinv = 1./diag(d); % inv(diag(d)) +vdinv=v.*(ones(size(v,2),1)*dinv'); %trial +xtx=vd*vd'; +xtxinv = vdinv*vdinv'; +%xty = phi'*y; % X'Y +uy = u'*y; %trial +xty = vd*uy; %trial +%Bh = xtx\xty; %inv(X'X)*(X'Y), k*m (ncoe*nvar). +Bh = xtxinv*xty; +%e = y - phi*Bh; % from Y = XB + U, e: (T-lags)*nvar +e = y - u*uy; \ No newline at end of file diff --git a/MatlabFiles/pathdef.m b/MatlabFiles/pathdef.m new file mode 100644 index 0000000..7dd3196 --- /dev/null +++ b/MatlabFiles/pathdef.m @@ -0,0 +1,247 @@ +function p = pathdef +%PATHDEF Search path defaults. +% PATHDEF returns a string that can be used as input to MATLABPATH +% in order to set the path. + + +% Copyright 1984-2007 The MathWorks, Inc. +% $Revision: 1.4.2.2 $ $Date: 2007/06/07 14:45:14 $ + + +% DO NOT MODIFY THIS FILE. IT IS AN AUTOGENERATED FILE. +% EDITING MAY CAUSE THE FILE TO BECOME UNREADABLE TO +% THE PATHTOOL AND THE INSTALLER. + +p = [... +%%% BEGIN ENTRIES %%% + '/Users/tzha/ZhaData/TZCcode/cstz:', ... + matlabroot,'/toolbox/matlab/general:', ... + matlabroot,'/toolbox/matlab/ops:', ... + matlabroot,'/toolbox/matlab/lang:', ... + matlabroot,'/toolbox/matlab/elmat:', ... + matlabroot,'/toolbox/matlab/randfun:', ... + matlabroot,'/toolbox/matlab/elfun:', ... + matlabroot,'/toolbox/matlab/specfun:', ... + matlabroot,'/toolbox/matlab/matfun:', ... + matlabroot,'/toolbox/matlab/datafun:', ... + matlabroot,'/toolbox/matlab/polyfun:', ... + matlabroot,'/toolbox/matlab/funfun:', ... + matlabroot,'/toolbox/matlab/sparfun:', ... + matlabroot,'/toolbox/matlab/scribe:', ... + matlabroot,'/toolbox/matlab/graph2d:', ... + matlabroot,'/toolbox/matlab/graph3d:', ... + matlabroot,'/toolbox/matlab/specgraph:', ... + matlabroot,'/toolbox/matlab/graphics:', ... + matlabroot,'/toolbox/matlab/uitools:', ... + matlabroot,'/toolbox/matlab/strfun:', ... + matlabroot,'/toolbox/matlab/imagesci:', ... + matlabroot,'/toolbox/matlab/iofun:', ... + matlabroot,'/toolbox/matlab/audiovideo:', ... + matlabroot,'/toolbox/matlab/timefun:', ... + matlabroot,'/toolbox/matlab/datatypes:', ... + matlabroot,'/toolbox/matlab/verctrl:', ... + matlabroot,'/toolbox/matlab/codetools:', ... + matlabroot,'/toolbox/matlab/helptools:', ... + matlabroot,'/toolbox/matlab/demos:', ... + matlabroot,'/toolbox/matlab/timeseries:', ... + matlabroot,'/toolbox/matlab/hds:', ... + matlabroot,'/toolbox/matlab/guide:', ... + matlabroot,'/toolbox/matlab/plottools:', ... + matlabroot,'/toolbox/local:', ... + matlabroot,'/toolbox/shared/controllib:', ... + matlabroot,'/toolbox/shared/dastudio:', ... + matlabroot,'/toolbox/matlab/datamanager:', ... + matlabroot,'/toolbox/simulink/simulink:', ... + matlabroot,'/toolbox/simulink/simulink/slresolve:', ... + matlabroot,'/toolbox/simulink/blocks:', ... + matlabroot,'/toolbox/simulink/components:', ... + matlabroot,'/toolbox/simulink/fixedandfloat:', ... + matlabroot,'/toolbox/simulink/fixedandfloat/fxpdemos:', ... + matlabroot,'/toolbox/simulink/fixedandfloat/obsolete:', ... + matlabroot,'/toolbox/simulink/simdemos:', ... + matlabroot,'/toolbox/simulink/simdemos/aerospace:', ... + matlabroot,'/toolbox/simulink/simdemos/automotive:', ... + matlabroot,'/toolbox/simulink/simdemos/simfeatures:', ... + matlabroot,'/toolbox/simulink/simdemos/simgeneral:', ... + matlabroot,'/toolbox/simulink/dee:', ... + matlabroot,'/toolbox/shared/dastudio/depviewer:', ... + matlabroot,'/toolbox/stateflow/stateflow:', ... + matlabroot,'/toolbox/rtw/rtw:', ... + matlabroot,'/toolbox/shared/sigbldr:', ... + matlabroot,'/toolbox/simulink/simulink/modeladvisor:', ... + matlabroot,'/toolbox/simulink/simulink/modeladvisor/fixpt:', ... + matlabroot,'/toolbox/simulink/simulink/MPlayIO:', ... + matlabroot,'/toolbox/simulink/simulink/dataobjectwizard:', ... + matlabroot,'/toolbox/shared/hdlshared:', ... + matlabroot,'/toolbox/rtw/accel:', ... + matlabroot,'/toolbox/rtw/rtwdemos:', ... + matlabroot,'/toolbox/rtw/rtwdemos/rsimdemos:', ... + matlabroot,'/toolbox/rtw/targets/asap2/asap2:', ... + matlabroot,'/toolbox/rtw/targets/asap2/asap2/user:', ... + matlabroot,'/toolbox/rtw/targets/common/can/blocks:', ... + matlabroot,'/toolbox/rtw/targets/common/configuration/resource:', ... + matlabroot,'/toolbox/rtw/targets/common/tgtcommon:', ... + matlabroot,'/toolbox/rtw/targets/connectivity:', ... + matlabroot,'/toolbox/rtw/targets/pil:', ... + matlabroot,'/toolbox/rtw/rtw/datadiff/GUI:', ... + matlabroot,'/toolbox/rtw/rtw/datadiff/GUI/Icons:', ... + matlabroot,'/toolbox/rtw/rtw/datadiff/API:', ... + matlabroot,'/toolbox/rtw/rtw/cgv/API:', ... + matlabroot,'/toolbox/stateflow/sfdemos:', ... + matlabroot,'/toolbox/stateflow/coder:', ... + matlabroot,'/toolbox/bioinfo/bioinfo:', ... + matlabroot,'/toolbox/bioinfo/biolearning:', ... + matlabroot,'/toolbox/bioinfo/microarray:', ... + matlabroot,'/toolbox/bioinfo/mass_spec:', ... + matlabroot,'/toolbox/bioinfo/proteins:', ... + matlabroot,'/toolbox/bioinfo/biomatrices:', ... + matlabroot,'/toolbox/bioinfo/biodemos:', ... + matlabroot,'/toolbox/bioinfo/graphtheory:', ... + matlabroot,'/toolbox/compiler:', ... + matlabroot,'/toolbox/control/control:', ... + matlabroot,'/toolbox/control/ctrlguis:', ... + matlabroot,'/toolbox/control/ctrlobsolete:', ... + matlabroot,'/toolbox/control/ctrlutil:', ... + matlabroot,'/toolbox/control/ctrldemos:', ... + matlabroot,'/toolbox/shared/slcontrollib:', ... + matlabroot,'/toolbox/curvefit/curvefit:', ... + matlabroot,'/toolbox/curvefit/cftoolgui:', ... + matlabroot,'/toolbox/curvefit/sftoolgui:', ... + matlabroot,'/toolbox/shared/optimlib:', ... + matlabroot,'/toolbox/database/database:', ... + matlabroot,'/toolbox/database/dbdemos:', ... + matlabroot,'/toolbox/database/vqb:', ... + matlabroot,'/toolbox/datafeed/datafeed:', ... + matlabroot,'/toolbox/datafeed/dfgui:', ... + matlabroot,'/toolbox/distcomp:', ... + matlabroot,'/toolbox/distcomp/distcomp:', ... + matlabroot,'/toolbox/distcomp/user:', ... + matlabroot,'/toolbox/distcomp/mpi:', ... + matlabroot,'/toolbox/distcomp/pctdemos:', ... + matlabroot,'/toolbox/distcomp/parallel:', ... + matlabroot,'/toolbox/distcomp/parallel/datafun:', ... + matlabroot,'/toolbox/distcomp/parallel/datatypes:', ... + matlabroot,'/toolbox/distcomp/parallel/elfun:', ... + matlabroot,'/toolbox/distcomp/parallel/elmat:', ... + matlabroot,'/toolbox/distcomp/parallel/lapack:', ... + matlabroot,'/toolbox/distcomp/parallel/matfun:', ... + matlabroot,'/toolbox/distcomp/parallel/ops:', ... + matlabroot,'/toolbox/distcomp/parallel/sparfun:', ... + matlabroot,'/toolbox/distcomp/parallel/specfun:', ... + matlabroot,'/toolbox/distcomp/parallel/util:', ... + matlabroot,'/toolbox/distcomp/lang:', ... + matlabroot,'/toolbox/dspblks/dspblks:', ... + matlabroot,'/toolbox/dspblks/dspmasks:', ... + matlabroot,'/toolbox/dspblks/dspmex:', ... + matlabroot,'/toolbox/dspblks/dspdemos:', ... + matlabroot,'/toolbox/shared/filterdesignlib:', ... + matlabroot,'/help/toolbox/dspblks/examples:', ... + matlabroot,'/toolbox/econ/econ:', ... + matlabroot,'/toolbox/econ/econdemos:', ... + matlabroot,'/toolbox/eml/eml:', ... + matlabroot,'/toolbox/emlcoder/emlcoder:', ... + matlabroot,'/toolbox/emlcoder/emlcodermex:', ... + matlabroot,'/toolbox/shared/simtargets:', ... + matlabroot,'/toolbox/finance/finance:', ... + matlabroot,'/toolbox/finance/calendar:', ... + matlabroot,'/toolbox/finance/findemos:', ... + matlabroot,'/toolbox/finance/finsupport:', ... + matlabroot,'/toolbox/finance/ftseries:', ... + matlabroot,'/toolbox/fixedpoint/fixedpoint:', ... + matlabroot,'/toolbox/fixedpoint/fidemos:', ... + matlabroot,'/toolbox/fixedpoint/fixedpointtool:', ... + matlabroot,'/toolbox/gads:', ... + matlabroot,'/toolbox/gads/gads:', ... + matlabroot,'/toolbox/gads/gadsdemos:', ... + matlabroot,'/toolbox/ident/ident:', ... + matlabroot,'/toolbox/ident/nlident:', ... + matlabroot,'/toolbox/ident/idobsolete:', ... + matlabroot,'/toolbox/ident/idguis:', ... + matlabroot,'/toolbox/ident/idutils:', ... + matlabroot,'/toolbox/ident/iddemos:', ... + matlabroot,'/toolbox/ident/iddemos/examples:', ... + matlabroot,'/toolbox/ident/idhelp:', ... + matlabroot,'/toolbox/images/colorspaces:', ... + matlabroot,'/toolbox/images/images:', ... + matlabroot,'/toolbox/images/imdemos:', ... + matlabroot,'/toolbox/images/imuitools:', ... + matlabroot,'/toolbox/images/iptformats:', ... + matlabroot,'/toolbox/images/iptutils:', ... + matlabroot,'/toolbox/shared/imageslib:', ... + matlabroot,'/toolbox/shared/spcuilib:', ... + matlabroot,'/toolbox/instrument/instrument:', ... + matlabroot,'/toolbox/instrument/instrumentdemos:', ... + matlabroot,'/toolbox/instrument/instrumentblks/instrumentblks:', ... + matlabroot,'/toolbox/instrument/instrumentblks/instrumentmex:', ... + matlabroot,'/toolbox/instrument/instrumentblks/instrumentmasks:', ... + matlabroot,'/toolbox/shared/testmeaslib:', ... + matlabroot,'/toolbox/slvnv/simcoverage:', ... + matlabroot,'/toolbox/nnet:', ... + matlabroot,'/toolbox/nnet/nncontrol:', ... + matlabroot,'/toolbox/nnet/nndemos:', ... + matlabroot,'/toolbox/nnet/nnet:', ... + matlabroot,'/toolbox/nnet/nnet/nnanalyze:', ... + matlabroot,'/toolbox/nnet/nnet/nncustom:', ... + matlabroot,'/toolbox/nnet/nnet/nndistance:', ... + matlabroot,'/toolbox/nnet/nnet/nnformat:', ... + matlabroot,'/toolbox/nnet/nnet/nninit:', ... + matlabroot,'/toolbox/nnet/nnet/nnlearn:', ... + matlabroot,'/toolbox/nnet/nnet/nnnetinput:', ... + matlabroot,'/toolbox/nnet/nnet/nnnetwork:', ... + matlabroot,'/toolbox/nnet/nnet/nnperformance:', ... + matlabroot,'/toolbox/nnet/nnet/nnplot:', ... + matlabroot,'/toolbox/nnet/nnet/nnprocess:', ... + matlabroot,'/toolbox/nnet/nnet/nnsearch:', ... + matlabroot,'/toolbox/nnet/nnet/nntopology:', ... + matlabroot,'/toolbox/nnet/nnet/nntrain:', ... + matlabroot,'/toolbox/nnet/nnet/nntransfer:', ... + matlabroot,'/toolbox/nnet/nnet/nnweight:', ... + matlabroot,'/toolbox/nnet/nnguis:', ... + matlabroot,'/toolbox/nnet/nnguis/nftool:', ... + matlabroot,'/toolbox/nnet/nnguis/nntool:', ... + matlabroot,'/toolbox/nnet/nnobsolete:', ... + matlabroot,'/toolbox/nnet/nnresource:', ... + matlabroot,'/toolbox/nnet/nnutils:', ... + matlabroot,'/toolbox/nnet/nnguis/nnguiutils:', ... + matlabroot,'/toolbox/nnet/nndemos/nndatasets:', ... + matlabroot,'/toolbox/nnet/nnguis/nntraintool:', ... + matlabroot,'/toolbox/optim/optim:', ... + matlabroot,'/toolbox/optim/optimdemos:', ... + matlabroot,'/toolbox/pde:', ... + matlabroot,'/toolbox/physmod/data_manager/data_manager:', ... + matlabroot,'/toolbox/physmod/equation_language/equation_language:', ... + matlabroot,'/toolbox/physmod/foundation/foundation:', ... + matlabroot,'/toolbox/physmod/mech/importer:', ... + matlabroot,'/toolbox/physmod/mech/mech:', ... + matlabroot,'/toolbox/physmod/mech/mechdemos:', ... + matlabroot,'/toolbox/physmod/network_engine/ne_sli:', ... + matlabroot,'/toolbox/physmod/network_engine/ne_support:', ... + matlabroot,'/toolbox/physmod/network_engine/network_engine:', ... + matlabroot,'/toolbox/physmod/pm_sli/pm_sli:', ... + matlabroot,'/toolbox/physmod/pm_visimpl/pm_visimpl:', ... + matlabroot,'/toolbox/physmod/pmir/pmir:', ... + matlabroot,'/toolbox/physmod/simscape/simscape:', ... + matlabroot,'/toolbox/physmod/simscape/simscapedemos:', ... + matlabroot,'/toolbox/physmod/simscape_language/simscape_language:', ... + matlabroot,'/toolbox/physmod/unit_manager/unit_manager:', ... + matlabroot,'/toolbox/signal/signal:', ... + matlabroot,'/toolbox/signal/sigtools:', ... + matlabroot,'/toolbox/signal/sptoolgui:', ... + matlabroot,'/toolbox/signal/sigdemos:', ... + matlabroot,'/toolbox/shared/siglib:', ... + matlabroot,'/toolbox/sl3d/sl3d:', ... + matlabroot,'/toolbox/sl3d/sl3ddemos:', ... + matlabroot,'/toolbox/shared/sldv:', ... + matlabroot,'/toolbox/splines:', ... + matlabroot,'/toolbox/stats:', ... + matlabroot,'/toolbox/shared/statslib:', ... + matlabroot,'/toolbox/symbolic:', ... + matlabroot,'/toolbox/wavelet/wavelet:', ... + matlabroot,'/toolbox/wavelet/wmultisig1d:', ... + matlabroot,'/toolbox/wavelet/wavedemo:', ... + matlabroot,'/toolbox/wavelet/compression:', ... +%%% END ENTRIES %%% + ... +]; + +p = [userpath,p]; diff --git a/MatlabFiles/pdfforg.m b/MatlabFiles/pdfforg.m new file mode 100755 index 0000000..6efa249 --- /dev/null +++ b/MatlabFiles/pdfforg.m @@ -0,0 +1,37 @@ +function [imfpdf,imfpo,imfprob] = pdfforg(imfcnt,imndraws,forep,nvar,ninv,invc,Am) +% [imfpdf,imfpo,imfprob] = pdfforg(imfcnt,imndraws,forep,nvar,ninv,invc,Am) +% +% Produce the dataset for generating p.d.f. and export the dataset for +% probability (NOT density) at each bin +% +% imfcnt: 2+ninv-by-forep*nvar. Counted logcnt, yhatqgcnt, or yhatCalygcnt. +% In the case of impulse responses, forep=imstp and nvar=nvar^2 +% ninv: the number of small interior intervals for sorting. +% invc: 1-by-forep*nvar. Whole inverval lenghth from min to max for one of +% (yhat, yhatqg, or yhatCalyg) +% Am: 1-by-forep*nvar. Range5{i}(:,:,1) is lowest range for for one of +% (yhat, yhatqg, or yhatCalyg) +%----------------- +% imfpdf: 2+ninv-by-forep*nvar. Density +% imfpo: 2+ninv-by-forep*nvar. Bin position (x-axis) in relation to imfs3 +% imfprob: 2+ninv-by-forep*nvar. Probability (NOT density) at each bin +% +% 27 August 1998 Tao Zha +% Revised, October 1998 + +invlength = invc ./ ninv; +invlengthM = repmat(invlength,[2+ninv,1]); +invlengthM([1 2+ninv],:) = 1; + % first (-inf, low bound) and last (high bound, +inf), the interval is set + % to be 1. Of course, theoretically, the interval length should be set + % to infinity, but 1 is large enough compared with invlength. +imfprob = imfcnt ./ imndraws; % probability (NOT density) +imfpdf = imfprob ./ invlengthM; % density + +imfpo = [1:2+ninv]'; % positions for each forecast +imfpo = imfpo - 2; % the first step to put back to original form +imfpo = repmat(imfpo,[1,forep*nvar]); +invcM = repmat(invc,[2+ninv,1]); +AmM = repmat(Am,[2+ninv,1]); +imfpo = ((imfpo .* invcM) ./ ninv) + AmM; % 2+ninv-by-forep*nvar + % the final step to put back to original form of impulse responses \ No newline at end of file diff --git a/MatlabFiles/perr1graph.m b/MatlabFiles/perr1graph.m new file mode 100755 index 0000000..6333e15 --- /dev/null +++ b/MatlabFiles/perr1graph.m @@ -0,0 +1,116 @@ +function scaleout = perr1graph(imf,firstl1,firsth1,... + nrow,ncol,nstp,xlab,ylab,XTick,YTickIndx,scaleIndx) +% imf: row: "nstp" time horizon (in the graphics), column: "nrow "variables (row in +% the graphics), 3rd D: across "ncol" different situations (column in +% the graphics) +% nrow: # of rows for the graphics +% ncol: # of columns for the graphics +% YTickIndx: 1: enable YTick; 0: disable +% scaleIndx: 1: enable scale along Y-axis; 0: disable +%function scaleout = imc2errgraph(imf,firstl1,firsth1,... +% firstl,firsth,nvar,imstp,xlab,ylab) +% imc2errgraph: impulse, c (column: shock 1 to N), 2 error bands, graph +% imf: impulse responses, column (responses to 1st shock, responses to 2nd shock +% etc), row (impusle steps), +% firstl1: lower band, .68 +% highth1: high band, .68 +% firstl: lower band, .90 +% highth: high band, .90 +% nvar: number of variables +% imstp: step of impulse responses +% xlab,ylab: labels +% +% See imrgraph, imcerrgraph, imrerrgraph +t = 1:nstp; +nrow +ncol + +temp1=zeros(ncol,1); +temp2=zeros(ncol,1); +maxval=zeros(nrow,1); +minval=zeros(nrow,1); +for i = 1:nrow + for j = 1:ncol + %jnk1=max(firsth(:,i,j)); + %jnk2=max(firstl(:,i,j)); + jnk3=max(firsth1(:,i,j)); + jnk4=max(firstl1(:,i,j)); + jnk5=max(imf(:,i,j)); + + temp1(j)=max([jnk3 jnk4 jnk5]); + % + %jnk1=min(firstl(:,i,j)); + %jnk2=min(firsth(:,i,j)); + jnk3=min(firstl1(:,i,j)); + jnk4=min(firsth1(:,i,j)); + jnk5=min(imf(:,i,j)); + + temp2(j)=min([jnk3 jnk4 jnk5]); + end + maxval(i)=max(temp1); + minval(i)=min(temp2); +end + +scaleout = [maxval(:) minval(:)]; + +%-------------- +% Column j: Shock 1 to N; Row i: Responses to +%------------- +figure +rowlabel = 1; +for i = 1:nrow % column: from top to bottom + columnlabel = 1; + + if minval(i)<0 + if maxval(i)<=0 + yt=[minval(i) 0]; + else + yt=[minval(i) 0 maxval(i)]; + end + else % (minval(i) >=0) + if maxval(i) > 0 + yt=[0 maxval(i)]; + else % (identically zero responses) + yt=[-1 0 1]; + end + end + + + scale=[1 nstp minval(i) maxval(i)]; + for j = 1:ncol % row: from left to right + k1=(i-1)*ncol+j; + subplot(nrow,ncol,k1) + plot(t,imf(:,i,j),t,firstl1(:,i,j),'--',t,firsth1(:,i,j),'--') + %t,[firstl(:,i,j) firsth(:,i,j)],':'); + grid; + if scaleIndx + axis(scale); + end + %set(gca,'YLim',[minval(i) maxval(i)]) + % + set(gca,'XTick',XTick) + if YTickIndx + set(gca,'YTick',yt) + end + + if i<nrow + set(gca,'XTickLabelMode','manual','XTickLabel',[]) + end + %set(gca,'XTickLabel',' '); + if j>1 + set(gca,'YTickLabel',' '); + end + if rowlabel == 1 + %title(['x' num2str(j)]) + %title(eval(['x' num2str(j)])) + title(char(xlab(j))) + end + if columnlabel == 1 + %ylabel(['x' num2str(i)]) + %ylabel(eval(['x' num2str(i)])) + ylabel(char(ylab(i))) + end + columnlabel = 0; + end + rowlabel = 0; +end \ No newline at end of file diff --git a/MatlabFiles/perr2graph.m b/MatlabFiles/perr2graph.m new file mode 100755 index 0000000..140e1f9 --- /dev/null +++ b/MatlabFiles/perr2graph.m @@ -0,0 +1,112 @@ +function scaleout = perr2graph(imf,firstl1,firsth1,... + firstl,firsth,nrow,ncol,nstp,xlab,ylab,XTick,YTickIndx,scaleIndx) +% scaleout = perr2graph(imf,firstl1,firsth1,... +% firstl,firsth,nrow,ncol,nstp,xlab,ylab,XTick,YTickIndx,scaleIndx) +% +% imf: nstp-by-nrow-by-ncol +% nrow: # of rows for the graphics (normally variables) +% ncol: # of columns for the graphics (normally situations such as shocks) +% firstl1: lower band, .68, nstp-by-nrow-by-ncol +% highth1: high band, .68, nstp-by-nrow-by-ncol +% firstl: lower band, .90, nstp-by-nrow-by-ncol +% highth: high band, .90, nstp-by-nrow-by-ncol +% YTickIndx: 1: enable YTick; 0: disable +% scaleIndx: 1: enable scale along Y-axis; 0: disable +% xlab,ylab: labels +% +% See imrgraph, imcerrgraph, imrerrgraph + + +t = 1:nstp; +nrow +ncol + +temp1=zeros(ncol,1); +temp2=zeros(ncol,1); +maxval=zeros(nrow,1); +minval=zeros(nrow,1); +for i = 1:nrow + for j = 1:ncol + jnk1=max(firsth(:,i,j)); + jnk2=max(firstl(:,i,j)); + jnk3=max(firsth1(:,i,j)); + jnk4=max(firstl1(:,i,j)); + jnk5=max(imf(:,i,j)); + + temp1(j)=max([jnk1 jnk2 jnk3 jnk4 jnk5]); + % + jnk1=min(firstl(:,i,j)); + jnk2=min(firsth(:,i,j)); + jnk3=min(firstl1(:,i,j)); + jnk4=min(firsth1(:,i,j)); + jnk5=min(imf(:,i,j)); + + temp2(j)=min([jnk1 jnk2 jnk3 jnk4 jnk5]); + end + maxval(i)=max(temp1); + minval(i)=min(temp2); +end + +scaleout = [maxval(:) minval(:)]; + +%-------------- +% Column j: Shock 1 to N; Row i: Responses to +%------------- +figure +rowlabel = 1; +for i = 1:nrow % column: from top to bottom + columnlabel = 1; + + if minval(i)<0 + if maxval(i)<=0 + yt=[minval(i) 0]; + else + yt=[minval(i) 0 maxval(i)]; + end + else % (minval(i) >=0) + if maxval(i) > 0 + yt=[0 maxval(i)]; + else % (identically zero responses) + yt=[-1 0 1]; + end + end + + + scale=[1 nstp minval(i) maxval(i)]; + for j = 1:ncol % row: from left to right + k1=(i-1)*ncol+j; + subplot(nrow,ncol,k1) + plot(t,imf(:,i,j),t,[firstl1(:,i,j) firsth1(:,i,j)],'k--',... + t,[firstl(:,i,j) firsth(:,i,j)],'k-.',t,zeros(length(imf(:,i,j)),1),'k-'); + grid; + if scaleIndx + axis(scale); + end + %set(gca,'YLim',[minval(i) maxval(i)]) + % + set(gca,'XTick',XTick) + if YTickIndx + set(gca,'YTick',yt) + end + + if i<nrow + set(gca,'XTickLabelMode','manual','XTickLabel',[]) + end + %set(gca,'XTickLabel',' '); + if j>1 + set(gca,'YTickLabel',' '); + end + if rowlabel == 1 + %title(['x' num2str(j)]) + %title(eval(['x' num2str(j)])) + title(char(xlab(j))) + end + if columnlabel == 1 + %ylabel(['x' num2str(i)]) + %ylabel(eval(['x' num2str(i)])) + ylabel(char(ylab(i))) + end + columnlabel = 0; + end + rowlabel = 0; +end \ No newline at end of file diff --git a/MatlabFiles/phg234.m b/MatlabFiles/phg234.m new file mode 100755 index 0000000..b524aa9 --- /dev/null +++ b/MatlabFiles/phg234.m @@ -0,0 +1,243 @@ +function g = phg234(x,idmat0,idmat1,fss,nvar,ncoef,phi, ... + y,A0b,sg0bid,sgpbid) +%function of = pmddf232(x,idmat,fss,nvar,ncoef,phi, ... +% y,A0b,sg0bid,sgpbid) +% Leeper-Sims-Zha BVAR setup +% general program to setup A0 matrix and compute the likelihood +% requires +% x (parameter vector) +% a0indx (matrix indicating the free parameters in A0) +% fss (forecast sample size) +% nvar (number of variables) +% ncoef (number of coefficients in a single equation in A+) +% phi (r.h.s. observations in the system for A+) +% y (l.h.s. observations for A0) +% A0b (initial prior mean on A0) +% sg0bid (diagonal of Sigma0_bar, unweighted prior vcv on the parameters in i-th equation in A0) +% sgpbid (diagonal of Sigma+_bar, unweighted prior vcv on the parameters in i-th equation in A+) +% +% Revisions by CAS 9/27/96: If we transmit idmat, rather than a0indx, we can scale the elements of +% idmat so that it carries information about relative prior variances. +% +% Revsions by TZ, 10/12/96: efficiency improvement by streamlining the previous code +% according to the general setup in Sims and Zha "Bayesian Methods for ...". +% +global vaya0 vaha0 vaxah vahad vbiga GlbAph FRESHFUNCTION +% FRESHFUNCTION added 8/20/90 by CAS. It signals the pmddg23 whether the global variables +% it uses have been refreshed by a new pmddf231 call since the last gradient call. +a0indx=find(idmat0); +% pre-allocate GlbAph to be zeros(nvar,lags*nvar+1=ncoef) + +nhp = 0; % <<>> 4 hyperparameters +na0p = length(a0indx); % <<>> number of A0 parameters +nfp = na0p+nhp; + +% *** initializing +vaya0 = zeros(na0p,1); +vaha0 = zeros(na0p,1); +vaxah = zeros(na0p,1); +vahad = zeros(na0p,1); +vbiga = zeros(na0p,1); + + +A0h = zeros(nvar,nvar); +A0h(a0indx) = x(1:na0p); +%A0h = reshape(a0,nvar,nvar); CAS 9/24/96. The reshape is not necessary if a0 starts as nvar x nvar + % restrictions on A0 + +[A0hl,A0hu] = lu(A0h); + +% ** hyperparameters +%%mu = x(na0p+1:nfp); +mu = ones(5,1); +mu(1) = 1; +%mu(1) = 2; +mu(2) = 0.3; +mu(3) = 25; +%mu(4)=1; +mu(4)=1; +mu(5) =1; +%mu(5) = 40; +% results from ...\dummy1\foreh\pmdd6.out +% +% mu(1): overall tightness and also for A0; +% mu(2): relative tightness for A+; +% mu(3): relative tightness for the constant term; +% mu(4): weight on single dummy initial observation including constant; +% mu(5): weight on nvar sums of coeffs dummy observations. + +% ** weight prior dummy observations +%phi(1:nvar,:) = (mu(5)^2/mu(1)^2)*phi(1:nvar,:); +%y(1:nvar,:) = (mu(5)^2/mu(1)^2)*y(1:nvar,:); +%phi(ndobs,:) = mu +% modified by CAS 8/6/96. The dummy obs weights are naturally in std units, not var units. +%%phi(1:nvar,:) = mu(5)*phi(1:nvar,:); +%%y(1:nvar,:) = mu(5)*y(1:nvar,:); +%%phi(nvar+1,:) = mu(4)*phi(nvar+1,:); +%%y(nvar+1,:) = mu(4)*y(nvar+1,:); + +% ** set up the conditional prior variance sg0bi and sgpbi. +%%sg0bida = mu(1)^2*sg0bid; +sgpbida = mu(1)^2*mu(2)^2*sgpbid; +sgpbida(ncoef) = mu(1)^2*mu(3)^2; +sgppbd = sgpbida(nvar+1:ncoef); % corresponding to A++, in an SZ paper +sgppb = diag(sgppbd); + +% +% ** some common terms +[u d v]=svd(phi,0); %trial +% xtx = phi'*phi; %trial +vd=v.*(ones(size(v,2),1)*diag(d)'); %trial +xtx=vd*vd'; +% M = eye(fss) - phi*(xtx\phi'); % not used except in line below %trial +yu = y'*u; %trial +cxyxx=yu*yu'; %trial +ymy=y'*y-cxyxx; %trial +%ymy = y'*M*y; +%cxy = phi'*y; %trial +cxy = vd*yu'; %trial +%cxpy = xtx\cxy; %not used further except in line below +%cxyxx = cxy'*cxpy; + +% ** estimate A+_hat conditional on A0, ncoef*nvar, but not using full prior +%GlbAph = cxpy*A0h; + + +%%%%%%% +%%% build the objective function below +%%%%%%% +% +disp(sprintf('Starting loop (of): %g',toc)) + +stril = 0; +Hp0p = zeros(ncoef); +% initializing Htd_+0*inv(Htd_00)*Htd_0+: conditional prior covariance +for i = 1:nvar + stri = find(idmat0(:,i)); %CAS change 9/24/96, to avoid slim chance of an exact zero in x vector + %at some point during an optimization. + strm = length(stri); + + %%A0hb = A0h(stri,i)-A0b(stri,i); + + % ** set up the conditional prior variance sg0bi and sgpbi. + % sg0bd = zeros(stri,1); Commented out by CAS, 9/24/96. Looks like this meant to have + % strm where it has stri, and in any case it is "overwritten" below. + %------------------------------ + % Introduce prior information on which variables "belong" in various equations. + % In this first trial, we just introduce this information here, in a model-specific way. + % Eventually this info has to be passed parametricly. In our first shot, we just damp down + % all coefficients except those on the diagonal. + %%factor0=idmat0(:,i); + %%sg0bd = sg0bida(stri).*factor0(stri); + %%sg0b = diag(sg0bd); + % + factor1=idmat1(:,i); + sg1bd = sgpbida(1:nvar).*factor1; + sg1b = diag(sg1bd); + + % ** set up the unconditional prior variance on A0i and A+i + XX = zeros(nvar,strm); + XX(stri,:) = eye(strm); % XX in Gelman, etel, on p479 + % + % * final conditional prior variance on A+i give that on A0i, and + % * unconditional variance on A0+ + %%H0td = sg0b; % unconditional + % H_~: td: tilde for ~ + % ** inverse and chol decomp + %%H0tdi = inv(H0td); + + % + Hptd = zeros(ncoef); + Hptd(1:nvar,1:nvar)=sg1b; + Hptd(nvar+1:ncoef,nvar+1:ncoef)=sgppb; + % condtional on A0i, H_plus_tilde + + % ** inverse + Hptdi = inv(Hptd); + %%chhh=Hptdi*Hp0; + chhh = zeros(ncoef,strm); % <<>> the term not used for "of"\ + chhh(1:nvar,:) = Hptdi(1:nvar,1:nvar)*XX; + chhh1 = XX'*chhh(1:nvar,:); + + % common term + xxhp = xtx+Hptdi; + + % ** final conditional prior mean on A+i + alptd = zeros(ncoef,1); + alptd(1:nvar) = XX*A0h(stri,i); + % conditional on A0i, alpha-plus-tilde + + % * alpha_plus_* for the ith equation, ncoef*1 + % *alps = xxhp\(phi'*y*A0h(:,i)+HptdDinalptd); + %%HptdDinalptd=Hptdi*alptd; + HptdDinalptd=zeros(ncoef,1); + HptdDinalptd(1:nvar) = Hptdi(1:nvar,1:nvar)*alptd(1:nvar); + xaha = cxy*A0h(:,i)+HptdDinalptd; %CAS 8/7/96. Replaced phi'*y with cxy + alpst = xaha'/xxhp; + GlbAph(i,:)=alpst; + % alpst': transpose of alps. + + % ** 3rd bid term in i-th equation, + % ** with all other 3rd big terms prior to i-th + A0hy = A0h(:,i)'*ymy; + % ** 4th bid term in i-th equation, + % ** with all other 4th big terms prior to i-th + A0hcxyxx = A0h(:,i)'*cxyxx; + %%atdHatd = alptd'*HptdDinalptd; % efficiency improvement + atdHatd = alptd(1:nvar)'*HptdDinalptd(1:nvar); + + %%%% + % *** passing the gradient to "pmdg6.m" (analytical gradient) + %%%% + % ** d1aya0 = d(alpha0'*Y'MY*alpha0)/d(a0??) + daya0 = 2.0*A0hy; + daya0 = daya0(:); + vaya0(stril+1:stril+strm) = daya0(stri); + + % ** daha0 = d((alpha0-alpha0_tilde)'*inv(H_0_tilde)* + % ** (alpha0-alpha0_tilde))/d(a0??) + %%daha0 = 2.0*A0hbH; + %%vaha0(stril+1:stril+strm) = daha0(:); + + % ** daxah = d(alpha_+^'*X'X*alpha_+^)/d(a0??) + % ** daxah = d(alpha_+^'*X'X*alpha_+^)/d(a0??) + %% daxah = 2*(Aph(:,i)'*xtx) * cxpy(:,stri); + %% vaxah(stril+1:stril+strm) = daxah'; + daxah = 2*A0hcxyxx; + daxah = daxah(:); + vaxah(stril+1:stril+strm) = daxah(stri); + + + % ** dahad = d(alpha_+~'*inv(H_+~)*alpha_+~)/d(a0??) + dahad = 2*A0h(stri,i)'*chhh1; + % <<>> multiplications not used in "of" + vahad(stril+1:stril+strm) = dahad(:); + + + % ** dbiga = d((X'X*alpha_+^+inv(H_+~)*alpha_+*)'*a_+_*)/d(a0??) + dbiga = 2*alpst*(cxy(:,stri)+chhh); + % <<>> multiplications not used in "of" + vbiga(stril+1:stril+strm) = dbiga'; + + stril = stril + strm; +end + +%disp(sprintf('Loop %d end: %g', i, toc)) +disp(sprintf('Loop end (of): %g', toc)) + +%e_tfat = toc + +g = zeros(nfp,1); + +%%%%%%% +%%% analytical gradient for A0 below +%%%%%%% +% +% ** dla0 = dlog|A0|/d(a0??) +vdla0 = zeros(na0p,1); +dla0 = inv(A0h)'; +dla0 = dla0(:); +vdla0 = dla0(a0indx); + +% without the prior |A0|^k +g = -fss*vdla0 + 0.5*vaya0 + 0.5*vaha0 + 0.5*vaxah + 0.5*vahad - 0.5*vbiga; \ No newline at end of file diff --git a/MatlabFiles/phg235.m b/MatlabFiles/phg235.m new file mode 100755 index 0000000..5ea7616 --- /dev/null +++ b/MatlabFiles/phg235.m @@ -0,0 +1,195 @@ +function g = phg235(x,idmat0,idmat1,fss,nvar,ncoef,phi, ... + y,A0b,sg0bid,sgpbid) +%function of = pmddf232(x,idmat,fss,nvar,ncoef,phi, ... +% y,A0b,sg0bid,sgpbid) +% Leeper-Sims-Zha BVAR setup +% general program to setup A0 matrix and compute the likelihood +% requires +% x (parameter vector) +% a0indx (matrix indicating the free parameters in A0) +% fss (forecast sample size) +% nvar (number of variables) +% ncoef (number of coefficients in a single equation in A+) +% phi (r.h.s. observations in the system for A+) +% y (l.h.s. observations for A0) +% A0b (initial prior mean on A0) +% sg0bid (diagonal of Sigma0_bar, unweighted prior vcv on the parameters in i-th equation in A0) +% sgpbid (diagonal of Sigma+_bar, unweighted prior vcv on the parameters in i-th equation in A+) +% +% Revisions by CAS 9/27/96: If we transmit idmat, rather than a0indx, we can scale the elements of +% idmat so that it carries information about relative prior variances. +% +% Revsions by TZ, 10/13/96: efficiency improvement by streamlining the previous code +% according to the general setup in Sims and Zha "Bayesian Methods for ...". +% +global vaha0 vaMMa0 GlbAph FRESHFUNCTION +% FRESHFUNCTION added 8/20/90 by CAS. It signals the pmddg23 whether the global variables +% it uses have been refreshed by a new pmddf231 call since the last gradient call. +a0indx=find(idmat0); +% pre-allocate GlbAph to be zeros(nvar,lags*nvar+1=ncoef) + +nhp = 0; % <<>> 4 hyperparameters +na0p = length(a0indx); % <<>> number of A0 parameters +nfp = na0p+nhp; + +% *** initializing +vaha0 = zeros(na0p,1); +vaMMa0 = zeros(na0p,1); + +% +A0h = zeros(nvar,nvar); +A0h(a0indx) = x(1:na0p); +%A0h = reshape(a0,nvar,nvar); CAS 9/24/96. The reshape is not necessary if a0 starts as nvar x nvar + % restrictions on A0 + +[A0hl,A0hu] = lu(A0h); + +% ** hyperparameters +%%mu = x(na0p+1:nfp); +mu = ones(5,1); +mu(1) = 1; +%mu(1) = 2; +mu(2) = 0.2; +mu(3) = 1; +%mu(4)=1; +mu(4)=10; +mu(5) =1; +%mu(5) = 40; +% results from ...\dummy1\foreh\pmdd6.out +% +% mu(1): overall tightness and also for A0; +% mu(2): relative tightness for A+; +% mu(3): relative tightness for the constant term; +% mu(4): weight on single dummy initial observation including constant; +% mu(5): weight on nvar sums of coeffs dummy observations. + +% ** weight prior dummy observations +%phi(1:nvar,:) = (mu(5)^2/mu(1)^2)*phi(1:nvar,:); +%y(1:nvar,:) = (mu(5)^2/mu(1)^2)*y(1:nvar,:); +%phi(ndobs,:) = mu +% modified by CAS 8/6/96. The dummy obs weights are naturally in std units, not var units. +phi(1:nvar,:) = mu(5)*phi(1:nvar,:); +y(1:nvar,:) = mu(5)*y(1:nvar,:); +phi(nvar+1,:) = mu(4)*phi(nvar+1,:); +y(nvar+1,:) = mu(4)*y(nvar+1,:); + +% ** set up the conditional prior variance sg0bi and sgpbi. +sg0bida = mu(1)^2*sg0bid; +sgpbida = mu(1)^2*mu(2)^2*sgpbid; +sgpbida(ncoef) = mu(1)^2*mu(3)^2; +sgppbd = sgpbida(nvar+1:ncoef); % corresponding to A++, in an SZ paper +sgppbdi = 1./sgppbd; +%sgppb = diag(sgppbd); + +% +% ** some common terms +[u d v]=svd(phi,0); %trial +% xtx = phi'*phi; %trial +vd=v.*(ones(size(v,2),1)*diag(d)'); %trial +xtx=vd*vd'; +% M = eye(fss) - phi*(xtx\phi'); % not used except in line below %trial +yu = y'*u; %trial +cxyxx=yu*yu'; %trial +yty=y'*y; +ymy=yty-cxyxx; %trial +%ymy = y'*M*y; +%cxy = phi'*y; %trial +cxy = vd*yu'; %trial +cyx = cxy'; +%cxpy = xtx\cxy; %not used further except in line below +%cxyxx = cxy'*cxpy; + +% ** estimate A+_hat conditional on A0, ncoef*nvar, but not using full prior +%GlbAph = cxpy*A0h; + + +%%%%%%% +%%% Analytical gradient for A0 below +%%%%%%% +% +% ** dla0 = dlog|A0|/d(a0??) +vdla0 = zeros(na0p,1); +dla0 = inv(A0h)'; +dla0 = dla0(:); +vdla0 = dla0(a0indx); + + +stril = 0; +Hptd = zeros(ncoef); +Hptdi=Hptd; +Hptd(nvar+1:ncoef,nvar+1:ncoef)=diag(sgppbd); +Hptdi(nvar+1:ncoef,nvar+1:ncoef)=diag(sgppbdi); + % condtional on A0i, H_plus_tilde +for i = 1:nvar + stri = find(idmat0(:,i)); %CAS change 9/24/96, to avoid slim chance of an exact zero in x vector + %at some point during an optimization. + strm = length(stri); + + A0hb = A0h(stri,i)-A0b(stri,i); + + % ** set up the conditional prior variance sg0bi and sgpbi. + % sg0bd = zeros(stri,1); Commented out by CAS, 9/24/96. Looks like this meant to have + % strm where it has stri, and in any case it is "overwritten" below. + %------------------------------ + % Introduce prior information on which variables "belong" in various equations. + % In this first trial, we just introduce this information here, in a model-specific way. + % Eventually this info has to be passed parametricly. In our first shot, we just damp down + % all coefficients except those on the diagonal. + factor0=idmat0(:,i); + sg0bd = sg0bida(stri).*factor0(stri); + sg0bdi = 1./sg0bd; + %sg0b = diag(sg0bd); + % + factor1=idmat1(:,i); + sg1bd = sgpbida(1:nvar).*factor1; + sg1bdi = 1./sg1bd; + %sg1b = diag(sg1bd); + + % ** set up the unconditional prior variance on A0i and A+i + XX = zeros(nvar,strm); + XX(stri,:) = eye(strm); % XX in Gelman, etel, on p479 + % + % * final conditional prior variance on A+i give that on A0i, and + % * unconditional variance on A0+ + H0td = diag(sg0bd); % unconditional + % H_~: td: tilde for ~ + % ** inverse and chol decomp + H0tdi = diag(sg0bdi); + + % + Hptd(1:nvar,1:nvar)=diag(sg1bd); + Hptdi(1:nvar,1:nvar)=diag(sg1bdi); + % condtional on A0i, H_plus_tilde + + % common terms + xxhp = xtx+Hptdi; + A0hbH = A0hb'*H0tdi; + H1p_1 = zeros(ncoef,nvar); + H1p_1(1:nvar,:) = Hptdi(1:nvar,1:nvar); + %%Hm = (cyx+H1p_1')*(xxhp\(cxy+H1p_1)); + Hm1 = (cyx+H1p_1')/xxhp; + Hm2 = cxy+H1p_1; + GlbAph(i,:) = A0h(stri,i)'*XX'*Hm1; % alpha_plus* + %%alpMpyh = A0h(stri,i)'*XX'*(yty+Hptdi(1:nvar,1:nvar)-Hm)*XX; + alpMpyh = A0h(stri,i)'*XX'*(yty+Hptdi(1:nvar,1:nvar))*XX - GlbAph(i,:)*Hm2*XX; + + %%%% + % *** passing the gradient to "pmdg6.m" (analytical gradient) + %%%% + % + % ** daha0 = d((alpha0-alpha0_tilde)'*inv(H_0_tilde)* + % ** (alpha0-alpha0_tilde))/d(a0??) + daha0 = 2.0*A0hbH; + vaha0(stril+1:stril+strm) = daha0(:); + % + % ** daMMa0 = d(alpha0'*P'*(Y'Y+H_1^(-1)+H_m)*P*apha0) / d(a0?) + daMMa0 = 2.0*alpMpyh; + vaMMa0(stril+1:stril+strm) = daMMa0(:); + + stril = stril + strm; +end + +% without the prior |A0|^k +g = -fss*vdla0 + 0.5*vaha0 + 0.5*vaMMa0; + +%disp(sprintf('Loop end (gradient): %g', toc)) \ No newline at end of file diff --git a/MatlabFiles/pmddf235.m b/MatlabFiles/pmddf235.m new file mode 100755 index 0000000..87c1130 --- /dev/null +++ b/MatlabFiles/pmddf235.m @@ -0,0 +1,204 @@ +function of = pmddf235(x,idmat0,idmat1,fss,nvar,ncoef,phi, ... + y,A0b,sg0bid,sgpbid) +%function of = pmddf232(x,idmat,fss,nvar,ncoef,phi, ... +% y,A0b,sg0bid,sgpbid) +% Leeper-Sims-Zha BVAR setup +% general program to setup A0 matrix and compute the likelihood +% requires +% x (parameter vector) +% a0indx (matrix indicating the free parameters in A0) +% fss (forecast sample size) +% nvar (number of variables) +% ncoef (number of coefficients in a single equation in A+) +% phi (r.h.s. observations in the system for A+) +% y (l.h.s. observations for A0) +% A0b (initial prior mean on A0) +% sg0bid (diagonal of Sigma0_bar, unweighted prior vcv on the parameters in i-th equation in A0) +% sgpbid (diagonal of Sigma+_bar, unweighted prior vcv on the parameters in i-th equation in A+) +% +% Revisions by CAS 9/27/96: If we transmit idmat, rather than a0indx, we can scale the elements of +% idmat so that it carries information about relative prior variances. +% +% Revsions by TZ, 10/13/96: efficiency improvement by streamlining the previous code +% according to the general setup in Sims and Zha "Bayesian Methods for ...". +% +global vaha0 vaMMa0 GlbAph FRESHFUNCTION +% FRESHFUNCTION added 8/20/90 by CAS. It signals the pmddg23 whether the global variables +% it uses have been refreshed by a new pmddf231 call since the last gradient call. +a0indx=find(idmat0); +% pre-allocate GlbAph to be zeros(nvar,lags*nvar+1=ncoef) + +nhp = 0; % <<>> 4 hyperparameters +na0p = length(a0indx); % <<>> number of A0 parameters +nfp = na0p+nhp; + +% *** initializing +vaha0 = zeros(na0p,1); +vaMMa0 = zeros(na0p,1); + +% +A0h = zeros(nvar,nvar); +A0h(a0indx) = x(1:na0p); +%A0h = reshape(a0,nvar,nvar); CAS 9/24/96. The reshape is not necessary if a0 starts as nvar x nvar + % restrictions on A0 + +[A0hl,A0hu] = lu(A0h); + +% ** hyperparameters +%%mu = x(na0p+1:nfp); +mu = ones(5,1); +mu(1) = 1; +%mu(1) = 2; +mu(2) = 0.2; +mu(3) = 1; +%mu(4)=1; +mu(4)=10; +mu(5) =1; +%mu(5) = 40; +% results from ...\dummy1\foreh\pmdd6.out +% +% mu(1): overall tightness and also for A0; +% mu(2): relative tightness for A+; +% mu(3): relative tightness for the constant term; +% mu(4): weight on single dummy initial observation including constant; +% mu(5): weight on nvar sums of coeffs dummy observations. + +% ** weight prior dummy observations +%phi(1:nvar,:) = (mu(5)^2/mu(1)^2)*phi(1:nvar,:); +%y(1:nvar,:) = (mu(5)^2/mu(1)^2)*y(1:nvar,:); +%phi(ndobs,:) = mu +% modified by CAS 8/6/96. The dummy obs weights are naturally in std units, not var units. +phi(1:nvar,:) = mu(5)*phi(1:nvar,:); +y(1:nvar,:) = mu(5)*y(1:nvar,:); +phi(nvar+1,:) = mu(4)*phi(nvar+1,:); +y(nvar+1,:) = mu(4)*y(nvar+1,:); + +% ** set up the conditional prior variance sg0bi and sgpbi. +sg0bida = mu(1)^2*sg0bid; +sgpbida = mu(1)^2*mu(2)^2*sgpbid; +sgpbida(ncoef) = mu(1)^2*mu(3)^2; +sgppbd = sgpbida(nvar+1:ncoef); % corresponding to A++, in an SZ paper +sgppbdi = 1./sgppbd; +%sgppb = diag(sgppbd); + +% +% ** some common terms +[u d v]=svd(phi,0); %trial +% xtx = phi'*phi; %trial +vd=v.*(ones(size(v,2),1)*diag(d)'); %trial +xtx=vd*vd'; +% M = eye(fss) - phi*(xtx\phi'); % not used except in line below %trial +yu = y'*u; %trial +cxyxx=yu*yu'; %trial +yty=y'*y; +ymy=yty-cxyxx; %trial +%ymy = y'*M*y; +%cxy = phi'*y; %trial +cxy = vd*yu'; %trial +cyx = cxy'; +%cxpy = xtx\cxy; %not used further except in line below +%cxyxx = cxy'*cxpy; + +% ** estimate A+_hat conditional on A0, ncoef*nvar, but not using full prior +%GlbAph = cxpy*A0h; + + +%%%%%%% +%%% build the objective function below +%%%%%%% +% +t1f = diag(abs(A0hu)); +t1f = log(t1f); +% * without the prior |A0|^k +tt1 = (-1.0)*fss*sum(t1f); + +tt3 = 0; + +disp(sprintf('Starting loop (of): %g',toc)) + +stril = 0; +Hptd = zeros(ncoef); +Hptdi=Hptd; +Hptd(nvar+1:ncoef,nvar+1:ncoef)=diag(sgppbd); +Hptdi(nvar+1:ncoef,nvar+1:ncoef)=diag(sgppbdi); + % condtional on A0i, H_plus_tilde +for i = 1:nvar + stri = find(idmat0(:,i)); %CAS change 9/24/96, to avoid slim chance of an exact zero in x vector + %at some point during an optimization. + strm = length(stri); + + A0hb = A0h(stri,i)-A0b(stri,i); + + % ** set up the conditional prior variance sg0bi and sgpbi. + % sg0bd = zeros(stri,1); Commented out by CAS, 9/24/96. Looks like this meant to have + % strm where it has stri, and in any case it is "overwritten" below. + %------------------------------ + % Introduce prior information on which variables "belong" in various equations. + % In this first trial, we just introduce this information here, in a model-specific way. + % Eventually this info has to be passed parametricly. In our first shot, we just damp down + % all coefficients except those on the diagonal. + factor0=idmat0(:,i); + sg0bd = sg0bida(stri).*factor0(stri); + sg0bdi = 1./sg0bd; + %sg0b = diag(sg0bd); + % + factor1=idmat1(:,i); + sg1bd = sgpbida(1:nvar).*factor1; + sg1bdi = 1./sg1bd; + %sg1b = diag(sg1bd); + + % ** set up the unconditional prior variance on A0i and A+i + XX = zeros(nvar,strm); + XX(stri,:) = eye(strm); % XX in Gelman, etel, on p479 + % + % * final conditional prior variance on A+i give that on A0i, and + % * unconditional variance on A0+ + H0td = diag(sg0bd); % unconditional + % H_~: td: tilde for ~ + % ** inverse and chol decomp + H0tdi = diag(sg0bdi); + + % + Hptd(1:nvar,1:nvar)=diag(sg1bd); + Hptdi(1:nvar,1:nvar)=diag(sg1bdi); + % condtional on A0i, H_plus_tilde + + % common terms + xxhp = xtx+Hptdi; + A0hbH = A0hb'*H0tdi; + H1p_1 = zeros(ncoef,nvar); + H1p_1(1:nvar,:) = Hptdi(1:nvar,1:nvar); + %%Hm = (cyx+H1p_1')*(xxhp\(cxy+H1p_1)); + Hm1 = (cyx+H1p_1')/xxhp; + Hm2 = cxy+H1p_1; + GlbAph(i,:) = A0h(stri,i)'*XX'*Hm1; % alpha_plus_*_transpose + %%alpMpyh = A0h(stri,i)'*XX'*(yty+Hptdi(1:nvar,1:nvar)-Hm)*XX; + alpMpyh = A0h(stri,i)'*XX'*(yty+Hptdi(1:nvar,1:nvar))*XX - GlbAph(i,:)*Hm2*XX; + + % ** 3rd bid term in i-th equation, + % ** with all other 3rd big terms before the i-th equation + tt3 = tt3 + A0hbH*A0hb + alpMpyh*A0h(stri,i); + + %%%% + % *** passing the gradient to "pmdg6.m" (analytical gradient) + %%%% + % + % ** daha0 = d((alpha0-alpha0_tilde)'*inv(H_0_tilde)* + % ** (alpha0-alpha0_tilde))/d(a0??) + daha0 = 2.0*A0hbH; + vaha0(stril+1:stril+strm) = daha0(:); + % + % ** daMMa0 = d(alpha0'*P'*(Y'Y+H_1^(-1)+H_m)*P*apha0) / d(a0?) + daMMa0 = 2.0*alpMpyh; + vaMMa0(stril+1:stril+strm) = daMMa0(:); + + stril = stril + strm; +end + +%disp(sprintf('Loop %d end: %g', i, toc)) +disp(sprintf('Loop end (of): %g', toc)) + +%e_tfat = toc + +of = tt1 + 0.5*tt3; +FRESHFUNCTION=1; \ No newline at end of file diff --git a/MatlabFiles/pmddf236.m b/MatlabFiles/pmddf236.m new file mode 100755 index 0000000..c67f111 --- /dev/null +++ b/MatlabFiles/pmddf236.m @@ -0,0 +1,213 @@ +function of = pmddf236(x,idmat0,idmatp,fss,nvar,ncoef,phi, ... + y,A0b,sg0bid,sgpbid) +%function of = pmddf232(x,idmat,fss,nvar,ncoef,phi, ... +% y,A0b,sg0bid,sgpbid) +% Leeper-Sims-Zha BVAR setup +% general program to setup A0 matrix and compute the likelihood +% requires +% x (parameter vector) +% a0indx (matrix indicating the free parameters in A0) +% fss (forecast sample size) +% nvar (number of variables) +% ncoef (number of coefficients in a single equation in A+) +% phi (r.h.s. observations in the system for A+) +% y (l.h.s. observations for A0) +% A0b (initial prior mean on A0) +% sg0bid (diagonal of Sigma0_bar, unweighted prior vcv on the parameters in i-th equation in A0) +% sgpbid (diagonal of Sigma+_bar, unweighted prior vcv on the parameters in i-th equation in A+) +% +% Revisions by CAS 9/27/96: If we transmit idmat, rather than a0indx, we can scale the elements of +% idmat so that it carries information about relative prior variances. +% +% Revsions by TZ, 10/13/96: efficiency improvement by streamlining the previous code +% according to the general setup in Sims and Zha "Bayesian Methods for ...". +% +global vaha0 vaMMa0 GlbAph FRESHFUNCTION +% FRESHFUNCTION added 8/20/90 by CAS. It signals the pmddg23 whether the global variables +% it uses have been refreshed by a new pmddf231 call since the last gradient call. +a0indx=find(idmat0); +% pre-allocate GlbAph to be zeros(nvar,lags*nvar+1=ncoef) + +nhp = 0; % <<>> 4 hyperparameters +na0p = length(a0indx); % <<>> number of A0 parameters +nfp = na0p+nhp; + +% *** initializing +vaha0 = zeros(na0p,1); +vaMMa0 = zeros(na0p,1); + +% +A0h = zeros(nvar,nvar); +A0h(a0indx) = x(1:na0p); +%A0h = reshape(a0,nvar,nvar); CAS 9/24/96. The reshape is not necessary if a0 starts as nvar x nvar + % restrictions on A0 + +[A0hl,A0hu] = lu(A0h); + +% ** hyperparameters +%%mu = x(na0p+1:nfp); +mu = ones(5,1); +mu(1) = 1; +%mu(1) = 2; +mu(2) = 0.2; +mu(3) = 1; +%mu(4)=1; +mu(4)=10; +mu(5) =1; +%mu(5) = 40; +% results from ...\dummy1\foreh\pmdd6.out +% +% mu(1): overall tightness and also for A0; +% mu(2): relative tightness for A+; +% mu(3): relative tightness for the constant term; +% mu(4): weight on single dummy initial observation including constant; +% mu(5): weight on nvar sums of coeffs dummy observations. + +% ** weight prior dummy observations +%phi(1:nvar,:) = (mu(5)^2/mu(1)^2)*phi(1:nvar,:); +%y(1:nvar,:) = (mu(5)^2/mu(1)^2)*y(1:nvar,:); +%phi(ndobs,:) = mu +% modified by CAS 8/6/96. The dummy obs weights are naturally in std units, not var units. +phi(1:nvar,:) = mu(5)*phi(1:nvar,:); +y(1:nvar,:) = mu(5)*y(1:nvar,:); +phi(nvar+1,:) = mu(4)*phi(nvar+1,:); +y(nvar+1,:) = mu(4)*y(nvar+1,:); + +% ** set up the conditional prior variance sg0bi and sgpbi. +sg0bida = mu(1)^2*sg0bid; +sgpbida = mu(1)^2*mu(2)^2*sgpbid; +sgpbida(ncoef) = mu(1)^2*mu(3)^2; +sgppbd = sgpbida(nvar+1:ncoef); % corresponding to A++, in an SZ paper +%%sgppbdi = 1./sgppbd; +%sgppb = diag(sgppbd); + +% +% ** some common terms +[u d v]=svd(phi,0); %trial +% xtx = phi'*phi; %trial +vd=v.*(ones(size(v,2),1)*diag(d)'); %trial +xtx=vd*vd'; +% M = eye(fss) - phi*(xtx\phi'); % not used except in line below %trial +yu = y'*u; %trial +cxyxx=yu*yu'; %trial +yty=y'*y; +ymy=yty-cxyxx; %trial +%ymy = y'*M*y; +%cxy = phi'*y; %trial +cxy = vd*yu'; %trial +cyx = cxy'; +%cxpy = xtx\cxy; %not used further except in line below +%cxyxx = cxy'*cxpy; + +% ** estimate A+_hat conditional on A0, ncoef*nvar, but not using full prior +%GlbAph = cxpy*A0h; + + +%%%%%%% +%%% build the objective function below +%%%%%%% +% +t1f = diag(abs(A0hu)); +t1f = log(t1f); +% * without the prior |A0|^k +tt1 = (-1.0)*fss*sum(t1f); + +tt3 = 0; + +disp(sprintf('Starting loop (of): %g',toc)) + +stril = 0; +Hptd = zeros(ncoef); +Hptdi=Hptd; +%%Hptd(nvar+1:ncoef,nvar+1:ncoef)=diag(sgppbd); +%%Hptdi(nvar+1:ncoef,nvar+1:ncoef)=diag(sgppbdi); +Hptd(ncoef,ncoef)=sgppbd(ncoef-nvar); +Hptdi(ncoef,ncoef)=1/sgppbd(ncoef-nvar); + % condtional on A0i, H_plus_tilde +for i = 1:nvar + stri = find(idmat0(:,i)); %CAS change 9/24/96, to avoid slim chance of an exact zero in x vector + %at some point during an optimization. + strm = length(stri); + + A0hb = A0h(stri,i)-A0b(stri,i); + + % ** set up the conditional prior variance sg0bi and sgpbi. + % sg0bd = zeros(stri,1); Commented out by CAS, 9/24/96. Looks like this meant to have + % strm where it has stri, and in any case it is "overwritten" below. + %------------------------------ + % Introduce prior information on which variables "belong" in various equations. + % In this first trial, we just introduce this information here, in a model-specific way. + % Eventually this info has to be passed parametricly. In our first shot, we just damp down + % all coefficients except those on the diagonal. + factor0=idmat0(:,i); + sg0bd = sg0bida(stri).*factor0(stri); + sg0bdi = 1./sg0bd; + %sg0b = diag(sg0bd); + % + factor1=idmatp(1:nvar,i); + sg1bd = sgpbida(1:nvar).*factor1; + sg1bdi = 1./sg1bd; + %sg1b = diag(sg1bd); + % + factorpp=idmatp(nvar+1:ncoef-1,i); + sgpp_cbd = sgppbd(1:ncoef-nvar-1) .* factorpp; + sgpp_cbdi = 1./sgpp_cbd; + + + % ** set up the unconditional prior variance on A0i and A+i + XX = zeros(nvar,strm); + XX(stri,:) = eye(strm); % XX in Gelman, etel, on p479 + % + % * final conditional prior variance on A+i give that on A0i, and + % * unconditional variance on A0+ + H0td = diag(sg0bd); % unconditional + % H_~: td: tilde for ~ + % ** inverse and chol decomp + H0tdi = diag(sg0bdi); + + % + Hptd(1:nvar,1:nvar)=diag(sg1bd); + Hptdi(1:nvar,1:nvar)=diag(sg1bdi); + Hptd(nvar+1:ncoef-1,nvar+1:ncoef-1)=diag(sgpp_cbd); + Hptdi(nvar+1:ncoef-1,nvar+1:ncoef-1)=diag(sgpp_cbdi); + % condtional on A0i, H_plus_tilde + + % common terms + xxhp = xtx+Hptdi; + A0hbH = A0hb'*H0tdi; + H1p_1 = zeros(ncoef,nvar); + H1p_1(1:nvar,:) = Hptdi(1:nvar,1:nvar); + %%Hm = (cyx+H1p_1')*(xxhp\(cxy+H1p_1)); + Hm1 = (cyx+H1p_1')/xxhp; + Hm2 = cxy+H1p_1; + GlbAph(i,:) = A0h(stri,i)'*XX'*Hm1; % alpha_plus_*_transpose + %%alpMpyh = A0h(stri,i)'*XX'*(yty+Hptdi(1:nvar,1:nvar)-Hm)*XX; + alpMpyh = A0h(stri,i)'*XX'*(yty+Hptdi(1:nvar,1:nvar))*XX - GlbAph(i,:)*Hm2*XX; + + % ** 3rd bid term in i-th equation, + % ** with all other 3rd big terms before the i-th equation + tt3 = tt3 + A0hbH*A0hb + alpMpyh*A0h(stri,i); + + %%%% + % *** passing the gradient to "pmdg6.m" (analytical gradient) + %%%% + % + % ** daha0 = d((alpha0-alpha0_tilde)'*inv(H_0_tilde)* + % ** (alpha0-alpha0_tilde))/d(a0??) + daha0 = 2.0*A0hbH; + vaha0(stril+1:stril+strm) = daha0(:); + % + % ** daMMa0 = d(alpha0'*P'*(Y'Y+H_1^(-1)+H_m)*P*apha0) / d(a0?) + daMMa0 = 2.0*alpMpyh; + vaMMa0(stril+1:stril+strm) = daMMa0(:); + + stril = stril + strm; +end + +%disp(sprintf('Loop %d end: %g', i, toc)) +disp(sprintf('Loop end (of): %g', toc)) + +%e_tfat = toc + +of = tt1 + 0.5*tt3; +FRESHFUNCTION=1; \ No newline at end of file diff --git a/MatlabFiles/pmddg235.m b/MatlabFiles/pmddg235.m new file mode 100755 index 0000000..332669d --- /dev/null +++ b/MatlabFiles/pmddg235.m @@ -0,0 +1,49 @@ +function [g,badg] = pmddg235(x,idmat0,idmat1,fss,nvar, ... + ncoef,phi,y,A0b,sg0bid,sgpbid); +% Leeper-Sims-Zha BVAR setup, analytical gradient for "csminwel.m" +% general program to setup A0 matrix and compute the likelihood +% requires x (parameter vector), a0indx (matrix indicating the free +% parameters in A0), fss (forecast sample size), nvar (number of variables), +% ncoef (number of coefficients in a single equation in A+), phi (r.h.s. +% observations in the system for A+), y (l.h.s. observations for A0), +% ymy (Y'*M*Y), xd0 (X(0) for dummy observations y*(1)), ys1 (dummy initial +% observations y*(1)), xtx (X'X or phi'*phi), A0b (initial prior on A0), +% sg0bid (diagonal of Sigma0_bar on the parameters in i-th equation in A0, +% initial prior covariace matrix), sgpbid (diagonal of Sigma+_bar on the +% parameters in i-th equation in A0, initial prior covariance matrix). +% +global vaha0 vaMMa0 FRESHFUNCTION +% CAS added FRESHFUNCTION 8/20/96 to allow use of pmddg23 in a numerical Hessian calculation, where +% it is invoked repeatedly without new function evaluations. +if ~FRESHFUNCTION + fjnk = pmddf235(x,idmat0,idmat1,fss,nvar,ncoef,phi,y,A0b,sg0bid,sgpbid); +end +FRESHFUNCTION=0; +badg = 0; +% +a0indx=find(idmat0); +nhp = 0; % <<>> 4 hyperparameters +na0p = length(a0indx); % <<>> number of A0 parameters +nfp = na0p+nhp; +g = zeros(nfp,1); +A0h= zeros(nvar); +A0h(a0indx) = x(1:na0p); + % restrictions on A0 + +%disp(sprintf('Starting loop (gradient): %g',toc)) + + +%%%%%%% +%%% analytical gradient for A0 below +%%%%%%% +% +% ** dla0 = dlog|A0|/d(a0??) +vdla0 = zeros(na0p,1); +dla0 = inv(A0h)'; +dla0 = dla0(:); +vdla0 = dla0(a0indx); + +% without the prior |A0|^k +g = -fss*vdla0 + 0.5*vaha0 + 0.5*vaMMa0; + +%disp(sprintf('Loop end (gradient): %g', toc)) \ No newline at end of file diff --git a/MatlabFiles/pmddg236.m b/MatlabFiles/pmddg236.m new file mode 100755 index 0000000..a1361c7 --- /dev/null +++ b/MatlabFiles/pmddg236.m @@ -0,0 +1,50 @@ +function [g,badg] = pmddg236(x,idmat0,idmatp,fss,nvar, ... + ncoef,phi,y,A0b,sg0bid,sgpbid); +% +% Leeper-Sims-Zha BVAR setup, analytical gradient for "csminwel.m" +% general program to setup A0 matrix and compute the likelihood +% requires x (parameter vector), a0indx (matrix indicating the free +% parameters in A0), fss (forecast sample size), nvar (number of variables), +% ncoef (number of coefficients in a single equation in A+), phi (r.h.s. +% observations in the system for A+), y (l.h.s. observations for A0), +% ymy (Y'*M*Y), xd0 (X(0) for dummy observations y*(1)), ys1 (dummy initial +% observations y*(1)), xtx (X'X or phi'*phi), A0b (initial prior on A0), +% sg0bid (diagonal of Sigma0_bar on the parameters in i-th equation in A0, +% initial prior covariace matrix), sgpbid (diagonal of Sigma+_bar on the +% parameters in i-th equation in A0, initial prior covariance matrix). +% +global vaha0 vaMMa0 FRESHFUNCTION +% CAS added FRESHFUNCTION 8/20/96 to allow use of pmddg23 in a numerical Hessian calculation, where +% it is invoked repeatedly without new function evaluations. +if ~FRESHFUNCTION + fjnk = pmddf236(x,idmat0,idmatp,fss,nvar,ncoef,phi,y,A0b,sg0bid,sgpbid); +end +FRESHFUNCTION=0; +badg = 0; +% +a0indx=find(idmat0); +nhp = 0; % <<>> 4 hyperparameters +na0p = length(a0indx); % <<>> number of A0 parameters +nfp = na0p+nhp; +g = zeros(nfp,1); +A0h= zeros(nvar); +A0h(a0indx) = x(1:na0p); + % restrictions on A0 + +%disp(sprintf('Starting loop (gradient): %g',toc)) + + +%%%%%%% +%%% analytical gradient for A0 below +%%%%%%% +% +% ** dla0 = dlog|A0|/d(a0??) +vdla0 = zeros(na0p,1); +dla0 = inv(A0h)'; +dla0 = dla0(:); +vdla0 = dla0(a0indx); + +% without the prior |A0|^k +g = -fss*vdla0 + 0.5*vaha0 + 0.5*vaMMa0; + +%disp(sprintf('Loop end (gradient): %g', toc)) \ No newline at end of file diff --git a/MatlabFiles/pmddwf23.m b/MatlabFiles/pmddwf23.m new file mode 100755 index 0000000..afc294a --- /dev/null +++ b/MatlabFiles/pmddwf23.m @@ -0,0 +1,197 @@ +function [of,GlbAphh] = pmddwf23(x,a0indx,fss,nvar,ncoef,phi, ... + y,xd0,ys1,A0b,sg0bid,sgpbid) +%function of = pmddf23(x,a0indx,fss,nvar,ncoef,phi, ... +% y,xd0,ys1,A0b,sg0bid,sgpbid) +% Leeper-Sims-Zha BVAR setup +% general program to setup A0 matrix and compute the likelihood +% requires +% x (parameter vector) +% a0indx (matrix indicating the free parameters in A0) +% fss (forecast sample size) +% nvar (number of variables) +% ncoef (number of coefficients in a single equation in A+) +% phi (r.h.s. observations in the system for A+) +% y (l.h.s. observations for A0) +% xd0 (X(0) for dummy observations y*(1)) +% ys1 (dummy initial observations y*(1)) +% A0b (initial prior mean on A0) +% sg0bid (diagonal of Sigma0_bar, unweighted prior vcv on the parameters in i-th equation in A0) +% sgpbid (diagonal of Sigma+_bar, unweighted prior vcv on the parameters in i-th equation in A+) +% +global vaya0 vaha0 vaxah vahad vbiga GlbAph +% pre-allocate GlbAph to be zeros(nvar,lags*nvar+1=ncoef) + +GlbAphh=zeros(ncoef,nvar); + + +nhp = 0; % <<>> 4 hyperparameters +na0p = length(a0indx); % <<>> number of A0 parameters +nfp = na0p+nhp; + +a0 = zeros(nvar^2,1); +a0(a0indx) = x(1:na0p); +A0h = reshape(a0,nvar,nvar); + % restrictions on A0 + +[A0hl,A0hu] = lu(A0h); + +% ** hyperparameters +%%mu = x(na0p+1:nfp); +mu = ones(5,1); +mu(1) = 1; +mu(2) = 0.2; +mu(3) = 20; +mu(5) = 1; +% results from ...\dummy1\foreh\pmdd6.out +% +% mu(1): overall tightness and also for A0; +% mu(2): relative tightness for A+; +% mu(3): relative tightness for the constant term; +% mu(4): relative tightness for dummy initial observations; +% mu(5): relative tightness for prior dummy observations. + +% ** weight prior dummy observations +%phi(1:nvar,:) = (mu(5)^2/mu(1)^2)*phi(1:nvar,:); +%y(1:nvar,:) = (mu(5)^2/mu(1)^2)*y(1:nvar,:); +% modified by CAS 8/6/96. The dummy obs weights are naturally in std units, not var units. +phi(1:nvar,:) = mu(5)*phi(1:nvar,:); +y(1:nvar,:) = mu(5)*y(1:nvar,:); + +% ** set up the conditional prior variance sg0bi and sgpbi. +sg0bida = mu(1)^2*sg0bid; +sgpbida = mu(1)^2*mu(2)^2*sgpbid; +sgpbida(ncoef) = mu(1)^2*mu(3)^2; +sg0bi = diag(sg0bida); +sgpbi = diag(sgpbida); + +% +% ** some common terms +[u d v]=svd(phi,0); %trial +% xtx = phi'*phi; %trial +vd=v.*(ones(size(v,2),1)*diag(d)'); %trial +xtx=vd*vd'; +% M = eye(fss) - phi*(xtx\phi'); % not used except in line below %trial +yu = y'*u; %trial +cxyxx=yu*yu'; %trial +ymy=y'*y-cxyxx; %trial +%ymy = y'*M*y; +%cxy = phi'*y; %trial +cxy = vd*yu'; %trial +%cxpy = xtx\cxy; %not used further except in line below +%cxyxx = cxy'*cxpy; + +% ** estimate A+_hat conditional on A0, ncoef*nvar, but not using full prior +%GlbAph = cxpy*A0h; + + +%%%%%%% +%%% build the objective function below +%%%%%%% +% +t1f = diag(abs(A0hu)); +t1f = log(t1f); +tt1 = (-1.0)*fss*sum(t1f); + +tt3 = 0; +tt4 = 0; + +stril = 0; +Hp0p = zeros(ncoef); +% initializing Htd_+0*inv(Htd_00)*Htd_0+: conditional prior covariance +for i = 1:nvar + stri = find(A0h(:,i)); + strm = length(stri); + + A0hb = A0h(stri,i)-A0b(stri,i); + Hp0 = zeros(ncoef,strm); + % initializing Htd_+0*inv(Htd_00)*Htd_0 + + % ** set up the conditional prior variance sg0bi and sgpbi. + sg0bd = zeros(stri,1); + sg0bd = sg0bida(stri); + sg0b = diag(sg0bd); + + % ** set up the unconditional prior variance on A0i and A+i + XX = zeros(nvar,strm); + XX(stri,:) = eye(strm); % XX in Gelman, etel, on p479 + % + Hb = zeros(strm+ncoef); % including A0i and A+i + Hb(1:strm,1:strm) = sg0b; + Hb(1:strm,strm+1:strm+nvar) = sg0b*XX'; + Hb(strm+1:strm+nvar,1:strm) = XX*sg0b; + Hb(strm+1:strm+nvar,strm+1:strm+nvar) = XX*sg0b*XX'+sgpbi(1:nvar,1:nvar); + Hb(strm+nvar+1:strm+ncoef,strm+nvar+1:strm+ncoef) = ... + sgpbi(nvar+1:ncoef,nvar+1:ncoef); + + % ** set up the final prior variance on A0i and A+i, i =1,..,6 separately. + % ** using dummy initial observations + %zs1 = [ys1(:,stri) -xd0]; % z*1 for the 1st equation + + % * final unconditional prior variance on A0i and A+i + %Hbzs1=Hb*zs1'; + %Htd = Hb - Hbzs1*((zs1*Hbzs1+mu(1)^2*mu(4)^2*eye(nvar))\Hbzs1'); + % CAS mod 8/7/96: Hope is that dropping above two lines in favor of the one below + % removes double-counting of dummy observations and a possible scale sensitivity. + Htd = Hb; + % H_~: td: tilde for ~ + + % * final conditional prior variance on A+i give that on A0i, and + % * unconditional variance on A0+ + H0td = Htd(1:strm,1:strm); % unconditional + % ** inverse and chol decomp + H0tdi = inv(H0td); + + % + Hptd10 = Htd(strm+1:strm+nvar,1:strm); + % top matrix of nvar in Htd_+0 + Hptd100 = Hptd10*H0tdi; + Hp0(1:nvar,:) = Hptd100; + Hptd101 = Hptd100*Hptd10'; + Hp0p(1:nvar,1:nvar) = Hptd101; + Hptd = Htd(strm+1:strm+ncoef,strm+1:strm+ncoef) - Hp0p; + % condtional on A0i, H_plus_tilde + + % ** inverse + Hptdi = inv(Hptd); + + % common term + xxhp = xtx+Hptdi; + Vxxhp = chol(xxhp); + % inverse of Vxxhp is the upper triangular decomp + % of inv(Vxxhp) (covariance of alpst) + + % ** final conditional prior mean on A+i + alptd = zeros(ncoef,1); + alptd(1:nvar) = XX*A0b(stri,i); + %alptd = alptd + Hptdf*(H0tdi*A0hb); CAS efficiency improvement 8/8/96 + alptd = alptd + Hp0*A0hb; + % conditional on A0i, alpha-plus-tilde + + % * alpha_plus_* for the ith equation, ncoef*1 + % *alps = xxhp\(phi'*y*A0h(:,i)+HptdDinalptd); + HptdDinalptd=Hptdi*alptd; + xaha = cxy*A0h(:,i)+HptdDinalptd; %CAS 8/7/96. Replaced phi'*y with cxy + alpst = xaha'/xxhp; + GlbAph(i,:)=alpst; + % alpst': transpose of alps. + GlbAphh(:,i)=alpst' + Vxxhp\randn(length(alpst),1); + % posterior alpha_plus_* + + + % ** 3rd bid term in i-th equation, + % ** with all other 3rd big terms prior to i-th + A0hy = A0h(:,i)'*ymy; + A0hbH = A0hb'*H0tdi; + tt3 = tt3 + A0hy*A0h(:,i) + A0hbH*A0hb; + + % ** 4th bid term in i-th equation, + % ** with all other 4th big terms prior to i-th + A0hcxyxx = A0h(:,i)'*cxyxx; + atdHatd = alptd'*HptdDinalptd; + tt4 = tt4 + A0hcxyxx*A0h(:,i)+atdHatd-alpst*xaha; + + stril = stril + strm; +end + +of = tt1 + 0.5*tt3 + 0.5*tt4; + \ No newline at end of file diff --git a/MatlabFiles/probvalsec.m b/MatlabFiles/probvalsec.m new file mode 100755 index 0000000..242a239 --- /dev/null +++ b/MatlabFiles/probvalsec.m @@ -0,0 +1,73 @@ +function [probelow,valow,yhatmean] = probvalsec(yhatprob,yhatpo,ninv,forep,nvar,findex,... + sindex,valix,prolix) +% [probelow,valow,yhatmean] = probvalsec(yhatprob,yhatpo,ninv,forep,nvar,findex,... +% sindex,valix,prolix) +% +% Probabilites (below) and values for selected variables and levels. +% This program takes outputs from "histpdfcnt.m" which must be run first. +% Compute (1) the probability of the x-value (such as FFR) that is below a level +% prespecified by valix (e.g., probability of R below 5%); (2) the x-value +% (such as median or .60 lower-tail value) below which the probability is at a level +% prespecified by "prolix" (e.g., median when 0.50 is prespecified); (3) the mean +% of the x-values (e.g., the mean of Pcm, M2, FFR, etc.). +% +% yhatprob: 2+ninv-by-forep*shockp(=1 here)*nvar. Probability (NOT density) at each bin +% yhatpo: 2+ninv-by-forep*shockp(=1 here)*nvar. Bin position (x-axis) in relation to yhat +% ninv: the number of bins which are small interior intervals on the x-axis +% forep: forecast periods -- 1st dim (must be compatible with findex) +% nvar: number of shocks or variables -- 2nd dim (must be compatible with sindex) +% findex: index for sected forecast periods 1st dim (c.f., forep) +% sindex: index for selected shocks or variables, 2nd dim (c.f., nvar) +% valix: length(findex)-by-length(sindex). Selected values on the x-axis +% prolix: length(findex)-by-length(sindex). Selected (below) probabilites +%----------- +% probelow: length(findex)-by-length(sindex). The probability of the x-value +% (such as FFR) that is below a level prespecified by valix (e.g., +% probability of R below 5%). +% valow: length(findex)-by-length(sindex). The x-value (such as median or .60 +% lower-tail value) below which the probability is at a level +% prespecified by "prolix" (e.g., median when 0.50 is prespecified); +% yhatmean: forep-by-nvar. The mean of forecasts of Pcm, M2, FFR, etc. +% +% 3/25/99 Tao A. Zha + +yhatprob2=reshape(yhatprob,2+ninv,forep,nvar); +yhatpo2=reshape(yhatpo,2+ninv,forep,nvar); +% +%** Mean +yhatmean0 = sum(yhatprob.*yhatpo,1); +yhatmean = reshape(yhatmean0,forep,nvar); +% +probelow=zeros(length(findex),length(sindex)); + % probablity of the x-value that is below a specified level + % E.g., probability of R below 5%. +valow=probelow; + % x-value for the probability that is below a specified level + % E.g., median when 0.50 is specified. +cumprob=cumsum(yhatprob2,1); % cumulative probabilities +% +count1=0; +for k1=sindex % forecast variables (or shocks) + count1=count1+1; + count2=0; + for k2=findex % forecast periods + count2=count2+1; + posix = max(find(yhatpo2(:,k2,k1)<valix(count2,count1))); + % index for the position corr. to the x-value respeicied. + if isempty(posix) + probelow(count2,count1) = cumprob(1,k2,k1); + else + probelow(count2,count1) = cumprob(posix,k2,k1); + end + posix1 = max(find(cumprob(:,k2,k1)<prolix(count2,count1))); + % index for the position corr. probability (below) specified. + if isempty(posix1) + valow(count2,count1) = yhatpo2(1,k2,k1); + else + valow(count2,count1) = yhatpo2(posix1,k2,k1); + end + end +end + + + diff --git a/MatlabFiles/pwf234.m b/MatlabFiles/pwf234.m new file mode 100755 index 0000000..7682685 --- /dev/null +++ b/MatlabFiles/pwf234.m @@ -0,0 +1,208 @@ +function of = pwf234(x,idmat0,idmat1,fss,nvar,ncoef,phi, ... + y,A0b,sg0bid,sgpbid) +%function of = pmddf232(x,idmat,fss,nvar,ncoef,phi, ... +% y,A0b,sg0bid,sgpbid) +% Leeper-Sims-Zha BVAR setup +% general program to setup A0 matrix and compute the likelihood +% requires +% x (parameter vector) +% a0indx (matrix indicating the free parameters in A0) +% fss (forecast sample size) +% nvar (number of variables) +% ncoef (number of coefficients in a single equation in A+) +% phi (r.h.s. observations in the system for A+) +% y (l.h.s. observations for A0) +% A0b (initial prior mean on A0) +% sg0bid (diagonal of Sigma0_bar, unweighted prior vcv on the parameters in i-th equation in A0) +% sgpbid (diagonal of Sigma+_bar, unweighted prior vcv on the parameters in i-th equation in A+) +% +% Revisions by CAS 9/27/96: If we transmit idmat, rather than a0indx, we can scale the elements of +% idmat so that it carries information about relative prior variances. +% +% Revsions by TZ, 10/12/96: efficiency improvement by streamlining the previous code +% according to the general setup in Sims and Zha "Bayesian Methods for ...". +% +global vaya0 vaha0 vaxah vahad vbiga GlbAph FRESHFUNCTION +% FRESHFUNCTION added 8/20/90 by CAS. It signals the pmddg23 whether the global variables +% it uses have been refreshed by a new pmddf231 call since the last gradient call. +a0indx=find(idmat0); +% pre-allocate GlbAph to be zeros(nvar,lags*nvar+1=ncoef) + +nhp = 0; % <<>> 4 hyperparameters +na0p = length(a0indx); % <<>> number of A0 parameters +nfp = na0p+nhp; + +% *** initializing +vaya0 = zeros(na0p,1); +vaha0 = zeros(na0p,1); +vaxah = zeros(na0p,1); +vahad = zeros(na0p,1); +vbiga = zeros(na0p,1); + + +A0h = zeros(nvar,nvar); +A0h(a0indx) = x(1:na0p); +%A0h = reshape(a0,nvar,nvar); CAS 9/24/96. The reshape is not necessary if a0 starts as nvar x nvar + % restrictions on A0 + +[A0hl,A0hu] = lu(A0h); + +% ** hyperparameters +%%mu = x(na0p+1:nfp); +mu = ones(5,1); +mu(1) = 1; +%mu(1) = 2; +mu(2) = 0.3; +mu(3) = 25; +%mu(4)=1; +mu(4)=1; +mu(5) =1; +%mu(5) = 40; +% results from ...\dummy1\foreh\pmdd6.out +% +% mu(1): overall tightness and also for A0; +% mu(2): relative tightness for A+; +% mu(3): relative tightness for the constant term; +% mu(4): weight on single dummy initial observation including constant; +% mu(5): weight on nvar sums of coeffs dummy observations. + +% ** weight prior dummy observations +%phi(1:nvar,:) = (mu(5)^2/mu(1)^2)*phi(1:nvar,:); +%y(1:nvar,:) = (mu(5)^2/mu(1)^2)*y(1:nvar,:); +%phi(ndobs,:) = mu +% modified by CAS 8/6/96. The dummy obs weights are naturally in std units, not var units. +%%phi(1:nvar,:) = mu(5)*phi(1:nvar,:); +%%y(1:nvar,:) = mu(5)*y(1:nvar,:); +%%phi(nvar+1,:) = mu(4)*phi(nvar+1,:); +%%y(nvar+1,:) = mu(4)*y(nvar+1,:); + +% ** set up the conditional prior variance sg0bi and sgpbi. +%%sg0bida = mu(1)^2*sg0bid; +sgpbida = mu(1)^2*mu(2)^2*sgpbid; +sgpbida(ncoef) = mu(1)^2*mu(3)^2; +sgppbd = sgpbida(nvar+1:ncoef); % corresponding to A++, in an SZ paper +sgppb = diag(sgppbd); + +% +% ** some common terms +[u d v]=svd(phi,0); %trial +% xtx = phi'*phi; %trial +vd=v.*(ones(size(v,2),1)*diag(d)'); %trial +xtx=vd*vd'; +% M = eye(fss) - phi*(xtx\phi'); % not used except in line below %trial +yu = y'*u; %trial +cxyxx=yu*yu'; %trial +ymy=y'*y-cxyxx; %trial +%ymy = y'*M*y; +%cxy = phi'*y; %trial +cxy = vd*yu'; %trial +%cxpy = xtx\cxy; %not used further except in line below +%cxyxx = cxy'*cxpy; + +% ** estimate A+_hat conditional on A0, ncoef*nvar, but not using full prior +%GlbAph = cxpy*A0h; + + +%%%%%%% +%%% build the objective function below +%%%%%%% +% +t1f = diag(abs(A0hu)); +t1f = log(t1f); +% * without the prior |A0|^k +tt1 = (-1.0)*fss*sum(t1f); + +tt3 = 0; +tt4 = 0; + + +stril = 0; +Hp0p = zeros(ncoef); +% initializing Htd_+0*inv(Htd_00)*Htd_0+: conditional prior covariance +for i = 1:nvar + stri = find(idmat0(:,i)); %CAS change 9/24/96, to avoid slim chance of an exact zero in x vector + %at some point during an optimization. + strm = length(stri); + + %%A0hb = A0h(stri,i)-A0b(stri,i); + + % ** set up the conditional prior variance sg0bi and sgpbi. + % sg0bd = zeros(stri,1); Commented out by CAS, 9/24/96. Looks like this meant to have + % strm where it has stri, and in any case it is "overwritten" below. + %------------------------------ + % Introduce prior information on which variables "belong" in various equations. + % In this first trial, we just introduce this information here, in a model-specific way. + % Eventually this info has to be passed parametricly. In our first shot, we just damp down + % all coefficients except those on the diagonal. + %%factor0=idmat0(:,i); + %%sg0bd = sg0bida(stri).*factor0(stri); + %%sg0b = diag(sg0bd); + % + factor1=idmat1(:,i); + sg1bd = sgpbida(1:nvar).*factor1; + sg1b = diag(sg1bd); + + % ** set up the unconditional prior variance on A0i and A+i + XX = zeros(nvar,strm); + XX(stri,:) = eye(strm); % XX in Gelman, etel, on p479 + % + % * final conditional prior variance on A+i give that on A0i, and + % * unconditional variance on A0+ + %%H0td = sg0b; % unconditional + % H_~: td: tilde for ~ + % ** inverse and chol decomp + %%H0tdi = inv(H0td); + + % + Hptd = zeros(ncoef); + Hptd(1:nvar,1:nvar)=sg1b; + Hptd(nvar+1:ncoef,nvar+1:ncoef)=sgppb; + % condtional on A0i, H_plus_tilde + + % ** inverse + Hptdi = inv(Hptd); + %%chhh=Hptdi*Hp0; + chhh = zeros(ncoef,strm); % <<>> the term not used for "of"\ + chhh(1:nvar,:) = Hptdi(1:nvar,1:nvar)*XX; + chhh1 = XX'*chhh(1:nvar,:); + + % common term + xxhp = xtx+Hptdi; + + % ** final conditional prior mean on A+i + alptd = zeros(ncoef,1); + alptd(1:nvar) = XX*A0h(stri,i); + % conditional on A0i, alpha-plus-tilde + + % * alpha_plus_* for the ith equation, ncoef*1 + % *alps = xxhp\(phi'*y*A0h(:,i)+HptdDinalptd); + %%HptdDinalptd=Hptdi*alptd; + HptdDinalptd=zeros(ncoef,1); + HptdDinalptd(1:nvar) = Hptdi(1:nvar,1:nvar)*alptd(1:nvar); + xaha = cxy*A0h(:,i)+HptdDinalptd; %CAS 8/7/96. Replaced phi'*y with cxy + alpst = xaha'/xxhp; + GlbAph(i,:)=alpst; + % alpst': transpose of alps. + + % ** 3rd bid term in i-th equation, + % ** with all other 3rd big terms prior to i-th + A0hy = A0h(:,i)'*ymy; + %%A0hbH = A0hb'*H0tdi; + %%tt3 = tt3 + A0hy*A0h(:,i) + A0hbH*A0hb; + tt3 = tt3 + A0hy*A0h(:,i); + % ** 4th bid term in i-th equation, + % ** with all other 4th big terms prior to i-th + A0hcxyxx = A0h(:,i)'*cxyxx; + %%atdHatd = alptd'*HptdDinalptd; % efficiency improvement + atdHatd = alptd(1:nvar)'*HptdDinalptd(1:nvar); + tt4 = tt4 + A0hcxyxx*A0h(:,i)+atdHatd-alpst*xaha; + + stril = stril + strm; +end + +%disp(sprintf('Loop %d end: %g', i, toc)) + +%e_tfat = toc + +of = tt1 + 0.5*tt3 + 0.5*tt4; +FRESHFUNCTION=1; \ No newline at end of file diff --git a/MatlabFiles/pwf235.m b/MatlabFiles/pwf235.m new file mode 100755 index 0000000..bddfea2 --- /dev/null +++ b/MatlabFiles/pwf235.m @@ -0,0 +1,190 @@ +function [of,GlbAphh] = pwf235(x,idmat0,idmat1,fss,nvar,ncoef,phi, ... + y,A0b,sg0bid,sgpbid) +%function of = pmddf232(x,idmat,fss,nvar,ncoef,phi, ... +% y,A0b,sg0bid,sgpbid) +% Leeper-Sims-Zha BVAR setup +% general program to setup A0 matrix and compute the likelihood +% requires +% x (parameter vector) +% a0indx (matrix indicating the free parameters in A0) +% fss (forecast sample size) +% nvar (number of variables) +% ncoef (number of coefficients in a single equation in A+) +% phi (r.h.s. observations in the system for A+) +% y (l.h.s. observations for A0) +% A0b (initial prior mean on A0) +% sg0bid (diagonal of Sigma0_bar, unweighted prior vcv on the parameters in i-th equation in A0) +% sgpbid (diagonal of Sigma+_bar, unweighted prior vcv on the parameters in i-th equation in A+) +% +% Revisions by CAS 9/27/96: If we transmit idmat, rather than a0indx, we can scale the elements of +% idmat so that it carries information about relative prior variances. +% +% Revsions by TZ, 10/13/96: efficiency improvement by streamlining the previous code +% according to the general setup in Sims and Zha "Bayesian Methods for ...". +% +global vaha0 vaMMa0 GlbAph FRESHFUNCTION +% FRESHFUNCTION added 8/20/90 by CAS. It signals the pmddg23 whether the global variables +% it uses have been refreshed by a new pmddf231 call since the last gradient call. +a0indx=find(idmat0); +GlbAphh=zeros(ncoef,nvar); +% pre-allocate GlbAph to be zeros(nvar,lags*nvar+1=ncoef) + +nhp = 0; % <<>> 4 hyperparameters +na0p = length(a0indx); % <<>> number of A0 parameters +nfp = na0p+nhp; + +% *** initializing +vaha0 = zeros(na0p,1); +vaMMa0 = zeros(na0p,1); + +% +A0h = zeros(nvar,nvar); +A0h(a0indx) = x(1:na0p); +%A0h = reshape(a0,nvar,nvar); CAS 9/24/96. The reshape is not necessary if a0 starts as nvar x nvar + % restrictions on A0 + +[A0hl,A0hu] = lu(A0h); + +% ** hyperparameters +%%mu = x(na0p+1:nfp); +mu = ones(5,1); +mu(1) = 1; +%mu(1) = 2; +mu(2) = 0.2; +mu(3) = 1; +%mu(4)=1; +mu(4)=10; +mu(5) =1; +%mu(5) = 40; +% results from ...\dummy1\foreh\pmdd6.out +% +% mu(1): overall tightness and also for A0; +% mu(2): relative tightness for A+; +% mu(3): relative tightness for the constant term; +% mu(4): weight on single dummy initial observation including constant; +% mu(5): weight on nvar sums of coeffs dummy observations. + +% ** weight prior dummy observations +%phi(1:nvar,:) = (mu(5)^2/mu(1)^2)*phi(1:nvar,:); +%y(1:nvar,:) = (mu(5)^2/mu(1)^2)*y(1:nvar,:); +%phi(ndobs,:) = mu +% modified by CAS 8/6/96. The dummy obs weights are naturally in std units, not var units. +phi(1:nvar,:) = mu(5)*phi(1:nvar,:); +y(1:nvar,:) = mu(5)*y(1:nvar,:); +phi(nvar+1,:) = mu(4)*phi(nvar+1,:); +y(nvar+1,:) = mu(4)*y(nvar+1,:); + +% ** set up the conditional prior variance sg0bi and sgpbi. +sg0bida = mu(1)^2*sg0bid; +sgpbida = mu(1)^2*mu(2)^2*sgpbid; +sgpbida(ncoef) = mu(1)^2*mu(3)^2; +sgppbd = sgpbida(nvar+1:ncoef); % corresponding to A++, in an SZ paper +sgppbdi = 1./sgppbd; +%sgppb = diag(sgppbd); + +% +% ** some common terms +[u d v]=svd(phi,0); %trial +% xtx = phi'*phi; %trial +vd=v.*(ones(size(v,2),1)*diag(d)'); %trial +xtx=vd*vd'; +% M = eye(fss) - phi*(xtx\phi'); % not used except in line below %trial +yu = y'*u; %trial +cxyxx=yu*yu'; %trial +yty=y'*y; +ymy=yty-cxyxx; %trial +%ymy = y'*M*y; +%cxy = phi'*y; %trial +cxy = vd*yu'; %trial +cyx = cxy'; +%cxpy = xtx\cxy; %not used further except in line below +%cxyxx = cxy'*cxpy; + +% ** estimate A+_hat conditional on A0, ncoef*nvar, but not using full prior +%GlbAph = cxpy*A0h; + + +%%%%%%% +%%% build the objective function below +%%%%%%% +% +t1f = diag(abs(A0hu)); +t1f = log(t1f); +% * without the prior |A0|^k +tt1 = (-1.0)*fss*sum(t1f); + +tt3 = 0; + +stril = 0; +Hptd = zeros(ncoef); +Hptdi=Hptd; +Hptd(nvar+1:ncoef,nvar+1:ncoef)=diag(sgppbd); +Hptdi(nvar+1:ncoef,nvar+1:ncoef)=diag(sgppbdi); + % condtional on A0i, H_plus_tilde +for i = 1:nvar + stri = find(idmat0(:,i)); %CAS change 9/24/96, to avoid slim chance of an exact zero in x vector + %at some point during an optimization. + strm = length(stri); + + A0hb = A0h(stri,i)-A0b(stri,i); + + % ** set up the conditional prior variance sg0bi and sgpbi. + % sg0bd = zeros(stri,1); Commented out by CAS, 9/24/96. Looks like this meant to have + % strm where it has stri, and in any case it is "overwritten" below. + %------------------------------ + % Introduce prior information on which variables "belong" in various equations. + % In this first trial, we just introduce this information here, in a model-specific way. + % Eventually this info has to be passed parametricly. In our first shot, we just damp down + % all coefficients except those on the diagonal. + factor0=idmat0(:,i); + sg0bd = sg0bida(stri).*factor0(stri); + sg0bdi = 1./sg0bd; + %sg0b = diag(sg0bd); + % + factor1=idmat1(:,i); + sg1bd = sgpbida(1:nvar).*factor1; + sg1bdi = 1./sg1bd; + %sg1b = diag(sg1bd); + + % ** set up the unconditional prior variance on A0i and A+i + XX = zeros(nvar,strm); + XX(stri,:) = eye(strm); % XX in Gelman, etel, on p479 + % + % * final conditional prior variance on A+i give that on A0i, and + % * unconditional variance on A0+ + H0td = diag(sg0bd); % unconditional + % H_~: td: tilde for ~ + % ** inverse and chol decomp + H0tdi = diag(sg0bdi); + + % + Hptd(1:nvar,1:nvar)=diag(sg1bd); + Hptdi(1:nvar,1:nvar)=diag(sg1bdi); + % condtional on A0i, H_plus_tilde + + % common terms + xxhp = xtx+Hptdi; + Vxxhp = chol(xxhp); + % inverse of Vxxhp is the upper triangular decomp + % of inv(Vxxhp) (covariance of alpst) + A0hbH = A0hb'*H0tdi; + H1p_1 = zeros(ncoef,nvar); + H1p_1(1:nvar,:) = Hptdi(1:nvar,1:nvar); + %%Hm = (cyx+H1p_1')*(xxhp\(cxy+H1p_1)); + Hm1 = (cyx+H1p_1')/xxhp; + Hm2 = cxy+H1p_1; + GlbAph(i,:) = A0h(stri,i)'*XX'*Hm1; % alpha_plus_*_transpose + GlbAphh(:,i)=GlbAph(i,:)' + Vxxhp\randn(length(GlbAph(i,:)),1); + % posterior alpha_plus_* + + %%alpMpyh = A0h(stri,i)'*XX'*(yty+Hptdi(1:nvar,1:nvar)-Hm)*XX; + alpMpyh = A0h(stri,i)'*XX'*(yty+Hptdi(1:nvar,1:nvar))*XX - GlbAph(i,:)*Hm2*XX; + + % ** 3rd bid term in i-th equation, + % ** with all other 3rd big terms before the i-th equation + tt3 = tt3 + A0hbH*A0hb + alpMpyh*A0h(stri,i); + + stril = stril + strm; +end + +of = tt1 + 0.5*tt3; \ No newline at end of file diff --git a/MatlabFiles/qplot2.m b/MatlabFiles/qplot2.m new file mode 100755 index 0000000..a6e033f --- /dev/null +++ b/MatlabFiles/qplot2.m @@ -0,0 +1,63 @@ +function dummyout = qplot2(datavector,inityear,initquart,quarter_label) +%QPLOT Quarterly data plot +%QPLOT(DATA,YEAR,QUARTER,LABEL) plots quarterly data against years +%and quarters begining with YEAR:QUARTER. Quarters are not labeled if +%LABEL=0. +% +%e.g. if GDP is a vector containing quarterly observations +%on gdp beginning in the third quarter of 1985, the command +%QPLOT(GDP,85,3) plots the observations against years and quarters. +%You may specify the year as 85 or 1985 but using 85 looks better. +% +%Setting LABEL to the values 5 or 10 will cause only every fifth +%or every tenth year to be labeled beginning with the first decade +%after YEAR. + +% QPLOT was written by Clark A. Burdick of the research +% department of the Federal Reserve Bank of Atlanta. +% Original: June 18, 1997 +% Last Modified: July 23, 1997 + +% TO BE DONE: +% 1. Add better bullet proofing +% 2. Cleaning and streamlining +% 3. Better string manipulation +% 4. Options for XTick + + +if nargin == 1 + warning('Proper usage is QPLOT(data,year,quarter,label') + inityear = input('What is the initial year? '); + initquart = input('What is the initial quarter? '); + quarter_label = input('Enter 1 for labeled quarters, 0 for unlableled quarters: '); +end + +if nargin == 3 + quarter_label = 1; +end + +nquart = length(datavector); +nyear = ceil(nquart/4); + +years = inityear + [0:nyear]; +if quarter_label == 5 + years = years.*[round(years/5) == years/5]; +end +if quarter_label == 10 + years = years.*[round(years/10) == years/10]; +end + +xtickvec = (kron(years,[1 0 0 0])+kron(ones(1,nyear+1),[0 2 3 4]))'; + +if quarter_label ~= 1 + xtickvec = num2str(xtickvec); + xtickvec = strrep(xtickvec,{' 0'},{' '}); + xtickvec = strrep(xtickvec,{' 2'},{' '}); + xtickvec = strrep(xtickvec,{' 3'},{' '}); + xtickvec = strrep(xtickvec,{' 4'},{' '}); +end + + +plot(datavector); +set(gca,'XTick',[1:nquart]); +set(gca,'XTickLabel',xtickvec(initquart:initquart+(nquart-1))); \ No newline at end of file diff --git a/MatlabFiles/qzdiv.m b/MatlabFiles/qzdiv.m new file mode 100755 index 0000000..9ab80a6 --- /dev/null +++ b/MatlabFiles/qzdiv.m @@ -0,0 +1,41 @@ +function [A,B,Q,Z,v] = qzdiv(stake,A,B,Q,Z,v) +%function [A,B,Q,Z,v] = qzdiv(stake,A,B,Q,Z,v) +% +% Takes U.T. matrices A, B, orthonormal matrices Q,Z, rearranges them +% so that all cases of abs(B(i,i)/A(i,i))>stake are in lower right +% corner, while preserving U.T. and orthonormal properties and Q'AZ' and +% Q'BZ'. The columns of v are sorted correspondingly. +% +% by Christopher A. Sims +% modified (to add v to input and output) 7/27/00 +vin = nargin==6; +if ~vin + v=[]; +end +[n jnk] = size(A); +root = abs([diag(A) diag(B)]); +root(:,1) = root(:,1)-(root(:,1)<1.e-13).*(root(:,1)+root(:,2)); +root(:,2) = root(:,2)./root(:,1); +for i = n:-1:1 + m=0; + for j=i:-1:1 + if (root(j,2) > stake | root(j,2) < -.1) + m=j; + break + end + end + if (m==0) + return + end + for k=m:1:i-1 + [A B Q Z] = qzswitch(k,A,B,Q,Z); + tmp = root(k,2); + root(k,2) = root(k+1,2); + root(k+1,2) = tmp; + if vin + tmp=v(:,k); + v(:,k)=v(:,k+1); + v(:,k+1)=tmp; + end + end +end diff --git a/MatlabFiles/qzdivct.m b/MatlabFiles/qzdivct.m new file mode 100755 index 0000000..289062c --- /dev/null +++ b/MatlabFiles/qzdivct.m @@ -0,0 +1,70 @@ +function [A,B,Q,Z] = qzdivct(stake,A,B,Q,Z) +%function [A,B,Q,Z] = qzdivct(stake,A,B,Q,Z) +% +% Takes U.T. matrices A, B, orthonormal matrices Q,Z, rearranges them +% so that all cases of real(B(i,i)/A(i,i))>stake are in lower right +% corner, while preserving U.T. and orthonormal properties and Q'AZ' and +% Q'BZ'. abs(A(i,i))<1e-11 is interpreted as a zero and as generating +% an infinitely positive real part of the ratio. All i's for which this +% criterion are satisfied are grouped together in the lower right corner +% of the lower right corner, with the non-zero roots above them. This +% version differs from +% qzdiv in that it works on the real part's value, as is appropriate for +% continuous time models, instead of on the absolute value, as is +% appropriate for discrete time models. +% +realsmall=sqrt(eps)*10; +%realsmall=1e-3; +[n jnk] = size(A); +root = [diag(A) diag(B)]; +% first sort on the non-zero root criterion +xdown0 = abs(root(:,1))<realsmall; +xdown = (xdown0 | (real(root(:,2)./(xdown0+root(:,1))) > stake)); +for i = n:-1:1 + m=0; + for j=i:-1:1 + if xdown0(j) + m=j; + break + end + end + if (m==0) + break + end + for k=m:1:i-1 + [A B Q Z] = qzswitch(k,A,B,Q,Z); + root=[diag(A) diag(B)]; + xdown0(k:k+1)=flipud(xdown0(k:k+1)); + xdown(k:k+1)=flipud(xdown(k:k+1)); + if any(xdown(k:k+1)~=(xdown0(k:k+1) | (real(root(k:k+1,2)./(xdown0(k:k+1)+root(k:k+1,1)))) > stake)) + disp('xdown shift during 0 pack at i,k:') + disp([i k]) + end + end +end +% now repeat, using the stake criterion +for i = n:-1:1 + m=0; + for j=i:-1:1 + if xdown(j) + m=j; + break + end + end + if (m==0) + return + end + for k=m:1:i-1 + gevOld=root(k:k+1,:); + [A B Q Z] = qzswitch(k,A,B,Q,Z); + root=[diag(A) diag(B)]; + xdown0(k:k+1)=flipud(xdown0(k:k+1)); + xdown(k:k+1)=flipud(xdown(k:k+1)); + if any(xdown(k:k+1)~=(xdown0(k:k+1) | (real(root(k:k+1,2)./(xdown0(k:k+1)+root(k:k+1,1)))) > stake)) + disp('xdown shift during pos pack at i,k:') + disp([i k]) + gev=root(k:k+1,:); + [gevOld gevOld(:,1).\gevOld(:,2);gev gev(:,1).\gev(:,2)] + end + end +end \ No newline at end of file diff --git a/MatlabFiles/qzswitch.m b/MatlabFiles/qzswitch.m new file mode 100755 index 0000000..93c3664 --- /dev/null +++ b/MatlabFiles/qzswitch.m @@ -0,0 +1,60 @@ +function [A,B,Q,Z] = qzswitch(i,A,B,Q,Z) +%function [A,B,Q,Z] = qzswitch(i,A,B,Q,Z) +% +% Takes U.T. matrices A, B, orthonormal matrices Q,Z, interchanges +% diagonal elements i and i+1 of both A and B, while maintaining +% Q'AZ' and Q'BZ' unchanged. If diagonal elements of A and B +% are zero at matching positions, the returned A will have zeros at both +% positions on the diagonal. This is natural behavior if this routine is used +% to drive all zeros on the diagonal of A to the lower right, but in this case +% the qz transformation is not unique and it is not possible simply to switch +% the positions of the diagonal elements of both A and B. + realsmall=sqrt(eps)*10; +%realsmall=1e-3; +a = A(i,i); d = B(i,i); b = A(i,i+1); e = B(i,i+1); +c = A(i+1,i+1); f = B(i+1,i+1); + % A(i:i+1,i:i+1)=[a b; 0 c]; + % B(i:i+1,i:i+1)=[d e; 0 f]; +if (abs(c)<realsmall & abs(f)<realsmall) + if abs(a)<realsmall + % l.r. coincident 0's with u.l. of A=0; do nothing + return + else + % l.r. coincident zeros; put 0 in u.l. of a + wz=[b; -a]; + wz=wz/sqrt(wz'*wz); + wz=[wz [wz(2)';-wz(1)'] ]; + xy=eye(2); + end +elseif (abs(a)<realsmall & abs(d)<realsmall) + if abs(c)<realsmall + % u.l. coincident zeros with l.r. of A=0; do nothing + return + else + % u.l. coincident zeros; put 0 in l.r. of A + wz=eye(2); + xy=[c -b]; + xy=xy/sqrt(xy*xy'); + xy=[[xy(2)' -xy(1)'];xy]; + end +else + % usual case + wz = [c*e-f*b, (c*d-f*a)']; + xy = [(b*d-e*a)', (c*d-f*a)']; + n = sqrt(wz*wz'); + m = sqrt(xy*xy'); + if m<eps*100 + % all elements of A and B proportional + return + end + wz = n\wz; + xy = m\xy; + wz = [wz; -wz(2)', wz(1)']; + xy = [xy;-xy(2)', xy(1)']; +end +A(i:i+1,:) = xy*A(i:i+1,:); +B(i:i+1,:) = xy*B(i:i+1,:); +A(:,i:i+1) = A(:,i:i+1)*wz; +B(:,i:i+1) = B(:,i:i+1)*wz; +Z(:,i:i+1) = Z(:,i:i+1)*wz; +Q(i:i+1,:) = xy*Q(i:i+1,:); \ No newline at end of file diff --git a/MatlabFiles/reset_ini_seed.m b/MatlabFiles/reset_ini_seed.m new file mode 100755 index 0000000..522d012 --- /dev/null +++ b/MatlabFiles/reset_ini_seed.m @@ -0,0 +1,11 @@ +function reset_ini_seed(seednumber) +%After Matlab starts, run this function to reset the seed number; otherwise, Matlab automatically resets to the same initial seed. +% seednumber: 0 -- random state reset to the clock time; + +if seednumber + randn('state',seednumber); + rand('state',seednumber); +else + randn('state',fix(100*sum(clock))); + rand('state',fix(100*sum(clock))); +end diff --git a/MatlabFiles/rlrpostr.m b/MatlabFiles/rlrpostr.m new file mode 100755 index 0000000..5bd1462 --- /dev/null +++ b/MatlabFiles/rlrpostr.m @@ -0,0 +1,46 @@ +function [P,H0inv,Hpinv] = rlrpostr(xtx,xty,yty,Ptld,H0invtld,Hpinvtld,Ui,Vi) +% [P,H0inv,Hpinv] = rlrpostr(xtx,xty,yty,Ptld,H0tld,Hptld,Ui,Vi) +% +% Exporting random Bayesian posterior matrices with linear restrictions +% See Waggoner and Zha's Gibbs sampling paper +% +% xtx: X'X: k-by-k where k=ncoef +% xty: X'Y: k-by-nvar +% yty: Y'Y: nvar-by-nvar +% Ptld: cell(nvar,1), linear transformation for random walk prior for the ith equation +% H0invtld: cell(nvar,1), transformed inv covaraince for free parameters in A0(:,i). +% Hpinvtld: cell(nvar,1), transformed inv covaraince for free parameters in A+(:,i); +% Ui: nvar-by-1 cell. In each cell, nvar-by-qi orthonormal basis for the null of the ith +% equation contemporaneous restriction matrix where qi is the number of free parameters. +% With this transformation, we have ai = Ui*bi or Ui'*ai = bi where ai is a vector +% of total original parameters and bi is a vector of free parameters. When no +% restrictions are imposed, we have Ui = I. There must be at least one free +% parameter left for the ith equation. Imported from dnrprior.m. +% Vi: nvar-by-1 cell. In each cell, k-by-ri orthonormal basis for the null of the ith +% equation lagged restriction matrix where k (ncoef) is a total number of RHS variables and +% ri is the number of free parameters. With this transformation, we have fi = Vi*gi +% or Vi'*fi = gi where fi is a vector of total original parameters and gi is a +% vector of free parameters. There must be at least one free parameter left for +% the ith equation. Imported from dnrprior.m. +%----------------- +% P: cell(nvar,1). In each cell, posterior linear transformation for random walk prior for the ith equation % tld: tilda +% H0inv: cell(nvar,1). In each cell, posterior inverse of covariance inv(H0) for the ith equation, +% resembling old SpH in the exponent term in posterior of A0, but not divided by T yet. +% Hpinv: cell(nvar,1). In each cell, posterior inv(Hp) for the ith equation. +% +% Tao Zha, February 2000 + +nvar = size(yty,1); + +P = cell(nvar,1); % tld: tilda +H0inv = cell(nvar,1); % posterior inv(H0), resemble old SpH, but not divided by T yet. +Hpinv = cell(nvar,1); % posterior inv(Hp). + + +for n=1:nvar % one for each equation + Hpinv{n} = Vi{n}'*xtx*Vi{n} + Hpinvtld{n}; + P1 = Vi{n}'*xty*Ui{n} + Hpinvtld{n}*Ptld{n}; + P{n} = Hpinv{n}\P1; + H0inv{n} = Ui{n}'*yty*Ui{n} + H0invtld{n} + Ptld{n}'*Hpinvtld{n}*Ptld{n} ... + - P1'*(Hpinv{n}\P1); +end diff --git a/MatlabFiles/rlrprior.m b/MatlabFiles/rlrprior.m new file mode 100755 index 0000000..f5cd6f8 --- /dev/null +++ b/MatlabFiles/rlrprior.m @@ -0,0 +1,39 @@ +function [Ptld,H0invtld,Hpinvtld] = rlrprior(Ui,Vi,Pi,H0multi,Hpmulti,nvar) +% [Ptld,H0invtld,Hpinvtld] = rlrprior(Ui,Vi,Pi,H0multi,Hpmulti,nvar) +% +% Exporting random Bayesian prior with linear restrictions +% See Waggoner and Zha's Gibbs sampling paper +% +% Ui: nvar-by-1 cell. In each cell, nvar-by-qi orthonormal basis for the null of the ith +% equation contemporaneous restriction matrix where qi is the number of free parameters. +% With this transformation, we have ai = Ui*bi or Ui'*ai = bi where ai is a vector +% of total original parameters and bi is a vector of free parameters. When no +% restrictions are imposed, we have Ui = I. There must be at least one free +% parameter left for the ith equation. Imported from dnrprior.m. +% Vi: nvar-by-1 cell. In each cell, k-by-ri orthonormal basis for the null of the ith +% equation lagged restriction matrix where k (ncoef) is a total number of RHS variables and +% ri is the number of free parameters. With this transformation, we have fi = Vi*gi +% or Vi'*fi = gi where fi is a vector of total original parameters and gi is a +% vector of free parameters. There must be at least one free parameter left for +% the ith equation. Imported from dnrprior.m. +% Pi: ncoef-by-nvar matrix for the ith equation under random walk. Same for all equations +% H0multi: nvar-by-nvar-by-nvar; H0 for different equations under asymmetric prior +% Hpmulti: ncoef-by-ncoef-by-nvar; H+ for different equations under asymmetric prior +% nvar: number of endogenous variables +% -------------------- +% Ptld: cell(nvar,1), linear transformation for random walk prior for the ith equation +% H0invtld: cell(nvar,1), transformed inv covaraince for free parameters in A0(:,i). +% Hpinvtld: cell(nvar,1), transformed inv covaraince for free parameters in A+(:,i); +% +% Tao Zha, February 2000 + +Ptld = cell(nvar,1); % tld: tilda +H0invtld = cell(nvar,1); % H0 for different equations under linear restrictions +Hpinvtld = cell(nvar,1); % H+ for different equations under linear restrictions + +for n=1:nvar % one for each equation + Hpinvtld{n} = Vi{n}'*(Hpmulti(:,:,n)\Vi{n}); + Ptld{n} = (Hpinvtld{n}\Vi{n}')*(Hpmulti(:,:,n)\Pi)*Ui{n}; + H0invtld{n} = Ui{n}'*(H0multi(:,:,n)\Ui{n}) + Ui{n}'*Pi'*(Hpmulti(:,:,n)\Pi)*Ui{n} ... + - Ptld{n}'*Hpinvtld{n}*Ptld{n}; +end diff --git a/MatlabFiles/rnrprior.m b/MatlabFiles/rnrprior.m new file mode 100755 index 0000000..4a1f93e --- /dev/null +++ b/MatlabFiles/rnrprior.m @@ -0,0 +1,215 @@ +function [Pi,H0multi,Hpmulti,H0invmulti,Hpinvmulti,asym0,asymp] ... + = rnrprior(nvar,q_m,lags,xdgel,mu,nexo) +% [Pi,H0multi,Hpmulti,H0invmulti,Hpinvmulti,asym0,asymp] ... +% = rnrprior(nvar,q_m,lags,xdgel,mu,nexo) +% +% Exporting random Bayesian prior of Sims and Zha with asymmetric rior (but no linear restrictions) +% See Waggoner and Zha's Gibbs sampling paper +% +% nvar: number of endogenous variables +% q_m: quarter or month +% lags: the maximum length of lag +% xdgel: the general matrix of the original data (no manipulation involved) +% with sample size including lags. Used only to get variances of residuals for +% the scaling purpose. +% mu: 6-by-1 vector of hyperparameters (the following numbers for Atlanta Fed's forecast) +% mu(1): overall tightness and also for A0; (0.57) +% mu(2): relative tightness for A+; (0.13) +% mu(3): relative tightness for the constant term; (0.1). NOTE: for other +% exogenous terms, the variance of each exogenous term must be taken into +% acount to eliminate the scaling factor. +% mu(4): tightness on lag decay; (1) +% mu(5): weight on nvar sums of coeffs dummy observations (unit roots); (5) +% mu(6): weight on single dummy initial observation including constant +% (cointegration, unit roots, and stationarity); (5) +% NOTE: for this subdirectory, mu(5) and mu(6) are not used. +% nexo: number of exogenous variables (if not specified, nexo=1 (constant) by default). +% The constant term is always put to the last of all endogenous and exogenous variables. +% -------------------- +% Pi: ncoef-by-nvar matrix for the ith equation under random walk. Same for all equations +% H0multi: nvar-by-nvar-by-nvar; H0 for different equations under asymmetric prior +% Hpmulti: ncoef-by-ncoef-by-nvar; H+ for different equations under asymmetric prior +% H0invmulti: nvar-by-nvar-by-nvar; inv(H0) for different equations under asymmetric prior +% Hpinvmulti: ncoef-by-ncoef-by-nvar; inv(H+) for different equations under asymmetric prior +% asym0: nvar-by-nvar asymmetric prior on A0. Column -- equation +% asymp: ncoef-1-by-nvar asymmetric prior on A+ bar constant. Column -- equation +% +% Tao Zha, February 2000 + + +if nargin==5, nexo=1; end +ncoef = nvar*lags+nexo; % number of coefficients in *each* equation, RHS coefficients only. + +H0multi=zeros(nvar,nvar,nvar); % H0 for different equations under asymmetric prior +Hpmulti=zeros(ncoef,ncoef,nvar); % H+ for different equations under asymmetric prior +H0invmulti=zeros(nvar,nvar,nvar); % inv(H0) for different equations under asymmetric prior +Hpinvmulti=zeros(ncoef,ncoef,nvar); % inv(H+) for different equations under asymmetric prior + +%*** Constructing Pi for the ith equation under the random walk assumption +Pi = zeros(ncoef,nvar); % same for all equations +Pi(1:nvar,1:nvar) = eye(nvar); % random walk + +% +%@@@ Prepared for Bayesian prior +% +% +% ** monthly lag decay in order to match quarterly decay: a*exp(bl) where +% ** l is the monthly lag. Suppose quarterly decay is 1/x where x=1,2,3,4. +% ** Let the decay of l1 (a*exp(b*l1)) match that of x1 (say, beginning: 1/1) +% ** and the decay of l2 (a*exp(b*l2)) match that of x2 (say, end: 1/5), +% ** we can solve for a and b which are +% ** b = (log_x1-log_x2)/(l1-l2), and a = x1*exp(-b*l1). +if q_m==12 + l1 = 1; % 1st month == 1st quarter + xx1 = 1; % 1st quarter + l2 = lags; % last month + xx2 = 1/((ceil(lags/3))^mu(4)); % last quarter + %xx2 = 1/6; % last quarter + % 3rd quarter: i.e., we intend to let decay of the 6th month match + % that of the 3rd quarter, so that the 6th month decays a little + % faster than the second quarter which is 1/2. + if lags==1 + b = 0; + else + b = (log(xx1)-log(xx2))/(l1-l2); + end + a = xx1*exp(-b*l1); +end + + + +% +% *** specify the prior for each equation separately, SZ method, +% ** get the residuals from univariate regressions. +% +sgh = zeros(nvar,1); % square root +sgsh = sgh; % square +nSample=size(xdgel,1); % sample size-lags +yu = xdgel; +C = ones(nSample,1); +for k=1:nvar + [Bk,ek,junk1,junk2,junk3,junk4] = sye([yu(:,k) C],lags); + clear Bk junk1 junk2 junk3 junk4; + sgsh(k) = ek'*ek/(nSample-lags); + sgh(k) = sqrt(sgsh(k)); +end +% ** prior variance for A0(:,1), same for all equations!!! +sg0bid = zeros(nvar,1); % Sigma0_bar diagonal only for the ith equation +for j=1:nvar + sg0bid(j) = 1/sgsh(j); % sgsh = sigmai^2 +end +% ** prior variance for lagged and exogeous variables, same for all equations +sgpbid = zeros(ncoef,1); % Sigma_plus_bar, diagonal, for the ith equation +for i = 1:lags + if (q_m==12) + lagdecay = a*exp(b*i*mu(4)); + end + % + for j = 1:nvar + if (q_m==12) + % exponential decay to match quarterly decay + sgpbid((i-1)*nvar+j) = lagdecay^2/sgsh(j); % ith equation + elseif (q_m==4) + sgpbid((i-1)*nvar+j) = (1/i^mu(4))^2/sgsh(j); % ith equation + else + error('Incompatibility with lags, check the possible errors!!!') + %warning('Incompatibility with lags, check the possible errors!!!') + %return + end + end +end +% + + +%================================================= +% Computing the (prior) covariance matrix for the posterior of A0, no data yet +%================================================= +% +% +% ** set up the conditional prior variance sg0bi and sgpbi. +sg0bida = mu(1)^2*sg0bid; % ith equation +sgpbida = mu(1)^2*mu(2)^2*sgpbid; +sgpbida(ncoef-nexo+1:ncoef) = mu(1)^2*mu(3)^2; + %<<>> No scaling adjustment has been made for exogenous terms other than constant +sgppbd = sgpbida(nvar+1:ncoef); % corresponding to A++, in a Sims-Zha paper + +Hptd = zeros(ncoef); +Hptdi=Hptd; +Hptd(ncoef,ncoef)=sgppbd(ncoef-nvar); +Hptdinv(ncoef,ncoef)=1./sgppbd(ncoef-nvar); + % condtional on A0i, H_plus_tilde + +%**** Asymmetric Information +asym0 = ones(nvar,nvar); % if not ones, then we have relative (asymmetric) tightness +asymp = ones(ncoef-1,nvar); % pp: plus without constant. Column -- equation +%>>>>>> B: asymmetric prior variance for asymp <<<<<<<< +% +%for i = 1:lags +% rowif = (i-1)*nvar+1; +% rowil = i*nvar; +% idmatw0 = 0.5; % weight assigned to idmat0 in the formation of asymp +% if (i==1) +% asymp(rowif:rowil,:)=(1-idmatw0)*ones(nvar)+idmatw0*idmat0; % first lag +% % note: idmat1 is already transposed. Column -- equation +% else +% %asymp(rowif:rowil,1:nvar) = (1-idmatw0)*ones(nvar)+idmatw0*idmat0; +% % <<<<<<< toggle + +% % Note: already transposed, since idmat0 is transposed. +% % Meaning: column implies equation +% asymp(rowif:rowil,1:nvar) = ones(nvar); +% % >>>>>>> toggle - +% end +%end +% +%>>>>>> E: asymmetric prior variance for asymp <<<<<<<< + + +%================================================= +% Computing the final covariance matrix (S1,...,Sm) for the prior of A0, +% and final Gb=(G1,...,Gm) for A+ if asymmetric prior or for +% B if symmetric prior for A+ +%================================================= +% +for i = 1:nvar + %------------------------------ + % Introduce prior information on which variables "belong" in various equations. + % In this first trial, we just introduce this information here, in a model-specific way. + % Eventually this info has to be passed parametricly. In our first shot, we just damp down + % all coefficients except those on the diagonal. + + %*** For A0 + factor0=asym0(:,i); + sg0bd = sg0bida.*factor0; % Note, this only works for the prior variance Sg(i) + % of a0(i) being diagonal. If the prior variance Sg(i) is not + % diagonal, we have to work on inv(Sg(i)) or sg0bdinv directly. + sg0bdinv = 1./sg0bd; + % * unconditional variance on A0+ + H0td = diag(sg0bd); % unconditional + H0tdinv = diag(sg0bdinv); + % + H0multi(:,:,i)=H0td; + H0invmulti(:,:,i)=H0tdinv; + + + %*** For A+ + if ~(lags==0) % For A1 to remain random walk properties + factor1=asymp(1:nvar,i); + sg1bd = sgpbida(1:nvar).*factor1; + sg1bdinv = 1./sg1bd; + % + Hptd(1:nvar,1:nvar)=diag(sg1bd); + Hptdinv(1:nvar,1:nvar)=diag(sg1bdinv); + if lags>1 + factorpp=asymp(nvar+1:ncoef-1,i); + sgpp_cbd = sgppbd(1:ncoef-nvar-1) .* factorpp; + sgpp_cbdinv = 1./sgpp_cbd; + Hptd(nvar+1:ncoef-1,nvar+1:ncoef-1)=diag(sgpp_cbd); + Hptdinv(nvar+1:ncoef-1,nvar+1:ncoef-1)=diag(sgpp_cbdinv); + % condtional on A0i, H_plus_tilde + end + end + Hpmulti(:,:,i)=Hptd; + Hpinvmulti(:,:,i)=Hptdinv; +end + + diff --git a/MatlabFiles/run.m b/MatlabFiles/run.m new file mode 100755 index 0000000..b8976b4 --- /dev/null +++ b/MatlabFiles/run.m @@ -0,0 +1,3 @@ +intervalcl +clear all +clsort \ No newline at end of file diff --git a/MatlabFiles/sbcontest.m b/MatlabFiles/sbcontest.m new file mode 100755 index 0000000..4fe57f0 --- /dev/null +++ b/MatlabFiles/sbcontest.m @@ -0,0 +1,63 @@ +function [pabove,pbelow]=sbcontest(xinput) +% [pabove,pbelow]=sbcontest(xinput) +% Small Sample Bayesian Contour Test (sbcontest) for overidentified models +% +% xinput{1}: idenmlh -- handle for the file idenml.mat +% xinput{2}: SpHUouth -- handle for the file sphuout.mat +% xinput{3}: fss -- effective sample size == nSample-lags+# of dummy observations +% xinput{4}: imndraws=nstarts*ndraws2 +% xinput{5}: nvar -- # of endogenous variables +% xinput{6}: nbuffer -- interval of whcih for printing, plotting, saving, etc. +%-------------- +% pabove: probablity of the reduced-form LH value above the overidentified LH peak value +% pbelow: probablity of the reduced-form LH value below the overidentified LH peak value + +idenmlh = xinput{1}; SpHUouth = xinput{2}; fss = xinput{3}; imndraws = xinput{4}; nvar = xinput{5}; +nbuffer = xinput{6}; + +neqn = nvar; %<<>> number of equations +eval(['load ' idenmlh]); +eval(['load ' SpHUouth]); + +pabove=0; +pbelow=0; +load idenml % fhat at ML for identified version +fhat=-fhat; + % this value is strictly smaller than that at the peak of reduced-form LH +disp('If you havent run idenml with Rform=1, you must do so now') +disp('Press ctrl-c to abort now or any other key to continue') +disp(' ') +pause +load SpHUout % this is the output file by running "idenml" with Rform=1 + % with output SpHU +SpHs = SpHU*fss; % for the Wishart draw +SpHsc = chol(SpHs); % upper triangular where Sphsc' is + % lower triangular Choleski, for Wishart draw +tic +for draws=1:imndraws + if ~mod(draws,nbuffer) + draws + end + ranw = randn(neqn,fss-neqn-1); + ranw = SpHsc\ranw; % inv(SpHsc) is upper triagular Choleski of inv(SpHs) + %ranw = SpHsic*ranw; + % normal draws (T-nvar-1)*nvar, with variance inv(SpHs) (note, NOT inv(SpH)) + sinh = ranw*ranw'; % Wishart draws for A0h*A0h' + A0_h = chol2(sinh); % upper triangular Choleski + a0indx = find(A0_h); + + xhat_h = A0_h(a0indx); + jnk = a0lhfun(xhat_h,SpHU,fss,nvar,a0indx); + fhat_h = -jnk; + + if fhat_h > fhat + pabove = pabove+1; + else + pbelow = pbelow+1; + end +end +timend=toc; +timeminutes=timend/60 + +pabove = pabove/imndraws +pbelow = pbelow/imndraws diff --git a/MatlabFiles/simtanzphi.m b/MatlabFiles/simtanzphi.m new file mode 100755 index 0000000..90e9705 --- /dev/null +++ b/MatlabFiles/simtanzphi.m @@ -0,0 +1,45 @@ +function simtanzphi(X,k,nvar,U); +% simtanzphi(X,k,nvar,U) +% Recursive function with global output argument ZPHI +% Export ZPHI: PHI_k--the span of proj(R(k))(w(a(i))|i~=k), whose rank determines +% the degree of simultaneity +% +% X: nvar-by-nvar matrix so that the 1st k columns are orthonormal +% k: <=nvar, orthonormal columns +% nvar: number of variables +% U: nvar-by-1 cell. Each cell contains a set of orthonormal bases for the ith +% column of idmat0s (restriction or R(i)) +%----------- +% ZPHI: global variable PHI_k--the span of proj(R(k))(w(a(i))|i~=k), whose rank determines +% the degree of simultaneity +% +% Copyright (c) 1999 by D.F. Waggoner and T.A. Zha + +global ZPHI + +if k<nvar + V=[X(:,1:k) U{k+1}]; + [Q,R,eindx]=qr(V,0); % eindx: index vector + Q1=Q; + Q1(:,1:k) = Q(:,find(eindx<=k)); % keep the first k col's in V in Q1 + jnk = find(eindx>k); + jnk1=length(Q(1,:))-k; + Q1(:,k+1:length(Q(1,:))) = Q(:,jnk(1:jnk1)); + tmp = abs(diag(R)); % largest absoluate value in R + jnk = find(tmp<max(tmp)*eps); % index for the zero's in R + if isempty(jnk) + Y = Q1(:,k+1:length(tmp)); + else + Y = Q1(:,k+1:min(jnk)-1); % all meaningful orthonormal columns after Q(1:k) + end + % + for ik=1:length(Y(1,:)) + X=[X(:,1:k) Y(:,ik)]; + simtanzphi(X,k+1,nvar,U); + end +else + Xn=X(:,nvar); + %* Projection of Xn into R{n} + Xnproj=U{nvar}*(Xn'*U{nvar})'; + ZPHI=[ZPHI Xnproj]; +end diff --git a/MatlabFiles/smtplis.m b/MatlabFiles/smtplis.m new file mode 100755 index 0000000..caf1d8e --- /dev/null +++ b/MatlabFiles/smtplis.m @@ -0,0 +1,45 @@ +function [Avhx,hAvhx,cJump] = smtplis(Avhx,hAvhx,tdf,cJump,scf,... + H_sr,nfp,Sbd,fss,nvar,a0indx) +% +% Straight Metropolis Algorithm for identified VARs +% +% Avhx: previous draw of parameter x in 1st (kept) sequence +% hAvhx: lh value of previous draw in 1st (kept) sequence +% tdf: degrees of freedom of the jump t-distribution +% cJump: old count for times of jumping +% scf: scale down factor for stand. dev. -- square root of covariance matrix H +% H_sr: square root of covariance matrix H in approximate density +% nfp: number of free parameters +% Sbd: S in block diagonal covariance matrix in asymmetric prior case +% fss: effective sample size, including # of dummy observations +% nvar: number of variables +% a0indx: index of locations of free elements in A0 +%-------------- +% Avhx: new draw of parameter x in 1st (kept) sequence +% hAvhx: lh value of new draw in 1st (kept) sequence +% cJump: new count for times of jumping +% +% December 1998 by Tao Zha + + +%** draw free elements Avh in A0 and hyperparameters from t-dist +Avhz1 = scf*H_sr*randn(nfp,1); % normal draws +csq=randn(tdf,1); +csq=sum(csq .* csq); +Avhz = Avhz1/sqrt(csq/tdf); + +Avhy = Avhx + Avhz; % random walk chain -- Metropolis +% ** actual density, having taken log +hAvhy = a0asfun(Avhy,Sbd,fss,nvar,a0indx); +hAvhy = -hAvhy; % converted to logLH + +mphxy = exp(hAvhy-hAvhx); + +%** draw u from uniform(0,1) +u = rand(1); +Jump = min([mphxy 1]); +if u <= Jump + Avhx = Avhy; + hAvhx = hAvhy; + cJump = cJump+1; +end diff --git a/MatlabFiles/smtplis2.m b/MatlabFiles/smtplis2.m new file mode 100755 index 0000000..5a601ef --- /dev/null +++ b/MatlabFiles/smtplis2.m @@ -0,0 +1,99 @@ +function [Avhx,AvhxD,hAvhx,hAvhxD,cJump,hAvhh] = smtplis2(Avhx,AvhxD,hAvhx,hAvhxD,... + A0xhat,tdf,cJump,scf,H_sr,nfp,Sbd,fss,nvar,a0indx,hAvhh) +% [Avhx,AvhxD,hAvhx,hAvhxD,cJump,hAvhh] = smtplis2(Avhx,AvhxD,hAvhx,hAvhxD,... +% A0xhat,tdf,cJump,scf,H_sr,nfp,Sbd,fss,nvar,a0indx,hAvhh) +% Straight Metropolis Algorithm for identified VARs with 2 parallel sequences +% +% Avhx: previous draw of parameter x in 1st (kept) sequence +% AvhxD: previous draw of parameter x in 2nd (discarded) sequence +% hAvhx: lh value of previous draw in 1st (kept) sequence +% hAvhxD: lh vlaue of previous draw in 2nd (discarded) sequence +% A0xhat: ML estimate of A0 +% tdf: degrees of freedom of the jump t-distribution +% cJump: old count for times of jumping +% scf: scale down factor for stand. dev. -- square root of covariance matrix H +% H_sr: square root of covariance matrix H +% nfp: number of free parameters +% Sbd: S in block diagonal covariance matrix in asymmetric prior case +% fss: effective sample size +% nvar: number of variables +% a0indx: index of locations of free elements in A0 +% hAvhh: highest point of lh +%-------------- +% Avhx: new draw of parameter x in 1st (kept) sequence +% AvhxD: new draw of parameter x in 2nd (discarded) sequence +% hAvhx: lh value of new draw in 1st (kept) sequence +% AvhxD: lh vlaue of new draw in 2nd (discarded) sequence +% cJump: new count for times of jumping +% hAvhh: highest point of lh +% +% November 1998 by Tao Zha + +if ~(fix(tdf)-tdf==0) + warning('tdf in msstart.m must be integer for drawing chi^2 from normal') + disp('press ctrl-c to abort') + pause +end + +for k=1:2 % parallel sequences; 2nd to be discarded + %** draw free elements Avh in A0 and hyperparameters from t-dist + %gsg = gamrnd(ga,gb); % G-sigma from Gamma draw + %Avhz = (1/sqrt(gsg))*(scf*H_sr*randn(nfp,1)); + % scf is used to control the acceptance ratio -- countJump + Avhz1 = scf*H_sr*randn(nfp,1); % normal draws + %Avhz1 = 2*randn(nfp,1); % normal draws + csq=randn(tdf,1); + csq=sum(csq .* csq); + Avhz = Avhz1/sqrt(csq/tdf); + + if (k==1) + Avhy = Avhx + Avhz; % random walk chain -- Metropolis + else + Avhy = AvhxD + Avhz; % random walk chain -- Metropolis + end + + % ** actual density, having taken log + hAvhy = a0asfun(Avhy,Sbd,fss,nvar,a0indx); + hAvhy = -hAvhy; % converted to logLH + + if (k==1) + mphxy = exp(hAvhy-hAvhx); + else + mphxy = exp(hAvhy-hAvhxD); + end + + %** draw u from uniform(0,1) + u = rand(1); + Jump = min([mphxy 1]); + if u <= Jump + %** Normalization: get the point that is nearest to axhat or A0xhat + Atem=zeros(nvar); + Atem(a0indx) = Avhy; + Adiff = (Atem - A0xhat).^2; + % distance that may be far from axhat or A0xhat + Adiffn = (-Atem - A0xhat).^2; + % distance by chaning the sign of Atem + cAdiff = sum(Adiff); % each column summed up + cAdiffn = sum(Adiffn); % each column summed up + cAindx = find(cAdiffn<cAdiff); % index for shorter distance + Atemn = Atem; + Atemn(:,cAindx) = -Atem(:,cAindx); + % find the shortest or nearest distance + %** get the value of logPoster or logLH + Avhy = Atemn(a0indx); + % + + if (k==1) + Avhx = Avhy; + hAvhx = hAvhy; + if hAvhy > hAvhh + hAvhh = hAvhy; + Avhh = Avhy; + end + cJump = cJump+1; + else + AvhxD = Avhy; + hAvhxD = hAvhy; + end + end +end diff --git a/MatlabFiles/startd.m b/MatlabFiles/startd.m new file mode 100755 index 0000000..a741fef --- /dev/null +++ b/MatlabFiles/startd.m @@ -0,0 +1,7 @@ +function startd(sd) +%function startd(sd) +% to set the directory started in the next time matlab is invoked, +% use this function. E.g. +% sd=cd %to set sd to the current directory +% startd(sd) +save '/Users/tzha/ZhaData/TZCcode/cstz/startdir0' sd diff --git a/MatlabFiles/startup.m b/MatlabFiles/startup.m new file mode 100755 index 0000000..a052b4e --- /dev/null +++ b/MatlabFiles/startup.m @@ -0,0 +1,27 @@ +function startup() +% Remembers a previously set startup directory to set the directory, invoke startd. E.g., +% sd=cd % Set sd to the current directory +% startd(sd) + +%---------------------------------- + +%path(path,'d:\Program Files\MATLAB\R2007a\work\cstz') +%path(path,'c:\softwdisk\matlabr12\toolbox\cstz\cmexfiles\csminwelfinal\csminwelmex') +%path(path,'C:\ZhaData\TZCcode') +%path(path,'C:\Program Files\Intel\MKL\ia32\lib') +%path(path,'C:\Program Files\Intel\MKL\include') +%path(path,'d:\matlabr12\toolbox\cstz\lzpaper2') +%path(path,'d:\matlabr12\toolbox\cstz\rvarcode') +%path(path,'C:\Program Files\MATLAB\R2006b\work\cstz') +path(path,'/Users/tzha/ZhaData/TZCcode/cstz') +path(path,'/Users/tzha/ZhaData/TZCcode/cstz/MSV') +if exist('startdir0.mat')==2 + load /Users/tzha/ZhaData/TZCcode/cstz/startdir0 + cd(sd) +end +format compact + +fn_reset_ini_seed(0); %Reset the random seed to clockcycle. Can be reoverwritten by fn_reset_ini_seed(number); + + + diff --git a/MatlabFiles/subtitle.m b/MatlabFiles/subtitle.m new file mode 100755 index 0000000..cc77fe7 --- /dev/null +++ b/MatlabFiles/subtitle.m @@ -0,0 +1,20 @@ + function [ax,h]=subtitle(text) + % + %Centers a title over a group of subplots. + %Returns a handle to the title and the handle to an axis. + % [ax,h]=subtitle(text) + % returns handles to both the axis and the title. + % ax=subtitle(text) + % returns a handle to the axis only. + +% ax=axes('Units','Normal','Position',[.05 .05 .9 .9],'Visible','off','FontSize',14,'FontWeight','Bold'); + ax=axes('Units','Normal','Position',[.05 .05 .9 .9],'Visible','off','FontSize',10,'FontWeight','Bold','FontName','Times New Roman'); +% ax=axes('Units','Normal','Position',[.075 .075 .85 .85],'Visible','off'); + set(get(ax,'Title'),'Visible','on') + title(text); + if (nargout < 2) + return + end + h=get(ax,'Title'); + + %%%END CODE%%% diff --git a/MatlabFiles/suptitle.m b/MatlabFiles/suptitle.m new file mode 100755 index 0000000..fdcd6fb --- /dev/null +++ b/MatlabFiles/suptitle.m @@ -0,0 +1,103 @@ +function hout=suptitle(str) +%SUPTITLE Puts a title above all subplots. +% SUPTITLE('text') adds text to the top of the figure +% above all subplots (a "super title"). Use this function +% after all subplot commands. + +% Drea Thomas 6/15/95 drea@mathworks.com + +% Warning: If the figure or axis units are non-default, this +% will break. + +% Parameters used to position the supertitle. + +% Amount of the figure window devoted to subplots +plotregion = .92; + +% Y position of title in normalized coordinates +titleypos = .95; + +% Fontsize for supertitle +fs = get(gcf,'defaultaxesfontsize')+4; + +% Fudge factor to adjust y spacing between subplots +fudge=1; + +haold = gca; +figunits = get(gcf,'units'); + +% Get the (approximate) difference between full height (plot + title +% + xlabel) and bounding rectangle. + + if (~strcmp(figunits,'pixels')), + set(gcf,'units','pixels'); + pos = get(gcf,'position'); + set(gcf,'units',figunits); + else, + pos = get(gcf,'position'); + end + ff = (fs-4)*1.27*5/pos(4)*fudge; + + % The 5 here reflects about 3 characters of height below + % an axis and 2 above. 1.27 is pixels per point. + +% Determine the bounding rectange for all the plots + +% h = findobj('Type','axes'); + +% findobj is a 4.2 thing.. if you don't have 4.2 comment out +% the next line and uncomment the following block. + +h = findobj(gcf,'Type','axes'); % Change suggested by Stacy J. Hills + +% If you don't have 4.2, use this code instead +%ch = get(gcf,'children'); +%h=[]; +%for i=1:length(ch), +% if strcmp(get(ch(i),'type'),'axes'), +% h=[h,ch(i)]; +% end +%end + + + + +max_y=0; +min_y=1; + +oldtitle =0; +for i=1:length(h), + if (~strcmp(get(h(i),'Tag'),'suptitle')), + pos=get(h(i),'pos'); + if (pos(2) < min_y), min_y=pos(2)-ff/5*3;end; + if (pos(4)+pos(2) > max_y), max_y=pos(4)+pos(2)+ff/5*2;end; + else, + oldtitle = h(i); + end +end + +if max_y > plotregion, + scale = (plotregion-min_y)/(max_y-min_y); + for i=1:length(h), + pos = get(h(i),'position'); + pos(2) = (pos(2)-min_y)*scale+min_y; + pos(4) = pos(4)*scale-(1-scale)*ff/5*3; + set(h(i),'position',pos); + end +end + +np = get(gcf,'nextplot'); +set(gcf,'nextplot','add'); +if (oldtitle), + delete(oldtitle); +end +ha=axes('pos',[0 1 1 1],'visible','off','Tag','suptitle'); +ht=text(.5,titleypos-1,str);set(ht,'horizontalalignment','center','fontsize',fs); +set(gcf,'nextplot',np); +axes(haold); +if nargout, + hout=ht; +end + + + diff --git a/MatlabFiles/szasbvar.m b/MatlabFiles/szasbvar.m new file mode 100755 index 0000000..db55b9c --- /dev/null +++ b/MatlabFiles/szasbvar.m @@ -0,0 +1,486 @@ +function [Gb,Sbd,Bh,SpH,fss,ndobs,phi,y,nvar,ncoef,xxhpc,a0indx,na0p,... + idmat0,idmatpp,H0invmulti,Hpinvmulti,xxhp] = szasbvar(idfile,q_m,lags,xdgel,mu) +% [Gb,Sbd,Bh,SpH,fss,ndobs,phi,y,nvar,ncoef,xxhpc,a0indx,na0p,... +% idmat0,idmatpp,H0invmulti,Hpinvmulti] = szasbvar(idfile,q_m,lags,xdgel,mu) +% +% Estimating the Bayesian VAR of Sims and Zha with asymmetric prior (as) +% +% idfile: Identification filename with rows corresponding to equations. +% But all the output will be transposed to columns +% corresponding to equations. +% q_m: quarter or month +% lags: the maximum length of lag +% nhp: number of haperparameters +% xdgel: the general matrix of the original data (no manipulation involved) +% with sample size including lags +% mu: 6-by-1 vector of hyperparameters (the following numbers for Atlanta Fed's forecast) +% mu(1): overall tightness and also for A0; (0.57) +% mu(2): relative tightness for A+; (0.13) +% mu(3): relative tightness for the constant term; (0.1) +% mu(4): tightness on lag decay; (1) +% mu(5): weight on nvar sums of coeffs dummy observations (unit roots); (5) +% mu(6): weight on single dummy initial observation including constant +% (cointegration, unit roots, and stationarity); (5) +% -------------------- +% -------------------- +% Gb: cell(nvar,1). Each cell, when postmultiplied by A0(:,i), is used to compute A+(:,i) +% where A+ is k-by-m, where k--ncnoef, m--nvar, if asymmetric prior. +% In particular, Aplus(:,i)=Gb{i}*A0(:,i), so Bh = Aplus/A0 +% Sbd: cell(nvar,1). Sbd=diag(S(1), ..., S(m)). Already divided by 'fss' for the +% posterior of a0 or A0(:) in Waggoner and Zha when one has asymmetric prior. +% Note,"bd" stands for block diagonal. +% Bh: reduced form B, k(mp+1)-by-m, column--equation. Bh=NaN if asymmetric prior. +% In the form of y=X*B+U where B=[B1|B2| ...|Bp|C] +% where Bi: m-by-m (i=1,..,p--lag length), C: 1-by-ml, constant. +% SpH: divided by T, the final S in the Waggoner-Zha exponential part of p(A0|y) +% SpH=NaN if asymmetric prior +% fss: in-sample-size (for forecasting). Including dummy observations +% ndobs: number of dummy observations, ndobs=nvar+1 +% phi: X in the form of y = X*B+U. Row: nSmaple-lags+ndobs. Column: ncoef +% y: y in the form y = X*B+U. Including the dummy observations too, +% T-lags+ndobs-by-nvar. +% nvar: number of variables +% ncoef: number of coefficients in *each* equation. RHS coefficients only, nvar*lags+1 +% xxhpc: chol(X'X+inv(H_p_tilde)): upper triangular but its transpose +% is lower triagular Choleski +% a0indx: the index number for free parameters in A0. Column meaning equation +% na0p: number of free parameters in A0 +% idmat0: identification matrix for A0 with asymmetric prior; column -- equation. +% idmatpp: asymmetric prior variance for A+ without constant; column -- equation. +% H0invmulti: nvar-by-nvar-by-nvar; inv(H0) for different equations under asymmetric prior +% Hpinvmulti: ncoef-by-ncoef-by-nvar; inv(H+) for different equations under asymmetric prior +% xxhp: ncoef-by-nocef, X'X+inv(H_p_tilde) +% +% Revisions by CAS 9/27/96: If we transmit idmat, rather than a0indx, we can scale +% the elements of idmat0 or idmatp so that it carries information about relative +% prior variances. +% Revsions by TZ, 10/13/96: Efficiency improvement by streamlining the previous +% code according to the general setup in Sims and Zha's IER and according +% to Zha's notes Forecast (0) (p.3) and Forecast (1) (p.9). +% Quick Revisions: May 2003. See H1p_1 on lines 406-409. +% +% Copyright (c) December 1997 by C.A. Sims and T. Zha, +% +% NOTE1: "nSample" is something I deleted as an input recently, so it may not +% be compatible with old programs, 10/15/98 by TZ. +% NOTE2: I put "mu" as an input arg and delete "nhp" as an input arg, so it may +% not be compatible with old programs, 03/06/99 by TZ +% NOTE3: added three output arguments: H0invmulti and Hpinvmulti and xxhp. 9/27/99 + + + +% +%@@@ Prepared for Bayesian VAR of Sims and Zha +% +%* Load identification and obtain idmat0 +eval(['load ' idfile '.prn -ascii']); +eval(['idmat0=' idfile ';']); +idmat0=idmat0'; % so that each column corresponds to an equation +a0indx=find(idmat0); % column meaning equation +na0p = length(a0indx); % number of free parameters in A0 +nhp = length(mu); % total number of hyperparameters +nfp = na0p + nhp; % total number of free parameters (including hyperparameters) +[nvar,neqn]=size(idmat0); +% +idmatpp = ones(nvar*lags,nvar); % pp: plus without constant. Column -- equation +%>>>>>> B: asymmetric prior variance for idmatpp <<<<<<<< +% +%for i = 1:lags +% rowif = (i-1)*nvar+1; +% rowil = i*nvar; +% idmatw0 = 0.5; % weight assigned to idmat0 in the formation of idmatpp +% if (i==1) +% idmatpp(rowif:rowil,:)=(1-idmatw0)*ones(nvar)+idmatw0*idmat0; % first lag +% % note: idmat1 is already transposed. Column -- equation +% else +% %idmatpp(rowif:rowil,1:nvar) = (1-idmatw0)*ones(nvar)+idmatw0*idmat0; +% % <<<<<<< toggle + +% % Note: already transposed, since idmat0 is transposed. +% % Meaning: column implies equation +% idmatpp(rowif:rowil,1:nvar) = ones(nvar); +% % >>>>>>> toggle - +% end +%end +% +%>>>>>> E: asymmetric prior variance for idmatpp <<<<<<<< + + +%$$$ available computations +% +%@@@ original +% total number of the sample under study, including lags, etc. -- original sample size +nSample = size(xdgel,1); % the sample size (including lags, of course) +sb = lags+1; % original beginning without dummies +sl = nSample; % original last period without dummies +ssp = nSample - lags; % original number of observations +% +ndobs=nvar+1; % number of dummy observations +ncoef = nvar*lags+1; % number of coefficients in *each* equation, RHS coefficients only. +%*** initializing for global variables +%%GlbAph=zeros(nvar,ncoef); +%Aplus=zeros(ncoef,nvar); +Gb = cell(nvar,1); % Storing potential reduced-form Bh (k-by-m) or prepared + % for computing Aplus (k-by-m), where k--ncnoef, m--nvar +Sbd = cell(nvar,1); % Storing for diag(S(1), ..., S(m)) for the posterior of a0 + % or vec(A0) when one has asymmetric prior. Note, + % "bd" stands for block diagonal. +SpH = ones(nvar,nvar); +%* flp: forecast last period (with dummies); +%* fbp: forecast beginning period (with dummies). +flp = sl+ndobs; +%fbp = ndobs+lags+1; % <<>> true begining by skipping dummies +fss = flp-lags; % forecast sample size (with dummies). + +% ** hyperparameters +% mu = zeros(nhp,1); +% mu(1) = 0.57; +% mu(2) = 0.13; +% mu(3) = 0.1; +% mu(4) = 1; +% mu(5) = 5; %10; +% mu(6) = 5; %10; +% +% mu(1): overall tightness and also for A0; +% mu(2): relative tightness for A+; +% mu(3): relative tightness for the constant term; +% mu(4): tightness on lag decay; +% mu(5): weight on nvar sums of coeffs dummy observations (unit roots); +% mu(6): weight on single dummy initial observation including constant (cointegration, unit +% roots, and stationarity). + + +% ** monthly lag decay in order to match quarterly decay: a*exp(bl) where +% ** l is the monthly lag. Suppose quarterly decay is 1/x where x=1,2,3,4. +% ** Let the decay of l1 (a*exp(b*l1)) match that of x1 (say, beginning: 1/1) +% ** and the decay of l2 (a*exp(b*l2)) match that of x2 (say, end: 1/5), +% ** we can solve for a and b which are +% ** b = (log_x1-log_x2)/(l1-l2), and a = x1*exp(-b*l1). +if q_m==12 + l1 = 1; % 1st month == 1st quarter + xx1 = 1; % 1st quarter + l2 = lags; % last month + xx2 = 1/((ceil(lags/3))^mu(4)); % last quarter + %xx2 = 1/6; % last quarter + % 3rd quarter: i.e., we intend to let decay of the 6th month match + % that of the 3rd quarter, so that the 6th month decays a little + % faster than the second quarter which is 1/2. + if lags==1 + b = 0; + else + b = (log(xx1)-log(xx2))/(l1-l2); + end + a = xx1*exp(-b*l1); +end + +% +% ** now run the VAR with +% +% **** nvar prior dummy observations with the sum of coefficients +% ** construct X for Y = X*B + U where phi = X: (T-lags)*k, Y: (T-lags)*nvar +% ** columns: k = # of [nvar for 1st lag, ..., nvar for last lag, const] +% ** Now, T=T+ndobs -- added with "ndobs" dummy observations +% +phi = zeros(fss,ncoef); +const = ones(fss,1); +const(1:nvar) = zeros(nvar,1); +phi(:,ncoef) = const; % the first nvar periods: no or zero constant! +% +xdgelint = mean(xdgel(1:lags,:),1); % mean of the first lags initial conditions +%* Dummies +for k=1:nvar + for m=1:lags + phi(ndobs,nvar*(m-1)+k) = xdgelint(k); + phi(k,nvar*(m-1)+k) = xdgelint(k); + % <<>> multiply hyperparameter later + end +end +%* True data +for k=1:lags + phi(ndobs+1:fss,nvar*(k-1)+1:nvar*k) = xdgel(sb-k:sl-k,:); + % row: T-lags; column: [nvar for 1st lag, ..., nvar for last lag, const] + % Thus, # of columns is nvar*lags+1 = ncoef. +end +% +% ** Y with "ndobs" dummies added +y = zeros(fss,nvar); +%* Dummies +for k=1:nvar + y(ndobs,k) = xdgelint(k); + y(k,k) = xdgelint(k); + % multiply hyperparameter later +end +%* True data +y(ndobs+1:fss,:) = xdgel(sb:sl,:); + + + +% +% *** specify the prior for each equation separately, SZ method, +% *** +% *** obtaining the residuals for the univariate processes: +% *** a total of "nvar" equations +% *** obtain the posterior peak of A0 which is Sims iden1 (Sims 1986) +% ** get the residuals from univariate regressions. +% +sgh = zeros(nvar,1); % square root +sgsh = sgh; % square +yu = xdgel; +C = ones(nSample,1); +for k=1:nvar + [Bk,ek,junk1,junk2,junk3,junk4] = sye([yu(:,k) C],lags); + clear Bk junk1 junk2 junk3 junk4; + sgsh(k) = ek'*ek/ssp; + %% sgh(k) = ek'*ek/(fss-7); to match "sqrt(ess)" in RATS univariate regression + sgh(k) = sqrt(sgsh(k)); +end +% ** prior variance for alpha0, same for all equations!!! +al0b = zeros(nvar*neqn,1); % prior mean for all A0 +sg0bid = zeros(nvar,1); % Sigma0_bar diagonal only +for j=1:nvar + sg0bid(j) = 1/sgsh(j); % sgsh = sigmai^2 +end +% ** prior variance for alpha_plus, same for all equations +sgpbid = zeros(ncoef,1); % Sigma_plus_bar, diagonal +for i = 1:lags + if (q_m==12) + lagdecay = a*exp(b*i); + end + % + for j = 1:nvar + if (q_m==12) + % exponential decay to match quarterly decay + sgpbid((i-1)*nvar+j) = lagdecay^2/sgsh(j); + %%sgpbid((i-1)*nvar+j) = (1/i)^2/sgsh(j); + elseif (q_m==4) + sgpbid((i-1)*nvar+j) = (1/i^mu(4))^2/sgsh(j); + else + error('Incompatibility with lags, check the possible errors!!!') + %warning('Incompatibility with lags, check the possible errors!!!') + %return + end + end +end +%%A0bd = sqrt(sg0bid); +% commented out by T.A. Zha, 10/3/96, to avoid double-counting of scaling and the problem +% of potential multiple peaks. +A0bd = zeros(nvar,1); +A0b = sparse(1:nvar,1:nvar,A0bd,nvar,nvar); +A0b = A0b'; % making a column in A0b correspond to an equation + +% + + +%================================================= +% Computing the (prior) covariance matrix for the posterior of A0, no data yet +%================================================= +% +% +% ** weight prior dummy observations +%phi(1:nvar,:) = (mu(5)^2/mu(1)^2)*phi(1:nvar,:); +%y(1:nvar,:) = (mu(5)^2/mu(1)^2)*y(1:nvar,:); +%phi(ndobs,:) = mu +% modified by CAS 8/6/96. The dummy obs weights are naturally in std units, not var units. +% +phi(1:nvar,:) = 1*mu(5)*phi(1:nvar,:); % standard Sims and Zha prior +y(1:nvar,:) = mu(5)*y(1:nvar,:); % standard Sims and Zha prior +%----- The following prior designed for GLZ +%phi(1,:) = 1.00*mu(5)*phi(1,:); +%phi(2:nvar,:) = 1.02*mu(7)*phi(2:nvar,:); +%y(1,:) = mu(5)*y(1,:); +%y(2:nvar,:) = mu(7)*y(2:nvar,:); +%---------------------------- +% +phi(nvar+1,:) = mu(6)*phi(nvar+1,:); +y(nvar+1,:) = mu(6)*y(nvar+1,:); + + +% ** set up the conditional prior variance sg0bi and sgpbi. +sg0bida = mu(1)^2*sg0bid; +sgpbida = mu(1)^2*mu(2)^2*sgpbid; +sgpbida(ncoef) = mu(1)^2*mu(3)^2; +sgppbd = sgpbida(nvar+1:ncoef); % corresponding to A++, in a Sims-Zha paper +%%sgppbdi = 1./sgppbd; +%sgppb = diag(sgppbd); + +Hptd = zeros(ncoef); +Hptdi=Hptd; +%%Hptd(nvar+1:ncoef,nvar+1:ncoef)=diag(sgppbd); +%%Hptdi(nvar+1:ncoef,nvar+1:ncoef)=diag(sgppbdi); +Hptd(ncoef,ncoef)=sgppbd(ncoef-nvar); +Hptdi(ncoef,ncoef)=1/sgppbd(ncoef-nvar); + % condtional on A0i, H_plus_tilde + +% ** some common terms +[u d v]=svd(phi,0); %trial +% xtx = phi'*phi; %trial +vd=v.*(ones(size(v,2),1)*diag(d)'); %trial +xtx=vd*vd'; +% M = eye(fss) - phi*(xtx\phi'); % not used except in line below %trial +yu = y'*u; %trial +cxyxx=yu*yu'; %trial +yty=y'*y; +ymy=yty-cxyxx; %trial +%ymy = y'*M*y; +%cxy = phi'*y; %trial +cxy = vd*yu'; %trial +cyx = cxy'; +%cxpy = xtx\cxy; %not used further except in line below +%cxyxx = cxy'*cxpy; + +% ** estimate A+_hat conditional on A0, ncoef*nvar, but not using full prior +%GlbAph = cxpy*A0h; + + +%================================================= +% Computing the final covariance matrix (S1,...,Sm) for the posterior of A0, +% with the data, and final Gb=(G1,...,Gm) for A+ if asymmetric prior or for +% B if symmetric prior for A+ +%================================================= +% +H0invmulti=zeros(nvar,nvar,nvar); % inv(H0) for different equations under asymmetric prior +Hpinvmulti=zeros(ncoef,ncoef,nvar); % inv(H+) for different equations under asymmetric prior +for i = 1:nvar + stri = find(idmat0(:,i)); + % CAS change 9/24/96, to avoid slim chance of an exact zero in x vector + % at some point during an optimization. + %strm = length(stri); % TZ, 11/27/97, no use any more + + %A0hb = A0h(stri,i)-A0b(stri,i); + + % ** set up the conditional prior variance sg0bi and sgpbi. + % sg0bd = zeros(stri,1); Commented out by CAS, 9/24/96. Looks like this + % meant to have strm where it has stri, and in any case it is "overwritten" below. + + %------------------------------ + % Introduce prior information on which variables "belong" in various equations. + % In this first trial, we just introduce this information here, in a model-specific way. + % Eventually this info has to be passed parametricly. In our first shot, we just damp down + % all coefficients except those on the diagonal. + factor0=idmat0(:,i); + sg0bd = sg0bida; % added by TZ, 2/26/98. I think at each equation, sg0bd must + % be refreshed. Note, this only works for the prior variance Sg(i) + % of a0(i) being diagonal. If the prior variance Sg(i) is not + % diagonal, we have to work on inv(Sg(i)) or sg0bdi directly. + sg0bd(stri) = sg0bida(stri).*factor0(stri); + sg0bdi = 1./sg0bd; + % + factor1=idmatpp(1:nvar,i); + sg1bd = sgpbida(1:nvar).*factor1; + sg1bdi = 1./sg1bd; + % + if lags>1 + factorpp=idmatpp(nvar+1:ncoef-1,i); + sgpp_cbd = sgppbd(1:ncoef-nvar-1) .* factorpp; + sgpp_cbdi = 1./sgpp_cbd; + end + + % ** set up the unconditional prior variance on A0i and A+i + %XX = zeros(nvar,strm); + %XX(stri,:) = eye(strm); % XX in Gelman, etel, on p479 + % Commented out by TZ, 11/27/97. Streamline. No need for these any more. + + + % * final conditional prior variance on A+i give that on A0i, and + % * unconditional variance on A0+ + H0td = diag(sg0bd); % unconditional + % H_~: td: tilde for ~ + % ** inverse and chol decomp + H0tdi = diag(sg0bdi); + H0invmulti(:,:,i)=H0tdi; + + % + Hptd(1:nvar,1:nvar)=diag(sg1bd); + Hptdi(1:nvar,1:nvar)=diag(sg1bdi); + if lags>1 + Hptd(nvar+1:ncoef-1,nvar+1:ncoef-1)=diag(sgpp_cbd); + Hptdi(nvar+1:ncoef-1,nvar+1:ncoef-1)=diag(sgpp_cbdi); + % condtional on A0i, H_plus_tilde + end + Hpinvmulti(:,:,i)=Hptdi; + + % common terms + xxhp = xtx+Hptdi; + %Lxxhpc = chol(inv(xxhp))'; % lower triangular + xxhpc = chol(xxhp); % upper triangular but its transpose is lower triagular Choleski + %A0hbH = A0hb'*H0tdi; + %====== The following two lines seem incorrect. The third line is supposed to correc the mistake. May 2003. + % H1p_1 = zeros(ncoef,nvar); + % H1p_1(1:nvar,:) = Hptdi(1:nvar,1:nvar); + H1p_1 = Hptdi(:,1:nvar); + %%Hm = (cyx+H1p_1')*(xxhp\(cxy+H1p_1)); + Hm1 = (cyx+H1p_1')/xxhp; % if symmetric prior, Bh=Hm1' -- reduced form k-by-m. + Gb{i} = Hm1'; % k-by-m, where k--ncoef, m--nvar. + % If asymmetric prior, Gb is used to compute A+ where A+(i) = Gb(i)*a0(i) + % where a0(i) is m-by-1 for the ith column of A0 or the ith equation. + %Hm2 = cxy+H1p_1; + Hm = Hm1*(cxy+H1p_1); + %GlbAph(i,:) = A0h(stri,i)'*XX'*Hm1; % alpha_plus_*_transpose + %%alpMpyh = A0h(stri,i)'*XX'*(yty+Hptdi(1:nvar,1:nvar)-Hm)*XX; + %Hss = XX'*(yty+Hptdi(1:nvar,1:nvar)-Hm)*XX; + Hss = yty+Hptdi(1:nvar,1:nvar)-Hm; + Sbd{i} = (H0tdi+Hss)./fss; % m-by-m, where m--nvar. If asymmetric prior, Scd is + % usde to form diag(Sbd{1}, ..., Sbd{m}) for a0 or vec(A0) in the + % posterior of A0. Note, "bd" stands for block diagonal and divided by + % "fss" already to make it compatible with SpH used in "a0lhfun" and make it + % it easier according to the notations by Waggoner and Zha +end + + +%%========================================= +%% check if there is asymmetric prior on both A+ and A0 +%%========================================= +% +spindx=1; % A+ index for asymmetric prior +s0indx=1; % A0 index for asymmetric prior +for i=2:nvar + diffGb = Gb{i}-Gb{i-1}; + diffSbd = Sbd{i}-Sbd{i-1}; + if ~any(any(diffGb)) + spindx=spindx+1; + end + if ~any(any(diffSbd)) + s0indx=s0indx+1; + end +end +% +if (spindx==nvar) + Bh = Gb{1}; % reduced-form parameter. Note: does not depend on A0 +else + Bh = NaN; +end +% +if (s0indx==nvar) + SpH = (H0tdi+Hss)/fss; % the final S in the exponential part of p(A0|y) + % divided by nobs in order to make Choleski decomp without optimization + % or in the form conformable to Waggoner and Zha +else + SpH=NaN; +end + + + + + +%---------------------------------------------- +% + +% *** +% *** Form the inverse of covarinace to draw from t- or Gaussian distribution +% *** +%SpHs = SpH*fss; % for the Wishart draw +%SpHsc = chol(SpHs); % upper triangular where Sphsc' is +% % lower triangular Choleski, for Wishart draw +%SpHsic = chol(inv(SpHs))'; % inverse Choleski decomposition -- lower triangular +%A0hin = chol(SpH); % upper triangular, inverse of A0h, each column + % corresponds to an equation. + + +%@@@ The following can be used for other purposes such as forecasting +% +%swish = A0hin'; % each row corresponds to an equation +%A0h = inv(A0hin); % each column corresponds to an equation +%xa0 = A0h(a0indx); + +%%*** form Bh (ncoef*nvar) +%Aplus = Hm1t*A0h; % estimate of Aplus -- the same as Astrar +%Bhp = Hm1t; diff --git a/MatlabFiles/szbvar.m b/MatlabFiles/szbvar.m new file mode 100755 index 0000000..5a00632 --- /dev/null +++ b/MatlabFiles/szbvar.m @@ -0,0 +1,337 @@ +function [A0hin,Hm1t,fss,ndobs,phi,y,nvar,ncoef,SpH,SpHsc,xxhpc,a0indx,na0p,... + idmat0] = szbvar(idfile,q_m,lags,nSample,nhp,xdgel) +% Estimating the Bayesian VAR of Sims and Zha: +% function [A0hin,Hm1t,fss,ndobs,phi,y,nvar,ncoef,SpH,SpHsc,xxhpc,a0indx,na0p,... +% idmat0] = szbvar(idfile,q_m,lags,nSample,nhp,xdgel) +% +% idfile: Identification filename such as "iden4" (with the extension ".prn"). +% q_m: quarter or month +% lags: the maximum length of lag +% nSample: the sample size (including lags, of course) +% nhp: number of haperparameters +% imstp: number of impusle response steps +% xdgel: the general matrix of the original data (no manipulation involved) +% ------ +% A0hin: chol(SpH) -- inverse of A0h, upper triangular, each column corresponds to an equation +% Hm1t: reduced form B +% fss: in-sample-size (for forecasting). Including dummy observations +% ndobs: number of dummy observations, ndobs=nvar+1 +% phi: X in the form of y = X*B+U. Row: nSmaple-lags+ndobs. Column: ncoef +% y: y in the form y = X*B+U. Including the dummy observations too, +% T-lags+ndobs-by-nvar. +% nvar: number of variables +% ncoef: number of coefficients in *each* equation. RHS coefficients only, nvar*lags+1 +% SpH: divided by T, the final S in the Waggoner-Zha exponential part of p(A0|y) +% SpHsc: upper triagular in the lower triangular Choleski of SpH*fss, for Wishart +% xxhpc: chol(X'X+inv(H_p_tilde)): upper triangular but its transpose +% is lower triagular Choleski +% a0indx: the index number for free parameters in A0. Column meaning equation +% na0p: number of free parameters in A0 +% idmat0: identification matrix for A0; only 1's and 0's. Column meaning equation. +% +% Copyright (c) July 1997 by C.A. Sims and T. Zha +% +% Quick Revisions: May 2003. See H1p_1 on lines 301-304. + +% +%@@@ Prepared for Bayesian VAR of Sims and Zha +% +%* Load identification and obtain idmat0 +eval(['load ' idfile '.prn -ascii']); +eval(['idmat0=' idfile ';']); +idmat0=idmat0'; % so that each column corresponds to an equation +a0indx=find(idmat0); % column meaning equation +na0p = length(a0indx); % number of free parameters in A0 +nfp = na0p + nhp; % total number of free parameter +[nvar,neqn]=size(idmat0); + +%$$$ available computations +% +%@@@ original +% total number of the sample under study, including lags, etc. -- original sample size +sb = lags+1; % original beginning without dummies +sl = nSample; % original last period without dummies +ssp = nSample - lags; % original number of observations +% +ndobs=nvar+1; % number of dummy observations +ncoef = nvar*lags+1; % number of coefficients in *each* equation, RHS coefficients only. +%*** initializing for global variables +%%GlbAph=zeros(nvar,ncoef); +Aplus=zeros(ncoef,nvar); +SpH = ones(nvar,nvar); +%* flp: forecast last period (with dummies); +%* fbp: forecast beginning period (with dummies). +flp = sl+ndobs; +fbp = ndobs+lags+1; % <<>> true begining by skipping dummies +fss = flp-lags; % forecast sample size (with dummies). + +% ** hyperparameters +mu = zeros(nhp,1); +mu(1) = 0.57; +mu(2) = 0.13; +mu(3) = 0.1; +mu(4) = 1; +mu(5) = 5; +mu(6) = 5; +% +% mu(1): overall tightness and also for A0; +% mu(2): relative tightness for A+; +% mu(3): relative tightness for the constant term; +% mu(4): tightness on lag decay; +% mu(5): weight on nvar sums of coeffs dummy observations (unit roots); +% mu(6): weight on single dummy initial observation including constant (cointegration, unit +% roots, and stationarity). + + +% ** monthly lag decay in order to match quarterly decay: a*exp(bl) where +% ** l is the monthly lag. Suppose quarterly decay is 1/x where x=1,2,3,4. +% ** Let the decay of l1 match that of x1 (say, beginning) and the decay +% ** of l2 match that of x2 (say, end), we can solve for a and b which are +% ** b = (log_x1-log_x2)/(l1-l2), and a = x1*exp(-b*l1). +if q_m==12 + l1 = 1; % 1st month == 1st quarter + xx1 = 1; % 1st quarter + l2 = lags; % last month + xx2 = 1/((ceil(lags/3))^mu(4)); % last quarter + %xx2 = 1/6; % last quarter + % 3rd quarter: i.e., we intend to let decay of the 6th month match + % that of the 3rd quarter, so that the 6th month decays a little + % faster than the second quarter which is 1/2. + if lags==1 + b = 0; + else + b = (log(xx1)-log(xx2))/(l1-l2); + end + a = xx1*exp(-b*l1); +end + +% +% ** now run the VAR with +% +% **** nvar prior dummy observations with the sum of coefficients +% ** construct X for Y = X*B + U where phi = X: (T-lags)*k, Y: (T-lags)*nvar +% ** columns: k = # of [nvar for 1st lag, ..., nvar for last lag, const] +% ** Now, T=T+ndobs -- added with "ndobs" dummy observations +% +phi = zeros(fss,ncoef); +const = ones(fss,1); +const(1:nvar) = zeros(nvar,1); +phi(:,ncoef) = const; % the first nvar periods: no or zero constant! +% +xdgelint = mean(xdgel(1:lags,:),1); +% mean of the first lags initial conditions +for k=1:nvar + for m=1:lags + phi(ndobs,nvar*(m-1)+k) = xdgelint(k); + phi(k,nvar*(m-1)+k) = xdgelint(k); + % <<>> multiply hyperparameter later + end +end +for k=1:lags + phi(ndobs+1:fss,nvar*(k-1)+1:nvar*k) = xdgel(sb-k:sl-k,:); + % row: T-lags; column: [nvar for 1st lag, ..., nvar for last lag, const] + % Thus, # of columns is nvar*lags+1 = ncoef. +end +% +% ** Y with "ndobs" dummies added +y = zeros(fss,nvar); +for k=1:nvar + y(ndobs,k) = xdgelint(k); + y(k,k) = xdgelint(k); + % <<>> place hyperparameter later +end +y(ndobs+1:fss,:) = xdgel(sb:sl,:); + +% +% *** specify the prior for each equation separately, SZ method, +% *** +% *** obtaining the residuals for the univariate processes: +% *** a total of "nvar" equations +% *** obtain the posterior peak of A0 which is Sims iden1 (Sims 1986) +% ** get the residuals from univariate regressions. +% +sgh = zeros(nvar,1); % square root +sgsh = sgh; % square +nn = [1 lags nSample]; +yu = xdgel; +C = ones(nSample,1); +for k=1:nvar + [Bk,ek,junk1,junk2,junk3,junk4] = sye([yu(:,k) C],nn); + clear Bk junk1 junk2 junk3 junk4; + sgsh(k) = ek'*ek/ssp; + %% sgh(k) = ek'*ek/(fss-7); to match "sqrt(ess)" in RATS univariate regression + sgh(k) = sqrt(sgsh(k)); +end +% ** prior variance for alpha0, same for all equations!!! +al0b = zeros(nvar*neqn,0); % prior mean for all A0 +sg0bid = zeros(nvar,1); % Sigma0_bar diagonal only +for j=1:nvar + sg0bid(j) = 1/sgsh(j); % sgsh = sigmai^2 +end +% ** prior variance for alpha_plus, same for all equations +sgpbid = zeros(ncoef,1); % Sigma_plus_bar, diagonal +for i = 1:lags + if (q_m==12) + lagdecay = a*exp(b*i); + end + % + for j = 1:nvar + if (q_m==12) + % exponential decay to match quarterly decay + sgpbid((i-1)*nvar+j) = lagdecay^2/sgsh(j); + %%sgpbid((i-1)*nvar+j) = (1/i)^2/sgsh(j); + elseif (q_m==4) + sgpbid((i-1)*nvar+j) = (1/i^mu(4))^2/sgsh(j); + else + warning('Incompatibility with lags, check the possible errors!!!') + return + end + end +end +%%A0bd = sqrt(sg0bid); +% commented out by T.A. Zha, 10/3/96, to avoid double-counting of scaling and the problem +% of potential multiple peaks. +A0bd = zeros(nvar,1); +A0b = sparse(1:nvar,1:nvar,A0bd,nvar,nvar); +A0b = A0b'; % making a column in A0b correspond to an equation + +% + + +%================================================= +% Computing the (prior) covariance matrix for the posterior of A0, no data yet +%================================================= +% +% +% ** weight prior dummy observations +%phi(1:nvar,:) = (mu(5)^2/mu(1)^2)*phi(1:nvar,:); +%y(1:nvar,:) = (mu(5)^2/mu(1)^2)*y(1:nvar,:); +%phi(ndobs,:) = mu +% modified by CAS 8/6/96. The dummy obs weights are naturally in std units, not var units. +% +phi(1:nvar,:) = mu(5)*phi(1:nvar,:); % standard Sims and Zha prior +y(1:nvar,:) = mu(5)*y(1:nvar,:); % standard Sims and Zha prior +%----- The following prior designed for GLZ +%phi(1,:) = 1.00*mu(5)*phi(1,:); +%phi(2:nvar,:) = 1.02*mu(7)*phi(2:nvar,:); +%y(1,:) = mu(5)*y(1,:); +%y(2:nvar,:) = mu(7)*y(2:nvar,:); +%---------------------------- +% +phi(nvar+1,:) = mu(6)*phi(nvar+1,:); +y(nvar+1,:) = mu(6)*y(nvar+1,:); + + +% ** set up the conditional prior variance sg0bi and sgpbi. +sg0bida = mu(1)^2*sg0bid; +sgpbida = mu(1)^2*mu(2)^2*sgpbid; +sgpbida(ncoef) = mu(1)^2*mu(3)^2; +sgppbd = sgpbida(nvar+1:ncoef); % corresponding to A++, in a Sims-Zha paper +%%sgppbdi = 1./sgppbd; +%sgppb = diag(sgppbd); + +Hptd = zeros(ncoef); +Hptdi=Hptd; +%%Hptd(nvar+1:ncoef,nvar+1:ncoef)=diag(sgppbd); +%%Hptdi(nvar+1:ncoef,nvar+1:ncoef)=diag(sgppbdi); +Hptd(ncoef,ncoef)=sgppbd(ncoef-nvar); +Hptdi(ncoef,ncoef)=1/sgppbd(ncoef-nvar); + % condtional on A0i, H_plus_tilde +sg0bd = sg0bida; +sg0bdi = 1./sg0bd; +sg1bd = sgpbida(1:nvar); +sg1bdi = 1./sg1bd; +if lags>1 + sgpp_cbd = sgppbd(1:ncoef-nvar-1); + sgpp_cbdi = 1./sgpp_cbd; % _cbd: c -- constant, b -- barred (without), d -- diagonal +end + + +% ** set up the unconditional prior variance on A0i and A+i +%%XX = zeros(nvar,strm); +%%XX(stri,:) = eye(strm); % XX in Gelman, etel, on p479 +% +% * final conditional prior variance on A+i give that on A0i, and +% * unconditional variance on A0+ +H0td = diag(sg0bd); % unconditional +% H_~: td: tilde for ~ +% ** inverse and chol decomp +H0tdi = diag(sg0bdi); + +% +Hptd(1:nvar,1:nvar)=diag(sg1bd); +Hptdi(1:nvar,1:nvar)=diag(sg1bdi); +if lags>1 + Hptd(nvar+1:ncoef-1,nvar+1:ncoef-1)=diag(sgpp_cbd); + Hptdi(nvar+1:ncoef-1,nvar+1:ncoef-1)=diag(sgpp_cbdi); + % condtional on A0i, H_plus_tilde +end + + +%================================================= +% Computing the final covariance matrix for the posterior of A0, with the data +%================================================= +% +% ** some common terms +[u d v]=svd(phi,0); %trial +% xtx = phi'*phi; %trial +vd=v.*(ones(size(v,2),1)*diag(d)'); %trial +xtx=vd*vd'; +% M = eye(fss) - phi*(xtx\phi'); % not used except in line below %trial +yu = y'*u; %trial +cxyxx=yu*yu'; %trial +yty=y'*y; +ymy=yty-cxyxx; %trial +%ymy = y'*M*y; +%cxy = phi'*y; %trial +cxy = vd*yu'; %trial +cyx = cxy'; +%cxpy = xtx\cxy; %not used further except in line below +%cxyxx = cxy'*cxpy; + +% ** estimate A+_hat conditional on A0, ncoef*nvar, but not using full prior +%GlbAph = cxpy*A0h; + + +% common terms +xxhp = xtx+Hptdi; +%Lxxhpc = chol(inv(xxhp))'; % lower triangular +xxhpc = chol(xxhp); % upper triangular but its transpose is lower triagular Choleski +%A0hbH = A0hb'*H0tdi; +%====== The following two lines seem incorrect. The third line is supposed to correc the mistake. May 2003. +% H1p_1 = zeros(ncoef,nvar); +% H1p_1(1:nvar,:) = Hptdi(1:nvar,1:nvar); +H1p_1 = Hptdi(:,1:nvar); +%%Hm = (cyx+H1p_1')*(xxhp\(cxy+H1p_1)); +Hm1 = (cyx+H1p_1')/xxhp; +Hm1t = Hm1'; +%Hm2 = cxy+H1p_1; +Hm = Hm1*(cxy+H1p_1); +%%alpMpyh = A0h(stri,i)'*XX'*(yty+Hptdi(1:nvar,1:nvar)-Hm)*XX; +Hss = yty+Hptdi(1:nvar,1:nvar)-Hm; +SpH = (H0tdi+Hss)/fss; % the final S in the exponential part of p(A0|y) +% divided by nobs in order to make Choleski decomp without optimization +% or in the form conformable to Waggoner and Zha + +% *** +% *** Form the inverse of covarinace to draw from t- or Gaussian distribution +% *** +SpHs = SpH*fss; % for the Wishart draw +SpHsc = chol(SpHs); % upper triangular where Sphsc' is lower triangular Choleski +%SpHsic = chol(inv(SpHs))'; % inverse Choleski decomposition -- lower triangular + +A0hin = chol(SpH); % upper triangular, inverse of A0h, each column + % corresponds to an equation. + + +%---------------------------------------------- +% +%@@@ The following can be used for other purposes such as forecasting +% +%swish = A0hin'; % each row corresponds to an equation +%A0h = inv(A0hin); % each column corresponds to an equation +%xa0 = A0h(a0indx); + +%%*** form Bh (ncoef*nvar) +%Aplus = Hm1t*A0h; % estimate of Aplus -- the same as Astrar +%Bhp = Hm1t; diff --git a/MatlabFiles/tran_a2b.m b/MatlabFiles/tran_a2b.m new file mode 100755 index 0000000..8158d13 --- /dev/null +++ b/MatlabFiles/tran_a2b.m @@ -0,0 +1,29 @@ +function b = tran_a2b(A0,Ui,nvar,n0) +% b = tran_a2b(A0,Ui,nvar,n0) +% +% Transform A0 to free parameters b's. Note: columns correspond to equations +% +% A0: nvar-by-nvar, contempareous matrix (columns correspond to equations) +% Ui: nvar-by-1 cell. In each cell, nvar-by-qi orthonormal basis for the null of the ith +% equation contemporaneous restriction matrix where qi is the number of free parameters. +% With this transformation, we have ai = Ui*bi or Ui'*ai = bi where ai is a vector +% of total original parameters and bi is a vector of free parameters. When no +% restrictions are imposed, we have Ui = I. There must be at least one free +% parameter left for the ith equation. +% nvar: number of endogeous variables +% n0: nvar-by-1, ith element represents the number of free A0 parameters in ith equation +%---------------- +% b: sum(n0)-by-1 vector of A0 free parameters +% +% Tao Zha, February 2000 + + +n0cum = cumsum(n0); +b=zeros(n0cum(end),1); +for kj = 1:nvar + if kj==1 + b(1:n0(kj))=Ui{kj}'*A0(:,kj); + else + b(n0cum(kj-1)+1:n0cum(kj))=Ui{kj}'*A0(:,kj); + end +end diff --git a/MatlabFiles/tran_b2a.m b/MatlabFiles/tran_b2a.m new file mode 100755 index 0000000..2c20b97 --- /dev/null +++ b/MatlabFiles/tran_b2a.m @@ -0,0 +1,29 @@ +function A0 = tran_b2a(b,Ui,nvar,n0) +% A0 = tran_b2a(b,Ui,nvar,n0) +% +% Transform free parameters b's to A0. Note: columns correspond to equations +% +% b: sum(n0)-by-1 vector of A0 free parameters +% Ui: nvar-by-1 cell. In each cell, nvar-by-qi orthonormal basis for the null of the ith +% equation contemporaneous restriction matrix where qi is the number of free parameters. +% With this transformation, we have ai = Ui*bi or Ui'*ai = bi where ai is a vector +% of total original parameters and bi is a vector of free parameters. When no +% restrictions are imposed, we have Ui = I. There must be at least one free +% parameter left for the ith equation. +% nvar: number of endogeous variables +% n0: nvar-by-1, ith element represents the number of free A0 parameters in ith equation +%---------------- +% A0: nvar-by-nvar, contempareous matrix (columns correspond to equations) +% +% Tao Zha, February 2000 + +b=b(:); +A0 = zeros(nvar); +n0cum = cumsum(n0); +for kj = 1:nvar + if kj==1 + A0(:,kj) = Ui{kj}*b(1:n0(kj)); + else + A0(:,kj) = Ui{kj}*b(n0cum(kj-1)+1:n0cum(kj)); + end +end diff --git a/MatlabFiles/xydata.m b/MatlabFiles/xydata.m new file mode 100755 index 0000000..4ba08e4 --- /dev/null +++ b/MatlabFiles/xydata.m @@ -0,0 +1,174 @@ +function [phi,y,fss,xtx,xty,yty,Bols] = xydata(xdgel,lags,mu) +% [phi,y,xtx,xty,yty,Bols,fss] = xydata(xdgel,lags,mu) +% Construct matrices X, Y, X'X, etc. so that y = X*B + U, where y is T-by-1, X T-by-ncoef, +% and B is ncoef-by-1. +% +% xdgel: the general matrix of the original data (no manipulation involved) +% with sample size including lags +% lags: the lag length in the AR(p) process +% mu: 2-by-1 vector of hyperparameters for dummy observations (FRA's parameter settings) +% mu(1): weight on nvar sums of coeffs dummy observations (unit roots); (5) +% mu(2): weight on single dummy initial observation including constant +% (cointegration, unit roots, and stationarity); (5) +%--------------- +% phi: X: T-by-ncoef where ncoef=nvar*lags + constant and T=fss +% y: Y: T-by-nvar where T=fss +% fss: effective sample size (including dummies if mu is provided) exclusing all lags +% xtx: X'X (Data) +% xty: X'Y (Data) +% yty: Y'Y (Data) +% Bols: ncoef-by-1: OLS estimate of B +% Copyright (c) September 1999 Tao Zha +% +% Copyright Kilian and Zha +%function [Gb,Sbd,Bh,SpH,fss,ndobs,phi,y,nvar,ncoef,xxhpc,a0indx,na0p,... +% idmat0,idmatpp] = szasbvar(idfile,q_m,lags,xdgel,mu) +% Now version: [Gb,Sbd,Bh,SpH,fss,ndobs,phi,y,nvar,ncoef,xxhpc,a0indx,na0p,... +% idmat0,idmatpp] = szasbvar(idfile,q_m,lags,xdgel,mu) +% +% Estimating the Bayesian VAR of Sims and Zha with asymmetric prior (as) +% +% idfile: Identification filename with rows corresponding to equations. +% But all the output will be transposed to columns +% corresponding to equations. +% q_m: quarter or month +% lags: the maximum length of lag +% nhp: number of haperparameters +% xdgel: the general matrix of the original data (no manipulation involved) +% with sample size including lags +% mu: 6-by-1 vector of hyperparameters (the following numbers for Atlanta Fed's forecast) +% mu(1): overall tightness and also for A0; (0.57) +% mu(2): relative tightness for A+; (0.13) +% mu(3): relative tightness for the constant term; (0.1) +% mu(4): tightness on lag decay; (1) +% mu(5): weight on nvar sums of coeffs dummy observations (unit roots); (5) +% mu(6): weight on single dummy initial observation including constant +% (cointegration, unit roots, and stationarity); (5) +% -------------------- +% -------------------- +% Gb: cell(nvar,1). Each cell, postmultiplied by A0(:,i), is used to compute A+(:,i) +% where A+ is k-by-m, where k--ncnoef, m--nvar, if asymmetric prior +% Sbd: cell(nvar,1). Sbd=diag(S(1), ..., S(m)). Already divided by 'fss' for the +% posterior of a0 or A0(:) in Waggoner and Zha when one has asymmetric prior. +% Note,"bd" stands for block diagonal. +% Bh: reduced form B, k(mp+1)-by-m, column--equation. Bh=NaN if asymmetric prior. +% In the form of y=X*B+U where B=[B1|B2| ...|Bp|C] +% where Bi: m-by-m (i=1,..,p--lag length), C: 1-by-ml, constant. +% SpH: divided by T, the final S in the Waggoner-Zha exponential part of p(A0|y) +% SpH=NaN if asymmetric prior +% fss: in-sample-size (for forecasting). Including dummy observations +% ndobs: number of dummy observations, ndobs=nvar+1 +% phi: X in the form of y = X*B+U. Row: nSmaple-lags+ndobs. Column: ncoef +% y: y in the form y = X*B+U. Including the dummy observations too, +% T-lags+ndobs-by-nvar. +% nvar: number of variables +% ncoef: number of coefficients in *each* equation. RHS coefficients only, nvar*lags+1 +% xxhpc: chol(X'X+inv(H_p_tilde)): upper triangular but its transpose +% is lower triagular Choleski +% a0indx: the index number for free parameters in A0. Column meaning equation +% na0p: number of free parameters in A0 +% idmat0: identification matrix for A0 with asymmetric prior; column -- equation. +% idmatpp: asymmetric prior variance for A+ without constant; column -- equation. +% +% Revisions by CAS 9/27/96: If we transmit idmat, rather than a0indx, we can scale +% the elements of idmat0 or idmatp so that it carries information about relative +% prior variances. +% Revsions by TZ, 10/13/96: Efficiency improvement by streamlining the previous +% code according to the general setup in Sims and Zha's IER and according +% to Zha's notes Forecast (0) (p.3) and Forecast (1) (p.9). +% +% Copyright (c) September 1999 by Tao Zha +% +% NOTE: "nSample" is something I deleted as an input recently, so it may not +% be compatible with old programs, 10/15/98 by TAZ. +% +% NOTE2: I put "mu" as an input arg and delete "nhp" as an input arg, so it may +% not be compatible with old programs, 03/06/99 by TAZ + + +[nSample,nvar]=size(xdgel); % sample size including lags and number of variables +ncoef=nvar*lags+1; % number of coefficients in *each* equation, RHS coefficients only, + % with only constant +ndobs=nvar+1; % number of dummy observations +sb = lags+1; % the beginning of original sample without dummies + +if nargin==3 % activate the option of dummy observations + fss = nSample+ndobs-lags; + % Effective sample size including dummies but exclusing all lags + + % + % **** nvar prior dummy observations with the sum of coefficients + % ** construct X for Y = X*B + U where phi = X: (T-lags)*k, Y: (T-lags)*nvar + % ** columns: k = # of [nvar for 1st lag, ..., nvar for last lag, const] + % ** Now, T=T+ndobs -- added with "ndobs" dummy observations + % + phi = zeros(fss,ncoef); + const = ones(fss,1); + const(1:nvar) = zeros(nvar,1); + % the first nvar periods: no or zero constant (designed for dummies)! + phi(:,ncoef) = const; + % + xdgelint = mean(xdgel(1:lags,:),1); % mean of the first lags initial conditions + %**** Dummies for phi + for k=1:nvar + for m=1:lags + phi(ndobs,nvar*(m-1)+k) = xdgelint(k); + phi(k,nvar*(m-1)+k) = xdgelint(k); + % <<>> multiply hyperparameter later + end + end + %* True data for phi + for k=1:lags + phi(ndobs+1:fss,nvar*(k-1)+1:nvar*k) = xdgel(sb-k:nSample-k,:); + % row: T-lags; column: [nvar for 1st lag, ..., nvar for last lag, const] + % Thus, # of columns is nvar*lags+1 = ncoef. + end + % + % ** Y with "ndobs" dummies added + y = zeros(fss,nvar); + %* Dummies for y + for k=1:nvar + y(ndobs,k) = xdgelint(k); + y(k,k) = xdgelint(k); + % multiply hyperparameter later + end + %* True data for y + y(ndobs+1:fss,:) = xdgel(sb:nSample,:); + % + %*** Dummies once again (finfal version) + phi(1:nvar,:) = 1*mu(1)*phi(1:nvar,:); % standard Sims and Zha prior + y(1:nvar,:) = mu(1)*y(1:nvar,:); % standard Sims and Zha prior + % + phi(nvar+1,:) = mu(2)*phi(nvar+1,:); + y(nvar+1,:) = mu(2)*y(nvar+1,:); +else % dummy observations + fss = nSample-lags; + % Effective sample size with no dummies but exclusing all lags + + % + % **** nvar prior dummy observations with the sum of coefficients + % ** construct X for Y = X*B + U where phi = X: (T-lags)*k, Y: (T-lags)*nvar + % ** columns: k = # of [nvar for 1st lag, ..., nvar for last lag, const] + % ** Now, T=T+ndobs -- added with "ndobs" dummy observations + % + phi = zeros(fss,ncoef); + const = ones(fss,1); + phi(:,ncoef) = const; + %* True data for phi + for k=1:lags + phi(1:fss,nvar*(k-1)+1:nvar*k) = xdgel(sb-k:nSample-k,:); + % row: T-lags; column: [nvar for 1st lag, ..., nvar for last lag, const] + % Thus, # of columns is nvar*lags+1 = ncoef. + end + % + %* True data for y + y(1:fss,:) = xdgel(sb:nSample,:); +end +%*** data input for the posterior density +[xq,xr]=qr(phi,0); +xtx=xr'*xr; % X'X +xty=phi'*y; % X'Y +yty = y'*y; % Y'Y + +Bols = xr\(xr'\xty); % inv(X'X)*X'Y + diff --git a/MatlabFiles/zroot.m b/MatlabFiles/zroot.m new file mode 100755 index 0000000..f72125d --- /dev/null +++ b/MatlabFiles/zroot.m @@ -0,0 +1,30 @@ +function zstar = zroot(B) +% zroot(B); find roots of a matrix polynomial +% B: the 3 dimensional array B, e.g. B(:,:,1) is B_1, B(:,:,2) is B_2 and +% B(:,:,p) is B_p. Note: rows correpond to equations. See Judge (1), pp. 763-764. +% For the system of equations: +% y_t = B_1*y_{t-1} + ... + B_p*Y_{t-p} + u_t. +% The corresponding matrix polynomial is: +% det(eye(m)-B_1*z-...-B_p*z^p) = 0 +% zroot(B) solves for the roots of this above polynomial. The matrices B_1, B_2,....B_p +% are passed through B. The degree of the matrix polynomial is determined +% by the size of the third dimension of B. +% Each of the B(:,:,i) must be an m by m matrix. + +% ZROOT was written by Clark A. Burdick of the research +% department of the Federal Reserve Bank of Atlanta. +% Original: July 31, 1997 +% Last Modified: July 31, 1997 + +% TO BE DONE: +% Better bullet proofing + + +[a b c] = size(B); +syms z; +thepoly = eye(size(B(:,:,1)))-B(:,:,1)*z; +for i=2:c + thepoly = thepoly-B(:,:,i)*z^i; +end +zstar=roots(sym2poly(det(thepoly))); + -- GitLab