| 66 /// Iterations between merging heuristic tries |
66 /// Iterations between merging heuristic tries |
| 67 pub merge_every: usize, |
67 pub merge_every: usize, |
| 68 |
68 |
| 69 /// Additional weight optimisation steps |
69 /// Additional weight optimisation steps |
| 70 pub extra_weight_optimisation_steps: usize, |
70 pub extra_weight_optimisation_steps: usize, |
| |
71 |
| |
72 /// Maximum iteration for scaling hack, zero if no maximum. |
| |
73 pub max_scaling_iter: usize, |
| 71 } |
74 } |
| 72 |
75 |
| 73 #[replace_float_literals(F::cast_from(literal))] |
76 #[replace_float_literals(F::cast_from(literal))] |
| 74 impl<F: Float> Default for InsertionConfig<F> { |
77 impl<F: Float> Default for InsertionConfig<F> { |
| 75 fn default() -> Self { |
78 fn default() -> Self { |
| 85 final_merging: true, |
88 final_merging: true, |
| 86 fitness_merging: false, |
89 fitness_merging: false, |
| 87 merge_every: 10, |
90 merge_every: 10, |
| 88 merge_tolerance_mult: 2.0, |
91 merge_tolerance_mult: 2.0, |
| 89 extra_weight_optimisation_steps: 0, |
92 extra_weight_optimisation_steps: 0, |
| |
93 max_scaling_iter: 0, |
| 90 } |
94 } |
| 91 } |
95 } |
| 92 } |
96 } |
| 93 |
97 |
| 94 impl<F: Float> InsertionConfig<F> { |
98 impl<F: Float> InsertionConfig<F> { |
| 95 /// Check if merging should be attempted this iteration |
99 /// Check if merging should be attempted this iteration |
| 96 pub fn merge_now<I: AlgIterator>(&self, state: &AlgIteratorIteration<I>) -> bool { |
100 pub fn if_merge_now<I: AlgIterator, A>( |
| 97 self.merging.enabled && state.iteration() % self.merge_every == 0 |
101 &self, |
| |
102 state: &AlgIteratorIteration<I>, |
| |
103 mut f: impl FnMut(&Self) -> A, |
| |
104 ) -> Option<A> { |
| |
105 if (self.merging.enabled || self.merging.scaling.is_some()) |
| |
106 && state.iteration() % self.merge_every == 0 |
| |
107 { |
| |
108 if self.max_scaling_iter != 0 && state.iteration() > self.max_scaling_iter { |
| |
109 if !self.merging.enabled { |
| |
110 None |
| |
111 } else { |
| |
112 Some(f(&InsertionConfig { |
| |
113 merging: SpikeMergingMethod { scaling: None, ..self.merging }, |
| |
114 ..*self |
| |
115 })) |
| |
116 } |
| |
117 } else { |
| |
118 Some(f(self)) |
| |
119 } |
| |
120 } else { |
| |
121 None |
| |
122 } |
| 98 } |
123 } |
| 99 |
124 |
| 100 /// Returns the final merging method |
125 /// Returns the final merging method |
| 101 pub fn final_merging_method(&self) -> SpikeMergingMethod<F> { |
126 pub fn final_merging_method(&self) -> SpikeMergingMethod<F> { |
| 102 SpikeMergingMethod { enabled: self.final_merging, ..self.merging } |
127 SpikeMergingMethod { enabled: self.final_merging, scaling: None, ..self.merging } |
| 103 } |
128 } |
| 104 } |
129 } |
| 105 |
130 |
| 106 /// Available proximal terms |
131 /// Available proximal terms |
| 107 #[derive(Copy, Clone, Debug, Serialize, Deserialize, Eq, PartialEq)] |
132 #[derive(Copy, Clone, Debug, Serialize, Deserialize, Eq, PartialEq)] |