@@ -32,6 +32,7 @@ pub struct GlobalStrategy<M: Math, A: MassMatrixAdaptStrategy<M>> {
32
32
final_step_size_window : u64 ,
33
33
tuning : bool ,
34
34
has_initial_mass_matrix : bool ,
35
+ last_update : u64 ,
35
36
}
36
37
37
38
#[ derive( Debug , Clone , Copy ) ]
@@ -42,6 +43,7 @@ pub struct AdaptOptions<S: Debug + Default> {
42
43
pub step_size_window : f64 ,
43
44
pub mass_matrix_switch_freq : u64 ,
44
45
pub early_mass_matrix_switch_freq : u64 ,
46
+ pub mass_matrix_update_freq : u64 ,
45
47
}
46
48
47
49
impl < S : Debug + Default > Default for AdaptOptions < S > {
@@ -53,6 +55,7 @@ impl<S: Debug + Default> Default for AdaptOptions<S> {
53
55
step_size_window : 0.15 ,
54
56
mass_matrix_switch_freq : 80 ,
55
57
early_mass_matrix_switch_freq : 10 ,
58
+ mass_matrix_update_freq : 1 ,
56
59
}
57
60
}
58
61
}
@@ -104,6 +107,7 @@ impl<M: Math, A: MassMatrixAdaptStrategy<M>> AdaptStrategy<M> for GlobalStrategy
104
107
final_step_size_window : final_second_step_size,
105
108
tuning : true ,
106
109
has_initial_mass_matrix : true ,
110
+ last_update : 0 ,
107
111
}
108
112
}
109
113
@@ -150,10 +154,24 @@ impl<M: Math, A: MassMatrixAdaptStrategy<M>> AdaptStrategy<M> for GlobalStrategy
150
154
// the switch frequency.
151
155
let could_switch = self . mass_matrix . background_count ( ) >= switch_freq;
152
156
let is_late = switch_freq + draw > self . final_step_size_window ;
157
+
158
+ let mut force_update = false ;
153
159
if could_switch && ( !is_late) {
154
160
self . mass_matrix . switch ( math) ;
161
+ force_update = true ;
162
+ }
163
+
164
+ let did_change = if force_update
165
+ | ( draw - self . last_update >= self . options . mass_matrix_update_freq )
166
+ {
167
+ self . mass_matrix . update_potential ( math, potential)
168
+ } else {
169
+ false
170
+ } ;
171
+
172
+ if did_change {
173
+ self . last_update = draw;
155
174
}
156
- let did_change = self . mass_matrix . update_potential ( math, potential) ;
157
175
if is_late {
158
176
self . step_size . use_mean_sym ( ) ;
159
177
}
0 commit comments