src/regularisation.rs

changeset 98
b9818eb24b47
parent 92
759634edb536
child 99
82e3cb274186
equal deleted inserted replaced
97:f91f382ba4ae 98:b9818eb24b47
146 config: &InsertionConfig<F>, 146 config: &InsertionConfig<F>,
147 ) -> Option<(Domain, F, bool)> 147 ) -> Option<(Domain, F, bool)>
148 where 148 where
149 M: MinMaxMapping<Domain, F>; 149 M: MinMaxMapping<Domain, F>;
150 150
151 /// Returns the minimum distance of the subdifferential of $τ[F+R]$ to zero,
152 /// where $F$ is the smooth data term (differential given in `τv/τ`), and $R$ is
153 /// this regulariser.
154 fn discrepancy<M>(
155 &self,
156 τv: &mut M,
157 τ: F,
158 ε: F,
159 μ: &DiscreteMeasure<Domain, F>,
160 config: &InsertionConfig<F>,
161 ) -> F
162 where
163 M: MinMaxMapping<Domain, F>;
164
151 /// Verify that `d` is in bounds `ε` for a merge candidate `μ` 165 /// Verify that `d` is in bounds `ε` for a merge candidate `μ`
152 /// 166 ///
153 /// `ε` is the current main tolerance and `τ` a scaling factor for the regulariser. 167 /// `ε` is the current main tolerance and `τ` a scaling factor for the regulariser.
154 fn verify_merge_candidate<M>( 168 fn verify_merge_candidate<M>(
155 &self, 169 &self,
286 config.refinement.max_steps, 300 config.refinement.max_steps,
287 ); 301 );
288 302
289 res.map(|(ξ, v_ξ)| (ξ, v_ξ, v_ξ >= keep_above)) 303 res.map(|(ξ, v_ξ)| (ξ, v_ξ, v_ξ >= keep_above))
290 } 304 }
305 }
306
307 fn discrepancy<M>(
308 &self,
309 τv: &mut M,
310 τ: F,
311 ε: F,
312 μ: &DiscreteMeasure<Loc<N, F>, F>,
313 config: &InsertionConfig<F>,
314 ) -> F
315 where
316 M: MinMaxMapping<Loc<N, F>, F>,
317 {
318 let refinement_tolerance = ε * config.refinement.tolerance_mult;
319 let τα = self.α()*τ;
320
321 let μ_disrepancy = μ
322 .iter_spikes()
323 .map(|δ| {
324 let v = τv.apply(&δ.x);
325 if δ.α > 0.0 {
326 (v + τα).abs()
327 } else {
328 (-v - τα).max(0.0)
329 }
330 })
331 .reduce(F::max)
332 .unwrap_or(0.0);
333
334 let (_, τv_min) = τv.minimise(refinement_tolerance, config.refinement.max_steps);
335 //let rest_discrepancy = (-d_min - self.α()).max(0.0);
336 //return rest_discrepancy.max(μ_disrepancy)
337 // Simplifies to
338 return (-τv_min - τα).max(μ_disrepancy);
291 } 339 }
292 340
293 fn verify_merge_candidate<M>( 341 fn verify_merge_candidate<M>(
294 &self, 342 &self,
295 d: &mut M, 343 d: &mut M,
528 Some((ζ, v_ζ, keep_above <= v_ζ)) 576 Some((ζ, v_ζ, keep_above <= v_ζ))
529 } 577 }
530 } 578 }
531 } 579 }
532 } 580 }
581 }
582
583 fn discrepancy<M>(
584 &self,
585 τv: &mut M,
586 τ: F,
587 ε: F,
588 μ: &DiscreteMeasure<Loc<N, F>, F>,
589 config: &InsertionConfig<F>,
590 ) -> F
591 where
592 M: MinMaxMapping<Loc<N, F>, F>,
593 {
594 use std::cmp::Ordering::*;
595 let refinement_tolerance = ε * config.refinement.tolerance_mult;
596 let τα = τ * self.α();
597
598 let threshold = |v: F, α: F| {
599 if v > α {
600 v - α
601 } else if v < -α {
602 -v - α
603 } else {
604 0.0
605 }
606 };
607
608 let μ_disrepancy = μ
609 .iter_spikes()
610 .map(|δ| {
611 let v = τv.apply(&δ.x);
612 match δ.α.total_cmp(&0.0) {
613 Greater => (v + τα).abs(),
614 Less => (v - τα).abs(),
615 Equal => threshold(v, τα),
616 }
617 })
618 .reduce(F::max)
619 .unwrap_or(0.0);
620
621 let (_, τv_min) = τv.minimise(refinement_tolerance, config.refinement.max_steps);
622 let (_, τv_max) = τv.maximise(refinement_tolerance, config.refinement.max_steps);
623 //let rest_discrepancy = (-d_min - α).max(0.0);
624 //return rest_discrepancy.max(μ_disrepancy)
625 // Simplifies to
626 return threshold(τv_min, τα)
627 .max(threshold(τv_max, τα))
628 .max(μ_disrepancy);
533 } 629 }
534 630
535 fn verify_merge_candidate<M>( 631 fn verify_merge_candidate<M>(
536 &self, 632 &self,
537 d: &mut M, 633 d: &mut M,

mercurial