Debian Codegraph @

contrib/ms-sbvar/switch_dw/switching/dw_metropolis_theta.h

raw
1 /*
2 * Copyright (C) 1996-2011 Daniel Waggoner and Tao Zha
3 *
4 * This free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * It is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * If you did not received a copy of the GNU General Public License
15 * with this software, see <http://www.gnu.org/licenses/>.
16 */
17
18 #ifndef __dw_metropolis_theta__
19 #define __dw_metropolis_theta__
20
21 #include "dw_matrix.h"
22 #include "dw_switch.h"
23
24 #ifdef __cplusplus
25 extern "C"
26 {
27 #endif
28
29 /*******************************************************************************/
30 /**************************** TMetropolis Structure ****************************/
31 /*******************************************************************************/
32 typedef struct TMetropolis_theta_tag
33 {
34 //=== Metropolis parameters ===
35 int n_parameters;
36 int n_blocks;
37 int *block_dims;
38 int *block_offsets;
39 TVector scale;
40 TVector *direction;
41
42 //=== Simulation status fields ===
43 int *jumps;
44 int *draws;
45
46 } TMetropolis_theta;
47
48 TMetropolis_theta* Create_metropolis_theta(int n_parameters);
49 void Free_metropolis_theta(TMetropolis_theta *metropolis);
50
51 void Setup_metropolis_theta(TMetropolis_theta *metropolis, TVector scale, TVector *directions);
52 void Setup_metropolis_theta_diagonal(TMetropolis_theta *metropolis);
53 void Setup_metropolis_theta_hessian(TMetropolis_theta *metropolis, TMatrix hessian);
54 void Setup_metropolis_theta_variance(TMetropolis_theta *metropolis, TMatrix hessian);
55
56 void Setup_metropolis_theta_blocks(TMetropolis_theta *metropolis, int n_blocks, int *dims);
57 void Setup_metropolis_theta_blocks_full(TMetropolis_theta *metropolis);
58 void Setup_metropolis_theta_blocks_single(TMetropolis_theta *metropolis);
59
60 void ResetCounts_metropolis_theta(TMetropolis_theta *metropolis);
61
62 void Draw_metropolis_theta(TStateModel *model);
63 void Draw_metropolis_theta_single_block(int block, TStateModel *model);
64
65 void AdaptiveScale_metropolis_theta(TStateModel *model, PRECISION mid, int period, int max_period, int verbose);
66 void AdaptiveScale_metropolis_theta_single_block(int block, TStateModel *model, PRECISION mid, int period, int max_period, int verbose);
67
68 void Calibrate_metropolis_theta(TStateModel *model, PRECISION center, int period, int max_period, int verbose);
69 int Calibrate_metropolis_theta_single_direction(int idx, TStateModel *model, PRECISION center, int period, int max_period, int verbose);
70 int Calibrate_metropolis_theta_two_pass(TStateModel *model, PRECISION center_s, int period_s, int max_period_s,
71 PRECISION center_a, int period_a, int max_period_a, int verbose);
72
73
74 /*******************************************************************************/
75 /****************************** Adaptive Scaling *******************************/
76 /*******************************************************************************/
77 //=== Adaptive scaling
78 typedef struct
79 {
80 int period;
81 int begin_draws;
82 int end_draws;
83 int begin_jumps;
84 PRECISION previous_ratio;
85 PRECISION scale;
86 PRECISION best_scale;
87 PRECISION low_scale;
88 PRECISION low_jump_ratio;
89 PRECISION high_scale;
90 PRECISION high_jump_ratio;
91
92 PRECISION mid;
93 PRECISION log_mid;
94 PRECISION lower_bound;
95 PRECISION upper_bound;
96
97 } TAdaptive;
98 TAdaptive* CreateAdaptive(PRECISION mid);
99 void SetAdaptiveCenter(PRECISION mid, TAdaptive *adaptive);
100 void InitializeAdaptive(int period, int block, TAdaptive *adaptive, TMetropolis_theta *metropolis);
101 PRECISION RecomputeScale(int end_jumps, int end_draws, TAdaptive *adaptive);
102 void PrintJumpingInfo(int b, TAdaptive *adaptive, TMetropolis_theta *metropolis);
103
104 #ifdef __cplusplus
105 }
106 #endif
107
108 #endif