From 99cb7311127e3bd57f4d921abbbf18f7ae927029 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Charybdis=29?= <stephane.adjemian@univ-lemans.fr> Date: Thu, 1 Jun 2017 19:34:01 +0200 Subject: [PATCH] Fixed indentation of matlab files. --- doc/userguide/models/fs2000ns_steadystate.m | 98 +- doc/userguide/models/fsdat.m | 388 +- dynare++/extern/matlab/dynare_simul.m | 82 +- dynare++/sylv/matlab/gensylv.m | 15 +- examples/NK_baseline_steadystate.m | 14 +- examples/fsdat_simul.m | 816 +-- matlab/@dynTimeIndex/subsref.m | 2 +- matlab/AHessian.m | 175 +- matlab/AIM/SPAimerr.m | 2 +- matlab/AIM/SPAmalg.m | 2 +- matlab/AIM/SPBuild_a.m | 14 +- matlab/AIM/SPCopy_w.m | 6 +- matlab/AIM/SPEigensystem.m | 32 +- matlab/AIM/SPExact_shift.m | 12 +- matlab/AIM/SPNumeric_shift.m | 20 +- matlab/AIM/SPObstruct.m | 10 +- matlab/AIM/SPReduced_form.m | 2 +- matlab/AIM_first_order_solver.m | 54 +- matlab/DsgeSmoother.m | 48 +- matlab/GetPosteriorMeanVariance.m | 64 +- matlab/PosteriorIRF.m | 158 +- matlab/PosteriorIRF_core2.m | 4 +- matlab/UnivariateSpectralDensity.m | 2 +- matlab/WriteShockDecomp2Excel.m | 2 +- matlab/add_filter_subtitle.m | 2 +- matlab/add_path_to_mex_files.m | 4 +- matlab/annualized_shock_decomposition.m | 208 +- matlab/backward/simul_backward_model.m | 4 +- matlab/basic_plan.m | 114 +- matlab/bvar_forecast.m | 6 +- matlab/check_matlab_path.m | 66 +- matlab/check_posterior_sampler_options.m | 606 +-- matlab/chol_SE.m | 2 +- matlab/cli/prior.m | 12 +- matlab/collect_latex_files.m | 8 +- matlab/compute_moments_varendo.m | 4 +- matlab/compute_overall_acceptance_ratio.m | 2 +- .../convergence_diagnostics/McMCDiagnostics.m | 10 +- .../geweke_chi2_test.m | 22 +- .../convergence_diagnostics/geweke_moments.m | 2 +- matlab/convergence_diagnostics/mcmc_ifac.m | 142 +- .../convergence_diagnostics/raftery_lewis.m | 8 +- matlab/convert_dyn_45_to_44.m | 16 +- matlab/convert_oo_.m | 2 +- matlab/covariance_mc_analysis.m | 4 +- matlab/cubature_with_gaussian_weight.m | 20 +- matlab/datatomfile.m | 4 +- matlab/delete_mh_history_files.m | 2 +- matlab/discretionary_policy_1.m | 50 +- matlab/discretionary_policy_engine.m | 8 +- matlab/disp_dr.m | 12 +- matlab/disp_identification.m | 80 +- matlab/disp_moments.m | 10 +- matlab/disp_th_moments.m | 4 +- ...splay_conditional_variance_decomposition.m | 12 +- matlab/display_estimation_results_table.m | 128 +- matlab/display_problematic_vars_Jacobian.m | 52 +- matlab/distributions/lpdfgweibull.m | 2 +- matlab/dr_block.m | 130 +- matlab/dsge_likelihood.m | 132 +- .../dsge_simulated_theoretical_correlation.m | 2 +- ...lated_theoretical_variance_decomposition.m | 10 +- matlab/dsge_var_likelihood.m | 8 +- matlab/dyn_first_order_solver.m | 2 +- matlab/dyn_forecast.m | 8 +- matlab/dyn_latex_table.m | 2 +- matlab/dyn_ramsey_static.m | 14 +- matlab/dyn_risky_steadystate_solver.m | 952 ++-- matlab/dyn_saveas.m | 14 +- matlab/dyn_second_order_solver.m | 264 +- matlab/dyn_waitbar.m | 2 +- matlab/dynare.m | 10 +- matlab/dynare_config.m | 2 +- matlab/dynare_estimation.m | 24 +- matlab/dynare_estimation_1.m | 186 +- matlab/dynare_estimation_init.m | 12 +- matlab/dynare_identification.m | 140 +- matlab/dynare_sensitivity.m | 108 +- matlab/dynare_solve.m | 8 +- matlab/dynare_solve_block_or_bytecode.m | 4 +- matlab/dyntable.m | 2 +- matlab/endogenous_prior.m | 2 +- matlab/endogenous_prior_restrictions.m | 356 +- matlab/ep/ep_problem_2.m | 2 +- matlab/ep/extended_path_core.m | 8 +- matlab/ep/extended_path_homotopy.m | 2 +- matlab/ep/setup_integration_nodes.m | 72 +- ...tochastic_perfect_foresight_model_solver.m | 2 +- ...solve_stochastic_perfect_foresight_model.m | 350 +- matlab/ep/stroud_judd_7.5.8.m | 18 +- matlab/evaluate_max_dynamic_residual.m | 2 +- matlab/evaluate_planner_objective.m | 4 +- matlab/evaluate_smoother.m | 2 +- matlab/evaluate_static_model.m | 46 +- matlab/evaluate_steady_state.m | 490 +- matlab/evaluate_steady_state_file.m | 214 +- matlab/flip_plan.m | 120 +- matlab/gensylv_fp.m | 2 +- matlab/getH.m | 304 +- matlab/getJJ.m | 2 +- matlab/get_Hessian.m | 301 +- matlab/get_all_parameters.m | 4 +- matlab/get_dynare_random_generator_state.m | 32 +- matlab/get_file_extension.m | 2 +- matlab/get_optimal_policy_discount_factor.m | 2 +- matlab/get_subsamples_range_indx.m | 2 +- matlab/global_initialization.m | 6 +- matlab/graph_decomp.m | 6 +- matlab/graph_decomp_detail.m | 160 +- matlab/gsa/Morris_Measure_Groups.m | 52 +- matlab/gsa/Sampling_Function_2.m | 22 +- matlab/gsa/filt_mc_.m | 190 +- matlab/gsa/ghx2transition.m | 36 +- matlab/gsa/gsa_plotmatrix.m | 50 +- matlab/gsa/gsa_skewness.m | 6 +- matlab/gsa/gsa_speed.m | 36 +- matlab/gsa/log_trans_.m | 88 +- matlab/gsa/map_calibration.m | 2 +- matlab/gsa/map_ident_.m | 2856 +++++------ matlab/gsa/mc_moments.m | 28 +- matlab/gsa/mcf_analysis.m | 168 +- matlab/gsa/myboxplot.m | 134 +- matlab/gsa/myprctilecol.m | 8 +- matlab/gsa/pick.m | 178 +- matlab/gsa/prior_draw_gsa.m | 66 +- matlab/gsa/read_data.m | 10 +- matlab/gsa/redform_map.m | 158 +- matlab/gsa/redform_screen.m | 166 +- matlab/gsa/scatter_callback.m | 14 +- matlab/gsa/scatter_mcf.m | 364 +- matlab/gsa/scatter_plots.m | 22 +- matlab/gsa/set_shocks_param.m | 2 +- matlab/gsa/stab_map_.m | 50 +- matlab/gsa/stab_map_1.m | 18 +- matlab/gsa/stab_map_2.m | 96 +- matlab/gsa/stand_.m | 4 +- matlab/gsa/tcrit.m | 204 +- matlab/gsa/teff.m | 46 +- matlab/gsa/trank.m | 4 +- matlab/hessian.m | 2 +- matlab/hessian_sparse.m | 10 +- matlab/ident_bruteforce.m | 6 +- matlab/identification_analysis.m | 88 +- matlab/identification_checks.m | 44 +- matlab/imcforecast.m | 2 +- matlab/init_plan.m | 50 +- matlab/initial_condition_decomposition.m | 88 +- matlab/initial_estimation_checks.m | 6 +- matlab/initvalf.m | 18 +- matlab/interpret_resol_info.m | 4 +- matlab/isolder.m | 4 +- matlab/k_order_pert.m | 26 +- matlab/kalman/likelihood/computeDLIK.m | 198 +- matlab/kalman/likelihood/kalman_filter.m | 2 +- matlab/kalman/likelihood/kalman_filter_d.m | 26 +- matlab/kalman/likelihood/kalman_filter_fast.m | 6 +- .../missing_observations_kalman_filter_d.m | 12 +- .../likelihood/univariate_computeDLIK.m | 16 +- .../likelihood/univariate_computeDstate.m | 10 +- .../likelihood/univariate_kalman_filter.m | 6 +- .../likelihood/univariate_kalman_filter_ss.m | 2 +- matlab/lmmcp/catstruct.m | 348 +- matlab/lmmcp/dyn_lmmcp_func.m | 58 +- matlab/lmmcp/get_complementarity_conditions.m | 16 +- matlab/lmmcp/lmmcp.m | 1250 ++--- matlab/load_first_mh_history_file.m | 2 +- matlab/load_m_file_data_legacy.m | 144 +- matlab/load_mat_file_data_legacy.m | 2 +- matlab/lyapunov_symm.m | 2 +- matlab/marginal_density.m | 6 +- matlab/metropolis_draw.m | 2 +- matlab/metropolis_hastings_initialization.m | 20 +- matlab/metropolis_run_analysis.m | 2 +- matlab/minus_logged_prior_density.m | 4 +- matlab/missing/corrcoef/corrcoef.m | 284 +- .../missing/corrcoef/flag_implicit_skip_nan.m | 16 +- matlab/missing/corrcoef/sumskipnan.m | 36 +- matlab/missing/corrcoef/tcdf.m | 6 +- matlab/missing/ilu/ilu.m | 30 +- matlab/missing/issquare/issquare.m | 4 +- matlab/missing/stats/corr.m | 4 +- matlab/missing/stats/quantile.m | 40 +- matlab/missing_DiffuseKalmanSmootherH1_Z.m | 16 +- matlab/missing_DiffuseKalmanSmootherH3_Z.m | 14 +- matlab/mode_check.m | 2 +- matlab/model_diagnostics.m | 16 +- matlab/model_info.m | 22 +- matlab/model_inversion.m | 4 +- .../clean_files_for_second_type_of_mex.m | 16 +- matlab/ms-sbvar/dyn_save_graph.m | 70 +- matlab/ms-sbvar/identification/exclusions.m | 32 +- .../ms-sbvar/identification/lower_cholesky.m | 12 +- .../ms-sbvar/identification/upper_cholesky.m | 16 +- matlab/ms-sbvar/ms_estimation.m | 2 +- matlab/ms-sbvar/ms_forecast.m | 16 +- matlab/ms-sbvar/ms_irf.m | 16 +- matlab/ms-sbvar/ms_mardd.m | 196 +- matlab/ms-sbvar/ms_sbvar_setup.m | 6 +- matlab/ms-sbvar/ms_variance_decomposition.m | 4 +- matlab/ms-sbvar/ms_write_markov_file.m | 230 +- matlab/ms-sbvar/ms_write_mhm_input.m | 60 +- matlab/ms-sbvar/msstart2.m | 1100 ++--- matlab/ms-sbvar/msstart_setup.m | 88 +- matlab/ms-sbvar/plot_ms_forecast.m | 202 +- matlab/ms-sbvar/plot_ms_irf.m | 168 +- matlab/ms-sbvar/plot_ms_probabilities.m | 34 +- .../ms-sbvar/plot_ms_variance_decomposition.m | 232 +- ...ot_ms_variance_decomposition_error_bands.m | 12 +- .../svar_global_identification_check.m | 2 +- matlab/non_linear_dsge_likelihood.m | 4 +- matlab/occbin/call_solve_one_constraint.m | 42 +- matlab/occbin/call_solve_two_constraints.m | 42 +- matlab/occbin/get_deriv.m | 166 +- matlab/occbin/get_pq.m | 54 +- matlab/occbin/makechart.m | 162 +- matlab/occbin/makechart9.m | 272 +- matlab/occbin/map_regime.m | 50 +- matlab/occbin/mkdata.m | 124 +- matlab/occbin/mkdatap_anticipated.m | 248 +- .../occbin/mkdatap_anticipated_2constraints.m | 358 +- matlab/occbin/pickaxes.m | 32 +- matlab/occbin/process_constraint.m | 74 +- matlab/occbin/setss.m | 28 +- matlab/occbin/solve_no_constraint.m | 100 +- matlab/occbin/solve_no_constraint_noclear.m | 96 +- matlab/occbin/solve_one_constraint.1.m | 384 +- matlab/occbin/solve_one_constraint.m | 400 +- matlab/occbin/solve_two_constraints.m | 610 +-- matlab/occbin/strmerge.m | 16 +- matlab/occbin/tokenize.m | 110 +- matlab/one_sided_hp_filter.m | 2 +- matlab/optimization/cmaes.m | 4362 ++++++++--------- matlab/optimization/csminit1.m | 4 +- matlab/optimization/csminwel1.m | 30 +- .../optimization/dynare_minimize_objective.m | 32 +- matlab/optimization/gmhmaxlik.m | 2 +- matlab/optimization/mr_hessian.m | 14 +- matlab/optimization/newrat.m | 22 +- .../simplex_optimization_routine.m | 76 +- matlab/optimization/simpsa.m | 30 +- matlab/optimization/simpsaget.m | 68 +- matlab/optimization/simpsaset.m | 120 +- matlab/optimization/simulated_annealing.m | 6 +- matlab/options2cell.m | 2 +- matlab/osr1.m | 30 +- matlab/osr_obj.m | 4 +- .../AnalyseComputationalEnvironment.m | 1312 ++--- matlab/parallel/GiveCPUnumber.m | 152 +- matlab/parallel/closeSlave.m | 8 +- matlab/parallel/distributeJobs.m | 4 +- .../parallel/dynareParallelDeleteNewFiles.m | 8 +- matlab/parallel/dynareParallelDir.m | 8 +- matlab/parallel/dynareParallelFindNewFiles.m | 2 +- matlab/parallel/dynareParallelGetFiles.m | 2 +- matlab/parallel/dynareParallelListAllFiles.m | 8 +- matlab/parallel/dynareParallelSendFiles.m | 10 +- matlab/parallel/dynareParallelSnapshot.m | 2 +- matlab/parallel/masterParallel.m | 366 +- matlab/parallel/slaveParallel.m | 2 +- .../det_cond_forecast.m | 120 +- .../linear_perfect_foresight_problem.m | 10 +- .../perfect_foresight_mcp_problem.m | 14 +- .../perfect_foresight_problem.m | 82 +- .../perfect_foresight_setup.m | 14 +- .../perfect_foresight_solver.m | 8 +- .../perfect_foresight_solver_core.m | 4 +- .../private/initialize_stacked_problem.m | 2 +- .../private/simulation_core.m | 4 +- matlab/perfect-foresight-models/sim1.m | 191 +- .../sim1_purely_backward.m | 4 +- .../sim1_purely_forward.m | 2 +- .../solve_stacked_linear_problem.m | 10 +- .../solve_stacked_problem.m | 2 +- matlab/plot_identification.m | 38 +- matlab/plot_shock_decomposition.m | 216 +- matlab/pm3.m | 172 +- matlab/pm3_core.m | 4 +- matlab/posterior_sampler_initialization.m | 50 +- matlab/posterior_sampler_iteration.m | 344 +- matlab/print_info.m | 14 +- matlab/print_table_prior.m | 44 +- matlab/prior_posterior_statistics.m | 10 +- matlab/prior_posterior_statistics_core.m | 38 +- matlab/quadratic_matrix_equation_solver.m | 46 +- matlab/ramsey_policy.m | 2 +- matlab/read_key_value_string.m | 16 +- matlab/read_variables.m | 86 +- matlab/realtime_shock_decomposition.m | 14 +- matlab/reduced_rank_cholesky.m | 2 +- matlab/resid.m | 2 +- matlab/rotated_slice_sampler.m | 368 +- matlab/rplot.m | 20 +- matlab/score.m | 143 +- matlab/set_dynare_random_generator_state.m | 60 +- matlab/set_prior.m | 2 +- matlab/shock_decomposition.m | 2 +- matlab/simulated_moments_estimation.m | 4 +- matlab/simult_.m | 2 +- matlab/simultxdet.m | 4 +- matlab/slice_sampler.m | 246 +- matlab/solve_perfect_foresight_model.m | 170 +- matlab/steady.m | 2 +- matlab/step_length_correction.m | 10 +- matlab/stoch_simul.m | 2 +- matlab/stochastic_solvers.m | 52 +- matlab/store_smoother_results.m | 6 +- matlab/subset.m | 6 +- matlab/th_autocovariances.m | 2 +- matlab/thet2tau.m | 2 +- matlab/user_has_matlab_license.m | 16 +- matlab/utilities/dataset/initialize_dataset.m | 2 +- matlab/utilities/dataset/lagged.m | 64 +- matlab/utilities/dataset/makedataset.m | 2 +- matlab/utilities/dataset/quarterly2annual.m | 288 +- matlab/utilities/doc/get_internal_doc_block.m | 14 +- .../utilities/general/clean_current_folder.m | 2 +- matlab/utilities/general/compare_vectors.m | 4 +- matlab/utilities/general/demean.m | 4 +- matlab/utilities/general/dyn_mex.m | 42 +- .../general/isinestimationobjective.m | 6 +- matlab/utilities/general/ispd.m | 2 +- matlab/utilities/graphics/colorspace.m | 402 +- .../graphics/distinguishable_colors.m | 10 +- matlab/vnorm.m | 2 +- matlab/writeVarExpectationFunction.m | 4 +- matlab/write_latex_definitions.m | 6 +- matlab/write_latex_parameter_table.m | 28 +- matlab/write_latex_prior_table.m | 90 +- matlab/writecellofchar.m | 40 +- matlab/writematrixofchar.m | 2 +- mex/sources/bytecode/testing/bytecode_debug.m | 150 +- mex/sources/bytecode/testing/simulate_debug.m | 18 +- .../random_walk_metropolis_hastings_core.m | 8 +- .../rawdata_euromodel_1.m | 1026 ++-- .../random_walk_metropolis_hastings_core.m | 342 +- .../estimation/tests/rawdata_euromodel_1.m | 1026 ++-- .../k_order_perturbation/tests/first_order.m | 58 +- tests/AIM/data_ca1.m | 176 +- tests/AIM/fsdat.m | 388 +- tests/analytic_derivatives/fsdat_simul.m | 1632 +++--- tests/block_bytecode/run_ls2003.m | 26 +- tests/bvar_a_la_sims/bvar_sample.m | 2004 ++++---- tests/conditional_forecasts/2/fsdat_simul.m | 1632 +++--- tests/dates/fsdat_simul.m | 1632 +++--- ...ison_policy_functions_dynare_mathematica.m | 16 +- tests/ep/ar_steadystate.m | 4 +- tests/ep/exact_solution.m | 58 +- tests/ep/rbcii_steady_state.m | 148 +- tests/estimation/fsdat_simul.m | 1632 +++--- .../expectation_ss_old_steadystate.m | 20 +- tests/fataltest.m | 6 +- tests/fs2000/fsdat_simul.m | 1632 +++--- tests/fs2000/fsdat_simul_dseries.m | 1624 +++--- tests/fs2000/fsdat_simul_missing_obs.m | 816 +-- tests/fs2000_ssfile_aux.m | 4 +- tests/gsa/data_ca1.m | 176 +- .../as2007/as2007_steadystate.m | 12 +- tests/identification/kim/kim2_steadystate.m | 12 +- .../likelihood/compare_kalman_routines.m | 1 - .../likelihood/simul_state_space_model.m | 46 +- .../fsdat_simul_logged.m | 1632 +++--- tests/kalman_filter_smoother/fsdat_simul.m | 1632 +++--- tests/kalman_filter_smoother/testsmoother.m | 22 +- tests/load_octave_packages.m | 14 +- tests/ls2003/data_ca1.m | 176 +- tests/measurement_errors/data_ca1.m | 176 +- .../fs2000_corr_me_ml_mcmc/fsdat_simul.m | 816 +-- .../ftd_2s_caseall_upperchol3v.m | 262 +- .../ftd_2s_caseall_upperchol4v.m | 354 +- .../ftd_2s_caseall_upperchol6v.m | 570 +-- .../ftd_2s_caseall_upperchol7v.m | 694 +-- .../ms-sbvar/archive-files/ftd_RSvensson_4v.m | 94 +- tests/ms-sbvar/archive-files/ftd_cholesky.m | 286 +- tests/ms-sbvar/archive-files/ftd_non_rec_5v.m | 74 +- tests/ms-sbvar/archive-files/ftd_simszha5v.m | 94 +- .../ms-sbvar/archive-files/ftd_upperchol3v.m | 68 +- .../ms-sbvar/archive-files/ftd_upperchol4v.m | 70 +- .../ms-sbvar/archive-files/ftd_upperchol5v.m | 72 +- .../ms-sbvar/archive-files/ftd_upperchol6v.m | 74 +- .../ms-sbvar/archive-files/ftd_upperchol7v.m | 76 +- tests/ms-sbvar/data.m | 378 +- tests/parallel/data_ca1.m | 176 +- tests/particle/benchmark.m | 298 +- tests/particle/dsge_base2_steadystate.m | 2 +- tests/particle/extreme.m | 298 +- tests/particle/risky.m | 298 +- tests/practicing/datasaver.m | 46 +- tests/printMakeCheckMatlabErrMsg.m | 14 +- tests/printMakeCheckOctaveErrMsg.m | 24 +- tests/recursive/data_ca1.m | 176 +- tests/reporting/ResidTablePage.m | 2 +- tests/reporting/runDynareReport.m | 8 +- tests/run_all_unitary_tests.m | 14 +- tests/run_block_byte_tests_matlab.m | 16 +- tests/run_block_byte_tests_octave.m | 264 +- tests/run_m_script.m | 30 +- tests/run_o_script.m | 66 +- tests/run_reporting_test_matlab.m | 18 +- tests/run_reporting_test_octave.m | 94 +- tests/run_test_matlab.m | 32 +- tests/run_test_octave.m | 116 +- tests/shock_decomposition/fsdat_simul.m | 1632 +++--- tests/smoother2histval/fsdat_simul.m | 772 +-- .../steady_state/walsh1_old_ss_steadystate.m | 50 +- 404 files changed, 30462 insertions(+), 30468 deletions(-) diff --git a/doc/userguide/models/fs2000ns_steadystate.m b/doc/userguide/models/fs2000ns_steadystate.m index 3720ec68e6..f9991e4d45 100644 --- a/doc/userguide/models/fs2000ns_steadystate.m +++ b/doc/userguide/models/fs2000ns_steadystate.m @@ -1,53 +1,53 @@ % computes the steady state of fs2000 analyticaly % largely inspired by the program of F. Schorfheide function [ys,check] = fs2000ns_steadystate(ys,exe) - global M_ - - alp = M_.params(1); - bet = M_.params(2); - gam = M_.params(3); - mst = M_.params(4); - rho = M_.params(5); - psi = M_.params(6); - del = M_.params(7); +global M_ - check = 0; - - dA = exp(gam); - gst = 1/dA; - m = mst; - - khst = ( (1-gst*bet*(1-del)) / (alp*gst^alp*bet) )^(1/(alp-1)); - xist = ( ((khst*gst)^alp - (1-gst*(1-del))*khst)/mst )^(-1); - nust = psi*mst^2/( (1-alp)*(1-psi)*bet*gst^alp*khst^alp ); - n = xist/(nust+xist); - P = xist + nust; - k = khst*n; - l = psi*mst*n/( (1-psi)*(1-n) ); - c = mst/P; - d = l - mst + 1; - y = k^alp*n^(1-alp)*gst^alp; - R = mst/bet; - W = l/n; - ist = y-c; - q = 1 - d; - e = 1; - - P_obs = 1; - Y_obs = 1; - - ys =[ -m -P -c -e -W -R -k -d -n -l -Y_obs -P_obs -y -dA ]; \ No newline at end of file +alp = M_.params(1); +bet = M_.params(2); +gam = M_.params(3); +mst = M_.params(4); +rho = M_.params(5); +psi = M_.params(6); +del = M_.params(7); + +check = 0; + +dA = exp(gam); +gst = 1/dA; +m = mst; + +khst = ( (1-gst*bet*(1-del)) / (alp*gst^alp*bet) )^(1/(alp-1)); +xist = ( ((khst*gst)^alp - (1-gst*(1-del))*khst)/mst )^(-1); +nust = psi*mst^2/( (1-alp)*(1-psi)*bet*gst^alp*khst^alp ); +n = xist/(nust+xist); +P = xist + nust; +k = khst*n; +l = psi*mst*n/( (1-psi)*(1-n) ); +c = mst/P; +d = l - mst + 1; +y = k^alp*n^(1-alp)*gst^alp; +R = mst/bet; +W = l/n; +ist = y-c; +q = 1 - d; +e = 1; + +P_obs = 1; +Y_obs = 1; + +ys =[ + m + P + c + e + W + R + k + d + n + l + Y_obs + P_obs + y + dA ]; \ No newline at end of file diff --git a/doc/userguide/models/fsdat.m b/doc/userguide/models/fsdat.m index aba209b908..ef1279c0b3 100644 --- a/doc/userguide/models/fsdat.m +++ b/doc/userguide/models/fsdat.m @@ -1,198 +1,198 @@ data_q = [ -18.02 1474.5 150.2 -17.94 1538.2 150.9 -18.01 1584.5 151.4 -18.42 1644.1 152 -18.73 1678.6 152.7 -19.46 1693.1 153.3 -19.55 1724 153.9 -19.56 1758.2 154.7 -19.79 1760.6 155.4 -19.77 1779.2 156 -19.82 1778.8 156.6 -20.03 1790.9 157.3 -20.12 1846 158 -20.1 1882.6 158.6 -20.14 1897.3 159.2 -20.22 1887.4 160 -20.27 1858.2 160.7 -20.34 1849.9 161.4 -20.39 1848.5 162 -20.42 1868.9 162.8 -20.47 1905.6 163.6 -20.56 1959.6 164.3 -20.62 1994.4 164.9 -20.78 2020.1 165.7 -21 2030.5 166.5 -21.2 2023.6 167.2 -21.33 2037.7 167.9 -21.62 2033.4 168.7 -21.71 2066.2 169.5 -22.01 2077.5 170.2 -22.15 2071.9 170.9 -22.27 2094 171.7 -22.29 2070.8 172.5 -22.56 2012.6 173.1 -22.64 2024.7 173.8 -22.77 2072.3 174.5 -22.88 2120.6 175.3 -22.92 2165 176.045 -22.91 2223.3 176.727 -22.94 2221.4 177.481 -23.03 2230.95 178.268 -23.13 2279.22 179.694 -23.22 2265.48 180.335 -23.32 2268.29 181.094 -23.4 2238.57 181.915 -23.45 2251.68 182.634 -23.51 2292.02 183.337 -23.56 2332.61 184.103 -23.63 2381.01 184.894 -23.75 2422.59 185.553 -23.81 2448.01 186.203 -23.87 2471.86 186.926 -23.94 2476.67 187.68 -24 2508.7 188.299 -24.07 2538.05 188.906 -24.12 2586.26 189.631 -24.29 2604.62 190.362 -24.35 2666.69 190.954 -24.41 2697.54 191.56 -24.52 2729.63 192.256 -24.64 2739.75 192.938 -24.77 2808.88 193.467 -24.88 2846.34 193.994 -25.01 2898.79 194.647 -25.17 2970.48 195.279 -25.32 3042.35 195.763 -25.53 3055.53 196.277 -25.79 3076.51 196.877 -26.02 3102.36 197.481 -26.14 3127.15 197.967 -26.31 3129.53 198.455 -26.6 3154.19 199.012 -26.9 3177.98 199.572 -27.21 3236.18 199.995 -27.49 3292.07 200.452 -27.75 3316.11 200.997 -28.12 3331.22 201.538 -28.39 3381.86 201.955 -28.73 3390.23 202.419 -29.14 3409.65 202.986 -29.51 3392.6 203.584 -29.94 3386.49 204.086 -30.36 3391.61 204.721 -30.61 3422.95 205.419 -31.02 3389.36 206.13 -31.5 3481.4 206.763 -31.93 3500.95 207.362 -32.27 3523.8 208 -32.54 3533.79 208.642 -33.02 3604.73 209.142 -33.2 3687.9 209.637 -33.49 3726.18 210.181 -33.95 3790.44 210.737 -34.36 3892.22 211.192 -34.94 3919.01 211.663 -35.61 3907.08 212.191 -36.29 3947.11 212.708 -37.01 3908.15 213.144 -37.79 3922.57 213.602 -38.96 3879.98 214.147 -40.13 3854.13 214.7 -41.05 3800.93 215.135 -41.66 3835.21 215.652 -42.41 3907.02 216.289 -43.19 3952.48 216.848 -43.69 4044.59 217.314 -44.15 4072.19 217.776 -44.77 4088.49 218.338 -45.57 4126.39 218.917 -46.32 4176.28 219.427 -47.07 4260.08 219.956 -47.66 4329.46 220.573 -48.63 4328.33 221.201 -49.42 4345.51 221.719 -50.41 4510.73 222.281 -51.27 4552.14 222.933 -52.35 4603.65 223.583 -53.51 4605.65 224.152 -54.65 4615.64 224.737 -55.82 4644.93 225.418 -56.92 4656.23 226.117 -58.18 4678.96 226.754 -59.55 4566.62 227.389 -61.01 4562.25 228.07 -62.59 4651.86 228.689 -64.15 4739.16 229.155 -65.37 4696.82 229.674 -66.65 4753.02 230.301 -67.87 4693.76 230.903 -68.86 4615.89 231.395 -69.72 4634.88 231.906 -70.66 4612.08 232.498 -71.44 4618.26 233.074 -72.08 4662.97 233.546 -72.83 4763.57 234.028 -73.48 4849 234.603 -74.19 4939.23 235.153 -75.02 5053.56 235.605 -75.58 5132.87 236.082 -76.25 5170.34 236.657 -76.81 5203.68 237.232 -77.63 5257.26 237.673 -78.25 5283.73 238.176 -78.76 5359.6 238.789 -79.45 5393.57 239.387 -79.81 5460.83 239.861 -80.22 5466.95 240.368 -80.84 5496.29 240.962 -81.45 5526.77 241.539 -82.09 5561.8 242.009 -82.68 5618 242.52 -83.33 5667.39 243.12 -84.09 5750.57 243.721 -84.67 5785.29 244.208 -85.56 5844.05 244.716 -86.66 5878.7 245.354 -87.44 5952.83 245.966 -88.45 6010.96 246.46 -89.39 6055.61 247.017 -90.13 6087.96 247.698 -90.88 6093.51 248.374 -92 6152.59 248.928 -93.18 6171.57 249.564 -94.14 6142.1 250.299 -95.11 6078.96 251.031 -96.27 6047.49 251.65 -97 6074.66 252.295 -97.7 6090.14 253.033 -98.31 6105.25 253.743 -99.13 6175.69 254.338 -99.79 6214.22 255.032 -100.17 6260.74 255.815 -100.88 6327.12 256.543 -101.84 6327.93 257.151 -102.35 6359.9 257.785 -102.83 6393.5 258.516 -103.51 6476.86 259.191 -104.13 6524.5 259.738 -104.71 6600.31 260.351 -105.39 6629.47 261.04 -106.09 6688.61 261.692 -106.75 6717.46 262.236 -107.24 6724.2 262.847 -107.75 6779.53 263.527 -108.29 6825.8 264.169 -108.91 6882 264.681 -109.24 6983.91 265.258 -109.74 7020 265.887 -110.23 7093.12 266.491 -111 7166.68 266.987 -111.43 7236.5 267.545 -111.76 7311.24 268.171 -112.08 7364.63 268.815 -]; + 18.02 1474.5 150.2 + 17.94 1538.2 150.9 + 18.01 1584.5 151.4 + 18.42 1644.1 152 + 18.73 1678.6 152.7 + 19.46 1693.1 153.3 + 19.55 1724 153.9 + 19.56 1758.2 154.7 + 19.79 1760.6 155.4 + 19.77 1779.2 156 + 19.82 1778.8 156.6 + 20.03 1790.9 157.3 + 20.12 1846 158 + 20.1 1882.6 158.6 + 20.14 1897.3 159.2 + 20.22 1887.4 160 + 20.27 1858.2 160.7 + 20.34 1849.9 161.4 + 20.39 1848.5 162 + 20.42 1868.9 162.8 + 20.47 1905.6 163.6 + 20.56 1959.6 164.3 + 20.62 1994.4 164.9 + 20.78 2020.1 165.7 + 21 2030.5 166.5 + 21.2 2023.6 167.2 + 21.33 2037.7 167.9 + 21.62 2033.4 168.7 + 21.71 2066.2 169.5 + 22.01 2077.5 170.2 + 22.15 2071.9 170.9 + 22.27 2094 171.7 + 22.29 2070.8 172.5 + 22.56 2012.6 173.1 + 22.64 2024.7 173.8 + 22.77 2072.3 174.5 + 22.88 2120.6 175.3 + 22.92 2165 176.045 + 22.91 2223.3 176.727 + 22.94 2221.4 177.481 + 23.03 2230.95 178.268 + 23.13 2279.22 179.694 + 23.22 2265.48 180.335 + 23.32 2268.29 181.094 + 23.4 2238.57 181.915 + 23.45 2251.68 182.634 + 23.51 2292.02 183.337 + 23.56 2332.61 184.103 + 23.63 2381.01 184.894 + 23.75 2422.59 185.553 + 23.81 2448.01 186.203 + 23.87 2471.86 186.926 + 23.94 2476.67 187.68 + 24 2508.7 188.299 + 24.07 2538.05 188.906 + 24.12 2586.26 189.631 + 24.29 2604.62 190.362 + 24.35 2666.69 190.954 + 24.41 2697.54 191.56 + 24.52 2729.63 192.256 + 24.64 2739.75 192.938 + 24.77 2808.88 193.467 + 24.88 2846.34 193.994 + 25.01 2898.79 194.647 + 25.17 2970.48 195.279 + 25.32 3042.35 195.763 + 25.53 3055.53 196.277 + 25.79 3076.51 196.877 + 26.02 3102.36 197.481 + 26.14 3127.15 197.967 + 26.31 3129.53 198.455 + 26.6 3154.19 199.012 + 26.9 3177.98 199.572 + 27.21 3236.18 199.995 + 27.49 3292.07 200.452 + 27.75 3316.11 200.997 + 28.12 3331.22 201.538 + 28.39 3381.86 201.955 + 28.73 3390.23 202.419 + 29.14 3409.65 202.986 + 29.51 3392.6 203.584 + 29.94 3386.49 204.086 + 30.36 3391.61 204.721 + 30.61 3422.95 205.419 + 31.02 3389.36 206.13 + 31.5 3481.4 206.763 + 31.93 3500.95 207.362 + 32.27 3523.8 208 + 32.54 3533.79 208.642 + 33.02 3604.73 209.142 + 33.2 3687.9 209.637 + 33.49 3726.18 210.181 + 33.95 3790.44 210.737 + 34.36 3892.22 211.192 + 34.94 3919.01 211.663 + 35.61 3907.08 212.191 + 36.29 3947.11 212.708 + 37.01 3908.15 213.144 + 37.79 3922.57 213.602 + 38.96 3879.98 214.147 + 40.13 3854.13 214.7 + 41.05 3800.93 215.135 + 41.66 3835.21 215.652 + 42.41 3907.02 216.289 + 43.19 3952.48 216.848 + 43.69 4044.59 217.314 + 44.15 4072.19 217.776 + 44.77 4088.49 218.338 + 45.57 4126.39 218.917 + 46.32 4176.28 219.427 + 47.07 4260.08 219.956 + 47.66 4329.46 220.573 + 48.63 4328.33 221.201 + 49.42 4345.51 221.719 + 50.41 4510.73 222.281 + 51.27 4552.14 222.933 + 52.35 4603.65 223.583 + 53.51 4605.65 224.152 + 54.65 4615.64 224.737 + 55.82 4644.93 225.418 + 56.92 4656.23 226.117 + 58.18 4678.96 226.754 + 59.55 4566.62 227.389 + 61.01 4562.25 228.07 + 62.59 4651.86 228.689 + 64.15 4739.16 229.155 + 65.37 4696.82 229.674 + 66.65 4753.02 230.301 + 67.87 4693.76 230.903 + 68.86 4615.89 231.395 + 69.72 4634.88 231.906 + 70.66 4612.08 232.498 + 71.44 4618.26 233.074 + 72.08 4662.97 233.546 + 72.83 4763.57 234.028 + 73.48 4849 234.603 + 74.19 4939.23 235.153 + 75.02 5053.56 235.605 + 75.58 5132.87 236.082 + 76.25 5170.34 236.657 + 76.81 5203.68 237.232 + 77.63 5257.26 237.673 + 78.25 5283.73 238.176 + 78.76 5359.6 238.789 + 79.45 5393.57 239.387 + 79.81 5460.83 239.861 + 80.22 5466.95 240.368 + 80.84 5496.29 240.962 + 81.45 5526.77 241.539 + 82.09 5561.8 242.009 + 82.68 5618 242.52 + 83.33 5667.39 243.12 + 84.09 5750.57 243.721 + 84.67 5785.29 244.208 + 85.56 5844.05 244.716 + 86.66 5878.7 245.354 + 87.44 5952.83 245.966 + 88.45 6010.96 246.46 + 89.39 6055.61 247.017 + 90.13 6087.96 247.698 + 90.88 6093.51 248.374 + 92 6152.59 248.928 + 93.18 6171.57 249.564 + 94.14 6142.1 250.299 + 95.11 6078.96 251.031 + 96.27 6047.49 251.65 + 97 6074.66 252.295 + 97.7 6090.14 253.033 + 98.31 6105.25 253.743 + 99.13 6175.69 254.338 + 99.79 6214.22 255.032 + 100.17 6260.74 255.815 + 100.88 6327.12 256.543 + 101.84 6327.93 257.151 + 102.35 6359.9 257.785 + 102.83 6393.5 258.516 + 103.51 6476.86 259.191 + 104.13 6524.5 259.738 + 104.71 6600.31 260.351 + 105.39 6629.47 261.04 + 106.09 6688.61 261.692 + 106.75 6717.46 262.236 + 107.24 6724.2 262.847 + 107.75 6779.53 263.527 + 108.29 6825.8 264.169 + 108.91 6882 264.681 + 109.24 6983.91 265.258 + 109.74 7020 265.887 + 110.23 7093.12 266.491 + 111 7166.68 266.987 + 111.43 7236.5 267.545 + 111.76 7311.24 268.171 + 112.08 7364.63 268.815 + ]; %GDPD GDPQ GPOP series = zeros(193,2); diff --git a/dynare++/extern/matlab/dynare_simul.m b/dynare++/extern/matlab/dynare_simul.m index 32ac8dc57e..a77fc458bd 100644 --- a/dynare++/extern/matlab/dynare_simul.m +++ b/dynare++/extern/matlab/dynare_simul.m @@ -80,71 +80,71 @@ eval(['load ' fname]); % set prefix, shocks, ystart if ischar(varargin{2}) - prefix = varargin{2}; - if length(varargin) == 3 - shocks = varargin{3}; - ystart = NaN; - elseif length(varargin) == 4 - shocks = varargin{3}; - ystart = varargin{4}; - else - error('Wrong number of parameters.'); - end + prefix = varargin{2}; + if length(varargin) == 3 + shocks = varargin{3}; + ystart = NaN; + elseif length(varargin) == 4 + shocks = varargin{3}; + ystart = varargin{4}; + else + error('Wrong number of parameters.'); + end else - prefix = 'dyn'; - if length(varargin) == 2 - shocks = varargin{2}; - ystart = NaN; - elseif length(varargin) == 3 - shocks = varargin{2}; - ystart = varargin{3}; - else - error('Wrong number of parameters.'); - end + prefix = 'dyn'; + if length(varargin) == 2 + shocks = varargin{2}; + ystart = NaN; + elseif length(varargin) == 3 + shocks = varargin{2}; + ystart = varargin{3}; + else + error('Wrong number of parameters.'); + end end % load all needed variables but prefix_g_* if (exist([prefix '_nstat'])) - nstat = eval([prefix '_nstat']); + nstat = eval([prefix '_nstat']); else - error(['Could not find variable ' prefix '_nstat in workspace']); + error(['Could not find variable ' prefix '_nstat in workspace']); end if (exist([prefix '_npred'])) - npred = eval([prefix '_npred']); + npred = eval([prefix '_npred']); else - error(['Could not find variable ' prefix '_npred in workspace']); + error(['Could not find variable ' prefix '_npred in workspace']); end if (exist([prefix '_nboth'])) - nboth = eval([prefix '_nboth']); + nboth = eval([prefix '_nboth']); else - error(['Could not find variable ' prefix '_nboth in workspace']); + error(['Could not find variable ' prefix '_nboth in workspace']); end if (exist([prefix '_nforw'])) - nforw = eval([prefix '_nforw']); + nforw = eval([prefix '_nforw']); else - error(['Could not find variable ' prefix '_nforw in workspace']); + error(['Could not find variable ' prefix '_nforw in workspace']); end if (exist([prefix '_ss'])) - ss = eval([prefix '_ss']); + ss = eval([prefix '_ss']); else - error(['Could not find variable ' prefix '_ss in workspace']); + error(['Could not find variable ' prefix '_ss in workspace']); end if (exist([prefix '_vcov_exo'])) - vcov_exo = eval([prefix '_vcov_exo']); + vcov_exo = eval([prefix '_vcov_exo']); else - error(['Could not find variable ' prefix '_vcov_exo in workspace']); + error(['Could not find variable ' prefix '_vcov_exo in workspace']); end nexog = size(vcov_exo,1); if isnan(ystart) - ystart = ss; + ystart = ss; end % newer version of dynare++ doesn't return prefix_g_0, we make it here if % it does not exist in workspace g_zero = [prefix '_g_0']; if (~ exist(g_zero)) - eval([ g_zero '= zeros(nstat+npred+nboth+nforw,1);']); + eval([ g_zero '= zeros(nstat+npred+nboth+nforw,1);']); end % make derstr a string of comma seperated existing prefix_g_* @@ -152,13 +152,13 @@ derstr = [',' g_zero]; order = 1; cont = 1; while cont == 1 - g_ord = [prefix '_g_' num2str(order)]; - if (exist(g_ord)) - derstr = [derstr ',' g_ord]; - order = order + 1; - else - cont = 0; - end + g_ord = [prefix '_g_' num2str(order)]; + if (exist(g_ord)) + derstr = [derstr ',' g_ord]; + order = order + 1; + else + cont = 0; + end end % set seed diff --git a/dynare++/sylv/matlab/gensylv.m b/dynare++/sylv/matlab/gensylv.m index 56f5f0e73b..d16bde3640 100644 --- a/dynare++/sylv/matlab/gensylv.m +++ b/dynare++/sylv/matlab/gensylv.m @@ -58,19 +58,18 @@ function [err, X, varargout] = gensylv(order, A, B, C, D) % in Windows, ensure that aa_gensylv.dll is loaded, this prevents % clearing the function and a successive Matlab crash if strcmp('PCWIN', computer) - if ~ libisloaded('aa_gensylv') - loadlibrary('aa_gensylv', 'dummy'); - end + if ~ libisloaded('aa_gensylv') + loadlibrary('aa_gensylv', 'dummy'); + end end % launch aa_gensylv if nargout == 2 - X = aa_gensylv(order, A, B, C, D); + X = aa_gensylv(order, A, B, C, D); elseif nargout == 3 - [X, par] = aa_gensylv(order, A, B, C, D); - varargout(1) = {par}; + [X, par] = aa_gensylv(order, A, B, C, D); + varargout(1) = {par}; else - error('Must have 2 or 3 output arguments.'); + error('Must have 2 or 3 output arguments.'); end err = 0; - \ No newline at end of file diff --git a/examples/NK_baseline_steadystate.m b/examples/NK_baseline_steadystate.m index f7254b8fbb..48c8d60f7b 100644 --- a/examples/NK_baseline_steadystate.m +++ b/examples/NK_baseline_steadystate.m @@ -17,8 +17,8 @@ global M_ % read out parameters to access them with their name NumberOfParameters = M_.param_nbr; for ii = 1:NumberOfParameters - paramname = deblank(M_.param_names(ii,:)); - eval([ paramname ' = M_.params(' int2str(ii) ');']); + paramname = deblank(M_.param_names(ii,:)); + eval([ paramname ' = M_.params(' int2str(ii) ');']); end % initialize indicator check = 0; @@ -68,8 +68,8 @@ vw=(1-thetaw)/(1-thetaw*PI^((1-chiw)*eta)*mu_z^eta)*PIstarw^(-eta); tempvaromega=alppha/(1-alppha)*w/r*mu_z*mu_I; [ld,fval,exitflag]=fzero(@(ld)(1-betta*thetaw*mu_z^(eta-1)*PI^(-(1-chiw)*(1-eta)))/(1-betta*thetaw*mu_z^(eta*(1+gammma))*PI^(eta*(1-chiw)*(1+gammma)))... --(eta-1)/eta*wstar/(varpsi*PIstarw^(-eta*gammma)*ld^gammma)*((1-h*mu_z^(-1))^(-1)-betta*h*(mu_z-h)^(-1))*... -((mu_A*mu_z^(-1)*vp^(-1)*tempvaromega^alppha-tempvaromega*(1-(1-delta)*(mu_z*mu_I)^(-1)))*ld-vp^(-1)*Phi)^(-1),0.25,options); + -(eta-1)/eta*wstar/(varpsi*PIstarw^(-eta*gammma)*ld^gammma)*((1-h*mu_z^(-1))^(-1)-betta*h*(mu_z-h)^(-1))*... + ((mu_A*mu_z^(-1)*vp^(-1)*tempvaromega^alppha-tempvaromega*(1-(1-delta)*(mu_z*mu_I)^(-1)))*ld-vp^(-1)*Phi)^(-1),0.25,options); if exitflag <1 %indicate the SS computation was not sucessful; this would also be detected by Dynare %setting the indicator here shows how to use this functionality to @@ -95,11 +95,11 @@ g2=epsilon/(epsilon-1)*g1; %% end own model equations for iter = 1:length(M_.params) %update parameters set in the file - eval([ 'M_.params(' num2str(iter) ') = ' M_.param_names(iter,:) ';' ]) + eval([ 'M_.params(' num2str(iter) ') = ' M_.param_names(iter,:) ';' ]) end NumberOfEndogenousVariables = M_.orig_endo_nbr; %auxiliary variables are set automatically for ii = 1:NumberOfEndogenousVariables - varname = deblank(M_.endo_names(ii,:)); - eval(['ys(' int2str(ii) ') = ' varname ';']); + varname = deblank(M_.endo_names(ii,:)); + eval(['ys(' int2str(ii) ') = ' varname ';']); end diff --git a/examples/fsdat_simul.m b/examples/fsdat_simul.m index 56c0e4cd56..f6ad30c85b 100644 --- a/examples/fsdat_simul.m +++ b/examples/fsdat_simul.m @@ -1,416 +1,416 @@ % Generated data, used by fs2000.mod gy_obs =[ - 1.0030045 - 1.0002599 - 0.99104664 - 1.0321162 - 1.0223545 - 1.0043614 - 0.98626929 - 1.0092127 - 1.0357197 - 1.0150827 - 1.0051548 - 0.98465775 - 0.99132132 - 0.99904153 - 1.0044641 - 1.0179198 - 1.0113462 - 0.99409421 - 0.99904293 - 1.0448336 - 0.99932433 - 1.0057004 - 0.99619787 - 1.0267504 - 1.0077645 - 1.0058026 - 1.0025891 - 0.9939097 - 0.99604693 - 0.99908569 - 1.0151094 - 0.99348134 - 1.0039124 - 1.0145805 - 0.99800868 - 0.98578138 - 1.0065771 - 0.99843919 - 0.97979062 - 0.98413351 - 0.96468174 - 1.0273857 - 1.0225211 - 0.99958667 - 1.0111157 - 1.0099585 - 0.99480311 - 1.0079265 - 0.98924573 - 1.0070613 - 1.0075706 - 0.9937151 - 1.0224711 - 1.0018891 - 0.99051863 - 1.0042944 - 1.0184055 - 0.99419508 - 0.99756624 - 1.0015983 - 0.9845772 - 1.0004407 - 1.0116237 - 0.9861885 - 1.0073094 - 0.99273355 - 1.0013224 - 0.99777979 - 1.0301686 - 0.96809556 - 0.99917088 - 0.99949253 - 0.96590004 - 1.0083938 - 0.96662298 - 1.0221454 - 1.0069792 - 1.0343996 - 1.0066531 - 1.0072525 - 0.99743563 - 0.99723703 - 1.000372 - 0.99013917 - 1.0095223 - 0.98864268 - 0.98092242 - 0.98886488 - 1.0030341 - 1.01894 - 0.99155059 - 0.99533235 - 0.99734316 - 1.0047356 - 1.0082737 - 0.98425116 - 0.99949212 - 1.0055899 - 1.0065075 - 0.99385069 - 0.98867975 - 0.99804843 - 1.0184038 - 0.99301902 - 1.0177222 - 1.0051924 - 1.0187852 - 1.0098985 - 1.0097172 - 1.0145811 - 0.98721038 - 1.0361722 - 1.0105821 - 0.99469309 - 0.98626785 - 1.013871 - 0.99858924 - 0.99302637 - 1.0042186 - 0.99623745 - 0.98545708 - 1.0225435 - 1.0011861 - 1.0130321 - 0.97861347 - 1.0228193 - 0.99627435 - 1.0272779 - 1.0075172 - 1.0096762 - 1.0129306 - 0.99966549 - 1.0262882 - 1.0026914 - 1.0061475 - 1.009523 - 1.0036127 - 0.99762992 - 0.99092634 - 1.0058469 - 0.99887292 - 1.0060653 - 0.98673557 - 0.98895709 - 0.99111967 - 0.990118 - 0.99788054 - 0.97054709 - 1.0099157 - 1.0107431 - 0.99518695 - 1.0114048 - 0.99376019 - 1.0023369 - 0.98783327 - 1.0051727 - 1.0100462 - 0.98607387 - 1.0000064 - 0.99692442 - 1.012225 - 0.99574078 - 0.98642833 - 0.99008207 - 1.0197359 - 1.0112849 - 0.98711069 - 0.99402748 - 1.0242141 - 1.0135349 - 0.99842505 - 1.0130714 - 0.99887044 - 1.0059058 - 1.0185998 - 1.0073314 - 0.98687706 - 1.0084551 - 0.97698964 - 0.99482714 - 1.0015302 - 1.0105331 - 1.0261767 - 1.0232822 - 1.0084176 - 0.99785167 - 0.99619733 - 1.0055223 - 1.0076326 - 0.99205461 - 1.0030587 - 1.0137012 - 1.0145878 - 1.0190297 - 1.0000681 - 1.0153894 - 1.0140649 - 1.0007236 - 0.97961463 - 1.0125257 - 1.0169503 - 1.0197363 - 1.0221185 + 1.0030045 + 1.0002599 + 0.99104664 + 1.0321162 + 1.0223545 + 1.0043614 + 0.98626929 + 1.0092127 + 1.0357197 + 1.0150827 + 1.0051548 + 0.98465775 + 0.99132132 + 0.99904153 + 1.0044641 + 1.0179198 + 1.0113462 + 0.99409421 + 0.99904293 + 1.0448336 + 0.99932433 + 1.0057004 + 0.99619787 + 1.0267504 + 1.0077645 + 1.0058026 + 1.0025891 + 0.9939097 + 0.99604693 + 0.99908569 + 1.0151094 + 0.99348134 + 1.0039124 + 1.0145805 + 0.99800868 + 0.98578138 + 1.0065771 + 0.99843919 + 0.97979062 + 0.98413351 + 0.96468174 + 1.0273857 + 1.0225211 + 0.99958667 + 1.0111157 + 1.0099585 + 0.99480311 + 1.0079265 + 0.98924573 + 1.0070613 + 1.0075706 + 0.9937151 + 1.0224711 + 1.0018891 + 0.99051863 + 1.0042944 + 1.0184055 + 0.99419508 + 0.99756624 + 1.0015983 + 0.9845772 + 1.0004407 + 1.0116237 + 0.9861885 + 1.0073094 + 0.99273355 + 1.0013224 + 0.99777979 + 1.0301686 + 0.96809556 + 0.99917088 + 0.99949253 + 0.96590004 + 1.0083938 + 0.96662298 + 1.0221454 + 1.0069792 + 1.0343996 + 1.0066531 + 1.0072525 + 0.99743563 + 0.99723703 + 1.000372 + 0.99013917 + 1.0095223 + 0.98864268 + 0.98092242 + 0.98886488 + 1.0030341 + 1.01894 + 0.99155059 + 0.99533235 + 0.99734316 + 1.0047356 + 1.0082737 + 0.98425116 + 0.99949212 + 1.0055899 + 1.0065075 + 0.99385069 + 0.98867975 + 0.99804843 + 1.0184038 + 0.99301902 + 1.0177222 + 1.0051924 + 1.0187852 + 1.0098985 + 1.0097172 + 1.0145811 + 0.98721038 + 1.0361722 + 1.0105821 + 0.99469309 + 0.98626785 + 1.013871 + 0.99858924 + 0.99302637 + 1.0042186 + 0.99623745 + 0.98545708 + 1.0225435 + 1.0011861 + 1.0130321 + 0.97861347 + 1.0228193 + 0.99627435 + 1.0272779 + 1.0075172 + 1.0096762 + 1.0129306 + 0.99966549 + 1.0262882 + 1.0026914 + 1.0061475 + 1.009523 + 1.0036127 + 0.99762992 + 0.99092634 + 1.0058469 + 0.99887292 + 1.0060653 + 0.98673557 + 0.98895709 + 0.99111967 + 0.990118 + 0.99788054 + 0.97054709 + 1.0099157 + 1.0107431 + 0.99518695 + 1.0114048 + 0.99376019 + 1.0023369 + 0.98783327 + 1.0051727 + 1.0100462 + 0.98607387 + 1.0000064 + 0.99692442 + 1.012225 + 0.99574078 + 0.98642833 + 0.99008207 + 1.0197359 + 1.0112849 + 0.98711069 + 0.99402748 + 1.0242141 + 1.0135349 + 0.99842505 + 1.0130714 + 0.99887044 + 1.0059058 + 1.0185998 + 1.0073314 + 0.98687706 + 1.0084551 + 0.97698964 + 0.99482714 + 1.0015302 + 1.0105331 + 1.0261767 + 1.0232822 + 1.0084176 + 0.99785167 + 0.99619733 + 1.0055223 + 1.0076326 + 0.99205461 + 1.0030587 + 1.0137012 + 1.0145878 + 1.0190297 + 1.0000681 + 1.0153894 + 1.0140649 + 1.0007236 + 0.97961463 + 1.0125257 + 1.0169503 + 1.0197363 + 1.0221185 -]; + ]; gp_obs =[ - 1.0079715 - 1.0115853 - 1.0167502 - 1.0068957 - 1.0138189 - 1.0258364 - 1.0243817 - 1.017373 - 1.0020171 - 1.0003742 - 1.0008974 - 1.0104804 - 1.0116393 - 1.0114294 - 0.99932124 - 0.99461459 - 1.0170349 - 1.0051446 - 1.020639 - 1.0051964 - 1.0093042 - 1.007068 - 1.01086 - 0.99590086 - 1.0014883 - 1.0117332 - 0.9990095 - 1.0108284 - 1.0103672 - 1.0036722 - 1.0005124 - 1.0190331 - 1.0130978 - 1.007842 - 1.0285436 - 1.0322054 - 1.0213403 - 1.0246486 - 1.0419306 - 1.0258867 - 1.0156316 - 0.99818589 - 0.9894107 - 1.0127584 - 1.0146882 - 1.0136529 - 1.0340107 - 1.0343652 - 1.02971 - 1.0077932 - 1.0198114 - 1.013971 - 1.0061083 - 1.0089573 - 1.0037926 - 1.0082071 - 0.99498155 - 0.99735772 - 0.98765026 - 1.006465 - 1.0196088 - 1.0053233 - 1.0119974 - 1.0188066 - 1.0029302 - 1.0183459 - 1.0034218 - 1.0158799 - 0.98824798 - 1.0274357 - 1.0168832 - 1.0180641 - 1.0294657 - 0.98864091 - 1.0358326 - 0.99889969 - 1.0178322 - 0.99813566 - 1.0073549 - 1.0215985 - 1.0084245 - 1.0080939 - 1.0157021 - 1.0075815 - 1.0032633 - 1.0117871 - 1.0209276 - 1.0077569 - 0.99680958 - 1.0120266 - 1.0017625 - 1.0138811 - 1.0198358 - 1.0059629 - 1.0115416 - 1.0319473 - 1.0167074 - 1.0116111 - 1.0048627 - 1.0217622 - 1.0125221 - 1.0142045 - 0.99792469 - 0.99823971 - 0.99561547 - 0.99850373 - 0.9898464 - 1.0030963 - 1.0051373 - 1.0004213 - 1.0144117 - 0.97185592 - 0.9959518 - 1.0073529 - 1.0051603 - 0.98642572 - 0.99433423 - 1.0112131 - 1.0007695 - 1.0176867 - 1.0134363 - 0.99926191 - 0.99879835 - 0.99878754 - 1.0331374 - 1.0077797 - 1.0127221 - 1.0047393 - 1.0074106 - 0.99784213 - 1.0056495 - 1.0057708 - 0.98817494 - 0.98742176 - 0.99930555 - 1.0000687 - 1.0129754 - 1.009529 - 1.0226731 - 1.0149534 - 1.0164295 - 1.0239469 - 1.0293458 - 1.026199 - 1.0197525 - 1.0126818 - 1.0054473 - 1.0254423 - 1.0069461 - 1.0153135 - 1.0337515 - 1.0178187 - 1.0240469 - 1.0079489 - 1.0186953 - 1.0008628 - 1.0113799 - 1.0140118 - 1.0168007 - 1.011441 - 0.98422774 - 0.98909729 - 1.0157859 - 1.0151586 - 0.99756232 - 0.99497777 - 1.0102841 - 1.0221659 - 0.9937759 - 0.99877193 - 1.0079433 - 0.99667692 - 1.0095959 - 1.0128804 - 1.0156949 - 1.0111951 - 1.0228887 - 1.0122083 - 1.0190197 - 1.0074927 - 1.0268096 - 0.99689352 - 0.98948474 - 1.0024938 - 1.0105543 - 1.014116 - 1.0141217 - 1.0056504 - 1.0101026 - 1.0105069 - 0.99619053 - 1.0059439 - 0.99449473 - 0.99482458 - 1.0037702 - 1.0068087 - 0.99575975 - 1.0030815 - 1.0334014 - 0.99879386 - 0.99625634 - 1.0171195 - 0.99233844 + 1.0079715 + 1.0115853 + 1.0167502 + 1.0068957 + 1.0138189 + 1.0258364 + 1.0243817 + 1.017373 + 1.0020171 + 1.0003742 + 1.0008974 + 1.0104804 + 1.0116393 + 1.0114294 + 0.99932124 + 0.99461459 + 1.0170349 + 1.0051446 + 1.020639 + 1.0051964 + 1.0093042 + 1.007068 + 1.01086 + 0.99590086 + 1.0014883 + 1.0117332 + 0.9990095 + 1.0108284 + 1.0103672 + 1.0036722 + 1.0005124 + 1.0190331 + 1.0130978 + 1.007842 + 1.0285436 + 1.0322054 + 1.0213403 + 1.0246486 + 1.0419306 + 1.0258867 + 1.0156316 + 0.99818589 + 0.9894107 + 1.0127584 + 1.0146882 + 1.0136529 + 1.0340107 + 1.0343652 + 1.02971 + 1.0077932 + 1.0198114 + 1.013971 + 1.0061083 + 1.0089573 + 1.0037926 + 1.0082071 + 0.99498155 + 0.99735772 + 0.98765026 + 1.006465 + 1.0196088 + 1.0053233 + 1.0119974 + 1.0188066 + 1.0029302 + 1.0183459 + 1.0034218 + 1.0158799 + 0.98824798 + 1.0274357 + 1.0168832 + 1.0180641 + 1.0294657 + 0.98864091 + 1.0358326 + 0.99889969 + 1.0178322 + 0.99813566 + 1.0073549 + 1.0215985 + 1.0084245 + 1.0080939 + 1.0157021 + 1.0075815 + 1.0032633 + 1.0117871 + 1.0209276 + 1.0077569 + 0.99680958 + 1.0120266 + 1.0017625 + 1.0138811 + 1.0198358 + 1.0059629 + 1.0115416 + 1.0319473 + 1.0167074 + 1.0116111 + 1.0048627 + 1.0217622 + 1.0125221 + 1.0142045 + 0.99792469 + 0.99823971 + 0.99561547 + 0.99850373 + 0.9898464 + 1.0030963 + 1.0051373 + 1.0004213 + 1.0144117 + 0.97185592 + 0.9959518 + 1.0073529 + 1.0051603 + 0.98642572 + 0.99433423 + 1.0112131 + 1.0007695 + 1.0176867 + 1.0134363 + 0.99926191 + 0.99879835 + 0.99878754 + 1.0331374 + 1.0077797 + 1.0127221 + 1.0047393 + 1.0074106 + 0.99784213 + 1.0056495 + 1.0057708 + 0.98817494 + 0.98742176 + 0.99930555 + 1.0000687 + 1.0129754 + 1.009529 + 1.0226731 + 1.0149534 + 1.0164295 + 1.0239469 + 1.0293458 + 1.026199 + 1.0197525 + 1.0126818 + 1.0054473 + 1.0254423 + 1.0069461 + 1.0153135 + 1.0337515 + 1.0178187 + 1.0240469 + 1.0079489 + 1.0186953 + 1.0008628 + 1.0113799 + 1.0140118 + 1.0168007 + 1.011441 + 0.98422774 + 0.98909729 + 1.0157859 + 1.0151586 + 0.99756232 + 0.99497777 + 1.0102841 + 1.0221659 + 0.9937759 + 0.99877193 + 1.0079433 + 0.99667692 + 1.0095959 + 1.0128804 + 1.0156949 + 1.0111951 + 1.0228887 + 1.0122083 + 1.0190197 + 1.0074927 + 1.0268096 + 0.99689352 + 0.98948474 + 1.0024938 + 1.0105543 + 1.014116 + 1.0141217 + 1.0056504 + 1.0101026 + 1.0105069 + 0.99619053 + 1.0059439 + 0.99449473 + 0.99482458 + 1.0037702 + 1.0068087 + 0.99575975 + 1.0030815 + 1.0334014 + 0.99879386 + 0.99625634 + 1.0171195 + 0.99233844 -]; + ]; diff --git a/matlab/@dynTimeIndex/subsref.m b/matlab/@dynTimeIndex/subsref.m index 6c8aa79d42..bae6edc565 100644 --- a/matlab/@dynTimeIndex/subsref.m +++ b/matlab/@dynTimeIndex/subsref.m @@ -4,7 +4,7 @@ function B = subsref(A,S) % --*-- Unitary tests --*-- % % Overloads the subsref method for dynTimeIndex class. This method only allows to get % the value of the field `index`. - + % Copyright (C) 2013 Dynare Team % % This file is part of Dynare. diff --git a/matlab/AHessian.m b/matlab/AHessian.m index 561c380a00..be59603fdc 100644 --- a/matlab/AHessian.m +++ b/matlab/AHessian.m @@ -26,106 +26,106 @@ function [AHess, DLIK, LIK] = AHessian(T,R,Q,H,P,Y,DT,DYss,DOm,DH,DP,start,mf,ka % along with Dynare. If not, see <http://www.gnu.org/licenses/>. - k = size(DT,3); % number of structural parameters - smpl = size(Y,2); % Sample size. - pp = size(Y,1); % Maximum number of observed variables. - mm = size(T,2); % Number of state variables. - a = zeros(mm,1); % State vector. - Om = R*Q*transpose(R); % Variance of R times the vector of structural innovations. - t = 0; % Initialization of the time index. - oldK = 0; - notsteady = 1; % Steady state flag. - F_singular = 1; +k = size(DT,3); % number of structural parameters +smpl = size(Y,2); % Sample size. +pp = size(Y,1); % Maximum number of observed variables. +mm = size(T,2); % Number of state variables. +a = zeros(mm,1); % State vector. +Om = R*Q*transpose(R); % Variance of R times the vector of structural innovations. +t = 0; % Initialization of the time index. +oldK = 0; +notsteady = 1; % Steady state flag. +F_singular = 1; lik = zeros(smpl,1); % Initialization of the vector gathering the densities. LIK = Inf; % Default value of the log likelihood. if nargout > 1, DLIK = zeros(k,1); % Initialization of the score. end - AHess = zeros(k,k); % Initialization of the Hessian - Da = zeros(mm,k); % State vector. - Dv = zeros(length(mf),k); - +AHess = zeros(k,k); % Initialization of the Hessian +Da = zeros(mm,k); % State vector. +Dv = zeros(length(mf),k); + % for ii = 1:k % DOm = DR(:,:,ii)*Q*transpose(R) + R*DQ(:,:,ii)*transpose(R) + R*Q*transpose(DR(:,:,ii)); % end - - while notsteady && t<smpl - t = t+1; - v = Y(:,t)-a(mf); - F = P(mf,mf) + H; - if rcond(F) < kalman_tol - if ~all(abs(F(:))<kalman_tol) - return - else - a = T*a; - P = T*P*transpose(T)+Om; - end + +while notsteady && t<smpl + t = t+1; + v = Y(:,t)-a(mf); + F = P(mf,mf) + H; + if rcond(F) < kalman_tol + if ~all(abs(F(:))<kalman_tol) + return else - F_singular = 0; - iF = inv(F); - K = P(:,mf)*iF; - lik(t) = log(det(F))+transpose(v)*iF*v; - - [DK,DF,DP1] = computeDKalman(T,DT,DOm,P,DP,DH,mf,iF,K); - - for ii = 1:k - Dv(:,ii) = -Da(mf,ii) - DYss(mf,ii); - Da(:,ii) = DT(:,:,ii)*(a+K*v) + T*(Da(:,ii)+DK(:,:,ii)*v + K*Dv(:,ii)); - if t>=start && nargout > 1 - DLIK(ii,1) = DLIK(ii,1) + trace( iF*DF(:,:,ii) ) + 2*Dv(:,ii)'*iF*v - v'*(iF*DF(:,:,ii)*iF)*v; - end - end - vecDPmf = reshape(DP(mf,mf,:),[],k); -% iPmf = inv(P(mf,mf)); - if t>=start - AHess = AHess + Dv'*iF*Dv + .5*(vecDPmf' * kron(iF,iF) * vecDPmf); - end - a = T*(a+K*v); - P = T*(P-K*P(mf,:))*transpose(T)+Om; - DP = DP1; + a = T*a; + P = T*P*transpose(T)+Om; end - notsteady = max(max(abs(K-oldK))) > riccati_tol; - oldK = K; - end + else + F_singular = 0; + iF = inv(F); + K = P(:,mf)*iF; + lik(t) = log(det(F))+transpose(v)*iF*v; - if F_singular - error('The variance of the forecast error remains singular until the end of the sample') + [DK,DF,DP1] = computeDKalman(T,DT,DOm,P,DP,DH,mf,iF,K); + + for ii = 1:k + Dv(:,ii) = -Da(mf,ii) - DYss(mf,ii); + Da(:,ii) = DT(:,:,ii)*(a+K*v) + T*(Da(:,ii)+DK(:,:,ii)*v + K*Dv(:,ii)); + if t>=start && nargout > 1 + DLIK(ii,1) = DLIK(ii,1) + trace( iF*DF(:,:,ii) ) + 2*Dv(:,ii)'*iF*v - v'*(iF*DF(:,:,ii)*iF)*v; + end + end + vecDPmf = reshape(DP(mf,mf,:),[],k); + % iPmf = inv(P(mf,mf)); + if t>=start + AHess = AHess + Dv'*iF*Dv + .5*(vecDPmf' * kron(iF,iF) * vecDPmf); + end + a = T*(a+K*v); + P = T*(P-K*P(mf,:))*transpose(T)+Om; + DP = DP1; end + notsteady = max(max(abs(K-oldK))) > riccati_tol; + oldK = K; +end - - if t < smpl - t0 = t+1; - while t < smpl - t = t+1; - v = Y(:,t)-a(mf); - for ii = 1:k - Dv(:,ii) = -Da(mf,ii)-DYss(mf,ii); - Da(:,ii) = DT(:,:,ii)*(a+K*v) + T*(Da(:,ii)+DK(:,:,ii)*v + K*Dv(:,ii)); - if t>=start && nargout >1 - DLIK(ii,1) = DLIK(ii,1) + trace( iF*DF(:,:,ii) ) + 2*Dv(:,ii)'*iF*v - v'*(iF*DF(:,:,ii)*iF)*v; - end - end - if t>=start - AHess = AHess + Dv'*iF*Dv; - end - a = T*(a+K*v); - lik(t) = transpose(v)*iF*v; - end - AHess = AHess + .5*(smpl-t0+1)*(vecDPmf' * kron(iF,iF) * vecDPmf); - if nargout > 1 +if F_singular + error('The variance of the forecast error remains singular until the end of the sample') +end + + +if t < smpl + t0 = t+1; + while t < smpl + t = t+1; + v = Y(:,t)-a(mf); for ii = 1:k -% DLIK(ii,1) = DLIK(ii,1) + (smpl-t0+1)*trace( iF*DF(:,:,ii) ); + Dv(:,ii) = -Da(mf,ii)-DYss(mf,ii); + Da(:,ii) = DT(:,:,ii)*(a+K*v) + T*(Da(:,ii)+DK(:,:,ii)*v + K*Dv(:,ii)); + if t>=start && nargout >1 + DLIK(ii,1) = DLIK(ii,1) + trace( iF*DF(:,:,ii) ) + 2*Dv(:,ii)'*iF*v - v'*(iF*DF(:,:,ii)*iF)*v; + end end + if t>=start + AHess = AHess + Dv'*iF*Dv; + end + a = T*(a+K*v); + lik(t) = transpose(v)*iF*v; + end + AHess = AHess + .5*(smpl-t0+1)*(vecDPmf' * kron(iF,iF) * vecDPmf); + if nargout > 1 + for ii = 1:k + % DLIK(ii,1) = DLIK(ii,1) + (smpl-t0+1)*trace( iF*DF(:,:,ii) ); end - lik(t0:smpl) = lik(t0:smpl) + log(det(F)); -% for ii = 1:k; -% for jj = 1:ii -% H(ii,jj) = trace(iPmf*(.5*DP(mf,mf,ii)*iPmf*DP(mf,mf,jj) + Dv(:,ii)*Dv(:,jj)')); -% end -% end - end - + end + lik(t0:smpl) = lik(t0:smpl) + log(det(F)); + % for ii = 1:k; + % for jj = 1:ii + % H(ii,jj) = trace(iPmf*(.5*DP(mf,mf,ii)*iPmf*DP(mf,mf,jj) + Dv(:,ii)*Dv(:,jj)')); + % end + % end +end + AHess = -AHess; if nargout > 1, DLIK = DLIK/2; @@ -134,12 +134,12 @@ end lik = (lik + pp*log(2*pi))/2; LIK = sum(lik(start:end)); % Minus the log-likelihood. -% end of main function - + % end of main function + function [DK,DF,DP1] = computeDKalman(T,DT,DOm,P,DP,DH,mf,iF,K) - k = size(DT,3); - tmp = P-K*P(mf,:); +k = size(DT,3); +tmp = P-K*P(mf,:); for ii = 1:k DF(:,:,ii) = DP(mf,mf,ii) + DH(:,:,ii); @@ -152,4 +152,3 @@ end % end of computeDKalman - \ No newline at end of file diff --git a/matlab/AIM/SPAimerr.m b/matlab/AIM/SPAimerr.m index 2894a89a78..fb20705275 100644 --- a/matlab/AIM/SPAimerr.m +++ b/matlab/AIM/SPAimerr.m @@ -29,7 +29,7 @@ function e = SPAimerr(c); % Journal of Economic Dynamics and Control, 2010, vol. 34, issue 3, % pages 472-489 - if(c==1) e='Aim: unique solution.'; +if(c==1) e='Aim: unique solution.'; elseif(c==2) e='Aim: roots not correctly computed by real_schur.'; elseif(c==3) e='Aim: too many big roots.'; elseif(c==35) e='Aim: too many big roots, and q(:,right) is singular.'; diff --git a/matlab/AIM/SPAmalg.m b/matlab/AIM/SPAmalg.m index 41307b445e..19cc958fe5 100644 --- a/matlab/AIM/SPAmalg.m +++ b/matlab/AIM/SPAmalg.m @@ -1,5 +1,5 @@ function [b,rts,ia,nexact,nnumeric,lgroots,aimcode] = ... - SPAmalg(h,neq,nlag,nlead,condn,uprbnd) + SPAmalg(h,neq,nlag,nlead,condn,uprbnd) % [b,rts,ia,nexact,nnumeric,lgroots,aimcode] = ... % SPAmalg(h,neq,nlag,nlead,condn,uprbnd) % diff --git a/matlab/AIM/SPBuild_a.m b/matlab/AIM/SPBuild_a.m index eb12473a8a..b4d61ad92b 100644 --- a/matlab/AIM/SPBuild_a.m +++ b/matlab/AIM/SPBuild_a.m @@ -41,9 +41,9 @@ hs(:,left) = -hs(:,right)\hs(:,left); a = zeros(qcols,qcols); if(qcols > neq) - eyerows = 1:qcols-neq; - eyecols = neq+1:qcols; - a(eyerows,eyecols) = eye(qcols-neq); + eyerows = 1:qcols-neq; + eyecols = neq+1:qcols; + a(eyerows,eyecols) = eye(qcols-neq); end hrows = qcols-neq+1:qcols; a(hrows,:) = hs(:,left); @@ -56,9 +56,9 @@ a(hrows,:) = hs(:,left); js = 1:qcols; zerocols = sum(abs(a)) == 0; while( any(zerocols) ) - a(:,zerocols) = []; - a(zerocols,:) = []; - js(zerocols) = []; - zerocols = sum(abs(a)) == 0; + a(:,zerocols) = []; + a(zerocols,:) = []; + js(zerocols) = []; + zerocols = sum(abs(a)) == 0; end ia = length(js); diff --git a/matlab/AIM/SPCopy_w.m b/matlab/AIM/SPCopy_w.m index 714a1e2746..d7da8c647e 100644 --- a/matlab/AIM/SPCopy_w.m +++ b/matlab/AIM/SPCopy_w.m @@ -30,7 +30,7 @@ function q = SPCopy_w(q,w,js,iq,qrows) if(iq < qrows) - lastrows = iq+1:qrows; - wrows = 1:length(lastrows); - q(lastrows,js) = w(:,wrows)'; + lastrows = iq+1:qrows; + wrows = 1:length(lastrows); + q(lastrows,js) = w(:,wrows)'; end diff --git a/matlab/AIM/SPEigensystem.m b/matlab/AIM/SPEigensystem.m index 16855401a5..2ef1676ce1 100644 --- a/matlab/AIM/SPEigensystem.m +++ b/matlab/AIM/SPEigensystem.m @@ -39,22 +39,22 @@ opts.disp=0; % [mag,k] = sort(-mag); % rts = rts(k); %catch - %disp('Catch in SPE'); - %pause(0.5); - %aStr=datestr(clock); - %eval(['save ' regexprep(aStr,' ','') ' a']); - try - [w,d]=eig(a'); - catch - lasterr - w=[];rts=[];lgroots=[]; - flag_trouble=1; - return - end - rts = diag(d); - mag = abs(rts); - [mag,k] = sort(-mag); - rts = rts(k); +%disp('Catch in SPE'); +%pause(0.5); +%aStr=datestr(clock); +%eval(['save ' regexprep(aStr,' ','') ' a']); +try + [w,d]=eig(a'); +catch + lasterr + w=[];rts=[];lgroots=[]; + flag_trouble=1; + return +end +rts = diag(d); +mag = abs(rts); +[mag,k] = sort(-mag); +rts = rts(k); %end flag_trouble=0; diff --git a/matlab/AIM/SPExact_shift.m b/matlab/AIM/SPExact_shift.m index c9034e319b..876d9ca4f4 100644 --- a/matlab/AIM/SPExact_shift.m +++ b/matlab/AIM/SPExact_shift.m @@ -36,12 +36,12 @@ right = qcols+1:qcols+neq; zerorows = find( sum(abs( hs(:,right)' ))==0 ); while( any(zerorows) && iq <= qrows ) - nz = length(zerorows); - q(iq+1:iq+nz,:) = hs(zerorows,left); - hs(zerorows,:) = SPShiftright(hs(zerorows,:),neq); - iq = iq + nz; - nexact = nexact + nz; - zerorows = find( sum(abs( hs(:,right)' ))==0 ); + nz = length(zerorows); + q(iq+1:iq+nz,:) = hs(zerorows,left); + hs(zerorows,:) = SPShiftright(hs(zerorows,:),neq); + iq = iq + nz; + nexact = nexact + nz; + zerorows = find( sum(abs( hs(:,right)' ))==0 ); end h=full(hs); diff --git a/matlab/AIM/SPNumeric_shift.m b/matlab/AIM/SPNumeric_shift.m index cc1e1825f7..27049ca0cc 100644 --- a/matlab/AIM/SPNumeric_shift.m +++ b/matlab/AIM/SPNumeric_shift.m @@ -37,14 +37,14 @@ right = qcols+1:qcols+neq; zerorows = find( abs(diag(R)) <= condn ); while( any(zerorows) && iq <= qrows ) - h=sparse(h); - Q=sparse(Q); - h = Q'*h; - nz = length(zerorows); - q(iq+1:iq+nz,:) = h(zerorows,left); - h(zerorows,:) = SPShiftright( h(zerorows,:), neq ); - iq = iq + nz; - nnumeric = nnumeric + nz; - [Q,R,E] = qr( full(h(:,right)) ); - zerorows = find( abs(diag(R)) <= condn ); + h=sparse(h); + Q=sparse(Q); + h = Q'*h; + nz = length(zerorows); + q(iq+1:iq+nz,:) = h(zerorows,left); + h(zerorows,:) = SPShiftright( h(zerorows,:), neq ); + iq = iq + nz; + nnumeric = nnumeric + nz; + [Q,R,E] = qr( full(h(:,right)) ); + zerorows = find( abs(diag(R)) <= condn ); end diff --git a/matlab/AIM/SPObstruct.m b/matlab/AIM/SPObstruct.m index 8620ca1b9b..ea8252856c 100644 --- a/matlab/AIM/SPObstruct.m +++ b/matlab/AIM/SPObstruct.m @@ -52,16 +52,16 @@ qs(1:rc,1:cc) = sparse(cofb); qcols = neq*(nlag+nlead); if( nlead > 1 ) - for i = 1:nlead-1 - rows = i*neq + (1:neq); - qs(rows,:) = SPShiftright( qs((rows-neq),:), neq ); - end + for i = 1:nlead-1 + rows = i*neq + (1:neq); + qs(rows,:) = SPShiftright( qs((rows-neq),:), neq ); + end end l = (1: neq*nlag); r = (neq*nlag+1: neq*(nlag+nlead)); - qs(:,l) = - qs(:,r) \ qs(:,l); +qs(:,l) = - qs(:,r) \ qs(:,l); minus = 1: neq*(nlag+1); plus = neq*(nlag+1)+1: neq*(nlag+1+nlead); diff --git a/matlab/AIM/SPReduced_form.m b/matlab/AIM/SPReduced_form.m index 3d5c889907..8d529fc4e1 100644 --- a/matlab/AIM/SPReduced_form.m +++ b/matlab/AIM/SPReduced_form.m @@ -38,7 +38,7 @@ if(nonsing) b = qs(1:neq,1:bcols); b = full(b); else %rescale by dividing row by maximal qr element - %'inverse condition number small, rescaling ' + %'inverse condition number small, rescaling ' themax=max(abs(qs(:,right)),[],2); oneover = diag(1 ./ themax); nonsing = rcond(full(oneover *qs(:,right))) > condn; diff --git a/matlab/AIM_first_order_solver.m b/matlab/AIM_first_order_solver.m index fb3a99dc6a..51993d119d 100644 --- a/matlab/AIM_first_order_solver.m +++ b/matlab/AIM_first_order_solver.m @@ -67,35 +67,35 @@ function [dr,info]=AIM_first_order_solver(jacobia,M,dr,qz_criterium) % % You should have received a copy of the GNU General Public License % along with Dynare. If not, see <http://www.gnu.org/licenses/>. - - info = 0; - - [dr,aimcode]=dynAIMsolver1(jacobia,M,dr); - if aimcode ~=1 - info(1) = convertAimCodeToInfo(aimCode); %convert to be in the 100 range - info(2) = 1.0e+8; - return - end - A = kalman_transition_matrix(dr,M.nstatic+(1:M.nspred), 1:M.nspred,... - M.exo_nbr); - dr.eigval = eig(A); - disp(dr.eigval) - nd = size(dr.kstate,1); - nba = nd-sum( abs(dr.eigval) < qz_criterium ); +info = 0; + +[dr,aimcode]=dynAIMsolver1(jacobia,M,dr); + +if aimcode ~=1 + info(1) = convertAimCodeToInfo(aimCode); %convert to be in the 100 range + info(2) = 1.0e+8; + return +end +A = kalman_transition_matrix(dr,M.nstatic+(1:M.nspred), 1:M.nspred,... + M.exo_nbr); +dr.eigval = eig(A); +disp(dr.eigval) +nd = size(dr.kstate,1); +nba = nd-sum( abs(dr.eigval) < qz_criterium ); - nsfwrd = M.nsfwrd; +nsfwrd = M.nsfwrd; - if nba ~= nsfwrd - temp = sort(abs(dr.eigval)); - if nba > nsfwrd - temp = temp(nd-nba+1:nd-nsfwrd)-1-qz_criterium; - info(1) = 3; - elseif nba < nsfwrd; - temp = temp(nd-nsfwrd+1:nd-nba)-1-qz_criterium; - info(1) = 4; - end - info(2) = temp'*temp; - return +if nba ~= nsfwrd + temp = sort(abs(dr.eigval)); + if nba > nsfwrd + temp = temp(nd-nba+1:nd-nsfwrd)-1-qz_criterium; + info(1) = 3; + elseif nba < nsfwrd; + temp = temp(nd-nsfwrd+1:nd-nba)-1-qz_criterium; + info(1) = 4; end + info(2) = temp'*temp; + return +end diff --git a/matlab/DsgeSmoother.m b/matlab/DsgeSmoother.m index 08b7011e93..d3894bc088 100644 --- a/matlab/DsgeSmoother.m +++ b/matlab/DsgeSmoother.m @@ -169,7 +169,7 @@ elseif options_.lik_init == 3 % Diffuse Kalman filter kalman_algo = 3; else if ~all(all(abs(H-diag(diag(H)))<1e-14))% ie, the covariance matrix is diagonal... - %Augment state vector (follows Section 6.4.3 of DK (2012)) + %Augment state vector (follows Section 6.4.3 of DK (2012)) expanded_state_vector_for_univariate_filter=1; T = blkdiag(T,zeros(vobs)); np = size(T,1); @@ -240,32 +240,32 @@ if kalman_algo == 1 || kalman_algo == 3 end if kalman_algo == 2 || kalman_algo == 4 - if ~all(all(abs(H-diag(diag(H)))<1e-14))% ie, the covariance matrix is diagonal... - if ~expanded_state_vector_for_univariate_filter - %Augment state vector (follows Section 6.4.3 of DK (2012)) - expanded_state_vector_for_univariate_filter=1; - Z = [Z, eye(vobs)]; - ST = blkdiag(ST,zeros(vobs)); - np = size(ST,1); - Q = blkdiag(Q,H); - R1 = blkdiag(R,eye(vobs)); - if kalman_algo == 4 - %recompute Schur state space transformation with - %expanded state space - [Pstar,Pinf] = compute_Pinf_Pstar(mf,ST,R1,Q,options_.qz_criterium); - else - Pstar = blkdiag(Pstar,H); - if ~isempty(Pinf) - Pinf = blkdiag(Pinf,zeros(vobs)); - end - end - %now reset H to 0 - H = zeros(vobs,vobs); + if ~all(all(abs(H-diag(diag(H)))<1e-14))% ie, the covariance matrix is diagonal... + if ~expanded_state_vector_for_univariate_filter + %Augment state vector (follows Section 6.4.3 of DK (2012)) + expanded_state_vector_for_univariate_filter=1; + Z = [Z, eye(vobs)]; + ST = blkdiag(ST,zeros(vobs)); + np = size(ST,1); + Q = blkdiag(Q,H); + R1 = blkdiag(R,eye(vobs)); + if kalman_algo == 4 + %recompute Schur state space transformation with + %expanded state space + [Pstar,Pinf] = compute_Pinf_Pstar(mf,ST,R1,Q,options_.qz_criterium); else - %do nothing, state vector was already expanded + Pstar = blkdiag(Pstar,H); + if ~isempty(Pinf) + Pinf = blkdiag(Pinf,zeros(vobs)); + end end + %now reset H to 0 + H = zeros(vobs,vobs); + else + %do nothing, state vector was already expanded end - + end + [alphahat,epsilonhat,etahat,ahat,P,aK,PK,decomp,state_uncertainty] = missing_DiffuseKalmanSmootherH3_Z(ST, ... Z,R1,Q,diag(H), ... Pinf,Pstar,data1,vobs,np,smpl,data_index, ... diff --git a/matlab/GetPosteriorMeanVariance.m b/matlab/GetPosteriorMeanVariance.m index d1e2935873..285b944802 100644 --- a/matlab/GetPosteriorMeanVariance.m +++ b/matlab/GetPosteriorMeanVariance.m @@ -16,38 +16,38 @@ function [mean,variance] = GetPosteriorMeanVariance(M,drop) % % You should have received a copy of the GNU General Public License % along with Dynare. If not, see <http://www.gnu.org/licenses/>. - - MetropolisFolder = CheckPath('metropolis',M.dname); - FileName = M.fname; - BaseName = [MetropolisFolder filesep FileName]; - load_last_mh_history_file(MetropolisFolder, FileName); - NbrDraws = sum(record.MhDraws(:,1)); - NbrFiles = sum(record.MhDraws(:,2)); - NbrBlocks = record.Nblck; - mean = 0; - variance = 0; - - NbrKeptDraws = 0; - for i=1:NbrBlocks - NbrDrawsCurrentBlock = 0; - for j=1:NbrFiles - o = load([BaseName '_mh' int2str(j) '_blck' int2str(i),'.mat']); - NbrDrawsCurrentFile = size(o.x2,1); - if NbrDrawsCurrentBlock + NbrDrawsCurrentFile <= drop*NbrDraws - NbrDrawsCurrentBlock = NbrDrawsCurrentBlock + NbrDrawsCurrentFile; - continue - elseif NbrDrawsCurrentBlock < drop*NbrDraws - FirstDraw = ceil(drop*NbrDraws - NbrDrawsCurrentBlock + 1); - x2 = o.x2(FirstDraw:end,:); - else - x2 = o.x2; - end - NbrKeptDrawsCurrentFile = size(x2,1); - %recursively compute mean and variance - mean = (NbrKeptDraws*mean + sum(x2)')/(NbrKeptDraws+NbrKeptDrawsCurrentFile); - x2Demeaned = bsxfun(@minus,x2,mean'); - variance = (NbrKeptDraws*variance + x2Demeaned'*x2Demeaned)/(NbrKeptDraws+NbrKeptDrawsCurrentFile); + +MetropolisFolder = CheckPath('metropolis',M.dname); +FileName = M.fname; +BaseName = [MetropolisFolder filesep FileName]; +load_last_mh_history_file(MetropolisFolder, FileName); +NbrDraws = sum(record.MhDraws(:,1)); +NbrFiles = sum(record.MhDraws(:,2)); +NbrBlocks = record.Nblck; +mean = 0; +variance = 0; + +NbrKeptDraws = 0; +for i=1:NbrBlocks + NbrDrawsCurrentBlock = 0; + for j=1:NbrFiles + o = load([BaseName '_mh' int2str(j) '_blck' int2str(i),'.mat']); + NbrDrawsCurrentFile = size(o.x2,1); + if NbrDrawsCurrentBlock + NbrDrawsCurrentFile <= drop*NbrDraws NbrDrawsCurrentBlock = NbrDrawsCurrentBlock + NbrDrawsCurrentFile; - NbrKeptDraws = NbrKeptDraws + NbrKeptDrawsCurrentFile; + continue + elseif NbrDrawsCurrentBlock < drop*NbrDraws + FirstDraw = ceil(drop*NbrDraws - NbrDrawsCurrentBlock + 1); + x2 = o.x2(FirstDraw:end,:); + else + x2 = o.x2; end + NbrKeptDrawsCurrentFile = size(x2,1); + %recursively compute mean and variance + mean = (NbrKeptDraws*mean + sum(x2)')/(NbrKeptDraws+NbrKeptDrawsCurrentFile); + x2Demeaned = bsxfun(@minus,x2,mean'); + variance = (NbrKeptDraws*variance + x2Demeaned'*x2Demeaned)/(NbrKeptDraws+NbrKeptDrawsCurrentFile); + NbrDrawsCurrentBlock = NbrDrawsCurrentBlock + NbrDrawsCurrentFile; + NbrKeptDraws = NbrKeptDraws + NbrKeptDrawsCurrentFile; end +end diff --git a/matlab/PosteriorIRF.m b/matlab/PosteriorIRF.m index c0d393d4e9..1d51f5967b 100644 --- a/matlab/PosteriorIRF.m +++ b/matlab/PosteriorIRF.m @@ -368,101 +368,101 @@ end % PosteriorIRF_core2.m function. if ~options_.nograph && ~options_.no_graph.posterior -% Save the local variables. -localVars=[]; + % Save the local variables. + localVars=[]; -Check=options_.TeX; -if (Check) - localVars.varlist_TeX=varlist_TeX; -end + Check=options_.TeX; + if (Check) + localVars.varlist_TeX=varlist_TeX; + end -localVars.nvar=nvar; -localVars.MeanIRF=MeanIRF; -localVars.tit=tit; -localVars.nn=nn; -localVars.MAX_nirfs_dsgevar=MAX_nirfs_dsgevar; -localVars.HPDIRF=HPDIRF; -localVars.varlist=varlist; -localVars.MaxNumberOfPlotPerFigure=MaxNumberOfPlotPerFigure; -if options_.dsge_var - localVars.HPDIRFdsgevar=HPDIRFdsgevar; - localVars.MeanIRFdsgevar = MeanIRFdsgevar; -end + localVars.nvar=nvar; + localVars.MeanIRF=MeanIRF; + localVars.tit=tit; + localVars.nn=nn; + localVars.MAX_nirfs_dsgevar=MAX_nirfs_dsgevar; + localVars.HPDIRF=HPDIRF; + localVars.varlist=varlist; + localVars.MaxNumberOfPlotPerFigure=MaxNumberOfPlotPerFigure; + if options_.dsge_var + localVars.HPDIRFdsgevar=HPDIRFdsgevar; + localVars.MeanIRFdsgevar = MeanIRFdsgevar; + end -% The files .TeX are genereted in sequential way always! - -% The files .TeX are generated in sequential way always! -subplotnum = 0; -tit_TeX(M_.exo_names_orig_ord,:) = M_.exo_names_tex; -if options_.TeX && any(strcmp('eps',cellstr(options_.graph_format))) - fidTeX = fopen([DirectoryName filesep M_.fname '_BayesianIRF.tex'],'w'); - fprintf(fidTeX,'%% TeX eps-loader file generated by PosteriorIRF.m (Dynare).\n'); - fprintf(fidTeX,['%% ' datestr(now,0) '\n']); - fprintf(fidTeX,' \n'); - titTeX(M_.exo_names_orig_ord,:) = M_.exo_names_tex; - - for ii=irf_shocks_indx - figunumber = 0; - - for jj=1:nvar - if max(abs(MeanIRF(:,jj,ii))) >= options_.impulse_responses.plot_threshold - subplotnum = subplotnum+1; - - if subplotnum == 1 - fprintf(fidTeX,'\\begin{figure}[H]\n'); + % The files .TeX are genereted in sequential way always! + + % The files .TeX are generated in sequential way always! + subplotnum = 0; + tit_TeX(M_.exo_names_orig_ord,:) = M_.exo_names_tex; + if options_.TeX && any(strcmp('eps',cellstr(options_.graph_format))) + fidTeX = fopen([DirectoryName filesep M_.fname '_BayesianIRF.tex'],'w'); + fprintf(fidTeX,'%% TeX eps-loader file generated by PosteriorIRF.m (Dynare).\n'); + fprintf(fidTeX,['%% ' datestr(now,0) '\n']); + fprintf(fidTeX,' \n'); + titTeX(M_.exo_names_orig_ord,:) = M_.exo_names_tex; + + for ii=irf_shocks_indx + figunumber = 0; + + for jj=1:nvar + if max(abs(MeanIRF(:,jj,ii))) >= options_.impulse_responses.plot_threshold + subplotnum = subplotnum+1; + + if subplotnum == 1 + fprintf(fidTeX,'\\begin{figure}[H]\n'); + end + name = deblank(varlist(jj,:)); + texname = deblank(varlist_TeX(jj,:)); + fprintf(fidTeX,['\\psfrag{%s}[1][][0.5][0]{%s}\n'],name,['$' texname '$']); end - name = deblank(varlist(jj,:)); - texname = deblank(varlist_TeX(jj,:)); - fprintf(fidTeX,['\\psfrag{%s}[1][][0.5][0]{%s}\n'],name,['$' texname '$']); + if subplotnum == MaxNumberOfPlotPerFigure || (jj == nvar && subplotnum> 0) + figunumber = figunumber+1; + + fprintf(fidTeX,'\\centering \n'); + fprintf(fidTeX,'\\includegraphics[width=%2.2f\\textwidth]{%s/%s_Bayesian_IRF_%s_%d}\n',options_.figures.textwidth*min(subplotnum/nn,1),DirectoryName,M_.fname,deblank(tit(ii,:)),figunumber); + if options_.relative_irf + fprintf(fidTeX,['\\caption{Bayesian relative IRF.}']); + else + fprintf(fidTeX,'\\caption{Bayesian IRF: Orthogonalized shock to $%s$.}\n',deblank(tit_TeX(ii,:))); + end + fprintf(fidTeX,'\\label{Fig:BayesianIRF:%s:%d}\n',deblank(tit(ii,:)),figunumber); + fprintf(fidTeX,'\\end{figure}\n'); + fprintf(fidTeX,' \n'); + + subplotnum = 0; + end end - if subplotnum == MaxNumberOfPlotPerFigure || (jj == nvar && subplotnum> 0) - figunumber = figunumber+1; - - fprintf(fidTeX,'\\centering \n'); - fprintf(fidTeX,'\\includegraphics[width=%2.2f\\textwidth]{%s/%s_Bayesian_IRF_%s_%d}\n',options_.figures.textwidth*min(subplotnum/nn,1),DirectoryName,M_.fname,deblank(tit(ii,:)),figunumber); - if options_.relative_irf - fprintf(fidTeX,['\\caption{Bayesian relative IRF.}']); - else - fprintf(fidTeX,'\\caption{Bayesian IRF: Orthogonalized shock to $%s$.}\n',deblank(tit_TeX(ii,:))); - end - fprintf(fidTeX,'\\label{Fig:BayesianIRF:%s:%d}\n',deblank(tit(ii,:)),figunumber); - fprintf(fidTeX,'\\end{figure}\n'); - fprintf(fidTeX,' \n'); - - subplotnum = 0; - end end + fprintf(fidTeX,'%% End of TeX file.\n'); + fclose(fidTeX); end - fprintf(fidTeX,'%% End of TeX file.\n'); - fclose(fidTeX); -end -% The others file format are generated in parallel by PosteriorIRF_core2! + % The others file format are generated in parallel by PosteriorIRF_core2! -% Comment for testing! -if ~isoctave - if isnumeric(options_.parallel) || (M_.exo_nbr*ceil(size(varlist,1)/MaxNumberOfPlotPerFigure))<8, - [fout] = PosteriorIRF_core2(localVars,1,M_.exo_nbr,0); - else - isRemoteOctave = 0; - for indPC=1:length(options_.parallel), - isRemoteOctave = isRemoteOctave + (findstr(options_.parallel(indPC).MatlabOctavePath, 'octave')); - end - if isRemoteOctave + % Comment for testing! + if ~isoctave + if isnumeric(options_.parallel) || (M_.exo_nbr*ceil(size(varlist,1)/MaxNumberOfPlotPerFigure))<8, [fout] = PosteriorIRF_core2(localVars,1,M_.exo_nbr,0); else - globalVars = struct('M_',M_, ... - 'options_', options_); + isRemoteOctave = 0; + for indPC=1:length(options_.parallel), + isRemoteOctave = isRemoteOctave + (findstr(options_.parallel(indPC).MatlabOctavePath, 'octave')); + end + if isRemoteOctave + [fout] = PosteriorIRF_core2(localVars,1,M_.exo_nbr,0); + else + globalVars = struct('M_',M_, ... + 'options_', options_); - [fout] = masterParallel(options_.parallel, 1, M_.exo_nbr,NamFileInput,'PosteriorIRF_core2', localVars, globalVars, options_.parallel_info); + [fout] = masterParallel(options_.parallel, 1, M_.exo_nbr,NamFileInput,'PosteriorIRF_core2', localVars, globalVars, options_.parallel_info); + end end + else + [fout] = PosteriorIRF_core2(localVars,1,M_.exo_nbr,0); end -else - [fout] = PosteriorIRF_core2(localVars,1,M_.exo_nbr,0); -end -% END parallel code! + % END parallel code! end diff --git a/matlab/PosteriorIRF_core2.m b/matlab/PosteriorIRF_core2.m index abf1c3cbdb..9c08726d5b 100644 --- a/matlab/PosteriorIRF_core2.m +++ b/matlab/PosteriorIRF_core2.m @@ -135,7 +135,7 @@ for i=fpar:npar, plot(1:options_.irf,HPDIRFdsgevar(:,1,j,i),'--k','linewidth',1) plot(1:options_.irf,HPDIRFdsgevar(:,2,j,i),'--k','linewidth',1) end - % plot([1 options_.irf],[0 0],'-r','linewidth',0.5); + % plot([1 options_.irf],[0 0],'-r','linewidth',0.5); box on axis tight xlim([1 options_.irf]); @@ -162,7 +162,7 @@ for i=fpar:npar, if whoiam, fprintf('Done! \n'); waitbarString = [ 'Exog. shocks ' int2str(i) '/' int2str(npar) ' done.']; -% fMessageStatus((i-fpar+1)/(npar-fpar+1),whoiam,waitbarString, waitbarTitle, Parallel(ThisMatlab)); + % fMessageStatus((i-fpar+1)/(npar-fpar+1),whoiam,waitbarString, waitbarTitle, Parallel(ThisMatlab)); dyn_waitbar((i-fpar+1)/(npar-fpar+1),[],waitbarString); end end% loop over exo_var diff --git a/matlab/UnivariateSpectralDensity.m b/matlab/UnivariateSpectralDensity.m index ab00d18568..0039cae30f 100644 --- a/matlab/UnivariateSpectralDensity.m +++ b/matlab/UnivariateSpectralDensity.m @@ -112,7 +112,7 @@ tneg = exp(-sqrt(-1)*freqs); %negative frequencies if options_.one_sided_hp_filter error('UnivariateSpectralDensity:: spectral density estimate not available with one-sided HP filter') elseif options_.hp_filter == 0 && ~options_.bandpass.indicator %do not filter - filter_gain=ones(ngrid,1); + filter_gain=ones(ngrid,1); elseif ~(options_.hp_filter == 0 && ~options_.bandpass.indicator) && options_.bandpass.indicator %filter with bandpass filter_gain = zeros(1,ngrid); lowest_periodicity=options_.bandpass.passband(2); diff --git a/matlab/WriteShockDecomp2Excel.m b/matlab/WriteShockDecomp2Excel.m index dff5c79bbb..e71b2772de 100644 --- a/matlab/WriteShockDecomp2Excel.m +++ b/matlab/WriteShockDecomp2Excel.m @@ -60,7 +60,7 @@ if nargin==8 , end if isfield(opts_decomp,'fig_name') fig_name = opts_decomp.fig_name; -% fig_name = ['_' fig_name]; + % fig_name = ['_' fig_name]; fig_name1 = [fig_name]; fig_name = [fig_name '_']; end diff --git a/matlab/add_filter_subtitle.m b/matlab/add_filter_subtitle.m index 6525875179..a11dbe5525 100644 --- a/matlab/add_filter_subtitle.m +++ b/matlab/add_filter_subtitle.m @@ -1,7 +1,7 @@ function title=add_filter_subtitle(title,options_) if ~options_.hp_filter && ~options_.one_sided_hp_filter && ~options_.bandpass.indicator %do not filter - %nothing to add here + %nothing to add here elseif ~options_.hp_filter && ~options_.one_sided_hp_filter && options_.bandpass.indicator title = [title ' (Bandpass filter, (' ... num2str(options_.bandpass.passband(1)),' ',num2str(options_.bandpass.passband(2)), '))']; diff --git a/matlab/add_path_to_mex_files.m b/matlab/add_path_to_mex_files.m index e35d29a6b9..13140bba5b 100644 --- a/matlab/add_path_to_mex_files.m +++ b/matlab/add_path_to_mex_files.m @@ -1,5 +1,5 @@ function mexpath = add_path_to_mex_files(dynareroot, modifypath) - + % Copyright (C) 2015-2017 Dynare Team % % This file is part of Dynare. @@ -20,7 +20,7 @@ function mexpath = add_path_to_mex_files(dynareroot, modifypath) if nargin<2 modifypath = true; end - + if exist('OCTAVE_VERSION') if ispc() && strcmpi(computer(), 'i686-w64-mingw32') mexpath = {[dynareroot '../mex/octave32/']}; diff --git a/matlab/annualized_shock_decomposition.m b/matlab/annualized_shock_decomposition.m index 9590699b3b..fe0b9cc4ec 100644 --- a/matlab/annualized_shock_decomposition.m +++ b/matlab/annualized_shock_decomposition.m @@ -59,11 +59,11 @@ aux0 = aux; cumfix = q2a.cumfix; % usual shock decomp if isstruct(oo_) -% z = oo_.shock_decomposition; - myopts=options_; - myopts.plot_shock_decomp.type='qoq'; - myopts.plot_shock_decomp.realtime=0; - [z, junk] = plot_shock_decomposition(M_,oo_,myopts,[]); + % z = oo_.shock_decomposition; + myopts=options_; + myopts.plot_shock_decomp.type='qoq'; + myopts.plot_shock_decomp.realtime=0; + [z, junk] = plot_shock_decomposition(M_,oo_,myopts,[]); else z = oo_; end @@ -177,147 +177,147 @@ end % realtime if realtime_ && isstruct(oo_) && isfield(oo_, 'realtime_shock_decomposition'), -init=1; -for i=t0:4:t1, - yr=floor(i/4); - za=[]; - gza=[]; + init=1; + for i=t0:4:t1, + yr=floor(i/4); + za=[]; + gza=[]; myopts=options_; myopts.plot_shock_decomp.type='qoq'; myopts.plot_shock_decomp.realtime=1; myopts.plot_shock_decomp.vintage=i; [z, steady_state_aux] = plot_shock_decomposition(M_,oo_,myopts,[]); z = z(i_var,:,:); -if isstruct(aux) - if ischar(aux0.y) - [y_aux, steady_state_aux] = plot_shock_decomposition(M_,oo_,myopts,aux0.y); - aux.y=y_aux; - aux.yss=steady_state_aux; - end - yaux=aux.y; -end + if isstruct(aux) + if ischar(aux0.y) + [y_aux, steady_state_aux] = plot_shock_decomposition(M_,oo_,myopts,aux0.y); + aux.y=y_aux; + aux.yss=steady_state_aux; + end + yaux=aux.y; + end nterms = size(z,2); - -% z = oo_.realtime_shock_decomposition.(['time_' int2str(i)]); -% z = z(i_var,:,:); - - for j=1:nvar - for k =nterms:-1:1, -% if k<nterms -% ztmp = squeeze(sum(z(j,[1:k-1,k+1:end-1],t0-4:end))); -% else + + % z = oo_.realtime_shock_decomposition.(['time_' int2str(i)]); + % z = z(i_var,:,:); + + for j=1:nvar + for k =nterms:-1:1, + % if k<nterms + % ztmp = squeeze(sum(z(j,[1:k-1,k+1:end-1],t0-4:end))); + % else ztmp = squeeze(z(j,k,min((t0-3):-4:1):end)); -% end - if isstruct(aux), - aux.y = squeeze(yaux(j,k,min((t0-3):-4:1):end)); + % end + if isstruct(aux), + aux.y = squeeze(yaux(j,k,min((t0-3):-4:1):end)); + end + [za(j,k,:), steady_state_a(j,1), gza(j,k,:), steady_state_ga(j,1)] = ... + quarterly2annual(ztmp,steady_state(j),GYTREND0,var_type,islog,aux); + % if k<nterms + % za(j,k,:) = za(j,end,:) - za(j,k,:); + % gza(j,k,:) = gza(j,end,:) - gza(j,k,:); + % end + end - [za(j,k,:), steady_state_a(j,1), gza(j,k,:), steady_state_ga(j,1)] = ... - quarterly2annual(ztmp,steady_state(j),GYTREND0,var_type,islog,aux); -% if k<nterms -% za(j,k,:) = za(j,end,:) - za(j,k,:); -% gza(j,k,:) = gza(j,end,:) - gza(j,k,:); -% end - end - - ztmp=squeeze(za(j,:,:)); + ztmp=squeeze(za(j,:,:)); - if cumfix==0, - zscale = sum(ztmp(1:end-1,:))./ztmp(end,:); - ztmp(1:end-1,:) = ztmp(1:end-1,:)./repmat(zscale,[nterms-1,1]); - else - zres = ztmp(end,:)-sum(ztmp(1:end-1,:)); - ztmp(end-1,:) = ztmp(end-1,:) + zres; + if cumfix==0, + zscale = sum(ztmp(1:end-1,:))./ztmp(end,:); + ztmp(1:end-1,:) = ztmp(1:end-1,:)./repmat(zscale,[nterms-1,1]); + else + zres = ztmp(end,:)-sum(ztmp(1:end-1,:)); + ztmp(end-1,:) = ztmp(end-1,:) + zres; + end + + gztmp=squeeze(gza(j,:,:)); + if cumfix==0, + gscale = sum(gztmp(1:end-1,:))./ gztmp(end,:); + gztmp(1:end-1,:) = gztmp(1:end-1,:)./repmat(gscale,[nterms-1,1]); + else + gres = gztmp(end,:) - sum(gztmp(1:end-1,:)); + gztmp(end-1,:) = gztmp(end-1,:)+gres; + end + + za(j,:,:) = ztmp; + gza(j,:,:) = gztmp; end - gztmp=squeeze(gza(j,:,:)); - if cumfix==0, - gscale = sum(gztmp(1:end-1,:))./ gztmp(end,:); - gztmp(1:end-1,:) = gztmp(1:end-1,:)./repmat(gscale,[nterms-1,1]); + if q2a.plot ==1, + z=gza; + elseif q2a.plot == 2 + z=za; else - gres = gztmp(end,:) - sum(gztmp(1:end-1,:)); - gztmp(end-1,:) = gztmp(end-1,:)+gres; + z=cat(1,za,gza); end - za(j,:,:) = ztmp; - gza(j,:,:) = gztmp; - end - - if q2a.plot ==1, - z=gza; - elseif q2a.plot == 2 - z=za; - else - z=cat(1,za,gza); - end - - if init==1, - oo_.annualized_realtime_shock_decomposition.pool = z; - else - oo_.annualized_realtime_shock_decomposition.pool(:,:,yr) = z(:,:,end-nfrcst); - end - oo_.annualized_realtime_shock_decomposition.(['yr_' int2str(yr)]) = z; + if init==1, + oo_.annualized_realtime_shock_decomposition.pool = z; + else + oo_.annualized_realtime_shock_decomposition.pool(:,:,yr) = z(:,:,end-nfrcst); + end + oo_.annualized_realtime_shock_decomposition.(['yr_' int2str(yr)]) = z; - if opts.forecast - oo_.annualized_realtime_forecast_shock_decomposition.(['yr_' int2str(yr)]) = z(:,:,end-nfrcst:end); - if init>nfrcst - oo_.annualized_realtime_conditional_shock_decomposition.(['yr_' int2str(yr-nfrcst)]) = ... - oo_.annualized_realtime_shock_decomposition.pool(:,:,yr-nfrcst:end) - ... - oo_.annualized_realtime_forecast_shock_decomposition.(['yr_' int2str(yr-nfrcst)]); - % fix others - oo_.annualized_realtime_conditional_shock_decomposition.(['yr_' int2str(yr-nfrcst)])(:,end-1,:) = ... - oo_.annualized_realtime_conditional_shock_decomposition.(['yr_' int2str(yr-nfrcst)])(:,end-1,:) + ... - oo_.annualized_realtime_forecast_shock_decomposition.(['yr_' int2str(yr-nfrcst)])(:,end,:); - % fix total - oo_.annualized_realtime_conditional_shock_decomposition.(['yr_' int2str(yr-nfrcst)])(:,end,:) = ... - oo_.annualized_realtime_shock_decomposition.pool(:,end,yr-nfrcst:end); - if i==t1 - for my_forecast_=(nfrcst-1):-1:1, - oo_.annualized_realtime_conditional_shock_decomposition.(['yr_' int2str(yr-my_forecast_)]) = ... - oo_.annualized_realtime_shock_decomposition.pool(:,:,yr-my_forecast_:yr) - ... - oo_.annualized_realtime_forecast_shock_decomposition.(['yr_' int2str(yr-my_forecast_)])(:,:,1:my_forecast_+1); - oo_.annualized_realtime_conditional_shock_decomposition.(['yr_' int2str(yr-my_forecast_)])(:,end-1,:) = ... - oo_.annualized_realtime_forecast_shock_decomposition.(['yr_' int2str(yr-my_forecast_)])(:,end,1:my_forecast_+1); - oo_.annualized_realtime_conditional_shock_decomposition.(['yr_' int2str(yr-my_forecast_)])(:,end,:) = ... - oo_.annualized_realtime_shock_decomposition.pool(:,end,yr-my_forecast_:yr); + if opts.forecast + oo_.annualized_realtime_forecast_shock_decomposition.(['yr_' int2str(yr)]) = z(:,:,end-nfrcst:end); + if init>nfrcst + oo_.annualized_realtime_conditional_shock_decomposition.(['yr_' int2str(yr-nfrcst)]) = ... + oo_.annualized_realtime_shock_decomposition.pool(:,:,yr-nfrcst:end) - ... + oo_.annualized_realtime_forecast_shock_decomposition.(['yr_' int2str(yr-nfrcst)]); + % fix others + oo_.annualized_realtime_conditional_shock_decomposition.(['yr_' int2str(yr-nfrcst)])(:,end-1,:) = ... + oo_.annualized_realtime_conditional_shock_decomposition.(['yr_' int2str(yr-nfrcst)])(:,end-1,:) + ... + oo_.annualized_realtime_forecast_shock_decomposition.(['yr_' int2str(yr-nfrcst)])(:,end,:); + % fix total + oo_.annualized_realtime_conditional_shock_decomposition.(['yr_' int2str(yr-nfrcst)])(:,end,:) = ... + oo_.annualized_realtime_shock_decomposition.pool(:,end,yr-nfrcst:end); + if i==t1 + for my_forecast_=(nfrcst-1):-1:1, + oo_.annualized_realtime_conditional_shock_decomposition.(['yr_' int2str(yr-my_forecast_)]) = ... + oo_.annualized_realtime_shock_decomposition.pool(:,:,yr-my_forecast_:yr) - ... + oo_.annualized_realtime_forecast_shock_decomposition.(['yr_' int2str(yr-my_forecast_)])(:,:,1:my_forecast_+1); + oo_.annualized_realtime_conditional_shock_decomposition.(['yr_' int2str(yr-my_forecast_)])(:,end-1,:) = ... + oo_.annualized_realtime_forecast_shock_decomposition.(['yr_' int2str(yr-my_forecast_)])(:,end,1:my_forecast_+1); + oo_.annualized_realtime_conditional_shock_decomposition.(['yr_' int2str(yr-my_forecast_)])(:,end,:) = ... + oo_.annualized_realtime_shock_decomposition.pool(:,end,yr-my_forecast_:yr); + end end end end - end -% ztmp=oo_.realtime_shock_decomposition.pool(:,:,21:29)-oo_.realtime_forecast_shock_decomposition.time_21; + % ztmp=oo_.realtime_shock_decomposition.pool(:,:,21:29)-oo_.realtime_forecast_shock_decomposition.time_21; - init=init+1; -end + init=init+1; + end -switch realtime_ - - case 0 + switch realtime_ + + case 0 z = oo_.annualized_shock_decomposition; - - case 1 % realtime + + case 1 % realtime if vintage_ z = oo_.annualized_realtime_shock_decomposition.(['yr_' int2str(floor(vintage_/4))]); else z = oo_.annualized_realtime_shock_decomposition.pool; end - - case 2 % conditional + + case 2 % conditional if vintage_ z = oo_.annualized_realtime_conditional_shock_decomposition.(['yr_' int2str(floor(vintage_/4))]); else error(); end - case 3 % forecast + case 3 % forecast if vintage_ z = oo_.annualized_realtime_forecast_shock_decomposition.(['yr_' int2str(floor(vintage_/4))]); else error() end -end + end end if q2a.plot ==0, diff --git a/matlab/backward/simul_backward_model.m b/matlab/backward/simul_backward_model.m index 4cf801fbdb..5327e6435c 100644 --- a/matlab/backward/simul_backward_model.m +++ b/matlab/backward/simul_backward_model.m @@ -91,8 +91,8 @@ end if DynareOptions.linear DynareOutput = simul_backward_linear_model(initial_conditions, sample_size, DynareOptions, ... - DynareModel, DynareOutput, innovations); + DynareModel, DynareOutput, innovations); else DynareOutput = simul_backward_nonlinear_model(initial_conditions, sample_size, DynareOptions, ... - DynareModel, DynareOutput, innovations); + DynareModel, DynareOutput, innovations); end \ No newline at end of file diff --git a/matlab/basic_plan.m b/matlab/basic_plan.m index c7b4cb3603..233e795eb1 100644 --- a/matlab/basic_plan.m +++ b/matlab/basic_plan.m @@ -31,60 +31,60 @@ function plan = basic_plan(plan, exogenous, expectation_type, date, value) % You should have received a copy of the GNU General Public License % along with Dynare. If not, see <http://www.gnu.org/licenses/>. - if ~ischar(expectation_type) || size(expectation_type,1) ~= 1 - error(['in basic_plan the third argument should be a string containing the simulation type (''perfect_foresight'' or ''surprise'')']); - end - exogenous = strtrim(exogenous); - ix = find(strcmp(exogenous, plan.exo_names)); - if isempty(ix) - error(['in basic_plan the second argument ' exogenous ' is not an exogenous variable']); - end; - sdate = length(date); - if sdate > 1 - if date(1) < plan.date(1) || date(end) > plan.date(end) - error(['in basic_plan the fourth argument (date=' date ') must lay inside the plan.date ' plan.date]); - end - else - if date < plan.date(1) || date > plan.date(end) - error(['in basic_plan the fourth argument (date=' date ') must lay iside the plan.date ' plan.date]); - end - end - if length(date) ~= length(value) - error(['in basic_plan the number of dates (' int2str(length(date)) ') is not equal to the numbers of shock (' int2str(length(value)) ') for exogenous variable ' exogenous]); - end - if ~isempty(plan.options_cond_fcst_.controlled_varexo) - common_var = find(ix == plan.options_cond_fcst_.controlled_varexo); - if ~isempty(common_var) - common_date = intersect(date, plan.constrained_date_{common_var}); - if ~isempty(common_date) - [date_, i_date] = setdiff(date, common_date); - value = value(i_date); - if common_date.length > 1 - the_dates = [cell2mat(strings(common_date(1))) ':' cell2mat(strings(common_date(end)))]; - else - the_dates = cell2mat(strings(common_date)); - end - warning(['Impossible case: ' plan.exo_names{plan.options_cond_fcst_.controlled_varexo(common_var)} ' is used both as a shock and as an endogenous variable to control the path of ' plan.endo_names{plan.constrained_vars_(common_var)} ' at the dates ' the_dates]); - warning('This shock will not be considered'); - end - end - end - if isempty(plan.shock_vars_) - plan.shock_vars_ = ix; - if strcmp(expectation_type, 'perfect_foresight') - plan.shock_perfect_foresight_ = 1; - else - plan.shock_perfect_foresight_ = 0; - end - else - plan.shock_vars_ = [plan.shock_vars_ ; ix]; - if strcmp(expectation_type, 'perfect_foresight') - plan.shock_perfect_foresight_ = [plan.shock_perfect_foresight_ ; 1]; - else - plan.shock_perfect_foresight_ = [plan.shock_perfect_foresight_ ; 0]; - end - end - plan.shock_date_{length(plan.shock_date_) + 1} = date; - plan.shock_str_date_{length(plan.shock_str_date_) + 1} = strings(date); - plan.shock_int_date_{length(plan.shock_int_date_) + 1} = date - plan.date(1) + 1; - plan.shock_paths_{length(plan.shock_paths_) + 1} = value; +if ~ischar(expectation_type) || size(expectation_type,1) ~= 1 + error(['in basic_plan the third argument should be a string containing the simulation type (''perfect_foresight'' or ''surprise'')']); +end +exogenous = strtrim(exogenous); +ix = find(strcmp(exogenous, plan.exo_names)); +if isempty(ix) + error(['in basic_plan the second argument ' exogenous ' is not an exogenous variable']); +end; +sdate = length(date); +if sdate > 1 + if date(1) < plan.date(1) || date(end) > plan.date(end) + error(['in basic_plan the fourth argument (date=' date ') must lay inside the plan.date ' plan.date]); + end +else + if date < plan.date(1) || date > plan.date(end) + error(['in basic_plan the fourth argument (date=' date ') must lay iside the plan.date ' plan.date]); + end +end +if length(date) ~= length(value) + error(['in basic_plan the number of dates (' int2str(length(date)) ') is not equal to the numbers of shock (' int2str(length(value)) ') for exogenous variable ' exogenous]); +end +if ~isempty(plan.options_cond_fcst_.controlled_varexo) + common_var = find(ix == plan.options_cond_fcst_.controlled_varexo); + if ~isempty(common_var) + common_date = intersect(date, plan.constrained_date_{common_var}); + if ~isempty(common_date) + [date_, i_date] = setdiff(date, common_date); + value = value(i_date); + if common_date.length > 1 + the_dates = [cell2mat(strings(common_date(1))) ':' cell2mat(strings(common_date(end)))]; + else + the_dates = cell2mat(strings(common_date)); + end + warning(['Impossible case: ' plan.exo_names{plan.options_cond_fcst_.controlled_varexo(common_var)} ' is used both as a shock and as an endogenous variable to control the path of ' plan.endo_names{plan.constrained_vars_(common_var)} ' at the dates ' the_dates]); + warning('This shock will not be considered'); + end + end +end +if isempty(plan.shock_vars_) + plan.shock_vars_ = ix; + if strcmp(expectation_type, 'perfect_foresight') + plan.shock_perfect_foresight_ = 1; + else + plan.shock_perfect_foresight_ = 0; + end +else + plan.shock_vars_ = [plan.shock_vars_ ; ix]; + if strcmp(expectation_type, 'perfect_foresight') + plan.shock_perfect_foresight_ = [plan.shock_perfect_foresight_ ; 1]; + else + plan.shock_perfect_foresight_ = [plan.shock_perfect_foresight_ ; 0]; + end +end +plan.shock_date_{length(plan.shock_date_) + 1} = date; +plan.shock_str_date_{length(plan.shock_str_date_) + 1} = strings(date); +plan.shock_int_date_{length(plan.shock_int_date_) + 1} = date - plan.date(1) + 1; +plan.shock_paths_{length(plan.shock_paths_) + 1} = value; diff --git a/matlab/bvar_forecast.m b/matlab/bvar_forecast.m index d070884b4b..5319ab8be3 100644 --- a/matlab/bvar_forecast.m +++ b/matlab/bvar_forecast.m @@ -120,9 +120,9 @@ dyn_graph=dynare_graph_init(sprintf('BVAR forecasts (nlags = %d)', nlags), ny, { for i = 1:ny dyn_graph=dynare_graph(dyn_graph,[ sims_no_shock_median(:, i) ... - sims_no_shock_up_conf(:, i) sims_no_shock_down_conf(:, i) ... - sims_with_shocks_up_conf(:, i) sims_with_shocks_down_conf(:, i) ], ... - options_.varobs{i}); + sims_no_shock_up_conf(:, i) sims_no_shock_down_conf(:, i) ... + sims_with_shocks_up_conf(:, i) sims_with_shocks_down_conf(:, i) ], ... + options_.varobs{i}); end dyn_saveas(dyn_graph.fh,[OutputDirectoryName '/' M_.fname '_BVAR_forecast_',num2str(nlags)],options_.nodisplay,options_.graph_format) diff --git a/matlab/check_matlab_path.m b/matlab/check_matlab_path.m index 3817def6be..a5156df919 100644 --- a/matlab/check_matlab_path.m +++ b/matlab/check_matlab_path.m @@ -1,5 +1,5 @@ function check_matlab_path(change_path_flag) - + % Copyright (C) 2015-2016 Dynare Team % % This file is part of Dynare. @@ -107,40 +107,40 @@ else end function q = path2cell(p) - % Converts the output of path() to a cell - s = strfind(p,pathsep); - n = length(s)+1; - q = cell(n,1); - q(1) = {p(1:s(1)-1)}; - q(n) = {p(s(end)+1:end)}; - for i=2:n-1 - q(i) = {p(s(i-1)+1:s(i)-1)}; - end - +% Converts the output of path() to a cell +s = strfind(p,pathsep); +n = length(s)+1; +q = cell(n,1); +q(1) = {p(1:s(1)-1)}; +q(n) = {p(s(end)+1:end)}; +for i=2:n-1 + q(i) = {p(s(i-1)+1:s(i)-1)}; +end + function flist = getallroutinenames(p, excludedsubfolders) - if nargin<2 - excludedsubfolders = {}; - end - flist={}; - %get m-files in this directory - dd = dir([p,filesep '*.m']); - temp=struct2cell(dd); - flist=[flist temp(1,:)]; - %deal with subdirectories - dlist=getalldirectories(p,excludedsubfolders); %first call with excluded directories - for ii=1:length(dlist) - flist=[flist getallroutinenames([ p filesep dlist{ii}])]; %recursive calls without subfolders - end - +if nargin<2 + excludedsubfolders = {}; +end +flist={}; +%get m-files in this directory +dd = dir([p,filesep '*.m']); +temp=struct2cell(dd); +flist=[flist temp(1,:)]; +%deal with subdirectories +dlist=getalldirectories(p,excludedsubfolders); %first call with excluded directories +for ii=1:length(dlist) + flist=[flist getallroutinenames([ p filesep dlist{ii}])]; %recursive calls without subfolders +end + function dlist = getalldirectories(p,excluded_directories) - if nargin<2 - excluded_directories = {}; - end - dd = dir(p); - dir_result=struct2cell(dd); - directory_indicator=cell2mat(dir_result(4,:)); - dlist = dir_result(1,directory_indicator==1 & ~strcmp('.',dir_result(1,:)) & ~strcmp('..',dir_result(1,:)) & ~ismember(dir_result(1,:),excluded_directories)); +if nargin<2 + excluded_directories = {}; +end +dd = dir(p); +dir_result=struct2cell(dd); +directory_indicator=cell2mat(dir_result(4,:)); +dlist = dir_result(1,directory_indicator==1 & ~strcmp('.',dir_result(1,:)) & ~strcmp('..',dir_result(1,:)) & ~ismember(dir_result(1,:),excluded_directories)); function n = position(i, currentpath) - n = length(strfind(currentpath(1:i), pathsep)); \ No newline at end of file +n = length(strfind(currentpath(1:i), pathsep)); \ No newline at end of file diff --git a/matlab/check_posterior_sampler_options.m b/matlab/check_posterior_sampler_options.m index 1980c0a798..d20f85a161 100644 --- a/matlab/check_posterior_sampler_options.m +++ b/matlab/check_posterior_sampler_options.m @@ -43,334 +43,334 @@ if init, switch posterior_sampler_options.posterior_sampling_method - case 'random_walk_metropolis_hastings' - posterior_sampler_options.parallel_bar_refresh_rate=50; - posterior_sampler_options.serial_bar_refresh_rate=3; - posterior_sampler_options.parallel_bar_title='RWMH'; - posterior_sampler_options.serial_bar_title='RW Metropolis-Hastings'; - - % default options - posterior_sampler_options = add_fields_(posterior_sampler_options,options_.posterior_sampler_options.rwmh); - - % user defined options - if ~isempty(options_.posterior_sampler_options.sampling_opt) - options_list = read_key_value_string(options_.posterior_sampler_options.sampling_opt); - for i=1:rows(options_list) - switch options_list{i,1} - - case 'proposal_distribution' - if ~(strcmpi(options_list{i,2}, 'rand_multivariate_student') || ... - strcmpi(options_list{i,2}, 'rand_multivariate_normal')) - error(['initial_estimation_checks:: the proposal_distribution option to estimation takes either ' ... - 'rand_multivariate_student or rand_multivariate_normal as options']); - else - posterior_sampler_options.proposal_distribution=options_list{i,2}; - end - - - case 'student_degrees_of_freedom' - if options_list{i,2} <= 0 - error('initial_estimation_checks:: the student_degrees_of_freedom takes a positive integer argument'); - else - posterior_sampler_options.student_degrees_of_freedom=options_list{i,2}; - end - - case 'use_mh_covariance_matrix' - % indicates to use the covariance matrix from previous iterations to - % define the covariance of the proposal distribution - % default = 0 - posterior_sampler_options.use_mh_covariance_matrix = options_list{i,2}; - options_.use_mh_covariance_matrix = options_list{i,2}; - case 'scale_file' - % load optimal_mh_scale parameter if previous run was with mode_compute=6 - % will overwrite jscale from set_prior.m - if exist(options_list{i,2},'file') || exist([options_list{i,2},'.mat'],'file') - tmp = load(options_list{i,2},'Scale'); - global bayestopt_ - bayestopt_.mh_jscale = tmp.Scale; - options_.mh_jscale = tmp.Scale; - bayestopt_.jscale = ones(size(bounds.lb,1),1)*tmp.Scale; -% options_.mh_init_scale = 2*options_.mh_jscale; - else - error('initial_estimation_checks:: The specified mh_scale_file does not exist.') - end - case 'save_tmp_file' - posterior_sampler_options.save_tmp_file = options_list{i,2}; - otherwise - warning(['rwmh_sampler: Unknown option (' options_list{i,1} ')!']) + case 'random_walk_metropolis_hastings' + posterior_sampler_options.parallel_bar_refresh_rate=50; + posterior_sampler_options.serial_bar_refresh_rate=3; + posterior_sampler_options.parallel_bar_title='RWMH'; + posterior_sampler_options.serial_bar_title='RW Metropolis-Hastings'; + + % default options + posterior_sampler_options = add_fields_(posterior_sampler_options,options_.posterior_sampler_options.rwmh); + + % user defined options + if ~isempty(options_.posterior_sampler_options.sampling_opt) + options_list = read_key_value_string(options_.posterior_sampler_options.sampling_opt); + for i=1:rows(options_list) + switch options_list{i,1} + + case 'proposal_distribution' + if ~(strcmpi(options_list{i,2}, 'rand_multivariate_student') || ... + strcmpi(options_list{i,2}, 'rand_multivariate_normal')) + error(['initial_estimation_checks:: the proposal_distribution option to estimation takes either ' ... + 'rand_multivariate_student or rand_multivariate_normal as options']); + else + posterior_sampler_options.proposal_distribution=options_list{i,2}; + end + + + case 'student_degrees_of_freedom' + if options_list{i,2} <= 0 + error('initial_estimation_checks:: the student_degrees_of_freedom takes a positive integer argument'); + else + posterior_sampler_options.student_degrees_of_freedom=options_list{i,2}; + end + + case 'use_mh_covariance_matrix' + % indicates to use the covariance matrix from previous iterations to + % define the covariance of the proposal distribution + % default = 0 + posterior_sampler_options.use_mh_covariance_matrix = options_list{i,2}; + options_.use_mh_covariance_matrix = options_list{i,2}; + case 'scale_file' + % load optimal_mh_scale parameter if previous run was with mode_compute=6 + % will overwrite jscale from set_prior.m + if exist(options_list{i,2},'file') || exist([options_list{i,2},'.mat'],'file') + tmp = load(options_list{i,2},'Scale'); + global bayestopt_ + bayestopt_.mh_jscale = tmp.Scale; + options_.mh_jscale = tmp.Scale; + bayestopt_.jscale = ones(size(bounds.lb,1),1)*tmp.Scale; + % options_.mh_init_scale = 2*options_.mh_jscale; + else + error('initial_estimation_checks:: The specified mh_scale_file does not exist.') end + case 'save_tmp_file' + posterior_sampler_options.save_tmp_file = options_list{i,2}; + otherwise + warning(['rwmh_sampler: Unknown option (' options_list{i,1} ')!']) end end - - case 'tailored_random_block_metropolis_hastings' - posterior_sampler_options.parallel_bar_refresh_rate=5; - posterior_sampler_options.serial_bar_refresh_rate=1; - posterior_sampler_options.parallel_bar_title='TaRB-MH'; - posterior_sampler_options.serial_bar_title='TaRB Metropolis-Hastings'; - - % default options - posterior_sampler_options = add_fields_(posterior_sampler_options,options_.posterior_sampler_options.tarb); - - % user defined options - if ~isempty(options_.posterior_sampler_options.sampling_opt) - options_list = read_key_value_string(options_.posterior_sampler_options.sampling_opt); - for i=1:rows(options_list) + end + + case 'tailored_random_block_metropolis_hastings' + posterior_sampler_options.parallel_bar_refresh_rate=5; + posterior_sampler_options.serial_bar_refresh_rate=1; + posterior_sampler_options.parallel_bar_title='TaRB-MH'; + posterior_sampler_options.serial_bar_title='TaRB Metropolis-Hastings'; + + % default options + posterior_sampler_options = add_fields_(posterior_sampler_options,options_.posterior_sampler_options.tarb); + + % user defined options + if ~isempty(options_.posterior_sampler_options.sampling_opt) + options_list = read_key_value_string(options_.posterior_sampler_options.sampling_opt); + for i=1:rows(options_list) + + switch options_list{i,1} + + case 'proposal_distribution' + if ~(strcmpi(options_list{i,2}, 'rand_multivariate_student') || ... + strcmpi(options_list{i,2}, 'rand_multivariate_normal')) + error(['initial_estimation_checks:: the proposal_distribution option to estimation takes either ' ... + 'rand_multivariate_student or rand_multivariate_normal as options']); + else + posterior_sampler_options.proposal_distribution=options_list{i,2}; + end + + + case 'student_degrees_of_freedom' + if options_list{i,2} <= 0 + error('initial_estimation_checks:: the student_degrees_of_freedom takes a positive integer argument'); + else + posterior_sampler_options.student_degrees_of_freedom=options_list{i,2}; + end - switch options_list{i,1} - - case 'proposal_distribution' - if ~(strcmpi(options_list{i,2}, 'rand_multivariate_student') || ... - strcmpi(options_list{i,2}, 'rand_multivariate_normal')) - error(['initial_estimation_checks:: the proposal_distribution option to estimation takes either ' ... - 'rand_multivariate_student or rand_multivariate_normal as options']); - else - posterior_sampler_options.proposal_distribution=options_list{i,2}; - end - - - case 'student_degrees_of_freedom' - if options_list{i,2} <= 0 - error('initial_estimation_checks:: the student_degrees_of_freedom takes a positive integer argument'); - else - posterior_sampler_options.student_degrees_of_freedom=options_list{i,2}; - end - - case 'mode_compute' - posterior_sampler_options.mode_compute=options_list{i,2}; - - case 'optim' - posterior_sampler_options.optim_opt=options_list{i,2}; + case 'mode_compute' + posterior_sampler_options.mode_compute=options_list{i,2}; + + case 'optim' + posterior_sampler_options.optim_opt=options_list{i,2}; - case 'new_block_probability' - if options_list{i,2}<0 || options_list{i,2}>1 - error('check_posterior_sampler_options:: The tarb new_block_probability must be between 0 and 1!') - else - posterior_sampler_options.new_block_probability=options_list{i,2}; - end - case 'scale_file' - % load optimal_mh_scale parameter if previous run was with mode_compute=6 - % will overwrite jscale from set_prior.m - if exist(options_list{i,2},'file') || exist([options_list{i,2},'.mat'],'file') - tmp = load(options_list{i,2},'Scale'); - global bayestopt_ - bayestopt_.mh_jscale = tmp.Scale; - options_.mh_jscale = tmp.Scale; - bayestopt_.jscale = ones(size(bounds.lb,1),1)*tmp.Scale; -% options_.mh_init_scale = 2*options_.mh_jscale; - else - error('initial_estimation_checks:: The specified scale_file does not exist.') - end - case 'save_tmp_file' - posterior_sampler_options.save_tmp_file = options_list{i,2}; - - otherwise - warning(['tarb_sampler: Unknown option (' options_list{i,1} ')!']) - + case 'new_block_probability' + if options_list{i,2}<0 || options_list{i,2}>1 + error('check_posterior_sampler_options:: The tarb new_block_probability must be between 0 and 1!') + else + posterior_sampler_options.new_block_probability=options_list{i,2}; + end + case 'scale_file' + % load optimal_mh_scale parameter if previous run was with mode_compute=6 + % will overwrite jscale from set_prior.m + if exist(options_list{i,2},'file') || exist([options_list{i,2},'.mat'],'file') + tmp = load(options_list{i,2},'Scale'); + global bayestopt_ + bayestopt_.mh_jscale = tmp.Scale; + options_.mh_jscale = tmp.Scale; + bayestopt_.jscale = ones(size(bounds.lb,1),1)*tmp.Scale; + % options_.mh_init_scale = 2*options_.mh_jscale; + else + error('initial_estimation_checks:: The specified scale_file does not exist.') end + case 'save_tmp_file' + posterior_sampler_options.save_tmp_file = options_list{i,2}; + + otherwise + warning(['tarb_sampler: Unknown option (' options_list{i,1} ')!']) end end - case 'independent_metropolis_hastings' - posterior_sampler_options.parallel_bar_refresh_rate=50; - posterior_sampler_options.serial_bar_refresh_rate=3; - posterior_sampler_options.parallel_bar_title='IMH'; - posterior_sampler_options.serial_bar_title='Ind. Metropolis-Hastings'; - - % default options - posterior_sampler_options = add_fields_(posterior_sampler_options,options_.posterior_sampler_options.imh); - - % user defined options - if ~isempty(options_.posterior_sampler_options.sampling_opt) - options_list = read_key_value_string(options_.posterior_sampler_options.sampling_opt); - for i=1:rows(options_list) - switch options_list{i,1} - - case 'proposal_distribution' - if ~(strcmpi(options_list{i,2}, 'rand_multivariate_student') || ... - strcmpi(options_list{i,2}, 'rand_multivariate_normal')) - error(['initial_estimation_checks:: the proposal_distribution option to estimation takes either ' ... - 'rand_multivariate_student or rand_multivariate_normal as options']); - else - posterior_sampler_options.proposal_distribution=options_list{i,2}; - end - - - case 'student_degrees_of_freedom' - if options_list{i,2} <= 0 - error('initial_estimation_checks:: the student_degrees_of_freedom takes a positive integer argument'); - else - posterior_sampler_options.student_degrees_of_freedom=options_list{i,2}; - end - - case 'use_mh_covariance_matrix' - % indicates to use the covariance matrix from previous iterations to - % define the covariance of the proposal distribution - % default = 0 - posterior_sampler_options.use_mh_covariance_matrix = options_list{i,2}; - options_.use_mh_covariance_matrix = options_list{i,2}; - - case 'save_tmp_file' - posterior_sampler_options.save_tmp_file = options_list{i,2}; - - otherwise - warning(['imh_sampler: Unknown option (' options_list{i,1} ')!']) + end + + case 'independent_metropolis_hastings' + posterior_sampler_options.parallel_bar_refresh_rate=50; + posterior_sampler_options.serial_bar_refresh_rate=3; + posterior_sampler_options.parallel_bar_title='IMH'; + posterior_sampler_options.serial_bar_title='Ind. Metropolis-Hastings'; + + % default options + posterior_sampler_options = add_fields_(posterior_sampler_options,options_.posterior_sampler_options.imh); + + % user defined options + if ~isempty(options_.posterior_sampler_options.sampling_opt) + options_list = read_key_value_string(options_.posterior_sampler_options.sampling_opt); + for i=1:rows(options_list) + switch options_list{i,1} + + case 'proposal_distribution' + if ~(strcmpi(options_list{i,2}, 'rand_multivariate_student') || ... + strcmpi(options_list{i,2}, 'rand_multivariate_normal')) + error(['initial_estimation_checks:: the proposal_distribution option to estimation takes either ' ... + 'rand_multivariate_student or rand_multivariate_normal as options']); + else + posterior_sampler_options.proposal_distribution=options_list{i,2}; + end + + + case 'student_degrees_of_freedom' + if options_list{i,2} <= 0 + error('initial_estimation_checks:: the student_degrees_of_freedom takes a positive integer argument'); + else + posterior_sampler_options.student_degrees_of_freedom=options_list{i,2}; end + + case 'use_mh_covariance_matrix' + % indicates to use the covariance matrix from previous iterations to + % define the covariance of the proposal distribution + % default = 0 + posterior_sampler_options.use_mh_covariance_matrix = options_list{i,2}; + options_.use_mh_covariance_matrix = options_list{i,2}; + + case 'save_tmp_file' + posterior_sampler_options.save_tmp_file = options_list{i,2}; + + otherwise + warning(['imh_sampler: Unknown option (' options_list{i,1} ')!']) end end - - - case 'slice' - posterior_sampler_options.parallel_bar_refresh_rate=1; - posterior_sampler_options.serial_bar_refresh_rate=1; - posterior_sampler_options.parallel_bar_title='SLICE'; - posterior_sampler_options.serial_bar_title='SLICE'; - - % default options - posterior_sampler_options = add_fields_(posterior_sampler_options,options_.posterior_sampler_options.slice); - - % user defined options - if ~isempty(options_.posterior_sampler_options.sampling_opt) - options_list = read_key_value_string(options_.posterior_sampler_options.sampling_opt); - for i=1:rows(options_list) - switch options_list{i,1} - case 'rotated' - % triggers rotated slice iterations using a covariance - % matrix from initial burn-in iterations - % must be associated with: - % <use_mh_covariance_matrix> or <slice_initialize_with_mode> - % default = 0 - posterior_sampler_options.rotated = options_list{i,2}; - - case 'mode' - % for multimodal posteriors, provide the list of modes as a - % matrix, ordered by column, i.e. [x1 x2 x3] for three - % modes x1 x2 x3 - % MR note: not sure this is possible with the - % read_key_value_string ??? - % if this is not possible <mode_files> does to job in any case - % This will automatically trigger <rotated> - % default = [] - tmp_mode = options_list{i,2}; - for j=1:size(tmp_mode,2), - posterior_sampler_options.mode(j).m = tmp_mode(:,j); - end - - case 'mode_files' - % for multimodal posteriors provide the name of - % a file containing a variable array xparams = [nparam * nmodes] - % one column per mode. With this info, the code will automatically - % set the <mode> option. - % This will automatically trigger <rotated> - % default = [] - posterior_sampler_options.mode_files = options_list{i,2}; - - case 'slice_initialize_with_mode' - % the default for slice is to set mode_compute = 0 in the - % preprocessor and start the chain(s) from a random location in the prior. - % This option first runs the optimizer and then starts the - % chain from the mode. Associated with optios <rotated>, it will - % use invhess from the mode to perform rotated slice - % iterations. - % default = 0 - posterior_sampler_options.slice_initialize_with_mode = options_list{i,2}; - - case 'initial_step_size' - % sets the initial size of the interval in the STEPPING-OUT PROCEDURE - % the initial_step_size must be a real number in [0, 1], - % and it sets the size as a proportion of the prior bounds, - % i.e. the size will be initial_step_size*(UB-LB) - % slice sampler requires prior_truncation > 0! - % default = 0.8 - if options_list{i,2}<=0 || options_list{i,2}>=1 - error('check_posterior_sampler_options:: slice initial_step_size must be between 0 and 1') - else - posterior_sampler_options.initial_step_size=options_list{i,2}; - end - case 'use_mh_covariance_matrix' - % in association with <rotated> indicates to use the - % covariance matrix from previous iterations to define the - % rotated slice - % default = 0 - posterior_sampler_options.use_mh_covariance_matrix = options_list{i,2}; - options_.use_mh_covariance_matrix = options_list{i,2}; - - case 'save_tmp_file' - posterior_sampler_options.save_tmp_file = options_list{i,2}; - - otherwise - warning(['slice_sampler: Unknown option (' options_list{i,1} ')!']) + end + + + case 'slice' + posterior_sampler_options.parallel_bar_refresh_rate=1; + posterior_sampler_options.serial_bar_refresh_rate=1; + posterior_sampler_options.parallel_bar_title='SLICE'; + posterior_sampler_options.serial_bar_title='SLICE'; + + % default options + posterior_sampler_options = add_fields_(posterior_sampler_options,options_.posterior_sampler_options.slice); + + % user defined options + if ~isempty(options_.posterior_sampler_options.sampling_opt) + options_list = read_key_value_string(options_.posterior_sampler_options.sampling_opt); + for i=1:rows(options_list) + switch options_list{i,1} + case 'rotated' + % triggers rotated slice iterations using a covariance + % matrix from initial burn-in iterations + % must be associated with: + % <use_mh_covariance_matrix> or <slice_initialize_with_mode> + % default = 0 + posterior_sampler_options.rotated = options_list{i,2}; + + case 'mode' + % for multimodal posteriors, provide the list of modes as a + % matrix, ordered by column, i.e. [x1 x2 x3] for three + % modes x1 x2 x3 + % MR note: not sure this is possible with the + % read_key_value_string ??? + % if this is not possible <mode_files> does to job in any case + % This will automatically trigger <rotated> + % default = [] + tmp_mode = options_list{i,2}; + for j=1:size(tmp_mode,2), + posterior_sampler_options.mode(j).m = tmp_mode(:,j); + end + + case 'mode_files' + % for multimodal posteriors provide the name of + % a file containing a variable array xparams = [nparam * nmodes] + % one column per mode. With this info, the code will automatically + % set the <mode> option. + % This will automatically trigger <rotated> + % default = [] + posterior_sampler_options.mode_files = options_list{i,2}; + + case 'slice_initialize_with_mode' + % the default for slice is to set mode_compute = 0 in the + % preprocessor and start the chain(s) from a random location in the prior. + % This option first runs the optimizer and then starts the + % chain from the mode. Associated with optios <rotated>, it will + % use invhess from the mode to perform rotated slice + % iterations. + % default = 0 + posterior_sampler_options.slice_initialize_with_mode = options_list{i,2}; + + case 'initial_step_size' + % sets the initial size of the interval in the STEPPING-OUT PROCEDURE + % the initial_step_size must be a real number in [0, 1], + % and it sets the size as a proportion of the prior bounds, + % i.e. the size will be initial_step_size*(UB-LB) + % slice sampler requires prior_truncation > 0! + % default = 0.8 + if options_list{i,2}<=0 || options_list{i,2}>=1 + error('check_posterior_sampler_options:: slice initial_step_size must be between 0 and 1') + else + posterior_sampler_options.initial_step_size=options_list{i,2}; end + case 'use_mh_covariance_matrix' + % in association with <rotated> indicates to use the + % covariance matrix from previous iterations to define the + % rotated slice + % default = 0 + posterior_sampler_options.use_mh_covariance_matrix = options_list{i,2}; + options_.use_mh_covariance_matrix = options_list{i,2}; + + case 'save_tmp_file' + posterior_sampler_options.save_tmp_file = options_list{i,2}; + + otherwise + warning(['slice_sampler: Unknown option (' options_list{i,1} ')!']) end end - - % slice posterior sampler does not require mode or hessian to run - % needs to be set to 1 to skip parts in dynare_estimation_1.m - % requiring posterior maximization/calibrated smoother before MCMC - options_.mh_posterior_mode_estimation=1; - - if ~ posterior_sampler_options.slice_initialize_with_mode + end + + % slice posterior sampler does not require mode or hessian to run + % needs to be set to 1 to skip parts in dynare_estimation_1.m + % requiring posterior maximization/calibrated smoother before MCMC + options_.mh_posterior_mode_estimation=1; + + if ~ posterior_sampler_options.slice_initialize_with_mode % by default, slice sampler should trigger % mode_compute=0 and % mh_replic=100 (much smaller than the default mh_replic=20000 of RWMH) - options_.mode_compute = 0; - options_.cova_compute = 0; - else - if (isequal(options_.mode_compute,0) && isempty(options_.mode_file) ) - skipline() - disp('check_posterior_sampler_options:: You have specified the option "slice_initialize_with_mode"') - disp('check_posterior_sampler_options:: to initialize the slice sampler using mode information') - disp('check_posterior_sampler_options:: but no mode file nor posterior maximization is selected,') - error('check_posterior_sampler_options:: The option "slice_initialize_with_mode" is inconsistent with mode_compute=0 or empty mode_file.') - else - options_.mh_posterior_mode_estimation=0; - end - end - - if any(isinf(bounds.lb)) || any(isinf(bounds.ub)), + options_.mode_compute = 0; + options_.cova_compute = 0; + else + if (isequal(options_.mode_compute,0) && isempty(options_.mode_file) ) skipline() - disp('some priors are unbounded and prior_trunc is set to zero') - error('The option "slice" is inconsistent with prior_trunc=0.') + disp('check_posterior_sampler_options:: You have specified the option "slice_initialize_with_mode"') + disp('check_posterior_sampler_options:: to initialize the slice sampler using mode information') + disp('check_posterior_sampler_options:: but no mode file nor posterior maximization is selected,') + error('check_posterior_sampler_options:: The option "slice_initialize_with_mode" is inconsistent with mode_compute=0 or empty mode_file.') + else + options_.mh_posterior_mode_estimation=0; end - - % moreover slice must be associated to: - % options_.mh_posterior_mode_estimation = 0; - % this is done below, but perhaps preprocessing should do this? - - if ~isempty(posterior_sampler_options.mode) - % multimodal case - posterior_sampler_options.rotated = 1; - posterior_sampler_options.WR=[]; + end + + if any(isinf(bounds.lb)) || any(isinf(bounds.ub)), + skipline() + disp('some priors are unbounded and prior_trunc is set to zero') + error('The option "slice" is inconsistent with prior_trunc=0.') + end + + % moreover slice must be associated to: + % options_.mh_posterior_mode_estimation = 0; + % this is done below, but perhaps preprocessing should do this? + + if ~isempty(posterior_sampler_options.mode) + % multimodal case + posterior_sampler_options.rotated = 1; + posterior_sampler_options.WR=[]; + end + % posterior_sampler_options = set_default_option(posterior_sampler_options,'mode_files',[]); + + + posterior_sampler_options.W1=posterior_sampler_options.initial_step_size*(bounds.ub-bounds.lb); + if options_.load_mh_file, + posterior_sampler_options.slice_initialize_with_mode = 0; + else + if ~posterior_sampler_options.slice_initialize_with_mode, + posterior_sampler_options.invhess=[]; end - % posterior_sampler_options = set_default_option(posterior_sampler_options,'mode_files',[]); - - - posterior_sampler_options.W1=posterior_sampler_options.initial_step_size*(bounds.ub-bounds.lb); - if options_.load_mh_file, - posterior_sampler_options.slice_initialize_with_mode = 0; - else - if ~posterior_sampler_options.slice_initialize_with_mode, - posterior_sampler_options.invhess=[]; - end + end + + if ~isempty(posterior_sampler_options.mode_files), % multimodal case + modes = posterior_sampler_options.mode_files; % these can be also mean files from previous parallel slice chains + load(modes, 'xparams') + if size(xparams,2)<2, + error(['check_posterior_sampler_options:: Variable xparams loaded in file <' modes '> has size [' int2str(size(xparams,1)) 'x' int2str(size(xparams,2)) ']: it must contain at least two columns, to allow multi-modal sampling.']) end - - if ~isempty(posterior_sampler_options.mode_files), % multimodal case - modes = posterior_sampler_options.mode_files; % these can be also mean files from previous parallel slice chains - load(modes, 'xparams') - if size(xparams,2)<2, - error(['check_posterior_sampler_options:: Variable xparams loaded in file <' modes '> has size [' int2str(size(xparams,1)) 'x' int2str(size(xparams,2)) ']: it must contain at least two columns, to allow multi-modal sampling.']) - end - for j=1:size(xparams,2), - mode(j).m=xparams(:,j); - end - posterior_sampler_options.mode = mode; - posterior_sampler_options.rotated = 1; - posterior_sampler_options.WR=[]; + for j=1:size(xparams,2), + mode(j).m=xparams(:,j); end - - otherwise - error('check_posterior_sampler_options:: Unknown posterior_sampling_method option %s ',posterior_sampler_options.posterior_sampling_method); + posterior_sampler_options.mode = mode; + posterior_sampler_options.rotated = 1; + posterior_sampler_options.WR=[]; + end + + otherwise + error('check_posterior_sampler_options:: Unknown posterior_sampling_method option %s ',posterior_sampler_options.posterior_sampling_method); end return diff --git a/matlab/chol_SE.m b/matlab/chol_SE.m index 0ec5a900bf..0e516c4960 100644 --- a/matlab/chol_SE.m +++ b/matlab/chol_SE.m @@ -229,7 +229,7 @@ for j = 1:n-1 end % Calculate delta and add to the diagonal. delta=max{0,-A(j,j) + max{normj,taugam},delta_previous} % where normj=sum of |A(i,j)|,for i=1,n, delta_previous is the delta computed at the previous iter and taugam is tau1*gamma. - + normj=sum(abs(A(j+1:n,j))); delta = max([0;delta;-A(j,j)+normj;-A(j,j)+taugam]); % get adjustment based on formula on bottom of p. 309 of Eskow/Schnabel (1991) diff --git a/matlab/cli/prior.m b/matlab/cli/prior.m index 9e04450664..6395a7e444 100644 --- a/matlab/cli/prior.m +++ b/matlab/cli/prior.m @@ -53,11 +53,11 @@ end if (size(estim_params_.var_endo,1) || size(estim_params_.corrn,1)) % Prior over measurement errors are defined... - if ((isfield(options_,'varobs') && isempty(options_.varobs)) || ~isfield(options_,'varobs')) - % ... But the list of observed variabled is not yet defined. - warning('Prior detected on measurement erros, but no list of observed variables (varobs is missing)!') - return - end + if ((isfield(options_,'varobs') && isempty(options_.varobs)) || ~isfield(options_,'varobs')) + % ... But the list of observed variabled is not yet defined. + warning('Prior detected on measurement erros, but no list of observed variables (varobs is missing)!') + return + end end % Fill or update bayestopt_ structure @@ -114,7 +114,7 @@ if ismember('optimize', varargin) % Prior optimization. end if ismember('moments', varargin) % Prior simulations (2nd order moments). - % Set estimated parameters to the prior mode... + % Set estimated parameters to the prior mode... xparam1 = BayesOptions.p5; % ... Except for uniform priors (use the prior mean)! k = find(isnan(xparam1)); diff --git a/matlab/collect_latex_files.m b/matlab/collect_latex_files.m index 5c4f2b7d64..9220d25646 100644 --- a/matlab/collect_latex_files.m +++ b/matlab/collect_latex_files.m @@ -45,10 +45,10 @@ TeX_Files=dir([M_.fname,'*.tex']); for ii=1:length(TeX_Files) [pathstr,f_name,ext] = fileparts(TeX_Files(ii).name); if ~strcmp(TeX_Files(ii).name,f_name_binder) && ... - ~strcmp(TeX_Files(ii).name,[M_.fname,'_dynamic.tex']) && ... - ~strcmp(TeX_Files(ii).name,[M_.fname,'_static.tex']) && ... - ~strcmp(TeX_Files(ii).name,[M_.fname,'_original.tex']) && ... - ~strcmp(TeX_Files(ii).name,[M_.fname,'_TeX_binder.tex']) + ~strcmp(TeX_Files(ii).name,[M_.fname,'_dynamic.tex']) && ... + ~strcmp(TeX_Files(ii).name,[M_.fname,'_static.tex']) && ... + ~strcmp(TeX_Files(ii).name,[M_.fname,'_original.tex']) && ... + ~strcmp(TeX_Files(ii).name,[M_.fname,'_TeX_binder.tex']) fprintf(fid,'%s \n',['\include{',f_name,'}']); end end diff --git a/matlab/compute_moments_varendo.m b/matlab/compute_moments_varendo.m index f2e2674401..a74b55fe30 100644 --- a/matlab/compute_moments_varendo.m +++ b/matlab/compute_moments_varendo.m @@ -129,7 +129,7 @@ if M_.exo_nbr > 1 headers = char(' ',headers); lh = size(deblank(var_list_),2)+2; dyntable(options_,title,headers,deblank(var_list_),100* ... - temp,lh,8,2); + temp,lh,8,2); if options_.TeX headers=M_.exo_names_tex; headers = char(' ',headers); @@ -166,7 +166,7 @@ if M_.exo_nbr > 1 headers = char(' ',headers); lh = size(deblank(var_list_),2)+2; dyntable(options_,title_print,headers,deblank(var_list_),100* ... - temp(:,:,step_iter),lh,8,2); + temp(:,:,step_iter),lh,8,2); if options_.TeX headers=M_.exo_names_tex; headers = char(' ',headers); diff --git a/matlab/compute_overall_acceptance_ratio.m b/matlab/compute_overall_acceptance_ratio.m index d3b323eb30..937579e910 100644 --- a/matlab/compute_overall_acceptance_ratio.m +++ b/matlab/compute_overall_acceptance_ratio.m @@ -16,7 +16,7 @@ function overallacceptanceratio = compute_overall_acceptance_ratio(MetropolisFol % % You should have received a copy of the GNU General Public License % along with Dynare. If not, see <http://www.gnu.org/licenses/>. - + BaseName = [MetropolisFolder filesep ModelName]; mh_history_files = dir([BaseName '_mh_history_*.mat']); diff --git a/matlab/convergence_diagnostics/McMCDiagnostics.m b/matlab/convergence_diagnostics/McMCDiagnostics.m index c42467d31a..ff6c1089da 100644 --- a/matlab/convergence_diagnostics/McMCDiagnostics.m +++ b/matlab/convergence_diagnostics/McMCDiagnostics.m @@ -130,7 +130,7 @@ end if nblck == 1 % Brooks and Gelman tests need more than one block convergence_diagnostics_geweke=zeros(npar,4+2*length(options_.convergence.geweke.taper_steps)); if any(options_.convergence.geweke.geweke_interval<0) || any(options_.convergence.geweke.geweke_interval>1) || length(options_.convergence.geweke.geweke_interval)~=2 ... - || (options_.convergence.geweke.geweke_interval(2)-options_.convergence.geweke.geweke_interval(1)<0) + || (options_.convergence.geweke.geweke_interval(2)-options_.convergence.geweke.geweke_interval(1)<0) fprintf('\nCONVERGENCE DIAGNOSTICS: Invalid option for geweke_interval. Using the default of [0.2 0.5].\n') options_.convergence.geweke.geweke_interval=[0.2 0.5]; end @@ -168,7 +168,7 @@ if nblck == 1 % Brooks and Gelman tests need more than one block end [results_vec, results_struct] = geweke_moments(param_draws,options_); convergence_diagnostics_geweke(jj,:)=results_vec; - + param_draws1 = param_draws(first_obs_begin_sample:last_obs_begin_sample,:); param_draws2 = param_draws(first_obs_end_sample:end,:); [results_vec1] = geweke_moments(param_draws1,options_); @@ -183,7 +183,7 @@ if nblck == 1 % Brooks and Gelman tests need more than one block if options_.TeX Geweke_tex_header=char('Parameter', 'Mean', 'Std', 'No\ Taper'); additional_header={[' & \multicolumn{2}{c}{Posterior} & \multicolumn{',num2str(1+length(options_.convergence.geweke.taper_steps)),'}{c}{p-values} \\'], - ['\cmidrule(r{.75em}){2-3} \cmidrule(r{.75em}){4-',num2str(4+length(options_.convergence.geweke.taper_steps)),'}']}; + ['\cmidrule(r{.75em}){2-3} \cmidrule(r{.75em}){4-',num2str(4+length(options_.convergence.geweke.taper_steps)),'}']}; for ii=1:length(options_.convergence.geweke.taper_steps) Geweke_tex_header=char(Geweke_tex_header,[num2str(options_.convergence.geweke.taper_steps(ii)),'\%%\ Taper']); end @@ -196,7 +196,7 @@ if nblck == 1 % Brooks and Gelman tests need more than one block if options_.convergence.rafterylewis.indicator if any(options_.convergence.rafterylewis.qrs<0) || any(options_.convergence.rafterylewis.qrs>1) || length(options_.convergence.rafterylewis.qrs)~=3 ... - || (options_.convergence.rafterylewis.qrs(1)-options_.convergence.rafterylewis.qrs(2)<=0) + || (options_.convergence.rafterylewis.qrs(1)-options_.convergence.rafterylewis.qrs(2)<=0) fprintf('\nCONVERGENCE DIAGNOSTICS: Invalid option for raftery_lewis_qrs. Using the default of [0.025 0.005 0.95].\n') options_.convergence.rafterylewis.qrs=[0.025 0.005 0.95]; end @@ -219,7 +219,7 @@ if nblck == 1 % Brooks and Gelman tests need more than one block dyn_latex_table(M_,options_,my_title,'raftery_lewis',headers,labels_Raftery_Lewis_tex,raftery_data_mat,lh,10,0); end end - + return; end diff --git a/matlab/convergence_diagnostics/geweke_chi2_test.m b/matlab/convergence_diagnostics/geweke_chi2_test.m index 7ed3831398..5009b5f26f 100644 --- a/matlab/convergence_diagnostics/geweke_chi2_test.m +++ b/matlab/convergence_diagnostics/geweke_chi2_test.m @@ -58,17 +58,17 @@ function results_struct = geweke_chi2_test(results1,results2,results_struct,opti % drew on MATLAB programs written by Siddartha Chib for k=1:length(options.convergence.geweke.taper_steps)+1; - NSE=[results1(:,3+(k-1)*2) results2(:,3+(k-1)*2)]; - means=[results1(:,1) results2(:,1)]; - diff_Means=means(:,1)-means(:,2); - sum_of_weights=sum(1./(NSE.^2),2); - pooled_mean=sum(means./(NSE.^2),2)./sum_of_weights; - pooled_NSE=1./sqrt(sum_of_weights); + NSE=[results1(:,3+(k-1)*2) results2(:,3+(k-1)*2)]; + means=[results1(:,1) results2(:,1)]; + diff_Means=means(:,1)-means(:,2); + sum_of_weights=sum(1./(NSE.^2),2); + pooled_mean=sum(means./(NSE.^2),2)./sum_of_weights; + pooled_NSE=1./sqrt(sum_of_weights); - test_stat=diff_Means.^2./sum(NSE.^2,2); - p = 1-chi2cdf(test_stat,1); - results_struct.pooled_mean(:,k) = pooled_mean; - results_struct.pooled_nse(:,k) = pooled_NSE; - results_struct.prob_chi2_test(:,k) = p; + test_stat=diff_Means.^2./sum(NSE.^2,2); + p = 1-chi2cdf(test_stat,1); + results_struct.pooled_mean(:,k) = pooled_mean; + results_struct.pooled_nse(:,k) = pooled_NSE; + results_struct.prob_chi2_test(:,k) = p; end; diff --git a/matlab/convergence_diagnostics/geweke_moments.m b/matlab/convergence_diagnostics/geweke_moments.m index 242a9d5501..eceaa7ee12 100644 --- a/matlab/convergence_diagnostics/geweke_moments.m +++ b/matlab/convergence_diagnostics/geweke_moments.m @@ -53,7 +53,7 @@ function [results_vec, results_struct] = geweke_moments(draws,Dynareoptions) % based on code by James P. LeSage, who in turn % drew on MATLAB programs written by Siddartha Chib - + ndraw = size(draws,1); n_groups=100; taper_steps=Dynareoptions.convergence.geweke.taper_steps; diff --git a/matlab/convergence_diagnostics/mcmc_ifac.m b/matlab/convergence_diagnostics/mcmc_ifac.m index 3688153f98..7f231842be 100644 --- a/matlab/convergence_diagnostics/mcmc_ifac.m +++ b/matlab/convergence_diagnostics/mcmc_ifac.m @@ -1,71 +1,71 @@ -function Ifac = mcmc_ifac(X, Nc) -% function Ifac = mcmc_ifac(X, Nc) -% Compute inefficiency factor of a MCMC sample X based on a Parzen Window -% -% INPUTS -% X: time series -% Nc: # of lags -% -% OUTPUTS -% Ifac: inefficiency factor of MCMC sample -% -% SPECIAL REQUIREMENTS -% none -% ALGORITHM: -% Inefficiency factors are computed as -% \[ -% Ifac = 1 + 2\sum\limits_{i=1}^{Nc} {\hat \rho(i)} -% \] -% where $\hat \rho(i)$ denotes the autocorrelation at lag i and the terms -% of the sum are truncated using a Parzen window. -% -% For inefficiency factors, see Section 6.1 of Paolo Giordani, Michael Pitt, and Robert Kohn (2011): -% "Bayesian Inference for Time Series State Space Models" in : John Geweke, Gary Koop, -% Herman van Dijk (editors): "The Oxford Handbook of Bayesian -% Econometrics", Oxford University Press -% -% The Parzen-Window is given by -% \[ -% k(x) = \left\{ {\begin{array}{*{20}{c}} -% {1 - 6{x^2} + 6|x|^3} \text{ for } 0 \leqslant |x| \leqslant \frac{1}{2}} \\ -% {2(1-|x|^3) \text{ for } \frac{1}{2} \leqslant |x| \leqslant 1} \\ -% {0 \text{ otherwise}} -% \end{array}} \right. -% \] -% See Donald W.K Andrews (1991): "Heteroskedasticity and autocorrelation -% consistent covariance matrix estimation", Econometrica, 59(3), p. 817-858 - - -% Copyright (C) 2015-16 Dynare Team -% -% This file is part of Dynare. -% -% Dynare is free software: you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation, either version 3 of the License, or -% (at your option) any later version. -% -% Dynare is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. -% -% You should have received a copy of the GNU General Public License -% along with Dynare. If not, see <http://www.gnu.org/licenses/>. - -Nc = floor(min(Nc, length(X)/2)); -if mod(Nc,2), - Nc=Nc-1; -end -AcorrXSIM = dyn_autocorr(X(:), Nc); -% -%Calculate the Parzen Weight -Parzen=zeros(Nc+1,1); -for i=1: Nc/2+1 - Parzen(i)=1 - 6*(i/Nc)^2+ 6*(i/Nc)^3; -end -for i=(Nc/2)+1: Nc+1 - Parzen(i)=2 * (1-(i/Nc))^3; -end -Parzen=Parzen'; -Ifac= 1+2*sum(Parzen(:).* AcorrXSIM); +function Ifac = mcmc_ifac(X, Nc) +% function Ifac = mcmc_ifac(X, Nc) +% Compute inefficiency factor of a MCMC sample X based on a Parzen Window +% +% INPUTS +% X: time series +% Nc: # of lags +% +% OUTPUTS +% Ifac: inefficiency factor of MCMC sample +% +% SPECIAL REQUIREMENTS +% none +% ALGORITHM: +% Inefficiency factors are computed as +% \[ +% Ifac = 1 + 2\sum\limits_{i=1}^{Nc} {\hat \rho(i)} +% \] +% where $\hat \rho(i)$ denotes the autocorrelation at lag i and the terms +% of the sum are truncated using a Parzen window. +% +% For inefficiency factors, see Section 6.1 of Paolo Giordani, Michael Pitt, and Robert Kohn (2011): +% "Bayesian Inference for Time Series State Space Models" in : John Geweke, Gary Koop, +% Herman van Dijk (editors): "The Oxford Handbook of Bayesian +% Econometrics", Oxford University Press +% +% The Parzen-Window is given by +% \[ +% k(x) = \left\{ {\begin{array}{*{20}{c}} +% {1 - 6{x^2} + 6|x|^3} \text{ for } 0 \leqslant |x| \leqslant \frac{1}{2}} \\ +% {2(1-|x|^3) \text{ for } \frac{1}{2} \leqslant |x| \leqslant 1} \\ +% {0 \text{ otherwise}} +% \end{array}} \right. +% \] +% See Donald W.K Andrews (1991): "Heteroskedasticity and autocorrelation +% consistent covariance matrix estimation", Econometrica, 59(3), p. 817-858 + + +% Copyright (C) 2015-16 Dynare Team +% +% This file is part of Dynare. +% +% Dynare is free software: you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation, either version 3 of the License, or +% (at your option) any later version. +% +% Dynare is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with Dynare. If not, see <http://www.gnu.org/licenses/>. + +Nc = floor(min(Nc, length(X)/2)); +if mod(Nc,2), + Nc=Nc-1; +end +AcorrXSIM = dyn_autocorr(X(:), Nc); +% +%Calculate the Parzen Weight +Parzen=zeros(Nc+1,1); +for i=1: Nc/2+1 + Parzen(i)=1 - 6*(i/Nc)^2+ 6*(i/Nc)^3; +end +for i=(Nc/2)+1: Nc+1 + Parzen(i)=2 * (1-(i/Nc))^3; +end +Parzen=Parzen'; +Ifac= 1+2*sum(Parzen(:).* AcorrXSIM); diff --git a/matlab/convergence_diagnostics/raftery_lewis.m b/matlab/convergence_diagnostics/raftery_lewis.m index c2a162d875..d6e403c5b1 100644 --- a/matlab/convergence_diagnostics/raftery_lewis.m +++ b/matlab/convergence_diagnostics/raftery_lewis.m @@ -142,17 +142,17 @@ for ind_1 = 1:2 for ind_3 = 1:2 if tran(ind_1,ind_2,ind_3) ~= 0 fitted = (tran(ind_1,ind_2,1) + tran(ind_1,ind_2,2))*(tran(1,ind_2,ind_3) + tran(2,ind_2,ind_3))/... - (tran(1,ind_2,1) + tran(1,ind_2,2) + tran(2,ind_2,1) + tran(2,ind_2,2)); + (tran(1,ind_2,1) + tran(1,ind_2,2) + tran(2,ind_2,1) + tran(2,ind_2,2)); focus = tran(ind_1,ind_2,ind_3); g2 = g2 + log(focus/fitted)*focus; end end; % end of for i3 end; % end of for i2 end; % end of for i1 -g2 = g2*2; -bic = g2 - log(n_obs-2)*2; + g2 = g2*2; + bic = g2 - log(n_obs-2)*2; -end + end function [g2, bic] = independence_chain_test(d) diff --git a/matlab/convert_dyn_45_to_44.m b/matlab/convert_dyn_45_to_44.m index ba3dbc671f..12306cccc8 100644 --- a/matlab/convert_dyn_45_to_44.m +++ b/matlab/convert_dyn_45_to_44.m @@ -147,11 +147,11 @@ end if ~isempty(options_.nk) && options_.nk ~= 0 && ~isempty(bayestopt_) if ~((any(bayestopt_.pshape > 0) && options_.mh_replic) || (any(bayestopt_.pshape> 0) && options_.load_mh_file)) %no Bayesian estimation positions_in_decision_order=oo_.dr.inv_order_var(bayestopt_.smoother_var_list(bayestopt_.smoother_saved_var_list)); - if options_.loglinear == 1 %logged steady state must be used - constant_all_variables=log(oo_.dr.ys(bayestopt_.smoother_var_list(bayestopt_.smoother_saved_var_list))); - elseif options_.loglinear == 0 %unlogged steady state must be used - constant_all_variables=oo_.dr.ys(bayestopt_.smoother_var_list(bayestopt_.smoother_saved_var_list)); - end + if options_.loglinear == 1 %logged steady state must be used + constant_all_variables=log(oo_.dr.ys(bayestopt_.smoother_var_list(bayestopt_.smoother_saved_var_list))); + elseif options_.loglinear == 0 %unlogged steady state must be used + constant_all_variables=oo_.dr.ys(bayestopt_.smoother_var_list(bayestopt_.smoother_saved_var_list)); + end if ~(options_.selected_variables_only && ~(options_.forecast > 0)) %happens only when selected_variables_only is not used oo_.FilteredVariablesKStepAhead(:,positions_in_decision_order,:)=oo_.FilteredVariablesKStepAhead-constant_all_variables; if ~isempty(PK) %get K-step ahead variances @@ -182,11 +182,11 @@ end %Deal with OSR if ~isempty(M_.osr.variable_weights) - evalin('base','optim_weights_=M_.osr.variable_weights') + evalin('base','optim_weights_=M_.osr.variable_weights') end if ~isempty(M_.osr.variable_indices) - evalin('base','obj_var_=M_.osr.variable_indices') + evalin('base','obj_var_=M_.osr.variable_indices') end if ~isempty(M_.osr.param_names) - evalin('base','osr_params_=char(M_.osr.param_names)') + evalin('base','osr_params_=char(M_.osr.param_names)') end diff --git a/matlab/convert_oo_.m b/matlab/convert_oo_.m index ef5f72280d..948fc708da 100644 --- a/matlab/convert_oo_.m +++ b/matlab/convert_oo_.m @@ -81,5 +81,5 @@ else end eval(['oo_ = convert_dyn_' strrep(new_from_ver, '.', '') '_to_' ... - strrep(to_ver, '.', '') '(M_, options_, oo_);']); + strrep(to_ver, '.', '') '(M_, options_, oo_);']); end diff --git a/matlab/covariance_mc_analysis.m b/matlab/covariance_mc_analysis.m index 60753407b4..1d0139d435 100644 --- a/matlab/covariance_mc_analysis.m +++ b/matlab/covariance_mc_analysis.m @@ -110,11 +110,11 @@ end if options_.estimation.moments_posterior_density.indicator [p_mean, p_median, p_var, hpd_interval, p_deciles, density] = ... - posterior_moments(tmp,1,mh_conf_sig); + posterior_moments(tmp,1,mh_conf_sig); oo_.([TYPE, 'TheoreticalMoments']).dsge.covariance.density.(var1).(var2) = density; else [p_mean, p_median, p_var, hpd_interval, p_deciles] = ... - posterior_moments(tmp,0,mh_conf_sig); + posterior_moments(tmp,0,mh_conf_sig); end oo_.([TYPE, 'TheoreticalMoments']).dsge.covariance.Mean.(var1).(var2) = p_mean; oo_.([TYPE, 'TheoreticalMoments']).dsge.covariance.Median.(var1).(var2) = p_median; diff --git a/matlab/cubature_with_gaussian_weight.m b/matlab/cubature_with_gaussian_weight.m index ecc69230dd..43f05b61c2 100644 --- a/matlab/cubature_with_gaussian_weight.m +++ b/matlab/cubature_with_gaussian_weight.m @@ -52,7 +52,7 @@ function [nodes, weights] = cubature_with_gaussian_weight(d,n,method) % along with Dynare. If not, see <http://www.gnu.org/licenses/>. % AUTHOR(S) stephane DOT adjemian AT univ DASH lemans DOT fr - + % Set default. if nargin<3 || isempty(method) method = 'Stroud'; @@ -117,16 +117,16 @@ end function v = e(n,i) - v = zeros(n,1); - v(i) = 1; - +v = zeros(n,1); +v(i) = 1; + function m = ee(n,i,j) - m = zeros(n,4); - m(:,1) = e(n,i)+e(n,j); - m(:,2) = e(n,i)-e(n,j); - m(:,3) = -m(:,2); - m(:,4) = -m(:,1); - +m = zeros(n,4); +m(:,1) = e(n,i)+e(n,j); +m(:,2) = e(n,i)-e(n,j); +m(:,3) = -m(:,2); +m(:,4) = -m(:,1); + %@test:1 %$ % Set problem %$ d = 4; diff --git a/matlab/datatomfile.m b/matlab/datatomfile.m index 4f6a5ff49a..c2ea03ef68 100644 --- a/matlab/datatomfile.m +++ b/matlab/datatomfile.m @@ -65,8 +65,8 @@ for i=1:n end end stack = dbstack; - fprintf(fid,'%% Dataset generated by %s.\n',stack(2).file); - fprintf(fid,['%% ' datestr(now,0) '\n']); +fprintf(fid,'%% Dataset generated by %s.\n',stack(2).file); +fprintf(fid,['%% ' datestr(now,0) '\n']); % Save the selected data. for i = 1:n fprintf(fid,[strtrim(names(i,:)), ' = ['],'\n') ; diff --git a/matlab/delete_mh_history_files.m b/matlab/delete_mh_history_files.m index 64b720ec9b..635bb9c94d 100644 --- a/matlab/delete_mh_history_files.m +++ b/matlab/delete_mh_history_files.m @@ -1,5 +1,5 @@ function info = delete_mh_history_files(MetropolisFolder, ModelName) - + % Copyright (C) 2013 Dynare Team % % This file is part of Dynare. diff --git a/matlab/discretionary_policy_1.m b/matlab/discretionary_policy_1.m index 931d3b596f..09584e8642 100644 --- a/matlab/discretionary_policy_1.m +++ b/matlab/discretionary_policy_1.m @@ -39,7 +39,7 @@ if isfield(M_,'orig_model') M_.maximum_lag = orig_model.maximum_lag; M_.maximum_endo_lag = orig_model.maximum_endo_lag; else - M_.orig_model = M_; + M_.orig_model = M_; end beta = get_optimal_policy_discount_factor(M_.params,M_.param_names); @@ -53,10 +53,10 @@ if isfield(M_,'orig_model') MaxLead = orig_model.maximum_lead; MaxLag = orig_model.maximum_lag; else - endo_names = M_.endo_names; - endo_nbr = M_.endo_nbr; - MaxLag=M_.maximum_lag; - MaxLead=M_.maximum_lead; + endo_names = M_.endo_names; + endo_nbr = M_.endo_nbr; + MaxLag=M_.maximum_lag; + MaxLead=M_.maximum_lead; lead_lag_incidence = M_.lead_lag_incidence; end @@ -64,7 +64,7 @@ end if options_.steadystate_flag % explicit steady state file [junk,M_.params,info] = evaluate_steady_state_file(oo_.steady_state,[oo_.exo_steady_state; oo_.exo_det_steady_state],M_, ... - options_,0); + options_,0); end [U,Uy,W] = feval([M_.fname,'_objective_static'],zeros(endo_nbr,1),[], M_.params); if any(any(Uy~=0)) @@ -99,29 +99,29 @@ if instr_nbr==0 error('discretionary_policy:: There are no available instruments, because the model has as many equations as variables.') end if size(Instruments,1)~= instr_nbr - error('discretionary_policy:: There are more declared instruments than omitted equations.') + error('discretionary_policy:: There are more declared instruments than omitted equations.') end instr_id=nan(instr_nbr,1); for j=1:instr_nbr - vj=deblank(Instruments(j,:)); - vj_id=strmatch(vj,endo_names,'exact'); - if ~isempty(vj_id) - instr_id(j)=vj_id; - else - error([mfilename,':: instrument ',vj,' not found']) - end + vj=deblank(Instruments(j,:)); + vj_id=strmatch(vj,endo_names,'exact'); + if ~isempty(vj_id) + instr_id(j)=vj_id; + else + error([mfilename,':: instrument ',vj,' not found']) + end end Indices={'lag','0','lead'}; iter=1; for j=1:numel(Indices) eval(['A',Indices{j},'=zeros(eq_nbr,endo_nbr);']) - if strcmp(Indices{j},'0')||(strcmp(Indices{j},'lag') && MaxLag)||(strcmp(Indices{j},'lead') && MaxLead) - [junk,row,col]=find(lead_lag_incidence(iter,:)); - eval(['A',Indices{j},'(:,row)=jacobia_(:,col);']) - iter=iter+1; - end + if strcmp(Indices{j},'0')||(strcmp(Indices{j},'lag') && MaxLag)||(strcmp(Indices{j},'lead') && MaxLead) + [junk,row,col]=find(lead_lag_incidence(iter,:)); + eval(['A',Indices{j},'(:,row)=jacobia_(:,col);']) + iter=iter+1; + end end B=jacobia_(:,nnz(iyv)+1:end); @@ -131,17 +131,17 @@ solve_maxit = options_.dp.maxit; discretion_tol = options_.discretionary_tol; if ~isempty(Hold) - [H,G,info]=discretionary_policy_engine(Alag,A0,Alead,B,W,instr_id,beta,solve_maxit,discretion_tol,qz_criterium,Hold); + [H,G,info]=discretionary_policy_engine(Alag,A0,Alead,B,W,instr_id,beta,solve_maxit,discretion_tol,qz_criterium,Hold); else - [H,G,info]=discretionary_policy_engine(Alag,A0,Alead,B,W,instr_id,beta,solve_maxit,discretion_tol,qz_criterium); + [H,G,info]=discretionary_policy_engine(Alag,A0,Alead,B,W,instr_id,beta,solve_maxit,discretion_tol,qz_criterium); end if info dr=[]; return else - Hold=H; %save previous solution - % Hold=[]; use this line if persistent command is not used. + Hold=H; %save previous solution + % Hold=[]; use this line if persistent command is not used. end % set the state dr=oo_.dr; @@ -159,7 +159,7 @@ dr.ys=ys; % <--- dr.ys =zeros(NewEndo_nbr,1); function ys=NondistortionarySteadyState(M_) if exist([M_.fname,'_steadystate.m'],'file') - eval(['ys=',M_.fname,'_steadystate.m;']) + eval(['ys=',M_.fname,'_steadystate.m;']) else - ys=zeros(M_.endo_nbr,1); + ys=zeros(M_.endo_nbr,1); end diff --git a/matlab/discretionary_policy_engine.m b/matlab/discretionary_policy_engine.m index 154b66426e..7189dabef4 100644 --- a/matlab/discretionary_policy_engine.m +++ b/matlab/discretionary_policy_engine.m @@ -253,7 +253,7 @@ end function v = SylvesterHessenbergSchur(d,g,h) % -% DSYLHS Solves a discrete time sylvester equation using the +% DSYLHS Solves a discrete time sylvester equation using the % Hessenberg-Schur algorithm % % v = DSYLHS(g,d,h) computes the matrix v that satisfies the @@ -301,7 +301,7 @@ if i< n, i = i+1; else A = [w-g*h(i,i) (-g*h(i+1,i));... - -g*h(i,i+1) w-g*h(i+1,i+1)]; + -g*h(i,i+1) w-g*h(i+1,i+1)]; C = [d(:,i); d(:,i+1)]; X = A\C; v(:,i) = X(1:m,:); @@ -320,9 +320,9 @@ while i<n, i = i+1; else A = [w - g*h(i,i) (-g*h(i+1,i)); ... - -g*h(i,i+1) w - g*h(i+1,i+1)]; + -g*h(i,i+1) w - g*h(i+1,i+1)]; C = [d(:,i) + temp*h(1:b,i); ... - d(:,i+1) + temp*h(1:b,i+1)]; + d(:,i+1) + temp*h(1:b,i+1)]; X = A\C; v(:,i) = X(1:m,:); v(:,i+1) = X(m+1:2*m, :); diff --git a/matlab/disp_dr.m b/matlab/disp_dr.m index a23c8f4be2..673838a6e6 100644 --- a/matlab/disp_dr.m +++ b/matlab/disp_dr.m @@ -256,10 +256,10 @@ error(sprintf('Could not find aux var: %s', M_.endo_names(aux_index, :))) end function [str,flag]=get_print_string(str,x,value_format_zero,value_format_float,flag,options_) - if abs(x) >= options_.dr_display_tol - flag = 1; - str = [str sprintf(value_format_float,x)]; - else - str = [str sprintf(value_format_zero,0)]; - end +if abs(x) >= options_.dr_display_tol + flag = 1; + str = [str sprintf(value_format_float,x)]; +else + str = [str sprintf(value_format_zero,0)]; +end end \ No newline at end of file diff --git a/matlab/disp_identification.m b/matlab/disp_identification.m index 5bdb3e8e55..6f89e429d6 100644 --- a/matlab/disp_identification.m +++ b/matlab/disp_identification.m @@ -133,23 +133,23 @@ if any(idemodel.ino), end end end -% if npar>(j+1), -% [ipair, jpair] = find(squeeze(idemodel.Pco(j,j+1:end,:))'>(1-1.e-10)); -% else -% [ipair, jpair] = find(squeeze(idemodel.Pco(j,j+1:end,:))>(1-1.e-10)); -% end -% if ~isempty(jpair), -% for jx=j+1:npar, -% ixp = find(jx==(jpair+j)); -% if ~isempty(ixp) -% if SampleSize > 1, -% disp([' [',name{j},',',name{jx},'] are PAIRWISE collinear (with tol = 1.e-10) for ',num2str(length(ixp)/SampleSize*100),'% of MC runs!' ]) -% else -% disp([' [',name{j},',',name{jx},'] are PAIRWISE collinear (with tol = 1.e-10)!' ]) -% end -% end -% end -% end + % if npar>(j+1), + % [ipair, jpair] = find(squeeze(idemodel.Pco(j,j+1:end,:))'>(1-1.e-10)); + % else + % [ipair, jpair] = find(squeeze(idemodel.Pco(j,j+1:end,:))>(1-1.e-10)); + % end + % if ~isempty(jpair), + % for jx=j+1:npar, + % ixp = find(jx==(jpair+j)); + % if ~isempty(ixp) + % if SampleSize > 1, + % disp([' [',name{j},',',name{jx},'] are PAIRWISE collinear (with tol = 1.e-10) for ',num2str(length(ixp)/SampleSize*100),'% of MC runs!' ]) + % else + % disp([' [',name{j},',',name{jx},'] are PAIRWISE collinear (with tol = 1.e-10)!' ]) + % end + % end + % end + % end end if ~any(idemodel.ino) && ~any(any(idemodel.ind0==0)) @@ -167,10 +167,10 @@ if any(idemoments.ino), end % disp('WARNING !!!') % disp(['The rank of J (moments) is deficient for ', num2str(length(find(idemoments.ino))/SampleSize*100),'% of MC runs!' ]), -% indno=[]; -% for j=1:SampleSize, indno=[indno;idemoments.indno{j}]; end -% freqno = mean(indno)*100; -% ifreq=find(freqno); + % indno=[]; + % for j=1:SampleSize, indno=[indno;idemoments.indno{j}]; end + % freqno = mean(indno)*100; + % ifreq=find(freqno); % disp('MOMENT RANK FAILURE DUE TO COLLINEARITY OF PARAMETERS:'); skipline() for j=1:npar, @@ -214,25 +214,25 @@ if any(idemoments.ino), end end end -% if npar>(j+1), -% [ipair, jpair] = find(squeeze(idemoments.Pco(j,j+1:end,:))'>(1-1.e-10)); -% else -% [ipair, jpair] = find(squeeze(idemoments.Pco(j,j+1:end,:))>(1-1.e-10)); -% end -% if ~isempty(jpair), -% for jx=j+1:npar, -% ixp = find(jx==(jpair+j)); -% if ~isempty(ixp) -% if SampleSize > 1 -% disp([' [',name{j},',',name{jx},'] are PAIRWISE collinear (with tol = 1.e-10) for ',num2str(length(ixp)/SampleSize*100),'% of MC runs!' ]) -% else -% disp([' [',name{j},',',name{jx},'] are PAIRWISE collinear (with tol = 1.e-10) !' ]) -% end -% end -% end -% end -% end -% end + % if npar>(j+1), + % [ipair, jpair] = find(squeeze(idemoments.Pco(j,j+1:end,:))'>(1-1.e-10)); + % else + % [ipair, jpair] = find(squeeze(idemoments.Pco(j,j+1:end,:))>(1-1.e-10)); + % end + % if ~isempty(jpair), + % for jx=j+1:npar, + % ixp = find(jx==(jpair+j)); + % if ~isempty(ixp) + % if SampleSize > 1 + % disp([' [',name{j},',',name{jx},'] are PAIRWISE collinear (with tol = 1.e-10) for ',num2str(length(ixp)/SampleSize*100),'% of MC runs!' ]) + % else + % disp([' [',name{j},',',name{jx},'] are PAIRWISE collinear (with tol = 1.e-10) !' ]) + % end + % end + % end + % end + % end + % end end if ~any(idemoments.ino) && ~any(any(idemoments.ind0==0)) skipline() diff --git a/matlab/disp_moments.m b/matlab/disp_moments.m index 07e4b3c7d3..8bbf1f567c 100644 --- a/matlab/disp_moments.m +++ b/matlab/disp_moments.m @@ -98,7 +98,7 @@ if options_.nocorr == 0 end if options_.noprint == 0 && length(options_.conditional_variance_decomposition) - fprintf('\nSTOCH_SIMUL: conditional_variance_decomposition requires theoretical moments, i.e. periods=0.\n') + fprintf('\nSTOCH_SIMUL: conditional_variance_decomposition requires theoretical moments, i.e. periods=0.\n') end ar = options_.ar; @@ -156,7 +156,7 @@ if ~options_.nodecomposition if ~options_.noprint %options_.nomoments == 0 skipline() title='VARIANCE DECOMPOSITION SIMULATING ONE SHOCK AT A TIME (in percent)'; - + title=add_filter_subtitle(title,options_); headers = M_.exo_names; @@ -181,12 +181,12 @@ if ~options_.nodecomposition end end - + warning(warning_old_state); end function y=get_filtered_time_series(y,m,options_) - + if options_.hp_filter && ~options_.one_sided_hp_filter && ~options_.bandpass.indicator [hptrend,y] = sample_hp_filter(y,options_.hp_filter); elseif ~options_.hp_filter && options_.one_sided_hp_filter && ~options_.bandpass.indicator @@ -200,5 +200,5 @@ elseif ~options_.hp_filter && ~options_.one_sided_hp_filter && ~options_.bandpa else error('disp_moments:: You cannot use more than one filter at the same time') end - + end \ No newline at end of file diff --git a/matlab/disp_th_moments.m b/matlab/disp_th_moments.m index 45d217611c..77e38c5e75 100644 --- a/matlab/disp_th_moments.m +++ b/matlab/disp_th_moments.m @@ -86,7 +86,7 @@ if size(stationary_vars, 1) > 0 headers = char(' ',headers); lh = size(deblank(M_.endo_names(ivar(stationary_vars),:)),2)+2; dyntable(options_,title,headers,deblank(M_.endo_names(ivar(stationary_vars), ... - :)),100* ... + :)),100* ... oo_.gamma_y{options_.ar+2}(stationary_vars,:),lh,8,2); if options_.TeX headers=M_.exo_names_tex; @@ -110,7 +110,7 @@ if size(stationary_vars, 1) > 0 if options_.noprint == 0 display_conditional_variance_decomposition(oo_.conditional_variance_decomposition,conditional_variance_steps,... - ivar,M_,options_); + ivar,M_,options_); end end end diff --git a/matlab/display_conditional_variance_decomposition.m b/matlab/display_conditional_variance_decomposition.m index 597aa0b1b9..2a82c7e2fd 100644 --- a/matlab/display_conditional_variance_decomposition.m +++ b/matlab/display_conditional_variance_decomposition.m @@ -56,10 +56,10 @@ for i=1:length(Steps) dyntable(options_,'',headers,... deblank(M_.endo_names(SubsetOfVariables,:)),... vardec_i,lh,8,2); - if options_.TeX - labels_TeX = deblank(M_.endo_names_tex(SubsetOfVariables,:)); - headers_TeX=char('',deblank(M_.exo_names_tex)); - lh = size(labels_TeX,2)+2; - dyn_latex_table(M_,options_,[title,'; Period ' int2str(Steps(i))],['th_var_decomp_cond_h',int2str(Steps(i))],headers_TeX,labels_TeX,vardec_i,lh,8,2); - end + if options_.TeX + labels_TeX = deblank(M_.endo_names_tex(SubsetOfVariables,:)); + headers_TeX=char('',deblank(M_.exo_names_tex)); + lh = size(labels_TeX,2)+2; + dyn_latex_table(M_,options_,[title,'; Period ' int2str(Steps(i))],['th_var_decomp_cond_h',int2str(Steps(i))],headers_TeX,labels_TeX,vardec_i,lh,8,2); + end end \ No newline at end of file diff --git a/matlab/display_estimation_results_table.m b/matlab/display_estimation_results_table.m index 152ea006b9..52ffacfda6 100644 --- a/matlab/display_estimation_results_table.m +++ b/matlab/display_estimation_results_table.m @@ -64,13 +64,13 @@ if np name = bayestopt_.name{ip}; if strcmp(field_name,'posterior') fprintf('%-*s %7.3f %8.4f %7.4f %4s %6.4f \n', ... - header_width,name, ... - bayestopt_.p1(ip),xparam1(ip),stdh(ip), ... - pnames(bayestopt_.pshape(ip)+1,:), ... - bayestopt_.p2(ip)); + header_width,name, ... + bayestopt_.p1(ip),xparam1(ip),stdh(ip), ... + pnames(bayestopt_.pshape(ip)+1,:), ... + bayestopt_.p2(ip)); else fprintf('%-*s %8.4f %7.4f %7.4f \n', ... - header_width,name,xparam1(ip),stdh(ip),tstath(ip)); + header_width,name,xparam1(ip),stdh(ip),tstath(ip)); end eval(['oo_.' field_name '_mode.parameters.' name ' = xparam1(ip);']); eval(['oo_.' field_name '_std_at_mode.parameters.' name ' = stdh(ip);']); @@ -87,9 +87,9 @@ if nvx name = deblank(M_.exo_names(k,:)); if strcmp(field_name,'posterior') fprintf('%-*s %7.3f %8.4f %7.4f %4s %6.4f \n', ... - header_width,name,bayestopt_.p1(ip),xparam1(ip), ... - stdh(ip),pnames(bayestopt_.pshape(ip)+1,:), ... - bayestopt_.p2(ip)); + header_width,name,bayestopt_.p1(ip),xparam1(ip), ... + stdh(ip),pnames(bayestopt_.pshape(ip)+1,:), ... + bayestopt_.p2(ip)); else fprintf('%-*s %8.4f %7.4f %7.4f \n',header_width,name,xparam1(ip),stdh(ip),tstath(ip)); end @@ -99,8 +99,8 @@ if nvx ip = ip+1; end skipline() - end - if nvn +end +if nvn disp('standard deviation of measurement errors') disp(tit1) ip = nvx+1; @@ -108,10 +108,10 @@ if nvx name = options_.varobs{estim_params_.nvn_observable_correspondence(i,1)}; if strcmp(field_name,'posterior') fprintf('%-*s %7.3f %8.4f %7.4f %4s %6.4f \n', ... - header_width,name,bayestopt_.p1(ip), ... - xparam1(ip),stdh(ip), ... - pnames(bayestopt_.pshape(ip)+1,:), ... - bayestopt_.p2(ip)); + header_width,name,bayestopt_.p1(ip), ... + xparam1(ip),stdh(ip), ... + pnames(bayestopt_.pshape(ip)+1,:), ... + bayestopt_.p2(ip)); else fprintf('%-*s %8.4f %7.4f %7.4f \n',header_width,name,xparam1(ip),stdh(ip),tstath(ip)) end @@ -120,7 +120,7 @@ if nvx ip = ip+1; end skipline() - end +end if ncx disp('correlation of shocks') @@ -133,8 +133,8 @@ if ncx NAME = [deblank(M_.exo_names(k1,:)) '_' deblank(M_.exo_names(k2,:))]; if strcmp(field_name,'posterior') fprintf('%-*s %7.3f %8.4f %7.4f %4s %6.4f \n', ... - header_width,name,bayestopt_.p1(ip),xparam1(ip),stdh(ip), ... - pnames(bayestopt_.pshape(ip)+1,:), bayestopt_.p2(ip)); + header_width,name,bayestopt_.p1(ip),xparam1(ip),stdh(ip), ... + pnames(bayestopt_.pshape(ip)+1,:), bayestopt_.p2(ip)); else fprintf('%-*s %8.4f %7.4f %7.4f \n', header_width,name,xparam1(ip),stdh(ip),tstath(ip)); end @@ -158,8 +158,8 @@ if ncn NAME = [deblank(M_.endo_names(k1,:)) '_' deblank(M_.endo_names(k2,:))]; if strcmp(field_name,'posterior') fprintf('%-*s %7.3f %8.4f %7.4f %4s %6.4f \n', ... - header_width,name,bayestopt_.p1(ip),xparam1(ip),stdh(ip), ... - pnames(bayestopt_.pshape(ip)+1,:), bayestopt_.p2(ip)); + header_width,name,bayestopt_.p1(ip),xparam1(ip),stdh(ip), ... + pnames(bayestopt_.pshape(ip)+1,:), bayestopt_.p2(ip)); else fprintf('%-*s %8.4f %7.4f %7.4f \n',header_width,name,xparam1(ip),stdh(ip),tstath(ip)); end @@ -305,8 +305,8 @@ elseif all(bayestopt_.pshape == 0) && options_.TeX %% MLE and GMM Latex output TeXBegin_ML(fidTeX,3,'standard deviation of measurement errors',table_title,LaTeXtitle) ip = nvx+1; for i=1:nvn - idx = strmatch(options_.varobs{estim_params_.nvn_observable_correspondence(i,1)},M_.endo_names); - fprintf(fidTeX,'$%s$ & %8.4f & %7.4f & %7.4f \\\\ \n',... + idx = strmatch(options_.varobs{estim_params_.nvn_observable_correspondence(i,1)},M_.endo_names); + fprintf(fidTeX,'$%s$ & %8.4f & %7.4f & %7.4f \\\\ \n',... deblank(M_.endo_names_tex(idx,:)), ... xparam1(ip),... stdh(ip),... @@ -347,7 +347,7 @@ elseif all(bayestopt_.pshape == 0) && options_.TeX %% MLE and GMM Latex output tstath(ip)); ip = ip+1; end - TeXEnd(fidTeX) + TeXEnd(fidTeX) end end @@ -356,49 +356,49 @@ end %% subfunctions: % function TeXBegin_Bayesian(fid,fnum,title) - fprintf(fid,'%% TeX-table generated by dynare_estimation (Dynare).\n'); - fprintf(fid,['%% RESULTS FROM POSTERIOR MAXIMIZATION (' title ')\n']); - fprintf(fid,['%% ' datestr(now,0)]); - fprintf(fid,' \n'); - fprintf(fid,' \n'); - fprintf(fid,'\\begin{center}\n'); - fprintf(fid,'\\begin{longtable}{llcccc} \n'); - fprintf(fid,['\\caption{Results from posterior maximization (' title ')}\\\\\n ']); - fprintf(fid,['\\label{Table:Posterior:' int2str(fnum) '}\\\\\n']); - fprintf(fid,'\\toprule \n'); - fprintf(fid,' & \\multicolumn{3}{c}{Prior} & \\multicolumn{2}{c}{Posterior} \\\\\n'); - fprintf(fid,' \\cmidrule(r{.75em}){2-4} \\cmidrule(r{.75em}){5-6}\n'); - fprintf(fid,' & Dist. & Mean & Stdev & Mode & Stdev \\\\ \n'); - fprintf(fid,'\\midrule \\endfirsthead \n'); - fprintf(fid,'\\caption{(continued)}\\\\\n '); - fprintf(fid,'\\bottomrule \n'); - fprintf(fid,' & \\multicolumn{3}{c}{Prior} & \\multicolumn{2}{c}{Posterior} \\\\\n'); - fprintf(fid,' \\cmidrule(r{.75em}){2-4} \\cmidrule(r{.75em}){5-6}\n'); - fprintf(fid,' & Dist. & Mean & Stdev & Mode & Stdev \\\\ \n'); - fprintf(fid,'\\midrule \\endhead \n'); - fprintf(fid,'\\bottomrule \\multicolumn{6}{r}{(Continued on next page)}\\endfoot \n'); - fprintf(fid,'\\bottomrule\\endlastfoot \n'); +fprintf(fid,'%% TeX-table generated by dynare_estimation (Dynare).\n'); +fprintf(fid,['%% RESULTS FROM POSTERIOR MAXIMIZATION (' title ')\n']); +fprintf(fid,['%% ' datestr(now,0)]); +fprintf(fid,' \n'); +fprintf(fid,' \n'); +fprintf(fid,'\\begin{center}\n'); +fprintf(fid,'\\begin{longtable}{llcccc} \n'); +fprintf(fid,['\\caption{Results from posterior maximization (' title ')}\\\\\n ']); +fprintf(fid,['\\label{Table:Posterior:' int2str(fnum) '}\\\\\n']); +fprintf(fid,'\\toprule \n'); +fprintf(fid,' & \\multicolumn{3}{c}{Prior} & \\multicolumn{2}{c}{Posterior} \\\\\n'); +fprintf(fid,' \\cmidrule(r{.75em}){2-4} \\cmidrule(r{.75em}){5-6}\n'); +fprintf(fid,' & Dist. & Mean & Stdev & Mode & Stdev \\\\ \n'); +fprintf(fid,'\\midrule \\endfirsthead \n'); +fprintf(fid,'\\caption{(continued)}\\\\\n '); +fprintf(fid,'\\bottomrule \n'); +fprintf(fid,' & \\multicolumn{3}{c}{Prior} & \\multicolumn{2}{c}{Posterior} \\\\\n'); +fprintf(fid,' \\cmidrule(r{.75em}){2-4} \\cmidrule(r{.75em}){5-6}\n'); +fprintf(fid,' & Dist. & Mean & Stdev & Mode & Stdev \\\\ \n'); +fprintf(fid,'\\midrule \\endhead \n'); +fprintf(fid,'\\bottomrule \\multicolumn{6}{r}{(Continued on next page)}\\endfoot \n'); +fprintf(fid,'\\bottomrule\\endlastfoot \n'); + +function TeXBegin_ML(fid,fnum,title,table_title,LaTeXtitle) +fprintf(fid,'%% TeX-table generated by dynare_estimation (Dynare).\n'); +fprintf(fid,['%% RESULTS FROM ' table_title ' MAXIMIZATION (' title ')\n']); +fprintf(fid,['%% ' datestr(now,0)]); +fprintf(fid,' \n'); +fprintf(fid,' \n'); +fprintf(fid,'\\begin{center}\n'); +fprintf(fid,'\\begin{longtable}{llcc} \n'); +fprintf(fid,['\\caption{Results from ' table_title ' maximization (' title ')}\\\\\n ']); +fprintf(fid,['\\label{Table:' LaTeXtitle ':' int2str(fnum) '}\\\\\n']); +fprintf(fid,'\\toprule \n'); +fprintf(fid,' & Mode & s.d. & t-stat\\\\ \n'); +fprintf(fid,'\\midrule \\endfirsthead \n'); +fprintf(fid,'\\caption{(continued)}\\\\\n '); +fprintf(fid,'\\toprule \n'); +fprintf(fid,' & Mode & s.d. & t-stat\\\\ \n'); +fprintf(fid,'\\midrule \\endhead \n'); +fprintf(fid,'\\bottomrule \\multicolumn{4}{r}{(Continued on next page)} \\endfoot \n'); +fprintf(fid,'\\bottomrule \\endlastfoot \n'); - function TeXBegin_ML(fid,fnum,title,table_title,LaTeXtitle) - fprintf(fid,'%% TeX-table generated by dynare_estimation (Dynare).\n'); - fprintf(fid,['%% RESULTS FROM ' table_title ' MAXIMIZATION (' title ')\n']); - fprintf(fid,['%% ' datestr(now,0)]); - fprintf(fid,' \n'); - fprintf(fid,' \n'); - fprintf(fid,'\\begin{center}\n'); - fprintf(fid,'\\begin{longtable}{llcc} \n'); - fprintf(fid,['\\caption{Results from ' table_title ' maximization (' title ')}\\\\\n ']); - fprintf(fid,['\\label{Table:' LaTeXtitle ':' int2str(fnum) '}\\\\\n']); - fprintf(fid,'\\toprule \n'); - fprintf(fid,' & Mode & s.d. & t-stat\\\\ \n'); - fprintf(fid,'\\midrule \\endfirsthead \n'); - fprintf(fid,'\\caption{(continued)}\\\\\n '); - fprintf(fid,'\\toprule \n'); - fprintf(fid,' & Mode & s.d. & t-stat\\\\ \n'); - fprintf(fid,'\\midrule \\endhead \n'); - fprintf(fid,'\\bottomrule \\multicolumn{4}{r}{(Continued on next page)} \\endfoot \n'); - fprintf(fid,'\\bottomrule \\endlastfoot \n'); - function TeXEnd(fid) fprintf(fid,'\\end{longtable}\n '); fprintf(fid,'\\end{center}\n'); diff --git a/matlab/display_problematic_vars_Jacobian.m b/matlab/display_problematic_vars_Jacobian.m index a4278208b7..26cfef4523 100644 --- a/matlab/display_problematic_vars_Jacobian.m +++ b/matlab/display_problematic_vars_Jacobian.m @@ -62,25 +62,25 @@ if strcmp(type,'dynamic') fprintf('Derivative of Equation %d with respect to %s Variable %s (initial value of %s: %g) \n',eq_nbr,type_string,deblank(M_.endo_names(var_index,:)),deblank(M_.endo_names(var_index,:)),x(var_index)) end elseif problemcol(ii)<=max(max(M_.lead_lag_incidence)) && var_index>M_.orig_endo_nbr %auxiliary vars - if M_.aux_vars(1,problemcol(ii)-M_.orig_endo_nbr).type ==6 %Ramsey Lagrange Multiplier - if problemrow(ii)<=aux_eq_nbr - eq_nbr=problemrow(ii); - fprintf('Derivative of Auxiliary Equation %d with respect to %s of Langrange multiplier of equation %s (initial value: %g) \n',eq_nbr,type_string,M_.aux_vars(1,problemcol(ii)-M_.orig_endo_nbr).eq_nbr,x(problemcol(ii))) - else - eq_nbr=problemrow(ii)-aux_eq_nbr; - fprintf('Derivative of Equation %d with respect to %s of Langrange multiplier of equation %s (initial value: %g) \n',eq_nbr,type_string,M_.aux_vars(1,problemcol(ii)-M_.orig_endo_nbr).eq_nbr,x(problemcol(ii))) - end + if M_.aux_vars(1,problemcol(ii)-M_.orig_endo_nbr).type ==6 %Ramsey Lagrange Multiplier + if problemrow(ii)<=aux_eq_nbr + eq_nbr=problemrow(ii); + fprintf('Derivative of Auxiliary Equation %d with respect to %s of Langrange multiplier of equation %s (initial value: %g) \n',eq_nbr,type_string,M_.aux_vars(1,problemcol(ii)-M_.orig_endo_nbr).eq_nbr,x(problemcol(ii))) else - if problemrow(ii)<=aux_eq_nbr - eq_nbr=problemrow(ii); - orig_var_index=M_.aux_vars(1,var_index-M_.orig_endo_nbr).orig_index; - fprintf('Derivative of Auxiliary Equation %d with respect to %s Variable %s (initial value of %s: %g) \n',eq_nbr,type_string,deblank(M_.endo_names(orig_var_index,:)),deblank(M_.endo_names(orig_var_index,:)),x(orig_var_index)) - else - eq_nbr=problemrow(ii)-aux_eq_nbr; - orig_var_index=M_.aux_vars(1,var_index-M_.orig_endo_nbr).orig_index; - fprintf('Derivative of Equation %d with respect to %s Variable %s (initial value of %s: %g) \n',eq_nbr,type_string,deblank(M_.endo_names(orig_var_index,:)),deblank(M_.endo_names(orig_var_index,:)),x(orig_var_index)) - end + eq_nbr=problemrow(ii)-aux_eq_nbr; + fprintf('Derivative of Equation %d with respect to %s of Langrange multiplier of equation %s (initial value: %g) \n',eq_nbr,type_string,M_.aux_vars(1,problemcol(ii)-M_.orig_endo_nbr).eq_nbr,x(problemcol(ii))) end + else + if problemrow(ii)<=aux_eq_nbr + eq_nbr=problemrow(ii); + orig_var_index=M_.aux_vars(1,var_index-M_.orig_endo_nbr).orig_index; + fprintf('Derivative of Auxiliary Equation %d with respect to %s Variable %s (initial value of %s: %g) \n',eq_nbr,type_string,deblank(M_.endo_names(orig_var_index,:)),deblank(M_.endo_names(orig_var_index,:)),x(orig_var_index)) + else + eq_nbr=problemrow(ii)-aux_eq_nbr; + orig_var_index=M_.aux_vars(1,var_index-M_.orig_endo_nbr).orig_index; + fprintf('Derivative of Equation %d with respect to %s Variable %s (initial value of %s: %g) \n',eq_nbr,type_string,deblank(M_.endo_names(orig_var_index,:)),deblank(M_.endo_names(orig_var_index,:)),x(orig_var_index)) + end + end elseif problemcol(ii)>max(max(M_.lead_lag_incidence)) && var_index<=M_.exo_nbr if problemrow(ii)<=aux_eq_nbr eq_nbr=problemrow(ii); @@ -117,15 +117,15 @@ elseif strcmp(type,'static') fprintf('Derivative of Equation %d with respect to Lagrange multiplier of equation %d (initial value: %g) \n',eq_nbr,M_.aux_vars(1,problemcol(ii)-M_.orig_endo_nbr).eq_nbr,x(problemcol(ii))) end else - if problemrow(ii)<=aux_eq_nbr - eq_nbr=problemrow(ii); - orig_var_index=M_.aux_vars(1,problemcol(ii)-M_.orig_endo_nbr).orig_index; - fprintf('Derivative of Auxiliary Equation %d with respect to Variable %s (initial value of %s: %g) \n',eq_nbr,deblank(M_.endo_names(orig_var_index,:)),deblank(M_.endo_names(orig_var_index,:)),x(problemcol(ii))) - else - eq_nbr=problemrow(ii)-aux_eq_nbr; - orig_var_index=M_.aux_vars(1,problemcol(ii)-M_.orig_endo_nbr).orig_index; - fprintf('Derivative of Equation %d with respect to Variable %s (initial value of %s: %g) \n',eq_nbr,deblank(M_.endo_names(orig_var_index,:)),deblank(M_.endo_names(orig_var_index,:)),x(problemcol(ii))) - end + if problemrow(ii)<=aux_eq_nbr + eq_nbr=problemrow(ii); + orig_var_index=M_.aux_vars(1,problemcol(ii)-M_.orig_endo_nbr).orig_index; + fprintf('Derivative of Auxiliary Equation %d with respect to Variable %s (initial value of %s: %g) \n',eq_nbr,deblank(M_.endo_names(orig_var_index,:)),deblank(M_.endo_names(orig_var_index,:)),x(problemcol(ii))) + else + eq_nbr=problemrow(ii)-aux_eq_nbr; + orig_var_index=M_.aux_vars(1,problemcol(ii)-M_.orig_endo_nbr).orig_index; + fprintf('Derivative of Equation %d with respect to Variable %s (initial value of %s: %g) \n',eq_nbr,deblank(M_.endo_names(orig_var_index,:)),deblank(M_.endo_names(orig_var_index,:)),x(problemcol(ii))) + end end end end diff --git a/matlab/distributions/lpdfgweibull.m b/matlab/distributions/lpdfgweibull.m index 3f2df819d2..e8ca18c2e8 100644 --- a/matlab/distributions/lpdfgweibull.m +++ b/matlab/distributions/lpdfgweibull.m @@ -77,7 +77,7 @@ if isempty(idx), return, end jdx = find( abs(a-1)<1e-12 & x>=c & (x-c)<1e-12) ; ldens(jdx) = 1.0; - + if ~isempty(idx) x0 = x(idx)-c(idx); x1 = x0./b(idx); diff --git a/matlab/dr_block.m b/matlab/dr_block.m index 47c20add23..d2e35a1057 100644 --- a/matlab/dr_block.m +++ b/matlab/dr_block.m @@ -54,7 +54,7 @@ function [dr,info,M_,options_,oo_] = dr_block(dr,task,M_,options_,oo_,varargin) info = 0; verbose = 0; if nargin > 5 - verbose = varargin{1}; + verbose = varargin{1}; end %verbose = options_.verbosity; if options_.order > 1 @@ -134,7 +134,7 @@ for i = 1:Size; end; switch block_type case 1 - %% ------------------------------------------------------------------ + %% ------------------------------------------------------------------ %Evaluate Forward if maximum_lag > 0 && n_pred > 0 indx_r = find(M_.block_structure.block(i).lead_lag_incidence(1,:)); @@ -175,7 +175,7 @@ for i = 1:Size; l_x_sv = dr.ghx(dr.state_var, 1:n_sv); selector_tm1 = M_.block_structure.block(i).tm1; - + ghx_other = - B \ (fx_t * l_x + (fx_tp1 * l_x * l_x_sv) + fx_tm1 * selector_tm1); dr.ghx(endo, :) = dr.ghx(endo, :) + ghx_other; end; @@ -198,17 +198,17 @@ for i = 1:Size; else exo = dr.exo_var; if other_endo_nbr > 0 - l_u_sv = dr.ghu(dr.state_var,:); - l_x = dr.ghx(data(i).other_endogenous,:); - l_u = dr.ghu(data(i).other_endogenous,:); - ghu = -B \ (fx_tp1 * l_x * l_u_sv + (fx_t) * l_u ); + l_u_sv = dr.ghu(dr.state_var,:); + l_x = dr.ghx(data(i).other_endogenous,:); + l_u = dr.ghu(data(i).other_endogenous,:); + ghu = -B \ (fx_tp1 * l_x * l_u_sv + (fx_t) * l_u ); else ghu = []; end end end case 2 - %% ------------------------------------------------------------------ + %% ------------------------------------------------------------------ %Evaluate Backward if maximum_lead > 0 && n_fwrd > 0 indx_r = find(M_.block_structure.block(i).lead_lag_incidence(3,:)); @@ -233,7 +233,7 @@ for i = 1:Size; ghu = - inv(jacob(indx_r, indx_c)) * data(i).g1_x; end case 3 - %% ------------------------------------------------------------------ + %% ------------------------------------------------------------------ %Solve Forward single equation if maximum_lag > 0 && n_pred > 0 data(i).eigval = - jacob(1 , 1 : n_pred) / jacob(1 , n_pred + n_static + 1 : n_pred + n_static + n_pred + n_both); @@ -246,9 +246,9 @@ for i = 1:Size; %First order approximation if task ~= 1 if (maximum_lag > 0) - ghx = - jacob(1 , 1 : n_pred) / jacob(1 , n_pred + n_static + 1 : n_pred + n_static + n_pred + n_both); + ghx = - jacob(1 , 1 : n_pred) / jacob(1 , n_pred + n_static + 1 : n_pred + n_static + n_pred + n_both); else - ghx = 0; + ghx = 0; end; if other_endo_nbr fx = data(i).g1_o; @@ -289,19 +289,19 @@ for i = 1:Size; ghu = - fu / jacob(1 , n_pred + 1 : n_pred + n_static + n_pred + n_both); end; else - if other_endo_nbr > 0 - l_u_sv = dr.ghu(dr.state_var,:); - l_x = dr.ghx(data(i).other_endogenous,:); - l_u = dr.ghu(data(i).other_endogenous,:); - ghu = -(fx_tp1 * l_x * l_u_sv + (fx_t) * l_u ) / jacob(1 , n_pred + 1 : n_pred + n_static + n_pred + n_both); - exo = dr.exo_var; - else - ghu = []; - end + if other_endo_nbr > 0 + l_u_sv = dr.ghu(dr.state_var,:); + l_x = dr.ghx(data(i).other_endogenous,:); + l_u = dr.ghu(data(i).other_endogenous,:); + ghu = -(fx_tp1 * l_x * l_u_sv + (fx_t) * l_u ) / jacob(1 , n_pred + 1 : n_pred + n_static + n_pred + n_both); + exo = dr.exo_var; + else + ghu = []; + end end end case 4 - %% ------------------------------------------------------------------ + %% ------------------------------------------------------------------ %Solve Backward single equation if maximum_lead > 0 && n_fwrd > 0 data(i).eigval = - jacob(1 , n_pred + n - n_fwrd + 1 : n_pred + n) / jacob(1 , n_pred + n + 1 : n_pred + n + n_fwrd) ; @@ -315,11 +315,11 @@ for i = 1:Size; dr.full_rank = dr.full_rank && full_rank; dr.eigval = [dr.eigval ; data(i).eigval]; case 6 - %% ------------------------------------------------------------------ - %Solve Forward complete + %% ------------------------------------------------------------------ + %Solve Forward complete if (maximum_lag > 0) ghx = - jacob(: , n_pred + 1 : n_pred + n_static ... - + n_pred + n_both) \ jacob(: , 1 : n_pred); + + n_pred + n_both) \ jacob(: , 1 : n_pred); else ghx = 0; end; @@ -373,19 +373,19 @@ for i = 1:Size; ghu = - fu / jacob(: , n_pred + 1 : n_pred + n_static + n_pred + n_both); end; else - if other_endo_nbr > 0 - l_u_sv = dr.ghu(dr.state_var,:); - l_x = dr.ghx(data(i).other_endogenous,:); - l_u = dr.ghu(data(i).other_endogenous,:); - ghu = -(fx_tp1 * l_x * l_u_sv + (fx_t) * l_u ) / jacob(1 , n_pred + 1 : n_pred + n_static + n_pred + n_both); - exo = dr.exo_var; - else - ghu = []; - end + if other_endo_nbr > 0 + l_u_sv = dr.ghu(dr.state_var,:); + l_x = dr.ghx(data(i).other_endogenous,:); + l_u = dr.ghu(data(i).other_endogenous,:); + ghu = -(fx_tp1 * l_x * l_u_sv + (fx_t) * l_u ) / jacob(1 , n_pred + 1 : n_pred + n_static + n_pred + n_both); + exo = dr.exo_var; + else + ghu = []; + end end end case 7 - %% ------------------------------------------------------------------ + %% ------------------------------------------------------------------ %Solve Backward complete if maximum_lead > 0 && n_fwrd > 0 data(i).eigval = eig(- jacob(: , n_pred + n - n_fwrd + 1: n_pred + n))/ ... @@ -401,7 +401,7 @@ for i = 1:Size; dr.full_rank = dr.full_rank && full_rank; dr.eigval = [dr.eigval ; data(i).eigval]; case {5,8} - %% ------------------------------------------------------------------ + %% ------------------------------------------------------------------ %The lead_lag_incidence contains columns in the following order: % static variables, backward variable, mixed variables and forward variables % @@ -483,7 +483,7 @@ for i = 1:Size; nba = nyf; end else - sorted_roots = sort(abs(data(i).eigval)); + sorted_roots = sort(abs(data(i).eigval)); if nba > nyf temp = sorted_roots(nd-nba+1:nd-nyf)-1-options_.qz_criterium; info(1) = 3; @@ -497,8 +497,8 @@ for i = 1:Size; end indx_stable_root = 1: (nd - nyf); %=> index of stable roots indx_explosive_root = n_pred + n_both + 1:nd; %=> index of explosive roots - % derivatives with respect to dynamic state variables - % forward variables + % derivatives with respect to dynamic state variables + % forward variables Z = w'; Z11t = Z(indx_stable_root, indx_stable_root)'; Z21 = Z(indx_explosive_root, indx_stable_root); @@ -555,7 +555,7 @@ for i = 1:Size; if other_endo_nbr if n_static > 0 - fx = Q' * data(i).g1_o; + fx = Q' * data(i).g1_o; else fx = data(i).g1_o; end; @@ -594,8 +594,8 @@ for i = 1:Size; [err, ghx_other] = gensylv(1, A_, B_, C_, -D_); end; if options_.aim_solver ~= 1 && options_.use_qzdiv - % Necessary when using Sims' routines for QZ - ghx_other = real(ghx_other); + % Necessary when using Sims' routines for QZ + ghx_other = real(ghx_other); end dr.ghx(endo, :) = dr.ghx(endo, :) + ghx_other; @@ -640,13 +640,13 @@ for i = 1:Size; if options_.loglinear error('The loglinear option is not yet supported in first order approximation for a block decomposed model'); -% k = find(dr.kstate(:,2) <= M_.maximum_endo_lag+1); -% klag = dr.kstate(k,[1 2]); -% k1 = dr.order_var; -% -% ghx = repmat(1./dr.ys(k1),1,size(ghx,2)).*ghx.* ... -% repmat(dr.ys(k1(klag(:,1)))',size(ghx,1),1); -% ghu = repmat(1./dr.ys(k1),1,size(ghu,2)).*ghu; + % k = find(dr.kstate(:,2) <= M_.maximum_endo_lag+1); + % klag = dr.kstate(k,[1 2]); + % k1 = dr.order_var; + % + % ghx = repmat(1./dr.ys(k1),1,size(ghx,2)).*ghx.* ... + % repmat(dr.ys(k1(klag(:,1)))',size(ghx,1),1); + % ghu = repmat(1./dr.ys(k1),1,size(ghu,2)).*ghu; end @@ -659,16 +659,16 @@ for i = 1:Size; %exogenous deterministic variables if exo_det_nbr > 0 error('Deterministic exogenous variables are not yet implemented in first order approximation for a block decomposed model'); -% f1 = sparse(jacobia_(:,nonzeros(M_.lead_lag_incidence(M_.maximum_endo_lag+2:end,order_var)))); -% f0 = sparse(jacobia_(:,nonzeros(M_.lead_lag_incidence(M_.maximum_endo_lag+1,order_var)))); -% fudet = data(i).g1_xd; -% M1 = inv(f0+[zeros(n,n_static) f1*gx zeros(n,nyf-n_both)]); -% M2 = M1*f1; -% dr.ghud = cell(M_.exo_det_length,1); -% dr.ghud{1} = -M1*fudet; -% for i = 2:M_.exo_det_length -% dr.ghud{i} = -M2*dr.ghud{i-1}(end-nyf+1:end,:); -% end + % f1 = sparse(jacobia_(:,nonzeros(M_.lead_lag_incidence(M_.maximum_endo_lag+2:end,order_var)))); + % f0 = sparse(jacobia_(:,nonzeros(M_.lead_lag_incidence(M_.maximum_endo_lag+1,order_var)))); + % fudet = data(i).g1_xd; + % M1 = inv(f0+[zeros(n,n_static) f1*gx zeros(n,nyf-n_both)]); + % M2 = M1*f1; + % dr.ghud = cell(M_.exo_det_length,1); + % dr.ghud{1} = -M1*fudet; + % for i = 2:M_.exo_det_length + % dr.ghud{i} = -M2*dr.ghud{i-1}(end-nyf+1:end,:); + % end end end end; @@ -686,20 +686,20 @@ for i = 1:Size; data(i).pol.i_ghu = exo; end; - if (verbose) + if (verbose) disp('dr.ghx'); dr.ghx disp('dr.ghu'); dr.ghu - end; - + end; + end; M_.block_structure.block = data ; if (verbose) - disp('dr.ghx'); - disp(real(dr.ghx)); - disp('dr.ghu'); - disp(real(dr.ghu)); + disp('dr.ghx'); + disp(real(dr.ghx)); + disp('dr.ghu'); + disp(real(dr.ghu)); end; if (task == 1) return; diff --git a/matlab/dsge_likelihood.m b/matlab/dsge_likelihood.m index 30bb87b5fb..b8ee614b93 100644 --- a/matlab/dsge_likelihood.m +++ b/matlab/dsge_likelihood.m @@ -149,7 +149,7 @@ xparam1 = xparam1(:); if DynareOptions.estimation_dll [fval,exit_flag,SteadyState,trend_coeff,info,params,H,Q] ... = logposterior(xparam1,DynareDataset, DynareOptions,Model, ... - EstimatedParameters,BayesInfo,DynareResults); + EstimatedParameters,BayesInfo,DynareResults); mexErrCheck('logposterior', exit_flag); Model.params = params; if ~isequal(Model.H,0) @@ -268,8 +268,8 @@ end % Return, with endogenous penalty when possible, if dynare_resolve issues an error code (defined in resol). if info(1) if info(1) == 3 || info(1) == 4 || info(1) == 5 || info(1)==6 ||info(1) == 19 ||... - info(1) == 20 || info(1) == 21 || info(1) == 23 || info(1) == 26 || ... - info(1) == 81 || info(1) == 84 || info(1) == 85 || info(1) == 86 + info(1) == 20 || info(1) == 21 || info(1) == 23 || info(1) == 26 || ... + info(1) == 81 || info(1) == 84 || info(1) == 85 || info(1) == 86 %meaningful second entry of output that can be used fval = Inf; info(4) = info(2); @@ -323,8 +323,8 @@ if BayesInfo.with_trend [trend_addition, trend_coeff]=compute_trend_coefficients(Model,DynareOptions,DynareDataset.vobs,DynareDataset.nobs); trend = repmat(constant,1,DynareDataset.nobs)+trend_addition; else - trend_coeff = zeros(DynareDataset.vobs,1); - trend = repmat(constant,1,DynareDataset.nobs); + trend_coeff = zeros(DynareDataset.vobs,1); + trend = repmat(constant,1,DynareDataset.nobs); end % Get needed informations for kalman filter routines. @@ -372,8 +372,8 @@ switch DynareOptions.lik_init if kalman_algo == 0 kalman_algo = 3; elseif ~((kalman_algo == 3) || (kalman_algo == 4)) - error(['The model requires Diffuse filter, but you specified a different Kalman filter. You must set options_.kalman_algo ' ... - 'to 0 (default), 3 or 4']) + error(['The model requires Diffuse filter, but you specified a different Kalman filter. You must set options_.kalman_algo ' ... + 'to 0 (default), 3 or 4']) end [Pstar,Pinf] = compute_Pinf_Pstar(Z,T,R,Q,DynareOptions.qz_criterium,[1:length(T)]); Z =zeros(length(BayesInfo.mf),size(T,1)); @@ -387,9 +387,9 @@ switch DynareOptions.lik_init Pstar0 = Pstar; % store Pstar if no_missing_data_flag [dLIK,dlik,a,Pstar] = kalman_filter_d(Y, 1, size(Y,2), ... - zeros(mm,1), Pinf, Pstar, ... - kalman_tol, diffuse_kalman_tol, riccati_tol, DynareOptions.presample, ... - T,R,Q,H,Z,mm,pp,rr); + zeros(mm,1), Pinf, Pstar, ... + kalman_tol, diffuse_kalman_tol, riccati_tol, DynareOptions.presample, ... + T,R,Q,H,Z,mm,pp,rr); else [dLIK,dlik,a,Pstar] = missing_observations_kalman_filter_d(DatasetInfo.missing.aindex,DatasetInfo.missing.number_of_observations,DatasetInfo.missing.no_more_missing_observations, ... Y, 1, size(Y,2), ... @@ -438,12 +438,12 @@ switch DynareOptions.lik_init end [dLIK,dlik,a,Pstar] = univariate_kalman_filter_d(DatasetInfo.missing.aindex,... - DatasetInfo.missing.number_of_observations,... - DatasetInfo.missing.no_more_missing_observations, ... - Y, 1, size(Y,2), ... - zeros(mmm,1), Pinf, Pstar, ... - kalman_tol, diffuse_kalman_tol, riccati_tol, DynareOptions.presample, ... - T,R,Q,H1,Z,mmm,pp,rr); + DatasetInfo.missing.number_of_observations,... + DatasetInfo.missing.no_more_missing_observations, ... + Y, 1, size(Y,2), ... + zeros(mmm,1), Pinf, Pstar, ... + kalman_tol, diffuse_kalman_tol, riccati_tol, DynareOptions.presample, ... + T,R,Q,H1,Z,mmm,pp,rr); diffuse_periods = size(dlik,1); end if isnan(dLIK), @@ -541,9 +541,9 @@ if analytic_derivation, full_Hess = derivatives_info.full_Hess; end if full_Hess, - D2T = derivatives_info.D2T; - D2Om = derivatives_info.D2Om; - D2Yss = derivatives_info.D2Yss; + D2T = derivatives_info.D2T; + D2Om = derivatives_info.D2Om; + D2Yss = derivatives_info.D2Yss; end if isfield(derivatives_info,'no_DLIK'), no_DLIK = derivatives_info.no_DLIK; @@ -556,7 +556,7 @@ if analytic_derivation, DP=zeros([size(T),length(xparam1)]); if full_Hess, for j=1:size(D2Yss,1), - tmp(j,:,:) = blkdiag(zeros(offset,offset), squeeze(D2Yss(j,:,:))); + tmp(j,:,:) = blkdiag(zeros(offset,offset), squeeze(D2Yss(j,:,:))); end D2Yss = tmp; D2H=sparse(size(D2Om,1),size(D2Om,2)); %zeros([size(H),length(xparam1),length(xparam1)]); @@ -564,58 +564,58 @@ if analytic_derivation, jcount=0; end if DynareOptions.lik_init==1, - for i=1:EstimatedParameters.nvx - k =EstimatedParameters.var_exo(i,1); - DQ(k,k,i) = 2*sqrt(Q(k,k)); - dum = lyapunov_symm(T,DOm(:,:,i),DynareOptions.lyapunov_fixed_point_tol,DynareOptions.qz_criterium,DynareOptions.lyapunov_complex_threshold,[],DynareOptions.debug); -% kk = find(abs(dum) < 1e-12); -% dum(kk) = 0; - DP(:,:,i)=dum; - if full_Hess - for j=1:i, - jcount=jcount+1; - dum = lyapunov_symm(T,dyn_unvech(D2Om(:,jcount)),DynareOptions.lyapunov_fixed_point_tol,DynareOptions.qz_criterium,DynareOptions.lyapunov_complex_threshold,[],DynareOptions.debug); -% kk = (abs(dum) < 1e-12); -% dum(kk) = 0; - D2P(:,jcount)=dyn_vech(dum); -% D2P(:,:,j,i)=dum; - end + for i=1:EstimatedParameters.nvx + k =EstimatedParameters.var_exo(i,1); + DQ(k,k,i) = 2*sqrt(Q(k,k)); + dum = lyapunov_symm(T,DOm(:,:,i),DynareOptions.lyapunov_fixed_point_tol,DynareOptions.qz_criterium,DynareOptions.lyapunov_complex_threshold,[],DynareOptions.debug); + % kk = find(abs(dum) < 1e-12); + % dum(kk) = 0; + DP(:,:,i)=dum; + if full_Hess + for j=1:i, + jcount=jcount+1; + dum = lyapunov_symm(T,dyn_unvech(D2Om(:,jcount)),DynareOptions.lyapunov_fixed_point_tol,DynareOptions.qz_criterium,DynareOptions.lyapunov_complex_threshold,[],DynareOptions.debug); + % kk = (abs(dum) < 1e-12); + % dum(kk) = 0; + D2P(:,jcount)=dyn_vech(dum); + % D2P(:,:,j,i)=dum; + end + end end end - end offset = EstimatedParameters.nvx; for i=1:EstimatedParameters.nvn k = EstimatedParameters.var_endo(i,1); DH(k,k,i+offset) = 2*sqrt(H(k,k)); if full_Hess - D2H(k,k,i+offset,i+offset) = 2; + D2H(k,k,i+offset,i+offset) = 2; end end offset = offset + EstimatedParameters.nvn; if DynareOptions.lik_init==1, - for j=1:EstimatedParameters.np - dum = lyapunov_symm(T,DT(:,:,j+offset)*Pstar*T'+T*Pstar*DT(:,:,j+offset)'+DOm(:,:,j+offset),DynareOptions.lyapunov_fixed_point_tol,DynareOptions.qz_criterium,DynareOptions.lyapunov_complex_threshold,[],DynareOptions.debug); -% kk = find(abs(dum) < 1e-12); -% dum(kk) = 0; - DP(:,:,j+offset)=dum; - if full_Hess - DTj = DT(:,:,j+offset); - DPj = dum; - for i=1:j+offset, - jcount=jcount+1; - DTi = DT(:,:,i); - DPi = DP(:,:,i); - D2Tij = reshape(D2T(:,jcount),size(T)); - D2Omij = dyn_unvech(D2Om(:,jcount)); - tmp = D2Tij*Pstar*T' + T*Pstar*D2Tij' + DTi*DPj*T' + DTj*DPi*T' + T*DPj*DTi' + T*DPi*DTj' + DTi*Pstar*DTj' + DTj*Pstar*DTi' + D2Omij; - dum = lyapunov_symm(T,tmp,DynareOptions.lyapunov_fixed_point_tol,DynareOptions.qz_criterium,DynareOptions.lyapunov_complex_threshold,[],DynareOptions.debug); -% dum(abs(dum)<1.e-12) = 0; - D2P(:,jcount) = dyn_vech(dum); -% D2P(:,:,j+offset,i) = dum; - end + for j=1:EstimatedParameters.np + dum = lyapunov_symm(T,DT(:,:,j+offset)*Pstar*T'+T*Pstar*DT(:,:,j+offset)'+DOm(:,:,j+offset),DynareOptions.lyapunov_fixed_point_tol,DynareOptions.qz_criterium,DynareOptions.lyapunov_complex_threshold,[],DynareOptions.debug); + % kk = find(abs(dum) < 1e-12); + % dum(kk) = 0; + DP(:,:,j+offset)=dum; + if full_Hess + DTj = DT(:,:,j+offset); + DPj = dum; + for i=1:j+offset, + jcount=jcount+1; + DTi = DT(:,:,i); + DPi = DP(:,:,i); + D2Tij = reshape(D2T(:,jcount),size(T)); + D2Omij = dyn_unvech(D2Om(:,jcount)); + tmp = D2Tij*Pstar*T' + T*Pstar*D2Tij' + DTi*DPj*T' + DTj*DPi*T' + T*DPj*DTi' + T*DPi*DTj' + DTi*Pstar*DTj' + DTj*Pstar*DTi' + D2Omij; + dum = lyapunov_symm(T,tmp,DynareOptions.lyapunov_fixed_point_tol,DynareOptions.qz_criterium,DynareOptions.lyapunov_complex_threshold,[],DynareOptions.debug); + % dum(abs(dum)<1.e-12) = 0; + D2P(:,jcount) = dyn_vech(dum); + % D2P(:,:,j+offset,i) = dum; + end + end end end - end if analytic_derivation==1, analytic_deriv_info={analytic_derivation,DT,DYss,DOm,DH,DP,asy_Hess}; else @@ -848,14 +848,14 @@ else end if DynareOptions.endogenous_prior==1 - if DynareOptions.lik_init==2 || DynareOptions.lik_init==3 - error('Endogenous prior not supported with non-stationary models') - else - [lnpriormom] = endogenous_prior(Y,Pstar,BayesInfo,H); - fval = (likelihood-lnprior-lnpriormom); - end + if DynareOptions.lik_init==2 || DynareOptions.lik_init==3 + error('Endogenous prior not supported with non-stationary models') + else + [lnpriormom] = endogenous_prior(Y,Pstar,BayesInfo,H); + fval = (likelihood-lnprior-lnpriormom); + end else - fval = (likelihood-lnprior); + fval = (likelihood-lnprior); end if DynareOptions.prior_restrictions.status diff --git a/matlab/dsge_simulated_theoretical_correlation.m b/matlab/dsge_simulated_theoretical_correlation.m index 265336dbb0..23485a8d50 100644 --- a/matlab/dsge_simulated_theoretical_correlation.m +++ b/matlab/dsge_simulated_theoretical_correlation.m @@ -16,7 +16,7 @@ function [nvar,vartan,CorrFileNumber] = dsge_simulated_theoretical_correlation(S % nvar [integer] nvar is the number of stationary variables. % vartan [char] array of characters (with nvar rows). % CorrFileNumber [integer] scalar, number of prior or posterior data files (for correlation). - + % Copyright (C) 2007-2015 Dynare Team % % This file is part of Dynare. diff --git a/matlab/dsge_simulated_theoretical_variance_decomposition.m b/matlab/dsge_simulated_theoretical_variance_decomposition.m index a8ddadec6d..1cb8f0d314 100644 --- a/matlab/dsge_simulated_theoretical_variance_decomposition.m +++ b/matlab/dsge_simulated_theoretical_variance_decomposition.m @@ -119,17 +119,17 @@ for file = 1:NumberOfDrawsFiles if file==1 && linee==1 [tmp, stationary_vars] = th_autocovariances(dr,ivar,M_,options_,nodecomposition); if isempty(stationary_vars) - fprintf('\ndsge_simulated_theoretical_variance_decomposition:: All requested endogenous variables have a unit root and thus infinite variance.\n') - fprintf('dsge_simulated_theoretical_variance_decomposition:: No decomposition is performed.\n') - only_non_stationary_vars=1; + fprintf('\ndsge_simulated_theoretical_variance_decomposition:: All requested endogenous variables have a unit root and thus infinite variance.\n') + fprintf('dsge_simulated_theoretical_variance_decomposition:: No decomposition is performed.\n') + only_non_stationary_vars=1; end end if only_non_stationary_vars - for i=1:nvar + for i=1:nvar for j=1:nexo Decomposition_array(linea,(i-1)*nexo+j) = NaN; end - end + end else tmp = th_autocovariances(dr,ivar,M_,options_,nodecomposition); for i=1:nvar diff --git a/matlab/dsge_var_likelihood.m b/matlab/dsge_var_likelihood.m index 94f8e21ac4..c37fca0589 100644 --- a/matlab/dsge_var_likelihood.m +++ b/matlab/dsge_var_likelihood.m @@ -158,8 +158,8 @@ end % Return, with endogenous penalty when possible, if dynare_resolve issues an error code (defined in resol). if info(1) if info(1) == 3 || info(1) == 4 || info(1) == 5 || info(1)==6 ||info(1) == 19 ||... - info(1) == 20 || info(1) == 21 || info(1) == 23 || info(1) == 26 || ... - info(1) == 81 || info(1) == 84 || info(1) == 85 + info(1) == 20 || info(1) == 21 || info(1) == 23 || info(1) == 26 || ... + info(1) == 81 || info(1) == 84 || info(1) == 85 %meaningful second entry of output that can be used fval = Inf; info(4) = info(2); @@ -265,7 +265,7 @@ if ~isinf(dsge_prior_weight)% Evaluation of the likelihood of the dsge-var model prodlng2 = sum(gammaln(.5*(dsge_prior_weight*NumberOfObservations- ... NumberOfParameters ... +1-(1:NumberOfObservedVariables)'))); %last term in denominator of third line of (A.2), DS (2004) - %Compute minus log likelihood according to (A.2), DS (2004) + %Compute minus log likelihood according to (A.2), DS (2004) lik = .5*NumberOfObservedVariables*log(det(dsge_prior_weight*NumberOfObservations*GXX+mXX)) ... %first term in numerator of second line of (A.2), DS (2004) + .5*((dsge_prior_weight+1)*NumberOfObservations-NumberOfParameters)*log(det((dsge_prior_weight+1)*NumberOfObservations*SIGMA_u_tilde)) ... %second term in numerator of second line of (A.2), DS (2004) - .5*NumberOfObservedVariables*log(det(dsge_prior_weight*NumberOfObservations*GXX)) ... %first term in denominator of second line of (A.2), DS (2004) @@ -278,7 +278,7 @@ else% Evaluation of the likelihood of the dsge-var model when the dsge prior wei PHI_star = iGXX*transpose(GYX); %Compute minus log likelihood according to (33), DS (2004) (where the last term in the trace operator has been multiplied out) lik = NumberOfObservations * ( log(det(SIGMA_u_star)) + NumberOfObservedVariables*log(2*pi) + ... - trace(inv(SIGMA_u_star)*(mYY - transpose(mYX*PHI_star) - mYX*PHI_star + transpose(PHI_star)*mXX*PHI_star)/NumberOfObservations)); + trace(inv(SIGMA_u_star)*(mYY - transpose(mYX*PHI_star) - mYX*PHI_star + transpose(PHI_star)*mXX*PHI_star)/NumberOfObservations)); lik = .5*lik;% Minus likelihood SIGMA_u_tilde=SIGMA_u_star; PHI_tilde=PHI_star; diff --git a/matlab/dyn_first_order_solver.m b/matlab/dyn_first_order_solver.m index cb5e407a83..0adf0e2c0e 100644 --- a/matlab/dyn_first_order_solver.m +++ b/matlab/dyn_first_order_solver.m @@ -179,7 +179,7 @@ if task ~= 1 && (DynareOptions.dr_cycle_reduction || DynareOptions.dr_logarithmi if n_current < DynareModel.endo_nbr if DynareOptions.dr_cycle_reduction error(['The cycle reduction algorithme can''t be used when the ' ... - 'coefficient matrix for current variables isn''t invertible']) + 'coefficient matrix for current variables isn''t invertible']) elseif DynareOptions.dr_logarithmic_reduction error(['The logarithmic reduction algorithme can''t be used when the ' ... 'coefficient matrix for current variables isn''t invertible']) diff --git a/matlab/dyn_forecast.m b/matlab/dyn_forecast.m index 8189b7e597..e5faf86afb 100644 --- a/matlab/dyn_forecast.m +++ b/matlab/dyn_forecast.m @@ -43,7 +43,7 @@ if nargin<6 && options.prefilter elseif nargin==6 mean_varobs=dataset_info.descriptive.mean'; end - + info = 0; oo=make_ex_(M,options,oo); @@ -92,7 +92,7 @@ switch task for i = 1:M.endo_nbr v_name = deblank(M.endo_names(i,:)); y0(i,:) = y_smoothed.(v_name)(end-maximum_lag+1:end); %includes steady state or mean, but simult_ will subtract only steady state - % 2. Subtract mean/steady state and add steady state; takes care of prefiltering + % 2. Subtract mean/steady state and add steady state; takes care of prefiltering if isfield(oo.Smoother,'Constant') && isfield(oo.Smoother.Constant,v_name) y0(i,:)=y0(i,:)-oo.Smoother.Constant.(v_name)(end-maximum_lag+1:end); %subtract mean or steady state if options.loglinear @@ -153,10 +153,10 @@ else end if isequal(M.H,0) [yf,int_width] = simultxdet(y0,ex,oo.exo_det_simul,... - options.order,var_list,M,oo,options); + options.order,var_list,M,oo,options); else [yf,int_width,int_width_ME] = simultxdet(y0,ex,oo.exo_det_simul,... - options.order,var_list,M,oo,options); + options.order,var_list,M,oo,options); end end diff --git a/matlab/dyn_latex_table.m b/matlab/dyn_latex_table.m index 63fb6095f6..ca14e351f5 100644 --- a/matlab/dyn_latex_table.m +++ b/matlab/dyn_latex_table.m @@ -27,7 +27,7 @@ OutputDirectoryName = CheckPath('Output',M_.dname); %% get width of label column if ~isempty(label_width) label_width = max(size(deblank(char(headers(1,:),labels)),2)+2, ... - label_width); + label_width); else %use default length label_width = max(size(deblank(char(headers(1,:),labels)),2))+2; end diff --git a/matlab/dyn_ramsey_static.m b/matlab/dyn_ramsey_static.m index 964bede382..d20582c3b5 100644 --- a/matlab/dyn_ramsey_static.m +++ b/matlab/dyn_ramsey_static.m @@ -39,7 +39,7 @@ function [steady_state,params,check] = dyn_ramsey_static(ys_init,M,options_,oo) params = M.params; check = 0; options_.steadystate.nocheck = 1; %locally disable checking because Lagrange multipliers are not accounted for in evaluate_steady_state_file -% dyn_ramsey_static_1 is a subfunction + % dyn_ramsey_static_1 is a subfunction nl_func = @(x) dyn_ramsey_static_1(x,M,options_,oo); % check_static_model is a subfunction @@ -120,7 +120,7 @@ if options_.steadystate_flag ys_init(k_inst) = x; %set instrument, the only value required for steady state computation, to current value [x,params,check] = evaluate_steady_state_file(ys_init,... %returned x now has size endo_nbr as opposed to input size of n_instruments [oo.exo_steady_state; ... - oo.exo_det_steady_state], ... + oo.exo_det_steady_state], ... M,options_,~options_.steadystate.nocheck); if any(imag(x(1:M.orig_endo_nbr))) %return with penalty resids=1+sum(abs(imag(x(1:M.orig_endo_nbr)))); %return with penalty @@ -154,12 +154,12 @@ Uyy = reshape(Uyy,endo_nbr,endo_nbr); % set multipliers and auxiliary variables that % depends on multipliers to 0 to compute residuals if (options_.bytecode) - [chck, res, junk] = bytecode('static',xx,[oo.exo_steady_state oo.exo_det_steady_state], ... - params, 'evaluate'); - fJ = junk.g1; + [chck, res, junk] = bytecode('static',xx,[oo.exo_steady_state oo.exo_det_steady_state], ... + params, 'evaluate'); + fJ = junk.g1; else - [res,fJ] = feval([fname '_static'],xx,[oo.exo_steady_state oo.exo_det_steady_state], ... - params); + [res,fJ] = feval([fname '_static'],xx,[oo.exo_steady_state oo.exo_det_steady_state], ... + params); end % index of multipliers and corresponding equations % the auxiliary variables before the Lagrange multipliers are treated diff --git a/matlab/dyn_risky_steadystate_solver.m b/matlab/dyn_risky_steadystate_solver.m index a7e09b1bd3..1292523a4a 100644 --- a/matlab/dyn_risky_steadystate_solver.m +++ b/matlab/dyn_risky_steadystate_solver.m @@ -1,273 +1,311 @@ function [dr,info] = dyn_risky_steadystate_solver(ys0,M, ... dr,options,oo) - %@info: - %! @deftypefn {Function File} {[@var{dr},@var{info}] =} dyn_risky_steadystate_solver (@var{ys0},@var{M},@var{dr},@var{options},@var{oo}) - %! @anchor{dyn_risky_steadystate_solver} - %! @sp 1 - %! Computes the second order risky steady state and first and second order reduced form of the DSGE model. - %! @sp 2 - %! @strong{Inputs} - %! @sp 1 - %! @table @ @var - %! @item ys0 - %! Vector containing a guess value for the risky steady state - %! @item M - %! Matlab's structure describing the model (initialized by @code{dynare}). - %! @item dr - %! Matlab's structure describing the reduced form solution of the model. - %! @item options - %! Matlab's structure describing the options (initialized by @code{dynare}). - %! @item oo - %! Matlab's structure gathering the results (initialized by @code{dynare}). - %! @end table - %! @sp 2 - %! @strong{Outputs} - %! @sp 1 - %! @table @ @var - %! @item dr - %! Matlab's structure describing the reduced form solution of the model. - %! @item info - %! Integer scalar, error code. - %! @sp 1 - %! @table @ @code - %! @item info==0 - %! No error. - %! @item info==1 - %! The model doesn't determine the current variables uniquely. - %! @item info==2 - %! MJDGGES returned an error code. - %! @item info==3 - %! Blanchard & Kahn conditions are not satisfied: no stable equilibrium. - %! @item info==4 - %! Blanchard & Kahn conditions are not satisfied: indeterminacy. - %! @item info==5 - %! Blanchard & Kahn conditions are not satisfied: indeterminacy due to rank failure. - %! @item info==6 - %! The jacobian evaluated at the deterministic steady state is complex. - %! @item info==19 - %! The steadystate routine thrown an exception (inconsistent deep parameters). - %! @item info==20 - %! Cannot find the steady state, info(2) contains the sum of square residuals (of the static equations). - %! @item info==21 - %! The steady state is complex, info(2) contains the sum of square of imaginary parts of the steady state. - %! @item info==22 - %! The steady has NaNs. - %! @item info==23 - %! M_.params has been updated in the steadystate routine and has complex valued scalars. - %! @item info==24 - %! M_.params has been updated in the steadystate routine and has some NaNs. - %! @end table - %! @end table - %! @end deftypefn - %@eod: - - % Copyright (C) 2001-2012 Dynare Team - % - % This file is part of Dynare. - % - % Dynare is free software: you can redistribute it and/or modify - % it under the terms of the GNU General Public License as published by - % the Free Software Foundation, either version 3 of the License, or - % (at your option) any later version. - % - % Dynare is distributed in the hope that it will be useful, - % but WITHOUT ANY WARRANTY; without even the implied warranty of - % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - % GNU General Public License for more details. - % - % You should have received a copy of the GNU General Public License - % along with Dynare. If not, see <http://www.gnu.org/licenses/>. +%@info: +%! @deftypefn {Function File} {[@var{dr},@var{info}] =} dyn_risky_steadystate_solver (@var{ys0},@var{M},@var{dr},@var{options},@var{oo}) +%! @anchor{dyn_risky_steadystate_solver} +%! @sp 1 +%! Computes the second order risky steady state and first and second order reduced form of the DSGE model. +%! @sp 2 +%! @strong{Inputs} +%! @sp 1 +%! @table @ @var +%! @item ys0 +%! Vector containing a guess value for the risky steady state +%! @item M +%! Matlab's structure describing the model (initialized by @code{dynare}). +%! @item dr +%! Matlab's structure describing the reduced form solution of the model. +%! @item options +%! Matlab's structure describing the options (initialized by @code{dynare}). +%! @item oo +%! Matlab's structure gathering the results (initialized by @code{dynare}). +%! @end table +%! @sp 2 +%! @strong{Outputs} +%! @sp 1 +%! @table @ @var +%! @item dr +%! Matlab's structure describing the reduced form solution of the model. +%! @item info +%! Integer scalar, error code. +%! @sp 1 +%! @table @ @code +%! @item info==0 +%! No error. +%! @item info==1 +%! The model doesn't determine the current variables uniquely. +%! @item info==2 +%! MJDGGES returned an error code. +%! @item info==3 +%! Blanchard & Kahn conditions are not satisfied: no stable equilibrium. +%! @item info==4 +%! Blanchard & Kahn conditions are not satisfied: indeterminacy. +%! @item info==5 +%! Blanchard & Kahn conditions are not satisfied: indeterminacy due to rank failure. +%! @item info==6 +%! The jacobian evaluated at the deterministic steady state is complex. +%! @item info==19 +%! The steadystate routine thrown an exception (inconsistent deep parameters). +%! @item info==20 +%! Cannot find the steady state, info(2) contains the sum of square residuals (of the static equations). +%! @item info==21 +%! The steady state is complex, info(2) contains the sum of square of imaginary parts of the steady state. +%! @item info==22 +%! The steady has NaNs. +%! @item info==23 +%! M_.params has been updated in the steadystate routine and has complex valued scalars. +%! @item info==24 +%! M_.params has been updated in the steadystate routine and has some NaNs. +%! @end table +%! @end table +%! @end deftypefn +%@eod: + +% Copyright (C) 2001-2012 Dynare Team +% +% This file is part of Dynare. +% +% Dynare is free software: you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation, either version 3 of the License, or +% (at your option) any later version. +% +% Dynare is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with Dynare. If not, see <http://www.gnu.org/licenses/>. + + +info = 0; +lead_lag_incidence = M.lead_lag_incidence; +order_var = dr.order_var; +endo_nbr = M.endo_nbr; +exo_nbr = M.exo_nbr; + +M.var_order_endo_names = M.endo_names(dr.order_var,:); + +[junk,dr.i_fwrd_g,i_fwrd_f] = find(lead_lag_incidence(3,order_var)); +dr.i_fwrd_f = i_fwrd_f; +nd = nnz(lead_lag_incidence) + M.exo_nbr; +dr.nd = nd; +kk = reshape(1:nd^2,nd,nd); +kkk = reshape(1:nd^3,nd^2,nd); +dr.i_fwrd2_f = kk(i_fwrd_f,i_fwrd_f); +dr.i_fwrd2a_f = kk(i_fwrd_f,:); +dr.i_fwrd3_f = kkk(dr.i_fwrd2_f,:); +dr.i_uu = kk(end-exo_nbr+1:end,end-exo_nbr+1:end); +if options.k_order_solver + func = @risky_residuals_k_order; +else + func = @risky_residuals; +end +if isfield(options,'portfolio') && options.portfolio == 1 + pm = portfolio_model_structure(M,options); - info = 0; - lead_lag_incidence = M.lead_lag_incidence; - order_var = dr.order_var; - endo_nbr = M.endo_nbr; - exo_nbr = M.exo_nbr; - - M.var_order_endo_names = M.endo_names(dr.order_var,:); - - [junk,dr.i_fwrd_g,i_fwrd_f] = find(lead_lag_incidence(3,order_var)); - dr.i_fwrd_f = i_fwrd_f; - nd = nnz(lead_lag_incidence) + M.exo_nbr; - dr.nd = nd; - kk = reshape(1:nd^2,nd,nd); - kkk = reshape(1:nd^3,nd^2,nd); - dr.i_fwrd2_f = kk(i_fwrd_f,i_fwrd_f); - dr.i_fwrd2a_f = kk(i_fwrd_f,:); - dr.i_fwrd3_f = kkk(dr.i_fwrd2_f,:); - dr.i_uu = kk(end-exo_nbr+1:end,end-exo_nbr+1:end); - if options.k_order_solver - func = @risky_residuals_k_order; - else - func = @risky_residuals; - end - - if isfield(options,'portfolio') && options.portfolio == 1 - pm = portfolio_model_structure(M,options); - - x0 = ys0(pm.v_p); - n = length(x0); - [x, info] = solve1(@risky_residuals_ds,x0,1:n,1:n,0,options.gstep, ... - options.solve_tolf,options.solve_tolx, ... - options.steady.maxit,options.debug,pm,M,dr, ... - options,oo); - if info - error('DS approach can''t be computed') - end - %[x, info] = csolve(@risky_residuals_ds,x0,[],1e-10,100,M,dr,options,oo); - % ys0(l_var) = x; - [resids,dr1] = risky_residuals_ds(x,pm,M,dr,options,oo); - ys1 = dr1.ys; - else - pm = model_structure(M,options); - end - - [ys, info] = solve1(func,ys0,1:endo_nbr,1:endo_nbr,0,options.gstep, ... - options.solve_tolf,options.solve_tolx, ... - options.steady.maxit,options.debug,pm,M,dr,options,oo); - % [ys, info] = csolve(func,ys0,[],1e-10,100,M,dr,options,oo); + x0 = ys0(pm.v_p); + n = length(x0); + [x, info] = solve1(@risky_residuals_ds,x0,1:n,1:n,0,options.gstep, ... + options.solve_tolf,options.solve_tolx, ... + options.steady.maxit,options.debug,pm,M,dr, ... + options,oo); if info - error('RSS approach can''t be computed') - end - dr.ys = ys; - - [resid,dr] = func(ys,pm,M,dr,options,oo); - dr.ghs2 = zeros(M.endo_nbr,1); - - for i=1:M.endo_nbr - if isfield(options,'portfolio') && options.portfolio == 1 - disp(sprintf('%16s %12.6f %12.6f',M.endo_names(i,:),ys1(i), ... - ys(i))) - else - disp(sprintf('%16s %12.6f %12.6f',M.endo_names(i,:),ys(i))) - end + error('DS approach can''t be computed') end + %[x, info] = csolve(@risky_residuals_ds,x0,[],1e-10,100,M,dr,options,oo); + % ys0(l_var) = x; + [resids,dr1] = risky_residuals_ds(x,pm,M,dr,options,oo); + ys1 = dr1.ys; +else + pm = model_structure(M,options); +end +[ys, info] = solve1(func,ys0,1:endo_nbr,1:endo_nbr,0,options.gstep, ... + options.solve_tolf,options.solve_tolx, ... + options.steady.maxit,options.debug,pm,M,dr,options,oo); +% [ys, info] = csolve(func,ys0,[],1e-10,100,M,dr,options,oo); +if info + error('RSS approach can''t be computed') end +dr.ys = ys; -function [resid,dr] = risky_residuals(ys,pm,M,dr,options,oo) - - lead_lag_incidence = M.lead_lag_incidence; - iyv = lead_lag_incidence'; - iyv = iyv(:); - iyr0 = find(iyv) ; - - if M.exo_nbr == 0 - oo.exo_steady_state = [] ; - end - - z = repmat(ys,1,3); - z = z(iyr0) ; - [resid1,d1,d2] = feval([M.fname '_dynamic'],z,... - [oo.exo_simul ... - oo.exo_det_simul], M.params, dr.ys, 2); - if ~isreal(d1) || ~isreal(d2) - pause - end - - if options.use_dll - % In USE_DLL mode, the hessian is in the 3-column sparse representation - d2 = sparse(d2(:,1), d2(:,2), d2(:,3), ... - size(d1, 1), size(d1, 2)*size(d1, 2)); - end +[resid,dr] = func(ys,pm,M,dr,options,oo); +dr.ghs2 = zeros(M.endo_nbr,1); +for i=1:M.endo_nbr if isfield(options,'portfolio') && options.portfolio == 1 - pm = portfolio_model_structure(M,options); - x = ys(pm.v_p); - dr = first_step_ds(x,pm,M,dr,options,oo); - dr.ys = ys; + disp(sprintf('%16s %12.6f %12.6f',M.endo_names(i,:),ys1(i), ... + ys(i))) else - pm = model_structure(M,options); - [dr,info] = dyn_first_order_solver(d1,M,dr,options,0); - if info - print_info(info,options.noprint,options); - end - dr = dyn_second_order_solver(d1,d2,dr,M,... - options.threads.kronecker.A_times_B_kronecker_C,... - options.threads.kronecker.sparse_hessian_times_B_kronecker_C); + disp(sprintf('%16s %12.6f %12.6f',M.endo_names(i,:),ys(i))) end - - gu1 = dr.ghu(pm.i_fwrd_g,:); +end - resid = resid1+0.5*(d1(:,pm.i_fwrd_f1)*dr.ghuu(pm.i_fwrd_g,:)+ ... - d2(:,pm.i_fwrd_f2)*kron(gu1,gu1))*vec(M.Sigma_e); end -function [resid,dr] = risky_residuals_ds(x,pm,M,dr,options,oo) - - v_p = pm.v_p; - v_np = pm.v_np; - - % computing steady state of non-portfolio variables consistent with - % assumed portfolio - dr.ys(v_p) = x; - ys0 = dr.ys(v_np); - f_h =str2func([M.fname '_static']); - [dr.ys(v_np),info] = csolve(@ds_static_model,ys0,[],1e-10,100,f_h,x,pm.eq_np,v_np,v_p, ... - M.endo_nbr,M.exo_nbr,M.params); +function [resid,dr] = risky_residuals(ys,pm,M,dr,options,oo) + +lead_lag_incidence = M.lead_lag_incidence; +iyv = lead_lag_incidence'; +iyv = iyv(:); +iyr0 = find(iyv) ; + +if M.exo_nbr == 0 + oo.exo_steady_state = [] ; +end + +z = repmat(ys,1,3); +z = z(iyr0) ; +[resid1,d1,d2] = feval([M.fname '_dynamic'],z,... + [oo.exo_simul ... + oo.exo_det_simul], M.params, dr.ys, 2); +if ~isreal(d1) || ~isreal(d2) + pause +end + +if options.use_dll + % In USE_DLL mode, the hessian is in the 3-column sparse representation + d2 = sparse(d2(:,1), d2(:,2), d2(:,3), ... + size(d1, 1), size(d1, 2)*size(d1, 2)); +end + +if isfield(options,'portfolio') && options.portfolio == 1 + pm = portfolio_model_structure(M,options); + x = ys(pm.v_p); + dr = first_step_ds(x,pm,M,dr,options,oo); + dr.ys = ys; +else + pm = model_structure(M,options); + [dr,info] = dyn_first_order_solver(d1,M,dr,options,0); if info - error('can''t compute non-portfolio steady state') + print_info(info,options.noprint,options); end - - dr_np = first_step_ds(x,pm,M,dr,options,oo); + dr = dyn_second_order_solver(d1,d2,dr,M,... + options.threads.kronecker.A_times_B_kronecker_C,... + options.threads.kronecker.sparse_hessian_times_B_kronecker_C); +end - lead_lag_incidence = M.lead_lag_incidence; - iyv = lead_lag_incidence'; - iyv = iyv(:); - iyr0 = find(iyv) ; - - z = repmat(dr.ys,1,3); - z = z(iyr0) ; - [resid1,d1,d2] = feval([M.fname '_dynamic'],z,... - [oo.exo_simul ... - oo.exo_det_simul], M.params, dr.ys, 2); - if ~isreal(d1) || ~isreal(d2) - pause - end - - if options.use_dll - % In USE_DLL mode, the hessian is in the 3-column sparse representation - d2 = sparse(d2(:,1), d2(:,2), d2(:,3), ... - size(d1, 1), size(d1, 2)*size(d1, 2)); - end +gu1 = dr.ghu(pm.i_fwrd_g,:); - - gu1 = dr_np.ghu(pm.i_fwrd_g,:); +resid = resid1+0.5*(d1(:,pm.i_fwrd_f1)*dr.ghuu(pm.i_fwrd_g,:)+ ... + d2(:,pm.i_fwrd_f2)*kron(gu1,gu1))*vec(M.Sigma_e); +end - resid = resid1+0.5*(d2(:,pm.i_fwrd_f2)*kron(gu1,gu1))*vec(M.Sigma_e); +function [resid,dr] = risky_residuals_ds(x,pm,M,dr,options,oo) - resid = resid(pm.eq_p) +v_p = pm.v_p; +v_np = pm.v_np; + +% computing steady state of non-portfolio variables consistent with +% assumed portfolio +dr.ys(v_p) = x; +ys0 = dr.ys(v_np); +f_h =str2func([M.fname '_static']); +[dr.ys(v_np),info] = csolve(@ds_static_model,ys0,[],1e-10,100,f_h,x,pm.eq_np,v_np,v_p, ... + M.endo_nbr,M.exo_nbr,M.params); +if info + error('can''t compute non-portfolio steady state') +end + +dr_np = first_step_ds(x,pm,M,dr,options,oo); + +lead_lag_incidence = M.lead_lag_incidence; +iyv = lead_lag_incidence'; +iyv = iyv(:); +iyr0 = find(iyv) ; + +z = repmat(dr.ys,1,3); +z = z(iyr0) ; +[resid1,d1,d2] = feval([M.fname '_dynamic'],z,... + [oo.exo_simul ... + oo.exo_det_simul], M.params, dr.ys, 2); +if ~isreal(d1) || ~isreal(d2) + pause +end + +if options.use_dll + % In USE_DLL mode, the hessian is in the 3-column sparse representation + d2 = sparse(d2(:,1), d2(:,2), d2(:,3), ... + size(d1, 1), size(d1, 2)*size(d1, 2)); +end + + +gu1 = dr_np.ghu(pm.i_fwrd_g,:); + +resid = resid1+0.5*(d2(:,pm.i_fwrd_f2)*kron(gu1,gu1))*vec(M.Sigma_e); + +resid = resid(pm.eq_p) end function dr_np = first_step_ds(x,pm,M,dr,options,oo) - lead_lag_incidence = M.lead_lag_incidence; - iyv = lead_lag_incidence'; - iyv = iyv(:); - iyr0 = find(iyv) ; +lead_lag_incidence = M.lead_lag_incidence; +iyv = lead_lag_incidence'; +iyv = iyv(:); +iyr0 = find(iyv) ; + +ys = dr.ys; +ys(pm.v_p) = x; + +z = repmat(ys,1,3); +z = z(iyr0) ; +[resid1,d1,d2] = feval([M.fname '_dynamic'],z,... + [oo.exo_simul ... + oo.exo_det_simul], M.params, dr.ys, 2); +if ~isreal(d1) || ~isreal(d2) + pause +end + +if options.use_dll + % In USE_DLL mode, the hessian is in the 3-column sparse representation + d2 = sparse(d2(:,1), d2(:,2), d2(:,3), ... + size(d1, 1), size(d1, 2)*size(d1, 2)); +end - ys = dr.ys; - ys(pm.v_p) = x; - - z = repmat(ys,1,3); - z = z(iyr0) ; - [resid1,d1,d2] = feval([M.fname '_dynamic'],z,... - [oo.exo_simul ... - oo.exo_det_simul], M.params, dr.ys, 2); - if ~isreal(d1) || ~isreal(d2) - pause - end +d1_np = d1(pm.eq_np,pm.i_d1_np); +d2_np = d2(pm.eq_np,pm.i_d2_np); + +[dr_np,info] = dyn_first_order_solver(d1_np,pm.M_np,pm.dr_np,options,0); +if info + print_info(info, 0, options); + return +end + +dr_np = dyn_second_order_solver(d1_np,d2_np,dr_np,pm.M_np,... + options.threads.kronecker.A_times_B_kronecker_C,... + options.threads.kronecker.sparse_hessian_times_B_kronecker_C); +end + +function [resid,dr] = risky_residuals_k_order(ys,pm,M,dr,options,oo) +exo_nbr = M.exo_nbr; +endo_nbr = M.endo_nbr; + +iyv = M.lead_lag_incidence'; +iyv = iyv(:); +iyr0 = find(iyv) ; + +if exo_nbr == 0 + oo.exo_steady_state = [] ; +end + +z = repmat(ys,1,3); +z = z(iyr0) ; +[resid1,d1,d2] = feval([M.fname '_dynamic'],z,... + [oo.exo_simul ... + oo.exo_det_simul], M.params, dr.ys, 2); + +if isfield(options,'portfolio') && options.portfolio == 1 + eq_np = pm.eq_np; - if options.use_dll - % In USE_DLL mode, the hessian is in the 3-column sparse representation - d2 = sparse(d2(:,1), d2(:,2), d2(:,3), ... - size(d1, 1), size(d1, 2)*size(d1, 2)); - end + d1_np = d1(eq_np,pm.i_d1_np); + d2_np = d2(eq_np,pm.i_d2_np); - d1_np = d1(pm.eq_np,pm.i_d1_np); - d2_np = d2(pm.eq_np,pm.i_d2_np); + M_np = pm.M_np; + dr_np = pm.dr_np; [dr_np,info] = dyn_first_order_solver(d1_np,pm.M_np,pm.dr_np,options,0); if info @@ -280,271 +318,233 @@ function dr_np = first_step_ds(x,pm,M,dr,options,oo) options.threads.kronecker.sparse_hessian_times_B_kronecker_C); end -function [resid,dr] = risky_residuals_k_order(ys,pm,M,dr,options,oo) - exo_nbr = M.exo_nbr; - endo_nbr = M.endo_nbr; - - iyv = M.lead_lag_incidence'; - iyv = iyv(:); - iyr0 = find(iyv) ; - - if exo_nbr == 0 - oo.exo_steady_state = [] ; - end - - z = repmat(ys,1,3); - z = z(iyr0) ; - [resid1,d1,d2] = feval([M.fname '_dynamic'],z,... +i_fwrd_f1 = pm.i_fwrd_f1; +i_fwrd_f2 = pm.i_fwrd_f2; +i_fwrd_f3 = pm.i_fwrd_f3; +i_fwrd_g = pm.i_fwrd_g; +gu1 = dr_np.ghu(i_fwrd_g,:); +ghuu = dr_np.ghuu; + +resid = resid1+0.5*(d1(:,i_fwrd_f1)*ghuu(i_fwrd_g,:)+d2(:,i_fwrd_f2)* ... + kron(gu1,gu1))*vec(M.Sigma_e); + +if nargout > 1 + [resid1,d1,d2,d3] = feval([M.fname '_dynamic'],z,... [oo.exo_simul ... oo.exo_det_simul], M.params, dr.ys, 2); + - if isfield(options,'portfolio') && options.portfolio == 1 - eq_np = pm.eq_np; - - d1_np = d1(eq_np,pm.i_d1_np); - d2_np = d2(eq_np,pm.i_d2_np); - - M_np = pm.M_np; - dr_np = pm.dr_np; - - [dr_np,info] = dyn_first_order_solver(d1_np,pm.M_np,pm.dr_np,options,0); - if info - print_info(info, 0, options); - return - end - - dr_np = dyn_second_order_solver(d1_np,d2_np,dr_np,pm.M_np,... - options.threads.kronecker.A_times_B_kronecker_C,... - options.threads.kronecker.sparse_hessian_times_B_kronecker_C); - end + [a,b,c] = find(d2(eq_np,pm.i_d2_np)); + d2_np = [a b c]; - i_fwrd_f1 = pm.i_fwrd_f1; - i_fwrd_f2 = pm.i_fwrd_f2; - i_fwrd_f3 = pm.i_fwrd_f3; - i_fwrd_g = pm.i_fwrd_g; - gu1 = dr_np.ghu(i_fwrd_g,:); - ghuu = dr_np.ghuu; + [a,b,c] = find(d3(eq_np,pm.i_d3_np)); + d3_np = [a b c]; - resid = resid1+0.5*(d1(:,i_fwrd_f1)*ghuu(i_fwrd_g,:)+d2(:,i_fwrd_f2)* ... - kron(gu1,gu1))*vec(M.Sigma_e); - - if nargout > 1 - [resid1,d1,d2,d3] = feval([M.fname '_dynamic'],z,... - [oo.exo_simul ... - oo.exo_det_simul], M.params, dr.ys, 2); - - - [a,b,c] = find(d2(eq_np,pm.i_d2_np)); - d2_np = [a b c]; - - [a,b,c] = find(d3(eq_np,pm.i_d3_np)); - d3_np = [a b c]; - - options.order = 3; - % space holder, unused by k_order_pertrubation - dr_np.ys = dr.ys(pm.v_np); - nu2 = exo_nbr*(exo_nbr+1)/2; - nu3 = exo_nbr*(exo_nbr+1)*(exo_nbr+2)/3; - M_np.NZZDerivatives = [nnz(d1_np); nnz(d2_np); nnz(d3_np)]; - [err,g_0, g_1, g_2, g_3] = k_order_perturbation(dr_np,M_np,options,d1_np,d2_np,d3_np); - mexErrCheck('k_order_perturbation', err); - - gu1 = g_1(i_fwrd_g,end-exo_nbr+1:end); - ghuu = unfold2(g_2(:,end-nu2+1:end),exo_nbr); - ghsuu = get_ghsuu(g_3,size(g_1,2),exo_nbr); - - i_fwrd1_f2 = pm.i_fwrd1_f2; - i_fwrd1_f3 = pm.i_fwrd1_f3; - n = size(d1,2); - d1b = d1 + 0.5*( ... - d1(:,i_fwrd_f1)*... - d2(:,i_fwrd1_f2)*kron(eye(n),dr_np.ghuu(i_fwrd_g,:)*vec(M.Sigma_e))... - + 0.5*d3(:,i_fwrd1_f3)*kron(eye(n),kron(gu1,gu1)*vec(M.Sigma_e))); - format short - kk1 = [nonzeros(M.lead_lag_incidence(:,1:6)'); ... - nnz(M.lead_lag_incidence)+[1; 2]] - kk2 = [nonzeros(M.lead_lag_incidence(:,1:6)'); ... - nnz(M.lead_lag_incidence)+[3; 4]] - format short - gu1 - kron(gu1,gu1)*vec(M.Sigma_e) - disp(d1(:,:)) - disp(d1b(:,:)) - aa2=d2(:,i_fwrd1_f2)*kron(eye(n),dr_np.ghuu(i_fwrd_g,:)*vec(M.Sigma_e)); - aa3=d3(:,i_fwrd1_f3)*kron(eye(n),kron(gu1,gu1)*vec(M.Sigma_e)); - disp(d3(4,7+6*n+6*n*n)) - disp(d3(4,8+16*n+17*n*n)) %8,17,18 - disp(d3(4,8+17*n+16*n*n)) %8,17,18 - disp(d3(4,7*n+17+17*n*n)) %8,17,18 - disp(d3(4,7*n+18+16*n*n)) %8,17,18 - disp(d3(4,7*n*n+16*n+18)) %8,17,18 - disp(d3(4,7*n*n+17+17*n)) %8,17,18 - pause - disp(aa2(:,kk1)) - disp(aa2(:,kk2)) - disp(aa3(:,kk1)) - disp(aa3(:,kk2)) - [dr,info] = dyn_first_order_solver(d1b,M,dr,options,0); - if info - print_info(info, 0, options); - return - end - - disp_dr(dr,dr.order_var,[]); - + options.order = 3; + % space holder, unused by k_order_pertrubation + dr_np.ys = dr.ys(pm.v_np); + nu2 = exo_nbr*(exo_nbr+1)/2; + nu3 = exo_nbr*(exo_nbr+1)*(exo_nbr+2)/3; + M_np.NZZDerivatives = [nnz(d1_np); nnz(d2_np); nnz(d3_np)]; + [err,g_0, g_1, g_2, g_3] = k_order_perturbation(dr_np,M_np,options,d1_np,d2_np,d3_np); + mexErrCheck('k_order_perturbation', err); + + gu1 = g_1(i_fwrd_g,end-exo_nbr+1:end); + ghuu = unfold2(g_2(:,end-nu2+1:end),exo_nbr); + ghsuu = get_ghsuu(g_3,size(g_1,2),exo_nbr); + + i_fwrd1_f2 = pm.i_fwrd1_f2; + i_fwrd1_f3 = pm.i_fwrd1_f3; + n = size(d1,2); + d1b = d1 + 0.5*( ... + d1(:,i_fwrd_f1)*... + d2(:,i_fwrd1_f2)*kron(eye(n),dr_np.ghuu(i_fwrd_g,:)*vec(M.Sigma_e))... + + 0.5*d3(:,i_fwrd1_f3)*kron(eye(n),kron(gu1,gu1)*vec(M.Sigma_e))); + format short + kk1 = [nonzeros(M.lead_lag_incidence(:,1:6)'); ... + nnz(M.lead_lag_incidence)+[1; 2]] + kk2 = [nonzeros(M.lead_lag_incidence(:,1:6)'); ... + nnz(M.lead_lag_incidence)+[3; 4]] + format short + gu1 + kron(gu1,gu1)*vec(M.Sigma_e) + disp(d1(:,:)) + disp(d1b(:,:)) + aa2=d2(:,i_fwrd1_f2)*kron(eye(n),dr_np.ghuu(i_fwrd_g,:)*vec(M.Sigma_e)); + aa3=d3(:,i_fwrd1_f3)*kron(eye(n),kron(gu1,gu1)*vec(M.Sigma_e)); + disp(d3(4,7+6*n+6*n*n)) + disp(d3(4,8+16*n+17*n*n)) %8,17,18 + disp(d3(4,8+17*n+16*n*n)) %8,17,18 + disp(d3(4,7*n+17+17*n*n)) %8,17,18 + disp(d3(4,7*n+18+16*n*n)) %8,17,18 + disp(d3(4,7*n*n+16*n+18)) %8,17,18 + disp(d3(4,7*n*n+17+17*n)) %8,17,18 + pause + disp(aa2(:,kk1)) + disp(aa2(:,kk2)) + disp(aa3(:,kk1)) + disp(aa3(:,kk2)) + [dr,info] = dyn_first_order_solver(d1b,M,dr,options,0); + if info + print_info(info, 0, options); + return end + + disp_dr(dr,dr.order_var,[]); + +end end function y=unfold2(x,n) - y = zeros(size(x,1),n*n); - k = 1; - for i=1:n - for j=i:n - y(:,(i-1)*n+j) = x(:,k); - if i ~= j - y(:,(j-1)*n+i) = x(:,k); - end - k = k+1; +y = zeros(size(x,1),n*n); +k = 1; +for i=1:n + for j=i:n + y(:,(i-1)*n+j) = x(:,k); + if i ~= j + y(:,(j-1)*n+i) = x(:,k); end + k = k+1; end end +end function y=unfold3(x,n) - y = zeros(size(x,1),n*n*n); - k = 1; - for i=1:n - for j=i:n - for m=j:n - y(:,(i-1)*n*n+(j-1)*n+m) = x(:,k); - y(:,(i-1)*n*n+(m-1)*n+j) = x(:,k); - y(:,(j-1)*n*n+(i-1)*n+m) = x(:,k); - y(:,(j-1)*n*n+(m-1)*n+i) = x(:,k); - y(:,(m-1)*n*n+(i-1)*n+j) = x(:,k); - y(:,(m-1)*n*n+(j-1)*n+i) = x(:,k); - - k = k+1; - end +y = zeros(size(x,1),n*n*n); +k = 1; +for i=1:n + for j=i:n + for m=j:n + y(:,(i-1)*n*n+(j-1)*n+m) = x(:,k); + y(:,(i-1)*n*n+(m-1)*n+j) = x(:,k); + y(:,(j-1)*n*n+(i-1)*n+m) = x(:,k); + y(:,(j-1)*n*n+(m-1)*n+i) = x(:,k); + y(:,(m-1)*n*n+(i-1)*n+j) = x(:,k); + y(:,(m-1)*n*n+(j-1)*n+i) = x(:,k); + + k = k+1; end end end +end function pm = model_structure(M,options) - lead_index = M.maximum_endo_lag+2; - lead_lag_incidence = M.lead_lag_incidence; - dr = struct(); - dr = set_state_space(dr,M,options); - pm.i_fwrd_g = find(lead_lag_incidence(lead_index,dr.order_var)'); - - i_fwrd_f1 = nonzeros(lead_lag_incidence(lead_index,dr.order_var)); - pm.i_fwrd_f1 = i_fwrd_f1; - n = nnz(lead_lag_incidence)+M.exo_nbr; - ih = reshape(1:n*n,n,n); - i_fwrd_f2 = ih(i_fwrd_f1,i_fwrd_f1); - pm.i_fwrd_f2 = i_fwrd_f2(:); - i_fwrd1_f2 = ih(i_fwrd_f1,:); - pm.i_fwrd1_f2 = i_fwrd1_f2(:); - - ih = reshape(1:n*n*n,n,n,n); - i_fwrd_f3 = ih(i_fwrd_f1,i_fwrd_f1,i_fwrd_f1); - pm.i_fwrd_f3 = i_fwrd_f3(:); - i_fwrd1_f3 = ih(i_fwrd_f1,i_fwrd_f1,:); - pm.i_fwrd1_f3 = i_fwrd1_f3(:); +lead_index = M.maximum_endo_lag+2; +lead_lag_incidence = M.lead_lag_incidence; +dr = struct(); +dr = set_state_space(dr,M,options); +pm.i_fwrd_g = find(lead_lag_incidence(lead_index,dr.order_var)'); + +i_fwrd_f1 = nonzeros(lead_lag_incidence(lead_index,dr.order_var)); +pm.i_fwrd_f1 = i_fwrd_f1; +n = nnz(lead_lag_incidence)+M.exo_nbr; +ih = reshape(1:n*n,n,n); +i_fwrd_f2 = ih(i_fwrd_f1,i_fwrd_f1); +pm.i_fwrd_f2 = i_fwrd_f2(:); +i_fwrd1_f2 = ih(i_fwrd_f1,:); +pm.i_fwrd1_f2 = i_fwrd1_f2(:); + +ih = reshape(1:n*n*n,n,n,n); +i_fwrd_f3 = ih(i_fwrd_f1,i_fwrd_f1,i_fwrd_f1); +pm.i_fwrd_f3 = i_fwrd_f3(:); +i_fwrd1_f3 = ih(i_fwrd_f1,i_fwrd_f1,:); +pm.i_fwrd1_f3 = i_fwrd1_f3(:); end function pm = portfolio_model_structure(M,options) - i_d3_np = []; - i_d3_p = []; - - lead_index = M.maximum_endo_lag+2; - lead_lag_incidence = M.lead_lag_incidence; - eq_tags = M.equations_tags; - n_tags = size(eq_tags,1); - eq_p = cell2mat(eq_tags(strcmp(eq_tags(:,2), ... - 'portfolio'),1)); - pm.eq_p = eq_p; - pm.eq_np = setdiff(1:M.endo_nbr,eq_p); - v_p = zeros(n_tags,1); - for i=1:n_tags - v_p(i) = find(strncmp(eq_tags(i,3),M.endo_names, ... - length(cell2mat(eq_tags(i,3))))); - end - if any(lead_lag_incidence(lead_index,v_p)) - error(['portfolio variables appear in the model as forward ' ... - 'variable']) - end - pm.v_p = v_p; - v_np = setdiff(1:M.endo_nbr,v_p); - pm.v_np = v_np; - lli_np = lead_lag_incidence(:,v_np)'; - k = find(lli_np); - lead_lag_incidence_np = lli_np; - lead_lag_incidence_np(k) = 1:nnz(lli_np); - lead_lag_incidence_np = lead_lag_incidence_np'; - pm.lead_lag_incidence_np = lead_lag_incidence_np; - i_d1_np = [nonzeros(lli_np); nnz(lead_lag_incidence)+(1:M.exo_nbr)']; - pm.i_d1_np = i_d1_np; - - n = nnz(lead_lag_incidence)+M.exo_nbr; - ih = reshape(1:n*n,n,n); - i_d2_np = ih(i_d1_np,i_d1_np); - pm.i_d2_np = i_d2_np(:); - - ih = reshape(1:n*n*n,n,n,n); - i_d3_np = ih(i_d1_np,i_d1_np,i_d1_np); - pm.i_d3_np = i_d3_np(:); - - M_np = M; - M_np.lead_lag_incidence = lead_lag_incidence_np; - M_np.lead_lag_incidence = lead_lag_incidence_np; - M_np.endo_nbr = length(v_np); - M_np.endo_names = M.endo_names(v_np,:); - dr_np = struct(); - dr_np = set_state_space(dr_np,M_np,options); - pm.dr_np = dr_np; - M_np.var_order_endo_names = M_np.endo_names(dr_np.order_var,:); - pm.M_np = M_np; - pm.i_fwrd_g = find(lead_lag_incidence_np(lead_index,dr_np.order_var)'); - - i_fwrd_f1 = nonzeros(lead_lag_incidence(lead_index,:)); - pm.i_fwrd_f1 = i_fwrd_f1; - n = nnz(lead_lag_incidence)+M.exo_nbr; - ih = reshape(1:n*n,n,n); - i_fwrd_f2 = ih(i_fwrd_f1,i_fwrd_f1); - pm.i_fwrd_f2 = i_fwrd_f2(:); - i_fwrd1_f2 = ih(i_fwrd_f1,:); - pm.i_fwrd1_f2 = i_fwrd1_f2(:); - - ih = reshape(1:n*n*n,n,n,n); - i_fwrd_f3 = ih(i_fwrd_f1,i_fwrd_f1,i_fwrd_f1); - pm.i_fwrd_f3 = i_fwrd_f3(:); - i_fwrd1_f3 = ih(i_fwrd_f1,i_fwrd_f1,:); - pm.i_fwrd1_f3 = i_fwrd1_f3(:); +i_d3_np = []; +i_d3_p = []; + +lead_index = M.maximum_endo_lag+2; +lead_lag_incidence = M.lead_lag_incidence; +eq_tags = M.equations_tags; +n_tags = size(eq_tags,1); +eq_p = cell2mat(eq_tags(strcmp(eq_tags(:,2), ... + 'portfolio'),1)); +pm.eq_p = eq_p; +pm.eq_np = setdiff(1:M.endo_nbr,eq_p); +v_p = zeros(n_tags,1); +for i=1:n_tags + v_p(i) = find(strncmp(eq_tags(i,3),M.endo_names, ... + length(cell2mat(eq_tags(i,3))))); +end +if any(lead_lag_incidence(lead_index,v_p)) + error(['portfolio variables appear in the model as forward ' ... + 'variable']) +end +pm.v_p = v_p; +v_np = setdiff(1:M.endo_nbr,v_p); +pm.v_np = v_np; +lli_np = lead_lag_incidence(:,v_np)'; +k = find(lli_np); +lead_lag_incidence_np = lli_np; +lead_lag_incidence_np(k) = 1:nnz(lli_np); +lead_lag_incidence_np = lead_lag_incidence_np'; +pm.lead_lag_incidence_np = lead_lag_incidence_np; +i_d1_np = [nonzeros(lli_np); nnz(lead_lag_incidence)+(1:M.exo_nbr)']; +pm.i_d1_np = i_d1_np; + +n = nnz(lead_lag_incidence)+M.exo_nbr; +ih = reshape(1:n*n,n,n); +i_d2_np = ih(i_d1_np,i_d1_np); +pm.i_d2_np = i_d2_np(:); + +ih = reshape(1:n*n*n,n,n,n); +i_d3_np = ih(i_d1_np,i_d1_np,i_d1_np); +pm.i_d3_np = i_d3_np(:); + +M_np = M; +M_np.lead_lag_incidence = lead_lag_incidence_np; +M_np.lead_lag_incidence = lead_lag_incidence_np; +M_np.endo_nbr = length(v_np); +M_np.endo_names = M.endo_names(v_np,:); +dr_np = struct(); +dr_np = set_state_space(dr_np,M_np,options); +pm.dr_np = dr_np; +M_np.var_order_endo_names = M_np.endo_names(dr_np.order_var,:); +pm.M_np = M_np; +pm.i_fwrd_g = find(lead_lag_incidence_np(lead_index,dr_np.order_var)'); + +i_fwrd_f1 = nonzeros(lead_lag_incidence(lead_index,:)); +pm.i_fwrd_f1 = i_fwrd_f1; +n = nnz(lead_lag_incidence)+M.exo_nbr; +ih = reshape(1:n*n,n,n); +i_fwrd_f2 = ih(i_fwrd_f1,i_fwrd_f1); +pm.i_fwrd_f2 = i_fwrd_f2(:); +i_fwrd1_f2 = ih(i_fwrd_f1,:); +pm.i_fwrd1_f2 = i_fwrd1_f2(:); + +ih = reshape(1:n*n*n,n,n,n); +i_fwrd_f3 = ih(i_fwrd_f1,i_fwrd_f1,i_fwrd_f1); +pm.i_fwrd_f3 = i_fwrd_f3(:); +i_fwrd1_f3 = ih(i_fwrd_f1,i_fwrd_f1,:); +pm.i_fwrd1_f3 = i_fwrd1_f3(:); end function r=ds_static_model(y0,f_h,p0,eq_np,v_np,v_p,endo_nbr,exo_nbr,params) - ys = zeros(endo_nbr,1); - ys(v_p) = p0; - ys(v_np) = y0; - r = f_h(ys,zeros(exo_nbr,1),params); - r = r(eq_np); +ys = zeros(endo_nbr,1); +ys(v_p) = p0; +ys(v_np) = y0; +r = f_h(ys,zeros(exo_nbr,1),params); +r = r(eq_np); end function ghsuu = get_ghsuu(g,ns,nx) - nxx = nx*(nx+1)/2; - m1 = 0; - m2 = ns*(ns+1)/2; - kk = 1:(nx*nx); - ghsuu = zeros(size(g,1),(ns*nx*nx)); - - for i=1:n - j = m1+(1:m2); - k = j(end-nxx+1:end); - ghsuu(:,kk) = unfold2(g(:,k),nx); - m1 = m1+m2; - m2 = m2 - (n-i+1); - kk = kk + nx*nx; - end +nxx = nx*(nx+1)/2; +m1 = 0; +m2 = ns*(ns+1)/2; +kk = 1:(nx*nx); +ghsuu = zeros(size(g,1),(ns*nx*nx)); + +for i=1:n + j = m1+(1:m2); + k = j(end-nxx+1:end); + ghsuu(:,kk) = unfold2(g(:,k),nx); + m1 = m1+m2; + m2 = m2 - (n-i+1); + kk = kk + nx*nx; +end end \ No newline at end of file diff --git a/matlab/dyn_saveas.m b/matlab/dyn_saveas.m index a31c724b2e..fb70bab755 100644 --- a/matlab/dyn_saveas.m +++ b/matlab/dyn_saveas.m @@ -53,19 +53,19 @@ if any(strcmp('fig',cellstr(graph_format))) error('Octave cannot create fig files!') else if nodisplay -% THE FOLLOWING LINES COULD BE USED IF BUGS/PROBLEMS ARE REPORTED USING LINE 60 -% set(h,'Units','Normalized') -% mypos=get(h,'Position'); -% set(h,'Position',[-1 -1 mypos(3:4)]) -% set(h, 'Visible','on'); + % THE FOLLOWING LINES COULD BE USED IF BUGS/PROBLEMS ARE REPORTED USING LINE 60 + % set(h,'Units','Normalized') + % mypos=get(h,'Position'); + % set(h,'Position',[-1 -1 mypos(3:4)]) + % set(h, 'Visible','on'); set(h,'CreateFcn','set(gcf, ''Visible'',''on'')') ; end saveas(h,[fname '.fig']); end end if any(strcmp('none',cellstr(graph_format))) -% don't save -% check here as a reminder that none is an option to graph_format + % don't save + % check here as a reminder that none is an option to graph_format end if nodisplay close(h); diff --git a/matlab/dyn_second_order_solver.m b/matlab/dyn_second_order_solver.m index dd2d2bfb8e..37e13f8412 100644 --- a/matlab/dyn_second_order_solver.m +++ b/matlab/dyn_second_order_solver.m @@ -48,135 +48,135 @@ function dr = dyn_second_order_solver(jacobia,hessian_mat,dr,M_,threads_ABC,thre % % You should have received a copy of the GNU General Public License % along with Dynare. If not, see <http://www.gnu.org/licenses/>. - - dr.ghxx = []; - dr.ghuu = []; - dr.ghxu = []; - dr.ghs2 = []; - Gy = dr.Gy; - - kstate = dr.kstate; - nstatic = M_.nstatic; - nfwrd = M_.nfwrd; - nspred = M_.nspred; - nboth = M_.nboth; - nsfwrd = M_.nsfwrd; - order_var = dr.order_var; - nd = size(kstate,1); - lead_lag_incidence = M_.lead_lag_incidence; - - np = nd - nsfwrd; - - k1 = nonzeros(lead_lag_incidence(:,order_var)'); - kk = [k1; length(k1)+(1:M_.exo_nbr+M_.exo_det_nbr)']; - nk = size(kk,1); - kk1 = reshape([1:nk^2],nk,nk); - kk1 = kk1(kk,kk); - % reordering second order derivatives - hessian_mat = hessian_mat(:,kk1(:)); - - zx = zeros(np,np); - zu=zeros(np,M_.exo_nbr); - zx(1:np,:)=eye(np); - k0 = [1:M_.endo_nbr]; - gx1 = dr.ghx; - hu = dr.ghu(nstatic+[1:nspred],:); - k0 = find(lead_lag_incidence(M_.maximum_endo_lag+1,order_var)'); - zx = [zx; gx1(k0,:)]; - zu = [zu; dr.ghu(k0,:)]; - k1 = find(lead_lag_incidence(M_.maximum_endo_lag+2,order_var)'); - zu = [zu; gx1(k1,:)*hu]; - zx = [zx; gx1(k1,:)*Gy]; - zx=[zx; zeros(M_.exo_nbr,np);zeros(M_.exo_det_nbr,np)]; - zu=[zu; eye(M_.exo_nbr);zeros(M_.exo_det_nbr,M_.exo_nbr)]; - [nrzx,nczx] = size(zx); - - [rhs, err] = sparse_hessian_times_B_kronecker_C(hessian_mat,zx,threads_BC); - mexErrCheck('sparse_hessian_times_B_kronecker_C', err); - rhs = -rhs; - - %lhs - n = M_.endo_nbr+sum(kstate(:,2) > M_.maximum_endo_lag+1 & kstate(:,2) < M_.maximum_endo_lag+M_.maximum_endo_lead+1); - A = zeros(M_.endo_nbr,M_.endo_nbr); - B = zeros(M_.endo_nbr,M_.endo_nbr); - A(:,k0) = jacobia(:,nonzeros(lead_lag_incidence(M_.maximum_endo_lag+1,order_var))); - % variables with the highest lead - k1 = find(kstate(:,2) == M_.maximum_endo_lag+2); - % Jacobian with respect to the variables with the highest lead - fyp = jacobia(:,kstate(k1,3)+nnz(M_.lead_lag_incidence(M_.maximum_endo_lag+1,:))); - B(:,nstatic+M_.npred+1:end) = fyp; - [junk,k1,k2] = find(M_.lead_lag_incidence(M_.maximum_endo_lag+M_.maximum_endo_lead+1,order_var)); - A(1:M_.endo_nbr,nstatic+1:nstatic+nspred)=... - A(1:M_.endo_nbr,nstatic+[1:nspred])+fyp*gx1(k1,1:nspred); - C = Gy; - D = [rhs; zeros(n-M_.endo_nbr,size(rhs,2))]; - - - [err, dr.ghxx] = gensylv(2,A,B,C,D); - mexErrCheck('gensylv', err); - - %ghxu - %rhs - hu = dr.ghu(nstatic+1:nstatic+nspred,:); - [rhs, err] = sparse_hessian_times_B_kronecker_C(hessian_mat,zx,zu,threads_BC); - mexErrCheck('sparse_hessian_times_B_kronecker_C', err); - - hu1 = [hu;zeros(np-nspred,M_.exo_nbr)]; - [nrhx,nchx] = size(Gy); - [nrhu1,nchu1] = size(hu1); - - [abcOut,err] = A_times_B_kronecker_C(dr.ghxx,Gy,hu1,threads_ABC); - mexErrCheck('A_times_B_kronecker_C', err); - B1 = B*abcOut; - rhs = -[rhs; zeros(n-M_.endo_nbr,size(rhs,2))]-B1; - - - %lhs - dr.ghxu = A\rhs; - - %ghuu - %rhs - [rhs, err] = sparse_hessian_times_B_kronecker_C(hessian_mat,zu,threads_BC); - mexErrCheck('sparse_hessian_times_B_kronecker_C', err); - - [B1, err] = A_times_B_kronecker_C(B*dr.ghxx,hu1,threads_ABC); - mexErrCheck('A_times_B_kronecker_C', err); - rhs = -[rhs; zeros(n-M_.endo_nbr,size(rhs,2))]-B1; - - %lhs - dr.ghuu = A\rhs; - - % dr.ghs2 - % derivatives of F with respect to forward variables - % reordering predetermined variables in diminishing lag order - O1 = zeros(M_.endo_nbr,nstatic); - O2 = zeros(M_.endo_nbr,M_.endo_nbr-nstatic-nspred); - LHS = zeros(M_.endo_nbr,M_.endo_nbr); - LHS(:,k0) = jacobia(:,nonzeros(lead_lag_incidence(M_.maximum_endo_lag+1,order_var))); - RHS = zeros(M_.endo_nbr,M_.exo_nbr^2); - gu = dr.ghu; - guu = dr.ghuu; - E = eye(M_.endo_nbr); - kh = reshape([1:nk^2],nk,nk); - kp = sum(kstate(:,2) <= M_.maximum_endo_lag+1); - E1 = [eye(nspred); zeros(kp-nspred,nspred)]; - H = E1; - hxx = dr.ghxx(nstatic+[1:nspred],:); - [junk,k2a,k2] = find(M_.lead_lag_incidence(M_.maximum_endo_lag+2,order_var)); - k3 = nnz(M_.lead_lag_incidence(1:M_.maximum_endo_lag+1,:))+(1:M_.nsfwrd)'; - [B1, err] = sparse_hessian_times_B_kronecker_C(hessian_mat(:,kh(k3,k3)),gu(k2a,:),threads_BC); - mexErrCheck('sparse_hessian_times_B_kronecker_C', err); - RHS = RHS + jacobia(:,k2)*guu(k2a,:)+B1; - - % LHS - LHS = LHS + jacobia(:,k2)*(E(k2a,:)+[O1(k2a,:) dr.ghx(k2a,:)*H O2(k2a,:)]); - - RHS = RHS*M_.Sigma_e(:); - dr.fuu = RHS; - %RHS = -RHS-dr.fbias; - RHS = -RHS; - dr.ghs2 = LHS\RHS; - - % deterministic exogenous variables - if M_.exo_det_nbr > 0 - end + +dr.ghxx = []; +dr.ghuu = []; +dr.ghxu = []; +dr.ghs2 = []; +Gy = dr.Gy; + +kstate = dr.kstate; +nstatic = M_.nstatic; +nfwrd = M_.nfwrd; +nspred = M_.nspred; +nboth = M_.nboth; +nsfwrd = M_.nsfwrd; +order_var = dr.order_var; +nd = size(kstate,1); +lead_lag_incidence = M_.lead_lag_incidence; + +np = nd - nsfwrd; + +k1 = nonzeros(lead_lag_incidence(:,order_var)'); +kk = [k1; length(k1)+(1:M_.exo_nbr+M_.exo_det_nbr)']; +nk = size(kk,1); +kk1 = reshape([1:nk^2],nk,nk); +kk1 = kk1(kk,kk); +% reordering second order derivatives +hessian_mat = hessian_mat(:,kk1(:)); + +zx = zeros(np,np); +zu=zeros(np,M_.exo_nbr); +zx(1:np,:)=eye(np); +k0 = [1:M_.endo_nbr]; +gx1 = dr.ghx; +hu = dr.ghu(nstatic+[1:nspred],:); +k0 = find(lead_lag_incidence(M_.maximum_endo_lag+1,order_var)'); +zx = [zx; gx1(k0,:)]; +zu = [zu; dr.ghu(k0,:)]; +k1 = find(lead_lag_incidence(M_.maximum_endo_lag+2,order_var)'); +zu = [zu; gx1(k1,:)*hu]; +zx = [zx; gx1(k1,:)*Gy]; +zx=[zx; zeros(M_.exo_nbr,np);zeros(M_.exo_det_nbr,np)]; +zu=[zu; eye(M_.exo_nbr);zeros(M_.exo_det_nbr,M_.exo_nbr)]; +[nrzx,nczx] = size(zx); + +[rhs, err] = sparse_hessian_times_B_kronecker_C(hessian_mat,zx,threads_BC); +mexErrCheck('sparse_hessian_times_B_kronecker_C', err); +rhs = -rhs; + +%lhs +n = M_.endo_nbr+sum(kstate(:,2) > M_.maximum_endo_lag+1 & kstate(:,2) < M_.maximum_endo_lag+M_.maximum_endo_lead+1); +A = zeros(M_.endo_nbr,M_.endo_nbr); +B = zeros(M_.endo_nbr,M_.endo_nbr); +A(:,k0) = jacobia(:,nonzeros(lead_lag_incidence(M_.maximum_endo_lag+1,order_var))); +% variables with the highest lead +k1 = find(kstate(:,2) == M_.maximum_endo_lag+2); +% Jacobian with respect to the variables with the highest lead +fyp = jacobia(:,kstate(k1,3)+nnz(M_.lead_lag_incidence(M_.maximum_endo_lag+1,:))); +B(:,nstatic+M_.npred+1:end) = fyp; +[junk,k1,k2] = find(M_.lead_lag_incidence(M_.maximum_endo_lag+M_.maximum_endo_lead+1,order_var)); +A(1:M_.endo_nbr,nstatic+1:nstatic+nspred)=... + A(1:M_.endo_nbr,nstatic+[1:nspred])+fyp*gx1(k1,1:nspred); +C = Gy; +D = [rhs; zeros(n-M_.endo_nbr,size(rhs,2))]; + + +[err, dr.ghxx] = gensylv(2,A,B,C,D); +mexErrCheck('gensylv', err); + +%ghxu +%rhs +hu = dr.ghu(nstatic+1:nstatic+nspred,:); +[rhs, err] = sparse_hessian_times_B_kronecker_C(hessian_mat,zx,zu,threads_BC); +mexErrCheck('sparse_hessian_times_B_kronecker_C', err); + +hu1 = [hu;zeros(np-nspred,M_.exo_nbr)]; +[nrhx,nchx] = size(Gy); +[nrhu1,nchu1] = size(hu1); + +[abcOut,err] = A_times_B_kronecker_C(dr.ghxx,Gy,hu1,threads_ABC); +mexErrCheck('A_times_B_kronecker_C', err); +B1 = B*abcOut; +rhs = -[rhs; zeros(n-M_.endo_nbr,size(rhs,2))]-B1; + + +%lhs +dr.ghxu = A\rhs; + +%ghuu +%rhs +[rhs, err] = sparse_hessian_times_B_kronecker_C(hessian_mat,zu,threads_BC); +mexErrCheck('sparse_hessian_times_B_kronecker_C', err); + +[B1, err] = A_times_B_kronecker_C(B*dr.ghxx,hu1,threads_ABC); +mexErrCheck('A_times_B_kronecker_C', err); +rhs = -[rhs; zeros(n-M_.endo_nbr,size(rhs,2))]-B1; + +%lhs +dr.ghuu = A\rhs; + +% dr.ghs2 +% derivatives of F with respect to forward variables +% reordering predetermined variables in diminishing lag order +O1 = zeros(M_.endo_nbr,nstatic); +O2 = zeros(M_.endo_nbr,M_.endo_nbr-nstatic-nspred); +LHS = zeros(M_.endo_nbr,M_.endo_nbr); +LHS(:,k0) = jacobia(:,nonzeros(lead_lag_incidence(M_.maximum_endo_lag+1,order_var))); +RHS = zeros(M_.endo_nbr,M_.exo_nbr^2); +gu = dr.ghu; +guu = dr.ghuu; +E = eye(M_.endo_nbr); +kh = reshape([1:nk^2],nk,nk); +kp = sum(kstate(:,2) <= M_.maximum_endo_lag+1); +E1 = [eye(nspred); zeros(kp-nspred,nspred)]; +H = E1; +hxx = dr.ghxx(nstatic+[1:nspred],:); +[junk,k2a,k2] = find(M_.lead_lag_incidence(M_.maximum_endo_lag+2,order_var)); +k3 = nnz(M_.lead_lag_incidence(1:M_.maximum_endo_lag+1,:))+(1:M_.nsfwrd)'; +[B1, err] = sparse_hessian_times_B_kronecker_C(hessian_mat(:,kh(k3,k3)),gu(k2a,:),threads_BC); +mexErrCheck('sparse_hessian_times_B_kronecker_C', err); +RHS = RHS + jacobia(:,k2)*guu(k2a,:)+B1; + +% LHS +LHS = LHS + jacobia(:,k2)*(E(k2a,:)+[O1(k2a,:) dr.ghx(k2a,:)*H O2(k2a,:)]); + +RHS = RHS*M_.Sigma_e(:); +dr.fuu = RHS; +%RHS = -RHS-dr.fbias; +RHS = -RHS; +dr.ghs2 = LHS\RHS; + +% deterministic exogenous variables +if M_.exo_det_nbr > 0 +end diff --git a/matlab/dyn_waitbar.m b/matlab/dyn_waitbar.m index f9665c9509..5b315a5d1d 100644 --- a/matlab/dyn_waitbar.m +++ b/matlab/dyn_waitbar.m @@ -45,7 +45,7 @@ end if ~whoiam if isoctave || options_.console_mode - + if init, diary off; running_text = varargin{1}; diff --git a/matlab/dynare.m b/matlab/dynare.m index 3ab08aef48..38dbe1b4c1 100644 --- a/matlab/dynare.m +++ b/matlab/dynare.m @@ -111,7 +111,7 @@ if isempty(strfind(fname,'.')) % Checking file extension else if dot_location~=length(fname)-3 ... %if the file name has fewer than 4 characters and there is a period - || ~strcmp(upper(fname(size(fname,2)-3:size(fname,2))),'.MOD') ... + || ~strcmp(upper(fname(size(fname,2)-3:size(fname,2))),'.MOD') ... && ~strcmp(upper(fname(size(fname,2)-3:size(fname,2))),'.DYN') error('DYNARE: argument must be a filename with .mod or .dyn extension and must not include any other periods') end; @@ -176,11 +176,11 @@ else end if isempty(strfind(arch, '64')) - arch_ext = '32'; - disp('Using 32-bit preprocessor'); + arch_ext = '32'; + disp('Using 32-bit preprocessor'); else - arch_ext = '64'; - disp('Using 64-bit preprocessor'); + arch_ext = '64'; + disp('Using 64-bit preprocessor'); end command = ['"' dynareroot 'preprocessor' arch_ext filesep 'dynare_m" ' fname] ; diff --git a/matlab/dynare_config.m b/matlab/dynare_config.m index 5b2f34b9e5..342a03c4b7 100644 --- a/matlab/dynare_config.m +++ b/matlab/dynare_config.m @@ -115,7 +115,7 @@ end % nanmean is in Octave Forge Statistics package and in MATLAB Statistics % toolbox if (isoctave && ~user_has_octave_forge_package('statistics')) ... - || (~isoctave && ~user_has_matlab_license('statistics_toolbox')) + || (~isoctave && ~user_has_matlab_license('statistics_toolbox')) p{end+1} = '/missing/nanmean'; end diff --git a/matlab/dynare_estimation.m b/matlab/dynare_estimation.m index 5d140bd189..a476a8072c 100644 --- a/matlab/dynare_estimation.m +++ b/matlab/dynare_estimation.m @@ -33,7 +33,7 @@ global options_ oo_ M_ dataset_ dataset_info oo_recursive_={}; mode_file0 = options_.mode_file; % store mode_file set by the user -% Test if the order of approximation is nonzero (the preprocessor tests if order is non negative). + % Test if the order of approximation is nonzero (the preprocessor tests if order is non negative). if isequal(options_.order,0) error('Estimation:: The order of the Taylor approximation cannot be 0!') end @@ -55,7 +55,7 @@ nfirstobs = length(first_obs); if nnobs~=1 && nfirstobs~=1 error('You cannot simultaneously do rolling window and recursive estimation') end - + horizon = options_.forecast; if nargin<2 || ~exist('dname','var') || isempty(dname) @@ -142,7 +142,7 @@ if nnobs > 1 && horizon > 0 gend = dataset_.nobs; time_offset=min(3,gend-1); %for observables, plot 3 previous periods unless data is shorter k = time_offset+min(nobs(end)-nobs(1)+horizon, ... - size(dataset_.data,1)-nobs(1)); + size(dataset_.data,1)-nobs(1)); data2 = dataset_info.rawdata(end-k+1:end,:); [nbplt,nr,nc,lr,lc,nstar] = pltorg(nvar); m = 1; @@ -167,23 +167,23 @@ if nnobs > 1 && horizon > 0 for j=1:nnobs if mh_replic > 0 oo_.RecursiveForecast.Mean.(vname)(j,:) = ... - oo_recursive_{nobs(j)}.MeanForecast.Mean.(vname); + oo_recursive_{nobs(j)}.MeanForecast.Mean.(vname); oo_.RecursiveForecast.HPDinf.(vname)(j,:) = ... - oo_recursive_{nobs(j)}.MeanForecast.HPDinf.(vname); + oo_recursive_{nobs(j)}.MeanForecast.HPDinf.(vname); oo_.RecursiveForecast.HPDsup.(vname)(j,:) = ... - oo_recursive_{nobs(j)}.MeanForecast.HPDsup.(vname); + oo_recursive_{nobs(j)}.MeanForecast.HPDsup.(vname); oo_.RecursiveForecast.HPDTotalinf.(vname)(j,:) = ... - oo_recursive_{nobs(j)}.PointForecast.HPDinf.(vname); + oo_recursive_{nobs(j)}.PointForecast.HPDinf.(vname); oo_.RecursiveForecast.HPDTotalsup.(vname)(j,:) = ... - oo_recursive_{nobs(j)}.PointForecast.HPDsup.(vname); + oo_recursive_{nobs(j)}.PointForecast.HPDsup.(vname); else oo_.RecursiveForecast.Mean.(vname)(j,:) =... - oo_recursive_{nobs(j)}.forecast.Mean.(vname); + oo_recursive_{nobs(j)}.forecast.Mean.(vname); oo_.RecursiveForecast.HPDinf.(vname)(j,:) =... - oo_recursive_{nobs(j)}.forecast.HPDinf.(vname); + oo_recursive_{nobs(j)}.forecast.HPDinf.(vname); oo_.RecursiveForecast.HPDsup.(vname)(j,:) =... - oo_recursive_{nobs(j)}.forecast.HPDsup.(vname); - end + oo_recursive_{nobs(j)}.forecast.HPDsup.(vname); + end x = nobs(1)+nobs(j)-nobs(1)+(1:horizon); y = oo_.RecursiveForecast.Mean.(vname)(j,:); diff --git a/matlab/dynare_estimation_1.m b/matlab/dynare_estimation_1.m index 0a27271ded..83361af116 100644 --- a/matlab/dynare_estimation_1.m +++ b/matlab/dynare_estimation_1.m @@ -221,7 +221,7 @@ if ~isequal(options_.mode_compute,0) && ~options_.mh_posterior_mode_estimation fprintf('\nFinal value of minus the log posterior (or likelihood):%f \n', fval); if isnumeric(options_.mode_compute) && options_.mode_compute==5 && options_.analytic_derivation==-1 %reset options changed by newrat - options_.analytic_derivation = options_analytic_derivation_old; %reset + options_.analytic_derivation = options_analytic_derivation_old; %reset elseif isnumeric(options_.mode_compute) && options_.mode_compute==6 %save scaling factor save([M_.fname '_optimal_mh_scale_parameter.mat'],'Scale'); options_.mh_jscale = Scale; @@ -233,7 +233,7 @@ if ~isequal(options_.mode_compute,0) && ~options_.mh_posterior_mode_estimation ana_deriv_old = options_.analytic_derivation; options_.analytic_derivation = 2; [junk1, junk2,junk3, junk4, hh] = feval(objective_function,xparam1, ... - dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,bounds,oo_); + dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,bounds,oo_); options_.analytic_derivation = ana_deriv_old; elseif ~isnumeric(options_.mode_compute) || ~(isequal(options_.mode_compute,5) && newratflag~=1), % with flag==0, we force to use the hessian from outer product gradient of optimizer 5 @@ -296,7 +296,7 @@ if ~options_.mh_posterior_mode_estimation && options_.cova_compute params_at_bound=find(abs(xparam1-bounds.ub)<1.e-10 | abs(xparam1-bounds.lb)<1.e-10); if ~isempty(params_at_bound) for ii=1:length(params_at_bound) - params_at_bound_name{ii,1}=get_the_name(params_at_bound(ii),0,M_,estim_params_,options_); + params_at_bound_name{ii,1}=get_the_name(params_at_bound(ii),0,M_,estim_params_,options_); end disp_string=[params_at_bound_name{1,:}]; for ii=2:size(params_at_bound_name,1) @@ -385,36 +385,36 @@ if np > 0 end switch options_.MCMC_jumping_covariance - case 'hessian' %Baseline - %do nothing and use hessian from mode_compute - case 'prior_variance' %Use prior variance - if any(isinf(bayestopt_.p2)) - error('Infinite prior variances detected. You cannot use the prior variances as the proposal density, if some variances are Inf.') - else - hh = diag(1./(bayestopt_.p2.^2)); - end + case 'hessian' %Baseline + %do nothing and use hessian from mode_compute + case 'prior_variance' %Use prior variance + if any(isinf(bayestopt_.p2)) + error('Infinite prior variances detected. You cannot use the prior variances as the proposal density, if some variances are Inf.') + else + hh = diag(1./(bayestopt_.p2.^2)); + end + hsd = sqrt(diag(hh)); + invhess = inv(hh./(hsd*hsd'))./(hsd*hsd'); + case 'identity_matrix' %Use identity + invhess = eye(nx); + otherwise %user specified matrix in file + try + load(options_.MCMC_jumping_covariance,'jumping_covariance') + hh=jumping_covariance; + catch + error(['No matrix named ''jumping_covariance'' could be found in ',options_.MCMC_jumping_covariance,'.mat']) + end + [nrow, ncol]=size(hh); + if ~isequal(nrow,ncol) && ~isequal(nrow,nx) %check if square and right size + error(['jumping_covariance matrix must be square and have ',num2str(nx),' rows and columns']) + end + try %check for positive definiteness + chol(hh); hsd = sqrt(diag(hh)); invhess = inv(hh./(hsd*hsd'))./(hsd*hsd'); - case 'identity_matrix' %Use identity - invhess = eye(nx); - otherwise %user specified matrix in file - try - load(options_.MCMC_jumping_covariance,'jumping_covariance') - hh=jumping_covariance; - catch - error(['No matrix named ''jumping_covariance'' could be found in ',options_.MCMC_jumping_covariance,'.mat']) - end - [nrow, ncol]=size(hh); - if ~isequal(nrow,ncol) && ~isequal(nrow,nx) %check if square and right size - error(['jumping_covariance matrix must be square and have ',num2str(nx),' rows and columns']) - end - try %check for positive definiteness - chol(hh); - hsd = sqrt(diag(hh)); - invhess = inv(hh./(hsd*hsd'))./(hsd*hsd'); - catch - error(['Specified jumping_covariance is not positive definite']) - end + catch + error(['Specified jumping_covariance is not positive definite']) + end end if (any(bayestopt_.pshape >0 ) && options_.mh_replic) || ... @@ -483,9 +483,9 @@ if (any(bayestopt_.pshape >0 ) && options_.mh_replic) || ... elseif options_.load_mh_file && options_.load_results_after_load_mh %% load fields from previous MCMC run stored in results-file field_names={'posterior_mode','posterior_std_at_mode',...% fields set by marginal_density - 'posterior_mean','posterior_hpdinf','posterior_hpdsup','posterior_median','posterior_variance','posterior_std','posterior_deciles','posterior_density',...% fields set by GetPosteriorParametersStatistics - 'prior_density',...%fields set by PlotPosteriorDistributions - }; + 'posterior_mean','posterior_hpdinf','posterior_hpdsup','posterior_median','posterior_variance','posterior_std','posterior_deciles','posterior_density',...% fields set by GetPosteriorParametersStatistics + 'prior_density',...%fields set by PlotPosteriorDistributions + }; for field_iter=1:size(field_names,2) if isfield(oo_load_mh.oo_,field_names{1,field_iter}) oo_.(field_names{1,field_iter})=oo_load_mh.oo_.(field_names{1,field_iter}); @@ -692,76 +692,76 @@ if (~((any(bayestopt_.pshape > 0) && options_.mh_replic) || (any(bayestopt_.psha %% Historical and smoothed variabes %% if ~options_.nograph - [nbplt,nr,nc,lr,lc,nstar] = pltorg(n_varobs); - if options_.TeX && any(strcmp('eps',cellstr(options_.graph_format))) - fidTeX = fopen([M_.fname '_HistoricalAndSmoothedVariables.tex'],'w'); - fprintf(fidTeX,'%% TeX eps-loader file generated by dynare_estimation_1.m (Dynare).\n'); - fprintf(fidTeX,['%% ' datestr(now,0) '\n']); - fprintf(fidTeX,' \n'); - end - for plt = 1:nbplt, - fh = dyn_figure(options_.nodisplay,'Name','Historical and smoothed variables'); - NAMES = []; - if options_.TeX, TeXNAMES = []; end - nstar0=min(nstar,n_varobs-(plt-1)*nstar); - if gend==1 - marker_string{1,1}='-ro'; - marker_string{2,1}='--ko'; - else - marker_string{1,1}='-r'; - marker_string{2,1}='--k'; + [nbplt,nr,nc,lr,lc,nstar] = pltorg(n_varobs); + if options_.TeX && any(strcmp('eps',cellstr(options_.graph_format))) + fidTeX = fopen([M_.fname '_HistoricalAndSmoothedVariables.tex'],'w'); + fprintf(fidTeX,'%% TeX eps-loader file generated by dynare_estimation_1.m (Dynare).\n'); + fprintf(fidTeX,['%% ' datestr(now,0) '\n']); + fprintf(fidTeX,' \n'); end - for i=1:nstar0, - k = (plt-1)*nstar+i; - subplot(nr,nc,i); - plot(1:gend,yf(k,:),marker_string{1,1},'linewidth',1) - hold on - plot(1:gend,rawdata(:,k),marker_string{2,1},'linewidth',1) - hold off - name = options_.varobs{k}; - if isempty(NAMES) - NAMES = name; + for plt = 1:nbplt, + fh = dyn_figure(options_.nodisplay,'Name','Historical and smoothed variables'); + NAMES = []; + if options_.TeX, TeXNAMES = []; end + nstar0=min(nstar,n_varobs-(plt-1)*nstar); + if gend==1 + marker_string{1,1}='-ro'; + marker_string{2,1}='--ko'; else - NAMES = char(NAMES,name); - end - if ~isempty(options_.XTick) - set(gca,'XTick',options_.XTick) - set(gca,'XTickLabel',options_.XTickLabel) - end - if gend>1 - xlim([1 gend]) + marker_string{1,1}='-r'; + marker_string{2,1}='--k'; end - if options_.TeX - idx = strmatch(options_.varobs{k},M_.endo_names,'exact'); - texname = M_.endo_names_tex(idx,:); - if isempty(TeXNAMES) - TeXNAMES = ['$ ' deblank(texname) ' $']; + for i=1:nstar0, + k = (plt-1)*nstar+i; + subplot(nr,nc,i); + plot(1:gend,yf(k,:),marker_string{1,1},'linewidth',1) + hold on + plot(1:gend,rawdata(:,k),marker_string{2,1},'linewidth',1) + hold off + name = options_.varobs{k}; + if isempty(NAMES) + NAMES = name; else - TeXNAMES = char(TeXNAMES,['$ ' deblank(texname) ' $']); + NAMES = char(NAMES,name); + end + if ~isempty(options_.XTick) + set(gca,'XTick',options_.XTick) + set(gca,'XTickLabel',options_.XTickLabel) + end + if gend>1 + xlim([1 gend]) + end + if options_.TeX + idx = strmatch(options_.varobs{k},M_.endo_names,'exact'); + texname = M_.endo_names_tex(idx,:); + if isempty(TeXNAMES) + TeXNAMES = ['$ ' deblank(texname) ' $']; + else + TeXNAMES = char(TeXNAMES,['$ ' deblank(texname) ' $']); + end + end + title(name,'Interpreter','none') + end + dyn_saveas(fh,[M_.fname '_HistoricalAndSmoothedVariables' int2str(plt)],options_.nodisplay,options_.graph_format); + if options_.TeX && any(strcmp('eps',cellstr(options_.graph_format))) + fprintf(fidTeX,'\\begin{figure}[H]\n'); + for jj = 1:nstar0, + fprintf(fidTeX,'\\psfrag{%s}[1][][0.5][0]{%s}\n',deblank(NAMES(jj,:)),deblank(TeXNAMES(jj,:))); end + fprintf(fidTeX,'\\centering \n'); + fprintf(fidTeX,'\\includegraphics[width=%2.2f\\textwidth]{%s_HistoricalAndSmoothedVariables%s}\n',options_.figures.textwidth*min(i/nc,1),M_.fname,int2str(plt)); + fprintf(fidTeX,'\\caption{Historical and smoothed variables.}'); + fprintf(fidTeX,'\\label{Fig:HistoricalAndSmoothedVariables:%s}\n',int2str(plt)); + fprintf(fidTeX,'\\end{figure}\n'); + fprintf(fidTeX,'\n'); end - title(name,'Interpreter','none') end - dyn_saveas(fh,[M_.fname '_HistoricalAndSmoothedVariables' int2str(plt)],options_.nodisplay,options_.graph_format); if options_.TeX && any(strcmp('eps',cellstr(options_.graph_format))) - fprintf(fidTeX,'\\begin{figure}[H]\n'); - for jj = 1:nstar0, - fprintf(fidTeX,'\\psfrag{%s}[1][][0.5][0]{%s}\n',deblank(NAMES(jj,:)),deblank(TeXNAMES(jj,:))); - end - fprintf(fidTeX,'\\centering \n'); - fprintf(fidTeX,'\\includegraphics[width=%2.2f\\textwidth]{%s_HistoricalAndSmoothedVariables%s}\n',options_.figures.textwidth*min(i/nc,1),M_.fname,int2str(plt)); - fprintf(fidTeX,'\\caption{Historical and smoothed variables.}'); - fprintf(fidTeX,'\\label{Fig:HistoricalAndSmoothedVariables:%s}\n',int2str(plt)); - fprintf(fidTeX,'\\end{figure}\n'); fprintf(fidTeX,'\n'); + fprintf(fidTeX,'%% End of TeX file.\n'); + fclose(fidTeX); end end - if options_.TeX && any(strcmp('eps',cellstr(options_.graph_format))) - fprintf(fidTeX,'\n'); - fprintf(fidTeX,'%% End of TeX file.\n'); - fclose(fidTeX); - end - end end if options_.forecast > 0 && options_.mh_replic == 0 && ~options_.load_mh_file diff --git a/matlab/dynare_estimation_init.m b/matlab/dynare_estimation_init.m index b8e8b4ff6d..6e52a2d538 100644 --- a/matlab/dynare_estimation_init.m +++ b/matlab/dynare_estimation_init.m @@ -14,7 +14,7 @@ function [dataset_, dataset_info, xparam1, hh, M_, options_, oo_, estim_params_, % estim_params_: structure storing information about estimated % parameters % bayestopt_: structure storing information about priors - + % OUTPUTS % dataset_: the dataset after required transformation % dataset_info: Various informations about the dataset (descriptive statistics and missing observations). @@ -107,10 +107,10 @@ end if options_.fast_kalman_filter if ~ismember(options_.kalman_algo, [0,1,3]) error(['estimation option conflict: fast_kalman_filter is only available ' ... - 'with kalman_algo = 0, 1 or 3']) + 'with kalman_algo = 0, 1 or 3']) elseif options_.block error(['estimation option conflict: fast_kalman_filter is not available ' ... - 'with block']) + 'with block']) end end @@ -322,8 +322,8 @@ if ~isempty(estim_params_) && ~(all(strcmp(fieldnames(estim_params_),'full_calib bounds.lb = max(bounds.lb,lb); bounds.ub = min(bounds.ub,ub); else % estimated parameters but no declared priors - % No priors are declared so Dynare will estimate the model by - % maximum likelihood with inequality constraints for the parameters. + % No priors are declared so Dynare will estimate the model by + % maximum likelihood with inequality constraints for the parameters. options_.mh_replic = 0;% No metropolis. bounds.lb = lb; bounds.ub = ub; @@ -551,7 +551,7 @@ ncx = estim_params_.ncx; nvn = estim_params_.nvn; ncn = estim_params_.ncn; if estim_params_.np - M.params(estim_params_.param_vals(:,1)) = xparam1(nvx+ncx+nvn+ncn+1:end); + M.params(estim_params_.param_vals(:,1)) = xparam1(nvx+ncx+nvn+ncn+1:end); end [oo_.steady_state, params,info] = evaluate_steady_state(oo_.steady_state,M,options_,oo_,steadystate_check_flag); diff --git a/matlab/dynare_identification.m b/matlab/dynare_identification.m index c84faf2c67..a7d005b38a 100644 --- a/matlab/dynare_identification.m +++ b/matlab/dynare_identification.m @@ -250,18 +250,18 @@ if iload <=0, [I,J]=find(M_.lead_lag_incidence'); if prior_exist, -% if exist([fname_,'_mean.mat'],'file'), -% % disp('Testing posterior mean') -% load([fname_,'_mean'],'xparam1') -% pmean = xparam1'; -% clear xparam1 -% end -% if exist([fname_,'_mode.mat'],'file'), -% % disp('Testing posterior mode') -% load([fname_,'_mode'],'xparam1') -% pmode = xparam1'; -% clear xparam1 -% end + % if exist([fname_,'_mean.mat'],'file'), + % % disp('Testing posterior mean') + % load([fname_,'_mean'],'xparam1') + % pmean = xparam1'; + % clear xparam1 + % end + % if exist([fname_,'_mode.mat'],'file'), + % % disp('Testing posterior mode') + % load([fname_,'_mode'],'xparam1') + % pmode = xparam1'; + % clear xparam1 + % end params = set_prior(estim_params_,M_,options_)'; if all(bayestopt_.pshape == 0) parameters = 'ML_Starting_value'; @@ -269,38 +269,38 @@ if iload <=0, disp('Testing ML Starting value') else switch parameters - case 'calibration' - parameters_TeX = 'Calibration'; - disp('Testing calibration') - params(1,:) = get_all_parameters(estim_params_,M_);; - case 'posterior_mode' - parameters_TeX = 'Posterior mode'; - disp('Testing posterior mode') - params(1,:) = get_posterior_parameters('mode'); - case 'posterior_mean' - parameters_TeX = 'Posterior mean'; - disp('Testing posterior mean') - params(1,:) = get_posterior_parameters('mean'); - case 'posterior_median' - parameters_TeX = 'Posterior median'; - disp('Testing posterior median') - params(1,:) = get_posterior_parameters('median'); - case 'prior_mode' - parameters_TeX = 'Prior mode'; - disp('Testing prior mode') - params(1,:) = bayestopt_.p5(:); - case 'prior_mean' - parameters_TeX = 'Prior mean'; - disp('Testing prior mean') - params(1,:) = bayestopt_.p1; - otherwise - disp('The option parameter_set has to be equal to:') - disp(' ''posterior_mode'', ') - disp(' ''posterior_mean'', ') - disp(' ''posterior_median'', ') - disp(' ''prior_mode'' or') - disp(' ''prior_mean''.') - error; + case 'calibration' + parameters_TeX = 'Calibration'; + disp('Testing calibration') + params(1,:) = get_all_parameters(estim_params_,M_);; + case 'posterior_mode' + parameters_TeX = 'Posterior mode'; + disp('Testing posterior mode') + params(1,:) = get_posterior_parameters('mode'); + case 'posterior_mean' + parameters_TeX = 'Posterior mean'; + disp('Testing posterior mean') + params(1,:) = get_posterior_parameters('mean'); + case 'posterior_median' + parameters_TeX = 'Posterior median'; + disp('Testing posterior median') + params(1,:) = get_posterior_parameters('median'); + case 'prior_mode' + parameters_TeX = 'Prior mode'; + disp('Testing prior mode') + params(1,:) = bayestopt_.p5(:); + case 'prior_mean' + parameters_TeX = 'Prior mean'; + disp('Testing prior mean') + params(1,:) = bayestopt_.p1; + otherwise + disp('The option parameter_set has to be equal to:') + disp(' ''posterior_mode'', ') + disp(' ''posterior_mean'', ') + disp(' ''posterior_median'', ') + disp(' ''prior_mode'' or') + disp(' ''prior_mean''.') + error; end end else @@ -318,31 +318,31 @@ if iload <=0, disp(['The model does not solve for ', parameters, ' with error code info = ', int2str(info(1))]), skipline() if info(1)==1, - disp('info==1 %! The model doesn''t determine the current variables uniquely.') + disp('info==1 %! The model doesn''t determine the current variables uniquely.') elseif info(1)==2, - disp('info==2 %! MJDGGES returned an error code.') + disp('info==2 %! MJDGGES returned an error code.') elseif info(1)==3, - disp('info==3 %! Blanchard & Kahn conditions are not satisfied: no stable equilibrium. ') + disp('info==3 %! Blanchard & Kahn conditions are not satisfied: no stable equilibrium. ') elseif info(1)==4, - disp('info==4 %! Blanchard & Kahn conditions are not satisfied: indeterminacy. ') + disp('info==4 %! Blanchard & Kahn conditions are not satisfied: indeterminacy. ') elseif info(1)==5, - disp('info==5 %! Blanchard & Kahn conditions are not satisfied: indeterminacy due to rank failure. ') + disp('info==5 %! Blanchard & Kahn conditions are not satisfied: indeterminacy due to rank failure. ') elseif info(1)==6, - disp('info==6 %! The jacobian evaluated at the deterministic steady state is complex.') + disp('info==6 %! The jacobian evaluated at the deterministic steady state is complex.') elseif info(1)==19, - disp('info==19 %! The steadystate routine thrown an exception (inconsistent deep parameters). ') + disp('info==19 %! The steadystate routine thrown an exception (inconsistent deep parameters). ') elseif info(1)==20, - disp('info==20 %! Cannot find the steady state, info(2) contains the sum of square residuals (of the static equations). ') + disp('info==20 %! Cannot find the steady state, info(2) contains the sum of square residuals (of the static equations). ') elseif info(1)==21, - disp('info==21 %! The steady state is complex, info(2) contains the sum of square of imaginary parts of the steady state.') + disp('info==21 %! The steady state is complex, info(2) contains the sum of square of imaginary parts of the steady state.') elseif info(1)==22, - disp('info==22 %! The steady has NaNs. ') + disp('info==22 %! The steady has NaNs. ') elseif info(1)==23, - disp('info==23 %! M_.params has been updated in the steadystate routine and has complex valued scalars. ') + disp('info==23 %! M_.params has been updated in the steadystate routine and has complex valued scalars. ') elseif info(1)==24, - disp('info==24 %! M_.params has been updated in the steadystate routine and has some NaNs. ') + disp('info==24 %! M_.params has been updated in the steadystate routine and has some NaNs. ') elseif info(1)==30, - disp('info==30 %! Ergodic variance can''t be computed. ') + disp('info==30 %! Ergodic variance can''t be computed. ') end disp('----------- ') skipline() @@ -372,12 +372,12 @@ if iload <=0, end end idehess_point.params=params; -% siH = idemodel_point.siH; -% siJ = idemoments_point.siJ; -% siLRE = idelre_point.siLRE; -% normH = max(abs(siH)')'; -% normJ = max(abs(siJ)')'; -% normLRE = max(abs(siLRE)')'; + % siH = idemodel_point.siH; + % siJ = idemoments_point.siJ; + % siLRE = idelre_point.siLRE; + % normH = max(abs(siH)')'; + % normJ = max(abs(siJ)')'; + % normLRE = max(abs(siLRE)')'; save([IdentifDirectoryName '/' M_.fname '_identif.mat'], 'idehess_point', 'idemoments_point','idemodel_point', 'idelre_point','store_options_ident') save([IdentifDirectoryName '/' M_.fname '_' parameters '_identif.mat'], 'idehess_point', 'idemoments_point','idemodel_point', 'idelre_point','store_options_ident') disp_identification(params, idemodel_point, idemoments_point, name, advanced); @@ -485,11 +485,11 @@ if iload <=0, end if SampleSize > 1, -% if isoctave || options_.console_mode, -% console_waitbar(0,iteration/SampleSize); -% else - dyn_waitbar(iteration/SampleSize,h,['MC identification checks ',int2str(iteration),'/',int2str(SampleSize)]) -% end + % if isoctave || options_.console_mode, + % console_waitbar(0,iteration/SampleSize); + % else + dyn_waitbar(iteration/SampleSize,h,['MC identification checks ',int2str(iteration),'/',int2str(SampleSize)]) + % end end end @@ -522,7 +522,7 @@ if iload <=0, idemodel.siHnorm = siHnorm; idelre.siLREnorm = siLREnorm; save([IdentifDirectoryName '/' M_.fname '_identif.mat'], 'pdraws', 'idemodel', 'idemoments', 'idelre', ... %'indJJ', 'indH', 'indLRE', ... - 'TAU', 'GAM', 'LRE','-append') + 'TAU', 'GAM', 'LRE','-append') else siJnorm = idemoments_point.siJnorm; siHnorm = idemodel_point.siHnorm; @@ -531,7 +531,7 @@ if iload <=0, else load([IdentifDirectoryName '/' M_.fname '_identif']) -% identFiles = dir([IdentifDirectoryName '/' M_.fname '_identif_*']); + % identFiles = dir([IdentifDirectoryName '/' M_.fname '_identif_*']); parameters = store_options_ident.parameter_set; options_ident.parameter_set = parameters; options_ident.prior_mc=size(pdraws,1); diff --git a/matlab/dynare_sensitivity.m b/matlab/dynare_sensitivity.m index 62f688ec7b..b661dd32e5 100644 --- a/matlab/dynare_sensitivity.m +++ b/matlab/dynare_sensitivity.m @@ -24,7 +24,7 @@ function x0=dynare_sensitivity(options_gsa) global M_ options_ oo_ bayestopt_ estim_params_ if options_.dsge_var - error('Identification does not support DSGE-VARs at the current stage') + error('Identification does not support DSGE-VARs at the current stage') end fname_ = M_.fname; @@ -43,7 +43,7 @@ end if isfield(options_gsa,'morris') && options_gsa.morris==1, if isfield(options_gsa,'identification') && options_gsa.identification==0, -% options_gsa.redform=1; + % options_gsa.redform=1; end if isfield(options_gsa,'ppost') && options_gsa.ppost, error('sensitivity:: Morris is incompatible with posterior sampling') @@ -214,7 +214,7 @@ if options_gsa.morris>2, disp('the option is reset at morris = 1 .') options_gsa.morris=1; end - + if options_gsa.morris==1, if ~options_gsa.identification, options_gsa.redform=1; @@ -232,12 +232,12 @@ if options_gsa.morris==1, options_gsa.alpha2_stab=1; options_gsa.pvalue_ks=0; options_gsa.pvalue_corr=0; -% if options_gsa.morris==3, -% options_gsa = set_default_option(options_gsa,'Nsam',256); -% OutputDirectoryName = CheckPath('gsa/identif',M_.dname); -% else - OutputDirectoryName = CheckPath('gsa/screen',M_.dname); -% end + % if options_gsa.morris==3, + % options_gsa = set_default_option(options_gsa,'Nsam',256); + % OutputDirectoryName = CheckPath('gsa/identif',M_.dname); + % else + OutputDirectoryName = CheckPath('gsa/screen',M_.dname); + % end else OutputDirectoryName = CheckPath('gsa',M_.dname); end @@ -295,7 +295,7 @@ if options_gsa.identification, end if options_gsa.redform && ~isempty(options_gsa.namendo),% ... - % && ~options_gsa.ppost, + % && ~options_gsa.ppost, if options_gsa.ppost, filnam = dir([M_.dname filesep 'metropolis' filesep '*param_irf*.mat']); lpmat=[]; @@ -329,13 +329,13 @@ if options_gsa.redform && ~isempty(options_gsa.namendo),% ... if strmatch(':',options_gsa.namlagendo,'exact'), options_gsa.namlagendo=M_.endo_names(1:M_.orig_endo_nbr,:); end -% options_.opt_gsa = options_gsa; + % options_.opt_gsa = options_gsa; if options_gsa.morris==1, redform_screen(OutputDirectoryName,options_gsa); else % check existence of the SS_ANOVA toolbox if isempty(options_gsa.threshold_redform) && ... - ~(exist('gsa_sdp','file')==6 || exist('gsa_sdp','file')==2), + ~(exist('gsa_sdp','file')==6 || exist('gsa_sdp','file')==2), fprintf('\nThe "SS-ANOVA-R: MATLAB Toolbox for the estimation of Smoothing Spline ANOVA models with Recursive algorithms" is missing.\n') fprintf('To obtain it, go to:\n\n') fprintf('http://ipsc.jrc.ec.europa.eu/?id=790 \n\n') @@ -369,54 +369,54 @@ if options_gsa.rmse, end end if isempty(a), - if options_gsa.lik_only, - options_.smoother=0; - options_.filter_step_ahead=[]; - options_.forecast=0; - options_.filtered_vars=0; - end -% dynare_MC([],OutputDirectoryName,data,rawdata,data_info); - if options_gsa.pprior - TmpDirectoryName = ([M_.dname filesep 'gsa' filesep 'prior']); - else - TmpDirectoryName = ([M_.dname filesep 'gsa' filesep 'mc']); - end - if exist(TmpDirectoryName,'dir'); - mydelete([M_.fname '_filter_step_ahead*.mat'],[TmpDirectoryName filesep]); - mydelete([M_.fname '_inno*.mat'],[TmpDirectoryName filesep]); - mydelete([M_.fname '_smooth*.mat'],[TmpDirectoryName filesep]); - mydelete([M_.fname '_update*.mat'],[TmpDirectoryName filesep]); - filparam = dir([TmpDirectoryName filesep M_.fname '_param*.mat']); - for j=1:length(filparam), - if isempty(strmatch([M_.fname '_param_irf'],filparam(j).name)) - delete([TmpDirectoryName filesep filparam(j).name]); + if options_gsa.lik_only, + options_.smoother=0; + options_.filter_step_ahead=[]; + options_.forecast=0; + options_.filtered_vars=0; + end + % dynare_MC([],OutputDirectoryName,data,rawdata,data_info); + if options_gsa.pprior + TmpDirectoryName = ([M_.dname filesep 'gsa' filesep 'prior']); + else + TmpDirectoryName = ([M_.dname filesep 'gsa' filesep 'mc']); + end + if exist(TmpDirectoryName,'dir'); + mydelete([M_.fname '_filter_step_ahead*.mat'],[TmpDirectoryName filesep]); + mydelete([M_.fname '_inno*.mat'],[TmpDirectoryName filesep]); + mydelete([M_.fname '_smooth*.mat'],[TmpDirectoryName filesep]); + mydelete([M_.fname '_update*.mat'],[TmpDirectoryName filesep]); + filparam = dir([TmpDirectoryName filesep M_.fname '_param*.mat']); + for j=1:length(filparam), + if isempty(strmatch([M_.fname '_param_irf'],filparam(j).name)) + delete([TmpDirectoryName filesep filparam(j).name]); + end end + end - - end - prior_posterior_statistics('gsa',dataset_, dataset_info); - if options_.bayesian_irf - PosteriorIRF('gsa'); - end - options_gsa.load_rmse=0; - % else - % if options_gsa.load_rmse==0, - % disp('You already saved a MC filter/smoother analysis ') - % disp('Do you want to overwrite ?') - % pause; - % if options_gsa.pprior - % delete([OutputDirectoryName,'/',fname_,'_prior_*.mat']) - % else - % delete([OutputDirectoryName,'/',fname_,'_mc_*.mat']) - % end - % dynare_MC([],OutputDirectoryName); - % options_gsa.load_rmse=0; - % end + prior_posterior_statistics('gsa',dataset_, dataset_info); + if options_.bayesian_irf + PosteriorIRF('gsa'); + end + options_gsa.load_rmse=0; + % else + % if options_gsa.load_rmse==0, + % disp('You already saved a MC filter/smoother analysis ') + % disp('Do you want to overwrite ?') + % pause; + % if options_gsa.pprior + % delete([OutputDirectoryName,'/',fname_,'_prior_*.mat']) + % else + % delete([OutputDirectoryName,'/',fname_,'_mc_*.mat']) + % end + % dynare_MC([],OutputDirectoryName); + % options_gsa.load_rmse=0; + % end end end clear a; -% filt_mc_(OutputDirectoryName,data_info); + % filt_mc_(OutputDirectoryName,data_info); filt_mc_(OutputDirectoryName,options_gsa,dataset_,dataset_info); end options_.opt_gsa = options_gsa; diff --git a/matlab/dynare_solve.m b/matlab/dynare_solve.m index 36981b9493..8c13f524e4 100644 --- a/matlab/dynare_solve.m +++ b/matlab/dynare_solve.m @@ -209,13 +209,13 @@ if options.solve_algo == 0 info = 1; end elseif options.solve_algo == 1 - [x,info]=solve1(func,x,1:nn,1:nn,jacobian_flag,options.gstep, ... + [x,info]=solve1(func,x,1:nn,1:nn,jacobian_flag,options.gstep, ... tolf,options.solve_tolx, ... maxit,options.debug,varargin{:}); elseif options.solve_algo == 9 - [x,info]=trust_region(func,x,1:nn,1:nn,jacobian_flag,options.gstep, ... - tolf,options.solve_tolx, ... - maxit,options.debug,varargin{:}); + [x,info]=trust_region(func,x,1:nn,1:nn,jacobian_flag,options.gstep, ... + tolf,options.solve_tolx, ... + maxit,options.debug,varargin{:}); elseif options.solve_algo == 2 || options.solve_algo == 4 if options.solve_algo == 2 diff --git a/matlab/dynare_solve_block_or_bytecode.m b/matlab/dynare_solve_block_or_bytecode.m index 1032d0921e..37ba7a8ea4 100644 --- a/matlab/dynare_solve_block_or_bytecode.m +++ b/matlab/dynare_solve_block_or_bytecode.m @@ -22,7 +22,7 @@ if options.block && ~options.bytecode for b = 1:length(M.block_structure_stat.block) ss = x; if M.block_structure_stat.block(b).Simulation_Type ~= 1 && ... - M.block_structure_stat.block(b).Simulation_Type ~= 2 + M.block_structure_stat.block(b).Simulation_Type ~= 2 if options.solve_algo <= 4 [y, check] = dynare_solve('block_mfs_steadystate', ... ss(M.block_structure_stat.block(b).variable), ... @@ -60,7 +60,7 @@ elseif options.bytecode elseif options.block for b = 1:length(M.block_structure_stat.block) if M.block_structure_stat.block(b).Simulation_Type ~= 1 && ... - M.block_structure_stat.block(b).Simulation_Type ~= 2 + M.block_structure_stat.block(b).Simulation_Type ~= 2 [y, check] = dynare_solve('block_bytecode_mfs_steadystate', ... x(M.block_structure_stat ... .block(b).variable), ... diff --git a/matlab/dyntable.m b/matlab/dyntable.m index 23d56feff1..f67789bc3b 100644 --- a/matlab/dyntable.m +++ b/matlab/dyntable.m @@ -35,7 +35,7 @@ end %% get width of label column if ~isempty(label_width) label_width = max(size(deblank(char(headers(1,:),labels)),2)+2, ... - label_width); + label_width); else %use default length label_width = max(size(deblank(char(headers(1,:),labels)),2))+2; end diff --git a/matlab/endogenous_prior.m b/matlab/endogenous_prior.m index c2930abad8..7e879df609 100644 --- a/matlab/endogenous_prior.m +++ b/matlab/endogenous_prior.m @@ -75,7 +75,7 @@ end % Finally, we have the sampling uncertainty measure Shat: Shat=C0 +(1-1/(2+1))*(C1+C1')... - +(1-2/(2+1))*(C2+C2'); + +(1-2/(2+1))*(C2+C2'); % Model variances below: mf=BayesInfo.mf1; diff --git a/matlab/endogenous_prior_restrictions.m b/matlab/endogenous_prior_restrictions.m index 617116a890..5d480fd9e6 100644 --- a/matlab/endogenous_prior_restrictions.m +++ b/matlab/endogenous_prior_restrictions.m @@ -1,178 +1,178 @@ -function [info, info_irf, info_moment, data_irf, data_moment] = endogenous_prior_restrictions(T,R,Model,DynareOptions,DynareResults); -% Check for prior (sign) restrictions on irf's and theoretical moments -% -% INPUTS -% T [double] n*n state space matrix -% R [double] n*k matrix of shocks -% Model [structure] -% DynareOptions [structure] -% DynareResults [structure] - -% OUTPUTS -% info [double] check if prior restrictions are matched by the -% model and related info -% info_irf [double] array of test checks for all individual irf restrictions -% info_moment [double] array of test checks for all individual moment restrictions -% - -% Copyright (C) 2013 Dynare Team -% -% This file is part of Dynare. -% -% Dynare is free software: you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation, either version 3 of the License, or -% (at your option) any later version. -% -% Dynare is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. -% -% You should have received a copy of the GNU General Public License -% along with Dynare. If not, see <http://www.gnu.org/licenses/>. - -info=[0 0]; -info_irf=[]; -info_moment=[]; -data_irf=[]; -data_moment=[]; - -endo_prior_restrictions.irf= DynareOptions.endogenous_prior_restrictions.irf; -endo_prior_restrictions.moment= DynareOptions.endogenous_prior_restrictions.moment; - -if ~isempty(endo_prior_restrictions.irf), - data_irf=cell(size(endo_prior_restrictions.irf,1),1); - if DynareOptions.order>1, - error('The algorithm for prior (sign) restrictions on irf''s is currently restricted to first-order decision rules') - return - end - varlist=Model.endo_names(DynareResults.dr.order_var,:); - if isempty(T), - [T,R,SteadyState,infox,Model,DynareOptions,DynareResults] = dynare_resolve(Model,DynareOptions,DynareResults); - else % check if T and R are given in the restricted form!!! - if size(T,1)<size(varlist,1), - varlist=varlist(DynareResults.dr.restrict_var_list,:); - end - % check if endo_prior_restrictions.irf{:,1} variables are in varlist - varlistok=1; - for j=1:size(endo_prior_restrictions.irf,1) - if isempty(strmatch(endo_prior_restrictions.irf{j,1},varlist,'exact')) - varlistok=0; - end - end - if ~varlistok - varlist=Model.endo_names(DynareResults.dr.order_var,:); - [T,R,SteadyState,infox,Model,DynareOptions,DynareResults] = dynare_resolve(Model,DynareOptions,DynareResults); - end - end - NT=1; - for j=1:size(endo_prior_restrictions.irf,1), - NT=max(NT,max(endo_prior_restrictions.irf{j,3})); - end - info_irf=ones(size(endo_prior_restrictions.irf,1),2); - for t=1:NT, - if ~DynareOptions.relative_irf, - RR = T^(t-1)*R*diag(sqrt(diag(Model.Sigma_e))); - else - RR = T^(t-1)*R*100; - end - for j=1:size(endo_prior_restrictions.irf,1), - if endo_prior_restrictions.irf{j,3}~=t, - continue, - end - iendo=strmatch(endo_prior_restrictions.irf{j,1},varlist,'exact'); - iexo=strmatch(endo_prior_restrictions.irf{j,2},Model.exo_names,'exact'); - data_irf{j}=[data_irf{j}; [t RR(iendo,iexo)]]; - if (RR(iendo,iexo)>endo_prior_restrictions.irf{j,4}(1)) && (RR(iendo,iexo)<endo_prior_restrictions.irf{j,4}(2)), - info_irf(j,:)=info_irf(j,:).*[0, 0]; - else - if RR(iendo,iexo)<endo_prior_restrictions.irf{j,4}(1), - delt = (RR(iendo,iexo)-endo_prior_restrictions.irf{j,4}(1))^2; - else - delt = (RR(iendo,iexo)-endo_prior_restrictions.irf{j,4}(2))^2; - end - info_irf(j,:)=info_irf(j,:).*[49, delt]; - end - end - end - if any(info_irf), - info=[49,sum(info_irf(:,2))]; - end - -end - -if ~isempty(endo_prior_restrictions.moment), - - if DynareOptions.order>1, - error('The algorithm for prior (sign) restrictions on moments is currently restricted to first-order decision rules') - return - end - - data_moment=cell(size(endo_prior_restrictions.moment,1),1); - var_list_=endo_prior_restrictions.moment{1,1}; - for j=1:size(endo_prior_restrictions.moment,1), - tmp=endo_prior_restrictions.moment{j,1}; - if ~ismember(tmp,cellstr(var_list_)), - var_list_ = char(var_list_, tmp); - end - tmp=endo_prior_restrictions.moment{j,2}; - if ~ismember(tmp,cellstr(var_list_)), - var_list_ = char(var_list_, tmp); - end - end - NTmax=0; - NTmin=0; - for j=1:size(endo_prior_restrictions.moment,1), - NTmax=max(NTmax,max(endo_prior_restrictions.moment{j,3})); - NTmin=min(NTmin,min(endo_prior_restrictions.moment{j,3})); - end - info_moment=ones(size(endo_prior_restrictions.moment,1),2); - nvar = size(var_list_,1); - ivar=zeros(nvar,1); - for i=1:nvar - i_tmp = strmatch(var_list_(i,:),Model.endo_names,'exact'); - if isempty(i_tmp) - error (['One of the variable specified does not exist']) ; - else - ivar(i) = i_tmp; - end - end - DynareOptions.ar = max(abs(NTmin),NTmax); - [gamma_y,stationary_vars] = th_autocovariances(DynareResults.dr, ivar, Model, DynareOptions,1); - for t=NTmin:NTmax, - RR = gamma_y{abs(t)+1}; - if t==0, - RR = RR./(sqrt(diag(RR))*sqrt(diag(RR))')-eye(nvar)+diag(diag(gamma_y{t+1})); % becomes correlation - end - for j=1:size(endo_prior_restrictions.moment,1), - if endo_prior_restrictions.moment{j,3}~=t, - continue, - end - iendo1 = strmatch(endo_prior_restrictions.moment{j,1},var_list_,'exact'); - iendo2 = strmatch(endo_prior_restrictions.moment{j,2},var_list_,'exact'); - if t>0 - tmp0 = iendo1; - iendo1=iendo2; - iendo2=tmp0; - end - data_moment{j}=[data_moment{j}; [t RR(iendo1,iendo2)]]; - if (RR(iendo1,iendo2)>endo_prior_restrictions.moment{j,4}(1)) && (RR(iendo1,iendo2)<endo_prior_restrictions.moment{j,4}(2)), - info_moment(j,:)=info_moment(j,:).*[0, 0]; - else - if RR(iendo1,iendo2)<endo_prior_restrictions.moment{j,4}(1), - delt = (RR(iendo1,iendo2)-endo_prior_restrictions.moment{j,4}(1))^2; - else - delt = (RR(iendo1,iendo2)-endo_prior_restrictions.moment{j,4}(2))^2; - end - info_moment(j,:)=info_moment(j,:).*[49, delt]; - end - end - end - if any(info_moment), - info=[49, info(2) + sum(info_moment(:,2))]; - end -end -return - - +function [info, info_irf, info_moment, data_irf, data_moment] = endogenous_prior_restrictions(T,R,Model,DynareOptions,DynareResults); +% Check for prior (sign) restrictions on irf's and theoretical moments +% +% INPUTS +% T [double] n*n state space matrix +% R [double] n*k matrix of shocks +% Model [structure] +% DynareOptions [structure] +% DynareResults [structure] + +% OUTPUTS +% info [double] check if prior restrictions are matched by the +% model and related info +% info_irf [double] array of test checks for all individual irf restrictions +% info_moment [double] array of test checks for all individual moment restrictions +% + +% Copyright (C) 2013 Dynare Team +% +% This file is part of Dynare. +% +% Dynare is free software: you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation, either version 3 of the License, or +% (at your option) any later version. +% +% Dynare is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with Dynare. If not, see <http://www.gnu.org/licenses/>. + +info=[0 0]; +info_irf=[]; +info_moment=[]; +data_irf=[]; +data_moment=[]; + +endo_prior_restrictions.irf= DynareOptions.endogenous_prior_restrictions.irf; +endo_prior_restrictions.moment= DynareOptions.endogenous_prior_restrictions.moment; + +if ~isempty(endo_prior_restrictions.irf), + data_irf=cell(size(endo_prior_restrictions.irf,1),1); + if DynareOptions.order>1, + error('The algorithm for prior (sign) restrictions on irf''s is currently restricted to first-order decision rules') + return + end + varlist=Model.endo_names(DynareResults.dr.order_var,:); + if isempty(T), + [T,R,SteadyState,infox,Model,DynareOptions,DynareResults] = dynare_resolve(Model,DynareOptions,DynareResults); + else % check if T and R are given in the restricted form!!! + if size(T,1)<size(varlist,1), + varlist=varlist(DynareResults.dr.restrict_var_list,:); + end + % check if endo_prior_restrictions.irf{:,1} variables are in varlist + varlistok=1; + for j=1:size(endo_prior_restrictions.irf,1) + if isempty(strmatch(endo_prior_restrictions.irf{j,1},varlist,'exact')) + varlistok=0; + end + end + if ~varlistok + varlist=Model.endo_names(DynareResults.dr.order_var,:); + [T,R,SteadyState,infox,Model,DynareOptions,DynareResults] = dynare_resolve(Model,DynareOptions,DynareResults); + end + end + NT=1; + for j=1:size(endo_prior_restrictions.irf,1), + NT=max(NT,max(endo_prior_restrictions.irf{j,3})); + end + info_irf=ones(size(endo_prior_restrictions.irf,1),2); + for t=1:NT, + if ~DynareOptions.relative_irf, + RR = T^(t-1)*R*diag(sqrt(diag(Model.Sigma_e))); + else + RR = T^(t-1)*R*100; + end + for j=1:size(endo_prior_restrictions.irf,1), + if endo_prior_restrictions.irf{j,3}~=t, + continue, + end + iendo=strmatch(endo_prior_restrictions.irf{j,1},varlist,'exact'); + iexo=strmatch(endo_prior_restrictions.irf{j,2},Model.exo_names,'exact'); + data_irf{j}=[data_irf{j}; [t RR(iendo,iexo)]]; + if (RR(iendo,iexo)>endo_prior_restrictions.irf{j,4}(1)) && (RR(iendo,iexo)<endo_prior_restrictions.irf{j,4}(2)), + info_irf(j,:)=info_irf(j,:).*[0, 0]; + else + if RR(iendo,iexo)<endo_prior_restrictions.irf{j,4}(1), + delt = (RR(iendo,iexo)-endo_prior_restrictions.irf{j,4}(1))^2; + else + delt = (RR(iendo,iexo)-endo_prior_restrictions.irf{j,4}(2))^2; + end + info_irf(j,:)=info_irf(j,:).*[49, delt]; + end + end + end + if any(info_irf), + info=[49,sum(info_irf(:,2))]; + end + +end + +if ~isempty(endo_prior_restrictions.moment), + + if DynareOptions.order>1, + error('The algorithm for prior (sign) restrictions on moments is currently restricted to first-order decision rules') + return + end + + data_moment=cell(size(endo_prior_restrictions.moment,1),1); + var_list_=endo_prior_restrictions.moment{1,1}; + for j=1:size(endo_prior_restrictions.moment,1), + tmp=endo_prior_restrictions.moment{j,1}; + if ~ismember(tmp,cellstr(var_list_)), + var_list_ = char(var_list_, tmp); + end + tmp=endo_prior_restrictions.moment{j,2}; + if ~ismember(tmp,cellstr(var_list_)), + var_list_ = char(var_list_, tmp); + end + end + NTmax=0; + NTmin=0; + for j=1:size(endo_prior_restrictions.moment,1), + NTmax=max(NTmax,max(endo_prior_restrictions.moment{j,3})); + NTmin=min(NTmin,min(endo_prior_restrictions.moment{j,3})); + end + info_moment=ones(size(endo_prior_restrictions.moment,1),2); + nvar = size(var_list_,1); + ivar=zeros(nvar,1); + for i=1:nvar + i_tmp = strmatch(var_list_(i,:),Model.endo_names,'exact'); + if isempty(i_tmp) + error (['One of the variable specified does not exist']) ; + else + ivar(i) = i_tmp; + end + end + DynareOptions.ar = max(abs(NTmin),NTmax); + [gamma_y,stationary_vars] = th_autocovariances(DynareResults.dr, ivar, Model, DynareOptions,1); + for t=NTmin:NTmax, + RR = gamma_y{abs(t)+1}; + if t==0, + RR = RR./(sqrt(diag(RR))*sqrt(diag(RR))')-eye(nvar)+diag(diag(gamma_y{t+1})); % becomes correlation + end + for j=1:size(endo_prior_restrictions.moment,1), + if endo_prior_restrictions.moment{j,3}~=t, + continue, + end + iendo1 = strmatch(endo_prior_restrictions.moment{j,1},var_list_,'exact'); + iendo2 = strmatch(endo_prior_restrictions.moment{j,2},var_list_,'exact'); + if t>0 + tmp0 = iendo1; + iendo1=iendo2; + iendo2=tmp0; + end + data_moment{j}=[data_moment{j}; [t RR(iendo1,iendo2)]]; + if (RR(iendo1,iendo2)>endo_prior_restrictions.moment{j,4}(1)) && (RR(iendo1,iendo2)<endo_prior_restrictions.moment{j,4}(2)), + info_moment(j,:)=info_moment(j,:).*[0, 0]; + else + if RR(iendo1,iendo2)<endo_prior_restrictions.moment{j,4}(1), + delt = (RR(iendo1,iendo2)-endo_prior_restrictions.moment{j,4}(1))^2; + else + delt = (RR(iendo1,iendo2)-endo_prior_restrictions.moment{j,4}(2))^2; + end + info_moment(j,:)=info_moment(j,:).*[49, delt]; + end + end + end + if any(info_moment), + info=[49, info(2) + sum(info_moment(:,2))]; + end +end +return + + diff --git a/matlab/ep/ep_problem_2.m b/matlab/ep/ep_problem_2.m index d31f0e7aa1..1b4e0d9a79 100644 --- a/matlab/ep/ep_problem_2.m +++ b/matlab/ep/ep_problem_2.m @@ -180,7 +180,7 @@ for j=1:world_nbr nzA{i,j} = [offset_r+ir,offset_c+icA(ic), v]'; else d1 = dynamic_model(Y(i_rows_y,j),x,params, ... - steady_state,i+1); + steady_state,i+1); end res(:,i,j) = d1(eq_index); i_rows_y = i_rows_y + ny; diff --git a/matlab/ep/extended_path_core.m b/matlab/ep/extended_path_core.m index 33c42b619c..8a56646434 100644 --- a/matlab/ep/extended_path_core.m +++ b/matlab/ep/extended_path_core.m @@ -1,8 +1,8 @@ function [y, info_convergence, endogenousvariablespaths] = extended_path_core(periods,endo_nbr,exo_nbr,positive_var_indx, ... - exo_simul,init,initial_conditions,... - steady_state, ... - debug,bytecode_flag,order,M,pfm,algo,solve_algo,stack_solve_algo,... - olmmcp,options,oo,initialguess) + exo_simul,init,initial_conditions,... + steady_state, ... + debug,bytecode_flag,order,M,pfm,algo,solve_algo,stack_solve_algo,... + olmmcp,options,oo,initialguess) % Copyright (C) 2016 Dynare Team % diff --git a/matlab/ep/extended_path_homotopy.m b/matlab/ep/extended_path_homotopy.m index 463003d2bf..47259765c0 100644 --- a/matlab/ep/extended_path_homotopy.m +++ b/matlab/ep/extended_path_homotopy.m @@ -17,7 +17,7 @@ function [info_convergence, endo_simul] = extended_path_homotopy(endo_simul, exo % You should have received a copy of the GNU General Public License % along with Dynare. If not, see <http://www.gnu.org/licenses/>. - + endo_simul0 = endo_simul; if ismember(method, [1, 2]) noconvergence = true; diff --git a/matlab/ep/setup_integration_nodes.m b/matlab/ep/setup_integration_nodes.m index 85d1be960c..2577d59327 100644 --- a/matlab/ep/setup_integration_nodes.m +++ b/matlab/ep/setup_integration_nodes.m @@ -1,39 +1,39 @@ function [nodes,weights,nnodes] = setup_integration_nodes(EpOptions,pfm) - if EpOptions.stochastic.order - % Compute weights and nodes for the stochastic version of the extended path. - switch EpOptions.IntegrationAlgorithm - case 'Tensor-Gaussian-Quadrature' - % Get the nodes and weights from a univariate Gauss-Hermite quadrature. - [nodes0,weights0] = gauss_hermite_weights_and_nodes(EpOptions.stochastic.quadrature.nodes); - % Replicate the univariate nodes for each innovation and dates, and, if needed, correlate them. - nodes0 = repmat(nodes0,1,pfm.number_of_shocks*pfm.stochastic_order)*kron(eye(pfm.stochastic_order),pfm.Omega); - % Put the nodes and weights in cells - for i=1:pfm.number_of_shocks - rr(i) = {nodes0(:,i)}; - ww(i) = {weights0}; - end - % Build the tensorial grid - nodes = cartesian_product_of_sets(rr{:}); - weights = prod(cartesian_product_of_sets(ww{:}),2); - nnodes = length(weights); - case 'Stroud-Cubature-3' - [nodes,weights] = cubature_with_gaussian_weight(pfm.number_of_shocks*pfm.stochastic_order,3,'Stroud') - nodes = kron(eye(pfm.stochastic_order),transpose(pfm.Omega))*nodes; - weights = weights; - nnodes = length(weights); - case 'Stroud-Cubature-5' - [nodes,weights] = cubature_with_gaussian_weight(pfm.number_of_shocks*pfm.stochastic_order,5,'Stroud') - nodes = kron(eye(pfm.stochastic_order),transpose(pfm.Omega))*nodes; - weights = weights; - nnodes = length(weights); - case 'Unscented' - p = pfm.number_of_shocks; - k = EpOptions.ut.k; - C = sqrt(pfm.number_of_shocks + k)*pfm.Omega'; - nodes = [zeros(1,p); -C; C]; - weights = [k/(p+k); (1/(2*(p+k)))*ones(2*p,1)]; - nnodes = 2*p+1; - otherwise - error('Stochastic extended path:: Unknown integration algorithm!') +if EpOptions.stochastic.order + % Compute weights and nodes for the stochastic version of the extended path. + switch EpOptions.IntegrationAlgorithm + case 'Tensor-Gaussian-Quadrature' + % Get the nodes and weights from a univariate Gauss-Hermite quadrature. + [nodes0,weights0] = gauss_hermite_weights_and_nodes(EpOptions.stochastic.quadrature.nodes); + % Replicate the univariate nodes for each innovation and dates, and, if needed, correlate them. + nodes0 = repmat(nodes0,1,pfm.number_of_shocks*pfm.stochastic_order)*kron(eye(pfm.stochastic_order),pfm.Omega); + % Put the nodes and weights in cells + for i=1:pfm.number_of_shocks + rr(i) = {nodes0(:,i)}; + ww(i) = {weights0}; end + % Build the tensorial grid + nodes = cartesian_product_of_sets(rr{:}); + weights = prod(cartesian_product_of_sets(ww{:}),2); + nnodes = length(weights); + case 'Stroud-Cubature-3' + [nodes,weights] = cubature_with_gaussian_weight(pfm.number_of_shocks*pfm.stochastic_order,3,'Stroud') + nodes = kron(eye(pfm.stochastic_order),transpose(pfm.Omega))*nodes; + weights = weights; + nnodes = length(weights); + case 'Stroud-Cubature-5' + [nodes,weights] = cubature_with_gaussian_weight(pfm.number_of_shocks*pfm.stochastic_order,5,'Stroud') + nodes = kron(eye(pfm.stochastic_order),transpose(pfm.Omega))*nodes; + weights = weights; + nnodes = length(weights); + case 'Unscented' + p = pfm.number_of_shocks; + k = EpOptions.ut.k; + C = sqrt(pfm.number_of_shocks + k)*pfm.Omega'; + nodes = [zeros(1,p); -C; C]; + weights = [k/(p+k); (1/(2*(p+k)))*ones(2*p,1)]; + nnodes = 2*p+1; + otherwise + error('Stochastic extended path:: Unknown integration algorithm!') end +end diff --git a/matlab/ep/setup_stochastic_perfect_foresight_model_solver.m b/matlab/ep/setup_stochastic_perfect_foresight_model_solver.m index 286bd16acb..6ec1dbe9e5 100644 --- a/matlab/ep/setup_stochastic_perfect_foresight_model_solver.m +++ b/matlab/ep/setup_stochastic_perfect_foresight_model_solver.m @@ -16,7 +16,7 @@ function pfm = setup_stochastic_perfect_foresight_model_solver(DynareModel,Dynar % % You should have received a copy of the GNU General Public License % along with Dynare. If not, see <http://www.gnu.org/licenses/>. - + pfm.lead_lag_incidence = DynareModel.lead_lag_incidence; pfm.ny = DynareModel.endo_nbr; pfm.Sigma = DynareModel.Sigma_e; diff --git a/matlab/ep/solve_stochastic_perfect_foresight_model.m b/matlab/ep/solve_stochastic_perfect_foresight_model.m index ab13e3043a..12373d15d9 100644 --- a/matlab/ep/solve_stochastic_perfect_foresight_model.m +++ b/matlab/ep/solve_stochastic_perfect_foresight_model.m @@ -17,219 +17,219 @@ function [flag,endo_simul,err] = solve_stochastic_perfect_foresight_model(endo_s % You should have received a copy of the GNU General Public License % along with Dynare. If not, see <http://www.gnu.org/licenses/>. - flag = 0; - err = 0; - stop = 0; +flag = 0; +err = 0; +stop = 0; - params = pfm.params; - steady_state = pfm.steady_state; - ny = pfm.ny; - periods = pfm.periods; - dynamic_model = pfm.dynamic_model; - lead_lag_incidence = pfm.lead_lag_incidence; - nyp = pfm.nyp; - nyf = pfm.nyf; - i_cols_1 = pfm.i_cols_1; - i_cols_A1 = pfm.i_cols_A1; - i_cols_j = pfm.i_cols_j; - i_cols_T = nonzeros(lead_lag_incidence(1:2,:)'); +params = pfm.params; +steady_state = pfm.steady_state; +ny = pfm.ny; +periods = pfm.periods; +dynamic_model = pfm.dynamic_model; +lead_lag_incidence = pfm.lead_lag_incidence; +nyp = pfm.nyp; +nyf = pfm.nyf; +i_cols_1 = pfm.i_cols_1; +i_cols_A1 = pfm.i_cols_A1; +i_cols_j = pfm.i_cols_j; +i_cols_T = nonzeros(lead_lag_incidence(1:2,:)'); - maxit = pfm.maxit_; - tolerance = pfm.tolerance; - verbose = pfm.verbose; +maxit = pfm.maxit_; +tolerance = pfm.tolerance; +verbose = pfm.verbose; - number_of_shocks = size(exo_simul,2); +number_of_shocks = size(exo_simul,2); - [nodes,weights] = gauss_hermite_weights_and_nodes(nnodes); +[nodes,weights] = gauss_hermite_weights_and_nodes(nnodes); - if number_of_shocks>1 - nodes = repmat(nodes,1,number_of_shocks)*chol(pfm.Sigma); - % to be fixed for Sigma ~= I - for i=1:number_of_shocks - rr(i) = {nodes(:,i)}; - ww(i) = {weights}; - end - nodes = cartesian_product_of_sets(rr{:}); - weights = prod(cartesian_product_of_sets(ww{:}),2); - nnodes = nnodes^number_of_shocks; - else - nodes = nodes*sqrt(pfm.Sigma); +if number_of_shocks>1 + nodes = repmat(nodes,1,number_of_shocks)*chol(pfm.Sigma); + % to be fixed for Sigma ~= I + for i=1:number_of_shocks + rr(i) = {nodes(:,i)}; + ww(i) = {weights}; end + nodes = cartesian_product_of_sets(rr{:}); + weights = prod(cartesian_product_of_sets(ww{:}),2); + nnodes = nnodes^number_of_shocks; +else + nodes = nodes*sqrt(pfm.Sigma); +end - innovations = zeros(periods+2,number_of_shocks); +innovations = zeros(periods+2,number_of_shocks); - if verbose - disp ([' -----------------------------------------------------']); - disp (['MODEL SIMULATION :']); - fprintf('\n'); - end +if verbose + disp ([' -----------------------------------------------------']); + disp (['MODEL SIMULATION :']); + fprintf('\n'); +end - z = endo_simul(find(lead_lag_incidence')); - [d1,jacobian] = dynamic_model(z,exo_simul,params,steady_state,2); +z = endo_simul(find(lead_lag_incidence')); +[d1,jacobian] = dynamic_model(z,exo_simul,params,steady_state,2); - % Each column of Y represents a different world - % The upper right cells are unused - % The first row block is ny x 1 - % The second row block is ny x nnodes - % The third row block is ny x nnodes^2 - % and so on until size ny x nnodes^order - world_nbr = nnodes^order; - Y = repmat(endo_simul(:),1,world_nbr); +% Each column of Y represents a different world +% The upper right cells are unused +% The first row block is ny x 1 +% The second row block is ny x nnodes +% The third row block is ny x nnodes^2 +% and so on until size ny x nnodes^order +world_nbr = nnodes^order; +Y = repmat(endo_simul(:),1,world_nbr); - % The columns of A map the elements of Y such that - % each block of Y with ny rows are unfolded column wise - dimension = ny*(sum(nnodes.^(0:order-1),2)+(periods-order)*world_nbr); - if order == 0 - i_upd_r = (1:ny*periods); - i_upd_y = i_upd_r + ny; - else - i_upd_r = zeros(dimension,1); - i_upd_y = i_upd_r; - i_upd_r(1:ny) = (1:ny); - i_upd_y(1:ny) = ny+(1:ny); - i1 = ny+1; - i2 = 2*ny; - n1 = ny+1; - n2 = 2*ny; - for i=2:periods - k = n1:n2; - for j=1:nnodes^min(i-1,order) - i_upd_r(i1:i2) = (n1:n2)+(j-1)*ny*periods; - i_upd_y(i1:i2) = (n1:n2)+ny+(j-1)*ny*(periods+2); - i1 = i2+1; - i2 = i2+ny; - end - n1 = n2+1; - n2 = n2+ny; +% The columns of A map the elements of Y such that +% each block of Y with ny rows are unfolded column wise +dimension = ny*(sum(nnodes.^(0:order-1),2)+(periods-order)*world_nbr); +if order == 0 + i_upd_r = (1:ny*periods); + i_upd_y = i_upd_r + ny; +else + i_upd_r = zeros(dimension,1); + i_upd_y = i_upd_r; + i_upd_r(1:ny) = (1:ny); + i_upd_y(1:ny) = ny+(1:ny); + i1 = ny+1; + i2 = 2*ny; + n1 = ny+1; + n2 = 2*ny; + for i=2:periods + k = n1:n2; + for j=1:nnodes^min(i-1,order) + i_upd_r(i1:i2) = (n1:n2)+(j-1)*ny*periods; + i_upd_y(i1:i2) = (n1:n2)+ny+(j-1)*ny*(periods+2); + i1 = i2+1; + i2 = i2+ny; end + n1 = n2+1; + n2 = n2+ny; end - icA = [find(lead_lag_incidence(1,:)) find(lead_lag_incidence(2,:))+world_nbr*ny ... - find(lead_lag_incidence(3,:))+2*world_nbr*ny]'; - h1 = clock; - for iter = 1:maxit - h2 = clock; - A1 = sparse([],[],[],ny*(sum(nnodes.^(0:order-1),2)+1),dimension,(order+1)*world_nbr*nnz(jacobian)); - res = zeros(ny,periods,world_nbr); - i_rows = 1:ny; - i_cols = find(lead_lag_incidence'); - i_cols_p = i_cols(1:nyp); - i_cols_s = i_cols(nyp+(1:ny)); - i_cols_f = i_cols(nyp+ny+(1:nyf)); - i_cols_A = i_cols; - i_cols_Ap = i_cols_p; - i_cols_As = i_cols_s; - i_cols_Af = i_cols_f - ny; - for i = 1:order+1 - i_w_p = 1; - for j = 1:nnodes^(i-1) - innovation = exo_simul; - if i > 1 - innovation(i+1,:) = nodes(mod(j-1,nnodes)+1,:); - end - if i <= order - for k=1:nnodes - y = [Y(i_cols_p,i_w_p); - Y(i_cols_s,j); - Y(i_cols_f,(j-1)*nnodes+k)]; - [d1,jacobian] = dynamic_model(y,innovation,params,steady_state,i+1); - if i == 1 - % in first period we don't keep track of - % predetermined variables - i_cols_A = [i_cols_As - ny; i_cols_Af]; - A1(i_rows,i_cols_A) = A1(i_rows,i_cols_A) + weights(k)*jacobian(:,i_cols_1); - else - i_cols_A = [i_cols_Ap; i_cols_As; i_cols_Af]; - A1(i_rows,i_cols_A) = A1(i_rows,i_cols_A) + weights(k)*jacobian(:,i_cols_j); - end - res(:,i,j) = res(:,i,j)+weights(k)*d1; - i_cols_Af = i_cols_Af + ny; - end - else +end +icA = [find(lead_lag_incidence(1,:)) find(lead_lag_incidence(2,:))+world_nbr*ny ... + find(lead_lag_incidence(3,:))+2*world_nbr*ny]'; +h1 = clock; +for iter = 1:maxit + h2 = clock; + A1 = sparse([],[],[],ny*(sum(nnodes.^(0:order-1),2)+1),dimension,(order+1)*world_nbr*nnz(jacobian)); + res = zeros(ny,periods,world_nbr); + i_rows = 1:ny; + i_cols = find(lead_lag_incidence'); + i_cols_p = i_cols(1:nyp); + i_cols_s = i_cols(nyp+(1:ny)); + i_cols_f = i_cols(nyp+ny+(1:nyf)); + i_cols_A = i_cols; + i_cols_Ap = i_cols_p; + i_cols_As = i_cols_s; + i_cols_Af = i_cols_f - ny; + for i = 1:order+1 + i_w_p = 1; + for j = 1:nnodes^(i-1) + innovation = exo_simul; + if i > 1 + innovation(i+1,:) = nodes(mod(j-1,nnodes)+1,:); + end + if i <= order + for k=1:nnodes y = [Y(i_cols_p,i_w_p); Y(i_cols_s,j); - Y(i_cols_f,j)]; + Y(i_cols_f,(j-1)*nnodes+k)]; [d1,jacobian] = dynamic_model(y,innovation,params,steady_state,i+1); if i == 1 % in first period we don't keep track of % predetermined variables i_cols_A = [i_cols_As - ny; i_cols_Af]; - A1(i_rows,i_cols_A) = jacobian(:,i_cols_1); + A1(i_rows,i_cols_A) = A1(i_rows,i_cols_A) + weights(k)*jacobian(:,i_cols_1); else i_cols_A = [i_cols_Ap; i_cols_As; i_cols_Af]; - A1(i_rows,i_cols_A) = jacobian(:,i_cols_j); + A1(i_rows,i_cols_A) = A1(i_rows,i_cols_A) + weights(k)*jacobian(:,i_cols_j); end - res(:,i,j) = d1; + res(:,i,j) = res(:,i,j)+weights(k)*d1; i_cols_Af = i_cols_Af + ny; end - i_rows = i_rows + ny; - if mod(j,nnodes) == 0 - i_w_p = i_w_p + 1; - end - if i > 1 - if mod(j,nnodes) == 0 - i_cols_Ap = i_cols_Ap + ny; - end - i_cols_As = i_cols_As + ny; - end - end - i_cols_p = i_cols_p + ny; - i_cols_s = i_cols_s + ny; - i_cols_f = i_cols_f + ny; - end - nzA = cell(periods,world_nbr); - for j=1:world_nbr - i_rows_y = find(lead_lag_incidence')+(order+1)*ny; - offset_c = ny*(sum(nnodes.^(0:order-1),2)+j-1); - offset_r = (j-1)*ny; - for i=order+2:periods - [d1,jacobian] = dynamic_model(Y(i_rows_y,j), ... - exo_simul,params, ... - steady_state,i+1); - if i == periods - [ir,ic,v] = find(jacobian(:,i_cols_T)); + else + y = [Y(i_cols_p,i_w_p); + Y(i_cols_s,j); + Y(i_cols_f,j)]; + [d1,jacobian] = dynamic_model(y,innovation,params,steady_state,i+1); + if i == 1 + % in first period we don't keep track of + % predetermined variables + i_cols_A = [i_cols_As - ny; i_cols_Af]; + A1(i_rows,i_cols_A) = jacobian(:,i_cols_1); else - [ir,ic,v] = find(jacobian(:,i_cols_j)); + i_cols_A = [i_cols_Ap; i_cols_As; i_cols_Af]; + A1(i_rows,i_cols_A) = jacobian(:,i_cols_j); end - nzA{i,j} = [offset_r+ir,offset_c+icA(ic), v]'; res(:,i,j) = d1; - i_rows_y = i_rows_y + ny; - offset_c = offset_c + world_nbr*ny; - offset_r = offset_r + world_nbr*ny; + i_cols_Af = i_cols_Af + ny; + end + i_rows = i_rows + ny; + if mod(j,nnodes) == 0 + i_w_p = i_w_p + 1; + end + if i > 1 + if mod(j,nnodes) == 0 + i_cols_Ap = i_cols_Ap + ny; + end + i_cols_As = i_cols_As + ny; end end - err = max(abs(res(i_upd_r))); - if err < tolerance - stop = 1; - if verbose - fprintf('\n') ; - disp([' Total time of simulation :' num2str(etime(clock,h1))]) ; - fprintf('\n') ; - disp([' Convergency obtained.']) ; - fprintf('\n') ; + i_cols_p = i_cols_p + ny; + i_cols_s = i_cols_s + ny; + i_cols_f = i_cols_f + ny; + end + nzA = cell(periods,world_nbr); + for j=1:world_nbr + i_rows_y = find(lead_lag_incidence')+(order+1)*ny; + offset_c = ny*(sum(nnodes.^(0:order-1),2)+j-1); + offset_r = (j-1)*ny; + for i=order+2:periods + [d1,jacobian] = dynamic_model(Y(i_rows_y,j), ... + exo_simul,params, ... + steady_state,i+1); + if i == periods + [ir,ic,v] = find(jacobian(:,i_cols_T)); + else + [ir,ic,v] = find(jacobian(:,i_cols_j)); end - flag = 0;% Convergency obtained. - endo_simul = reshape(Y(:,1),ny,periods+2);%Y(ny+(1:ny),1); - % figure;plot(Y(16:ny:(periods+2)*ny,:)) - % pause - break + nzA{i,j} = [offset_r+ir,offset_c+icA(ic), v]'; + res(:,i,j) = d1; + i_rows_y = i_rows_y + ny; + offset_c = offset_c + world_nbr*ny; + offset_r = offset_r + world_nbr*ny; end - A2 = [nzA{:}]'; - A = [A1; sparse(A2(:,1),A2(:,2),A2(:,3),ny*(periods-order-1)*world_nbr,dimension)]; - dy = -A\res(i_upd_r); - Y(i_upd_y) = Y(i_upd_y) + dy; end - - if ~stop + err = max(abs(res(i_upd_r))); + if err < tolerance + stop = 1; if verbose fprintf('\n') ; - disp([' Total time of simulation :' num2str(etime(clock,h1))]) ; + disp([' Total time of simulation :' num2str(etime(clock,h1))]) ; fprintf('\n') ; - disp(['WARNING : maximum number of iterations is reached (modify options_.simul.maxit).']) ; + disp([' Convergency obtained.']) ; fprintf('\n') ; end - flag = 1;% more iterations are needed. - endo_simul = 1; + flag = 0;% Convergency obtained. + endo_simul = reshape(Y(:,1),ny,periods+2);%Y(ny+(1:ny),1); + % figure;plot(Y(16:ny:(periods+2)*ny,:)) + % pause + break end + A2 = [nzA{:}]'; + A = [A1; sparse(A2(:,1),A2(:,2),A2(:,3),ny*(periods-order-1)*world_nbr,dimension)]; + dy = -A\res(i_upd_r); + Y(i_upd_y) = Y(i_upd_y) + dy; +end + +if ~stop if verbose - disp (['-----------------------------------------------------']) ; + fprintf('\n') ; + disp([' Total time of simulation :' num2str(etime(clock,h1))]) ; + fprintf('\n') ; + disp(['WARNING : maximum number of iterations is reached (modify options_.simul.maxit).']) ; + fprintf('\n') ; end + flag = 1;% more iterations are needed. + endo_simul = 1; +end +if verbose + disp (['-----------------------------------------------------']) ; +end diff --git a/matlab/ep/stroud_judd_7.5.8.m b/matlab/ep/stroud_judd_7.5.8.m index 40c9bc08db..57d3f8d62f 100644 --- a/matlab/ep/stroud_judd_7.5.8.m +++ b/matlab/ep/stroud_judd_7.5.8.m @@ -1,9 +1,9 @@ -function [X,w]=stroud_judd_7.5.8(d) - - E = eye(d); - X = cell(2*d,1); - m = 1; - for i=1:d - X{m} = E(:,i); - m = m+1; - X{m} = -E(:,i); +function [X,w]=stroud_judd_7.5.8.5.8(d) + +E = eye(d); +X = cell(2*d,1); +m = 1; +for i=1:d + X{m} = E(:,i); + m = m+1; + X{m} = -E(:,i); diff --git a/matlab/evaluate_max_dynamic_residual.m b/matlab/evaluate_max_dynamic_residual.m index 41aa4ec249..ac4dbb32a0 100644 --- a/matlab/evaluate_max_dynamic_residual.m +++ b/matlab/evaluate_max_dynamic_residual.m @@ -16,7 +16,7 @@ function err = evaluate_max_dynamic_residual(model_dynamic, Y, exogenous_variabl % % You should have received a copy of the GNU General Public License % along with Dynare. If not, see <http://www.gnu.org/licenses/>. - + i_rows = 1:ny; i_cols = find(lead_lag_incidence'); diff --git a/matlab/evaluate_planner_objective.m b/matlab/evaluate_planner_objective.m index 40f1865903..599fab1c04 100644 --- a/matlab/evaluate_planner_objective.m +++ b/matlab/evaluate_planner_objective.m @@ -40,7 +40,7 @@ if nspred > 180 return end beta = get_optimal_policy_discount_factor(M.params,M.param_names); - + Gy = dr.ghx(nstatic+(1:nspred),:); Gu = dr.ghu(nstatic+(1:nspred),:); gy(dr.order_var,:) = dr.ghx; @@ -113,7 +113,7 @@ if ~options.noprint disp('Approximated value of planner objective function') if options.ramsey_policy disp([' - with initial Lagrange multipliers set to 0: ' ... - num2str(planner_objective_value(2)) ]) + num2str(planner_objective_value(2)) ]) disp([' - with initial Lagrange multipliers set to steady state: ' ... num2str(planner_objective_value(1)) ]) elseif options.discretionary_policy diff --git a/matlab/evaluate_smoother.m b/matlab/evaluate_smoother.m index fb3eaad7ad..09fb958be7 100644 --- a/matlab/evaluate_smoother.m +++ b/matlab/evaluate_smoother.m @@ -106,7 +106,7 @@ end [oo_]=store_smoother_results(M_,oo_,options_,bayestopt_,dataset_,dataset_info,atT,innov,measurement_error,updated_variables,ys,trend_coeff,aK,P,PK,decomp,Trend,state_uncertainty); if nargout>4 - Smoothed_variables_declaration_order_deviation_form=atT(oo_.dr.inv_order_var(bayestopt_.smoother_var_list),:); + Smoothed_variables_declaration_order_deviation_form=atT(oo_.dr.inv_order_var(bayestopt_.smoother_var_list),:); end %reset qz_criterium diff --git a/matlab/evaluate_static_model.m b/matlab/evaluate_static_model.m index 9225179642..873dabe2b4 100644 --- a/matlab/evaluate_static_model.m +++ b/matlab/evaluate_static_model.m @@ -37,29 +37,29 @@ function [residuals,check1,jacob] = evaluate_static_model(ys,exo_ss,params,M,opt % You should have received a copy of the GNU General Public License % along with Dynare. If not, see <http://www.gnu.org/licenses/>. - check1 = 0; - if options.bytecode - [check1, residuals] = bytecode('evaluate','static',ys,... - exo_ss, params, ys, 1); - mexErrCheck('bytecode', check1); - else - fh_static = str2func([M.fname '_static']); - if options.block - residuals = zeros(M.endo_nbr,1); - for b = 1:length(M.block_structure_stat.block) - mfsb = M.block_structure_stat.block(b).variable; - % blocks that can be directly evaluated (mfsb is empty) - % have zero residuals by construction - if M.block_structure_stat.block(b).Simulation_Type ~= 1 && ... - M.block_structure_stat.block(b).Simulation_Type ~= 2 - residuals(mfsb) = feval(fh_static,b,ys,exo_ss,params); - else - %need to evaluate the recursive blocks to compute the - %temporary terms - feval(fh_static,b,ys,exo_ss,params); - end +check1 = 0; +if options.bytecode + [check1, residuals] = bytecode('evaluate','static',ys,... + exo_ss, params, ys, 1); + mexErrCheck('bytecode', check1); +else + fh_static = str2func([M.fname '_static']); + if options.block + residuals = zeros(M.endo_nbr,1); + for b = 1:length(M.block_structure_stat.block) + mfsb = M.block_structure_stat.block(b).variable; + % blocks that can be directly evaluated (mfsb is empty) + % have zero residuals by construction + if M.block_structure_stat.block(b).Simulation_Type ~= 1 && ... + M.block_structure_stat.block(b).Simulation_Type ~= 2 + residuals(mfsb) = feval(fh_static,b,ys,exo_ss,params); + else + %need to evaluate the recursive blocks to compute the + %temporary terms + feval(fh_static,b,ys,exo_ss,params); end - else - residuals = feval(fh_static,ys,exo_ss,params); end + else + residuals = feval(fh_static,ys,exo_ss,params); end +end diff --git a/matlab/evaluate_steady_state.m b/matlab/evaluate_steady_state.m index 053d62255e..fd101f3211 100644 --- a/matlab/evaluate_steady_state.m +++ b/matlab/evaluate_steady_state.m @@ -39,120 +39,36 @@ function [ys,params,info] = evaluate_steady_state(ys_init,M,options,oo,steadysta % You should have received a copy of the GNU General Public License % along with Dynare. If not, see <http://www.gnu.org/licenses/>. - info = 0; - check = 0; +info = 0; +check = 0; - steadystate_flag = options.steadystate_flag; - params = M.params; - exo_ss = [oo.exo_steady_state; oo.exo_det_steady_state]; +steadystate_flag = options.steadystate_flag; +params = M.params; +exo_ss = [oo.exo_steady_state; oo.exo_det_steady_state]; - if length(M.aux_vars) > 0 - h_set_auxiliary_variables = str2func([M.fname '_set_auxiliary_variables']); - if ~steadystate_flag - ys_init = h_set_auxiliary_variables(ys_init,exo_ss,M.params); - end +if length(M.aux_vars) > 0 + h_set_auxiliary_variables = str2func([M.fname '_set_auxiliary_variables']); + if ~steadystate_flag + ys_init = h_set_auxiliary_variables(ys_init,exo_ss,M.params); end +end - if options.ramsey_policy - if steadystate_flag - % explicit steady state file - [ys,params,info] = evaluate_steady_state_file(ys_init,exo_ss,M, ... - options,steadystate_check_flag); - %test whether it solves model conditional on the instruments - resids = evaluate_static_model(ys,exo_ss,params,M,options); - n_multipliers=M.ramsey_eq_nbr; - nan_indices=find(isnan(resids(n_multipliers+1:end))); - - if ~isempty(nan_indices) - if options.debug - fprintf('\nevaluate_steady_state: The steady state file computation for the Ramsey problem resulted in NaNs.\n') - fprintf('evaluate_steady_state: The steady state was computed conditional on the following initial instrument values: \n') - for ii = 1:size(options.instruments,1); - fprintf('\t %s \t %f \n',options.instruments(ii,:),ys_init(strmatch(options.instruments(ii,:),M.endo_names,'exact'))) - end - fprintf('evaluate_steady_state: The problem occured in the following equations: \n') - fprintf('\t Equation(s): ') - for ii=1:length(nan_indices) - fprintf('%d, ',nan_indices(ii)); - end - skipline(); - fprintf('evaluate_steady_state: If those initial values are not admissable, change them using an initval-block.\n') - skipline(2); - end - info(1) = 84; - info(2) = resids'*resids; - return; - end - - if any(imag(ys(n_multipliers+1:end))) - if options.debug - fprintf('\nevaluate_steady_state: The steady state file computation for the Ramsey problem resulted in complex numbers.\n') - fprintf('evaluate_steady_state: The steady state was computed conditional on the following initial instrument values: \n') - for ii = 1:size(options.instruments,1); - fprintf('\t %s \t %f \n',options.instruments(ii,:),ys_init(strmatch(options.instruments(ii,:),M.endo_names,'exact'))) - end - fprintf('evaluate_steady_state: If those initial values are not admissable, change them using an initval-block.\n') - skipline(2); - end - info(1) = 86; - info(2) = resids'*resids; - return; - end - - if max(abs(resids(n_multipliers+1:end))) > options.solve_tolf %does it solve for all variables except for the Lagrange multipliers - if options.debug - fprintf('\nevaluate_steady_state: The steady state file does not solve the steady state for the Ramsey problem.\n') - fprintf('evaluate_steady_state: Conditional on the following instrument values: \n') - for ii = 1:size(options.instruments,1); - fprintf('\t %s \t %f \n',options.instruments(ii,:),ys_init(strmatch(options.instruments(ii,:),M.endo_names,'exact'))) - end - fprintf('evaluate_steady_state: the following equations have non-zero residuals: \n') - for ii=n_multipliers+1:M.endo_nbr - if abs(resids(ii)) > options.solve_tolf - fprintf('\t Equation number %d: %f\n',ii-n_multipliers, resids(ii)) - end - end - skipline(2); - end - info(1) = 85; - info(2) = resids'*resids; - return; - end - end - if options.debug - infrow=find(isinf(ys_init)); - if ~isempty(infrow) - fprintf('\nevaluate_steady_state: The initial values for the steady state of the following variables are Inf:\n'); - for iter=1:length(infrow) - fprintf('%s\n',M.endo_names(infrow(iter),:)); - end - end - nanrow=find(isnan(ys_init)); - if ~isempty(nanrow) - fprintf('\nevaluate_steady_state: The initial values for the steady state of the following variables are NaN:\n'); - for iter=1:length(nanrow) - fprintf('%s\n',M.endo_names(nanrow(iter),:)); - end - end - end - %either if no steady state file or steady state file without problems - [ys,params,info] = dyn_ramsey_static(ys_init,M,options,oo); - if info - return; - end - %check whether steady state really solves the model +if options.ramsey_policy + if steadystate_flag + % explicit steady state file + [ys,params,info] = evaluate_steady_state_file(ys_init,exo_ss,M, ... + options,steadystate_check_flag); + %test whether it solves model conditional on the instruments resids = evaluate_static_model(ys,exo_ss,params,M,options); - n_multipliers=M.ramsey_eq_nbr; - nan_indices_multiplier=find(isnan(resids(1:n_multipliers))); nan_indices=find(isnan(resids(n_multipliers+1:end))); if ~isempty(nan_indices) if options.debug - fprintf('\nevaluate_steady_state: The steady state computation for the Ramsey problem resulted in NaNs.\n') - fprintf('evaluate_steady_state: The steady state computation resulted in the following instrument values: \n') - for i = 1:size(options.instruments,1); - fprintf('\t %s \t %f \n',options.instruments(i,:),ys(strmatch(options.instruments(i,:),M.endo_names,'exact'))) + fprintf('\nevaluate_steady_state: The steady state file computation for the Ramsey problem resulted in NaNs.\n') + fprintf('evaluate_steady_state: The steady state was computed conditional on the following initial instrument values: \n') + for ii = 1:size(options.instruments,1); + fprintf('\t %s \t %f \n',options.instruments(ii,:),ys_init(strmatch(options.instruments(ii,:),M.endo_names,'exact'))) end fprintf('evaluate_steady_state: The problem occured in the following equations: \n') fprintf('\t Equation(s): ') @@ -160,188 +76,272 @@ function [ys,params,info] = evaluate_steady_state(ys_init,M,options,oo,steadysta fprintf('%d, ',nan_indices(ii)); end skipline(); + fprintf('evaluate_steady_state: If those initial values are not admissable, change them using an initval-block.\n') + skipline(2); end - info(1) = 82; + info(1) = 84; + info(2) = resids'*resids; return; end - - if ~isempty(nan_indices_multiplier) + + if any(imag(ys(n_multipliers+1:end))) if options.debug - fprintf('\nevaluate_steady_state: The steady state computation for the Ramsey problem resulted in NaNs in the auxiliary equations.\n') - fprintf('evaluate_steady_state: The steady state computation resulted in the following instrument values: \n') - for i = 1:size(options.instruments,1); - fprintf('\t %s \t %f \n',options.instruments(i,:),ys(strmatch(options.instruments(i,:),M.endo_names,'exact'))) - end - fprintf('evaluate_steady_state: The problem occured in the following equations: \n') - fprintf('\t Auxiliary equation(s): ') - for ii=1:length(nan_indices_multiplier) - fprintf('%d, ',nan_indices_multiplier(ii)); + fprintf('\nevaluate_steady_state: The steady state file computation for the Ramsey problem resulted in complex numbers.\n') + fprintf('evaluate_steady_state: The steady state was computed conditional on the following initial instrument values: \n') + for ii = 1:size(options.instruments,1); + fprintf('\t %s \t %f \n',options.instruments(ii,:),ys_init(strmatch(options.instruments(ii,:),M.endo_names,'exact'))) end - skipline(); + fprintf('evaluate_steady_state: If those initial values are not admissable, change them using an initval-block.\n') + skipline(2); end - info(1) = 83; + info(1) = 86; + info(2) = resids'*resids; return; end - if max(abs(resids)) > options.solve_tolf %does it solve for all variables including the auxiliary ones + if max(abs(resids(n_multipliers+1:end))) > options.solve_tolf %does it solve for all variables except for the Lagrange multipliers if options.debug - fprintf('\nevaluate_steady_state: The steady state for the Ramsey problem could not be computed.\n') - fprintf('evaluate_steady_state: The steady state computation stopped with the following instrument values:: \n') - for i = 1:size(options.instruments,1); - fprintf('\t %s \t %f \n',options.instruments(i,:),ys(strmatch(options.instruments(i,:),M.endo_names,'exact'))) - end - fprintf('evaluate_steady_state: The following equations have non-zero residuals: \n') - for ii=1:n_multipliers - if abs(resids(ii)) > options.solve_tolf/100 - fprintf('\t Auxiliary Ramsey equation number %d: %f\n',ii, resids(ii)) - end + fprintf('\nevaluate_steady_state: The steady state file does not solve the steady state for the Ramsey problem.\n') + fprintf('evaluate_steady_state: Conditional on the following instrument values: \n') + for ii = 1:size(options.instruments,1); + fprintf('\t %s \t %f \n',options.instruments(ii,:),ys_init(strmatch(options.instruments(ii,:),M.endo_names,'exact'))) end + fprintf('evaluate_steady_state: the following equations have non-zero residuals: \n') for ii=n_multipliers+1:M.endo_nbr - if abs(resids(ii)) > options.solve_tolf/100 + if abs(resids(ii)) > options.solve_tolf fprintf('\t Equation number %d: %f\n',ii-n_multipliers, resids(ii)) end end skipline(2); end - info(1) = 81; + info(1) = 85; info(2) = resids'*resids; return; end - elseif steadystate_flag - % explicit steady state file - [ys,params,info] = evaluate_steady_state_file(ys_init,exo_ss,M, ... - options,steadystate_check_flag); - if size(ys,2)>size(ys,1) - error('STEADY: steady_state-file must return a column vector, not a row vector.') - end - if info(1) - return; + end + if options.debug + infrow=find(isinf(ys_init)); + if ~isempty(infrow) + fprintf('\nevaluate_steady_state: The initial values for the steady state of the following variables are Inf:\n'); + for iter=1:length(infrow) + fprintf('%s\n',M.endo_names(infrow(iter),:)); + end end - elseif (options.bytecode == 0 && options.block == 0) - if options.linear == 0 - % non linear model - static_model = str2func([M.fname '_static']); - [ys,check] = dynare_solve(@static_problem,... - ys_init,... - options, exo_ss, params,... - M.endo_nbr,... - static_model); - if check && options.debug - [ys,check,fvec,fjac] = dynare_solve(@static_problem,... - ys_init,... - options, exo_ss, params,... - M.endo_nbr,... - static_model); - [infrow,infcol]=find(isinf(fjac) | isnan(fjac)); - if ~isempty(infrow) - fprintf('\nSTEADY: The Jacobian at the initial values contains Inf or NaN. The problem arises from: \n') - display_problematic_vars_Jacobian(infrow,infcol,M,ys_init,'static','STEADY: ') - end - problematic_equation = find(~isfinite(fvec)); - if ~isempty(problematic_equation) - fprintf('\nSTEADY: numerical initial values or parameters incompatible with the following equations\n') - disp(problematic_equation') - fprintf('Please check for example\n') - fprintf(' i) if all parameters occurring in these equations are defined\n') - fprintf(' ii) that no division by an endogenous variable initialized to 0 occurs\n') - end + nanrow=find(isnan(ys_init)); + if ~isempty(nanrow) + fprintf('\nevaluate_steady_state: The initial values for the steady state of the following variables are NaN:\n'); + for iter=1:length(nanrow) + fprintf('%s\n',M.endo_names(nanrow(iter),:)); end - else - % linear model - fh_static = str2func([M.fname '_static']); - [fvec,jacob] = fh_static(ys_init,exo_ss, ... - params); + end + end + %either if no steady state file or steady state file without problems + [ys,params,info] = dyn_ramsey_static(ys_init,M,options,oo); + if info + return; + end + %check whether steady state really solves the model + resids = evaluate_static_model(ys,exo_ss,params,M,options); - ii = find(~isfinite(fvec)); - if ~isempty(ii) - ys=fvec; - check=1; - disp(['STEADY: numerical initial values or parameters incompatible with the following' ... - ' equations']) - disp(ii') - disp('Check whether your model is truly linear. Put "resid(1);" before "steady;" to see the problematic equations.\n') - elseif isempty(ii) && max(abs(fvec)) > 1e-12 - ys = ys_init-jacob\fvec; - resid = evaluate_static_model(ys,exo_ss,params,M,options); - if max(abs(resid)) > 1e-6 - check=1; - fprintf('STEADY: No steady state for your model could be found\n') - fprintf('STEADY: Check whether your model is truly linear. Put "resid(1);" before "steady;" to see the problematic equations.\n') - end + n_multipliers=M.ramsey_eq_nbr; + nan_indices_multiplier=find(isnan(resids(1:n_multipliers))); + nan_indices=find(isnan(resids(n_multipliers+1:end))); - else - ys = ys_init; + if ~isempty(nan_indices) + if options.debug + fprintf('\nevaluate_steady_state: The steady state computation for the Ramsey problem resulted in NaNs.\n') + fprintf('evaluate_steady_state: The steady state computation resulted in the following instrument values: \n') + for i = 1:size(options.instruments,1); + fprintf('\t %s \t %f \n',options.instruments(i,:),ys(strmatch(options.instruments(i,:),M.endo_names,'exact'))) end - if options.debug - if any(any(isinf(jacob) | isnan(jacob))) - [infrow,infcol]=find(isinf(jacob) | isnan(jacob)); - fprintf('\nSTEADY: The Jacobian contains Inf or NaN. The problem arises from: \n\n') - for ii=1:length(infrow) - fprintf('STEADY: Derivative of Equation %d with respect to Variable %s (initial value of %s: %g) \n',infrow(ii),deblank(M.endo_names(infcol(ii),:)),deblank(M.endo_names(infcol(ii),:)),ys_init(infcol(ii))) - end - fprintf('Check whether your model is truly linear. Put "resid(1);" before "steady;" to see the problematic equations.\n') - end + fprintf('evaluate_steady_state: The problem occured in the following equations: \n') + fprintf('\t Equation(s): ') + for ii=1:length(nan_indices) + fprintf('%d, ',nan_indices(ii)); end + skipline(); end - else - % block or bytecode - [ys,check] = dynare_solve_block_or_bytecode(ys_init,exo_ss, params, ... - options, M); + info(1) = 82; + return; end - if check - info(1)= 20; - %make sure ys contains auxiliary variables in case of problem with dynare_solve - if length(M.aux_vars) > 0 && ~steadystate_flag - ys = h_set_auxiliary_variables(ys,exo_ss,M.params); + if ~isempty(nan_indices_multiplier) + if options.debug + fprintf('\nevaluate_steady_state: The steady state computation for the Ramsey problem resulted in NaNs in the auxiliary equations.\n') + fprintf('evaluate_steady_state: The steady state computation resulted in the following instrument values: \n') + for i = 1:size(options.instruments,1); + fprintf('\t %s \t %f \n',options.instruments(i,:),ys(strmatch(options.instruments(i,:),M.endo_names,'exact'))) + end + fprintf('evaluate_steady_state: The problem occured in the following equations: \n') + fprintf('\t Auxiliary equation(s): ') + for ii=1:length(nan_indices_multiplier) + fprintf('%d, ',nan_indices_multiplier(ii)); + end + skipline(); end - resid = evaluate_static_model(ys,exo_ss,params,M,options); - info(2) = resid'*resid ; - if isnan(info(2)) - info(1)=22; + info(1) = 83; + return; + end + + if max(abs(resids)) > options.solve_tolf %does it solve for all variables including the auxiliary ones + if options.debug + fprintf('\nevaluate_steady_state: The steady state for the Ramsey problem could not be computed.\n') + fprintf('evaluate_steady_state: The steady state computation stopped with the following instrument values:: \n') + for i = 1:size(options.instruments,1); + fprintf('\t %s \t %f \n',options.instruments(i,:),ys(strmatch(options.instruments(i,:),M.endo_names,'exact'))) + end + fprintf('evaluate_steady_state: The following equations have non-zero residuals: \n') + for ii=1:n_multipliers + if abs(resids(ii)) > options.solve_tolf/100 + fprintf('\t Auxiliary Ramsey equation number %d: %f\n',ii, resids(ii)) + end + end + for ii=n_multipliers+1:M.endo_nbr + if abs(resids(ii)) > options.solve_tolf/100 + fprintf('\t Equation number %d: %f\n',ii-n_multipliers, resids(ii)) + end + end + skipline(2); end - return + info(1) = 81; + info(2) = resids'*resids; + return; + end +elseif steadystate_flag + % explicit steady state file + [ys,params,info] = evaluate_steady_state_file(ys_init,exo_ss,M, ... + options,steadystate_check_flag); + if size(ys,2)>size(ys,1) + error('STEADY: steady_state-file must return a column vector, not a row vector.') + end + if info(1) + return; end +elseif (options.bytecode == 0 && options.block == 0) + if options.linear == 0 + % non linear model + static_model = str2func([M.fname '_static']); + [ys,check] = dynare_solve(@static_problem,... + ys_init,... + options, exo_ss, params,... + M.endo_nbr,... + static_model); + if check && options.debug + [ys,check,fvec,fjac] = dynare_solve(@static_problem,... + ys_init,... + options, exo_ss, params,... + M.endo_nbr,... + static_model); + [infrow,infcol]=find(isinf(fjac) | isnan(fjac)); + if ~isempty(infrow) + fprintf('\nSTEADY: The Jacobian at the initial values contains Inf or NaN. The problem arises from: \n') + display_problematic_vars_Jacobian(infrow,infcol,M,ys_init,'static','STEADY: ') + end + problematic_equation = find(~isfinite(fvec)); + if ~isempty(problematic_equation) + fprintf('\nSTEADY: numerical initial values or parameters incompatible with the following equations\n') + disp(problematic_equation') + fprintf('Please check for example\n') + fprintf(' i) if all parameters occurring in these equations are defined\n') + fprintf(' ii) that no division by an endogenous variable initialized to 0 occurs\n') + end + end + else + % linear model + fh_static = str2func([M.fname '_static']); + [fvec,jacob] = fh_static(ys_init,exo_ss, ... + params); + + ii = find(~isfinite(fvec)); + if ~isempty(ii) + ys=fvec; + check=1; + disp(['STEADY: numerical initial values or parameters incompatible with the following' ... + ' equations']) + disp(ii') + disp('Check whether your model is truly linear. Put "resid(1);" before "steady;" to see the problematic equations.\n') + elseif isempty(ii) && max(abs(fvec)) > 1e-12 + ys = ys_init-jacob\fvec; + resid = evaluate_static_model(ys,exo_ss,params,M,options); + if max(abs(resid)) > 1e-6 + check=1; + fprintf('STEADY: No steady state for your model could be found\n') + fprintf('STEADY: Check whether your model is truly linear. Put "resid(1);" before "steady;" to see the problematic equations.\n') + end - % If some equations are tagged [static] or [dynamic], verify consistency - if M.static_and_dynamic_models_differ - % Evaluate residual of *dynamic* model using the steady state - % computed on the *static* one - z = repmat(ys,1,M.maximum_lead + M.maximum_lag + 1); - zx = repmat([exo_ss'], M.maximum_lead + M.maximum_lag + 1, 1); - if options.bytecode - [chck, r, junk]= bytecode('dynamic','evaluate', z, zx, M.params, ys, 1); - mexErrCheck('bytecode', chck); - elseif options.block - [r, oo.dr] = feval([M.fname '_dynamic'], z', zx, M.params, ys, M.maximum_lag+1, oo.dr); else - iyv = M.lead_lag_incidence'; - iyr0 = find(iyv(:)); - xys = z(iyr0); - r = feval([M.fname '_dynamic'], z(iyr0), zx, M.params, ys, M.maximum_lag + 1); + ys = ys_init; end - - % Fail if residual greater than tolerance - if max(abs(r)) > options.solve_tolf - info(1) = 25; - return + if options.debug + if any(any(isinf(jacob) | isnan(jacob))) + [infrow,infcol]=find(isinf(jacob) | isnan(jacob)); + fprintf('\nSTEADY: The Jacobian contains Inf or NaN. The problem arises from: \n\n') + for ii=1:length(infrow) + fprintf('STEADY: Derivative of Equation %d with respect to Variable %s (initial value of %s: %g) \n',infrow(ii),deblank(M.endo_names(infcol(ii),:)),deblank(M.endo_names(infcol(ii),:)),ys_init(infcol(ii))) + end + fprintf('Check whether your model is truly linear. Put "resid(1);" before "steady;" to see the problematic equations.\n') + end end end +else + % block or bytecode + [ys,check] = dynare_solve_block_or_bytecode(ys_init,exo_ss, params, ... + options, M); +end - if ~isreal(ys) - info(1) = 21; - info(2) = sum(imag(ys).^2); - ys = real(ys); - return +if check + info(1)= 20; + %make sure ys contains auxiliary variables in case of problem with dynare_solve + if length(M.aux_vars) > 0 && ~steadystate_flag + ys = h_set_auxiliary_variables(ys,exo_ss,M.params); + end + resid = evaluate_static_model(ys,exo_ss,params,M,options); + info(2) = resid'*resid ; + if isnan(info(2)) + info(1)=22; end + return +end - if ~isempty(find(isnan(ys))) - info(1) = 22; - info(2) = NaN; +% If some equations are tagged [static] or [dynamic], verify consistency +if M.static_and_dynamic_models_differ + % Evaluate residual of *dynamic* model using the steady state + % computed on the *static* one + z = repmat(ys,1,M.maximum_lead + M.maximum_lag + 1); + zx = repmat([exo_ss'], M.maximum_lead + M.maximum_lag + 1, 1); + if options.bytecode + [chck, r, junk]= bytecode('dynamic','evaluate', z, zx, M.params, ys, 1); + mexErrCheck('bytecode', chck); + elseif options.block + [r, oo.dr] = feval([M.fname '_dynamic'], z', zx, M.params, ys, M.maximum_lag+1, oo.dr); + else + iyv = M.lead_lag_incidence'; + iyr0 = find(iyv(:)); + xys = z(iyr0); + r = feval([M.fname '_dynamic'], z(iyr0), zx, M.params, ys, M.maximum_lag + 1); + end + + % Fail if residual greater than tolerance + if max(abs(r)) > options.solve_tolf + info(1) = 25; return end +end + +if ~isreal(ys) + info(1) = 21; + info(2) = sum(imag(ys).^2); + ys = real(ys); + return +end + +if ~isempty(find(isnan(ys))) + info(1) = 22; + info(2) = NaN; + return +end function [resids,jac] = static_problem(y,x,params,nvar,fh_static_model) - [r,j] = fh_static_model(y,x,params); - resids = r(1:nvar); - jac = j(1:nvar,1:nvar); +[r,j] = fh_static_model(y,x,params); +resids = r(1:nvar); +jac = j(1:nvar,1:nvar); diff --git a/matlab/evaluate_steady_state_file.m b/matlab/evaluate_steady_state_file.m index 8f67a5b87d..2e3afceb9e 100644 --- a/matlab/evaluate_steady_state_file.m +++ b/matlab/evaluate_steady_state_file.m @@ -36,125 +36,125 @@ function [ys,params,info] = evaluate_steady_state_file(ys_init,exo_ss,M,options, % You should have received a copy of the GNU General Public License % along with Dynare. If not, see <http://www.gnu.org/licenses/>. - debug = false; +debug = false; - ys = []; - params = M.params; - info = 0; +ys = []; +params = M.params; +info = 0; - fname = M.fname; +fname = M.fname; - if options.steadystate_flag == 1 - % old format - assignin('base','tmp_00_',params); - evalin('base','M_.params=tmp_00_; clear(''tmp_00_'')'); - h_steadystate = str2func([fname '_steadystate']); - [ys,check] = h_steadystate(ys_init, exo_ss); - params1 = evalin('base','M_.params'); - else % steadystate_flag == 2 - % new format - h_steadystate = str2func([fname '_steadystate2']); - [ys,params1,check] = h_steadystate(ys_init, exo_ss, params); - end - - if check - info(1) = 19; - info(2) = NaN; - return - end - - if M.param_nbr > 0 - updated_params_flag = max(abs(params1-params)) > 1e-12 ... - || ~isequal(isnan(params1),isnan(params)); %checks whether numbers or NaN changed - else - updated_params_flag = 0; - end +if options.steadystate_flag == 1 + % old format + assignin('base','tmp_00_',params); + evalin('base','M_.params=tmp_00_; clear(''tmp_00_'')'); + h_steadystate = str2func([fname '_steadystate']); + [ys,check] = h_steadystate(ys_init, exo_ss); + params1 = evalin('base','M_.params'); +else % steadystate_flag == 2 + % new format + h_steadystate = str2func([fname '_steadystate2']); + [ys,params1,check] = h_steadystate(ys_init, exo_ss, params); +end - h_set_auxiliary_variables = str2func([M.fname '_set_auxiliary_variables']); - if isnan(updated_params_flag) || (updated_params_flag && any(isnan(params(~isnan(params))-params1(~isnan(params))))) %checks if new NaNs were added - info(1) = 24; - info(2) = NaN; - ys = h_set_auxiliary_variables(ys,exo_ss,params); - return - end +if check + info(1) = 19; + info(2) = NaN; + return +end - if updated_params_flag && ~isreal(params1) - info(1) = 23; - info(2) = sum(imag(params).^2); - ys = h_set_auxiliary_variables(ys,exo_ss,params); - return +if M.param_nbr > 0 + updated_params_flag = max(abs(params1-params)) > 1e-12 ... + || ~isequal(isnan(params1),isnan(params)); %checks whether numbers or NaN changed +else + updated_params_flag = 0; +end + +h_set_auxiliary_variables = str2func([M.fname '_set_auxiliary_variables']); +if isnan(updated_params_flag) || (updated_params_flag && any(isnan(params(~isnan(params))-params1(~isnan(params))))) %checks if new NaNs were added + info(1) = 24; + info(2) = NaN; + ys = h_set_auxiliary_variables(ys,exo_ss,params); + return +end + +if updated_params_flag && ~isreal(params1) + info(1) = 23; + info(2) = sum(imag(params).^2); + ys = h_set_auxiliary_variables(ys,exo_ss,params); + return +end + +if updated_params_flag + params = params1; +end + +% adding values for auxiliary variables +if length(M.aux_vars) > 0 && ~options.ramsey_policy + if debug + ys0 = ys; end - - if updated_params_flag - params = params1; + ys = h_set_auxiliary_variables(ys,exo_ss,params); + if debug + ys1 = ys; end - - % adding values for auxiliary variables - if length(M.aux_vars) > 0 && ~options.ramsey_policy - if debug - ys0 = ys; - end + ys = h_set_auxiliary_variables(ys,exo_ss,params); + if debug + ys2 = ys; + end + if debug ys = h_set_auxiliary_variables(ys,exo_ss,params); - if debug - ys1 = ys; + ys3 = ys; + idx = find(abs(ys0-ys1)>0); + if ~isempty(idx) + M.endo_names(idx,:) + else + disp('1-invariant') end - ys = h_set_auxiliary_variables(ys,exo_ss,params); - if debug - ys2 = ys; + idx = find(abs(ys2-ys1)>0); + if ~isempty(idx) + M.endo_names(idx,:) + else + disp('2-invariant') end - if debug - ys = h_set_auxiliary_variables(ys,exo_ss,params); - ys3 = ys; - idx = find(abs(ys0-ys1)>0); - if ~isempty(idx) - M.endo_names(idx,:) - else - disp('1-invariant') - end - idx = find(abs(ys2-ys1)>0); - if ~isempty(idx) - M.endo_names(idx,:) - else - disp('2-invariant') - end - idx = find(abs(ys3-ys3)>0); - if ~isempty(idx) - M.endo_names(idx,:) - else - disp('3-invariant') - end - pause + idx = find(abs(ys3-ys3)>0); + if ~isempty(idx) + M.endo_names(idx,:) + else + disp('3-invariant') end + pause end +end - check1 = 0; - if steady_state_checkflag - % Check whether the steady state obtained from the _steadystate file is a steady state. - [residuals, check] = evaluate_static_model(ys, exo_ss, params, M, options); - if check - info(1) = 19; - info(2) = check; % to be improved - return; - end - if max(abs(residuals)) > options.dynatol.f - info(1) = 19; - info(2) = residuals'*residuals; - return - end - if any(isnan(residuals)) - info(1) = 22; - return - end - elseif ~isempty(options.steadystate_partial) - ssvar = options.steadystate_partial.ssvar; - nov = length(ssvar); - indv = zeros(nov,1); - for i = 1:nov - indv(i) = strmatch(ssvar(i),M.endo_names,'exact'); - end - [ys,check] = dynare_solve('restricted_steadystate',... - ys(indv),... - options, exo_ss,indv); +check1 = 0; +if steady_state_checkflag + % Check whether the steady state obtained from the _steadystate file is a steady state. + [residuals, check] = evaluate_static_model(ys, exo_ss, params, M, options); + if check + info(1) = 19; + info(2) = check; % to be improved + return; end + if max(abs(residuals)) > options.dynatol.f + info(1) = 19; + info(2) = residuals'*residuals; + return + end + if any(isnan(residuals)) + info(1) = 22; + return + end +elseif ~isempty(options.steadystate_partial) + ssvar = options.steadystate_partial.ssvar; + nov = length(ssvar); + indv = zeros(nov,1); + for i = 1:nov + indv(i) = strmatch(ssvar(i),M.endo_names,'exact'); + end + [ys,check] = dynare_solve('restricted_steadystate',... + ys(indv),... + options, exo_ss,indv); +end + - diff --git a/matlab/flip_plan.m b/matlab/flip_plan.m index a5a0952a9f..15fd3aa688 100644 --- a/matlab/flip_plan.m +++ b/matlab/flip_plan.m @@ -31,71 +31,71 @@ function plan = flip_plan(plan, exogenous, endogenous, expectation_type, date, v % % You should have received a copy of the GNU General Public License % along with Dynare. If not, see <http://www.gnu.org/licenses/>. - if ~ischar(expectation_type) || size(expectation_type,1) ~= 1 - error(['in flip_plan the fourth argument should be a string containing the simulation type (''perfect_foresight'' or ''surprise'')']); - end - exogenous = strtrim(exogenous); - ix = find(strcmp(exogenous, plan.endo_names)); - if isempty(ix) - error(['in flip_plan the second argument ' exogenous ' is not an endogenous variable']); - end; - endogenous = strtrim(endogenous); - iy = find(strcmp(endogenous, plan.exo_names)); - if isempty(iy) - error(['in flip_plan the third argument ' endogenous ' is not an exogenous variable']); - end; - sdate = length(date); - if sdate > 1 - if date(1) < plan.date(1) || date(end) > plan.date(end) - error(['in flip_plan the fifth argument (date=' date ') must lay inside the plan.date ' plan.date]); - end - else - if date < plan.date(1) || date > plan.date(end) - error(['in flip_plan the fifth argument (date=' date ') must lay iside the plan.date ' plan.date]); - end - end - if ~isempty(plan.shock_vars_) - common_var = find(iy == plan.shock_vars_); - if ~isempty(common_var) - common_date = intersect(date, plan.shock_date_{common_var}); - if ~isempty(common_date) - if common_date.length > 1 - the_dates = [cell2mat(strings(common_date(1))) ':' cell2mat(strings(common_date(end)))]; - else - the_dates = cell2mat(strings(common_date)); - end - error(['Impossible case: ' plan.exo_names{plan.shock_vars_(common_var)} ' is used both as a shock and as an endogenous variable to control the path of ' plan.endo_names{ix} ' at the dates ' the_dates]); - end - end - end - i_ix = find(ix == plan.constrained_vars_); - if isempty(i_ix) +if ~ischar(expectation_type) || size(expectation_type,1) ~= 1 + error(['in flip_plan the fourth argument should be a string containing the simulation type (''perfect_foresight'' or ''surprise'')']); +end +exogenous = strtrim(exogenous); +ix = find(strcmp(exogenous, plan.endo_names)); +if isempty(ix) + error(['in flip_plan the second argument ' exogenous ' is not an endogenous variable']); +end; +endogenous = strtrim(endogenous); +iy = find(strcmp(endogenous, plan.exo_names)); +if isempty(iy) + error(['in flip_plan the third argument ' endogenous ' is not an exogenous variable']); +end; +sdate = length(date); +if sdate > 1 + if date(1) < plan.date(1) || date(end) > plan.date(end) + error(['in flip_plan the fifth argument (date=' date ') must lay inside the plan.date ' plan.date]); + end +else + if date < plan.date(1) || date > plan.date(end) + error(['in flip_plan the fifth argument (date=' date ') must lay iside the plan.date ' plan.date]); + end +end +if ~isempty(plan.shock_vars_) + common_var = find(iy == plan.shock_vars_); + if ~isempty(common_var) + common_date = intersect(date, plan.shock_date_{common_var}); + if ~isempty(common_date) + if common_date.length > 1 + the_dates = [cell2mat(strings(common_date(1))) ':' cell2mat(strings(common_date(end)))]; + else + the_dates = cell2mat(strings(common_date)); + end + error(['Impossible case: ' plan.exo_names{plan.shock_vars_(common_var)} ' is used both as a shock and as an endogenous variable to control the path of ' plan.endo_names{ix} ' at the dates ' the_dates]); + end + end +end +i_ix = find(ix == plan.constrained_vars_); +if isempty(i_ix) if isempty(plan.constrained_vars_) - plan.constrained_vars_ = ix; - plan.options_cond_fcst_.controlled_varexo = iy; - if strcmp(expectation_type, 'perfect_foresight') - plan.constrained_perfect_foresight_ = 1; - else - plan.constrained_perfect_foresight_ = 0; - end + plan.constrained_vars_ = ix; + plan.options_cond_fcst_.controlled_varexo = iy; + if strcmp(expectation_type, 'perfect_foresight') + plan.constrained_perfect_foresight_ = 1; + else + plan.constrained_perfect_foresight_ = 0; + end else - plan.constrained_vars_ = [plan.constrained_vars_ ; ix]; - plan.options_cond_fcst_.controlled_varexo = [plan.options_cond_fcst_.controlled_varexo ; iy]; - if strcmp(expectation_type, 'perfect_foresight') - plan.constrained_perfect_foresight_ = [plan.constrained_perfect_foresight_ ; 1]; - else - plan.constrained_perfect_foresight_ = [plan.constrained_perfect_foresight_ ; 0]; - end + plan.constrained_vars_ = [plan.constrained_vars_ ; ix]; + plan.options_cond_fcst_.controlled_varexo = [plan.options_cond_fcst_.controlled_varexo ; iy]; + if strcmp(expectation_type, 'perfect_foresight') + plan.constrained_perfect_foresight_ = [plan.constrained_perfect_foresight_ ; 1]; + else + plan.constrained_perfect_foresight_ = [plan.constrained_perfect_foresight_ ; 0]; + end end plan.constrained_date_{length(plan.constrained_date_) + 1} = date; plan.constrained_str_date_{length(plan.constrained_str_date_) + 1} = strings(date); plan.constrained_int_date_{length(plan.constrained_int_date_) + 1} = date - plan.date(1) + 1; plan.constrained_paths_{length(plan.constrained_paths_) + 1} = value; - elseif plan.options_cond_fcst_.controlled_varexo(i_ix) == iy % same exogenous and endogenous hard tune - [plan.constrained_str_date_{i_ix}, i1, i2] = union(strings(date), plan.constrained_str_date_{i_ix}); - plan.constrained_date_{i_ix} = [date(i1) plan.constrained_date_{i_ix}(i2)]; - plan.constrained_int_date_{i_ix} = [date(i1) - plan.date(1) + 1; plan.constrained_int_date_{i_ix}(i2)]; - plan.constrained_paths_{i_ix} = [value(i1)'; plan.constrained_paths_{i_ix}(i2)]; - else +elseif plan.options_cond_fcst_.controlled_varexo(i_ix) == iy % same exogenous and endogenous hard tune +[plan.constrained_str_date_{i_ix}, i1, i2] = union(strings(date), plan.constrained_str_date_{i_ix}); +plan.constrained_date_{i_ix} = [date(i1) plan.constrained_date_{i_ix}(i2)]; +plan.constrained_int_date_{i_ix} = [date(i1) - plan.date(1) + 1; plan.constrained_int_date_{i_ix}(i2)]; +plan.constrained_paths_{i_ix} = [value(i1)'; plan.constrained_paths_{i_ix}(i2)]; +else error(['impossible case you have two conditional forecasts:\n - one involving ' plan.endo_names{plan.options_cond_fcst_.controlled_varexo(i_ix),:} ' as control and ' plan_exo_names{plan.constrained_vars_(ix_)} ' as constrined endogenous\n - the other involving ' plan.endo_names{plan.options_cond_fcst_.controlled_varexo(iy),:} ' as control and ' plan_exo_names{plan.constrained_vars_(ix)} ' as constrined endogenous\n']); - end +end diff --git a/matlab/gensylv_fp.m b/matlab/gensylv_fp.m index 2e5c167b5e..35ca3352ae 100644 --- a/matlab/gensylv_fp.m +++ b/matlab/gensylv_fp.m @@ -62,7 +62,7 @@ while it_fp < maxit_fp && evol > tol; Z_old = Z; Z = - (B * X * C + D); evol = max(sum(abs(Z - Z_old))); %norm_1 - %evol = max(sum(abs(Z - Z_old)')); %norm_inf + %evol = max(sum(abs(Z - Z_old)')); %norm_inf it_fp = it_fp + 1; end; %fprintf('sylvester it_fp=%d evol=%g | ',it_fp,evol); diff --git a/matlab/getH.m b/matlab/getH.m index 0db11d8e33..7a3b8d791e 100644 --- a/matlab/getH.m +++ b/matlab/getH.m @@ -96,7 +96,7 @@ if kronflag==-1, % perturbation end if nargout>5, H2 = hessian_sparse('thet2tau',[sqrt(diag(M_.Sigma_e(indexo,indexo))); M_.params(indx)], ... - options_.gstep,estim_params_,M_, oo_, indx,indexo,0,[],[],[],iv); + options_.gstep,estim_params_,M_, oo_, indx,indexo,0,[],[],[],iv); H2ss = zeros(m1,tot_param_nbr,tot_param_nbr); iax=find(triu(rand(tot_param_nbr,tot_param_nbr))); H2 = H2(:,iax); @@ -109,23 +109,23 @@ if kronflag==-1, % perturbation d2A(:,:) = H2(m1+1:m1+m1*m1,:); d2Om(:,:) = H2(m1+m1*m1+1:end,:); clear H2 -% tmp0=zeros(m1,m1); -% tmp0(iv,iv)=1; -% iax=find(tmp0); -% d2A=d2a(iax,:); -% iax=find(dyn_vech(tmp0)); -% d2Om=d2om(iax,:); + % tmp0=zeros(m1,m1); + % tmp0(iv,iv)=1; + % iax=find(tmp0); + % d2A=d2a(iax,:); + % iax=find(dyn_vech(tmp0)); + % d2Om=d2om(iax,:); end -% assignin('base','M_', M_); -% assignin('base','oo_', oo_); + % assignin('base','M_', M_); + % assignin('base','oo_', oo_); return end if kronflag==-2, if nargout>5, [residual, g1, g2 ] = feval([M_.fname,'_dynamic'],yy0, oo_.exo_steady_state', ... - M_.params, oo_.dr.ys, 1); + M_.params, oo_.dr.ys, 1); g22 = hessian_sparse('thet2tau',[M_.params(indx)],options_.gstep,estim_params_,M_, oo_, indx,[],-1); H2ss=full(g22(1:M_.endo_nbr,:)); H2ss = reshape(H2ss,[M_.endo_nbr param_nbr param_nbr]); @@ -145,7 +145,7 @@ if kronflag==-2, clear gx22; else [residual, g1 ] = feval([M_.fname,'_dynamic'],yy0, oo_.exo_steady_state', ... - M_.params, oo_.dr.ys, 1); + M_.params, oo_.dr.ys, 1); end gp = fjaco('thet2tau',[M_.params(indx)],estim_params_,M_, oo_, indx,[],-1); Hss=gp(1:M_.endo_nbr,:); @@ -153,134 +153,134 @@ if kronflag==-2, gp = reshape(gp,[size(g1) param_nbr]); else -% yy0=[]; -% for j=1:size(M_.lead_lag_incidence,1); -% yy0 = [ yy0; oo_.dr.ys(find(M_.lead_lag_incidence(j,:)))]; -% end -dyssdtheta=zeros(length(oo_.dr.ys),M_.param_nbr); -d2yssdtheta=zeros(length(oo_.dr.ys),M_.param_nbr,M_.param_nbr); -[residual, gg1] = feval([M_.fname,'_static'],oo_.dr.ys, oo_.exo_steady_state', M_.params); -df = feval([M_.fname,'_static_params_derivs'],oo_.dr.ys, repmat(oo_.exo_steady_state',[M_.maximum_exo_lag+M_.maximum_exo_lead+1]), ... - M_.params); -dyssdtheta = -gg1\df; -if nargout>5, - [residual, gg1, gg2] = feval([M_.fname,'_static'],oo_.dr.ys, oo_.exo_steady_state', M_.params); - [residual, g1, g2, g3] = feval([M_.fname,'_dynamic'],yy0, oo_.exo_steady_state', ... - M_.params, oo_.dr.ys, 1); - [nr, nc]=size(gg2); - - [df, gpx, d2f] = feval([M_.fname,'_static_params_derivs'],oo_.dr.ys, oo_.exo_steady_state', ... - M_.params);%, oo_.dr.ys, 1, dyssdtheta*0, d2yssdtheta); - d2f = get_all_resid_2nd_derivs(d2f,length(oo_.dr.ys),M_.param_nbr); - - if isempty(find(gg2)), - for j=1:M_.param_nbr, - d2yssdtheta(:,:,j) = -gg1\d2f(:,:,j); - end - else - gam = d2f*0; - for j=1:nr, - tmp1 = (squeeze(gpx(j,:,:))'*dyssdtheta); - gam(j,:,:)=transpose(reshape(gg2(j,:),[nr nr])*dyssdtheta)*dyssdtheta ... - + tmp1 + tmp1'; - end - for j=1:M_.param_nbr, - d2yssdtheta(:,:,j) = -gg1\(d2f(:,:,j)+gam(:,:,j)); -% d2yssdtheta(:,:,j) = -gg1\(d2f(:,:,j)+gam(:,:,j)+ squeeze(gpx(:,:,j))*dyssdtheta); + % yy0=[]; + % for j=1:size(M_.lead_lag_incidence,1); + % yy0 = [ yy0; oo_.dr.ys(find(M_.lead_lag_incidence(j,:)))]; + % end + dyssdtheta=zeros(length(oo_.dr.ys),M_.param_nbr); + d2yssdtheta=zeros(length(oo_.dr.ys),M_.param_nbr,M_.param_nbr); + [residual, gg1] = feval([M_.fname,'_static'],oo_.dr.ys, oo_.exo_steady_state', M_.params); + df = feval([M_.fname,'_static_params_derivs'],oo_.dr.ys, repmat(oo_.exo_steady_state',[M_.maximum_exo_lag+M_.maximum_exo_lead+1]), ... + M_.params); + dyssdtheta = -gg1\df; + if nargout>5, + [residual, gg1, gg2] = feval([M_.fname,'_static'],oo_.dr.ys, oo_.exo_steady_state', M_.params); + [residual, g1, g2, g3] = feval([M_.fname,'_dynamic'],yy0, oo_.exo_steady_state', ... + M_.params, oo_.dr.ys, 1); + [nr, nc]=size(gg2); + + [df, gpx, d2f] = feval([M_.fname,'_static_params_derivs'],oo_.dr.ys, oo_.exo_steady_state', ... + M_.params);%, oo_.dr.ys, 1, dyssdtheta*0, d2yssdtheta); + d2f = get_all_resid_2nd_derivs(d2f,length(oo_.dr.ys),M_.param_nbr); + + if isempty(find(gg2)), + for j=1:M_.param_nbr, + d2yssdtheta(:,:,j) = -gg1\d2f(:,:,j); + end + else + gam = d2f*0; + for j=1:nr, + tmp1 = (squeeze(gpx(j,:,:))'*dyssdtheta); + gam(j,:,:)=transpose(reshape(gg2(j,:),[nr nr])*dyssdtheta)*dyssdtheta ... + + tmp1 + tmp1'; + end + for j=1:M_.param_nbr, + d2yssdtheta(:,:,j) = -gg1\(d2f(:,:,j)+gam(:,:,j)); + % d2yssdtheta(:,:,j) = -gg1\(d2f(:,:,j)+gam(:,:,j)+ squeeze(gpx(:,:,j))*dyssdtheta); + end + clear tmp1 gpx gam, end - clear tmp1 gpx gam, end -end -if any(any(isnan(dyssdtheta))), - [U,T] = schur(gg1); - qz_criterium=options_.qz_criterium; - e1 = abs(ordeig(T)) < qz_criterium-1; - k = sum(e1); % Number non stationary variables. -% n = length(e1)-k; % Number of stationary variables. - [U,T] = ordschur(U,T,e1); - T = T(k+1:end,k+1:end); - dyssdtheta = -U(:,k+1:end)*(T\U(:,k+1:end)')*df; - if nargout>5, - for j=1:length(indx), - d2yssdtheta(:,:,j) = -U(:,k+1:end)*(T\U(:,k+1:end)')*d2f(:,:,j); + if any(any(isnan(dyssdtheta))), + [U,T] = schur(gg1); + qz_criterium=options_.qz_criterium; + e1 = abs(ordeig(T)) < qz_criterium-1; + k = sum(e1); % Number non stationary variables. + % n = length(e1)-k; % Number of stationary variables. + [U,T] = ordschur(U,T,e1); + T = T(k+1:end,k+1:end); + dyssdtheta = -U(:,k+1:end)*(T\U(:,k+1:end)')*df; + if nargout>5, + for j=1:length(indx), + d2yssdtheta(:,:,j) = -U(:,k+1:end)*(T\U(:,k+1:end)')*d2f(:,:,j); + end end end -end -if nargout>5, - [df, gp, d2f, gpp, hp] = feval([M_.fname,'_params_derivs'],yy0, oo_.exo_steady_state', ... - M_.params, oo_.dr.ys, 1, dyssdtheta, d2yssdtheta); - H2ss = d2yssdtheta(oo_.dr.order_var,indx,indx); -% nelem=size(g1,2); -% g22 = get_all_2nd_derivs(gpp,m,nelem,M_.param_nbr); -% g22 = g22(:,:,indx,indx); -else - [df, gp] = feval([M_.fname,'_params_derivs'],yy0, repmat(oo_.exo_steady_state',[M_.maximum_exo_lag+M_.maximum_exo_lead+1,1]), ... - M_.params, oo_.dr.ys, 1, dyssdtheta,d2yssdtheta); - [residual, g1, g2 ] = feval([M_.fname,'_dynamic'],yy0, repmat(oo_.exo_steady_state',[M_.maximum_exo_lag+M_.maximum_exo_lead+1,1]), ... - M_.params, oo_.dr.ys, 1); -end + if nargout>5, + [df, gp, d2f, gpp, hp] = feval([M_.fname,'_params_derivs'],yy0, oo_.exo_steady_state', ... + M_.params, oo_.dr.ys, 1, dyssdtheta, d2yssdtheta); + H2ss = d2yssdtheta(oo_.dr.order_var,indx,indx); + % nelem=size(g1,2); + % g22 = get_all_2nd_derivs(gpp,m,nelem,M_.param_nbr); + % g22 = g22(:,:,indx,indx); + else + [df, gp] = feval([M_.fname,'_params_derivs'],yy0, repmat(oo_.exo_steady_state',[M_.maximum_exo_lag+M_.maximum_exo_lead+1,1]), ... + M_.params, oo_.dr.ys, 1, dyssdtheta,d2yssdtheta); + [residual, g1, g2 ] = feval([M_.fname,'_dynamic'],yy0, repmat(oo_.exo_steady_state',[M_.maximum_exo_lag+M_.maximum_exo_lead+1,1]), ... + M_.params, oo_.dr.ys, 1); + end -[nr, nc]=size(g2); -nc = sqrt(nc); -Hss = dyssdtheta(oo_.dr.order_var,indx); -dyssdtheta = dyssdtheta(I,:); -ns = max(max(M_.lead_lag_incidence)); % retrieve the number of states excluding columns for shocks -gp2 = gp*0; -for j=1:nr, - [II JJ]=ind2sub([nc nc],find(g2(j,:))); - for i=1:nc, - is = find(II==i); - is = is(find(JJ(is)<=ns)); - if ~isempty(is), - g20=full(g2(j,find(g2(j,:)))); - gp2(j,i,:)=g20(is)*dyssdtheta(JJ(is),:); + [nr, nc]=size(g2); + nc = sqrt(nc); + Hss = dyssdtheta(oo_.dr.order_var,indx); + dyssdtheta = dyssdtheta(I,:); + ns = max(max(M_.lead_lag_incidence)); % retrieve the number of states excluding columns for shocks + gp2 = gp*0; + for j=1:nr, + [II JJ]=ind2sub([nc nc],find(g2(j,:))); + for i=1:nc, + is = find(II==i); + is = is(find(JJ(is)<=ns)); + if ~isempty(is), + g20=full(g2(j,find(g2(j,:)))); + gp2(j,i,:)=g20(is)*dyssdtheta(JJ(is),:); + end end end -end -gp = gp+gp2; -gp = gp(:,:,indx); + gp = gp+gp2; + gp = gp(:,:,indx); -if nargout>5, -% h22 = get_all_hess_derivs(hp,nr,nc,M_.param_nbr); - g22 = gpp; - gp22 = sparse(nr*nc,param_nbr*param_nbr); - tmp1 = reshape(g3,[nr*nc*nc nc]); - tmp2=sparse(size(tmp1,1),M_.param_nbr); -% tmp2=tmp1*[dyssdtheta; zeros(nc-ns,M_.param_nbr)]; - tmpa=[dyssdtheta; zeros(nc-ns,M_.param_nbr)]; - tmpa=sparse(tmpa); - for j=1:M_.param_nbr, - tmp2(:,j)=tmp1*tmpa(:,j); - end -% tmp2=sparse(tmp2); -% [i1 i2]=ind2sub([nc M_.param_nbr],[1:nc*M_.param_nbr]'); + if nargout>5, + % h22 = get_all_hess_derivs(hp,nr,nc,M_.param_nbr); + g22 = gpp; + gp22 = sparse(nr*nc,param_nbr*param_nbr); + tmp1 = reshape(g3,[nr*nc*nc nc]); + tmp2=sparse(size(tmp1,1),M_.param_nbr); + % tmp2=tmp1*[dyssdtheta; zeros(nc-ns,M_.param_nbr)]; + tmpa=[dyssdtheta; zeros(nc-ns,M_.param_nbr)]; + tmpa=sparse(tmpa); + for j=1:M_.param_nbr, + tmp2(:,j)=tmp1*tmpa(:,j); + end + % tmp2=sparse(tmp2); + % [i1 i2]=ind2sub([nc M_.param_nbr],[1:nc*M_.param_nbr]'); - for j=1:nr, - tmp0=reshape(g2(j,:),[nc nc]); - tmp0 = tmp0(:,1:ns)*reshape(d2yssdtheta(I,:,:),[ns,M_.param_nbr*M_.param_nbr]); - for i=1:nc, - indo = sub2ind([nr nc nc], ones(nc,1)*j ,ones(nc,1)*i, (1:nc)'); - tmpx = (tmp2(indo,:))'*[dyssdtheta; zeros(nc-ns,M_.param_nbr)]; -% gp22(j,i,:,:)=squeeze(tmp1(j,i,:,:))'*[dyssdtheta; zeros(nc-ns,M_.param_nbr)]; - tmpu = (get_hess_deriv(hp,j,i,nc,M_.param_nbr))'*[dyssdtheta; zeros(nc-ns,M_.param_nbr)]; - tmpy = tmpx+tmpu+tmpu'+reshape(tmp0(i,:,:),[M_.param_nbr M_.param_nbr]); - tmpy = tmpy + get_2nd_deriv_mat(gpp,j,i,M_.param_nbr); - tmpy = tmpy(indx,indx); - if any(any(tmpy)), - ina = find(triu(tmpy)); - gp22(sub2ind([nr nc],j,i),ina)=transpose(tmpy(ina)); -% gp22(j,i,:,:)= reshape(tmpy,[1 1 M_.param_nbr M_.param_nbr]); + for j=1:nr, + tmp0=reshape(g2(j,:),[nc nc]); + tmp0 = tmp0(:,1:ns)*reshape(d2yssdtheta(I,:,:),[ns,M_.param_nbr*M_.param_nbr]); + for i=1:nc, + indo = sub2ind([nr nc nc], ones(nc,1)*j ,ones(nc,1)*i, (1:nc)'); + tmpx = (tmp2(indo,:))'*[dyssdtheta; zeros(nc-ns,M_.param_nbr)]; + % gp22(j,i,:,:)=squeeze(tmp1(j,i,:,:))'*[dyssdtheta; zeros(nc-ns,M_.param_nbr)]; + tmpu = (get_hess_deriv(hp,j,i,nc,M_.param_nbr))'*[dyssdtheta; zeros(nc-ns,M_.param_nbr)]; + tmpy = tmpx+tmpu+tmpu'+reshape(tmp0(i,:,:),[M_.param_nbr M_.param_nbr]); + tmpy = tmpy + get_2nd_deriv_mat(gpp,j,i,M_.param_nbr); + tmpy = tmpy(indx,indx); + if any(any(tmpy)), + ina = find(triu(tmpy)); + gp22(sub2ind([nr nc],j,i),ina)=transpose(tmpy(ina)); + % gp22(j,i,:,:)= reshape(tmpy,[1 1 M_.param_nbr M_.param_nbr]); + end end + % gp22(j,:,:,:)=gp22(j,:,:,:)+reshape(tmp0(:,1:ns)*d2yssdtheta(I,:,:),[1 nc M_.param_nbr M_.param_nbr]); end -% gp22(j,:,:,:)=gp22(j,:,:,:)+reshape(tmp0(:,1:ns)*d2yssdtheta(I,:,:),[1 nc M_.param_nbr M_.param_nbr]); - end -% g22 = g22+gp22; -% g22 = g22(:,:,indx,indx); - clear tmp0 tmp1 tmp2 tmpu tmpx tmpy, + % g22 = g22+gp22; + % g22 = g22(:,:,indx,indx); + clear tmp0 tmp1 tmp2 tmpu tmpx tmpy, inx=find(gp22); gx22=zeros(length(inx),5); for j=1:length(inx), @@ -292,7 +292,7 @@ if nargout>5, g22 = gx22; clear gx22 gp22; -end + end end @@ -309,7 +309,7 @@ if nargout > 5, inxinx = find(nonzeros(k11')==tmp(j,2)); d2a(j,2) = inxinx; end -% d2a = g22(:,nonzeros(k11'),:,:); + % d2a = g22(:,nonzeros(k11'),:,:); end kstate = oo_.dr.kstate; @@ -474,13 +474,13 @@ else % generalized sylvester equation for j=1:length(indexo) dSig(indexo(j),indexo(j),j) = 2*sqrt(M_.Sigma_e(indexo(j),indexo(j))); y = B*dSig(:,:,j)*B'; -% y = y(nauxe+1:end,nauxe+1:end); -% H(:,j) = [zeros((m-nauxe)^2,1); dyn_vech(y)]; + % y = y(nauxe+1:end,nauxe+1:end); + % H(:,j) = [zeros((m-nauxe)^2,1); dyn_vech(y)]; H(:,j) = [zeros(m1^2,1); dyn_vech(y(iv,iv))]; if nargout>1, dOm(:,:,j) = y(iv,iv); end -% dSig(indexo(j),indexo(j)) = 0; + % dSig(indexo(j),indexo(j)) = 0; end end for j=1:param_nbr, @@ -490,8 +490,8 @@ else % generalized sylvester equation dB(:,:,j) = y; end y = y*M_.Sigma_e*B'+B*M_.Sigma_e*y'; -% x = x(nauxe+1:end,nauxe+1:end); -% y = y(nauxe+1:end,nauxe+1:end); + % x = x(nauxe+1:end,nauxe+1:end); + % y = y(nauxe+1:end,nauxe+1:end); if nargout>1, dA(:,:,j+length(indexo)) = x(iv,iv); dOm(:,:,j+length(indexo)) = y(iv,iv); @@ -532,7 +532,7 @@ if nargout > 5, cumjcount=0; jinx = []; x2x=sparse(m*m,param_nbr_2); -% x2x=[]; + % x2x=[]; for i=1:param_nbr, for j=1:i, elem1 = (get_2nd_deriv(D2g0,m,m,j,i)-get_2nd_deriv(D2g1,m,m,j,i)*A); @@ -549,7 +549,7 @@ if nargout > 5, if (j*i)==param_nbr^2, d = d(:,:,1:jcount); end -% d(find(abs(d)<1.e-12))=0; + % d(find(abs(d)<1.e-12))=0; xx2=sylvester3(a,b,c,d); flag=1; icount=0; @@ -557,12 +557,12 @@ if nargout > 5, [xx2, flag]=sylvester3a(xx2,a,b,c,d); icount = icount + 1; end -% inx = find(abs(xx2)>1.e-12); -% xx2(find(abs(xx2)<1.e-12))=0; + % inx = find(abs(xx2)>1.e-12); + % xx2(find(abs(xx2)<1.e-12))=0; x2x(:,cumjcount+1:cumjcount+jcount)=reshape(xx2,[m*m jcount]); cumjcount=cumjcount+jcount; -% [i1 i2 i3]=ind2sub(size(xx2),inx); -% x2x = [x2x; [i1 i2 jinx(i3,:) xx2(inx)]]; + % [i1 i2 i3]=ind2sub(size(xx2),inx); + % x2x = [x2x; [i1 i2 jinx(i3,:) xx2(inx)]]; jcount = 0; jinx = []; end @@ -590,7 +590,7 @@ if nargout > 5, if i==j, d2Sig(indexo(j),indexo(j),j) = 2; y = B*d2Sig(:,:,j)*B'; -% y(abs(y)<1.e-8)=0; + % y(abs(y)<1.e-8)=0; d2Om_tmp(:,jcount) = dyn_vech(y(iv,iv)); end else @@ -598,12 +598,12 @@ if nargout > 5, iind = i-offset; if i<=offset, y = dB(:,:,jind)*dSig(:,:,i)*B'+B*dSig(:,:,i)*dB(:,:,jind)'; -% y(abs(y)<1.e-8)=0; + % y(abs(y)<1.e-8)=0; d2Om_tmp(:,jcount) = dyn_vech(y(iv,iv)); else icount=icount+1; x = reshape(x2x(:,icount),[m m]); -% x = get_2nd_deriv(x2x,m,m,iind,jind);%xx2(:,:,jcount); + % x = get_2nd_deriv(x2x,m,m,iind,jind);%xx2(:,:,jcount); elem1 = (get_2nd_deriv(D2g0,m,m,iind,jind)-get_2nd_deriv(D2g1,m,m,iind,jind)*A); elem1 = elem1 -( Dg1(:,:,jind)*xx(:,:,iind) + Dg1(:,:,iind)*xx(:,:,jind) ); elemj0 = Dg0(:,:,jind)-Dg1(:,:,jind)*A-GAM1*xx(:,:,jind); @@ -614,9 +614,9 @@ if nargout > 5, % d2B(:,:,i+length(indexo),j+length(indexo)) = y; y = y*M_.Sigma_e*B'+B*M_.Sigma_e*y'+ ... dB(:,:,jind)*M_.Sigma_e*dB(:,:,iind)'+dB(:,:,iind)*M_.Sigma_e*dB(:,:,jind)'; -% x(abs(x)<1.e-8)=0; + % x(abs(x)<1.e-8)=0; d2A_tmp(:,jcount) = vec(x(iv,iv)); -% y(abs(y)<1.e-8)=0; + % y(abs(y)<1.e-8)=0; d2Om_tmp(:,jcount) = dyn_vech(y(iv,iv)); end end @@ -674,23 +674,23 @@ end if fsparse, g22=sparse(m*n,npar*npar); else -g22=zeros(m,n,npar,npar); + g22=zeros(m,n,npar,npar); end % c=ones(npar,npar); % c=triu(c); % ic=find(c); for is=1:length(gpp), -% d=zeros(npar,npar); -% d(gpp(is,3),gpp(is,4))=1; -% indx = find(ic==find(d)); + % d=zeros(npar,npar); + % d(gpp(is,3),gpp(is,4))=1; + % indx = find(ic==find(d)); if fsparse, g22(sub2ind([m,n],gpp(is,1),gpp(is,2)),sub2ind([npar,npar],gpp(is,3),gpp(is,4)))=gpp(is,5); g22(sub2ind([m,n],gpp(is,1),gpp(is,2)),sub2ind([npar,npar],gpp(is,4),gpp(is,3)))=gpp(is,5); else - g22(gpp(is,1),gpp(is,2),gpp(is,3),gpp(is,4))=gpp(is,5); - g22(gpp(is,1),gpp(is,2),gpp(is,4),gpp(is,3))=gpp(is,5); -end + g22(gpp(is,1),gpp(is,2),gpp(is,3),gpp(is,4))=gpp(is,5); + g22(gpp(is,1),gpp(is,2),gpp(is,4),gpp(is,3))=gpp(is,5); + end end return @@ -703,9 +703,9 @@ r22=zeros(m,npar,npar); % ic=find(c); for is=1:length(rpp), -% d=zeros(npar,npar); -% d(rpp(is,2),rpp(is,3))=1; -% indx = find(ic==find(d)); + % d=zeros(npar,npar); + % d(rpp(is,2),rpp(is,3))=1; + % indx = find(ic==find(d)); r22(rpp(is,1),rpp(is,2),rpp(is,3))=rpp(is,4); r22(rpp(is,1),rpp(is,3),rpp(is,2))=rpp(is,4); end diff --git a/matlab/getJJ.m b/matlab/getJJ.m index b7686a0359..c3b1f1c1e8 100644 --- a/matlab/getJJ.m +++ b/matlab/getJJ.m @@ -55,7 +55,7 @@ function [JJ, H, gam, gp, dA, dOm, dYss] = getJJ(A, B, estim_params_, M_,oo_,opt % along with Dynare. If not, see <http://www.gnu.org/licenses/>. if nargin<8 || isempty(indx) -% indx = [1:M_.param_nbr]; + % indx = [1:M_.param_nbr]; end, if nargin<9 || isempty(indexo) indexo = []; diff --git a/matlab/get_Hessian.m b/matlab/get_Hessian.m index a42b3c8125..bf423e07c6 100644 --- a/matlab/get_Hessian.m +++ b/matlab/get_Hessian.m @@ -28,142 +28,142 @@ function [Hess] = get_Hessian(T,R,Q,H,P,Y,DT,DYss,DOm,DH,DP,D2T,D2Yss,D2Om,D2H,D % along with Dynare. If not, see <http://www.gnu.org/licenses/>. - k = size(DT,3); % number of structural parameters - smpl = size(Y,2); % Sample size. - pp = size(Y,1); % Maximum number of observed variables. - mm = size(T,2); % Number of state variables. - a = zeros(mm,1); % State vector. - Om = R*Q*transpose(R); % Variance of R times the vector of structural innovations. - t = 0; % Initialization of the time index. - oldK = 0; - notsteady = 1; % Steady state flag. - F_singular = 1; - - Hess = zeros(k,k); % Initialization of the Hessian - Da = zeros(mm,k); % State vector. - Dv = zeros(length(mf),k); - D2a = zeros(mm,k,k); % State vector. - D2v = zeros(length(mf),k,k); - - C = zeros(length(mf),mm); - for ii=1:length(mf); C(ii,mf(ii))=1;end % SELECTION MATRIX IN MEASUREMENT EQ. (FOR WHEN IT IS NOT CONSTANT) - dC = zeros(length(mf),mm,k); - d2C = zeros(length(mf),mm,k,k); - - s = zeros(pp,1); % CONSTANT TERM IN MEASUREMENT EQ. (FOR WHEN IT IS NOT CONSTANT) - ds = zeros(pp,1,k); - d2s = zeros(pp,1,k,k); - +k = size(DT,3); % number of structural parameters +smpl = size(Y,2); % Sample size. +pp = size(Y,1); % Maximum number of observed variables. +mm = size(T,2); % Number of state variables. +a = zeros(mm,1); % State vector. +Om = R*Q*transpose(R); % Variance of R times the vector of structural innovations. +t = 0; % Initialization of the time index. +oldK = 0; +notsteady = 1; % Steady state flag. +F_singular = 1; + +Hess = zeros(k,k); % Initialization of the Hessian +Da = zeros(mm,k); % State vector. +Dv = zeros(length(mf),k); +D2a = zeros(mm,k,k); % State vector. +D2v = zeros(length(mf),k,k); + +C = zeros(length(mf),mm); +for ii=1:length(mf); C(ii,mf(ii))=1;end % SELECTION MATRIX IN MEASUREMENT EQ. (FOR WHEN IT IS NOT CONSTANT) +dC = zeros(length(mf),mm,k); +d2C = zeros(length(mf),mm,k,k); + +s = zeros(pp,1); % CONSTANT TERM IN MEASUREMENT EQ. (FOR WHEN IT IS NOT CONSTANT) +ds = zeros(pp,1,k); +d2s = zeros(pp,1,k,k); + % for ii = 1:k % DOm = DR(:,:,ii)*Q*transpose(R) + R*DQ(:,:,ii)*transpose(R) + R*Q*transpose(DR(:,:,ii)); % end - - while notsteady & t<smpl - t = t+1; - v = Y(:,t)-a(mf); - F = P(mf,mf) + H; - if rcond(F) < kalman_tol - if ~all(abs(F(:))<kalman_tol) - return - else - a = T*a; - P = T*P*transpose(T)+Om; - end + +while notsteady & t<smpl + t = t+1; + v = Y(:,t)-a(mf); + F = P(mf,mf) + H; + if rcond(F) < kalman_tol + if ~all(abs(F(:))<kalman_tol) + return else - F_singular = 0; - iF = inv(F); - K = P(:,mf)*iF; - - [DK,DF,DP1] = computeDKalman(T,DT,DOm,P,DP,DH,mf,iF,K); - [D2K,D2F,D2P1] = computeD2Kalman(T,DT,D2T,D2Om,P,DP,D2P,DH,mf,iF,K,DK); - tmp = (a+K*v); - - for ii = 1:k - Dv(:,ii) = -Da(mf,ii) - DYss(mf,ii); - % dai = da(:,:,ii); - dKi = DK(:,:,ii); - diFi = -iF*DF(:,:,ii)*iF; - dtmpi = Da(:,ii)+dKi*v+K*Dv(:,ii); + a = T*a; + P = T*P*transpose(T)+Om; + end + else + F_singular = 0; + iF = inv(F); + K = P(:,mf)*iF; + + [DK,DF,DP1] = computeDKalman(T,DT,DOm,P,DP,DH,mf,iF,K); + [D2K,D2F,D2P1] = computeD2Kalman(T,DT,D2T,D2Om,P,DP,D2P,DH,mf,iF,K,DK); + tmp = (a+K*v); + + for ii = 1:k + Dv(:,ii) = -Da(mf,ii) - DYss(mf,ii); + % dai = da(:,:,ii); + dKi = DK(:,:,ii); + diFi = -iF*DF(:,:,ii)*iF; + dtmpi = Da(:,ii)+dKi*v+K*Dv(:,ii); - - for jj = 1:ii - dFj = DF(:,:,jj); - diFj = -iF*DF(:,:,jj)*iF; - dKj = DK(:,:,jj); - d2Kij = D2K(:,:,jj,ii); - d2Fij = D2F(:,:,jj,ii); - d2iFij = -diFi*dFj*iF -iF*d2Fij*iF -iF*dFj*diFi; - dtmpj = Da(:,jj)+dKj*v+K*Dv(:,jj); - - d2vij = -D2Yss(mf,jj,ii) - D2a(mf,jj,ii); - d2tmpij = D2a(:,jj,ii) + d2Kij*v + dKj*Dv(:,ii) + dKi*Dv(:,jj) + K*d2vij; - D2a(:,jj,ii) = D2T(:,:,jj,ii)*tmp + DT(:,:,jj)*dtmpi + DT(:,:,ii)*dtmpj + T*d2tmpij; - - Hesst(ii,jj) = getHesst_ij(v,Dv(:,ii),Dv(:,jj),d2vij,iF,diFi,diFj,d2iFij,dFj,d2Fij); + + for jj = 1:ii + dFj = DF(:,:,jj); + diFj = -iF*DF(:,:,jj)*iF; + dKj = DK(:,:,jj); + d2Kij = D2K(:,:,jj,ii); + d2Fij = D2F(:,:,jj,ii); + d2iFij = -diFi*dFj*iF -iF*d2Fij*iF -iF*dFj*diFi; + dtmpj = Da(:,jj)+dKj*v+K*Dv(:,jj); + + d2vij = -D2Yss(mf,jj,ii) - D2a(mf,jj,ii); + d2tmpij = D2a(:,jj,ii) + d2Kij*v + dKj*Dv(:,ii) + dKi*Dv(:,jj) + K*d2vij; + D2a(:,jj,ii) = D2T(:,:,jj,ii)*tmp + DT(:,:,jj)*dtmpi + DT(:,:,ii)*dtmpj + T*d2tmpij; + + Hesst(ii,jj) = getHesst_ij(v,Dv(:,ii),Dv(:,jj),d2vij,iF,diFi,diFj,d2iFij,dFj,d2Fij); + end + Da(:,ii) = DT(:,:,ii)*tmp + T*dtmpi; end - Da(:,ii) = DT(:,:,ii)*tmp + T*dtmpi; - end -% vecDPmf = reshape(DP(mf,mf,:),[],k); -% iPmf = inv(P(mf,mf)); - if t>=start - Hess = Hess + Hesst; - end - a = T*(a+K*v); - P = T*(P-K*P(mf,:))*transpose(T)+Om; - DP = DP1; - D2P = D2P1; + % vecDPmf = reshape(DP(mf,mf,:),[],k); + % iPmf = inv(P(mf,mf)); + if t>=start + Hess = Hess + Hesst; end - notsteady = max(max(abs(K-oldK))) > riccati_tol; - oldK = K; + a = T*(a+K*v); + P = T*(P-K*P(mf,:))*transpose(T)+Om; + DP = DP1; + D2P = D2P1; end + notsteady = max(max(abs(K-oldK))) > riccati_tol; + oldK = K; +end - if F_singular - error('The variance of the forecast error remains singular until the end of the sample') - end +if F_singular + error('The variance of the forecast error remains singular until the end of the sample') +end - - if t < smpl - t0 = t+1; - while t < smpl - t = t+1; - v = Y(:,t)-a(mf); - tmp = (a+K*v); - for ii = 1:k, - Dv(:,ii) = -Da(mf,ii)-DYss(mf,ii); - dKi = DK(:,:,ii); - diFi = -iF*DF(:,:,ii)*iF; - dtmpi = Da(:,ii)+dKi*v+K*Dv(:,ii); + +if t < smpl + t0 = t+1; + while t < smpl + t = t+1; + v = Y(:,t)-a(mf); + tmp = (a+K*v); + for ii = 1:k, + Dv(:,ii) = -Da(mf,ii)-DYss(mf,ii); + dKi = DK(:,:,ii); + diFi = -iF*DF(:,:,ii)*iF; + dtmpi = Da(:,ii)+dKi*v+K*Dv(:,ii); + + for jj = 1:ii, + dFj = DF(:,:,jj); + diFj = -iF*DF(:,:,jj)*iF; + dKj = DK(:,:,jj); + d2Kij = D2K(:,:,jj,ii); + d2Fij = D2F(:,:,jj,ii); + d2iFij = -diFi*dFj*iF -iF*d2Fij*iF -iF*dFj*diFi; + dtmpj = Da(:,jj)+dKj*v+K*Dv(:,jj); - for jj = 1:ii, - dFj = DF(:,:,jj); - diFj = -iF*DF(:,:,jj)*iF; - dKj = DK(:,:,jj); - d2Kij = D2K(:,:,jj,ii); - d2Fij = D2F(:,:,jj,ii); - d2iFij = -diFi*dFj*iF -iF*d2Fij*iF -iF*dFj*diFi; - dtmpj = Da(:,jj)+dKj*v+K*Dv(:,jj); - - d2vij = -D2Yss(mf,jj,ii) - D2a(mf,jj,ii); - d2tmpij = D2a(:,jj,ii) + d2Kij*v + dKj*Dv(:,ii) + dKi*Dv(:,jj) + K*d2vij; - D2a(:,jj,ii) = D2T(:,:,jj,ii)*tmp + DT(:,:,jj)*dtmpi + DT(:,:,ii)*dtmpj + T*d2tmpij; - - Hesst(ii,jj) = getHesst_ij(v,Dv(:,ii),Dv(:,jj),d2vij,iF,diFi,diFj,d2iFij,dFj,d2Fij); - end - Da(:,ii) = DT(:,:,ii)*tmp + T*dtmpi; - end - if t>=start - Hess = Hess + Hesst; + d2vij = -D2Yss(mf,jj,ii) - D2a(mf,jj,ii); + d2tmpij = D2a(:,jj,ii) + d2Kij*v + dKj*Dv(:,ii) + dKi*Dv(:,jj) + K*d2vij; + D2a(:,jj,ii) = D2T(:,:,jj,ii)*tmp + DT(:,:,jj)*dtmpi + DT(:,:,ii)*dtmpj + T*d2tmpij; + + Hesst(ii,jj) = getHesst_ij(v,Dv(:,ii),Dv(:,jj),d2vij,iF,diFi,diFj,d2iFij,dFj,d2Fij); end - a = T*(a+K*v); + Da(:,ii) = DT(:,:,ii)*tmp + T*dtmpi; + end + if t>=start + Hess = Hess + Hesst; end -% Hess = Hess + .5*(smpl+t0-1)*(vecDPmf' * kron(iPmf,iPmf) * vecDPmf); - % for ii = 1:k; - % for jj = 1:ii - % H(ii,jj) = trace(iPmf*(.5*DP(mf,mf,ii)*iPmf*DP(mf,mf,jj) + Dv(:,ii)*Dv(:,jj)')); - % end - % end + a = T*(a+K*v); end - + % Hess = Hess + .5*(smpl+t0-1)*(vecDPmf' * kron(iPmf,iPmf) * vecDPmf); + % for ii = 1:k; + % for jj = 1:ii + % H(ii,jj) = trace(iPmf*(.5*DP(mf,mf,ii)*iPmf*DP(mf,mf,jj) + Dv(:,ii)*Dv(:,jj)')); + % end + % end +end + Hess = Hess + tril(Hess,-1)'; Hess = -Hess/2; @@ -178,8 +178,8 @@ Hesst_ij = trace(diSi*dSj + iS*d2Sij) + e'*d2iSij*e + 2*(dei'*diSj*e + dei'*iS*d function [DK,DF,DP1] = computeDKalman(T,DT,DOm,P,DP,DH,mf,iF,K) - k = size(DT,3); - tmp = P-K*P(mf,:); +k = size(DT,3); +tmp = P-K*P(mf,:); for ii = 1:k DF(:,:,ii) = DP(mf,mf,ii) + DH(:,:,ii); @@ -194,9 +194,9 @@ end function [d2K,d2S,d2P1] = computeD2Kalman(A,dA,d2A,d2Om,P0,dP0,d2P0,DH,mf,iF,K0,dK0); % computes the second derivatives of the Kalman matrices % note: A=T in main func. - - k = size(dA,3); - tmp = P0-K0*P0(mf,:); + +k = size(dA,3); +tmp = P0-K0*P0(mf,:); [ns,no] = size(K0); % CPC = C*P0*C'; CPC = .5*(CPC+CPC');iF = inv(CPC); @@ -225,34 +225,33 @@ for ii = 1:k d2Aij = d2A(:,:,jj,ii); d2Pij = d2P0(:,:,jj,ii); d2Omij = d2Om(:,:,jj,ii); - - % second order - - d2Fij = d2Pij(mf,mf) ; - -% d2APC = d2Aij*P0*C' + A*d2Pij*C' + A*P0*d2Cij' + dAi*dPj*C' + dAj*dPi*C' + A*dPj*dCi' + A*dPi*dCj' + dAi*P0*dCj' + dAj*P0*dCi'; - d2APC = d2Pij(:,mf); - - d2iF = -diFi*dFj*iF -iF*d2Fij*iF -iF*dFj*diFi; - - d2Kij= d2Pij(:,mf)*iF + P0(:,mf)*d2iF + dP0(:,mf,jj)*diFi + dP0(:,mf,ii)*diFj; - d2KCP = d2Kij*P0(mf,:) + K0*d2Pij(mf,:) + dKi*dP0(mf,:,jj) + dKj*dP0(mf,:,ii) ; - - dtmpi = dP0(:,:,ii) - dK0(:,:,ii)*P0(mf,:) - K0*dP0(mf,:,ii); - dtmpj = dP0(:,:,jj) - dK0(:,:,jj)*P0(mf,:) - K0*dP0(mf,:,jj); - d2tmp = d2Pij - d2KCP; - - d2AtmpA = d2Aij*tmp*A' + A*d2tmp*A' + A*tmp*d2Aij' + dAi*dtmpj*A' + dAj*dtmpi*A' + A*dtmpj*dAi' + A*dtmpi*dAj' + dAi*tmp*dAj' + dAj*tmp*dAi'; - - d2K(:,:,ii,jj) = d2Kij; %#ok<NASGU> - d2P1(:,:,ii,jj) = d2AtmpA + d2Omij; %#ok<*NASGU> - d2S(:,:,ii,jj) = d2Fij; -% d2iS(:,:,ii,jj) = d2iF; + % second order + + d2Fij = d2Pij(mf,mf) ; + + % d2APC = d2Aij*P0*C' + A*d2Pij*C' + A*P0*d2Cij' + dAi*dPj*C' + dAj*dPi*C' + A*dPj*dCi' + A*dPi*dCj' + dAi*P0*dCj' + dAj*P0*dCi'; + d2APC = d2Pij(:,mf); + + d2iF = -diFi*dFj*iF -iF*d2Fij*iF -iF*dFj*diFi; + + d2Kij= d2Pij(:,mf)*iF + P0(:,mf)*d2iF + dP0(:,mf,jj)*diFi + dP0(:,mf,ii)*diFj; + + d2KCP = d2Kij*P0(mf,:) + K0*d2Pij(mf,:) + dKi*dP0(mf,:,jj) + dKj*dP0(mf,:,ii) ; + + dtmpi = dP0(:,:,ii) - dK0(:,:,ii)*P0(mf,:) - K0*dP0(mf,:,ii); + dtmpj = dP0(:,:,jj) - dK0(:,:,jj)*P0(mf,:) - K0*dP0(mf,:,jj); + d2tmp = d2Pij - d2KCP; + + d2AtmpA = d2Aij*tmp*A' + A*d2tmp*A' + A*tmp*d2Aij' + dAi*dtmpj*A' + dAj*dtmpi*A' + A*dtmpj*dAi' + A*dtmpi*dAj' + dAi*tmp*dAj' + dAj*tmp*dAi'; + + d2K(:,:,ii,jj) = d2Kij; %#ok<NASGU> + d2P1(:,:,ii,jj) = d2AtmpA + d2Omij; %#ok<*NASGU> + d2S(:,:,ii,jj) = d2Fij; + % d2iS(:,:,ii,jj) = d2iF; end end % end of computeD2Kalman - \ No newline at end of file diff --git a/matlab/get_all_parameters.m b/matlab/get_all_parameters.m index f924157705..30d325f68b 100644 --- a/matlab/get_all_parameters.m +++ b/matlab/get_all_parameters.m @@ -6,7 +6,7 @@ function xparam1=get_all_parameters(estim_params_,M_) % parameter values % % INPUTS -% estim_params_: Dynare structure describing the estimated parameters. +% estim_params_: Dynare structure describing the estimated parameters. % M_: Dynare structure describing the model. % % OUTPUTS @@ -100,5 +100,5 @@ offset = nvx+ncx+nvn+ncn; % structural parameters if np - xparam1(offset+1:end)=M_.params(estim_params_.param_vals(:,1)); + xparam1(offset+1:end)=M_.params(estim_params_.param_vals(:,1)); end \ No newline at end of file diff --git a/matlab/get_dynare_random_generator_state.m b/matlab/get_dynare_random_generator_state.m index 513919c220..4525bc20d9 100644 --- a/matlab/get_dynare_random_generator_state.m +++ b/matlab/get_dynare_random_generator_state.m @@ -23,22 +23,22 @@ function [state_u,state_n] = get_dynare_random_generator_state() % You should have received a copy of the GNU General Public License % along with Dynare. If not, see <http://www.gnu.org/licenses/>. - matlab_random_streams = ~(isoctave || matlab_ver_less_than('7.7')); +matlab_random_streams = ~(isoctave || matlab_ver_less_than('7.7')); - if matlab_random_streams% Use new matlab interface. - if matlab_ver_less_than('7.12') - s = RandStream.getDefaultStream(); - else - s = RandStream.getGlobalStream(); - end - if isequal(s.Type,'legacy') - state_u = rand('state'); - state_n = randn('state'); - else - state_u = s.State; - state_n = state_u; - end - else% Use old matlab interface. +if matlab_random_streams% Use new matlab interface. + if matlab_ver_less_than('7.12') + s = RandStream.getDefaultStream(); + else + s = RandStream.getGlobalStream(); + end + if isequal(s.Type,'legacy') state_u = rand('state'); state_n = randn('state'); - end \ No newline at end of file + else + state_u = s.State; + state_n = state_u; + end +else% Use old matlab interface. + state_u = rand('state'); + state_n = randn('state'); +end \ No newline at end of file diff --git a/matlab/get_file_extension.m b/matlab/get_file_extension.m index d922b36ac5..3951e8c3cb 100644 --- a/matlab/get_file_extension.m +++ b/matlab/get_file_extension.m @@ -10,7 +10,7 @@ function ext = get_file_extension(file) % % REMARKS % If the provided file name has no extension, the routine will return an empty array. - + % Copyright (C) 2013-2015 Dynare Team % % This file is part of Dynare. diff --git a/matlab/get_optimal_policy_discount_factor.m b/matlab/get_optimal_policy_discount_factor.m index 67931b8ab1..fd471a01bb 100644 --- a/matlab/get_optimal_policy_discount_factor.m +++ b/matlab/get_optimal_policy_discount_factor.m @@ -30,4 +30,4 @@ function discount_factor=get_optimal_policy_discount_factor(params,param_names) % You should have received a copy of the GNU General Public License % along with Dynare. If not, see <http://www.gnu.org/licenses/>. - discount_factor = params(find(strcmp('optimal_policy_discount_factor',cellstr(param_names)))); +discount_factor = params(find(strcmp('optimal_policy_discount_factor',cellstr(param_names)))); diff --git a/matlab/get_subsamples_range_indx.m b/matlab/get_subsamples_range_indx.m index 1d114c6869..cb9b971f5d 100644 --- a/matlab/get_subsamples_range_indx.m +++ b/matlab/get_subsamples_range_indx.m @@ -39,5 +39,5 @@ range_indx = find(strcmp(range_label, estimation_info.subsamples(subsamples_indx if size(range_indx,2) ~= 1 error(['Error: Index not found in estimation_info.subsamples(' ... - num2str(subsamples_indx) ').range_index for label ' range_label]); + num2str(subsamples_indx) ').range_index for label ' range_label]); end diff --git a/matlab/global_initialization.m b/matlab/global_initialization.m index cbeff6085e..168fe8d5d9 100644 --- a/matlab/global_initialization.m +++ b/matlab/global_initialization.m @@ -471,7 +471,7 @@ options_.sub_draws = []; options_.gradient_method = 2; %used by csminwel and newrat options_.gradient_epsilon = 1e-6; %used by csminwel and newrat options_.posterior_sampler_options.sampling_opt = []; %extended set of options for individual posterior samplers -% Random Walk Metropolis-Hastings + % Random Walk Metropolis-Hastings options_.posterior_sampler_options.posterior_sampling_method = 'random_walk_metropolis_hastings'; options_.posterior_sampler_options.rwmh.proposal_distribution = 'rand_multivariate_normal'; options_.posterior_sampler_options.rwmh.student_degrees_of_freedom = 3; @@ -525,8 +525,8 @@ options_.estimation.moments_posterior_density.indicator = 1; options_.estimation.moments_posterior_density.gridpoints = 2^9; options_.estimation.moments_posterior_density.bandwidth = 0; % Rule of thumb optimal bandwidth parameter. options_.estimation.moments_posterior_density.kernel_function = 'gaussian'; % Gaussian kernel for Fast Fourrier Transform approximaton. -% Misc -% options_.conf_sig = 0.6; + % Misc + % options_.conf_sig = 0.6; oo_.exo_simul = []; oo_.endo_simul = []; ys0_ = []; diff --git a/matlab/graph_decomp.m b/matlab/graph_decomp.m index 6fae28f3bb..341658ff7a 100644 --- a/matlab/graph_decomp.m +++ b/matlab/graph_decomp.m @@ -131,8 +131,8 @@ for j=1:nvar fhandle = dyn_figure(DynareOptions.plot_shock_decomp.nodisplay,'Name',[preamble_txt fig_name_long strrep(fig_mode1, '_', ' ') ': ' deblank(endo_names(i_var(j),:)) '.'], 'PaperPositionMode', 'auto','PaperOrientation','landscape','renderermode','auto'); set(fhandle,'position' ,[50 50 1500 750]) ax=axes('Position',[0.1 0.1 0.6 0.8],'box','on'); -% plot(ax,x(2:end),z1(end,:),'k-','LineWidth',2) -% axis(ax,[xmin xmax ymin ymax]); + % plot(ax,x(2:end),z1(end,:),'k-','LineWidth',2) + % axis(ax,[xmin xmax ymin ymax]); hold on; for i=1:gend i_1 = i-1; @@ -184,7 +184,7 @@ for j=1:nvar height = 1/comp_nbr; for i=comp_nbr:-1:1 -% for i=1:comp_nbr + % for i=1:comp_nbr hl = fill([0 0 0.2 0.2],[y1 y1+0.7*height y1+0.7*height y1],i); hold on ht = text(0.3,y1+0.3*height,labels(i,:),'Interpreter','none'); diff --git a/matlab/graph_decomp_detail.m b/matlab/graph_decomp_detail.m index 077653ea6d..771d2d9225 100644 --- a/matlab/graph_decomp_detail.m +++ b/matlab/graph_decomp_detail.m @@ -59,7 +59,7 @@ fig_name_long = opts_decomp.fig_name; % fig_name = ['_' fig_name]; if screen_shocks -% fig_name1 = [fig_name1 '_screen']; + % fig_name1 = [fig_name1 '_screen']; fig_name_long = [fig_name_long ' SCREEN']; end @@ -151,89 +151,89 @@ for j=1:nvar continue end for jf = 1:nfigs - fhandle = dyn_figure(DynareOptions.plot_shock_decomp.nodisplay,'Name',[preamble_txt fig_name_long strrep(fig_mode1, '_', ' ') ': ' deblank(endo_names(i_var(j),:)) ' (detail).'],'position',[200 100 650 850], 'PaperPositionMode', 'auto','PaperOrientation','portrait','renderermode','auto'); - a0=zeros(1,4); - a0(3)=inf; - a0(4)=-inf; - for ic=1+nrow*ncol*(jf-1):min(nrow*ncol*jf,comp_nbr), - i = ic-nrow*ncol*(jf-1); - zz = z1(ic,:); - zz(2,:)=z1(end,:)-zz; - ipos=zz>0; - ineg=zz<0; - hax = subplot(nrow,ncol,i); set(gca,'box','on') - hbar = bar(x(2:end),(zz.*ipos)','stacked'); - colormap([0.15 0.15 0.15;0.85 0.85 0.85]), - set(hbar,'edgecolor','flat'); - hold on, - hbar = bar(x(2:end),(zz.*ineg)','stacked'); - colormap([0.15 0.15 0.15;0.85 0.85 0.85]), - set(hbar,'edgecolor','flat'); - title(deblank(labels(ic,:)),'Interpreter','none'), - axis tight; - a=axis; - set(gca,'Xtick',xind_tick) - set(gca,'xlim',[xmin xmax]) - a0(3)=min(a(3),a0(3)); - a0(4)=max(a(4),a0(4)); - set(gca,'ylim',a0(3:4)) - hold on, h1=plot(x(2:end),z1(end,:),'k-','LineWidth',2); - if interactive & (~isoctave & use_shock_groups) - mydata.fig_name = DynareOptions.plot_shock_decomp.fig_name(2:end); - mydata.use_shock_groups = DynareOptions.plot_shock_decomp.use_shock_groups; - mydata.shock_group = shock_groups.(shock_ind{ic}); - mydata.shock_decomp = DynareOptions.plot_shock_decomp; - if ~isempty(mydata.shock_group.shocks{1}) - c = uicontextmenu; - hax.UIContextMenu=c; - browse_menu = uimenu(c,'Label','Browse group'); - expand_menu = uimenu(c,'Label','Expand group','Callback',['expand_group(''' mydata.use_shock_groups ''',''' deblank(mydata.shock_decomp.orig_varlist(j,:)) ''',' int2str(ic) ')']); - set(expand_menu,'UserData',mydata,'Tag',['group' int2str(ic)]); - for jmember = mydata.shock_group.shocks - uimenu('parent',browse_menu,'Label',char(jmember)) + fhandle = dyn_figure(DynareOptions.plot_shock_decomp.nodisplay,'Name',[preamble_txt fig_name_long strrep(fig_mode1, '_', ' ') ': ' deblank(endo_names(i_var(j),:)) ' (detail).'],'position',[200 100 650 850], 'PaperPositionMode', 'auto','PaperOrientation','portrait','renderermode','auto'); + a0=zeros(1,4); + a0(3)=inf; + a0(4)=-inf; + for ic=1+nrow*ncol*(jf-1):min(nrow*ncol*jf,comp_nbr), + i = ic-nrow*ncol*(jf-1); + zz = z1(ic,:); + zz(2,:)=z1(end,:)-zz; + ipos=zz>0; + ineg=zz<0; + hax = subplot(nrow,ncol,i); set(gca,'box','on') + hbar = bar(x(2:end),(zz.*ipos)','stacked'); + colormap([0.15 0.15 0.15;0.85 0.85 0.85]), + set(hbar,'edgecolor','flat'); + hold on, + hbar = bar(x(2:end),(zz.*ineg)','stacked'); + colormap([0.15 0.15 0.15;0.85 0.85 0.85]), + set(hbar,'edgecolor','flat'); + title(deblank(labels(ic,:)),'Interpreter','none'), + axis tight; + a=axis; + set(gca,'Xtick',xind_tick) + set(gca,'xlim',[xmin xmax]) + a0(3)=min(a(3),a0(3)); + a0(4)=max(a(4),a0(4)); + set(gca,'ylim',a0(3:4)) + hold on, h1=plot(x(2:end),z1(end,:),'k-','LineWidth',2); + if interactive & (~isoctave & use_shock_groups) + mydata.fig_name = DynareOptions.plot_shock_decomp.fig_name(2:end); + mydata.use_shock_groups = DynareOptions.plot_shock_decomp.use_shock_groups; + mydata.shock_group = shock_groups.(shock_ind{ic}); + mydata.shock_decomp = DynareOptions.plot_shock_decomp; + if ~isempty(mydata.shock_group.shocks{1}) + c = uicontextmenu; + hax.UIContextMenu=c; + browse_menu = uimenu(c,'Label','Browse group'); + expand_menu = uimenu(c,'Label','Expand group','Callback',['expand_group(''' mydata.use_shock_groups ''',''' deblank(mydata.shock_decomp.orig_varlist(j,:)) ''',' int2str(ic) ')']); + set(expand_menu,'UserData',mydata,'Tag',['group' int2str(ic)]); + for jmember = mydata.shock_group.shocks + uimenu('parent',browse_menu,'Label',char(jmember)) + end end end end - end - for isub=1:i, - subplot(nrow,ncol,isub), - set(gca,'ylim',a0(3:4)) - end - -% make legend - axes('Position',[0.1 0.01 0.8 0.02],'units','normalized'); - axis([0 1 0 1]); - axis off; - hold on; - x1 = 0; - width = 1/2; - mylabels = {'Individual contrib.','Residual contrib.'}; + for isub=1:i, + subplot(nrow,ncol,isub), + set(gca,'ylim',a0(3:4)) + end + + % make legend + axes('Position',[0.1 0.01 0.8 0.02],'units','normalized'); + axis([0 1 0 1]); + axis off; + hold on; + x1 = 0; + width = 1/2; + mylabels = {'Individual contrib.','Residual contrib.'}; - for i=1:2 -% for i=1:comp_nbr - hl = fill([x1 x1 x1+0.3*width x1+0.3*width],[0 1 1 0],i); - hold on - ht = text(x1+0.4*width,0.3,mylabels{i},'Interpreter','none'); - hold on - x1 = x1 + width; - end - - - if nfigs>1, - suffix = ['_detail_' int2str(jf)]; - else - suffix = ['_detail']; - end - dyn_saveas(fhandle,[GraphDirectoryName, filesep, DynareModel.fname,'_shock_decomposition_',deblank(endo_names(i_var(j),:)),fig_mode1,fig_name suffix],DynareOptions.plot_shock_decomp.nodisplay,DynareOptions.plot_shock_decomp.graph_format); - if DynareOptions.TeX && any(strcmp('eps',cellstr(DynareOptions.plot_shock_decomp.graph_format))) - fprintf(fidTeX,'\\begin{figure}[H]\n'); - fprintf(fidTeX,'\\centering \n'); - fprintf(fidTeX,'\\includegraphics[width=0.8\\textwidth]{%s/graphs/%s_shock_decomposition_%s}\n',DynareModel.fname,DynareModel.fname,[deblank(endo_names(i_var(j),:)) fig_mode1 fig_name suffix]); - fprintf(fidTeX,'\\label{Fig:shock_decomp_detail:%s}\n',[fig_mode deblank(endo_names(i_var(j),:)) fig_name suffix]); - fprintf(fidTeX,['\\caption{' preamble_txt fig_name_long strrep(fig_mode1, '_', ' ') ': $ %s $ (detail).}\n'],deblank(DynareModel.endo_names_tex(i_var(j),:))); - fprintf(fidTeX,'\\end{figure}\n'); - fprintf(fidTeX,' \n'); - end + for i=1:2 + % for i=1:comp_nbr + hl = fill([x1 x1 x1+0.3*width x1+0.3*width],[0 1 1 0],i); + hold on + ht = text(x1+0.4*width,0.3,mylabels{i},'Interpreter','none'); + hold on + x1 = x1 + width; + end + + + if nfigs>1, + suffix = ['_detail_' int2str(jf)]; + else + suffix = ['_detail']; + end + dyn_saveas(fhandle,[GraphDirectoryName, filesep, DynareModel.fname,'_shock_decomposition_',deblank(endo_names(i_var(j),:)),fig_mode1,fig_name suffix],DynareOptions.plot_shock_decomp.nodisplay,DynareOptions.plot_shock_decomp.graph_format); + if DynareOptions.TeX && any(strcmp('eps',cellstr(DynareOptions.plot_shock_decomp.graph_format))) + fprintf(fidTeX,'\\begin{figure}[H]\n'); + fprintf(fidTeX,'\\centering \n'); + fprintf(fidTeX,'\\includegraphics[width=0.8\\textwidth]{%s/graphs/%s_shock_decomposition_%s}\n',DynareModel.fname,DynareModel.fname,[deblank(endo_names(i_var(j),:)) fig_mode1 fig_name suffix]); + fprintf(fidTeX,'\\label{Fig:shock_decomp_detail:%s}\n',[fig_mode deblank(endo_names(i_var(j),:)) fig_name suffix]); + fprintf(fidTeX,['\\caption{' preamble_txt fig_name_long strrep(fig_mode1, '_', ' ') ': $ %s $ (detail).}\n'],deblank(DynareModel.endo_names_tex(i_var(j),:))); + fprintf(fidTeX,'\\end{figure}\n'); + fprintf(fidTeX,' \n'); + end end end diff --git a/matlab/gsa/Morris_Measure_Groups.m b/matlab/gsa/Morris_Measure_Groups.m index dfd37bdd12..cc5921206e 100644 --- a/matlab/gsa/Morris_Measure_Groups.m +++ b/matlab/gsa/Morris_Measure_Groups.m @@ -45,9 +45,9 @@ function [SAmeas, OutMatrix] = Morris_Measure_Groups(NumFact, Sample, Output, p, % along with Dynare. If not, see <http://www.gnu.org/licenses/>. if nargin==0, - skipline() - disp('[SAmeas, OutMatrix] = Morris_Measure_Groups(NumFact, Sample, Output, p, Group);') - return + skipline() + disp('[SAmeas, OutMatrix] = Morris_Measure_Groups(NumFact, Sample, Output, p, Group);') + return end OutMatrix=[]; @@ -72,10 +72,10 @@ r=size(Sample,1)/(sizea+1); % Number of trajectories for k=1:size(Output,2) OutValues=Output(:,k); - + % For each r trajectory for i=1:r - + % For each step j in the trajectory % Read the orientation matrix fact for the r-th sampling % Read the corresponding output values @@ -87,12 +87,12 @@ for k=1:size(Output,2) % For each point of the fixed trajectory compute the values of the Morris function. The function % is partitioned in four parts, from order zero to order 4th. for j=1:sizea % For each point in the trajectory i.e for each factor - % matrix of factor which changes + % matrix of factor which changes if NumGroups ~ 0; AuxFind (:,1) = A(:,j); -% AuxFind(find(A(:,j)),1)=1; -% Pippo = sum((Group - repmat(AuxFind,1,NumGroups)),1); -% Change_factor(j,i) = find(Pippo==0); + % AuxFind(find(A(:,j)),1)=1; + % Pippo = sum((Group - repmat(AuxFind,1,NumGroups)),1); + % Change_factor(j,i) = find(Pippo==0); Change_factor = find(abs(AuxFind)>1e-010); % If we deal with groups we can only estimate the new mu* % measure since factors in the same groups can move in @@ -113,31 +113,31 @@ for k=1:size(Output,2) end end end %for j=1:sizea - + end %for i=1:r - + if NumGroups ~ 0 SAmeas = SAmeas'; end % Compute Mu AbsMu and StDev if any(any(isnan(SAmeas))) - for j=1:NumFact, - SAm = SAmeas(j,:); - SAm = SAm(find(~isnan(SAm))); - rr=length(SAm); - AbsMu(j,1) = sum(abs(SAm),2)/rr; - if NumGroups == 0 - Mu(j,1) = sum(SAm,2)/rr; - StDev(j,1) = sum((SAm - repmat(Mu(j),1,rr)).^2/(rr*(rr-1)),2).^0.5; - end - end + for j=1:NumFact, + SAm = SAmeas(j,:); + SAm = SAm(find(~isnan(SAm))); + rr=length(SAm); + AbsMu(j,1) = sum(abs(SAm),2)/rr; + if NumGroups == 0 + Mu(j,1) = sum(SAm,2)/rr; + StDev(j,1) = sum((SAm - repmat(Mu(j),1,rr)).^2/(rr*(rr-1)),2).^0.5; + end + end else - AbsMu = sum(abs(SAmeas),2)/r; - if NumGroups == 0 - Mu = sum(SAmeas,2)/r; - StDev = sum((SAmeas - repmat(Mu,1,r)).^2/(r*(r-1)),2).^0.5; - end + AbsMu = sum(abs(SAmeas),2)/r; + if NumGroups == 0 + Mu = sum(SAmeas,2)/r; + StDev = sum((SAmeas - repmat(Mu,1,r)).^2/(r*(r-1)),2).^0.5; + end end % Define the output Matrix - if we have groups we cannot define the old diff --git a/matlab/gsa/Sampling_Function_2.m b/matlab/gsa/Sampling_Function_2.m index 60255cafbb..a7260d2525 100644 --- a/matlab/gsa/Sampling_Function_2.m +++ b/matlab/gsa/Sampling_Function_2.m @@ -1,10 +1,10 @@ function [Outmatrix, OutFact] = Sampling_Function_2(p, k, r, UB, LB, GroupMat) %[Outmatrix, OutFact] = Sampling_Function_2(p, k, r, UB, LB, GroupMat) -% Inputs: k (1,1) := number of factors examined or number of groups examined. +% Inputs: k (1,1) := number of factors examined or number of groups examined. % In case the groups are chosen the number of factors is stores in NumFact and % sizea becomes the number of created groups. % NumFact (1,1) := number of factors examined in the case when groups are chosen -% r (1,1) := sample size +% r (1,1) := sample size % p (1,1) := number of intervals considered in [0, 1] % UB(sizea,1) := Upper Bound for each factor % LB(sizea,1) := Lower Bound for each factor @@ -13,18 +13,18 @@ function [Outmatrix, OutFact] = Sampling_Function_2(p, k, r, UB, LB, GroupMat) % are set to 1 in correspondence of the factors that belong to the fixed group. All % the other elements are zero. % Local Variables: -% sizeb (1,1) := sizea+1 +% sizeb (1,1) := sizea+1 % sizec (1,1) := 1 % randmult (sizea,1) := vector of random +1 and -1 % perm_e(1,sizea) := vector of sizea random permutated indeces % fact(sizea) := vector containing the factor varied within each traj -% DDo(sizea,sizea) := D* in Morris, 1991 -% A(sizeb,sizea) := Jk+1,k in Morris, 1991 -% B(sizeb,sizea) := B in Morris, 1991 -% Po(sizea,sizea) := P* in Morris, 1991 +% DDo(sizea,sizea) := D* in Morris, 1991 +% A(sizeb,sizea) := Jk+1,k in Morris, 1991 +% B(sizeb,sizea) := B in Morris, 1991 +% Po(sizea,sizea) := P* in Morris, 1991 % Bo(sizeb,sizea) := B* in Morris, 1991 -% Ao(sizeb,sizec) := Jk+1,1 in Morris, 1991 -% xo(sizec,sizea) := x* in Morris, 1991 (starting point for the trajectory) +% Ao(sizeb,sizec) := Jk+1,1 in Morris, 1991 +% xo(sizec,sizea) := x* in Morris, 1991 (starting point for the trajectory) % In(sizeb,sizea) := for each loop orientation matrix. It corresponds to a trajectory % of k step in the parameter space and it provides a single elementary % effect per factor @@ -34,7 +34,7 @@ function [Outmatrix, OutFact] = Sampling_Function_2(p, k, r, UB, LB, GroupMat) % AuxMat(sizeb,sizea) := Delta*0.5*((2*B - A) * DD0 + A) in Morris, 1991. The AuxMat is used as in Morris design % for single factor analysis, while it constitutes an intermediate step for the group analysis. % -% Output: Outmatrix(sizeb*r, sizea) := for the entire sample size computed In(i,j) matrices +% Output: Outmatrix(sizeb*r, sizea) := for the entire sample size computed In(i,j) matrices % OutFact(sizea*r,1) := for the entire sample size computed Fact(i,1) vectors % % Note: B0 is constructed as in Morris design when groups are not considered. When groups are considered the routine @@ -110,7 +110,7 @@ for i=1:r % Construct B (lower triangular) B = ones(sizeb,sizea); for j = 1:sizea - B(1:j,j)=0; + B(1:j,j)=0; end % Construct A0, A diff --git a/matlab/gsa/filt_mc_.m b/matlab/gsa/filt_mc_.m index b6c4994d8d..f9510c8afa 100644 --- a/matlab/gsa/filt_mc_.m +++ b/matlab/gsa/filt_mc_.m @@ -58,33 +58,33 @@ disp('Starting sensitivity analysis') disp('for the fit of EACH observed series ...') skipline() if ~options_.nograph, -disp('Deleting old SA figures...') -a=dir([OutDir,filesep,'*.*']); -tmp1='0'; -if options_.opt_gsa.ppost, - tmp=['_rmse_post']; -else - if options_.opt_gsa.pprior - tmp=['_rmse_prior']; + disp('Deleting old SA figures...') + a=dir([OutDir,filesep,'*.*']); + tmp1='0'; + if options_.opt_gsa.ppost, + tmp=['_rmse_post']; else - tmp=['_rmse_mc']; - end - if options_gsa_.lik_only, - tmp1 = [tmp,'_post_SA']; - tmp = [tmp,'_lik_SA']; + if options_.opt_gsa.pprior + tmp=['_rmse_prior']; + else + tmp=['_rmse_mc']; + end + if options_gsa_.lik_only, + tmp1 = [tmp,'_post_SA']; + tmp = [tmp,'_lik_SA']; + end end -end -for j=1:length(a), - if strmatch([fname_,tmp],a(j).name), - disp(a(j).name) - delete([OutDir,filesep,a(j).name]) - end, - if strmatch([fname_,tmp1],a(j).name), - disp(a(j).name) - delete([OutDir,filesep,a(j).name]) - end, -end -disp('done !') + for j=1:length(a), + if strmatch([fname_,tmp],a(j).name), + disp(a(j).name) + delete([OutDir,filesep,a(j).name]) + end, + if strmatch([fname_,tmp1],a(j).name), + disp(a(j).name) + delete([OutDir,filesep,a(j).name]) + end, + end + disp('done !') end nshock=estim_params_.nvx + estim_params_.nvn + estim_params_.ncx + estim_params_.ncn; @@ -425,19 +425,19 @@ else if options_.opt_gsa.ppost dyn_saveas(hh,[OutDir filesep fname_ '_rmse_post_lnprior',int2str(ifig)],options_.nodisplay,options_.graph_format); if options_.TeX - create_TeX_loader(options_,[OutDir '/' fname_ '_rmse_post_lnprior',int2str(ifig)],ifig,[temp_name,' ',int2str(ifig)],'rmse_post_lnprior',options_.figures.textwidth*min((i-9*(ifig-1))/3,1)) + create_TeX_loader(options_,[OutDir '/' fname_ '_rmse_post_lnprior',int2str(ifig)],ifig,[temp_name,' ',int2str(ifig)],'rmse_post_lnprior',options_.figures.textwidth*min((i-9*(ifig-1))/3,1)) end else if options_.opt_gsa.pprior dyn_saveas(hh,[OutDir filesep fname_ '_rmse_prior_lnprior',int2str(ifig) ],options_.nodisplay,options_.graph_format); - if options_.TeX - create_TeX_loader(options_,[OutDir '/' fname_ '_rmse_prior_lnprior',int2str(ifig)],ifig,[temp_name,' ',int2str(ifig)],'rmse_prior_lnprior',options_.figures.textwidth*min((i-9*(ifig-1))/3,1)) - end + if options_.TeX + create_TeX_loader(options_,[OutDir '/' fname_ '_rmse_prior_lnprior',int2str(ifig)],ifig,[temp_name,' ',int2str(ifig)],'rmse_prior_lnprior',options_.figures.textwidth*min((i-9*(ifig-1))/3,1)) + end else dyn_saveas(hh,[OutDir filesep fname_ '_rmse_mc_lnprior',int2str(ifig) ],options_.nodisplay,options_.graph_format); - if options_.TeX - create_TeX_loader(options_,[OutDir '/' fname_ '_rmse_mc_lnprior',int2str(ifig)],ifig,[temp_name,' ',int2str(ifig)],'rmse_mc_lnprior',options_.figures.textwidth*min((i-9*(ifig-1))/3,1)) - end + if options_.TeX + create_TeX_loader(options_,[OutDir '/' fname_ '_rmse_mc_lnprior',int2str(ifig)],ifig,[temp_name,' ',int2str(ifig)],'rmse_mc_lnprior',options_.figures.textwidth*min((i-9*(ifig-1))/3,1)) + end end end end @@ -604,10 +604,10 @@ else data_mat=NaN(size(vvarvecm,1),5); for j=1:size(vvarvecm,1), data_mat(j,:)=[min(rmse_MC(ixx(1:nfilt0(j),j),j)) ... - max(rmse_MC(ixx(1:nfilt0(j),j),j)) ... - min(rmse_MC(ixx(nfilt0(j)+1:end,j),j)) ... - max(rmse_MC(ixx(nfilt0(j)+1:end,j),j)) ... - rmse_txt(j)]; + max(rmse_MC(ixx(1:nfilt0(j),j),j)) ... + min(rmse_MC(ixx(nfilt0(j)+1:end,j),j)) ... + max(rmse_MC(ixx(nfilt0(j)+1:end,j),j)) ... + rmse_txt(j)]; end %get formatting for additional header line val_width=15; @@ -678,10 +678,10 @@ else data_mat=NaN(size(vvarvecm,1),5); for j=1:size(vvarvecm,1), data_mat(j,:)=[min(r2_MC(ixx(1:nfilt0(j),j),j)) ... - max(r2_MC(ixx(1:nfilt0(j),j),j)) ... - min(r2_MC(ixx(nfilt0(j)+1:end,j),j)) ... - max(r2_MC(ixx(nfilt0(j)+1:end,j),j)) ... - r2_txt(j)]; + max(r2_MC(ixx(1:nfilt0(j),j),j)) ... + min(r2_MC(ixx(nfilt0(j)+1:end,j),j)) ... + max(r2_MC(ixx(nfilt0(j)+1:end,j),j)) ... + r2_txt(j)]; end %get formatting for additional header line val_width=15; @@ -924,64 +924,64 @@ else end end -% for j=1:size(SP,2), -% nsx(j)=length(find(SP(:,j))); -% end + % for j=1:size(SP,2), + % nsx(j)=length(find(SP(:,j))); + % end -% skipline(2) -% disp('Sensitivity table (significance and direction):') -% vav=char(zeros(1, size(param_names,2)+3 )); -% ibl = 12-size(vvarvecm,2); -% for j=1:size(vvarvecm,1), -% vav = [vav, char(zeros(1,ibl)),vvarvecm(j,:)]; -% end -% disp(vav) -% for j=1:npar+nshock, %estim_params_.np, -% %disp([param_names(j,:), sprintf('%8.5g',SP(j,:))]) -% disp([param_names(j,:),' ', sprintf('%12.3g',PP(j,:))]) -% disp([char(zeros(1, size(param_names,2)+3 )),sprintf(' (%6g)',SS(j,:))]) -% end + % skipline(2) + % disp('Sensitivity table (significance and direction):') + % vav=char(zeros(1, size(param_names,2)+3 )); + % ibl = 12-size(vvarvecm,2); + % for j=1:size(vvarvecm,1), + % vav = [vav, char(zeros(1,ibl)),vvarvecm(j,:)]; + % end + % disp(vav) + % for j=1:npar+nshock, %estim_params_.np, + % %disp([param_names(j,:), sprintf('%8.5g',SP(j,:))]) + % disp([param_names(j,:),' ', sprintf('%12.3g',PP(j,:))]) + % disp([char(zeros(1, size(param_names,2)+3 )),sprintf(' (%6g)',SS(j,:))]) + % end -% skipline() -% disp('Starting bivariate analysis:') -% -% for i=1:size(vvarvecm,1) -% if options_.opt_gsa.ppost -% fnam = ['rmse_post_',deblank(vvarvecm(i,:))]; -% else -% if options_.opt_gsa.pprior -% fnam = ['rmse_prior_',deblank(vvarvecm(i,:))]; -% else -% fnam = ['rmse_mc_',deblank(vvarvecm(i,:))]; -% end -% end -% stab_map_2(x(ixx(1:nfilt0(i),i),:),alpha2,pvalue,fnam, OutDir,[],[temp_name ' observed variable ' deblank(vvarvecm(i,:))]); -% -% % [pc,latent,explained] = pcacov(c0); -% % %figure, bar([explained cumsum(explained)]) -% % ifig=0; -% % j2=0; -% % for j=1:npar+nshock, -% % i2=find(abs(pc(:,j))>alphaPC); -% % if ~isempty(i2), -% % j2=j2+1; -% % if mod(j2,12)==1, -% % ifig=ifig+1; -% % figure('name',['PCA of the filtered sample ',deblank(vvarvecm(i,:)),' ',num2str(ifig)]), -% % end -% % subplot(3,4,j2-(ifig-1)*12) -% % bar(pc(i2,j)), -% % set(gca,'xticklabel',bayestopt_.name(i2)), -% % set(gca,'xtick',[1:length(i2)]) -% % title(['PC ',num2str(j),'. Explained ',num2str(explained(j)),'%']) -% % end -% % if (mod(j2,12)==0 | j==(npar+nshock)) & j2, -% % saveas(gcf,[fname_,'_SA_PCA_',deblank(vvarvecm(i,:)),'_',int2str(ifig)]) -% % end -% % end -% % close all -% end + % skipline() + % disp('Starting bivariate analysis:') + % + % for i=1:size(vvarvecm,1) + % if options_.opt_gsa.ppost + % fnam = ['rmse_post_',deblank(vvarvecm(i,:))]; + % else + % if options_.opt_gsa.pprior + % fnam = ['rmse_prior_',deblank(vvarvecm(i,:))]; + % else + % fnam = ['rmse_mc_',deblank(vvarvecm(i,:))]; + % end + % end + % stab_map_2(x(ixx(1:nfilt0(i),i),:),alpha2,pvalue,fnam, OutDir,[],[temp_name ' observed variable ' deblank(vvarvecm(i,:))]); + % + % % [pc,latent,explained] = pcacov(c0); + % % %figure, bar([explained cumsum(explained)]) + % % ifig=0; + % % j2=0; + % % for j=1:npar+nshock, + % % i2=find(abs(pc(:,j))>alphaPC); + % % if ~isempty(i2), + % % j2=j2+1; + % % if mod(j2,12)==1, + % % ifig=ifig+1; + % % figure('name',['PCA of the filtered sample ',deblank(vvarvecm(i,:)),' ',num2str(ifig)]), + % % end + % % subplot(3,4,j2-(ifig-1)*12) + % % bar(pc(i2,j)), + % % set(gca,'xticklabel',bayestopt_.name(i2)), + % % set(gca,'xtick',[1:length(i2)]) + % % title(['PC ',num2str(j),'. Explained ',num2str(explained(j)),'%']) + % % end + % % if (mod(j2,12)==0 | j==(npar+nshock)) & j2, + % % saveas(gcf,[fname_,'_SA_PCA_',deblank(vvarvecm(i,:)),'_',int2str(ifig)]) + % % end + % % end + % % close all + % end end diff --git a/matlab/gsa/ghx2transition.m b/matlab/gsa/ghx2transition.m index 072d8fe362..80b1fe040e 100644 --- a/matlab/gsa/ghx2transition.m +++ b/matlab/gsa/ghx2transition.m @@ -25,10 +25,10 @@ function [A,B] = ghx2transition(mm,iv,ic,aux) global oo_ M_ - [nr1, nc1] = size(mm); - ghx = mm(:, [1:(nc1-M_.exo_nbr)]); - ghu = mm(:, [(nc1-M_.exo_nbr+1):end] ); - if nargin == 1 +[nr1, nc1] = size(mm); +ghx = mm(:, [1:(nc1-M_.exo_nbr)]); +ghu = mm(:, [(nc1-M_.exo_nbr+1):end] ); +if nargin == 1 oo_.dr.ghx = ghx; oo_.dr.ghu = ghu; endo_nbr = M_.endo_nbr; @@ -40,18 +40,18 @@ global oo_ M_ k = find(aux(:,2) > nspred); aux(:,2) = aux(:,2) + nstatic; aux(k,2) = aux(k,2) + M_.nfwrd; - end - n_iv = length(iv); - n_ir1 = size(aux,1); - nr = n_iv + n_ir1; - - A = zeros(nr,nr); - B = zeros(nr,M_.exo_nbr); - - i_n_iv = 1:n_iv; - A(i_n_iv,ic) = ghx(iv,:); - if n_ir1 > 0 +end +n_iv = length(iv); +n_ir1 = size(aux,1); +nr = n_iv + n_ir1; + +A = zeros(nr,nr); +B = zeros(nr,M_.exo_nbr); + +i_n_iv = 1:n_iv; +A(i_n_iv,ic) = ghx(iv,:); +if n_ir1 > 0 A(n_iv+1:end,:) = sparse(aux(:,1),aux(:,2),ones(n_ir1,1),n_ir1,nr); - end - - B(i_n_iv,:) = ghu(iv,:); +end + +B(i_n_iv,:) = ghu(iv,:); diff --git a/matlab/gsa/gsa_plotmatrix.m b/matlab/gsa/gsa_plotmatrix.m index 9c9aee99fc..b2d9a027df 100644 --- a/matlab/gsa/gsa_plotmatrix.m +++ b/matlab/gsa/gsa_plotmatrix.m @@ -38,31 +38,31 @@ end iexplosive = iunstable(~ismember(iunstable,[iindeterm;iwrong])); switch type - case 'all' - x=[lpmat0 lpmat]; - NumberOfDraws=size(x,1); - B=NumberOfDraws; - case 'stable' - x=[lpmat0(istable,:) lpmat(istable,:)]; - NumberOfDraws=size(x,1); - B=NumberOfDraws; - case 'nosolution' - x=[lpmat0(iunstable,:) lpmat(iunstable,:)]; - NumberOfDraws=size(x,1); - B=NumberOfDraws; - case 'unstable' - x=[lpmat0(iexplosive,:) lpmat(iexplosive,:)]; - NumberOfDraws=size(x,1); - B=NumberOfDraws; - case 'indeterm' - x=[lpmat0(iindeterm,:) lpmat(iindeterm,:)]; - NumberOfDraws=size(x,1); - B=NumberOfDraws; - case 'wrong' - x=[lpmat0(iwrong,:) lpmat(iwrong,:)]; - NumberOfDraws=size(x,1); - B=NumberOfDraws; - + case 'all' + x=[lpmat0 lpmat]; + NumberOfDraws=size(x,1); + B=NumberOfDraws; + case 'stable' + x=[lpmat0(istable,:) lpmat(istable,:)]; + NumberOfDraws=size(x,1); + B=NumberOfDraws; + case 'nosolution' + x=[lpmat0(iunstable,:) lpmat(iunstable,:)]; + NumberOfDraws=size(x,1); + B=NumberOfDraws; + case 'unstable' + x=[lpmat0(iexplosive,:) lpmat(iexplosive,:)]; + NumberOfDraws=size(x,1); + B=NumberOfDraws; + case 'indeterm' + x=[lpmat0(iindeterm,:) lpmat(iindeterm,:)]; + NumberOfDraws=size(x,1); + B=NumberOfDraws; + case 'wrong' + x=[lpmat0(iwrong,:) lpmat(iwrong,:)]; + NumberOfDraws=size(x,1); + B=NumberOfDraws; + end if isempty(x), diff --git a/matlab/gsa/gsa_skewness.m b/matlab/gsa/gsa_skewness.m index b5af1c6ce2..45dfb39014 100644 --- a/matlab/gsa/gsa_skewness.m +++ b/matlab/gsa/gsa_skewness.m @@ -24,6 +24,6 @@ function s=gsa_skewness(y), % y=stand_(y); % s=mean(y.^3); - m2=mean((y-mean(y)).^2); - m3=mean((y-mean(y)).^3); - s=m3/m2^1.5; \ No newline at end of file +m2=mean((y-mean(y)).^2); +m3=mean((y-mean(y)).^3); +s=m3/m2^1.5; \ No newline at end of file diff --git a/matlab/gsa/gsa_speed.m b/matlab/gsa/gsa_speed.m index 9fce2e94b0..7ed7e59473 100644 --- a/matlab/gsa/gsa_speed.m +++ b/matlab/gsa/gsa_speed.m @@ -34,24 +34,24 @@ disp('Computing speed of adjustement ...') h = dyn_waitbar(0,'Speed of adjustement...'); for i=1:nrun, - irf=zeros(nvar,nshock); - a=squeeze(A(:,:,i)); - b=squeeze(B(:,:,i)); - IFF=inv(eye(nstate)-a)*b; - iff(:,:,i)=IFF(mf,:); - IF=IFF-b; - - t=0; - while any(any(irf<0.5)) - t=t+1; - IFT=((eye(nstate)-a^(t+1))*inv(eye(nstate)-a))*b-b; - irf=IFT(mf,:)./(IF(mf,:)+eps); - irf = irf.*(abs(IF(mf,:))>1.e-7)+(abs(IF(mf,:))<=1.e-7); - %irf=ft(mf,:); - tt=(irf>0.5).*t; - tadj(:,:,i)=((tt-tadj(:,:,i))==tt).*tt+tadj(:,:,i); - end - dyn_waitbar(i/nrun,h) + irf=zeros(nvar,nshock); + a=squeeze(A(:,:,i)); + b=squeeze(B(:,:,i)); + IFF=inv(eye(nstate)-a)*b; + iff(:,:,i)=IFF(mf,:); + IF=IFF-b; + + t=0; + while any(any(irf<0.5)) + t=t+1; + IFT=((eye(nstate)-a^(t+1))*inv(eye(nstate)-a))*b-b; + irf=IFT(mf,:)./(IF(mf,:)+eps); + irf = irf.*(abs(IF(mf,:))>1.e-7)+(abs(IF(mf,:))<=1.e-7); + %irf=ft(mf,:); + tt=(irf>0.5).*t; + tadj(:,:,i)=((tt-tadj(:,:,i))==tt).*tt+tadj(:,:,i); + end + dyn_waitbar(i/nrun,h) end skipline() disp('.. done !') diff --git a/matlab/gsa/log_trans_.m b/matlab/gsa/log_trans_.m index d1a028e65f..e051a0c884 100644 --- a/matlab/gsa/log_trans_.m +++ b/matlab/gsa/log_trans_.m @@ -29,55 +29,55 @@ if nargin==4, end if nargin==1, - xdir0=''; + xdir0=''; end f=@(lam,y)gsa_skewness(log(y+lam)); isig=1; if ~(max(y0)<0 | min(y0)>0) - if gsa_skewness(y0)<0, - isig=-1; - y0=-y0; - end - n=hist(y0,10); - if n(1)>20*n(end), - try lam=fzero(f,[-min(y0)+10*eps -min(y0)+abs(median(y0))],[],y0); - catch - yl(1)=f(-min(y0)+10*eps,y0); - yl(2)=f(-min(y0)+abs(median(y0)),y0); - if abs(yl(1))<abs(yl(2)) - lam=-min(y0)+eps; - else - lam = -min(y0)+abs(median(y0)); %abs(100*(1+min(y0))); - end + if gsa_skewness(y0)<0, + isig=-1; + y0=-y0; end - yy = log(y0+lam); - xdir=[xdir0,'_logskew']; - else - isig=0; - lam=0; - yy = log(y0.^2); - xdir=[xdir0,'_logsquared']; - end -else - if max(y0)<0 - isig=-1; - y0=-y0; - %yy=log(-y0); - xdir=[xdir0,'_minuslog']; - elseif min(y0)>0 - %yy=log(y0); - xdir=[xdir0,'_log']; - end - try lam=fzero(f,[-min(y0)+10*eps -min(y0)+median(y0)],[],y0); - catch - yl(1)=f(-min(y0)+10*eps,y0); - yl(2)=f(-min(y0)+abs(median(y0)),y0); - if abs(yl(1))<abs(yl(2)) - lam=-min(y0)+eps; + n=hist(y0,10); + if n(1)>20*n(end), + try lam=fzero(f,[-min(y0)+10*eps -min(y0)+abs(median(y0))],[],y0); + catch + yl(1)=f(-min(y0)+10*eps,y0); + yl(2)=f(-min(y0)+abs(median(y0)),y0); + if abs(yl(1))<abs(yl(2)) + lam=-min(y0)+eps; + else + lam = -min(y0)+abs(median(y0)); %abs(100*(1+min(y0))); + end + end + yy = log(y0+lam); + xdir=[xdir0,'_logskew']; else - lam = -min(y0)+abs(median(y0)); %abs(100*(1+min(y0))); + isig=0; + lam=0; + yy = log(y0.^2); + xdir=[xdir0,'_logsquared']; + end +else + if max(y0)<0 + isig=-1; + y0=-y0; + %yy=log(-y0); + xdir=[xdir0,'_minuslog']; + elseif min(y0)>0 + %yy=log(y0); + xdir=[xdir0,'_log']; + end + try lam=fzero(f,[-min(y0)+10*eps -min(y0)+median(y0)],[],y0); + catch + yl(1)=f(-min(y0)+10*eps,y0); + yl(2)=f(-min(y0)+abs(median(y0)),y0); + if abs(yl(1))<abs(yl(2)) + lam=-min(y0)+eps; + else + lam = -min(y0)+abs(median(y0)); %abs(100*(1+min(y0))); + end end - end - lam = max(lam,0); - yy = log(y0+lam); + lam = max(lam,0); + yy = log(y0+lam); end diff --git a/matlab/gsa/map_calibration.m b/matlab/gsa/map_calibration.m index 712d4572fe..20b8084a45 100644 --- a/matlab/gsa/map_calibration.m +++ b/matlab/gsa/map_calibration.m @@ -165,7 +165,7 @@ if ~isempty(indx_irf), end disp('done !') skipline() - + % For single legend search which has maximum nbr of restrictions all_irf_couples = cellstr([char(endo_prior_restrictions.irf(:,1)) char(endo_prior_restrictions.irf(:,2))]); irf_couples = unique(all_irf_couples); diff --git a/matlab/gsa/map_ident_.m b/matlab/gsa/map_ident_.m index 94e69f7fd8..a93ef006f0 100644 --- a/matlab/gsa/map_ident_.m +++ b/matlab/gsa/map_ident_.m @@ -32,23 +32,23 @@ itrans = opt_gsa.trans_ident; np = estim_params_.np; if opt_gsa.load_ident_files, - gsa_flag=0; + gsa_flag=0; else - gsa_flag=-2; + gsa_flag=-2; end pnames = M_.param_names(estim_params_.param_vals(:,1),:); - if opt_gsa.pprior, +if opt_gsa.pprior, -filetoload=[OutputDirectoryName '/' fname_ '_prior']; - else -filetoload=[OutputDirectoryName '/' fname_ '_mc']; - end + filetoload=[OutputDirectoryName '/' fname_ '_prior']; +else + filetoload=[OutputDirectoryName '/' fname_ '_mc']; +end load(filetoload,'lpmat','lpmat0','istable','T','yys','nspred','nboth','nfwrd') if ~isempty(lpmat0), - lpmatx=lpmat0(istable,:); + lpmatx=lpmat0(istable,:); else - lpmatx=[]; + lpmatx=[]; end Nsam = size(lpmat,1); nshock = size(lpmat0,2); @@ -57,139 +57,139 @@ npT = np+nshock; fname_ = M_.fname; if opt_gsa.load_ident_files==0, - % th moments -% options_.ar = min(3,options_.ar); + % th moments + % options_.ar = min(3,options_.ar); - mss = yys(bayestopt_.mfys,:); - mss = teff(mss(:,istable),Nsam,istable); - yys = teff(yys(oo_.dr.order_var,istable),Nsam,istable); - if exist('T'), - [vdec, cc, ac] = mc_moments(T, lpmatx, oo_.dr); - else - return, - end + mss = yys(bayestopt_.mfys,:); + mss = teff(mss(:,istable),Nsam,istable); + yys = teff(yys(oo_.dr.order_var,istable),Nsam,istable); + if exist('T'), + [vdec, cc, ac] = mc_moments(T, lpmatx, oo_.dr); + else + return, + end - if opt_gsa.morris==2, - pdraws = dynare_identification(options_.options_ident,[lpmatx lpmat(istable,:)]); -% [pdraws, TAU, GAM] = dynare_identification(options_.options_ident,[lpmatx lpmat(istable,:)]); - if ~isempty(pdraws) && max(max(abs(pdraws-[lpmatx lpmat(istable,:)])))==0, - disp(['Sample check OK ', num2str(max(max(abs(pdraws-[lpmatx lpmat(istable,:)]))))]), - clear pdraws; + if opt_gsa.morris==2, + pdraws = dynare_identification(options_.options_ident,[lpmatx lpmat(istable,:)]); + % [pdraws, TAU, GAM] = dynare_identification(options_.options_ident,[lpmatx lpmat(istable,:)]); + if ~isempty(pdraws) && max(max(abs(pdraws-[lpmatx lpmat(istable,:)])))==0, + disp(['Sample check OK ', num2str(max(max(abs(pdraws-[lpmatx lpmat(istable,:)]))))]), + clear pdraws; + end + % for j=1:length(istable), gas(:,j)=[vech(cc(:,:,j)); vec(ac(:,:,j))]; end + % if ~isempty(mss), + % gas = [mss(istable,:)'; gas]; + % end + % if max(max(abs(GAM-gas)))<=1.e-8, + % disp(['Moments check OK ',num2str(max(max(abs(GAM-gas))))]), + clear GAM gas + % end end -% for j=1:length(istable), gas(:,j)=[vech(cc(:,:,j)); vec(ac(:,:,j))]; end -% if ~isempty(mss), -% gas = [mss(istable,:)'; gas]; -% end -% if max(max(abs(GAM-gas)))<=1.e-8, -% disp(['Moments check OK ',num2str(max(max(abs(GAM-gas))))]), - clear GAM gas -% end - end - if opt_gsa.morris~=1 & M_.exo_nbr>1, - ifig=0; - for j=1:M_.exo_nbr, - if mod(j,6)==1 - hh=dyn_figure(options_.nodisplay,'name',['Variance decomposition shocks']); - ifig=ifig+1; - iplo=0; - end - iplo=iplo+1; - subplot(2,3,iplo) - myboxplot(squeeze(vdec(:,j,:))',[],'.',[],10) - % boxplot(squeeze(vdec(:,j,:))','whis',10,'symbol','.r') - set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:size(options_.varobs,1)]) - set(gca,'xlim',[0.5 size(options_.varobs,1)+0.5]) - set(gca,'ylim',[-2 102]) - for ip=1:size(options_.varobs,1), - text(ip,-4,deblank(options_.varobs(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') - end - xlabel(' ') - ylabel(' ') - title(M_.exo_names(j,:),'interpreter','none') - if mod(j,6)==0 | j==M_.exo_nbr, - dyn_saveas(hh,[OutputDirectoryName,'/',fname_,'_vdec_exo_',int2str(ifig)],options_.nodisplay,options_.graph_format); - create_TeX_loader(options_,[OutputDirectoryName,'/',fname_,'_vdec_exo_',int2str(ifig)],ifig,['Variance decomposition shocks'],'vdec_exo',options_.figures.textwidth*min(iplo/3,1)) - end + if opt_gsa.morris~=1 & M_.exo_nbr>1, + ifig=0; + for j=1:M_.exo_nbr, + if mod(j,6)==1 + hh=dyn_figure(options_.nodisplay,'name',['Variance decomposition shocks']); + ifig=ifig+1; + iplo=0; + end + iplo=iplo+1; + subplot(2,3,iplo) + myboxplot(squeeze(vdec(:,j,:))',[],'.',[],10) + % boxplot(squeeze(vdec(:,j,:))','whis',10,'symbol','.r') + set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:size(options_.varobs,1)]) + set(gca,'xlim',[0.5 size(options_.varobs,1)+0.5]) + set(gca,'ylim',[-2 102]) + for ip=1:size(options_.varobs,1), + text(ip,-4,deblank(options_.varobs(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') + end + xlabel(' ') + ylabel(' ') + title(M_.exo_names(j,:),'interpreter','none') + if mod(j,6)==0 | j==M_.exo_nbr, + dyn_saveas(hh,[OutputDirectoryName,'/',fname_,'_vdec_exo_',int2str(ifig)],options_.nodisplay,options_.graph_format); + create_TeX_loader(options_,[OutputDirectoryName,'/',fname_,'_vdec_exo_',int2str(ifig)],ifig,['Variance decomposition shocks'],'vdec_exo',options_.figures.textwidth*min(iplo/3,1)) + end + end + end + for j=1:size(cc,1) + cc(j,j,:)=stand_(squeeze(log(cc(j,j,:))))./2; end - end - for j=1:size(cc,1) - cc(j,j,:)=stand_(squeeze(log(cc(j,j,:))))./2; - end - [vdec, j0, ir_vdec, ic_vdec] = teff(vdec,Nsam,istable); - [cc, j0, ir_cc, ic_cc] = teff(cc,Nsam,istable); - [ac, j0, ir_ac, ic_ac] = teff(ac,Nsam,istable); + [vdec, j0, ir_vdec, ic_vdec] = teff(vdec,Nsam,istable); + [cc, j0, ir_cc, ic_cc] = teff(cc,Nsam,istable); + [ac, j0, ir_ac, ic_ac] = teff(ac,Nsam,istable); - [nr1, nc1, nnn] = size(T); + [nr1, nc1, nnn] = size(T); endo_nbr = M_.endo_nbr; nstatic = M_.nstatic; nspred = M_.nspred; iv = (1:endo_nbr)'; ic = [ nstatic+(1:nspred) endo_nbr+(1:size(oo_.dr.ghx,2)-nspred) ]'; - + dr.ghx = T(:, [1:(nc1-M_.exo_nbr)],1); dr.ghu = T(:, [(nc1-M_.exo_nbr+1):end], 1); [Aa,Bb] = kalman_transition_matrix(dr,iv,ic,M_.exo_nbr); -% bayestopt_.restrict_var_list, ... -% bayestopt_.restrict_columns, ... -% bayestopt_.restrict_aux, M_.exo_nbr); - A = zeros(size(Aa,1),size(Aa,2)+size(Aa,1),length(istable)); - % Sig(estim_params_.var_exo(:,1))=lpmatx(1,:).^2; - if ~isempty(lpmatx), - set_shocks_param(lpmatx(1,:)); - end - A(:,:,1)=[Aa, triu(Bb*M_.Sigma_e*Bb')]; - for j=2:length(istable), - dr.ghx = T(:, [1:(nc1-M_.exo_nbr)],j); - dr.ghu = T(:, [(nc1-M_.exo_nbr+1):end], j); - [Aa,Bb] = kalman_transition_matrix(dr, iv, ic, M_.exo_nbr); -% bayestopt_.restrict_var_list, ... -% bayestopt_.restrict_columns, ... -% bayestopt_.restrict_aux, M_.exo_nbr); + % bayestopt_.restrict_var_list, ... + % bayestopt_.restrict_columns, ... + % bayestopt_.restrict_aux, M_.exo_nbr); + A = zeros(size(Aa,1),size(Aa,2)+size(Aa,1),length(istable)); + % Sig(estim_params_.var_exo(:,1))=lpmatx(1,:).^2; if ~isempty(lpmatx), - set_shocks_param(lpmatx(j,:)); + set_shocks_param(lpmatx(1,:)); end - A(:,:,j)=[Aa, triu(Bb*M_.Sigma_e*Bb')]; - end - clear T; - clear lpmatx; + A(:,:,1)=[Aa, triu(Bb*M_.Sigma_e*Bb')]; + for j=2:length(istable), + dr.ghx = T(:, [1:(nc1-M_.exo_nbr)],j); + dr.ghu = T(:, [(nc1-M_.exo_nbr+1):end], j); + [Aa,Bb] = kalman_transition_matrix(dr, iv, ic, M_.exo_nbr); + % bayestopt_.restrict_var_list, ... + % bayestopt_.restrict_columns, ... + % bayestopt_.restrict_aux, M_.exo_nbr); + if ~isempty(lpmatx), + set_shocks_param(lpmatx(j,:)); + end + A(:,:,j)=[Aa, triu(Bb*M_.Sigma_e*Bb')]; + end + clear T; + clear lpmatx; - [nr,nc,nn]=size(A); - io=bayestopt_.mf2; - % T1=A(io,1:nr,:); - % ino=find(~ismember([1:nr],io)); - % T2=A(ino,1:nr,:); - R=A(:,nr+1:nc,:); -% [tadj, iff] = gsa_speed(A(1:nr,1:nr,:),R,io,0.5); -% [tadj, j0, ir_tadj, ic_tadj] = teff(tadj,Nsam,istable); -% [iff, j0, ir_if, ic_if] = teff(iff,Nsam,istable); + [nr,nc,nn]=size(A); + io=bayestopt_.mf2; + % T1=A(io,1:nr,:); + % ino=find(~ismember([1:nr],io)); + % T2=A(ino,1:nr,:); + R=A(:,nr+1:nc,:); + % [tadj, iff] = gsa_speed(A(1:nr,1:nr,:),R,io,0.5); + % [tadj, j0, ir_tadj, ic_tadj] = teff(tadj,Nsam,istable); + % [iff, j0, ir_if, ic_if] = teff(iff,Nsam,istable); - [yt, j0]=teff(A,Nsam,istable); - yt = [yys yt]; - if opt_gsa.morris==2, -% iii=find(std(yt(istable,:))>1.e-8); -% if max(max(abs(TAU-yt(istable,iii)')))<= 1.e-8, -% err = max(max(abs(TAU-yt(istable,iii)'))); -% disp(['Model check OK ',num2str(err)]), - clear TAU A -% end - else - clear A, - end - % [yt1, j01]=teff(T1,Nsam,istable); - % [yt2, j02]=teff(T2,Nsam,istable); - % [ytr, j0r]=teff(R,Nsam,istable); - % - % yt=[yt1 yt2 ytr]; - save([OutputDirectoryName,'/',fname_,'_main_eff.mat'],'ac','cc','vdec','yt','mss') + [yt, j0]=teff(A,Nsam,istable); + yt = [yys yt]; + if opt_gsa.morris==2, + % iii=find(std(yt(istable,:))>1.e-8); + % if max(max(abs(TAU-yt(istable,iii)')))<= 1.e-8, + % err = max(max(abs(TAU-yt(istable,iii)'))); + % disp(['Model check OK ',num2str(err)]), + clear TAU A + % end + else + clear A, + end + % [yt1, j01]=teff(T1,Nsam,istable); + % [yt2, j02]=teff(T2,Nsam,istable); + % [ytr, j0r]=teff(R,Nsam,istable); + % + % yt=[yt1 yt2 ytr]; + save([OutputDirectoryName,'/',fname_,'_main_eff.mat'],'ac','cc','vdec','yt','mss') else - if opt_gsa.morris==2, -% [pdraws, TAU, GAM] = dynare_identification([1:npT]); %,[lpmatx lpmat(istable,:)]); -% [pdraws, TAU, GAM] = dynare_identification(options_.options_ident); - pdraws = dynare_identification(options_.options_ident); - end - load([OutputDirectoryName,'/',fname_,'_main_eff.mat'],'ac','cc','vdec','yt','mss') + if opt_gsa.morris==2, + % [pdraws, TAU, GAM] = dynare_identification([1:npT]); %,[lpmatx lpmat(istable,:)]); + % [pdraws, TAU, GAM] = dynare_identification(options_.options_ident); + pdraws = dynare_identification(options_.options_ident); + end + load([OutputDirectoryName,'/',fname_,'_main_eff.mat'],'ac','cc','vdec','yt','mss') end % for j=1:nr, @@ -206,1353 +206,1353 @@ end % yt = yt(:,j0); if opt_gsa.morris==1, - %OutputDir = CheckPath('gsa/screen'); - if ~isempty(vdec), - if opt_gsa.load_ident_files==0, - SAMorris = []; - for i=1:size(vdec,2), - [SAmeas, SAMorris(:,:,i)] = Morris_Measure_Groups(npT, [lpmat0 lpmat], vdec(:,i),nliv); - end - SAvdec = squeeze(SAMorris(:,1,:))'; - save([OutputDirectoryName,'/',fname_,'_morris_IDE.mat'],'SAvdec','vdec','ir_vdec','ic_vdec') - else - load([OutputDirectoryName,'/',fname_,'_morris_IDE'],'SAvdec','vdec','ir_vdec','ic_vdec') - end - - hh = dyn_figure(options_.nodisplay,'name','Screening identification: variance decomposition'); -% boxplot(SAvdec,'whis',10,'symbol','r.') - myboxplot(SAvdec,[],'.',[],10) - set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:npT]) - set(gca,'xlim',[0.5 npT+0.5]) - ydum = get(gca,'ylim'); - set(gca,'ylim',[0 ydum(2)]) - set(gca,'position',[0.13 0.2 0.775 0.7]) - for ip=1:npT, - text(ip,-2,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') - end - xlabel(' ') - title('Elementary effects variance decomposition') - dyn_saveas(hh,[OutputDirectoryName,'/',fname_,'_morris_vdec'],options_.nodisplay,options_.graph_format); - create_TeX_loader(options_,[OutputDirectoryName,'/',fname_,'_morris_vdec'],1,'Screening identification: variance decomposition','morris_vdec',1) - else - save([OutputDirectoryName,'/',fname_,'_morris_IDE.mat'],'vdec') - - end + %OutputDir = CheckPath('gsa/screen'); + if ~isempty(vdec), + if opt_gsa.load_ident_files==0, + SAMorris = []; + for i=1:size(vdec,2), + [SAmeas, SAMorris(:,:,i)] = Morris_Measure_Groups(npT, [lpmat0 lpmat], vdec(:,i),nliv); + end + SAvdec = squeeze(SAMorris(:,1,:))'; + save([OutputDirectoryName,'/',fname_,'_morris_IDE.mat'],'SAvdec','vdec','ir_vdec','ic_vdec') + else + load([OutputDirectoryName,'/',fname_,'_morris_IDE'],'SAvdec','vdec','ir_vdec','ic_vdec') + end + + hh = dyn_figure(options_.nodisplay,'name','Screening identification: variance decomposition'); + % boxplot(SAvdec,'whis',10,'symbol','r.') + myboxplot(SAvdec,[],'.',[],10) + set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:npT]) + set(gca,'xlim',[0.5 npT+0.5]) + ydum = get(gca,'ylim'); + set(gca,'ylim',[0 ydum(2)]) + set(gca,'position',[0.13 0.2 0.775 0.7]) + for ip=1:npT, + text(ip,-2,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') + end + xlabel(' ') + title('Elementary effects variance decomposition') + dyn_saveas(hh,[OutputDirectoryName,'/',fname_,'_morris_vdec'],options_.nodisplay,options_.graph_format); + create_TeX_loader(options_,[OutputDirectoryName,'/',fname_,'_morris_vdec'],1,'Screening identification: variance decomposition','morris_vdec',1) + else + save([OutputDirectoryName,'/',fname_,'_morris_IDE.mat'],'vdec') + + end -% ifig = 0; -% for j=1:size(options_.varobs,1) -% if mod(j,6)==1 -% figure('name',['EET variance decomposition observed variables']); -% ifig=ifig+1; -% iplo=0; -% end -% iplo=iplo+1; -% subplot(3,2,iplo) -% iv = find(ir_vdec==j); -% if ~isempty(iv) -% if length(iv)>1 -% % boxplot(SAvdec(iv,:),'whis',3,'symbol','r.'); -% myboxplot(SAvdec(iv,:),[],'.',[],3) -% else -% plot(SAvdec(iv,:),'r.'); -% end -% set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:npT]) -% set(gca,'xlim',[0.5 npT+0.5]) -% ydum = get(gca,'ylim'); -% set(gca,'ylim',[0 ydum(2)]) -% for ip=1:npT, -% text(ip,-2,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') -% end -% xlabel(' ') -% end -% title(options_.varobs(j,:),'interpreter','none') -% if mod(j,6)==0 | j==size(options_.varobs,1) -% saveas(gcf,[OutputDirectoryName,'/',fname_,'_morris_vdec_varobs_',int2str(ifig)]) -% eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_morris_vdec_varobs_',int2str(ifig)]); -% eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_morris_vdec_varobs_',int2str(ifig)]); -% close(gcf) -% end -% end -% -% ifig = 0; -% for j=1:M_.exo_nbr, -% if mod(j,6)==1 -% figure('name',['EET variance decomposition shocks']); -% ifig=ifig+1; -% iplo=0; -% end -% iplo=iplo+1; -% subplot(3,2,iplo) -% iv = find(ic_vdec==j); -% if ~isempty(iv) -% if length(iv)>1 -% % boxplot(SAvdec(iv,:),'whis',3,'symbol','r.'); -% myboxplot(SAvdec(iv,:),[],'.',[],3) -% else -% plot(SAvdec(iv,:),'r.'); -% end -% set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:npT]) -% set(gca,'xlim',[0.5 npT+0.5]) -% ydum = get(gca,'ylim'); -% set(gca,'ylim',[0 ydum(2)]) -% for ip=1:npT, -% text(ip,-2,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') -% end -% xlabel(' ') -% end -% title(M_.exo_names(j,:),'interpreter','none') -% if mod(j,6)==0 | j==M_.exo_nbr, -% saveas(gcf,[OutputDirectoryName,'/',fname_,'_morris_vdec_exo_',int2str(ifig)]) -% eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_morris_vdec_exo_',int2str(ifig)]); -% eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_morris_vdec_exo_',int2str(ifig)]); -% close(gcf), -% end -% end + % ifig = 0; + % for j=1:size(options_.varobs,1) + % if mod(j,6)==1 + % figure('name',['EET variance decomposition observed variables']); + % ifig=ifig+1; + % iplo=0; + % end + % iplo=iplo+1; + % subplot(3,2,iplo) + % iv = find(ir_vdec==j); + % if ~isempty(iv) + % if length(iv)>1 + % % boxplot(SAvdec(iv,:),'whis',3,'symbol','r.'); + % myboxplot(SAvdec(iv,:),[],'.',[],3) + % else + % plot(SAvdec(iv,:),'r.'); + % end + % set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:npT]) + % set(gca,'xlim',[0.5 npT+0.5]) + % ydum = get(gca,'ylim'); + % set(gca,'ylim',[0 ydum(2)]) + % for ip=1:npT, + % text(ip,-2,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') + % end + % xlabel(' ') + % end + % title(options_.varobs(j,:),'interpreter','none') + % if mod(j,6)==0 | j==size(options_.varobs,1) + % saveas(gcf,[OutputDirectoryName,'/',fname_,'_morris_vdec_varobs_',int2str(ifig)]) + % eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_morris_vdec_varobs_',int2str(ifig)]); + % eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_morris_vdec_varobs_',int2str(ifig)]); + % close(gcf) + % end + % end + % + % ifig = 0; + % for j=1:M_.exo_nbr, + % if mod(j,6)==1 + % figure('name',['EET variance decomposition shocks']); + % ifig=ifig+1; + % iplo=0; + % end + % iplo=iplo+1; + % subplot(3,2,iplo) + % iv = find(ic_vdec==j); + % if ~isempty(iv) + % if length(iv)>1 + % % boxplot(SAvdec(iv,:),'whis',3,'symbol','r.'); + % myboxplot(SAvdec(iv,:),[],'.',[],3) + % else + % plot(SAvdec(iv,:),'r.'); + % end + % set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:npT]) + % set(gca,'xlim',[0.5 npT+0.5]) + % ydum = get(gca,'ylim'); + % set(gca,'ylim',[0 ydum(2)]) + % for ip=1:npT, + % text(ip,-2,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') + % end + % xlabel(' ') + % end + % title(M_.exo_names(j,:),'interpreter','none') + % if mod(j,6)==0 | j==M_.exo_nbr, + % saveas(gcf,[OutputDirectoryName,'/',fname_,'_morris_vdec_exo_',int2str(ifig)]) + % eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_morris_vdec_exo_',int2str(ifig)]); + % eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_morris_vdec_exo_',int2str(ifig)]); + % close(gcf), + % end + % end - if opt_gsa.load_ident_files==0, - SAMorris = []; - ccac = [mss cc ac]; - for i=1:size(ccac,2), - [SAmeas, SAMorris(:,:,i)] = Morris_Measure_Groups(npT, [lpmat0 lpmat], [ccac(:,i)],nliv); - end - SAcc = squeeze(SAMorris(:,1,:))'; - SAcc = SAcc./(max(SAcc')'*ones(1,npT)); - save([OutputDirectoryName,'/',fname_,'_morris_IDE.mat'],'SAcc','cc','ir_cc','ic_cc','-append') - save([OutputDirectoryName,'/',fname_,'_morris_IDE.mat'],'ac','ir_ac','ic_ac','-append') - else - load([OutputDirectoryName,'/',fname_,'_morris_IDE'],'SAcc','cc','ir_cc','ic_cc') - load([OutputDirectoryName,'/',fname_,'_morris_IDE'],'ac','ir_ac','ic_ac') - end - - hh=dyn_figure(options_.nodisplay,'name','Screening identification: theoretical moments'); -% boxplot(SAcc,'whis',10,'symbol','r.') - myboxplot(SAcc,[],'.',[],10) - set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:npT]) - set(gca,'xlim',[0.5 npT+0.5]) - ydum = get(gca,'ylim'); - set(gca,'ylim',[0 1]) - set(gca,'position',[0.13 0.2 0.775 0.7]) - for ip=1:npT, - text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') - end - xlabel(' ') - title('Elementary effects in the moments') - dyn_saveas(hh,[OutputDirectoryName,'/',fname_,'_morris_moments'],options_.nodisplay,options_.graph_format); - create_TeX_loader(options_,[OutputDirectoryName,'/',fname_,'_morris_moments'],1,'Screening identification: theoretical moments','morris_moments',1) + if opt_gsa.load_ident_files==0, + SAMorris = []; + ccac = [mss cc ac]; + for i=1:size(ccac,2), + [SAmeas, SAMorris(:,:,i)] = Morris_Measure_Groups(npT, [lpmat0 lpmat], [ccac(:,i)],nliv); + end + SAcc = squeeze(SAMorris(:,1,:))'; + SAcc = SAcc./(max(SAcc')'*ones(1,npT)); + save([OutputDirectoryName,'/',fname_,'_morris_IDE.mat'],'SAcc','cc','ir_cc','ic_cc','-append') + save([OutputDirectoryName,'/',fname_,'_morris_IDE.mat'],'ac','ir_ac','ic_ac','-append') + else + load([OutputDirectoryName,'/',fname_,'_morris_IDE'],'SAcc','cc','ir_cc','ic_cc') + load([OutputDirectoryName,'/',fname_,'_morris_IDE'],'ac','ir_ac','ic_ac') + end + + hh=dyn_figure(options_.nodisplay,'name','Screening identification: theoretical moments'); + % boxplot(SAcc,'whis',10,'symbol','r.') + myboxplot(SAcc,[],'.',[],10) + set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:npT]) + set(gca,'xlim',[0.5 npT+0.5]) + ydum = get(gca,'ylim'); + set(gca,'ylim',[0 1]) + set(gca,'position',[0.13 0.2 0.775 0.7]) + for ip=1:npT, + text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') + end + xlabel(' ') + title('Elementary effects in the moments') + dyn_saveas(hh,[OutputDirectoryName,'/',fname_,'_morris_moments'],options_.nodisplay,options_.graph_format); + create_TeX_loader(options_,[OutputDirectoryName,'/',fname_,'_morris_moments'],1,'Screening identification: theoretical moments','morris_moments',1) -% close(gcf), + % close(gcf), -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% MORRIS FOR DERIVATIVES -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + % MORRIS FOR DERIVATIVES + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% if opt_gsa.load_ident_files==0, -% for j=1:npT, -% SAMorris = []; -% ddd=NaN(size(lpmat,1),size(JJ,1)); -% ddd(istable,:) = squeeze(JJ(:,j,:))'; -% for i=1:size(ddd,2), -% [SAmeas, SAMorris(:,:,i)] = Morris_Measure_Groups(npT, [lpmat0 lpmat], [ddd(:,i)],nliv); -% end -% SAddd(:,:,j) = squeeze(SAMorris(:,1,:))'; -% SAddd(:,:,j) = SAddd(:,:,j)./(max(SAddd(:,:,j)')'*ones(1,npT)); -% sad(:,j) = median(SAddd(find(~isnan(squeeze(SAddd(:,1,j)))),:,j))'; -% end -% save([OutputDirectoryName,'/',fname_,'_morris_IDE'],'SAddd','sad','-append') -% else -% load([OutputDirectoryName,'/',fname_,'_morris_IDE'],'SAddd','sad') -% end -% figure, -% contourf(sad,10), colorbar -% set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:npT]) -% set(gca,'yticklabel',' ','fontsize',10,'ytick',[1:npT]) -% for ip=1:npT, -% text(ip,0.9,['D(',bayestopt_.name{ip},')'],'rotation',90,'HorizontalAlignment','right','interpreter','none') -% text(0.9,ip,[bayestopt_.name{ip}],'rotation',0,'HorizontalAlignment','right','interpreter','none') -% end -% [m,im]=max(sad); -% iii = find((im-[1:npT])==0); -% disp('Most identified params') -% disp(bayestopt_.name(iii)) - - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% END OF MORRIS FOR DERIVATIVES -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -% ifig = 0; -% for j=1:size(options_.varobs,1) -% if mod(j,6)==1 -% figure('name',['EET cross-correlations']); -% ifig=ifig+1; -% iplo=0; -% end -% iplo=iplo+1; -% subplot(3,2,iplo) -% iv = find(ir_cc==j); -% iv = [iv; find(ic_cc==j)]; -% if ~isempty(iv) -% if length(iv)>1 -% % boxplot(SAcc(iv,:),'whis',3,'symbol','r.'); -% myboxplot(SAcc(iv,:),[],'.',[],3) -% else -% plot(SAcc(iv,:),'r.'); -% end -% set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:npT]) -% set(gca,'xlim',[0.5 npT+0.5]) -% ydum = get(gca,'ylim'); -% set(gca,'ylim',[0 ydum(2)]) -% for ip=1:npT, -% text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') -% end -% xlabel(' ') -% end -% title(options_.varobs(j,:),'interpreter','none') -% if mod(j,6)==0 | j==size(options_.varobs,1) -% saveas(gcf,[OutputDirectoryName,'/',fname_,'_morris_cc_',int2str(ifig)]) -% eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_morris_cc_',int2str(ifig)]); -% eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_morris_cc_',int2str(ifig)]); -% close(gcf), -% end -% end + % if opt_gsa.load_ident_files==0, + % for j=1:npT, + % SAMorris = []; + % ddd=NaN(size(lpmat,1),size(JJ,1)); + % ddd(istable,:) = squeeze(JJ(:,j,:))'; + % for i=1:size(ddd,2), + % [SAmeas, SAMorris(:,:,i)] = Morris_Measure_Groups(npT, [lpmat0 lpmat], [ddd(:,i)],nliv); + % end + % SAddd(:,:,j) = squeeze(SAMorris(:,1,:))'; + % SAddd(:,:,j) = SAddd(:,:,j)./(max(SAddd(:,:,j)')'*ones(1,npT)); + % sad(:,j) = median(SAddd(find(~isnan(squeeze(SAddd(:,1,j)))),:,j))'; + % end + % save([OutputDirectoryName,'/',fname_,'_morris_IDE'],'SAddd','sad','-append') + % else + % load([OutputDirectoryName,'/',fname_,'_morris_IDE'],'SAddd','sad') + % end + % figure, + % contourf(sad,10), colorbar + % set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:npT]) + % set(gca,'yticklabel',' ','fontsize',10,'ytick',[1:npT]) + % for ip=1:npT, + % text(ip,0.9,['D(',bayestopt_.name{ip},')'],'rotation',90,'HorizontalAlignment','right','interpreter','none') + % text(0.9,ip,[bayestopt_.name{ip}],'rotation',0,'HorizontalAlignment','right','interpreter','none') + % end + % [m,im]=max(sad); + % iii = find((im-[1:npT])==0); + % disp('Most identified params') + % disp(bayestopt_.name(iii)) + + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + % END OF MORRIS FOR DERIVATIVES + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + % ifig = 0; + % for j=1:size(options_.varobs,1) + % if mod(j,6)==1 + % figure('name',['EET cross-correlations']); + % ifig=ifig+1; + % iplo=0; + % end + % iplo=iplo+1; + % subplot(3,2,iplo) + % iv = find(ir_cc==j); + % iv = [iv; find(ic_cc==j)]; + % if ~isempty(iv) + % if length(iv)>1 + % % boxplot(SAcc(iv,:),'whis',3,'symbol','r.'); + % myboxplot(SAcc(iv,:),[],'.',[],3) + % else + % plot(SAcc(iv,:),'r.'); + % end + % set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:npT]) + % set(gca,'xlim',[0.5 npT+0.5]) + % ydum = get(gca,'ylim'); + % set(gca,'ylim',[0 ydum(2)]) + % for ip=1:npT, + % text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') + % end + % xlabel(' ') + % end + % title(options_.varobs(j,:),'interpreter','none') + % if mod(j,6)==0 | j==size(options_.varobs,1) + % saveas(gcf,[OutputDirectoryName,'/',fname_,'_morris_cc_',int2str(ifig)]) + % eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_morris_cc_',int2str(ifig)]); + % eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_morris_cc_',int2str(ifig)]); + % close(gcf), + % end + % end -% if opt_gsa.load_ident_files==0, -% SAMorris = []; -% for i=1:size(ac,2), -% [SAmeas, SAMorris(:,:,i)] = Morris_Measure_Groups(npT, [lpmat0 lpmat], ac(:,i),nliv); -% end -% %end -% SAac = squeeze(SAMorris(:,1,:))'; -% save([OutputDirectoryName,'/',fname_,'_morris_IDE'],'SAac','ac','ir_ac','ic_ac','-append') -% else -% load([OutputDirectoryName,'/',fname_,'_morris_IDE'],'SAac','ac','ir_ac','ic_ac') -% end -% figure, -% % boxplot(SAac,'whis',10,'symbol','r.') -% myboxplot(SAac,[],'.',[],10) -% set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:npT]) -% set(gca,'xlim',[0.5 npT+0.5]) -% ydum = get(gca,'ylim'); -% set(gca,'ylim',[0 ydum(2)]) -% set(gca,'position',[0.13 0.2 0.775 0.7]) -% for ip=1:npT, -% text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') -% end -% xlabel(' ') -% title('EET All auto-correlations') -% saveas(gcf,[OutputDirectoryName,'/',fname_,'_morris_ac']) -% eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_morris_ac']); -% eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_morris_ac']); -% close(gcf), + % if opt_gsa.load_ident_files==0, + % SAMorris = []; + % for i=1:size(ac,2), + % [SAmeas, SAMorris(:,:,i)] = Morris_Measure_Groups(npT, [lpmat0 lpmat], ac(:,i),nliv); + % end + % %end + % SAac = squeeze(SAMorris(:,1,:))'; + % save([OutputDirectoryName,'/',fname_,'_morris_IDE'],'SAac','ac','ir_ac','ic_ac','-append') + % else + % load([OutputDirectoryName,'/',fname_,'_morris_IDE'],'SAac','ac','ir_ac','ic_ac') + % end + % figure, + % % boxplot(SAac,'whis',10,'symbol','r.') + % myboxplot(SAac,[],'.',[],10) + % set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:npT]) + % set(gca,'xlim',[0.5 npT+0.5]) + % ydum = get(gca,'ylim'); + % set(gca,'ylim',[0 ydum(2)]) + % set(gca,'position',[0.13 0.2 0.775 0.7]) + % for ip=1:npT, + % text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') + % end + % xlabel(' ') + % title('EET All auto-correlations') + % saveas(gcf,[OutputDirectoryName,'/',fname_,'_morris_ac']) + % eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_morris_ac']); + % eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_morris_ac']); + % close(gcf), -% ifig = 0; -% for j=1:size(options_.varobs,1) -% if mod(j,6)==1 -% figure('name',['EET auto-correlations']); -% ifig=ifig+1; -% iplo=0; -% end -% iplo=iplo+1; -% subplot(3,2,iplo) -% iv = find(ir_ac==j); -% if ~isempty(iv) -% if length(iv)>1 -% % boxplot(SAac(iv,:),'whis',3,'symbol','r.'); -% myboxplot(SAac(iv,:),[],'.',[],3) -% else -% plot(SAac(iv,:),'r.'); -% end -% set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:npT]) -% set(gca,'xlim',[0.5 npT+0.5]) -% ydum = get(gca,'ylim'); -% set(gca,'ylim',[0 ydum(2)]) -% for ip=1:npT, -% text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') -% end -% xlabel(' ') -% end -% title(options_.varobs(j,:),'interpreter','none') -% if mod(j,6)==0 | j==size(options_.varobs,1) -% saveas(gcf,[OutputDirectoryName,'/',fname_,'_morris_ac_',int2str(ifig)]) -% eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_morris_ac_',int2str(ifig)]); -% eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_morris_ac_',int2str(ifig)]); -% close(gcf), -% end -% end + % ifig = 0; + % for j=1:size(options_.varobs,1) + % if mod(j,6)==1 + % figure('name',['EET auto-correlations']); + % ifig=ifig+1; + % iplo=0; + % end + % iplo=iplo+1; + % subplot(3,2,iplo) + % iv = find(ir_ac==j); + % if ~isempty(iv) + % if length(iv)>1 + % % boxplot(SAac(iv,:),'whis',3,'symbol','r.'); + % myboxplot(SAac(iv,:),[],'.',[],3) + % else + % plot(SAac(iv,:),'r.'); + % end + % set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:npT]) + % set(gca,'xlim',[0.5 npT+0.5]) + % ydum = get(gca,'ylim'); + % set(gca,'ylim',[0 ydum(2)]) + % for ip=1:npT, + % text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') + % end + % xlabel(' ') + % end + % title(options_.varobs(j,:),'interpreter','none') + % if mod(j,6)==0 | j==size(options_.varobs,1) + % saveas(gcf,[OutputDirectoryName,'/',fname_,'_morris_ac_',int2str(ifig)]) + % eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_morris_ac_',int2str(ifig)]); + % eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_morris_ac_',int2str(ifig)]); + % close(gcf), + % end + % end -% if opt_gsa.load_ident_files==0, -% js=0; -% %for j=1:size(tadj,1), -% SAMorris = []; -% for i=1:size(tadj,2), -% js=js+1; -% [SAmeas, SAMorris(:,:,js)] = Morris_Measure_Groups(npT, [lpmat0 lpmat], tadj(:,i),nliv); -% end -% %end -% SAM = squeeze(SAMorris(nshock+1:end,1,:)); -% for j=1:js, -% SAtadj(:,j)=SAM(:,j)./(max(SAM(:,j))+eps); -% end -% SAtadj = SAtadj'; -% save([OutputDirectoryName,'/',fname_,'_morris_IDE'],'SAtadj','tadj','ir_tadj','ic_tadj','-append') -% else -% load([OutputDirectoryName,'/',fname_,'_morris_IDE'],'SAtadj','tadj','ir_tadj','ic_tadj') -% end -% if opt_gsa.load_ident_files==0, -% js=0; -% SAMorris = []; -% for i=1:size(iff,2), -% js=js+1; -% [SAmeas, SAMorriss(:,:,js)] = Morris_Measure_Groups(npT, [lpmat0 lpmat], iff(:,i),nliv); -% end -% SAM = squeeze(SAMorriss(nshock+1:end,1,:)); -% for j=1:js, -% SAIF(:,j)=SAM(:,j)./(max(SAM(:,j))+eps); -% end -% SAIF = SAIF'; -% save([OutputDirectoryName,'/',fname_,'_morris_IDE'],'SAIF','iff','ir_if','ic_if','-append') -% else -% load([OutputDirectoryName,'/',fname_,'_morris_IDE'],'SAIF','iff','ir_if','ic_if') -% end -% figure, -% %bar(SAtadj), -% % boxplot(SAtadj,'whis',10,'symbol','r.') -% myboxplot(SAtadj,[],'.',[],10) -% set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) -% set(gca,'xlim',[0.5 np+0.5]) -% set(gca,'ylim',[0 1]) -% set(gca,'position',[0.13 0.2 0.775 0.7]) -% for ip=1:np, -% text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') -% end -% xlabel(' ') -% title('All half-life') -% saveas(gcf,[OutputDirectoryName,'/',fname_,'_morris_tadj']) -% eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_morris_tadj']); -% eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_morris_tadj']); -% close(gcf), + % if opt_gsa.load_ident_files==0, + % js=0; + % %for j=1:size(tadj,1), + % SAMorris = []; + % for i=1:size(tadj,2), + % js=js+1; + % [SAmeas, SAMorris(:,:,js)] = Morris_Measure_Groups(npT, [lpmat0 lpmat], tadj(:,i),nliv); + % end + % %end + % SAM = squeeze(SAMorris(nshock+1:end,1,:)); + % for j=1:js, + % SAtadj(:,j)=SAM(:,j)./(max(SAM(:,j))+eps); + % end + % SAtadj = SAtadj'; + % save([OutputDirectoryName,'/',fname_,'_morris_IDE'],'SAtadj','tadj','ir_tadj','ic_tadj','-append') + % else + % load([OutputDirectoryName,'/',fname_,'_morris_IDE'],'SAtadj','tadj','ir_tadj','ic_tadj') + % end + % if opt_gsa.load_ident_files==0, + % js=0; + % SAMorris = []; + % for i=1:size(iff,2), + % js=js+1; + % [SAmeas, SAMorriss(:,:,js)] = Morris_Measure_Groups(npT, [lpmat0 lpmat], iff(:,i),nliv); + % end + % SAM = squeeze(SAMorriss(nshock+1:end,1,:)); + % for j=1:js, + % SAIF(:,j)=SAM(:,j)./(max(SAM(:,j))+eps); + % end + % SAIF = SAIF'; + % save([OutputDirectoryName,'/',fname_,'_morris_IDE'],'SAIF','iff','ir_if','ic_if','-append') + % else + % load([OutputDirectoryName,'/',fname_,'_morris_IDE'],'SAIF','iff','ir_if','ic_if') + % end + % figure, + % %bar(SAtadj), + % % boxplot(SAtadj,'whis',10,'symbol','r.') + % myboxplot(SAtadj,[],'.',[],10) + % set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) + % set(gca,'xlim',[0.5 np+0.5]) + % set(gca,'ylim',[0 1]) + % set(gca,'position',[0.13 0.2 0.775 0.7]) + % for ip=1:np, + % text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') + % end + % xlabel(' ') + % title('All half-life') + % saveas(gcf,[OutputDirectoryName,'/',fname_,'_morris_tadj']) + % eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_morris_tadj']); + % eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_morris_tadj']); + % close(gcf), -% ifig = 0; -% for j=1:size(options_.varobs,1) -% if mod(j,6)==1 -% figure('name',['EET speed of adjustment observed variables']); -% ifig=ifig+1; -% iplo=0; -% end -% iplo=iplo+1; -% subplot(3,2,iplo) -% iv = find(ir_tadj==j); -% if ~isempty(iv) -% if length(iv)>1 -% % boxplot(SAtadj(iv,:),'whis',3,'symbol','r.'); -% myboxplot(SAtadj(iv,:),[],'.',[],3) -% else -% plot(SAtadj(iv,:),'r.'); -% end -% set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) -% set(gca,'xlim',[0.5 np+0.5]) -% ydum = get(gca,'ylim'); -% set(gca,'ylim',[0 ydum(2)]) -% for ip=1:np, -% text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') -% end -% xlabel(' ') -% end -% title(options_.varobs(j,:),'interpreter','none') -% if mod(j,6)==0 | j==size(options_.varobs,1) -% saveas(gcf,[OutputDirectoryName,'/',fname_,'_morris_tadj_varobs_',int2str(ifig)]) -% eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_morris_tadj_varobs_',int2str(ifig)]); -% eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_morris_tadj_varobs_',int2str(ifig)]); -% close(gcf), -% end -% end + % ifig = 0; + % for j=1:size(options_.varobs,1) + % if mod(j,6)==1 + % figure('name',['EET speed of adjustment observed variables']); + % ifig=ifig+1; + % iplo=0; + % end + % iplo=iplo+1; + % subplot(3,2,iplo) + % iv = find(ir_tadj==j); + % if ~isempty(iv) + % if length(iv)>1 + % % boxplot(SAtadj(iv,:),'whis',3,'symbol','r.'); + % myboxplot(SAtadj(iv,:),[],'.',[],3) + % else + % plot(SAtadj(iv,:),'r.'); + % end + % set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) + % set(gca,'xlim',[0.5 np+0.5]) + % ydum = get(gca,'ylim'); + % set(gca,'ylim',[0 ydum(2)]) + % for ip=1:np, + % text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') + % end + % xlabel(' ') + % end + % title(options_.varobs(j,:),'interpreter','none') + % if mod(j,6)==0 | j==size(options_.varobs,1) + % saveas(gcf,[OutputDirectoryName,'/',fname_,'_morris_tadj_varobs_',int2str(ifig)]) + % eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_morris_tadj_varobs_',int2str(ifig)]); + % eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_morris_tadj_varobs_',int2str(ifig)]); + % close(gcf), + % end + % end -% ifig = 0; -% for j=1:M_.exo_nbr, -% if mod(j,6)==1 -% figure('name',['EET speed of adjustment shocks']); -% ifig=ifig+1; -% iplo=0; -% end -% iplo=iplo+1; -% subplot(3,2,iplo) -% iv = find(ic_tadj==j); -% if ~isempty(iv) -% if length(iv)>1 -% % boxplot(SAtadj(iv,:),'whis',3,'symbol','r.'); -% myboxplot(SAtadj(iv,:),[],'.',[],3) -% else -% plot(SAtadj(iv,:),'r.'); -% end -% set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) -% set(gca,'xlim',[0.5 np+0.5]) -% ydum = get(gca,'ylim'); -% set(gca,'ylim',[0 ydum(2)]) -% for ip=1:np, -% text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') -% end -% xlabel(' ') -% end -% title(M_.exo_names(j,:),'interpreter','none') -% if mod(j,6)==0 | j==M_.exo_nbr, -% saveas(gcf,[OutputDirectoryName,'/',fname_,'_morris_tadj_exo_',int2str(ifig)]) -% eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_morris_tadj_exo_',int2str(ifig)]); -% eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_morris_tadj_exo_',int2str(ifig)]); -% close(gcf), -% end -% end + % ifig = 0; + % for j=1:M_.exo_nbr, + % if mod(j,6)==1 + % figure('name',['EET speed of adjustment shocks']); + % ifig=ifig+1; + % iplo=0; + % end + % iplo=iplo+1; + % subplot(3,2,iplo) + % iv = find(ic_tadj==j); + % if ~isempty(iv) + % if length(iv)>1 + % % boxplot(SAtadj(iv,:),'whis',3,'symbol','r.'); + % myboxplot(SAtadj(iv,:),[],'.',[],3) + % else + % plot(SAtadj(iv,:),'r.'); + % end + % set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) + % set(gca,'xlim',[0.5 np+0.5]) + % ydum = get(gca,'ylim'); + % set(gca,'ylim',[0 ydum(2)]) + % for ip=1:np, + % text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') + % end + % xlabel(' ') + % end + % title(M_.exo_names(j,:),'interpreter','none') + % if mod(j,6)==0 | j==M_.exo_nbr, + % saveas(gcf,[OutputDirectoryName,'/',fname_,'_morris_tadj_exo_',int2str(ifig)]) + % eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_morris_tadj_exo_',int2str(ifig)]); + % eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_morris_tadj_exo_',int2str(ifig)]); + % close(gcf), + % end + % end -% figure, -% %bar(SAIF), -% % boxplot(SAIF,'whis',10,'symbol','r.') -% myboxplot(SAIF,[],'.',[],10) -% set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) -% set(gca,'xlim',[0.5 np+0.5]) -% set(gca,'ylim',[0 1]) -% set(gca,'position',[0.13 0.2 0.775 0.7]) -% for ip=1:np, -% text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') -% end -% xlabel(' ') -% ylabel('Elementary Effects') -% title('Steady state gains (impact factors)') -% saveas(gcf,[OutputDirectoryName,'/',fname_,'_morris_gain']) -% eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_morris_gain']); -% eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_morris_gain']); -% close(gcf), - %figure, bar(SAIF'), title('All Gain Relationships') -% ifig = 0; -% for j=1:size(options_.varobs,1) -% if mod(j,6)==1 -% figure('name',['EET steady state gain observed series']); -% ifig=ifig+1; -% iplo=0; -% end -% iplo=iplo+1; -% subplot(3,2,iplo) -% iv = find(ir_if==j); -% if ~isempty(iv) -% if length(iv)>1 -% % boxplot(SAIF(iv,:),'whis',10,'symbol','r.'); -% myboxplot(SAIF(iv,:),[],'.',[],10) -% else -% plot(SAIF(iv,:),'r.'); -% end -% set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) -% set(gca,'xlim',[0.5 np+0.5]) -% ydum = get(gca,'ylim'); -% set(gca,'ylim',[0 ydum(2)]) -% for ip=1:np, -% text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') -% end -% xlabel(' ') -% end -% title(options_.varobs(j,:),'interpreter','none') -% if mod(j,6)==0 | j==size(options_.varobs,1) -% saveas(gcf,[OutputDirectoryName,'/',fname_,'_morris_gain_varobs_',int2str(ifig)]) -% eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_morris_gain_varobs_',int2str(ifig)]); -% eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_morris_gain_varobs_',int2str(ifig)]); -% close(gcf), -% end -% end -% -% ifig = 0; -% for j=1:M_.exo_nbr, -% if mod(j,6)==1 -% figure('name',['EET steady state gain shocks']); -% ifig=ifig+1; -% iplo=0; -% end -% iplo=iplo+1; -% subplot(3,2,iplo) -% iv = find(ic_if==j); -% if ~isempty(iv) -% if length(iv)>1 -% % boxplot(SAIF(iv,:),'whis',3,'symbol','r.'); -% myboxplot(SAIF(iv,:),[],'.',[],3) -% else -% plot(SAIF(iv,:),'r.'); -% end -% set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) -% set(gca,'xlim',[0.5 np+0.5]) -% ydum = get(gca,'ylim'); -% set(gca,'ylim',[0 ydum(2)]) -% for ip=1:np, -% text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') -% end -% xlabel(' ') -% end -% title(M_.exo_names(j,:),'interpreter','none') -% if mod(j,6)==0 | j==M_.exo_nbr, -% saveas(gcf,[OutputDirectoryName,'/',fname_,'_morris_gain_exo_',int2str(ifig)]) -% eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_morris_gain_exo_',int2str(ifig)]); -% eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_morris_gain_exo_',int2str(ifig)]); -% close(gcf), -% end -% end + % figure, + % %bar(SAIF), + % % boxplot(SAIF,'whis',10,'symbol','r.') + % myboxplot(SAIF,[],'.',[],10) + % set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) + % set(gca,'xlim',[0.5 np+0.5]) + % set(gca,'ylim',[0 1]) + % set(gca,'position',[0.13 0.2 0.775 0.7]) + % for ip=1:np, + % text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') + % end + % xlabel(' ') + % ylabel('Elementary Effects') + % title('Steady state gains (impact factors)') + % saveas(gcf,[OutputDirectoryName,'/',fname_,'_morris_gain']) + % eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_morris_gain']); + % eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_morris_gain']); + % close(gcf), + %figure, bar(SAIF'), title('All Gain Relationships') + % ifig = 0; + % for j=1:size(options_.varobs,1) + % if mod(j,6)==1 + % figure('name',['EET steady state gain observed series']); + % ifig=ifig+1; + % iplo=0; + % end + % iplo=iplo+1; + % subplot(3,2,iplo) + % iv = find(ir_if==j); + % if ~isempty(iv) + % if length(iv)>1 + % % boxplot(SAIF(iv,:),'whis',10,'symbol','r.'); + % myboxplot(SAIF(iv,:),[],'.',[],10) + % else + % plot(SAIF(iv,:),'r.'); + % end + % set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) + % set(gca,'xlim',[0.5 np+0.5]) + % ydum = get(gca,'ylim'); + % set(gca,'ylim',[0 ydum(2)]) + % for ip=1:np, + % text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') + % end + % xlabel(' ') + % end + % title(options_.varobs(j,:),'interpreter','none') + % if mod(j,6)==0 | j==size(options_.varobs,1) + % saveas(gcf,[OutputDirectoryName,'/',fname_,'_morris_gain_varobs_',int2str(ifig)]) + % eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_morris_gain_varobs_',int2str(ifig)]); + % eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_morris_gain_varobs_',int2str(ifig)]); + % close(gcf), + % end + % end + % + % ifig = 0; + % for j=1:M_.exo_nbr, + % if mod(j,6)==1 + % figure('name',['EET steady state gain shocks']); + % ifig=ifig+1; + % iplo=0; + % end + % iplo=iplo+1; + % subplot(3,2,iplo) + % iv = find(ic_if==j); + % if ~isempty(iv) + % if length(iv)>1 + % % boxplot(SAIF(iv,:),'whis',3,'symbol','r.'); + % myboxplot(SAIF(iv,:),[],'.',[],3) + % else + % plot(SAIF(iv,:),'r.'); + % end + % set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) + % set(gca,'xlim',[0.5 np+0.5]) + % ydum = get(gca,'ylim'); + % set(gca,'ylim',[0 ydum(2)]) + % for ip=1:np, + % text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') + % end + % xlabel(' ') + % end + % title(M_.exo_names(j,:),'interpreter','none') + % if mod(j,6)==0 | j==M_.exo_nbr, + % saveas(gcf,[OutputDirectoryName,'/',fname_,'_morris_gain_exo_',int2str(ifig)]) + % eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_morris_gain_exo_',int2str(ifig)]); + % eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_morris_gain_exo_',int2str(ifig)]); + % close(gcf), + % end + % end - if opt_gsa.load_ident_files==0, - SAMorris = []; - for j=1:j0, - [SAmeas, SAMorris(:,:,j)] = Morris_Measure_Groups(npT, [lpmat0 lpmat], yt(:,j),nliv); - end + if opt_gsa.load_ident_files==0, + SAMorris = []; + for j=1:j0, + [SAmeas, SAMorris(:,:,j)] = Morris_Measure_Groups(npT, [lpmat0 lpmat], yt(:,j),nliv); + end -% SAM = squeeze(SAMorris(nshock+1:end,1,:)); - SAM = squeeze(SAMorris(1:end,1,:)); - for j=1:j0 - SAnorm(:,j)=SAM(:,j)./max(SAM(:,j)); - irex(j)=length(find(SAnorm(:,j)>0.01)); - end - [dum, irel]=sort(irex); + % SAM = squeeze(SAMorris(nshock+1:end,1,:)); + SAM = squeeze(SAMorris(1:end,1,:)); + for j=1:j0 + SAnorm(:,j)=SAM(:,j)./max(SAM(:,j)); + irex(j)=length(find(SAnorm(:,j)>0.01)); + end + [dum, irel]=sort(irex); -% SAMmu = squeeze(SAMorris(nshock+1:end,2,:)); - SAMmu = squeeze(SAMorris(1:end,2,:)); - for j=1:j0 - SAmunorm(:,j)=SAMmu(:,j)./max(SAM(:,j)); % normalised w.r.t. mu* - end -% SAMsig = squeeze(SAMorris(nshock+1:end,3,:)); - SAMsig = squeeze(SAMorris(1:end,3,:)); - for j=1:j0 - SAsignorm(:,j)=SAMsig(:,j)./max(SAMsig(:,j)); - end - save([OutputDirectoryName,'/',fname_,'_morris_IDE.mat'],'SAnorm','SAmunorm','SAsignorm','-append') - else - load([OutputDirectoryName,'/',fname_,'_morris_IDE'],'SAnorm','SAmunorm','SAsignorm') - end - hh=dyn_figure(options_.nodisplay,'name','Screening identification: model'); %bar(SAnorm(:,irel)) -% boxplot(SAnorm','whis',10,'symbol','r.') - myboxplot(SAnorm',[],'.',[],10) - set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:npT]) - set(gca,'xlim',[0.5 npT+0.5]) - set(gca,'ylim',[0 1]) - set(gca,'position',[0.13 0.2 0.775 0.7]) - xlabel(' ') - for ip=1:npT, -% text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') - text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') - end - xlabel(' ') - title('Elementary effects in the model') - dyn_saveas(hh,[OutputDirectoryName,'/',fname_,'_morris_par'],options_.nodisplay,options_.graph_format); - create_TeX_loader(options_,[OutputDirectoryName,'/',fname_,'_morris_par'],1,'Screening identification: model','morris_par',1) + % SAMmu = squeeze(SAMorris(nshock+1:end,2,:)); + SAMmu = squeeze(SAMorris(1:end,2,:)); + for j=1:j0 + SAmunorm(:,j)=SAMmu(:,j)./max(SAM(:,j)); % normalised w.r.t. mu* + end + % SAMsig = squeeze(SAMorris(nshock+1:end,3,:)); + SAMsig = squeeze(SAMorris(1:end,3,:)); + for j=1:j0 + SAsignorm(:,j)=SAMsig(:,j)./max(SAMsig(:,j)); + end + save([OutputDirectoryName,'/',fname_,'_morris_IDE.mat'],'SAnorm','SAmunorm','SAsignorm','-append') + else + load([OutputDirectoryName,'/',fname_,'_morris_IDE'],'SAnorm','SAmunorm','SAsignorm') + end + hh=dyn_figure(options_.nodisplay,'name','Screening identification: model'); %bar(SAnorm(:,irel)) + % boxplot(SAnorm','whis',10,'symbol','r.') + myboxplot(SAnorm',[],'.',[],10) + set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:npT]) + set(gca,'xlim',[0.5 npT+0.5]) + set(gca,'ylim',[0 1]) + set(gca,'position',[0.13 0.2 0.775 0.7]) + xlabel(' ') + for ip=1:npT, + % text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') + text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') + end + xlabel(' ') + title('Elementary effects in the model') + dyn_saveas(hh,[OutputDirectoryName,'/',fname_,'_morris_par'],options_.nodisplay,options_.graph_format); + create_TeX_loader(options_,[OutputDirectoryName,'/',fname_,'_morris_par'],1,'Screening identification: model','morris_par',1) -% hh=dyn_figure(options_.nodisplay); %bar(SAmunorm(:,irel)) -% % boxplot(SAmunorm','whis',10,'symbol','r.') -% myboxplot(SAmunorm',[],'.',[],10) -% set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:npT]) -% set(gca,'xlim',[0.5 npT+0.5]) -% set(gca,'ylim',[-1 1]) -% set(gca,'position',[0.13 0.2 0.775 0.7]) -% xlabel(' ') -% for ip=1:npT, -% text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') -% end -% xlabel(' ') -% title('\mu in the model') -% dyn_saveas(hh,[OutputDirectoryName,'/',fname_,'_morrismu_par'],options_.nodisplay,options_.graph_format); -% -% hh=dyn_figure(options_.nodisplay); %bar(SAsignorm(:,irel)) -% % boxplot(SAsignorm','whis',10,'symbol','r.') -% myboxplot(SAsignorm',[],'.',[],10) -% set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:npT]) -% set(gca,'xlim',[0.5 npT+0.5]) -% set(gca,'ylim',[0 1]) -% set(gca,'position',[0.13 0.2 0.775 0.7]) -% xlabel(' ') -% for ip=1:npT, -% text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') -% end -% xlabel(' ') -% title('\sigma in the model') -% dyn_saveas(hh,[OutputDirectoryName,'/',fname_,'_morrissig_par'],options_.nodisplay,options_.graph_format); + % hh=dyn_figure(options_.nodisplay); %bar(SAmunorm(:,irel)) + % % boxplot(SAmunorm','whis',10,'symbol','r.') + % myboxplot(SAmunorm',[],'.',[],10) + % set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:npT]) + % set(gca,'xlim',[0.5 npT+0.5]) + % set(gca,'ylim',[-1 1]) + % set(gca,'position',[0.13 0.2 0.775 0.7]) + % xlabel(' ') + % for ip=1:npT, + % text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') + % end + % xlabel(' ') + % title('\mu in the model') + % dyn_saveas(hh,[OutputDirectoryName,'/',fname_,'_morrismu_par'],options_.nodisplay,options_.graph_format); + % + % hh=dyn_figure(options_.nodisplay); %bar(SAsignorm(:,irel)) + % % boxplot(SAsignorm','whis',10,'symbol','r.') + % myboxplot(SAsignorm',[],'.',[],10) + % set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:npT]) + % set(gca,'xlim',[0.5 npT+0.5]) + % set(gca,'ylim',[0 1]) + % set(gca,'position',[0.13 0.2 0.775 0.7]) + % xlabel(' ') + % for ip=1:npT, + % text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') + % end + % xlabel(' ') + % title('\sigma in the model') + % dyn_saveas(hh,[OutputDirectoryName,'/',fname_,'_morrissig_par'],options_.nodisplay,options_.graph_format); - % figure, bar(SAnorm(:,irel)') - % set(gca,'xtick',[1:j0]) - % set(gca,'xlim',[0.5 j0+0.5]) - % title('Elementary effects relationships') - % saveas(gcf,[OutputDirectoryName,'/',fname_,'_morris_redform']) - % eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_morris_redform']); - % eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_morris_redform']); + % figure, bar(SAnorm(:,irel)') + % set(gca,'xtick',[1:j0]) + % set(gca,'xlim',[0.5 j0+0.5]) + % title('Elementary effects relationships') + % saveas(gcf,[OutputDirectoryName,'/',fname_,'_morris_redform']) + % eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_morris_redform']); + % eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_morris_redform']); elseif opt_gsa.morris==3, return - np=estim_params_.np; - na=(4*np+1)*opt_gsa.Nsam; - for j=1:j0, - [idex(j,:), yd(j,:)] = spop_ide(lpmat, yt(:,j), opt_gsa.Nsam, 5-1); - end - iok=find(~isnan(yt(1:opt_gsa.Nsam,1))); - yr=NaN*ones(size(lpmat,1),j0); - for j=1:j0, - ys(j,:)=yd(j,:)./max(yd(j,:)); - [dum, is]=sort(yt(iok,j)); - yr(iok(is),j)=[1:length(iok)]'./length(iok); - yr(istable(length(iok)+1:end),j) = interp1(yt(iok,j),yr(iok,j),yt(istable(length(iok)+1:end),j),'','extrap'); - ineg=find(yr(:,j)<0); - if any(ineg), - [dum, is]=sort(yr(ineg,j)); - yr(ineg(is),j)=-[length(ineg):-1:1]./length(iok); - + np=estim_params_.np; + na=(4*np+1)*opt_gsa.Nsam; + for j=1:j0, + [idex(j,:), yd(j,:)] = spop_ide(lpmat, yt(:,j), opt_gsa.Nsam, 5-1); end - [idex_r(j,:), yd_r(j,:)] = spop_ide(lpmat, yr(:,j), opt_gsa.Nsam, 5-1); - ys_r(j,:)=yd_r(j,:)./max(yd_r(j,:)); + iok=find(~isnan(yt(1:opt_gsa.Nsam,1))); + yr=NaN*ones(size(lpmat,1),j0); + for j=1:j0, + ys(j,:)=yd(j,:)./max(yd(j,:)); + [dum, is]=sort(yt(iok,j)); + yr(iok(is),j)=[1:length(iok)]'./length(iok); + yr(istable(length(iok)+1:end),j) = interp1(yt(iok,j),yr(iok,j),yt(istable(length(iok)+1:end),j),'','extrap'); + ineg=find(yr(:,j)<0); + if any(ineg), + [dum, is]=sort(yr(ineg,j)); + yr(ineg(is),j)=-[length(ineg):-1:1]./length(iok); + + end + [idex_r(j,:), yd_r(j,:)] = spop_ide(lpmat, yr(:,j), opt_gsa.Nsam, 5-1); + ys_r(j,:)=yd_r(j,:)./max(yd_r(j,:)); - end, - figure, bar((idex.*ys)./opt_gsa.Nsam), title('Relationships') - figure, bar((idex.*ys)'./opt_gsa.Nsam), title('Parameters') - figure, bar((idex_r.*ys_r)./opt_gsa.Nsam), title('Relationships rank') - figure, bar((idex_r.*ys_r)'./opt_gsa.Nsam), title('Parameters rank') - [v0,d0]=eig(corrcoef(yt(iok,:))); - ee=diag(d0); - ee=ee([end:-1:1])./j0; - i0=length(find(ee>0.01)); - v0=v0(:,[end:-1:1]); - for j=1:i0, - [idex_pc(j,:), yd_pc(j,:)] = spop_ide(lpmat, yt*v0(:,j), opt_gsa.Nsam, 5-1); - end - for j=1:i0, - ys_pc(j,:)=yd_pc(j,:)./max(yd_pc(j,:)); - end, - figure, bar((idex_pc.*ys_pc)./opt_gsa.Nsam), title('Relationships PCA') - figure, bar((idex_pc.*ys_pc)'./opt_gsa.Nsam), title('Parameters PCA') + end, + figure, bar((idex.*ys)./opt_gsa.Nsam), title('Relationships') + figure, bar((idex.*ys)'./opt_gsa.Nsam), title('Parameters') + figure, bar((idex_r.*ys_r)./opt_gsa.Nsam), title('Relationships rank') + figure, bar((idex_r.*ys_r)'./opt_gsa.Nsam), title('Parameters rank') + [v0,d0]=eig(corrcoef(yt(iok,:))); + ee=diag(d0); + ee=ee([end:-1:1])./j0; + i0=length(find(ee>0.01)); + v0=v0(:,[end:-1:1]); + for j=1:i0, + [idex_pc(j,:), yd_pc(j,:)] = spop_ide(lpmat, yt*v0(:,j), opt_gsa.Nsam, 5-1); + end + for j=1:i0, + ys_pc(j,:)=yd_pc(j,:)./max(yd_pc(j,:)); + end, + figure, bar((idex_pc.*ys_pc)./opt_gsa.Nsam), title('Relationships PCA') + figure, bar((idex_pc.*ys_pc)'./opt_gsa.Nsam), title('Parameters PCA') - [vr,dr]=eig(corrcoef(yr(iok,:))); - er=diag(dr); - er=er([end:-1:1])./j0; - ir0=length(find(er>0.01)); - vr=vr(:,[end:-1:1]); - for j=1:ir0, - [idex_pcr(j,:), yd_pcr(j,:)] = spop_ide(lpmat, yr*vr(:,j), opt_gsa.Nsam, 5-1); - end - for j=1:ir0, - ys_pcr(j,:)=yd_pcr(j,:)./max(yd_pcr(j,:)); - end, - figure, bar((idex_pcr.*ys_pcr)./opt_gsa.Nsam), title('Relationships rank PCA') - figure, bar((idex_pcr.*ys_pcr)'./opt_gsa.Nsam), title('Parameters rank PCA') - + [vr,dr]=eig(corrcoef(yr(iok,:))); + er=diag(dr); + er=er([end:-1:1])./j0; + ir0=length(find(er>0.01)); + vr=vr(:,[end:-1:1]); + for j=1:ir0, + [idex_pcr(j,:), yd_pcr(j,:)] = spop_ide(lpmat, yr*vr(:,j), opt_gsa.Nsam, 5-1); + end + for j=1:ir0, + ys_pcr(j,:)=yd_pcr(j,:)./max(yd_pcr(j,:)); + end, + figure, bar((idex_pcr.*ys_pcr)./opt_gsa.Nsam), title('Relationships rank PCA') + figure, bar((idex_pcr.*ys_pcr)'./opt_gsa.Nsam), title('Parameters rank PCA') + elseif opt_gsa.morris==2, % ISKREV staff - return, + return, - + else, % main effects analysis - - if itrans==0, - fsuffix = ''; - elseif itrans==1, - fsuffix = '_log'; - else - fsuffix = '_rank'; - end - - imap=[1:npT]; - - if isempty(lpmat0), - x0=lpmat(istable,:); - else - - x0=[lpmat0(istable,:), lpmat(istable,:)]; - end - nrun=length(istable); - nest=min(250,nrun); - nfit=min(1000,nrun); - -% opt_gsa.load_ident_files=0; - -% if opt_gsa.load_ident_files==0, -% try -% EET=load([OutputDirectoryName,'/SCREEN/',fname_,'_morris_IDE'],'SAvdec','vdec','ir_vdec','ic_vdec'); -% catch -% EET=[]; -% end -% SAvdec=zeros(size(vdec,2),npT); -% -% for j=1:size(vdec,2), -% if itrans==0, -% y0 = vdec(istable,j); -% elseif itrans==1, -% y0 = log_trans_(vdec(istable,j)); -% else -% y0 = trank(vdec(istable,j)); -% end -% if ~isempty(EET), -% % imap=find(EET.SAvdec(j,:)); -% % [dum, isort]=sort(-EET.SAvdec(j,:)); -% imap=find(EET.SAvdec(j,:) >= (0.1.*max(EET.SAvdec(j,:))) ); -% end -% gsa_(j) = gsa_sdp(y0(1:nest), x0(1:nest,imap), ... -% 2, [],[],[],0,[OutputDirectoryName,'/map_vdec',fsuffix,int2str(j)], pnames); -% if nfit>nest, -% gsa_(j) = gsa_sdp(y0(1:nfit), x0(1:nfit,imap), ... -% -2, gsa_(j).nvr*nest^3/nfit^3,[],[],0,[OutputDirectoryName,'/map_vdec',fsuffix,int2str(j)], pnames); -% end -% -% SAvdec(j,imap)=gsa_(j).si; -% imap_vdec{j}=imap; -% end -% save([OutputDirectoryName,'/',fname_,'_main_eff'],'imap_vdec','SAvdec','vdec','ir_vdec','ic_vdec','-append') -% else -% load([OutputDirectoryName,'/',fname_,'_main_eff'],'imap_vdec','SAvdec','vdec','ir_vdec','ic_vdec') -% end -% figure, -% % boxplot(SAvdec,'whis',10,'symbol','r.') -% myboxplot(SAvdec,[],'.',[],10) -% set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) -% set(gca,'xlim',[0.5 npT+0.5]) -% ydum = get(gca,'ylim'); -% set(gca,'ylim',[0 ydum(2)]) -% set(gca,'position',[0.13 0.2 0.775 0.7]) -% for ip=1:npT, -% text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') -% % text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') -% end -% xlabel(' ') -% title(['Main effects variance decomposition ',fsuffix],'interpreter','none') -% saveas(gcf,[OutputDirectoryName,'/',fname_,'_map_vdec',fsuffix]) -% eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_map_vdec',fsuffix]); -% eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_map_vdec',fsuffix]); -% close(gcf), -% -% ifig = 0; -% for j=1:size(options_.varobs,1) -% if mod(j,6)==1 -% figure('name',['Main effects observed variance decomposition ',fsuffix]); -% ifig=ifig+1; -% iplo=0; -% end -% iplo=iplo+1; -% subplot(3,2,iplo) -% iv = find(ir_vdec==j); -% if ~isempty(iv) -% if length(iv)>1 -% % boxplot(SAvdec(iv,:),'whis',10,'symbol','r.'); -% myboxplot(SAvdec(iv,:),[],'.',[],10) -% else -% plot(SAvdec(iv,:),'r.'); -% end -% set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) -% set(gca,'xlim',[0.5 npT+0.5]) -% ydum = get(gca,'ylim'); -% set(gca,'ylim',[0 ydum(2)]) -% for ip=1:npT, -% text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') -% % text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') -% end -% xlabel(' ') -% end -% title(options_.varobs(j,:),'interpreter','none') -% if mod(j,6)==0 | j==size(options_.varobs,1) -% saveas(gcf,[OutputDirectoryName,'/',fname_,'_map_vdec',fsuffix,'_varobs_',int2str(ifig)]) -% eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_map_vdec',fsuffix,'_varobs_',int2str(ifig)]); -% eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_map_vdec',fsuffix,'_varobs_',int2str(ifig)]); -% close(gcf), -% end -% end -% -% ifig = 0; -% for j=1:M_.exo_nbr, -% if mod(j,6)==1 -% figure('name',['Main effects shocks variance decomposition ',fsuffix]); -% ifig=ifig+1; -% iplo=0; -% end -% iplo=iplo+1; -% subplot(3,2,iplo) -% iv = find(ic_vdec==j); -% if ~isempty(iv) -% if length(iv)>1 -% % boxplot(SAvdec(iv,:),'whis',3,'symbol','r.'); -% myboxplot(SAvdec(iv,:),[],'.',[],10) -% else -% plot(SAvdec(iv,:),'r.'); -% end -% set(gca,'xticklabel',' ','fontsize',3,'xtick',[1:np]) -% set(gca,'xlim',[0.5 npT+0.5]) -% ydum = get(gca,'ylim'); -% set(gca,'ylim',[0 ydum(2)]) -% for ip=1:npT, -% text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') -% % text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') -% end -% xlabel(' ') -% set(gca,'fontsize',10) -% end -% title(M_.exo_names(j,:),'interpreter','none','fontsize',10) -% if mod(j,6)==0 | j==M_.exo_nbr -% saveas(gcf,[OutputDirectoryName,'/',fname_,'_map_vdec',fsuffix,'_exo_',int2str(ifig)]) -% eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_map_vdec',fsuffix,'_exo_',int2str(ifig)]); -% eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_map_vdec',fsuffix,'_exo_',int2str(ifig)]); -% close(gcf), -% end -% end - - if opt_gsa.load_ident_files==0, - try - EET=load([OutputDirectoryName,'/SCREEN/',fname_,'_morris_IDE'],'SAcc','ir_cc','ic_cc'); - catch - EET=[]; - end - ccac = stand_([mss cc ac]); - [pcc, dd] = eig(cov(ccac(istable,:))); - [latent, isort] = sort(-diag(dd)); - latent = -latent; - figure, bar(latent) - title('Eigenvalues in PCA') - pcc=pcc(:,isort); - ccac = ccac*pcc; -% npca = min(40, max(find(cumsum(latent)./length(latent)<0.99))+1); - npca = max(find(cumsum(latent)./length(latent)<0.99))+1; - siPCA = (EET.SAcc'*abs(pcc'))'; -% siPCA = siPCA./(max(siPCA')'*ones(1,npT)).*(latent*ones(1,npT)); - siPCA = siPCA./(max(siPCA')'*ones(1,npT)); -% siPCA = sum(siPCA,1); -% siPCA = siPCA./max(siPCA); - SAcc=zeros(size(ccac,2),npT); - for j=1:npca, %size(ccac,2), + if itrans==0, - y0 = ccac(istable,j); + fsuffix = ''; elseif itrans==1, - y0 = log_trans_(ccac(istable,j)); + fsuffix = '_log'; else - y0 = trank(ccac(istable,j)); - end - if ~isempty(EET), -% imap=find(EET.SAvdec(j,:)); -% [dum, isort]=sort(-EET.SAvdec(j,:)); - imap=find(siPCA(j,:) >= (0.1.*max(siPCA(j,:))) ); -% imap=find(EET.SAcc(j,:) >= (0.1.*max(EET.SAcc(j,:))) ); + fsuffix = '_rank'; end - gsa_(j) = gsa_sdp(y0(1:nest), x0(1:nest,imap), ... - 2, [],[],[],0,[OutputDirectoryName,'/map_cc',fsuffix,int2str(j)], pnames); -% if nfit>nest, -% gsa_(j) = gsa_sdp(y0(1:nfit), x0(1:nfit,imap), ... -% -2, gsa_(j).nvr*nest^3/nfit^3,[],[],0,[OutputDirectoryName,'/map_cc',fsuffix,int2str(j)], pnames); -% end - SAcc(j,imap)=gsa_(j).si; - imap_cc{j}=imap; + + imap=[1:npT]; - end - save([OutputDirectoryName,'/map_cc',fsuffix,'.mat'],'gsa_') - save([OutputDirectoryName,'/',fname_,'_main_eff.mat'],'imap_cc','SAcc','ccac','-append') - else - load([OutputDirectoryName,'/',fname_,'_main_eff'],'imap_cc','SAcc','ccac') + if isempty(lpmat0), + x0=lpmat(istable,:); + else + + x0=[lpmat0(istable,:), lpmat(istable,:)]; + end + nrun=length(istable); + nest=min(250,nrun); + nfit=min(1000,nrun); - end -% figure, -% % boxplot(SAcc,'whis',10,'symbol','r.') -% myboxplot(SAcc,[],'.',[],10) -% set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) -% set(gca,'xlim',[0.5 npT+0.5]) -% ydum = get(gca,'ylim'); -% set(gca,'ylim',[0 ydum(2)]) -% set(gca,'position',[0.13 0.2 0.775 0.7]) -% for ip=1:npT, -% text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') -% % text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') -% end -% xlabel(' ') -% ylabel(' ') -% title(['Main effects moments''s PCA ',fsuffix],'interpreter','none') -% saveas(gcf,[OutputDirectoryName,'/',fname_,'_map_cc',fsuffix]) -% eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_map_moments',fsuffix]); -% eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_map_moments',fsuffix]); -% close(gcf), + % opt_gsa.load_ident_files=0; + + % if opt_gsa.load_ident_files==0, + % try + % EET=load([OutputDirectoryName,'/SCREEN/',fname_,'_morris_IDE'],'SAvdec','vdec','ir_vdec','ic_vdec'); + % catch + % EET=[]; + % end + % SAvdec=zeros(size(vdec,2),npT); + % + % for j=1:size(vdec,2), + % if itrans==0, + % y0 = vdec(istable,j); + % elseif itrans==1, + % y0 = log_trans_(vdec(istable,j)); + % else + % y0 = trank(vdec(istable,j)); + % end + % if ~isempty(EET), + % % imap=find(EET.SAvdec(j,:)); + % % [dum, isort]=sort(-EET.SAvdec(j,:)); + % imap=find(EET.SAvdec(j,:) >= (0.1.*max(EET.SAvdec(j,:))) ); + % end + % gsa_(j) = gsa_sdp(y0(1:nest), x0(1:nest,imap), ... + % 2, [],[],[],0,[OutputDirectoryName,'/map_vdec',fsuffix,int2str(j)], pnames); + % if nfit>nest, + % gsa_(j) = gsa_sdp(y0(1:nfit), x0(1:nfit,imap), ... + % -2, gsa_(j).nvr*nest^3/nfit^3,[],[],0,[OutputDirectoryName,'/map_vdec',fsuffix,int2str(j)], pnames); + % end + % + % SAvdec(j,imap)=gsa_(j).si; + % imap_vdec{j}=imap; + % end + % save([OutputDirectoryName,'/',fname_,'_main_eff'],'imap_vdec','SAvdec','vdec','ir_vdec','ic_vdec','-append') + % else + % load([OutputDirectoryName,'/',fname_,'_main_eff'],'imap_vdec','SAvdec','vdec','ir_vdec','ic_vdec') + % end + % figure, + % % boxplot(SAvdec,'whis',10,'symbol','r.') + % myboxplot(SAvdec,[],'.',[],10) + % set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) + % set(gca,'xlim',[0.5 npT+0.5]) + % ydum = get(gca,'ylim'); + % set(gca,'ylim',[0 ydum(2)]) + % set(gca,'position',[0.13 0.2 0.775 0.7]) + % for ip=1:npT, + % text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') + % % text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') + % end + % xlabel(' ') + % title(['Main effects variance decomposition ',fsuffix],'interpreter','none') + % saveas(gcf,[OutputDirectoryName,'/',fname_,'_map_vdec',fsuffix]) + % eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_map_vdec',fsuffix]); + % eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_map_vdec',fsuffix]); + % close(gcf), + % + % ifig = 0; + % for j=1:size(options_.varobs,1) + % if mod(j,6)==1 + % figure('name',['Main effects observed variance decomposition ',fsuffix]); + % ifig=ifig+1; + % iplo=0; + % end + % iplo=iplo+1; + % subplot(3,2,iplo) + % iv = find(ir_vdec==j); + % if ~isempty(iv) + % if length(iv)>1 + % % boxplot(SAvdec(iv,:),'whis',10,'symbol','r.'); + % myboxplot(SAvdec(iv,:),[],'.',[],10) + % else + % plot(SAvdec(iv,:),'r.'); + % end + % set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) + % set(gca,'xlim',[0.5 npT+0.5]) + % ydum = get(gca,'ylim'); + % set(gca,'ylim',[0 ydum(2)]) + % for ip=1:npT, + % text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') + % % text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') + % end + % xlabel(' ') + % end + % title(options_.varobs(j,:),'interpreter','none') + % if mod(j,6)==0 | j==size(options_.varobs,1) + % saveas(gcf,[OutputDirectoryName,'/',fname_,'_map_vdec',fsuffix,'_varobs_',int2str(ifig)]) + % eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_map_vdec',fsuffix,'_varobs_',int2str(ifig)]); + % eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_map_vdec',fsuffix,'_varobs_',int2str(ifig)]); + % close(gcf), + % end + % end + % + % ifig = 0; + % for j=1:M_.exo_nbr, + % if mod(j,6)==1 + % figure('name',['Main effects shocks variance decomposition ',fsuffix]); + % ifig=ifig+1; + % iplo=0; + % end + % iplo=iplo+1; + % subplot(3,2,iplo) + % iv = find(ic_vdec==j); + % if ~isempty(iv) + % if length(iv)>1 + % % boxplot(SAvdec(iv,:),'whis',3,'symbol','r.'); + % myboxplot(SAvdec(iv,:),[],'.',[],10) + % else + % plot(SAvdec(iv,:),'r.'); + % end + % set(gca,'xticklabel',' ','fontsize',3,'xtick',[1:np]) + % set(gca,'xlim',[0.5 npT+0.5]) + % ydum = get(gca,'ylim'); + % set(gca,'ylim',[0 ydum(2)]) + % for ip=1:npT, + % text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') + % % text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') + % end + % xlabel(' ') + % set(gca,'fontsize',10) + % end + % title(M_.exo_names(j,:),'interpreter','none','fontsize',10) + % if mod(j,6)==0 | j==M_.exo_nbr + % saveas(gcf,[OutputDirectoryName,'/',fname_,'_map_vdec',fsuffix,'_exo_',int2str(ifig)]) + % eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_map_vdec',fsuffix,'_exo_',int2str(ifig)]); + % eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_map_vdec',fsuffix,'_exo_',int2str(ifig)]); + % close(gcf), + % end + % end -% ifig = 0; -% for j=1:size(options_.varobs,1) -% if mod(j,6)==1 -% figure('name',['Main effects cross-covariances ',fsuffix]); -% ifig=ifig+1; -% iplo=0; -% end -% iplo=iplo+1; -% subplot(3,2,iplo) -% iv = find(ir_cc==j); -% iv = [iv; find(ic_cc==j)]; -% if ~isempty(iv) -% if length(iv)>1 -% % boxplot(SAcc(iv,:),'whis',10,'symbol','r.'); -% myboxplot(SAcc(iv,:),[],'.',[],10) -% else -% plot(SAcc(iv,:),'r.'); -% end -% set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) -% set(gca,'xlim',[0.5 npT+0.5]) -% ydum = get(gca,'ylim'); -% set(gca,'ylim',[0 ydum(2)]) -% for ip=1:npT, -% text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') -% % text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') -% end -% xlabel(' ') -% set(gca,'fontsize',10) -% end -% title(options_.varobs(j,:),'interpreter','none','fontsize',10) -% if mod(j,6)==0 | j==size(options_.varobs,1) -% saveas(gcf,[OutputDirectoryName,'/',fname_,'_map_cc',fsuffix,'_',int2str(ifig)]) -% eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_map_cc',fsuffix,'_',int2str(ifig)]); -% eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_map_cc',fsuffix,'_',int2str(ifig)]); -% close(gcf), -% end -% end -% -% if opt_gsa.load_ident_files==0, -% try -% EET=load([OutputDirectoryName,'/SCREEN/',fname_,'_morris_IDE'],'SAac','ir_ac','ic_ac'); -% catch -% EET=[]; -% end -% SAac=zeros(size(ac,2),npT); -% for j=1:size(ac,2), -% if itrans==0, -% y0 = ac(istable,j); -% elseif itrans==1, -% y0 = log_trans_(ac(istable,j)); -% else -% y0 = trank(ac(istable,j)); -% end -% if ~isempty(EET), -% imap=find(EET.SAac(j,:) >= (0.1.*max(EET.SAac(j,:))) ); -% end -% % gsa_(j) = gsa_sdp_dyn( y0, lpmat(istable,:), ... -% % gsa_flag, [],[],[],0,[OutputDirectoryName,'/map_ac',fsuffix,int2str(j)], pnames); -% gsa_(j) = gsa_sdp(y0(1:nest), x0(1:nest,imap), ... -% 2, [],[],[],0,[OutputDirectoryName,'/map_ac',fsuffix,int2str(j)], pnames); -% if nfit>nest, -% gsa_(j) = gsa_sdp(y0(1:nfit), x0(1:nfit,imap), ... -% -2, gsa_(j).nvr*nest^3/nfit^3,[],[],0,[OutputDirectoryName,'/map_ac',fsuffix,int2str(j)], pnames); -% end -% SAac(j,imap)=gsa_(j).si; -% imap_ac{j}=imap; -% -% end -% save([OutputDirectoryName,'/',fname_,'_main_eff'],'imap_ac','SAac','ac','ir_ac','ic_ac','-append') -% else -% load([OutputDirectoryName,'/',fname_,'_main_eff'],'imap_ac','SAac','ac','ir_ac','ic_ac') -% end -% -% figure, -% % boxplot(SAac,'whis',10,'symbol','r.') -% myboxplot(SAac,[],'.',[],10) -% set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) -% set(gca,'xlim',[0.5 npT+0.5]) -% ydum = get(gca,'ylim'); -% set(gca,'ylim',[0 ydum(2)]) -% set(gca,'position',[0.13 0.2 0.775 0.7]) -% for ip=1:np, -% text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') -% end -% xlabel(' ') -% title(['Main effects 1 lag auto-covariances ',fsuffix],'interpreter','none') -% saveas(gcf,[OutputDirectoryName,'/',fname_,'_map_ac',fsuffix]) -% eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_map_ac',fsuffix]); -% eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_map_ac',fsuffix]); -% close(gcf), -% -% ifig = 0; -% for j=1:size(options_.varobs,1) -% if mod(j,6)==1 -% figure('name',['Main effects auto-covariances ',fsuffix]); -% ifig=ifig+1; -% iplo = 0; -% end -% iplo=iplo+1; -% subplot(3,2,iplo) -% iv = find(ir_ac==j); -% %iv = [iv; find(ic_ac==j)]; -% if ~isempty(iv) -% if length(iv)>1 -% % boxplot(SAac(iv,:),'whis',10,'symbol','r.'); -% myboxplot(SAac(iv,:),[],'.',[],10) -% else -% plot(SAac(iv,:),'r.'); -% end -% set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) -% set(gca,'xlim',[0.5 npT+0.5]) -% ydum = get(gca,'ylim'); -% set(gca,'ylim',[0 ydum(2)]) -% for ip=1:npT, -% text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') -% % text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') -% end -% xlabel(' ') -% set(gca,'fontsize',10) -% end -% title(options_.varobs(j,:),'interpreter','none','fontsize',10) -% if mod(j,6)==0 | j==size(options_.varobs,1) -% saveas(gcf,[OutputDirectoryName,'/',fname_,'_map_ac',fsuffix,'_',int2str(ifig)]) -% eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_map_ac',fsuffix,'_',int2str(ifig)]); -% eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_map_ac',fsuffix,'_',int2str(ifig)]); -% close(gcf), -% end -% end - -% x0=x0(:,nshock+1:end); - imap=[1:npT]; + if opt_gsa.load_ident_files==0, + try + EET=load([OutputDirectoryName,'/SCREEN/',fname_,'_morris_IDE'],'SAcc','ir_cc','ic_cc'); + catch + EET=[]; + end + ccac = stand_([mss cc ac]); + [pcc, dd] = eig(cov(ccac(istable,:))); + [latent, isort] = sort(-diag(dd)); + latent = -latent; + figure, bar(latent) + title('Eigenvalues in PCA') + pcc=pcc(:,isort); + ccac = ccac*pcc; + % npca = min(40, max(find(cumsum(latent)./length(latent)<0.99))+1); + npca = max(find(cumsum(latent)./length(latent)<0.99))+1; + siPCA = (EET.SAcc'*abs(pcc'))'; + % siPCA = siPCA./(max(siPCA')'*ones(1,npT)).*(latent*ones(1,npT)); + siPCA = siPCA./(max(siPCA')'*ones(1,npT)); + % siPCA = sum(siPCA,1); + % siPCA = siPCA./max(siPCA); + SAcc=zeros(size(ccac,2),npT); + for j=1:npca, %size(ccac,2), + if itrans==0, + y0 = ccac(istable,j); + elseif itrans==1, + y0 = log_trans_(ccac(istable,j)); + else + y0 = trank(ccac(istable,j)); + end + if ~isempty(EET), + % imap=find(EET.SAvdec(j,:)); + % [dum, isort]=sort(-EET.SAvdec(j,:)); + imap=find(siPCA(j,:) >= (0.1.*max(siPCA(j,:))) ); + % imap=find(EET.SAcc(j,:) >= (0.1.*max(EET.SAcc(j,:))) ); + end + gsa_(j) = gsa_sdp(y0(1:nest), x0(1:nest,imap), ... + 2, [],[],[],0,[OutputDirectoryName,'/map_cc',fsuffix,int2str(j)], pnames); + % if nfit>nest, + % gsa_(j) = gsa_sdp(y0(1:nfit), x0(1:nfit,imap), ... + % -2, gsa_(j).nvr*nest^3/nfit^3,[],[],0,[OutputDirectoryName,'/map_cc',fsuffix,int2str(j)], pnames); + % end + SAcc(j,imap)=gsa_(j).si; + imap_cc{j}=imap; -% if opt_gsa.load_ident_files==0, -% try -% EET=load([OutputDirectoryName,'/SCREEN/',fname_,'_morris_IDE'],'SAtadj','ir_tadj','ic_tadj'); -% ny=size(EET.SAtadj,1); -% catch -% EET=[]; -% end -% SAtadj=zeros(size(tadj,2),np); -% for j=1:size(tadj,2), -% if itrans==0, -% y0 = tadj(istable,j); -% elseif itrans==1, -% y0 = log_trans_(tadj(istable,j)); -% else -% y0 = trank(tadj(istable,j)); -% end -% if ~isempty(EET), -% if size(tadj,2)~=ny, -% jj=find(EET.ir_tadj==ir_tadj(j)); -% jj=jj(find(EET.ic_tadj(jj)==ic_tadj(j))); -% if ~isempty(jj), -% imap=find(EET.SAtadj(jj,:) >= (0.1.*max(EET.SAtadj(jj,:))) ); -% else -% imap=[1:np]; -% end -% else -% imap=find(EET.SAtadj(j,:) >= (0.1.*max(EET.SAtadj(j,:))) ); -% end -% end -% % gsa_(j) = gsa_sdp_dyn( y0, lpmat(istable,:), ... -% % gsa_flag, [],[],[],0,[OutputDirectoryName,'/map_tadj',fsuffix,int2str(j)], pnames); -% gsa_(j) = gsa_sdp(y0(1:nest), x0(1:nest,imap), ... -% 2, [],[],[],0,[OutputDirectoryName,'/map_tadj',fsuffix,int2str(j)], pnames); -% if nfit>nest, -% gsa_(j) = gsa_sdp(y0(1:nfit), x0(1:nfit,imap), ... -% -2, gsa_(j).nvr*nest^3/nfit^3,[],[],0,[OutputDirectoryName,'/map_tadj',fsuffix,int2str(j)], pnames); -% end -% SAtadj(j,imap)=gsa_(j).si; -% imap_tadj{j}=imap; -% -% end -% save([OutputDirectoryName,'/',fname_,'_main_eff'],'imap_tadj','SAtadj','tadj','ir_tadj','ic_tadj','-append') -% else -% load([OutputDirectoryName,'/',fname_,'_main_eff'],'imap_tadj','SAtadj','tadj','ir_tadj','ic_tadj') -% end -% -% figure, -% % boxplot(SAtadj,'whis',10,'symbol','r.') -% myboxplot(SAtadj,[],'.',[],10) -% set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) -% set(gca,'xlim',[0.5 np+0.5]) -% ydum = get(gca,'ylim'); -% set(gca,'ylim',[0 ydum(2)]) -% set(gca,'position',[0.13 0.2 0.775 0.7]) -% for ip=1:np, -% text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') -% end -% xlabel(' ') -% title(['Main effects speed of adjustment ',fsuffix],'interpreter','none') -% saveas(gcf,[OutputDirectoryName,'/',fname_,'_map_tadj',fsuffix]) -% eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_map_tadj',fsuffix]); -% eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_map_tadj',fsuffix]); -% close(gcf), -% -% ifig = 0; -% for j=1:size(options_.varobs,1) -% if mod(j,6)==1 -% figure('name',['Main effects observed speed adjustment ',fsuffix]); -% ifig=ifig+1; -% iplo = 0; -% end -% iplo=iplo+1; -% subplot(3,2,iplo) -% iv = find(ir_tadj==j); -% if ~isempty(iv) -% if length(iv)>1 -% % boxplot(SAtadj(iv,:),'whis',3,'symbol','r.'); -% myboxplot(SAtadj(iv,:),[],'.',[],10) -% else -% plot(SAtadj(iv,:),'r.'); -% end -% set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) -% set(gca,'xlim',[0.5 np+0.5]) -% ydum = get(gca,'ylim'); -% set(gca,'ylim',[0 ydum(2)]) -% for ip=1:np, -% text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') -% end -% xlabel(' ') -% end -% title(options_.varobs(j,:),'interpreter','none') -% if mod(j,6)==0 | j==size(options_.varobs,1) -% saveas(gcf,[OutputDirectoryName,'/',fname_,'_map_tadj',fsuffix,'_varobs_',int2str(ifig)]) -% eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_map_tadj',fsuffix,'_varobs_',int2str(ifig)]); -% eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_map_tadj',fsuffix,'_varobs_',int2str(ifig)]); -% close(gcf), -% end -% end -% -% ifig = 0; -% for j=1:M_.exo_nbr, -% if mod(j,6)==1 -% figure('name',['Main effects shocks speed of adjustment ',fsuffix]); -% ifig=ifig+1; -% iplo=0; -% end -% iplo=iplo+1; -% subplot(3,2,iplo) -% iv = find(ic_tadj==j); -% if ~isempty(iv) -% if length(iv)>1 -% % boxplot(SAtadj(iv,:),'whis',3,'symbol','r.'); -% myboxplot(SAtadj(iv,:),[],'.',[],10) -% else -% plot(SAtadj(iv,:),'r.'); -% end -% set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) -% set(gca,'xlim',[0.5 np+0.5]) -% ydum = get(gca,'ylim'); -% set(gca,'ylim',[0 ydum(2)]) -% for ip=1:np, -% text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') -% end -% xlabel(' ') -% end -% title(M_.exo_names(j,:),'interpreter','none') -% if mod(j,6)==0 | j==M_.exo_nbr, -% saveas(gcf,[OutputDirectoryName,'/',fname_,'_map_tadj',fsuffix,'_exo_',int2str(ifig)]) -% eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_map_tadj',fsuffix,'_exo_',int2str(ifig)]); -% eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_map_tadj',fsuffix,'_exo_',int2str(ifig)]); -% close(gcf), -% end -% end -% -% -% if opt_gsa.load_ident_files==0, -% try -% EET=load([OutputDirectoryName,'/SCREEN/',fname_,'_morris_IDE'],'SAIF','ir_if','ic_if'); -% catch -% EET=[]; -% end -% SAif=zeros(size(iff,2),np); -% for j=1:size(iff,2), -% if itrans==0, -% y0 = iff(istable,j); -% elseif itrans==1, -% y0 = log_trans_(iff(istable,j)); -% else -% y0 = trank(iff(istable,j)); -% end -% if ~isempty(EET), -% imap=find(EET.SAIF(j,:) >= (0.1.*max(EET.SAIF(j,:))) ); -% end -% % gsa_(j) = gsa_sdp_dyn( y0, lpmat(istable,:), ... -% % gsa_flag, [],[],[],0,[OutputDirectoryName,'/map_if',fsuffix,int2str(j)], pnames); -% gsa_(j) = gsa_sdp(y0(1:nest), x0(1:nest,imap), ... -% 2, [],[],[],0,[OutputDirectoryName,'/map_if',fsuffix,int2str(j)], pnames); -% if nfit>nest, -% gsa_(j) = gsa_sdp(y0(1:nfit), x0(1:nfit,imap), ... -% -2, gsa_(j).nvr*nest^3/nfit^3,[],[],0,[OutputDirectoryName,'/map_if',fsuffix,int2str(j)], pnames); -% end -% SAif(j,imap)=gsa_(j).si; -% imap_if{j}=imap; -% -% end -% save([OutputDirectoryName,'/',fname_,'_main_eff'],'imap_if','SAif','iff','ir_if','ic_if','-append') -% else -% load([OutputDirectoryName,'/',fname_,'_main_eff'],'imap_if','SAif','iff','ir_if','ic_if') -% end -% -% figure, -% % boxplot(SAif,'whis',10,'symbol','r.') -% myboxplot(SAif,[],'.',[],10) -% set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) -% set(gca,'xlim',[0.5 np+0.5]) -% ydum = get(gca,'ylim'); -% set(gca,'ylim',[0 ydum(2)]) -% set(gca,'position',[0.13 0.2 0.775 0.7]) -% for ip=1:np, -% text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') -% end -% xlabel(' ') -% title(['Main effects impact factors ',fsuffix],'interpreter','none') -% saveas(gcf,[OutputDirectoryName,'/',fname_,'_map_if',fsuffix]) -% eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_map_if',fsuffix]); -% eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_map_if',fsuffix]); -% close(gcf), -% -% ifig = 0; -% for j=1:size(options_.varobs,1) -% if mod(j,6)==1 -% figure('name',['Main effects observed impact factors ',fsuffix]); -% ifig=ifig+1; -% iplo = 0; -% end -% iplo=iplo+1; -% subplot(3,2,iplo) -% iv = find(ir_if==j); -% if ~isempty(iv) -% if length(iv)>1 -% % boxplot(SAif(iv,:),'whis',3,'symbol','r.'); -% myboxplot(SAif(iv,:),[],'.',[],10) -% else -% plot(SAif(iv,:),'r.'); -% end -% set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) -% set(gca,'xlim',[0.5 np+0.5]) -% ydum = get(gca,'ylim'); -% set(gca,'ylim',[0 ydum(2)]) -% for ip=1:np, -% text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') -% end -% xlabel(' ') -% end -% title(options_.varobs(j,:),'interpreter','none') -% if mod(j,6)==0 | j==size(options_.varobs,1) -% saveas(gcf,[OutputDirectoryName,'/',fname_,'_map_if',fsuffix,'_varobs_',int2str(ifig)]) -% eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_map_if',fsuffix,'_varobs_',int2str(ifig)]); -% eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_map_if',fsuffix,'_varobs_',int2str(ifig)]); -% close(gcf), -% end -% end -% -% ifig = 0; -% for j=1:M_.exo_nbr, -% if mod(j,6)==1 -% figure('name',['Main effects shocks impact factors ',fsuffix]); -% ifig=ifig+1; -% iplo=0; -% end -% iplo=iplo+1; -% subplot(3,2,iplo) -% iv = find(ic_if==j); -% if ~isempty(iv) -% if length(iv)>1 -% % boxplot(SAif(iv,:),'whis',3,'symbol','r.'); -% myboxplot(SAif(iv,:),[],'.',[],10) -% else -% plot(SAif(iv,:),'r.'); -% end -% set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) -% set(gca,'xlim',[0.5 np+0.5]) -% ydum = get(gca,'ylim'); -% set(gca,'ylim',[0 ydum(2)]) -% for ip=1:np, -% text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') -% end -% xlabel(' ') -% end -% title(M_.exo_names(j,:),'interpreter','none') -% if mod(j,6)==0 | j==M_.exo_nbr -% saveas(gcf,[OutputDirectoryName,'/',fname_,'_map_if',fsuffix,'_exo_',int2str(ifig)]) -% eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_map_if',fsuffix,'_exo_',int2str(ifig)]); -% eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_map_if',fsuffix,'_exo_',int2str(ifig)]); -% close(gcf), -% end -% end -% SAmom = [SAvdec' SAcc' SAac']'; -% SAdyn = [SAtadj' SAif']'; -% SAall = [SAmom(:,nshock+1:end)' SAdyn']'; -% -% figure, -% % boxplot(SAtadj,'whis',10,'symbol','r.') -% myboxplot(SAmom,[],'.',[],10) -% set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:npT]) -% set(gca,'xlim',[0.5 npT+0.5]) -% ydum = get(gca,'ylim'); -% set(gca,'ylim',[0 ydum(2)]) -% set(gca,'position',[0.13 0.2 0.775 0.7]) -% for ip=1:npT, -% % text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') -% text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') -% end -% xlabel(' ') -% title(['Main effects theoretical moments ',fsuffix],'interpreter','none') -% saveas(gcf,[OutputDirectoryName,'/',fname_,'_map_moments',fsuffix]) -% eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_map_moments',fsuffix]); -% eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_map_moments',fsuffix]); -% % close(gcf), -% -% figure, -% % boxplot(SAtadj,'whis',10,'symbol','r.') -% myboxplot(SAdyn,[],'.',[],10) -% set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) -% set(gca,'xlim',[0.5 np+0.5]) -% ydum = get(gca,'ylim'); -% set(gca,'ylim',[0 ydum(2)]) -% set(gca,'position',[0.13 0.2 0.775 0.7]) -% for ip=1:np, -% text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') -% % text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') -% end -% xlabel(' ') -% title(['Main effects short-long term dynamics ',fsuffix],'interpreter','none') -% saveas(gcf,[OutputDirectoryName,'/',fname_,'_map_dynamics',fsuffix]) -% eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_map_dynamics',fsuffix]); -% eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_map_dynamics',fsuffix]); -% % close(gcf), -% -% figure, -% % boxplot(SAtadj,'whis',10,'symbol','r.') -% myboxplot(SAall,[],'.',[],10) -% set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) -% set(gca,'xlim',[0.5 np+0.5]) -% ydum = get(gca,'ylim'); -% set(gca,'ylim',[0 ydum(2)]) -% set(gca,'position',[0.13 0.2 0.775 0.7]) -% for ip=1:np, -% text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') -% % text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') -% end -% xlabel(' ') -% title(['Main effects all ',fsuffix],'interpreter','none') -% saveas(gcf,[OutputDirectoryName,'/',fname_,'_map_ALL',fsuffix]) -% eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_map_ALL',fsuffix]); -% eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_map_ALL',fsuffix]); -% % close(gcf), + end + save([OutputDirectoryName,'/map_cc',fsuffix,'.mat'],'gsa_') + save([OutputDirectoryName,'/',fname_,'_main_eff.mat'],'imap_cc','SAcc','ccac','-append') + else + load([OutputDirectoryName,'/',fname_,'_main_eff'],'imap_cc','SAcc','ccac') + + end + % figure, + % % boxplot(SAcc,'whis',10,'symbol','r.') + % myboxplot(SAcc,[],'.',[],10) + % set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) + % set(gca,'xlim',[0.5 npT+0.5]) + % ydum = get(gca,'ylim'); + % set(gca,'ylim',[0 ydum(2)]) + % set(gca,'position',[0.13 0.2 0.775 0.7]) + % for ip=1:npT, + % text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') + % % text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') + % end + % xlabel(' ') + % ylabel(' ') + % title(['Main effects moments''s PCA ',fsuffix],'interpreter','none') + % saveas(gcf,[OutputDirectoryName,'/',fname_,'_map_cc',fsuffix]) + % eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_map_moments',fsuffix]); + % eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_map_moments',fsuffix]); + % close(gcf), -% for j=1:size(SAall,1), -% SAallN(j,:)=SAall(j,:)./max(SAall(j,:)); -% end -% SAmean=mean(SAallN); -% for j=1:size(SAmom,1), -% SAmomN(j,:)=SAmom(j,1:nshock)./max(SAmom(j,1:nshock)); -% end -% SAmomN(find(isnan(SAmomN)))=0; -% SAmeanexo=mean(SAmomN(:,1:nshock)); + % ifig = 0; + % for j=1:size(options_.varobs,1) + % if mod(j,6)==1 + % figure('name',['Main effects cross-covariances ',fsuffix]); + % ifig=ifig+1; + % iplo=0; + % end + % iplo=iplo+1; + % subplot(3,2,iplo) + % iv = find(ir_cc==j); + % iv = [iv; find(ic_cc==j)]; + % if ~isempty(iv) + % if length(iv)>1 + % % boxplot(SAcc(iv,:),'whis',10,'symbol','r.'); + % myboxplot(SAcc(iv,:),[],'.',[],10) + % else + % plot(SAcc(iv,:),'r.'); + % end + % set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) + % set(gca,'xlim',[0.5 npT+0.5]) + % ydum = get(gca,'ylim'); + % set(gca,'ylim',[0 ydum(2)]) + % for ip=1:npT, + % text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') + % % text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') + % end + % xlabel(' ') + % set(gca,'fontsize',10) + % end + % title(options_.varobs(j,:),'interpreter','none','fontsize',10) + % if mod(j,6)==0 | j==size(options_.varobs,1) + % saveas(gcf,[OutputDirectoryName,'/',fname_,'_map_cc',fsuffix,'_',int2str(ifig)]) + % eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_map_cc',fsuffix,'_',int2str(ifig)]); + % eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_map_cc',fsuffix,'_',int2str(ifig)]); + % close(gcf), + % end + % end + % + % if opt_gsa.load_ident_files==0, + % try + % EET=load([OutputDirectoryName,'/SCREEN/',fname_,'_morris_IDE'],'SAac','ir_ac','ic_ac'); + % catch + % EET=[]; + % end + % SAac=zeros(size(ac,2),npT); + % for j=1:size(ac,2), + % if itrans==0, + % y0 = ac(istable,j); + % elseif itrans==1, + % y0 = log_trans_(ac(istable,j)); + % else + % y0 = trank(ac(istable,j)); + % end + % if ~isempty(EET), + % imap=find(EET.SAac(j,:) >= (0.1.*max(EET.SAac(j,:))) ); + % end + % % gsa_(j) = gsa_sdp_dyn( y0, lpmat(istable,:), ... + % % gsa_flag, [],[],[],0,[OutputDirectoryName,'/map_ac',fsuffix,int2str(j)], pnames); + % gsa_(j) = gsa_sdp(y0(1:nest), x0(1:nest,imap), ... + % 2, [],[],[],0,[OutputDirectoryName,'/map_ac',fsuffix,int2str(j)], pnames); + % if nfit>nest, + % gsa_(j) = gsa_sdp(y0(1:nfit), x0(1:nfit,imap), ... + % -2, gsa_(j).nvr*nest^3/nfit^3,[],[],0,[OutputDirectoryName,'/map_ac',fsuffix,int2str(j)], pnames); + % end + % SAac(j,imap)=gsa_(j).si; + % imap_ac{j}=imap; + % + % end + % save([OutputDirectoryName,'/',fname_,'_main_eff'],'imap_ac','SAac','ac','ir_ac','ic_ac','-append') + % else + % load([OutputDirectoryName,'/',fname_,'_main_eff'],'imap_ac','SAac','ac','ir_ac','ic_ac') + % end + % + % figure, + % % boxplot(SAac,'whis',10,'symbol','r.') + % myboxplot(SAac,[],'.',[],10) + % set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) + % set(gca,'xlim',[0.5 npT+0.5]) + % ydum = get(gca,'ylim'); + % set(gca,'ylim',[0 ydum(2)]) + % set(gca,'position',[0.13 0.2 0.775 0.7]) + % for ip=1:np, + % text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') + % end + % xlabel(' ') + % title(['Main effects 1 lag auto-covariances ',fsuffix],'interpreter','none') + % saveas(gcf,[OutputDirectoryName,'/',fname_,'_map_ac',fsuffix]) + % eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_map_ac',fsuffix]); + % eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_map_ac',fsuffix]); + % close(gcf), + % + % ifig = 0; + % for j=1:size(options_.varobs,1) + % if mod(j,6)==1 + % figure('name',['Main effects auto-covariances ',fsuffix]); + % ifig=ifig+1; + % iplo = 0; + % end + % iplo=iplo+1; + % subplot(3,2,iplo) + % iv = find(ir_ac==j); + % %iv = [iv; find(ic_ac==j)]; + % if ~isempty(iv) + % if length(iv)>1 + % % boxplot(SAac(iv,:),'whis',10,'symbol','r.'); + % myboxplot(SAac(iv,:),[],'.',[],10) + % else + % plot(SAac(iv,:),'r.'); + % end + % set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) + % set(gca,'xlim',[0.5 npT+0.5]) + % ydum = get(gca,'ylim'); + % set(gca,'ylim',[0 ydum(2)]) + % for ip=1:npT, + % text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') + % % text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') + % end + % xlabel(' ') + % set(gca,'fontsize',10) + % end + % title(options_.varobs(j,:),'interpreter','none','fontsize',10) + % if mod(j,6)==0 | j==size(options_.varobs,1) + % saveas(gcf,[OutputDirectoryName,'/',fname_,'_map_ac',fsuffix,'_',int2str(ifig)]) + % eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_map_ac',fsuffix,'_',int2str(ifig)]); + % eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_map_ac',fsuffix,'_',int2str(ifig)]); + % close(gcf), + % end + % end + + % x0=x0(:,nshock+1:end); + imap=[1:npT]; -% figure, bar(latent'*SAcc), - hh=dyn_figure(options_.nodisplay,'Name',['Identifiability indices in the ',fsuffix,' moments.']); - bar(sum(SAcc)), - set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:npT]) - set(gca,'xlim',[0.5 npT+0.5]) - ydum = get(gca,'ylim'); - set(gca,'ylim',[0 ydum(2)]) - set(gca,'position',[0.13 0.2 0.775 0.7]) - for ip=1:npT, - text(ip,-0.02*(ydum(2)),bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') + % if opt_gsa.load_ident_files==0, + % try + % EET=load([OutputDirectoryName,'/SCREEN/',fname_,'_morris_IDE'],'SAtadj','ir_tadj','ic_tadj'); + % ny=size(EET.SAtadj,1); + % catch + % EET=[]; + % end + % SAtadj=zeros(size(tadj,2),np); + % for j=1:size(tadj,2), + % if itrans==0, + % y0 = tadj(istable,j); + % elseif itrans==1, + % y0 = log_trans_(tadj(istable,j)); + % else + % y0 = trank(tadj(istable,j)); + % end + % if ~isempty(EET), + % if size(tadj,2)~=ny, + % jj=find(EET.ir_tadj==ir_tadj(j)); + % jj=jj(find(EET.ic_tadj(jj)==ic_tadj(j))); + % if ~isempty(jj), + % imap=find(EET.SAtadj(jj,:) >= (0.1.*max(EET.SAtadj(jj,:))) ); + % else + % imap=[1:np]; + % end + % else + % imap=find(EET.SAtadj(j,:) >= (0.1.*max(EET.SAtadj(j,:))) ); + % end + % end + % % gsa_(j) = gsa_sdp_dyn( y0, lpmat(istable,:), ... + % % gsa_flag, [],[],[],0,[OutputDirectoryName,'/map_tadj',fsuffix,int2str(j)], pnames); + % gsa_(j) = gsa_sdp(y0(1:nest), x0(1:nest,imap), ... + % 2, [],[],[],0,[OutputDirectoryName,'/map_tadj',fsuffix,int2str(j)], pnames); + % if nfit>nest, + % gsa_(j) = gsa_sdp(y0(1:nfit), x0(1:nfit,imap), ... + % -2, gsa_(j).nvr*nest^3/nfit^3,[],[],0,[OutputDirectoryName,'/map_tadj',fsuffix,int2str(j)], pnames); + % end + % SAtadj(j,imap)=gsa_(j).si; + % imap_tadj{j}=imap; + % + % end + % save([OutputDirectoryName,'/',fname_,'_main_eff'],'imap_tadj','SAtadj','tadj','ir_tadj','ic_tadj','-append') + % else + % load([OutputDirectoryName,'/',fname_,'_main_eff'],'imap_tadj','SAtadj','tadj','ir_tadj','ic_tadj') + % end + % + % figure, + % % boxplot(SAtadj,'whis',10,'symbol','r.') + % myboxplot(SAtadj,[],'.',[],10) + % set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) + % set(gca,'xlim',[0.5 np+0.5]) + % ydum = get(gca,'ylim'); + % set(gca,'ylim',[0 ydum(2)]) + % set(gca,'position',[0.13 0.2 0.775 0.7]) + % for ip=1:np, + % text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') + % end + % xlabel(' ') + % title(['Main effects speed of adjustment ',fsuffix],'interpreter','none') + % saveas(gcf,[OutputDirectoryName,'/',fname_,'_map_tadj',fsuffix]) + % eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_map_tadj',fsuffix]); + % eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_map_tadj',fsuffix]); + % close(gcf), + % + % ifig = 0; + % for j=1:size(options_.varobs,1) + % if mod(j,6)==1 + % figure('name',['Main effects observed speed adjustment ',fsuffix]); + % ifig=ifig+1; + % iplo = 0; + % end + % iplo=iplo+1; + % subplot(3,2,iplo) + % iv = find(ir_tadj==j); + % if ~isempty(iv) + % if length(iv)>1 + % % boxplot(SAtadj(iv,:),'whis',3,'symbol','r.'); + % myboxplot(SAtadj(iv,:),[],'.',[],10) + % else + % plot(SAtadj(iv,:),'r.'); + % end + % set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) + % set(gca,'xlim',[0.5 np+0.5]) + % ydum = get(gca,'ylim'); + % set(gca,'ylim',[0 ydum(2)]) + % for ip=1:np, + % text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') + % end + % xlabel(' ') + % end + % title(options_.varobs(j,:),'interpreter','none') + % if mod(j,6)==0 | j==size(options_.varobs,1) + % saveas(gcf,[OutputDirectoryName,'/',fname_,'_map_tadj',fsuffix,'_varobs_',int2str(ifig)]) + % eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_map_tadj',fsuffix,'_varobs_',int2str(ifig)]); + % eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_map_tadj',fsuffix,'_varobs_',int2str(ifig)]); + % close(gcf), + % end + % end + % + % ifig = 0; + % for j=1:M_.exo_nbr, + % if mod(j,6)==1 + % figure('name',['Main effects shocks speed of adjustment ',fsuffix]); + % ifig=ifig+1; + % iplo=0; + % end + % iplo=iplo+1; + % subplot(3,2,iplo) + % iv = find(ic_tadj==j); + % if ~isempty(iv) + % if length(iv)>1 + % % boxplot(SAtadj(iv,:),'whis',3,'symbol','r.'); + % myboxplot(SAtadj(iv,:),[],'.',[],10) + % else + % plot(SAtadj(iv,:),'r.'); + % end + % set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) + % set(gca,'xlim',[0.5 np+0.5]) + % ydum = get(gca,'ylim'); + % set(gca,'ylim',[0 ydum(2)]) + % for ip=1:np, + % text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') + % end + % xlabel(' ') + % end + % title(M_.exo_names(j,:),'interpreter','none') + % if mod(j,6)==0 | j==M_.exo_nbr, + % saveas(gcf,[OutputDirectoryName,'/',fname_,'_map_tadj',fsuffix,'_exo_',int2str(ifig)]) + % eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_map_tadj',fsuffix,'_exo_',int2str(ifig)]); + % eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_map_tadj',fsuffix,'_exo_',int2str(ifig)]); + % close(gcf), + % end + % end + % + % + % if opt_gsa.load_ident_files==0, + % try + % EET=load([OutputDirectoryName,'/SCREEN/',fname_,'_morris_IDE'],'SAIF','ir_if','ic_if'); + % catch + % EET=[]; + % end + % SAif=zeros(size(iff,2),np); + % for j=1:size(iff,2), + % if itrans==0, + % y0 = iff(istable,j); + % elseif itrans==1, + % y0 = log_trans_(iff(istable,j)); + % else + % y0 = trank(iff(istable,j)); + % end + % if ~isempty(EET), + % imap=find(EET.SAIF(j,:) >= (0.1.*max(EET.SAIF(j,:))) ); + % end + % % gsa_(j) = gsa_sdp_dyn( y0, lpmat(istable,:), ... + % % gsa_flag, [],[],[],0,[OutputDirectoryName,'/map_if',fsuffix,int2str(j)], pnames); + % gsa_(j) = gsa_sdp(y0(1:nest), x0(1:nest,imap), ... + % 2, [],[],[],0,[OutputDirectoryName,'/map_if',fsuffix,int2str(j)], pnames); + % if nfit>nest, + % gsa_(j) = gsa_sdp(y0(1:nfit), x0(1:nfit,imap), ... + % -2, gsa_(j).nvr*nest^3/nfit^3,[],[],0,[OutputDirectoryName,'/map_if',fsuffix,int2str(j)], pnames); + % end + % SAif(j,imap)=gsa_(j).si; + % imap_if{j}=imap; + % + % end + % save([OutputDirectoryName,'/',fname_,'_main_eff'],'imap_if','SAif','iff','ir_if','ic_if','-append') + % else + % load([OutputDirectoryName,'/',fname_,'_main_eff'],'imap_if','SAif','iff','ir_if','ic_if') + % end + % + % figure, + % % boxplot(SAif,'whis',10,'symbol','r.') + % myboxplot(SAif,[],'.',[],10) + % set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) + % set(gca,'xlim',[0.5 np+0.5]) + % ydum = get(gca,'ylim'); + % set(gca,'ylim',[0 ydum(2)]) + % set(gca,'position',[0.13 0.2 0.775 0.7]) + % for ip=1:np, + % text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') + % end + % xlabel(' ') + % title(['Main effects impact factors ',fsuffix],'interpreter','none') + % saveas(gcf,[OutputDirectoryName,'/',fname_,'_map_if',fsuffix]) + % eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_map_if',fsuffix]); + % eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_map_if',fsuffix]); + % close(gcf), + % + % ifig = 0; + % for j=1:size(options_.varobs,1) + % if mod(j,6)==1 + % figure('name',['Main effects observed impact factors ',fsuffix]); + % ifig=ifig+1; + % iplo = 0; + % end + % iplo=iplo+1; + % subplot(3,2,iplo) + % iv = find(ir_if==j); + % if ~isempty(iv) + % if length(iv)>1 + % % boxplot(SAif(iv,:),'whis',3,'symbol','r.'); + % myboxplot(SAif(iv,:),[],'.',[],10) + % else + % plot(SAif(iv,:),'r.'); + % end + % set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) + % set(gca,'xlim',[0.5 np+0.5]) + % ydum = get(gca,'ylim'); + % set(gca,'ylim',[0 ydum(2)]) + % for ip=1:np, + % text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') + % end + % xlabel(' ') + % end + % title(options_.varobs(j,:),'interpreter','none') + % if mod(j,6)==0 | j==size(options_.varobs,1) + % saveas(gcf,[OutputDirectoryName,'/',fname_,'_map_if',fsuffix,'_varobs_',int2str(ifig)]) + % eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_map_if',fsuffix,'_varobs_',int2str(ifig)]); + % eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_map_if',fsuffix,'_varobs_',int2str(ifig)]); + % close(gcf), + % end + % end + % + % ifig = 0; + % for j=1:M_.exo_nbr, + % if mod(j,6)==1 + % figure('name',['Main effects shocks impact factors ',fsuffix]); + % ifig=ifig+1; + % iplo=0; + % end + % iplo=iplo+1; + % subplot(3,2,iplo) + % iv = find(ic_if==j); + % if ~isempty(iv) + % if length(iv)>1 + % % boxplot(SAif(iv,:),'whis',3,'symbol','r.'); + % myboxplot(SAif(iv,:),[],'.',[],10) + % else + % plot(SAif(iv,:),'r.'); + % end + % set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) + % set(gca,'xlim',[0.5 np+0.5]) + % ydum = get(gca,'ylim'); + % set(gca,'ylim',[0 ydum(2)]) + % for ip=1:np, + % text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') + % end + % xlabel(' ') + % end + % title(M_.exo_names(j,:),'interpreter','none') + % if mod(j,6)==0 | j==M_.exo_nbr + % saveas(gcf,[OutputDirectoryName,'/',fname_,'_map_if',fsuffix,'_exo_',int2str(ifig)]) + % eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_map_if',fsuffix,'_exo_',int2str(ifig)]); + % eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_map_if',fsuffix,'_exo_',int2str(ifig)]); + % close(gcf), + % end + % end + % SAmom = [SAvdec' SAcc' SAac']'; + % SAdyn = [SAtadj' SAif']'; + % SAall = [SAmom(:,nshock+1:end)' SAdyn']'; + % + % figure, + % % boxplot(SAtadj,'whis',10,'symbol','r.') + % myboxplot(SAmom,[],'.',[],10) + % set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:npT]) + % set(gca,'xlim',[0.5 npT+0.5]) + % ydum = get(gca,'ylim'); + % set(gca,'ylim',[0 ydum(2)]) + % set(gca,'position',[0.13 0.2 0.775 0.7]) + % for ip=1:npT, + % % text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') % text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') - end - xlabel(' ') - title(['Identifiability indices in the ',fsuffix,' moments.'],'interpreter','none') - dyn_saveas(hh,[OutputDirectoryName,'/',fname_,'_ident_ALL',fsuffix],options_.nodisplay,options_.graph_format); - create_TeX_loader(options_,[OutputDirectoryName,'/',fname_,'_ident_ALL',fsuffix],1,['Identifiability indices in the ',fsuffix,' moments.'],['ident_ALL',fsuffix]',1) + % end + % xlabel(' ') + % title(['Main effects theoretical moments ',fsuffix],'interpreter','none') + % saveas(gcf,[OutputDirectoryName,'/',fname_,'_map_moments',fsuffix]) + % eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_map_moments',fsuffix]); + % eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_map_moments',fsuffix]); + % % close(gcf), + % + % figure, + % % boxplot(SAtadj,'whis',10,'symbol','r.') + % myboxplot(SAdyn,[],'.',[],10) + % set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) + % set(gca,'xlim',[0.5 np+0.5]) + % ydum = get(gca,'ylim'); + % set(gca,'ylim',[0 ydum(2)]) + % set(gca,'position',[0.13 0.2 0.775 0.7]) + % for ip=1:np, + % text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') + % % text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') + % end + % xlabel(' ') + % title(['Main effects short-long term dynamics ',fsuffix],'interpreter','none') + % saveas(gcf,[OutputDirectoryName,'/',fname_,'_map_dynamics',fsuffix]) + % eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_map_dynamics',fsuffix]); + % eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_map_dynamics',fsuffix]); + % % close(gcf), + % + % figure, + % % boxplot(SAtadj,'whis',10,'symbol','r.') + % myboxplot(SAall,[],'.',[],10) + % set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) + % set(gca,'xlim',[0.5 np+0.5]) + % ydum = get(gca,'ylim'); + % set(gca,'ylim',[0 ydum(2)]) + % set(gca,'position',[0.13 0.2 0.775 0.7]) + % for ip=1:np, + % text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') + % % text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') + % end + % xlabel(' ') + % title(['Main effects all ',fsuffix],'interpreter','none') + % saveas(gcf,[OutputDirectoryName,'/',fname_,'_map_ALL',fsuffix]) + % eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_map_ALL',fsuffix]); + % eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_map_ALL',fsuffix]); + % % close(gcf), -% figure, bar(SAmeanexo), -% set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:nshock]) -% set(gca,'xlim',[0.5 nshock+0.5]) -% ydum = get(gca,'ylim'); -% set(gca,'ylim',[0 ydum(2)]) -% set(gca,'position',[0.13 0.2 0.775 0.7]) -% for ip=1:nshock, -% % text(ip,-0.02*(ydum(2)),deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') -% text(ip,-0.02*(ydum(2)),bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') -% end -% xlabel(' ') -% title(['Identifiability indices for shocks',fsuffix],'interpreter','none') -% saveas(gcf,[OutputDirectoryName,'/',fname_,'_ident_SHOCKS',fsuffix]) -% eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_ident_SHOCKS',fsuffix]); -% eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_ident_SHOCKS',fsuffix]); + % for j=1:size(SAall,1), + % SAallN(j,:)=SAall(j,:)./max(SAall(j,:)); + % end + % SAmean=mean(SAallN); + % for j=1:size(SAmom,1), + % SAmomN(j,:)=SAmom(j,1:nshock)./max(SAmom(j,1:nshock)); + % end + % SAmomN(find(isnan(SAmomN)))=0; + % SAmeanexo=mean(SAmomN(:,1:nshock)); + + % figure, bar(latent'*SAcc), + hh=dyn_figure(options_.nodisplay,'Name',['Identifiability indices in the ',fsuffix,' moments.']); + bar(sum(SAcc)), + set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:npT]) + set(gca,'xlim',[0.5 npT+0.5]) + ydum = get(gca,'ylim'); + set(gca,'ylim',[0 ydum(2)]) + set(gca,'position',[0.13 0.2 0.775 0.7]) + for ip=1:npT, + text(ip,-0.02*(ydum(2)),bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') + % text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') + end + xlabel(' ') + title(['Identifiability indices in the ',fsuffix,' moments.'],'interpreter','none') + dyn_saveas(hh,[OutputDirectoryName,'/',fname_,'_ident_ALL',fsuffix],options_.nodisplay,options_.graph_format); + create_TeX_loader(options_,[OutputDirectoryName,'/',fname_,'_ident_ALL',fsuffix],1,['Identifiability indices in the ',fsuffix,' moments.'],['ident_ALL',fsuffix]',1) + + % figure, bar(SAmeanexo), + % set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:nshock]) + % set(gca,'xlim',[0.5 nshock+0.5]) + % ydum = get(gca,'ylim'); + % set(gca,'ylim',[0 ydum(2)]) + % set(gca,'position',[0.13 0.2 0.775 0.7]) + % for ip=1:nshock, + % % text(ip,-0.02*(ydum(2)),deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') + % text(ip,-0.02*(ydum(2)),bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') + % end + % xlabel(' ') + % title(['Identifiability indices for shocks',fsuffix],'interpreter','none') + % saveas(gcf,[OutputDirectoryName,'/',fname_,'_ident_SHOCKS',fsuffix]) + % eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_ident_SHOCKS',fsuffix]); + % eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_ident_SHOCKS',fsuffix]); end return diff --git a/matlab/gsa/mc_moments.m b/matlab/gsa/mc_moments.m index b2ea935385..ed492d7451 100644 --- a/matlab/gsa/mc_moments.m +++ b/matlab/gsa/mc_moments.m @@ -19,19 +19,19 @@ function [vdec, cc, ac] = mc_moments(mm, ss, dr) global options_ M_ estim_params_ oo_ - [nr1, nc1, nsam] = size(mm); - nobs=size(options_.varobs,2); - disp('Computing theoretical moments ...') - h = dyn_waitbar(0,'Theoretical moments ...'); - vdec = zeros(nobs,M_.exo_nbr,nsam); - cc = zeros(nobs,nobs,nsam); - ac = zeros(nobs,nobs*options_.ar,nsam); - - for j=1:nsam, +[nr1, nc1, nsam] = size(mm); +nobs=size(options_.varobs,2); +disp('Computing theoretical moments ...') +h = dyn_waitbar(0,'Theoretical moments ...'); +vdec = zeros(nobs,M_.exo_nbr,nsam); +cc = zeros(nobs,nobs,nsam); +ac = zeros(nobs,nobs*options_.ar,nsam); + +for j=1:nsam, oo_.dr.ghx = mm(:, [1:(nc1-M_.exo_nbr)],j); oo_.dr.ghu = mm(:, [(nc1-M_.exo_nbr+1):end], j); if ~isempty(ss), - set_shocks_param(ss(j,:)); + set_shocks_param(ss(j,:)); end [vdec(:,:,j), corr, autocorr, z, zz] = th_moments(oo_.dr,options_.varobs); cc(:,:,j)=triu(corr); @@ -41,7 +41,7 @@ global options_ M_ estim_params_ oo_ end ac(:,:,j)=dum; dyn_waitbar(j/nsam,h) - end - dyn_waitbar_close(h) - skipline() - disp('... done !') +end +dyn_waitbar_close(h) +skipline() +disp('... done !') diff --git a/matlab/gsa/mcf_analysis.m b/matlab/gsa/mcf_analysis.m index e15bdea557..2d61691851 100644 --- a/matlab/gsa/mcf_analysis.m +++ b/matlab/gsa/mcf_analysis.m @@ -1,84 +1,84 @@ -function indmcf = mcf_analysis(lpmat, ibeha, inobeha, options_mcf, DynareOptions) -% -% Written by Marco Ratto -% Joint Research Centre, The European Commission, -% marco.ratto@ec.europa.eu -% - -% Copyright (C) 2014 European Commission -% Copyright (C) 2016 Dynare Team -% -% This file is part of Dynare. -% -% Dynare is free software: you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation, either version 3 of the License, or -% (at your option) any later version. -% -% Dynare is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. -% -% You should have received a copy of the GNU General Public License -% along with Dynare. If not, see <http://www.gnu.org/licenses/>. - -pvalue_ks = options_mcf.pvalue_ks; -pvalue_corr = options_mcf.pvalue_corr; -alpha2 = options_mcf.alpha2; -param_names = options_mcf.param_names; - -if DynareOptions.TeX - if ~isfield(options_mcf,'param_names_tex') - param_names_tex = options_mcf.param_names; - else - param_names_tex = options_mcf.param_names_tex; - end -end -amcf_name = options_mcf.amcf_name; -amcf_title = options_mcf.amcf_title; -beha_title = options_mcf.beha_title; -nobeha_title = options_mcf.nobeha_title; -title = options_mcf.title; -fname_ = options_mcf.fname_; -xparam1=[]; -if isfield(options_mcf,'xparam1'), - xparam1=options_mcf.xparam1; -end -OutputDirectoryName = options_mcf.OutputDirectoryName; - -[proba, dproba] = stab_map_1(lpmat, ibeha, inobeha, [],0); -indmcf=find(proba<pvalue_ks); -[tmp,jtmp] = sort(proba(indmcf),2,'ascend'); -indmcf = indmcf(jtmp); -if ~isempty(indmcf) - skipline() - headers=char('Parameter','d-stat','p-value'); - labels=char(param_names(indmcf,:)); - data_mat=[dproba(indmcf)' proba(indmcf)']; - options_temp.noprint=0; - dyntable(options_temp,['Smirnov statistics in driving ', title],headers,labels,data_mat,size(labels,2)+2,16,3); - if DynareOptions.TeX - labels_TeX=param_names_tex(indmcf,:); - M_temp.dname=OutputDirectoryName ; - M_temp.fname=fname_; - dyn_latex_table(M_temp,options_temp,['Smirnov statistics in driving ', strrep(title,'_','\\_')],amcf_name,headers,labels_TeX,data_mat,size(labels,2)+2,16,6); - end -end - - -if length(ibeha)>10 && length(inobeha)>10, - indcorr1 = stab_map_2(lpmat(ibeha,:),alpha2, pvalue_corr, beha_title); - indcorr2 = stab_map_2(lpmat(inobeha,:),alpha2, pvalue_corr, nobeha_title); - indcorr = union(indcorr1(:), indcorr2(:)); - indcorr = indcorr(~ismember(indcorr(:),indmcf)); - indmcf = [indmcf(:); indcorr(:)]; -end -if ~isempty(indmcf) && ~DynareOptions.nograph, - skipline() - xx=[]; - if ~ isempty(xparam1), xx=xparam1(indmcf); end - scatter_mcf(lpmat(ibeha,indmcf),lpmat(inobeha,indmcf), param_names(indmcf,:), ... - '.', [fname_,'_',amcf_name], OutputDirectoryName, amcf_title,xx, DynareOptions, ... - beha_title, nobeha_title) -end +function indmcf = mcf_analysis(lpmat, ibeha, inobeha, options_mcf, DynareOptions) +% +% Written by Marco Ratto +% Joint Research Centre, The European Commission, +% marco.ratto@ec.europa.eu +% + +% Copyright (C) 2014 European Commission +% Copyright (C) 2016 Dynare Team +% +% This file is part of Dynare. +% +% Dynare is free software: you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation, either version 3 of the License, or +% (at your option) any later version. +% +% Dynare is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with Dynare. If not, see <http://www.gnu.org/licenses/>. + +pvalue_ks = options_mcf.pvalue_ks; +pvalue_corr = options_mcf.pvalue_corr; +alpha2 = options_mcf.alpha2; +param_names = options_mcf.param_names; + +if DynareOptions.TeX + if ~isfield(options_mcf,'param_names_tex') + param_names_tex = options_mcf.param_names; + else + param_names_tex = options_mcf.param_names_tex; + end +end +amcf_name = options_mcf.amcf_name; +amcf_title = options_mcf.amcf_title; +beha_title = options_mcf.beha_title; +nobeha_title = options_mcf.nobeha_title; +title = options_mcf.title; +fname_ = options_mcf.fname_; +xparam1=[]; +if isfield(options_mcf,'xparam1'), + xparam1=options_mcf.xparam1; +end +OutputDirectoryName = options_mcf.OutputDirectoryName; + +[proba, dproba] = stab_map_1(lpmat, ibeha, inobeha, [],0); +indmcf=find(proba<pvalue_ks); +[tmp,jtmp] = sort(proba(indmcf),2,'ascend'); +indmcf = indmcf(jtmp); +if ~isempty(indmcf) + skipline() + headers=char('Parameter','d-stat','p-value'); + labels=char(param_names(indmcf,:)); + data_mat=[dproba(indmcf)' proba(indmcf)']; + options_temp.noprint=0; + dyntable(options_temp,['Smirnov statistics in driving ', title],headers,labels,data_mat,size(labels,2)+2,16,3); + if DynareOptions.TeX + labels_TeX=param_names_tex(indmcf,:); + M_temp.dname=OutputDirectoryName ; + M_temp.fname=fname_; + dyn_latex_table(M_temp,options_temp,['Smirnov statistics in driving ', strrep(title,'_','\\_')],amcf_name,headers,labels_TeX,data_mat,size(labels,2)+2,16,6); + end +end + + +if length(ibeha)>10 && length(inobeha)>10, + indcorr1 = stab_map_2(lpmat(ibeha,:),alpha2, pvalue_corr, beha_title); + indcorr2 = stab_map_2(lpmat(inobeha,:),alpha2, pvalue_corr, nobeha_title); + indcorr = union(indcorr1(:), indcorr2(:)); + indcorr = indcorr(~ismember(indcorr(:),indmcf)); + indmcf = [indmcf(:); indcorr(:)]; +end +if ~isempty(indmcf) && ~DynareOptions.nograph, + skipline() + xx=[]; + if ~ isempty(xparam1), xx=xparam1(indmcf); end + scatter_mcf(lpmat(ibeha,indmcf),lpmat(inobeha,indmcf), param_names(indmcf,:), ... + '.', [fname_,'_',amcf_name], OutputDirectoryName, amcf_title,xx, DynareOptions, ... + beha_title, nobeha_title) +end diff --git a/matlab/gsa/myboxplot.m b/matlab/gsa/myboxplot.m index b71ad169e3..054f664306 100644 --- a/matlab/gsa/myboxplot.m +++ b/matlab/gsa/myboxplot.m @@ -36,10 +36,10 @@ a=1-notched; % ## figure out how many data sets we have if iscell(data), - nc = length(data); + nc = length(data); else -% if isvector(data), data = data(:); end - nc = size(data,2); + % if isvector(data), data = data(:); end + nc = size(data,2); end % ## compute statistics @@ -63,60 +63,60 @@ for i=1:nc else col = data(:,i); end -% ## Skip missing data -% % % % % % % col(isnan(col) | isna (col)) = []; - col(isnan(col)) = []; - - % ## Remember the data length - nd = length(col); - box(i) = nd; - if (nd > 1) -% ## min,max and quartiles -% s(1:5,i) = statistics(col)(1:5); -s(1,i)=min(col); -s(5,i)=max(col); -s(2,i)=myprctilecol(col,25); -s(3,i)=myprctilecol(col,50); -s(4,i)=myprctilecol(col,75); - - - - - - - - -% ## confidence interval for the median - est = 1.57*(s(4,i)-s(2,i))/sqrt(nd); - s(6,i) = max([s(3,i)-est, s(2,i)]); - s(7,i) = min([s(3,i)+est, s(4,i)]); -% ## whiskers out to the last point within the desired inter-quartile range - IQR = maxwhisker*(s(4,i)-s(2,i)); - whisker_y(:,i) = [min(col(col >= s(2,i)-IQR)); s(2,i)]; - whisker_y(:,nc+i) = [max(col(col <= s(4,i)+IQR)); s(4,i)]; -% ## outliers beyond 1 and 2 inter-quartile ranges - outliers = col((col < s(2,i)-IQR & col >= s(2,i)-2*IQR) | (col > s(4,i)+IQR & col <= s(4,i)+2*IQR)); - outliers2 = col(col < s(2,i)-2*IQR | col > s(4,i)+2*IQR); - outliers_x = [outliers_x; i*ones(size(outliers))]; - outliers_y = [outliers_y; outliers]; - outliers2_x = [outliers2_x; i*ones(size(outliers2))]; - outliers2_y = [outliers2_y; outliers2]; - elseif (nd == 1) -% ## all statistics collapse to the value of the point - s(:,i) = col; -% ## single point data sets are plotted as outliers. - outliers_x = [outliers_x; i]; - outliers_y = [outliers_y; col]; - else -% ## no statistics if no points - s(:,i) = NaN; - end + % ## Skip missing data + % % % % % % % col(isnan(col) | isna (col)) = []; + col(isnan(col)) = []; + + % ## Remember the data length + nd = length(col); + box(i) = nd; + if (nd > 1) + % ## min,max and quartiles + % s(1:5,i) = statistics(col)(1:5); + s(1,i)=min(col); + s(5,i)=max(col); + s(2,i)=myprctilecol(col,25); + s(3,i)=myprctilecol(col,50); + s(4,i)=myprctilecol(col,75); + + + + + + + + + % ## confidence interval for the median + est = 1.57*(s(4,i)-s(2,i))/sqrt(nd); + s(6,i) = max([s(3,i)-est, s(2,i)]); + s(7,i) = min([s(3,i)+est, s(4,i)]); + % ## whiskers out to the last point within the desired inter-quartile range + IQR = maxwhisker*(s(4,i)-s(2,i)); + whisker_y(:,i) = [min(col(col >= s(2,i)-IQR)); s(2,i)]; + whisker_y(:,nc+i) = [max(col(col <= s(4,i)+IQR)); s(4,i)]; + % ## outliers beyond 1 and 2 inter-quartile ranges + outliers = col((col < s(2,i)-IQR & col >= s(2,i)-2*IQR) | (col > s(4,i)+IQR & col <= s(4,i)+2*IQR)); + outliers2 = col(col < s(2,i)-2*IQR | col > s(4,i)+2*IQR); + outliers_x = [outliers_x; i*ones(size(outliers))]; + outliers_y = [outliers_y; outliers]; + outliers2_x = [outliers2_x; i*ones(size(outliers2))]; + outliers2_y = [outliers2_y; outliers2]; + elseif (nd == 1) + % ## all statistics collapse to the value of the point + s(:,i) = col; + % ## single point data sets are plotted as outliers. + outliers_x = [outliers_x; i]; + outliers_y = [outliers_y; col]; + else + % ## no statistics if no points + s(:,i) = NaN; + end end % % % % if isempty(outliers2_y) % % % % outliers2_y= % ## Note which boxes don't have enough stats chop = find(box <= 1); - + % ## Draw a box around the quartiles, with width proportional to the number of % ## items in the box. Draw notches if desired. box = box*0.23/max(box); @@ -154,25 +154,25 @@ MM=max(max(data)); if vertical plot (quartile_x, quartile_y, 'b', ... - whisker_x, whisker_y, 'b--', ... - cap_x, cap_y, 'k', ... - median_x, median_y, 'r', ... - outliers_x, outliers_y, [symbol(1),'r'], ... - outliers2_x, outliers2_y, [symbol(2),'r']); - set(gca,'XTick',1:nc); - set(gca, 'XLim', [0.5, nc+0.5]); - set(gca, 'YLim', [mm-(MM-mm)*0.05-eps, MM+(MM-mm)*0.05+eps]); + whisker_x, whisker_y, 'b--', ... + cap_x, cap_y, 'k', ... + median_x, median_y, 'r', ... + outliers_x, outliers_y, [symbol(1),'r'], ... + outliers2_x, outliers2_y, [symbol(2),'r']); + set(gca,'XTick',1:nc); + set(gca, 'XLim', [0.5, nc+0.5]); + set(gca, 'YLim', [mm-(MM-mm)*0.05-eps, MM+(MM-mm)*0.05+eps]); else -% % % % % plot (quartile_y, quartile_x, "b;;", -% % % % % whisker_y, whisker_x, "b;;", -% % % % % cap_y, cap_x, "b;;", -% % % % % median_y, median_x, "r;;", -% % % % % outliers_y, outliers_x, [symbol(1),"r;;"], -% % % % % outliers2_y, outliers2_x, [symbol(2),"r;;"]); + % % % % % plot (quartile_y, quartile_x, "b;;", + % % % % % whisker_y, whisker_x, "b;;", + % % % % % cap_y, cap_x, "b;;", + % % % % % median_y, median_x, "r;;", + % % % % % outliers_y, outliers_x, [symbol(1),"r;;"], + % % % % % outliers2_y, outliers2_x, [symbol(2),"r;;"]); end if nargout, - sout=s; + sout=s; end % % % endfunction \ No newline at end of file diff --git a/matlab/gsa/myprctilecol.m b/matlab/gsa/myprctilecol.m index a71d21687c..b6f8e26614 100644 --- a/matlab/gsa/myprctilecol.m +++ b/matlab/gsa/myprctilecol.m @@ -27,10 +27,10 @@ xx = sort(x); if m==1 | n==1 m = max(m,n); - if m == 1, - y = x*ones(length(p),1); - return; - end + if m == 1, + y = x*ones(length(p),1); + return; + end n = 1; q = 100*(0.5:m - 0.5)./m; xx = [min(x); xx(:); max(x)]; diff --git a/matlab/gsa/pick.m b/matlab/gsa/pick.m index 87838acc55..9b6894c8dc 100644 --- a/matlab/gsa/pick.m +++ b/matlab/gsa/pick.m @@ -1,90 +1,90 @@ -function pick -% -% Copyright (C) 2001-2017 European Commission -% -% This file is part of GLUEWIN -% GLUEWIN is a MATLAB code designed for analysing the output -% of Monte Carlo runs when empirical observations of the model output are available -% and implements the GSA-GLUE methodology by Ratto et al. [1], based on a combination -% of GLUE (Generalised Likelihood Uncertainty Estimation) by K. Beven [2] and GSA -% Global Sensitivity Analysis) [3].'] -% The program has been developed by M. Ratto, European Commission, Joint Research Centre, -% Institute for the Protection and Security of The Citizen, Technological and Economic Risk Management, -% Applied Statistics, as a deliverable of the IMPACT project -% (EC Fifth Framework Programme, SCA Project, IST-1999-11313, DG-INFSO). -% -% The graphical layout of the code is inspired by the freeware GLUE package by K. Beven, -% vailable at the Lancaster University web site on the page [4]: -% http://www.es.lancs.ac.uk/hfdg/glue.html -% to which the GLUEWIN code introduces several extensions and additional options. -% Thanks are due to R. Girardi, A. Rossi, A. Saltelli, S. Tarantola and U. Callies for numerous -% comments and suggestions. -% For more information, please contact marco.ratto@ec.europa.eu -% -% Disclaimer: This software has been developed at the Joint Research Centre of European Commission -% by officers in the course of their official duties. This software is not subject to copyright -% protection and is in the public domain. It is an experimental system. The Joint Research Centre -% of European Commission assumes no responsibility whatsoever for its use by other parties -% and makes no guarantees, expressed or implied, about its quality, reliability, or any other -% characteristic. We would appreciate acknowledgement if the software is used. -% -% [1] Ratto, M., Tarantola, S., A. Saltelli, Sensitivity analysis in model calibration: GSA-GLUE approach. -% 'Computer Physics Communications, 136, 2001, 212-224 -% [2] Beven K.J., Binley A., The Future of Distributed Models: Model Calibration and Uncertainty -% 'Prediction, Hydrological Processes, 6, 279-298, 1992 -% [3] Saltelli, A., K. Chan, M. Scott, Editors, (2000), Sensitivity analysis, John Wiley & Sons -% 'publishers, Probability and Statistics series. -% [4] Beven K., GLUE for Windows User manual, 1998. - - - -pmenu=findobj(gcf,'type','uicontextmenu','Tag','Run viewer'); -button1=findobj(gcf,'type','uimenu','Tag','save params'); -button2=findobj(gcf,'type','uimenu','Tag','eval params'); -%button=get(pmenu,'children'); -gg=gco; -ax0=gca; -set(gg,'buttondownfcn',[]); -c=get(gca,'currentpoint'); -x=c(1,1); -y=c(1,2); -X=get(gco,'xdata'); -Y=get(gco,'ydata'); -dx=get(gca,'xlim'); -dy=get(gca,'ylim'); -pos=get(gca,'position'); -scalex=dx(2)-dx(1); -scaley=dy(2)-dy(1); -if length(X)>1, - K = dsearchn([(Y./scaley)' (X./scalex)'],[y/scaley x/scalex]); -else - az=get(gca,'children'); - T =get(az(end),'ydata'); - [dum K]=max(T); -end - -KK=K; - -set(button1,'Label',['Save ',num2str(K)],'Callback',['scatter_callback(',num2str(KK),',''save'')']); -set(button2,'Label',['Eval ',num2str(K)],'Callback',['scatter_callback(',num2str(KK),',''eval'')']); -hh=findobj(gcf,'type','axes','Tag','scatter'); -for k=1:length(hh), - axes(hh(k)); - dum=get(gca,'children'); - dumx=get(dum(end),'xdata'); - dumy=get(dum(end),'ydata'); - xmid=min(dumx) + 0.5*(max(dumx)-min(dumx)); - hold on - plot(dumx(KK),dumy(KK),'or'); - if dumx(KK) < xmid, - text(dumx(KK),dumy(KK),[' ',num2str(K)], ... - 'FontWeight','Bold',... - 'Color','r'); - else - text(dumx(KK),dumy(KK),[num2str(K),' '], ... - 'HorizontalAlignment','right', ... - 'FontWeight','Bold',... - 'Color','r'); - end - hold off +function pick +% +% Copyright (C) 2001-2017 European Commission +% +% This file is part of GLUEWIN +% GLUEWIN is a MATLAB code designed for analysing the output +% of Monte Carlo runs when empirical observations of the model output are available +% and implements the GSA-GLUE methodology by Ratto et al. [1], based on a combination +% of GLUE (Generalised Likelihood Uncertainty Estimation) by K. Beven [2] and GSA +% Global Sensitivity Analysis) [3].'] +% The program has been developed by M. Ratto, European Commission, Joint Research Centre, +% Institute for the Protection and Security of The Citizen, Technological and Economic Risk Management, +% Applied Statistics, as a deliverable of the IMPACT project +% (EC Fifth Framework Programme, SCA Project, IST-1999-11313, DG-INFSO). +% +% The graphical layout of the code is inspired by the freeware GLUE package by K. Beven, +% vailable at the Lancaster University web site on the page [4]: +% http://www.es.lancs.ac.uk/hfdg/glue.html +% to which the GLUEWIN code introduces several extensions and additional options. +% Thanks are due to R. Girardi, A. Rossi, A. Saltelli, S. Tarantola and U. Callies for numerous +% comments and suggestions. +% For more information, please contact marco.ratto@ec.europa.eu +% +% Disclaimer: This software has been developed at the Joint Research Centre of European Commission +% by officers in the course of their official duties. This software is not subject to copyright +% protection and is in the public domain. It is an experimental system. The Joint Research Centre +% of European Commission assumes no responsibility whatsoever for its use by other parties +% and makes no guarantees, expressed or implied, about its quality, reliability, or any other +% characteristic. We would appreciate acknowledgement if the software is used. +% +% [1] Ratto, M., Tarantola, S., A. Saltelli, Sensitivity analysis in model calibration: GSA-GLUE approach. +% 'Computer Physics Communications, 136, 2001, 212-224 +% [2] Beven K.J., Binley A., The Future of Distributed Models: Model Calibration and Uncertainty +% 'Prediction, Hydrological Processes, 6, 279-298, 1992 +% [3] Saltelli, A., K. Chan, M. Scott, Editors, (2000), Sensitivity analysis, John Wiley & Sons +% 'publishers, Probability and Statistics series. +% [4] Beven K., GLUE for Windows User manual, 1998. + + + +pmenu=findobj(gcf,'type','uicontextmenu','Tag','Run viewer'); +button1=findobj(gcf,'type','uimenu','Tag','save params'); +button2=findobj(gcf,'type','uimenu','Tag','eval params'); +%button=get(pmenu,'children'); +gg=gco; +ax0=gca; +set(gg,'buttondownfcn',[]); +c=get(gca,'currentpoint'); +x=c(1,1); +y=c(1,2); +X=get(gco,'xdata'); +Y=get(gco,'ydata'); +dx=get(gca,'xlim'); +dy=get(gca,'ylim'); +pos=get(gca,'position'); +scalex=dx(2)-dx(1); +scaley=dy(2)-dy(1); +if length(X)>1, + K = dsearchn([(Y./scaley)' (X./scalex)'],[y/scaley x/scalex]); +else + az=get(gca,'children'); + T =get(az(end),'ydata'); + [dum K]=max(T); +end + +KK=K; + +set(button1,'Label',['Save ',num2str(K)],'Callback',['scatter_callback(',num2str(KK),',''save'')']); +set(button2,'Label',['Eval ',num2str(K)],'Callback',['scatter_callback(',num2str(KK),',''eval'')']); +hh=findobj(gcf,'type','axes','Tag','scatter'); +for k=1:length(hh), + axes(hh(k)); + dum=get(gca,'children'); + dumx=get(dum(end),'xdata'); + dumy=get(dum(end),'ydata'); + xmid=min(dumx) + 0.5*(max(dumx)-min(dumx)); + hold on + plot(dumx(KK),dumy(KK),'or'); + if dumx(KK) < xmid, + text(dumx(KK),dumy(KK),[' ',num2str(K)], ... + 'FontWeight','Bold',... + 'Color','r'); + else + text(dumx(KK),dumy(KK),[num2str(K),' '], ... + 'HorizontalAlignment','right', ... + 'FontWeight','Bold',... + 'Color','r'); + end + hold off end \ No newline at end of file diff --git a/matlab/gsa/prior_draw_gsa.m b/matlab/gsa/prior_draw_gsa.m index a54fda1b3b..cdb795f0a8 100644 --- a/matlab/gsa/prior_draw_gsa.m +++ b/matlab/gsa/prior_draw_gsa.m @@ -38,7 +38,7 @@ function pdraw = prior_draw_gsa(init,rdraw) global bayestopt_ options_ estim_params_ M_ persistent npar pshape p6 p7 p3 p4 lbcum ubcum - + if init pshape = bayestopt_.pshape; p6 = bayestopt_.p6; @@ -56,40 +56,40 @@ if init bounds.lb = max(bounds.lb,lb); bounds.ub = min(bounds.ub,ub); else % estimated parameters but no declared priors - % No priors are declared so Dynare will estimate the model by - % maximum likelihood with inequality constraints for the parameters. + % No priors are declared so Dynare will estimate the model by + % maximum likelihood with inequality constraints for the parameters. bounds.lb = lb; bounds.ub = ub; end % set bounds for cumulative probabilities for i = 1:npar - switch pshape(i) - case 5% Uniform prior. - p4(i) = min(p4(i),bounds.ub(i)); - p3(i) = max(p3(i),bounds.lb(i)); - case 3% Gaussian prior. - lbcum(i) = 0.5 * erfc(-(bounds.lb(i)-p6(i))/p7(i) ./ sqrt(2)); - ubcum(i) = 0.5 * erfc(-(bounds.ub(i)-p6(i))/p7(i) ./ sqrt(2)); - case 2% Gamma prior. - lbcum(i) = gamcdf(bounds.lb(i)-p3(i),p6(i),p7(i)); - ubcum(i) = gamcdf(bounds.ub(i)-p3(i),p6(i),p7(i)); - case 1% Beta distribution (TODO: generalized beta distribution) - lbcum(i) = betainc((bounds.lb(i)-p3(i))./(p4(i)-p3(i)),p6(i),p7(i)); - ubcum(i) = betainc((bounds.ub(i)-p3(i))./(p4(i)-p3(i)),p6(i),p7(i)); - case 4% INV-GAMMA1 distribution - % TO BE CHECKED - lbcum(i) = gamcdf(1/(bounds.ub(i)-p3(i))^2,p7(i)/2,2/p6(i)); - ubcum(i) = gamcdf(1/(bounds.lb(i)-p3(i))^2,p7(i)/2,2/p6(i)); - case 6% INV-GAMMA2 distribution - % TO BE CHECKED - lbcum(i) = gamcdf(1/(bounds.ub(i)-p3(i)),p7(i)/2,2/p6(i)); - ubcum(i) = gamcdf(1/(bounds.lb(i)-p3(i)),p7(i)/2,2/p6(i)); - case 8 - lbcum(i) = weibcdf(bounds.lb(i)-p3(i),p6(i),p7(i)); - ubcum(i) = weibcdf(bounds.ub(i)-p3(i),p6(i),p7(i)); - otherwise - % Nothing to do here. - end + switch pshape(i) + case 5% Uniform prior. + p4(i) = min(p4(i),bounds.ub(i)); + p3(i) = max(p3(i),bounds.lb(i)); + case 3% Gaussian prior. + lbcum(i) = 0.5 * erfc(-(bounds.lb(i)-p6(i))/p7(i) ./ sqrt(2)); + ubcum(i) = 0.5 * erfc(-(bounds.ub(i)-p6(i))/p7(i) ./ sqrt(2)); + case 2% Gamma prior. + lbcum(i) = gamcdf(bounds.lb(i)-p3(i),p6(i),p7(i)); + ubcum(i) = gamcdf(bounds.ub(i)-p3(i),p6(i),p7(i)); + case 1% Beta distribution (TODO: generalized beta distribution) + lbcum(i) = betainc((bounds.lb(i)-p3(i))./(p4(i)-p3(i)),p6(i),p7(i)); + ubcum(i) = betainc((bounds.ub(i)-p3(i))./(p4(i)-p3(i)),p6(i),p7(i)); + case 4% INV-GAMMA1 distribution + % TO BE CHECKED + lbcum(i) = gamcdf(1/(bounds.ub(i)-p3(i))^2,p7(i)/2,2/p6(i)); + ubcum(i) = gamcdf(1/(bounds.lb(i)-p3(i))^2,p7(i)/2,2/p6(i)); + case 6% INV-GAMMA2 distribution + % TO BE CHECKED + lbcum(i) = gamcdf(1/(bounds.ub(i)-p3(i)),p7(i)/2,2/p6(i)); + ubcum(i) = gamcdf(1/(bounds.lb(i)-p3(i)),p7(i)/2,2/p6(i)); + case 8 + lbcum(i) = weibcdf(bounds.lb(i)-p3(i),p6(i),p7(i)); + ubcum(i) = weibcdf(bounds.ub(i)-p3(i),p6(i),p7(i)); + otherwise + % Nothing to do here. + end end return end @@ -107,10 +107,10 @@ for i = 1:npar case 1% Beta distribution (TODO: generalized beta distribution) pdraw(:,i) = betainv(rdraw(:,i),p6(i),p7(i))*(p4(i)-p3(i))+p3(i); case 4% INV-GAMMA1 distribution - % TO BE CHECKED + % TO BE CHECKED pdraw(:,i) = sqrt(1./gaminv(rdraw(:,i),p7(i)/2,2/p6(i)))+p3(i); case 6% INV-GAMMA2 distribution - % TO BE CHECKED + % TO BE CHECKED pdraw(:,i) = 1./gaminv(rdraw(:,i),p7(i)/2,2/p6(i))+p3(i); case 8 pdraw(:,i) = wblinv(rdraw(:,i),p6(i),p7(i))+p3(i); @@ -119,4 +119,4 @@ for i = 1:npar end end - + diff --git a/matlab/gsa/read_data.m b/matlab/gsa/read_data.m index 85674bc5e2..bbb2d80a7a 100644 --- a/matlab/gsa/read_data.m +++ b/matlab/gsa/read_data.m @@ -30,15 +30,15 @@ gend = options_.nobs; rawdata = rawdata(options_.first_obs:options_.first_obs+gend-1,:); if options_.loglinear == 1 & ~options_.logdata - rawdata = log(rawdata); + rawdata = log(rawdata); end if options_.prefilter == 1 - data = transpose(rawdata-ones(gend,1)* mean(rawdata,1)); + data = transpose(rawdata-ones(gend,1)* mean(rawdata,1)); else - data = transpose(rawdata); + data = transpose(rawdata); end if ~isreal(rawdata) - error(['There are complex values in the data. Probably a wrong' ... - ' transformation']) + error(['There are complex values in the data. Probably a wrong' ... + ' transformation']) end diff --git a/matlab/gsa/redform_map.m b/matlab/gsa/redform_map.m index c7b2573254..5f2c712920 100644 --- a/matlab/gsa/redform_map.m +++ b/matlab/gsa/redform_map.m @@ -429,7 +429,7 @@ end if isempty(threshold) && ~options_.nograph, if ilog==0, hfig=dyn_figure(options_.nodisplay,'name','Reduced Form GSA'); %bar(si) - % boxplot(si','whis',10,'symbol','r.') + % boxplot(si','whis',10,'symbol','r.') myboxplot(si',[],'.',[],10) xlabel(' ') set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) @@ -445,7 +445,7 @@ if isempty(threshold) && ~options_.nograph, else hfig=dyn_figure(options_.nodisplay,'name','Reduced Form GSA'); %bar(silog) - % boxplot(silog','whis',10,'symbol','r.') + % boxplot(silog','whis',10,'symbol','r.') myboxplot(silog',[],'.',[],10) set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) xlabel(' ') @@ -494,15 +494,15 @@ if iload==0, nest=min(250,nest); nfit=min(1000,nrun); % dotheplots = (nfit<=nest); -% gsa_ = gsa_sdp(y0(1:nest), x0(1:nest,:), 2, [],[-1 -1 -1 -1 -1 0],[],0,[fname,'_est'], pnames); + % gsa_ = gsa_sdp(y0(1:nest), x0(1:nest,:), 2, [],[-1 -1 -1 -1 -1 0],[],0,[fname,'_est'], pnames); [ys,is] = sort(y0); istep = ceil(nrun/nest); if istep>1, - iest = is(floor(istep/2):istep:end); - nest = length(iest); - irest = is(setdiff([1:nrun],[floor(istep/2):istep:nrun])); - istep = ceil(length(irest)/(nfit-nest)); - ifit = union(iest, irest(1:istep:end)); + iest = is(floor(istep/2):istep:end); + nest = length(iest); + irest = is(setdiff([1:nrun],[floor(istep/2):istep:nrun])); + istep = ceil(length(irest)/(nfit-nest)); + ifit = union(iest, irest(1:istep:end)); else warning('the number of samples is too small for ANOVA estimation') si=nan(np,1); @@ -512,9 +512,9 @@ if iload==0, ifit = union(ifit, irest(end)); end nfit=length(ifit); -% ifit = union(iest, irest(randperm(nrun-nest,nfit-nest))); -% ifit = iest; -% nfit=nest; + % ifit = union(iest, irest(randperm(nrun-nest,nfit-nest))); + % ifit = iest; + % nfit=nest; ipred = setdiff([1:nrun],ifit); if ilog, @@ -544,61 +544,61 @@ if iload==0, if ilog, [gsa22, gsa1, gsax] = ss_anova_log(y1(iest), x0(iest,:), isig, lam, gsa0); end -% if (gsa1.out.bic-gsa0.out.bic) < 10, -% y00=y0; -% gsa00=gsa0; -% gsa0=gsa1; -% y0=y1; -% ilog=1; -% end -if nfit>nest, - % gsa_ = gsa_sdp(y0(1:nfit), x0(1:nfit,:), -2, gsa_.nvr*nest^3/nfit^3,[-1 -1 -1 -1 -1 0],[],0,fname, pnames); - nvr = gsa0.nvr*nest^3/nfit^3; - nvr(gsa0.stat<2) = gsa0.nvr(gsa0.stat<2)*nest^5/nfit^5; - gsa_ = ss_anova(y0(ifit), x0(ifit,:), 1, 0, 2, nvr); - if ilog - gsa0 = gsa_; - nvr1 = gsa1.nvr*nest^3/nfit^3; - nvr1(gsa1.stat<2) = gsa1.nvr(gsa1.stat<2)*nest^5/nfit^5; - nvrx = gsax.nvr*nest^3/nfit^3; - nvrx(gsax.stat<2) = gsax.nvr(gsax.stat<2)*nest^5/nfit^5; - [gsa22, gsa1, gsax] = ss_anova_log(y1(ifit), x0(ifit,:), isig, lam, gsa0, [nvr1' nvrx']); -% gsa1 = ss_anova(y1(ifit), x0(ifit,:), 1, 0, 2, nvr); -% gsa2=gsa1; -% gsa2.y = gsa0.y; -% gsa2.fit = (exp(gsa1.fit)-lam)*isig; -% gsa2.f0 = mean(gsa2.fit); -% gsa2.out.SSE = sum((gsa2.fit-gsa2.y).^2); -% gsa2.out.bic = gsa2.out.bic-nest*log(gsa1.out.SSE)+nest*log(gsa2.out.SSE); -% gsa2.r2 = 1-cov(gsa2.fit-gsa2.y)/cov(gsa2.y); -% for j=1:np, -% gsa2.fs(:,j) = exp(gsa1.fs(:,j)).*mean(exp(gsa1.fit-gsa1.f(:,j)))*isig-lam*isig-gsa2.f0; -% gsa2.f(:,j) = exp(gsa1.f(:,j)).*mean(exp(gsa1.fit-gsa1.f(:,j)))*isig-lam*isig-gsa2.f0; -% gsa2.si(j) = var(gsa2.f(:,j))/var(gsa2.y); -% end -% nvr = gsax.nvr*nest^3/nfit^3; -% nvr(gsax.stat<2) = gsax.nvr(gsax.stat<2)*nest^5/nfit^5; -% gsax = ss_anova([gsa2.y-gsa2.fit], x0(ifit,:), 1, 0, 2, nvr); -% gsa22=gsa2; -% gsa22.fit = gsa2.fit+gsax.fit; -% gsa22.f0 = mean(gsa22.fit); -% gsa22.out.SSE = sum((gsa22.fit-gsa22.y).^2); -% gsa22.out.bic = nest*log(gsa22.out.SSE/nest) + (gsax.out.df+gsa2.out.df-1)*log(nest); -% gsa22.r2 = 1-sum((gsa22.fit-gsa22.y).^2)/sum((gsa22.y-mean(gsa22.y)).^2); -% for j=1:np, -% gsa22.fs(:,j) = gsa2.fs(:,j)+gsax.fs(:,j); -% gsa22.f(:,j) = gsa2.f(:,j)+gsax.f(:,j); -% gsa22.si(j) = var(gsa22.f(:,j))/var(gsa22.y); -% end - gsa_ = gsa22; - end -else - if ilog - gsa_ = gsa22; + % if (gsa1.out.bic-gsa0.out.bic) < 10, + % y00=y0; + % gsa00=gsa0; + % gsa0=gsa1; + % y0=y1; + % ilog=1; + % end + if nfit>nest, + % gsa_ = gsa_sdp(y0(1:nfit), x0(1:nfit,:), -2, gsa_.nvr*nest^3/nfit^3,[-1 -1 -1 -1 -1 0],[],0,fname, pnames); + nvr = gsa0.nvr*nest^3/nfit^3; + nvr(gsa0.stat<2) = gsa0.nvr(gsa0.stat<2)*nest^5/nfit^5; + gsa_ = ss_anova(y0(ifit), x0(ifit,:), 1, 0, 2, nvr); + if ilog + gsa0 = gsa_; + nvr1 = gsa1.nvr*nest^3/nfit^3; + nvr1(gsa1.stat<2) = gsa1.nvr(gsa1.stat<2)*nest^5/nfit^5; + nvrx = gsax.nvr*nest^3/nfit^3; + nvrx(gsax.stat<2) = gsax.nvr(gsax.stat<2)*nest^5/nfit^5; + [gsa22, gsa1, gsax] = ss_anova_log(y1(ifit), x0(ifit,:), isig, lam, gsa0, [nvr1' nvrx']); + % gsa1 = ss_anova(y1(ifit), x0(ifit,:), 1, 0, 2, nvr); + % gsa2=gsa1; + % gsa2.y = gsa0.y; + % gsa2.fit = (exp(gsa1.fit)-lam)*isig; + % gsa2.f0 = mean(gsa2.fit); + % gsa2.out.SSE = sum((gsa2.fit-gsa2.y).^2); + % gsa2.out.bic = gsa2.out.bic-nest*log(gsa1.out.SSE)+nest*log(gsa2.out.SSE); + % gsa2.r2 = 1-cov(gsa2.fit-gsa2.y)/cov(gsa2.y); + % for j=1:np, + % gsa2.fs(:,j) = exp(gsa1.fs(:,j)).*mean(exp(gsa1.fit-gsa1.f(:,j)))*isig-lam*isig-gsa2.f0; + % gsa2.f(:,j) = exp(gsa1.f(:,j)).*mean(exp(gsa1.fit-gsa1.f(:,j)))*isig-lam*isig-gsa2.f0; + % gsa2.si(j) = var(gsa2.f(:,j))/var(gsa2.y); + % end + % nvr = gsax.nvr*nest^3/nfit^3; + % nvr(gsax.stat<2) = gsax.nvr(gsax.stat<2)*nest^5/nfit^5; + % gsax = ss_anova([gsa2.y-gsa2.fit], x0(ifit,:), 1, 0, 2, nvr); + % gsa22=gsa2; + % gsa22.fit = gsa2.fit+gsax.fit; + % gsa22.f0 = mean(gsa22.fit); + % gsa22.out.SSE = sum((gsa22.fit-gsa22.y).^2); + % gsa22.out.bic = nest*log(gsa22.out.SSE/nest) + (gsax.out.df+gsa2.out.df-1)*log(nest); + % gsa22.r2 = 1-sum((gsa22.fit-gsa22.y).^2)/sum((gsa22.y-mean(gsa22.y)).^2); + % for j=1:np, + % gsa22.fs(:,j) = gsa2.fs(:,j)+gsax.fs(:,j); + % gsa22.f(:,j) = gsa2.f(:,j)+gsax.f(:,j); + % gsa22.si(j) = var(gsa22.f(:,j))/var(gsa22.y); + % end + gsa_ = gsa22; + end else - gsa_ = gsa0; + if ilog + gsa_ = gsa22; + else + gsa_ = gsa0; + end end -end save([fname,'_map.mat'],'gsa_') [sidum, iii]=sort(-gsa_.si); gsa_.x0=x00(ifit,:); @@ -613,13 +613,13 @@ end subplot(223), plot(y0(ifit),[gsa_.fit y0(ifit)],'.'), r2 = gsa_.r2; -% if ilog, -% plot(y00(ifit),[log_trans_(gsa_.fit,'',isig,lam) y00(ifit)],'.'), -% r2 = 1 - cov(log_trans_(gsa_.fit,'',isig,lam)-y00(ifit))/cov(y00(ifit)); -% else -% plot(y0(ifit),[gsa_.fit y0(ifit)],'.'), -% r2 = gsa_.r2; -% end + % if ilog, + % plot(y00(ifit),[log_trans_(gsa_.fit,'',isig,lam) y00(ifit)],'.'), + % r2 = 1 - cov(log_trans_(gsa_.fit,'',isig,lam)-y00(ifit))/cov(y00(ifit)); + % else + % plot(y0(ifit),[gsa_.fit y0(ifit)],'.'), + % r2 = gsa_.r2; + % end title(['Learning sample fit - R2=' num2str(r2,2)],'interpreter','none') if nfit<nrun, if ilog, @@ -643,7 +643,7 @@ end end else % gsa_ = gsa_sdp_dyn(y0, x0, 0, [],[],[],0,fname, pnames); -% gsa_ = gsa_sdp(y0, x0, 0, [],[],[],0,fname, pnames); + % gsa_ = gsa_sdp(y0, x0, 0, [],[],[],0,fname, pnames); load([fname,'_map.mat'],'gsa_') if ~options_.nograph, yf = ss_anova_fcast(x0, gsa_); @@ -727,7 +727,7 @@ function indmcf = redform_mcf(y0, x0, options_mcf, options_) hfig=dyn_figure(options_.nodisplay,'name',options_mcf.amcf_title); [post_mean, post_median, post_var, hpd_interval, post_deciles, ... - density] = posterior_moments(y0,1,0.9); + density] = posterior_moments(y0,1,0.9); post_deciles = [-inf; post_deciles; inf]; for jt=1:10, @@ -763,16 +763,16 @@ aa(2)=0.02; set(hleg,'Position',aa); if ~isoctave annotation('textbox', [0.25,0.01,0.5,0.05], ... - 'String', options_mcf.title, ... - 'Color','black',... - 'FontWeight','bold',... - 'interpreter','none',... - 'horizontalalignment','center'); + 'String', options_mcf.title, ... + 'Color','black',... + 'FontWeight','bold',... + 'interpreter','none',... + 'horizontalalignment','center'); end dyn_saveas(hfig,[options_mcf.OutputDirectoryName filesep options_mcf.fname_,'_',options_mcf.amcf_name],options_.nodisplay,options_.graph_format); create_TeX_loader(options_,[options_mcf.OutputDirectoryName filesep options_mcf.fname_,'_',options_mcf.amcf_name],strrep(options_mcf.amcf_title,'_','\_'),[options_mcf.fname_,'_',options_mcf.amcf_name]) - + return function []=create_TeX_loader(options_,figpath,caption,label_name,scale_factor) diff --git a/matlab/gsa/redform_screen.m b/matlab/gsa/redform_screen.m index 311c6b520b..fd09d9cace 100644 --- a/matlab/gsa/redform_screen.m +++ b/matlab/gsa/redform_screen.m @@ -40,7 +40,7 @@ nliv = options_gsa_.morris_nliv; pnames = M_.param_names(estim_params_.param_vals(:,1),:); if nargin==0, - dirname=''; + dirname=''; end load([dirname,'/',M_.fname,'_prior'],'lpmat','lpmat0','istable','T'); @@ -54,92 +54,92 @@ nsok = length(find(M_.lead_lag_incidence(M_.maximum_lag,:))); js=0; for j=1:size(anamendo,1), - namendo=deblank(anamendo(j,:)); - iendo=strmatch(namendo,M_.endo_names(oo_.dr.order_var,:),'exact'); - - iplo=0; - ifig=0; - for jx=1:size(anamexo,1) - namexo=deblank(anamexo(jx,:)); - iexo=strmatch(namexo,M_.exo_names,'exact'); - - if ~isempty(iexo), - y0=teff(T(iendo,iexo+nspred,:),kn,istable); - if ~isempty(y0), - if mod(iplo,9)==0, - ifig=ifig+1; - hh=dyn_figure(options_.nodisplay,'name',[namendo,' vs. shocks ',int2str(ifig)]); - iplo=0; + namendo=deblank(anamendo(j,:)); + iendo=strmatch(namendo,M_.endo_names(oo_.dr.order_var,:),'exact'); + + iplo=0; + ifig=0; + for jx=1:size(anamexo,1) + namexo=deblank(anamexo(jx,:)); + iexo=strmatch(namexo,M_.exo_names,'exact'); + + if ~isempty(iexo), + y0=teff(T(iendo,iexo+nspred,:),kn,istable); + if ~isempty(y0), + if mod(iplo,9)==0, + ifig=ifig+1; + hh=dyn_figure(options_.nodisplay,'name',[namendo,' vs. shocks ',int2str(ifig)]); + iplo=0; + end + iplo=iplo+1; + js=js+1; + subplot(3,3,iplo), + [SAmeas, SAMorris] = Morris_Measure_Groups(np+nshock, [lpmat0 lpmat], y0,nliv); + SAM = squeeze(SAMorris(nshock+1:end,1)); + SA(:,js)=SAM./(max(SAM)+eps); + [saso, iso] = sort(-SA(:,js)); + bar(SA(iso(1:min(np,10)),js)) + %set(gca,'xticklabel',pnames(iso(1:min(np,10)),:),'fontsize',8) + set(gca,'xticklabel',' ','fontsize',10) + set(gca,'xlim',[0.5 10.5]) + for ip=1:min(np,10), + text(ip,-0.02,deblank(pnames(iso(ip),:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') + end + title([namendo,' vs. ',namexo],'interpreter','none') + if iplo==9, + dyn_saveas(hh,[dirname,'/',M_.fname,'_', namendo,'_vs_shock_',num2str(ifig)],options_.nodisplay,options_.graph_format); + create_TeX_loader(options_,[dirname,'/',M_.fname,'_', namendo,'_vs_shock_',num2str(ifig)],ifig,[namendo,' vs. shocks ',int2str(ifig)],[namendo,'_vs_shock'],1) + end + + end end - iplo=iplo+1; - js=js+1; - subplot(3,3,iplo), - [SAmeas, SAMorris] = Morris_Measure_Groups(np+nshock, [lpmat0 lpmat], y0,nliv); - SAM = squeeze(SAMorris(nshock+1:end,1)); - SA(:,js)=SAM./(max(SAM)+eps); - [saso, iso] = sort(-SA(:,js)); - bar(SA(iso(1:min(np,10)),js)) - %set(gca,'xticklabel',pnames(iso(1:min(np,10)),:),'fontsize',8) - set(gca,'xticklabel',' ','fontsize',10) - set(gca,'xlim',[0.5 10.5]) - for ip=1:min(np,10), - text(ip,-0.02,deblank(pnames(iso(ip),:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') - end - title([namendo,' vs. ',namexo],'interpreter','none') - if iplo==9, - dyn_saveas(hh,[dirname,'/',M_.fname,'_', namendo,'_vs_shock_',num2str(ifig)],options_.nodisplay,options_.graph_format); - create_TeX_loader(options_,[dirname,'/',M_.fname,'_', namendo,'_vs_shock_',num2str(ifig)],ifig,[namendo,' vs. shocks ',int2str(ifig)],[namendo,'_vs_shock'],1) - end - - end end - end - if iplo<9 && iplo>0 && ifig, - dyn_saveas(hh,[dirname,'/',M_.fname,'_', namendo,'_vs_shocks_',num2str(ifig)],options_.nodisplay,options_.graph_format); - create_TeX_loader(options_,[dirname,'/',M_.fname,'_', namendo,'_vs_shock_',num2str(ifig)],ifig,[namendo,' vs. shocks ',int2str(ifig)],[namendo,'_vs_shock'],options_.figures.textwidth*min(iplo/3)) - end - - iplo=0; - ifig=0; - for je=1:size(anamlagendo,1) - namlagendo=deblank(anamlagendo(je,:)); - ilagendo=strmatch(namlagendo,M_.endo_names(oo_.dr.order_var(M_.nstatic+1:M_.nstatic+nsok),:),'exact'); - - if ~isempty(ilagendo), - y0=teff(T(iendo,ilagendo,:),kn,istable); - if ~isempty(y0), - if mod(iplo,9)==0, - ifig=ifig+1; - hh=dyn_figure(options_.nodisplay,'name',[namendo,' vs. lagged endogenous ',int2str(ifig)]); - iplo=0; - end - iplo=iplo+1; - js=js+1; - subplot(3,3,iplo), - [SAmeas, SAMorris] = Morris_Measure_Groups(np+nshock, [lpmat0 lpmat], y0,nliv); - SAM = squeeze(SAMorris(nshock+1:end,1)); - SA(:,js)=SAM./(max(SAM)+eps); - [saso, iso] = sort(-SA(:,js)); - bar(SA(iso(1:min(np,10)),js)) - %set(gca,'xticklabel',pnames(iso(1:min(np,10)),:),'fontsize',8) - set(gca,'xticklabel',' ','fontsize',10) - set(gca,'xlim',[0.5 10.5]) - for ip=1:min(np,10), - text(ip,-0.02,deblank(pnames(iso(ip),:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') - end + if iplo<9 && iplo>0 && ifig, + dyn_saveas(hh,[dirname,'/',M_.fname,'_', namendo,'_vs_shocks_',num2str(ifig)],options_.nodisplay,options_.graph_format); + create_TeX_loader(options_,[dirname,'/',M_.fname,'_', namendo,'_vs_shock_',num2str(ifig)],ifig,[namendo,' vs. shocks ',int2str(ifig)],[namendo,'_vs_shock'],options_.figures.textwidth*min(iplo/3)) + end - title([namendo,' vs. ',namlagendo,'(-1)'],'interpreter','none') - if iplo==9, - dyn_saveas(hh,[dirname,'/',M_.fname,'_', namendo,'_vs_lags_',num2str(ifig)],options_.nodisplay,options_.graph_format); - create_TeX_loader(options_,[dirname,'/',M_.fname,'_', namendo,'_vs_lags_',num2str(ifig)],ifig,[namendo,' vs. lagged endogenous ',int2str(ifig)],[namendo,'_vs_lags'],1) + iplo=0; + ifig=0; + for je=1:size(anamlagendo,1) + namlagendo=deblank(anamlagendo(je,:)); + ilagendo=strmatch(namlagendo,M_.endo_names(oo_.dr.order_var(M_.nstatic+1:M_.nstatic+nsok),:),'exact'); + + if ~isempty(ilagendo), + y0=teff(T(iendo,ilagendo,:),kn,istable); + if ~isempty(y0), + if mod(iplo,9)==0, + ifig=ifig+1; + hh=dyn_figure(options_.nodisplay,'name',[namendo,' vs. lagged endogenous ',int2str(ifig)]); + iplo=0; + end + iplo=iplo+1; + js=js+1; + subplot(3,3,iplo), + [SAmeas, SAMorris] = Morris_Measure_Groups(np+nshock, [lpmat0 lpmat], y0,nliv); + SAM = squeeze(SAMorris(nshock+1:end,1)); + SA(:,js)=SAM./(max(SAM)+eps); + [saso, iso] = sort(-SA(:,js)); + bar(SA(iso(1:min(np,10)),js)) + %set(gca,'xticklabel',pnames(iso(1:min(np,10)),:),'fontsize',8) + set(gca,'xticklabel',' ','fontsize',10) + set(gca,'xlim',[0.5 10.5]) + for ip=1:min(np,10), + text(ip,-0.02,deblank(pnames(iso(ip),:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') + end + + title([namendo,' vs. ',namlagendo,'(-1)'],'interpreter','none') + if iplo==9, + dyn_saveas(hh,[dirname,'/',M_.fname,'_', namendo,'_vs_lags_',num2str(ifig)],options_.nodisplay,options_.graph_format); + create_TeX_loader(options_,[dirname,'/',M_.fname,'_', namendo,'_vs_lags_',num2str(ifig)],ifig,[namendo,' vs. lagged endogenous ',int2str(ifig)],[namendo,'_vs_lags'],1) + end + end end - end end - end - if iplo<9 && iplo>0 && ifig, - dyn_saveas(hh,[dirname,'/',M_.fname,'_', namendo,'_vs_lags_',num2str(ifig)],options_.nodisplay,options_.graph_format); - create_TeX_loader(options_,[dirname,'/',M_.fname,'_', namendo,'_vs_lags_',num2str(ifig)],ifig,[namendo,' vs. lagged endogenous ',int2str(ifig)],[namendo,'_vs_lags'],options_.figures.textwidth*min(iplo/3)) - end + if iplo<9 && iplo>0 && ifig, + dyn_saveas(hh,[dirname,'/',M_.fname,'_', namendo,'_vs_lags_',num2str(ifig)],options_.nodisplay,options_.graph_format); + create_TeX_loader(options_,[dirname,'/',M_.fname,'_', namendo,'_vs_lags_',num2str(ifig)],ifig,[namendo,' vs. lagged endogenous ',int2str(ifig)],[namendo,'_vs_lags'],options_.figures.textwidth*min(iplo/3)) + end end hh=dyn_figure(options_.nodisplay,'Name','Reduced form screening'); @@ -151,7 +151,7 @@ set(gca,'xlim',[0.5 np+0.5]) set(gca,'ylim',[0 1]) set(gca,'position',[0.13 0.2 0.775 0.7]) for ip=1:np, - text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') + text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') end xlabel(' ') ylabel('Elementary Effects') diff --git a/matlab/gsa/scatter_callback.m b/matlab/gsa/scatter_callback.m index 84b7d9ec06..afba86225b 100644 --- a/matlab/gsa/scatter_callback.m +++ b/matlab/gsa/scatter_callback.m @@ -32,11 +32,11 @@ x=x{2}; xparam1=x(K,:)'; switch type - case 'save' - save(['my_params_' int2str(K)],'xparam1') - - case 'eval' - disp('Evaluating smoother ...') - [oo_, M_]=evaluate_smoother(xparam1,M_.endo_names,M_,oo_,options_,bayestopt_,estim_params_); - % [rmse, lnam, r2,vv] = plot_fit(obsname{:}); + case 'save' + save(['my_params_' int2str(K)],'xparam1') + + case 'eval' + disp('Evaluating smoother ...') + [oo_, M_]=evaluate_smoother(xparam1,M_.endo_names,M_,oo_,options_,bayestopt_,estim_params_); + % [rmse, lnam, r2,vv] = plot_fit(obsname{:}); end diff --git a/matlab/gsa/scatter_mcf.m b/matlab/gsa/scatter_mcf.m index fa42293750..3718b23ed0 100644 --- a/matlab/gsa/scatter_mcf.m +++ b/matlab/gsa/scatter_mcf.m @@ -1,183 +1,183 @@ -function scatter_mcf(X,Y,vnames,plotsymbol, fnam, dirname, figtitle, xparam1, DynareOptions, beha_name, non_beha_name) -% -% Written by Marco Ratto -% Joint Research Centre, The European Commission, -% marco.ratto@ec.europa.eu - -% Copyright (C) 2014-2016 European Commission -% Copyright (C) 2014-2017 Dynare Team -% -% This file is part of Dynare. -% -% Dynare is free software: you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation, either version 3 of the License, or -% (at your option) any later version. -% -% Dynare is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. -% -% You should have received a copy of the GNU General Public License -% along with Dynare. If not, see <http://www.gnu.org/licenses/>. - -% PURPOSE: Pairwise scatter plots of the columns of x and y after -% Monte Carlo filtering -%--------------------------------------------------- -% USAGE: scatter_mcf(x,y,vnames,pltsym,diagon) -% or scatter_mcf(x,y) which relies on defaults -% where: -% x = an nxk matrix with columns containing behavioural sample -% y = an mxk matrix with columns containing non-behavioural sample -% vnames = a vector of variable names -% (default = numeric labels 1,2,3 etc.) -% pltsym = a plt symbol -% (default = '.' for npts > 100, 'o' for npts < 100 - - -Z=[X;Y]; -[n,p] = size(X); -% X = X - ones(n,1)*min(Z); -% X = X ./ (ones(n,1)*max(Z)); -[n,p] = size(Y); -% Y = Y - ones(n,1)*min(Z); -% Y = Y ./ (ones(n,1)*max(Z)); -[n,p] = size(Z); -clear Z; - -nflag = 0; -if nargin >=3 - nflag = 1; -end; - -if nargin<4 || isempty(plotsymbol) - if n*p<100, plotsymbol = 'o'; - else plotsymbol = '.'; - end -end - -if nargin<5 - fnam=''; -end -if nargin<6, - dirname=''; - nograph=1; -else - nograph=0; -end -if nargin<7, - figtitle=fnam; -end -if nargin<8, - xparam1=[]; -end -if nargin<10, - beha_name = 'BEHAVIOUR'; - non_beha_name = 'NON-BEHAVIOUR'; -end -if nargin==10, - non_beha_name = ['NON-' beha_name]; -end - -figtitle_tex=strrep(figtitle,'_','\_'); - -fig_nam_=[fnam]; -if ~nograph, - hh=dyn_figure(DynareOptions.nodisplay,'name',figtitle); -end - -bf = 0.1; -ffs = 0.05/(p-1); -ffl = (1-2*bf-0.05)/p; -if p>1, - fL = linspace(bf,1-bf+ffs,p+1); -else - fL = bf; -end -for i = 1:p - for j = 1:p - h = axes('position',[fL(i),fL(p+1-j),ffl,ffl]); - if i==j - h1=cumplot(X(:,j)); - % set(h1,'color',[0 0 1], 'linestyle','--','LineWidth',1.5) - set(h1,'color',[0 0 1],'LineWidth',1.5) - hold on, - h2=cumplot(Y(:,j)); - set(h2,'color',[1 0 0],'LineWidth',1.5) - if ~isempty(xparam1) - hold on, plot(xparam1([j j]),[0 1],'k--') - end - if j<p - set(gca,'XTickLabel',[],'XTick',[]); - else - grid off - end - set(gca,'YTickLabel',[],'YTick',[]); - else - if j>i - plot(X(:,i),X(:,j),[plotsymbol,'b']) - hold on, - plot(Y(:,i),Y(:,j),[plotsymbol,'r']) - else - plot(Y(:,i),Y(:,j),[plotsymbol,'r']) - hold on, - plot(X(:,i),X(:,j),[plotsymbol,'b']) - end - if ~isempty(xparam1) - hold on, plot(xparam1(i),xparam1(j),'s','MarkerFaceColor',[0 0.75 0],'MarkerEdgeColor',[0 0.75 0]) - end - hold off; - % axis([-0.1 1.1 -0.1 1.1]) - if i<p, - set(gca,'YTickLabel',[],'YTick',[]); - else - set(gca,'yaxislocation','right'); - end - if j<p - set(gca,'XTickLabel',[],'XTick',[]); - end - end - if nflag == 1 - set(gca,'fontsize',9); - end; - if i==1 - if nflag == 1 - ylabel(vnames(j,:),'Rotation',45,'interpreter','none', ... - 'HorizontalAlignment','right','VerticalAlignment','middle'); - else - ylabel([num2str(j),' '],'Rotation',90) - end; - end - if j==1 - if nflag == 1 - title(vnames(i,:),'interpreter','none','Rotation',45, ... - 'HorizontalAlignment','left','VerticalAlignment','bottom') - else - title(num2str(i)) - end; - end - drawnow - end -end -if ~isoctave - annotation('textbox', [0.1,0,0.35,0.05],'String', beha_name,'Color','Blue','horizontalalignment','center','interpreter','none'); - annotation('textbox', [0.55,0,0.35,0.05],'String', non_beha_name,'Color','Red','horizontalalignment','center','interpreter','none'); -end - -if ~nograph, - dyn_saveas(hh,[dirname,filesep,fig_nam_],DynareOptions.nodisplay,DynareOptions.graph_format); - if DynareOptions.TeX && any(strcmp('eps',cellstr(DynareOptions.graph_format))) - fidTeX = fopen([dirname,'/',fig_nam_ '.tex'],'w'); - fprintf(fidTeX,'%% TeX eps-loader file generated by scatter_mcf.m (Dynare).\n'); - fprintf(fidTeX,['%% ' datestr(now,0) '\n\n']); - fprintf(fidTeX,'\\begin{figure}[H]\n'); - fprintf(fidTeX,'\\centering \n'); - fprintf(fidTeX,'\\includegraphics[width=0.8\\textwidth]{%s}\n',strrep([dirname,'/',fig_nam_],'\','/')); - fprintf(fidTeX,'\\caption{%s.}',figtitle_tex); - fprintf(fidTeX,'\\label{Fig:%s}\n',fig_nam_); - fprintf(fidTeX,'\\end{figure}\n\n'); - fprintf(fidTeX,'%% End Of TeX file. \n'); - fclose(fidTeX); - end +function scatter_mcf(X,Y,vnames,plotsymbol, fnam, dirname, figtitle, xparam1, DynareOptions, beha_name, non_beha_name) +% +% Written by Marco Ratto +% Joint Research Centre, The European Commission, +% marco.ratto@ec.europa.eu + +% Copyright (C) 2014-2016 European Commission +% Copyright (C) 2014-2017 Dynare Team +% +% This file is part of Dynare. +% +% Dynare is free software: you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation, either version 3 of the License, or +% (at your option) any later version. +% +% Dynare is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with Dynare. If not, see <http://www.gnu.org/licenses/>. + +% PURPOSE: Pairwise scatter plots of the columns of x and y after +% Monte Carlo filtering +%--------------------------------------------------- +% USAGE: scatter_mcf(x,y,vnames,pltsym,diagon) +% or scatter_mcf(x,y) which relies on defaults +% where: +% x = an nxk matrix with columns containing behavioural sample +% y = an mxk matrix with columns containing non-behavioural sample +% vnames = a vector of variable names +% (default = numeric labels 1,2,3 etc.) +% pltsym = a plt symbol +% (default = '.' for npts > 100, 'o' for npts < 100 + + +Z=[X;Y]; +[n,p] = size(X); +% X = X - ones(n,1)*min(Z); +% X = X ./ (ones(n,1)*max(Z)); +[n,p] = size(Y); +% Y = Y - ones(n,1)*min(Z); +% Y = Y ./ (ones(n,1)*max(Z)); +[n,p] = size(Z); +clear Z; + +nflag = 0; +if nargin >=3 + nflag = 1; +end; + +if nargin<4 || isempty(plotsymbol) + if n*p<100, plotsymbol = 'o'; + else plotsymbol = '.'; + end +end + +if nargin<5 + fnam=''; +end +if nargin<6, + dirname=''; + nograph=1; +else + nograph=0; +end +if nargin<7, + figtitle=fnam; +end +if nargin<8, + xparam1=[]; +end +if nargin<10, + beha_name = 'BEHAVIOUR'; + non_beha_name = 'NON-BEHAVIOUR'; +end +if nargin==10, + non_beha_name = ['NON-' beha_name]; +end + +figtitle_tex=strrep(figtitle,'_','\_'); + +fig_nam_=[fnam]; +if ~nograph, + hh=dyn_figure(DynareOptions.nodisplay,'name',figtitle); +end + +bf = 0.1; +ffs = 0.05/(p-1); +ffl = (1-2*bf-0.05)/p; +if p>1, + fL = linspace(bf,1-bf+ffs,p+1); +else + fL = bf; +end +for i = 1:p + for j = 1:p + h = axes('position',[fL(i),fL(p+1-j),ffl,ffl]); + if i==j + h1=cumplot(X(:,j)); + % set(h1,'color',[0 0 1], 'linestyle','--','LineWidth',1.5) + set(h1,'color',[0 0 1],'LineWidth',1.5) + hold on, + h2=cumplot(Y(:,j)); + set(h2,'color',[1 0 0],'LineWidth',1.5) + if ~isempty(xparam1) + hold on, plot(xparam1([j j]),[0 1],'k--') + end + if j<p + set(gca,'XTickLabel',[],'XTick',[]); + else + grid off + end + set(gca,'YTickLabel',[],'YTick',[]); + else + if j>i + plot(X(:,i),X(:,j),[plotsymbol,'b']) + hold on, + plot(Y(:,i),Y(:,j),[plotsymbol,'r']) + else + plot(Y(:,i),Y(:,j),[plotsymbol,'r']) + hold on, + plot(X(:,i),X(:,j),[plotsymbol,'b']) + end + if ~isempty(xparam1) + hold on, plot(xparam1(i),xparam1(j),'s','MarkerFaceColor',[0 0.75 0],'MarkerEdgeColor',[0 0.75 0]) + end + hold off; + % axis([-0.1 1.1 -0.1 1.1]) + if i<p, + set(gca,'YTickLabel',[],'YTick',[]); + else + set(gca,'yaxislocation','right'); + end + if j<p + set(gca,'XTickLabel',[],'XTick',[]); + end + end + if nflag == 1 + set(gca,'fontsize',9); + end; + if i==1 + if nflag == 1 + ylabel(vnames(j,:),'Rotation',45,'interpreter','none', ... + 'HorizontalAlignment','right','VerticalAlignment','middle'); + else + ylabel([num2str(j),' '],'Rotation',90) + end; + end + if j==1 + if nflag == 1 + title(vnames(i,:),'interpreter','none','Rotation',45, ... + 'HorizontalAlignment','left','VerticalAlignment','bottom') + else + title(num2str(i)) + end; + end + drawnow + end +end +if ~isoctave + annotation('textbox', [0.1,0,0.35,0.05],'String', beha_name,'Color','Blue','horizontalalignment','center','interpreter','none'); + annotation('textbox', [0.55,0,0.35,0.05],'String', non_beha_name,'Color','Red','horizontalalignment','center','interpreter','none'); +end + +if ~nograph, + dyn_saveas(hh,[dirname,filesep,fig_nam_],DynareOptions.nodisplay,DynareOptions.graph_format); + if DynareOptions.TeX && any(strcmp('eps',cellstr(DynareOptions.graph_format))) + fidTeX = fopen([dirname,'/',fig_nam_ '.tex'],'w'); + fprintf(fidTeX,'%% TeX eps-loader file generated by scatter_mcf.m (Dynare).\n'); + fprintf(fidTeX,['%% ' datestr(now,0) '\n\n']); + fprintf(fidTeX,'\\begin{figure}[H]\n'); + fprintf(fidTeX,'\\centering \n'); + fprintf(fidTeX,'\\includegraphics[width=0.8\\textwidth]{%s}\n',strrep([dirname,'/',fig_nam_],'\','/')); + fprintf(fidTeX,'\\caption{%s.}',figtitle_tex); + fprintf(fidTeX,'\\label{Fig:%s}\n',fig_nam_); + fprintf(fidTeX,'\\end{figure}\n\n'); + fprintf(fidTeX,'%% End Of TeX file. \n'); + fclose(fidTeX); + end end \ No newline at end of file diff --git a/matlab/gsa/scatter_plots.m b/matlab/gsa/scatter_plots.m index e64195464c..61e47bb518 100644 --- a/matlab/gsa/scatter_plots.m +++ b/matlab/gsa/scatter_plots.m @@ -56,25 +56,25 @@ if nargin<5 || isempty(fnam) fnam='scatter_plot'; end if nargin<6 || isempty(dirname), - dirname=''; - nograph=1; - DynareOptions.nodisplay=0; + dirname=''; + nograph=1; + DynareOptions.nodisplay=0; else - nograph=0; + nograph=0; end if nargin<7 || isempty(figtitle), - figtitle=fnam; + figtitle=fnam; end if nargin<8, - xparam1=[]; + xparam1=[]; end figtitle_tex=strrep(figtitle,'_','\_'); fig_nam_=[fnam]; - hh=dyn_figure(DynareOptions.nodisplay,'name',figtitle); - set(hh,'userdata',{X,xp}) +hh=dyn_figure(DynareOptions.nodisplay,'name',figtitle); +set(hh,'userdata',{X,xp}) bf = 0.1; ffs = 0.05/(p-1); @@ -111,7 +111,7 @@ for i = 1:p %% if ~isoctave - % Define a context menu; it is not attached to anything + % Define a context menu; it is not attached to anything hcmenu = uicontextmenu('Callback','pick','Tag','Run viewer'); % Define callbacks for context menu % items that change linestyle @@ -150,7 +150,7 @@ for i = 1:p if i==1 if nflag == 1 ylabel(vnames(j,:),'Rotation',45,'interpreter','none', ... - 'HorizontalAlignment','right','VerticalAlignment','middle'); + 'HorizontalAlignment','right','VerticalAlignment','middle'); else ylabel([num2str(j),' '],'Rotation',90) end; @@ -158,7 +158,7 @@ for i = 1:p if j==1 if nflag == 1 title(vnames(i,:),'interpreter','none','Rotation',45, ... - 'HorizontalAlignment','left','VerticalAlignment','bottom') + 'HorizontalAlignment','left','VerticalAlignment','bottom') else title(num2str(i)) end; diff --git a/matlab/gsa/set_shocks_param.m b/matlab/gsa/set_shocks_param.m index 8902dfb102..bd22ccb561 100644 --- a/matlab/gsa/set_shocks_param.m +++ b/matlab/gsa/set_shocks_param.m @@ -93,7 +93,7 @@ if isfield(estim_params_,'calibrated_covariances_ME') H(estim_params_.calibrated_covariances_ME.position)=estim_params_.calibrated_covariances_ME.cov_value; end - + % updating matrices in M if nvx || ncx M_.Sigma_e = Sigma_e; diff --git a/matlab/gsa/stab_map_.m b/matlab/gsa/stab_map_.m index 78ab1a368c..e6b22edacf 100644 --- a/matlab/gsa/stab_map_.m +++ b/matlab/gsa/stab_map_.m @@ -99,8 +99,8 @@ if ~isempty(bayestopt_) && any(bayestopt_.pshape > 0) bounds.lb = max(bounds.lb,lb); bounds.ub = min(bounds.ub,ub); else % estimated parameters but no declared priors - % No priors are declared so Dynare will estimate the model by - % maximum likelihood with inequality constraints for the parameters. + % No priors are declared so Dynare will estimate the model by + % maximum likelihood with inequality constraints for the parameters. bounds.lb = lb; bounds.ub = ub; if opt_gsa.prior_range==0 @@ -159,9 +159,9 @@ if fload==0, Nsam=size(lpmat,1); lpmat0 = lpmat(:,1:nshock); lpmat = lpmat(:,nshock+1:end); -% elseif opt_gsa.morris==3, -% lpmat = prep_ide(Nsam,np,5); -% Nsam=size(lpmat,1); + % elseif opt_gsa.morris==3, + % lpmat = prep_ide(Nsam,np,5); + % Nsam=size(lpmat,1); else if np<52 && ilptau>0, [lpmat] = qmc_sequence(np, int64(1), 0, Nsam)'; @@ -180,14 +180,14 @@ if fload==0, end % try dummy=prior_draw_gsa(1); %initialize persistent variables - % catch - % if pprior, - % if opt_gsa.prior_range==0; - % error('Some unknown prior is specified or ML estimation,: use prior_range=1 option!!'); - % end - % end - % - % end + % catch + % if pprior, + % if opt_gsa.prior_range==0; + % error('Some unknown prior is specified or ML estimation,: use prior_range=1 option!!'); + % end + % end + % + % end if pprior, for j=1:nshock, if opt_gsa.morris~=1, @@ -257,12 +257,12 @@ if fload==0, if neighborhood_width>0 && isempty(options_.mode_file), xparam1 = get_all_parameters(estim_params_,M_); else - eval(['load ' options_.mode_file '.mat;']); + eval(['load ' options_.mode_file '.mat;']); end if neighborhood_width>0, for j=1:nshock, if opt_gsa.morris ~= 1 - lpmat0(:,j) = randperm(Nsam)'./(Nsam+1); %latin hypercube + lpmat0(:,j) = randperm(Nsam)'./(Nsam+1); %latin hypercube end ub=min([bounds.ub(j) xparam1(j)*(1+neighborhood_width)]); lb=max([bounds.lb(j) xparam1(j)*(1-neighborhood_width)]); @@ -335,7 +335,7 @@ if fload==0, egg=zeros(length(dr_.eigval),Nsam); end if infox(j,1), -% disp('no solution'), + % disp('no solution'), if isfield(oo_.dr,'ghx'), oo_.dr=rmfield(oo_.dr,'ghx'); end @@ -457,23 +457,23 @@ if fload==0, if pprior, if ~prepSA save([OutputDirectoryName filesep fname_ '_prior.mat'], ... - 'bkpprior','lpmat','lpmat0','irestriction','iunstable','istable','iindeterm','iwrong','ixun', ... - 'egg','yys','nspred','nboth','nfwrd','infox') + 'bkpprior','lpmat','lpmat0','irestriction','iunstable','istable','iindeterm','iwrong','ixun', ... + 'egg','yys','nspred','nboth','nfwrd','infox') else save([OutputDirectoryName filesep fname_ '_prior.mat'], ... - 'bkpprior','lpmat','lpmat0','irestriction','iunstable','istable','iindeterm','iwrong','ixun', ... - 'egg','yys','T','nspred','nboth','nfwrd','infox') + 'bkpprior','lpmat','lpmat0','irestriction','iunstable','istable','iindeterm','iwrong','ixun', ... + 'egg','yys','T','nspred','nboth','nfwrd','infox') end else if ~prepSA save([OutputDirectoryName filesep fname_ '_mc.mat'], ... - 'lpmat','lpmat0','irestriction','iunstable','istable','iindeterm','iwrong','ixun', ... - 'egg','yys','nspred','nboth','nfwrd','infox') + 'lpmat','lpmat0','irestriction','iunstable','istable','iindeterm','iwrong','ixun', ... + 'egg','yys','nspred','nboth','nfwrd','infox') else save([OutputDirectoryName filesep fname_ '_mc.mat'], ... - 'lpmat','lpmat0','irestriction','iunstable','istable','iindeterm','iwrong','ixun', ... - 'egg','yys','T','nspred','nboth','nfwrd','infox') + 'lpmat','lpmat0','irestriction','iunstable','istable','iindeterm','iwrong','ixun', ... + 'egg','yys','T','nspred','nboth','nfwrd','infox') end end else @@ -601,7 +601,7 @@ if length(iunstable)>0 || length(iwrong)>0, if length(iunstable)<Nsam || length(istable)>1 itot = [1:Nsam]; isolve = itot(find(~ismember(itot,iwrong))); % dynare could find a solution - % Blanchard Kahn + % Blanchard Kahn if neighborhood_width, options_mcf.xparam1 = xparam1(nshock+1:end); end diff --git a/matlab/gsa/stab_map_1.m b/matlab/gsa/stab_map_1.m index 8535a78ecd..6a23fe63dc 100644 --- a/matlab/gsa/stab_map_1.m +++ b/matlab/gsa/stab_map_1.m @@ -41,14 +41,14 @@ function [proba, dproba] = stab_map_1(lpmat, ibehaviour, inonbehaviour, aname, i global estim_params_ bayestopt_ M_ options_ if nargin<5, - iplot=1; + iplot=1; end fname_ = M_.fname; if nargin<7, - dirname=''; + dirname=''; end if nargin<9, - atitle=aname; + atitle=aname; end nshock = estim_params_.nvx; @@ -60,20 +60,20 @@ npar=size(lpmat,2); ishock= npar>estim_params_.np; if nargin<6, - ipar=[]; + ipar=[]; end if nargin<8 || isempty(pcrit), - pcrit=1; + pcrit=1; end % Smirnov test for Blanchard; for j=1:npar, - [H,P,KSSTAT] = smirnov(lpmat(ibehaviour,j),lpmat(inonbehaviour,j)); - proba(j)=P; - dproba(j)=KSSTAT; + [H,P,KSSTAT] = smirnov(lpmat(ibehaviour,j),lpmat(inonbehaviour,j)); + proba(j)=P; + dproba(j)=KSSTAT; end if isempty(ipar), -% ipar=find(dproba>dcrit); + % ipar=find(dproba>dcrit); ipar=find(proba<pcrit); end nparplot=length(ipar); diff --git a/matlab/gsa/stab_map_2.m b/matlab/gsa/stab_map_2.m index beed786dc6..80d140e15e 100644 --- a/matlab/gsa/stab_map_2.m +++ b/matlab/gsa/stab_map_2.m @@ -30,17 +30,17 @@ nsam=size(x,1); ishock= npar>estim_params_.np; nograph = options_.nograph; if nargin<4, - fnam=''; + fnam=''; end if nargin<5, - dirname=''; - nograph=1; + dirname=''; + nograph=1; end if nargin<6, - xparam1=[]; + xparam1=[]; end if nargin<7, - figtitle=fnam; + figtitle=fnam; end ys_ = oo_.dr.ys; @@ -60,12 +60,12 @@ fig_nam_=strrep(fig_nam_,' ','_'); ifig=0; j2=0; if ishock==0 - npar=estim_params_.np; - if ~isempty(xparam1), - xparam1=xparam1(nshock+1:end); - end + npar=estim_params_.np; + if ~isempty(xparam1), + xparam1=xparam1(nshock+1:end); + end else - npar=estim_params_.np+nshock; + npar=estim_params_.np+nshock; end skipline(); title_string=['Correlation analysis for ',fnam]; @@ -118,45 +118,45 @@ for j=1:npar, if ~nograph, if mod(j2,12)==1, - ifig=ifig+1; - hh=dyn_figure(options_.nodisplay,'name',[figtitle,' sample bivariate projection ', num2str(ifig)]); - end - subplot(3,4,j2-(ifig-1)*12) - % bar(c0(i2,j)), - % set(gca,'xticklabel',bayestopt_.name(i2)), - % set(gca,'xtick',[1:length(i2)]) - %plot(stock_par(ixx(nfilt+1:end,i),j),stock_par(ixx(nfilt+1:end,i),i2(jx)),'.k') - %hold on, - plot(x(:,j),x(:,i2(jx)),'.') - if ~isempty(xparam1) - hold on, plot(xparam1(j),xparam1(i2(jx)),'ro') - end - % xlabel(deblank(estim_params_.param_names(j,:)),'interpreter','none'), - % ylabel(deblank(estim_params_.param_names(i2(jx),:)),'interpreter','none'), - if ishock, - xlabel(bayestopt_.name{j},'interpreter','none'), - ylabel(bayestopt_.name{i2(jx)},'interpreter','none'), - else - xlabel(bayestopt_.name{j+nshock},'interpreter','none'), - ylabel(bayestopt_.name{i2(jx)+nshock},'interpreter','none'), - end - title(['cc = ',num2str(c0(i2(jx),j))]) - if (mod(j2,12)==0) && j2>0, - dyn_saveas(hh,[dirname,filesep,fig_nam_,int2str(ifig)],options_.nodisplay,options_.graph_format); - if options_.TeX && any(strcmp('eps',cellstr(options_.graph_format))) - fidTeX = fopen([dirname,filesep,fig_nam_,int2str(ifig),'.tex'],'w'); - fprintf(fidTeX,'%% TeX eps-loader file generated by stab_map_2.m (Dynare).\n'); - fprintf(fidTeX,['%% ' datestr(now,0) '\n\n']); - fprintf(fidTeX,'\\begin{figure}[H]\n'); - fprintf(fidTeX,'\\centering \n'); - fprintf(fidTeX,'\\includegraphics[width=0.8\\textwidth]{%s}\n',strrep([dirname,'/',fig_nam_,int2str(ifig)],'\','/')); - fprintf(fidTeX,'\\caption{%s.}',[figtitle,' sample bivariate projection ', num2str(ifig)]); - fprintf(fidTeX,'\\label{Fig:%s:%u}\n',fig_nam_,ifig); - fprintf(fidTeX,'\\end{figure}\n\n'); - fprintf(fidTeX,'%% End Of TeX file. \n'); - fclose(fidTeX); + ifig=ifig+1; + hh=dyn_figure(options_.nodisplay,'name',[figtitle,' sample bivariate projection ', num2str(ifig)]); + end + subplot(3,4,j2-(ifig-1)*12) + % bar(c0(i2,j)), + % set(gca,'xticklabel',bayestopt_.name(i2)), + % set(gca,'xtick',[1:length(i2)]) + %plot(stock_par(ixx(nfilt+1:end,i),j),stock_par(ixx(nfilt+1:end,i),i2(jx)),'.k') + %hold on, + plot(x(:,j),x(:,i2(jx)),'.') + if ~isempty(xparam1) + hold on, plot(xparam1(j),xparam1(i2(jx)),'ro') + end + % xlabel(deblank(estim_params_.param_names(j,:)),'interpreter','none'), + % ylabel(deblank(estim_params_.param_names(i2(jx),:)),'interpreter','none'), + if ishock, + xlabel(bayestopt_.name{j},'interpreter','none'), + ylabel(bayestopt_.name{i2(jx)},'interpreter','none'), + else + xlabel(bayestopt_.name{j+nshock},'interpreter','none'), + ylabel(bayestopt_.name{i2(jx)+nshock},'interpreter','none'), + end + title(['cc = ',num2str(c0(i2(jx),j))]) + if (mod(j2,12)==0) && j2>0, + dyn_saveas(hh,[dirname,filesep,fig_nam_,int2str(ifig)],options_.nodisplay,options_.graph_format); + if options_.TeX && any(strcmp('eps',cellstr(options_.graph_format))) + fidTeX = fopen([dirname,filesep,fig_nam_,int2str(ifig),'.tex'],'w'); + fprintf(fidTeX,'%% TeX eps-loader file generated by stab_map_2.m (Dynare).\n'); + fprintf(fidTeX,['%% ' datestr(now,0) '\n\n']); + fprintf(fidTeX,'\\begin{figure}[H]\n'); + fprintf(fidTeX,'\\centering \n'); + fprintf(fidTeX,'\\includegraphics[width=0.8\\textwidth]{%s}\n',strrep([dirname,'/',fig_nam_,int2str(ifig)],'\','/')); + fprintf(fidTeX,'\\caption{%s.}',[figtitle,' sample bivariate projection ', num2str(ifig)]); + fprintf(fidTeX,'\\label{Fig:%s:%u}\n',fig_nam_,ifig); + fprintf(fidTeX,'\\end{figure}\n\n'); + fprintf(fidTeX,'%% End Of TeX file. \n'); + fclose(fidTeX); + end end - end end end diff --git a/matlab/gsa/stand_.m b/matlab/gsa/stand_.m index c69ec4bf3d..f1547c3c66 100644 --- a/matlab/gsa/stand_.m +++ b/matlab/gsa/stand_.m @@ -35,8 +35,8 @@ if nargin==0, end for j=1:size(x,2); -meany(j)=mean(x(find(~isnan(x(:,j))),j)); -stdy(j)=std(x(find(~isnan(x(:,j))),j)); + meany(j)=mean(x(find(~isnan(x(:,j))),j)); + stdy(j)=std(x(find(~isnan(x(:,j))),j)); y(:,j)=(x(:,j)-meany(j))./stdy(j); end % end of m-file \ No newline at end of file diff --git a/matlab/gsa/tcrit.m b/matlab/gsa/tcrit.m index 291725aadd..560d90175c 100644 --- a/matlab/gsa/tcrit.m +++ b/matlab/gsa/tcrit.m @@ -43,108 +43,108 @@ pval0=max(pval0,min(pval)); ncol=min(find(pval<=pval0))+1; t_crit=[ - 1 3.078 6.314 12.706 31.821 63.657 318.313 - 2 1.886 2.920 4.303 6.965 9.925 22.327 - 3 1.638 2.353 3.182 4.541 5.841 10.215 - 4 1.533 2.132 2.776 3.747 4.604 7.173 - 5 1.476 2.015 2.571 3.365 4.032 5.893 - 6 1.440 1.943 2.447 3.143 3.707 5.208 - 7 1.415 1.895 2.365 2.998 3.499 4.782 - 8 1.397 1.860 2.306 2.896 3.355 4.499 - 9 1.383 1.833 2.262 2.821 3.250 4.296 - 10 1.372 1.812 2.228 2.764 3.169 4.143 - 11 1.363 1.796 2.201 2.718 3.106 4.024 - 12 1.356 1.782 2.179 2.681 3.055 3.929 - 13 1.350 1.771 2.160 2.650 3.012 3.852 - 14 1.345 1.761 2.145 2.624 2.977 3.787 - 15 1.341 1.753 2.131 2.602 2.947 3.733 - 16 1.337 1.746 2.120 2.583 2.921 3.686 - 17 1.333 1.740 2.110 2.567 2.898 3.646 - 18 1.330 1.734 2.101 2.552 2.878 3.610 - 19 1.328 1.729 2.093 2.539 2.861 3.579 - 20 1.325 1.725 2.086 2.528 2.845 3.552 - 21 1.323 1.721 2.080 2.518 2.831 3.527 - 22 1.321 1.717 2.074 2.508 2.819 3.505 - 23 1.319 1.714 2.069 2.500 2.807 3.485 - 24 1.318 1.711 2.064 2.492 2.797 3.467 - 25 1.316 1.708 2.060 2.485 2.787 3.450 - 26 1.315 1.706 2.056 2.479 2.779 3.435 - 27 1.314 1.703 2.052 2.473 2.771 3.421 - 28 1.313 1.701 2.048 2.467 2.763 3.408 - 29 1.311 1.699 2.045 2.462 2.756 3.396 - 30 1.310 1.697 2.042 2.457 2.750 3.385 - 31 1.309 1.696 2.040 2.453 2.744 3.375 - 32 1.309 1.694 2.037 2.449 2.738 3.365 - 33 1.308 1.692 2.035 2.445 2.733 3.356 - 34 1.307 1.691 2.032 2.441 2.728 3.348 - 35 1.306 1.690 2.030 2.438 2.724 3.340 - 36 1.306 1.688 2.028 2.434 2.719 3.333 - 37 1.305 1.687 2.026 2.431 2.715 3.326 - 38 1.304 1.686 2.024 2.429 2.712 3.319 - 39 1.304 1.685 2.023 2.426 2.708 3.313 - 40 1.303 1.684 2.021 2.423 2.704 3.307 - 41 1.303 1.683 2.020 2.421 2.701 3.301 - 42 1.302 1.682 2.018 2.418 2.698 3.296 - 43 1.302 1.681 2.017 2.416 2.695 3.291 - 44 1.301 1.680 2.015 2.414 2.692 3.286 - 45 1.301 1.679 2.014 2.412 2.690 3.281 - 46 1.300 1.679 2.013 2.410 2.687 3.277 - 47 1.300 1.678 2.012 2.408 2.685 3.273 - 48 1.299 1.677 2.011 2.407 2.682 3.269 - 49 1.299 1.677 2.010 2.405 2.680 3.265 - 50 1.299 1.676 2.009 2.403 2.678 3.261 - 51 1.298 1.675 2.008 2.402 2.676 3.258 - 52 1.298 1.675 2.007 2.400 2.674 3.255 - 53 1.298 1.674 2.006 2.399 2.672 3.251 - 54 1.297 1.674 2.005 2.397 2.670 3.248 - 55 1.297 1.673 2.004 2.396 2.668 3.245 - 56 1.297 1.673 2.003 2.395 2.667 3.242 - 57 1.297 1.672 2.002 2.394 2.665 3.239 - 58 1.296 1.672 2.002 2.392 2.663 3.237 - 59 1.296 1.671 2.001 2.391 2.662 3.234 - 60 1.296 1.671 2.000 2.390 2.660 3.232 - 61 1.296 1.670 2.000 2.389 2.659 3.229 - 62 1.295 1.670 1.999 2.388 2.657 3.227 - 63 1.295 1.669 1.998 2.387 2.656 3.225 - 64 1.295 1.669 1.998 2.386 2.655 3.223 - 65 1.295 1.669 1.997 2.385 2.654 3.220 - 66 1.295 1.668 1.997 2.384 2.652 3.218 - 67 1.294 1.668 1.996 2.383 2.651 3.216 - 68 1.294 1.668 1.995 2.382 2.650 3.214 - 69 1.294 1.667 1.995 2.382 2.649 3.213 - 70 1.294 1.667 1.994 2.381 2.648 3.211 - 71 1.294 1.667 1.994 2.380 2.647 3.209 - 72 1.293 1.666 1.993 2.379 2.646 3.207 - 73 1.293 1.666 1.993 2.379 2.645 3.206 - 74 1.293 1.666 1.993 2.378 2.644 3.204 - 75 1.293 1.665 1.992 2.377 2.643 3.202 - 76 1.293 1.665 1.992 2.376 2.642 3.201 - 77 1.293 1.665 1.991 2.376 2.641 3.199 - 78 1.292 1.665 1.991 2.375 2.640 3.198 - 79 1.292 1.664 1.990 2.374 2.640 3.197 - 80 1.292 1.664 1.990 2.374 2.639 3.195 - 81 1.292 1.664 1.990 2.373 2.638 3.194 - 82 1.292 1.664 1.989 2.373 2.637 3.193 - 83 1.292 1.663 1.989 2.372 2.636 3.191 - 84 1.292 1.663 1.989 2.372 2.636 3.190 - 85 1.292 1.663 1.988 2.371 2.635 3.189 - 86 1.291 1.663 1.988 2.370 2.634 3.188 - 87 1.291 1.663 1.988 2.370 2.634 3.187 - 88 1.291 1.662 1.987 2.369 2.633 3.185 - 89 1.291 1.662 1.987 2.369 2.632 3.184 - 90 1.291 1.662 1.987 2.368 2.632 3.183 - 91 1.291 1.662 1.986 2.368 2.631 3.182 - 92 1.291 1.662 1.986 2.368 2.630 3.181 - 93 1.291 1.661 1.986 2.367 2.630 3.180 - 94 1.291 1.661 1.986 2.367 2.629 3.179 - 95 1.291 1.661 1.985 2.366 2.629 3.178 - 96 1.290 1.661 1.985 2.366 2.628 3.177 - 97 1.290 1.661 1.985 2.365 2.627 3.176 - 98 1.290 1.661 1.984 2.365 2.627 3.175 - 99 1.290 1.660 1.984 2.365 2.626 3.175 -100 1.290 1.660 1.984 2.364 2.626 3.174 -inf 1.282 1.645 1.960 2.326 2.576 3.090 -]; + 1 3.078 6.314 12.706 31.821 63.657 318.313 + 2 1.886 2.920 4.303 6.965 9.925 22.327 + 3 1.638 2.353 3.182 4.541 5.841 10.215 + 4 1.533 2.132 2.776 3.747 4.604 7.173 + 5 1.476 2.015 2.571 3.365 4.032 5.893 + 6 1.440 1.943 2.447 3.143 3.707 5.208 + 7 1.415 1.895 2.365 2.998 3.499 4.782 + 8 1.397 1.860 2.306 2.896 3.355 4.499 + 9 1.383 1.833 2.262 2.821 3.250 4.296 + 10 1.372 1.812 2.228 2.764 3.169 4.143 + 11 1.363 1.796 2.201 2.718 3.106 4.024 + 12 1.356 1.782 2.179 2.681 3.055 3.929 + 13 1.350 1.771 2.160 2.650 3.012 3.852 + 14 1.345 1.761 2.145 2.624 2.977 3.787 + 15 1.341 1.753 2.131 2.602 2.947 3.733 + 16 1.337 1.746 2.120 2.583 2.921 3.686 + 17 1.333 1.740 2.110 2.567 2.898 3.646 + 18 1.330 1.734 2.101 2.552 2.878 3.610 + 19 1.328 1.729 2.093 2.539 2.861 3.579 + 20 1.325 1.725 2.086 2.528 2.845 3.552 + 21 1.323 1.721 2.080 2.518 2.831 3.527 + 22 1.321 1.717 2.074 2.508 2.819 3.505 + 23 1.319 1.714 2.069 2.500 2.807 3.485 + 24 1.318 1.711 2.064 2.492 2.797 3.467 + 25 1.316 1.708 2.060 2.485 2.787 3.450 + 26 1.315 1.706 2.056 2.479 2.779 3.435 + 27 1.314 1.703 2.052 2.473 2.771 3.421 + 28 1.313 1.701 2.048 2.467 2.763 3.408 + 29 1.311 1.699 2.045 2.462 2.756 3.396 + 30 1.310 1.697 2.042 2.457 2.750 3.385 + 31 1.309 1.696 2.040 2.453 2.744 3.375 + 32 1.309 1.694 2.037 2.449 2.738 3.365 + 33 1.308 1.692 2.035 2.445 2.733 3.356 + 34 1.307 1.691 2.032 2.441 2.728 3.348 + 35 1.306 1.690 2.030 2.438 2.724 3.340 + 36 1.306 1.688 2.028 2.434 2.719 3.333 + 37 1.305 1.687 2.026 2.431 2.715 3.326 + 38 1.304 1.686 2.024 2.429 2.712 3.319 + 39 1.304 1.685 2.023 2.426 2.708 3.313 + 40 1.303 1.684 2.021 2.423 2.704 3.307 + 41 1.303 1.683 2.020 2.421 2.701 3.301 + 42 1.302 1.682 2.018 2.418 2.698 3.296 + 43 1.302 1.681 2.017 2.416 2.695 3.291 + 44 1.301 1.680 2.015 2.414 2.692 3.286 + 45 1.301 1.679 2.014 2.412 2.690 3.281 + 46 1.300 1.679 2.013 2.410 2.687 3.277 + 47 1.300 1.678 2.012 2.408 2.685 3.273 + 48 1.299 1.677 2.011 2.407 2.682 3.269 + 49 1.299 1.677 2.010 2.405 2.680 3.265 + 50 1.299 1.676 2.009 2.403 2.678 3.261 + 51 1.298 1.675 2.008 2.402 2.676 3.258 + 52 1.298 1.675 2.007 2.400 2.674 3.255 + 53 1.298 1.674 2.006 2.399 2.672 3.251 + 54 1.297 1.674 2.005 2.397 2.670 3.248 + 55 1.297 1.673 2.004 2.396 2.668 3.245 + 56 1.297 1.673 2.003 2.395 2.667 3.242 + 57 1.297 1.672 2.002 2.394 2.665 3.239 + 58 1.296 1.672 2.002 2.392 2.663 3.237 + 59 1.296 1.671 2.001 2.391 2.662 3.234 + 60 1.296 1.671 2.000 2.390 2.660 3.232 + 61 1.296 1.670 2.000 2.389 2.659 3.229 + 62 1.295 1.670 1.999 2.388 2.657 3.227 + 63 1.295 1.669 1.998 2.387 2.656 3.225 + 64 1.295 1.669 1.998 2.386 2.655 3.223 + 65 1.295 1.669 1.997 2.385 2.654 3.220 + 66 1.295 1.668 1.997 2.384 2.652 3.218 + 67 1.294 1.668 1.996 2.383 2.651 3.216 + 68 1.294 1.668 1.995 2.382 2.650 3.214 + 69 1.294 1.667 1.995 2.382 2.649 3.213 + 70 1.294 1.667 1.994 2.381 2.648 3.211 + 71 1.294 1.667 1.994 2.380 2.647 3.209 + 72 1.293 1.666 1.993 2.379 2.646 3.207 + 73 1.293 1.666 1.993 2.379 2.645 3.206 + 74 1.293 1.666 1.993 2.378 2.644 3.204 + 75 1.293 1.665 1.992 2.377 2.643 3.202 + 76 1.293 1.665 1.992 2.376 2.642 3.201 + 77 1.293 1.665 1.991 2.376 2.641 3.199 + 78 1.292 1.665 1.991 2.375 2.640 3.198 + 79 1.292 1.664 1.990 2.374 2.640 3.197 + 80 1.292 1.664 1.990 2.374 2.639 3.195 + 81 1.292 1.664 1.990 2.373 2.638 3.194 + 82 1.292 1.664 1.989 2.373 2.637 3.193 + 83 1.292 1.663 1.989 2.372 2.636 3.191 + 84 1.292 1.663 1.989 2.372 2.636 3.190 + 85 1.292 1.663 1.988 2.371 2.635 3.189 + 86 1.291 1.663 1.988 2.370 2.634 3.188 + 87 1.291 1.663 1.988 2.370 2.634 3.187 + 88 1.291 1.662 1.987 2.369 2.633 3.185 + 89 1.291 1.662 1.987 2.369 2.632 3.184 + 90 1.291 1.662 1.987 2.368 2.632 3.183 + 91 1.291 1.662 1.986 2.368 2.631 3.182 + 92 1.291 1.662 1.986 2.368 2.630 3.181 + 93 1.291 1.661 1.986 2.367 2.630 3.180 + 94 1.291 1.661 1.986 2.367 2.629 3.179 + 95 1.291 1.661 1.985 2.366 2.629 3.178 + 96 1.290 1.661 1.985 2.366 2.628 3.177 + 97 1.290 1.661 1.985 2.365 2.627 3.176 + 98 1.290 1.661 1.984 2.365 2.627 3.175 + 99 1.290 1.660 1.984 2.365 2.626 3.175 + 100 1.290 1.660 1.984 2.364 2.626 3.174 + inf 1.282 1.645 1.960 2.326 2.576 3.090 + ]; if n<=100, t_crit=t_crit(n,ncol); diff --git a/matlab/gsa/teff.m b/matlab/gsa/teff.m index 0956669a38..622abca94a 100644 --- a/matlab/gsa/teff.m +++ b/matlab/gsa/teff.m @@ -28,32 +28,32 @@ function [yt, j0, ir, ic]=teff(T,Nsam,istable) ndim = (length(size(T))); if ndim==3, -if nargin==1, - Nsam=size(T,3); - istable = [1:Nsam]'; -end -tmax=max(T,[],3); -tmin=min(T,[],3); -[ir, ic]=(find( (tmax-tmin)>1.e-8)); -j0 = length(ir); -yt=zeros(Nsam, j0); + if nargin==1, + Nsam=size(T,3); + istable = [1:Nsam]'; + end + tmax=max(T,[],3); + tmin=min(T,[],3); + [ir, ic]=(find( (tmax-tmin)>1.e-8)); + j0 = length(ir); + yt=zeros(Nsam, j0); -for j=1:j0, - y0=squeeze(T(ir(j),ic(j),:)); - %y1=ones(size(lpmat,1),1)*NaN; - y1=ones(Nsam,1)*NaN; - y1(istable,1)=y0; - yt(:,j)=y1; -end + for j=1:j0, + y0=squeeze(T(ir(j),ic(j),:)); + %y1=ones(size(lpmat,1),1)*NaN; + y1=ones(Nsam,1)*NaN; + y1(istable,1)=y0; + yt(:,j)=y1; + end else -tmax=max(T,[],2); -tmin=min(T,[],2); -ir=(find( (tmax-tmin)>1.e-8)); -j0 = length(ir); -yt=NaN(Nsam, j0); -yt(istable,:)=T(ir,:)'; + tmax=max(T,[],2); + tmin=min(T,[],2); + ir=(find( (tmax-tmin)>1.e-8)); + j0 = length(ir); + yt=NaN(Nsam, j0); + yt(istable,:)=T(ir,:)'; - + end %clear y0 y1; diff --git a/matlab/gsa/trank.m b/matlab/gsa/trank.m index d6ac2d2db0..a47c912622 100644 --- a/matlab/gsa/trank.m +++ b/matlab/gsa/trank.m @@ -29,6 +29,6 @@ function yr = trank(y); [nr, nc] = size(y); for j=1:nc, - [dum, is]=sort(y(:,j)); - yr(is,j)=[1:nr]'./nr; + [dum, is]=sort(y(:,j)); + yr(is,j)=[1:nr]'./nr; end diff --git a/matlab/hessian.m b/matlab/hessian.m index 4faa4c5000..cf2f549bd9 100644 --- a/matlab/hessian.m +++ b/matlab/hessian.m @@ -90,7 +90,7 @@ for i=1:n xh_1(i) = x(i)-h1(i); xh_1(j) = x(j)-h_1(j); hessian_mat(:,(i-1)*n+j) =-(-feval(func, xh1, varargin{:})-feval(func, xh_1, varargin{:})+temp(:,i)+temp(:,j))./(2*h1(i)*h_1(j)); %formula 25.3.27 - %reset grid points + %reset grid points xh1(i) = x(i); xh1(j) = x(j); xh_1(i) = x(i); diff --git a/matlab/hessian_sparse.m b/matlab/hessian_sparse.m index eb447f8d34..d63534e79b 100644 --- a/matlab/hessian_sparse.m +++ b/matlab/hessian_sparse.m @@ -60,11 +60,11 @@ xh_1=xh1; hessian_mat = sparse(size(f0,1),n*n); for i=1:n -% if i > 1 -% k=[i:n:n*(i-1)]; -% hessian_mat(:,(i-1)*n+1:(i-1)*n+i-1)=hessian_mat(:,k); -% hessian_mat(:,k)=0; -% end + % if i > 1 + % k=[i:n:n*(i-1)]; + % hessian_mat(:,(i-1)*n+1:(i-1)*n+i-1)=hessian_mat(:,k); + % hessian_mat(:,k)=0; + % end hessian_mat(:,(i-1)*n+i)=(f1(:,i)+f_1(:,i)-2*f0)./(h1(i)*h_1(i)); temp=f1+f_1-f0*ones(1,n); for j=1:i-1 diff --git a/matlab/ident_bruteforce.m b/matlab/ident_bruteforce.m index 41ed952d71..ea68deaea1 100644 --- a/matlab/ident_bruteforce.m +++ b/matlab/ident_bruteforce.m @@ -111,9 +111,9 @@ for ll = 1:n, end end fprintf(fidTeX,'$%s$ & [%s] & %7.3f \\\\ \n',... - pnames_TeX(i,:),... - plist,... - cosnJ(i,ll)); + pnames_TeX(i,:),... + plist,... + cosnJ(i,ll)); end fprintf(fidTeX,'\\bottomrule \n'); fprintf(fidTeX,'\\end{longtable}\n'); diff --git a/matlab/identification_analysis.m b/matlab/identification_analysis.m index 88b60ca4d4..f83bcf1a61 100644 --- a/matlab/identification_analysis.m +++ b/matlab/identification_analysis.m @@ -63,7 +63,7 @@ periods = options_ident.periods; max_dim_cova_group = options_ident.max_dim_cova_group; normalize_jacobians = options_ident.normalize_jacobians; kron_flag = options_ident.analytic_derivation_mode; - + [I,J]=find(M_.lead_lag_incidence'); ide_hess = struct(); @@ -78,8 +78,8 @@ if info(1)==0, tau=[oo_.dr.ys(oo_.dr.order_var); vec(A); dyn_vech(B*M_.Sigma_e*B')]; yy0=oo_.dr.ys(I); [residual, g1 ] = feval([M_.fname,'_dynamic'],yy0, ... - repmat(oo_.exo_steady_state',[M_.maximum_exo_lag+M_.maximum_exo_lead+1]), M_.params, ... - oo_.dr.ys, 1); + repmat(oo_.exo_steady_state',[M_.maximum_exo_lag+M_.maximum_exo_lead+1]), M_.params, ... + oo_.dr.ys, 1); vg1 = [oo_.dr.ys(oo_.dr.order_var); vec(g1)]; [JJ, H, gam, gp, dA, dOm, dYss] = getJJ(A, B, estim_params_, M_,oo0,options_,kron_flag,indx,indexo,bayestopt_.mf2,nlags,useautocorr); @@ -157,13 +157,13 @@ if info(1)==0, derivatives_info.no_DLIK=1; %bounds = prior_bounds(bayestopt_, options_.prior_trunc); [fval,info,cost_flag,DLIK,AHess,ys,trend_coeff,M_,options_,bayestopt_,oo_] = dsge_likelihood(params',dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,bounds,oo_,derivatives_info); -% fval = DsgeLikelihood(xparam1,data_info,options_,M_,estim_params_,bayestopt_,oo_); + % fval = DsgeLikelihood(xparam1,data_info,options_,M_,estim_params_,bayestopt_,oo_); options_.analytic_derivation = analytic_derivation; AHess=-AHess; if min(eig(AHess))<-1.e-10, error('identification_analysis: Analytic Hessian is not positive semi-definite!') end -% chol(AHess); + % chol(AHess); ide_hess.AHess= AHess; deltaM = sqrt(diag(AHess)); iflag=any((deltaM.*deltaM)==0); @@ -181,17 +181,17 @@ if info(1)==0, cmm = siJ(:,ind1)*((AHess(ind1,ind1))\siJ(:,ind1)'); temp1=((AHess(ind1,ind1))\siH(:,ind1)'); diag_chh=sum(siH(:,ind1)'.*temp1)'; -% chh = siH(:,ind1)*((AHess(ind1,ind1))\siH(:,ind1)'); + % chh = siH(:,ind1)*((AHess(ind1,ind1))\siH(:,ind1)'); ind1=ind1(ind1>offset); clre = siLRE(:,ind1-offset)*((AHess(ind1,ind1))\siLRE(:,ind1-offset)'); rhoM=sqrt(1./diag(inv(tildaM(indok,indok)))); -% deltaM = deltaM.*abs(params'); + % deltaM = deltaM.*abs(params'); flag_score=1; catch, -% replic = max([replic, nparam*(nparam+1)/2*10]); + % replic = max([replic, nparam*(nparam+1)/2*10]); replic = max([replic, length(indJJ)*3]); cmm = simulated_moment_uncertainty(indJJ, periods, replic,options_,M_,oo_); -% [V,D,W]=eig(cmm); + % [V,D,W]=eig(cmm); sd=sqrt(diag(cmm)); cc=cmm./(sd*sd'); if isoctave || matlab_ver_less_than('8.3') @@ -206,21 +206,21 @@ if info(1)==0, siTMP=siJ./repmat(sd,[1 nparam]); MIM=(siTMP'*V(:,id))*(D(id,id)\(W(:,id)'*siTMP)); clear siTMP; -% MIM=siJ(:,indok)'*(cmm\siJ(:,indok)); -% look for independent moments! -% % % sd=sqrt(diag(cmm)); -% % % cc=cmm./(sd*sd'); -% % % ix=[]; -% % % for jc=1:length(cmm), -% % % jcheck=find(abs(cc(:,jc))>(1-1.e-6)); -% % % ix=[ix; jcheck(jcheck>jc)]; -% % % end -% % % iy=find(~ismember([1:length(cmm)],ix)); -% % % indJJ=indJJ(iy); -% % % GAM=GAM(iy); -% % % cmm=cmm(iy,iy); -% % % siJ = (JJ(indJJ,:)); -% % % MIM=siJ'*(cmm\siJ); + % MIM=siJ(:,indok)'*(cmm\siJ(:,indok)); + % look for independent moments! + % % % sd=sqrt(diag(cmm)); + % % % cc=cmm./(sd*sd'); + % % % ix=[]; + % % % for jc=1:length(cmm), + % % % jcheck=find(abs(cc(:,jc))>(1-1.e-6)); + % % % ix=[ix; jcheck(jcheck>jc)]; + % % % end + % % % iy=find(~ismember([1:length(cmm)],ix)); + % % % indJJ=indJJ(iy); + % % % GAM=GAM(iy); + % % % cmm=cmm(iy,iy); + % % % siJ = (JJ(indJJ,:)); + % % % MIM=siJ'*(cmm\siJ); ide_hess.AHess= MIM; deltaM = sqrt(diag(MIM)); iflag=any((deltaM.*deltaM)==0); @@ -231,12 +231,12 @@ if info(1)==0, [ide_hess.cond, ide_hess.ind0, ide_hess.indno, ide_hess.ino, ide_hess.Mco, ide_hess.Pco] = identification_checks(tildaM, 1); end indok = find(max(ide_hess.indno,[],1)==0); -% rhoM=sqrt(1-1./diag(inv(tildaM))); -% rhoM=(1-1./diag(inv(tildaM))); + % rhoM=sqrt(1-1./diag(inv(tildaM))); + % rhoM=(1-1./diag(inv(tildaM))); ind1=find(ide_hess.ind0); temp1=((MIM(ind1,ind1))\siH(:,ind1)'); diag_chh=sum(siH(:,ind1)'.*temp1)'; -% chh = siH(:,ind1)*((MIM(ind1,ind1))\siH(:,ind1)'); + % chh = siH(:,ind1)*((MIM(ind1,ind1))\siH(:,ind1)'); ind1=ind1(ind1>offset); clre = siLRE(:,ind1-offset)*((MIM(ind1,ind1))\siLRE(:,ind1-offset)'); if ~isempty(indok), @@ -260,11 +260,11 @@ if info(1)==0, end % siJnorm = vnorm(siJ(inok,:)).*normaliz; quant=[]; -% inok = find((abs(TAU)<1.e-8)); -% isok = find((abs(TAU)>=1.e-8)); -% quant(isok,:) = siH(isok,:)./repmat(TAU(isok,1),1,nparam); -% quant(inok,:) = siH(inok,:)./repmat(mean(abs(TAU)),length(inok),nparam); -% quant = siH./repmat(sqrt(diag(chh)),1,nparam); + % inok = find((abs(TAU)<1.e-8)); + % isok = find((abs(TAU)>=1.e-8)); + % quant(isok,:) = siH(isok,:)./repmat(TAU(isok,1),1,nparam); + % quant(inok,:) = siH(inok,:)./repmat(mean(abs(TAU)),length(inok),nparam); + % quant = siH./repmat(sqrt(diag(chh)),1,nparam); iy = find(diag_chh); indH=indH(iy); siH=siH(iy,:); @@ -280,10 +280,10 @@ if info(1)==0, end % siHnorm = vnorm(siH./repmat(TAU,1,nparam)).*normaliz; quant=[]; -% inok = find((abs(LRE)<1.e-8)); -% isok = find((abs(LRE)>=1.e-8)); -% quant(isok,:) = siLRE(isok,:)./repmat(LRE(isok,1),1,np); -% quant(inok,:) = siLRE(inok,:)./repmat(mean(abs(LRE)),length(inok),np); + % inok = find((abs(LRE)<1.e-8)); + % isok = find((abs(LRE)>=1.e-8)); + % quant(isok,:) = siLRE(isok,:)./repmat(LRE(isok,1),1,np); + % quant(inok,:) = siLRE(inok,:)./repmat(mean(abs(LRE)),length(inok),np); diag_clre = diag(clre); iy = find(diag_clre); indLRE=indLRE(iy); @@ -329,14 +329,14 @@ if info(1)==0, ide_moments.GAM=GAM; ide_model.TAU=TAU; ide_lre.LRE=LRE; -% [ide_checks.idemodel_Mco, ide_checks.idemoments_Mco, ide_checks.idelre_Mco, ... -% ide_checks.idemodel_Pco, ide_checks.idemoments_Pco, ide_checks.idelre_Pco, ... -% ide_checks.idemodel_cond, ide_checks.idemoments_cond, ide_checks.idelre_cond, ... -% ide_checks.idemodel_ee, ide_checks.idemoments_ee, ide_checks.idelre_ee, ... -% ide_checks.idemodel_ind, ide_checks.idemoments_ind, ... -% ide_checks.idemodel_indno, ide_checks.idemoments_indno, ... -% ide_checks.idemodel_ino, ide_checks.idemoments_ino] = ... -% identification_checks(H(indH,:)./normH(:,ones(nparam,1)),JJ(indJJ,:)./normJ(:,ones(nparam,1)), gp(indLRE,:)./normLRE(:,ones(size(gp,2),1))); + % [ide_checks.idemodel_Mco, ide_checks.idemoments_Mco, ide_checks.idelre_Mco, ... + % ide_checks.idemodel_Pco, ide_checks.idemoments_Pco, ide_checks.idelre_Pco, ... + % ide_checks.idemodel_cond, ide_checks.idemoments_cond, ide_checks.idelre_cond, ... + % ide_checks.idemodel_ee, ide_checks.idemoments_ee, ide_checks.idelre_ee, ... + % ide_checks.idemodel_ind, ide_checks.idemoments_ind, ... + % ide_checks.idemodel_indno, ide_checks.idemoments_indno, ... + % ide_checks.idemodel_ino, ide_checks.idemoments_ino] = ... + % identification_checks(H(indH,:)./normH(:,ones(nparam,1)),JJ(indJJ,:)./normJ(:,ones(nparam,1)), gp(indLRE,:)./normLRE(:,ones(size(gp,2),1))); [ide_moments.cond, ide_moments.ind0, ide_moments.indno, ide_moments.ino, ide_moments.Mco, ide_moments.Pco, ide_moments.jweak, ide_moments.jweak_pair] = ... identification_checks(JJ(indJJ,:)./normJ, 0); [ide_model.cond, ide_model.ind0, ide_model.indno, ide_model.ino, ide_model.Mco, ide_model.Pco, ide_model.jweak, ide_model.jweak_pair] = ... diff --git a/matlab/identification_checks.m b/matlab/identification_checks.m index 208d7ecd4e..735682ec7d 100644 --- a/matlab/identification_checks.m +++ b/matlab/identification_checks.m @@ -70,13 +70,13 @@ if npar>0 && (rankJ<npar), end if icheck, -JJ1 = JJ(:,ind1); -[eu,ee2,ee1] = svd( JJ1, 0 ); -condJ= cond(JJ1); -rankJ = rank(JJ); -rankJJ = rankJ; + JJ1 = JJ(:,ind1); + [eu,ee2,ee1] = svd( JJ1, 0 ); + condJ= cond(JJ1); + rankJ = rank(JJ); + rankJJ = rankJ; end - + % if hess_flag==0, % rankJJ = rank(JJ'*JJ); @@ -96,7 +96,7 @@ else tildaJ = JJ(ind1,ind1)./((deltaJ)*(deltaJ')); McoJ(ind1,1)=(1-1./diag(inv(tildaJ))); rhoM=sqrt(1-McoJ); -% PcoJ=inv(tildaJ); + % PcoJ=inv(tildaJ); PcoJ=NaN(npar,npar); PcoJ(ind1,ind1)=inv(JJ(ind1,ind1)); sd=sqrt(diag(PcoJ)); @@ -132,27 +132,27 @@ jweak=zeros(1,npar); jweak_pair=zeros(npar,npar); if hess_flag==0, -PcoJ = NaN(npar,npar); + PcoJ = NaN(npar,npar); -for ii = 1:size(JJ1,2); - PcoJ(ind1(ii),ind1(ii)) = 1; - for jj = ii+1:size(JJ1,2); - PcoJ(ind1(ii),ind1(jj)) = cosn([JJ1(:,ii),JJ1(:,jj)]); - PcoJ(ind1(jj),ind1(ii)) = PcoJ(ind1(ii),ind1(jj)); + for ii = 1:size(JJ1,2); + PcoJ(ind1(ii),ind1(ii)) = 1; + for jj = ii+1:size(JJ1,2); + PcoJ(ind1(ii),ind1(jj)) = cosn([JJ1(:,ii),JJ1(:,jj)]); + PcoJ(ind1(jj),ind1(ii)) = PcoJ(ind1(ii),ind1(jj)); + end end -end -for j=1:npar, - if McoJ(j)>(1-1.e-10), - jweak(j)=1; - [ipair, jpair] = find(PcoJ(j,j+1:end)>(1-1.e-10)); - for jx=1:length(jpair), - jweak_pair(j, jpair(jx)+j)=1; - jweak_pair(jpair(jx)+j, j)=1; + for j=1:npar, + if McoJ(j)>(1-1.e-10), + jweak(j)=1; + [ipair, jpair] = find(PcoJ(j,j+1:end)>(1-1.e-10)); + for jx=1:length(jpair), + jweak_pair(j, jpair(jx)+j)=1; + jweak_pair(jpair(jx)+j, j)=1; + end end end end -end jweak_pair=dyn_vech(jweak_pair)'; diff --git a/matlab/imcforecast.m b/matlab/imcforecast.m index 8ddb3755db..9f7bdc4805 100644 --- a/matlab/imcforecast.m +++ b/matlab/imcforecast.m @@ -225,7 +225,7 @@ jdx = []; for i = 1:n1 idx = [idx ; constrained_vars(i,:)]; -% idx = [idx ; oo_.dr.inv_order_var(constrained_vars(i,:))]; + % idx = [idx ; oo_.dr.inv_order_var(constrained_vars(i,:))]; jdx = [jdx ; strmatch(deblank(options_cond_fcst.controlled_varexo(i,:)),M_.exo_names,'exact')]; end mv = zeros(n1,NumberOfStates); diff --git a/matlab/init_plan.m b/matlab/init_plan.m index 0e9957f48f..24bd3ea653 100644 --- a/matlab/init_plan.m +++ b/matlab/init_plan.m @@ -25,28 +25,28 @@ function plan = init_plan(date) % % You should have received a copy of the GNU General Public License % along with Dynare. If not, see <http://www.gnu.org/licenses/>. - global M_ - plan = struct(); - plan.date = date; - plan.date_str = strings(date); - endo_names_length = size(M_.endo_names,2); - plan.endo_names = deblank(mat2cell(M_.endo_names(1:M_.orig_endo_nbr,:),ones(1,M_.orig_endo_nbr),endo_names_length)); - exo_names_length = size(M_.exo_names,2); - plan.exo_names = deblank(mat2cell(M_.exo_names(1:M_.exo_nbr,:),ones(1,M_.exo_nbr),exo_names_length)); - plan.constrained_vars_ = []; - plan.constrained_paths_ = []; - plan.constrained_date_ = []; - plan.constrained_int_date_ = []; - plan.constrained_str_date_ = []; - plan.constrained_perfect_foresight_ = []; - plan.shock_vars_ = []; - plan.shock_paths_ = []; - plan.shock_date_ = []; - plan.shock_int_date_ = []; - plan.shock_str_date_ = []; - plan.shock_perfect_foresight_ = []; - plan.options_cond_fcst_ = struct(); - plan.options_cond_fcst_.parameter_set = 'calibration'; - plan.options_cond_fcst_.simulation_type = 'deterministic'; - plan.options_cond_fcst_.controlled_varexo = []; - +global M_ +plan = struct(); +plan.date = date; +plan.date_str = strings(date); +endo_names_length = size(M_.endo_names,2); +plan.endo_names = deblank(mat2cell(M_.endo_names(1:M_.orig_endo_nbr,:),ones(1,M_.orig_endo_nbr),endo_names_length)); +exo_names_length = size(M_.exo_names,2); +plan.exo_names = deblank(mat2cell(M_.exo_names(1:M_.exo_nbr,:),ones(1,M_.exo_nbr),exo_names_length)); +plan.constrained_vars_ = []; +plan.constrained_paths_ = []; +plan.constrained_date_ = []; +plan.constrained_int_date_ = []; +plan.constrained_str_date_ = []; +plan.constrained_perfect_foresight_ = []; +plan.shock_vars_ = []; +plan.shock_paths_ = []; +plan.shock_date_ = []; +plan.shock_int_date_ = []; +plan.shock_str_date_ = []; +plan.shock_perfect_foresight_ = []; +plan.options_cond_fcst_ = struct(); +plan.options_cond_fcst_.parameter_set = 'calibration'; +plan.options_cond_fcst_.simulation_type = 'deterministic'; +plan.options_cond_fcst_.controlled_varexo = []; + diff --git a/matlab/initial_condition_decomposition.m b/matlab/initial_condition_decomposition.m index 1eb2b79598..f99bcd622e 100644 --- a/matlab/initial_condition_decomposition.m +++ b/matlab/initial_condition_decomposition.m @@ -71,61 +71,61 @@ if isempty(parameter_set) end if ~isfield(oo_,'initval_decomposition') -options_.selected_variables_only = 0; %make sure all variables are stored -options_.plot_priors=0; -[oo,junk1,junk2,Smoothed_Variables_deviation_from_mean] = evaluate_smoother(parameter_set,varlist,M_,oo_,options_,bayestopt_,estim_params_); + options_.selected_variables_only = 0; %make sure all variables are stored + options_.plot_priors=0; + [oo,junk1,junk2,Smoothed_Variables_deviation_from_mean] = evaluate_smoother(parameter_set,varlist,M_,oo_,options_,bayestopt_,estim_params_); -% reduced form -dr = oo.dr; + % reduced form + dr = oo.dr; -% data reordering -order_var = dr.order_var; -inv_order_var = dr.inv_order_var; + % data reordering + order_var = dr.order_var; + inv_order_var = dr.inv_order_var; -% coefficients -A = dr.ghx; -B = dr.ghu; + % coefficients + A = dr.ghx; + B = dr.ghu; -% initialization -gend = size(oo.SmoothedShocks.(deblank(M_.exo_names(1,:))),1); %+options_.forecast; -z = zeros(endo_nbr,endo_nbr+2,gend); -z(:,end,:) = Smoothed_Variables_deviation_from_mean; + % initialization + gend = size(oo.SmoothedShocks.(deblank(M_.exo_names(1,:))),1); %+options_.forecast; + z = zeros(endo_nbr,endo_nbr+2,gend); + z(:,end,:) = Smoothed_Variables_deviation_from_mean; -for i=1:endo_nbr, - z(i,i,1) = Smoothed_Variables_deviation_from_mean(i,1); -end + for i=1:endo_nbr, + z(i,i,1) = Smoothed_Variables_deviation_from_mean(i,1); + end -maximum_lag = M_.maximum_lag; + maximum_lag = M_.maximum_lag; + + k2 = dr.kstate(find(dr.kstate(:,2) <= maximum_lag+1),[1 2]); + i_state = order_var(k2(:,1))+(min(i,maximum_lag)+1-k2(:,2))*M_.endo_nbr; + for i=1:gend + if i > 1 && i <= maximum_lag+1 + lags = min(i-1,maximum_lag):-1:1; + end + + if i > 1 + tempx = permute(z(:,1:endo_nbr,lags),[1 3 2]); + m = min(i-1,maximum_lag); + tempx = [reshape(tempx,endo_nbr*m,endo_nbr); zeros(endo_nbr*(maximum_lag-i+1),endo_nbr)]; + z(:,1:endo_nbr,i) = A(inv_order_var,:)*tempx(i_state,:); + lags = lags+1; + end + z(:,endo_nbr+1,i) = z(:,endo_nbr+2,i) - sum(z(:,1:endo_nbr,i),2); -k2 = dr.kstate(find(dr.kstate(:,2) <= maximum_lag+1),[1 2]); -i_state = order_var(k2(:,1))+(min(i,maximum_lag)+1-k2(:,2))*M_.endo_nbr; -for i=1:gend - if i > 1 && i <= maximum_lag+1 - lags = min(i-1,maximum_lag):-1:1; - end - - if i > 1 - tempx = permute(z(:,1:endo_nbr,lags),[1 3 2]); - m = min(i-1,maximum_lag); - tempx = [reshape(tempx,endo_nbr*m,endo_nbr); zeros(endo_nbr*(maximum_lag-i+1),endo_nbr)]; - z(:,1:endo_nbr,i) = A(inv_order_var,:)*tempx(i_state,:); - lags = lags+1; end - z(:,endo_nbr+1,i) = z(:,endo_nbr+2,i) - sum(z(:,1:endo_nbr,i),2); - -end -oo_.initval_decomposition = z; + oo_.initval_decomposition = z; end % if ~options_.no_graph.shock_decomposition - oo=oo_; - oo.shock_decomposition = oo_.initval_decomposition; - M_.exo_names = M_.endo_names; - M_.exo_nbr = M_.endo_nbr; - options_.plot_shock_decomp.screen_shocks=1; - options_.plot_shock_decomp.use_shock_groups = ''; - options_.plot_shock_decomp.fig_names='initval'; - plot_shock_decomposition(M_,oo,options_,varlist); +oo=oo_; +oo.shock_decomposition = oo_.initval_decomposition; +M_.exo_names = M_.endo_names; +M_.exo_nbr = M_.endo_nbr; +options_.plot_shock_decomp.screen_shocks=1; +options_.plot_shock_decomp.use_shock_groups = ''; +options_.plot_shock_decomp.fig_names='initval'; +plot_shock_decomposition(M_,oo,options_,varlist); % end \ No newline at end of file diff --git a/matlab/initial_estimation_checks.m b/matlab/initial_estimation_checks.m index a13f88ee40..7155552a6d 100644 --- a/matlab/initial_estimation_checks.m +++ b/matlab/initial_estimation_checks.m @@ -69,7 +69,7 @@ if isfield(EstimatedParameters,'param_vals') && ~isempty(EstimatedParameters.par [junk, new_steady_params_2] = evaluate_steady_state(DynareResults.steady_state,Model_par_varied,DynareOptions,DynareResults,DynareOptions.diffuse_filter==0); changed_par_indices=find((old_steady_params(EstimatedParameters.param_vals(:,1))-new_steady_params(EstimatedParameters.param_vals(:,1))) ... - | (Model_par_varied.params(EstimatedParameters.param_vals(:,1))-new_steady_params_2(EstimatedParameters.param_vals(:,1)))); + | (Model_par_varied.params(EstimatedParameters.param_vals(:,1))-new_steady_params_2(EstimatedParameters.param_vals(:,1)))); if ~isempty(changed_par_indices) fprintf('\nThe steady state file internally changed the values of the following estimated parameters:\n') @@ -171,8 +171,8 @@ if info(1) > 0 error('Your model has at least one unit root and you are using a nonlinear filter. Please set nonlinear_filter_initialization=3.') end else - disp('Error in computing likelihood for initial parameter values') - print_info(info, DynareOptions.noprint, DynareOptions) + disp('Error in computing likelihood for initial parameter values') + print_info(info, DynareOptions.noprint, DynareOptions) end end diff --git a/matlab/initvalf.m b/matlab/initvalf.m index 0493a2b48a..28292ed61f 100644 --- a/matlab/initvalf.m +++ b/matlab/initvalf.m @@ -58,15 +58,15 @@ if ~exist(fullname) end switch (extension) - case '.m' - eval(basename); - case '.mat' - load(basename); - case { '.xls', '.xlsx' } - [data_,names_v_]=xlsread(fullname); % Octave needs the extension explicitly - series_=0; - otherwise - error(['Unsupported extension for datafile: ' extension]) + case '.m' + eval(basename); + case '.mat' + load(basename); + case { '.xls', '.xlsx' } + [data_,names_v_]=xlsread(fullname); % Octave needs the extension explicitly + series_=0; + otherwise + error(['Unsupported extension for datafile: ' extension]) end options_.initval_file = 1; diff --git a/matlab/interpret_resol_info.m b/matlab/interpret_resol_info.m index de16d47e09..a80a23f5d4 100644 --- a/matlab/interpret_resol_info.m +++ b/matlab/interpret_resol_info.m @@ -1,5 +1,5 @@ function message = interpret_resol_info(info) - + % Returns a message describing problem encountered during the resolution of % a model. % @@ -8,7 +8,7 @@ function message = interpret_resol_info(info) % % OUTPUTS % - message [string] Description of the issue preventing model's resolution. - + % Copyright (C) 2001-2016 Dynare Team % % This file is part of Dynare. diff --git a/matlab/isolder.m b/matlab/isolder.m index 091455ad07..127393854e 100644 --- a/matlab/isolder.m +++ b/matlab/isolder.m @@ -29,9 +29,9 @@ function b = isolder(f, F) % --*-- Unitary tests --*-- if nargin<2 || isempty(F) F = pwd(); end - + b = true; - + files = dir(F); tfile = dir(f); tdate = tfile.datenum; diff --git a/matlab/k_order_pert.m b/matlab/k_order_pert.m index db1ef91f48..4c6917f5fb 100644 --- a/matlab/k_order_pert.m +++ b/matlab/k_order_pert.m @@ -28,26 +28,26 @@ exo_nbr = M.exo_nbr; nspred = M.nspred; if order>1 && options.loglinear - error('The loglinear-option currently only works at order 1') + error('The loglinear-option currently only works at order 1') end if M.maximum_endo_lead == 0 && order>1 - error(['2nd and 3rd order approximation not implemented for purely ' ... - 'backward models']) + error(['2nd and 3rd order approximation not implemented for purely ' ... + 'backward models']) end switch(order) case 1 [err, g_1] = k_order_perturbation(dr,M,options); if err - info(1)=9; - return; + info(1)=9; + return; end dr.g_1 = g_1; case 2 [err, g_0, g_1, g_2] = k_order_perturbation(dr,M,options); if err - info(1)=9; - return; + info(1)=9; + return; end dr.g_0 = g_0; dr.g_1 = g_1; @@ -57,15 +57,15 @@ switch(order) [err, g_0, g_1, g_2, g_3, derivs] = k_order_perturbation(dr, ... M,options); if err - info(1)=9; - return; + info(1)=9; + return; end else [err, g_0, g_1, g_2, g_3] = k_order_perturbation(dr, ... M,options); if err - info(1)=9; - return; + info(1)=9; + return; end end dr.g_0 = g_0; @@ -205,5 +205,5 @@ for i=1:n1 end - - + + diff --git a/matlab/kalman/likelihood/computeDLIK.m b/matlab/kalman/likelihood/computeDLIK.m index 1acb0796ff..eab34c3baf 100644 --- a/matlab/kalman/likelihood/computeDLIK.m +++ b/matlab/kalman/likelihood/computeDLIK.m @@ -22,19 +22,19 @@ function [Da,DP,DLIK,D2a,D2P,Hesst] = computeDLIK(k,tmp,Z,Zflag,v,T,K,P,iF,Da,DY persistent DK DF D2K D2F if notsteady -if Zflag - [DK,DF,DP1] = computeDKalmanZ(T,DT,DOm,P,DP,DH,Z,iF,K); - if nargout>4, - [D2K,D2F,D2P] = computeD2KalmanZ(T,DT,D2T,D2Om,P,DP,D2P,DH,Z,iF,K,DK); - end -else - [DK,DF,DP1] = computeDKalman(T,DT,DOm,P,DP,DH,Z,iF,K); - if nargout>4, - [D2K,D2F,D2P] = computeD2Kalman(T,DT,D2T,D2Om,P,DP,D2P,DH,Z,iF,K,DK); + if Zflag + [DK,DF,DP1] = computeDKalmanZ(T,DT,DOm,P,DP,DH,Z,iF,K); + if nargout>4, + [D2K,D2F,D2P] = computeD2KalmanZ(T,DT,D2T,D2Om,P,DP,D2P,DH,Z,iF,K,DK); + end + else + [DK,DF,DP1] = computeDKalman(T,DT,DOm,P,DP,DH,Z,iF,K); + if nargout>4, + [D2K,D2F,D2P] = computeD2Kalman(T,DT,D2T,D2Om,P,DP,D2P,DH,Z,iF,K,DK); + end end -end -DP=DP1; -clear DP1, + DP=DP1; + clear DP1, else DP=DP; if nargout>4, @@ -47,20 +47,20 @@ Dv=zeros(length(v),k); for ii = 1:k if Zflag Dv(:,ii) = -Z*Da(:,ii) - Z*DYss(:,ii); -% if nargout>4, -% for jj = 1:ii -% D2v(:,jj,ii) = -Z*D2Yss(:,jj,ii) - Z*D2a(:,jj,ii); -% D2v(:,ii,jj) = D2v(:,jj,ii); -% end -% end + % if nargout>4, + % for jj = 1:ii + % D2v(:,jj,ii) = -Z*D2Yss(:,jj,ii) - Z*D2a(:,jj,ii); + % D2v(:,ii,jj) = D2v(:,jj,ii); + % end + % end else Dv(:,ii) = -Da(Z,ii) - DYss(Z,ii); -% if nargout>4, -% for jj = 1:ii -% D2v(:,jj,ii) = -D2Yss(Z,jj,ii) - D2a(Z,jj,ii); -% D2v(:,ii,jj) = D2v(:,jj,ii); -% end -% end + % if nargout>4, + % for jj = 1:ii + % D2v(:,jj,ii) = -D2Yss(Z,jj,ii) - D2a(Z,jj,ii); + % D2v(:,ii,jj) = D2v(:,jj,ii); + % end + % end end end @@ -82,9 +82,9 @@ for ii = 1:k d2Kij = D2K(:,:,jj,ii); d2Fij = D2F(:,:,jj,ii); d2iFij = -diFi*dFj*iF -iF*d2Fij*iF -iF*dFj*diFi; -% dtmpj = Da(:,jj)+dKj*v+K*Dv(:,jj); + % dtmpj = Da(:,jj)+dKj*v+K*Dv(:,jj); -% d2vij = D2v(:,ii,jj); + % d2vij = D2v(:,ii,jj); if Zflag d2vij = -Z*D2Yss(:,jj,ii) - Z*D2a(:,jj,ii); else @@ -99,7 +99,7 @@ for ii = 1:k end end end - + Da(:,ii) = DT(:,:,ii)*tmp + T*dtmp(:,ii); DLIK(ii,1) = trace( iF*DF(:,:,ii) ) + 2*Dv(:,ii)'*iF*v - v'*(iF*DF(:,:,ii)*iF)*v; end @@ -108,16 +108,16 @@ if nargout==4, % Hesst(ii,jj) = getHesst_ij(v,Dv(:,ii),Dv(:,jj),0,iF,diFi,diFj,0,dFj,0); vecDPmf = reshape(DF,[],k); D2a = 2*Dv'*iF*Dv + (vecDPmf' * kron(iF,iF) * vecDPmf); -% for ii = 1:k -% -% diFi = -iF*DF(:,:,ii)*iF; -% for jj = 1:ii -% dFj = DF(:,:,jj); -% diFj = -iF*DF(:,:,jj)*iF; -% -% Hesst(ii,jj) = getHesst_ij(v*0,Dv(:,ii),Dv(:,jj),v*0,iF,diFi,diFj,0,-dFj,0); -% end -% end + % for ii = 1:k + % + % diFi = -iF*DF(:,:,ii)*iF; + % for jj = 1:ii + % dFj = DF(:,:,jj); + % diFj = -iF*DF(:,:,jj)*iF; + % + % Hesst(ii,jj) = getHesst_ij(v*0,Dv(:,ii),Dv(:,jj),v*0,iF,diFi,diFj,0,-dFj,0); + % end + % end end % end of computeDLIK @@ -168,9 +168,9 @@ end function [d2K,d2S,d2P1] = computeD2Kalman(A,dA,d2A,d2Om,P0,dP0,d2P1,DH,Z,iF,K0,dK0); % computes the second derivatives of the Kalman matrices % note: A=T in main func. - - k = size(dA,3); - tmp = P0-K0*P0(Z,:); + +k = size(dA,3); +tmp = P0-K0*P0(Z,:); [ns,no] = size(K0); % CPC = C*P0*C'; CPC = .5*(CPC+CPC');iF = inv(CPC); @@ -186,14 +186,14 @@ jcount=0; for ii = 1:k dAi = dA(:,:,ii); dFi = dP0(Z,Z,ii); -% d2Omi = d2Om(:,:,ii); + % d2Omi = d2Om(:,:,ii); diFi = -iF*dFi*iF; dKi = dK0(:,:,ii); for jj = 1:ii, jcount=jcount+1; dAj = dA(:,:,jj); dFj = dP0(Z,Z,jj); -% d2Omj = d2Om(:,:,jj); + % d2Omj = d2Om(:,:,jj); dFj = dP0(Z,Z,jj); diFj = -iF*dFj*iF; dKj = dK0(:,:,jj); @@ -201,33 +201,33 @@ for ii = 1:k d2Aij = reshape(d2A(:,jcount),[ns ns]); d2Pij = dyn_unvech(d2P1(:,jcount)); d2Omij = dyn_unvech(d2Om(:,jcount)); - - % second order - - d2Fij = d2Pij(Z,Z) ; - -% d2APC = d2Aij*P0*C' + A*d2Pij*C' + A*P0*d2Cij' + dAi*dPj*C' + dAj*dPi*C' + A*dPj*dCi' + A*dPi*dCj' + dAi*P0*dCj' + dAj*P0*dCi'; - d2APC = d2Pij(:,Z); - - d2iF = -diFi*dFj*iF -iF*d2Fij*iF -iF*dFj*diFi; - - d2Kij= d2Pij(:,Z)*iF + P0(:,Z)*d2iF + dP0(:,Z,jj)*diFi + dP0(:,Z,ii)*diFj; - d2KCP = d2Kij*P0(Z,:) + K0*d2Pij(Z,:) + dKi*dP0(Z,:,jj) + dKj*dP0(Z,:,ii) ; - - dtmpi = dP0(:,:,ii) - dK0(:,:,ii)*P0(Z,:) - K0*dP0(Z,:,ii); - dtmpj = dP0(:,:,jj) - dK0(:,:,jj)*P0(Z,:) - K0*dP0(Z,:,jj); - d2tmp = d2Pij - d2KCP; - - d2AtmpA = d2Aij*tmp*A' + A*d2tmp*A' + A*tmp*d2Aij' + dAi*dtmpj*A' + dAj*dtmpi*A' + A*dtmpj*dAi' + A*dtmpi*dAj' + dAi*tmp*dAj' + dAj*tmp*dAi'; - - d2K(:,:,ii,jj) = d2Kij; %#ok<NASGU> - d2P1(:,jcount) = dyn_vech(d2AtmpA + d2Omij); %#ok<*NASGU> - d2S(:,:,ii,jj) = d2Fij; - d2K(:,:,jj,ii) = d2Kij; %#ok<NASGU> -% d2P1(:,:,jj,ii) = d2AtmpA + d2Omij; %#ok<*NASGU> - d2S(:,:,jj,ii) = d2Fij; -% d2iS(:,:,ii,jj) = d2iF; + % second order + + d2Fij = d2Pij(Z,Z) ; + + % d2APC = d2Aij*P0*C' + A*d2Pij*C' + A*P0*d2Cij' + dAi*dPj*C' + dAj*dPi*C' + A*dPj*dCi' + A*dPi*dCj' + dAi*P0*dCj' + dAj*P0*dCi'; + d2APC = d2Pij(:,Z); + + d2iF = -diFi*dFj*iF -iF*d2Fij*iF -iF*dFj*diFi; + + d2Kij= d2Pij(:,Z)*iF + P0(:,Z)*d2iF + dP0(:,Z,jj)*diFi + dP0(:,Z,ii)*diFj; + + d2KCP = d2Kij*P0(Z,:) + K0*d2Pij(Z,:) + dKi*dP0(Z,:,jj) + dKj*dP0(Z,:,ii) ; + + dtmpi = dP0(:,:,ii) - dK0(:,:,ii)*P0(Z,:) - K0*dP0(Z,:,ii); + dtmpj = dP0(:,:,jj) - dK0(:,:,jj)*P0(Z,:) - K0*dP0(Z,:,jj); + d2tmp = d2Pij - d2KCP; + + d2AtmpA = d2Aij*tmp*A' + A*d2tmp*A' + A*tmp*d2Aij' + dAi*dtmpj*A' + dAj*dtmpi*A' + A*dtmpj*dAi' + A*dtmpi*dAj' + dAi*tmp*dAj' + dAj*tmp*dAi'; + + d2K(:,:,ii,jj) = d2Kij; %#ok<NASGU> + d2P1(:,jcount) = dyn_vech(d2AtmpA + d2Omij); %#ok<*NASGU> + d2S(:,:,ii,jj) = d2Fij; + d2K(:,:,jj,ii) = d2Kij; %#ok<NASGU> + % d2P1(:,:,jj,ii) = d2AtmpA + d2Omij; %#ok<*NASGU> + d2S(:,:,jj,ii) = d2Fij; + % d2iS(:,:,ii,jj) = d2iF; end end @@ -236,9 +236,9 @@ end function [d2K,d2S,d2P1] = computeD2KalmanZ(A,dA,d2A,d2Om,P0,dP0,d2P1,DH,Z,iF,K0,dK0); % computes the second derivatives of the Kalman matrices % note: A=T in main func. - - k = size(dA,3); - tmp = P0-K0*Z*P0(:,:); + +k = size(dA,3); +tmp = P0-K0*Z*P0(:,:); [ns,no] = size(K0); % CPC = C*P0*C'; CPC = .5*(CPC+CPC');iF = inv(CPC); @@ -254,14 +254,14 @@ jcount=0; for ii = 1:k, dAi = dA(:,:,ii); dFi = Z*dP0(:,:,ii)*Z; -% d2Omi = d2Om(:,:,ii); + % d2Omi = d2Om(:,:,ii); diFi = -iF*dFi*iF; dKi = dK0(:,:,ii); for jj = 1:ii, jcount=jcount+1; dAj = dA(:,:,jj); dFj = Z*dP0(:,:,jj)*Z; -% d2Omj = d2Om(:,:,jj); + % d2Omj = d2Om(:,:,jj); dFj = Z*dP0(:,:,jj)*Z; diFj = -iF*dFj*iF; dKj = dK0(:,:,jj); @@ -269,33 +269,33 @@ for ii = 1:k, d2Aij = reshape(d2A(:,jcount),[ns ns]); d2Pij = dyn_unvech(d2P1(:,jcount)); d2Omij = dyn_unvech(d2Om(:,jcount)); - - % second order - - d2Fij = Z*d2Pij(:,:)*Z ; - -% d2APC = d2Aij*P0*C' + A*d2Pij*C' + A*P0*d2Cij' + dAi*dPj*C' + dAj*dPi*C' + A*dPj*dCi' + A*dPi*dCj' + dAi*P0*dCj' + dAj*P0*dCi'; - d2APC = d2Pij(:,:)*Z; - - d2iF = -diFi*dFj*iF -iF*d2Fij*iF -iF*dFj*diFi; - - d2Kij= d2Pij(:,:)*Z*iF + P0(:,:)*Z*d2iF + dP0(:,:,jj)*Z*diFi + dP0(:,:,ii)*Z*diFj; - d2KCP = d2Kij*Z*P0(:,:) + K0*Z*d2Pij(:,:) + dKi*Z*dP0(:,:,jj) + dKj*Z*dP0(:,:,ii) ; - - dtmpi = dP0(:,:,ii) - dK0(:,:,ii)*Z*P0(:,:) - K0*Z*dP0(:,:,ii); - dtmpj = dP0(:,:,jj) - dK0(:,:,jj)*Z*P0(:,:) - K0*Z*dP0(:,:,jj); - d2tmp = d2Pij - d2KCP; - - d2AtmpA = d2Aij*tmp*A' + A*d2tmp*A' + A*tmp*d2Aij' + dAi*dtmpj*A' + dAj*dtmpi*A' + A*dtmpj*dAi' + A*dtmpi*dAj' + dAi*tmp*dAj' + dAj*tmp*dAi'; - - d2K(:,:,ii,jj) = d2Kij; %#ok<NASGU> - d2P1(:,jcount) = dyn_vech(d2AtmpA + d2Omij); %#ok<*NASGU> - d2S(:,:,ii,jj) = d2Fij; -% d2iS(:,:,ii,jj) = d2iF; - d2K(:,:,jj,ii) = d2Kij; %#ok<NASGU> -% d2P1(:,:,jj,ii) = d2AtmpA + d2Omij; %#ok<*NASGU> - d2S(:,:,jj,ii) = d2Fij; + % second order + + d2Fij = Z*d2Pij(:,:)*Z ; + + % d2APC = d2Aij*P0*C' + A*d2Pij*C' + A*P0*d2Cij' + dAi*dPj*C' + dAj*dPi*C' + A*dPj*dCi' + A*dPi*dCj' + dAi*P0*dCj' + dAj*P0*dCi'; + d2APC = d2Pij(:,:)*Z; + + d2iF = -diFi*dFj*iF -iF*d2Fij*iF -iF*dFj*diFi; + + d2Kij= d2Pij(:,:)*Z*iF + P0(:,:)*Z*d2iF + dP0(:,:,jj)*Z*diFi + dP0(:,:,ii)*Z*diFj; + + d2KCP = d2Kij*Z*P0(:,:) + K0*Z*d2Pij(:,:) + dKi*Z*dP0(:,:,jj) + dKj*Z*dP0(:,:,ii) ; + + dtmpi = dP0(:,:,ii) - dK0(:,:,ii)*Z*P0(:,:) - K0*Z*dP0(:,:,ii); + dtmpj = dP0(:,:,jj) - dK0(:,:,jj)*Z*P0(:,:) - K0*Z*dP0(:,:,jj); + d2tmp = d2Pij - d2KCP; + + d2AtmpA = d2Aij*tmp*A' + A*d2tmp*A' + A*tmp*d2Aij' + dAi*dtmpj*A' + dAj*dtmpi*A' + A*dtmpj*dAi' + A*dtmpi*dAj' + dAi*tmp*dAj' + dAj*tmp*dAi'; + + d2K(:,:,ii,jj) = d2Kij; %#ok<NASGU> + d2P1(:,jcount) = dyn_vech(d2AtmpA + d2Omij); %#ok<*NASGU> + d2S(:,:,ii,jj) = d2Fij; + % d2iS(:,:,ii,jj) = d2iF; + d2K(:,:,jj,ii) = d2Kij; %#ok<NASGU> + % d2P1(:,:,jj,ii) = d2AtmpA + d2Omij; %#ok<*NASGU> + d2S(:,:,jj,ii) = d2Fij; end end diff --git a/matlab/kalman/likelihood/kalman_filter.m b/matlab/kalman/likelihood/kalman_filter.m index 398ab1f4bd..e0dcafadcb 100644 --- a/matlab/kalman/likelihood/kalman_filter.m +++ b/matlab/kalman/likelihood/kalman_filter.m @@ -237,7 +237,7 @@ if analytic_derivation, dlikk = dlikk/2; if analytic_derivation==2 || asy_hess, if asy_hess==0, - Hess = Hess + tril(Hess,-1)'; + Hess = Hess + tril(Hess,-1)'; end Hess = -Hess/2; end diff --git a/matlab/kalman/likelihood/kalman_filter_d.m b/matlab/kalman/likelihood/kalman_filter_d.m index a10cf6f4d2..61c4b53fea 100644 --- a/matlab/kalman/likelihood/kalman_filter_d.m +++ b/matlab/kalman/likelihood/kalman_filter_d.m @@ -69,10 +69,10 @@ while rank(Pinf,diffuse_kalman_tol) && (t<=last) s = t-start+1; v = Y(:,t)-Z*a; %get prediction error v^(0) in (5.13) DK (2012) Finf = Z*Pinf*Z'; % (5.7) in DK (2012) - %do case distinction based on whether F_{\infty,t} has full rank or 0 rank + %do case distinction based on whether F_{\infty,t} has full rank or 0 rank if rcond(Finf) < diffuse_kalman_tol %F_{\infty,t} = 0 if ~all(abs(Finf(:)) < diffuse_kalman_tol) %rank-deficient but not rank 0 - % The univariate diffuse kalman filter should be used instead. + % The univariate diffuse kalman filter should be used instead. return else %rank of F_{\infty,t} is 0 Fstar = Z*Pstar*Z' + H; % (5.7) in DK (2012) @@ -81,8 +81,8 @@ while rank(Pinf,diffuse_kalman_tol) && (t<=last) % The univariate diffuse kalman filter should be used. return else %rank 0 - %pathological case, discard draw - return + %pathological case, discard draw + return end else iFstar = inv(Fstar); @@ -95,15 +95,15 @@ while rank(Pinf,diffuse_kalman_tol) && (t<=last) end end else %F_{\infty,t} positive definite - %To compare to DK (2012), this block makes use of the following transformation - %Kstar=T^{-1}*K^{(1)}=M_{*}*F^{(1)}+M_{\infty}*F^{(2)} - % =P_{*}*Z'*F^{(1)}+P_{\infty}*Z'*((-1)*(-F_{\infty}^{-1})*F_{*}*(F_{\infty}^{-1})) - % =[P_{*}*Z'-Kinf*F_{*})]*F^{(1)} - %Make use of L^{0}'=(T-K^{(0)}*Z)'=(T-T*M_{\infty}*F^{(1)}*Z)' - % =(T-T*P_{\infty*Z'*F^{(1)}*Z)'=(T-T*Kinf*Z)' - % = (T*(I-*Kinf*Z))'=(I-Z'*Kinf')*T' - %P_{*}=T*P_{\infty}*L^{(1)}+T*P_{*}*L^{(0)}+RQR - % =T*[(P_{\infty}*(-K^{(1)*Z}))+P_{*}*(I-Z'*Kinf')*T'+RQR] + %To compare to DK (2012), this block makes use of the following transformation + %Kstar=T^{-1}*K^{(1)}=M_{*}*F^{(1)}+M_{\infty}*F^{(2)} + % =P_{*}*Z'*F^{(1)}+P_{\infty}*Z'*((-1)*(-F_{\infty}^{-1})*F_{*}*(F_{\infty}^{-1})) + % =[P_{*}*Z'-Kinf*F_{*})]*F^{(1)} + %Make use of L^{0}'=(T-K^{(0)}*Z)'=(T-T*M_{\infty}*F^{(1)}*Z)' + % =(T-T*P_{\infty*Z'*F^{(1)}*Z)'=(T-T*Kinf*Z)' + % = (T*(I-*Kinf*Z))'=(I-Z'*Kinf')*T' + %P_{*}=T*P_{\infty}*L^{(1)}+T*P_{*}*L^{(0)}+RQR + % =T*[(P_{\infty}*(-K^{(1)*Z}))+P_{*}*(I-Z'*Kinf')*T'+RQR] dlik(s)= log(det(Finf)); %set w_t to top case in bottom equation page 172, DK (2012) iFinf = inv(Finf); Kinf = Pinf*Z'*iFinf; %define Kinf=T^{-1}*K_0 with M_{\infty}=Pinf*Z' diff --git a/matlab/kalman/likelihood/kalman_filter_fast.m b/matlab/kalman/likelihood/kalman_filter_fast.m index 4319b5502f..cc8c3d1f92 100644 --- a/matlab/kalman/likelihood/kalman_filter_fast.m +++ b/matlab/kalman/likelihood/kalman_filter_fast.m @@ -199,7 +199,7 @@ if analytic_derivation, dlikk = dlikk/2; if analytic_derivation==2 || asy_hess, if asy_hess==0, - Hess = Hess + tril(Hess,-1)'; + Hess = Hess + tril(Hess,-1)'; end Hess = -Hess/2; end @@ -210,10 +210,10 @@ if t <= last if analytic_derivation, if analytic_derivation==2, [tmp, tmp2] = kalman_filter_ss(Y,t,last,a,T,K,iF,dF,Z,pp,Zflag, ... - analytic_derivation,Da,DT,DYss,D2a,D2T,D2Yss); + analytic_derivation,Da,DT,DYss,D2a,D2T,D2Yss); else [tmp, tmp2] = kalman_filter_ss(Y,t,last,a,T,K,iF,dF,Z,pp,Zflag, ... - analytic_derivation,Da,DT,DYss,asy_hess); + analytic_derivation,Da,DT,DYss,asy_hess); end likk(s+1:end)=tmp2{1}; dlikk(s+1:end,:)=tmp2{2}; diff --git a/matlab/kalman/likelihood/missing_observations_kalman_filter_d.m b/matlab/kalman/likelihood/missing_observations_kalman_filter_d.m index a497d6e53f..5334c301e0 100644 --- a/matlab/kalman/likelihood/missing_observations_kalman_filter_d.m +++ b/matlab/kalman/likelihood/missing_observations_kalman_filter_d.m @@ -1,8 +1,8 @@ function [dLIK,dlik,a,Pstar] = missing_observations_kalman_filter_d(data_index,number_of_observations,no_more_missing_observations, ... - Y, start, last, ... - a, Pinf, Pstar, ... - kalman_tol, diffuse_kalman_tol, riccati_tol, presample, ... - T, R, Q, H, Z, mm, pp, rr) + Y, start, last, ... + a, Pinf, Pstar, ... + kalman_tol, diffuse_kalman_tol, riccati_tol, presample, ... + T, R, Q, H, Z, mm, pp, rr) % Computes the diffuse likelihood of a state space model when some observations are missing. % % INPUTS @@ -91,7 +91,7 @@ while rank(Pinf,diffuse_kalman_tol) && (t<=last) Finf = ZZ*Pinf*ZZ'; % (5.7) in DK (2012) if rcond(Finf) < diffuse_kalman_tol %F_{\infty,t} = 0 if ~all(abs(Finf(:)) < diffuse_kalman_tol) %rank-deficient but not rank 0 - % The univariate diffuse kalman filter should be used. + % The univariate diffuse kalman filter should be used. return else %rank of F_{\infty,t} is 0 Fstar = ZZ*Pstar*ZZ' + H(d_index,d_index); % (5.7) in DK (2012) @@ -100,7 +100,7 @@ while rank(Pinf,diffuse_kalman_tol) && (t<=last) % The univariate diffuse kalman filter should be used. return else %rank 0 - %pathological case, discard draw + %pathological case, discard draw return end else diff --git a/matlab/kalman/likelihood/univariate_computeDLIK.m b/matlab/kalman/likelihood/univariate_computeDLIK.m index 1338a84a62..3601ba7544 100644 --- a/matlab/kalman/likelihood/univariate_computeDLIK.m +++ b/matlab/kalman/likelihood/univariate_computeDLIK.m @@ -67,7 +67,7 @@ if notsteady, D2K(:,i,j) = D2K(:,i,j) -PZ*D2F(j,i)/F^2 - squeeze(DP(:,Z,i))*DF(j)/F^2 - ... squeeze(DP(:,Z,j))*DF(i)'/F^2 + 2/F^3*PZ*DF(i)'*DF(j); D2K(:,j,i) = D2K(:,i,j); -% D2K = squeeze(D2P(:,Z,:,:))/F; + % D2K = squeeze(D2P(:,Z,:,:))/F; end end end @@ -104,12 +104,12 @@ end DLIK = DF/F + 2*Dv'/F*v - v^2/F^2*DF; if nargout==6 Hesst = D2F/F-1/F^2*(DF*DF') + 2*D2v/F*v + 2*(Dv'*Dv)/F - 2*(DF*Dv)*v/F^2 ... - - v^2/F^2*D2F - 2*v/F^2*(Dv'*DF') + 2*v^2/F^3*(DF*DF'); + - v^2/F^2*D2F - 2*v/F^2*(Dv'*DF') + 2*v^2/F^3*(DF*DF'); elseif nargout==4, D2a = 1/F^2*(DF*DF') + 2*(Dv'*Dv)/F ; -% D2a = -1/F^2*(DF*DF') + 2*(Dv'*Dv)/F + 2*v^2/F^3*(DF*DF') ... -% - 2*(DF*Dv)*v/F^2 - 2*v/F^2*(Dv'*DF'); -% D2a = +2*(Dv'*Dv)/F + (DF' * DF)/F^2; + % D2a = -1/F^2*(DF*DF') + 2*(Dv'*Dv)/F + 2*v^2/F^3*(DF*DF') ... + % - 2*(DF*Dv)*v/F^2 - 2*v/F^2*(Dv'*DF'); + % D2a = +2*(Dv'*Dv)/F + (DF' * DF)/F^2; end Da = Da + DK*v+K*Dv; @@ -145,9 +145,9 @@ if notsteady, jcount = jcount+1; tmp = dyn_unvech(D2P(:,jcount)); tmp = tmp - (tmp*Z')*K' - (DP(:,:,j)*Z')*DK(:,i)' ... - - (DP(:,:,i)*Z')*DK(:,j)' -PZ*D2K(:,j,i)'; + - (DP(:,:,i)*Z')*DK(:,j)' -PZ*D2K(:,j,i)'; D2P(:,jcount) = dyn_vech(tmp); -% D2P(:,:,i,j) = D2P(:,:,j,i); + % D2P(:,:,i,j) = D2P(:,:,j,i); end end else @@ -160,7 +160,7 @@ if notsteady, D2PZ = tmp(:,Z); tmp = tmp - D2PZ*K' - DPZ(:,j)*DK(:,i)'- DPZ(:,i)*DK(:,j)' - PZ*squeeze(D2K(:,j,i))'; D2P(:,jcount) = dyn_vech(tmp); -% D2P(:,:,i,j) = D2P(:,:,j,i); + % D2P(:,:,i,j) = D2P(:,:,j,i); end end diff --git a/matlab/kalman/likelihood/univariate_computeDstate.m b/matlab/kalman/likelihood/univariate_computeDstate.m index a535a0a518..52e85c2553 100644 --- a/matlab/kalman/likelihood/univariate_computeDstate.m +++ b/matlab/kalman/likelihood/univariate_computeDstate.m @@ -43,12 +43,12 @@ if nargout>2, if notsteady, tmp = dyn_unvech(D2P(:,jcount)); tmp = T*tmp*T' +DT(:,:,i)*DP(:,:,j)*T'+T*DP(:,:,j)*DT(:,:,i)' + ... - DT(:,:,j)*DP(:,:,i)*T'+T*DP(:,:,i)*DT(:,:,j)' + ... - DT(:,:,j)*P*DT(:,:,i)'+DT(:,:,i)*P*DT(:,:,j)'+ ... - reshape(D2T(:,jcount),size(T))*P*T'+T*P*reshape(D2T(:,jcount),size(T))' + ... - dyn_unvech(D2Om(:,jcount)); + DT(:,:,j)*DP(:,:,i)*T'+T*DP(:,:,i)*DT(:,:,j)' + ... + DT(:,:,j)*P*DT(:,:,i)'+DT(:,:,i)*P*DT(:,:,j)'+ ... + reshape(D2T(:,jcount),size(T))*P*T'+T*P*reshape(D2T(:,jcount),size(T))' + ... + dyn_unvech(D2Om(:,jcount)); D2P(:,jcount) = dyn_vech(tmp); -% D2P(:,:,i,j) = D2P(:,:,j,i); + % D2P(:,:,i,j) = D2P(:,:,j,i); end end end diff --git a/matlab/kalman/likelihood/univariate_kalman_filter.m b/matlab/kalman/likelihood/univariate_kalman_filter.m index dd4559cd5f..9f9571a645 100644 --- a/matlab/kalman/likelihood/univariate_kalman_filter.m +++ b/matlab/kalman/likelihood/univariate_kalman_filter.m @@ -229,7 +229,7 @@ if analytic_derivation, DLIK = DLIK/2; dlik = dlik/2; if analytic_derivation==2 || asy_hess, -% Hess = (Hess + Hess')/2; + % Hess = (Hess + Hess')/2; Hess = -Hess/2; end end @@ -239,10 +239,10 @@ if t <= last if analytic_derivation, if analytic_derivation==2, [tmp, tmp2] = univariate_kalman_filter_ss(Y,t,last,a,P,kalman_tol,T,H,Z,pp,Zflag, ... - analytic_derivation,Da,DT,DYss,DP,DH,D2a,D2T,D2Yss,D2P); + analytic_derivation,Da,DT,DYss,DP,DH,D2a,D2T,D2Yss,D2P); else [tmp, tmp2] = univariate_kalman_filter_ss(Y,t,last,a,P,kalman_tol,T,H,Z,pp,Zflag, ... - analytic_derivation,Da,DT,DYss,DP,DH,asy_hess); + analytic_derivation,Da,DT,DYss,DP,DH,asy_hess); end lik(s+1:end,:)=tmp2{1}; dlik(s+1:end,:)=tmp2{2}; diff --git a/matlab/kalman/likelihood/univariate_kalman_filter_ss.m b/matlab/kalman/likelihood/univariate_kalman_filter_ss.m index cbc1d57753..dd2623b8ee 100644 --- a/matlab/kalman/likelihood/univariate_kalman_filter_ss.m +++ b/matlab/kalman/likelihood/univariate_kalman_filter_ss.m @@ -171,7 +171,7 @@ if analytic_derivation, likk = {likk, dlikk}; end if analytic_derivation==2 || asy_hess, -% Hess = (Hess + Hess')/2; + % Hess = (Hess + Hess')/2; Hess = -Hess/2; LIK={LIK,DLIK,Hess}; elseif analytic_derivation==1, diff --git a/matlab/lmmcp/catstruct.m b/matlab/lmmcp/catstruct.m index 540bc99d7a..040c0b7ed9 100644 --- a/matlab/lmmcp/catstruct.m +++ b/matlab/lmmcp/catstruct.m @@ -1,174 +1,174 @@ -function A = catstruct(varargin) -% CATSTRUCT Concatenate or merge structures with different fieldnames -% X = CATSTRUCT(S1,S2,S3,...) merges the structures S1, S2, S3 ... -% into one new structure X. X contains all fields present in the various -% structures. An example: -% -% A.name = 'Me' ; -% B.income = 99999 ; -% X = catstruct(A,B) -% % -> X.name = 'Me' ; -% % X.income = 99999 ; -% -% If a fieldname is not unique among structures (i.e., a fieldname is -% present in more than one structure), only the value from the last -% structure with this field is used. In this case, the fields are -% alphabetically sorted. A warning is issued as well. An axample: -% -% S1.name = 'Me' ; -% S2.age = 20 ; S3.age = 30 ; S4.age = 40 ; -% S5.honest = false ; -% Y = catstruct(S1,S2,S3,S4,S5) % use value from S4 -% -% The inputs can be array of structures. All structures should have the -% same size. An example: -% -% C(1).bb = 1 ; C(2).bb = 2 ; -% D(1).aa = 3 ; D(2).aa = 4 ; -% CD = catstruct(C,D) % CD is a 1x2 structure array with fields bb and aa -% -% The last input can be the string 'sorted'. In this case, -% CATSTRUCT(S1,S2, ..., 'sorted') will sort the fieldnames alphabetically. -% To sort the fieldnames of a structure A, you could use -% CATSTRUCT(A,'sorted') but I recommend ORDERFIELDS for doing that. -% -% When there is nothing to concatenate, the result will be an empty -% struct (0x0 struct array with no fields). -% -% NOTE: To concatenate similar arrays of structs, you can use simple -% concatenation: -% A = dir('*.mat') ; B = dir('*.m') ; C = [A ; B] ; -% -% See also CAT, STRUCT, FIELDNAMES, STRUCT2CELL, ORDERFIELDS - -% for Matlab R13 and up -% version 3.0 (mar 2013) -% Originally downloaded from MATLAB central: -% http://www.mathworks.com/matlabcentral/fileexchange/7842-catstruct - -% Copyright (C) 2005 Jos van der Geest <jos@jasen.nl> -% Copyright (C) 2013 Christophe Gouel -% Copyright (C) 2016 Dynare Team -% -% Redistribution and use in source and binary forms, with or without -% modification, are permitted provided that the following conditions are -% met: -% -% * Redistributions of source code must retain the above copyright -% notice, this list of conditions and the following disclaimer. -% * Redistributions in binary form must reproduce the above copyright -% notice, this list of conditions and the following disclaimer in -% the documentation and/or other materials provided with the distribution -% -% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -% POSSIBILITY OF SUCH DAMAGE. - -% History -% Created in 2005 -% Revisions -% 2.0 (sep 2007) removed bug when dealing with fields containing cell -% arrays (Thanks to Rene Willemink) -% 2.1 (sep 2008) added warning and error identifiers -% 2.2 (oct 2008) fixed error when dealing with empty structs (Thanks to -% Lars Barring) -% 3.0 (mar 2013) fixed problem when the inputs were array of structures -% (thanks to Tor Inge Birkenes for pointing this out). -% Rephrased the help section as well. - -narginchk(1, Inf); -N = nargin ; - -if ~isstruct(varargin{end}), - if isequal(varargin{end},'sorted'), - sorted = 1 ; - N = N-1 ; - if N<1 - error('catstruct: wrong number of input arguments') ; - end - else - error('catstruct:InvalidArgument','Last argument should be a structure, or the string "sorted".') ; - end -else - sorted = 0 ; -end - -sz0 = [] ; % used to check that all inputs have the same size - -% used to check for a few trivial cases -NonEmptyInputs = false(N,1) ; -NonEmptyInputsN = 0 ; - -% used to collect the fieldnames and the inputs -FN = cell(N,1) ; -VAL = cell(N,1) ; - -% parse the inputs -for ii=1:N, - X = varargin{ii} ; - if ~isstruct(X), - error('catstruct:InvalidArgument',['Argument #' num2str(ii) ' is not a structure.']) ; - end - - if ~isempty(X), - % empty structs are ignored - if ii > 1 && ~isempty(sz0) - if ~isequal(size(X), sz0) - error('catstruct:UnequalSizes','All structures should have the same size.') ; - end - else - sz0 = size(X) ; - end - NonEmptyInputsN = NonEmptyInputsN + 1 ; - NonEmptyInputs(ii) = true ; - FN{ii} = fieldnames(X) ; - VAL{ii} = struct2cell(X) ; - end -end - -if NonEmptyInputsN == 0 - % all structures were empty - A = struct([]) ; -elseif NonEmptyInputsN == 1, - % there was only one non-empty structure - A = varargin{NonEmptyInputs} ; - if sorted, - A = orderfields(A) ; - end -else - % there is actually something to concatenate - FN = cat(1,FN{:}) ; - VAL = cat(1,VAL{:}) ; - FN = squeeze(FN) ; - VAL = squeeze(VAL) ; - MatlabVersion = version; - if isoctave || str2double(MatlabVersion(end-5:end-2))<2013 % Equivalent to, but faster than if verLessThan('matlab','8.1') - [UFN,ind] = unique(FN) ; - else - [UFN,ind] = unique(FN,'legacy') ; - end - - if numel(UFN) ~= numel(FN), - warning('catstruct:DuplicatesFound','Fieldnames are not unique between structures.') ; - sorted = 1 ; - end - - if sorted, - VAL = VAL(ind,:) ; - FN = FN(ind,:) ; - end - - A = cell2struct(VAL, FN); - A = reshape(A, sz0) ; % reshape into original format -end - - - +function A = catstruct(varargin) +% CATSTRUCT Concatenate or merge structures with different fieldnames +% X = CATSTRUCT(S1,S2,S3,...) merges the structures S1, S2, S3 ... +% into one new structure X. X contains all fields present in the various +% structures. An example: +% +% A.name = 'Me' ; +% B.income = 99999 ; +% X = catstruct(A,B) +% % -> X.name = 'Me' ; +% % X.income = 99999 ; +% +% If a fieldname is not unique among structures (i.e., a fieldname is +% present in more than one structure), only the value from the last +% structure with this field is used. In this case, the fields are +% alphabetically sorted. A warning is issued as well. An axample: +% +% S1.name = 'Me' ; +% S2.age = 20 ; S3.age = 30 ; S4.age = 40 ; +% S5.honest = false ; +% Y = catstruct(S1,S2,S3,S4,S5) % use value from S4 +% +% The inputs can be array of structures. All structures should have the +% same size. An example: +% +% C(1).bb = 1 ; C(2).bb = 2 ; +% D(1).aa = 3 ; D(2).aa = 4 ; +% CD = catstruct(C,D) % CD is a 1x2 structure array with fields bb and aa +% +% The last input can be the string 'sorted'. In this case, +% CATSTRUCT(S1,S2, ..., 'sorted') will sort the fieldnames alphabetically. +% To sort the fieldnames of a structure A, you could use +% CATSTRUCT(A,'sorted') but I recommend ORDERFIELDS for doing that. +% +% When there is nothing to concatenate, the result will be an empty +% struct (0x0 struct array with no fields). +% +% NOTE: To concatenate similar arrays of structs, you can use simple +% concatenation: +% A = dir('*.mat') ; B = dir('*.m') ; C = [A ; B] ; +% +% See also CAT, STRUCT, FIELDNAMES, STRUCT2CELL, ORDERFIELDS + +% for Matlab R13 and up +% version 3.0 (mar 2013) +% Originally downloaded from MATLAB central: +% http://www.mathworks.com/matlabcentral/fileexchange/7842-catstruct + +% Copyright (C) 2005 Jos van der Geest <jos@jasen.nl> +% Copyright (C) 2013 Christophe Gouel +% Copyright (C) 2016 Dynare Team +% +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are +% met: +% +% * Redistributions of source code must retain the above copyright +% notice, this list of conditions and the following disclaimer. +% * Redistributions in binary form must reproduce the above copyright +% notice, this list of conditions and the following disclaimer in +% the documentation and/or other materials provided with the distribution +% +% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +% POSSIBILITY OF SUCH DAMAGE. + +% History +% Created in 2005 +% Revisions +% 2.0 (sep 2007) removed bug when dealing with fields containing cell +% arrays (Thanks to Rene Willemink) +% 2.1 (sep 2008) added warning and error identifiers +% 2.2 (oct 2008) fixed error when dealing with empty structs (Thanks to +% Lars Barring) +% 3.0 (mar 2013) fixed problem when the inputs were array of structures +% (thanks to Tor Inge Birkenes for pointing this out). +% Rephrased the help section as well. + +narginchk(1, Inf); +N = nargin ; + +if ~isstruct(varargin{end}), + if isequal(varargin{end},'sorted'), + sorted = 1 ; + N = N-1 ; + if N<1 + error('catstruct: wrong number of input arguments') ; + end + else + error('catstruct:InvalidArgument','Last argument should be a structure, or the string "sorted".') ; + end +else + sorted = 0 ; +end + +sz0 = [] ; % used to check that all inputs have the same size + +% used to check for a few trivial cases +NonEmptyInputs = false(N,1) ; +NonEmptyInputsN = 0 ; + +% used to collect the fieldnames and the inputs +FN = cell(N,1) ; +VAL = cell(N,1) ; + +% parse the inputs +for ii=1:N, + X = varargin{ii} ; + if ~isstruct(X), + error('catstruct:InvalidArgument',['Argument #' num2str(ii) ' is not a structure.']) ; + end + + if ~isempty(X), + % empty structs are ignored + if ii > 1 && ~isempty(sz0) + if ~isequal(size(X), sz0) + error('catstruct:UnequalSizes','All structures should have the same size.') ; + end + else + sz0 = size(X) ; + end + NonEmptyInputsN = NonEmptyInputsN + 1 ; + NonEmptyInputs(ii) = true ; + FN{ii} = fieldnames(X) ; + VAL{ii} = struct2cell(X) ; + end +end + +if NonEmptyInputsN == 0 + % all structures were empty + A = struct([]) ; +elseif NonEmptyInputsN == 1, + % there was only one non-empty structure + A = varargin{NonEmptyInputs} ; + if sorted, + A = orderfields(A) ; + end +else + % there is actually something to concatenate + FN = cat(1,FN{:}) ; + VAL = cat(1,VAL{:}) ; + FN = squeeze(FN) ; + VAL = squeeze(VAL) ; + MatlabVersion = version; + if isoctave || str2double(MatlabVersion(end-5:end-2))<2013 % Equivalent to, but faster than if verLessThan('matlab','8.1') + [UFN,ind] = unique(FN) ; + else + [UFN,ind] = unique(FN,'legacy') ; + end + + if numel(UFN) ~= numel(FN), + warning('catstruct:DuplicatesFound','Fieldnames are not unique between structures.') ; + sorted = 1 ; + end + + if sorted, + VAL = VAL(ind,:) ; + FN = FN(ind,:) ; + end + + A = cell2struct(VAL, FN); + A = reshape(A, sz0) ; % reshape into original format +end + + + diff --git a/matlab/lmmcp/dyn_lmmcp_func.m b/matlab/lmmcp/dyn_lmmcp_func.m index 936f98306d..f08da101ea 100644 --- a/matlab/lmmcp/dyn_lmmcp_func.m +++ b/matlab/lmmcp/dyn_lmmcp_func.m @@ -20,37 +20,37 @@ function [F,A] = dyn_lmmcp_func(x, model_dynamic, Y0, YT, exo_simul, params, ... % You should have received a copy of the GNU General Public License % along with Dynare. If not, see <http://www.gnu.org/licenses/>. - Y = [Y0; x; YT]; - - F = zeros(periods*ny,1); - if nargout == 2 - A = sparse([],[],[],periods*ny,periods*ny,periods*nnzA); - end +Y = [Y0; x; YT]; - i_rows = 1:ny; - i_cols = find(lead_lag_incidence'); - i_cols_A = i_cols; +F = zeros(periods*ny,1); +if nargout == 2 + A = sparse([],[],[],periods*ny,periods*ny,periods*nnzA); +end - for it = 2:(periods+1) - - [res,jacobian] = model_dynamic(Y(i_cols),exo_simul, params, ... - steady_state,it); - F(i_rows) = res(eq_index); - - if nargout == 2 - if it == 2 - A(i_rows,i_cols_A1) = jacobian(eq_index,i_cols_1); - elseif it == periods+1 - A(i_rows,i_cols_A(i_cols_T)) = jacobian(eq_index,i_cols_T); - else - A(i_rows,i_cols_A) = jacobian(eq_index,i_cols_j); - end - end - - i_rows = i_rows + ny; - i_cols = i_cols + ny; - if nargout == 2 && it > 2 - i_cols_A = i_cols_A + ny; +i_rows = 1:ny; +i_cols = find(lead_lag_incidence'); +i_cols_A = i_cols; + +for it = 2:(periods+1) + + [res,jacobian] = model_dynamic(Y(i_cols),exo_simul, params, ... + steady_state,it); + F(i_rows) = res(eq_index); + + if nargout == 2 + if it == 2 + A(i_rows,i_cols_A1) = jacobian(eq_index,i_cols_1); + elseif it == periods+1 + A(i_rows,i_cols_A(i_cols_T)) = jacobian(eq_index,i_cols_T); + else + A(i_rows,i_cols_A) = jacobian(eq_index,i_cols_j); end end + + i_rows = i_rows + ny; + i_cols = i_cols + ny; + if nargout == 2 && it > 2 + i_cols_A = i_cols_A + ny; + end +end diff --git a/matlab/lmmcp/get_complementarity_conditions.m b/matlab/lmmcp/get_complementarity_conditions.m index d1ea1771fd..291627f592 100644 --- a/matlab/lmmcp/get_complementarity_conditions.m +++ b/matlab/lmmcp/get_complementarity_conditions.m @@ -55,14 +55,14 @@ for i=1:size(etags,1) str = etags{i,3}; kop = strfind(etags{i,3},'<'); if ~isempty(kop) - k = find(strcmp(strtrim(str(1:kop-1)),cellstr(M.endo_names))); %get variable index with restriction - if isempty(k) - error(sprintf(['Complementarity condition %s: variable %s is ' ... - 'not recognized'],etags{i,3},strtrim(str(1:kop-1)))) - end - ub(k) = str2num(str(kop+1:end)); - eq_index(etags{i,1}) = k; - eq_index(k) = etags{i,1}; + k = find(strcmp(strtrim(str(1:kop-1)),cellstr(M.endo_names))); %get variable index with restriction + if isempty(k) + error(sprintf(['Complementarity condition %s: variable %s is ' ... + 'not recognized'],etags{i,3},strtrim(str(1:kop-1)))) + end + ub(k) = str2num(str(kop+1:end)); + eq_index(etags{i,1}) = k; + eq_index(k) = etags{i,1}; else kop = strfind(etags{i,3},'>'); if ~isempty(kop) diff --git a/matlab/lmmcp/lmmcp.m b/matlab/lmmcp/lmmcp.m index 1ac1c5e0a4..76cb49a987 100644 --- a/matlab/lmmcp/lmmcp.m +++ b/matlab/lmmcp/lmmcp.m @@ -1,625 +1,625 @@ -function [x,FVAL,EXITFLAG,OUTPUT,JACOB] = lmmcp(FUN,x,lb,ub,options,varargin) -% LMMCP solves a mixed complementarity problem. -% -% LMMCP uses a semismooth least squares formulation. The method applies a -% Levenberg-Marquardt/Gauss-Newton algorithm to a least-squares formulation. -% -% X = LMMCP(FUN,X0) tries to solve the system of nonlinear equations F(X)=0 and -% starts at the vector X0. FUN accepts a vector X and return a vector F of equation -% values F evaluated at X and, as second output if required, a matrix J, the -% Jacobian evaluated at X. -% -% X = LMMCP(FUN,X0,LB,UB) solves the mixed complementarity problem of the form: -% LB =X => F(X)>0, -% LB<=X<=UB => F(X)=0, -% X =UB => F(X)<0. -% -% X = LMMCP(FUN,X0,LB,UB,OPTIONS) solves the MCP problem using the options -% defined in the structure OPTIONS. Main fields are -% Display : control the display of iterations, 'none' (default), -% 'iter-detailed' or 'final-detailed' -% Switch from phase I to phase II -% preprocess : activate preprocessor for phase I (default = 1) -% presteps : number of iterations in phase I (default = 20) -% Termination parameters -% MaxIter : Maximum number of iterations (default = 500) -% tmin : safeguard stepsize (default = 1E-12) -% TolFun : Termination tolerance on the function value, a positive -% scalar (default = sqrt(eps)) -% Stepsize parameters -% m : number of previous function values to use in the nonmonotone -% line search rule (default = 10) -% kwatch : maximum number of steps (default = 20 and should not be -% smaller than m) -% watchdog : activate the watchdog strategy (default = 1) -% Ther are other minor parameters. Please see the code for their default values -% and interpretation. -% -% [X,FVAL] = LMMCP(FUN,X0,...) returns the value of the equations FUN at X. -% -% [X,FVAL,EXITFLAG] = LMMCP(FUN,X0,...) returns EXITFLAG that describes the exit -% conditions. Possible values are -% 1 : LMMCP converged to a root -% 0 : Too many iterations -% -1 : -% -% [X,FVAL,EXITFLAG,OUTPUT] = LMMCP(FUN,X0,...) returns the structure OUTPUT that -% contains the number of iterations (OUTPUT.iterations), the value of the merit -% function (OUTPUT.Psix), and the norm of the derivative of the merit function -% (OUTPUT.normDPsix). -% -% [X,FVAL,EXITFLAG,OUTPUT,JACOB] = LMMCP(FUN,X0,...) returns JACOB the Jacobian -% of FUN evaluated at X. -% -% More details of the main program may be found in the following paper: -% -% Christian Kanzow and Stefania Petra: On a semismooth least squares formulation of -% complementarity problems with gap reduction. Optimization Methods and Software -% 19, 2004, pp. 507-525. -% -% In addition, the current implementation uses a preprocessor which is the -% projected Levenberg-Marquardt step from the following preprint: -% -% Christian Kanzow and Stefania Petra: Projected filter trust region methods for a -% semismooth least squares formulation of mixed complementarity -% problems. Optimization Methods and Software -% 22, 2007, pp. 713-735. -% -% A user's guide is also available: -% -% Christian Kanzow and Stefania Petra (2005). -% LMMCP --- A Levenberg-Marquardt-type MATLAB Solver for Mixed Complementarity Problems. -% University of Wuerzburg. -% http://www.mathematik.uni-wuerzburg.de/~kanzow/software/UserGuide.pdf -% -% This is a modification by Christophe Gouel of the original files, which can be -% downloaded from: -% http://www.mathematik.uni-wuerzburg.de/~kanzow/software/LMMCP.zip -% -% Written by Christian Kanzow and Stefania Petra -% Institute of Applied Mathematics and Statistics -% University of Wuerzburg -% Am Hubland -% 97074 Wuerzburg -% GERMANY -% -% e-mail: kanzow@mathematik.uni-wuerzburg.de -% petra@mathematik.uni-wuerzburg.de -% -% Christian Kanzow sent a private message to Dynare Team on July 8, 2014, -% confirming the free software status of lmmcp and granting unlimited -% permission to use, copy, modifiy or redistribute the file. - -% Copyright (C) 2005 Christian Kanzow and Stefania Petra -% Copyright (C) 2013 Christophe Gouel -% Copyright (C) 2014 Dynare Team -% -% Unlimited permission is granted to everyone to use, copy, modify or -% distribute this software. - -%% Initialization -defaultopt = struct(... - 'beta', 0.55,... - 'Big', 1e10,... - 'delta', 5,... - 'deltamin', 1,... - 'Display', 'none',... - 'epsilon1', 1e-6,... - 'eta', 0.95,... - 'kwatch', 20,... - 'lambda1', 0.1,... - 'm', 10,... - 'MaxIter', 500,... - 'null', 1e-10,... - 'preprocess', 1,... - 'presteps', 20,... - 'sigma', 1e-4,... - 'sigma1', 0.5,... - 'sigma2', 2,... - 'tmin', 1e-12,... - 'TolFun', sqrt(eps),... - 'watchdog', 1); - -if nargin < 4 - ub = inf(size(x)); - if nargin < 3 - lb = -inf(size(x)); - end -end - -if nargin < 5 || isempty(options) || ~isstruct(options) - options = defaultopt; -else - warning('off','catstruct:DuplicatesFound') - options = catstruct(defaultopt,options); -end - -warning('off','MATLAB:rankDeficientMatrix') - -switch options.Display - case {'off','none'} - verbosity = 0; - case {'iter','iter-detailed'} - verbosity = 2; - case {'final','final-detailed'} - verbosity = 1; - otherwise - verbosity = 0; -end - -% parameter settings -eps1 = options.epsilon1; -eps2 = 0.5*options.TolFun^2; -null = options.null; -Big = options.Big; - -% maximal number of iterations -kmax = options.MaxIter; - -% choice of lambda -lambda1 = options.lambda1; -lambda2 = 1-lambda1; - -% steplength parameters -beta = options.beta; -sigma = options.sigma; -tmin = options.tmin; - -% parameters watchdog and nonmonotone line search; redefined later -m = options.m; -kwatch = options.kwatch; -watchdog = options.watchdog; % 1=watchdog strategy active, otherwise not - -% parameters for preprocessor -preprocess = options.preprocess; % 1=preprocessor used, otherwise not -presteps = options.presteps; % maximum number of preprocessing steps - -% trust-region parameters for preprocessor -delta = options.delta; -deltamin = options.deltamin; -sigma1 = options.sigma1; -sigma2 = options.sigma2; -eta = options.eta; - -% initializations -k = 0; -k_main = 0; - -% compute a feasible starting point by projection -x = max(lb,min(x,ub)); - -n = length(x); -OUTPUT.Dim = n; - -% definition of index sets I_l, I_u and I_lu -Indexset = zeros(n,1); -I_l = lb>-Big & ub>Big; -I_u = lb<-Big & ub<Big; -I_lu = lb>-Big & ub<Big; -Indexset(I_l) = 1; -Indexset(I_u) = 2; -Indexset(I_lu) = 3; - -% function evaluations -[Fx,DFx] = feval(FUN,x,varargin{:}); - -% choice of NCP-function and corresponding evaluations -Phix = Phi(x,Fx,lb,ub,lambda1,lambda2,n,Indexset); -normPhix = norm(Phix); -Psix = 0.5*(Phix'*Phix); -DPhix = DPhi(x,Fx,DFx,lb,ub,lambda1,lambda2,n,Indexset); -DPsix = DPhix'*Phix; -normDPsix = norm(DPsix); - -% save initial values -x0 = x; -Phix0 = Phix; -Psix0 = Psix; -DPhix0 = DPhix; -DPsix0 = DPsix; -normDPsix0 = normDPsix; - -% watchdog strategy -aux = zeros(m,1); -aux(1) = Psix; -MaxPsi = Psix; - -if watchdog==1 - kbest = k; - xbest = x; - Phibest = Phix; - Psibest = Psix; - DPhibest = DPhix; - DPsibest = DPsix; - normDPsibest = normDPsix; -end - -% initial output -if verbosity > 1 - fprintf(' k Psi(x) || DPsi(x) || stepsize\n'); - disp('====================================================================') - disp('********************* Output at starting point *********************') - fprintf('%4.0f %24.5e %24.5e\n',k,Psix,normDPsix); -end - -%% Preprocessor using local method - -if preprocess==1 - - if verbosity > 1 - disp('************************** Preprocessor ****************************') - end - - normpLM=1; - while (k < presteps) && (Psix > eps2) && (normpLM>null) - k = k+1; - - % choice of Levenberg-Marquardt parameter, note that we do not use - % the condition estimator for large-scale problems, although this - % may cause numerical problems in some examples - - i = false; - mu = 0; - if n<100 - i = true; - mu = 1e-16; - if condest(DPhix'*DPhix)>1e25 - mu = 1e-6/(k+1); - end - end - if i - pLM = [DPhix; sqrt(mu)*speye(n)]\[-Phix; zeros(n,1)]; - else - pLM = -DPhix\Phix; - end - normpLM = norm(pLM); - - % compute the projected Levenberg-Marquard step onto box Xk - lbnew = max(min(lb-x,0),-delta); - ubnew = min(max(ub-x,0),delta); - d = max(lbnew,min(pLM,ubnew)); - xnew = x+d; - - % function evaluations etc. - [Fxnew,DFxnew] = feval(FUN,xnew,varargin{:}); - Phixnew = Phi(xnew,Fxnew,lb,ub,lambda1,lambda2,n,Indexset); - Psixnew = 0.5*(Phixnew'*Phixnew); - normPhixnew = norm(Phixnew); - - % update of delta - if normPhixnew<=eta*normPhix - delta = max(deltamin,sigma2*delta); - elseif normPhixnew>5*eta*normPhix - delta = max(deltamin,sigma1*delta); - end - - % update - x = xnew; - Fx = Fxnew; - DFx = DFxnew; - Phix = Phixnew; - Psix = Psixnew; - normPhix = normPhixnew; - DPhix = DPhi(x,Fx,DFx,lb,ub,lambda1,lambda2,n,Indexset); - DPsix = DPhix'*Phix; - normDPsix = norm(DPsix,inf); - - % output at each iteration - t=1; - if verbosity > 1 - fprintf('%4.0f %24.5e %24.5e %11.7g\n',k,Psix,normDPsix,t); - end - end -end - -% terminate program or redefine current iterate as original initial point -if preprocess==1 && Psix<eps2 - if verbosity > 0 - fprintf('Psix = %1.4e\nnormDPsix = %1.4e\n',Psix,normDPsix); - disp('Approximate solution found.') - end - EXITFLAG = 1; - FVAL = Fx; - OUTPUT.iterations = k; - OUTPUT.Psix = Psix; - OUTPUT.normDPsix = normDPsix; - JACOB = DFx; - return -elseif preprocess==1 && Psix>=eps2 - x=x0; - Phix=Phix0; - Psix=Psix0; - DPhix=DPhix0; - DPsix=DPsix0; - if verbosity > 1 - disp('******************** Restart with initial point ********************') - fprintf('%4.0f %24.5e %24.5e\n',k_main,Psix0,normDPsix0); - end -end - -%% Main algorithm - -if verbosity > 1 - disp('************************** Main program ****************************') -end - -while (k < kmax) && (Psix > eps2) - - % choice of Levenberg-Marquardt parameter, note that we do not use - % the condition estimator for large-scale problems, although this - % may cause numerical problems in some examples - - i = false; - if n<100 - i = true; - mu = 1e-16; - if condest(DPhix'*DPhix)>1e25 - mu = 1e-1/(k+1); - end - end - - % compute a Levenberg-Marquard direction - - if i - d = [DPhix; sqrt(mu)*speye(n)]\[-Phix; zeros(n,1)]; - else - d = -DPhix\Phix; - end - - % computation of steplength t using the nonmonotone Armijo-rule - % starting with the 6-th iteration - - % computation of steplength t using the monotone Armijo-rule if - % d is a 'good' descent direction or k<=5 - - t = 1; - xnew = x+d; - Fxnew = feval(FUN,xnew,varargin{:}); - Phixnew = Phi(xnew,Fxnew,lb,ub,lambda1,lambda2,n,Indexset); - Psixnew = 0.5*(Phixnew'*Phixnew); - const = sigma*DPsix'*d; - - while (Psixnew > MaxPsi + const*t) && (t > tmin) - t = t*beta; - xnew = x+t*d; - Fxnew = feval(FUN,xnew,varargin{:}); - Phixnew = Phi(xnew,Fxnew,lb,ub,lambda1,lambda2,n,Indexset); - Psixnew = 0.5*(Phixnew'*Phixnew); - end - - % updatings - x = xnew; - Fx = Fxnew; - Phix = Phixnew; - Psix = Psixnew; - [junk,DFx] = feval(FUN,x,varargin{:}); - DPhix = DPhi(x,Fx,DFx,lb,ub,lambda1,lambda2,n,Indexset); - DPsix = DPhix'*Phix; - normDPsix = norm(DPsix); - k = k+1; - k_main = k_main+1; - - if k_main<=5 - aux(mod(k_main,m)+1) = Psix; - MaxPsi = Psix; - else - aux(mod(k_main,m)+1) = Psix; - MaxPsi = max(aux); - end - - % updatings for the watchdog strategy - if watchdog ==1 - if Psix<Psibest - kbest = k; - xbest = x; - Phibest = Phix; - Psibest = Psix; - DPhibest = DPhix; - DPsibest = DPsix; - normDPsibest = normDPsix; - elseif k-kbest>kwatch - x=xbest; - Phix=Phibest; - Psix=Psibest; - DPhix=DPhibest; - DPsix=DPsibest; - normDPsix=normDPsibest; - MaxPsi=Psix; - end - end - - if verbosity > 1 - % output at each iteration - fprintf('%4.0f %24.5e %24.5e %11.7g\n',k,Psix,normDPsix,t); - end -end - -%% Final output -if Psix<=eps2 - EXITFLAG = 1; - if verbosity > 0, disp('Approximate solution found.'); end -elseif k>=kmax - EXITFLAG = 0; - if verbosity > 0, disp('Maximum iteration number reached.'); end -elseif normDPsix<=eps1 - EXITFLAG = -1; % Provisoire - if verbosity > 0, disp('Approximate stationary point found.'); end -else - EXITFLAG = -1; % Provisoire - if verbosity > 0, disp('No solution found.'); end -end - -FVAL = Fx; -OUTPUT.iterations = k; -OUTPUT.Psix = Psix; -OUTPUT.normDPsix = normDPsix; -JACOB = DFx; - -%% Subfunctions - -function y = Phi(x,Fx,lb,ub,lambda1,lambda2,n,Indexset) -%% PHI - -y = zeros(2*n,1); -phi_u = sqrt((ub-x).^2+Fx.^2)-ub+x+Fx; -LZ = false(n,1); % logical zero - -I0 = Indexset==0; -y(I0) = -lambda1*Fx(I0); -y([LZ; I0]) = -lambda2*Fx(I0); - -I1 = Indexset==1; -y(I1) = lambda1*(-x(I1)+lb(I1)-Fx(I1)+sqrt((x(I1)-lb(I1)).^2+Fx(I1).^2)); -y([LZ; I1]) = lambda2*max(0,x(I1)-lb(I1)).*max(0,Fx(I1)); - -I2 = Indexset==2; -y(I2) = -lambda1*phi_u(I2); -y([LZ; I2]) = lambda2*max(0,ub(I2)-x(I2)).*max(0,-Fx(I2)); - -I3 = Indexset==3; -y(I3) = lambda1*(sqrt((x(I3)-lb(I3)).^2+phi_u(I3).^2)-x(I3)+lb(I3)-phi_u(I3)); -y([LZ; I3]) = lambda2*(max(0,x(I3)-lb(I3)).*max(0,Fx(I3))+max(0,ub(I3)-x(I3)).*max(0,-Fx(I3))); - - -function H = DPhi(x,Fx,DFx,lb,ub,lambda1,lambda2,n,Indexset) -%% DPHI evaluates an element of the C-subdifferential of operator Phi - -null = 1e-8; -beta_l = zeros(n,1); -beta_u = zeros(n,1); -alpha_l = zeros(n,1); -alpha_u = zeros(n,1); - - -z = zeros(n,1); -H2 = sparse(n,n); - -I = abs(x-lb)<=null & abs(Fx)<=null; -beta_l(I) = 1; -z(I) = 1; - -I = abs(ub-x)<=null & abs(Fx)<=null; -beta_u(I) = 1; -z(I) = 1; - -I = x-lb>=-null & Fx>=-null; -alpha_l(I) = 1; - -I = ub-x>=-null & Fx<=null; -alpha_u(I) = 1; - -Da = zeros(n,1); -Db = zeros(n,1); - -I = 1:n; - -I0 = Indexset==0; -Da(I0) = 0; -Db(I0) = -1; -H2(I0,:) = -DFx(I0,:); - -I1 = Indexset==1; -denom1 = zeros(n,1); -denom2 = zeros(n,1); -if any(I1) - denom1(I1) = max(null,sqrt((x(I1)-lb(I1)).^2+Fx(I1).^2)); - denom2(I1) = max(null,sqrt(z(I1).^2+(DFx(I1,:)*z).^2)); -end - -I1b = Indexset==1 & beta_l==0; -Da(I1b) = (x(I1b)-lb(I1b))./denom1(I1b)-1; -Db(I1b) = Fx(I1b)./denom1(I1b)-1; -I1b = Indexset==1 & beta_l~=0; -if any(I1b) - Da(I1b) = z(I1b)./denom2(I1b)-1; - Db(I1b) = (DFx(I1b,:)*z)./denom2(I1b)-1; -end - -I1a = I(Indexset==1 & alpha_l==1); -if any(I1a) - H2(I1a,:) = spdiags(x(I1a)-lb(I1a), 0, length(I1a), length(I1a))*DFx(I1a,:) +... - sparse(1:length(I1a),I1a,Fx(I1a),length(I1a),n,length(I1a)); -end - -I2 = Indexset==2; -denom1 = zeros(n,1); -denom2 = zeros(n,1); -if any(I2) - denom1(I2) = max(null,sqrt((ub(I2)-x(I2)).^2+Fx(I2).^2)); - denom2(I2) = max(null,sqrt(z(I2).^2+(DFx(I2,:)*z).^2)); -end - -I2b = Indexset==2 & beta_u==0; -Da(I2b) = (ub(I2b)-x(I2b))./denom1(I2b)-1; -Db(I2b) = -Fx(I2b)./denom1(I2b)-1; -I2b = Indexset==2 & beta_u~=0; -if any(I2b) - Da(I2b) = -z(I2b)./denom2(I2b)-1; - Db(I2b) = -(DFx(I2b,:)*z)./denom2(I2b)-1; -end - -I2a = I(Indexset==2 & alpha_u==1); -if any(I2a) - H2(I2a,:) = bsxfun(@times,x(I2a)-ub(I2a),DFx(I2a,:))+... - sparse(1:length(I2a),I2a,Fx(I2a),length(I2a),n,length(I2a)); -end - -I3 = Indexset==3; -phi = zeros(n,1); -ai = zeros(n,1); -bi = zeros(n,1); -ci = zeros(n,1); -di = zeros(n,1); -denom1 = zeros(n,1); -denom2 = zeros(n,1); -denom3 = zeros(n,1); -denom4 = zeros(n,1); -if any(I3) - phi(I3) = -ub(I3)+x(I3)+Fx(I3)+sqrt((ub(I3)-x(I3)).^2+Fx(I3).^2); - denom1(I3) = max(null,sqrt((x(I3)-lb(I3)).^2+phi(I3).^2)); - denom2(I3) = max(null,sqrt(z(I3).^2+(DFx(I3,:)*z).^2)); - denom3(I3) = max(null,sqrt((ub(I3)-x(I3)).^2+Fx(I3).^2)); - denom4(I3) = max(null,sqrt(z(I3).^2)); -end - -I3bu = Indexset==3 & beta_u==0; -ci(I3bu) = (x(I3bu)-ub(I3bu))./denom3(I3bu)+1; -di(I3bu) = Fx(I3bu)./denom3(I3bu)+1; -I3bu = Indexset==3 & beta_u~=0; -if any(I3bu) - ci(I3bu) = 1+z(I3bu)./denom2(I3bu); - di(I3bu) = 1+(DFx(I3bu,:)*z)./denom2(I3bu); -end - -I3bl = Indexset==3 & beta_l==0; -ai(I3bl) = (x(I3bl)-lb(I3bl))./denom1(I3bl)-1; -bi(I3bl) = phi(I3bl)./denom1(I3bl)-1; -I3bl = Indexset==3 & beta_l~=0; -if any(I3bl) - ai(I3bl) = z(I3bl)./denom4(I3bl)-1; - bi(I3bl) = (ci(I3bl).*z(I3bl)+(di(I3bl,ones(1,n)).*DFx(I3bl,:))*z)./denom4(I3bl)-1; -end - -Da(I3) = ai(I3)+bi(I3).*ci(I3); -Db(I3) = bi(I3).*di(I3); - -I3a = I(Indexset==3 & alpha_l==1 & alpha_u==1); -if any(I3a) - H2(I3a,:) = bsxfun(@times,-lb(I3a)-ub(I3a)+2*x(I3a),DFx(I3a,:))+... - 2*sparse(1:length(I3a),I3a,Fx(I3a),length(I3a),n,length(I3a)); -end -I3a = I(Indexset==3 & alpha_l==1 & alpha_u~=1); -if any(I3a) - H2(I3a,:) = bsxfun(@times,x(I3a)-lb(I3a),DFx(I3a,:))+... - sparse(1:length(I3a),I3a,Fx(I3a),length(I3a),n,length(I3a)); -end -I3a = I(Indexset==3 & alpha_l~=1 & alpha_u==1); -if any(I3a) - H2(I3a,:) = bsxfun(@times,x(I3a)-ub(I3a),DFx(I3a,:))+... - sparse(1:length(I3a),I3a,Fx(I3a),length(I3a),n,length(I3a)); -end - -H1 = spdiags(Db,0,length(Db),length(Db))*DFx; -H1 = H1 + spdiags(Da, 0, length(Da), length(Da)); - -H = [lambda1*H1; lambda2*H2]; +function [x,FVAL,EXITFLAG,OUTPUT,JACOB] = lmmcp(FUN,x,lb,ub,options,varargin) +% LMMCP solves a mixed complementarity problem. +% +% LMMCP uses a semismooth least squares formulation. The method applies a +% Levenberg-Marquardt/Gauss-Newton algorithm to a least-squares formulation. +% +% X = LMMCP(FUN,X0) tries to solve the system of nonlinear equations F(X)=0 and +% starts at the vector X0. FUN accepts a vector X and return a vector F of equation +% values F evaluated at X and, as second output if required, a matrix J, the +% Jacobian evaluated at X. +% +% X = LMMCP(FUN,X0,LB,UB) solves the mixed complementarity problem of the form: +% LB =X => F(X)>0, +% LB<=X<=UB => F(X)=0, +% X =UB => F(X)<0. +% +% X = LMMCP(FUN,X0,LB,UB,OPTIONS) solves the MCP problem using the options +% defined in the structure OPTIONS. Main fields are +% Display : control the display of iterations, 'none' (default), +% 'iter-detailed' or 'final-detailed' +% Switch from phase I to phase II +% preprocess : activate preprocessor for phase I (default = 1) +% presteps : number of iterations in phase I (default = 20) +% Termination parameters +% MaxIter : Maximum number of iterations (default = 500) +% tmin : safeguard stepsize (default = 1E-12) +% TolFun : Termination tolerance on the function value, a positive +% scalar (default = sqrt(eps)) +% Stepsize parameters +% m : number of previous function values to use in the nonmonotone +% line search rule (default = 10) +% kwatch : maximum number of steps (default = 20 and should not be +% smaller than m) +% watchdog : activate the watchdog strategy (default = 1) +% Ther are other minor parameters. Please see the code for their default values +% and interpretation. +% +% [X,FVAL] = LMMCP(FUN,X0,...) returns the value of the equations FUN at X. +% +% [X,FVAL,EXITFLAG] = LMMCP(FUN,X0,...) returns EXITFLAG that describes the exit +% conditions. Possible values are +% 1 : LMMCP converged to a root +% 0 : Too many iterations +% -1 : +% +% [X,FVAL,EXITFLAG,OUTPUT] = LMMCP(FUN,X0,...) returns the structure OUTPUT that +% contains the number of iterations (OUTPUT.iterations), the value of the merit +% function (OUTPUT.Psix), and the norm of the derivative of the merit function +% (OUTPUT.normDPsix). +% +% [X,FVAL,EXITFLAG,OUTPUT,JACOB] = LMMCP(FUN,X0,...) returns JACOB the Jacobian +% of FUN evaluated at X. +% +% More details of the main program may be found in the following paper: +% +% Christian Kanzow and Stefania Petra: On a semismooth least squares formulation of +% complementarity problems with gap reduction. Optimization Methods and Software +% 19, 2004, pp. 507-525. +% +% In addition, the current implementation uses a preprocessor which is the +% projected Levenberg-Marquardt step from the following preprint: +% +% Christian Kanzow and Stefania Petra: Projected filter trust region methods for a +% semismooth least squares formulation of mixed complementarity +% problems. Optimization Methods and Software +% 22, 2007, pp. 713-735. +% +% A user's guide is also available: +% +% Christian Kanzow and Stefania Petra (2005). +% LMMCP --- A Levenberg-Marquardt-type MATLAB Solver for Mixed Complementarity Problems. +% University of Wuerzburg. +% http://www.mathematik.uni-wuerzburg.de/~kanzow/software/UserGuide.pdf +% +% This is a modification by Christophe Gouel of the original files, which can be +% downloaded from: +% http://www.mathematik.uni-wuerzburg.de/~kanzow/software/LMMCP.zip +% +% Written by Christian Kanzow and Stefania Petra +% Institute of Applied Mathematics and Statistics +% University of Wuerzburg +% Am Hubland +% 97074 Wuerzburg +% GERMANY +% +% e-mail: kanzow@mathematik.uni-wuerzburg.de +% petra@mathematik.uni-wuerzburg.de +% +% Christian Kanzow sent a private message to Dynare Team on July 8, 2014, +% confirming the free software status of lmmcp and granting unlimited +% permission to use, copy, modifiy or redistribute the file. + +% Copyright (C) 2005 Christian Kanzow and Stefania Petra +% Copyright (C) 2013 Christophe Gouel +% Copyright (C) 2014 Dynare Team +% +% Unlimited permission is granted to everyone to use, copy, modify or +% distribute this software. + +%% Initialization +defaultopt = struct(... + 'beta', 0.55,... + 'Big', 1e10,... + 'delta', 5,... + 'deltamin', 1,... + 'Display', 'none',... + 'epsilon1', 1e-6,... + 'eta', 0.95,... + 'kwatch', 20,... + 'lambda1', 0.1,... + 'm', 10,... + 'MaxIter', 500,... + 'null', 1e-10,... + 'preprocess', 1,... + 'presteps', 20,... + 'sigma', 1e-4,... + 'sigma1', 0.5,... + 'sigma2', 2,... + 'tmin', 1e-12,... + 'TolFun', sqrt(eps),... + 'watchdog', 1); + +if nargin < 4 + ub = inf(size(x)); + if nargin < 3 + lb = -inf(size(x)); + end +end + +if nargin < 5 || isempty(options) || ~isstruct(options) + options = defaultopt; +else + warning('off','catstruct:DuplicatesFound') + options = catstruct(defaultopt,options); +end + +warning('off','MATLAB:rankDeficientMatrix') + +switch options.Display + case {'off','none'} + verbosity = 0; + case {'iter','iter-detailed'} + verbosity = 2; + case {'final','final-detailed'} + verbosity = 1; + otherwise + verbosity = 0; +end + +% parameter settings +eps1 = options.epsilon1; +eps2 = 0.5*options.TolFun^2; +null = options.null; +Big = options.Big; + +% maximal number of iterations +kmax = options.MaxIter; + +% choice of lambda +lambda1 = options.lambda1; +lambda2 = 1-lambda1; + +% steplength parameters +beta = options.beta; +sigma = options.sigma; +tmin = options.tmin; + +% parameters watchdog and nonmonotone line search; redefined later +m = options.m; +kwatch = options.kwatch; +watchdog = options.watchdog; % 1=watchdog strategy active, otherwise not + +% parameters for preprocessor +preprocess = options.preprocess; % 1=preprocessor used, otherwise not +presteps = options.presteps; % maximum number of preprocessing steps + +% trust-region parameters for preprocessor +delta = options.delta; +deltamin = options.deltamin; +sigma1 = options.sigma1; +sigma2 = options.sigma2; +eta = options.eta; + +% initializations +k = 0; +k_main = 0; + +% compute a feasible starting point by projection +x = max(lb,min(x,ub)); + +n = length(x); +OUTPUT.Dim = n; + +% definition of index sets I_l, I_u and I_lu +Indexset = zeros(n,1); +I_l = lb>-Big & ub>Big; +I_u = lb<-Big & ub<Big; +I_lu = lb>-Big & ub<Big; +Indexset(I_l) = 1; +Indexset(I_u) = 2; +Indexset(I_lu) = 3; + +% function evaluations +[Fx,DFx] = feval(FUN,x,varargin{:}); + +% choice of NCP-function and corresponding evaluations +Phix = Phi(x,Fx,lb,ub,lambda1,lambda2,n,Indexset); +normPhix = norm(Phix); +Psix = 0.5*(Phix'*Phix); +DPhix = DPhi(x,Fx,DFx,lb,ub,lambda1,lambda2,n,Indexset); +DPsix = DPhix'*Phix; +normDPsix = norm(DPsix); + +% save initial values +x0 = x; +Phix0 = Phix; +Psix0 = Psix; +DPhix0 = DPhix; +DPsix0 = DPsix; +normDPsix0 = normDPsix; + +% watchdog strategy +aux = zeros(m,1); +aux(1) = Psix; +MaxPsi = Psix; + +if watchdog==1 + kbest = k; + xbest = x; + Phibest = Phix; + Psibest = Psix; + DPhibest = DPhix; + DPsibest = DPsix; + normDPsibest = normDPsix; +end + +% initial output +if verbosity > 1 + fprintf(' k Psi(x) || DPsi(x) || stepsize\n'); + disp('====================================================================') + disp('********************* Output at starting point *********************') + fprintf('%4.0f %24.5e %24.5e\n',k,Psix,normDPsix); +end + +%% Preprocessor using local method + +if preprocess==1 + + if verbosity > 1 + disp('************************** Preprocessor ****************************') + end + + normpLM=1; + while (k < presteps) && (Psix > eps2) && (normpLM>null) + k = k+1; + + % choice of Levenberg-Marquardt parameter, note that we do not use + % the condition estimator for large-scale problems, although this + % may cause numerical problems in some examples + + i = false; + mu = 0; + if n<100 + i = true; + mu = 1e-16; + if condest(DPhix'*DPhix)>1e25 + mu = 1e-6/(k+1); + end + end + if i + pLM = [DPhix; sqrt(mu)*speye(n)]\[-Phix; zeros(n,1)]; + else + pLM = -DPhix\Phix; + end + normpLM = norm(pLM); + + % compute the projected Levenberg-Marquard step onto box Xk + lbnew = max(min(lb-x,0),-delta); + ubnew = min(max(ub-x,0),delta); + d = max(lbnew,min(pLM,ubnew)); + xnew = x+d; + + % function evaluations etc. + [Fxnew,DFxnew] = feval(FUN,xnew,varargin{:}); + Phixnew = Phi(xnew,Fxnew,lb,ub,lambda1,lambda2,n,Indexset); + Psixnew = 0.5*(Phixnew'*Phixnew); + normPhixnew = norm(Phixnew); + + % update of delta + if normPhixnew<=eta*normPhix + delta = max(deltamin,sigma2*delta); + elseif normPhixnew>5*eta*normPhix + delta = max(deltamin,sigma1*delta); + end + + % update + x = xnew; + Fx = Fxnew; + DFx = DFxnew; + Phix = Phixnew; + Psix = Psixnew; + normPhix = normPhixnew; + DPhix = DPhi(x,Fx,DFx,lb,ub,lambda1,lambda2,n,Indexset); + DPsix = DPhix'*Phix; + normDPsix = norm(DPsix,inf); + + % output at each iteration + t=1; + if verbosity > 1 + fprintf('%4.0f %24.5e %24.5e %11.7g\n',k,Psix,normDPsix,t); + end + end +end + +% terminate program or redefine current iterate as original initial point +if preprocess==1 && Psix<eps2 + if verbosity > 0 + fprintf('Psix = %1.4e\nnormDPsix = %1.4e\n',Psix,normDPsix); + disp('Approximate solution found.') + end + EXITFLAG = 1; + FVAL = Fx; + OUTPUT.iterations = k; + OUTPUT.Psix = Psix; + OUTPUT.normDPsix = normDPsix; + JACOB = DFx; + return +elseif preprocess==1 && Psix>=eps2 + x=x0; + Phix=Phix0; + Psix=Psix0; + DPhix=DPhix0; + DPsix=DPsix0; + if verbosity > 1 + disp('******************** Restart with initial point ********************') + fprintf('%4.0f %24.5e %24.5e\n',k_main,Psix0,normDPsix0); + end +end + +%% Main algorithm + +if verbosity > 1 + disp('************************** Main program ****************************') +end + +while (k < kmax) && (Psix > eps2) + + % choice of Levenberg-Marquardt parameter, note that we do not use + % the condition estimator for large-scale problems, although this + % may cause numerical problems in some examples + + i = false; + if n<100 + i = true; + mu = 1e-16; + if condest(DPhix'*DPhix)>1e25 + mu = 1e-1/(k+1); + end + end + + % compute a Levenberg-Marquard direction + + if i + d = [DPhix; sqrt(mu)*speye(n)]\[-Phix; zeros(n,1)]; + else + d = -DPhix\Phix; + end + + % computation of steplength t using the nonmonotone Armijo-rule + % starting with the 6-th iteration + + % computation of steplength t using the monotone Armijo-rule if + % d is a 'good' descent direction or k<=5 + + t = 1; + xnew = x+d; + Fxnew = feval(FUN,xnew,varargin{:}); + Phixnew = Phi(xnew,Fxnew,lb,ub,lambda1,lambda2,n,Indexset); + Psixnew = 0.5*(Phixnew'*Phixnew); + const = sigma*DPsix'*d; + + while (Psixnew > MaxPsi + const*t) && (t > tmin) + t = t*beta; + xnew = x+t*d; + Fxnew = feval(FUN,xnew,varargin{:}); + Phixnew = Phi(xnew,Fxnew,lb,ub,lambda1,lambda2,n,Indexset); + Psixnew = 0.5*(Phixnew'*Phixnew); + end + + % updatings + x = xnew; + Fx = Fxnew; + Phix = Phixnew; + Psix = Psixnew; + [junk,DFx] = feval(FUN,x,varargin{:}); + DPhix = DPhi(x,Fx,DFx,lb,ub,lambda1,lambda2,n,Indexset); + DPsix = DPhix'*Phix; + normDPsix = norm(DPsix); + k = k+1; + k_main = k_main+1; + + if k_main<=5 + aux(mod(k_main,m)+1) = Psix; + MaxPsi = Psix; + else + aux(mod(k_main,m)+1) = Psix; + MaxPsi = max(aux); + end + + % updatings for the watchdog strategy + if watchdog ==1 + if Psix<Psibest + kbest = k; + xbest = x; + Phibest = Phix; + Psibest = Psix; + DPhibest = DPhix; + DPsibest = DPsix; + normDPsibest = normDPsix; + elseif k-kbest>kwatch + x=xbest; + Phix=Phibest; + Psix=Psibest; + DPhix=DPhibest; + DPsix=DPsibest; + normDPsix=normDPsibest; + MaxPsi=Psix; + end + end + + if verbosity > 1 + % output at each iteration + fprintf('%4.0f %24.5e %24.5e %11.7g\n',k,Psix,normDPsix,t); + end +end + +%% Final output +if Psix<=eps2 + EXITFLAG = 1; + if verbosity > 0, disp('Approximate solution found.'); end +elseif k>=kmax + EXITFLAG = 0; + if verbosity > 0, disp('Maximum iteration number reached.'); end +elseif normDPsix<=eps1 + EXITFLAG = -1; % Provisoire + if verbosity > 0, disp('Approximate stationary point found.'); end +else + EXITFLAG = -1; % Provisoire + if verbosity > 0, disp('No solution found.'); end +end + +FVAL = Fx; +OUTPUT.iterations = k; +OUTPUT.Psix = Psix; +OUTPUT.normDPsix = normDPsix; +JACOB = DFx; + +%% Subfunctions + +function y = Phi(x,Fx,lb,ub,lambda1,lambda2,n,Indexset) +%% PHI + +y = zeros(2*n,1); +phi_u = sqrt((ub-x).^2+Fx.^2)-ub+x+Fx; +LZ = false(n,1); % logical zero + +I0 = Indexset==0; +y(I0) = -lambda1*Fx(I0); +y([LZ; I0]) = -lambda2*Fx(I0); + +I1 = Indexset==1; +y(I1) = lambda1*(-x(I1)+lb(I1)-Fx(I1)+sqrt((x(I1)-lb(I1)).^2+Fx(I1).^2)); +y([LZ; I1]) = lambda2*max(0,x(I1)-lb(I1)).*max(0,Fx(I1)); + +I2 = Indexset==2; +y(I2) = -lambda1*phi_u(I2); +y([LZ; I2]) = lambda2*max(0,ub(I2)-x(I2)).*max(0,-Fx(I2)); + +I3 = Indexset==3; +y(I3) = lambda1*(sqrt((x(I3)-lb(I3)).^2+phi_u(I3).^2)-x(I3)+lb(I3)-phi_u(I3)); +y([LZ; I3]) = lambda2*(max(0,x(I3)-lb(I3)).*max(0,Fx(I3))+max(0,ub(I3)-x(I3)).*max(0,-Fx(I3))); + + +function H = DPhi(x,Fx,DFx,lb,ub,lambda1,lambda2,n,Indexset) +%% DPHI evaluates an element of the C-subdifferential of operator Phi + +null = 1e-8; +beta_l = zeros(n,1); +beta_u = zeros(n,1); +alpha_l = zeros(n,1); +alpha_u = zeros(n,1); + + +z = zeros(n,1); +H2 = sparse(n,n); + +I = abs(x-lb)<=null & abs(Fx)<=null; +beta_l(I) = 1; +z(I) = 1; + +I = abs(ub-x)<=null & abs(Fx)<=null; +beta_u(I) = 1; +z(I) = 1; + +I = x-lb>=-null & Fx>=-null; +alpha_l(I) = 1; + +I = ub-x>=-null & Fx<=null; +alpha_u(I) = 1; + +Da = zeros(n,1); +Db = zeros(n,1); + +I = 1:n; + +I0 = Indexset==0; +Da(I0) = 0; +Db(I0) = -1; +H2(I0,:) = -DFx(I0,:); + +I1 = Indexset==1; +denom1 = zeros(n,1); +denom2 = zeros(n,1); +if any(I1) + denom1(I1) = max(null,sqrt((x(I1)-lb(I1)).^2+Fx(I1).^2)); + denom2(I1) = max(null,sqrt(z(I1).^2+(DFx(I1,:)*z).^2)); +end + +I1b = Indexset==1 & beta_l==0; +Da(I1b) = (x(I1b)-lb(I1b))./denom1(I1b)-1; +Db(I1b) = Fx(I1b)./denom1(I1b)-1; +I1b = Indexset==1 & beta_l~=0; +if any(I1b) + Da(I1b) = z(I1b)./denom2(I1b)-1; + Db(I1b) = (DFx(I1b,:)*z)./denom2(I1b)-1; +end + +I1a = I(Indexset==1 & alpha_l==1); +if any(I1a) + H2(I1a,:) = spdiags(x(I1a)-lb(I1a), 0, length(I1a), length(I1a))*DFx(I1a,:) +... + sparse(1:length(I1a),I1a,Fx(I1a),length(I1a),n,length(I1a)); +end + +I2 = Indexset==2; +denom1 = zeros(n,1); +denom2 = zeros(n,1); +if any(I2) + denom1(I2) = max(null,sqrt((ub(I2)-x(I2)).^2+Fx(I2).^2)); + denom2(I2) = max(null,sqrt(z(I2).^2+(DFx(I2,:)*z).^2)); +end + +I2b = Indexset==2 & beta_u==0; +Da(I2b) = (ub(I2b)-x(I2b))./denom1(I2b)-1; +Db(I2b) = -Fx(I2b)./denom1(I2b)-1; +I2b = Indexset==2 & beta_u~=0; +if any(I2b) + Da(I2b) = -z(I2b)./denom2(I2b)-1; + Db(I2b) = -(DFx(I2b,:)*z)./denom2(I2b)-1; +end + +I2a = I(Indexset==2 & alpha_u==1); +if any(I2a) + H2(I2a,:) = bsxfun(@times,x(I2a)-ub(I2a),DFx(I2a,:))+... + sparse(1:length(I2a),I2a,Fx(I2a),length(I2a),n,length(I2a)); +end + +I3 = Indexset==3; +phi = zeros(n,1); +ai = zeros(n,1); +bi = zeros(n,1); +ci = zeros(n,1); +di = zeros(n,1); +denom1 = zeros(n,1); +denom2 = zeros(n,1); +denom3 = zeros(n,1); +denom4 = zeros(n,1); +if any(I3) + phi(I3) = -ub(I3)+x(I3)+Fx(I3)+sqrt((ub(I3)-x(I3)).^2+Fx(I3).^2); + denom1(I3) = max(null,sqrt((x(I3)-lb(I3)).^2+phi(I3).^2)); + denom2(I3) = max(null,sqrt(z(I3).^2+(DFx(I3,:)*z).^2)); + denom3(I3) = max(null,sqrt((ub(I3)-x(I3)).^2+Fx(I3).^2)); + denom4(I3) = max(null,sqrt(z(I3).^2)); +end + +I3bu = Indexset==3 & beta_u==0; +ci(I3bu) = (x(I3bu)-ub(I3bu))./denom3(I3bu)+1; +di(I3bu) = Fx(I3bu)./denom3(I3bu)+1; +I3bu = Indexset==3 & beta_u~=0; +if any(I3bu) + ci(I3bu) = 1+z(I3bu)./denom2(I3bu); + di(I3bu) = 1+(DFx(I3bu,:)*z)./denom2(I3bu); +end + +I3bl = Indexset==3 & beta_l==0; +ai(I3bl) = (x(I3bl)-lb(I3bl))./denom1(I3bl)-1; +bi(I3bl) = phi(I3bl)./denom1(I3bl)-1; +I3bl = Indexset==3 & beta_l~=0; +if any(I3bl) + ai(I3bl) = z(I3bl)./denom4(I3bl)-1; + bi(I3bl) = (ci(I3bl).*z(I3bl)+(di(I3bl,ones(1,n)).*DFx(I3bl,:))*z)./denom4(I3bl)-1; +end + +Da(I3) = ai(I3)+bi(I3).*ci(I3); +Db(I3) = bi(I3).*di(I3); + +I3a = I(Indexset==3 & alpha_l==1 & alpha_u==1); +if any(I3a) + H2(I3a,:) = bsxfun(@times,-lb(I3a)-ub(I3a)+2*x(I3a),DFx(I3a,:))+... + 2*sparse(1:length(I3a),I3a,Fx(I3a),length(I3a),n,length(I3a)); +end +I3a = I(Indexset==3 & alpha_l==1 & alpha_u~=1); +if any(I3a) + H2(I3a,:) = bsxfun(@times,x(I3a)-lb(I3a),DFx(I3a,:))+... + sparse(1:length(I3a),I3a,Fx(I3a),length(I3a),n,length(I3a)); +end +I3a = I(Indexset==3 & alpha_l~=1 & alpha_u==1); +if any(I3a) + H2(I3a,:) = bsxfun(@times,x(I3a)-ub(I3a),DFx(I3a,:))+... + sparse(1:length(I3a),I3a,Fx(I3a),length(I3a),n,length(I3a)); +end + +H1 = spdiags(Db,0,length(Db),length(Db))*DFx; +H1 = H1 + spdiags(Da, 0, length(Da), length(Da)); + +H = [lambda1*H1; lambda2*H2]; diff --git a/matlab/load_first_mh_history_file.m b/matlab/load_first_mh_history_file.m index 3177fafe45..67bd70a1c5 100644 --- a/matlab/load_first_mh_history_file.m +++ b/matlab/load_first_mh_history_file.m @@ -1,7 +1,7 @@ function info = load_first_mh_history_file(MetropolisFolder, ModelName) % This routine requires that the MCMC draws were obtained with a dynare version greater than 4.3.3. - + % Copyright (C) 2013 Dynare Team % % This file is part of Dynare. diff --git a/matlab/load_m_file_data_legacy.m b/matlab/load_m_file_data_legacy.m index 5a4cdecb90..9d4b8e34c8 100644 --- a/matlab/load_m_file_data_legacy.m +++ b/matlab/load_m_file_data_legacy.m @@ -81,82 +81,82 @@ o2WysrOISH = dseries(eval(sprintf(VbO4y7zOlh, U7ORsJ0vy3{:})), [], U7ORsJ0vy3); return %@test:1 - % Write a data file - fid = fopen('example.m','w'); - fwriten(fid, 'a = randn(100,1);'); - fwriten(fid, 'b = randn(100,1);'); - fwriten(fid, 'c = transpose(randn(100,1));'); - fwriten(fid, 'd = randn(100,1);'); - fwriten(fid, 'e = randn(100,2);'); - fwriten(fid, ' '); - fwriten(fid, 'f = NaN(100,1);'); - fwriten(fid, 'for i=1:100'); - fwriten(fid, ' f(i) = log(rand());') - fwriten(fid, 'end'); - fclose(fid); - % Define a set of variables to be loaded. - listofvariablestobeloaded = {'b', 'a'}; - % Test if we can load the data. - try - data = load_m_file_data_legacy('example.m', listofvariablestobeloaded); - delete example.m - t(1) = 1; - catch - t(1) = 0; - end - T = all(t); +% Write a data file +fid = fopen('example.m','w'); +fwriten(fid, 'a = randn(100,1);'); +fwriten(fid, 'b = randn(100,1);'); +fwriten(fid, 'c = transpose(randn(100,1));'); +fwriten(fid, 'd = randn(100,1);'); +fwriten(fid, 'e = randn(100,2);'); +fwriten(fid, ' '); +fwriten(fid, 'f = NaN(100,1);'); +fwriten(fid, 'for i=1:100'); +fwriten(fid, ' f(i) = log(rand());') +fwriten(fid, 'end'); +fclose(fid); +% Define a set of variables to be loaded. +listofvariablestobeloaded = {'b', 'a'}; +% Test if we can load the data. +try + data = load_m_file_data_legacy('example.m', listofvariablestobeloaded); + delete example.m + t(1) = 1; +catch + t(1) = 0; +end +T = all(t); %@eof:1 %@test:2 - % Write a data file - fid = fopen('example.m','w'); - fwriten(fid, 'a = randn(100,1);'); - fwriten(fid, 'b = randn(100,1);'); - fwriten(fid, 'c = transpose(randn(100,1));'); - fwriten(fid, 'd = randn(100,1);'); - fwriten(fid, 'e = randn(100,2);'); - fwriten(fid, ' '); - fwriten(fid, 'f = NaN(100,1);'); - fwriten(fid, 'for i=1:100'); - fwriten(fid, ' f(i) = log(rand());') - fwriten(fid, 'end'); - fclose(fid); - % Define a set of variables to be loaded. - listofvariablestobeloaded = {'e', 'a'}; - % Test if we can load the data. - try - data = load_m_file_data_legacy('example.m', listofvariablestobeloaded); - delete example.m - t(1) = 0; - catch - t(1) = 1; - end - T = all(t); +% Write a data file +fid = fopen('example.m','w'); +fwriten(fid, 'a = randn(100,1);'); +fwriten(fid, 'b = randn(100,1);'); +fwriten(fid, 'c = transpose(randn(100,1));'); +fwriten(fid, 'd = randn(100,1);'); +fwriten(fid, 'e = randn(100,2);'); +fwriten(fid, ' '); +fwriten(fid, 'f = NaN(100,1);'); +fwriten(fid, 'for i=1:100'); +fwriten(fid, ' f(i) = log(rand());') +fwriten(fid, 'end'); +fclose(fid); +% Define a set of variables to be loaded. +listofvariablestobeloaded = {'e', 'a'}; +% Test if we can load the data. +try + data = load_m_file_data_legacy('example.m', listofvariablestobeloaded); + delete example.m + t(1) = 0; +catch + t(1) = 1; +end +T = all(t); %@eof:2 %@test:3 - % Write a data file - fid = fopen('example.m','w'); - fwriten(fid, 'a = randn(100,1);'); - fwriten(fid, 'b = randn(100,1);'); - fwriten(fid, 'c = transpose(randn(100,1));'); - fwriten(fid, 'd = randn(100,1);'); - fwriten(fid, 'e = randn(100,2);'); - fwriten(fid, ' '); - fwriten(fid, 'f = NaN(100,1);'); - fwriten(fid, 'for i=1:100'); - fwriten(fid, ' f(i) = log(rand());') - fwriten(fid, 'end'); - fclose(fid); - % Define a set of variables to be loaded. - listofvariablestobeloaded = {'c', 'a'}; - % Test if we can load the data. - try - data = load_m_file_data_legacy('example.m', listofvariablestobeloaded); - delete example.m - t(1) = 1; - catch - t(1) = 0; - end - T = all(t); +% Write a data file +fid = fopen('example.m','w'); +fwriten(fid, 'a = randn(100,1);'); +fwriten(fid, 'b = randn(100,1);'); +fwriten(fid, 'c = transpose(randn(100,1));'); +fwriten(fid, 'd = randn(100,1);'); +fwriten(fid, 'e = randn(100,2);'); +fwriten(fid, ' '); +fwriten(fid, 'f = NaN(100,1);'); +fwriten(fid, 'for i=1:100'); +fwriten(fid, ' f(i) = log(rand());') +fwriten(fid, 'end'); +fclose(fid); +% Define a set of variables to be loaded. +listofvariablestobeloaded = {'c', 'a'}; +% Test if we can load the data. +try + data = load_m_file_data_legacy('example.m', listofvariablestobeloaded); + delete example.m + t(1) = 1; +catch + t(1) = 0; +end +T = all(t); %@eof:3 diff --git a/matlab/load_mat_file_data_legacy.m b/matlab/load_mat_file_data_legacy.m index bf8f342b1d..c771013b32 100644 --- a/matlab/load_mat_file_data_legacy.m +++ b/matlab/load_mat_file_data_legacy.m @@ -32,7 +32,7 @@ else data_mat=[]; for var_iter=1:length(varobs) try - data_mat=[data_mat vec(data_file.(varobs{1,var_iter}))]; + data_mat=[data_mat vec(data_file.(varobs{1,var_iter}))]; catch error('makedataset: The variable %s does not have dimensions conformable with the previous one',varobs{1,var_iter}); end diff --git a/matlab/lyapunov_symm.m b/matlab/lyapunov_symm.m index 694415d714..a4618b1711 100644 --- a/matlab/lyapunov_symm.m +++ b/matlab/lyapunov_symm.m @@ -74,7 +74,7 @@ if method == 3 X_old = X; X = a * X * at + b; evol = max(sum(abs(X - X_old))); %norm_1 - %evol = max(sum(abs(X - X_old)')); %norm_inf + %evol = max(sum(abs(X - X_old)')); %norm_inf it_fp = it_fp + 1; end; if debug diff --git a/matlab/marginal_density.m b/matlab/marginal_density.m index 250bb5ddff..58e293da87 100644 --- a/matlab/marginal_density.m +++ b/matlab/marginal_density.m @@ -172,8 +172,8 @@ if nvx eval(['oo_.' field_name '_std_at_mode.shocks_std.' name ' = stdh(ip);']); ip = ip+1; end - end - if nvn +end +if nvn ip = nvx+1; for i=1:nvn name = options_.varobs{estim_params_.nvn_observable_correspondence(i,1)}; @@ -181,7 +181,7 @@ if nvx eval(['oo_.' field_name '_std_at_mode.measurement_errors_std.' name ' = stdh(ip);']); ip = ip+1; end - end +end if ncx ip = nvx+nvn+1; diff --git a/matlab/metropolis_draw.m b/matlab/metropolis_draw.m index ad396b30b7..a8e1e602d3 100644 --- a/matlab/metropolis_draw.m +++ b/matlab/metropolis_draw.m @@ -82,7 +82,7 @@ if init end return else %not initialization, return one draw - %get random draw from random chain + %get random draw from random chain ChainNumber = ceil(rand*mh_nblck); DrawNumber = ceil(rand*NumberOfDraws); diff --git a/matlab/metropolis_hastings_initialization.m b/matlab/metropolis_hastings_initialization.m index e18ea098a4..97a454eeea 100644 --- a/matlab/metropolis_hastings_initialization.m +++ b/matlab/metropolis_hastings_initialization.m @@ -335,9 +335,9 @@ elseif options_.mh_recover if OldMhExists LastLineNumberInThePreviousMh = record.MhDraws(end-1,3);% Number of lines in the last mh files of the previous session. LastFileNumberInThePreviousMh = sum(record.MhDraws(1:end-1,2),1);% Number of mh files in the the previous sessions. - %Test if the last mh files of the previous session were not full yet + %Test if the last mh files of the previous session were not full yet if LastLineNumberInThePreviousMh < MAX_nruns%not full - %store starting point if whole chain needs to be redone + %store starting point if whole chain needs to be redone NewFile = ones(NumberOfBlocks,1)*LastFileNumberInThePreviousMh; FirstLine = ones(NumberOfBlocks,1)*(LastLineNumberInThePreviousMh+1); LastFileFullIndicator=0; @@ -394,7 +394,7 @@ elseif options_.mh_recover % How many mh-files are saved in this block? NumberOfSavedMhFilesInTheCrashedBlck = NumberOfMhFilesPerBlock(FirstBlock); ExistingDrawsInLastMCFile=0; %initialize: no MCMC draws of current MCMC are in file from last run - % Check whether last present file is a file included in the last MCMC run + % Check whether last present file is a file included in the last MCMC run if ~LastFileFullIndicator if NumberOfSavedMhFilesInTheCrashedBlck==NewFile(FirstBlock) %only that last file exists, but no files from current MCMC loaded_results=load([BaseName '_mh' int2str(NewFile(FirstBlock)) '_blck' int2str(FirstBlock) '.mat']); @@ -413,13 +413,13 @@ elseif options_.mh_recover NewFile(FirstBlock)=NewFile(FirstBlock)+1; %set first file to be created to next one end end -% % Correct the number of saved mh files if the crashed Metropolis was not the first session (so -% % that NumberOfSavedMhFilesInTheCrashedBlck is the number of saved mh files in the crashed chain -% % of the current session). -% if OldMhExists -% NumberOfSavedMhFilesInTheCrashedBlck = NumberOfSavedMhFilesInTheCrashedBlck - LastFileNumberInThePreviousMh; -% end -% NumberOfSavedMhFiles = NumberOfSavedMhFilesInTheCrashedBlck+LastFileNumberInThePreviousMh; + % % Correct the number of saved mh files if the crashed Metropolis was not the first session (so + % % that NumberOfSavedMhFilesInTheCrashedBlck is the number of saved mh files in the crashed chain + % % of the current session). + % if OldMhExists + % NumberOfSavedMhFilesInTheCrashedBlck = NumberOfSavedMhFilesInTheCrashedBlck - LastFileNumberInThePreviousMh; + % end + % NumberOfSavedMhFiles = NumberOfSavedMhFilesInTheCrashedBlck+LastFileNumberInThePreviousMh; % Correct initial conditions. if NumberOfSavedMhFilesInTheCrashedBlck<ExpectedNumberOfMhFilesPerBlock diff --git a/matlab/metropolis_run_analysis.m b/matlab/metropolis_run_analysis.m index 99b589c820..0433b7f6f9 100644 --- a/matlab/metropolis_run_analysis.m +++ b/matlab/metropolis_run_analysis.m @@ -39,7 +39,7 @@ params = []; blck = 1; for i=1:record.LastFileNumber fname = [M.fname '/metropolis/' M.fname '_mh' int2str(i) '_blck' ... - int2str(blck) '.mat']; + int2str(blck) '.mat']; if exist(fname,'file') o=load(fname); logPost = [logPost; o.logpo2]; diff --git a/matlab/minus_logged_prior_density.m b/matlab/minus_logged_prior_density.m index 38662541e1..60208647f7 100644 --- a/matlab/minus_logged_prior_density.m +++ b/matlab/minus_logged_prior_density.m @@ -128,8 +128,8 @@ M_ = set_all_parameters(xparams,EstimatedParams,DynareModel); % Return, with endogenous penalty when possible, if dynare_resolve issues an error code (defined in resol). if info(1) if info(1) == 3 || info(1) == 4 || info(1) == 5 || info(1)==6 ||info(1) == 19 ... - info(1) == 20 || info(1) == 21 || info(1) == 23 || info(1) == 26 || ... - info(1) == 81 || info(1) == 84 || info(1) == 85 + info(1) == 20 || info(1) == 21 || info(1) == 23 || info(1) == 26 || ... + info(1) == 81 || info(1) == 84 || info(1) == 85 %meaningful second entry of output that can be used fval = Inf; info(4) = info(2); diff --git a/matlab/missing/corrcoef/corrcoef.m b/matlab/missing/corrcoef/corrcoef.m index c918c61043..ec3b670917 100644 --- a/matlab/missing/corrcoef/corrcoef.m +++ b/matlab/missing/corrcoef/corrcoef.m @@ -25,28 +25,28 @@ function [R,sig,ci1,ci2,nan_sig] = corrcoef(X,Y,varargin) % This replaces RANKCORR.M % % [...] = CORRCOEF(..., param1, value1, param2, value2, ... ); -% param value -% 'Mode' type of correlation -% 'Pearson','parametric' -% 'Spearman' -% 'rank' -% 'rows' how do deal with missing values encoded as NaN's. -% 'complete': remove all rows with at least one NaN -% 'pairwise': [default] -% 'alpha' 0.01 : significance level to compute confidence interval +% param value +% 'Mode' type of correlation +% 'Pearson','parametric' +% 'Spearman' +% 'rank' +% 'rows' how do deal with missing values encoded as NaN's. +% 'complete': remove all rows with at least one NaN +% 'pairwise': [default] +% 'alpha' 0.01 : significance level to compute confidence interval % % [R,p,ci1,ci2,nansig] = CORRCOEF(...); % R is the correlation matrix -% R(i,j) is the correlation coefficient r between X(:,i) and Y(:,j) +% R(i,j) is the correlation coefficient r between X(:,i) and Y(:,j) % p gives the significance of R -% It tests the null hypothesis that the product moment correlation coefficient is zero +% It tests the null hypothesis that the product moment correlation coefficient is zero % using Student's t-test on the statistic t = r*sqrt(N-2)/sqrt(1-r^2) % where N is the number of samples (Statistics, M. Spiegel, Schaum series). % p > alpha: do not reject the Null hypothesis: 'R is zero'. % p < alpha: The alternative hypothesis 'R is larger than zero' is true with probability (1-alpha). -% ci1 lower (1-alpha) confidence interval -% ci2 upper (1-alpha) confidence interval -% If no alpha is provided, the default alpha is 0.01. This can be changed with function flag_implicit_significance. +% ci1 lower (1-alpha) confidence interval +% ci2 upper (1-alpha) confidence interval +% If no alpha is provided, the default alpha is 0.01. This can be changed with function flag_implicit_significance. % nan_sig p-value whether H0: 'NaN''s are not correlated' could be correct % if nan_sig < alpha, H1 ('NaNs are correlated') is very likely. % @@ -65,7 +65,7 @@ function [R,sig,ci1,ci2,nan_sig] = corrcoef(X,Y,varargin) % Further recommandation related to the correlation coefficient: % + LOOK AT THE SCATTERPLOTS to make sure that the relationship is linear % + Correlation is not causation because -% it is not clear which parameter is 'cause' and which is 'effect' and +% it is not clear which parameter is 'cause' and which is 'effect' and % the observed correlation between two variables might be due to the action of other, unobserved variables. % % see also: SUMSKIPNAN, COVM, COV, COR, SPEARMAN, RANKCORR, RANKS, @@ -124,54 +124,54 @@ function [R,sig,ci1,ci2,nan_sig] = corrcoef(X,Y,varargin) global FLAG_NANS_OCCURED; -NARG = nargout; % needed because nargout is not reentrant in Octave, and corrcoef is recursive +NARG = nargout; % needed because nargout is not reentrant in Octave, and corrcoef is recursive mode = []; if nargin==1 - Y = []; - Mode='Pearson'; + Y = []; + Mode='Pearson'; elseif nargin==0 - fprintf(2,'Error CORRCOEF: Missing argument(s)\n'); + fprintf(2,'Error CORRCOEF: Missing argument(s)\n'); elseif nargin>1 - if ischar(Y) - varg = [Y,varargin]; - Y=[]; - else - varg = varargin; - end; + if ischar(Y) + varg = [Y,varargin]; + Y=[]; + else + varg = varargin; + end; - if length(varg)<1, - Mode = 'Pearson'; - elseif length(varg)==1, - Mode = varg{1}; - else - for k = 2:2:length(varg), - mode = setfield(mode,lower(varg{k-1}),varg{k}); - end; - if isfield(mode,'mode') - Mode = mode.mode; - end; + if length(varg)<1, + Mode = 'Pearson'; + elseif length(varg)==1, + Mode = varg{1}; + else + for k = 2:2:length(varg), + mode = setfield(mode,lower(varg{k-1}),varg{k}); + end; + if isfield(mode,'mode') + Mode = mode.mode; end; + end; end; if isempty(Mode) Mode='pearson'; end; Mode=[Mode,' ']; -FLAG_WARNING = warning; % save warning status +FLAG_WARNING = warning; % save warning status warning('off'); [r1,c1]=size(X); if ~isempty(Y) - [r2,c2]=size(Y); - if r1~=r2, - fprintf(2,'Error CORRCOEF: X and Y must have the same number of observations (rows).\n'); - return; - end; - NN = real(~isnan(X)')*real(~isnan(Y)); + [r2,c2]=size(Y); + if r1~=r2, + fprintf(2,'Error CORRCOEF: X and Y must have the same number of observations (rows).\n'); + return; + end; + NN = real(~isnan(X)')*real(~isnan(Y)); else - [r2,c2]=size(X); - NN = real(~isnan(X)')*real(~isnan(X)); + [r2,c2]=size(X); + NN = real(~isnan(X)')*real(~isnan(X)); end; %%%%% generate combinations using indices for pairwise calculation of the correlation @@ -196,117 +196,117 @@ if YESNAN, end; end; if isempty(Y), - IX = ones(c1)-diag(ones(c1,1)); - [jx, jy ] = find(IX); - [jxo,jyo] = find(IX); + IX = ones(c1)-diag(ones(c1,1)); + [jx, jy ] = find(IX); + [jxo,jyo] = find(IX); R = eye(c1); else - IX = sparse([],[],[],c1+c2,c1+c2,c1*c2); - IX(1:c1,c1+(1:c2)) = 1; - [jx,jy] = find(IX); + IX = sparse([],[],[],c1+c2,c1+c2,c1*c2); + IX(1:c1,c1+(1:c2)) = 1; + [jx,jy] = find(IX); - IX = ones(c1,c2); - [jxo,jyo] = find(IX); + IX = ones(c1,c2); + [jxo,jyo] = find(IX); R = zeros(c1,c2); end; if strcmp(lower(Mode(1:7)),'pearson'); - % see http://mathworld.wolfram.com/CorrelationCoefficient.html + % see http://mathworld.wolfram.com/CorrelationCoefficient.html if ~YESNAN, - [S,N,SSQ] = sumskipnan(X,1); - if ~isempty(Y), - [S2,N2,SSQ2] = sumskipnan(Y,1); - CC = X'*Y; - M1 = S./N; - M2 = S2./N2; - cc = CC./NN - M1'*M2; - R = cc./sqrt((SSQ./N-M1.*M1)'*(SSQ2./N2-M2.*M2)); - else - CC = X'*X; - M = S./N; - cc = CC./NN - M'*M; - v = SSQ./N - M.*M; %max(N-1,0); - R = cc./sqrt(v'*v); - end; + [S,N,SSQ] = sumskipnan(X,1); + if ~isempty(Y), + [S2,N2,SSQ2] = sumskipnan(Y,1); + CC = X'*Y; + M1 = S./N; + M2 = S2./N2; + cc = CC./NN - M1'*M2; + R = cc./sqrt((SSQ./N-M1.*M1)'*(SSQ2./N2-M2.*M2)); else - if ~isempty(Y), - X = [X,Y]; - end; - for k = 1:length(jx), - %ik = ~any(isnan(X(:,[jx(k),jy(k)])),2); - ik = ~isnan(X(:,jx(k))) & ~isnan(X(:,jy(k))); - [s,n,s2] = sumskipnan(X(ik,[jx(k),jy(k)]),1); - v = (s2-s.*s./n)./n; - cc = X(ik,jx(k))'*X(ik,jy(k)); - cc = cc/n(1) - prod(s./n); - %r(k) = cc./sqrt(prod(v)); - R(jxo(k),jyo(k)) = cc./sqrt(prod(v)); - end; + CC = X'*X; + M = S./N; + cc = CC./NN - M'*M; + v = SSQ./N - M.*M; %max(N-1,0); + R = cc./sqrt(v'*v); + end; + else + if ~isempty(Y), + X = [X,Y]; + end; + for k = 1:length(jx), + %ik = ~any(isnan(X(:,[jx(k),jy(k)])),2); + ik = ~isnan(X(:,jx(k))) & ~isnan(X(:,jy(k))); + [s,n,s2] = sumskipnan(X(ik,[jx(k),jy(k)]),1); + v = (s2-s.*s./n)./n; + cc = X(ik,jx(k))'*X(ik,jy(k)); + cc = cc/n(1) - prod(s./n); + %r(k) = cc./sqrt(prod(v)); + R(jxo(k),jyo(k)) = cc./sqrt(prod(v)); + end; end elseif strcmp(lower(Mode(1:4)),'rank'); - % see [ 6] http://mathworld.wolfram.com/SpearmanRankCorrelationCoefficient.html + % see [ 6] http://mathworld.wolfram.com/SpearmanRankCorrelationCoefficient.html if ~YESNAN, - if isempty(Y) - R = corrcoef(ranks(X)); - else - R = corrcoef(ranks(X),ranks(Y)); - end; + if isempty(Y) + R = corrcoef(ranks(X)); else - if ~isempty(Y), - X = [X,Y]; - end; - for k = 1:length(jx), - %ik = ~any(isnan(X(:,[jx(k),jy(k)])),2); - ik = ~isnan(X(:,jx(k))) & ~isnan(X(:,jy(k))); - il = ranks(X(ik,[jx(k),jy(k)])); - R(jxo(k),jyo(k)) = corrcoef(il(:,1),il(:,2)); - end; + R = corrcoef(ranks(X),ranks(Y)); + end; + else + if ~isempty(Y), + X = [X,Y]; + end; + for k = 1:length(jx), + %ik = ~any(isnan(X(:,[jx(k),jy(k)])),2); + ik = ~isnan(X(:,jx(k))) & ~isnan(X(:,jy(k))); + il = ranks(X(ik,[jx(k),jy(k)])); + R(jxo(k),jyo(k)) = corrcoef(il(:,1),il(:,2)); + end; X = ranks(X); end; elseif strcmp(lower(Mode(1:8)),'spearman'); - % see [ 6] http://mathworld.wolfram.com/SpearmanRankCorrelationCoefficient.html - if ~isempty(Y), - X = [X,Y]; - end; + % see [ 6] http://mathworld.wolfram.com/SpearmanRankCorrelationCoefficient.html + if ~isempty(Y), + X = [X,Y]; + end; - n = repmat(nan,c1,c2); + n = repmat(nan,c1,c2); - if ~YESNAN, - iy = ranks(X); % calculates ranks; + if ~YESNAN, + iy = ranks(X); % calculates ranks; - for k = 1:length(jx), - [R(jxo(k),jyo(k)),n(jxo(k),jyo(k))] = sumskipnan((iy(:,jx(k)) - iy(:,jy(k))).^2); % NN is the number of non-missing values - end; - else - for k = 1:length(jx), - %ik = ~any(isnan(X(:,[jx(k),jy(k)])),2); - ik = ~isnan(X(:,jx(k))) & ~isnan(X(:,jy(k))); - il = ranks(X(ik,[jx(k),jy(k)])); - % NN is the number of non-missing values - [R(jxo(k),jyo(k)),n(jxo(k),jyo(k))] = sumskipnan((il(:,1) - il(:,2)).^2); - end; - X = ranks(X); + for k = 1:length(jx), + [R(jxo(k),jyo(k)),n(jxo(k),jyo(k))] = sumskipnan((iy(:,jx(k)) - iy(:,jy(k))).^2); % NN is the number of non-missing values + end; + else + for k = 1:length(jx), + %ik = ~any(isnan(X(:,[jx(k),jy(k)])),2); + ik = ~isnan(X(:,jx(k))) & ~isnan(X(:,jy(k))); + il = ranks(X(ik,[jx(k),jy(k)])); + % NN is the number of non-missing values + [R(jxo(k),jyo(k)),n(jxo(k),jyo(k))] = sumskipnan((il(:,1) - il(:,2)).^2); end; - R = 1 - 6 * R ./ (n.*(n.*n-1)); + X = ranks(X); + end; + R = 1 - 6 * R ./ (n.*(n.*n-1)); elseif strcmp(lower(Mode(1:7)),'partial'); - fprintf(2,'Error CORRCOEF: use PARTCORRCOEF \n',Mode); + fprintf(2,'Error CORRCOEF: use PARTCORRCOEF \n',Mode); - return; + return; elseif strcmp(lower(Mode(1:7)),'kendall'); - fprintf(2,'Error CORRCOEF: mode ''%s'' not implemented yet.\n',Mode); + fprintf(2,'Error CORRCOEF: mode ''%s'' not implemented yet.\n',Mode); - return; + return; else - fprintf(2,'Error CORRCOEF: unknown mode ''%s''\n',Mode); + fprintf(2,'Error CORRCOEF: unknown mode ''%s''\n',Mode); end; if (NARG<2), - warning(FLAG_WARNING); % restore warning status - return; + warning(FLAG_WARNING); % restore warning status + return; end; @@ -314,7 +314,7 @@ end; if isfield(mode,'alpha') alpha = mode.alpha; elseif exist('flag_implicit_significance','file'), - alpha = flag_implicit_significance; + alpha = flag_implicit_significance; else alpha = 0.01; end; @@ -324,36 +324,36 @@ end; % SIGNIFICANCE TEST R(isnan(R))=0; tmp = 1 - R.*R; -tmp(tmp<0) = 0; % prevent tmp<0 i.e. imag(t)~=0 +tmp(tmp<0) = 0; % prevent tmp<0 i.e. imag(t)~=0 t = R.*sqrt(max(NN-2,0)./tmp); if exist('t_cdf','file'); - sig = t_cdf(t,NN-2); + sig = t_cdf(t,NN-2); elseif exist('tcdf','file')>1; - sig = tcdf(t,NN-2); + sig = tcdf(t,NN-2); else - fprintf('CORRCOEF: significance test not completed because of missing TCDF-function\n') - sig = repmat(nan,size(R)); + fprintf('CORRCOEF: significance test not completed because of missing TCDF-function\n') + sig = repmat(nan,size(R)); end; sig = 2 * min(sig,1 - sig); if NARG<3, warning(FLAG_WARNING); % restore warning status - return; + return; end; tmp = R; -%tmp(ix1 | ix2) = nan; % avoid division-by-zero warning +%tmp(ix1 | ix2) = nan; % avoid division-by-zero warning z = log((1+tmp)./(1-tmp))/2; % Fisher transformation [21] -%sz = 1./sqrt(NN-3); % standard error of z -sz = sqrt(2)*erfinv(1-alpha)./sqrt(NN-3); % confidence interval for alpha of z + %sz = 1./sqrt(NN-3); % standard error of z +sz = sqrt(2)*erfinv(1-alpha)./sqrt(NN-3); % confidence interval for alpha of z ci1 = tanh(z-sz); ci2 = tanh(z+sz); -%ci1(isnan(ci1))=R(isnan(ci1)); % in case of isnan(ci), the interval limits are exactly the R value +%ci1(isnan(ci1))=R(isnan(ci1)); % in case of isnan(ci), the interval limits are exactly the R value %ci2(isnan(ci2))=R(isnan(ci2)); if (NARG<5) || ~YESNAN, @@ -371,13 +371,13 @@ nan_sig(isnan(nan_R)) = nan; nan_R(isnan(nan_R)) = 0; if 0, any(nan_sig(:) < alpha), - tmp = nan_sig(:); % Hack to skip NaN's in MIN(X) - min_sig = min(tmp(~isnan(tmp))); % Necessary, because Octave returns NaN rather than min(X) for min(NaN,X) - fprintf(1,'CORRCOFF Warning: Missing Values (i.e. NaNs) are not independent of data (p-value=%f)\n', min_sig); - fprintf(1,' Its recommended to remove all samples (i.e. rows) with any missing value (NaN).\n'); - fprintf(1,' The null-hypotheses (NaNs are uncorrelated) is rejected for the following parameter pair(s).\n'); - [ix,iy] = find(nan_sig < alpha); - disp([ix,iy]) + tmp = nan_sig(:); % Hack to skip NaN's in MIN(X) + min_sig = min(tmp(~isnan(tmp))); % Necessary, because Octave returns NaN rather than min(X) for min(NaN,X) + fprintf(1,'CORRCOFF Warning: Missing Values (i.e. NaNs) are not independent of data (p-value=%f)\n', min_sig); + fprintf(1,' Its recommended to remove all samples (i.e. rows) with any missing value (NaN).\n'); + fprintf(1,' The null-hypotheses (NaNs are uncorrelated) is rejected for the following parameter pair(s).\n'); + [ix,iy] = find(nan_sig < alpha); + disp([ix,iy]) end; %%%%% ----- end of independence check ------ diff --git a/matlab/missing/corrcoef/flag_implicit_skip_nan.m b/matlab/missing/corrcoef/flag_implicit_skip_nan.m index 409b9f6964..bf162f0718 100644 --- a/matlab/missing/corrcoef/flag_implicit_skip_nan.m +++ b/matlab/missing/corrcoef/flag_implicit_skip_nan.m @@ -1,6 +1,6 @@ function FLAG = flag_implicit_skip_nan(i) % FLAG_IMPLICIT_SKIP_NAN sets and gets default mode for handling NaNs -% 1 skips NaN's (the default mode if no mode is set) +% 1 skips NaN's (the default mode if no mode is set) % 0 NaNs are propagated; input NaN's give NaN's at the output % % FLAG = flag_implicit_skip_nan() @@ -9,15 +9,15 @@ function FLAG = flag_implicit_skip_nan(i) % flag_implicit_skip_nan(FLAG) % sets mode % % prevFLAG = flag_implicit_skip_nan(nextFLAG) -% gets previous set FLAG and sets FLAG for the future +% gets previous set FLAG and sets FLAG for the future % flag_implicit_skip_nan(prevFLAG) -% resets FLAG to previous mode +% resets FLAG to previous mode % % It is used in: -% SUMSKIPNAN, MEDIAN, QUANTILES, TRIMEAN +% SUMSKIPNAN, MEDIAN, QUANTILES, TRIMEAN % and affects many other functions like: -% CENTER, KURTOSIS, MAD, MEAN, MOMENT, RMS, SEM, SKEWNESS, -% STATISTIC, STD, VAR, ZSCORE etc. +% CENTER, KURTOSIS, MAD, MEAN, MOMENT, RMS, SEM, SKEWNESS, +% STATISTIC, STD, VAR, ZSCORE etc. % % The mode is stored in the global variable FLAG_implicit_skip_nan % It is recommended to use flag_implicit_skip_nan(1) as default and @@ -40,7 +40,7 @@ function FLAG = flag_implicit_skip_nan(i) % along with this program; if not, write to the Free Software % Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -% $Id: flag_implicit_skip_nan.m 8351 2011-06-24 17:35:07Z carandraug $ +% $Id: flag_implicit_skip_nan.m 8351 2011-06-24 17:35:07Z carandraug $ % Copyright (C) 2001-2003,2009 by Alois Schloegl <alois.schloegl@gmail.com> % Copyright (C) 2014 Dynare Team % This function is part of the NaN-toolbox @@ -49,7 +49,7 @@ function FLAG = flag_implicit_skip_nan(i) persistent FLAG_implicit_skip_nan; -%% if strcmp(version,'3.6'), FLAG_implicit_skip_nan=(1==1); end; %% hack for the use with Freemat3.6 +%% if strcmp(version,'3.6'), FLAG_implicit_skip_nan=(1==1); end; %% hack for the use with Freemat3.6 %%% set DEFAULT value of FLAG if isempty(FLAG_implicit_skip_nan), diff --git a/matlab/missing/corrcoef/sumskipnan.m b/matlab/missing/corrcoef/sumskipnan.m index 78f8ecbc1e..15768dc09c 100644 --- a/matlab/missing/corrcoef/sumskipnan.m +++ b/matlab/missing/corrcoef/sumskipnan.m @@ -13,13 +13,13 @@ function [o,count,SSQ] = sumskipnan(x, DIM, W) % [Y,N,SSQ] = sumskipnan(x [,DIM]) % [...] = sumskipnan(x, DIM, W) % -% x input data -% DIM dimension (default: []) -% empty DIM sets DIM to first non singleton dimension -% W weight vector for weighted sum, numel(W) must fit size(x,DIM) -% Y resulting sum -% N number of valid (not missing) elements -% SSQ sum of squares +% x input data +% DIM dimension (default: []) +% empty DIM sets DIM to first non singleton dimension +% W weight vector for weighted sum, numel(W) must fit size(x,DIM) +% Y resulting sum +% N number of valid (not missing) elements +% SSQ sum of squares % % the function FLAG_NANS_OCCURED() returns whether any value in x % is a not-a-number (NaN) @@ -47,7 +47,7 @@ function [o,count,SSQ] = sumskipnan(x, DIM, W) % You should have received a copy of the GNU General Public License % along with this program; If not, see <http://www.gnu.org/licenses/>. -% $Id: sumskipnan.m 9033 2011-11-08 20:58:07Z schloegl $ +% $Id: sumskipnan.m 9033 2011-11-08 20:58:07Z schloegl $ % Copyright (C) 2000-2005,2009,2011 by Alois Schloegl <alois.schloegl@gmail.com> % Copyright (C) 2014 Dynare Team % This function is part of the NaN-toolbox @@ -57,10 +57,10 @@ function [o,count,SSQ] = sumskipnan(x, DIM, W) global FLAG_NANS_OCCURED; if nargin<2, - DIM = []; + DIM = []; end; if nargin<3, - W = []; + W = []; end; % an efficient implementation in C of the following lines @@ -73,14 +73,14 @@ end; % if ~isnan(i(k)) % { o += x(k); % count += 1; -% tmp = x(k)*x(k) -% o2 += tmp; -% o3 += tmp.*tmp; +% tmp = x(k)*x(k) +% o2 += tmp; +% o3 += tmp.*tmp; % }; if isempty(DIM), - DIM = find(size(x)>1,1); - if isempty(DIM), DIM = 1; end; + DIM = find(size(x)>1,1); + if isempty(DIM), DIM = 1; end; end if (DIM<1), DIM = 1; end; %% Hack, because min([])=0 for FreeMat v3.5 @@ -169,7 +169,7 @@ end; % count non-NaN's %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% if nargout>1, - count = sum(x==x,DIM); + count = sum(x==x,DIM); FLAG_NANS_OCCURED = any(count(:)<size(x,DIM)); end; @@ -180,8 +180,8 @@ x(x~=x) = 0; o = sum(x,DIM); if nargout>2, - x = real(x).^2 + imag(x).^2; - SSQ = sum(x,DIM); + x = real(x).^2 + imag(x).^2; + SSQ = sum(x,DIM); end; %!assert(sumskipnan([1,2],1),[1,2]) diff --git a/matlab/missing/corrcoef/tcdf.m b/matlab/missing/corrcoef/tcdf.m index c282e0a174..b3827862a9 100644 --- a/matlab/missing/corrcoef/tcdf.m +++ b/matlab/missing/corrcoef/tcdf.m @@ -11,8 +11,8 @@ function p = tcdf(x,n) % Reference(s): -% $Id: tcdf.m 9033 2011-11-08 20:58:07Z schloegl $ -% Copyright (C) 2000-2003,2009 by Alois Schloegl <alois.schloegl@gmail.com> +% $Id: tcdf.m 9033 2011-11-08 20:58:07Z schloegl $ +% Copyright (C) 2000-2003,2009 by Alois Schloegl <alois.schloegl@gmail.com> % Copyright (C) 2014 Dynare Team % This is part of the NaN-toolbox. For more details see % http://pub.ist.ac.at/~schloegl/matlab/NaN/ @@ -37,7 +37,7 @@ if all(size(x)==1) elseif all(size(n)==1) n = repmat(n,size(x)); elseif all(size(x)==size(n)) - ; %% OK, do nothing + ; %% OK, do nothing else error('size of input arguments must be equal or scalar') end; diff --git a/matlab/missing/ilu/ilu.m b/matlab/missing/ilu/ilu.m index 4b4fe23382..0b8f8df737 100644 --- a/matlab/missing/ilu/ilu.m +++ b/matlab/missing/ilu/ilu.m @@ -18,20 +18,20 @@ function [L, U, P] = ilu(A, setup) % You should have received a copy of the GNU General Public License % along with Dynare. If not, see <http://www.gnu.org/licenses/>. - if nargout ~= 2 - error('Only two output arguments supported') - end - if nargin ~= 2 - error('Only two input arguments supported') - end +if nargout ~= 2 + error('Only two output arguments supported') +end +if nargin ~= 2 + error('Only two input arguments supported') +end + +if isfield(setup, 'milu') + if setup.milu == 'off' + setup.milu = 0; + else + error(['Unsupported milu: ' setup.milu ]) + end +end - if isfield(setup, 'milu') - if setup.milu == 'off' - setup.milu = 0; - else - error(['Unsupported milu: ' setup.milu ]) - end - end - - [L, U] = luinc(A, setup); +[L, U] = luinc(A, setup); end diff --git a/matlab/missing/issquare/issquare.m b/matlab/missing/issquare/issquare.m index 4d4eb2b572..dfbfe89259 100644 --- a/matlab/missing/issquare/issquare.m +++ b/matlab/missing/issquare/issquare.m @@ -46,7 +46,7 @@ function i = issquare(A) d = size(A); if (length(d)==2) && (d(1)==d(2)) - i = d(1); + i = d(1); else - i = 0; + i = 0; end diff --git a/matlab/missing/stats/corr.m b/matlab/missing/stats/corr.m index 21cdda767e..c862e1e671 100644 --- a/matlab/missing/stats/corr.m +++ b/matlab/missing/stats/corr.m @@ -63,12 +63,12 @@ end % Input validation if (nargin==1 && ~(isnumeric (x) || islogical (x))) || ... - (nargin==2 && ~(isnumeric (x) || islogical (x) || isnumeric (y) || islogical (y))) + (nargin==2 && ~(isnumeric (x) || islogical (x) || isnumeric (y) || islogical (y))) error ('corr: X and Y must be numeric matrices or vectors'); end if (nargin==1 && ~ismatrix(x)) || (nargin==2 && (~ismatrix(y) || ~ismatrix(x))) -error ('corr: X and Y must be 2-D matrices or vectors'); + error ('corr: X and Y must be 2-D matrices or vectors'); end if (nargin == 2) diff --git a/matlab/missing/stats/quantile.m b/matlab/missing/stats/quantile.m index ec7dbfa64f..54c77c3f92 100644 --- a/matlab/missing/stats/quantile.m +++ b/matlab/missing/stats/quantile.m @@ -205,34 +205,34 @@ if numel(p)==numel(q) end function cumweights = accumulateWeights(weights, ind, n, N) - % ACCUMULATEWEIGHTS accumulate the weights - wSorted = weights(ind,n); % sort weights - wSorted = wSorted*N/sum(wSorted); % normalize weights to sum to N - cumweights = cumsum(wSorted); % cumulative weights +% ACCUMULATEWEIGHTS accumulate the weights +wSorted = weights(ind,n); % sort weights +wSorted = wSorted*N/sum(wSorted); % normalize weights to sum to N +cumweights = cumsum(wSorted); % cumulative weights function hw = weightedIndex(huw, cumweights) - % WEIGHTEDINDEX calculate index from cumulative weights - ii = find(sign(cumweights-huw)<0,1,'last'); - jj = find(sign(cumweights-huw)>0,1,'first'); - if isempty(ii) || isempty(jj) - hw = huw; - else - hw = ii + (huw-cumweights(ii))/(cumweights(jj)-cumweights(ii)); % weighted index - end +% WEIGHTEDINDEX calculate index from cumulative weights +ii = find(sign(cumweights-huw)<0,1,'last'); +jj = find(sign(cumweights-huw)>0,1,'first'); +if isempty(ii) || isempty(jj) + hw = huw; +else + hw = ii + (huw-cumweights(ii))/(cumweights(jj)-cumweights(ii)); % weighted index +end function y = isint(x) - % ISINT check if input is whole number - y = x==round(x); +% ISINT check if input is whole number +y = x==round(x); function y = rearrange(x,order,shape) - %REARRANGE reshape and permute to make target dim column - y = permute(x,order); - y = reshape(y,shape); +%REARRANGE reshape and permute to make target dim column +y = permute(x,order); +y = reshape(y,shape); function y = irearrange(x,order,shape) - %IREARRANGE reshape and permute to original size - y = reshape(x,shape); - y = ipermute(y,order); +%IREARRANGE reshape and permute to original size +y = reshape(x,shape); +y = ipermute(y,order); %@test:1 diff --git a/matlab/missing_DiffuseKalmanSmootherH1_Z.m b/matlab/missing_DiffuseKalmanSmootherH1_Z.m index a19d3fff63..6595daf67d 100644 --- a/matlab/missing_DiffuseKalmanSmootherH1_Z.m +++ b/matlab/missing_DiffuseKalmanSmootherH1_Z.m @@ -129,7 +129,7 @@ while rank(Pinf(:,:,t+1),diffuse_kalman_tol) && t<smpl Finf = ZZ*Pinf(:,:,t)*ZZ'; % (5.7) in DK (2012) if rcond(Finf) < diffuse_kalman_tol %F_{\infty,t} = 0 if ~all(abs(Finf(:)) < diffuse_kalman_tol) %rank-deficient but not rank 0 - % The univariate diffuse kalman filter should be used. + % The univariate diffuse kalman filter should be used. alphahat = Inf; return else %rank of F_{\infty,t} is 0 @@ -206,7 +206,7 @@ while notsteady && t<smpl atilde(:,t) = a(:,t) + PZI*v(di,t); K(:,di,t) = T*PZI; L(:,:,t) = T-K(:,di,t)*ZZ; - P(:,:,t+1) = T*P(:,:,t)*L(:,:,t)' + QQ; + P(:,:,t+1) = T*P(:,:,t)*L(:,:,t)' + QQ; end a(:,t+1) = T*atilde(:,t); Pf = P(:,:,t); @@ -267,7 +267,7 @@ while t>d+1 end end if d %diffuse periods - % initialize r_d^(0) and r_d^(1) as below DK (2012), eq. 5.23 + % initialize r_d^(0) and r_d^(1) as below DK (2012), eq. 5.23 r0 = zeros(mm,d+1); r0(:,d+1) = r(:,d+1); %set r0_{d}, i.e. shifted by one period r1 = zeros(mm,d+1); %set r1_{d}, i.e. shifted by one period @@ -284,7 +284,7 @@ if d %diffuse periods if ~Finf_singular(1,t) r0(:,t) = Linf(:,:,t)'*r0(:,t+1); % DK (2012), eq. 5.21 where L^(0) is named Linf r1(:,t) = Z(di,:)'*(iFinf(di,di,t)*v(di,t)-Kstar(:,di,t)'*T'*r0(:,t+1)) ... - + Linf(:,:,t)'*r1(:,t+1); % DK (2012), eq. 5.21, noting that i) F^(1)=(F^Inf)^(-1)(see 5.10), ii) where L^(0) is named Linf, and iii) Kstar=T^{-1}*K^(1) + + Linf(:,:,t)'*r1(:,t+1); % DK (2012), eq. 5.21, noting that i) F^(1)=(F^Inf)^(-1)(see 5.10), ii) where L^(0) is named Linf, and iii) Kstar=T^{-1}*K^(1) if state_uncertainty_flag L_1=(-T*Kstar(:,di,t)*Z(di,:)); % noting that Kstar=T^{-1}*K^(1) N(:,:,t)=Linf(:,:,t)'*N(:,:,t+1)*Linf(:,:,t); % DK (2012), eq. 5.19, noting that L^(0) is named Linf @@ -301,7 +301,7 @@ if d %diffuse periods r1(:,t) = T'*r1(:,t+1); % DK (2003), eq. (14) if state_uncertainty_flag N(:,:,t)=Z(di,:)'*iFstar(di,di,t)*Z(di,:)... - +Lstar(:,:,t)'*N(:,:,t+1)*Lstar(:,:,t); % DK (2003), eq. (14) + +Lstar(:,:,t)'*N(:,:,t+1)*Lstar(:,:,t); % DK (2003), eq. (14) N_1(:,:,t)=T'*N_1(:,:,t+1)*Lstar(:,:,t); % DK (2003), eq. (14) N_2(:,:,t)=T'*N_2(:,:,t+1)*T'; % DK (2003), eq. (14) end @@ -311,9 +311,9 @@ if d %diffuse periods etahat(:,t) = QRt*r0(:,t); % DK (2012), p. 135 if state_uncertainty_flag V(:,:,t)=Pstar(:,:,t)-Pstar(:,:,t)*N(:,:,t)*Pstar(:,:,t)... - -(Pinf(:,:,t)*N_1(:,:,t)*Pstar(:,:,t))'... - - Pinf(:,:,t)*N_1(:,:,t)*Pstar(:,:,t)... - - Pinf(:,:,t)*N_2(:,:,t)*Pinf(:,:,t); % DK (2012), eq. 5.30 + -(Pinf(:,:,t)*N_1(:,:,t)*Pstar(:,:,t))'... + - Pinf(:,:,t)*N_1(:,:,t)*Pstar(:,:,t)... + - Pinf(:,:,t)*N_2(:,:,t)*Pinf(:,:,t); % DK (2012), eq. 5.30 end end end diff --git a/matlab/missing_DiffuseKalmanSmootherH3_Z.m b/matlab/missing_DiffuseKalmanSmootherH3_Z.m index b03b13ee0e..665f285323 100644 --- a/matlab/missing_DiffuseKalmanSmootherH3_Z.m +++ b/matlab/missing_DiffuseKalmanSmootherH3_Z.m @@ -81,7 +81,7 @@ function [alphahat,epsilonhat,etahat,a,P,aK,PK,decomp,V] = missing_DiffuseKalman if size(H,2)>1 error('missing_DiffuseKalmanSmootherH3_Z:: H is not a vector. This must not happens') end - + d = 0; decomp = []; spinf = size(Pinf1); @@ -152,8 +152,8 @@ while newRank && t < smpl elseif Fstar(i,t) > kalman_tol a(:,t) = a(:,t) + Kstar(:,i,t)*v(i,t)/Fstar(i,t); % KD (2000), eq. (17) Pstar(:,:,t) = Pstar(:,:,t) - Kstar(:,i,t)*Kstar(:,i,t)'/Fstar(i,t); % KD (2000), eq. (17) - % Pinf is passed through unaltered, see eq. (17) of - % Koopman/Durbin (2000) + % Pinf is passed through unaltered, see eq. (17) of + % Koopman/Durbin (2000) else % do nothing as a_{t,i+1}=a_{t,i} and P_{t,i+1}=P_{t,i}, see % p. 157, DK (2012) @@ -227,7 +227,7 @@ while notsteady && t<smpl end end P(:,:,t+1) = T*P(:,:,t)*T' + QQ; %transition according to (6.14) in DK (2012) - % notsteady = ~(max(max(abs(P(:,:,t+1)-P(:,:,t))))<kalman_tol); + % notsteady = ~(max(max(abs(P(:,:,t+1)-P(:,:,t))))<kalman_tol); end % $$$ P_s=tril(P(:,:,t))+tril(P(:,:,t),-1)'; % $$$ P1_s=tril(P1(:,:,t))+tril(P1(:,:,t),-1)'; @@ -335,9 +335,9 @@ if d etahat(:,t) = QRt*r(:,t); % KD (2000), eq. (27) if state_uncertainty_flag V(:,:,t)=Pstar(:,:,t)-Pstar(:,:,t)*N_0(:,:,t)*Pstar(:,:,t)... - -(Pinf(:,:,t)*N_1(:,:,t)*Pstar(:,:,t))'... - - Pinf(:,:,t)*N_1(:,:,t)*Pstar(:,:,t)... - - Pinf(:,:,t)*N_2(:,:,t)*Pinf(:,:,t); % DK (2012), eq. 5.30 + -(Pinf(:,:,t)*N_1(:,:,t)*Pstar(:,:,t))'... + - Pinf(:,:,t)*N_1(:,:,t)*Pstar(:,:,t)... + - Pinf(:,:,t)*N_2(:,:,t)*Pinf(:,:,t); % DK (2012), eq. 5.30 end if t > 1 r0(:,t-1) = T'*r0(:,t); % KD (2000), below eq. (25) r_{t-1,p_{t-1}}=T'*r_{t,0} diff --git a/matlab/mode_check.m b/matlab/mode_check.m index 3217dbd125..bd003bd8e4 100644 --- a/matlab/mode_check.m +++ b/matlab/mode_check.m @@ -203,7 +203,7 @@ for plt = 1:nbplt, end end if TeX && any(strcmp('eps',cellstr(DynareOptions.graph_format))) - fclose(fidTeX); + fclose(fidTeX); end OutputDirectoryName = CheckPath('modecheck',Model.dname); diff --git a/matlab/model_diagnostics.m b/matlab/model_diagnostics.m index 32a01725d5..5b4b4221eb 100644 --- a/matlab/model_diagnostics.m +++ b/matlab/model_diagnostics.m @@ -108,7 +108,7 @@ for b=1:nb if options.bytecode if nb == 1 [chk, res, jacob] = bytecode(dr.ys, exo, M.params, dr.ys, 1, exo, ... - 'evaluate', 'static'); + 'evaluate', 'static'); else [chk, res, jacob] = bytecode(dr.ys, exo, M.params, dr.ys, 1, exo, ... 'evaluate', 'static',['block=' ... @@ -173,7 +173,7 @@ for b=1:nb end end end - + if singularity_problem try options_check=options; @@ -205,26 +205,26 @@ if ~options.block if options.order == 1 if (options.bytecode) [chck, junk, loc_dr] = bytecode('dynamic','evaluate', z,exo_simul, ... - M.params, dr.ys, 1); + M.params, dr.ys, 1); jacobia_ = [loc_dr.g1 loc_dr.g1_x loc_dr.g1_xd]; else [junk,jacobia_] = feval([M.fname '_dynamic'],z(iyr0),exo_simul, ... - M.params, dr.ys, it_); + M.params, dr.ys, it_); end; elseif options.order >= 2 if (options.bytecode) [chck, junk, loc_dr] = bytecode('dynamic','evaluate', z,exo_simul, ... - M.params, dr.ys, 1); + M.params, dr.ys, 1); jacobia_ = [loc_dr.g1 loc_dr.g1_x]; else [junk,jacobia_,hessian1] = feval([M.fname '_dynamic'],z(iyr0),... - exo_simul, ... - M.params, dr.ys, it_); + exo_simul, ... + M.params, dr.ys, it_); end; if options.use_dll % In USE_DLL mode, the hessian is in the 3-column sparse representation hessian1 = sparse(hessian1(:,1), hessian1(:,2), hessian1(:,3), ... - size(jacobia_, 1), size(jacobia_, 2)*size(jacobia_, 2)); + size(jacobia_, 1), size(jacobia_, 2)*size(jacobia_, 2)); end end diff --git a/matlab/model_info.m b/matlab/model_info.m index d99ca48078..281bfa09ac 100644 --- a/matlab/model_info.m +++ b/matlab/model_info.m @@ -30,14 +30,14 @@ else incidence = 0; end; if static_ - fprintf(' Informations about %s (static model)\n',M_.fname); - block_structre_str = 'block_structure_stat'; - nb_leadlag = 1; - else - fprintf(' Informations about %s (dynamic model)\n',M_.fname); - block_structre_str = 'block_structure'; - nb_leadlag = 3; - end; + fprintf(' Informations about %s (static model)\n',M_.fname); + block_structre_str = 'block_structure_stat'; + nb_leadlag = 1; +else + fprintf(' Informations about %s (dynamic model)\n',M_.fname); + block_structre_str = 'block_structure'; + nb_leadlag = 3; +end; if(isfield(M_,block_structre_str)) if static_ block_structure = M_.block_structure_stat; @@ -136,7 +136,7 @@ if(isfield(M_,block_structre_str)) fprintf('\n Gross incidence matrix\n'); fprintf(' =======================\n'); disp([topp; bott]); - + %printing the reordered incidence matrix IM_star_reordered = char([kron(ones(M_.endo_nbr, M_.endo_nbr-1), double(blanks(3))) double(blanks(M_.endo_nbr)')]); eq(block_structure.equation_reordered) = seq; @@ -201,7 +201,7 @@ if(isfield(M_,block_structre_str)) end; if past_block ~= cur_block for j = 1:i-1 - IM_star_reordered(j, 3 * (i - 1) - 1) = '|'; + IM_star_reordered(j, 3 * (i - 1) - 1) = '|'; end; end; end @@ -211,7 +211,7 @@ if(isfield(M_,block_structre_str)) fprintf(' ==========================\n'); disp([topp; bott]); fprintf('1: non nul element, X: non nul element related to a state variable\n'); - end; + end; else fprintf('There is no block decomposition of the model.\nUse ''block'' model''s option.\n'); end; diff --git a/matlab/model_inversion.m b/matlab/model_inversion.m index 6c873c6550..75594ecca2 100644 --- a/matlab/model_inversion.m +++ b/matlab/model_inversion.m @@ -1,6 +1,6 @@ function [endogenousvariables, exogenousvariables] = model_inversion(constraints, ... - exogenousvariables, ... - initialconditions, DynareModel, DynareOptions, DynareOutput) + exogenousvariables, ... + initialconditions, DynareModel, DynareOptions, DynareOutput) % INPUTS % - constraints [dseries] with N constrained endogenous variables from t1 to t2. diff --git a/matlab/ms-sbvar/clean_files_for_second_type_of_mex.m b/matlab/ms-sbvar/clean_files_for_second_type_of_mex.m index d29b532bfa..5f6d7d43cd 100644 --- a/matlab/ms-sbvar/clean_files_for_second_type_of_mex.m +++ b/matlab/ms-sbvar/clean_files_for_second_type_of_mex.m @@ -34,12 +34,12 @@ if ~strcmp(tagtouse, options_.ms.output_file_tag) end switch type - case 'irf' - clean_ms_irf_files(tagtouse); - case 'forecast' - clean_ms_forecast_files(tagtouse); - case 'variance_decomposition' - clean_ms_variance_decomposition_files(tagtouse); - otherwise - error('clean_files_for_second_type_of_mex: should not arrive here'); + case 'irf' + clean_ms_irf_files(tagtouse); + case 'forecast' + clean_ms_forecast_files(tagtouse); + case 'variance_decomposition' + clean_ms_variance_decomposition_files(tagtouse); + otherwise + error('clean_files_for_second_type_of_mex: should not arrive here'); end diff --git a/matlab/ms-sbvar/dyn_save_graph.m b/matlab/ms-sbvar/dyn_save_graph.m index e3ae96326b..9d7cde0fa6 100644 --- a/matlab/ms-sbvar/dyn_save_graph.m +++ b/matlab/ms-sbvar/dyn_save_graph.m @@ -30,40 +30,40 @@ function dyn_save_graph(dirname,graph_name,graph_formats,TeX,names,texnames,capt % You should have received a copy of the GNU General Public License % along with Dynare. If not, see <http://www.gnu.org/licenses/>. - create_dir(dirname); - graph_name = [dirname filesep regexprep(graph_name,' ','_')]; - if nargin <= 2 - TeX = 0; - elseif nargin <= 4 - names = {}; - texnames = {}; - elseif nargin <= 6 - caption = ''; - end - - if graph_formats.eps || TeX - print([ graph_name '.eps' ],'-depsc2'); - end - if graph_formats.pdf && ~isoctave - print(graph_name,'-dpdf'); - end - if graph_formats.fig && ~isoctave - print(graph_name,'-dfig'); +create_dir(dirname); +graph_name = [dirname filesep regexprep(graph_name,' ','_')]; +if nargin <= 2 + TeX = 0; +elseif nargin <= 4 + names = {}; + texnames = {}; +elseif nargin <= 6 + caption = ''; +end + +if graph_formats.eps || TeX + print([ graph_name '.eps' ],'-depsc2'); +end +if graph_formats.pdf && ~isoctave + print(graph_name,'-dpdf'); +end +if graph_formats.fig && ~isoctave + print(graph_name,'-dfig'); +end + +if TeX + fh = fopen([graph_name '.tex'],'w'); + for i=1:length(names) + fprintf(fh,'\\psfrag{%s}[1][][0.5][0]{%s}\n',names{i},texnames{i}); end - - if TeX - fh = fopen([graph_name '.tex'],'w'); - for i=1:length(names) - fprintf(fh,'\\psfrag{%s}[1][][0.5][0]{%s}\n',names{i},texnames{i}); - end - fprintf(fh,'\\centering \n'); - fprintf(fh,'\\includegraphics[width=0.8\\textwidth]{%s}\n',graph_name); - if caption - fprintf(fh,'\\caption{%s}',caption); - end - fprintf(fh,'\\label{Fig:%s}\n',graph_name); - fprintf(fh,'\\end{figure}\n'); - fprintf(fh,'\n'); - fprintf(fh,'%% End of TeX file.\n'); - fclose(fh); + fprintf(fh,'\\centering \n'); + fprintf(fh,'\\includegraphics[width=0.8\\textwidth]{%s}\n',graph_name); + if caption + fprintf(fh,'\\caption{%s}',caption); end + fprintf(fh,'\\label{Fig:%s}\n',graph_name); + fprintf(fh,'\\end{figure}\n'); + fprintf(fh,'\n'); + fprintf(fh,'%% End of TeX file.\n'); + fclose(fh); +end diff --git a/matlab/ms-sbvar/identification/exclusions.m b/matlab/ms-sbvar/identification/exclusions.m index 5e7d3ef5c0..90df49d225 100644 --- a/matlab/ms-sbvar/identification/exclusions.m +++ b/matlab/ms-sbvar/identification/exclusions.m @@ -47,25 +47,25 @@ np = zeros(nvar,1); k = nlags*nvar+1; for n=1:nvar - Qi{n} = zeros(nvar,nvar); - sQ = size(Qi1{n}); - if all(sQ) > 0 - Qi{n}(1:sQ(1),1:sQ(2)) = Qi1{n}; - end - Ri{n} = zeros(k,k); - sR = size(Ri1{n}); - if all(sR) > 0 - Ri{n}(1:sR(1),1:sR(2)) = Ri1{n}; - end + Qi{n} = zeros(nvar,nvar); + sQ = size(Qi1{n}); + if all(sQ) > 0 + Qi{n}(1:sQ(1),1:sQ(2)) = Qi1{n}; + end + Ri{n} = zeros(k,k); + sR = size(Ri1{n}); + if all(sR) > 0 + Ri{n}(1:sR(1),1:sR(2)) = Ri1{n}; + end - if options_ms.constants_exclusion + if options_ms.constants_exclusion Ri{n}(sR(1)+1,k) = 1; - end + end - Ui{n} = null(Qi{n}); - Vi{n} = null(Ri{n}); - n0(n) = size(Ui{n},2); - np(n) = size(Vi{n},2); + Ui{n} = null(Qi{n}); + Vi{n} = null(Ri{n}); + n0(n) = size(Ui{n},2); + np(n) = size(Vi{n},2); end ixmC0Pres = NaN; \ No newline at end of file diff --git a/matlab/ms-sbvar/identification/lower_cholesky.m b/matlab/ms-sbvar/identification/lower_cholesky.m index 2af96ca9b7..b6054acf64 100644 --- a/matlab/ms-sbvar/identification/lower_cholesky.m +++ b/matlab/ms-sbvar/identification/lower_cholesky.m @@ -41,9 +41,9 @@ Vi = cell(nvar,1); n0 = zeros(nvar,1); np = zeros(nvar,1); if (nargin==2) - nexo = 1; + nexo = 1; elseif (nargin==3) - indxC0Pres = 0; + indxC0Pres = 0; end k = lags*nvar+nexo; Qi = zeros(nvar,nvar,nvar); @@ -62,10 +62,10 @@ if options_ms.constants_exclusion end for n=1:nvar - Ui{n} = null(Qi(:,:,n)); - Vi{n} = null(Ri(:,:,n)); - n0(n) = size(Ui{n},2); - np(n) = size(Vi{n},2); + Ui{n} = null(Qi(:,:,n)); + Vi{n} = null(Ri(:,:,n)); + n0(n) = size(Ui{n},2); + np(n) = size(Vi{n},2); end ixmC0Pres = NaN; \ No newline at end of file diff --git a/matlab/ms-sbvar/identification/upper_cholesky.m b/matlab/ms-sbvar/identification/upper_cholesky.m index 7f4d2027c5..65c403a810 100644 --- a/matlab/ms-sbvar/identification/upper_cholesky.m +++ b/matlab/ms-sbvar/identification/upper_cholesky.m @@ -42,9 +42,9 @@ n0 = zeros(nvar,1); np = zeros(nvar,1); if (nargin==2) - nexo = 1; + nexo = 1; elseif (nargin==3) - indxC0Pres = 0; + indxC0Pres = 0; end k = lags*nvar+nexo; @@ -52,8 +52,8 @@ Qi = zeros(nvar,nvar,nvar); Ri = zeros(k,k,nvar); for ii=2:nvar - Qi(ii-1,ii-1,ii)=1; - Qi(:,:,ii)=Qi(:,:,ii)+Qi(:,:,ii-1); + Qi(ii-1,ii-1,ii)=1; + Qi(:,:,ii)=Qi(:,:,ii)+Qi(:,:,ii-1); end if options_ms.constants_exclusion @@ -63,10 +63,10 @@ if options_ms.constants_exclusion end for n=1:nvar - Ui{n} = null(Qi(:,:,n)); - Vi{n} = null(Ri(:,:,n)); - n0(n) = size(Ui{n},2); - np(n) = size(Vi{n},2); + Ui{n} = null(Qi(:,:,n)); + Vi{n} = null(Ri(:,:,n)); + n0(n) = size(Ui{n},2); + np(n) = size(Vi{n},2); end ixmC0Pres = NaN; \ No newline at end of file diff --git a/matlab/ms-sbvar/ms_estimation.m b/matlab/ms-sbvar/ms_estimation.m index 6d5eec32d7..67b8c34fc5 100644 --- a/matlab/ms-sbvar/ms_estimation.m +++ b/matlab/ms-sbvar/ms_estimation.m @@ -45,7 +45,7 @@ else exist(['matlab_' options_.ms.file_tag '.prn'],'file') ~= 2 || ... exist([options_.ms.file_tag '_markov_file.dat'],'file') ~= 2 error(['You must run ms_estimation without no_create_init as '... - 'you are missing an initialization file it needs.']); + 'you are missing an initialization file it needs.']); end if ~strcmp(options_.ms.file_tag, options_.ms.output_file_tag) clean_ms_estimation_files(options_.ms.output_file_tag); diff --git a/matlab/ms-sbvar/ms_forecast.m b/matlab/ms-sbvar/ms_forecast.m index 55030c9021..e8ed8be20c 100644 --- a/matlab/ms-sbvar/ms_forecast.m +++ b/matlab/ms-sbvar/ms_forecast.m @@ -89,30 +89,30 @@ if options_.ms.regimes for regime_i=1:n_regimes forecast_title = ['Forecast, Regimes ' num2str(regime_i)]; forecast_data = load([forecastdir filesep 'forecasts_percentiles_regime_' ... - num2str(regime_i-1) '_' options_.ms.output_file_tag ... - '.out'], '-ascii'); + num2str(regime_i-1) '_' options_.ms.output_file_tag ... + '.out'], '-ascii'); forecast_data = reshape_ascii_forecast_data(M_.endo_nbr, ... - percentiles_size, options_.ms.horizon, forecast_data); + percentiles_size, options_.ms.horizon, forecast_data); save([forecastdir filesep 'forecast_regime_' num2str(regime_i-1) '.mat'], ... - 'forecast_data'); + 'forecast_data'); plot_ms_forecast(M_, options_, forecast_data, forecast_title); end else if options_.ms.regime forecast_data = load([forecastdir filesep 'forecasts_percentiles_regime_' ... - num2str(options_.ms.regime-1) '_' options_.ms.output_file_tag ... - '.out'], '-ascii'); + num2str(options_.ms.regime-1) '_' options_.ms.output_file_tag ... + '.out'], '-ascii'); forecast_title = ['Forecast, Regime ' num2str(options_.ms.regime)]; save_filename = ['forecast_regime_' num2str(options_.ms.regime-1) '.mat']; else forecast_data = load([forecastdir filesep 'forecasts_percentiles_' ... - options_.ms.output_file_tag '.out'], '-ascii'); + options_.ms.output_file_tag '.out'], '-ascii'); forecast_title = 'Forecast'; save_filename = 'forecast.mat'; end forecast_data = reshape_ascii_forecast_data(M_.endo_nbr, ... - percentiles_size, options_.ms.horizon, forecast_data); + percentiles_size, options_.ms.horizon, forecast_data); save([forecastdir filesep save_filename], 'forecast_data'); plot_ms_forecast(M_, options_, forecast_data, forecast_title); end diff --git a/matlab/ms-sbvar/ms_irf.m b/matlab/ms-sbvar/ms_irf.m index 32718aa29c..9b13aaa5e1 100644 --- a/matlab/ms-sbvar/ms_irf.m +++ b/matlab/ms-sbvar/ms_irf.m @@ -91,34 +91,34 @@ if options_.ms.regimes for regime_i=1:n_regimes irf_title = ['Impulse Responses, Regime ' num2str(regime_i)]; irf_data = load([irfdir filesep 'ir_percentiles_regime_' ... - num2str(regime_i-1) '_' options_.ms.output_file_tag ... - '.out'], '-ascii'); + num2str(regime_i-1) '_' options_.ms.output_file_tag ... + '.out'], '-ascii'); irf_data = reshape_ascii_irf_data(M_.endo_nbr, percentiles_size, ... - options_.ms.horizon, irf_data); + options_.ms.horizon, irf_data); save([irfdir filesep 'irf_regime_' num2str(regime_i-1) '.mat'], 'irf_data'); plot_ms_irf(M_, options_, irf_data, irf_title, varlist); end else if options_.ms.regime irf_data = load([irfdir filesep 'ir_percentiles_regime_' ... - num2str(options_.ms.regime-1) '_' options_.ms.output_file_tag ... - '.out'], '-ascii'); + num2str(options_.ms.regime-1) '_' options_.ms.output_file_tag ... + '.out'], '-ascii'); irf_title = ['Impulse Response, Regime ' num2str(options_.ms.regime)]; save_filename = ['irf_regime_' num2str(options_.ms.regime-1) '.mat']; elseif options_.ms.filtered_probabilities irf_data = load([irfdir filesep 'ir_percentiles_filtered_' ... - options_.ms.output_file_tag '.out'], '-ascii'); + options_.ms.output_file_tag '.out'], '-ascii'); irf_title = 'Impulse Response Filtered'; save_filename = 'irf.mat'; else irf_data = load([irfdir filesep 'ir_percentiles_ergodic_' ... - options_.ms.output_file_tag '.out'], '-ascii'); + options_.ms.output_file_tag '.out'], '-ascii'); irf_title = 'Impulse Response Ergodic'; save_filename = 'irf.mat'; end irf_data = reshape_ascii_irf_data(M_.endo_nbr, percentiles_size, ... - options_.ms.horizon, irf_data); + options_.ms.horizon, irf_data); save([irfdir filesep save_filename], 'irf_data'); plot_ms_irf(M_, options_, irf_data, irf_title, varlist); end diff --git a/matlab/ms-sbvar/ms_mardd.m b/matlab/ms-sbvar/ms_mardd.m index 9932f0186a..f13b614af5 100644 --- a/matlab/ms-sbvar/ms_mardd.m +++ b/matlab/ms-sbvar/ms_mardd.m @@ -25,26 +25,26 @@ function ms_mardd(options_) msstart2 % start the program in which everyhting is initialized through msstart2.m if ~options_.ms.indxestima - warning(' ') - disp('You must set IxEstima=1 in msstart to run this program') - disp('Press ctrl-c to abort now') - pause + warning(' ') + disp('You must set IxEstima=1 in msstart to run this program') + disp('Press ctrl-c to abort now') + pause end A0xhat = zeros(size(A0hat)); Apxhat = zeros(size(Aphat)); if (0) - %Robustness check to see if the same result is obtained with the purterbation of the parameters. - for k=1:nvar - bk = Uiconst{k}'*A0hat(:,k); - gk = Viconst{k}'*Aphat(:,k); - A0xhat(:,k) = Uiconst{k}*(bk + 5.2*randn(size(bk))); % Perturbing the posterior estimate. - Apxhat(:,k) = Viconst{k}*(gk + 5.2*randn(size(gk))); % Perturbing the posterior estimate. - end + %Robustness check to see if the same result is obtained with the purterbation of the parameters. + for k=1:nvar + bk = Uiconst{k}'*A0hat(:,k); + gk = Viconst{k}'*Aphat(:,k); + A0xhat(:,k) = Uiconst{k}*(bk + 5.2*randn(size(bk))); % Perturbing the posterior estimate. + Apxhat(:,k) = Viconst{k}*(gk + 5.2*randn(size(gk))); % Perturbing the posterior estimate. + end else - %At the posterior estimate. - A0xhat = A0hat; % ML estimate of A0 - Apxhat = Aphat; % ML estimate of A+ + %At the posterior estimate. + A0xhat = A0hat; % ML estimate of A0 + Apxhat = Aphat; % ML estimate of A+ end %--- Rename variables. YatYa = yty; @@ -59,40 +59,40 @@ XatXa = xtx; vlog_a0p = 0; Yexpt=0; % exponential term for Y in p(Y|A0,A+) at some point such as the peak Apexpt=0.0; % 0.0 because we have chosen posterior estimate of A+ as A+*. Exponential term for A+ conditional on A0 and Y -%======= Computing the log prior pdf of a0a+ and the exponential term for Y in p(Y|A0,A+). + %======= Computing the log prior pdf of a0a+ and the exponential term for Y in p(Y|A0,A+). for k=1:nvar - a0k = A0xhat(:,k); % meaningful parameters in the kth equation. - apk = Apxhat(:,k); % meaningful parameters in the kth equation. - - %--- Prior settings. - S0bar = H0invtld{k}; %See Claim 2 on p.69b. - Spbar = Hpinvtld{k}; - bk = Uiconst{k}'*a0k; % free parameters in the kth equation. - gk = Viconst{k}'*apk; % free parameters in the kth equation. - gbark = Ptld{k}*bk; % bar: prior - - %--- The exponential term for Y in p(Y|A0,A+) - Yexpt = Yexpt - 0.5*(a0k'*YatYa*a0k - 2*apk'*XatYa*a0k + apk'*XatXa*apk); - %--- The log prior pdf. - vlog_a0p = vlog_a0p - 0.5*(size(Uiconst{k},2)+size(Viconst{k},2))*log(2*pi) + 0.5*log(abs(det(S0bar))) + ... - 0.5*log(abs(det(Spbar))) - 0.5*(bk'*S0bar*bk+(gk-gbark)'*Spbar*(gk-gbark)); - %--- For p(A+|Y,a0) only. - tmpd = gk - Pmat{k}*bk; - Apexpt = Apexpt - 0.5*tmpd'*(Hpinv{k}*tmpd); + a0k = A0xhat(:,k); % meaningful parameters in the kth equation. + apk = Apxhat(:,k); % meaningful parameters in the kth equation. + + %--- Prior settings. + S0bar = H0invtld{k}; %See Claim 2 on p.69b. + Spbar = Hpinvtld{k}; + bk = Uiconst{k}'*a0k; % free parameters in the kth equation. + gk = Viconst{k}'*apk; % free parameters in the kth equation. + gbark = Ptld{k}*bk; % bar: prior + + %--- The exponential term for Y in p(Y|A0,A+) + Yexpt = Yexpt - 0.5*(a0k'*YatYa*a0k - 2*apk'*XatYa*a0k + apk'*XatXa*apk); + %--- The log prior pdf. + vlog_a0p = vlog_a0p - 0.5*(size(Uiconst{k},2)+size(Viconst{k},2))*log(2*pi) + 0.5*log(abs(det(S0bar))) + ... + 0.5*log(abs(det(Spbar))) - 0.5*(bk'*S0bar*bk+(gk-gbark)'*Spbar*(gk-gbark)); + %--- For p(A+|Y,a0) only. + tmpd = gk - Pmat{k}*bk; + Apexpt = Apexpt - 0.5*tmpd'*(Hpinv{k}*tmpd); end vlog_a0p %--------- The log value of p(Y|A0,A+) at some point such as the peak. ---------- %--------- Note that logMarLHres is the same as vlog_Y_a, just to double check. ---------- vlog_Y_a = -0.5*nvar*fss*log(2*pi) + fss*log(abs(det(A0xhat))) + Yexpt - % a: given a0 and a+ +% a: given a0 and a+ logMarLHres = 0; % Initialize log of the marginal likelihood (restricted or constant parameters). for ki=1:fss %ndobs+1:fss % Forward recursion to get the marginal likelihood. See F on p.19 and pp. 48-49. - %---- Restricted log marginal likelihood function (constant parameters). - [A0l,A0u] = lu(A0xhat); - ada = sum(log(abs(diag(A0u)))); % log|A0| - termexp = y(ki,:)*A0xhat - phi(ki,:)*Apxhat; % 1-by-nvar - logMarLHres = logMarLHres - (0.5*nvar)*log(2*pi) + ada - 0.5*termexp*termexp'; % log value + %---- Restricted log marginal likelihood function (constant parameters). + [A0l,A0u] = lu(A0xhat); + ada = sum(log(abs(diag(A0u)))); % log|A0| + termexp = y(ki,:)*A0xhat - phi(ki,:)*Apxhat; % 1-by-nvar + logMarLHres = logMarLHres - (0.5*nvar)*log(2*pi) + ada - 0.5*termexp*termexp'; % log value end logMarLHres @@ -101,8 +101,8 @@ logMarLHres totparsp = 0.0; tmpd = 0.0; for k=1:nvar - totparsp = totparsp + size(Viconst{k},2); - tmpd = tmpd + 0.5*log(abs(det(Hpinv{k}))); + totparsp = totparsp + size(Viconst{k},2); + tmpd = tmpd + 0.5*log(abs(det(Hpinv{k}))); end vlog_ap_Ya0 = -0.5*totparsp*log(2*pi) + tmpd + Apexpt; @@ -117,65 +117,65 @@ vlog_ap_Ya0 = -0.5*totparsp*log(2*pi) + tmpd + Apexpt; [Tinv,UT] = fn_gibbsrvar_setup(H0inv, Uiconst, Hpinv, Pmat, Viconst, nvar, fss); % vlog_a0_Yao = zeros(nvar,1); - % the log value of p(a0k|Y,ao) where ao: other a's at some point such as the peak of ONLY some a0's +% the log value of p(a0k|Y,ao) where ao: other a's at some point such as the peak of ONLY some a0's vlog=zeros(ndraws2,1); for k=1:nvar - bk = Uiconst{k}'*A0xhat(:,k); - indx_ks=[k:nvar]; % the columns that exclude 1-(k-1)th columns - A0gbs0 = A0hat; % starting at some point such as the peak - nk = n0(k); - - if k<nvar - %--------- The 1st set of draws to be tossed away. ------------------ - for draws = 1:ndraws1 - if ~mod(draws,nbuffer) - skipline() - disp(sprintf('The %dth column or equation in A0 with %d 1st tossed-away draws in Gibbs',k,draws)) - end - A0gbs1 = fn_gibbsrvar(A0gbs0,UT,nvar,fss,n0,indx_ks); - A0gbs0=A0gbs1; % repeat the Gibbs sampling - end - - - %--------- The 2nd set of draws to be used. ------------------ - for draws = 1:ndraws2 - if ~mod(draws,nbuffer) - skipline() - disp(sprintf('The %dth column or equation in A0 with %d usable draws in Gibbs',k,draws)) - end - [A0gbs1, Wcell] = fn_gibbsrvar(A0gbs0,UT,nvar,fss,n0,indx_ks); - %------ See p.71, Forecast (II). - %------ Computing p(a0_k|Y,a_others) at some point such as the peak along the dimensions of indx_ks. - Vk = Tinv{k}\Wcell{k}; %V_k on p.71 of Forecast (II). - gbeta = Vk\bk; % inv(V_k)*b_k on p.71 of Forecast (II) where alpha_k = b_k in our notation. - [Vtq,Vtr]=qr(Vk',0); %To get inv(V_k)'*inv(V_k) in (*) on p.71 of Forecast (II). - % - vlog(draws) = 0.5*(fss+nk)*log(fss)-log(abs(det(Vk)))-0.5*(nk-1)*log(2*pi)-... - 0.5*(fss+1)*log(2)-gammaln(0.5*(fss+1))+fss*log(abs(gbeta(1)))-... - 0.5*fss*bk'*(Vtr\(Vtr'\bk)); - - A0gbs0=A0gbs1; % repeat the Gibbs sampling - end - vlogm=max(vlog); - qlog=vlog-vlogm; - vlogxhat=vlogm-log(ndraws2)+log(sum(exp(qlog))); - vlog_a0_Yao(k) = vlogxhat; - % The log value of p(a0_k|Y,a_others) where a_others: other a's at some point such as the peak of ONLY some a0's - else - skipline() - disp(sprintf('The last(6th) column or equation in A0 with no Gibbs draws')) - [A0gbs1, Wcell] = fn_gibbsrvar(A0gbs0,UT,nvar,fss,n0,indx_ks) - %------ See p.71, Forecast (II). - %------ Computing p(a0_k|Y,a_others) at some point such as the peak along the dimensions of indx_ks. - Vk = Tinv{k}\Wcell{k}; %V_k on p.71 of Forecast (II). - gbeta = Vk\bk; % inv(V_k)*b_k on p.71 of Forecast (II) where alpha_k = b_k in our notation. - [Vtq,Vtr]=qr(Vk',0); %To get inv(V_k)'*inv(V_k) in (*) on p.71 of Forecast (II). - % - vloglast = 0.5*(fss+nk)*log(fss)-log(abs(det(Vk)))-0.5*(nk-1)*log(2*pi)-... - 0.5*(fss+1)*log(2)-gammaln(0.5*(fss+1))+fss*log(abs(gbeta(1)))-... - 0.5*fss*bk'*(Vtr\(Vtr'\bk)); - vlog_a0_Yao(k) = vloglast; - end + bk = Uiconst{k}'*A0xhat(:,k); + indx_ks=[k:nvar]; % the columns that exclude 1-(k-1)th columns + A0gbs0 = A0hat; % starting at some point such as the peak + nk = n0(k); + + if k<nvar + %--------- The 1st set of draws to be tossed away. ------------------ + for draws = 1:ndraws1 + if ~mod(draws,nbuffer) + skipline() + disp(sprintf('The %dth column or equation in A0 with %d 1st tossed-away draws in Gibbs',k,draws)) + end + A0gbs1 = fn_gibbsrvar(A0gbs0,UT,nvar,fss,n0,indx_ks); + A0gbs0=A0gbs1; % repeat the Gibbs sampling + end + + + %--------- The 2nd set of draws to be used. ------------------ + for draws = 1:ndraws2 + if ~mod(draws,nbuffer) + skipline() + disp(sprintf('The %dth column or equation in A0 with %d usable draws in Gibbs',k,draws)) + end + [A0gbs1, Wcell] = fn_gibbsrvar(A0gbs0,UT,nvar,fss,n0,indx_ks); + %------ See p.71, Forecast (II). + %------ Computing p(a0_k|Y,a_others) at some point such as the peak along the dimensions of indx_ks. + Vk = Tinv{k}\Wcell{k}; %V_k on p.71 of Forecast (II). + gbeta = Vk\bk; % inv(V_k)*b_k on p.71 of Forecast (II) where alpha_k = b_k in our notation. + [Vtq,Vtr]=qr(Vk',0); %To get inv(V_k)'*inv(V_k) in (*) on p.71 of Forecast (II). + % + vlog(draws) = 0.5*(fss+nk)*log(fss)-log(abs(det(Vk)))-0.5*(nk-1)*log(2*pi)-... + 0.5*(fss+1)*log(2)-gammaln(0.5*(fss+1))+fss*log(abs(gbeta(1)))-... + 0.5*fss*bk'*(Vtr\(Vtr'\bk)); + + A0gbs0=A0gbs1; % repeat the Gibbs sampling + end + vlogm=max(vlog); + qlog=vlog-vlogm; + vlogxhat=vlogm-log(ndraws2)+log(sum(exp(qlog))); + vlog_a0_Yao(k) = vlogxhat; + % The log value of p(a0_k|Y,a_others) where a_others: other a's at some point such as the peak of ONLY some a0's + else + skipline() + disp(sprintf('The last(6th) column or equation in A0 with no Gibbs draws')) + [A0gbs1, Wcell] = fn_gibbsrvar(A0gbs0,UT,nvar,fss,n0,indx_ks) + %------ See p.71, Forecast (II). + %------ Computing p(a0_k|Y,a_others) at some point such as the peak along the dimensions of indx_ks. + Vk = Tinv{k}\Wcell{k}; %V_k on p.71 of Forecast (II). + gbeta = Vk\bk; % inv(V_k)*b_k on p.71 of Forecast (II) where alpha_k = b_k in our notation. + [Vtq,Vtr]=qr(Vk',0); %To get inv(V_k)'*inv(V_k) in (*) on p.71 of Forecast (II). + % + vloglast = 0.5*(fss+nk)*log(fss)-log(abs(det(Vk)))-0.5*(nk-1)*log(2*pi)-... + 0.5*(fss+1)*log(2)-gammaln(0.5*(fss+1))+fss*log(abs(gbeta(1)))-... + 0.5*fss*bk'*(Vtr\(Vtr'\bk)); + vlog_a0_Yao(k) = vloglast; + end end ndraws2 diff --git a/matlab/ms-sbvar/ms_sbvar_setup.m b/matlab/ms-sbvar/ms_sbvar_setup.m index 181a6f7d2e..40e01decb3 100644 --- a/matlab/ms-sbvar/ms_sbvar_setup.m +++ b/matlab/ms-sbvar/ms_sbvar_setup.m @@ -29,7 +29,7 @@ function ms_sbvar_setup(options_) % along with Dynare. If not, see <http://www.gnu.org/licenses/>. options_.data = read_variables(options_.datafile, ... - options_.varobs, [], options_.xls_sheet, options_.xls_range); + options_.varobs, [], options_.xls_sheet, options_.xls_range); [options_.ms.final_year,options_.ms.final_subperiod] = check_datafile_years_assigned(options_); if options_.ms.upper_cholesky @@ -277,10 +277,10 @@ else if indxC0Pres Fhatur0P = Fhat; % ur: unrestriced across A0 and A+ for ki = 1:size(ixmC0Pres,1) % loop through the number of equations in which - % cross-A0-A+ restrictions occur. See St. Louis Note p.5. + % cross-A0-A+ restrictions occur. See St. Louis Note p.5. ixeq = ixmC0Pres{ki}(1,1); % index for the jth equation in consideration. Lit = Vi{ixeq}(ixmC0Pres{ki}(:,2),:); % transposed restriction matrix Li - % V_j(i,:) in f_j(i) = V_j(i,:)*g_j + % V_j(i,:) in f_j(i) = V_j(i,:)*g_j ci = ixmC0Pres{ki}(:,4) .* A0hat(ixmC0Pres{ki}(:,3),ixeq); % s * a_j(h) in the restriction f_j(i) = s * a_j(h). LtH = Lit/Hpinv{ixeq}; diff --git a/matlab/ms-sbvar/ms_variance_decomposition.m b/matlab/ms-sbvar/ms_variance_decomposition.m index 553488acd1..83e270171a 100644 --- a/matlab/ms-sbvar/ms_variance_decomposition.m +++ b/matlab/ms-sbvar/ms_variance_decomposition.m @@ -85,7 +85,7 @@ if options_.ms.regime || options_.ms.regimes outfile = [outfile 'regime_']; if options_.ms.regime outfile = [outfile num2str(options_.ms.regime-1) ... - '_' options_.ms.output_file_tag '.out']; + '_' options_.ms.output_file_tag '.out']; end elseif options_.ms.filtered_probabilities outfile = [outfile 'filtered_' options_.ms.output_file_tag '.out']; @@ -103,7 +103,7 @@ if options_.ms.regimes for regime_i=1:n_regimes vd_title = ['Variance Decomposition, Regime ' num2str(regime_i)]; vd_data = load([outfile num2str(regime_i-1) '_' ... - options_.ms.output_file_tag '.out'], '-ascii'); + options_.ms.output_file_tag '.out'], '-ascii'); vd_data = reshape_ascii_variance_decomposition_data( ... M_.endo_nbr, percentiles_size, options_.ms.horizon, vd_data); save([vddir filesep 'variance_decomposition_regime_' num2str(regime_i-1) '.mat'], 'vd_data'); diff --git a/matlab/ms-sbvar/ms_write_markov_file.m b/matlab/ms-sbvar/ms_write_markov_file.m index 02b934a3e7..630cfd570c 100644 --- a/matlab/ms-sbvar/ms_write_markov_file.m +++ b/matlab/ms-sbvar/ms_write_markov_file.m @@ -27,136 +27,136 @@ function ms_write_markov_file(fname, options) % You should have received a copy of the GNU General Public License % along with Dynare. If not, see <http://www.gnu.org/licenses/>. - n_chains = length(options.ms.ms_chain); - nvars = length(options.varobs); - - fh = fopen(fname,'w'); - %/******************************************************************************/ - %/********************* Markov State Variable Information **********************/ - %/******************************************************************************/ - - fprintf(fh,'//== Markov State Variables with Simple Restrictions ==//\n\n'); - - - %//This number is NOT used but read in. - fprintf(fh,'//== Number Observations ==//\n'); - fprintf(fh,'0\n\n'); +n_chains = length(options.ms.ms_chain); +nvars = length(options.varobs); - fprintf(fh,'//== Number independent state variables ==//\n'); - fprintf(fh,'%d\n\n',n_chains); +fh = fopen(fname,'w'); +%/******************************************************************************/ +%/********************* Markov State Variable Information **********************/ +%/******************************************************************************/ - for i_chain = 1:n_chains +fprintf(fh,'//== Markov State Variables with Simple Restrictions ==//\n\n'); - %//=====================================================// - %//== state_variable[i] (1 <= i <= n_state_variables) ==// - %//=====================================================// - fprintf(fh,'//== Number of states for state_variable[%d] ==//\n', ... - i_chain); - n_states = length(options.ms.ms_chain(i_chain).regime); - fprintf(fh,'%d\n\n',n_states); - - %//== 03/15/06: DW TVBVAR code reads the data below and overwrite the prior data read somewhere else if any. - %//== Each column contains the parameters for a Dirichlet prior on the corresponding - %//== column of the transition matrix. Each element must be positive. For each column, - %//== the relative size of the prior elements determine the relative size of the elements - %//== of the transition matrix and overall larger sizes implies a tighter prior. - fprintf(fh,['//== Transition matrix prior for state_variable[%d] ==//\n'], ... - i_chain); - Alpha = ones(n_states,n_states); - for i_state = 1:n_states - p = 1-1/options.ms.ms_chain(i_chain).regime(i_state).duration; - Alpha(i_state,i_state) = p*(n_states-1)/(1-p); - fprintf(fh,'%22.16f',Alpha(i_state,:)); - fprintf(fh,'\n'); + +%//This number is NOT used but read in. +fprintf(fh,'//== Number Observations ==//\n'); +fprintf(fh,'0\n\n'); + +fprintf(fh,'//== Number independent state variables ==//\n'); +fprintf(fh,'%d\n\n',n_chains); + +for i_chain = 1:n_chains + + %//=====================================================// + %//== state_variable[i] (1 <= i <= n_state_variables) ==// + %//=====================================================// + fprintf(fh,'//== Number of states for state_variable[%d] ==//\n', ... + i_chain); + n_states = length(options.ms.ms_chain(i_chain).regime); + fprintf(fh,'%d\n\n',n_states); + + %//== 03/15/06: DW TVBVAR code reads the data below and overwrite the prior data read somewhere else if any. + %//== Each column contains the parameters for a Dirichlet prior on the corresponding + %//== column of the transition matrix. Each element must be positive. For each column, + %//== the relative size of the prior elements determine the relative size of the elements + %//== of the transition matrix and overall larger sizes implies a tighter prior. + fprintf(fh,['//== Transition matrix prior for state_variable[%d] ==//\n'], ... + i_chain); + Alpha = ones(n_states,n_states); + for i_state = 1:n_states + p = 1-1/options.ms.ms_chain(i_chain).regime(i_state).duration; + Alpha(i_state,i_state) = p*(n_states-1)/(1-p); + fprintf(fh,'%22.16f',Alpha(i_state,:)); + fprintf(fh,'\n'); + end + + fprintf(fh,['\n//== Dirichlet dimensions for state_variable[%d] ' ... + '==//\n'],i_chain); + % fprintf(fh,'%d ',repmat(n_states,1,n_states)); + fprintf(fh,'%d ',repmat(2,1,n_states)); + fprintf(fh,'\n\n'); + + %//== The jth restriction matrix is n_states-by-free[j]. Each row of the restriction + %//== matrix has exactly one non-zero entry and the sum of each column must be one. + fprintf(fh,['//== Column restrictions for state_variable[%d] ' ... + '==//\n'],i_chain); + for i_state = 1:n_states + if i_state == 1 + M = eye(n_states,2); + elseif i_state == n_states + M = [zeros(n_states-2,2); eye(2)]; + else + M = zeros(n_states,2); + M(i_state+[-1 1],1) = ones(2,1)/2; + M(i_state,2) = 1; + disp(M) end - - fprintf(fh,['\n//== Dirichlet dimensions for state_variable[%d] ' ... - '==//\n'],i_chain); - % fprintf(fh,'%d ',repmat(n_states,1,n_states)); - fprintf(fh,'%d ',repmat(2,1,n_states)); - fprintf(fh,'\n\n'); - - %//== The jth restriction matrix is n_states-by-free[j]. Each row of the restriction - %//== matrix has exactly one non-zero entry and the sum of each column must be one. - fprintf(fh,['//== Column restrictions for state_variable[%d] ' ... - '==//\n'],i_chain); - for i_state = 1:n_states - if i_state == 1 - M = eye(n_states,2); - elseif i_state == n_states - M = [zeros(n_states-2,2); eye(2)]; - else - M = zeros(n_states,2); - M(i_state+[-1 1],1) = ones(2,1)/2; - M(i_state,2) = 1; - disp(M) - end - for j_state = 1:n_states - fprintf(fh,'%f ',M(j_state,:)); - fprintf(fh,'\n'); - end + for j_state = 1:n_states + fprintf(fh,'%f ',M(j_state,:)); fprintf(fh,'\n'); end + fprintf(fh,'\n'); end +end - %/******************************************************************************/ - %/******************************* VAR Parameters *******************************/ - %/******************************************************************************/ - %//NOT read - fprintf(fh,'//== Number Variables ==//\n'); - fprintf(fh,'%d\n\n',nvars); +%/******************************************************************************/ +%/******************************* VAR Parameters *******************************/ +%/******************************************************************************/ +%//NOT read +fprintf(fh,'//== Number Variables ==//\n'); +fprintf(fh,'%d\n\n',nvars); - %//NOT read - fprintf(fh,'//== Number Lags ==//\n'); - fprintf(fh,'%d\n\n',options.ms.nlags); +%//NOT read +fprintf(fh,'//== Number Lags ==//\n'); +fprintf(fh,'%d\n\n',options.ms.nlags); - %//NOT read - fprintf(fh,'//== Exogenous Variables ==//\n'); - fprintf(fh,'1\n\n'); +%//NOT read +fprintf(fh,'//== Exogenous Variables ==//\n'); +fprintf(fh,'1\n\n'); - %//== nvar x n_state_variables matrix. In the jth row, a non-zero value implies that - %this state variable controls the jth column of A0 and Aplus - fprintf(fh,['//== Controlling states variables for coefficients ==//\' ... - 'n']); - - for i_var = 1:nvars - for i_chain = 1:n_chains - if ~isfield(options.ms.ms_chain(i_chain),'svar_coefficients') ... - || isempty(options.ms.ms_chain(i_chain).svar_coefficients) - i_equations = 0; - else - i_equations = ... - options.ms.ms_chain(i_chain).svar_coefficients.equations; - end - if strcmp(i_equations,'ALL') || any(i_equations == i_var) - fprintf(fh,'%d ',1); - else - fprintf(fh,'%d ',0); - end +%//== nvar x n_state_variables matrix. In the jth row, a non-zero value implies that +%this state variable controls the jth column of A0 and Aplus +fprintf(fh,['//== Controlling states variables for coefficients ==//\' ... + 'n']); + +for i_var = 1:nvars + for i_chain = 1:n_chains + if ~isfield(options.ms.ms_chain(i_chain),'svar_coefficients') ... + || isempty(options.ms.ms_chain(i_chain).svar_coefficients) + i_equations = 0; + else + i_equations = ... + options.ms.ms_chain(i_chain).svar_coefficients.equations; + end + if strcmp(i_equations,'ALL') || any(i_equations == i_var) + fprintf(fh,'%d ',1); + else + fprintf(fh,'%d ',0); end - fprintf(fh,'\n'); end + fprintf(fh,'\n'); +end - %//== nvar x n_state_variables matrix. In the jth row, a non-zero value implies that - %this state variable controls the jth diagonal element of Xi - fprintf(fh,'\n//== Controlling states variables for variance ==//\n'); - for i_var = 1:nvars - for i_chain = 1:n_chains - if ~isfield(options.ms.ms_chain(i_chain),'svar_variances') ... - || isempty(options.ms.ms_chain(i_chain).svar_variances) - i_equations = 0; - else - i_equations = ... - options.ms.ms_chain(i_chain).svar_variances.equations; - end - if strcmp(i_equations,'ALL') || any(i_equations == i_var) - fprintf(fh,'%d ',1); - else - fprintf(fh,'%d ',0); - end +%//== nvar x n_state_variables matrix. In the jth row, a non-zero value implies that +%this state variable controls the jth diagonal element of Xi +fprintf(fh,'\n//== Controlling states variables for variance ==//\n'); +for i_var = 1:nvars + for i_chain = 1:n_chains + if ~isfield(options.ms.ms_chain(i_chain),'svar_variances') ... + || isempty(options.ms.ms_chain(i_chain).svar_variances) + i_equations = 0; + else + i_equations = ... + options.ms.ms_chain(i_chain).svar_variances.equations; + end + if strcmp(i_equations,'ALL') || any(i_equations == i_var) + fprintf(fh,'%d ',1); + else + fprintf(fh,'%d ',0); end - fprintf(fh,'\n'); end + fprintf(fh,'\n'); +end - fclose(fh); +fclose(fh); diff --git a/matlab/ms-sbvar/ms_write_mhm_input.m b/matlab/ms-sbvar/ms_write_mhm_input.m index 57854d59ae..1edd4b4a2d 100644 --- a/matlab/ms-sbvar/ms_write_mhm_input.m +++ b/matlab/ms-sbvar/ms_write_mhm_input.m @@ -28,41 +28,41 @@ function ms_write_mhm_input(fname, options_ms) % You should have received a copy of the GNU General Public License % along with Dynare. If not, see <http://www.gnu.org/licenses/>. - fh = fopen(fname,'w'); +fh = fopen(fname,'w'); - fprintf(fh,'/**********************************************************\n'); - fprintf(fh,' *** This input file is read by swzmsbvar_mhm_1 and swzmsbvar_mhm_1.exe only, NOT by swzmsbvar_printdraws.exe.\n'); - fprintf(fh,' ***\n'); - fprintf(fh,' **********************************************************/\n'); +fprintf(fh,'/**********************************************************\n'); +fprintf(fh,' *** This input file is read by swzmsbvar_mhm_1 and swzmsbvar_mhm_1.exe only, NOT by swzmsbvar_printdraws.exe.\n'); +fprintf(fh,' ***\n'); +fprintf(fh,' **********************************************************/\n'); - fprintf(fh,'\n\n//------------- 1st set of posterior draws to find optimal scales for Metropolis (30000). ---------------\n'); - fprintf(fh,'//== number draws for first burn-in ==// //For determining the Metropolis scales only.\n'); - fprintf(fh,'%d\n\n',options_ms.draws_nbr_burn_in_1); +fprintf(fh,'\n\n//------------- 1st set of posterior draws to find optimal scales for Metropolis (30000). ---------------\n'); +fprintf(fh,'//== number draws for first burn-in ==// //For determining the Metropolis scales only.\n'); +fprintf(fh,'%d\n\n',options_ms.draws_nbr_burn_in_1); - fprintf(fh,'//------------- MCMC burn-in draws once the Metropolis scales (previous stage) are fixed. --------------\n'); - fprintf(fh,'//------------- 2nd set of standard burn-in posterior draws to throw away the initial draws (10000). ---------------\n'); - fprintf(fh,'//== number draws for second burn-in ==//\n'); - fprintf(fh,'%d\n\n',options_ms.draws_nbr_burn_in_2); +fprintf(fh,'//------------- MCMC burn-in draws once the Metropolis scales (previous stage) are fixed. --------------\n'); +fprintf(fh,'//------------- 2nd set of standard burn-in posterior draws to throw away the initial draws (10000). ---------------\n'); +fprintf(fh,'//== number draws for second burn-in ==//\n'); +fprintf(fh,'%d\n\n',options_ms.draws_nbr_burn_in_2); - fprintf(fh,'//--------------- 1st set of posterior draws to compute the mean and variance for the weighting function in the MHM (200000) ----------------\n'); - fprintf(fh,'//== number draws to estimate mean and variance ==//\n'); - fprintf(fh,'%d\n\n',options_ms.draws_nbr_mean_var_estimate); +fprintf(fh,'//--------------- 1st set of posterior draws to compute the mean and variance for the weighting function in the MHM (200000) ----------------\n'); +fprintf(fh,'//== number draws to estimate mean and variance ==//\n'); +fprintf(fh,'%d\n\n',options_ms.draws_nbr_mean_var_estimate); - fprintf(fh,'//--------------- Only applied to mhm_2 process: total number of MCMC draws = thinning factor * 2nd set of saved posterior draws ----------------\n'); - fprintf(fh,'//== thinning factor for modified harmonic mean process ==//\n'); - fprintf(fh,'%d\n\n',options_ms.thinning_factor); +fprintf(fh,'//--------------- Only applied to mhm_2 process: total number of MCMC draws = thinning factor * 2nd set of saved posterior draws ----------------\n'); +fprintf(fh,'//== thinning factor for modified harmonic mean process ==//\n'); +fprintf(fh,'%d\n\n',options_ms.thinning_factor); - fprintf(fh,'//--------------- 2nd set of saved posterior draws from MHM_2 (second stage): saved draws AFTER thinning (1000000) ----------------\n'); - fprintf(fh,'//== number draws for modified harmonic mean process ==//\n'); - fprintf(fh,'%d\n\n',options_ms.draws_nbr_modified_harmonic_mean); +fprintf(fh,'//--------------- 2nd set of saved posterior draws from MHM_2 (second stage): saved draws AFTER thinning (1000000) ----------------\n'); +fprintf(fh,'//== number draws for modified harmonic mean process ==//\n'); +fprintf(fh,'%d\n\n',options_ms.draws_nbr_modified_harmonic_mean); - fprintf(fh,'//------- 1st stage: computing all three tightness factors for Dirichlet. ---------\n'); - fprintf(fh,'//------- 2nd stage: hard-code the second scale factor (in principle, we can do all three). ---------\n'); - fprintf(fh,'//------- It seems that Dan''s code only use the first element of the following scales. The scale applies to the Dirichlet''s hyperparameter alpha for the diagonal of the transition matrix in the weighting function. Note that the weighting function for the transition matrix parameters is Dirichlet. ---------\n'); - - fprintf(fh,'//== scale values for Dirichlet distribution ==//\n'); - fprintf(fh,'3\n\n'); - fprintf(fh,'%f ',options_ms.dirichlet_scale); - fprintf(fh,'\n'); - fclose(fh); \ No newline at end of file +fprintf(fh,'//------- 1st stage: computing all three tightness factors for Dirichlet. ---------\n'); +fprintf(fh,'//------- 2nd stage: hard-code the second scale factor (in principle, we can do all three). ---------\n'); +fprintf(fh,'//------- It seems that Dan''s code only use the first element of the following scales. The scale applies to the Dirichlet''s hyperparameter alpha for the diagonal of the transition matrix in the weighting function. Note that the weighting function for the transition matrix parameters is Dirichlet. ---------\n'); + +fprintf(fh,'//== scale values for Dirichlet distribution ==//\n'); +fprintf(fh,'3\n\n'); +fprintf(fh,'%f ',options_ms.dirichlet_scale); +fprintf(fh,'\n'); +fclose(fh); \ No newline at end of file diff --git a/matlab/ms-sbvar/msstart2.m b/matlab/ms-sbvar/msstart2.m index 6fa5861cd9..aee78c03dd 100644 --- a/matlab/ms-sbvar/msstart2.m +++ b/matlab/ms-sbvar/msstart2.m @@ -45,17 +45,17 @@ msstart_setup %options_.ms.Indxcol = [1:nvar]; % a vector of random columns in which MC draws are made. % %options_.ms.indxparr = 1; % 1: parameters random; 0: no randomness in parameters - % Note, when 0, there is no effect from the values of options_.ms.IndxAp, options_.ms.Aband, etc. +% Note, when 0, there is no effect from the values of options_.ms.IndxAp, options_.ms.Aband, etc. %options_.ms.indxovr = 0; % 1: distributions for other variables of interest; 0: no distribution. - % Example: joint distribution of a(1) and a(2). Only for specific purposes +% Example: joint distribution of a(1) and a(2). Only for specific purposes %options_.ms.Aband = 1; % 1: error bands with only A0 and A+ random. %options_.ms.IndxAp = 1; % 1: generate draws of A+; 0: no such draws. - % Note: when options_.ms.IndxAp=0, there is no effect from the values of options_.ms.options_.ms.options_.ms.options_.ms.indximf, IndxFore, - % or options_.ms.apband. +% Note: when options_.ms.IndxAp=0, there is no effect from the values of options_.ms.options_.ms.options_.ms.options_.ms.indximf, IndxFore, +% or options_.ms.apband. %options_.ms.apband = 1; % 1: error bands for A+; 0: no error bands for A+. %*** The following (impulse responses and forecasts) is used only if options_.ms.IndxAp=1 %options_.ms.indximf = 1; % 1: generate draws of impulse responses; 0: no such draws (thus no effect - % from options_.ms.imfband) +% from options_.ms.imfband) %options_.ms.imfband = 1; % 1: error bands for impulse responses; 0: no error bands %options_.ms.indxfore = 0; % 1: generate draws of forecasts; 0: no such draws (thus no effect from options_.ms.foreband) %options_.ms.foreband = 0; % 1: error bands for out-of-sample forecasts; 0: no error bands @@ -64,23 +64,23 @@ msstart_setup rnum = nvar; % number of rows in the graph cnum = 1; % number of columns in the graph if rnum*cnum<nvar - warning('rnum*cnum must be at least as large as nvar') - disp('Hit any key to continue, or ctrl-c to abort') - pause + warning('rnum*cnum must be at least as large as nvar') + disp('Hit any key to continue, or ctrl-c to abort') + pause end %options_.ms.indxgimfhat = 1; % 1: plot ML impulse responses; 0: no plot %options_.ms.indxestima = 1; %1: ML estimation; 0: no estimation and data only % IndxNmlr = [1 0 0 0 0 0]; % imported by nmlzvar.m - % 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 let A0inu=[]) - % IndxNmlr(6): Assigned postive rule (such as off-diagonal elements). Added 1/3/00 + % 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 let A0inu=[]) + % IndxNmlr(6): Assigned postive rule (such as off-diagonal elements). Added 1/3/00 %%%%---------------------------------------- @@ -90,7 +90,7 @@ IndxNmlr = [1 0 0 0 0 0]; % imported by nmlzvar.m nconstr1=nfqm; % number of the 1st set of constraints nconstr2=options_.forecast ; % number of the 2nd set of constraints nconstr=nconstr1+nconstr2; % q: 4 years -- 4*12 months. - % When 0, no conditions directly on variables <<>> + % When 0, no conditions directly on variables <<>> nconstr=0 ; %6*nconstr1; options_.ms.eq_ms = []; % location of MS equation; if [], all shocks PorR = [4*ones(nconstr1,1);2*ones(nconstr1,1);3*ones(nconstr1,1)]; % the variable conditioned. 1: Pcm; 3: FFR; 4: CPI @@ -102,32 +102,32 @@ PorR = [PorR;1*ones(nconstr1,1);5*ones(nconstr1,1);6*ones(nconstr1,1)]; % Conditions directly on future shocks % %options_.ms.cms = 0 % 1: condition on ms shocks; 0: disable this and "fidcnderr.m" gives - % unconditional forecasts if nconstr = 0 as well; <<>> +% unconditional forecasts if nconstr = 0 as well; <<>> %options_.ms.ncms = 0; % number of the stance of policy; 0 if no tightening or loosening %options_.ms.eq_cms = 1; % location of MS shocks options_.ms.tlindx = 1*ones(1,options_.ms.ncms); % 1-by-options_.ms.ncms vector; 1: tightening; 0: loosen options_.ms.tlnumber = [0.5 0.5 0 0]; %94:4 % [2 2 1.5 1.5]; %79:9 %[1.5 1.5 1 1]; 90:9 - % 1-by-options_.ms.ncms vector; cut-off point for MS shocks + % 1-by-options_.ms.ncms vector; cut-off point for MS shocks TLmean = zeros(1,options_.ms.ncms); - % unconditional, i.e., 0 mean, for the final report in the paper +% unconditional, i.e., 0 mean, for the final report in the paper if options_.ms.cms - options_.ms.eq_ms = []; - % At least at this point, it makes no sense to have DLS type of options_.ms.eq_ms; 10/12/98 - if all(isfinite(options_.ms.tlnumber)) - for k=1:options_.ms.ncms - TLmean(k) = lcnmean(options_.ms.tlnumber(k),options_.ms.tlindx(k)); - % shock mean magnitude. 1: tight; 0: loose - % Never used for any subsequent computation but - % simply used for the final report in the paper. - %options_.ms.tlnumber(k) = fzero('lcutoff',0,[],[],TLmean(k)) - % get an idea about the cutoff point given TLmean instead - - end - end + options_.ms.eq_ms = []; + % At least at this point, it makes no sense to have DLS type of options_.ms.eq_ms; 10/12/98 + if all(isfinite(options_.ms.tlnumber)) + for k=1:options_.ms.ncms + TLmean(k) = lcnmean(options_.ms.tlnumber(k),options_.ms.tlindx(k)); + % shock mean magnitude. 1: tight; 0: loose + % Never used for any subsequent computation but + % simply used for the final report in the paper. + %options_.ms.tlnumber(k) = fzero('lcutoff',0,[],[],TLmean(k)) + % get an idea about the cutoff point given TLmean instead + + end + end else - options_.ms.ncms = 0; % only for the use of the graph by msprobg.m - options_.ms.tlnumber = NaN*ones(1,options_.ms.ncms); - % -infinity, only for the use of the graph by msprobg.m + options_.ms.ncms = 0; % only for the use of the graph by msprobg.m + options_.ms.tlnumber = NaN*ones(1,options_.ms.ncms); + % -infinity, only for the use of the graph by msprobg.m end @@ -135,22 +135,22 @@ end % Soft conditions on variables % %cnum = 0 % # of band condtions; when 0, disable this option - % Note (different from "fidencon") that each condition corres. to variable +% Note (different from "fidencon") that each condition corres. to variable %options_.ms.banact = 1; % 1: use infor on actual; 0: preset without infor on actual if cnum - banindx = cell(cnum,1); % index for each variable or conditon - banstp = cell(cnum,1); % steps: annual in general - banvar = zeros(cnum,1); % varables: annual in general - banval = cell(cnum,1); % band value (each variable occupy a cell) - badval{1} = zeros(length(banstp{1}),2); % 2: lower or higher bound - - banstp{1} = 1:4; % 3 or 4 years - banvar(1) = 3; % 3: FFR; 5: CPI - if ~options_.ms.banact - for i=1:length(banstp{1}) - banval{1}(i,:) = [5.0 10.0]; - end - end + banindx = cell(cnum,1); % index for each variable or conditon + banstp = cell(cnum,1); % steps: annual in general + banvar = zeros(cnum,1); % varables: annual in general + banval = cell(cnum,1); % band value (each variable occupy a cell) + badval{1} = zeros(length(banstp{1}),2); % 2: lower or higher bound + + banstp{1} = 1:4; % 3 or 4 years + banvar(1) = 3; % 3: FFR; 5: CPI + if ~options_.ms.banact + for i=1:length(banstp{1}) + banval{1}(i,:) = [5.0 10.0]; + end + end end % pause(1) @@ -171,60 +171,60 @@ pause(1) %(1)-------------------------------------- % if (options_.ms.freq==12) - nStart=(yrStart-options_.ms.initial_year )*12+qmStart-options_.ms.initial_subperiod ; % positive number of months at the start - nEnd=(yrEnd-options_.ms.final_year )*12+qmEnd-options_.ms.final_subperiod ; % negative number of months towards end + nStart=(yrStart-options_.ms.initial_year )*12+qmStart-options_.ms.initial_subperiod ; % positive number of months at the start + nEnd=(yrEnd-options_.ms.final_year )*12+qmEnd-options_.ms.final_subperiod ; % negative number of months towards end elseif (options_.ms.freq==4) - nStart=(yrStart-options_.ms.initial_year )*4+qmStart-options_.ms.initial_subperiod ; % positive number of months at the start - nEnd=(yrEnd-options_.ms.final_year )*4+qmEnd-options_.ms.final_subperiod ; % negative number of months towards end + nStart=(yrStart-options_.ms.initial_year )*4+qmStart-options_.ms.initial_subperiod ; % positive number of months at the start + nEnd=(yrEnd-options_.ms.final_year )*4+qmEnd-options_.ms.final_subperiod ; % negative number of months towards end elseif (options_.ms.freq==1) - nStart=(yrStart-options_.ms.initial_year )*1+qmStart-options_.ms.initial_subperiod ; % positive number of months at the start - nEnd=(yrEnd-options_.ms.final_year )*1+qmEnd-options_.ms.final_subperiod ; % negative number of months towards end + nStart=(yrStart-options_.ms.initial_year )*1+qmStart-options_.ms.initial_subperiod ; % positive number of months at the start + nEnd=(yrEnd-options_.ms.final_year )*1+qmEnd-options_.ms.final_subperiod ; % negative number of months towards end else - error('Error: this code is only good for monthly/quarterly/yearly data!!!') - return + error('Error: this code is only good for monthly/quarterly/yearly data!!!') + return end % if nEnd>0 || nStart<0 - disp('Warning: this particular sample consider is out of bounds of the data!!!') - return + disp('Warning: this particular sample consider is out of bounds of the data!!!') + return end %*** Note, both xdgel and xdata have the same start with the specific sample xdgel=options_.data(nStart+1:nData+nEnd,options_.ms.vlist); - % gel: general options_.data within sample (nSample) +% gel: general options_.data within sample (nSample) if ~(nSample==size(xdgel,1)) - warning('The sample size (including options_.ms.nlags ) and data are incompatible') - disp('Check to make sure nSample and size(xdgel,1) are the same') - return + warning('The sample size (including options_.ms.nlags ) and data are incompatible') + disp('Check to make sure nSample and size(xdgel,1) are the same') + return end % baddata = find(isnan(xdgel)); if ~isempty(baddata) - warning('Some data for this selected sample are actually unavailable.') - disp('Hit any key to continue, or ctrl-c to abort') - pause + warning('Some data for this selected sample are actually unavailable.') + disp('Hit any key to continue, or ctrl-c to abort') + pause end % if options_.ms.initial_subperiod ==1 - yrB = options_.ms.initial_year ; qmB = options_.ms.initial_subperiod ; + yrB = options_.ms.initial_year ; qmB = options_.ms.initial_subperiod ; else - yrB = options_.ms.initial_year +1; qmB = 1; + yrB = options_.ms.initial_year +1; qmB = 1; end yrF = options_.ms.final_year ; qmF = options_.ms.final_subperiod ; [Mdate,tmp] = fn_calyrqm(options_.ms.freq,[options_.ms.initial_year options_.ms.initial_subperiod ],[options_.ms.final_year options_.ms.final_subperiod ]); xdatae=[Mdate options_.data(1:nData,options_.ms.vlist)]; - % beyond sample into forecast horizon until the end of the data options_.ms.final_year :options_.ms.final_subperiod - % Note: may contain NaN data. So must be careful about its use +% beyond sample into forecast horizon until the end of the data options_.ms.final_year :options_.ms.final_subperiod +% Note: may contain NaN data. So must be careful about its use %=========== Obtain prior-period, period-to-last period, and annual growth rates [yactyrge,yactyre,yactqmyge,yactqmge,yactqme] = fn_datana(xdatae,options_.ms.freq,options_.ms.log_var,options_.ms.percent_var,[yrB qmB],[yrF qmF]); qdates = zeros(size(yactqmyge,1),1); for ki=1:length(qdates) - qdates(ki) = yactqmyge(1,1) + (yactqmyge(1,2)+ki-2)/options_.ms.freq; + qdates(ki) = yactqmyge(1,1) + (yactqmyge(1,2)+ki-2)/options_.ms.freq; end for ki=1:nvar - figure - plot(qdates, yactqmyge(:,2+ki)/100) - xlabel(options_.ms.varlist{ki}) + figure + plot(qdates, yactqmyge(:,2+ki)/100) + xlabel(options_.ms.varlist{ki}) end save outactqmygdata.prn yactqmyge -ascii @@ -236,11 +236,11 @@ spstr1 = 'disp([sprintf('; spstr2 = '%4.0f %2.0f'; yactyrget=yactyrge'; for ki=1:length(options_.ms.vlist) - if ki==length(options_.ms.vlist) - spstr2 = [spstr2 ' %8.3f\n']; - else - spstr2 = [spstr2 ' %8.3f']; - end + if ki==length(options_.ms.vlist) + spstr2 = [spstr2 ' %8.3f\n']; + else + spstr2 = [spstr2 ' %8.3f']; + end end spstr = [spstr1 'spstr2' ', yactyrget)])']; eval(spstr) @@ -251,11 +251,11 @@ fid = fopen('outyrqm.prn','w'); fpstr1 = 'fprintf(fid,'; fpstr2 = '%4.0f %2.0f'; for ki=1:nvar - if ki==nvar - fpstr2 = [fpstr2 ' %8.3f\n']; - else - fpstr2 = [fpstr2 ' %8.3f']; - end + if ki==nvar + fpstr2 = [fpstr2 ' %8.3f\n']; + else + fpstr2 = [fpstr2 ' %8.3f']; + end end fpstr = [fpstr1 'fpstr2' ', yactyrget);']; eval(fpstr) @@ -264,479 +264,479 @@ fclose(fid); if options_.ms.indxestima - %(2)---------------------------------------------------------------------------- - % Estimation - % ML forecast and impulse responses - % Hard or soft conditions for conditional forecasts - %(2)---------------------------------------------------------------------------- - % - %* Arranged data information, WITHOUT dummy obs when 0 after mu is used. See fn_rnrprior_covres_dobs.m for using the dummy - % observations as part of an explicit prior. - [xtx,xty,yty,fss,phi,y,ncoef,xr,Bh] = fn_dataxy(nvar,options_.ms.nlags ,xdgel,mu,0,nexo); - if qmStart+options_.ms.nlags -options_.ms.dummy_obs >0 - qmStartEsti = rem(qmStart+options_.ms.nlags -options_.ms.dummy_obs ,options_.ms.freq); % dummy observations are included in the sample. - if (~qmStartEsti) - qmStartEsti = options_.ms.freq; - end - yrStartEsti = yrStart + floor((qmStart+options_.ms.nlags -options_.ms.dummy_obs )/(options_.ms.freq+0.01)); + %(2)---------------------------------------------------------------------------- + % Estimation + % ML forecast and impulse responses + % Hard or soft conditions for conditional forecasts + %(2)---------------------------------------------------------------------------- + % + %* Arranged data information, WITHOUT dummy obs when 0 after mu is used. See fn_rnrprior_covres_dobs.m for using the dummy + % observations as part of an explicit prior. + [xtx,xty,yty,fss,phi,y,ncoef,xr,Bh] = fn_dataxy(nvar,options_.ms.nlags ,xdgel,mu,0,nexo); + if qmStart+options_.ms.nlags -options_.ms.dummy_obs >0 + qmStartEsti = rem(qmStart+options_.ms.nlags -options_.ms.dummy_obs ,options_.ms.freq); % dummy observations are included in the sample. + if (~qmStartEsti) + qmStartEsti = options_.ms.freq; + end + yrStartEsti = yrStart + floor((qmStart+options_.ms.nlags -options_.ms.dummy_obs )/(options_.ms.freq+0.01)); % + 0.01 (or any number < 1) is used so that qmStart+options_.ms.nlags -options_.ms.dummy_obs ==?*options_.ms.freq doesn't give us an extra year forward. - else - qmStartEsti = options_.ms.freq + rem(qmStart+options_.ms.nlags -options_.ms.dummy_obs ,options_.ms.freq); % dummy observations are included in the sample. - if (qmStart+options_.ms.nlags -options_.ms.dummy_obs ==0) - yrStartEsti = yrStart - 1; % one year back. - else - yrStartEsti = yrStart + floor((qmStart+options_.ms.nlags -options_.ms.dummy_obs )/(options_.ms.freq-0.01)); - % - 0.01 (or any number < 1) is used so that qmStart+options_.ms.nlags -options_.ms.dummy_obs ==-?*options_.ms.freq give us an extra year back. - end - end - dateswd = fn_dataext([yrStartEsti qmStartEsti],[yrEnd qmEnd],xdatae(:,[1:2])); % dates with dummies - phie = [dateswd phi]; - ye = [dateswd y]; - - %* Obtain linear restrictions - [Uiconst,Viconst,n0,np,ixmC0Pres] = feval(options_.ms.restriction_fname,nvar,nexo,options_.ms ); - if min(n0)==0 - skipline() - warning('A0: restrictions in dlrprior.m give no free parameter in one of equations') - disp('Press ctrl-c to abort') - pause - elseif min(np)==0 - skipline() - warning('Ap: Restrictions in dlrprior.m give no free parameter in one of equations') - disp('Press ctrl-c to abort') - pause - end - - if options_.ms.contemp_reduced_form - Uiconst=cell(nvar,1); Viconst=cell(ncoef,1); - for kj=1:nvar - Uiconst{kj} = eye(nvar); Viconst{kj} = eye(ncoef); - end - end - - if options_.ms.bayesian_prior - %*** Obtains asymmetric prior (with no linear restrictions) with dummy observations as part of an explicit prior (i.e, - % reflected in Hpmulti and Hpinvmulti). See Forecast II, pp.69a-69b for details. - if 1 % Liquidity effect prior on both MS and MD equations. - [Pi,H0multi,Hpmulti,H0invmulti,Hpinvmulti] = fn_rnrprior_covres_dobs(nvar,options_.ms.freq,options_.ms.nlags ,xdgel,mu,indxDummy,hpmsmd,indxmsmdeqn); - else - [Pi,H0multi,Hpmulti,H0invmulti,Hpinvmulti] = fn_rnrprior(nvar,options_.ms.freq,options_.ms.nlags ,xdgel,mu); - end - - %*** Combines asymmetric prior with linear restrictions - [Ptld,H0invtld,Hpinvtld] = fn_rlrprior(Uiconst,Viconst,Pi,H0multi,Hpmulti,nvar); - - %*** Obtains the posterior matrices for estimation and inference - [Pmat,H0inv,Hpinv] = fn_rlrpostr(xtx,xty,yty,Ptld,H0invtld,Hpinvtld,Uiconst,Viconst); - - if options_.ms.contemp_reduced_form - %*** Obtain the ML estimate - A0hatinv = chol(H0inv{1}/fss); % upper triangular but lower triangular choleski - A0hat=inv(A0hatinv); - a0indx = find(A0hat); - else - %*** Obtain the ML estimate - % load idenml - x = 10*rand(sum(n0),1); - H0 = eye(sum(n0)); - crit = 1.0e-9; - nit = 10000; - % - [fhat,xhat,grad,Hhat,itct,fcount,retcodehat] = ... - csminwel('fn_a0freefun',x,H0,'fn_a0freegrad',crit,nit,Uiconst,nvar,n0,fss,H0inv); - - A0hat = fn_tran_b2a(xhat,Uiconst,nvar,n0) - A0hatinv = inv(A0hat); - fhat - xhat - grad - itct - fcount - retcodehat - save outm.mat xhat A0hat A0hatinv grad fhat itct itct fcount retcodehat - end - else - %*** Obtain the posterior matrices for estimation and inference - [Pmat,H0inv,Hpinv] = fn_dlrpostr(xtx,xty,yty,Uiconst,Viconst); - - if options_.ms.contemp_reduced_form - %*** Obtain the ML estimate - A0hatinv = chol(H0inv{1}/fss); % upper triangular but lower triangular choleski - A0hat=inv(A0hatinv); - a0indx = find(A0hat); - else - %*** Obtain the ML estimate - % load idenml - x = 10*rand(sum(n0),1); - H0 = eye(sum(n0)); - crit = 1.0e-9; - nit = 10000; - % - [fhat,xhat,grad,Hhat,itct,fcount,retcodehat] = ... - csminwel('fn_a0freefun',x,H0,'fn_a0freegrad',crit,nit,Uiconst,nvar,n0,fss,H0inv); - - A0hat = fn_tran_b2a(xhat,Uiconst,nvar,n0) - A0hatinv = inv(A0hat); - fhat - xhat - grad - itct - fcount - retcodehat - save outm.mat xhat A0hat A0hatinv grad fhat itct itct fcount retcodehat - end - end - - %**** impulse responses - swish = A0hatinv; % each column corresponds to an equation - if options_.ms.contemp_reduced_form - xhat = A0hat(a0indx); - Bhat=Pmat{1}; - Fhat = Bhat*A0hat - ghat = NaN; - else - xhat = fn_tran_a2b(A0hat,Uiconst,nvar,n0); - [Fhat,ghat] = fn_gfmean(xhat,Pmat,Viconst,nvar,ncoef,n0,np); - if options_.ms.cross_restrictions - Fhatur0P = Fhat; % ur: unrestriced across A0 and A+ - for ki = 1:size(ixmC0Pres,1) % loop through the number of equations in which - % cross-A0-A+ restrictions occur. See St. Louis Note p.5. - ixeq = ixmC0Pres{ki}(1,1); % index for the jth equation in consideration. - Lit = Viconst{ixeq}(ixmC0Pres{ki}(:,2),:); % transposed restriction matrix Li - % V_j(i,:) in f_j(i) = V_j(i,:)*g_j - ci = ixmC0Pres{ki}(:,4) .* A0hat(ixmC0Pres{ki}(:,3),ixeq); - % s * a_j(h) in the restriction f_j(i) = s * a_j(h). - LtH = Lit/Hpinv{ixeq}; - HLV = LtH'/(LtH*Lit'); - gihat = Viconst{ixeq}'*Fhatur0P(:,ixeq); - Fhat(:,ixeq) = Viconst{ixeq}*(gihat + HLV*(ci-Lit*gihat)); - end - end - Fhat - Bhat = Fhat/A0hat; % ncoef-by-nvar reduced form lagged parameters. - end - nn = [nvar options_.ms.nlags imstp]; - imfhat = fn_impulse(Bhat,swish,nn); % in the form that is congenial to RATS - imf3hat=reshape(imfhat,size(imfhat,1),nvar,nvar); - % imf3: row--steps, column--nvar responses, 3rd dimension--nvar shocks - imf3shat=permute(imf3hat,[1 3 2]); - % imf3s: permuted so that row--steps, column--nvar shocks, - % 3rd dimension--nvar responses - % Note: reshape(imf3s(1,:,:),nvar,nvar) = A0in (columns -- equations) - if options_.ms.indxgimfhat - figure - end - scaleout = fn_imcgraph(imfhat,nvar,imstp,xlab,ylab,options_.ms.indxgimfhat); - imfstd = max(abs(scaleout)'); % row: nvar (largest number); used for standard deviations - - % - % %**** save stds. of both data and impulse responses in idfile1 - % temp = [std(yactqmyge(:,3:end)); std(yactyrge(:,3:end)); imfstd]; %<<>> - % save idenyimstd.prn temp -ascii % export forecast and impulse response to the file "idenyimstd.prn", 3-by-nvar - % % - % %**** save stds. of both data and impulse responses in idfile1 - % temp = [std(yactqmyge(:,3:end)); std(yactyrge(:,3:end)); imfstd]; %<<>> - % save idenyimstd.prn temp -ascii % export forecast and impulse response to the file "idenyimstd.prn", 3-by-nvar - % if options_.ms.indxparr - % idfile1='idenyimstd'; - % end - - %===================================== - % Now, out-of-sample forecasts. Note: Hm1t does not change with A0. - %===================================== - % - % * updating the last row of X (phi) with the current (last row of) y. - tcwx = nvar*options_.ms.nlags ; % total coefficeint without exogenous variables - phil = phi(size(phi,1),:); - phil(nvar+1:tcwx) = phil(1:tcwx-nvar); - phil(1:nvar) = y(end,:); - %*** exogenous variables excluding constant terms - if (nexo>1) - Xexoe = fn_dataext([yrEnd qmEnd],[yrEnd qmEnd],xdatae(:,[1:2 2+nvar+1:2+nvar+nexo-1])); - phil(1,tcwx+1:tcwx+nexo-1) = Xexoe(1,3:end); - end - % - %*** ML unconditional point forecast - nn = [nvar options_.ms.nlags nfqm]; - if nexo<2 - yforehat = fn_forecast(Bhat,phil,nn); % nfqm-by-nvar, in log - else - Xfexoe = fn_dataext(fdates(1,:),fdates(numel(fdates),:),xdatae(:,[1:2 2+nvar+1:2+nvar+nexo-1])); - %Xfexoe = fn_dataext(fdates(1,:),fdates(end,:),xdatae(:,[1:2 2+nvar+1:2+nvar+nexo-1])); - yforehat = fn_forecast(Bhat,phil,nn,nexo,Xfexoe(:,3:end)); % nfqm-by-nvar, in log - end - yforehate = [fdates yforehat]; - % - yact1e = fn_dataext([yrEnd-nayr 1],[yrEnd qmEnd],xdatae(:,1:nvar+2)); - if options_.ms.real_pseudo_forecast - %yact2e = fn_dataext([yrEnd-nayr 1],E2yrqm,xdatae); - yact2e = fn_dataext([yrEnd-nayr 1],[fdates(end,1) options_.ms.freq],xdatae(:,1:nvar+2)); - else - yact2e=yact1e; - end - yafhate = [yact1e; yforehate]; % actual and forecast - % - %===== Converted to mg, qg, and calendar yg - % - [yafyrghate,yafyrhate,yafqmyghate] = fn_datana(yafhate,options_.ms.freq,options_.ms.log_var(1:nlogeno),options_.ms.percent_var(1:npereno)); - % actual and forecast growth rates - [yact2yrge,yact2yre,yact2qmyge] = fn_datana(yact2e,options_.ms.freq,options_.ms.log_var(1:nlogeno),options_.ms.percent_var(1:npereno)); - % only actual growth rates - yafyrghate - if options_.ms.indxgforhat - keyindx = [1:nvar]; - conlab=['unconditional']; - - figure - yafyrghate(:,3:end) = yafyrghate(:,3:end)/100; - yact2yrge(:,3:end) = yact2yrge(:,3:end)/100; - fn_foregraph(yafyrghate,yact2yrge,keyindx,rnum,cnum,options_.ms.freq,ylab,forelabel,conlab) - end - - %------------------------------------------------- - % Setup for point conditional forecast - % ML Conditional Forecast - %------------------------------------------------- - % - %% 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. - % - - if (nconstr > 0) - %*** 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 - varcon(:)=PorR; % 1: Pcm; 3: FFR; 5: CPI - - % - for i=1:nconstr - if i<=nconstr1 - stepcon{i}=i; % FFR - elseif i<=2*nconstr1 - stepcon{i}=i-nconstr1; % FFR - elseif i<=3*nconstr1 - stepcon{i}=i-2*nconstr1; % FFR - elseif i<=4*nconstr1 - stepcon{i}=i-3*nconstr1; % FFR - elseif i<=5*nconstr1 - stepcon{i}=i-4*nconstr1; % FFR - elseif i<=6*nconstr1 - stepcon{i}=i-5*nconstr1; % FFR - end - end - -% for i=1:nconstr -% stepcon{i}=i; % FFR -% end - -% bend=12; -% stepcon{1}=[1:bend]'; % average over -% stepcon{nconstr1+1}=[1:options_.ms.freq-qmSub]'; % average over the remaing months in 1st forecast year -% stepcon{nconstr1+2}=[options_.ms.freq-qmSub+1:options_.ms.freq-qmSub+12]'; % average over 12 months next year -% stepcon{nconstr1+3}=[options_.ms.freq-qmSub+13:options_.ms.freq-qmSub+24]'; % average over 12 months. 3rd year -% stepcon{nconstr1+4}=[options_.ms.freq-qmSub+25:options_.ms.freq-qmSub+36]'; % average over 12 months. 4th year - -% %**** avearage condition over, say, options_.ms.freq periods -% if qmEnd==options_.ms.freq -% stepcon{1}=[1:options_.ms.freq]'; % average over the remaing periods in 1st forecast year -% else -% stepcon{1}=[1:options_.ms.freq-qmEnd]'; % average over the remaing periods in 1st forecast year -% end -% for kj=2:nconstr -% stepcon{kj}=[length(stepcon{kj-1})+1:length(stepcon{kj-1})+options_.ms.freq]'; % average over 12 months next year -% end - - if options_.ms.real_pseudo_forecast -% %*** conditions in every period -% for i=1:nconstr -% valuecon(i) = yact(actup+i,varcon(i)); -% %valuecon(i) = mean( yact(actup+1:actup+bend,varcon(i)) ); -% %valuecon(i) = 0.060; % 95:01 -% %valuecon(i) = (0.0475+0.055)/2; % 94:10 -% end - -% %*** average condtions over,say, options_.ms.freq periods. -% for i=nconstr1+1:nconstr1+nconstr2 -% i=1; -% valuecon(nconstr1+i) = ( ( mean(ylast12Cal(:,varcon(nconstr1+i)),1) + ... -% log(1+yactCalyg(yAg-yFg+i,varcon(nconstr1+i))/100) )*options_.ms.freq - ... -% yCal_1(:,varcon(nconstr1+i)) ) ./ length(stepcon{nconstr1+i}); -% % the same as unconditional "yactCalyg" 1st calendar year -% i=2; -% valuecon(nconstr1+i) = mean(ylast12Cal(:,varcon(nconstr1+i))) + ... -% log(1+yactCalyg(yAg-yFg+1,varcon(nconstr1+i))/100) ... -% + log(1+yactCalyg(yAg-yFg+i,varcon(nconstr1+i))/100); -% % the same as actual "yactCalgy" 2nd calendar year -% i=3; -% valuecon(nconstr1+i) = valuecon(nconstr1+i-1) + ... -% log(1+yactCalyg(yAg-yFg+i,varcon(nconstr1+i))/100); -% % the same as actual "yactCalgy" 3rd calendar year -% %i=4; -% %valuecon(nconstr1+i) = valuecon(nconstr1+i-1) + ... -% % log(1+yactCalyg(yAg-yFg+i,varcon(nconstr1+i))/100); -% % the same as actual "yactCalgy" 4th calendar year -% end - - %*** conditions in every period - vpntM = fn_dataext(E1yrqm, E2yrqm,xdatae); % point value matrix with dates - % vaveM = fn_dataext([yrEnd+1 0],[yrEnd+options_.forecast 0],yact2yre); % average value matrix with dates - for i=1:nconstr + else + qmStartEsti = options_.ms.freq + rem(qmStart+options_.ms.nlags -options_.ms.dummy_obs ,options_.ms.freq); % dummy observations are included in the sample. + if (qmStart+options_.ms.nlags -options_.ms.dummy_obs ==0) + yrStartEsti = yrStart - 1; % one year back. + else + yrStartEsti = yrStart + floor((qmStart+options_.ms.nlags -options_.ms.dummy_obs )/(options_.ms.freq-0.01)); + % - 0.01 (or any number < 1) is used so that qmStart+options_.ms.nlags -options_.ms.dummy_obs ==-?*options_.ms.freq give us an extra year back. + end + end + dateswd = fn_dataext([yrStartEsti qmStartEsti],[yrEnd qmEnd],xdatae(:,[1:2])); % dates with dummies + phie = [dateswd phi]; + ye = [dateswd y]; + + %* Obtain linear restrictions + [Uiconst,Viconst,n0,np,ixmC0Pres] = feval(options_.ms.restriction_fname,nvar,nexo,options_.ms ); + if min(n0)==0 + skipline() + warning('A0: restrictions in dlrprior.m give no free parameter in one of equations') + disp('Press ctrl-c to abort') + pause + elseif min(np)==0 + skipline() + warning('Ap: Restrictions in dlrprior.m give no free parameter in one of equations') + disp('Press ctrl-c to abort') + pause + end + + if options_.ms.contemp_reduced_form + Uiconst=cell(nvar,1); Viconst=cell(ncoef,1); + for kj=1:nvar + Uiconst{kj} = eye(nvar); Viconst{kj} = eye(ncoef); + end + end + + if options_.ms.bayesian_prior + %*** Obtains asymmetric prior (with no linear restrictions) with dummy observations as part of an explicit prior (i.e, + % reflected in Hpmulti and Hpinvmulti). See Forecast II, pp.69a-69b for details. + if 1 % Liquidity effect prior on both MS and MD equations. + [Pi,H0multi,Hpmulti,H0invmulti,Hpinvmulti] = fn_rnrprior_covres_dobs(nvar,options_.ms.freq,options_.ms.nlags ,xdgel,mu,indxDummy,hpmsmd,indxmsmdeqn); + else + [Pi,H0multi,Hpmulti,H0invmulti,Hpinvmulti] = fn_rnrprior(nvar,options_.ms.freq,options_.ms.nlags ,xdgel,mu); + end + + %*** Combines asymmetric prior with linear restrictions + [Ptld,H0invtld,Hpinvtld] = fn_rlrprior(Uiconst,Viconst,Pi,H0multi,Hpmulti,nvar); + + %*** Obtains the posterior matrices for estimation and inference + [Pmat,H0inv,Hpinv] = fn_rlrpostr(xtx,xty,yty,Ptld,H0invtld,Hpinvtld,Uiconst,Viconst); + + if options_.ms.contemp_reduced_form + %*** Obtain the ML estimate + A0hatinv = chol(H0inv{1}/fss); % upper triangular but lower triangular choleski + A0hat=inv(A0hatinv); + a0indx = find(A0hat); + else + %*** Obtain the ML estimate + % load idenml + x = 10*rand(sum(n0),1); + H0 = eye(sum(n0)); + crit = 1.0e-9; + nit = 10000; + % + [fhat,xhat,grad,Hhat,itct,fcount,retcodehat] = ... + csminwel('fn_a0freefun',x,H0,'fn_a0freegrad',crit,nit,Uiconst,nvar,n0,fss,H0inv); + + A0hat = fn_tran_b2a(xhat,Uiconst,nvar,n0) + A0hatinv = inv(A0hat); + fhat + xhat + grad + itct + fcount + retcodehat + save outm.mat xhat A0hat A0hatinv grad fhat itct itct fcount retcodehat + end + else + %*** Obtain the posterior matrices for estimation and inference + [Pmat,H0inv,Hpinv] = fn_dlrpostr(xtx,xty,yty,Uiconst,Viconst); + + if options_.ms.contemp_reduced_form + %*** Obtain the ML estimate + A0hatinv = chol(H0inv{1}/fss); % upper triangular but lower triangular choleski + A0hat=inv(A0hatinv); + a0indx = find(A0hat); + else + %*** Obtain the ML estimate + % load idenml + x = 10*rand(sum(n0),1); + H0 = eye(sum(n0)); + crit = 1.0e-9; + nit = 10000; + % + [fhat,xhat,grad,Hhat,itct,fcount,retcodehat] = ... + csminwel('fn_a0freefun',x,H0,'fn_a0freegrad',crit,nit,Uiconst,nvar,n0,fss,H0inv); + + A0hat = fn_tran_b2a(xhat,Uiconst,nvar,n0) + A0hatinv = inv(A0hat); + fhat + xhat + grad + itct + fcount + retcodehat + save outm.mat xhat A0hat A0hatinv grad fhat itct itct fcount retcodehat + end + end + + %**** impulse responses + swish = A0hatinv; % each column corresponds to an equation + if options_.ms.contemp_reduced_form + xhat = A0hat(a0indx); + Bhat=Pmat{1}; + Fhat = Bhat*A0hat + ghat = NaN; + else + xhat = fn_tran_a2b(A0hat,Uiconst,nvar,n0); + [Fhat,ghat] = fn_gfmean(xhat,Pmat,Viconst,nvar,ncoef,n0,np); + if options_.ms.cross_restrictions + Fhatur0P = Fhat; % ur: unrestriced across A0 and A+ + for ki = 1:size(ixmC0Pres,1) % loop through the number of equations in which + % cross-A0-A+ restrictions occur. See St. Louis Note p.5. + ixeq = ixmC0Pres{ki}(1,1); % index for the jth equation in consideration. + Lit = Viconst{ixeq}(ixmC0Pres{ki}(:,2),:); % transposed restriction matrix Li + % V_j(i,:) in f_j(i) = V_j(i,:)*g_j + ci = ixmC0Pres{ki}(:,4) .* A0hat(ixmC0Pres{ki}(:,3),ixeq); + % s * a_j(h) in the restriction f_j(i) = s * a_j(h). + LtH = Lit/Hpinv{ixeq}; + HLV = LtH'/(LtH*Lit'); + gihat = Viconst{ixeq}'*Fhatur0P(:,ixeq); + Fhat(:,ixeq) = Viconst{ixeq}*(gihat + HLV*(ci-Lit*gihat)); + end + end + Fhat + Bhat = Fhat/A0hat; % ncoef-by-nvar reduced form lagged parameters. + end + nn = [nvar options_.ms.nlags imstp]; + imfhat = fn_impulse(Bhat,swish,nn); % in the form that is congenial to RATS + imf3hat=reshape(imfhat,size(imfhat,1),nvar,nvar); + % imf3: row--steps, column--nvar responses, 3rd dimension--nvar shocks + imf3shat=permute(imf3hat,[1 3 2]); + % imf3s: permuted so that row--steps, column--nvar shocks, + % 3rd dimension--nvar responses + % Note: reshape(imf3s(1,:,:),nvar,nvar) = A0in (columns -- equations) + if options_.ms.indxgimfhat + figure + end + scaleout = fn_imcgraph(imfhat,nvar,imstp,xlab,ylab,options_.ms.indxgimfhat); + imfstd = max(abs(scaleout)'); % row: nvar (largest number); used for standard deviations + + % + % %**** save stds. of both data and impulse responses in idfile1 + % temp = [std(yactqmyge(:,3:end)); std(yactyrge(:,3:end)); imfstd]; %<<>> + % save idenyimstd.prn temp -ascii % export forecast and impulse response to the file "idenyimstd.prn", 3-by-nvar + % % + % %**** save stds. of both data and impulse responses in idfile1 + % temp = [std(yactqmyge(:,3:end)); std(yactyrge(:,3:end)); imfstd]; %<<>> + % save idenyimstd.prn temp -ascii % export forecast and impulse response to the file "idenyimstd.prn", 3-by-nvar + % if options_.ms.indxparr + % idfile1='idenyimstd'; + % end + + %===================================== + % Now, out-of-sample forecasts. Note: Hm1t does not change with A0. + %===================================== + % + % * updating the last row of X (phi) with the current (last row of) y. + tcwx = nvar*options_.ms.nlags ; % total coefficeint without exogenous variables + phil = phi(size(phi,1),:); + phil(nvar+1:tcwx) = phil(1:tcwx-nvar); + phil(1:nvar) = y(end,:); + %*** exogenous variables excluding constant terms + if (nexo>1) + Xexoe = fn_dataext([yrEnd qmEnd],[yrEnd qmEnd],xdatae(:,[1:2 2+nvar+1:2+nvar+nexo-1])); + phil(1,tcwx+1:tcwx+nexo-1) = Xexoe(1,3:end); + end + % + %*** ML unconditional point forecast + nn = [nvar options_.ms.nlags nfqm]; + if nexo<2 + yforehat = fn_forecast(Bhat,phil,nn); % nfqm-by-nvar, in log + else + Xfexoe = fn_dataext(fdates(1,:),fdates(numel(fdates),:),xdatae(:,[1:2 2+nvar+1:2+nvar+nexo-1])); + %Xfexoe = fn_dataext(fdates(1,:),fdates(end,:),xdatae(:,[1:2 2+nvar+1:2+nvar+nexo-1])); + yforehat = fn_forecast(Bhat,phil,nn,nexo,Xfexoe(:,3:end)); % nfqm-by-nvar, in log + end + yforehate = [fdates yforehat]; + % + yact1e = fn_dataext([yrEnd-nayr 1],[yrEnd qmEnd],xdatae(:,1:nvar+2)); + if options_.ms.real_pseudo_forecast + %yact2e = fn_dataext([yrEnd-nayr 1],E2yrqm,xdatae); + yact2e = fn_dataext([yrEnd-nayr 1],[fdates(end,1) options_.ms.freq],xdatae(:,1:nvar+2)); + else + yact2e=yact1e; + end + yafhate = [yact1e; yforehate]; % actual and forecast + % + %===== Converted to mg, qg, and calendar yg + % + [yafyrghate,yafyrhate,yafqmyghate] = fn_datana(yafhate,options_.ms.freq,options_.ms.log_var(1:nlogeno),options_.ms.percent_var(1:npereno)); + % actual and forecast growth rates + [yact2yrge,yact2yre,yact2qmyge] = fn_datana(yact2e,options_.ms.freq,options_.ms.log_var(1:nlogeno),options_.ms.percent_var(1:npereno)); + % only actual growth rates + yafyrghate + if options_.ms.indxgforhat + keyindx = [1:nvar]; + conlab=['unconditional']; + + figure + yafyrghate(:,3:end) = yafyrghate(:,3:end)/100; + yact2yrge(:,3:end) = yact2yrge(:,3:end)/100; + fn_foregraph(yafyrghate,yact2yrge,keyindx,rnum,cnum,options_.ms.freq,ylab,forelabel,conlab) + end + + %------------------------------------------------- + % Setup for point conditional forecast + % ML Conditional Forecast + %------------------------------------------------- + % + %% 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. + % + + if (nconstr > 0) + %*** 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 + varcon(:)=PorR; % 1: Pcm; 3: FFR; 5: CPI + + % + for i=1:nconstr if i<=nconstr1 - valuecon(i) = vpntM(i,2+varcon(i)); % 2: first 2 elements are dates + stepcon{i}=i; % FFR elseif i<=2*nconstr1 - valuecon(i) = vpntM(i-nconstr1,2+varcon(i)); + stepcon{i}=i-nconstr1; % FFR elseif i<=3*nconstr1 - valuecon(i) = vpntM(i-2*nconstr1,2+varcon(i)); + stepcon{i}=i-2*nconstr1; % FFR elseif i<=4*nconstr1 - valuecon(i) = vpntM(i-3*nconstr1,2+varcon(i)); + stepcon{i}=i-3*nconstr1; % FFR elseif i<=5*nconstr1 - valuecon(i) = vpntM(i-4*nconstr1,2+varcon(i)); + stepcon{i}=i-4*nconstr1; % FFR elseif i<=6*nconstr1 - valuecon(i) = vpntM(i-5*nconstr1,2+varcon(i)); + stepcon{i}=i-5*nconstr1; % FFR end - end - -% %*** average condtions over,say, options_.ms.freq periods. -% if qmEnd==options_.ms.freq -% vaveM = fn_dataext([yrEnd+1 0],[yrEnd+options_.forecast 0],yact2yre); % average value matrix with dates -% valuecon(1) = vaveM(1,2+varcon(1)); % 2: first 2 elements are dates -% else -% vaveM = fn_dataext([yrEnd 0],[yrEnd+options_.forecast 0],yact2yre); % average value matrix with dates -% yactrem = fn_dataext([yrEnd qmEnd+1],[yrEnd options_.ms.freq],xdatae); -% valuecon(1) = sum(yactrem(:,2+varcon(1)),1)/length(stepcon{1}); -% % 2: first 2 elements are dates -% end -% for kj=2:nconstr -% valuecon(kj) = vaveM(kj,2+varcon(kj)); % 2: first 2 elements are dates -% end - else - vpntM = dataext([yrEnd qmEnd+1],[yrEnd qmEnd+2],xdatae); % point value matrix with dates - for i=1:nconstr - if i<=nconstr1 - valuecon(i) = vpntM(i,2+varcon(i)); % 2: first 2 elements are dates; Poil - elseif i<=2*nconstr1 - valuecon(i) = vpntM(i-nconstr1,2+varcon(i)); % 2: first 2 elements are dates; M2 - elseif i<=3*nconstr1 - valuecon(i) = vpntM(i-2*nconstr1,2+varcon(i)); % 2: first 2 elements are dates; FFR - elseif i<=4*nconstr1 - valuecon(i) = vpntM(i-3*nconstr1,2+varcon(i)); % 2: first 2 elements are dates; CPI - elseif i<=5*nconstr1 - valuecon(i) = vpntM(i-4*nconstr1,2+varcon(i)); % 2: first 2 elements are dates; U - elseif i<=5*nconstr1+nconstr2 - valuecon(i)=xdata(end,5)+(i-5*nconstr1)*log(1.001)/options_.ms.freq; %CPI - elseif i<=5*nconstr1+2*nconstr2 - valuecon(i)=0.0725; %FFR - else - valuecon(i)=xdata(end,6)+(i-5*nconstr1-2*nconstr2)*0.01/nfqm; %U + end + + % for i=1:nconstr + % stepcon{i}=i; % FFR + % end + + % bend=12; + % stepcon{1}=[1:bend]'; % average over + % stepcon{nconstr1+1}=[1:options_.ms.freq-qmSub]'; % average over the remaing months in 1st forecast year + % stepcon{nconstr1+2}=[options_.ms.freq-qmSub+1:options_.ms.freq-qmSub+12]'; % average over 12 months next year + % stepcon{nconstr1+3}=[options_.ms.freq-qmSub+13:options_.ms.freq-qmSub+24]'; % average over 12 months. 3rd year + % stepcon{nconstr1+4}=[options_.ms.freq-qmSub+25:options_.ms.freq-qmSub+36]'; % average over 12 months. 4th year + + % %**** avearage condition over, say, options_.ms.freq periods + % if qmEnd==options_.ms.freq + % stepcon{1}=[1:options_.ms.freq]'; % average over the remaing periods in 1st forecast year + % else + % stepcon{1}=[1:options_.ms.freq-qmEnd]'; % average over the remaing periods in 1st forecast year + % end + % for kj=2:nconstr + % stepcon{kj}=[length(stepcon{kj-1})+1:length(stepcon{kj-1})+options_.ms.freq]'; % average over 12 months next year + % end + + if options_.ms.real_pseudo_forecast + % %*** conditions in every period + % for i=1:nconstr + % valuecon(i) = yact(actup+i,varcon(i)); + % %valuecon(i) = mean( yact(actup+1:actup+bend,varcon(i)) ); + % %valuecon(i) = 0.060; % 95:01 + % %valuecon(i) = (0.0475+0.055)/2; % 94:10 + % end + + % %*** average condtions over,say, options_.ms.freq periods. + % for i=nconstr1+1:nconstr1+nconstr2 + % i=1; + % valuecon(nconstr1+i) = ( ( mean(ylast12Cal(:,varcon(nconstr1+i)),1) + ... + % log(1+yactCalyg(yAg-yFg+i,varcon(nconstr1+i))/100) )*options_.ms.freq - ... + % yCal_1(:,varcon(nconstr1+i)) ) ./ length(stepcon{nconstr1+i}); + % % the same as unconditional "yactCalyg" 1st calendar year + % i=2; + % valuecon(nconstr1+i) = mean(ylast12Cal(:,varcon(nconstr1+i))) + ... + % log(1+yactCalyg(yAg-yFg+1,varcon(nconstr1+i))/100) ... + % + log(1+yactCalyg(yAg-yFg+i,varcon(nconstr1+i))/100); + % % the same as actual "yactCalgy" 2nd calendar year + % i=3; + % valuecon(nconstr1+i) = valuecon(nconstr1+i-1) + ... + % log(1+yactCalyg(yAg-yFg+i,varcon(nconstr1+i))/100); + % % the same as actual "yactCalgy" 3rd calendar year + % %i=4; + % %valuecon(nconstr1+i) = valuecon(nconstr1+i-1) + ... + % % log(1+yactCalyg(yAg-yFg+i,varcon(nconstr1+i))/100); + % % the same as actual "yactCalgy" 4th calendar year + % end + + %*** conditions in every period + vpntM = fn_dataext(E1yrqm, E2yrqm,xdatae); % point value matrix with dates + % vaveM = fn_dataext([yrEnd+1 0],[yrEnd+options_.forecast 0],yact2yre); % average value matrix with dates + for i=1:nconstr + if i<=nconstr1 + valuecon(i) = vpntM(i,2+varcon(i)); % 2: first 2 elements are dates + elseif i<=2*nconstr1 + valuecon(i) = vpntM(i-nconstr1,2+varcon(i)); + elseif i<=3*nconstr1 + valuecon(i) = vpntM(i-2*nconstr1,2+varcon(i)); + elseif i<=4*nconstr1 + valuecon(i) = vpntM(i-3*nconstr1,2+varcon(i)); + elseif i<=5*nconstr1 + valuecon(i) = vpntM(i-4*nconstr1,2+varcon(i)); + elseif i<=6*nconstr1 + valuecon(i) = vpntM(i-5*nconstr1,2+varcon(i)); + end + end + + % %*** average condtions over,say, options_.ms.freq periods. + % if qmEnd==options_.ms.freq + % vaveM = fn_dataext([yrEnd+1 0],[yrEnd+options_.forecast 0],yact2yre); % average value matrix with dates + % valuecon(1) = vaveM(1,2+varcon(1)); % 2: first 2 elements are dates + % else + % vaveM = fn_dataext([yrEnd 0],[yrEnd+options_.forecast 0],yact2yre); % average value matrix with dates + % yactrem = fn_dataext([yrEnd qmEnd+1],[yrEnd options_.ms.freq],xdatae); + % valuecon(1) = sum(yactrem(:,2+varcon(1)),1)/length(stepcon{1}); + % % 2: first 2 elements are dates + % end + % for kj=2:nconstr + % valuecon(kj) = vaveM(kj,2+varcon(kj)); % 2: first 2 elements are dates + % end + else + vpntM = dataext([yrEnd qmEnd+1],[yrEnd qmEnd+2],xdatae); % point value matrix with dates + for i=1:nconstr + if i<=nconstr1 + valuecon(i) = vpntM(i,2+varcon(i)); % 2: first 2 elements are dates; Poil + elseif i<=2*nconstr1 + valuecon(i) = vpntM(i-nconstr1,2+varcon(i)); % 2: first 2 elements are dates; M2 + elseif i<=3*nconstr1 + valuecon(i) = vpntM(i-2*nconstr1,2+varcon(i)); % 2: first 2 elements are dates; FFR + elseif i<=4*nconstr1 + valuecon(i) = vpntM(i-3*nconstr1,2+varcon(i)); % 2: first 2 elements are dates; CPI + elseif i<=5*nconstr1 + valuecon(i) = vpntM(i-4*nconstr1,2+varcon(i)); % 2: first 2 elements are dates; U + elseif i<=5*nconstr1+nconstr2 + valuecon(i)=xdata(end,5)+(i-5*nconstr1)*log(1.001)/options_.ms.freq; %CPI + elseif i<=5*nconstr1+2*nconstr2 + valuecon(i)=0.0725; %FFR + else + valuecon(i)=xdata(end,6)+(i-5*nconstr1-2*nconstr2)*0.01/nfqm; %U + end + end + %valuecon(i) = 0.060; % 95:01 + end + else + valuecon = []; + stepcon = []; + varcon = []; + end + + nstepsm = 0; % initializing, the maximum step in all constraints + for i=1:nconstr + nstepsm = max([nstepsm max(stepcon{i})]); + end + + if cnum + if options_.ms.real_pseudo_forecast && options_.ms.banact + for i=1:length(banstp{1}) + banval{1}(1:length(banstp{1}),1) = ... + yactCalyg(yAg-yFg+1:yAg-yFg+length(banstp{1}),banvar(1)) - 2; + banval{1}(1:length(banstp{1}),2) = ... + yactCalyg(yAg-yFg+1:yAg-yFg+length(banstp{1}),banvar(1)) + 2; end - end - %valuecon(i) = 0.060; % 95:01 - end - else - valuecon = []; - stepcon = []; - varcon = []; - end - - nstepsm = 0; % initializing, the maximum step in all constraints - for i=1:nconstr - nstepsm = max([nstepsm max(stepcon{i})]); - end - - if cnum - if options_.ms.real_pseudo_forecast && options_.ms.banact - for i=1:length(banstp{1}) - banval{1}(1:length(banstp{1}),1) = ... - yactCalyg(yAg-yFg+1:yAg-yFg+length(banstp{1}),banvar(1)) - 2; - banval{1}(1:length(banstp{1}),2) = ... - yactCalyg(yAg-yFg+1:yAg-yFg+length(banstp{1}),banvar(1)) + 2; - end - end - end - - - %=================================================== - % ML conditional forecast - %=================================================== - %/* - [ychat,Estr,rcon] = fn_fcstidcnd(valuecon,stepcon,varcon,nstepsm,... - nconstr,options_.ms.eq_ms,nvar,options_.ms.nlags ,phil,0,0,yforehat,imf3shat,A0hat,Bhat,... - nfqm,options_.ms.tlindx,options_.ms.tlnumber,options_.ms.ncms,options_.ms.eq_cms); - ychate = [fdates ychat]; - yachate = [yact1e; ychate]; % actual and condtional forecast - %===== Converted to mg, qg, and calendar yg - [yacyrghate,yacyrhate,yacqmyghate] = fn_datana(yachate,options_.ms.freq,options_.ms.log_var(1:nlogeno),options_.ms.percent_var(1:npereno)); - % actual and conditional forecast growth rates - if options_.ms.indxgdls && nconstr - keyindx = [1:nvar]; - % conlab=['conditional on' ylab{PorR(1)}]; - conlab=['v-conditions']; - - figure - fn_foregraph(yafyrghate,yact2yrge,keyindx,rnum,cnum,options_.ms.freq,ylab,forelabel,conlab) - end - - if options_.ms.ncsk - Estr = zeros(nfqm,nvar); - Estr(1:2,:) = [ - -2.1838 -1.5779 0.53064 -0.099425 -0.69269 -1.0391 - 1.9407 3.3138 -0.10563 -0.55457 -0.68772 1.3534 - ]; - Estr(3:6,3) = [0.5*ones(1,4)]'; % MD shocks - - Estr(3:10,2) = [1.5 1.5 1.5*ones(1,6)]'; % MS shocks - - %Estr(3:6,6) = 1*ones(4,1); % U shocks - %Estr(8:11,4) = 1*ones(4,1); % y shocks - - %Estr(3:10,2) = [2.5 2.5 1.5*ones(1,6)]'; % MS shocks alone - - nn = [nvar options_.ms.noptions_.ms.nlags nfqm]; - ycEhat = forefixe(A0hat,Bhat,phil,nn,Estr); - ycEhate = [fdates ycEhat]; - yacEhate = [yact1e; ycEhate]; % actual and condtional forecast - %===== Converted to mg, qg, and calendar yg - [yacEyrghate,yacEyrhate,yacEqmyghate] = datana(yacEhate,options_.ms.freq,options_.ms.log_var(1:nlogeno),options_.ms.percent_var(1:npereno)); - % actual and conditional forecast growth rates - disp([sprintf('%4.0f %2.0f %8.3f %8.3f %8.3f %8.3f %8.3f %8.3f\n',yacEyrghate')]) - - if 1 - keyindx = [1:nvar]; - % conlab=['conditional on' ylab{PorR(1)}]; - conlab=['shock-conditions']; - - figure - gyrfore(yacEyrghate,yact2yrge,keyindx,rnum,cnum,ylab,forelabel,conlab) - end - end - - %----------------------------------------------------------- - % Compute structural shocks for the whole sample period excluding dummy observations. - %----------------------------------------------------------- - ywod = y(options_.ms.dummy_obs +1:end,:); % without dummy observations - phiwod=phi(options_.ms.dummy_obs +1:end,:); % without dummy observations - eplhat=ywod*A0hat-phiwod*Fhat; - qmStartWod = mod(qmStart+options_.ms.nlags ,options_.ms.freq); - if (~qmStartWod) - qmStartWod = options_.ms.freq; - end - yrStartWod = yrStart + floor((qmStart+options_.ms.nlags -1)/options_.ms.freq); - dateswod = fn_dataext([yrStartWod qmStartWod],[yrEnd qmEnd],xdatae(:,[1:2])); - eplhate = [dateswod eplhat]; - - Aphat = Fhat; + end + end + + + %=================================================== + % ML conditional forecast + %=================================================== + %/* + [ychat,Estr,rcon] = fn_fcstidcnd(valuecon,stepcon,varcon,nstepsm,... + nconstr,options_.ms.eq_ms,nvar,options_.ms.nlags ,phil,0,0,yforehat,imf3shat,A0hat,Bhat,... + nfqm,options_.ms.tlindx,options_.ms.tlnumber,options_.ms.ncms,options_.ms.eq_cms); + ychate = [fdates ychat]; + yachate = [yact1e; ychate]; % actual and condtional forecast + %===== Converted to mg, qg, and calendar yg + [yacyrghate,yacyrhate,yacqmyghate] = fn_datana(yachate,options_.ms.freq,options_.ms.log_var(1:nlogeno),options_.ms.percent_var(1:npereno)); + % actual and conditional forecast growth rates + if options_.ms.indxgdls && nconstr + keyindx = [1:nvar]; + % conlab=['conditional on' ylab{PorR(1)}]; + conlab=['v-conditions']; + + figure + fn_foregraph(yafyrghate,yact2yrge,keyindx,rnum,cnum,options_.ms.freq,ylab,forelabel,conlab) + end + + if options_.ms.ncsk + Estr = zeros(nfqm,nvar); + Estr(1:2,:) = [ + -2.1838 -1.5779 0.53064 -0.099425 -0.69269 -1.0391 + 1.9407 3.3138 -0.10563 -0.55457 -0.68772 1.3534 + ]; + Estr(3:6,3) = [0.5*ones(1,4)]'; % MD shocks + + Estr(3:10,2) = [1.5 1.5 1.5*ones(1,6)]'; % MS shocks + + %Estr(3:6,6) = 1*ones(4,1); % U shocks + %Estr(8:11,4) = 1*ones(4,1); % y shocks + + %Estr(3:10,2) = [2.5 2.5 1.5*ones(1,6)]'; % MS shocks alone + + nn = [nvar options_.ms.noptions_.ms.nlags nfqm]; + ycEhat = forefixe(A0hat,Bhat,phil,nn,Estr); + ycEhate = [fdates ycEhat]; + yacEhate = [yact1e; ycEhate]; % actual and condtional forecast + %===== Converted to mg, qg, and calendar yg + [yacEyrghate,yacEyrhate,yacEqmyghate] = datana(yacEhate,options_.ms.freq,options_.ms.log_var(1:nlogeno),options_.ms.percent_var(1:npereno)); + % actual and conditional forecast growth rates + disp([sprintf('%4.0f %2.0f %8.3f %8.3f %8.3f %8.3f %8.3f %8.3f\n',yacEyrghate')]) + + if 1 + keyindx = [1:nvar]; + % conlab=['conditional on' ylab{PorR(1)}]; + conlab=['shock-conditions']; + + figure + gyrfore(yacEyrghate,yact2yrge,keyindx,rnum,cnum,ylab,forelabel,conlab) + end + end + + %----------------------------------------------------------- + % Compute structural shocks for the whole sample period excluding dummy observations. + %----------------------------------------------------------- + ywod = y(options_.ms.dummy_obs +1:end,:); % without dummy observations + phiwod=phi(options_.ms.dummy_obs +1:end,:); % without dummy observations + eplhat=ywod*A0hat-phiwod*Fhat; + qmStartWod = mod(qmStart+options_.ms.nlags ,options_.ms.freq); + if (~qmStartWod) + qmStartWod = options_.ms.freq; + end + yrStartWod = yrStart + floor((qmStart+options_.ms.nlags -1)/options_.ms.freq); + dateswod = fn_dataext([yrStartWod qmStartWod],[yrEnd qmEnd],xdatae(:,[1:2])); + eplhate = [dateswod eplhat]; + + Aphat = Fhat; end %---------------------------------------- diff --git a/matlab/ms-sbvar/msstart_setup.m b/matlab/ms-sbvar/msstart_setup.m index 37b6e27e9e..c951ad4eda 100644 --- a/matlab/ms-sbvar/msstart_setup.m +++ b/matlab/ms-sbvar/msstart_setup.m @@ -26,14 +26,14 @@ % Exordium I %=========================================== format short g % format -% -%options_.ms.freq = 4; % quarters or months -%options_.ms.initial_year=1959; % beginning of the year -%options_.ms.initial_subperiod=1; % begining of the quarter or month -%options_.ms.final_year=2005; % final year -%options_.ms.final_subperiod=4; % final month or quarter + % + %options_.ms.freq = 4; % quarters or months + %options_.ms.initial_year=1959; % beginning of the year + %options_.ms.initial_subperiod=1; % begining of the quarter or month + %options_.ms.final_year=2005; % final year + %options_.ms.final_subperiod=4; % final month or quarter nData=(options_.ms.final_year-options_.ms.initial_year)*options_.ms.freq + (options_.ms.final_subperiod-options_.ms.initial_subperiod+1); - % total number of the available data -- this is all you have +% total number of the available data -- this is all you have %*** Load data and series %load datainf_argen.prn % the default name for the variable is "options_.ms.data". @@ -61,19 +61,19 @@ nvar = length(options_.varobs); % number of endogenous variables nlogeno = length(options_.ms.log_var); % number of endogenous variables in options_.ms.log_var npereno = length(options_.ms.percent_var); % number of endogenous variables in options_.ms.percent_var if (nvar~=(nlogeno+npereno)) - skipline() - warning('Check xlab, nlogeno or npereno to make sure of endogenous variables in options_.ms.vlist') - disp('Press ctrl-c to abort') - return + skipline() + warning('Check xlab, nlogeno or npereno to make sure of endogenous variables in options_.ms.vlist') + disp('Press ctrl-c to abort') + return elseif (nvar==length(options_.ms.vlist)) - nexo=1; % only constants as an exogenous variable. The default setting. + nexo=1; % only constants as an exogenous variable. The default setting. elseif (nvar<length(options_.ms.vlist)) - nexo=length(options_.ms.vlist)-nvar+1; + nexo=length(options_.ms.vlist)-nvar+1; else - skipline() - warning('Make sure there are only nvar endogenous variables in options_.ms.vlist') - disp('Press ctrl-c to abort') - return + skipline() + warning('Make sure there are only nvar endogenous variables in options_.ms.vlist') + disp('Press ctrl-c to abort') + return end @@ -84,24 +84,24 @@ yrEnd=options_.ms.final_year; qmEnd=options_.ms.final_subperiod; %options_.forecast = 4; % number of years for forecasting if options_.forecast<1 - error('To be safe, the number of forecast years should be at least 1') + error('To be safe, the number of forecast years should be at least 1') end forelabel = [num2str(yrEnd) ':' num2str(qmEnd) ' Forecast']; nSample=(yrEnd-yrStart)*options_.ms.freq + (qmEnd-qmStart+1); if qmEnd==options_.ms.freq - E1yrqm = [yrEnd+1 1]; % first year and quarter (month) after the sample + E1yrqm = [yrEnd+1 1]; % first year and quarter (month) after the sample else - E1yrqm = [yrEnd qmEnd+1]; % first year and quarter (month) after the sample + E1yrqm = [yrEnd qmEnd+1]; % first year and quarter (month) after the sample end E2yrqm = [yrEnd+options_.forecast qmEnd]; % end at the last month (quarter) of a calendar year after the sample [fdates,nfqm]=fn_calyrqm(options_.ms.freq,E1yrqm,E2yrqm); % forecast dates and number of forecast dates [sdates,nsqm] = fn_calyrqm(options_.ms.freq,[yrStart qmStart],[yrEnd qmEnd]); - % sdates: dates for the whole sample (including options_.ms.nlags) +% sdates: dates for the whole sample (including options_.ms.nlags) if nSample~=nsqm - warning('Make sure that nSample is consistent with the size of sdates') - disp('Hit any key to continue, or ctrl-c to abort') - pause + warning('Make sure that nSample is consistent with the size of sdates') + disp('Hit any key to continue, or ctrl-c to abort') + pause end imstp = 4*options_.ms.freq; % <<>> impulse responses (4 years) nayr = 4; %options_.forecast; % number of years before forecasting for plotting. @@ -110,18 +110,18 @@ nayr = 4; %options_.forecast; % number of years before forecasting for plotting %------- Prior, etc. ------- %options_.ms.nlags = 4; % number of options_.ms.nlags %options_.ms.cross_restrictions = 0; % 1: cross-A0-and-A+ restrictions; 0: options_.ms.restriction_fname is all we have - % Example for indxOres==1: restrictions of the form P(t) = P(t-1). +% Example for indxOres==1: restrictions of the form P(t) = P(t-1). %options_.ms.contemp_reduced_form = 0; % 1: contemporaneous recursive reduced form; 0: restricted (non-recursive) form %options_.ms.real_pseudo_forecast = 0; % 1: options_.ms.real_pseudo_forecast forecasts; 0: real time forecasts %options_.ms.bayesian_prior = 1; % 1: Bayesian prior; 0: no prior indxDummy = options_.ms.bayesian_prior; % 1: add dummy observations to the data; 0: no dummy added. -%options_.ms.dummy_obs = 0; % No dummy observations for xtx, phi, fss, xdatae, etc. Dummy observations are used as an explicit prior in fn_rnrprior_covres_dobs.m. -%if indxDummy -% options_.ms.dummy_obs=nvar+1; % number of dummy observations -%else -% options_.ms.dummy_obs=0; % no dummy observations -%end -%=== The following mu is effective only if options_.ms.bayesian_prior==1. + %options_.ms.dummy_obs = 0; % No dummy observations for xtx, phi, fss, xdatae, etc. Dummy observations are used as an explicit prior in fn_rnrprior_covres_dobs.m. + %if indxDummy + % options_.ms.dummy_obs=nvar+1; % number of dummy observations + %else + % options_.ms.dummy_obs=0; % no dummy observations + %end + %=== The following mu is effective only if options_.ms.bayesian_prior==1. mu = options_.ms.coefficients_prior_hyperparameters; @@ -142,18 +142,18 @@ tdf = 3; % degrees of freedom for t-dist for initial draw of the MC loo nbuffer = 1000; % a block or buffer of draws (buffer) that is saved to the disk (not memory) ndraws1=1*nbuffer; % 1st part of Monte Carlo draws ndraws2=10*ndraws1; % 2nd part of Monte Carlo draws -% seednumber = options_.DynareRandomStreams.seed; %7910; %472534; % if 0, random state at each clock time -% % good one 420 for [29 45], [29 54] -% if seednumber -% randn('state',seednumber); -% rand('state',seednumber); -% else -% randn('state',fix(100*sum(clock))); -% rand('state',fix(100*sum(clock))); -% end -% nstarts=1 % number of starting points -% imndraws = nstarts*ndraws2; % total draws for impulse responses or forecasts -%<<<<<<<<<<<<<<<<<<< + % seednumber = options_.DynareRandomStreams.seed; %7910; %472534; % if 0, random state at each clock time + % % good one 420 for [29 45], [29 54] + % if seednumber + % randn('state',seednumber); + % rand('state',seednumber); + % else + % randn('state',fix(100*sum(clock))); + % rand('state',fix(100*sum(clock))); + % end + % nstarts=1 % number of starting points + % imndraws = nstarts*ndraws2; % total draws for impulse responses or forecasts + %<<<<<<<<<<<<<<<<<<< diff --git a/matlab/ms-sbvar/plot_ms_forecast.m b/matlab/ms-sbvar/plot_ms_forecast.m index c6f0661f3c..c76f8af895 100644 --- a/matlab/ms-sbvar/plot_ms_forecast.m +++ b/matlab/ms-sbvar/plot_ms_forecast.m @@ -32,122 +32,122 @@ function plot_ms_forecast(M_, options_, forecast, figure_name) % You should have received a copy of the GNU General Public License % along with Dynare. If not, see <http://www.gnu.org/licenses/>. - nc = 2; - nr = 2; - nvars = M_.endo_nbr; - endo_names = M_.endo_names; - var_list = endo_names(1:M_.orig_endo_nbr,:); - names = {}; - tex_names = {}; - m = 1; - for i = 1:size(var_list) - tmp = strmatch(var_list(i,:),endo_names,'exact'); - if isempty(tmp) - error([var_list(i,:) ' isn''t and endogenous variable']) - end - tex_name = deblank(M_.endo_names_tex(i,:)); - if ~isempty(tex_name) - names{m} = deblank(var_list(i,:)); - tex_names{m} = tex_name; - m = m + 1; - end +nc = 2; +nr = 2; +nvars = M_.endo_nbr; +endo_names = M_.endo_names; +var_list = endo_names(1:M_.orig_endo_nbr,:); +names = {}; +tex_names = {}; +m = 1; +for i = 1:size(var_list) + tmp = strmatch(var_list(i,:),endo_names,'exact'); + if isempty(tmp) + error([var_list(i,:) ' isn''t and endogenous variable']) end - - dims = size(forecast); - if (length(dims) == 2) - % Point Forecast (horizon x nvars ) - horizon = dims(1); - num_percentiles = 1; - elseif (length(dims) == 3) - % Banded Forecast - horizon = dims(2); - num_percentiles = dims(1); - else - error('The impulse response matrix passed to be plotted does not appear to be the correct size'); + tex_name = deblank(M_.endo_names_tex(i,:)); + if ~isempty(tex_name) + names{m} = deblank(var_list(i,:)); + tex_names{m} = tex_name; + m = m + 1; end +end - if num_percentiles == 1 - plot_point_forecast(forecast, nvars, nr, nc, var_list, figure_name, ... - options_.graph_save_formats, options_.TeX, names, tex_names, ... - [options_.ms.output_file_tag filesep 'Output' filesep 'Forecast']); - else - plot_banded_forecast(forecast, nvars, nr, nc, var_list, num_percentiles, ... - figure_name, options_.graph_save_formats, options_.TeX, names, tex_names, ... - [options_.ms.output_file_tag filesep 'Output' filesep 'Forecast']); - end +dims = size(forecast); +if (length(dims) == 2) + % Point Forecast (horizon x nvars ) + horizon = dims(1); + num_percentiles = 1; +elseif (length(dims) == 3) + % Banded Forecast + horizon = dims(2); + num_percentiles = dims(1); +else + error('The impulse response matrix passed to be plotted does not appear to be the correct size'); +end + +if num_percentiles == 1 + plot_point_forecast(forecast, nvars, nr, nc, var_list, figure_name, ... + options_.graph_save_formats, options_.TeX, names, tex_names, ... + [options_.ms.output_file_tag filesep 'Output' filesep 'Forecast']); +else + plot_banded_forecast(forecast, nvars, nr, nc, var_list, num_percentiles, ... + figure_name, options_.graph_save_formats, options_.TeX, names, tex_names, ... + [options_.ms.output_file_tag filesep 'Output' filesep 'Forecast']); +end end function plot_point_forecast(forecast,nvars,nr,nc,endo_names,figure_name,save_graph_formats,TeX,names,tex_names,dirname) - if nvars > nr*nc - graph_name = ['MS (1) ' figure_name]; - figure('Name', graph_name); - else - graph_name = figure_name; - figure('Name', graph_name); - end - m = 1; - n_fig = 1; - for j=1:nvars - if m > nr*nc - graph_name = ['MS (' int2str(n_fig) ') ' figure_name]; - dyn_save_graph(dirname,['MS-forecast-' int2str(n_fig)],... - save_graph_formats,TeX,names,tex_names,graph_name); - n_fig =n_fig+1; - figure('Name', graph_name); - m = 1; - end - subplot(nr,nc,m); - vn = deblank(endo_names(j,:)); - plot(forecast(:,j)) - title(vn,'Interpreter','none'); - grid on; - m = m+1; - end - if m > 1 +if nvars > nr*nc + graph_name = ['MS (1) ' figure_name]; + figure('Name', graph_name); +else + graph_name = figure_name; + figure('Name', graph_name); +end +m = 1; +n_fig = 1; +for j=1:nvars + if m > nr*nc + graph_name = ['MS (' int2str(n_fig) ') ' figure_name]; dyn_save_graph(dirname,['MS-forecast-' int2str(n_fig)],... save_graph_formats,TeX,names,tex_names,graph_name); + n_fig =n_fig+1; + figure('Name', graph_name); + m = 1; end + subplot(nr,nc,m); + vn = deblank(endo_names(j,:)); + plot(forecast(:,j)) + title(vn,'Interpreter','none'); + grid on; + m = m+1; +end +if m > 1 + dyn_save_graph(dirname,['MS-forecast-' int2str(n_fig)],... + save_graph_formats,TeX,names,tex_names,graph_name); +end end function plot_banded_forecast(forecast,nvars,nr,nc,endo_names,num_percentiles,figure_name,save_graph_formats,TeX,names,tex_names,dirname) - if nvars > nr*nc - graph_name = ['MS (1) ' figure_name]; - figure('Name', graph_name); - else - graph_name = figure_name; - figure('Name', graph_name); +if nvars > nr*nc + graph_name = ['MS (1) ' figure_name]; + figure('Name', graph_name); +else + graph_name = figure_name; + figure('Name', graph_name); +end +m = 1; +n_fig = 1; +for j=1:nvars + if m > nr*nc + graph_name = ['MS (' int2str(n_fig) ') ' figure_name]; + dyn_save_graph(dirname,['MS-forecast-' int2str(n_fig)],... + save_graph_formats,TeX,names,tex_names,graph_name); + n_fig =n_fig+1; + figure('Name',graph_name); + m = 1; end - m = 1; - n_fig = 1; - for j=1:nvars - if m > nr*nc - graph_name = ['MS (' int2str(n_fig) ') ' figure_name]; - dyn_save_graph(dirname,['MS-forecast-' int2str(n_fig)],... - save_graph_formats,TeX,names,tex_names,graph_name); - n_fig =n_fig+1; - figure('Name',graph_name); - m = 1; + subplot(nr,nc,m); + vn = deblank(endo_names(j,:)); + for k=1:num_percentiles + if ceil(num_percentiles/2) == k + plot(forecast(k,:,j),'LineWidth',1.5) + else + plot(forecast(k,:,j),'LineWidth',1.1) end - subplot(nr,nc,m); - vn = deblank(endo_names(j,:)); - for k=1:num_percentiles - if ceil(num_percentiles/2) == k - plot(forecast(k,:,j),'LineWidth',1.5) - else - plot(forecast(k,:,j),'LineWidth',1.1) - end - if k==1 - hold on; - end + if k==1 + hold on; end - title(vn,'Interpreter','none'); - hold off - grid on; - m = m+1; - end - if m > 1 - dyn_save_graph(dirname,['MS-forecast-' int2str(n_fig)],... - save_graph_formats,TeX,names,tex_names,graph_name); end + title(vn,'Interpreter','none'); + hold off + grid on; + m = m+1; +end +if m > 1 + dyn_save_graph(dirname,['MS-forecast-' int2str(n_fig)],... + save_graph_formats,TeX,names,tex_names,graph_name); +end end diff --git a/matlab/ms-sbvar/plot_ms_irf.m b/matlab/ms-sbvar/plot_ms_irf.m index 82c9727479..39ca642cff 100644 --- a/matlab/ms-sbvar/plot_ms_irf.m +++ b/matlab/ms-sbvar/plot_ms_irf.m @@ -32,108 +32,108 @@ function plot_ms_irf(M_, options_, irf, figure_name, varlist) % You should have received a copy of the GNU General Public License % along with Dynare. If not, see <http://www.gnu.org/licenses/>. - if nargin < 4 - figure_name = ''; - end +if nargin < 4 + figure_name = ''; +end - nvars = M_.endo_nbr; - endo_names = M_.endo_names; +nvars = M_.endo_nbr; +endo_names = M_.endo_names; - if isempty(varlist) - var_list = endo_names(1:M_.orig_endo_nbr,:); - end +if isempty(varlist) + var_list = endo_names(1:M_.orig_endo_nbr,:); +end - names = {}; - tex_names = {}; - m = 1; - for i = 1:size(var_list) - tmp = strmatch(var_list(i,:),endo_names,'exact'); - if isempty(tmp) - error([var_list(i,:) ' isn''t and endogenous variable']) - end - tex_name = deblank(M_.endo_names_tex(tmp,:)); - if ~isempty(tex_name) - names{m} = deblank(var_list(i,:)); - tex_names{m} = tex_name; - m = m + 1; - end +names = {}; +tex_names = {}; +m = 1; +for i = 1:size(var_list) + tmp = strmatch(var_list(i,:),endo_names,'exact'); + if isempty(tmp) + error([var_list(i,:) ' isn''t and endogenous variable']) end - - for i=1:M_.exo_nbr - tex_name = deblank(M_.exo_names_tex(i,:)); - if ~isempty(tex_name) - names{m} = deblank(M_.exo_names(i,:)); - tex_names{m} = tex_name; - m = m + 1; - end + tex_name = deblank(M_.endo_names_tex(tmp,:)); + if ~isempty(tex_name) + names{m} = deblank(var_list(i,:)); + tex_names{m} = tex_name; + m = m + 1; end +end - dims = size(irf); - if (length(dims) == 2) - % Point IRF (horizon x (nvarsxnvars) ) - horizon = dims(1); - num_percentiles = 1; - elseif (length(dims) == 3) - % Banded IRF - horizon = dims(2); - num_percentiles = dims(1); - else - error('The impulse response matrix passed to be plotted does not appear to be the correct size'); +for i=1:M_.exo_nbr + tex_name = deblank(M_.exo_names_tex(i,:)); + if ~isempty(tex_name) + names{m} = deblank(M_.exo_names(i,:)); + tex_names{m} = tex_name; + m = m + 1; end +end - if size(endo_names,1) ~= nvars - error('The names passed are not the same length as the number of variables'); - end +dims = size(irf); +if (length(dims) == 2) + % Point IRF (horizon x (nvarsxnvars) ) + horizon = dims(1); + num_percentiles = 1; +elseif (length(dims) == 3) + % Banded IRF + horizon = dims(2); + num_percentiles = dims(1); +else + error('The impulse response matrix passed to be plotted does not appear to be the correct size'); +end - if num_percentiles == 1 - % loop through the shocks - for s=1:nvars - shock = zeros(horizon,nvars); - for i=1:nvars - shock(:,i) = irf(:,((i-1) + ((s-1)*nvars)+1)); - end - plot_point_irf_for_shock(shock, nvars,endo_names, deblank(endo_names(s,:)), ... - figure_name, [options_.ms.output_file_tag filesep 'Output' filesep 'IRF'], options_, names, tex_names); +if size(endo_names,1) ~= nvars + error('The names passed are not the same length as the number of variables'); +end + +if num_percentiles == 1 + % loop through the shocks + for s=1:nvars + shock = zeros(horizon,nvars); + for i=1:nvars + shock(:,i) = irf(:,((i-1) + ((s-1)*nvars)+1)); end - else - for s=1:nvars - shock = zeros(horizon,nvars,num_percentiles); - for n=1:num_percentiles - for i=1:nvars - shock(:,i,n) = irf(n,:,((i-1) + ((s-1)*nvars)+1)); - end + plot_point_irf_for_shock(shock, nvars,endo_names, deblank(endo_names(s,:)), ... + figure_name, [options_.ms.output_file_tag filesep 'Output' filesep 'IRF'], options_, names, tex_names); + end +else + for s=1:nvars + shock = zeros(horizon,nvars,num_percentiles); + for n=1:num_percentiles + for i=1:nvars + shock(:,i,n) = irf(n,:,((i-1) + ((s-1)*nvars)+1)); end - plot_banded_irf_for_shock(shock, nvars,endo_names, deblank(endo_names(s,:)), ... - figure_name, [options_.ms.output_file_tag filesep 'Output' filesep 'IRF'], options_, names, tex_names); end + plot_banded_irf_for_shock(shock, nvars,endo_names, deblank(endo_names(s,:)), ... + figure_name, [options_.ms.output_file_tag filesep 'Output' filesep 'IRF'], options_, names, tex_names); end end +end function [fig] = plot_point_irf_for_shock(irf,nvars,endo_names,shock_name,figure_name,dirname,options_,names,tex_names) - fig = figure('Name',figure_name); - for k=1:nvars - subplot(ceil(sqrt(nvars)), ceil(sqrt(nvars)),k); - plot(irf(:,k)) - disp([endo_names(k,:) ' shock from ' shock_name]); - title([endo_names(k,:) ' shock from ' shock_name]); - end - dyn_save_graph(dirname,[figure_name ' ' shock_name],options_.graph_save_formats, ... - options_.TeX,names,tex_names,[figure_name ' ' shock_name]); +fig = figure('Name',figure_name); +for k=1:nvars + subplot(ceil(sqrt(nvars)), ceil(sqrt(nvars)),k); + plot(irf(:,k)) + disp([endo_names(k,:) ' shock from ' shock_name]); + title([endo_names(k,:) ' shock from ' shock_name]); +end +dyn_save_graph(dirname,[figure_name ' ' shock_name],options_.graph_save_formats, ... + options_.TeX,names,tex_names,[figure_name ' ' shock_name]); end function [fig] = plot_banded_irf_for_shock(irf,nvars, endo_names, shock_name,figure_name,dirname,options_,names,tex_names) - fig = figure('Name',figure_name); - npercentiles = size(irf,3); - for k=1:nvars - subplot(ceil(sqrt(nvars)), ceil(sqrt(nvars)),k); - for nn=1:npercentiles - plot(irf(:,k,nn)) - hold on - end - hold off - disp([endo_names(k,:) ' shock from ' shock_name]); - title([endo_names(k,:) ' shock from ' shock_name]); +fig = figure('Name',figure_name); +npercentiles = size(irf,3); +for k=1:nvars + subplot(ceil(sqrt(nvars)), ceil(sqrt(nvars)),k); + for nn=1:npercentiles + plot(irf(:,k,nn)) + hold on end - dyn_save_graph(dirname,[figure_name ' ' shock_name],options_.graph_save_formats, ... - options_.TeX,names,tex_names,[figure_name ' ' shock_name]); + hold off + disp([endo_names(k,:) ' shock from ' shock_name]); + title([endo_names(k,:) ' shock from ' shock_name]); +end +dyn_save_graph(dirname,[figure_name ' ' shock_name],options_.graph_save_formats, ... + options_.TeX,names,tex_names,[figure_name ' ' shock_name]); end diff --git a/matlab/ms-sbvar/plot_ms_probabilities.m b/matlab/ms-sbvar/plot_ms_probabilities.m index 023ecfd449..3fd26eab12 100644 --- a/matlab/ms-sbvar/plot_ms_probabilities.m +++ b/matlab/ms-sbvar/plot_ms_probabilities.m @@ -27,41 +27,41 @@ function plot_ms_probabilities(computed_probabilities, options_) % % You should have received a copy of the GNU General Public License % along with Dynare. If not, see <http://www.gnu.org/licenses/>. - - [T,num_grand_regimes] = size(computed_probabilities); - num_chains = length(options_.ms.ms_chain); - for i=1:num_chains + +[T,num_grand_regimes] = size(computed_probabilities); +num_chains = length(options_.ms.ms_chain); +for i=1:num_chains chains(i).num_regimes = length(options_.ms.ms_chain(i).regime); chains(i).probabilities = zeros([T,chains(i).num_regimes]); - end - - for t=1:T +end + +for t=1:T chains = iterate_chain(computed_probabilities(t,:), t, chains, 1, num_chains); - end - - for i=1:num_chains +end + +for i=1:num_chains graph_name = ['MS-Probabilities, Chain ' int2str(i)]; figure('Name',graph_name) plot(chains(i).probabilities,'LineWidth', 1.2); ltxt = {}; for j=1:chains(i).num_regimes - ltxt{j} = ['Regime ' int2str(j)]; + ltxt{j} = ['Regime ' int2str(j)]; end legend(ltxt{:}); title(['Chain ' int2str(i)]); ylim([0 1.0]); dyn_save_graph([options_.ms.output_file_tag filesep 'Output' filesep 'Probabilities'], ['MS-Probabilities-Chain-' int2str(i)], ... - options_.graph_save_formats,options_.TeX,[],[],graph_name); - end + options_.graph_save_formats,options_.TeX,[],[],graph_name); +end end function [chains] = iterate_chain(probs, t, chains, chain, num_chains) - offset_length = length(probs)/chains(chain).num_regimes; - for i=1:chains(chain).num_regimes +offset_length = length(probs)/chains(chain).num_regimes; +for i=1:chains(chain).num_regimes p = probs( (i-1)*offset_length+1 : i*offset_length ); chains(chain).probabilities(t, i) = chains(chain).probabilities(t, i) + sum( p ); if chain < num_chains - chains = iterate_chain(p, t, chains, chain+1, num_chains); + chains = iterate_chain(p, t, chains, chain+1, num_chains); end - end +end end diff --git a/matlab/ms-sbvar/plot_ms_variance_decomposition.m b/matlab/ms-sbvar/plot_ms_variance_decomposition.m index 7cd30dca84..9a9e85fe7e 100644 --- a/matlab/ms-sbvar/plot_ms_variance_decomposition.m +++ b/matlab/ms-sbvar/plot_ms_variance_decomposition.m @@ -9,12 +9,12 @@ function plot_ms_variance_decomposition(M_, options_, vd, figure_name, varargin) % figure_name: (string) graph name % % OPTIONAL INPUTS -% 'data': the actual data, TxK with K=number of data series -% 'steady': the steady state value, TxK -% 'shock_names': to specify the names of the shocks -% 'series_names': to specify the names of the different series -% 'dates': pass a date vector to use, otherwise will just index on 1:T -% 'colors': Jx3 list of the rgb colors to use for each shock +% 'data': the actual data, TxK with K=number of data series +% 'steady': the steady state value, TxK +% 'shock_names': to specify the names of the shocks +% 'series_names': to specify the names of the different series +% 'dates': pass a date vector to use, otherwise will just index on 1:T +% 'colors': Jx3 list of the rgb colors to use for each shock % % OUTPUTS % none @@ -44,130 +44,130 @@ if length(size(vd)) == 3 return; end - nvars = M_.endo_nbr; - endo_names = M_.endo_names; +nvars = M_.endo_nbr; +endo_names = M_.endo_names; - names = {}; - tex_names = {}; - m = 1; - for i=1:M_.orig_endo_nbr - tex_name = deblank(M_.endo_names_tex(i,:)); - if ~isempty(tex_name) - names{m} = deblank(endo_names(i,:)); - tex_names{m} = tex_name; - m = m + 1; - end +names = {}; +tex_names = {}; +m = 1; +for i=1:M_.orig_endo_nbr + tex_name = deblank(M_.endo_names_tex(i,:)); + if ~isempty(tex_name) + names{m} = deblank(endo_names(i,:)); + tex_names{m} = tex_name; + m = m + 1; end +end - dims = size(vd); - if length(dims) == 3 - T = dims(1); - K = dims(2); - J = dims(3); - shocks = vd; - else - T = dims(1); - K = nvars; - J = nvars; - temp_vd = zeros(T,K,J); - for i=1:nvars - for j=1:nvars - temp_vd(:,i,j) = vd(:,((j-1) + ((i-1)*nvars)+1)); - end +dims = size(vd); +if length(dims) == 3 + T = dims(1); + K = dims(2); + J = dims(3); + shocks = vd; +else + T = dims(1); + K = nvars; + J = nvars; + temp_vd = zeros(T,K,J); + for i=1:nvars + for j=1:nvars + temp_vd(:,i,j) = vd(:,((j-1) + ((i-1)*nvars)+1)); end - shocks = temp_vd; end + shocks = temp_vd; +end - for i=1:nvars - shock_names{i} = endo_names(i,:); - series_names{i} = endo_names(i,:); - end +for i=1:nvars + shock_names{i} = endo_names(i,:); + series_names{i} = endo_names(i,:); +end - x = [1:T]; - plot_dates = 0; - data = 0; - steady = 0; - colors = [ .1 .1 .75 - .8 0 0 - 1 .7 .25 - 1 1 0 - .5 1 .5 - .7 .7 .1 - .5 .6 .2 - .1 .5 .1]; +x = [1:T]; +plot_dates = 0; +data = 0; +steady = 0; +colors = [ .1 .1 .75 + .8 0 0 + 1 .7 .25 + 1 1 0 + .5 1 .5 + .7 .7 .1 + .5 .6 .2 + .1 .5 .1]; - % overide the defaults with optional inputs - for i=1:length(varargin) - if strcmpi(varargin{i},'data') - data = varargin{i+1}; - elseif strcmpi(varargin{i},'steady') - steady = varargin{i+1}; - elseif strcmpi(varargin{i},'shock_names') - shock_names = varargin{i+1}; - elseif strcmpi(varargin{i},'series_names') - series_names = varargin{i+1}; - elseif strcmpi(varargin{i}, 'dates') - x = varargin{i+1}; plot_dates = 1; - elseif strcmpi(varargin{i},'colors') - colors = varargin{i+1}; - end +% overide the defaults with optional inputs +for i=1:length(varargin) + if strcmpi(varargin{i},'data') + data = varargin{i+1}; + elseif strcmpi(varargin{i},'steady') + steady = varargin{i+1}; + elseif strcmpi(varargin{i},'shock_names') + shock_names = varargin{i+1}; + elseif strcmpi(varargin{i},'series_names') + series_names = varargin{i+1}; + elseif strcmpi(varargin{i}, 'dates') + x = varargin{i+1}; plot_dates = 1; + elseif strcmpi(varargin{i},'colors') + colors = varargin{i+1}; end +end - % add an extra period to the time series - x(T+1) = x(T) + (x(T) - x(T-1)); +% add an extra period to the time series +x(T+1) = x(T) + (x(T) - x(T-1)); - figure('Name',figure_name) - for k=1:K - % Go through each series - subplot(K,1,k); - sshocks = shocks(:,k,:); - hold on - % plot the stacked shocks - for t=1:T - % step through each time period - pos_position = 0; neg_position = 0; - xt = [x(t) x(t) x(t+1) x(t+1)]; - for j=1:J - % stack each shock - st = sshocks(t,1,j); - if st < 0 - yi = st+neg_position; - y = [neg_position yi yi neg_position]; - neg_position = yi; - else - yi = st+pos_position; - y = [pos_position yi yi pos_position]; - pos_position = yi; - end - fill(xt,y,colors(j,:)); - XY(t,j,:) = y; - end - end - if data - plot(x(2:end)',data(:,k),'k','LineWidth',2.5); - end - if steady - plot(x(2:end)',steady(:,k), '--k','LineWidth',2.25); - end - if k==K - if isoctave - legend(shock_names,'Location','SouthOutside'); +figure('Name',figure_name) +for k=1:K + % Go through each series + subplot(K,1,k); + sshocks = shocks(:,k,:); + hold on + % plot the stacked shocks + for t=1:T + % step through each time period + pos_position = 0; neg_position = 0; + xt = [x(t) x(t) x(t+1) x(t+1)]; + for j=1:J + % stack each shock + st = sshocks(t,1,j); + if st < 0 + yi = st+neg_position; + y = [neg_position yi yi neg_position]; + neg_position = yi; else - legend(shock_names,'Location','BestOutside','Orientation','horizontal'); + yi = st+pos_position; + y = [pos_position yi yi pos_position]; + pos_position = yi; end + fill(xt,y,colors(j,:)); + XY(t,j,:) = y; end - - hold off - if plot_dates - datetick 'x'; + end + if data + plot(x(2:end)',data(:,k),'k','LineWidth',2.5); + end + if steady + plot(x(2:end)',steady(:,k), '--k','LineWidth',2.25); + end + if k==K + if isoctave + legend(shock_names,'Location','SouthOutside'); + else + legend(shock_names,'Location','BestOutside','Orientation','horizontal'); end - xlim([min(x),max(x)]) - ylim([0 , 1]) - grid on - title(series_names{k}); end - dyn_save_graph([options_.ms.output_file_tag filesep 'Output' ... - filesep 'Variance_Decomposition'], 'MS-Variance-Decomposition', ... - options_.graph_save_formats, options_.TeX, names, tex_names, ... - 'Variance decomposition'); + + hold off + if plot_dates + datetick 'x'; + end + xlim([min(x),max(x)]) + ylim([0 , 1]) + grid on + title(series_names{k}); +end +dyn_save_graph([options_.ms.output_file_tag filesep 'Output' ... + filesep 'Variance_Decomposition'], 'MS-Variance-Decomposition', ... + options_.graph_save_formats, options_.TeX, names, tex_names, ... + 'Variance decomposition'); end diff --git a/matlab/ms-sbvar/plot_ms_variance_decomposition_error_bands.m b/matlab/ms-sbvar/plot_ms_variance_decomposition_error_bands.m index cc03e87c7f..193c9b59ff 100644 --- a/matlab/ms-sbvar/plot_ms_variance_decomposition_error_bands.m +++ b/matlab/ms-sbvar/plot_ms_variance_decomposition_error_bands.m @@ -79,14 +79,14 @@ for s=1:nvars end end plot_banded_vddata_for_shock(shock, nvars, endo_names, ... - deblank(endo_names(s,:)), figure_name, ... - [options_.ms.output_file_tag filesep 'Output' filesep 'Variance_Decomposition'], ... - options_, names, tex_names); + deblank(endo_names(s,:)), figure_name, ... + [options_.ms.output_file_tag filesep 'Output' filesep 'Variance_Decomposition'], ... + options_, names, tex_names); end end function [fig] = plot_banded_vddata_for_shock(vddata, nvars, endo_names, ... - shock_name, figure_name, dirname, options_, names, tex_names) + shock_name, figure_name, dirname, options_, names, tex_names) fig = figure('Name', figure_name); npercentiles = size(vddata,3); for k=1:nvars @@ -100,6 +100,6 @@ for k=1:nvars title([endo_names(k,:) ' contribution to ' shock_name]); end dyn_save_graph(dirname, [figure_name ' ' shock_name], ... - options_.graph_save_formats, options_.TeX, names, tex_names, ... - [figure_name ' ' shock_name]); + options_.graph_save_formats, options_.TeX, names, tex_names, ... + [figure_name ' ' shock_name]); end diff --git a/matlab/ms-sbvar/svar_global_identification_check.m b/matlab/ms-sbvar/svar_global_identification_check.m index 549d5c7fd4..b0884defe5 100644 --- a/matlab/ms-sbvar/svar_global_identification_check.m +++ b/matlab/ms-sbvar/svar_global_identification_check.m @@ -47,7 +47,7 @@ if isequal(options_.ms.restriction_fname, 'upper_cholesky') || ... end nvar = length(options_.varobs); % number of endogenous variables nexo = 1; - + [Uiconst,Viconst,n0,np,ixmC0Pres,Qi,Ri] = exclusions(nvar,nexo,options_.ms ); % order column constraints by rank diff --git a/matlab/non_linear_dsge_likelihood.m b/matlab/non_linear_dsge_likelihood.m index 57e02a0b7a..43574d4e95 100644 --- a/matlab/non_linear_dsge_likelihood.m +++ b/matlab/non_linear_dsge_likelihood.m @@ -229,8 +229,8 @@ end if info(1) if info(1) == 3 || info(1) == 4 || info(1) == 5 || info(1)==6 ||info(1) == 19 || ... - info(1) == 20 || info(1) == 21 || info(1) == 23 || info(1) == 26 || ... - info(1) == 81 || info(1) == 84 || info(1) == 85 + info(1) == 20 || info(1) == 21 || info(1) == 23 || info(1) == 26 || ... + info(1) == 81 || info(1) == 84 || info(1) == 85 %meaningful second entry of output that can be used fval = Inf; info(4) = info(2); diff --git a/matlab/occbin/call_solve_one_constraint.m b/matlab/occbin/call_solve_one_constraint.m index b4ec1baed9..d7a83c8361 100755 --- a/matlab/occbin/call_solve_one_constraint.m +++ b/matlab/occbin/call_solve_one_constraint.m @@ -1,21 +1,21 @@ -% Solve model, generate model IRFs -[zdatalinear zdatapiecewise zdatass oobase_ Mbase_ ] = ... - solve_one_constraint(modnam,modnamstar,... - constraint, constraint_relax,... - shockssequence,irfshock,nperiods,maxiter); - - - -% unpack the IRFs -for i=1:Mbase_.endo_nbr - eval([deblank(Mbase_.endo_names(i,:)),'_uncdifference=zdatalinear(:,i);']); - eval([deblank(Mbase_.endo_names(i,:)),'_difference=zdatapiecewise(:,i);']); - eval([deblank(Mbase_.endo_names(i,:)),'_ss=zdatass(i);']); -end - - -nparams = size(Mbase_.param_names,1); - -for i = 1:nparams - eval([Mbase_.param_names(i,:),'= Mbase_.params(i);']); -end +% Solve model, generate model IRFs +[zdatalinear zdatapiecewise zdatass oobase_ Mbase_ ] = ... + solve_one_constraint(modnam,modnamstar,... + constraint, constraint_relax,... + shockssequence,irfshock,nperiods,maxiter); + + + +% unpack the IRFs +for i=1:Mbase_.endo_nbr + eval([deblank(Mbase_.endo_names(i,:)),'_uncdifference=zdatalinear(:,i);']); + eval([deblank(Mbase_.endo_names(i,:)),'_difference=zdatapiecewise(:,i);']); + eval([deblank(Mbase_.endo_names(i,:)),'_ss=zdatass(i);']); +end + + +nparams = size(Mbase_.param_names,1); + +for i = 1:nparams + eval([Mbase_.param_names(i,:),'= Mbase_.params(i);']); +end diff --git a/matlab/occbin/call_solve_two_constraints.m b/matlab/occbin/call_solve_two_constraints.m index b782e6db76..1b54718e5b 100755 --- a/matlab/occbin/call_solve_two_constraints.m +++ b/matlab/occbin/call_solve_two_constraints.m @@ -1,21 +1,21 @@ -[zdatalinear zdatapiecewise zdatass oobase_ Mbase_] = solve_two_constraints(... - modnam_00,modnam_10,modnam_01,modnam_11,... - constraint1, constraint2,... - constraint_relax1, constraint_relax2,... - scalefactormod,irfshock,nperiods,curb_retrench,maxiter); - - -for i=1:Mbase_.endo_nbr - eval([deblank(Mbase_.endo_names(i,:)),'_uncdifference=zdatalinear(:,i);']); - eval([deblank(Mbase_.endo_names(i,:)),'_difference=zdatapiecewise(:,i);']); - eval([deblank(Mbase_.endo_names(i,:)),'_ss=zdatass(i);']); -end - -constraint1_difference = process_constraint(constraint1,'_difference',Mbase_.endo_names,0); -constraint2_difference = process_constraint(constraint2,'_difference',Mbase_.endo_names,0); - -nparams = size(Mbase_.param_names,1); - -for i = 1:nparams - eval([Mbase_.param_names(i,:),'= Mbase_.params(i);']); -end +[zdatalinear zdatapiecewise zdatass oobase_ Mbase_] = solve_two_constraints(... + modnam_00,modnam_10,modnam_01,modnam_11,... + constraint1, constraint2,... + constraint_relax1, constraint_relax2,... + scalefactormod,irfshock,nperiods,curb_retrench,maxiter); + + +for i=1:Mbase_.endo_nbr + eval([deblank(Mbase_.endo_names(i,:)),'_uncdifference=zdatalinear(:,i);']); + eval([deblank(Mbase_.endo_names(i,:)),'_difference=zdatapiecewise(:,i);']); + eval([deblank(Mbase_.endo_names(i,:)),'_ss=zdatass(i);']); +end + +constraint1_difference = process_constraint(constraint1,'_difference',Mbase_.endo_names,0); +constraint2_difference = process_constraint(constraint2,'_difference',Mbase_.endo_names,0); + +nparams = size(Mbase_.param_names,1); + +for i = 1:nparams + eval([Mbase_.param_names(i,:),'= Mbase_.params(i);']); +end diff --git a/matlab/occbin/get_deriv.m b/matlab/occbin/get_deriv.m index 24f1b42aeb..19fe87001a 100755 --- a/matlab/occbin/get_deriv.m +++ b/matlab/occbin/get_deriv.m @@ -1,83 +1,83 @@ -function [hm1,h,hl1,j,resid] = get_deriv(M_,ys_) - -iy_ = M_.lead_lag_incidence; -it_ = 1; - -x = zeros(1,M_.exo_nbr); - -% For most models, there are leads, lags and current values of variables -if size(iy_,1)==3 - % find non-zero columns of hm1 - lag_cols = find(iy_(1,:)~=0); - % find non-zero columns of h - con_cols = find(iy_(2,:)); - % find non-zero columns of hl1 - lea_cols = find(iy_(3,:)); - -% If models either lacks leads or lags, iy_ will have two rows -% In this case, we guess that the row with more nonzeros is the row with current variables -elseif size(iy_,1)==2 - % if first row has more nonzero entries than the second, assume model lacks lagged variables - if length(find(iy_(1,:)))>length(find(iy_(2,:))) - warning('Model does not have lagged endogenous variables') - con_cols = find(iy_(1,:)); - lea_cols = find(iy_(2,:)); - lag_cols = []; - else - warning('Model does not have expected future endogenous variables') - lag_cols = find(iy_(1,:)); - con_cols = find(iy_(2,:)); - lea_cols = []; - end - -end - - - -% find number of entries for y vector -ny = length(find(iy_~=0)); - -% build steady state y -y = ys_(lag_cols); -y = [y;ys_(con_cols)]; -y = [y;ys_(lea_cols)]; - - -if ismac -eval(['[resid,g1]=',M_.fname,'_dynamic(y,x, M_.params, ys_, it_);']); -% Older versions of DYNARE for Mac did not include ys_ in the call structure -%eval(['[resid,g1]=',M_.fname,'_dynamic(y,x, M_.params, it_);']); -else -eval(['[resid,g1]=',M_.fname,'_dynamic(y,x, M_.params, ys_, it_);']); -end - - -hm1=zeros(M_.endo_nbr); -h = hm1; -hl1 = hm1; -j = zeros(M_.endo_nbr,M_.exo_nbr); - - -% build hm1 -nlag_cols = length(lag_cols); -for i=1:nlag_cols - hm1(:,lag_cols(i)) = g1(:,i); -end - -% build h -ncon_cols = length(con_cols); -for i=1:ncon_cols - h(:,con_cols(i)) = g1(:,i+nlag_cols); -end - -% build hl1 -nlea_cols = length(lea_cols); -for i=1:nlea_cols - hl1(:,lea_cols(i)) = g1(:,i+nlag_cols+ncon_cols); -end - - -for i = 1:M_.exo_nbr; - j(:,i) =g1(:,i+ny); -end - +function [hm1,h,hl1,j,resid] = get_deriv(M_,ys_) + +iy_ = M_.lead_lag_incidence; +it_ = 1; + +x = zeros(1,M_.exo_nbr); + +% For most models, there are leads, lags and current values of variables +if size(iy_,1)==3 + % find non-zero columns of hm1 + lag_cols = find(iy_(1,:)~=0); + % find non-zero columns of h + con_cols = find(iy_(2,:)); + % find non-zero columns of hl1 + lea_cols = find(iy_(3,:)); + + % If models either lacks leads or lags, iy_ will have two rows + % In this case, we guess that the row with more nonzeros is the row with current variables +elseif size(iy_,1)==2 + % if first row has more nonzero entries than the second, assume model lacks lagged variables + if length(find(iy_(1,:)))>length(find(iy_(2,:))) + warning('Model does not have lagged endogenous variables') + con_cols = find(iy_(1,:)); + lea_cols = find(iy_(2,:)); + lag_cols = []; + else + warning('Model does not have expected future endogenous variables') + lag_cols = find(iy_(1,:)); + con_cols = find(iy_(2,:)); + lea_cols = []; + end + +end + + + +% find number of entries for y vector +ny = length(find(iy_~=0)); + +% build steady state y +y = ys_(lag_cols); +y = [y;ys_(con_cols)]; +y = [y;ys_(lea_cols)]; + + +if ismac + eval(['[resid,g1]=',M_.fname,'_dynamic(y,x, M_.params, ys_, it_);']); + % Older versions of DYNARE for Mac did not include ys_ in the call structure + %eval(['[resid,g1]=',M_.fname,'_dynamic(y,x, M_.params, it_);']); +else + eval(['[resid,g1]=',M_.fname,'_dynamic(y,x, M_.params, ys_, it_);']); +end + + +hm1=zeros(M_.endo_nbr); +h = hm1; +hl1 = hm1; +j = zeros(M_.endo_nbr,M_.exo_nbr); + + +% build hm1 +nlag_cols = length(lag_cols); +for i=1:nlag_cols + hm1(:,lag_cols(i)) = g1(:,i); +end + +% build h +ncon_cols = length(con_cols); +for i=1:ncon_cols + h(:,con_cols(i)) = g1(:,i+nlag_cols); +end + +% build hl1 +nlea_cols = length(lea_cols); +for i=1:nlea_cols + hl1(:,lea_cols(i)) = g1(:,i+nlag_cols+ncon_cols); +end + + +for i = 1:M_.exo_nbr; + j(:,i) =g1(:,i+ny); +end + diff --git a/matlab/occbin/get_pq.m b/matlab/occbin/get_pq.m index 5caab79af2..6ef8c8ec78 100755 --- a/matlab/occbin/get_pq.m +++ b/matlab/occbin/get_pq.m @@ -1,28 +1,28 @@ -function [p,q]=get_pq(dr_,nstatic,nfwrd); - -nvars = size(dr_.ghx,1); -nshocks = size(dr_.ghu,2); -statevar_pos = (nstatic +1):(nvars-nfwrd); - -p = zeros(nvars); -% interlace matrix -nnotzero = length(statevar_pos); -for i=1:nnotzero - p(:,statevar_pos(i)) = dr_.ghx(:,i); -end - -% reorder p matrix according to order in lgy_ -inverse_order = zeros(nvars,1); -for i=1:nvars - inverse_order(i) = find(i==dr_.order_var); -end - -p_reordered = zeros(nvars); -q = zeros(nvars,nshocks); -for i=1:nvars - for j=1:nvars - p_reordered(i,j)=p(inverse_order(i),inverse_order(j)); - end - q(i,:)=dr_.ghu(inverse_order(i),:); -end +function [p,q]=get_pq(dr_,nstatic,nfwrd); + +nvars = size(dr_.ghx,1); +nshocks = size(dr_.ghu,2); +statevar_pos = (nstatic +1):(nvars-nfwrd); + +p = zeros(nvars); +% interlace matrix +nnotzero = length(statevar_pos); +for i=1:nnotzero + p(:,statevar_pos(i)) = dr_.ghx(:,i); +end + +% reorder p matrix according to order in lgy_ +inverse_order = zeros(nvars,1); +for i=1:nvars + inverse_order(i) = find(i==dr_.order_var); +end + +p_reordered = zeros(nvars); +q = zeros(nvars,nshocks); +for i=1:nvars + for j=1:nvars + p_reordered(i,j)=p(inverse_order(i),inverse_order(j)); + end + q(i,:)=dr_.ghu(inverse_order(i),:); +end p=p_reordered; \ No newline at end of file diff --git a/matlab/occbin/makechart.m b/matlab/occbin/makechart.m index a3801e9566..496a136ba8 100755 --- a/matlab/occbin/makechart.m +++ b/matlab/occbin/makechart.m @@ -1,81 +1,81 @@ -function makechart(titlelist,legendlist,figlabel,ylabels,zdata1,zdata2,zdata3) - - - -figure - -titlelist = char(strrep(cellstr(titlelist),'_','.')); - -ndsets=3; % default, changed below as applicable -if nargin==5 - zdata2=nan*zdata1; - zdata3=nan*zdata1; - ndsets =1; -elseif nargin == 6 - zdata3 =nan*zdata1; - ndsets=2; -elseif ((nargin>8) | (nargin <=4)) - error ('makechart takes 5 to 6 arguments') -end - -nobs = size(zdata1,1); -xvalues = (1:nobs)'; - -nvars = size(titlelist,1); -if nvars==1 - nrows=1; - ncols = 1; -elseif nvars==2 - nrows =2; - ncols = 1; -elseif (nvars == 3 | nvars ==4) - nrows = 2; - ncols =2; -elseif (nvars==5 |nvars ==6) - nrows = 3; - ncols = 2; -elseif (nvars==7 | nvars==8) - nrows = 4; - ncols = 2; -elseif (nvars==9 | nvars==10) - nrows = 5; - ncols = 2; -else - error('too many variables (makechart)') -end - -for i = 1:nvars - subplot(nrows,ncols,i) - h1=plot(xvalues,zdata1(:,i),'b-','linewidth',2); hold on - h1=plot(xvalues,zdata2(:,i),'r--','linewidth',2); hold on - h2=plot(xvalues,zdata3(:,i),'b-','LineWidth',3); - [x0 x1 y10 y11] = pickaxes(xvalues,zdata1(:,i)); - [x0 x1 y20 y21] = pickaxes(xvalues,zdata2(:,i)); - [x0 x1 y30 y31] = pickaxes(xvalues,zdata3(:,i)); - y0 = min([y10,y20,y30]); - y1 = max([y11,y21,y31]); - if y0==y1 - y1=y0+1; - end - - axis([x0 x1 y0 y1]) - set(h1); - - if i==1 && isempty(legendlist)==0 - legend(legendlist) - text('String',figlabel,'Units','normalized','Position',[1.2 1.24],... - 'FontSize',14,'FontWeight','bold','HorizontalAlignment','center'); - end - - if i==nvars | i==nvars-1 - xlabel('Time'); - end -% set(gca,'XTick',xtick) -% set(gca,'XTickLabel',xticklabel) - - title([num2str(i),'. ',titlelist(i,:)]); - ylabel(ylabels(i,:)) -end - -% sets printing preferences -%printpref +function makechart(titlelist,legendlist,figlabel,ylabels,zdata1,zdata2,zdata3) + + + +figure + +titlelist = char(strrep(cellstr(titlelist),'_','.')); + +ndsets=3; % default, changed below as applicable +if nargin==5 + zdata2=nan*zdata1; + zdata3=nan*zdata1; + ndsets =1; +elseif nargin == 6 + zdata3 =nan*zdata1; + ndsets=2; +elseif ((nargin>8) | (nargin <=4)) + error ('makechart takes 5 to 6 arguments') +end + +nobs = size(zdata1,1); +xvalues = (1:nobs)'; + +nvars = size(titlelist,1); +if nvars==1 + nrows=1; + ncols = 1; +elseif nvars==2 + nrows =2; + ncols = 1; +elseif (nvars == 3 | nvars ==4) + nrows = 2; + ncols =2; +elseif (nvars==5 |nvars ==6) + nrows = 3; + ncols = 2; +elseif (nvars==7 | nvars==8) + nrows = 4; + ncols = 2; +elseif (nvars==9 | nvars==10) + nrows = 5; + ncols = 2; +else + error('too many variables (makechart)') +end + +for i = 1:nvars + subplot(nrows,ncols,i) + h1=plot(xvalues,zdata1(:,i),'b-','linewidth',2); hold on + h1=plot(xvalues,zdata2(:,i),'r--','linewidth',2); hold on + h2=plot(xvalues,zdata3(:,i),'b-','LineWidth',3); + [x0 x1 y10 y11] = pickaxes(xvalues,zdata1(:,i)); + [x0 x1 y20 y21] = pickaxes(xvalues,zdata2(:,i)); + [x0 x1 y30 y31] = pickaxes(xvalues,zdata3(:,i)); + y0 = min([y10,y20,y30]); + y1 = max([y11,y21,y31]); + if y0==y1 + y1=y0+1; + end + + axis([x0 x1 y0 y1]) + set(h1); + + if i==1 && isempty(legendlist)==0 + legend(legendlist) + text('String',figlabel,'Units','normalized','Position',[1.2 1.24],... + 'FontSize',14,'FontWeight','bold','HorizontalAlignment','center'); + end + + if i==nvars | i==nvars-1 + xlabel('Time'); + end + % set(gca,'XTick',xtick) + % set(gca,'XTickLabel',xticklabel) + + title([num2str(i),'. ',titlelist(i,:)]); + ylabel(ylabels(i,:)) +end + +% sets printing preferences +%printpref diff --git a/matlab/occbin/makechart9.m b/matlab/occbin/makechart9.m index c6e65afcdf..e876189599 100755 --- a/matlab/occbin/makechart9.m +++ b/matlab/occbin/makechart9.m @@ -1,136 +1,136 @@ -function makechart9(titlelist,legendlist,figlabel,yearshock,ylabels,... - zdata1,zdata2,zdata3,zdata4,zdata5,zdata6,zdata7) - - - -figure - -titlelist = char(strrep(cellstr(titlelist),'_','.')); - -ndsets=7; % default, changed below as applicable -if nargin==6 - zdata2=nan*zdata1; - zdata3=nan*zdata1; - zdata4=nan*zdata1; - zdata5=nan*zdata1; - zdata6=nan*zdata1; - zdata7=nan*zdata1; - ndsets =1; -elseif nargin==7 - zdata3=nan*zdata1; - zdata4=nan*zdata1; - zdata5=nan*zdata1; - zdata6=nan*zdata1; - zdata7=nan*zdata1; - ndsets =2; -elseif nargin == 8 - zdata4 =nan*zdata1; - zdata5 =nan*zdata1; - zdata6=nan*zdata1; - zdata7=nan*zdata1; - ndsets=3; -elseif nargin == 9 - zdata5 =nan*zdata1; - zdata6=nan*zdata1; - zdata7=nan*zdata1; - ndsets=4; -elseif nargin == 10 - zdata6 =nan*zdata1; - zdata7=nan*zdata1; - ndsets=5; -elseif nargin == 11 - zdata7=nan*zdata1; - ndsets=6; -elseif ((nargin>=13) | (nargin <=3)) - error ('makechart takes 4 to 10 arguments') -end - -nobs = size(zdata1,1); - -if yearshock>-100 -xvalues = yearshock+(0:nobs-1)'/4; % Matteo plot year on x axis -else -xvalues = (1:nobs)'; % Matteo plot year on x axis -end - -nvars = size(titlelist,1); -if nvars==1 - nrows=1; - ncols = 1; -elseif nvars==2 - nrows =2; - ncols = 1; -elseif nvars == 3 - nrows = 3; - ncols = 1; -elseif nvars==4 - nrows = 2; - ncols = 2; -elseif (nvars==5 | nvars ==6) - nrows = 3; - ncols = 2; -elseif (nvars==7 | nvars==8) - nrows = 4; - ncols = 2; -elseif nvars>8 & nvars<=12; - nrows = 3; - ncols = 4; -elseif nvars>12 & nvars<=15; - nrows = 5; - ncols = 3; -else - error('too many variables (makechart)') -end - - -for i = 1:nvars - subplot(nrows,ncols,i) - h1=plot(xvalues,zdata1(:,i),'k',... - xvalues,zdata2(:,i),'r',... - xvalues,zdata3(:,i),'b',... - xvalues,zdata4(:,i),'g',... - xvalues,zdata5(:,i),'g',... - xvalues,zdata6(:,i),'c',... - xvalues,zdata7(:,i),'y'); - [x0 x1 y10 y11] = pickaxes(xvalues,zdata1(:,i)); - [x0 x1 y20 y21] = pickaxes(xvalues,zdata2(:,i)); - [x0 x1 y30 y31] = pickaxes(xvalues,zdata3(:,i)); - [x0 x1 y40 y41] = pickaxes(xvalues,zdata4(:,i)); - [x0 x1 y50 y51] = pickaxes(xvalues,zdata5(:,i)); - [x0 x1 y60 y61] = pickaxes(xvalues,zdata6(:,i)); - [x0 x1 y70 y71] = pickaxes(xvalues,zdata7(:,i)); - grid on - y0 = min([y10,y20,y30,y40,y50,y60,y70]); - y1 = max([y11,y21,y31,y41,y51,y61,y71]); - if y0==y1 - y1=y0+1; - end - - axis([x0 x1 y0 y1]) - set(h1,'linewidth',2); - if i==1 - if numel(strvcat(legendlist(1,:))) - h=legend(legendlist,'Location','Northwest'); - set(h,'Fontsize',8) - end - end - if i==1 - if nvars>3 - text('String',figlabel,'Units','normalized','Position',[1.2 1.21],... - 'FontSize',13,'FontWeight','bold','HorizontalAlignment','center'); - else - text('String',figlabel,'Units','normalized','Position',[0.4 1.24],... - 'FontSize',13,'FontWeight','bold','HorizontalAlignment','center'); - end - end - - %set(gca,'XTick',xtick) - %set(gca,'XTickLabel',xticklabel) - - title(titlelist(i,:),'Fontsize',11); - ylabel(ylabels(i,:)) - -end - -% sets printing preferences -%printpref +function makechart9(titlelist,legendlist,figlabel,yearshock,ylabels,... + zdata1,zdata2,zdata3,zdata4,zdata5,zdata6,zdata7) + + + +figure + +titlelist = char(strrep(cellstr(titlelist),'_','.')); + +ndsets=7; % default, changed below as applicable +if nargin==6 + zdata2=nan*zdata1; + zdata3=nan*zdata1; + zdata4=nan*zdata1; + zdata5=nan*zdata1; + zdata6=nan*zdata1; + zdata7=nan*zdata1; + ndsets =1; +elseif nargin==7 + zdata3=nan*zdata1; + zdata4=nan*zdata1; + zdata5=nan*zdata1; + zdata6=nan*zdata1; + zdata7=nan*zdata1; + ndsets =2; +elseif nargin == 8 + zdata4 =nan*zdata1; + zdata5 =nan*zdata1; + zdata6=nan*zdata1; + zdata7=nan*zdata1; + ndsets=3; +elseif nargin == 9 + zdata5 =nan*zdata1; + zdata6=nan*zdata1; + zdata7=nan*zdata1; + ndsets=4; +elseif nargin == 10 + zdata6 =nan*zdata1; + zdata7=nan*zdata1; + ndsets=5; +elseif nargin == 11 + zdata7=nan*zdata1; + ndsets=6; +elseif ((nargin>=13) | (nargin <=3)) + error ('makechart takes 4 to 10 arguments') +end + +nobs = size(zdata1,1); + +if yearshock>-100 + xvalues = yearshock+(0:nobs-1)'/4; % Matteo plot year on x axis +else + xvalues = (1:nobs)'; % Matteo plot year on x axis +end + +nvars = size(titlelist,1); +if nvars==1 + nrows=1; + ncols = 1; +elseif nvars==2 + nrows =2; + ncols = 1; +elseif nvars == 3 + nrows = 3; + ncols = 1; +elseif nvars==4 + nrows = 2; + ncols = 2; +elseif (nvars==5 | nvars ==6) + nrows = 3; + ncols = 2; +elseif (nvars==7 | nvars==8) + nrows = 4; + ncols = 2; +elseif nvars>8 & nvars<=12; + nrows = 3; + ncols = 4; +elseif nvars>12 & nvars<=15; + nrows = 5; + ncols = 3; +else + error('too many variables (makechart)') +end + + +for i = 1:nvars + subplot(nrows,ncols,i) + h1=plot(xvalues,zdata1(:,i),'k',... + xvalues,zdata2(:,i),'r',... + xvalues,zdata3(:,i),'b',... + xvalues,zdata4(:,i),'g',... + xvalues,zdata5(:,i),'g',... + xvalues,zdata6(:,i),'c',... + xvalues,zdata7(:,i),'y'); + [x0 x1 y10 y11] = pickaxes(xvalues,zdata1(:,i)); + [x0 x1 y20 y21] = pickaxes(xvalues,zdata2(:,i)); + [x0 x1 y30 y31] = pickaxes(xvalues,zdata3(:,i)); + [x0 x1 y40 y41] = pickaxes(xvalues,zdata4(:,i)); + [x0 x1 y50 y51] = pickaxes(xvalues,zdata5(:,i)); + [x0 x1 y60 y61] = pickaxes(xvalues,zdata6(:,i)); + [x0 x1 y70 y71] = pickaxes(xvalues,zdata7(:,i)); + grid on + y0 = min([y10,y20,y30,y40,y50,y60,y70]); + y1 = max([y11,y21,y31,y41,y51,y61,y71]); + if y0==y1 + y1=y0+1; + end + + axis([x0 x1 y0 y1]) + set(h1,'linewidth',2); + if i==1 + if numel(strvcat(legendlist(1,:))) + h=legend(legendlist,'Location','Northwest'); + set(h,'Fontsize',8) + end + end + if i==1 + if nvars>3 + text('String',figlabel,'Units','normalized','Position',[1.2 1.21],... + 'FontSize',13,'FontWeight','bold','HorizontalAlignment','center'); + else + text('String',figlabel,'Units','normalized','Position',[0.4 1.24],... + 'FontSize',13,'FontWeight','bold','HorizontalAlignment','center'); + end + end + + %set(gca,'XTick',xtick) + %set(gca,'XTickLabel',xticklabel) + + title(titlelist(i,:),'Fontsize',11); + ylabel(ylabels(i,:)) + +end + +% sets printing preferences +%printpref diff --git a/matlab/occbin/map_regime.m b/matlab/occbin/map_regime.m index a3ed88b478..64a87250e9 100755 --- a/matlab/occbin/map_regime.m +++ b/matlab/occbin/map_regime.m @@ -1,25 +1,25 @@ -function [regime regimestart]=map_regimes(violvecbool) - -nperiods = length(violvecbool)-1; - -% analyse violvec and isolate contiguous periods in the other regime. - regime(1) = violvecbool(1); - regimeindx = 1; - regimestart(1) = 1; - for i=2:nperiods - if violvecbool(i)~=regime(regimeindx) - regimeindx=regimeindx+1; - regime(regimeindx) = violvecbool(i); - regimestart(regimeindx)=i; - end - end - - - if (regime(1) == 1 & length(regimestart)==1) - warning('Increase nperiods'); - end - - if (regime(end)==1) - warning('Increase nperiods'); - end - +function [regime regimestart]=map_regime(violvecbool) + +nperiods = length(violvecbool)-1; + +% analyse violvec and isolate contiguous periods in the other regime. +regime(1) = violvecbool(1); +regimeindx = 1; +regimestart(1) = 1; +for i=2:nperiods + if violvecbool(i)~=regime(regimeindx) + regimeindx=regimeindx+1; + regime(regimeindx) = violvecbool(i); + regimestart(regimeindx)=i; + end +end + + +if (regime(1) == 1 & length(regimestart)==1) + warning('Increase nperiods'); +end + +if (regime(end)==1) + warning('Increase nperiods'); +end + diff --git a/matlab/occbin/mkdata.m b/matlab/occbin/mkdata.m index a7f855743d..02b2eb703e 100755 --- a/matlab/occbin/mkdata.m +++ b/matlab/occbin/mkdata.m @@ -1,63 +1,63 @@ -function [zdata]=mkdata(nperiods,decrulea,decruleb,endog_,exog_,wishlist,irfshock,scalefactormod,init) - -%[nsim, ksim, ysim, isim, csim] = mkdata(nperiods,cofb,endog_) - -% given decision rule -neqs = size(endog_,1); - -if nargin<9 - init = zeros(neqs,1); -end - -if nargin<8 - scalefactormod=1; -end - -if nargin<7 - error('Not enough inputs') -end - -history = zeros(neqs,nperiods+1); - - nshocks = size(irfshock,1); - for i = 1:nshocks - shockpos = strmatch(irfshock(i,:),exog_,'exact'); - if ~isempty(shockpos) - irfshockpos(i) = shockpos; - else - error(['Shock ',irfshock(i,:),' is not in the model']); - end - end - - -% generate data -% history will contain data, the state vector at each period in time will -% be stored columnwise. -history = zeros(neqs,nperiods); -history(:,1)= init; - -lengthshock = size(scalefactormod,1); - -errvec = zeros(size(exog_,1),1); - -for i = 2:nperiods+1 - if i<=(lengthshock+1) - for j = 1:nshocks - errvec(irfshockpos(j)) = scalefactormod(i-1,j); - end - history(:,i) = decrulea * history(:,i-1)+decruleb*errvec; - else - % update endogenous variables - history(:,i) = decrulea * history(:,i-1); - end -end - -% extract desired variables -nwish=size(wishlist,1); -wishpos = zeros(nwish,1); - -history=history'; -for i=1:nwish - wishpos(i) = strmatch(wishlist(i,:),endog_,'exact'); -end +function [zdata]=mkdata(nperiods,decrulea,decruleb,endog_,exog_,wishlist,irfshock,scalefactormod,init) + +%[nsim, ksim, ysim, isim, csim] = mkdata(nperiods,cofb,endog_) + +% given decision rule +neqs = size(endog_,1); + +if nargin<9 + init = zeros(neqs,1); +end + +if nargin<8 + scalefactormod=1; +end + +if nargin<7 + error('Not enough inputs') +end + +history = zeros(neqs,nperiods+1); + +nshocks = size(irfshock,1); +for i = 1:nshocks + shockpos = strmatch(irfshock(i,:),exog_,'exact'); + if ~isempty(shockpos) + irfshockpos(i) = shockpos; + else + error(['Shock ',irfshock(i,:),' is not in the model']); + end +end + + +% generate data +% history will contain data, the state vector at each period in time will +% be stored columnwise. +history = zeros(neqs,nperiods); +history(:,1)= init; + +lengthshock = size(scalefactormod,1); + +errvec = zeros(size(exog_,1),1); + +for i = 2:nperiods+1 + if i<=(lengthshock+1) + for j = 1:nshocks + errvec(irfshockpos(j)) = scalefactormod(i-1,j); + end + history(:,i) = decrulea * history(:,i-1)+decruleb*errvec; + else + % update endogenous variables + history(:,i) = decrulea * history(:,i-1); + end +end + +% extract desired variables +nwish=size(wishlist,1); +wishpos = zeros(nwish,1); + +history=history'; +for i=1:nwish + wishpos(i) = strmatch(wishlist(i,:),endog_,'exact'); +end zdata = history(2:end,wishpos); \ No newline at end of file diff --git a/matlab/occbin/mkdatap_anticipated.m b/matlab/occbin/mkdatap_anticipated.m index 524d3dd5d7..6e745e0a45 100755 --- a/matlab/occbin/mkdatap_anticipated.m +++ b/matlab/occbin/mkdatap_anticipated.m @@ -1,125 +1,125 @@ -function [zdata]=mkdatap_anticipated(nperiods,decrulea,decruleb,... - cof,Jbarmat,cofstar,Jstarbarmat,Dstarbarmat,... - regime,regimestart,violvecbool,... - endog_,exog_,irfshock,scalefactormod,init) - - - -nvars = size(endog_,1); - - -if nargin<16 - init=zeros(nvars,1); -end - -if nargin<15; - scalefactormod=1; -end - - -nshocks = size(irfshock,1); -for i = 1:nshocks - shockpos = strmatch(irfshock(i,:),exog_,'exact'); - if ~isempty(shockpos) - irfshockpos(i) = shockpos; - else - error(['Shock ',irfshock(i,:),' is not in the model']); - end -end - - -nregimes = length(regime); - -Cbarmat = cof(:,1:nvars); -Bbarmat = cof(:,nvars+1:2*nvars); -Abarmat = cof(:,2*nvars+1:3*nvars); - - -% cofstar contains the system for the model when the constraint binds -Cstarbarmat = cofstar(:,1:nvars); -Bstarbarmat = cofstar(:,nvars+1:2*nvars); -Astarbarmat = cofstar(:,2*nvars+1:3*nvars); - -% get the time-dependent decision rules - -Tmax = regimestart(nregimes)-1; % Tmax is the position of the last period -% when the constraint binds - -if Tmax > 0 - P = zeros(nvars,nvars,Tmax); - D = zeros(nvars,Tmax); - - - invmat = inv((Astarbarmat*decrulea+Bstarbarmat)); - P(:,:,Tmax) = -invmat*Cstarbarmat; - D(:,Tmax) = -invmat*Dstarbarmat; - - - % equivalent to pre-multiplying by the inverse above if the target - % matrix is invertible. Otherwise it yields the minimum state solution - %P(:,:,Tmax) = -(Astarbarmat*decrulea+Bstarbarmat)\Cstarbarmat; - %D(:,Tmax) = -(Astarbarmat*decrulea+Bstarbarmat)\Dstarbarmat; - - - for i = Tmax-1:-1:1 - - if violvecbool(i) - invmat = inv(Bstarbarmat+Astarbarmat*P(:,:,i+1)); - P(:,:,i)=-invmat*Cstarbarmat; - D(:,i) = -invmat*(Astarbarmat*D(:,i+1)+Dstarbarmat); - else - invmat = inv(Bbarmat+Abarmat*P(:,:,i+1)); - P(:,:,i)=-invmat*Cbarmat; - D(:,i) = -invmat*(Abarmat*D(:,i+1)); - end - end - -if Tmax > 1 -if violvecbool(1) - E = -invmat*Jstarbarmat; -else - E = -invmat*Jbarmat; -end -else - invmat = inv(Astarbarmat*decrulea+Bstarbarmat); - E = -invmat*Jstarbarmat; - -end - - -end - -% generate data -% history will contain data, the state vector at each period in time will -% be stored columnwise. -history = zeros(nvars,nperiods+1); -history(:,1) = init; -errvec = zeros(size(exog_,1),1); - -% deal with predetermined conditions -for i = 1:nshocks - errvec(irfshockpos(i)) = scalefactormod(i); -end - -% deal with shocks -irfpos =1; -if irfpos <=Tmax - history(:,irfpos+1) = P(:,:,irfpos)* history(:,irfpos)+... - D(:,irfpos) + E*errvec; -else - history(:,irfpos+1) = decrulea*history(:,irfpos)+decruleb*errvec; -end - -% all other periods -for irfpos=2:nperiods+1 - if irfpos <=Tmax - history(:,irfpos+1) = P(:,:,irfpos)* history(:,irfpos)+... - D(:,irfpos); - else - history(:,irfpos+1) = decrulea*history(:,irfpos); - end -end - - -history=history'; +function [zdata]=mkdatap_anticipated(nperiods,decrulea,decruleb,... + cof,Jbarmat,cofstar,Jstarbarmat,Dstarbarmat,... + regime,regimestart,violvecbool,... + endog_,exog_,irfshock,scalefactormod,init) + + + +nvars = size(endog_,1); + + +if nargin<16 + init=zeros(nvars,1); +end + +if nargin<15; + scalefactormod=1; +end + + +nshocks = size(irfshock,1); +for i = 1:nshocks + shockpos = strmatch(irfshock(i,:),exog_,'exact'); + if ~isempty(shockpos) + irfshockpos(i) = shockpos; + else + error(['Shock ',irfshock(i,:),' is not in the model']); + end +end + + +nregimes = length(regime); + +Cbarmat = cof(:,1:nvars); +Bbarmat = cof(:,nvars+1:2*nvars); +Abarmat = cof(:,2*nvars+1:3*nvars); + + +% cofstar contains the system for the model when the constraint binds +Cstarbarmat = cofstar(:,1:nvars); +Bstarbarmat = cofstar(:,nvars+1:2*nvars); +Astarbarmat = cofstar(:,2*nvars+1:3*nvars); + +% get the time-dependent decision rules + +Tmax = regimestart(nregimes)-1; % Tmax is the position of the last period + % when the constraint binds + +if Tmax > 0 + P = zeros(nvars,nvars,Tmax); + D = zeros(nvars,Tmax); + + + invmat = inv((Astarbarmat*decrulea+Bstarbarmat)); + P(:,:,Tmax) = -invmat*Cstarbarmat; + D(:,Tmax) = -invmat*Dstarbarmat; + + + % equivalent to pre-multiplying by the inverse above if the target + % matrix is invertible. Otherwise it yields the minimum state solution + %P(:,:,Tmax) = -(Astarbarmat*decrulea+Bstarbarmat)\Cstarbarmat; + %D(:,Tmax) = -(Astarbarmat*decrulea+Bstarbarmat)\Dstarbarmat; + + + for i = Tmax-1:-1:1 + + if violvecbool(i) + invmat = inv(Bstarbarmat+Astarbarmat*P(:,:,i+1)); + P(:,:,i)=-invmat*Cstarbarmat; + D(:,i) = -invmat*(Astarbarmat*D(:,i+1)+Dstarbarmat); + else + invmat = inv(Bbarmat+Abarmat*P(:,:,i+1)); + P(:,:,i)=-invmat*Cbarmat; + D(:,i) = -invmat*(Abarmat*D(:,i+1)); + end + end + + if Tmax > 1 + if violvecbool(1) + E = -invmat*Jstarbarmat; + else + E = -invmat*Jbarmat; + end + else + invmat = inv(Astarbarmat*decrulea+Bstarbarmat); + E = -invmat*Jstarbarmat; + + end + + +end + +% generate data +% history will contain data, the state vector at each period in time will +% be stored columnwise. +history = zeros(nvars,nperiods+1); +history(:,1) = init; +errvec = zeros(size(exog_,1),1); + +% deal with predetermined conditions +for i = 1:nshocks + errvec(irfshockpos(i)) = scalefactormod(i); +end + +% deal with shocks +irfpos =1; +if irfpos <=Tmax + history(:,irfpos+1) = P(:,:,irfpos)* history(:,irfpos)+... + D(:,irfpos) + E*errvec; +else + history(:,irfpos+1) = decrulea*history(:,irfpos)+decruleb*errvec; +end + +% all other periods +for irfpos=2:nperiods+1 + if irfpos <=Tmax + history(:,irfpos+1) = P(:,:,irfpos)* history(:,irfpos)+... + D(:,irfpos); + else + history(:,irfpos+1) = decrulea*history(:,irfpos); + end +end + + +history=history'; zdata = history(2:end,:); \ No newline at end of file diff --git a/matlab/occbin/mkdatap_anticipated_2constraints.m b/matlab/occbin/mkdatap_anticipated_2constraints.m index b05c90d6de..c18cef2f9f 100755 --- a/matlab/occbin/mkdatap_anticipated_2constraints.m +++ b/matlab/occbin/mkdatap_anticipated_2constraints.m @@ -1,180 +1,180 @@ -function [zdata]=mkdatap_anticipated_2constraints_alt(nperiods,decrulea,decruleb,... - cof,Jbarmat,... - cof10,Jbarmat10,Dbarmat10,... - cof01,Jbarmat01,Dbarmat01,... - cof11,Jbarmat11,Dbarmat11,... - regime1,regimestart1,... - regime2,regimestart2,... - violvecbool,endog_,exog_,... - irfshock,scalefactormod,init) - - -nvars = size(endog_,1); - - -if nargin<16 - init=zeros(nvars,1); -end - -if nargin<15; - scalefactormod=1; -end - - -nshocks = size(irfshock,1); -for i = 1:nshocks - shockpos = strmatch(irfshock(i,:),exog_,'exact'); - if ~isempty(shockpos) - irfshockpos(i) = shockpos; - else - error(['Shock ',irfshock(i,:),' is not in the model']); - end -end - - - -Cbarmat = cof(:,1:nvars); -Bbarmat = cof(:,nvars+1:2*nvars); -Abarmat = cof(:,2*nvars+1:3*nvars); - - -% cofstar contains the system for the model when the constraint binds - - -Cbarmat10 = cof10(:,1:nvars); -Bbarmat10 = cof10(:,nvars+1:2*nvars); -Abarmat10 = cof10(:,2*nvars+1:3*nvars); - -Cbarmat01 = cof01(:,1:nvars); -Bbarmat01 = cof01(:,nvars+1:2*nvars); -Abarmat01 = cof01(:,2*nvars+1:3*nvars); - -Cbarmat11 = cof11(:,1:nvars); -Bbarmat11 = cof11(:,nvars+1:2*nvars); -Abarmat11 = cof11(:,2*nvars+1:3*nvars); - -% get the time-dependent decision rules -nregimes1 = length(regime1); -nregimes2 = length(regime2); - -Tmax = max([regimestart1(nregimes1) regimestart2(nregimes2)])-1; % Tmax is the position of the last period -% when the constraint binds - -if Tmax > 0 - P = zeros(nvars,nvars,Tmax); - D = zeros(nvars,Tmax); - -% invmat = inv((Astarbarmat*decrulea+Bstarbarmat)); -% P(:,:,Tmax) = -invmat*Cstarbarmat; -% D(:,Tmax) = -invmat*Dstarbarmat; - - - if (violvecbool(Tmax,1) & ~violvecbool(Tmax,2)) - %XXX fix next three lines - invmat = inv((Abarmat10*decrulea+Bbarmat10)); - P(:,:,Tmax) = -invmat*Cbarmat10; - D(:,Tmax) = -invmat*Dbarmat10; - elseif (violvecbool(Tmax,1) & violvecbool(Tmax,2)) - invmat = inv((Abarmat11*decrulea+Bbarmat11)); - P(:,:,Tmax) = -invmat*Cbarmat11; - D(:,Tmax) = -invmat*Dbarmat11; - else - invmat = inv((Abarmat01*decrulea+Bbarmat01)); - P(:,:,Tmax) = -invmat*Cbarmat01; - D(:,Tmax) = -invmat*Dbarmat01; - end - - - - - for i = Tmax-1:-1:1 - - if (violvecbool(i,1) & ~violvecbool(i,2)) - invmat = inv(Bbarmat10+Abarmat10*P(:,:,i+1)); - P(:,:,i)=-invmat*Cbarmat10; - D(:,i) = -invmat*(Abarmat10*D(:,i+1)+Dbarmat10); - elseif (~violvecbool(i,1) & violvecbool(i,2)) - invmat = inv(Bbarmat01+Abarmat01*P(:,:,i+1)); - P(:,:,i)=-invmat*Cbarmat01; - D(:,i) = -invmat*(Abarmat01*D(:,i+1)+Dbarmat01); - elseif (violvecbool(i,1) & violvecbool(i,2)) - invmat = inv(Bbarmat11+Abarmat11*P(:,:,i+1)); - P(:,:,i)=-invmat*Cbarmat11; - D(:,i) = -invmat*(Abarmat11*D(:,i+1)+Dbarmat11); - else - invmat = inv(Bbarmat+Abarmat*P(:,:,i+1)); - P(:,:,i)=-invmat*Cbarmat; - D(:,i) = -invmat*(Abarmat*D(:,i+1)); - end - - end - - -% Double check the appropriate invmat in each case -% right now -- inherited from previous loop -if Tmax > 1 - - if ( ~violvecbool(1,1) & violvecbool(1,2) ) - E = -invmat*Jbarmat01; - elseif ( violvecbool(1,1) & ~violvecbool(1,2) ) - E = -invmat*Jbarmat10; - elseif ( violvecbool(1,1) & violvecbool(1,2) ) - E = -invmat*Jbarmat11; - else - E = -invmat*Jbarmat; - end - -else % Tmax is equal to 1 -% invmat = inv((Astarbarmat*decrulea+Bstarbarmat)); -% E = -invmat*Jstarbarmat; - - if ( ~violvecbool(1,1) & violvecbool(1,2) ) - invmat = inv((Abarmat01*decrulea+Bbarmat01)); - E = -invmat*Jbarmat01; - elseif ( violvecbool(1,1) & violvecbool(1,2) ) - invmat = inv((Abarmat11*decrulea+Bbarmat11)); - E = -invmat*Jbarmat11; - else - invmat = inv((Abarmat10*decrulea+Bbarmat10)); - E = -invmat*Jbarmat10; - - end - -end - - -end - -% generate data -% history will contain data, the state vector at each period in time will -% be stored columnwise. -history = zeros(nvars,nperiods+1); -history(:,1) = init; -errvec = zeros(size(exog_,1),1); - -for i = 1:nshocks - errvec(irfshockpos(i)) = scalefactormod(i); -end - -% deal with shocks -irfpos =1; -if irfpos <=Tmax - history(:,irfpos+1) = P(:,:,irfpos)* history(:,irfpos)+... - D(:,irfpos) + E*errvec; -else - history(:,irfpos+1) = decrulea*history(:,irfpos)+decruleb*errvec; -end - -% all other periods -for irfpos=2:nperiods+1 - if irfpos <=Tmax - history(:,irfpos+1) = P(:,:,irfpos)* history(:,irfpos)+... - D(:,irfpos); - else - history(:,irfpos+1) = decrulea*history(:,irfpos); - end -end - - -history=history'; +function [zdata]=mkdatap_anticipated_2constraints(nperiods,decrulea,decruleb,... + cof,Jbarmat,... + cof10,Jbarmat10,Dbarmat10,... + cof01,Jbarmat01,Dbarmat01,... + cof11,Jbarmat11,Dbarmat11,... + regime1,regimestart1,... + regime2,regimestart2,... + violvecbool,endog_,exog_,... + irfshock,scalefactormod,init) + + +nvars = size(endog_,1); + + +if nargin<16 + init=zeros(nvars,1); +end + +if nargin<15; + scalefactormod=1; +end + + +nshocks = size(irfshock,1); +for i = 1:nshocks + shockpos = strmatch(irfshock(i,:),exog_,'exact'); + if ~isempty(shockpos) + irfshockpos(i) = shockpos; + else + error(['Shock ',irfshock(i,:),' is not in the model']); + end +end + + + +Cbarmat = cof(:,1:nvars); +Bbarmat = cof(:,nvars+1:2*nvars); +Abarmat = cof(:,2*nvars+1:3*nvars); + + +% cofstar contains the system for the model when the constraint binds + + +Cbarmat10 = cof10(:,1:nvars); +Bbarmat10 = cof10(:,nvars+1:2*nvars); +Abarmat10 = cof10(:,2*nvars+1:3*nvars); + +Cbarmat01 = cof01(:,1:nvars); +Bbarmat01 = cof01(:,nvars+1:2*nvars); +Abarmat01 = cof01(:,2*nvars+1:3*nvars); + +Cbarmat11 = cof11(:,1:nvars); +Bbarmat11 = cof11(:,nvars+1:2*nvars); +Abarmat11 = cof11(:,2*nvars+1:3*nvars); + +% get the time-dependent decision rules +nregimes1 = length(regime1); +nregimes2 = length(regime2); + +Tmax = max([regimestart1(nregimes1) regimestart2(nregimes2)])-1; % Tmax is the position of the last period + % when the constraint binds + +if Tmax > 0 + P = zeros(nvars,nvars,Tmax); + D = zeros(nvars,Tmax); + + % invmat = inv((Astarbarmat*decrulea+Bstarbarmat)); + % P(:,:,Tmax) = -invmat*Cstarbarmat; + % D(:,Tmax) = -invmat*Dstarbarmat; + + + if (violvecbool(Tmax,1) & ~violvecbool(Tmax,2)) + %XXX fix next three lines + invmat = inv((Abarmat10*decrulea+Bbarmat10)); + P(:,:,Tmax) = -invmat*Cbarmat10; + D(:,Tmax) = -invmat*Dbarmat10; + elseif (violvecbool(Tmax,1) & violvecbool(Tmax,2)) + invmat = inv((Abarmat11*decrulea+Bbarmat11)); + P(:,:,Tmax) = -invmat*Cbarmat11; + D(:,Tmax) = -invmat*Dbarmat11; + else + invmat = inv((Abarmat01*decrulea+Bbarmat01)); + P(:,:,Tmax) = -invmat*Cbarmat01; + D(:,Tmax) = -invmat*Dbarmat01; + end + + + + + for i = Tmax-1:-1:1 + + if (violvecbool(i,1) & ~violvecbool(i,2)) + invmat = inv(Bbarmat10+Abarmat10*P(:,:,i+1)); + P(:,:,i)=-invmat*Cbarmat10; + D(:,i) = -invmat*(Abarmat10*D(:,i+1)+Dbarmat10); + elseif (~violvecbool(i,1) & violvecbool(i,2)) + invmat = inv(Bbarmat01+Abarmat01*P(:,:,i+1)); + P(:,:,i)=-invmat*Cbarmat01; + D(:,i) = -invmat*(Abarmat01*D(:,i+1)+Dbarmat01); + elseif (violvecbool(i,1) & violvecbool(i,2)) + invmat = inv(Bbarmat11+Abarmat11*P(:,:,i+1)); + P(:,:,i)=-invmat*Cbarmat11; + D(:,i) = -invmat*(Abarmat11*D(:,i+1)+Dbarmat11); + else + invmat = inv(Bbarmat+Abarmat*P(:,:,i+1)); + P(:,:,i)=-invmat*Cbarmat; + D(:,i) = -invmat*(Abarmat*D(:,i+1)); + end + + end + + + % Double check the appropriate invmat in each case + % right now -- inherited from previous loop + if Tmax > 1 + + if ( ~violvecbool(1,1) & violvecbool(1,2) ) + E = -invmat*Jbarmat01; + elseif ( violvecbool(1,1) & ~violvecbool(1,2) ) + E = -invmat*Jbarmat10; + elseif ( violvecbool(1,1) & violvecbool(1,2) ) + E = -invmat*Jbarmat11; + else + E = -invmat*Jbarmat; + end + + else % Tmax is equal to 1 + % invmat = inv((Astarbarmat*decrulea+Bstarbarmat)); + % E = -invmat*Jstarbarmat; + + if ( ~violvecbool(1,1) & violvecbool(1,2) ) + invmat = inv((Abarmat01*decrulea+Bbarmat01)); + E = -invmat*Jbarmat01; + elseif ( violvecbool(1,1) & violvecbool(1,2) ) + invmat = inv((Abarmat11*decrulea+Bbarmat11)); + E = -invmat*Jbarmat11; + else + invmat = inv((Abarmat10*decrulea+Bbarmat10)); + E = -invmat*Jbarmat10; + + end + + end + + +end + +% generate data +% history will contain data, the state vector at each period in time will +% be stored columnwise. +history = zeros(nvars,nperiods+1); +history(:,1) = init; +errvec = zeros(size(exog_,1),1); + +for i = 1:nshocks + errvec(irfshockpos(i)) = scalefactormod(i); +end + +% deal with shocks +irfpos =1; +if irfpos <=Tmax + history(:,irfpos+1) = P(:,:,irfpos)* history(:,irfpos)+... + D(:,irfpos) + E*errvec; +else + history(:,irfpos+1) = decrulea*history(:,irfpos)+decruleb*errvec; +end + +% all other periods +for irfpos=2:nperiods+1 + if irfpos <=Tmax + history(:,irfpos+1) = P(:,:,irfpos)* history(:,irfpos)+... + D(:,irfpos); + else + history(:,irfpos+1) = decrulea*history(:,irfpos); + end +end + + +history=history'; zdata = history(2:end,:); \ No newline at end of file diff --git a/matlab/occbin/pickaxes.m b/matlab/occbin/pickaxes.m index 46c4b79c6d..c2e2d5e0d5 100755 --- a/matlab/occbin/pickaxes.m +++ b/matlab/occbin/pickaxes.m @@ -1,16 +1,16 @@ -function [x0,x1,y0,y1] = pickaxes(xvalues,yvalues) - -x0=xvalues(1); -nobs = length(xvalues); -x1=xvalues(nobs); - -maxy = max(yvalues); -miny = min(yvalues); - - -y0 = miny - .05*abs(miny); -if (miny>0 & y0<0) - y0 = 0; -end - -y1 = maxy + .05*abs(maxy); +function [x0,x1,y0,y1] = pickaxes(xvalues,yvalues) + +x0=xvalues(1); +nobs = length(xvalues); +x1=xvalues(nobs); + +maxy = max(yvalues); +miny = min(yvalues); + + +y0 = miny - .05*abs(miny); +if (miny>0 & y0<0) + y0 = 0; +end + +y1 = maxy + .05*abs(maxy); diff --git a/matlab/occbin/process_constraint.m b/matlab/occbin/process_constraint.m index d209111755..0573eb6419 100755 --- a/matlab/occbin/process_constraint.m +++ b/matlab/occbin/process_constraint.m @@ -1,38 +1,38 @@ -% this function looks for occurrences of the endogenous variables in -% endo_names in the input string constraint -% all occurrences of the endogenous variables are appended a suffix -% if the invert_switch is true, the direction of the inequality in the -% constraint is inverted - -function constraint1 = process_constraint(constraint,suffix,endo_names,invert_switch) - -% create a list of delimiters that can separate parameters and endogenoous -% variables in the string that expresses the constraint -delimiters = char(',',';','(',')','+','-','^','*','/',' ','>','<','='); - -% split the string that holds the constraint into tokens -tokens = tokenize(constraint,delimiters); - -ntokens = length(tokens); - -% search for tokens that match the list of endogenous variables -for i=1:ntokens - if ~isempty(find(strcmp(tokens(i),endo_names))) - % when there is a match with an endogenous variable append the - % suffix - tokens(i) = cellstr([char(tokens(i)),suffix]); - end - - % if the invert_switch is true - % reverse the direction of the inequality - if invert_switch - if strcmp(tokens(i),cellstr('>')) - tokens(i) = cellstr('<'); - elseif strcmp(tokens(i),cellstr('<')) - tokens(i) = cellstr('>'); - end - end -end - -% reassemble the tokens to create a string that expresses the constraint +% this function looks for occurrences of the endogenous variables in +% endo_names in the input string constraint +% all occurrences of the endogenous variables are appended a suffix +% if the invert_switch is true, the direction of the inequality in the +% constraint is inverted + +function constraint1 = process_constraint(constraint,suffix,endo_names,invert_switch) + +% create a list of delimiters that can separate parameters and endogenoous +% variables in the string that expresses the constraint +delimiters = char(',',';','(',')','+','-','^','*','/',' ','>','<','='); + +% split the string that holds the constraint into tokens +tokens = tokenize(constraint,delimiters); + +ntokens = length(tokens); + +% search for tokens that match the list of endogenous variables +for i=1:ntokens + if ~isempty(find(strcmp(tokens(i),endo_names))) + % when there is a match with an endogenous variable append the + % suffix + tokens(i) = cellstr([char(tokens(i)),suffix]); + end + + % if the invert_switch is true + % reverse the direction of the inequality + if invert_switch + if strcmp(tokens(i),cellstr('>')) + tokens(i) = cellstr('<'); + elseif strcmp(tokens(i),cellstr('<')) + tokens(i) = cellstr('>'); + end + end +end + +% reassemble the tokens to create a string that expresses the constraint constraint1 = strmerge(tokens); \ No newline at end of file diff --git a/matlab/occbin/setss.m b/matlab/occbin/setss.m index d1c0e440ac..39e269d519 100755 --- a/matlab/occbin/setss.m +++ b/matlab/occbin/setss.m @@ -1,14 +1,14 @@ -% Script that retrieves parameter values once model is solved - -nendog = size(Mbase_.endo_names,1); - -for i=1:nendog - eval([deblank(Mbase_.endo_names(i,:)) '_ss = oo_.dr.ys(i); ']); -end - -nparams = size(Mbase_.param_names); - -for i = 1:nparams - eval([Mbase_.param_names(i,:),'= M_.params(i);']); -end - +% Script that retrieves parameter values once model is solved + +nendog = size(Mbase_.endo_names,1); + +for i=1:nendog + eval([deblank(Mbase_.endo_names(i,:)) '_ss = oo_.dr.ys(i); ']); +end + +nparams = size(Mbase_.param_names); + +for i = 1:nparams + eval([Mbase_.param_names(i,:),'= M_.params(i);']); +end + diff --git a/matlab/occbin/solve_no_constraint.m b/matlab/occbin/solve_no_constraint.m index d9671409d2..d4f61a3f44 100755 --- a/matlab/occbin/solve_no_constraint.m +++ b/matlab/occbin/solve_no_constraint.m @@ -1,50 +1,50 @@ -function [zdata_, zdatass_, oobase_, Mbase_ ] = ... - solve_no_constraint(modnam,... - shockssequence,irfshock,nperiods) - -global M_ oo_ - -errlist = []; - -% solve model -eval(['dynare ',modnam,' noclearall']) -oobase_ = oo_; -Mbase_ = M_; - -ys_ = oobase_.dr.ys; -nvars = numel(ys_); -zdatass_ = ys_ ; - -for i=1:Mbase_.endo_nbr - eval([deblank(Mbase_.endo_names(i,:)) '_ss = oo_.dr.ys(i); ']); -end - -for i = 1:size(Mbase_.param_names) - eval([Mbase_.param_names(i,:),'= M_.params(i);']); -end - - - - - - - -[hm1,h,hl1,Jbarmat] = get_deriv(Mbase_,ys_); -cof = [hm1,h,hl1]; - -[decrulea,decruleb]=get_pq(oobase_.dr); -endog_ = M_.endo_names; -exog_ = M_.exo_names; - -nvars = numel(Mbase_.endo_nbr); - - -nshocks = size(shockssequence,1); -init = zeros(nvars,1); - -wishlist = endog_; -nwishes = size(wishlist,1); - - -zdata_ = mkdata(nperiods,decrulea,decruleb,endog_,exog_,wishlist,irfshock,shockssequence); - +function [zdata_, zdatass_, oobase_, Mbase_ ] = ... + solve_no_constraint(modnam,... + shockssequence,irfshock,nperiods) + +global M_ oo_ + +errlist = []; + +% solve model +eval(['dynare ',modnam,' noclearall']) +oobase_ = oo_; +Mbase_ = M_; + +ys_ = oobase_.dr.ys; +nvars = numel(ys_); +zdatass_ = ys_ ; + +for i=1:Mbase_.endo_nbr + eval([deblank(Mbase_.endo_names(i,:)) '_ss = oo_.dr.ys(i); ']); +end + +for i = 1:size(Mbase_.param_names) + eval([Mbase_.param_names(i,:),'= M_.params(i);']); +end + + + + + + + +[hm1,h,hl1,Jbarmat] = get_deriv(Mbase_,ys_); +cof = [hm1,h,hl1]; + +[decrulea,decruleb]=get_pq(oobase_.dr); +endog_ = M_.endo_names; +exog_ = M_.exo_names; + +nvars = numel(Mbase_.endo_nbr); + + +nshocks = size(shockssequence,1); +init = zeros(nvars,1); + +wishlist = endog_; +nwishes = size(wishlist,1); + + +zdata_ = mkdata(nperiods,decrulea,decruleb,endog_,exog_,wishlist,irfshock,shockssequence); + diff --git a/matlab/occbin/solve_no_constraint_noclear.m b/matlab/occbin/solve_no_constraint_noclear.m index 309c5c546e..b899708e29 100755 --- a/matlab/occbin/solve_no_constraint_noclear.m +++ b/matlab/occbin/solve_no_constraint_noclear.m @@ -1,48 +1,48 @@ -function [zdata oobase_ Mbase_ ] = ... - solve_no_constraint_noclear(modnam,... - shockssequence,irfshock,nperiods); - -global M_ oo_ - -errlist = []; - -% solve model -eval(['dynare ',modnam,' nolog']); -oobase_ = oo_; -Mbase_ = M_; - -ys_ = oobase_.dr.ys; - -for i=1:Mbase_.endo_nbr - eval([deblank(Mbase_.endo_names(i,:)) '_ss = oo_.dr.ys(i); ']); -end - -for i = 1:size(Mbase_.param_names) - eval([Mbase_.param_names(i,:),'= M_.params(i);']); -end - -setss - - - - - -[hm1,h,hl1,Jbarmat] = get_deriv(Mbase_,ys_); -cof = [hm1,h,hl1]; - -[decrulea,decruleb]=get_pq(oobase_.dr); -endog_ = M_.endo_names; -exog_ = M_.exo_names; - - -nvars = numel(Mbase_.endo_nbr); - -nshocks = size(shockssequence,1); -init = zeros(nvars,1); - -wishlist = endog_; -nwishes = size(wishlist,1); - - -zdata = mkdata(nperiods,decrulea,decruleb,endog_,exog_,wishlist,irfshock,shockssequence); - +function [zdata oobase_ Mbase_ ] = ... + solve_no_constraint_noclear(modnam,... + shockssequence,irfshock,nperiods); + +global M_ oo_ + +errlist = []; + +% solve model +eval(['dynare ',modnam,' nolog']); +oobase_ = oo_; +Mbase_ = M_; + +ys_ = oobase_.dr.ys; + +for i=1:Mbase_.endo_nbr + eval([deblank(Mbase_.endo_names(i,:)) '_ss = oo_.dr.ys(i); ']); +end + +for i = 1:size(Mbase_.param_names) + eval([Mbase_.param_names(i,:),'= M_.params(i);']); +end + +setss + + + + + +[hm1,h,hl1,Jbarmat] = get_deriv(Mbase_,ys_); +cof = [hm1,h,hl1]; + +[decrulea,decruleb]=get_pq(oobase_.dr); +endog_ = M_.endo_names; +exog_ = M_.exo_names; + + +nvars = numel(Mbase_.endo_nbr); + +nshocks = size(shockssequence,1); +init = zeros(nvars,1); + +wishlist = endog_; +nwishes = size(wishlist,1); + + +zdata = mkdata(nperiods,decrulea,decruleb,endog_,exog_,wishlist,irfshock,shockssequence); + diff --git a/matlab/occbin/solve_one_constraint.1.m b/matlab/occbin/solve_one_constraint.1.m index 34e296496b..344e85f5ae 100755 --- a/matlab/occbin/solve_one_constraint.1.m +++ b/matlab/occbin/solve_one_constraint.1.m @@ -1,192 +1,192 @@ -% solve_one_constraint [zdatalinear zdatapiecewise zdatass oo base M base] = solve one constraint(modnam, modnamstar, constraint, constraint relax, shockssequence, irfshock, nperiods, maxiter, init); -% -% Inputs: -% modnam: name of .mod file for the reference regime (excludes the .mod extension). -% modnamstar: name of .mod file for the alternative regime (excludes the .mod exten- sion). -% constraint: the constraint (see notes 1 and 2 below). When the condition in constraint evaluates to true, the solution switches from the reference to the alternative regime. -% constraint relax: when the condition in constraint relax evaluates to true, the solution returns to the reference regime. -% shockssequence: a sequence of unforeseen shocks under which one wants to solve the model (size T�nshocks). -% irfshock: label for innovation for IRFs, from Dynare .mod file (one or more of the ?varexo?). -% nperiods: simulation horizon (can be longer than the sequence of shocks defined in shockssequence; must be long enough to ensure convergence back to the reference model at the end of the simulation horizon and may need to be varied depending on the sequence of shocks). -% maxiter: maximum number of iterations allowed for the solution algorithm (20 if not specified). -% init: the initial position for the vector of state variables, in deviation from steady state (if not specified, the default is steady state). The ordering follows the definition order in the .mod files. -% -% Outputs: -% zdatalinear: an array containing paths for all endogenous variables ignoring the occasionally binding constraint (the linear solution), in deviation from steady state. Each column is a variable, the order is the definition order in the .mod files. -% zdatapiecewise: an array containing paths for all endogenous variables satisfying the occasionally binding constraint (the occbin/piecewise solution), in deviation from steady state. Each column is a variable, the order is the definition order in the .mod files. -% zdatass: theinitialpositionforthevectorofstatevariables,indeviationfromsteady state (if not specified, the default is a vectors of zero implying that the initial conditions coincide with the steady state). The ordering follows the definition order in the .mod files. -% oobase,Mbase: structures produced by Dynare for the reference model ? see Dynare User Guide. - -% Log of changes: -% 6/17/2013 -- Luca added a trailing underscore to local variables in an -% attempt to avoid conflicts with parameter names defined in the .mod files -% to be processed. -% 6/17/2013 -- Luca replaced external .m file setss.m - - -function [zdatalinear_ zdatapiecewise_ zdatass_ oobase_ Mbase_ ] = ... - solve_one_constraint(modnam_,modnamstar_,... - constraint_, constraint_relax_,... - shockssequence_,irfshock_,nperiods_,maxiter_,init_) - -global M_ oo_ - -errlist_ = []; - -% solve the reference model linearly -eval(['dynare ',modnam_,' noclearall nolog ']) -oobase_ = oo_; -Mbase_ = M_; - -% import locally the values of parameters assigned in the reference .mod -% file -for i_indx_ = 1:Mbase_.param_nbr - eval([Mbase_.param_names(i_indx_,:),'= M_.params(i_indx_);']); -end - -% Create steady state values of the variables if needed for processing the constraint -for i=1:Mbase_.endo_nbr - eval([deblank(Mbase_.endo_names(i,:)) '_ss = oobase_.dr.ys(i); ']); -end - - -% parse the .mod file for the alternative regime -eval(['dynare ',modnamstar_,' noclearall nolog ']) -oostar_ = oo_; -Mstar_ = M_; - - -% check inputs -if ~strcmp(Mbase_.endo_names,Mstar_.endo_names) - error('The two .mod files need to have exactly the same endogenous variables declared in the same order') -end - -if ~strcmp(Mbase_.exo_names,Mstar_.exo_names) - error('The two .mod files need to have exactly the same exogenous variables declared in the same order') -end - -if ~strcmp(Mbase_.param_names,Mstar_.param_names) - warning('The parameter list does not match across .mod files') -end - -% ensure that the two models have the same parameters -% use the parameters for the base model. -Mstar_.params = Mbase_.params; - -nvars_ = Mbase_.endo_nbr; -zdatass_ = oobase_.dr.ys; - - -% get the matrices holding the first derivatives for the model -% each regime is treated separately -[hm1_,h_,hl1_,Jbarmat_] = get_deriv(Mbase_,zdatass_); -cof_ = [hm1_,h_,hl1_]; - -[hm1_,h_,hl1_,Jstarbarmat_,resid_] = get_deriv(Mstar_,zdatass_); -cofstar_ = [hm1_,h_,hl1_]; -Dstartbarmat_ = resid_; - -[decrulea_,decruleb_]=get_pq(oobase_.dr); -endog_ = M_.endo_names; -exog_ = M_.exo_names; - - -% processes the constraints specified in the call to this function -% uppend a suffix to each endogenous variable -constraint_difference_ = process_constraint(constraint_,'_difference',Mbase_.endo_names,0); - -constraint_relax_difference_ = process_constraint(constraint_relax_,'_difference',Mbase_.endo_names,0); - - - -nshocks_ = size(shockssequence_,1); - -% if necessary, set default values for optional arguments -if ~exist('init_') - init_ = zeros(nvars_,1); -end - -if ~exist('maxiter_') - maxiter_ = 20; -end - -if ~exist('nperiods_') - nperiods_ = 100; -end - - -% set some initial conditions and loop through the shocks -% period by period -init_orig_ = init_; -zdatapiecewise_ = zeros(nperiods_,nvars_); -wishlist_ = endog_; -nwishes_ = size(wishlist_,1); -violvecbool_ = zeros(nperiods_+1,1); - - -for ishock_ = 1:nshocks_ - - changes_=1; - iter_ = 0; - - - while (changes_ & iter_<maxiter_) - iter_ = iter_ +1; - - % analyze when each regime starts based on current guess - [regime regimestart]=map_regime(violvecbool_); - - - % get the hypothesized piece wise linear solution - [zdatalinear_]=mkdatap_anticipated(nperiods_,decrulea_,decruleb_,... - cof_,Jbarmat_,cofstar_,Jstarbarmat_,Dstartbarmat_,... - regime,regimestart,violvecbool_,... - endog_,exog_,irfshock_,shockssequence_(ishock_,:),init_); - - for i_indx_=1:nwishes_ - eval([deblank(wishlist_(i_indx_,:)),'_difference=zdatalinear_(:,i_indx_);']); - end - - - - newviolvecbool_ = eval(constraint_difference_); - relaxconstraint_ = eval(constraint_relax_difference_); - - - - % check if changes to the hypothesis of the duration for each - % regime - if (max(newviolvecbool_-violvecbool_>0)) | sum(relaxconstraint_(find(violvecbool_==1))>0) - changes_ = 1; - else - changes_ = 0; - end - - - violvecbool_ = (violvecbool_|newviolvecbool_)-(relaxconstraint_ & violvecbool_); - - - end - - init_ = zdatalinear_(1,:); - zdatapiecewise_(ishock_,:)=init_; - init_= init_'; - - % reset violvecbool_ for next period's shock -- this resetting is - % consistent with expecting no additional shocks - violvecbool_=[violvecbool_(2:end);0]; - -end - -% if necessary, fill in the rest of the path with the remainder of the -% last IRF computed. -zdatapiecewise_(ishock_+1:end,:)=zdatalinear_(2:nperiods_-ishock_+1,:); - -% get the linear responses -zdatalinear_ = mkdata(max(nperiods_,size(shockssequence_,1)),... - decrulea_,decruleb_,endog_,exog_,... - wishlist_,irfshock_,shockssequence_,init_orig_); - -if changes_ ==1 - display('Did not converge -- increase maxiter_') -end +% solve_one_constraint [zdatalinear zdatapiecewise zdatass oo base M base] = solve one constraint(modnam, modnamstar, constraint, constraint relax, shockssequence, irfshock, nperiods, maxiter, init); +% +% Inputs: +% modnam: name of .mod file for the reference regime (excludes the .mod extension). +% modnamstar: name of .mod file for the alternative regime (excludes the .mod exten- sion). +% constraint: the constraint (see notes 1 and 2 below). When the condition in constraint evaluates to true, the solution switches from the reference to the alternative regime. +% constraint relax: when the condition in constraint relax evaluates to true, the solution returns to the reference regime. +% shockssequence: a sequence of unforeseen shocks under which one wants to solve the model (size T�nshocks). +% irfshock: label for innovation for IRFs, from Dynare .mod file (one or more of the ?varexo?). +% nperiods: simulation horizon (can be longer than the sequence of shocks defined in shockssequence; must be long enough to ensure convergence back to the reference model at the end of the simulation horizon and may need to be varied depending on the sequence of shocks). +% maxiter: maximum number of iterations allowed for the solution algorithm (20 if not specified). +% init: the initial position for the vector of state variables, in deviation from steady state (if not specified, the default is steady state). The ordering follows the definition order in the .mod files. +% +% Outputs: +% zdatalinear: an array containing paths for all endogenous variables ignoring the occasionally binding constraint (the linear solution), in deviation from steady state. Each column is a variable, the order is the definition order in the .mod files. +% zdatapiecewise: an array containing paths for all endogenous variables satisfying the occasionally binding constraint (the occbin/piecewise solution), in deviation from steady state. Each column is a variable, the order is the definition order in the .mod files. +% zdatass: theinitialpositionforthevectorofstatevariables,indeviationfromsteady state (if not specified, the default is a vectors of zero implying that the initial conditions coincide with the steady state). The ordering follows the definition order in the .mod files. +% oobase,Mbase: structures produced by Dynare for the reference model ? see Dynare User Guide. + +% Log of changes: +% 6/17/2013 -- Luca added a trailing underscore to local variables in an +% attempt to avoid conflicts with parameter names defined in the .mod files +% to be processed. +% 6/17/2013 -- Luca replaced external .m file setss.m + + +function [zdatalinear_ zdatapiecewise_ zdatass_ oobase_ Mbase_ ] = ... + solve_one_constraint.1(modnam_,modnamstar_,... + constraint_, constraint_relax_,... + shockssequence_,irfshock_,nperiods_,maxiter_,init_) + +global M_ oo_ + +errlist_ = []; + +% solve the reference model linearly +eval(['dynare ',modnam_,' noclearall nolog ']) +oobase_ = oo_; +Mbase_ = M_; + +% import locally the values of parameters assigned in the reference .mod +% file +for i_indx_ = 1:Mbase_.param_nbr + eval([Mbase_.param_names(i_indx_,:),'= M_.params(i_indx_);']); +end + +% Create steady state values of the variables if needed for processing the constraint +for i=1:Mbase_.endo_nbr + eval([deblank(Mbase_.endo_names(i,:)) '_ss = oobase_.dr.ys(i); ']); +end + + +% parse the .mod file for the alternative regime +eval(['dynare ',modnamstar_,' noclearall nolog ']) +oostar_ = oo_; +Mstar_ = M_; + + +% check inputs +if ~strcmp(Mbase_.endo_names,Mstar_.endo_names) + error('The two .mod files need to have exactly the same endogenous variables declared in the same order') +end + +if ~strcmp(Mbase_.exo_names,Mstar_.exo_names) + error('The two .mod files need to have exactly the same exogenous variables declared in the same order') +end + +if ~strcmp(Mbase_.param_names,Mstar_.param_names) + warning('The parameter list does not match across .mod files') +end + +% ensure that the two models have the same parameters +% use the parameters for the base model. +Mstar_.params = Mbase_.params; + +nvars_ = Mbase_.endo_nbr; +zdatass_ = oobase_.dr.ys; + + +% get the matrices holding the first derivatives for the model +% each regime is treated separately +[hm1_,h_,hl1_,Jbarmat_] = get_deriv(Mbase_,zdatass_); +cof_ = [hm1_,h_,hl1_]; + +[hm1_,h_,hl1_,Jstarbarmat_,resid_] = get_deriv(Mstar_,zdatass_); +cofstar_ = [hm1_,h_,hl1_]; +Dstartbarmat_ = resid_; + +[decrulea_,decruleb_]=get_pq(oobase_.dr); +endog_ = M_.endo_names; +exog_ = M_.exo_names; + + +% processes the constraints specified in the call to this function +% uppend a suffix to each endogenous variable +constraint_difference_ = process_constraint(constraint_,'_difference',Mbase_.endo_names,0); + +constraint_relax_difference_ = process_constraint(constraint_relax_,'_difference',Mbase_.endo_names,0); + + + +nshocks_ = size(shockssequence_,1); + +% if necessary, set default values for optional arguments +if ~exist('init_') + init_ = zeros(nvars_,1); +end + +if ~exist('maxiter_') + maxiter_ = 20; +end + +if ~exist('nperiods_') + nperiods_ = 100; +end + + +% set some initial conditions and loop through the shocks +% period by period +init_orig_ = init_; +zdatapiecewise_ = zeros(nperiods_,nvars_); +wishlist_ = endog_; +nwishes_ = size(wishlist_,1); +violvecbool_ = zeros(nperiods_+1,1); + + +for ishock_ = 1:nshocks_ + + changes_=1; + iter_ = 0; + + + while (changes_ & iter_<maxiter_) + iter_ = iter_ +1; + + % analyze when each regime starts based on current guess + [regime regimestart]=map_regime(violvecbool_); + + + % get the hypothesized piece wise linear solution + [zdatalinear_]=mkdatap_anticipated(nperiods_,decrulea_,decruleb_,... + cof_,Jbarmat_,cofstar_,Jstarbarmat_,Dstartbarmat_,... + regime,regimestart,violvecbool_,... + endog_,exog_,irfshock_,shockssequence_(ishock_,:),init_); + + for i_indx_=1:nwishes_ + eval([deblank(wishlist_(i_indx_,:)),'_difference=zdatalinear_(:,i_indx_);']); + end + + + + newviolvecbool_ = eval(constraint_difference_); + relaxconstraint_ = eval(constraint_relax_difference_); + + + + % check if changes to the hypothesis of the duration for each + % regime + if (max(newviolvecbool_-violvecbool_>0)) | sum(relaxconstraint_(find(violvecbool_==1))>0) + changes_ = 1; + else + changes_ = 0; + end + + + violvecbool_ = (violvecbool_|newviolvecbool_)-(relaxconstraint_ & violvecbool_); + + + end + + init_ = zdatalinear_(1,:); + zdatapiecewise_(ishock_,:)=init_; + init_= init_'; + + % reset violvecbool_ for next period's shock -- this resetting is + % consistent with expecting no additional shocks + violvecbool_=[violvecbool_(2:end);0]; + +end + +% if necessary, fill in the rest of the path with the remainder of the +% last IRF computed. +zdatapiecewise_(ishock_+1:end,:)=zdatalinear_(2:nperiods_-ishock_+1,:); + +% get the linear responses +zdatalinear_ = mkdata(max(nperiods_,size(shockssequence_,1)),... + decrulea_,decruleb_,endog_,exog_,... + wishlist_,irfshock_,shockssequence_,init_orig_); + +if changes_ ==1 + display('Did not converge -- increase maxiter_') +end diff --git a/matlab/occbin/solve_one_constraint.m b/matlab/occbin/solve_one_constraint.m index c446f4c40d..ee59e9a3d7 100755 --- a/matlab/occbin/solve_one_constraint.m +++ b/matlab/occbin/solve_one_constraint.m @@ -1,200 +1,200 @@ -% solve_one_constraint [zdatalinear zdatapiecewise zdatass oo base M base] = solve one constraint(modnam, modnamstar, constraint, constraint relax, shockssequence, irfshock, nperiods, maxiter, init); -% -% Inputs: -% modnam: name of .mod file for the reference regime (excludes the .mod extension). -% modnamstar: name of .mod file for the alternative regime (excludes the .mod exten- sion). -% constraint: the constraint (see notes 1 and 2 below). When the condition in constraint evaluates to true, the solution switches from the reference to the alternative regime. -% constraint relax: when the condition in constraint relax evaluates to true, the solution returns to the reference regime. -% shockssequence: a sequence of unforeseen shocks under which one wants to solve the model (size T�nshocks). -% irfshock: label for innovation for IRFs, from Dynare .mod file (one or more of the ?varexo?). -% nperiods: simulation horizon (can be longer than the sequence of shocks defined in shockssequence; must be long enough to ensure convergence back to the reference model at the end of the simulation horizon and may need to be varied depending on the sequence of shocks). -% maxiter: maximum number of iterations allowed for the solution algorithm (20 if not specified). -% init: the initial position for the vector of state variables, in deviation from steady state (if not specified, the default is steady state). The ordering follows the definition order in the .mod files. -% -% Outputs: -% zdatalinear: an array containing paths for all endogenous variables ignoring the occasionally binding constraint (the linear solution), in deviation from steady state. Each column is a variable, the order is the definition order in the .mod files. -% zdatapiecewise: an array containing paths for all endogenous variables satisfying the occasionally binding constraint (the occbin/piecewise solution), in deviation from steady state. Each column is a variable, the order is the definition order in the .mod files. -% zdatass: theinitialpositionforthevectorofstatevariables,indeviationfromsteady state (if not specified, the default is a vectors of zero implying that the initial conditions coincide with the steady state). The ordering follows the definition order in the .mod files. -% oobase,Mbase: structures produced by Dynare for the reference model ? see Dynare User Guide. - -% Log of changes: -% 6/17/2013 -- Luca added a trailing underscore to local variables in an -% attempt to avoid conflicts with parameter names defined in the .mod files -% to be processed. -% 6/17/2013 -- Luca replaced external .m file setss.m - - -function [zdatalinear_ zdatapiecewise_ zdatass_ oobase_ Mbase_ ] = ... - solve_one_constraint(modnam_,modnamstar_,... - constraint_, constraint_relax_,... - shockssequence_,irfshock_,nperiods_,maxiter_,init_) - -global M_ oo_ - -errlist_ = []; - -% solve the reference model linearly -eval(['dynare ',modnam_,' noclearall nolog ']) -oobase_ = oo_; -Mbase_ = M_; - -% import locally the values of parameters assigned in the reference .mod -% file -for i_indx_ = 1:Mbase_.param_nbr - eval([Mbase_.param_names(i_indx_,:),'= M_.params(i_indx_);']); -end - -% Create steady state values of the variables if needed for processing the constraint -for i=1:Mbase_.endo_nbr - eval([deblank(Mbase_.endo_names(i,:)) '_ss = oobase_.dr.ys(i); ']); -end - - -% parse the .mod file for the alternative regime -eval(['dynare ',modnamstar_,' noclearall nolog ']) -oostar_ = oo_; -Mstar_ = M_; - - -% check inputs -if ~strcmp(Mbase_.endo_names,Mstar_.endo_names) - error('The two .mod files need to have exactly the same endogenous variables declared in the same order') -end - -if ~strcmp(Mbase_.exo_names,Mstar_.exo_names) - error('The two .mod files need to have exactly the same exogenous variables declared in the same order') -end - -if ~strcmp(Mbase_.param_names,Mstar_.param_names) - warning('The parameter list does not match across .mod files') -end - -% ensure that the two models have the same parameters -% use the parameters for the base model. -Mstar_.params = Mbase_.params; - -nvars_ = Mbase_.endo_nbr; -zdatass_ = oobase_.dr.ys; - - -% get the matrices holding the first derivatives for the model -% each regime is treated separately -[hm1_,h_,hl1_,Jbarmat_] = get_deriv(Mbase_,zdatass_); -cof_ = [hm1_,h_,hl1_]; - -[hm1_,h_,hl1_,Jstarbarmat_,resid_] = get_deriv(Mstar_,zdatass_); -cofstar_ = [hm1_,h_,hl1_]; -Dstartbarmat_ = resid_; - -if isfield(Mbase_,'nfwrd') - % the latest Dynare distributions have moved nstatic and nfwrd - [decrulea_,decruleb_]=get_pq(oobase_.dr,Mbase_.nstatic,Mbase_.nfwrd); -else - [decrulea_,decruleb_]=get_pq(oobase_.dr,oobase_.dr.nstatic,oobase_.dr.nfwrd); -end - -endog_ = M_.endo_names; -exog_ = M_.exo_names; - - -% processes the constraints specified in the call to this function -% uppend a suffix to each endogenous variable -constraint_difference_ = process_constraint(constraint_,'_difference',Mbase_.endo_names,0); - -constraint_relax_difference_ = process_constraint(constraint_relax_,'_difference',Mbase_.endo_names,0); - - - -nshocks_ = size(shockssequence_,1); - -% if necessary, set default values for optional arguments -if ~exist('init_') - init_ = zeros(nvars_,1); -end - -if ~exist('maxiter_') - maxiter_ = 20; -end - -if ~exist('nperiods_') - nperiods_ = 100; -end - - -% set some initial conditions and loop through the shocks -% period by period -init_orig_ = init_; -zdatapiecewise_ = zeros(nperiods_,nvars_); -wishlist_ = endog_; -nwishes_ = size(wishlist_,1); -violvecbool_ = zeros(nperiods_+1,1); - - -for ishock_ = 1:nshocks_ - - changes_=1; - iter_ = 0; - - - while (changes_ & iter_<maxiter_) - iter_ = iter_ +1; - - % analyze when each regime starts based on current guess - [regime regimestart]=map_regime(violvecbool_); - - - - % get the hypothesized piece wise linear solution - [zdatalinear_]=mkdatap_anticipated(nperiods_,decrulea_,decruleb_,... - cof_,Jbarmat_,cofstar_,Jstarbarmat_,Dstartbarmat_,... - regime,regimestart,violvecbool_,... - endog_,exog_,irfshock_,shockssequence_(ishock_,:),init_); - - for i_indx_=1:nwishes_ - eval([deblank(wishlist_(i_indx_,:)),'_difference=zdatalinear_(:,i_indx_);']); - end - - - - newviolvecbool_ = eval(constraint_difference_); - relaxconstraint_ = eval(constraint_relax_difference_); - - - - % check if changes to the hypothesis of the duration for each - % regime - if (max(newviolvecbool_-violvecbool_>0)) | sum(relaxconstraint_(find(violvecbool_==1))>0) - changes_ = 1; - else - changes_ = 0; - end - - - - violvecbool_ = (violvecbool_|newviolvecbool_)-(relaxconstraint_ & violvecbool_); - - - end - - init_ = zdatalinear_(1,:); - zdatapiecewise_(ishock_,:)=init_; - init_= init_'; - - % reset violvecbool_ for next period's shock -- this resetting is - % consistent with expecting no additional shocks - violvecbool_=[violvecbool_(2:end);0]; - -end - -% if necessary, fill in the rest of the path with the remainder of the -% last IRF computed. -zdatapiecewise_(ishock_+1:end,:)=zdatalinear_(2:nperiods_-ishock_+1,:); - -% get the linear responses -zdatalinear_ = mkdata(max(nperiods_,size(shockssequence_,1)),... - decrulea_,decruleb_,endog_,exog_,... - wishlist_,irfshock_,shockssequence_,init_orig_); - -if changes_ ==1 - display('Did not converge -- increase maxiter_') -end +% solve_one_constraint [zdatalinear zdatapiecewise zdatass oo base M base] = solve one constraint(modnam, modnamstar, constraint, constraint relax, shockssequence, irfshock, nperiods, maxiter, init); +% +% Inputs: +% modnam: name of .mod file for the reference regime (excludes the .mod extension). +% modnamstar: name of .mod file for the alternative regime (excludes the .mod exten- sion). +% constraint: the constraint (see notes 1 and 2 below). When the condition in constraint evaluates to true, the solution switches from the reference to the alternative regime. +% constraint relax: when the condition in constraint relax evaluates to true, the solution returns to the reference regime. +% shockssequence: a sequence of unforeseen shocks under which one wants to solve the model (size T�nshocks). +% irfshock: label for innovation for IRFs, from Dynare .mod file (one or more of the ?varexo?). +% nperiods: simulation horizon (can be longer than the sequence of shocks defined in shockssequence; must be long enough to ensure convergence back to the reference model at the end of the simulation horizon and may need to be varied depending on the sequence of shocks). +% maxiter: maximum number of iterations allowed for the solution algorithm (20 if not specified). +% init: the initial position for the vector of state variables, in deviation from steady state (if not specified, the default is steady state). The ordering follows the definition order in the .mod files. +% +% Outputs: +% zdatalinear: an array containing paths for all endogenous variables ignoring the occasionally binding constraint (the linear solution), in deviation from steady state. Each column is a variable, the order is the definition order in the .mod files. +% zdatapiecewise: an array containing paths for all endogenous variables satisfying the occasionally binding constraint (the occbin/piecewise solution), in deviation from steady state. Each column is a variable, the order is the definition order in the .mod files. +% zdatass: theinitialpositionforthevectorofstatevariables,indeviationfromsteady state (if not specified, the default is a vectors of zero implying that the initial conditions coincide with the steady state). The ordering follows the definition order in the .mod files. +% oobase,Mbase: structures produced by Dynare for the reference model ? see Dynare User Guide. + +% Log of changes: +% 6/17/2013 -- Luca added a trailing underscore to local variables in an +% attempt to avoid conflicts with parameter names defined in the .mod files +% to be processed. +% 6/17/2013 -- Luca replaced external .m file setss.m + + +function [zdatalinear_ zdatapiecewise_ zdatass_ oobase_ Mbase_ ] = ... + solve_one_constraint(modnam_,modnamstar_,... + constraint_, constraint_relax_,... + shockssequence_,irfshock_,nperiods_,maxiter_,init_) + +global M_ oo_ + +errlist_ = []; + +% solve the reference model linearly +eval(['dynare ',modnam_,' noclearall nolog ']) +oobase_ = oo_; +Mbase_ = M_; + +% import locally the values of parameters assigned in the reference .mod +% file +for i_indx_ = 1:Mbase_.param_nbr + eval([Mbase_.param_names(i_indx_,:),'= M_.params(i_indx_);']); +end + +% Create steady state values of the variables if needed for processing the constraint +for i=1:Mbase_.endo_nbr + eval([deblank(Mbase_.endo_names(i,:)) '_ss = oobase_.dr.ys(i); ']); +end + + +% parse the .mod file for the alternative regime +eval(['dynare ',modnamstar_,' noclearall nolog ']) +oostar_ = oo_; +Mstar_ = M_; + + +% check inputs +if ~strcmp(Mbase_.endo_names,Mstar_.endo_names) + error('The two .mod files need to have exactly the same endogenous variables declared in the same order') +end + +if ~strcmp(Mbase_.exo_names,Mstar_.exo_names) + error('The two .mod files need to have exactly the same exogenous variables declared in the same order') +end + +if ~strcmp(Mbase_.param_names,Mstar_.param_names) + warning('The parameter list does not match across .mod files') +end + +% ensure that the two models have the same parameters +% use the parameters for the base model. +Mstar_.params = Mbase_.params; + +nvars_ = Mbase_.endo_nbr; +zdatass_ = oobase_.dr.ys; + + +% get the matrices holding the first derivatives for the model +% each regime is treated separately +[hm1_,h_,hl1_,Jbarmat_] = get_deriv(Mbase_,zdatass_); +cof_ = [hm1_,h_,hl1_]; + +[hm1_,h_,hl1_,Jstarbarmat_,resid_] = get_deriv(Mstar_,zdatass_); +cofstar_ = [hm1_,h_,hl1_]; +Dstartbarmat_ = resid_; + +if isfield(Mbase_,'nfwrd') + % the latest Dynare distributions have moved nstatic and nfwrd + [decrulea_,decruleb_]=get_pq(oobase_.dr,Mbase_.nstatic,Mbase_.nfwrd); +else + [decrulea_,decruleb_]=get_pq(oobase_.dr,oobase_.dr.nstatic,oobase_.dr.nfwrd); +end + +endog_ = M_.endo_names; +exog_ = M_.exo_names; + + +% processes the constraints specified in the call to this function +% uppend a suffix to each endogenous variable +constraint_difference_ = process_constraint(constraint_,'_difference',Mbase_.endo_names,0); + +constraint_relax_difference_ = process_constraint(constraint_relax_,'_difference',Mbase_.endo_names,0); + + + +nshocks_ = size(shockssequence_,1); + +% if necessary, set default values for optional arguments +if ~exist('init_') + init_ = zeros(nvars_,1); +end + +if ~exist('maxiter_') + maxiter_ = 20; +end + +if ~exist('nperiods_') + nperiods_ = 100; +end + + +% set some initial conditions and loop through the shocks +% period by period +init_orig_ = init_; +zdatapiecewise_ = zeros(nperiods_,nvars_); +wishlist_ = endog_; +nwishes_ = size(wishlist_,1); +violvecbool_ = zeros(nperiods_+1,1); + + +for ishock_ = 1:nshocks_ + + changes_=1; + iter_ = 0; + + + while (changes_ & iter_<maxiter_) + iter_ = iter_ +1; + + % analyze when each regime starts based on current guess + [regime regimestart]=map_regime(violvecbool_); + + + + % get the hypothesized piece wise linear solution + [zdatalinear_]=mkdatap_anticipated(nperiods_,decrulea_,decruleb_,... + cof_,Jbarmat_,cofstar_,Jstarbarmat_,Dstartbarmat_,... + regime,regimestart,violvecbool_,... + endog_,exog_,irfshock_,shockssequence_(ishock_,:),init_); + + for i_indx_=1:nwishes_ + eval([deblank(wishlist_(i_indx_,:)),'_difference=zdatalinear_(:,i_indx_);']); + end + + + + newviolvecbool_ = eval(constraint_difference_); + relaxconstraint_ = eval(constraint_relax_difference_); + + + + % check if changes to the hypothesis of the duration for each + % regime + if (max(newviolvecbool_-violvecbool_>0)) | sum(relaxconstraint_(find(violvecbool_==1))>0) + changes_ = 1; + else + changes_ = 0; + end + + + + violvecbool_ = (violvecbool_|newviolvecbool_)-(relaxconstraint_ & violvecbool_); + + + end + + init_ = zdatalinear_(1,:); + zdatapiecewise_(ishock_,:)=init_; + init_= init_'; + + % reset violvecbool_ for next period's shock -- this resetting is + % consistent with expecting no additional shocks + violvecbool_=[violvecbool_(2:end);0]; + +end + +% if necessary, fill in the rest of the path with the remainder of the +% last IRF computed. +zdatapiecewise_(ishock_+1:end,:)=zdatalinear_(2:nperiods_-ishock_+1,:); + +% get the linear responses +zdatalinear_ = mkdata(max(nperiods_,size(shockssequence_,1)),... + decrulea_,decruleb_,endog_,exog_,... + wishlist_,irfshock_,shockssequence_,init_orig_); + +if changes_ ==1 + display('Did not converge -- increase maxiter_') +end diff --git a/matlab/occbin/solve_two_constraints.m b/matlab/occbin/solve_two_constraints.m index dfca403a22..0ca5d559a0 100755 --- a/matlab/occbin/solve_two_constraints.m +++ b/matlab/occbin/solve_two_constraints.m @@ -1,305 +1,305 @@ -% [zdatalinear zdatapiecewise zdatass oo 00 M 00] = solve two constraints(modnam 00,modnam 10,modnam 01,modnam 11,... constraint1, constraint2,... constraint relax1, constraint relax2,... shockssequence,irfshock,nperiods,curb retrench,maxiter,init); -% -% Inputs: -% modnam 00: name of the .mod file for reference regime (excludes the .mod extension). modnam10: name of the .mod file for the alternative regime governed by the first -% constraint. -% modnam01: name of the .mod file for the alternative regime governed by the second constraint. -% modnam 11: name of the .mod file for the case in which both constraints force a switch to their alternative regimes. -% constraint1: the first constraint (see notes 1 and 2 below). If constraint1 evaluates to true, then the solution switches to the alternative regime for condition 1. In thatcase, if constraint2 (described below) evaluates to false, then the model solution switches to enforcing the conditions for an equilibrium in modnam 10. Otherwise, if constraint2 also evaluates to true, then the model solution switches to enforcing the conditions for an equilibrium in modnam 11. -% constraint relax1: when the condition in constraint relax1 evaluates to true, the solution returns to the reference regime for constraint1. -% constraint2: the second constraint (see notes 1 and 2 below). constraint relax2: when the condition in constraint relax2 evaluates to true, the -% solution returns to the reference regime for constraint2. shockssequence: a sequence of unforeseen shocks under which one wants to solve the -% model -% irfshock: label for innovation for IRFs, from Dynare .mod file (one or more of the ?varexo?) -% nperiods: simulation horizon (can be longer than the sequence of shocks defined in shockssequence; must be long enough to ensure convergence back to the reference model at the end of the simulation horizon and may need to be varied depending on the sequence of shocks). -% curb retrench: a scalar equal to 0 or 1. Default is 0. When set to 0, it updates the guess based of regimes based on the previous iteration. When set to 1, it updates in a manner similar to a Gauss-Jacobi scheme, slowing the iterations down by updating the guess of regimes only one period at a time. -% maxiter: maximum number of iterations allowed for the solution algorithm (20 if not specified). -% init: the initial position for the vector of state variables, in deviation from steady state (if not specified, the default is a vector of zero implying that the initial conditions coincide with the steady state). The ordering follows the definition order in the .mod files. -% -% Outputs: -% zdatalinear: an array containing paths for all endogenous variables ignoring the occasionally binding constraint (the linear solution), in deviation from steady state. Each column is a variable, the order is the definition order in the .mod files. -% zdatapiecewise: an array containing paths for all endogenous variables satisfying the occasionally binding constraint (the occbin/piecewise solution), in deviation from steady state. Each column is a variable, the order is the definition order in the .mod files. -% zdatass: a vector that holds the steady state values of the endogenous variables ( following the definition order in the .mod file). -% oo00 , M00 : structures produced by Dynare for the reference model ? see Dynare User Guide. - - -% Log of changes -% 6/17/2013 -- Luca added a trailing underscore to local variables in an -% attempt to avoid conflicts with parameter names defined in the .mod files -% to be processed. -% 6/17/2013 -- Luca replaced external .m file setss.m - -function [ zdatalinear_ zdatapiecewise_ zdatass_ oo00_ M00_ ] = ... - solve_two_constraints(modnam_00_,modnam_10_,modnam_01_,modnam_11_,... - constrain1_, constrain2_,... - constraint_relax1_, constraint_relax2_,... - shockssequence_,irfshock_,nperiods_,curb_retrench_,maxiter_,init_) - -global M_ oo_ - - - -% solve model -eval(['dynare ',modnam_00_,' noclearall nolog']) -oo00_ = oo_; -M00_ = M_; - - -for i=1:M00_.endo_nbr - eval([deblank(M00_.endo_names(i,:)) '_ss = oo00_.dr.ys(i); ']); -end - -for i_indx_ = 1:M00_.param_nbr - eval([M00_.param_names(i_indx_,:),'= M00_.params(i_indx_);']); -end - - - -eval(['dynare ',modnam_10_,' noclearall']) -oo10_ = oo_; -M10_ = M_; - -eval(['dynare ',modnam_01_,' noclearall']) -oo01_ = oo_; -M01_ = M_; - -eval(['dynare ',modnam_11_,' noclearall']) -oo11_ = oo_; -M11_ = M_; - - -% do some error checking - -% check inputs -if ~strcmp(M00_.endo_names,M10_.endo_names) - error([modnam_00_,' and ',modnam_10_,' need to have exactly the same endogenous variables and they need to be declared in the same order']) -end - -if ~strcmp(M00_.exo_names,M10_.exo_names) - error([modnam_00_,' and ',modnam_10_,' need to have exactly the same exogenous variables and they need to be declared in the same order']) -end - -if ~strcmp(M00_.param_names,M10_.param_names) - warning(['The parameter list does not match across the files ',modnam_00_,' and ',modnam_10_]) -end - - -if ~strcmp(M00_.endo_names,M01_.endo_names) - error([modnam_00,' and ',modnam_01_,' need to have exactly the same endogenous variables and they need to be declared in the same order']) -end - -if ~strcmp(M00_.exo_names,M01_.exo_names) - error([modnam_00_,' and ',modnam_01_,' need to have exactly the same exogenous variables and they need to be declared in the same order']) -end - -if ~strcmp(M00_.param_names,M01_.param_names) - warning(['The parameter list does not match across the files ',modnam_00_,' and ',modnam_01_]) -end - - -if ~strcmp(M00_.endo_names,M11_.endo_names) - error([modnam_00_,' and ',modnam_11_,' need to have exactly the same endogenous variables and they need to be declared in the same order']) -end - -if ~strcmp(M00_.exo_names,M11_.exo_names) - error([modnam_00_,' and ',modnam_11_,' need to have exactly the same exogenous variables and they need to be declared in the same order']) -end - -if ~strcmp(M00_.param_names,M11_.param_names) - warning(['The parameter list does not match across the files ',modnam_00_,' and ',modnam_11_]) -end - - - - - -nvars_ = M00_.endo_nbr; -zdatass_ = oo00_.dr.ys; - - -[hm1_,h_,hl1_,Jbarmat_] = get_deriv(M00_,zdatass_); -cof_ = [hm1_,h_,hl1_]; - - -M10_.params = M00_.params; -[hm1_,h_,hl1_,Jbarmat10_,resid_] = get_deriv(M10_,zdatass_); -cof10_ = [hm1_,h_,hl1_]; -Dbarmat10_ = resid_; - -M01_.params = M00_.params; -[hm1_,h_,hl1_,Jbarmat01_,resid_] = get_deriv(M01_,zdatass_); -cof01_ = [hm1_,h_,hl1_]; -Dbarmat01_ = resid_; - -M11_.params = M00_.params; -[hm1_,h_,hl1_,Jbarmat11_,resid_] = get_deriv(M11_,zdatass_); -cof11_ = [hm1_,h_,hl1_]; -Dbarmat11_ = resid_; - - -if isfield(M00_,'nfwrd') % needed for bakward compatibility with older Dynare releases -[decrulea,decruleb]=get_pq(oo00_.dr,M00_.nstatic,M00_.nfwrd); -else -[decrulea,decruleb]=get_pq(oo00_.dr,oo00_.dr.nstatic,oo00_.dr.nfwrd); -end -endog_ = M00_.endo_names; -exog_ = M00_.exo_names; - - -% processes the constrain so as to uppend a suffix to each -% endogenous variables -constraint1_difference_ = process_constraint(constrain1_,'_difference',M00_.endo_names,0); - -% when the last argument in process_constraint is set to 1, the -% direction of the inequality in the constraint is inverted -constraint_relax1_difference_ = process_constraint(constraint_relax1_,'_difference',M00_.endo_names,0); - - -% processes the constrain so as to uppend a suffix to each -% endogenous variables -constraint2_difference_ = process_constraint(constrain2_,'_difference',M00_.endo_names,0); - -% when the last argument in process_constraint is set to 1, the -% direction of the inequality in the constraint is inverted -constraint_relax2_difference_ = process_constraint(constraint_relax2_,'_difference',M00_.endo_names,0); - - - -nshocks = size(shockssequence_,1); - - - - -if ~exist('init_') - init_ = zeros(nvars_,1); -end - -if ~exist('maxiter_') - maxiter_ = 20; -end - -if ~exist('curb_retrench_') - curb_retrench_ = 0; -end - -init_orig_ = init_; - - - - - - -zdatapiecewise_ = zeros(nperiods_,nvars_); - - -violvecbool_ = zeros(nperiods_+1,2); % This sets the first guess for when -% the constraints are going to hold. -% The variable is a boolean with two -% columns. The first column refers to -% constrain1_; the second to -% constrain2_. -% Each row is a period in time. -% If the boolean is true it indicates -% the relevant constraint is expected -% to evaluate to true. -% The default initial guess is -% consistent with the base model always -% holding -- equivalent to the linear -% solution. - -wishlist_ = endog_; -nwishes_ = size(wishlist_,1); -for ishock_ = 1:nshocks - - - changes_=1; - iter_ = 0; - - while (changes_ & iter_<maxiter_) - iter_ = iter_ +1; - - % analyse violvec and isolate contiguous periods in the other - % regime. - [regime1 regimestart1]=map_regime(violvecbool_(:,1)); - [regime2 regimestart2]=map_regime(violvecbool_(:,2)); - - - [zdatalinear_]=mkdatap_anticipated_2constraints(nperiods_,decrulea,decruleb,... - cof_,Jbarmat_,... - cof10_,Jbarmat10_,Dbarmat10_,... - cof01_,Jbarmat01_,Dbarmat01_,... - cof11_,Jbarmat11_,Dbarmat11_,... - regime1,regimestart1,... - regime2,regimestart2,... - violvecbool_,endog_,exog_,... - irfshock_,shockssequence_(ishock_,:),init_); - - for i_indx_=1:nwishes_ - eval([deblank(wishlist_(i_indx_,:)),'_difference=zdatalinear_(:,i_indx_);']); - end - - - - - newviolvecbool1_ = eval(constraint1_difference_); - relaxconstraint1_ = eval(constraint_relax1_difference_); - - newviolvecbool2_ = eval(constraint2_difference_); - relaxconstraint2_ = eval(constraint_relax2_difference_); - - - - newviolvecbool_ = [newviolvecbool1_;newviolvecbool2_]; - relaxconstraint_ = [relaxconstraint1_;relaxconstraint2_]; - - - - % check if changes_ - if (max(newviolvecbool_(:)-violvecbool_(:)>0)) | sum(relaxconstraint_(find(violvecbool_==1))>0) - changes_ = 1; - else - changes_ = 0; - end - - if curb_retrench_ % apply Gauss-Sidel idea of slowing down the change in the guess - % for the constraint -- only relax one - % period at a time starting from the last - % one when each of the constraints is true. - retrench = 0*violvecbool_(:); - if ~isempty(find(relaxconstraint1_ & violvecbool_(:,1))) - retrenchpos = max(find(relaxconstraint1_ & violvecbool_(:,1))); - retrench(retrenchpos) = 1; - end - if ~isempty(find(relaxconstraint2_ & violvecbool_(:,2))) - retrenchpos = max(find(relaxconstraint2_ & violvecbool_(:,2))); - retrench(retrenchpos+nperiods_+1) = 1; - end - violvecbool_ = (violvecbool_(:) | newviolvecbool_(:))-retrench(:); - else - violvecbool_ = (violvecbool_(:) | newviolvecbool_(:))-(relaxconstraint_(:) & violvecbool_(:)); - end - - violvecbool_ = reshape(violvecbool_,nperiods_+1,2); - - - - end - if changes_ ==1 - display('Did not converge -- increase maxiter') - end - - init_ = zdatalinear_(1,:); - zdatapiecewise_(ishock_,:)=init_; - init_= init_'; - - % update the guess for constraint violations for next period - % update is consistent with expecting no additional shocks next period - violvecbool_=[violvecbool_(2:end,:);zeros(1,2)]; - -end - - -zdatapiecewise_(ishock_+1:end,:)=zdatalinear_(2:nperiods_-ishock_+1,:); - -zdatalinear_ = mkdata(nperiods_,decrulea,decruleb,endog_,exog_,wishlist_,irfshock_,shockssequence_,init_orig_); - +% [zdatalinear zdatapiecewise zdatass oo 00 M 00] = solve two constraints(modnam 00,modnam 10,modnam 01,modnam 11,... constraint1, constraint2,... constraint relax1, constraint relax2,... shockssequence,irfshock,nperiods,curb retrench,maxiter,init); +% +% Inputs: +% modnam 00: name of the .mod file for reference regime (excludes the .mod extension). modnam10: name of the .mod file for the alternative regime governed by the first +% constraint. +% modnam01: name of the .mod file for the alternative regime governed by the second constraint. +% modnam 11: name of the .mod file for the case in which both constraints force a switch to their alternative regimes. +% constraint1: the first constraint (see notes 1 and 2 below). If constraint1 evaluates to true, then the solution switches to the alternative regime for condition 1. In thatcase, if constraint2 (described below) evaluates to false, then the model solution switches to enforcing the conditions for an equilibrium in modnam 10. Otherwise, if constraint2 also evaluates to true, then the model solution switches to enforcing the conditions for an equilibrium in modnam 11. +% constraint relax1: when the condition in constraint relax1 evaluates to true, the solution returns to the reference regime for constraint1. +% constraint2: the second constraint (see notes 1 and 2 below). constraint relax2: when the condition in constraint relax2 evaluates to true, the +% solution returns to the reference regime for constraint2. shockssequence: a sequence of unforeseen shocks under which one wants to solve the +% model +% irfshock: label for innovation for IRFs, from Dynare .mod file (one or more of the ?varexo?) +% nperiods: simulation horizon (can be longer than the sequence of shocks defined in shockssequence; must be long enough to ensure convergence back to the reference model at the end of the simulation horizon and may need to be varied depending on the sequence of shocks). +% curb retrench: a scalar equal to 0 or 1. Default is 0. When set to 0, it updates the guess based of regimes based on the previous iteration. When set to 1, it updates in a manner similar to a Gauss-Jacobi scheme, slowing the iterations down by updating the guess of regimes only one period at a time. +% maxiter: maximum number of iterations allowed for the solution algorithm (20 if not specified). +% init: the initial position for the vector of state variables, in deviation from steady state (if not specified, the default is a vector of zero implying that the initial conditions coincide with the steady state). The ordering follows the definition order in the .mod files. +% +% Outputs: +% zdatalinear: an array containing paths for all endogenous variables ignoring the occasionally binding constraint (the linear solution), in deviation from steady state. Each column is a variable, the order is the definition order in the .mod files. +% zdatapiecewise: an array containing paths for all endogenous variables satisfying the occasionally binding constraint (the occbin/piecewise solution), in deviation from steady state. Each column is a variable, the order is the definition order in the .mod files. +% zdatass: a vector that holds the steady state values of the endogenous variables ( following the definition order in the .mod file). +% oo00 , M00 : structures produced by Dynare for the reference model ? see Dynare User Guide. + + +% Log of changes +% 6/17/2013 -- Luca added a trailing underscore to local variables in an +% attempt to avoid conflicts with parameter names defined in the .mod files +% to be processed. +% 6/17/2013 -- Luca replaced external .m file setss.m + +function [ zdatalinear_ zdatapiecewise_ zdatass_ oo00_ M00_ ] = ... + solve_two_constraints(modnam_00_,modnam_10_,modnam_01_,modnam_11_,... + constrain1_, constrain2_,... + constraint_relax1_, constraint_relax2_,... + shockssequence_,irfshock_,nperiods_,curb_retrench_,maxiter_,init_) + +global M_ oo_ + + + +% solve model +eval(['dynare ',modnam_00_,' noclearall nolog']) +oo00_ = oo_; +M00_ = M_; + + +for i=1:M00_.endo_nbr + eval([deblank(M00_.endo_names(i,:)) '_ss = oo00_.dr.ys(i); ']); +end + +for i_indx_ = 1:M00_.param_nbr + eval([M00_.param_names(i_indx_,:),'= M00_.params(i_indx_);']); +end + + + +eval(['dynare ',modnam_10_,' noclearall']) +oo10_ = oo_; +M10_ = M_; + +eval(['dynare ',modnam_01_,' noclearall']) +oo01_ = oo_; +M01_ = M_; + +eval(['dynare ',modnam_11_,' noclearall']) +oo11_ = oo_; +M11_ = M_; + + +% do some error checking + +% check inputs +if ~strcmp(M00_.endo_names,M10_.endo_names) + error([modnam_00_,' and ',modnam_10_,' need to have exactly the same endogenous variables and they need to be declared in the same order']) +end + +if ~strcmp(M00_.exo_names,M10_.exo_names) + error([modnam_00_,' and ',modnam_10_,' need to have exactly the same exogenous variables and they need to be declared in the same order']) +end + +if ~strcmp(M00_.param_names,M10_.param_names) + warning(['The parameter list does not match across the files ',modnam_00_,' and ',modnam_10_]) +end + + +if ~strcmp(M00_.endo_names,M01_.endo_names) + error([modnam_00,' and ',modnam_01_,' need to have exactly the same endogenous variables and they need to be declared in the same order']) +end + +if ~strcmp(M00_.exo_names,M01_.exo_names) + error([modnam_00_,' and ',modnam_01_,' need to have exactly the same exogenous variables and they need to be declared in the same order']) +end + +if ~strcmp(M00_.param_names,M01_.param_names) + warning(['The parameter list does not match across the files ',modnam_00_,' and ',modnam_01_]) +end + + +if ~strcmp(M00_.endo_names,M11_.endo_names) + error([modnam_00_,' and ',modnam_11_,' need to have exactly the same endogenous variables and they need to be declared in the same order']) +end + +if ~strcmp(M00_.exo_names,M11_.exo_names) + error([modnam_00_,' and ',modnam_11_,' need to have exactly the same exogenous variables and they need to be declared in the same order']) +end + +if ~strcmp(M00_.param_names,M11_.param_names) + warning(['The parameter list does not match across the files ',modnam_00_,' and ',modnam_11_]) +end + + + + + +nvars_ = M00_.endo_nbr; +zdatass_ = oo00_.dr.ys; + + +[hm1_,h_,hl1_,Jbarmat_] = get_deriv(M00_,zdatass_); +cof_ = [hm1_,h_,hl1_]; + + +M10_.params = M00_.params; +[hm1_,h_,hl1_,Jbarmat10_,resid_] = get_deriv(M10_,zdatass_); +cof10_ = [hm1_,h_,hl1_]; +Dbarmat10_ = resid_; + +M01_.params = M00_.params; +[hm1_,h_,hl1_,Jbarmat01_,resid_] = get_deriv(M01_,zdatass_); +cof01_ = [hm1_,h_,hl1_]; +Dbarmat01_ = resid_; + +M11_.params = M00_.params; +[hm1_,h_,hl1_,Jbarmat11_,resid_] = get_deriv(M11_,zdatass_); +cof11_ = [hm1_,h_,hl1_]; +Dbarmat11_ = resid_; + + +if isfield(M00_,'nfwrd') % needed for bakward compatibility with older Dynare releases + [decrulea,decruleb]=get_pq(oo00_.dr,M00_.nstatic,M00_.nfwrd); +else + [decrulea,decruleb]=get_pq(oo00_.dr,oo00_.dr.nstatic,oo00_.dr.nfwrd); +end +endog_ = M00_.endo_names; +exog_ = M00_.exo_names; + + +% processes the constrain so as to uppend a suffix to each +% endogenous variables +constraint1_difference_ = process_constraint(constrain1_,'_difference',M00_.endo_names,0); + +% when the last argument in process_constraint is set to 1, the +% direction of the inequality in the constraint is inverted +constraint_relax1_difference_ = process_constraint(constraint_relax1_,'_difference',M00_.endo_names,0); + + +% processes the constrain so as to uppend a suffix to each +% endogenous variables +constraint2_difference_ = process_constraint(constrain2_,'_difference',M00_.endo_names,0); + +% when the last argument in process_constraint is set to 1, the +% direction of the inequality in the constraint is inverted +constraint_relax2_difference_ = process_constraint(constraint_relax2_,'_difference',M00_.endo_names,0); + + + +nshocks = size(shockssequence_,1); + + + + +if ~exist('init_') + init_ = zeros(nvars_,1); +end + +if ~exist('maxiter_') + maxiter_ = 20; +end + +if ~exist('curb_retrench_') + curb_retrench_ = 0; +end + +init_orig_ = init_; + + + + + + +zdatapiecewise_ = zeros(nperiods_,nvars_); + + +violvecbool_ = zeros(nperiods_+1,2); % This sets the first guess for when + % the constraints are going to hold. + % The variable is a boolean with two + % columns. The first column refers to + % constrain1_; the second to + % constrain2_. + % Each row is a period in time. + % If the boolean is true it indicates + % the relevant constraint is expected + % to evaluate to true. + % The default initial guess is + % consistent with the base model always + % holding -- equivalent to the linear + % solution. + +wishlist_ = endog_; +nwishes_ = size(wishlist_,1); +for ishock_ = 1:nshocks + + + changes_=1; + iter_ = 0; + + while (changes_ & iter_<maxiter_) + iter_ = iter_ +1; + + % analyse violvec and isolate contiguous periods in the other + % regime. + [regime1 regimestart1]=map_regime(violvecbool_(:,1)); + [regime2 regimestart2]=map_regime(violvecbool_(:,2)); + + + [zdatalinear_]=mkdatap_anticipated_2constraints(nperiods_,decrulea,decruleb,... + cof_,Jbarmat_,... + cof10_,Jbarmat10_,Dbarmat10_,... + cof01_,Jbarmat01_,Dbarmat01_,... + cof11_,Jbarmat11_,Dbarmat11_,... + regime1,regimestart1,... + regime2,regimestart2,... + violvecbool_,endog_,exog_,... + irfshock_,shockssequence_(ishock_,:),init_); + + for i_indx_=1:nwishes_ + eval([deblank(wishlist_(i_indx_,:)),'_difference=zdatalinear_(:,i_indx_);']); + end + + + + + newviolvecbool1_ = eval(constraint1_difference_); + relaxconstraint1_ = eval(constraint_relax1_difference_); + + newviolvecbool2_ = eval(constraint2_difference_); + relaxconstraint2_ = eval(constraint_relax2_difference_); + + + + newviolvecbool_ = [newviolvecbool1_;newviolvecbool2_]; + relaxconstraint_ = [relaxconstraint1_;relaxconstraint2_]; + + + + % check if changes_ + if (max(newviolvecbool_(:)-violvecbool_(:)>0)) | sum(relaxconstraint_(find(violvecbool_==1))>0) + changes_ = 1; + else + changes_ = 0; + end + + if curb_retrench_ % apply Gauss-Sidel idea of slowing down the change in the guess + % for the constraint -- only relax one + % period at a time starting from the last + % one when each of the constraints is true. + retrench = 0*violvecbool_(:); + if ~isempty(find(relaxconstraint1_ & violvecbool_(:,1))) + retrenchpos = max(find(relaxconstraint1_ & violvecbool_(:,1))); + retrench(retrenchpos) = 1; + end + if ~isempty(find(relaxconstraint2_ & violvecbool_(:,2))) + retrenchpos = max(find(relaxconstraint2_ & violvecbool_(:,2))); + retrench(retrenchpos+nperiods_+1) = 1; + end + violvecbool_ = (violvecbool_(:) | newviolvecbool_(:))-retrench(:); + else + violvecbool_ = (violvecbool_(:) | newviolvecbool_(:))-(relaxconstraint_(:) & violvecbool_(:)); + end + + violvecbool_ = reshape(violvecbool_,nperiods_+1,2); + + + + end + if changes_ ==1 + display('Did not converge -- increase maxiter') + end + + init_ = zdatalinear_(1,:); + zdatapiecewise_(ishock_,:)=init_; + init_= init_'; + + % update the guess for constraint violations for next period + % update is consistent with expecting no additional shocks next period + violvecbool_=[violvecbool_(2:end,:);zeros(1,2)]; + +end + + +zdatapiecewise_(ishock_+1:end,:)=zdatalinear_(2:nperiods_-ishock_+1,:); + +zdatalinear_ = mkdata(nperiods_,decrulea,decruleb,endog_,exog_,wishlist_,irfshock_,shockssequence_,init_orig_); + diff --git a/matlab/occbin/strmerge.m b/matlab/occbin/strmerge.m index b8585df04d..8aebb00995 100755 --- a/matlab/occbin/strmerge.m +++ b/matlab/occbin/strmerge.m @@ -1,9 +1,9 @@ -function string = strmerge(tokens) - -ntokens = length(tokens); - -string = char(tokens(1)); - -for i=2:ntokens - string = [string,char(tokens(i))]; +function string = strmerge(tokens) + +ntokens = length(tokens); + +string = char(tokens(1)); + +for i=2:ntokens + string = [string,char(tokens(i))]; end \ No newline at end of file diff --git a/matlab/occbin/tokenize.m b/matlab/occbin/tokenize.m index f6e9f330c9..257be91313 100755 --- a/matlab/occbin/tokenize.m +++ b/matlab/occbin/tokenize.m @@ -1,55 +1,55 @@ -function tokens = tokenize(source,delimiter) -% syntax -% tokens = tokenize(source,delimiters) -% -% source is a string to be broken into tokens -% delimiters is a character array of single character delimiters -% tokens is a cell string array containing the tokens - - -posdelims = []; - -% assumes that delimiter cannot be in the first position or the last -% position -ndelimiters = size(delimiter,1); -for i=1:ndelimiters - newpositions = strfind(source,delimiter(i,:)); - if ~isempty(newpositions) - posdelims =[posdelims, newpositions]; - end -end - -% reorder posdelims in ascending order -posdelims = sort(posdelims); - -if isempty(posdelims) - tokens = cellstr(source); -else - ndelims = length(posdelims); - % build positions for substrings - delims = zeros(ndelims+1,2); - for i=1:ndelims+1; - if i==1 - if posdelims(1) == 1 - tokens = cellstr(source(1)); - else - delims(i,:) = [1,posdelims(i)-1]; - tokens = cellstr(source([delims(i,1):delims(i,2)])); - tokens = [tokens, source(posdelims(i))]; - end - elseif i==ndelims+1 - if (posdelims(i-1) < length(source)) - delims(i,:) = [posdelims(i-1)+1,length(source)]; - tokens = [tokens, cellstr(source([delims(i,1):delims(i,2)]))]; - end - else - if posdelims(i)>posdelims(i-1)+1 - delims(i,:) = [posdelims(i-1)+1,posdelims(i)-1]; - tokens = [tokens, cellstr(source([delims(i,1):delims(i,2)]))]; - end - tokens = [tokens, source(posdelims(i))]; - end - end - -end - +function tokens = tokenize(source,delimiter) +% syntax +% tokens = tokenize(source,delimiters) +% +% source is a string to be broken into tokens +% delimiters is a character array of single character delimiters +% tokens is a cell string array containing the tokens + + +posdelims = []; + +% assumes that delimiter cannot be in the first position or the last +% position +ndelimiters = size(delimiter,1); +for i=1:ndelimiters + newpositions = strfind(source,delimiter(i,:)); + if ~isempty(newpositions) + posdelims =[posdelims, newpositions]; + end +end + +% reorder posdelims in ascending order +posdelims = sort(posdelims); + +if isempty(posdelims) + tokens = cellstr(source); +else + ndelims = length(posdelims); + % build positions for substrings + delims = zeros(ndelims+1,2); + for i=1:ndelims+1; + if i==1 + if posdelims(1) == 1 + tokens = cellstr(source(1)); + else + delims(i,:) = [1,posdelims(i)-1]; + tokens = cellstr(source([delims(i,1):delims(i,2)])); + tokens = [tokens, source(posdelims(i))]; + end + elseif i==ndelims+1 + if (posdelims(i-1) < length(source)) + delims(i,:) = [posdelims(i-1)+1,length(source)]; + tokens = [tokens, cellstr(source([delims(i,1):delims(i,2)]))]; + end + else + if posdelims(i)>posdelims(i-1)+1 + delims(i,:) = [posdelims(i-1)+1,posdelims(i)-1]; + tokens = [tokens, cellstr(source([delims(i,1):delims(i,2)]))]; + end + tokens = [tokens, source(posdelims(i))]; + end + end + +end + diff --git a/matlab/one_sided_hp_filter.m b/matlab/one_sided_hp_filter.m index 38af32ea28..46fed23437 100644 --- a/matlab/one_sided_hp_filter.m +++ b/matlab/one_sided_hp_filter.m @@ -63,7 +63,7 @@ end %Set up state space q=1/lambda; % the signal-to-noise ration: i.e. var eta_t / var epsilon_t F=[2,-1; - 1,0]; % state transition matrix + 1,0]; % state transition matrix H=[1,0]; % observation matrix Q=[q,0; 0,0]; % covariance matrix state equation errors diff --git a/matlab/optimization/cmaes.m b/matlab/optimization/cmaes.m index 833dbe9b2f..b4790786af 100644 --- a/matlab/optimization/cmaes.m +++ b/matlab/optimization/cmaes.m @@ -1,161 +1,161 @@ function [xmin, ... % minimum search point of last iteration - fmin, ... % function value of xmin - counteval, ... % number of function evaluations done - stopflag, ... % stop criterion reached - out, ... % struct with various histories and solutions - bestever ... % struct containing overall best solution (for convenience) - ] = cmaes( ... - fitfun, ... % name of objective/fitness function - xstart, ... % objective variables initial point, determines N - insigma, ... % initial coordinate wise standard deviation(s) - inopts, ... % options struct, see defopts below - varargin ) % arguments passed to objective function -% cmaes.m, Version 3.56.beta, last change: February, 2012 -% CMAES implements an Evolution Strategy with Covariance Matrix -% Adaptation (CMA-ES) for nonlinear function minimization. For -% introductory comments and copyright (GPL) see end of file (type -% 'type cmaes'). cmaes.m runs with MATLAB (Windows, Linux) and, -% without data logging and plotting, it should run under Octave -% (Linux, package octave-forge is needed). -% -% OPTS = CMAES returns default options. -% OPTS = CMAES('defaults') returns default options quietly. -% OPTS = CMAES('displayoptions') displays options. -% OPTS = CMAES('defaults', OPTS) supplements options OPTS with default -% options. -% -% XMIN = CMAES(FUN, X0, SIGMA[, OPTS]) locates the minimum XMIN of -% function FUN starting from column vector X0 with the initial -% coordinate wise search standard deviation SIGMA. -% -% Input arguments: -% -% FUN is a string function name like 'myfun'. FUN takes as argument a -% column vector of size of X0 and returns a scalar. An easy way to -% implement a hard non-linear constraint is to return NaN. Then, -% this function evaluation is not counted and a newly sampled -% point is tried immediately. -% -% X0 is a column vector, or a matrix, or a string. If X0 is a matrix, -% mean(X0, 2) is taken as initial point. If X0 is a string like -% '2*rand(10,1)-1', the string is evaluated first. -% -% SIGMA is a scalar, or a column vector of size(X0,1), or a string -% that can be evaluated into one of these. SIGMA determines the -% initial coordinate wise standard deviations for the search. -% Setting SIGMA one third of the initial search region is -% appropriate, e.g., the initial point in [0, 6]^10 and SIGMA=2 -% means cmaes('myfun', 3*rand(10,1), 2). If SIGMA is missing and -% size(X0,2) > 1, SIGMA is set to sqrt(var(X0')'). That is, X0 is -% used as a sample for estimating initial mean and variance of the -% search distribution. -% -% OPTS (an optional argument) is a struct holding additional input -% options. Valid field names and a short documentation can be -% discovered by looking at the default options (type 'cmaes' -% without arguments, see above). Empty or missing fields in OPTS -% invoke the default value, i.e. OPTS needs not to have all valid -% field names. Capitalization does not matter and unambiguous -% abbreviations can be used for the field names. If a string is -% given where a numerical value is needed, the string is evaluated -% by eval, where 'N' expands to the problem dimension -% (==size(X0,1)) and 'popsize' to the population size. -% -% [XMIN, FMIN, COUNTEVAL, STOPFLAG, OUT, BESTEVER] = ... -% CMAES(FITFUN, X0, SIGMA) -% returns the best (minimal) point XMIN (found in the last -% generation); function value FMIN of XMIN; the number of needed -% function evaluations COUNTEVAL; a STOPFLAG value as cell array, -% where possible entries are 'fitness', 'tolx', 'tolupx', 'tolfun', -% 'maxfunevals', 'maxiter', 'stoptoresume', 'manual', -% 'warnconditioncov', 'warnnoeffectcoord', 'warnnoeffectaxis', -% 'warnequalfunvals', 'warnequalfunvalhist', 'bug' (use -% e.g. any(strcmp(STOPFLAG, 'tolx')) or findstr(strcat(STOPFLAG, -% 'tolx')) for further processing); a record struct OUT with some -% more output, where the struct SOLUTIONS.BESTEVER contains the overall -% best evaluated point X with function value F evaluated at evaluation -% count EVALS. The last output argument BESTEVER equals -% OUT.SOLUTIONS.BESTEVER. Moreover a history of solutions and -% parameters is written to files according to the Log-options. -% -% A regular manual stop can be achieved via the file signals.par. The -% program is terminated if the first two non-white sequences in any -% line of this file are 'stop' and the value of the LogFilenamePrefix -% option (by default 'outcmaes'). Also a run can be skipped. -% Given, for example, 'skip outcmaes run 2', skips the second run -% if option Restarts is at least 2, and another run will be started. -% -% To run the code completely silently set Disp, Save, and Log options -% to 0. With OPTS.LogModulo > 0 (1 by default) the most important -% data are written to ASCII files permitting to investigate the -% results (e.g. plot with function plotcmaesdat) even while CMAES is -% still running (which can be quite useful on expensive objective -% functions). When OPTS.SaveVariables==1 (default) everything is saved -% in file OPTS.SaveFilename (default 'variablescmaes.mat') allowing to -% resume the search afterwards by using the resume option. -% -% To find the best ever evaluated point load the variables typing -% "es=load('variablescmaes')" and investigate the variable -% es.out.solutions.bestever. -% -% In case of a noisy objective function (uncertainties) set -% OPTS.Noise.on = 1. This option interferes presumably with some -% termination criteria, because the step-size sigma will presumably -% not converge to zero anymore. If CMAES was provided with a -% fifth argument (P1 in the below example, which is passed to the -% objective function FUN), this argument is multiplied with the -% factor given in option Noise.alphaevals, each time the detected -% noise exceeds a threshold. This argument can be used within -% FUN, for example, as averaging number to reduce the noise level. -% -% OPTS.DiagonalOnly > 1 defines the number of initial iterations, -% where the covariance matrix remains diagonal and the algorithm has -% internally linear time complexity. OPTS.DiagonalOnly = 1 means -% keeping the covariance matrix always diagonal and this setting -% also exhibits linear space complexity. This can be particularly -% useful for dimension > 100. The default is OPTS.DiagonalOnly = 0. -% -% OPTS.CMA.active = 1 turns on "active CMA" with a negative update -% of the covariance matrix and checks for positive definiteness. -% OPTS.CMA.active = 2 does not check for pos. def. and is numerically -% faster. Active CMA usually speeds up the adaptation and might -% become a default in near future. -% -% The primary strategy parameter to play with is OPTS.PopSize, which -% can be increased from its default value. Increasing the population -% size (by default linked to increasing parent number OPTS.ParentNumber) -% improves global search properties in exchange to speed. Speed -% decreases, as a rule, at most linearely with increasing population -% size. It is advisable to begin with the default small population -% size. The options Restarts and IncPopSize can be used for an -% automated multistart where the population size is increased by the -% factor IncPopSize (two by default) before each restart. X0 (given as -% string) is reevaluated for each restart. Stopping options -% StopFunEvals, StopIter, MaxFunEvals, and Fitness terminate the -% program, all others including MaxIter invoke another restart, where -% the iteration counter is reset to zero. -% -% Examples: -% -% XMIN = cmaes('myfun', 5*ones(10,1), 1.5); starts the search at -% 10D-point 5 and initially searches mainly between 5-3 and 5+3 -% (+- two standard deviations), but this is not a strict bound. -% 'myfun' is a name of a function that returns a scalar from a 10D -% column vector. -% -% opts.LBounds = 0; opts.UBounds = 10; -% X=cmaes('myfun', 10*rand(10,1), 5, opts); -% search within lower bound of 0 and upper bound of 10. Bounds can -% also be given as column vectors. If the optimum is not located -% on the boundary, use rather a penalty approach to handle bounds. -% -% opts=cmaes; opts.StopFitness=1e-10; -% X=cmaes('myfun', rand(5,1), 0.5, opts); stops the search, if -% the function value is smaller than 1e-10. -% -% [X, F, E, STOP, OUT] = cmaes('myfun2', 'rand(5,1)', 1, [], P1, P2); -% passes two additional parameters to the function MYFUN2. -% + fmin, ... % function value of xmin + counteval, ... % number of function evaluations done + stopflag, ... % stop criterion reached + out, ... % struct with various histories and solutions + bestever ... % struct containing overall best solution (for convenience) + ] = cmaes( ... + fitfun, ... % name of objective/fitness function + xstart, ... % objective variables initial point, determines N + insigma, ... % initial coordinate wise standard deviation(s) + inopts, ... % options struct, see defopts below + varargin ) % arguments passed to objective function + % cmaes.m, Version 3.56.beta, last change: February, 2012 + % CMAES implements an Evolution Strategy with Covariance Matrix + % Adaptation (CMA-ES) for nonlinear function minimization. For + % introductory comments and copyright (GPL) see end of file (type + % 'type cmaes'). cmaes.m runs with MATLAB (Windows, Linux) and, + % without data logging and plotting, it should run under Octave + % (Linux, package octave-forge is needed). + % + % OPTS = CMAES returns default options. + % OPTS = CMAES('defaults') returns default options quietly. + % OPTS = CMAES('displayoptions') displays options. + % OPTS = CMAES('defaults', OPTS) supplements options OPTS with default + % options. + % + % XMIN = CMAES(FUN, X0, SIGMA[, OPTS]) locates the minimum XMIN of + % function FUN starting from column vector X0 with the initial + % coordinate wise search standard deviation SIGMA. + % + % Input arguments: + % + % FUN is a string function name like 'myfun'. FUN takes as argument a + % column vector of size of X0 and returns a scalar. An easy way to + % implement a hard non-linear constraint is to return NaN. Then, + % this function evaluation is not counted and a newly sampled + % point is tried immediately. + % + % X0 is a column vector, or a matrix, or a string. If X0 is a matrix, + % mean(X0, 2) is taken as initial point. If X0 is a string like + % '2*rand(10,1)-1', the string is evaluated first. + % + % SIGMA is a scalar, or a column vector of size(X0,1), or a string + % that can be evaluated into one of these. SIGMA determines the + % initial coordinate wise standard deviations for the search. + % Setting SIGMA one third of the initial search region is + % appropriate, e.g., the initial point in [0, 6]^10 and SIGMA=2 + % means cmaes('myfun', 3*rand(10,1), 2). If SIGMA is missing and + % size(X0,2) > 1, SIGMA is set to sqrt(var(X0')'). That is, X0 is + % used as a sample for estimating initial mean and variance of the + % search distribution. + % + % OPTS (an optional argument) is a struct holding additional input + % options. Valid field names and a short documentation can be + % discovered by looking at the default options (type 'cmaes' + % without arguments, see above). Empty or missing fields in OPTS + % invoke the default value, i.e. OPTS needs not to have all valid + % field names. Capitalization does not matter and unambiguous + % abbreviations can be used for the field names. If a string is + % given where a numerical value is needed, the string is evaluated + % by eval, where 'N' expands to the problem dimension + % (==size(X0,1)) and 'popsize' to the population size. + % + % [XMIN, FMIN, COUNTEVAL, STOPFLAG, OUT, BESTEVER] = ... + % CMAES(FITFUN, X0, SIGMA) + % returns the best (minimal) point XMIN (found in the last + % generation); function value FMIN of XMIN; the number of needed + % function evaluations COUNTEVAL; a STOPFLAG value as cell array, + % where possible entries are 'fitness', 'tolx', 'tolupx', 'tolfun', + % 'maxfunevals', 'maxiter', 'stoptoresume', 'manual', + % 'warnconditioncov', 'warnnoeffectcoord', 'warnnoeffectaxis', + % 'warnequalfunvals', 'warnequalfunvalhist', 'bug' (use + % e.g. any(strcmp(STOPFLAG, 'tolx')) or findstr(strcat(STOPFLAG, + % 'tolx')) for further processing); a record struct OUT with some + % more output, where the struct SOLUTIONS.BESTEVER contains the overall + % best evaluated point X with function value F evaluated at evaluation + % count EVALS. The last output argument BESTEVER equals + % OUT.SOLUTIONS.BESTEVER. Moreover a history of solutions and + % parameters is written to files according to the Log-options. + % + % A regular manual stop can be achieved via the file signals.par. The + % program is terminated if the first two non-white sequences in any + % line of this file are 'stop' and the value of the LogFilenamePrefix + % option (by default 'outcmaes'). Also a run can be skipped. + % Given, for example, 'skip outcmaes run 2', skips the second run + % if option Restarts is at least 2, and another run will be started. + % + % To run the code completely silently set Disp, Save, and Log options + % to 0. With OPTS.LogModulo > 0 (1 by default) the most important + % data are written to ASCII files permitting to investigate the + % results (e.g. plot with function plotcmaesdat) even while CMAES is + % still running (which can be quite useful on expensive objective + % functions). When OPTS.SaveVariables==1 (default) everything is saved + % in file OPTS.SaveFilename (default 'variablescmaes.mat') allowing to + % resume the search afterwards by using the resume option. + % + % To find the best ever evaluated point load the variables typing + % "es=load('variablescmaes')" and investigate the variable + % es.out.solutions.bestever. + % + % In case of a noisy objective function (uncertainties) set + % OPTS.Noise.on = 1. This option interferes presumably with some + % termination criteria, because the step-size sigma will presumably + % not converge to zero anymore. If CMAES was provided with a + % fifth argument (P1 in the below example, which is passed to the + % objective function FUN), this argument is multiplied with the + % factor given in option Noise.alphaevals, each time the detected + % noise exceeds a threshold. This argument can be used within + % FUN, for example, as averaging number to reduce the noise level. + % + % OPTS.DiagonalOnly > 1 defines the number of initial iterations, + % where the covariance matrix remains diagonal and the algorithm has + % internally linear time complexity. OPTS.DiagonalOnly = 1 means + % keeping the covariance matrix always diagonal and this setting + % also exhibits linear space complexity. This can be particularly + % useful for dimension > 100. The default is OPTS.DiagonalOnly = 0. + % + % OPTS.CMA.active = 1 turns on "active CMA" with a negative update + % of the covariance matrix and checks for positive definiteness. + % OPTS.CMA.active = 2 does not check for pos. def. and is numerically + % faster. Active CMA usually speeds up the adaptation and might + % become a default in near future. + % + % The primary strategy parameter to play with is OPTS.PopSize, which + % can be increased from its default value. Increasing the population + % size (by default linked to increasing parent number OPTS.ParentNumber) + % improves global search properties in exchange to speed. Speed + % decreases, as a rule, at most linearely with increasing population + % size. It is advisable to begin with the default small population + % size. The options Restarts and IncPopSize can be used for an + % automated multistart where the population size is increased by the + % factor IncPopSize (two by default) before each restart. X0 (given as + % string) is reevaluated for each restart. Stopping options + % StopFunEvals, StopIter, MaxFunEvals, and Fitness terminate the + % program, all others including MaxIter invoke another restart, where + % the iteration counter is reset to zero. + % + % Examples: + % + % XMIN = cmaes('myfun', 5*ones(10,1), 1.5); starts the search at + % 10D-point 5 and initially searches mainly between 5-3 and 5+3 + % (+- two standard deviations), but this is not a strict bound. + % 'myfun' is a name of a function that returns a scalar from a 10D + % column vector. + % + % opts.LBounds = 0; opts.UBounds = 10; + % X=cmaes('myfun', 10*rand(10,1), 5, opts); + % search within lower bound of 0 and upper bound of 10. Bounds can + % also be given as column vectors. If the optimum is not located + % on the boundary, use rather a penalty approach to handle bounds. + % + % opts=cmaes; opts.StopFitness=1e-10; + % X=cmaes('myfun', rand(5,1), 0.5, opts); stops the search, if + % the function value is smaller than 1e-10. + % + % [X, F, E, STOP, OUT] = cmaes('myfun2', 'rand(5,1)', 1, [], P1, P2); + % passes two additional parameters to the function MYFUN2. + % % Copyright (C) 2001-2012 Nikolaus Hansen, % Copyright (C) 2012 Dynare Team @@ -227,7 +227,7 @@ defopts.Noise.alphaevals = '1+2/(N+10) % factor for increasing 2nd arg to fitf defopts.Noise.callback = '[] % callback function when uncertainty threshold is exceeded'; % defopts.TPA = 0; defopts.CMA.cs = '(mueff+2)/(N+mueff+3) % cumulation constant for step-size'; - %qqq cs = (mueff^0.5)/(N^0.5+mueff^0.5) % the short time horizon version +%qqq cs = (mueff^0.5)/(N^0.5+mueff^0.5) % the short time horizon version defopts.CMA.damps = '1 + 2*max(0,sqrt((mueff-1)/(N+1))-1) + cs % damping for step-size'; % defopts.CMA.ccum = '4/(N+4) % cumulation constant for covariance matrix'; defopts.CMA.ccum = '(4 + mueff/N) / (N+4 + 2*mueff/N) % cumulation constant for pc'; @@ -238,22 +238,22 @@ defopts.CMA.active = '0 % active CMA 1: neg. updates with pos. def. check, 2: n flg_future_setting = 0; % testing for possible future variant(s) if flg_future_setting - disp('in the future') + disp('in the future') - % damps setting from Brockhoff et al 2010 - % this damps diverges with popsize 400: - % cmaeshtml('benchmarkszero', ones(20,1)*2, 5, o, 15); - defopts.CMA.damps = '2*mueff/lambda + 0.3 + cs % damping for step-size'; % cs: for large mueff - % how about: - % defopts.CMA.damps = '2*mueff/lambda + 0.3 + 2*max(0,sqrt((mueff-1)/(N+1))-1) + cs % damping for step-size'; + % damps setting from Brockhoff et al 2010 + % this damps diverges with popsize 400: + % cmaeshtml('benchmarkszero', ones(20,1)*2, 5, o, 15); + defopts.CMA.damps = '2*mueff/lambda + 0.3 + cs % damping for step-size'; % cs: for large mueff + % how about: + % defopts.CMA.damps = '2*mueff/lambda + 0.3 + 2*max(0,sqrt((mueff-1)/(N+1))-1) + cs % damping for step-size'; - % ccum adjusted for large mueff, better on schefelmult? - % TODO: this should also depend on diagonal option!? - defopts.CMA.ccum = '(4 + mueff/N) / (N+4 + 2*mueff/N) % cumulation constant for pc'; + % ccum adjusted for large mueff, better on schefelmult? + % TODO: this should also depend on diagonal option!? + defopts.CMA.ccum = '(4 + mueff/N) / (N+4 + 2*mueff/N) % cumulation constant for pc'; - defopts.CMA.active = '1 % active CMA 1: neg. updates with pos. def. check, 2: neg. updates'; + defopts.CMA.active = '1 % active CMA 1: neg. updates with pos. def. check, 2: neg. updates'; end - + defopts.Resume = 'no % resume former run from SaveFile'; defopts.Science = 'on % off==do some additional (minor) problem capturing, NOT IN USE'; defopts.ReadSignals = 'on % from file signals.par for termination, yet a stumb'; @@ -276,1481 +276,1481 @@ defopts.UserDat2 = ''; 'for saving data/comments associated with the run'; % ---------------------- Handling Input Parameters ---------------------- if nargin < 1 || isequal(fitfun, 'defaults') % pass default options - if nargin < 1 - disp('Default options returned (type "help cmaes" for help).'); - end - xmin = defopts; - if nargin > 1 % supplement second argument with default options - xmin = getoptions(xstart, defopts); - end - return; + if nargin < 1 + disp('Default options returned (type "help cmaes" for help).'); + end + xmin = defopts; + if nargin > 1 % supplement second argument with default options + xmin = getoptions(xstart, defopts); + end + return; end if isequal(fitfun, 'displayoptions') - names = fieldnames(defopts); - for name = names' - disp([name{:} repmat(' ', 1, 20-length(name{:})) ': ''' defopts.(name{:}) '''']); - end - return; + names = fieldnames(defopts); + for name = names' + disp([name{:} repmat(' ', 1, 20-length(name{:})) ': ''' defopts.(name{:}) '''']); + end + return; end input.fitfun = fitfun; % record used input if isempty(fitfun) - % fitfun = definput.fitfun; - % warning(['Objective function not determined, ''' fitfun ''' used']); - error(['Objective function not determined']); + % fitfun = definput.fitfun; + % warning(['Objective function not determined, ''' fitfun ''' used']); + error(['Objective function not determined']); end if ~ischar(fitfun) - error('first argument FUN must be a string'); + error('first argument FUN must be a string'); end if nargin < 2 - xstart = []; + xstart = []; end input.xstart = xstart; if isempty(xstart) - % xstart = definput.xstart; % objective variables initial point - % warning('Initial search point, and problem dimension, not determined'); - error('Initial search point, and problem dimension, not determined'); + % xstart = definput.xstart; % objective variables initial point + % warning('Initial search point, and problem dimension, not determined'); + error('Initial search point, and problem dimension, not determined'); end if nargin < 3 - insigma = []; + insigma = []; end if isa(insigma, 'struct') - error(['Third argument SIGMA must be (or eval to) a scalar '... - 'or a column vector of size(X0,1)']); + error(['Third argument SIGMA must be (or eval to) a scalar '... + 'or a column vector of size(X0,1)']); end input.sigma = insigma; if isempty(insigma) - if all(size(myeval(xstart)) > 1) - insigma = std(xstart, 0, 2); - if any(insigma == 0) - error(['Initial search volume is zero, choose SIGMA or X0 appropriate']); + if all(size(myeval(xstart)) > 1) + insigma = std(xstart, 0, 2); + if any(insigma == 0) + error(['Initial search volume is zero, choose SIGMA or X0 appropriate']); + end + else + % will be captured later + % error(['Initial step sizes (SIGMA) not determined']); end - else - % will be captured later - % error(['Initial step sizes (SIGMA) not determined']); - end end % Compose options opts if nargin < 4 || isempty(inopts) % no input options available - inopts = []; - opts = defopts; + inopts = []; + opts = defopts; else - opts = getoptions(inopts, defopts); + opts = getoptions(inopts, defopts); end i = strfind(opts.SaveFilename, ' '); % remove everything after white space if ~isempty(i) - opts.SaveFilename = opts.SaveFilename(1:i(1)-1); + opts.SaveFilename = opts.SaveFilename(1:i(1)-1); end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% counteval = 0; countevalNaN = 0; irun = 0; while irun <= myeval(opts.Restarts) % for-loop does not work with resume - irun = irun + 1; - -% ------------------------ Initialization ------------------------------- - -% Handle resuming of old run -flgresume = myevalbool(opts.Resume); -xmean = myeval(xstart); -if all(size(xmean) > 1) - xmean = mean(xmean, 2); % in case if xstart is a population -elseif size(xmean, 2) > 1 - xmean = xmean'; -end -if ~flgresume % not resuming a former run - % Assign settings from input parameters and options for myeval... - N = size(xmean, 1); numberofvariables = N; - lambda0 = floor(myeval(opts.PopSize) * myeval(opts.IncPopSize)^(irun-1)); - % lambda0 = floor(myeval(opts.PopSize) * 3^floor((irun-1)/2)); - popsize = lambda0; - lambda = lambda0; - insigma = myeval(insigma); - if all(size(insigma) == [N 2]) - insigma = 0.5 * (insigma(:,2) - insigma(:,1)); - end -else % flgresume is true, do resume former run - tmp = whos('-file', opts.SaveFilename); - for i = 1:length(tmp) - if strcmp(tmp(i).name, 'localopts'); - error('Saved variables include variable "localopts", please remove'); - end - end - local.opts = opts; % keep stopping and display options - local.varargin = varargin; - load(opts.SaveFilename); - varargin = local.varargin; - flgresume = 1; - - % Overwrite old stopping and display options - opts.StopFitness = local.opts.StopFitness; - %%opts.MaxFunEvals = local.opts.MaxFunEvals; - %%opts.MaxIter = local.opts.MaxIter; - opts.StopFunEvals = local.opts.StopFunEvals; - opts.StopIter = local.opts.StopIter; - opts.TolX = local.opts.TolX; - opts.TolUpX = local.opts.TolUpX; - opts.TolFun = local.opts.TolFun; - opts.TolHistFun = local.opts.TolHistFun; - opts.StopOnStagnation = local.opts.StopOnStagnation; - opts.StopOnWarnings = local.opts.StopOnWarnings; - opts.ReadSignals = local.opts.ReadSignals; - opts.DispFinal = local.opts.DispFinal; - opts.LogPlot = local.opts.LogPlot; - opts.DispModulo = local.opts.DispModulo; - opts.SaveVariables = local.opts.SaveVariables; - opts.LogModulo = local.opts.LogModulo; - opts.LogTime = local.opts.LogTime; - clear local; % otherwise local would be overwritten during load -end - -%-------------------------------------------------------------- -% Evaluate options -stopFitness = myeval(opts.StopFitness); -stopMaxFunEvals = myeval(opts.MaxFunEvals); -stopMaxIter = myeval(opts.MaxIter); -stopFunEvals = myeval(opts.StopFunEvals); -stopIter = myeval(opts.StopIter); -stopTolX = myeval(opts.TolX); -stopTolUpX = myeval(opts.TolUpX); -stopTolFun = myeval(opts.TolFun); -stopTolHistFun = myeval(opts.TolHistFun); -stopOnStagnation = myevalbool(opts.StopOnStagnation); -stopOnWarnings = myevalbool(opts.StopOnWarnings); -flgreadsignals = myevalbool(opts.ReadSignals); -flgWarnOnEqualFunctionValues = myevalbool(opts.WarnOnEqualFunctionValues); -flgEvalParallel = myevalbool(opts.EvalParallel); -stopOnEqualFunctionValues = myeval(opts.StopOnEqualFunctionValues); -arrEqualFunvals = zeros(1,10+N); -flgDiagonalOnly = myeval(opts.DiagonalOnly); -flgActiveCMA = myeval(opts.CMA.active); -noiseHandling = myevalbool(opts.Noise.on); -noiseMinMaxEvals = myeval(opts.Noise.minmaxevals); -noiseAlphaEvals = myeval(opts.Noise.alphaevals); -noiseCallback = myeval(opts.Noise.callback); -flgdisplay = myevalbool(opts.DispFinal); -flgplotting = myevalbool(opts.LogPlot); -verbosemodulo = myeval(opts.DispModulo); -flgscience = myevalbool(opts.Science); -flgsaving = []; -strsaving = []; -if strfind(opts.SaveVariables, '-v6') - i = strfind(opts.SaveVariables, '%'); - if isempty(i) || i == 0 || strfind(opts.SaveVariables, '-v6') < i - strsaving = '-v6'; - flgsaving = 1; - flgsavingfinal = 1; - end -end -if strncmp('final', opts.SaveVariables, 5) - flgsaving = 0; - flgsavingfinal = 1; -end -if isempty(flgsaving) - flgsaving = myevalbool(opts.SaveVariables); - flgsavingfinal = flgsaving; -end -savemodulo = myeval(opts.LogModulo); -savetime = myeval(opts.LogTime); - -i = strfind(opts.LogFilenamePrefix, ' '); % remove everything after white space -if ~isempty(i) - opts.LogFilenamePrefix = opts.LogFilenamePrefix(1:i(1)-1); -end - -% TODO here silent option? set disp, save and log options to 0 - -%-------------------------------------------------------------- - -if (isfinite(stopFunEvals) || isfinite(stopIter)) && ~flgsaving - warning('To resume later the saving option needs to be set'); -end - - -% Do more checking and initialization -if flgresume % resume is on - time.t0 = clock; - if flgdisplay - disp([' resumed from ' opts.SaveFilename ]); - end - if counteval >= stopMaxFunEvals - error(['MaxFunEvals exceeded, use StopFunEvals as stopping ' ... - 'criterion before resume']); - end - if countiter >= stopMaxIter - error(['MaxIter exceeded, use StopIter as stopping criterion ' ... - 'before resume']); - end - -else % flgresume - % xmean = mean(myeval(xstart), 2); % evaluate xstart again, because of irun - maxdx = myeval(opts.DiffMaxChange); % maximal sensible variable change - mindx = myeval(opts.DiffMinChange); % minimal sensible variable change - % can both also be defined as Nx1 vectors - lbounds = myeval(opts.LBounds); - ubounds = myeval(opts.UBounds); - if length(lbounds) == 1 - lbounds = repmat(lbounds, N, 1); - end - if length(ubounds) == 1 - ubounds = repmat(ubounds, N, 1); - end - if isempty(insigma) % last chance to set insigma - if all(lbounds > -Inf) && all(ubounds < Inf) - if any(lbounds>=ubounds) - error('upper bound must be greater than lower bound'); - end - insigma = 0.3*(ubounds-lbounds); - stopTolX = myeval(opts.TolX); % reevaluate these - stopTolUpX = myeval(opts.TolUpX); - else - error(['Initial step sizes (SIGMA) not determined']); - end - end - - % Check all vector sizes - if size(xmean, 2) > 1 || size(xmean,1) ~= N - error(['intial search point should be a column vector of size ' ... - num2str(N)]); - elseif ~(all(size(insigma) == [1 1]) || all(size(insigma) == [N 1])) - error(['input parameter SIGMA should be (or eval to) a scalar '... - 'or a column vector of size ' num2str(N)] ); - elseif size(stopTolX, 2) > 1 || ~ismember(size(stopTolX, 1), [1 N]) - error(['option TolX should be (or eval to) a scalar '... - 'or a column vector of size ' num2str(N)] ); - elseif size(stopTolUpX, 2) > 1 || ~ismember(size(stopTolUpX, 1), [1 N]) - error(['option TolUpX should be (or eval to) a scalar '... - 'or a column vector of size ' num2str(N)] ); - elseif size(maxdx, 2) > 1 || ~ismember(size(maxdx, 1), [1 N]) - error(['option DiffMaxChange should be (or eval to) a scalar '... - 'or a column vector of size ' num2str(N)] ); - elseif size(mindx, 2) > 1 || ~ismember(size(mindx, 1), [1 N]) - error(['option DiffMinChange should be (or eval to) a scalar '... - 'or a column vector of size ' num2str(N)] ); - elseif size(lbounds, 2) > 1 || ~ismember(size(lbounds, 1), [1 N]) - error(['option lbounds should be (or eval to) a scalar '... - 'or a column vector of size ' num2str(N)] ); - elseif size(ubounds, 2) > 1 || ~ismember(size(ubounds, 1), [1 N]) - error(['option ubounds should be (or eval to) a scalar '... - 'or a column vector of size ' num2str(N)] ); - end - - % Initialize dynamic internal state parameters - if any(insigma <= 0) - error(['Initial search volume (SIGMA) must be greater than zero']); - end - if max(insigma)/min(insigma) > 1e6 - error(['Initial search volume (SIGMA) badly conditioned']); - end - sigma = max(insigma); % overall standard deviation - pc = zeros(N,1); ps = zeros(N,1); % evolution paths for C and sigma - - if length(insigma) == 1 - insigma = insigma * ones(N,1) ; - end - diagD = insigma/max(insigma); % diagonal matrix D defines the scaling - diagC = diagD.^2; - if flgDiagonalOnly ~= 1 % use at some point full covariance matrix - B = eye(N,N); % B defines the coordinate system - BD = B.*repmat(diagD',N,1); % B*D for speed up only - C = diag(diagC); % covariance matrix == BD*(BD)' - end - if flgDiagonalOnly - B = 1; - end - - fitness.hist=NaN*ones(1,10+ceil(3*10*N/lambda)); % history of fitness values - fitness.histsel=NaN*ones(1,10+ceil(3*10*N/lambda)); % history of fitness values - fitness.histbest=[]; % history of fitness values - fitness.histmedian=[]; % history of fitness values - - % Initialize boundary handling - bnd.isactive = any(lbounds > -Inf) || any(ubounds < Inf); - if bnd.isactive - if any(lbounds>ubounds) - error('lower bound found to be greater than upper bound'); - end - [xmean ti] = xintobounds(xmean, lbounds, ubounds); % just in case - if any(ti) - warning('Initial point was out of bounds, corrected'); - end - bnd.weights = zeros(N,1); % weights for bound penalty - % scaling is better in axis-parallel case, worse in rotated - bnd.flgscale = 0; % scaling will be omitted if zero - if bnd.flgscale ~= 0 - bnd.scale = diagC/mean(diagC); - else - bnd.scale = ones(N,1); + irun = irun + 1; + + % ------------------------ Initialization ------------------------------- + + % Handle resuming of old run + flgresume = myevalbool(opts.Resume); + xmean = myeval(xstart); + if all(size(xmean) > 1) + xmean = mean(xmean, 2); % in case if xstart is a population + elseif size(xmean, 2) > 1 + xmean = xmean'; + end + if ~flgresume % not resuming a former run + % Assign settings from input parameters and options for myeval... + N = size(xmean, 1); numberofvariables = N; + lambda0 = floor(myeval(opts.PopSize) * myeval(opts.IncPopSize)^(irun-1)); + % lambda0 = floor(myeval(opts.PopSize) * 3^floor((irun-1)/2)); + popsize = lambda0; + lambda = lambda0; + insigma = myeval(insigma); + if all(size(insigma) == [N 2]) + insigma = 0.5 * (insigma(:,2) - insigma(:,1)); + end + else % flgresume is true, do resume former run + tmp = whos('-file', opts.SaveFilename); + for i = 1:length(tmp) + if strcmp(tmp(i).name, 'localopts'); + error('Saved variables include variable "localopts", please remove'); + end + end + local.opts = opts; % keep stopping and display options + local.varargin = varargin; + load(opts.SaveFilename); + varargin = local.varargin; + flgresume = 1; + + % Overwrite old stopping and display options + opts.StopFitness = local.opts.StopFitness; + %%opts.MaxFunEvals = local.opts.MaxFunEvals; + %%opts.MaxIter = local.opts.MaxIter; + opts.StopFunEvals = local.opts.StopFunEvals; + opts.StopIter = local.opts.StopIter; + opts.TolX = local.opts.TolX; + opts.TolUpX = local.opts.TolUpX; + opts.TolFun = local.opts.TolFun; + opts.TolHistFun = local.opts.TolHistFun; + opts.StopOnStagnation = local.opts.StopOnStagnation; + opts.StopOnWarnings = local.opts.StopOnWarnings; + opts.ReadSignals = local.opts.ReadSignals; + opts.DispFinal = local.opts.DispFinal; + opts.LogPlot = local.opts.LogPlot; + opts.DispModulo = local.opts.DispModulo; + opts.SaveVariables = local.opts.SaveVariables; + opts.LogModulo = local.opts.LogModulo; + opts.LogTime = local.opts.LogTime; + clear local; % otherwise local would be overwritten during load end - idx = (lbounds > -Inf) | (ubounds < Inf); - if length(idx) == 1 - idx = idx * ones(N,1); - end - bnd.isbounded = zeros(N,1); - bnd.isbounded(find(idx)) = 1; - maxdx = min(maxdx, (ubounds - lbounds)/2); - if any(sigma*sqrt(diagC) > maxdx) - fac = min(maxdx ./ sqrt(diagC))/sigma; - sigma = min(maxdx ./ sqrt(diagC)); - warning(['Initial SIGMA multiplied by the factor ' num2str(fac) ... - ', because it was larger than half' ... - ' of one of the boundary intervals']); + %-------------------------------------------------------------- + % Evaluate options + stopFitness = myeval(opts.StopFitness); + stopMaxFunEvals = myeval(opts.MaxFunEvals); + stopMaxIter = myeval(opts.MaxIter); + stopFunEvals = myeval(opts.StopFunEvals); + stopIter = myeval(opts.StopIter); + stopTolX = myeval(opts.TolX); + stopTolUpX = myeval(opts.TolUpX); + stopTolFun = myeval(opts.TolFun); + stopTolHistFun = myeval(opts.TolHistFun); + stopOnStagnation = myevalbool(opts.StopOnStagnation); + stopOnWarnings = myevalbool(opts.StopOnWarnings); + flgreadsignals = myevalbool(opts.ReadSignals); + flgWarnOnEqualFunctionValues = myevalbool(opts.WarnOnEqualFunctionValues); + flgEvalParallel = myevalbool(opts.EvalParallel); + stopOnEqualFunctionValues = myeval(opts.StopOnEqualFunctionValues); + arrEqualFunvals = zeros(1,10+N); + flgDiagonalOnly = myeval(opts.DiagonalOnly); + flgActiveCMA = myeval(opts.CMA.active); + noiseHandling = myevalbool(opts.Noise.on); + noiseMinMaxEvals = myeval(opts.Noise.minmaxevals); + noiseAlphaEvals = myeval(opts.Noise.alphaevals); + noiseCallback = myeval(opts.Noise.callback); + flgdisplay = myevalbool(opts.DispFinal); + flgplotting = myevalbool(opts.LogPlot); + verbosemodulo = myeval(opts.DispModulo); + flgscience = myevalbool(opts.Science); + flgsaving = []; + strsaving = []; + if strfind(opts.SaveVariables, '-v6') + i = strfind(opts.SaveVariables, '%'); + if isempty(i) || i == 0 || strfind(opts.SaveVariables, '-v6') < i + strsaving = '-v6'; + flgsaving = 1; + flgsavingfinal = 1; + end end - idx = (lbounds > -Inf) & (ubounds < Inf); - dd = diagC; - if any(5*sigma*sqrt(dd(idx)) < ubounds(idx) - lbounds(idx)) - warning(['Initial SIGMA is, in at least one coordinate, ' ... - 'much smaller than the '... - 'given boundary intervals. For reasonable ' ... - 'global search performance SIGMA should be ' ... - 'between 0.2 and 0.5 of the bounded interval in ' ... - 'each coordinate. If all coordinates have ' ... - 'lower and upper bounds SIGMA can be empty']); + if strncmp('final', opts.SaveVariables, 5) + flgsaving = 0; + flgsavingfinal = 1; end - bnd.dfithist = 1; % delta fit for setting weights - bnd.aridxpoints = []; % remember complete outside points - bnd.arfitness = []; % and their fitness - bnd.validfitval = 0; - bnd.iniphase = 1; - end - - % ooo initial feval, for output only - if irun == 1 - out.solutions.bestever.x = xmean; - out.solutions.bestever.f = Inf; % for simpler comparison below - out.solutions.bestever.evals = counteval; - bestever = out.solutions.bestever; - end - if myevalbool(opts.EvalInitialX) - fitness.hist(1)=feval(fitfun, xmean, varargin{:}); - fitness.histsel(1)=fitness.hist(1); - counteval = counteval + 1; - if fitness.hist(1) < out.solutions.bestever.f - out.solutions.bestever.x = xmean; - out.solutions.bestever.f = fitness.hist(1); - out.solutions.bestever.evals = counteval; - bestever = out.solutions.bestever; + if isempty(flgsaving) + flgsaving = myevalbool(opts.SaveVariables); + flgsavingfinal = flgsaving; end - else - fitness.hist(1)=NaN; - fitness.histsel(1)=NaN; - end - - % initialize random number generator -% $$$ if ischar(opts.Seed) -% $$$ randn('state', eval(opts.Seed)); % random number generator state -% $$$ else -% $$$ randn('state', opts.Seed); -% $$$ end - %qqq -% load(opts.SaveFilename, 'startseed'); -% randn('state', startseed); -% disp(['SEED RELOADED FROM ' opts.SaveFilename]); -% startseed = randn('state'); % for retrieving in saved variables + savemodulo = myeval(opts.LogModulo); + savetime = myeval(opts.LogTime); - % Initialize further constants - chiN=N^0.5*(1-1/(4*N)+1/(21*N^2)); % expectation of - % ||N(0,I)|| == norm(randn(N,1)) - - countiter = 0; - % Initialize records and output - if irun == 1 - time.t0 = clock; - - % TODO: keep also median solution? - out.evals = counteval; % should be first entry - out.stopflag = {}; - - outiter = 0; - - % Write headers to output data files - filenameprefix = opts.LogFilenamePrefix; - if savemodulo && savetime - filenames = {}; - filenames(end+1) = {'axlen'}; - filenames(end+1) = {'fit'}; - filenames(end+1) = {'stddev'}; - filenames(end+1) = {'xmean'}; - filenames(end+1) = {'xrecentbest'}; - str = [' (startseed=' num2str(startseed(2)) ... - ', ' num2str(clock, '%d/%02d/%d %d:%d:%2.2f') ')']; - for namecell = filenames(:)' - name = namecell{:}; - - [fid, err] = fopen(['./' filenameprefix name '.dat'], 'w'); - if fid < 1 % err ~= 0 - warning(['could not open ' filenameprefix name '.dat']); - filenames(find(strcmp(filenames,name))) = []; - else -% fprintf(fid, '%s\n', ... -% ['<CMAES-OUTPUT version="' cmaVersion '">']); -% fprintf(fid, [' <NAME>' name '</NAME>\n']); -% fprintf(fid, [' <DATE>' date() '</DATE>\n']); -% fprintf(fid, ' <PARAMETERS>\n'); -% fprintf(fid, [' dimension=' num2str(N) '\n']); -% fprintf(fid, ' </PARAMETERS>\n'); - % different cases for DATA columns annotations here -% fprintf(fid, ' <DATA'); - if strcmp(name, 'axlen') - fprintf(fid, ['%% columns="iteration, evaluation, sigma, ' ... - 'max axis length, min axis length, ' ... - 'all principal axes lengths (sorted square roots ' ... - 'of eigenvalues of C)"' str]); - elseif strcmp(name, 'fit') - fprintf(fid, ['%% columns="iteration, evaluation, sigma, axis ratio, bestever,' ... - ' best, median, worst fitness function value,' ... - ' further objective values of best"' str]); - elseif strcmp(name, 'stddev') - fprintf(fid, ['%% columns=["iteration, evaluation, sigma, void, void, ' ... - 'stds==sigma*sqrt(diag(C))"' str]); - elseif strcmp(name, 'xmean') - fprintf(fid, ['%% columns="iteration, evaluation, void, ' ... - 'void, void, xmean"' str]); - elseif strcmp(name, 'xrecentbest') - fprintf(fid, ['%% columns="iteration, evaluation, fitness, ' ... - 'void, void, xrecentbest"' str]); - end - fprintf(fid, '\n'); % DATA - if strcmp(name, 'xmean') - fprintf(fid, '%ld %ld 0 0 0 ', 0, counteval); - % fprintf(fid, '%ld %ld 0 0 %e ', countiter, counteval, fmean); -%qqq fprintf(fid, msprintf('%e ', genophenotransform(out.genopheno, xmean)) + '\n'); - fprintf(fid, '%e ', xmean); - fprintf(fid, '\n'); - end - fclose(fid); - clear fid; % preventing - end - end % for files - end % savemodulo - end % irun == 1 - -end % else flgresume - -% -------------------- Generation Loop -------------------------------- -stopflag = {}; -while isempty(stopflag) - % set internal parameters - if countiter == 0 || lambda ~= lambda_last - if countiter > 0 && floor(log10(lambda)) ~= floor(log10(lambda_last)) ... - && flgdisplay - disp([' lambda = ' num2str(lambda)]); - lambda_hist(:,end+1) = [countiter+1; lambda]; - else - lambda_hist = [countiter+1; lambda]; - end - lambda_last = lambda; - % Strategy internal parameter setting: Selection - mu = myeval(opts.ParentNumber); % number of parents/points for recombination - if strncmp(lower(opts.RecombinationWeights), 'equal', 3) - weights = ones(mu,1); % (mu_I,lambda)-CMA-ES - elseif strncmp(lower(opts.RecombinationWeights), 'linear', 3) - weights = mu+0.5-(1:mu)'; - elseif strncmp(lower(opts.RecombinationWeights), 'superlinear', 3) - weights = log(mu+0.5)-log(1:mu)'; % muXone array for weighted recombination - % qqq mu can be non-integer and - % should become ceil(mu-0.5) (minor correction) - else - error(['Recombination weights to be "' opts.RecombinationWeights ... - '" is not implemented']); - end - mueff=sum(weights)^2/sum(weights.^2); % variance-effective size of mu - weights = weights/sum(weights); % normalize recombination weights array - if mueff == lambda - error(['Combination of values for PopSize, ParentNumber and ' ... - ' and RecombinationWeights is not reasonable']); - end - - % Strategy internal parameter setting: Adaptation - cc = myeval(opts.CMA.ccum); % time constant for cumulation for covariance matrix - cs = myeval(opts.CMA.cs); - - % old way TODO: remove this at some point - % mucov = mueff; % size of mu used for calculating learning rate ccov - % ccov = (1/mucov) * 2/(N+1.41)^2 ... % learning rate for covariance matrix - % + (1-1/mucov) * min(1,(2*mucov-1)/((N+2)^2+mucov)); - - % new way - if myevalbool(opts.CMA.on) - ccov1 = myeval(opts.CMA.ccov1); - ccovmu = min(1-ccov1, myeval(opts.CMA.ccovmu)); - else - ccov1 = 0; - ccovmu = 0; - end - - % flgDiagonalOnly = -lambda*4*1/ccov; % for ccov==1 it is not needed - % 0 : C will never be diagonal anymore - % 1 : C will always be diagonal - % >1: C is diagonal for first iterations, set to 0 afterwards - if flgDiagonalOnly < 1 - flgDiagonalOnly = 0; - end - if flgDiagonalOnly - ccov1_sep = min(1, ccov1 * (N+1.5) / 3); - ccovmu_sep = min(1-ccov1_sep, ccovmu * (N+1.5) / 3); - elseif N > 98 && flgdisplay && countiter == 0 - disp('consider option DiagonalOnly for high-dimensional problems'); + i = strfind(opts.LogFilenamePrefix, ' '); % remove everything after white space + if ~isempty(i) + opts.LogFilenamePrefix = opts.LogFilenamePrefix(1:i(1)-1); end - % ||ps|| is close to sqrt(mueff/N) for mueff large on linear fitness - %damps = ... % damping for step size control, usually close to one - % (1 + 2*max(0,sqrt((mueff-1)/(N+1))-1)) ... % limit sigma increase - % * max(0.3, ... % reduce damps, if max. iteration number is small - % 1 - N/min(stopMaxIter,stopMaxFunEvals/lambda)) + cs; - damps = myeval(opts.CMA.damps); - if noiseHandling - noiseReevals = min(myeval(opts.Noise.reevals), lambda); - noiseAlpha = myeval(opts.Noise.alphasigma); - noiseEpsilon = myeval(opts.Noise.epsilon); - noiseTheta = myeval(opts.Noise.theta); - noisecum = myeval(opts.Noise.cum); - noiseCutOff = myeval(opts.Noise.cutoff); % arguably of minor relevance - else - noiseReevals = 0; % more convenient in later coding - end + % TODO here silent option? set disp, save and log options to 0 - %qqq hacking of a different parameter setting, e.g. for ccov or damps, - % can be done here, but is not necessary anymore, see opts.CMA. - % ccov1 = 0.0*ccov1; disp(['CAVE: ccov1=' num2str(ccov1)]); - % ccovmu = 0.0*ccovmu; disp(['CAVE: ccovmu=' num2str(ccovmu)]); - % damps = inf*damps; disp(['CAVE: damps=' num2str(damps)]); - % cc = 1; disp(['CAVE: cc=' num2str(cc)]); - - end - - % Display initial message - if countiter == 0 && flgdisplay - if mu == 1 - strw = '100'; - elseif mu < 8 - strw = [sprintf('%.0f', 100*weights(1)) ... - sprintf(' %.0f', 100*weights(2:end)')]; - else - strw = [sprintf('%.2g ', 100*weights(1:2)') ... - sprintf('%.2g', 100*weights(3)') '...' ... - sprintf(' %.2g', 100*weights(end-1:end)') ']%, ']; - end - if irun > 1 - strrun = [', run ' num2str(irun)]; - else - strrun = ''; - end - disp([' n=' num2str(N) ': (' num2str(mu) ',' ... - num2str(lambda) ')-CMA-ES(w=[' ... - strw ']%, ' ... - 'mu_eff=' num2str(mueff,'%.1f') ... - ') on function ' ... - (fitfun) strrun]); - if flgDiagonalOnly == 1 - disp(' C is diagonal'); - elseif flgDiagonalOnly - disp([' C is diagonal for ' num2str(floor(flgDiagonalOnly)) ' iterations']); + %-------------------------------------------------------------- + + if (isfinite(stopFunEvals) || isfinite(stopIter)) && ~flgsaving + warning('To resume later the saving option needs to be set'); end - end - - flush; - - countiter = countiter + 1; - - % Generate and evaluate lambda offspring - - fitness.raw = repmat(NaN, 1, lambda + noiseReevals); - - % parallel evaluation - if flgEvalParallel - arz = randn(N,lambda); - - if ~flgDiagonalOnly - arx = repmat(xmean, 1, lambda) + sigma * (BD * arz); % Eq. (1) - else - arx = repmat(xmean, 1, lambda) + repmat(sigma * diagD, 1, lambda) .* arz; - end - - if noiseHandling - if noiseEpsilon == 0 - arx = [arx arx(:,1:noiseReevals)]; - elseif flgDiagonalOnly - arx = [arx arx(:,1:noiseReevals) + ... - repmat(noiseEpsilon * sigma * diagD, 1, noiseReevals) ... - .* randn(N,noiseReevals)]; - else - arx = [arx arx(:,1:noiseReevals) + ... - noiseEpsilon * sigma * ... - (BD * randn(N,noiseReevals))]; + + + % Do more checking and initialization + if flgresume % resume is on + time.t0 = clock; + if flgdisplay + disp([' resumed from ' opts.SaveFilename ]); end - end - - % You may handle constraints here. You may either resample - % arz(:,k) and/or multiply it with a factor between -1 and 1 - % (the latter will decrease the overall step size) and - % recalculate arx accordingly. Do not change arx or arz in any - % other way. - - if ~bnd.isactive - arxvalid = arx; - else - arxvalid = xintobounds(arx, lbounds, ubounds); - end - % You may handle constraints here. You may copy and alter - % (columns of) arxvalid(:,k) only for the evaluation of the - % fitness function. arx and arxvalid should not be changed. - fitness.raw = feval(fitfun, arxvalid, varargin{:}); - countevalNaN = countevalNaN + sum(isnan(fitness.raw)); - counteval = counteval + sum(~isnan(fitness.raw)); - end - - % non-parallel evaluation and remaining NaN-values - % set also the reevaluated solution to NaN - fitness.raw(lambda + find(isnan(fitness.raw(1:noiseReevals)))) = NaN; - for k=find(isnan(fitness.raw)), - % fitness.raw(k) = NaN; - tries = 0; - % Resample, until fitness is not NaN - while isnan(fitness.raw(k)) - if k <= lambda % regular samples (not the re-evaluation-samples) - arz(:,k) = randn(N,1); % (re)sample - - if flgDiagonalOnly - arx(:,k) = xmean + sigma * diagD .* arz(:,k); % Eq. (1) - else - arx(:,k) = xmean + sigma * (BD * arz(:,k)); % Eq. (1) + if counteval >= stopMaxFunEvals + error(['MaxFunEvals exceeded, use StopFunEvals as stopping ' ... + 'criterion before resume']); end - else % re-evaluation solution with index > lambda - if flgDiagonalOnly - arx(:,k) = arx(:,k-lambda) + (noiseEpsilon * sigma) * diagD .* randn(N,1); - else - arx(:,k) = arx(:,k-lambda) + (noiseEpsilon * sigma) * (BD * randn(N,1)); + if countiter >= stopMaxIter + error(['MaxIter exceeded, use StopIter as stopping criterion ' ... + 'before resume']); + end + + else % flgresume + % xmean = mean(myeval(xstart), 2); % evaluate xstart again, because of irun + maxdx = myeval(opts.DiffMaxChange); % maximal sensible variable change + mindx = myeval(opts.DiffMinChange); % minimal sensible variable change + % can both also be defined as Nx1 vectors + lbounds = myeval(opts.LBounds); + ubounds = myeval(opts.UBounds); + if length(lbounds) == 1 + lbounds = repmat(lbounds, N, 1); + end + if length(ubounds) == 1 + ubounds = repmat(ubounds, N, 1); + end + if isempty(insigma) % last chance to set insigma + if all(lbounds > -Inf) && all(ubounds < Inf) + if any(lbounds>=ubounds) + error('upper bound must be greater than lower bound'); + end + insigma = 0.3*(ubounds-lbounds); + stopTolX = myeval(opts.TolX); % reevaluate these + stopTolUpX = myeval(opts.TolUpX); + else + error(['Initial step sizes (SIGMA) not determined']); + end end - end - - % You may handle constraints here. You may either resample - % arz(:,k) and/or multiply it with a factor between -1 and 1 - % (the latter will decrease the overall step size) and - % recalculate arx accordingly. Do not change arx or arz in any - % other way. - - if ~bnd.isactive - arxvalid(:,k) = arx(:,k); - else - arxvalid(:,k) = xintobounds(arx(:,k), lbounds, ubounds); - end - % You may handle constraints here. You may copy and alter - % (columns of) arxvalid(:,k) only for the evaluation of the - % fitness function. arx should not be changed. - fitness.raw(k) = feval(fitfun, arxvalid(:,k), varargin{:}); - tries = tries + 1; - if isnan(fitness.raw(k)) - countevalNaN = countevalNaN + 1; - end - if mod(tries, 100) == 0 - warning([num2str(tries) ... - ' NaN objective function values at evaluation ' ... - num2str(counteval)]); - end - end - counteval = counteval + 1; % retries due to NaN are not counted - end - - fitness.sel = fitness.raw; - - % ----- handle boundaries ----- - if 1 < 3 && bnd.isactive - % Get delta fitness values - val = myprctile(fitness.raw, [25 75]); - % more precise would be exp(mean(log(diagC))) - val = (val(2) - val(1)) / N / mean(diagC) / sigma^2; - %val = (myprctile(fitness.raw, 75) - myprctile(fitness.raw, 25)) ... - % / N / mean(diagC) / sigma^2; - % Catch non-sensible values - if ~isfinite(val) - warning('Non-finite fitness range'); - val = max(bnd.dfithist); - elseif val == 0 % happens if all points are out of bounds - val = min(bnd.dfithist(bnd.dfithist>0)); % seems not to make sense, given all solutions are out of bounds - elseif bnd.validfitval == 0 % flag that first sensible val was found - bnd.dfithist = []; - bnd.validfitval = 1; - end - - % Store delta fitness values - if length(bnd.dfithist) < 20+(3*N)/lambda - bnd.dfithist = [bnd.dfithist val]; - else - bnd.dfithist = [bnd.dfithist(2:end) val]; - end - [tx ti] = xintobounds(xmean, lbounds, ubounds); - - % Set initial weights - if bnd.iniphase - if any(ti) - bnd.weights(find(bnd.isbounded)) = 2.0002 * median(bnd.dfithist); - if bnd.flgscale == 0 % scale only initial weights then - dd = diagC; - idx = find(bnd.isbounded); - dd = dd(idx) / mean(dd); % remove mean scaling - bnd.weights(idx) = bnd.weights(idx) ./ dd; - end - if bnd.validfitval && countiter > 2 - bnd.iniphase = 0; - end - end - end + % Check all vector sizes + if size(xmean, 2) > 1 || size(xmean,1) ~= N + error(['intial search point should be a column vector of size ' ... + num2str(N)]); + elseif ~(all(size(insigma) == [1 1]) || all(size(insigma) == [N 1])) + error(['input parameter SIGMA should be (or eval to) a scalar '... + 'or a column vector of size ' num2str(N)] ); + elseif size(stopTolX, 2) > 1 || ~ismember(size(stopTolX, 1), [1 N]) + error(['option TolX should be (or eval to) a scalar '... + 'or a column vector of size ' num2str(N)] ); + elseif size(stopTolUpX, 2) > 1 || ~ismember(size(stopTolUpX, 1), [1 N]) + error(['option TolUpX should be (or eval to) a scalar '... + 'or a column vector of size ' num2str(N)] ); + elseif size(maxdx, 2) > 1 || ~ismember(size(maxdx, 1), [1 N]) + error(['option DiffMaxChange should be (or eval to) a scalar '... + 'or a column vector of size ' num2str(N)] ); + elseif size(mindx, 2) > 1 || ~ismember(size(mindx, 1), [1 N]) + error(['option DiffMinChange should be (or eval to) a scalar '... + 'or a column vector of size ' num2str(N)] ); + elseif size(lbounds, 2) > 1 || ~ismember(size(lbounds, 1), [1 N]) + error(['option lbounds should be (or eval to) a scalar '... + 'or a column vector of size ' num2str(N)] ); + elseif size(ubounds, 2) > 1 || ~ismember(size(ubounds, 1), [1 N]) + error(['option ubounds should be (or eval to) a scalar '... + 'or a column vector of size ' num2str(N)] ); + end + + % Initialize dynamic internal state parameters + if any(insigma <= 0) + error(['Initial search volume (SIGMA) must be greater than zero']); + end + if max(insigma)/min(insigma) > 1e6 + error(['Initial search volume (SIGMA) badly conditioned']); + end + sigma = max(insigma); % overall standard deviation + pc = zeros(N,1); ps = zeros(N,1); % evolution paths for C and sigma - % Increase weights - if 1 < 3 && any(ti) % any coordinate of xmean out of bounds - % judge distance of xmean to boundary - tx = xmean - tx; - idx = (ti ~= 0 & abs(tx) > 3*max(1,sqrt(N)/mueff) ... - * sigma*sqrt(diagC)) ; - % only increase if xmean is moving away - idx = idx & (sign(tx) == sign(xmean - xold)); - if ~isempty(idx) % increase - % the factor became 1.2 instead of 1.1, because - % changed from max to min in version 3.52 - bnd.weights(idx) = 1.2^(min(1, mueff/10/N)) * bnd.weights(idx); - end - end + if length(insigma) == 1 + insigma = insigma * ones(N,1) ; + end + diagD = insigma/max(insigma); % diagonal matrix D defines the scaling + diagC = diagD.^2; + if flgDiagonalOnly ~= 1 % use at some point full covariance matrix + B = eye(N,N); % B defines the coordinate system + BD = B.*repmat(diagD',N,1); % B*D for speed up only + C = diag(diagC); % covariance matrix == BD*(BD)' + end + if flgDiagonalOnly + B = 1; + end - % Calculate scaling biased to unity, product is one - if bnd.flgscale ~= 0 - bnd.scale = exp(0.9*(log(diagC)-mean(log(diagC)))); - end + fitness.hist=NaN*ones(1,10+ceil(3*10*N/lambda)); % history of fitness values + fitness.histsel=NaN*ones(1,10+ceil(3*10*N/lambda)); % history of fitness values + fitness.histbest=[]; % history of fitness values + fitness.histmedian=[]; % history of fitness values + + % Initialize boundary handling + bnd.isactive = any(lbounds > -Inf) || any(ubounds < Inf); + if bnd.isactive + if any(lbounds>ubounds) + error('lower bound found to be greater than upper bound'); + end + [xmean ti] = xintobounds(xmean, lbounds, ubounds); % just in case + if any(ti) + warning('Initial point was out of bounds, corrected'); + end + bnd.weights = zeros(N,1); % weights for bound penalty + % scaling is better in axis-parallel case, worse in rotated + bnd.flgscale = 0; % scaling will be omitted if zero + if bnd.flgscale ~= 0 + bnd.scale = diagC/mean(diagC); + else + bnd.scale = ones(N,1); + end + + idx = (lbounds > -Inf) | (ubounds < Inf); + if length(idx) == 1 + idx = idx * ones(N,1); + end + bnd.isbounded = zeros(N,1); + bnd.isbounded(find(idx)) = 1; + maxdx = min(maxdx, (ubounds - lbounds)/2); + if any(sigma*sqrt(diagC) > maxdx) + fac = min(maxdx ./ sqrt(diagC))/sigma; + sigma = min(maxdx ./ sqrt(diagC)); + warning(['Initial SIGMA multiplied by the factor ' num2str(fac) ... + ', because it was larger than half' ... + ' of one of the boundary intervals']); + end + idx = (lbounds > -Inf) & (ubounds < Inf); + dd = diagC; + if any(5*sigma*sqrt(dd(idx)) < ubounds(idx) - lbounds(idx)) + warning(['Initial SIGMA is, in at least one coordinate, ' ... + 'much smaller than the '... + 'given boundary intervals. For reasonable ' ... + 'global search performance SIGMA should be ' ... + 'between 0.2 and 0.5 of the bounded interval in ' ... + 'each coordinate. If all coordinates have ' ... + 'lower and upper bounds SIGMA can be empty']); + end + bnd.dfithist = 1; % delta fit for setting weights + bnd.aridxpoints = []; % remember complete outside points + bnd.arfitness = []; % and their fitness + bnd.validfitval = 0; + bnd.iniphase = 1; + end - % Assigned penalized fitness - bnd.arpenalty = (bnd.weights ./ bnd.scale)' * (arxvalid - arx).^2; - - fitness.sel = fitness.raw + bnd.arpenalty; - - end % handle boundaries - % ----- end handle boundaries ----- - - % compute noise measurement and reduce fitness arrays to size lambda - if noiseHandling - [noiseS] = local_noisemeasurement(fitness.sel(1:lambda), ... - fitness.sel(lambda+(1:noiseReevals)), ... - noiseReevals, noiseTheta, noiseCutOff); - if countiter == 1 % TODO: improve this very rude way of initialization - noiseSS = 0; - noiseN = 0; % counter for mean - end - noiseSS = noiseSS + noisecum * (noiseS - noiseSS); - - % noise-handling could be done here, but the original sigma is still needed - % disp([noiseS noiseSS noisecum]) - - fitness.rawar12 = fitness.raw; % just documentary - fitness.selar12 = fitness.sel; % just documentary - % qqq refine fitness based on both values - if 11 < 3 % TODO: in case of outliers this mean is counterproductive - % median out of three would be ok - fitness.raw(1:noiseReevals) = ... % not so raw anymore - (fitness.raw(1:noiseReevals) + fitness.raw(lambda+(1:noiseReevals))) / 2; - fitness.sel(1:noiseReevals) = ... - (fitness.sel(1:noiseReevals) + fitness.sel(lambda+(1:noiseReevals))) / 2; - end - fitness.raw = fitness.raw(1:lambda); - fitness.sel = fitness.sel(1:lambda); - end - - % Sort by fitness - [fitness.raw, fitness.idx] = sort(fitness.raw); - [fitness.sel, fitness.idxsel] = sort(fitness.sel); % minimization - fitness.hist(2:end) = fitness.hist(1:end-1); % record short history of - fitness.hist(1) = fitness.raw(1); % best fitness values - if length(fitness.histbest) < 120+ceil(30*N/lambda) || ... - (mod(countiter, 5) == 0 && length(fitness.histbest) < 2e4) % 20 percent of 1e5 gen. - fitness.histbest = [fitness.raw(1) fitness.histbest]; % best fitness values - fitness.histmedian = [median(fitness.raw) fitness.histmedian]; % median fitness values - else - fitness.histbest(2:end) = fitness.histbest(1:end-1); - fitness.histmedian(2:end) = fitness.histmedian(1:end-1); - fitness.histbest(1) = fitness.raw(1); % best fitness values - fitness.histmedian(1) = median(fitness.raw); % median fitness values - end - fitness.histsel(2:end) = fitness.histsel(1:end-1); % record short history of - fitness.histsel(1) = fitness.sel(1); % best sel fitness values - - % Calculate new xmean, this is selection and recombination - xold = xmean; % for speed up of Eq. (2) and (3) - xmean = arx(:,fitness.idxsel(1:mu))*weights; - zmean = arz(:,fitness.idxsel(1:mu))*weights;%==D^-1*B'*(xmean-xold)/sigma - if mu == 1 - fmean = fitness.sel(1); - else - fmean = NaN; % [] does not work in the latter assignment - % fmean = feval(fitfun, xintobounds(xmean, lbounds, ubounds), varargin{:}); - % counteval = counteval + 1; - end - - % Cumulation: update evolution paths - ps = (1-cs)*ps + sqrt(cs*(2-cs)*mueff) * (B*zmean); % Eq. (4) - hsig = norm(ps)/sqrt(1-(1-cs)^(2*countiter))/chiN < 1.4 + 2/(N+1); - if flg_future_setting - hsig = sum(ps.^2) / (1-(1-cs)^(2*countiter)) / N < 2 + 4/(N+1); % just simplified - end -% hsig = norm(ps)/sqrt(1-(1-cs)^(2*countiter))/chiN < 1.4 + 2/(N+1); -% hsig = norm(ps)/sqrt(1-(1-cs)^(2*countiter))/chiN < 1.5 + 1/(N-0.5); -% hsig = norm(ps) < 1.5 * sqrt(N); -% hsig = 1; - - pc = (1-cc)*pc ... - + hsig*(sqrt(cc*(2-cc)*mueff)/sigma) * (xmean-xold); % Eq. (2) - if hsig == 0 - % disp([num2str(countiter) ' ' num2str(counteval) ' pc update stalled']); - end - - % Adapt covariance matrix - neg.ccov = 0; % TODO: move parameter setting upwards at some point - if ccov1 + ccovmu > 0 % Eq. (3) - if flgDiagonalOnly % internal linear(?) complexity - diagC = (1-ccov1_sep-ccovmu_sep+(1-hsig)*ccov1_sep*cc*(2-cc)) * diagC ... % regard old matrix - + ccov1_sep * pc.^2 ... % plus rank one update - + ccovmu_sep ... % plus rank mu update - * (diagC .* (arz(:,fitness.idxsel(1:mu)).^2 * weights)); -% * (repmat(diagC,1,mu) .* arz(:,fitness.idxsel(1:mu)).^2 * weights); - diagD = sqrt(diagC); % replaces eig(C) - else - arpos = (arx(:,fitness.idxsel(1:mu))-repmat(xold,1,mu)) / sigma; - % "active" CMA update: negative update, in case controlling pos. definiteness - if flgActiveCMA > 0 - % set parameters - neg.mu = mu; - neg.mueff = mueff; - if flgActiveCMA > 10 % flat weights with mu=lambda/2 - neg.mu = floor(lambda/2); - neg.mueff = neg.mu; + % ooo initial feval, for output only + if irun == 1 + out.solutions.bestever.x = xmean; + out.solutions.bestever.f = Inf; % for simpler comparison below + out.solutions.bestever.evals = counteval; + bestever = out.solutions.bestever; end - % neg.mu = ceil(min([N, lambda/4, mueff])); neg.mueff = mu; % i.e. neg.mu <= N - % Parameter study: in 3-D lambda=50,100, 10-D lambda=200,400, 30-D lambda=1000,2000 a - % three times larger neg.ccov does not work. - % increasing all ccov rates three times does work (probably because of the factor (1-ccovmu)) - % in 30-D to looks fine - - neg.ccov = (1 - ccovmu) * 0.25 * neg.mueff / ((N+2)^1.5 + 2*neg.mueff); - neg.minresidualvariance = 0.66; % keep at least 0.66 in all directions, small popsize are most critical - neg.alphaold = 0.5; % where to make up for the variance loss, 0.5 means no idea what to do - % 1 is slightly more robust and gives a better "guaranty" for pos. def., - % but does it make sense from the learning perspective for large ccovmu? - - neg.ccovfinal = neg.ccov; - - % prepare vectors, compute negative updating matrix Cneg and checking matrix Ccheck - arzneg = arz(:,fitness.idxsel(lambda:-1:lambda - neg.mu + 1)); - % i-th longest becomes i-th shortest - % TODO: this is not in compliance with the paper Hansen&Ros2010, - % where simply arnorms = arnorms(end:-1:1) ? - [arnorms idxnorms] = sort(sqrt(sum(arzneg.^2, 1))); - [ignore idxnorms] = sort(idxnorms); % inverse index - arnormfacs = arnorms(end:-1:1) ./ arnorms; - % arnormfacs = arnorms(randperm(neg.mu)) ./ arnorms; - arnorms = arnorms(end:-1:1); % for the record - if flgActiveCMA < 20 - arzneg = arzneg .* repmat(arnormfacs(idxnorms), N, 1); % E x*x' is N - % arzneg = sqrt(N) * arzneg ./ repmat(sqrt(sum(arzneg.^2, 1)), N, 1); % E x*x' is N + if myevalbool(opts.EvalInitialX) + fitness.hist(1)=feval(fitfun, xmean, varargin{:}); + fitness.histsel(1)=fitness.hist(1); + counteval = counteval + 1; + if fitness.hist(1) < out.solutions.bestever.f + out.solutions.bestever.x = xmean; + out.solutions.bestever.f = fitness.hist(1); + out.solutions.bestever.evals = counteval; + bestever = out.solutions.bestever; + end + else + fitness.hist(1)=NaN; + fitness.histsel(1)=NaN; end - if flgActiveCMA < 10 && neg.mu == mu % weighted sum - if mod(flgActiveCMA, 10) == 1 % TODO: prevent this with a less tight but more efficient check (see below) - Ccheck = arzneg * diag(weights) * arzneg'; % in order to check the largest EV - end - artmp = BD * arzneg; - Cneg = artmp * diag(weights) * artmp'; - else % simple sum - if mod(flgActiveCMA, 10) == 1 - Ccheck = (1/neg.mu) * arzneg*arzneg'; % in order to check largest EV - end - artmp = BD * arzneg; - Cneg = (1/neg.mu) * artmp*artmp'; + + % initialize random number generator +% $$$ if ischar(opts.Seed) +% $$$ randn('state', eval(opts.Seed)); % random number generator state +% $$$ else +% $$$ randn('state', opts.Seed); +% $$$ end +%qqq +% load(opts.SaveFilename, 'startseed'); +% randn('state', startseed); +% disp(['SEED RELOADED FROM ' opts.SaveFilename]); +% startseed = randn('state'); % for retrieving in saved variables + % Initialize further constants + chiN=N^0.5*(1-1/(4*N)+1/(21*N^2)); % expectation of + % ||N(0,I)|| == norm(randn(N,1)) + + countiter = 0; + % Initialize records and output + if irun == 1 + time.t0 = clock; + + % TODO: keep also median solution? + out.evals = counteval; % should be first entry + out.stopflag = {}; + + outiter = 0; + + % Write headers to output data files + filenameprefix = opts.LogFilenamePrefix; + if savemodulo && savetime + filenames = {}; + filenames(end+1) = {'axlen'}; + filenames(end+1) = {'fit'}; + filenames(end+1) = {'stddev'}; + filenames(end+1) = {'xmean'}; + filenames(end+1) = {'xrecentbest'}; + str = [' (startseed=' num2str(startseed(2)) ... + ', ' num2str(clock, '%d/%02d/%d %d:%d:%2.2f') ')']; + for namecell = filenames(:)' + name = namecell{:}; + + [fid, err] = fopen(['./' filenameprefix name '.dat'], 'w'); + if fid < 1 % err ~= 0 + warning(['could not open ' filenameprefix name '.dat']); + filenames(find(strcmp(filenames,name))) = []; + else + % fprintf(fid, '%s\n', ... + % ['<CMAES-OUTPUT version="' cmaVersion '">']); + % fprintf(fid, [' <NAME>' name '</NAME>\n']); + % fprintf(fid, [' <DATE>' date() '</DATE>\n']); + % fprintf(fid, ' <PARAMETERS>\n'); + % fprintf(fid, [' dimension=' num2str(N) '\n']); + % fprintf(fid, ' </PARAMETERS>\n'); + % different cases for DATA columns annotations here + % fprintf(fid, ' <DATA'); + if strcmp(name, 'axlen') + fprintf(fid, ['%% columns="iteration, evaluation, sigma, ' ... + 'max axis length, min axis length, ' ... + 'all principal axes lengths (sorted square roots ' ... + 'of eigenvalues of C)"' str]); + elseif strcmp(name, 'fit') + fprintf(fid, ['%% columns="iteration, evaluation, sigma, axis ratio, bestever,' ... + ' best, median, worst fitness function value,' ... + ' further objective values of best"' str]); + elseif strcmp(name, 'stddev') + fprintf(fid, ['%% columns=["iteration, evaluation, sigma, void, void, ' ... + 'stds==sigma*sqrt(diag(C))"' str]); + elseif strcmp(name, 'xmean') + fprintf(fid, ['%% columns="iteration, evaluation, void, ' ... + 'void, void, xmean"' str]); + elseif strcmp(name, 'xrecentbest') + fprintf(fid, ['%% columns="iteration, evaluation, fitness, ' ... + 'void, void, xrecentbest"' str]); + end + fprintf(fid, '\n'); % DATA + if strcmp(name, 'xmean') + fprintf(fid, '%ld %ld 0 0 0 ', 0, counteval); + % fprintf(fid, '%ld %ld 0 0 %e ', countiter, counteval, fmean); + %qqq fprintf(fid, msprintf('%e ', genophenotransform(out.genopheno, xmean)) + '\n'); + fprintf(fid, '%e ', xmean); + fprintf(fid, '\n'); + end + fclose(fid); + clear fid; % preventing + end + end % for files + end % savemodulo + end % irun == 1 + + end % else flgresume + + % -------------------- Generation Loop -------------------------------- + stopflag = {}; + while isempty(stopflag) + % set internal parameters + if countiter == 0 || lambda ~= lambda_last + if countiter > 0 && floor(log10(lambda)) ~= floor(log10(lambda_last)) ... + && flgdisplay + disp([' lambda = ' num2str(lambda)]); + lambda_hist(:,end+1) = [countiter+1; lambda]; + else + lambda_hist = [countiter+1; lambda]; + end + lambda_last = lambda; + % Strategy internal parameter setting: Selection + mu = myeval(opts.ParentNumber); % number of parents/points for recombination + if strncmp(lower(opts.RecombinationWeights), 'equal', 3) + weights = ones(mu,1); % (mu_I,lambda)-CMA-ES + elseif strncmp(lower(opts.RecombinationWeights), 'linear', 3) + weights = mu+0.5-(1:mu)'; + elseif strncmp(lower(opts.RecombinationWeights), 'superlinear', 3) + weights = log(mu+0.5)-log(1:mu)'; % muXone array for weighted recombination + % qqq mu can be non-integer and + % should become ceil(mu-0.5) (minor correction) + else + error(['Recombination weights to be "' opts.RecombinationWeights ... + '" is not implemented']); + end + mueff=sum(weights)^2/sum(weights.^2); % variance-effective size of mu + weights = weights/sum(weights); % normalize recombination weights array + if mueff == lambda + error(['Combination of values for PopSize, ParentNumber and ' ... + ' and RecombinationWeights is not reasonable']); + end + + % Strategy internal parameter setting: Adaptation + cc = myeval(opts.CMA.ccum); % time constant for cumulation for covariance matrix + cs = myeval(opts.CMA.cs); + + % old way TODO: remove this at some point + % mucov = mueff; % size of mu used for calculating learning rate ccov + % ccov = (1/mucov) * 2/(N+1.41)^2 ... % learning rate for covariance matrix + % + (1-1/mucov) * min(1,(2*mucov-1)/((N+2)^2+mucov)); + + % new way + if myevalbool(opts.CMA.on) + ccov1 = myeval(opts.CMA.ccov1); + ccovmu = min(1-ccov1, myeval(opts.CMA.ccovmu)); + else + ccov1 = 0; + ccovmu = 0; + end + + % flgDiagonalOnly = -lambda*4*1/ccov; % for ccov==1 it is not needed + % 0 : C will never be diagonal anymore + % 1 : C will always be diagonal + % >1: C is diagonal for first iterations, set to 0 afterwards + if flgDiagonalOnly < 1 + flgDiagonalOnly = 0; + end + if flgDiagonalOnly + ccov1_sep = min(1, ccov1 * (N+1.5) / 3); + ccovmu_sep = min(1-ccov1_sep, ccovmu * (N+1.5) / 3); + elseif N > 98 && flgdisplay && countiter == 0 + disp('consider option DiagonalOnly for high-dimensional problems'); + end + + % ||ps|| is close to sqrt(mueff/N) for mueff large on linear fitness + %damps = ... % damping for step size control, usually close to one + % (1 + 2*max(0,sqrt((mueff-1)/(N+1))-1)) ... % limit sigma increase + % * max(0.3, ... % reduce damps, if max. iteration number is small + % 1 - N/min(stopMaxIter,stopMaxFunEvals/lambda)) + cs; + damps = myeval(opts.CMA.damps); + if noiseHandling + noiseReevals = min(myeval(opts.Noise.reevals), lambda); + noiseAlpha = myeval(opts.Noise.alphasigma); + noiseEpsilon = myeval(opts.Noise.epsilon); + noiseTheta = myeval(opts.Noise.theta); + noisecum = myeval(opts.Noise.cum); + noiseCutOff = myeval(opts.Noise.cutoff); % arguably of minor relevance + else + noiseReevals = 0; % more convenient in later coding + end + + %qqq hacking of a different parameter setting, e.g. for ccov or damps, + % can be done here, but is not necessary anymore, see opts.CMA. + % ccov1 = 0.0*ccov1; disp(['CAVE: ccov1=' num2str(ccov1)]); + % ccovmu = 0.0*ccovmu; disp(['CAVE: ccovmu=' num2str(ccovmu)]); + % damps = inf*damps; disp(['CAVE: damps=' num2str(damps)]); + % cc = 1; disp(['CAVE: cc=' num2str(cc)]); + + end + + % Display initial message + if countiter == 0 && flgdisplay + if mu == 1 + strw = '100'; + elseif mu < 8 + strw = [sprintf('%.0f', 100*weights(1)) ... + sprintf(' %.0f', 100*weights(2:end)')]; + else + strw = [sprintf('%.2g ', 100*weights(1:2)') ... + sprintf('%.2g', 100*weights(3)') '...' ... + sprintf(' %.2g', 100*weights(end-1:end)') ']%, ']; + end + if irun > 1 + strrun = [', run ' num2str(irun)]; + else + strrun = ''; + end + disp([' n=' num2str(N) ': (' num2str(mu) ',' ... + num2str(lambda) ')-CMA-ES(w=[' ... + strw ']%, ' ... + 'mu_eff=' num2str(mueff,'%.1f') ... + ') on function ' ... + (fitfun) strrun]); + if flgDiagonalOnly == 1 + disp(' C is diagonal'); + elseif flgDiagonalOnly + disp([' C is diagonal for ' num2str(floor(flgDiagonalOnly)) ' iterations']); + end end - % check pos.def. and set learning rate neg.ccov accordingly, - % this check makes the original choice of neg.ccov extremly failsafe - % still assuming C == BD*BD', which is only approxim. correct - if mod(flgActiveCMA, 10) == 1 && 1 - neg.ccov * arnorms(idxnorms).^2 * weights < neg.minresidualvariance - % TODO: the simple and cheap way would be to set - % fac = 1 - ccovmu - ccov1 OR 1 - mueff/lambda and - % neg.ccov = fac*(1 - neg.minresidualvariance) / (arnorms(idxnorms).^2 * weights) - % this is the more sophisticated way: - % maxeigenval = eigs(arzneg * arzneg', 1, 'lm', eigsopts); % not faster - maxeigenval = max(eig(Ccheck)); % norm is much slower, because (norm()==max(svd()) - %disp([countiter log10([neg.ccov, maxeigenval, arnorms(idxnorms).^2 * weights, max(arnorms)^2]), ... - % neg.ccov * arnorms(idxnorms).^2 * weights]) - % pause - % remove less than ??34*(1-cmu)%?? of variance in any direction - % 1-ccovmu is the variance left from the old C - neg.ccovfinal = min(neg.ccov, (1-ccovmu)*(1-neg.minresidualvariance)/maxeigenval); - % -ccov1 removed to avoid error message?? - if neg.ccovfinal < neg.ccov - disp(['active CMA at iteration ' num2str(countiter) ... - ': max EV ==', num2str([maxeigenval, neg.ccov, neg.ccovfinal])]); - end + flush; + + countiter = countiter + 1; + + % Generate and evaluate lambda offspring + + fitness.raw = repmat(NaN, 1, lambda + noiseReevals); + + % parallel evaluation + if flgEvalParallel + arz = randn(N,lambda); + + if ~flgDiagonalOnly + arx = repmat(xmean, 1, lambda) + sigma * (BD * arz); % Eq. (1) + else + arx = repmat(xmean, 1, lambda) + repmat(sigma * diagD, 1, lambda) .* arz; + end + + if noiseHandling + if noiseEpsilon == 0 + arx = [arx arx(:,1:noiseReevals)]; + elseif flgDiagonalOnly + arx = [arx arx(:,1:noiseReevals) + ... + repmat(noiseEpsilon * sigma * diagD, 1, noiseReevals) ... + .* randn(N,noiseReevals)]; + else + arx = [arx arx(:,1:noiseReevals) + ... + noiseEpsilon * sigma * ... + (BD * randn(N,noiseReevals))]; + end + end + + % You may handle constraints here. You may either resample + % arz(:,k) and/or multiply it with a factor between -1 and 1 + % (the latter will decrease the overall step size) and + % recalculate arx accordingly. Do not change arx or arz in any + % other way. + + if ~bnd.isactive + arxvalid = arx; + else + arxvalid = xintobounds(arx, lbounds, ubounds); + end + % You may handle constraints here. You may copy and alter + % (columns of) arxvalid(:,k) only for the evaluation of the + % fitness function. arx and arxvalid should not be changed. + fitness.raw = feval(fitfun, arxvalid, varargin{:}); + countevalNaN = countevalNaN + sum(isnan(fitness.raw)); + counteval = counteval + sum(~isnan(fitness.raw)); end - % xmean = xold; % the distribution does not degenerate!? - % update C - C = (1-ccov1-ccovmu+neg.alphaold*neg.ccovfinal+(1-hsig)*ccov1*cc*(2-cc)) * C ... % regard old matrix - + ccov1 * pc*pc' ... % plus rank one update - + (ccovmu + (1-neg.alphaold)*neg.ccovfinal) ... % plus rank mu update - * arpos * (repmat(weights,1,N) .* arpos') ... - - neg.ccovfinal * Cneg; % minus rank mu update - else % no active (negative) update - C = (1-ccov1-ccovmu+(1-hsig)*ccov1*cc*(2-cc)) * C ... % regard old matrix - + ccov1 * pc*pc' ... % plus rank one update - + ccovmu ... % plus rank mu update - * arpos * (repmat(weights,1,N) .* arpos'); - % is now O(mu*N^2 + mu*N), was O(mu*N^2 + mu^2*N) when using diag(weights) - % for mu=30*N it is now 10 times faster, overall 3 times faster - end - diagC = diag(C); - end - end - - % the following is de-preciated and will be removed in future - % better setting for cc makes this hack obsolete - if 11 < 2 && ~flgscience - % remove momentum in ps, if ps is large and fitness is getting worse. - % this should rarely happen. - % this might very well be counterproductive in dynamic environments - if sum(ps.^2)/N > 1.5 + 10*(2/N)^.5 && ... - fitness.histsel(1) > max(fitness.histsel(2:3)) - ps = ps * sqrt(N*(1+max(0,log(sum(ps.^2)/N))) / sum(ps.^2)); - if flgdisplay - disp(['Momentum in ps removed at [niter neval]=' ... - num2str([countiter counteval]) ']']); - end - end - end - - % Adapt sigma - if flg_future_setting % according to a suggestion from Dirk Arnold (2000) - % exp(1) is still not reasonably small enough - sigma = sigma * exp(min(1, (sum(ps.^2)/N - 1)/2 * cs/damps)); % Eq. (5) - else - % exp(1) is still not reasonably small enough - sigma = sigma * exp(min(1, (sqrt(sum(ps.^2))/chiN - 1) * cs/damps)); % Eq. (5) - end - % disp([countiter norm(ps)/chiN]); - - if 11 < 3 % testing with optimal step-size - if countiter == 1 - disp('*********** sigma set to const * ||x|| ******************'); - end - sigma = 0.04 * mueff * sqrt(sum(xmean.^2)) / N; % 20D,lam=1000:25e3 - sigma = 0.3 * mueff * sqrt(sum(xmean.^2)) / N; % 20D,lam=(40,1000):17e3 - % 75e3 with def (1.5) - % 35e3 with damps=0.25 - end - if 11 < 3 - if countiter == 1 - disp('*********** xmean set to const ******************'); - end - xmean = ones(N,1); - end - - % Update B and D from C - - if ~flgDiagonalOnly && (ccov1+ccovmu+neg.ccov) > 0 && mod(countiter, 1/(ccov1+ccovmu+neg.ccov)/N/10) < 1 - C=triu(C)+triu(C,1)'; % enforce symmetry to prevent complex numbers - [B,tmp] = eig(C); % eigen decomposition, B==normalized eigenvectors - % effort: approx. 15*N matrix-vector multiplications - diagD = diag(tmp); - - if any(~isfinite(diagD)) - clear idx; % prevents error under octave - save(['tmp' opts.SaveFilename]); - error(['function eig returned non-finited eigenvalues, cond(C)=' ... - num2str(cond(C)) ]); - end - if any(any(~isfinite(B))) - clear idx; % prevents error under octave - save(['tmp' opts.SaveFilename]); - error(['function eig returned non-finited eigenvectors, cond(C)=' ... - num2str(cond(C)) ]); - end - % limit condition of C to 1e14 + 1 - if min(diagD) <= 0 - if stopOnWarnings - stopflag(end+1) = {'warnconditioncov'}; - else - warning(['Iteration ' num2str(countiter) ... - ': Eigenvalue (smaller) zero']); - diagD(diagD<0) = 0; - tmp = max(diagD)/1e14; - C = C + tmp*eye(N,N); diagD = diagD + tmp*ones(N,1); - end - end - if max(diagD) > 1e14*min(diagD) - if stopOnWarnings - stopflag(end+1) = {'warnconditioncov'}; - else - warning(['Iteration ' num2str(countiter) ': condition of C ' ... - 'at upper limit' ]); - tmp = max(diagD)/1e14 - min(diagD); - C = C + tmp*eye(N,N); diagD = diagD + tmp*ones(N,1); - end - end + % non-parallel evaluation and remaining NaN-values + % set also the reevaluated solution to NaN + fitness.raw(lambda + find(isnan(fitness.raw(1:noiseReevals)))) = NaN; + for k=find(isnan(fitness.raw)), + % fitness.raw(k) = NaN; + tries = 0; + % Resample, until fitness is not NaN + while isnan(fitness.raw(k)) + if k <= lambda % regular samples (not the re-evaluation-samples) + arz(:,k) = randn(N,1); % (re)sample + + if flgDiagonalOnly + arx(:,k) = xmean + sigma * diagD .* arz(:,k); % Eq. (1) + else + arx(:,k) = xmean + sigma * (BD * arz(:,k)); % Eq. (1) + end + else % re-evaluation solution with index > lambda + if flgDiagonalOnly + arx(:,k) = arx(:,k-lambda) + (noiseEpsilon * sigma) * diagD .* randn(N,1); + else + arx(:,k) = arx(:,k-lambda) + (noiseEpsilon * sigma) * (BD * randn(N,1)); + end + end + + % You may handle constraints here. You may either resample + % arz(:,k) and/or multiply it with a factor between -1 and 1 + % (the latter will decrease the overall step size) and + % recalculate arx accordingly. Do not change arx or arz in any + % other way. + + if ~bnd.isactive + arxvalid(:,k) = arx(:,k); + else + arxvalid(:,k) = xintobounds(arx(:,k), lbounds, ubounds); + end + % You may handle constraints here. You may copy and alter + % (columns of) arxvalid(:,k) only for the evaluation of the + % fitness function. arx should not be changed. + fitness.raw(k) = feval(fitfun, arxvalid(:,k), varargin{:}); + tries = tries + 1; + if isnan(fitness.raw(k)) + countevalNaN = countevalNaN + 1; + end + if mod(tries, 100) == 0 + warning([num2str(tries) ... + ' NaN objective function values at evaluation ' ... + num2str(counteval)]); + end + end + counteval = counteval + 1; % retries due to NaN are not counted + end - diagC = diag(C); - diagD = sqrt(diagD); % D contains standard deviations now - % diagD = diagD / prod(diagD)^(1/N); C = C / prod(diagD)^(2/N); - BD = B.*repmat(diagD',N,1); % O(n^2) - end % if mod - - % Align/rescale order of magnitude of scales of sigma and C for nicer output - % not a very usual case - if 1 < 2 && sigma > 1e10*max(diagD) - fac = sigma / max(diagD); - sigma = sigma/fac; - pc = fac * pc; - diagD = fac * diagD; - if ~flgDiagonalOnly - C = fac^2 * C; % disp(fac); - BD = B.*repmat(diagD',N,1); % O(n^2), but repmat might be inefficient todo? - end - diagC = fac^2 * diagC; - end - - if flgDiagonalOnly > 1 && countiter > flgDiagonalOnly - % full covariance matrix from now on - flgDiagonalOnly = 0; - B = eye(N,N); - BD = diag(diagD); - C = diag(diagC); % is better, because correlations are spurious anyway - end - - if noiseHandling - if countiter == 1 % assign firstvarargin for noise treatment e.g. as #reevaluations - if ~isempty(varargin) && length(varargin{1}) == 1 && isnumeric(varargin{1}) - if irun == 1 - firstvarargin = varargin{1}; - else - varargin{1} = firstvarargin; % reset varargin{1} - end - else - firstvarargin = 0; - end - end - if noiseSS < 0 && noiseMinMaxEvals(2) > noiseMinMaxEvals(1) && firstvarargin - varargin{1} = max(noiseMinMaxEvals(1), varargin{1} / noiseAlphaEvals^(1/4)); % still experimental - elseif noiseSS > 0 - if ~isempty(noiseCallback) % to be removed? - res = feval(noiseCallback); % should also work without output argument!? - if ~isempty(res) && res > 1 % TODO: decide for interface of callback - % also a dynamic popsize could be done here - sigma = sigma * noiseAlpha; - end - else - if noiseMinMaxEvals(2) > noiseMinMaxEvals(1) && firstvarargin - varargin{1} = min(noiseMinMaxEvals(2), varargin{1} * noiseAlphaEvals); - end - - sigma = sigma * noiseAlpha; - % lambda = ceil(0.1 * sqrt(lambda) + lambda); - % TODO: find smallest increase of lambda with log-linear - % convergence in iterations - end - % qqq experimental: take a mean to estimate the true optimum - noiseN = noiseN + 1; - if noiseN == 1 - noiseX = xmean; - else - noiseX = noiseX + (3/noiseN) * (xmean - noiseX); - end - end - end - - % ----- numerical error management ----- - % Adjust maximal coordinate axis deviations - if any(sigma*sqrt(diagC) > maxdx) - sigma = min(maxdx ./ sqrt(diagC)); - %warning(['Iteration ' num2str(countiter) ': coordinate axis std ' ... - % 'deviation at upper limit of ' num2str(maxdx)]); - % stopflag(end+1) = {'maxcoorddev'}; - end - % Adjust minimal coordinate axis deviations - if any(sigma*sqrt(diagC) < mindx) - sigma = max(mindx ./ sqrt(diagC)) * exp(0.05+cs/damps); - %warning(['Iteration ' num2str(countiter) ': coordinate axis std ' ... - % 'deviation at lower limit of ' num2str(mindx)]); - % stopflag(end+1) = {'mincoorddev'};; - end - % Adjust too low coordinate axis deviations - if any(xmean == xmean + 0.2*sigma*sqrt(diagC)) - if stopOnWarnings - stopflag(end+1) = {'warnnoeffectcoord'}; - else - warning(['Iteration ' num2str(countiter) ': coordinate axis std ' ... - 'deviation too low' ]); - if flgDiagonalOnly - diagC = diagC + (ccov1_sep+ccovmu_sep) * (diagC .* ... - (xmean == xmean + 0.2*sigma*sqrt(diagC))); - else - C = C + (ccov1+ccovmu) * diag(diagC .* ... - (xmean == xmean + 0.2*sigma*sqrt(diagC))); - end - sigma = sigma * exp(0.05+cs/damps); - end - end - % Adjust step size in case of (numerical) precision problem - if flgDiagonalOnly - tmp = 0.1*sigma*diagD; - else - tmp = 0.1*sigma*BD(:,1+floor(mod(countiter,N))); - end - if all(xmean == xmean + tmp) - i = 1+floor(mod(countiter,N)); - if stopOnWarnings - stopflag(end+1) = {'warnnoeffectaxis'}; - else - warning(['Iteration ' num2str(countiter) ... - ': main axis standard deviation ' ... - num2str(sigma*diagD(i)) ' has no effect' ]); - sigma = sigma * exp(0.2+cs/damps); - end - end - % Adjust step size in case of equal function values (flat fitness) - % isequalfuncvalues = 0; - if fitness.sel(1) == fitness.sel(1+ceil(0.1+lambda/4)) - % isequalfuncvalues = 1; - if stopOnEqualFunctionValues - arrEqualFunvals = [countiter arrEqualFunvals(1:end-1)]; - % stop if this happens in more than 33% - if arrEqualFunvals(end) > countiter - 3 * length(arrEqualFunvals) - stopflag(end+1) = {'equalfunvals'}; - end - else - if flgWarnOnEqualFunctionValues - warning(['Iteration ' num2str(countiter) ... - ': equal function values f=' num2str(fitness.sel(1)) ... - ' at maximal main axis sigma ' ... - num2str(sigma*max(diagD))]); - end - sigma = sigma * exp(0.2+cs/damps); - end - end - % Adjust step size in case of equal function values - if countiter > 2 && myrange([fitness.hist fitness.sel(1)]) == 0 - if stopOnWarnings - stopflag(end+1) = {'warnequalfunvalhist'}; - else - warning(['Iteration ' num2str(countiter) ... - ': equal function values in history at maximal main ' ... - 'axis sigma ' num2str(sigma*max(diagD))]); - sigma = sigma * exp(0.2+cs/damps); - end - end - - % ----- end numerical error management ----- - - % Keep overall best solution - out.evals = counteval; - out.solutions.evals = counteval; - out.solutions.mean.x = xmean; - out.solutions.mean.f = fmean; - out.solutions.mean.evals = counteval; - out.solutions.recentbest.x = arxvalid(:, fitness.idx(1)); - out.solutions.recentbest.f = fitness.raw(1); - out.solutions.recentbest.evals = counteval + fitness.idx(1) - lambda; - out.solutions.recentworst.x = arxvalid(:, fitness.idx(end)); - out.solutions.recentworst.f = fitness.raw(end); - out.solutions.recentworst.evals = counteval + fitness.idx(end) - lambda; - if fitness.hist(1) < out.solutions.bestever.f - out.solutions.bestever.x = arxvalid(:, fitness.idx(1)); - out.solutions.bestever.f = fitness.hist(1); - out.solutions.bestever.evals = counteval + fitness.idx(1) - lambda; - bestever = out.solutions.bestever; - end - - % Set stop flag - if fitness.raw(1) <= stopFitness, stopflag(end+1) = {'fitness'}; end - if counteval >= stopMaxFunEvals, stopflag(end+1) = {'maxfunevals'}; end - if countiter >= stopMaxIter, stopflag(end+1) = {'maxiter'}; end - if all(sigma*(max(abs(pc), sqrt(diagC))) < stopTolX) - stopflag(end+1) = {'tolx'}; - end - if any(sigma*sqrt(diagC) > stopTolUpX) - stopflag(end+1) = {'tolupx'}; - end - if sigma*max(diagD) == 0 % should never happen - stopflag(end+1) = {'bug'}; - end - if countiter > 2 && myrange([fitness.sel fitness.hist]) <= stopTolFun - stopflag(end+1) = {'tolfun'}; - end - if countiter >= length(fitness.hist) && myrange(fitness.hist) <= stopTolHistFun - stopflag(end+1) = {'tolhistfun'}; - end - l = floor(length(fitness.histbest)/3); - if 1 < 2 && stopOnStagnation && ... % leads sometimes early stop on ftablet, fcigtab - countiter > N * (5+100/lambda) && ... - length(fitness.histbest) > 100 && ... - median(fitness.histmedian(1:l)) >= median(fitness.histmedian(end-l:end)) && ... - median(fitness.histbest(1:l)) >= median(fitness.histbest(end-l:end)) - stopflag(end+1) = {'stagnation'}; - end - - if counteval >= stopFunEvals || countiter >= stopIter - stopflag(end+1) = {'stoptoresume'}; - if length(stopflag) == 1 && flgsaving == 0 - error('To resume later the saving option needs to be set'); - end - end - % read stopping message from file signals.par - if flgreadsignals - fid = fopen('./signals.par', 'rt'); % can be performance critical - while fid > 0 - strline = fgetl(fid); %fgets(fid, 300); - if strline < 0 % fgets and fgetl returns -1 at end of file - break; - end - % 'stop filename' sets stopflag to manual - str = sscanf(strline, ' %s %s', 2); - if strcmp(str, ['stop' opts.LogFilenamePrefix]) - stopflag(end+1) = {'manual'}; - break; - end - % 'skip filename run 3' skips a run, but not the last - str = sscanf(strline, ' %s %s %s', 3); - if strcmp(str, ['skip' opts.LogFilenamePrefix 'run']) - i = strfind(strline, 'run'); - if irun == sscanf(strline(i+3:end), ' %d ', 1) && irun <= myeval(opts.Restarts) - stopflag(end+1) = {'skipped'}; - end - end - end % while, break - if fid > 0 - fclose(fid); - clear fid; % prevents strange error under octave - end - end - - out.stopflag = stopflag; - - % ----- output generation ----- - if verbosemodulo > 0 && isfinite(verbosemodulo) - if countiter == 1 || mod(countiter, 10*verbosemodulo) < 1 - disp(['Iterat, #Fevals: Function Value (median,worst) ' ... - '|Axis Ratio|' ... - 'idx:Min SD idx:Max SD']); - end - if mod(countiter, verbosemodulo) < 1 ... - || (verbosemodulo > 0 && isfinite(verbosemodulo) && ... - (countiter < 3 || ~isempty(stopflag))) - [minstd minstdidx] = min(sigma*sqrt(diagC)); - [maxstd maxstdidx] = max(sigma*sqrt(diagC)); - % format display nicely - disp([repmat(' ',1,4-floor(log10(countiter))) ... - num2str(countiter) ' , ' ... - repmat(' ',1,5-floor(log10(counteval))) ... - num2str(counteval) ' : ' ... - num2str(fitness.hist(1), '%.13e') ... - ' +(' num2str(median(fitness.raw)-fitness.hist(1), '%.0e ') ... - ',' num2str(max(fitness.raw)-fitness.hist(1), '%.0e ') ... - ') | ' ... - num2str(max(diagD)/min(diagD), '%4.2e') ' | ' ... - repmat(' ',1,1-floor(log10(minstdidx))) num2str(minstdidx) ':' ... - num2str(minstd, ' %.1e') ' ' ... - repmat(' ',1,1-floor(log10(maxstdidx))) num2str(maxstdidx) ':' ... - num2str(maxstd, ' %.1e')]); - end - end - - % measure time for recording data - if countiter < 3 - time.c = 0.05; - time.nonoutput = 0; - time.recording = 0; - time.saving = 0.15; % first saving after 3 seconds of 100 iterations - time.plotting = 0; - elseif countiter > 300 - % set backward horizon, must be long enough to cover infrequent plotting etc - % time.c = min(1, time.nonoutput/3 + 1e-9); - time.c = max(1e-5, 0.1/sqrt(countiter)); % mean over all or 1e-5 - end - % get average time per iteration - time.t1 = clock; - time.act = max(0,etime(time.t1, time.t0)); - time.nonoutput = (1-time.c) * time.nonoutput ... - + time.c * time.act; - - time.recording = (1-time.c) * time.recording; % per iteration - time.saving = (1-time.c) * time.saving; - time.plotting = (1-time.c) * time.plotting; - - % record output data, concerning time issues - if savemodulo && savetime && (countiter < 1e2 || ~isempty(stopflag) || ... - countiter >= outiter + savemodulo) - outiter = countiter; - % Save output data to files - for namecell = filenames(:)' - name = namecell{:}; - - [fid, err] = fopen(['./' filenameprefix name '.dat'], 'a'); - if fid < 1 % err ~= 0 - warning(['could not open ' filenameprefix name '.dat']); - else - if strcmp(name, 'axlen') - fprintf(fid, '%d %d %e %e %e ', countiter, counteval, sigma, ... - max(diagD), min(diagD)); - fprintf(fid, '%e ', sort(diagD)); - fprintf(fid, '\n'); - elseif strcmp(name, 'disp') % TODO - elseif strcmp(name, 'fit') - fprintf(fid, '%ld %ld %e %e %25.18e %25.18e %25.18e %25.18e', ... - countiter, counteval, sigma, max(diagD)/min(diagD), ... - out.solutions.bestever.f, ... - fitness.raw(1), median(fitness.raw), fitness.raw(end)); - if ~isempty(varargin) && length(varargin{1}) == 1 && isnumeric(varargin{1}) && varargin{1} ~= 0 - fprintf(fid, ' %f', varargin{1}); - end - fprintf(fid, '\n'); - elseif strcmp(name, 'stddev') - fprintf(fid, '%ld %ld %e 0 0 ', countiter, counteval, sigma); - fprintf(fid, '%e ', sigma*sqrt(diagC)); - fprintf(fid, '\n'); - elseif strcmp(name, 'xmean') - if isnan(fmean) - fprintf(fid, '%ld %ld 0 0 0 ', countiter, counteval); - else - fprintf(fid, '%ld %ld 0 0 %e ', countiter, counteval, fmean); - end - fprintf(fid, '%e ', xmean); - fprintf(fid, '\n'); - elseif strcmp(name, 'xrecentbest') - % TODO: fitness is inconsistent with x-value - fprintf(fid, '%ld %ld %25.18e 0 0 ', countiter, counteval, fitness.raw(1)); - fprintf(fid, '%e ', arx(:,fitness.idx(1))); - fprintf(fid, '\n'); - end - fclose(fid); - end - end - - % get average time for recording data - time.t2 = clock; - time.recording = time.recording + time.c * max(0,etime(time.t2, time.t1)); - - % plot - if flgplotting && countiter > 1 - if countiter == 2 - iterplotted = 0; - end - if ~isempty(stopflag) || ... - ((time.nonoutput+time.recording) * (countiter - iterplotted) > 1 && ... - time.plotting < 0.05 * (time.nonoutput+time.recording)) - local_plotcmaesdat(324, filenameprefix); - iterplotted = countiter; - % outplot(out); % outplot defined below - if time.plotting == 0 % disregard opening of the window - time.plotting = time.nonoutput+time.recording; + fitness.sel = fitness.raw; + + % ----- handle boundaries ----- + if 1 < 3 && bnd.isactive + % Get delta fitness values + val = myprctile(fitness.raw, [25 75]); + % more precise would be exp(mean(log(diagC))) + val = (val(2) - val(1)) / N / mean(diagC) / sigma^2; + %val = (myprctile(fitness.raw, 75) - myprctile(fitness.raw, 25)) ... + % / N / mean(diagC) / sigma^2; + % Catch non-sensible values + if ~isfinite(val) + warning('Non-finite fitness range'); + val = max(bnd.dfithist); + elseif val == 0 % happens if all points are out of bounds + val = min(bnd.dfithist(bnd.dfithist>0)); % seems not to make sense, given all solutions are out of bounds + elseif bnd.validfitval == 0 % flag that first sensible val was found + bnd.dfithist = []; + bnd.validfitval = 1; + end + + % Store delta fitness values + if length(bnd.dfithist) < 20+(3*N)/lambda + bnd.dfithist = [bnd.dfithist val]; + else + bnd.dfithist = [bnd.dfithist(2:end) val]; + end + + [tx ti] = xintobounds(xmean, lbounds, ubounds); + + % Set initial weights + if bnd.iniphase + if any(ti) + bnd.weights(find(bnd.isbounded)) = 2.0002 * median(bnd.dfithist); + if bnd.flgscale == 0 % scale only initial weights then + dd = diagC; + idx = find(bnd.isbounded); + dd = dd(idx) / mean(dd); % remove mean scaling + bnd.weights(idx) = bnd.weights(idx) ./ dd; + end + if bnd.validfitval && countiter > 2 + bnd.iniphase = 0; + end + end + end + + % Increase weights + if 1 < 3 && any(ti) % any coordinate of xmean out of bounds + % judge distance of xmean to boundary + tx = xmean - tx; + idx = (ti ~= 0 & abs(tx) > 3*max(1,sqrt(N)/mueff) ... + * sigma*sqrt(diagC)) ; + % only increase if xmean is moving away + idx = idx & (sign(tx) == sign(xmean - xold)); + if ~isempty(idx) % increase + % the factor became 1.2 instead of 1.1, because + % changed from max to min in version 3.52 + bnd.weights(idx) = 1.2^(min(1, mueff/10/N)) * bnd.weights(idx); + end + end + + % Calculate scaling biased to unity, product is one + if bnd.flgscale ~= 0 + bnd.scale = exp(0.9*(log(diagC)-mean(log(diagC)))); + end + + % Assigned penalized fitness + bnd.arpenalty = (bnd.weights ./ bnd.scale)' * (arxvalid - arx).^2; + + fitness.sel = fitness.raw + bnd.arpenalty; + + end % handle boundaries + % ----- end handle boundaries ----- + + % compute noise measurement and reduce fitness arrays to size lambda + if noiseHandling + [noiseS] = local_noisemeasurement(fitness.sel(1:lambda), ... + fitness.sel(lambda+(1:noiseReevals)), ... + noiseReevals, noiseTheta, noiseCutOff); + if countiter == 1 % TODO: improve this very rude way of initialization + noiseSS = 0; + noiseN = 0; % counter for mean + end + noiseSS = noiseSS + noisecum * (noiseS - noiseSS); + + % noise-handling could be done here, but the original sigma is still needed + % disp([noiseS noiseSS noisecum]) + + fitness.rawar12 = fitness.raw; % just documentary + fitness.selar12 = fitness.sel; % just documentary + % qqq refine fitness based on both values + if 11 < 3 % TODO: in case of outliers this mean is counterproductive + % median out of three would be ok + fitness.raw(1:noiseReevals) = ... % not so raw anymore + (fitness.raw(1:noiseReevals) + fitness.raw(lambda+(1:noiseReevals))) / 2; + fitness.sel(1:noiseReevals) = ... + (fitness.sel(1:noiseReevals) + fitness.sel(lambda+(1:noiseReevals))) / 2; + end + fitness.raw = fitness.raw(1:lambda); + fitness.sel = fitness.sel(1:lambda); + end + + % Sort by fitness + [fitness.raw, fitness.idx] = sort(fitness.raw); + [fitness.sel, fitness.idxsel] = sort(fitness.sel); % minimization + fitness.hist(2:end) = fitness.hist(1:end-1); % record short history of + fitness.hist(1) = fitness.raw(1); % best fitness values + if length(fitness.histbest) < 120+ceil(30*N/lambda) || ... + (mod(countiter, 5) == 0 && length(fitness.histbest) < 2e4) % 20 percent of 1e5 gen. + fitness.histbest = [fitness.raw(1) fitness.histbest]; % best fitness values + fitness.histmedian = [median(fitness.raw) fitness.histmedian]; % median fitness values + else + fitness.histbest(2:end) = fitness.histbest(1:end-1); + fitness.histmedian(2:end) = fitness.histmedian(1:end-1); + fitness.histbest(1) = fitness.raw(1); % best fitness values + fitness.histmedian(1) = median(fitness.raw); % median fitness values + end + fitness.histsel(2:end) = fitness.histsel(1:end-1); % record short history of + fitness.histsel(1) = fitness.sel(1); % best sel fitness values + + % Calculate new xmean, this is selection and recombination + xold = xmean; % for speed up of Eq. (2) and (3) + xmean = arx(:,fitness.idxsel(1:mu))*weights; + zmean = arz(:,fitness.idxsel(1:mu))*weights;%==D^-1*B'*(xmean-xold)/sigma + if mu == 1 + fmean = fitness.sel(1); + else + fmean = NaN; % [] does not work in the latter assignment + % fmean = feval(fitfun, xintobounds(xmean, lbounds, ubounds), varargin{:}); + % counteval = counteval + 1; + end + + % Cumulation: update evolution paths + ps = (1-cs)*ps + sqrt(cs*(2-cs)*mueff) * (B*zmean); % Eq. (4) + hsig = norm(ps)/sqrt(1-(1-cs)^(2*countiter))/chiN < 1.4 + 2/(N+1); + if flg_future_setting + hsig = sum(ps.^2) / (1-(1-cs)^(2*countiter)) / N < 2 + 4/(N+1); % just simplified + end + % hsig = norm(ps)/sqrt(1-(1-cs)^(2*countiter))/chiN < 1.4 + 2/(N+1); + % hsig = norm(ps)/sqrt(1-(1-cs)^(2*countiter))/chiN < 1.5 + 1/(N-0.5); + % hsig = norm(ps) < 1.5 * sqrt(N); + % hsig = 1; + + pc = (1-cc)*pc ... + + hsig*(sqrt(cc*(2-cc)*mueff)/sigma) * (xmean-xold); % Eq. (2) + if hsig == 0 + % disp([num2str(countiter) ' ' num2str(counteval) ' pc update stalled']); + end + + % Adapt covariance matrix + neg.ccov = 0; % TODO: move parameter setting upwards at some point + if ccov1 + ccovmu > 0 % Eq. (3) + if flgDiagonalOnly % internal linear(?) complexity + diagC = (1-ccov1_sep-ccovmu_sep+(1-hsig)*ccov1_sep*cc*(2-cc)) * diagC ... % regard old matrix + + ccov1_sep * pc.^2 ... % plus rank one update + + ccovmu_sep ... % plus rank mu update + * (diagC .* (arz(:,fitness.idxsel(1:mu)).^2 * weights)); + % * (repmat(diagC,1,mu) .* arz(:,fitness.idxsel(1:mu)).^2 * weights); + diagD = sqrt(diagC); % replaces eig(C) + else + arpos = (arx(:,fitness.idxsel(1:mu))-repmat(xold,1,mu)) / sigma; + % "active" CMA update: negative update, in case controlling pos. definiteness + if flgActiveCMA > 0 + % set parameters + neg.mu = mu; + neg.mueff = mueff; + if flgActiveCMA > 10 % flat weights with mu=lambda/2 + neg.mu = floor(lambda/2); + neg.mueff = neg.mu; + end + % neg.mu = ceil(min([N, lambda/4, mueff])); neg.mueff = mu; % i.e. neg.mu <= N + % Parameter study: in 3-D lambda=50,100, 10-D lambda=200,400, 30-D lambda=1000,2000 a + % three times larger neg.ccov does not work. + % increasing all ccov rates three times does work (probably because of the factor (1-ccovmu)) + % in 30-D to looks fine + + neg.ccov = (1 - ccovmu) * 0.25 * neg.mueff / ((N+2)^1.5 + 2*neg.mueff); + neg.minresidualvariance = 0.66; % keep at least 0.66 in all directions, small popsize are most critical + neg.alphaold = 0.5; % where to make up for the variance loss, 0.5 means no idea what to do + % 1 is slightly more robust and gives a better "guaranty" for pos. def., + % but does it make sense from the learning perspective for large ccovmu? + + neg.ccovfinal = neg.ccov; + + % prepare vectors, compute negative updating matrix Cneg and checking matrix Ccheck + arzneg = arz(:,fitness.idxsel(lambda:-1:lambda - neg.mu + 1)); + % i-th longest becomes i-th shortest + % TODO: this is not in compliance with the paper Hansen&Ros2010, + % where simply arnorms = arnorms(end:-1:1) ? + [arnorms idxnorms] = sort(sqrt(sum(arzneg.^2, 1))); + [ignore idxnorms] = sort(idxnorms); % inverse index + arnormfacs = arnorms(end:-1:1) ./ arnorms; + % arnormfacs = arnorms(randperm(neg.mu)) ./ arnorms; + arnorms = arnorms(end:-1:1); % for the record + if flgActiveCMA < 20 + arzneg = arzneg .* repmat(arnormfacs(idxnorms), N, 1); % E x*x' is N + % arzneg = sqrt(N) * arzneg ./ repmat(sqrt(sum(arzneg.^2, 1)), N, 1); % E x*x' is N + end + if flgActiveCMA < 10 && neg.mu == mu % weighted sum + if mod(flgActiveCMA, 10) == 1 % TODO: prevent this with a less tight but more efficient check (see below) + Ccheck = arzneg * diag(weights) * arzneg'; % in order to check the largest EV + end + artmp = BD * arzneg; + Cneg = artmp * diag(weights) * artmp'; + else % simple sum + if mod(flgActiveCMA, 10) == 1 + Ccheck = (1/neg.mu) * arzneg*arzneg'; % in order to check largest EV + end + artmp = BD * arzneg; + Cneg = (1/neg.mu) * artmp*artmp'; + + end + + % check pos.def. and set learning rate neg.ccov accordingly, + % this check makes the original choice of neg.ccov extremly failsafe + % still assuming C == BD*BD', which is only approxim. correct + if mod(flgActiveCMA, 10) == 1 && 1 - neg.ccov * arnorms(idxnorms).^2 * weights < neg.minresidualvariance + % TODO: the simple and cheap way would be to set + % fac = 1 - ccovmu - ccov1 OR 1 - mueff/lambda and + % neg.ccov = fac*(1 - neg.minresidualvariance) / (arnorms(idxnorms).^2 * weights) + % this is the more sophisticated way: + % maxeigenval = eigs(arzneg * arzneg', 1, 'lm', eigsopts); % not faster + maxeigenval = max(eig(Ccheck)); % norm is much slower, because (norm()==max(svd()) + %disp([countiter log10([neg.ccov, maxeigenval, arnorms(idxnorms).^2 * weights, max(arnorms)^2]), ... + % neg.ccov * arnorms(idxnorms).^2 * weights]) + % pause + % remove less than ??34*(1-cmu)%?? of variance in any direction + % 1-ccovmu is the variance left from the old C + neg.ccovfinal = min(neg.ccov, (1-ccovmu)*(1-neg.minresidualvariance)/maxeigenval); + % -ccov1 removed to avoid error message?? + if neg.ccovfinal < neg.ccov + disp(['active CMA at iteration ' num2str(countiter) ... + ': max EV ==', num2str([maxeigenval, neg.ccov, neg.ccovfinal])]); + end + end + % xmean = xold; % the distribution does not degenerate!? + % update C + C = (1-ccov1-ccovmu+neg.alphaold*neg.ccovfinal+(1-hsig)*ccov1*cc*(2-cc)) * C ... % regard old matrix + + ccov1 * pc*pc' ... % plus rank one update + + (ccovmu + (1-neg.alphaold)*neg.ccovfinal) ... % plus rank mu update + * arpos * (repmat(weights,1,N) .* arpos') ... + - neg.ccovfinal * Cneg; % minus rank mu update + else % no active (negative) update + C = (1-ccov1-ccovmu+(1-hsig)*ccov1*cc*(2-cc)) * C ... % regard old matrix + + ccov1 * pc*pc' ... % plus rank one update + + ccovmu ... % plus rank mu update + * arpos * (repmat(weights,1,N) .* arpos'); + % is now O(mu*N^2 + mu*N), was O(mu*N^2 + mu^2*N) when using diag(weights) + % for mu=30*N it is now 10 times faster, overall 3 times faster + end + diagC = diag(C); + end + end + + % the following is de-preciated and will be removed in future + % better setting for cc makes this hack obsolete + if 11 < 2 && ~flgscience + % remove momentum in ps, if ps is large and fitness is getting worse. + % this should rarely happen. + % this might very well be counterproductive in dynamic environments + if sum(ps.^2)/N > 1.5 + 10*(2/N)^.5 && ... + fitness.histsel(1) > max(fitness.histsel(2:3)) + ps = ps * sqrt(N*(1+max(0,log(sum(ps.^2)/N))) / sum(ps.^2)); + if flgdisplay + disp(['Momentum in ps removed at [niter neval]=' ... + num2str([countiter counteval]) ']']); + end + end + end + + % Adapt sigma + if flg_future_setting % according to a suggestion from Dirk Arnold (2000) + % exp(1) is still not reasonably small enough + sigma = sigma * exp(min(1, (sum(ps.^2)/N - 1)/2 * cs/damps)); % Eq. (5) + else + % exp(1) is still not reasonably small enough + sigma = sigma * exp(min(1, (sqrt(sum(ps.^2))/chiN - 1) * cs/damps)); % Eq. (5) + end + % disp([countiter norm(ps)/chiN]); + + if 11 < 3 % testing with optimal step-size + if countiter == 1 + disp('*********** sigma set to const * ||x|| ******************'); + end + sigma = 0.04 * mueff * sqrt(sum(xmean.^2)) / N; % 20D,lam=1000:25e3 + sigma = 0.3 * mueff * sqrt(sum(xmean.^2)) / N; % 20D,lam=(40,1000):17e3 + % 75e3 with def (1.5) + % 35e3 with damps=0.25 + end + if 11 < 3 + if countiter == 1 + disp('*********** xmean set to const ******************'); + end + xmean = ones(N,1); + end + + % Update B and D from C + + if ~flgDiagonalOnly && (ccov1+ccovmu+neg.ccov) > 0 && mod(countiter, 1/(ccov1+ccovmu+neg.ccov)/N/10) < 1 + C=triu(C)+triu(C,1)'; % enforce symmetry to prevent complex numbers + [B,tmp] = eig(C); % eigen decomposition, B==normalized eigenvectors + % effort: approx. 15*N matrix-vector multiplications + diagD = diag(tmp); + + if any(~isfinite(diagD)) + clear idx; % prevents error under octave + save(['tmp' opts.SaveFilename]); + error(['function eig returned non-finited eigenvalues, cond(C)=' ... + num2str(cond(C)) ]); + end + if any(any(~isfinite(B))) + clear idx; % prevents error under octave + save(['tmp' opts.SaveFilename]); + error(['function eig returned non-finited eigenvectors, cond(C)=' ... + num2str(cond(C)) ]); + end + + % limit condition of C to 1e14 + 1 + if min(diagD) <= 0 + if stopOnWarnings + stopflag(end+1) = {'warnconditioncov'}; + else + warning(['Iteration ' num2str(countiter) ... + ': Eigenvalue (smaller) zero']); + diagD(diagD<0) = 0; + tmp = max(diagD)/1e14; + C = C + tmp*eye(N,N); diagD = diagD + tmp*ones(N,1); + end + end + if max(diagD) > 1e14*min(diagD) + if stopOnWarnings + stopflag(end+1) = {'warnconditioncov'}; + else + warning(['Iteration ' num2str(countiter) ': condition of C ' ... + 'at upper limit' ]); + tmp = max(diagD)/1e14 - min(diagD); + C = C + tmp*eye(N,N); diagD = diagD + tmp*ones(N,1); + end + end + + diagC = diag(C); + diagD = sqrt(diagD); % D contains standard deviations now + % diagD = diagD / prod(diagD)^(1/N); C = C / prod(diagD)^(2/N); + BD = B.*repmat(diagD',N,1); % O(n^2) + end % if mod + + % Align/rescale order of magnitude of scales of sigma and C for nicer output + % not a very usual case + if 1 < 2 && sigma > 1e10*max(diagD) + fac = sigma / max(diagD); + sigma = sigma/fac; + pc = fac * pc; + diagD = fac * diagD; + if ~flgDiagonalOnly + C = fac^2 * C; % disp(fac); + BD = B.*repmat(diagD',N,1); % O(n^2), but repmat might be inefficient todo? + end + diagC = fac^2 * diagC; + end + + if flgDiagonalOnly > 1 && countiter > flgDiagonalOnly + % full covariance matrix from now on + flgDiagonalOnly = 0; + B = eye(N,N); + BD = diag(diagD); + C = diag(diagC); % is better, because correlations are spurious anyway + end + + if noiseHandling + if countiter == 1 % assign firstvarargin for noise treatment e.g. as #reevaluations + if ~isempty(varargin) && length(varargin{1}) == 1 && isnumeric(varargin{1}) + if irun == 1 + firstvarargin = varargin{1}; + else + varargin{1} = firstvarargin; % reset varargin{1} + end + else + firstvarargin = 0; + end + end + if noiseSS < 0 && noiseMinMaxEvals(2) > noiseMinMaxEvals(1) && firstvarargin + varargin{1} = max(noiseMinMaxEvals(1), varargin{1} / noiseAlphaEvals^(1/4)); % still experimental + elseif noiseSS > 0 + if ~isempty(noiseCallback) % to be removed? + res = feval(noiseCallback); % should also work without output argument!? + if ~isempty(res) && res > 1 % TODO: decide for interface of callback + % also a dynamic popsize could be done here + sigma = sigma * noiseAlpha; + end + else + if noiseMinMaxEvals(2) > noiseMinMaxEvals(1) && firstvarargin + varargin{1} = min(noiseMinMaxEvals(2), varargin{1} * noiseAlphaEvals); + end + + sigma = sigma * noiseAlpha; + % lambda = ceil(0.1 * sqrt(lambda) + lambda); + % TODO: find smallest increase of lambda with log-linear + % convergence in iterations + end + % qqq experimental: take a mean to estimate the true optimum + noiseN = noiseN + 1; + if noiseN == 1 + noiseX = xmean; + else + noiseX = noiseX + (3/noiseN) * (xmean - noiseX); + end + end + end + + % ----- numerical error management ----- + % Adjust maximal coordinate axis deviations + if any(sigma*sqrt(diagC) > maxdx) + sigma = min(maxdx ./ sqrt(diagC)); + %warning(['Iteration ' num2str(countiter) ': coordinate axis std ' ... + % 'deviation at upper limit of ' num2str(maxdx)]); + % stopflag(end+1) = {'maxcoorddev'}; + end + % Adjust minimal coordinate axis deviations + if any(sigma*sqrt(diagC) < mindx) + sigma = max(mindx ./ sqrt(diagC)) * exp(0.05+cs/damps); + %warning(['Iteration ' num2str(countiter) ': coordinate axis std ' ... + % 'deviation at lower limit of ' num2str(mindx)]); + % stopflag(end+1) = {'mincoorddev'};; + end + % Adjust too low coordinate axis deviations + if any(xmean == xmean + 0.2*sigma*sqrt(diagC)) + if stopOnWarnings + stopflag(end+1) = {'warnnoeffectcoord'}; + else + warning(['Iteration ' num2str(countiter) ': coordinate axis std ' ... + 'deviation too low' ]); + if flgDiagonalOnly + diagC = diagC + (ccov1_sep+ccovmu_sep) * (diagC .* ... + (xmean == xmean + 0.2*sigma*sqrt(diagC))); + else + C = C + (ccov1+ccovmu) * diag(diagC .* ... + (xmean == xmean + 0.2*sigma*sqrt(diagC))); + end + sigma = sigma * exp(0.05+cs/damps); + end + end + % Adjust step size in case of (numerical) precision problem + if flgDiagonalOnly + tmp = 0.1*sigma*diagD; + else + tmp = 0.1*sigma*BD(:,1+floor(mod(countiter,N))); + end + if all(xmean == xmean + tmp) + i = 1+floor(mod(countiter,N)); + if stopOnWarnings + stopflag(end+1) = {'warnnoeffectaxis'}; + else + warning(['Iteration ' num2str(countiter) ... + ': main axis standard deviation ' ... + num2str(sigma*diagD(i)) ' has no effect' ]); + sigma = sigma * exp(0.2+cs/damps); + end + end + % Adjust step size in case of equal function values (flat fitness) + % isequalfuncvalues = 0; + if fitness.sel(1) == fitness.sel(1+ceil(0.1+lambda/4)) + % isequalfuncvalues = 1; + if stopOnEqualFunctionValues + arrEqualFunvals = [countiter arrEqualFunvals(1:end-1)]; + % stop if this happens in more than 33% + if arrEqualFunvals(end) > countiter - 3 * length(arrEqualFunvals) + stopflag(end+1) = {'equalfunvals'}; + end + else + if flgWarnOnEqualFunctionValues + warning(['Iteration ' num2str(countiter) ... + ': equal function values f=' num2str(fitness.sel(1)) ... + ' at maximal main axis sigma ' ... + num2str(sigma*max(diagD))]); + end + sigma = sigma * exp(0.2+cs/damps); + end + end + % Adjust step size in case of equal function values + if countiter > 2 && myrange([fitness.hist fitness.sel(1)]) == 0 + if stopOnWarnings + stopflag(end+1) = {'warnequalfunvalhist'}; + else + warning(['Iteration ' num2str(countiter) ... + ': equal function values in history at maximal main ' ... + 'axis sigma ' num2str(sigma*max(diagD))]); + sigma = sigma * exp(0.2+cs/damps); + end + end + + % ----- end numerical error management ----- + + % Keep overall best solution + out.evals = counteval; + out.solutions.evals = counteval; + out.solutions.mean.x = xmean; + out.solutions.mean.f = fmean; + out.solutions.mean.evals = counteval; + out.solutions.recentbest.x = arxvalid(:, fitness.idx(1)); + out.solutions.recentbest.f = fitness.raw(1); + out.solutions.recentbest.evals = counteval + fitness.idx(1) - lambda; + out.solutions.recentworst.x = arxvalid(:, fitness.idx(end)); + out.solutions.recentworst.f = fitness.raw(end); + out.solutions.recentworst.evals = counteval + fitness.idx(end) - lambda; + if fitness.hist(1) < out.solutions.bestever.f + out.solutions.bestever.x = arxvalid(:, fitness.idx(1)); + out.solutions.bestever.f = fitness.hist(1); + out.solutions.bestever.evals = counteval + fitness.idx(1) - lambda; + bestever = out.solutions.bestever; + end + + % Set stop flag + if fitness.raw(1) <= stopFitness, stopflag(end+1) = {'fitness'}; end + if counteval >= stopMaxFunEvals, stopflag(end+1) = {'maxfunevals'}; end + if countiter >= stopMaxIter, stopflag(end+1) = {'maxiter'}; end + if all(sigma*(max(abs(pc), sqrt(diagC))) < stopTolX) + stopflag(end+1) = {'tolx'}; + end + if any(sigma*sqrt(diagC) > stopTolUpX) + stopflag(end+1) = {'tolupx'}; + end + if sigma*max(diagD) == 0 % should never happen + stopflag(end+1) = {'bug'}; + end + if countiter > 2 && myrange([fitness.sel fitness.hist]) <= stopTolFun + stopflag(end+1) = {'tolfun'}; + end + if countiter >= length(fitness.hist) && myrange(fitness.hist) <= stopTolHistFun + stopflag(end+1) = {'tolhistfun'}; + end + l = floor(length(fitness.histbest)/3); + if 1 < 2 && stopOnStagnation && ... % leads sometimes early stop on ftablet, fcigtab + countiter > N * (5+100/lambda) && ... + length(fitness.histbest) > 100 && ... + median(fitness.histmedian(1:l)) >= median(fitness.histmedian(end-l:end)) && ... + median(fitness.histbest(1:l)) >= median(fitness.histbest(end-l:end)) + stopflag(end+1) = {'stagnation'}; + end + + if counteval >= stopFunEvals || countiter >= stopIter + stopflag(end+1) = {'stoptoresume'}; + if length(stopflag) == 1 && flgsaving == 0 + error('To resume later the saving option needs to be set'); + end + end + % read stopping message from file signals.par + if flgreadsignals + fid = fopen('./signals.par', 'rt'); % can be performance critical + while fid > 0 + strline = fgetl(fid); %fgets(fid, 300); + if strline < 0 % fgets and fgetl returns -1 at end of file + break; + end + % 'stop filename' sets stopflag to manual + str = sscanf(strline, ' %s %s', 2); + if strcmp(str, ['stop' opts.LogFilenamePrefix]) + stopflag(end+1) = {'manual'}; + break; + end + % 'skip filename run 3' skips a run, but not the last + str = sscanf(strline, ' %s %s %s', 3); + if strcmp(str, ['skip' opts.LogFilenamePrefix 'run']) + i = strfind(strline, 'run'); + if irun == sscanf(strline(i+3:end), ' %d ', 1) && irun <= myeval(opts.Restarts) + stopflag(end+1) = {'skipped'}; + end + end + end % while, break + if fid > 0 + fclose(fid); + clear fid; % prevents strange error under octave + end + end + + out.stopflag = stopflag; + + % ----- output generation ----- + if verbosemodulo > 0 && isfinite(verbosemodulo) + if countiter == 1 || mod(countiter, 10*verbosemodulo) < 1 + disp(['Iterat, #Fevals: Function Value (median,worst) ' ... + '|Axis Ratio|' ... + 'idx:Min SD idx:Max SD']); + end + if mod(countiter, verbosemodulo) < 1 ... + || (verbosemodulo > 0 && isfinite(verbosemodulo) && ... + (countiter < 3 || ~isempty(stopflag))) + [minstd minstdidx] = min(sigma*sqrt(diagC)); + [maxstd maxstdidx] = max(sigma*sqrt(diagC)); + % format display nicely + disp([repmat(' ',1,4-floor(log10(countiter))) ... + num2str(countiter) ' , ' ... + repmat(' ',1,5-floor(log10(counteval))) ... + num2str(counteval) ' : ' ... + num2str(fitness.hist(1), '%.13e') ... + ' +(' num2str(median(fitness.raw)-fitness.hist(1), '%.0e ') ... + ',' num2str(max(fitness.raw)-fitness.hist(1), '%.0e ') ... + ') | ' ... + num2str(max(diagD)/min(diagD), '%4.2e') ' | ' ... + repmat(' ',1,1-floor(log10(minstdidx))) num2str(minstdidx) ':' ... + num2str(minstd, ' %.1e') ' ' ... + repmat(' ',1,1-floor(log10(maxstdidx))) num2str(maxstdidx) ':' ... + num2str(maxstd, ' %.1e')]); + end + end + + % measure time for recording data + if countiter < 3 + time.c = 0.05; + time.nonoutput = 0; + time.recording = 0; + time.saving = 0.15; % first saving after 3 seconds of 100 iterations + time.plotting = 0; + elseif countiter > 300 + % set backward horizon, must be long enough to cover infrequent plotting etc + % time.c = min(1, time.nonoutput/3 + 1e-9); + time.c = max(1e-5, 0.1/sqrt(countiter)); % mean over all or 1e-5 + end + % get average time per iteration + time.t1 = clock; + time.act = max(0,etime(time.t1, time.t0)); + time.nonoutput = (1-time.c) * time.nonoutput ... + + time.c * time.act; + + time.recording = (1-time.c) * time.recording; % per iteration + time.saving = (1-time.c) * time.saving; + time.plotting = (1-time.c) * time.plotting; + + % record output data, concerning time issues + if savemodulo && savetime && (countiter < 1e2 || ~isempty(stopflag) || ... + countiter >= outiter + savemodulo) + outiter = countiter; + % Save output data to files + for namecell = filenames(:)' + name = namecell{:}; + + [fid, err] = fopen(['./' filenameprefix name '.dat'], 'a'); + if fid < 1 % err ~= 0 + warning(['could not open ' filenameprefix name '.dat']); + else + if strcmp(name, 'axlen') + fprintf(fid, '%d %d %e %e %e ', countiter, counteval, sigma, ... + max(diagD), min(diagD)); + fprintf(fid, '%e ', sort(diagD)); + fprintf(fid, '\n'); + elseif strcmp(name, 'disp') % TODO + elseif strcmp(name, 'fit') + fprintf(fid, '%ld %ld %e %e %25.18e %25.18e %25.18e %25.18e', ... + countiter, counteval, sigma, max(diagD)/min(diagD), ... + out.solutions.bestever.f, ... + fitness.raw(1), median(fitness.raw), fitness.raw(end)); + if ~isempty(varargin) && length(varargin{1}) == 1 && isnumeric(varargin{1}) && varargin{1} ~= 0 + fprintf(fid, ' %f', varargin{1}); + end + fprintf(fid, '\n'); + elseif strcmp(name, 'stddev') + fprintf(fid, '%ld %ld %e 0 0 ', countiter, counteval, sigma); + fprintf(fid, '%e ', sigma*sqrt(diagC)); + fprintf(fid, '\n'); + elseif strcmp(name, 'xmean') + if isnan(fmean) + fprintf(fid, '%ld %ld 0 0 0 ', countiter, counteval); + else + fprintf(fid, '%ld %ld 0 0 %e ', countiter, counteval, fmean); + end + fprintf(fid, '%e ', xmean); + fprintf(fid, '\n'); + elseif strcmp(name, 'xrecentbest') + % TODO: fitness is inconsistent with x-value + fprintf(fid, '%ld %ld %25.18e 0 0 ', countiter, counteval, fitness.raw(1)); + fprintf(fid, '%e ', arx(:,fitness.idx(1))); + fprintf(fid, '\n'); + end + fclose(fid); + end + end + + % get average time for recording data + time.t2 = clock; + time.recording = time.recording + time.c * max(0,etime(time.t2, time.t1)); + + % plot + if flgplotting && countiter > 1 + if countiter == 2 + iterplotted = 0; + end + if ~isempty(stopflag) || ... + ((time.nonoutput+time.recording) * (countiter - iterplotted) > 1 && ... + time.plotting < 0.05 * (time.nonoutput+time.recording)) + local_plotcmaesdat(324, filenameprefix); + iterplotted = countiter; + % outplot(out); % outplot defined below + if time.plotting == 0 % disregard opening of the window + time.plotting = time.nonoutput+time.recording; + else + time.plotting = time.plotting + time.c * max(0,etime(clock, time.t2)); + end + end + end + if countiter > 100 + 20 && savemodulo && ... + time.recording * countiter > 0.1 && ... % absolute time larger 0.1 second + time.recording > savetime * (time.nonoutput+time.recording) / 100 + savemodulo = floor(1.1 * savemodulo) + 1; + % disp('++savemodulo'); %qqq + end + end % if output + + % save everything + time.t3 = clock; + if ~isempty(stopflag) || time.saving < 0.05 * time.nonoutput || countiter == 100 + xmin = arxvalid(:, fitness.idx(1)); + fmin = fitness.raw(1); + if flgsaving && countiter > 2 + clear idx; % prevents error under octave + % -v6 : non-compressed non-unicode for version 6 and earlier + if ~isempty(strsaving) && ~isoctave + save('-mat', strsaving, opts.SaveFilename); % for inspection and possible restart + else + save('-mat', opts.SaveFilename); % for inspection and possible restart + end + time.saving = time.saving + time.c * max(0,etime(clock, time.t3)); + end + end + time.t0 = clock; + + % ----- end output generation ----- + + end % while, end generation loop + + % -------------------- Final Procedures ------------------------------- + + % Evaluate xmean and return best recent point in xmin + fmin = fitness.raw(1); + xmin = arxvalid(:, fitness.idx(1)); % Return best point of last generation. + if length(stopflag) > sum(strcmp(stopflag, 'stoptoresume')) % final stopping + out.solutions.mean.f = ... + feval(fitfun, xintobounds(xmean, lbounds, ubounds), varargin{:}); + counteval = counteval + 1; + out.solutions.mean.evals = counteval; + if out.solutions.mean.f < fitness.raw(1) + fmin = out.solutions.mean.f; + xmin = xintobounds(xmean, lbounds, ubounds); % Return xmean as best point + end + if out.solutions.mean.f < out.solutions.bestever.f + out.solutions.bestever = out.solutions.mean; % Return xmean as bestever point + out.solutions.bestever.x = xintobounds(xmean, lbounds, ubounds); + bestever = out.solutions.bestever; + end + end + + % Save everything and display final message + if flgsavingfinal + clear idx; % prevents error under octave + if ~isempty(strsaving) && ~isoctave + save('-mat', strsaving, opts.SaveFilename); % for inspection and possible restart + else + save('-mat', opts.SaveFilename); % for inspection and possible restart + end + message = [' (saved to ' opts.SaveFilename ')']; else - time.plotting = time.plotting + time.c * max(0,etime(clock, time.t2)); + message = []; + end + + if flgdisplay + disp(['#Fevals: f(returned x) | bestever.f | stopflag' ... + message]); + if isoctave + strstop = stopflag(:); + else + strcat(stopflag(:), '.'); + end + strstop = stopflag(:); %strcat(stopflag(:), '.'); + disp([repmat(' ',1,6-floor(log10(counteval))) ... + num2str(counteval, '%6.0f') ': ' num2str(fmin, '%.11e') ' | ' ... + num2str(out.solutions.bestever.f, '%.11e') ' | ' ... + strstop{1:end}]); + if N < 102 + disp(['mean solution:' sprintf(' %+.1e', xmean)]); + disp(['std deviation:' sprintf(' %.1e', sigma*sqrt(diagC))]); + disp(sprintf('use plotcmaesdat.m for plotting the output at any time (option LogModulo must not be zero)')); + end + if exist('sfile', 'var') + disp(['Results saved in ' sfile]); + end + end + + out.arstopflags{irun} = stopflag; + if any(strcmp(stopflag, 'fitness')) ... + || any(strcmp(stopflag, 'maxfunevals')) ... + || any(strcmp(stopflag, 'stoptoresume')) ... + || any(strcmp(stopflag, 'manual')) + break; end - end - end - if countiter > 100 + 20 && savemodulo && ... - time.recording * countiter > 0.1 && ... % absolute time larger 0.1 second - time.recording > savetime * (time.nonoutput+time.recording) / 100 - savemodulo = floor(1.1 * savemodulo) + 1; - % disp('++savemodulo'); %qqq - end - end % if output - - % save everything - time.t3 = clock; - if ~isempty(stopflag) || time.saving < 0.05 * time.nonoutput || countiter == 100 - xmin = arxvalid(:, fitness.idx(1)); - fmin = fitness.raw(1); - if flgsaving && countiter > 2 - clear idx; % prevents error under octave - % -v6 : non-compressed non-unicode for version 6 and earlier - if ~isempty(strsaving) && ~isoctave - save('-mat', strsaving, opts.SaveFilename); % for inspection and possible restart - else - save('-mat', opts.SaveFilename); % for inspection and possible restart - end - time.saving = time.saving + time.c * max(0,etime(clock, time.t3)); - end - end - time.t0 = clock; - - % ----- end output generation ----- - -end % while, end generation loop - -% -------------------- Final Procedures ------------------------------- - -% Evaluate xmean and return best recent point in xmin -fmin = fitness.raw(1); -xmin = arxvalid(:, fitness.idx(1)); % Return best point of last generation. -if length(stopflag) > sum(strcmp(stopflag, 'stoptoresume')) % final stopping - out.solutions.mean.f = ... - feval(fitfun, xintobounds(xmean, lbounds, ubounds), varargin{:}); - counteval = counteval + 1; - out.solutions.mean.evals = counteval; - if out.solutions.mean.f < fitness.raw(1) - fmin = out.solutions.mean.f; - xmin = xintobounds(xmean, lbounds, ubounds); % Return xmean as best point - end - if out.solutions.mean.f < out.solutions.bestever.f - out.solutions.bestever = out.solutions.mean; % Return xmean as bestever point - out.solutions.bestever.x = xintobounds(xmean, lbounds, ubounds); - bestever = out.solutions.bestever; - end -end - -% Save everything and display final message -if flgsavingfinal - clear idx; % prevents error under octave - if ~isempty(strsaving) && ~isoctave - save('-mat', strsaving, opts.SaveFilename); % for inspection and possible restart - else - save('-mat', opts.SaveFilename); % for inspection and possible restart - end - message = [' (saved to ' opts.SaveFilename ')']; -else - message = []; -end - -if flgdisplay - disp(['#Fevals: f(returned x) | bestever.f | stopflag' ... - message]); - if isoctave - strstop = stopflag(:); - else - strcat(stopflag(:), '.'); - end - strstop = stopflag(:); %strcat(stopflag(:), '.'); - disp([repmat(' ',1,6-floor(log10(counteval))) ... - num2str(counteval, '%6.0f') ': ' num2str(fmin, '%.11e') ' | ' ... - num2str(out.solutions.bestever.f, '%.11e') ' | ' ... - strstop{1:end}]); - if N < 102 - disp(['mean solution:' sprintf(' %+.1e', xmean)]); - disp(['std deviation:' sprintf(' %.1e', sigma*sqrt(diagC))]); - disp(sprintf('use plotcmaesdat.m for plotting the output at any time (option LogModulo must not be zero)')); - end - if exist('sfile', 'var') - disp(['Results saved in ' sfile]); - end -end - - out.arstopflags{irun} = stopflag; - if any(strcmp(stopflag, 'fitness')) ... - || any(strcmp(stopflag, 'maxfunevals')) ... - || any(strcmp(stopflag, 'stoptoresume')) ... - || any(strcmp(stopflag, 'manual')) - break; - end end % while irun <= Restarts % --------------------------------------------------------------- @@ -1759,32 +1759,32 @@ function [x, idx] = xintobounds(x, lbounds, ubounds) % % x can be a column vector or a matrix consisting of column vectors % - if ~isempty(lbounds) +if ~isempty(lbounds) if length(lbounds) == 1 - idx = x < lbounds; - x(idx) = lbounds; + idx = x < lbounds; + x(idx) = lbounds; else - arbounds = repmat(lbounds, 1, size(x,2)); - idx = x < arbounds; - x(idx) = arbounds(idx); + arbounds = repmat(lbounds, 1, size(x,2)); + idx = x < arbounds; + x(idx) = arbounds(idx); end - else +else idx = 0; - end - if ~isempty(ubounds) +end +if ~isempty(ubounds) if length(ubounds) == 1 - idx2 = x > ubounds; - x(idx2) = ubounds; + idx2 = x > ubounds; + x(idx2) = ubounds; else - arbounds = repmat(ubounds, 1, size(x,2)); - idx2 = x > arbounds; - x(idx2) = arbounds(idx2); + arbounds = repmat(ubounds, 1, size(x,2)); + idx2 = x > arbounds; + x(idx2) = arbounds(idx2); end - else +else idx2 = 0; - end - idx = idx2-idx; - +end +idx = idx2-idx; + % --------------------------------------------------------------- % --------------------------------------------------------------- function opts=getoptions(inopts, defopts) @@ -1838,122 +1838,122 @@ function opts=getoptions(inopts, defopts) % if nargin < 2 || isempty(defopts) % no default options available - opts=inopts; - return; + opts=inopts; + return; elseif isempty(inopts) % empty inopts invoke default options - opts = defopts; - return; -elseif ~isstruct(defopts) % handle a single option value - if isempty(inopts) opts = defopts; - elseif ~isstruct(inopts) - opts = inopts; - else - error('Input options are a struct, while default options are not'); - end - return; + return; +elseif ~isstruct(defopts) % handle a single option value + if isempty(inopts) + opts = defopts; + elseif ~isstruct(inopts) + opts = inopts; + else + error('Input options are a struct, while default options are not'); + end + return; elseif ~isstruct(inopts) % no valid input options - error('The options need to be a struct or empty'); + error('The options need to be a struct or empty'); end - opts = defopts; % start from defopts - % if necessary overwrite opts fields by inopts values - defnames = fieldnames(defopts); - idxmatched = []; % indices of defopts that already matched - for name = fieldnames(inopts)' +opts = defopts; % start from defopts + % if necessary overwrite opts fields by inopts values +defnames = fieldnames(defopts); +idxmatched = []; % indices of defopts that already matched +for name = fieldnames(inopts)' name = name{1}; % name of i-th inopts-field if isoctave - for i = 1:size(defnames, 1) - idx(i) = strncmp(lower(defnames(i)), lower(name), length(name)); - end + for i = 1:size(defnames, 1) + idx(i) = strncmp(lower(defnames(i)), lower(name), length(name)); + end else - idx = strncmpi(defnames, name, length(name)); + idx = strncmpi(defnames, name, length(name)); end if sum(idx) > 1 - error(['option "' name '" is not an unambigous abbreviation. ' ... - 'Use opts=RMFIELD(opts, ''' name, ... - ''') to remove the field from the struct.']); + error(['option "' name '" is not an unambigous abbreviation. ' ... + 'Use opts=RMFIELD(opts, ''' name, ... + ''') to remove the field from the struct.']); end if sum(idx) == 1 - defname = defnames{find(idx)}; - if ismember(find(idx), idxmatched) - error(['input options match more than ones with "' ... - defname '". ' ... - 'Use opts=RMFIELD(opts, ''' name, ... - ''') to remove the field from the struct.']); - end - idxmatched = [idxmatched find(idx)]; - val = getfield(inopts, name); - % next line can replace previous line from MATLAB version 6.5.0 on and in octave - % val = inopts.(name); - if isstruct(val) % valid syntax only from version 6.5.0 - opts = setfield(opts, defname, ... - getoptions(val, getfield(defopts, defname))); - elseif isstruct(getfield(defopts, defname)) - % next three lines can replace previous three lines from MATLAB - % version 6.5.0 on - % opts.(defname) = ... - % getoptions(val, defopts.(defname)); - % elseif isstruct(defopts.(defname)) - warning(['option "' name '" disregarded (must be struct)']); - elseif ~isempty(val) % empty value: do nothing, i.e. stick to default - opts = setfield(opts, defnames{find(idx)}, val); - % next line can replace previous line from MATLAB version 6.5.0 on - % opts.(defname) = inopts.(name); - end + defname = defnames{find(idx)}; + if ismember(find(idx), idxmatched) + error(['input options match more than ones with "' ... + defname '". ' ... + 'Use opts=RMFIELD(opts, ''' name, ... + ''') to remove the field from the struct.']); + end + idxmatched = [idxmatched find(idx)]; + val = getfield(inopts, name); + % next line can replace previous line from MATLAB version 6.5.0 on and in octave + % val = inopts.(name); + if isstruct(val) % valid syntax only from version 6.5.0 + opts = setfield(opts, defname, ... + getoptions(val, getfield(defopts, defname))); + elseif isstruct(getfield(defopts, defname)) + % next three lines can replace previous three lines from MATLAB + % version 6.5.0 on + % opts.(defname) = ... + % getoptions(val, defopts.(defname)); + % elseif isstruct(defopts.(defname)) + warning(['option "' name '" disregarded (must be struct)']); + elseif ~isempty(val) % empty value: do nothing, i.e. stick to default + opts = setfield(opts, defnames{find(idx)}, val); + % next line can replace previous line from MATLAB version 6.5.0 on + % opts.(defname) = inopts.(name); + end else - warning(['option "' name '" disregarded (unknown field name)']); + warning(['option "' name '" disregarded (unknown field name)']); end - end +end % --------------------------------------------------------------- % --------------------------------------------------------------- function res=myeval(s) - if ischar(s) +if ischar(s) res = evalin('caller', s); - else +else res = s; - end - +end + % --------------------------------------------------------------- % --------------------------------------------------------------- function res=myevalbool(s) - if ~ischar(s) % s may not and cannot be empty +if ~ischar(s) % s may not and cannot be empty res = s; - else % evaluation string s +else % evaluation string s if strncmpi(lower(s), 'yes', 3) || strncmpi(s, 'on', 2) ... - || strncmpi(s, 'true', 4) || strncmp(s, '1 ', 2) - res = 1; + || strncmpi(s, 'true', 4) || strncmp(s, '1 ', 2) + res = 1; elseif strncmpi(s, 'no', 2) || strncmpi(s, 'off', 3) ... - || strncmpi(s, 'false', 5) || strncmp(s, '0 ', 2) - res = 0; + || strncmpi(s, 'false', 5) || strncmp(s, '0 ', 2) + res = 0; else - try res = evalin('caller', s); catch - error(['String value "' s '" cannot be evaluated']); - end - try res ~= 0; catch - error(['String value "' s '" cannot be evaluated reasonably']); - end + try res = evalin('caller', s); catch + error(['String value "' s '" cannot be evaluated']); + end + try res ~= 0; catch + error(['String value "' s '" cannot be evaluated reasonably']); + end end - end - +end + % --------------------------------------------------------------- % --------------------------------------------------------------- function res = isoctave % any hack to find out whether we are running octave - s = version; - res = 0; - if exist('fflush', 'builtin') && eval(s(1)) < 7 +s = version; +res = 0; +if exist('fflush', 'builtin') && eval(s(1)) < 7 res = 1; - end +end % --------------------------------------------------------------- % --------------------------------------------------------------- function flush - if isoctave +if isoctave feval('fflush', stdout); - end +end % --------------------------------------------------------------- % --------------------------------------------------------------- @@ -1961,8 +1961,8 @@ function flush % --------------------------------------------------------------- % --------------------------------------------------------------- function res=myrange(x) - res = max(x) - min(x); - +res = max(x) - min(x); + % --------------------------------------------------------------- % --------------------------------------------------------------- function res = myprctile(inar, perc, idx) @@ -1977,43 +1977,43 @@ flgtranspose = 0; % sizes if size(perc,1) > 1 - perc = perc'; - flgtranspose = 1; - if size(perc,1) > 1 - error('perc must not be a matrix'); - end + perc = perc'; + flgtranspose = 1; + if size(perc,1) > 1 + error('perc must not be a matrix'); + end end if size(inar, 1) > 1 && size(inar,2) > 1 - error('data inar must not be a matrix'); + error('data inar must not be a matrix'); end - + % sort inar if nargin < 3 || isempty(idx) - [sar idx] = sort(inar); + [sar idx] = sort(inar); else - sar = inar(idx); + sar = inar(idx); end res = []; for p = perc - if p <= 100*(0.5/N) - res(end+1) = sar(1); - elseif p >= 100*((N-0.5)/N) - res(end+1) = sar(N); - else - % find largest index smaller than required percentile - availablepercentiles = 100*((1:N)-0.5)/N; - i = max(find(p > availablepercentiles)); - % interpolate linearly - res(end+1) = sar(i) ... - + (sar(i+1)-sar(i))*(p - availablepercentiles(i)) ... - / (availablepercentiles(i+1) - availablepercentiles(i)); - - end + if p <= 100*(0.5/N) + res(end+1) = sar(1); + elseif p >= 100*((N-0.5)/N) + res(end+1) = sar(N); + else + % find largest index smaller than required percentile + availablepercentiles = 100*((1:N)-0.5)/N; + i = max(find(p > availablepercentiles)); + % interpolate linearly + res(end+1) = sar(i) ... + + (sar(i+1)-sar(i))*(p - availablepercentiles(i)) ... + / (availablepercentiles(i+1) - availablepercentiles(i)); + + end end if flgtranspose - res = res'; + res = res'; end @@ -2055,25 +2055,25 @@ function [s ranks rankDelta] = local_noisemeasurement(arf1, arf2, lamreev, theta %%% verify input argument sizes if size(arf1,1) ~= 1 - error('arf1 must be an 1xlambda array'); + error('arf1 must be an 1xlambda array'); elseif size(arf2,1) ~= 1 - error('arf2 must be an 1xsomething array'); + error('arf2 must be an 1xsomething array'); elseif size(arf1,2) < size(arf2,2) % not really necessary, but saver - error('arf2 must not be smaller than arf1 in length'); + error('arf2 must not be smaller than arf1 in length'); end lam = size(arf1, 2); if size(arf1,2) ~= size(arf2,2) - arf2(end+1:lam) = arf1((size(arf2,2)+1):lam); + arf2(end+1:lam) = arf1((size(arf2,2)+1):lam); end if nargin < 5 - cutlimit = inf; + cutlimit = inf; end %%% capture unusual values if any(diff(arf1) == 0) - % this will presumably interpreted as rank change, because - % sort(ones(...)) returns 1,2,3,... - warning([num2str(sum(diff(arf1)==0)) ' equal function values']); + % this will presumably interpreted as rank change, because + % sort(ones(...)) returns 1,2,3,... + warning([num2str(sum(diff(arf1)==0)) ' equal function values']); end %%% compute rank changes into rankDelta @@ -2086,12 +2086,12 @@ rankDelta = ranks(1,:) - ranks(2,:) - sign(ranks(1,:) - ranks(2,:)); %%% compute rank change limits using both ranks(1,...) and ranks(2,...) for i = 1:lamreev - sumlim(i) = ... - 0.5 * (... - myprctile(abs((1:2*lam-1) - (ranks(1,i) - (ranks(1,i)>ranks(2,i)))), ... - theta*50) ... - + myprctile(abs((1:2*lam-1) - (ranks(2,i) - (ranks(2,i)>ranks(1,i)))), ... - theta*50)); + sumlim(i) = ... + 0.5 * (... + myprctile(abs((1:2*lam-1) - (ranks(1,i) - (ranks(1,i)>ranks(2,i)))), ... + theta*50) ... + + myprctile(abs((1:2*lam-1) - (ranks(2,i) - (ranks(2,i)>ranks(1,i)))), ... + theta*50)); end %%% compute measurement @@ -2139,193 +2139,193 @@ function local_plotcmaesdat(figNb, filenameprefix, filenameextension, objectvarn manual_mode = 0; - if nargin < 1 || isempty(figNb) +if nargin < 1 || isempty(figNb) figNb = 325; - end - if nargin < 2 || isempty(filenameprefix) +end +if nargin < 2 || isempty(filenameprefix) filenameprefix = 'outcmaes'; - end - if nargin < 3 || isempty(filenameextension) +end +if nargin < 3 || isempty(filenameextension) filenameextension = '.dat'; - end - if nargin < 4 || isempty(objectvarname) +end +if nargin < 4 || isempty(objectvarname) objectvarname = 'xmean'; objectvarname = 'xrecentbest'; - end - % load data - d.x = load([filenameprefix objectvarname filenameextension]); - % d.x = load([filenameprefix 'xmean' filenameextension]); - % d.x = load([filenameprefix 'xrecentbest' filenameextension]); - d.f = load([filenameprefix 'fit' filenameextension]); - d.std = load([filenameprefix 'stddev' filenameextension]); - d.D = load([filenameprefix 'axlen' filenameextension]); - - % interpret entries in figNb for cutting out some data - if length(figNb) > 1 +end +% load data +d.x = load([filenameprefix objectvarname filenameextension]); +% d.x = load([filenameprefix 'xmean' filenameextension]); +% d.x = load([filenameprefix 'xrecentbest' filenameextension]); +d.f = load([filenameprefix 'fit' filenameextension]); +d.std = load([filenameprefix 'stddev' filenameextension]); +d.D = load([filenameprefix 'axlen' filenameextension]); + +% interpret entries in figNb for cutting out some data +if length(figNb) > 1 iend = inf; istart = figNb(2); if length(figNb) > 2 - iend = figNb(3); + iend = figNb(3); end figNb = figNb(1); d.x = d.x(d.x(:,1) >= istart & d.x(:,1) <= iend, :); d.f = d.f(d.f(:,1) >= istart & d.f(:,1) <= iend, :); d.std = d.std(d.std(:,1) >= istart & d.std(:,1) <= iend, :); d.D = d.D(d.D(:,1) >= istart & d.D(:,1) <= iend, :); - end +end - % decide for x-axis - iabscissa = 2; % 1== versus iterations, 2==versus fevals - if mod(figNb,100) == 1 +% decide for x-axis +iabscissa = 2; % 1== versus iterations, 2==versus fevals +if mod(figNb,100) == 1 iabscissa = 1; % a short hack - end - if iabscissa == 1 +end +if iabscissa == 1 xlab ='iterations'; - elseif iabscissa == 2 +elseif iabscissa == 2 xlab = 'function evaluations'; - end +end - if size(d.x, 2) < 1000 +if size(d.x, 2) < 1000 minxend = 1.03*d.x(end, iabscissa); - else +else minxend = 0; - end +end - % set up figure window - if manual_mode +% set up figure window +if manual_mode figure(figNb); % just create and raise the figure window - else +else if 1 < 3 && evalin('caller', 'iterplotted') == 0 && evalin('caller', 'irun') == 1 - figure(figNb); % incomment this, if figure raise in the beginning is not desired + figure(figNb); % incomment this, if figure raise in the beginning is not desired elseif ismember(figNb, findobj('Type', 'figure')) - set(0, 'CurrentFigure', figNb); % prevents raise of existing figure window + set(0, 'CurrentFigure', figNb); % prevents raise of existing figure window else - figure(figNb); + figure(figNb); end - end - - % plot fitness etc - foffset = 1e-99; - dfit = d.f(:,6)-min(d.f(:,6)); - [ignore idxbest] = min(dfit); - dfit(dfit<1e-98) = NaN; - subplot(2,2,1); hold off; - dd = abs(d.f(:,7:8)) + foffset; - dd(d.f(:,7:8)==0) = NaN; - semilogy(d.f(:,iabscissa), dd, '-k'); hold on; - % additional fitness data, for example constraints values - if size(d.f,2) > 8 +end + +% plot fitness etc +foffset = 1e-99; +dfit = d.f(:,6)-min(d.f(:,6)); +[ignore idxbest] = min(dfit); +dfit(dfit<1e-98) = NaN; +subplot(2,2,1); hold off; +dd = abs(d.f(:,7:8)) + foffset; +dd(d.f(:,7:8)==0) = NaN; +semilogy(d.f(:,iabscissa), dd, '-k'); hold on; +% additional fitness data, for example constraints values +if size(d.f,2) > 8 dd = abs(d.f(:,9:end)) + 10*foffset; % a hack - % dd(d.f(:,9:end)==0) = NaN; + % dd(d.f(:,9:end)==0) = NaN; semilogy(d.f(:,iabscissa), dd, '-m'); hold on; if size(d.f,2) > 12 - semilogy(d.f(:,iabscissa),abs(d.f(:,[7 8 11 13]))+foffset,'-k'); hold on; + semilogy(d.f(:,iabscissa),abs(d.f(:,[7 8 11 13]))+foffset,'-k'); hold on; end - end +end - idx = find(d.f(:,6)>1e-98); % positive values - if ~isempty(idx) % otherwise non-log plot gets hold +idx = find(d.f(:,6)>1e-98); % positive values +if ~isempty(idx) % otherwise non-log plot gets hold semilogy(d.f(idx,iabscissa), d.f(idx,6)+foffset, '.b'); hold on; - end - idx = find(d.f(:,6) < -1e-98); % negative values - if ~isempty(idx) +end +idx = find(d.f(:,6) < -1e-98); % negative values +if ~isempty(idx) semilogy(d.f(idx, iabscissa), abs(d.f(idx,6))+foffset,'.r'); hold on; - end - semilogy(d.f(:,iabscissa),abs(d.f(:,6))+foffset,'-b'); hold on; - semilogy(d.f(:,iabscissa),dfit,'-c'); hold on; - semilogy(d.f(:,iabscissa),(d.f(:,4)),'-r'); hold on; % AR - semilogy(d.std(:,iabscissa), [max(d.std(:,6:end)')' ... - min(d.std(:,6:end)')'], '-m'); % max,min std - maxval = max(d.std(end,6:end)); - minval = min(d.std(end,6:end)); - text(d.std(end,iabscissa), maxval, sprintf('%.0e', maxval)); - text(d.std(end,iabscissa), minval, sprintf('%.0e', minval)); - - semilogy(d.std(:,iabscissa),(d.std(:,3)),'-g'); % sigma - % plot best f - semilogy(d.f(idxbest,iabscissa),min(dfit),'*c'); hold on; - semilogy(d.f(idxbest,iabscissa),abs(d.f(idxbest,6))+foffset,'*r'); hold on; - - ax = axis; - ax(2) = max(minxend, ax(2)); - axis(ax); - - yannote = 10^(log10(ax(3)) + 0.05*(log10(ax(4))-log10(ax(3)))); - text(ax(1), yannote, ... - [ 'f=' num2str(d.f(end,6), '%.15g') ]); - - title('blue:abs(f), cyan:f-min(f), green:sigma, red:axis ratio'); - grid on; - - subplot(2,2,2); hold off; - plot(d.x(:,iabscissa), d.x(:,6:end),'-'); hold on; - ax = axis; - ax(2) = max(minxend, ax(2)); - axis(ax); - - % add some annotation lines - [ignore idx] = sort(d.x(end,6:end)); - % choose no more than 25 indices - idxs = round(linspace(1, size(d.x,2)-5, min(size(d.x,2)-5, 25))); - yy = repmat(NaN, 2, size(d.x,2)-5); - yy(1,:) = d.x(end, 6:end); - yy(2,idx(idxs)) = linspace(ax(3), ax(4), length(idxs)); - plot([d.x(end,iabscissa) ax(2)], yy, '-'); - plot(repmat(d.x(end,iabscissa),2), [ax(3) ax(4)], 'k-'); - for i = idx(idxs) +end +semilogy(d.f(:,iabscissa),abs(d.f(:,6))+foffset,'-b'); hold on; +semilogy(d.f(:,iabscissa),dfit,'-c'); hold on; +semilogy(d.f(:,iabscissa),(d.f(:,4)),'-r'); hold on; % AR +semilogy(d.std(:,iabscissa), [max(d.std(:,6:end)')' ... + min(d.std(:,6:end)')'], '-m'); % max,min std +maxval = max(d.std(end,6:end)); +minval = min(d.std(end,6:end)); +text(d.std(end,iabscissa), maxval, sprintf('%.0e', maxval)); +text(d.std(end,iabscissa), minval, sprintf('%.0e', minval)); + +semilogy(d.std(:,iabscissa),(d.std(:,3)),'-g'); % sigma + % plot best f +semilogy(d.f(idxbest,iabscissa),min(dfit),'*c'); hold on; +semilogy(d.f(idxbest,iabscissa),abs(d.f(idxbest,6))+foffset,'*r'); hold on; + +ax = axis; +ax(2) = max(minxend, ax(2)); +axis(ax); + +yannote = 10^(log10(ax(3)) + 0.05*(log10(ax(4))-log10(ax(3)))); +text(ax(1), yannote, ... + [ 'f=' num2str(d.f(end,6), '%.15g') ]); + +title('blue:abs(f), cyan:f-min(f), green:sigma, red:axis ratio'); +grid on; + +subplot(2,2,2); hold off; +plot(d.x(:,iabscissa), d.x(:,6:end),'-'); hold on; +ax = axis; +ax(2) = max(minxend, ax(2)); +axis(ax); + +% add some annotation lines +[ignore idx] = sort(d.x(end,6:end)); +% choose no more than 25 indices +idxs = round(linspace(1, size(d.x,2)-5, min(size(d.x,2)-5, 25))); +yy = repmat(NaN, 2, size(d.x,2)-5); +yy(1,:) = d.x(end, 6:end); +yy(2,idx(idxs)) = linspace(ax(3), ax(4), length(idxs)); +plot([d.x(end,iabscissa) ax(2)], yy, '-'); +plot(repmat(d.x(end,iabscissa),2), [ax(3) ax(4)], 'k-'); +for i = idx(idxs) text(ax(2), yy(2,i), ... ['x(' num2str(i) ')=' num2str(yy(1,i))]); - end - - lam = 'NA'; - if size(d.x, 1) > 1 && d.x(end, 1) > d.x(end-1, 1) +end + +lam = 'NA'; +if size(d.x, 1) > 1 && d.x(end, 1) > d.x(end-1, 1) lam = num2str((d.x(end, 2) - d.x(end-1, 2)) / (d.x(end, 1) - d.x(end-1, 1))); - end - title(['Object Variables (' num2str(size(d.x, 2)-5) ... - '-D, popsize~' lam ')']);grid on; - - subplot(2,2,3); hold off; semilogy(d.D(:,iabscissa), d.D(:,6:end), '-'); - ax = axis; - ax(2) = max(minxend, ax(2)); - axis(ax); - title('Principal Axes Lengths');grid on; - xlabel(xlab); - - subplot(2,2,4); hold off; - % semilogy(d.std(:,iabscissa), d.std(:,6:end), 'k-'); hold on; - % remove sigma from stds - d.std(:,6:end) = d.std(:,6:end) ./ (d.std(:,3) * ones(1,size(d.std,2)-5)); - semilogy(d.std(:,iabscissa), d.std(:,6:end), '-'); hold on; - if 11 < 3 % max and min std +end +title(['Object Variables (' num2str(size(d.x, 2)-5) ... + '-D, popsize~' lam ')']);grid on; + +subplot(2,2,3); hold off; semilogy(d.D(:,iabscissa), d.D(:,6:end), '-'); +ax = axis; +ax(2) = max(minxend, ax(2)); +axis(ax); +title('Principal Axes Lengths');grid on; +xlabel(xlab); + +subplot(2,2,4); hold off; +% semilogy(d.std(:,iabscissa), d.std(:,6:end), 'k-'); hold on; +% remove sigma from stds +d.std(:,6:end) = d.std(:,6:end) ./ (d.std(:,3) * ones(1,size(d.std,2)-5)); +semilogy(d.std(:,iabscissa), d.std(:,6:end), '-'); hold on; +if 11 < 3 % max and min std semilogy(d.std(:,iabscissa), [d.std(:,3).*max(d.std(:,6:end)')' ... d.std(:,3).*min(d.std(:,6:end)')'], '-m', 'linewidth', 2); maxval = max(d.std(end,6:end)); minval = min(d.std(end,6:end)); text(d.std(end,iabscissa), d.std(end,3)*maxval, sprintf('max=%.0e', maxval)); text(d.std(end,iabscissa), d.std(end,3)*minval, sprintf('min=%.0e', minval)); - end - ax = axis; - ax(2) = max(minxend, ax(2)); - axis(ax); - % add some annotation lines - [ignore idx] = sort(d.std(end,6:end)); - % choose no more than 25 indices - idxs = round(linspace(1, size(d.x,2)-5, min(size(d.x,2)-5, 25))); - yy = repmat(NaN, 2, size(d.std,2)-5); - yy(1,:) = d.std(end, 6:end); - yy(2,idx(idxs)) = logspace(log10(ax(3)), log10(ax(4)), length(idxs)); - semilogy([d.std(end,iabscissa) ax(2)], yy, '-'); - semilogy(repmat(d.std(end,iabscissa),2), [ax(3) ax(4)], 'k-'); - for i = idx(idxs) +end +ax = axis; +ax(2) = max(minxend, ax(2)); +axis(ax); +% add some annotation lines +[ignore idx] = sort(d.std(end,6:end)); +% choose no more than 25 indices +idxs = round(linspace(1, size(d.x,2)-5, min(size(d.x,2)-5, 25))); +yy = repmat(NaN, 2, size(d.std,2)-5); +yy(1,:) = d.std(end, 6:end); +yy(2,idx(idxs)) = logspace(log10(ax(3)), log10(ax(4)), length(idxs)); +semilogy([d.std(end,iabscissa) ax(2)], yy, '-'); +semilogy(repmat(d.std(end,iabscissa),2), [ax(3) ax(4)], 'k-'); +for i = idx(idxs) text(ax(2), yy(2,i), [' ' num2str(i)]); - end - title('Standard Deviations in Coordinates divided by sigma');grid on; - xlabel(xlab); +end +title('Standard Deviations in Coordinates divided by sigma');grid on; +xlabel(xlab); - if figNb ~= 324 +if figNb ~= 324 % zoom on; % does not work in Octave - end - drawnow; +end +drawnow; % --------------------------------------------------------------- % --------------- TEST OBJECTIVE FUNCTIONS ---------------------- @@ -2337,24 +2337,24 @@ function f=fjens1(x) % % use population size about 2*N % - f = sum((x>0) .* x.^1, 1); - if any(any(x<0)) +f = sum((x>0) .* x.^1, 1); +if any(any(x<0)) idx = sum(x < 0, 1) > 0; f(idx) = 1e3; -% f = f + 1e3 * sum(x<0, 1); -% f = f + 10 * sum((x<0) .* x.^2, 1); + % f = f + 1e3 * sum(x<0, 1); + % f = f + 10 * sum((x<0) .* x.^2, 1); f(idx) = f(idx) + 1e-3*abs(randn(1,sum(idx))); -% f(idx) = NaN; - end + % f(idx) = NaN; +end function f=fsphere(x) - f = sum(x.^2,1); +f = sum(x.^2,1); function f=fmax(x) - f = max(abs(x), [], 1); +f = max(abs(x), [], 1); function f=fssphere(x) - f=sqrt(sum(x.^2, 1)); +f=sqrt(sum(x.^2, 1)); % lb = -0.512; ub = 512; % xfeas = x; @@ -2362,99 +2362,99 @@ function f=fssphere(x) % xfeas(x>ub) = ub; % f=sum(xfeas.^2, 1); % f = f + 1e-9 * sum((xfeas-x).^2); - + function f=fspherenoise(x, Nevals) - if nargin < 2 || isempty(Nevals) +if nargin < 2 || isempty(Nevals) Nevals = 1; - end - [N,popsi] = size(x); +end +[N,popsi] = size(x); % x = x .* (1 + 0.3e-0 * randn(N, popsi)/(2*N)); % actuator noise - fsum = 10.^(0*(0:N-1)/(N-1)) * x.^2; +fsum = 10.^(0*(0:N-1)/(N-1)) * x.^2; % f = 0*rand(1,1) ... % + fsum ... % + fsum .* (2*randn(1,popsi) ./ randn(1,popsi).^0 / (2*N)) ... % + 1*fsum.^0.9 .* 2*randn(1,popsi) / (2*N); % % f = fsum .* exp(0.1*randn(1,popsi)); - f = fsum .* (1 + (10/(N+10)/sqrt(Nevals))*randn(1,popsi)); +f = fsum .* (1 + (10/(N+10)/sqrt(Nevals))*randn(1,popsi)); % f = fsum .* (1 + (0.1/N)*randn(1,popsi)./randn(1,popsi).^1); - idx = rand(1,popsi) < 0.0; - if sum(idx) > 0 +idx = rand(1,popsi) < 0.0; +if sum(idx) > 0 f(idx) = f(idx) + 1e3*exp(randn(1,sum(idx))); - end - +end + function f=fmixranks(x) - N = size(x,1); - f=(10.^(0*(0:(N-1))/(N-1))*x.^2).^0.5; - if size(x, 2) > 1 % compute ranks, if it is a population +N = size(x,1); +f=(10.^(0*(0:(N-1))/(N-1))*x.^2).^0.5; +if size(x, 2) > 1 % compute ranks, if it is a population [ignore, idx] = sort(f); [ignore, ranks] = sort(idx); k = 9; % number of solutions randomly permuted, lambda/2-1 % works still quite well (two time slower) for i = k+1:k-0:size(x,2) - idx(i-k+(1:k)) = idx(i-k+randperm(k)); + idx(i-k+(1:k)) = idx(i-k+randperm(k)); end %disp([ranks' f']) [ignore, ranks] = sort(idx); %disp([ranks' f']) %pause f = ranks+1e-9*randn(1,1); - end - +end + function f = fsphereoneax(x) - f = x(1)^2; - f = mean(x)^2; - +f = x(1)^2; +f = mean(x)^2; + function f=frandsphere(x) - N = size(x,1); - idx = ceil(N*rand(7,1)); - f=sum(x(idx).^2); +N = size(x,1); +idx = ceil(N*rand(7,1)); +f=sum(x(idx).^2); function f=fspherelb0(x, M) % lbound at zero for 1:M needed - if nargin < 2 M = 0; end - N = size(x,1); - % M active bounds, f_i = 1 for x = 0 - f = -M + sum((x(1:M) + 1).^2); - f = f + sum(x(M+1:N).^2); - +if nargin < 2 M = 0; end +N = size(x,1); +% M active bounds, f_i = 1 for x = 0 +f = -M + sum((x(1:M) + 1).^2); +f = f + sum(x(M+1:N).^2); + function f=fspherehull(x) - % Patton, Dexter, Goodman, Punch - % in -500..500 - % spherical ridge through zeros(N,1) - % worst case start point seems x = 2*100*sqrt(N) - % and small step size - N = size(x,1); - f = norm(x) + (norm(x-100*sqrt(N)) - 100*N)^2; - +% Patton, Dexter, Goodman, Punch +% in -500..500 +% spherical ridge through zeros(N,1) +% worst case start point seems x = 2*100*sqrt(N) +% and small step size +N = size(x,1); +f = norm(x) + (norm(x-100*sqrt(N)) - 100*N)^2; + function f=fellilb0(x, idxM, scal) % lbound at zero for 1:M needed - N = size(x,1); - if nargin < 3 || isempty(scal) +N = size(x,1); +if nargin < 3 || isempty(scal) scal = 100; - end - scale=scal.^((0:N-1)/(N-1)); - if nargin < 2 || isempty(idxM) +end +scale=scal.^((0:N-1)/(N-1)); +if nargin < 2 || isempty(idxM) idxM = 1:N; - end - %scale(N) = 1e0; - % M active bounds - xopt = 0.1; - x(idxM) = x(idxM) + xopt; - f = scale.^2*x.^2; - f = f - sum((xopt*scale(idxM)).^2); +end +%scale(N) = 1e0; +% M active bounds +xopt = 0.1; +x(idxM) = x(idxM) + xopt; +f = scale.^2*x.^2; +f = f - sum((xopt*scale(idxM)).^2); % f = exp(f) - 1; % f = log10(f+1e-19) + 19; - f = f + 1e-19; - +f = f + 1e-19; + function f=fcornersphere(x) - w = ones(size(x,1)); - w(1) = 2.5; w(2)=2.5; - idx = x < 0; - f = sum(x(idx).^2); - idx = x > 0; - f = f + 2^2*sum(w(idx).*x(idx).^2); - +w = ones(size(x,1)); +w(1) = 2.5; w(2)=2.5; +idx = x < 0; +f = sum(x(idx).^2); +idx = x > 0; +f = f + 2^2*sum(w(idx).*x(idx).^2); + function f=fsectorsphere(x, scal) % % This is deceptive for cumulative sigma control CSA in large dimension: @@ -2467,407 +2467,407 @@ function f=fsectorsphere(x, scal) % reasonable, but I do not know better alternatives. In particular: % TPA takes longer to converge than CSA when the latter still works. % - if nargin < 2 || isempty (scal) +if nargin < 2 || isempty (scal) scal = 1e3; - end - f=sum(x.^2,1); - idx = x<0; - f = f + (scal^2 - 1) * sum((idx.*x).^2,1); - if 11 < 3 +end +f=sum(x.^2,1); +idx = x<0; +f = f + (scal^2 - 1) * sum((idx.*x).^2,1); +if 11 < 3 idxpen = find(f>1e9); if ~isempty(idxpen) - f(idxpen) = f(idxpen) + 1e8*sum(x(:,idxpen).^2,1); + f(idxpen) = f(idxpen) + 1e8*sum(x(:,idxpen).^2,1); end - end - +end + function f=fstepsphere(x, scal) - if nargin < 2 || isempty (scal) +if nargin < 2 || isempty (scal) scal = 1e0; - end - N = size(x,1); - f=1e-11+sum(scal.^((0:N-1)/(N-1))*floor(x+0.5).^2); - f=1e-11+sum(floor(scal.^((0:N-1)/(N-1))'.*x+0.5).^2); +end +N = size(x,1); +f=1e-11+sum(scal.^((0:N-1)/(N-1))*floor(x+0.5).^2); +f=1e-11+sum(floor(scal.^((0:N-1)/(N-1))'.*x+0.5).^2); % f=1e-11+sum(floor(x+0.5).^2); function f=fstep(x) - % in -5.12..5.12 (bounded) - N = size(x,1); - f=1e-11+6*N+sum(floor(x)); +% in -5.12..5.12 (bounded) +N = size(x,1); +f=1e-11+6*N+sum(floor(x)); function f=flnorm(x, scal, e) if nargin < 2 || isempty(scal) - scal = 1; + scal = 1; end if nargin < 3 || isempty(e) - e = 1; + e = 1; end if e==inf - f = max(abs(x)); + f = max(abs(x)); else - N = size(x,1); - scale = scal.^((0:N-1)/(N-1))'; - f=sum(abs(scale.*x).^e); + N = size(x,1); + scale = scal.^((0:N-1)/(N-1))'; + f=sum(abs(scale.*x).^e); end function f=fneumaier3(x) - % in -n^2..n^2 - % x^*-i = i(n+1-i) - N = size(x,1); +% in -n^2..n^2 +% x^*-i = i(n+1-i) +N = size(x,1); % f = N*(N+4)*(N-1)/6 + sum((x-1).^2) - sum(x(1:N-1).*x(2:N)); - f = sum((x-1).^2) - sum(x(1:N-1).*x(2:N)); +f = sum((x-1).^2) - sum(x(1:N-1).*x(2:N)); function f = fmaxmindist(y) - % y in [-1,1], y(1:2) is first point on a plane, y(3:4) second etc - % points best - % 5 1.4142 - % 8 1.03527618 - % 10 0.842535997 - % 20 0.5997 - pop = size(y,2); - N = size(y,1)/2; - f = []; - for ipop = 1:pop +% y in [-1,1], y(1:2) is first point on a plane, y(3:4) second etc +% points best +% 5 1.4142 +% 8 1.03527618 +% 10 0.842535997 +% 20 0.5997 +pop = size(y,2); +N = size(y,1)/2; +f = []; +for ipop = 1:pop if any(abs(y(:,ipop)) > 1) - f(ipop) = NaN; + f(ipop) = NaN; else - x = reshape(y(:,ipop), [2, N]); - f(ipop) = inf; - for i = 1:N - f(ipop) = min(f(ipop), min(sqrt(sum((x(:,[1:i-1 i+1:N]) - repmat(x(:,i), 1, N-1)).^2, 1)))); - end + x = reshape(y(:,ipop), [2, N]); + f(ipop) = inf; + for i = 1:N + f(ipop) = min(f(ipop), min(sqrt(sum((x(:,[1:i-1 i+1:N]) - repmat(x(:,i), 1, N-1)).^2, 1)))); + end end - end - f = -f; +end +f = -f; function f=fchangingsphere(x) - N = size(x,1); - global scale_G; global count_G; if isempty(count_G) count_G=-1; end - count_G = count_G+1; - if mod(count_G,10) == 0 +N = size(x,1); +global scale_G; global count_G; if isempty(count_G) count_G=-1; end +count_G = count_G+1; +if mod(count_G,10) == 0 scale_G = 10.^(2*rand(1,N)); - end - %disp(scale(1)); - f = scale_G*x.^2; - +end +%disp(scale(1)); +f = scale_G*x.^2; + function f= flogsphere(x) - f = 1-exp(-sum(x.^2)); - +f = 1-exp(-sum(x.^2)); + function f= fexpsphere(x) - f = exp(sum(x.^2)) - 1; - +f = exp(sum(x.^2)) - 1; + function f=fbaluja(x) - % in [-0.16 0.16] - y = x(1); - for i = 2:length(x) +% in [-0.16 0.16] +y = x(1); +for i = 2:length(x) y(i) = x(i) + y(i-1); - end - f = 1e5 - 1/(1e-5 + sum(abs(y))); +end +f = 1e5 - 1/(1e-5 + sum(abs(y))); function f=fschwefel(x) - f = 0; - for i = 1:size(x,1), +f = 0; +for i = 1:size(x,1), f = f+sum(x(1:i))^2; - end +end function f=fcigar(x, ar) - if nargin < 2 || isempty(ar) +if nargin < 2 || isempty(ar) ar = 1e3; - end - f = x(1,:).^2 + ar^2*sum(x(2:end,:).^2,1); - +end +f = x(1,:).^2 + ar^2*sum(x(2:end,:).^2,1); + function f=fcigtab(x) - f = x(1,:).^2 + 1e8*x(end,:).^2 + 1e4*sum(x(2:(end-1),:).^2, 1); - +f = x(1,:).^2 + 1e8*x(end,:).^2 + 1e4*sum(x(2:(end-1),:).^2, 1); + function f=ftablet(x) - f = 1e6*x(1,:).^2 + sum(x(2:end,:).^2, 1); +f = 1e6*x(1,:).^2 + sum(x(2:end,:).^2, 1); function f=felli(x, lgscal, expon, expon2) - % lgscal: log10(axis ratio) - % expon: x_i^expon, sphere==2 - N = size(x,1); if N < 2 error('dimension must be greater one'); end +% lgscal: log10(axis ratio) +% expon: x_i^expon, sphere==2 +N = size(x,1); if N < 2 error('dimension must be greater one'); end % x = x - repmat(-0.5+(1:N)',1,size(x,2)); % optimum in 1:N - if nargin < 2 || isempty(lgscal), lgscal = 3; end - if nargin < 3 || isempty(expon), expon = 2; end - if nargin < 4 || isempty(expon2), expon2 = 1; end +if nargin < 2 || isempty(lgscal), lgscal = 3; end +if nargin < 3 || isempty(expon), expon = 2; end +if nargin < 4 || isempty(expon2), expon2 = 1; end - f=((10^(lgscal*expon)).^((0:N-1)/(N-1)) * abs(x).^expon).^(1/expon2); +f=((10^(lgscal*expon)).^((0:N-1)/(N-1)) * abs(x).^expon).^(1/expon2); % if rand(1,1) > 0.015 % f = NaN; % end % f = f + randn(size(f)); function f=fellitest(x) - beta = 0.9; - N = size(x,1); - f = (1e6.^((0:(N-1))/(N-1))).^beta * (x.^2).^beta; +beta = 0.9; +N = size(x,1); +f = (1e6.^((0:(N-1))/(N-1))).^beta * (x.^2).^beta; + - function f=fellii(x, scal) - N = size(x,1); if N < 2 error('dimension must be greater one'); end - if nargin < 2 +N = size(x,1); if N < 2 error('dimension must be greater one'); end +if nargin < 2 scal = 1; - end - f= (scal*(1:N)).^2 * (x).^2; +end +f= (scal*(1:N)).^2 * (x).^2; function f=fellirot(x) - N = size(x,1); - global ORTHOGONALCOORSYSTEM_G - if isempty(ORTHOGONALCOORSYSTEM_G) ... - || length(ORTHOGONALCOORSYSTEM_G) < N ... - || isempty(ORTHOGONALCOORSYSTEM_G{N}) +N = size(x,1); +global ORTHOGONALCOORSYSTEM_G +if isempty(ORTHOGONALCOORSYSTEM_G) ... + || length(ORTHOGONALCOORSYSTEM_G) < N ... + || isempty(ORTHOGONALCOORSYSTEM_G{N}) coordinatesystem(N); - end - f = felli(ORTHOGONALCOORSYSTEM_G{N}*x); - +end +f = felli(ORTHOGONALCOORSYSTEM_G{N}*x); + function f=frot(x, fun, varargin) - N = size(x,1); - global ORTHOGONALCOORSYSTEM_G - if isempty(ORTHOGONALCOORSYSTEM_G) ... - || length(ORTHOGONALCOORSYSTEM_G) < N ... - || isempty(ORTHOGONALCOORSYSTEM_G{N}) +N = size(x,1); +global ORTHOGONALCOORSYSTEM_G +if isempty(ORTHOGONALCOORSYSTEM_G) ... + || length(ORTHOGONALCOORSYSTEM_G) < N ... + || isempty(ORTHOGONALCOORSYSTEM_G{N}) coordinatesystem(N); - end - f = feval(fun, ORTHOGONALCOORSYSTEM_G{N}*x, varargin{:}); - +end +f = feval(fun, ORTHOGONALCOORSYSTEM_G{N}*x, varargin{:}); + function coordinatesystem(N) - if nargin < 1 || isempty(N) +if nargin < 1 || isempty(N) arN = 2:30; - else +else arN = N; - end - global ORTHOGONALCOORSYSTEM_G - ORTHOGONALCOORSYSTEM_G{1} = 1; - for N = arN +end +global ORTHOGONALCOORSYSTEM_G +ORTHOGONALCOORSYSTEM_G{1} = 1; +for N = arN ar = randn(N,N); for i = 1:N - for j = 1:i-1 - ar(:,i) = ar(:,i) - ar(:,i)'*ar(:,j) * ar(:,j); - end - ar(:,i) = ar(:,i) / norm(ar(:,i)); + for j = 1:i-1 + ar(:,i) = ar(:,i) - ar(:,i)'*ar(:,j) * ar(:,j); + end + ar(:,i) = ar(:,i) / norm(ar(:,i)); end ORTHOGONALCOORSYSTEM_G{N} = ar; - end +end function f=fplane(x) - f=x(1); +f=x(1); function f=ftwoaxes(x) - f = sum(x(1:floor(end/2),:).^2, 1) + 1e6*sum(x(floor(1+end/2):end,:).^2, 1); +f = sum(x(1:floor(end/2),:).^2, 1) + 1e6*sum(x(floor(1+end/2):end,:).^2, 1); function f=fparabR(x) - f = -x(1,:) + 100*sum(x(2:end,:).^2,1); +f = -x(1,:) + 100*sum(x(2:end,:).^2,1); function f=fsharpR(x) - f = abs(-x(1, :)).^2 + 100 * sqrt(sum(x(2:end,:).^2, 1)); - +f = abs(-x(1, :)).^2 + 100 * sqrt(sum(x(2:end,:).^2, 1)); + function f=frosen(x) - if size(x,1) < 2 error('dimension must be greater one'); end - N = size(x,1); - popsi = size(x,2); - f = 1e2*sum((x(1:end-1,:).^2 - x(2:end,:)).^2,1) + sum((x(1:end-1,:)-1).^2,1); - % f = f + f^0.9 .* (2*randn(1,popsi) ./ randn(1,popsi).^0 / (2*N)); +if size(x,1) < 2 error('dimension must be greater one'); end +N = size(x,1); +popsi = size(x,2); +f = 1e2*sum((x(1:end-1,:).^2 - x(2:end,:)).^2,1) + sum((x(1:end-1,:)-1).^2,1); +% f = f + f^0.9 .* (2*randn(1,popsi) ./ randn(1,popsi).^0 / (2*N)); function f=frosenlin(x) - if size(x,1) < 2 error('dimension must be greater one'); end +if size(x,1) < 2 error('dimension must be greater one'); end - x_org = x; - x(x>30) = 30; - x(x<-30) = -30; +x_org = x; +x(x>30) = 30; +x(x<-30) = -30; - f = 1e2*sum(-(x(1:end-1,:).^2 - x(2:end,:)),1) + ... - sum((x(1:end-1,:)-1).^2,1); +f = 1e2*sum(-(x(1:end-1,:).^2 - x(2:end,:)),1) + ... + sum((x(1:end-1,:)-1).^2,1); - f = f + sum((x-x_org).^2,1); +f = f + sum((x-x_org).^2,1); % f(any(abs(x)>30,1)) = NaN; function f=frosenrot(x) - N = size(x,1); - global ORTHOGONALCOORSYSTEM_G - if isempty(ORTHOGONALCOORSYSTEM_G) ... - || length(ORTHOGONALCOORSYSTEM_G) < N ... - || isempty(ORTHOGONALCOORSYSTEM_G{N}) +N = size(x,1); +global ORTHOGONALCOORSYSTEM_G +if isempty(ORTHOGONALCOORSYSTEM_G) ... + || length(ORTHOGONALCOORSYSTEM_G) < N ... + || isempty(ORTHOGONALCOORSYSTEM_G{N}) coordinatesystem(N); - end - f = frosen(ORTHOGONALCOORSYSTEM_G{N}*x); +end +f = frosen(ORTHOGONALCOORSYSTEM_G{N}*x); function f=frosenmodif(x) - f = 74 + 100*(x(2)-x(1)^2)^2 + (1-x(1))^2 ... - - 400*exp(-sum((x+1).^2)/2/0.05); - +f = 74 + 100*(x(2)-x(1)^2)^2 + (1-x(1))^2 ... + - 400*exp(-sum((x+1).^2)/2/0.05); + function f=fschwefelrosen1(x) - % in [-10 10] - f=sum((x.^2-x(1)).^2 + (x-1).^2); - +% in [-10 10] +f=sum((x.^2-x(1)).^2 + (x-1).^2); + function f=fschwefelrosen2(x) - % in [-10 10] - f=sum((x(2:end).^2-x(1)).^2 + (x(2:end)-1).^2); +% in [-10 10] +f=sum((x(2:end).^2-x(1)).^2 + (x(2:end)-1).^2); function f=fdiffpow(x) - [N popsi] = size(x); if N < 2 error('dimension must be greater one'); end +[N popsi] = size(x); if N < 2 error('dimension must be greater one'); end - f = sum(abs(x).^repmat(2+10*(0:N-1)'/(N-1), 1, popsi), 1); - f = sqrt(f); +f = sum(abs(x).^repmat(2+10*(0:N-1)'/(N-1), 1, popsi), 1); +f = sqrt(f); function f=fabsprod(x) - f = sum(abs(x),1) + prod(abs(x),1); +f = sum(abs(x),1) + prod(abs(x),1); function f=ffloor(x) - f = sum(floor(x+0.5).^2,1); +f = sum(floor(x+0.5).^2,1); function f=fmaxx(x) - f = max(abs(x), [], 1); +f = max(abs(x), [], 1); %%% Multimodal functions function f=fbirastrigin(x) % todo: the volume needs to be a constant - N = size(x,1); - idx = (sum(x, 1) < 0.5*N); % global optimum - f = zeros(1,size(x,2)); - f(idx) = 10*(N-sum(cos(2*pi*x(:,idx)),1)) + sum(x(:,idx).^2,1); - idx = ~idx; - f(idx) = 0.1 + 10*(N-sum(cos(2*pi*(x(:,idx)-2)),1)) + sum((x(:,idx)-2).^2,1); +N = size(x,1); +idx = (sum(x, 1) < 0.5*N); % global optimum +f = zeros(1,size(x,2)); +f(idx) = 10*(N-sum(cos(2*pi*x(:,idx)),1)) + sum(x(:,idx).^2,1); +idx = ~idx; +f(idx) = 0.1 + 10*(N-sum(cos(2*pi*(x(:,idx)-2)),1)) + sum((x(:,idx)-2).^2,1); function f=fackley(x) - % -32.768..32.768 - % Adding a penalty outside the interval is recommended, - % because for large step sizes, fackley imposes like frand - % - N = size(x,1); - f = 20-20*exp(-0.2*sqrt(sum(x.^2)/N)); - f = f + (exp(1) - exp(sum(cos(2*pi*x))/N)); - % add penalty outside the search interval - f = f + sum((x(x>32.768)-32.768).^2) + sum((x(x<-32.768)+32.768).^2); - +% -32.768..32.768 +% Adding a penalty outside the interval is recommended, +% because for large step sizes, fackley imposes like frand +% +N = size(x,1); +f = 20-20*exp(-0.2*sqrt(sum(x.^2)/N)); +f = f + (exp(1) - exp(sum(cos(2*pi*x))/N)); +% add penalty outside the search interval +f = f + sum((x(x>32.768)-32.768).^2) + sum((x(x<-32.768)+32.768).^2); + function f = fbohachevsky(x) - % -15..15 - f = sum(x(1:end-1).^2 + 2 * x(2:end).^2 - 0.3 * cos(3*pi*x(1:end-1)) ... - - 0.4 * cos(4*pi*x(2:end)) + 0.7); - +% -15..15 +f = sum(x(1:end-1).^2 + 2 * x(2:end).^2 - 0.3 * cos(3*pi*x(1:end-1)) ... + - 0.4 * cos(4*pi*x(2:end)) + 0.7); + function f=fconcentric(x) - % in +-600 - s = sum(x.^2); - f = s^0.25 * (sin(50*s^0.1)^2 + 1); +% in +-600 +s = sum(x.^2); +f = s^0.25 * (sin(50*s^0.1)^2 + 1); function f=fgriewank(x) - % in [-600 600] - [N, P] = size(x); - f = 1 - prod(cos(x'./sqrt(1:N))) + sum(x.^2)/4e3; - scale = repmat(sqrt(1:N)', 1, P); - f = 1 - prod(cos(x./scale), 1) + sum(x.^2, 1)/4e3; - % f = f + 1e4*sum(x(abs(x)>5).^2); - % if sum(x(abs(x)>5).^2) > 0 - % f = 1e4 * sum(x(abs(x)>5).^2) + 1e8 * sum(x(x>5)).^2; - % end +% in [-600 600] +[N, P] = size(x); +f = 1 - prod(cos(x'./sqrt(1:N))) + sum(x.^2)/4e3; +scale = repmat(sqrt(1:N)', 1, P); +f = 1 - prod(cos(x./scale), 1) + sum(x.^2, 1)/4e3; +% f = f + 1e4*sum(x(abs(x)>5).^2); +% if sum(x(abs(x)>5).^2) > 0 +% f = 1e4 * sum(x(abs(x)>5).^2) + 1e8 * sum(x(x>5)).^2; +% end function f=fgriewrosen(x) % F13 or F8F2 - [N, P] = size(x); - scale = repmat(sqrt(1:N)', 1, P); - y = [x(2:end,:); x(1,:)]; - x = 100 * (x.^2 - y) + (x - 1).^2; % Rosenbrock part - f = 1 - prod(cos(x./scale), 1) + sum(x.^2, 1)/4e3; - f = sum(1 - cos(x) + x.^2/4e3, 1); +[N, P] = size(x); +scale = repmat(sqrt(1:N)', 1, P); +y = [x(2:end,:); x(1,:)]; +x = 100 * (x.^2 - y) + (x - 1).^2; % Rosenbrock part +f = 1 - prod(cos(x./scale), 1) + sum(x.^2, 1)/4e3; +f = sum(1 - cos(x) + x.^2/4e3, 1); function f=fspallpseudorastrigin(x, scal, skewfac, skewstart, amplitude) % by default multi-modal about between -30 and 30 - if nargin < 5 || isempty(amplitude) +if nargin < 5 || isempty(amplitude) amplitude = 40; - end - if nargin < 4 || isempty(skewstart) +end +if nargin < 4 || isempty(skewstart) skewstart = 0; - end - if nargin < 3 || isempty(skewfac) +end +if nargin < 3 || isempty(skewfac) skewfac = 1; - end - if nargin < 2 || isempty(scal) +end +if nargin < 2 || isempty(scal) scal = 1; - end - N = size(x,1); - scale = 1; - if N > 1 +end +N = size(x,1); +scale = 1; +if N > 1 scale=scal.^((0:N-1)'/(N-1)); - end - % simple version: - % f = amplitude*(N - sum(cos(2*pi*(scale.*x)))) + sum((scale.*x).^2); - - % skew version: - y = repmat(scale, 1, size(x,2)) .* x; - idx = find(x > skewstart); - if ~isempty(idx) +end +% simple version: +% f = amplitude*(N - sum(cos(2*pi*(scale.*x)))) + sum((scale.*x).^2); + +% skew version: +y = repmat(scale, 1, size(x,2)) .* x; +idx = find(x > skewstart); +if ~isempty(idx) y(idx) = skewfac*y(idx); - end - f = amplitude * (0*N-prod(cos((2*pi)^0*y),1)) + 0.05 * sum(y.^2,1) ... - + randn(1,1); +end +f = amplitude * (0*N-prod(cos((2*pi)^0*y),1)) + 0.05 * sum(y.^2,1) ... + + randn(1,1); function f=frastrigin(x, scal, skewfac, skewstart, amplitude) % by default multi-modal about between -30 and 30 - if nargin < 5 || isempty(amplitude) +if nargin < 5 || isempty(amplitude) amplitude = 10; - end - if nargin < 4 || isempty(skewstart) +end +if nargin < 4 || isempty(skewstart) skewstart = 0; - end - if nargin < 3 || isempty(skewfac) +end +if nargin < 3 || isempty(skewfac) skewfac = 1; - end - if nargin < 2 || isempty(scal) +end +if nargin < 2 || isempty(scal) scal = 1; - end - N = size(x,1); - scale = 1; - if N > 1 +end +N = size(x,1); +scale = 1; +if N > 1 scale=scal.^((0:N-1)'/(N-1)); - end - % simple version: - % f = amplitude*(N - sum(cos(2*pi*(scale.*x)))) + sum((scale.*x).^2); - - % skew version: - y = repmat(scale, 1, size(x,2)) .* x; - idx = find(x > skewstart); - % idx = intersect(idx, 2:2:10); - if ~isempty(idx) +end +% simple version: +% f = amplitude*(N - sum(cos(2*pi*(scale.*x)))) + sum((scale.*x).^2); + +% skew version: +y = repmat(scale, 1, size(x,2)) .* x; +idx = find(x > skewstart); +% idx = intersect(idx, 2:2:10); +if ~isempty(idx) y(idx) = skewfac*y(idx); - end - f = amplitude * (N-sum(cos(2*pi*y),1)) + sum(y.^2,1); - +end +f = amplitude * (N-sum(cos(2*pi*y),1)) + sum(y.^2,1); + function f=frastriginmax(x) - N = size(x,1); - f = (N/20)*807.06580387678 - (10 * (N-sum(cos(2*pi*x),1)) + sum(x.^2,1)); - f(any(abs(x) > 5.12)) = 1e2*N; +N = size(x,1); +f = (N/20)*807.06580387678 - (10 * (N-sum(cos(2*pi*x),1)) + sum(x.^2,1)); +f(any(abs(x) > 5.12)) = 1e2*N; function f = fschaffer(x) - % -100..100 - N = size(x,1); - s = x(1:N-1,:).^2 + x(2:N,:).^2; - f = sum(s.^0.25 .* (sin(50*s.^0.1).^2+1), 1); +% -100..100 +N = size(x,1); +s = x(1:N-1,:).^2 + x(2:N,:).^2; +f = sum(s.^0.25 .* (sin(50*s.^0.1).^2+1), 1); function f=fschwefelmult(x) - % -500..500 - % - N = size(x,1); - f = - sum(x.*sin(sqrt(abs(x))), 1); - f = 418.9829*N - 1.27275661e-5*N - sum(x.*sin(sqrt(abs(x))), 1); - % penalty term - f = f + 1e4*sum((abs(x)>500) .* (abs(x)-500).^2, 1); - +% -500..500 +% +N = size(x,1); +f = - sum(x.*sin(sqrt(abs(x))), 1); +f = 418.9829*N - 1.27275661e-5*N - sum(x.*sin(sqrt(abs(x))), 1); +% penalty term +f = f + 1e4*sum((abs(x)>500) .* (abs(x)-500).^2, 1); + function f=ftwomax(x) - % Boundaries at +/-5 - N = size(x,1); - f = -abs(sum(x)) + 5*N; +% Boundaries at +/-5 +N = size(x,1); +f = -abs(sum(x)) + 5*N; function f=ftwomaxtwo(x) - % Boundaries at +/-10 - N = size(x,1); - f = abs(sum(x)); - if f > 30 +% Boundaries at +/-10 +N = size(x,1); +f = abs(sum(x)); +if f > 30 f = f - 30; - end - f = -f; - +end +f = -f; + function f=frand(x) - f=1./(1-rand(1, size(x,2))) - 1; +f=1./(1-rand(1, size(x,2))) - 1; % CHANGES % 12/02/19: "future" setting of ccum, correcting for large mueff, is default now diff --git a/matlab/optimization/csminit1.m b/matlab/optimization/csminit1.m index 1a07951957..633e7dc9b9 100644 --- a/matlab/optimization/csminit1.m +++ b/matlab/optimization/csminit1.m @@ -122,7 +122,7 @@ else disp_verbose(sprintf('Correct for low angle: %g',a),Verbose) end end - disp_verbose(sprintf('Predicted improvement: %18.9f',-dfhat/2),Verbose) + disp_verbose(sprintf('Predicted improvement: %18.9f',-dfhat/2),Verbose) % % Have OK dx, now adjust length of step (lambda) until min and % max improvement rate criteria are met. @@ -145,7 +145,7 @@ else %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_verbose(sprintf('lambda = %10.5g; f = %20.7f',lambda,f ),Verbose) + disp_verbose(sprintf('lambda = %10.5g; f = %20.7f',lambda,f ),Verbose) %debug %disp(sprintf('Improvement too great? f0-f: %g, criterion: %g',f0-f,-(1-THETA)*dfhat*lambda)) if f<fhat diff --git a/matlab/optimization/csminwel1.m b/matlab/optimization/csminwel1.m index 52a0187929..af341b11db 100644 --- a/matlab/optimization/csminwel1.m +++ b/matlab/optimization/csminwel1.m @@ -302,7 +302,7 @@ while ~done error('Unaccounted Case, please contact the developers',Verbose) end end - + f=fh; x=xh; g=gh; @@ -312,18 +312,18 @@ end end function [g, badg]=get_num_grad(method,fcn,penalty,f0,x0,epsilon,varargin) - switch method - case 2 - [g,badg] = numgrad2(fcn, f0, x0, penalty, epsilon, varargin{:}); - case 3 - [g,badg] = numgrad3(fcn, f0, x0, penalty, epsilon, varargin{:}); - case 5 - [g,badg] = numgrad5(fcn, f0, x0, penalty, epsilon, varargin{:}); - case 13 - [g,badg] = numgrad3_(fcn, f0, x0, penalty, epsilon, varargin{:}); - case 15 - [g,badg] = numgrad5_(fcn, f0, x0, penalty, epsilon, varargin{:}); - otherwise - error('csminwel1: Unknown method for gradient evaluation!') - end +switch method + case 2 + [g,badg] = numgrad2(fcn, f0, x0, penalty, epsilon, varargin{:}); + case 3 + [g,badg] = numgrad3(fcn, f0, x0, penalty, epsilon, varargin{:}); + case 5 + [g,badg] = numgrad5(fcn, f0, x0, penalty, epsilon, varargin{:}); + case 13 + [g,badg] = numgrad3_(fcn, f0, x0, penalty, epsilon, varargin{:}); + case 15 + [g,badg] = numgrad5_(fcn, f0, x0, penalty, epsilon, varargin{:}); + otherwise + error('csminwel1: Unknown method for gradient evaluation!') +end end \ No newline at end of file diff --git a/matlab/optimization/dynare_minimize_objective.m b/matlab/optimization/dynare_minimize_objective.m index 30705f54aa..8aca0d2e10 100644 --- a/matlab/optimization/dynare_minimize_objective.m +++ b/matlab/optimization/dynare_minimize_objective.m @@ -339,14 +339,14 @@ switch minimizer_algorithm end case 'SaveFiles' if options_list{i,2}==0 - cmaesOptions.SaveVariables='off'; - cmaesOptions.LogModulo = '0'; % [0:Inf] if >1 record data less frequently after gen=100'; - cmaesOptions.LogTime = '0'; % [0:100] max. percentage of time for recording data'; + cmaesOptions.SaveVariables='off'; + cmaesOptions.LogModulo = '0'; % [0:Inf] if >1 record data less frequently after gen=100'; + cmaesOptions.LogTime = '0'; % [0:100] max. percentage of time for recording data'; end case 'CMAESResume' - if options_list{i,2}==1 + if options_list{i,2}==1 cmaesOptions.Resume = 'yes'; - end + end otherwise warning(['cmaes: Unknown option (' options_list{i,1} ')!']) end @@ -386,11 +386,11 @@ switch minimizer_algorithm case 'MaxFunEvals' simpsaOptions.MAX_FUN_EVALS = options_list{i,2}; case 'verbosity' - if options_list{i,2} == 0 + if options_list{i,2} == 0 simpsaOptions.DISPLAY = 'none'; - else + else simpsaOptions.DISPLAY = 'iter'; - end + end otherwise warning(['simpsa: Unknown option (' options_list{i,1} ')!']) end @@ -414,10 +414,10 @@ switch minimizer_algorithm if ~isempty(options_.optim_opt) options_list = read_key_value_string(options_.optim_opt); SupportedListOfOptions = {'CreationFcn', 'Display', 'DisplayInterval', 'FunctionTolerance', ... - 'FunValCheck', 'HybridFcn', 'InertiaRange', 'InitialSwarmMatrix', 'InitialSwarmSpan', ... - 'MaxIterations', 'MaxStallIterations', 'MaxStallTime', 'MaxTime', ... - 'MinNeighborsFraction', 'ObjectiveLimit', 'OutputFcn', 'PlotFcn', 'SelfAdjustmentWeight', ... - 'SocialAdjustmentWeight', 'SwarmSize', 'UseParallel', 'UseVectorized'}; + 'FunValCheck', 'HybridFcn', 'InertiaRange', 'InitialSwarmMatrix', 'InitialSwarmSpan', ... + 'MaxIterations', 'MaxStallIterations', 'MaxStallTime', 'MaxTime', ... + 'MinNeighborsFraction', 'ObjectiveLimit', 'OutputFcn', 'PlotFcn', 'SelfAdjustmentWeight', ... + 'SocialAdjustmentWeight', 'SwarmSize', 'UseParallel', 'UseVectorized'}; for i=1:rows(options_list) if ismember(options_list{i,1}, SupportedListOfOptions) particleswarmOptions = optimoptions(particleswarmOptions, options_list{i,1}, options_list{i,2}); @@ -514,8 +514,8 @@ end end function [LB, UB]=set_bounds_to_finite_values(bounds, huge_number) - LB=bounds(:,1); - LB(isinf(LB))=-huge_number; - UB=bounds(:,2); - UB(isinf(UB))=huge_number; +LB=bounds(:,1); +LB(isinf(LB))=-huge_number; +UB=bounds(:,2); +UB(isinf(UB))=huge_number; end diff --git a/matlab/optimization/gmhmaxlik.m b/matlab/optimization/gmhmaxlik.m index 3710d8d65e..bc800f8f84 100644 --- a/matlab/optimization/gmhmaxlik.m +++ b/matlab/optimization/gmhmaxlik.m @@ -16,7 +16,7 @@ function [PostMode, HessianMatrix, Scale, ModeValue] = gmhmaxlik(fun, xinit, Hin % % You should have received a copy of the GNU General Public License % along with Dynare. If not, see <http://www.gnu.org/licenses/>. - + % Set default options if ~isempty(Hinit); diff --git a/matlab/optimization/mr_hessian.m b/matlab/optimization/mr_hessian.m index eb1c0752e6..c3ed293457 100644 --- a/matlab/optimization/mr_hessian.m +++ b/matlab/optimization/mr_hessian.m @@ -223,7 +223,7 @@ if outer_product_gradient, hh_mat=gga'*gga; % rescaled outer product hessian hh_mat0=ggh'*ggh; % outer product hessian A=diag(2.*hess_info.h1); % rescaling matrix - % igg=inv(hh_mat); % inverted rescaled outer product hessian + % igg=inv(hh_mat); % inverted rescaled outer product hessian ihh=A'*(hh_mat\A); % inverted outer product hessian if hflag>0 && min(eig(reshape(hessian_mat,n,n)))>0 hh0 = A*reshape(hessian_mat,n,n)*A'; %rescaled second order derivatives @@ -244,12 +244,12 @@ if outer_product_gradient, igg=inv(A)'*ihh*inv(A); % inverted rescaled outer product hessian with modified std's hh_mat=inv(igg); % outer product rescaled hessian with modified std's hh_mat0=inv(A)'*hh_mat*inv(A); % outer product hessian with modified std's - % sd0=sqrt(1./diag(hh0)); %rescaled 'standard errors' using second order derivatives - % sd=sqrt(diag(igg)); %rescaled 'standard errors' using outer product - % igg=igg./(sd*sd').*(sd0*sd0'); %rescaled inverse outer product with 'true' std's - % hh_mat=inv(igg); % rescaled outer product hessian with 'true' std's - % ihh=A'*igg*A; % inverted outer product hessian - % hh_mat0=inv(A)'*hh_mat*inv(A); % outer product hessian with 'true' std's + % sd0=sqrt(1./diag(hh0)); %rescaled 'standard errors' using second order derivatives + % sd=sqrt(diag(igg)); %rescaled 'standard errors' using outer product + % igg=igg./(sd*sd').*(sd0*sd0'); %rescaled inverse outer product with 'true' std's + % hh_mat=inv(igg); % rescaled outer product hessian with 'true' std's + % ihh=A'*igg*A; % inverted outer product hessian + % hh_mat0=inv(A)'*hh_mat*inv(A); % outer product hessian with 'true' std's end if hflag<2 hessian_mat=hh_mat0(:); diff --git a/matlab/optimization/newrat.m b/matlab/optimization/newrat.m index 8085316d05..4d1ab52932 100644 --- a/matlab/optimization/newrat.m +++ b/matlab/optimization/newrat.m @@ -200,21 +200,21 @@ while norm(gg)>gtol && check==0 && jit<nit hhg=hh; H = inv(hh); else - if flagit==2 - hh=hh0; - elseif flagg>0 - [dum, gg, htol0, igg, hhg, h1, hess_info]=mr_hessian(xparam1,func0,penalty,flagg,ftol0,hess_info,varargin{:}); - if flagg==2 - hh = reshape(dum,nx,nx); - ee=eig(hh); - if min(ee)<0 + if flagit==2 + hh=hh0; + elseif flagg>0 + [dum, gg, htol0, igg, hhg, h1, hess_info]=mr_hessian(xparam1,func0,penalty,flagg,ftol0,hess_info,varargin{:}); + if flagg==2 + hh = reshape(dum,nx,nx); + ee=eig(hh); + if min(ee)<0 + hh=hhg; + end + else hh=hhg; end - else - hh=hhg; end end - end disp_verbose(['Actual dxnorm ',num2str(norm(x(:,end)-x(:,end-1)))],Verbose) disp_verbose(['FVAL ',num2str(fval)],Verbose) disp_verbose(['Improvement ',num2str(fval0(icount)-fval)],Verbose) diff --git a/matlab/optimization/simplex_optimization_routine.m b/matlab/optimization/simplex_optimization_routine.m index 58b3ff1b09..aff23b2468 100644 --- a/matlab/optimization/simplex_optimization_routine.m +++ b/matlab/optimization/simplex_optimization_routine.m @@ -251,7 +251,7 @@ while (func_count < max_func_calls) && (iter_count < max_iterations) && (simplex fxr = feval(objective_function,x,varargin{:}); func_count = func_count+1; if fxr < fv(1)% xr is better than previous best point v(:,1). - % Calculate the expansion point + % Calculate the expansion point xe = xbar + rho*chi*(xbar-v(:,end)); x = xe; fxe = feval(objective_function,x,varargin{:}); @@ -499,7 +499,7 @@ while (func_count < max_func_calls) && (iter_count < max_iterations) && (simplex else break end - end + end end% while loop. x(:) = v(:,1); @@ -520,43 +520,43 @@ end function [v,fv,delta] = simplex_initialization(objective_function,point,point_score,delta,zero_delta,check_delta,varargin) - n = length(point); - v = zeros(n,n+1); - v(:,1) = point; - fv = zeros(n+1,1); - fv(1) = point_score; - if length(delta)==1 - delta = repmat(delta,n,1); +n = length(point); +v = zeros(n,n+1); +v(:,1) = point; +fv = zeros(n+1,1); +fv(1) = point_score; +if length(delta)==1 + delta = repmat(delta,n,1); +end +for j = 1:n + y = point; + if y(j) ~= 0 + y(j) = (1 + delta(j))*y(j); + else + y(j) = zero_delta; end - for j = 1:n - y = point; - if y(j) ~= 0 - y(j) = (1 + delta(j))*y(j); - else - y(j) = zero_delta; - end - v(:,j+1) = y; - x = y; - [fv(j+1),junk1,junk2,nopenalty_flag] = feval(objective_function,x,varargin{:}); - if check_delta - while ~nopenalty_flag - if y(j)~=0 - delta(j) = delta(j)/1.1; - else - zero_delta = zero_delta/1.1; - end - y = point; - if y(j) ~= 0 - y(j) = (1 + delta(j))*y(j); - else - y(j) = zero_delta; - end - v(:,j+1) = y; - x = y; - [fv(j+1),junk1,junk2,nopenalty_flag] = feval(objective_function,x,varargin{:}); + v(:,j+1) = y; + x = y; + [fv(j+1),junk1,junk2,nopenalty_flag] = feval(objective_function,x,varargin{:}); + if check_delta + while ~nopenalty_flag + if y(j)~=0 + delta(j) = delta(j)/1.1; + else + zero_delta = zero_delta/1.1; end + y = point; + if y(j) ~= 0 + y(j) = (1 + delta(j))*y(j); + else + y(j) = zero_delta; + end + v(:,j+1) = y; + x = y; + [fv(j+1),junk1,junk2,nopenalty_flag] = feval(objective_function,x,varargin{:}); end end - % Sort by increasing order of the objective function values. - [fv,sort_idx] = sort(fv); - v = v(:,sort_idx); \ No newline at end of file +end +% Sort by increasing order of the objective function values. +[fv,sort_idx] = sort(fv); +v = v(:,sort_idx); \ No newline at end of file diff --git a/matlab/optimization/simpsa.m b/matlab/optimization/simpsa.m index 260607a240..228a6bad21 100644 --- a/matlab/optimization/simpsa.m +++ b/matlab/optimization/simpsa.m @@ -122,20 +122,20 @@ NDIM = length(X0); % set default options DEFAULT_OPTIONS = simpsaset('TEMP_START',[],... % starting temperature (if none provided, an optimal one will be estimated) - 'TEMP_END',.1,... % end temperature - 'COOL_RATE',10,... % small values (<1) means slow convergence,large values (>1) means fast convergence - 'INITIAL_ACCEPTANCE_RATIO',0.95,... % when initial temperature is estimated, this will be the initial acceptance ratio in the first round - 'MIN_COOLING_FACTOR',0.9,... % minimum cooling factor (<1) - 'MAX_ITER_TEMP_FIRST',50,... % number of iterations in the preliminary temperature loop - 'MAX_ITER_TEMP_LAST',2000,... % number of iterations in the last temperature loop (pure simplex) - 'MAX_ITER_TEMP',10,... % number of iterations in the remaining temperature loops - 'MAX_ITER_TOTAL',2500,... % maximum number of iterations tout court - 'MAX_TIME',2500,... % maximum duration of optimization - 'MAX_FUN_EVALS',20000,... % maximum number of function evaluations - 'TOLX',1e-6,... % maximum difference between best and worst function evaluation in simplex - 'TOLFUN',1e-6,... % maximum difference between the coordinates of the vertices - 'DISPLAY','iter',... % 'iter' or 'none' indicating whether user wants feedback - 'OUTPUT_FCN',[]); % string with output function name + 'TEMP_END',.1,... % end temperature + 'COOL_RATE',10,... % small values (<1) means slow convergence,large values (>1) means fast convergence + 'INITIAL_ACCEPTANCE_RATIO',0.95,... % when initial temperature is estimated, this will be the initial acceptance ratio in the first round + 'MIN_COOLING_FACTOR',0.9,... % minimum cooling factor (<1) + 'MAX_ITER_TEMP_FIRST',50,... % number of iterations in the preliminary temperature loop + 'MAX_ITER_TEMP_LAST',2000,... % number of iterations in the last temperature loop (pure simplex) + 'MAX_ITER_TEMP',10,... % number of iterations in the remaining temperature loops + 'MAX_ITER_TOTAL',2500,... % maximum number of iterations tout court + 'MAX_TIME',2500,... % maximum duration of optimization + 'MAX_FUN_EVALS',20000,... % maximum number of function evaluations + 'TOLX',1e-6,... % maximum difference between best and worst function evaluation in simplex + 'TOLFUN',1e-6,... % maximum difference between the coordinates of the vertices + 'DISPLAY','iter',... % 'iter' or 'none' indicating whether user wants feedback + 'OUTPUT_FCN',[]); % string with output function name % update default options with supplied options @@ -329,7 +329,7 @@ while 1, %% 2. maximum difference between the coordinates of the vertices in simplex is less than TOLX %% 3. no convergence,but maximum number of iterations has been reached %% 4. no convergence,but maximum time has been reached - + if (abs(max(Y)-min(Y)) < OPTIONS.TOLFUN) && (TEMP_LOOP_NUMBER ~= 1), if strcmp(OPTIONS.DISPLAY,'iter'), disp('Change in the objective function value less than the specified tolerance (TOLFUN).') diff --git a/matlab/optimization/simpsaget.m b/matlab/optimization/simpsaget.m index e482a3e001..c22c82df4c 100644 --- a/matlab/optimization/simpsaget.m +++ b/matlab/optimization/simpsaget.m @@ -38,25 +38,25 @@ function o = simpsaget(options,name,default,flag) % undocumented usage for fast access with no error checking if (nargin == 4) && isequal(flag,'fast') - o = getknownfield(options,name,default); - return + o = getknownfield(options,name,default); + return end if nargin < 2 - error('MATLAB:odeget:NotEnoughInputs','Not enough input arguments.'); + error('MATLAB:odeget:NotEnoughInputs','Not enough input arguments.'); end if nargin < 3 - default = []; + default = []; end if ~isempty(options) && ~isa(options,'struct') - error('MATLAB:odeget:Arg1NotODESETstruct',... - 'First argument must be an options structure created with ODESET.'); + error('MATLAB:odeget:Arg1NotODESETstruct',... + 'First argument must be an options structure created with ODESET.'); end if isempty(options) - o = default; - return; + o = default; + return; end Names = [ @@ -75,39 +75,39 @@ Names = [ 'TOLFUN ' 'DISPLAY ' 'OUTPUT_FCN ' - ]; + ]; names = lower(Names); lowName = lower(name); j = strmatch(lowName,names); if isempty(j) % if no matches - error('MATLAB:odeget:InvalidPropName',... - ['Unrecognized property name ''%s''. ' ... - 'See ODESET for possibilities.'], name); + error('MATLAB:odeget:InvalidPropName',... + ['Unrecognized property name ''%s''. ' ... + 'See ODESET for possibilities.'], name); elseif length(j) > 1 % if more than one match - % Check for any exact matches (in case any names are subsets of others) - k = strmatch(lowName,names,'exact'); - if length(k) == 1 - j = k; - else - msg = sprintf('Ambiguous property name ''%s'' ', name); - msg = [msg '(' deblank(Names(j(1),:))]; - for k = j(2:length(j))' - msg = [msg ', ' deblank(Names(k,:))]; + % Check for any exact matches (in case any names are subsets of others) + k = strmatch(lowName,names,'exact'); + if length(k) == 1 + j = k; + else + msg = sprintf('Ambiguous property name ''%s'' ', name); + msg = [msg '(' deblank(Names(j(1),:))]; + for k = j(2:length(j))' + msg = [msg ', ' deblank(Names(k,:))]; + end + msg = sprintf('%s).', msg); + error('MATLAB:odeget:AmbiguousPropName', msg); end - msg = sprintf('%s).', msg); - error('MATLAB:odeget:AmbiguousPropName', msg); - end end if any(strcmp(fieldnames(options),deblank(Names(j,:)))) - o = options.(deblank(Names(j,:))); - if isempty(o) - o = default; - end + o = options.(deblank(Names(j,:))); + if isempty(o) + o = default; + end else - o = default; + o = default; end % -------------------------------------------------------------------------- @@ -115,11 +115,11 @@ function v = getknownfield(s, f, d) %GETKNOWNFIELD Get field f from struct s, or else yield default d. if isfield(s,f) % s could be empty. - v = subsref(s, struct('type','.','subs',f)); - if isempty(v) - v = d; - end + v = subsref(s, struct('type','.','subs',f)); + if isempty(v) + v = d; + end else - v = d; + v = d; end diff --git a/matlab/optimization/simpsaset.m b/matlab/optimization/simpsaset.m index ca687891a8..1944e024fc 100644 --- a/matlab/optimization/simpsaset.m +++ b/matlab/optimization/simpsaset.m @@ -64,7 +64,7 @@ if (nargin == 0) && (nargout == 0) fprintf(' DISPLAY: [ ''iter'' or ''none'' {''iter''} ]\n'); fprintf(' OUTPUT_FCN: [ function_handle ]\n'); fprintf('\n'); -return; + return; end Names = [ @@ -83,7 +83,7 @@ Names = [ 'TOLFUN ' 'DISPLAY ' 'OUTPUT_FCN ' - ]; + ]; m = size(Names,1); names = lower(Names); @@ -91,82 +91,82 @@ names = lower(Names); % Combine all leading options structures o1, o2, ... in odeset(o1,o2,...). options = []; for j = 1:m - options.(deblank(Names(j,:))) = []; + options.(deblank(Names(j,:))) = []; end i = 1; while i <= nargin - arg = varargin{i}; - if ischar(arg) % arg is an option name - break; - end - if ~isempty(arg) % [] is a valid options argument - if ~isa(arg,'struct') - error('MATLAB:odeset:NoPropNameOrStruct',... - ['Expected argument %d to be a string property name ' ... - 'or an options structure\ncreated with SIMANSET.'], i); + arg = varargin{i}; + if ischar(arg) % arg is an option name + break; end - for j = 1:m - if any(strcmp(fieldnames(arg),deblank(Names(j,:)))) - val = arg.(deblank(Names(j,:))); - else - val = []; - end - if ~isempty(val) - options.(deblank(Names(j,:))) = val; - end + if ~isempty(arg) % [] is a valid options argument + if ~isa(arg,'struct') + error('MATLAB:odeset:NoPropNameOrStruct',... + ['Expected argument %d to be a string property name ' ... + 'or an options structure\ncreated with SIMANSET.'], i); + end + for j = 1:m + if any(strcmp(fieldnames(arg),deblank(Names(j,:)))) + val = arg.(deblank(Names(j,:))); + else + val = []; + end + if ~isempty(val) + options.(deblank(Names(j,:))) = val; + end + end end - end - i = i + 1; + i = i + 1; end % A finite state machine to parse name-value pairs. if rem(nargin-i+1,2) ~= 0 - error('MATLAB:odeset:ArgNameValueMismatch',... - 'Arguments must occur in name-value pairs.'); + error('MATLAB:odeset:ArgNameValueMismatch',... + 'Arguments must occur in name-value pairs.'); end expectval = 0; % start expecting a name, not a value while i <= nargin - arg = varargin{i}; - - if ~expectval - if ~ischar(arg) - error('MATLAB:odeset:NoPropName',... - 'Expected argument %d to be a string property name.', i); - end + arg = varargin{i}; - lowArg = lower(arg); - j = strmatch(lowArg,names); - if isempty(j) % if no matches - error('MATLAB:odeset:InvalidPropName',... - 'Unrecognized property name ''%s''.', arg); - elseif length(j) > 1 % if more than one match - % Check for any exact matches (in case any names are subsets of others) - k = strmatch(lowArg,names,'exact'); - if length(k) == 1 - j = k; - else - msg = sprintf('Ambiguous property name ''%s'' ', arg); - msg = [msg '(' deblank(Names(j(1),:))]; - for k = j(2:length(j))' - msg = [msg ', ' deblank(Names(k,:))]; + if ~expectval + if ~ischar(arg) + error('MATLAB:odeset:NoPropName',... + 'Expected argument %d to be a string property name.', i); + end + + lowArg = lower(arg); + j = strmatch(lowArg,names); + if isempty(j) % if no matches + error('MATLAB:odeset:InvalidPropName',... + 'Unrecognized property name ''%s''.', arg); + elseif length(j) > 1 % if more than one match + % Check for any exact matches (in case any names are subsets of others) + k = strmatch(lowArg,names,'exact'); + if length(k) == 1 + j = k; + else + msg = sprintf('Ambiguous property name ''%s'' ', arg); + msg = [msg '(' deblank(Names(j(1),:))]; + for k = j(2:length(j))' + msg = [msg ', ' deblank(Names(k,:))]; + end + msg = sprintf('%s).', msg); + error('MATLAB:odeset:AmbiguousPropName', msg); + end end - msg = sprintf('%s).', msg); - error('MATLAB:odeset:AmbiguousPropName', msg); - end + expectval = 1; % we expect a value next + + else + options.(deblank(Names(j,:))) = arg; + expectval = 0; + end - expectval = 1; % we expect a value next - - else - options.(deblank(Names(j,:))) = arg; - expectval = 0; - - end - i = i + 1; + i = i + 1; end if expectval - error('MATLAB:odeset:NoValueForProp',... - 'Expected value for property ''%s''.', arg); + error('MATLAB:odeset:NoValueForProp',... + 'Expected value for property ''%s''.', arg); end end diff --git a/matlab/optimization/simulated_annealing.m b/matlab/optimization/simulated_annealing.m index 5b505b71d6..b2cfc52eec 100644 --- a/matlab/optimization/simulated_annealing.m +++ b/matlab/optimization/simulated_annealing.m @@ -314,9 +314,9 @@ while (1>0); if(pp<p); if(optim.verbosity >=3); if(optim.maximizer_indicator); - fprintf('though lower, point accepted\n'); + fprintf('though lower, point accepted\n'); else - fprintf('though higher, point accepted\n'); + fprintf('though higher, point accepted\n'); end; end; x=xp; @@ -401,7 +401,7 @@ end function print_current_invalid_try(max,xp,x,fp,f) fprintf('\n'); - disp(['Current x ' num2str(x(:)')]); +disp(['Current x ' num2str(x(:)')]); if(max); disp(['Current f ' num2str(f)]); else diff --git a/matlab/options2cell.m b/matlab/options2cell.m index 3ff8ef2274..1296df22d5 100644 --- a/matlab/options2cell.m +++ b/matlab/options2cell.m @@ -28,7 +28,7 @@ function c = options2cell(o) s = fieldnames(o); c = {}; j = 1; - + for i=1:length(s) c(j) = {s{i}}; c(j+1) = {o.(s{i})}; diff --git a/matlab/osr1.m b/matlab/osr1.m index cf13da166d..a92dfedd52 100644 --- a/matlab/osr1.m +++ b/matlab/osr1.m @@ -101,17 +101,17 @@ i_var=unique(i_var); %% do initial checks [loss,info,exit_flag,vx]=osr_obj(t0,i_params,inv_order_var(i_var),weights(i_var,i_var)); if info~=0 - print_info(info, options_.noprint, options_); - else - if ~options_.noprint - fprintf('\nOSR: Initial value of the objective function: %g \n\n',loss); - end + print_info(info, options_.noprint, options_); +else + if ~options_.noprint + fprintf('\nOSR: Initial value of the objective function: %g \n\n',loss); + end end if ~options_.noprint && isinf(loss) - fprintf('\nOSR: The initial value of the objective function is infinite.\n'); - fprintf('\nOSR: Check whether the unconditional variance of a target variable is infinite\n'); - fprintf('\nOSR: due to the presence of a unit root.\n'); - error('OSR: Initial likelihood is infinite') + fprintf('\nOSR: The initial value of the objective function is infinite.\n'); + fprintf('\nOSR: Check whether the unconditional variance of a target variable is infinite\n'); + fprintf('\nOSR: due to the presence of a unit root.\n'); + error('OSR: Initial likelihood is infinite') end @@ -125,12 +125,12 @@ elseif isequal(options_.osr.opt_algo,11) error('OSR: OSR does not support opt_algo=11.') else -if ~isempty(M_.osr.param_bounds) && ~(ismember(options_.osr.opt_algo,[1,2,5,9]) || ischar(options_.osr.opt_algo)) - error('OSR: OSR with bounds on parameters requires a constrained optimizer, i.e. 1,2,5, or 9.') -end -%%do actual optimization -[p, f, exitflag] = dynare_minimize_objective(str2func('osr_obj'),t0,options_.osr.opt_algo,options_,M_.osr.param_bounds,cellstr(M_.param_names(i_params,:)),[],[], i_params,... - inv_order_var(i_var),weights(i_var,i_var)); + if ~isempty(M_.osr.param_bounds) && ~(ismember(options_.osr.opt_algo,[1,2,5,9]) || ischar(options_.osr.opt_algo)) + error('OSR: OSR with bounds on parameters requires a constrained optimizer, i.e. 1,2,5, or 9.') + end + %%do actual optimization + [p, f, exitflag] = dynare_minimize_objective(str2func('osr_obj'),t0,options_.osr.opt_algo,options_,M_.osr.param_bounds,cellstr(M_.param_names(i_params,:)),[],[], i_params,... + inv_order_var(i_var),weights(i_var,i_var)); end osr_res.objective_function = f; diff --git a/matlab/osr_obj.m b/matlab/osr_obj.m index 67efbbbc08..5bea8e7605 100644 --- a/matlab/osr_obj.m +++ b/matlab/osr_obj.m @@ -51,8 +51,8 @@ it_ = M_.maximum_lag+1; if info(1) if info(1) == 3 || info(1) == 4 || info(1) == 5 || info(1)==6 ||info(1) == 19 ||... - info(1) == 20 || info(1) == 21 || info(1) == 23 || info(1) == 26 || ... - info(1) == 81 || info(1) == 84 || info(1) == 85 + info(1) == 20 || info(1) == 21 || info(1) == 23 || info(1) == 26 || ... + info(1) == 81 || info(1) == 84 || info(1) == 85 loss = 1e8; info(4)=info(2); return diff --git a/matlab/parallel/AnalyseComputationalEnvironment.m b/matlab/parallel/AnalyseComputationalEnvironment.m index e5d2a87f53..ff9920abfd 100644 --- a/matlab/parallel/AnalyseComputationalEnvironment.m +++ b/matlab/parallel/AnalyseComputationalEnvironment.m @@ -1,657 +1,657 @@ -function [ErrorCode] = AnalyseComputationalEnvironment(DataInput, DataInputAdd) -% PARALLEL CONTEXT -% In a parallel context, this function is used to check the cluster defined by the user. -% If no error happen the function returns 0. The function complies with -% Windows/Linux operating systems and Matlab/Octave software. -% -% -% INPUT/OUTPUT description: -% -% -% DataInput -% is the strcture option_.parallel, with the follow fields: -% -% Local 1 is on local machine, 0 remote -% ComputerName the computer name. -% CPUnbr the CPU's -% UserName the user name for the ComputerName. -% Password the password for the user name in ComputerName. -% RemoteDrive Drive used for Remote computation (data exchange, etc): must be contain 'RemoteFolder'. -% RemoteDirectory Folder in RemoteDrive used for Remote computation. -% MatlabOctavePath Path to MATLAB or Octave executable. -% DynarePath Path to matlab directory within the Dynare installation directory. -% -% This information is typed by the user in the DYNARE configuration file and is parsed by the preprocessor, -% the goal of this function is to check if configuration is correct and if dynare -% can be executed successfully in parallel mode. -% -% -% DataInputAdd -% it is the structure options_.parallel_info. Currently , only the string in the -% field RemoteTmpFolder (the temporary directory created/destroyed on remote -% computer) is used. - -if ispc, - [tempo, MasterName]=system('hostname'); - MasterName=deblank(MasterName); -end - -RemoteTmpFolder=DataInputAdd.RemoteTmpFolder; -dynareParallelMkDir(RemoteTmpFolder,DataInput); - - -% The variable ErrorCode is initialized at 0. If there are non problems with -% Local, ComputerName connections,... in general with parallel software execution, -% the ErrorCode is unchanged, in the others cases 1, 2 , ... The values -% table is below. -% -% -% Table for ErrorCode Values. -% -% ErrorCode -> 0 Initial Value -> No Error Detected!!! -% ErrorCode -> 1 ... When an error is detected, the values 1, 2, 3... are -% used to specify the type of error or warning. -% -% Value 1: The variable 'Local' has a bad value! -% -% Value 2: The variable 'CPUnbr' has a bad value. For more information -% see http://www.dynare.org/DynareWiki/ParallelDynare. -% 2.1 [warning] The user asks to use more CPU's than those available. -% 2.2 [warning] There are unused CPU's! -% 2.3 [error] NumberOfThreadsPerJob is not a divisor of CPUnbr -% -% -% Value 3: The remote computer is unreachable!!! -% -% Value 4: The fields user name and/or password are/is empty! -% -% Value 5: Remote Drive and/or Remote Folder do not exist! -% -% Value 6: It is impossible write/read files on the remote computer. -% -% Value 7: The values user and/or passwd are incorrect or the user has -% no permissions to execute a Matlab session. Or simply -% Matlab path (MatlabOctavePath) is incorrect! -% -% Value 8: Dynare path (DynarePath) is incorrect! -% -% Value 9: It is impossible delete remote computational temporary files! -% -% -% -% -% Currently when errors are detected execution simply stops and users can -% fix configuration errors according to the error type. - -% Copyright (C) 2009-2013 Dynare Team -% -% This file is part of Dynare. -% -% Dynare is free software: you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation, either version 3 of the License, or -% (at your option) any later version. -% -% Dynare is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. -% -% You should have received a copy of the GNU General Public License -% along with Dynare. If not, see <http://www.gnu.org/licenses/>. - - -ErrorCode=0; - - -for Node=1:length(DataInput) % To obtain a recoursive function remove the 'for' - % and use AnalyseComputationalEnvironment with differents input! - - - % Determine the operating system or software version when necessary - % for different command types. - - OScallerUnix=~ispc; - OScallerWindows=ispc; - OStargetUnix=strcmpi('unix',DataInput(Node).OperatingSystem); - if isempty(DataInput(Node).OperatingSystem), - OStargetUnix=OScallerUnix; - end - OStargetWindows=strcmpi('windows',DataInput(Node).OperatingSystem); - if isempty(DataInput(Node).OperatingSystem), - OStargetWindows=OScallerWindows; - end - - Environment= (OScallerUnix || OStargetUnix); - - skipline(2) - disp(['Testing computer -> ',DataInput(Node).ComputerName,' <- ...']); - skipline(2) - - % The function is composed by two main blocks, determined by the 'Local' - % variable. - - % This check can be removed ... according to the dynare parser - % strategy. - - if ((DataInput(Node).Local == 0) |(DataInput(Node).Local == 1)) - % Continue it is Ok! - disp('Check on Local Variable ..... Ok!'); - skipline() - else - disp('The variable "Local" has a bad value!'); - skipline() - disp('ErrorCode 1.'); - skipline() - ErrorCode=1; - return - end - - % %%%%%%%%%% Local (No Network) Computing %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - % Here only the multi-core, or multi-processor avaiable on local - % machine are involved in parallel computing. No network - % comunications are required! - - - % In this case we need to check only the variable 'CPUnbr'. - - % We run the parallel code on local computer, so the others fields are automatically - % fixed by Dynare parser. Then the user can also fill them with wrong values. - - - % %%%%%%%%%% Cluster Computing %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - % Here we can have many computer with multi-core, or multi-processor avaiable on the - % network and involved in parallel computing. - % So in this case we need more sophisticated check. - - - if (DataInput(Node).Local == 0) - - % Now we verify if it is possibile to be connected with the - % remote computer. - - si1=[]; - de1=[]; - - if Environment - if OScallerWindows - [si1 de1]=system(['ping ', DataInput(Node).ComputerName]); - else - [si1 de1]=system(['ping ', DataInput(Node).ComputerName, ' -c 4']); - end - else - [si1 de1]=system(['ping ', DataInput(Node).ComputerName]); - end - - if (si1) - disp(['It is impossibile to ping to the computer with name "',DataInput(Node).ComputerName,'" using the network!']) - skipline() - disp('ErrorCode 3.') - ErrorCode=3; - skipline(2) - else - disp('Check on ComputerName Variable ..... Ok!') - skipline(2) - end - - - % Now we verify if user name and password are correct and if remote - % drive and remote folder exist on the remote computer and it is - % possible to exchange data with them. - - if Environment - % This check can be removed ... according to the dynare parser - % strategy. - - if (isempty(DataInput(Node).UserName)) - disp('The fields UserName is empty!') - skipline() - disp('ErrorCode 4.') - skipline(2) - ErrorCode=4; - return - end - disp('Check on UserName Variable ..... Ok!') - skipline(2) - - % This check can be removed ... according to the dynare parser - % strategy. - if (~isempty(DataInput(Node).Password)) - disp('[WARNING] The field Password should be empty under unix or mac!'); - skipline() - disp(['Remove the string ',DataInput(Node).Password,' from this field!']) - skipline() - disp('ErrorCode 4.') - skipline(2) - ErrorCode=4; - else - disp('Check on Password Variable ..... Ok!') - skipline(2) - end - else - - % This check can be removed ... according to the dynare parser - % strategy. - - if (isempty(DataInput(Node).UserName)) || (isempty(DataInput(Node).Password)) - disp('The fields UserName and/or Password are/is empty!'); - skipline() - disp('ErrorCode 4.') - skipline(2) - ErrorCode=4; - return - end - disp('Check on UserName Variable ..... Ok!'); - skipline() - disp('Check on Password Variable ..... Ok!'); - skipline() - end - - % Now we very if RemoteDrive and/or RemoteDirectory exist on remote - % computer! - - if Environment - - % This check can be removed ... according to the dynare parser - % strategy. - - if isempty(DataInput(Node).RemoteDirectory) - disp('The field RemoteDirectory is empty!') - skipline() - disp('ErrorCode 5.') - skipline() - ErrorCode=5; - return - end - - % This check can be removed ... according to the dynare parser - % strategy. - - if (~isempty(DataInput(Node).RemoteDrive)) - disp('[WARNING] The fields RemoteDrive should be empty under unix or mac!') - skipline() - disp(['remove the string ',DataInput(Node).RemoteDrive,' from this field!']) - skipline() - disp('ErrorCode 5.') - skipline(2) - ErrorCode=5; - end - - si2=[]; - de2=[]; - if ~isempty(DataInput(Node).Port), - ssh_token = ['-p ',DataInput(Node).Port]; - else - ssh_token = ''; - end - - [si2 de2]=system(['ssh ',ssh_token,' ',DataInput(Node).UserName,'@',DataInput(Node).ComputerName,' ls ',DataInput(Node).RemoteDirectory,'/',RemoteTmpFolder,'/']); - - if (si2) - disp ('Remote Directory does not exist or is not reachable!') - skipline() - disp('ErrorCode 5.') - skipline(2) - ErrorCode=5; - return - end - - disp('Check on RemoteDirectory Variable ..... Ok!') - skipline(2) - disp('Check on RemoteDrive Variable ..... Ok!') - skipline(2) - - else - % This check can be removed ... according to the dynare parser - % strategy. - - if (isempty(DataInput(Node).RemoteDrive)||isempty(DataInput(Node).RemoteDirectory)) - disp('Remote RemoteDrive and/or RemoteDirectory is/are empty!') - skipline() - disp('ErrorCode 5.') - skipline(2) - ErrorCode=5; - return - end - - - si2=[]; - de2=[]; - [si2 de2]=system(['dir \\',DataInput(Node).ComputerName,'\',DataInput(Node).RemoteDrive,'$\',DataInput(Node).RemoteDirectory,'\',RemoteTmpFolder]); - - if (si2) - disp ('Remote Directory does not exist or it is not reachable!') - skipline() - disp('ErrorCode 5.') - skipline(2) - ErrorCode=5; - return - end - - disp('Check on RemoteDirectory Variable ..... Ok!') - skipline(2) - disp('Check on RemoteDrive Variable ..... Ok!') - skipline(2) - - end - - - % Now we verify if it possible to exchange data with the remote - % computer: - - - % Build a command file to test the matlab execution and dynare path ... - - fid = fopen('Tracing.m', 'w+'); - s1=(['fT = fopen(''MatlabOctaveIsOk.txt'',''w+'');\n']); - s2='fclose(fT);\n'; - SBS=strfind(DataInput(Node).DynarePath,'\'); - DPStr=DataInput(Node).DynarePath; - if isempty(SBS), - DPStrNew=DPStr; - else - DPStrNew=[DPStr(1:SBS(1)),'\']; - for j=2:length(SBS), - DPStrNew=[DPStrNew,DPStr(SBS(j-1)+1:SBS(j)),'\']; - end - DPStrNew=[DPStrNew,DPStr(SBS(end)+1:end)]; - end - s3=['addpath(''',DPStrNew,'''),\n']; - s4=['try,\n dynareroot = dynare_config();\n']; - s41=([' fT = fopen(''DynareIsOk.txt'',''w+'');\n']); - s42=' fclose(fT);\n'; - s5=['catch,\n']; - s51=([' fT = fopen(''DynareFailed.txt'',''w+'');\n']); - s52=' fclose(fT);\n'; - s6=['end,\n']; - s7=['if ismac,\n']; - s71=([' fT = fopen(''IsMac.txt'',''w+'');\n']); - s72=' fclose(fT);\n'; - s8=['end,\n']; - send='exit'; - StrCommand=([s1,s2,s3,s4,s41,s42,s5,s51,s52,s6,s7,s71,s72,s8,send]); - - % Mettere controllo su NbW ... - % if isoctave - % NbW = fprintf(fid,StrCommand, '%s'); - % else - NbW = fprintf(fid,StrCommand, '%s'); - % end - fclose(fid); - - dynareParallelSendFiles('Tracing.m', RemoteTmpFolder,DataInput(Node)); - FindTracing = dynareParallelDir('Tracing.m', RemoteTmpFolder,DataInput(Node)); - - delete ('Tracing.m'); - - if (isempty(FindTracing)) - disp('It is impossible to exchange data with Remote Drive and/or Remote Directory! ErrorCode 6.') - skipline() - disp('ErrorCode 6.') - skipline(2) - ErrorCode=6; - return - else - disp('Check on Exchange File with Remote Computer ..... Ok!') - skipline(2) - end - - - % Now we verify if it is possible execute a matlab/octave section on remote - % machine when the user is .UserName with password .Password and - % the path is MatlabOctavePath. - - if Environment, - if ~isempty(DataInput(Node).Port), - ssh_token = ['-p ',DataInput(Node).Port]; - else - ssh_token = ''; - end - if strfind([DataInput(Node).MatlabOctavePath], 'octave') % Hybrid computing Matlab(Master)->Octave(Slaves) and Vice Versa! - system(['ssh ',ssh_token,' ',DataInput(Node).UserName,'@',DataInput(Node).ComputerName,' "cd ',DataInput(Node).RemoteDirectory,'/',RemoteTmpFolder, '; ', DataInput(Node).MatlabOctavePath, ' Tracing.m;" &']); - else - system(['ssh ',ssh_token,' ',DataInput(Node).UserName,'@',DataInput(Node).ComputerName,' "cd ',DataInput(Node).RemoteDirectory,'/',RemoteTmpFolder, '; ', DataInput(Node).MatlabOctavePath, ' -nosplash -nodesktop -minimize -r Tracing;" &']); - end - else - if ~strcmp(DataInput(Node).ComputerName,MasterName), % run on remote machine - if strfind([DataInput(Node).MatlabOctavePath], 'octave') % Hybrid computing Matlab(Master)->Octave(Slaves) and Vice Versa! - [NonServeS NenServeD]=system(['start /B psexec \\',DataInput(Node).ComputerName,' -e -u ',DataInput(Node).UserName,' -p ',DataInput(Node).Password,' -W ',DataInput(Node).RemoteDrive,':\',DataInput(Node).RemoteDirectory,'\',RemoteTmpFolder ' -low ',DataInput(Node).MatlabOctavePath,' Tracing.m']); - else - [NonServeS NenServeD]=system(['start /B psexec \\',DataInput(Node).ComputerName,' -e -u ',DataInput(Node).UserName,' -p ',DataInput(Node).Password,' -W ',DataInput(Node).RemoteDrive,':\',DataInput(Node).RemoteDirectory,'\',RemoteTmpFolder ' -low ',DataInput(Node).MatlabOctavePath,' -nosplash -nodesktop -minimize -r Tracing']); - end - else % run on local machine via the network: user and passwd cannot be used! - if strfind([DataInput(Node).MatlabOctavePath], 'octave') % Hybrid computing Matlab(Master)->Octave(Slaves) and Vice Versa! - [NonServeS NenServeD]=system(['start /B psexec \\',DataInput(Node).ComputerName,' -e ',' -W ',DataInput(Node).RemoteDrive,':\',DataInput(Node).RemoteDirectory,'\',RemoteTmpFolder ' -low ',DataInput(Node).MatlabOctavePath,' Tracing.m']); - else - [NonServeS NenServeD]=system(['start /B psexec \\',DataInput(Node).ComputerName,' -e ',' -W ',DataInput(Node).RemoteDrive,':\',DataInput(Node).RemoteDirectory,'\',RemoteTmpFolder ' -low ',DataInput(Node).MatlabOctavePath,' -nosplash -nodesktop -minimize -r Tracing']); - end - end - - end - - % Timer da fissare, nei valori di attesa! - - t1=fix(clock); - - if t1(5)+1>60; - t2=2; - else t2=t1(5)+1; - end - - Flag=0; - - while (1); - if Flag==0 - disp('Try to run matlab/octave on remote machine ... ') - skipline() - disp('please wait ... ') - skipline() - Flag=1; - end - nt=fix(clock); - nt(5)-t2; - - if (~isempty (dynareParallelDir('MatlabOctaveIsOk.txt',RemoteTmpFolder,DataInput(Node)))) || ((nt(5)-t2)>0) - if ((nt(5)-t2)>0) - ErrorCode=7; - end - break - end - - end - - if (ErrorCode==7) - - disp ('It is not possible execute a matlab session on remote machine!') - skipline() - disp('ErrorCode 7.') - skipline(2) - ErrorCode=7; - dynareParallelRmDir(RemoteTmpFolder,DataInput(Node)); - return - else - disp('Check on MatlabOctave Path and MatlabOctave Program Execution on remote machine ..... Ok!') - skipline(2) - - % Now we verify if the DynarePath is correct ... - disp('Check the Dynare path on remote machine ... ') - skipline() - disp('please wait ... ') - skipline(2) - pause(2) - - if isempty(dynareParallelDir('DynareIsOk.txt',RemoteTmpFolder,DataInput(Node))) - ErrorCode=8; - end - - if (ErrorCode==8) - disp ('The DynarePath is incorrect!') - skipline() - disp('ErrorCode 8.') - skipline(2) - ErrorCode=8; - dynareParallelRmDir(RemoteTmpFolder,DataInput(Node)); - return - else - disp('Check on Dynare Path remote machine ..... Ok!') - if isempty(dynareParallelDir('IsMac.txt',RemoteTmpFolder,DataInput(Node))) - RemoteEnvironment=Environment; - else - RemoteEnvironment=2; - end - skipline(2) - end - end - - - % Now we verify if it is possible delete remote computational traces! - - dynareParallelRmDir(RemoteTmpFolder,DataInput(Node)); - - si3=[]; - - si3=dynareParallelDir('Tracing.m', RemoteTmpFolder,DataInput(Node)); - - if (isempty(si3)) - disp ('Check on Delete Remote Computational Traces ..... Ok!') - skipline(2) - else - disp ('It is impossible to delete temporary files on remote machine!') - skipline() - disp('ErrorCode 9.') - skipline(2) - ErrorCode=9; - return - end - - - end - % Now we check the variable 'CPUnbr'. - - % This check can be removed ... according to the dynare parser - % strategy. - - yn=isempty(DataInput(Node).CPUnbr); - - if yn==1 - % The field is empty! - disp('The field "CPUnbr" is empty!') - skipline() - disp('ErrorCode 2.') - skipline(2) - ErrorCode=2; - return - end - - % This check can be removed ... according to the dynare parser - % strategy. - - - - % We look for the information on local computer hardware. - - si0=[]; - de0=[]; - - Environment1=Environment; - disp('Checking Hardware please wait ...'); - if (DataInput(Node).Local == 1) - if Environment, - if ~ismac - [si0 de0]=system('grep processor /proc/cpuinfo'); - else - [si0 de0]=system('sysctl -n hw.ncpu'); - Environment1=2; - end - else - [si0 de0]=system(['psinfo \\']); - end - else - if Environment, - if ~isempty(DataInput(Node).Port), - ssh_token = ['-p ',DataInput(Node).Port]; - else - ssh_token = ''; - end - if OStargetUnix, - if RemoteEnvironment ==1 , - [si0 de0]=system(['ssh ',ssh_token,' ',DataInput(Node).UserName,'@',DataInput(Node).ComputerName,' grep processor /proc/cpuinfo']); - else % it is MAC - [si0 de0]=system(['ssh ',ssh_token,' ',DataInput(Node).UserName,'@',DataInput(Node).ComputerName,' sysctl -n hw.ncpu']); - Environment1=2; - end - else - [si0 de0]=system(['ssh ',ssh_token,' ',DataInput(Node).UserName,'@',DataInput(Node).ComputerName,' psinfo']); - end - else - [si0 de0]=system(['psinfo \\',DataInput(Node).ComputerName,' -u ',DataInput(Node).UserName,' -p ',DataInput(Node).Password]); - end - end - - - RealCPUnbr=''; -% keyboard; - RealCPUnbr=GiveCPUnumber(de0,Environment1); - - % Questo controllo penso che si possa MIGLIORARE!!!!! - if isempty (RealCPUnbr) && Environment1==0, - [si0 de0]=system(['psinfo \\',DataInput(Node).ComputerName]); - end - RealCPUnbr=GiveCPUnumber(de0,Environment1); - - if isempty (RealCPUnbr) - % An error occurred when we try to know the Cpu/Cores - % numbers. - disp('It is impossible determine the number of Cpu/Processor avaiable on this machine!') - skipline() - disp('ErrorCode 2.') - skipline() - if Environment - disp('Check the command "$less /proc/cpuinfo" ... !') - else - disp('Check if the pstools are installed and are in machine path! And check the command "psinfo \\"') - end - skipline() - ErrorCode=2; - return - end - - - % Trasforming the input data provided in a form [n1:n2] in a single numerical - % value. - - - CPUnbrUser=length(DataInput(Node).CPUnbr); - maxCPUnbrUser=max(DataInput(Node).CPUnbr)+1; - - disp(['Hardware has ', num2str(RealCPUnbr),' Cpu/Cores!']) - disp(['User requires ',num2str(CPUnbrUser),' Cpu/Cores!']) - if CPUnbrUser==RealCPUnbr, - % It is Ok! - disp('Check on CPUnbr Variable ..... Ok!') - skipline(3) - end - - if CPUnbrUser > RealCPUnbr - disp('Warning! The user asks to use more CPU''s than those available.') - skipline(2) - ErrorCode=2.1; - end - if CPUnbrUser < RealCPUnbr - disp('Warning! There are unused CPU''s!') - skipline(2) - ErrorCode=2.2; - end - - if mod(length(DataInput(Node).CPUnbr),DataInput(Node).NumberOfThreadsPerJob) - skipline() - disp(['NumberOfThreadsPerJob = ',int2str(DataInput(Node).NumberOfThreadsPerJob),' is not an exact divisor of number of CPUs = ',int2str(DataInput(Node).CPUnbr),'!']) - disp([' You must re-set properly NumberOfThreadsPerJob of node ' int2str(Node) ' ' DataInput(Node).ComputerName]) - disp(' in your configuration file') - skipline() - ErrorCode=2.3; - end - - disp(['Test for Cluster computation, computer ',DataInput(Node).ComputerName, ' ..... Passed!']) - skipline(2) +function [ErrorCode] = AnalyseComputationalEnvironment(DataInput, DataInputAdd) +% PARALLEL CONTEXT +% In a parallel context, this function is used to check the cluster defined by the user. +% If no error happen the function returns 0. The function complies with +% Windows/Linux operating systems and Matlab/Octave software. +% +% +% INPUT/OUTPUT description: +% +% +% DataInput +% is the strcture option_.parallel, with the follow fields: +% +% Local 1 is on local machine, 0 remote +% ComputerName the computer name. +% CPUnbr the CPU's +% UserName the user name for the ComputerName. +% Password the password for the user name in ComputerName. +% RemoteDrive Drive used for Remote computation (data exchange, etc): must be contain 'RemoteFolder'. +% RemoteDirectory Folder in RemoteDrive used for Remote computation. +% MatlabOctavePath Path to MATLAB or Octave executable. +% DynarePath Path to matlab directory within the Dynare installation directory. +% +% This information is typed by the user in the DYNARE configuration file and is parsed by the preprocessor, +% the goal of this function is to check if configuration is correct and if dynare +% can be executed successfully in parallel mode. +% +% +% DataInputAdd +% it is the structure options_.parallel_info. Currently , only the string in the +% field RemoteTmpFolder (the temporary directory created/destroyed on remote +% computer) is used. + +if ispc, + [tempo, MasterName]=system('hostname'); + MasterName=deblank(MasterName); +end + +RemoteTmpFolder=DataInputAdd.RemoteTmpFolder; +dynareParallelMkDir(RemoteTmpFolder,DataInput); + + +% The variable ErrorCode is initialized at 0. If there are non problems with +% Local, ComputerName connections,... in general with parallel software execution, +% the ErrorCode is unchanged, in the others cases 1, 2 , ... The values +% table is below. +% +% +% Table for ErrorCode Values. +% +% ErrorCode -> 0 Initial Value -> No Error Detected!!! +% ErrorCode -> 1 ... When an error is detected, the values 1, 2, 3... are +% used to specify the type of error or warning. +% +% Value 1: The variable 'Local' has a bad value! +% +% Value 2: The variable 'CPUnbr' has a bad value. For more information +% see http://www.dynare.org/DynareWiki/ParallelDynare. +% 2.1 [warning] The user asks to use more CPU's than those available. +% 2.2 [warning] There are unused CPU's! +% 2.3 [error] NumberOfThreadsPerJob is not a divisor of CPUnbr +% +% +% Value 3: The remote computer is unreachable!!! +% +% Value 4: The fields user name and/or password are/is empty! +% +% Value 5: Remote Drive and/or Remote Folder do not exist! +% +% Value 6: It is impossible write/read files on the remote computer. +% +% Value 7: The values user and/or passwd are incorrect or the user has +% no permissions to execute a Matlab session. Or simply +% Matlab path (MatlabOctavePath) is incorrect! +% +% Value 8: Dynare path (DynarePath) is incorrect! +% +% Value 9: It is impossible delete remote computational temporary files! +% +% +% +% +% Currently when errors are detected execution simply stops and users can +% fix configuration errors according to the error type. + +% Copyright (C) 2009-2013 Dynare Team +% +% This file is part of Dynare. +% +% Dynare is free software: you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation, either version 3 of the License, or +% (at your option) any later version. +% +% Dynare is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with Dynare. If not, see <http://www.gnu.org/licenses/>. + + +ErrorCode=0; + + +for Node=1:length(DataInput) % To obtain a recoursive function remove the 'for' + % and use AnalyseComputationalEnvironment with differents input! + + + % Determine the operating system or software version when necessary + % for different command types. + + OScallerUnix=~ispc; + OScallerWindows=ispc; + OStargetUnix=strcmpi('unix',DataInput(Node).OperatingSystem); + if isempty(DataInput(Node).OperatingSystem), + OStargetUnix=OScallerUnix; + end + OStargetWindows=strcmpi('windows',DataInput(Node).OperatingSystem); + if isempty(DataInput(Node).OperatingSystem), + OStargetWindows=OScallerWindows; + end + + Environment= (OScallerUnix || OStargetUnix); + + skipline(2) + disp(['Testing computer -> ',DataInput(Node).ComputerName,' <- ...']); + skipline(2) + + % The function is composed by two main blocks, determined by the 'Local' + % variable. + + % This check can be removed ... according to the dynare parser + % strategy. + + if ((DataInput(Node).Local == 0) |(DataInput(Node).Local == 1)) + % Continue it is Ok! + disp('Check on Local Variable ..... Ok!'); + skipline() + else + disp('The variable "Local" has a bad value!'); + skipline() + disp('ErrorCode 1.'); + skipline() + ErrorCode=1; + return + end + + % %%%%%%%%%% Local (No Network) Computing %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + % Here only the multi-core, or multi-processor avaiable on local + % machine are involved in parallel computing. No network + % comunications are required! + + + % In this case we need to check only the variable 'CPUnbr'. + + % We run the parallel code on local computer, so the others fields are automatically + % fixed by Dynare parser. Then the user can also fill them with wrong values. + + + % %%%%%%%%%% Cluster Computing %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + % Here we can have many computer with multi-core, or multi-processor avaiable on the + % network and involved in parallel computing. + % So in this case we need more sophisticated check. + + + if (DataInput(Node).Local == 0) + + % Now we verify if it is possibile to be connected with the + % remote computer. + + si1=[]; + de1=[]; + + if Environment + if OScallerWindows + [si1 de1]=system(['ping ', DataInput(Node).ComputerName]); + else + [si1 de1]=system(['ping ', DataInput(Node).ComputerName, ' -c 4']); + end + else + [si1 de1]=system(['ping ', DataInput(Node).ComputerName]); + end + + if (si1) + disp(['It is impossibile to ping to the computer with name "',DataInput(Node).ComputerName,'" using the network!']) + skipline() + disp('ErrorCode 3.') + ErrorCode=3; + skipline(2) + else + disp('Check on ComputerName Variable ..... Ok!') + skipline(2) + end + + + % Now we verify if user name and password are correct and if remote + % drive and remote folder exist on the remote computer and it is + % possible to exchange data with them. + + if Environment + % This check can be removed ... according to the dynare parser + % strategy. + + if (isempty(DataInput(Node).UserName)) + disp('The fields UserName is empty!') + skipline() + disp('ErrorCode 4.') + skipline(2) + ErrorCode=4; + return + end + disp('Check on UserName Variable ..... Ok!') + skipline(2) + + % This check can be removed ... according to the dynare parser + % strategy. + if (~isempty(DataInput(Node).Password)) + disp('[WARNING] The field Password should be empty under unix or mac!'); + skipline() + disp(['Remove the string ',DataInput(Node).Password,' from this field!']) + skipline() + disp('ErrorCode 4.') + skipline(2) + ErrorCode=4; + else + disp('Check on Password Variable ..... Ok!') + skipline(2) + end + else + + % This check can be removed ... according to the dynare parser + % strategy. + + if (isempty(DataInput(Node).UserName)) || (isempty(DataInput(Node).Password)) + disp('The fields UserName and/or Password are/is empty!'); + skipline() + disp('ErrorCode 4.') + skipline(2) + ErrorCode=4; + return + end + disp('Check on UserName Variable ..... Ok!'); + skipline() + disp('Check on Password Variable ..... Ok!'); + skipline() + end + + % Now we very if RemoteDrive and/or RemoteDirectory exist on remote + % computer! + + if Environment + + % This check can be removed ... according to the dynare parser + % strategy. + + if isempty(DataInput(Node).RemoteDirectory) + disp('The field RemoteDirectory is empty!') + skipline() + disp('ErrorCode 5.') + skipline() + ErrorCode=5; + return + end + + % This check can be removed ... according to the dynare parser + % strategy. + + if (~isempty(DataInput(Node).RemoteDrive)) + disp('[WARNING] The fields RemoteDrive should be empty under unix or mac!') + skipline() + disp(['remove the string ',DataInput(Node).RemoteDrive,' from this field!']) + skipline() + disp('ErrorCode 5.') + skipline(2) + ErrorCode=5; + end + + si2=[]; + de2=[]; + if ~isempty(DataInput(Node).Port), + ssh_token = ['-p ',DataInput(Node).Port]; + else + ssh_token = ''; + end + + [si2 de2]=system(['ssh ',ssh_token,' ',DataInput(Node).UserName,'@',DataInput(Node).ComputerName,' ls ',DataInput(Node).RemoteDirectory,'/',RemoteTmpFolder,'/']); + + if (si2) + disp ('Remote Directory does not exist or is not reachable!') + skipline() + disp('ErrorCode 5.') + skipline(2) + ErrorCode=5; + return + end + + disp('Check on RemoteDirectory Variable ..... Ok!') + skipline(2) + disp('Check on RemoteDrive Variable ..... Ok!') + skipline(2) + + else + % This check can be removed ... according to the dynare parser + % strategy. + + if (isempty(DataInput(Node).RemoteDrive)||isempty(DataInput(Node).RemoteDirectory)) + disp('Remote RemoteDrive and/or RemoteDirectory is/are empty!') + skipline() + disp('ErrorCode 5.') + skipline(2) + ErrorCode=5; + return + end + + + si2=[]; + de2=[]; + [si2 de2]=system(['dir \\',DataInput(Node).ComputerName,'\',DataInput(Node).RemoteDrive,'$\',DataInput(Node).RemoteDirectory,'\',RemoteTmpFolder]); + + if (si2) + disp ('Remote Directory does not exist or it is not reachable!') + skipline() + disp('ErrorCode 5.') + skipline(2) + ErrorCode=5; + return + end + + disp('Check on RemoteDirectory Variable ..... Ok!') + skipline(2) + disp('Check on RemoteDrive Variable ..... Ok!') + skipline(2) + + end + + + % Now we verify if it possible to exchange data with the remote + % computer: + + + % Build a command file to test the matlab execution and dynare path ... + + fid = fopen('Tracing.m', 'w+'); + s1=(['fT = fopen(''MatlabOctaveIsOk.txt'',''w+'');\n']); + s2='fclose(fT);\n'; + SBS=strfind(DataInput(Node).DynarePath,'\'); + DPStr=DataInput(Node).DynarePath; + if isempty(SBS), + DPStrNew=DPStr; + else + DPStrNew=[DPStr(1:SBS(1)),'\']; + for j=2:length(SBS), + DPStrNew=[DPStrNew,DPStr(SBS(j-1)+1:SBS(j)),'\']; + end + DPStrNew=[DPStrNew,DPStr(SBS(end)+1:end)]; + end + s3=['addpath(''',DPStrNew,'''),\n']; + s4=['try,\n dynareroot = dynare_config();\n']; + s41=([' fT = fopen(''DynareIsOk.txt'',''w+'');\n']); + s42=' fclose(fT);\n'; + s5=['catch,\n']; + s51=([' fT = fopen(''DynareFailed.txt'',''w+'');\n']); + s52=' fclose(fT);\n'; + s6=['end,\n']; + s7=['if ismac,\n']; + s71=([' fT = fopen(''IsMac.txt'',''w+'');\n']); + s72=' fclose(fT);\n'; + s8=['end,\n']; + send='exit'; + StrCommand=([s1,s2,s3,s4,s41,s42,s5,s51,s52,s6,s7,s71,s72,s8,send]); + + % Mettere controllo su NbW ... + % if isoctave + % NbW = fprintf(fid,StrCommand, '%s'); + % else + NbW = fprintf(fid,StrCommand, '%s'); + % end + fclose(fid); + + dynareParallelSendFiles('Tracing.m', RemoteTmpFolder,DataInput(Node)); + FindTracing = dynareParallelDir('Tracing.m', RemoteTmpFolder,DataInput(Node)); + + delete ('Tracing.m'); + + if (isempty(FindTracing)) + disp('It is impossible to exchange data with Remote Drive and/or Remote Directory! ErrorCode 6.') + skipline() + disp('ErrorCode 6.') + skipline(2) + ErrorCode=6; + return + else + disp('Check on Exchange File with Remote Computer ..... Ok!') + skipline(2) + end + + + % Now we verify if it is possible execute a matlab/octave section on remote + % machine when the user is .UserName with password .Password and + % the path is MatlabOctavePath. + + if Environment, + if ~isempty(DataInput(Node).Port), + ssh_token = ['-p ',DataInput(Node).Port]; + else + ssh_token = ''; + end + if strfind([DataInput(Node).MatlabOctavePath], 'octave') % Hybrid computing Matlab(Master)->Octave(Slaves) and Vice Versa! + system(['ssh ',ssh_token,' ',DataInput(Node).UserName,'@',DataInput(Node).ComputerName,' "cd ',DataInput(Node).RemoteDirectory,'/',RemoteTmpFolder, '; ', DataInput(Node).MatlabOctavePath, ' Tracing.m;" &']); + else + system(['ssh ',ssh_token,' ',DataInput(Node).UserName,'@',DataInput(Node).ComputerName,' "cd ',DataInput(Node).RemoteDirectory,'/',RemoteTmpFolder, '; ', DataInput(Node).MatlabOctavePath, ' -nosplash -nodesktop -minimize -r Tracing;" &']); + end + else + if ~strcmp(DataInput(Node).ComputerName,MasterName), % run on remote machine + if strfind([DataInput(Node).MatlabOctavePath], 'octave') % Hybrid computing Matlab(Master)->Octave(Slaves) and Vice Versa! + [NonServeS NenServeD]=system(['start /B psexec \\',DataInput(Node).ComputerName,' -e -u ',DataInput(Node).UserName,' -p ',DataInput(Node).Password,' -W ',DataInput(Node).RemoteDrive,':\',DataInput(Node).RemoteDirectory,'\',RemoteTmpFolder ' -low ',DataInput(Node).MatlabOctavePath,' Tracing.m']); + else + [NonServeS NenServeD]=system(['start /B psexec \\',DataInput(Node).ComputerName,' -e -u ',DataInput(Node).UserName,' -p ',DataInput(Node).Password,' -W ',DataInput(Node).RemoteDrive,':\',DataInput(Node).RemoteDirectory,'\',RemoteTmpFolder ' -low ',DataInput(Node).MatlabOctavePath,' -nosplash -nodesktop -minimize -r Tracing']); + end + else % run on local machine via the network: user and passwd cannot be used! + if strfind([DataInput(Node).MatlabOctavePath], 'octave') % Hybrid computing Matlab(Master)->Octave(Slaves) and Vice Versa! + [NonServeS NenServeD]=system(['start /B psexec \\',DataInput(Node).ComputerName,' -e ',' -W ',DataInput(Node).RemoteDrive,':\',DataInput(Node).RemoteDirectory,'\',RemoteTmpFolder ' -low ',DataInput(Node).MatlabOctavePath,' Tracing.m']); + else + [NonServeS NenServeD]=system(['start /B psexec \\',DataInput(Node).ComputerName,' -e ',' -W ',DataInput(Node).RemoteDrive,':\',DataInput(Node).RemoteDirectory,'\',RemoteTmpFolder ' -low ',DataInput(Node).MatlabOctavePath,' -nosplash -nodesktop -minimize -r Tracing']); + end + end + + end + + % Timer da fissare, nei valori di attesa! + + t1=fix(clock); + + if t1(5)+1>60; + t2=2; + else t2=t1(5)+1; + end + + Flag=0; + + while (1); + if Flag==0 + disp('Try to run matlab/octave on remote machine ... ') + skipline() + disp('please wait ... ') + skipline() + Flag=1; + end + nt=fix(clock); + nt(5)-t2; + + if (~isempty (dynareParallelDir('MatlabOctaveIsOk.txt',RemoteTmpFolder,DataInput(Node)))) || ((nt(5)-t2)>0) + if ((nt(5)-t2)>0) + ErrorCode=7; + end + break + end + + end + + if (ErrorCode==7) + + disp ('It is not possible execute a matlab session on remote machine!') + skipline() + disp('ErrorCode 7.') + skipline(2) + ErrorCode=7; + dynareParallelRmDir(RemoteTmpFolder,DataInput(Node)); + return + else + disp('Check on MatlabOctave Path and MatlabOctave Program Execution on remote machine ..... Ok!') + skipline(2) + + % Now we verify if the DynarePath is correct ... + disp('Check the Dynare path on remote machine ... ') + skipline() + disp('please wait ... ') + skipline(2) + pause(2) + + if isempty(dynareParallelDir('DynareIsOk.txt',RemoteTmpFolder,DataInput(Node))) + ErrorCode=8; + end + + if (ErrorCode==8) + disp ('The DynarePath is incorrect!') + skipline() + disp('ErrorCode 8.') + skipline(2) + ErrorCode=8; + dynareParallelRmDir(RemoteTmpFolder,DataInput(Node)); + return + else + disp('Check on Dynare Path remote machine ..... Ok!') + if isempty(dynareParallelDir('IsMac.txt',RemoteTmpFolder,DataInput(Node))) + RemoteEnvironment=Environment; + else + RemoteEnvironment=2; + end + skipline(2) + end + end + + + % Now we verify if it is possible delete remote computational traces! + + dynareParallelRmDir(RemoteTmpFolder,DataInput(Node)); + + si3=[]; + + si3=dynareParallelDir('Tracing.m', RemoteTmpFolder,DataInput(Node)); + + if (isempty(si3)) + disp ('Check on Delete Remote Computational Traces ..... Ok!') + skipline(2) + else + disp ('It is impossible to delete temporary files on remote machine!') + skipline() + disp('ErrorCode 9.') + skipline(2) + ErrorCode=9; + return + end + + + end + % Now we check the variable 'CPUnbr'. + + % This check can be removed ... according to the dynare parser + % strategy. + + yn=isempty(DataInput(Node).CPUnbr); + + if yn==1 + % The field is empty! + disp('The field "CPUnbr" is empty!') + skipline() + disp('ErrorCode 2.') + skipline(2) + ErrorCode=2; + return + end + + % This check can be removed ... according to the dynare parser + % strategy. + + + + % We look for the information on local computer hardware. + + si0=[]; + de0=[]; + + Environment1=Environment; + disp('Checking Hardware please wait ...'); + if (DataInput(Node).Local == 1) + if Environment, + if ~ismac + [si0 de0]=system('grep processor /proc/cpuinfo'); + else + [si0 de0]=system('sysctl -n hw.ncpu'); + Environment1=2; + end + else + [si0 de0]=system(['psinfo \\']); + end + else + if Environment, + if ~isempty(DataInput(Node).Port), + ssh_token = ['-p ',DataInput(Node).Port]; + else + ssh_token = ''; + end + if OStargetUnix, + if RemoteEnvironment ==1 , + [si0 de0]=system(['ssh ',ssh_token,' ',DataInput(Node).UserName,'@',DataInput(Node).ComputerName,' grep processor /proc/cpuinfo']); + else % it is MAC + [si0 de0]=system(['ssh ',ssh_token,' ',DataInput(Node).UserName,'@',DataInput(Node).ComputerName,' sysctl -n hw.ncpu']); + Environment1=2; + end + else + [si0 de0]=system(['ssh ',ssh_token,' ',DataInput(Node).UserName,'@',DataInput(Node).ComputerName,' psinfo']); + end + else + [si0 de0]=system(['psinfo \\',DataInput(Node).ComputerName,' -u ',DataInput(Node).UserName,' -p ',DataInput(Node).Password]); + end + end + + + RealCPUnbr=''; + % keyboard; + RealCPUnbr=GiveCPUnumber(de0,Environment1); + + % Questo controllo penso che si possa MIGLIORARE!!!!! + if isempty (RealCPUnbr) && Environment1==0, + [si0 de0]=system(['psinfo \\',DataInput(Node).ComputerName]); + end + RealCPUnbr=GiveCPUnumber(de0,Environment1); + + if isempty (RealCPUnbr) + % An error occurred when we try to know the Cpu/Cores + % numbers. + disp('It is impossible determine the number of Cpu/Processor avaiable on this machine!') + skipline() + disp('ErrorCode 2.') + skipline() + if Environment + disp('Check the command "$less /proc/cpuinfo" ... !') + else + disp('Check if the pstools are installed and are in machine path! And check the command "psinfo \\"') + end + skipline() + ErrorCode=2; + return + end + + + % Trasforming the input data provided in a form [n1:n2] in a single numerical + % value. + + + CPUnbrUser=length(DataInput(Node).CPUnbr); + maxCPUnbrUser=max(DataInput(Node).CPUnbr)+1; + + disp(['Hardware has ', num2str(RealCPUnbr),' Cpu/Cores!']) + disp(['User requires ',num2str(CPUnbrUser),' Cpu/Cores!']) + if CPUnbrUser==RealCPUnbr, + % It is Ok! + disp('Check on CPUnbr Variable ..... Ok!') + skipline(3) + end + + if CPUnbrUser > RealCPUnbr + disp('Warning! The user asks to use more CPU''s than those available.') + skipline(2) + ErrorCode=2.1; + end + if CPUnbrUser < RealCPUnbr + disp('Warning! There are unused CPU''s!') + skipline(2) + ErrorCode=2.2; + end + + if mod(length(DataInput(Node).CPUnbr),DataInput(Node).NumberOfThreadsPerJob) + skipline() + disp(['NumberOfThreadsPerJob = ',int2str(DataInput(Node).NumberOfThreadsPerJob),' is not an exact divisor of number of CPUs = ',int2str(DataInput(Node).CPUnbr),'!']) + disp([' You must re-set properly NumberOfThreadsPerJob of node ' int2str(Node) ' ' DataInput(Node).ComputerName]) + disp(' in your configuration file') + skipline() + ErrorCode=2.3; + end + + disp(['Test for Cluster computation, computer ',DataInput(Node).ComputerName, ' ..... Passed!']) + skipline(2) end \ No newline at end of file diff --git a/matlab/parallel/GiveCPUnumber.m b/matlab/parallel/GiveCPUnumber.m index 00b7fc451b..b45d3f879e 100644 --- a/matlab/parallel/GiveCPUnumber.m +++ b/matlab/parallel/GiveCPUnumber.m @@ -1,76 +1,76 @@ -function [nCPU]= GiveCPUnumber (ComputerInformations, Environment) -% PARALLEL CONTEXT -% In a parallel context this function return the CPUs or cores numer avaiable -% on the computer used for run parallel code. -% -% INPUTS -% an array contained several fields that describe the hardaware -% software enviroments of a generic computer. -% -% OUTPUTS -% The CPUs or Cores numbers of computer. -% -% SPECIAL REQUIREMENTS -% none - -% Copyright (C) 2010-2013 Dynare Team -% -% This file is part of Dynare. -% -% Dynare is free software: you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation, either version 3 of the License, or -% (at your option) any later version. -% -% Dynare is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. -% -% You should have received a copy of the GNU General Public License -% along with Dynare. If not, see <http://www.gnu.org/licenses/>. - - -nCPU=''; - -if nargin < 2, -% Determine a specific operating system or software version when necessary -% for different command (sintax, name, ...). -Environment=~ispc; -end - -switch Environment - case 0 %WINDOWS OPERATING SYSTEM - - OffSet=27; - - SringPosition=strfind(ComputerInformations, 'Processors:'); - nCPU=ComputerInformations(SringPosition+OffSet); - - % We check if there are Processors/Cores more than 9. - - - t0=ComputerInformations(SringPosition+OffSet+1); - t1=str2num(t0); - t1=isempty(t1); - - % if t1 is 0 the machine have more than 9 CPU. - - if t1==0 - nCPU=strcat(nCPU,t0); - end - - nCPU=str2num(nCPU); - - return - case 1 %LIKE UNIX OPERATING SYSTEM - - % Da generalizzare a un numero di CPu maggiore di 9!!! - - nCPU=str2num(ComputerInformations(length(ComputerInformations)-1))+1; - - case 2 %MAC-OS OPERATING SYSTEM - - nCPU=str2num(ComputerInformations); - -end +function [nCPU]= GiveCPUnumber (ComputerInformations, Environment) +% PARALLEL CONTEXT +% In a parallel context this function return the CPUs or cores numer avaiable +% on the computer used for run parallel code. +% +% INPUTS +% an array contained several fields that describe the hardaware +% software enviroments of a generic computer. +% +% OUTPUTS +% The CPUs or Cores numbers of computer. +% +% SPECIAL REQUIREMENTS +% none + +% Copyright (C) 2010-2013 Dynare Team +% +% This file is part of Dynare. +% +% Dynare is free software: you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation, either version 3 of the License, or +% (at your option) any later version. +% +% Dynare is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with Dynare. If not, see <http://www.gnu.org/licenses/>. + + +nCPU=''; + +if nargin < 2, + % Determine a specific operating system or software version when necessary + % for different command (sintax, name, ...). + Environment=~ispc; +end + +switch Environment + case 0 %WINDOWS OPERATING SYSTEM + + OffSet=27; + + SringPosition=strfind(ComputerInformations, 'Processors:'); + nCPU=ComputerInformations(SringPosition+OffSet); + + % We check if there are Processors/Cores more than 9. + + + t0=ComputerInformations(SringPosition+OffSet+1); + t1=str2num(t0); + t1=isempty(t1); + + % if t1 is 0 the machine have more than 9 CPU. + + if t1==0 + nCPU=strcat(nCPU,t0); + end + + nCPU=str2num(nCPU); + + return + case 1 %LIKE UNIX OPERATING SYSTEM + + % Da generalizzare a un numero di CPu maggiore di 9!!! + + nCPU=str2num(ComputerInformations(length(ComputerInformations)-1))+1; + + case 2 %MAC-OS OPERATING SYSTEM + + nCPU=str2num(ComputerInformations); + +end diff --git a/matlab/parallel/closeSlave.m b/matlab/parallel/closeSlave.m index 339d776bb2..03e3106065 100644 --- a/matlab/parallel/closeSlave.m +++ b/matlab/parallel/closeSlave.m @@ -45,7 +45,7 @@ if partial==1 dynareParallelSendFiles('slaveParallel_break.mat',TmpFolder,Parallel(indPC)); end end -% delete('slaveParallel_break') + % delete('slaveParallel_break') return end if partial==-1 @@ -55,7 +55,7 @@ if partial==-1 dynareParallelDelete( 'slaveParallel_break.mat',TmpFolder,Parallel(indPC)); end end -% delete('slaveParallel_break') + % delete('slaveParallel_break') return end @@ -64,7 +64,7 @@ for indPC=1:length(Parallel), dynareParallelDelete( 'slaveParallel_input*.mat',TmpFolder,Parallel(indPC)); end - + delete( 'slaveParallel_input*.mat'); delete( 'slaveJob*.mat'); pause(1) @@ -86,4 +86,4 @@ while(1) end s=warning('on'); - + diff --git a/matlab/parallel/distributeJobs.m b/matlab/parallel/distributeJobs.m index 0667d902f7..65f2627a2e 100644 --- a/matlab/parallel/distributeJobs.m +++ b/matlab/parallel/distributeJobs.m @@ -92,7 +92,7 @@ for i=1:nC % JobsForNode(i)=round(JobsForNode(i)); % JobsForNode(i)=floor(JobsForNode(i)); - JobsForNode(i)=ceil(JobsForNode(i)); + JobsForNode(i)=ceil(JobsForNode(i)); end @@ -151,7 +151,7 @@ for i=1:nC % Many choices are possible: % - ... (see above). - + JobAssignedCpu=max(1,floor(JobsForNode(i)/nCPUoriginal(i))); ChekOverFlow=0; diff --git a/matlab/parallel/dynareParallelDeleteNewFiles.m b/matlab/parallel/dynareParallelDeleteNewFiles.m index e28cd77da7..4f12357ddd 100644 --- a/matlab/parallel/dynareParallelDeleteNewFiles.m +++ b/matlab/parallel/dynareParallelDeleteNewFiles.m @@ -60,11 +60,11 @@ for indPC=1:length(Parallel), exception_flag=exception_flag+(~isempty(strfind(fileaddress{2},varargin{indexc}))); end if exception_flag==0, - dynareParallelDelete(fileaddress{2},[PRCDir,fS,fileaddress{1}],Parallel(indPC)); + dynareParallelDelete(fileaddress{2},[PRCDir,fS,fileaddress{1}],Parallel(indPC)); - disp('New file deleted in remote -->'); - disp(fileaddress{2}); - disp('<--'); + disp('New file deleted in remote -->'); + disp(fileaddress{2}); + disp('<--'); end end diff --git a/matlab/parallel/dynareParallelDir.m b/matlab/parallel/dynareParallelDir.m index daecfe6cd4..6a9dd492c9 100644 --- a/matlab/parallel/dynareParallelDir.m +++ b/matlab/parallel/dynareParallelDir.m @@ -37,10 +37,10 @@ for indPC=1:length(Parallel), ssh_token = ''; end if isoctave % Patch for peculiar behaviour of ssh-ls under Linux. - % It is necessary to capture the ls warning message. - % To do it under the ssh protocol it is necessary to redirect the ls message in a text file. - % The file is 'OctaveStandardOutputMessage.txt' and it is - % saved in the Model directory. + % It is necessary to capture the ls warning message. + % To do it under the ssh protocol it is necessary to redirect the ls message in a text file. + % The file is 'OctaveStandardOutputMessage.txt' and it is + % saved in the Model directory. [check, ax]=system(['ssh ',ssh_token,' ',Parallel(indPC).UserName,'@',Parallel(indPC).ComputerName,' ls ',Parallel(indPC).RemoteDirectory,'/',PRCDir,'/',filename, ' 2> OctaveStandardOutputMessage.txt']); else [check, ax]=system(['ssh ',ssh_token,' ',Parallel(indPC).UserName,'@',Parallel(indPC).ComputerName,' ls ',Parallel(indPC).RemoteDirectory,'/',PRCDir,'/',filename]); diff --git a/matlab/parallel/dynareParallelFindNewFiles.m b/matlab/parallel/dynareParallelFindNewFiles.m index 4c6dabf36e..143f208703 100644 --- a/matlab/parallel/dynareParallelFindNewFiles.m +++ b/matlab/parallel/dynareParallelFindNewFiles.m @@ -36,7 +36,7 @@ function [NewFilesFrom, NewFileList]=dynareParallelFindNewFiles(FileList,Paralle NewFilesFrom={}; LfL=length(FileList); - % The first call ... +% The first call ... NewFileList = dynareParallelListAllFiles('Root',PRCDir,Parallel); diff --git a/matlab/parallel/dynareParallelGetFiles.m b/matlab/parallel/dynareParallelGetFiles.m index 6dbf0539e4..9ec95f3860 100644 --- a/matlab/parallel/dynareParallelGetFiles.m +++ b/matlab/parallel/dynareParallelGetFiles.m @@ -55,7 +55,7 @@ for indPC=1:length(Parallel), for jfil=1:size(NamFileInput,1), if isoctave % Patch for peculiar behaviour of ls under Linux. - % It is necessary to manage the jolly char '*'! + % It is necessary to manage the jolly char '*'! FindAst=strfind(NamFileInput{jfil,2},'comp_status_posterior_sampler_core*'); diff --git a/matlab/parallel/dynareParallelListAllFiles.m b/matlab/parallel/dynareParallelListAllFiles.m index 53e893e15c..189908b710 100644 --- a/matlab/parallel/dynareParallelListAllFiles.m +++ b/matlab/parallel/dynareParallelListAllFiles.m @@ -34,7 +34,7 @@ function fileList = dynareParallelListAllFiles(dirName,PRCDir,Parallel) if (~ispc || strcmpi('unix',Parallel.OperatingSystem)) - + fileList={}; currentPath=[]; if ~isempty(Parallel.Port), @@ -43,7 +43,7 @@ if (~ispc || strcmpi('unix',Parallel.OperatingSystem)) ssh_token = ''; end - % Get the data for the current remote directory. + % Get the data for the current remote directory. [Flag fL]=system(['ssh ',ssh_token,' ',' ',Parallel.UserName,'@',Parallel.ComputerName,' ls ',Parallel.RemoteDirectory,'/',PRCDir, ' -R -p -1']); % Format the return value fL. @@ -60,7 +60,7 @@ if (~ispc || strcmpi('unix',Parallel.OperatingSystem)) start=nL(i)+1; continue end - + if strfind(stringProcessed,'/') if strfind(stringProcessed,PRCDir) DD=strfind(stringProcessed,':'); @@ -92,7 +92,7 @@ else % Build the path files: if ~isempty(fileList) fileList = cellfun(@(x) fullfile(dirName,x),... - fileList,'UniformOutput',false); + fileList,'UniformOutput',false); end % Get a list of the subdirectories: diff --git a/matlab/parallel/dynareParallelSendFiles.m b/matlab/parallel/dynareParallelSendFiles.m index 6f7e645f55..f65697286a 100644 --- a/matlab/parallel/dynareParallelSendFiles.m +++ b/matlab/parallel/dynareParallelSendFiles.m @@ -68,9 +68,9 @@ for indPC=1:length(Parallel), % It is Necessary because Octave is not able to % create two nested directory at the same time. - % Remove (if present) the '/' chars. Can be easily transformed - % in a function. - + % Remove (if present) the '/' chars. Can be easily transformed + % in a function. + NamFileInputTemp=NamFileInput{jfil,1}; while(1) Bs=strfind(NamFileInputTemp,'/'); @@ -94,8 +94,8 @@ for indPC=1:length(Parallel), % It is Necessary because Octave is not able to % use the jolly char '*' with copyfile. - % Remove (if present) the '/' chars. Can be easily transformed - % in a function. + % Remove (if present) the '/' chars. Can be easily transformed + % in a function. NamFileInputTemp=NamFileInput{jfil,1}; while(1) diff --git a/matlab/parallel/dynareParallelSnapshot.m b/matlab/parallel/dynareParallelSnapshot.m index 4f07b04df8..ebff7a33c9 100644 --- a/matlab/parallel/dynareParallelSnapshot.m +++ b/matlab/parallel/dynareParallelSnapshot.m @@ -35,7 +35,7 @@ PRCDirSnapshot={}; for indPC=1:length(Parallel), if Parallel(indPC).Local==0; - % The first call ... + % The first call ... PRCDirSnapshot{indPC}=dynareParallelListAllFiles('Root',PRCDir,Parallel(indPC)); end diff --git a/matlab/parallel/masterParallel.m b/matlab/parallel/masterParallel.m index 902b237dc3..f5a5b50fd2 100644 --- a/matlab/parallel/masterParallel.m +++ b/matlab/parallel/masterParallel.m @@ -136,15 +136,15 @@ if isHybridMatlabOctave || isoctave end if exist('fGlobalVar','var') && ~isempty(fGlobalVar), - fInputNames = fieldnames(fGlobalVar); - for j=1:length(fInputNames), - TargetVar = fGlobalVar.(fInputNames{j}); - if isa(TargetVar,'function_handle'), - TargetVar=func2str(TargetVar); - fGlobalVar.(fInputNames{j})=TargetVar; + fInputNames = fieldnames(fGlobalVar); + for j=1:length(fInputNames), + TargetVar = fGlobalVar.(fInputNames{j}); + if isa(TargetVar,'function_handle'), + TargetVar=func2str(TargetVar); + fGlobalVar.(fInputNames{j})=TargetVar; + end end end - end end if Strategy==1 @@ -165,18 +165,18 @@ end % Save input data for use by the slaves. switch Strategy - case 0 - storeGlobalVars([fname,'_input.mat']); - save([fname,'_input.mat'],'fInputVar','Parallel','-append') - - case 1 - if exist('fGlobalVar','var'), - save(['temp_input.mat'],'fInputVar','fGlobalVar') - else - save(['temp_input.mat'],'fInputVar') - end - save(['temp_input.mat'],'Parallel','-append') - closeSlave(Parallel,PRCDir,-1); + case 0 + storeGlobalVars([fname,'_input.mat']); + save([fname,'_input.mat'],'fInputVar','Parallel','-append') + + case 1 + if exist('fGlobalVar','var'), + save(['temp_input.mat'],'fInputVar','fGlobalVar') + else + save(['temp_input.mat'],'fInputVar') + end + save(['temp_input.mat'],'Parallel','-append') + closeSlave(Parallel,PRCDir,-1); end @@ -329,35 +329,108 @@ for j=1:totCPU, for jaff=2:length(affinity_range), my_affinity = [my_affinity ',' int2str(Parallel(indPC).CPUnbr(affinity_range(jaff)))]; end -% % % int2str(Parallel(indPC).CPUnbr(j-nCPU0)) + % % % int2str(Parallel(indPC).CPUnbr(j-nCPU0)) % DA SINTETIZZARE: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % The following 'switch - case' code is the core of this function! switch Strategy - case 0 + case 0 + + if Parallel(indPC).Local == 1, % 0.1 Run on the local machine (localhost). - if Parallel(indPC).Local == 1, % 0.1 Run on the local machine (localhost). - - if ~ispc || strcmpi('unix',Parallel(indPC).OperatingSystem), % Hybrid computing Windows <-> Unix! - if regexpi([Parallel(indPC).MatlabOctavePath], 'octave') % Hybrid computing Matlab(Master)->Octave(Slaves) and Vice Versa! - command1=[Parallel(indPC).MatlabOctavePath,' -f --eval "default_save_options(''-v7''); addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); fParallel(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',''',fname,''')" &']; + if ~ispc || strcmpi('unix',Parallel(indPC).OperatingSystem), % Hybrid computing Windows <-> Unix! + if regexpi([Parallel(indPC).MatlabOctavePath], 'octave') % Hybrid computing Matlab(Master)->Octave(Slaves) and Vice Versa! + command1=[Parallel(indPC).MatlabOctavePath,' -f --eval "default_save_options(''-v7''); addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); fParallel(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',''',fname,''')" &']; + else + command1=[Parallel(indPC).MatlabOctavePath,' -nosplash -nodesktop -minimize ',compThread,' -r "addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); fParallel(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',''',fname,''')" &']; + end + else % Hybrid computing Matlab(Master)->Octave(Slaves) and Vice Versa! + if regexpi([Parallel(indPC).MatlabOctavePath], 'octave') + command1=['psexec -d -W "',DyMo, '" -a ',my_affinity,' -low ',Parallel(indPC).MatlabOctavePath,' -f --eval "default_save_options(''-v7''); addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); fParallel(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',''',fname,''')"']; + else + command1=['psexec -d -W "',DyMo, '" -a ',my_affinity,' -low ',Parallel(indPC).MatlabOctavePath,' -nosplash -nodesktop -minimize ',compThread,' -r "addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); fParallel(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',''',fname,''')"']; + end + end + else % 0.2 Parallel(indPC).Local==0: Run using network on remote machine or also on local machine. + if j==nCPU0+1, + dynareParallelSendFiles([fname,'_input.mat'],PRCDir,Parallel(indPC)); + dynareParallelSendFiles(NamFileInput,PRCDir,Parallel(indPC)); + end + + if (~ispc || strcmpi('unix',Parallel(indPC).OperatingSystem)), % Hybrid computing Windows <-> Unix! + if ispc, token='start /B '; + else token = ''; + end + if ~isempty(Parallel(indPC).Port), + ssh_token = ['-p ',Parallel(indPC).Port]; + else + ssh_token = ''; + end + % To manage the diferences in Unix/Windows OS syntax. + remoteFile=['remoteDynare',int2str(j)]; + fidRemote=fopen([remoteFile,'.m'],'w+'); + if regexpi([Parallel(indPC).MatlabOctavePath], 'octave'),% Hybrid computing Matlab(Master)->Octave(Slaves) and Vice Versa! + remoteString=['default_save_options(''-v7''); addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); fParallel(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',''',fname,''')']; + command1=[token, 'ssh ',ssh_token,' ',Parallel(indPC).UserName,'@',Parallel(indPC).ComputerName,' "cd ',Parallel(indPC).RemoteDirectory,'/',PRCDir, '; ',Parallel(indPC).MatlabOctavePath,' -f --eval ',remoteFile,' " &']; + else + remoteString=['addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); fParallel(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',''',fname,''')']; + command1=[token, 'ssh ',ssh_token,' ',Parallel(indPC).UserName,'@',Parallel(indPC).ComputerName,' "cd ',Parallel(indPC).RemoteDirectory,'/',PRCDir, '; ',Parallel(indPC).MatlabOctavePath,' -nosplash -nodesktop -minimize ',compThread,' -r ',remoteFile,';" &']; + end + fprintf(fidRemote,'%s\n',remoteString); + fclose(fidRemote); + dynareParallelSendFiles([remoteFile,'.m'],PRCDir,Parallel(indPC)); + delete([remoteFile,'.m']); + else + if ~strcmpi(Parallel(indPC).ComputerName,MasterName), % 0.3 Run on a remote machine! + % Hybrid computing Matlab(Master)-> Octave(Slaves) and Vice Versa! + if regexpi([Parallel(indPC).MatlabOctavePath], 'octave') + command1=['psexec \\',Parallel(indPC).ComputerName,' -d -e -u ',Parallel(indPC).UserName,' -p ',Parallel(indPC).Password,' -W "',Parallel(indPC).RemoteDrive,':\',Parallel(indPC).RemoteDirectory,'\',PRCDir,'\" -a ',my_affinity, ... + ' -low ',Parallel(indPC).MatlabOctavePath,' -f --eval "default_save_options(''-v7''); addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); fParallel(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',''',fname,''')"']; else - command1=[Parallel(indPC).MatlabOctavePath,' -nosplash -nodesktop -minimize ',compThread,' -r "addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); fParallel(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',''',fname,''')" &']; + + command1=['psexec \\',Parallel(indPC).ComputerName,' -d -e -u ',Parallel(indPC).UserName,' -p ',Parallel(indPC).Password,' -W "',Parallel(indPC).RemoteDrive,':\',Parallel(indPC).RemoteDirectory,'\',PRCDir,'\" -a ',my_affinity, ... + ' -low ',Parallel(indPC).MatlabOctavePath,' -nosplash -nodesktop -minimize ',compThread,' -r "addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); fParallel(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',''',fname,''')"']; end - else % Hybrid computing Matlab(Master)->Octave(Slaves) and Vice Versa! + else % 0.4 Run on the local machine via the network + % Hybrid computing Matlab(Master)->Octave(Slaves) and Vice Versa! if regexpi([Parallel(indPC).MatlabOctavePath], 'octave') - command1=['psexec -d -W "',DyMo, '" -a ',my_affinity,' -low ',Parallel(indPC).MatlabOctavePath,' -f --eval "default_save_options(''-v7''); addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); fParallel(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',''',fname,''')"']; + command1=['psexec \\',Parallel(indPC).ComputerName,' -d -e -W "',Parallel(indPC).RemoteDrive,':\',Parallel(indPC).RemoteDirectory,'\',PRCDir,'\" -a ',my_affinity, ... + ' -low ',Parallel(indPC).MatlabOctavePath,' -f --eval "default_save_options(''-v7''); addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); fParallel(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',''',fname,''')"']; else - command1=['psexec -d -W "',DyMo, '" -a ',my_affinity,' -low ',Parallel(indPC).MatlabOctavePath,' -nosplash -nodesktop -minimize ',compThread,' -r "addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); fParallel(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',''',fname,''')"']; + command1=['psexec \\',Parallel(indPC).ComputerName,' -d -e -W "',Parallel(indPC).RemoteDrive,':\',Parallel(indPC).RemoteDirectory,'\',PRCDir,'\" -a ',my_affinity, ... + ' -low ',Parallel(indPC).MatlabOctavePath,' -nosplash -nodesktop -minimize ',compThread,' -r "addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); fParallel(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',''',fname,''')"']; end end - else % 0.2 Parallel(indPC).Local==0: Run using network on remote machine or also on local machine. - if j==nCPU0+1, - dynareParallelSendFiles([fname,'_input.mat'],PRCDir,Parallel(indPC)); - dynareParallelSendFiles(NamFileInput,PRCDir,Parallel(indPC)); + end + end + + + case 1 + if Parallel(indPC).Local == 1 && newInstance, % 1.1 Run on the local machine. + if (~ispc || strcmpi('unix',Parallel(indPC).OperatingSystem)), % Hybrid computing Windows <-> Unix! + if regexpi([Parallel(indPC).MatlabOctavePath], 'octave') % Hybrid computing Matlab(Master)-> Octave(Slaves) and Vice Versa! + command1=[Parallel(indPC).MatlabOctavePath,' -f --eval "default_save_options(''-v7''); addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); slaveParallel(',int2str(j),',',int2str(indPC),')" &']; + else + command1=[Parallel(indPC).MatlabOctavePath,' -nosplash -nodesktop -minimize ',compThread,' -r "addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); slaveParallel(',int2str(j),',',int2str(indPC),')" &']; end - + else % Hybrid computing Matlab(Master)->Octave(Slaves) and Vice Versa! + if regexpi([Parallel(indPC).MatlabOctavePath], 'octave') + command1=['psexec -d -W "',DyMo, '" -a ',my_affinity,' -low ',Parallel(indPC).MatlabOctavePath,' -f --eval "default_save_options(''-v7'');addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); slaveParallel(',int2str(j),',',int2str(indPC),')"']; + else + command1=['psexec -d -W "',DyMo, '" -a ',my_affinity,' -low ',Parallel(indPC).MatlabOctavePath,' -nosplash -nodesktop -minimize ',compThread,' -r "addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); slaveParallel(',int2str(j),',',int2str(indPC),')"']; + end + end + elseif Parallel(indPC).Local==0, % 1.2 Run using network on remote machine or also on local machine. + if j==nCPU0+1, + dynareParallelSendFiles(NamFileInput,PRCDir,Parallel(indPC)); + end + dynareParallelSendFiles(['P_',fname,'_',int2str(j),'End.txt'],PRCDir,Parallel(indPC)); + delete(['P_',fname,'_',int2str(j),'End.txt']); + if newInstance, + dynareParallelSendFiles(['slaveJob',int2str(j),'.mat'],PRCDir,Parallel(indPC)); + delete(['slaveJob',int2str(j),'.mat']); + dynareParallelSendFiles(['slaveParallel_input',int2str(j),'.mat'],PRCDir,Parallel(indPC)) if (~ispc || strcmpi('unix',Parallel(indPC).OperatingSystem)), % Hybrid computing Windows <-> Unix! if ispc, token='start /B '; else token = ''; @@ -370,128 +443,55 @@ for j=1:totCPU, % To manage the diferences in Unix/Windows OS syntax. remoteFile=['remoteDynare',int2str(j)]; fidRemote=fopen([remoteFile,'.m'],'w+'); - if regexpi([Parallel(indPC).MatlabOctavePath], 'octave'),% Hybrid computing Matlab(Master)->Octave(Slaves) and Vice Versa! - remoteString=['default_save_options(''-v7''); addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); fParallel(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',''',fname,''')']; - command1=[token, 'ssh ',ssh_token,' ',Parallel(indPC).UserName,'@',Parallel(indPC).ComputerName,' "cd ',Parallel(indPC).RemoteDirectory,'/',PRCDir, '; ',Parallel(indPC).MatlabOctavePath,' -f --eval ',remoteFile,' " &']; + if regexpi([Parallel(indPC).MatlabOctavePath], 'octave') % Hybrid computing Matlab(Master)-> Octave(Slaves) and Vice Versa! + remoteString=['default_save_options(''-v7''); addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); slaveParallel(',int2str(j),',',int2str(indPC),');']; + command1=[token, 'ssh ',ssh_token,' ',Parallel(indPC).UserName,'@',Parallel(indPC).ComputerName,' "cd ',Parallel(indPC).RemoteDirectory,'/',PRCDir '; ',Parallel(indPC).MatlabOctavePath,' -f --eval ',remoteFile,' " &']; else - remoteString=['addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); fParallel(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',''',fname,''')']; - command1=[token, 'ssh ',ssh_token,' ',Parallel(indPC).UserName,'@',Parallel(indPC).ComputerName,' "cd ',Parallel(indPC).RemoteDirectory,'/',PRCDir, '; ',Parallel(indPC).MatlabOctavePath,' -nosplash -nodesktop -minimize ',compThread,' -r ',remoteFile,';" &']; + remoteString=['addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); slaveParallel(',int2str(j),',',int2str(indPC),');']; + command1=[token, 'ssh ',ssh_token,' ',Parallel(indPC).UserName,'@',Parallel(indPC).ComputerName,' "cd ',Parallel(indPC).RemoteDirectory,'/',PRCDir '; ',Parallel(indPC).MatlabOctavePath,' -nosplash -nodesktop -minimize ',compThread,' -r ',remoteFile,';" &']; end fprintf(fidRemote,'%s\n',remoteString); fclose(fidRemote); dynareParallelSendFiles([remoteFile,'.m'],PRCDir,Parallel(indPC)); delete([remoteFile,'.m']); else - if ~strcmpi(Parallel(indPC).ComputerName,MasterName), % 0.3 Run on a remote machine! - % Hybrid computing Matlab(Master)-> Octave(Slaves) and Vice Versa! + if ~strcmpi(Parallel(indPC).ComputerName,MasterName), % 1.3 Run on a remote machine. + % Hybrid computing Matlab(Master)->Octave(Slaves) and Vice Versa! if regexpi([Parallel(indPC).MatlabOctavePath], 'octave') command1=['psexec \\',Parallel(indPC).ComputerName,' -d -e -u ',Parallel(indPC).UserName,' -p ',Parallel(indPC).Password,' -W "',Parallel(indPC).RemoteDrive,':\',Parallel(indPC).RemoteDirectory,'\',PRCDir,'\" -a ',my_affinity, ... - ' -low ',Parallel(indPC).MatlabOctavePath,' -f --eval "default_save_options(''-v7''); addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); fParallel(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',''',fname,''')"']; + ' -low ',Parallel(indPC).MatlabOctavePath,' -f --eval "default_save_options(''-v7'');addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); slaveParallel(',int2str(j),',',int2str(indPC),')"']; else - command1=['psexec \\',Parallel(indPC).ComputerName,' -d -e -u ',Parallel(indPC).UserName,' -p ',Parallel(indPC).Password,' -W "',Parallel(indPC).RemoteDrive,':\',Parallel(indPC).RemoteDirectory,'\',PRCDir,'\" -a ',my_affinity, ... - ' -low ',Parallel(indPC).MatlabOctavePath,' -nosplash -nodesktop -minimize ',compThread,' -r "addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); fParallel(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',''',fname,''')"']; + ' -low ',Parallel(indPC).MatlabOctavePath,' -nosplash -nodesktop -minimize ',compThread,' -r "addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); slaveParallel(',int2str(j),',',int2str(indPC),')"']; end - else % 0.4 Run on the local machine via the network - % Hybrid computing Matlab(Master)->Octave(Slaves) and Vice Versa! + else % 1.4 Run on the local machine via the network. + % Hybrid computing Matlab(Master)->Octave(Slaves) and Vice Versa! if regexpi([Parallel(indPC).MatlabOctavePath], 'octave') command1=['psexec \\',Parallel(indPC).ComputerName,' -d -e -W "',Parallel(indPC).RemoteDrive,':\',Parallel(indPC).RemoteDirectory,'\',PRCDir,'\" -a ',my_affinity, ... - ' -low ',Parallel(indPC).MatlabOctavePath,' -f --eval "default_save_options(''-v7''); addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); fParallel(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',''',fname,''')"']; + ' -low ',Parallel(indPC).MatlabOctavePath,' -f --eval "default_save_options(''-v7''); addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); slaveParallel(',int2str(j),',',int2str(indPC),')"']; else command1=['psexec \\',Parallel(indPC).ComputerName,' -d -e -W "',Parallel(indPC).RemoteDrive,':\',Parallel(indPC).RemoteDirectory,'\',PRCDir,'\" -a ',my_affinity, ... - ' -low ',Parallel(indPC).MatlabOctavePath,' -nosplash -nodesktop -minimize ',compThread,' -r "addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); fParallel(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',''',fname,''')"']; + ' -low ',Parallel(indPC).MatlabOctavePath,' -nosplash -nodesktop -minimize ',compThread,' -r "addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); slaveParallel(',int2str(j),',',int2str(indPC),')"']; end end end - end - - - case 1 - if Parallel(indPC).Local == 1 && newInstance, % 1.1 Run on the local machine. - if (~ispc || strcmpi('unix',Parallel(indPC).OperatingSystem)), % Hybrid computing Windows <-> Unix! - if regexpi([Parallel(indPC).MatlabOctavePath], 'octave') % Hybrid computing Matlab(Master)-> Octave(Slaves) and Vice Versa! - command1=[Parallel(indPC).MatlabOctavePath,' -f --eval "default_save_options(''-v7''); addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); slaveParallel(',int2str(j),',',int2str(indPC),')" &']; - else - command1=[Parallel(indPC).MatlabOctavePath,' -nosplash -nodesktop -minimize ',compThread,' -r "addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); slaveParallel(',int2str(j),',',int2str(indPC),')" &']; - end - else % Hybrid computing Matlab(Master)->Octave(Slaves) and Vice Versa! - if regexpi([Parallel(indPC).MatlabOctavePath], 'octave') - command1=['psexec -d -W "',DyMo, '" -a ',my_affinity,' -low ',Parallel(indPC).MatlabOctavePath,' -f --eval "default_save_options(''-v7'');addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); slaveParallel(',int2str(j),',',int2str(indPC),')"']; - else - command1=['psexec -d -W "',DyMo, '" -a ',my_affinity,' -low ',Parallel(indPC).MatlabOctavePath,' -nosplash -nodesktop -minimize ',compThread,' -r "addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); slaveParallel(',int2str(j),',',int2str(indPC),')"']; - end - end - elseif Parallel(indPC).Local==0, % 1.2 Run using network on remote machine or also on local machine. - if j==nCPU0+1, - dynareParallelSendFiles(NamFileInput,PRCDir,Parallel(indPC)); - end - dynareParallelSendFiles(['P_',fname,'_',int2str(j),'End.txt'],PRCDir,Parallel(indPC)); - delete(['P_',fname,'_',int2str(j),'End.txt']); - if newInstance, - dynareParallelSendFiles(['slaveJob',int2str(j),'.mat'],PRCDir,Parallel(indPC)); - delete(['slaveJob',int2str(j),'.mat']); - dynareParallelSendFiles(['slaveParallel_input',int2str(j),'.mat'],PRCDir,Parallel(indPC)) - if (~ispc || strcmpi('unix',Parallel(indPC).OperatingSystem)), % Hybrid computing Windows <-> Unix! - if ispc, token='start /B '; - else token = ''; - end - if ~isempty(Parallel(indPC).Port), - ssh_token = ['-p ',Parallel(indPC).Port]; - else - ssh_token = ''; - end - % To manage the diferences in Unix/Windows OS syntax. - remoteFile=['remoteDynare',int2str(j)]; - fidRemote=fopen([remoteFile,'.m'],'w+'); - if regexpi([Parallel(indPC).MatlabOctavePath], 'octave') % Hybrid computing Matlab(Master)-> Octave(Slaves) and Vice Versa! - remoteString=['default_save_options(''-v7''); addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); slaveParallel(',int2str(j),',',int2str(indPC),');']; - command1=[token, 'ssh ',ssh_token,' ',Parallel(indPC).UserName,'@',Parallel(indPC).ComputerName,' "cd ',Parallel(indPC).RemoteDirectory,'/',PRCDir '; ',Parallel(indPC).MatlabOctavePath,' -f --eval ',remoteFile,' " &']; - else - remoteString=['addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); slaveParallel(',int2str(j),',',int2str(indPC),');']; - command1=[token, 'ssh ',ssh_token,' ',Parallel(indPC).UserName,'@',Parallel(indPC).ComputerName,' "cd ',Parallel(indPC).RemoteDirectory,'/',PRCDir '; ',Parallel(indPC).MatlabOctavePath,' -nosplash -nodesktop -minimize ',compThread,' -r ',remoteFile,';" &']; - end - fprintf(fidRemote,'%s\n',remoteString); - fclose(fidRemote); - dynareParallelSendFiles([remoteFile,'.m'],PRCDir,Parallel(indPC)); - delete([remoteFile,'.m']); - else - if ~strcmpi(Parallel(indPC).ComputerName,MasterName), % 1.3 Run on a remote machine. - % Hybrid computing Matlab(Master)->Octave(Slaves) and Vice Versa! - if regexpi([Parallel(indPC).MatlabOctavePath], 'octave') - command1=['psexec \\',Parallel(indPC).ComputerName,' -d -e -u ',Parallel(indPC).UserName,' -p ',Parallel(indPC).Password,' -W "',Parallel(indPC).RemoteDrive,':\',Parallel(indPC).RemoteDirectory,'\',PRCDir,'\" -a ',my_affinity, ... - ' -low ',Parallel(indPC).MatlabOctavePath,' -f --eval "default_save_options(''-v7'');addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); slaveParallel(',int2str(j),',',int2str(indPC),')"']; - else - command1=['psexec \\',Parallel(indPC).ComputerName,' -d -e -u ',Parallel(indPC).UserName,' -p ',Parallel(indPC).Password,' -W "',Parallel(indPC).RemoteDrive,':\',Parallel(indPC).RemoteDirectory,'\',PRCDir,'\" -a ',my_affinity, ... - ' -low ',Parallel(indPC).MatlabOctavePath,' -nosplash -nodesktop -minimize ',compThread,' -r "addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); slaveParallel(',int2str(j),',',int2str(indPC),')"']; - end - else % 1.4 Run on the local machine via the network. - % Hybrid computing Matlab(Master)->Octave(Slaves) and Vice Versa! - if regexpi([Parallel(indPC).MatlabOctavePath], 'octave') - command1=['psexec \\',Parallel(indPC).ComputerName,' -d -e -W "',Parallel(indPC).RemoteDrive,':\',Parallel(indPC).RemoteDirectory,'\',PRCDir,'\" -a ',my_affinity, ... - ' -low ',Parallel(indPC).MatlabOctavePath,' -f --eval "default_save_options(''-v7''); addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); slaveParallel(',int2str(j),',',int2str(indPC),')"']; - else - command1=['psexec \\',Parallel(indPC).ComputerName,' -d -e -W "',Parallel(indPC).RemoteDrive,':\',Parallel(indPC).RemoteDirectory,'\',PRCDir,'\" -a ',my_affinity, ... - ' -low ',Parallel(indPC).MatlabOctavePath,' -nosplash -nodesktop -minimize ',compThread,' -r "addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); slaveParallel(',int2str(j),',',int2str(indPC),')"']; - end - end - end + else + % When the user user strategy is equal to 1, you must + % do PRCDirSnapshot here to to avoid problems of + % synchronization. + + if isempty(PRCDirSnapshot{indPC}), + PRCDirSnapshot(indPC)=dynareParallelSnapshot(PRCDir,Parallel(indPC)); + PRCDirSnapshotInit(indPC) = PRCDirSnapshot(indPC); else - % When the user user strategy is equal to 1, you must - % do PRCDirSnapshot here to to avoid problems of - % synchronization. - - if isempty(PRCDirSnapshot{indPC}), - PRCDirSnapshot(indPC)=dynareParallelSnapshot(PRCDir,Parallel(indPC)); - PRCDirSnapshotInit(indPC) = PRCDirSnapshot(indPC); - else - PRCDirSnapshot(indPC)=dynareParallelGetNewFiles(PRCDir,Parallel(indPC),PRCDirSnapshot(indPC)); - end - dynareParallelSendFiles(['slaveJob',int2str(j),'.mat'],PRCDir,Parallel(indPC)); - delete(['slaveJob',int2str(j),'.mat']); - + PRCDirSnapshot(indPC)=dynareParallelGetNewFiles(PRCDir,Parallel(indPC),PRCDirSnapshot(indPC)); end + dynareParallelSendFiles(['slaveJob',int2str(j),'.mat'],PRCDir,Parallel(indPC)); + delete(['slaveJob',int2str(j),'.mat']); + end - + end + end fprintf(fid,'%s\n',command1); @@ -549,18 +549,18 @@ if isoctave || options_.console_mode end else hfigstatus = figure('name',['Parallel ',fname],... - 'DockControls','off', ... - 'IntegerHandle','off', ... - 'Interruptible','off', ... - 'MenuBar', 'none', ... - 'NumberTitle','off', ... - 'Renderer','Painters', ... - 'Resize','off'); + 'DockControls','off', ... + 'IntegerHandle','off', ... + 'Interruptible','off', ... + 'MenuBar', 'none', ... + 'NumberTitle','off', ... + 'Renderer','Painters', ... + 'Resize','off'); ncol = ceil(totCPU/10); hspace = 0.9/ncol; hstatus(1) = axes('position',[0.05/ncol 0.92 0.9/ncol 0.03], ... - 'box','on','xtick',[],'ytick',[],'xlim',[0 1],'ylim',[0 1]); + 'box','on','xtick',[],'ytick',[],'xlim',[0 1],'ylim',[0 1]); set(hstatus(1),'Units','pixels') hpixel = get(hstatus(1),'Position'); hfigure = get(hfigstatus,'Position'); @@ -573,7 +573,7 @@ else jrow = mod(j-1,10)+1; jcol = ceil(j/10); hstatus(j) = axes('position',[0.05/ncol+(jcol-1)/ncol vstart-vspace*(jrow-1) 0.9/ncol 0.3*vspace], ... - 'box','on','xtick',[],'ytick',[],'xlim',[0 1],'ylim',[0 1]); + 'box','on','xtick',[],'ytick',[],'xlim',[0 1],'ylim',[0 1]); hpat(j) = patch([0 0 0 0],[0 1 1 0],'r','EdgeColor','r'); htit(j) = title(['Initialize ...']); @@ -667,7 +667,7 @@ while (ForEver) try if ~isempty(['comp_status_',fname,int2str(j),'.mat']) load(['comp_status_',fname,int2str(j),'.mat']); -% whoCloseAllSlaves = who(['comp_status_',fname,int2str(j),'.mat','CloseAllSlaves']); + % whoCloseAllSlaves = who(['comp_status_',fname,int2str(j),'.mat','CloseAllSlaves']); if exist('CloseAllSlaves') && flag_CloseAllSlaves==0, flag_CloseAllSlaves=1; whoiamCloseAllSlaves=j; @@ -687,7 +687,7 @@ while (ForEver) status_Title{j} = waitbarTitle; end catch % ME - % To define! + % To define! if isoctave || options_.console_mode if (~ispc || strcmpi('unix',Parallel(indPC).OperatingSystem)) statusString = [statusString, int2str(j), ' %3.f%% done! ']; @@ -804,7 +804,7 @@ for j=1:totCPU, end end for k=1:size(tmp1,1), - dynareParallelGetFiles([OutputFileName(i,1) {tmp1(k,:)}],PRCDir,Parallel(indPC)); + dynareParallelGetFiles([OutputFileName(i,1) {tmp1(k,:)}],PRCDir,Parallel(indPC)); end end % check if some output file is missing! @@ -856,46 +856,46 @@ pause(1), % Wait for all remote diary off completed dynareParallelGetFiles('*.log',PRCDir,Parallel(1:totSlaves)); switch Strategy - case 0 - for indPC=1:min(find(nCPU>=totCPU)), - if Parallel(indPC).Local == 0 - dynareParallelRmDir(PRCDir,Parallel(indPC)); - end - - if isempty(dir('dynareParallelLogFiles')) - [A B C]=rmdir('dynareParallelLogFiles'); - mkdir('dynareParallelLogFiles'); - end - try - copyfile('*.log','dynareParallelLogFiles'); - mydelete([fname,'*.log']); - catch - end - - mydelete(['*_core*_input*.mat']); - + case 0 + for indPC=1:min(find(nCPU>=totCPU)), + if Parallel(indPC).Local == 0 + dynareParallelRmDir(PRCDir,Parallel(indPC)); end - delete ConcurrentCommand1.bat - case 1 - delete(['temp_input.mat']) - if newInstance, - if isempty(dir('dynareParallelLogFiles')) - [A B C]=rmdir('dynareParallelLogFiles'); - mkdir('dynareParallelLogFiles'); - end + if isempty(dir('dynareParallelLogFiles')) + [A B C]=rmdir('dynareParallelLogFiles'); + mkdir('dynareParallelLogFiles'); end - copyfile('*.log','dynareParallelLogFiles'); - if newInstance, - delete ConcurrentCommand1.bat + try + copyfile('*.log','dynareParallelLogFiles'); + mydelete([fname,'*.log']); + catch end - dynareParallelDelete(['comp_status_',fname,'*.mat'],PRCDir,Parallel); - for indPC=1:min(find(nCPU>=totCPU)), - if Parallel(indPC).Local == 0, - dynareParallelDeleteNewFiles(PRCDir,Parallel(indPC),PRCDirSnapshotInit(indPC),'.log'); - for ifil=1:size(NamFileInput,1), - dynareParallelDelete([NamFileInput{ifil,:}],PRCDir,Parallel(indPC)); - end + + mydelete(['*_core*_input*.mat']); + + end + + delete ConcurrentCommand1.bat + case 1 + delete(['temp_input.mat']) + if newInstance, + if isempty(dir('dynareParallelLogFiles')) + [A B C]=rmdir('dynareParallelLogFiles'); + mkdir('dynareParallelLogFiles'); + end + end + copyfile('*.log','dynareParallelLogFiles'); + if newInstance, + delete ConcurrentCommand1.bat + end + dynareParallelDelete(['comp_status_',fname,'*.mat'],PRCDir,Parallel); + for indPC=1:min(find(nCPU>=totCPU)), + if Parallel(indPC).Local == 0, + dynareParallelDeleteNewFiles(PRCDir,Parallel(indPC),PRCDirSnapshotInit(indPC),'.log'); + for ifil=1:size(NamFileInput,1), + dynareParallelDelete([NamFileInput{ifil,:}],PRCDir,Parallel(indPC)); end end + end end \ No newline at end of file diff --git a/matlab/parallel/slaveParallel.m b/matlab/parallel/slaveParallel.m index d7275a4fdb..5de3115757 100644 --- a/matlab/parallel/slaveParallel.m +++ b/matlab/parallel/slaveParallel.m @@ -136,7 +136,7 @@ while (etime(clock,t0)<1200 && ~isempty(fslave)) || ~isempty(dir(['stayalive',in % Save the output result. save([ fname,'_output_',int2str(whoiam),'.mat'],'fOutputVar' ); -% keyboard, + % keyboard, if isfield(fOutputVar,'CloseAllSlaves'), CloseAllSlaves = 1; fOutputVar = rmfield(fOutputVar,'CloseAllSlaves'); diff --git a/matlab/perfect-foresight-models/det_cond_forecast.m b/matlab/perfect-foresight-models/det_cond_forecast.m index 38d72d3459..df64df222f 100644 --- a/matlab/perfect-foresight-models/det_cond_forecast.m +++ b/matlab/perfect-foresight-models/det_cond_forecast.m @@ -34,7 +34,7 @@ pp = 2; initial_conditions = oo_.steady_state; verbosity = options_.verbosity; if options_.periods == 0 - options_.periods = 25; + options_.periods = 25; end; %We have to get an initial guess for the conditional forecast % and terminal conditions for the non-stationary variables, we @@ -82,7 +82,7 @@ if length(varargin) > 3 error(['Unknown exogenous variable ' controlled_varexo(i,:)]); end end - + else % alternative way to call: plan, dset, dates_of_frcst plan = varargin{1}; @@ -105,7 +105,7 @@ else sym_dset = dset(dates(-range(1)):dates(range(range.ndat))); periods = options_.periods + M_.maximum_lag + M_.maximum_lead; - total_periods = periods + range.ndat; + total_periods = periods + range.ndat; if isfield(oo_, 'exo_simul') if size(oo_.exo_simul, 1) ~= total_periods oo_.exo_simul = repmat(oo_.exo_steady_state',total_periods,1); @@ -121,14 +121,14 @@ else if ~isempty(iy) oo_.endo_simul(iy,1:sym_dset.nobs) = sym_dset.data(:, i); initial_conditions(iy) = sym_dset.data(1, i); - else - ix = find(strcmp(strtrim(sym_dset.name{i}), strtrim(plan.exo_names))); - if ~isempty(ix) - oo_.exo_simul(1, ix) = sym_dset.data(1, i)'; + else + ix = find(strcmp(strtrim(sym_dset.name{i}), strtrim(plan.exo_names))); + if ~isempty(ix) + oo_.exo_simul(1, ix) = sym_dset.data(1, i)'; else %warning(['The variable ' sym_dset.name{i} ' in the dataset ' inputname(2) ' is not a endogenous neither an exogenous variable!!']); end - end + end end for i = 1:length(M_.aux_vars) if M_.aux_vars(i).type == 1 %lag variable @@ -146,8 +146,8 @@ else %Compute the initial path using the the steady-state % steady-state %for jj = 2 : (options_.periods + 2) - for jj = 2 : (range.ndat + 2) - oo_.endo_simul(:, jj) = oo_.steady_state; + for jj = 2 : (range.ndat + 2) + oo_.endo_simul(:, jj) = oo_.steady_state; end missings = isnan(oo_.endo_simul(:,1)); if any(missings) @@ -165,11 +165,11 @@ else options_.dynatol.f = save_options_dynatol_f; if Info == 0 - oo_.endo_simul = endo; - oo_.exo_simul = exo; + oo_.endo_simul = endo; + oo_.exo_simul = exo; end endo = endo'; - endo_l = size(endo(1+M_.maximum_lag:end,:),1); + endo_l = size(endo(1+M_.maximum_lag:end,:),1); jrng = dates(plan.date(1)):dates(plan.date(1)+endo_l); data_set = dseries(nan(endo_l, dset.vobs), plan.date(1), dset.name); for i = 1:length(dset.name) @@ -179,7 +179,7 @@ else else pos = find(strcmp(dset.name{i},plan.exo_names)); if ~isempty(pos) - data_set{dset.name{i}} = dseries(exo(1+M_.maximum_lag:end,pos), plan.date(1),dset.name{i}); + data_set{dset.name{i}} = dseries(exo(1+M_.maximum_lag:end,pos), plan.date(1),dset.name{i}); end end end @@ -209,9 +209,9 @@ else return; end; else - error('impossible case'); + error('impossible case'); end; - + else oo_.exo_simul = repmat(oo_.exo_steady_state',options_.periods+2,1); oo_.endo_simul = repmat(oo_.steady_state, 1, options_.periods+2); @@ -536,19 +536,19 @@ if pf && ~surprise end; -% col_count = 1; -% for j = controlled_varexo' -% for time = time_index_constraint -% saved = oo_.exo_simul(time,j); -% oo_.exo_simul(time,j) = oo_.exo_simul(time,j) + eps1; -% simul(); -% J1(:,col_count) = (oo_.endo_simul(indx_endo) - ys) / eps1; -% oo_.exo_simul(time,j) = saved; -% col_count = col_count + 1; -% end; -% end; -% J1 -% sdfmlksdf; + % col_count = 1; + % for j = controlled_varexo' + % for time = time_index_constraint + % saved = oo_.exo_simul(time,j); + % oo_.exo_simul(time,j) = oo_.exo_simul(time,j) + eps1; + % simul(); + % J1(:,col_count) = (oo_.endo_simul(indx_endo) - ys) / eps1; + % oo_.exo_simul(time,j) = saved; + % col_count = col_count + 1; + % end; + % end; + % J1 + % sdfmlksdf; disp(['iteration ' int2str(it) ' error = ' num2str(normr)]); @@ -582,7 +582,7 @@ else else pf = length(indx_endo_solve_pf); end; - + [pos_constrained_surprise, junk] = find((1-constrained_perfect_foresight) .* is_constraint(t, :)'); indx_endo_solve_surprise = constrained_vars(pos_constrained_surprise); @@ -601,7 +601,7 @@ else else b_pf = length(indx_endo_solve_pf); end; - + [pos_shock_surprise, junk] = find((1-shock_perfect_foresight) .* is_shock(t, :)'); indx_endo_solve_surprise = shock_vars(pos_shock_surprise); @@ -822,34 +822,34 @@ else end; -% % Numerical computation of the derivatives in the second systme -% J1 = []; -% col_count = 1; -% for j = constraint_index_t -% j_pos = controlled_varexo(j); -% if constrained_perfect_foresight(j) -% for time = time_index_constraint -% saved = oo_.exo_simul(time,j_pos); -% oo_.exo_simul(time,j_pos) = oo_.exo_simul(time,j_pos) + eps1; -% simul(); -% J1(:,col_count) = (oo_.endo_simul(indx_endo) - ys) / eps1; -% oo_.exo_simul(time,j_pos) = saved; -% col_count = col_count + 1; -% end; -% else -% saved = oo_.exo_simul(maximum_lag+1,j_pos); -% oo_.exo_simul(maximum_lag+1,j_pos) = oo_.exo_simul(maximum_lag+1,j_pos) + eps1; -% simul(); -% % indx_endo -% J1(:,col_count) = (oo_.endo_simul(indx_endo) - ys) / eps1; -% % J(:,col_count) = (oo_.endo_simul((pp - 1) * M_.endo_nbr + 1: pp * M_.endo_nbr) - ys) / eps1; -% oo_.exo_simul(maximum_lag+1,j_pos) = saved; -% col_count = col_count + 1; -% end; -% end; -% disp('J1'); -% disp(full(J1)); -% sdfmlk; + % % Numerical computation of the derivatives in the second systme + % J1 = []; + % col_count = 1; + % for j = constraint_index_t + % j_pos = controlled_varexo(j); + % if constrained_perfect_foresight(j) + % for time = time_index_constraint + % saved = oo_.exo_simul(time,j_pos); + % oo_.exo_simul(time,j_pos) = oo_.exo_simul(time,j_pos) + eps1; + % simul(); + % J1(:,col_count) = (oo_.endo_simul(indx_endo) - ys) / eps1; + % oo_.exo_simul(time,j_pos) = saved; + % col_count = col_count + 1; + % end; + % else + % saved = oo_.exo_simul(maximum_lag+1,j_pos); + % oo_.exo_simul(maximum_lag+1,j_pos) = oo_.exo_simul(maximum_lag+1,j_pos) + eps1; + % simul(); + % % indx_endo + % J1(:,col_count) = (oo_.endo_simul(indx_endo) - ys) / eps1; + % % J(:,col_count) = (oo_.endo_simul((pp - 1) * M_.endo_nbr + 1: pp * M_.endo_nbr) - ys) / eps1; + % oo_.exo_simul(maximum_lag+1,j_pos) = saved; + % col_count = col_count + 1; + % end; + % end; + % disp('J1'); + % disp(full(J1)); + % sdfmlk; normr = norm(r, 1); @@ -862,7 +862,7 @@ else else % Newton update on exogenous shocks try - D_exo = - J \ r; + D_exo = - J \ r; catch [V, D] = eig(full(J)); ev = diag(D); diff --git a/matlab/perfect-foresight-models/linear_perfect_foresight_problem.m b/matlab/perfect-foresight-models/linear_perfect_foresight_problem.m index 306960b4c8..b8f710bd41 100644 --- a/matlab/perfect-foresight-models/linear_perfect_foresight_problem.m +++ b/matlab/perfect-foresight-models/linear_perfect_foresight_problem.m @@ -1,8 +1,8 @@ -function [residuals,JJacobian] = perfect_foresight_problem(y, dynamicjacobian, Y0, YT, ... - exo_simul, params, steady_state, ... - maximum_lag, T, ny, i_cols, ... - i_cols_J1, i_cols_1, i_cols_T, ... - i_cols_j,nnzJ,jendo,jexog) +function [residuals,JJacobian] = linear_perfect_foresight_problem(y, dynamicjacobian, Y0, YT, ... + exo_simul, params, steady_state, ... + maximum_lag, T, ny, i_cols, ... + i_cols_J1, i_cols_1, i_cols_T, ... + i_cols_j,nnzJ,jendo,jexog) % function [residuals,JJacobian] = perfect_foresight_problem(x, model_dynamic, Y0, YT,exo_simul, % params, steady_state, maximum_lag, periods, ny, i_cols,i_cols_J1, i_cols_1, % i_cols_T, i_cols_j, nnzA) diff --git a/matlab/perfect-foresight-models/perfect_foresight_mcp_problem.m b/matlab/perfect-foresight-models/perfect_foresight_mcp_problem.m index d4b4193086..ed6553201c 100644 --- a/matlab/perfect-foresight-models/perfect_foresight_mcp_problem.m +++ b/matlab/perfect-foresight-models/perfect_foresight_mcp_problem.m @@ -1,8 +1,8 @@ function [residuals,JJacobian] = perfect_foresight_mcp_problem(y, dynamic_function, Y0, YT, ... - exo_simul, params, steady_state, ... - maximum_lag, T, ny, i_cols, ... - i_cols_J1, i_cols_1, i_cols_T, ... - i_cols_j,nnzJ,eq_index) + exo_simul, params, steady_state, ... + maximum_lag, T, ny, i_cols, ... + i_cols_J1, i_cols_1, i_cols_T, ... + i_cols_j,nnzJ,eq_index) % function [residuals,JJacobian] = perfect_foresight_mcp_problem(y, dynamic_function, Y0, YT, ... % exo_simul, params, steady_state, ... % maximum_lag, T, ny, i_cols, ... @@ -77,11 +77,11 @@ i_cols_J = i_cols; for it = 2:(T+1) if nargout == 1 res = dynamic_function(YY(i_cols),exo_simul, params, ... - steady_state,it); + steady_state,it); residuals(i_rows) = res(eq_index); elseif nargout == 2 [res,jacobian] = dynamic_function(YY(i_cols),exo_simul, params, ... - steady_state,it); + steady_state,it); residuals(i_rows) = res(eq_index); if it == 2 [rows,cols,vals] = find(jacobian(eq_index,i_cols_1)); @@ -104,5 +104,5 @@ end if nargout == 2 iJacobian = cat(1,iJacobian{:}); JJacobian = sparse(iJacobian(:,1),iJacobian(:,2),iJacobian(:,3),T* ... - ny,T*ny); + ny,T*ny); end \ No newline at end of file diff --git a/matlab/perfect-foresight-models/perfect_foresight_problem.m b/matlab/perfect-foresight-models/perfect_foresight_problem.m index 9561190945..2f4cee6fd3 100644 --- a/matlab/perfect-foresight-models/perfect_foresight_problem.m +++ b/matlab/perfect-foresight-models/perfect_foresight_problem.m @@ -1,8 +1,8 @@ function [residuals,JJacobian] = perfect_foresight_problem(y, dynamic_function, Y0, YT, ... - exo_simul, params, steady_state, ... - maximum_lag, T, ny, i_cols, ... - i_cols_J1, i_cols_1, i_cols_T, ... - i_cols_j,nnzJ) + exo_simul, params, steady_state, ... + maximum_lag, T, ny, i_cols, ... + i_cols_J1, i_cols_1, i_cols_T, ... + i_cols_j,nnzJ) % function [residuals,JJacobian] = perfect_foresight_problem(y, dynamic_function, Y0, YT, ... % exo_simul, params, steady_state, ... % maximum_lag, T, ny, i_cols, ... @@ -60,44 +60,44 @@ function [residuals,JJacobian] = perfect_foresight_problem(y, dynamic_function, % along with Dynare. If not, see <http://www.gnu.org/licenses/>. - YY = [Y0; y; YT]; - - residuals = zeros(T*ny,1); - if nargout == 2 - iJacobian = cell(T,1); - end +YY = [Y0; y; YT]; - i_rows = 1:ny; - i_cols_J = i_cols; - offset = 0; - - for it = 2:(T+1) - if nargout == 1 - residuals(i_rows) = dynamic_function(YY(i_cols),exo_simul, params, ... - steady_state,it); - elseif nargout == 2 - [residuals(i_rows),jacobian] = dynamic_function(YY(i_cols),exo_simul, params, ... - steady_state,it); - if it == 2 - [rows,cols,vals] = find(jacobian(:,i_cols_1)); - iJacobian{1} = [offset+rows, i_cols_J1(cols), vals]; - elseif it == T + 1 - [rows,cols,vals] = find(jacobian(:,i_cols_T)); - iJacobian{T} = [offset+rows, i_cols_J(i_cols_T(cols)), vals]; - else - [rows,cols,vals] = find(jacobian(:,i_cols_j)); - iJacobian{it-1} = [offset+rows, i_cols_J(cols), vals]; - i_cols_J = i_cols_J + ny; - end - offset = offset + ny; - end +residuals = zeros(T*ny,1); +if nargout == 2 + iJacobian = cell(T,1); +end + +i_rows = 1:ny; +i_cols_J = i_cols; +offset = 0; - i_rows = i_rows + ny; - i_cols = i_cols + ny; +for it = 2:(T+1) + if nargout == 1 + residuals(i_rows) = dynamic_function(YY(i_cols),exo_simul, params, ... + steady_state,it); + elseif nargout == 2 + [residuals(i_rows),jacobian] = dynamic_function(YY(i_cols),exo_simul, params, ... + steady_state,it); + if it == 2 + [rows,cols,vals] = find(jacobian(:,i_cols_1)); + iJacobian{1} = [offset+rows, i_cols_J1(cols), vals]; + elseif it == T + 1 + [rows,cols,vals] = find(jacobian(:,i_cols_T)); + iJacobian{T} = [offset+rows, i_cols_J(i_cols_T(cols)), vals]; + else + [rows,cols,vals] = find(jacobian(:,i_cols_j)); + iJacobian{it-1} = [offset+rows, i_cols_J(cols), vals]; + i_cols_J = i_cols_J + ny; + end + offset = offset + ny; end - if nargout == 2 - iJacobian = cat(1,iJacobian{:}); - JJacobian = sparse(iJacobian(:,1),iJacobian(:,2),iJacobian(:,3),T* ... - ny,T*ny); - end \ No newline at end of file + i_rows = i_rows + ny; + i_cols = i_cols + ny; +end + +if nargout == 2 + iJacobian = cat(1,iJacobian{:}); + JJacobian = sparse(iJacobian(:,1),iJacobian(:,2),iJacobian(:,3),T* ... + ny,T*ny); +end \ No newline at end of file diff --git a/matlab/perfect-foresight-models/perfect_foresight_setup.m b/matlab/perfect-foresight-models/perfect_foresight_setup.m index 3b28254326..7d7312fc03 100644 --- a/matlab/perfect-foresight-models/perfect_foresight_setup.m +++ b/matlab/perfect-foresight-models/perfect_foresight_setup.m @@ -35,14 +35,14 @@ test_for_deep_parameters_calibration(M_); if size(M_.lead_lag_incidence,2)-nnz(M_.lead_lag_incidence(M_.maximum_endo_lag+1,:)) > 0 mess = ['PERFECT_FORESIGHT_SETUP: error in model specification : the variable(s) ']; - var_list=M_.endo_names(find(M_.lead_lag_incidence(M_.maximum_lag+1,:)==0),:); - for i=1:size(var_list,1) - if i<size(var_list,1) - mess = [mess, deblank(var_list(i,:)) ', ']; - else - mess = [mess, deblank(var_list(i,:)) ]; - end + var_list=M_.endo_names(find(M_.lead_lag_incidence(M_.maximum_lag+1,:)==0),:); + for i=1:size(var_list,1) + if i<size(var_list,1) + mess = [mess, deblank(var_list(i,:)) ', ']; + else + mess = [mess, deblank(var_list(i,:)) ]; end + end mess = [mess ' don''t appear as current period variables.']; error(mess) end diff --git a/matlab/perfect-foresight-models/perfect_foresight_solver.m b/matlab/perfect-foresight-models/perfect_foresight_solver.m index b5fc7e4f21..b159f2aea7 100644 --- a/matlab/perfect-foresight-models/perfect_foresight_solver.m +++ b/matlab/perfect-foresight-models/perfect_foresight_solver.m @@ -184,10 +184,10 @@ if ~isreal(oo_.endo_simul(:)) %can only happen without bytecode [i_cols_J1,junk,i_cols_1] = find(illi(:)); i_cols_T = nonzeros(M_.lead_lag_incidence(1:2,:)'); residuals = perfect_foresight_problem(yy(:),str2func([M_.fname '_dynamic']), y0, yT, ... - oo_.exo_simul,M_.params,oo_.steady_state, ... - M_.maximum_lag,options_.periods,M_.endo_nbr,i_cols, ... - i_cols_J1, i_cols_1, i_cols_T, i_cols_j, ... - M_.NNZDerivatives(1)); + oo_.exo_simul,M_.params,oo_.steady_state, ... + M_.maximum_lag,options_.periods,M_.endo_nbr,i_cols, ... + i_cols_J1, i_cols_1, i_cols_T, i_cols_j, ... + M_.NNZDerivatives(1)); if max(abs(residuals))< options_.dynatol.f oo_.deterministic_simulation.status = 1; oo_.endo_simul=real(oo_.endo_simul); diff --git a/matlab/perfect-foresight-models/perfect_foresight_solver_core.m b/matlab/perfect-foresight-models/perfect_foresight_solver_core.m index da267b7dae..c01333f0bc 100644 --- a/matlab/perfect-foresight-models/perfect_foresight_solver_core.m +++ b/matlab/perfect-foresight-models/perfect_foresight_solver_core.m @@ -81,8 +81,8 @@ else [oo_.endo_simul, oo_.deterministic_simulation] = ... sim1_purely_backward(oo_.endo_simul, oo_.exo_simul, oo_.steady_state, M_, options_); elseif M_.maximum_endo_lag == 0 % Purely forward model - [oo_.endo_simul, oo_.deterministic_simulation] = ... - sim1_purely_forward(oo_.endo_simul, oo_.exo_simul, oo_.steady_state, M_, options_); + [oo_.endo_simul, oo_.deterministic_simulation] = ... + sim1_purely_forward(oo_.endo_simul, oo_.exo_simul, oo_.steady_state, M_, options_); else % General case switch options_.stack_solve_algo case 0 diff --git a/matlab/perfect-foresight-models/private/initialize_stacked_problem.m b/matlab/perfect-foresight-models/private/initialize_stacked_problem.m index 64beba34e2..3f4ead4d12 100644 --- a/matlab/perfect-foresight-models/private/initialize_stacked_problem.m +++ b/matlab/perfect-foresight-models/private/initialize_stacked_problem.m @@ -43,7 +43,7 @@ function [options, y0, yT, z, i_cols, i_cols_J1, i_cols_T, i_cols_j, i_cols_1, . % % You should have received a copy of the GNU General Public License % along with Dynare. If not, see <http://www.gnu.org/licenses/>. - + periods = options.periods; if (options.solve_algo == 10) if ~isfield(options.lmmcp,'lb') diff --git a/matlab/perfect-foresight-models/private/simulation_core.m b/matlab/perfect-foresight-models/private/simulation_core.m index b52ecad172..1b8b1d51ec 100644 --- a/matlab/perfect-foresight-models/private/simulation_core.m +++ b/matlab/perfect-foresight-models/private/simulation_core.m @@ -66,8 +66,8 @@ else [oo_.endo_simul, oo_.deterministic_simulation] = ... sim1_purely_backward(oo_.endo_simul, oo_.exo_simul, oo_.steady_state, M_, options_); elseif M_.maximum_endo_lag == 0 % Purely forward model - [oo_.endo_simul, oo_.deterministic_simulation] = ... - sim1_purely_forward(oo_.endo_simul, oo_.exo_simul, oo_.steady_state, M_, options_); + [oo_.endo_simul, oo_.deterministic_simulation] = ... + sim1_purely_forward(oo_.endo_simul, oo_.exo_simul, oo_.steady_state, M_, options_); else % General case if options_.stack_solve_algo == 0 if options_.linear_approximation diff --git a/matlab/perfect-foresight-models/sim1.m b/matlab/perfect-foresight-models/sim1.m index 1a173b2115..f00bb43f8c 100644 --- a/matlab/perfect-foresight-models/sim1.m +++ b/matlab/perfect-foresight-models/sim1.m @@ -228,108 +228,107 @@ if verbose end function x = lin_solve( A, b,verbose) - if norm( b ) < sqrt( eps ) % then x = 0 is a solution - x = 0; - return - end - - x = A\b; - x( ~isfinite( x ) ) = 0; - relres = norm( b - A * x ) / norm( b ); - if relres > 1e-6 && verbose - fprintf( 'WARNING : Failed to find a solution to the linear system.\n' ); - end - +if norm( b ) < sqrt( eps ) % then x = 0 is a solution + x = 0; + return +end + +x = A\b; +x( ~isfinite( x ) ) = 0; +relres = norm( b - A * x ) / norm( b ); +if relres > 1e-6 && verbose + fprintf( 'WARNING : Failed to find a solution to the linear system.\n' ); +end + function [ x, flag, relres ] = lin_solve_robust( A, b , verbose) - if norm( b ) < sqrt( eps ) % then x = 0 is a solution - x = 0; - flag = 0; - relres = 0; - return - end - - x = A\b; - x( ~isfinite( x ) ) = 0; - [ x, flag, relres ] = bicgstab( A, b, [], [], [], [], x ); % returns immediately if x is a solution - if flag == 0 - return - end +if norm( b ) < sqrt( eps ) % then x = 0 is a solution + x = 0; + flag = 0; + relres = 0; + return +end - disp( relres ); +x = A\b; +x( ~isfinite( x ) ) = 0; +[ x, flag, relres ] = bicgstab( A, b, [], [], [], [], x ); % returns immediately if x is a solution +if flag == 0 + return +end - if verbose - fprintf( 'Initial bicgstab failed, trying alternative start point.\n' ); - end - old_x = x; - old_relres = relres; - [ x, flag, relres ] = bicgstab( A, b ); - if flag == 0 - return - end +disp( relres ); - if verbose - fprintf( 'Alternative start point also failed with bicgstab, trying gmres.\n' ); - end - if old_relres < relres - x = old_x; - end - [ x, flag, relres ] = gmres( A, b, [], [], [], [], [], x ); - if flag == 0 - return - end +if verbose + fprintf( 'Initial bicgstab failed, trying alternative start point.\n' ); +end +old_x = x; +old_relres = relres; +[ x, flag, relres ] = bicgstab( A, b ); +if flag == 0 + return +end - if verbose - fprintf( 'Initial gmres failed, trying alternative start point.\n' ); - end - old_x = x; - old_relres = relres; - [ x, flag, relres ] = gmres( A, b ); - if flag == 0 - return - end +if verbose + fprintf( 'Alternative start point also failed with bicgstab, trying gmres.\n' ); +end +if old_relres < relres + x = old_x; +end +[ x, flag, relres ] = gmres( A, b, [], [], [], [], [], x ); +if flag == 0 + return +end + +if verbose + fprintf( 'Initial gmres failed, trying alternative start point.\n' ); +end +old_x = x; +old_relres = relres; +[ x, flag, relres ] = gmres( A, b ); +if flag == 0 + return +end + +if verbose + fprintf( 'Alternative start point also failed with gmres, using the (SLOW) Moore-Penrose Pseudo-Inverse.\n' ); +end +if old_relres < relres + x = old_x; + relres = old_relres; +end +old_x = x; +old_relres = relres; +x = pinv( full( A ) ) * b; +relres = norm( b - A * x ) / norm( b ); +if old_relres < relres + x = old_x; + relres = old_relres; +end +flag = relres > 1e-6; +if flag ~= 0 && verbose + fprintf( 'WARNING : Failed to find a solution to the linear system\n' ); +end - if verbose - fprintf( 'Alternative start point also failed with gmres, using the (SLOW) Moore-Penrose Pseudo-Inverse.\n' ); - end - if old_relres < relres - x = old_x; - relres = old_relres; - end - old_x = x; - old_relres = relres; - x = pinv( full( A ) ) * b; - relres = norm( b - A * x ) / norm( b ); - if old_relres < relres - x = old_x; - relres = old_relres; - end - flag = relres > 1e-6; - if flag ~= 0 && verbose - fprintf( 'WARNING : Failed to find a solution to the linear system\n' ); - end - function display_critical_variables(dyy, M) - if any(isnan(dyy)) - indx = find(any(isnan(dyy))); - endo_names=cellstr(M.endo_names(indx,:)); - disp('Last iteration provided NaN for the following variables:') - fprintf('%s, ',endo_names{:}), - fprintf('\n'), - end - if any(isinf(dyy)) - indx = find(any(isinf(dyy))); - endo_names=cellstr(M.endo_names(indx,:)); - disp('Last iteration diverged (Inf) for the following variables:') - fprintf('%s, ',endo_names{:}), - fprintf('\n'), - end - if any(~isreal(dyy)) - indx = find(any(~isreal(dyy))); - endo_names=cellstr(M.endo_names(indx,:)); - disp('Last iteration provided complex number for the following variables:') - fprintf('%s, ',endo_names{:}), - fprintf('\n'), - end +if any(isnan(dyy)) + indx = find(any(isnan(dyy))); + endo_names=cellstr(M.endo_names(indx,:)); + disp('Last iteration provided NaN for the following variables:') + fprintf('%s, ',endo_names{:}), + fprintf('\n'), +end +if any(isinf(dyy)) + indx = find(any(isinf(dyy))); + endo_names=cellstr(M.endo_names(indx,:)); + disp('Last iteration diverged (Inf) for the following variables:') + fprintf('%s, ',endo_names{:}), + fprintf('\n'), +end +if any(~isreal(dyy)) + indx = find(any(~isreal(dyy))); + endo_names=cellstr(M.endo_names(indx,:)); + disp('Last iteration provided complex number for the following variables:') + fprintf('%s, ',endo_names{:}), + fprintf('\n'), +end - \ No newline at end of file diff --git a/matlab/perfect-foresight-models/sim1_purely_backward.m b/matlab/perfect-foresight-models/sim1_purely_backward.m index abc871a685..b4f1decd44 100644 --- a/matlab/perfect-foresight-models/sim1_purely_backward.m +++ b/matlab/perfect-foresight-models/sim1_purely_backward.m @@ -28,12 +28,12 @@ else nyb = 0; iyb = []; end - + if ny0 ~= M.endo_nbr error('All endogenous variables must appear at the current period!') end - + dynamicmodel = str2func([M.fname,'_dynamic']); info.status = 1; diff --git a/matlab/perfect-foresight-models/sim1_purely_forward.m b/matlab/perfect-foresight-models/sim1_purely_forward.m index ca2b2b5b27..5032e04988 100644 --- a/matlab/perfect-foresight-models/sim1_purely_forward.m +++ b/matlab/perfect-foresight-models/sim1_purely_forward.m @@ -24,7 +24,7 @@ iyf = find(M.lead_lag_incidence(2,:)>0); % Indices of variables at next period if ny0 ~= M.endo_nbr error('All endogenous variables must appear at the current period!') end - + dynamicmodel = str2func([M.fname,'_dynamic']); info.status = 1; diff --git a/matlab/perfect-foresight-models/solve_stacked_linear_problem.m b/matlab/perfect-foresight-models/solve_stacked_linear_problem.m index 52a2efe48c..cd50c1cbeb 100644 --- a/matlab/perfect-foresight-models/solve_stacked_linear_problem.m +++ b/matlab/perfect-foresight-models/solve_stacked_linear_problem.m @@ -42,11 +42,11 @@ z = bsxfun(@minus, z, steadystate_y); x = bsxfun(@minus, exogenousvariables, steadystate_x'); [y, check] = dynare_solve(@linear_perfect_foresight_problem,z(:), options, ... - jacobian, y0-steadystate_y, yT-steadystate_y, ... - x, M.params, steadystate_y, ... - M.maximum_lag, options.periods, M.endo_nbr, i_cols, ... - i_cols_J1, i_cols_1, i_cols_T, i_cols_j, ... - M.NNZDerivatives(1), jendo, jexog); + jacobian, y0-steadystate_y, yT-steadystate_y, ... + x, M.params, steadystate_y, ... + M.maximum_lag, options.periods, M.endo_nbr, i_cols, ... + i_cols_J1, i_cols_1, i_cols_T, i_cols_j, ... + M.NNZDerivatives(1), jendo, jexog); if all(imag(y)<.1*options.dynatol.x) if ~isreal(y) diff --git a/matlab/perfect-foresight-models/solve_stacked_problem.m b/matlab/perfect-foresight-models/solve_stacked_problem.m index 7a1835ba6b..1c29f565ef 100644 --- a/matlab/perfect-foresight-models/solve_stacked_problem.m +++ b/matlab/perfect-foresight-models/solve_stacked_problem.m @@ -29,7 +29,7 @@ function [endogenousvariables, info] = solve_stacked_problem(endogenousvariables % % You should have received a copy of the GNU General Public License % along with Dynare. If not, see <http://www.gnu.org/licenses/>. - + [options, y0, yT, z, i_cols, i_cols_J1, i_cols_T, i_cols_j, i_cols_1, dynamicmodel] = ... initialize_stacked_problem(endogenousvariables, options, M, steadystate); diff --git a/matlab/plot_identification.m b/matlab/plot_identification.m index f699d2e424..0c1f48b2cc 100644 --- a/matlab/plot_identification.m +++ b/matlab/plot_identification.m @@ -41,7 +41,7 @@ global M_ options_ if nargin <10 || isempty(tit_TeX) tit_TeX=tittxt; end - + if nargin <11 name_TeX=name; end @@ -169,9 +169,9 @@ if SampleSize == 1, % identificaton patterns for j=1:size(idemoments.cosnJ,2), pax=NaN(nparam,nparam); -% fprintf('\n') -% disp(['Collinearity patterns with ', int2str(j) ,' parameter(s)']) -% fprintf('%-15s [%-*s] %10s\n','Parameter',(15+1)*j,' Expl. params ','cosn') + % fprintf('\n') + % disp(['Collinearity patterns with ', int2str(j) ,' parameter(s)']) + % fprintf('%-15s [%-*s] %10s\n','Parameter',(15+1)*j,' Expl. params ','cosn') for i=1:nparam, namx=''; for in=1:j, @@ -183,7 +183,7 @@ if SampleSize == 1, pax(i,dumpindx)=idemoments.cosnJ(i,j); end end -% fprintf('%-15s [%s] %10.3f\n',name{i},namx,idemoments.cosnJ(i,j)) + % fprintf('%-15s [%s] %10.3f\n',name{i},namx,idemoments.cosnJ(i,j)) end hh = dyn_figure(options_.nodisplay,'Name',[tittxt,' - Collinearity patterns with ', int2str(j) ,' parameter(s)']); imagesc(pax,[0 1]); @@ -234,8 +234,8 @@ if SampleSize == 1, tex_tit_2=[tittxt,' - Identification patterns (Information matrix): HIGHEST SV']; end else -% S = idemoments.S; -% V = idemoments.V; + % S = idemoments.S; + % V = idemoments.V; if nparam<5, f1 = dyn_figure(options_.nodisplay,'Name',[tittxt,' - Identification patterns (moments Information matrix)']); tex_tit_1=[tittxt,' - Identification patterns (moments Information matrix)']; @@ -317,7 +317,7 @@ else mmm1 = [NaN(offset,1); mmm1./max(mmm1)]; mmm=[mmm mmm1]; end - + bar(mmm(is,:)) set(gca,'xlim',[0 nparam+1]) set(gca,'xticklabel','') @@ -349,7 +349,7 @@ else skipline() disp('Press ENTER to display advanced diagnostics'), pause(5), end -% options_.nograph=1; + % options_.nograph=1; hh = dyn_figure(options_.nodisplay,'Name','MC Condition Number'); subplot(221) hist(log10(idemodel.cond)) @@ -386,16 +386,16 @@ else options_mcf.title = 'MC Highest Condition Number Model Moments'; [dum,is]=sort(idemoments.cond); mcf_analysis(params, is(1:ncut), is(ncut+1:end), options_mcf, options_); -% [proba, dproba] = stab_map_1(idemoments.Mco', is(1:ncut), is(ncut+1:end), 'HighestCondNumberMoments_vs_Mco', 1, [], IdentifDirectoryName); -% for j=1:nparam, -% % ibeh=find(idemoments.Mco(j,:)<0.9); -% % inonbeh=find(idemoments.Mco(j,:)>=0.9); -% % if ~isempty(ibeh) && ~isempty(inonbeh) -% % [proba, dproba] = stab_map_1(params, ibeh, inonbeh, ['HighestMultiCollinearity_',name{j}], 1, [], IdentifDirectoryName); -% % end -% [~,is]=sort(idemoments.Mco(:,j)); -% [proba, dproba] = stab_map_1(params, is(1:ncut), is(ncut+1:end), ['MC_HighestMultiCollinearity_',name{j}], 1, [], IdentifDirectoryName, 0.15); -% end + % [proba, dproba] = stab_map_1(idemoments.Mco', is(1:ncut), is(ncut+1:end), 'HighestCondNumberMoments_vs_Mco', 1, [], IdentifDirectoryName); + % for j=1:nparam, + % % ibeh=find(idemoments.Mco(j,:)<0.9); + % % inonbeh=find(idemoments.Mco(j,:)>=0.9); + % % if ~isempty(ibeh) && ~isempty(inonbeh) + % % [proba, dproba] = stab_map_1(params, ibeh, inonbeh, ['HighestMultiCollinearity_',name{j}], 1, [], IdentifDirectoryName); + % % end + % [~,is]=sort(idemoments.Mco(:,j)); + % [proba, dproba] = stab_map_1(params, is(1:ncut), is(ncut+1:end), ['MC_HighestMultiCollinearity_',name{j}], 1, [], IdentifDirectoryName, 0.15); + % end if nparam<5, f1 = dyn_figure(options_.nodisplay,'Name',[tittxt,' - MC Identification patterns (moments): HIGHEST SV']); diff --git a/matlab/plot_shock_decomposition.m b/matlab/plot_shock_decomposition.m index 15c97506ac..81602d0590 100644 --- a/matlab/plot_shock_decomposition.m +++ b/matlab/plot_shock_decomposition.m @@ -76,7 +76,7 @@ if vintage_, end initial_date = options_.initial_date; - + if isfield(options_.plot_shock_decomp,'q2a'), % private trap for aoa calls q2a=options_.plot_shock_decomp.q2a; if isstruct(q2a) && isempty(fieldnames(q2a)), @@ -88,59 +88,59 @@ end switch realtime_ - case 0 - z = oo_.shock_decomposition; - fig_name1=fig_name; + case 0 + z = oo_.shock_decomposition; + fig_name1=fig_name; - case 1 % realtime - if vintage_ - z = oo_.realtime_shock_decomposition.(['time_' int2str(vintage_)]); - fig_name1=[fig_name ' realtime (vintage ' char(initial_date+vintage_-1) ')']; - else - z = oo_.realtime_shock_decomposition.pool; - fig_name1=[fig_name ' realtime (rolling)']; - end + case 1 % realtime + if vintage_ + z = oo_.realtime_shock_decomposition.(['time_' int2str(vintage_)]); + fig_name1=[fig_name ' realtime (vintage ' char(initial_date+vintage_-1) ')']; + else + z = oo_.realtime_shock_decomposition.pool; + fig_name1=[fig_name ' realtime (rolling)']; + end - case 2 % conditional - if vintage_ - z = oo_.realtime_conditional_shock_decomposition.(['time_' int2str(vintage_)]); - initial_date = options_.initial_date+vintage_-1; - fig_name1=[fig_name ' ' int2str(forecast_) '-step ahead conditional forecast (given ' char(initial_date) ')']; - else - z = oo_.conditional_shock_decomposition.pool; - fig_name1=[fig_name ' 1-step ahead conditional forecast (rolling)']; - end - - case 3 % forecast - if vintage_ - z = oo_.realtime_forecast_shock_decomposition.(['time_' int2str(vintage_)]); - initial_date = options_.initial_date+vintage_-1; - fig_name1=[fig_name ' ' int2str(forecast_) '-step ahead forecast (given ' char(initial_date) ')']; - else - z = oo_.realtime_forecast_shock_decomposition.pool; - fig_name1=[fig_name ' 1-step ahead forecast (rolling)']; - end + case 2 % conditional + if vintage_ + z = oo_.realtime_conditional_shock_decomposition.(['time_' int2str(vintage_)]); + initial_date = options_.initial_date+vintage_-1; + fig_name1=[fig_name ' ' int2str(forecast_) '-step ahead conditional forecast (given ' char(initial_date) ')']; + else + z = oo_.conditional_shock_decomposition.pool; + fig_name1=[fig_name ' 1-step ahead conditional forecast (rolling)']; + end + + case 3 % forecast + if vintage_ + z = oo_.realtime_forecast_shock_decomposition.(['time_' int2str(vintage_)]); + initial_date = options_.initial_date+vintage_-1; + fig_name1=[fig_name ' ' int2str(forecast_) '-step ahead forecast (given ' char(initial_date) ')']; + else + z = oo_.realtime_forecast_shock_decomposition.pool; + fig_name1=[fig_name ' 1-step ahead forecast (rolling)']; + end end steady_state = oo_.steady_state; if isequal(type,'aoa') && isstruct(q2a) && realtime_ - if isempty(initial_date), + if isempty(initial_date), + t0=1; + initial_date = dates('1Y'); + else + initial_date0 = dates([int2str(initial_date.time(1)) 'Y']); + if initial_date.time(2)==1, t0=1; - initial_date = dates('1Y'); + initial_date1=initial_date0; else - initial_date0 = dates([int2str(initial_date.time(1)) 'Y']); - if initial_date.time(2)==1, - t0=1; - initial_date1=initial_date0; - else - t0=(4-initial_date.time(2)+2); - initial_date1=initial_date0+1; - end + t0=(4-initial_date.time(2)+2); + initial_date1=initial_date0+1; end - t0=min(options_.plot_shock_decomp.save_realtime); - ini1 = initial_date+t0-1; - t0=t0+(4-ini1.time(2)); + end + t0=min(options_.plot_shock_decomp.save_realtime); + ini1 = initial_date+t0-1; + t0=t0+(4-ini1.time(2)); if ~isfield(q2a,'var_type'), % private trap for aoa calls q2a.var_type=1; end @@ -160,20 +160,20 @@ if isequal(type,'aoa') && isstruct(q2a) && realtime_ q2a.plot=1; % growth rate end -% if isstruct(q2a.aux) && ischar(q2a.aux.y) -% opts=options_; -% opts.plot_shock_decomp.type='qoq'; -% [y_aux, steady_state_aux] = plot_shock_decomposition(M_,oo_,opts,q2a.aux.y); -% q2a.aux.y=y_aux; -% q2a.aux.yss=steady_state_aux; -% end + % if isstruct(q2a.aux) && ischar(q2a.aux.y) + % opts=options_; + % opts.plot_shock_decomp.type='qoq'; + % [y_aux, steady_state_aux] = plot_shock_decomposition(M_,oo_,opts,q2a.aux.y); + % q2a.aux.y=y_aux; + % q2a.aux.yss=steady_state_aux; + % end [za, endo_names, endo_names_tex, steady_state, i_var, oo_] = ... annualized_shock_decomposition(oo_,M_, options_, i_var, t0, options_.nobs, realtime_, vintage_, steady_state,q2a); -% if realtime_<2 -% initial_date = initial_date1; -% else -% initial_date = initial_date0; -% end + % if realtime_<2 + % initial_date = initial_date1; + % else + % initial_date = initial_date0; + % end end @@ -189,7 +189,7 @@ if options_.plot_shock_decomp.use_shock_groups fig_name=[fig_name ' group ' options_.plot_shock_decomp.use_shock_groups]; shock_names = shock_ind; for i=1:ngroups, - shock_names{i} = (shock_groups.(shock_ind{i}).label); + shock_names{i} = (shock_groups.(shock_ind{i}).label); end zz = zeros(endo_nbr,ngroups+2,gend); kcum=[]; @@ -215,10 +215,10 @@ else shock_names = M_.exo_names; end - func = @(x) colorspace('RGB->Lab',x); - MAP = distinguishable_colors(size(z,2)-1,'w',func); +func = @(x) colorspace('RGB->Lab',x); +MAP = distinguishable_colors(size(z,2)-1,'w',func); % MAP = [MAP; MAP(end,:)]; - MAP(end,:) = [0.7 0.7 0.7]; +MAP(end,:) = [0.7 0.7 0.7]; % MAP = [MAP; [0.7 0.7 0.7]; [0.3 0.3 0.3]]; if isempty(options_.plot_shock_decomp.colormap), @@ -227,36 +227,36 @@ end switch type - case '' % default + case '' % default - case 'qoq' + case 'qoq' - case 'yoy' - z=z(:,:,1:end-3)+z(:,:,2:end-2)+z(:,:,3:end-1)+z(:,:,4:end); - if ~isempty(initial_date), - initial_date = initial_date+3; - else - initial_date = dates('1Q4'); - end - steady_state = 4*steady_state; - - case 'aoa' + case 'yoy' + z=z(:,:,1:end-3)+z(:,:,2:end-2)+z(:,:,3:end-1)+z(:,:,4:end); + if ~isempty(initial_date), + initial_date = initial_date+3; + else + initial_date = dates('1Q4'); + end + steady_state = 4*steady_state; + + case 'aoa' - if isempty(initial_date), - t0=4; - initial_date = dates('1Y'); + if isempty(initial_date), + t0=4; + initial_date = dates('1Y'); + else + initial_date0 = dates([int2str(initial_date.time(1)) 'Y']); + if initial_date.time(2)==1, + t0=1; + initial_date1=initial_date0; else - initial_date0 = dates([int2str(initial_date.time(1)) 'Y']); - if initial_date.time(2)==1, - t0=1; - initial_date1=initial_date0; - else - t0=(4-initial_date.time(2)+2); - initial_date1=initial_date0+1; - end + t0=(4-initial_date.time(2)+2); + initial_date1=initial_date0+1; end - if isstruct(q2a) - if realtime_ == 0 + end + if isstruct(q2a) + if realtime_ == 0 if ~isfield(q2a,'var_type'), % private trap for aoa calls q2a.var_type=1; end @@ -285,33 +285,33 @@ switch type end [za, endo_names, endo_names_tex, steady_state, i_var, oo_] = ... annualized_shock_decomposition(z,M_, options_, i_var, t0, options_.nobs, realtime_, vintage_, steady_state,q2a); - end - z = za; - M_.endo_names = endo_names; - M_.endo_names_tex = endo_names_tex; -% endo_nbr = size(z,1); - if realtime_<2 - initial_date = initial_date1; - else - initial_date = initial_date0; - end + end + z = za; + M_.endo_names = endo_names; + M_.endo_names_tex = endo_names_tex; + % endo_nbr = size(z,1); + if realtime_<2 + initial_date = initial_date1; else - t0=4-initial_date.time(2)+1; initial_date = initial_date0; - z=z(:,:,t0:4:end); - end - - if ~isempty(options_.plot_shock_decomp.plot_init_date) - options_.plot_shock_decomp.plot_init_date = dates([int2str(options_.plot_shock_decomp.plot_init_date.time(1)) 'Y']); end - if ~isempty(options_.plot_shock_decomp.plot_end_date) - options_.plot_shock_decomp.plot_end_date = dates([int2str(options_.plot_shock_decomp.plot_end_date.time(1)) 'Y']); - end - - - otherwise + else + t0=4-initial_date.time(2)+1; + initial_date = initial_date0; + z=z(:,:,t0:4:end); + end + + if ~isempty(options_.plot_shock_decomp.plot_init_date) + options_.plot_shock_decomp.plot_init_date = dates([int2str(options_.plot_shock_decomp.plot_init_date.time(1)) 'Y']); + end + if ~isempty(options_.plot_shock_decomp.plot_end_date) + options_.plot_shock_decomp.plot_end_date = dates([int2str(options_.plot_shock_decomp.plot_end_date.time(1)) 'Y']); + end + + + otherwise - error('plot_shock_decomposition:: Wrong type') + error('plot_shock_decomposition:: Wrong type') end if steadystate diff --git a/matlab/pm3.m b/matlab/pm3.m index ae0f474d16..d5502d29bd 100644 --- a/matlab/pm3.m +++ b/matlab/pm3.m @@ -63,7 +63,7 @@ if options_.TeX if isempty(tit_tex), tit_tex=names1; end - + varlist_TeX = []; for i=1:nvar if i==1 @@ -289,112 +289,112 @@ if strcmp(var_type,'_trend_coeff') || max(max(abs(Mean(:,:))))<=10^(-6) || all(a return %not do plots end %% -%% Finally I build the plots. +%% Finally I build the plots. %% if ~options_.nograph && ~options_.no_graph.posterior -% Block of code executed in parallel, with the exception of file -% .tex generation always run sequentially. This portion of code is execute in parallel by -% pm3_core1.m function. + % Block of code executed in parallel, with the exception of file + % .tex generation always run sequentially. This portion of code is execute in parallel by + % pm3_core1.m function. -% %%%%%%%%% PARALLEL BLOCK % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% -% %%% The file .TeX! are not saved in parallel. + % %%%%%%%%% PARALLEL BLOCK % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + % + % %%% The file .TeX! are not saved in parallel. -% Store the variable mandatory for local/remote parallel computing. + % Store the variable mandatory for local/remote parallel computing. -localVars=[]; + localVars=[]; -localVars.tit1=tit1; -localVars.nn=nn; -localVars.n2=n2; -localVars.Distrib=Distrib; -localVars.varlist=varlist; -localVars.MaxNumberOfPlotsPerFigure=MaxNumberOfPlotsPerFigure; -localVars.name3=name3; -localVars.tit3=tit3; -localVars.Mean=Mean; -% Like sequential execution! -nvar0=nvar; + localVars.tit1=tit1; + localVars.nn=nn; + localVars.n2=n2; + localVars.Distrib=Distrib; + localVars.varlist=varlist; + localVars.MaxNumberOfPlotsPerFigure=MaxNumberOfPlotsPerFigure; + localVars.name3=name3; + localVars.tit3=tit3; + localVars.Mean=Mean; + % Like sequential execution! + nvar0=nvar; -if ~isoctave - % Commenting for testing! - if isnumeric(options_.parallel) || ceil(size(varlist,1)/MaxNumberOfPlotsPerFigure)<4, - fout = pm3_core(localVars,1,nvar,0); - - % Parallel execution! - else - isRemoteOctave = 0; - for indPC=1:length(options_.parallel), - isRemoteOctave = isRemoteOctave + (findstr(options_.parallel(indPC).MatlabOctavePath, 'octave')); - end - if isRemoteOctave + if ~isoctave + % Commenting for testing! + if isnumeric(options_.parallel) || ceil(size(varlist,1)/MaxNumberOfPlotsPerFigure)<4, fout = pm3_core(localVars,1,nvar,0); + + % Parallel execution! else - globalVars = struct('M_',M_, ... - 'options_', options_, ... - 'oo_', oo_); - [fout, nvar0, totCPU] = masterParallel(options_.parallel, 1, nvar, [],'pm3_core', localVars,globalVars, options_.parallel_info); + isRemoteOctave = 0; + for indPC=1:length(options_.parallel), + isRemoteOctave = isRemoteOctave + (findstr(options_.parallel(indPC).MatlabOctavePath, 'octave')); + end + if isRemoteOctave + fout = pm3_core(localVars,1,nvar,0); + else + globalVars = struct('M_',M_, ... + 'options_', options_, ... + 'oo_', oo_); + [fout, nvar0, totCPU] = masterParallel(options_.parallel, 1, nvar, [],'pm3_core', localVars,globalVars, options_.parallel_info); + end end + else + % For the time being in Octave enviroment the pm3.m is executed only in + % serial modality, to avoid problem with the plots. + + fout = pm3_core(localVars,1,nvar,0); end -else - % For the time being in Octave enviroment the pm3.m is executed only in - % serial modality, to avoid problem with the plots. - - fout = pm3_core(localVars,1,nvar,0); -end -subplotnum = 0; + subplotnum = 0; -if options_.TeX && any(strcmp('eps',cellstr(options_.graph_format))) - fidTeX = fopen([M_.dname '/Output/' M_.fname '_' name3 '.tex'],'w'); - fprintf(fidTeX,'%% TeX eps-loader file generated by Dynare.\n'); - fprintf(fidTeX,['%% ' datestr(now,0) '\n']); - fprintf(fidTeX,' \n'); - nvar0=cumsum(nvar0); + if options_.TeX && any(strcmp('eps',cellstr(options_.graph_format))) + fidTeX = fopen([M_.dname '/Output/' M_.fname '_' name3 '.tex'],'w'); + fprintf(fidTeX,'%% TeX eps-loader file generated by Dynare.\n'); + fprintf(fidTeX,['%% ' datestr(now,0) '\n']); + fprintf(fidTeX,' \n'); + nvar0=cumsum(nvar0); - i=0; - for j=1:length(nvar0), - - NAMES = []; - TEXNAMES = []; - nvar=nvar0(j); - while i<nvar, - i=i+1; - if max(abs(Mean(:,i))) > 10^(-6) - subplotnum = subplotnum+1; - name = deblank(varlist(i,:)); - texname = deblank(varlist_TeX(i,:)); - if subplotnum==1 - NAMES = name; - TEXNAMES = ['$' texname '$']; - else - NAMES = char(NAMES,name); - TEXNAMES = char(TEXNAMES,['$' texname '$']); - end - end - if subplotnum == MaxNumberOfPlotsPerFigure || i == nvar - fprintf(fidTeX,'\\begin{figure}[H]\n'); - for jj = 1:size(TEXNAMES,1) - fprintf(fidTeX,['\\psfrag{%s}[1][][0.5][0]{%s}\n'],deblank(NAMES(jj,:)),deblank(TEXNAMES(jj,:))); - end - fprintf(fidTeX,'\\centering \n'); - fprintf(fidTeX,['\\includegraphics[width=%2.2f\\textwidth]{%s/Output/%s_' name3 '_%s}\n'],options_.figures.textwidth*min(subplotnum/nn,1),M_.dname,M_.fname,deblank(tit3(i,:))); - fprintf(fidTeX,'\\label{Fig:%s:%s}\n',name3,deblank(tit3(i,:))); - fprintf(fidTeX,'\\caption{%s}\n',tit1); - fprintf(fidTeX,'\\end{figure}\n'); - fprintf(fidTeX,' \n'); - subplotnum = 0; + i=0; + for j=1:length(nvar0), + NAMES = []; TEXNAMES = []; + nvar=nvar0(j); + while i<nvar, + i=i+1; + if max(abs(Mean(:,i))) > 10^(-6) + subplotnum = subplotnum+1; + name = deblank(varlist(i,:)); + texname = deblank(varlist_TeX(i,:)); + if subplotnum==1 + NAMES = name; + TEXNAMES = ['$' texname '$']; + else + NAMES = char(NAMES,name); + TEXNAMES = char(TEXNAMES,['$' texname '$']); + end + end + if subplotnum == MaxNumberOfPlotsPerFigure || i == nvar + fprintf(fidTeX,'\\begin{figure}[H]\n'); + for jj = 1:size(TEXNAMES,1) + fprintf(fidTeX,['\\psfrag{%s}[1][][0.5][0]{%s}\n'],deblank(NAMES(jj,:)),deblank(TEXNAMES(jj,:))); + end + fprintf(fidTeX,'\\centering \n'); + fprintf(fidTeX,['\\includegraphics[width=%2.2f\\textwidth]{%s/Output/%s_' name3 '_%s}\n'],options_.figures.textwidth*min(subplotnum/nn,1),M_.dname,M_.fname,deblank(tit3(i,:))); + fprintf(fidTeX,'\\label{Fig:%s:%s}\n',name3,deblank(tit3(i,:))); + fprintf(fidTeX,'\\caption{%s}\n',tit1); + fprintf(fidTeX,'\\end{figure}\n'); + fprintf(fidTeX,' \n'); + subplotnum = 0; + NAMES = []; + TEXNAMES = []; + end + end end + fprintf(fidTeX,'%% End of TeX file.\n'); + fclose(fidTeX); end - end - fprintf(fidTeX,'%% End of TeX file.\n'); - fclose(fidTeX); -end end fprintf(['Estimation::mcmc: ' tit1 ', done!\n']); diff --git a/matlab/pm3_core.m b/matlab/pm3_core.m index 32052f83c4..2f925e5e37 100644 --- a/matlab/pm3_core.m +++ b/matlab/pm3_core.m @@ -120,8 +120,8 @@ for i=fpar:nvar end if whoiam, -% waitbarString = [ 'Variable ' int2str(i) '/' int2str(nvar) ' done.']; -% fMessageStatus((i-fpar+1)/(nvar-fpar+1),whoiam,waitbarString, waitbarTitle, Parallel(ThisMatlab)); + % waitbarString = [ 'Variable ' int2str(i) '/' int2str(nvar) ' done.']; + % fMessageStatus((i-fpar+1)/(nvar-fpar+1),whoiam,waitbarString, waitbarTitle, Parallel(ThisMatlab)); dyn_waitbar((i-fpar+1)/(nvar-fpar+1),h); end diff --git a/matlab/posterior_sampler_initialization.m b/matlab/posterior_sampler_initialization.m index f7927a1735..0292b010d9 100644 --- a/matlab/posterior_sampler_initialization.m +++ b/matlab/posterior_sampler_initialization.m @@ -347,9 +347,9 @@ elseif options_.mh_recover if OldMhExists LastLineNumberInThePreviousMh = record.MhDraws(end-1,3);% Number of lines in the last mh files of the previous session. LastFileNumberInThePreviousMh = sum(record.MhDraws(1:end-1,2),1);% Number of mh files in the the previous sessions. - %Test if the last mh files of the previous session were not full yet + %Test if the last mh files of the previous session were not full yet if LastLineNumberInThePreviousMh < MAX_nruns%not full - %store starting point if whole chain needs to be redone + %store starting point if whole chain needs to be redone NewFile = ones(NumberOfBlocks,1)*LastFileNumberInThePreviousMh; FirstLine = ones(NumberOfBlocks,1)*(LastLineNumberInThePreviousMh+1); LastFileFullIndicator=0; @@ -406,7 +406,7 @@ elseif options_.mh_recover % How many mh-files are saved in this block? NumberOfSavedMhFilesInTheCrashedBlck = NumberOfMhFilesPerBlock(FirstBlock); ExistingDrawsInLastMCFile=0; %initialize: no MCMC draws of current MCMC are in file from last run - % Check whether last present file is a file included in the last MCMC run + % Check whether last present file is a file included in the last MCMC run if ~LastFileFullIndicator if NumberOfSavedMhFilesInTheCrashedBlck==NewFile(FirstBlock) %only that last file exists, but no files from current MCMC loaded_results=load([BaseName '_mh' int2str(NewFile(FirstBlock)) '_blck' int2str(FirstBlock) '.mat']); @@ -425,13 +425,13 @@ elseif options_.mh_recover NewFile(FirstBlock)=NewFile(FirstBlock)+1; %set first file to be created to next one end end -% % Correct the number of saved mh files if the crashed Metropolis was not the first session (so -% % that NumberOfSavedMhFilesInTheCrashedBlck is the number of saved mh files in the crashed chain -% % of the current session). -% if OldMhExists -% NumberOfSavedMhFilesInTheCrashedBlck = NumberOfSavedMhFilesInTheCrashedBlck - LastFileNumberInThePreviousMh; -% end -% NumberOfSavedMhFiles = NumberOfSavedMhFilesInTheCrashedBlck+LastFileNumberInThePreviousMh; + % % Correct the number of saved mh files if the crashed Metropolis was not the first session (so + % % that NumberOfSavedMhFilesInTheCrashedBlck is the number of saved mh files in the crashed chain + % % of the current session). + % if OldMhExists + % NumberOfSavedMhFilesInTheCrashedBlck = NumberOfSavedMhFilesInTheCrashedBlck - LastFileNumberInThePreviousMh; + % end + % NumberOfSavedMhFiles = NumberOfSavedMhFilesInTheCrashedBlck+LastFileNumberInThePreviousMh; % Correct initial conditions. if NumberOfSavedMhFilesInTheCrashedBlck<ExpectedNumberOfMhFilesPerBlock @@ -452,19 +452,19 @@ elseif options_.mh_recover end function [d,bayestopt_]=set_proposal_density_to_previous_value(record,options_,bayestopt_,d) - if isfield(record,'ProposalCovariance') && isfield(record,'ProposalCovariance') - if isfield(record,'MCMC_sampler') - if ~strcmp(record.MCMC_sampler,options_.posterior_sampler_options.posterior_sampling_method) - error(fprintf('Estimation::mcmc: The posterior_sampling_method differs from the one of the original chain. Please reset it to %s',record.MCMC_sampler)) - end - end - fprintf('Estimation::mcmc: Recovering the previous proposal density.\n') - d=record.ProposalCovariance; - bayestopt_.jscale=record.ProposalScaleVec; - else - if options_.mode_compute~=0 - fprintf('Estimation::mcmc: No stored previous proposal density found, continuing with the one implied by mode_compute\n.'); - elseif ~isempty(options_.mode_file) - fprintf('Estimation::mcmc: No stored previous proposal density found, continuing with the one implied by the mode_file\n.'); - end +if isfield(record,'ProposalCovariance') && isfield(record,'ProposalCovariance') + if isfield(record,'MCMC_sampler') + if ~strcmp(record.MCMC_sampler,options_.posterior_sampler_options.posterior_sampling_method) + error(fprintf('Estimation::mcmc: The posterior_sampling_method differs from the one of the original chain. Please reset it to %s',record.MCMC_sampler)) + end + end + fprintf('Estimation::mcmc: Recovering the previous proposal density.\n') + d=record.ProposalCovariance; + bayestopt_.jscale=record.ProposalScaleVec; +else + if options_.mode_compute~=0 + fprintf('Estimation::mcmc: No stored previous proposal density found, continuing with the one implied by mode_compute\n.'); + elseif ~isempty(options_.mode_file) + fprintf('Estimation::mcmc: No stored previous proposal density found, continuing with the one implied by the mode_file\n.'); end +end diff --git a/matlab/posterior_sampler_iteration.m b/matlab/posterior_sampler_iteration.m index 09e5d88510..14dc11b923 100644 --- a/matlab/posterior_sampler_iteration.m +++ b/matlab/posterior_sampler_iteration.m @@ -1,173 +1,173 @@ -function [par, logpost, accepted, neval] = posterior_sampler_iteration(TargetFun,last_draw, last_posterior, sampler_options,varargin) - -% function [par, logpost, accepted, neval] = posterior_sampler_iteration(TargetFun,last_draw, last_posterior, sampler_options,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,mh_bounds,oo_) -% posterior samplers -% -% INPUTS -% posterior_sampler_options: posterior sampler options -% options_: structure storing the options - -% OUTPUTS -% posterior_sampler_options: checked posterior sampler options -% -% SPECIAL REQUIREMENTS -% none - -% Copyright (C) 2015-16 Dynare Team -% -% This file is part of Dynare. -% -% Dynare is free software: you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation, either version 3 of the License, or -% (at your option) any later version. -% -% Dynare is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. -% -% You should have received a copy of the GNU General Public License -% along with Dynare. If not, see <http://www.gnu.org/licenses/>. - - -posterior_sampling_method = sampler_options.posterior_sampling_method; -mh_bounds = sampler_options.bounds; - -switch posterior_sampling_method - case 'slice' - - [par, logpost, neval] = slice_sampler(TargetFun,last_draw, [mh_bounds.lb mh_bounds.ub], sampler_options,varargin{:}); - accepted = 1; - case 'random_walk_metropolis_hastings' - neval = 1; - ProposalFun = sampler_options.proposal_distribution; - proposal_covariance_Cholesky_decomposition = sampler_options.proposal_covariance_Cholesky_decomposition; - n = sampler_options.n; - - par = feval(ProposalFun, last_draw, proposal_covariance_Cholesky_decomposition, n); - if all( par(:) > mh_bounds.lb ) && all( par(:) < mh_bounds.ub ) - try - logpost = - feval(TargetFun, par(:),varargin{:}); - catch - logpost = -inf; - end - else - logpost = -inf; - end - r = logpost-last_posterior; - if (logpost > -inf) && (log(rand) < r) - accepted = 1; - else - accepted = 0; - par = last_draw; - logpost = last_posterior; - end - case 'tailored_random_block_metropolis_hastings' - options_=varargin{3}; - bayestopt_=varargin{6}; - npar=length(last_draw); - %% randomize indices for blocking in this iteration - indices=randperm(npar)'; - blocks=[1; (1+cumsum((rand(length(indices)-1,1)>(1-sampler_options.new_block_probability))))]; - nblocks=blocks(end,1); %get number of blocks this iteration - current_draw=last_draw'; %get starting point for current draw for updating - blocked_draws_counter=0; - accepted_draws_counter=0; - for block_iter=1:nblocks - blocked_draws_counter=blocked_draws_counter+1; - nxopt=length(indices(blocks==block_iter,1)); %get size of current block - par_start_current_block=current_draw(indices(blocks==block_iter,1)); - [xopt_current_block, fval, exitflag, hess_mat_optimizer, options_, Scale] = dynare_minimize_objective(@TaRB_optimizer_wrapper,par_start_current_block,sampler_options.mode_compute,options_,[mh_bounds.lb(indices(blocks==block_iter,1),1) mh_bounds.ub(indices(blocks==block_iter,1),1)],bayestopt_.name,bayestopt_,[],... - current_draw,indices(blocks==block_iter,1),TargetFun,...% inputs for wrapper - varargin{:}); %inputs for objective - %% covariance for proposal density - hessian_mat = reshape(hessian('TaRB_optimizer_wrapper',xopt_current_block, ... - options_.gstep,... - current_draw,indices(blocks==block_iter,1),TargetFun,...% inputs for wrapper - varargin{:}),nxopt,nxopt); - - if any(any(isnan(hessian_mat))) || any(any(isinf(hessian_mat))) - inverse_hessian_mat=eye(nxopt)*1e-4; %use diagonal - else - inverse_hessian_mat=inv(hessian_mat); %get inverse Hessian - if any(any((isnan(inverse_hessian_mat)))) || any(any((isinf(inverse_hessian_mat)))) - inverse_hessian_mat=eye(nxopt)*1e-4; %use diagonal - end - end - [proposal_covariance_Cholesky_decomposition_upper,negeigenvalues]=chol(inverse_hessian_mat); - %if not positive definite, use generalized Cholesky of Eskow/Schnabel - if negeigenvalues~=0 - proposal_covariance_Cholesky_decomposition_upper=chol_SE(inverse_hessian_mat,0); - end - proposal_covariance_Cholesky_decomposition_upper=proposal_covariance_Cholesky_decomposition_upper*diag(bayestopt_.jscale(indices(blocks==block_iter,1),:)); - %get proposal draw - if strcmpi(sampler_options.proposal_distribution,'rand_multivariate_normal') - n = nxopt; - elseif strcmpi(sampler_options.proposal_distribution,'rand_multivariate_student') - n = options_.student_degrees_of_freedom; - end - - proposed_par = feval(sampler_options.proposal_distribution, xopt_current_block', proposal_covariance_Cholesky_decomposition_upper, n); - % check whether draw is valid and compute posterior - if all( proposed_par(:) > mh_bounds.lb(indices(blocks==block_iter,1),:) ) && all( proposed_par(:) < mh_bounds.ub(indices(blocks==block_iter,1),:) ) - try - logpost = - feval('TaRB_optimizer_wrapper', proposed_par(:),... - current_draw,indices(blocks==block_iter,1),TargetFun,...% inputs for wrapper - varargin{:}); - catch - logpost = -inf; - end - else - logpost = -inf; - end - %get ratio of proposal densities, required because proposal depends - %on current mode via Hessian and is thus not symmetric anymore - if strcmpi(sampler_options.proposal_distribution,'rand_multivariate_normal') - proposal_density_proposed_move_forward=multivariate_normal_pdf(proposed_par,xopt_current_block',proposal_covariance_Cholesky_decomposition_upper,n); - proposal_density_proposed_move_backward=multivariate_normal_pdf(par_start_current_block',xopt_current_block',proposal_covariance_Cholesky_decomposition_upper,n); - elseif strcmpi(sampler_options.proposal_distribution,'rand_multivariate_student') - proposal_density_proposed_move_forward=multivariate_student_pdf(proposed_par,xopt_current_block',proposal_covariance_Cholesky_decomposition_upper,n); - proposal_density_proposed_move_backward=multivariate_student_pdf(par_start_current_block',xopt_current_block',proposal_covariance_Cholesky_decomposition_upper,n); - end - accprob=logpost-last_posterior+ log(proposal_density_proposed_move_backward)-log(proposal_density_proposed_move_forward); %Formula (6), Chib/Ramamurthy - - if (logpost > -inf) && (log(rand) < accprob) - current_draw(indices(blocks==block_iter,1))=proposed_par; - last_posterior=logpost; - accepted_draws_counter =accepted_draws_counter +1; - else %no updating - %do nothing, keep old value - end - end - accepted=accepted_draws_counter/blocked_draws_counter; - par = current_draw; - neval=1; - case 'independent_metropolis_hastings' - neval = 1; - ProposalFun = sampler_options.proposal_distribution; - ProposalDensity = sampler_options.ProposalDensity; - proposal_covariance_Cholesky_decomposition = sampler_options.proposal_covariance_Cholesky_decomposition; - n = sampler_options.n; - xparam1 = sampler_options.xparam1'; - par = feval(ProposalFun, xparam1, proposal_covariance_Cholesky_decomposition, n); - if all( par(:) > mh_bounds.lb ) && all( par(:) < mh_bounds.ub ) - try - logpost = - feval(TargetFun, par(:),varargin{:}); - catch - logpost = -inf; - end - else - logpost = -inf; - end - r = logpost - last_posterior + ... - log(feval(ProposalDensity, last_draw, xparam1, proposal_covariance_Cholesky_decomposition, n)) - ... - log(feval(ProposalDensity, par, xparam1, proposal_covariance_Cholesky_decomposition, n)); - if (logpost > -inf) && (log(rand) < r) - accepted = 1; - else - accepted = 0; - par = last_draw; - logpost = last_posterior; - end +function [par, logpost, accepted, neval] = posterior_sampler_iteration(TargetFun,last_draw, last_posterior, sampler_options,varargin) + +% function [par, logpost, accepted, neval] = posterior_sampler_iteration(TargetFun,last_draw, last_posterior, sampler_options,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,mh_bounds,oo_) +% posterior samplers +% +% INPUTS +% posterior_sampler_options: posterior sampler options +% options_: structure storing the options + +% OUTPUTS +% posterior_sampler_options: checked posterior sampler options +% +% SPECIAL REQUIREMENTS +% none + +% Copyright (C) 2015-16 Dynare Team +% +% This file is part of Dynare. +% +% Dynare is free software: you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation, either version 3 of the License, or +% (at your option) any later version. +% +% Dynare is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with Dynare. If not, see <http://www.gnu.org/licenses/>. + + +posterior_sampling_method = sampler_options.posterior_sampling_method; +mh_bounds = sampler_options.bounds; + +switch posterior_sampling_method + case 'slice' + + [par, logpost, neval] = slice_sampler(TargetFun,last_draw, [mh_bounds.lb mh_bounds.ub], sampler_options,varargin{:}); + accepted = 1; + case 'random_walk_metropolis_hastings' + neval = 1; + ProposalFun = sampler_options.proposal_distribution; + proposal_covariance_Cholesky_decomposition = sampler_options.proposal_covariance_Cholesky_decomposition; + n = sampler_options.n; + + par = feval(ProposalFun, last_draw, proposal_covariance_Cholesky_decomposition, n); + if all( par(:) > mh_bounds.lb ) && all( par(:) < mh_bounds.ub ) + try + logpost = - feval(TargetFun, par(:),varargin{:}); + catch + logpost = -inf; + end + else + logpost = -inf; + end + r = logpost-last_posterior; + if (logpost > -inf) && (log(rand) < r) + accepted = 1; + else + accepted = 0; + par = last_draw; + logpost = last_posterior; + end + case 'tailored_random_block_metropolis_hastings' + options_=varargin{3}; + bayestopt_=varargin{6}; + npar=length(last_draw); + %% randomize indices for blocking in this iteration + indices=randperm(npar)'; + blocks=[1; (1+cumsum((rand(length(indices)-1,1)>(1-sampler_options.new_block_probability))))]; + nblocks=blocks(end,1); %get number of blocks this iteration + current_draw=last_draw'; %get starting point for current draw for updating + blocked_draws_counter=0; + accepted_draws_counter=0; + for block_iter=1:nblocks + blocked_draws_counter=blocked_draws_counter+1; + nxopt=length(indices(blocks==block_iter,1)); %get size of current block + par_start_current_block=current_draw(indices(blocks==block_iter,1)); + [xopt_current_block, fval, exitflag, hess_mat_optimizer, options_, Scale] = dynare_minimize_objective(@TaRB_optimizer_wrapper,par_start_current_block,sampler_options.mode_compute,options_,[mh_bounds.lb(indices(blocks==block_iter,1),1) mh_bounds.ub(indices(blocks==block_iter,1),1)],bayestopt_.name,bayestopt_,[],... + current_draw,indices(blocks==block_iter,1),TargetFun,...% inputs for wrapper + varargin{:}); %inputs for objective + %% covariance for proposal density + hessian_mat = reshape(hessian('TaRB_optimizer_wrapper',xopt_current_block, ... + options_.gstep,... + current_draw,indices(blocks==block_iter,1),TargetFun,...% inputs for wrapper + varargin{:}),nxopt,nxopt); + + if any(any(isnan(hessian_mat))) || any(any(isinf(hessian_mat))) + inverse_hessian_mat=eye(nxopt)*1e-4; %use diagonal + else + inverse_hessian_mat=inv(hessian_mat); %get inverse Hessian + if any(any((isnan(inverse_hessian_mat)))) || any(any((isinf(inverse_hessian_mat)))) + inverse_hessian_mat=eye(nxopt)*1e-4; %use diagonal + end + end + [proposal_covariance_Cholesky_decomposition_upper,negeigenvalues]=chol(inverse_hessian_mat); + %if not positive definite, use generalized Cholesky of Eskow/Schnabel + if negeigenvalues~=0 + proposal_covariance_Cholesky_decomposition_upper=chol_SE(inverse_hessian_mat,0); + end + proposal_covariance_Cholesky_decomposition_upper=proposal_covariance_Cholesky_decomposition_upper*diag(bayestopt_.jscale(indices(blocks==block_iter,1),:)); + %get proposal draw + if strcmpi(sampler_options.proposal_distribution,'rand_multivariate_normal') + n = nxopt; + elseif strcmpi(sampler_options.proposal_distribution,'rand_multivariate_student') + n = options_.student_degrees_of_freedom; + end + + proposed_par = feval(sampler_options.proposal_distribution, xopt_current_block', proposal_covariance_Cholesky_decomposition_upper, n); + % check whether draw is valid and compute posterior + if all( proposed_par(:) > mh_bounds.lb(indices(blocks==block_iter,1),:) ) && all( proposed_par(:) < mh_bounds.ub(indices(blocks==block_iter,1),:) ) + try + logpost = - feval('TaRB_optimizer_wrapper', proposed_par(:),... + current_draw,indices(blocks==block_iter,1),TargetFun,...% inputs for wrapper + varargin{:}); + catch + logpost = -inf; + end + else + logpost = -inf; + end + %get ratio of proposal densities, required because proposal depends + %on current mode via Hessian and is thus not symmetric anymore + if strcmpi(sampler_options.proposal_distribution,'rand_multivariate_normal') + proposal_density_proposed_move_forward=multivariate_normal_pdf(proposed_par,xopt_current_block',proposal_covariance_Cholesky_decomposition_upper,n); + proposal_density_proposed_move_backward=multivariate_normal_pdf(par_start_current_block',xopt_current_block',proposal_covariance_Cholesky_decomposition_upper,n); + elseif strcmpi(sampler_options.proposal_distribution,'rand_multivariate_student') + proposal_density_proposed_move_forward=multivariate_student_pdf(proposed_par,xopt_current_block',proposal_covariance_Cholesky_decomposition_upper,n); + proposal_density_proposed_move_backward=multivariate_student_pdf(par_start_current_block',xopt_current_block',proposal_covariance_Cholesky_decomposition_upper,n); + end + accprob=logpost-last_posterior+ log(proposal_density_proposed_move_backward)-log(proposal_density_proposed_move_forward); %Formula (6), Chib/Ramamurthy + + if (logpost > -inf) && (log(rand) < accprob) + current_draw(indices(blocks==block_iter,1))=proposed_par; + last_posterior=logpost; + accepted_draws_counter =accepted_draws_counter +1; + else %no updating + %do nothing, keep old value + end + end + accepted=accepted_draws_counter/blocked_draws_counter; + par = current_draw; + neval=1; + case 'independent_metropolis_hastings' + neval = 1; + ProposalFun = sampler_options.proposal_distribution; + ProposalDensity = sampler_options.ProposalDensity; + proposal_covariance_Cholesky_decomposition = sampler_options.proposal_covariance_Cholesky_decomposition; + n = sampler_options.n; + xparam1 = sampler_options.xparam1'; + par = feval(ProposalFun, xparam1, proposal_covariance_Cholesky_decomposition, n); + if all( par(:) > mh_bounds.lb ) && all( par(:) < mh_bounds.ub ) + try + logpost = - feval(TargetFun, par(:),varargin{:}); + catch + logpost = -inf; + end + else + logpost = -inf; + end + r = logpost - last_posterior + ... + log(feval(ProposalDensity, last_draw, xparam1, proposal_covariance_Cholesky_decomposition, n)) - ... + log(feval(ProposalDensity, par, xparam1, proposal_covariance_Cholesky_decomposition, n)); + if (logpost > -inf) && (log(rand) < r) + accepted = 1; + else + accepted = 0; + par = last_draw; + logpost = last_posterior; + end end \ No newline at end of file diff --git a/matlab/print_info.m b/matlab/print_info.m index e66b2e82a0..3185e16bf8 100644 --- a/matlab/print_info.m +++ b/matlab/print_info.m @@ -54,15 +54,15 @@ if ~noprint error('One of the eigenvalues is close to 0/0 (the absolute value of numerator and denominator is smaller than %s!\n If you believe that the model has a unique solution you can try to reduce the value of qz_zero_threshold.',num2str(DynareOptions.qz_zero_threshold)) case 8 if size(info,2)>=2 - global M_; + global M_; disp_string=deblank(M_.param_names(info(2),:)); - for ii=1:length(info)-2 - disp_string=[disp_string,', ',deblank(M_.param_names(info(2+ii),:))]; - end - error(['The Jacobian contains NaNs because the following parameters are NaN: '... - disp_string]) + for ii=1:length(info)-2 + disp_string=[disp_string,', ',deblank(M_.param_names(info(2+ii),:))]; + end + error(['The Jacobian contains NaNs because the following parameters are NaN: '... + disp_string]) else - error(['The Jacobian contains NaNs. For more information, use options_.debug.']) + error(['The Jacobian contains NaNs. For more information, use options_.debug.']) end case 9 error(['k_order_pert was unable to compute the solution']) diff --git a/matlab/print_table_prior.m b/matlab/print_table_prior.m index 605adfabf7..d84e69a9cc 100644 --- a/matlab/print_table_prior.m +++ b/matlab/print_table_prior.m @@ -134,25 +134,25 @@ skipline(2) function format_string = build_format_string(PriorMode,PriorStandardDeviation,LowerBound,UpperBound) - format_string = ['%s \t %6.4f \t']; - if isnan(PriorMode) - format_string = [ format_string , ' %s \t']; - else - format_string = [ format_string , ' %6.4f \t']; - end - if ~isnumeric(PriorStandardDeviation) - format_string = [ format_string , ' %s \t']; - else - format_string = [ format_string , ' %6.4f \t']; - end - if ~isnumeric(LowerBound) - format_string = [ format_string , ' %s \t']; - else - format_string = [ format_string , ' %6.4f \t']; - end - if ~isnumeric(UpperBound) - format_string = [ format_string , ' %s \t']; - else - format_string = [ format_string , ' %6.4f \t']; - end - format_string = [ format_string , ' %6.4f \t %6.4f']; \ No newline at end of file +format_string = ['%s \t %6.4f \t']; +if isnan(PriorMode) + format_string = [ format_string , ' %s \t']; +else + format_string = [ format_string , ' %6.4f \t']; +end +if ~isnumeric(PriorStandardDeviation) + format_string = [ format_string , ' %s \t']; +else + format_string = [ format_string , ' %6.4f \t']; +end +if ~isnumeric(LowerBound) + format_string = [ format_string , ' %s \t']; +else + format_string = [ format_string , ' %6.4f \t']; +end +if ~isnumeric(UpperBound) + format_string = [ format_string , ' %s \t']; +else + format_string = [ format_string , ' %6.4f \t']; +end +format_string = [ format_string , ' %6.4f \t %6.4f']; \ No newline at end of file diff --git a/matlab/prior_posterior_statistics.m b/matlab/prior_posterior_statistics.m index b3cfdc933b..cf5d18e14e 100644 --- a/matlab/prior_posterior_statistics.m +++ b/matlab/prior_posterior_statistics.m @@ -331,7 +331,7 @@ if options_.smoother '',M_.exo_names,M_.exo_names_tex,M_.exo_names,... M_.exo_names,'SmoothedShocks',DirectoryName,'_inno'); pm3(endo_nbr,1,ifil(9),B,'Trend_coefficients',... - '',varlist,M_.endo_names_tex,M_.endo_names,... + '',varlist,M_.endo_names_tex,M_.endo_names,... varlist,'TrendCoeff',DirectoryName,'_trend_coeff'); pm3(endo_nbr,gend,ifil(10),B,'Smoothed constant',... '',varlist,M_.endo_names_tex,M_.endo_names,... @@ -357,8 +357,8 @@ if options_.smoother meas_error_names=char(meas_error_names); texnames=char(texnames); pm3(meas_err_nbr,gend,ifil(3),B,'Smoothed measurement errors',... - '',meas_error_names,texnames,meas_error_names,... - meas_error_names,'SmoothedMeasurementErrors',DirectoryName,'_error') + '',meas_error_names,texnames,meas_error_names,... + meas_error_names,'SmoothedMeasurementErrors',DirectoryName,'_error') end end @@ -385,8 +385,8 @@ if options_.forecast texnames=char(texnames); varlist_forecast_ME=intersect(options_.varobs,varlist); pm3(meas_err_nbr,horizon,ifil(12),B,'Forecasted variables (point) with ME',... - '',char(varlist_forecast_ME),texnames,obs_names,... - char(varlist_forecast_ME),'PointForecastME',DirectoryName,'_forc_point_ME') + '',char(varlist_forecast_ME),texnames,obs_names,... + char(varlist_forecast_ME),'PointForecastME',DirectoryName,'_forc_point_ME') end end diff --git a/matlab/prior_posterior_statistics_core.m b/matlab/prior_posterior_statistics_core.m index 3e8e314366..bb21031ea6 100644 --- a/matlab/prior_posterior_statistics_core.m +++ b/matlab/prior_posterior_statistics_core.m @@ -157,22 +157,22 @@ end %initialize arrays if run_smoother - stock_smooth=NaN(endo_nbr,gend,MAX_nsmoo); - stock_update=NaN(endo_nbr,gend,MAX_nsmoo); - stock_innov=NaN(M_.exo_nbr,gend,MAX_ninno); - stock_smoothed_constant=NaN(endo_nbr,gend,MAX_n_smoothed_constant); - stock_smoothed_trend=NaN(endo_nbr,gend,MAX_n_smoothed_trend); - stock_trend_coeff = zeros(endo_nbr,MAX_n_trend_coeff); - if horizon - stock_forcst_mean= NaN(endo_nbr,horizon,MAX_nforc1); - stock_forcst_point = NaN(endo_nbr,horizon,MAX_nforc2); - if ~isequal(M_.H,0) - stock_forcst_point_ME = NaN(length(varobs),horizon,MAX_nforc_ME); - end - end + stock_smooth=NaN(endo_nbr,gend,MAX_nsmoo); + stock_update=NaN(endo_nbr,gend,MAX_nsmoo); + stock_innov=NaN(M_.exo_nbr,gend,MAX_ninno); + stock_smoothed_constant=NaN(endo_nbr,gend,MAX_n_smoothed_constant); + stock_smoothed_trend=NaN(endo_nbr,gend,MAX_n_smoothed_trend); + stock_trend_coeff = zeros(endo_nbr,MAX_n_trend_coeff); + if horizon + stock_forcst_mean= NaN(endo_nbr,horizon,MAX_nforc1); + stock_forcst_point = NaN(endo_nbr,horizon,MAX_nforc2); + if ~isequal(M_.H,0) + stock_forcst_point_ME = NaN(length(varobs),horizon,MAX_nforc_ME); + end + end end if nvn - stock_error = NaN(length(varobs),gend,MAX_nerro); + stock_error = NaN(length(varobs),gend,MAX_nerro); end if naK stock_filter_step_ahead =NaN(length(options_.filter_step_ahead),endo_nbr,gend+max(options_.filter_step_ahead),MAX_naK); @@ -286,10 +286,10 @@ for b=fpar:B horizon+maxlag,1); % add trend, taking into account that last point of sample is still included in forecasts and only cut off later yf(:,IdObs) = yf(:,IdObs)+((options_.first_obs-1)+gend+[1-maxlag:horizon]')*trend_coeff'-... - repmat(mean(trend_coeff*[options_.first_obs:options_.first_obs+gend-1],2)',length(1-maxlag:horizon),1); %center trend + repmat(mean(trend_coeff*[options_.first_obs:options_.first_obs+gend-1],2)',length(1-maxlag:horizon),1); %center trend else % add trend, taking into account that last point of sample is still included in forecasts and only cut off later - yf(:,IdObs) = yf(:,IdObs)+((options_.first_obs-1)+gend+[1-maxlag:horizon]')*trend_coeff'; + yf(:,IdObs) = yf(:,IdObs)+((options_.first_obs-1)+gend+[1-maxlag:horizon]')*trend_coeff'; end if options_.loglinear yf = yf+repmat(log(SteadyState'),horizon+maxlag,1); @@ -303,10 +303,10 @@ for b=fpar:B repmat(mean_varobs,[horizon+maxlag,1,1]); % add trend, taking into account that last point of sample is still included in forecasts and only cut off later yf1(:,IdObs) = yf1(:,IdObs)+((options_.first_obs-1)+gend+[1-maxlag:horizon]')*trend_coeff'-... - repmat(mean(trend_coeff*[options_.first_obs:options_.first_obs+gend-1],2)',length(1-maxlag:horizon),1); %center trend + repmat(mean(trend_coeff*[options_.first_obs:options_.first_obs+gend-1],2)',length(1-maxlag:horizon),1); %center trend else - % add trend, taking into account that last point of sample is still included in forecasts and only cut off later - yf1(:,IdObs,:) = yf1(:,IdObs,:)+repmat(((options_.first_obs-1)+gend+[1-maxlag:horizon]')* ... + % add trend, taking into account that last point of sample is still included in forecasts and only cut off later + yf1(:,IdObs,:) = yf1(:,IdObs,:)+repmat(((options_.first_obs-1)+gend+[1-maxlag:horizon]')* ... trend_coeff',[1,1,1]); end if options_.loglinear diff --git a/matlab/quadratic_matrix_equation_solver.m b/matlab/quadratic_matrix_equation_solver.m index f222df843f..d96ea0d9d5 100644 --- a/matlab/quadratic_matrix_equation_solver.m +++ b/matlab/quadratic_matrix_equation_solver.m @@ -106,34 +106,34 @@ end function f = eval_quadratic_matrix_equation(A,B,C,X) - f = C + (B + A*X)*X; +f = C + (B + A*X)*X; function [p0,p1] = merit_polynomial(A,H,F) - AHH = A*H*H; - gamma = norm(AHH,'fro')^2; - alpha = norm(F,'fro')^2; - beta = trace(F*AHH*AHH*F); - p0 = [gamma, -beta, alpha+beta, -2*alpha, alpha]; - p1 = [4*gamma, -3*beta, 2*(alpha+beta), -2*alpha]; +AHH = A*H*H; +gamma = norm(AHH,'fro')^2; +alpha = norm(F,'fro')^2; +beta = trace(F*AHH*AHH*F); +p0 = [gamma, -beta, alpha+beta, -2*alpha, alpha]; +p1 = [4*gamma, -3*beta, 2*(alpha+beta), -2*alpha]; function t = line_search(A,H,F) - [p0,p1] = merit_polynomial(A,H,F); - if any(isnan(p0)) || any(isinf(p0)) - t = 1.0; - return - end - r = roots(p1); - s = [Inf(3,1),r]; - for i = 1:3 - if isreal(r(i)) - s(i,1) = p0(1)*r(i)^4 + p0(2)*r(i)^3 + p0(3)*r(i)^2 + p0(4)*r(i) + p0(5); - end - end - s = sortrows(s,1); - t = s(1,2); - if t<=1e-12 || t>=2 - t = 1; +[p0,p1] = merit_polynomial(A,H,F); +if any(isnan(p0)) || any(isinf(p0)) + t = 1.0; + return +end +r = roots(p1); +s = [Inf(3,1),r]; +for i = 1:3 + if isreal(r(i)) + s(i,1) = p0(1)*r(i)^4 + p0(2)*r(i)^3 + p0(3)*r(i)^2 + p0(4)*r(i) + p0(5); end +end +s = sortrows(s,1); +t = s(1,2); +if t<=1e-12 || t>=2 + t = 1; +end %@test:1 %$ addpath ../matlab diff --git a/matlab/ramsey_policy.m b/matlab/ramsey_policy.m index 9766a5519c..ccc50fb040 100644 --- a/matlab/ramsey_policy.m +++ b/matlab/ramsey_policy.m @@ -38,7 +38,7 @@ else error('You have specified a steady state file, but not provided an instrument. Either delete the steady state file or provide an instrument') end end - + info = stoch_simul(var_list); oo_.steady_state = oo_.dr.ys; diff --git a/matlab/read_key_value_string.m b/matlab/read_key_value_string.m index d6b7124ed6..d92fb26985 100644 --- a/matlab/read_key_value_string.m +++ b/matlab/read_key_value_string.m @@ -40,7 +40,7 @@ iComma = strfind(s,','); %delete commata in sublists from further checks for sublist_iter=length(i_begin_sublist):-1:1 - iComma(iComma>=i_begin_sublist(sublist_iter) & iComma<=i_end_sublist(sublist_iter))=[]; + iComma(iComma>=i_begin_sublist(sublist_iter) & iComma<=i_end_sublist(sublist_iter))=[]; end nComma = length(iComma); @@ -85,10 +85,10 @@ end function j = comma2opt(i) - if isodd(i) - % The comma is a separator between a Key and a Value (returned j is minus the option number). - j = - (i+1)/2; - else - % The comma is a separator between two options (returned j is the option number). - j = i/2; - end \ No newline at end of file +if isodd(i) + % The comma is a separator between a Key and a Value (returned j is minus the option number). + j = - (i+1)/2; +else + % The comma is a separator between two options (returned j is the option number). + j = i/2; +end \ No newline at end of file diff --git a/matlab/read_variables.m b/matlab/read_variables.m index 6859a67957..a96e8d013c 100644 --- a/matlab/read_variables.m +++ b/matlab/read_variables.m @@ -68,61 +68,61 @@ if ~exist(fullname) end switch (extension) - case '.m' - eval(basename); - for dyn_i_01=1:var_size_01 - dyn_tmp_01 = eval(var_names_01{dyn_i_01}); + case '.m' + eval(basename); + for dyn_i_01=1:var_size_01 + dyn_tmp_01 = eval(var_names_01{dyn_i_01}); + if length(dyn_tmp_01) > dyn_size_01 && dyn_size_01 > 0 + cd(old_pwd) + error('data size is too large') + end + dyn_data_01(:,dyn_i_01) = dyn_tmp_01; + end + case '.mat' + s = load(basename); + for dyn_i_01=1:var_size_01 + dyn_tmp_01 = s.(var_names_01{dyn_i_01}); + if length(dyn_tmp_01) > dyn_size_01 && dyn_size_01 > 0 + cd(old_pwd) + error('data size is too large') + end + dyn_data_01(:,dyn_i_01) = dyn_tmp_01; + end + case { '.xls', '.xlsx' } + [freq,init,data,varlist] = load_xls_file_data(fullname,xls_sheet,xls_range); + for dyn_i_01=1:var_size_01 + iv = strmatch(strtrim(var_names_01(dyn_i_01,:)),varlist,'exact'); + if ~isempty(iv) + dyn_tmp_01 = [data(:,iv)]'; if length(dyn_tmp_01) > dyn_size_01 && dyn_size_01 > 0 cd(old_pwd) error('data size is too large') end dyn_data_01(:,dyn_i_01) = dyn_tmp_01; + else + cd(old_pwd) + error([strtrim(var_names_01(dyn_i_01,:)) ' not found in ' fullname]) end - case '.mat' - s = load(basename); - for dyn_i_01=1:var_size_01 - dyn_tmp_01 = s.(var_names_01{dyn_i_01}); + end + case '.csv' + [freq,init,data,varlist] = load_csv_file_data(fullname); + for dyn_i_01=1:var_size_01 + iv = strmatch(var_names_01{dyn_i_01},varlist,'exact'); + if ~isempty(iv) + dyn_tmp_01 = [data(:,iv)]'; if length(dyn_tmp_01) > dyn_size_01 && dyn_size_01 > 0 cd(old_pwd) error('data size is too large') end dyn_data_01(:,dyn_i_01) = dyn_tmp_01; + else + cd(old_pwd) + error([var_names_01{dyn_i_01} ' not found in ' fullname]) end - case { '.xls', '.xlsx' } - [freq,init,data,varlist] = load_xls_file_data(fullname,xls_sheet,xls_range); - for dyn_i_01=1:var_size_01 - iv = strmatch(strtrim(var_names_01(dyn_i_01,:)),varlist,'exact'); - if ~isempty(iv) - dyn_tmp_01 = [data(:,iv)]'; - if length(dyn_tmp_01) > dyn_size_01 && dyn_size_01 > 0 - cd(old_pwd) - error('data size is too large') - end - dyn_data_01(:,dyn_i_01) = dyn_tmp_01; - else - cd(old_pwd) - error([strtrim(var_names_01(dyn_i_01,:)) ' not found in ' fullname]) - end - end - case '.csv' - [freq,init,data,varlist] = load_csv_file_data(fullname); - for dyn_i_01=1:var_size_01 - iv = strmatch(var_names_01{dyn_i_01},varlist,'exact'); - if ~isempty(iv) - dyn_tmp_01 = [data(:,iv)]'; - if length(dyn_tmp_01) > dyn_size_01 && dyn_size_01 > 0 - cd(old_pwd) - error('data size is too large') - end - dyn_data_01(:,dyn_i_01) = dyn_tmp_01; - else - cd(old_pwd) - error([var_names_01{dyn_i_01} ' not found in ' fullname]) - end - end - otherwise - cd(old_pwd) - error(['Unsupported extension for datafile: ' extension]) + end + otherwise + cd(old_pwd) + error(['Unsupported extension for datafile: ' extension]) end cd(old_pwd) diff --git a/matlab/realtime_shock_decomposition.m b/matlab/realtime_shock_decomposition.m index 2e47066e15..72b1bde3ef 100644 --- a/matlab/realtime_shock_decomposition.m +++ b/matlab/realtime_shock_decomposition.m @@ -63,7 +63,7 @@ if isempty(parameter_set) parameter_set = 'posterior_mode'; else error(['realtime_shock_decomposition: option parameter_set is not specified ' ... - 'and posterior mode is not available']) + 'and posterior mode is not available']) end end @@ -103,7 +103,7 @@ if forecast_ && any(forecast_params), end for j=presample+1:nobs, -% evalin('base',['options_.nobs=' int2str(j) ';']) + % evalin('base',['options_.nobs=' int2str(j) ';']) options_.nobs=j; [oo, M_, junk2, junk3, Smoothed_Variables_deviation_from_mean] = evaluate_smoother(parameter_set,varlist,M_,oo_,options_,bayestopt_,estim_params_); @@ -165,7 +165,7 @@ for j=presample+1:nobs, z(:,1:nshocks,i) = z(:,1:nshocks,i) + B(inv_order_var,:).*repmat(epsilon(:,i)',endo_nbr,1); end -% z(:,1:nshocks,i) = z(:,1:nshocks,i) + B(inv_order_var,:).*repmat(epsilon(:,i)',endo_nbr,1); + % z(:,1:nshocks,i) = z(:,1:nshocks,i) + B(inv_order_var,:).*repmat(epsilon(:,i)',endo_nbr,1); z(:,nshocks+1,i) = z(:,nshocks+2,i) - sum(z(:,1:nshocks,i),2); end @@ -197,13 +197,13 @@ for j=presample+1:nobs, zn(:,1:nshocks,i) = zn(:,1:nshocks,i) + B(inv_order_var,:).*repmat(epsilon(:,i+gend-forecast_-1)',endo_nbr,1); end -% zn(:,1:nshocks,i) = zn(:,1:nshocks,i) + B(inv_order_var,:).*repmat(epsilon(:,i+gend-forecast_-1)',endo_nbr,1); + % zn(:,1:nshocks,i) = zn(:,1:nshocks,i) + B(inv_order_var,:).*repmat(epsilon(:,i+gend-forecast_-1)',endo_nbr,1); zn(:,nshocks+1,i) = zn(:,nshocks+2,i) - sum(zn(:,1:nshocks,i),2); end oo_.conditional_shock_decomposition.(['time_' int2str(j-forecast_)])=zn; end %% - + if init, zreal(:,:,1:j) = z(:,:,1:j); else @@ -218,7 +218,7 @@ for j=presample+1:nobs, zfrcst(:,:,j+1) = z(:,:,gend+1); oo_.realtime_forecast_shock_decomposition.(['time_' int2str(j)])=z(:,:,gend:end); if j>forecast_+presample - %% realtime conditional shock decomp k step ahead + %% realtime conditional shock decomp k step ahead oo_.realtime_conditional_shock_decomposition.(['time_' int2str(j-forecast_)]) = ... zreal(:,:,j-forecast_:j) - ... oo_.realtime_forecast_shock_decomposition.(['time_' int2str(j-forecast_)]); @@ -226,7 +226,7 @@ for j=presample+1:nobs, oo_.realtime_forecast_shock_decomposition.(['time_' int2str(j-forecast_)])(:,end,:); oo_.realtime_conditional_shock_decomposition.(['time_' int2str(j-forecast_)])(:,end,:) = ... zreal(:,end,j-forecast_:j); - + if j==nobs for my_forecast_=(forecast_-1):-1:1, oo_.realtime_conditional_shock_decomposition.(['time_' int2str(j-my_forecast_)]) = ... diff --git a/matlab/reduced_rank_cholesky.m b/matlab/reduced_rank_cholesky.m index 1af9ec6090..f2b6ff74c2 100644 --- a/matlab/reduced_rank_cholesky.m +++ b/matlab/reduced_rank_cholesky.m @@ -52,7 +52,7 @@ function T = reduced_rank_cholesky(X) % % You should have received a copy of the GNU General Public License % along with Dynare. If not, see <http://www.gnu.org/licenses/>. - + [T,X_is_not_positive_definite] = chol(X); if X_is_not_positive_definite diff --git a/matlab/resid.m b/matlab/resid.m index 7383c19443..71e0f66194 100644 --- a/matlab/resid.m +++ b/matlab/resid.m @@ -60,7 +60,7 @@ if any(imag(oo_.steady_state)) end end end - + if options_.steadystate_flag [oo_.steady_state,M_.params,info] = ... evaluate_steady_state(oo_.steady_state,M_,options_,oo_,0); diff --git a/matlab/rotated_slice_sampler.m b/matlab/rotated_slice_sampler.m index 66908d77d4..d5e53e384e 100644 --- a/matlab/rotated_slice_sampler.m +++ b/matlab/rotated_slice_sampler.m @@ -1,184 +1,184 @@ -function [theta, fxsim, neval] = rotated_slice_sampler(objective_function,theta,thetaprior,sampler_options,varargin) -% ---------------------------------------------------------- -% ROTATED SLICE SAMPLER - with stepping out (Neal, 2003) -% extension of the orthogonal univarite sampler (slice_sampler.m) -% copyright M. Ratto (European Commission) -% -% objective_function(theta,varargin): -log of any unnormalized pdf -% with varargin (optional) a vector of auxiliaty parameters -% to be passed to f( ). -% ---------------------------------------------------------- -% -% INPUTS -% objective_function: objective function (expressed as minus the log of a density) -% theta: last value of theta -% thetaprior: bounds of the theta space -% sampler_options: posterior sampler options -% varargin: optional input arguments to objective function -% -% OUTPUTS -% theta: new theta sample -% fxsim: value of the objective function for the new sample -% neval: number of function evaluations -% -% SPECIAL REQUIREMENTS -% none - -% Copyright (C) 2015 Dynare Team -% -% This file is part of Dynare. -% -% Dynare is free software: you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation, either version 3 of the License, or -% (at your option) any later version. -% -% Dynare is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. -% -% You should have received a copy of the GNU General Public License -% along with Dynare. If not, see <http://www.gnu.org/licenses/>. - -theta=theta(:); -npar = length(theta); -neval = zeros(npar,1); -W1=[]; -if isfield(sampler_options,'WR'), - W1 = sampler_options.WR; -end -if ~isempty(sampler_options.mode), - mm = sampler_options.mode; - n = length(mm); - for j=1:n, - distance(j)=sqrt(sum((theta-mm(j).m).^2)); - end - [m, im] = min(distance); - - r=im; - V1 = mm(r).m; - jj=0; - for j=1:n, - if j~=r, - jj=jj+1; - tmp=mm(j).m-mm(r).m; - %tmp=mm(j).m-theta; - V1(:,jj)=tmp/norm(tmp); - end - end - resul=randperm(n-1,n-1); - V1 = V1(:,resul); - - %V1 = V1(:, randperm(n-1)); -% %d = chol(mm(r).invhess); -% %V1 = transpose(feval(sampler_options.proposal_distribution, transpose(mm(r).m), d, npar)); -% -% V1=eye(npar); -% V1=V1(:,randperm(npar)); -% for j=1:2, -% V1(:,j)=mm(r(j)).m-theta; -% V1(:,j)=V1(:,j)/norm(V1(:,j)); -% end -% % Gram-Schmidt -% for j=2:npar, -% for k=1:j-1, -% V1(:,j)=V1(:,j)-V1(:,k)'*V1(:,j)*V1(:,k); -% end -% V1(:,j)=V1(:,j)/norm(V1(:,j)); -% end -% for j=1:n, -% distance(j)=sqrt(sum((theta-mm(j).m).^2)); -% end -% [m, im] = min(distance); -% if im==r, -% fxsim=[]; -% return, -% else -% theta1=theta; -% end -else - V1 = sampler_options.V1; -end -npar=size(V1,2); - -for it=1:npar, - theta0 = theta; - neval(it) = 0; - xold = 0; - % XLB = thetaprior(3); - % XUB = thetaprior(4); - tb=sort([(thetaprior(:,1)-theta)./V1(:,it) (thetaprior(:,2)-theta)./V1(:,it)],2); - XLB=max(tb(:,1)); - XUB=min(tb(:,2)); - if isempty(W1), - W = (XUB-XLB); %*0.8; - else - W = W1(it); - end - - % ------------------------------------------------------- - % 1. DRAW Z = ln[f(X0)] - EXP(1) where EXP(1)=-ln(U(0,1)) - % THIS DEFINES THE SLICE S={x: z < ln(f(x))} - % ------------------------------------------------------- - - fxold = -feval(objective_function,theta,varargin{:}); - %I have to be sure that the rotation is for L,R or for Fxold, theta(it) - neval(it) = neval(it) + 1; - Z = fxold + log(rand(1,1)); - % ------------------------------------------------------------- - % 2. FIND I=(L,R) AROUND X0 THAT CONTAINS S AS MUCH AS POSSIBLE - % STEPPING-OUT PROCEDURE - % ------------------------------------------------------------- - u = rand(1,1); - L = max(XLB,xold-W*u); - R = min(XUB,L+W); - - %[L R]=slice_rotation(L, R, alpha); - while(L > XLB) - xsim = L; - theta = theta0+xsim*V1(:,it); - fxl = -feval(objective_function,theta,varargin{:}); - neval(it) = neval(it) + 1; - if (fxl <= Z) - break; - end - L = max(XLB,L-W); - end - while(R < XUB) - xsim = R; - theta = theta0+xsim*V1(:,it); - fxr = -feval(objective_function,theta,varargin{:}); - neval(it) = neval(it) + 1; - if (fxr <= Z) - break; - end - R = min(XUB,R+W); - end - % ------------------------------------------------------ - % 3. SAMPLING FROM THE SET A = (I INTERSECT S) = (LA,RA) - % ------------------------------------------------------ - fxsim = Z-1; - while (fxsim < Z) - u = rand(1,1); - xsim = L + u*(R - L); - theta = theta0+xsim*V1(:,it); - fxsim = -feval(objective_function,theta,varargin{:}); - neval(it) = neval(it) + 1; - if (xsim > xold) - R = xsim; - else - L = xsim; - end - end -end - -% if ~isempty(sampler_options.mode), -% dist1=sqrt(sum((theta-mm(r).m).^2)); -% if dist1>distance(r), -% theta=theta1; -% fxsim=[]; -% end -% end -end - +function [theta, fxsim, neval] = rotated_slice_sampler(objective_function,theta,thetaprior,sampler_options,varargin) +% ---------------------------------------------------------- +% ROTATED SLICE SAMPLER - with stepping out (Neal, 2003) +% extension of the orthogonal univarite sampler (slice_sampler.m) +% copyright M. Ratto (European Commission) +% +% objective_function(theta,varargin): -log of any unnormalized pdf +% with varargin (optional) a vector of auxiliaty parameters +% to be passed to f( ). +% ---------------------------------------------------------- +% +% INPUTS +% objective_function: objective function (expressed as minus the log of a density) +% theta: last value of theta +% thetaprior: bounds of the theta space +% sampler_options: posterior sampler options +% varargin: optional input arguments to objective function +% +% OUTPUTS +% theta: new theta sample +% fxsim: value of the objective function for the new sample +% neval: number of function evaluations +% +% SPECIAL REQUIREMENTS +% none + +% Copyright (C) 2015 Dynare Team +% +% This file is part of Dynare. +% +% Dynare is free software: you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation, either version 3 of the License, or +% (at your option) any later version. +% +% Dynare is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with Dynare. If not, see <http://www.gnu.org/licenses/>. + +theta=theta(:); +npar = length(theta); +neval = zeros(npar,1); +W1=[]; +if isfield(sampler_options,'WR'), + W1 = sampler_options.WR; +end +if ~isempty(sampler_options.mode), + mm = sampler_options.mode; + n = length(mm); + for j=1:n, + distance(j)=sqrt(sum((theta-mm(j).m).^2)); + end + [m, im] = min(distance); + + r=im; + V1 = mm(r).m; + jj=0; + for j=1:n, + if j~=r, + jj=jj+1; + tmp=mm(j).m-mm(r).m; + %tmp=mm(j).m-theta; + V1(:,jj)=tmp/norm(tmp); + end + end + resul=randperm(n-1,n-1); + V1 = V1(:,resul); + + %V1 = V1(:, randperm(n-1)); + % %d = chol(mm(r).invhess); + % %V1 = transpose(feval(sampler_options.proposal_distribution, transpose(mm(r).m), d, npar)); + % + % V1=eye(npar); + % V1=V1(:,randperm(npar)); + % for j=1:2, + % V1(:,j)=mm(r(j)).m-theta; + % V1(:,j)=V1(:,j)/norm(V1(:,j)); + % end + % % Gram-Schmidt + % for j=2:npar, + % for k=1:j-1, + % V1(:,j)=V1(:,j)-V1(:,k)'*V1(:,j)*V1(:,k); + % end + % V1(:,j)=V1(:,j)/norm(V1(:,j)); + % end + % for j=1:n, + % distance(j)=sqrt(sum((theta-mm(j).m).^2)); + % end + % [m, im] = min(distance); + % if im==r, + % fxsim=[]; + % return, + % else + % theta1=theta; + % end +else + V1 = sampler_options.V1; +end +npar=size(V1,2); + +for it=1:npar, + theta0 = theta; + neval(it) = 0; + xold = 0; + % XLB = thetaprior(3); + % XUB = thetaprior(4); + tb=sort([(thetaprior(:,1)-theta)./V1(:,it) (thetaprior(:,2)-theta)./V1(:,it)],2); + XLB=max(tb(:,1)); + XUB=min(tb(:,2)); + if isempty(W1), + W = (XUB-XLB); %*0.8; + else + W = W1(it); + end + + % ------------------------------------------------------- + % 1. DRAW Z = ln[f(X0)] - EXP(1) where EXP(1)=-ln(U(0,1)) + % THIS DEFINES THE SLICE S={x: z < ln(f(x))} + % ------------------------------------------------------- + + fxold = -feval(objective_function,theta,varargin{:}); + %I have to be sure that the rotation is for L,R or for Fxold, theta(it) + neval(it) = neval(it) + 1; + Z = fxold + log(rand(1,1)); + % ------------------------------------------------------------- + % 2. FIND I=(L,R) AROUND X0 THAT CONTAINS S AS MUCH AS POSSIBLE + % STEPPING-OUT PROCEDURE + % ------------------------------------------------------------- + u = rand(1,1); + L = max(XLB,xold-W*u); + R = min(XUB,L+W); + + %[L R]=slice_rotation(L, R, alpha); + while(L > XLB) + xsim = L; + theta = theta0+xsim*V1(:,it); + fxl = -feval(objective_function,theta,varargin{:}); + neval(it) = neval(it) + 1; + if (fxl <= Z) + break; + end + L = max(XLB,L-W); + end + while(R < XUB) + xsim = R; + theta = theta0+xsim*V1(:,it); + fxr = -feval(objective_function,theta,varargin{:}); + neval(it) = neval(it) + 1; + if (fxr <= Z) + break; + end + R = min(XUB,R+W); + end + % ------------------------------------------------------ + % 3. SAMPLING FROM THE SET A = (I INTERSECT S) = (LA,RA) + % ------------------------------------------------------ + fxsim = Z-1; + while (fxsim < Z) + u = rand(1,1); + xsim = L + u*(R - L); + theta = theta0+xsim*V1(:,it); + fxsim = -feval(objective_function,theta,varargin{:}); + neval(it) = neval(it) + 1; + if (xsim > xold) + R = xsim; + else + L = xsim; + end + end +end + +% if ~isempty(sampler_options.mode), +% dist1=sqrt(sum((theta-mm(r).m).^2)); +% if dist1>distance(r), +% theta=theta1; +% fxsim=[]; +% end +% end +end + diff --git a/matlab/rplot.m b/matlab/rplot.m index 5f19018941..b77bbdd2fa 100644 --- a/matlab/rplot.m +++ b/matlab/rplot.m @@ -140,16 +140,16 @@ if options_.TeX && any(strcmp('eps',cellstr(options_.graph_format))) end function []=create_TeX_loader(fidTeX,options,figpath,caption,label_name,label_type,scale_factor) - if nargin<6 - scale_factor=1; - end - fprintf(fidTeX,' \n'); - fprintf(fidTeX,'\\begin{figure}[H]\n'); - fprintf(fidTeX,'\\centering \n'); - fprintf(fidTeX,'\\includegraphics[width=%2.2f\\textwidth]{%s}\n',0.8*scale_factor,strrep(figpath,'\','/')); - fprintf(fidTeX,'\\caption{%s.}',caption); - fprintf(fidTeX,'\\label{Fig:%s:%s}\n',label_name,label_type); - fprintf(fidTeX,'\\end{figure}\n\n'); +if nargin<6 + scale_factor=1; +end +fprintf(fidTeX,' \n'); +fprintf(fidTeX,'\\begin{figure}[H]\n'); +fprintf(fidTeX,'\\centering \n'); +fprintf(fidTeX,'\\includegraphics[width=%2.2f\\textwidth]{%s}\n',0.8*scale_factor,strrep(figpath,'\','/')); +fprintf(fidTeX,'\\caption{%s.}',caption); +fprintf(fidTeX,'\\label{Fig:%s:%s}\n',label_name,label_type); +fprintf(fidTeX,'\\end{figure}\n\n'); % 02/28/01 MJ replaced bseastr by MATLAB's strmatch % 06/19/01 MJ added 'exact' to strmatch calls diff --git a/matlab/score.m b/matlab/score.m index 273ca63953..f9d418bfec 100644 --- a/matlab/score.m +++ b/matlab/score.m @@ -25,92 +25,92 @@ function [DLIK] = score(T,R,Q,H,P,Y,DT,DYss,DOm,DH,DP,start,mf,kalman_tol,riccat % You should have received a copy of the GNU General Public License % along with Dynare. If not, see <http://www.gnu.org/licen - k = size(DT,3); % number of structural parameters - smpl = size(Y,2); % Sample size. - mm = size(T,2); % Number of state variables. - a = zeros(mm,1); % State vector. - Om = R*Q*transpose(R); % Variance of R times the vector of structural innovations. - t = 0; % Initialization of the time index. - oldK = 0; - notsteady = 1; % Steady state flag. - F_singular = 1; - - DLIK = zeros(k,1); % Initialization of the score. - Da = zeros(mm,k); % State vector. - Dv = zeros(length(mf),k); % observation vector. - +k = size(DT,3); % number of structural parameters +smpl = size(Y,2); % Sample size. +mm = size(T,2); % Number of state variables. +a = zeros(mm,1); % State vector. +Om = R*Q*transpose(R); % Variance of R times the vector of structural innovations. +t = 0; % Initialization of the time index. +oldK = 0; +notsteady = 1; % Steady state flag. +F_singular = 1; + +DLIK = zeros(k,1); % Initialization of the score. +Da = zeros(mm,k); % State vector. +Dv = zeros(length(mf),k); % observation vector. + % for ii = 1:k % DOm = DR(:,:,ii)*Q*transpose(R) + R*DQ(:,:,ii)*transpose(R) + R*Q*transpose(DR(:,:,ii)); % end - - while notsteady & t<smpl - t = t+1; - v = Y(:,t)-a(mf); - F = P(mf,mf) + H; - if rcond(F) < kalman_tol - if ~all(abs(F(:))<kalman_tol) - return - else - a = T*a; - P = T*P*transpose(T)+Om; - end + +while notsteady & t<smpl + t = t+1; + v = Y(:,t)-a(mf); + F = P(mf,mf) + H; + if rcond(F) < kalman_tol + if ~all(abs(F(:))<kalman_tol) + return else - F_singular = 0; - iF = inv(F); - K = P(:,mf)*iF; - - [DK,DF,DP1] = computeDKalman(T,DT,DOm,P,DP,DH,mf,iF,K); - for ii = 1:k - Dv(:,ii) = -Da(mf,ii)-DYss(mf,ii); - Da(:,ii) = DT(:,:,ii)*(a+K*v) + T*(Da(:,ii)+DK(:,:,ii)*v + K*Dv(:,ii)); - if t>=start - DLIK(ii,1) = DLIK(ii,1) + trace( iF*DF(:,:,ii) ) + 2*Dv(:,ii)'*iF*v - v'*(iF*DF(:,:,ii)*iF)*v; - end + a = T*a; + P = T*P*transpose(T)+Om; + end + else + F_singular = 0; + iF = inv(F); + K = P(:,mf)*iF; + + [DK,DF,DP1] = computeDKalman(T,DT,DOm,P,DP,DH,mf,iF,K); + for ii = 1:k + Dv(:,ii) = -Da(mf,ii)-DYss(mf,ii); + Da(:,ii) = DT(:,:,ii)*(a+K*v) + T*(Da(:,ii)+DK(:,:,ii)*v + K*Dv(:,ii)); + if t>=start + DLIK(ii,1) = DLIK(ii,1) + trace( iF*DF(:,:,ii) ) + 2*Dv(:,ii)'*iF*v - v'*(iF*DF(:,:,ii)*iF)*v; end - a = T*(a+K*v); - P = T*(P-K*P(mf,:))*transpose(T)+Om; - DP = DP1; end - notsteady = max(max(abs(K-oldK))) > riccati_tol; - oldK = K; + a = T*(a+K*v); + P = T*(P-K*P(mf,:))*transpose(T)+Om; + DP = DP1; end + notsteady = max(max(abs(K-oldK))) > riccati_tol; + oldK = K; +end - if F_singular - error('The variance of the forecast error remains singular until the end of the sample') - end +if F_singular + error('The variance of the forecast error remains singular until the end of the sample') +end - for ii = 1:k - tmp0(:,:,ii) = iF*DF(:,:,ii)*iF; - end - - if t < smpl - t0 = t+1; - while t < smpl - t = t+1; - v = Y(:,t)-a(mf); - for ii = 1:k - Dv(:,ii) = -Da(mf,ii)-DYss(mf,ii); - Da(:,ii) = DT(:,:,ii)*(a+K*v) + T*(Da(:,ii)+DK(:,:,ii)*v + K*Dv(:,ii)); - if t>=start - DLIK(ii,1) = DLIK(ii,1) + trace( iF*DF(:,:,ii) ) + 2*Dv(:,ii)'*iF*v - v'*(iF*DF(:,:,ii)*iF)*v; - end - end - a = T*(a+K*v); - end +for ii = 1:k + tmp0(:,:,ii) = iF*DF(:,:,ii)*iF; +end + +if t < smpl + t0 = t+1; + while t < smpl + t = t+1; + v = Y(:,t)-a(mf); for ii = 1:k -% DLIK(ii,1) = DLIK(ii,1) + (smpl-t0+1)*trace( iF*DF(:,:,ii) ); + Dv(:,ii) = -Da(mf,ii)-DYss(mf,ii); + Da(:,ii) = DT(:,:,ii)*(a+K*v) + T*(Da(:,ii)+DK(:,:,ii)*v + K*Dv(:,ii)); + if t>=start + DLIK(ii,1) = DLIK(ii,1) + trace( iF*DF(:,:,ii) ) + 2*Dv(:,ii)'*iF*v - v'*(iF*DF(:,:,ii)*iF)*v; + end end - - end - - DLIK = DLIK/2; + a = T*(a+K*v); + end + for ii = 1:k + % DLIK(ii,1) = DLIK(ii,1) + (smpl-t0+1)*trace( iF*DF(:,:,ii) ); + end +end + +DLIK = DLIK/2; + % end of main function - + function [DK,DF,DP1] = computeDKalman(T,DT,DOm,P,DP,DH,mf,iF,K) - k = size(DT,3); - tmp = P-K*P(mf,:); +k = size(DT,3); +tmp = P-K*P(mf,:); for ii = 1:k DF(:,:,ii) = DP(mf,mf,ii) + DH(:,:,ii); @@ -123,4 +123,3 @@ end % end of computeDKalman - \ No newline at end of file diff --git a/matlab/set_dynare_random_generator_state.m b/matlab/set_dynare_random_generator_state.m index f16ce13aed..209965124b 100644 --- a/matlab/set_dynare_random_generator_state.m +++ b/matlab/set_dynare_random_generator_state.m @@ -23,37 +23,37 @@ function [state_u,state_n] = set_dynare_random_generator_state(state_u,state_n) % You should have received a copy of the GNU General Public License % along with Dynare. If not, see <http://www.gnu.org/licenses/>. - matlab_random_streams = ~(isoctave || matlab_ver_less_than('7.7')); +matlab_random_streams = ~(isoctave || matlab_ver_less_than('7.7')); - if matlab_random_streams% Use new matlab interface. +if matlab_random_streams% Use new matlab interface. + if matlab_ver_less_than('7.12') + s = RandStream.getDefaultStream(); + else + s = RandStream.getGlobalStream(); + end + if isequal(s.Type,'legacy') + rand('state',state_u); + randn('state',state_n); + else + if ~isequal(state_u,state_n) + error(['You are using the new Matlab RandStream mechanism ' ... + 'with a single random generator, but the values ' ... + 'of the state of the uniformly ' ... + 'distributed numbers and of the state of the ' ... + 'normally distributed numbers are different. Something must be ' ... + 'wrong, such as reloading old Metropolis runs, ' ... + 'computed on a different version of Matlab. If you ' ... + 'don''t understand the origin of the problem, ' ... + 'please, contact Dynare''s development team.']) + end + s.State = state_u; if matlab_ver_less_than('7.12') - s = RandStream.getDefaultStream(); + RandStream.setDefaultStream(s); else - s = RandStream.getGlobalStream(); + RandStream.setGlobalStream(s); end - if isequal(s.Type,'legacy') - rand('state',state_u); - randn('state',state_n); - else - if ~isequal(state_u,state_n) - error(['You are using the new Matlab RandStream mechanism ' ... - 'with a single random generator, but the values ' ... - 'of the state of the uniformly ' ... - 'distributed numbers and of the state of the ' ... - 'normally distributed numbers are different. Something must be ' ... - 'wrong, such as reloading old Metropolis runs, ' ... - 'computed on a different version of Matlab. If you ' ... - 'don''t understand the origin of the problem, ' ... - 'please, contact Dynare''s development team.']) - end - s.State = state_u; - if matlab_ver_less_than('7.12') - RandStream.setDefaultStream(s); - else - RandStream.setGlobalStream(s); - end - end - else% Use old matlab interface. - rand('state',state_u); - randn('state',state_n); - end \ No newline at end of file + end +else% Use old matlab interface. + rand('state',state_u); + randn('state',state_n); +end \ No newline at end of file diff --git a/matlab/set_prior.m b/matlab/set_prior.m index 4c9e604117..bb4924c4c0 100644 --- a/matlab/set_prior.m +++ b/matlab/set_prior.m @@ -158,7 +158,7 @@ bayestopt_.p7 = bayestopt_.p6 ; %% check for point priors and disallow them as they do not work with MCMC if any(bayestopt_.p2 ==0) error(sprintf(['Error in prior for %s: you cannot use a point prior in estimation. Either increase the prior standard deviation',... - ' or fix the parameter completely.'], bayestopt_.name{bayestopt_.p2 ==0})) + ' or fix the parameter completely.'], bayestopt_.name{bayestopt_.p2 ==0})) end % generalized location parameters by default for beta distribution diff --git a/matlab/shock_decomposition.m b/matlab/shock_decomposition.m index 9c5144110c..c63facfe78 100644 --- a/matlab/shock_decomposition.m +++ b/matlab/shock_decomposition.m @@ -114,7 +114,7 @@ for i=1:gend end if i > options_.shock_decomp.init_state - z(:,1:nshocks,i) = z(:,1:nshocks,i) + B(inv_order_var,:).*repmat(epsilon(:,i)',endo_nbr,1); + z(:,1:nshocks,i) = z(:,1:nshocks,i) + B(inv_order_var,:).*repmat(epsilon(:,i)',endo_nbr,1); end z(:,nshocks+1,i) = z(:,nshocks+2,i) - sum(z(:,1:nshocks,i),2); end diff --git a/matlab/simulated_moments_estimation.m b/matlab/simulated_moments_estimation.m index 314122d835..0946e3117a 100644 --- a/matlab/simulated_moments_estimation.m +++ b/matlab/simulated_moments_estimation.m @@ -270,9 +270,9 @@ fprintf(fid,'M_.Sigma_e = diag(tmp);') fprintf(fid,['stream=RandStream(''mt19937ar'',''Seed'',' int2str(slave_number) ');\n']); if matlab_ver_less_than('7.12') - fprintf(fid,['RandStream.setDefaultStream(stream);\n\n']); + fprintf(fid,['RandStream.setDefaultStream(stream);\n\n']); else - fprintf(fid,['RandStream.setGlobalStream(stream);\n\n']); + fprintf(fid,['RandStream.setGlobalStream(stream);\n\n']); end fprintf(fid,['maxNumCompThreads(' int2str(threads_per_job) ');\n\n']); diff --git a/matlab/simult_.m b/matlab/simult_.m index 31daa3a6cc..6113cbb370 100644 --- a/matlab/simult_.m +++ b/matlab/simult_.m @@ -134,7 +134,7 @@ else y_(dr.order_var,i) = constant + dr.ghx*yhat + dr.ghu*epsilon ... + abcOut1 + abcOut2 + abcOut3; end - end + end case 3 % only with pruning % the third moments of the shocks are assumed null. We don't have diff --git a/matlab/simultxdet.m b/matlab/simultxdet.m index 032f20588c..96b1f4c442 100644 --- a/matlab/simultxdet.m +++ b/matlab/simultxdet.m @@ -153,7 +153,7 @@ end int_width = zeros(iter,nvar); for i=1:nvar int_width(:,i) = fact*sqrt(var_yf(:,i)); - if nargout==3 + if nargout==3 int_width_ME(:,i) = -fact*sqrt(var_yf_ME(:,i)); - end + end end diff --git a/matlab/slice_sampler.m b/matlab/slice_sampler.m index e454d59365..1505a5f282 100644 --- a/matlab/slice_sampler.m +++ b/matlab/slice_sampler.m @@ -1,123 +1,123 @@ -function [theta, fxsim, neval] = slice_sampler(objective_function,theta,thetaprior,sampler_options,varargin) -% function [theta, fxsim, neval] = slice_sampler(objective_function,theta,thetaprior,sampler_options,varargin) -% ---------------------------------------------------------- -% UNIVARIATE SLICE SAMPLER - stepping out (Neal, 2003) -% W: optimal value in the range (3,10)*std(x) -% - see C.Planas and A.Rossi (2014) -% objective_function(theta,varargin): -log of any unnormalized pdf -% with varargin (optional) a vector of auxiliaty parameters -% to be passed to f( ). -% ---------------------------------------------------------- -% -% INPUTS -% objective_function: objective function (expressed as minus the log of a density) -% theta: last value of theta -% thetaprior: bounds of the theta space -% sampler_options: posterior sampler options -% varargin: optional input arguments to objective function -% -% OUTPUTS -% theta: new theta sample -% fxsim: value of the objective function for the new sample -% neval: number of function evaluations -% -% SPECIAL REQUIREMENTS -% none - -% Copyright (C) 2015 Dynare Team -% -% This file is part of Dynare. -% -% Dynare is free software: you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation, either version 3 of the License, or -% (at your option) any later version. -% -% Dynare is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. -% -% You should have received a copy of the GNU General Public License -% along with Dynare. If not, see <http://www.gnu.org/licenses/>. - -if sampler_options.rotated %&& ~isempty(sampler_options.V1), - [theta, fxsim, neval] = rotated_slice_sampler(objective_function,theta,thetaprior,sampler_options,varargin{:}); - if isempty(sampler_options.mode), % jumping - return, - else - nevalR=sum(neval); - end -end - -theta=theta(:); -npar = length(theta); -W1 = sampler_options.W1; -neval = zeros(npar,1); - -for it=1:npar, - neval(it) = 0; - W = W1(it); - xold = theta(it); - % XLB = thetaprior(3); - % XUB = thetaprior(4); - XLB = thetaprior(it,1); - XUB = thetaprior(it,2); - - - % ------------------------------------------------------- - % 1. DRAW Z = ln[f(X0)] - EXP(1) where EXP(1)=-ln(U(0,1)) - % THIS DEFINES THE SLICE S={x: z < ln(f(x))} - % ------------------------------------------------------- - fxold = -feval(objective_function,theta,varargin{:}); - neval(it) = neval(it) + 1; - Z = fxold + log(rand(1,1)); - % ------------------------------------------------------------- - % 2. FIND I=(L,R) AROUND X0 THAT CONTAINS S AS MUCH AS POSSIBLE - % STEPPING-OUT PROCEDURE - % ------------------------------------------------------------- - u = rand(1,1); - L = max(XLB,xold-W*u); - R = min(XUB,L+W); - while(L > XLB) - xsim = L; - theta(it) = xsim; - fxl = -feval(objective_function,theta,varargin{:}); - neval(it) = neval(it) + 1; - if (fxl <= Z) - break; - end - L = max(XLB,L-W); - end - while(R < XUB) - xsim = R; - theta(it) = xsim; - fxr = -feval(objective_function,theta,varargin{:}); - neval(it) = neval(it) + 1; - if (fxr <= Z) - break; - end - R = min(XUB,R+W); - end - % ------------------------------------------------------ - % 3. SAMPLING FROM THE SET A = (I INTERSECT S) = (LA,RA) - % ------------------------------------------------------ - fxsim = Z-1; - while (fxsim < Z) - u = rand(1,1); - xsim = L + u*(R - L); - theta(it) = xsim; - fxsim = -feval(objective_function,theta,varargin{:}); - neval(it) = neval(it) + 1; - if (xsim > xold) - R = xsim; - else - L = xsim; - end - end - -end - -if sampler_options.rotated && ~isempty(sampler_options.mode), % jumping - neval=sum(neval)+nevalR; -end +function [theta, fxsim, neval] = slice_sampler(objective_function,theta,thetaprior,sampler_options,varargin) +% function [theta, fxsim, neval] = slice_sampler(objective_function,theta,thetaprior,sampler_options,varargin) +% ---------------------------------------------------------- +% UNIVARIATE SLICE SAMPLER - stepping out (Neal, 2003) +% W: optimal value in the range (3,10)*std(x) +% - see C.Planas and A.Rossi (2014) +% objective_function(theta,varargin): -log of any unnormalized pdf +% with varargin (optional) a vector of auxiliaty parameters +% to be passed to f( ). +% ---------------------------------------------------------- +% +% INPUTS +% objective_function: objective function (expressed as minus the log of a density) +% theta: last value of theta +% thetaprior: bounds of the theta space +% sampler_options: posterior sampler options +% varargin: optional input arguments to objective function +% +% OUTPUTS +% theta: new theta sample +% fxsim: value of the objective function for the new sample +% neval: number of function evaluations +% +% SPECIAL REQUIREMENTS +% none + +% Copyright (C) 2015 Dynare Team +% +% This file is part of Dynare. +% +% Dynare is free software: you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation, either version 3 of the License, or +% (at your option) any later version. +% +% Dynare is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with Dynare. If not, see <http://www.gnu.org/licenses/>. + +if sampler_options.rotated %&& ~isempty(sampler_options.V1), + [theta, fxsim, neval] = rotated_slice_sampler(objective_function,theta,thetaprior,sampler_options,varargin{:}); + if isempty(sampler_options.mode), % jumping + return, + else + nevalR=sum(neval); + end +end + +theta=theta(:); +npar = length(theta); +W1 = sampler_options.W1; +neval = zeros(npar,1); + +for it=1:npar, + neval(it) = 0; + W = W1(it); + xold = theta(it); + % XLB = thetaprior(3); + % XUB = thetaprior(4); + XLB = thetaprior(it,1); + XUB = thetaprior(it,2); + + + % ------------------------------------------------------- + % 1. DRAW Z = ln[f(X0)] - EXP(1) where EXP(1)=-ln(U(0,1)) + % THIS DEFINES THE SLICE S={x: z < ln(f(x))} + % ------------------------------------------------------- + fxold = -feval(objective_function,theta,varargin{:}); + neval(it) = neval(it) + 1; + Z = fxold + log(rand(1,1)); + % ------------------------------------------------------------- + % 2. FIND I=(L,R) AROUND X0 THAT CONTAINS S AS MUCH AS POSSIBLE + % STEPPING-OUT PROCEDURE + % ------------------------------------------------------------- + u = rand(1,1); + L = max(XLB,xold-W*u); + R = min(XUB,L+W); + while(L > XLB) + xsim = L; + theta(it) = xsim; + fxl = -feval(objective_function,theta,varargin{:}); + neval(it) = neval(it) + 1; + if (fxl <= Z) + break; + end + L = max(XLB,L-W); + end + while(R < XUB) + xsim = R; + theta(it) = xsim; + fxr = -feval(objective_function,theta,varargin{:}); + neval(it) = neval(it) + 1; + if (fxr <= Z) + break; + end + R = min(XUB,R+W); + end + % ------------------------------------------------------ + % 3. SAMPLING FROM THE SET A = (I INTERSECT S) = (LA,RA) + % ------------------------------------------------------ + fxsim = Z-1; + while (fxsim < Z) + u = rand(1,1); + xsim = L + u*(R - L); + theta(it) = xsim; + fxsim = -feval(objective_function,theta,varargin{:}); + neval(it) = neval(it) + 1; + if (xsim > xold) + R = xsim; + else + L = xsim; + end + end + +end + +if sampler_options.rotated && ~isempty(sampler_options.mode), % jumping + neval=sum(neval)+nevalR; +end diff --git a/matlab/solve_perfect_foresight_model.m b/matlab/solve_perfect_foresight_model.m index 5de112ad8a..89d39fac65 100644 --- a/matlab/solve_perfect_foresight_model.m +++ b/matlab/solve_perfect_foresight_model.m @@ -17,107 +17,107 @@ function [flag,endo_simul,err] = solve_perfect_foresight_model(endo_simul,exo_si % You should have received a copy of the GNU General Public License % along with Dynare. If not, see <http://www.gnu.org/licenses/>. - flag = 0; - err = 0; - stop = 0; - nan_flag = 0; +flag = 0; +err = 0; +stop = 0; +nan_flag = 0; - model_dynamic = pfm.dynamic_model; +model_dynamic = pfm.dynamic_model; - Y = endo_simul(:); +Y = endo_simul(:); - if pfm.verbose - disp (['-----------------------------------------------------']) ; - disp (['MODEL SIMULATION :']) ; - fprintf('\n') ; - end +if pfm.verbose + disp (['-----------------------------------------------------']) ; + disp (['MODEL SIMULATION :']) ; + fprintf('\n') ; +end - if pfm.use_bytecode - [flag, endo_simul]=bytecode(Y, exo_simul, pfm.params); - return; - end +if pfm.use_bytecode + [flag, endo_simul]=bytecode(Y, exo_simul, pfm.params); + return; +end - z = Y(find(pfm.lead_lag_incidence')); - [d1,jacobian] = model_dynamic(z,exo_simul,pfm.params,pfm.steady_state,2); +z = Y(find(pfm.lead_lag_incidence')); +[d1,jacobian] = model_dynamic(z,exo_simul,pfm.params,pfm.steady_state,2); - % Initialization of the jacobian of the stacked model. - A = sparse([],[],[],pfm.periods*pfm.ny,pfm.periods*pfm.ny,pfm.periods*nnz(jacobian)); +% Initialization of the jacobian of the stacked model. +A = sparse([],[],[],pfm.periods*pfm.ny,pfm.periods*pfm.ny,pfm.periods*nnz(jacobian)); - % Initialization of the Newton residuals. - res = zeros(pfm.periods*pfm.ny,1); +% Initialization of the Newton residuals. +res = zeros(pfm.periods*pfm.ny,1); - h1 = clock; - - % Newton loop. - for iter = 1:pfm.maxit_ - h2 = clock; - i_rows = 1:pfm.ny; - i_cols = find(pfm.lead_lag_incidence'); - i_cols_A = i_cols; - % Fill the jacobian of the stacked model. - for it = 2:(pfm.periods+1) - [d1,jacobian] = model_dynamic(Y(i_cols),exo_simul,pfm.params,pfm.steady_state,it); - if it == 2 - A(i_rows,pfm.i_cols_A1) = jacobian(:,pfm.i_cols_1); - elseif it == pfm.periods+1 - A(i_rows,i_cols_A(pfm.i_cols_T)) = jacobian(:,pfm.i_cols_T); - else - A(i_rows,i_cols_A) = jacobian(:,pfm.i_cols_j); - end - res(i_rows) = d1; - i_rows = i_rows + pfm.ny; - i_cols = i_cols + pfm.ny; - if it > 2 - i_cols_A = i_cols_A + pfm.ny; - end - end - % Stop if Newton residuals are zero. - err = max(abs(res)); - if err < pfm.tolerance - stop = 1 ; - if pfm.verbose - fprintf('\n') ; - disp([' Total time of simulation :' num2str(etime(clock,h1))]) ; - fprintf('\n') ; - disp([' Convergency obtained.']) ; - fprintf('\n') ; - end - flag = 0;% Convergency obtained. - endo_simul = reshape(Y,pfm.ny,pfm.periods+2); - break +h1 = clock; + +% Newton loop. +for iter = 1:pfm.maxit_ + h2 = clock; + i_rows = 1:pfm.ny; + i_cols = find(pfm.lead_lag_incidence'); + i_cols_A = i_cols; + % Fill the jacobian of the stacked model. + for it = 2:(pfm.periods+1) + [d1,jacobian] = model_dynamic(Y(i_cols),exo_simul,pfm.params,pfm.steady_state,it); + if it == 2 + A(i_rows,pfm.i_cols_A1) = jacobian(:,pfm.i_cols_1); + elseif it == pfm.periods+1 + A(i_rows,i_cols_A(pfm.i_cols_T)) = jacobian(:,pfm.i_cols_T); + else + A(i_rows,i_cols_A) = jacobian(:,pfm.i_cols_j); end - % Compute the Newton step. - dy = -A\res; - if any(isnan(dy)) - nan_flag = 1; - break + res(i_rows) = d1; + i_rows = i_rows + pfm.ny; + i_cols = i_cols + pfm.ny; + if it > 2 + i_cols_A = i_cols_A + pfm.ny; end - % Update the endogenous variables paths. - Y(pfm.i_upd) = Y(pfm.i_upd) + dy; end - - if ~stop + % Stop if Newton residuals are zero. + err = max(abs(res)); + if err < pfm.tolerance + stop = 1 ; if pfm.verbose fprintf('\n') ; - disp([' Total time of simulation :' num2str(etime(clock,h1))]) ; + disp([' Total time of simulation :' num2str(etime(clock,h1))]) ; fprintf('\n') ; - disp(['WARNING : maximum number of iterations is reached (modify options_.simul.maxit).']) ; + disp([' Convergency obtained.']) ; fprintf('\n') ; end - flag = 1;% more iterations are needed. - endo_simul = 1; + flag = 0;% Convergency obtained. + endo_simul = reshape(Y,pfm.ny,pfm.periods+2); + break end - if nan_flag - if pfm.verbose - fprintf('\n') ; - disp([' Total time of simulation :' num2str(etime(clock,h1))]) ; - fprintf('\n') ; - disp(['WARNING : NaNs!']) ; - fprintf('\n') ; - end - flag = 1; - endo_simul = 1; + % Compute the Newton step. + dy = -A\res; + if any(isnan(dy)) + nan_flag = 1; + break end + % Update the endogenous variables paths. + Y(pfm.i_upd) = Y(pfm.i_upd) + dy; +end + +if ~stop if pfm.verbose - disp (['-----------------------------------------------------']) ; - end \ No newline at end of file + fprintf('\n') ; + disp([' Total time of simulation :' num2str(etime(clock,h1))]) ; + fprintf('\n') ; + disp(['WARNING : maximum number of iterations is reached (modify options_.simul.maxit).']) ; + fprintf('\n') ; + end + flag = 1;% more iterations are needed. + endo_simul = 1; +end +if nan_flag + if pfm.verbose + fprintf('\n') ; + disp([' Total time of simulation :' num2str(etime(clock,h1))]) ; + fprintf('\n') ; + disp(['WARNING : NaNs!']) ; + fprintf('\n') ; + end + flag = 1; + endo_simul = 1; +end +if pfm.verbose + disp (['-----------------------------------------------------']) ; +end \ No newline at end of file diff --git a/matlab/steady.m b/matlab/steady.m index 760fb1d3f5..5f11f73c83 100644 --- a/matlab/steady.m +++ b/matlab/steady.m @@ -77,7 +77,7 @@ if info(1) error('Homotopy step failed') end end - + [steady_state,M_.params,info] = steady_(M_,options_,oo_); oo_.steady_state = steady_state; diff --git a/matlab/step_length_correction.m b/matlab/step_length_correction.m index 8950bc7649..5af7dcaee8 100644 --- a/matlab/step_length_correction.m +++ b/matlab/step_length_correction.m @@ -17,8 +17,8 @@ function c = step_length_correction(x,scale,i) % You should have received a copy of the GNU General Public License % along with Dynare. If not, see <http://www.gnu.org/licenses/>. - if isempty(scale) - c = 10^round(log10(abs(x))); - else - c = scale(i); - end +if isempty(scale) + c = 10^round(log10(abs(x))); +else + c = scale(i); +end diff --git a/matlab/stoch_simul.m b/matlab/stoch_simul.m index d187a45a53..5e7decfff7 100644 --- a/matlab/stoch_simul.m +++ b/matlab/stoch_simul.m @@ -159,7 +159,7 @@ if options_.periods > 0 && ~PI_PCL_solver [ys, oo_] = simult(y0,oo_.dr,M_,options_,oo_); oo_.endo_simul = ys; if ~options_.minimal_workspace - dyn2vec; + dyn2vec; end end diff --git a/matlab/stochastic_solvers.m b/matlab/stochastic_solvers.m index 7332654a8d..1da71109dd 100644 --- a/matlab/stochastic_solvers.m +++ b/matlab/stochastic_solvers.m @@ -59,16 +59,16 @@ if M_.hessian_eq_zero && local_order~=1 end if (options_.aim_solver == 1) && (local_order > 1) - error('Option "aim_solver" is incompatible with order >= 2') + error('Option "aim_solver" is incompatible with order >= 2') end if M_.maximum_endo_lag == 0 if local_order >= 2 - fprintf('\nSTOCHASTIC_SOLVER: Dynare does not solve purely forward models at higher order.\n') - fprintf('STOCHASTIC_SOLVER: To circumvent this restriction, you can add a backward-looking dummy equation of the form:\n') - fprintf('STOCHASTIC_SOLVER: junk=0.9*junk(-1);\n') - error(['2nd and 3rd order approximation not implemented for purely ' ... - 'forward models']) + fprintf('\nSTOCHASTIC_SOLVER: Dynare does not solve purely forward models at higher order.\n') + fprintf('STOCHASTIC_SOLVER: To circumvent this restriction, you can add a backward-looking dummy equation of the form:\n') + fprintf('STOCHASTIC_SOLVER: junk=0.9*junk(-1);\n') + error(['2nd and 3rd order approximation not implemented for purely ' ... + 'forward models']) end if M_.exo_det_nbr~=0 fprintf('\nSTOCHASTIC_SOLVER: Dynare does not solve purely forward models with var_exo_det.\n') @@ -88,7 +88,7 @@ end if options_.k_order_solver; if options_.risky_steadystate [dr,info] = dyn_risky_steadystate_solver(oo_.steady_state,M_,dr, ... - options_,oo_); + options_,oo_); else orig_order = options_.order; options_.order = local_order; @@ -119,12 +119,12 @@ if local_order == 1 jacobia_ = [loc_dr.g1 loc_dr.g1_x loc_dr.g1_xd]; else [junk,jacobia_] = feval([M_.fname '_dynamic'],z(iyr0),exo_simul, ... - M_.params, dr.ys, it_); + M_.params, dr.ys, it_); end; elseif local_order == 2 if (options_.bytecode) [chck, junk, loc_dr] = bytecode('dynamic','evaluate', z,exo_simul, ... - M_.params, dr.ys, 1); + M_.params, dr.ys, 1); jacobia_ = [loc_dr.g1 loc_dr.g1_x]; else [junk,jacobia_,hessian1] = feval([M_.fname '_dynamic'],z(iyr0),... @@ -139,9 +139,9 @@ elseif local_order == 2 [infrow,infcol]=find(isinf(hessian1)); if options_.debug if ~isempty(infrow) - fprintf('\nSTOCHASTIC_SOLVER: The Hessian of the dynamic model contains Inf.\n') - fprintf('STOCHASTIC_SOLVER: Try running model_diagnostics to find the source of the problem.\n') - save([M_.fname '_debug.mat'],'hessian1') + fprintf('\nSTOCHASTIC_SOLVER: The Hessian of the dynamic model contains Inf.\n') + fprintf('STOCHASTIC_SOLVER: Try running model_diagnostics to find the source of the problem.\n') + save([M_.fname '_debug.mat'],'hessian1') end end if ~isempty(infrow) @@ -163,12 +163,12 @@ elseif local_order == 2 end [infrow,infcol]=find(isinf(jacobia_)); - + if options_.debug if ~isempty(infrow) - fprintf('\nSTOCHASTIC_SOLVER: The Jacobian of the dynamic model contains Inf. The problem is associated with:\n\n') - display_problematic_vars_Jacobian(infrow,infcol,M_,dr.ys,'dynamic','STOCHASTIC_SOLVER: ') - save([M_.fname '_debug.mat'],'jacobia_') + fprintf('\nSTOCHASTIC_SOLVER: The Jacobian of the dynamic model contains Inf. The problem is associated with:\n\n') + display_problematic_vars_Jacobian(infrow,infcol,M_,dr.ys,'dynamic','STOCHASTIC_SOLVER: ') + save([M_.fname '_debug.mat'],'jacobia_') end end @@ -195,17 +195,17 @@ end [nanrow,nancol]=find(isnan(jacobia_)); if options_.debug if ~isempty(nanrow) - fprintf('\nSTOCHASTIC_SOLVER: The Jacobian of the dynamic model contains NaN. The problem is associated with:\n\n') - display_problematic_vars_Jacobian(nanrow,nancol,M_,dr.ys,'dynamic','STOCHASTIC_SOLVER: ') - save([M_.fname '_debug.mat'],'jacobia_') + fprintf('\nSTOCHASTIC_SOLVER: The Jacobian of the dynamic model contains NaN. The problem is associated with:\n\n') + display_problematic_vars_Jacobian(nanrow,nancol,M_,dr.ys,'dynamic','STOCHASTIC_SOLVER: ') + save([M_.fname '_debug.mat'],'jacobia_') end end if ~isempty(nanrow) - info(1) = 8; - NaN_params=find(isnan(M_.params)); - info(2:length(NaN_params)+1) = NaN_params; - return + info(1) = 8; + NaN_params=find(isnan(M_.params)); + info(2:length(NaN_params)+1) = NaN_params; + return end kstate = dr.kstate; @@ -272,7 +272,7 @@ else dr = dyn_second_order_solver(jacobia_,hessian1,dr,M_,... options_.threads.kronecker.A_times_B_kronecker_C,... options_.threads.kronecker.sparse_hessian_times_B_kronecker_C); - + % reordering second order derivatives, used for deterministic % variables below k1 = nonzeros(M_.lead_lag_incidence(:,order_var)'); @@ -306,7 +306,7 @@ if M_.exo_det_nbr > 0 hu = dr.ghu(nstatic+[1:nspred],:); hud = dr.ghud{1}(nstatic+1:nstatic+nspred,:); zx = [eye(nspred);dr.ghx(k0,:);gx*dr.Gy;zeros(M_.exo_nbr+M_.exo_det_nbr, ... - nspred)]; + nspred)]; zu = [zeros(nspred,M_.exo_nbr); dr.ghu(k0,:); gx*hu; zeros(M_.exo_nbr+M_.exo_det_nbr, ... M_.exo_nbr)]; zud=[zeros(nspred,M_.exo_det_nbr);dr.ghud{1};gx(:,1:nspred)*hud;zeros(M_.exo_nbr,M_.exo_det_nbr);eye(M_.exo_det_nbr)]; @@ -377,7 +377,7 @@ if options_.loglinear length(il),1); end if local_order > 1 - error('Loglinear options currently only works at order 1') + error('Loglinear options currently only works at order 1') end end end diff --git a/matlab/store_smoother_results.m b/matlab/store_smoother_results.m index 98882dde37..d8fcbbd069 100644 --- a/matlab/store_smoother_results.m +++ b/matlab/store_smoother_results.m @@ -167,7 +167,7 @@ for i_endo_in_bayestopt_smoother_varlist=bayestopt_.smoother_saved_var_list' end oo_.UpdatedVariables.(deblank(M_.endo_names(i_endo_declaration_order,:)))=updated_variables(i_endo_in_dr,:)'+constant_current_variable; end - + %% Add trend and constant for observed variables for pos_iter=1:length(bayestopt_.mf) oo_.Smoother.Constant.(deblank(M_.endo_names(bayestopt_.mfys(pos_iter),:)))=constant_part(pos_iter,:)'; @@ -229,8 +229,8 @@ end %% Smoothed measurement errors if ~isequal(M_.H,0) -% measurement_error_indices=find(diag(M_.H)~=0); + % measurement_error_indices=find(diag(M_.H)~=0); for meas_error_iter=1:length(options_.varobs) - oo_.SmoothedMeasurementErrors.(options_.varobs{meas_error_iter})= measurement_error(meas_error_iter,:)'; + oo_.SmoothedMeasurementErrors.(options_.varobs{meas_error_iter})= measurement_error(meas_error_iter,:)'; end end diff --git a/matlab/subset.m b/matlab/subset.m index dedbdbfba2..95ad236457 100644 --- a/matlab/subset.m +++ b/matlab/subset.m @@ -54,8 +54,8 @@ else for i = 1:length(ExcludedParamNames) tmp = strmatch(ExcludedParamNames{i},M_.exo_names); if ~isempty(tmp) && ( strcmpi(info,'All') || strcmpi(info,'StructuralShocks') || ... - strcmpi(info,'StructuralShocksWithoutCorrelations') || ... - strcmpi(info,'AllWithoutMeasurementErrors') ) + strcmpi(info,'StructuralShocksWithoutCorrelations') || ... + strcmpi(info,'AllWithoutMeasurementErrors') ) % The parameter the user wants to exclude is related to the size of the structural innovations. if ncx disp(['I cannot exclude some of the structural variances if the']) @@ -66,7 +66,7 @@ else elseif isempty(tmp) && nvn tmp = strmatch(ExcludedParamNames{i},options_.varobs); if ~isempty(tmp) && ( strcmpi(info,'All') || strcmpi(info,'MeasurementErrors') || ... - strcmpi(info,'MeasurementErrorsWithoutCorrelations') ) + strcmpi(info,'MeasurementErrorsWithoutCorrelations') ) % The parameter the user wants to exclude is related to the size of the measurement errors variances. tmp = nvx+tmp; if ncn diff --git a/matlab/th_autocovariances.m b/matlab/th_autocovariances.m index 966ece8341..0f08c18cec 100644 --- a/matlab/th_autocovariances.m +++ b/matlab/th_autocovariances.m @@ -237,7 +237,7 @@ else% ==> Theoretical filters. f_hp = zeros(length(ivar),length(ivar)); else f_omega =(1/(2*pi))*([(IA-A*tneg(ig))\ghu1;IE]... - *M_.Sigma_e*[ghu1'/(IA-A'*tpos(ig)) IE]); % spectral density of state variables; top formula Uhlig (2001), p. 20 with N=0 + *M_.Sigma_e*[ghu1'/(IA-A'*tpos(ig)) IE]); % spectral density of state variables; top formula Uhlig (2001), p. 20 with N=0 g_omega = [aa*tneg(ig) bb]*f_omega*[aa'*tpos(ig); bb']; % spectral density of selected variables; middle formula Uhlig (2001), p. 20; only middle block, i.e. y_t' f_hp = filter_gain(ig)^2*g_omega; % spectral density of selected filtered series; top formula Uhlig (2001), p. 21; end diff --git a/matlab/thet2tau.m b/matlab/thet2tau.m index 929193ca44..54673e5420 100644 --- a/matlab/thet2tau.m +++ b/matlab/thet2tau.m @@ -51,7 +51,7 @@ elseif flagmoments==-1 [I,J]=find(M_.lead_lag_incidence'); yy0=oo_.dr.ys(I); [residual, g1] = feval([M_.fname,'_dynamic'],yy0, oo_.exo_steady_state', ... - M_.params, oo_.dr.ys, 1); + M_.params, oo_.dr.ys, 1); tau=[oo_.dr.ys(oo_.dr.order_var); g1(:)]; else diff --git a/matlab/user_has_matlab_license.m b/matlab/user_has_matlab_license.m index 86b8c94bd6..51d7cf0b67 100644 --- a/matlab/user_has_matlab_license.m +++ b/matlab/user_has_matlab_license.m @@ -38,14 +38,14 @@ if ~hasLicense end switch toolbox %use function unique to toolbox - case 'statistics_toolbox' - n = 'gppdf'; - case 'optimization_toolbox' - n='fsolve'; - case 'GADS_Toolbox' - n='simulannealbnd'; - case 'control_toolbox' - n='dlyap'; + case 'statistics_toolbox' + n = 'gppdf'; + case 'optimization_toolbox' + n='fsolve'; + case 'GADS_Toolbox' + n='simulannealbnd'; + case 'control_toolbox' + n='dlyap'; end hasInstallation=check_toolbox_installation(n); if ~hasInstallation diff --git a/matlab/utilities/dataset/initialize_dataset.m b/matlab/utilities/dataset/initialize_dataset.m index 5d992a2889..0b00df4dcf 100644 --- a/matlab/utilities/dataset/initialize_dataset.m +++ b/matlab/utilities/dataset/initialize_dataset.m @@ -55,7 +55,7 @@ if dataset_.info.nvobs-size(rawdata,2) end if size(rawdata,1)~=dataset_.info.ntobs - fprintf('Restricting the sample to observations %d to %d. Using in total %d observations. \n',first,first+dataset_.info.ntobs-1,dataset_.info.ntobs) + fprintf('Restricting the sample to observations %d to %d. Using in total %d observations. \n',first,first+dataset_.info.ntobs-1,dataset_.info.ntobs) end rawdata = rawdata(first:(first+dataset_.info.ntobs-1),:); diff --git a/matlab/utilities/dataset/lagged.m b/matlab/utilities/dataset/lagged.m index 31a58909ac..87a7c64a44 100644 --- a/matlab/utilities/dataset/lagged.m +++ b/matlab/utilities/dataset/lagged.m @@ -1,32 +1,32 @@ -function xlag = lagged(x, n); -% xlag = lagged(x, n); -% applies n-lags backward shift operator to x -% -% INPUTS -% x = time series -% n = number of backward shifts [DEFAULT=1] -% -% OUTPUT -% xlag = backward shifted series - -% Copyright (C) 2017 Dynare Team -% -% This file is part of Dynare. -% -% Dynare is free software: you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation, either version 3 of the License, or -% (at your option) any later version. -% -% Dynare is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. -% -% You should have received a copy of the GNU General Public License -% along with Dynare. If not, see <http://www.gnu.org/licenses/>. - -if nargin==1, n=1; end - -x=x(:); -xlag=[NaN(n,1); x(1:end-n)]; +function xlag = lagged(x, n); +% xlag = lagged(x, n); +% applies n-lags backward shift operator to x +% +% INPUTS +% x = time series +% n = number of backward shifts [DEFAULT=1] +% +% OUTPUT +% xlag = backward shifted series + +% Copyright (C) 2017 Dynare Team +% +% This file is part of Dynare. +% +% Dynare is free software: you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation, either version 3 of the License, or +% (at your option) any later version. +% +% Dynare is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with Dynare. If not, see <http://www.gnu.org/licenses/>. + +if nargin==1, n=1; end + +x=x(:); +xlag=[NaN(n,1); x(1:end-n)]; diff --git a/matlab/utilities/dataset/makedataset.m b/matlab/utilities/dataset/makedataset.m index 6ac4035c83..e46f7aa76d 100644 --- a/matlab/utilities/dataset/makedataset.m +++ b/matlab/utilities/dataset/makedataset.m @@ -37,7 +37,7 @@ if isempty(DynareOptions.datafile) && isempty(DynareOptions.dataset.file) && ise if gsa_flag DynareDataset = dseries(); DatasetInfo = struct('missing', struct('state', 0, 'aindex', [], 'vindex', [], 'number_of_observations', NaN, 'no_more_missing_observations', NaN), ... - 'descriptive', struct('mean', [], 'covariance', [], 'correlation', [], 'autocovariance', [])); + 'descriptive', struct('mean', [], 'covariance', [], 'correlation', [], 'autocovariance', [])); newdatainterface=0; return else diff --git a/matlab/utilities/dataset/quarterly2annual.m b/matlab/utilities/dataset/quarterly2annual.m index cc655f1e0d..4a01941bda 100644 --- a/matlab/utilities/dataset/quarterly2annual.m +++ b/matlab/utilities/dataset/quarterly2annual.m @@ -1,144 +1,144 @@ -function [ya, yass, gya, gyass] = quarterly2annual(y,yss,GYTREND0,type,islog,aux) -% function [ya, yass, gya, gyass] = quarterly2annual(y,yss,GYTREND0,type,islog,aux) -% transforms quarterly (log-)level time series to annual level and growth rate -% it accounts for stock/flow/deflator series. -% -% INPUTS -% y quarterly time series -% yss steady state of y -% GYTREND0 growth rate of y -% type 1 sum (default) -% 2 average -% 3 last period (Q4) -% 4 geometric average -% 5 annual price as quantity weighted average -% 6 annual quantity from average price -% 7 annual nominal from Q real and deflator -% islog 0 level (default) -% 1 log-level -% 2 growth rate Q frequency -% aux optional input used when type>4 -% -% -% OUTPUTS -% ya annual (log-)level -% yass annual steadystate (log-)level -% gya annual growth rate -% gyass annual growth rate steadystate - -% Copyright (C) 2017 Dynare Team -% -% This file is part of Dynare. -% -% Dynare is free software: you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation, either version 3 of the License, or -% (at your option) any later version. -% -% Dynare is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. -% -% You should have received a copy of the GNU General Public License -% along with Dynare. If not, see <http://www.gnu.org/licenses/>. - -if nargin ==0, - disp('[ya, yass, gya, gyass] = quarterly2annual(y,yss,GYTREND0,type,islog);') - return -end - -if nargin<4 || isempty(type), - type=1; -end -if nargin<5 || isempty(islog), - islog=0; -end -if isstruct(aux), - yaux=aux.y; - yauxss=aux.yss; - islogaux=aux.islog; - GYTREND0aux=aux.GYTREND0; - typeaux=aux.type; - if islogaux - yaux=exp(yaux+yauxss); - yauxss=exp(yauxss); - yaux=yaux-yauxss; - end -elseif type > 4, - error('TYPE>4 requires auxiliary variable!') -end -if islog == 2, - % construct loglevel out of growth rate - y = cumsum(y); - yss=0; - islog=1; -end -if islog == 1 - y=exp(y+yss); - yss=exp(yss); - y=y-yss; -end -switch type - - case 1 - yass = yss*(exp(-GYTREND0*3)+exp(-GYTREND0*2)+exp(-GYTREND0)+1); - tmp = lagged(y,3)*exp(-GYTREND0*3)+lagged(y,2)*exp(-GYTREND0*2)+lagged(y,1)*exp(-GYTREND0)+y; % annualized level - ya = tmp(4:4:end); - - case 2 - yass = yss*(exp(-GYTREND0*3)+exp(-GYTREND0*2)+exp(-GYTREND0)+1)/4; - tmp = (lagged(y,3)*exp(-GYTREND0*3)+lagged(y,2)*exp(-GYTREND0*2)+lagged(y,1)*exp(-GYTREND0)+y)/4; % annualized level - ya = tmp(4:4:end); - - case 3 - yass=yss; - tmp = y; - ya = tmp(4:4:end); - - case 4 - yass = yss*(exp(-GYTREND0*3/2)); - tmp = (lagged(y+yss,3)*exp(-GYTREND0*3).*lagged(y+yss,2)*exp(-GYTREND0*2).*lagged(y+yss,1)*exp(-GYTREND0).*(y+yss)).^(1/4); % annualized level - tmp = tmp - yass; - ya = tmp(4:4:end); - - case 5 - % nominal series - yn = (y+yss).*(yaux+yauxss) - yss.*yauxss; - [yna, ynass] = quarterly2annual(yn,yss.*yauxss,GYTREND0+GYTREND0aux,typeaux,0,0); - % real series - [yra, yrass] = quarterly2annual(yaux,yauxss,GYTREND0aux,typeaux,0,0); - % deflator - yass = ynass/yrass; - ya = (yna+ynass)./(yr+yrass)-yass; - - case 6 - % nominal series - yn = (y+yss).*(yaux+yauxss) - yss.*yauxss; - [yna, ynass] = quarterly2annual(yn,yss.*yauxss,GYTREND0+GYTREND0aux,typeaux,0,0); - % deflator - [pa, pass] = quarterly2annual(yaux,yauxss,GYTREND0aux,2,0,0); - % real series - yass = ynass/pass; - ya = (yna+ynass)./(pa+pass)-yass; - - case 7 - % nominal series - yn = (y+yss).*(yaux+yauxss) - yss.*yauxss; - [ya, yass] = quarterly2annual(yn,yss.*yauxss,GYTREND0+GYTREND0aux,typeaux,0,0); - GYTREND0=GYTREND0+GYTREND0aux; - - otherwise - error('Wrong type input') -end - -% annual growth rate -gyass = GYTREND0*4; -gya = (ya+yass)./(lagged(ya,1)+yass).*exp(4*GYTREND0)-1-gyass; - -if islog - ya=log(ya+yass); - yass=log(yass); - ya=ya-yass; -end - +function [ya, yass, gya, gyass] = quarterly2annual(y,yss,GYTREND0,type,islog,aux) +% function [ya, yass, gya, gyass] = quarterly2annual(y,yss,GYTREND0,type,islog,aux) +% transforms quarterly (log-)level time series to annual level and growth rate +% it accounts for stock/flow/deflator series. +% +% INPUTS +% y quarterly time series +% yss steady state of y +% GYTREND0 growth rate of y +% type 1 sum (default) +% 2 average +% 3 last period (Q4) +% 4 geometric average +% 5 annual price as quantity weighted average +% 6 annual quantity from average price +% 7 annual nominal from Q real and deflator +% islog 0 level (default) +% 1 log-level +% 2 growth rate Q frequency +% aux optional input used when type>4 +% +% +% OUTPUTS +% ya annual (log-)level +% yass annual steadystate (log-)level +% gya annual growth rate +% gyass annual growth rate steadystate + +% Copyright (C) 2017 Dynare Team +% +% This file is part of Dynare. +% +% Dynare is free software: you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation, either version 3 of the License, or +% (at your option) any later version. +% +% Dynare is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with Dynare. If not, see <http://www.gnu.org/licenses/>. + +if nargin ==0, + disp('[ya, yass, gya, gyass] = quarterly2annual(y,yss,GYTREND0,type,islog);') + return +end + +if nargin<4 || isempty(type), + type=1; +end +if nargin<5 || isempty(islog), + islog=0; +end +if isstruct(aux), + yaux=aux.y; + yauxss=aux.yss; + islogaux=aux.islog; + GYTREND0aux=aux.GYTREND0; + typeaux=aux.type; + if islogaux + yaux=exp(yaux+yauxss); + yauxss=exp(yauxss); + yaux=yaux-yauxss; + end +elseif type > 4, + error('TYPE>4 requires auxiliary variable!') +end +if islog == 2, + % construct loglevel out of growth rate + y = cumsum(y); + yss=0; + islog=1; +end +if islog == 1 + y=exp(y+yss); + yss=exp(yss); + y=y-yss; +end +switch type + + case 1 + yass = yss*(exp(-GYTREND0*3)+exp(-GYTREND0*2)+exp(-GYTREND0)+1); + tmp = lagged(y,3)*exp(-GYTREND0*3)+lagged(y,2)*exp(-GYTREND0*2)+lagged(y,1)*exp(-GYTREND0)+y; % annualized level + ya = tmp(4:4:end); + + case 2 + yass = yss*(exp(-GYTREND0*3)+exp(-GYTREND0*2)+exp(-GYTREND0)+1)/4; + tmp = (lagged(y,3)*exp(-GYTREND0*3)+lagged(y,2)*exp(-GYTREND0*2)+lagged(y,1)*exp(-GYTREND0)+y)/4; % annualized level + ya = tmp(4:4:end); + + case 3 + yass=yss; + tmp = y; + ya = tmp(4:4:end); + + case 4 + yass = yss*(exp(-GYTREND0*3/2)); + tmp = (lagged(y+yss,3)*exp(-GYTREND0*3).*lagged(y+yss,2)*exp(-GYTREND0*2).*lagged(y+yss,1)*exp(-GYTREND0).*(y+yss)).^(1/4); % annualized level + tmp = tmp - yass; + ya = tmp(4:4:end); + + case 5 + % nominal series + yn = (y+yss).*(yaux+yauxss) - yss.*yauxss; + [yna, ynass] = quarterly2annual(yn,yss.*yauxss,GYTREND0+GYTREND0aux,typeaux,0,0); + % real series + [yra, yrass] = quarterly2annual(yaux,yauxss,GYTREND0aux,typeaux,0,0); + % deflator + yass = ynass/yrass; + ya = (yna+ynass)./(yr+yrass)-yass; + + case 6 + % nominal series + yn = (y+yss).*(yaux+yauxss) - yss.*yauxss; + [yna, ynass] = quarterly2annual(yn,yss.*yauxss,GYTREND0+GYTREND0aux,typeaux,0,0); + % deflator + [pa, pass] = quarterly2annual(yaux,yauxss,GYTREND0aux,2,0,0); + % real series + yass = ynass/pass; + ya = (yna+ynass)./(pa+pass)-yass; + + case 7 + % nominal series + yn = (y+yss).*(yaux+yauxss) - yss.*yauxss; + [ya, yass] = quarterly2annual(yn,yss.*yauxss,GYTREND0+GYTREND0aux,typeaux,0,0); + GYTREND0=GYTREND0+GYTREND0aux; + + otherwise + error('Wrong type input') +end + +% annual growth rate +gyass = GYTREND0*4; +gya = (ya+yass)./(lagged(ya,1)+yass).*exp(4*GYTREND0)-1-gyass; + +if islog + ya=log(ya+yass); + yass=log(yass); + ya=ya-yass; +end + diff --git a/matlab/utilities/doc/get_internal_doc_block.m b/matlab/utilities/doc/get_internal_doc_block.m index 718b2a28d9..77e4f6625b 100644 --- a/matlab/utilities/doc/get_internal_doc_block.m +++ b/matlab/utilities/doc/get_internal_doc_block.m @@ -1,6 +1,6 @@ function block = get_internal_doc_block(fname,fpath) % Extract doc sections from matlab's routine. - + % Copyright (C) 2011-2012 Dynare Team % % This file is part of Dynare. @@ -22,7 +22,7 @@ function block = get_internal_doc_block(fname,fpath) % Default output block = []; - + % Open the matlab file. mid = fopen([fpath '/' fname '.m'],'r'); @@ -43,11 +43,11 @@ if ( isempty(b1) && isempty(b2) && isempty(b) ) return else if ( (~isempty(b1) && isempty(b2) && isempty(b)) || ... - (isempty(b1) && ~isempty(b2) && isempty(b)) || ... - (isempty(b1) && isempty(b2) && ~isempty(b)) || ... - (isempty(b1) && ~isempty(b2) && ~isempty(b)) || ... - (~isempty(b1) && isempty(b2) && ~isempty(b)) || ... - (~isempty(b1) && ~isempty(b2) && isempty(b)) ) + (isempty(b1) && ~isempty(b2) && isempty(b)) || ... + (isempty(b1) && isempty(b2) && ~isempty(b)) || ... + (isempty(b1) && ~isempty(b2) && ~isempty(b)) || ... + (~isempty(b1) && isempty(b2) && ~isempty(b)) || ... + (~isempty(b1) && ~isempty(b2) && isempty(b)) ) error('get_internal_doc_block:: There is a problem with the internal block definition!') end if ( b2~=b(end) || b1~=b(1) || any(b-transpose(b1:1:b2)) ) diff --git a/matlab/utilities/general/clean_current_folder.m b/matlab/utilities/general/clean_current_folder.m index e3408bec15..8375c5607a 100644 --- a/matlab/utilities/general/clean_current_folder.m +++ b/matlab/utilities/general/clean_current_folder.m @@ -1,4 +1,4 @@ -function clean() +function clean_current_folder() % Copyright (C) 2014 Dynare Team % diff --git a/matlab/utilities/general/compare_vectors.m b/matlab/utilities/general/compare_vectors.m index 97e916c757..e0ec681a2c 100644 --- a/matlab/utilities/general/compare_vectors.m +++ b/matlab/utilities/general/compare_vectors.m @@ -1,5 +1,5 @@ function C = compare_vectors(f, A, B) % --*-- Unitary tests --*-- - + % Performs lexicographical comparison of vectors. % % INPUTS @@ -12,7 +12,7 @@ function C = compare_vectors(f, A, B) % --*-- Unitary tests --*-- % % REMARKS % o It is assumed that vectors A and B have the same number of elements. - + % Copyright (C) 2013 Dynare Team % % This file is part of Dynare. diff --git a/matlab/utilities/general/demean.m b/matlab/utilities/general/demean.m index 4bf53aaa62..aed9eb4b11 100644 --- a/matlab/utilities/general/demean.m +++ b/matlab/utilities/general/demean.m @@ -1,6 +1,6 @@ function c = demean(x) % Removes the mean of each column of a matrix. - + %@info: %! @deftypefn {Function File} {@var{c} =} demean (@var{x}) %! @anchor{demean} @@ -45,7 +45,7 @@ function c = demean(x) % along with Dynare. If not, see <http://www.gnu.org/licenses/>. % Original author: stephane DOT adjemian AT univ DASH lemans DOT fr - + if ndim(x)==1 c = x-mean(x); elseif ndim(x)==2 diff --git a/matlab/utilities/general/dyn_mex.m b/matlab/utilities/general/dyn_mex.m index 7892ee9bed..d4fd7336f9 100644 --- a/matlab/utilities/general/dyn_mex.m +++ b/matlab/utilities/general/dyn_mex.m @@ -14,7 +14,7 @@ function dyn_mex(win_compiler,basename,force) % none % - + % Copyright (C) 2015-2016 Dynare Team % % This file is part of Dynare. @@ -47,26 +47,26 @@ end if ~exist('OCTAVE_VERSION') % Some mex commands are enclosed in an eval(), because otherwise it will make Octave fail if ispc - if strcmp(win_compiler,'msvc') - % MATLAB/Windows + Microsoft Visual C++ - % Add /TP flag as fix for #1227 - eval(['mex -O LINKFLAGS="$LINKFLAGS /export:Dynamic" COMPFLAGS="/TP" ' basename '_dynamic.c ' basename '_dynamic_mex.c']) - eval(['mex -O LINKFLAGS="$LINKFLAGS /export:Static" COMPFLAGS="/TP" ' basename '_static.c ' basename '_static_mex.c']) - elseif strcmp(win_compiler,'mingw') - eval(['mex -O LINKFLAGS="$LINKFLAGS /export:Dynamic" ' basename '_dynamic.c ' basename '_dynamic_mex.c']) - eval(['mex -O LINKFLAGS="$LINKFLAGS /export:Static" ' basename '_static.c ' basename '_static_mex.c']) - elseif strcmp(win_compiler,'cygwin') %legacy support for Cygwin with mexopts.bat - % MATLAB/Windows + Cygwin g++ - eval(['mex -O PRELINK_CMDS1="echo EXPORTS > mex.def & echo ' ... - 'mexFunction >> mex.def & echo Dynamic >> mex.def" ' ... - basename '_dynamic.c ' basename '_dynamic_mex.c']) - eval(['mex -O PRELINK_CMDS1="echo EXPORTS > mex.def & echo ' ... - 'mexFunction >> mex.def & echo Dynamic >> mex.def" ' ... - basename '_static.c ' basename '_static_mex.c']) - else - error(['When using the USE_DLL option, you must give either ' ... - '''cygwin'', ''mingw'' or ''msvc'' option to the ''dynare'' command']) - end + if strcmp(win_compiler,'msvc') + % MATLAB/Windows + Microsoft Visual C++ + % Add /TP flag as fix for #1227 + eval(['mex -O LINKFLAGS="$LINKFLAGS /export:Dynamic" COMPFLAGS="/TP" ' basename '_dynamic.c ' basename '_dynamic_mex.c']) + eval(['mex -O LINKFLAGS="$LINKFLAGS /export:Static" COMPFLAGS="/TP" ' basename '_static.c ' basename '_static_mex.c']) + elseif strcmp(win_compiler,'mingw') + eval(['mex -O LINKFLAGS="$LINKFLAGS /export:Dynamic" ' basename '_dynamic.c ' basename '_dynamic_mex.c']) + eval(['mex -O LINKFLAGS="$LINKFLAGS /export:Static" ' basename '_static.c ' basename '_static_mex.c']) + elseif strcmp(win_compiler,'cygwin') %legacy support for Cygwin with mexopts.bat + % MATLAB/Windows + Cygwin g++ + eval(['mex -O PRELINK_CMDS1="echo EXPORTS > mex.def & echo ' ... + 'mexFunction >> mex.def & echo Dynamic >> mex.def" ' ... + basename '_dynamic.c ' basename '_dynamic_mex.c']) + eval(['mex -O PRELINK_CMDS1="echo EXPORTS > mex.def & echo ' ... + 'mexFunction >> mex.def & echo Dynamic >> mex.def" ' ... + basename '_static.c ' basename '_static_mex.c']) + else + error(['When using the USE_DLL option, you must give either ' ... + '''cygwin'', ''mingw'' or ''msvc'' option to the ''dynare'' command']) + end elseif isunix && ~ismac % MATLAB/Linux if matlab_ver_less_than('8.3') diff --git a/matlab/utilities/general/isinestimationobjective.m b/matlab/utilities/general/isinestimationobjective.m index b6bbb5faf4..023e4cb14e 100644 --- a/matlab/utilities/general/isinestimationobjective.m +++ b/matlab/utilities/general/isinestimationobjective.m @@ -25,8 +25,8 @@ tmp = struct2cell(dbstack); list_of_previously_called_routines = transpose(tmp(2,:)); if ~isempty(strmatch('dsge_likelihood', list_of_previously_called_routines, 'exact')) || ... - ~isempty(strmatch('dsge_var_likelihood', list_of_previously_called_routines, 'exact')) || ... - ~isempty(strmatch('non_linear_dsge_likelihood', list_of_previously_called_routines, 'exact')) || ... - ~isempty(strmatch('simulated_moments_estimation', list_of_previously_called_routines, 'exact')) + ~isempty(strmatch('dsge_var_likelihood', list_of_previously_called_routines, 'exact')) || ... + ~isempty(strmatch('non_linear_dsge_likelihood', list_of_previously_called_routines, 'exact')) || ... + ~isempty(strmatch('simulated_moments_estimation', list_of_previously_called_routines, 'exact')) b = true; end diff --git a/matlab/utilities/general/ispd.m b/matlab/utilities/general/ispd.m index e319a47a1f..7fed2d44c1 100644 --- a/matlab/utilities/general/ispd.m +++ b/matlab/utilities/general/ispd.m @@ -44,7 +44,7 @@ function [test, penalty] = ispd(A) if ~isquare(A) error(['ispd:: Input argument ' inputname(1) ' has to be a square matrix!']) end - + [cholA, info] = chol(A); test = ~info; diff --git a/matlab/utilities/graphics/colorspace.m b/matlab/utilities/graphics/colorspace.m index dc46d5e850..3cd4f1c232 100644 --- a/matlab/utilities/graphics/colorspace.m +++ b/matlab/utilities/graphics/colorspace.m @@ -88,11 +88,11 @@ function varargout = colorspace(Conversion,varargin) % modification, are permitted provided that the following conditions are % met: % - % * Redistributions of source code must retain the above copyright - % notice, this list of conditions and the following disclaimer. - % * Redistributions in binary form must reproduce the above copyright - % notice, this list of conditions and the following disclaimer in - % the documentation and/or other materials provided with the distribution +% * Redistributions of source code must retain the above copyright +% notice, this list of conditions and the following disclaimer. +% * Redistributions in binary form must reproduce the above copyright +% notice, this list of conditions and the following disclaimer in +% the documentation and/or other materials provided with the distribution % % THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" % AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE @@ -111,11 +111,11 @@ if nargin < 2, error('Not enough input arguments.'); end [SrcSpace,DestSpace] = parse(Conversion); if nargin == 2 - Image = varargin{1}; + Image = varargin{1}; elseif nargin >= 3 - Image = cat(3,varargin{:}); + Image = cat(3,varargin{:}); else - error('Invalid number of input arguments.'); + error('Invalid number of input arguments.'); end FlipDims = (size(Image,3) == 1); @@ -128,31 +128,31 @@ SrcT = gettransform(SrcSpace); DestT = gettransform(DestSpace); if ~ischar(SrcT) && ~ischar(DestT) - % Both source and destination transforms are affine, so they - % can be composed into one affine operation - T = [DestT(:,1:3)*SrcT(:,1:3),DestT(:,1:3)*SrcT(:,4)+DestT(:,4)]; - Temp = zeros(size(Image)); - Temp(:,:,1) = T(1)*Image(:,:,1) + T(4)*Image(:,:,2) + T(7)*Image(:,:,3) + T(10); - Temp(:,:,2) = T(2)*Image(:,:,1) + T(5)*Image(:,:,2) + T(8)*Image(:,:,3) + T(11); - Temp(:,:,3) = T(3)*Image(:,:,1) + T(6)*Image(:,:,2) + T(9)*Image(:,:,3) + T(12); - Image = Temp; + % Both source and destination transforms are affine, so they + % can be composed into one affine operation + T = [DestT(:,1:3)*SrcT(:,1:3),DestT(:,1:3)*SrcT(:,4)+DestT(:,4)]; + Temp = zeros(size(Image)); + Temp(:,:,1) = T(1)*Image(:,:,1) + T(4)*Image(:,:,2) + T(7)*Image(:,:,3) + T(10); + Temp(:,:,2) = T(2)*Image(:,:,1) + T(5)*Image(:,:,2) + T(8)*Image(:,:,3) + T(11); + Temp(:,:,3) = T(3)*Image(:,:,1) + T(6)*Image(:,:,2) + T(9)*Image(:,:,3) + T(12); + Image = Temp; elseif ~ischar(DestT) - Image = rgb(Image,SrcSpace); - Temp = zeros(size(Image)); - Temp(:,:,1) = DestT(1)*Image(:,:,1) + DestT(4)*Image(:,:,2) + DestT(7)*Image(:,:,3) + DestT(10); - Temp(:,:,2) = DestT(2)*Image(:,:,1) + DestT(5)*Image(:,:,2) + DestT(8)*Image(:,:,3) + DestT(11); - Temp(:,:,3) = DestT(3)*Image(:,:,1) + DestT(6)*Image(:,:,2) + DestT(9)*Image(:,:,3) + DestT(12); - Image = Temp; + Image = rgb(Image,SrcSpace); + Temp = zeros(size(Image)); + Temp(:,:,1) = DestT(1)*Image(:,:,1) + DestT(4)*Image(:,:,2) + DestT(7)*Image(:,:,3) + DestT(10); + Temp(:,:,2) = DestT(2)*Image(:,:,1) + DestT(5)*Image(:,:,2) + DestT(8)*Image(:,:,3) + DestT(11); + Temp(:,:,3) = DestT(3)*Image(:,:,1) + DestT(6)*Image(:,:,2) + DestT(9)*Image(:,:,3) + DestT(12); + Image = Temp; else - Image = feval(DestT,Image,SrcSpace); + Image = feval(DestT,Image,SrcSpace); end %%% Output format %%% if nargout > 1 - varargout = {Image(:,:,1),Image(:,:,2),Image(:,:,3)}; + varargout = {Image(:,:,1),Image(:,:,2),Image(:,:,3)}; else - if FlipDims, Image = permute(Image,[1,3,2]); end - varargout = {Image}; + if FlipDims, Image = permute(Image,[1,3,2]); end + varargout = {Image}; end return; @@ -162,29 +162,29 @@ function [SrcSpace,DestSpace] = parse(Str) % Parse conversion argument if ischar(Str) - Str = lower(strrep(strrep(Str,'-',''),'=','')); - k = find(Str == '>'); - - if length(k) == 1 % Interpret the form 'src->dest' - SrcSpace = Str(1:k-1); - DestSpace = Str(k+1:end); - else - k = find(Str == '<'); - - if length(k) == 1 % Interpret the form 'dest<-src' - DestSpace = Str(1:k-1); - SrcSpace = Str(k+1:end); - else - error(['Invalid conversion, ''',Str,'''.']); - end - end - - SrcSpace = alias(SrcSpace); - DestSpace = alias(DestSpace); + Str = lower(strrep(strrep(Str,'-',''),'=','')); + k = find(Str == '>'); + + if length(k) == 1 % Interpret the form 'src->dest' + SrcSpace = Str(1:k-1); + DestSpace = Str(k+1:end); + else + k = find(Str == '<'); + + if length(k) == 1 % Interpret the form 'dest<-src' + DestSpace = Str(1:k-1); + SrcSpace = Str(k+1:end); + else + error(['Invalid conversion, ''',Str,'''.']); + end + end + + SrcSpace = alias(SrcSpace); + DestSpace = alias(DestSpace); else - SrcSpace = 1; % No source pre-transform - DestSpace = Conversion; - if any(size(Conversion) ~= 3), error('Transformation matrix must be 3x3.'); end + SrcSpace = 1; % No source pre-transform + DestSpace = Conversion; + if any(size(Conversion) ~= 3), error('Transformation matrix must be 3x3.'); end end return; @@ -193,18 +193,18 @@ function Space = alias(Space) Space = strrep(strrep(Space,'cie',''),' ',''); if isempty(Space) - Space = 'rgb'; + Space = 'rgb'; end switch Space -case {'ycbcr','ycc'} - Space = 'ycbcr'; -case {'hsv','hsb'} - Space = 'hsv'; -case {'hsl','hsi','hls'} - Space = 'hsl'; -case {'rgb','yuv','yiq','ydbdr','ycbcr','jpegycbcr','xyz','lab','luv','lch'} - return; + case {'ycbcr','ycc'} + Space = 'ycbcr'; + case {'hsv','hsb'} + Space = 'hsv'; + case {'hsl','hsi','hls'} + Space = 'hsl'; + case {'rgb','yuv','yiq','ydbdr','ycbcr','jpegycbcr','xyz','lab','luv','lch'} + return; end return; @@ -213,32 +213,32 @@ function T = gettransform(Space) % Get a colorspace transform: either a matrix describing an affine transform, % or a string referring to a conversion subroutine switch Space -case 'ypbpr' - T = [0.299,0.587,0.114,0;-0.1687367,-0.331264,0.5,0;0.5,-0.418688,-0.081312,0]; -case 'yuv' - % sRGB to NTSC/PAL YUV - % Wikipedia: http://en.wikipedia.org/wiki/YUV - T = [0.299,0.587,0.114,0;-0.147,-0.289,0.436,0;0.615,-0.515,-0.100,0]; -case 'ydbdr' - % sRGB to SECAM YDbDr - % Wikipedia: http://en.wikipedia.org/wiki/YDbDr - T = [0.299,0.587,0.114,0;-0.450,-0.883,1.333,0;-1.333,1.116,0.217,0]; -case 'yiq' - % sRGB in [0,1] to NTSC YIQ in [0,1];[-0.595716,0.595716];[-0.522591,0.522591]; - % Wikipedia: http://en.wikipedia.org/wiki/YIQ - T = [0.299,0.587,0.114,0;0.595716,-0.274453,-0.321263,0;0.211456,-0.522591,0.311135,0]; -case 'ycbcr' - % sRGB (range [0,1]) to ITU-R BRT.601 (CCIR 601) Y'CbCr - % Wikipedia: http://en.wikipedia.org/wiki/YCbCr - % Poynton, Equation 3, scaling of R'G'B to Y'PbPr conversion - T = [65.481,128.553,24.966,16;-37.797,-74.203,112.0,128;112.0,-93.786,-18.214,128]; -case 'jpegycbcr' - % Wikipedia: http://en.wikipedia.org/wiki/YCbCr - T = [0.299,0.587,0.114,0;-0.168736,-0.331264,0.5,0.5;0.5,-0.418688,-0.081312,0.5]*255; -case {'rgb','xyz','hsv','hsl','lab','luv','lch','cat02lms'} - T = Space; -otherwise - error(['Unknown color space, ''',Space,'''.']); + case 'ypbpr' + T = [0.299,0.587,0.114,0;-0.1687367,-0.331264,0.5,0;0.5,-0.418688,-0.081312,0]; + case 'yuv' + % sRGB to NTSC/PAL YUV + % Wikipedia: http://en.wikipedia.org/wiki/YUV + T = [0.299,0.587,0.114,0;-0.147,-0.289,0.436,0;0.615,-0.515,-0.100,0]; + case 'ydbdr' + % sRGB to SECAM YDbDr + % Wikipedia: http://en.wikipedia.org/wiki/YDbDr + T = [0.299,0.587,0.114,0;-0.450,-0.883,1.333,0;-1.333,1.116,0.217,0]; + case 'yiq' + % sRGB in [0,1] to NTSC YIQ in [0,1];[-0.595716,0.595716];[-0.522591,0.522591]; + % Wikipedia: http://en.wikipedia.org/wiki/YIQ + T = [0.299,0.587,0.114,0;0.595716,-0.274453,-0.321263,0;0.211456,-0.522591,0.311135,0]; + case 'ycbcr' + % sRGB (range [0,1]) to ITU-R BRT.601 (CCIR 601) Y'CbCr + % Wikipedia: http://en.wikipedia.org/wiki/YCbCr + % Poynton, Equation 3, scaling of R'G'B to Y'PbPr conversion + T = [65.481,128.553,24.966,16;-37.797,-74.203,112.0,128;112.0,-93.786,-18.214,128]; + case 'jpegycbcr' + % Wikipedia: http://en.wikipedia.org/wiki/YCbCr + T = [0.299,0.587,0.114,0;-0.168736,-0.331264,0.5,0.5;0.5,-0.418688,-0.081312,0.5]*255; + case {'rgb','xyz','hsv','hsl','lab','luv','lch','cat02lms'} + T = Space; + otherwise + error(['Unknown color space, ''',Space,'''.']); end return; @@ -246,43 +246,43 @@ return; function Image = rgb(Image,SrcSpace) % Convert to sRGB from 'SrcSpace' switch SrcSpace -case 'rgb' - return; -case 'hsv' - % Convert HSV to sRGB - Image = huetorgb((1 - Image(:,:,2)).*Image(:,:,3),Image(:,:,3),Image(:,:,1)); -case 'hsl' - % Convert HSL to sRGB - L = Image(:,:,3); - Delta = Image(:,:,2).*min(L,1-L); - Image = huetorgb(L-Delta,L+Delta,Image(:,:,1)); -case {'xyz','lab','luv','lch','cat02lms'} - % Convert to CIE XYZ - Image = xyz(Image,SrcSpace); - % Convert XYZ to RGB - T = [3.2406, -1.5372, -0.4986; -0.9689, 1.8758, 0.0415; 0.0557, -0.2040, 1.057]; - R = T(1)*Image(:,:,1) + T(4)*Image(:,:,2) + T(7)*Image(:,:,3); % R - G = T(2)*Image(:,:,1) + T(5)*Image(:,:,2) + T(8)*Image(:,:,3); % G - B = T(3)*Image(:,:,1) + T(6)*Image(:,:,2) + T(9)*Image(:,:,3); % B - % Desaturate and rescale to constrain resulting RGB values to [0,1] - AddWhite = -min(min(min(R,G),B),0); - R = R + AddWhite; - G = G + AddWhite; - B = B + AddWhite; - % Apply gamma correction to convert linear RGB to sRGB - Image(:,:,1) = gammacorrection(R); % R' - Image(:,:,2) = gammacorrection(G); % G' - Image(:,:,3) = gammacorrection(B); % B' -otherwise % Conversion is through an affine transform - T = gettransform(SrcSpace); - temp = inv(T(:,1:3)); - T = [temp,-temp*T(:,4)]; - R = T(1)*Image(:,:,1) + T(4)*Image(:,:,2) + T(7)*Image(:,:,3) + T(10); - G = T(2)*Image(:,:,1) + T(5)*Image(:,:,2) + T(8)*Image(:,:,3) + T(11); - B = T(3)*Image(:,:,1) + T(6)*Image(:,:,2) + T(9)*Image(:,:,3) + T(12); - Image(:,:,1) = R; - Image(:,:,2) = G; - Image(:,:,3) = B; + case 'rgb' + return; + case 'hsv' + % Convert HSV to sRGB + Image = huetorgb((1 - Image(:,:,2)).*Image(:,:,3),Image(:,:,3),Image(:,:,1)); + case 'hsl' + % Convert HSL to sRGB + L = Image(:,:,3); + Delta = Image(:,:,2).*min(L,1-L); + Image = huetorgb(L-Delta,L+Delta,Image(:,:,1)); + case {'xyz','lab','luv','lch','cat02lms'} + % Convert to CIE XYZ + Image = xyz(Image,SrcSpace); + % Convert XYZ to RGB + T = [3.2406, -1.5372, -0.4986; -0.9689, 1.8758, 0.0415; 0.0557, -0.2040, 1.057]; + R = T(1)*Image(:,:,1) + T(4)*Image(:,:,2) + T(7)*Image(:,:,3); % R + G = T(2)*Image(:,:,1) + T(5)*Image(:,:,2) + T(8)*Image(:,:,3); % G + B = T(3)*Image(:,:,1) + T(6)*Image(:,:,2) + T(9)*Image(:,:,3); % B + % Desaturate and rescale to constrain resulting RGB values to [0,1] + AddWhite = -min(min(min(R,G),B),0); + R = R + AddWhite; + G = G + AddWhite; + B = B + AddWhite; + % Apply gamma correction to convert linear RGB to sRGB + Image(:,:,1) = gammacorrection(R); % R' + Image(:,:,2) = gammacorrection(G); % G' + Image(:,:,3) = gammacorrection(B); % B' + otherwise % Conversion is through an affine transform + T = gettransform(SrcSpace); + temp = inv(T(:,1:3)); + T = [temp,-temp*T(:,4)]; + R = T(1)*Image(:,:,1) + T(4)*Image(:,:,2) + T(7)*Image(:,:,3) + T(10); + G = T(2)*Image(:,:,1) + T(5)*Image(:,:,2) + T(8)*Image(:,:,3) + T(11); + B = T(3)*Image(:,:,1) + T(6)*Image(:,:,2) + T(9)*Image(:,:,3) + T(12); + Image(:,:,1) = R; + Image(:,:,2) = G; + Image(:,:,3) = B; end % Clip to [0,1] @@ -295,50 +295,50 @@ function Image = xyz(Image,SrcSpace) WhitePoint = [0.950456,1,1.088754]; switch SrcSpace -case 'xyz' - return; -case 'luv' - % Convert CIE L*uv to XYZ - WhitePointU = (4*WhitePoint(1))./(WhitePoint(1) + 15*WhitePoint(2) + 3*WhitePoint(3)); - WhitePointV = (9*WhitePoint(2))./(WhitePoint(1) + 15*WhitePoint(2) + 3*WhitePoint(3)); - L = Image(:,:,1); - Y = (L + 16)/116; - Y = invf(Y)*WhitePoint(2); - U = Image(:,:,2)./(13*L + 1e-6*(L==0)) + WhitePointU; - V = Image(:,:,3)./(13*L + 1e-6*(L==0)) + WhitePointV; - Image(:,:,1) = -(9*Y.*U)./((U-4).*V - U.*V); % X - Image(:,:,2) = Y; % Y - Image(:,:,3) = (9*Y - (15*V.*Y) - (V.*Image(:,:,1)))./(3*V); % Z -case {'lab','lch'} - Image = lab(Image,SrcSpace); - % Convert CIE L*ab to XYZ - fY = (Image(:,:,1) + 16)/116; - fX = fY + Image(:,:,2)/500; - fZ = fY - Image(:,:,3)/200; - Image(:,:,1) = WhitePoint(1)*invf(fX); % X - Image(:,:,2) = WhitePoint(2)*invf(fY); % Y - Image(:,:,3) = WhitePoint(3)*invf(fZ); % Z -case 'cat02lms' + case 'xyz' + return; + case 'luv' + % Convert CIE L*uv to XYZ + WhitePointU = (4*WhitePoint(1))./(WhitePoint(1) + 15*WhitePoint(2) + 3*WhitePoint(3)); + WhitePointV = (9*WhitePoint(2))./(WhitePoint(1) + 15*WhitePoint(2) + 3*WhitePoint(3)); + L = Image(:,:,1); + Y = (L + 16)/116; + Y = invf(Y)*WhitePoint(2); + U = Image(:,:,2)./(13*L + 1e-6*(L==0)) + WhitePointU; + V = Image(:,:,3)./(13*L + 1e-6*(L==0)) + WhitePointV; + Image(:,:,1) = -(9*Y.*U)./((U-4).*V - U.*V); % X + Image(:,:,2) = Y; % Y + Image(:,:,3) = (9*Y - (15*V.*Y) - (V.*Image(:,:,1)))./(3*V); % Z + case {'lab','lch'} + Image = lab(Image,SrcSpace); + % Convert CIE L*ab to XYZ + fY = (Image(:,:,1) + 16)/116; + fX = fY + Image(:,:,2)/500; + fZ = fY - Image(:,:,3)/200; + Image(:,:,1) = WhitePoint(1)*invf(fX); % X + Image(:,:,2) = WhitePoint(2)*invf(fY); % Y + Image(:,:,3) = WhitePoint(3)*invf(fZ); % Z + case 'cat02lms' % Convert CAT02 LMS to XYZ - T = inv([0.7328, 0.4296, -0.1624;-0.7036, 1.6975, 0.0061; 0.0030, 0.0136, 0.9834]); - L = Image(:,:,1); - M = Image(:,:,2); - S = Image(:,:,3); - Image(:,:,1) = T(1)*L + T(4)*M + T(7)*S; % X - Image(:,:,2) = T(2)*L + T(5)*M + T(8)*S; % Y - Image(:,:,3) = T(3)*L + T(6)*M + T(9)*S; % Z -otherwise % Convert from some gamma-corrected space - % Convert to sRGB - Image = rgb(Image,SrcSpace); - % Undo gamma correction - R = invgammacorrection(Image(:,:,1)); - G = invgammacorrection(Image(:,:,2)); - B = invgammacorrection(Image(:,:,3)); - % Convert RGB to XYZ - T = inv([3.2406, -1.5372, -0.4986; -0.9689, 1.8758, 0.0415; 0.0557, -0.2040, 1.057]); - Image(:,:,1) = T(1)*R + T(4)*G + T(7)*B; % X - Image(:,:,2) = T(2)*R + T(5)*G + T(8)*B; % Y - Image(:,:,3) = T(3)*R + T(6)*G + T(9)*B; % Z + T = inv([0.7328, 0.4296, -0.1624;-0.7036, 1.6975, 0.0061; 0.0030, 0.0136, 0.9834]); + L = Image(:,:,1); + M = Image(:,:,2); + S = Image(:,:,3); + Image(:,:,1) = T(1)*L + T(4)*M + T(7)*S; % X + Image(:,:,2) = T(2)*L + T(5)*M + T(8)*S; % Y + Image(:,:,3) = T(3)*L + T(6)*M + T(9)*S; % Z + otherwise % Convert from some gamma-corrected space + % Convert to sRGB + Image = rgb(Image,SrcSpace); + % Undo gamma correction + R = invgammacorrection(Image(:,:,1)); + G = invgammacorrection(Image(:,:,2)); + B = invgammacorrection(Image(:,:,3)); + % Convert RGB to XYZ + T = inv([3.2406, -1.5372, -0.4986; -0.9689, 1.8758, 0.0415; 0.0557, -0.2040, 1.057]); + Image(:,:,1) = T(1)*R + T(4)*G + T(7)*B; % X + Image(:,:,2) = T(2)*R + T(5)*G + T(8)*B; % Y + Image(:,:,3) = T(3)*R + T(6)*G + T(9)*B; % Z end return; @@ -357,25 +357,25 @@ return; function Image = hsl(Image,SrcSpace) % Convert to HSL switch SrcSpace -case 'hsv' - % Convert HSV to HSL - MaxVal = Image(:,:,3); - MinVal = (1 - Image(:,:,2)).*MaxVal; - L = 0.5*(MaxVal + MinVal); - temp = min(L,1-L); - Image(:,:,2) = 0.5*(MaxVal - MinVal)./(temp + (temp == 0)); - Image(:,:,3) = L; -otherwise - Image = rgb(Image,SrcSpace); % Convert to sRGB - % Convert sRGB to HSL - MinVal = min(Image,[],3); - MaxVal = max(Image,[],3); - L = 0.5*(MaxVal + MinVal); - temp = min(L,1-L); - S = 0.5*(MaxVal - MinVal)./(temp + (temp == 0)); - Image(:,:,1) = rgbtohue(Image); - Image(:,:,2) = S; - Image(:,:,3) = L; + case 'hsv' + % Convert HSV to HSL + MaxVal = Image(:,:,3); + MinVal = (1 - Image(:,:,2)).*MaxVal; + L = 0.5*(MaxVal + MinVal); + temp = min(L,1-L); + Image(:,:,2) = 0.5*(MaxVal - MinVal)./(temp + (temp == 0)); + Image(:,:,3) = L; + otherwise + Image = rgb(Image,SrcSpace); % Convert to sRGB + % Convert sRGB to HSL + MinVal = min(Image,[],3); + MaxVal = max(Image,[],3); + L = 0.5*(MaxVal + MinVal); + temp = min(L,1-L); + S = 0.5*(MaxVal - MinVal)./(temp + (temp == 0)); + Image(:,:,1) = rgbtohue(Image); + Image(:,:,2) = S; + Image(:,:,3) = L; end return; @@ -385,25 +385,25 @@ function Image = lab(Image,SrcSpace) WhitePoint = [0.950456,1,1.088754]; switch SrcSpace -case 'lab' - return; -case 'lch' - % Convert CIE L*CH to CIE L*ab - C = Image(:,:,2); - Image(:,:,2) = cos(Image(:,:,3)*pi/180).*C; % a* - Image(:,:,3) = sin(Image(:,:,3)*pi/180).*C; % b* -otherwise - Image = xyz(Image,SrcSpace); % Convert to XYZ - % Convert XYZ to CIE L*a*b* - X = Image(:,:,1)/WhitePoint(1); - Y = Image(:,:,2)/WhitePoint(2); - Z = Image(:,:,3)/WhitePoint(3); - fX = f(X); - fY = f(Y); - fZ = f(Z); - Image(:,:,1) = 116*fY - 16; % L* - Image(:,:,2) = 500*(fX - fY); % a* - Image(:,:,3) = 200*(fY - fZ); % b* + case 'lab' + return; + case 'lch' + % Convert CIE L*CH to CIE L*ab + C = Image(:,:,2); + Image(:,:,2) = cos(Image(:,:,3)*pi/180).*C; % a* + Image(:,:,3) = sin(Image(:,:,3)*pi/180).*C; % b* + otherwise + Image = xyz(Image,SrcSpace); % Convert to XYZ + % Convert XYZ to CIE L*a*b* + X = Image(:,:,1)/WhitePoint(1); + Y = Image(:,:,2)/WhitePoint(2); + Z = Image(:,:,3)/WhitePoint(3); + fX = f(X); + fY = f(Y); + fZ = f(Z); + Image(:,:,1) = 116*fY - 16; % L* + Image(:,:,2) = 500*(fX - fY); % a* + Image(:,:,3) = 200*(fY - fZ); % b* end return; diff --git a/matlab/utilities/graphics/distinguishable_colors.m b/matlab/utilities/graphics/distinguishable_colors.m index 0b9fb7a33f..f2c66231d5 100644 --- a/matlab/utilities/graphics/distinguishable_colors.m +++ b/matlab/utilities/graphics/distinguishable_colors.m @@ -61,11 +61,11 @@ function colors = distinguishable_colors(n_colors,bg,func) % modification, are permitted provided that the following conditions are % met: % - % * Redistributions of source code must retain the above copyright - % notice, this list of conditions and the following disclaimer. - % * Redistributions in binary form must reproduce the above copyright - % notice, this list of conditions and the following disclaimer in - % the documentation and/or other materials provided with the distribution +% * Redistributions of source code must retain the above copyright +% notice, this list of conditions and the following disclaimer. +% * Redistributions in binary form must reproduce the above copyright +% notice, this list of conditions and the following disclaimer in +% the documentation and/or other materials provided with the distribution % % THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" % AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE diff --git a/matlab/vnorm.m b/matlab/vnorm.m index b6bb123d94..fc9f5850a1 100644 --- a/matlab/vnorm.m +++ b/matlab/vnorm.m @@ -71,7 +71,7 @@ if isempty(dim) idx = find(size(A)~=1); dim = idx(1); end - + if isempty(ntype) y = sqrt(sum( abs(A).^2 , dim) ); elseif ntype==1 diff --git a/matlab/writeVarExpectationFunction.m b/matlab/writeVarExpectationFunction.m index 50fcd10baa..513a5cb8ab 100644 --- a/matlab/writeVarExpectationFunction.m +++ b/matlab/writeVarExpectationFunction.m @@ -176,8 +176,8 @@ else spaces = ' '; end fprintf(fid, '%sy = ...\n%s[ ... %% intercept\n%s', fs, spaces, ns); -fprintf(fid, [repmat('% f ', 1, size(mu, 2)) '; ...\n' ns], mu'); + fprintf(fid, [repmat('% f ', 1, size(mu, 2)) '; ...\n' ns], mu'); fprintf(fid, ' ] + ...\n%s[ ... %% autoregressive matrices\n%s', spaces, ns); -fprintf(fid, [repmat('% f ', 1, size(A, 2)) '; ...\n' ns], A'); + fprintf(fid, [repmat('% f ', 1, size(A, 2)) '; ...\n' ns], A'); fprintf(fid, ' ] * y;\n'); end \ No newline at end of file diff --git a/matlab/write_latex_definitions.m b/matlab/write_latex_definitions.m index 2bf3acf366..144f6242be 100644 --- a/matlab/write_latex_definitions.m +++ b/matlab/write_latex_definitions.m @@ -65,9 +65,9 @@ for i=1:length(tables) long = eval([M_var_root{i} '_names_long']); for j=1:size(names,1) fprintf(fid, '\\texttt{%s} & $%s$ & %s\\\\\n', ... - regexprep(strtrim(names(j,:)), '_', '\\_'), ... - strtrim(tex(j,:)), ... - regexprep(strtrim(long(j,:)), '_', '\\_')); + regexprep(strtrim(names(j,:)), '_', '\\_'), ... + strtrim(tex(j,:)), ... + regexprep(strtrim(long(j,:)), '_', '\\_')); end fprintf(fid, '\\hline%%\n'); fprintf(fid, '\\end{longtable}\n'); diff --git a/matlab/write_latex_parameter_table.m b/matlab/write_latex_parameter_table.m index c2d7398019..5a753c31cf 100644 --- a/matlab/write_latex_parameter_table.m +++ b/matlab/write_latex_parameter_table.m @@ -75,20 +75,20 @@ fprintf(fid, '\\endhead\n'); tex = M_.param_names_tex; long = M_.param_names_long; for j=1:size(tex,1) -if Long_names_present==1; - % replace underscores - long_names_temp=regexprep(strtrim(long(j,:)), '_', '\\_'); - % replace percent - long_names_temp=regexprep(long_names_temp, '%', '\\%'); - fprintf(fid, '$%s$ \t & \t %4.3f \t & \t %s\\\\\n', ... - strtrim(tex(j,:)), ... - M_.params(j,:),... - long_names_temp); -else - fprintf(fid, '$%s$ \t & \t %4.3f \\\\\n', ... - strtrim(tex(j,:)), ... - M_.params(j,:)); -end + if Long_names_present==1; + % replace underscores + long_names_temp=regexprep(strtrim(long(j,:)), '_', '\\_'); + % replace percent + long_names_temp=regexprep(long_names_temp, '%', '\\%'); + fprintf(fid, '$%s$ \t & \t %4.3f \t & \t %s\\\\\n', ... + strtrim(tex(j,:)), ... + M_.params(j,:),... + long_names_temp); + else + fprintf(fid, '$%s$ \t & \t %4.3f \\\\\n', ... + strtrim(tex(j,:)), ... + M_.params(j,:)); + end end fprintf(fid, '\\bottomrule%%\n'); fprintf(fid, '\\end{longtable}\n'); diff --git a/matlab/write_latex_prior_table.m b/matlab/write_latex_prior_table.m index 46a5e3bf52..db9c8bfbce 100644 --- a/matlab/write_latex_prior_table.m +++ b/matlab/write_latex_prior_table.m @@ -37,11 +37,11 @@ end if (size(estim_params_.var_endo,1) || size(estim_params_.corrn,1)) % Prior over measurement errors are defined... - if ((isfield(options_,'varobs') && isempty(options_.varobs)) || ~isfield(options_,'varobs')) - % ... But the list of observed variabled is not yet defined. - fprintf(['\nwrite_latex_prior_table:: varobs should be declared before. Skipping table creation.\n']) - return - end + if ((isfield(options_,'varobs') && isempty(options_.varobs)) || ~isfield(options_,'varobs')) + % ... But the list of observed variabled is not yet defined. + fprintf(['\nwrite_latex_prior_table:: varobs should be declared before. Skipping table creation.\n']) + return + end end % Fill or update bayestopt_ structure @@ -115,56 +115,56 @@ for i=1:size(BayesOptions.name,1) PriorMode = BayesOptions.p5(i); PriorStandardDeviation = BayesOptions.p2(i); switch BayesOptions.pshape(i) - case { 1 , 5 } + case { 1 , 5 } + LowerBound = BayesOptions.p3(i); + UpperBound = BayesOptions.p4(i); + if ~isinf(lb(i)) + LowerBound=max(LowerBound,lb(i)); + end + if ~isinf(ub(i)) + UpperBound=min(UpperBound,ub(i)); + end + case { 2 , 4 , 6, 8 } + LowerBound = BayesOptions.p3(i); + if ~isinf(lb(i)) + LowerBound=max(LowerBound,lb(i)); + end + if ~isinf(ub(i)) + UpperBound=ub(i); + else + UpperBound = '$\infty$'; + end + case 3 + if isinf(BayesOptions.p3(i)) && isinf(lb(i)) + LowerBound = '$-\infty$'; + else LowerBound = BayesOptions.p3(i); - UpperBound = BayesOptions.p4(i); if ~isinf(lb(i)) LowerBound=max(LowerBound,lb(i)); end + end + if isinf(BayesOptions.p4(i)) && isinf(ub(i)) + UpperBound = '$\infty$'; + else + UpperBound = BayesOptions.p4(i); if ~isinf(ub(i)) UpperBound=min(UpperBound,ub(i)); end - case { 2 , 4 , 6, 8 } - LowerBound = BayesOptions.p3(i); - if ~isinf(lb(i)) - LowerBound=max(LowerBound,lb(i)); - end - if ~isinf(ub(i)) - UpperBound=ub(i); - else - UpperBound = '$\infty$'; - end - case 3 - if isinf(BayesOptions.p3(i)) && isinf(lb(i)) - LowerBound = '$-\infty$'; - else - LowerBound = BayesOptions.p3(i); - if ~isinf(lb(i)) - LowerBound=max(LowerBound,lb(i)); - end - end - if isinf(BayesOptions.p4(i)) && isinf(ub(i)) - UpperBound = '$\infty$'; - else - UpperBound = BayesOptions.p4(i); - if ~isinf(ub(i)) - UpperBound=min(UpperBound,ub(i)); - end - end - otherwise - error('write_latex_prior_table:: Dynare bug!') + end + otherwise + error('write_latex_prior_table:: Dynare bug!') end format_string = build_format_string(PriorMode, PriorStandardDeviation,LowerBound,UpperBound); fprintf(fidTeX,format_string, ... - TexName, ... - PriorShape, ... - PriorMean, ... - PriorMode, ... - PriorStandardDeviation, ... - LowerBound, ... - UpperBound, ... - PriorIntervals.lb(i), ... - PriorIntervals.ub(i) ); + TexName, ... + PriorShape, ... + PriorMean, ... + PriorMode, ... + PriorStandardDeviation, ... + LowerBound, ... + UpperBound, ... + PriorIntervals.lb(i), ... + PriorIntervals.ub(i) ); end fprintf(fidTeX,'\\end{longtable}\n '); fprintf(fidTeX,'\\end{center}\n'); diff --git a/matlab/writecellofchar.m b/matlab/writecellofchar.m index be636e6f17..9ad378cb21 100644 --- a/matlab/writecellofchar.m +++ b/matlab/writecellofchar.m @@ -37,27 +37,27 @@ function str = writecellofchar(c) % % You should have received a copy of the GNU General Public License % along with Dynare. If not, see <http://www.gnu.org/licenses/>. - + str = '{'; for i=1:size(c, 1) - for j=1:size(c, 2) - if iscell(c{i,j}) - str = sprintf('%s%s', str, writecellofchar(c{i, j})); - elseif ischar(c{i, j}) - if size(c{i, j}, 1)>1 - str = sprintf('%s''%s''', str, writematrixofchar(c{i, j})); - else - str = sprintf('%s''%s''', str, c{i, j}); - end - else - error('Type not implemenented!') - end - if j<size(c, 2) - str = sprintf('%s, ', str); - end - end - if i<size(c, 1) - str = sprintf('%s; ', str); - end +for j=1:size(c, 2) +if iscell(c{i,j}) +str = sprintf('%s%s', str, writecellofchar(c{i, j})); +elseif ischar(c{i, j}) +if size(c{i, j}, 1)>1 +str = sprintf('%s''%s''', str, writematrixofchar(c{i, j})); +else +str = sprintf('%s''%s''', str, c{i, j}); +end +else +error('Type not implemenented!') +end +if j<size(c, 2) +str = sprintf('%s, ', str); +end +end +if i<size(c, 1) +str = sprintf('%s; ', str); +end end str = sprintf('%s}', str); \ No newline at end of file diff --git a/matlab/writematrixofchar.m b/matlab/writematrixofchar.m index 6f230e554f..aca7839558 100644 --- a/matlab/writematrixofchar.m +++ b/matlab/writematrixofchar.m @@ -16,7 +16,7 @@ function str = writematrixofchar(m) % ['a'; 'b'] % % where the returned argument is a string which can be evaluated or printed. - + % Copyright (C) 2015 Dynare Team % % This file is part of Dynare. diff --git a/mex/sources/bytecode/testing/bytecode_debug.m b/mex/sources/bytecode/testing/bytecode_debug.m index 7f2e8f9e59..e13535841b 100644 --- a/mex/sources/bytecode/testing/bytecode_debug.m +++ b/mex/sources/bytecode/testing/bytecode_debug.m @@ -4,18 +4,18 @@ fid = fopen([M_.fname '_options.txt'],'wt'); nfields = fieldnames(options_); fprintf(fid, '%d %d %d\n',size(nfields,1), size(options_,1), size(options_,2)); for i=1:size(nfields, 1) - disp(nfields(i)); - if iscell(nfields(i)) - AA = cell2mat(nfields(i)); - else - AA = nfields(i); - end; - if iscell(AA) - AA = cell2mat(AA); - end; - fprintf(fid, '%s\n', AA); - Z = getfield(options_, AA); - print_object(fid, Z); + disp(nfields(i)); + if iscell(nfields(i)) + AA = cell2mat(nfields(i)); + else + AA = nfields(i); + end; + if iscell(AA) + AA = cell2mat(AA); + end; + fprintf(fid, '%s\n', AA); + Z = getfield(options_, AA); + print_object(fid, Z); end; fclose(fid); @@ -23,14 +23,14 @@ fid = fopen([M_.fname '_M.txt'],'wt'); nfields = fields(M_); fprintf(fid, '%d %d %d\n',size(nfields,1), size(M_,1), size(M_,2)); for i=1:size(nfields, 1) - disp(nfields(i)); - if iscell(nfields(i)) - AA = cell2mat(nfields(i)); - else - AA = nfields(i); - end; - fprintf(fid, '%s\n', AA); - print_object(fid, getfield(M_, AA)); + disp(nfields(i)); + if iscell(nfields(i)) + AA = cell2mat(nfields(i)); + else + AA = nfields(i); + end; + fprintf(fid, '%s\n', AA); + print_object(fid, getfield(M_, AA)); end; fclose(fid); @@ -39,65 +39,65 @@ fid = fopen([M_.fname '_oo.txt'],'wt'); nfields = fields(oo_); fprintf(fid, '%d %d %d\n',size(nfields,1), size(oo_,1), size(oo_,2)); for i=1:size(nfields, 1) - disp(nfields(i)); - if iscell(nfields(i)) - AA = cell2mat(nfields(i)); - else - AA = nfields(i); - end; - if iscell(AA) - AA = cell2mat(AA); - end; - fprintf(fid, '%s\n', AA); - print_object(fid, getfield(oo_, AA)); + disp(nfields(i)); + if iscell(nfields(i)) + AA = cell2mat(nfields(i)); + else + AA = nfields(i); + end; + if iscell(AA) + AA = cell2mat(AA); + end; + fprintf(fid, '%s\n', AA); + print_object(fid, getfield(oo_, AA)); end; fclose(fid); function print_object(fid, object_arg) - if iscell(object_arg) - object = cell2mat(object_arg); - else - object = object_arg; - end; - if isa(object,'float') == 1 - fprintf(fid, '%d ', 0); - fprintf(fid, '%d %d\n',size(object,1), size(object,2)); - fprintf(fid, '%f\n', object); - %for i=1:size(object, 2) - %for j=1:size(object, 1) - %fprintf(fid, '%f\n', object(i,j)); - %end; - %end; - elseif isa(object,'char') == 1 - fprintf(fid, '%d ', 3); - fprintf(fid, '%d %d\n',size(object,1), size(object,2)); - %object - for i=1:size(object, 1) - %for i=1:size(object, 2) - fprintf(fid, '%s ', object(i,:)); - %end; - %fprintf(fid, '\n'); - end; - fprintf(fid, '\n'); - elseif isa(object,'struct') == 1 - fprintf(fid, '%d ', 5); - nfields = fields(object); - fprintf(fid, '%d %d %d\n',size(nfields,1), size(object,1), size(object,2)); - for j=1:size(object, 1) * size(object, 2) - nfields = fields(object(j)); - for i=1:size(nfields, 1) - if iscell(nfields(i)) - AA = cell2mat(nfields(i)); - else - AA = nfields(i); - end; - fprintf(fid, '%s\n', AA); - print_object(fid, getfield(object, AA)); - end; - end; - else - disp(['type ' object 'note handle']); - end; +if iscell(object_arg) + object = cell2mat(object_arg); +else + object = object_arg; +end; +if isa(object,'float') == 1 + fprintf(fid, '%d ', 0); + fprintf(fid, '%d %d\n',size(object,1), size(object,2)); + fprintf(fid, '%f\n', object); + %for i=1:size(object, 2) + %for j=1:size(object, 1) + %fprintf(fid, '%f\n', object(i,j)); + %end; + %end; +elseif isa(object,'char') == 1 + fprintf(fid, '%d ', 3); + fprintf(fid, '%d %d\n',size(object,1), size(object,2)); + %object + for i=1:size(object, 1) + %for i=1:size(object, 2) + fprintf(fid, '%s ', object(i,:)); + %end; + %fprintf(fid, '\n'); + end; + fprintf(fid, '\n'); +elseif isa(object,'struct') == 1 + fprintf(fid, '%d ', 5); + nfields = fields(object); + fprintf(fid, '%d %d %d\n',size(nfields,1), size(object,1), size(object,2)); + for j=1:size(object, 1) * size(object, 2) + nfields = fields(object(j)); + for i=1:size(nfields, 1) + if iscell(nfields(i)) + AA = cell2mat(nfields(i)); + else + AA = nfields(i); + end; + fprintf(fid, '%s\n', AA); + print_object(fid, getfield(object, AA)); + end; + end; +else + disp(['type ' object 'note handle']); +end; diff --git a/mex/sources/bytecode/testing/simulate_debug.m b/mex/sources/bytecode/testing/simulate_debug.m index 9384eb7fe9..4c3e818f14 100644 --- a/mex/sources/bytecode/testing/simulate_debug.m +++ b/mex/sources/bytecode/testing/simulate_debug.m @@ -2,7 +2,7 @@ function simulate_debug(steady_state) global M_ oo_ options_; fid = fopen([M_.fname '_options.txt'],'wt'); if steady_state~=1 - fprintf(fid,'%d\n',options_.periods); + fprintf(fid,'%d\n',options_.periods); end; fprintf(fid,'%d\n',options_.simul.maxit); fprintf(fid,'%6.20f\n',options_.slowc); @@ -17,11 +17,11 @@ fprintf(fid,'%d\n',M_.maximum_lead); fprintf(fid,'%d\n',M_.maximum_endo_lag); fprintf(fid,'%d\n',M_.param_nbr); if steady_state==1 - fprintf(fid,'%d\n',size(oo_.exo_steady_state, 1)); - fprintf(fid,'%d\n',size(oo_.exo_steady_state, 2)); + fprintf(fid,'%d\n',size(oo_.exo_steady_state, 1)); + fprintf(fid,'%d\n',size(oo_.exo_steady_state, 2)); else - fprintf(fid,'%d\n',size(oo_.exo_simul, 1)); - fprintf(fid,'%d\n',size(oo_.exo_simul, 2)); + fprintf(fid,'%d\n',size(oo_.exo_simul, 1)); + fprintf(fid,'%d\n',size(oo_.exo_simul, 2)); end; fprintf(fid,'%d\n',M_.endo_nbr); if steady_state==1 @@ -41,11 +41,11 @@ fprintf(fid,'%6.20f\n',M_.params); fclose(fid); fid = fopen([M_.fname '_oo.txt'],'wt'); if steady_state==1 - fprintf(fid,'%6.20f\n',oo_.steady_state); - fprintf(fid,'%6.20f\n',oo_.exo_steady_state); + fprintf(fid,'%6.20f\n',oo_.steady_state); + fprintf(fid,'%6.20f\n',oo_.exo_steady_state); else - fprintf(fid,'%6.20f\n',oo_.endo_simul); - fprintf(fid,'%6.20f\n',oo_.exo_simul); + fprintf(fid,'%6.20f\n',oo_.endo_simul); + fprintf(fid,'%6.20f\n',oo_.exo_simul); end; fprintf(fid,'%6.20f\n',oo_.steady_state); fprintf(fid,'%6.20f\n',oo_.exo_steady_state); diff --git a/mex/sources/estimation/tests/logposterior_dll_test/random_walk_metropolis_hastings_core.m b/mex/sources/estimation/tests/logposterior_dll_test/random_walk_metropolis_hastings_core.m index 9e741fa7f7..9dd8fc7722 100644 --- a/mex/sources/estimation/tests/logposterior_dll_test/random_walk_metropolis_hastings_core.m +++ b/mex/sources/estimation/tests/logposterior_dll_test/random_walk_metropolis_hastings_core.m @@ -94,10 +94,10 @@ varargin=myinputs.varargin; % Necessary only for remote computing! if whoiam - Parallel=myinputs.Parallel; - % initialize persistent variables in priordens() - priordens(xparam1,bayestopt_.pshape,bayestopt_.p6,bayestopt_.p7, ... - bayestopt_.p3,bayestopt_.p4,1); + Parallel=myinputs.Parallel; + % initialize persistent variables in priordens() + priordens(xparam1,bayestopt_.pshape,bayestopt_.p6,bayestopt_.p7, ... + bayestopt_.p3,bayestopt_.p4,1); end % (re)Set the penalty diff --git a/mex/sources/estimation/tests/logposterior_dll_test/rawdata_euromodel_1.m b/mex/sources/estimation/tests/logposterior_dll_test/rawdata_euromodel_1.m index 25bbc92414..6b9fee7203 100644 --- a/mex/sources/estimation/tests/logposterior_dll_test/rawdata_euromodel_1.m +++ b/mex/sources/estimation/tests/logposterior_dll_test/rawdata_euromodel_1.m @@ -1,25 +1,25 @@ C =[ - -7.4073 - -6.1860 - -6.5983 - -5.6088 - -5.0547 - -4.4774 - -3.8081 - -3.8425 - -2.4178 - -1.9835 - -1.0395 - -0.1583 - -0.0397 + -7.4073 + -6.1860 + -6.5983 + -5.6088 + -5.0547 + -4.4774 + -3.8081 + -3.8425 + -2.4178 + -1.9835 + -1.0395 + -0.1583 + -0.0397 0.3505 - -0.1879 - -0.0067 + -0.1879 + -0.0067 0.0478 - -1.2247 - -1.4349 - -0.7973 - -0.0461 + -1.2247 + -1.4349 + -0.7973 + -0.0461 0.5844 1.1372 1.3801 @@ -47,26 +47,26 @@ C =[ 1.5563 1.2308 0.3264 - -0.2208 - -0.2483 - -0.4082 - -1.0315 - -1.6030 - -1.5499 - -1.3777 - -2.1675 - -2.5138 - -2.8820 - -2.6958 - -2.4719 - -1.9854 - -1.7954 - -2.2362 - -1.0595 - -0.8808 - -0.8548 - -1.2839 - -0.1363 + -0.2208 + -0.2483 + -0.4082 + -1.0315 + -1.6030 + -1.5499 + -1.3777 + -2.1675 + -2.5138 + -2.8820 + -2.6958 + -2.4719 + -1.9854 + -1.7954 + -2.2362 + -1.0595 + -0.8808 + -0.8548 + -1.2839 + -0.1363 0.2104 0.8810 0.3555 @@ -93,31 +93,31 @@ C =[ 0.0847 0.0104 0.2115 - -0.6649 - -0.9625 - -0.7330 - -0.8664 - -1.4441 - -1.0179 - -1.2729 - -1.9539 - -1.4427 - -2.0371 - -1.9764 - -2.5654 - -2.8570 - -2.5842 - -3.0427 - -2.8312 - -2.3320 - -2.2768 - -2.1816 - -2.1043 - -1.8969 - -2.2388 - -2.1679 - -2.1172 -]; + -0.6649 + -0.9625 + -0.7330 + -0.8664 + -1.4441 + -1.0179 + -1.2729 + -1.9539 + -1.4427 + -2.0371 + -1.9764 + -2.5654 + -2.8570 + -2.5842 + -3.0427 + -2.8312 + -2.3320 + -2.2768 + -2.1816 + -2.1043 + -1.8969 + -2.2388 + -2.1679 + -2.1172 + ]; E =[ 0.6263 @@ -139,23 +139,23 @@ E =[ 1.2422 0.8084 0.4710 - -0.3704 - -0.6427 - -0.5323 - -0.5562 - -0.3651 - -0.4356 - -0.7164 - -0.5816 - -0.4635 - -0.8456 - -0.9708 - -0.7138 - -0.7499 - -0.6941 - -0.6656 - -0.2912 - -0.1650 + -0.3704 + -0.6427 + -0.5323 + -0.5562 + -0.3651 + -0.4356 + -0.7164 + -0.5816 + -0.4635 + -0.8456 + -0.9708 + -0.7138 + -0.7499 + -0.6941 + -0.6656 + -0.2912 + -0.1650 0.0774 0.2307 0.4484 @@ -163,34 +163,34 @@ E =[ 0.4653 0.2196 0.1736 - -0.1595 - -0.3918 - -0.4611 - -0.8493 - -0.7384 - -1.0604 - -1.2166 - -1.7187 - -1.6932 - -1.7830 - -1.7035 - -2.2079 - -2.3769 - -2.2511 - -2.1093 - -2.4638 - -2.4027 - -2.1313 - -1.9199 - -1.7941 - -1.4661 - -1.2269 - -1.0392 - -1.0725 - -0.7156 - -0.4778 - -0.4233 - -0.0409 + -0.1595 + -0.3918 + -0.4611 + -0.8493 + -0.7384 + -1.0604 + -1.2166 + -1.7187 + -1.6932 + -1.7830 + -1.7035 + -2.2079 + -2.3769 + -2.2511 + -2.1093 + -2.4638 + -2.4027 + -2.1313 + -1.9199 + -1.7941 + -1.4661 + -1.2269 + -1.0392 + -1.0725 + -0.7156 + -0.4778 + -0.4233 + -0.0409 0.1620 0.4280 0.5873 @@ -211,34 +211,34 @@ E =[ 1.9223 1.1777 0.4483 - -0.0661 - -0.4424 - -0.9000 - -1.1478 - -1.2047 - -1.1412 - -1.2383 - -1.1048 - -0.9716 - -0.9287 - -1.0057 - -1.0827 - -1.0200 - -1.0072 - -1.1740 - -1.2809 - -1.1086 - -0.9866 - -0.8947 - -0.5875 - -0.2329 + -0.0661 + -0.4424 + -0.9000 + -1.1478 + -1.2047 + -1.1412 + -1.2383 + -1.1048 + -0.9716 + -0.9287 + -1.0057 + -1.0827 + -1.0200 + -1.0072 + -1.1740 + -1.2809 + -1.1086 + -0.9866 + -0.8947 + -0.5875 + -0.2329 0.1493 0.4906 0.8400 1.0720 1.2648 1.5431 -]; + ]; I =[ 2.6617 @@ -253,29 +253,29 @@ I =[ 7.8923 9.4297 9.5010 - 10.0150 - 10.0413 + 10.0150 + 10.0413 9.6046 6.4766 5.9647 3.0114 0.5683 - -2.1226 - -2.1855 - -0.8329 - -1.5207 - -1.3419 - -1.7897 - -0.1476 + -2.1226 + -2.1855 + -0.8329 + -1.5207 + -1.3419 + -1.7897 + -0.1476 0.4675 - -1.6516 - -1.5419 - -1.3050 - -1.2451 - -0.7815 - -0.7796 - -0.3612 - -2.4072 + -1.6516 + -1.5419 + -1.3050 + -1.2451 + -0.7815 + -0.7796 + -0.3612 + -2.4072 1.1162 1.1383 3.4132 @@ -283,36 +283,36 @@ I =[ 2.8016 2.1734 0.9366 - -0.7050 - -1.5021 - -2.9868 - -6.0237 - -6.2589 - -6.9138 - -8.2340 - -9.2589 - -9.2465 - -9.6988 - -9.7782 - -10.5645 - -10.7544 - -13.1583 - -12.2718 - -12.0131 - -13.5983 - -12.3579 - -10.9146 - -11.1572 - -12.4935 - -9.4393 - -8.5535 - -7.3723 - -10.0169 - -6.6088 - -5.2045 - -4.1024 - -2.8472 - -1.3139 + -0.7050 + -1.5021 + -2.9868 + -6.0237 + -6.2589 + -6.9138 + -8.2340 + -9.2589 + -9.2465 + -9.6988 + -9.7782 + -10.5645 + -10.7544 + -13.1583 + -12.2718 + -12.0131 + -13.5983 + -12.3579 + -10.9146 + -11.1572 + -12.4935 + -9.4393 + -8.5535 + -7.3723 + -10.0169 + -6.6088 + -5.2045 + -4.1024 + -2.8472 + -1.3139 0.0477 1.5629 3.6947 @@ -324,30 +324,30 @@ I =[ 7.6576 8.8022 8.9611 - 10.0871 + 10.0871 9.4797 9.3964 - 10.0363 + 10.0363 8.6340 6.6522 4.4471 0.2854 - -2.1879 - -2.9879 - -4.1021 - -2.7713 - -2.2281 - -1.2908 - -0.3250 + -2.1879 + -2.9879 + -4.1021 + -2.7713 + -2.2281 + -1.2908 + -0.3250 0.6534 0.3942 0.3534 - -0.1532 - -1.7936 + -0.1532 + -1.7936 0.4909 0.3634 0.4290 - -0.9709 + -0.9709 0.1942 0.6103 1.4426 @@ -359,7 +359,7 @@ I =[ 5.3312 6.4402 6.6529 -]; + ]; L =[ 0.6263 @@ -381,23 +381,23 @@ L =[ 1.2422 0.8084 0.4710 - -0.3704 - -0.6427 - -0.5323 - -0.5562 - -0.3651 - -0.4356 - -0.7164 - -0.5816 - -0.4635 - -0.8456 - -0.9708 - -0.7138 - -0.7499 - -0.6941 - -0.6656 - -0.2912 - -0.1650 + -0.3704 + -0.6427 + -0.5323 + -0.5562 + -0.3651 + -0.4356 + -0.7164 + -0.5816 + -0.4635 + -0.8456 + -0.9708 + -0.7138 + -0.7499 + -0.6941 + -0.6656 + -0.2912 + -0.1650 0.0774 0.2307 0.4484 @@ -405,34 +405,34 @@ L =[ 0.4653 0.2196 0.1736 - -0.1595 - -0.3918 - -0.4611 - -0.8493 - -0.7384 - -1.0604 - -1.2166 - -1.7187 - -1.6932 - -1.7830 - -1.7035 - -2.2079 - -2.3769 - -2.2511 - -2.1093 - -2.4638 - -2.4027 - -2.1313 - -1.9199 - -1.7941 - -1.4661 - -1.2269 - -1.0392 - -1.0725 - -0.7156 - -0.4778 - -0.4233 - -0.0409 + -0.1595 + -0.3918 + -0.4611 + -0.8493 + -0.7384 + -1.0604 + -1.2166 + -1.7187 + -1.6932 + -1.7830 + -1.7035 + -2.2079 + -2.3769 + -2.2511 + -2.1093 + -2.4638 + -2.4027 + -2.1313 + -1.9199 + -1.7941 + -1.4661 + -1.2269 + -1.0392 + -1.0725 + -0.7156 + -0.4778 + -0.4233 + -0.0409 0.1620 0.4280 0.5873 @@ -453,48 +453,48 @@ L =[ 1.9223 1.1777 0.4483 - -0.0661 - -0.4424 - -0.9000 - -1.1478 - -1.2047 - -1.1412 - -1.2383 - -1.1048 - -0.9716 - -0.9287 - -1.0057 - -1.0827 - -1.0200 - -1.0072 - -1.1740 - -1.2809 - -1.1086 - -0.9866 - -0.8947 - -0.5875 - -0.2329 + -0.0661 + -0.4424 + -0.9000 + -1.1478 + -1.2047 + -1.1412 + -1.2383 + -1.1048 + -0.9716 + -0.9287 + -1.0057 + -1.0827 + -1.0200 + -1.0072 + -1.1740 + -1.2809 + -1.1086 + -0.9866 + -0.8947 + -0.5875 + -0.2329 0.1493 0.4906 0.8400 1.0720 1.2648 1.5431 -]; + ]; PIE =[ - -1.0113 - -0.8305 + -1.0113 + -0.8305 0.2332 - -0.8746 - -0.7978 - -0.9220 - -0.2487 - -0.7749 - -0.5460 - -0.5347 + -0.8746 + -0.7978 + -0.9220 + -0.2487 + -0.7749 + -0.5460 + -0.5347 0.5050 - -0.0334 + -0.0334 0.6756 0.8791 0.7267 @@ -516,7 +516,7 @@ PIE =[ 0.4025 0.4799 0.5981 - -0.1523 + -0.1523 0.4458 0.2182 0.9793 @@ -538,108 +538,108 @@ PIE =[ 0.3910 0.3301 0.2547 - -0.2702 - -0.2998 - -0.1953 - -0.2293 - -0.3284 + -0.2702 + -0.2998 + -0.1953 + -0.2293 + -0.3284 0.0480 - -0.0374 + -0.0374 0.3253 - -0.3434 - -0.3892 - -0.7178 - -0.4758 - -0.6794 - -0.8505 - -0.3512 - -0.4436 - -0.5101 - -0.4574 - -0.2696 - -0.1047 - -0.5745 - -0.2989 - -0.0063 + -0.3434 + -0.3892 + -0.7178 + -0.4758 + -0.6794 + -0.8505 + -0.3512 + -0.4436 + -0.5101 + -0.4574 + -0.2696 + -0.1047 + -0.5745 + -0.2989 + -0.0063 0.0088 - -0.1184 - -0.1506 - -0.4073 + -0.1184 + -0.1506 + -0.4073 0.2674 0.2896 0.0669 0.1166 - -0.1699 - -0.2518 - -0.0562 - -0.3269 - -0.0703 - -0.1046 - -0.4888 - -0.3524 - -0.2485 - -0.5870 - -0.4546 - -0.3970 - -0.2353 - -0.0352 - -0.2171 - -0.3754 - -0.4322 - -0.4572 - -0.4903 - -0.4518 - -0.6435 - -0.6304 - -0.4148 - -0.2892 - -0.4318 - -0.6010 - -0.4148 - -0.4315 - -0.3531 - -0.8053 - -0.4680 - -0.4263 -]; + -0.1699 + -0.2518 + -0.0562 + -0.3269 + -0.0703 + -0.1046 + -0.4888 + -0.3524 + -0.2485 + -0.5870 + -0.4546 + -0.3970 + -0.2353 + -0.0352 + -0.2171 + -0.3754 + -0.4322 + -0.4572 + -0.4903 + -0.4518 + -0.6435 + -0.6304 + -0.4148 + -0.2892 + -0.4318 + -0.6010 + -0.4148 + -0.4315 + -0.3531 + -0.8053 + -0.4680 + -0.4263 + ]; R =[ - -1.0750 - -1.1540 - -1.3682 - -1.4569 - -1.3490 - -1.4011 - -1.6486 - -1.6968 - -1.6976 - -1.2567 - -1.1392 - -0.7783 - -0.3021 - -0.0435 + -1.0750 + -1.1540 + -1.3682 + -1.4569 + -1.3490 + -1.4011 + -1.6486 + -1.6968 + -1.6976 + -1.2567 + -1.1392 + -0.7783 + -0.3021 + -0.0435 0.0066 - -0.0043 + -0.0043 0.1029 - -0.0628 - -0.5358 - -0.9627 - -1.1079 - -1.0918 - -0.9966 - -0.6223 - -0.3616 - -0.2711 - -0.0997 - -0.2810 - -0.3710 - -0.3167 - -0.5301 - -0.5826 - -0.3194 - -0.2713 - -0.5287 - -0.2432 + -0.0628 + -0.5358 + -0.9627 + -1.1079 + -1.0918 + -0.9966 + -0.6223 + -0.3616 + -0.2711 + -0.0997 + -0.2810 + -0.3710 + -0.3167 + -0.5301 + -0.5826 + -0.3194 + -0.2713 + -0.5287 + -0.2432 0.1098 0.5349 0.7094 @@ -667,15 +667,15 @@ R =[ 0.1741 0.0348 0.0771 - -0.1005 - -0.1518 - -0.1104 - -0.0681 - -0.0059 + -0.1005 + -0.1518 + -0.1104 + -0.0681 + -0.0059 0.0256 0.0404 - -0.1721 - -0.2002 + -0.1721 + -0.2002 0.0015 0.1249 0.3738 @@ -699,51 +699,51 @@ R =[ 0.3178 0.1472 0.0227 - -0.0799 - -0.0611 - -0.0140 + -0.0799 + -0.0611 + -0.0140 0.1132 0.1774 0.0782 0.0436 - -0.1596 - -0.2691 - -0.2895 - -0.3791 - -0.4020 - -0.4166 - -0.4037 - -0.3636 - -0.4075 - -0.4311 - -0.4470 - -0.5111 - -0.6274 - -0.7261 - -0.6974 - -0.5012 -]; + -0.1596 + -0.2691 + -0.2895 + -0.3791 + -0.4020 + -0.4166 + -0.4037 + -0.3636 + -0.4075 + -0.4311 + -0.4470 + -0.5111 + -0.6274 + -0.7261 + -0.6974 + -0.5012 + ]; W =[ - -14.8791 - -13.2300 - -13.5037 - -13.0249 - -11.2546 - -10.0148 - -8.8586 - -8.5739 - -7.7851 - -6.7136 - -5.5878 - -4.6881 - -3.8039 - -3.0366 - -2.7342 - -1.3135 - -0.7387 - -0.1131 - -0.2769 + -14.8791 + -13.2300 + -13.5037 + -13.0249 + -11.2546 + -10.0148 + -8.8586 + -8.5739 + -7.7851 + -6.7136 + -5.5878 + -4.6881 + -3.8039 + -3.0366 + -2.7342 + -1.3135 + -0.7387 + -0.1131 + -0.2769 0.8696 1.8855 2.3667 @@ -788,26 +788,26 @@ W =[ 1.6092 1.2741 0.2031 - -0.0236 - -0.1004 - -0.3034 - -1.0273 - -0.2205 + -0.0236 + -0.1004 + -0.3034 + -1.0273 + -0.2205 0.0458 0.2386 - -0.0977 - -0.3145 - -0.1416 - -0.7009 - -0.9082 - -0.8802 - -0.5644 - -0.5852 - -0.5346 + -0.0977 + -0.3145 + -0.1416 + -0.7009 + -0.9082 + -0.8802 + -0.5644 + -0.5852 + -0.5346 0.0652 0.1301 0.3444 - -0.3592 + -0.3592 0.8096 0.9644 1.0289 @@ -819,43 +819,43 @@ W =[ 0.6506 0.5531 0.2456 - -0.5351 - -0.8183 - -0.8967 - -0.7268 - -1.0738 - -1.2844 - -1.4338 - -1.6995 - -1.7085 - -2.2889 - -2.1018 - -2.4273 - -2.4609 - -2.1407 - -2.3847 - -3.1689 - -4.5581 - -4.1027 - -4.2436 - -4.8836 - -5.9660 - -4.9971 - -5.2386 - -5.6618 -]; + -0.5351 + -0.8183 + -0.8967 + -0.7268 + -1.0738 + -1.2844 + -1.4338 + -1.6995 + -1.7085 + -2.2889 + -2.1018 + -2.4273 + -2.4609 + -2.1407 + -2.3847 + -3.1689 + -4.5581 + -4.1027 + -4.2436 + -4.8836 + -5.9660 + -4.9971 + -5.2386 + -5.6618 + ]; Y =[ - -4.9347 - -4.6205 - -5.2198 - -4.5937 - -3.8015 - -3.6643 - -2.7239 - -2.7524 - -2.0634 - -1.0112 + -4.9347 + -4.6205 + -5.2198 + -4.5937 + -3.8015 + -3.6643 + -2.7239 + -2.7524 + -2.0634 + -1.0112 0.0530 0.7623 1.7927 @@ -863,12 +863,12 @@ Y =[ 2.4866 2.1456 2.1671 - -0.0254 - -1.6716 - -1.9673 - -1.6109 - -1.0292 - -0.1222 + -0.0254 + -1.6716 + -1.9673 + -1.6109 + -1.0292 + -0.1222 0.7329 1.1234 2.0603 @@ -894,28 +894,28 @@ Y =[ 0.7594 0.3695 0.0832 - -0.8118 - -1.4557 - -1.4850 - -1.2346 - -1.5696 - -1.3785 - -0.7682 - -2.0308 - -1.7778 - -1.7801 - -2.1711 - -1.7469 - -1.3413 - -1.3352 - -2.4390 - -1.2125 - -1.1695 - -1.0891 - -2.4753 - -1.3503 - -0.9412 - -0.1470 + -0.8118 + -1.4557 + -1.4850 + -1.2346 + -1.5696 + -1.3785 + -0.7682 + -2.0308 + -1.7778 + -1.7801 + -2.1711 + -1.7469 + -1.3413 + -1.3352 + -2.4390 + -1.2125 + -1.1695 + -1.0891 + -2.4753 + -1.3503 + -0.9412 + -0.1470 0.0026 0.1108 0.6890 @@ -936,32 +936,32 @@ Y =[ 2.4609 1.9534 0.9962 - -0.7904 - -1.1672 - -1.2586 - -1.3593 - -1.3443 - -0.9413 - -0.6023 - -0.4516 - -0.5129 - -0.8741 - -1.0784 - -1.4091 - -1.3627 - -1.5731 - -1.6037 - -1.8814 - -2.1482 - -1.3597 - -1.1855 - -1.1122 - -0.8424 - -0.9747 - -1.1385 - -1.4548 - -1.4284 - -1.4633 - -1.0621 - -0.7871 -]; + -0.7904 + -1.1672 + -1.2586 + -1.3593 + -1.3443 + -0.9413 + -0.6023 + -0.4516 + -0.5129 + -0.8741 + -1.0784 + -1.4091 + -1.3627 + -1.5731 + -1.6037 + -1.8814 + -2.1482 + -1.3597 + -1.1855 + -1.1122 + -0.8424 + -0.9747 + -1.1385 + -1.4548 + -1.4284 + -1.4633 + -1.0621 + -0.7871 + ]; diff --git a/mex/sources/estimation/tests/random_walk_metropolis_hastings_core.m b/mex/sources/estimation/tests/random_walk_metropolis_hastings_core.m index 14646c1578..5a61586123 100644 --- a/mex/sources/estimation/tests/random_walk_metropolis_hastings_core.m +++ b/mex/sources/estimation/tests/random_walk_metropolis_hastings_core.m @@ -94,12 +94,12 @@ varargin=myinputs.varargin; % Necessary only for remote computing! if whoiam - Parallel=myinputs.Parallel; - MasterName=myinputs.MasterName; - DyMo=myinputs.DyMo; - % initialize persistent variables in priordens() - priordens(xparam1,bayestopt_.pshape,bayestopt_.p6,bayestopt_.p7, ... - bayestopt_.p3,bayestopt_.p4,1); + Parallel=myinputs.Parallel; + MasterName=myinputs.MasterName; + DyMo=myinputs.DyMo; + % initialize persistent variables in priordens() + priordens(xparam1,bayestopt_.pshape,bayestopt_.p6,bayestopt_.p7, ... + bayestopt_.p3,bayestopt_.p4,1); end % (re)Set the penalty @@ -122,185 +122,185 @@ jscale = diag(bayestopt_.jscale); jloop=0; if options_.use_dll==1 - -%%%TEST%%% -oldoptions_console_mode=options_.console_mode; -%options_.console_mode=1; + + %%%TEST%%% + oldoptions_console_mode=options_.console_mode; + %options_.console_mode=1; - if exist('OCTAVE_VERSION') - oldoptions_console_mode=options_.console_mode; - options_.console_mode=1; - end - for b = fblck:nblck, - record.Seeds(b).Normal = randn('state'); - record.Seeds(b).Unifor = rand('state'); - end - % calculate draws and get last line run in the last MH block sub-array - [err irun] = logMHMCMCposterior( xparam1, varargin{2}, mexext, fblck, nblck, nruns, vv) - mexErrCheck('logMHMCMCposterior',err); - if irun<0 - error('Error in logMHMCMCposterior'); - end - for b = fblck:nblck, - record.Seeds(b).Normal = randn('state'); - record.Seeds(b).Unifor = rand('state'); - OutputFileName(b,:) = {[MhDirectoryName,filesep], [ModelName '_mh*_blck' int2str(b) '.mat']}; - end + if exist('OCTAVE_VERSION') + oldoptions_console_mode=options_.console_mode; + options_.console_mode=1; + end + for b = fblck:nblck, + record.Seeds(b).Normal = randn('state'); + record.Seeds(b).Unifor = rand('state'); + end + % calculate draws and get last line run in the last MH block sub-array + [err irun] = logMHMCMCposterior( xparam1, varargin{2}, mexext, fblck, nblck, nruns, vv) + mexErrCheck('logMHMCMCposterior',err); + if irun<0 + error('Error in logMHMCMCposterior'); + end + for b = fblck:nblck, + record.Seeds(b).Normal = randn('state'); + record.Seeds(b).Unifor = rand('state'); + OutputFileName(b,:) = {[MhDirectoryName,filesep], [ModelName '_mh*_blck' int2str(b) '.mat']}; + end - if exist('OCTAVE_VERSION') + if exist('OCTAVE_VERSION') + options_.console_mode=oldoptions_console_mode; + options_.console_mode=1; + end + record.AcceptationRates=record_AcceptationRates; + record.LastLogLiK=record_LastLogLiK; + record.LastParameters=record_LastParameters; options_.console_mode=oldoptions_console_mode; - options_.console_mode=1; - end - record.AcceptationRates=record_AcceptationRates; - record.LastLogLiK=record_LastLogLiK; - record.LastParameters=record_LastParameters; - options_.console_mode=oldoptions_console_mode; else - for b = fblck:nblck, - jloop=jloop+1; - randn('state',record.Seeds(b).Normal); - rand('state',record.Seeds(b).Unifor); - if (options_.load_mh_file~=0) & (fline(b)>1) & OpenOldFile(b) - load(['./' MhDirectoryName '/' ModelName '_mh' int2str(NewFile(b)) ... - '_blck' int2str(b) '.mat']) - x2 = [x2;zeros(InitSizeArray(b)-fline(b)+1,npar)]; - logpo2 = [logpo2;zeros(InitSizeArray(b)-fline(b)+1,1)]; - OpenOldFile(b) = 0; - else - x2 = zeros(InitSizeArray(b),npar); - logpo2 = zeros(InitSizeArray(b),1); - end - if exist('OCTAVE_VERSION') || options_.console_mode - diary off - disp(' ') - elseif whoiam - % keyboard; - waitbarString = ['Please wait... Metropolis-Hastings (' int2str(b) '/' int2str(options_.mh_nblck) ')...']; - % waitbarTitle=['Metropolis-Hastings ',options_.parallel(ThisMatlab).PcName]; - if options_.parallel(ThisMatlab).Local, - waitbarTitle=['Local ']; + for b = fblck:nblck, + jloop=jloop+1; + randn('state',record.Seeds(b).Normal); + rand('state',record.Seeds(b).Unifor); + if (options_.load_mh_file~=0) & (fline(b)>1) & OpenOldFile(b) + load(['./' MhDirectoryName '/' ModelName '_mh' int2str(NewFile(b)) ... + '_blck' int2str(b) '.mat']) + x2 = [x2;zeros(InitSizeArray(b)-fline(b)+1,npar)]; + logpo2 = [logpo2;zeros(InitSizeArray(b)-fline(b)+1,1)]; + OpenOldFile(b) = 0; else - waitbarTitle=[options_.parallel(ThisMatlab).PcName]; - end - fMessageStatus(0,whoiam,waitbarString, waitbarTitle, options_.parallel(ThisMatlab), MasterName, DyMo); - else, - hh = waitbar(0,['Please wait... Metropolis-Hastings (' int2str(b) '/' int2str(options_.mh_nblck) ')...']); - set(hh,'Name','Metropolis-Hastings'); - - end - isux = 0; - jsux = 0; - irun = fline(b); - j = 1; - load urand_1_1.csv - load paramdraws_1_1.csv - while j <= nruns(b) - par = feval(ProposalFun, ix2(b,:), d * jscale, n); - par=paramdraws_1_1(j,:); - if all( par(:) > mh_bounds(:,1) ) & all( par(:) < mh_bounds(:,2) ) - try - logpost = - feval(TargetFun, par(:),varargin{:}); - catch - logpost = -inf; - end - else - logpost = -inf; + x2 = zeros(InitSizeArray(b),npar); + logpo2 = zeros(InitSizeArray(b),1); end - lurand=log(urand_1_1(j)); -% if (logpost > -inf) && (log(rand) < logpost-ilogpo2(b)) - if (logpost > -inf) && (lurand < logpost-ilogpo2(b)) - x2(irun,:) = par; - ix2(b,:) = par; - logpo2(irun) = logpost; - ilogpo2(b) = logpost; - isux = isux + 1; - jsux = jsux + 1; - else - x2(irun,:) = ix2(b,:); - logpo2(irun) = ilogpo2(b); - end - prtfrc = j/nruns(b); if exist('OCTAVE_VERSION') || options_.console_mode - if mod(j, 10) == 0 - if exist('OCTAVE_VERSION') - printf('MH: Computing Metropolis-Hastings (chain %d/%d): %3.f%% done, acception rate: %3.f%%\r', b, nblck, 100 * prtfrc, 100 * isux / j); - else - fprintf(' MH: Computing Metropolis-Hastings (chain %d/%d): %3.f \b%% done, acceptance rate: %3.f \b%%\r', b, nblck, 100 * prtfrc, 100 * isux / j); - end - end - if mod(j,50)==0 & whoiam - % keyboard; - waitbarString = [ '(' int2str(b) '/' int2str(options_.mh_nblck) '), ' sprintf('accept. %3.f%%%%', 100 * isux/j)]; - fMessageStatus(prtfrc,whoiam,waitbarString, '', options_.parallel(ThisMatlab), MasterName, DyMo) - end - else - if mod(j, 3)==0 & ~whoiam - waitbar(prtfrc,hh,[ '(' int2str(b) '/' int2str(options_.mh_nblck) ') ' sprintf('%f done, acceptation rate %f',prtfrc,isux/j)]); - elseif mod(j,50)==0 & whoiam, - % keyboard; - waitbarString = [ '(' int2str(b) '/' int2str(options_.mh_nblck) ') ' sprintf('%f done, acceptation rate %f',prtfrc,isux/j)]; - fMessageStatus(prtfrc,whoiam,waitbarString, waitbarTitle, options_.parallel(ThisMatlab), MasterName, DyMo) - end + diary off + disp(' ') + elseif whoiam + % keyboard; + waitbarString = ['Please wait... Metropolis-Hastings (' int2str(b) '/' int2str(options_.mh_nblck) ')...']; + % waitbarTitle=['Metropolis-Hastings ',options_.parallel(ThisMatlab).PcName]; + if options_.parallel(ThisMatlab).Local, + waitbarTitle=['Local ']; + else + waitbarTitle=[options_.parallel(ThisMatlab).PcName]; + end + fMessageStatus(0,whoiam,waitbarString, waitbarTitle, options_.parallel(ThisMatlab), MasterName, DyMo); + else, + hh = waitbar(0,['Please wait... Metropolis-Hastings (' int2str(b) '/' int2str(options_.mh_nblck) ')...']); + set(hh,'Name','Metropolis-Hastings'); + end - - if (irun == InitSizeArray(b)) | (j == nruns(b)) % Now I save the simulations - save([MhDirectoryName '/' ModelName '_mh' int2str(NewFile(b)) '_blck' int2str(b) '.mat'],'x2','logpo2'); - fidlog = fopen([MhDirectoryName '/metropolis.log'],'a'); - fprintf(fidlog,['\n']); - fprintf(fidlog,['%% Mh' int2str(NewFile(b)) 'Blck' int2str(b) ' (' datestr(now,0) ')\n']); - fprintf(fidlog,' \n'); - fprintf(fidlog,[' Number of simulations.: ' int2str(length(logpo2)) '\n']); - fprintf(fidlog,[' Acceptation rate......: ' num2str(jsux/length(logpo2)) '\n']); - fprintf(fidlog,[' Posterior mean........:\n']); - for i=1:length(x2(1,:)) - fprintf(fidlog,[' params:' int2str(i) ': ' num2str(mean(x2(:,i))) '\n']); + isux = 0; + jsux = 0; + irun = fline(b); + j = 1; + load urand_1_1.csv + load paramdraws_1_1.csv + while j <= nruns(b) + par = feval(ProposalFun, ix2(b,:), d * jscale, n); + par=paramdraws_1_1(j,:); + if all( par(:) > mh_bounds(:,1) ) & all( par(:) < mh_bounds(:,2) ) + try + logpost = - feval(TargetFun, par(:),varargin{:}); + catch + logpost = -inf; + end + else + logpost = -inf; end - fprintf(fidlog,[' log2po:' num2str(mean(logpo2)) '\n']); - fprintf(fidlog,[' Minimum value.........:\n']);; - for i=1:length(x2(1,:)) - fprintf(fidlog,[' params:' int2str(i) ': ' num2str(min(x2(:,i))) '\n']); + lurand=log(urand_1_1(j)); + % if (logpost > -inf) && (log(rand) < logpost-ilogpo2(b)) + if (logpost > -inf) && (lurand < logpost-ilogpo2(b)) + x2(irun,:) = par; + ix2(b,:) = par; + logpo2(irun) = logpost; + ilogpo2(b) = logpost; + isux = isux + 1; + jsux = jsux + 1; + else + x2(irun,:) = ix2(b,:); + logpo2(irun) = ilogpo2(b); end - fprintf(fidlog,[' log2po:' num2str(min(logpo2)) '\n']); - fprintf(fidlog,[' Maximum value.........:\n']); - for i=1:length(x2(1,:)) - fprintf(fidlog,[' params:' int2str(i) ': ' num2str(max(x2(:,i))) '\n']); + prtfrc = j/nruns(b); + if exist('OCTAVE_VERSION') || options_.console_mode + if mod(j, 10) == 0 + if exist('OCTAVE_VERSION') + printf('MH: Computing Metropolis-Hastings (chain %d/%d): %3.f%% done, acception rate: %3.f%%\r', b, nblck, 100 * prtfrc, 100 * isux / j); + else + fprintf(' MH: Computing Metropolis-Hastings (chain %d/%d): %3.f \b%% done, acceptance rate: %3.f \b%%\r', b, nblck, 100 * prtfrc, 100 * isux / j); + end + end + if mod(j,50)==0 & whoiam + % keyboard; + waitbarString = [ '(' int2str(b) '/' int2str(options_.mh_nblck) '), ' sprintf('accept. %3.f%%%%', 100 * isux/j)]; + fMessageStatus(prtfrc,whoiam,waitbarString, '', options_.parallel(ThisMatlab), MasterName, DyMo) + end + else + if mod(j, 3)==0 & ~whoiam + waitbar(prtfrc,hh,[ '(' int2str(b) '/' int2str(options_.mh_nblck) ') ' sprintf('%f done, acceptation rate %f',prtfrc,isux/j)]); + elseif mod(j,50)==0 & whoiam, + % keyboard; + waitbarString = [ '(' int2str(b) '/' int2str(options_.mh_nblck) ') ' sprintf('%f done, acceptation rate %f',prtfrc,isux/j)]; + fMessageStatus(prtfrc,whoiam,waitbarString, waitbarTitle, options_.parallel(ThisMatlab), MasterName, DyMo) + end end - fprintf(fidlog,[' log2po:' num2str(max(logpo2)) '\n']); - fprintf(fidlog,' \n'); - fclose(fidlog); - jsux = 0; - if j == nruns(b) % I record the last draw... - record.LastParameters(b,:) = x2(end,:); - record.LastLogLiK(b) = logpo2(end); + + if (irun == InitSizeArray(b)) | (j == nruns(b)) % Now I save the simulations + save([MhDirectoryName '/' ModelName '_mh' int2str(NewFile(b)) '_blck' int2str(b) '.mat'],'x2','logpo2'); + fidlog = fopen([MhDirectoryName '/metropolis.log'],'a'); + fprintf(fidlog,['\n']); + fprintf(fidlog,['%% Mh' int2str(NewFile(b)) 'Blck' int2str(b) ' (' datestr(now,0) ')\n']); + fprintf(fidlog,' \n'); + fprintf(fidlog,[' Number of simulations.: ' int2str(length(logpo2)) '\n']); + fprintf(fidlog,[' Acceptation rate......: ' num2str(jsux/length(logpo2)) '\n']); + fprintf(fidlog,[' Posterior mean........:\n']); + for i=1:length(x2(1,:)) + fprintf(fidlog,[' params:' int2str(i) ': ' num2str(mean(x2(:,i))) '\n']); + end + fprintf(fidlog,[' log2po:' num2str(mean(logpo2)) '\n']); + fprintf(fidlog,[' Minimum value.........:\n']);; + for i=1:length(x2(1,:)) + fprintf(fidlog,[' params:' int2str(i) ': ' num2str(min(x2(:,i))) '\n']); + end + fprintf(fidlog,[' log2po:' num2str(min(logpo2)) '\n']); + fprintf(fidlog,[' Maximum value.........:\n']); + for i=1:length(x2(1,:)) + fprintf(fidlog,[' params:' int2str(i) ': ' num2str(max(x2(:,i))) '\n']); + end + fprintf(fidlog,[' log2po:' num2str(max(logpo2)) '\n']); + fprintf(fidlog,' \n'); + fclose(fidlog); + jsux = 0; + if j == nruns(b) % I record the last draw... + record.LastParameters(b,:) = x2(end,:); + record.LastLogLiK(b) = logpo2(end); + end + % size of next file in chain b + InitSizeArray(b) = min(nruns(b)-j,MAX_nruns); + % initialization of next file if necessary + if InitSizeArray(b) + x2 = zeros(InitSizeArray(b),npar); + logpo2 = zeros(InitSizeArray(b),1); + NewFile(b) = NewFile(b) + 1; + irun = 0; + end end - % size of next file in chain b - InitSizeArray(b) = min(nruns(b)-j,MAX_nruns); - % initialization of next file if necessary - if InitSizeArray(b) - x2 = zeros(InitSizeArray(b),npar); - logpo2 = zeros(InitSizeArray(b),1); - NewFile(b) = NewFile(b) + 1; - irun = 0; + j=j+1; + irun = irun + 1; + end% End of the simulations for one mh-block. + record.AcceptationRates(b) = isux/j; + if exist('OCTAVE_VERSION') || options_.console_mode + if exist('OCTAVE_VERSION') + printf('\n'); + else + fprintf('\n'); end + diary on; + elseif ~whoiam + close(hh); end - j=j+1; - irun = irun + 1; - end% End of the simulations for one mh-block. - record.AcceptationRates(b) = isux/j; - if exist('OCTAVE_VERSION') || options_.console_mode - if exist('OCTAVE_VERSION') - printf('\n'); - else - fprintf('\n'); - end - diary on; - elseif ~whoiam - close(hh); - end - record.Seeds(b).Normal = randn('state'); - record.Seeds(b).Unifor = rand('state'); - OutputFileName(jloop,:) = {[MhDirectoryName,filesep], [ModelName '_mh*_blck' int2str(b) '.mat']}; - end% End of the loop over the mh-blocks. + record.Seeds(b).Normal = randn('state'); + record.Seeds(b).Unifor = rand('state'); + OutputFileName(jloop,:) = {[MhDirectoryName,filesep], [ModelName '_mh*_blck' int2str(b) '.mat']}; + end% End of the loop over the mh-blocks. end % if use_dll myoutput.record = record; diff --git a/mex/sources/estimation/tests/rawdata_euromodel_1.m b/mex/sources/estimation/tests/rawdata_euromodel_1.m index 25bbc92414..6b9fee7203 100644 --- a/mex/sources/estimation/tests/rawdata_euromodel_1.m +++ b/mex/sources/estimation/tests/rawdata_euromodel_1.m @@ -1,25 +1,25 @@ C =[ - -7.4073 - -6.1860 - -6.5983 - -5.6088 - -5.0547 - -4.4774 - -3.8081 - -3.8425 - -2.4178 - -1.9835 - -1.0395 - -0.1583 - -0.0397 + -7.4073 + -6.1860 + -6.5983 + -5.6088 + -5.0547 + -4.4774 + -3.8081 + -3.8425 + -2.4178 + -1.9835 + -1.0395 + -0.1583 + -0.0397 0.3505 - -0.1879 - -0.0067 + -0.1879 + -0.0067 0.0478 - -1.2247 - -1.4349 - -0.7973 - -0.0461 + -1.2247 + -1.4349 + -0.7973 + -0.0461 0.5844 1.1372 1.3801 @@ -47,26 +47,26 @@ C =[ 1.5563 1.2308 0.3264 - -0.2208 - -0.2483 - -0.4082 - -1.0315 - -1.6030 - -1.5499 - -1.3777 - -2.1675 - -2.5138 - -2.8820 - -2.6958 - -2.4719 - -1.9854 - -1.7954 - -2.2362 - -1.0595 - -0.8808 - -0.8548 - -1.2839 - -0.1363 + -0.2208 + -0.2483 + -0.4082 + -1.0315 + -1.6030 + -1.5499 + -1.3777 + -2.1675 + -2.5138 + -2.8820 + -2.6958 + -2.4719 + -1.9854 + -1.7954 + -2.2362 + -1.0595 + -0.8808 + -0.8548 + -1.2839 + -0.1363 0.2104 0.8810 0.3555 @@ -93,31 +93,31 @@ C =[ 0.0847 0.0104 0.2115 - -0.6649 - -0.9625 - -0.7330 - -0.8664 - -1.4441 - -1.0179 - -1.2729 - -1.9539 - -1.4427 - -2.0371 - -1.9764 - -2.5654 - -2.8570 - -2.5842 - -3.0427 - -2.8312 - -2.3320 - -2.2768 - -2.1816 - -2.1043 - -1.8969 - -2.2388 - -2.1679 - -2.1172 -]; + -0.6649 + -0.9625 + -0.7330 + -0.8664 + -1.4441 + -1.0179 + -1.2729 + -1.9539 + -1.4427 + -2.0371 + -1.9764 + -2.5654 + -2.8570 + -2.5842 + -3.0427 + -2.8312 + -2.3320 + -2.2768 + -2.1816 + -2.1043 + -1.8969 + -2.2388 + -2.1679 + -2.1172 + ]; E =[ 0.6263 @@ -139,23 +139,23 @@ E =[ 1.2422 0.8084 0.4710 - -0.3704 - -0.6427 - -0.5323 - -0.5562 - -0.3651 - -0.4356 - -0.7164 - -0.5816 - -0.4635 - -0.8456 - -0.9708 - -0.7138 - -0.7499 - -0.6941 - -0.6656 - -0.2912 - -0.1650 + -0.3704 + -0.6427 + -0.5323 + -0.5562 + -0.3651 + -0.4356 + -0.7164 + -0.5816 + -0.4635 + -0.8456 + -0.9708 + -0.7138 + -0.7499 + -0.6941 + -0.6656 + -0.2912 + -0.1650 0.0774 0.2307 0.4484 @@ -163,34 +163,34 @@ E =[ 0.4653 0.2196 0.1736 - -0.1595 - -0.3918 - -0.4611 - -0.8493 - -0.7384 - -1.0604 - -1.2166 - -1.7187 - -1.6932 - -1.7830 - -1.7035 - -2.2079 - -2.3769 - -2.2511 - -2.1093 - -2.4638 - -2.4027 - -2.1313 - -1.9199 - -1.7941 - -1.4661 - -1.2269 - -1.0392 - -1.0725 - -0.7156 - -0.4778 - -0.4233 - -0.0409 + -0.1595 + -0.3918 + -0.4611 + -0.8493 + -0.7384 + -1.0604 + -1.2166 + -1.7187 + -1.6932 + -1.7830 + -1.7035 + -2.2079 + -2.3769 + -2.2511 + -2.1093 + -2.4638 + -2.4027 + -2.1313 + -1.9199 + -1.7941 + -1.4661 + -1.2269 + -1.0392 + -1.0725 + -0.7156 + -0.4778 + -0.4233 + -0.0409 0.1620 0.4280 0.5873 @@ -211,34 +211,34 @@ E =[ 1.9223 1.1777 0.4483 - -0.0661 - -0.4424 - -0.9000 - -1.1478 - -1.2047 - -1.1412 - -1.2383 - -1.1048 - -0.9716 - -0.9287 - -1.0057 - -1.0827 - -1.0200 - -1.0072 - -1.1740 - -1.2809 - -1.1086 - -0.9866 - -0.8947 - -0.5875 - -0.2329 + -0.0661 + -0.4424 + -0.9000 + -1.1478 + -1.2047 + -1.1412 + -1.2383 + -1.1048 + -0.9716 + -0.9287 + -1.0057 + -1.0827 + -1.0200 + -1.0072 + -1.1740 + -1.2809 + -1.1086 + -0.9866 + -0.8947 + -0.5875 + -0.2329 0.1493 0.4906 0.8400 1.0720 1.2648 1.5431 -]; + ]; I =[ 2.6617 @@ -253,29 +253,29 @@ I =[ 7.8923 9.4297 9.5010 - 10.0150 - 10.0413 + 10.0150 + 10.0413 9.6046 6.4766 5.9647 3.0114 0.5683 - -2.1226 - -2.1855 - -0.8329 - -1.5207 - -1.3419 - -1.7897 - -0.1476 + -2.1226 + -2.1855 + -0.8329 + -1.5207 + -1.3419 + -1.7897 + -0.1476 0.4675 - -1.6516 - -1.5419 - -1.3050 - -1.2451 - -0.7815 - -0.7796 - -0.3612 - -2.4072 + -1.6516 + -1.5419 + -1.3050 + -1.2451 + -0.7815 + -0.7796 + -0.3612 + -2.4072 1.1162 1.1383 3.4132 @@ -283,36 +283,36 @@ I =[ 2.8016 2.1734 0.9366 - -0.7050 - -1.5021 - -2.9868 - -6.0237 - -6.2589 - -6.9138 - -8.2340 - -9.2589 - -9.2465 - -9.6988 - -9.7782 - -10.5645 - -10.7544 - -13.1583 - -12.2718 - -12.0131 - -13.5983 - -12.3579 - -10.9146 - -11.1572 - -12.4935 - -9.4393 - -8.5535 - -7.3723 - -10.0169 - -6.6088 - -5.2045 - -4.1024 - -2.8472 - -1.3139 + -0.7050 + -1.5021 + -2.9868 + -6.0237 + -6.2589 + -6.9138 + -8.2340 + -9.2589 + -9.2465 + -9.6988 + -9.7782 + -10.5645 + -10.7544 + -13.1583 + -12.2718 + -12.0131 + -13.5983 + -12.3579 + -10.9146 + -11.1572 + -12.4935 + -9.4393 + -8.5535 + -7.3723 + -10.0169 + -6.6088 + -5.2045 + -4.1024 + -2.8472 + -1.3139 0.0477 1.5629 3.6947 @@ -324,30 +324,30 @@ I =[ 7.6576 8.8022 8.9611 - 10.0871 + 10.0871 9.4797 9.3964 - 10.0363 + 10.0363 8.6340 6.6522 4.4471 0.2854 - -2.1879 - -2.9879 - -4.1021 - -2.7713 - -2.2281 - -1.2908 - -0.3250 + -2.1879 + -2.9879 + -4.1021 + -2.7713 + -2.2281 + -1.2908 + -0.3250 0.6534 0.3942 0.3534 - -0.1532 - -1.7936 + -0.1532 + -1.7936 0.4909 0.3634 0.4290 - -0.9709 + -0.9709 0.1942 0.6103 1.4426 @@ -359,7 +359,7 @@ I =[ 5.3312 6.4402 6.6529 -]; + ]; L =[ 0.6263 @@ -381,23 +381,23 @@ L =[ 1.2422 0.8084 0.4710 - -0.3704 - -0.6427 - -0.5323 - -0.5562 - -0.3651 - -0.4356 - -0.7164 - -0.5816 - -0.4635 - -0.8456 - -0.9708 - -0.7138 - -0.7499 - -0.6941 - -0.6656 - -0.2912 - -0.1650 + -0.3704 + -0.6427 + -0.5323 + -0.5562 + -0.3651 + -0.4356 + -0.7164 + -0.5816 + -0.4635 + -0.8456 + -0.9708 + -0.7138 + -0.7499 + -0.6941 + -0.6656 + -0.2912 + -0.1650 0.0774 0.2307 0.4484 @@ -405,34 +405,34 @@ L =[ 0.4653 0.2196 0.1736 - -0.1595 - -0.3918 - -0.4611 - -0.8493 - -0.7384 - -1.0604 - -1.2166 - -1.7187 - -1.6932 - -1.7830 - -1.7035 - -2.2079 - -2.3769 - -2.2511 - -2.1093 - -2.4638 - -2.4027 - -2.1313 - -1.9199 - -1.7941 - -1.4661 - -1.2269 - -1.0392 - -1.0725 - -0.7156 - -0.4778 - -0.4233 - -0.0409 + -0.1595 + -0.3918 + -0.4611 + -0.8493 + -0.7384 + -1.0604 + -1.2166 + -1.7187 + -1.6932 + -1.7830 + -1.7035 + -2.2079 + -2.3769 + -2.2511 + -2.1093 + -2.4638 + -2.4027 + -2.1313 + -1.9199 + -1.7941 + -1.4661 + -1.2269 + -1.0392 + -1.0725 + -0.7156 + -0.4778 + -0.4233 + -0.0409 0.1620 0.4280 0.5873 @@ -453,48 +453,48 @@ L =[ 1.9223 1.1777 0.4483 - -0.0661 - -0.4424 - -0.9000 - -1.1478 - -1.2047 - -1.1412 - -1.2383 - -1.1048 - -0.9716 - -0.9287 - -1.0057 - -1.0827 - -1.0200 - -1.0072 - -1.1740 - -1.2809 - -1.1086 - -0.9866 - -0.8947 - -0.5875 - -0.2329 + -0.0661 + -0.4424 + -0.9000 + -1.1478 + -1.2047 + -1.1412 + -1.2383 + -1.1048 + -0.9716 + -0.9287 + -1.0057 + -1.0827 + -1.0200 + -1.0072 + -1.1740 + -1.2809 + -1.1086 + -0.9866 + -0.8947 + -0.5875 + -0.2329 0.1493 0.4906 0.8400 1.0720 1.2648 1.5431 -]; + ]; PIE =[ - -1.0113 - -0.8305 + -1.0113 + -0.8305 0.2332 - -0.8746 - -0.7978 - -0.9220 - -0.2487 - -0.7749 - -0.5460 - -0.5347 + -0.8746 + -0.7978 + -0.9220 + -0.2487 + -0.7749 + -0.5460 + -0.5347 0.5050 - -0.0334 + -0.0334 0.6756 0.8791 0.7267 @@ -516,7 +516,7 @@ PIE =[ 0.4025 0.4799 0.5981 - -0.1523 + -0.1523 0.4458 0.2182 0.9793 @@ -538,108 +538,108 @@ PIE =[ 0.3910 0.3301 0.2547 - -0.2702 - -0.2998 - -0.1953 - -0.2293 - -0.3284 + -0.2702 + -0.2998 + -0.1953 + -0.2293 + -0.3284 0.0480 - -0.0374 + -0.0374 0.3253 - -0.3434 - -0.3892 - -0.7178 - -0.4758 - -0.6794 - -0.8505 - -0.3512 - -0.4436 - -0.5101 - -0.4574 - -0.2696 - -0.1047 - -0.5745 - -0.2989 - -0.0063 + -0.3434 + -0.3892 + -0.7178 + -0.4758 + -0.6794 + -0.8505 + -0.3512 + -0.4436 + -0.5101 + -0.4574 + -0.2696 + -0.1047 + -0.5745 + -0.2989 + -0.0063 0.0088 - -0.1184 - -0.1506 - -0.4073 + -0.1184 + -0.1506 + -0.4073 0.2674 0.2896 0.0669 0.1166 - -0.1699 - -0.2518 - -0.0562 - -0.3269 - -0.0703 - -0.1046 - -0.4888 - -0.3524 - -0.2485 - -0.5870 - -0.4546 - -0.3970 - -0.2353 - -0.0352 - -0.2171 - -0.3754 - -0.4322 - -0.4572 - -0.4903 - -0.4518 - -0.6435 - -0.6304 - -0.4148 - -0.2892 - -0.4318 - -0.6010 - -0.4148 - -0.4315 - -0.3531 - -0.8053 - -0.4680 - -0.4263 -]; + -0.1699 + -0.2518 + -0.0562 + -0.3269 + -0.0703 + -0.1046 + -0.4888 + -0.3524 + -0.2485 + -0.5870 + -0.4546 + -0.3970 + -0.2353 + -0.0352 + -0.2171 + -0.3754 + -0.4322 + -0.4572 + -0.4903 + -0.4518 + -0.6435 + -0.6304 + -0.4148 + -0.2892 + -0.4318 + -0.6010 + -0.4148 + -0.4315 + -0.3531 + -0.8053 + -0.4680 + -0.4263 + ]; R =[ - -1.0750 - -1.1540 - -1.3682 - -1.4569 - -1.3490 - -1.4011 - -1.6486 - -1.6968 - -1.6976 - -1.2567 - -1.1392 - -0.7783 - -0.3021 - -0.0435 + -1.0750 + -1.1540 + -1.3682 + -1.4569 + -1.3490 + -1.4011 + -1.6486 + -1.6968 + -1.6976 + -1.2567 + -1.1392 + -0.7783 + -0.3021 + -0.0435 0.0066 - -0.0043 + -0.0043 0.1029 - -0.0628 - -0.5358 - -0.9627 - -1.1079 - -1.0918 - -0.9966 - -0.6223 - -0.3616 - -0.2711 - -0.0997 - -0.2810 - -0.3710 - -0.3167 - -0.5301 - -0.5826 - -0.3194 - -0.2713 - -0.5287 - -0.2432 + -0.0628 + -0.5358 + -0.9627 + -1.1079 + -1.0918 + -0.9966 + -0.6223 + -0.3616 + -0.2711 + -0.0997 + -0.2810 + -0.3710 + -0.3167 + -0.5301 + -0.5826 + -0.3194 + -0.2713 + -0.5287 + -0.2432 0.1098 0.5349 0.7094 @@ -667,15 +667,15 @@ R =[ 0.1741 0.0348 0.0771 - -0.1005 - -0.1518 - -0.1104 - -0.0681 - -0.0059 + -0.1005 + -0.1518 + -0.1104 + -0.0681 + -0.0059 0.0256 0.0404 - -0.1721 - -0.2002 + -0.1721 + -0.2002 0.0015 0.1249 0.3738 @@ -699,51 +699,51 @@ R =[ 0.3178 0.1472 0.0227 - -0.0799 - -0.0611 - -0.0140 + -0.0799 + -0.0611 + -0.0140 0.1132 0.1774 0.0782 0.0436 - -0.1596 - -0.2691 - -0.2895 - -0.3791 - -0.4020 - -0.4166 - -0.4037 - -0.3636 - -0.4075 - -0.4311 - -0.4470 - -0.5111 - -0.6274 - -0.7261 - -0.6974 - -0.5012 -]; + -0.1596 + -0.2691 + -0.2895 + -0.3791 + -0.4020 + -0.4166 + -0.4037 + -0.3636 + -0.4075 + -0.4311 + -0.4470 + -0.5111 + -0.6274 + -0.7261 + -0.6974 + -0.5012 + ]; W =[ - -14.8791 - -13.2300 - -13.5037 - -13.0249 - -11.2546 - -10.0148 - -8.8586 - -8.5739 - -7.7851 - -6.7136 - -5.5878 - -4.6881 - -3.8039 - -3.0366 - -2.7342 - -1.3135 - -0.7387 - -0.1131 - -0.2769 + -14.8791 + -13.2300 + -13.5037 + -13.0249 + -11.2546 + -10.0148 + -8.8586 + -8.5739 + -7.7851 + -6.7136 + -5.5878 + -4.6881 + -3.8039 + -3.0366 + -2.7342 + -1.3135 + -0.7387 + -0.1131 + -0.2769 0.8696 1.8855 2.3667 @@ -788,26 +788,26 @@ W =[ 1.6092 1.2741 0.2031 - -0.0236 - -0.1004 - -0.3034 - -1.0273 - -0.2205 + -0.0236 + -0.1004 + -0.3034 + -1.0273 + -0.2205 0.0458 0.2386 - -0.0977 - -0.3145 - -0.1416 - -0.7009 - -0.9082 - -0.8802 - -0.5644 - -0.5852 - -0.5346 + -0.0977 + -0.3145 + -0.1416 + -0.7009 + -0.9082 + -0.8802 + -0.5644 + -0.5852 + -0.5346 0.0652 0.1301 0.3444 - -0.3592 + -0.3592 0.8096 0.9644 1.0289 @@ -819,43 +819,43 @@ W =[ 0.6506 0.5531 0.2456 - -0.5351 - -0.8183 - -0.8967 - -0.7268 - -1.0738 - -1.2844 - -1.4338 - -1.6995 - -1.7085 - -2.2889 - -2.1018 - -2.4273 - -2.4609 - -2.1407 - -2.3847 - -3.1689 - -4.5581 - -4.1027 - -4.2436 - -4.8836 - -5.9660 - -4.9971 - -5.2386 - -5.6618 -]; + -0.5351 + -0.8183 + -0.8967 + -0.7268 + -1.0738 + -1.2844 + -1.4338 + -1.6995 + -1.7085 + -2.2889 + -2.1018 + -2.4273 + -2.4609 + -2.1407 + -2.3847 + -3.1689 + -4.5581 + -4.1027 + -4.2436 + -4.8836 + -5.9660 + -4.9971 + -5.2386 + -5.6618 + ]; Y =[ - -4.9347 - -4.6205 - -5.2198 - -4.5937 - -3.8015 - -3.6643 - -2.7239 - -2.7524 - -2.0634 - -1.0112 + -4.9347 + -4.6205 + -5.2198 + -4.5937 + -3.8015 + -3.6643 + -2.7239 + -2.7524 + -2.0634 + -1.0112 0.0530 0.7623 1.7927 @@ -863,12 +863,12 @@ Y =[ 2.4866 2.1456 2.1671 - -0.0254 - -1.6716 - -1.9673 - -1.6109 - -1.0292 - -0.1222 + -0.0254 + -1.6716 + -1.9673 + -1.6109 + -1.0292 + -0.1222 0.7329 1.1234 2.0603 @@ -894,28 +894,28 @@ Y =[ 0.7594 0.3695 0.0832 - -0.8118 - -1.4557 - -1.4850 - -1.2346 - -1.5696 - -1.3785 - -0.7682 - -2.0308 - -1.7778 - -1.7801 - -2.1711 - -1.7469 - -1.3413 - -1.3352 - -2.4390 - -1.2125 - -1.1695 - -1.0891 - -2.4753 - -1.3503 - -0.9412 - -0.1470 + -0.8118 + -1.4557 + -1.4850 + -1.2346 + -1.5696 + -1.3785 + -0.7682 + -2.0308 + -1.7778 + -1.7801 + -2.1711 + -1.7469 + -1.3413 + -1.3352 + -2.4390 + -1.2125 + -1.1695 + -1.0891 + -2.4753 + -1.3503 + -0.9412 + -0.1470 0.0026 0.1108 0.6890 @@ -936,32 +936,32 @@ Y =[ 2.4609 1.9534 0.9962 - -0.7904 - -1.1672 - -1.2586 - -1.3593 - -1.3443 - -0.9413 - -0.6023 - -0.4516 - -0.5129 - -0.8741 - -1.0784 - -1.4091 - -1.3627 - -1.5731 - -1.6037 - -1.8814 - -2.1482 - -1.3597 - -1.1855 - -1.1122 - -0.8424 - -0.9747 - -1.1385 - -1.4548 - -1.4284 - -1.4633 - -1.0621 - -0.7871 -]; + -0.7904 + -1.1672 + -1.2586 + -1.3593 + -1.3443 + -0.9413 + -0.6023 + -0.4516 + -0.5129 + -0.8741 + -1.0784 + -1.4091 + -1.3627 + -1.5731 + -1.6037 + -1.8814 + -2.1482 + -1.3597 + -1.1855 + -1.1122 + -0.8424 + -0.9747 + -1.1385 + -1.4548 + -1.4284 + -1.4633 + -1.0621 + -0.7871 + ]; diff --git a/mex/sources/k_order_perturbation/tests/first_order.m b/mex/sources/k_order_perturbation/tests/first_order.m index f46631c220..a282ae3c3b 100644 --- a/mex/sources/k_order_perturbation/tests/first_order.m +++ b/mex/sources/k_order_perturbation/tests/first_order.m @@ -51,20 +51,20 @@ off=off+ nu; n= ypart.ny+ypart.nboth; %TwoDMatrix matD=zeros(n,n); -% matD.place(fypzero,0,0); +% matD.place(fypzero,0,0); matD(1:n-ypart.nboth,1:ypart.npred)= fypzero; -% matD.place(fybzero,0,ypart.npred); +% matD.place(fybzero,0,ypart.npred); matD(1:n-ypart.nboth,ypart.npred+1:ypart.npred+ypart.nboth)=fybzero; -% matD.place(fyplus,0,ypart.nys()+ypart.nstat); +% matD.place(fyplus,0,ypart.nys()+ypart.nstat); matD(1:n-ypart.nboth,ypart.nys+ypart.nstat+1:ypart.nys+ypart.nstat+ypart.nyss)=fyplus; for i=1:ypart.nboth matD(ypart.ny()+i,ypart.npred+i)= 1.0; end matE=[fymins, fyszero, zeros(n-ypart.nboth,ypart.nboth), fyfzero; zeros(ypart.nboth,n)]; -% matE.place(fymins; -% matE.place(fyszero,0,ypart.nys()); -% matE.place(fyfzero,0,ypart.nys()+ypart.nstat+ypart.nboth); +% matE.place(fymins; +% matE.place(fyszero,0,ypart.nys()); +% matE.place(fyfzero,0,ypart.nys()+ypart.nstat+ypart.nboth); for i= 1:ypart.nboth matE(ypart.ny()+i,ypart.nys()+ypart.nstat+i)= -1.0; @@ -72,39 +72,39 @@ end matE=-matE; %matE.mult(-1.0); % vsl=zeros(n,n); -% vsr=zeros(n,n); -% lwork= 100*n+16; -% work=zeros(1,lwork); -% bwork=zeros(1,n); +% vsr=zeros(n,n); +% lwork= 100*n+16; +% work=zeros(1,lwork); +% bwork=zeros(1,n); %int info; -% LAPACK_dgges("N","V","S",order_eigs,&n,matE.getData().base(),&n, -% matD.getData().base(),&n,&sdim,alphar.base(),alphai.base(), -% beta.base(),vsl.getData().base(),&n,vsr.getData().base(),&n, -% work.base(),&lwork,&(bwork[0]),&info); +% LAPACK_dgges("N","V","S",order_eigs,&n,matE.getData().base(),&n, +% matD.getData().base(),&n,&sdim,alphar.base(),alphai.base(), +% beta.base(),vsl.getData().base(),&n,vsr.getData().base(),&n, +% work.base(),&lwork,&(bwork[0]),&info); [matE1,matD1,vsr,sdim,dr.eigval,info] = mjdgges(matE,matD,1); bk_cond= (sdim==ypart.nys); -% ConstGeneralMatrix z11(vsr,0,0,ypart.nys(),ypart.nys()); +% ConstGeneralMatrix z11(vsr,0,0,ypart.nys(),ypart.nys()); z11=vsr(1:ypart.nys,1:ypart.nys); -% ConstGeneralMatrix z12(vsr,0,ypart.nys(),ypart.nys(),n-ypart.nys()); +% ConstGeneralMatrix z12(vsr,0,ypart.nys(),ypart.nys(),n-ypart.nys()); z12=vsr(1:ypart.nys(),ypart.nys+1:end);%, n-ypart.nys); - % ConstGeneralMatrix z21(vsr,ypart.nys(),0,n-ypart.nys(),ypart.nys()); + % ConstGeneralMatrix z21(vsr,ypart.nys(),0,n-ypart.nys(),ypart.nys()); z21=vsr(ypart.nys+1:end,1:ypart.nys); -% ConstGeneralMatrix z22(vsr,ypart.nys(),ypart.nys(),n-ypart.nys(),n-ypart.nys()); +% ConstGeneralMatrix z22(vsr,ypart.nys(),ypart.nys(),n-ypart.nys(),n-ypart.nys()); z22=vsr(ypart.nys+1:end,ypart.nys+1:end); -% GeneralMatrix sfder(z12,"transpose"); +% GeneralMatrix sfder(z12,"transpose"); sfder=z12';%,"transpose"); - % z22.multInvLeftTrans(sfder); + % z22.multInvLeftTrans(sfder); sfder=z22'\sfder; sfder=-sfder;% .mult(-1); %s11(matE,0,0,ypart.nys(),ypart.nys()); s11=matE1(1:ypart.nys,1:ypart.nys); -% t11=(matD1,0,0,ypart.nys(),ypart.nys()); +% t11=(matD1,0,0,ypart.nys(),ypart.nys()); t11=matD1(1:ypart.nys,1:ypart.nys); dumm=(s11');%,"transpose"); %z11.multInvLeftTrans(dumm); @@ -115,15 +115,15 @@ preder=t11\preder; %preder.multLeft(z11); preder= z11*preder; -% gy.place(preder,ypart.nstat,0); -% gy=(zeros(ypart.nstat,size(preder,2)) ;preder); -% sder(sfder,0,0,ypart.nstat,ypart.nys()); +% gy.place(preder,ypart.nstat,0); +% gy=(zeros(ypart.nstat,size(preder,2)) ;preder); +% sder(sfder,0,0,ypart.nstat,ypart.nys()); sder=sfder(1:ypart.nstat,1:ypart.nys); -% gy.place(sder,0,0); -% gy(1:ypart.nstat, 1:ypart.nys)=sder; +% gy.place(sder,0,0); +% gy(1:ypart.nstat, 1:ypart.nys)=sder; % gy=[sder;preder]; -% fder(sfder,ypart.nstat+ypart.nboth,0,ypart.nforw,ypart.nys()); +% fder(sfder,ypart.nstat+ypart.nboth,0,ypart.nforw,ypart.nys()); fder=sfder(ypart.nstat+ypart.nboth+1:ypart.nstat+ypart.nboth+ypart.nforw,1:ypart.nys); -% gy.place(fder,ypart.nstat+ypart.nys(),0); -% gy(ypart.nstat+ypart.nys,1)=fder; +% gy.place(fder,ypart.nstat+ypart.nys(),0); +% gy(ypart.nstat+ypart.nys,1)=fder; gy=[sder;preder;fder]; diff --git a/tests/AIM/data_ca1.m b/tests/AIM/data_ca1.m index c28fae1a28..ca003056bd 100644 --- a/tests/AIM/data_ca1.m +++ b/tests/AIM/data_ca1.m @@ -1,98 +1,98 @@ data = [0.928467646476 11.8716889412 20 0.418037507392 0.227382377518 ... --0.705994063083 11.7522582094 21.25 1.09254424511 -1.29488274994 ... --0.511895351926 9.68144025625 17.25 -1.66150408407 0.331508393098 ... --0.990955971267 10.0890781236 17 1.43016275252 -2.43589670141 ... --0.981233061806 12.1094840679 18.25 2.91293288733 -0.790246576864 ... --0.882182844512 8.54559460406 15 0.419579139481 0.358729719566 ... --0.930893002836 6.19238374422 12.5 -1.48847457959 0.739779938797 ... -1.53158206947 2.76544271886 11.5 -0.336216769682 0.455559918769 ... -2.2659052834 5.47418162513 11 0.306436789767 -0.0707985731221 ... -1.05419803797 6.35698426189 11 0.140700250477 0.620401487202 ... -1.20161076793 3.4253301593 11 0.461296492351 0.14354323987 ... -1.73934077971 4.70926070322 11.5 1.35798282982 0.38564694435 ... -1.71735262584 3.54232079749 12.5 2.9097529155 -0.804308583301 ... -0.426343657844 3.32719108897 13 1.64214862652 -1.18214664701 ... -1.67751812324 2.93444727338 11.25 0.344434910651 -1.6529373719 ... -1.37013301099 4.72303361923 11.75 2.61511526582 0.327684243041 ... -0.281231073781 4.4893853071 10.5 1.17043449257 1.12855106649 ... -1.53638992834 3.7325309699 10.25 -0.683947046728 0.11943538737 ... -1.68081431462 3.34729969129 10 1.41159342106 -1.59065680853 ... --0.343321601133 5.05563513564 12 1.75117366498 -2.40127764642 ... -0.873415608666 3.2779996255 10.25 -1.39895866711 0.0971444398216 ... -0.26399696544 4.78229419828 9.75 0.0914692438124 0.299310457612 ... --0.562233624818 3.88598638237 9.75 -0.0505384765105 0.332826708151 ... -2.15161914936 3.84859710132 8.75 -3.44811080489 0.789138678784 ... -1.2345093726 5.62225030942 9.5 -0.366945407434 2.32974981198 ... -1.62554967459 4.24667132831 10 -0.800958371402 0.0293183770935 ... -1.33035402527 2.75248979249 9.75 -0.855723113225 0.852493939813 ... -1.52078814077 3.53415985826 9.75 -3.37963469203 -1.05133958119 ... -1.16704983697 4.92754079464 10.75 -3.0142303324 0.459907431978 ... -0.277213572101 4.55532133037 11.75 -0.851995599415 2.03242034852 ... -0.842215068977 3.11164509647 12.25 -1.08290421696 0.014323281961 ... -1.05325028606 4.92882647578 13.5 -1.1953883867 0.706764750654 ... -0.453051253568 6.82998950103 13.5 0.111803656462 0.088462593153 ... -0.199885995525 5.82643354662 13.5 -0.920501518421 -0.26504958666 ... -0.137907999624 2.66076369132 13.5 -1.17122929812 -0.995642430514 ... -0.721949686709 5.70497876823 14.25 1.19378169018 -1.10644839651 ... --0.418465249225 3.75861110232 14.75 -1.03131674824 0.188507675831 ... --0.644028342116 4.15104788154 13.75 -1.48911756546 0.204560913792 ... --0.848213852668 5.65580324027 12.75 0.677011703877 -0.849628054542 ... --1.51954076928 11.4866911266 11.25 -0.446024680774 -0.456342350765 ... -0.265275055215 2.85472749592 9.75 -0.598778202436 -0.907311640831 ... -0.356162529063 2.29614015658 9.5 -0.46820788432 -1.22130883441 ... -0.368308864363 -0.539083504685 8 -0.781333991956 0.374007246518 ... --0.145751412732 1.61507621789 8.25 3.68291932628 1.32438399845 ... -0.285457283664 2.14334055993 7 1.42819405379 -0.00818660844123 ... -0.372390129412 1.60000213334 6.25 0.626106424052 -0.10136772765 ... -0.382720203063 1.72614243263 7.25 4.89631941021 -1.10060711916 ... -0.737957515573 2.90430582851 6 -0.0422721010314 0.4178952497 ... -0.649532581668 0.657135682543 6 0.692066153971 0.422299120276 ... -0.627159201987 1.70352689913 5.75 2.62066711305 -1.29237304034 ... -0.905441299817 1.95663197267 5.5 1.5949697565 -0.27115830703 ... -1.49322577898 -2.08741765309 6.25 1.23027694802 0.418336889527 ... -1.48750731567 -1.57274121871 8 3.01660550994 -0.893958254365 ... -1.39783858087 2.22623066426 7 -0.80842319214 1.47625453886 ... -0.89274836317 1.30378081742 8 -0.249485058661 0.159871204185 ... -0.920652246088 4.1437741965 9.75 2.8204453623 0.178149239655 ... --0.00264276644799 3.07989972052 8.75 -2.56342461535 2.105998353 ... -0.0198190461681 0.766283759256 8 -1.15838865989 1.56888883418 ... -0.440050515311 0.127570085801 7.5 0.0400753569995 0.028914333532 ... -0.129536637901 1.78174141526 6.75 0.959943962785 0.307781224401 ... -0.398549827172 3.03606770667 6.5 -0.340209794742 0.100979469478 ... -1.17174775425 0.629625188037 5.75 0.403003686814 0.902394579377 ... -0.991163981251 2.50862910684 4.75 -1.44963996982 1.16150986945 ... -0.967603566096 2.12003739013 4.75 0.610846030775 -0.889994896068 ... -1.14689383604 1.24185011459 4.75 2.01098091308 -1.73846431001 ... -1.32593824054 0.990713820685 4.75 -0.0955142989332 -0.0369257308362 ... -0.861135002644 -0.24744943605 6 1.72793107135 -0.691506789639 ... -1.26870850151 2.09844764887 6.5 1.50720217572 -1.31399187077 ... -0.260364987715 1.10650139716 6.5 1.13659047496 0.0720441664643 ... -1.09731242214 0.490796381346 7.25 4.59123894147 -2.14073070763 ... -1.63792841781 0.612652594286 6.75 1.79604605035 -0.644363995357 ... -1.48465576034 0.978295808687 6.75 -2.00753620902 1.39437534964 ... -1.0987608663 4.25212569087 6.25 -2.58901196498 2.56054320803 ... -1.42592178132 2.76984518311 6.25 0.888195752358 1.03114549274 ... -1.52958239462 1.31795955491 6.5 -0.902907564082 -0.0952198893776 ... -1.0170168994 2.14733589918 7 -1.3054866978 2.68803738466 ... -0.723253652257 3.43552889347 7.5 1.8213700853 0.592593586195 ... -1.24720806008 3.87383806577 7.5 0.0522300654168 0.988871238698 ... -0.482531471239 2.67793287032 7.5 2.9693944293 -0.108591166081 ... -0.154056100439 0.927269031704 6.75 0.119222057561 3.30489209451 ... -0.0694865769274 6.65916526788 6.25 0.889014476084 -2.83976849035 ... --0.121267434867 0.341442615696 5.25 0.323053239216 -3.49289229012 ... -0.726473690375 -3.5423730964 4 2.19149290449 -3.20855054004 ... -1.39271709108 2.63121085718 3.75 0.88406577736 0.75622580197 ... -1.07502077727 5.88578836799 4.25 -2.55088273352 2.89018116374 ... -0.759049251607 4.24703604223 4.5 0.575687665685 -0.388292506167 ... -]; - + -0.705994063083 11.7522582094 21.25 1.09254424511 -1.29488274994 ... + -0.511895351926 9.68144025625 17.25 -1.66150408407 0.331508393098 ... + -0.990955971267 10.0890781236 17 1.43016275252 -2.43589670141 ... + -0.981233061806 12.1094840679 18.25 2.91293288733 -0.790246576864 ... + -0.882182844512 8.54559460406 15 0.419579139481 0.358729719566 ... + -0.930893002836 6.19238374422 12.5 -1.48847457959 0.739779938797 ... + 1.53158206947 2.76544271886 11.5 -0.336216769682 0.455559918769 ... + 2.2659052834 5.47418162513 11 0.306436789767 -0.0707985731221 ... + 1.05419803797 6.35698426189 11 0.140700250477 0.620401487202 ... + 1.20161076793 3.4253301593 11 0.461296492351 0.14354323987 ... + 1.73934077971 4.70926070322 11.5 1.35798282982 0.38564694435 ... + 1.71735262584 3.54232079749 12.5 2.9097529155 -0.804308583301 ... + 0.426343657844 3.32719108897 13 1.64214862652 -1.18214664701 ... + 1.67751812324 2.93444727338 11.25 0.344434910651 -1.6529373719 ... + 1.37013301099 4.72303361923 11.75 2.61511526582 0.327684243041 ... + 0.281231073781 4.4893853071 10.5 1.17043449257 1.12855106649 ... + 1.53638992834 3.7325309699 10.25 -0.683947046728 0.11943538737 ... + 1.68081431462 3.34729969129 10 1.41159342106 -1.59065680853 ... + -0.343321601133 5.05563513564 12 1.75117366498 -2.40127764642 ... + 0.873415608666 3.2779996255 10.25 -1.39895866711 0.0971444398216 ... + 0.26399696544 4.78229419828 9.75 0.0914692438124 0.299310457612 ... + -0.562233624818 3.88598638237 9.75 -0.0505384765105 0.332826708151 ... + 2.15161914936 3.84859710132 8.75 -3.44811080489 0.789138678784 ... + 1.2345093726 5.62225030942 9.5 -0.366945407434 2.32974981198 ... + 1.62554967459 4.24667132831 10 -0.800958371402 0.0293183770935 ... + 1.33035402527 2.75248979249 9.75 -0.855723113225 0.852493939813 ... + 1.52078814077 3.53415985826 9.75 -3.37963469203 -1.05133958119 ... + 1.16704983697 4.92754079464 10.75 -3.0142303324 0.459907431978 ... + 0.277213572101 4.55532133037 11.75 -0.851995599415 2.03242034852 ... + 0.842215068977 3.11164509647 12.25 -1.08290421696 0.014323281961 ... + 1.05325028606 4.92882647578 13.5 -1.1953883867 0.706764750654 ... + 0.453051253568 6.82998950103 13.5 0.111803656462 0.088462593153 ... + 0.199885995525 5.82643354662 13.5 -0.920501518421 -0.26504958666 ... + 0.137907999624 2.66076369132 13.5 -1.17122929812 -0.995642430514 ... + 0.721949686709 5.70497876823 14.25 1.19378169018 -1.10644839651 ... + -0.418465249225 3.75861110232 14.75 -1.03131674824 0.188507675831 ... + -0.644028342116 4.15104788154 13.75 -1.48911756546 0.204560913792 ... + -0.848213852668 5.65580324027 12.75 0.677011703877 -0.849628054542 ... + -1.51954076928 11.4866911266 11.25 -0.446024680774 -0.456342350765 ... + 0.265275055215 2.85472749592 9.75 -0.598778202436 -0.907311640831 ... + 0.356162529063 2.29614015658 9.5 -0.46820788432 -1.22130883441 ... + 0.368308864363 -0.539083504685 8 -0.781333991956 0.374007246518 ... + -0.145751412732 1.61507621789 8.25 3.68291932628 1.32438399845 ... + 0.285457283664 2.14334055993 7 1.42819405379 -0.00818660844123 ... + 0.372390129412 1.60000213334 6.25 0.626106424052 -0.10136772765 ... + 0.382720203063 1.72614243263 7.25 4.89631941021 -1.10060711916 ... + 0.737957515573 2.90430582851 6 -0.0422721010314 0.4178952497 ... + 0.649532581668 0.657135682543 6 0.692066153971 0.422299120276 ... + 0.627159201987 1.70352689913 5.75 2.62066711305 -1.29237304034 ... + 0.905441299817 1.95663197267 5.5 1.5949697565 -0.27115830703 ... + 1.49322577898 -2.08741765309 6.25 1.23027694802 0.418336889527 ... + 1.48750731567 -1.57274121871 8 3.01660550994 -0.893958254365 ... + 1.39783858087 2.22623066426 7 -0.80842319214 1.47625453886 ... + 0.89274836317 1.30378081742 8 -0.249485058661 0.159871204185 ... + 0.920652246088 4.1437741965 9.75 2.8204453623 0.178149239655 ... + -0.00264276644799 3.07989972052 8.75 -2.56342461535 2.105998353 ... + 0.0198190461681 0.766283759256 8 -1.15838865989 1.56888883418 ... + 0.440050515311 0.127570085801 7.5 0.0400753569995 0.028914333532 ... + 0.129536637901 1.78174141526 6.75 0.959943962785 0.307781224401 ... + 0.398549827172 3.03606770667 6.5 -0.340209794742 0.100979469478 ... + 1.17174775425 0.629625188037 5.75 0.403003686814 0.902394579377 ... + 0.991163981251 2.50862910684 4.75 -1.44963996982 1.16150986945 ... + 0.967603566096 2.12003739013 4.75 0.610846030775 -0.889994896068 ... + 1.14689383604 1.24185011459 4.75 2.01098091308 -1.73846431001 ... + 1.32593824054 0.990713820685 4.75 -0.0955142989332 -0.0369257308362 ... + 0.861135002644 -0.24744943605 6 1.72793107135 -0.691506789639 ... + 1.26870850151 2.09844764887 6.5 1.50720217572 -1.31399187077 ... + 0.260364987715 1.10650139716 6.5 1.13659047496 0.0720441664643 ... + 1.09731242214 0.490796381346 7.25 4.59123894147 -2.14073070763 ... + 1.63792841781 0.612652594286 6.75 1.79604605035 -0.644363995357 ... + 1.48465576034 0.978295808687 6.75 -2.00753620902 1.39437534964 ... + 1.0987608663 4.25212569087 6.25 -2.58901196498 2.56054320803 ... + 1.42592178132 2.76984518311 6.25 0.888195752358 1.03114549274 ... + 1.52958239462 1.31795955491 6.5 -0.902907564082 -0.0952198893776 ... + 1.0170168994 2.14733589918 7 -1.3054866978 2.68803738466 ... + 0.723253652257 3.43552889347 7.5 1.8213700853 0.592593586195 ... + 1.24720806008 3.87383806577 7.5 0.0522300654168 0.988871238698 ... + 0.482531471239 2.67793287032 7.5 2.9693944293 -0.108591166081 ... + 0.154056100439 0.927269031704 6.75 0.119222057561 3.30489209451 ... + 0.0694865769274 6.65916526788 6.25 0.889014476084 -2.83976849035 ... + -0.121267434867 0.341442615696 5.25 0.323053239216 -3.49289229012 ... + 0.726473690375 -3.5423730964 4 2.19149290449 -3.20855054004 ... + 1.39271709108 2.63121085718 3.75 0.88406577736 0.75622580197 ... + 1.07502077727 5.88578836799 4.25 -2.55088273352 2.89018116374 ... + 0.759049251607 4.24703604223 4.5 0.575687665685 -0.388292506167 ... + ]; + data = reshape(data,5,86)'; y_obs = data(:,1); pie_obs = data(:,2); R_obs = data(:,3); de = data(:,4); dq = data(:,5); - + %Country: Canada %Sample Range: 1981:2 to 2002:3 %Observations: 86 diff --git a/tests/AIM/fsdat.m b/tests/AIM/fsdat.m index aba209b908..ef1279c0b3 100644 --- a/tests/AIM/fsdat.m +++ b/tests/AIM/fsdat.m @@ -1,198 +1,198 @@ data_q = [ -18.02 1474.5 150.2 -17.94 1538.2 150.9 -18.01 1584.5 151.4 -18.42 1644.1 152 -18.73 1678.6 152.7 -19.46 1693.1 153.3 -19.55 1724 153.9 -19.56 1758.2 154.7 -19.79 1760.6 155.4 -19.77 1779.2 156 -19.82 1778.8 156.6 -20.03 1790.9 157.3 -20.12 1846 158 -20.1 1882.6 158.6 -20.14 1897.3 159.2 -20.22 1887.4 160 -20.27 1858.2 160.7 -20.34 1849.9 161.4 -20.39 1848.5 162 -20.42 1868.9 162.8 -20.47 1905.6 163.6 -20.56 1959.6 164.3 -20.62 1994.4 164.9 -20.78 2020.1 165.7 -21 2030.5 166.5 -21.2 2023.6 167.2 -21.33 2037.7 167.9 -21.62 2033.4 168.7 -21.71 2066.2 169.5 -22.01 2077.5 170.2 -22.15 2071.9 170.9 -22.27 2094 171.7 -22.29 2070.8 172.5 -22.56 2012.6 173.1 -22.64 2024.7 173.8 -22.77 2072.3 174.5 -22.88 2120.6 175.3 -22.92 2165 176.045 -22.91 2223.3 176.727 -22.94 2221.4 177.481 -23.03 2230.95 178.268 -23.13 2279.22 179.694 -23.22 2265.48 180.335 -23.32 2268.29 181.094 -23.4 2238.57 181.915 -23.45 2251.68 182.634 -23.51 2292.02 183.337 -23.56 2332.61 184.103 -23.63 2381.01 184.894 -23.75 2422.59 185.553 -23.81 2448.01 186.203 -23.87 2471.86 186.926 -23.94 2476.67 187.68 -24 2508.7 188.299 -24.07 2538.05 188.906 -24.12 2586.26 189.631 -24.29 2604.62 190.362 -24.35 2666.69 190.954 -24.41 2697.54 191.56 -24.52 2729.63 192.256 -24.64 2739.75 192.938 -24.77 2808.88 193.467 -24.88 2846.34 193.994 -25.01 2898.79 194.647 -25.17 2970.48 195.279 -25.32 3042.35 195.763 -25.53 3055.53 196.277 -25.79 3076.51 196.877 -26.02 3102.36 197.481 -26.14 3127.15 197.967 -26.31 3129.53 198.455 -26.6 3154.19 199.012 -26.9 3177.98 199.572 -27.21 3236.18 199.995 -27.49 3292.07 200.452 -27.75 3316.11 200.997 -28.12 3331.22 201.538 -28.39 3381.86 201.955 -28.73 3390.23 202.419 -29.14 3409.65 202.986 -29.51 3392.6 203.584 -29.94 3386.49 204.086 -30.36 3391.61 204.721 -30.61 3422.95 205.419 -31.02 3389.36 206.13 -31.5 3481.4 206.763 -31.93 3500.95 207.362 -32.27 3523.8 208 -32.54 3533.79 208.642 -33.02 3604.73 209.142 -33.2 3687.9 209.637 -33.49 3726.18 210.181 -33.95 3790.44 210.737 -34.36 3892.22 211.192 -34.94 3919.01 211.663 -35.61 3907.08 212.191 -36.29 3947.11 212.708 -37.01 3908.15 213.144 -37.79 3922.57 213.602 -38.96 3879.98 214.147 -40.13 3854.13 214.7 -41.05 3800.93 215.135 -41.66 3835.21 215.652 -42.41 3907.02 216.289 -43.19 3952.48 216.848 -43.69 4044.59 217.314 -44.15 4072.19 217.776 -44.77 4088.49 218.338 -45.57 4126.39 218.917 -46.32 4176.28 219.427 -47.07 4260.08 219.956 -47.66 4329.46 220.573 -48.63 4328.33 221.201 -49.42 4345.51 221.719 -50.41 4510.73 222.281 -51.27 4552.14 222.933 -52.35 4603.65 223.583 -53.51 4605.65 224.152 -54.65 4615.64 224.737 -55.82 4644.93 225.418 -56.92 4656.23 226.117 -58.18 4678.96 226.754 -59.55 4566.62 227.389 -61.01 4562.25 228.07 -62.59 4651.86 228.689 -64.15 4739.16 229.155 -65.37 4696.82 229.674 -66.65 4753.02 230.301 -67.87 4693.76 230.903 -68.86 4615.89 231.395 -69.72 4634.88 231.906 -70.66 4612.08 232.498 -71.44 4618.26 233.074 -72.08 4662.97 233.546 -72.83 4763.57 234.028 -73.48 4849 234.603 -74.19 4939.23 235.153 -75.02 5053.56 235.605 -75.58 5132.87 236.082 -76.25 5170.34 236.657 -76.81 5203.68 237.232 -77.63 5257.26 237.673 -78.25 5283.73 238.176 -78.76 5359.6 238.789 -79.45 5393.57 239.387 -79.81 5460.83 239.861 -80.22 5466.95 240.368 -80.84 5496.29 240.962 -81.45 5526.77 241.539 -82.09 5561.8 242.009 -82.68 5618 242.52 -83.33 5667.39 243.12 -84.09 5750.57 243.721 -84.67 5785.29 244.208 -85.56 5844.05 244.716 -86.66 5878.7 245.354 -87.44 5952.83 245.966 -88.45 6010.96 246.46 -89.39 6055.61 247.017 -90.13 6087.96 247.698 -90.88 6093.51 248.374 -92 6152.59 248.928 -93.18 6171.57 249.564 -94.14 6142.1 250.299 -95.11 6078.96 251.031 -96.27 6047.49 251.65 -97 6074.66 252.295 -97.7 6090.14 253.033 -98.31 6105.25 253.743 -99.13 6175.69 254.338 -99.79 6214.22 255.032 -100.17 6260.74 255.815 -100.88 6327.12 256.543 -101.84 6327.93 257.151 -102.35 6359.9 257.785 -102.83 6393.5 258.516 -103.51 6476.86 259.191 -104.13 6524.5 259.738 -104.71 6600.31 260.351 -105.39 6629.47 261.04 -106.09 6688.61 261.692 -106.75 6717.46 262.236 -107.24 6724.2 262.847 -107.75 6779.53 263.527 -108.29 6825.8 264.169 -108.91 6882 264.681 -109.24 6983.91 265.258 -109.74 7020 265.887 -110.23 7093.12 266.491 -111 7166.68 266.987 -111.43 7236.5 267.545 -111.76 7311.24 268.171 -112.08 7364.63 268.815 -]; + 18.02 1474.5 150.2 + 17.94 1538.2 150.9 + 18.01 1584.5 151.4 + 18.42 1644.1 152 + 18.73 1678.6 152.7 + 19.46 1693.1 153.3 + 19.55 1724 153.9 + 19.56 1758.2 154.7 + 19.79 1760.6 155.4 + 19.77 1779.2 156 + 19.82 1778.8 156.6 + 20.03 1790.9 157.3 + 20.12 1846 158 + 20.1 1882.6 158.6 + 20.14 1897.3 159.2 + 20.22 1887.4 160 + 20.27 1858.2 160.7 + 20.34 1849.9 161.4 + 20.39 1848.5 162 + 20.42 1868.9 162.8 + 20.47 1905.6 163.6 + 20.56 1959.6 164.3 + 20.62 1994.4 164.9 + 20.78 2020.1 165.7 + 21 2030.5 166.5 + 21.2 2023.6 167.2 + 21.33 2037.7 167.9 + 21.62 2033.4 168.7 + 21.71 2066.2 169.5 + 22.01 2077.5 170.2 + 22.15 2071.9 170.9 + 22.27 2094 171.7 + 22.29 2070.8 172.5 + 22.56 2012.6 173.1 + 22.64 2024.7 173.8 + 22.77 2072.3 174.5 + 22.88 2120.6 175.3 + 22.92 2165 176.045 + 22.91 2223.3 176.727 + 22.94 2221.4 177.481 + 23.03 2230.95 178.268 + 23.13 2279.22 179.694 + 23.22 2265.48 180.335 + 23.32 2268.29 181.094 + 23.4 2238.57 181.915 + 23.45 2251.68 182.634 + 23.51 2292.02 183.337 + 23.56 2332.61 184.103 + 23.63 2381.01 184.894 + 23.75 2422.59 185.553 + 23.81 2448.01 186.203 + 23.87 2471.86 186.926 + 23.94 2476.67 187.68 + 24 2508.7 188.299 + 24.07 2538.05 188.906 + 24.12 2586.26 189.631 + 24.29 2604.62 190.362 + 24.35 2666.69 190.954 + 24.41 2697.54 191.56 + 24.52 2729.63 192.256 + 24.64 2739.75 192.938 + 24.77 2808.88 193.467 + 24.88 2846.34 193.994 + 25.01 2898.79 194.647 + 25.17 2970.48 195.279 + 25.32 3042.35 195.763 + 25.53 3055.53 196.277 + 25.79 3076.51 196.877 + 26.02 3102.36 197.481 + 26.14 3127.15 197.967 + 26.31 3129.53 198.455 + 26.6 3154.19 199.012 + 26.9 3177.98 199.572 + 27.21 3236.18 199.995 + 27.49 3292.07 200.452 + 27.75 3316.11 200.997 + 28.12 3331.22 201.538 + 28.39 3381.86 201.955 + 28.73 3390.23 202.419 + 29.14 3409.65 202.986 + 29.51 3392.6 203.584 + 29.94 3386.49 204.086 + 30.36 3391.61 204.721 + 30.61 3422.95 205.419 + 31.02 3389.36 206.13 + 31.5 3481.4 206.763 + 31.93 3500.95 207.362 + 32.27 3523.8 208 + 32.54 3533.79 208.642 + 33.02 3604.73 209.142 + 33.2 3687.9 209.637 + 33.49 3726.18 210.181 + 33.95 3790.44 210.737 + 34.36 3892.22 211.192 + 34.94 3919.01 211.663 + 35.61 3907.08 212.191 + 36.29 3947.11 212.708 + 37.01 3908.15 213.144 + 37.79 3922.57 213.602 + 38.96 3879.98 214.147 + 40.13 3854.13 214.7 + 41.05 3800.93 215.135 + 41.66 3835.21 215.652 + 42.41 3907.02 216.289 + 43.19 3952.48 216.848 + 43.69 4044.59 217.314 + 44.15 4072.19 217.776 + 44.77 4088.49 218.338 + 45.57 4126.39 218.917 + 46.32 4176.28 219.427 + 47.07 4260.08 219.956 + 47.66 4329.46 220.573 + 48.63 4328.33 221.201 + 49.42 4345.51 221.719 + 50.41 4510.73 222.281 + 51.27 4552.14 222.933 + 52.35 4603.65 223.583 + 53.51 4605.65 224.152 + 54.65 4615.64 224.737 + 55.82 4644.93 225.418 + 56.92 4656.23 226.117 + 58.18 4678.96 226.754 + 59.55 4566.62 227.389 + 61.01 4562.25 228.07 + 62.59 4651.86 228.689 + 64.15 4739.16 229.155 + 65.37 4696.82 229.674 + 66.65 4753.02 230.301 + 67.87 4693.76 230.903 + 68.86 4615.89 231.395 + 69.72 4634.88 231.906 + 70.66 4612.08 232.498 + 71.44 4618.26 233.074 + 72.08 4662.97 233.546 + 72.83 4763.57 234.028 + 73.48 4849 234.603 + 74.19 4939.23 235.153 + 75.02 5053.56 235.605 + 75.58 5132.87 236.082 + 76.25 5170.34 236.657 + 76.81 5203.68 237.232 + 77.63 5257.26 237.673 + 78.25 5283.73 238.176 + 78.76 5359.6 238.789 + 79.45 5393.57 239.387 + 79.81 5460.83 239.861 + 80.22 5466.95 240.368 + 80.84 5496.29 240.962 + 81.45 5526.77 241.539 + 82.09 5561.8 242.009 + 82.68 5618 242.52 + 83.33 5667.39 243.12 + 84.09 5750.57 243.721 + 84.67 5785.29 244.208 + 85.56 5844.05 244.716 + 86.66 5878.7 245.354 + 87.44 5952.83 245.966 + 88.45 6010.96 246.46 + 89.39 6055.61 247.017 + 90.13 6087.96 247.698 + 90.88 6093.51 248.374 + 92 6152.59 248.928 + 93.18 6171.57 249.564 + 94.14 6142.1 250.299 + 95.11 6078.96 251.031 + 96.27 6047.49 251.65 + 97 6074.66 252.295 + 97.7 6090.14 253.033 + 98.31 6105.25 253.743 + 99.13 6175.69 254.338 + 99.79 6214.22 255.032 + 100.17 6260.74 255.815 + 100.88 6327.12 256.543 + 101.84 6327.93 257.151 + 102.35 6359.9 257.785 + 102.83 6393.5 258.516 + 103.51 6476.86 259.191 + 104.13 6524.5 259.738 + 104.71 6600.31 260.351 + 105.39 6629.47 261.04 + 106.09 6688.61 261.692 + 106.75 6717.46 262.236 + 107.24 6724.2 262.847 + 107.75 6779.53 263.527 + 108.29 6825.8 264.169 + 108.91 6882 264.681 + 109.24 6983.91 265.258 + 109.74 7020 265.887 + 110.23 7093.12 266.491 + 111 7166.68 266.987 + 111.43 7236.5 267.545 + 111.76 7311.24 268.171 + 112.08 7364.63 268.815 + ]; %GDPD GDPQ GPOP series = zeros(193,2); diff --git a/tests/analytic_derivatives/fsdat_simul.m b/tests/analytic_derivatives/fsdat_simul.m index d4f4a8066f..159612e577 100644 --- a/tests/analytic_derivatives/fsdat_simul.m +++ b/tests/analytic_derivatives/fsdat_simul.m @@ -1,828 +1,828 @@ gy_obs =[ - 1.0030045 - 0.99990934 - 1.0172778 - 0.99464043 - 1.0253423 - 1.0150215 - 0.97772557 - 0.97832186 - 1.0159561 - 1.0085937 - 1.0102649 - 1.0007604 - 1.0112596 - 1.0163279 - 1.0173204 - 1.0103896 - 1.0006493 - 0.99447124 - 1.0196405 - 1.0089304 - 0.99650737 - 1.0139707 - 0.97865842 - 1.0192225 - 0.99139628 - 1.0141362 - 1.0196612 - 0.97483476 - 0.99686151 - 0.99594464 - 1.0000642 - 1.0172243 - 1.0025773 - 0.97199728 - 1.0217815 - 1.0219949 - 0.99490252 - 1.0190728 - 1.0111337 - 1.0003792 - 0.98969164 - 1.010438 - 1.0216309 - 1.0016671 - 1.0357588 - 0.98803787 - 1.0093457 - 1.0177035 - 0.98548204 - 1.0274294 - 1.0141377 - 1.0091174 - 0.96427632 - 1.0083272 - 1.0007882 - 0.99038262 - 1.0031336 - 0.99500213 - 0.98203716 - 0.9889452 - 1.011632 - 0.99451949 - 0.97291047 - 0.98750871 - 0.99992418 - 0.97657318 - 0.99930448 - 1.0008515 - 1.0044064 - 0.98133792 - 1.0091702 - 1.0087023 - 1.0119876 - 1.0143019 - 1.0311061 - 0.99340471 - 1.0057428 - 0.99197259 - 1.0071019 - 0.99448853 - 1.0061819 - 1.0070088 - 0.9950913 - 1.0302318 - 0.9817693 - 1.0072885 - 0.97355282 - 0.98782586 - 1.0136674 - 0.99863956 - 1.0205668 - 0.99611384 - 1.0073805 - 0.99691529 - 1.0089194 - 1.0030467 - 1.0112006 - 1.0260523 - 0.97803331 - 0.99423374 - 1.0043727 - 1.0140173 - 1.0111473 - 0.99524348 - 0.99775943 - 0.9958619 - 0.9982344 - 1.0210212 - 1.0022288 - 1.0014801 - 1.011456 - 1.0124871 - 0.99843599 - 0.99324886 - 0.99912838 - 1.003327 - 1.0072071 - 1.0115223 - 1.009266 - 1.0070554 - 1.0129916 - 1.0053413 - 1.0051638 - 0.99212952 - 1.0214422 - 0.98716707 - 0.99905788 - 0.98877357 - 0.98568476 - 0.99767393 - 1.0061791 - 0.98423439 - 0.99492949 - 0.98786999 - 0.99754239 - 1.0168619 - 0.99472384 - 1.0041658 - 0.98123181 - 1.0112882 - 0.99245422 - 1.0010255 - 1.0017799 - 1.0089968 - 1.0072824 - 0.99768475 - 1.0044726 - 1.0118678 - 1.0056385 - 1.0276965 - 1.0025122 - 1.0065161 - 1.0234338 - 0.99760167 - 0.98922272 - 1.0101918 - 1.011615 - 1.0085286 - 1.0074455 - 0.98866757 - 0.99959012 - 1.0129881 - 0.99127881 - 0.97971901 - 1.0185314 - 1.020054 - 1.0132605 - 0.98063643 - 0.99490253 - 1.0101531 - 1.0004526 - 1.0059109 - 0.98974491 - 1.0062391 - 1.0216488 - 0.99398446 - 0.97786609 - 1.0019274 - 0.99587153 - 1.0095881 - 1.0111887 - 0.99457649 - 0.97896734 - 1.000172 - 1.0142951 - 1.0034224 - 1.0037242 - 1.0016059 - 1.016556 - 0.99687023 - 1.0117844 - 1.0059212 - 0.98083159 - 0.98638851 - 1.0128713 - 1.0096232 - 1.0115891 - 1.0011213 - 1.0147105 - 1.0066344 - 1.0164429 - 0.99825038 - 0.99403411 + 1.0030045 + 0.99990934 + 1.0172778 + 0.99464043 + 1.0253423 + 1.0150215 + 0.97772557 + 0.97832186 + 1.0159561 + 1.0085937 + 1.0102649 + 1.0007604 + 1.0112596 + 1.0163279 + 1.0173204 + 1.0103896 + 1.0006493 + 0.99447124 + 1.0196405 + 1.0089304 + 0.99650737 + 1.0139707 + 0.97865842 + 1.0192225 + 0.99139628 + 1.0141362 + 1.0196612 + 0.97483476 + 0.99686151 + 0.99594464 + 1.0000642 + 1.0172243 + 1.0025773 + 0.97199728 + 1.0217815 + 1.0219949 + 0.99490252 + 1.0190728 + 1.0111337 + 1.0003792 + 0.98969164 + 1.010438 + 1.0216309 + 1.0016671 + 1.0357588 + 0.98803787 + 1.0093457 + 1.0177035 + 0.98548204 + 1.0274294 + 1.0141377 + 1.0091174 + 0.96427632 + 1.0083272 + 1.0007882 + 0.99038262 + 1.0031336 + 0.99500213 + 0.98203716 + 0.9889452 + 1.011632 + 0.99451949 + 0.97291047 + 0.98750871 + 0.99992418 + 0.97657318 + 0.99930448 + 1.0008515 + 1.0044064 + 0.98133792 + 1.0091702 + 1.0087023 + 1.0119876 + 1.0143019 + 1.0311061 + 0.99340471 + 1.0057428 + 0.99197259 + 1.0071019 + 0.99448853 + 1.0061819 + 1.0070088 + 0.9950913 + 1.0302318 + 0.9817693 + 1.0072885 + 0.97355282 + 0.98782586 + 1.0136674 + 0.99863956 + 1.0205668 + 0.99611384 + 1.0073805 + 0.99691529 + 1.0089194 + 1.0030467 + 1.0112006 + 1.0260523 + 0.97803331 + 0.99423374 + 1.0043727 + 1.0140173 + 1.0111473 + 0.99524348 + 0.99775943 + 0.9958619 + 0.9982344 + 1.0210212 + 1.0022288 + 1.0014801 + 1.011456 + 1.0124871 + 0.99843599 + 0.99324886 + 0.99912838 + 1.003327 + 1.0072071 + 1.0115223 + 1.009266 + 1.0070554 + 1.0129916 + 1.0053413 + 1.0051638 + 0.99212952 + 1.0214422 + 0.98716707 + 0.99905788 + 0.98877357 + 0.98568476 + 0.99767393 + 1.0061791 + 0.98423439 + 0.99492949 + 0.98786999 + 0.99754239 + 1.0168619 + 0.99472384 + 1.0041658 + 0.98123181 + 1.0112882 + 0.99245422 + 1.0010255 + 1.0017799 + 1.0089968 + 1.0072824 + 0.99768475 + 1.0044726 + 1.0118678 + 1.0056385 + 1.0276965 + 1.0025122 + 1.0065161 + 1.0234338 + 0.99760167 + 0.98922272 + 1.0101918 + 1.011615 + 1.0085286 + 1.0074455 + 0.98866757 + 0.99959012 + 1.0129881 + 0.99127881 + 0.97971901 + 1.0185314 + 1.020054 + 1.0132605 + 0.98063643 + 0.99490253 + 1.0101531 + 1.0004526 + 1.0059109 + 0.98974491 + 1.0062391 + 1.0216488 + 0.99398446 + 0.97786609 + 1.0019274 + 0.99587153 + 1.0095881 + 1.0111887 + 0.99457649 + 0.97896734 + 1.000172 + 1.0142951 + 1.0034224 + 1.0037242 + 1.0016059 + 1.016556 + 0.99687023 + 1.0117844 + 1.0059212 + 0.98083159 + 0.98638851 + 1.0128713 + 1.0096232 + 1.0115891 + 1.0011213 + 1.0147105 + 1.0066344 + 1.0164429 + 0.99825038 + 0.99403411 -]; + ]; gp_obs =[ - 1.0079715 - 1.0074573 - 1.0153107 - 1.0152677 - 1.0011653 - 0.99950061 - 1.0328311 - 1.0192317 - 1.009827 - 0.99588916 - 1.007474 - 1.0113061 - 0.98696624 - 0.99978663 - 0.98240542 - 0.98861723 - 0.99008763 - 1.0185076 - 1.0052452 - 0.99447194 - 1.0092685 - 1.01208 - 1.0105237 - 0.98513875 - 1.0165628 - 0.99485934 - 1.0050255 - 1.0140756 - 1.0093128 - 1.0155868 - 1.0107023 - 0.99212762 - 1.0095465 - 1.0028435 - 1.0069437 - 1.0070473 - 1.0145902 - 1.0186922 - 1.0059917 - 1.0113072 - 1.0107386 - 0.99769196 - 0.99793444 - 1.0050791 - 0.98307821 - 1.0107594 - 0.99689982 - 0.98667064 - 0.9991662 - 0.98274722 - 0.98422032 - 0.99393016 - 1.0118567 - 0.99912781 - 1.0023744 - 1.0086662 - 1.0164773 - 1.0169327 - 1.0372478 - 1.0314242 - 1.0004256 - 1.0110541 - 1.0076575 - 1.0119851 - 1.0055188 - 1.0213959 - 1.0234416 - 1.0264917 - 1.0292725 - 1.0385184 - 1.0200999 - 1.0107697 - 1.008583 - 1.0200332 - 1.0030413 - 1.0108659 - 1.0185145 - 1.0168619 - 1.0180462 - 1.0239657 - 1.0205509 - 1.0189973 - 1.0246446 - 1.0135089 - 1.0352973 - 1.0099289 - 1.0266474 - 1.0279829 - 1.0101653 - 1.041216 - 1.0103861 - 1.0114727 - 1.0054605 - 1.0190722 - 1.0114837 - 1.0179213 - 1.006082 - 1.0049696 - 1.0143629 - 0.9971036 - 1.0005602 - 1.0078403 - 1.0240222 - 1.0195063 - 1.0355136 - 1.0218743 - 1.0171331 - 1.0049817 - 1.0140974 - 1.0168431 - 1.0049966 - 1.0045568 - 1.0156414 - 1.0273055 - 1.0197653 - 1.0030624 - 1.0154993 - 0.99782084 - 0.99711648 - 1.014408 - 1.0057417 - 0.99936837 - 1.0096934 - 1.0095138 - 1.0057734 - 1.0114497 - 1.0059784 - 1.0328889 - 1.0098032 - 1.0041114 - 1.0101247 - 1.0181588 - 1.0115712 - 1.0227509 - 1.0065104 - 1.0110902 - 1.0298169 - 1.0089532 - 1.0368733 - 1.0123033 - 1.0060763 - 1.0150937 - 1.0239325 - 0.99555536 - 0.99861271 - 1.0076201 - 0.99941535 - 1.0119522 - 1.0129183 - 0.99288924 - 1.0260784 - 1.0144982 - 1.0121985 - 1.0234916 - 1.02215 - 1.0190118 - 1.0172679 - 1.0118398 - 1.0002123 - 1.0092124 - 1.0071943 - 0.99508468 - 1.0019303 - 1.0030733 - 0.9964198 - 1.0027298 - 0.99797614 - 1.006942 - 0.99793928 - 1.0083214 - 1.0283732 - 1.0111102 - 1.016936 - 1.0229061 - 0.98846454 - 1.0015387 - 1.0201769 - 1.0079822 - 1.0064007 - 1.0095543 - 1.0092207 - 1.0135485 - 1.0198974 - 1.0140252 - 1.0128686 - 1.0092903 - 1.0141974 - 1.0023492 - 0.99731455 - 1.0026598 - 0.99303643 - 1.0036469 - 1.0160975 - 1.0368378 - 1.0139625 - 1.01493 - 1.0113531 - 1.0114548 - 0.99833441 - 0.99648401 - 0.97645361 - 1.0154053 - 1.01703 + 1.0079715 + 1.0074573 + 1.0153107 + 1.0152677 + 1.0011653 + 0.99950061 + 1.0328311 + 1.0192317 + 1.009827 + 0.99588916 + 1.007474 + 1.0113061 + 0.98696624 + 0.99978663 + 0.98240542 + 0.98861723 + 0.99008763 + 1.0185076 + 1.0052452 + 0.99447194 + 1.0092685 + 1.01208 + 1.0105237 + 0.98513875 + 1.0165628 + 0.99485934 + 1.0050255 + 1.0140756 + 1.0093128 + 1.0155868 + 1.0107023 + 0.99212762 + 1.0095465 + 1.0028435 + 1.0069437 + 1.0070473 + 1.0145902 + 1.0186922 + 1.0059917 + 1.0113072 + 1.0107386 + 0.99769196 + 0.99793444 + 1.0050791 + 0.98307821 + 1.0107594 + 0.99689982 + 0.98667064 + 0.9991662 + 0.98274722 + 0.98422032 + 0.99393016 + 1.0118567 + 0.99912781 + 1.0023744 + 1.0086662 + 1.0164773 + 1.0169327 + 1.0372478 + 1.0314242 + 1.0004256 + 1.0110541 + 1.0076575 + 1.0119851 + 1.0055188 + 1.0213959 + 1.0234416 + 1.0264917 + 1.0292725 + 1.0385184 + 1.0200999 + 1.0107697 + 1.008583 + 1.0200332 + 1.0030413 + 1.0108659 + 1.0185145 + 1.0168619 + 1.0180462 + 1.0239657 + 1.0205509 + 1.0189973 + 1.0246446 + 1.0135089 + 1.0352973 + 1.0099289 + 1.0266474 + 1.0279829 + 1.0101653 + 1.041216 + 1.0103861 + 1.0114727 + 1.0054605 + 1.0190722 + 1.0114837 + 1.0179213 + 1.006082 + 1.0049696 + 1.0143629 + 0.9971036 + 1.0005602 + 1.0078403 + 1.0240222 + 1.0195063 + 1.0355136 + 1.0218743 + 1.0171331 + 1.0049817 + 1.0140974 + 1.0168431 + 1.0049966 + 1.0045568 + 1.0156414 + 1.0273055 + 1.0197653 + 1.0030624 + 1.0154993 + 0.99782084 + 0.99711648 + 1.014408 + 1.0057417 + 0.99936837 + 1.0096934 + 1.0095138 + 1.0057734 + 1.0114497 + 1.0059784 + 1.0328889 + 1.0098032 + 1.0041114 + 1.0101247 + 1.0181588 + 1.0115712 + 1.0227509 + 1.0065104 + 1.0110902 + 1.0298169 + 1.0089532 + 1.0368733 + 1.0123033 + 1.0060763 + 1.0150937 + 1.0239325 + 0.99555536 + 0.99861271 + 1.0076201 + 0.99941535 + 1.0119522 + 1.0129183 + 0.99288924 + 1.0260784 + 1.0144982 + 1.0121985 + 1.0234916 + 1.02215 + 1.0190118 + 1.0172679 + 1.0118398 + 1.0002123 + 1.0092124 + 1.0071943 + 0.99508468 + 1.0019303 + 1.0030733 + 0.9964198 + 1.0027298 + 0.99797614 + 1.006942 + 0.99793928 + 1.0083214 + 1.0283732 + 1.0111102 + 1.016936 + 1.0229061 + 0.98846454 + 1.0015387 + 1.0201769 + 1.0079822 + 1.0064007 + 1.0095543 + 1.0092207 + 1.0135485 + 1.0198974 + 1.0140252 + 1.0128686 + 1.0092903 + 1.0141974 + 1.0023492 + 0.99731455 + 1.0026598 + 0.99303643 + 1.0036469 + 1.0160975 + 1.0368378 + 1.0139625 + 1.01493 + 1.0113531 + 1.0114548 + 0.99833441 + 0.99648401 + 0.97645361 + 1.0154053 + 1.01703 -]; + ]; Y_obs =[ - 1 - 0.99690484 - 1.0111781 - 1.0028141 - 1.0251518 - 1.0371688 - 1.0118899 - 0.98720726 - 1.0001589 - 1.0057481 - 1.0130085 - 1.0107643 - 1.0190194 - 1.0323428 - 1.0466587 - 1.0540438 - 1.0516886 - 1.0431553 - 1.0597913 - 1.0657172 - 1.0592201 - 1.0701863 - 1.0458402 - 1.0620582 - 1.0504499 - 1.0615817 - 1.0782384 - 1.0500687 - 1.0439257 - 1.0368658 - 1.0339255 - 1.0481453 - 1.0477181 - 1.0167109 - 1.0354878 - 1.0544782 - 1.0463762 - 1.0624445 - 1.0705737 - 1.0679484 - 1.0546356 - 1.0620691 - 1.0806955 - 1.0793581 - 1.1121124 - 1.0971458 - 1.1034869 - 1.1181859 - 1.1006634 - 1.1250883 - 1.1362214 - 1.1423343 - 1.1036061 - 1.1089288 - 1.1067125 - 1.0940906 - 1.0942197 - 1.0862174 - 1.06525 - 1.0511907 - 1.0598182 - 1.0513331 - 1.0212391 - 1.0057433 - 1.002663 - 0.97623167 - 0.97253165 - 0.97037865 - 0.97178055 - 0.95011397 - 0.95627969 - 0.96197747 - 0.97096053 - 0.98225794 - 1.0103595 - 1.0007597 - 1.003498 - 0.99246608 - 0.99656347 - 0.98804749 - 0.99122491 - 0.99522926 - 0.98731605 - 1.0145434 - 0.99330816 - 0.99759216 - 0.96814048 - 0.95296183 - 0.96362471 - 0.95925977 - 0.97682205 - 0.96993138 - 0.9743074 - 0.96821818 - 0.97413308 - 0.9741753 - 0.98237142 - 1.0054193 - 0.98044807 - 0.9716773 - 0.9730455 - 0.98405828 - 0.99220103 - 0.98444001 - 0.97919493 - 0.97205233 - 0.96728223 - 0.98529893 - 0.98452324 - 0.98299888 - 0.99145042 - 1.000933 - 0.99636447 - 0.98660883 - 0.98273271 - 0.98305518 - 0.98725774 - 0.99577549 - 1.002037 - 1.0060879 - 1.016075 - 1.0184118 - 1.0205711 - 1.0096961 - 1.0281337 - 1.0122963 - 1.0083497 - 0.99411874 - 0.976799 - 0.97146842 - 0.97464304 - 0.95587292 - 0.94779791 - 0.93266339 - 0.92720128 - 0.94105864 - 0.93277798 - 0.93393927 - 0.91216657 - 0.92045028 - 0.9099 - 0.90792098 - 0.90669634 - 0.91268867 - 0.91696661 - 0.91164685 - 0.91311495 - 0.92197825 - 0.92461222 - 0.94930422 - 0.9488119 - 0.95232353 - 0.97275278 - 0.96734995 - 0.95356817 - 0.96075548 - 0.96936594 - 0.97489002 - 0.97933106 - 0.96499412 - 0.96157973 - 0.97156334 - 0.95983765 - 0.93655215 - 0.95207909 - 0.96912862 - 0.97938462 - 0.95701655 - 0.94891457 - 0.95606317 - 0.95351125 - 0.95641767 - 0.94315807 - 0.94639265 - 0.96503697 - 0.95601693 - 0.93087851 - 0.92980141 - 0.92266844 - 0.92925206 - 0.93743628 - 0.92900826 - 0.9049711 - 0.90213859 - 0.91342916 - 0.91384707 - 0.91456681 - 0.91316822 - 0.92671976 - 0.92058549 - 0.92936541 - 0.93228212 - 0.91010921 - 0.89349322 - 0.90336005 - 0.90997873 - 0.91856328 - 0.91668007 - 0.92838606 - 0.932016 - 0.94545438 - 0.94070026 - 0.93172987 + 1 + 0.99690484 + 1.0111781 + 1.0028141 + 1.0251518 + 1.0371688 + 1.0118899 + 0.98720726 + 1.0001589 + 1.0057481 + 1.0130085 + 1.0107643 + 1.0190194 + 1.0323428 + 1.0466587 + 1.0540438 + 1.0516886 + 1.0431553 + 1.0597913 + 1.0657172 + 1.0592201 + 1.0701863 + 1.0458402 + 1.0620582 + 1.0504499 + 1.0615817 + 1.0782384 + 1.0500687 + 1.0439257 + 1.0368658 + 1.0339255 + 1.0481453 + 1.0477181 + 1.0167109 + 1.0354878 + 1.0544782 + 1.0463762 + 1.0624445 + 1.0705737 + 1.0679484 + 1.0546356 + 1.0620691 + 1.0806955 + 1.0793581 + 1.1121124 + 1.0971458 + 1.1034869 + 1.1181859 + 1.1006634 + 1.1250883 + 1.1362214 + 1.1423343 + 1.1036061 + 1.1089288 + 1.1067125 + 1.0940906 + 1.0942197 + 1.0862174 + 1.06525 + 1.0511907 + 1.0598182 + 1.0513331 + 1.0212391 + 1.0057433 + 1.002663 + 0.97623167 + 0.97253165 + 0.97037865 + 0.97178055 + 0.95011397 + 0.95627969 + 0.96197747 + 0.97096053 + 0.98225794 + 1.0103595 + 1.0007597 + 1.003498 + 0.99246608 + 0.99656347 + 0.98804749 + 0.99122491 + 0.99522926 + 0.98731605 + 1.0145434 + 0.99330816 + 0.99759216 + 0.96814048 + 0.95296183 + 0.96362471 + 0.95925977 + 0.97682205 + 0.96993138 + 0.9743074 + 0.96821818 + 0.97413308 + 0.9741753 + 0.98237142 + 1.0054193 + 0.98044807 + 0.9716773 + 0.9730455 + 0.98405828 + 0.99220103 + 0.98444001 + 0.97919493 + 0.97205233 + 0.96728223 + 0.98529893 + 0.98452324 + 0.98299888 + 0.99145042 + 1.000933 + 0.99636447 + 0.98660883 + 0.98273271 + 0.98305518 + 0.98725774 + 0.99577549 + 1.002037 + 1.0060879 + 1.016075 + 1.0184118 + 1.0205711 + 1.0096961 + 1.0281337 + 1.0122963 + 1.0083497 + 0.99411874 + 0.976799 + 0.97146842 + 0.97464304 + 0.95587292 + 0.94779791 + 0.93266339 + 0.92720128 + 0.94105864 + 0.93277798 + 0.93393927 + 0.91216657 + 0.92045028 + 0.9099 + 0.90792098 + 0.90669634 + 0.91268867 + 0.91696661 + 0.91164685 + 0.91311495 + 0.92197825 + 0.92461222 + 0.94930422 + 0.9488119 + 0.95232353 + 0.97275278 + 0.96734995 + 0.95356817 + 0.96075548 + 0.96936594 + 0.97489002 + 0.97933106 + 0.96499412 + 0.96157973 + 0.97156334 + 0.95983765 + 0.93655215 + 0.95207909 + 0.96912862 + 0.97938462 + 0.95701655 + 0.94891457 + 0.95606317 + 0.95351125 + 0.95641767 + 0.94315807 + 0.94639265 + 0.96503697 + 0.95601693 + 0.93087851 + 0.92980141 + 0.92266844 + 0.92925206 + 0.93743628 + 0.92900826 + 0.9049711 + 0.90213859 + 0.91342916 + 0.91384707 + 0.91456681 + 0.91316822 + 0.92671976 + 0.92058549 + 0.92936541 + 0.93228212 + 0.91010921 + 0.89349322 + 0.90336005 + 0.90997873 + 0.91856328 + 0.91668007 + 0.92838606 + 0.932016 + 0.94545438 + 0.94070026 + 0.93172987 -]; + ]; P_obs =[ - 1 - 0.99948573 - 1.0068249 - 1.0141211 - 1.0073149 - 0.99884398 - 1.0237035 - 1.0349636 - 1.036819 - 1.0247366 - 1.0242391 - 1.0275737 - 1.0065684 - 0.99838346 - 0.97281734 - 0.95346302 - 0.9355791 - 0.9461152 - 0.94338882 - 0.92988921 - 0.9311862 - 0.93529467 - 0.93784681 - 0.91501401 - 0.92360522 - 0.91049302 - 0.90754698 - 0.91365103 - 0.91499228 - 0.92260749 - 0.92533824 - 0.90949431 - 0.91106924 - 0.90594116 - 0.90491334 - 0.9039891 - 0.91060772 - 0.92132842 - 0.91934854 - 0.92268418 - 0.92545127 - 0.91517169 - 0.90513459 - 0.90224212 - 0.87734878 - 0.88013667 - 0.86906494 - 0.84776403 - 0.83895869 - 0.81373437 - 0.78998314 - 0.77594176 - 0.77982695 - 0.77098321 - 0.76538611 - 0.76608075 - 0.77458654 - 0.78354767 - 0.81282389 - 0.83627649 - 0.82873051 - 0.83181309 - 0.83149903 - 0.83551261 - 0.83305985 - 0.84648418 - 0.86195421 - 0.88047436 - 0.90177533 - 0.93232215 - 0.94445051 - 0.9472487 - 0.94786015 - 0.95992178 - 0.95499149 - 0.95788581 - 0.9684288 - 0.97731917 - 0.98739379 - 1.0033879 - 1.0159673 - 1.0269931 - 1.0436661 - 1.0492034 - 1.0765292 - 1.0784865 - 1.0971624 - 1.1171737 - 1.1193675 - 1.1526119 - 1.1550265 - 1.1585277 - 1.1560166 - 1.1671172 - 1.1706294 - 1.1805791 - 1.1786896 - 1.1756876 - 1.1820789 - 1.171211 - 1.1637997 - 1.1636684 - 1.179719 - 1.1912538 - 1.2187959 - 1.2326986 - 1.2418602 - 1.2388704 - 1.2449963 - 1.2538678 - 1.2508929 - 1.2474781 - 1.255148 - 1.274482 - 1.2862757 - 1.2813665 - 1.2888943 - 1.2787436 - 1.2678886 - 1.274325 - 1.2720952 - 1.263492 - 1.2652139 - 1.2667561 - 1.264558 - 1.2680362 - 1.2660431 - 1.2909605 - 1.2927921 - 1.288932 - 1.2910852 - 1.3012725 - 1.3048721 - 1.3196515 - 1.3181903 - 1.321309 - 1.3431543 - 1.344136 - 1.3730377 - 1.3773695 - 1.3754742 - 1.3825964 - 1.3985574 - 1.3861412 - 1.3767823 - 1.3764309 - 1.3678747 - 1.3718554 - 1.3768022 - 1.3617199 - 1.3798267 - 1.3863533 - 1.3905803 - 1.4061004 - 1.4202788 - 1.4313191 - 1.4406155 - 1.4444837 - 1.4367244 - 1.4379653 - 1.4371881 - 1.4243012 - 1.41826 - 1.4133617 - 1.40181 - 1.3965683 - 1.3865729 - 1.3855433 - 1.3755111 - 1.3758609 - 1.3962625 - 1.3994012 - 1.4083656 - 1.4233002 - 1.4037932 - 1.3973604 - 1.4095657 - 1.4095764 - 1.4080055 - 1.4095882 - 1.4108374 - 1.4164143 - 1.4283402 - 1.4343939 - 1.4392909 - 1.4406097 - 1.4468355 - 1.4412132 - 1.4305562 - 1.4252445 - 1.4103094 - 1.4059847 - 1.4141106 - 1.4429769 - 1.4489679 - 1.4559263 - 1.4593079 - 1.4627911 - 1.453154 - 1.4416665 - 1.4101485 - 1.4175823 - 1.4266407 + 1 + 0.99948573 + 1.0068249 + 1.0141211 + 1.0073149 + 0.99884398 + 1.0237035 + 1.0349636 + 1.036819 + 1.0247366 + 1.0242391 + 1.0275737 + 1.0065684 + 0.99838346 + 0.97281734 + 0.95346302 + 0.9355791 + 0.9461152 + 0.94338882 + 0.92988921 + 0.9311862 + 0.93529467 + 0.93784681 + 0.91501401 + 0.92360522 + 0.91049302 + 0.90754698 + 0.91365103 + 0.91499228 + 0.92260749 + 0.92533824 + 0.90949431 + 0.91106924 + 0.90594116 + 0.90491334 + 0.9039891 + 0.91060772 + 0.92132842 + 0.91934854 + 0.92268418 + 0.92545127 + 0.91517169 + 0.90513459 + 0.90224212 + 0.87734878 + 0.88013667 + 0.86906494 + 0.84776403 + 0.83895869 + 0.81373437 + 0.78998314 + 0.77594176 + 0.77982695 + 0.77098321 + 0.76538611 + 0.76608075 + 0.77458654 + 0.78354767 + 0.81282389 + 0.83627649 + 0.82873051 + 0.83181309 + 0.83149903 + 0.83551261 + 0.83305985 + 0.84648418 + 0.86195421 + 0.88047436 + 0.90177533 + 0.93232215 + 0.94445051 + 0.9472487 + 0.94786015 + 0.95992178 + 0.95499149 + 0.95788581 + 0.9684288 + 0.97731917 + 0.98739379 + 1.0033879 + 1.0159673 + 1.0269931 + 1.0436661 + 1.0492034 + 1.0765292 + 1.0784865 + 1.0971624 + 1.1171737 + 1.1193675 + 1.1526119 + 1.1550265 + 1.1585277 + 1.1560166 + 1.1671172 + 1.1706294 + 1.1805791 + 1.1786896 + 1.1756876 + 1.1820789 + 1.171211 + 1.1637997 + 1.1636684 + 1.179719 + 1.1912538 + 1.2187959 + 1.2326986 + 1.2418602 + 1.2388704 + 1.2449963 + 1.2538678 + 1.2508929 + 1.2474781 + 1.255148 + 1.274482 + 1.2862757 + 1.2813665 + 1.2888943 + 1.2787436 + 1.2678886 + 1.274325 + 1.2720952 + 1.263492 + 1.2652139 + 1.2667561 + 1.264558 + 1.2680362 + 1.2660431 + 1.2909605 + 1.2927921 + 1.288932 + 1.2910852 + 1.3012725 + 1.3048721 + 1.3196515 + 1.3181903 + 1.321309 + 1.3431543 + 1.344136 + 1.3730377 + 1.3773695 + 1.3754742 + 1.3825964 + 1.3985574 + 1.3861412 + 1.3767823 + 1.3764309 + 1.3678747 + 1.3718554 + 1.3768022 + 1.3617199 + 1.3798267 + 1.3863533 + 1.3905803 + 1.4061004 + 1.4202788 + 1.4313191 + 1.4406155 + 1.4444837 + 1.4367244 + 1.4379653 + 1.4371881 + 1.4243012 + 1.41826 + 1.4133617 + 1.40181 + 1.3965683 + 1.3865729 + 1.3855433 + 1.3755111 + 1.3758609 + 1.3962625 + 1.3994012 + 1.4083656 + 1.4233002 + 1.4037932 + 1.3973604 + 1.4095657 + 1.4095764 + 1.4080055 + 1.4095882 + 1.4108374 + 1.4164143 + 1.4283402 + 1.4343939 + 1.4392909 + 1.4406097 + 1.4468355 + 1.4412132 + 1.4305562 + 1.4252445 + 1.4103094 + 1.4059847 + 1.4141106 + 1.4429769 + 1.4489679 + 1.4559263 + 1.4593079 + 1.4627911 + 1.453154 + 1.4416665 + 1.4101485 + 1.4175823 + 1.4266407 -]; + ]; diff --git a/tests/block_bytecode/run_ls2003.m b/tests/block_bytecode/run_ls2003.m index 0b1d898e34..f0c11d31f7 100644 --- a/tests/block_bytecode/run_ls2003.m +++ b/tests/block_bytecode/run_ls2003.m @@ -17,20 +17,20 @@ function run_ls2003(block, bytecode, solve_algo, stack_solve_algo) % You should have received a copy of the GNU General Public License % along with Dynare. If not, see <http://www.gnu.org/licenses/>. - % Workaround for a strange race condition under Octave - if exist('ls2003_tmp.m') == 2 - delete('ls2003_tmp.m') - end +% Workaround for a strange race condition under Octave +if exist('ls2003_tmp.m') == 2 + delete('ls2003_tmp.m') +end - disp(['TEST: ls2003 (block=' num2str(block) ', bytecode=' ... +disp(['TEST: ls2003 (block=' num2str(block) ', bytecode=' ... num2str(bytecode) ', solve_algo=' num2str(solve_algo) ... ', stack_solve_algo=' num2str(stack_solve_algo) ')...']); - fid = fopen('ls2003_tmp.mod', 'w'); - assert(fid > 0); - fprintf(fid, ['@#define block = %d\n@#define bytecode = %d\n' ... - '@#define solve_algo = %d\n@#define stack_solve_algo = %d\n' ... - '@#include \"ls2003.mod\"\n'], block, bytecode, ... - solve_algo, stack_solve_algo); - fclose(fid); - dynare('ls2003_tmp.mod','console') +fid = fopen('ls2003_tmp.mod', 'w'); +assert(fid > 0); +fprintf(fid, ['@#define block = %d\n@#define bytecode = %d\n' ... + '@#define solve_algo = %d\n@#define stack_solve_algo = %d\n' ... + '@#include \"ls2003.mod\"\n'], block, bytecode, ... + solve_algo, stack_solve_algo); +fclose(fid); +dynare('ls2003_tmp.mod','console') end diff --git a/tests/bvar_a_la_sims/bvar_sample.m b/tests/bvar_a_la_sims/bvar_sample.m index 8093afe18f..3dd002e3b8 100644 --- a/tests/bvar_a_la_sims/bvar_sample.m +++ b/tests/bvar_a_la_sims/bvar_sample.m @@ -1,1006 +1,1006 @@ bvar_data = [ -0.00000000000, 0.00000000000; --0.00485199480, -0.00034195121; --0.00369702440, -0.01212953600; -0.01577573000, -0.00131845390; --0.01132415000, -0.00364839770; -0.01158109800, -0.00262917340; --0.00385969150, -0.00374515890; --0.00605244640, 0.00760215990; --0.00027881367, -0.01014485600; -0.00328156560, -0.00358791610; --0.01152432500, -0.00064990774; --0.00417541420, -0.02726543200; -0.01165937200, -0.01565713900; -0.00327415420, -0.01403374100; --0.00262015080, -0.01667459700; --0.01146453600, -0.01088215300; -0.00521521470, -0.02177149300; -0.00767451980, -0.01671285200; -0.01259883800, 0.00306304710; --0.01790411600, -0.01240549400; -0.00451096210, 0.00713706070; -0.02171339100, -0.00405944740; --0.00984485920, -0.00280935440; -0.00303833090, -0.00658279110; -0.00496516950, -0.00329239970; -0.01425115100, -0.01417161800; --0.00848068480, -0.01036798700; -0.01384593500, 0.00307931740; --0.00911261030, -0.00409005360; -0.00104231040, -0.00503950650; --0.01669998300, -0.00919063320; -0.02192734300, -0.00900963420; -0.00895830410, 0.00889444930; --0.00078210473, 0.00303194750; --0.00369206110, 0.00307427120; -0.01569838000, -0.00494547550; --0.00518999260, -0.02284842300; -0.01668021700, -0.02845341900; --0.02568046200, -0.03263100900; -0.00662056690, -0.00759856640; --0.00051553622, -0.00266545800; -0.00588163920, 0.00553735730; -0.00496782960, -0.00439611810; --0.00917153500, -0.02059437900; -0.01824072100, -0.01633834000; -0.01007005900, -0.02248933700; --0.00560011310, -0.02417716500; --0.00769812730, -0.00017818698; -0.00133784330, -0.00149211110; --0.01435760300, 0.00692602660; -0.00404759460, -0.01017014800; --0.00663831950, -0.00315748290; --0.00085548858, -0.02827386400; -0.00421366420, -0.02999430500; -0.00228340080, 0.00351766350; -0.00067972662, 0.00394969830; -0.00010249414, -0.00227112120; -0.01352092200, 0.00054581385; --0.01119695100, 0.01346546700; -0.03037738600, 0.01926781500; --0.00648092580, 0.03341492100; -0.00742909040, 0.03054532700; -0.00348382550, 0.01877144600; -0.00246629280, 0.00970566090; -0.01095858000, 0.01093582600; --0.01513041900, 0.02512391700; -0.00903471840, 0.03498919400; --0.00618408790, 0.02227141800; -0.01096205900, -0.00920153520; -0.00262835580, -0.00765528570; -0.01114218200, 0.00619863290; --0.00919430790, 0.01755913200; -0.01006375400, 0.01441648800; --0.01990465700, 0.00916741770; -0.00855497720, -0.00323036000; --0.01369815600, 0.00361482240; --0.00712474120, 0.01056456100; --0.01264778000, 0.00232601930; --0.01423405400, -0.00320915910; --0.00016743283, 0.00840220560; -0.00285416310, 0.01212758900; --0.00345522980, -0.01240091400; --0.01061054000, -0.00392867620; --0.01603832900, 0.00257474180; -0.00324895860, 0.01867151600; --0.00291754020, 0.01065674500; -0.02361004800, 0.01609781500; --0.00318450010, 0.00712827010; -0.02139297300, 0.01445064800; -0.01460282300, -0.00449260470; -0.00647488450, 0.02045964500; -0.00854365700, -0.00148195210; --0.02251529400, -0.00256425170; -0.00222816500, -0.01526768300; -0.02185776000, -0.00714712190; --0.00455624340, -0.00160773030; --0.01246960000, 0.00150635870; -0.00924045130, -0.00910181770; -0.00343446870, 0.01052361000; -0.01349456500, -0.01018272900; --0.00740446960, -0.00215583630; -0.00813427010, 0.00314027880; --0.00739251150, -0.01104516400; --0.00135688900, -0.00758587260; -0.01004834800, 0.00714729720; -0.00071365274, 0.00981284720; -0.00354068790, -0.01254811000; --0.02248783700, 0.00397571800; --0.00865090470, 0.00869799720; -0.00755320970, -0.00274643140; -0.00718197010, -0.01057977500; --0.00890055570, -0.01187215200; --0.00221861280, -0.00737277380; --0.00176862730, -0.00544962520; --0.01488865900, -0.00755715830; --0.01003201200, -0.01536865400; --0.00885387310, 0.00157814460; --0.01057416100, -0.00872661580; -0.00529372600, -0.02309533000; --0.00129770280, 0.00439926800; --0.00471011830, 0.00686916260; -0.00221095220, -0.00075376512; -0.00396970840, -0.00307360450; --0.00949946950, -0.00932127890; --0.01425166300, -0.00887158980; --0.00839041170, -0.00739858640; -0.01094292700, -0.00463808010; --0.01503297800, -0.00486242570; --0.00780511670, -0.00013977193; -0.00295906390, -0.00244925080; -0.00888417030, -0.00027793976; --0.00264289810, -0.00356239480; --0.00233235380, 0.00853562660; -0.00999011710, -0.01266408700; -0.00615571440, -0.01048649200; -0.00129589980, -0.02057649900; --0.00167519580, -0.00756073410; -0.00573725950, -0.00893045730; --0.01489402600, 0.00410294180; -0.02847956800, -0.00493285520; --0.01474864500, -0.00667757730; -0.01322265000, -0.01081593400; --0.01326839900, -0.01371889900; -0.01640160600, -0.01247788100; --0.00374336080, 0.00492074290; -0.00615137690, 0.01806502100; -0.01356203500, 0.01259282000; --0.01542659000, 0.00767045720; -0.00642653950, -0.00537146090; -0.00310662030, 0.00506285650; --0.00504839670, 0.00859490920; -0.00355458360, -0.00183994500; --0.02023486200, 0.00574867890; -0.00454694680, 0.01137622400; --0.00387160520, 0.01413229400; --0.01348735800, 0.00439081620; -0.01672376100, 0.00070763533; --0.00455330340, -0.00686520060; -0.00822146830, -0.01299495800; --0.00426795680, 0.00457871690; -0.00550981790, 0.00756567730; --0.01690307400, -0.00726203990; -0.01440696000, -0.01560053400; -0.00957262890, -0.01337257400; --0.00220497700, -0.00441573200; --0.00056364617, -0.00045505510; --0.00194646630, 0.00321663400; -0.01391187800, -0.01801557100; -0.00082409925, -0.01950009600; --0.01465276400, -0.00260673980; --0.00650069260, -0.01902260000; -0.00029876759, -0.01215615700; -0.01261499800, -0.01651988700; -0.00063004297, -0.02457780800; -0.00169295250, 0.00033544910; --0.00976376420, 0.00505643970; --0.00711589770, -0.00639119460; -0.01025748200, -0.00422405210; --0.00945158550, 0.00792116440; --0.01345565600, -0.00015260044; -0.00347003790, -0.00603041040; --0.01301538300, -0.01133294300; --0.00750695770, -0.00933159140; --0.00440517780, -0.02171622400; --0.00147922330, -0.02082012000; --0.00906688280, -0.02642304400; -0.00194159560, -0.02100981100; --0.00420262710, -0.00838592350; -0.01891564200, 0.01082611100; -0.00182342580, -0.00240049780; --0.01810654000, 0.01711595900; --0.00212834600, 0.00352360610; -0.00178391370, -0.00108616550; --0.00043459404, 0.00088082942; --0.00412604630, 0.01755816600; --0.00064959885, 0.01457685600; -0.01347751700, 0.00931501890; -0.00352526210, 0.00083007064; --0.01322128800, -0.00201091000; -0.00009614403, -0.00995798470; -0.00444349320, -0.01249145900; -0.00425595950, -0.00116484430; --0.01175602700, 0.00285725700; -0.00657894370, 0.00180430300; --0.00704443210, -0.00289686610; --0.00639969420, 0.00144511130; --0.01682459800, -0.01084454800; -0.00046732062, -0.01183596800; --0.00265618720, -0.00617053630; --0.00627824550, -0.01772563100; --0.01435354300, -0.00991358750; -0.00428677970, 0.01192595200; -0.00863044650, 0.00914107900; --0.00273840730, -0.00467048220; -0.01769520800, -0.01364493500; --0.00860223420, -0.00593776970; -0.00834198560, -0.00768299240; --0.01394435200, -0.01339647000; --0.00251396410, -0.02358333200; -0.00252897310, 0.00127176740; -0.00229634080, 0.01985044500; --0.01441004500, 0.00210260990; -0.00994943720, 0.01327428000; --0.02038994400, 0.01331653800; -0.01941131500, 0.00250981050; --0.02126588500, 0.00117877630; -0.01703305400, -0.00767290020; --0.01349053100, -0.00602226180; --0.01591448200, -0.00589764240; -0.00843590470, 0.01499918200; --0.00014857487, 0.00860687000; --0.02363695800, -0.00112907670; --0.00706394760, -0.00303277220; --0.01303618000, 0.01329845500; --0.00483198940, -0.02019482500; -0.00339302700, 0.00572997660; --0.00551248650, 0.00769795860; -0.00419796130, 0.00406189010; --0.00370703540, 0.00782197680; -0.00867027450, 0.00822771140; -0.00596786670, 0.02899416200; -0.00681206890, 0.02001652400; -0.00165106500, 0.00849942220; -0.01299251700, 0.00086235046; --0.00748960250, 0.00782463780; -0.00209973650, 0.00815596800; --0.00850592120, 0.02334669100; -0.01134628100, 0.01134613400; --0.01352224100, -0.00836556270; -0.00671531310, -0.01956063600; --0.00242272570, -0.00033519061; -0.01284221800, -0.00689856370; --0.01145770400, -0.01209985200; -0.00424026140, -0.00680320230; -0.00499683310, -0.00186745700; --0.00379175090, -0.00973519550; --0.00284374760, -0.00534973380; -0.00751068230, -0.00172811330; --0.00973646530, -0.01550932400; -0.01166327400, -0.01425923100; -0.00160914390, -0.00604851180; --0.00663530550, -0.00054579530; -0.00060567236, 0.02071117500; --0.00036915903, 0.01075306500; --0.02211141600, 0.01878292800; -0.00686511410, 0.00102341950; --0.00340655980, 0.00238579960; --0.00067203259, 0.00114114460; --0.00102357060, 0.00753831560; --0.00768802670, -0.00839238920; -0.01638687000, 0.00724520850; --0.00347730340, 0.00605236490; -0.00269696720, 0.02358320200; --0.01185299400, -0.00448258220; --0.00641221420, 0.00183018270; -0.02135322200, 0.00817785940; -0.00869419570, -0.00233532870; --0.00769650030, -0.00544744100; -0.00878221650, -0.00288025810; --0.00427262690, -0.00458403970; -0.01034842700, -0.00944620050; -0.00019401874, -0.02223294900; --0.00148483690, -0.00943247910; --0.00436740400, -0.01781865300; -0.00173273960, -0.00608950980; --0.01099621500, -0.00400127680; -0.02741524200, -0.01422095500; --0.00882605320, -0.00466699960; -0.01370161600, -0.01526308600; -0.00054116472, -0.00448123640; -0.00621596090, 0.00724029820; --0.01069932100, -0.00560117420; --0.01421629600, 0.00928500080; -0.01192448400, 0.02028709800; --0.01069542700, 0.01139402200; -0.01009124900, 0.00256825410; -0.00127767120, 0.00434814080; -0.00499351370, -0.00928891760; --0.00473548910, -0.00480540750; -0.00740867780, 0.00620164840; --0.00569582270, -0.00336372610; -0.02118048300, 0.00751171350; --0.02275689800, 0.00448348720; --0.00180431540, 0.00477640310; --0.00343045450, 0.02132982500; --0.00110349160, 0.01799333500; -0.00566623340, 0.00824425200; -0.01008643600, -0.01564701600; -0.01109274800, -0.01687864900; --0.01099148700, -0.01485227600; -0.02434629100, -0.02618405000; -0.00145410160, -0.01696036900; --0.02344772100, 0.00088506469; -0.01081117400, 0.01607764500; --0.01274696100, 0.01073171700; --0.02814399500, -0.01204674900; -0.01467717300, 0.01001183700; --0.01282640100, 0.00785533930; --0.00039151466, -0.00158353920; -0.00506089730, 0.01103509500; -0.00520334890, 0.00764525420; --0.00791932050, 0.01578666600; --0.02282695200, 0.02060965800; --0.00477700370, 0.00444865870; --0.00001976087, 0.00925757550; -0.00031481039, -0.01739030000; -0.01023393500, -0.00412322340; --0.00657133560, 0.01098436400; -0.01332517600, 0.01175247000; -0.00853561840, 0.01257092400; --0.00990227900, 0.00971206290; -0.00601343650, 0.01676401700; -0.02034657200, 0.00380624610; --0.01610970400, -0.00382222490; --0.00784886630, -0.01541948200; --0.01486246300, 0.00046089183; -0.00059140790, 0.00977498470; -0.00131100280, 0.01144934500; --0.00249520130, 0.00763555490; --0.00995953580, 0.00947764900; -0.00515067260, -0.00447725650; --0.00628485890, -0.00625777520; --0.00055236814, -0.00045996980; -0.00907149900, 0.00550255670; --0.02189032300, 0.00647248100; -0.02009786100, 0.00745576110; --0.00891947350, -0.01155851100; -0.00125060520, -0.01440449400; --0.00331509880, -0.01211877600; -0.00176437740, 0.00308533290; --0.00423796010, 0.00764018890; -0.00502629330, -0.00524800480; --0.01859839300, -0.01602257900; -0.00760957450, -0.00063382743; -0.01352106500, -0.02070491800; --0.01484082600, -0.01837788900; --0.00180805220, 0.00180058220; -0.00646895960, -0.01067731900; --0.00319460360, 0.00204543950; -0.01283819000, 0.00788961100; -0.00897728170, 0.01235817300; --0.00911367310, 0.00216576220; -0.00247233850, 0.00197748290; -0.01385073000, -0.00628759110; --0.00244131680, -0.00549276880; -0.00247377740, 0.00010081507; -0.00223374800, 0.00167638370; -0.00622179480, 0.00636981950; --0.01451075100, 0.00349200990; -0.01701029100, 0.01655859500; -0.00540505380, 0.00805163880; --0.01032426300, 0.00545309340; -0.01498743600, 0.00845128410; -0.02407752900, 0.00198533570; --0.00960939560, 0.00853352640; --0.01023723300, 0.01335469200; --0.00270911950, 0.00849549120; --0.00369286780, -0.00121018950; -0.00826982030, 0.00814966480; --0.00479820070, -0.00430578830; -0.01720646400, 0.01156837700; -0.01664923600, -0.00173370660; --0.00369501470, 0.02465627800; --0.01376969800, 0.01146760700; -0.00789807890, 0.00927350640; --0.02031981900, 0.00182745860; -0.00893684220, -0.00310349950; --0.00058117960, -0.01036477300; -0.00398354320, 0.00524400960; --0.01072630400, 0.00893152600; --0.01281647700, 0.00198587250; -0.00527370920, -0.00790188520; --0.00006975255, 0.02076850400; --0.00795713420, 0.01823942500; -0.00709618300, 0.00210983490; -0.00385266830, 0.00600135910; --0.01078681200, -0.02391983000; -0.02052245600, -0.01704146200; --0.00944289330, -0.01192082800; --0.00394662410, -0.02925877900; -0.01354173000, -0.02406313000; --0.00718647540, -0.01098199500; -0.02058008400, -0.00638229480; --0.00854536810, -0.00450554770; -0.00866409980, -0.00330021160; --0.00686748550, -0.02114934800; -0.00445321310, -0.00847144790; -0.00801991790, -0.00241975850; --0.00120417690, -0.00393759540; --0.00494995210, -0.02696714500; --0.01267562000, -0.01038903900; -0.00353257720, -0.00908920320; --0.00975382080, 0.01760238600; --0.01260558500, 0.02760804400; --0.00316022200, 0.02508482500; -0.00082647851, 0.01143638600; -0.00479109240, -0.00074145901; -0.00524306200, -0.00265805690; --0.00578202170, 0.01897214300; -0.00893716350, -0.00482091210; --0.01982108100, -0.01158432200; -0.03126658600, 0.00409586630; --0.00273803110, -0.00161845770; --0.01761996600, 0.01334919500; -0.00757518640, 0.01502052000; --0.00292343760, 0.02766780900; -0.00547019230, 0.02912370300; -0.00907626300, 0.01593786700; --0.00455934350, 0.00063507953; -0.00508186300, 0.02238021200; -0.01289502600, -0.00593488700; -0.00236970730, 0.00388511510; -0.00883958660, -0.00257234340; -0.01720261100, 0.01188001800; --0.00006246719, -0.00203679550; --0.01575553100, -0.00676416250; -0.00814828810, -0.00356291510; -0.00379630600, -0.00175582960; -0.01519689300, 0.01032388100; -0.00604297190, -0.01207842000; -0.00784725260, 0.00484980530; -0.00757792060, 0.00642184950; -0.00097163435, -0.01346602900; --0.00080646536, -0.01005009400; --0.00544594560, -0.01436795200; --0.00170059540, 0.00889975570; --0.00234754820, 0.01182947400; -0.01225048700, 0.01299069100; --0.01026220700, 0.01595514900; --0.00944973050, 0.00843166930; -0.00874279600, -0.01267545100; --0.00362453400, 0.01054616000; --0.00084828359, -0.00199187910; -0.01428511500, -0.00406989120; --0.00882438660, -0.02808280200; -0.00704659960, -0.02179662700; --0.00410832820, -0.00192698990; --0.00147723550, -0.00896090550; -0.00459580110, 0.01065118700; --0.00605537920, -0.00488607770; --0.00027256522, -0.00401632280; --0.01978864800, -0.00626533710; -0.00607277630, -0.01497391500; --0.01143713900, -0.00323604060; -0.01228681400, -0.00172676930; --0.00793191320, -0.00843394290; -0.00991768270, -0.00966059600; -0.00992587030, -0.00349087710; -0.00505795500, -0.00671022150; -0.00788954440, 0.00332091270; -0.01182401000, -0.00092086600; --0.00660517190, -0.01039393600; -0.01134255700, -0.00751655470; -0.00038790604, -0.01755658800; --0.00807366080, 0.00988425450; --0.00088186225, 0.00561425140; --0.00923030850, 0.00486096700; -0.02739705100, 0.01565417800; --0.02436147600, -0.00475603930; --0.00474490120, 0.01578322600; -0.00832453990, 0.00998216280; --0.00713154110, -0.00411591940; -0.01586726000, -0.00728781440; -0.00901038060, 0.00388117450; --0.01278363800, 0.00560553200; --0.00341314840, -0.01414107100; --0.01413398600, 0.02152507100; --0.00084512439, 0.00416185940; --0.00213784220, -0.00065205271; -0.00447733340, -0.01064756800; -0.01404655600, -0.00371620300; -0.02279766500, 0.00569317110; --0.00682377560, -0.00308033630; -0.01124674300, -0.00598650510; --0.01376857100, -0.00734424350; -0.00966640550, 0.00595518380; --0.01042231400, -0.00339618560; --0.00210584750, -0.01492290700; -0.00793225120, -0.01773942700; --0.00746719420, -0.02023369900; -0.00320403030, -0.00425187160; --0.01498758300, -0.00172616900; --0.00125324900, -0.01646365100; --0.02719981800, -0.00720045620; -0.00507847130, -0.00507992190; -0.00408332760, -0.00696923090; -0.00206618350, -0.01585097200; --0.00266175350, -0.01324462400; --0.00031912447, 0.00100260870; --0.01038003300, 0.01981869200; --0.01218511000, 0.02173349700; -0.01136888100, 0.02204497600; --0.01202743900, 0.00829954090; --0.00021401182, -0.00175504700; --0.00596558870, 0.00380210670; -0.01569683000, 0.00347734000; -0.00801820710, -0.00144632600; --0.02250001500, 0.00504014370; -0.01240035200, -0.00942954560; -0.00858523030, -0.00623408720; --0.01626079300, 0.00397289760; -0.00723434090, 0.00783343600; --0.00919603870, -0.00059345202; -0.01085680800, 0.00243835800; --0.00888834510, 0.00445439110; --0.00052505879, 0.03196236900; -0.00407476500, 0.02115388200; -0.01036235200, 0.00961476180; -0.00176157930, 0.00765388480; --0.00053452369, -0.00819328090; -0.00703537300, 0.00742844800; --0.00014851151, 0.02083584000; -0.00393808440, -0.00220486220; -0.00068062472, -0.01090794200; -0.00162973150, 0.01016291400; -0.00956508570, 0.00314153260; -0.00040965810, 0.00424568390; --0.00342205330, 0.01575583500; --0.00666487520, 0.03253912100; -0.00357257790, -0.00193096120; --0.00479944880, 0.00276754820; --0.02008366200, 0.01813183600; -0.01024278800, 0.00899311180; -0.00331510340, 0.00874296380; --0.00367787790, 0.01032780200; -0.02355042500, 0.00879580860; --0.02098926500, -0.00010779314; -0.02242707300, -0.00613259750; --0.00708729650, -0.00601044260; -0.01401990900, 0.00501994170; -0.01116776500, 0.00055147171; --0.00789437150, 0.00307380160; --0.00079795363, 0.00071918763; -0.00024460379, -0.01076551400; -0.00413459290, -0.01001296500; --0.02104470800, 0.00080366086; -0.01176522400, 0.01678986600; --0.01816742200, 0.01265489200; --0.01569319400, -0.00779392590; --0.00283881540, -0.01456612300; -0.00040506759, 0.00058628945; -0.00945908740, 0.00075994717; --0.00979130970, -0.00461547690; -0.00265457950, 0.00878213250; --0.02489547100, -0.00853506250; -0.00102885490, 0.00684600140; --0.00130745500, -0.00382792360; -0.00762038530, -0.00423731260; --0.00147484510, 0.01924464600; -0.00727643910, 0.00989738330; --0.00160290830, -0.00187813300; -0.00428527540, -0.00219760860; --0.03317646800, 0.00116740200; -0.01658756800, 0.00518323290; -0.00785352990, -0.00838975030; --0.00451492520, 0.00547096380; --0.00320296040, -0.02426730500; -0.01417389300, -0.03256394100; --0.00661515490, -0.00421165110; -0.01470659000, -0.00042946856; --0.02350439700, 0.00348050750; -0.00366709700, 0.00938778820; --0.00046899718, 0.00674591590; -0.01975974900, 0.00026316635; --0.00441742910, -0.01386567100; -0.01032374900, -0.01708067200; --0.00343647840, -0.00627385440; -0.01341498100, -0.00152079670; --0.01328190700, 0.00750671680; --0.00194644230, 0.01508688300; --0.01114553600, 0.03635301900; --0.00904033490, 0.00672707110; -0.00213535390, 0.01554549900; --0.00147753730, 0.01329763200; -0.00116701690, -0.00008942344; -0.00341716790, -0.00317315000; --0.01381591900, -0.00277583010; -0.01813890000, -0.01732665300; --0.01199155600, -0.00610674530; -0.00444251760, 0.00143958250; -0.01005538100, -0.00644700780; --0.00343175930, -0.00473816370; -0.00077039637, 0.00638741850; -0.01094944500, 0.02697045000; --0.00052522484, 0.00372434700; --0.01200624400, 0.01233773200; --0.00631723760, -0.00616098400; --0.00267661130, -0.00189383380; -0.01800845900, 0.00251762240; --0.00070703292, -0.00777855150; -0.01011331300, 0.00476866670; -0.00535917660, -0.01284853600; -0.01971133300, -0.00711727660; -0.00471936570, -0.00527618130; --0.01922986900, -0.01071921700; -0.01058494000, -0.01208949400; -0.00252107150, -0.01009809800; --0.00635082770, -0.00325476460; --0.00338369140, -0.00678190390; --0.00560879390, 0.01429874600; --0.00730724340, 0.00839658360; -0.01073289400, 0.01332610500; -0.01411626800, 0.01741862000; --0.00578601340, 0.01236888600; --0.00640703040, 0.00204314960; --0.00277533020, 0.00809611970; -0.01131091600, 0.02231586400; --0.00290565000, 0.01281723000; --0.00466721850, 0.01066850100; -0.00003017692, -0.00045287596; -0.01184006400, 0.02096790900; --0.01807510700, 0.00007107626; -0.01200216000, 0.01695265800; --0.00233991190, -0.00762127830; -0.01731830300, -0.01470775300; --0.00871332370, -0.00536830240; -0.01416221600, -0.00020614753; --0.00720019210, -0.01392737100; --0.01677725400, -0.00963694400; -0.00376816350, -0.01806841400; --0.01168453900, -0.02520963700; --0.00242508010, -0.01003563800; --0.00398142050, -0.00574731140; -0.01750174900, -0.00421972000; -0.00585300950, -0.01083337500; -0.00418233240, -0.01247003500; --0.00614589600, -0.00520667130; -0.01135575200, 0.00930381060; -0.00591022240, -0.01228150100; --0.00330099160, -0.01714747100; -0.00461113550, 0.00279658620; -0.01844313500, -0.00381210120; --0.00730330260, -0.01948227900; -0.00114113770, 0.00359516800; --0.01340516800, 0.01142347700; -0.00242013210, 0.01479981600; --0.01177683000, 0.00005024148; --0.00140618160, 0.01536890200; --0.00496745630, 0.03046414700; -0.01227024900, 0.01537145000; -0.00015891232, 0.02228270700; --0.00275003980, 0.01807071800; -0.00213022040, 0.02195794900; --0.00456855430, -0.00847451820; -0.00368394090, 0.00167170220; -0.00053423273, -0.00101325060; -0.01502387300, -0.00299957890; --0.00364911970, 0.01043386100; -0.00292325880, 0.00369136530; --0.01000623700, 0.01065743200; --0.00737237320, 0.01173679900; -0.00470212590, -0.00172331660; -0.00064041836, -0.00112935140; -0.00801705600, 0.00908517860; --0.01752767500, 0.01340269200; --0.00167078620, 0.00984110940; --0.00736765550, -0.00183892060; -0.00171112270, 0.00325198900; --0.00459124470, 0.00333673000; -0.00090628466, -0.00136710980; --0.00953744110, -0.00330812520; -0.01382525800, -0.00074019487; -0.00182379050, 0.00271536240; --0.00144417870, -0.01965826300; -0.00262746520, -0.00738069840; --0.00315157850, -0.00579473100; --0.00149920540, -0.00471902850; -0.01724853900, -0.00444270650; --0.00323729290, 0.01599976100; -0.00818759990, 0.00475884400; --0.00670440270, 0.00662529590; -0.00761535810, -0.01531597000; --0.00898965620, -0.01407707000; --0.00095826091, 0.00110351110; -0.01922539900, 0.00976795960; -0.00107279500, -0.00201196850; -0.00184468230, -0.01900434900; -0.00206808720, -0.01044463400; -0.01012566700, -0.00995885900; --0.00264965050, -0.00197648630; -0.01007788900, -0.01722402900; -0.00857747020, -0.00978182180; --0.00390662100, -0.00260237180; -0.00692129190, -0.00378992080; -0.00029091915, -0.00259509570; --0.00360680420, -0.00713074060; --0.00860419840, -0.02057721600; -0.00044751379, -0.01449312400; --0.00145591500, -0.01523862700; -0.01682939900, -0.01270554100; -0.00567881680, -0.01943714400; -0.00848238640, -0.00223198500; -0.00325092290, -0.00082652871; -0.01223402300, 0.00644947070; -0.00051464095, 0.00898356600; -0.01260583200, 0.00834137450; -0.01064180800, -0.00190874350; -0.01005380200, -0.00116214780; --0.00116234090, -0.00675879300; --0.02332964500, -0.01838281800; --0.00696804150, -0.00944441820; --0.01819834100, -0.01808908500; -0.02201795200, -0.00716774540; --0.01672468800, -0.00826797040; -0.01170834800, -0.00949888840; --0.00615648660, -0.00355936780; -0.00535839890, 0.00559401360; --0.00703042400, -0.01059598600; -0.00318876840, 0.00011921905; --0.01874264500, 0.00790409920; -0.00552417410, 0.00766524880; --0.01497631100, -0.00238697410; --0.00439945850, 0.00914147460; -0.01828331600, -0.00206804820; -0.00068550745, -0.00122205150; --0.00759101970, -0.01153777900; -0.00648242600, -0.01640673600; --0.00543452600, -0.02063951400; -0.00155147620, -0.02622296300; --0.00564122550, -0.01103051900; -0.00341228520, 0.00583169540; -0.00646375290, 0.00936322370; --0.00478098810, 0.01100696200; -0.00573895680, -0.00239250900; --0.00970467940, 0.00871843140; -0.02038830400, 0.01480759600; -0.00026758833, 0.02045451100; -0.00791676330, 0.01696119900; -0.00151902060, 0.00369441970; -0.00695727800, -0.00513502650; --0.01493114700, 0.00259436800; -0.01356549700, -0.00125019700; -0.01129927200, -0.01805236600; --0.01605158000, -0.00110185760; -0.01796653700, -0.01000584500; --0.01611534000, -0.00357616450; -0.00480241820, -0.01235228300; -0.00765884520, 0.00199081530; --0.00445450970, 0.00373594290; -0.00836337530, 0.00844062310; -0.00000608640, 0.00814252730; --0.00242506490, 0.00107690310; --0.00655880720, -0.01044158000; -0.00959842540, -0.01282298400; -0.00710086670, -0.00628089330; --0.01539525500, 0.00145629030; --0.01019127500, 0.00506089250; --0.00415539980, 0.00121860340; --0.00222234300, -0.00235775530; -0.00145298240, 0.00074290054; -0.00383045620, 0.00499606180; --0.01581364300, 0.00991048820; --0.00505534040, 0.00362636340; -0.01275955400, -0.00852445050; --0.00646790680, -0.00849281040; -0.00822635380, 0.00506450010; --0.00999777920, 0.01192172300; -0.01259965900, -0.01267426000; --0.00334331530, -0.01193505000; -0.00531845400, 0.00036486233; -0.00324434670, 0.01617751400; --0.00182198070, 0.01450107800; --0.01316162900, 0.00575151330; --0.00245819090, -0.00185123220; -0.00716449280, 0.00787328720; --0.00111474240, 0.00293388970; --0.01296516800, -0.00225148550; -0.00284074300, -0.00331728310; -0.01133071500, 0.02057075900; --0.00100379480, 0.01280891700; -0.00049387445, 0.00507951680; -0.00229614130, -0.00764568280; --0.01313835900, -0.00525744170; -0.00966316020, -0.00556556230; -0.01118421300, -0.00490035560; -0.01672044300, -0.00988298390; --0.01088174000, -0.00216302190; --0.00920015300, 0.00190343440; -0.00027256857, -0.00606717780; -0.00745269630, 0.00488672340; --0.00485878040, 0.00337006910; --0.01014946800, 0.00628172350; -0.00133496050, -0.00095504333; -0.01278446800, 0.00344898280; --0.00703416400, 0.00739247270; -0.01328898700, 0.00304838790; --0.01491870500, 0.00633638140; -0.00873045630, 0.00319640990; -0.00254909610, 0.01211332200; -0.00232342310, 0.00470528570; --0.00764997870, -0.00240813430; --0.01090000900, -0.01170578800; -0.00843239100, -0.01170118700; --0.02507916900, -0.01158650100; -0.04003462300, -0.01629908500; --0.01222446500, -0.01477344200; -0.00521617900, -0.00968336430; -0.01952769300, -0.02338928900; --0.00455805500, -0.01208632300; --0.00421777900, -0.01515016500; --0.02292950600, 0.00681974800; -0.02065804000, -0.01601951200; --0.01175698600, -0.01763198100; -0.00847885710, -0.01709137000; --0.00522204640, 0.00520781450; -0.01653303200, 0.01230743800; -0.01491689300, 0.02278097800; --0.00390021000, -0.00599679960; -0.00987391320, -0.01527627300; --0.01292332700, -0.01725711000; --0.00611290270, -0.00008627481; -0.01173359600, 0.00525802720; -0.00023658130, 0.00219369170; -0.00527818840, -0.01008107600; --0.00805139170, -0.01193710000; --0.01872491200, 0.00860016370; --0.01259698500, -0.01756964500; --0.00088728350, -0.01512096000; --0.01535824800, -0.01295353000; -0.02003583600, -0.00614556620; --0.00662873120, 0.00258939970; -0.02039917600, -0.00012182475; --0.00137236040, -0.00075700965; --0.01450454300, -0.00207827570; -0.01535757000, 0.00707412260; --0.01704817500, -0.00431544930; -0.00832049550, -0.01881308400; -0.00788077160, -0.01301967100; --0.00535764100, -0.02307963700; -0.01684468900, -0.01761785700; --0.00494331070, -0.02023850500; --0.01844518300, -0.01120281300; -0.01030114100, -0.00246253960; -0.00737732820, 0.01367079900; -0.00930385080, -0.01638037700; -0.01184141400, -0.00128950800; --0.02316092800, 0.00518400230; -0.01259350700, 0.01851841100; -0.00032334407, 0.00708510310; --0.00380004070, 0.01466849000; -0.00572216670, 0.02763848700; -0.01450073300, 0.02130598400; --0.00061716695, 0.01299269100; -0.00032716641, 0.02931071500; -0.00102466110, 0.01050204800; --0.00339657480, -0.00413612190; -0.01311750600, -0.00235546960; -0.00609382540, 0.00646251750; --0.00126880700, 0.01452674700; --0.00768738760, 0.01051401500; -0.01058750900, 0.00661389120; --0.00857671250, 0.00564091490; -0.00603614820, 0.00790147090; --0.00383731350, 0.01219309200; --0.00750234770, -0.00565016960; --0.01197183700, -0.01579100100; -0.00940025550, 0.01919136600; --0.00001261024, 0.02626728500; --0.01119718500, 0.00144775010; -0.02249039100, 0.02039881000; --0.00379732890, -0.01609038000; -0.01565908800, -0.00588713290; -0.00875294490, 0.00373467350; -0.00256396420, 0.01632317700; --0.00451786920, -0.00480455360; --0.00790291250, 0.00345569200; --0.01455265100, -0.01382336400; -0.01350253300, 0.00019931557; --0.00674284800, 0.00449999260; -0.02374096100, -0.00641924120; --0.02211973900, -0.00053401624; -0.01207118500, -0.00983951590; --0.00702998800, -0.02173194800; -0.00650176870, -0.03939793300; -0.01983586800, -0.01688164300; --0.00523048000, -0.01586871000; --0.00024937096, -0.00762047480; -0.01848711000, -0.02202737800; -0.00320481510, 0.00115403630; --0.00339570830, -0.00416020450; -0.00292867830, -0.00800372950; --0.00085958037, -0.00702345910; --0.00661261130, -0.00240180080; -0.00915375200, -0.00072184277; --0.02097610500, 0.00164769990; -0.00794447800, 0.00132242720; -0.00417510660, -0.00030181197; --0.00634899330, -0.01677800600; -0.00999671400, -0.00762022470; --0.01004270400, 0.00644466200; -0.00245296560, -0.00189053390; --0.00558639080, -0.00629843410; -0.00063566426, 0.00748679840; --0.00197196620, -0.01231472900; --0.00858143530, -0.00982022010; -0.01118201300, -0.00005704770; --0.01452712100, 0.00525489720; -0.00556580190, -0.00614996780; -0.00722027820, 0.00126887710; --0.00106240920, 0.00248088000; -0.00266047030, 0.00506315460; --0.01615042800, -0.00024735048; -0.00690899540, -0.02230154100; -0.00016806370, -0.00703005220; -0.01157961100, -0.00046847502; --0.00569027140, -0.00074088147; -0.00279183700, -0.01112727400; -0.01159847500, -0.01397495400; --0.01618859800, -0.03057030300; -0.00051325767, -0.00865006790; -0.00549707250, 0.00357878980; --0.00970590920, -0.00253900500; -0.01545455300, 0.00679668570; --0.01066617100, -0.00621207310; -0.00575491460, -0.00657640880; --0.00605682630, 0.01005724800; --0.00028086638, 0.01720437100; -0.00314218690, -0.00112510120; --0.01232869600, 0.00529184200; -0.00156071380, 0.00332171610; -0.01586504900, -0.00687919610; --0.00700561370, 0.00627937710; -0.00416313760, 0.01338622200; --0.00469103860, -0.00207565840; --0.00515967500, -0.02677465800; --0.00329796470, -0.02347414900; -0.00458593860, -0.01994345300; -0.00449779160, -0.01500910700; --0.01450006100, -0.02433756900; --0.00982530810, 0.00515777190; -0.02169452900, 0.00395559630; --0.02732960700, -0.01296309000; --0.00943391470, 0.00970794530; -0.00883871190, -0.00847782470; --0.00641242250, -0.00159739350; --0.00622211610, -0.00023249961; -0.01103231400, 0.01345929400; --0.01604871600, 0.01444581500; -0.00408581520, 0.00391976300; --0.00585816760, -0.00136833520; -0.01285105500, -0.01355861400; --0.01282979900, -0.02075753400; -0.00240514790, -0.00583408830; --0.00821620830, -0.00917124260; -0.01161346900, 0.00589059210; --0.00416354780, 0.01478035400; -0.00910147760, 0.00162353340; -0.00645020290, -0.00029596225; -0.00664065850, 0.00334591190; --0.01628421500, -0.01667108200; -0.01017428900, -0.01182986900; --0.01740919900, 0.00421845090; -0.01419528300, -0.00170271310; --0.01832044100, -0.00271804760; -0.00478798390, 0.01451607600; --0.01552720100, 0.00680642330; -0.00557794300, 0.01041172100; -0.00418925410, -0.00240398610; --0.00542981940, -0.01092214200; -0.01256706900, -0.01379128400; --0.01899332900, -0.00274706900; -0.00907149380, -0.00663018700; -0.01506829200, -0.00293179520; --0.01827722500, -0.00283953570; --0.00150598710, 0.00448947120; -0.00689968130, 0.01392841800; -0.00838313220, 0.00056270157; --0.01889400800, 0.00445784700; -0.01083541500, -0.00433810380; -0.00975696280, -0.01959502400; --0.00687770220, -0.01815605200; --0.01112640300, -0.01494359600; --0.00472052850, -0.01500657700; --0.01367499100, -0.00267410440; -0.01489290400, -0.00432076310; --0.00262017640, -0.00290406560; --0.00261222360, 0.00098096246; -0.00452692100, -0.01865841900; -0.00118941740, 0.00323370830; -0.00029588303, 0.00675359970; --0.01081920700, 0.02384338300; -]; + 0.00000000000, 0.00000000000; + -0.00485199480, -0.00034195121; + -0.00369702440, -0.01212953600; + 0.01577573000, -0.00131845390; + -0.01132415000, -0.00364839770; + 0.01158109800, -0.00262917340; + -0.00385969150, -0.00374515890; + -0.00605244640, 0.00760215990; + -0.00027881367, -0.01014485600; + 0.00328156560, -0.00358791610; + -0.01152432500, -0.00064990774; + -0.00417541420, -0.02726543200; + 0.01165937200, -0.01565713900; + 0.00327415420, -0.01403374100; + -0.00262015080, -0.01667459700; + -0.01146453600, -0.01088215300; + 0.00521521470, -0.02177149300; + 0.00767451980, -0.01671285200; + 0.01259883800, 0.00306304710; + -0.01790411600, -0.01240549400; + 0.00451096210, 0.00713706070; + 0.02171339100, -0.00405944740; + -0.00984485920, -0.00280935440; + 0.00303833090, -0.00658279110; + 0.00496516950, -0.00329239970; + 0.01425115100, -0.01417161800; + -0.00848068480, -0.01036798700; + 0.01384593500, 0.00307931740; + -0.00911261030, -0.00409005360; + 0.00104231040, -0.00503950650; + -0.01669998300, -0.00919063320; + 0.02192734300, -0.00900963420; + 0.00895830410, 0.00889444930; + -0.00078210473, 0.00303194750; + -0.00369206110, 0.00307427120; + 0.01569838000, -0.00494547550; + -0.00518999260, -0.02284842300; + 0.01668021700, -0.02845341900; + -0.02568046200, -0.03263100900; + 0.00662056690, -0.00759856640; + -0.00051553622, -0.00266545800; + 0.00588163920, 0.00553735730; + 0.00496782960, -0.00439611810; + -0.00917153500, -0.02059437900; + 0.01824072100, -0.01633834000; + 0.01007005900, -0.02248933700; + -0.00560011310, -0.02417716500; + -0.00769812730, -0.00017818698; + 0.00133784330, -0.00149211110; + -0.01435760300, 0.00692602660; + 0.00404759460, -0.01017014800; + -0.00663831950, -0.00315748290; + -0.00085548858, -0.02827386400; + 0.00421366420, -0.02999430500; + 0.00228340080, 0.00351766350; + 0.00067972662, 0.00394969830; + 0.00010249414, -0.00227112120; + 0.01352092200, 0.00054581385; + -0.01119695100, 0.01346546700; + 0.03037738600, 0.01926781500; + -0.00648092580, 0.03341492100; + 0.00742909040, 0.03054532700; + 0.00348382550, 0.01877144600; + 0.00246629280, 0.00970566090; + 0.01095858000, 0.01093582600; + -0.01513041900, 0.02512391700; + 0.00903471840, 0.03498919400; + -0.00618408790, 0.02227141800; + 0.01096205900, -0.00920153520; + 0.00262835580, -0.00765528570; + 0.01114218200, 0.00619863290; + -0.00919430790, 0.01755913200; + 0.01006375400, 0.01441648800; + -0.01990465700, 0.00916741770; + 0.00855497720, -0.00323036000; + -0.01369815600, 0.00361482240; + -0.00712474120, 0.01056456100; + -0.01264778000, 0.00232601930; + -0.01423405400, -0.00320915910; + -0.00016743283, 0.00840220560; + 0.00285416310, 0.01212758900; + -0.00345522980, -0.01240091400; + -0.01061054000, -0.00392867620; + -0.01603832900, 0.00257474180; + 0.00324895860, 0.01867151600; + -0.00291754020, 0.01065674500; + 0.02361004800, 0.01609781500; + -0.00318450010, 0.00712827010; + 0.02139297300, 0.01445064800; + 0.01460282300, -0.00449260470; + 0.00647488450, 0.02045964500; + 0.00854365700, -0.00148195210; + -0.02251529400, -0.00256425170; + 0.00222816500, -0.01526768300; + 0.02185776000, -0.00714712190; + -0.00455624340, -0.00160773030; + -0.01246960000, 0.00150635870; + 0.00924045130, -0.00910181770; + 0.00343446870, 0.01052361000; + 0.01349456500, -0.01018272900; + -0.00740446960, -0.00215583630; + 0.00813427010, 0.00314027880; + -0.00739251150, -0.01104516400; + -0.00135688900, -0.00758587260; + 0.01004834800, 0.00714729720; + 0.00071365274, 0.00981284720; + 0.00354068790, -0.01254811000; + -0.02248783700, 0.00397571800; + -0.00865090470, 0.00869799720; + 0.00755320970, -0.00274643140; + 0.00718197010, -0.01057977500; + -0.00890055570, -0.01187215200; + -0.00221861280, -0.00737277380; + -0.00176862730, -0.00544962520; + -0.01488865900, -0.00755715830; + -0.01003201200, -0.01536865400; + -0.00885387310, 0.00157814460; + -0.01057416100, -0.00872661580; + 0.00529372600, -0.02309533000; + -0.00129770280, 0.00439926800; + -0.00471011830, 0.00686916260; + 0.00221095220, -0.00075376512; + 0.00396970840, -0.00307360450; + -0.00949946950, -0.00932127890; + -0.01425166300, -0.00887158980; + -0.00839041170, -0.00739858640; + 0.01094292700, -0.00463808010; + -0.01503297800, -0.00486242570; + -0.00780511670, -0.00013977193; + 0.00295906390, -0.00244925080; + 0.00888417030, -0.00027793976; + -0.00264289810, -0.00356239480; + -0.00233235380, 0.00853562660; + 0.00999011710, -0.01266408700; + 0.00615571440, -0.01048649200; + 0.00129589980, -0.02057649900; + -0.00167519580, -0.00756073410; + 0.00573725950, -0.00893045730; + -0.01489402600, 0.00410294180; + 0.02847956800, -0.00493285520; + -0.01474864500, -0.00667757730; + 0.01322265000, -0.01081593400; + -0.01326839900, -0.01371889900; + 0.01640160600, -0.01247788100; + -0.00374336080, 0.00492074290; + 0.00615137690, 0.01806502100; + 0.01356203500, 0.01259282000; + -0.01542659000, 0.00767045720; + 0.00642653950, -0.00537146090; + 0.00310662030, 0.00506285650; + -0.00504839670, 0.00859490920; + 0.00355458360, -0.00183994500; + -0.02023486200, 0.00574867890; + 0.00454694680, 0.01137622400; + -0.00387160520, 0.01413229400; + -0.01348735800, 0.00439081620; + 0.01672376100, 0.00070763533; + -0.00455330340, -0.00686520060; + 0.00822146830, -0.01299495800; + -0.00426795680, 0.00457871690; + 0.00550981790, 0.00756567730; + -0.01690307400, -0.00726203990; + 0.01440696000, -0.01560053400; + 0.00957262890, -0.01337257400; + -0.00220497700, -0.00441573200; + -0.00056364617, -0.00045505510; + -0.00194646630, 0.00321663400; + 0.01391187800, -0.01801557100; + 0.00082409925, -0.01950009600; + -0.01465276400, -0.00260673980; + -0.00650069260, -0.01902260000; + 0.00029876759, -0.01215615700; + 0.01261499800, -0.01651988700; + 0.00063004297, -0.02457780800; + 0.00169295250, 0.00033544910; + -0.00976376420, 0.00505643970; + -0.00711589770, -0.00639119460; + 0.01025748200, -0.00422405210; + -0.00945158550, 0.00792116440; + -0.01345565600, -0.00015260044; + 0.00347003790, -0.00603041040; + -0.01301538300, -0.01133294300; + -0.00750695770, -0.00933159140; + -0.00440517780, -0.02171622400; + -0.00147922330, -0.02082012000; + -0.00906688280, -0.02642304400; + 0.00194159560, -0.02100981100; + -0.00420262710, -0.00838592350; + 0.01891564200, 0.01082611100; + 0.00182342580, -0.00240049780; + -0.01810654000, 0.01711595900; + -0.00212834600, 0.00352360610; + 0.00178391370, -0.00108616550; + -0.00043459404, 0.00088082942; + -0.00412604630, 0.01755816600; + -0.00064959885, 0.01457685600; + 0.01347751700, 0.00931501890; + 0.00352526210, 0.00083007064; + -0.01322128800, -0.00201091000; + 0.00009614403, -0.00995798470; + 0.00444349320, -0.01249145900; + 0.00425595950, -0.00116484430; + -0.01175602700, 0.00285725700; + 0.00657894370, 0.00180430300; + -0.00704443210, -0.00289686610; + -0.00639969420, 0.00144511130; + -0.01682459800, -0.01084454800; + 0.00046732062, -0.01183596800; + -0.00265618720, -0.00617053630; + -0.00627824550, -0.01772563100; + -0.01435354300, -0.00991358750; + 0.00428677970, 0.01192595200; + 0.00863044650, 0.00914107900; + -0.00273840730, -0.00467048220; + 0.01769520800, -0.01364493500; + -0.00860223420, -0.00593776970; + 0.00834198560, -0.00768299240; + -0.01394435200, -0.01339647000; + -0.00251396410, -0.02358333200; + 0.00252897310, 0.00127176740; + 0.00229634080, 0.01985044500; + -0.01441004500, 0.00210260990; + 0.00994943720, 0.01327428000; + -0.02038994400, 0.01331653800; + 0.01941131500, 0.00250981050; + -0.02126588500, 0.00117877630; + 0.01703305400, -0.00767290020; + -0.01349053100, -0.00602226180; + -0.01591448200, -0.00589764240; + 0.00843590470, 0.01499918200; + -0.00014857487, 0.00860687000; + -0.02363695800, -0.00112907670; + -0.00706394760, -0.00303277220; + -0.01303618000, 0.01329845500; + -0.00483198940, -0.02019482500; + 0.00339302700, 0.00572997660; + -0.00551248650, 0.00769795860; + 0.00419796130, 0.00406189010; + -0.00370703540, 0.00782197680; + 0.00867027450, 0.00822771140; + 0.00596786670, 0.02899416200; + 0.00681206890, 0.02001652400; + 0.00165106500, 0.00849942220; + 0.01299251700, 0.00086235046; + -0.00748960250, 0.00782463780; + 0.00209973650, 0.00815596800; + -0.00850592120, 0.02334669100; + 0.01134628100, 0.01134613400; + -0.01352224100, -0.00836556270; + 0.00671531310, -0.01956063600; + -0.00242272570, -0.00033519061; + 0.01284221800, -0.00689856370; + -0.01145770400, -0.01209985200; + 0.00424026140, -0.00680320230; + 0.00499683310, -0.00186745700; + -0.00379175090, -0.00973519550; + -0.00284374760, -0.00534973380; + 0.00751068230, -0.00172811330; + -0.00973646530, -0.01550932400; + 0.01166327400, -0.01425923100; + 0.00160914390, -0.00604851180; + -0.00663530550, -0.00054579530; + 0.00060567236, 0.02071117500; + -0.00036915903, 0.01075306500; + -0.02211141600, 0.01878292800; + 0.00686511410, 0.00102341950; + -0.00340655980, 0.00238579960; + -0.00067203259, 0.00114114460; + -0.00102357060, 0.00753831560; + -0.00768802670, -0.00839238920; + 0.01638687000, 0.00724520850; + -0.00347730340, 0.00605236490; + 0.00269696720, 0.02358320200; + -0.01185299400, -0.00448258220; + -0.00641221420, 0.00183018270; + 0.02135322200, 0.00817785940; + 0.00869419570, -0.00233532870; + -0.00769650030, -0.00544744100; + 0.00878221650, -0.00288025810; + -0.00427262690, -0.00458403970; + 0.01034842700, -0.00944620050; + 0.00019401874, -0.02223294900; + -0.00148483690, -0.00943247910; + -0.00436740400, -0.01781865300; + 0.00173273960, -0.00608950980; + -0.01099621500, -0.00400127680; + 0.02741524200, -0.01422095500; + -0.00882605320, -0.00466699960; + 0.01370161600, -0.01526308600; + 0.00054116472, -0.00448123640; + 0.00621596090, 0.00724029820; + -0.01069932100, -0.00560117420; + -0.01421629600, 0.00928500080; + 0.01192448400, 0.02028709800; + -0.01069542700, 0.01139402200; + 0.01009124900, 0.00256825410; + 0.00127767120, 0.00434814080; + 0.00499351370, -0.00928891760; + -0.00473548910, -0.00480540750; + 0.00740867780, 0.00620164840; + -0.00569582270, -0.00336372610; + 0.02118048300, 0.00751171350; + -0.02275689800, 0.00448348720; + -0.00180431540, 0.00477640310; + -0.00343045450, 0.02132982500; + -0.00110349160, 0.01799333500; + 0.00566623340, 0.00824425200; + 0.01008643600, -0.01564701600; + 0.01109274800, -0.01687864900; + -0.01099148700, -0.01485227600; + 0.02434629100, -0.02618405000; + 0.00145410160, -0.01696036900; + -0.02344772100, 0.00088506469; + 0.01081117400, 0.01607764500; + -0.01274696100, 0.01073171700; + -0.02814399500, -0.01204674900; + 0.01467717300, 0.01001183700; + -0.01282640100, 0.00785533930; + -0.00039151466, -0.00158353920; + 0.00506089730, 0.01103509500; + 0.00520334890, 0.00764525420; + -0.00791932050, 0.01578666600; + -0.02282695200, 0.02060965800; + -0.00477700370, 0.00444865870; + -0.00001976087, 0.00925757550; + 0.00031481039, -0.01739030000; + 0.01023393500, -0.00412322340; + -0.00657133560, 0.01098436400; + 0.01332517600, 0.01175247000; + 0.00853561840, 0.01257092400; + -0.00990227900, 0.00971206290; + 0.00601343650, 0.01676401700; + 0.02034657200, 0.00380624610; + -0.01610970400, -0.00382222490; + -0.00784886630, -0.01541948200; + -0.01486246300, 0.00046089183; + 0.00059140790, 0.00977498470; + 0.00131100280, 0.01144934500; + -0.00249520130, 0.00763555490; + -0.00995953580, 0.00947764900; + 0.00515067260, -0.00447725650; + -0.00628485890, -0.00625777520; + -0.00055236814, -0.00045996980; + 0.00907149900, 0.00550255670; + -0.02189032300, 0.00647248100; + 0.02009786100, 0.00745576110; + -0.00891947350, -0.01155851100; + 0.00125060520, -0.01440449400; + -0.00331509880, -0.01211877600; + 0.00176437740, 0.00308533290; + -0.00423796010, 0.00764018890; + 0.00502629330, -0.00524800480; + -0.01859839300, -0.01602257900; + 0.00760957450, -0.00063382743; + 0.01352106500, -0.02070491800; + -0.01484082600, -0.01837788900; + -0.00180805220, 0.00180058220; + 0.00646895960, -0.01067731900; + -0.00319460360, 0.00204543950; + 0.01283819000, 0.00788961100; + 0.00897728170, 0.01235817300; + -0.00911367310, 0.00216576220; + 0.00247233850, 0.00197748290; + 0.01385073000, -0.00628759110; + -0.00244131680, -0.00549276880; + 0.00247377740, 0.00010081507; + 0.00223374800, 0.00167638370; + 0.00622179480, 0.00636981950; + -0.01451075100, 0.00349200990; + 0.01701029100, 0.01655859500; + 0.00540505380, 0.00805163880; + -0.01032426300, 0.00545309340; + 0.01498743600, 0.00845128410; + 0.02407752900, 0.00198533570; + -0.00960939560, 0.00853352640; + -0.01023723300, 0.01335469200; + -0.00270911950, 0.00849549120; + -0.00369286780, -0.00121018950; + 0.00826982030, 0.00814966480; + -0.00479820070, -0.00430578830; + 0.01720646400, 0.01156837700; + 0.01664923600, -0.00173370660; + -0.00369501470, 0.02465627800; + -0.01376969800, 0.01146760700; + 0.00789807890, 0.00927350640; + -0.02031981900, 0.00182745860; + 0.00893684220, -0.00310349950; + -0.00058117960, -0.01036477300; + 0.00398354320, 0.00524400960; + -0.01072630400, 0.00893152600; + -0.01281647700, 0.00198587250; + 0.00527370920, -0.00790188520; + -0.00006975255, 0.02076850400; + -0.00795713420, 0.01823942500; + 0.00709618300, 0.00210983490; + 0.00385266830, 0.00600135910; + -0.01078681200, -0.02391983000; + 0.02052245600, -0.01704146200; + -0.00944289330, -0.01192082800; + -0.00394662410, -0.02925877900; + 0.01354173000, -0.02406313000; + -0.00718647540, -0.01098199500; + 0.02058008400, -0.00638229480; + -0.00854536810, -0.00450554770; + 0.00866409980, -0.00330021160; + -0.00686748550, -0.02114934800; + 0.00445321310, -0.00847144790; + 0.00801991790, -0.00241975850; + -0.00120417690, -0.00393759540; + -0.00494995210, -0.02696714500; + -0.01267562000, -0.01038903900; + 0.00353257720, -0.00908920320; + -0.00975382080, 0.01760238600; + -0.01260558500, 0.02760804400; + -0.00316022200, 0.02508482500; + 0.00082647851, 0.01143638600; + 0.00479109240, -0.00074145901; + 0.00524306200, -0.00265805690; + -0.00578202170, 0.01897214300; + 0.00893716350, -0.00482091210; + -0.01982108100, -0.01158432200; + 0.03126658600, 0.00409586630; + -0.00273803110, -0.00161845770; + -0.01761996600, 0.01334919500; + 0.00757518640, 0.01502052000; + -0.00292343760, 0.02766780900; + 0.00547019230, 0.02912370300; + 0.00907626300, 0.01593786700; + -0.00455934350, 0.00063507953; + 0.00508186300, 0.02238021200; + 0.01289502600, -0.00593488700; + 0.00236970730, 0.00388511510; + 0.00883958660, -0.00257234340; + 0.01720261100, 0.01188001800; + -0.00006246719, -0.00203679550; + -0.01575553100, -0.00676416250; + 0.00814828810, -0.00356291510; + 0.00379630600, -0.00175582960; + 0.01519689300, 0.01032388100; + 0.00604297190, -0.01207842000; + 0.00784725260, 0.00484980530; + 0.00757792060, 0.00642184950; + 0.00097163435, -0.01346602900; + -0.00080646536, -0.01005009400; + -0.00544594560, -0.01436795200; + -0.00170059540, 0.00889975570; + -0.00234754820, 0.01182947400; + 0.01225048700, 0.01299069100; + -0.01026220700, 0.01595514900; + -0.00944973050, 0.00843166930; + 0.00874279600, -0.01267545100; + -0.00362453400, 0.01054616000; + -0.00084828359, -0.00199187910; + 0.01428511500, -0.00406989120; + -0.00882438660, -0.02808280200; + 0.00704659960, -0.02179662700; + -0.00410832820, -0.00192698990; + -0.00147723550, -0.00896090550; + 0.00459580110, 0.01065118700; + -0.00605537920, -0.00488607770; + -0.00027256522, -0.00401632280; + -0.01978864800, -0.00626533710; + 0.00607277630, -0.01497391500; + -0.01143713900, -0.00323604060; + 0.01228681400, -0.00172676930; + -0.00793191320, -0.00843394290; + 0.00991768270, -0.00966059600; + 0.00992587030, -0.00349087710; + 0.00505795500, -0.00671022150; + 0.00788954440, 0.00332091270; + 0.01182401000, -0.00092086600; + -0.00660517190, -0.01039393600; + 0.01134255700, -0.00751655470; + 0.00038790604, -0.01755658800; + -0.00807366080, 0.00988425450; + -0.00088186225, 0.00561425140; + -0.00923030850, 0.00486096700; + 0.02739705100, 0.01565417800; + -0.02436147600, -0.00475603930; + -0.00474490120, 0.01578322600; + 0.00832453990, 0.00998216280; + -0.00713154110, -0.00411591940; + 0.01586726000, -0.00728781440; + 0.00901038060, 0.00388117450; + -0.01278363800, 0.00560553200; + -0.00341314840, -0.01414107100; + -0.01413398600, 0.02152507100; + -0.00084512439, 0.00416185940; + -0.00213784220, -0.00065205271; + 0.00447733340, -0.01064756800; + 0.01404655600, -0.00371620300; + 0.02279766500, 0.00569317110; + -0.00682377560, -0.00308033630; + 0.01124674300, -0.00598650510; + -0.01376857100, -0.00734424350; + 0.00966640550, 0.00595518380; + -0.01042231400, -0.00339618560; + -0.00210584750, -0.01492290700; + 0.00793225120, -0.01773942700; + -0.00746719420, -0.02023369900; + 0.00320403030, -0.00425187160; + -0.01498758300, -0.00172616900; + -0.00125324900, -0.01646365100; + -0.02719981800, -0.00720045620; + 0.00507847130, -0.00507992190; + 0.00408332760, -0.00696923090; + 0.00206618350, -0.01585097200; + -0.00266175350, -0.01324462400; + -0.00031912447, 0.00100260870; + -0.01038003300, 0.01981869200; + -0.01218511000, 0.02173349700; + 0.01136888100, 0.02204497600; + -0.01202743900, 0.00829954090; + -0.00021401182, -0.00175504700; + -0.00596558870, 0.00380210670; + 0.01569683000, 0.00347734000; + 0.00801820710, -0.00144632600; + -0.02250001500, 0.00504014370; + 0.01240035200, -0.00942954560; + 0.00858523030, -0.00623408720; + -0.01626079300, 0.00397289760; + 0.00723434090, 0.00783343600; + -0.00919603870, -0.00059345202; + 0.01085680800, 0.00243835800; + -0.00888834510, 0.00445439110; + -0.00052505879, 0.03196236900; + 0.00407476500, 0.02115388200; + 0.01036235200, 0.00961476180; + 0.00176157930, 0.00765388480; + -0.00053452369, -0.00819328090; + 0.00703537300, 0.00742844800; + -0.00014851151, 0.02083584000; + 0.00393808440, -0.00220486220; + 0.00068062472, -0.01090794200; + 0.00162973150, 0.01016291400; + 0.00956508570, 0.00314153260; + 0.00040965810, 0.00424568390; + -0.00342205330, 0.01575583500; + -0.00666487520, 0.03253912100; + 0.00357257790, -0.00193096120; + -0.00479944880, 0.00276754820; + -0.02008366200, 0.01813183600; + 0.01024278800, 0.00899311180; + 0.00331510340, 0.00874296380; + -0.00367787790, 0.01032780200; + 0.02355042500, 0.00879580860; + -0.02098926500, -0.00010779314; + 0.02242707300, -0.00613259750; + -0.00708729650, -0.00601044260; + 0.01401990900, 0.00501994170; + 0.01116776500, 0.00055147171; + -0.00789437150, 0.00307380160; + -0.00079795363, 0.00071918763; + 0.00024460379, -0.01076551400; + 0.00413459290, -0.01001296500; + -0.02104470800, 0.00080366086; + 0.01176522400, 0.01678986600; + -0.01816742200, 0.01265489200; + -0.01569319400, -0.00779392590; + -0.00283881540, -0.01456612300; + 0.00040506759, 0.00058628945; + 0.00945908740, 0.00075994717; + -0.00979130970, -0.00461547690; + 0.00265457950, 0.00878213250; + -0.02489547100, -0.00853506250; + 0.00102885490, 0.00684600140; + -0.00130745500, -0.00382792360; + 0.00762038530, -0.00423731260; + -0.00147484510, 0.01924464600; + 0.00727643910, 0.00989738330; + -0.00160290830, -0.00187813300; + 0.00428527540, -0.00219760860; + -0.03317646800, 0.00116740200; + 0.01658756800, 0.00518323290; + 0.00785352990, -0.00838975030; + -0.00451492520, 0.00547096380; + -0.00320296040, -0.02426730500; + 0.01417389300, -0.03256394100; + -0.00661515490, -0.00421165110; + 0.01470659000, -0.00042946856; + -0.02350439700, 0.00348050750; + 0.00366709700, 0.00938778820; + -0.00046899718, 0.00674591590; + 0.01975974900, 0.00026316635; + -0.00441742910, -0.01386567100; + 0.01032374900, -0.01708067200; + -0.00343647840, -0.00627385440; + 0.01341498100, -0.00152079670; + -0.01328190700, 0.00750671680; + -0.00194644230, 0.01508688300; + -0.01114553600, 0.03635301900; + -0.00904033490, 0.00672707110; + 0.00213535390, 0.01554549900; + -0.00147753730, 0.01329763200; + 0.00116701690, -0.00008942344; + 0.00341716790, -0.00317315000; + -0.01381591900, -0.00277583010; + 0.01813890000, -0.01732665300; + -0.01199155600, -0.00610674530; + 0.00444251760, 0.00143958250; + 0.01005538100, -0.00644700780; + -0.00343175930, -0.00473816370; + 0.00077039637, 0.00638741850; + 0.01094944500, 0.02697045000; + -0.00052522484, 0.00372434700; + -0.01200624400, 0.01233773200; + -0.00631723760, -0.00616098400; + -0.00267661130, -0.00189383380; + 0.01800845900, 0.00251762240; + -0.00070703292, -0.00777855150; + 0.01011331300, 0.00476866670; + 0.00535917660, -0.01284853600; + 0.01971133300, -0.00711727660; + 0.00471936570, -0.00527618130; + -0.01922986900, -0.01071921700; + 0.01058494000, -0.01208949400; + 0.00252107150, -0.01009809800; + -0.00635082770, -0.00325476460; + -0.00338369140, -0.00678190390; + -0.00560879390, 0.01429874600; + -0.00730724340, 0.00839658360; + 0.01073289400, 0.01332610500; + 0.01411626800, 0.01741862000; + -0.00578601340, 0.01236888600; + -0.00640703040, 0.00204314960; + -0.00277533020, 0.00809611970; + 0.01131091600, 0.02231586400; + -0.00290565000, 0.01281723000; + -0.00466721850, 0.01066850100; + 0.00003017692, -0.00045287596; + 0.01184006400, 0.02096790900; + -0.01807510700, 0.00007107626; + 0.01200216000, 0.01695265800; + -0.00233991190, -0.00762127830; + 0.01731830300, -0.01470775300; + -0.00871332370, -0.00536830240; + 0.01416221600, -0.00020614753; + -0.00720019210, -0.01392737100; + -0.01677725400, -0.00963694400; + 0.00376816350, -0.01806841400; + -0.01168453900, -0.02520963700; + -0.00242508010, -0.01003563800; + -0.00398142050, -0.00574731140; + 0.01750174900, -0.00421972000; + 0.00585300950, -0.01083337500; + 0.00418233240, -0.01247003500; + -0.00614589600, -0.00520667130; + 0.01135575200, 0.00930381060; + 0.00591022240, -0.01228150100; + -0.00330099160, -0.01714747100; + 0.00461113550, 0.00279658620; + 0.01844313500, -0.00381210120; + -0.00730330260, -0.01948227900; + 0.00114113770, 0.00359516800; + -0.01340516800, 0.01142347700; + 0.00242013210, 0.01479981600; + -0.01177683000, 0.00005024148; + -0.00140618160, 0.01536890200; + -0.00496745630, 0.03046414700; + 0.01227024900, 0.01537145000; + 0.00015891232, 0.02228270700; + -0.00275003980, 0.01807071800; + 0.00213022040, 0.02195794900; + -0.00456855430, -0.00847451820; + 0.00368394090, 0.00167170220; + 0.00053423273, -0.00101325060; + 0.01502387300, -0.00299957890; + -0.00364911970, 0.01043386100; + 0.00292325880, 0.00369136530; + -0.01000623700, 0.01065743200; + -0.00737237320, 0.01173679900; + 0.00470212590, -0.00172331660; + 0.00064041836, -0.00112935140; + 0.00801705600, 0.00908517860; + -0.01752767500, 0.01340269200; + -0.00167078620, 0.00984110940; + -0.00736765550, -0.00183892060; + 0.00171112270, 0.00325198900; + -0.00459124470, 0.00333673000; + 0.00090628466, -0.00136710980; + -0.00953744110, -0.00330812520; + 0.01382525800, -0.00074019487; + 0.00182379050, 0.00271536240; + -0.00144417870, -0.01965826300; + 0.00262746520, -0.00738069840; + -0.00315157850, -0.00579473100; + -0.00149920540, -0.00471902850; + 0.01724853900, -0.00444270650; + -0.00323729290, 0.01599976100; + 0.00818759990, 0.00475884400; + -0.00670440270, 0.00662529590; + 0.00761535810, -0.01531597000; + -0.00898965620, -0.01407707000; + -0.00095826091, 0.00110351110; + 0.01922539900, 0.00976795960; + 0.00107279500, -0.00201196850; + 0.00184468230, -0.01900434900; + 0.00206808720, -0.01044463400; + 0.01012566700, -0.00995885900; + -0.00264965050, -0.00197648630; + 0.01007788900, -0.01722402900; + 0.00857747020, -0.00978182180; + -0.00390662100, -0.00260237180; + 0.00692129190, -0.00378992080; + 0.00029091915, -0.00259509570; + -0.00360680420, -0.00713074060; + -0.00860419840, -0.02057721600; + 0.00044751379, -0.01449312400; + -0.00145591500, -0.01523862700; + 0.01682939900, -0.01270554100; + 0.00567881680, -0.01943714400; + 0.00848238640, -0.00223198500; + 0.00325092290, -0.00082652871; + 0.01223402300, 0.00644947070; + 0.00051464095, 0.00898356600; + 0.01260583200, 0.00834137450; + 0.01064180800, -0.00190874350; + 0.01005380200, -0.00116214780; + -0.00116234090, -0.00675879300; + -0.02332964500, -0.01838281800; + -0.00696804150, -0.00944441820; + -0.01819834100, -0.01808908500; + 0.02201795200, -0.00716774540; + -0.01672468800, -0.00826797040; + 0.01170834800, -0.00949888840; + -0.00615648660, -0.00355936780; + 0.00535839890, 0.00559401360; + -0.00703042400, -0.01059598600; + 0.00318876840, 0.00011921905; + -0.01874264500, 0.00790409920; + 0.00552417410, 0.00766524880; + -0.01497631100, -0.00238697410; + -0.00439945850, 0.00914147460; + 0.01828331600, -0.00206804820; + 0.00068550745, -0.00122205150; + -0.00759101970, -0.01153777900; + 0.00648242600, -0.01640673600; + -0.00543452600, -0.02063951400; + 0.00155147620, -0.02622296300; + -0.00564122550, -0.01103051900; + 0.00341228520, 0.00583169540; + 0.00646375290, 0.00936322370; + -0.00478098810, 0.01100696200; + 0.00573895680, -0.00239250900; + -0.00970467940, 0.00871843140; + 0.02038830400, 0.01480759600; + 0.00026758833, 0.02045451100; + 0.00791676330, 0.01696119900; + 0.00151902060, 0.00369441970; + 0.00695727800, -0.00513502650; + -0.01493114700, 0.00259436800; + 0.01356549700, -0.00125019700; + 0.01129927200, -0.01805236600; + -0.01605158000, -0.00110185760; + 0.01796653700, -0.01000584500; + -0.01611534000, -0.00357616450; + 0.00480241820, -0.01235228300; + 0.00765884520, 0.00199081530; + -0.00445450970, 0.00373594290; + 0.00836337530, 0.00844062310; + 0.00000608640, 0.00814252730; + -0.00242506490, 0.00107690310; + -0.00655880720, -0.01044158000; + 0.00959842540, -0.01282298400; + 0.00710086670, -0.00628089330; + -0.01539525500, 0.00145629030; + -0.01019127500, 0.00506089250; + -0.00415539980, 0.00121860340; + -0.00222234300, -0.00235775530; + 0.00145298240, 0.00074290054; + 0.00383045620, 0.00499606180; + -0.01581364300, 0.00991048820; + -0.00505534040, 0.00362636340; + 0.01275955400, -0.00852445050; + -0.00646790680, -0.00849281040; + 0.00822635380, 0.00506450010; + -0.00999777920, 0.01192172300; + 0.01259965900, -0.01267426000; + -0.00334331530, -0.01193505000; + 0.00531845400, 0.00036486233; + 0.00324434670, 0.01617751400; + -0.00182198070, 0.01450107800; + -0.01316162900, 0.00575151330; + -0.00245819090, -0.00185123220; + 0.00716449280, 0.00787328720; + -0.00111474240, 0.00293388970; + -0.01296516800, -0.00225148550; + 0.00284074300, -0.00331728310; + 0.01133071500, 0.02057075900; + -0.00100379480, 0.01280891700; + 0.00049387445, 0.00507951680; + 0.00229614130, -0.00764568280; + -0.01313835900, -0.00525744170; + 0.00966316020, -0.00556556230; + 0.01118421300, -0.00490035560; + 0.01672044300, -0.00988298390; + -0.01088174000, -0.00216302190; + -0.00920015300, 0.00190343440; + 0.00027256857, -0.00606717780; + 0.00745269630, 0.00488672340; + -0.00485878040, 0.00337006910; + -0.01014946800, 0.00628172350; + 0.00133496050, -0.00095504333; + 0.01278446800, 0.00344898280; + -0.00703416400, 0.00739247270; + 0.01328898700, 0.00304838790; + -0.01491870500, 0.00633638140; + 0.00873045630, 0.00319640990; + 0.00254909610, 0.01211332200; + 0.00232342310, 0.00470528570; + -0.00764997870, -0.00240813430; + -0.01090000900, -0.01170578800; + 0.00843239100, -0.01170118700; + -0.02507916900, -0.01158650100; + 0.04003462300, -0.01629908500; + -0.01222446500, -0.01477344200; + 0.00521617900, -0.00968336430; + 0.01952769300, -0.02338928900; + -0.00455805500, -0.01208632300; + -0.00421777900, -0.01515016500; + -0.02292950600, 0.00681974800; + 0.02065804000, -0.01601951200; + -0.01175698600, -0.01763198100; + 0.00847885710, -0.01709137000; + -0.00522204640, 0.00520781450; + 0.01653303200, 0.01230743800; + 0.01491689300, 0.02278097800; + -0.00390021000, -0.00599679960; + 0.00987391320, -0.01527627300; + -0.01292332700, -0.01725711000; + -0.00611290270, -0.00008627481; + 0.01173359600, 0.00525802720; + 0.00023658130, 0.00219369170; + 0.00527818840, -0.01008107600; + -0.00805139170, -0.01193710000; + -0.01872491200, 0.00860016370; + -0.01259698500, -0.01756964500; + -0.00088728350, -0.01512096000; + -0.01535824800, -0.01295353000; + 0.02003583600, -0.00614556620; + -0.00662873120, 0.00258939970; + 0.02039917600, -0.00012182475; + -0.00137236040, -0.00075700965; + -0.01450454300, -0.00207827570; + 0.01535757000, 0.00707412260; + -0.01704817500, -0.00431544930; + 0.00832049550, -0.01881308400; + 0.00788077160, -0.01301967100; + -0.00535764100, -0.02307963700; + 0.01684468900, -0.01761785700; + -0.00494331070, -0.02023850500; + -0.01844518300, -0.01120281300; + 0.01030114100, -0.00246253960; + 0.00737732820, 0.01367079900; + 0.00930385080, -0.01638037700; + 0.01184141400, -0.00128950800; + -0.02316092800, 0.00518400230; + 0.01259350700, 0.01851841100; + 0.00032334407, 0.00708510310; + -0.00380004070, 0.01466849000; + 0.00572216670, 0.02763848700; + 0.01450073300, 0.02130598400; + -0.00061716695, 0.01299269100; + 0.00032716641, 0.02931071500; + 0.00102466110, 0.01050204800; + -0.00339657480, -0.00413612190; + 0.01311750600, -0.00235546960; + 0.00609382540, 0.00646251750; + -0.00126880700, 0.01452674700; + -0.00768738760, 0.01051401500; + 0.01058750900, 0.00661389120; + -0.00857671250, 0.00564091490; + 0.00603614820, 0.00790147090; + -0.00383731350, 0.01219309200; + -0.00750234770, -0.00565016960; + -0.01197183700, -0.01579100100; + 0.00940025550, 0.01919136600; + -0.00001261024, 0.02626728500; + -0.01119718500, 0.00144775010; + 0.02249039100, 0.02039881000; + -0.00379732890, -0.01609038000; + 0.01565908800, -0.00588713290; + 0.00875294490, 0.00373467350; + 0.00256396420, 0.01632317700; + -0.00451786920, -0.00480455360; + -0.00790291250, 0.00345569200; + -0.01455265100, -0.01382336400; + 0.01350253300, 0.00019931557; + -0.00674284800, 0.00449999260; + 0.02374096100, -0.00641924120; + -0.02211973900, -0.00053401624; + 0.01207118500, -0.00983951590; + -0.00702998800, -0.02173194800; + 0.00650176870, -0.03939793300; + 0.01983586800, -0.01688164300; + -0.00523048000, -0.01586871000; + -0.00024937096, -0.00762047480; + 0.01848711000, -0.02202737800; + 0.00320481510, 0.00115403630; + -0.00339570830, -0.00416020450; + 0.00292867830, -0.00800372950; + -0.00085958037, -0.00702345910; + -0.00661261130, -0.00240180080; + 0.00915375200, -0.00072184277; + -0.02097610500, 0.00164769990; + 0.00794447800, 0.00132242720; + 0.00417510660, -0.00030181197; + -0.00634899330, -0.01677800600; + 0.00999671400, -0.00762022470; + -0.01004270400, 0.00644466200; + 0.00245296560, -0.00189053390; + -0.00558639080, -0.00629843410; + 0.00063566426, 0.00748679840; + -0.00197196620, -0.01231472900; + -0.00858143530, -0.00982022010; + 0.01118201300, -0.00005704770; + -0.01452712100, 0.00525489720; + 0.00556580190, -0.00614996780; + 0.00722027820, 0.00126887710; + -0.00106240920, 0.00248088000; + 0.00266047030, 0.00506315460; + -0.01615042800, -0.00024735048; + 0.00690899540, -0.02230154100; + 0.00016806370, -0.00703005220; + 0.01157961100, -0.00046847502; + -0.00569027140, -0.00074088147; + 0.00279183700, -0.01112727400; + 0.01159847500, -0.01397495400; + -0.01618859800, -0.03057030300; + 0.00051325767, -0.00865006790; + 0.00549707250, 0.00357878980; + -0.00970590920, -0.00253900500; + 0.01545455300, 0.00679668570; + -0.01066617100, -0.00621207310; + 0.00575491460, -0.00657640880; + -0.00605682630, 0.01005724800; + -0.00028086638, 0.01720437100; + 0.00314218690, -0.00112510120; + -0.01232869600, 0.00529184200; + 0.00156071380, 0.00332171610; + 0.01586504900, -0.00687919610; + -0.00700561370, 0.00627937710; + 0.00416313760, 0.01338622200; + -0.00469103860, -0.00207565840; + -0.00515967500, -0.02677465800; + -0.00329796470, -0.02347414900; + 0.00458593860, -0.01994345300; + 0.00449779160, -0.01500910700; + -0.01450006100, -0.02433756900; + -0.00982530810, 0.00515777190; + 0.02169452900, 0.00395559630; + -0.02732960700, -0.01296309000; + -0.00943391470, 0.00970794530; + 0.00883871190, -0.00847782470; + -0.00641242250, -0.00159739350; + -0.00622211610, -0.00023249961; + 0.01103231400, 0.01345929400; + -0.01604871600, 0.01444581500; + 0.00408581520, 0.00391976300; + -0.00585816760, -0.00136833520; + 0.01285105500, -0.01355861400; + -0.01282979900, -0.02075753400; + 0.00240514790, -0.00583408830; + -0.00821620830, -0.00917124260; + 0.01161346900, 0.00589059210; + -0.00416354780, 0.01478035400; + 0.00910147760, 0.00162353340; + 0.00645020290, -0.00029596225; + 0.00664065850, 0.00334591190; + -0.01628421500, -0.01667108200; + 0.01017428900, -0.01182986900; + -0.01740919900, 0.00421845090; + 0.01419528300, -0.00170271310; + -0.01832044100, -0.00271804760; + 0.00478798390, 0.01451607600; + -0.01552720100, 0.00680642330; + 0.00557794300, 0.01041172100; + 0.00418925410, -0.00240398610; + -0.00542981940, -0.01092214200; + 0.01256706900, -0.01379128400; + -0.01899332900, -0.00274706900; + 0.00907149380, -0.00663018700; + 0.01506829200, -0.00293179520; + -0.01827722500, -0.00283953570; + -0.00150598710, 0.00448947120; + 0.00689968130, 0.01392841800; + 0.00838313220, 0.00056270157; + -0.01889400800, 0.00445784700; + 0.01083541500, -0.00433810380; + 0.00975696280, -0.01959502400; + -0.00687770220, -0.01815605200; + -0.01112640300, -0.01494359600; + -0.00472052850, -0.01500657700; + -0.01367499100, -0.00267410440; + 0.01489290400, -0.00432076310; + -0.00262017640, -0.00290406560; + -0.00261222360, 0.00098096246; + 0.00452692100, -0.01865841900; + 0.00118941740, 0.00323370830; + 0.00029588303, 0.00675359970; + -0.01081920700, 0.02384338300; + ]; dy = bvar_data(:, 1); dx = bvar_data(:, 2); diff --git a/tests/conditional_forecasts/2/fsdat_simul.m b/tests/conditional_forecasts/2/fsdat_simul.m index d4f4a8066f..159612e577 100644 --- a/tests/conditional_forecasts/2/fsdat_simul.m +++ b/tests/conditional_forecasts/2/fsdat_simul.m @@ -1,828 +1,828 @@ gy_obs =[ - 1.0030045 - 0.99990934 - 1.0172778 - 0.99464043 - 1.0253423 - 1.0150215 - 0.97772557 - 0.97832186 - 1.0159561 - 1.0085937 - 1.0102649 - 1.0007604 - 1.0112596 - 1.0163279 - 1.0173204 - 1.0103896 - 1.0006493 - 0.99447124 - 1.0196405 - 1.0089304 - 0.99650737 - 1.0139707 - 0.97865842 - 1.0192225 - 0.99139628 - 1.0141362 - 1.0196612 - 0.97483476 - 0.99686151 - 0.99594464 - 1.0000642 - 1.0172243 - 1.0025773 - 0.97199728 - 1.0217815 - 1.0219949 - 0.99490252 - 1.0190728 - 1.0111337 - 1.0003792 - 0.98969164 - 1.010438 - 1.0216309 - 1.0016671 - 1.0357588 - 0.98803787 - 1.0093457 - 1.0177035 - 0.98548204 - 1.0274294 - 1.0141377 - 1.0091174 - 0.96427632 - 1.0083272 - 1.0007882 - 0.99038262 - 1.0031336 - 0.99500213 - 0.98203716 - 0.9889452 - 1.011632 - 0.99451949 - 0.97291047 - 0.98750871 - 0.99992418 - 0.97657318 - 0.99930448 - 1.0008515 - 1.0044064 - 0.98133792 - 1.0091702 - 1.0087023 - 1.0119876 - 1.0143019 - 1.0311061 - 0.99340471 - 1.0057428 - 0.99197259 - 1.0071019 - 0.99448853 - 1.0061819 - 1.0070088 - 0.9950913 - 1.0302318 - 0.9817693 - 1.0072885 - 0.97355282 - 0.98782586 - 1.0136674 - 0.99863956 - 1.0205668 - 0.99611384 - 1.0073805 - 0.99691529 - 1.0089194 - 1.0030467 - 1.0112006 - 1.0260523 - 0.97803331 - 0.99423374 - 1.0043727 - 1.0140173 - 1.0111473 - 0.99524348 - 0.99775943 - 0.9958619 - 0.9982344 - 1.0210212 - 1.0022288 - 1.0014801 - 1.011456 - 1.0124871 - 0.99843599 - 0.99324886 - 0.99912838 - 1.003327 - 1.0072071 - 1.0115223 - 1.009266 - 1.0070554 - 1.0129916 - 1.0053413 - 1.0051638 - 0.99212952 - 1.0214422 - 0.98716707 - 0.99905788 - 0.98877357 - 0.98568476 - 0.99767393 - 1.0061791 - 0.98423439 - 0.99492949 - 0.98786999 - 0.99754239 - 1.0168619 - 0.99472384 - 1.0041658 - 0.98123181 - 1.0112882 - 0.99245422 - 1.0010255 - 1.0017799 - 1.0089968 - 1.0072824 - 0.99768475 - 1.0044726 - 1.0118678 - 1.0056385 - 1.0276965 - 1.0025122 - 1.0065161 - 1.0234338 - 0.99760167 - 0.98922272 - 1.0101918 - 1.011615 - 1.0085286 - 1.0074455 - 0.98866757 - 0.99959012 - 1.0129881 - 0.99127881 - 0.97971901 - 1.0185314 - 1.020054 - 1.0132605 - 0.98063643 - 0.99490253 - 1.0101531 - 1.0004526 - 1.0059109 - 0.98974491 - 1.0062391 - 1.0216488 - 0.99398446 - 0.97786609 - 1.0019274 - 0.99587153 - 1.0095881 - 1.0111887 - 0.99457649 - 0.97896734 - 1.000172 - 1.0142951 - 1.0034224 - 1.0037242 - 1.0016059 - 1.016556 - 0.99687023 - 1.0117844 - 1.0059212 - 0.98083159 - 0.98638851 - 1.0128713 - 1.0096232 - 1.0115891 - 1.0011213 - 1.0147105 - 1.0066344 - 1.0164429 - 0.99825038 - 0.99403411 + 1.0030045 + 0.99990934 + 1.0172778 + 0.99464043 + 1.0253423 + 1.0150215 + 0.97772557 + 0.97832186 + 1.0159561 + 1.0085937 + 1.0102649 + 1.0007604 + 1.0112596 + 1.0163279 + 1.0173204 + 1.0103896 + 1.0006493 + 0.99447124 + 1.0196405 + 1.0089304 + 0.99650737 + 1.0139707 + 0.97865842 + 1.0192225 + 0.99139628 + 1.0141362 + 1.0196612 + 0.97483476 + 0.99686151 + 0.99594464 + 1.0000642 + 1.0172243 + 1.0025773 + 0.97199728 + 1.0217815 + 1.0219949 + 0.99490252 + 1.0190728 + 1.0111337 + 1.0003792 + 0.98969164 + 1.010438 + 1.0216309 + 1.0016671 + 1.0357588 + 0.98803787 + 1.0093457 + 1.0177035 + 0.98548204 + 1.0274294 + 1.0141377 + 1.0091174 + 0.96427632 + 1.0083272 + 1.0007882 + 0.99038262 + 1.0031336 + 0.99500213 + 0.98203716 + 0.9889452 + 1.011632 + 0.99451949 + 0.97291047 + 0.98750871 + 0.99992418 + 0.97657318 + 0.99930448 + 1.0008515 + 1.0044064 + 0.98133792 + 1.0091702 + 1.0087023 + 1.0119876 + 1.0143019 + 1.0311061 + 0.99340471 + 1.0057428 + 0.99197259 + 1.0071019 + 0.99448853 + 1.0061819 + 1.0070088 + 0.9950913 + 1.0302318 + 0.9817693 + 1.0072885 + 0.97355282 + 0.98782586 + 1.0136674 + 0.99863956 + 1.0205668 + 0.99611384 + 1.0073805 + 0.99691529 + 1.0089194 + 1.0030467 + 1.0112006 + 1.0260523 + 0.97803331 + 0.99423374 + 1.0043727 + 1.0140173 + 1.0111473 + 0.99524348 + 0.99775943 + 0.9958619 + 0.9982344 + 1.0210212 + 1.0022288 + 1.0014801 + 1.011456 + 1.0124871 + 0.99843599 + 0.99324886 + 0.99912838 + 1.003327 + 1.0072071 + 1.0115223 + 1.009266 + 1.0070554 + 1.0129916 + 1.0053413 + 1.0051638 + 0.99212952 + 1.0214422 + 0.98716707 + 0.99905788 + 0.98877357 + 0.98568476 + 0.99767393 + 1.0061791 + 0.98423439 + 0.99492949 + 0.98786999 + 0.99754239 + 1.0168619 + 0.99472384 + 1.0041658 + 0.98123181 + 1.0112882 + 0.99245422 + 1.0010255 + 1.0017799 + 1.0089968 + 1.0072824 + 0.99768475 + 1.0044726 + 1.0118678 + 1.0056385 + 1.0276965 + 1.0025122 + 1.0065161 + 1.0234338 + 0.99760167 + 0.98922272 + 1.0101918 + 1.011615 + 1.0085286 + 1.0074455 + 0.98866757 + 0.99959012 + 1.0129881 + 0.99127881 + 0.97971901 + 1.0185314 + 1.020054 + 1.0132605 + 0.98063643 + 0.99490253 + 1.0101531 + 1.0004526 + 1.0059109 + 0.98974491 + 1.0062391 + 1.0216488 + 0.99398446 + 0.97786609 + 1.0019274 + 0.99587153 + 1.0095881 + 1.0111887 + 0.99457649 + 0.97896734 + 1.000172 + 1.0142951 + 1.0034224 + 1.0037242 + 1.0016059 + 1.016556 + 0.99687023 + 1.0117844 + 1.0059212 + 0.98083159 + 0.98638851 + 1.0128713 + 1.0096232 + 1.0115891 + 1.0011213 + 1.0147105 + 1.0066344 + 1.0164429 + 0.99825038 + 0.99403411 -]; + ]; gp_obs =[ - 1.0079715 - 1.0074573 - 1.0153107 - 1.0152677 - 1.0011653 - 0.99950061 - 1.0328311 - 1.0192317 - 1.009827 - 0.99588916 - 1.007474 - 1.0113061 - 0.98696624 - 0.99978663 - 0.98240542 - 0.98861723 - 0.99008763 - 1.0185076 - 1.0052452 - 0.99447194 - 1.0092685 - 1.01208 - 1.0105237 - 0.98513875 - 1.0165628 - 0.99485934 - 1.0050255 - 1.0140756 - 1.0093128 - 1.0155868 - 1.0107023 - 0.99212762 - 1.0095465 - 1.0028435 - 1.0069437 - 1.0070473 - 1.0145902 - 1.0186922 - 1.0059917 - 1.0113072 - 1.0107386 - 0.99769196 - 0.99793444 - 1.0050791 - 0.98307821 - 1.0107594 - 0.99689982 - 0.98667064 - 0.9991662 - 0.98274722 - 0.98422032 - 0.99393016 - 1.0118567 - 0.99912781 - 1.0023744 - 1.0086662 - 1.0164773 - 1.0169327 - 1.0372478 - 1.0314242 - 1.0004256 - 1.0110541 - 1.0076575 - 1.0119851 - 1.0055188 - 1.0213959 - 1.0234416 - 1.0264917 - 1.0292725 - 1.0385184 - 1.0200999 - 1.0107697 - 1.008583 - 1.0200332 - 1.0030413 - 1.0108659 - 1.0185145 - 1.0168619 - 1.0180462 - 1.0239657 - 1.0205509 - 1.0189973 - 1.0246446 - 1.0135089 - 1.0352973 - 1.0099289 - 1.0266474 - 1.0279829 - 1.0101653 - 1.041216 - 1.0103861 - 1.0114727 - 1.0054605 - 1.0190722 - 1.0114837 - 1.0179213 - 1.006082 - 1.0049696 - 1.0143629 - 0.9971036 - 1.0005602 - 1.0078403 - 1.0240222 - 1.0195063 - 1.0355136 - 1.0218743 - 1.0171331 - 1.0049817 - 1.0140974 - 1.0168431 - 1.0049966 - 1.0045568 - 1.0156414 - 1.0273055 - 1.0197653 - 1.0030624 - 1.0154993 - 0.99782084 - 0.99711648 - 1.014408 - 1.0057417 - 0.99936837 - 1.0096934 - 1.0095138 - 1.0057734 - 1.0114497 - 1.0059784 - 1.0328889 - 1.0098032 - 1.0041114 - 1.0101247 - 1.0181588 - 1.0115712 - 1.0227509 - 1.0065104 - 1.0110902 - 1.0298169 - 1.0089532 - 1.0368733 - 1.0123033 - 1.0060763 - 1.0150937 - 1.0239325 - 0.99555536 - 0.99861271 - 1.0076201 - 0.99941535 - 1.0119522 - 1.0129183 - 0.99288924 - 1.0260784 - 1.0144982 - 1.0121985 - 1.0234916 - 1.02215 - 1.0190118 - 1.0172679 - 1.0118398 - 1.0002123 - 1.0092124 - 1.0071943 - 0.99508468 - 1.0019303 - 1.0030733 - 0.9964198 - 1.0027298 - 0.99797614 - 1.006942 - 0.99793928 - 1.0083214 - 1.0283732 - 1.0111102 - 1.016936 - 1.0229061 - 0.98846454 - 1.0015387 - 1.0201769 - 1.0079822 - 1.0064007 - 1.0095543 - 1.0092207 - 1.0135485 - 1.0198974 - 1.0140252 - 1.0128686 - 1.0092903 - 1.0141974 - 1.0023492 - 0.99731455 - 1.0026598 - 0.99303643 - 1.0036469 - 1.0160975 - 1.0368378 - 1.0139625 - 1.01493 - 1.0113531 - 1.0114548 - 0.99833441 - 0.99648401 - 0.97645361 - 1.0154053 - 1.01703 + 1.0079715 + 1.0074573 + 1.0153107 + 1.0152677 + 1.0011653 + 0.99950061 + 1.0328311 + 1.0192317 + 1.009827 + 0.99588916 + 1.007474 + 1.0113061 + 0.98696624 + 0.99978663 + 0.98240542 + 0.98861723 + 0.99008763 + 1.0185076 + 1.0052452 + 0.99447194 + 1.0092685 + 1.01208 + 1.0105237 + 0.98513875 + 1.0165628 + 0.99485934 + 1.0050255 + 1.0140756 + 1.0093128 + 1.0155868 + 1.0107023 + 0.99212762 + 1.0095465 + 1.0028435 + 1.0069437 + 1.0070473 + 1.0145902 + 1.0186922 + 1.0059917 + 1.0113072 + 1.0107386 + 0.99769196 + 0.99793444 + 1.0050791 + 0.98307821 + 1.0107594 + 0.99689982 + 0.98667064 + 0.9991662 + 0.98274722 + 0.98422032 + 0.99393016 + 1.0118567 + 0.99912781 + 1.0023744 + 1.0086662 + 1.0164773 + 1.0169327 + 1.0372478 + 1.0314242 + 1.0004256 + 1.0110541 + 1.0076575 + 1.0119851 + 1.0055188 + 1.0213959 + 1.0234416 + 1.0264917 + 1.0292725 + 1.0385184 + 1.0200999 + 1.0107697 + 1.008583 + 1.0200332 + 1.0030413 + 1.0108659 + 1.0185145 + 1.0168619 + 1.0180462 + 1.0239657 + 1.0205509 + 1.0189973 + 1.0246446 + 1.0135089 + 1.0352973 + 1.0099289 + 1.0266474 + 1.0279829 + 1.0101653 + 1.041216 + 1.0103861 + 1.0114727 + 1.0054605 + 1.0190722 + 1.0114837 + 1.0179213 + 1.006082 + 1.0049696 + 1.0143629 + 0.9971036 + 1.0005602 + 1.0078403 + 1.0240222 + 1.0195063 + 1.0355136 + 1.0218743 + 1.0171331 + 1.0049817 + 1.0140974 + 1.0168431 + 1.0049966 + 1.0045568 + 1.0156414 + 1.0273055 + 1.0197653 + 1.0030624 + 1.0154993 + 0.99782084 + 0.99711648 + 1.014408 + 1.0057417 + 0.99936837 + 1.0096934 + 1.0095138 + 1.0057734 + 1.0114497 + 1.0059784 + 1.0328889 + 1.0098032 + 1.0041114 + 1.0101247 + 1.0181588 + 1.0115712 + 1.0227509 + 1.0065104 + 1.0110902 + 1.0298169 + 1.0089532 + 1.0368733 + 1.0123033 + 1.0060763 + 1.0150937 + 1.0239325 + 0.99555536 + 0.99861271 + 1.0076201 + 0.99941535 + 1.0119522 + 1.0129183 + 0.99288924 + 1.0260784 + 1.0144982 + 1.0121985 + 1.0234916 + 1.02215 + 1.0190118 + 1.0172679 + 1.0118398 + 1.0002123 + 1.0092124 + 1.0071943 + 0.99508468 + 1.0019303 + 1.0030733 + 0.9964198 + 1.0027298 + 0.99797614 + 1.006942 + 0.99793928 + 1.0083214 + 1.0283732 + 1.0111102 + 1.016936 + 1.0229061 + 0.98846454 + 1.0015387 + 1.0201769 + 1.0079822 + 1.0064007 + 1.0095543 + 1.0092207 + 1.0135485 + 1.0198974 + 1.0140252 + 1.0128686 + 1.0092903 + 1.0141974 + 1.0023492 + 0.99731455 + 1.0026598 + 0.99303643 + 1.0036469 + 1.0160975 + 1.0368378 + 1.0139625 + 1.01493 + 1.0113531 + 1.0114548 + 0.99833441 + 0.99648401 + 0.97645361 + 1.0154053 + 1.01703 -]; + ]; Y_obs =[ - 1 - 0.99690484 - 1.0111781 - 1.0028141 - 1.0251518 - 1.0371688 - 1.0118899 - 0.98720726 - 1.0001589 - 1.0057481 - 1.0130085 - 1.0107643 - 1.0190194 - 1.0323428 - 1.0466587 - 1.0540438 - 1.0516886 - 1.0431553 - 1.0597913 - 1.0657172 - 1.0592201 - 1.0701863 - 1.0458402 - 1.0620582 - 1.0504499 - 1.0615817 - 1.0782384 - 1.0500687 - 1.0439257 - 1.0368658 - 1.0339255 - 1.0481453 - 1.0477181 - 1.0167109 - 1.0354878 - 1.0544782 - 1.0463762 - 1.0624445 - 1.0705737 - 1.0679484 - 1.0546356 - 1.0620691 - 1.0806955 - 1.0793581 - 1.1121124 - 1.0971458 - 1.1034869 - 1.1181859 - 1.1006634 - 1.1250883 - 1.1362214 - 1.1423343 - 1.1036061 - 1.1089288 - 1.1067125 - 1.0940906 - 1.0942197 - 1.0862174 - 1.06525 - 1.0511907 - 1.0598182 - 1.0513331 - 1.0212391 - 1.0057433 - 1.002663 - 0.97623167 - 0.97253165 - 0.97037865 - 0.97178055 - 0.95011397 - 0.95627969 - 0.96197747 - 0.97096053 - 0.98225794 - 1.0103595 - 1.0007597 - 1.003498 - 0.99246608 - 0.99656347 - 0.98804749 - 0.99122491 - 0.99522926 - 0.98731605 - 1.0145434 - 0.99330816 - 0.99759216 - 0.96814048 - 0.95296183 - 0.96362471 - 0.95925977 - 0.97682205 - 0.96993138 - 0.9743074 - 0.96821818 - 0.97413308 - 0.9741753 - 0.98237142 - 1.0054193 - 0.98044807 - 0.9716773 - 0.9730455 - 0.98405828 - 0.99220103 - 0.98444001 - 0.97919493 - 0.97205233 - 0.96728223 - 0.98529893 - 0.98452324 - 0.98299888 - 0.99145042 - 1.000933 - 0.99636447 - 0.98660883 - 0.98273271 - 0.98305518 - 0.98725774 - 0.99577549 - 1.002037 - 1.0060879 - 1.016075 - 1.0184118 - 1.0205711 - 1.0096961 - 1.0281337 - 1.0122963 - 1.0083497 - 0.99411874 - 0.976799 - 0.97146842 - 0.97464304 - 0.95587292 - 0.94779791 - 0.93266339 - 0.92720128 - 0.94105864 - 0.93277798 - 0.93393927 - 0.91216657 - 0.92045028 - 0.9099 - 0.90792098 - 0.90669634 - 0.91268867 - 0.91696661 - 0.91164685 - 0.91311495 - 0.92197825 - 0.92461222 - 0.94930422 - 0.9488119 - 0.95232353 - 0.97275278 - 0.96734995 - 0.95356817 - 0.96075548 - 0.96936594 - 0.97489002 - 0.97933106 - 0.96499412 - 0.96157973 - 0.97156334 - 0.95983765 - 0.93655215 - 0.95207909 - 0.96912862 - 0.97938462 - 0.95701655 - 0.94891457 - 0.95606317 - 0.95351125 - 0.95641767 - 0.94315807 - 0.94639265 - 0.96503697 - 0.95601693 - 0.93087851 - 0.92980141 - 0.92266844 - 0.92925206 - 0.93743628 - 0.92900826 - 0.9049711 - 0.90213859 - 0.91342916 - 0.91384707 - 0.91456681 - 0.91316822 - 0.92671976 - 0.92058549 - 0.92936541 - 0.93228212 - 0.91010921 - 0.89349322 - 0.90336005 - 0.90997873 - 0.91856328 - 0.91668007 - 0.92838606 - 0.932016 - 0.94545438 - 0.94070026 - 0.93172987 + 1 + 0.99690484 + 1.0111781 + 1.0028141 + 1.0251518 + 1.0371688 + 1.0118899 + 0.98720726 + 1.0001589 + 1.0057481 + 1.0130085 + 1.0107643 + 1.0190194 + 1.0323428 + 1.0466587 + 1.0540438 + 1.0516886 + 1.0431553 + 1.0597913 + 1.0657172 + 1.0592201 + 1.0701863 + 1.0458402 + 1.0620582 + 1.0504499 + 1.0615817 + 1.0782384 + 1.0500687 + 1.0439257 + 1.0368658 + 1.0339255 + 1.0481453 + 1.0477181 + 1.0167109 + 1.0354878 + 1.0544782 + 1.0463762 + 1.0624445 + 1.0705737 + 1.0679484 + 1.0546356 + 1.0620691 + 1.0806955 + 1.0793581 + 1.1121124 + 1.0971458 + 1.1034869 + 1.1181859 + 1.1006634 + 1.1250883 + 1.1362214 + 1.1423343 + 1.1036061 + 1.1089288 + 1.1067125 + 1.0940906 + 1.0942197 + 1.0862174 + 1.06525 + 1.0511907 + 1.0598182 + 1.0513331 + 1.0212391 + 1.0057433 + 1.002663 + 0.97623167 + 0.97253165 + 0.97037865 + 0.97178055 + 0.95011397 + 0.95627969 + 0.96197747 + 0.97096053 + 0.98225794 + 1.0103595 + 1.0007597 + 1.003498 + 0.99246608 + 0.99656347 + 0.98804749 + 0.99122491 + 0.99522926 + 0.98731605 + 1.0145434 + 0.99330816 + 0.99759216 + 0.96814048 + 0.95296183 + 0.96362471 + 0.95925977 + 0.97682205 + 0.96993138 + 0.9743074 + 0.96821818 + 0.97413308 + 0.9741753 + 0.98237142 + 1.0054193 + 0.98044807 + 0.9716773 + 0.9730455 + 0.98405828 + 0.99220103 + 0.98444001 + 0.97919493 + 0.97205233 + 0.96728223 + 0.98529893 + 0.98452324 + 0.98299888 + 0.99145042 + 1.000933 + 0.99636447 + 0.98660883 + 0.98273271 + 0.98305518 + 0.98725774 + 0.99577549 + 1.002037 + 1.0060879 + 1.016075 + 1.0184118 + 1.0205711 + 1.0096961 + 1.0281337 + 1.0122963 + 1.0083497 + 0.99411874 + 0.976799 + 0.97146842 + 0.97464304 + 0.95587292 + 0.94779791 + 0.93266339 + 0.92720128 + 0.94105864 + 0.93277798 + 0.93393927 + 0.91216657 + 0.92045028 + 0.9099 + 0.90792098 + 0.90669634 + 0.91268867 + 0.91696661 + 0.91164685 + 0.91311495 + 0.92197825 + 0.92461222 + 0.94930422 + 0.9488119 + 0.95232353 + 0.97275278 + 0.96734995 + 0.95356817 + 0.96075548 + 0.96936594 + 0.97489002 + 0.97933106 + 0.96499412 + 0.96157973 + 0.97156334 + 0.95983765 + 0.93655215 + 0.95207909 + 0.96912862 + 0.97938462 + 0.95701655 + 0.94891457 + 0.95606317 + 0.95351125 + 0.95641767 + 0.94315807 + 0.94639265 + 0.96503697 + 0.95601693 + 0.93087851 + 0.92980141 + 0.92266844 + 0.92925206 + 0.93743628 + 0.92900826 + 0.9049711 + 0.90213859 + 0.91342916 + 0.91384707 + 0.91456681 + 0.91316822 + 0.92671976 + 0.92058549 + 0.92936541 + 0.93228212 + 0.91010921 + 0.89349322 + 0.90336005 + 0.90997873 + 0.91856328 + 0.91668007 + 0.92838606 + 0.932016 + 0.94545438 + 0.94070026 + 0.93172987 -]; + ]; P_obs =[ - 1 - 0.99948573 - 1.0068249 - 1.0141211 - 1.0073149 - 0.99884398 - 1.0237035 - 1.0349636 - 1.036819 - 1.0247366 - 1.0242391 - 1.0275737 - 1.0065684 - 0.99838346 - 0.97281734 - 0.95346302 - 0.9355791 - 0.9461152 - 0.94338882 - 0.92988921 - 0.9311862 - 0.93529467 - 0.93784681 - 0.91501401 - 0.92360522 - 0.91049302 - 0.90754698 - 0.91365103 - 0.91499228 - 0.92260749 - 0.92533824 - 0.90949431 - 0.91106924 - 0.90594116 - 0.90491334 - 0.9039891 - 0.91060772 - 0.92132842 - 0.91934854 - 0.92268418 - 0.92545127 - 0.91517169 - 0.90513459 - 0.90224212 - 0.87734878 - 0.88013667 - 0.86906494 - 0.84776403 - 0.83895869 - 0.81373437 - 0.78998314 - 0.77594176 - 0.77982695 - 0.77098321 - 0.76538611 - 0.76608075 - 0.77458654 - 0.78354767 - 0.81282389 - 0.83627649 - 0.82873051 - 0.83181309 - 0.83149903 - 0.83551261 - 0.83305985 - 0.84648418 - 0.86195421 - 0.88047436 - 0.90177533 - 0.93232215 - 0.94445051 - 0.9472487 - 0.94786015 - 0.95992178 - 0.95499149 - 0.95788581 - 0.9684288 - 0.97731917 - 0.98739379 - 1.0033879 - 1.0159673 - 1.0269931 - 1.0436661 - 1.0492034 - 1.0765292 - 1.0784865 - 1.0971624 - 1.1171737 - 1.1193675 - 1.1526119 - 1.1550265 - 1.1585277 - 1.1560166 - 1.1671172 - 1.1706294 - 1.1805791 - 1.1786896 - 1.1756876 - 1.1820789 - 1.171211 - 1.1637997 - 1.1636684 - 1.179719 - 1.1912538 - 1.2187959 - 1.2326986 - 1.2418602 - 1.2388704 - 1.2449963 - 1.2538678 - 1.2508929 - 1.2474781 - 1.255148 - 1.274482 - 1.2862757 - 1.2813665 - 1.2888943 - 1.2787436 - 1.2678886 - 1.274325 - 1.2720952 - 1.263492 - 1.2652139 - 1.2667561 - 1.264558 - 1.2680362 - 1.2660431 - 1.2909605 - 1.2927921 - 1.288932 - 1.2910852 - 1.3012725 - 1.3048721 - 1.3196515 - 1.3181903 - 1.321309 - 1.3431543 - 1.344136 - 1.3730377 - 1.3773695 - 1.3754742 - 1.3825964 - 1.3985574 - 1.3861412 - 1.3767823 - 1.3764309 - 1.3678747 - 1.3718554 - 1.3768022 - 1.3617199 - 1.3798267 - 1.3863533 - 1.3905803 - 1.4061004 - 1.4202788 - 1.4313191 - 1.4406155 - 1.4444837 - 1.4367244 - 1.4379653 - 1.4371881 - 1.4243012 - 1.41826 - 1.4133617 - 1.40181 - 1.3965683 - 1.3865729 - 1.3855433 - 1.3755111 - 1.3758609 - 1.3962625 - 1.3994012 - 1.4083656 - 1.4233002 - 1.4037932 - 1.3973604 - 1.4095657 - 1.4095764 - 1.4080055 - 1.4095882 - 1.4108374 - 1.4164143 - 1.4283402 - 1.4343939 - 1.4392909 - 1.4406097 - 1.4468355 - 1.4412132 - 1.4305562 - 1.4252445 - 1.4103094 - 1.4059847 - 1.4141106 - 1.4429769 - 1.4489679 - 1.4559263 - 1.4593079 - 1.4627911 - 1.453154 - 1.4416665 - 1.4101485 - 1.4175823 - 1.4266407 + 1 + 0.99948573 + 1.0068249 + 1.0141211 + 1.0073149 + 0.99884398 + 1.0237035 + 1.0349636 + 1.036819 + 1.0247366 + 1.0242391 + 1.0275737 + 1.0065684 + 0.99838346 + 0.97281734 + 0.95346302 + 0.9355791 + 0.9461152 + 0.94338882 + 0.92988921 + 0.9311862 + 0.93529467 + 0.93784681 + 0.91501401 + 0.92360522 + 0.91049302 + 0.90754698 + 0.91365103 + 0.91499228 + 0.92260749 + 0.92533824 + 0.90949431 + 0.91106924 + 0.90594116 + 0.90491334 + 0.9039891 + 0.91060772 + 0.92132842 + 0.91934854 + 0.92268418 + 0.92545127 + 0.91517169 + 0.90513459 + 0.90224212 + 0.87734878 + 0.88013667 + 0.86906494 + 0.84776403 + 0.83895869 + 0.81373437 + 0.78998314 + 0.77594176 + 0.77982695 + 0.77098321 + 0.76538611 + 0.76608075 + 0.77458654 + 0.78354767 + 0.81282389 + 0.83627649 + 0.82873051 + 0.83181309 + 0.83149903 + 0.83551261 + 0.83305985 + 0.84648418 + 0.86195421 + 0.88047436 + 0.90177533 + 0.93232215 + 0.94445051 + 0.9472487 + 0.94786015 + 0.95992178 + 0.95499149 + 0.95788581 + 0.9684288 + 0.97731917 + 0.98739379 + 1.0033879 + 1.0159673 + 1.0269931 + 1.0436661 + 1.0492034 + 1.0765292 + 1.0784865 + 1.0971624 + 1.1171737 + 1.1193675 + 1.1526119 + 1.1550265 + 1.1585277 + 1.1560166 + 1.1671172 + 1.1706294 + 1.1805791 + 1.1786896 + 1.1756876 + 1.1820789 + 1.171211 + 1.1637997 + 1.1636684 + 1.179719 + 1.1912538 + 1.2187959 + 1.2326986 + 1.2418602 + 1.2388704 + 1.2449963 + 1.2538678 + 1.2508929 + 1.2474781 + 1.255148 + 1.274482 + 1.2862757 + 1.2813665 + 1.2888943 + 1.2787436 + 1.2678886 + 1.274325 + 1.2720952 + 1.263492 + 1.2652139 + 1.2667561 + 1.264558 + 1.2680362 + 1.2660431 + 1.2909605 + 1.2927921 + 1.288932 + 1.2910852 + 1.3012725 + 1.3048721 + 1.3196515 + 1.3181903 + 1.321309 + 1.3431543 + 1.344136 + 1.3730377 + 1.3773695 + 1.3754742 + 1.3825964 + 1.3985574 + 1.3861412 + 1.3767823 + 1.3764309 + 1.3678747 + 1.3718554 + 1.3768022 + 1.3617199 + 1.3798267 + 1.3863533 + 1.3905803 + 1.4061004 + 1.4202788 + 1.4313191 + 1.4406155 + 1.4444837 + 1.4367244 + 1.4379653 + 1.4371881 + 1.4243012 + 1.41826 + 1.4133617 + 1.40181 + 1.3965683 + 1.3865729 + 1.3855433 + 1.3755111 + 1.3758609 + 1.3962625 + 1.3994012 + 1.4083656 + 1.4233002 + 1.4037932 + 1.3973604 + 1.4095657 + 1.4095764 + 1.4080055 + 1.4095882 + 1.4108374 + 1.4164143 + 1.4283402 + 1.4343939 + 1.4392909 + 1.4406097 + 1.4468355 + 1.4412132 + 1.4305562 + 1.4252445 + 1.4103094 + 1.4059847 + 1.4141106 + 1.4429769 + 1.4489679 + 1.4559263 + 1.4593079 + 1.4627911 + 1.453154 + 1.4416665 + 1.4101485 + 1.4175823 + 1.4266407 -]; + ]; diff --git a/tests/dates/fsdat_simul.m b/tests/dates/fsdat_simul.m index bc2c5a4fe3..6ce6114a74 100644 --- a/tests/dates/fsdat_simul.m +++ b/tests/dates/fsdat_simul.m @@ -2,830 +2,830 @@ INIT__ = '1950Q1'; FREQ__ = 4; gy_obs =[ - 1.0030045 - 0.99990934 - 1.0172778 - 0.99464043 - 1.0253423 - 1.0150215 - 0.97772557 - 0.97832186 - 1.0159561 - 1.0085937 - 1.0102649 - 1.0007604 - 1.0112596 - 1.0163279 - 1.0173204 - 1.0103896 - 1.0006493 - 0.99447124 - 1.0196405 - 1.0089304 - 0.99650737 - 1.0139707 - 0.97865842 - 1.0192225 - 0.99139628 - 1.0141362 - 1.0196612 - 0.97483476 - 0.99686151 - 0.99594464 - 1.0000642 - 1.0172243 - 1.0025773 - 0.97199728 - 1.0217815 - 1.0219949 - 0.99490252 - 1.0190728 - 1.0111337 - 1.0003792 - 0.98969164 - 1.010438 - 1.0216309 - 1.0016671 - 1.0357588 - 0.98803787 - 1.0093457 - 1.0177035 - 0.98548204 - 1.0274294 - 1.0141377 - 1.0091174 - 0.96427632 - 1.0083272 - 1.0007882 - 0.99038262 - 1.0031336 - 0.99500213 - 0.98203716 - 0.9889452 - 1.011632 - 0.99451949 - 0.97291047 - 0.98750871 - 0.99992418 - 0.97657318 - 0.99930448 - 1.0008515 - 1.0044064 - 0.98133792 - 1.0091702 - 1.0087023 - 1.0119876 - 1.0143019 - 1.0311061 - 0.99340471 - 1.0057428 - 0.99197259 - 1.0071019 - 0.99448853 - 1.0061819 - 1.0070088 - 0.9950913 - 1.0302318 - 0.9817693 - 1.0072885 - 0.97355282 - 0.98782586 - 1.0136674 - 0.99863956 - 1.0205668 - 0.99611384 - 1.0073805 - 0.99691529 - 1.0089194 - 1.0030467 - 1.0112006 - 1.0260523 - 0.97803331 - 0.99423374 - 1.0043727 - 1.0140173 - 1.0111473 - 0.99524348 - 0.99775943 - 0.9958619 - 0.9982344 - 1.0210212 - 1.0022288 - 1.0014801 - 1.011456 - 1.0124871 - 0.99843599 - 0.99324886 - 0.99912838 - 1.003327 - 1.0072071 - 1.0115223 - 1.009266 - 1.0070554 - 1.0129916 - 1.0053413 - 1.0051638 - 0.99212952 - 1.0214422 - 0.98716707 - 0.99905788 - 0.98877357 - 0.98568476 - 0.99767393 - 1.0061791 - 0.98423439 - 0.99492949 - 0.98786999 - 0.99754239 - 1.0168619 - 0.99472384 - 1.0041658 - 0.98123181 - 1.0112882 - 0.99245422 - 1.0010255 - 1.0017799 - 1.0089968 - 1.0072824 - 0.99768475 - 1.0044726 - 1.0118678 - 1.0056385 - 1.0276965 - 1.0025122 - 1.0065161 - 1.0234338 - 0.99760167 - 0.98922272 - 1.0101918 - 1.011615 - 1.0085286 - 1.0074455 - 0.98866757 - 0.99959012 - 1.0129881 - 0.99127881 - 0.97971901 - 1.0185314 - 1.020054 - 1.0132605 - 0.98063643 - 0.99490253 - 1.0101531 - 1.0004526 - 1.0059109 - 0.98974491 - 1.0062391 - 1.0216488 - 0.99398446 - 0.97786609 - 1.0019274 - 0.99587153 - 1.0095881 - 1.0111887 - 0.99457649 - 0.97896734 - 1.000172 - 1.0142951 - 1.0034224 - 1.0037242 - 1.0016059 - 1.016556 - 0.99687023 - 1.0117844 - 1.0059212 - 0.98083159 - 0.98638851 - 1.0128713 - 1.0096232 - 1.0115891 - 1.0011213 - 1.0147105 - 1.0066344 - 1.0164429 - 0.99825038 - 0.99403411 + 1.0030045 + 0.99990934 + 1.0172778 + 0.99464043 + 1.0253423 + 1.0150215 + 0.97772557 + 0.97832186 + 1.0159561 + 1.0085937 + 1.0102649 + 1.0007604 + 1.0112596 + 1.0163279 + 1.0173204 + 1.0103896 + 1.0006493 + 0.99447124 + 1.0196405 + 1.0089304 + 0.99650737 + 1.0139707 + 0.97865842 + 1.0192225 + 0.99139628 + 1.0141362 + 1.0196612 + 0.97483476 + 0.99686151 + 0.99594464 + 1.0000642 + 1.0172243 + 1.0025773 + 0.97199728 + 1.0217815 + 1.0219949 + 0.99490252 + 1.0190728 + 1.0111337 + 1.0003792 + 0.98969164 + 1.010438 + 1.0216309 + 1.0016671 + 1.0357588 + 0.98803787 + 1.0093457 + 1.0177035 + 0.98548204 + 1.0274294 + 1.0141377 + 1.0091174 + 0.96427632 + 1.0083272 + 1.0007882 + 0.99038262 + 1.0031336 + 0.99500213 + 0.98203716 + 0.9889452 + 1.011632 + 0.99451949 + 0.97291047 + 0.98750871 + 0.99992418 + 0.97657318 + 0.99930448 + 1.0008515 + 1.0044064 + 0.98133792 + 1.0091702 + 1.0087023 + 1.0119876 + 1.0143019 + 1.0311061 + 0.99340471 + 1.0057428 + 0.99197259 + 1.0071019 + 0.99448853 + 1.0061819 + 1.0070088 + 0.9950913 + 1.0302318 + 0.9817693 + 1.0072885 + 0.97355282 + 0.98782586 + 1.0136674 + 0.99863956 + 1.0205668 + 0.99611384 + 1.0073805 + 0.99691529 + 1.0089194 + 1.0030467 + 1.0112006 + 1.0260523 + 0.97803331 + 0.99423374 + 1.0043727 + 1.0140173 + 1.0111473 + 0.99524348 + 0.99775943 + 0.9958619 + 0.9982344 + 1.0210212 + 1.0022288 + 1.0014801 + 1.011456 + 1.0124871 + 0.99843599 + 0.99324886 + 0.99912838 + 1.003327 + 1.0072071 + 1.0115223 + 1.009266 + 1.0070554 + 1.0129916 + 1.0053413 + 1.0051638 + 0.99212952 + 1.0214422 + 0.98716707 + 0.99905788 + 0.98877357 + 0.98568476 + 0.99767393 + 1.0061791 + 0.98423439 + 0.99492949 + 0.98786999 + 0.99754239 + 1.0168619 + 0.99472384 + 1.0041658 + 0.98123181 + 1.0112882 + 0.99245422 + 1.0010255 + 1.0017799 + 1.0089968 + 1.0072824 + 0.99768475 + 1.0044726 + 1.0118678 + 1.0056385 + 1.0276965 + 1.0025122 + 1.0065161 + 1.0234338 + 0.99760167 + 0.98922272 + 1.0101918 + 1.011615 + 1.0085286 + 1.0074455 + 0.98866757 + 0.99959012 + 1.0129881 + 0.99127881 + 0.97971901 + 1.0185314 + 1.020054 + 1.0132605 + 0.98063643 + 0.99490253 + 1.0101531 + 1.0004526 + 1.0059109 + 0.98974491 + 1.0062391 + 1.0216488 + 0.99398446 + 0.97786609 + 1.0019274 + 0.99587153 + 1.0095881 + 1.0111887 + 0.99457649 + 0.97896734 + 1.000172 + 1.0142951 + 1.0034224 + 1.0037242 + 1.0016059 + 1.016556 + 0.99687023 + 1.0117844 + 1.0059212 + 0.98083159 + 0.98638851 + 1.0128713 + 1.0096232 + 1.0115891 + 1.0011213 + 1.0147105 + 1.0066344 + 1.0164429 + 0.99825038 + 0.99403411 -]; + ]; gp_obs =[ - 1.0079715 - 1.0074573 - 1.0153107 - 1.0152677 - 1.0011653 - 0.99950061 - 1.0328311 - 1.0192317 - 1.009827 - 0.99588916 - 1.007474 - 1.0113061 - 0.98696624 - 0.99978663 - 0.98240542 - 0.98861723 - 0.99008763 - 1.0185076 - 1.0052452 - 0.99447194 - 1.0092685 - 1.01208 - 1.0105237 - 0.98513875 - 1.0165628 - 0.99485934 - 1.0050255 - 1.0140756 - 1.0093128 - 1.0155868 - 1.0107023 - 0.99212762 - 1.0095465 - 1.0028435 - 1.0069437 - 1.0070473 - 1.0145902 - 1.0186922 - 1.0059917 - 1.0113072 - 1.0107386 - 0.99769196 - 0.99793444 - 1.0050791 - 0.98307821 - 1.0107594 - 0.99689982 - 0.98667064 - 0.9991662 - 0.98274722 - 0.98422032 - 0.99393016 - 1.0118567 - 0.99912781 - 1.0023744 - 1.0086662 - 1.0164773 - 1.0169327 - 1.0372478 - 1.0314242 - 1.0004256 - 1.0110541 - 1.0076575 - 1.0119851 - 1.0055188 - 1.0213959 - 1.0234416 - 1.0264917 - 1.0292725 - 1.0385184 - 1.0200999 - 1.0107697 - 1.008583 - 1.0200332 - 1.0030413 - 1.0108659 - 1.0185145 - 1.0168619 - 1.0180462 - 1.0239657 - 1.0205509 - 1.0189973 - 1.0246446 - 1.0135089 - 1.0352973 - 1.0099289 - 1.0266474 - 1.0279829 - 1.0101653 - 1.041216 - 1.0103861 - 1.0114727 - 1.0054605 - 1.0190722 - 1.0114837 - 1.0179213 - 1.006082 - 1.0049696 - 1.0143629 - 0.9971036 - 1.0005602 - 1.0078403 - 1.0240222 - 1.0195063 - 1.0355136 - 1.0218743 - 1.0171331 - 1.0049817 - 1.0140974 - 1.0168431 - 1.0049966 - 1.0045568 - 1.0156414 - 1.0273055 - 1.0197653 - 1.0030624 - 1.0154993 - 0.99782084 - 0.99711648 - 1.014408 - 1.0057417 - 0.99936837 - 1.0096934 - 1.0095138 - 1.0057734 - 1.0114497 - 1.0059784 - 1.0328889 - 1.0098032 - 1.0041114 - 1.0101247 - 1.0181588 - 1.0115712 - 1.0227509 - 1.0065104 - 1.0110902 - 1.0298169 - 1.0089532 - 1.0368733 - 1.0123033 - 1.0060763 - 1.0150937 - 1.0239325 - 0.99555536 - 0.99861271 - 1.0076201 - 0.99941535 - 1.0119522 - 1.0129183 - 0.99288924 - 1.0260784 - 1.0144982 - 1.0121985 - 1.0234916 - 1.02215 - 1.0190118 - 1.0172679 - 1.0118398 - 1.0002123 - 1.0092124 - 1.0071943 - 0.99508468 - 1.0019303 - 1.0030733 - 0.9964198 - 1.0027298 - 0.99797614 - 1.006942 - 0.99793928 - 1.0083214 - 1.0283732 - 1.0111102 - 1.016936 - 1.0229061 - 0.98846454 - 1.0015387 - 1.0201769 - 1.0079822 - 1.0064007 - 1.0095543 - 1.0092207 - 1.0135485 - 1.0198974 - 1.0140252 - 1.0128686 - 1.0092903 - 1.0141974 - 1.0023492 - 0.99731455 - 1.0026598 - 0.99303643 - 1.0036469 - 1.0160975 - 1.0368378 - 1.0139625 - 1.01493 - 1.0113531 - 1.0114548 - 0.99833441 - 0.99648401 - 0.97645361 - 1.0154053 - 1.01703 + 1.0079715 + 1.0074573 + 1.0153107 + 1.0152677 + 1.0011653 + 0.99950061 + 1.0328311 + 1.0192317 + 1.009827 + 0.99588916 + 1.007474 + 1.0113061 + 0.98696624 + 0.99978663 + 0.98240542 + 0.98861723 + 0.99008763 + 1.0185076 + 1.0052452 + 0.99447194 + 1.0092685 + 1.01208 + 1.0105237 + 0.98513875 + 1.0165628 + 0.99485934 + 1.0050255 + 1.0140756 + 1.0093128 + 1.0155868 + 1.0107023 + 0.99212762 + 1.0095465 + 1.0028435 + 1.0069437 + 1.0070473 + 1.0145902 + 1.0186922 + 1.0059917 + 1.0113072 + 1.0107386 + 0.99769196 + 0.99793444 + 1.0050791 + 0.98307821 + 1.0107594 + 0.99689982 + 0.98667064 + 0.9991662 + 0.98274722 + 0.98422032 + 0.99393016 + 1.0118567 + 0.99912781 + 1.0023744 + 1.0086662 + 1.0164773 + 1.0169327 + 1.0372478 + 1.0314242 + 1.0004256 + 1.0110541 + 1.0076575 + 1.0119851 + 1.0055188 + 1.0213959 + 1.0234416 + 1.0264917 + 1.0292725 + 1.0385184 + 1.0200999 + 1.0107697 + 1.008583 + 1.0200332 + 1.0030413 + 1.0108659 + 1.0185145 + 1.0168619 + 1.0180462 + 1.0239657 + 1.0205509 + 1.0189973 + 1.0246446 + 1.0135089 + 1.0352973 + 1.0099289 + 1.0266474 + 1.0279829 + 1.0101653 + 1.041216 + 1.0103861 + 1.0114727 + 1.0054605 + 1.0190722 + 1.0114837 + 1.0179213 + 1.006082 + 1.0049696 + 1.0143629 + 0.9971036 + 1.0005602 + 1.0078403 + 1.0240222 + 1.0195063 + 1.0355136 + 1.0218743 + 1.0171331 + 1.0049817 + 1.0140974 + 1.0168431 + 1.0049966 + 1.0045568 + 1.0156414 + 1.0273055 + 1.0197653 + 1.0030624 + 1.0154993 + 0.99782084 + 0.99711648 + 1.014408 + 1.0057417 + 0.99936837 + 1.0096934 + 1.0095138 + 1.0057734 + 1.0114497 + 1.0059784 + 1.0328889 + 1.0098032 + 1.0041114 + 1.0101247 + 1.0181588 + 1.0115712 + 1.0227509 + 1.0065104 + 1.0110902 + 1.0298169 + 1.0089532 + 1.0368733 + 1.0123033 + 1.0060763 + 1.0150937 + 1.0239325 + 0.99555536 + 0.99861271 + 1.0076201 + 0.99941535 + 1.0119522 + 1.0129183 + 0.99288924 + 1.0260784 + 1.0144982 + 1.0121985 + 1.0234916 + 1.02215 + 1.0190118 + 1.0172679 + 1.0118398 + 1.0002123 + 1.0092124 + 1.0071943 + 0.99508468 + 1.0019303 + 1.0030733 + 0.9964198 + 1.0027298 + 0.99797614 + 1.006942 + 0.99793928 + 1.0083214 + 1.0283732 + 1.0111102 + 1.016936 + 1.0229061 + 0.98846454 + 1.0015387 + 1.0201769 + 1.0079822 + 1.0064007 + 1.0095543 + 1.0092207 + 1.0135485 + 1.0198974 + 1.0140252 + 1.0128686 + 1.0092903 + 1.0141974 + 1.0023492 + 0.99731455 + 1.0026598 + 0.99303643 + 1.0036469 + 1.0160975 + 1.0368378 + 1.0139625 + 1.01493 + 1.0113531 + 1.0114548 + 0.99833441 + 0.99648401 + 0.97645361 + 1.0154053 + 1.01703 -]; + ]; Y_obs =[ - 1 - 0.99690484 - 1.0111781 - 1.0028141 - 1.0251518 - 1.0371688 - 1.0118899 - 0.98720726 - 1.0001589 - 1.0057481 - 1.0130085 - 1.0107643 - 1.0190194 - 1.0323428 - 1.0466587 - 1.0540438 - 1.0516886 - 1.0431553 - 1.0597913 - 1.0657172 - 1.0592201 - 1.0701863 - 1.0458402 - 1.0620582 - 1.0504499 - 1.0615817 - 1.0782384 - 1.0500687 - 1.0439257 - 1.0368658 - 1.0339255 - 1.0481453 - 1.0477181 - 1.0167109 - 1.0354878 - 1.0544782 - 1.0463762 - 1.0624445 - 1.0705737 - 1.0679484 - 1.0546356 - 1.0620691 - 1.0806955 - 1.0793581 - 1.1121124 - 1.0971458 - 1.1034869 - 1.1181859 - 1.1006634 - 1.1250883 - 1.1362214 - 1.1423343 - 1.1036061 - 1.1089288 - 1.1067125 - 1.0940906 - 1.0942197 - 1.0862174 - 1.06525 - 1.0511907 - 1.0598182 - 1.0513331 - 1.0212391 - 1.0057433 - 1.002663 - 0.97623167 - 0.97253165 - 0.97037865 - 0.97178055 - 0.95011397 - 0.95627969 - 0.96197747 - 0.97096053 - 0.98225794 - 1.0103595 - 1.0007597 - 1.003498 - 0.99246608 - 0.99656347 - 0.98804749 - 0.99122491 - 0.99522926 - 0.98731605 - 1.0145434 - 0.99330816 - 0.99759216 - 0.96814048 - 0.95296183 - 0.96362471 - 0.95925977 - 0.97682205 - 0.96993138 - 0.9743074 - 0.96821818 - 0.97413308 - 0.9741753 - 0.98237142 - 1.0054193 - 0.98044807 - 0.9716773 - 0.9730455 - 0.98405828 - 0.99220103 - 0.98444001 - 0.97919493 - 0.97205233 - 0.96728223 - 0.98529893 - 0.98452324 - 0.98299888 - 0.99145042 - 1.000933 - 0.99636447 - 0.98660883 - 0.98273271 - 0.98305518 - 0.98725774 - 0.99577549 - 1.002037 - 1.0060879 - 1.016075 - 1.0184118 - 1.0205711 - 1.0096961 - 1.0281337 - 1.0122963 - 1.0083497 - 0.99411874 - 0.976799 - 0.97146842 - 0.97464304 - 0.95587292 - 0.94779791 - 0.93266339 - 0.92720128 - 0.94105864 - 0.93277798 - 0.93393927 - 0.91216657 - 0.92045028 - 0.9099 - 0.90792098 - 0.90669634 - 0.91268867 - 0.91696661 - 0.91164685 - 0.91311495 - 0.92197825 - 0.92461222 - 0.94930422 - 0.9488119 - 0.95232353 - 0.97275278 - 0.96734995 - 0.95356817 - 0.96075548 - 0.96936594 - 0.97489002 - 0.97933106 - 0.96499412 - 0.96157973 - 0.97156334 - 0.95983765 - 0.93655215 - 0.95207909 - 0.96912862 - 0.97938462 - 0.95701655 - 0.94891457 - 0.95606317 - 0.95351125 - 0.95641767 - 0.94315807 - 0.94639265 - 0.96503697 - 0.95601693 - 0.93087851 - 0.92980141 - 0.92266844 - 0.92925206 - 0.93743628 - 0.92900826 - 0.9049711 - 0.90213859 - 0.91342916 - 0.91384707 - 0.91456681 - 0.91316822 - 0.92671976 - 0.92058549 - 0.92936541 - 0.93228212 - 0.91010921 - 0.89349322 - 0.90336005 - 0.90997873 - 0.91856328 - 0.91668007 - 0.92838606 - 0.932016 - 0.94545438 - 0.94070026 - 0.93172987 + 1 + 0.99690484 + 1.0111781 + 1.0028141 + 1.0251518 + 1.0371688 + 1.0118899 + 0.98720726 + 1.0001589 + 1.0057481 + 1.0130085 + 1.0107643 + 1.0190194 + 1.0323428 + 1.0466587 + 1.0540438 + 1.0516886 + 1.0431553 + 1.0597913 + 1.0657172 + 1.0592201 + 1.0701863 + 1.0458402 + 1.0620582 + 1.0504499 + 1.0615817 + 1.0782384 + 1.0500687 + 1.0439257 + 1.0368658 + 1.0339255 + 1.0481453 + 1.0477181 + 1.0167109 + 1.0354878 + 1.0544782 + 1.0463762 + 1.0624445 + 1.0705737 + 1.0679484 + 1.0546356 + 1.0620691 + 1.0806955 + 1.0793581 + 1.1121124 + 1.0971458 + 1.1034869 + 1.1181859 + 1.1006634 + 1.1250883 + 1.1362214 + 1.1423343 + 1.1036061 + 1.1089288 + 1.1067125 + 1.0940906 + 1.0942197 + 1.0862174 + 1.06525 + 1.0511907 + 1.0598182 + 1.0513331 + 1.0212391 + 1.0057433 + 1.002663 + 0.97623167 + 0.97253165 + 0.97037865 + 0.97178055 + 0.95011397 + 0.95627969 + 0.96197747 + 0.97096053 + 0.98225794 + 1.0103595 + 1.0007597 + 1.003498 + 0.99246608 + 0.99656347 + 0.98804749 + 0.99122491 + 0.99522926 + 0.98731605 + 1.0145434 + 0.99330816 + 0.99759216 + 0.96814048 + 0.95296183 + 0.96362471 + 0.95925977 + 0.97682205 + 0.96993138 + 0.9743074 + 0.96821818 + 0.97413308 + 0.9741753 + 0.98237142 + 1.0054193 + 0.98044807 + 0.9716773 + 0.9730455 + 0.98405828 + 0.99220103 + 0.98444001 + 0.97919493 + 0.97205233 + 0.96728223 + 0.98529893 + 0.98452324 + 0.98299888 + 0.99145042 + 1.000933 + 0.99636447 + 0.98660883 + 0.98273271 + 0.98305518 + 0.98725774 + 0.99577549 + 1.002037 + 1.0060879 + 1.016075 + 1.0184118 + 1.0205711 + 1.0096961 + 1.0281337 + 1.0122963 + 1.0083497 + 0.99411874 + 0.976799 + 0.97146842 + 0.97464304 + 0.95587292 + 0.94779791 + 0.93266339 + 0.92720128 + 0.94105864 + 0.93277798 + 0.93393927 + 0.91216657 + 0.92045028 + 0.9099 + 0.90792098 + 0.90669634 + 0.91268867 + 0.91696661 + 0.91164685 + 0.91311495 + 0.92197825 + 0.92461222 + 0.94930422 + 0.9488119 + 0.95232353 + 0.97275278 + 0.96734995 + 0.95356817 + 0.96075548 + 0.96936594 + 0.97489002 + 0.97933106 + 0.96499412 + 0.96157973 + 0.97156334 + 0.95983765 + 0.93655215 + 0.95207909 + 0.96912862 + 0.97938462 + 0.95701655 + 0.94891457 + 0.95606317 + 0.95351125 + 0.95641767 + 0.94315807 + 0.94639265 + 0.96503697 + 0.95601693 + 0.93087851 + 0.92980141 + 0.92266844 + 0.92925206 + 0.93743628 + 0.92900826 + 0.9049711 + 0.90213859 + 0.91342916 + 0.91384707 + 0.91456681 + 0.91316822 + 0.92671976 + 0.92058549 + 0.92936541 + 0.93228212 + 0.91010921 + 0.89349322 + 0.90336005 + 0.90997873 + 0.91856328 + 0.91668007 + 0.92838606 + 0.932016 + 0.94545438 + 0.94070026 + 0.93172987 -]; + ]; P_obs =[ - 1 - 0.99948573 - 1.0068249 - 1.0141211 - 1.0073149 - 0.99884398 - 1.0237035 - 1.0349636 - 1.036819 - 1.0247366 - 1.0242391 - 1.0275737 - 1.0065684 - 0.99838346 - 0.97281734 - 0.95346302 - 0.9355791 - 0.9461152 - 0.94338882 - 0.92988921 - 0.9311862 - 0.93529467 - 0.93784681 - 0.91501401 - 0.92360522 - 0.91049302 - 0.90754698 - 0.91365103 - 0.91499228 - 0.92260749 - 0.92533824 - 0.90949431 - 0.91106924 - 0.90594116 - 0.90491334 - 0.9039891 - 0.91060772 - 0.92132842 - 0.91934854 - 0.92268418 - 0.92545127 - 0.91517169 - 0.90513459 - 0.90224212 - 0.87734878 - 0.88013667 - 0.86906494 - 0.84776403 - 0.83895869 - 0.81373437 - 0.78998314 - 0.77594176 - 0.77982695 - 0.77098321 - 0.76538611 - 0.76608075 - 0.77458654 - 0.78354767 - 0.81282389 - 0.83627649 - 0.82873051 - 0.83181309 - 0.83149903 - 0.83551261 - 0.83305985 - 0.84648418 - 0.86195421 - 0.88047436 - 0.90177533 - 0.93232215 - 0.94445051 - 0.9472487 - 0.94786015 - 0.95992178 - 0.95499149 - 0.95788581 - 0.9684288 - 0.97731917 - 0.98739379 - 1.0033879 - 1.0159673 - 1.0269931 - 1.0436661 - 1.0492034 - 1.0765292 - 1.0784865 - 1.0971624 - 1.1171737 - 1.1193675 - 1.1526119 - 1.1550265 - 1.1585277 - 1.1560166 - 1.1671172 - 1.1706294 - 1.1805791 - 1.1786896 - 1.1756876 - 1.1820789 - 1.171211 - 1.1637997 - 1.1636684 - 1.179719 - 1.1912538 - 1.2187959 - 1.2326986 - 1.2418602 - 1.2388704 - 1.2449963 - 1.2538678 - 1.2508929 - 1.2474781 - 1.255148 - 1.274482 - 1.2862757 - 1.2813665 - 1.2888943 - 1.2787436 - 1.2678886 - 1.274325 - 1.2720952 - 1.263492 - 1.2652139 - 1.2667561 - 1.264558 - 1.2680362 - 1.2660431 - 1.2909605 - 1.2927921 - 1.288932 - 1.2910852 - 1.3012725 - 1.3048721 - 1.3196515 - 1.3181903 - 1.321309 - 1.3431543 - 1.344136 - 1.3730377 - 1.3773695 - 1.3754742 - 1.3825964 - 1.3985574 - 1.3861412 - 1.3767823 - 1.3764309 - 1.3678747 - 1.3718554 - 1.3768022 - 1.3617199 - 1.3798267 - 1.3863533 - 1.3905803 - 1.4061004 - 1.4202788 - 1.4313191 - 1.4406155 - 1.4444837 - 1.4367244 - 1.4379653 - 1.4371881 - 1.4243012 - 1.41826 - 1.4133617 - 1.40181 - 1.3965683 - 1.3865729 - 1.3855433 - 1.3755111 - 1.3758609 - 1.3962625 - 1.3994012 - 1.4083656 - 1.4233002 - 1.4037932 - 1.3973604 - 1.4095657 - 1.4095764 - 1.4080055 - 1.4095882 - 1.4108374 - 1.4164143 - 1.4283402 - 1.4343939 - 1.4392909 - 1.4406097 - 1.4468355 - 1.4412132 - 1.4305562 - 1.4252445 - 1.4103094 - 1.4059847 - 1.4141106 - 1.4429769 - 1.4489679 - 1.4559263 - 1.4593079 - 1.4627911 - 1.453154 - 1.4416665 - 1.4101485 - 1.4175823 - 1.4266407 + 1 + 0.99948573 + 1.0068249 + 1.0141211 + 1.0073149 + 0.99884398 + 1.0237035 + 1.0349636 + 1.036819 + 1.0247366 + 1.0242391 + 1.0275737 + 1.0065684 + 0.99838346 + 0.97281734 + 0.95346302 + 0.9355791 + 0.9461152 + 0.94338882 + 0.92988921 + 0.9311862 + 0.93529467 + 0.93784681 + 0.91501401 + 0.92360522 + 0.91049302 + 0.90754698 + 0.91365103 + 0.91499228 + 0.92260749 + 0.92533824 + 0.90949431 + 0.91106924 + 0.90594116 + 0.90491334 + 0.9039891 + 0.91060772 + 0.92132842 + 0.91934854 + 0.92268418 + 0.92545127 + 0.91517169 + 0.90513459 + 0.90224212 + 0.87734878 + 0.88013667 + 0.86906494 + 0.84776403 + 0.83895869 + 0.81373437 + 0.78998314 + 0.77594176 + 0.77982695 + 0.77098321 + 0.76538611 + 0.76608075 + 0.77458654 + 0.78354767 + 0.81282389 + 0.83627649 + 0.82873051 + 0.83181309 + 0.83149903 + 0.83551261 + 0.83305985 + 0.84648418 + 0.86195421 + 0.88047436 + 0.90177533 + 0.93232215 + 0.94445051 + 0.9472487 + 0.94786015 + 0.95992178 + 0.95499149 + 0.95788581 + 0.9684288 + 0.97731917 + 0.98739379 + 1.0033879 + 1.0159673 + 1.0269931 + 1.0436661 + 1.0492034 + 1.0765292 + 1.0784865 + 1.0971624 + 1.1171737 + 1.1193675 + 1.1526119 + 1.1550265 + 1.1585277 + 1.1560166 + 1.1671172 + 1.1706294 + 1.1805791 + 1.1786896 + 1.1756876 + 1.1820789 + 1.171211 + 1.1637997 + 1.1636684 + 1.179719 + 1.1912538 + 1.2187959 + 1.2326986 + 1.2418602 + 1.2388704 + 1.2449963 + 1.2538678 + 1.2508929 + 1.2474781 + 1.255148 + 1.274482 + 1.2862757 + 1.2813665 + 1.2888943 + 1.2787436 + 1.2678886 + 1.274325 + 1.2720952 + 1.263492 + 1.2652139 + 1.2667561 + 1.264558 + 1.2680362 + 1.2660431 + 1.2909605 + 1.2927921 + 1.288932 + 1.2910852 + 1.3012725 + 1.3048721 + 1.3196515 + 1.3181903 + 1.321309 + 1.3431543 + 1.344136 + 1.3730377 + 1.3773695 + 1.3754742 + 1.3825964 + 1.3985574 + 1.3861412 + 1.3767823 + 1.3764309 + 1.3678747 + 1.3718554 + 1.3768022 + 1.3617199 + 1.3798267 + 1.3863533 + 1.3905803 + 1.4061004 + 1.4202788 + 1.4313191 + 1.4406155 + 1.4444837 + 1.4367244 + 1.4379653 + 1.4371881 + 1.4243012 + 1.41826 + 1.4133617 + 1.40181 + 1.3965683 + 1.3865729 + 1.3855433 + 1.3755111 + 1.3758609 + 1.3962625 + 1.3994012 + 1.4083656 + 1.4233002 + 1.4037932 + 1.3973604 + 1.4095657 + 1.4095764 + 1.4080055 + 1.4095882 + 1.4108374 + 1.4164143 + 1.4283402 + 1.4343939 + 1.4392909 + 1.4406097 + 1.4468355 + 1.4412132 + 1.4305562 + 1.4252445 + 1.4103094 + 1.4059847 + 1.4141106 + 1.4429769 + 1.4489679 + 1.4559263 + 1.4593079 + 1.4627911 + 1.453154 + 1.4416665 + 1.4101485 + 1.4175823 + 1.4266407 -]; + ]; diff --git a/tests/decision_rules/third_order/comparison_policy_functions_dynare_mathematica.m b/tests/decision_rules/third_order/comparison_policy_functions_dynare_mathematica.m index 729fd152fc..8739e93168 100644 --- a/tests/decision_rules/third_order/comparison_policy_functions_dynare_mathematica.m +++ b/tests/decision_rules/third_order/comparison_policy_functions_dynare_mathematica.m @@ -1,8 +1,8 @@ %read in the FV et al. policy functions derived from Mathematica if ~isoctave() && ~matlab_ver_less_than('8.4') - websave('FV_2011_policyfunctions.mat','http://www.dynare.org/Datasets/FV_2011_policyfunctions.mat', weboptions('Timeout', 30)) + websave('FV_2011_policyfunctions.mat','http://www.dynare.org/Datasets/FV_2011_policyfunctions.mat', weboptions('Timeout', 30)) else - urlwrite('http://www.dynare.org/Datasets/FV_2011_policyfunctions.mat','FV_2011_policyfunctions.mat') + urlwrite('http://www.dynare.org/Datasets/FV_2011_policyfunctions.mat','FV_2011_policyfunctions.mat') end load FV_2011_policyfunctions @@ -79,9 +79,9 @@ end gxxx_dyn=zeros(size(gxxx)); for endo_iter_1=1:nx for endo_iter_2=1:nx - for endo_iter_3=1:nx + for endo_iter_3=1:nx gxxx_dyn(nu+endo_iter_1,nu+endo_iter_2,nu+endo_iter_3,:)=dr.ghxxx(FV_endo_order,(FV_endo_state_order(endo_iter_1)-1)*nx*nx+(FV_endo_state_order(endo_iter_2)-1)*nx+FV_endo_state_order(endo_iter_3)); - end + end end end @@ -95,21 +95,21 @@ end for endo_iter_1=1:nx for endo_iter_2=1:nx - for exo_iter=1:nu + for exo_iter=1:nu gxxx_dyn(nu+endo_iter_1,nu+endo_iter_2,exo_iter,:)=dr.ghxxu(FV_endo_order,(FV_endo_state_order(endo_iter_1)-1)*nx*nu+(FV_endo_state_order(endo_iter_2)-1)*nu+FV_exo_order(exo_iter)); gxxx_dyn(exo_iter,nu+endo_iter_2,nu+endo_iter_1,:)=dr.ghxxu(FV_endo_order,(FV_endo_state_order(endo_iter_1)-1)*nx*nu+(FV_endo_state_order(endo_iter_2)-1)*nu+FV_exo_order(exo_iter)); gxxx_dyn(nu+endo_iter_1,exo_iter,nu+endo_iter_2,:)=dr.ghxxu(FV_endo_order,(FV_endo_state_order(endo_iter_1)-1)*nx*nu+(FV_endo_state_order(endo_iter_2)-1)*nu+FV_exo_order(exo_iter)); - end + end end end for endo_iter_1=1:nx for exo_iter_1=1:nu - for exo_iter_2=1:nu + for exo_iter_2=1:nu gxxx_dyn(nu+endo_iter_1,exo_iter_1,exo_iter_2,:)=dr.ghxuu(FV_endo_order,(FV_endo_state_order(endo_iter_1)-1)*nu*nu+(FV_exo_order(exo_iter_1)-1)*nu+FV_exo_order(exo_iter_2)); gxxx_dyn(exo_iter_1,nu+endo_iter_1,exo_iter_2,:)=dr.ghxuu(FV_endo_order,(FV_endo_state_order(endo_iter_1)-1)*nu*nu+(FV_exo_order(exo_iter_1)-1)*nu+FV_exo_order(exo_iter_2)); gxxx_dyn(exo_iter_1,exo_iter_2,nu+endo_iter_1,:)=dr.ghxuu(FV_endo_order,(FV_endo_state_order(endo_iter_1)-1)*nu*nu+(FV_exo_order(exo_iter_1)-1)*nu+FV_exo_order(exo_iter_2)); - end + end end end diff --git a/tests/ep/ar_steadystate.m b/tests/ep/ar_steadystate.m index 966331f8e2..d040472426 100644 --- a/tests/ep/ar_steadystate.m +++ b/tests/ep/ar_steadystate.m @@ -1,8 +1,8 @@ function [ys, info] = ar_steadystate(ys, exogenous) % Steady state routine for ar.mod (First order autoregressive process) - + global M_ - + info = 0; ys(1)=M_.params(2); diff --git a/tests/ep/exact_solution.m b/tests/ep/exact_solution.m index 5b525797fa..64b1aa7dc6 100644 --- a/tests/ep/exact_solution.m +++ b/tests/ep/exact_solution.m @@ -1,30 +1,30 @@ function y=exact_solution(M,oo,n) - beta = M.params(1); - theta = M.params(2); - rho = M.params(3); - xbar = M.params(4); - sigma2 = M.Sigma_e; - - if beta*exp(theta*xbar+.5*theta^2*sigma2/(1-rho)^2)>1-eps - disp('The model doesn''t have a solution!') - return - end - - i = 1:n; - a = theta*xbar*i+(theta^2*sigma2)/(2*(1-rho)^2)*(i-2*rho*(1-rho.^i)/(1-rho)+rho^2*(1-rho.^(2*i))/(1-rho^2)); - b = theta*rho*(1-rho.^i)/(1-rho); - - x = oo.endo_simul(2,:); - xhat = x-xbar; - - n2 = size(x,2); - - y = zeros(1,n2); - - - for j=1:n2 - y(j) = sum(beta.^i.*exp(a+b*xhat(j))); - end - - disp(sum(beta.^i.*exp(theta*xbar*i))) - disp(sum(beta.^i.*exp(a))) \ No newline at end of file +beta = M.params(1); +theta = M.params(2); +rho = M.params(3); +xbar = M.params(4); +sigma2 = M.Sigma_e; + +if beta*exp(theta*xbar+.5*theta^2*sigma2/(1-rho)^2)>1-eps + disp('The model doesn''t have a solution!') + return +end + +i = 1:n; +a = theta*xbar*i+(theta^2*sigma2)/(2*(1-rho)^2)*(i-2*rho*(1-rho.^i)/(1-rho)+rho^2*(1-rho.^(2*i))/(1-rho^2)); +b = theta*rho*(1-rho.^i)/(1-rho); + +x = oo.endo_simul(2,:); +xhat = x-xbar; + +n2 = size(x,2); + +y = zeros(1,n2); + + +for j=1:n2 + y(j) = sum(beta.^i.*exp(a+b*xhat(j))); +end + +disp(sum(beta.^i.*exp(theta*xbar*i))) +disp(sum(beta.^i.*exp(a))) \ No newline at end of file diff --git a/tests/ep/rbcii_steady_state.m b/tests/ep/rbcii_steady_state.m index 5fc2dcb1ae..dd79d28a4b 100644 --- a/tests/ep/rbcii_steady_state.m +++ b/tests/ep/rbcii_steady_state.m @@ -1,61 +1,61 @@ -function [ys_, params, info] = rbcii_steadystate2(ys_, exo_, params) - - % Flag initialization (equal to zero if the deterministic steady state exists) - info = 0; - - % efficiency - ys_(13)=0; - - % Efficiency - ys_(12)=params(8); - - % Steady state ratios - Output_per_unit_of_Capital=((1/params(1)-1+params(6))/params(4))^(1/(1-params(5))); - Consumption_per_unit_of_Capital=Output_per_unit_of_Capital-params(6); - Labour_per_unit_of_Capital=(((Output_per_unit_of_Capital/ys_(12))^params(5)-params(4))/(1-params(4)))^(1/params(5)); - Output_per_unit_of_Labour=Output_per_unit_of_Capital/Labour_per_unit_of_Capital; - Consumption_per_unit_of_Labour=Consumption_per_unit_of_Capital/Labour_per_unit_of_Capital; - - % Steady state share of capital revenues in total revenues (calibration check) - ShareOfCapital=params(4)/(params(4)+(1-params(4))*Labour_per_unit_of_Capital^params(5)); - - % Steady state level of labour - ys_(3)=1/(1+Consumption_per_unit_of_Labour/((1-params(4))*params(2)/(1-params(2))*Output_per_unit_of_Labour^(1-params(5)))); - - % Steady state level of consumption - ys_(4)=Consumption_per_unit_of_Labour*ys_(3); - - % Steady state level of physical capital stock - ys_(1)=ys_(3)/Labour_per_unit_of_Capital; - - % Steady state level of output - ys_(2)=Output_per_unit_of_Capital*ys_(1); - - % Steady state level of investment - ys_(5)=params(6)*ys_(1); - - % Steady state level of the expected term appearing in the Euler equation - ys_(14)=(ys_(4)^params(2)*(1-ys_(3))^(1-params(2)))^(1-params(3))/ys_(4)*(1+params(4)*(ys_(2)/ys_(1))^(1-params(5))-params(6)); - - % Steady state level of output in the unconstrained regime (positive investment) - ys_(6)=ys_(2); - - % Steady state level of labour in the unconstrained regime - ys_(7)=ys_(3); - - % Steady state level of consumption in the unconstrained regime - ys_(8)=ys_(4); - - % Steady state level of labour in the constrained regime (noinvestment) - [lss,info] = l_solver(ys_(3),params(4),params(5),params(2),params(8),ys_(1),100); - if info, return, end - ys_(10) = lss; - - % Steady state level of consumption in the constrained regime - ys_(11)=params(8)*(params(4)*ys_(1)^params(5)+(1-params(4))*ys_(10)^params(5))^(1/params(5)); - - % Steady state level of output in the constrained regime - ys_(9)=ys_(11); +function [ys_, params, info] = rbcii_steady_state(ys_, exo_, params) + +% Flag initialization (equal to zero if the deterministic steady state exists) +info = 0; + +% efficiency +ys_(13)=0; + +% Efficiency +ys_(12)=params(8); + +% Steady state ratios +Output_per_unit_of_Capital=((1/params(1)-1+params(6))/params(4))^(1/(1-params(5))); +Consumption_per_unit_of_Capital=Output_per_unit_of_Capital-params(6); +Labour_per_unit_of_Capital=(((Output_per_unit_of_Capital/ys_(12))^params(5)-params(4))/(1-params(4)))^(1/params(5)); +Output_per_unit_of_Labour=Output_per_unit_of_Capital/Labour_per_unit_of_Capital; +Consumption_per_unit_of_Labour=Consumption_per_unit_of_Capital/Labour_per_unit_of_Capital; + +% Steady state share of capital revenues in total revenues (calibration check) +ShareOfCapital=params(4)/(params(4)+(1-params(4))*Labour_per_unit_of_Capital^params(5)); + +% Steady state level of labour +ys_(3)=1/(1+Consumption_per_unit_of_Labour/((1-params(4))*params(2)/(1-params(2))*Output_per_unit_of_Labour^(1-params(5)))); + +% Steady state level of consumption +ys_(4)=Consumption_per_unit_of_Labour*ys_(3); + +% Steady state level of physical capital stock +ys_(1)=ys_(3)/Labour_per_unit_of_Capital; + +% Steady state level of output +ys_(2)=Output_per_unit_of_Capital*ys_(1); + +% Steady state level of investment +ys_(5)=params(6)*ys_(1); + +% Steady state level of the expected term appearing in the Euler equation +ys_(14)=(ys_(4)^params(2)*(1-ys_(3))^(1-params(2)))^(1-params(3))/ys_(4)*(1+params(4)*(ys_(2)/ys_(1))^(1-params(5))-params(6)); + +% Steady state level of output in the unconstrained regime (positive investment) +ys_(6)=ys_(2); + +% Steady state level of labour in the unconstrained regime +ys_(7)=ys_(3); + +% Steady state level of consumption in the unconstrained regime +ys_(8)=ys_(4); + +% Steady state level of labour in the constrained regime (noinvestment) +[lss,info] = l_solver(ys_(3),params(4),params(5),params(2),params(8),ys_(1),100); +if info, return, end +ys_(10) = lss; + +% Steady state level of consumption in the constrained regime +ys_(11)=params(8)*(params(4)*ys_(1)^params(5)+(1-params(4))*ys_(10)^params(5))^(1/params(5)); + +% Steady state level of output in the constrained regime +ys_(9)=ys_(11); end @@ -63,26 +63,26 @@ end function r = p0(labour,alpha,psi,theta,effstar,kstar) - r = labour * ( alpha*kstar^psi/labour^psi + 1-alpha + theta*(1-alpha)/(1-theta)/effstar^psi ) - theta*(1-alpha)/(1-theta)/effstar^psi; +r = labour * ( alpha*kstar^psi/labour^psi + 1-alpha + theta*(1-alpha)/(1-theta)/effstar^psi ) - theta*(1-alpha)/(1-theta)/effstar^psi; end - + function d = p1(labour,alpha,psi,theta,effstar,kstar) - d = alpha*(1-psi)*kstar^psi/labour^psi + 1-alpha + theta*(1-alpha)/(1-alpha)/effstar^psi; +d = alpha*(1-psi)*kstar^psi/labour^psi + 1-alpha + theta*(1-alpha)/(1-alpha)/effstar^psi; end function [labour,info] = l_solver(labour,alpha,psi,theta,effstar,kstar,maxiter) - iteration = 1; info = 0; - r = p0(labour,alpha,psi,theta,effstar,kstar); - condition = abs(r); - while condition - if iteration==maxiter - info = 1; - break - end - d = p1(labour,alpha,psi,theta,effstar,kstar); - labour = labour - r/d; - r = p0(labour,alpha,psi,theta,effstar,kstar); - condition = abs(r)>1e-9; - iteration = iteration + 1; +iteration = 1; info = 0; +r = p0(labour,alpha,psi,theta,effstar,kstar); +condition = abs(r); +while condition + if iteration==maxiter + info = 1; + break end + d = p1(labour,alpha,psi,theta,effstar,kstar); + labour = labour - r/d; + r = p0(labour,alpha,psi,theta,effstar,kstar); + condition = abs(r)>1e-9; + iteration = iteration + 1; +end end \ No newline at end of file diff --git a/tests/estimation/fsdat_simul.m b/tests/estimation/fsdat_simul.m index d4f4a8066f..159612e577 100644 --- a/tests/estimation/fsdat_simul.m +++ b/tests/estimation/fsdat_simul.m @@ -1,828 +1,828 @@ gy_obs =[ - 1.0030045 - 0.99990934 - 1.0172778 - 0.99464043 - 1.0253423 - 1.0150215 - 0.97772557 - 0.97832186 - 1.0159561 - 1.0085937 - 1.0102649 - 1.0007604 - 1.0112596 - 1.0163279 - 1.0173204 - 1.0103896 - 1.0006493 - 0.99447124 - 1.0196405 - 1.0089304 - 0.99650737 - 1.0139707 - 0.97865842 - 1.0192225 - 0.99139628 - 1.0141362 - 1.0196612 - 0.97483476 - 0.99686151 - 0.99594464 - 1.0000642 - 1.0172243 - 1.0025773 - 0.97199728 - 1.0217815 - 1.0219949 - 0.99490252 - 1.0190728 - 1.0111337 - 1.0003792 - 0.98969164 - 1.010438 - 1.0216309 - 1.0016671 - 1.0357588 - 0.98803787 - 1.0093457 - 1.0177035 - 0.98548204 - 1.0274294 - 1.0141377 - 1.0091174 - 0.96427632 - 1.0083272 - 1.0007882 - 0.99038262 - 1.0031336 - 0.99500213 - 0.98203716 - 0.9889452 - 1.011632 - 0.99451949 - 0.97291047 - 0.98750871 - 0.99992418 - 0.97657318 - 0.99930448 - 1.0008515 - 1.0044064 - 0.98133792 - 1.0091702 - 1.0087023 - 1.0119876 - 1.0143019 - 1.0311061 - 0.99340471 - 1.0057428 - 0.99197259 - 1.0071019 - 0.99448853 - 1.0061819 - 1.0070088 - 0.9950913 - 1.0302318 - 0.9817693 - 1.0072885 - 0.97355282 - 0.98782586 - 1.0136674 - 0.99863956 - 1.0205668 - 0.99611384 - 1.0073805 - 0.99691529 - 1.0089194 - 1.0030467 - 1.0112006 - 1.0260523 - 0.97803331 - 0.99423374 - 1.0043727 - 1.0140173 - 1.0111473 - 0.99524348 - 0.99775943 - 0.9958619 - 0.9982344 - 1.0210212 - 1.0022288 - 1.0014801 - 1.011456 - 1.0124871 - 0.99843599 - 0.99324886 - 0.99912838 - 1.003327 - 1.0072071 - 1.0115223 - 1.009266 - 1.0070554 - 1.0129916 - 1.0053413 - 1.0051638 - 0.99212952 - 1.0214422 - 0.98716707 - 0.99905788 - 0.98877357 - 0.98568476 - 0.99767393 - 1.0061791 - 0.98423439 - 0.99492949 - 0.98786999 - 0.99754239 - 1.0168619 - 0.99472384 - 1.0041658 - 0.98123181 - 1.0112882 - 0.99245422 - 1.0010255 - 1.0017799 - 1.0089968 - 1.0072824 - 0.99768475 - 1.0044726 - 1.0118678 - 1.0056385 - 1.0276965 - 1.0025122 - 1.0065161 - 1.0234338 - 0.99760167 - 0.98922272 - 1.0101918 - 1.011615 - 1.0085286 - 1.0074455 - 0.98866757 - 0.99959012 - 1.0129881 - 0.99127881 - 0.97971901 - 1.0185314 - 1.020054 - 1.0132605 - 0.98063643 - 0.99490253 - 1.0101531 - 1.0004526 - 1.0059109 - 0.98974491 - 1.0062391 - 1.0216488 - 0.99398446 - 0.97786609 - 1.0019274 - 0.99587153 - 1.0095881 - 1.0111887 - 0.99457649 - 0.97896734 - 1.000172 - 1.0142951 - 1.0034224 - 1.0037242 - 1.0016059 - 1.016556 - 0.99687023 - 1.0117844 - 1.0059212 - 0.98083159 - 0.98638851 - 1.0128713 - 1.0096232 - 1.0115891 - 1.0011213 - 1.0147105 - 1.0066344 - 1.0164429 - 0.99825038 - 0.99403411 + 1.0030045 + 0.99990934 + 1.0172778 + 0.99464043 + 1.0253423 + 1.0150215 + 0.97772557 + 0.97832186 + 1.0159561 + 1.0085937 + 1.0102649 + 1.0007604 + 1.0112596 + 1.0163279 + 1.0173204 + 1.0103896 + 1.0006493 + 0.99447124 + 1.0196405 + 1.0089304 + 0.99650737 + 1.0139707 + 0.97865842 + 1.0192225 + 0.99139628 + 1.0141362 + 1.0196612 + 0.97483476 + 0.99686151 + 0.99594464 + 1.0000642 + 1.0172243 + 1.0025773 + 0.97199728 + 1.0217815 + 1.0219949 + 0.99490252 + 1.0190728 + 1.0111337 + 1.0003792 + 0.98969164 + 1.010438 + 1.0216309 + 1.0016671 + 1.0357588 + 0.98803787 + 1.0093457 + 1.0177035 + 0.98548204 + 1.0274294 + 1.0141377 + 1.0091174 + 0.96427632 + 1.0083272 + 1.0007882 + 0.99038262 + 1.0031336 + 0.99500213 + 0.98203716 + 0.9889452 + 1.011632 + 0.99451949 + 0.97291047 + 0.98750871 + 0.99992418 + 0.97657318 + 0.99930448 + 1.0008515 + 1.0044064 + 0.98133792 + 1.0091702 + 1.0087023 + 1.0119876 + 1.0143019 + 1.0311061 + 0.99340471 + 1.0057428 + 0.99197259 + 1.0071019 + 0.99448853 + 1.0061819 + 1.0070088 + 0.9950913 + 1.0302318 + 0.9817693 + 1.0072885 + 0.97355282 + 0.98782586 + 1.0136674 + 0.99863956 + 1.0205668 + 0.99611384 + 1.0073805 + 0.99691529 + 1.0089194 + 1.0030467 + 1.0112006 + 1.0260523 + 0.97803331 + 0.99423374 + 1.0043727 + 1.0140173 + 1.0111473 + 0.99524348 + 0.99775943 + 0.9958619 + 0.9982344 + 1.0210212 + 1.0022288 + 1.0014801 + 1.011456 + 1.0124871 + 0.99843599 + 0.99324886 + 0.99912838 + 1.003327 + 1.0072071 + 1.0115223 + 1.009266 + 1.0070554 + 1.0129916 + 1.0053413 + 1.0051638 + 0.99212952 + 1.0214422 + 0.98716707 + 0.99905788 + 0.98877357 + 0.98568476 + 0.99767393 + 1.0061791 + 0.98423439 + 0.99492949 + 0.98786999 + 0.99754239 + 1.0168619 + 0.99472384 + 1.0041658 + 0.98123181 + 1.0112882 + 0.99245422 + 1.0010255 + 1.0017799 + 1.0089968 + 1.0072824 + 0.99768475 + 1.0044726 + 1.0118678 + 1.0056385 + 1.0276965 + 1.0025122 + 1.0065161 + 1.0234338 + 0.99760167 + 0.98922272 + 1.0101918 + 1.011615 + 1.0085286 + 1.0074455 + 0.98866757 + 0.99959012 + 1.0129881 + 0.99127881 + 0.97971901 + 1.0185314 + 1.020054 + 1.0132605 + 0.98063643 + 0.99490253 + 1.0101531 + 1.0004526 + 1.0059109 + 0.98974491 + 1.0062391 + 1.0216488 + 0.99398446 + 0.97786609 + 1.0019274 + 0.99587153 + 1.0095881 + 1.0111887 + 0.99457649 + 0.97896734 + 1.000172 + 1.0142951 + 1.0034224 + 1.0037242 + 1.0016059 + 1.016556 + 0.99687023 + 1.0117844 + 1.0059212 + 0.98083159 + 0.98638851 + 1.0128713 + 1.0096232 + 1.0115891 + 1.0011213 + 1.0147105 + 1.0066344 + 1.0164429 + 0.99825038 + 0.99403411 -]; + ]; gp_obs =[ - 1.0079715 - 1.0074573 - 1.0153107 - 1.0152677 - 1.0011653 - 0.99950061 - 1.0328311 - 1.0192317 - 1.009827 - 0.99588916 - 1.007474 - 1.0113061 - 0.98696624 - 0.99978663 - 0.98240542 - 0.98861723 - 0.99008763 - 1.0185076 - 1.0052452 - 0.99447194 - 1.0092685 - 1.01208 - 1.0105237 - 0.98513875 - 1.0165628 - 0.99485934 - 1.0050255 - 1.0140756 - 1.0093128 - 1.0155868 - 1.0107023 - 0.99212762 - 1.0095465 - 1.0028435 - 1.0069437 - 1.0070473 - 1.0145902 - 1.0186922 - 1.0059917 - 1.0113072 - 1.0107386 - 0.99769196 - 0.99793444 - 1.0050791 - 0.98307821 - 1.0107594 - 0.99689982 - 0.98667064 - 0.9991662 - 0.98274722 - 0.98422032 - 0.99393016 - 1.0118567 - 0.99912781 - 1.0023744 - 1.0086662 - 1.0164773 - 1.0169327 - 1.0372478 - 1.0314242 - 1.0004256 - 1.0110541 - 1.0076575 - 1.0119851 - 1.0055188 - 1.0213959 - 1.0234416 - 1.0264917 - 1.0292725 - 1.0385184 - 1.0200999 - 1.0107697 - 1.008583 - 1.0200332 - 1.0030413 - 1.0108659 - 1.0185145 - 1.0168619 - 1.0180462 - 1.0239657 - 1.0205509 - 1.0189973 - 1.0246446 - 1.0135089 - 1.0352973 - 1.0099289 - 1.0266474 - 1.0279829 - 1.0101653 - 1.041216 - 1.0103861 - 1.0114727 - 1.0054605 - 1.0190722 - 1.0114837 - 1.0179213 - 1.006082 - 1.0049696 - 1.0143629 - 0.9971036 - 1.0005602 - 1.0078403 - 1.0240222 - 1.0195063 - 1.0355136 - 1.0218743 - 1.0171331 - 1.0049817 - 1.0140974 - 1.0168431 - 1.0049966 - 1.0045568 - 1.0156414 - 1.0273055 - 1.0197653 - 1.0030624 - 1.0154993 - 0.99782084 - 0.99711648 - 1.014408 - 1.0057417 - 0.99936837 - 1.0096934 - 1.0095138 - 1.0057734 - 1.0114497 - 1.0059784 - 1.0328889 - 1.0098032 - 1.0041114 - 1.0101247 - 1.0181588 - 1.0115712 - 1.0227509 - 1.0065104 - 1.0110902 - 1.0298169 - 1.0089532 - 1.0368733 - 1.0123033 - 1.0060763 - 1.0150937 - 1.0239325 - 0.99555536 - 0.99861271 - 1.0076201 - 0.99941535 - 1.0119522 - 1.0129183 - 0.99288924 - 1.0260784 - 1.0144982 - 1.0121985 - 1.0234916 - 1.02215 - 1.0190118 - 1.0172679 - 1.0118398 - 1.0002123 - 1.0092124 - 1.0071943 - 0.99508468 - 1.0019303 - 1.0030733 - 0.9964198 - 1.0027298 - 0.99797614 - 1.006942 - 0.99793928 - 1.0083214 - 1.0283732 - 1.0111102 - 1.016936 - 1.0229061 - 0.98846454 - 1.0015387 - 1.0201769 - 1.0079822 - 1.0064007 - 1.0095543 - 1.0092207 - 1.0135485 - 1.0198974 - 1.0140252 - 1.0128686 - 1.0092903 - 1.0141974 - 1.0023492 - 0.99731455 - 1.0026598 - 0.99303643 - 1.0036469 - 1.0160975 - 1.0368378 - 1.0139625 - 1.01493 - 1.0113531 - 1.0114548 - 0.99833441 - 0.99648401 - 0.97645361 - 1.0154053 - 1.01703 + 1.0079715 + 1.0074573 + 1.0153107 + 1.0152677 + 1.0011653 + 0.99950061 + 1.0328311 + 1.0192317 + 1.009827 + 0.99588916 + 1.007474 + 1.0113061 + 0.98696624 + 0.99978663 + 0.98240542 + 0.98861723 + 0.99008763 + 1.0185076 + 1.0052452 + 0.99447194 + 1.0092685 + 1.01208 + 1.0105237 + 0.98513875 + 1.0165628 + 0.99485934 + 1.0050255 + 1.0140756 + 1.0093128 + 1.0155868 + 1.0107023 + 0.99212762 + 1.0095465 + 1.0028435 + 1.0069437 + 1.0070473 + 1.0145902 + 1.0186922 + 1.0059917 + 1.0113072 + 1.0107386 + 0.99769196 + 0.99793444 + 1.0050791 + 0.98307821 + 1.0107594 + 0.99689982 + 0.98667064 + 0.9991662 + 0.98274722 + 0.98422032 + 0.99393016 + 1.0118567 + 0.99912781 + 1.0023744 + 1.0086662 + 1.0164773 + 1.0169327 + 1.0372478 + 1.0314242 + 1.0004256 + 1.0110541 + 1.0076575 + 1.0119851 + 1.0055188 + 1.0213959 + 1.0234416 + 1.0264917 + 1.0292725 + 1.0385184 + 1.0200999 + 1.0107697 + 1.008583 + 1.0200332 + 1.0030413 + 1.0108659 + 1.0185145 + 1.0168619 + 1.0180462 + 1.0239657 + 1.0205509 + 1.0189973 + 1.0246446 + 1.0135089 + 1.0352973 + 1.0099289 + 1.0266474 + 1.0279829 + 1.0101653 + 1.041216 + 1.0103861 + 1.0114727 + 1.0054605 + 1.0190722 + 1.0114837 + 1.0179213 + 1.006082 + 1.0049696 + 1.0143629 + 0.9971036 + 1.0005602 + 1.0078403 + 1.0240222 + 1.0195063 + 1.0355136 + 1.0218743 + 1.0171331 + 1.0049817 + 1.0140974 + 1.0168431 + 1.0049966 + 1.0045568 + 1.0156414 + 1.0273055 + 1.0197653 + 1.0030624 + 1.0154993 + 0.99782084 + 0.99711648 + 1.014408 + 1.0057417 + 0.99936837 + 1.0096934 + 1.0095138 + 1.0057734 + 1.0114497 + 1.0059784 + 1.0328889 + 1.0098032 + 1.0041114 + 1.0101247 + 1.0181588 + 1.0115712 + 1.0227509 + 1.0065104 + 1.0110902 + 1.0298169 + 1.0089532 + 1.0368733 + 1.0123033 + 1.0060763 + 1.0150937 + 1.0239325 + 0.99555536 + 0.99861271 + 1.0076201 + 0.99941535 + 1.0119522 + 1.0129183 + 0.99288924 + 1.0260784 + 1.0144982 + 1.0121985 + 1.0234916 + 1.02215 + 1.0190118 + 1.0172679 + 1.0118398 + 1.0002123 + 1.0092124 + 1.0071943 + 0.99508468 + 1.0019303 + 1.0030733 + 0.9964198 + 1.0027298 + 0.99797614 + 1.006942 + 0.99793928 + 1.0083214 + 1.0283732 + 1.0111102 + 1.016936 + 1.0229061 + 0.98846454 + 1.0015387 + 1.0201769 + 1.0079822 + 1.0064007 + 1.0095543 + 1.0092207 + 1.0135485 + 1.0198974 + 1.0140252 + 1.0128686 + 1.0092903 + 1.0141974 + 1.0023492 + 0.99731455 + 1.0026598 + 0.99303643 + 1.0036469 + 1.0160975 + 1.0368378 + 1.0139625 + 1.01493 + 1.0113531 + 1.0114548 + 0.99833441 + 0.99648401 + 0.97645361 + 1.0154053 + 1.01703 -]; + ]; Y_obs =[ - 1 - 0.99690484 - 1.0111781 - 1.0028141 - 1.0251518 - 1.0371688 - 1.0118899 - 0.98720726 - 1.0001589 - 1.0057481 - 1.0130085 - 1.0107643 - 1.0190194 - 1.0323428 - 1.0466587 - 1.0540438 - 1.0516886 - 1.0431553 - 1.0597913 - 1.0657172 - 1.0592201 - 1.0701863 - 1.0458402 - 1.0620582 - 1.0504499 - 1.0615817 - 1.0782384 - 1.0500687 - 1.0439257 - 1.0368658 - 1.0339255 - 1.0481453 - 1.0477181 - 1.0167109 - 1.0354878 - 1.0544782 - 1.0463762 - 1.0624445 - 1.0705737 - 1.0679484 - 1.0546356 - 1.0620691 - 1.0806955 - 1.0793581 - 1.1121124 - 1.0971458 - 1.1034869 - 1.1181859 - 1.1006634 - 1.1250883 - 1.1362214 - 1.1423343 - 1.1036061 - 1.1089288 - 1.1067125 - 1.0940906 - 1.0942197 - 1.0862174 - 1.06525 - 1.0511907 - 1.0598182 - 1.0513331 - 1.0212391 - 1.0057433 - 1.002663 - 0.97623167 - 0.97253165 - 0.97037865 - 0.97178055 - 0.95011397 - 0.95627969 - 0.96197747 - 0.97096053 - 0.98225794 - 1.0103595 - 1.0007597 - 1.003498 - 0.99246608 - 0.99656347 - 0.98804749 - 0.99122491 - 0.99522926 - 0.98731605 - 1.0145434 - 0.99330816 - 0.99759216 - 0.96814048 - 0.95296183 - 0.96362471 - 0.95925977 - 0.97682205 - 0.96993138 - 0.9743074 - 0.96821818 - 0.97413308 - 0.9741753 - 0.98237142 - 1.0054193 - 0.98044807 - 0.9716773 - 0.9730455 - 0.98405828 - 0.99220103 - 0.98444001 - 0.97919493 - 0.97205233 - 0.96728223 - 0.98529893 - 0.98452324 - 0.98299888 - 0.99145042 - 1.000933 - 0.99636447 - 0.98660883 - 0.98273271 - 0.98305518 - 0.98725774 - 0.99577549 - 1.002037 - 1.0060879 - 1.016075 - 1.0184118 - 1.0205711 - 1.0096961 - 1.0281337 - 1.0122963 - 1.0083497 - 0.99411874 - 0.976799 - 0.97146842 - 0.97464304 - 0.95587292 - 0.94779791 - 0.93266339 - 0.92720128 - 0.94105864 - 0.93277798 - 0.93393927 - 0.91216657 - 0.92045028 - 0.9099 - 0.90792098 - 0.90669634 - 0.91268867 - 0.91696661 - 0.91164685 - 0.91311495 - 0.92197825 - 0.92461222 - 0.94930422 - 0.9488119 - 0.95232353 - 0.97275278 - 0.96734995 - 0.95356817 - 0.96075548 - 0.96936594 - 0.97489002 - 0.97933106 - 0.96499412 - 0.96157973 - 0.97156334 - 0.95983765 - 0.93655215 - 0.95207909 - 0.96912862 - 0.97938462 - 0.95701655 - 0.94891457 - 0.95606317 - 0.95351125 - 0.95641767 - 0.94315807 - 0.94639265 - 0.96503697 - 0.95601693 - 0.93087851 - 0.92980141 - 0.92266844 - 0.92925206 - 0.93743628 - 0.92900826 - 0.9049711 - 0.90213859 - 0.91342916 - 0.91384707 - 0.91456681 - 0.91316822 - 0.92671976 - 0.92058549 - 0.92936541 - 0.93228212 - 0.91010921 - 0.89349322 - 0.90336005 - 0.90997873 - 0.91856328 - 0.91668007 - 0.92838606 - 0.932016 - 0.94545438 - 0.94070026 - 0.93172987 + 1 + 0.99690484 + 1.0111781 + 1.0028141 + 1.0251518 + 1.0371688 + 1.0118899 + 0.98720726 + 1.0001589 + 1.0057481 + 1.0130085 + 1.0107643 + 1.0190194 + 1.0323428 + 1.0466587 + 1.0540438 + 1.0516886 + 1.0431553 + 1.0597913 + 1.0657172 + 1.0592201 + 1.0701863 + 1.0458402 + 1.0620582 + 1.0504499 + 1.0615817 + 1.0782384 + 1.0500687 + 1.0439257 + 1.0368658 + 1.0339255 + 1.0481453 + 1.0477181 + 1.0167109 + 1.0354878 + 1.0544782 + 1.0463762 + 1.0624445 + 1.0705737 + 1.0679484 + 1.0546356 + 1.0620691 + 1.0806955 + 1.0793581 + 1.1121124 + 1.0971458 + 1.1034869 + 1.1181859 + 1.1006634 + 1.1250883 + 1.1362214 + 1.1423343 + 1.1036061 + 1.1089288 + 1.1067125 + 1.0940906 + 1.0942197 + 1.0862174 + 1.06525 + 1.0511907 + 1.0598182 + 1.0513331 + 1.0212391 + 1.0057433 + 1.002663 + 0.97623167 + 0.97253165 + 0.97037865 + 0.97178055 + 0.95011397 + 0.95627969 + 0.96197747 + 0.97096053 + 0.98225794 + 1.0103595 + 1.0007597 + 1.003498 + 0.99246608 + 0.99656347 + 0.98804749 + 0.99122491 + 0.99522926 + 0.98731605 + 1.0145434 + 0.99330816 + 0.99759216 + 0.96814048 + 0.95296183 + 0.96362471 + 0.95925977 + 0.97682205 + 0.96993138 + 0.9743074 + 0.96821818 + 0.97413308 + 0.9741753 + 0.98237142 + 1.0054193 + 0.98044807 + 0.9716773 + 0.9730455 + 0.98405828 + 0.99220103 + 0.98444001 + 0.97919493 + 0.97205233 + 0.96728223 + 0.98529893 + 0.98452324 + 0.98299888 + 0.99145042 + 1.000933 + 0.99636447 + 0.98660883 + 0.98273271 + 0.98305518 + 0.98725774 + 0.99577549 + 1.002037 + 1.0060879 + 1.016075 + 1.0184118 + 1.0205711 + 1.0096961 + 1.0281337 + 1.0122963 + 1.0083497 + 0.99411874 + 0.976799 + 0.97146842 + 0.97464304 + 0.95587292 + 0.94779791 + 0.93266339 + 0.92720128 + 0.94105864 + 0.93277798 + 0.93393927 + 0.91216657 + 0.92045028 + 0.9099 + 0.90792098 + 0.90669634 + 0.91268867 + 0.91696661 + 0.91164685 + 0.91311495 + 0.92197825 + 0.92461222 + 0.94930422 + 0.9488119 + 0.95232353 + 0.97275278 + 0.96734995 + 0.95356817 + 0.96075548 + 0.96936594 + 0.97489002 + 0.97933106 + 0.96499412 + 0.96157973 + 0.97156334 + 0.95983765 + 0.93655215 + 0.95207909 + 0.96912862 + 0.97938462 + 0.95701655 + 0.94891457 + 0.95606317 + 0.95351125 + 0.95641767 + 0.94315807 + 0.94639265 + 0.96503697 + 0.95601693 + 0.93087851 + 0.92980141 + 0.92266844 + 0.92925206 + 0.93743628 + 0.92900826 + 0.9049711 + 0.90213859 + 0.91342916 + 0.91384707 + 0.91456681 + 0.91316822 + 0.92671976 + 0.92058549 + 0.92936541 + 0.93228212 + 0.91010921 + 0.89349322 + 0.90336005 + 0.90997873 + 0.91856328 + 0.91668007 + 0.92838606 + 0.932016 + 0.94545438 + 0.94070026 + 0.93172987 -]; + ]; P_obs =[ - 1 - 0.99948573 - 1.0068249 - 1.0141211 - 1.0073149 - 0.99884398 - 1.0237035 - 1.0349636 - 1.036819 - 1.0247366 - 1.0242391 - 1.0275737 - 1.0065684 - 0.99838346 - 0.97281734 - 0.95346302 - 0.9355791 - 0.9461152 - 0.94338882 - 0.92988921 - 0.9311862 - 0.93529467 - 0.93784681 - 0.91501401 - 0.92360522 - 0.91049302 - 0.90754698 - 0.91365103 - 0.91499228 - 0.92260749 - 0.92533824 - 0.90949431 - 0.91106924 - 0.90594116 - 0.90491334 - 0.9039891 - 0.91060772 - 0.92132842 - 0.91934854 - 0.92268418 - 0.92545127 - 0.91517169 - 0.90513459 - 0.90224212 - 0.87734878 - 0.88013667 - 0.86906494 - 0.84776403 - 0.83895869 - 0.81373437 - 0.78998314 - 0.77594176 - 0.77982695 - 0.77098321 - 0.76538611 - 0.76608075 - 0.77458654 - 0.78354767 - 0.81282389 - 0.83627649 - 0.82873051 - 0.83181309 - 0.83149903 - 0.83551261 - 0.83305985 - 0.84648418 - 0.86195421 - 0.88047436 - 0.90177533 - 0.93232215 - 0.94445051 - 0.9472487 - 0.94786015 - 0.95992178 - 0.95499149 - 0.95788581 - 0.9684288 - 0.97731917 - 0.98739379 - 1.0033879 - 1.0159673 - 1.0269931 - 1.0436661 - 1.0492034 - 1.0765292 - 1.0784865 - 1.0971624 - 1.1171737 - 1.1193675 - 1.1526119 - 1.1550265 - 1.1585277 - 1.1560166 - 1.1671172 - 1.1706294 - 1.1805791 - 1.1786896 - 1.1756876 - 1.1820789 - 1.171211 - 1.1637997 - 1.1636684 - 1.179719 - 1.1912538 - 1.2187959 - 1.2326986 - 1.2418602 - 1.2388704 - 1.2449963 - 1.2538678 - 1.2508929 - 1.2474781 - 1.255148 - 1.274482 - 1.2862757 - 1.2813665 - 1.2888943 - 1.2787436 - 1.2678886 - 1.274325 - 1.2720952 - 1.263492 - 1.2652139 - 1.2667561 - 1.264558 - 1.2680362 - 1.2660431 - 1.2909605 - 1.2927921 - 1.288932 - 1.2910852 - 1.3012725 - 1.3048721 - 1.3196515 - 1.3181903 - 1.321309 - 1.3431543 - 1.344136 - 1.3730377 - 1.3773695 - 1.3754742 - 1.3825964 - 1.3985574 - 1.3861412 - 1.3767823 - 1.3764309 - 1.3678747 - 1.3718554 - 1.3768022 - 1.3617199 - 1.3798267 - 1.3863533 - 1.3905803 - 1.4061004 - 1.4202788 - 1.4313191 - 1.4406155 - 1.4444837 - 1.4367244 - 1.4379653 - 1.4371881 - 1.4243012 - 1.41826 - 1.4133617 - 1.40181 - 1.3965683 - 1.3865729 - 1.3855433 - 1.3755111 - 1.3758609 - 1.3962625 - 1.3994012 - 1.4083656 - 1.4233002 - 1.4037932 - 1.3973604 - 1.4095657 - 1.4095764 - 1.4080055 - 1.4095882 - 1.4108374 - 1.4164143 - 1.4283402 - 1.4343939 - 1.4392909 - 1.4406097 - 1.4468355 - 1.4412132 - 1.4305562 - 1.4252445 - 1.4103094 - 1.4059847 - 1.4141106 - 1.4429769 - 1.4489679 - 1.4559263 - 1.4593079 - 1.4627911 - 1.453154 - 1.4416665 - 1.4101485 - 1.4175823 - 1.4266407 + 1 + 0.99948573 + 1.0068249 + 1.0141211 + 1.0073149 + 0.99884398 + 1.0237035 + 1.0349636 + 1.036819 + 1.0247366 + 1.0242391 + 1.0275737 + 1.0065684 + 0.99838346 + 0.97281734 + 0.95346302 + 0.9355791 + 0.9461152 + 0.94338882 + 0.92988921 + 0.9311862 + 0.93529467 + 0.93784681 + 0.91501401 + 0.92360522 + 0.91049302 + 0.90754698 + 0.91365103 + 0.91499228 + 0.92260749 + 0.92533824 + 0.90949431 + 0.91106924 + 0.90594116 + 0.90491334 + 0.9039891 + 0.91060772 + 0.92132842 + 0.91934854 + 0.92268418 + 0.92545127 + 0.91517169 + 0.90513459 + 0.90224212 + 0.87734878 + 0.88013667 + 0.86906494 + 0.84776403 + 0.83895869 + 0.81373437 + 0.78998314 + 0.77594176 + 0.77982695 + 0.77098321 + 0.76538611 + 0.76608075 + 0.77458654 + 0.78354767 + 0.81282389 + 0.83627649 + 0.82873051 + 0.83181309 + 0.83149903 + 0.83551261 + 0.83305985 + 0.84648418 + 0.86195421 + 0.88047436 + 0.90177533 + 0.93232215 + 0.94445051 + 0.9472487 + 0.94786015 + 0.95992178 + 0.95499149 + 0.95788581 + 0.9684288 + 0.97731917 + 0.98739379 + 1.0033879 + 1.0159673 + 1.0269931 + 1.0436661 + 1.0492034 + 1.0765292 + 1.0784865 + 1.0971624 + 1.1171737 + 1.1193675 + 1.1526119 + 1.1550265 + 1.1585277 + 1.1560166 + 1.1671172 + 1.1706294 + 1.1805791 + 1.1786896 + 1.1756876 + 1.1820789 + 1.171211 + 1.1637997 + 1.1636684 + 1.179719 + 1.1912538 + 1.2187959 + 1.2326986 + 1.2418602 + 1.2388704 + 1.2449963 + 1.2538678 + 1.2508929 + 1.2474781 + 1.255148 + 1.274482 + 1.2862757 + 1.2813665 + 1.2888943 + 1.2787436 + 1.2678886 + 1.274325 + 1.2720952 + 1.263492 + 1.2652139 + 1.2667561 + 1.264558 + 1.2680362 + 1.2660431 + 1.2909605 + 1.2927921 + 1.288932 + 1.2910852 + 1.3012725 + 1.3048721 + 1.3196515 + 1.3181903 + 1.321309 + 1.3431543 + 1.344136 + 1.3730377 + 1.3773695 + 1.3754742 + 1.3825964 + 1.3985574 + 1.3861412 + 1.3767823 + 1.3764309 + 1.3678747 + 1.3718554 + 1.3768022 + 1.3617199 + 1.3798267 + 1.3863533 + 1.3905803 + 1.4061004 + 1.4202788 + 1.4313191 + 1.4406155 + 1.4444837 + 1.4367244 + 1.4379653 + 1.4371881 + 1.4243012 + 1.41826 + 1.4133617 + 1.40181 + 1.3965683 + 1.3865729 + 1.3855433 + 1.3755111 + 1.3758609 + 1.3962625 + 1.3994012 + 1.4083656 + 1.4233002 + 1.4037932 + 1.3973604 + 1.4095657 + 1.4095764 + 1.4080055 + 1.4095882 + 1.4108374 + 1.4164143 + 1.4283402 + 1.4343939 + 1.4392909 + 1.4406097 + 1.4468355 + 1.4412132 + 1.4305562 + 1.4252445 + 1.4103094 + 1.4059847 + 1.4141106 + 1.4429769 + 1.4489679 + 1.4559263 + 1.4593079 + 1.4627911 + 1.453154 + 1.4416665 + 1.4101485 + 1.4175823 + 1.4266407 -]; + ]; diff --git a/tests/expectations/expectation_ss_old_steadystate.m b/tests/expectations/expectation_ss_old_steadystate.m index bfd46d82a7..1b230e4b02 100644 --- a/tests/expectations/expectation_ss_old_steadystate.m +++ b/tests/expectations/expectation_ss_old_steadystate.m @@ -1,12 +1,12 @@ function [ys_, check_] = expectation_ss_old_steadystate(ys_orig_, exo_) - ys_=zeros(6,1); - global M_ - ys_(4)=0; - ys_(6)=0; - ys_(5)=0.3333333333333333; - ys_(3)=((1/M_.params(1)-(1-M_.params(4)))/(M_.params(3)*ys_(5)^(1-M_.params(3))))^(1/(M_.params(3)-1)); - ys_(1)=ys_(5)^(1-M_.params(3))*ys_(3)^M_.params(3); - ys_(2)=ys_(1)-M_.params(4)*ys_(3); - M_.params(5)=(1-M_.params(3))*ys_(1)/(ys_(2)*ys_(5)^(1+M_.params(6))); - check_=0; +ys_=zeros(6,1); +global M_ +ys_(4)=0; +ys_(6)=0; +ys_(5)=0.3333333333333333; +ys_(3)=((1/M_.params(1)-(1-M_.params(4)))/(M_.params(3)*ys_(5)^(1-M_.params(3))))^(1/(M_.params(3)-1)); +ys_(1)=ys_(5)^(1-M_.params(3))*ys_(3)^M_.params(3); +ys_(2)=ys_(1)-M_.params(4)*ys_(3); +M_.params(5)=(1-M_.params(3))*ys_(1)/(ys_(2)*ys_(5)^(1+M_.params(6))); +check_=0; end diff --git a/tests/fataltest.m b/tests/fataltest.m index a23db43112..1ea213403a 100644 --- a/tests/fataltest.m +++ b/tests/fataltest.m @@ -1,4 +1,4 @@ -function test(a,b,n) - if max(max(abs(a)-abs(b))) > 1e-5 +function fataltest(a,b,n) +if max(max(abs(a)-abs(b))) > 1e-5 error(['Test error in test ' int2str(n)]) - end \ No newline at end of file +end \ No newline at end of file diff --git a/tests/fs2000/fsdat_simul.m b/tests/fs2000/fsdat_simul.m index d4f4a8066f..159612e577 100644 --- a/tests/fs2000/fsdat_simul.m +++ b/tests/fs2000/fsdat_simul.m @@ -1,828 +1,828 @@ gy_obs =[ - 1.0030045 - 0.99990934 - 1.0172778 - 0.99464043 - 1.0253423 - 1.0150215 - 0.97772557 - 0.97832186 - 1.0159561 - 1.0085937 - 1.0102649 - 1.0007604 - 1.0112596 - 1.0163279 - 1.0173204 - 1.0103896 - 1.0006493 - 0.99447124 - 1.0196405 - 1.0089304 - 0.99650737 - 1.0139707 - 0.97865842 - 1.0192225 - 0.99139628 - 1.0141362 - 1.0196612 - 0.97483476 - 0.99686151 - 0.99594464 - 1.0000642 - 1.0172243 - 1.0025773 - 0.97199728 - 1.0217815 - 1.0219949 - 0.99490252 - 1.0190728 - 1.0111337 - 1.0003792 - 0.98969164 - 1.010438 - 1.0216309 - 1.0016671 - 1.0357588 - 0.98803787 - 1.0093457 - 1.0177035 - 0.98548204 - 1.0274294 - 1.0141377 - 1.0091174 - 0.96427632 - 1.0083272 - 1.0007882 - 0.99038262 - 1.0031336 - 0.99500213 - 0.98203716 - 0.9889452 - 1.011632 - 0.99451949 - 0.97291047 - 0.98750871 - 0.99992418 - 0.97657318 - 0.99930448 - 1.0008515 - 1.0044064 - 0.98133792 - 1.0091702 - 1.0087023 - 1.0119876 - 1.0143019 - 1.0311061 - 0.99340471 - 1.0057428 - 0.99197259 - 1.0071019 - 0.99448853 - 1.0061819 - 1.0070088 - 0.9950913 - 1.0302318 - 0.9817693 - 1.0072885 - 0.97355282 - 0.98782586 - 1.0136674 - 0.99863956 - 1.0205668 - 0.99611384 - 1.0073805 - 0.99691529 - 1.0089194 - 1.0030467 - 1.0112006 - 1.0260523 - 0.97803331 - 0.99423374 - 1.0043727 - 1.0140173 - 1.0111473 - 0.99524348 - 0.99775943 - 0.9958619 - 0.9982344 - 1.0210212 - 1.0022288 - 1.0014801 - 1.011456 - 1.0124871 - 0.99843599 - 0.99324886 - 0.99912838 - 1.003327 - 1.0072071 - 1.0115223 - 1.009266 - 1.0070554 - 1.0129916 - 1.0053413 - 1.0051638 - 0.99212952 - 1.0214422 - 0.98716707 - 0.99905788 - 0.98877357 - 0.98568476 - 0.99767393 - 1.0061791 - 0.98423439 - 0.99492949 - 0.98786999 - 0.99754239 - 1.0168619 - 0.99472384 - 1.0041658 - 0.98123181 - 1.0112882 - 0.99245422 - 1.0010255 - 1.0017799 - 1.0089968 - 1.0072824 - 0.99768475 - 1.0044726 - 1.0118678 - 1.0056385 - 1.0276965 - 1.0025122 - 1.0065161 - 1.0234338 - 0.99760167 - 0.98922272 - 1.0101918 - 1.011615 - 1.0085286 - 1.0074455 - 0.98866757 - 0.99959012 - 1.0129881 - 0.99127881 - 0.97971901 - 1.0185314 - 1.020054 - 1.0132605 - 0.98063643 - 0.99490253 - 1.0101531 - 1.0004526 - 1.0059109 - 0.98974491 - 1.0062391 - 1.0216488 - 0.99398446 - 0.97786609 - 1.0019274 - 0.99587153 - 1.0095881 - 1.0111887 - 0.99457649 - 0.97896734 - 1.000172 - 1.0142951 - 1.0034224 - 1.0037242 - 1.0016059 - 1.016556 - 0.99687023 - 1.0117844 - 1.0059212 - 0.98083159 - 0.98638851 - 1.0128713 - 1.0096232 - 1.0115891 - 1.0011213 - 1.0147105 - 1.0066344 - 1.0164429 - 0.99825038 - 0.99403411 + 1.0030045 + 0.99990934 + 1.0172778 + 0.99464043 + 1.0253423 + 1.0150215 + 0.97772557 + 0.97832186 + 1.0159561 + 1.0085937 + 1.0102649 + 1.0007604 + 1.0112596 + 1.0163279 + 1.0173204 + 1.0103896 + 1.0006493 + 0.99447124 + 1.0196405 + 1.0089304 + 0.99650737 + 1.0139707 + 0.97865842 + 1.0192225 + 0.99139628 + 1.0141362 + 1.0196612 + 0.97483476 + 0.99686151 + 0.99594464 + 1.0000642 + 1.0172243 + 1.0025773 + 0.97199728 + 1.0217815 + 1.0219949 + 0.99490252 + 1.0190728 + 1.0111337 + 1.0003792 + 0.98969164 + 1.010438 + 1.0216309 + 1.0016671 + 1.0357588 + 0.98803787 + 1.0093457 + 1.0177035 + 0.98548204 + 1.0274294 + 1.0141377 + 1.0091174 + 0.96427632 + 1.0083272 + 1.0007882 + 0.99038262 + 1.0031336 + 0.99500213 + 0.98203716 + 0.9889452 + 1.011632 + 0.99451949 + 0.97291047 + 0.98750871 + 0.99992418 + 0.97657318 + 0.99930448 + 1.0008515 + 1.0044064 + 0.98133792 + 1.0091702 + 1.0087023 + 1.0119876 + 1.0143019 + 1.0311061 + 0.99340471 + 1.0057428 + 0.99197259 + 1.0071019 + 0.99448853 + 1.0061819 + 1.0070088 + 0.9950913 + 1.0302318 + 0.9817693 + 1.0072885 + 0.97355282 + 0.98782586 + 1.0136674 + 0.99863956 + 1.0205668 + 0.99611384 + 1.0073805 + 0.99691529 + 1.0089194 + 1.0030467 + 1.0112006 + 1.0260523 + 0.97803331 + 0.99423374 + 1.0043727 + 1.0140173 + 1.0111473 + 0.99524348 + 0.99775943 + 0.9958619 + 0.9982344 + 1.0210212 + 1.0022288 + 1.0014801 + 1.011456 + 1.0124871 + 0.99843599 + 0.99324886 + 0.99912838 + 1.003327 + 1.0072071 + 1.0115223 + 1.009266 + 1.0070554 + 1.0129916 + 1.0053413 + 1.0051638 + 0.99212952 + 1.0214422 + 0.98716707 + 0.99905788 + 0.98877357 + 0.98568476 + 0.99767393 + 1.0061791 + 0.98423439 + 0.99492949 + 0.98786999 + 0.99754239 + 1.0168619 + 0.99472384 + 1.0041658 + 0.98123181 + 1.0112882 + 0.99245422 + 1.0010255 + 1.0017799 + 1.0089968 + 1.0072824 + 0.99768475 + 1.0044726 + 1.0118678 + 1.0056385 + 1.0276965 + 1.0025122 + 1.0065161 + 1.0234338 + 0.99760167 + 0.98922272 + 1.0101918 + 1.011615 + 1.0085286 + 1.0074455 + 0.98866757 + 0.99959012 + 1.0129881 + 0.99127881 + 0.97971901 + 1.0185314 + 1.020054 + 1.0132605 + 0.98063643 + 0.99490253 + 1.0101531 + 1.0004526 + 1.0059109 + 0.98974491 + 1.0062391 + 1.0216488 + 0.99398446 + 0.97786609 + 1.0019274 + 0.99587153 + 1.0095881 + 1.0111887 + 0.99457649 + 0.97896734 + 1.000172 + 1.0142951 + 1.0034224 + 1.0037242 + 1.0016059 + 1.016556 + 0.99687023 + 1.0117844 + 1.0059212 + 0.98083159 + 0.98638851 + 1.0128713 + 1.0096232 + 1.0115891 + 1.0011213 + 1.0147105 + 1.0066344 + 1.0164429 + 0.99825038 + 0.99403411 -]; + ]; gp_obs =[ - 1.0079715 - 1.0074573 - 1.0153107 - 1.0152677 - 1.0011653 - 0.99950061 - 1.0328311 - 1.0192317 - 1.009827 - 0.99588916 - 1.007474 - 1.0113061 - 0.98696624 - 0.99978663 - 0.98240542 - 0.98861723 - 0.99008763 - 1.0185076 - 1.0052452 - 0.99447194 - 1.0092685 - 1.01208 - 1.0105237 - 0.98513875 - 1.0165628 - 0.99485934 - 1.0050255 - 1.0140756 - 1.0093128 - 1.0155868 - 1.0107023 - 0.99212762 - 1.0095465 - 1.0028435 - 1.0069437 - 1.0070473 - 1.0145902 - 1.0186922 - 1.0059917 - 1.0113072 - 1.0107386 - 0.99769196 - 0.99793444 - 1.0050791 - 0.98307821 - 1.0107594 - 0.99689982 - 0.98667064 - 0.9991662 - 0.98274722 - 0.98422032 - 0.99393016 - 1.0118567 - 0.99912781 - 1.0023744 - 1.0086662 - 1.0164773 - 1.0169327 - 1.0372478 - 1.0314242 - 1.0004256 - 1.0110541 - 1.0076575 - 1.0119851 - 1.0055188 - 1.0213959 - 1.0234416 - 1.0264917 - 1.0292725 - 1.0385184 - 1.0200999 - 1.0107697 - 1.008583 - 1.0200332 - 1.0030413 - 1.0108659 - 1.0185145 - 1.0168619 - 1.0180462 - 1.0239657 - 1.0205509 - 1.0189973 - 1.0246446 - 1.0135089 - 1.0352973 - 1.0099289 - 1.0266474 - 1.0279829 - 1.0101653 - 1.041216 - 1.0103861 - 1.0114727 - 1.0054605 - 1.0190722 - 1.0114837 - 1.0179213 - 1.006082 - 1.0049696 - 1.0143629 - 0.9971036 - 1.0005602 - 1.0078403 - 1.0240222 - 1.0195063 - 1.0355136 - 1.0218743 - 1.0171331 - 1.0049817 - 1.0140974 - 1.0168431 - 1.0049966 - 1.0045568 - 1.0156414 - 1.0273055 - 1.0197653 - 1.0030624 - 1.0154993 - 0.99782084 - 0.99711648 - 1.014408 - 1.0057417 - 0.99936837 - 1.0096934 - 1.0095138 - 1.0057734 - 1.0114497 - 1.0059784 - 1.0328889 - 1.0098032 - 1.0041114 - 1.0101247 - 1.0181588 - 1.0115712 - 1.0227509 - 1.0065104 - 1.0110902 - 1.0298169 - 1.0089532 - 1.0368733 - 1.0123033 - 1.0060763 - 1.0150937 - 1.0239325 - 0.99555536 - 0.99861271 - 1.0076201 - 0.99941535 - 1.0119522 - 1.0129183 - 0.99288924 - 1.0260784 - 1.0144982 - 1.0121985 - 1.0234916 - 1.02215 - 1.0190118 - 1.0172679 - 1.0118398 - 1.0002123 - 1.0092124 - 1.0071943 - 0.99508468 - 1.0019303 - 1.0030733 - 0.9964198 - 1.0027298 - 0.99797614 - 1.006942 - 0.99793928 - 1.0083214 - 1.0283732 - 1.0111102 - 1.016936 - 1.0229061 - 0.98846454 - 1.0015387 - 1.0201769 - 1.0079822 - 1.0064007 - 1.0095543 - 1.0092207 - 1.0135485 - 1.0198974 - 1.0140252 - 1.0128686 - 1.0092903 - 1.0141974 - 1.0023492 - 0.99731455 - 1.0026598 - 0.99303643 - 1.0036469 - 1.0160975 - 1.0368378 - 1.0139625 - 1.01493 - 1.0113531 - 1.0114548 - 0.99833441 - 0.99648401 - 0.97645361 - 1.0154053 - 1.01703 + 1.0079715 + 1.0074573 + 1.0153107 + 1.0152677 + 1.0011653 + 0.99950061 + 1.0328311 + 1.0192317 + 1.009827 + 0.99588916 + 1.007474 + 1.0113061 + 0.98696624 + 0.99978663 + 0.98240542 + 0.98861723 + 0.99008763 + 1.0185076 + 1.0052452 + 0.99447194 + 1.0092685 + 1.01208 + 1.0105237 + 0.98513875 + 1.0165628 + 0.99485934 + 1.0050255 + 1.0140756 + 1.0093128 + 1.0155868 + 1.0107023 + 0.99212762 + 1.0095465 + 1.0028435 + 1.0069437 + 1.0070473 + 1.0145902 + 1.0186922 + 1.0059917 + 1.0113072 + 1.0107386 + 0.99769196 + 0.99793444 + 1.0050791 + 0.98307821 + 1.0107594 + 0.99689982 + 0.98667064 + 0.9991662 + 0.98274722 + 0.98422032 + 0.99393016 + 1.0118567 + 0.99912781 + 1.0023744 + 1.0086662 + 1.0164773 + 1.0169327 + 1.0372478 + 1.0314242 + 1.0004256 + 1.0110541 + 1.0076575 + 1.0119851 + 1.0055188 + 1.0213959 + 1.0234416 + 1.0264917 + 1.0292725 + 1.0385184 + 1.0200999 + 1.0107697 + 1.008583 + 1.0200332 + 1.0030413 + 1.0108659 + 1.0185145 + 1.0168619 + 1.0180462 + 1.0239657 + 1.0205509 + 1.0189973 + 1.0246446 + 1.0135089 + 1.0352973 + 1.0099289 + 1.0266474 + 1.0279829 + 1.0101653 + 1.041216 + 1.0103861 + 1.0114727 + 1.0054605 + 1.0190722 + 1.0114837 + 1.0179213 + 1.006082 + 1.0049696 + 1.0143629 + 0.9971036 + 1.0005602 + 1.0078403 + 1.0240222 + 1.0195063 + 1.0355136 + 1.0218743 + 1.0171331 + 1.0049817 + 1.0140974 + 1.0168431 + 1.0049966 + 1.0045568 + 1.0156414 + 1.0273055 + 1.0197653 + 1.0030624 + 1.0154993 + 0.99782084 + 0.99711648 + 1.014408 + 1.0057417 + 0.99936837 + 1.0096934 + 1.0095138 + 1.0057734 + 1.0114497 + 1.0059784 + 1.0328889 + 1.0098032 + 1.0041114 + 1.0101247 + 1.0181588 + 1.0115712 + 1.0227509 + 1.0065104 + 1.0110902 + 1.0298169 + 1.0089532 + 1.0368733 + 1.0123033 + 1.0060763 + 1.0150937 + 1.0239325 + 0.99555536 + 0.99861271 + 1.0076201 + 0.99941535 + 1.0119522 + 1.0129183 + 0.99288924 + 1.0260784 + 1.0144982 + 1.0121985 + 1.0234916 + 1.02215 + 1.0190118 + 1.0172679 + 1.0118398 + 1.0002123 + 1.0092124 + 1.0071943 + 0.99508468 + 1.0019303 + 1.0030733 + 0.9964198 + 1.0027298 + 0.99797614 + 1.006942 + 0.99793928 + 1.0083214 + 1.0283732 + 1.0111102 + 1.016936 + 1.0229061 + 0.98846454 + 1.0015387 + 1.0201769 + 1.0079822 + 1.0064007 + 1.0095543 + 1.0092207 + 1.0135485 + 1.0198974 + 1.0140252 + 1.0128686 + 1.0092903 + 1.0141974 + 1.0023492 + 0.99731455 + 1.0026598 + 0.99303643 + 1.0036469 + 1.0160975 + 1.0368378 + 1.0139625 + 1.01493 + 1.0113531 + 1.0114548 + 0.99833441 + 0.99648401 + 0.97645361 + 1.0154053 + 1.01703 -]; + ]; Y_obs =[ - 1 - 0.99690484 - 1.0111781 - 1.0028141 - 1.0251518 - 1.0371688 - 1.0118899 - 0.98720726 - 1.0001589 - 1.0057481 - 1.0130085 - 1.0107643 - 1.0190194 - 1.0323428 - 1.0466587 - 1.0540438 - 1.0516886 - 1.0431553 - 1.0597913 - 1.0657172 - 1.0592201 - 1.0701863 - 1.0458402 - 1.0620582 - 1.0504499 - 1.0615817 - 1.0782384 - 1.0500687 - 1.0439257 - 1.0368658 - 1.0339255 - 1.0481453 - 1.0477181 - 1.0167109 - 1.0354878 - 1.0544782 - 1.0463762 - 1.0624445 - 1.0705737 - 1.0679484 - 1.0546356 - 1.0620691 - 1.0806955 - 1.0793581 - 1.1121124 - 1.0971458 - 1.1034869 - 1.1181859 - 1.1006634 - 1.1250883 - 1.1362214 - 1.1423343 - 1.1036061 - 1.1089288 - 1.1067125 - 1.0940906 - 1.0942197 - 1.0862174 - 1.06525 - 1.0511907 - 1.0598182 - 1.0513331 - 1.0212391 - 1.0057433 - 1.002663 - 0.97623167 - 0.97253165 - 0.97037865 - 0.97178055 - 0.95011397 - 0.95627969 - 0.96197747 - 0.97096053 - 0.98225794 - 1.0103595 - 1.0007597 - 1.003498 - 0.99246608 - 0.99656347 - 0.98804749 - 0.99122491 - 0.99522926 - 0.98731605 - 1.0145434 - 0.99330816 - 0.99759216 - 0.96814048 - 0.95296183 - 0.96362471 - 0.95925977 - 0.97682205 - 0.96993138 - 0.9743074 - 0.96821818 - 0.97413308 - 0.9741753 - 0.98237142 - 1.0054193 - 0.98044807 - 0.9716773 - 0.9730455 - 0.98405828 - 0.99220103 - 0.98444001 - 0.97919493 - 0.97205233 - 0.96728223 - 0.98529893 - 0.98452324 - 0.98299888 - 0.99145042 - 1.000933 - 0.99636447 - 0.98660883 - 0.98273271 - 0.98305518 - 0.98725774 - 0.99577549 - 1.002037 - 1.0060879 - 1.016075 - 1.0184118 - 1.0205711 - 1.0096961 - 1.0281337 - 1.0122963 - 1.0083497 - 0.99411874 - 0.976799 - 0.97146842 - 0.97464304 - 0.95587292 - 0.94779791 - 0.93266339 - 0.92720128 - 0.94105864 - 0.93277798 - 0.93393927 - 0.91216657 - 0.92045028 - 0.9099 - 0.90792098 - 0.90669634 - 0.91268867 - 0.91696661 - 0.91164685 - 0.91311495 - 0.92197825 - 0.92461222 - 0.94930422 - 0.9488119 - 0.95232353 - 0.97275278 - 0.96734995 - 0.95356817 - 0.96075548 - 0.96936594 - 0.97489002 - 0.97933106 - 0.96499412 - 0.96157973 - 0.97156334 - 0.95983765 - 0.93655215 - 0.95207909 - 0.96912862 - 0.97938462 - 0.95701655 - 0.94891457 - 0.95606317 - 0.95351125 - 0.95641767 - 0.94315807 - 0.94639265 - 0.96503697 - 0.95601693 - 0.93087851 - 0.92980141 - 0.92266844 - 0.92925206 - 0.93743628 - 0.92900826 - 0.9049711 - 0.90213859 - 0.91342916 - 0.91384707 - 0.91456681 - 0.91316822 - 0.92671976 - 0.92058549 - 0.92936541 - 0.93228212 - 0.91010921 - 0.89349322 - 0.90336005 - 0.90997873 - 0.91856328 - 0.91668007 - 0.92838606 - 0.932016 - 0.94545438 - 0.94070026 - 0.93172987 + 1 + 0.99690484 + 1.0111781 + 1.0028141 + 1.0251518 + 1.0371688 + 1.0118899 + 0.98720726 + 1.0001589 + 1.0057481 + 1.0130085 + 1.0107643 + 1.0190194 + 1.0323428 + 1.0466587 + 1.0540438 + 1.0516886 + 1.0431553 + 1.0597913 + 1.0657172 + 1.0592201 + 1.0701863 + 1.0458402 + 1.0620582 + 1.0504499 + 1.0615817 + 1.0782384 + 1.0500687 + 1.0439257 + 1.0368658 + 1.0339255 + 1.0481453 + 1.0477181 + 1.0167109 + 1.0354878 + 1.0544782 + 1.0463762 + 1.0624445 + 1.0705737 + 1.0679484 + 1.0546356 + 1.0620691 + 1.0806955 + 1.0793581 + 1.1121124 + 1.0971458 + 1.1034869 + 1.1181859 + 1.1006634 + 1.1250883 + 1.1362214 + 1.1423343 + 1.1036061 + 1.1089288 + 1.1067125 + 1.0940906 + 1.0942197 + 1.0862174 + 1.06525 + 1.0511907 + 1.0598182 + 1.0513331 + 1.0212391 + 1.0057433 + 1.002663 + 0.97623167 + 0.97253165 + 0.97037865 + 0.97178055 + 0.95011397 + 0.95627969 + 0.96197747 + 0.97096053 + 0.98225794 + 1.0103595 + 1.0007597 + 1.003498 + 0.99246608 + 0.99656347 + 0.98804749 + 0.99122491 + 0.99522926 + 0.98731605 + 1.0145434 + 0.99330816 + 0.99759216 + 0.96814048 + 0.95296183 + 0.96362471 + 0.95925977 + 0.97682205 + 0.96993138 + 0.9743074 + 0.96821818 + 0.97413308 + 0.9741753 + 0.98237142 + 1.0054193 + 0.98044807 + 0.9716773 + 0.9730455 + 0.98405828 + 0.99220103 + 0.98444001 + 0.97919493 + 0.97205233 + 0.96728223 + 0.98529893 + 0.98452324 + 0.98299888 + 0.99145042 + 1.000933 + 0.99636447 + 0.98660883 + 0.98273271 + 0.98305518 + 0.98725774 + 0.99577549 + 1.002037 + 1.0060879 + 1.016075 + 1.0184118 + 1.0205711 + 1.0096961 + 1.0281337 + 1.0122963 + 1.0083497 + 0.99411874 + 0.976799 + 0.97146842 + 0.97464304 + 0.95587292 + 0.94779791 + 0.93266339 + 0.92720128 + 0.94105864 + 0.93277798 + 0.93393927 + 0.91216657 + 0.92045028 + 0.9099 + 0.90792098 + 0.90669634 + 0.91268867 + 0.91696661 + 0.91164685 + 0.91311495 + 0.92197825 + 0.92461222 + 0.94930422 + 0.9488119 + 0.95232353 + 0.97275278 + 0.96734995 + 0.95356817 + 0.96075548 + 0.96936594 + 0.97489002 + 0.97933106 + 0.96499412 + 0.96157973 + 0.97156334 + 0.95983765 + 0.93655215 + 0.95207909 + 0.96912862 + 0.97938462 + 0.95701655 + 0.94891457 + 0.95606317 + 0.95351125 + 0.95641767 + 0.94315807 + 0.94639265 + 0.96503697 + 0.95601693 + 0.93087851 + 0.92980141 + 0.92266844 + 0.92925206 + 0.93743628 + 0.92900826 + 0.9049711 + 0.90213859 + 0.91342916 + 0.91384707 + 0.91456681 + 0.91316822 + 0.92671976 + 0.92058549 + 0.92936541 + 0.93228212 + 0.91010921 + 0.89349322 + 0.90336005 + 0.90997873 + 0.91856328 + 0.91668007 + 0.92838606 + 0.932016 + 0.94545438 + 0.94070026 + 0.93172987 -]; + ]; P_obs =[ - 1 - 0.99948573 - 1.0068249 - 1.0141211 - 1.0073149 - 0.99884398 - 1.0237035 - 1.0349636 - 1.036819 - 1.0247366 - 1.0242391 - 1.0275737 - 1.0065684 - 0.99838346 - 0.97281734 - 0.95346302 - 0.9355791 - 0.9461152 - 0.94338882 - 0.92988921 - 0.9311862 - 0.93529467 - 0.93784681 - 0.91501401 - 0.92360522 - 0.91049302 - 0.90754698 - 0.91365103 - 0.91499228 - 0.92260749 - 0.92533824 - 0.90949431 - 0.91106924 - 0.90594116 - 0.90491334 - 0.9039891 - 0.91060772 - 0.92132842 - 0.91934854 - 0.92268418 - 0.92545127 - 0.91517169 - 0.90513459 - 0.90224212 - 0.87734878 - 0.88013667 - 0.86906494 - 0.84776403 - 0.83895869 - 0.81373437 - 0.78998314 - 0.77594176 - 0.77982695 - 0.77098321 - 0.76538611 - 0.76608075 - 0.77458654 - 0.78354767 - 0.81282389 - 0.83627649 - 0.82873051 - 0.83181309 - 0.83149903 - 0.83551261 - 0.83305985 - 0.84648418 - 0.86195421 - 0.88047436 - 0.90177533 - 0.93232215 - 0.94445051 - 0.9472487 - 0.94786015 - 0.95992178 - 0.95499149 - 0.95788581 - 0.9684288 - 0.97731917 - 0.98739379 - 1.0033879 - 1.0159673 - 1.0269931 - 1.0436661 - 1.0492034 - 1.0765292 - 1.0784865 - 1.0971624 - 1.1171737 - 1.1193675 - 1.1526119 - 1.1550265 - 1.1585277 - 1.1560166 - 1.1671172 - 1.1706294 - 1.1805791 - 1.1786896 - 1.1756876 - 1.1820789 - 1.171211 - 1.1637997 - 1.1636684 - 1.179719 - 1.1912538 - 1.2187959 - 1.2326986 - 1.2418602 - 1.2388704 - 1.2449963 - 1.2538678 - 1.2508929 - 1.2474781 - 1.255148 - 1.274482 - 1.2862757 - 1.2813665 - 1.2888943 - 1.2787436 - 1.2678886 - 1.274325 - 1.2720952 - 1.263492 - 1.2652139 - 1.2667561 - 1.264558 - 1.2680362 - 1.2660431 - 1.2909605 - 1.2927921 - 1.288932 - 1.2910852 - 1.3012725 - 1.3048721 - 1.3196515 - 1.3181903 - 1.321309 - 1.3431543 - 1.344136 - 1.3730377 - 1.3773695 - 1.3754742 - 1.3825964 - 1.3985574 - 1.3861412 - 1.3767823 - 1.3764309 - 1.3678747 - 1.3718554 - 1.3768022 - 1.3617199 - 1.3798267 - 1.3863533 - 1.3905803 - 1.4061004 - 1.4202788 - 1.4313191 - 1.4406155 - 1.4444837 - 1.4367244 - 1.4379653 - 1.4371881 - 1.4243012 - 1.41826 - 1.4133617 - 1.40181 - 1.3965683 - 1.3865729 - 1.3855433 - 1.3755111 - 1.3758609 - 1.3962625 - 1.3994012 - 1.4083656 - 1.4233002 - 1.4037932 - 1.3973604 - 1.4095657 - 1.4095764 - 1.4080055 - 1.4095882 - 1.4108374 - 1.4164143 - 1.4283402 - 1.4343939 - 1.4392909 - 1.4406097 - 1.4468355 - 1.4412132 - 1.4305562 - 1.4252445 - 1.4103094 - 1.4059847 - 1.4141106 - 1.4429769 - 1.4489679 - 1.4559263 - 1.4593079 - 1.4627911 - 1.453154 - 1.4416665 - 1.4101485 - 1.4175823 - 1.4266407 + 1 + 0.99948573 + 1.0068249 + 1.0141211 + 1.0073149 + 0.99884398 + 1.0237035 + 1.0349636 + 1.036819 + 1.0247366 + 1.0242391 + 1.0275737 + 1.0065684 + 0.99838346 + 0.97281734 + 0.95346302 + 0.9355791 + 0.9461152 + 0.94338882 + 0.92988921 + 0.9311862 + 0.93529467 + 0.93784681 + 0.91501401 + 0.92360522 + 0.91049302 + 0.90754698 + 0.91365103 + 0.91499228 + 0.92260749 + 0.92533824 + 0.90949431 + 0.91106924 + 0.90594116 + 0.90491334 + 0.9039891 + 0.91060772 + 0.92132842 + 0.91934854 + 0.92268418 + 0.92545127 + 0.91517169 + 0.90513459 + 0.90224212 + 0.87734878 + 0.88013667 + 0.86906494 + 0.84776403 + 0.83895869 + 0.81373437 + 0.78998314 + 0.77594176 + 0.77982695 + 0.77098321 + 0.76538611 + 0.76608075 + 0.77458654 + 0.78354767 + 0.81282389 + 0.83627649 + 0.82873051 + 0.83181309 + 0.83149903 + 0.83551261 + 0.83305985 + 0.84648418 + 0.86195421 + 0.88047436 + 0.90177533 + 0.93232215 + 0.94445051 + 0.9472487 + 0.94786015 + 0.95992178 + 0.95499149 + 0.95788581 + 0.9684288 + 0.97731917 + 0.98739379 + 1.0033879 + 1.0159673 + 1.0269931 + 1.0436661 + 1.0492034 + 1.0765292 + 1.0784865 + 1.0971624 + 1.1171737 + 1.1193675 + 1.1526119 + 1.1550265 + 1.1585277 + 1.1560166 + 1.1671172 + 1.1706294 + 1.1805791 + 1.1786896 + 1.1756876 + 1.1820789 + 1.171211 + 1.1637997 + 1.1636684 + 1.179719 + 1.1912538 + 1.2187959 + 1.2326986 + 1.2418602 + 1.2388704 + 1.2449963 + 1.2538678 + 1.2508929 + 1.2474781 + 1.255148 + 1.274482 + 1.2862757 + 1.2813665 + 1.2888943 + 1.2787436 + 1.2678886 + 1.274325 + 1.2720952 + 1.263492 + 1.2652139 + 1.2667561 + 1.264558 + 1.2680362 + 1.2660431 + 1.2909605 + 1.2927921 + 1.288932 + 1.2910852 + 1.3012725 + 1.3048721 + 1.3196515 + 1.3181903 + 1.321309 + 1.3431543 + 1.344136 + 1.3730377 + 1.3773695 + 1.3754742 + 1.3825964 + 1.3985574 + 1.3861412 + 1.3767823 + 1.3764309 + 1.3678747 + 1.3718554 + 1.3768022 + 1.3617199 + 1.3798267 + 1.3863533 + 1.3905803 + 1.4061004 + 1.4202788 + 1.4313191 + 1.4406155 + 1.4444837 + 1.4367244 + 1.4379653 + 1.4371881 + 1.4243012 + 1.41826 + 1.4133617 + 1.40181 + 1.3965683 + 1.3865729 + 1.3855433 + 1.3755111 + 1.3758609 + 1.3962625 + 1.3994012 + 1.4083656 + 1.4233002 + 1.4037932 + 1.3973604 + 1.4095657 + 1.4095764 + 1.4080055 + 1.4095882 + 1.4108374 + 1.4164143 + 1.4283402 + 1.4343939 + 1.4392909 + 1.4406097 + 1.4468355 + 1.4412132 + 1.4305562 + 1.4252445 + 1.4103094 + 1.4059847 + 1.4141106 + 1.4429769 + 1.4489679 + 1.4559263 + 1.4593079 + 1.4627911 + 1.453154 + 1.4416665 + 1.4101485 + 1.4175823 + 1.4266407 -]; + ]; diff --git a/tests/fs2000/fsdat_simul_dseries.m b/tests/fs2000/fsdat_simul_dseries.m index 2dd9c2e2d6..5fa6d19a3b 100644 --- a/tests/fs2000/fsdat_simul_dseries.m +++ b/tests/fs2000/fsdat_simul_dseries.m @@ -7,822 +7,822 @@ NAMES__ = {'P_obs'; 'Y_obs'; 'gp_obs'; 'gy_obs'}; TEX__ = {'P\_obs'; 'Y\_obs'; 'gp\_obs'; 'gy\_obs'}; P_obs = [ - 1 - 0.99948573 - 1.0068249 - 1.0141211 - 1.0073149 - 0.99884398 - 1.0237035 - 1.0349636 - 1.036819 - 1.0247366 - 1.0242391 - 1.0275737 - 1.0065684 - 0.99838346 - 0.97281734 - 0.95346302 - 0.9355791 - 0.9461152 - 0.94338882 - 0.92988921 - 0.9311862 - 0.93529467 - 0.93784681 - 0.91501401 - 0.92360522 - 0.91049302 - 0.90754698 - 0.91365103 - 0.91499228 - 0.92260749 - 0.92533824 - 0.90949431 - 0.91106924 - 0.90594116 - 0.90491334 - 0.9039891 - 0.91060772 - 0.92132842 - 0.91934854 - 0.92268418 - 0.92545127 - 0.91517169 - 0.90513459 - 0.90224212 - 0.87734878 - 0.88013667 - 0.86906494 - 0.84776403 - 0.83895869 - 0.81373437 - 0.78998314 - 0.77594176 - 0.77982695 - 0.77098321 - 0.76538611 - 0.76608075 - 0.77458654 - 0.78354767 - 0.81282389 - 0.83627649 - 0.82873051 - 0.83181309 - 0.83149903 - 0.83551261 - 0.83305985 - 0.84648418 - 0.86195421 - 0.88047436 - 0.90177533 - 0.93232215 - 0.94445051 - 0.9472487 - 0.94786015 - 0.95992178 - 0.95499149 - 0.95788581 - 0.9684288 - 0.97731917 - 0.98739379 - 1.0033879 - 1.0159673 - 1.0269931 - 1.0436661 - 1.0492034 - 1.0765292 - 1.0784865 - 1.0971624 - 1.1171737 - 1.1193675 - 1.1526119 - 1.1550265 - 1.1585277 - 1.1560166 - 1.1671172 - 1.1706294 - 1.1805791 - 1.1786896 - 1.1756876 - 1.1820789 - 1.171211 - 1.1637997 - 1.1636684 - 1.179719 - 1.1912538 - 1.2187959 - 1.2326986 - 1.2418602 - 1.2388704 - 1.2449963 - 1.2538678 - 1.2508929 - 1.2474781 - 1.255148 - 1.274482 - 1.2862757 - 1.2813665 - 1.2888943 - 1.2787436 - 1.2678886 - 1.274325 - 1.2720952 - 1.263492 - 1.2652139 - 1.2667561 - 1.264558 - 1.2680362 - 1.2660431 - 1.2909605 - 1.2927921 - 1.288932 - 1.2910852 - 1.3012725 - 1.3048721 - 1.3196515 - 1.3181903 - 1.321309 - 1.3431543 - 1.344136 - 1.3730377 - 1.3773695 - 1.3754742 - 1.3825964 - 1.3985574 - 1.3861412 - 1.3767823 - 1.3764309 - 1.3678747 - 1.3718554 - 1.3768022 - 1.3617199 - 1.3798267 - 1.3863533 - 1.3905803 - 1.4061004 - 1.4202788 - 1.4313191 - 1.4406155 - 1.4444837 - 1.4367244 - 1.4379653 - 1.4371881 - 1.4243012 - 1.41826 - 1.4133617 - 1.40181 - 1.3965683 - 1.3865729 - 1.3855433 - 1.3755111 - 1.3758609 - 1.3962625 - 1.3994012 - 1.4083656 - 1.4233002 - 1.4037932 - 1.3973604 - 1.4095657 - 1.4095764 - 1.4080055 - 1.4095882 - 1.4108374 - 1.4164143 - 1.4283402 - 1.4343939 - 1.4392909 - 1.4406097 - 1.4468355 - 1.4412132 - 1.4305562 - 1.4252445 - 1.4103094 - 1.4059847 - 1.4141106 - 1.4429769 - 1.4489679 - 1.4559263 - 1.4593079 - 1.4627911 - 1.453154 - 1.4416665 - 1.4101485 - 1.4175823 - 1.4266407]; + 1 + 0.99948573 + 1.0068249 + 1.0141211 + 1.0073149 + 0.99884398 + 1.0237035 + 1.0349636 + 1.036819 + 1.0247366 + 1.0242391 + 1.0275737 + 1.0065684 + 0.99838346 + 0.97281734 + 0.95346302 + 0.9355791 + 0.9461152 + 0.94338882 + 0.92988921 + 0.9311862 + 0.93529467 + 0.93784681 + 0.91501401 + 0.92360522 + 0.91049302 + 0.90754698 + 0.91365103 + 0.91499228 + 0.92260749 + 0.92533824 + 0.90949431 + 0.91106924 + 0.90594116 + 0.90491334 + 0.9039891 + 0.91060772 + 0.92132842 + 0.91934854 + 0.92268418 + 0.92545127 + 0.91517169 + 0.90513459 + 0.90224212 + 0.87734878 + 0.88013667 + 0.86906494 + 0.84776403 + 0.83895869 + 0.81373437 + 0.78998314 + 0.77594176 + 0.77982695 + 0.77098321 + 0.76538611 + 0.76608075 + 0.77458654 + 0.78354767 + 0.81282389 + 0.83627649 + 0.82873051 + 0.83181309 + 0.83149903 + 0.83551261 + 0.83305985 + 0.84648418 + 0.86195421 + 0.88047436 + 0.90177533 + 0.93232215 + 0.94445051 + 0.9472487 + 0.94786015 + 0.95992178 + 0.95499149 + 0.95788581 + 0.9684288 + 0.97731917 + 0.98739379 + 1.0033879 + 1.0159673 + 1.0269931 + 1.0436661 + 1.0492034 + 1.0765292 + 1.0784865 + 1.0971624 + 1.1171737 + 1.1193675 + 1.1526119 + 1.1550265 + 1.1585277 + 1.1560166 + 1.1671172 + 1.1706294 + 1.1805791 + 1.1786896 + 1.1756876 + 1.1820789 + 1.171211 + 1.1637997 + 1.1636684 + 1.179719 + 1.1912538 + 1.2187959 + 1.2326986 + 1.2418602 + 1.2388704 + 1.2449963 + 1.2538678 + 1.2508929 + 1.2474781 + 1.255148 + 1.274482 + 1.2862757 + 1.2813665 + 1.2888943 + 1.2787436 + 1.2678886 + 1.274325 + 1.2720952 + 1.263492 + 1.2652139 + 1.2667561 + 1.264558 + 1.2680362 + 1.2660431 + 1.2909605 + 1.2927921 + 1.288932 + 1.2910852 + 1.3012725 + 1.3048721 + 1.3196515 + 1.3181903 + 1.321309 + 1.3431543 + 1.344136 + 1.3730377 + 1.3773695 + 1.3754742 + 1.3825964 + 1.3985574 + 1.3861412 + 1.3767823 + 1.3764309 + 1.3678747 + 1.3718554 + 1.3768022 + 1.3617199 + 1.3798267 + 1.3863533 + 1.3905803 + 1.4061004 + 1.4202788 + 1.4313191 + 1.4406155 + 1.4444837 + 1.4367244 + 1.4379653 + 1.4371881 + 1.4243012 + 1.41826 + 1.4133617 + 1.40181 + 1.3965683 + 1.3865729 + 1.3855433 + 1.3755111 + 1.3758609 + 1.3962625 + 1.3994012 + 1.4083656 + 1.4233002 + 1.4037932 + 1.3973604 + 1.4095657 + 1.4095764 + 1.4080055 + 1.4095882 + 1.4108374 + 1.4164143 + 1.4283402 + 1.4343939 + 1.4392909 + 1.4406097 + 1.4468355 + 1.4412132 + 1.4305562 + 1.4252445 + 1.4103094 + 1.4059847 + 1.4141106 + 1.4429769 + 1.4489679 + 1.4559263 + 1.4593079 + 1.4627911 + 1.453154 + 1.4416665 + 1.4101485 + 1.4175823 + 1.4266407]; Y_obs = [ - 1 - 0.99690484 - 1.0111781 - 1.0028141 - 1.0251518 - 1.0371688 - 1.0118899 - 0.98720726 - 1.0001589 - 1.0057481 - 1.0130085 - 1.0107643 - 1.0190194 - 1.0323428 - 1.0466587 - 1.0540438 - 1.0516886 - 1.0431553 - 1.0597913 - 1.0657172 - 1.0592201 - 1.0701863 - 1.0458402 - 1.0620582 - 1.0504499 - 1.0615817 - 1.0782384 - 1.0500687 - 1.0439257 - 1.0368658 - 1.0339255 - 1.0481453 - 1.0477181 - 1.0167109 - 1.0354878 - 1.0544782 - 1.0463762 - 1.0624445 - 1.0705737 - 1.0679484 - 1.0546356 - 1.0620691 - 1.0806955 - 1.0793581 - 1.1121124 - 1.0971458 - 1.1034869 - 1.1181859 - 1.1006634 - 1.1250883 - 1.1362214 - 1.1423343 - 1.1036061 - 1.1089288 - 1.1067125 - 1.0940906 - 1.0942197 - 1.0862174 - 1.06525 - 1.0511907 - 1.0598182 - 1.0513331 - 1.0212391 - 1.0057433 - 1.002663 - 0.97623167 - 0.97253165 - 0.97037865 - 0.97178055 - 0.95011397 - 0.95627969 - 0.96197747 - 0.97096053 - 0.98225794 - 1.0103595 - 1.0007597 - 1.003498 - 0.99246608 - 0.99656347 - 0.98804749 - 0.99122491 - 0.99522926 - 0.98731605 - 1.0145434 - 0.99330816 - 0.99759216 - 0.96814048 - 0.95296183 - 0.96362471 - 0.95925977 - 0.97682205 - 0.96993138 - 0.9743074 - 0.96821818 - 0.97413308 - 0.9741753 - 0.98237142 - 1.0054193 - 0.98044807 - 0.9716773 - 0.9730455 - 0.98405828 - 0.99220103 - 0.98444001 - 0.97919493 - 0.97205233 - 0.96728223 - 0.98529893 - 0.98452324 - 0.98299888 - 0.99145042 - 1.000933 - 0.99636447 - 0.98660883 - 0.98273271 - 0.98305518 - 0.98725774 - 0.99577549 - 1.002037 - 1.0060879 - 1.016075 - 1.0184118 - 1.0205711 - 1.0096961 - 1.0281337 - 1.0122963 - 1.0083497 - 0.99411874 - 0.976799 - 0.97146842 - 0.97464304 - 0.95587292 - 0.94779791 - 0.93266339 - 0.92720128 - 0.94105864 - 0.93277798 - 0.93393927 - 0.91216657 - 0.92045028 - 0.9099 - 0.90792098 - 0.90669634 - 0.91268867 - 0.91696661 - 0.91164685 - 0.91311495 - 0.92197825 - 0.92461222 - 0.94930422 - 0.9488119 - 0.95232353 - 0.97275278 - 0.96734995 - 0.95356817 - 0.96075548 - 0.96936594 - 0.97489002 - 0.97933106 - 0.96499412 - 0.96157973 - 0.97156334 - 0.95983765 - 0.93655215 - 0.95207909 - 0.96912862 - 0.97938462 - 0.95701655 - 0.94891457 - 0.95606317 - 0.95351125 - 0.95641767 - 0.94315807 - 0.94639265 - 0.96503697 - 0.95601693 - 0.93087851 - 0.92980141 - 0.92266844 - 0.92925206 - 0.93743628 - 0.92900826 - 0.9049711 - 0.90213859 - 0.91342916 - 0.91384707 - 0.91456681 - 0.91316822 - 0.92671976 - 0.92058549 - 0.92936541 - 0.93228212 - 0.91010921 - 0.89349322 - 0.90336005 - 0.90997873 - 0.91856328 - 0.91668007 - 0.92838606 - 0.932016 - 0.94545438 - 0.94070026 - 0.93172987]; + 1 + 0.99690484 + 1.0111781 + 1.0028141 + 1.0251518 + 1.0371688 + 1.0118899 + 0.98720726 + 1.0001589 + 1.0057481 + 1.0130085 + 1.0107643 + 1.0190194 + 1.0323428 + 1.0466587 + 1.0540438 + 1.0516886 + 1.0431553 + 1.0597913 + 1.0657172 + 1.0592201 + 1.0701863 + 1.0458402 + 1.0620582 + 1.0504499 + 1.0615817 + 1.0782384 + 1.0500687 + 1.0439257 + 1.0368658 + 1.0339255 + 1.0481453 + 1.0477181 + 1.0167109 + 1.0354878 + 1.0544782 + 1.0463762 + 1.0624445 + 1.0705737 + 1.0679484 + 1.0546356 + 1.0620691 + 1.0806955 + 1.0793581 + 1.1121124 + 1.0971458 + 1.1034869 + 1.1181859 + 1.1006634 + 1.1250883 + 1.1362214 + 1.1423343 + 1.1036061 + 1.1089288 + 1.1067125 + 1.0940906 + 1.0942197 + 1.0862174 + 1.06525 + 1.0511907 + 1.0598182 + 1.0513331 + 1.0212391 + 1.0057433 + 1.002663 + 0.97623167 + 0.97253165 + 0.97037865 + 0.97178055 + 0.95011397 + 0.95627969 + 0.96197747 + 0.97096053 + 0.98225794 + 1.0103595 + 1.0007597 + 1.003498 + 0.99246608 + 0.99656347 + 0.98804749 + 0.99122491 + 0.99522926 + 0.98731605 + 1.0145434 + 0.99330816 + 0.99759216 + 0.96814048 + 0.95296183 + 0.96362471 + 0.95925977 + 0.97682205 + 0.96993138 + 0.9743074 + 0.96821818 + 0.97413308 + 0.9741753 + 0.98237142 + 1.0054193 + 0.98044807 + 0.9716773 + 0.9730455 + 0.98405828 + 0.99220103 + 0.98444001 + 0.97919493 + 0.97205233 + 0.96728223 + 0.98529893 + 0.98452324 + 0.98299888 + 0.99145042 + 1.000933 + 0.99636447 + 0.98660883 + 0.98273271 + 0.98305518 + 0.98725774 + 0.99577549 + 1.002037 + 1.0060879 + 1.016075 + 1.0184118 + 1.0205711 + 1.0096961 + 1.0281337 + 1.0122963 + 1.0083497 + 0.99411874 + 0.976799 + 0.97146842 + 0.97464304 + 0.95587292 + 0.94779791 + 0.93266339 + 0.92720128 + 0.94105864 + 0.93277798 + 0.93393927 + 0.91216657 + 0.92045028 + 0.9099 + 0.90792098 + 0.90669634 + 0.91268867 + 0.91696661 + 0.91164685 + 0.91311495 + 0.92197825 + 0.92461222 + 0.94930422 + 0.9488119 + 0.95232353 + 0.97275278 + 0.96734995 + 0.95356817 + 0.96075548 + 0.96936594 + 0.97489002 + 0.97933106 + 0.96499412 + 0.96157973 + 0.97156334 + 0.95983765 + 0.93655215 + 0.95207909 + 0.96912862 + 0.97938462 + 0.95701655 + 0.94891457 + 0.95606317 + 0.95351125 + 0.95641767 + 0.94315807 + 0.94639265 + 0.96503697 + 0.95601693 + 0.93087851 + 0.92980141 + 0.92266844 + 0.92925206 + 0.93743628 + 0.92900826 + 0.9049711 + 0.90213859 + 0.91342916 + 0.91384707 + 0.91456681 + 0.91316822 + 0.92671976 + 0.92058549 + 0.92936541 + 0.93228212 + 0.91010921 + 0.89349322 + 0.90336005 + 0.90997873 + 0.91856328 + 0.91668007 + 0.92838606 + 0.932016 + 0.94545438 + 0.94070026 + 0.93172987]; gp_obs = [ - 1.0079715 - 1.0074573 - 1.0153107 - 1.0152677 - 1.0011653 - 0.99950061 - 1.0328311 - 1.0192317 - 1.009827 - 0.99588916 - 1.007474 - 1.0113061 - 0.98696624 - 0.99978663 - 0.98240542 - 0.98861723 - 0.99008763 - 1.0185076 - 1.0052452 - 0.99447194 - 1.0092685 - 1.01208 - 1.0105237 - 0.98513875 - 1.0165628 - 0.99485934 - 1.0050255 - 1.0140756 - 1.0093128 - 1.0155868 - 1.0107023 - 0.99212762 - 1.0095465 - 1.0028435 - 1.0069437 - 1.0070473 - 1.0145902 - 1.0186922 - 1.0059917 - 1.0113072 - 1.0107386 - 0.99769196 - 0.99793444 - 1.0050791 - 0.98307821 - 1.0107594 - 0.99689982 - 0.98667064 - 0.9991662 - 0.98274722 - 0.98422032 - 0.99393016 - 1.0118567 - 0.99912781 - 1.0023744 - 1.0086662 - 1.0164773 - 1.0169327 - 1.0372478 - 1.0314242 - 1.0004256 - 1.0110541 - 1.0076575 - 1.0119851 - 1.0055188 - 1.0213959 - 1.0234416 - 1.0264917 - 1.0292725 - 1.0385184 - 1.0200999 - 1.0107697 - 1.008583 - 1.0200332 - 1.0030413 - 1.0108659 - 1.0185145 - 1.0168619 - 1.0180462 - 1.0239657 - 1.0205509 - 1.0189973 - 1.0246446 - 1.0135089 - 1.0352973 - 1.0099289 - 1.0266474 - 1.0279829 - 1.0101653 - 1.041216 - 1.0103861 - 1.0114727 - 1.0054605 - 1.0190722 - 1.0114837 - 1.0179213 - 1.006082 - 1.0049696 - 1.0143629 - 0.9971036 - 1.0005602 - 1.0078403 - 1.0240222 - 1.0195063 - 1.0355136 - 1.0218743 - 1.0171331 - 1.0049817 - 1.0140974 - 1.0168431 - 1.0049966 - 1.0045568 - 1.0156414 - 1.0273055 - 1.0197653 - 1.0030624 - 1.0154993 - 0.99782084 - 0.99711648 - 1.014408 - 1.0057417 - 0.99936837 - 1.0096934 - 1.0095138 - 1.0057734 - 1.0114497 - 1.0059784 - 1.0328889 - 1.0098032 - 1.0041114 - 1.0101247 - 1.0181588 - 1.0115712 - 1.0227509 - 1.0065104 - 1.0110902 - 1.0298169 - 1.0089532 - 1.0368733 - 1.0123033 - 1.0060763 - 1.0150937 - 1.0239325 - 0.99555536 - 0.99861271 - 1.0076201 - 0.99941535 - 1.0119522 - 1.0129183 - 0.99288924 - 1.0260784 - 1.0144982 - 1.0121985 - 1.0234916 - 1.02215 - 1.0190118 - 1.0172679 - 1.0118398 - 1.0002123 - 1.0092124 - 1.0071943 - 0.99508468 - 1.0019303 - 1.0030733 - 0.9964198 - 1.0027298 - 0.99797614 - 1.006942 - 0.99793928 - 1.0083214 - 1.0283732 - 1.0111102 - 1.016936 - 1.0229061 - 0.98846454 - 1.0015387 - 1.0201769 - 1.0079822 - 1.0064007 - 1.0095543 - 1.0092207 - 1.0135485 - 1.0198974 - 1.0140252 - 1.0128686 - 1.0092903 - 1.0141974 - 1.0023492 - 0.99731455 - 1.0026598 - 0.99303643 - 1.0036469 - 1.0160975 - 1.0368378 - 1.0139625 - 1.01493 - 1.0113531 - 1.0114548 - 0.99833441 - 0.99648401 - 0.97645361 - 1.0154053 - 1.01703]; + 1.0079715 + 1.0074573 + 1.0153107 + 1.0152677 + 1.0011653 + 0.99950061 + 1.0328311 + 1.0192317 + 1.009827 + 0.99588916 + 1.007474 + 1.0113061 + 0.98696624 + 0.99978663 + 0.98240542 + 0.98861723 + 0.99008763 + 1.0185076 + 1.0052452 + 0.99447194 + 1.0092685 + 1.01208 + 1.0105237 + 0.98513875 + 1.0165628 + 0.99485934 + 1.0050255 + 1.0140756 + 1.0093128 + 1.0155868 + 1.0107023 + 0.99212762 + 1.0095465 + 1.0028435 + 1.0069437 + 1.0070473 + 1.0145902 + 1.0186922 + 1.0059917 + 1.0113072 + 1.0107386 + 0.99769196 + 0.99793444 + 1.0050791 + 0.98307821 + 1.0107594 + 0.99689982 + 0.98667064 + 0.9991662 + 0.98274722 + 0.98422032 + 0.99393016 + 1.0118567 + 0.99912781 + 1.0023744 + 1.0086662 + 1.0164773 + 1.0169327 + 1.0372478 + 1.0314242 + 1.0004256 + 1.0110541 + 1.0076575 + 1.0119851 + 1.0055188 + 1.0213959 + 1.0234416 + 1.0264917 + 1.0292725 + 1.0385184 + 1.0200999 + 1.0107697 + 1.008583 + 1.0200332 + 1.0030413 + 1.0108659 + 1.0185145 + 1.0168619 + 1.0180462 + 1.0239657 + 1.0205509 + 1.0189973 + 1.0246446 + 1.0135089 + 1.0352973 + 1.0099289 + 1.0266474 + 1.0279829 + 1.0101653 + 1.041216 + 1.0103861 + 1.0114727 + 1.0054605 + 1.0190722 + 1.0114837 + 1.0179213 + 1.006082 + 1.0049696 + 1.0143629 + 0.9971036 + 1.0005602 + 1.0078403 + 1.0240222 + 1.0195063 + 1.0355136 + 1.0218743 + 1.0171331 + 1.0049817 + 1.0140974 + 1.0168431 + 1.0049966 + 1.0045568 + 1.0156414 + 1.0273055 + 1.0197653 + 1.0030624 + 1.0154993 + 0.99782084 + 0.99711648 + 1.014408 + 1.0057417 + 0.99936837 + 1.0096934 + 1.0095138 + 1.0057734 + 1.0114497 + 1.0059784 + 1.0328889 + 1.0098032 + 1.0041114 + 1.0101247 + 1.0181588 + 1.0115712 + 1.0227509 + 1.0065104 + 1.0110902 + 1.0298169 + 1.0089532 + 1.0368733 + 1.0123033 + 1.0060763 + 1.0150937 + 1.0239325 + 0.99555536 + 0.99861271 + 1.0076201 + 0.99941535 + 1.0119522 + 1.0129183 + 0.99288924 + 1.0260784 + 1.0144982 + 1.0121985 + 1.0234916 + 1.02215 + 1.0190118 + 1.0172679 + 1.0118398 + 1.0002123 + 1.0092124 + 1.0071943 + 0.99508468 + 1.0019303 + 1.0030733 + 0.9964198 + 1.0027298 + 0.99797614 + 1.006942 + 0.99793928 + 1.0083214 + 1.0283732 + 1.0111102 + 1.016936 + 1.0229061 + 0.98846454 + 1.0015387 + 1.0201769 + 1.0079822 + 1.0064007 + 1.0095543 + 1.0092207 + 1.0135485 + 1.0198974 + 1.0140252 + 1.0128686 + 1.0092903 + 1.0141974 + 1.0023492 + 0.99731455 + 1.0026598 + 0.99303643 + 1.0036469 + 1.0160975 + 1.0368378 + 1.0139625 + 1.01493 + 1.0113531 + 1.0114548 + 0.99833441 + 0.99648401 + 0.97645361 + 1.0154053 + 1.01703]; gy_obs = [ - 1.0030045 - 0.99990934 - 1.0172778 - 0.99464043 - 1.0253423 - 1.0150215 - 0.97772557 - 0.97832186 - 1.0159561 - 1.0085937 - 1.0102649 - 1.0007604 - 1.0112596 - 1.0163279 - 1.0173204 - 1.0103896 - 1.0006493 - 0.99447124 - 1.0196405 - 1.0089304 - 0.99650737 - 1.0139707 - 0.97865842 - 1.0192225 - 0.99139628 - 1.0141362 - 1.0196612 - 0.97483476 - 0.99686151 - 0.99594464 - 1.0000642 - 1.0172243 - 1.0025773 - 0.97199728 - 1.0217815 - 1.0219949 - 0.99490252 - 1.0190728 - 1.0111337 - 1.0003792 - 0.98969164 - 1.010438 - 1.0216309 - 1.0016671 - 1.0357588 - 0.98803787 - 1.0093457 - 1.0177035 - 0.98548204 - 1.0274294 - 1.0141377 - 1.0091174 - 0.96427632 - 1.0083272 - 1.0007882 - 0.99038262 - 1.0031336 - 0.99500213 - 0.98203716 - 0.9889452 - 1.011632 - 0.99451949 - 0.97291047 - 0.98750871 - 0.99992418 - 0.97657318 - 0.99930448 - 1.0008515 - 1.0044064 - 0.98133792 - 1.0091702 - 1.0087023 - 1.0119876 - 1.0143019 - 1.0311061 - 0.99340471 - 1.0057428 - 0.99197259 - 1.0071019 - 0.99448853 - 1.0061819 - 1.0070088 - 0.9950913 - 1.0302318 - 0.9817693 - 1.0072885 - 0.97355282 - 0.98782586 - 1.0136674 - 0.99863956 - 1.0205668 - 0.99611384 - 1.0073805 - 0.99691529 - 1.0089194 - 1.0030467 - 1.0112006 - 1.0260523 - 0.97803331 - 0.99423374 - 1.0043727 - 1.0140173 - 1.0111473 - 0.99524348 - 0.99775943 - 0.9958619 - 0.9982344 - 1.0210212 - 1.0022288 - 1.0014801 - 1.011456 - 1.0124871 - 0.99843599 - 0.99324886 - 0.99912838 - 1.003327 - 1.0072071 - 1.0115223 - 1.009266 - 1.0070554 - 1.0129916 - 1.0053413 - 1.0051638 - 0.99212952 - 1.0214422 - 0.98716707 - 0.99905788 - 0.98877357 - 0.98568476 - 0.99767393 - 1.0061791 - 0.98423439 - 0.99492949 - 0.98786999 - 0.99754239 - 1.0168619 - 0.99472384 - 1.0041658 - 0.98123181 - 1.0112882 - 0.99245422 - 1.0010255 - 1.0017799 - 1.0089968 - 1.0072824 - 0.99768475 - 1.0044726 - 1.0118678 - 1.0056385 - 1.0276965 - 1.0025122 - 1.0065161 - 1.0234338 - 0.99760167 - 0.98922272 - 1.0101918 - 1.011615 - 1.0085286 - 1.0074455 - 0.98866757 - 0.99959012 - 1.0129881 - 0.99127881 - 0.97971901 - 1.0185314 - 1.020054 - 1.0132605 - 0.98063643 - 0.99490253 - 1.0101531 - 1.0004526 - 1.0059109 - 0.98974491 - 1.0062391 - 1.0216488 - 0.99398446 - 0.97786609 - 1.0019274 - 0.99587153 - 1.0095881 - 1.0111887 - 0.99457649 - 0.97896734 - 1.000172 - 1.0142951 - 1.0034224 - 1.0037242 - 1.0016059 - 1.016556 - 0.99687023 - 1.0117844 - 1.0059212 - 0.98083159 - 0.98638851 - 1.0128713 - 1.0096232 - 1.0115891 - 1.0011213 - 1.0147105 - 1.0066344 - 1.0164429 - 0.99825038 - 0.99403411]; + 1.0030045 + 0.99990934 + 1.0172778 + 0.99464043 + 1.0253423 + 1.0150215 + 0.97772557 + 0.97832186 + 1.0159561 + 1.0085937 + 1.0102649 + 1.0007604 + 1.0112596 + 1.0163279 + 1.0173204 + 1.0103896 + 1.0006493 + 0.99447124 + 1.0196405 + 1.0089304 + 0.99650737 + 1.0139707 + 0.97865842 + 1.0192225 + 0.99139628 + 1.0141362 + 1.0196612 + 0.97483476 + 0.99686151 + 0.99594464 + 1.0000642 + 1.0172243 + 1.0025773 + 0.97199728 + 1.0217815 + 1.0219949 + 0.99490252 + 1.0190728 + 1.0111337 + 1.0003792 + 0.98969164 + 1.010438 + 1.0216309 + 1.0016671 + 1.0357588 + 0.98803787 + 1.0093457 + 1.0177035 + 0.98548204 + 1.0274294 + 1.0141377 + 1.0091174 + 0.96427632 + 1.0083272 + 1.0007882 + 0.99038262 + 1.0031336 + 0.99500213 + 0.98203716 + 0.9889452 + 1.011632 + 0.99451949 + 0.97291047 + 0.98750871 + 0.99992418 + 0.97657318 + 0.99930448 + 1.0008515 + 1.0044064 + 0.98133792 + 1.0091702 + 1.0087023 + 1.0119876 + 1.0143019 + 1.0311061 + 0.99340471 + 1.0057428 + 0.99197259 + 1.0071019 + 0.99448853 + 1.0061819 + 1.0070088 + 0.9950913 + 1.0302318 + 0.9817693 + 1.0072885 + 0.97355282 + 0.98782586 + 1.0136674 + 0.99863956 + 1.0205668 + 0.99611384 + 1.0073805 + 0.99691529 + 1.0089194 + 1.0030467 + 1.0112006 + 1.0260523 + 0.97803331 + 0.99423374 + 1.0043727 + 1.0140173 + 1.0111473 + 0.99524348 + 0.99775943 + 0.9958619 + 0.9982344 + 1.0210212 + 1.0022288 + 1.0014801 + 1.011456 + 1.0124871 + 0.99843599 + 0.99324886 + 0.99912838 + 1.003327 + 1.0072071 + 1.0115223 + 1.009266 + 1.0070554 + 1.0129916 + 1.0053413 + 1.0051638 + 0.99212952 + 1.0214422 + 0.98716707 + 0.99905788 + 0.98877357 + 0.98568476 + 0.99767393 + 1.0061791 + 0.98423439 + 0.99492949 + 0.98786999 + 0.99754239 + 1.0168619 + 0.99472384 + 1.0041658 + 0.98123181 + 1.0112882 + 0.99245422 + 1.0010255 + 1.0017799 + 1.0089968 + 1.0072824 + 0.99768475 + 1.0044726 + 1.0118678 + 1.0056385 + 1.0276965 + 1.0025122 + 1.0065161 + 1.0234338 + 0.99760167 + 0.98922272 + 1.0101918 + 1.011615 + 1.0085286 + 1.0074455 + 0.98866757 + 0.99959012 + 1.0129881 + 0.99127881 + 0.97971901 + 1.0185314 + 1.020054 + 1.0132605 + 0.98063643 + 0.99490253 + 1.0101531 + 1.0004526 + 1.0059109 + 0.98974491 + 1.0062391 + 1.0216488 + 0.99398446 + 0.97786609 + 1.0019274 + 0.99587153 + 1.0095881 + 1.0111887 + 0.99457649 + 0.97896734 + 1.000172 + 1.0142951 + 1.0034224 + 1.0037242 + 1.0016059 + 1.016556 + 0.99687023 + 1.0117844 + 1.0059212 + 0.98083159 + 0.98638851 + 1.0128713 + 1.0096232 + 1.0115891 + 1.0011213 + 1.0147105 + 1.0066344 + 1.0164429 + 0.99825038 + 0.99403411]; diff --git a/tests/fs2000/fsdat_simul_missing_obs.m b/tests/fs2000/fsdat_simul_missing_obs.m index fe9dc57794..cc5674e625 100644 --- a/tests/fs2000/fsdat_simul_missing_obs.m +++ b/tests/fs2000/fsdat_simul_missing_obs.m @@ -1,416 +1,416 @@ % Generated data, used by fs2000.mod gy_obs =[ - NaN - 1.0002599 - 0.99104664 - 1.0321162 - 1.0223545 - 1.0043614 - 0.98626929 - 1.0092127 - 1.0357197 - 1.0150827 - 1.0051548 - 0.98465775 - 0.99132132 - 0.99904153 - 1.0044641 - 1.0179198 - 1.0113462 - 0.99409421 - 0.99904293 - 1.0448336 - 0.99932433 - 1.0057004 - 0.99619787 - 1.0267504 - 1.0077645 - 1.0058026 - 1.0025891 - 0.9939097 - 0.99604693 - 0.99908569 - 1.0151094 - 0.99348134 - 1.0039124 - 1.0145805 - 0.99800868 - 0.98578138 - 1.0065771 - 0.99843919 - 0.97979062 - 0.98413351 - 0.96468174 - 1.0273857 - 1.0225211 - 0.99958667 - 1.0111157 - 1.0099585 - 0.99480311 - 1.0079265 - 0.98924573 - 1.0070613 - 1.0075706 - 0.9937151 - 1.0224711 - 1.0018891 - 0.99051863 - 1.0042944 - 1.0184055 - 0.99419508 - 0.99756624 - 1.0015983 - 0.9845772 - 1.0004407 - 1.0116237 - 0.9861885 - 1.0073094 - 0.99273355 - 1.0013224 - 0.99777979 - 1.0301686 - 0.96809556 - 0.99917088 - 0.99949253 - 0.96590004 - 1.0083938 - 0.96662298 - 1.0221454 - 1.0069792 - 1.0343996 - 1.0066531 - 1.0072525 - 0.99743563 - 0.99723703 - 1.000372 - 0.99013917 - 1.0095223 - 0.98864268 - 0.98092242 - 0.98886488 - 1.0030341 - 1.01894 - 0.99155059 - 0.99533235 - 0.99734316 - 1.0047356 - 1.0082737 - 0.98425116 - 0.99949212 - 1.0055899 - 1.0065075 - 0.99385069 - 0.98867975 - 0.99804843 - 1.0184038 - 0.99301902 - 1.0177222 - 1.0051924 - 1.0187852 - 1.0098985 - 1.0097172 - 1.0145811 - 0.98721038 - 1.0361722 - 1.0105821 - 0.99469309 - 0.98626785 - 1.013871 - 0.99858924 - 0.99302637 - 1.0042186 - 0.99623745 - 0.98545708 - 1.0225435 - 1.0011861 - 1.0130321 - 0.97861347 - 1.0228193 - 0.99627435 - 1.0272779 - 1.0075172 - 1.0096762 - 1.0129306 - 0.99966549 - 1.0262882 - 1.0026914 - 1.0061475 - 1.009523 - 1.0036127 - 0.99762992 - 0.99092634 - 1.0058469 - 0.99887292 - 1.0060653 - 0.98673557 - 0.98895709 - 0.99111967 - 0.990118 - 0.99788054 - 0.97054709 - 1.0099157 - 1.0107431 - 0.99518695 - 1.0114048 - 0.99376019 - 1.0023369 - 0.98783327 - 1.0051727 - 1.0100462 - 0.98607387 - 1.0000064 - 0.99692442 - 1.012225 - 0.99574078 - 0.98642833 - 0.99008207 - 1.0197359 - 1.0112849 - 0.98711069 - 0.99402748 - 1.0242141 - 1.0135349 - 0.99842505 - 1.0130714 - 0.99887044 - 1.0059058 - 1.0185998 - 1.0073314 - 0.98687706 - 1.0084551 - 0.97698964 - 0.99482714 - 1.0015302 - 1.0105331 - 1.0261767 - 1.0232822 - 1.0084176 - 0.99785167 - 0.99619733 - 1.0055223 - 1.0076326 - 0.99205461 - 1.0030587 - 1.0137012 - 1.0145878 - 1.0190297 - 1.0000681 - 1.0153894 - 1.0140649 - 1.0007236 - 0.97961463 - 1.0125257 - 1.0169503 - NaN - 1.0221185 + NaN + 1.0002599 + 0.99104664 + 1.0321162 + 1.0223545 + 1.0043614 + 0.98626929 + 1.0092127 + 1.0357197 + 1.0150827 + 1.0051548 + 0.98465775 + 0.99132132 + 0.99904153 + 1.0044641 + 1.0179198 + 1.0113462 + 0.99409421 + 0.99904293 + 1.0448336 + 0.99932433 + 1.0057004 + 0.99619787 + 1.0267504 + 1.0077645 + 1.0058026 + 1.0025891 + 0.9939097 + 0.99604693 + 0.99908569 + 1.0151094 + 0.99348134 + 1.0039124 + 1.0145805 + 0.99800868 + 0.98578138 + 1.0065771 + 0.99843919 + 0.97979062 + 0.98413351 + 0.96468174 + 1.0273857 + 1.0225211 + 0.99958667 + 1.0111157 + 1.0099585 + 0.99480311 + 1.0079265 + 0.98924573 + 1.0070613 + 1.0075706 + 0.9937151 + 1.0224711 + 1.0018891 + 0.99051863 + 1.0042944 + 1.0184055 + 0.99419508 + 0.99756624 + 1.0015983 + 0.9845772 + 1.0004407 + 1.0116237 + 0.9861885 + 1.0073094 + 0.99273355 + 1.0013224 + 0.99777979 + 1.0301686 + 0.96809556 + 0.99917088 + 0.99949253 + 0.96590004 + 1.0083938 + 0.96662298 + 1.0221454 + 1.0069792 + 1.0343996 + 1.0066531 + 1.0072525 + 0.99743563 + 0.99723703 + 1.000372 + 0.99013917 + 1.0095223 + 0.98864268 + 0.98092242 + 0.98886488 + 1.0030341 + 1.01894 + 0.99155059 + 0.99533235 + 0.99734316 + 1.0047356 + 1.0082737 + 0.98425116 + 0.99949212 + 1.0055899 + 1.0065075 + 0.99385069 + 0.98867975 + 0.99804843 + 1.0184038 + 0.99301902 + 1.0177222 + 1.0051924 + 1.0187852 + 1.0098985 + 1.0097172 + 1.0145811 + 0.98721038 + 1.0361722 + 1.0105821 + 0.99469309 + 0.98626785 + 1.013871 + 0.99858924 + 0.99302637 + 1.0042186 + 0.99623745 + 0.98545708 + 1.0225435 + 1.0011861 + 1.0130321 + 0.97861347 + 1.0228193 + 0.99627435 + 1.0272779 + 1.0075172 + 1.0096762 + 1.0129306 + 0.99966549 + 1.0262882 + 1.0026914 + 1.0061475 + 1.009523 + 1.0036127 + 0.99762992 + 0.99092634 + 1.0058469 + 0.99887292 + 1.0060653 + 0.98673557 + 0.98895709 + 0.99111967 + 0.990118 + 0.99788054 + 0.97054709 + 1.0099157 + 1.0107431 + 0.99518695 + 1.0114048 + 0.99376019 + 1.0023369 + 0.98783327 + 1.0051727 + 1.0100462 + 0.98607387 + 1.0000064 + 0.99692442 + 1.012225 + 0.99574078 + 0.98642833 + 0.99008207 + 1.0197359 + 1.0112849 + 0.98711069 + 0.99402748 + 1.0242141 + 1.0135349 + 0.99842505 + 1.0130714 + 0.99887044 + 1.0059058 + 1.0185998 + 1.0073314 + 0.98687706 + 1.0084551 + 0.97698964 + 0.99482714 + 1.0015302 + 1.0105331 + 1.0261767 + 1.0232822 + 1.0084176 + 0.99785167 + 0.99619733 + 1.0055223 + 1.0076326 + 0.99205461 + 1.0030587 + 1.0137012 + 1.0145878 + 1.0190297 + 1.0000681 + 1.0153894 + 1.0140649 + 1.0007236 + 0.97961463 + 1.0125257 + 1.0169503 + NaN + 1.0221185 -]; + ]; gp_obs =[ - 1.0079715 - 1.0115853 - 1.0167502 - 1.0068957 - 1.0138189 - 1.0258364 - 1.0243817 - 1.017373 - 1.0020171 - 1.0003742 - 1.0008974 - 1.0104804 - 1.0116393 - 1.0114294 - 0.99932124 - 0.99461459 - 1.0170349 - 1.0051446 - 1.020639 - 1.0051964 - 1.0093042 - 1.007068 - 1.01086 - NaN - 1.0014883 - 1.0117332 - 0.9990095 - 1.0108284 - 1.0103672 - 1.0036722 - 1.0005124 - 1.0190331 - 1.0130978 - 1.007842 - 1.0285436 - 1.0322054 - 1.0213403 - 1.0246486 - 1.0419306 - 1.0258867 - 1.0156316 - 0.99818589 - 0.9894107 - 1.0127584 - 1.0146882 - 1.0136529 - 1.0340107 - 1.0343652 - 1.02971 - 1.0077932 - 1.0198114 - 1.013971 - 1.0061083 - 1.0089573 - 1.0037926 - 1.0082071 - 0.99498155 - 0.99735772 - 0.98765026 - 1.006465 - 1.0196088 - 1.0053233 - 1.0119974 - 1.0188066 - 1.0029302 - 1.0183459 - 1.0034218 - 1.0158799 - 0.98824798 - 1.0274357 - 1.0168832 - 1.0180641 - 1.0294657 - 0.98864091 - 1.0358326 - 0.99889969 - 1.0178322 - 0.99813566 - 1.0073549 - 1.0215985 - 1.0084245 - 1.0080939 - 1.0157021 - 1.0075815 - 1.0032633 - 1.0117871 - 1.0209276 - 1.0077569 - 0.99680958 - 1.0120266 - 1.0017625 - 1.0138811 - 1.0198358 - 1.0059629 - 1.0115416 - 1.0319473 - 1.0167074 - 1.0116111 - 1.0048627 - 1.0217622 - 1.0125221 - 1.0142045 - 0.99792469 - 0.99823971 - 0.99561547 - 0.99850373 - 0.9898464 - 1.0030963 - 1.0051373 - 1.0004213 - 1.0144117 - 0.97185592 - 0.9959518 - 1.0073529 - 1.0051603 - 0.98642572 - 0.99433423 - 1.0112131 - 1.0007695 - 1.0176867 - 1.0134363 - 0.99926191 - 0.99879835 - 0.99878754 - 1.0331374 - 1.0077797 - 1.0127221 - 1.0047393 - 1.0074106 - 0.99784213 - 1.0056495 - 1.0057708 - 0.98817494 - 0.98742176 - 0.99930555 - 1.0000687 - 1.0129754 - 1.009529 - 1.0226731 - 1.0149534 - 1.0164295 - 1.0239469 - 1.0293458 - 1.026199 - 1.0197525 - 1.0126818 - 1.0054473 - 1.0254423 - 1.0069461 - 1.0153135 - 1.0337515 - 1.0178187 - 1.0240469 - 1.0079489 - 1.0186953 - 1.0008628 - 1.0113799 - 1.0140118 - 1.0168007 - 1.011441 - 0.98422774 - 0.98909729 - 1.0157859 - 1.0151586 - 0.99756232 - 0.99497777 - 1.0102841 - 1.0221659 - 0.9937759 - 0.99877193 - 1.0079433 - 0.99667692 - 1.0095959 - 1.0128804 - 1.0156949 - 1.0111951 - 1.0228887 - 1.0122083 - 1.0190197 - 1.0074927 - 1.0268096 - 0.99689352 - 0.98948474 - 1.0024938 - 1.0105543 - 1.014116 - 1.0141217 - 1.0056504 - 1.0101026 - 1.0105069 - 0.99619053 - 1.0059439 - 0.99449473 - 0.99482458 - 1.0037702 - 1.0068087 - 0.99575975 - 1.0030815 - 1.0334014 - 0.99879386 - 0.99625634 - NaN - 0.99233844 + 1.0079715 + 1.0115853 + 1.0167502 + 1.0068957 + 1.0138189 + 1.0258364 + 1.0243817 + 1.017373 + 1.0020171 + 1.0003742 + 1.0008974 + 1.0104804 + 1.0116393 + 1.0114294 + 0.99932124 + 0.99461459 + 1.0170349 + 1.0051446 + 1.020639 + 1.0051964 + 1.0093042 + 1.007068 + 1.01086 + NaN + 1.0014883 + 1.0117332 + 0.9990095 + 1.0108284 + 1.0103672 + 1.0036722 + 1.0005124 + 1.0190331 + 1.0130978 + 1.007842 + 1.0285436 + 1.0322054 + 1.0213403 + 1.0246486 + 1.0419306 + 1.0258867 + 1.0156316 + 0.99818589 + 0.9894107 + 1.0127584 + 1.0146882 + 1.0136529 + 1.0340107 + 1.0343652 + 1.02971 + 1.0077932 + 1.0198114 + 1.013971 + 1.0061083 + 1.0089573 + 1.0037926 + 1.0082071 + 0.99498155 + 0.99735772 + 0.98765026 + 1.006465 + 1.0196088 + 1.0053233 + 1.0119974 + 1.0188066 + 1.0029302 + 1.0183459 + 1.0034218 + 1.0158799 + 0.98824798 + 1.0274357 + 1.0168832 + 1.0180641 + 1.0294657 + 0.98864091 + 1.0358326 + 0.99889969 + 1.0178322 + 0.99813566 + 1.0073549 + 1.0215985 + 1.0084245 + 1.0080939 + 1.0157021 + 1.0075815 + 1.0032633 + 1.0117871 + 1.0209276 + 1.0077569 + 0.99680958 + 1.0120266 + 1.0017625 + 1.0138811 + 1.0198358 + 1.0059629 + 1.0115416 + 1.0319473 + 1.0167074 + 1.0116111 + 1.0048627 + 1.0217622 + 1.0125221 + 1.0142045 + 0.99792469 + 0.99823971 + 0.99561547 + 0.99850373 + 0.9898464 + 1.0030963 + 1.0051373 + 1.0004213 + 1.0144117 + 0.97185592 + 0.9959518 + 1.0073529 + 1.0051603 + 0.98642572 + 0.99433423 + 1.0112131 + 1.0007695 + 1.0176867 + 1.0134363 + 0.99926191 + 0.99879835 + 0.99878754 + 1.0331374 + 1.0077797 + 1.0127221 + 1.0047393 + 1.0074106 + 0.99784213 + 1.0056495 + 1.0057708 + 0.98817494 + 0.98742176 + 0.99930555 + 1.0000687 + 1.0129754 + 1.009529 + 1.0226731 + 1.0149534 + 1.0164295 + 1.0239469 + 1.0293458 + 1.026199 + 1.0197525 + 1.0126818 + 1.0054473 + 1.0254423 + 1.0069461 + 1.0153135 + 1.0337515 + 1.0178187 + 1.0240469 + 1.0079489 + 1.0186953 + 1.0008628 + 1.0113799 + 1.0140118 + 1.0168007 + 1.011441 + 0.98422774 + 0.98909729 + 1.0157859 + 1.0151586 + 0.99756232 + 0.99497777 + 1.0102841 + 1.0221659 + 0.9937759 + 0.99877193 + 1.0079433 + 0.99667692 + 1.0095959 + 1.0128804 + 1.0156949 + 1.0111951 + 1.0228887 + 1.0122083 + 1.0190197 + 1.0074927 + 1.0268096 + 0.99689352 + 0.98948474 + 1.0024938 + 1.0105543 + 1.014116 + 1.0141217 + 1.0056504 + 1.0101026 + 1.0105069 + 0.99619053 + 1.0059439 + 0.99449473 + 0.99482458 + 1.0037702 + 1.0068087 + 0.99575975 + 1.0030815 + 1.0334014 + 0.99879386 + 0.99625634 + NaN + 0.99233844 -]; + ]; diff --git a/tests/fs2000_ssfile_aux.m b/tests/fs2000_ssfile_aux.m index c16bfc96da..50a40bcfba 100644 --- a/tests/fs2000_ssfile_aux.m +++ b/tests/fs2000_ssfile_aux.m @@ -1,4 +1,4 @@ function [W, e] = fs2000_ssfile_aux(l, n) - W = l/n; - e = 1; +W = l/n; +e = 1; end diff --git a/tests/gsa/data_ca1.m b/tests/gsa/data_ca1.m index c28fae1a28..ca003056bd 100644 --- a/tests/gsa/data_ca1.m +++ b/tests/gsa/data_ca1.m @@ -1,98 +1,98 @@ data = [0.928467646476 11.8716889412 20 0.418037507392 0.227382377518 ... --0.705994063083 11.7522582094 21.25 1.09254424511 -1.29488274994 ... --0.511895351926 9.68144025625 17.25 -1.66150408407 0.331508393098 ... --0.990955971267 10.0890781236 17 1.43016275252 -2.43589670141 ... --0.981233061806 12.1094840679 18.25 2.91293288733 -0.790246576864 ... --0.882182844512 8.54559460406 15 0.419579139481 0.358729719566 ... --0.930893002836 6.19238374422 12.5 -1.48847457959 0.739779938797 ... -1.53158206947 2.76544271886 11.5 -0.336216769682 0.455559918769 ... -2.2659052834 5.47418162513 11 0.306436789767 -0.0707985731221 ... -1.05419803797 6.35698426189 11 0.140700250477 0.620401487202 ... -1.20161076793 3.4253301593 11 0.461296492351 0.14354323987 ... -1.73934077971 4.70926070322 11.5 1.35798282982 0.38564694435 ... -1.71735262584 3.54232079749 12.5 2.9097529155 -0.804308583301 ... -0.426343657844 3.32719108897 13 1.64214862652 -1.18214664701 ... -1.67751812324 2.93444727338 11.25 0.344434910651 -1.6529373719 ... -1.37013301099 4.72303361923 11.75 2.61511526582 0.327684243041 ... -0.281231073781 4.4893853071 10.5 1.17043449257 1.12855106649 ... -1.53638992834 3.7325309699 10.25 -0.683947046728 0.11943538737 ... -1.68081431462 3.34729969129 10 1.41159342106 -1.59065680853 ... --0.343321601133 5.05563513564 12 1.75117366498 -2.40127764642 ... -0.873415608666 3.2779996255 10.25 -1.39895866711 0.0971444398216 ... -0.26399696544 4.78229419828 9.75 0.0914692438124 0.299310457612 ... --0.562233624818 3.88598638237 9.75 -0.0505384765105 0.332826708151 ... -2.15161914936 3.84859710132 8.75 -3.44811080489 0.789138678784 ... -1.2345093726 5.62225030942 9.5 -0.366945407434 2.32974981198 ... -1.62554967459 4.24667132831 10 -0.800958371402 0.0293183770935 ... -1.33035402527 2.75248979249 9.75 -0.855723113225 0.852493939813 ... -1.52078814077 3.53415985826 9.75 -3.37963469203 -1.05133958119 ... -1.16704983697 4.92754079464 10.75 -3.0142303324 0.459907431978 ... -0.277213572101 4.55532133037 11.75 -0.851995599415 2.03242034852 ... -0.842215068977 3.11164509647 12.25 -1.08290421696 0.014323281961 ... -1.05325028606 4.92882647578 13.5 -1.1953883867 0.706764750654 ... -0.453051253568 6.82998950103 13.5 0.111803656462 0.088462593153 ... -0.199885995525 5.82643354662 13.5 -0.920501518421 -0.26504958666 ... -0.137907999624 2.66076369132 13.5 -1.17122929812 -0.995642430514 ... -0.721949686709 5.70497876823 14.25 1.19378169018 -1.10644839651 ... --0.418465249225 3.75861110232 14.75 -1.03131674824 0.188507675831 ... --0.644028342116 4.15104788154 13.75 -1.48911756546 0.204560913792 ... --0.848213852668 5.65580324027 12.75 0.677011703877 -0.849628054542 ... --1.51954076928 11.4866911266 11.25 -0.446024680774 -0.456342350765 ... -0.265275055215 2.85472749592 9.75 -0.598778202436 -0.907311640831 ... -0.356162529063 2.29614015658 9.5 -0.46820788432 -1.22130883441 ... -0.368308864363 -0.539083504685 8 -0.781333991956 0.374007246518 ... --0.145751412732 1.61507621789 8.25 3.68291932628 1.32438399845 ... -0.285457283664 2.14334055993 7 1.42819405379 -0.00818660844123 ... -0.372390129412 1.60000213334 6.25 0.626106424052 -0.10136772765 ... -0.382720203063 1.72614243263 7.25 4.89631941021 -1.10060711916 ... -0.737957515573 2.90430582851 6 -0.0422721010314 0.4178952497 ... -0.649532581668 0.657135682543 6 0.692066153971 0.422299120276 ... -0.627159201987 1.70352689913 5.75 2.62066711305 -1.29237304034 ... -0.905441299817 1.95663197267 5.5 1.5949697565 -0.27115830703 ... -1.49322577898 -2.08741765309 6.25 1.23027694802 0.418336889527 ... -1.48750731567 -1.57274121871 8 3.01660550994 -0.893958254365 ... -1.39783858087 2.22623066426 7 -0.80842319214 1.47625453886 ... -0.89274836317 1.30378081742 8 -0.249485058661 0.159871204185 ... -0.920652246088 4.1437741965 9.75 2.8204453623 0.178149239655 ... --0.00264276644799 3.07989972052 8.75 -2.56342461535 2.105998353 ... -0.0198190461681 0.766283759256 8 -1.15838865989 1.56888883418 ... -0.440050515311 0.127570085801 7.5 0.0400753569995 0.028914333532 ... -0.129536637901 1.78174141526 6.75 0.959943962785 0.307781224401 ... -0.398549827172 3.03606770667 6.5 -0.340209794742 0.100979469478 ... -1.17174775425 0.629625188037 5.75 0.403003686814 0.902394579377 ... -0.991163981251 2.50862910684 4.75 -1.44963996982 1.16150986945 ... -0.967603566096 2.12003739013 4.75 0.610846030775 -0.889994896068 ... -1.14689383604 1.24185011459 4.75 2.01098091308 -1.73846431001 ... -1.32593824054 0.990713820685 4.75 -0.0955142989332 -0.0369257308362 ... -0.861135002644 -0.24744943605 6 1.72793107135 -0.691506789639 ... -1.26870850151 2.09844764887 6.5 1.50720217572 -1.31399187077 ... -0.260364987715 1.10650139716 6.5 1.13659047496 0.0720441664643 ... -1.09731242214 0.490796381346 7.25 4.59123894147 -2.14073070763 ... -1.63792841781 0.612652594286 6.75 1.79604605035 -0.644363995357 ... -1.48465576034 0.978295808687 6.75 -2.00753620902 1.39437534964 ... -1.0987608663 4.25212569087 6.25 -2.58901196498 2.56054320803 ... -1.42592178132 2.76984518311 6.25 0.888195752358 1.03114549274 ... -1.52958239462 1.31795955491 6.5 -0.902907564082 -0.0952198893776 ... -1.0170168994 2.14733589918 7 -1.3054866978 2.68803738466 ... -0.723253652257 3.43552889347 7.5 1.8213700853 0.592593586195 ... -1.24720806008 3.87383806577 7.5 0.0522300654168 0.988871238698 ... -0.482531471239 2.67793287032 7.5 2.9693944293 -0.108591166081 ... -0.154056100439 0.927269031704 6.75 0.119222057561 3.30489209451 ... -0.0694865769274 6.65916526788 6.25 0.889014476084 -2.83976849035 ... --0.121267434867 0.341442615696 5.25 0.323053239216 -3.49289229012 ... -0.726473690375 -3.5423730964 4 2.19149290449 -3.20855054004 ... -1.39271709108 2.63121085718 3.75 0.88406577736 0.75622580197 ... -1.07502077727 5.88578836799 4.25 -2.55088273352 2.89018116374 ... -0.759049251607 4.24703604223 4.5 0.575687665685 -0.388292506167 ... -]; - + -0.705994063083 11.7522582094 21.25 1.09254424511 -1.29488274994 ... + -0.511895351926 9.68144025625 17.25 -1.66150408407 0.331508393098 ... + -0.990955971267 10.0890781236 17 1.43016275252 -2.43589670141 ... + -0.981233061806 12.1094840679 18.25 2.91293288733 -0.790246576864 ... + -0.882182844512 8.54559460406 15 0.419579139481 0.358729719566 ... + -0.930893002836 6.19238374422 12.5 -1.48847457959 0.739779938797 ... + 1.53158206947 2.76544271886 11.5 -0.336216769682 0.455559918769 ... + 2.2659052834 5.47418162513 11 0.306436789767 -0.0707985731221 ... + 1.05419803797 6.35698426189 11 0.140700250477 0.620401487202 ... + 1.20161076793 3.4253301593 11 0.461296492351 0.14354323987 ... + 1.73934077971 4.70926070322 11.5 1.35798282982 0.38564694435 ... + 1.71735262584 3.54232079749 12.5 2.9097529155 -0.804308583301 ... + 0.426343657844 3.32719108897 13 1.64214862652 -1.18214664701 ... + 1.67751812324 2.93444727338 11.25 0.344434910651 -1.6529373719 ... + 1.37013301099 4.72303361923 11.75 2.61511526582 0.327684243041 ... + 0.281231073781 4.4893853071 10.5 1.17043449257 1.12855106649 ... + 1.53638992834 3.7325309699 10.25 -0.683947046728 0.11943538737 ... + 1.68081431462 3.34729969129 10 1.41159342106 -1.59065680853 ... + -0.343321601133 5.05563513564 12 1.75117366498 -2.40127764642 ... + 0.873415608666 3.2779996255 10.25 -1.39895866711 0.0971444398216 ... + 0.26399696544 4.78229419828 9.75 0.0914692438124 0.299310457612 ... + -0.562233624818 3.88598638237 9.75 -0.0505384765105 0.332826708151 ... + 2.15161914936 3.84859710132 8.75 -3.44811080489 0.789138678784 ... + 1.2345093726 5.62225030942 9.5 -0.366945407434 2.32974981198 ... + 1.62554967459 4.24667132831 10 -0.800958371402 0.0293183770935 ... + 1.33035402527 2.75248979249 9.75 -0.855723113225 0.852493939813 ... + 1.52078814077 3.53415985826 9.75 -3.37963469203 -1.05133958119 ... + 1.16704983697 4.92754079464 10.75 -3.0142303324 0.459907431978 ... + 0.277213572101 4.55532133037 11.75 -0.851995599415 2.03242034852 ... + 0.842215068977 3.11164509647 12.25 -1.08290421696 0.014323281961 ... + 1.05325028606 4.92882647578 13.5 -1.1953883867 0.706764750654 ... + 0.453051253568 6.82998950103 13.5 0.111803656462 0.088462593153 ... + 0.199885995525 5.82643354662 13.5 -0.920501518421 -0.26504958666 ... + 0.137907999624 2.66076369132 13.5 -1.17122929812 -0.995642430514 ... + 0.721949686709 5.70497876823 14.25 1.19378169018 -1.10644839651 ... + -0.418465249225 3.75861110232 14.75 -1.03131674824 0.188507675831 ... + -0.644028342116 4.15104788154 13.75 -1.48911756546 0.204560913792 ... + -0.848213852668 5.65580324027 12.75 0.677011703877 -0.849628054542 ... + -1.51954076928 11.4866911266 11.25 -0.446024680774 -0.456342350765 ... + 0.265275055215 2.85472749592 9.75 -0.598778202436 -0.907311640831 ... + 0.356162529063 2.29614015658 9.5 -0.46820788432 -1.22130883441 ... + 0.368308864363 -0.539083504685 8 -0.781333991956 0.374007246518 ... + -0.145751412732 1.61507621789 8.25 3.68291932628 1.32438399845 ... + 0.285457283664 2.14334055993 7 1.42819405379 -0.00818660844123 ... + 0.372390129412 1.60000213334 6.25 0.626106424052 -0.10136772765 ... + 0.382720203063 1.72614243263 7.25 4.89631941021 -1.10060711916 ... + 0.737957515573 2.90430582851 6 -0.0422721010314 0.4178952497 ... + 0.649532581668 0.657135682543 6 0.692066153971 0.422299120276 ... + 0.627159201987 1.70352689913 5.75 2.62066711305 -1.29237304034 ... + 0.905441299817 1.95663197267 5.5 1.5949697565 -0.27115830703 ... + 1.49322577898 -2.08741765309 6.25 1.23027694802 0.418336889527 ... + 1.48750731567 -1.57274121871 8 3.01660550994 -0.893958254365 ... + 1.39783858087 2.22623066426 7 -0.80842319214 1.47625453886 ... + 0.89274836317 1.30378081742 8 -0.249485058661 0.159871204185 ... + 0.920652246088 4.1437741965 9.75 2.8204453623 0.178149239655 ... + -0.00264276644799 3.07989972052 8.75 -2.56342461535 2.105998353 ... + 0.0198190461681 0.766283759256 8 -1.15838865989 1.56888883418 ... + 0.440050515311 0.127570085801 7.5 0.0400753569995 0.028914333532 ... + 0.129536637901 1.78174141526 6.75 0.959943962785 0.307781224401 ... + 0.398549827172 3.03606770667 6.5 -0.340209794742 0.100979469478 ... + 1.17174775425 0.629625188037 5.75 0.403003686814 0.902394579377 ... + 0.991163981251 2.50862910684 4.75 -1.44963996982 1.16150986945 ... + 0.967603566096 2.12003739013 4.75 0.610846030775 -0.889994896068 ... + 1.14689383604 1.24185011459 4.75 2.01098091308 -1.73846431001 ... + 1.32593824054 0.990713820685 4.75 -0.0955142989332 -0.0369257308362 ... + 0.861135002644 -0.24744943605 6 1.72793107135 -0.691506789639 ... + 1.26870850151 2.09844764887 6.5 1.50720217572 -1.31399187077 ... + 0.260364987715 1.10650139716 6.5 1.13659047496 0.0720441664643 ... + 1.09731242214 0.490796381346 7.25 4.59123894147 -2.14073070763 ... + 1.63792841781 0.612652594286 6.75 1.79604605035 -0.644363995357 ... + 1.48465576034 0.978295808687 6.75 -2.00753620902 1.39437534964 ... + 1.0987608663 4.25212569087 6.25 -2.58901196498 2.56054320803 ... + 1.42592178132 2.76984518311 6.25 0.888195752358 1.03114549274 ... + 1.52958239462 1.31795955491 6.5 -0.902907564082 -0.0952198893776 ... + 1.0170168994 2.14733589918 7 -1.3054866978 2.68803738466 ... + 0.723253652257 3.43552889347 7.5 1.8213700853 0.592593586195 ... + 1.24720806008 3.87383806577 7.5 0.0522300654168 0.988871238698 ... + 0.482531471239 2.67793287032 7.5 2.9693944293 -0.108591166081 ... + 0.154056100439 0.927269031704 6.75 0.119222057561 3.30489209451 ... + 0.0694865769274 6.65916526788 6.25 0.889014476084 -2.83976849035 ... + -0.121267434867 0.341442615696 5.25 0.323053239216 -3.49289229012 ... + 0.726473690375 -3.5423730964 4 2.19149290449 -3.20855054004 ... + 1.39271709108 2.63121085718 3.75 0.88406577736 0.75622580197 ... + 1.07502077727 5.88578836799 4.25 -2.55088273352 2.89018116374 ... + 0.759049251607 4.24703604223 4.5 0.575687665685 -0.388292506167 ... + ]; + data = reshape(data,5,86)'; y_obs = data(:,1); pie_obs = data(:,2); R_obs = data(:,3); de = data(:,4); dq = data(:,5); - + %Country: Canada %Sample Range: 1981:2 to 2002:3 %Observations: 86 diff --git a/tests/identification/as2007/as2007_steadystate.m b/tests/identification/as2007/as2007_steadystate.m index 473207a0ba..0f070859de 100644 --- a/tests/identification/as2007/as2007_steadystate.m +++ b/tests/identification/as2007/as2007_steadystate.m @@ -3,11 +3,11 @@ function [ys,check1]=as2007_steadystate(ys,exo) global M_ for j=1:size(M_.param_names,1) - eval([deblank(M_.param_names(j,:)),' = M_.params(j);']) - assignin('base',deblank(M_.param_names(j,:)),M_.params(j)); + eval([deblank(M_.param_names(j,:)),' = M_.params(j);']) + assignin('base',deblank(M_.param_names(j,:)),M_.params(j)); end for j=1:size(M_.endo_names,1) - eval([deblank(M_.endo_names(j,:)),' = NaN;']) + eval([deblank(M_.endo_names(j,:)),' = NaN;']) end check1=0; @@ -24,11 +24,11 @@ INT = pi_steady+rr_steady+4*gam_steady; %% end own model equations for iter = 1:length(M_.params) %update parameters set in the file - eval([ 'M_.params(' num2str(iter) ') = ' M_.param_names(iter,:) ';' ]) + eval([ 'M_.params(' num2str(iter) ') = ' M_.param_names(iter,:) ';' ]) end NumberOfEndogenousVariables = M_.orig_endo_nbr; %auxiliary variables are set automatically for ii = 1:NumberOfEndogenousVariables - varname = deblank(M_.endo_names(ii,:)); - eval(['ys(' int2str(ii) ') = ' varname ';']); + varname = deblank(M_.endo_names(ii,:)); + eval(['ys(' int2str(ii) ') = ' varname ';']); end diff --git a/tests/identification/kim/kim2_steadystate.m b/tests/identification/kim/kim2_steadystate.m index ffbd641ed6..5955fb16fd 100644 --- a/tests/identification/kim/kim2_steadystate.m +++ b/tests/identification/kim/kim2_steadystate.m @@ -3,11 +3,11 @@ function [ys,check1]=kim2_steadystate(ys,exo) global M_ for j=1:size(M_.param_names,1) - eval([deblank(M_.param_names(j,:)),' = M_.params(j);']) - assignin('base',deblank(M_.param_names(j,:)),M_.params(j)); + eval([deblank(M_.param_names(j,:)),' = M_.params(j);']) + assignin('base',deblank(M_.param_names(j,:)),M_.params(j)); end for j=1:size(M_.endo_names,1) - eval([deblank(M_.endo_names(j,:)),' = NaN;']) + eval([deblank(M_.endo_names(j,:)),' = NaN;']) end check1=0; @@ -22,11 +22,11 @@ lam = (1-s)^theta/c^(1+theta)/(1+theta); %% end own model equations for iter = 1:length(M_.params) %update parameters set in the file - eval([ 'M_.params(' num2str(iter) ') = ' M_.param_names(iter,:) ';' ]) + eval([ 'M_.params(' num2str(iter) ') = ' M_.param_names(iter,:) ';' ]) end NumberOfEndogenousVariables = M_.orig_endo_nbr; %auxiliary variables are set automatically for ii = 1:NumberOfEndogenousVariables - varname = deblank(M_.endo_names(ii,:)); - eval(['ys(' int2str(ii) ') = ' varname ';']); + varname = deblank(M_.endo_names(ii,:)); + eval(['ys(' int2str(ii) ') = ' varname ';']); end diff --git a/tests/kalman/likelihood/compare_kalman_routines.m b/tests/kalman/likelihood/compare_kalman_routines.m index 13022bbead..8650db0865 100644 --- a/tests/kalman/likelihood/compare_kalman_routines.m +++ b/tests/kalman/likelihood/compare_kalman_routines.m @@ -187,4 +187,3 @@ else disp(['percentage dev. = ' num2str((LIK3/LIK2-1)*100)]) end end - \ No newline at end of file diff --git a/tests/kalman/likelihood/simul_state_space_model.m b/tests/kalman/likelihood/simul_state_space_model.m index 92d3450e06..5cc0e336c6 100644 --- a/tests/kalman/likelihood/simul_state_space_model.m +++ b/tests/kalman/likelihood/simul_state_space_model.m @@ -1,25 +1,25 @@ function observed_data = simul_state_space_model(T,R,Q,mf,nobs,H) - pp = length(mf); - mm = length(T); - rr = length(Q); - - upper_cholesky_Q = chol(Q); - if nargin>5 - upper_cholesky_H = chol(H); +pp = length(mf); +mm = length(T); +rr = length(Q); + +upper_cholesky_Q = chol(Q); +if nargin>5 + upper_cholesky_H = chol(H); +end + +state_data = zeros(mm,1); + +if (nargin==5) + for t = 1:nobs + state_data = T*state_data + R* upper_cholesky_Q * randn(rr,1); + observed_data(:,t) = state_data(mf); end - - state_data = zeros(mm,1); - - if (nargin==5) - for t = 1:nobs - state_data = T*state_data + R* upper_cholesky_Q * randn(rr,1); - observed_data(:,t) = state_data(mf); - end - elseif (nargin==6) - for t = 1:nobs - state_data = T*state_data + R* upper_cholesky_Q * randn(rr,1); - observed_data(:,t) = state_data(mf) + upper_cholesky_H * randn(pp,1); - end - else - error('simul_state_space_model:: I don''t understand what you want!!!') - end \ No newline at end of file +elseif (nargin==6) + for t = 1:nobs + state_data = T*state_data + R* upper_cholesky_Q * randn(rr,1); + observed_data(:,t) = state_data(mf) + upper_cholesky_H * randn(pp,1); + end +else + error('simul_state_space_model:: I don''t understand what you want!!!') +end \ No newline at end of file diff --git a/tests/kalman_filter_smoother/compare_results_simulation/fsdat_simul_logged.m b/tests/kalman_filter_smoother/compare_results_simulation/fsdat_simul_logged.m index 3e442115c2..1129467473 100644 --- a/tests/kalman_filter_smoother/compare_results_simulation/fsdat_simul_logged.m +++ b/tests/kalman_filter_smoother/compare_results_simulation/fsdat_simul_logged.m @@ -1,830 +1,830 @@ gy_obs =[ - 1.0030045 - 0.99990934 - 1.0172778 - 0.99464043 - 1.0253423 - 1.0150215 - 0.97772557 - 0.97832186 - 1.0159561 - 1.0085937 - 1.0102649 - 1.0007604 - 1.0112596 - 1.0163279 - 1.0173204 - 1.0103896 - 1.0006493 - 0.99447124 - 1.0196405 - 1.0089304 - 0.99650737 - 1.0139707 - 0.97865842 - 1.0192225 - 0.99139628 - 1.0141362 - 1.0196612 - 0.97483476 - 0.99686151 - 0.99594464 - 1.0000642 - 1.0172243 - 1.0025773 - 0.97199728 - 1.0217815 - 1.0219949 - 0.99490252 - 1.0190728 - 1.0111337 - 1.0003792 - 0.98969164 - 1.010438 - 1.0216309 - 1.0016671 - 1.0357588 - 0.98803787 - 1.0093457 - 1.0177035 - 0.98548204 - 1.0274294 - 1.0141377 - 1.0091174 - 0.96427632 - 1.0083272 - 1.0007882 - 0.99038262 - 1.0031336 - 0.99500213 - 0.98203716 - 0.9889452 - 1.011632 - 0.99451949 - 0.97291047 - 0.98750871 - 0.99992418 - 0.97657318 - 0.99930448 - 1.0008515 - 1.0044064 - 0.98133792 - 1.0091702 - 1.0087023 - 1.0119876 - 1.0143019 - 1.0311061 - 0.99340471 - 1.0057428 - 0.99197259 - 1.0071019 - 0.99448853 - 1.0061819 - 1.0070088 - 0.9950913 - 1.0302318 - 0.9817693 - 1.0072885 - 0.97355282 - 0.98782586 - 1.0136674 - 0.99863956 - 1.0205668 - 0.99611384 - 1.0073805 - 0.99691529 - 1.0089194 - 1.0030467 - 1.0112006 - 1.0260523 - 0.97803331 - 0.99423374 - 1.0043727 - 1.0140173 - 1.0111473 - 0.99524348 - 0.99775943 - 0.9958619 - 0.9982344 - 1.0210212 - 1.0022288 - 1.0014801 - 1.011456 - 1.0124871 - 0.99843599 - 0.99324886 - 0.99912838 - 1.003327 - 1.0072071 - 1.0115223 - 1.009266 - 1.0070554 - 1.0129916 - 1.0053413 - 1.0051638 - 0.99212952 - 1.0214422 - 0.98716707 - 0.99905788 - 0.98877357 - 0.98568476 - 0.99767393 - 1.0061791 - 0.98423439 - 0.99492949 - 0.98786999 - 0.99754239 - 1.0168619 - 0.99472384 - 1.0041658 - 0.98123181 - 1.0112882 - 0.99245422 - 1.0010255 - 1.0017799 - 1.0089968 - 1.0072824 - 0.99768475 - 1.0044726 - 1.0118678 - 1.0056385 - 1.0276965 - 1.0025122 - 1.0065161 - 1.0234338 - 0.99760167 - 0.98922272 - 1.0101918 - 1.011615 - 1.0085286 - 1.0074455 - 0.98866757 - 0.99959012 - 1.0129881 - 0.99127881 - 0.97971901 - 1.0185314 - 1.020054 - 1.0132605 - 0.98063643 - 0.99490253 - 1.0101531 - 1.0004526 - 1.0059109 - 0.98974491 - 1.0062391 - 1.0216488 - 0.99398446 - 0.97786609 - 1.0019274 - 0.99587153 - 1.0095881 - 1.0111887 - 0.99457649 - 0.97896734 - 1.000172 - 1.0142951 - 1.0034224 - 1.0037242 - 1.0016059 - 1.016556 - 0.99687023 - 1.0117844 - 1.0059212 - 0.98083159 - 0.98638851 - 1.0128713 - 1.0096232 - 1.0115891 - 1.0011213 - 1.0147105 - 1.0066344 - 1.0164429 - 0.99825038 - 0.99403411 + 1.0030045 + 0.99990934 + 1.0172778 + 0.99464043 + 1.0253423 + 1.0150215 + 0.97772557 + 0.97832186 + 1.0159561 + 1.0085937 + 1.0102649 + 1.0007604 + 1.0112596 + 1.0163279 + 1.0173204 + 1.0103896 + 1.0006493 + 0.99447124 + 1.0196405 + 1.0089304 + 0.99650737 + 1.0139707 + 0.97865842 + 1.0192225 + 0.99139628 + 1.0141362 + 1.0196612 + 0.97483476 + 0.99686151 + 0.99594464 + 1.0000642 + 1.0172243 + 1.0025773 + 0.97199728 + 1.0217815 + 1.0219949 + 0.99490252 + 1.0190728 + 1.0111337 + 1.0003792 + 0.98969164 + 1.010438 + 1.0216309 + 1.0016671 + 1.0357588 + 0.98803787 + 1.0093457 + 1.0177035 + 0.98548204 + 1.0274294 + 1.0141377 + 1.0091174 + 0.96427632 + 1.0083272 + 1.0007882 + 0.99038262 + 1.0031336 + 0.99500213 + 0.98203716 + 0.9889452 + 1.011632 + 0.99451949 + 0.97291047 + 0.98750871 + 0.99992418 + 0.97657318 + 0.99930448 + 1.0008515 + 1.0044064 + 0.98133792 + 1.0091702 + 1.0087023 + 1.0119876 + 1.0143019 + 1.0311061 + 0.99340471 + 1.0057428 + 0.99197259 + 1.0071019 + 0.99448853 + 1.0061819 + 1.0070088 + 0.9950913 + 1.0302318 + 0.9817693 + 1.0072885 + 0.97355282 + 0.98782586 + 1.0136674 + 0.99863956 + 1.0205668 + 0.99611384 + 1.0073805 + 0.99691529 + 1.0089194 + 1.0030467 + 1.0112006 + 1.0260523 + 0.97803331 + 0.99423374 + 1.0043727 + 1.0140173 + 1.0111473 + 0.99524348 + 0.99775943 + 0.9958619 + 0.9982344 + 1.0210212 + 1.0022288 + 1.0014801 + 1.011456 + 1.0124871 + 0.99843599 + 0.99324886 + 0.99912838 + 1.003327 + 1.0072071 + 1.0115223 + 1.009266 + 1.0070554 + 1.0129916 + 1.0053413 + 1.0051638 + 0.99212952 + 1.0214422 + 0.98716707 + 0.99905788 + 0.98877357 + 0.98568476 + 0.99767393 + 1.0061791 + 0.98423439 + 0.99492949 + 0.98786999 + 0.99754239 + 1.0168619 + 0.99472384 + 1.0041658 + 0.98123181 + 1.0112882 + 0.99245422 + 1.0010255 + 1.0017799 + 1.0089968 + 1.0072824 + 0.99768475 + 1.0044726 + 1.0118678 + 1.0056385 + 1.0276965 + 1.0025122 + 1.0065161 + 1.0234338 + 0.99760167 + 0.98922272 + 1.0101918 + 1.011615 + 1.0085286 + 1.0074455 + 0.98866757 + 0.99959012 + 1.0129881 + 0.99127881 + 0.97971901 + 1.0185314 + 1.020054 + 1.0132605 + 0.98063643 + 0.99490253 + 1.0101531 + 1.0004526 + 1.0059109 + 0.98974491 + 1.0062391 + 1.0216488 + 0.99398446 + 0.97786609 + 1.0019274 + 0.99587153 + 1.0095881 + 1.0111887 + 0.99457649 + 0.97896734 + 1.000172 + 1.0142951 + 1.0034224 + 1.0037242 + 1.0016059 + 1.016556 + 0.99687023 + 1.0117844 + 1.0059212 + 0.98083159 + 0.98638851 + 1.0128713 + 1.0096232 + 1.0115891 + 1.0011213 + 1.0147105 + 1.0066344 + 1.0164429 + 0.99825038 + 0.99403411 -]; + ]; gp_obs =[ - 1.0079715 - 1.0074573 - 1.0153107 - 1.0152677 - 1.0011653 - 0.99950061 - 1.0328311 - 1.0192317 - 1.009827 - 0.99588916 - 1.007474 - 1.0113061 - 0.98696624 - 0.99978663 - 0.98240542 - 0.98861723 - 0.99008763 - 1.0185076 - 1.0052452 - 0.99447194 - 1.0092685 - 1.01208 - 1.0105237 - 0.98513875 - 1.0165628 - 0.99485934 - 1.0050255 - 1.0140756 - 1.0093128 - 1.0155868 - 1.0107023 - 0.99212762 - 1.0095465 - 1.0028435 - 1.0069437 - 1.0070473 - 1.0145902 - 1.0186922 - 1.0059917 - 1.0113072 - 1.0107386 - 0.99769196 - 0.99793444 - 1.0050791 - 0.98307821 - 1.0107594 - 0.99689982 - 0.98667064 - 0.9991662 - 0.98274722 - 0.98422032 - 0.99393016 - 1.0118567 - 0.99912781 - 1.0023744 - 1.0086662 - 1.0164773 - 1.0169327 - 1.0372478 - 1.0314242 - 1.0004256 - 1.0110541 - 1.0076575 - 1.0119851 - 1.0055188 - 1.0213959 - 1.0234416 - 1.0264917 - 1.0292725 - 1.0385184 - 1.0200999 - 1.0107697 - 1.008583 - 1.0200332 - 1.0030413 - 1.0108659 - 1.0185145 - 1.0168619 - 1.0180462 - 1.0239657 - 1.0205509 - 1.0189973 - 1.0246446 - 1.0135089 - 1.0352973 - 1.0099289 - 1.0266474 - 1.0279829 - 1.0101653 - 1.041216 - 1.0103861 - 1.0114727 - 1.0054605 - 1.0190722 - 1.0114837 - 1.0179213 - 1.006082 - 1.0049696 - 1.0143629 - 0.9971036 - 1.0005602 - 1.0078403 - 1.0240222 - 1.0195063 - 1.0355136 - 1.0218743 - 1.0171331 - 1.0049817 - 1.0140974 - 1.0168431 - 1.0049966 - 1.0045568 - 1.0156414 - 1.0273055 - 1.0197653 - 1.0030624 - 1.0154993 - 0.99782084 - 0.99711648 - 1.014408 - 1.0057417 - 0.99936837 - 1.0096934 - 1.0095138 - 1.0057734 - 1.0114497 - 1.0059784 - 1.0328889 - 1.0098032 - 1.0041114 - 1.0101247 - 1.0181588 - 1.0115712 - 1.0227509 - 1.0065104 - 1.0110902 - 1.0298169 - 1.0089532 - 1.0368733 - 1.0123033 - 1.0060763 - 1.0150937 - 1.0239325 - 0.99555536 - 0.99861271 - 1.0076201 - 0.99941535 - 1.0119522 - 1.0129183 - 0.99288924 - 1.0260784 - 1.0144982 - 1.0121985 - 1.0234916 - 1.02215 - 1.0190118 - 1.0172679 - 1.0118398 - 1.0002123 - 1.0092124 - 1.0071943 - 0.99508468 - 1.0019303 - 1.0030733 - 0.9964198 - 1.0027298 - 0.99797614 - 1.006942 - 0.99793928 - 1.0083214 - 1.0283732 - 1.0111102 - 1.016936 - 1.0229061 - 0.98846454 - 1.0015387 - 1.0201769 - 1.0079822 - 1.0064007 - 1.0095543 - 1.0092207 - 1.0135485 - 1.0198974 - 1.0140252 - 1.0128686 - 1.0092903 - 1.0141974 - 1.0023492 - 0.99731455 - 1.0026598 - 0.99303643 - 1.0036469 - 1.0160975 - 1.0368378 - 1.0139625 - 1.01493 - 1.0113531 - 1.0114548 - 0.99833441 - 0.99648401 - 0.97645361 - 1.0154053 - 1.01703 + 1.0079715 + 1.0074573 + 1.0153107 + 1.0152677 + 1.0011653 + 0.99950061 + 1.0328311 + 1.0192317 + 1.009827 + 0.99588916 + 1.007474 + 1.0113061 + 0.98696624 + 0.99978663 + 0.98240542 + 0.98861723 + 0.99008763 + 1.0185076 + 1.0052452 + 0.99447194 + 1.0092685 + 1.01208 + 1.0105237 + 0.98513875 + 1.0165628 + 0.99485934 + 1.0050255 + 1.0140756 + 1.0093128 + 1.0155868 + 1.0107023 + 0.99212762 + 1.0095465 + 1.0028435 + 1.0069437 + 1.0070473 + 1.0145902 + 1.0186922 + 1.0059917 + 1.0113072 + 1.0107386 + 0.99769196 + 0.99793444 + 1.0050791 + 0.98307821 + 1.0107594 + 0.99689982 + 0.98667064 + 0.9991662 + 0.98274722 + 0.98422032 + 0.99393016 + 1.0118567 + 0.99912781 + 1.0023744 + 1.0086662 + 1.0164773 + 1.0169327 + 1.0372478 + 1.0314242 + 1.0004256 + 1.0110541 + 1.0076575 + 1.0119851 + 1.0055188 + 1.0213959 + 1.0234416 + 1.0264917 + 1.0292725 + 1.0385184 + 1.0200999 + 1.0107697 + 1.008583 + 1.0200332 + 1.0030413 + 1.0108659 + 1.0185145 + 1.0168619 + 1.0180462 + 1.0239657 + 1.0205509 + 1.0189973 + 1.0246446 + 1.0135089 + 1.0352973 + 1.0099289 + 1.0266474 + 1.0279829 + 1.0101653 + 1.041216 + 1.0103861 + 1.0114727 + 1.0054605 + 1.0190722 + 1.0114837 + 1.0179213 + 1.006082 + 1.0049696 + 1.0143629 + 0.9971036 + 1.0005602 + 1.0078403 + 1.0240222 + 1.0195063 + 1.0355136 + 1.0218743 + 1.0171331 + 1.0049817 + 1.0140974 + 1.0168431 + 1.0049966 + 1.0045568 + 1.0156414 + 1.0273055 + 1.0197653 + 1.0030624 + 1.0154993 + 0.99782084 + 0.99711648 + 1.014408 + 1.0057417 + 0.99936837 + 1.0096934 + 1.0095138 + 1.0057734 + 1.0114497 + 1.0059784 + 1.0328889 + 1.0098032 + 1.0041114 + 1.0101247 + 1.0181588 + 1.0115712 + 1.0227509 + 1.0065104 + 1.0110902 + 1.0298169 + 1.0089532 + 1.0368733 + 1.0123033 + 1.0060763 + 1.0150937 + 1.0239325 + 0.99555536 + 0.99861271 + 1.0076201 + 0.99941535 + 1.0119522 + 1.0129183 + 0.99288924 + 1.0260784 + 1.0144982 + 1.0121985 + 1.0234916 + 1.02215 + 1.0190118 + 1.0172679 + 1.0118398 + 1.0002123 + 1.0092124 + 1.0071943 + 0.99508468 + 1.0019303 + 1.0030733 + 0.9964198 + 1.0027298 + 0.99797614 + 1.006942 + 0.99793928 + 1.0083214 + 1.0283732 + 1.0111102 + 1.016936 + 1.0229061 + 0.98846454 + 1.0015387 + 1.0201769 + 1.0079822 + 1.0064007 + 1.0095543 + 1.0092207 + 1.0135485 + 1.0198974 + 1.0140252 + 1.0128686 + 1.0092903 + 1.0141974 + 1.0023492 + 0.99731455 + 1.0026598 + 0.99303643 + 1.0036469 + 1.0160975 + 1.0368378 + 1.0139625 + 1.01493 + 1.0113531 + 1.0114548 + 0.99833441 + 0.99648401 + 0.97645361 + 1.0154053 + 1.01703 -]; + ]; Y_obs =[ - 1 - 0.99690484 - 1.0111781 - 1.0028141 - 1.0251518 - 1.0371688 - 1.0118899 - 0.98720726 - 1.0001589 - 1.0057481 - 1.0130085 - 1.0107643 - 1.0190194 - 1.0323428 - 1.0466587 - 1.0540438 - 1.0516886 - 1.0431553 - 1.0597913 - 1.0657172 - 1.0592201 - 1.0701863 - 1.0458402 - 1.0620582 - 1.0504499 - 1.0615817 - 1.0782384 - 1.0500687 - 1.0439257 - 1.0368658 - 1.0339255 - 1.0481453 - 1.0477181 - 1.0167109 - 1.0354878 - 1.0544782 - 1.0463762 - 1.0624445 - 1.0705737 - 1.0679484 - 1.0546356 - 1.0620691 - 1.0806955 - 1.0793581 - 1.1121124 - 1.0971458 - 1.1034869 - 1.1181859 - 1.1006634 - 1.1250883 - 1.1362214 - 1.1423343 - 1.1036061 - 1.1089288 - 1.1067125 - 1.0940906 - 1.0942197 - 1.0862174 - 1.06525 - 1.0511907 - 1.0598182 - 1.0513331 - 1.0212391 - 1.0057433 - 1.002663 - 0.97623167 - 0.97253165 - 0.97037865 - 0.97178055 - 0.95011397 - 0.95627969 - 0.96197747 - 0.97096053 - 0.98225794 - 1.0103595 - 1.0007597 - 1.003498 - 0.99246608 - 0.99656347 - 0.98804749 - 0.99122491 - 0.99522926 - 0.98731605 - 1.0145434 - 0.99330816 - 0.99759216 - 0.96814048 - 0.95296183 - 0.96362471 - 0.95925977 - 0.97682205 - 0.96993138 - 0.9743074 - 0.96821818 - 0.97413308 - 0.9741753 - 0.98237142 - 1.0054193 - 0.98044807 - 0.9716773 - 0.9730455 - 0.98405828 - 0.99220103 - 0.98444001 - 0.97919493 - 0.97205233 - 0.96728223 - 0.98529893 - 0.98452324 - 0.98299888 - 0.99145042 - 1.000933 - 0.99636447 - 0.98660883 - 0.98273271 - 0.98305518 - 0.98725774 - 0.99577549 - 1.002037 - 1.0060879 - 1.016075 - 1.0184118 - 1.0205711 - 1.0096961 - 1.0281337 - 1.0122963 - 1.0083497 - 0.99411874 - 0.976799 - 0.97146842 - 0.97464304 - 0.95587292 - 0.94779791 - 0.93266339 - 0.92720128 - 0.94105864 - 0.93277798 - 0.93393927 - 0.91216657 - 0.92045028 - 0.9099 - 0.90792098 - 0.90669634 - 0.91268867 - 0.91696661 - 0.91164685 - 0.91311495 - 0.92197825 - 0.92461222 - 0.94930422 - 0.9488119 - 0.95232353 - 0.97275278 - 0.96734995 - 0.95356817 - 0.96075548 - 0.96936594 - 0.97489002 - 0.97933106 - 0.96499412 - 0.96157973 - 0.97156334 - 0.95983765 - 0.93655215 - 0.95207909 - 0.96912862 - 0.97938462 - 0.95701655 - 0.94891457 - 0.95606317 - 0.95351125 - 0.95641767 - 0.94315807 - 0.94639265 - 0.96503697 - 0.95601693 - 0.93087851 - 0.92980141 - 0.92266844 - 0.92925206 - 0.93743628 - 0.92900826 - 0.9049711 - 0.90213859 - 0.91342916 - 0.91384707 - 0.91456681 - 0.91316822 - 0.92671976 - 0.92058549 - 0.92936541 - 0.93228212 - 0.91010921 - 0.89349322 - 0.90336005 - 0.90997873 - 0.91856328 - 0.91668007 - 0.92838606 - 0.932016 - 0.94545438 - 0.94070026 - 0.93172987 + 1 + 0.99690484 + 1.0111781 + 1.0028141 + 1.0251518 + 1.0371688 + 1.0118899 + 0.98720726 + 1.0001589 + 1.0057481 + 1.0130085 + 1.0107643 + 1.0190194 + 1.0323428 + 1.0466587 + 1.0540438 + 1.0516886 + 1.0431553 + 1.0597913 + 1.0657172 + 1.0592201 + 1.0701863 + 1.0458402 + 1.0620582 + 1.0504499 + 1.0615817 + 1.0782384 + 1.0500687 + 1.0439257 + 1.0368658 + 1.0339255 + 1.0481453 + 1.0477181 + 1.0167109 + 1.0354878 + 1.0544782 + 1.0463762 + 1.0624445 + 1.0705737 + 1.0679484 + 1.0546356 + 1.0620691 + 1.0806955 + 1.0793581 + 1.1121124 + 1.0971458 + 1.1034869 + 1.1181859 + 1.1006634 + 1.1250883 + 1.1362214 + 1.1423343 + 1.1036061 + 1.1089288 + 1.1067125 + 1.0940906 + 1.0942197 + 1.0862174 + 1.06525 + 1.0511907 + 1.0598182 + 1.0513331 + 1.0212391 + 1.0057433 + 1.002663 + 0.97623167 + 0.97253165 + 0.97037865 + 0.97178055 + 0.95011397 + 0.95627969 + 0.96197747 + 0.97096053 + 0.98225794 + 1.0103595 + 1.0007597 + 1.003498 + 0.99246608 + 0.99656347 + 0.98804749 + 0.99122491 + 0.99522926 + 0.98731605 + 1.0145434 + 0.99330816 + 0.99759216 + 0.96814048 + 0.95296183 + 0.96362471 + 0.95925977 + 0.97682205 + 0.96993138 + 0.9743074 + 0.96821818 + 0.97413308 + 0.9741753 + 0.98237142 + 1.0054193 + 0.98044807 + 0.9716773 + 0.9730455 + 0.98405828 + 0.99220103 + 0.98444001 + 0.97919493 + 0.97205233 + 0.96728223 + 0.98529893 + 0.98452324 + 0.98299888 + 0.99145042 + 1.000933 + 0.99636447 + 0.98660883 + 0.98273271 + 0.98305518 + 0.98725774 + 0.99577549 + 1.002037 + 1.0060879 + 1.016075 + 1.0184118 + 1.0205711 + 1.0096961 + 1.0281337 + 1.0122963 + 1.0083497 + 0.99411874 + 0.976799 + 0.97146842 + 0.97464304 + 0.95587292 + 0.94779791 + 0.93266339 + 0.92720128 + 0.94105864 + 0.93277798 + 0.93393927 + 0.91216657 + 0.92045028 + 0.9099 + 0.90792098 + 0.90669634 + 0.91268867 + 0.91696661 + 0.91164685 + 0.91311495 + 0.92197825 + 0.92461222 + 0.94930422 + 0.9488119 + 0.95232353 + 0.97275278 + 0.96734995 + 0.95356817 + 0.96075548 + 0.96936594 + 0.97489002 + 0.97933106 + 0.96499412 + 0.96157973 + 0.97156334 + 0.95983765 + 0.93655215 + 0.95207909 + 0.96912862 + 0.97938462 + 0.95701655 + 0.94891457 + 0.95606317 + 0.95351125 + 0.95641767 + 0.94315807 + 0.94639265 + 0.96503697 + 0.95601693 + 0.93087851 + 0.92980141 + 0.92266844 + 0.92925206 + 0.93743628 + 0.92900826 + 0.9049711 + 0.90213859 + 0.91342916 + 0.91384707 + 0.91456681 + 0.91316822 + 0.92671976 + 0.92058549 + 0.92936541 + 0.93228212 + 0.91010921 + 0.89349322 + 0.90336005 + 0.90997873 + 0.91856328 + 0.91668007 + 0.92838606 + 0.932016 + 0.94545438 + 0.94070026 + 0.93172987 -]; + ]; P_obs =[ - 1 - 0.99948573 - 1.0068249 - 1.0141211 - 1.0073149 - 0.99884398 - 1.0237035 - 1.0349636 - 1.036819 - 1.0247366 - 1.0242391 - 1.0275737 - 1.0065684 - 0.99838346 - 0.97281734 - 0.95346302 - 0.9355791 - 0.9461152 - 0.94338882 - 0.92988921 - 0.9311862 - 0.93529467 - 0.93784681 - 0.91501401 - 0.92360522 - 0.91049302 - 0.90754698 - 0.91365103 - 0.91499228 - 0.92260749 - 0.92533824 - 0.90949431 - 0.91106924 - 0.90594116 - 0.90491334 - 0.9039891 - 0.91060772 - 0.92132842 - 0.91934854 - 0.92268418 - 0.92545127 - 0.91517169 - 0.90513459 - 0.90224212 - 0.87734878 - 0.88013667 - 0.86906494 - 0.84776403 - 0.83895869 - 0.81373437 - 0.78998314 - 0.77594176 - 0.77982695 - 0.77098321 - 0.76538611 - 0.76608075 - 0.77458654 - 0.78354767 - 0.81282389 - 0.83627649 - 0.82873051 - 0.83181309 - 0.83149903 - 0.83551261 - 0.83305985 - 0.84648418 - 0.86195421 - 0.88047436 - 0.90177533 - 0.93232215 - 0.94445051 - 0.9472487 - 0.94786015 - 0.95992178 - 0.95499149 - 0.95788581 - 0.9684288 - 0.97731917 - 0.98739379 - 1.0033879 - 1.0159673 - 1.0269931 - 1.0436661 - 1.0492034 - 1.0765292 - 1.0784865 - 1.0971624 - 1.1171737 - 1.1193675 - 1.1526119 - 1.1550265 - 1.1585277 - 1.1560166 - 1.1671172 - 1.1706294 - 1.1805791 - 1.1786896 - 1.1756876 - 1.1820789 - 1.171211 - 1.1637997 - 1.1636684 - 1.179719 - 1.1912538 - 1.2187959 - 1.2326986 - 1.2418602 - 1.2388704 - 1.2449963 - 1.2538678 - 1.2508929 - 1.2474781 - 1.255148 - 1.274482 - 1.2862757 - 1.2813665 - 1.2888943 - 1.2787436 - 1.2678886 - 1.274325 - 1.2720952 - 1.263492 - 1.2652139 - 1.2667561 - 1.264558 - 1.2680362 - 1.2660431 - 1.2909605 - 1.2927921 - 1.288932 - 1.2910852 - 1.3012725 - 1.3048721 - 1.3196515 - 1.3181903 - 1.321309 - 1.3431543 - 1.344136 - 1.3730377 - 1.3773695 - 1.3754742 - 1.3825964 - 1.3985574 - 1.3861412 - 1.3767823 - 1.3764309 - 1.3678747 - 1.3718554 - 1.3768022 - 1.3617199 - 1.3798267 - 1.3863533 - 1.3905803 - 1.4061004 - 1.4202788 - 1.4313191 - 1.4406155 - 1.4444837 - 1.4367244 - 1.4379653 - 1.4371881 - 1.4243012 - 1.41826 - 1.4133617 - 1.40181 - 1.3965683 - 1.3865729 - 1.3855433 - 1.3755111 - 1.3758609 - 1.3962625 - 1.3994012 - 1.4083656 - 1.4233002 - 1.4037932 - 1.3973604 - 1.4095657 - 1.4095764 - 1.4080055 - 1.4095882 - 1.4108374 - 1.4164143 - 1.4283402 - 1.4343939 - 1.4392909 - 1.4406097 - 1.4468355 - 1.4412132 - 1.4305562 - 1.4252445 - 1.4103094 - 1.4059847 - 1.4141106 - 1.4429769 - 1.4489679 - 1.4559263 - 1.4593079 - 1.4627911 - 1.453154 - 1.4416665 - 1.4101485 - 1.4175823 - 1.4266407 + 1 + 0.99948573 + 1.0068249 + 1.0141211 + 1.0073149 + 0.99884398 + 1.0237035 + 1.0349636 + 1.036819 + 1.0247366 + 1.0242391 + 1.0275737 + 1.0065684 + 0.99838346 + 0.97281734 + 0.95346302 + 0.9355791 + 0.9461152 + 0.94338882 + 0.92988921 + 0.9311862 + 0.93529467 + 0.93784681 + 0.91501401 + 0.92360522 + 0.91049302 + 0.90754698 + 0.91365103 + 0.91499228 + 0.92260749 + 0.92533824 + 0.90949431 + 0.91106924 + 0.90594116 + 0.90491334 + 0.9039891 + 0.91060772 + 0.92132842 + 0.91934854 + 0.92268418 + 0.92545127 + 0.91517169 + 0.90513459 + 0.90224212 + 0.87734878 + 0.88013667 + 0.86906494 + 0.84776403 + 0.83895869 + 0.81373437 + 0.78998314 + 0.77594176 + 0.77982695 + 0.77098321 + 0.76538611 + 0.76608075 + 0.77458654 + 0.78354767 + 0.81282389 + 0.83627649 + 0.82873051 + 0.83181309 + 0.83149903 + 0.83551261 + 0.83305985 + 0.84648418 + 0.86195421 + 0.88047436 + 0.90177533 + 0.93232215 + 0.94445051 + 0.9472487 + 0.94786015 + 0.95992178 + 0.95499149 + 0.95788581 + 0.9684288 + 0.97731917 + 0.98739379 + 1.0033879 + 1.0159673 + 1.0269931 + 1.0436661 + 1.0492034 + 1.0765292 + 1.0784865 + 1.0971624 + 1.1171737 + 1.1193675 + 1.1526119 + 1.1550265 + 1.1585277 + 1.1560166 + 1.1671172 + 1.1706294 + 1.1805791 + 1.1786896 + 1.1756876 + 1.1820789 + 1.171211 + 1.1637997 + 1.1636684 + 1.179719 + 1.1912538 + 1.2187959 + 1.2326986 + 1.2418602 + 1.2388704 + 1.2449963 + 1.2538678 + 1.2508929 + 1.2474781 + 1.255148 + 1.274482 + 1.2862757 + 1.2813665 + 1.2888943 + 1.2787436 + 1.2678886 + 1.274325 + 1.2720952 + 1.263492 + 1.2652139 + 1.2667561 + 1.264558 + 1.2680362 + 1.2660431 + 1.2909605 + 1.2927921 + 1.288932 + 1.2910852 + 1.3012725 + 1.3048721 + 1.3196515 + 1.3181903 + 1.321309 + 1.3431543 + 1.344136 + 1.3730377 + 1.3773695 + 1.3754742 + 1.3825964 + 1.3985574 + 1.3861412 + 1.3767823 + 1.3764309 + 1.3678747 + 1.3718554 + 1.3768022 + 1.3617199 + 1.3798267 + 1.3863533 + 1.3905803 + 1.4061004 + 1.4202788 + 1.4313191 + 1.4406155 + 1.4444837 + 1.4367244 + 1.4379653 + 1.4371881 + 1.4243012 + 1.41826 + 1.4133617 + 1.40181 + 1.3965683 + 1.3865729 + 1.3855433 + 1.3755111 + 1.3758609 + 1.3962625 + 1.3994012 + 1.4083656 + 1.4233002 + 1.4037932 + 1.3973604 + 1.4095657 + 1.4095764 + 1.4080055 + 1.4095882 + 1.4108374 + 1.4164143 + 1.4283402 + 1.4343939 + 1.4392909 + 1.4406097 + 1.4468355 + 1.4412132 + 1.4305562 + 1.4252445 + 1.4103094 + 1.4059847 + 1.4141106 + 1.4429769 + 1.4489679 + 1.4559263 + 1.4593079 + 1.4627911 + 1.453154 + 1.4416665 + 1.4101485 + 1.4175823 + 1.4266407 -]; + ]; gp_obs=log(gp_obs); gy_obs=log(gy_obs); diff --git a/tests/kalman_filter_smoother/fsdat_simul.m b/tests/kalman_filter_smoother/fsdat_simul.m index d4f4a8066f..159612e577 100644 --- a/tests/kalman_filter_smoother/fsdat_simul.m +++ b/tests/kalman_filter_smoother/fsdat_simul.m @@ -1,828 +1,828 @@ gy_obs =[ - 1.0030045 - 0.99990934 - 1.0172778 - 0.99464043 - 1.0253423 - 1.0150215 - 0.97772557 - 0.97832186 - 1.0159561 - 1.0085937 - 1.0102649 - 1.0007604 - 1.0112596 - 1.0163279 - 1.0173204 - 1.0103896 - 1.0006493 - 0.99447124 - 1.0196405 - 1.0089304 - 0.99650737 - 1.0139707 - 0.97865842 - 1.0192225 - 0.99139628 - 1.0141362 - 1.0196612 - 0.97483476 - 0.99686151 - 0.99594464 - 1.0000642 - 1.0172243 - 1.0025773 - 0.97199728 - 1.0217815 - 1.0219949 - 0.99490252 - 1.0190728 - 1.0111337 - 1.0003792 - 0.98969164 - 1.010438 - 1.0216309 - 1.0016671 - 1.0357588 - 0.98803787 - 1.0093457 - 1.0177035 - 0.98548204 - 1.0274294 - 1.0141377 - 1.0091174 - 0.96427632 - 1.0083272 - 1.0007882 - 0.99038262 - 1.0031336 - 0.99500213 - 0.98203716 - 0.9889452 - 1.011632 - 0.99451949 - 0.97291047 - 0.98750871 - 0.99992418 - 0.97657318 - 0.99930448 - 1.0008515 - 1.0044064 - 0.98133792 - 1.0091702 - 1.0087023 - 1.0119876 - 1.0143019 - 1.0311061 - 0.99340471 - 1.0057428 - 0.99197259 - 1.0071019 - 0.99448853 - 1.0061819 - 1.0070088 - 0.9950913 - 1.0302318 - 0.9817693 - 1.0072885 - 0.97355282 - 0.98782586 - 1.0136674 - 0.99863956 - 1.0205668 - 0.99611384 - 1.0073805 - 0.99691529 - 1.0089194 - 1.0030467 - 1.0112006 - 1.0260523 - 0.97803331 - 0.99423374 - 1.0043727 - 1.0140173 - 1.0111473 - 0.99524348 - 0.99775943 - 0.9958619 - 0.9982344 - 1.0210212 - 1.0022288 - 1.0014801 - 1.011456 - 1.0124871 - 0.99843599 - 0.99324886 - 0.99912838 - 1.003327 - 1.0072071 - 1.0115223 - 1.009266 - 1.0070554 - 1.0129916 - 1.0053413 - 1.0051638 - 0.99212952 - 1.0214422 - 0.98716707 - 0.99905788 - 0.98877357 - 0.98568476 - 0.99767393 - 1.0061791 - 0.98423439 - 0.99492949 - 0.98786999 - 0.99754239 - 1.0168619 - 0.99472384 - 1.0041658 - 0.98123181 - 1.0112882 - 0.99245422 - 1.0010255 - 1.0017799 - 1.0089968 - 1.0072824 - 0.99768475 - 1.0044726 - 1.0118678 - 1.0056385 - 1.0276965 - 1.0025122 - 1.0065161 - 1.0234338 - 0.99760167 - 0.98922272 - 1.0101918 - 1.011615 - 1.0085286 - 1.0074455 - 0.98866757 - 0.99959012 - 1.0129881 - 0.99127881 - 0.97971901 - 1.0185314 - 1.020054 - 1.0132605 - 0.98063643 - 0.99490253 - 1.0101531 - 1.0004526 - 1.0059109 - 0.98974491 - 1.0062391 - 1.0216488 - 0.99398446 - 0.97786609 - 1.0019274 - 0.99587153 - 1.0095881 - 1.0111887 - 0.99457649 - 0.97896734 - 1.000172 - 1.0142951 - 1.0034224 - 1.0037242 - 1.0016059 - 1.016556 - 0.99687023 - 1.0117844 - 1.0059212 - 0.98083159 - 0.98638851 - 1.0128713 - 1.0096232 - 1.0115891 - 1.0011213 - 1.0147105 - 1.0066344 - 1.0164429 - 0.99825038 - 0.99403411 + 1.0030045 + 0.99990934 + 1.0172778 + 0.99464043 + 1.0253423 + 1.0150215 + 0.97772557 + 0.97832186 + 1.0159561 + 1.0085937 + 1.0102649 + 1.0007604 + 1.0112596 + 1.0163279 + 1.0173204 + 1.0103896 + 1.0006493 + 0.99447124 + 1.0196405 + 1.0089304 + 0.99650737 + 1.0139707 + 0.97865842 + 1.0192225 + 0.99139628 + 1.0141362 + 1.0196612 + 0.97483476 + 0.99686151 + 0.99594464 + 1.0000642 + 1.0172243 + 1.0025773 + 0.97199728 + 1.0217815 + 1.0219949 + 0.99490252 + 1.0190728 + 1.0111337 + 1.0003792 + 0.98969164 + 1.010438 + 1.0216309 + 1.0016671 + 1.0357588 + 0.98803787 + 1.0093457 + 1.0177035 + 0.98548204 + 1.0274294 + 1.0141377 + 1.0091174 + 0.96427632 + 1.0083272 + 1.0007882 + 0.99038262 + 1.0031336 + 0.99500213 + 0.98203716 + 0.9889452 + 1.011632 + 0.99451949 + 0.97291047 + 0.98750871 + 0.99992418 + 0.97657318 + 0.99930448 + 1.0008515 + 1.0044064 + 0.98133792 + 1.0091702 + 1.0087023 + 1.0119876 + 1.0143019 + 1.0311061 + 0.99340471 + 1.0057428 + 0.99197259 + 1.0071019 + 0.99448853 + 1.0061819 + 1.0070088 + 0.9950913 + 1.0302318 + 0.9817693 + 1.0072885 + 0.97355282 + 0.98782586 + 1.0136674 + 0.99863956 + 1.0205668 + 0.99611384 + 1.0073805 + 0.99691529 + 1.0089194 + 1.0030467 + 1.0112006 + 1.0260523 + 0.97803331 + 0.99423374 + 1.0043727 + 1.0140173 + 1.0111473 + 0.99524348 + 0.99775943 + 0.9958619 + 0.9982344 + 1.0210212 + 1.0022288 + 1.0014801 + 1.011456 + 1.0124871 + 0.99843599 + 0.99324886 + 0.99912838 + 1.003327 + 1.0072071 + 1.0115223 + 1.009266 + 1.0070554 + 1.0129916 + 1.0053413 + 1.0051638 + 0.99212952 + 1.0214422 + 0.98716707 + 0.99905788 + 0.98877357 + 0.98568476 + 0.99767393 + 1.0061791 + 0.98423439 + 0.99492949 + 0.98786999 + 0.99754239 + 1.0168619 + 0.99472384 + 1.0041658 + 0.98123181 + 1.0112882 + 0.99245422 + 1.0010255 + 1.0017799 + 1.0089968 + 1.0072824 + 0.99768475 + 1.0044726 + 1.0118678 + 1.0056385 + 1.0276965 + 1.0025122 + 1.0065161 + 1.0234338 + 0.99760167 + 0.98922272 + 1.0101918 + 1.011615 + 1.0085286 + 1.0074455 + 0.98866757 + 0.99959012 + 1.0129881 + 0.99127881 + 0.97971901 + 1.0185314 + 1.020054 + 1.0132605 + 0.98063643 + 0.99490253 + 1.0101531 + 1.0004526 + 1.0059109 + 0.98974491 + 1.0062391 + 1.0216488 + 0.99398446 + 0.97786609 + 1.0019274 + 0.99587153 + 1.0095881 + 1.0111887 + 0.99457649 + 0.97896734 + 1.000172 + 1.0142951 + 1.0034224 + 1.0037242 + 1.0016059 + 1.016556 + 0.99687023 + 1.0117844 + 1.0059212 + 0.98083159 + 0.98638851 + 1.0128713 + 1.0096232 + 1.0115891 + 1.0011213 + 1.0147105 + 1.0066344 + 1.0164429 + 0.99825038 + 0.99403411 -]; + ]; gp_obs =[ - 1.0079715 - 1.0074573 - 1.0153107 - 1.0152677 - 1.0011653 - 0.99950061 - 1.0328311 - 1.0192317 - 1.009827 - 0.99588916 - 1.007474 - 1.0113061 - 0.98696624 - 0.99978663 - 0.98240542 - 0.98861723 - 0.99008763 - 1.0185076 - 1.0052452 - 0.99447194 - 1.0092685 - 1.01208 - 1.0105237 - 0.98513875 - 1.0165628 - 0.99485934 - 1.0050255 - 1.0140756 - 1.0093128 - 1.0155868 - 1.0107023 - 0.99212762 - 1.0095465 - 1.0028435 - 1.0069437 - 1.0070473 - 1.0145902 - 1.0186922 - 1.0059917 - 1.0113072 - 1.0107386 - 0.99769196 - 0.99793444 - 1.0050791 - 0.98307821 - 1.0107594 - 0.99689982 - 0.98667064 - 0.9991662 - 0.98274722 - 0.98422032 - 0.99393016 - 1.0118567 - 0.99912781 - 1.0023744 - 1.0086662 - 1.0164773 - 1.0169327 - 1.0372478 - 1.0314242 - 1.0004256 - 1.0110541 - 1.0076575 - 1.0119851 - 1.0055188 - 1.0213959 - 1.0234416 - 1.0264917 - 1.0292725 - 1.0385184 - 1.0200999 - 1.0107697 - 1.008583 - 1.0200332 - 1.0030413 - 1.0108659 - 1.0185145 - 1.0168619 - 1.0180462 - 1.0239657 - 1.0205509 - 1.0189973 - 1.0246446 - 1.0135089 - 1.0352973 - 1.0099289 - 1.0266474 - 1.0279829 - 1.0101653 - 1.041216 - 1.0103861 - 1.0114727 - 1.0054605 - 1.0190722 - 1.0114837 - 1.0179213 - 1.006082 - 1.0049696 - 1.0143629 - 0.9971036 - 1.0005602 - 1.0078403 - 1.0240222 - 1.0195063 - 1.0355136 - 1.0218743 - 1.0171331 - 1.0049817 - 1.0140974 - 1.0168431 - 1.0049966 - 1.0045568 - 1.0156414 - 1.0273055 - 1.0197653 - 1.0030624 - 1.0154993 - 0.99782084 - 0.99711648 - 1.014408 - 1.0057417 - 0.99936837 - 1.0096934 - 1.0095138 - 1.0057734 - 1.0114497 - 1.0059784 - 1.0328889 - 1.0098032 - 1.0041114 - 1.0101247 - 1.0181588 - 1.0115712 - 1.0227509 - 1.0065104 - 1.0110902 - 1.0298169 - 1.0089532 - 1.0368733 - 1.0123033 - 1.0060763 - 1.0150937 - 1.0239325 - 0.99555536 - 0.99861271 - 1.0076201 - 0.99941535 - 1.0119522 - 1.0129183 - 0.99288924 - 1.0260784 - 1.0144982 - 1.0121985 - 1.0234916 - 1.02215 - 1.0190118 - 1.0172679 - 1.0118398 - 1.0002123 - 1.0092124 - 1.0071943 - 0.99508468 - 1.0019303 - 1.0030733 - 0.9964198 - 1.0027298 - 0.99797614 - 1.006942 - 0.99793928 - 1.0083214 - 1.0283732 - 1.0111102 - 1.016936 - 1.0229061 - 0.98846454 - 1.0015387 - 1.0201769 - 1.0079822 - 1.0064007 - 1.0095543 - 1.0092207 - 1.0135485 - 1.0198974 - 1.0140252 - 1.0128686 - 1.0092903 - 1.0141974 - 1.0023492 - 0.99731455 - 1.0026598 - 0.99303643 - 1.0036469 - 1.0160975 - 1.0368378 - 1.0139625 - 1.01493 - 1.0113531 - 1.0114548 - 0.99833441 - 0.99648401 - 0.97645361 - 1.0154053 - 1.01703 + 1.0079715 + 1.0074573 + 1.0153107 + 1.0152677 + 1.0011653 + 0.99950061 + 1.0328311 + 1.0192317 + 1.009827 + 0.99588916 + 1.007474 + 1.0113061 + 0.98696624 + 0.99978663 + 0.98240542 + 0.98861723 + 0.99008763 + 1.0185076 + 1.0052452 + 0.99447194 + 1.0092685 + 1.01208 + 1.0105237 + 0.98513875 + 1.0165628 + 0.99485934 + 1.0050255 + 1.0140756 + 1.0093128 + 1.0155868 + 1.0107023 + 0.99212762 + 1.0095465 + 1.0028435 + 1.0069437 + 1.0070473 + 1.0145902 + 1.0186922 + 1.0059917 + 1.0113072 + 1.0107386 + 0.99769196 + 0.99793444 + 1.0050791 + 0.98307821 + 1.0107594 + 0.99689982 + 0.98667064 + 0.9991662 + 0.98274722 + 0.98422032 + 0.99393016 + 1.0118567 + 0.99912781 + 1.0023744 + 1.0086662 + 1.0164773 + 1.0169327 + 1.0372478 + 1.0314242 + 1.0004256 + 1.0110541 + 1.0076575 + 1.0119851 + 1.0055188 + 1.0213959 + 1.0234416 + 1.0264917 + 1.0292725 + 1.0385184 + 1.0200999 + 1.0107697 + 1.008583 + 1.0200332 + 1.0030413 + 1.0108659 + 1.0185145 + 1.0168619 + 1.0180462 + 1.0239657 + 1.0205509 + 1.0189973 + 1.0246446 + 1.0135089 + 1.0352973 + 1.0099289 + 1.0266474 + 1.0279829 + 1.0101653 + 1.041216 + 1.0103861 + 1.0114727 + 1.0054605 + 1.0190722 + 1.0114837 + 1.0179213 + 1.006082 + 1.0049696 + 1.0143629 + 0.9971036 + 1.0005602 + 1.0078403 + 1.0240222 + 1.0195063 + 1.0355136 + 1.0218743 + 1.0171331 + 1.0049817 + 1.0140974 + 1.0168431 + 1.0049966 + 1.0045568 + 1.0156414 + 1.0273055 + 1.0197653 + 1.0030624 + 1.0154993 + 0.99782084 + 0.99711648 + 1.014408 + 1.0057417 + 0.99936837 + 1.0096934 + 1.0095138 + 1.0057734 + 1.0114497 + 1.0059784 + 1.0328889 + 1.0098032 + 1.0041114 + 1.0101247 + 1.0181588 + 1.0115712 + 1.0227509 + 1.0065104 + 1.0110902 + 1.0298169 + 1.0089532 + 1.0368733 + 1.0123033 + 1.0060763 + 1.0150937 + 1.0239325 + 0.99555536 + 0.99861271 + 1.0076201 + 0.99941535 + 1.0119522 + 1.0129183 + 0.99288924 + 1.0260784 + 1.0144982 + 1.0121985 + 1.0234916 + 1.02215 + 1.0190118 + 1.0172679 + 1.0118398 + 1.0002123 + 1.0092124 + 1.0071943 + 0.99508468 + 1.0019303 + 1.0030733 + 0.9964198 + 1.0027298 + 0.99797614 + 1.006942 + 0.99793928 + 1.0083214 + 1.0283732 + 1.0111102 + 1.016936 + 1.0229061 + 0.98846454 + 1.0015387 + 1.0201769 + 1.0079822 + 1.0064007 + 1.0095543 + 1.0092207 + 1.0135485 + 1.0198974 + 1.0140252 + 1.0128686 + 1.0092903 + 1.0141974 + 1.0023492 + 0.99731455 + 1.0026598 + 0.99303643 + 1.0036469 + 1.0160975 + 1.0368378 + 1.0139625 + 1.01493 + 1.0113531 + 1.0114548 + 0.99833441 + 0.99648401 + 0.97645361 + 1.0154053 + 1.01703 -]; + ]; Y_obs =[ - 1 - 0.99690484 - 1.0111781 - 1.0028141 - 1.0251518 - 1.0371688 - 1.0118899 - 0.98720726 - 1.0001589 - 1.0057481 - 1.0130085 - 1.0107643 - 1.0190194 - 1.0323428 - 1.0466587 - 1.0540438 - 1.0516886 - 1.0431553 - 1.0597913 - 1.0657172 - 1.0592201 - 1.0701863 - 1.0458402 - 1.0620582 - 1.0504499 - 1.0615817 - 1.0782384 - 1.0500687 - 1.0439257 - 1.0368658 - 1.0339255 - 1.0481453 - 1.0477181 - 1.0167109 - 1.0354878 - 1.0544782 - 1.0463762 - 1.0624445 - 1.0705737 - 1.0679484 - 1.0546356 - 1.0620691 - 1.0806955 - 1.0793581 - 1.1121124 - 1.0971458 - 1.1034869 - 1.1181859 - 1.1006634 - 1.1250883 - 1.1362214 - 1.1423343 - 1.1036061 - 1.1089288 - 1.1067125 - 1.0940906 - 1.0942197 - 1.0862174 - 1.06525 - 1.0511907 - 1.0598182 - 1.0513331 - 1.0212391 - 1.0057433 - 1.002663 - 0.97623167 - 0.97253165 - 0.97037865 - 0.97178055 - 0.95011397 - 0.95627969 - 0.96197747 - 0.97096053 - 0.98225794 - 1.0103595 - 1.0007597 - 1.003498 - 0.99246608 - 0.99656347 - 0.98804749 - 0.99122491 - 0.99522926 - 0.98731605 - 1.0145434 - 0.99330816 - 0.99759216 - 0.96814048 - 0.95296183 - 0.96362471 - 0.95925977 - 0.97682205 - 0.96993138 - 0.9743074 - 0.96821818 - 0.97413308 - 0.9741753 - 0.98237142 - 1.0054193 - 0.98044807 - 0.9716773 - 0.9730455 - 0.98405828 - 0.99220103 - 0.98444001 - 0.97919493 - 0.97205233 - 0.96728223 - 0.98529893 - 0.98452324 - 0.98299888 - 0.99145042 - 1.000933 - 0.99636447 - 0.98660883 - 0.98273271 - 0.98305518 - 0.98725774 - 0.99577549 - 1.002037 - 1.0060879 - 1.016075 - 1.0184118 - 1.0205711 - 1.0096961 - 1.0281337 - 1.0122963 - 1.0083497 - 0.99411874 - 0.976799 - 0.97146842 - 0.97464304 - 0.95587292 - 0.94779791 - 0.93266339 - 0.92720128 - 0.94105864 - 0.93277798 - 0.93393927 - 0.91216657 - 0.92045028 - 0.9099 - 0.90792098 - 0.90669634 - 0.91268867 - 0.91696661 - 0.91164685 - 0.91311495 - 0.92197825 - 0.92461222 - 0.94930422 - 0.9488119 - 0.95232353 - 0.97275278 - 0.96734995 - 0.95356817 - 0.96075548 - 0.96936594 - 0.97489002 - 0.97933106 - 0.96499412 - 0.96157973 - 0.97156334 - 0.95983765 - 0.93655215 - 0.95207909 - 0.96912862 - 0.97938462 - 0.95701655 - 0.94891457 - 0.95606317 - 0.95351125 - 0.95641767 - 0.94315807 - 0.94639265 - 0.96503697 - 0.95601693 - 0.93087851 - 0.92980141 - 0.92266844 - 0.92925206 - 0.93743628 - 0.92900826 - 0.9049711 - 0.90213859 - 0.91342916 - 0.91384707 - 0.91456681 - 0.91316822 - 0.92671976 - 0.92058549 - 0.92936541 - 0.93228212 - 0.91010921 - 0.89349322 - 0.90336005 - 0.90997873 - 0.91856328 - 0.91668007 - 0.92838606 - 0.932016 - 0.94545438 - 0.94070026 - 0.93172987 + 1 + 0.99690484 + 1.0111781 + 1.0028141 + 1.0251518 + 1.0371688 + 1.0118899 + 0.98720726 + 1.0001589 + 1.0057481 + 1.0130085 + 1.0107643 + 1.0190194 + 1.0323428 + 1.0466587 + 1.0540438 + 1.0516886 + 1.0431553 + 1.0597913 + 1.0657172 + 1.0592201 + 1.0701863 + 1.0458402 + 1.0620582 + 1.0504499 + 1.0615817 + 1.0782384 + 1.0500687 + 1.0439257 + 1.0368658 + 1.0339255 + 1.0481453 + 1.0477181 + 1.0167109 + 1.0354878 + 1.0544782 + 1.0463762 + 1.0624445 + 1.0705737 + 1.0679484 + 1.0546356 + 1.0620691 + 1.0806955 + 1.0793581 + 1.1121124 + 1.0971458 + 1.1034869 + 1.1181859 + 1.1006634 + 1.1250883 + 1.1362214 + 1.1423343 + 1.1036061 + 1.1089288 + 1.1067125 + 1.0940906 + 1.0942197 + 1.0862174 + 1.06525 + 1.0511907 + 1.0598182 + 1.0513331 + 1.0212391 + 1.0057433 + 1.002663 + 0.97623167 + 0.97253165 + 0.97037865 + 0.97178055 + 0.95011397 + 0.95627969 + 0.96197747 + 0.97096053 + 0.98225794 + 1.0103595 + 1.0007597 + 1.003498 + 0.99246608 + 0.99656347 + 0.98804749 + 0.99122491 + 0.99522926 + 0.98731605 + 1.0145434 + 0.99330816 + 0.99759216 + 0.96814048 + 0.95296183 + 0.96362471 + 0.95925977 + 0.97682205 + 0.96993138 + 0.9743074 + 0.96821818 + 0.97413308 + 0.9741753 + 0.98237142 + 1.0054193 + 0.98044807 + 0.9716773 + 0.9730455 + 0.98405828 + 0.99220103 + 0.98444001 + 0.97919493 + 0.97205233 + 0.96728223 + 0.98529893 + 0.98452324 + 0.98299888 + 0.99145042 + 1.000933 + 0.99636447 + 0.98660883 + 0.98273271 + 0.98305518 + 0.98725774 + 0.99577549 + 1.002037 + 1.0060879 + 1.016075 + 1.0184118 + 1.0205711 + 1.0096961 + 1.0281337 + 1.0122963 + 1.0083497 + 0.99411874 + 0.976799 + 0.97146842 + 0.97464304 + 0.95587292 + 0.94779791 + 0.93266339 + 0.92720128 + 0.94105864 + 0.93277798 + 0.93393927 + 0.91216657 + 0.92045028 + 0.9099 + 0.90792098 + 0.90669634 + 0.91268867 + 0.91696661 + 0.91164685 + 0.91311495 + 0.92197825 + 0.92461222 + 0.94930422 + 0.9488119 + 0.95232353 + 0.97275278 + 0.96734995 + 0.95356817 + 0.96075548 + 0.96936594 + 0.97489002 + 0.97933106 + 0.96499412 + 0.96157973 + 0.97156334 + 0.95983765 + 0.93655215 + 0.95207909 + 0.96912862 + 0.97938462 + 0.95701655 + 0.94891457 + 0.95606317 + 0.95351125 + 0.95641767 + 0.94315807 + 0.94639265 + 0.96503697 + 0.95601693 + 0.93087851 + 0.92980141 + 0.92266844 + 0.92925206 + 0.93743628 + 0.92900826 + 0.9049711 + 0.90213859 + 0.91342916 + 0.91384707 + 0.91456681 + 0.91316822 + 0.92671976 + 0.92058549 + 0.92936541 + 0.93228212 + 0.91010921 + 0.89349322 + 0.90336005 + 0.90997873 + 0.91856328 + 0.91668007 + 0.92838606 + 0.932016 + 0.94545438 + 0.94070026 + 0.93172987 -]; + ]; P_obs =[ - 1 - 0.99948573 - 1.0068249 - 1.0141211 - 1.0073149 - 0.99884398 - 1.0237035 - 1.0349636 - 1.036819 - 1.0247366 - 1.0242391 - 1.0275737 - 1.0065684 - 0.99838346 - 0.97281734 - 0.95346302 - 0.9355791 - 0.9461152 - 0.94338882 - 0.92988921 - 0.9311862 - 0.93529467 - 0.93784681 - 0.91501401 - 0.92360522 - 0.91049302 - 0.90754698 - 0.91365103 - 0.91499228 - 0.92260749 - 0.92533824 - 0.90949431 - 0.91106924 - 0.90594116 - 0.90491334 - 0.9039891 - 0.91060772 - 0.92132842 - 0.91934854 - 0.92268418 - 0.92545127 - 0.91517169 - 0.90513459 - 0.90224212 - 0.87734878 - 0.88013667 - 0.86906494 - 0.84776403 - 0.83895869 - 0.81373437 - 0.78998314 - 0.77594176 - 0.77982695 - 0.77098321 - 0.76538611 - 0.76608075 - 0.77458654 - 0.78354767 - 0.81282389 - 0.83627649 - 0.82873051 - 0.83181309 - 0.83149903 - 0.83551261 - 0.83305985 - 0.84648418 - 0.86195421 - 0.88047436 - 0.90177533 - 0.93232215 - 0.94445051 - 0.9472487 - 0.94786015 - 0.95992178 - 0.95499149 - 0.95788581 - 0.9684288 - 0.97731917 - 0.98739379 - 1.0033879 - 1.0159673 - 1.0269931 - 1.0436661 - 1.0492034 - 1.0765292 - 1.0784865 - 1.0971624 - 1.1171737 - 1.1193675 - 1.1526119 - 1.1550265 - 1.1585277 - 1.1560166 - 1.1671172 - 1.1706294 - 1.1805791 - 1.1786896 - 1.1756876 - 1.1820789 - 1.171211 - 1.1637997 - 1.1636684 - 1.179719 - 1.1912538 - 1.2187959 - 1.2326986 - 1.2418602 - 1.2388704 - 1.2449963 - 1.2538678 - 1.2508929 - 1.2474781 - 1.255148 - 1.274482 - 1.2862757 - 1.2813665 - 1.2888943 - 1.2787436 - 1.2678886 - 1.274325 - 1.2720952 - 1.263492 - 1.2652139 - 1.2667561 - 1.264558 - 1.2680362 - 1.2660431 - 1.2909605 - 1.2927921 - 1.288932 - 1.2910852 - 1.3012725 - 1.3048721 - 1.3196515 - 1.3181903 - 1.321309 - 1.3431543 - 1.344136 - 1.3730377 - 1.3773695 - 1.3754742 - 1.3825964 - 1.3985574 - 1.3861412 - 1.3767823 - 1.3764309 - 1.3678747 - 1.3718554 - 1.3768022 - 1.3617199 - 1.3798267 - 1.3863533 - 1.3905803 - 1.4061004 - 1.4202788 - 1.4313191 - 1.4406155 - 1.4444837 - 1.4367244 - 1.4379653 - 1.4371881 - 1.4243012 - 1.41826 - 1.4133617 - 1.40181 - 1.3965683 - 1.3865729 - 1.3855433 - 1.3755111 - 1.3758609 - 1.3962625 - 1.3994012 - 1.4083656 - 1.4233002 - 1.4037932 - 1.3973604 - 1.4095657 - 1.4095764 - 1.4080055 - 1.4095882 - 1.4108374 - 1.4164143 - 1.4283402 - 1.4343939 - 1.4392909 - 1.4406097 - 1.4468355 - 1.4412132 - 1.4305562 - 1.4252445 - 1.4103094 - 1.4059847 - 1.4141106 - 1.4429769 - 1.4489679 - 1.4559263 - 1.4593079 - 1.4627911 - 1.453154 - 1.4416665 - 1.4101485 - 1.4175823 - 1.4266407 + 1 + 0.99948573 + 1.0068249 + 1.0141211 + 1.0073149 + 0.99884398 + 1.0237035 + 1.0349636 + 1.036819 + 1.0247366 + 1.0242391 + 1.0275737 + 1.0065684 + 0.99838346 + 0.97281734 + 0.95346302 + 0.9355791 + 0.9461152 + 0.94338882 + 0.92988921 + 0.9311862 + 0.93529467 + 0.93784681 + 0.91501401 + 0.92360522 + 0.91049302 + 0.90754698 + 0.91365103 + 0.91499228 + 0.92260749 + 0.92533824 + 0.90949431 + 0.91106924 + 0.90594116 + 0.90491334 + 0.9039891 + 0.91060772 + 0.92132842 + 0.91934854 + 0.92268418 + 0.92545127 + 0.91517169 + 0.90513459 + 0.90224212 + 0.87734878 + 0.88013667 + 0.86906494 + 0.84776403 + 0.83895869 + 0.81373437 + 0.78998314 + 0.77594176 + 0.77982695 + 0.77098321 + 0.76538611 + 0.76608075 + 0.77458654 + 0.78354767 + 0.81282389 + 0.83627649 + 0.82873051 + 0.83181309 + 0.83149903 + 0.83551261 + 0.83305985 + 0.84648418 + 0.86195421 + 0.88047436 + 0.90177533 + 0.93232215 + 0.94445051 + 0.9472487 + 0.94786015 + 0.95992178 + 0.95499149 + 0.95788581 + 0.9684288 + 0.97731917 + 0.98739379 + 1.0033879 + 1.0159673 + 1.0269931 + 1.0436661 + 1.0492034 + 1.0765292 + 1.0784865 + 1.0971624 + 1.1171737 + 1.1193675 + 1.1526119 + 1.1550265 + 1.1585277 + 1.1560166 + 1.1671172 + 1.1706294 + 1.1805791 + 1.1786896 + 1.1756876 + 1.1820789 + 1.171211 + 1.1637997 + 1.1636684 + 1.179719 + 1.1912538 + 1.2187959 + 1.2326986 + 1.2418602 + 1.2388704 + 1.2449963 + 1.2538678 + 1.2508929 + 1.2474781 + 1.255148 + 1.274482 + 1.2862757 + 1.2813665 + 1.2888943 + 1.2787436 + 1.2678886 + 1.274325 + 1.2720952 + 1.263492 + 1.2652139 + 1.2667561 + 1.264558 + 1.2680362 + 1.2660431 + 1.2909605 + 1.2927921 + 1.288932 + 1.2910852 + 1.3012725 + 1.3048721 + 1.3196515 + 1.3181903 + 1.321309 + 1.3431543 + 1.344136 + 1.3730377 + 1.3773695 + 1.3754742 + 1.3825964 + 1.3985574 + 1.3861412 + 1.3767823 + 1.3764309 + 1.3678747 + 1.3718554 + 1.3768022 + 1.3617199 + 1.3798267 + 1.3863533 + 1.3905803 + 1.4061004 + 1.4202788 + 1.4313191 + 1.4406155 + 1.4444837 + 1.4367244 + 1.4379653 + 1.4371881 + 1.4243012 + 1.41826 + 1.4133617 + 1.40181 + 1.3965683 + 1.3865729 + 1.3855433 + 1.3755111 + 1.3758609 + 1.3962625 + 1.3994012 + 1.4083656 + 1.4233002 + 1.4037932 + 1.3973604 + 1.4095657 + 1.4095764 + 1.4080055 + 1.4095882 + 1.4108374 + 1.4164143 + 1.4283402 + 1.4343939 + 1.4392909 + 1.4406097 + 1.4468355 + 1.4412132 + 1.4305562 + 1.4252445 + 1.4103094 + 1.4059847 + 1.4141106 + 1.4429769 + 1.4489679 + 1.4559263 + 1.4593079 + 1.4627911 + 1.453154 + 1.4416665 + 1.4101485 + 1.4175823 + 1.4266407 -]; + ]; diff --git a/tests/kalman_filter_smoother/testsmoother.m b/tests/kalman_filter_smoother/testsmoother.m index 2e633bc234..3ec1c8cdff 100644 --- a/tests/kalman_filter_smoother/testsmoother.m +++ b/tests/kalman_filter_smoother/testsmoother.m @@ -9,10 +9,10 @@ Pstar1(1,1) = 0; Pstar1(4,1) = 0; Pstar1(1,4) = 0; [alphahat1,epsilonhat1,etahat1,a11, aK1] = DiffuseKalmanSmootherH1(T,R,Q,H, ... - Pinf1,Pstar1,Y,trend,pp,mm,smpl,mf); + Pinf1,Pstar1,Y,trend,pp,mm,smpl,mf); [alphahat2,epsilonhat2,etahat2,a12, aK2] = DiffuseKalmanSmootherH3(T,R,Q,H, ... - Pinf1,Pstar1,Y,trend, ... - pp,mm,smpl,mf); + Pinf1,Pstar1,Y,trend, ... + pp,mm,smpl,mf); max(max(abs(alphahat1-alphahat2))) max(max(abs(epsilonhat1-epsilonhat2))) max(max(abs(etahat1-etahat2))) @@ -21,10 +21,10 @@ max(max(abs(aK1-aK2))) return [alphahat1,etahat1,a11, aK1] = DiffuseKalmanSmoother1(T,R,Q, ... - Pinf1,Pstar1,Y,trend,pp,mm,smpl,mf); + Pinf1,Pstar1,Y,trend,pp,mm,smpl,mf); [alphahat2,etahat2,a12, aK2] = DiffuseKalmanSmoother3(T,R,Q, ... - Pinf1,Pstar1,Y,trend, ... - pp,mm,smpl,mf); + Pinf1,Pstar1,Y,trend, ... + pp,mm,smpl,mf); max(max(abs(alphahat1-alphahat2))) @@ -35,10 +35,10 @@ max(max(abs(a11-a12))) H = zeros(size(H)); [alphahat1,etahat1,a11, aK1] = DiffuseKalmanSmoother1(T,R,Q, ... - Pinf1,Pstar1,Y,trend,pp,mm,smpl,mf); + Pinf1,Pstar1,Y,trend,pp,mm,smpl,mf); [alphahat2,epsilonhat2,etahat2,a12, aK2] = DiffuseKalmanSmootherH1(T,R,Q,H, ... - Pinf1,Pstar1,Y,trend, ... - pp,mm,smpl,mf); + Pinf1,Pstar1,Y,trend, ... + pp,mm,smpl,mf); max(max(abs(alphahat1-alphahat2))) max(max(abs(etahat1-etahat2))) max(max(abs(a11-a12))) @@ -46,9 +46,9 @@ max(max(abs(a11-a12))) [alphahat1,etahat1,a11, aK1] = DiffuseKalmanSmoother3(T,R,Q, ... - Pinf1,Pstar1,Y,trend,pp,mm,smpl,mf); + Pinf1,Pstar1,Y,trend,pp,mm,smpl,mf); [alphahat2,epsilonhat2,etahat2,a12, aK2] = DiffuseKalmanSmootherH3(T,R,Q, H, ... - Pinf1,Pstar1,Y,trend,pp,mm,smpl,mf); + Pinf1,Pstar1,Y,trend,pp,mm,smpl,mf); max(max(abs(alphahat1-alphahat2))) max(max(abs(etahat1-etahat2))) diff --git a/tests/load_octave_packages.m b/tests/load_octave_packages.m index 886bf644b0..62b6e3d3c4 100644 --- a/tests/load_octave_packages.m +++ b/tests/load_octave_packages.m @@ -11,11 +11,11 @@ ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with Dynare. If not, see <http://www.gnu.org/licenses/>. + ## + ## You should have received a copy of the GNU General Public License + ## along with Dynare. If not, see <http://www.gnu.org/licenses/>. -pkg load io -pkg load optim -pkg load control -pkg load statistics \ No newline at end of file + pkg load io + pkg load optim + pkg load control + pkg load statistics \ No newline at end of file diff --git a/tests/ls2003/data_ca1.m b/tests/ls2003/data_ca1.m index c28fae1a28..ca003056bd 100644 --- a/tests/ls2003/data_ca1.m +++ b/tests/ls2003/data_ca1.m @@ -1,98 +1,98 @@ data = [0.928467646476 11.8716889412 20 0.418037507392 0.227382377518 ... --0.705994063083 11.7522582094 21.25 1.09254424511 -1.29488274994 ... --0.511895351926 9.68144025625 17.25 -1.66150408407 0.331508393098 ... --0.990955971267 10.0890781236 17 1.43016275252 -2.43589670141 ... --0.981233061806 12.1094840679 18.25 2.91293288733 -0.790246576864 ... --0.882182844512 8.54559460406 15 0.419579139481 0.358729719566 ... --0.930893002836 6.19238374422 12.5 -1.48847457959 0.739779938797 ... -1.53158206947 2.76544271886 11.5 -0.336216769682 0.455559918769 ... -2.2659052834 5.47418162513 11 0.306436789767 -0.0707985731221 ... -1.05419803797 6.35698426189 11 0.140700250477 0.620401487202 ... -1.20161076793 3.4253301593 11 0.461296492351 0.14354323987 ... -1.73934077971 4.70926070322 11.5 1.35798282982 0.38564694435 ... -1.71735262584 3.54232079749 12.5 2.9097529155 -0.804308583301 ... -0.426343657844 3.32719108897 13 1.64214862652 -1.18214664701 ... -1.67751812324 2.93444727338 11.25 0.344434910651 -1.6529373719 ... -1.37013301099 4.72303361923 11.75 2.61511526582 0.327684243041 ... -0.281231073781 4.4893853071 10.5 1.17043449257 1.12855106649 ... -1.53638992834 3.7325309699 10.25 -0.683947046728 0.11943538737 ... -1.68081431462 3.34729969129 10 1.41159342106 -1.59065680853 ... --0.343321601133 5.05563513564 12 1.75117366498 -2.40127764642 ... -0.873415608666 3.2779996255 10.25 -1.39895866711 0.0971444398216 ... -0.26399696544 4.78229419828 9.75 0.0914692438124 0.299310457612 ... --0.562233624818 3.88598638237 9.75 -0.0505384765105 0.332826708151 ... -2.15161914936 3.84859710132 8.75 -3.44811080489 0.789138678784 ... -1.2345093726 5.62225030942 9.5 -0.366945407434 2.32974981198 ... -1.62554967459 4.24667132831 10 -0.800958371402 0.0293183770935 ... -1.33035402527 2.75248979249 9.75 -0.855723113225 0.852493939813 ... -1.52078814077 3.53415985826 9.75 -3.37963469203 -1.05133958119 ... -1.16704983697 4.92754079464 10.75 -3.0142303324 0.459907431978 ... -0.277213572101 4.55532133037 11.75 -0.851995599415 2.03242034852 ... -0.842215068977 3.11164509647 12.25 -1.08290421696 0.014323281961 ... -1.05325028606 4.92882647578 13.5 -1.1953883867 0.706764750654 ... -0.453051253568 6.82998950103 13.5 0.111803656462 0.088462593153 ... -0.199885995525 5.82643354662 13.5 -0.920501518421 -0.26504958666 ... -0.137907999624 2.66076369132 13.5 -1.17122929812 -0.995642430514 ... -0.721949686709 5.70497876823 14.25 1.19378169018 -1.10644839651 ... --0.418465249225 3.75861110232 14.75 -1.03131674824 0.188507675831 ... --0.644028342116 4.15104788154 13.75 -1.48911756546 0.204560913792 ... --0.848213852668 5.65580324027 12.75 0.677011703877 -0.849628054542 ... --1.51954076928 11.4866911266 11.25 -0.446024680774 -0.456342350765 ... -0.265275055215 2.85472749592 9.75 -0.598778202436 -0.907311640831 ... -0.356162529063 2.29614015658 9.5 -0.46820788432 -1.22130883441 ... -0.368308864363 -0.539083504685 8 -0.781333991956 0.374007246518 ... --0.145751412732 1.61507621789 8.25 3.68291932628 1.32438399845 ... -0.285457283664 2.14334055993 7 1.42819405379 -0.00818660844123 ... -0.372390129412 1.60000213334 6.25 0.626106424052 -0.10136772765 ... -0.382720203063 1.72614243263 7.25 4.89631941021 -1.10060711916 ... -0.737957515573 2.90430582851 6 -0.0422721010314 0.4178952497 ... -0.649532581668 0.657135682543 6 0.692066153971 0.422299120276 ... -0.627159201987 1.70352689913 5.75 2.62066711305 -1.29237304034 ... -0.905441299817 1.95663197267 5.5 1.5949697565 -0.27115830703 ... -1.49322577898 -2.08741765309 6.25 1.23027694802 0.418336889527 ... -1.48750731567 -1.57274121871 8 3.01660550994 -0.893958254365 ... -1.39783858087 2.22623066426 7 -0.80842319214 1.47625453886 ... -0.89274836317 1.30378081742 8 -0.249485058661 0.159871204185 ... -0.920652246088 4.1437741965 9.75 2.8204453623 0.178149239655 ... --0.00264276644799 3.07989972052 8.75 -2.56342461535 2.105998353 ... -0.0198190461681 0.766283759256 8 -1.15838865989 1.56888883418 ... -0.440050515311 0.127570085801 7.5 0.0400753569995 0.028914333532 ... -0.129536637901 1.78174141526 6.75 0.959943962785 0.307781224401 ... -0.398549827172 3.03606770667 6.5 -0.340209794742 0.100979469478 ... -1.17174775425 0.629625188037 5.75 0.403003686814 0.902394579377 ... -0.991163981251 2.50862910684 4.75 -1.44963996982 1.16150986945 ... -0.967603566096 2.12003739013 4.75 0.610846030775 -0.889994896068 ... -1.14689383604 1.24185011459 4.75 2.01098091308 -1.73846431001 ... -1.32593824054 0.990713820685 4.75 -0.0955142989332 -0.0369257308362 ... -0.861135002644 -0.24744943605 6 1.72793107135 -0.691506789639 ... -1.26870850151 2.09844764887 6.5 1.50720217572 -1.31399187077 ... -0.260364987715 1.10650139716 6.5 1.13659047496 0.0720441664643 ... -1.09731242214 0.490796381346 7.25 4.59123894147 -2.14073070763 ... -1.63792841781 0.612652594286 6.75 1.79604605035 -0.644363995357 ... -1.48465576034 0.978295808687 6.75 -2.00753620902 1.39437534964 ... -1.0987608663 4.25212569087 6.25 -2.58901196498 2.56054320803 ... -1.42592178132 2.76984518311 6.25 0.888195752358 1.03114549274 ... -1.52958239462 1.31795955491 6.5 -0.902907564082 -0.0952198893776 ... -1.0170168994 2.14733589918 7 -1.3054866978 2.68803738466 ... -0.723253652257 3.43552889347 7.5 1.8213700853 0.592593586195 ... -1.24720806008 3.87383806577 7.5 0.0522300654168 0.988871238698 ... -0.482531471239 2.67793287032 7.5 2.9693944293 -0.108591166081 ... -0.154056100439 0.927269031704 6.75 0.119222057561 3.30489209451 ... -0.0694865769274 6.65916526788 6.25 0.889014476084 -2.83976849035 ... --0.121267434867 0.341442615696 5.25 0.323053239216 -3.49289229012 ... -0.726473690375 -3.5423730964 4 2.19149290449 -3.20855054004 ... -1.39271709108 2.63121085718 3.75 0.88406577736 0.75622580197 ... -1.07502077727 5.88578836799 4.25 -2.55088273352 2.89018116374 ... -0.759049251607 4.24703604223 4.5 0.575687665685 -0.388292506167 ... -]; - + -0.705994063083 11.7522582094 21.25 1.09254424511 -1.29488274994 ... + -0.511895351926 9.68144025625 17.25 -1.66150408407 0.331508393098 ... + -0.990955971267 10.0890781236 17 1.43016275252 -2.43589670141 ... + -0.981233061806 12.1094840679 18.25 2.91293288733 -0.790246576864 ... + -0.882182844512 8.54559460406 15 0.419579139481 0.358729719566 ... + -0.930893002836 6.19238374422 12.5 -1.48847457959 0.739779938797 ... + 1.53158206947 2.76544271886 11.5 -0.336216769682 0.455559918769 ... + 2.2659052834 5.47418162513 11 0.306436789767 -0.0707985731221 ... + 1.05419803797 6.35698426189 11 0.140700250477 0.620401487202 ... + 1.20161076793 3.4253301593 11 0.461296492351 0.14354323987 ... + 1.73934077971 4.70926070322 11.5 1.35798282982 0.38564694435 ... + 1.71735262584 3.54232079749 12.5 2.9097529155 -0.804308583301 ... + 0.426343657844 3.32719108897 13 1.64214862652 -1.18214664701 ... + 1.67751812324 2.93444727338 11.25 0.344434910651 -1.6529373719 ... + 1.37013301099 4.72303361923 11.75 2.61511526582 0.327684243041 ... + 0.281231073781 4.4893853071 10.5 1.17043449257 1.12855106649 ... + 1.53638992834 3.7325309699 10.25 -0.683947046728 0.11943538737 ... + 1.68081431462 3.34729969129 10 1.41159342106 -1.59065680853 ... + -0.343321601133 5.05563513564 12 1.75117366498 -2.40127764642 ... + 0.873415608666 3.2779996255 10.25 -1.39895866711 0.0971444398216 ... + 0.26399696544 4.78229419828 9.75 0.0914692438124 0.299310457612 ... + -0.562233624818 3.88598638237 9.75 -0.0505384765105 0.332826708151 ... + 2.15161914936 3.84859710132 8.75 -3.44811080489 0.789138678784 ... + 1.2345093726 5.62225030942 9.5 -0.366945407434 2.32974981198 ... + 1.62554967459 4.24667132831 10 -0.800958371402 0.0293183770935 ... + 1.33035402527 2.75248979249 9.75 -0.855723113225 0.852493939813 ... + 1.52078814077 3.53415985826 9.75 -3.37963469203 -1.05133958119 ... + 1.16704983697 4.92754079464 10.75 -3.0142303324 0.459907431978 ... + 0.277213572101 4.55532133037 11.75 -0.851995599415 2.03242034852 ... + 0.842215068977 3.11164509647 12.25 -1.08290421696 0.014323281961 ... + 1.05325028606 4.92882647578 13.5 -1.1953883867 0.706764750654 ... + 0.453051253568 6.82998950103 13.5 0.111803656462 0.088462593153 ... + 0.199885995525 5.82643354662 13.5 -0.920501518421 -0.26504958666 ... + 0.137907999624 2.66076369132 13.5 -1.17122929812 -0.995642430514 ... + 0.721949686709 5.70497876823 14.25 1.19378169018 -1.10644839651 ... + -0.418465249225 3.75861110232 14.75 -1.03131674824 0.188507675831 ... + -0.644028342116 4.15104788154 13.75 -1.48911756546 0.204560913792 ... + -0.848213852668 5.65580324027 12.75 0.677011703877 -0.849628054542 ... + -1.51954076928 11.4866911266 11.25 -0.446024680774 -0.456342350765 ... + 0.265275055215 2.85472749592 9.75 -0.598778202436 -0.907311640831 ... + 0.356162529063 2.29614015658 9.5 -0.46820788432 -1.22130883441 ... + 0.368308864363 -0.539083504685 8 -0.781333991956 0.374007246518 ... + -0.145751412732 1.61507621789 8.25 3.68291932628 1.32438399845 ... + 0.285457283664 2.14334055993 7 1.42819405379 -0.00818660844123 ... + 0.372390129412 1.60000213334 6.25 0.626106424052 -0.10136772765 ... + 0.382720203063 1.72614243263 7.25 4.89631941021 -1.10060711916 ... + 0.737957515573 2.90430582851 6 -0.0422721010314 0.4178952497 ... + 0.649532581668 0.657135682543 6 0.692066153971 0.422299120276 ... + 0.627159201987 1.70352689913 5.75 2.62066711305 -1.29237304034 ... + 0.905441299817 1.95663197267 5.5 1.5949697565 -0.27115830703 ... + 1.49322577898 -2.08741765309 6.25 1.23027694802 0.418336889527 ... + 1.48750731567 -1.57274121871 8 3.01660550994 -0.893958254365 ... + 1.39783858087 2.22623066426 7 -0.80842319214 1.47625453886 ... + 0.89274836317 1.30378081742 8 -0.249485058661 0.159871204185 ... + 0.920652246088 4.1437741965 9.75 2.8204453623 0.178149239655 ... + -0.00264276644799 3.07989972052 8.75 -2.56342461535 2.105998353 ... + 0.0198190461681 0.766283759256 8 -1.15838865989 1.56888883418 ... + 0.440050515311 0.127570085801 7.5 0.0400753569995 0.028914333532 ... + 0.129536637901 1.78174141526 6.75 0.959943962785 0.307781224401 ... + 0.398549827172 3.03606770667 6.5 -0.340209794742 0.100979469478 ... + 1.17174775425 0.629625188037 5.75 0.403003686814 0.902394579377 ... + 0.991163981251 2.50862910684 4.75 -1.44963996982 1.16150986945 ... + 0.967603566096 2.12003739013 4.75 0.610846030775 -0.889994896068 ... + 1.14689383604 1.24185011459 4.75 2.01098091308 -1.73846431001 ... + 1.32593824054 0.990713820685 4.75 -0.0955142989332 -0.0369257308362 ... + 0.861135002644 -0.24744943605 6 1.72793107135 -0.691506789639 ... + 1.26870850151 2.09844764887 6.5 1.50720217572 -1.31399187077 ... + 0.260364987715 1.10650139716 6.5 1.13659047496 0.0720441664643 ... + 1.09731242214 0.490796381346 7.25 4.59123894147 -2.14073070763 ... + 1.63792841781 0.612652594286 6.75 1.79604605035 -0.644363995357 ... + 1.48465576034 0.978295808687 6.75 -2.00753620902 1.39437534964 ... + 1.0987608663 4.25212569087 6.25 -2.58901196498 2.56054320803 ... + 1.42592178132 2.76984518311 6.25 0.888195752358 1.03114549274 ... + 1.52958239462 1.31795955491 6.5 -0.902907564082 -0.0952198893776 ... + 1.0170168994 2.14733589918 7 -1.3054866978 2.68803738466 ... + 0.723253652257 3.43552889347 7.5 1.8213700853 0.592593586195 ... + 1.24720806008 3.87383806577 7.5 0.0522300654168 0.988871238698 ... + 0.482531471239 2.67793287032 7.5 2.9693944293 -0.108591166081 ... + 0.154056100439 0.927269031704 6.75 0.119222057561 3.30489209451 ... + 0.0694865769274 6.65916526788 6.25 0.889014476084 -2.83976849035 ... + -0.121267434867 0.341442615696 5.25 0.323053239216 -3.49289229012 ... + 0.726473690375 -3.5423730964 4 2.19149290449 -3.20855054004 ... + 1.39271709108 2.63121085718 3.75 0.88406577736 0.75622580197 ... + 1.07502077727 5.88578836799 4.25 -2.55088273352 2.89018116374 ... + 0.759049251607 4.24703604223 4.5 0.575687665685 -0.388292506167 ... + ]; + data = reshape(data,5,86)'; y_obs = data(:,1); pie_obs = data(:,2); R_obs = data(:,3); de = data(:,4); dq = data(:,5); - + %Country: Canada %Sample Range: 1981:2 to 2002:3 %Observations: 86 diff --git a/tests/measurement_errors/data_ca1.m b/tests/measurement_errors/data_ca1.m index c28fae1a28..ca003056bd 100644 --- a/tests/measurement_errors/data_ca1.m +++ b/tests/measurement_errors/data_ca1.m @@ -1,98 +1,98 @@ data = [0.928467646476 11.8716889412 20 0.418037507392 0.227382377518 ... --0.705994063083 11.7522582094 21.25 1.09254424511 -1.29488274994 ... --0.511895351926 9.68144025625 17.25 -1.66150408407 0.331508393098 ... --0.990955971267 10.0890781236 17 1.43016275252 -2.43589670141 ... --0.981233061806 12.1094840679 18.25 2.91293288733 -0.790246576864 ... --0.882182844512 8.54559460406 15 0.419579139481 0.358729719566 ... --0.930893002836 6.19238374422 12.5 -1.48847457959 0.739779938797 ... -1.53158206947 2.76544271886 11.5 -0.336216769682 0.455559918769 ... -2.2659052834 5.47418162513 11 0.306436789767 -0.0707985731221 ... -1.05419803797 6.35698426189 11 0.140700250477 0.620401487202 ... -1.20161076793 3.4253301593 11 0.461296492351 0.14354323987 ... -1.73934077971 4.70926070322 11.5 1.35798282982 0.38564694435 ... -1.71735262584 3.54232079749 12.5 2.9097529155 -0.804308583301 ... -0.426343657844 3.32719108897 13 1.64214862652 -1.18214664701 ... -1.67751812324 2.93444727338 11.25 0.344434910651 -1.6529373719 ... -1.37013301099 4.72303361923 11.75 2.61511526582 0.327684243041 ... -0.281231073781 4.4893853071 10.5 1.17043449257 1.12855106649 ... -1.53638992834 3.7325309699 10.25 -0.683947046728 0.11943538737 ... -1.68081431462 3.34729969129 10 1.41159342106 -1.59065680853 ... --0.343321601133 5.05563513564 12 1.75117366498 -2.40127764642 ... -0.873415608666 3.2779996255 10.25 -1.39895866711 0.0971444398216 ... -0.26399696544 4.78229419828 9.75 0.0914692438124 0.299310457612 ... --0.562233624818 3.88598638237 9.75 -0.0505384765105 0.332826708151 ... -2.15161914936 3.84859710132 8.75 -3.44811080489 0.789138678784 ... -1.2345093726 5.62225030942 9.5 -0.366945407434 2.32974981198 ... -1.62554967459 4.24667132831 10 -0.800958371402 0.0293183770935 ... -1.33035402527 2.75248979249 9.75 -0.855723113225 0.852493939813 ... -1.52078814077 3.53415985826 9.75 -3.37963469203 -1.05133958119 ... -1.16704983697 4.92754079464 10.75 -3.0142303324 0.459907431978 ... -0.277213572101 4.55532133037 11.75 -0.851995599415 2.03242034852 ... -0.842215068977 3.11164509647 12.25 -1.08290421696 0.014323281961 ... -1.05325028606 4.92882647578 13.5 -1.1953883867 0.706764750654 ... -0.453051253568 6.82998950103 13.5 0.111803656462 0.088462593153 ... -0.199885995525 5.82643354662 13.5 -0.920501518421 -0.26504958666 ... -0.137907999624 2.66076369132 13.5 -1.17122929812 -0.995642430514 ... -0.721949686709 5.70497876823 14.25 1.19378169018 -1.10644839651 ... --0.418465249225 3.75861110232 14.75 -1.03131674824 0.188507675831 ... --0.644028342116 4.15104788154 13.75 -1.48911756546 0.204560913792 ... --0.848213852668 5.65580324027 12.75 0.677011703877 -0.849628054542 ... --1.51954076928 11.4866911266 11.25 -0.446024680774 -0.456342350765 ... -0.265275055215 2.85472749592 9.75 -0.598778202436 -0.907311640831 ... -0.356162529063 2.29614015658 9.5 -0.46820788432 -1.22130883441 ... -0.368308864363 -0.539083504685 8 -0.781333991956 0.374007246518 ... --0.145751412732 1.61507621789 8.25 3.68291932628 1.32438399845 ... -0.285457283664 2.14334055993 7 1.42819405379 -0.00818660844123 ... -0.372390129412 1.60000213334 6.25 0.626106424052 -0.10136772765 ... -0.382720203063 1.72614243263 7.25 4.89631941021 -1.10060711916 ... -0.737957515573 2.90430582851 6 -0.0422721010314 0.4178952497 ... -0.649532581668 0.657135682543 6 0.692066153971 0.422299120276 ... -0.627159201987 1.70352689913 5.75 2.62066711305 -1.29237304034 ... -0.905441299817 1.95663197267 5.5 1.5949697565 -0.27115830703 ... -1.49322577898 -2.08741765309 6.25 1.23027694802 0.418336889527 ... -1.48750731567 -1.57274121871 8 3.01660550994 -0.893958254365 ... -1.39783858087 2.22623066426 7 -0.80842319214 1.47625453886 ... -0.89274836317 1.30378081742 8 -0.249485058661 0.159871204185 ... -0.920652246088 4.1437741965 9.75 2.8204453623 0.178149239655 ... --0.00264276644799 3.07989972052 8.75 -2.56342461535 2.105998353 ... -0.0198190461681 0.766283759256 8 -1.15838865989 1.56888883418 ... -0.440050515311 0.127570085801 7.5 0.0400753569995 0.028914333532 ... -0.129536637901 1.78174141526 6.75 0.959943962785 0.307781224401 ... -0.398549827172 3.03606770667 6.5 -0.340209794742 0.100979469478 ... -1.17174775425 0.629625188037 5.75 0.403003686814 0.902394579377 ... -0.991163981251 2.50862910684 4.75 -1.44963996982 1.16150986945 ... -0.967603566096 2.12003739013 4.75 0.610846030775 -0.889994896068 ... -1.14689383604 1.24185011459 4.75 2.01098091308 -1.73846431001 ... -1.32593824054 0.990713820685 4.75 -0.0955142989332 -0.0369257308362 ... -0.861135002644 -0.24744943605 6 1.72793107135 -0.691506789639 ... -1.26870850151 2.09844764887 6.5 1.50720217572 -1.31399187077 ... -0.260364987715 1.10650139716 6.5 1.13659047496 0.0720441664643 ... -1.09731242214 0.490796381346 7.25 4.59123894147 -2.14073070763 ... -1.63792841781 0.612652594286 6.75 1.79604605035 -0.644363995357 ... -1.48465576034 0.978295808687 6.75 -2.00753620902 1.39437534964 ... -1.0987608663 4.25212569087 6.25 -2.58901196498 2.56054320803 ... -1.42592178132 2.76984518311 6.25 0.888195752358 1.03114549274 ... -1.52958239462 1.31795955491 6.5 -0.902907564082 -0.0952198893776 ... -1.0170168994 2.14733589918 7 -1.3054866978 2.68803738466 ... -0.723253652257 3.43552889347 7.5 1.8213700853 0.592593586195 ... -1.24720806008 3.87383806577 7.5 0.0522300654168 0.988871238698 ... -0.482531471239 2.67793287032 7.5 2.9693944293 -0.108591166081 ... -0.154056100439 0.927269031704 6.75 0.119222057561 3.30489209451 ... -0.0694865769274 6.65916526788 6.25 0.889014476084 -2.83976849035 ... --0.121267434867 0.341442615696 5.25 0.323053239216 -3.49289229012 ... -0.726473690375 -3.5423730964 4 2.19149290449 -3.20855054004 ... -1.39271709108 2.63121085718 3.75 0.88406577736 0.75622580197 ... -1.07502077727 5.88578836799 4.25 -2.55088273352 2.89018116374 ... -0.759049251607 4.24703604223 4.5 0.575687665685 -0.388292506167 ... -]; - + -0.705994063083 11.7522582094 21.25 1.09254424511 -1.29488274994 ... + -0.511895351926 9.68144025625 17.25 -1.66150408407 0.331508393098 ... + -0.990955971267 10.0890781236 17 1.43016275252 -2.43589670141 ... + -0.981233061806 12.1094840679 18.25 2.91293288733 -0.790246576864 ... + -0.882182844512 8.54559460406 15 0.419579139481 0.358729719566 ... + -0.930893002836 6.19238374422 12.5 -1.48847457959 0.739779938797 ... + 1.53158206947 2.76544271886 11.5 -0.336216769682 0.455559918769 ... + 2.2659052834 5.47418162513 11 0.306436789767 -0.0707985731221 ... + 1.05419803797 6.35698426189 11 0.140700250477 0.620401487202 ... + 1.20161076793 3.4253301593 11 0.461296492351 0.14354323987 ... + 1.73934077971 4.70926070322 11.5 1.35798282982 0.38564694435 ... + 1.71735262584 3.54232079749 12.5 2.9097529155 -0.804308583301 ... + 0.426343657844 3.32719108897 13 1.64214862652 -1.18214664701 ... + 1.67751812324 2.93444727338 11.25 0.344434910651 -1.6529373719 ... + 1.37013301099 4.72303361923 11.75 2.61511526582 0.327684243041 ... + 0.281231073781 4.4893853071 10.5 1.17043449257 1.12855106649 ... + 1.53638992834 3.7325309699 10.25 -0.683947046728 0.11943538737 ... + 1.68081431462 3.34729969129 10 1.41159342106 -1.59065680853 ... + -0.343321601133 5.05563513564 12 1.75117366498 -2.40127764642 ... + 0.873415608666 3.2779996255 10.25 -1.39895866711 0.0971444398216 ... + 0.26399696544 4.78229419828 9.75 0.0914692438124 0.299310457612 ... + -0.562233624818 3.88598638237 9.75 -0.0505384765105 0.332826708151 ... + 2.15161914936 3.84859710132 8.75 -3.44811080489 0.789138678784 ... + 1.2345093726 5.62225030942 9.5 -0.366945407434 2.32974981198 ... + 1.62554967459 4.24667132831 10 -0.800958371402 0.0293183770935 ... + 1.33035402527 2.75248979249 9.75 -0.855723113225 0.852493939813 ... + 1.52078814077 3.53415985826 9.75 -3.37963469203 -1.05133958119 ... + 1.16704983697 4.92754079464 10.75 -3.0142303324 0.459907431978 ... + 0.277213572101 4.55532133037 11.75 -0.851995599415 2.03242034852 ... + 0.842215068977 3.11164509647 12.25 -1.08290421696 0.014323281961 ... + 1.05325028606 4.92882647578 13.5 -1.1953883867 0.706764750654 ... + 0.453051253568 6.82998950103 13.5 0.111803656462 0.088462593153 ... + 0.199885995525 5.82643354662 13.5 -0.920501518421 -0.26504958666 ... + 0.137907999624 2.66076369132 13.5 -1.17122929812 -0.995642430514 ... + 0.721949686709 5.70497876823 14.25 1.19378169018 -1.10644839651 ... + -0.418465249225 3.75861110232 14.75 -1.03131674824 0.188507675831 ... + -0.644028342116 4.15104788154 13.75 -1.48911756546 0.204560913792 ... + -0.848213852668 5.65580324027 12.75 0.677011703877 -0.849628054542 ... + -1.51954076928 11.4866911266 11.25 -0.446024680774 -0.456342350765 ... + 0.265275055215 2.85472749592 9.75 -0.598778202436 -0.907311640831 ... + 0.356162529063 2.29614015658 9.5 -0.46820788432 -1.22130883441 ... + 0.368308864363 -0.539083504685 8 -0.781333991956 0.374007246518 ... + -0.145751412732 1.61507621789 8.25 3.68291932628 1.32438399845 ... + 0.285457283664 2.14334055993 7 1.42819405379 -0.00818660844123 ... + 0.372390129412 1.60000213334 6.25 0.626106424052 -0.10136772765 ... + 0.382720203063 1.72614243263 7.25 4.89631941021 -1.10060711916 ... + 0.737957515573 2.90430582851 6 -0.0422721010314 0.4178952497 ... + 0.649532581668 0.657135682543 6 0.692066153971 0.422299120276 ... + 0.627159201987 1.70352689913 5.75 2.62066711305 -1.29237304034 ... + 0.905441299817 1.95663197267 5.5 1.5949697565 -0.27115830703 ... + 1.49322577898 -2.08741765309 6.25 1.23027694802 0.418336889527 ... + 1.48750731567 -1.57274121871 8 3.01660550994 -0.893958254365 ... + 1.39783858087 2.22623066426 7 -0.80842319214 1.47625453886 ... + 0.89274836317 1.30378081742 8 -0.249485058661 0.159871204185 ... + 0.920652246088 4.1437741965 9.75 2.8204453623 0.178149239655 ... + -0.00264276644799 3.07989972052 8.75 -2.56342461535 2.105998353 ... + 0.0198190461681 0.766283759256 8 -1.15838865989 1.56888883418 ... + 0.440050515311 0.127570085801 7.5 0.0400753569995 0.028914333532 ... + 0.129536637901 1.78174141526 6.75 0.959943962785 0.307781224401 ... + 0.398549827172 3.03606770667 6.5 -0.340209794742 0.100979469478 ... + 1.17174775425 0.629625188037 5.75 0.403003686814 0.902394579377 ... + 0.991163981251 2.50862910684 4.75 -1.44963996982 1.16150986945 ... + 0.967603566096 2.12003739013 4.75 0.610846030775 -0.889994896068 ... + 1.14689383604 1.24185011459 4.75 2.01098091308 -1.73846431001 ... + 1.32593824054 0.990713820685 4.75 -0.0955142989332 -0.0369257308362 ... + 0.861135002644 -0.24744943605 6 1.72793107135 -0.691506789639 ... + 1.26870850151 2.09844764887 6.5 1.50720217572 -1.31399187077 ... + 0.260364987715 1.10650139716 6.5 1.13659047496 0.0720441664643 ... + 1.09731242214 0.490796381346 7.25 4.59123894147 -2.14073070763 ... + 1.63792841781 0.612652594286 6.75 1.79604605035 -0.644363995357 ... + 1.48465576034 0.978295808687 6.75 -2.00753620902 1.39437534964 ... + 1.0987608663 4.25212569087 6.25 -2.58901196498 2.56054320803 ... + 1.42592178132 2.76984518311 6.25 0.888195752358 1.03114549274 ... + 1.52958239462 1.31795955491 6.5 -0.902907564082 -0.0952198893776 ... + 1.0170168994 2.14733589918 7 -1.3054866978 2.68803738466 ... + 0.723253652257 3.43552889347 7.5 1.8213700853 0.592593586195 ... + 1.24720806008 3.87383806577 7.5 0.0522300654168 0.988871238698 ... + 0.482531471239 2.67793287032 7.5 2.9693944293 -0.108591166081 ... + 0.154056100439 0.927269031704 6.75 0.119222057561 3.30489209451 ... + 0.0694865769274 6.65916526788 6.25 0.889014476084 -2.83976849035 ... + -0.121267434867 0.341442615696 5.25 0.323053239216 -3.49289229012 ... + 0.726473690375 -3.5423730964 4 2.19149290449 -3.20855054004 ... + 1.39271709108 2.63121085718 3.75 0.88406577736 0.75622580197 ... + 1.07502077727 5.88578836799 4.25 -2.55088273352 2.89018116374 ... + 0.759049251607 4.24703604223 4.5 0.575687665685 -0.388292506167 ... + ]; + data = reshape(data,5,86)'; y_obs = data(:,1); pie_obs = data(:,2); R_obs = data(:,3); de = data(:,4); dq = data(:,5); - + %Country: Canada %Sample Range: 1981:2 to 2002:3 %Observations: 86 diff --git a/tests/measurement_errors/fs2000_corr_me_ml_mcmc/fsdat_simul.m b/tests/measurement_errors/fs2000_corr_me_ml_mcmc/fsdat_simul.m index 56c0e4cd56..f6ad30c85b 100644 --- a/tests/measurement_errors/fs2000_corr_me_ml_mcmc/fsdat_simul.m +++ b/tests/measurement_errors/fs2000_corr_me_ml_mcmc/fsdat_simul.m @@ -1,416 +1,416 @@ % Generated data, used by fs2000.mod gy_obs =[ - 1.0030045 - 1.0002599 - 0.99104664 - 1.0321162 - 1.0223545 - 1.0043614 - 0.98626929 - 1.0092127 - 1.0357197 - 1.0150827 - 1.0051548 - 0.98465775 - 0.99132132 - 0.99904153 - 1.0044641 - 1.0179198 - 1.0113462 - 0.99409421 - 0.99904293 - 1.0448336 - 0.99932433 - 1.0057004 - 0.99619787 - 1.0267504 - 1.0077645 - 1.0058026 - 1.0025891 - 0.9939097 - 0.99604693 - 0.99908569 - 1.0151094 - 0.99348134 - 1.0039124 - 1.0145805 - 0.99800868 - 0.98578138 - 1.0065771 - 0.99843919 - 0.97979062 - 0.98413351 - 0.96468174 - 1.0273857 - 1.0225211 - 0.99958667 - 1.0111157 - 1.0099585 - 0.99480311 - 1.0079265 - 0.98924573 - 1.0070613 - 1.0075706 - 0.9937151 - 1.0224711 - 1.0018891 - 0.99051863 - 1.0042944 - 1.0184055 - 0.99419508 - 0.99756624 - 1.0015983 - 0.9845772 - 1.0004407 - 1.0116237 - 0.9861885 - 1.0073094 - 0.99273355 - 1.0013224 - 0.99777979 - 1.0301686 - 0.96809556 - 0.99917088 - 0.99949253 - 0.96590004 - 1.0083938 - 0.96662298 - 1.0221454 - 1.0069792 - 1.0343996 - 1.0066531 - 1.0072525 - 0.99743563 - 0.99723703 - 1.000372 - 0.99013917 - 1.0095223 - 0.98864268 - 0.98092242 - 0.98886488 - 1.0030341 - 1.01894 - 0.99155059 - 0.99533235 - 0.99734316 - 1.0047356 - 1.0082737 - 0.98425116 - 0.99949212 - 1.0055899 - 1.0065075 - 0.99385069 - 0.98867975 - 0.99804843 - 1.0184038 - 0.99301902 - 1.0177222 - 1.0051924 - 1.0187852 - 1.0098985 - 1.0097172 - 1.0145811 - 0.98721038 - 1.0361722 - 1.0105821 - 0.99469309 - 0.98626785 - 1.013871 - 0.99858924 - 0.99302637 - 1.0042186 - 0.99623745 - 0.98545708 - 1.0225435 - 1.0011861 - 1.0130321 - 0.97861347 - 1.0228193 - 0.99627435 - 1.0272779 - 1.0075172 - 1.0096762 - 1.0129306 - 0.99966549 - 1.0262882 - 1.0026914 - 1.0061475 - 1.009523 - 1.0036127 - 0.99762992 - 0.99092634 - 1.0058469 - 0.99887292 - 1.0060653 - 0.98673557 - 0.98895709 - 0.99111967 - 0.990118 - 0.99788054 - 0.97054709 - 1.0099157 - 1.0107431 - 0.99518695 - 1.0114048 - 0.99376019 - 1.0023369 - 0.98783327 - 1.0051727 - 1.0100462 - 0.98607387 - 1.0000064 - 0.99692442 - 1.012225 - 0.99574078 - 0.98642833 - 0.99008207 - 1.0197359 - 1.0112849 - 0.98711069 - 0.99402748 - 1.0242141 - 1.0135349 - 0.99842505 - 1.0130714 - 0.99887044 - 1.0059058 - 1.0185998 - 1.0073314 - 0.98687706 - 1.0084551 - 0.97698964 - 0.99482714 - 1.0015302 - 1.0105331 - 1.0261767 - 1.0232822 - 1.0084176 - 0.99785167 - 0.99619733 - 1.0055223 - 1.0076326 - 0.99205461 - 1.0030587 - 1.0137012 - 1.0145878 - 1.0190297 - 1.0000681 - 1.0153894 - 1.0140649 - 1.0007236 - 0.97961463 - 1.0125257 - 1.0169503 - 1.0197363 - 1.0221185 + 1.0030045 + 1.0002599 + 0.99104664 + 1.0321162 + 1.0223545 + 1.0043614 + 0.98626929 + 1.0092127 + 1.0357197 + 1.0150827 + 1.0051548 + 0.98465775 + 0.99132132 + 0.99904153 + 1.0044641 + 1.0179198 + 1.0113462 + 0.99409421 + 0.99904293 + 1.0448336 + 0.99932433 + 1.0057004 + 0.99619787 + 1.0267504 + 1.0077645 + 1.0058026 + 1.0025891 + 0.9939097 + 0.99604693 + 0.99908569 + 1.0151094 + 0.99348134 + 1.0039124 + 1.0145805 + 0.99800868 + 0.98578138 + 1.0065771 + 0.99843919 + 0.97979062 + 0.98413351 + 0.96468174 + 1.0273857 + 1.0225211 + 0.99958667 + 1.0111157 + 1.0099585 + 0.99480311 + 1.0079265 + 0.98924573 + 1.0070613 + 1.0075706 + 0.9937151 + 1.0224711 + 1.0018891 + 0.99051863 + 1.0042944 + 1.0184055 + 0.99419508 + 0.99756624 + 1.0015983 + 0.9845772 + 1.0004407 + 1.0116237 + 0.9861885 + 1.0073094 + 0.99273355 + 1.0013224 + 0.99777979 + 1.0301686 + 0.96809556 + 0.99917088 + 0.99949253 + 0.96590004 + 1.0083938 + 0.96662298 + 1.0221454 + 1.0069792 + 1.0343996 + 1.0066531 + 1.0072525 + 0.99743563 + 0.99723703 + 1.000372 + 0.99013917 + 1.0095223 + 0.98864268 + 0.98092242 + 0.98886488 + 1.0030341 + 1.01894 + 0.99155059 + 0.99533235 + 0.99734316 + 1.0047356 + 1.0082737 + 0.98425116 + 0.99949212 + 1.0055899 + 1.0065075 + 0.99385069 + 0.98867975 + 0.99804843 + 1.0184038 + 0.99301902 + 1.0177222 + 1.0051924 + 1.0187852 + 1.0098985 + 1.0097172 + 1.0145811 + 0.98721038 + 1.0361722 + 1.0105821 + 0.99469309 + 0.98626785 + 1.013871 + 0.99858924 + 0.99302637 + 1.0042186 + 0.99623745 + 0.98545708 + 1.0225435 + 1.0011861 + 1.0130321 + 0.97861347 + 1.0228193 + 0.99627435 + 1.0272779 + 1.0075172 + 1.0096762 + 1.0129306 + 0.99966549 + 1.0262882 + 1.0026914 + 1.0061475 + 1.009523 + 1.0036127 + 0.99762992 + 0.99092634 + 1.0058469 + 0.99887292 + 1.0060653 + 0.98673557 + 0.98895709 + 0.99111967 + 0.990118 + 0.99788054 + 0.97054709 + 1.0099157 + 1.0107431 + 0.99518695 + 1.0114048 + 0.99376019 + 1.0023369 + 0.98783327 + 1.0051727 + 1.0100462 + 0.98607387 + 1.0000064 + 0.99692442 + 1.012225 + 0.99574078 + 0.98642833 + 0.99008207 + 1.0197359 + 1.0112849 + 0.98711069 + 0.99402748 + 1.0242141 + 1.0135349 + 0.99842505 + 1.0130714 + 0.99887044 + 1.0059058 + 1.0185998 + 1.0073314 + 0.98687706 + 1.0084551 + 0.97698964 + 0.99482714 + 1.0015302 + 1.0105331 + 1.0261767 + 1.0232822 + 1.0084176 + 0.99785167 + 0.99619733 + 1.0055223 + 1.0076326 + 0.99205461 + 1.0030587 + 1.0137012 + 1.0145878 + 1.0190297 + 1.0000681 + 1.0153894 + 1.0140649 + 1.0007236 + 0.97961463 + 1.0125257 + 1.0169503 + 1.0197363 + 1.0221185 -]; + ]; gp_obs =[ - 1.0079715 - 1.0115853 - 1.0167502 - 1.0068957 - 1.0138189 - 1.0258364 - 1.0243817 - 1.017373 - 1.0020171 - 1.0003742 - 1.0008974 - 1.0104804 - 1.0116393 - 1.0114294 - 0.99932124 - 0.99461459 - 1.0170349 - 1.0051446 - 1.020639 - 1.0051964 - 1.0093042 - 1.007068 - 1.01086 - 0.99590086 - 1.0014883 - 1.0117332 - 0.9990095 - 1.0108284 - 1.0103672 - 1.0036722 - 1.0005124 - 1.0190331 - 1.0130978 - 1.007842 - 1.0285436 - 1.0322054 - 1.0213403 - 1.0246486 - 1.0419306 - 1.0258867 - 1.0156316 - 0.99818589 - 0.9894107 - 1.0127584 - 1.0146882 - 1.0136529 - 1.0340107 - 1.0343652 - 1.02971 - 1.0077932 - 1.0198114 - 1.013971 - 1.0061083 - 1.0089573 - 1.0037926 - 1.0082071 - 0.99498155 - 0.99735772 - 0.98765026 - 1.006465 - 1.0196088 - 1.0053233 - 1.0119974 - 1.0188066 - 1.0029302 - 1.0183459 - 1.0034218 - 1.0158799 - 0.98824798 - 1.0274357 - 1.0168832 - 1.0180641 - 1.0294657 - 0.98864091 - 1.0358326 - 0.99889969 - 1.0178322 - 0.99813566 - 1.0073549 - 1.0215985 - 1.0084245 - 1.0080939 - 1.0157021 - 1.0075815 - 1.0032633 - 1.0117871 - 1.0209276 - 1.0077569 - 0.99680958 - 1.0120266 - 1.0017625 - 1.0138811 - 1.0198358 - 1.0059629 - 1.0115416 - 1.0319473 - 1.0167074 - 1.0116111 - 1.0048627 - 1.0217622 - 1.0125221 - 1.0142045 - 0.99792469 - 0.99823971 - 0.99561547 - 0.99850373 - 0.9898464 - 1.0030963 - 1.0051373 - 1.0004213 - 1.0144117 - 0.97185592 - 0.9959518 - 1.0073529 - 1.0051603 - 0.98642572 - 0.99433423 - 1.0112131 - 1.0007695 - 1.0176867 - 1.0134363 - 0.99926191 - 0.99879835 - 0.99878754 - 1.0331374 - 1.0077797 - 1.0127221 - 1.0047393 - 1.0074106 - 0.99784213 - 1.0056495 - 1.0057708 - 0.98817494 - 0.98742176 - 0.99930555 - 1.0000687 - 1.0129754 - 1.009529 - 1.0226731 - 1.0149534 - 1.0164295 - 1.0239469 - 1.0293458 - 1.026199 - 1.0197525 - 1.0126818 - 1.0054473 - 1.0254423 - 1.0069461 - 1.0153135 - 1.0337515 - 1.0178187 - 1.0240469 - 1.0079489 - 1.0186953 - 1.0008628 - 1.0113799 - 1.0140118 - 1.0168007 - 1.011441 - 0.98422774 - 0.98909729 - 1.0157859 - 1.0151586 - 0.99756232 - 0.99497777 - 1.0102841 - 1.0221659 - 0.9937759 - 0.99877193 - 1.0079433 - 0.99667692 - 1.0095959 - 1.0128804 - 1.0156949 - 1.0111951 - 1.0228887 - 1.0122083 - 1.0190197 - 1.0074927 - 1.0268096 - 0.99689352 - 0.98948474 - 1.0024938 - 1.0105543 - 1.014116 - 1.0141217 - 1.0056504 - 1.0101026 - 1.0105069 - 0.99619053 - 1.0059439 - 0.99449473 - 0.99482458 - 1.0037702 - 1.0068087 - 0.99575975 - 1.0030815 - 1.0334014 - 0.99879386 - 0.99625634 - 1.0171195 - 0.99233844 + 1.0079715 + 1.0115853 + 1.0167502 + 1.0068957 + 1.0138189 + 1.0258364 + 1.0243817 + 1.017373 + 1.0020171 + 1.0003742 + 1.0008974 + 1.0104804 + 1.0116393 + 1.0114294 + 0.99932124 + 0.99461459 + 1.0170349 + 1.0051446 + 1.020639 + 1.0051964 + 1.0093042 + 1.007068 + 1.01086 + 0.99590086 + 1.0014883 + 1.0117332 + 0.9990095 + 1.0108284 + 1.0103672 + 1.0036722 + 1.0005124 + 1.0190331 + 1.0130978 + 1.007842 + 1.0285436 + 1.0322054 + 1.0213403 + 1.0246486 + 1.0419306 + 1.0258867 + 1.0156316 + 0.99818589 + 0.9894107 + 1.0127584 + 1.0146882 + 1.0136529 + 1.0340107 + 1.0343652 + 1.02971 + 1.0077932 + 1.0198114 + 1.013971 + 1.0061083 + 1.0089573 + 1.0037926 + 1.0082071 + 0.99498155 + 0.99735772 + 0.98765026 + 1.006465 + 1.0196088 + 1.0053233 + 1.0119974 + 1.0188066 + 1.0029302 + 1.0183459 + 1.0034218 + 1.0158799 + 0.98824798 + 1.0274357 + 1.0168832 + 1.0180641 + 1.0294657 + 0.98864091 + 1.0358326 + 0.99889969 + 1.0178322 + 0.99813566 + 1.0073549 + 1.0215985 + 1.0084245 + 1.0080939 + 1.0157021 + 1.0075815 + 1.0032633 + 1.0117871 + 1.0209276 + 1.0077569 + 0.99680958 + 1.0120266 + 1.0017625 + 1.0138811 + 1.0198358 + 1.0059629 + 1.0115416 + 1.0319473 + 1.0167074 + 1.0116111 + 1.0048627 + 1.0217622 + 1.0125221 + 1.0142045 + 0.99792469 + 0.99823971 + 0.99561547 + 0.99850373 + 0.9898464 + 1.0030963 + 1.0051373 + 1.0004213 + 1.0144117 + 0.97185592 + 0.9959518 + 1.0073529 + 1.0051603 + 0.98642572 + 0.99433423 + 1.0112131 + 1.0007695 + 1.0176867 + 1.0134363 + 0.99926191 + 0.99879835 + 0.99878754 + 1.0331374 + 1.0077797 + 1.0127221 + 1.0047393 + 1.0074106 + 0.99784213 + 1.0056495 + 1.0057708 + 0.98817494 + 0.98742176 + 0.99930555 + 1.0000687 + 1.0129754 + 1.009529 + 1.0226731 + 1.0149534 + 1.0164295 + 1.0239469 + 1.0293458 + 1.026199 + 1.0197525 + 1.0126818 + 1.0054473 + 1.0254423 + 1.0069461 + 1.0153135 + 1.0337515 + 1.0178187 + 1.0240469 + 1.0079489 + 1.0186953 + 1.0008628 + 1.0113799 + 1.0140118 + 1.0168007 + 1.011441 + 0.98422774 + 0.98909729 + 1.0157859 + 1.0151586 + 0.99756232 + 0.99497777 + 1.0102841 + 1.0221659 + 0.9937759 + 0.99877193 + 1.0079433 + 0.99667692 + 1.0095959 + 1.0128804 + 1.0156949 + 1.0111951 + 1.0228887 + 1.0122083 + 1.0190197 + 1.0074927 + 1.0268096 + 0.99689352 + 0.98948474 + 1.0024938 + 1.0105543 + 1.014116 + 1.0141217 + 1.0056504 + 1.0101026 + 1.0105069 + 0.99619053 + 1.0059439 + 0.99449473 + 0.99482458 + 1.0037702 + 1.0068087 + 0.99575975 + 1.0030815 + 1.0334014 + 0.99879386 + 0.99625634 + 1.0171195 + 0.99233844 -]; + ]; diff --git a/tests/ms-sbvar/archive-files/ftd_2s_caseall_upperchol3v.m b/tests/ms-sbvar/archive-files/ftd_2s_caseall_upperchol3v.m index ce6156c7b9..11a132b648 100644 --- a/tests/ms-sbvar/archive-files/ftd_2s_caseall_upperchol3v.m +++ b/tests/ms-sbvar/archive-files/ftd_2s_caseall_upperchol3v.m @@ -49,7 +49,7 @@ n0 = zeros(nvar,1); % ith element represents the number of free A0 parameters in np = zeros(nvar,1); % ith element represents the number of free D+ parameters in ith equation in all states. if (nargin==3) - nexo = 1; % 1: constant as default where nexo must be a nonnegative integer + nexo = 1; % 1: constant as default where nexo must be a nonnegative integer end @@ -59,10 +59,10 @@ k = kvar*nStates; % Maximum number of lagged and exogenous variables in each eq Qi = zeros(n,n,nvar); % 3rd dim: nvar contemporaneous equations. Ri = zeros(k,k,nvar); % 1st and 2nd dims: lagged and exogenous equations. - % Row corresponds to equation with nvar variables for state 1, ..., nvar variables for state nState. - % 0 means no restriction. - % 1 and -1 or any other number means the linear combination of the corresponding parameters is restricted to 0. - % 1 (only 1) means that the corresponding parameter is restricted to 0. + % Row corresponds to equation with nvar variables for state 1, ..., nvar variables for state nState. + % 0 means no restriction. + % 1 and -1 or any other number means the linear combination of the corresponding parameters is restricted to 0. + % 1 (only 1) means that the corresponding parameter is restricted to 0. %nfvar = 6; % number of foreign (Granger causing) variables %nhvar = nvar-nfvar; % number of home (affected) variables. @@ -77,47 +77,47 @@ Ri = zeros(k,k,nvar); % 1st and 2nd dims: lagged and exogenous equations. eqninx = 1; nreseqn = 2; % Number of linear restrictions for A0(:,eqninx) for each state. if (indxEqnTv_m(eqninx, 2)<=2) - %**** For constant A0_s. In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi. - Qi(1:(nStates-1)*nvar+nreseqn,:,eqninx) = [ - 1 0 0 -1 0 0 - 0 1 0 0 -1 0 - 0 0 1 0 0 -1 - - 0 0 0 0 1 0 - 0 0 0 0 0 1 - ]; - %**** For constant D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri. - for si=1:nStates-1 - for ki=1:kvar - Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; - end - end -else % Time-varying equations at least for A0_s. For D+_s, constant-parameter equations in general. - %**** For time-varying A0_s. In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi. - Qi(1:nreseqn*nStates,:,eqninx) = [ - 0 1 0 0 0 0 - 0 0 1 0 0 0 - - 0 0 0 0 1 0 - 0 0 0 0 0 1 - ]; - - %**** For D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri. - if (indxEqnTv_m(eqninx, 2)==3) % For constant D+** except the constant term. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri. - for si=1:nStates-1 - for ki=1:kvar-1 % -1: no restrictions on the constant term, which is freely time-varying. - Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; - end - end - elseif (indxEqnTv_m(eqninx, 2)==4) % For constant D+**. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri. - for si=1:nStates-1 - for ki=1:kvar + %**** For constant A0_s. In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi. + Qi(1:(nStates-1)*nvar+nreseqn,:,eqninx) = [ + 1 0 0 -1 0 0 + 0 1 0 0 -1 0 + 0 0 1 0 0 -1 + + 0 0 0 0 1 0 + 0 0 0 0 0 1 + ]; + %**** For constant D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri. + for si=1:nStates-1 + for ki=1:kvar Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; - end - end - else - error('.../ftd_2s_caseall_*.m: Have not got time to deal with the simple case indxEqnTv_m(eqninx, 2)=5.') - end + end + end +else % Time-varying equations at least for A0_s. For D+_s, constant-parameter equations in general. + %**** For time-varying A0_s. In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi. + Qi(1:nreseqn*nStates,:,eqninx) = [ + 0 1 0 0 0 0 + 0 0 1 0 0 0 + + 0 0 0 0 1 0 + 0 0 0 0 0 1 + ]; + + %**** For D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri. + if (indxEqnTv_m(eqninx, 2)==3) % For constant D+** except the constant term. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri. + for si=1:nStates-1 + for ki=1:kvar-1 % -1: no restrictions on the constant term, which is freely time-varying. + Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; + end + end + elseif (indxEqnTv_m(eqninx, 2)==4) % For constant D+**. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri. + for si=1:nStates-1 + for ki=1:kvar + Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; + end + end + else + error('.../ftd_2s_caseall_*.m: Have not got time to deal with the simple case indxEqnTv_m(eqninx, 2)=5.') + end end @@ -125,61 +125,61 @@ end eqninx = 2; nreseqn = 1; % Number of linear restrictions for A0(:,eqninx) for each state. if (indxEqnTv_m(eqninx, 2)<=2) - %**** For constant A0_s. In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi. - Qi(1:(nStates-1)*nvar+nreseqn,:,eqninx) = [ - 1 0 0 -1 0 0 - 0 1 0 0 -1 0 - 0 0 1 0 0 -1 - - 0 0 0 0 0 1 - ]; - %**** For constant D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri. - for si=1:nStates-1 - for ki=1:kvar - Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; - end - end -else % Time-varying equations at least for A0_s. For D+_s, constant-parameter equations in general. - %**** For time-varying A0_s. In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi. - Qi(1:nreseqn*nStates,:,eqninx) = [ - 0 0 1 0 0 0 - - 0 0 0 0 0 1 - ]; - - %**** For D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri. - if (indxEqnTv_m(eqninx, 2)==3) % For constant D+** except the constant term. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri. - for si=1:nStates-1 - for ki=1:kvar-1 % -1: no restrictions on the constant term, which is freely time-varying. + %**** For constant A0_s. In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi. + Qi(1:(nStates-1)*nvar+nreseqn,:,eqninx) = [ + 1 0 0 -1 0 0 + 0 1 0 0 -1 0 + 0 0 1 0 0 -1 + + 0 0 0 0 0 1 + ]; + %**** For constant D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri. + for si=1:nStates-1 + for ki=1:kvar Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; - end - end - elseif (indxEqnTv_m(eqninx, 2)==4) % For constant D+**. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri. - for si=1:nStates-1 - for ki=1:kvar - Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; - end - end - else - error('.../ftd_3s_case3a.m: Have not got time to deal with the simple case indxEqnTv_m(eqninx, 2)=5.') - end - - %==== For freely time-varying A+ for only the first 6 lags. - %==== Lagged restrictions: zeros on all lags except the first 6 lags in the MS equation. - % nlagsno0 = 6; % Number of lags to be nonzero. - % for si=1:nStates - % for ki = 1:lags-nlagsno0 - % for kj=1:nvar - % Ri(kvar*(si-1)+nlagsno0*nvar+nvar*(ki-1)+kj,kvar*(si-1)+nlagsno0*nvar+nvar*(ki-1)+kj,2) = 1; - % end - % end - % end - %**** For constant D+_s except the first two lags and the constant term. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri. - % for si=1:nStates-1 - % for ki=[2*nvar+1:kvar-1] - % Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; - % end - % end + end + end +else % Time-varying equations at least for A0_s. For D+_s, constant-parameter equations in general. + %**** For time-varying A0_s. In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi. + Qi(1:nreseqn*nStates,:,eqninx) = [ + 0 0 1 0 0 0 + + 0 0 0 0 0 1 + ]; + + %**** For D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri. + if (indxEqnTv_m(eqninx, 2)==3) % For constant D+** except the constant term. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri. + for si=1:nStates-1 + for ki=1:kvar-1 % -1: no restrictions on the constant term, which is freely time-varying. + Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; + end + end + elseif (indxEqnTv_m(eqninx, 2)==4) % For constant D+**. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri. + for si=1:nStates-1 + for ki=1:kvar + Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; + end + end + else + error('.../ftd_3s_case3a.m: Have not got time to deal with the simple case indxEqnTv_m(eqninx, 2)=5.') + end + + %==== For freely time-varying A+ for only the first 6 lags. + %==== Lagged restrictions: zeros on all lags except the first 6 lags in the MS equation. + % nlagsno0 = 6; % Number of lags to be nonzero. + % for si=1:nStates + % for ki = 1:lags-nlagsno0 + % for kj=1:nvar + % Ri(kvar*(si-1)+nlagsno0*nvar+nvar*(ki-1)+kj,kvar*(si-1)+nlagsno0*nvar+nvar*(ki-1)+kj,2) = 1; + % end + % end + % end + %**** For constant D+_s except the first two lags and the constant term. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri. + % for si=1:nStates-1 + % for ki=[2*nvar+1:kvar-1] + % Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; + % end + % end end @@ -187,42 +187,42 @@ end eqninx = 3; nreseqn = 0; % Number of linear restrictions for the equation for each state. if (indxEqnTv_m(eqninx, 2)<=2) - %**** For constant A0_s. In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi. - Qi(1:(nStates-1)*nvar+nreseqn,:,eqninx) = [ - 1 0 0 -1 0 0 - 0 1 0 0 -1 0 - 0 0 1 0 0 -1 - ]; - %**** For constant D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri. - for si=1:nStates-1 - for ki=1:kvar - Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; - end - end -else % Time-varying equations at least for A0_s. For D+_s, constant-parameter equations in general. - %**** For D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri. - if (indxEqnTv_m(eqninx, 2)==3) % For constant D+** except the constant term. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri. - for si=1:nStates-1 - for ki=1:kvar-1 % -1: no restrictions on the constant term, which is freely time-varying. + %**** For constant A0_s. In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi. + Qi(1:(nStates-1)*nvar+nreseqn,:,eqninx) = [ + 1 0 0 -1 0 0 + 0 1 0 0 -1 0 + 0 0 1 0 0 -1 + ]; + %**** For constant D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri. + for si=1:nStates-1 + for ki=1:kvar Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; - end - end - elseif (indxEqnTv_m(eqninx, 2)==4) % For constant D+**. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri. - for si=1:nStates-1 - for ki=1:kvar - Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; - end - end - else - error('.../ftd_2s_caseall_*.m: Have not got time to deal with the simple case indxEqnTv_m(eqninx, 2)=5.') - end + end + end +else % Time-varying equations at least for A0_s. For D+_s, constant-parameter equations in general. + %**** For D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri. + if (indxEqnTv_m(eqninx, 2)==3) % For constant D+** except the constant term. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri. + for si=1:nStates-1 + for ki=1:kvar-1 % -1: no restrictions on the constant term, which is freely time-varying. + Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; + end + end + elseif (indxEqnTv_m(eqninx, 2)==4) % For constant D+**. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri. + for si=1:nStates-1 + for ki=1:kvar + Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; + end + end + else + error('.../ftd_2s_caseall_*.m: Have not got time to deal with the simple case indxEqnTv_m(eqninx, 2)=5.') + end end for ki=1:nvar % initializing loop for each equation - Ui{ki} = null(Qi(:,:,ki)); - Vi{ki} = null(Ri(:,:,ki)); - n0(ki) = size(Ui{ki},2); - np(ki) = size(Vi{ki},2); + Ui{ki} = null(Qi(:,:,ki)); + Vi{ki} = null(Ri(:,:,ki)); + n0(ki) = size(Ui{ki},2); + np(ki) = size(Vi{ki},2); end diff --git a/tests/ms-sbvar/archive-files/ftd_2s_caseall_upperchol4v.m b/tests/ms-sbvar/archive-files/ftd_2s_caseall_upperchol4v.m index bc3215cdeb..7af810db3a 100644 --- a/tests/ms-sbvar/archive-files/ftd_2s_caseall_upperchol4v.m +++ b/tests/ms-sbvar/archive-files/ftd_2s_caseall_upperchol4v.m @@ -49,7 +49,7 @@ n0 = zeros(nvar,1); % ith element represents the number of free A0 parameters in np = zeros(nvar,1); % ith element represents the number of free D+ parameters in ith equation in all states. if (nargin==3) - nexo = 1; % 1: constant as default where nexo must be a nonnegative integer + nexo = 1; % 1: constant as default where nexo must be a nonnegative integer end @@ -59,10 +59,10 @@ k = kvar*nStates; % Maximum number of lagged and exogenous variables in each eq Qi = zeros(n,n,nvar); % 3rd dim: nvar contemporaneous equations. Ri = zeros(k,k,nvar); % 1st and 2nd dims: lagged and exogenous equations. - % Row corresponds to equation with nvar variables for state 1, ..., nvar variables for state nState. - % 0 means no restriction. - % 1 and -1 or any other number means the linear combination of the corresponding parameters is restricted to 0. - % 1 (only 1) means that the corresponding parameter is restricted to 0. + % Row corresponds to equation with nvar variables for state 1, ..., nvar variables for state nState. + % 0 means no restriction. + % 1 and -1 or any other number means the linear combination of the corresponding parameters is restricted to 0. + % 1 (only 1) means that the corresponding parameter is restricted to 0. %nfvar = 6; % number of foreign (Granger causing) variables %nhvar = nvar-nfvar; % number of home (affected) variables. @@ -77,51 +77,51 @@ Ri = zeros(k,k,nvar); % 1st and 2nd dims: lagged and exogenous equations. eqninx = 1; nreseqn = 3; % Number of linear restrictions for A0(:,eqninx) for each state. if (indxEqnTv_m(eqninx, 2)<=2) - %**** For constant A0_s. In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi. - Qi(1:(nStates-1)*nvar+nreseqn,:,eqninx) = [ - 1 0 0 0 -1 0 0 0 - 0 1 0 0 0 -1 0 0 - 0 0 1 0 0 0 -1 0 - 0 0 0 1 0 0 0 -1 - - 0 0 0 0 0 1 0 0 - 0 0 0 0 0 0 1 0 - 0 0 0 0 0 0 0 1 - ]; - %**** For constant D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri. - for si=1:nStates-1 - for ki=1:kvar - Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; - end - end -else % Time-varying equations at least for A0_s. For D+_s, constant-parameter equations in general. - %**** For time-varying A0_s. In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi. - Qi(1:nreseqn*nStates,:,eqninx) = [ - 0 1 0 0 0 0 0 0 - 0 0 1 0 0 0 0 0 - 0 0 0 1 0 0 0 0 - - 0 0 0 0 0 1 0 0 - 0 0 0 0 0 0 1 0 - 0 0 0 0 0 0 0 1 - ]; - - %**** For D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri. - if (indxEqnTv_m(eqninx, 2)==3) % For constant D+** except the constant term. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri. - for si=1:nStates-1 - for ki=1:kvar-1 % -1: no restrictions on the constant term, which is freely time-varying. - Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; - end - end - elseif (indxEqnTv_m(eqninx, 2)==4) % For constant D+**. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri. - for si=1:nStates-1 - for ki=1:kvar + %**** For constant A0_s. In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi. + Qi(1:(nStates-1)*nvar+nreseqn,:,eqninx) = [ + 1 0 0 0 -1 0 0 0 + 0 1 0 0 0 -1 0 0 + 0 0 1 0 0 0 -1 0 + 0 0 0 1 0 0 0 -1 + + 0 0 0 0 0 1 0 0 + 0 0 0 0 0 0 1 0 + 0 0 0 0 0 0 0 1 + ]; + %**** For constant D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri. + for si=1:nStates-1 + for ki=1:kvar Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; - end - end - else - error('.../ftd_2s_caseall_simszha5v.m: Have not got time to deal with the simple case indxEqnTv_m(eqninx, 2)=5.') - end + end + end +else % Time-varying equations at least for A0_s. For D+_s, constant-parameter equations in general. + %**** For time-varying A0_s. In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi. + Qi(1:nreseqn*nStates,:,eqninx) = [ + 0 1 0 0 0 0 0 0 + 0 0 1 0 0 0 0 0 + 0 0 0 1 0 0 0 0 + + 0 0 0 0 0 1 0 0 + 0 0 0 0 0 0 1 0 + 0 0 0 0 0 0 0 1 + ]; + + %**** For D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri. + if (indxEqnTv_m(eqninx, 2)==3) % For constant D+** except the constant term. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri. + for si=1:nStates-1 + for ki=1:kvar-1 % -1: no restrictions on the constant term, which is freely time-varying. + Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; + end + end + elseif (indxEqnTv_m(eqninx, 2)==4) % For constant D+**. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri. + for si=1:nStates-1 + for ki=1:kvar + Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; + end + end + else + error('.../ftd_2s_caseall_simszha5v.m: Have not got time to deal with the simple case indxEqnTv_m(eqninx, 2)=5.') + end end @@ -129,65 +129,65 @@ end eqninx = 2; nreseqn = 2; % Number of linear restrictions for A0(:,eqninx) for each state. if (indxEqnTv_m(eqninx, 2)<=2) - %**** For constant A0_s. In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi. - Qi(1:(nStates-1)*nvar+nreseqn,:,eqninx) = [ - 1 0 0 0 -1 0 0 0 - 0 1 0 0 0 -1 0 0 - 0 0 1 0 0 0 -1 0 - 0 0 0 1 0 0 0 -1 - - 0 0 0 0 0 0 1 0 - 0 0 0 0 0 0 0 1 - ]; - %**** For constant D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri. - for si=1:nStates-1 - for ki=1:kvar - Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; - end - end -else % Time-varying equations at least for A0_s. For D+_s, constant-parameter equations in general. - %**** For time-varying A0_s. In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi. - Qi(1:nreseqn*nStates,:,eqninx) = [ - 0 0 1 0 0 0 0 0 - 0 0 0 1 0 0 0 0 - - 0 0 0 0 0 0 1 0 - 0 0 0 0 0 0 0 1 - ]; - - %**** For D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri. - if (indxEqnTv_m(eqninx, 2)==3) % For constant D+** except the constant term. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri. - for si=1:nStates-1 - for ki=1:kvar-1 % -1: no restrictions on the constant term, which is freely time-varying. - Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; - end - end - elseif (indxEqnTv_m(eqninx, 2)==4) % For constant D+**. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri. - for si=1:nStates-1 - for ki=1:kvar + %**** For constant A0_s. In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi. + Qi(1:(nStates-1)*nvar+nreseqn,:,eqninx) = [ + 1 0 0 0 -1 0 0 0 + 0 1 0 0 0 -1 0 0 + 0 0 1 0 0 0 -1 0 + 0 0 0 1 0 0 0 -1 + + 0 0 0 0 0 0 1 0 + 0 0 0 0 0 0 0 1 + ]; + %**** For constant D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri. + for si=1:nStates-1 + for ki=1:kvar Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; - end - end - else - error('.../ftd_3s_case3a.m: Have not got time to deal with the simple case indxEqnTv_m(eqninx, 2)=5.') - end - - %==== For freely time-varying A+ for only the first 6 lags. - %==== Lagged restrictions: zeros on all lags except the first 6 lags in the MS equation. - % nlagsno0 = 6; % Number of lags to be nonzero. - % for si=1:nStates - % for ki = 1:lags-nlagsno0 - % for kj=1:nvar - % Ri(kvar*(si-1)+nlagsno0*nvar+nvar*(ki-1)+kj,kvar*(si-1)+nlagsno0*nvar+nvar*(ki-1)+kj,2) = 1; - % end - % end - % end - %**** For constant D+_s except the first two lags and the constant term. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri. - % for si=1:nStates-1 - % for ki=[2*nvar+1:kvar-1] - % Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; - % end - % end + end + end +else % Time-varying equations at least for A0_s. For D+_s, constant-parameter equations in general. + %**** For time-varying A0_s. In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi. + Qi(1:nreseqn*nStates,:,eqninx) = [ + 0 0 1 0 0 0 0 0 + 0 0 0 1 0 0 0 0 + + 0 0 0 0 0 0 1 0 + 0 0 0 0 0 0 0 1 + ]; + + %**** For D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri. + if (indxEqnTv_m(eqninx, 2)==3) % For constant D+** except the constant term. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri. + for si=1:nStates-1 + for ki=1:kvar-1 % -1: no restrictions on the constant term, which is freely time-varying. + Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; + end + end + elseif (indxEqnTv_m(eqninx, 2)==4) % For constant D+**. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri. + for si=1:nStates-1 + for ki=1:kvar + Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; + end + end + else + error('.../ftd_3s_case3a.m: Have not got time to deal with the simple case indxEqnTv_m(eqninx, 2)=5.') + end + + %==== For freely time-varying A+ for only the first 6 lags. + %==== Lagged restrictions: zeros on all lags except the first 6 lags in the MS equation. + % nlagsno0 = 6; % Number of lags to be nonzero. + % for si=1:nStates + % for ki = 1:lags-nlagsno0 + % for kj=1:nvar + % Ri(kvar*(si-1)+nlagsno0*nvar+nvar*(ki-1)+kj,kvar*(si-1)+nlagsno0*nvar+nvar*(ki-1)+kj,2) = 1; + % end + % end + % end + %**** For constant D+_s except the first two lags and the constant term. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri. + % for si=1:nStates-1 + % for ki=[2*nvar+1:kvar-1] + % Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; + % end + % end end @@ -195,44 +195,44 @@ end eqninx = 3; nreseqn = 1; % Number of linear restrictions for the equation for each state. if (indxEqnTv_m(eqninx, 2)<=2) - %**** For constant A0_s. In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi. - Qi(1:(nStates-1)*nvar+nreseqn,:,eqninx) = [ - 1 0 0 0 -1 0 0 0 - 0 1 0 0 0 -1 0 0 - 0 0 1 0 0 0 -1 0 - 0 0 0 1 0 0 0 -1 - - 0 0 0 0 0 0 0 1 - ]; - %**** For constant D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri. - for si=1:nStates-1 - for ki=1:kvar - Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; - end - end -else % Time-varying equations at least for A0_s. For D+_s, constant-parameter equations in general. - %**** For time-varying A0_s. In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi. - Qi(1:nreseqn*nStates,:,eqninx) = [ - 0 0 0 1 0 0 0 0 - - 0 0 0 0 0 0 0 1 - ]; - %**** For D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri. - if (indxEqnTv_m(eqninx, 2)==3) % For constant D+** except the constant term. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri. - for si=1:nStates-1 - for ki=1:kvar-1 % -1: no restrictions on the constant term, which is freely time-varying. - Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; - end - end - elseif (indxEqnTv_m(eqninx, 2)==4) % For constant D+**. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri. - for si=1:nStates-1 - for ki=1:kvar + %**** For constant A0_s. In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi. + Qi(1:(nStates-1)*nvar+nreseqn,:,eqninx) = [ + 1 0 0 0 -1 0 0 0 + 0 1 0 0 0 -1 0 0 + 0 0 1 0 0 0 -1 0 + 0 0 0 1 0 0 0 -1 + + 0 0 0 0 0 0 0 1 + ]; + %**** For constant D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri. + for si=1:nStates-1 + for ki=1:kvar Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; - end - end - else - error('.../ftd_2s_caseall_simszha5v.m: Have not got time to deal with the simple case indxEqnTv_m(eqninx, 2)=5.') - end + end + end +else % Time-varying equations at least for A0_s. For D+_s, constant-parameter equations in general. + %**** For time-varying A0_s. In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi. + Qi(1:nreseqn*nStates,:,eqninx) = [ + 0 0 0 1 0 0 0 0 + + 0 0 0 0 0 0 0 1 + ]; + %**** For D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri. + if (indxEqnTv_m(eqninx, 2)==3) % For constant D+** except the constant term. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri. + for si=1:nStates-1 + for ki=1:kvar-1 % -1: no restrictions on the constant term, which is freely time-varying. + Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; + end + end + elseif (indxEqnTv_m(eqninx, 2)==4) % For constant D+**. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri. + for si=1:nStates-1 + for ki=1:kvar + Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; + end + end + else + error('.../ftd_2s_caseall_simszha5v.m: Have not got time to deal with the simple case indxEqnTv_m(eqninx, 2)=5.') + end end @@ -240,36 +240,36 @@ end eqninx = 4; nreseqn = 0; % Number of linear restrictions for the equation for each state. if (indxEqnTv_m(eqninx, 2)<=2) - %**** For constant A0_s. In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi. - Qi(1:(nStates-1)*nvar+nreseqn,:,eqninx) = [ - 1 0 0 0 -1 0 0 0 - 0 1 0 0 0 -1 0 0 - 0 0 1 0 0 0 -1 0 - 0 0 0 1 0 0 0 -1 - ]; - %**** For constant D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri. - for si=1:nStates-1 - for ki=1:kvar - Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; - end - end -else % Time-varying equations at least for A0_s. For D+_s, constant-parameter equations in general. - %**** For D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri. - if (indxEqnTv_m(eqninx, 2)==3) % For constant D+** except the constant term. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri. - for si=1:nStates-1 - for ki=1:kvar-1 % -1: no restrictions on the constant term, which is freely time-varying. - Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; - end - end - elseif (indxEqnTv_m(eqninx, 2)==4) % For constant D+**. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri. - for si=1:nStates-1 - for ki=1:kvar + %**** For constant A0_s. In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi. + Qi(1:(nStates-1)*nvar+nreseqn,:,eqninx) = [ + 1 0 0 0 -1 0 0 0 + 0 1 0 0 0 -1 0 0 + 0 0 1 0 0 0 -1 0 + 0 0 0 1 0 0 0 -1 + ]; + %**** For constant D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri. + for si=1:nStates-1 + for ki=1:kvar Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; - end - end - else - error('.../ftd_2s_caseall_simszha5v.m: Have not got time to deal with the simple case indxEqnTv_m(eqninx, 2)=5.') - end + end + end +else % Time-varying equations at least for A0_s. For D+_s, constant-parameter equations in general. + %**** For D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri. + if (indxEqnTv_m(eqninx, 2)==3) % For constant D+** except the constant term. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri. + for si=1:nStates-1 + for ki=1:kvar-1 % -1: no restrictions on the constant term, which is freely time-varying. + Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; + end + end + elseif (indxEqnTv_m(eqninx, 2)==4) % For constant D+**. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri. + for si=1:nStates-1 + for ki=1:kvar + Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; + end + end + else + error('.../ftd_2s_caseall_simszha5v.m: Have not got time to deal with the simple case indxEqnTv_m(eqninx, 2)=5.') + end end @@ -324,8 +324,8 @@ end for ki=1:nvar % initializing loop for each equation - Ui{ki} = null(Qi(:,:,ki)); - Vi{ki} = null(Ri(:,:,ki)); - n0(ki) = size(Ui{ki},2); - np(ki) = size(Vi{ki},2); + Ui{ki} = null(Qi(:,:,ki)); + Vi{ki} = null(Ri(:,:,ki)); + n0(ki) = size(Ui{ki},2); + np(ki) = size(Vi{ki},2); end diff --git a/tests/ms-sbvar/archive-files/ftd_2s_caseall_upperchol6v.m b/tests/ms-sbvar/archive-files/ftd_2s_caseall_upperchol6v.m index 389109df7a..932e927454 100644 --- a/tests/ms-sbvar/archive-files/ftd_2s_caseall_upperchol6v.m +++ b/tests/ms-sbvar/archive-files/ftd_2s_caseall_upperchol6v.m @@ -49,7 +49,7 @@ n0 = zeros(nvar,1); % ith element represents the number of free A0 parameters in np = zeros(nvar,1); % ith element represents the number of free D+ parameters in ith equation in all states. if (nargin==3) - nexo = 1; % 1: constant as default where nexo must be a nonnegative integer + nexo = 1; % 1: constant as default where nexo must be a nonnegative integer end @@ -59,10 +59,10 @@ k = kvar*nStates; % Maximum number of lagged and exogenous variables in each eq Qi = zeros(n,n,nvar); % 3rd dim: nvar contemporaneous equations. Ri = zeros(k,k,nvar); % 1st and 2nd dims: lagged and exogenous equations. - % Row corresponds to equation with nvar variables for state 1, ..., nvar variables for state nState. - % 0 means no restriction. - % 1 and -1 or any other number means the linear combination of the corresponding parameters is restricted to 0. - % 1 (only 1) means that the corresponding parameter is restricted to 0. + % Row corresponds to equation with nvar variables for state 1, ..., nvar variables for state nState. + % 0 means no restriction. + % 1 and -1 or any other number means the linear combination of the corresponding parameters is restricted to 0. + % 1 (only 1) means that the corresponding parameter is restricted to 0. %nfvar = 6; % number of foreign (Granger causing) variables %nhvar = nvar-nfvar; % number of home (affected) variables. @@ -77,59 +77,59 @@ Ri = zeros(k,k,nvar); % 1st and 2nd dims: lagged and exogenous equations. eqninx = 1; nreseqn = 5; % Number of linear restrictions for A0(:,eqninx) for each state. if (indxEqnTv_m(eqninx, 2)<=2) - %**** For constant A0_s. In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi. - Qi(1:(nStates-1)*nvar+nreseqn,:,eqninx) = [ - 1 0 0 0 0 0 -1 0 0 0 0 0 - 0 1 0 0 0 0 0 -1 0 0 0 0 - 0 0 1 0 0 0 0 0 -1 0 0 0 - 0 0 0 1 0 0 0 0 0 -1 0 0 - 0 0 0 0 1 0 0 0 0 0 -1 0 - 0 0 0 0 0 1 0 0 0 0 0 -1 - - 0 0 0 0 0 0 0 1 0 0 0 0 - 0 0 0 0 0 0 0 0 1 0 0 0 - 0 0 0 0 0 0 0 0 0 1 0 0 - 0 0 0 0 0 0 0 0 0 0 1 0 - 0 0 0 0 0 0 0 0 0 0 0 1 - ]; - %**** For constant D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri. - for si=1:nStates-1 - for ki=1:kvar - Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; - end - end -else % Time-varying equations at least for A0_s. For D+_s, constant-parameter equations in general. - %**** For time-varying A0_s. In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi. - Qi(1:nreseqn*nStates,:,eqninx) = [ - 0 1 0 0 0 0 0 0 0 0 0 0 - 0 0 1 0 0 0 0 0 0 0 0 0 - 0 0 0 1 0 0 0 0 0 0 0 0 - 0 0 0 0 1 0 0 0 0 0 0 0 - 0 0 0 0 0 1 0 0 0 0 0 0 - - 0 0 0 0 0 0 0 1 0 0 0 0 - 0 0 0 0 0 0 0 0 1 0 0 0 - 0 0 0 0 0 0 0 0 0 1 0 0 - 0 0 0 0 0 0 0 0 0 0 1 0 - 0 0 0 0 0 0 0 0 0 0 0 1 - ]; - - %**** For D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri. - if (indxEqnTv_m(eqninx, 2)==3) % For constant D+** except the constant term. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri. - for si=1:nStates-1 - for ki=1:kvar-1 % -1: no restrictions on the constant term, which is freely time-varying. - Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; - end - end - elseif (indxEqnTv_m(eqninx, 2)==4) % For constant D+**. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri. - for si=1:nStates-1 - for ki=1:kvar + %**** For constant A0_s. In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi. + Qi(1:(nStates-1)*nvar+nreseqn,:,eqninx) = [ + 1 0 0 0 0 0 -1 0 0 0 0 0 + 0 1 0 0 0 0 0 -1 0 0 0 0 + 0 0 1 0 0 0 0 0 -1 0 0 0 + 0 0 0 1 0 0 0 0 0 -1 0 0 + 0 0 0 0 1 0 0 0 0 0 -1 0 + 0 0 0 0 0 1 0 0 0 0 0 -1 + + 0 0 0 0 0 0 0 1 0 0 0 0 + 0 0 0 0 0 0 0 0 1 0 0 0 + 0 0 0 0 0 0 0 0 0 1 0 0 + 0 0 0 0 0 0 0 0 0 0 1 0 + 0 0 0 0 0 0 0 0 0 0 0 1 + ]; + %**** For constant D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri. + for si=1:nStates-1 + for ki=1:kvar Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; - end - end - else - error('.../ftd_2s_caseall_simszha5v.m: Have not got time to deal with the simple case indxEqnTv_m(eqninx, 2)=5.') - end + end + end +else % Time-varying equations at least for A0_s. For D+_s, constant-parameter equations in general. + %**** For time-varying A0_s. In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi. + Qi(1:nreseqn*nStates,:,eqninx) = [ + 0 1 0 0 0 0 0 0 0 0 0 0 + 0 0 1 0 0 0 0 0 0 0 0 0 + 0 0 0 1 0 0 0 0 0 0 0 0 + 0 0 0 0 1 0 0 0 0 0 0 0 + 0 0 0 0 0 1 0 0 0 0 0 0 + + 0 0 0 0 0 0 0 1 0 0 0 0 + 0 0 0 0 0 0 0 0 1 0 0 0 + 0 0 0 0 0 0 0 0 0 1 0 0 + 0 0 0 0 0 0 0 0 0 0 1 0 + 0 0 0 0 0 0 0 0 0 0 0 1 + ]; + + %**** For D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri. + if (indxEqnTv_m(eqninx, 2)==3) % For constant D+** except the constant term. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri. + for si=1:nStates-1 + for ki=1:kvar-1 % -1: no restrictions on the constant term, which is freely time-varying. + Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; + end + end + elseif (indxEqnTv_m(eqninx, 2)==4) % For constant D+**. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri. + for si=1:nStates-1 + for ki=1:kvar + Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; + end + end + else + error('.../ftd_2s_caseall_simszha5v.m: Have not got time to deal with the simple case indxEqnTv_m(eqninx, 2)=5.') + end end @@ -138,56 +138,56 @@ end eqninx = 2; nreseqn = 4; % Number of linear restrictions for A0(:,eqninx) for each state. if (indxEqnTv_m(eqninx, 2)<=2) - %**** For constant A0_s. In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi. - Qi(1:(nStates-1)*nvar+nreseqn,:,eqninx) = [ - 1 0 0 0 0 0 -1 0 0 0 0 0 - 0 1 0 0 0 0 0 -1 0 0 0 0 - 0 0 1 0 0 0 0 0 -1 0 0 0 - 0 0 0 1 0 0 0 0 0 -1 0 0 - 0 0 0 0 1 0 0 0 0 0 -1 0 - 0 0 0 0 0 1 0 0 0 0 0 -1 - - 0 0 0 0 0 0 0 0 1 0 0 0 - 0 0 0 0 0 0 0 0 0 1 0 0 - 0 0 0 0 0 0 0 0 0 0 1 0 - 0 0 0 0 0 0 0 0 0 0 0 1 - ]; - %**** For constant D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri. - for si=1:nStates-1 - for ki=1:kvar - Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; - end - end -else % Time-varying equations at least for A0_s. For D+_s, constant-parameter equations in general. - %**** For time-varying A0_s. In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi. - Qi(1:nreseqn*nStates,:,eqninx) = [ - 0 0 1 0 0 0 0 0 0 0 0 0 - 0 0 0 1 0 0 0 0 0 0 0 0 - 0 0 0 0 1 0 0 0 0 0 0 0 - 0 0 0 0 0 1 0 0 0 0 0 0 - - 0 0 0 0 0 0 0 0 1 0 0 0 - 0 0 0 0 0 0 0 0 0 1 0 0 - 0 0 0 0 0 0 0 0 0 0 1 0 - 0 0 0 0 0 0 0 0 0 0 0 1 - ]; - - %**** For D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri. - if (indxEqnTv_m(eqninx, 2)==3) % For constant D+** except the constant term. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri. - for si=1:nStates-1 - for ki=1:kvar-1 % -1: no restrictions on the constant term, which is freely time-varying. - Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; - end - end - elseif (indxEqnTv_m(eqninx, 2)==4) % For constant D+**. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri. - for si=1:nStates-1 - for ki=1:kvar + %**** For constant A0_s. In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi. + Qi(1:(nStates-1)*nvar+nreseqn,:,eqninx) = [ + 1 0 0 0 0 0 -1 0 0 0 0 0 + 0 1 0 0 0 0 0 -1 0 0 0 0 + 0 0 1 0 0 0 0 0 -1 0 0 0 + 0 0 0 1 0 0 0 0 0 -1 0 0 + 0 0 0 0 1 0 0 0 0 0 -1 0 + 0 0 0 0 0 1 0 0 0 0 0 -1 + + 0 0 0 0 0 0 0 0 1 0 0 0 + 0 0 0 0 0 0 0 0 0 1 0 0 + 0 0 0 0 0 0 0 0 0 0 1 0 + 0 0 0 0 0 0 0 0 0 0 0 1 + ]; + %**** For constant D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri. + for si=1:nStates-1 + for ki=1:kvar Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; - end - end - else - error('.../ftd_2s_caseall_simszha5v.m: Have not got time to deal with the simple case indxEqnTv_m(eqninx, 2)=5.') - end + end + end +else % Time-varying equations at least for A0_s. For D+_s, constant-parameter equations in general. + %**** For time-varying A0_s. In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi. + Qi(1:nreseqn*nStates,:,eqninx) = [ + 0 0 1 0 0 0 0 0 0 0 0 0 + 0 0 0 1 0 0 0 0 0 0 0 0 + 0 0 0 0 1 0 0 0 0 0 0 0 + 0 0 0 0 0 1 0 0 0 0 0 0 + + 0 0 0 0 0 0 0 0 1 0 0 0 + 0 0 0 0 0 0 0 0 0 1 0 0 + 0 0 0 0 0 0 0 0 0 0 1 0 + 0 0 0 0 0 0 0 0 0 0 0 1 + ]; + + %**** For D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri. + if (indxEqnTv_m(eqninx, 2)==3) % For constant D+** except the constant term. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri. + for si=1:nStates-1 + for ki=1:kvar-1 % -1: no restrictions on the constant term, which is freely time-varying. + Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; + end + end + elseif (indxEqnTv_m(eqninx, 2)==4) % For constant D+**. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri. + for si=1:nStates-1 + for ki=1:kvar + Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; + end + end + else + error('.../ftd_2s_caseall_simszha5v.m: Have not got time to deal with the simple case indxEqnTv_m(eqninx, 2)=5.') + end end @@ -195,70 +195,70 @@ end eqninx = 3; nreseqn = 3; % Number of linear restrictions for A0(:,eqninx) for each state. if (indxEqnTv_m(eqninx, 2)<=2) - %**** For constant A0_s. In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi. - Qi(1:(nStates-1)*nvar+nreseqn,:,eqninx) = [ - 1 0 0 0 0 0 -1 0 0 0 0 0 - 0 1 0 0 0 0 0 -1 0 0 0 0 - 0 0 1 0 0 0 0 0 -1 0 0 0 - 0 0 0 1 0 0 0 0 0 -1 0 0 - 0 0 0 0 1 0 0 0 0 0 -1 0 - 0 0 0 0 0 1 0 0 0 0 0 -1 - - 0 0 0 0 0 0 0 0 0 1 0 0 - 0 0 0 0 0 0 0 0 0 0 1 0 - 0 0 0 0 0 0 0 0 0 0 0 1 - ]; - %**** For constant D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri. - for si=1:nStates-1 - for ki=1:kvar - Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; - end - end -else % Time-varying equations at least for A0_s. For D+_s, constant-parameter equations in general. - %**** For time-varying A0_s. In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi. - Qi(1:nreseqn*nStates,:,eqninx) = [ - 0 0 0 1 0 0 0 0 0 0 0 0 - 0 0 0 0 1 0 0 0 0 0 0 0 - 0 0 0 0 0 1 0 0 0 0 0 0 - - 0 0 0 0 0 0 0 0 0 1 0 0 - 0 0 0 0 0 0 0 0 0 0 1 0 - 0 0 0 0 0 0 0 0 0 0 0 1 - ]; - - %**** For D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri. - if (indxEqnTv_m(eqninx, 2)==3) % For constant D+** except the constant term. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri. - for si=1:nStates-1 - for ki=1:kvar-1 % -1: no restrictions on the constant term, which is freely time-varying. + %**** For constant A0_s. In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi. + Qi(1:(nStates-1)*nvar+nreseqn,:,eqninx) = [ + 1 0 0 0 0 0 -1 0 0 0 0 0 + 0 1 0 0 0 0 0 -1 0 0 0 0 + 0 0 1 0 0 0 0 0 -1 0 0 0 + 0 0 0 1 0 0 0 0 0 -1 0 0 + 0 0 0 0 1 0 0 0 0 0 -1 0 + 0 0 0 0 0 1 0 0 0 0 0 -1 + + 0 0 0 0 0 0 0 0 0 1 0 0 + 0 0 0 0 0 0 0 0 0 0 1 0 + 0 0 0 0 0 0 0 0 0 0 0 1 + ]; + %**** For constant D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri. + for si=1:nStates-1 + for ki=1:kvar Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; - end - end - elseif (indxEqnTv_m(eqninx, 2)==4) % For constant D+**. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri. - for si=1:nStates-1 - for ki=1:kvar - Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; - end - end - else - error('.../ftd_3s_case3a.m: Have not got time to deal with the simple case indxEqnTv_m(eqninx, 2)=5.') - end - - %==== For freely time-varying A+ for only the first 6 lags. - %==== Lagged restrictions: zeros on all lags except the first 6 lags in the MS equation. - % nlagsno0 = 6; % Number of lags to be nonzero. - % for si=1:nStates - % for ki = 1:lags-nlagsno0 - % for kj=1:nvar - % Ri(kvar*(si-1)+nlagsno0*nvar+nvar*(ki-1)+kj,kvar*(si-1)+nlagsno0*nvar+nvar*(ki-1)+kj,2) = 1; - % end - % end - % end - %**** For constant D+_s except the first two lags and the constant term. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri. - % for si=1:nStates-1 - % for ki=[2*nvar+1:kvar-1] - % Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; - % end - % end + end + end +else % Time-varying equations at least for A0_s. For D+_s, constant-parameter equations in general. + %**** For time-varying A0_s. In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi. + Qi(1:nreseqn*nStates,:,eqninx) = [ + 0 0 0 1 0 0 0 0 0 0 0 0 + 0 0 0 0 1 0 0 0 0 0 0 0 + 0 0 0 0 0 1 0 0 0 0 0 0 + + 0 0 0 0 0 0 0 0 0 1 0 0 + 0 0 0 0 0 0 0 0 0 0 1 0 + 0 0 0 0 0 0 0 0 0 0 0 1 + ]; + + %**** For D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri. + if (indxEqnTv_m(eqninx, 2)==3) % For constant D+** except the constant term. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri. + for si=1:nStates-1 + for ki=1:kvar-1 % -1: no restrictions on the constant term, which is freely time-varying. + Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; + end + end + elseif (indxEqnTv_m(eqninx, 2)==4) % For constant D+**. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri. + for si=1:nStates-1 + for ki=1:kvar + Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; + end + end + else + error('.../ftd_3s_case3a.m: Have not got time to deal with the simple case indxEqnTv_m(eqninx, 2)=5.') + end + + %==== For freely time-varying A+ for only the first 6 lags. + %==== Lagged restrictions: zeros on all lags except the first 6 lags in the MS equation. + % nlagsno0 = 6; % Number of lags to be nonzero. + % for si=1:nStates + % for ki = 1:lags-nlagsno0 + % for kj=1:nvar + % Ri(kvar*(si-1)+nlagsno0*nvar+nvar*(ki-1)+kj,kvar*(si-1)+nlagsno0*nvar+nvar*(ki-1)+kj,2) = 1; + % end + % end + % end + %**** For constant D+_s except the first two lags and the constant term. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri. + % for si=1:nStates-1 + % for ki=[2*nvar+1:kvar-1] + % Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; + % end + % end end @@ -266,49 +266,49 @@ end eqninx = 4; nreseqn = 2; % Number of linear restrictions for the equation for each state. if (indxEqnTv_m(eqninx, 2)<=2) - %**** For constant A0_s. In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi. - Qi(1:(nStates-1)*nvar+nreseqn,:,eqninx) = [ - 1 0 0 0 0 0 -1 0 0 0 0 0 - 0 1 0 0 0 0 0 -1 0 0 0 0 - 0 0 1 0 0 0 0 0 -1 0 0 0 - 0 0 0 1 0 0 0 0 0 -1 0 0 - 0 0 0 0 1 0 0 0 0 0 -1 0 - 0 0 0 0 0 1 0 0 0 0 0 -1 - - 0 0 0 0 0 0 0 0 0 0 1 0 - 0 0 0 0 0 0 0 0 0 0 0 1 - ]; - %**** For constant D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri. - for si=1:nStates-1 - for ki=1:kvar - Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; - end - end -else % Time-varying equations at least for A0_s. For D+_s, constant-parameter equations in general. - %**** For time-varying A0_s. In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi. - Qi(1:nreseqn*nStates,:,eqninx) = [ - 0 0 0 0 1 0 0 0 0 0 0 0 - 0 0 0 0 0 1 0 0 0 0 0 0 - - 0 0 0 0 0 0 0 0 0 0 1 0 - 0 0 0 0 0 0 0 0 0 0 0 1 - ]; - %**** For D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri. - if (indxEqnTv_m(eqninx, 2)==3) % For constant D+** except the constant term. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri. - for si=1:nStates-1 - for ki=1:kvar-1 % -1: no restrictions on the constant term, which is freely time-varying. - Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; - end - end - elseif (indxEqnTv_m(eqninx, 2)==4) % For constant D+**. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri. - for si=1:nStates-1 - for ki=1:kvar + %**** For constant A0_s. In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi. + Qi(1:(nStates-1)*nvar+nreseqn,:,eqninx) = [ + 1 0 0 0 0 0 -1 0 0 0 0 0 + 0 1 0 0 0 0 0 -1 0 0 0 0 + 0 0 1 0 0 0 0 0 -1 0 0 0 + 0 0 0 1 0 0 0 0 0 -1 0 0 + 0 0 0 0 1 0 0 0 0 0 -1 0 + 0 0 0 0 0 1 0 0 0 0 0 -1 + + 0 0 0 0 0 0 0 0 0 0 1 0 + 0 0 0 0 0 0 0 0 0 0 0 1 + ]; + %**** For constant D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri. + for si=1:nStates-1 + for ki=1:kvar Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; - end - end - else - error('.../ftd_2s_caseall_simszha5v.m: Have not got time to deal with the simple case indxEqnTv_m(eqninx, 2)=5.') - end + end + end +else % Time-varying equations at least for A0_s. For D+_s, constant-parameter equations in general. + %**** For time-varying A0_s. In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi. + Qi(1:nreseqn*nStates,:,eqninx) = [ + 0 0 0 0 1 0 0 0 0 0 0 0 + 0 0 0 0 0 1 0 0 0 0 0 0 + + 0 0 0 0 0 0 0 0 0 0 1 0 + 0 0 0 0 0 0 0 0 0 0 0 1 + ]; + %**** For D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri. + if (indxEqnTv_m(eqninx, 2)==3) % For constant D+** except the constant term. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri. + for si=1:nStates-1 + for ki=1:kvar-1 % -1: no restrictions on the constant term, which is freely time-varying. + Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; + end + end + elseif (indxEqnTv_m(eqninx, 2)==4) % For constant D+**. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri. + for si=1:nStates-1 + for ki=1:kvar + Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; + end + end + else + error('.../ftd_2s_caseall_simszha5v.m: Have not got time to deal with the simple case indxEqnTv_m(eqninx, 2)=5.') + end end @@ -316,46 +316,46 @@ end eqninx = 5; nreseqn = 1; % Number of linear restrictions for the equation for each state. if (indxEqnTv_m(eqninx, 2)<=2) - %**** For constant A0_s. In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi. - Qi(1:(nStates-1)*nvar+nreseqn,:,eqninx) = [ - 1 0 0 0 0 0 -1 0 0 0 0 0 - 0 1 0 0 0 0 0 -1 0 0 0 0 - 0 0 1 0 0 0 0 0 -1 0 0 0 - 0 0 0 1 0 0 0 0 0 -1 0 0 - 0 0 0 0 1 0 0 0 0 0 -1 0 - 0 0 0 0 0 1 0 0 0 0 0 -1 - - 0 0 0 0 0 0 0 0 0 0 0 1 - ]; - %**** For constant D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri. - for si=1:nStates-1 - for ki=1:kvar - Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; - end - end -else % Time-varying equations at least for A0_s. For D+_s, constant-parameter equations in general. - %**** For time-varying A0_s. In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi. - Qi(1:nreseqn*nStates,:,eqninx) = [ - 0 0 0 0 0 1 0 0 0 0 0 0 - - 0 0 0 0 0 0 0 0 0 0 0 1 - ]; - %**** For D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri. - if (indxEqnTv_m(eqninx, 2)==3) % For constant D+** except the constant term. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri. - for si=1:nStates-1 - for ki=1:kvar-1 % -1: no restrictions on the constant term, which is freely time-varying. - Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; - end - end - elseif (indxEqnTv_m(eqninx, 2)==4) % For constant D+**. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri. - for si=1:nStates-1 - for ki=1:kvar + %**** For constant A0_s. In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi. + Qi(1:(nStates-1)*nvar+nreseqn,:,eqninx) = [ + 1 0 0 0 0 0 -1 0 0 0 0 0 + 0 1 0 0 0 0 0 -1 0 0 0 0 + 0 0 1 0 0 0 0 0 -1 0 0 0 + 0 0 0 1 0 0 0 0 0 -1 0 0 + 0 0 0 0 1 0 0 0 0 0 -1 0 + 0 0 0 0 0 1 0 0 0 0 0 -1 + + 0 0 0 0 0 0 0 0 0 0 0 1 + ]; + %**** For constant D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri. + for si=1:nStates-1 + for ki=1:kvar Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; - end - end - else - error('.../ftd_2s_caseall_simszha5v.m: Have not got time to deal with the simple case indxEqnTv_m(eqninx, 2)=5.') - end + end + end +else % Time-varying equations at least for A0_s. For D+_s, constant-parameter equations in general. + %**** For time-varying A0_s. In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi. + Qi(1:nreseqn*nStates,:,eqninx) = [ + 0 0 0 0 0 1 0 0 0 0 0 0 + + 0 0 0 0 0 0 0 0 0 0 0 1 + ]; + %**** For D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri. + if (indxEqnTv_m(eqninx, 2)==3) % For constant D+** except the constant term. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri. + for si=1:nStates-1 + for ki=1:kvar-1 % -1: no restrictions on the constant term, which is freely time-varying. + Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; + end + end + elseif (indxEqnTv_m(eqninx, 2)==4) % For constant D+**. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri. + for si=1:nStates-1 + for ki=1:kvar + Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; + end + end + else + error('.../ftd_2s_caseall_simszha5v.m: Have not got time to deal with the simple case indxEqnTv_m(eqninx, 2)=5.') + end end @@ -363,38 +363,38 @@ end eqninx = 6; nreseqn = 0; % Number of linear restrictions for the equation for each state. if (indxEqnTv_m(eqninx, 2)<=2) - %**** For constant A0_s. In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi. - Qi(1:(nStates-1)*nvar+nreseqn,:,eqninx) = [ - 1 0 0 0 0 0 -1 0 0 0 0 0 - 0 1 0 0 0 0 0 -1 0 0 0 0 - 0 0 1 0 0 0 0 0 -1 0 0 0 - 0 0 0 1 0 0 0 0 0 -1 0 0 - 0 0 0 0 1 0 0 0 0 0 -1 0 - 0 0 0 0 0 1 0 0 0 0 0 -1 - ]; - %**** For constant D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri. - for si=1:nStates-1 - for ki=1:kvar - Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; - end - end -else % Time-varying equations at least for A0_s. For D+_s, constant-parameter equations in general. - %**** For D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri. - if (indxEqnTv_m(eqninx, 2)==3) % For constant D+** except the constant term. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri. - for si=1:nStates-1 - for ki=1:kvar-1 % -1: no restrictions on the constant term, which is freely time-varying. + %**** For constant A0_s. In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi. + Qi(1:(nStates-1)*nvar+nreseqn,:,eqninx) = [ + 1 0 0 0 0 0 -1 0 0 0 0 0 + 0 1 0 0 0 0 0 -1 0 0 0 0 + 0 0 1 0 0 0 0 0 -1 0 0 0 + 0 0 0 1 0 0 0 0 0 -1 0 0 + 0 0 0 0 1 0 0 0 0 0 -1 0 + 0 0 0 0 0 1 0 0 0 0 0 -1 + ]; + %**** For constant D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri. + for si=1:nStates-1 + for ki=1:kvar Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; - end - end - elseif (indxEqnTv_m(eqninx, 2)==4) % For constant D+**. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri. - for si=1:nStates-1 - for ki=1:kvar - Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; - end - end - else - error('.../ftd_2s_caseall_simszha5v.m: Have not got time to deal with the simple case indxEqnTv_m(eqninx, 2)=5.') - end + end + end +else % Time-varying equations at least for A0_s. For D+_s, constant-parameter equations in general. + %**** For D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri. + if (indxEqnTv_m(eqninx, 2)==3) % For constant D+** except the constant term. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri. + for si=1:nStates-1 + for ki=1:kvar-1 % -1: no restrictions on the constant term, which is freely time-varying. + Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; + end + end + elseif (indxEqnTv_m(eqninx, 2)==4) % For constant D+**. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri. + for si=1:nStates-1 + for ki=1:kvar + Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; + end + end + else + error('.../ftd_2s_caseall_simszha5v.m: Have not got time to deal with the simple case indxEqnTv_m(eqninx, 2)=5.') + end end @@ -448,8 +448,8 @@ end for ki=1:nvar % initializing loop for each equation - Ui{ki} = null(Qi(:,:,ki)); - Vi{ki} = null(Ri(:,:,ki)); - n0(ki) = size(Ui{ki},2); - np(ki) = size(Vi{ki},2); + Ui{ki} = null(Qi(:,:,ki)); + Vi{ki} = null(Ri(:,:,ki)); + n0(ki) = size(Ui{ki},2); + np(ki) = size(Vi{ki},2); end diff --git a/tests/ms-sbvar/archive-files/ftd_2s_caseall_upperchol7v.m b/tests/ms-sbvar/archive-files/ftd_2s_caseall_upperchol7v.m index de818ab905..eb2e80c695 100644 --- a/tests/ms-sbvar/archive-files/ftd_2s_caseall_upperchol7v.m +++ b/tests/ms-sbvar/archive-files/ftd_2s_caseall_upperchol7v.m @@ -49,7 +49,7 @@ n0 = zeros(nvar,1); % ith element represents the number of free A0 parameters in np = zeros(nvar,1); % ith element represents the number of free D+ parameters in ith equation in all states. if (nargin==3) - nexo = 1; % 1: constant as default where nexo must be a nonnegative integer + nexo = 1; % 1: constant as default where nexo must be a nonnegative integer end @@ -59,10 +59,10 @@ k = kvar*nStates; % Maximum number of lagged and exogenous variables in each eq Qi = zeros(n,n,nvar); % 3rd dim: nvar contemporaneous equations. Ri = zeros(k,k,nvar); % 1st and 2nd dims: lagged and exogenous equations. - % Row corresponds to equation with nvar variables for state 1, ..., nvar variables for state nState. - % 0 means no restriction. - % 1 and -1 or any other number means the linear combination of the corresponding parameters is restricted to 0. - % 1 (only 1) means that the corresponding parameter is restricted to 0. + % Row corresponds to equation with nvar variables for state 1, ..., nvar variables for state nState. + % 0 means no restriction. + % 1 and -1 or any other number means the linear combination of the corresponding parameters is restricted to 0. + % 1 (only 1) means that the corresponding parameter is restricted to 0. %nfvar = 6; % number of foreign (Granger causing) variables %nhvar = nvar-nfvar; % number of home (affected) variables. @@ -77,63 +77,63 @@ Ri = zeros(k,k,nvar); % 1st and 2nd dims: lagged and exogenous equations. eqninx = 1; nreseqn = 6; % Number of linear restrictions for A0(:,eqninx) for each state. if (indxEqnTv_m(eqninx, 2)<=2) - %**** For constant A0_s. In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi. - Qi(1:(nStates-1)*nvar+nreseqn,:,eqninx) = [ - 1 0 0 0 0 0 0 -1 0 0 0 0 0 0 - 0 1 0 0 0 0 0 0 -1 0 0 0 0 0 - 0 0 1 0 0 0 0 0 0 -1 0 0 0 0 - 0 0 0 1 0 0 0 0 0 0 -1 0 0 0 - 0 0 0 0 1 0 0 0 0 0 0 -1 0 0 - 0 0 0 0 0 1 0 0 0 0 0 0 -1 0 - 0 0 0 0 0 0 1 0 0 0 0 0 0 -1 - - 0 0 0 0 0 0 0 0 1 0 0 0 0 0 - 0 0 0 0 0 0 0 0 0 1 0 0 0 0 - 0 0 0 0 0 0 0 0 0 0 1 0 0 0 - 0 0 0 0 0 0 0 0 0 0 0 1 0 0 - 0 0 0 0 0 0 0 0 0 0 0 0 1 0 - 0 0 0 0 0 0 0 0 0 0 0 0 0 1 - ]; - %**** For constant D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri. - for si=1:nStates-1 - for ki=1:kvar - Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; - end - end -else % Time-varying equations at least for A0_s. For D+_s, constant-parameter equations in general. - %**** For time-varying A0_s. In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi. - Qi(1:nreseqn*nStates,:,eqninx) = [ - 0 1 0 0 0 0 0 0 0 0 0 0 0 0 - 0 0 1 0 0 0 0 0 0 0 0 0 0 0 - 0 0 0 1 0 0 0 0 0 0 0 0 0 0 - 0 0 0 0 1 0 0 0 0 0 0 0 0 0 - 0 0 0 0 0 1 0 0 0 0 0 0 0 0 - 0 0 0 0 0 0 1 0 0 0 0 0 0 0 - - 0 0 0 0 0 0 0 0 1 0 0 0 0 0 - 0 0 0 0 0 0 0 0 0 1 0 0 0 0 - 0 0 0 0 0 0 0 0 0 0 1 0 0 0 - 0 0 0 0 0 0 0 0 0 0 0 1 0 0 - 0 0 0 0 0 0 0 0 0 0 0 0 1 0 - 0 0 0 0 0 0 0 0 0 0 0 0 0 1 - ]; - - %**** For D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri. - if (indxEqnTv_m(eqninx, 2)==3) % For constant D+** except the constant term. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri. - for si=1:nStates-1 - for ki=1:kvar-1 % -1: no restrictions on the constant term, which is freely time-varying. - Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; - end - end - elseif (indxEqnTv_m(eqninx, 2)==4) % For constant D+**. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri. - for si=1:nStates-1 - for ki=1:kvar + %**** For constant A0_s. In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi. + Qi(1:(nStates-1)*nvar+nreseqn,:,eqninx) = [ + 1 0 0 0 0 0 0 -1 0 0 0 0 0 0 + 0 1 0 0 0 0 0 0 -1 0 0 0 0 0 + 0 0 1 0 0 0 0 0 0 -1 0 0 0 0 + 0 0 0 1 0 0 0 0 0 0 -1 0 0 0 + 0 0 0 0 1 0 0 0 0 0 0 -1 0 0 + 0 0 0 0 0 1 0 0 0 0 0 0 -1 0 + 0 0 0 0 0 0 1 0 0 0 0 0 0 -1 + + 0 0 0 0 0 0 0 0 1 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 1 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 1 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 1 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 1 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 1 + ]; + %**** For constant D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri. + for si=1:nStates-1 + for ki=1:kvar Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; - end - end - else - error('.../ftd_2s_caseall_*.m: Have not got time to deal with the simple case indxEqnTv_m(eqninx, 2)=5.') - end + end + end +else % Time-varying equations at least for A0_s. For D+_s, constant-parameter equations in general. + %**** For time-varying A0_s. In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi. + Qi(1:nreseqn*nStates,:,eqninx) = [ + 0 1 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 1 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 1 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 1 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 1 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 1 0 0 0 0 0 0 0 + + 0 0 0 0 0 0 0 0 1 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 1 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 1 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 1 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 1 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 1 + ]; + + %**** For D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri. + if (indxEqnTv_m(eqninx, 2)==3) % For constant D+** except the constant term. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri. + for si=1:nStates-1 + for ki=1:kvar-1 % -1: no restrictions on the constant term, which is freely time-varying. + Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; + end + end + elseif (indxEqnTv_m(eqninx, 2)==4) % For constant D+**. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri. + for si=1:nStates-1 + for ki=1:kvar + Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; + end + end + else + error('.../ftd_2s_caseall_*.m: Have not got time to deal with the simple case indxEqnTv_m(eqninx, 2)=5.') + end end @@ -141,60 +141,60 @@ end eqninx = 2; nreseqn = 5; % Number of linear restrictions for A0(:,eqninx) for each state. if (indxEqnTv_m(eqninx, 2)<=2) - %**** For constant A0_s. In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi. - Qi(1:(nStates-1)*nvar+nreseqn,:,eqninx) = [ - 1 0 0 0 0 0 0 -1 0 0 0 0 0 0 - 0 1 0 0 0 0 0 0 -1 0 0 0 0 0 - 0 0 1 0 0 0 0 0 0 -1 0 0 0 0 - 0 0 0 1 0 0 0 0 0 0 -1 0 0 0 - 0 0 0 0 1 0 0 0 0 0 0 -1 0 0 - 0 0 0 0 0 1 0 0 0 0 0 0 -1 0 - 0 0 0 0 0 0 1 0 0 0 0 0 0 -1 - - 0 0 0 0 0 0 0 0 0 1 0 0 0 0 - 0 0 0 0 0 0 0 0 0 0 1 0 0 0 - 0 0 0 0 0 0 0 0 0 0 0 1 0 0 - 0 0 0 0 0 0 0 0 0 0 0 0 1 0 - 0 0 0 0 0 0 0 0 0 0 0 0 0 1 - ]; - %**** For constant D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri. - for si=1:nStates-1 - for ki=1:kvar - Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; - end - end -else % Time-varying equations at least for A0_s. For D+_s, constant-parameter equations in general. - %**** For time-varying A0_s. In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi. - Qi(1:nreseqn*nStates,:,eqninx) = [ - 0 0 1 0 0 0 0 0 0 0 0 0 0 0 - 0 0 0 1 0 0 0 0 0 0 0 0 0 0 - 0 0 0 0 1 0 0 0 0 0 0 0 0 0 - 0 0 0 0 0 1 0 0 0 0 0 0 0 0 - 0 0 0 0 0 0 1 0 0 0 0 0 0 0 - - 0 0 0 0 0 0 0 0 0 1 0 0 0 0 - 0 0 0 0 0 0 0 0 0 0 1 0 0 0 - 0 0 0 0 0 0 0 0 0 0 0 1 0 0 - 0 0 0 0 0 0 0 0 0 0 0 0 1 0 - 0 0 0 0 0 0 0 0 0 0 0 0 0 1 - ]; - - %**** For D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri. - if (indxEqnTv_m(eqninx, 2)==3) % For constant D+** except the constant term. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri. - for si=1:nStates-1 - for ki=1:kvar-1 % -1: no restrictions on the constant term, which is freely time-varying. - Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; - end - end - elseif (indxEqnTv_m(eqninx, 2)==4) % For constant D+**. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri. - for si=1:nStates-1 - for ki=1:kvar + %**** For constant A0_s. In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi. + Qi(1:(nStates-1)*nvar+nreseqn,:,eqninx) = [ + 1 0 0 0 0 0 0 -1 0 0 0 0 0 0 + 0 1 0 0 0 0 0 0 -1 0 0 0 0 0 + 0 0 1 0 0 0 0 0 0 -1 0 0 0 0 + 0 0 0 1 0 0 0 0 0 0 -1 0 0 0 + 0 0 0 0 1 0 0 0 0 0 0 -1 0 0 + 0 0 0 0 0 1 0 0 0 0 0 0 -1 0 + 0 0 0 0 0 0 1 0 0 0 0 0 0 -1 + + 0 0 0 0 0 0 0 0 0 1 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 1 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 1 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 1 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 1 + ]; + %**** For constant D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri. + for si=1:nStates-1 + for ki=1:kvar Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; - end - end - else - error('.../ftd_2s_caseall_*.m: Have not got time to deal with the simple case indxEqnTv_m(eqninx, 2)=5.') - end + end + end +else % Time-varying equations at least for A0_s. For D+_s, constant-parameter equations in general. + %**** For time-varying A0_s. In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi. + Qi(1:nreseqn*nStates,:,eqninx) = [ + 0 0 1 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 1 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 1 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 1 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 1 0 0 0 0 0 0 0 + + 0 0 0 0 0 0 0 0 0 1 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 1 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 1 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 1 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 1 + ]; + + %**** For D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri. + if (indxEqnTv_m(eqninx, 2)==3) % For constant D+** except the constant term. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri. + for si=1:nStates-1 + for ki=1:kvar-1 % -1: no restrictions on the constant term, which is freely time-varying. + Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; + end + end + elseif (indxEqnTv_m(eqninx, 2)==4) % For constant D+**. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri. + for si=1:nStates-1 + for ki=1:kvar + Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; + end + end + else + error('.../ftd_2s_caseall_*.m: Have not got time to deal with the simple case indxEqnTv_m(eqninx, 2)=5.') + end end @@ -202,57 +202,57 @@ end eqninx = 3; nreseqn = 4; % Number of linear restrictions for A0(:,eqninx) for each state. if (indxEqnTv_m(eqninx, 2)<=2) - %**** For constant A0_s. In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi. - Qi(1:(nStates-1)*nvar+nreseqn,:,eqninx) = [ - 1 0 0 0 0 0 0 -1 0 0 0 0 0 0 - 0 1 0 0 0 0 0 0 -1 0 0 0 0 0 - 0 0 1 0 0 0 0 0 0 -1 0 0 0 0 - 0 0 0 1 0 0 0 0 0 0 -1 0 0 0 - 0 0 0 0 1 0 0 0 0 0 0 -1 0 0 - 0 0 0 0 0 1 0 0 0 0 0 0 -1 0 - 0 0 0 0 0 0 1 0 0 0 0 0 0 -1 - - 0 0 0 0 0 0 0 0 0 0 1 0 0 0 - 0 0 0 0 0 0 0 0 0 0 0 1 0 0 - 0 0 0 0 0 0 0 0 0 0 0 0 1 0 - 0 0 0 0 0 0 0 0 0 0 0 0 0 1 - ]; - %**** For constant D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri. - for si=1:nStates-1 - for ki=1:kvar - Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; - end - end -else % Time-varying equations at least for A0_s. For D+_s, constant-parameter equations in general. - %**** For time-varying A0_s. In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi. - Qi(1:nreseqn*nStates,:,eqninx) = [ - 0 0 0 1 0 0 0 0 0 0 0 0 0 0 - 0 0 0 0 1 0 0 0 0 0 0 0 0 0 - 0 0 0 0 0 1 0 0 0 0 0 0 0 0 - 0 0 0 0 0 0 1 0 0 0 0 0 0 0 - - 0 0 0 0 0 0 0 0 0 0 1 0 0 0 - 0 0 0 0 0 0 0 0 0 0 0 1 0 0 - 0 0 0 0 0 0 0 0 0 0 0 0 1 0 - 0 0 0 0 0 0 0 0 0 0 0 0 0 1 - ]; - - %**** For D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri. - if (indxEqnTv_m(eqninx, 2)==3) % For constant D+** except the constant term. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri. - for si=1:nStates-1 - for ki=1:kvar-1 % -1: no restrictions on the constant term, which is freely time-varying. - Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; - end - end - elseif (indxEqnTv_m(eqninx, 2)==4) % For constant D+**. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri. - for si=1:nStates-1 - for ki=1:kvar + %**** For constant A0_s. In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi. + Qi(1:(nStates-1)*nvar+nreseqn,:,eqninx) = [ + 1 0 0 0 0 0 0 -1 0 0 0 0 0 0 + 0 1 0 0 0 0 0 0 -1 0 0 0 0 0 + 0 0 1 0 0 0 0 0 0 -1 0 0 0 0 + 0 0 0 1 0 0 0 0 0 0 -1 0 0 0 + 0 0 0 0 1 0 0 0 0 0 0 -1 0 0 + 0 0 0 0 0 1 0 0 0 0 0 0 -1 0 + 0 0 0 0 0 0 1 0 0 0 0 0 0 -1 + + 0 0 0 0 0 0 0 0 0 0 1 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 1 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 1 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 1 + ]; + %**** For constant D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri. + for si=1:nStates-1 + for ki=1:kvar Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; - end - end - else - error('.../ftd_2s_caseall_simszha5v.m: Have not got time to deal with the simple case indxEqnTv_m(eqninx, 2)=5.') - end + end + end +else % Time-varying equations at least for A0_s. For D+_s, constant-parameter equations in general. + %**** For time-varying A0_s. In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi. + Qi(1:nreseqn*nStates,:,eqninx) = [ + 0 0 0 1 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 1 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 1 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 1 0 0 0 0 0 0 0 + + 0 0 0 0 0 0 0 0 0 0 1 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 1 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 1 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 1 + ]; + + %**** For D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri. + if (indxEqnTv_m(eqninx, 2)==3) % For constant D+** except the constant term. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri. + for si=1:nStates-1 + for ki=1:kvar-1 % -1: no restrictions on the constant term, which is freely time-varying. + Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; + end + end + elseif (indxEqnTv_m(eqninx, 2)==4) % For constant D+**. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri. + for si=1:nStates-1 + for ki=1:kvar + Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; + end + end + else + error('.../ftd_2s_caseall_simszha5v.m: Have not got time to deal with the simple case indxEqnTv_m(eqninx, 2)=5.') + end end @@ -261,71 +261,71 @@ end eqninx = 4; nreseqn = 3; % Number of linear restrictions for A0(:,eqninx) for each state. if (indxEqnTv_m(eqninx, 2)<=2) - %**** For constant A0_s. In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi. - Qi(1:(nStates-1)*nvar+nreseqn,:,eqninx) = [ - 1 0 0 0 0 0 0 -1 0 0 0 0 0 0 - 0 1 0 0 0 0 0 0 -1 0 0 0 0 0 - 0 0 1 0 0 0 0 0 0 -1 0 0 0 0 - 0 0 0 1 0 0 0 0 0 0 -1 0 0 0 - 0 0 0 0 1 0 0 0 0 0 0 -1 0 0 - 0 0 0 0 0 1 0 0 0 0 0 0 -1 0 - 0 0 0 0 0 0 1 0 0 0 0 0 0 -1 - - 0 0 0 0 0 0 0 0 0 0 0 1 0 0 - 0 0 0 0 0 0 0 0 0 0 0 0 1 0 - 0 0 0 0 0 0 0 0 0 0 0 0 0 1 - ]; - %**** For constant D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri. - for si=1:nStates-1 - for ki=1:kvar - Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; - end - end -else % Time-varying equations at least for A0_s. For D+_s, constant-parameter equations in general. - %**** For time-varying A0_s. In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi. - Qi(1:nreseqn*nStates,:,eqninx) = [ - 0 0 0 0 1 0 0 0 0 0 0 0 0 0 - 0 0 0 0 0 1 0 0 0 0 0 0 0 0 - 0 0 0 0 0 0 1 0 0 0 0 0 0 0 - - 0 0 0 0 0 0 0 0 0 0 0 1 0 0 - 0 0 0 0 0 0 0 0 0 0 0 0 1 0 - 0 0 0 0 0 0 0 0 0 0 0 0 0 1 - ]; - - %**** For D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri. - if (indxEqnTv_m(eqninx, 2)==3) % For constant D+** except the constant term. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri. - for si=1:nStates-1 - for ki=1:kvar-1 % -1: no restrictions on the constant term, which is freely time-varying. - Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; - end - end - elseif (indxEqnTv_m(eqninx, 2)==4) % For constant D+**. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri. - for si=1:nStates-1 - for ki=1:kvar + %**** For constant A0_s. In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi. + Qi(1:(nStates-1)*nvar+nreseqn,:,eqninx) = [ + 1 0 0 0 0 0 0 -1 0 0 0 0 0 0 + 0 1 0 0 0 0 0 0 -1 0 0 0 0 0 + 0 0 1 0 0 0 0 0 0 -1 0 0 0 0 + 0 0 0 1 0 0 0 0 0 0 -1 0 0 0 + 0 0 0 0 1 0 0 0 0 0 0 -1 0 0 + 0 0 0 0 0 1 0 0 0 0 0 0 -1 0 + 0 0 0 0 0 0 1 0 0 0 0 0 0 -1 + + 0 0 0 0 0 0 0 0 0 0 0 1 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 1 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 1 + ]; + %**** For constant D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri. + for si=1:nStates-1 + for ki=1:kvar Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; - end - end - else - error('.../ftd_3s_case3a.m: Have not got time to deal with the simple case indxEqnTv_m(eqninx, 2)=5.') - end - - %==== For freely time-varying A+ for only the first 6 lags. - %==== Lagged restrictions: zeros on all lags except the first 6 lags in the MS equation. - % nlagsno0 = 6; % Number of lags to be nonzero. - % for si=1:nStates - % for ki = 1:lags-nlagsno0 - % for kj=1:nvar - % Ri(kvar*(si-1)+nlagsno0*nvar+nvar*(ki-1)+kj,kvar*(si-1)+nlagsno0*nvar+nvar*(ki-1)+kj,2) = 1; - % end - % end - % end - %**** For constant D+_s except the first two lags and the constant term. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri. - % for si=1:nStates-1 - % for ki=[2*nvar+1:kvar-1] - % Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; - % end - % end + end + end +else % Time-varying equations at least for A0_s. For D+_s, constant-parameter equations in general. + %**** For time-varying A0_s. In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi. + Qi(1:nreseqn*nStates,:,eqninx) = [ + 0 0 0 0 1 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 1 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 1 0 0 0 0 0 0 0 + + 0 0 0 0 0 0 0 0 0 0 0 1 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 1 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 1 + ]; + + %**** For D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri. + if (indxEqnTv_m(eqninx, 2)==3) % For constant D+** except the constant term. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri. + for si=1:nStates-1 + for ki=1:kvar-1 % -1: no restrictions on the constant term, which is freely time-varying. + Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; + end + end + elseif (indxEqnTv_m(eqninx, 2)==4) % For constant D+**. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri. + for si=1:nStates-1 + for ki=1:kvar + Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; + end + end + else + error('.../ftd_3s_case3a.m: Have not got time to deal with the simple case indxEqnTv_m(eqninx, 2)=5.') + end + + %==== For freely time-varying A+ for only the first 6 lags. + %==== Lagged restrictions: zeros on all lags except the first 6 lags in the MS equation. + % nlagsno0 = 6; % Number of lags to be nonzero. + % for si=1:nStates + % for ki = 1:lags-nlagsno0 + % for kj=1:nvar + % Ri(kvar*(si-1)+nlagsno0*nvar+nvar*(ki-1)+kj,kvar*(si-1)+nlagsno0*nvar+nvar*(ki-1)+kj,2) = 1; + % end + % end + % end + %**** For constant D+_s except the first two lags and the constant term. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri. + % for si=1:nStates-1 + % for ki=[2*nvar+1:kvar-1] + % Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; + % end + % end end @@ -333,50 +333,50 @@ end eqninx = 5; nreseqn = 2; % Number of linear restrictions for the equation for each state. if (indxEqnTv_m(eqninx, 2)<=2) - %**** For constant A0_s. In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi. - Qi(1:(nStates-1)*nvar+nreseqn,:,eqninx) = [ - 1 0 0 0 0 0 0 -1 0 0 0 0 0 0 - 0 1 0 0 0 0 0 0 -1 0 0 0 0 0 - 0 0 1 0 0 0 0 0 0 -1 0 0 0 0 - 0 0 0 1 0 0 0 0 0 0 -1 0 0 0 - 0 0 0 0 1 0 0 0 0 0 0 -1 0 0 - 0 0 0 0 0 1 0 0 0 0 0 0 -1 0 - 0 0 0 0 0 0 1 0 0 0 0 0 0 -1 - - 0 0 0 0 0 0 0 0 0 0 0 0 1 0 - 0 0 0 0 0 0 0 0 0 0 0 0 0 1 - ]; - %**** For constant D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri. - for si=1:nStates-1 - for ki=1:kvar - Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; - end - end -else % Time-varying equations at least for A0_s. For D+_s, constant-parameter equations in general. - %**** For time-varying A0_s. In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi. - Qi(1:nreseqn*nStates,:,eqninx) = [ - 0 0 0 0 0 1 0 0 0 0 0 0 0 0 - 0 0 0 0 0 0 1 0 0 0 0 0 0 0 - - 0 0 0 0 0 0 0 0 0 0 0 0 1 0 - 0 0 0 0 0 0 0 0 0 0 0 0 0 1 - ]; - %**** For D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri. - if (indxEqnTv_m(eqninx, 2)==3) % For constant D+** except the constant term. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri. - for si=1:nStates-1 - for ki=1:kvar-1 % -1: no restrictions on the constant term, which is freely time-varying. - Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; - end - end - elseif (indxEqnTv_m(eqninx, 2)==4) % For constant D+**. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri. - for si=1:nStates-1 - for ki=1:kvar + %**** For constant A0_s. In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi. + Qi(1:(nStates-1)*nvar+nreseqn,:,eqninx) = [ + 1 0 0 0 0 0 0 -1 0 0 0 0 0 0 + 0 1 0 0 0 0 0 0 -1 0 0 0 0 0 + 0 0 1 0 0 0 0 0 0 -1 0 0 0 0 + 0 0 0 1 0 0 0 0 0 0 -1 0 0 0 + 0 0 0 0 1 0 0 0 0 0 0 -1 0 0 + 0 0 0 0 0 1 0 0 0 0 0 0 -1 0 + 0 0 0 0 0 0 1 0 0 0 0 0 0 -1 + + 0 0 0 0 0 0 0 0 0 0 0 0 1 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 1 + ]; + %**** For constant D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri. + for si=1:nStates-1 + for ki=1:kvar Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; - end - end - else - error('.../ftd_2s_caseall_simszha5v.m: Have not got time to deal with the simple case indxEqnTv_m(eqninx, 2)=5.') - end + end + end +else % Time-varying equations at least for A0_s. For D+_s, constant-parameter equations in general. + %**** For time-varying A0_s. In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi. + Qi(1:nreseqn*nStates,:,eqninx) = [ + 0 0 0 0 0 1 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 1 0 0 0 0 0 0 0 + + 0 0 0 0 0 0 0 0 0 0 0 0 1 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 1 + ]; + %**** For D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri. + if (indxEqnTv_m(eqninx, 2)==3) % For constant D+** except the constant term. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri. + for si=1:nStates-1 + for ki=1:kvar-1 % -1: no restrictions on the constant term, which is freely time-varying. + Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; + end + end + elseif (indxEqnTv_m(eqninx, 2)==4) % For constant D+**. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri. + for si=1:nStates-1 + for ki=1:kvar + Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; + end + end + else + error('.../ftd_2s_caseall_simszha5v.m: Have not got time to deal with the simple case indxEqnTv_m(eqninx, 2)=5.') + end end @@ -384,47 +384,47 @@ end eqninx = 6; nreseqn = 1; % Number of linear restrictions for the equation for each state. if (indxEqnTv_m(eqninx, 2)<=2) - %**** For constant A0_s. In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi. - Qi(1:(nStates-1)*nvar+nreseqn,:,eqninx) = [ - 1 0 0 0 0 0 0 -1 0 0 0 0 0 0 - 0 1 0 0 0 0 0 0 -1 0 0 0 0 0 - 0 0 1 0 0 0 0 0 0 -1 0 0 0 0 - 0 0 0 1 0 0 0 0 0 0 -1 0 0 0 - 0 0 0 0 1 0 0 0 0 0 0 -1 0 0 - 0 0 0 0 0 1 0 0 0 0 0 0 -1 0 - 0 0 0 0 0 0 1 0 0 0 0 0 0 -1 - - 0 0 0 0 0 0 0 0 0 0 0 0 0 1 - ]; - %**** For constant D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri. - for si=1:nStates-1 - for ki=1:kvar - Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; - end - end -else % Time-varying equations at least for A0_s. For D+_s, constant-parameter equations in general. - %**** For time-varying A0_s. In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi. - Qi(1:nreseqn*nStates,:,eqninx) = [ - 0 0 0 0 0 0 1 0 0 0 0 0 0 0 - - 0 0 0 0 0 0 0 0 0 0 0 0 0 1 - ]; - %**** For D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri. - if (indxEqnTv_m(eqninx, 2)==3) % For constant D+** except the constant term. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri. - for si=1:nStates-1 - for ki=1:kvar-1 % -1: no restrictions on the constant term, which is freely time-varying. + %**** For constant A0_s. In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi. + Qi(1:(nStates-1)*nvar+nreseqn,:,eqninx) = [ + 1 0 0 0 0 0 0 -1 0 0 0 0 0 0 + 0 1 0 0 0 0 0 0 -1 0 0 0 0 0 + 0 0 1 0 0 0 0 0 0 -1 0 0 0 0 + 0 0 0 1 0 0 0 0 0 0 -1 0 0 0 + 0 0 0 0 1 0 0 0 0 0 0 -1 0 0 + 0 0 0 0 0 1 0 0 0 0 0 0 -1 0 + 0 0 0 0 0 0 1 0 0 0 0 0 0 -1 + + 0 0 0 0 0 0 0 0 0 0 0 0 0 1 + ]; + %**** For constant D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri. + for si=1:nStates-1 + for ki=1:kvar Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; - end - end - elseif (indxEqnTv_m(eqninx, 2)==4) % For constant D+**. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri. - for si=1:nStates-1 - for ki=1:kvar - Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; - end - end - else - error('.../ftd_2s_caseall_simszha5v.m: Have not got time to deal with the simple case indxEqnTv_m(eqninx, 2)=5.') - end + end + end +else % Time-varying equations at least for A0_s. For D+_s, constant-parameter equations in general. + %**** For time-varying A0_s. In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi. + Qi(1:nreseqn*nStates,:,eqninx) = [ + 0 0 0 0 0 0 1 0 0 0 0 0 0 0 + + 0 0 0 0 0 0 0 0 0 0 0 0 0 1 + ]; + %**** For D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri. + if (indxEqnTv_m(eqninx, 2)==3) % For constant D+** except the constant term. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri. + for si=1:nStates-1 + for ki=1:kvar-1 % -1: no restrictions on the constant term, which is freely time-varying. + Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; + end + end + elseif (indxEqnTv_m(eqninx, 2)==4) % For constant D+**. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri. + for si=1:nStates-1 + for ki=1:kvar + Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; + end + end + else + error('.../ftd_2s_caseall_simszha5v.m: Have not got time to deal with the simple case indxEqnTv_m(eqninx, 2)=5.') + end end @@ -432,39 +432,39 @@ end eqninx = 7; nreseqn = 0; % Number of linear restrictions for the equation for each state. if (indxEqnTv_m(eqninx, 2)<=2) - %**** For constant A0_s. In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi. - Qi(1:(nStates-1)*nvar+nreseqn,:,eqninx) = [ - 1 0 0 0 0 0 0 -1 0 0 0 0 0 0 - 0 1 0 0 0 0 0 0 -1 0 0 0 0 0 - 0 0 1 0 0 0 0 0 0 -1 0 0 0 0 - 0 0 0 1 0 0 0 0 0 0 -1 0 0 0 - 0 0 0 0 1 0 0 0 0 0 0 -1 0 0 - 0 0 0 0 0 1 0 0 0 0 0 0 -1 0 - 0 0 0 0 0 0 1 0 0 0 0 0 0 -1 - ]; - %**** For constant D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri. - for si=1:nStates-1 - for ki=1:kvar - Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; - end - end -else % Time-varying equations at least for A0_s. For D+_s, constant-parameter equations in general. - %**** For D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri. - if (indxEqnTv_m(eqninx, 2)==3) % For constant D+** except the constant term. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri. - for si=1:nStates-1 - for ki=1:kvar-1 % -1: no restrictions on the constant term, which is freely time-varying. + %**** For constant A0_s. In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi. + Qi(1:(nStates-1)*nvar+nreseqn,:,eqninx) = [ + 1 0 0 0 0 0 0 -1 0 0 0 0 0 0 + 0 1 0 0 0 0 0 0 -1 0 0 0 0 0 + 0 0 1 0 0 0 0 0 0 -1 0 0 0 0 + 0 0 0 1 0 0 0 0 0 0 -1 0 0 0 + 0 0 0 0 1 0 0 0 0 0 0 -1 0 0 + 0 0 0 0 0 1 0 0 0 0 0 0 -1 0 + 0 0 0 0 0 0 1 0 0 0 0 0 0 -1 + ]; + %**** For constant D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri. + for si=1:nStates-1 + for ki=1:kvar Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; - end - end - elseif (indxEqnTv_m(eqninx, 2)==4) % For constant D+**. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri. - for si=1:nStates-1 - for ki=1:kvar - Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; - end - end - else - error('.../ftd_2s_caseall_simszha5v.m: Have not got time to deal with the simple case indxEqnTv_m(eqninx, 2)=5.') - end + end + end +else % Time-varying equations at least for A0_s. For D+_s, constant-parameter equations in general. + %**** For D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri. + if (indxEqnTv_m(eqninx, 2)==3) % For constant D+** except the constant term. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri. + for si=1:nStates-1 + for ki=1:kvar-1 % -1: no restrictions on the constant term, which is freely time-varying. + Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; + end + end + elseif (indxEqnTv_m(eqninx, 2)==4) % For constant D+**. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri. + for si=1:nStates-1 + for ki=1:kvar + Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1]; + end + end + else + error('.../ftd_2s_caseall_simszha5v.m: Have not got time to deal with the simple case indxEqnTv_m(eqninx, 2)=5.') + end end @@ -518,8 +518,8 @@ end for ki=1:nvar % initializing loop for each equation - Ui{ki} = null(Qi(:,:,ki)); - Vi{ki} = null(Ri(:,:,ki)); - n0(ki) = size(Ui{ki},2); - np(ki) = size(Vi{ki},2); + Ui{ki} = null(Qi(:,:,ki)); + Vi{ki} = null(Ri(:,:,ki)); + n0(ki) = size(Ui{ki},2); + np(ki) = size(Vi{ki},2); end diff --git a/tests/ms-sbvar/archive-files/ftd_RSvensson_4v.m b/tests/ms-sbvar/archive-files/ftd_RSvensson_4v.m index 2b24a786ab..2c9f434475 100644 --- a/tests/ms-sbvar/archive-files/ftd_RSvensson_4v.m +++ b/tests/ms-sbvar/archive-files/ftd_RSvensson_4v.m @@ -1,4 +1,4 @@ -function [Ui,Vi,n0,np,ixmC0Pres] = ftd_reac_function_4v(lags,nvar,nexo,indxC0Pres) +function [Ui,Vi,n0,np,ixmC0Pres] = ftd_RSvensson_4v(lags,nvar,nexo,indxC0Pres) % vlist = [ff+ch fh dpgdp ffr) % % Exporting orthonormal matrices for the deterministic linear restrictions (equation by equation) @@ -50,17 +50,17 @@ n0 = zeros(nvar,1); % ith element represents the number of free A0 parameters in np = zeros(nvar,1); % ith element represents the number of free A+ parameters in ith equation if (nargin==2) - nexo = 1; % 1: constant as default where nexo must be a nonnegative integer + nexo = 1; % 1: constant as default where nexo must be a nonnegative integer elseif (nargin==3) - indxC0Pres = 0; % default is no cross-A0-and-A+ restrictions. + indxC0Pres = 0; % default is no cross-A0-and-A+ restrictions. end k = lags*nvar+nexo; % maximum number of lagged and exogenous variables in each equation Qi = zeros(nvar,nvar,nvar); % for nvar contemporaneous equations Ri = zeros(k,k,nvar); % for nvar lagged and exogenous equations - % Row corresponds to equation. 0 means no restriction. - % 1 means exclusion restriction such that the corresponding parameter is restricted to 0. + % Row corresponds to equation. 0 means no restriction. + % 1 means exclusion restriction such that the corresponding parameter is restricted to 0. %nfvar = 6; % number of foreign (Granger causing) variables %nhvar = nvar-nfvar; % number of home (affected) variables. @@ -75,13 +75,13 @@ Qi(1:3,:,1) = [ 0 1 0 0 0 0 1 0 0 0 0 1 - ]; + ]; %======== The second equation =========== Qi(1:2,:,2) = [ 0 0 1 0 0 0 0 1 - ]; + ]; %======== The third equation =========== NOTE THAT WE FORBID A %CONTEMPORANEOUS IMPACT OF OUTPUTON PRICES TO AVOID A CONSTRAINT THAT @@ -90,7 +90,7 @@ Qi(1:3,:,3) = [ 1 0 0 0 0 1 0 0 0 0 0 1 - ]; + ]; %======== The fourth equation =========== @@ -98,34 +98,34 @@ Qi(1:3,:,3) = [ % Restrictions on the A+ in order to focus strictly on the reaction fucntion % indicates free parameterers X i -% Ap = [ +% Ap = [ % X X X X -% X X X X +% X X X X % -a1 -b1 X X % a1 b1 0 X (1st lag) % X X X X -% X X X X +% X X X X % -a2 -b2 X X % b2 b2 0 X (2nd lag) % X 0 X X -% X X X X +% X X X X % -a3 -b3 X X % a3 a3 0 X (3rd lag) % X X X X -% X X X X +% X X X X % -a4 -b4 X X % a4 b4 0 X (4th lag) % X X X X (constant terms) -% ]; +% ]; k=nvar*lags+nexo; Ri = zeros(k,k,nvar); % constraints on IS curve /conso+corporate investment for nv=1:2 -for ll=1:lags -Ri(ll,3+lags*(ll-1),nv)=1; -Ri(ll,4+lags*(ll-1),nv)=1; -end + for ll=1:lags + Ri(ll,3+lags*(ll-1),nv)=1; + Ri(ll,4+lags*(ll-1),nv)=1; + end end % constraints on IS curve /conso+corporate investment only on the long run @@ -140,15 +140,15 @@ end % constraints on Ph curve / inflation does not react to interest rates for ll=1:lags -Ri(ll,4+lags*(ll-1),3)=1; + Ri(ll,4+lags*(ll-1),3)=1; end for n=1:nvar % initializing loop for each equation - Ui{n} = null(Qi(:,:,n)); - Vi{n} = null(Ri(:,:,n)); - n0(n) = size(Ui{n},2); - np(n) = size(Vi{n},2); + Ui{n} = null(Qi(:,:,n)); + Vi{n} = null(Ri(:,:,n)); + n0(n) = size(Ui{n},2); + np(n) = size(Vi{n},2); end @@ -159,30 +159,30 @@ end %(2)------------------------------------------------------------- % if indxC0Pres - neq_cres = 3; % the number of equations in which cross-A0-A+ restrictions occur. - ixmC0Pres = cell(neq_cres,1); % in each cell representing equation, we have 4 columns: - % 1st: the jth column (equation) of A+ or A0: f_j or a_j - % 2nd: the ith element f_j(i) -- the ith element in the jth column of A+ - % 3rd: the hth element a_j(h) -- the hth element in the jth column of A0 - % 4th: the number s such that f_j(i) = s * a_j(h) holds. - %** 1st equation - ixmC0Pres{1} = [1 2 2 1 - 1 7 1 1]; - %** 2nd equation - ixmC0Pres{2} = [2 2 2 2]; - %** 3rd equation - ixmC0Pres{3} = [3 7 1 1 - 3 2 2 1]; - - -% % 4 columns. -% ncres = 5; % manually key in the number of cross-A0-A+ restrictions - -% % 1st: the jth column (equation) of A+ or A0: f_j or a_j -% % 2nd: the ith element f_j(i) -- the ith element in the jth column of A+ -% % 3rd: the hth element a_j(h) -- the hth element in the jth column of A0 -% % 4th: the number s such that f_j(i) = s * a_j(h) holds. + neq_cres = 3; % the number of equations in which cross-A0-A+ restrictions occur. + ixmC0Pres = cell(neq_cres,1); % in each cell representing equation, we have 4 columns: + % 1st: the jth column (equation) of A+ or A0: f_j or a_j + % 2nd: the ith element f_j(i) -- the ith element in the jth column of A+ + % 3rd: the hth element a_j(h) -- the hth element in the jth column of A0 + % 4th: the number s such that f_j(i) = s * a_j(h) holds. + %** 1st equation + ixmC0Pres{1} = [1 2 2 1 + 1 7 1 1]; + %** 2nd equation + ixmC0Pres{2} = [2 2 2 2]; + %** 3rd equation + ixmC0Pres{3} = [3 7 1 1 + 3 2 2 1]; + + + % % 4 columns. + % ncres = 5; % manually key in the number of cross-A0-A+ restrictions + + % % 1st: the jth column (equation) of A+ or A0: f_j or a_j + % % 2nd: the ith element f_j(i) -- the ith element in the jth column of A+ + % % 3rd: the hth element a_j(h) -- the hth element in the jth column of A0 + % % 4th: the number s such that f_j(i) = s * a_j(h) holds. else - ixmC0Pres = NaN; + ixmC0Pres = NaN; end diff --git a/tests/ms-sbvar/archive-files/ftd_cholesky.m b/tests/ms-sbvar/archive-files/ftd_cholesky.m index 42126015ab..7c89c38eab 100644 --- a/tests/ms-sbvar/archive-files/ftd_cholesky.m +++ b/tests/ms-sbvar/archive-files/ftd_cholesky.m @@ -47,17 +47,17 @@ n0 = zeros(nvar,1); % ith element represents the number of free A0 parameters in np = zeros(nvar,1); % ith element represents the number of free A+ parameters in ith equation if (nargin==2) - nexo = 1; % 1: constant as default where nexo must be a nonnegative integer + nexo = 1; % 1: constant as default where nexo must be a nonnegative integer elseif (nargin==3) - indxC0Pres = 0; % default is no cross-A0-and-A+ restrictions. + indxC0Pres = 0; % default is no cross-A0-and-A+ restrictions. end k = lags*nvar+nexo; % maximum number of lagged and exogenous variables in each equation Qi = zeros(nvar,nvar,nvar); % for nvar contemporaneous equations Ri = zeros(k,k,nvar); % for nvar lagged and exogenous equations - % Row corresponds to equation. 0 means no restriction. - % 1 means exclusion restriction such that the corresponding parameter is restricted to 0. + % Row corresponds to equation. 0 means no restriction. + % 1 means exclusion restriction such that the corresponding parameter is restricted to 0. %nfvar = 6; % number of foreign (Granger causing) variables %nhvar = nvar-nfvar; % number of home (affected) variables. @@ -69,146 +69,146 @@ Ri = zeros(k,k,nvar); % for nvar lagged and exogenous equations %The restrictions considered here are in the following form where X means unrestricted: % A0 = [ % X 0 X X -% 0 X X X -% 0 0 X X -% 0 0 0 X -% ]; -% Ap = [ +% 0 X X X +% 0 0 X X +% 0 0 0 X +% ]; +% Ap = [ % X 0 X X -% 0 X X X +% 0 X X X % 0 0 X X % 0 0 X X (1st lag) % X 0 X X -% 0 X X X +% 0 X X X % 0 0 X X % 0 0 X X (2nd lag) % X 0 X X -% 0 X X X +% 0 X X X % 0 0 X X % 0 0 X X (3rd lag) % X 0 X X -% 0 X X X +% 0 X X X % 0 0 X X % 0 0 X X (4th lag) % 0 X 0 0 (constant terms) -% ]; +% ]; if (0) - %------------------------ Lower triangular A0 ------------------------------ - %======== The first equation =========== - - - %======== The second equation =========== - Qi(1:1,:,2) = [ - 1 0 0 0 - ]; - - %======== The third equation =========== - Qi(1:2,:,3) = [ - 1 0 0 0 - 0 1 0 0 - ]; - - %======== The fourth equation =========== - Qi(1:3,:,4) = [ - 1 0 0 0 - 0 1 0 0 - 0 0 1 0 - ]; + %------------------------ Lower triangular A0 ------------------------------ + %======== The first equation =========== + + + %======== The second equation =========== + Qi(1:1,:,2) = [ + 1 0 0 0 + ]; + + %======== The third equation =========== + Qi(1:2,:,3) = [ + 1 0 0 0 + 0 1 0 0 + ]; + + %======== The fourth equation =========== + Qi(1:3,:,4) = [ + 1 0 0 0 + 0 1 0 0 + 0 0 1 0 + ]; else - %------------------------ Upper triangular A0 ------------------------------ - %======== The first equation =========== - Qi(2:4,:,1) = [ - 0 1 0 0 - 0 0 1 0 - 0 0 0 1 - ]; - - %======== The second equation =========== - Qi([1 3:4],:,2) = [ - 1 0 0 0 - 0 0 1 0 - 0 0 0 1 - ]; - - %======== The third equation =========== - Qi(4:4,:,3) = [ - 0 0 0 1 - ]; - - %======== The fourth equation =========== + %------------------------ Upper triangular A0 ------------------------------ + %======== The first equation =========== + Qi(2:4,:,1) = [ + 0 1 0 0 + 0 0 1 0 + 0 0 0 1 + ]; + + %======== The second equation =========== + Qi([1 3:4],:,2) = [ + 1 0 0 0 + 0 0 1 0 + 0 0 0 1 + ]; + + %======== The third equation =========== + Qi(4:4,:,3) = [ + 0 0 0 1 + ]; + + %======== The fourth equation =========== end %-------------------------- Lag restrictions. ------------------------------------------ if (1) - %--- Lag restrictions. - indxeqn = 1; %Which equation. - nrestrs = (nvar-1)*lags+1; %Number of restrictions. - vars_restr = [2:nvar]; %Variables that are restricted: id, ik, and y. - blags = zeros(nrestrs,k); %k=nvar*lags+1 - cnt = 0; - for ki = 1:lags - for kj=vars_restr - cnt = cnt+1; - blags(cnt,nvar*(ki-1)+kj) = 1; - end - end - %--- Keep constant zero. - cnt = cnt+1; - blags(cnt,end) = 1; %Constant = 0. - if cnt~=nrestrs - error('Check lagged restrictions in 1st equation!') - end - Ri(1:nrestrs,:,indxeqn) = blags; - - %--- Lag restrictions. - indxeqn = 2; %Which equation. - nrestrs = (nvar-1)*lags; %Number of restrictions. - vars_restr = [1 3:nvar]; %Variables that are restricted: id, ik, and y. - blags = zeros(nrestrs,k); %k=nvar*lags+1 - cnt = 0; - for ki = 1:lags - for kj=vars_restr - cnt = cnt+1; - blags(cnt,nvar*(ki-1)+kj) = 1; - end - end - Ri(1:nrestrs,:,indxeqn) = blags; - - %--- Lag restrictions. - indxeqn = 3; %Which equation. - nrestrs = 1; %Number of restrictions. - blags = zeros(nrestrs,k); - cnt = 0; - %--- Keep constant zero. - cnt = cnt+1; - blags(cnt,end) = 1; %Constant = 0. - if cnt~=nrestrs - error('Check lagged restrictions in 1st equation!') - end - Ri(1:nrestrs,:,indxeqn) = blags; - - %--- Lag restrictions. - indxeqn = 4; %Which equation. - nrestrs = 1; %Number of restrictions. - blags = zeros(nrestrs,k); - cnt = 0; - %--- Keep constant zero. - cnt = cnt+1; - blags(cnt,end) = 1; %Constant = 0. - if cnt~=nrestrs - error('Check lagged restrictions in 1st equation!') - end - Ri(1:nrestrs,:,indxeqn) = blags; + %--- Lag restrictions. + indxeqn = 1; %Which equation. + nrestrs = (nvar-1)*lags+1; %Number of restrictions. + vars_restr = [2:nvar]; %Variables that are restricted: id, ik, and y. + blags = zeros(nrestrs,k); %k=nvar*lags+1 + cnt = 0; + for ki = 1:lags + for kj=vars_restr + cnt = cnt+1; + blags(cnt,nvar*(ki-1)+kj) = 1; + end + end + %--- Keep constant zero. + cnt = cnt+1; + blags(cnt,end) = 1; %Constant = 0. + if cnt~=nrestrs + error('Check lagged restrictions in 1st equation!') + end + Ri(1:nrestrs,:,indxeqn) = blags; + + %--- Lag restrictions. + indxeqn = 2; %Which equation. + nrestrs = (nvar-1)*lags; %Number of restrictions. + vars_restr = [1 3:nvar]; %Variables that are restricted: id, ik, and y. + blags = zeros(nrestrs,k); %k=nvar*lags+1 + cnt = 0; + for ki = 1:lags + for kj=vars_restr + cnt = cnt+1; + blags(cnt,nvar*(ki-1)+kj) = 1; + end + end + Ri(1:nrestrs,:,indxeqn) = blags; + + %--- Lag restrictions. + indxeqn = 3; %Which equation. + nrestrs = 1; %Number of restrictions. + blags = zeros(nrestrs,k); + cnt = 0; + %--- Keep constant zero. + cnt = cnt+1; + blags(cnt,end) = 1; %Constant = 0. + if cnt~=nrestrs + error('Check lagged restrictions in 1st equation!') + end + Ri(1:nrestrs,:,indxeqn) = blags; + + %--- Lag restrictions. + indxeqn = 4; %Which equation. + nrestrs = 1; %Number of restrictions. + blags = zeros(nrestrs,k); + cnt = 0; + %--- Keep constant zero. + cnt = cnt+1; + blags(cnt,end) = 1; %Constant = 0. + if cnt~=nrestrs + error('Check lagged restrictions in 1st equation!') + end + Ri(1:nrestrs,:,indxeqn) = blags; end for n=1:nvar % initializing loop for each equation - Ui{n} = null(Qi(:,:,n)); - Vi{n} = null(Ri(:,:,n)); - n0(n) = size(Ui{n},2); - np(n) = size(Vi{n},2); + Ui{n} = null(Qi(:,:,n)); + Vi{n} = null(Ri(:,:,n)); + n0(n) = size(Ui{n},2); + np(n) = size(Vi{n},2); end @@ -222,30 +222,30 @@ end %(2)------------------------------------------------------------- % if indxC0Pres - neq_cres = 3; % the number of equations in which cross-A0-A+ restrictions occur. - ixmC0Pres = cell(neq_cres,1); % in each cell representing equation, we have 4 columns: - % 1st: the jth column (equation) of A+ or A0: f_j or a_j - % 2nd: the ith element f_j(i) -- the ith element in the jth column of A+ - % 3rd: the hth element a_j(h) -- the hth element in the jth column of A0 - % 4th: the number s such that f_j(i) = s * a_j(h) holds. - %** 1st equation - ixmC0Pres{1} = [1 2 2 1 - 1 7 1 1]; - %** 2nd equation - ixmC0Pres{2} = [2 2 2 2]; - %** 3rd equation - ixmC0Pres{3} = [3 7 1 1 - 3 2 2 1]; - - -% % 4 columns. -% ncres = 5; % manually key in the number of cross-A0-A+ restrictions - -% % 1st: the jth column (equation) of A+ or A0: f_j or a_j -% % 2nd: the ith element f_j(i) -- the ith element in the jth column of A+ -% % 3rd: the hth element a_j(h) -- the hth element in the jth column of A0 -% % 4th: the number s such that f_j(i) = s * a_j(h) holds. + neq_cres = 3; % the number of equations in which cross-A0-A+ restrictions occur. + ixmC0Pres = cell(neq_cres,1); % in each cell representing equation, we have 4 columns: + % 1st: the jth column (equation) of A+ or A0: f_j or a_j + % 2nd: the ith element f_j(i) -- the ith element in the jth column of A+ + % 3rd: the hth element a_j(h) -- the hth element in the jth column of A0 + % 4th: the number s such that f_j(i) = s * a_j(h) holds. + %** 1st equation + ixmC0Pres{1} = [1 2 2 1 + 1 7 1 1]; + %** 2nd equation + ixmC0Pres{2} = [2 2 2 2]; + %** 3rd equation + ixmC0Pres{3} = [3 7 1 1 + 3 2 2 1]; + + + % % 4 columns. + % ncres = 5; % manually key in the number of cross-A0-A+ restrictions + + % % 1st: the jth column (equation) of A+ or A0: f_j or a_j + % % 2nd: the ith element f_j(i) -- the ith element in the jth column of A+ + % % 3rd: the hth element a_j(h) -- the hth element in the jth column of A0 + % % 4th: the number s such that f_j(i) = s * a_j(h) holds. else - ixmC0Pres = NaN; + ixmC0Pres = NaN; end diff --git a/tests/ms-sbvar/archive-files/ftd_non_rec_5v.m b/tests/ms-sbvar/archive-files/ftd_non_rec_5v.m index e9fbeb4099..ba328cb3de 100644 --- a/tests/ms-sbvar/archive-files/ftd_non_rec_5v.m +++ b/tests/ms-sbvar/archive-files/ftd_non_rec_5v.m @@ -1,4 +1,4 @@ -function [Ui,Vi,n0,np,ixmC0Pres] = ftd_upperchol5v(lags,nvar,nexo,indxC0Pres) +function [Ui,Vi,n0,np,ixmC0Pres] = ftd_non_rec_5v(lags,nvar,nexo,indxC0Pres) % vlist = [127 124 93 141 21]; % 1: GDP; 2: GDP deflator 124 (consumption deflator 79); 3: R; 4: M3 141 (M2 140); 5: exchange rate 21. % varlist={'y', 'P', 'R', 'M3', 'Ex'}; % @@ -45,17 +45,17 @@ n0 = zeros(nvar,1); % ith element represents the number of free A0 parameters in np = zeros(nvar,1); % ith element represents the number of free A+ parameters in ith equation if (nargin==2) - nexo = 1; % 1: constant as default where nexo must be a nonnegative integer + nexo = 1; % 1: constant as default where nexo must be a nonnegative integer elseif (nargin==3) - indxC0Pres = 0; % default is no cross-A0-and-A+ restrictions. + indxC0Pres = 0; % default is no cross-A0-and-A+ restrictions. end k = lags*nvar+nexo; % maximum number of lagged and exogenous variables in each equation Qi = zeros(nvar,nvar,nvar); % for nvar contemporaneous equations Ri = zeros(k,k,nvar); % for nvar lagged and exogenous equations - % Row corresponds to equation. 0 means no restriction. - % 1 means exclusion restriction such that the corresponding parameter is restricted to 0. + % Row corresponds to equation. 0 means no restriction. + % 1 means exclusion restriction such that the corresponding parameter is restricted to 0. %nfvar = 6; % number of foreign (Granger causing) variables %nhvar = nvar-nfvar; % number of home (affected) variables. @@ -71,20 +71,20 @@ Qi(1:4,:,1) = [ 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 - ]; + ]; %======== The second equation =========== Qi(1:3,:,2) = [ 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 - ]; + ]; %======== The third equation =========== Qi(1:2,:,3) = [ 0 0 0 1 0 0 0 0 0 1 - ]; + ]; %======== The fourth equation =========== @@ -99,7 +99,7 @@ Qi(1:3,:,5) = [ 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 - ]; + ]; @@ -149,10 +149,10 @@ Qi(1:3,:,5) = [ for n=1:nvar % initializing loop for each equation - Ui{n} = null(Qi(:,:,n)); - Vi{n} = null(Ri(:,:,n)); - n0(n) = size(Ui{n},2); - np(n) = size(Vi{n},2); + Ui{n} = null(Qi(:,:,n)); + Vi{n} = null(Ri(:,:,n)); + n0(n) = size(Ui{n},2); + np(n) = size(Vi{n},2); end @@ -163,30 +163,30 @@ end %(2)------------------------------------------------------------- % if indxC0Pres - neq_cres = 3; % the number of equations in which cross-A0-A+ restrictions occur. - ixmC0Pres = cell(neq_cres,1); % in each cell representing equation, we have 4 columns: - % 1st: the jth column (equation) of A+ or A0: f_j or a_j - % 2nd: the ith element f_j(i) -- the ith element in the jth column of A+ - % 3rd: the hth element a_j(h) -- the hth element in the jth column of A0 - % 4th: the number s such that f_j(i) = s * a_j(h) holds. - %** 1st equation - ixmC0Pres{1} = [1 2 2 1 - 1 7 1 1]; - %** 2nd equation - ixmC0Pres{2} = [2 2 2 2]; - %** 3rd equation - ixmC0Pres{3} = [3 7 1 1 - 3 2 2 1]; - - -% % 4 columns. -% ncres = 5; % manually key in the number of cross-A0-A+ restrictions - -% % 1st: the jth column (equation) of A+ or A0: f_j or a_j -% % 2nd: the ith element f_j(i) -- the ith element in the jth column of A+ -% % 3rd: the hth element a_j(h) -- the hth element in the jth column of A0 -% % 4th: the number s such that f_j(i) = s * a_j(h) holds. + neq_cres = 3; % the number of equations in which cross-A0-A+ restrictions occur. + ixmC0Pres = cell(neq_cres,1); % in each cell representing equation, we have 4 columns: + % 1st: the jth column (equation) of A+ or A0: f_j or a_j + % 2nd: the ith element f_j(i) -- the ith element in the jth column of A+ + % 3rd: the hth element a_j(h) -- the hth element in the jth column of A0 + % 4th: the number s such that f_j(i) = s * a_j(h) holds. + %** 1st equation + ixmC0Pres{1} = [1 2 2 1 + 1 7 1 1]; + %** 2nd equation + ixmC0Pres{2} = [2 2 2 2]; + %** 3rd equation + ixmC0Pres{3} = [3 7 1 1 + 3 2 2 1]; + + + % % 4 columns. + % ncres = 5; % manually key in the number of cross-A0-A+ restrictions + + % % 1st: the jth column (equation) of A+ or A0: f_j or a_j + % % 2nd: the ith element f_j(i) -- the ith element in the jth column of A+ + % % 3rd: the hth element a_j(h) -- the hth element in the jth column of A0 + % % 4th: the number s such that f_j(i) = s * a_j(h) holds. else - ixmC0Pres = NaN; + ixmC0Pres = NaN; end diff --git a/tests/ms-sbvar/archive-files/ftd_simszha5v.m b/tests/ms-sbvar/archive-files/ftd_simszha5v.m index 0a0034a9d0..a48168fc6a 100644 --- a/tests/ms-sbvar/archive-files/ftd_simszha5v.m +++ b/tests/ms-sbvar/archive-files/ftd_simszha5v.m @@ -45,17 +45,17 @@ n0 = zeros(nvar,1); % ith element represents the number of free A0 parameters in np = zeros(nvar,1); % ith element represents the number of free A+ parameters in ith equation if (nargin==2) - nexo = 1; % 1: constant as default where nexo must be a nonnegative integer + nexo = 1; % 1: constant as default where nexo must be a nonnegative integer elseif (nargin==3) - indxC0Pres = 0; % default is no cross-A0-and-A+ restrictions. + indxC0Pres = 0; % default is no cross-A0-and-A+ restrictions. end k = lags*nvar+nexo; % maximum number of lagged and exogenous variables in each equation Qi = zeros(nvar,nvar,nvar); % for nvar contemporaneous equations Ri = zeros(k,k,nvar); % for nvar lagged and exogenous equations - % Row corresponds to equation. 0 means no restriction. - % 1 means exclusion restriction such that the corresponding parameter is restricted to 0. + % Row corresponds to equation. 0 means no restriction. + % 1 means exclusion restriction such that the corresponding parameter is restricted to 0. %nfvar = 6; % number of foreign (Granger causing) variables %nhvar = nvar-nfvar; % number of home (affected) variables. @@ -75,30 +75,30 @@ Ri = zeros(k,k,nvar); % for nvar lagged and exogenous equations % 0 0 0 0 1 % ]; % Respond to Pcom. Qi(1:3,:,2) = [ - 1 0 0 0 0 - 0 0 0 1 0 - 0 0 0 0 1 - ]; % Not respond to Pcom. + 1 0 0 0 0 + 0 0 0 1 0 + 0 0 0 0 1 + ]; % Not respond to Pcom. %======== The third equation: money demand =========== Qi(1,:,3) = [ - 1 0 0 0 0 - ]; + 1 0 0 0 0 + ]; %======== The fourth equation: y equation =========== Qi(1:4,:,4) = [ - 1 0 0 0 0 - 0 1 0 0 0 - 0 0 1 0 0 - 0 0 0 0 1 - ]; + 1 0 0 0 0 + 0 1 0 0 0 + 0 0 1 0 0 + 0 0 0 0 1 + ]; %======== The fifth equation: p equation =========== Qi(1:3,:,5) = [ - 1 0 0 0 0 - 0 1 0 0 0 - 0 0 1 0 0 - ]; + 1 0 0 0 0 + 0 1 0 0 0 + 0 0 1 0 0 + ]; %===== Lagged restrictions in foreign (Granger causing) block @@ -147,10 +147,10 @@ Qi(1:3,:,5) = [ for n=1:nvar % initializing loop for each equation - Ui{n} = null(Qi(:,:,n)); - Vi{n} = null(Ri(:,:,n)); - n0(n) = size(Ui{n},2); - np(n) = size(Vi{n},2); + Ui{n} = null(Qi(:,:,n)); + Vi{n} = null(Ri(:,:,n)); + n0(n) = size(Ui{n},2); + np(n) = size(Vi{n},2); end @@ -161,30 +161,30 @@ end %(2)------------------------------------------------------------- % if indxC0Pres - neq_cres = 3; % the number of equations in which cross-A0-A+ restrictions occur. - ixmC0Pres = cell(neq_cres,1); % in each cell representing equation, we have 4 columns: - % 1st: the jth column (equation) of A+ or A0: f_j or a_j - % 2nd: the ith element f_j(i) -- the ith element in the jth column of A+ - % 3rd: the hth element a_j(h) -- the hth element in the jth column of A0 - % 4th: the number s such that f_j(i) = s * a_j(h) holds. - %** 1st equation - ixmC0Pres{1} = [1 2 2 1 - 1 7 1 1]; - %** 2nd equation - ixmC0Pres{2} = [2 2 2 2]; - %** 3rd equation - ixmC0Pres{3} = [3 7 1 1 - 3 2 2 1]; - - -% % 4 columns. -% ncres = 5; % manually key in the number of cross-A0-A+ restrictions - -% % 1st: the jth column (equation) of A+ or A0: f_j or a_j -% % 2nd: the ith element f_j(i) -- the ith element in the jth column of A+ -% % 3rd: the hth element a_j(h) -- the hth element in the jth column of A0 -% % 4th: the number s such that f_j(i) = s * a_j(h) holds. + neq_cres = 3; % the number of equations in which cross-A0-A+ restrictions occur. + ixmC0Pres = cell(neq_cres,1); % in each cell representing equation, we have 4 columns: + % 1st: the jth column (equation) of A+ or A0: f_j or a_j + % 2nd: the ith element f_j(i) -- the ith element in the jth column of A+ + % 3rd: the hth element a_j(h) -- the hth element in the jth column of A0 + % 4th: the number s such that f_j(i) = s * a_j(h) holds. + %** 1st equation + ixmC0Pres{1} = [1 2 2 1 + 1 7 1 1]; + %** 2nd equation + ixmC0Pres{2} = [2 2 2 2]; + %** 3rd equation + ixmC0Pres{3} = [3 7 1 1 + 3 2 2 1]; + + + % % 4 columns. + % ncres = 5; % manually key in the number of cross-A0-A+ restrictions + + % % 1st: the jth column (equation) of A+ or A0: f_j or a_j + % % 2nd: the ith element f_j(i) -- the ith element in the jth column of A+ + % % 3rd: the hth element a_j(h) -- the hth element in the jth column of A0 + % % 4th: the number s such that f_j(i) = s * a_j(h) holds. else - ixmC0Pres = NaN; + ixmC0Pres = NaN; end diff --git a/tests/ms-sbvar/archive-files/ftd_upperchol3v.m b/tests/ms-sbvar/archive-files/ftd_upperchol3v.m index a5c19f79e8..4c221df74f 100644 --- a/tests/ms-sbvar/archive-files/ftd_upperchol3v.m +++ b/tests/ms-sbvar/archive-files/ftd_upperchol3v.m @@ -44,17 +44,17 @@ n0 = zeros(nvar,1); % ith element represents the number of free A0 parameters in np = zeros(nvar,1); % ith element represents the number of free A+ parameters in ith equation if (nargin==2) - nexo = 1; % 1: constant as default where nexo must be a nonnegative integer + nexo = 1; % 1: constant as default where nexo must be a nonnegative integer elseif (nargin==3) - indxC0Pres = 0; % default is no cross-A0-and-A+ restrictions. + indxC0Pres = 0; % default is no cross-A0-and-A+ restrictions. end k = lags*nvar+nexo; % maximum number of lagged and exogenous variables in each equation Qi = zeros(nvar,nvar,nvar); % for nvar contemporaneous equations Ri = zeros(k,k,nvar); % for nvar lagged and exogenous equations - % Row corresponds to equation. 0 means no restriction. - % 1 means exclusion restriction such that the corresponding parameter is restricted to 0. + % Row corresponds to equation. 0 means no restriction. + % 1 means exclusion restriction such that the corresponding parameter is restricted to 0. %nfvar = 6; % number of foreign (Granger causing) variables %nhvar = nvar-nfvar; % number of home (affected) variables. @@ -69,12 +69,12 @@ Ri = zeros(k,k,nvar); % for nvar lagged and exogenous equations Qi(1:2,:,1) = [ 0 1 0 0 0 1 - ]; + ]; %======== The second equation =========== Qi(1:1,:,2) = [ 0 0 1 - ]; + ]; %======== The third equation =========== @@ -127,10 +127,10 @@ Qi(1:1,:,2) = [ for n=1:nvar % initializing loop for each equation - Ui{n} = null(Qi(:,:,n)); - Vi{n} = null(Ri(:,:,n)); - n0(n) = size(Ui{n},2); - np(n) = size(Vi{n},2); + Ui{n} = null(Qi(:,:,n)); + Vi{n} = null(Ri(:,:,n)); + n0(n) = size(Ui{n},2); + np(n) = size(Vi{n},2); end @@ -141,30 +141,30 @@ end %(2)------------------------------------------------------------- % if indxC0Pres - neq_cres = 3; % the number of equations in which cross-A0-A+ restrictions occur. - ixmC0Pres = cell(neq_cres,1); % in each cell representing equation, we have 4 columns: - % 1st: the jth column (equation) of A+ or A0: f_j or a_j - % 2nd: the ith element f_j(i) -- the ith element in the jth column of A+ - % 3rd: the hth element a_j(h) -- the hth element in the jth column of A0 - % 4th: the number s such that f_j(i) = s * a_j(h) holds. - %** 1st equation - ixmC0Pres{1} = [1 2 2 1 - 1 7 1 1]; - %** 2nd equation - ixmC0Pres{2} = [2 2 2 2]; - %** 3rd equation - ixmC0Pres{3} = [3 7 1 1 - 3 2 2 1]; - - -% % 4 columns. -% ncres = 5; % manually key in the number of cross-A0-A+ restrictions - -% % 1st: the jth column (equation) of A+ or A0: f_j or a_j -% % 2nd: the ith element f_j(i) -- the ith element in the jth column of A+ -% % 3rd: the hth element a_j(h) -- the hth element in the jth column of A0 -% % 4th: the number s such that f_j(i) = s * a_j(h) holds. + neq_cres = 3; % the number of equations in which cross-A0-A+ restrictions occur. + ixmC0Pres = cell(neq_cres,1); % in each cell representing equation, we have 4 columns: + % 1st: the jth column (equation) of A+ or A0: f_j or a_j + % 2nd: the ith element f_j(i) -- the ith element in the jth column of A+ + % 3rd: the hth element a_j(h) -- the hth element in the jth column of A0 + % 4th: the number s such that f_j(i) = s * a_j(h) holds. + %** 1st equation + ixmC0Pres{1} = [1 2 2 1 + 1 7 1 1]; + %** 2nd equation + ixmC0Pres{2} = [2 2 2 2]; + %** 3rd equation + ixmC0Pres{3} = [3 7 1 1 + 3 2 2 1]; + + + % % 4 columns. + % ncres = 5; % manually key in the number of cross-A0-A+ restrictions + + % % 1st: the jth column (equation) of A+ or A0: f_j or a_j + % % 2nd: the ith element f_j(i) -- the ith element in the jth column of A+ + % % 3rd: the hth element a_j(h) -- the hth element in the jth column of A0 + % % 4th: the number s such that f_j(i) = s * a_j(h) holds. else - ixmC0Pres = NaN; + ixmC0Pres = NaN; end diff --git a/tests/ms-sbvar/archive-files/ftd_upperchol4v.m b/tests/ms-sbvar/archive-files/ftd_upperchol4v.m index aadac9512f..db0b9c371a 100644 --- a/tests/ms-sbvar/archive-files/ftd_upperchol4v.m +++ b/tests/ms-sbvar/archive-files/ftd_upperchol4v.m @@ -45,17 +45,17 @@ n0 = zeros(nvar,1); % ith element represents the number of free A0 parameters in np = zeros(nvar,1); % ith element represents the number of free A+ parameters in ith equation if (nargin==2) - nexo = 1; % 1: constant as default where nexo must be a nonnegative integer + nexo = 1; % 1: constant as default where nexo must be a nonnegative integer elseif (nargin==3) - indxC0Pres = 0; % default is no cross-A0-and-A+ restrictions. + indxC0Pres = 0; % default is no cross-A0-and-A+ restrictions. end k = lags*nvar+nexo; % maximum number of lagged and exogenous variables in each equation Qi = zeros(nvar,nvar,nvar); % for nvar contemporaneous equations Ri = zeros(k,k,nvar); % for nvar lagged and exogenous equations - % Row corresponds to equation. 0 means no restriction. - % 1 means exclusion restriction such that the corresponding parameter is restricted to 0. + % Row corresponds to equation. 0 means no restriction. + % 1 means exclusion restriction such that the corresponding parameter is restricted to 0. %nfvar = 6; % number of foreign (Granger causing) variables %nhvar = nvar-nfvar; % number of home (affected) variables. @@ -70,18 +70,18 @@ Qi(1:3,:,1) = [ 0 1 0 0 0 0 1 0 0 0 0 1 - ]; + ]; %======== The second equation =========== Qi(1:2,:,2) = [ 0 0 1 0 0 0 0 1 - ]; + ]; %======== The third equation =========== Qi(1:1,:,3) = [ 0 0 0 1 - ]; + ]; %======== The fourth equation =========== @@ -135,10 +135,10 @@ Qi(1:1,:,3) = [ for n=1:nvar % initializing loop for each equation - Ui{n} = null(Qi(:,:,n)); - Vi{n} = null(Ri(:,:,n)); - n0(n) = size(Ui{n},2); - np(n) = size(Vi{n},2); + Ui{n} = null(Qi(:,:,n)); + Vi{n} = null(Ri(:,:,n)); + n0(n) = size(Ui{n},2); + np(n) = size(Vi{n},2); end @@ -149,30 +149,30 @@ end %(2)------------------------------------------------------------- % if indxC0Pres - neq_cres = 3; % the number of equations in which cross-A0-A+ restrictions occur. - ixmC0Pres = cell(neq_cres,1); % in each cell representing equation, we have 4 columns: - % 1st: the jth column (equation) of A+ or A0: f_j or a_j - % 2nd: the ith element f_j(i) -- the ith element in the jth column of A+ - % 3rd: the hth element a_j(h) -- the hth element in the jth column of A0 - % 4th: the number s such that f_j(i) = s * a_j(h) holds. - %** 1st equation - ixmC0Pres{1} = [1 2 2 1 - 1 7 1 1]; - %** 2nd equation - ixmC0Pres{2} = [2 2 2 2]; - %** 3rd equation - ixmC0Pres{3} = [3 7 1 1 - 3 2 2 1]; - - -% % 4 columns. -% ncres = 5; % manually key in the number of cross-A0-A+ restrictions - -% % 1st: the jth column (equation) of A+ or A0: f_j or a_j -% % 2nd: the ith element f_j(i) -- the ith element in the jth column of A+ -% % 3rd: the hth element a_j(h) -- the hth element in the jth column of A0 -% % 4th: the number s such that f_j(i) = s * a_j(h) holds. + neq_cres = 3; % the number of equations in which cross-A0-A+ restrictions occur. + ixmC0Pres = cell(neq_cres,1); % in each cell representing equation, we have 4 columns: + % 1st: the jth column (equation) of A+ or A0: f_j or a_j + % 2nd: the ith element f_j(i) -- the ith element in the jth column of A+ + % 3rd: the hth element a_j(h) -- the hth element in the jth column of A0 + % 4th: the number s such that f_j(i) = s * a_j(h) holds. + %** 1st equation + ixmC0Pres{1} = [1 2 2 1 + 1 7 1 1]; + %** 2nd equation + ixmC0Pres{2} = [2 2 2 2]; + %** 3rd equation + ixmC0Pres{3} = [3 7 1 1 + 3 2 2 1]; + + + % % 4 columns. + % ncres = 5; % manually key in the number of cross-A0-A+ restrictions + + % % 1st: the jth column (equation) of A+ or A0: f_j or a_j + % % 2nd: the ith element f_j(i) -- the ith element in the jth column of A+ + % % 3rd: the hth element a_j(h) -- the hth element in the jth column of A0 + % % 4th: the number s such that f_j(i) = s * a_j(h) holds. else - ixmC0Pres = NaN; + ixmC0Pres = NaN; end diff --git a/tests/ms-sbvar/archive-files/ftd_upperchol5v.m b/tests/ms-sbvar/archive-files/ftd_upperchol5v.m index b41a60c174..948d0c0d19 100644 --- a/tests/ms-sbvar/archive-files/ftd_upperchol5v.m +++ b/tests/ms-sbvar/archive-files/ftd_upperchol5v.m @@ -45,17 +45,17 @@ n0 = zeros(nvar,1); % ith element represents the number of free A0 parameters in np = zeros(nvar,1); % ith element represents the number of free A+ parameters in ith equation if (nargin==2) - nexo = 1; % 1: constant as default where nexo must be a nonnegative integer + nexo = 1; % 1: constant as default where nexo must be a nonnegative integer elseif (nargin==3) - indxC0Pres = 0; % default is no cross-A0-and-A+ restrictions. + indxC0Pres = 0; % default is no cross-A0-and-A+ restrictions. end k = lags*nvar+nexo; % maximum number of lagged and exogenous variables in each equation Qi = zeros(nvar,nvar,nvar); % for nvar contemporaneous equations Ri = zeros(k,k,nvar); % for nvar lagged and exogenous equations - % Row corresponds to equation. 0 means no restriction. - % 1 means exclusion restriction such that the corresponding parameter is restricted to 0. + % Row corresponds to equation. 0 means no restriction. + % 1 means exclusion restriction such that the corresponding parameter is restricted to 0. %nfvar = 6; % number of foreign (Granger causing) variables %nhvar = nvar-nfvar; % number of home (affected) variables. @@ -71,26 +71,26 @@ Qi(1:4,:,1) = [ 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 - ]; + ]; %======== The second equation =========== Qi(1:3,:,2) = [ 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 - ]; + ]; %======== The third equation =========== Qi(1:2,:,3) = [ 0 0 0 1 0 0 0 0 0 1 - ]; + ]; %======== The fourth equation =========== Qi(1:1,:,4) = [ 0 0 0 0 1 - ]; + ]; %======== The fifth equation =========== @@ -144,10 +144,10 @@ Qi(1:1,:,4) = [ for n=1:nvar % initializing loop for each equation - Ui{n} = null(Qi(:,:,n)); - Vi{n} = null(Ri(:,:,n)); - n0(n) = size(Ui{n},2); - np(n) = size(Vi{n},2); + Ui{n} = null(Qi(:,:,n)); + Vi{n} = null(Ri(:,:,n)); + n0(n) = size(Ui{n},2); + np(n) = size(Vi{n},2); end @@ -158,30 +158,30 @@ end %(2)------------------------------------------------------------- % if indxC0Pres - neq_cres = 3; % the number of equations in which cross-A0-A+ restrictions occur. - ixmC0Pres = cell(neq_cres,1); % in each cell representing equation, we have 4 columns: - % 1st: the jth column (equation) of A+ or A0: f_j or a_j - % 2nd: the ith element f_j(i) -- the ith element in the jth column of A+ - % 3rd: the hth element a_j(h) -- the hth element in the jth column of A0 - % 4th: the number s such that f_j(i) = s * a_j(h) holds. - %** 1st equation - ixmC0Pres{1} = [1 2 2 1 - 1 7 1 1]; - %** 2nd equation - ixmC0Pres{2} = [2 2 2 2]; - %** 3rd equation - ixmC0Pres{3} = [3 7 1 1 - 3 2 2 1]; - - -% % 4 columns. -% ncres = 5; % manually key in the number of cross-A0-A+ restrictions - -% % 1st: the jth column (equation) of A+ or A0: f_j or a_j -% % 2nd: the ith element f_j(i) -- the ith element in the jth column of A+ -% % 3rd: the hth element a_j(h) -- the hth element in the jth column of A0 -% % 4th: the number s such that f_j(i) = s * a_j(h) holds. + neq_cres = 3; % the number of equations in which cross-A0-A+ restrictions occur. + ixmC0Pres = cell(neq_cres,1); % in each cell representing equation, we have 4 columns: + % 1st: the jth column (equation) of A+ or A0: f_j or a_j + % 2nd: the ith element f_j(i) -- the ith element in the jth column of A+ + % 3rd: the hth element a_j(h) -- the hth element in the jth column of A0 + % 4th: the number s such that f_j(i) = s * a_j(h) holds. + %** 1st equation + ixmC0Pres{1} = [1 2 2 1 + 1 7 1 1]; + %** 2nd equation + ixmC0Pres{2} = [2 2 2 2]; + %** 3rd equation + ixmC0Pres{3} = [3 7 1 1 + 3 2 2 1]; + + + % % 4 columns. + % ncres = 5; % manually key in the number of cross-A0-A+ restrictions + + % % 1st: the jth column (equation) of A+ or A0: f_j or a_j + % % 2nd: the ith element f_j(i) -- the ith element in the jth column of A+ + % % 3rd: the hth element a_j(h) -- the hth element in the jth column of A0 + % % 4th: the number s such that f_j(i) = s * a_j(h) holds. else - ixmC0Pres = NaN; + ixmC0Pres = NaN; end diff --git a/tests/ms-sbvar/archive-files/ftd_upperchol6v.m b/tests/ms-sbvar/archive-files/ftd_upperchol6v.m index c6560ffd98..462704c240 100644 --- a/tests/ms-sbvar/archive-files/ftd_upperchol6v.m +++ b/tests/ms-sbvar/archive-files/ftd_upperchol6v.m @@ -45,17 +45,17 @@ n0 = zeros(nvar,1); % ith element represents the number of free A0 parameters in np = zeros(nvar,1); % ith element represents the number of free A+ parameters in ith equation if (nargin==2) - nexo = 1; % 1: constant as default where nexo must be a nonnegative integer + nexo = 1; % 1: constant as default where nexo must be a nonnegative integer elseif (nargin==3) - indxC0Pres = 0; % default is no cross-A0-and-A+ restrictions. + indxC0Pres = 0; % default is no cross-A0-and-A+ restrictions. end k = lags*nvar+nexo; % maximum number of lagged and exogenous variables in each equation Qi = zeros(nvar,nvar,nvar); % for nvar contemporaneous equations Ri = zeros(k,k,nvar); % for nvar lagged and exogenous equations - % Row corresponds to equation. 0 means no restriction. - % 1 means exclusion restriction such that the corresponding parameter is restricted to 0. + % Row corresponds to equation. 0 means no restriction. + % 1 means exclusion restriction such that the corresponding parameter is restricted to 0. %nfvar = 6; % number of foreign (Granger causing) variables %nhvar = nvar-nfvar; % number of home (affected) variables. @@ -72,7 +72,7 @@ Qi(1:5,:,1) = [ 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 - ]; + ]; %======== The second equation =========== Qi(1:4,:,2) = [ @@ -80,27 +80,27 @@ Qi(1:4,:,2) = [ 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 - ]; + ]; %======== The third equation =========== Qi(1:3,:,3) = [ 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 - ]; + ]; %======== The fourth equation =========== Qi(1:2,:,4) = [ 0 0 0 0 1 0 0 0 0 0 0 1 - ]; + ]; %======== The fifth equation =========== Qi(1:1,:,5) = [ 0 0 0 0 0 1 - ]; + ]; %======== The sixth equation =========== @@ -151,10 +151,10 @@ Qi(1:1,:,5) = [ for n=1:nvar % initializing loop for each equation - Ui{n} = null(Qi(:,:,n)); - Vi{n} = null(Ri(:,:,n)); - n0(n) = size(Ui{n},2); - np(n) = size(Vi{n},2); + Ui{n} = null(Qi(:,:,n)); + Vi{n} = null(Ri(:,:,n)); + n0(n) = size(Ui{n},2); + np(n) = size(Vi{n},2); end @@ -165,30 +165,30 @@ end %(2)------------------------------------------------------------- % if indxC0Pres - neq_cres = 3; % the number of equations in which cross-A0-A+ restrictions occur. - ixmC0Pres = cell(neq_cres,1); % in each cell representing equation, we have 4 columns: - % 1st: the jth column (equation) of A+ or A0: f_j or a_j - % 2nd: the ith element f_j(i) -- the ith element in the jth column of A+ - % 3rd: the hth element a_j(h) -- the hth element in the jth column of A0 - % 4th: the number s such that f_j(i) = s * a_j(h) holds. - %** 1st equation - ixmC0Pres{1} = [1 2 2 1 - 1 7 1 1]; - %** 2nd equation - ixmC0Pres{2} = [2 2 2 2]; - %** 3rd equation - ixmC0Pres{3} = [3 7 1 1 - 3 2 2 1]; - - -% % 4 columns. -% ncres = 5; % manually key in the number of cross-A0-A+ restrictions - -% % 1st: the jth column (equation) of A+ or A0: f_j or a_j -% % 2nd: the ith element f_j(i) -- the ith element in the jth column of A+ -% % 3rd: the hth element a_j(h) -- the hth element in the jth column of A0 -% % 4th: the number s such that f_j(i) = s * a_j(h) holds. + neq_cres = 3; % the number of equations in which cross-A0-A+ restrictions occur. + ixmC0Pres = cell(neq_cres,1); % in each cell representing equation, we have 4 columns: + % 1st: the jth column (equation) of A+ or A0: f_j or a_j + % 2nd: the ith element f_j(i) -- the ith element in the jth column of A+ + % 3rd: the hth element a_j(h) -- the hth element in the jth column of A0 + % 4th: the number s such that f_j(i) = s * a_j(h) holds. + %** 1st equation + ixmC0Pres{1} = [1 2 2 1 + 1 7 1 1]; + %** 2nd equation + ixmC0Pres{2} = [2 2 2 2]; + %** 3rd equation + ixmC0Pres{3} = [3 7 1 1 + 3 2 2 1]; + + + % % 4 columns. + % ncres = 5; % manually key in the number of cross-A0-A+ restrictions + + % % 1st: the jth column (equation) of A+ or A0: f_j or a_j + % % 2nd: the ith element f_j(i) -- the ith element in the jth column of A+ + % % 3rd: the hth element a_j(h) -- the hth element in the jth column of A0 + % % 4th: the number s such that f_j(i) = s * a_j(h) holds. else - ixmC0Pres = NaN; + ixmC0Pres = NaN; end diff --git a/tests/ms-sbvar/archive-files/ftd_upperchol7v.m b/tests/ms-sbvar/archive-files/ftd_upperchol7v.m index d0dc7969c4..dc7db34acc 100644 --- a/tests/ms-sbvar/archive-files/ftd_upperchol7v.m +++ b/tests/ms-sbvar/archive-files/ftd_upperchol7v.m @@ -45,17 +45,17 @@ n0 = zeros(nvar,1); % ith element represents the number of free A0 parameters in np = zeros(nvar,1); % ith element represents the number of free A+ parameters in ith equation if (nargin==2) - nexo = 1; % 1: constant as default where nexo must be a nonnegative integer + nexo = 1; % 1: constant as default where nexo must be a nonnegative integer elseif (nargin==3) - indxC0Pres = 0; % default is no cross-A0-and-A+ restrictions. + indxC0Pres = 0; % default is no cross-A0-and-A+ restrictions. end k = lags*nvar+nexo; % maximum number of lagged and exogenous variables in each equation Qi = zeros(nvar,nvar,nvar); % for nvar contemporaneous equations Ri = zeros(k,k,nvar); % for nvar lagged and exogenous equations - % Row corresponds to equation. 0 means no restriction. - % 1 means exclusion restriction such that the corresponding parameter is restricted to 0. + % Row corresponds to equation. 0 means no restriction. + % 1 means exclusion restriction such that the corresponding parameter is restricted to 0. %nfvar = 6; % number of foreign (Granger causing) variables %nhvar = nvar-nfvar; % number of home (affected) variables. @@ -73,7 +73,7 @@ Qi(1:6,:,1) = [ 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 - ]; + ]; %======== The second equation =========== Qi(1:5,:,2) = [ @@ -82,7 +82,7 @@ Qi(1:5,:,2) = [ 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 - ]; + ]; %======== The third equation =========== Qi(1:4,:,3) = [ @@ -90,27 +90,27 @@ Qi(1:4,:,3) = [ 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 - ]; + ]; %======== The fourth equation =========== Qi(1:3,:,4) = [ 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 - ]; + ]; %======== The fifth equation =========== Qi(1:2,:,5) = [ 0 0 0 0 0 1 0 0 0 0 0 0 0 1 - ]; + ]; %======== The sixth equation =========== Qi(1:1,:,6) = [ 0 0 0 0 0 0 1 - ]; + ]; %======== The seventh equation =========== @@ -161,10 +161,10 @@ Qi(1:1,:,6) = [ for n=1:nvar % initializing loop for each equation - Ui{n} = null(Qi(:,:,n)); - Vi{n} = null(Ri(:,:,n)); - n0(n) = size(Ui{n},2); - np(n) = size(Vi{n},2); + Ui{n} = null(Qi(:,:,n)); + Vi{n} = null(Ri(:,:,n)); + n0(n) = size(Ui{n},2); + np(n) = size(Vi{n},2); end @@ -175,30 +175,30 @@ end %(2)------------------------------------------------------------- % if indxC0Pres - neq_cres = 3; % the number of equations in which cross-A0-A+ restrictions occur. - ixmC0Pres = cell(neq_cres,1); % in each cell representing equation, we have 4 columns: - % 1st: the jth column (equation) of A+ or A0: f_j or a_j - % 2nd: the ith element f_j(i) -- the ith element in the jth column of A+ - % 3rd: the hth element a_j(h) -- the hth element in the jth column of A0 - % 4th: the number s such that f_j(i) = s * a_j(h) holds. - %** 1st equation - ixmC0Pres{1} = [1 2 2 1 - 1 7 1 1]; - %** 2nd equation - ixmC0Pres{2} = [2 2 2 2]; - %** 3rd equation - ixmC0Pres{3} = [3 7 1 1 - 3 2 2 1]; - - -% % 4 columns. -% ncres = 5; % manually key in the number of cross-A0-A+ restrictions - -% % 1st: the jth column (equation) of A+ or A0: f_j or a_j -% % 2nd: the ith element f_j(i) -- the ith element in the jth column of A+ -% % 3rd: the hth element a_j(h) -- the hth element in the jth column of A0 -% % 4th: the number s such that f_j(i) = s * a_j(h) holds. + neq_cres = 3; % the number of equations in which cross-A0-A+ restrictions occur. + ixmC0Pres = cell(neq_cres,1); % in each cell representing equation, we have 4 columns: + % 1st: the jth column (equation) of A+ or A0: f_j or a_j + % 2nd: the ith element f_j(i) -- the ith element in the jth column of A+ + % 3rd: the hth element a_j(h) -- the hth element in the jth column of A0 + % 4th: the number s such that f_j(i) = s * a_j(h) holds. + %** 1st equation + ixmC0Pres{1} = [1 2 2 1 + 1 7 1 1]; + %** 2nd equation + ixmC0Pres{2} = [2 2 2 2]; + %** 3rd equation + ixmC0Pres{3} = [3 7 1 1 + 3 2 2 1]; + + + % % 4 columns. + % ncres = 5; % manually key in the number of cross-A0-A+ restrictions + + % % 1st: the jth column (equation) of A+ or A0: f_j or a_j + % % 2nd: the ith element f_j(i) -- the ith element in the jth column of A+ + % % 3rd: the hth element a_j(h) -- the hth element in the jth column of A0 + % % 4th: the number s such that f_j(i) = s * a_j(h) holds. else - ixmC0Pres = NaN; + ixmC0Pres = NaN; end diff --git a/tests/ms-sbvar/data.m b/tests/ms-sbvar/data.m index 6f738015c7..d8a7c94125 100644 --- a/tests/ms-sbvar/data.m +++ b/tests/ms-sbvar/data.m @@ -1,193 +1,193 @@ sbvar_data = [ --9.3174834887745916e-003, 1.7994658843431877e-002, 2.5699999999999997e-002; -7.7668705855149511e-003, 6.0096276044880881e-003, 3.0800000000000001e-002; --1.9541593158383108e-003, 1.1443694953360728e-002, 3.5799999999999998e-002; --7.3230760374594084e-003, 1.6080663886388402e-002, 3.9900000000000005e-002; -5.7366104256297845e-003, 9.6254961625830138e-003, 3.9300000000000002e-002; --8.3093609995312789e-003, 1.7721697565065142e-002, 3.7000000000000005e-002; --1.5818734568909143e-002, 1.8802248364432783e-002, 2.9399999999999999e-002; --3.8114188274117389e-002, 1.7753163941062411e-002, 2.3000000000000000e-002; --4.1399862204639426e-002, 4.5389998028741996e-003, 2.0000000000000000e-002; --3.2217707697825837e-002, 7.3753322217300354e-003, 1.7299999999999999e-002; --2.5646357007195419e-002, 1.0583418386522991e-002, 1.6799999999999999e-002; --1.4897222570872337e-002, 1.0366269881014523e-002, 2.4000000000000000e-002; --6.6220480083236666e-003, 2.3042923285839567e-002, 2.4600000000000000e-002; --5.3027079623060303e-003, 1.0468178907987236e-002, 2.6099999999999998e-002; --5.7275387773225717e-003, 1.0815248301383029e-002, 2.8500000000000001e-002; --1.2909019643277730e-002, 1.3963993831495269e-002, 2.9200000000000000e-002; --9.6082193296807006e-003, 1.1306915202373702e-002, 2.9700000000000001e-002; --6.9847294194245180e-003, 4.0554812275257479e-003, 2.9600000000000001e-002; -1.8176103434601742e-003, 7.3752799189321649e-003, 3.3300000000000003e-002; --4.5038023245602687e-004, 2.3887283546807359e-002, 3.4500000000000003e-002; -1.1624668564948593e-002, 1.4307761419874110e-002, 3.4599999999999999e-002; -1.2948656776092804e-002, 1.3154713006571006e-002, 3.4900000000000000e-002; -1.6160285046599832e-002, 1.9531653948000383e-002, 3.4599999999999999e-002; -8.4081398395898788e-003, 1.8522230201726275e-002, 3.5799999999999998e-002; -2.2153370885423129e-002, 1.7709079726716315e-002, 3.9699999999999999e-002; -2.4844201757035833e-002, 1.7812125625833675e-002, 4.0800000000000003e-002; -3.4050690186470334e-002, 1.7733161216544779e-002, 4.0700000000000000e-002; -4.6893307071320223e-002, 2.4854086852623247e-002, 4.1700000000000001e-002; -5.9972460768834779e-002, 2.4879959563927745e-002, 4.5599999999999995e-002; -5.2289186415585220e-002, 3.7979469553559353e-002, 4.9100000000000005e-002; -4.7741188658148914e-002, 3.9049003040727781e-002, 5.4100000000000002e-002; -4.4667561574096126e-002, 3.5671179948047138e-002, 5.5599999999999997e-002; -4.2427836565945398e-002, 1.9374879269963063e-002, 4.8200000000000000e-002; -3.1462874033119093e-002, 2.5309792721300628e-002, 3.9900000000000005e-002; -2.8437659950142802e-002, 3.7210113920888466e-002, 3.8900000000000004e-002; -2.5156025048538311e-002, 4.4947363315081201e-002, 4.1700000000000001e-002; -3.4855619579102992e-002, 4.3766256282161686e-002, 4.7899999999999998e-002; -4.1146105898716812e-002, 4.5485089147871749e-002, 5.9800000000000006e-002; -3.7608522339491302e-002, 3.9312213398265738e-002, 5.9400000000000001e-002; -3.1755688168807694e-002, 5.7147340097736921e-002, 5.9200000000000003e-002; -3.7547536338742304e-002, 4.0820102882030529e-002, 6.5700000000000008e-002; -3.0780798807969134e-002, 5.4795099957268389e-002, 8.3299999999999999e-002; -2.7622883356809069e-002, 5.9674785474016057e-002, 8.9800000000000005e-002; -1.3687491471252144e-002, 5.1526594947709725e-002, 8.9399999999999993e-002; -3.0365204590552253e-003, 5.7110106004252703e-002, 8.5699999999999998e-002; --3.8946120840908094e-003, 5.8310720503999880e-002, 7.8799999999999995e-002; --3.7031729362304588e-003, 3.2162694194911579e-002, 6.7000000000000004e-002; --2.2953853215847531e-002, 5.2193859691229916e-002, 5.5700000000000000e-002; --3.9774834192911612e-003, 6.1343390594280400e-002, 3.8599999999999995e-002; --6.6430088990969693e-003, 5.4548116487401987e-002, 4.5599999999999995e-002; --6.9966828696923500e-003, 4.0591135320590110e-002, 5.4699999999999999e-002; --1.2347397716578001e-002, 3.2276797966984239e-002, 4.7500000000000001e-002; --2.9473495209533240e-003, 6.7805039825567626e-002, 3.5400000000000001e-002; -1.2120764500071601e-002, 2.3686434724627725e-002, 4.2999999999999997e-002; -1.3231348379735053e-002, 3.7187744116042420e-002, 4.7400000000000005e-002; -2.0987028138604202e-002, 4.7889363970077925e-002, 5.1399999999999994e-002; -3.7485754706574781e-002, 5.3965548807981989e-002, 6.5400000000000000e-002; -4.0318879693293397e-002, 6.8340638829176292e-002, 7.8200000000000006e-002; -2.6218511286559831e-002, 7.8958874043481897e-002, 1.0560000000000000e-001; -2.6929695576288992e-002, 7.0997794665009550e-002, 1.0000000000000001e-001; -9.4554586277908470e-003, 8.4242699131246379e-002, 9.3200000000000005e-002; -3.6174737897027853e-003, 9.1565984601668537e-002, 1.1250000000000000e-001; --1.4685635040370570e-002, 1.2944791465588246e-001, 1.2089999999999999e-001; --2.7095820218557165e-002, 1.2813135610460602e-001, 9.3500000000000000e-002; --4.7490291499844517e-002, 9.5634229266530868e-002, 6.3000000000000000e-002; --4.8493379593802288e-002, 6.0105697293320492e-002, 5.4199999999999998e-002; --3.9943449805699416e-002, 7.6752303729665350e-002, 6.1600000000000002e-002; --3.5077206071779443e-002, 7.2995258807648344e-002, 5.4100000000000002e-002; --2.0906071356066036e-002, 4.5679585226099162e-002, 4.8300000000000003e-002; --2.1531096410072337e-002, 4.3592360792875207e-002, 5.2000000000000005e-002; --2.4735476775209264e-002, 5.5187881222506396e-002, 5.2800000000000000e-002; --2.5561529099840996e-002, 7.0182306554444240e-002, 4.8700000000000000e-002; --2.1575901985043444e-002, 6.8358747781264828e-002, 4.6600000000000003e-002; --1.0282812897440152e-002, 6.5803889922906311e-002, 5.1600000000000000e-002; --9.1324207260257140e-004, 5.6172786341162295e-002, 5.8200000000000002e-002; --9.5486836624303351e-003, 6.9205174325260410e-002, 6.5099999999999991e-002; --1.4957543819619445e-002, 6.8508819756844419e-002, 6.7599999999999993e-002; -1.5069561708809687e-002, 7.9300571687745292e-002, 7.2800000000000004e-002; -1.6283475252537372e-002, 7.0872150059167804e-002, 8.1000000000000003e-002; -2.0908466837013862e-002, 8.4120663761548808e-002, 9.5799999999999996e-002; -1.4559374240283418e-002, 7.4654989747748868e-002, 1.0070000000000000e-001; -7.4026792768986382e-003, 1.0065048845414548e-001, 1.0180000000000000e-001; -6.7867658044900026e-003, 8.4869122045493794e-002, 1.0949999999999999e-001; -2.0964569874966088e-003, 8.1073829867721159e-002, 1.3580000000000000e-001; --2.1618734445638665e-003, 9.0701460926355892e-002, 1.5049999999999999e-001; --2.9866760868227260e-002, 9.1306883112545645e-002, 1.2689999999999999e-001; --3.8807200394211705e-002, 9.3833166941218682e-002, 9.8400000000000001e-002; --2.7491967650325577e-002, 1.1718934484063248e-001, 1.5850000000000000e-001; --1.4366396848604523e-002, 1.0830156525255896e-001, 1.6570000000000001e-001; --2.8990249638850329e-002, 7.2488303659308695e-002, 1.7780000000000001e-001; --2.3603799101664436e-002, 7.5735091281379452e-002, 1.7579999999999998e-001; --4.2733757910307091e-002, 7.1783638615472212e-002, 1.3589999999999999e-001; --6.5834256612443909e-002, 5.7815346934783074e-002, 1.4230000000000001e-001; --6.7076173517195414e-002, 5.0774215309779880e-002, 1.4510000000000001e-001; --7.7493754839396800e-002, 5.6543508350202609e-002, 1.1010000000000000e-001; --8.3437100867300273e-002, 4.3285023548542245e-002, 9.2899999999999996e-002; --7.8140443582185526e-002, 3.4701884333945499e-002, 8.6500000000000007e-002; --6.2904972370690260e-002, 2.9380728193572736e-002, 8.8000000000000009e-002; --5.0575674226140066e-002, 4.1378527908603857e-002, 9.4600000000000004e-002; --3.7530293571547801e-002, 2.9492818368749285e-002, 9.4299999999999995e-002; --2.5480519753907416e-002, 5.0489471212566306e-002, 9.6900000000000000e-002; --1.5811147128429681e-002, 3.6455602629870576e-002, 1.0560000000000000e-001; --1.3623195024511148e-002, 3.3023322354348572e-002, 1.1390000000000000e-001; --1.3078242370475834e-002, 2.3921358528453451e-002, 9.2699999999999991e-002; --1.1665978412656486e-002, 4.6889910860992590e-002, 8.4800000000000000e-002; --1.1057518477750605e-002, 2.1095767295774115e-002, 7.9199999999999993e-002; --3.5500769385130582e-003, 1.9350259876930620e-002, 7.9000000000000001e-002; --4.0091273397440119e-003, 2.4435086241793469e-002, 8.1000000000000003e-002; --2.6706581505724358e-003, 2.0699597271832237e-002, 7.8299999999999995e-002; --6.9080484514429941e-003, 1.9443895441419112e-002, 6.9199999999999998e-002; --5.5474687375021148e-003, 2.5823472588566876e-002, 6.2100000000000002e-002; --8.5975304020564636e-003, 2.8570642360117970e-002, 6.2699999999999992e-002; --1.0035881703480243e-002, 3.1152336660817959e-002, 6.2199999999999998e-002; --7.0303958060371485e-003, 2.1687265092285912e-002, 6.6500000000000004e-002; --5.8350389745083220e-003, 3.0295425205495219e-002, 6.8400000000000002e-002; -3.7000011882959427e-003, 2.7397559342506872e-002, 6.9199999999999998e-002; -8.4384375816348722e-004, 3.3739380042497880e-002, 6.6600000000000006e-002; -5.7875193242438172e-003, 3.9850322530345039e-002, 7.1599999999999997e-002; -3.4826974951247536e-003, 4.7684800945334560e-002, 7.9800000000000010e-002; -9.0205001602736701e-003, 3.2309473053872662e-002, 8.4700000000000011e-002; -1.1602002723241966e-002, 4.2437558261487096e-002, 9.4399999999999998e-002; -1.0727253531554126e-002, 3.9442307350746830e-002, 9.7299999999999998e-002; -1.0478054167251116e-002, 2.9474511048905416e-002, 9.0800000000000006e-002; -5.7769411729271525e-003, 2.6619819505881992e-002, 8.6099999999999996e-002; -1.0146775956780374e-002, 4.9017285623800477e-002, 8.2500000000000004e-002; -5.6961778759188064e-003, 4.7444796184034521e-002, 8.2400000000000001e-002; --1.1072568495222868e-003, 3.6239655982325480e-002, 8.1600000000000006e-002; --1.5465707409310525e-002, 3.1366693341789098e-002, 7.7399999999999997e-002; --2.7250024246535887e-002, 4.7905236749817171e-002, 6.4299999999999996e-002; --2.7337568911169896e-002, 2.5679327033720556e-002, 5.8600000000000006e-002; --2.8996765457870666e-002, 2.7744462882228538e-002, 5.6399999999999999e-002; --3.0694988523064737e-002, 2.0348807487869491e-002, 4.8200000000000000e-002; --2.6687542665930764e-002, 2.6838736648956640e-002, 4.0199999999999993e-002; --2.3361909698373040e-002, 2.0963598977361553e-002, 3.7699999999999997e-002; --1.9843866905633334e-002, 1.7512821090635011e-002, 3.2599999999999997e-002; --1.5118603774070039e-002, 2.1185582236595835e-002, 3.0400000000000000e-002; --2.0197613265910519e-002, 3.1946708550473213e-002, 3.0400000000000000e-002; --2.1520678025641615e-002, 2.1834134877041667e-002, 2.9999999999999999e-002; --2.2826650301176699e-002, 1.8033708065957166e-002, 3.0600000000000002e-002; --1.5976648136103222e-002, 1.9600906791856332e-002, 2.9900000000000003e-002; --1.2481565520511495e-002, 2.5764744780397253e-002, 3.2099999999999997e-002; --6.2498609089072232e-003, 1.7163326403677015e-002, 3.9399999999999998e-002; --7.5419440421207184e-003, 2.4448612633015232e-002, 4.4900000000000002e-002; --2.9008641302628035e-003, 1.9270549031769058e-002, 5.1699999999999996e-002; --7.2102329848391378e-003, 2.6468635791329520e-002, 5.8099999999999999e-002; --1.2589423111688092e-002, 1.4805044409490042e-002, 6.0199999999999997e-002; --1.1715387895728568e-002, 1.7085018789666284e-002, 5.7999999999999996e-002; --1.1777024741238762e-002, 1.9780736678506994e-002, 5.7200000000000001e-002; --1.2215155411272605e-002, 2.4726200999461767e-002, 5.3600000000000002e-002; --3.5465932809213285e-003, 1.3486465713533846e-002, 5.2400000000000002e-002; --2.9219038194341351e-003, 1.9323425037825803e-002, 5.3099999999999994e-002; -8.2672938771111149e-004, 1.6730936106534644e-002, 5.2800000000000000e-002; -5.2731183513543556e-004, 2.1687064498104203e-002, 5.2800000000000000e-002; -7.4708897268216390e-003, 1.3887651948481405e-002, 5.5199999999999999e-002; -1.1578449231922860e-002, 1.0535540622131023e-002, 5.5300000000000002e-002; -1.0543713785281739e-002, 1.3591721544186308e-002, 5.5099999999999996e-002; -1.3043222430857426e-002, 9.7155784328055717e-003, 5.5199999999999999e-002; -1.1021797245557963e-002, 7.8485022563632434e-003, 5.5000000000000000e-002; -1.3766304579396760e-002, 1.4031942678612408e-002, 5.5300000000000002e-002; -2.0010289782806723e-002, 1.1684049976040223e-002, 4.8600000000000004e-002; -1.9500810360241871e-002, 1.5486288460806463e-002, 4.7300000000000002e-002; -1.8677267947765586e-002, 1.7674602281525287e-002, 4.7500000000000001e-002; -2.1068187519647452e-002, 1.3207048148448308e-002, 5.0900000000000001e-002; -2.9432867931319606e-002, 1.8614186008366396e-002, 5.3099999999999994e-002; -2.2709401609937174e-002, 3.3601370511199269e-002, 5.6799999999999996e-002; -2.9063996825298588e-002, 1.9804593863093523e-002, 6.2699999999999992e-002; -1.8810297095397388e-002, 1.8609127901011213e-002, 6.5199999999999994e-002; -1.4978576794066001e-002, 1.7916238079900726e-002, 6.4699999999999994e-002; -4.8316137761403866e-003, 3.2976319868455617e-002, 5.5899999999999998e-002; --9.1822274865016595e-004, 3.1213866380320532e-002, 4.3299999999999998e-002; --1.3163778876048582e-002, 1.5733791887268644e-002, 3.5000000000000003e-002; --1.7841900605217731e-002, 1.6933827369602694e-002, 2.1299999999999999e-002; --1.9532762689722816e-002, 1.6823164543461777e-002, 1.7299999999999999e-002; --2.2376267503108949e-002, 1.5189134545742444e-002, 1.7500000000000002e-002; --2.4570058045892296e-002, 1.5598774847326746e-002, 1.7399999999999999e-002; --3.1885812767447064e-002, 2.2380594713903079e-002, 1.4400000000000000e-002; --3.5301487936340692e-002, 3.0770251840726015e-002, 1.2500000000000001e-002; --3.3809664438850362e-002, 1.1207937615285157e-002, 1.2500000000000001e-002; --2.3738888747095288e-002, 1.8271566479553414e-002, 1.0200000000000001e-002; --2.2389486776477341e-002, 1.8759653895370487e-002, 1.0000000000000000e-002; --1.9372963882339889e-002, 3.6183114349394030e-002, 1.0000000000000000e-002; --1.8172640165300180e-002, 3.8524562683139418e-002, 1.0100000000000000e-002; --1.5851276113677315e-002, 1.4577624436418635e-002, 1.4300000000000000e-002; --1.5145664166732686e-002, 2.7339757365790307e-002, 1.9500000000000000e-002; --1.3284941407389894e-002, 3.0828456732055809e-002, 2.4700000000000003e-002; --1.2679438144379773e-002, 2.5660138484441486e-002, 2.9399999999999999e-002; --1.0133886633141742e-002, 3.3074553498490200e-002, 3.4599999999999999e-002; --1.5055016783550812e-002, 3.0184663811322121e-002, 3.9800000000000002e-002; -]; + -9.3174834887745916e-003, 1.7994658843431877e-002, 2.5699999999999997e-002; + 7.7668705855149511e-003, 6.0096276044880881e-003, 3.0800000000000001e-002; + -1.9541593158383108e-003, 1.1443694953360728e-002, 3.5799999999999998e-002; + -7.3230760374594084e-003, 1.6080663886388402e-002, 3.9900000000000005e-002; + 5.7366104256297845e-003, 9.6254961625830138e-003, 3.9300000000000002e-002; + -8.3093609995312789e-003, 1.7721697565065142e-002, 3.7000000000000005e-002; + -1.5818734568909143e-002, 1.8802248364432783e-002, 2.9399999999999999e-002; + -3.8114188274117389e-002, 1.7753163941062411e-002, 2.3000000000000000e-002; + -4.1399862204639426e-002, 4.5389998028741996e-003, 2.0000000000000000e-002; + -3.2217707697825837e-002, 7.3753322217300354e-003, 1.7299999999999999e-002; + -2.5646357007195419e-002, 1.0583418386522991e-002, 1.6799999999999999e-002; + -1.4897222570872337e-002, 1.0366269881014523e-002, 2.4000000000000000e-002; + -6.6220480083236666e-003, 2.3042923285839567e-002, 2.4600000000000000e-002; + -5.3027079623060303e-003, 1.0468178907987236e-002, 2.6099999999999998e-002; + -5.7275387773225717e-003, 1.0815248301383029e-002, 2.8500000000000001e-002; + -1.2909019643277730e-002, 1.3963993831495269e-002, 2.9200000000000000e-002; + -9.6082193296807006e-003, 1.1306915202373702e-002, 2.9700000000000001e-002; + -6.9847294194245180e-003, 4.0554812275257479e-003, 2.9600000000000001e-002; + 1.8176103434601742e-003, 7.3752799189321649e-003, 3.3300000000000003e-002; + -4.5038023245602687e-004, 2.3887283546807359e-002, 3.4500000000000003e-002; + 1.1624668564948593e-002, 1.4307761419874110e-002, 3.4599999999999999e-002; + 1.2948656776092804e-002, 1.3154713006571006e-002, 3.4900000000000000e-002; + 1.6160285046599832e-002, 1.9531653948000383e-002, 3.4599999999999999e-002; + 8.4081398395898788e-003, 1.8522230201726275e-002, 3.5799999999999998e-002; + 2.2153370885423129e-002, 1.7709079726716315e-002, 3.9699999999999999e-002; + 2.4844201757035833e-002, 1.7812125625833675e-002, 4.0800000000000003e-002; + 3.4050690186470334e-002, 1.7733161216544779e-002, 4.0700000000000000e-002; + 4.6893307071320223e-002, 2.4854086852623247e-002, 4.1700000000000001e-002; + 5.9972460768834779e-002, 2.4879959563927745e-002, 4.5599999999999995e-002; + 5.2289186415585220e-002, 3.7979469553559353e-002, 4.9100000000000005e-002; + 4.7741188658148914e-002, 3.9049003040727781e-002, 5.4100000000000002e-002; + 4.4667561574096126e-002, 3.5671179948047138e-002, 5.5599999999999997e-002; + 4.2427836565945398e-002, 1.9374879269963063e-002, 4.8200000000000000e-002; + 3.1462874033119093e-002, 2.5309792721300628e-002, 3.9900000000000005e-002; + 2.8437659950142802e-002, 3.7210113920888466e-002, 3.8900000000000004e-002; + 2.5156025048538311e-002, 4.4947363315081201e-002, 4.1700000000000001e-002; + 3.4855619579102992e-002, 4.3766256282161686e-002, 4.7899999999999998e-002; + 4.1146105898716812e-002, 4.5485089147871749e-002, 5.9800000000000006e-002; + 3.7608522339491302e-002, 3.9312213398265738e-002, 5.9400000000000001e-002; + 3.1755688168807694e-002, 5.7147340097736921e-002, 5.9200000000000003e-002; + 3.7547536338742304e-002, 4.0820102882030529e-002, 6.5700000000000008e-002; + 3.0780798807969134e-002, 5.4795099957268389e-002, 8.3299999999999999e-002; + 2.7622883356809069e-002, 5.9674785474016057e-002, 8.9800000000000005e-002; + 1.3687491471252144e-002, 5.1526594947709725e-002, 8.9399999999999993e-002; + 3.0365204590552253e-003, 5.7110106004252703e-002, 8.5699999999999998e-002; + -3.8946120840908094e-003, 5.8310720503999880e-002, 7.8799999999999995e-002; + -3.7031729362304588e-003, 3.2162694194911579e-002, 6.7000000000000004e-002; + -2.2953853215847531e-002, 5.2193859691229916e-002, 5.5700000000000000e-002; + -3.9774834192911612e-003, 6.1343390594280400e-002, 3.8599999999999995e-002; + -6.6430088990969693e-003, 5.4548116487401987e-002, 4.5599999999999995e-002; + -6.9966828696923500e-003, 4.0591135320590110e-002, 5.4699999999999999e-002; + -1.2347397716578001e-002, 3.2276797966984239e-002, 4.7500000000000001e-002; + -2.9473495209533240e-003, 6.7805039825567626e-002, 3.5400000000000001e-002; + 1.2120764500071601e-002, 2.3686434724627725e-002, 4.2999999999999997e-002; + 1.3231348379735053e-002, 3.7187744116042420e-002, 4.7400000000000005e-002; + 2.0987028138604202e-002, 4.7889363970077925e-002, 5.1399999999999994e-002; + 3.7485754706574781e-002, 5.3965548807981989e-002, 6.5400000000000000e-002; + 4.0318879693293397e-002, 6.8340638829176292e-002, 7.8200000000000006e-002; + 2.6218511286559831e-002, 7.8958874043481897e-002, 1.0560000000000000e-001; + 2.6929695576288992e-002, 7.0997794665009550e-002, 1.0000000000000001e-001; + 9.4554586277908470e-003, 8.4242699131246379e-002, 9.3200000000000005e-002; + 3.6174737897027853e-003, 9.1565984601668537e-002, 1.1250000000000000e-001; + -1.4685635040370570e-002, 1.2944791465588246e-001, 1.2089999999999999e-001; + -2.7095820218557165e-002, 1.2813135610460602e-001, 9.3500000000000000e-002; + -4.7490291499844517e-002, 9.5634229266530868e-002, 6.3000000000000000e-002; + -4.8493379593802288e-002, 6.0105697293320492e-002, 5.4199999999999998e-002; + -3.9943449805699416e-002, 7.6752303729665350e-002, 6.1600000000000002e-002; + -3.5077206071779443e-002, 7.2995258807648344e-002, 5.4100000000000002e-002; + -2.0906071356066036e-002, 4.5679585226099162e-002, 4.8300000000000003e-002; + -2.1531096410072337e-002, 4.3592360792875207e-002, 5.2000000000000005e-002; + -2.4735476775209264e-002, 5.5187881222506396e-002, 5.2800000000000000e-002; + -2.5561529099840996e-002, 7.0182306554444240e-002, 4.8700000000000000e-002; + -2.1575901985043444e-002, 6.8358747781264828e-002, 4.6600000000000003e-002; + -1.0282812897440152e-002, 6.5803889922906311e-002, 5.1600000000000000e-002; + -9.1324207260257140e-004, 5.6172786341162295e-002, 5.8200000000000002e-002; + -9.5486836624303351e-003, 6.9205174325260410e-002, 6.5099999999999991e-002; + -1.4957543819619445e-002, 6.8508819756844419e-002, 6.7599999999999993e-002; + 1.5069561708809687e-002, 7.9300571687745292e-002, 7.2800000000000004e-002; + 1.6283475252537372e-002, 7.0872150059167804e-002, 8.1000000000000003e-002; + 2.0908466837013862e-002, 8.4120663761548808e-002, 9.5799999999999996e-002; + 1.4559374240283418e-002, 7.4654989747748868e-002, 1.0070000000000000e-001; + 7.4026792768986382e-003, 1.0065048845414548e-001, 1.0180000000000000e-001; + 6.7867658044900026e-003, 8.4869122045493794e-002, 1.0949999999999999e-001; + 2.0964569874966088e-003, 8.1073829867721159e-002, 1.3580000000000000e-001; + -2.1618734445638665e-003, 9.0701460926355892e-002, 1.5049999999999999e-001; + -2.9866760868227260e-002, 9.1306883112545645e-002, 1.2689999999999999e-001; + -3.8807200394211705e-002, 9.3833166941218682e-002, 9.8400000000000001e-002; + -2.7491967650325577e-002, 1.1718934484063248e-001, 1.5850000000000000e-001; + -1.4366396848604523e-002, 1.0830156525255896e-001, 1.6570000000000001e-001; + -2.8990249638850329e-002, 7.2488303659308695e-002, 1.7780000000000001e-001; + -2.3603799101664436e-002, 7.5735091281379452e-002, 1.7579999999999998e-001; + -4.2733757910307091e-002, 7.1783638615472212e-002, 1.3589999999999999e-001; + -6.5834256612443909e-002, 5.7815346934783074e-002, 1.4230000000000001e-001; + -6.7076173517195414e-002, 5.0774215309779880e-002, 1.4510000000000001e-001; + -7.7493754839396800e-002, 5.6543508350202609e-002, 1.1010000000000000e-001; + -8.3437100867300273e-002, 4.3285023548542245e-002, 9.2899999999999996e-002; + -7.8140443582185526e-002, 3.4701884333945499e-002, 8.6500000000000007e-002; + -6.2904972370690260e-002, 2.9380728193572736e-002, 8.8000000000000009e-002; + -5.0575674226140066e-002, 4.1378527908603857e-002, 9.4600000000000004e-002; + -3.7530293571547801e-002, 2.9492818368749285e-002, 9.4299999999999995e-002; + -2.5480519753907416e-002, 5.0489471212566306e-002, 9.6900000000000000e-002; + -1.5811147128429681e-002, 3.6455602629870576e-002, 1.0560000000000000e-001; + -1.3623195024511148e-002, 3.3023322354348572e-002, 1.1390000000000000e-001; + -1.3078242370475834e-002, 2.3921358528453451e-002, 9.2699999999999991e-002; + -1.1665978412656486e-002, 4.6889910860992590e-002, 8.4800000000000000e-002; + -1.1057518477750605e-002, 2.1095767295774115e-002, 7.9199999999999993e-002; + -3.5500769385130582e-003, 1.9350259876930620e-002, 7.9000000000000001e-002; + -4.0091273397440119e-003, 2.4435086241793469e-002, 8.1000000000000003e-002; + -2.6706581505724358e-003, 2.0699597271832237e-002, 7.8299999999999995e-002; + -6.9080484514429941e-003, 1.9443895441419112e-002, 6.9199999999999998e-002; + -5.5474687375021148e-003, 2.5823472588566876e-002, 6.2100000000000002e-002; + -8.5975304020564636e-003, 2.8570642360117970e-002, 6.2699999999999992e-002; + -1.0035881703480243e-002, 3.1152336660817959e-002, 6.2199999999999998e-002; + -7.0303958060371485e-003, 2.1687265092285912e-002, 6.6500000000000004e-002; + -5.8350389745083220e-003, 3.0295425205495219e-002, 6.8400000000000002e-002; + 3.7000011882959427e-003, 2.7397559342506872e-002, 6.9199999999999998e-002; + 8.4384375816348722e-004, 3.3739380042497880e-002, 6.6600000000000006e-002; + 5.7875193242438172e-003, 3.9850322530345039e-002, 7.1599999999999997e-002; + 3.4826974951247536e-003, 4.7684800945334560e-002, 7.9800000000000010e-002; + 9.0205001602736701e-003, 3.2309473053872662e-002, 8.4700000000000011e-002; + 1.1602002723241966e-002, 4.2437558261487096e-002, 9.4399999999999998e-002; + 1.0727253531554126e-002, 3.9442307350746830e-002, 9.7299999999999998e-002; + 1.0478054167251116e-002, 2.9474511048905416e-002, 9.0800000000000006e-002; + 5.7769411729271525e-003, 2.6619819505881992e-002, 8.6099999999999996e-002; + 1.0146775956780374e-002, 4.9017285623800477e-002, 8.2500000000000004e-002; + 5.6961778759188064e-003, 4.7444796184034521e-002, 8.2400000000000001e-002; + -1.1072568495222868e-003, 3.6239655982325480e-002, 8.1600000000000006e-002; + -1.5465707409310525e-002, 3.1366693341789098e-002, 7.7399999999999997e-002; + -2.7250024246535887e-002, 4.7905236749817171e-002, 6.4299999999999996e-002; + -2.7337568911169896e-002, 2.5679327033720556e-002, 5.8600000000000006e-002; + -2.8996765457870666e-002, 2.7744462882228538e-002, 5.6399999999999999e-002; + -3.0694988523064737e-002, 2.0348807487869491e-002, 4.8200000000000000e-002; + -2.6687542665930764e-002, 2.6838736648956640e-002, 4.0199999999999993e-002; + -2.3361909698373040e-002, 2.0963598977361553e-002, 3.7699999999999997e-002; + -1.9843866905633334e-002, 1.7512821090635011e-002, 3.2599999999999997e-002; + -1.5118603774070039e-002, 2.1185582236595835e-002, 3.0400000000000000e-002; + -2.0197613265910519e-002, 3.1946708550473213e-002, 3.0400000000000000e-002; + -2.1520678025641615e-002, 2.1834134877041667e-002, 2.9999999999999999e-002; + -2.2826650301176699e-002, 1.8033708065957166e-002, 3.0600000000000002e-002; + -1.5976648136103222e-002, 1.9600906791856332e-002, 2.9900000000000003e-002; + -1.2481565520511495e-002, 2.5764744780397253e-002, 3.2099999999999997e-002; + -6.2498609089072232e-003, 1.7163326403677015e-002, 3.9399999999999998e-002; + -7.5419440421207184e-003, 2.4448612633015232e-002, 4.4900000000000002e-002; + -2.9008641302628035e-003, 1.9270549031769058e-002, 5.1699999999999996e-002; + -7.2102329848391378e-003, 2.6468635791329520e-002, 5.8099999999999999e-002; + -1.2589423111688092e-002, 1.4805044409490042e-002, 6.0199999999999997e-002; + -1.1715387895728568e-002, 1.7085018789666284e-002, 5.7999999999999996e-002; + -1.1777024741238762e-002, 1.9780736678506994e-002, 5.7200000000000001e-002; + -1.2215155411272605e-002, 2.4726200999461767e-002, 5.3600000000000002e-002; + -3.5465932809213285e-003, 1.3486465713533846e-002, 5.2400000000000002e-002; + -2.9219038194341351e-003, 1.9323425037825803e-002, 5.3099999999999994e-002; + 8.2672938771111149e-004, 1.6730936106534644e-002, 5.2800000000000000e-002; + 5.2731183513543556e-004, 2.1687064498104203e-002, 5.2800000000000000e-002; + 7.4708897268216390e-003, 1.3887651948481405e-002, 5.5199999999999999e-002; + 1.1578449231922860e-002, 1.0535540622131023e-002, 5.5300000000000002e-002; + 1.0543713785281739e-002, 1.3591721544186308e-002, 5.5099999999999996e-002; + 1.3043222430857426e-002, 9.7155784328055717e-003, 5.5199999999999999e-002; + 1.1021797245557963e-002, 7.8485022563632434e-003, 5.5000000000000000e-002; + 1.3766304579396760e-002, 1.4031942678612408e-002, 5.5300000000000002e-002; + 2.0010289782806723e-002, 1.1684049976040223e-002, 4.8600000000000004e-002; + 1.9500810360241871e-002, 1.5486288460806463e-002, 4.7300000000000002e-002; + 1.8677267947765586e-002, 1.7674602281525287e-002, 4.7500000000000001e-002; + 2.1068187519647452e-002, 1.3207048148448308e-002, 5.0900000000000001e-002; + 2.9432867931319606e-002, 1.8614186008366396e-002, 5.3099999999999994e-002; + 2.2709401609937174e-002, 3.3601370511199269e-002, 5.6799999999999996e-002; + 2.9063996825298588e-002, 1.9804593863093523e-002, 6.2699999999999992e-002; + 1.8810297095397388e-002, 1.8609127901011213e-002, 6.5199999999999994e-002; + 1.4978576794066001e-002, 1.7916238079900726e-002, 6.4699999999999994e-002; + 4.8316137761403866e-003, 3.2976319868455617e-002, 5.5899999999999998e-002; + -9.1822274865016595e-004, 3.1213866380320532e-002, 4.3299999999999998e-002; + -1.3163778876048582e-002, 1.5733791887268644e-002, 3.5000000000000003e-002; + -1.7841900605217731e-002, 1.6933827369602694e-002, 2.1299999999999999e-002; + -1.9532762689722816e-002, 1.6823164543461777e-002, 1.7299999999999999e-002; + -2.2376267503108949e-002, 1.5189134545742444e-002, 1.7500000000000002e-002; + -2.4570058045892296e-002, 1.5598774847326746e-002, 1.7399999999999999e-002; + -3.1885812767447064e-002, 2.2380594713903079e-002, 1.4400000000000000e-002; + -3.5301487936340692e-002, 3.0770251840726015e-002, 1.2500000000000001e-002; + -3.3809664438850362e-002, 1.1207937615285157e-002, 1.2500000000000001e-002; + -2.3738888747095288e-002, 1.8271566479553414e-002, 1.0200000000000001e-002; + -2.2389486776477341e-002, 1.8759653895370487e-002, 1.0000000000000000e-002; + -1.9372963882339889e-002, 3.6183114349394030e-002, 1.0000000000000000e-002; + -1.8172640165300180e-002, 3.8524562683139418e-002, 1.0100000000000000e-002; + -1.5851276113677315e-002, 1.4577624436418635e-002, 1.4300000000000000e-002; + -1.5145664166732686e-002, 2.7339757365790307e-002, 1.9500000000000000e-002; + -1.3284941407389894e-002, 3.0828456732055809e-002, 2.4700000000000003e-002; + -1.2679438144379773e-002, 2.5660138484441486e-002, 2.9399999999999999e-002; + -1.0133886633141742e-002, 3.3074553498490200e-002, 3.4599999999999999e-002; + -1.5055016783550812e-002, 3.0184663811322121e-002, 3.9800000000000002e-002; + ]; Y = sbvar_data(:, 1); Pie = sbvar_data(:, 2); diff --git a/tests/parallel/data_ca1.m b/tests/parallel/data_ca1.m index c28fae1a28..ca003056bd 100644 --- a/tests/parallel/data_ca1.m +++ b/tests/parallel/data_ca1.m @@ -1,98 +1,98 @@ data = [0.928467646476 11.8716889412 20 0.418037507392 0.227382377518 ... --0.705994063083 11.7522582094 21.25 1.09254424511 -1.29488274994 ... --0.511895351926 9.68144025625 17.25 -1.66150408407 0.331508393098 ... --0.990955971267 10.0890781236 17 1.43016275252 -2.43589670141 ... --0.981233061806 12.1094840679 18.25 2.91293288733 -0.790246576864 ... --0.882182844512 8.54559460406 15 0.419579139481 0.358729719566 ... --0.930893002836 6.19238374422 12.5 -1.48847457959 0.739779938797 ... -1.53158206947 2.76544271886 11.5 -0.336216769682 0.455559918769 ... -2.2659052834 5.47418162513 11 0.306436789767 -0.0707985731221 ... -1.05419803797 6.35698426189 11 0.140700250477 0.620401487202 ... -1.20161076793 3.4253301593 11 0.461296492351 0.14354323987 ... -1.73934077971 4.70926070322 11.5 1.35798282982 0.38564694435 ... -1.71735262584 3.54232079749 12.5 2.9097529155 -0.804308583301 ... -0.426343657844 3.32719108897 13 1.64214862652 -1.18214664701 ... -1.67751812324 2.93444727338 11.25 0.344434910651 -1.6529373719 ... -1.37013301099 4.72303361923 11.75 2.61511526582 0.327684243041 ... -0.281231073781 4.4893853071 10.5 1.17043449257 1.12855106649 ... -1.53638992834 3.7325309699 10.25 -0.683947046728 0.11943538737 ... -1.68081431462 3.34729969129 10 1.41159342106 -1.59065680853 ... --0.343321601133 5.05563513564 12 1.75117366498 -2.40127764642 ... -0.873415608666 3.2779996255 10.25 -1.39895866711 0.0971444398216 ... -0.26399696544 4.78229419828 9.75 0.0914692438124 0.299310457612 ... --0.562233624818 3.88598638237 9.75 -0.0505384765105 0.332826708151 ... -2.15161914936 3.84859710132 8.75 -3.44811080489 0.789138678784 ... -1.2345093726 5.62225030942 9.5 -0.366945407434 2.32974981198 ... -1.62554967459 4.24667132831 10 -0.800958371402 0.0293183770935 ... -1.33035402527 2.75248979249 9.75 -0.855723113225 0.852493939813 ... -1.52078814077 3.53415985826 9.75 -3.37963469203 -1.05133958119 ... -1.16704983697 4.92754079464 10.75 -3.0142303324 0.459907431978 ... -0.277213572101 4.55532133037 11.75 -0.851995599415 2.03242034852 ... -0.842215068977 3.11164509647 12.25 -1.08290421696 0.014323281961 ... -1.05325028606 4.92882647578 13.5 -1.1953883867 0.706764750654 ... -0.453051253568 6.82998950103 13.5 0.111803656462 0.088462593153 ... -0.199885995525 5.82643354662 13.5 -0.920501518421 -0.26504958666 ... -0.137907999624 2.66076369132 13.5 -1.17122929812 -0.995642430514 ... -0.721949686709 5.70497876823 14.25 1.19378169018 -1.10644839651 ... --0.418465249225 3.75861110232 14.75 -1.03131674824 0.188507675831 ... --0.644028342116 4.15104788154 13.75 -1.48911756546 0.204560913792 ... --0.848213852668 5.65580324027 12.75 0.677011703877 -0.849628054542 ... --1.51954076928 11.4866911266 11.25 -0.446024680774 -0.456342350765 ... -0.265275055215 2.85472749592 9.75 -0.598778202436 -0.907311640831 ... -0.356162529063 2.29614015658 9.5 -0.46820788432 -1.22130883441 ... -0.368308864363 -0.539083504685 8 -0.781333991956 0.374007246518 ... --0.145751412732 1.61507621789 8.25 3.68291932628 1.32438399845 ... -0.285457283664 2.14334055993 7 1.42819405379 -0.00818660844123 ... -0.372390129412 1.60000213334 6.25 0.626106424052 -0.10136772765 ... -0.382720203063 1.72614243263 7.25 4.89631941021 -1.10060711916 ... -0.737957515573 2.90430582851 6 -0.0422721010314 0.4178952497 ... -0.649532581668 0.657135682543 6 0.692066153971 0.422299120276 ... -0.627159201987 1.70352689913 5.75 2.62066711305 -1.29237304034 ... -0.905441299817 1.95663197267 5.5 1.5949697565 -0.27115830703 ... -1.49322577898 -2.08741765309 6.25 1.23027694802 0.418336889527 ... -1.48750731567 -1.57274121871 8 3.01660550994 -0.893958254365 ... -1.39783858087 2.22623066426 7 -0.80842319214 1.47625453886 ... -0.89274836317 1.30378081742 8 -0.249485058661 0.159871204185 ... -0.920652246088 4.1437741965 9.75 2.8204453623 0.178149239655 ... --0.00264276644799 3.07989972052 8.75 -2.56342461535 2.105998353 ... -0.0198190461681 0.766283759256 8 -1.15838865989 1.56888883418 ... -0.440050515311 0.127570085801 7.5 0.0400753569995 0.028914333532 ... -0.129536637901 1.78174141526 6.75 0.959943962785 0.307781224401 ... -0.398549827172 3.03606770667 6.5 -0.340209794742 0.100979469478 ... -1.17174775425 0.629625188037 5.75 0.403003686814 0.902394579377 ... -0.991163981251 2.50862910684 4.75 -1.44963996982 1.16150986945 ... -0.967603566096 2.12003739013 4.75 0.610846030775 -0.889994896068 ... -1.14689383604 1.24185011459 4.75 2.01098091308 -1.73846431001 ... -1.32593824054 0.990713820685 4.75 -0.0955142989332 -0.0369257308362 ... -0.861135002644 -0.24744943605 6 1.72793107135 -0.691506789639 ... -1.26870850151 2.09844764887 6.5 1.50720217572 -1.31399187077 ... -0.260364987715 1.10650139716 6.5 1.13659047496 0.0720441664643 ... -1.09731242214 0.490796381346 7.25 4.59123894147 -2.14073070763 ... -1.63792841781 0.612652594286 6.75 1.79604605035 -0.644363995357 ... -1.48465576034 0.978295808687 6.75 -2.00753620902 1.39437534964 ... -1.0987608663 4.25212569087 6.25 -2.58901196498 2.56054320803 ... -1.42592178132 2.76984518311 6.25 0.888195752358 1.03114549274 ... -1.52958239462 1.31795955491 6.5 -0.902907564082 -0.0952198893776 ... -1.0170168994 2.14733589918 7 -1.3054866978 2.68803738466 ... -0.723253652257 3.43552889347 7.5 1.8213700853 0.592593586195 ... -1.24720806008 3.87383806577 7.5 0.0522300654168 0.988871238698 ... -0.482531471239 2.67793287032 7.5 2.9693944293 -0.108591166081 ... -0.154056100439 0.927269031704 6.75 0.119222057561 3.30489209451 ... -0.0694865769274 6.65916526788 6.25 0.889014476084 -2.83976849035 ... --0.121267434867 0.341442615696 5.25 0.323053239216 -3.49289229012 ... -0.726473690375 -3.5423730964 4 2.19149290449 -3.20855054004 ... -1.39271709108 2.63121085718 3.75 0.88406577736 0.75622580197 ... -1.07502077727 5.88578836799 4.25 -2.55088273352 2.89018116374 ... -0.759049251607 4.24703604223 4.5 0.575687665685 -0.388292506167 ... -]; - + -0.705994063083 11.7522582094 21.25 1.09254424511 -1.29488274994 ... + -0.511895351926 9.68144025625 17.25 -1.66150408407 0.331508393098 ... + -0.990955971267 10.0890781236 17 1.43016275252 -2.43589670141 ... + -0.981233061806 12.1094840679 18.25 2.91293288733 -0.790246576864 ... + -0.882182844512 8.54559460406 15 0.419579139481 0.358729719566 ... + -0.930893002836 6.19238374422 12.5 -1.48847457959 0.739779938797 ... + 1.53158206947 2.76544271886 11.5 -0.336216769682 0.455559918769 ... + 2.2659052834 5.47418162513 11 0.306436789767 -0.0707985731221 ... + 1.05419803797 6.35698426189 11 0.140700250477 0.620401487202 ... + 1.20161076793 3.4253301593 11 0.461296492351 0.14354323987 ... + 1.73934077971 4.70926070322 11.5 1.35798282982 0.38564694435 ... + 1.71735262584 3.54232079749 12.5 2.9097529155 -0.804308583301 ... + 0.426343657844 3.32719108897 13 1.64214862652 -1.18214664701 ... + 1.67751812324 2.93444727338 11.25 0.344434910651 -1.6529373719 ... + 1.37013301099 4.72303361923 11.75 2.61511526582 0.327684243041 ... + 0.281231073781 4.4893853071 10.5 1.17043449257 1.12855106649 ... + 1.53638992834 3.7325309699 10.25 -0.683947046728 0.11943538737 ... + 1.68081431462 3.34729969129 10 1.41159342106 -1.59065680853 ... + -0.343321601133 5.05563513564 12 1.75117366498 -2.40127764642 ... + 0.873415608666 3.2779996255 10.25 -1.39895866711 0.0971444398216 ... + 0.26399696544 4.78229419828 9.75 0.0914692438124 0.299310457612 ... + -0.562233624818 3.88598638237 9.75 -0.0505384765105 0.332826708151 ... + 2.15161914936 3.84859710132 8.75 -3.44811080489 0.789138678784 ... + 1.2345093726 5.62225030942 9.5 -0.366945407434 2.32974981198 ... + 1.62554967459 4.24667132831 10 -0.800958371402 0.0293183770935 ... + 1.33035402527 2.75248979249 9.75 -0.855723113225 0.852493939813 ... + 1.52078814077 3.53415985826 9.75 -3.37963469203 -1.05133958119 ... + 1.16704983697 4.92754079464 10.75 -3.0142303324 0.459907431978 ... + 0.277213572101 4.55532133037 11.75 -0.851995599415 2.03242034852 ... + 0.842215068977 3.11164509647 12.25 -1.08290421696 0.014323281961 ... + 1.05325028606 4.92882647578 13.5 -1.1953883867 0.706764750654 ... + 0.453051253568 6.82998950103 13.5 0.111803656462 0.088462593153 ... + 0.199885995525 5.82643354662 13.5 -0.920501518421 -0.26504958666 ... + 0.137907999624 2.66076369132 13.5 -1.17122929812 -0.995642430514 ... + 0.721949686709 5.70497876823 14.25 1.19378169018 -1.10644839651 ... + -0.418465249225 3.75861110232 14.75 -1.03131674824 0.188507675831 ... + -0.644028342116 4.15104788154 13.75 -1.48911756546 0.204560913792 ... + -0.848213852668 5.65580324027 12.75 0.677011703877 -0.849628054542 ... + -1.51954076928 11.4866911266 11.25 -0.446024680774 -0.456342350765 ... + 0.265275055215 2.85472749592 9.75 -0.598778202436 -0.907311640831 ... + 0.356162529063 2.29614015658 9.5 -0.46820788432 -1.22130883441 ... + 0.368308864363 -0.539083504685 8 -0.781333991956 0.374007246518 ... + -0.145751412732 1.61507621789 8.25 3.68291932628 1.32438399845 ... + 0.285457283664 2.14334055993 7 1.42819405379 -0.00818660844123 ... + 0.372390129412 1.60000213334 6.25 0.626106424052 -0.10136772765 ... + 0.382720203063 1.72614243263 7.25 4.89631941021 -1.10060711916 ... + 0.737957515573 2.90430582851 6 -0.0422721010314 0.4178952497 ... + 0.649532581668 0.657135682543 6 0.692066153971 0.422299120276 ... + 0.627159201987 1.70352689913 5.75 2.62066711305 -1.29237304034 ... + 0.905441299817 1.95663197267 5.5 1.5949697565 -0.27115830703 ... + 1.49322577898 -2.08741765309 6.25 1.23027694802 0.418336889527 ... + 1.48750731567 -1.57274121871 8 3.01660550994 -0.893958254365 ... + 1.39783858087 2.22623066426 7 -0.80842319214 1.47625453886 ... + 0.89274836317 1.30378081742 8 -0.249485058661 0.159871204185 ... + 0.920652246088 4.1437741965 9.75 2.8204453623 0.178149239655 ... + -0.00264276644799 3.07989972052 8.75 -2.56342461535 2.105998353 ... + 0.0198190461681 0.766283759256 8 -1.15838865989 1.56888883418 ... + 0.440050515311 0.127570085801 7.5 0.0400753569995 0.028914333532 ... + 0.129536637901 1.78174141526 6.75 0.959943962785 0.307781224401 ... + 0.398549827172 3.03606770667 6.5 -0.340209794742 0.100979469478 ... + 1.17174775425 0.629625188037 5.75 0.403003686814 0.902394579377 ... + 0.991163981251 2.50862910684 4.75 -1.44963996982 1.16150986945 ... + 0.967603566096 2.12003739013 4.75 0.610846030775 -0.889994896068 ... + 1.14689383604 1.24185011459 4.75 2.01098091308 -1.73846431001 ... + 1.32593824054 0.990713820685 4.75 -0.0955142989332 -0.0369257308362 ... + 0.861135002644 -0.24744943605 6 1.72793107135 -0.691506789639 ... + 1.26870850151 2.09844764887 6.5 1.50720217572 -1.31399187077 ... + 0.260364987715 1.10650139716 6.5 1.13659047496 0.0720441664643 ... + 1.09731242214 0.490796381346 7.25 4.59123894147 -2.14073070763 ... + 1.63792841781 0.612652594286 6.75 1.79604605035 -0.644363995357 ... + 1.48465576034 0.978295808687 6.75 -2.00753620902 1.39437534964 ... + 1.0987608663 4.25212569087 6.25 -2.58901196498 2.56054320803 ... + 1.42592178132 2.76984518311 6.25 0.888195752358 1.03114549274 ... + 1.52958239462 1.31795955491 6.5 -0.902907564082 -0.0952198893776 ... + 1.0170168994 2.14733589918 7 -1.3054866978 2.68803738466 ... + 0.723253652257 3.43552889347 7.5 1.8213700853 0.592593586195 ... + 1.24720806008 3.87383806577 7.5 0.0522300654168 0.988871238698 ... + 0.482531471239 2.67793287032 7.5 2.9693944293 -0.108591166081 ... + 0.154056100439 0.927269031704 6.75 0.119222057561 3.30489209451 ... + 0.0694865769274 6.65916526788 6.25 0.889014476084 -2.83976849035 ... + -0.121267434867 0.341442615696 5.25 0.323053239216 -3.49289229012 ... + 0.726473690375 -3.5423730964 4 2.19149290449 -3.20855054004 ... + 1.39271709108 2.63121085718 3.75 0.88406577736 0.75622580197 ... + 1.07502077727 5.88578836799 4.25 -2.55088273352 2.89018116374 ... + 0.759049251607 4.24703604223 4.5 0.575687665685 -0.388292506167 ... + ]; + data = reshape(data,5,86)'; y_obs = data(:,1); pie_obs = data(:,2); R_obs = data(:,3); de = data(:,4); dq = data(:,5); - + %Country: Canada %Sample Range: 1981:2 to 2002:3 %Observations: 86 diff --git a/tests/particle/benchmark.m b/tests/particle/benchmark.m index 6531fa3bca..ddf74133cd 100644 --- a/tests/particle/benchmark.m +++ b/tests/particle/benchmark.m @@ -1,153 +1,153 @@ series = [ 1.760105924130475 0.312845989288584 0.472239512216113 - 1.791115550250920 0.315305579629763 0.495435385609039 - 1.751331053949751 0.311989642569820 0.464766630177063 - 1.765929133664154 0.313176251276488 0.475784761647821 - 1.770872676560947 0.313535941672459 0.479277718740513 - 1.748075630214838 0.311640694207934 0.461812669855265 - 1.740886476370027 0.311073006485788 0.456517504298258 - 1.746988485610710 0.311609842604230 0.461340624803336 - 1.808281456868951 0.316539782119637 0.507629282479002 - 1.854947854385870 0.320010198263909 0.541895324334327 - 1.827811476526137 0.317608694730638 0.519624032701902 - 1.879047068282612 0.321359760057394 0.557145907254063 - 1.887936238720303 0.321683176283716 0.561813543154462 - 1.882365288701271 0.320907888275609 0.555461197000685 - 1.890963491380599 0.321242988024427 0.560026873563179 - 1.882743098340623 0.320289640711274 0.551797310779183 - 1.876245428003903 0.319508363989648 0.545106040180286 - 1.899034955459843 0.320980198691605 0.560776758509276 - 1.919897524223688 0.322227856348739 0.574674345449269 - 1.940465687586868 0.323391885583672 0.588076473486549 - 1.946743468303839 0.323448346524082 0.590378789190440 - 1.918157772981919 0.320928920092838 0.566236466080824 - 1.925845147314101 0.321216558537531 0.570201396175100 - 1.950276054315104 0.322717541652949 0.586824950361549 - 1.952915927458601 0.322540993947346 0.586583808819511 - 1.965636934883926 0.323122493559917 0.594038815545898 - 1.972278860444277 0.323231527516691 0.596759621388749 - 1.959399309100668 0.321916338391799 0.584645544633759 - 1.958073327908836 0.321508830194106 0.581624183440973 - 1.936706642470067 0.319634602213589 0.563522208941135 - 1.947132164851317 0.320188564417158 0.569981980824923 - 1.919592010791757 0.317893953785440 0.547555649660018 - 1.894582145436749 0.315863589696844 0.527608826086009 - 1.875328652440384 0.314322533775785 0.512518217710308 - 1.818937674207909 0.309930593995679 0.469772963605365 - 1.842409309222495 0.311897436693824 0.488301677052811 - 1.845447947284471 0.312192107041639 0.490975676211932 - 1.829190530052879 0.310975037205003 0.479016383910071 - 1.851212468593380 0.312780063456632 0.496217792811673 - 1.817833267055856 0.310203236444623 0.471201641902107 - 1.814097651048634 0.310028641358866 0.469129333784112 - 1.808063752653222 0.309676136030093 0.465359164080259 - 1.812053865835763 0.310126209868808 0.469216929060463 - 1.815799385165197 0.310539545366918 0.472785315494855 - 1.798798028758880 0.309298628496020 0.460618548651907 - 1.796971476500592 0.309299647541166 0.460158134508980 - 1.792859811632106 0.309117520299899 0.457969407540741 - 1.802670357795570 0.310047046957601 0.466302337158534 - 1.820354449456020 0.311558370446942 0.480365151317462 - 1.837863518950930 0.312988951978216 0.493967328821185 - 1.819974600115587 0.311600489058620 0.480537413839488 - 1.819271706701453 0.311606389118186 0.480384082633725 - 1.796029494102046 0.309829708408597 0.463237300920444 - 1.775524357691159 0.308313824436222 0.448559541114655 - 1.774854815875979 0.308434688960723 0.449144066862645 - 1.800835802767033 0.310677704459576 0.469765050688536 - 1.786059157721867 0.309590821826591 0.459188017661675 - 1.791551405000660 0.310156043725194 0.464114176691556 - 1.786523594020741 0.309861195621005 0.460986828042084 - 1.804952143362207 0.311441919821646 0.475591467341628 - 1.784480090431664 0.309872669759674 0.460532950060849 - 1.784140477821738 0.309959999276874 0.460985722206660 - 1.792798863056227 0.310761222426831 0.468191678518626 - 1.810747873450371 0.312264562058321 0.482223441024178 - 1.836065173354547 0.314274983408592 0.501492175433812 - 1.834938445492660 0.314139706316670 0.500357204123308 - 1.806164052494138 0.311841299442154 0.478396307371778 - 1.791620538153089 0.310730861290031 0.467698336394830 - 1.772173414017760 0.309256295298234 0.453561242440342 - 1.812359648762609 0.312589557817234 0.484663233994422 - 1.799780206306195 0.311608460056369 0.475265269172501 - 1.811364242815336 0.312573632439023 0.484300778401714 - 1.806180627845691 0.312178076723633 0.480478570801151 - 1.820046807592720 0.313298422774191 0.491109285086001 - 1.804568707455205 0.312065809617281 0.479359179539144 - 1.778702229794904 0.310038401087946 0.460068807524478 - 1.753649470369830 0.308120981940320 0.441860777634412 - 1.762068124424802 0.308974588046040 0.449247521833160 - 1.758856007155504 0.308854726469356 0.447693105953493 - 1.755433459009933 0.308720641041879 0.446000172507877 - 1.779715943854885 0.310825716005938 0.465178127643472 - 1.783930656673236 0.311234452750944 0.468790547227773 - 1.786393861473134 0.311487455757189 0.470991209360008 - 1.812898088968145 0.313635733468485 0.491256411174780 - 1.797000942820567 0.312346799207385 0.479078496049043 - 1.807708490475648 0.313210619724172 0.487246468090725 - 1.820545018487566 0.314204773496048 0.496832484203625 - 1.814116326762029 0.313647239601944 0.491664078190780 - 1.815926310618496 0.313758727958057 0.492837457825446 - 1.793643825095235 0.311961730422198 0.475822245177027 - 1.772611874266904 0.310310656389495 0.460168156652974 - 1.773842053215969 0.310499043015798 0.461642812402857 - 1.785642136192052 0.311526453631286 0.471032222071789 - 1.829627605677892 0.315044478550508 0.504474308367718 - 1.815474499865232 0.313850063604634 0.493282068447158 - 1.816739274169429 0.313910944956201 0.493994123075643 - 1.813254431983305 0.313595577041968 0.491112183202942 - 1.777865207201645 0.310754679633359 0.464261094025897 - 1.769595829699111 0.310163842241233 0.458485858065570 - 1.738659830875185 0.307745681157472 0.435795806472776 - 1.753436721676202 0.309129771430515 0.447999836470890 - 1.738481436021817 0.308039101942578 0.437545017347768 - 1.740721029687560 0.308389115201939 0.440245658063711 - 1.732029327854716 0.307829919218540 0.434648762458203 - 1.737881122071139 0.308481963044799 0.440093163154560 - 1.728349104083563 0.307847119795516 0.433830656073788 - 1.737427954717117 0.308761979466418 0.441680792447009 - 1.750442947374700 0.309959966873872 0.452290462457059 - 1.779708864329036 0.312413921952660 0.474876889887843 - 1.775517700307935 0.312080924290991 0.471738746822015 - 1.738514480440751 0.309096953236020 0.443991465279803 - 1.724939674799569 0.308103998655976 0.434532905394758 - 1.748639894643620 0.310202459511950 0.453294130844291 - 1.730755612953242 0.308820365538791 0.440340001996458 - 1.747650308897352 0.310332409785786 0.453823831757850 - 1.749916699862329 0.310591600424986 0.455980263561499 - 1.774426772869005 0.312637115042041 0.474818879600935 - 1.740468164509070 0.309876282879142 0.449208911368321 - 1.737549008596557 0.309727704615865 0.447559410722363 - 1.717860431453982 0.308201819817147 0.433340786017471 - 1.767957927064596 0.312440621914469 0.471904911234585 - 1.781541660272785 0.313526179152300 0.482105532880402 - 1.804344557934195 0.315294209577413 0.499025051607507 - 1.784390243718790 0.313599070228016 0.483320723495016 - 1.775311536722649 0.312826632807963 0.476202483262179 - 1.769910016585468 0.312375180855473 0.472029256009528 - 1.788150491156262 0.313835100220238 0.485763549426003 - 1.782208569646677 0.313306245996605 0.480957924899580 - 1.793299392486021 0.314155939009175 0.489106667914307 - 1.756885968603183 0.311168062389533 0.461287567602054 - 1.750759539703974 0.310714859720743 0.456944873825189 - 1.736951131154746 0.309648094136421 0.446925313549972 - 1.711160587304450 0.307618648711839 0.428144813997209 - 1.720963686450892 0.308600975424972 0.436526291240511 - 1.726695519089401 0.309207201827563 0.441636496567855 - 1.728089508420109 0.309432993463704 0.443352306847972 - 1.706713941073114 0.307765747865817 0.427915961562161 - 1.726924471697119 0.309600667916548 0.444058294820935 - 1.733588015863146 0.310242486127838 0.449633093256537 - 1.729174707935853 0.309950688669380 0.446740897858215 - 1.730286135569681 0.310122869634148 0.448060312437253 - 1.726601265171260 0.309893747429677 0.445735020251979 - 1.698421870820049 0.307636786323920 0.425068312709748 - 1.695448780500048 0.307550916364643 0.423804837967207 - 1.683650854279764 0.306723382060783 0.415936535399100 - 1.669913985903250 0.305753527158022 0.406787487941312 - 1.653878134082938 0.304611079255971 0.396118930676138 - 1.648446560982758 0.304410745365111 0.393617956062407 - 1.619912950387850 0.302205289654123 0.373881240161860 - 1.639388896456292 0.304249793143430 0.390462851630105] ; + 1.791115550250920 0.315305579629763 0.495435385609039 + 1.751331053949751 0.311989642569820 0.464766630177063 + 1.765929133664154 0.313176251276488 0.475784761647821 + 1.770872676560947 0.313535941672459 0.479277718740513 + 1.748075630214838 0.311640694207934 0.461812669855265 + 1.740886476370027 0.311073006485788 0.456517504298258 + 1.746988485610710 0.311609842604230 0.461340624803336 + 1.808281456868951 0.316539782119637 0.507629282479002 + 1.854947854385870 0.320010198263909 0.541895324334327 + 1.827811476526137 0.317608694730638 0.519624032701902 + 1.879047068282612 0.321359760057394 0.557145907254063 + 1.887936238720303 0.321683176283716 0.561813543154462 + 1.882365288701271 0.320907888275609 0.555461197000685 + 1.890963491380599 0.321242988024427 0.560026873563179 + 1.882743098340623 0.320289640711274 0.551797310779183 + 1.876245428003903 0.319508363989648 0.545106040180286 + 1.899034955459843 0.320980198691605 0.560776758509276 + 1.919897524223688 0.322227856348739 0.574674345449269 + 1.940465687586868 0.323391885583672 0.588076473486549 + 1.946743468303839 0.323448346524082 0.590378789190440 + 1.918157772981919 0.320928920092838 0.566236466080824 + 1.925845147314101 0.321216558537531 0.570201396175100 + 1.950276054315104 0.322717541652949 0.586824950361549 + 1.952915927458601 0.322540993947346 0.586583808819511 + 1.965636934883926 0.323122493559917 0.594038815545898 + 1.972278860444277 0.323231527516691 0.596759621388749 + 1.959399309100668 0.321916338391799 0.584645544633759 + 1.958073327908836 0.321508830194106 0.581624183440973 + 1.936706642470067 0.319634602213589 0.563522208941135 + 1.947132164851317 0.320188564417158 0.569981980824923 + 1.919592010791757 0.317893953785440 0.547555649660018 + 1.894582145436749 0.315863589696844 0.527608826086009 + 1.875328652440384 0.314322533775785 0.512518217710308 + 1.818937674207909 0.309930593995679 0.469772963605365 + 1.842409309222495 0.311897436693824 0.488301677052811 + 1.845447947284471 0.312192107041639 0.490975676211932 + 1.829190530052879 0.310975037205003 0.479016383910071 + 1.851212468593380 0.312780063456632 0.496217792811673 + 1.817833267055856 0.310203236444623 0.471201641902107 + 1.814097651048634 0.310028641358866 0.469129333784112 + 1.808063752653222 0.309676136030093 0.465359164080259 + 1.812053865835763 0.310126209868808 0.469216929060463 + 1.815799385165197 0.310539545366918 0.472785315494855 + 1.798798028758880 0.309298628496020 0.460618548651907 + 1.796971476500592 0.309299647541166 0.460158134508980 + 1.792859811632106 0.309117520299899 0.457969407540741 + 1.802670357795570 0.310047046957601 0.466302337158534 + 1.820354449456020 0.311558370446942 0.480365151317462 + 1.837863518950930 0.312988951978216 0.493967328821185 + 1.819974600115587 0.311600489058620 0.480537413839488 + 1.819271706701453 0.311606389118186 0.480384082633725 + 1.796029494102046 0.309829708408597 0.463237300920444 + 1.775524357691159 0.308313824436222 0.448559541114655 + 1.774854815875979 0.308434688960723 0.449144066862645 + 1.800835802767033 0.310677704459576 0.469765050688536 + 1.786059157721867 0.309590821826591 0.459188017661675 + 1.791551405000660 0.310156043725194 0.464114176691556 + 1.786523594020741 0.309861195621005 0.460986828042084 + 1.804952143362207 0.311441919821646 0.475591467341628 + 1.784480090431664 0.309872669759674 0.460532950060849 + 1.784140477821738 0.309959999276874 0.460985722206660 + 1.792798863056227 0.310761222426831 0.468191678518626 + 1.810747873450371 0.312264562058321 0.482223441024178 + 1.836065173354547 0.314274983408592 0.501492175433812 + 1.834938445492660 0.314139706316670 0.500357204123308 + 1.806164052494138 0.311841299442154 0.478396307371778 + 1.791620538153089 0.310730861290031 0.467698336394830 + 1.772173414017760 0.309256295298234 0.453561242440342 + 1.812359648762609 0.312589557817234 0.484663233994422 + 1.799780206306195 0.311608460056369 0.475265269172501 + 1.811364242815336 0.312573632439023 0.484300778401714 + 1.806180627845691 0.312178076723633 0.480478570801151 + 1.820046807592720 0.313298422774191 0.491109285086001 + 1.804568707455205 0.312065809617281 0.479359179539144 + 1.778702229794904 0.310038401087946 0.460068807524478 + 1.753649470369830 0.308120981940320 0.441860777634412 + 1.762068124424802 0.308974588046040 0.449247521833160 + 1.758856007155504 0.308854726469356 0.447693105953493 + 1.755433459009933 0.308720641041879 0.446000172507877 + 1.779715943854885 0.310825716005938 0.465178127643472 + 1.783930656673236 0.311234452750944 0.468790547227773 + 1.786393861473134 0.311487455757189 0.470991209360008 + 1.812898088968145 0.313635733468485 0.491256411174780 + 1.797000942820567 0.312346799207385 0.479078496049043 + 1.807708490475648 0.313210619724172 0.487246468090725 + 1.820545018487566 0.314204773496048 0.496832484203625 + 1.814116326762029 0.313647239601944 0.491664078190780 + 1.815926310618496 0.313758727958057 0.492837457825446 + 1.793643825095235 0.311961730422198 0.475822245177027 + 1.772611874266904 0.310310656389495 0.460168156652974 + 1.773842053215969 0.310499043015798 0.461642812402857 + 1.785642136192052 0.311526453631286 0.471032222071789 + 1.829627605677892 0.315044478550508 0.504474308367718 + 1.815474499865232 0.313850063604634 0.493282068447158 + 1.816739274169429 0.313910944956201 0.493994123075643 + 1.813254431983305 0.313595577041968 0.491112183202942 + 1.777865207201645 0.310754679633359 0.464261094025897 + 1.769595829699111 0.310163842241233 0.458485858065570 + 1.738659830875185 0.307745681157472 0.435795806472776 + 1.753436721676202 0.309129771430515 0.447999836470890 + 1.738481436021817 0.308039101942578 0.437545017347768 + 1.740721029687560 0.308389115201939 0.440245658063711 + 1.732029327854716 0.307829919218540 0.434648762458203 + 1.737881122071139 0.308481963044799 0.440093163154560 + 1.728349104083563 0.307847119795516 0.433830656073788 + 1.737427954717117 0.308761979466418 0.441680792447009 + 1.750442947374700 0.309959966873872 0.452290462457059 + 1.779708864329036 0.312413921952660 0.474876889887843 + 1.775517700307935 0.312080924290991 0.471738746822015 + 1.738514480440751 0.309096953236020 0.443991465279803 + 1.724939674799569 0.308103998655976 0.434532905394758 + 1.748639894643620 0.310202459511950 0.453294130844291 + 1.730755612953242 0.308820365538791 0.440340001996458 + 1.747650308897352 0.310332409785786 0.453823831757850 + 1.749916699862329 0.310591600424986 0.455980263561499 + 1.774426772869005 0.312637115042041 0.474818879600935 + 1.740468164509070 0.309876282879142 0.449208911368321 + 1.737549008596557 0.309727704615865 0.447559410722363 + 1.717860431453982 0.308201819817147 0.433340786017471 + 1.767957927064596 0.312440621914469 0.471904911234585 + 1.781541660272785 0.313526179152300 0.482105532880402 + 1.804344557934195 0.315294209577413 0.499025051607507 + 1.784390243718790 0.313599070228016 0.483320723495016 + 1.775311536722649 0.312826632807963 0.476202483262179 + 1.769910016585468 0.312375180855473 0.472029256009528 + 1.788150491156262 0.313835100220238 0.485763549426003 + 1.782208569646677 0.313306245996605 0.480957924899580 + 1.793299392486021 0.314155939009175 0.489106667914307 + 1.756885968603183 0.311168062389533 0.461287567602054 + 1.750759539703974 0.310714859720743 0.456944873825189 + 1.736951131154746 0.309648094136421 0.446925313549972 + 1.711160587304450 0.307618648711839 0.428144813997209 + 1.720963686450892 0.308600975424972 0.436526291240511 + 1.726695519089401 0.309207201827563 0.441636496567855 + 1.728089508420109 0.309432993463704 0.443352306847972 + 1.706713941073114 0.307765747865817 0.427915961562161 + 1.726924471697119 0.309600667916548 0.444058294820935 + 1.733588015863146 0.310242486127838 0.449633093256537 + 1.729174707935853 0.309950688669380 0.446740897858215 + 1.730286135569681 0.310122869634148 0.448060312437253 + 1.726601265171260 0.309893747429677 0.445735020251979 + 1.698421870820049 0.307636786323920 0.425068312709748 + 1.695448780500048 0.307550916364643 0.423804837967207 + 1.683650854279764 0.306723382060783 0.415936535399100 + 1.669913985903250 0.305753527158022 0.406787487941312 + 1.653878134082938 0.304611079255971 0.396118930676138 + 1.648446560982758 0.304410745365111 0.393617956062407 + 1.619912950387850 0.302205289654123 0.373881240161860 + 1.639388896456292 0.304249793143430 0.390462851630105] ; set_dynare_seed('default'); diff --git a/tests/particle/dsge_base2_steadystate.m b/tests/particle/dsge_base2_steadystate.m index e714180ecf..ae947de5b6 100644 --- a/tests/particle/dsge_base2_steadystate.m +++ b/tests/particle/dsge_base2_steadystate.m @@ -1,4 +1,4 @@ -function [ys,check,penlt] = mze_steadystate(ys,exe) +function [ys,check,penlt] = dsge_base2_steadystate(ys,exe) global M_ persistent idx NumberOfParameters NumberOfEndogenousVariables diff --git a/tests/particle/extreme.m b/tests/particle/extreme.m index c6a7dba26e..cf22bc161c 100644 --- a/tests/particle/extreme.m +++ b/tests/particle/extreme.m @@ -1,153 +1,153 @@ series = [ 1.831805242058402 0.326183687045750 0.571394980772413 - 1.984702489138465 0.335169748463059 0.670420465974991 - 1.797086108881765 0.323738578123985 0.547308667595199 - 1.868444017934854 0.328080679826740 0.593052853366243 - 1.895360226929111 0.329595817929623 0.609928225756056 - 1.790832321540929 0.323045792420179 0.541464341531705 - 1.760361113136238 0.321043326280900 0.521508650424371 - 1.790915969739093 0.322955490721488 0.540943037175086 - 2.094179862755653 0.340746414276014 0.739070344706716 - 2.351323603033167 0.353813072593956 0.910247160484619 - 2.210203726655083 0.345882571920415 0.814539583358436 - 2.502764243167320 0.360529072208579 1.010034424820335 - 2.569208789183717 0.362428841518866 1.055534562597981 - 2.547595154425792 0.360952177511515 1.039047992042150 - 2.609146531246866 0.363696577503416 1.078846711754488 - 2.571616001378042 0.361498291257734 1.051509986784717 - 2.541891024016321 0.360071155104088 1.028624099377237 - 2.689409275114334 0.366815600832908 1.128105032869184 - 2.836542116534716 0.372524050373151 1.229814150394072 - 2.989371778822207 0.378100564290163 1.336372695875410 - 3.053527484610819 0.379663367671839 1.381646099750626 - 2.881583926807516 0.371937515643922 1.259734111646857 - 2.937243454748999 0.375283171360020 1.293755438734926 - 3.118203726771490 0.382439157449350 1.420284000580079 - 3.162221425436911 0.382978730072962 1.452879778911405 - 3.270131116244304 0.387045130060735 1.528307700189284 - 3.342461488854179 0.389086673292955 1.580437828600709 - 3.273192452854725 0.385774052536333 1.531120751032252 - 3.275458381986319 0.386357608290016 1.529824198671000 - 3.140839718197673 0.380646875429989 1.433095635793685 - 3.219561570532605 0.384603663097986 1.485897119680615 - 3.046020484023621 0.376619364484571 1.363233558132235 - 2.875797146770958 0.369735139885355 1.238996996305890 - 2.749622178822991 0.364254301976450 1.147444649402347 - 2.392412920492719 0.346784183865998 0.894670846513585 - 2.538569352588205 0.354489172654320 0.995609156305664 - 2.568582116289918 0.355797653561804 1.017051641895211 - 2.473671797066097 0.350928176810026 0.950257635346841 - 2.620458952999331 0.358256344008751 1.053181588833955 - 2.417877040613256 0.347870025062447 0.911027320823617 - 2.397670314991495 0.346921694035742 0.896082963087687 - 2.366883065577286 0.345289845529682 0.874408874120826 - 2.398421161488027 0.346918229004658 0.896452534897949 - 2.429022432917506 0.348458911692765 0.917940360480214 - 2.329480001673114 0.343218039531235 0.848090572728616 - 2.323778203248307 0.342928605968239 0.843955176095121 - 2.304540951504139 0.341899250525543 0.830468123386457 - 2.371683909087846 0.345441636785679 0.877514351279621 - 2.490195690751581 0.351506590301081 0.960838542863225 - 2.611493982190879 0.357442690934199 1.046618170917642 - 2.503405760920729 0.351887256856341 0.970703524500816 - 2.502374477458479 0.351865505580769 0.969514474424414 - 2.359478710434038 0.344470328092121 0.868876338341471 - 2.235614401552562 0.337896673011709 0.781763976906244 - 2.237065512060965 0.337998138421979 0.782823153982811 - 2.405249293222310 0.346934628008361 0.900834255435682 - 2.317208444296528 0.342286974469216 0.839012239040374 - 2.356353796613430 0.344364397044866 0.866418340883992 - 2.329623188746103 0.342942028228397 0.847657055734664 - 2.451699791573160 0.349287377428137 0.933477131054643 - 2.326653326931049 0.342720642543720 0.845654324922242 - 2.328176409623511 0.342824741941796 0.846575965562970 - 2.387605984815603 0.345939128892875 0.888332186956944 - 2.508162718702005 0.352082240173918 0.973304394397491 - 2.682098704221850 0.360548632109151 1.096619975241019 - 2.683210187517440 0.360334208336806 1.098196347992521 - 2.495448180812561 0.351002978084749 0.965191387615425 - 2.400677321318541 0.346260011274923 0.897566056014340 - 2.279709427240636 0.339905112366486 0.812280162193439 - 2.543742139352676 0.353571759314430 0.998416614177836 - 2.466804544683231 0.349570487450388 0.944374705292784 - 2.545923232397798 0.353562161906674 1.000133847612044 - 2.516609766492527 0.351998960811952 0.979615171231177 - 2.612598123816773 0.356735709969249 1.047580818676070 - 2.514581877733644 0.351736314350723 0.978472497403178 - 2.346814819442599 0.343151537387364 0.859593502999736 - 2.190061053436186 0.334783668048696 0.749123665788591 - 2.248248190346710 0.337975537211722 0.790133451151325 - 2.231245577955952 0.337099249591117 0.778120306643938 - 2.213620813638347 0.336172963701584 0.765787919679999 - 2.372368622485876 0.344669139219734 0.877475808694303 - 2.402394532412963 0.346236714114806 0.898578702308663 - 2.421632200543405 0.347211723112796 0.912182166100545 - 2.600814823475984 0.356206951763316 1.039020125139189 - 2.499717430182296 0.351010191098421 0.967897548419094 - 2.572211042595633 0.354659119526649 1.018967108776286 - 2.663557373274198 0.359030754462987 1.084127294941044 - 2.624508384540186 0.356972637699486 1.056848324055082 - 2.638578391882532 0.357631581496546 1.066764536958948 - 2.490619544707827 0.350219619250241 0.961836430307891 - 2.351499685312523 0.343126531712676 0.862944429125821 - 2.361744409273265 0.343693557597678 0.870045243822348 - 2.442494968080141 0.347873202461086 0.927160968018594 - 2.745123805313629 0.362770643020118 1.142349343426111 - 2.655499503705102 0.358132929197389 1.079779897215503 - 2.663850696079126 0.358574973979539 1.085379958290025 - 2.642540272757401 0.357462408799286 1.070401889504760 - 2.404037994048185 0.345491588561572 0.900884395443159 - 2.348769349405146 0.342712258600463 0.861219163642359 - 2.151645849089095 0.332135094769575 0.722080451054128 - 2.252343203542463 0.337640454116440 0.793256172150181 - 2.158313350236808 0.332590653949928 0.726803768436609 - 2.177375300770910 0.333675009914873 0.740364253592691 - 2.125333870619463 0.330857624626525 0.703750112206580 - 2.166601866570710 0.333192210611845 0.732859178568121 - 2.108843923653465 0.330052027456209 0.692243810014626 - 2.170141182101418 0.333505871231270 0.735409067431057 - 2.254451075620278 0.338167643418567 0.794516594921980 - 2.446506792318999 0.348291161505242 0.929849297341202 - 2.420231514001146 0.346916032088861 0.911318264635804 - 2.181800682169253 0.334237425269950 0.743319742477540 - 2.099742314313267 0.329709128744430 0.685953130712018 - 2.253483605428042 0.338209143902201 0.794027010792921 - 2.139849820112224 0.332063175615470 0.714018808416182 - 2.250143469020041 0.338136253085361 0.791600043424550 - 2.264735780708348 0.338979274263224 0.801680191863518 - 2.425121660100526 0.347436401511180 0.914625338218002 - 2.206590644219017 0.335830510968584 0.760892479739662 - 2.189826738892797 0.334948331690477 0.749202347672420 - 2.069051029835663 0.328235256714593 0.664845519474291 - 2.391186717627713 0.345755663706005 0.891100361136644 - 2.478723828708481 0.350304667654797 0.952470631759343 - 2.633589418757750 0.357943374909926 1.062259709272963 - 2.501720459872961 0.351218582106388 0.969405568955396 - 2.438825464623843 0.348074452736294 0.924486170126454 - 2.402956953910124 0.346226899680829 0.899047137304136 - 2.524642865536631 0.352419486777799 0.985020882838327 - 2.486592708507011 0.350410839822111 0.958347818799192 - 2.561198294838873 0.354135408220830 1.011115336262727 - 2.320611782924737 0.341730318797737 0.841256200313256 - 2.279686641907904 0.339623952830723 0.812097446193594 - 2.192677970879956 0.334934939278205 0.750983611681066 - 2.034253696137675 0.326074943710870 0.640293522184461 - 2.100411653364924 0.329874859982984 0.687004183670506 - 2.136363142365890 0.331978934678318 0.712025267361496 - 2.145765618417357 0.332571647651874 0.718576738965439 - 2.015355353786295 0.325223748826715 0.627682513187217 - 2.144497911280442 0.332597163880719 0.718235199174144 - 2.184419901142909 0.334907791330299 0.745855884353715 - 2.156941988546521 0.333440304455754 0.726637490761326 - 2.164896092557094 0.333922888423381 0.732317236030551 - 2.142495889557134 0.332723978543999 0.716747302318746 - 1.972335146672318 0.323009944472129 0.598611382636265 - 1.960032978731420 0.322337700909600 0.590822458953444 - 1.892736021185325 0.318399928224863 0.544712037197812 - 1.817727518077365 0.313890597043592 0.493800641801013 - 1.732818354432900 0.308638151751227 0.436587334970866 - 1.709712053275818 0.307294092052731 0.421979569450315 - 1.560777278572816 0.297457158767192 0.322157189475494 - 1.678355925543266 0.305618851041591 0.403484108249424] ; + 1.984702489138465 0.335169748463059 0.670420465974991 + 1.797086108881765 0.323738578123985 0.547308667595199 + 1.868444017934854 0.328080679826740 0.593052853366243 + 1.895360226929111 0.329595817929623 0.609928225756056 + 1.790832321540929 0.323045792420179 0.541464341531705 + 1.760361113136238 0.321043326280900 0.521508650424371 + 1.790915969739093 0.322955490721488 0.540943037175086 + 2.094179862755653 0.340746414276014 0.739070344706716 + 2.351323603033167 0.353813072593956 0.910247160484619 + 2.210203726655083 0.345882571920415 0.814539583358436 + 2.502764243167320 0.360529072208579 1.010034424820335 + 2.569208789183717 0.362428841518866 1.055534562597981 + 2.547595154425792 0.360952177511515 1.039047992042150 + 2.609146531246866 0.363696577503416 1.078846711754488 + 2.571616001378042 0.361498291257734 1.051509986784717 + 2.541891024016321 0.360071155104088 1.028624099377237 + 2.689409275114334 0.366815600832908 1.128105032869184 + 2.836542116534716 0.372524050373151 1.229814150394072 + 2.989371778822207 0.378100564290163 1.336372695875410 + 3.053527484610819 0.379663367671839 1.381646099750626 + 2.881583926807516 0.371937515643922 1.259734111646857 + 2.937243454748999 0.375283171360020 1.293755438734926 + 3.118203726771490 0.382439157449350 1.420284000580079 + 3.162221425436911 0.382978730072962 1.452879778911405 + 3.270131116244304 0.387045130060735 1.528307700189284 + 3.342461488854179 0.389086673292955 1.580437828600709 + 3.273192452854725 0.385774052536333 1.531120751032252 + 3.275458381986319 0.386357608290016 1.529824198671000 + 3.140839718197673 0.380646875429989 1.433095635793685 + 3.219561570532605 0.384603663097986 1.485897119680615 + 3.046020484023621 0.376619364484571 1.363233558132235 + 2.875797146770958 0.369735139885355 1.238996996305890 + 2.749622178822991 0.364254301976450 1.147444649402347 + 2.392412920492719 0.346784183865998 0.894670846513585 + 2.538569352588205 0.354489172654320 0.995609156305664 + 2.568582116289918 0.355797653561804 1.017051641895211 + 2.473671797066097 0.350928176810026 0.950257635346841 + 2.620458952999331 0.358256344008751 1.053181588833955 + 2.417877040613256 0.347870025062447 0.911027320823617 + 2.397670314991495 0.346921694035742 0.896082963087687 + 2.366883065577286 0.345289845529682 0.874408874120826 + 2.398421161488027 0.346918229004658 0.896452534897949 + 2.429022432917506 0.348458911692765 0.917940360480214 + 2.329480001673114 0.343218039531235 0.848090572728616 + 2.323778203248307 0.342928605968239 0.843955176095121 + 2.304540951504139 0.341899250525543 0.830468123386457 + 2.371683909087846 0.345441636785679 0.877514351279621 + 2.490195690751581 0.351506590301081 0.960838542863225 + 2.611493982190879 0.357442690934199 1.046618170917642 + 2.503405760920729 0.351887256856341 0.970703524500816 + 2.502374477458479 0.351865505580769 0.969514474424414 + 2.359478710434038 0.344470328092121 0.868876338341471 + 2.235614401552562 0.337896673011709 0.781763976906244 + 2.237065512060965 0.337998138421979 0.782823153982811 + 2.405249293222310 0.346934628008361 0.900834255435682 + 2.317208444296528 0.342286974469216 0.839012239040374 + 2.356353796613430 0.344364397044866 0.866418340883992 + 2.329623188746103 0.342942028228397 0.847657055734664 + 2.451699791573160 0.349287377428137 0.933477131054643 + 2.326653326931049 0.342720642543720 0.845654324922242 + 2.328176409623511 0.342824741941796 0.846575965562970 + 2.387605984815603 0.345939128892875 0.888332186956944 + 2.508162718702005 0.352082240173918 0.973304394397491 + 2.682098704221850 0.360548632109151 1.096619975241019 + 2.683210187517440 0.360334208336806 1.098196347992521 + 2.495448180812561 0.351002978084749 0.965191387615425 + 2.400677321318541 0.346260011274923 0.897566056014340 + 2.279709427240636 0.339905112366486 0.812280162193439 + 2.543742139352676 0.353571759314430 0.998416614177836 + 2.466804544683231 0.349570487450388 0.944374705292784 + 2.545923232397798 0.353562161906674 1.000133847612044 + 2.516609766492527 0.351998960811952 0.979615171231177 + 2.612598123816773 0.356735709969249 1.047580818676070 + 2.514581877733644 0.351736314350723 0.978472497403178 + 2.346814819442599 0.343151537387364 0.859593502999736 + 2.190061053436186 0.334783668048696 0.749123665788591 + 2.248248190346710 0.337975537211722 0.790133451151325 + 2.231245577955952 0.337099249591117 0.778120306643938 + 2.213620813638347 0.336172963701584 0.765787919679999 + 2.372368622485876 0.344669139219734 0.877475808694303 + 2.402394532412963 0.346236714114806 0.898578702308663 + 2.421632200543405 0.347211723112796 0.912182166100545 + 2.600814823475984 0.356206951763316 1.039020125139189 + 2.499717430182296 0.351010191098421 0.967897548419094 + 2.572211042595633 0.354659119526649 1.018967108776286 + 2.663557373274198 0.359030754462987 1.084127294941044 + 2.624508384540186 0.356972637699486 1.056848324055082 + 2.638578391882532 0.357631581496546 1.066764536958948 + 2.490619544707827 0.350219619250241 0.961836430307891 + 2.351499685312523 0.343126531712676 0.862944429125821 + 2.361744409273265 0.343693557597678 0.870045243822348 + 2.442494968080141 0.347873202461086 0.927160968018594 + 2.745123805313629 0.362770643020118 1.142349343426111 + 2.655499503705102 0.358132929197389 1.079779897215503 + 2.663850696079126 0.358574973979539 1.085379958290025 + 2.642540272757401 0.357462408799286 1.070401889504760 + 2.404037994048185 0.345491588561572 0.900884395443159 + 2.348769349405146 0.342712258600463 0.861219163642359 + 2.151645849089095 0.332135094769575 0.722080451054128 + 2.252343203542463 0.337640454116440 0.793256172150181 + 2.158313350236808 0.332590653949928 0.726803768436609 + 2.177375300770910 0.333675009914873 0.740364253592691 + 2.125333870619463 0.330857624626525 0.703750112206580 + 2.166601866570710 0.333192210611845 0.732859178568121 + 2.108843923653465 0.330052027456209 0.692243810014626 + 2.170141182101418 0.333505871231270 0.735409067431057 + 2.254451075620278 0.338167643418567 0.794516594921980 + 2.446506792318999 0.348291161505242 0.929849297341202 + 2.420231514001146 0.346916032088861 0.911318264635804 + 2.181800682169253 0.334237425269950 0.743319742477540 + 2.099742314313267 0.329709128744430 0.685953130712018 + 2.253483605428042 0.338209143902201 0.794027010792921 + 2.139849820112224 0.332063175615470 0.714018808416182 + 2.250143469020041 0.338136253085361 0.791600043424550 + 2.264735780708348 0.338979274263224 0.801680191863518 + 2.425121660100526 0.347436401511180 0.914625338218002 + 2.206590644219017 0.335830510968584 0.760892479739662 + 2.189826738892797 0.334948331690477 0.749202347672420 + 2.069051029835663 0.328235256714593 0.664845519474291 + 2.391186717627713 0.345755663706005 0.891100361136644 + 2.478723828708481 0.350304667654797 0.952470631759343 + 2.633589418757750 0.357943374909926 1.062259709272963 + 2.501720459872961 0.351218582106388 0.969405568955396 + 2.438825464623843 0.348074452736294 0.924486170126454 + 2.402956953910124 0.346226899680829 0.899047137304136 + 2.524642865536631 0.352419486777799 0.985020882838327 + 2.486592708507011 0.350410839822111 0.958347818799192 + 2.561198294838873 0.354135408220830 1.011115336262727 + 2.320611782924737 0.341730318797737 0.841256200313256 + 2.279686641907904 0.339623952830723 0.812097446193594 + 2.192677970879956 0.334934939278205 0.750983611681066 + 2.034253696137675 0.326074943710870 0.640293522184461 + 2.100411653364924 0.329874859982984 0.687004183670506 + 2.136363142365890 0.331978934678318 0.712025267361496 + 2.145765618417357 0.332571647651874 0.718576738965439 + 2.015355353786295 0.325223748826715 0.627682513187217 + 2.144497911280442 0.332597163880719 0.718235199174144 + 2.184419901142909 0.334907791330299 0.745855884353715 + 2.156941988546521 0.333440304455754 0.726637490761326 + 2.164896092557094 0.333922888423381 0.732317236030551 + 2.142495889557134 0.332723978543999 0.716747302318746 + 1.972335146672318 0.323009944472129 0.598611382636265 + 1.960032978731420 0.322337700909600 0.590822458953444 + 1.892736021185325 0.318399928224863 0.544712037197812 + 1.817727518077365 0.313890597043592 0.493800641801013 + 1.732818354432900 0.308638151751227 0.436587334970866 + 1.709712053275818 0.307294092052731 0.421979569450315 + 1.560777278572816 0.297457158767192 0.322157189475494 + 1.678355925543266 0.305618851041591 0.403484108249424] ; set_dynare_seed('default'); diff --git a/tests/particle/risky.m b/tests/particle/risky.m index 4d0b7a8299..33c64573ad 100644 --- a/tests/particle/risky.m +++ b/tests/particle/risky.m @@ -1,153 +1,153 @@ series = [ 1.831805242058402 0.326183687045750 0.571394980772413 - 1.984702489138465 0.335169748463059 0.670420465974991 - 1.797086108881765 0.323738578123985 0.547308667595199 - 1.868444017934854 0.328080679826740 0.593052853366243 - 1.895360226929111 0.329595817929623 0.609928225756056 - 1.790832321540929 0.323045792420179 0.541464341531705 - 1.760361113136238 0.321043326280900 0.521508650424371 - 1.790915969739093 0.322955490721488 0.540943037175086 - 2.094179862755653 0.340746414276014 0.739070344706716 - 2.351323603033167 0.353813072593956 0.910247160484619 - 2.210203726655083 0.345882571920415 0.814539583358436 - 2.502764243167320 0.360529072208579 1.010034424820335 - 2.569208789183717 0.362428841518866 1.055534562597981 - 2.547595154425792 0.360952177511515 1.039047992042150 - 2.609146531246866 0.363696577503416 1.078846711754488 - 2.571616001378042 0.361498291257734 1.051509986784717 - 2.541891024016321 0.360071155104088 1.028624099377237 - 2.689409275114334 0.366815600832908 1.128105032869184 - 2.836542116534716 0.372524050373151 1.229814150394072 - 2.989371778822207 0.378100564290163 1.336372695875410 - 3.053527484610819 0.379663367671839 1.381646099750626 - 2.881583926807516 0.371937515643922 1.259734111646857 - 2.937243454748999 0.375283171360020 1.293755438734926 - 3.118203726771490 0.382439157449350 1.420284000580079 - 3.162221425436911 0.382978730072962 1.452879778911405 - 3.270131116244304 0.387045130060735 1.528307700189284 - 3.342461488854179 0.389086673292955 1.580437828600709 - 3.273192452854725 0.385774052536333 1.531120751032252 - 3.275458381986319 0.386357608290016 1.529824198671000 - 3.140839718197673 0.380646875429989 1.433095635793685 - 3.219561570532605 0.384603663097986 1.485897119680615 - 3.046020484023621 0.376619364484571 1.363233558132235 - 2.875797146770958 0.369735139885355 1.238996996305890 - 2.749622178822991 0.364254301976450 1.147444649402347 - 2.392412920492719 0.346784183865998 0.894670846513585 - 2.538569352588205 0.354489172654320 0.995609156305664 - 2.568582116289918 0.355797653561804 1.017051641895211 - 2.473671797066097 0.350928176810026 0.950257635346841 - 2.620458952999331 0.358256344008751 1.053181588833955 - 2.417877040613256 0.347870025062447 0.911027320823617 - 2.397670314991495 0.346921694035742 0.896082963087687 - 2.366883065577286 0.345289845529682 0.874408874120826 - 2.398421161488027 0.346918229004658 0.896452534897949 - 2.429022432917506 0.348458911692765 0.917940360480214 - 2.329480001673114 0.343218039531235 0.848090572728616 - 2.323778203248307 0.342928605968239 0.843955176095121 - 2.304540951504139 0.341899250525543 0.830468123386457 - 2.371683909087846 0.345441636785679 0.877514351279621 - 2.490195690751581 0.351506590301081 0.960838542863225 - 2.611493982190879 0.357442690934199 1.046618170917642 - 2.503405760920729 0.351887256856341 0.970703524500816 - 2.502374477458479 0.351865505580769 0.969514474424414 - 2.359478710434038 0.344470328092121 0.868876338341471 - 2.235614401552562 0.337896673011709 0.781763976906244 - 2.237065512060965 0.337998138421979 0.782823153982811 - 2.405249293222310 0.346934628008361 0.900834255435682 - 2.317208444296528 0.342286974469216 0.839012239040374 - 2.356353796613430 0.344364397044866 0.866418340883992 - 2.329623188746103 0.342942028228397 0.847657055734664 - 2.451699791573160 0.349287377428137 0.933477131054643 - 2.326653326931049 0.342720642543720 0.845654324922242 - 2.328176409623511 0.342824741941796 0.846575965562970 - 2.387605984815603 0.345939128892875 0.888332186956944 - 2.508162718702005 0.352082240173918 0.973304394397491 - 2.682098704221850 0.360548632109151 1.096619975241019 - 2.683210187517440 0.360334208336806 1.098196347992521 - 2.495448180812561 0.351002978084749 0.965191387615425 - 2.400677321318541 0.346260011274923 0.897566056014340 - 2.279709427240636 0.339905112366486 0.812280162193439 - 2.543742139352676 0.353571759314430 0.998416614177836 - 2.466804544683231 0.349570487450388 0.944374705292784 - 2.545923232397798 0.353562161906674 1.000133847612044 - 2.516609766492527 0.351998960811952 0.979615171231177 - 2.612598123816773 0.356735709969249 1.047580818676070 - 2.514581877733644 0.351736314350723 0.978472497403178 - 2.346814819442599 0.343151537387364 0.859593502999736 - 2.190061053436186 0.334783668048696 0.749123665788591 - 2.248248190346710 0.337975537211722 0.790133451151325 - 2.231245577955952 0.337099249591117 0.778120306643938 - 2.213620813638347 0.336172963701584 0.765787919679999 - 2.372368622485876 0.344669139219734 0.877475808694303 - 2.402394532412963 0.346236714114806 0.898578702308663 - 2.421632200543405 0.347211723112796 0.912182166100545 - 2.600814823475984 0.356206951763316 1.039020125139189 - 2.499717430182296 0.351010191098421 0.967897548419094 - 2.572211042595633 0.354659119526649 1.018967108776286 - 2.663557373274198 0.359030754462987 1.084127294941044 - 2.624508384540186 0.356972637699486 1.056848324055082 - 2.638578391882532 0.357631581496546 1.066764536958948 - 2.490619544707827 0.350219619250241 0.961836430307891 - 2.351499685312523 0.343126531712676 0.862944429125821 - 2.361744409273265 0.343693557597678 0.870045243822348 - 2.442494968080141 0.347873202461086 0.927160968018594 - 2.745123805313629 0.362770643020118 1.142349343426111 - 2.655499503705102 0.358132929197389 1.079779897215503 - 2.663850696079126 0.358574973979539 1.085379958290025 - 2.642540272757401 0.357462408799286 1.070401889504760 - 2.404037994048185 0.345491588561572 0.900884395443159 - 2.348769349405146 0.342712258600463 0.861219163642359 - 2.151645849089095 0.332135094769575 0.722080451054128 - 2.252343203542463 0.337640454116440 0.793256172150181 - 2.158313350236808 0.332590653949928 0.726803768436609 - 2.177375300770910 0.333675009914873 0.740364253592691 - 2.125333870619463 0.330857624626525 0.703750112206580 - 2.166601866570710 0.333192210611845 0.732859178568121 - 2.108843923653465 0.330052027456209 0.692243810014626 - 2.170141182101418 0.333505871231270 0.735409067431057 - 2.254451075620278 0.338167643418567 0.794516594921980 - 2.446506792318999 0.348291161505242 0.929849297341202 - 2.420231514001146 0.346916032088861 0.911318264635804 - 2.181800682169253 0.334237425269950 0.743319742477540 - 2.099742314313267 0.329709128744430 0.685953130712018 - 2.253483605428042 0.338209143902201 0.794027010792921 - 2.139849820112224 0.332063175615470 0.714018808416182 - 2.250143469020041 0.338136253085361 0.791600043424550 - 2.264735780708348 0.338979274263224 0.801680191863518 - 2.425121660100526 0.347436401511180 0.914625338218002 - 2.206590644219017 0.335830510968584 0.760892479739662 - 2.189826738892797 0.334948331690477 0.749202347672420 - 2.069051029835663 0.328235256714593 0.664845519474291 - 2.391186717627713 0.345755663706005 0.891100361136644 - 2.478723828708481 0.350304667654797 0.952470631759343 - 2.633589418757750 0.357943374909926 1.062259709272963 - 2.501720459872961 0.351218582106388 0.969405568955396 - 2.438825464623843 0.348074452736294 0.924486170126454 - 2.402956953910124 0.346226899680829 0.899047137304136 - 2.524642865536631 0.352419486777799 0.985020882838327 - 2.486592708507011 0.350410839822111 0.958347818799192 - 2.561198294838873 0.354135408220830 1.011115336262727 - 2.320611782924737 0.341730318797737 0.841256200313256 - 2.279686641907904 0.339623952830723 0.812097446193594 - 2.192677970879956 0.334934939278205 0.750983611681066 - 2.034253696137675 0.326074943710870 0.640293522184461 - 2.100411653364924 0.329874859982984 0.687004183670506 - 2.136363142365890 0.331978934678318 0.712025267361496 - 2.145765618417357 0.332571647651874 0.718576738965439 - 2.015355353786295 0.325223748826715 0.627682513187217 - 2.144497911280442 0.332597163880719 0.718235199174144 - 2.184419901142909 0.334907791330299 0.745855884353715 - 2.156941988546521 0.333440304455754 0.726637490761326 - 2.164896092557094 0.333922888423381 0.732317236030551 - 2.142495889557134 0.332723978543999 0.716747302318746 - 1.972335146672318 0.323009944472129 0.598611382636265 - 1.960032978731420 0.322337700909600 0.590822458953444 - 1.892736021185325 0.318399928224863 0.544712037197812 - 1.817727518077365 0.313890597043592 0.493800641801013 - 1.732818354432900 0.308638151751227 0.436587334970866 - 1.709712053275818 0.307294092052731 0.421979569450315 - 1.560777278572816 0.297457158767192 0.322157189475494 - 1.678355925543266 0.305618851041591 0.403484108249424] ; + 1.984702489138465 0.335169748463059 0.670420465974991 + 1.797086108881765 0.323738578123985 0.547308667595199 + 1.868444017934854 0.328080679826740 0.593052853366243 + 1.895360226929111 0.329595817929623 0.609928225756056 + 1.790832321540929 0.323045792420179 0.541464341531705 + 1.760361113136238 0.321043326280900 0.521508650424371 + 1.790915969739093 0.322955490721488 0.540943037175086 + 2.094179862755653 0.340746414276014 0.739070344706716 + 2.351323603033167 0.353813072593956 0.910247160484619 + 2.210203726655083 0.345882571920415 0.814539583358436 + 2.502764243167320 0.360529072208579 1.010034424820335 + 2.569208789183717 0.362428841518866 1.055534562597981 + 2.547595154425792 0.360952177511515 1.039047992042150 + 2.609146531246866 0.363696577503416 1.078846711754488 + 2.571616001378042 0.361498291257734 1.051509986784717 + 2.541891024016321 0.360071155104088 1.028624099377237 + 2.689409275114334 0.366815600832908 1.128105032869184 + 2.836542116534716 0.372524050373151 1.229814150394072 + 2.989371778822207 0.378100564290163 1.336372695875410 + 3.053527484610819 0.379663367671839 1.381646099750626 + 2.881583926807516 0.371937515643922 1.259734111646857 + 2.937243454748999 0.375283171360020 1.293755438734926 + 3.118203726771490 0.382439157449350 1.420284000580079 + 3.162221425436911 0.382978730072962 1.452879778911405 + 3.270131116244304 0.387045130060735 1.528307700189284 + 3.342461488854179 0.389086673292955 1.580437828600709 + 3.273192452854725 0.385774052536333 1.531120751032252 + 3.275458381986319 0.386357608290016 1.529824198671000 + 3.140839718197673 0.380646875429989 1.433095635793685 + 3.219561570532605 0.384603663097986 1.485897119680615 + 3.046020484023621 0.376619364484571 1.363233558132235 + 2.875797146770958 0.369735139885355 1.238996996305890 + 2.749622178822991 0.364254301976450 1.147444649402347 + 2.392412920492719 0.346784183865998 0.894670846513585 + 2.538569352588205 0.354489172654320 0.995609156305664 + 2.568582116289918 0.355797653561804 1.017051641895211 + 2.473671797066097 0.350928176810026 0.950257635346841 + 2.620458952999331 0.358256344008751 1.053181588833955 + 2.417877040613256 0.347870025062447 0.911027320823617 + 2.397670314991495 0.346921694035742 0.896082963087687 + 2.366883065577286 0.345289845529682 0.874408874120826 + 2.398421161488027 0.346918229004658 0.896452534897949 + 2.429022432917506 0.348458911692765 0.917940360480214 + 2.329480001673114 0.343218039531235 0.848090572728616 + 2.323778203248307 0.342928605968239 0.843955176095121 + 2.304540951504139 0.341899250525543 0.830468123386457 + 2.371683909087846 0.345441636785679 0.877514351279621 + 2.490195690751581 0.351506590301081 0.960838542863225 + 2.611493982190879 0.357442690934199 1.046618170917642 + 2.503405760920729 0.351887256856341 0.970703524500816 + 2.502374477458479 0.351865505580769 0.969514474424414 + 2.359478710434038 0.344470328092121 0.868876338341471 + 2.235614401552562 0.337896673011709 0.781763976906244 + 2.237065512060965 0.337998138421979 0.782823153982811 + 2.405249293222310 0.346934628008361 0.900834255435682 + 2.317208444296528 0.342286974469216 0.839012239040374 + 2.356353796613430 0.344364397044866 0.866418340883992 + 2.329623188746103 0.342942028228397 0.847657055734664 + 2.451699791573160 0.349287377428137 0.933477131054643 + 2.326653326931049 0.342720642543720 0.845654324922242 + 2.328176409623511 0.342824741941796 0.846575965562970 + 2.387605984815603 0.345939128892875 0.888332186956944 + 2.508162718702005 0.352082240173918 0.973304394397491 + 2.682098704221850 0.360548632109151 1.096619975241019 + 2.683210187517440 0.360334208336806 1.098196347992521 + 2.495448180812561 0.351002978084749 0.965191387615425 + 2.400677321318541 0.346260011274923 0.897566056014340 + 2.279709427240636 0.339905112366486 0.812280162193439 + 2.543742139352676 0.353571759314430 0.998416614177836 + 2.466804544683231 0.349570487450388 0.944374705292784 + 2.545923232397798 0.353562161906674 1.000133847612044 + 2.516609766492527 0.351998960811952 0.979615171231177 + 2.612598123816773 0.356735709969249 1.047580818676070 + 2.514581877733644 0.351736314350723 0.978472497403178 + 2.346814819442599 0.343151537387364 0.859593502999736 + 2.190061053436186 0.334783668048696 0.749123665788591 + 2.248248190346710 0.337975537211722 0.790133451151325 + 2.231245577955952 0.337099249591117 0.778120306643938 + 2.213620813638347 0.336172963701584 0.765787919679999 + 2.372368622485876 0.344669139219734 0.877475808694303 + 2.402394532412963 0.346236714114806 0.898578702308663 + 2.421632200543405 0.347211723112796 0.912182166100545 + 2.600814823475984 0.356206951763316 1.039020125139189 + 2.499717430182296 0.351010191098421 0.967897548419094 + 2.572211042595633 0.354659119526649 1.018967108776286 + 2.663557373274198 0.359030754462987 1.084127294941044 + 2.624508384540186 0.356972637699486 1.056848324055082 + 2.638578391882532 0.357631581496546 1.066764536958948 + 2.490619544707827 0.350219619250241 0.961836430307891 + 2.351499685312523 0.343126531712676 0.862944429125821 + 2.361744409273265 0.343693557597678 0.870045243822348 + 2.442494968080141 0.347873202461086 0.927160968018594 + 2.745123805313629 0.362770643020118 1.142349343426111 + 2.655499503705102 0.358132929197389 1.079779897215503 + 2.663850696079126 0.358574973979539 1.085379958290025 + 2.642540272757401 0.357462408799286 1.070401889504760 + 2.404037994048185 0.345491588561572 0.900884395443159 + 2.348769349405146 0.342712258600463 0.861219163642359 + 2.151645849089095 0.332135094769575 0.722080451054128 + 2.252343203542463 0.337640454116440 0.793256172150181 + 2.158313350236808 0.332590653949928 0.726803768436609 + 2.177375300770910 0.333675009914873 0.740364253592691 + 2.125333870619463 0.330857624626525 0.703750112206580 + 2.166601866570710 0.333192210611845 0.732859178568121 + 2.108843923653465 0.330052027456209 0.692243810014626 + 2.170141182101418 0.333505871231270 0.735409067431057 + 2.254451075620278 0.338167643418567 0.794516594921980 + 2.446506792318999 0.348291161505242 0.929849297341202 + 2.420231514001146 0.346916032088861 0.911318264635804 + 2.181800682169253 0.334237425269950 0.743319742477540 + 2.099742314313267 0.329709128744430 0.685953130712018 + 2.253483605428042 0.338209143902201 0.794027010792921 + 2.139849820112224 0.332063175615470 0.714018808416182 + 2.250143469020041 0.338136253085361 0.791600043424550 + 2.264735780708348 0.338979274263224 0.801680191863518 + 2.425121660100526 0.347436401511180 0.914625338218002 + 2.206590644219017 0.335830510968584 0.760892479739662 + 2.189826738892797 0.334948331690477 0.749202347672420 + 2.069051029835663 0.328235256714593 0.664845519474291 + 2.391186717627713 0.345755663706005 0.891100361136644 + 2.478723828708481 0.350304667654797 0.952470631759343 + 2.633589418757750 0.357943374909926 1.062259709272963 + 2.501720459872961 0.351218582106388 0.969405568955396 + 2.438825464623843 0.348074452736294 0.924486170126454 + 2.402956953910124 0.346226899680829 0.899047137304136 + 2.524642865536631 0.352419486777799 0.985020882838327 + 2.486592708507011 0.350410839822111 0.958347818799192 + 2.561198294838873 0.354135408220830 1.011115336262727 + 2.320611782924737 0.341730318797737 0.841256200313256 + 2.279686641907904 0.339623952830723 0.812097446193594 + 2.192677970879956 0.334934939278205 0.750983611681066 + 2.034253696137675 0.326074943710870 0.640293522184461 + 2.100411653364924 0.329874859982984 0.687004183670506 + 2.136363142365890 0.331978934678318 0.712025267361496 + 2.145765618417357 0.332571647651874 0.718576738965439 + 2.015355353786295 0.325223748826715 0.627682513187217 + 2.144497911280442 0.332597163880719 0.718235199174144 + 2.184419901142909 0.334907791330299 0.745855884353715 + 2.156941988546521 0.333440304455754 0.726637490761326 + 2.164896092557094 0.333922888423381 0.732317236030551 + 2.142495889557134 0.332723978543999 0.716747302318746 + 1.972335146672318 0.323009944472129 0.598611382636265 + 1.960032978731420 0.322337700909600 0.590822458953444 + 1.892736021185325 0.318399928224863 0.544712037197812 + 1.817727518077365 0.313890597043592 0.493800641801013 + 1.732818354432900 0.308638151751227 0.436587334970866 + 1.709712053275818 0.307294092052731 0.421979569450315 + 1.560777278572816 0.297457158767192 0.322157189475494 + 1.678355925543266 0.305618851041591 0.403484108249424] ; set_dynare_seed('default'); diff --git a/tests/practicing/datasaver.m b/tests/practicing/datasaver.m index 0ac532a4ae..11a7ae861f 100644 --- a/tests/practicing/datasaver.m +++ b/tests/practicing/datasaver.m @@ -9,19 +9,19 @@ function datasaver (s,var_list) % This is part of the examples included in F. Barillas, R. Colacito, % S. Kitao, C. Matthes, T. Sargent and Y. Shin (2007) "Practicing % Dynare". - + % Modified by M. Juillard to make it also compatible with Dynare % version 4 (12/4/07) - + global lgy_ lgx_ y_ endo_nbr M_ oo_ % test and adapt for Dynare version 4 if isempty(lgy_) - lgy_ = M_.endo_names; - lgx_ + M_.exo_names; - y_ = oo_.endo_simul; - endo_nbr = M_.endo_nbr; + lgy_ = M_.endo_names; + lgx_ + M_.exo_names; + y_ = oo_.endo_simul; + endo_nbr = M_.endo_nbr; end sm=[s,'.m']; @@ -29,29 +29,29 @@ fid=fopen(sm,'w') ; n = size(var_list,1); if n == 0 - n = endo_nbr; - ivar = [1:n]'; - var_list = lgy_; + n = endo_nbr; + ivar = [1:n]'; + var_list = lgy_; else - ivar=zeros(n,1); - for i=1:n - i_tmp = strmatch(var_list(i,:),lgy_,'exact'); - if isempty(i_tmp) - error (['One of the specified variables does not exist']) ; - else - ivar(i) = i_tmp; + ivar=zeros(n,1); + for i=1:n + i_tmp = strmatch(var_list(i,:),lgy_,'exact'); + if isempty(i_tmp) + error (['One of the specified variables does not exist']) ; + else + ivar(i) = i_tmp; + end end - end end for i = 1:n - fprintf(fid,[lgy_(ivar(i),:), '=['],'\n') ; - fprintf(fid,'\n') ; - fprintf(fid,'%15.8g\n',y_(ivar(i),:)') ; - fprintf(fid,'\n') ; - fprintf(fid,'];\n') ; - fprintf(fid,'\n') ; + fprintf(fid,[lgy_(ivar(i),:), '=['],'\n') ; + fprintf(fid,'\n') ; + fprintf(fid,'%15.8g\n',y_(ivar(i),:)') ; + fprintf(fid,'\n') ; + fprintf(fid,'];\n') ; + fprintf(fid,'\n') ; end fclose(fid) ; diff --git a/tests/printMakeCheckMatlabErrMsg.m b/tests/printMakeCheckMatlabErrMsg.m index a72b55401b..ef9895d853 100644 --- a/tests/printMakeCheckMatlabErrMsg.m +++ b/tests/printMakeCheckMatlabErrMsg.m @@ -1,9 +1,9 @@ function printMakeCheckMatlabErrMsg(modfilename, exception) - fprintf('\n********************************************\n'); - disp('*** DYNARE-TEST-MATLAB ERROR ENCOUNTERED ***'); - disp('********************************************'); - disp([' WHILE RUNNING MODFILE: ' modfilename]); - fprintf('\n'); - disp(getReport(exception)); - fprintf('*************************************\n\n\n'); +fprintf('\n********************************************\n'); +disp('*** DYNARE-TEST-MATLAB ERROR ENCOUNTERED ***'); +disp('********************************************'); +disp([' WHILE RUNNING MODFILE: ' modfilename]); +fprintf('\n'); +disp(getReport(exception)); +fprintf('*************************************\n\n\n'); end diff --git a/tests/printMakeCheckOctaveErrMsg.m b/tests/printMakeCheckOctaveErrMsg.m index 84e19d00ed..b64bb4bb0e 100644 --- a/tests/printMakeCheckOctaveErrMsg.m +++ b/tests/printMakeCheckOctaveErrMsg.m @@ -1,14 +1,14 @@ function printMakeCheckOctaveErrMsg(modfilename, err) - printf("\n"); - printf("********************************************\n"); - printf("*** DYNARE-TEST-OCTAVE ERROR ENCOUNTERED ***\n"); - printf("********************************************\n"); - printf(" WHILE RUNNING MODFILE: %s\n", modfilename); - printf(" MSG: %s\n", err.message); - if (isfield(err, 'stack')) - printf(" IN FILE: %s\n", err.stack(1).file); - printf(" IN FUNCTION: %s\n", err.stack(1).name); - printf(" ON LINE and COLUMN: %d and %d\n",err.stack(1).line,err.stack(1).column); - end - printf("*************************************\n\n\n"); +printf("\n"); +printf("********************************************\n"); +printf("*** DYNARE-TEST-OCTAVE ERROR ENCOUNTERED ***\n"); +printf("********************************************\n"); +printf(" WHILE RUNNING MODFILE: %s\n", modfilename); +printf(" MSG: %s\n", err.message); +if (isfield(err, 'stack')) + printf(" IN FILE: %s\n", err.stack(1).file); + printf(" IN FUNCTION: %s\n", err.stack(1).name); + printf(" ON LINE and COLUMN: %d and %d\n",err.stack(1).line,err.stack(1).column); +end +printf("*************************************\n\n\n"); end diff --git a/tests/recursive/data_ca1.m b/tests/recursive/data_ca1.m index c28fae1a28..ca003056bd 100644 --- a/tests/recursive/data_ca1.m +++ b/tests/recursive/data_ca1.m @@ -1,98 +1,98 @@ data = [0.928467646476 11.8716889412 20 0.418037507392 0.227382377518 ... --0.705994063083 11.7522582094 21.25 1.09254424511 -1.29488274994 ... --0.511895351926 9.68144025625 17.25 -1.66150408407 0.331508393098 ... --0.990955971267 10.0890781236 17 1.43016275252 -2.43589670141 ... --0.981233061806 12.1094840679 18.25 2.91293288733 -0.790246576864 ... --0.882182844512 8.54559460406 15 0.419579139481 0.358729719566 ... --0.930893002836 6.19238374422 12.5 -1.48847457959 0.739779938797 ... -1.53158206947 2.76544271886 11.5 -0.336216769682 0.455559918769 ... -2.2659052834 5.47418162513 11 0.306436789767 -0.0707985731221 ... -1.05419803797 6.35698426189 11 0.140700250477 0.620401487202 ... -1.20161076793 3.4253301593 11 0.461296492351 0.14354323987 ... -1.73934077971 4.70926070322 11.5 1.35798282982 0.38564694435 ... -1.71735262584 3.54232079749 12.5 2.9097529155 -0.804308583301 ... -0.426343657844 3.32719108897 13 1.64214862652 -1.18214664701 ... -1.67751812324 2.93444727338 11.25 0.344434910651 -1.6529373719 ... -1.37013301099 4.72303361923 11.75 2.61511526582 0.327684243041 ... -0.281231073781 4.4893853071 10.5 1.17043449257 1.12855106649 ... -1.53638992834 3.7325309699 10.25 -0.683947046728 0.11943538737 ... -1.68081431462 3.34729969129 10 1.41159342106 -1.59065680853 ... --0.343321601133 5.05563513564 12 1.75117366498 -2.40127764642 ... -0.873415608666 3.2779996255 10.25 -1.39895866711 0.0971444398216 ... -0.26399696544 4.78229419828 9.75 0.0914692438124 0.299310457612 ... --0.562233624818 3.88598638237 9.75 -0.0505384765105 0.332826708151 ... -2.15161914936 3.84859710132 8.75 -3.44811080489 0.789138678784 ... -1.2345093726 5.62225030942 9.5 -0.366945407434 2.32974981198 ... -1.62554967459 4.24667132831 10 -0.800958371402 0.0293183770935 ... -1.33035402527 2.75248979249 9.75 -0.855723113225 0.852493939813 ... -1.52078814077 3.53415985826 9.75 -3.37963469203 -1.05133958119 ... -1.16704983697 4.92754079464 10.75 -3.0142303324 0.459907431978 ... -0.277213572101 4.55532133037 11.75 -0.851995599415 2.03242034852 ... -0.842215068977 3.11164509647 12.25 -1.08290421696 0.014323281961 ... -1.05325028606 4.92882647578 13.5 -1.1953883867 0.706764750654 ... -0.453051253568 6.82998950103 13.5 0.111803656462 0.088462593153 ... -0.199885995525 5.82643354662 13.5 -0.920501518421 -0.26504958666 ... -0.137907999624 2.66076369132 13.5 -1.17122929812 -0.995642430514 ... -0.721949686709 5.70497876823 14.25 1.19378169018 -1.10644839651 ... --0.418465249225 3.75861110232 14.75 -1.03131674824 0.188507675831 ... --0.644028342116 4.15104788154 13.75 -1.48911756546 0.204560913792 ... --0.848213852668 5.65580324027 12.75 0.677011703877 -0.849628054542 ... --1.51954076928 11.4866911266 11.25 -0.446024680774 -0.456342350765 ... -0.265275055215 2.85472749592 9.75 -0.598778202436 -0.907311640831 ... -0.356162529063 2.29614015658 9.5 -0.46820788432 -1.22130883441 ... -0.368308864363 -0.539083504685 8 -0.781333991956 0.374007246518 ... --0.145751412732 1.61507621789 8.25 3.68291932628 1.32438399845 ... -0.285457283664 2.14334055993 7 1.42819405379 -0.00818660844123 ... -0.372390129412 1.60000213334 6.25 0.626106424052 -0.10136772765 ... -0.382720203063 1.72614243263 7.25 4.89631941021 -1.10060711916 ... -0.737957515573 2.90430582851 6 -0.0422721010314 0.4178952497 ... -0.649532581668 0.657135682543 6 0.692066153971 0.422299120276 ... -0.627159201987 1.70352689913 5.75 2.62066711305 -1.29237304034 ... -0.905441299817 1.95663197267 5.5 1.5949697565 -0.27115830703 ... -1.49322577898 -2.08741765309 6.25 1.23027694802 0.418336889527 ... -1.48750731567 -1.57274121871 8 3.01660550994 -0.893958254365 ... -1.39783858087 2.22623066426 7 -0.80842319214 1.47625453886 ... -0.89274836317 1.30378081742 8 -0.249485058661 0.159871204185 ... -0.920652246088 4.1437741965 9.75 2.8204453623 0.178149239655 ... --0.00264276644799 3.07989972052 8.75 -2.56342461535 2.105998353 ... -0.0198190461681 0.766283759256 8 -1.15838865989 1.56888883418 ... -0.440050515311 0.127570085801 7.5 0.0400753569995 0.028914333532 ... -0.129536637901 1.78174141526 6.75 0.959943962785 0.307781224401 ... -0.398549827172 3.03606770667 6.5 -0.340209794742 0.100979469478 ... -1.17174775425 0.629625188037 5.75 0.403003686814 0.902394579377 ... -0.991163981251 2.50862910684 4.75 -1.44963996982 1.16150986945 ... -0.967603566096 2.12003739013 4.75 0.610846030775 -0.889994896068 ... -1.14689383604 1.24185011459 4.75 2.01098091308 -1.73846431001 ... -1.32593824054 0.990713820685 4.75 -0.0955142989332 -0.0369257308362 ... -0.861135002644 -0.24744943605 6 1.72793107135 -0.691506789639 ... -1.26870850151 2.09844764887 6.5 1.50720217572 -1.31399187077 ... -0.260364987715 1.10650139716 6.5 1.13659047496 0.0720441664643 ... -1.09731242214 0.490796381346 7.25 4.59123894147 -2.14073070763 ... -1.63792841781 0.612652594286 6.75 1.79604605035 -0.644363995357 ... -1.48465576034 0.978295808687 6.75 -2.00753620902 1.39437534964 ... -1.0987608663 4.25212569087 6.25 -2.58901196498 2.56054320803 ... -1.42592178132 2.76984518311 6.25 0.888195752358 1.03114549274 ... -1.52958239462 1.31795955491 6.5 -0.902907564082 -0.0952198893776 ... -1.0170168994 2.14733589918 7 -1.3054866978 2.68803738466 ... -0.723253652257 3.43552889347 7.5 1.8213700853 0.592593586195 ... -1.24720806008 3.87383806577 7.5 0.0522300654168 0.988871238698 ... -0.482531471239 2.67793287032 7.5 2.9693944293 -0.108591166081 ... -0.154056100439 0.927269031704 6.75 0.119222057561 3.30489209451 ... -0.0694865769274 6.65916526788 6.25 0.889014476084 -2.83976849035 ... --0.121267434867 0.341442615696 5.25 0.323053239216 -3.49289229012 ... -0.726473690375 -3.5423730964 4 2.19149290449 -3.20855054004 ... -1.39271709108 2.63121085718 3.75 0.88406577736 0.75622580197 ... -1.07502077727 5.88578836799 4.25 -2.55088273352 2.89018116374 ... -0.759049251607 4.24703604223 4.5 0.575687665685 -0.388292506167 ... -]; - + -0.705994063083 11.7522582094 21.25 1.09254424511 -1.29488274994 ... + -0.511895351926 9.68144025625 17.25 -1.66150408407 0.331508393098 ... + -0.990955971267 10.0890781236 17 1.43016275252 -2.43589670141 ... + -0.981233061806 12.1094840679 18.25 2.91293288733 -0.790246576864 ... + -0.882182844512 8.54559460406 15 0.419579139481 0.358729719566 ... + -0.930893002836 6.19238374422 12.5 -1.48847457959 0.739779938797 ... + 1.53158206947 2.76544271886 11.5 -0.336216769682 0.455559918769 ... + 2.2659052834 5.47418162513 11 0.306436789767 -0.0707985731221 ... + 1.05419803797 6.35698426189 11 0.140700250477 0.620401487202 ... + 1.20161076793 3.4253301593 11 0.461296492351 0.14354323987 ... + 1.73934077971 4.70926070322 11.5 1.35798282982 0.38564694435 ... + 1.71735262584 3.54232079749 12.5 2.9097529155 -0.804308583301 ... + 0.426343657844 3.32719108897 13 1.64214862652 -1.18214664701 ... + 1.67751812324 2.93444727338 11.25 0.344434910651 -1.6529373719 ... + 1.37013301099 4.72303361923 11.75 2.61511526582 0.327684243041 ... + 0.281231073781 4.4893853071 10.5 1.17043449257 1.12855106649 ... + 1.53638992834 3.7325309699 10.25 -0.683947046728 0.11943538737 ... + 1.68081431462 3.34729969129 10 1.41159342106 -1.59065680853 ... + -0.343321601133 5.05563513564 12 1.75117366498 -2.40127764642 ... + 0.873415608666 3.2779996255 10.25 -1.39895866711 0.0971444398216 ... + 0.26399696544 4.78229419828 9.75 0.0914692438124 0.299310457612 ... + -0.562233624818 3.88598638237 9.75 -0.0505384765105 0.332826708151 ... + 2.15161914936 3.84859710132 8.75 -3.44811080489 0.789138678784 ... + 1.2345093726 5.62225030942 9.5 -0.366945407434 2.32974981198 ... + 1.62554967459 4.24667132831 10 -0.800958371402 0.0293183770935 ... + 1.33035402527 2.75248979249 9.75 -0.855723113225 0.852493939813 ... + 1.52078814077 3.53415985826 9.75 -3.37963469203 -1.05133958119 ... + 1.16704983697 4.92754079464 10.75 -3.0142303324 0.459907431978 ... + 0.277213572101 4.55532133037 11.75 -0.851995599415 2.03242034852 ... + 0.842215068977 3.11164509647 12.25 -1.08290421696 0.014323281961 ... + 1.05325028606 4.92882647578 13.5 -1.1953883867 0.706764750654 ... + 0.453051253568 6.82998950103 13.5 0.111803656462 0.088462593153 ... + 0.199885995525 5.82643354662 13.5 -0.920501518421 -0.26504958666 ... + 0.137907999624 2.66076369132 13.5 -1.17122929812 -0.995642430514 ... + 0.721949686709 5.70497876823 14.25 1.19378169018 -1.10644839651 ... + -0.418465249225 3.75861110232 14.75 -1.03131674824 0.188507675831 ... + -0.644028342116 4.15104788154 13.75 -1.48911756546 0.204560913792 ... + -0.848213852668 5.65580324027 12.75 0.677011703877 -0.849628054542 ... + -1.51954076928 11.4866911266 11.25 -0.446024680774 -0.456342350765 ... + 0.265275055215 2.85472749592 9.75 -0.598778202436 -0.907311640831 ... + 0.356162529063 2.29614015658 9.5 -0.46820788432 -1.22130883441 ... + 0.368308864363 -0.539083504685 8 -0.781333991956 0.374007246518 ... + -0.145751412732 1.61507621789 8.25 3.68291932628 1.32438399845 ... + 0.285457283664 2.14334055993 7 1.42819405379 -0.00818660844123 ... + 0.372390129412 1.60000213334 6.25 0.626106424052 -0.10136772765 ... + 0.382720203063 1.72614243263 7.25 4.89631941021 -1.10060711916 ... + 0.737957515573 2.90430582851 6 -0.0422721010314 0.4178952497 ... + 0.649532581668 0.657135682543 6 0.692066153971 0.422299120276 ... + 0.627159201987 1.70352689913 5.75 2.62066711305 -1.29237304034 ... + 0.905441299817 1.95663197267 5.5 1.5949697565 -0.27115830703 ... + 1.49322577898 -2.08741765309 6.25 1.23027694802 0.418336889527 ... + 1.48750731567 -1.57274121871 8 3.01660550994 -0.893958254365 ... + 1.39783858087 2.22623066426 7 -0.80842319214 1.47625453886 ... + 0.89274836317 1.30378081742 8 -0.249485058661 0.159871204185 ... + 0.920652246088 4.1437741965 9.75 2.8204453623 0.178149239655 ... + -0.00264276644799 3.07989972052 8.75 -2.56342461535 2.105998353 ... + 0.0198190461681 0.766283759256 8 -1.15838865989 1.56888883418 ... + 0.440050515311 0.127570085801 7.5 0.0400753569995 0.028914333532 ... + 0.129536637901 1.78174141526 6.75 0.959943962785 0.307781224401 ... + 0.398549827172 3.03606770667 6.5 -0.340209794742 0.100979469478 ... + 1.17174775425 0.629625188037 5.75 0.403003686814 0.902394579377 ... + 0.991163981251 2.50862910684 4.75 -1.44963996982 1.16150986945 ... + 0.967603566096 2.12003739013 4.75 0.610846030775 -0.889994896068 ... + 1.14689383604 1.24185011459 4.75 2.01098091308 -1.73846431001 ... + 1.32593824054 0.990713820685 4.75 -0.0955142989332 -0.0369257308362 ... + 0.861135002644 -0.24744943605 6 1.72793107135 -0.691506789639 ... + 1.26870850151 2.09844764887 6.5 1.50720217572 -1.31399187077 ... + 0.260364987715 1.10650139716 6.5 1.13659047496 0.0720441664643 ... + 1.09731242214 0.490796381346 7.25 4.59123894147 -2.14073070763 ... + 1.63792841781 0.612652594286 6.75 1.79604605035 -0.644363995357 ... + 1.48465576034 0.978295808687 6.75 -2.00753620902 1.39437534964 ... + 1.0987608663 4.25212569087 6.25 -2.58901196498 2.56054320803 ... + 1.42592178132 2.76984518311 6.25 0.888195752358 1.03114549274 ... + 1.52958239462 1.31795955491 6.5 -0.902907564082 -0.0952198893776 ... + 1.0170168994 2.14733589918 7 -1.3054866978 2.68803738466 ... + 0.723253652257 3.43552889347 7.5 1.8213700853 0.592593586195 ... + 1.24720806008 3.87383806577 7.5 0.0522300654168 0.988871238698 ... + 0.482531471239 2.67793287032 7.5 2.9693944293 -0.108591166081 ... + 0.154056100439 0.927269031704 6.75 0.119222057561 3.30489209451 ... + 0.0694865769274 6.65916526788 6.25 0.889014476084 -2.83976849035 ... + -0.121267434867 0.341442615696 5.25 0.323053239216 -3.49289229012 ... + 0.726473690375 -3.5423730964 4 2.19149290449 -3.20855054004 ... + 1.39271709108 2.63121085718 3.75 0.88406577736 0.75622580197 ... + 1.07502077727 5.88578836799 4.25 -2.55088273352 2.89018116374 ... + 0.759049251607 4.24703604223 4.5 0.575687665685 -0.388292506167 ... + ]; + data = reshape(data,5,86)'; y_obs = data(:,1); pie_obs = data(:,2); R_obs = data(:,3); de = data(:,4); dq = data(:,5); - + %Country: Canada %Sample Range: 1981:2 to 2002:3 %Observations: 86 diff --git a/tests/reporting/ResidTablePage.m b/tests/reporting/ResidTablePage.m index c283429a0d..c4e25e3051 100644 --- a/tests/reporting/ResidTablePage.m +++ b/tests/reporting/ResidTablePage.m @@ -50,7 +50,7 @@ rep = rep.addTable('title', countryName, ... for i=1:length(seriesNames) if (any(strcmp(countryAbbr, otherThree)) && ... - any(strcmp(seriesNames{i}{1}, notForOtherThree))) || ... + any(strcmp(seriesNames{i}{1}, notForOtherThree))) || ... (any(strcmp(countryAbbr, 'US')) && any(strcmp(seriesNames{i}{1}, notForUS))) || ... (any(strcmp(countryAbbr, firstThree)) && any(strcmp(seriesNames{i}{1}, notForFirstThree))) continue diff --git a/tests/reporting/runDynareReport.m b/tests/reporting/runDynareReport.m index eab6eb234d..ba67cec76f 100644 --- a/tests/reporting/runDynareReport.m +++ b/tests/reporting/runDynareReport.m @@ -202,13 +202,13 @@ rep = rep.addPage('title', {'Jan1 vs Jan2', 'World Oil and Food Prices'}, ... 'titleFormat', {'\large\bfseries', '\large'}); rep = rep.addSection('cols', 1); rep = rep.addParagraph('text', 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.', ... - 'cols', 2, ... - 'heading', '\textbf{My First Paragraph Has Two Columns}'); + 'cols', 2, ... + 'heading', '\textbf{My First Paragraph Has Two Columns}'); rep = rep.addSection('cols', 1); rep = rep.addParagraph('text', 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.\newline', ... - 'heading', '\textbf{My Next Paragraphs Only Have One}', ... - 'indent', false); + 'heading', '\textbf{My Next Paragraphs Only Have One}', ... + 'indent', false); rep = rep.addParagraph('text', 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.\newline'); rep = rep.addSection('cols', 2); diff --git a/tests/run_all_unitary_tests.m b/tests/run_all_unitary_tests.m index b31f9d8ada..7200f40b36 100644 --- a/tests/run_all_unitary_tests.m +++ b/tests/run_all_unitary_tests.m @@ -73,14 +73,14 @@ else fid = fopen('run_all_unitary_tests.m.trs', 'w+'); end if length(failedtests) > 0 - fprintf(fid,':test-result: FAIL\n'); - fprintf(fid,':number-tests: %d\n', counter); - fprintf(fid,':number-failed-tests: %d\n', length(failedtests)); - fprintf(fid,':list-of-failed-tests: %s\n', failedtests{:}); + fprintf(fid,':test-result: FAIL\n'); + fprintf(fid,':number-tests: %d\n', counter); + fprintf(fid,':number-failed-tests: %d\n', length(failedtests)); + fprintf(fid,':list-of-failed-tests: %s\n', failedtests{:}); else - fprintf(fid,':test-result: PASS\n'); - fprintf(fid,':number-tests: %d\n', counter); - fprintf(fid,':number-failed-tests: 0\n'); + fprintf(fid,':test-result: PASS\n'); + fprintf(fid,':number-tests: %d\n', counter); + fprintf(fid,':number-failed-tests: 0\n'); end fprintf(fid,':elapsed-time: %f\n',0.0); fclose(fid); diff --git a/tests/run_block_byte_tests_matlab.m b/tests/run_block_byte_tests_matlab.m index 846beadecf..3675c0da7e 100644 --- a/tests/run_block_byte_tests_matlab.m +++ b/tests/run_block_byte_tests_matlab.m @@ -29,7 +29,7 @@ addpath([top_test_dir filesep '..' filesep 'matlab']); % Test Dynare Version if ~strcmp(dynare_version(), getenv('DYNARE_VERSION')) - error('Incorrect version of Dynare is being tested') + error('Incorrect version of Dynare is being tested') end % Test block_bytecode/ls2003.mod with various combinations of @@ -134,14 +134,14 @@ delete('wsMat.mat') cd(getenv('TOP_TEST_DIR')); fid = fopen('run_block_byte_tests_matlab.m.trs', 'w+'); if size(failedBlock,2) > 0 - fprintf(fid,':test-result: FAIL\n'); - fprintf(fid,':number-tests: %d\n', num_block_tests); - fprintf(fid,':number-failed-tests: %d\n', size(failedBlock,2)); - fprintf(fid,':list-of-failed-tests: %s\n', failedBlock{:}); + fprintf(fid,':test-result: FAIL\n'); + fprintf(fid,':number-tests: %d\n', num_block_tests); + fprintf(fid,':number-failed-tests: %d\n', size(failedBlock,2)); + fprintf(fid,':list-of-failed-tests: %s\n', failedBlock{:}); else - fprintf(fid,':test-result: PASS\n'); - fprintf(fid,':number-tests: %d\n', num_block_tests); - fprintf(fid,':number-failed-tests: 0\n'); + fprintf(fid,':test-result: PASS\n'); + fprintf(fid,':number-tests: %d\n', num_block_tests); + fprintf(fid,':number-failed-tests: 0\n'); end fprintf(fid,':elapsed-time: %f\n', ecput); fclose(fid); diff --git a/tests/run_block_byte_tests_octave.m b/tests/run_block_byte_tests_octave.m index 288a17e942..d930e8028d 100644 --- a/tests/run_block_byte_tests_octave.m +++ b/tests/run_block_byte_tests_octave.m @@ -11,142 +11,142 @@ ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with Dynare. If not, see <http://www.gnu.org/licenses/>. + ## + ## You should have received a copy of the GNU General Public License + ## along with Dynare. If not, see <http://www.gnu.org/licenses/>. -## Implementation notes: -## -## Before every call to Dynare, the contents of the workspace is saved in -## 'wsOct', and reloaded after Dynare has finished (this is necessary since -## Dynare does a 'clear -all'). + ## Implementation notes: + ## + ## Before every call to Dynare, the contents of the workspace is saved in + ## 'wsOct', and reloaded after Dynare has finished (this is necessary since + ## Dynare does a 'clear -all'). -top_test_dir = getenv('TOP_TEST_DIR'); -addpath(top_test_dir); -addpath([top_test_dir filesep '..' filesep 'matlab']); + top_test_dir = getenv('TOP_TEST_DIR'); + addpath(top_test_dir); + addpath([top_test_dir filesep '..' filesep 'matlab']); -## Test Dynare Version -if !strcmp(dynare_version(), getenv("DYNARE_VERSION")) - error("Incorrect version of Dynare is being tested") -endif + ## Test Dynare Version + if !strcmp(dynare_version(), getenv("DYNARE_VERSION")) + error("Incorrect version of Dynare is being tested") + endif -## Ask gnuplot to create graphics in text mode -## Note that setenv() was introduced in Octave 3.0.2, for compatibility -## with MATLAB -putenv("GNUTERM", "dumb") + ## Ask gnuplot to create graphics in text mode + ## Note that setenv() was introduced in Octave 3.0.2, for compatibility + ## with MATLAB + putenv("GNUTERM", "dumb") -## Test block_bytecode/ls2003.mod with various combinations of -## block/bytecode/solve_algo/stack_solve_algo -failedBlock = {}; -num_block_tests = 0; -cd([top_test_dir filesep 'block_bytecode']); -tic; -for blockFlag = 0:1 - for bytecodeFlag = 0:1 - ## Recall that solve_algo=7 and stack_solve_algo=2 are not supported - ## under Octave - default_solve_algo = 2; - default_stack_solve_algo = 0; - if !blockFlag && !bytecodeFlag - solve_algos = 0:4; - stack_solve_algos = [0 6]; - elseif blockFlag && !bytecodeFlag - solve_algos = [0:4 6 8]; - stack_solve_algos = [0 1 3 4]; - else - solve_algos = [0:6 8]; - stack_solve_algos = [0 1 3:5]; - endif + ## Test block_bytecode/ls2003.mod with various combinations of + ## block/bytecode/solve_algo/stack_solve_algo + failedBlock = {}; + num_block_tests = 0; + cd([top_test_dir filesep 'block_bytecode']); + tic; + for blockFlag = 0:1 + for bytecodeFlag = 0:1 + ## Recall that solve_algo=7 and stack_solve_algo=2 are not supported + ## under Octave + default_solve_algo = 2; + default_stack_solve_algo = 0; + if !blockFlag && !bytecodeFlag + solve_algos = 0:4; + stack_solve_algos = [0 6]; + elseif blockFlag && !bytecodeFlag + solve_algos = [0:4 6 8]; + stack_solve_algos = [0 1 3 4]; + else + solve_algos = [0:6 8]; + stack_solve_algos = [0 1 3:5]; + endif - sleep(1) # Workaround for strange race condition related to the _static.m file + sleep(1) # Workaround for strange race condition related to the _static.m file - for i = 1:length(solve_algos) - num_block_tests = num_block_tests + 1; - if !blockFlag && !bytecodeFlag && (i == 1) - ## This is the reference simulation path against which all - ## other simulations will be tested - try - old_path = path; - save wsOct - run_ls2003(blockFlag, bytecodeFlag, solve_algos(i), default_stack_solve_algo) - load wsOct - path(old_path); - y_ref = oo_.endo_simul; - save('test.mat','y_ref'); - catch - load wsOct - path(old_path); - failedBlock{size(failedBlock,2)+1} = ['block_bytecode' filesep 'run_ls2003.m(' num2str(blockFlag) ',' num2str(bytecodeFlag) ',' num2str(solve_algos(i)) ',' num2str(default_stack_solve_algo) ')']; - printMakeCheckOctaveErrMsg(['block_bytecode' filesep 'run_ls2003.m(' num2str(blockFlag) ',' num2str(bytecodeFlag) ',' num2str(solve_algos(i)) ',' num2str(default_stack_solve_algo) ')'], lasterror); - end_try_catch - else - try - old_path = path; - save wsOct - run_ls2003(blockFlag, bytecodeFlag, solve_algos(i), default_stack_solve_algo) - load wsOct - path(old_path); - ## Test against the reference simulation path - load('test.mat','y_ref'); - diff = oo_.endo_simul - y_ref; - if(abs(diff) > options_.dynatol.x) - failedBlock{size(failedBlock,2)+1} = ['block_bytecode' filesep 'run_ls2003.m(' num2str(blockFlag) ',' num2str(bytecodeFlag) ',' num2str(solve_algos(i)) ',' num2str(default_stack_solve_algo) ')']; - differr.message = ["ERROR: simulation path differs from the reference path" ]; - printMakeCheckOctaveErrMsg(['block_bytecode' filesep 'run_ls2003.m(' num2str(blockFlag) ',' num2str(bytecodeFlag) ',' num2str(solve_algos(i)) ',' num2str(default_stack_solve_algo) ')'], differr); - endif - catch - load wsOct - e = lasterror(); # The path() command alters the lasterror, because of io package - path(old_path); - lasterror(e); - failedBlock{size(failedBlock,2)+1} = ['block_bytecode' filesep 'run_ls2003.m(' num2str(blockFlag) ',' num2str(bytecodeFlag) ',' num2str(solve_algos(i)) ',' num2str(default_stack_solve_algo) ')']; - printMakeCheckOctaveErrMsg(['block_bytecode' filesep 'run_ls2003.m(' num2str(blockFlag) ',' num2str(bytecodeFlag) ',' num2str(solve_algos(i)) ',' num2str(default_stack_solve_algo) ')'], lasterror); - end_try_catch - endif - endfor - for i = 1:length(stack_solve_algos) - num_block_tests = num_block_tests + 1; - try - old_path = path; - save wsOct - run_ls2003(blockFlag, bytecodeFlag, default_solve_algo, stack_solve_algos(i)) - load wsOct - path(old_path); - ## Test against the reference simulation path - load('test.mat','y_ref'); - diff = oo_.endo_simul - y_ref; - if(abs(diff) > options_.dynatol.x) - failedBlock{size(failedBlock,2)+1} = ['block_bytecode' filesep 'run_ls2003.m(' num2str(blockFlag) ',' num2str(bytecodeFlag) ',' num2str(default_solve_algo) ',' num2str(stack_solve_algos(i)) ')']; - differr.message = ["ERROR: simulation path differs from the reference path" ]; - printMakeCheckOctaveErrMsg(['block_bytecode' filesep 'run_ls2003.m(' num2str(blockFlag) ',' num2str(bytecodeFlag) ',' num2str(default_solve_algo) ',' num2str(stack_solve_algos(i)) ')'], differr); - endif - catch - load wsOct - e = lasterror(); # The path() command alters the lasterror, because of io package - path(old_path); - lasterror(e); - failedBlock{size(failedBlock,2)+1} = ['block_bytecode' filesep 'run_ls2003.m(' num2str(blockFlag) ',' num2str(bytecodeFlag) ',' num2str(default_solve_algo) ',' num2str(stack_solve_algos(i)) ')']; - printMakeCheckOctaveErrMsg(['block_bytecode' filesep 'run_ls2003.m(' num2str(blockFlag) ',' num2str(bytecodeFlag) ',' num2str(default_solve_algo) ',' num2str(stack_solve_algos(i)) ')'], lasterror); - end_try_catch - endfor - endfor -endfor -ecput = toc; -delete('wsOct'); -cd(getenv('TOP_TEST_DIR')); -fid = fopen('run_block_byte_tests_octave.o.trs', 'w+'); -if size(failedBlock,2) > 0 - fprintf(fid,':test-result: FAIL\n'); - fprintf(fid,':number-tests: %d\n', num_block_tests); - fprintf(fid,':number-failed-tests: %d\n', size(failedBlock,2)); - fprintf(fid,':list-of-failed-tests: %s\n', failedBlock{:}); -else - fprintf(fid,':test-result: PASS\n'); - fprintf(fid,':number-tests: %d\n', num_block_tests); - fprintf(fid,':number-failed-tests: 0\n'); -end -fprintf(fid,':elapsed-time: %f\n', ecput); -fclose(fid); -## Local variables: -## mode: Octave -## End: + for i = 1:length(solve_algos) + num_block_tests = num_block_tests + 1; + if !blockFlag && !bytecodeFlag && (i == 1) + ## This is the reference simulation path against which all + ## other simulations will be tested + try + old_path = path; + save wsOct + run_ls2003(blockFlag, bytecodeFlag, solve_algos(i), default_stack_solve_algo) + load wsOct + path(old_path); + y_ref = oo_.endo_simul; + save('test.mat','y_ref'); + catch + load wsOct + path(old_path); + failedBlock{size(failedBlock,2)+1} = ['block_bytecode' filesep 'run_ls2003.m(' num2str(blockFlag) ',' num2str(bytecodeFlag) ',' num2str(solve_algos(i)) ',' num2str(default_stack_solve_algo) ')']; + printMakeCheckOctaveErrMsg(['block_bytecode' filesep 'run_ls2003.m(' num2str(blockFlag) ',' num2str(bytecodeFlag) ',' num2str(solve_algos(i)) ',' num2str(default_stack_solve_algo) ')'], lasterror); + end_try_catch + else + try + old_path = path; + save wsOct + run_ls2003(blockFlag, bytecodeFlag, solve_algos(i), default_stack_solve_algo) + load wsOct + path(old_path); + ## Test against the reference simulation path + load('test.mat','y_ref'); + diff = oo_.endo_simul - y_ref; + if(abs(diff) > options_.dynatol.x) + failedBlock{size(failedBlock,2)+1} = ['block_bytecode' filesep 'run_ls2003.m(' num2str(blockFlag) ',' num2str(bytecodeFlag) ',' num2str(solve_algos(i)) ',' num2str(default_stack_solve_algo) ')']; + differr.message = ["ERROR: simulation path differs from the reference path" ]; + printMakeCheckOctaveErrMsg(['block_bytecode' filesep 'run_ls2003.m(' num2str(blockFlag) ',' num2str(bytecodeFlag) ',' num2str(solve_algos(i)) ',' num2str(default_stack_solve_algo) ')'], differr); + endif + catch + load wsOct + e = lasterror(); # The path() command alters the lasterror, because of io package + path(old_path); + lasterror(e); + failedBlock{size(failedBlock,2)+1} = ['block_bytecode' filesep 'run_ls2003.m(' num2str(blockFlag) ',' num2str(bytecodeFlag) ',' num2str(solve_algos(i)) ',' num2str(default_stack_solve_algo) ')']; + printMakeCheckOctaveErrMsg(['block_bytecode' filesep 'run_ls2003.m(' num2str(blockFlag) ',' num2str(bytecodeFlag) ',' num2str(solve_algos(i)) ',' num2str(default_stack_solve_algo) ')'], lasterror); + end_try_catch + endif + endfor + for i = 1:length(stack_solve_algos) + num_block_tests = num_block_tests + 1; + try + old_path = path; + save wsOct + run_ls2003(blockFlag, bytecodeFlag, default_solve_algo, stack_solve_algos(i)) + load wsOct + path(old_path); + ## Test against the reference simulation path + load('test.mat','y_ref'); + diff = oo_.endo_simul - y_ref; + if(abs(diff) > options_.dynatol.x) + failedBlock{size(failedBlock,2)+1} = ['block_bytecode' filesep 'run_ls2003.m(' num2str(blockFlag) ',' num2str(bytecodeFlag) ',' num2str(default_solve_algo) ',' num2str(stack_solve_algos(i)) ')']; + differr.message = ["ERROR: simulation path differs from the reference path" ]; + printMakeCheckOctaveErrMsg(['block_bytecode' filesep 'run_ls2003.m(' num2str(blockFlag) ',' num2str(bytecodeFlag) ',' num2str(default_solve_algo) ',' num2str(stack_solve_algos(i)) ')'], differr); + endif + catch + load wsOct + e = lasterror(); # The path() command alters the lasterror, because of io package + path(old_path); + lasterror(e); + failedBlock{size(failedBlock,2)+1} = ['block_bytecode' filesep 'run_ls2003.m(' num2str(blockFlag) ',' num2str(bytecodeFlag) ',' num2str(default_solve_algo) ',' num2str(stack_solve_algos(i)) ')']; + printMakeCheckOctaveErrMsg(['block_bytecode' filesep 'run_ls2003.m(' num2str(blockFlag) ',' num2str(bytecodeFlag) ',' num2str(default_solve_algo) ',' num2str(stack_solve_algos(i)) ')'], lasterror); + end_try_catch + endfor + endfor + endfor + ecput = toc; + delete('wsOct'); + cd(getenv('TOP_TEST_DIR')); + fid = fopen('run_block_byte_tests_octave.o.trs', 'w+'); + if size(failedBlock,2) > 0 + fprintf(fid,':test-result: FAIL\n'); + fprintf(fid,':number-tests: %d\n', num_block_tests); + fprintf(fid,':number-failed-tests: %d\n', size(failedBlock,2)); + fprintf(fid,':list-of-failed-tests: %s\n', failedBlock{:}); + else + fprintf(fid,':test-result: PASS\n'); + fprintf(fid,':number-tests: %d\n', num_block_tests); + fprintf(fid,':number-failed-tests: 0\n'); + end + fprintf(fid,':elapsed-time: %f\n', ecput); + fclose(fid); + ## Local variables: + ## mode: Octave + ## End: diff --git a/tests/run_m_script.m b/tests/run_m_script.m index f40fc242c0..09840efcad 100644 --- a/tests/run_m_script.m +++ b/tests/run_m_script.m @@ -22,31 +22,31 @@ top_test_dir = getenv('TOP_TEST_DIR'); cd(directory); try - mscript; - testFailed = false; + mscript; + testFailed = false; catch exception - printMakeCheckMatlabErrMsg(strtok(getenv('FILESTEM')), exception); - testFailed = true; + printMakeCheckMatlabErrMsg(strtok(getenv('FILESTEM')), exception); + testFailed = true; end cd(top_test_dir); name = strtok(getenv('FILESTEM')); fid = fopen([name '.m.tls'], 'w'); if fid < 0 - wd = pwd - filestep = getenv('FILESTEM') - error(['ERROR: problem opening file ' name '.m.tls for writing....']); + wd = pwd + filestep = getenv('FILESTEM') + error(['ERROR: problem opening file ' name '.m.tls for writing....']); end if testFailed - fprintf(fid,':test-result: FAIL\n'); - fprintf(fid,':number-tests: 1\n'); - fprintf(fid,':number-failed-tests: 1\n'); - fprintf(fid,':list-of-failed-tests: %s\n', [name '.m']); + fprintf(fid,':test-result: FAIL\n'); + fprintf(fid,':number-tests: 1\n'); + fprintf(fid,':number-failed-tests: 1\n'); + fprintf(fid,':list-of-failed-tests: %s\n', [name '.m']); else - fprintf(fid,':test-result: PASS\n'); - fprintf(fid,':number-tests: 1\n'); - fprintf(fid,':number-failed-tests: 0\n'); - fprintf(fid,':list-of-passed-tests: %s\n', [name '.m']); + fprintf(fid,':test-result: PASS\n'); + fprintf(fid,':number-tests: 1\n'); + fprintf(fid,':number-failed-tests: 0\n'); + fprintf(fid,':list-of-passed-tests: %s\n', [name '.m']); end fclose(fid); exit; \ No newline at end of file diff --git a/tests/run_o_script.m b/tests/run_o_script.m index 3edba05829..723df2e1b1 100644 --- a/tests/run_o_script.m +++ b/tests/run_o_script.m @@ -11,42 +11,42 @@ ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with Dynare. If not, see <http://www.gnu.org/licenses/>. + ## + ## You should have received a copy of the GNU General Public License + ## along with Dynare. If not, see <http://www.gnu.org/licenses/>. -load_octave_packages + load_octave_packages -top_test_dir = getenv('TOP_TEST_DIR'); -[mfile, name] = strtok(getenv('FILESTEM')); + top_test_dir = getenv('TOP_TEST_DIR'); + [mfile, name] = strtok(getenv('FILESTEM')); -[directory, mscript, ext] = fileparts([top_test_dir '/' mfile]); -cd(directory); + [directory, mscript, ext] = fileparts([top_test_dir '/' mfile]); + cd(directory); -try - mscript; - testFailed = false; -catch - printMakeCheckOctaveErrMsg(getenv('FILESTEM'), lasterror); - testFailed = true; -end_try_catch + try + mscript; + testFailed = false; + catch + printMakeCheckOctaveErrMsg(getenv('FILESTEM'), lasterror); + testFailed = true; + end_try_catch -cd(top_test_dir); -name = strtok(getenv('FILESTEM')); -fid = fopen([name '.o.tls'], 'w+'); -if testFailed - fprintf(fid,':test-result: FAIL\n'); - fprintf(fid,':number-tests: 1\n'); - fprintf(fid,':number-failed-tests: 1\n'); - fprintf(fid,':list-of-failed-tests: %s\n', [name '.m']); -else - fprintf(fid,':test-result: PASS\n'); - fprintf(fid,':number-tests: 1\n'); - fprintf(fid,':number-failed-tests: 0\n'); - fprintf(fid,':list-of-passed-tests: %s\n', [name '.m']); -end -fclose(fid); + cd(top_test_dir); + name = strtok(getenv('FILESTEM')); + fid = fopen([name '.o.tls'], 'w+'); + if testFailed + fprintf(fid,':test-result: FAIL\n'); + fprintf(fid,':number-tests: 1\n'); + fprintf(fid,':number-failed-tests: 1\n'); + fprintf(fid,':list-of-failed-tests: %s\n', [name '.m']); + else + fprintf(fid,':test-result: PASS\n'); + fprintf(fid,':number-tests: 1\n'); + fprintf(fid,':number-failed-tests: 0\n'); + fprintf(fid,':list-of-passed-tests: %s\n', [name '.m']); + end + fclose(fid); -## Local variables: -## mode: Octave -## End: + ## Local variables: + ## mode: Octave + ## End: diff --git a/tests/run_reporting_test_matlab.m b/tests/run_reporting_test_matlab.m index 3c5ccb95de..bd8a738d4f 100644 --- a/tests/run_reporting_test_matlab.m +++ b/tests/run_reporting_test_matlab.m @@ -21,7 +21,7 @@ addpath([top_test_dir filesep '..' filesep 'matlab']); % Test Dynare Version if ~strcmp(dynare_version(), getenv('DYNARE_VERSION')) - error('Incorrect version of Dynare is being tested') + error('Incorrect version of Dynare is being tested') end % To add default directories, empty dseries objects @@ -44,15 +44,15 @@ end cd(getenv('TOP_TEST_DIR')); fid = fopen('run_reporting_test_matlab.m.trs', 'w+'); if testFailed - fprintf(fid,':test-result: FAIL\n'); - fprintf(fid,':number-tests: 1\n'); - fprintf(fid,':number-failed-tests: 1\n'); - fprintf(fid,':list-of-failed-tests: run_reporting_test_matlab.m\n'); + fprintf(fid,':test-result: FAIL\n'); + fprintf(fid,':number-tests: 1\n'); + fprintf(fid,':number-failed-tests: 1\n'); + fprintf(fid,':list-of-failed-tests: run_reporting_test_matlab.m\n'); else - fprintf(fid,':test-result: PASS\n'); - fprintf(fid,':number-tests: 1\n'); - fprintf(fid,':number-failed-tests: 0\n'); - fprintf(fid,':list-of-passed-tests: run_reporting_test_matlab.m\n'); + fprintf(fid,':test-result: PASS\n'); + fprintf(fid,':number-tests: 1\n'); + fprintf(fid,':number-failed-tests: 0\n'); + fprintf(fid,':list-of-passed-tests: run_reporting_test_matlab.m\n'); end fprintf(fid,':elapsed-time: %f\n',0.0); fclose(fid); diff --git a/tests/run_reporting_test_octave.m b/tests/run_reporting_test_octave.m index 32edcfb630..d47fb64a66 100644 --- a/tests/run_reporting_test_octave.m +++ b/tests/run_reporting_test_octave.m @@ -11,58 +11,58 @@ ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with Dynare. If not, see <http://www.gnu.org/licenses/>. + ## + ## You should have received a copy of the GNU General Public License + ## along with Dynare. If not, see <http://www.gnu.org/licenses/>. -load_octave_packages + load_octave_packages -top_test_dir = getenv('TOP_TEST_DIR'); -addpath(top_test_dir); -addpath([top_test_dir filesep '..' filesep 'matlab']); + top_test_dir = getenv('TOP_TEST_DIR'); + addpath(top_test_dir); + addpath([top_test_dir filesep '..' filesep 'matlab']); -## Test Dynare Version -if !strcmp(dynare_version(), getenv("DYNARE_VERSION")) - error("Incorrect version of Dynare is being tested") -endif + ## Test Dynare Version + if !strcmp(dynare_version(), getenv("DYNARE_VERSION")) + error("Incorrect version of Dynare is being tested") + endif -## Ask gnuplot to create graphics in text mode -## Note that setenv() was introduced in Octave 3.0.2, for compatibility -## with MATLAB -putenv("GNUTERM", "dumb") + ## Ask gnuplot to create graphics in text mode + ## Note that setenv() was introduced in Octave 3.0.2, for compatibility + ## with MATLAB + putenv("GNUTERM", "dumb") -## To add default directories, empty dseries objects -dynare_config([], 0); + ## To add default directories, empty dseries objects + dynare_config([], 0); -printf("\n*** TESTING: run_reporting_test_octave.m ***\n"); -try - cd([top_test_dir filesep 'reporting']); - db_a = dseries('db_a.csv'); - db_q = dseries('db_q.csv'); - dc_a = dseries('dc_a.csv'); - dc_q = dseries('dc_q.csv'); - runDynareReport(dc_a, dc_q, db_a, db_q); - testFailed = false; -catch - testFailed = true; -end + printf("\n*** TESTING: run_reporting_test_octave.m ***\n"); + try + cd([top_test_dir filesep 'reporting']); + db_a = dseries('db_a.csv'); + db_q = dseries('db_q.csv'); + dc_a = dseries('dc_a.csv'); + dc_q = dseries('dc_q.csv'); + runDynareReport(dc_a, dc_q, db_a, db_q); + testFailed = false; + catch + testFailed = true; + end -cd(getenv('TOP_TEST_DIR')); -fid = fopen('run_reporting_test_octave.o.trs', 'w+'); -if testFailed - fprintf(fid,':test-result: FAIL\n'); - fprintf(fid,':number-tests: 1\n'); - fprintf(fid,':number-failed-tests: 1\n'); - fprintf(fid,':list-of-failed-tests: run_reporting_test_octave.m\n'); -else - fprintf(fid,':test-result: PASS\n'); - fprintf(fid,':number-tests: 1\n'); - fprintf(fid,':number-failed-tests: 0\n'); - fprintf(fid,':list-of-passed-tests: run_reporting_test_octave.m\n'); -end -fprintf(fid,':elapsed-time: %f\n',0.0); -fclose(fid); + cd(getenv('TOP_TEST_DIR')); + fid = fopen('run_reporting_test_octave.o.trs', 'w+'); + if testFailed + fprintf(fid,':test-result: FAIL\n'); + fprintf(fid,':number-tests: 1\n'); + fprintf(fid,':number-failed-tests: 1\n'); + fprintf(fid,':list-of-failed-tests: run_reporting_test_octave.m\n'); + else + fprintf(fid,':test-result: PASS\n'); + fprintf(fid,':number-tests: 1\n'); + fprintf(fid,':number-failed-tests: 0\n'); + fprintf(fid,':list-of-passed-tests: run_reporting_test_octave.m\n'); + end + fprintf(fid,':elapsed-time: %f\n',0.0); + fclose(fid); -## Local variables: -## mode: Octave -## End: + ## Local variables: + ## mode: Octave + ## End: diff --git a/tests/run_test_matlab.m b/tests/run_test_matlab.m index fb1b487a08..c7735dc168 100644 --- a/tests/run_test_matlab.m +++ b/tests/run_test_matlab.m @@ -21,7 +21,7 @@ addpath([top_test_dir filesep '..' filesep 'matlab']); % Test Dynare Version if ~strcmp(dynare_version(), getenv('DYNARE_VERSION')) - error('Incorrect version of Dynare is being tested') + error('Incorrect version of Dynare is being tested') end % Test MOD files listed in Makefile.am @@ -35,11 +35,11 @@ disp(['*** TESTING: ' modfile ' ***']); tic; save(['wsMat' testfile '.mat']); try - dynare([testfile ext], 'console') - testFailed = false; + dynare([testfile ext], 'console') + testFailed = false; catch exception - printMakeCheckMatlabErrMsg(strtok(getenv('FILESTEM')), exception); - testFailed = true; + printMakeCheckMatlabErrMsg(strtok(getenv('FILESTEM')), exception); + testFailed = true; end top_test_dir = getenv('TOP_TEST_DIR'); [modfile, name] = strtok(getenv('FILESTEM')); @@ -52,20 +52,20 @@ cd(top_test_dir); name = strtok(getenv('FILESTEM')); fid = fopen([name '.m.trs'], 'w'); if fid < 0 - wd = pwd - filestep = getenv('FILESTEM') - error(['ERROR: problem opening file ' name '.m.trs for writing....']); + wd = pwd + filestep = getenv('FILESTEM') + error(['ERROR: problem opening file ' name '.m.trs for writing....']); end if testFailed - fprintf(fid,':test-result: FAIL\n'); - fprintf(fid,':number-tests: 1\n'); - fprintf(fid,':number-failed-tests: 1\n'); - fprintf(fid,':list-of-failed-tests: %s\n', [name '.mod']); + fprintf(fid,':test-result: FAIL\n'); + fprintf(fid,':number-tests: 1\n'); + fprintf(fid,':number-failed-tests: 1\n'); + fprintf(fid,':list-of-failed-tests: %s\n', [name '.mod']); else - fprintf(fid,':test-result: PASS\n'); - fprintf(fid,':number-tests: 1\n'); - fprintf(fid,':number-failed-tests: 0\n'); - fprintf(fid,':list-of-passed-tests: %s\n', [name '.mod']); + fprintf(fid,':test-result: PASS\n'); + fprintf(fid,':number-tests: 1\n'); + fprintf(fid,':number-failed-tests: 0\n'); + fprintf(fid,':list-of-passed-tests: %s\n', [name '.mod']); end fprintf(fid,':elapsed-time: %f\n', ecput); fclose(fid); diff --git a/tests/run_test_octave.m b/tests/run_test_octave.m index 12cff43516..12ff117ad6 100644 --- a/tests/run_test_octave.m +++ b/tests/run_test_octave.m @@ -11,71 +11,71 @@ ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with Dynare. If not, see <http://www.gnu.org/licenses/>. + ## + ## You should have received a copy of the GNU General Public License + ## along with Dynare. If not, see <http://www.gnu.org/licenses/>. -## Implementation notes: -## -## Before every call to Dynare, the contents of the workspace is saved in -## 'wsOct', and reloaded after Dynare has finished (this is necessary since -## Dynare does a 'clear -all'). + ## Implementation notes: + ## + ## Before every call to Dynare, the contents of the workspace is saved in + ## 'wsOct', and reloaded after Dynare has finished (this is necessary since + ## Dynare does a 'clear -all'). -load_octave_packages + load_octave_packages -top_test_dir = getenv('TOP_TEST_DIR'); -addpath(top_test_dir); -addpath('.'); % workaround for bug in Octave 4.2.0-rc2: https://savannah.gnu.org/bugs/?49334 -addpath([top_test_dir filesep '..' filesep 'matlab']); + top_test_dir = getenv('TOP_TEST_DIR'); + addpath(top_test_dir); + addpath('.'); % workaround for bug in Octave 4.2.0-rc2: https://savannah.gnu.org/bugs/?49334 + addpath([top_test_dir filesep '..' filesep 'matlab']); -## Test Dynare Version -if !strcmp(dynare_version(), getenv("DYNARE_VERSION")) - error("Incorrect version of Dynare is being tested") -endif + ## Test Dynare Version + if !strcmp(dynare_version(), getenv("DYNARE_VERSION")) + error("Incorrect version of Dynare is being tested") + endif -## Ask gnuplot to create graphics in text mode -graphics_toolkit gnuplot; -setenv("GNUTERM", "dumb"); + ## Ask gnuplot to create graphics in text mode + graphics_toolkit gnuplot; + setenv("GNUTERM", "dumb"); -## Test MOD files listed in Makefile.am -name = getenv("FILESTEM"); -[directory, testfile, ext] = fileparts([top_test_dir '/' name]); -cd(directory); + ## Test MOD files listed in Makefile.am + name = getenv("FILESTEM"); + [directory, testfile, ext] = fileparts([top_test_dir '/' name]); + cd(directory); -printf("\n*** TESTING: %s ***\n", name); + printf("\n*** TESTING: %s ***\n", name); -tic; -save(['wsOct' testfile '.mat']); -try - dynare([testfile ext]) - testFailed = false; -catch - printMakeCheckOctaveErrMsg(getenv("FILESTEM"), lasterror); - testFailed = true; -end_try_catch -top_test_dir = getenv('TOP_TEST_DIR'); -name = getenv("FILESTEM"); -[directory, testfile, ext] = fileparts([top_test_dir '/' name]); -load(['wsOct' testfile '.mat']); -ecput = toc; -delete(['wsOct' testfile '.mat']); + tic; + save(['wsOct' testfile '.mat']); + try + dynare([testfile ext]) + testFailed = false; + catch + printMakeCheckOctaveErrMsg(getenv("FILESTEM"), lasterror); + testFailed = true; + end_try_catch + top_test_dir = getenv('TOP_TEST_DIR'); + name = getenv("FILESTEM"); + [directory, testfile, ext] = fileparts([top_test_dir '/' name]); + load(['wsOct' testfile '.mat']); + ecput = toc; + delete(['wsOct' testfile '.mat']); -cd(top_test_dir); -fid = fopen([name '.o.trs'], 'w+'); -if testFailed - fprintf(fid,':test-result: FAIL\n'); - fprintf(fid,':number-tests: 1\n'); - fprintf(fid,':number-failed-tests: 1\n'); - fprintf(fid,':list-of-failed-tests: %s\n', [name '.mod']); -else - fprintf(fid,':test-result: PASS\n'); - fprintf(fid,':number-tests: 1\n'); - fprintf(fid,':number-failed-tests: 0\n'); - fprintf(fid,':list-of-passed-tests: %s\n', [name '.mod']); -end -fprintf(fid,':elapsed-time: %f\n', ecput); -fclose(fid); + cd(top_test_dir); + fid = fopen([name '.o.trs'], 'w+'); + if testFailed + fprintf(fid,':test-result: FAIL\n'); + fprintf(fid,':number-tests: 1\n'); + fprintf(fid,':number-failed-tests: 1\n'); + fprintf(fid,':list-of-failed-tests: %s\n', [name '.mod']); + else + fprintf(fid,':test-result: PASS\n'); + fprintf(fid,':number-tests: 1\n'); + fprintf(fid,':number-failed-tests: 0\n'); + fprintf(fid,':list-of-passed-tests: %s\n', [name '.mod']); + end + fprintf(fid,':elapsed-time: %f\n', ecput); + fclose(fid); -## Local variables: -## mode: Octave -## End: + ## Local variables: + ## mode: Octave + ## End: diff --git a/tests/shock_decomposition/fsdat_simul.m b/tests/shock_decomposition/fsdat_simul.m index d4f4a8066f..159612e577 100644 --- a/tests/shock_decomposition/fsdat_simul.m +++ b/tests/shock_decomposition/fsdat_simul.m @@ -1,828 +1,828 @@ gy_obs =[ - 1.0030045 - 0.99990934 - 1.0172778 - 0.99464043 - 1.0253423 - 1.0150215 - 0.97772557 - 0.97832186 - 1.0159561 - 1.0085937 - 1.0102649 - 1.0007604 - 1.0112596 - 1.0163279 - 1.0173204 - 1.0103896 - 1.0006493 - 0.99447124 - 1.0196405 - 1.0089304 - 0.99650737 - 1.0139707 - 0.97865842 - 1.0192225 - 0.99139628 - 1.0141362 - 1.0196612 - 0.97483476 - 0.99686151 - 0.99594464 - 1.0000642 - 1.0172243 - 1.0025773 - 0.97199728 - 1.0217815 - 1.0219949 - 0.99490252 - 1.0190728 - 1.0111337 - 1.0003792 - 0.98969164 - 1.010438 - 1.0216309 - 1.0016671 - 1.0357588 - 0.98803787 - 1.0093457 - 1.0177035 - 0.98548204 - 1.0274294 - 1.0141377 - 1.0091174 - 0.96427632 - 1.0083272 - 1.0007882 - 0.99038262 - 1.0031336 - 0.99500213 - 0.98203716 - 0.9889452 - 1.011632 - 0.99451949 - 0.97291047 - 0.98750871 - 0.99992418 - 0.97657318 - 0.99930448 - 1.0008515 - 1.0044064 - 0.98133792 - 1.0091702 - 1.0087023 - 1.0119876 - 1.0143019 - 1.0311061 - 0.99340471 - 1.0057428 - 0.99197259 - 1.0071019 - 0.99448853 - 1.0061819 - 1.0070088 - 0.9950913 - 1.0302318 - 0.9817693 - 1.0072885 - 0.97355282 - 0.98782586 - 1.0136674 - 0.99863956 - 1.0205668 - 0.99611384 - 1.0073805 - 0.99691529 - 1.0089194 - 1.0030467 - 1.0112006 - 1.0260523 - 0.97803331 - 0.99423374 - 1.0043727 - 1.0140173 - 1.0111473 - 0.99524348 - 0.99775943 - 0.9958619 - 0.9982344 - 1.0210212 - 1.0022288 - 1.0014801 - 1.011456 - 1.0124871 - 0.99843599 - 0.99324886 - 0.99912838 - 1.003327 - 1.0072071 - 1.0115223 - 1.009266 - 1.0070554 - 1.0129916 - 1.0053413 - 1.0051638 - 0.99212952 - 1.0214422 - 0.98716707 - 0.99905788 - 0.98877357 - 0.98568476 - 0.99767393 - 1.0061791 - 0.98423439 - 0.99492949 - 0.98786999 - 0.99754239 - 1.0168619 - 0.99472384 - 1.0041658 - 0.98123181 - 1.0112882 - 0.99245422 - 1.0010255 - 1.0017799 - 1.0089968 - 1.0072824 - 0.99768475 - 1.0044726 - 1.0118678 - 1.0056385 - 1.0276965 - 1.0025122 - 1.0065161 - 1.0234338 - 0.99760167 - 0.98922272 - 1.0101918 - 1.011615 - 1.0085286 - 1.0074455 - 0.98866757 - 0.99959012 - 1.0129881 - 0.99127881 - 0.97971901 - 1.0185314 - 1.020054 - 1.0132605 - 0.98063643 - 0.99490253 - 1.0101531 - 1.0004526 - 1.0059109 - 0.98974491 - 1.0062391 - 1.0216488 - 0.99398446 - 0.97786609 - 1.0019274 - 0.99587153 - 1.0095881 - 1.0111887 - 0.99457649 - 0.97896734 - 1.000172 - 1.0142951 - 1.0034224 - 1.0037242 - 1.0016059 - 1.016556 - 0.99687023 - 1.0117844 - 1.0059212 - 0.98083159 - 0.98638851 - 1.0128713 - 1.0096232 - 1.0115891 - 1.0011213 - 1.0147105 - 1.0066344 - 1.0164429 - 0.99825038 - 0.99403411 + 1.0030045 + 0.99990934 + 1.0172778 + 0.99464043 + 1.0253423 + 1.0150215 + 0.97772557 + 0.97832186 + 1.0159561 + 1.0085937 + 1.0102649 + 1.0007604 + 1.0112596 + 1.0163279 + 1.0173204 + 1.0103896 + 1.0006493 + 0.99447124 + 1.0196405 + 1.0089304 + 0.99650737 + 1.0139707 + 0.97865842 + 1.0192225 + 0.99139628 + 1.0141362 + 1.0196612 + 0.97483476 + 0.99686151 + 0.99594464 + 1.0000642 + 1.0172243 + 1.0025773 + 0.97199728 + 1.0217815 + 1.0219949 + 0.99490252 + 1.0190728 + 1.0111337 + 1.0003792 + 0.98969164 + 1.010438 + 1.0216309 + 1.0016671 + 1.0357588 + 0.98803787 + 1.0093457 + 1.0177035 + 0.98548204 + 1.0274294 + 1.0141377 + 1.0091174 + 0.96427632 + 1.0083272 + 1.0007882 + 0.99038262 + 1.0031336 + 0.99500213 + 0.98203716 + 0.9889452 + 1.011632 + 0.99451949 + 0.97291047 + 0.98750871 + 0.99992418 + 0.97657318 + 0.99930448 + 1.0008515 + 1.0044064 + 0.98133792 + 1.0091702 + 1.0087023 + 1.0119876 + 1.0143019 + 1.0311061 + 0.99340471 + 1.0057428 + 0.99197259 + 1.0071019 + 0.99448853 + 1.0061819 + 1.0070088 + 0.9950913 + 1.0302318 + 0.9817693 + 1.0072885 + 0.97355282 + 0.98782586 + 1.0136674 + 0.99863956 + 1.0205668 + 0.99611384 + 1.0073805 + 0.99691529 + 1.0089194 + 1.0030467 + 1.0112006 + 1.0260523 + 0.97803331 + 0.99423374 + 1.0043727 + 1.0140173 + 1.0111473 + 0.99524348 + 0.99775943 + 0.9958619 + 0.9982344 + 1.0210212 + 1.0022288 + 1.0014801 + 1.011456 + 1.0124871 + 0.99843599 + 0.99324886 + 0.99912838 + 1.003327 + 1.0072071 + 1.0115223 + 1.009266 + 1.0070554 + 1.0129916 + 1.0053413 + 1.0051638 + 0.99212952 + 1.0214422 + 0.98716707 + 0.99905788 + 0.98877357 + 0.98568476 + 0.99767393 + 1.0061791 + 0.98423439 + 0.99492949 + 0.98786999 + 0.99754239 + 1.0168619 + 0.99472384 + 1.0041658 + 0.98123181 + 1.0112882 + 0.99245422 + 1.0010255 + 1.0017799 + 1.0089968 + 1.0072824 + 0.99768475 + 1.0044726 + 1.0118678 + 1.0056385 + 1.0276965 + 1.0025122 + 1.0065161 + 1.0234338 + 0.99760167 + 0.98922272 + 1.0101918 + 1.011615 + 1.0085286 + 1.0074455 + 0.98866757 + 0.99959012 + 1.0129881 + 0.99127881 + 0.97971901 + 1.0185314 + 1.020054 + 1.0132605 + 0.98063643 + 0.99490253 + 1.0101531 + 1.0004526 + 1.0059109 + 0.98974491 + 1.0062391 + 1.0216488 + 0.99398446 + 0.97786609 + 1.0019274 + 0.99587153 + 1.0095881 + 1.0111887 + 0.99457649 + 0.97896734 + 1.000172 + 1.0142951 + 1.0034224 + 1.0037242 + 1.0016059 + 1.016556 + 0.99687023 + 1.0117844 + 1.0059212 + 0.98083159 + 0.98638851 + 1.0128713 + 1.0096232 + 1.0115891 + 1.0011213 + 1.0147105 + 1.0066344 + 1.0164429 + 0.99825038 + 0.99403411 -]; + ]; gp_obs =[ - 1.0079715 - 1.0074573 - 1.0153107 - 1.0152677 - 1.0011653 - 0.99950061 - 1.0328311 - 1.0192317 - 1.009827 - 0.99588916 - 1.007474 - 1.0113061 - 0.98696624 - 0.99978663 - 0.98240542 - 0.98861723 - 0.99008763 - 1.0185076 - 1.0052452 - 0.99447194 - 1.0092685 - 1.01208 - 1.0105237 - 0.98513875 - 1.0165628 - 0.99485934 - 1.0050255 - 1.0140756 - 1.0093128 - 1.0155868 - 1.0107023 - 0.99212762 - 1.0095465 - 1.0028435 - 1.0069437 - 1.0070473 - 1.0145902 - 1.0186922 - 1.0059917 - 1.0113072 - 1.0107386 - 0.99769196 - 0.99793444 - 1.0050791 - 0.98307821 - 1.0107594 - 0.99689982 - 0.98667064 - 0.9991662 - 0.98274722 - 0.98422032 - 0.99393016 - 1.0118567 - 0.99912781 - 1.0023744 - 1.0086662 - 1.0164773 - 1.0169327 - 1.0372478 - 1.0314242 - 1.0004256 - 1.0110541 - 1.0076575 - 1.0119851 - 1.0055188 - 1.0213959 - 1.0234416 - 1.0264917 - 1.0292725 - 1.0385184 - 1.0200999 - 1.0107697 - 1.008583 - 1.0200332 - 1.0030413 - 1.0108659 - 1.0185145 - 1.0168619 - 1.0180462 - 1.0239657 - 1.0205509 - 1.0189973 - 1.0246446 - 1.0135089 - 1.0352973 - 1.0099289 - 1.0266474 - 1.0279829 - 1.0101653 - 1.041216 - 1.0103861 - 1.0114727 - 1.0054605 - 1.0190722 - 1.0114837 - 1.0179213 - 1.006082 - 1.0049696 - 1.0143629 - 0.9971036 - 1.0005602 - 1.0078403 - 1.0240222 - 1.0195063 - 1.0355136 - 1.0218743 - 1.0171331 - 1.0049817 - 1.0140974 - 1.0168431 - 1.0049966 - 1.0045568 - 1.0156414 - 1.0273055 - 1.0197653 - 1.0030624 - 1.0154993 - 0.99782084 - 0.99711648 - 1.014408 - 1.0057417 - 0.99936837 - 1.0096934 - 1.0095138 - 1.0057734 - 1.0114497 - 1.0059784 - 1.0328889 - 1.0098032 - 1.0041114 - 1.0101247 - 1.0181588 - 1.0115712 - 1.0227509 - 1.0065104 - 1.0110902 - 1.0298169 - 1.0089532 - 1.0368733 - 1.0123033 - 1.0060763 - 1.0150937 - 1.0239325 - 0.99555536 - 0.99861271 - 1.0076201 - 0.99941535 - 1.0119522 - 1.0129183 - 0.99288924 - 1.0260784 - 1.0144982 - 1.0121985 - 1.0234916 - 1.02215 - 1.0190118 - 1.0172679 - 1.0118398 - 1.0002123 - 1.0092124 - 1.0071943 - 0.99508468 - 1.0019303 - 1.0030733 - 0.9964198 - 1.0027298 - 0.99797614 - 1.006942 - 0.99793928 - 1.0083214 - 1.0283732 - 1.0111102 - 1.016936 - 1.0229061 - 0.98846454 - 1.0015387 - 1.0201769 - 1.0079822 - 1.0064007 - 1.0095543 - 1.0092207 - 1.0135485 - 1.0198974 - 1.0140252 - 1.0128686 - 1.0092903 - 1.0141974 - 1.0023492 - 0.99731455 - 1.0026598 - 0.99303643 - 1.0036469 - 1.0160975 - 1.0368378 - 1.0139625 - 1.01493 - 1.0113531 - 1.0114548 - 0.99833441 - 0.99648401 - 0.97645361 - 1.0154053 - 1.01703 + 1.0079715 + 1.0074573 + 1.0153107 + 1.0152677 + 1.0011653 + 0.99950061 + 1.0328311 + 1.0192317 + 1.009827 + 0.99588916 + 1.007474 + 1.0113061 + 0.98696624 + 0.99978663 + 0.98240542 + 0.98861723 + 0.99008763 + 1.0185076 + 1.0052452 + 0.99447194 + 1.0092685 + 1.01208 + 1.0105237 + 0.98513875 + 1.0165628 + 0.99485934 + 1.0050255 + 1.0140756 + 1.0093128 + 1.0155868 + 1.0107023 + 0.99212762 + 1.0095465 + 1.0028435 + 1.0069437 + 1.0070473 + 1.0145902 + 1.0186922 + 1.0059917 + 1.0113072 + 1.0107386 + 0.99769196 + 0.99793444 + 1.0050791 + 0.98307821 + 1.0107594 + 0.99689982 + 0.98667064 + 0.9991662 + 0.98274722 + 0.98422032 + 0.99393016 + 1.0118567 + 0.99912781 + 1.0023744 + 1.0086662 + 1.0164773 + 1.0169327 + 1.0372478 + 1.0314242 + 1.0004256 + 1.0110541 + 1.0076575 + 1.0119851 + 1.0055188 + 1.0213959 + 1.0234416 + 1.0264917 + 1.0292725 + 1.0385184 + 1.0200999 + 1.0107697 + 1.008583 + 1.0200332 + 1.0030413 + 1.0108659 + 1.0185145 + 1.0168619 + 1.0180462 + 1.0239657 + 1.0205509 + 1.0189973 + 1.0246446 + 1.0135089 + 1.0352973 + 1.0099289 + 1.0266474 + 1.0279829 + 1.0101653 + 1.041216 + 1.0103861 + 1.0114727 + 1.0054605 + 1.0190722 + 1.0114837 + 1.0179213 + 1.006082 + 1.0049696 + 1.0143629 + 0.9971036 + 1.0005602 + 1.0078403 + 1.0240222 + 1.0195063 + 1.0355136 + 1.0218743 + 1.0171331 + 1.0049817 + 1.0140974 + 1.0168431 + 1.0049966 + 1.0045568 + 1.0156414 + 1.0273055 + 1.0197653 + 1.0030624 + 1.0154993 + 0.99782084 + 0.99711648 + 1.014408 + 1.0057417 + 0.99936837 + 1.0096934 + 1.0095138 + 1.0057734 + 1.0114497 + 1.0059784 + 1.0328889 + 1.0098032 + 1.0041114 + 1.0101247 + 1.0181588 + 1.0115712 + 1.0227509 + 1.0065104 + 1.0110902 + 1.0298169 + 1.0089532 + 1.0368733 + 1.0123033 + 1.0060763 + 1.0150937 + 1.0239325 + 0.99555536 + 0.99861271 + 1.0076201 + 0.99941535 + 1.0119522 + 1.0129183 + 0.99288924 + 1.0260784 + 1.0144982 + 1.0121985 + 1.0234916 + 1.02215 + 1.0190118 + 1.0172679 + 1.0118398 + 1.0002123 + 1.0092124 + 1.0071943 + 0.99508468 + 1.0019303 + 1.0030733 + 0.9964198 + 1.0027298 + 0.99797614 + 1.006942 + 0.99793928 + 1.0083214 + 1.0283732 + 1.0111102 + 1.016936 + 1.0229061 + 0.98846454 + 1.0015387 + 1.0201769 + 1.0079822 + 1.0064007 + 1.0095543 + 1.0092207 + 1.0135485 + 1.0198974 + 1.0140252 + 1.0128686 + 1.0092903 + 1.0141974 + 1.0023492 + 0.99731455 + 1.0026598 + 0.99303643 + 1.0036469 + 1.0160975 + 1.0368378 + 1.0139625 + 1.01493 + 1.0113531 + 1.0114548 + 0.99833441 + 0.99648401 + 0.97645361 + 1.0154053 + 1.01703 -]; + ]; Y_obs =[ - 1 - 0.99690484 - 1.0111781 - 1.0028141 - 1.0251518 - 1.0371688 - 1.0118899 - 0.98720726 - 1.0001589 - 1.0057481 - 1.0130085 - 1.0107643 - 1.0190194 - 1.0323428 - 1.0466587 - 1.0540438 - 1.0516886 - 1.0431553 - 1.0597913 - 1.0657172 - 1.0592201 - 1.0701863 - 1.0458402 - 1.0620582 - 1.0504499 - 1.0615817 - 1.0782384 - 1.0500687 - 1.0439257 - 1.0368658 - 1.0339255 - 1.0481453 - 1.0477181 - 1.0167109 - 1.0354878 - 1.0544782 - 1.0463762 - 1.0624445 - 1.0705737 - 1.0679484 - 1.0546356 - 1.0620691 - 1.0806955 - 1.0793581 - 1.1121124 - 1.0971458 - 1.1034869 - 1.1181859 - 1.1006634 - 1.1250883 - 1.1362214 - 1.1423343 - 1.1036061 - 1.1089288 - 1.1067125 - 1.0940906 - 1.0942197 - 1.0862174 - 1.06525 - 1.0511907 - 1.0598182 - 1.0513331 - 1.0212391 - 1.0057433 - 1.002663 - 0.97623167 - 0.97253165 - 0.97037865 - 0.97178055 - 0.95011397 - 0.95627969 - 0.96197747 - 0.97096053 - 0.98225794 - 1.0103595 - 1.0007597 - 1.003498 - 0.99246608 - 0.99656347 - 0.98804749 - 0.99122491 - 0.99522926 - 0.98731605 - 1.0145434 - 0.99330816 - 0.99759216 - 0.96814048 - 0.95296183 - 0.96362471 - 0.95925977 - 0.97682205 - 0.96993138 - 0.9743074 - 0.96821818 - 0.97413308 - 0.9741753 - 0.98237142 - 1.0054193 - 0.98044807 - 0.9716773 - 0.9730455 - 0.98405828 - 0.99220103 - 0.98444001 - 0.97919493 - 0.97205233 - 0.96728223 - 0.98529893 - 0.98452324 - 0.98299888 - 0.99145042 - 1.000933 - 0.99636447 - 0.98660883 - 0.98273271 - 0.98305518 - 0.98725774 - 0.99577549 - 1.002037 - 1.0060879 - 1.016075 - 1.0184118 - 1.0205711 - 1.0096961 - 1.0281337 - 1.0122963 - 1.0083497 - 0.99411874 - 0.976799 - 0.97146842 - 0.97464304 - 0.95587292 - 0.94779791 - 0.93266339 - 0.92720128 - 0.94105864 - 0.93277798 - 0.93393927 - 0.91216657 - 0.92045028 - 0.9099 - 0.90792098 - 0.90669634 - 0.91268867 - 0.91696661 - 0.91164685 - 0.91311495 - 0.92197825 - 0.92461222 - 0.94930422 - 0.9488119 - 0.95232353 - 0.97275278 - 0.96734995 - 0.95356817 - 0.96075548 - 0.96936594 - 0.97489002 - 0.97933106 - 0.96499412 - 0.96157973 - 0.97156334 - 0.95983765 - 0.93655215 - 0.95207909 - 0.96912862 - 0.97938462 - 0.95701655 - 0.94891457 - 0.95606317 - 0.95351125 - 0.95641767 - 0.94315807 - 0.94639265 - 0.96503697 - 0.95601693 - 0.93087851 - 0.92980141 - 0.92266844 - 0.92925206 - 0.93743628 - 0.92900826 - 0.9049711 - 0.90213859 - 0.91342916 - 0.91384707 - 0.91456681 - 0.91316822 - 0.92671976 - 0.92058549 - 0.92936541 - 0.93228212 - 0.91010921 - 0.89349322 - 0.90336005 - 0.90997873 - 0.91856328 - 0.91668007 - 0.92838606 - 0.932016 - 0.94545438 - 0.94070026 - 0.93172987 + 1 + 0.99690484 + 1.0111781 + 1.0028141 + 1.0251518 + 1.0371688 + 1.0118899 + 0.98720726 + 1.0001589 + 1.0057481 + 1.0130085 + 1.0107643 + 1.0190194 + 1.0323428 + 1.0466587 + 1.0540438 + 1.0516886 + 1.0431553 + 1.0597913 + 1.0657172 + 1.0592201 + 1.0701863 + 1.0458402 + 1.0620582 + 1.0504499 + 1.0615817 + 1.0782384 + 1.0500687 + 1.0439257 + 1.0368658 + 1.0339255 + 1.0481453 + 1.0477181 + 1.0167109 + 1.0354878 + 1.0544782 + 1.0463762 + 1.0624445 + 1.0705737 + 1.0679484 + 1.0546356 + 1.0620691 + 1.0806955 + 1.0793581 + 1.1121124 + 1.0971458 + 1.1034869 + 1.1181859 + 1.1006634 + 1.1250883 + 1.1362214 + 1.1423343 + 1.1036061 + 1.1089288 + 1.1067125 + 1.0940906 + 1.0942197 + 1.0862174 + 1.06525 + 1.0511907 + 1.0598182 + 1.0513331 + 1.0212391 + 1.0057433 + 1.002663 + 0.97623167 + 0.97253165 + 0.97037865 + 0.97178055 + 0.95011397 + 0.95627969 + 0.96197747 + 0.97096053 + 0.98225794 + 1.0103595 + 1.0007597 + 1.003498 + 0.99246608 + 0.99656347 + 0.98804749 + 0.99122491 + 0.99522926 + 0.98731605 + 1.0145434 + 0.99330816 + 0.99759216 + 0.96814048 + 0.95296183 + 0.96362471 + 0.95925977 + 0.97682205 + 0.96993138 + 0.9743074 + 0.96821818 + 0.97413308 + 0.9741753 + 0.98237142 + 1.0054193 + 0.98044807 + 0.9716773 + 0.9730455 + 0.98405828 + 0.99220103 + 0.98444001 + 0.97919493 + 0.97205233 + 0.96728223 + 0.98529893 + 0.98452324 + 0.98299888 + 0.99145042 + 1.000933 + 0.99636447 + 0.98660883 + 0.98273271 + 0.98305518 + 0.98725774 + 0.99577549 + 1.002037 + 1.0060879 + 1.016075 + 1.0184118 + 1.0205711 + 1.0096961 + 1.0281337 + 1.0122963 + 1.0083497 + 0.99411874 + 0.976799 + 0.97146842 + 0.97464304 + 0.95587292 + 0.94779791 + 0.93266339 + 0.92720128 + 0.94105864 + 0.93277798 + 0.93393927 + 0.91216657 + 0.92045028 + 0.9099 + 0.90792098 + 0.90669634 + 0.91268867 + 0.91696661 + 0.91164685 + 0.91311495 + 0.92197825 + 0.92461222 + 0.94930422 + 0.9488119 + 0.95232353 + 0.97275278 + 0.96734995 + 0.95356817 + 0.96075548 + 0.96936594 + 0.97489002 + 0.97933106 + 0.96499412 + 0.96157973 + 0.97156334 + 0.95983765 + 0.93655215 + 0.95207909 + 0.96912862 + 0.97938462 + 0.95701655 + 0.94891457 + 0.95606317 + 0.95351125 + 0.95641767 + 0.94315807 + 0.94639265 + 0.96503697 + 0.95601693 + 0.93087851 + 0.92980141 + 0.92266844 + 0.92925206 + 0.93743628 + 0.92900826 + 0.9049711 + 0.90213859 + 0.91342916 + 0.91384707 + 0.91456681 + 0.91316822 + 0.92671976 + 0.92058549 + 0.92936541 + 0.93228212 + 0.91010921 + 0.89349322 + 0.90336005 + 0.90997873 + 0.91856328 + 0.91668007 + 0.92838606 + 0.932016 + 0.94545438 + 0.94070026 + 0.93172987 -]; + ]; P_obs =[ - 1 - 0.99948573 - 1.0068249 - 1.0141211 - 1.0073149 - 0.99884398 - 1.0237035 - 1.0349636 - 1.036819 - 1.0247366 - 1.0242391 - 1.0275737 - 1.0065684 - 0.99838346 - 0.97281734 - 0.95346302 - 0.9355791 - 0.9461152 - 0.94338882 - 0.92988921 - 0.9311862 - 0.93529467 - 0.93784681 - 0.91501401 - 0.92360522 - 0.91049302 - 0.90754698 - 0.91365103 - 0.91499228 - 0.92260749 - 0.92533824 - 0.90949431 - 0.91106924 - 0.90594116 - 0.90491334 - 0.9039891 - 0.91060772 - 0.92132842 - 0.91934854 - 0.92268418 - 0.92545127 - 0.91517169 - 0.90513459 - 0.90224212 - 0.87734878 - 0.88013667 - 0.86906494 - 0.84776403 - 0.83895869 - 0.81373437 - 0.78998314 - 0.77594176 - 0.77982695 - 0.77098321 - 0.76538611 - 0.76608075 - 0.77458654 - 0.78354767 - 0.81282389 - 0.83627649 - 0.82873051 - 0.83181309 - 0.83149903 - 0.83551261 - 0.83305985 - 0.84648418 - 0.86195421 - 0.88047436 - 0.90177533 - 0.93232215 - 0.94445051 - 0.9472487 - 0.94786015 - 0.95992178 - 0.95499149 - 0.95788581 - 0.9684288 - 0.97731917 - 0.98739379 - 1.0033879 - 1.0159673 - 1.0269931 - 1.0436661 - 1.0492034 - 1.0765292 - 1.0784865 - 1.0971624 - 1.1171737 - 1.1193675 - 1.1526119 - 1.1550265 - 1.1585277 - 1.1560166 - 1.1671172 - 1.1706294 - 1.1805791 - 1.1786896 - 1.1756876 - 1.1820789 - 1.171211 - 1.1637997 - 1.1636684 - 1.179719 - 1.1912538 - 1.2187959 - 1.2326986 - 1.2418602 - 1.2388704 - 1.2449963 - 1.2538678 - 1.2508929 - 1.2474781 - 1.255148 - 1.274482 - 1.2862757 - 1.2813665 - 1.2888943 - 1.2787436 - 1.2678886 - 1.274325 - 1.2720952 - 1.263492 - 1.2652139 - 1.2667561 - 1.264558 - 1.2680362 - 1.2660431 - 1.2909605 - 1.2927921 - 1.288932 - 1.2910852 - 1.3012725 - 1.3048721 - 1.3196515 - 1.3181903 - 1.321309 - 1.3431543 - 1.344136 - 1.3730377 - 1.3773695 - 1.3754742 - 1.3825964 - 1.3985574 - 1.3861412 - 1.3767823 - 1.3764309 - 1.3678747 - 1.3718554 - 1.3768022 - 1.3617199 - 1.3798267 - 1.3863533 - 1.3905803 - 1.4061004 - 1.4202788 - 1.4313191 - 1.4406155 - 1.4444837 - 1.4367244 - 1.4379653 - 1.4371881 - 1.4243012 - 1.41826 - 1.4133617 - 1.40181 - 1.3965683 - 1.3865729 - 1.3855433 - 1.3755111 - 1.3758609 - 1.3962625 - 1.3994012 - 1.4083656 - 1.4233002 - 1.4037932 - 1.3973604 - 1.4095657 - 1.4095764 - 1.4080055 - 1.4095882 - 1.4108374 - 1.4164143 - 1.4283402 - 1.4343939 - 1.4392909 - 1.4406097 - 1.4468355 - 1.4412132 - 1.4305562 - 1.4252445 - 1.4103094 - 1.4059847 - 1.4141106 - 1.4429769 - 1.4489679 - 1.4559263 - 1.4593079 - 1.4627911 - 1.453154 - 1.4416665 - 1.4101485 - 1.4175823 - 1.4266407 + 1 + 0.99948573 + 1.0068249 + 1.0141211 + 1.0073149 + 0.99884398 + 1.0237035 + 1.0349636 + 1.036819 + 1.0247366 + 1.0242391 + 1.0275737 + 1.0065684 + 0.99838346 + 0.97281734 + 0.95346302 + 0.9355791 + 0.9461152 + 0.94338882 + 0.92988921 + 0.9311862 + 0.93529467 + 0.93784681 + 0.91501401 + 0.92360522 + 0.91049302 + 0.90754698 + 0.91365103 + 0.91499228 + 0.92260749 + 0.92533824 + 0.90949431 + 0.91106924 + 0.90594116 + 0.90491334 + 0.9039891 + 0.91060772 + 0.92132842 + 0.91934854 + 0.92268418 + 0.92545127 + 0.91517169 + 0.90513459 + 0.90224212 + 0.87734878 + 0.88013667 + 0.86906494 + 0.84776403 + 0.83895869 + 0.81373437 + 0.78998314 + 0.77594176 + 0.77982695 + 0.77098321 + 0.76538611 + 0.76608075 + 0.77458654 + 0.78354767 + 0.81282389 + 0.83627649 + 0.82873051 + 0.83181309 + 0.83149903 + 0.83551261 + 0.83305985 + 0.84648418 + 0.86195421 + 0.88047436 + 0.90177533 + 0.93232215 + 0.94445051 + 0.9472487 + 0.94786015 + 0.95992178 + 0.95499149 + 0.95788581 + 0.9684288 + 0.97731917 + 0.98739379 + 1.0033879 + 1.0159673 + 1.0269931 + 1.0436661 + 1.0492034 + 1.0765292 + 1.0784865 + 1.0971624 + 1.1171737 + 1.1193675 + 1.1526119 + 1.1550265 + 1.1585277 + 1.1560166 + 1.1671172 + 1.1706294 + 1.1805791 + 1.1786896 + 1.1756876 + 1.1820789 + 1.171211 + 1.1637997 + 1.1636684 + 1.179719 + 1.1912538 + 1.2187959 + 1.2326986 + 1.2418602 + 1.2388704 + 1.2449963 + 1.2538678 + 1.2508929 + 1.2474781 + 1.255148 + 1.274482 + 1.2862757 + 1.2813665 + 1.2888943 + 1.2787436 + 1.2678886 + 1.274325 + 1.2720952 + 1.263492 + 1.2652139 + 1.2667561 + 1.264558 + 1.2680362 + 1.2660431 + 1.2909605 + 1.2927921 + 1.288932 + 1.2910852 + 1.3012725 + 1.3048721 + 1.3196515 + 1.3181903 + 1.321309 + 1.3431543 + 1.344136 + 1.3730377 + 1.3773695 + 1.3754742 + 1.3825964 + 1.3985574 + 1.3861412 + 1.3767823 + 1.3764309 + 1.3678747 + 1.3718554 + 1.3768022 + 1.3617199 + 1.3798267 + 1.3863533 + 1.3905803 + 1.4061004 + 1.4202788 + 1.4313191 + 1.4406155 + 1.4444837 + 1.4367244 + 1.4379653 + 1.4371881 + 1.4243012 + 1.41826 + 1.4133617 + 1.40181 + 1.3965683 + 1.3865729 + 1.3855433 + 1.3755111 + 1.3758609 + 1.3962625 + 1.3994012 + 1.4083656 + 1.4233002 + 1.4037932 + 1.3973604 + 1.4095657 + 1.4095764 + 1.4080055 + 1.4095882 + 1.4108374 + 1.4164143 + 1.4283402 + 1.4343939 + 1.4392909 + 1.4406097 + 1.4468355 + 1.4412132 + 1.4305562 + 1.4252445 + 1.4103094 + 1.4059847 + 1.4141106 + 1.4429769 + 1.4489679 + 1.4559263 + 1.4593079 + 1.4627911 + 1.453154 + 1.4416665 + 1.4101485 + 1.4175823 + 1.4266407 -]; + ]; diff --git a/tests/smoother2histval/fsdat_simul.m b/tests/smoother2histval/fsdat_simul.m index face0f579b..ed7853c80b 100644 --- a/tests/smoother2histval/fsdat_simul.m +++ b/tests/smoother2histval/fsdat_simul.m @@ -1,390 +1,390 @@ gp_obs = [ - 1.0193403 - 1.0345762 - 1.0011701 - 1.0147224 - 1.008392 - 1.0488327 - 1.0153551 - 1.0099775 - 1.0260561 - 1.0172218 - 1.0014374 - 1.0184572 - 1.0179988 - 1.0060339 - 1.0019536 - 0.99179578 - 1.004346 - 1.0345153 - 1.0004432 - 0.98327074 - 1.0007585 - 1.0034378 - 1.010532 - 1.0121367 - 1.0097161 - 1.0166682 - 1.0089513 - 1.0194821 - 1.0192704 - 1.0220258 - 1.020915 - 1.0176156 - 1.0040708 - 1.0157694 - 1.0357484 - 1.0256259 - 1.0240583 - 1.0095152 - 1.0241605 - 1.0115295 - 1.003636 - 1.0222399 - 1.0250969 - 1.0068969 - 1.0009829 - 1.0166179 - 1.0252018 - 1.0211178 - 0.99867851 - 0.99594002 - 0.9908135 - 0.99762919 - 0.99616309 - 1.0058679 - 0.99323315 - 1.0132879 - 0.98718922 - 0.99739822 - 0.97858594 - 0.99128769 - 0.98624299 - 0.98447966 - 1.0013312 - 0.99189504 - 0.98032699 - 0.99332035 - 1.0129565 - 1.0007785 - 1.0218292 - 1.0030419 - 1.0044453 - 1.0156181 - 1.0040112 - 1.0081137 - 1.0261598 - 1.0053686 - 1.0024674 - 0.99883223 - 1.0224791 - 1.0074723 - 1.0037807 - 1.0348866 - 1.0053664 - 1.0140072 - 1.017359 - 1.0013916 - 1.017887 - 1.008987 - 1.011771 - 1.0201455 - 1.0249464 - 1.0159166 - 1.0162718 - 1.0312397 - 1.0108745 - 1.0132205 - 1.0142484 - 1.0178907 - 1.0065039 - 1.0190304 - 1.0034406 - 1.0053556 - 1.012823 - 1.0009983 - 1.0073148 - 1.0247254 - 1.0140215 - 1.0053603 - 1.006169 - 0.994725 - 1.026685 - 1.0012279 - 1.0160733 - 1.0119851 - 1.0148392 - 0.99760076 - 1.0070377 - 1.0066215 - 0.98130614 - 1.0127043 - 1.0203824 - 1.0067477 - 0.99510728 - 1.0188472 - 1.0100108 - 1.0146874 - 1.0118012 - 1.0111904 - 0.97759194 - 0.99081872 - 0.98425915 - 1.0026496 - 0.98587189 - 0.98648329 - 1.0035766 - 1.0094743 - 0.99460644 - 0.9953724 - 1.0194433 - 1.0065039 - 1.0056522 - 1.0160367 - 1.006524 - 1.0092492 - 0.9864426 - 0.98723638 - 0.9994522 - 1.0026778 - 1.0255529 - 1.0030477 - 0.99411719 - 1.0045087 - 0.99375289 - 1.0017609 - 1.0039766 - 0.99976299 - 1.0155671 - 1.0192975 - 1.0135507 - 1.0099869 - 1.0125994 - 1.0050808 - 1.0088531 - 1.0135256 - 1.0322097 - 1.0065808 - 0.99857526 - 1.0008792 - 0.9997691 - 1.02875 - 1.0177818 - 1.0150152 - 1.026416 - 1.0209804 - 1.010633 - 1.009636 - 1.0028257 - 0.9896666 - 1.0094002 - 0.99958414 - 1.0077797 - 0.98933606 - 1.0014885 - 0.99875283 - 1.005051 - 1.016385 - 1.0116282 - 0.99774103 - 1.0101802 - 1.0281101 - 1.0024654 - 1.0174549 -]; + 1.0193403 + 1.0345762 + 1.0011701 + 1.0147224 + 1.008392 + 1.0488327 + 1.0153551 + 1.0099775 + 1.0260561 + 1.0172218 + 1.0014374 + 1.0184572 + 1.0179988 + 1.0060339 + 1.0019536 + 0.99179578 + 1.004346 + 1.0345153 + 1.0004432 + 0.98327074 + 1.0007585 + 1.0034378 + 1.010532 + 1.0121367 + 1.0097161 + 1.0166682 + 1.0089513 + 1.0194821 + 1.0192704 + 1.0220258 + 1.020915 + 1.0176156 + 1.0040708 + 1.0157694 + 1.0357484 + 1.0256259 + 1.0240583 + 1.0095152 + 1.0241605 + 1.0115295 + 1.003636 + 1.0222399 + 1.0250969 + 1.0068969 + 1.0009829 + 1.0166179 + 1.0252018 + 1.0211178 + 0.99867851 + 0.99594002 + 0.9908135 + 0.99762919 + 0.99616309 + 1.0058679 + 0.99323315 + 1.0132879 + 0.98718922 + 0.99739822 + 0.97858594 + 0.99128769 + 0.98624299 + 0.98447966 + 1.0013312 + 0.99189504 + 0.98032699 + 0.99332035 + 1.0129565 + 1.0007785 + 1.0218292 + 1.0030419 + 1.0044453 + 1.0156181 + 1.0040112 + 1.0081137 + 1.0261598 + 1.0053686 + 1.0024674 + 0.99883223 + 1.0224791 + 1.0074723 + 1.0037807 + 1.0348866 + 1.0053664 + 1.0140072 + 1.017359 + 1.0013916 + 1.017887 + 1.008987 + 1.011771 + 1.0201455 + 1.0249464 + 1.0159166 + 1.0162718 + 1.0312397 + 1.0108745 + 1.0132205 + 1.0142484 + 1.0178907 + 1.0065039 + 1.0190304 + 1.0034406 + 1.0053556 + 1.012823 + 1.0009983 + 1.0073148 + 1.0247254 + 1.0140215 + 1.0053603 + 1.006169 + 0.994725 + 1.026685 + 1.0012279 + 1.0160733 + 1.0119851 + 1.0148392 + 0.99760076 + 1.0070377 + 1.0066215 + 0.98130614 + 1.0127043 + 1.0203824 + 1.0067477 + 0.99510728 + 1.0188472 + 1.0100108 + 1.0146874 + 1.0118012 + 1.0111904 + 0.97759194 + 0.99081872 + 0.98425915 + 1.0026496 + 0.98587189 + 0.98648329 + 1.0035766 + 1.0094743 + 0.99460644 + 0.9953724 + 1.0194433 + 1.0065039 + 1.0056522 + 1.0160367 + 1.006524 + 1.0092492 + 0.9864426 + 0.98723638 + 0.9994522 + 1.0026778 + 1.0255529 + 1.0030477 + 0.99411719 + 1.0045087 + 0.99375289 + 1.0017609 + 1.0039766 + 0.99976299 + 1.0155671 + 1.0192975 + 1.0135507 + 1.0099869 + 1.0125994 + 1.0050808 + 1.0088531 + 1.0135256 + 1.0322097 + 1.0065808 + 0.99857526 + 1.0008792 + 0.9997691 + 1.02875 + 1.0177818 + 1.0150152 + 1.026416 + 1.0209804 + 1.010633 + 1.009636 + 1.0028257 + 0.9896666 + 1.0094002 + 0.99958414 + 1.0077797 + 0.98933606 + 1.0014885 + 0.99875283 + 1.005051 + 1.016385 + 1.0116282 + 0.99774103 + 1.0101802 + 1.0281101 + 1.0024654 + 1.0174549 + ]; gy_obs = [ - 1.0114349 - 0.95979862 - 1.0203958 - 1.0071401 - 1.0539221 - 0.95944922 - 1.0051974 - 1.0354593 - 0.98747321 - 1.02788 - 1.0112772 - 1.0052673 - 1.0104239 - 1.013491 - 1.0066127 - 1.0173802 - 0.98273662 - 0.95581791 - 1.0353011 - 1.0346887 - 0.9785853 - 1.0039954 - 0.99275146 - 1.0031733 - 1.0276747 - 0.978159 - 0.98248359 - 1.0192328 - 0.99057865 - 0.99776689 - 0.98890201 - 1.0163644 - 1.0300873 - 0.96109456 - 0.98850646 - 1.0115635 - 1.0010548 - 0.98951687 - 0.98151347 - 1.0106021 - 1.0310697 - 0.990769 - 0.97940286 - 1.0279158 - 1.0070844 - 0.97456591 - 1.0235486 - 0.99211813 - 0.99808011 - 1.0038972 - 1.0178385 - 1.0008656 - 1.0012176 - 1.0120603 - 1.0277974 - 0.95512181 - 1.0341867 - 1.0291133 - 1.0062875 - 0.99385308 - 1.0518127 - 1.0167908 - 0.97311489 - 1.0324251 - 1.0185255 - 0.98698556 - 0.97985038 - 1.0220522 - 0.98358428 - 1.0085008 - 1.0095106 - 0.96544852 - 1.0014508 - 0.99673838 - 0.9703847 - 1.0245765 - 1.0031506 - 1.009074 - 0.98601129 - 0.99799441 - 1.0078514 - 0.98192982 - 1.0371426 - 0.97563731 - 0.99473616 - 0.99510009 - 0.98135322 - 1.0224481 - 0.99779603 - 0.98590478 - 0.98366338 - 0.99767204 - 1.0208174 - 0.97633411 - 1.0138123 - 1.0032682 - 0.99039426 - 1.0087413 - 1.0285208 - 0.98783907 - 1.0007856 - 1.0265034 - 0.99713746 - 1.0032946 - 1.0027628 - 0.99316893 - 0.99241067 - 0.99845423 - 1.0057718 - 1.029354 - 0.9717329 - 1.0218727 - 0.98185255 - 0.99861261 - 1.0114349 - 1.0052126 - 0.9852852 - 0.99669175 - 1.0131849 - 0.99253202 - 0.98255644 - 1.0164264 - 1.0070027 - 0.99306997 - 1.004557 - 0.99064231 - 1.0100364 - 0.99857545 - 1.0365648 - 1.0323947 - 0.99584546 - 0.98641189 - 1.0200377 - 1.0167671 - 0.99615647 - 1.0067481 - 1.0201624 - 1.0012265 - 0.97564063 - 1.0141995 - 1.0260671 - 0.99697599 - 1.0127951 - 0.98922525 - 1.0268872 - 1.0048837 - 1.0124301 - 1.0020776 - 0.95526625 - 0.98592847 - 1.0303405 - 1.007508 - 1.0041718 - 1.0039668 - 1.0119603 - 1.0153073 - 0.99318888 - 0.96711969 - 0.99946578 - 1.0307262 - 0.97737468 - 1.0029169 - 1.0148043 - 0.97950296 - 0.97038701 - 1.010492 - 1.0087364 - 0.99717614 - 1.0375848 - 0.94419511 - 0.98325812 - 1.0350878 - 0.99049883 - 0.98795832 - 1.0191223 - 1.0148155 - 0.97941641 - 1.0395356 - 1.0005804 - 0.99178697 - 1.0024326 - 1.0312638 - 1.0100942 - 0.98526311 - 1.0029873 - 0.9836127 - 0.99747718 - 1.0193064 - 0.99270511 - 0.96646656 - 1.0575586 - 0.98945919 -]; + 1.0114349 + 0.95979862 + 1.0203958 + 1.0071401 + 1.0539221 + 0.95944922 + 1.0051974 + 1.0354593 + 0.98747321 + 1.02788 + 1.0112772 + 1.0052673 + 1.0104239 + 1.013491 + 1.0066127 + 1.0173802 + 0.98273662 + 0.95581791 + 1.0353011 + 1.0346887 + 0.9785853 + 1.0039954 + 0.99275146 + 1.0031733 + 1.0276747 + 0.978159 + 0.98248359 + 1.0192328 + 0.99057865 + 0.99776689 + 0.98890201 + 1.0163644 + 1.0300873 + 0.96109456 + 0.98850646 + 1.0115635 + 1.0010548 + 0.98951687 + 0.98151347 + 1.0106021 + 1.0310697 + 0.990769 + 0.97940286 + 1.0279158 + 1.0070844 + 0.97456591 + 1.0235486 + 0.99211813 + 0.99808011 + 1.0038972 + 1.0178385 + 1.0008656 + 1.0012176 + 1.0120603 + 1.0277974 + 0.95512181 + 1.0341867 + 1.0291133 + 1.0062875 + 0.99385308 + 1.0518127 + 1.0167908 + 0.97311489 + 1.0324251 + 1.0185255 + 0.98698556 + 0.97985038 + 1.0220522 + 0.98358428 + 1.0085008 + 1.0095106 + 0.96544852 + 1.0014508 + 0.99673838 + 0.9703847 + 1.0245765 + 1.0031506 + 1.009074 + 0.98601129 + 0.99799441 + 1.0078514 + 0.98192982 + 1.0371426 + 0.97563731 + 0.99473616 + 0.99510009 + 0.98135322 + 1.0224481 + 0.99779603 + 0.98590478 + 0.98366338 + 0.99767204 + 1.0208174 + 0.97633411 + 1.0138123 + 1.0032682 + 0.99039426 + 1.0087413 + 1.0285208 + 0.98783907 + 1.0007856 + 1.0265034 + 0.99713746 + 1.0032946 + 1.0027628 + 0.99316893 + 0.99241067 + 0.99845423 + 1.0057718 + 1.029354 + 0.9717329 + 1.0218727 + 0.98185255 + 0.99861261 + 1.0114349 + 1.0052126 + 0.9852852 + 0.99669175 + 1.0131849 + 0.99253202 + 0.98255644 + 1.0164264 + 1.0070027 + 0.99306997 + 1.004557 + 0.99064231 + 1.0100364 + 0.99857545 + 1.0365648 + 1.0323947 + 0.99584546 + 0.98641189 + 1.0200377 + 1.0167671 + 0.99615647 + 1.0067481 + 1.0201624 + 1.0012265 + 0.97564063 + 1.0141995 + 1.0260671 + 0.99697599 + 1.0127951 + 0.98922525 + 1.0268872 + 1.0048837 + 1.0124301 + 1.0020776 + 0.95526625 + 0.98592847 + 1.0303405 + 1.007508 + 1.0041718 + 1.0039668 + 1.0119603 + 1.0153073 + 0.99318888 + 0.96711969 + 0.99946578 + 1.0307262 + 0.97737468 + 1.0029169 + 1.0148043 + 0.97950296 + 0.97038701 + 1.010492 + 1.0087364 + 0.99717614 + 1.0375848 + 0.94419511 + 0.98325812 + 1.0350878 + 0.99049883 + 0.98795832 + 1.0191223 + 1.0148155 + 0.97941641 + 1.0395356 + 1.0005804 + 0.99178697 + 1.0024326 + 1.0312638 + 1.0100942 + 0.98526311 + 1.0029873 + 0.9836127 + 0.99747718 + 1.0193064 + 0.99270511 + 0.96646656 + 1.0575586 + 0.98945919 + ]; diff --git a/tests/steady_state/walsh1_old_ss_steadystate.m b/tests/steady_state/walsh1_old_ss_steadystate.m index 9530862643..e419a00ace 100644 --- a/tests/steady_state/walsh1_old_ss_steadystate.m +++ b/tests/steady_state/walsh1_old_ss_steadystate.m @@ -4,42 +4,42 @@ global M_ % read out parameters to access them with their name NumberOfParameters = M_.param_nbr; for ii = 1:NumberOfParameters - paramname = deblank(M_.param_names(ii,:)); - eval([ paramname ' = M_.params(' int2str(ii) ');']); + paramname = deblank(M_.param_names(ii,:)); + eval([ paramname ' = M_.params(' int2str(ii) ');']); end % initialize indicator check = 0; %% Enter model equations here - - pi = thetass-1; - en = 1/3; - eR = 1/betta; - y_k = (1/alphha)*(1/betta-1+delta); - ek = en*y_k^(-1/(1-alphha)); - ec = ek*(y_k-delta); - em = ec*(a/(1-a))^(-1/b)*((thetass-betta)/thetass)^(-1/b); - ey = ek*y_k; - Xss = a*ec^(1-b)*(1+(a/(1-a))^(-1/b)*((thetass-betta)/thetass)^((b-1)/b)); - Psi = (1-alphha)*(ey/en)*Xss^((b-phi1)/(1-b))*a*ec^(-b)*(1-en)^eta; - n = log(en); - k = log(ek); - m = log(em); - c = log(ec); - y = log(ey); - R = log(eR); - z = 0; - u = 0; - + +pi = thetass-1; +en = 1/3; +eR = 1/betta; +y_k = (1/alphha)*(1/betta-1+delta); +ek = en*y_k^(-1/(1-alphha)); +ec = ek*(y_k-delta); +em = ec*(a/(1-a))^(-1/b)*((thetass-betta)/thetass)^(-1/b); +ey = ek*y_k; +Xss = a*ec^(1-b)*(1+(a/(1-a))^(-1/b)*((thetass-betta)/thetass)^((b-1)/b)); +Psi = (1-alphha)*(ey/en)*Xss^((b-phi1)/(1-b))*a*ec^(-b)*(1-en)^eta; +n = log(en); +k = log(ek); +m = log(em); +c = log(ec); +y = log(ey); +R = log(eR); +z = 0; +u = 0; + %% end own model equations for iter = 1:length(M_.params) %update parameters set in the file - eval([ 'M_.params(' num2str(iter) ') = ' M_.param_names(iter,:) ';' ]) + eval([ 'M_.params(' num2str(iter) ') = ' M_.param_names(iter,:) ';' ]) end NumberOfEndogenousVariables = M_.orig_endo_nbr; %auxiliary variables are set automatically for ii = 1:NumberOfEndogenousVariables - varname = deblank(M_.endo_names(ii,:)); - eval(['ys(' int2str(ii) ') = ' varname ';']); + varname = deblank(M_.endo_names(ii,:)); + eval(['ys(' int2str(ii) ') = ' varname ';']); end -- GitLab