Thu, 29 Aug 2024 00:00:00 -0500
Radon FB + sliding improvements
| 0 | 1 | /*! |
| 2 | This module provides [`RunnableExperiment`] for running chosen algorithms on a chosen experiment. | |
| 3 | */ | |
| 4 | ||
| 5 | use numeric_literals::replace_float_literals; | |
| 6 | use colored::Colorize; | |
| 7 | use serde::{Serialize, Deserialize}; | |
| 8 | use serde_json; | |
| 9 | use nalgebra::base::DVector; | |
| 10 | use std::hash::Hash; | |
| 11 | use chrono::{DateTime, Utc}; | |
| 12 | use cpu_time::ProcessTime; | |
| 13 | use clap::ValueEnum; | |
| 14 | use std::collections::HashMap; | |
| 15 | use std::time::Instant; | |
| 16 | ||
| 17 | use rand::prelude::{ | |
| 18 | StdRng, | |
| 19 | SeedableRng | |
| 20 | }; | |
| 21 | use rand_distr::Distribution; | |
| 22 | ||
| 23 | use alg_tools::bisection_tree::*; | |
| 24 | use alg_tools::iterate::{ | |
| 25 | Timed, | |
| 26 | AlgIteratorOptions, | |
| 27 | Verbose, | |
| 28 | AlgIteratorFactory, | |
| 29 | }; | |
| 30 | use alg_tools::logger::Logger; | |
| 31 | use alg_tools::error::DynError; | |
| 32 | use alg_tools::tabledump::TableDump; | |
| 33 | use alg_tools::sets::Cube; | |
|
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
34 | use alg_tools::mapping::{ |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
35 | RealMapping, |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
36 | DifferentiableRealMapping |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
37 | }; |
| 0 | 38 | use alg_tools::nalgebra_support::ToNalgebraRealField; |
| 39 | use alg_tools::euclidean::Euclidean; | |
| 40 | use alg_tools::lingrid::lingrid; | |
| 41 | use alg_tools::sets::SetOrd; | |
| 42 | ||
| 43 | use crate::kernels::*; | |
| 44 | use crate::types::*; | |
| 45 | use crate::measures::*; | |
| 46 | use crate::measures::merging::SpikeMerging; | |
| 47 | use crate::forward_model::*; | |
| 48 | use crate::fb::{ | |
| 49 | FBConfig, | |
| 32 | 50 | FBGenericConfig, |
|
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
51 | pointsource_fb_reg, |
| 32 | 52 | pointsource_fista_reg, |
| 53 | }; | |
|
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
54 | use crate::radon_fb::{ |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
55 | RadonFBConfig, |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
56 | pointsource_radon_fb_reg, |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
57 | pointsource_radon_fista_reg, |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
58 | }; |
| 32 | 59 | use crate::sliding_fb::{ |
| 60 | SlidingFBConfig, | |
| 61 | pointsource_sliding_fb_reg | |
| 0 | 62 | }; |
| 63 | use crate::pdps::{ | |
| 64 | PDPSConfig, | |
|
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
65 | pointsource_pdps_reg, |
| 0 | 66 | }; |
| 67 | use crate::frank_wolfe::{ | |
| 68 | FWConfig, | |
| 69 | FWVariant, | |
|
25
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
70 | pointsource_fw_reg, |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
71 | WeightOptim, |
| 0 | 72 | }; |
| 73 | use crate::subproblem::InnerSettings; | |
| 74 | use crate::seminorms::*; | |
| 75 | use crate::plot::*; | |
|
9
21b0e537ac0e
Command line parameter passing simplifications and make `-o` required.
Tuomo Valkonen <tuomov@iki.fi>
parents:
0
diff
changeset
|
76 | use crate::{AlgorithmOverrides, CommandLineArgs}; |
|
20
90f77ad9a98d
Added command line option for (power) tolerance
Tuomo Valkonen <tuomov@iki.fi>
parents:
9
diff
changeset
|
77 | use crate::tolerance::Tolerance; |
| 32 | 78 | use crate::regularisation::{ |
| 79 | Regularisation, | |
| 80 | RadonRegTerm, | |
| 81 | NonnegRadonRegTerm | |
| 82 | }; | |
| 83 | use crate::dataterm::{ | |
| 84 | L1, | |
| 85 | L2Squared | |
| 86 | }; | |
| 87 | use alg_tools::norms::L2; | |
| 0 | 88 | |
| 89 | /// Available algorithms and their configurations | |
| 90 | #[derive(Copy, Clone, Debug, Serialize, Deserialize)] | |
| 91 | pub enum AlgorithmConfig<F : Float> { | |
| 92 | FB(FBConfig<F>), | |
| 32 | 93 | FISTA(FBConfig<F>), |
| 0 | 94 | FW(FWConfig<F>), |
| 95 | PDPS(PDPSConfig<F>), | |
|
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
96 | RadonFB(RadonFBConfig<F>), |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
97 | RadonFISTA(RadonFBConfig<F>), |
| 32 | 98 | SlidingFB(SlidingFBConfig<F>), |
| 0 | 99 | } |
| 100 | ||
|
20
90f77ad9a98d
Added command line option for (power) tolerance
Tuomo Valkonen <tuomov@iki.fi>
parents:
9
diff
changeset
|
101 | fn unpack_tolerance<F : Float>(v : &Vec<F>) -> Tolerance<F> { |
|
90f77ad9a98d
Added command line option for (power) tolerance
Tuomo Valkonen <tuomov@iki.fi>
parents:
9
diff
changeset
|
102 | assert!(v.len() == 3); |
|
90f77ad9a98d
Added command line option for (power) tolerance
Tuomo Valkonen <tuomov@iki.fi>
parents:
9
diff
changeset
|
103 | Tolerance::Power { initial : v[0], factor : v[1], exponent : v[2] } |
|
90f77ad9a98d
Added command line option for (power) tolerance
Tuomo Valkonen <tuomov@iki.fi>
parents:
9
diff
changeset
|
104 | } |
|
90f77ad9a98d
Added command line option for (power) tolerance
Tuomo Valkonen <tuomov@iki.fi>
parents:
9
diff
changeset
|
105 | |
| 0 | 106 | impl<F : ClapFloat> AlgorithmConfig<F> { |
| 107 | /// Override supported parameters based on the command line. | |
| 108 | pub fn cli_override(self, cli : &AlgorithmOverrides<F>) -> Self { | |
| 109 | let override_fb_generic = |g : FBGenericConfig<F>| { | |
| 110 | FBGenericConfig { | |
| 111 | bootstrap_insertions : cli.bootstrap_insertions | |
| 112 | .as_ref() | |
| 113 | .map_or(g.bootstrap_insertions, | |
| 114 | |n| Some((n[0], n[1]))), | |
| 115 | merge_every : cli.merge_every.unwrap_or(g.merge_every), | |
| 116 | merging : cli.merging.clone().unwrap_or(g.merging), | |
| 117 | final_merging : cli.final_merging.clone().unwrap_or(g.final_merging), | |
|
20
90f77ad9a98d
Added command line option for (power) tolerance
Tuomo Valkonen <tuomov@iki.fi>
parents:
9
diff
changeset
|
118 | tolerance: cli.tolerance.as_ref().map(unpack_tolerance).unwrap_or(g.tolerance), |
| 0 | 119 | .. g |
| 120 | } | |
| 121 | }; | |
| 122 | ||
| 123 | use AlgorithmConfig::*; | |
| 124 | match self { | |
| 125 | FB(fb) => FB(FBConfig { | |
| 126 | τ0 : cli.tau0.unwrap_or(fb.τ0), | |
|
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
127 | generic : override_fb_generic(fb.generic), |
| 0 | 128 | .. fb |
| 129 | }), | |
| 32 | 130 | FISTA(fb) => FISTA(FBConfig { |
| 131 | τ0 : cli.tau0.unwrap_or(fb.τ0), | |
|
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
132 | generic : override_fb_generic(fb.generic), |
| 32 | 133 | .. fb |
| 134 | }), | |
| 0 | 135 | PDPS(pdps) => PDPS(PDPSConfig { |
| 136 | τ0 : cli.tau0.unwrap_or(pdps.τ0), | |
| 137 | σ0 : cli.sigma0.unwrap_or(pdps.σ0), | |
| 138 | acceleration : cli.acceleration.unwrap_or(pdps.acceleration), | |
|
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
139 | generic : override_fb_generic(pdps.generic), |
| 0 | 140 | .. pdps |
| 141 | }), | |
| 142 | FW(fw) => FW(FWConfig { | |
| 143 | merging : cli.merging.clone().unwrap_or(fw.merging), | |
|
20
90f77ad9a98d
Added command line option for (power) tolerance
Tuomo Valkonen <tuomov@iki.fi>
parents:
9
diff
changeset
|
144 | tolerance : cli.tolerance.as_ref().map(unpack_tolerance).unwrap_or(fw.tolerance), |
| 0 | 145 | .. fw |
| 32 | 146 | }), |
|
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
147 | RadonFB(fb) => RadonFB(RadonFBConfig { |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
148 | τ0 : cli.tau0.unwrap_or(fb.τ0), |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
149 | insertion : override_fb_generic(fb.insertion), |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
150 | .. fb |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
151 | }), |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
152 | RadonFISTA(fb) => RadonFISTA(RadonFBConfig { |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
153 | τ0 : cli.tau0.unwrap_or(fb.τ0), |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
154 | insertion : override_fb_generic(fb.insertion), |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
155 | .. fb |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
156 | }), |
| 32 | 157 | SlidingFB(sfb) => SlidingFB(SlidingFBConfig { |
| 158 | τ0 : cli.tau0.unwrap_or(sfb.τ0), | |
|
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
159 | θ0 : cli.theta0.unwrap_or(sfb.θ0), |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
160 | transport_tolerance_ω: cli.transport_tolerance_omega.unwrap_or(sfb.transport_tolerance_ω), |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
161 | transport_tolerance_dv: cli.transport_tolerance_dv.unwrap_or(sfb.transport_tolerance_dv), |
| 32 | 162 | insertion : override_fb_generic(sfb.insertion), |
| 163 | .. sfb | |
| 164 | }), | |
| 0 | 165 | } |
| 166 | } | |
| 167 | } | |
| 168 | ||
| 169 | /// Helper struct for tagging and [`AlgorithmConfig`] or [`Experiment`] with a name. | |
| 170 | #[derive(Clone, Debug, Serialize, Deserialize)] | |
| 171 | pub struct Named<Data> { | |
| 172 | pub name : String, | |
| 173 | #[serde(flatten)] | |
| 174 | pub data : Data, | |
| 175 | } | |
| 176 | ||
| 177 | /// Shorthand algorithm configurations, to be used with the command line parser | |
|
9
21b0e537ac0e
Command line parameter passing simplifications and make `-o` required.
Tuomo Valkonen <tuomov@iki.fi>
parents:
0
diff
changeset
|
178 | #[derive(ValueEnum, Debug, Copy, Clone, Eq, PartialEq, Hash, Serialize, Deserialize)] |
| 0 | 179 | pub enum DefaultAlgorithm { |
| 180 | /// The μFB forward-backward method | |
| 181 | #[clap(name = "fb")] | |
| 182 | FB, | |
| 183 | /// The μFISTA inertial forward-backward method | |
| 184 | #[clap(name = "fista")] | |
| 185 | FISTA, | |
| 186 | /// The “fully corrective” conditional gradient method | |
| 187 | #[clap(name = "fw")] | |
| 188 | FW, | |
| 189 | /// The “relaxed conditional gradient method | |
| 190 | #[clap(name = "fwrelax")] | |
| 191 | FWRelax, | |
| 192 | /// The μPDPS primal-dual proximal splitting method | |
| 193 | #[clap(name = "pdps")] | |
| 194 | PDPS, | |
|
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
195 | /// The RadonFB forward-backward method |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
196 | #[clap(name = "radon_fb")] |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
197 | RadonFB, |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
198 | /// The RadonFISTA inertial forward-backward method |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
199 | #[clap(name = "radon_fista")] |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
200 | RadonFISTA, |
| 32 | 201 | /// The Sliding FB method |
| 202 | #[clap(name = "sliding_fb", alias = "sfb")] | |
| 203 | SlidingFB, | |
| 0 | 204 | } |
| 205 | ||
| 206 | impl DefaultAlgorithm { | |
| 207 | /// Returns the algorithm configuration corresponding to the algorithm shorthand | |
| 208 | pub fn default_config<F : Float>(&self) -> AlgorithmConfig<F> { | |
| 209 | use DefaultAlgorithm::*; | |
| 210 | match *self { | |
| 211 | FB => AlgorithmConfig::FB(Default::default()), | |
| 32 | 212 | FISTA => AlgorithmConfig::FISTA(Default::default()), |
| 0 | 213 | FW => AlgorithmConfig::FW(Default::default()), |
| 214 | FWRelax => AlgorithmConfig::FW(FWConfig{ | |
| 215 | variant : FWVariant::Relaxed, | |
| 216 | .. Default::default() | |
| 217 | }), | |
| 218 | PDPS => AlgorithmConfig::PDPS(Default::default()), | |
|
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
219 | RadonFB => AlgorithmConfig::RadonFB(Default::default()), |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
220 | RadonFISTA => AlgorithmConfig::RadonFISTA(Default::default()), |
| 32 | 221 | SlidingFB => AlgorithmConfig::SlidingFB(Default::default()), |
| 0 | 222 | } |
| 223 | } | |
| 224 | ||
| 225 | /// Returns the [`Named`] algorithm corresponding to the algorithm shorthand | |
| 226 | pub fn get_named<F : Float>(&self) -> Named<AlgorithmConfig<F>> { | |
| 227 | self.to_named(self.default_config()) | |
| 228 | } | |
| 229 | ||
| 230 | pub fn to_named<F : Float>(self, alg : AlgorithmConfig<F>) -> Named<AlgorithmConfig<F>> { | |
| 231 | let name = self.to_possible_value().unwrap().get_name().to_string(); | |
| 232 | Named{ name , data : alg } | |
| 233 | } | |
| 234 | } | |
| 235 | ||
| 236 | ||
| 237 | // // Floats cannot be hashed directly, so just hash the debug formatting | |
| 238 | // // for use as file identifier. | |
| 239 | // impl<F : Float> Hash for AlgorithmConfig<F> { | |
| 240 | // fn hash<H: Hasher>(&self, state: &mut H) { | |
| 241 | // format!("{:?}", self).hash(state); | |
| 242 | // } | |
| 243 | // } | |
| 244 | ||
| 245 | /// Plotting level configuration | |
| 246 | #[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Serialize, ValueEnum, Debug)] | |
| 247 | pub enum PlotLevel { | |
| 248 | /// Plot nothing | |
| 249 | #[clap(name = "none")] | |
| 250 | None, | |
| 251 | /// Plot problem data | |
| 252 | #[clap(name = "data")] | |
| 253 | Data, | |
| 254 | /// Plot iterationwise state | |
| 255 | #[clap(name = "iter")] | |
| 256 | Iter, | |
| 257 | } | |
| 258 | ||
| 259 | type DefaultBT<F, const N : usize> = BT< | |
| 260 | DynamicDepth, | |
| 261 | F, | |
| 262 | usize, | |
| 263 | Bounds<F>, | |
| 264 | N | |
| 265 | >; | |
| 266 | type DefaultSeminormOp<F, K, const N : usize> = ConvolutionOp<F, K, DefaultBT<F, N>, N>; | |
| 267 | type DefaultSG<F, Sensor, Spread, const N : usize> = SensorGrid::< | |
| 268 | F, | |
| 269 | Sensor, | |
| 270 | Spread, | |
| 271 | DefaultBT<F, N>, | |
| 272 | N | |
| 273 | >; | |
| 274 | ||
| 275 | /// This is a dirty workaround to rust-csv not supporting struct flattening etc. | |
| 276 | #[derive(Serialize)] | |
| 277 | struct CSVLog<F> { | |
| 278 | iter : usize, | |
| 279 | cpu_time : f64, | |
| 280 | value : F, | |
| 281 | post_value : F, | |
| 282 | n_spikes : usize, | |
| 283 | inner_iters : usize, | |
| 284 | merged : usize, | |
| 285 | pruned : usize, | |
| 286 | this_iters : usize, | |
| 287 | } | |
| 288 | ||
| 289 | /// Collected experiment statistics | |
| 290 | #[derive(Clone, Debug, Serialize)] | |
| 291 | struct ExperimentStats<F : Float> { | |
| 292 | /// Signal-to-noise ratio in decibels | |
| 293 | ssnr : F, | |
| 294 | /// Proportion of noise in the signal as a number in $[0, 1]$. | |
| 295 | noise_ratio : F, | |
| 296 | /// When the experiment was run (UTC) | |
| 297 | when : DateTime<Utc>, | |
| 298 | } | |
| 299 | ||
| 300 | #[replace_float_literals(F::cast_from(literal))] | |
| 301 | impl<F : Float> ExperimentStats<F> { | |
| 302 | /// Calculate [`ExperimentStats`] based on a noisy `signal` and the separated `noise` signal. | |
| 303 | fn new<E : Euclidean<F>>(signal : &E, noise : &E) -> Self { | |
| 304 | let s = signal.norm2_squared(); | |
| 305 | let n = noise.norm2_squared(); | |
| 306 | let noise_ratio = (n / s).sqrt(); | |
| 307 | let ssnr = 10.0 * (s / n).log10(); | |
| 308 | ExperimentStats { | |
| 309 | ssnr, | |
| 310 | noise_ratio, | |
| 311 | when : Utc::now(), | |
| 312 | } | |
| 313 | } | |
| 314 | } | |
| 315 | /// Collected algorithm statistics | |
| 316 | #[derive(Clone, Debug, Serialize)] | |
| 317 | struct AlgorithmStats<F : Float> { | |
| 318 | /// Overall CPU time spent | |
| 319 | cpu_time : F, | |
| 320 | /// Real time spent | |
| 321 | elapsed : F | |
| 322 | } | |
| 323 | ||
| 324 | ||
| 325 | /// A wrapper for [`serde_json::to_writer_pretty`] that takes a filename as input | |
| 326 | /// and outputs a [`DynError`]. | |
| 327 | fn write_json<T : Serialize>(filename : String, data : &T) -> DynError { | |
| 328 | serde_json::to_writer_pretty(std::fs::File::create(filename)?, data)?; | |
| 329 | Ok(()) | |
| 330 | } | |
| 331 | ||
| 332 | ||
| 333 | /// Struct for experiment configurations | |
| 334 | #[derive(Debug, Clone, Serialize)] | |
|
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
335 | pub struct ExperimentV2<F, NoiseDistr, S, K, P, const N : usize> |
| 0 | 336 | where F : Float, |
| 337 | [usize; N] : Serialize, | |
| 338 | NoiseDistr : Distribution<F>, | |
| 339 | S : Sensor<F, N>, | |
| 340 | P : Spread<F, N>, | |
| 341 | K : SimpleConvolutionKernel<F, N>, | |
| 342 | { | |
| 343 | /// Domain $Ω$. | |
| 344 | pub domain : Cube<F, N>, | |
| 345 | /// Number of sensors along each dimension | |
| 346 | pub sensor_count : [usize; N], | |
| 347 | /// Noise distribution | |
| 348 | pub noise_distr : NoiseDistr, | |
| 349 | /// Seed for random noise generation (for repeatable experiments) | |
| 350 | pub noise_seed : u64, | |
| 351 | /// Sensor $θ$; $θ * ψ$ forms the forward operator $𝒜$. | |
| 352 | pub sensor : S, | |
| 353 | /// Spread $ψ$; $θ * ψ$ forms the forward operator $𝒜$. | |
| 354 | pub spread : P, | |
| 355 | /// Kernel $ρ$ of $𝒟$. | |
| 356 | pub kernel : K, | |
| 357 | /// True point sources | |
| 358 | pub μ_hat : DiscreteMeasure<Loc<F, N>, F>, | |
|
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
359 | /// Regularisation term and parameter |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
360 | pub regularisation : Regularisation<F>, |
| 0 | 361 | /// For plotting : how wide should the kernels be plotted |
| 362 | pub kernel_plot_width : F, | |
| 363 | /// Data term | |
| 364 | pub dataterm : DataTerm, | |
| 365 | /// A map of default configurations for algorithms | |
| 366 | #[serde(skip)] | |
| 367 | pub algorithm_defaults : HashMap<DefaultAlgorithm, AlgorithmConfig<F>>, | |
| 368 | } | |
| 369 | ||
| 370 | /// Trait for runnable experiments | |
| 371 | pub trait RunnableExperiment<F : ClapFloat> { | |
|
9
21b0e537ac0e
Command line parameter passing simplifications and make `-o` required.
Tuomo Valkonen <tuomov@iki.fi>
parents:
0
diff
changeset
|
372 | /// Run all algorithms provided, or default algorithms if none provided, on the experiment. |
|
21b0e537ac0e
Command line parameter passing simplifications and make `-o` required.
Tuomo Valkonen <tuomov@iki.fi>
parents:
0
diff
changeset
|
373 | fn runall(&self, cli : &CommandLineArgs, |
|
21b0e537ac0e
Command line parameter passing simplifications and make `-o` required.
Tuomo Valkonen <tuomov@iki.fi>
parents:
0
diff
changeset
|
374 | algs : Option<Vec<Named<AlgorithmConfig<F>>>>) -> DynError; |
| 0 | 375 | |
| 376 | /// Return algorithm default config | |
| 377 | fn algorithm_defaults(&self, alg : DefaultAlgorithm, cli : &AlgorithmOverrides<F>) | |
| 378 | -> Named<AlgorithmConfig<F>>; | |
| 379 | } | |
| 380 | ||
|
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
381 | // *** macro boilerplate *** |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
382 | macro_rules! impl_experiment { |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
383 | ($type:ident, $reg_field:ident, $reg_convert:path) => { |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
384 | // *** macro *** |
| 0 | 385 | impl<F, NoiseDistr, S, K, P, const N : usize> RunnableExperiment<F> for |
|
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
386 | Named<$type<F, NoiseDistr, S, K, P, N>> |
| 0 | 387 | where F : ClapFloat + nalgebra::RealField + ToNalgebraRealField<MixedType=F>, |
| 388 | [usize; N] : Serialize, | |
|
23
9869fa1e0ccd
Print out experiment information when running it
Tuomo Valkonen <tuomov@iki.fi>
parents:
20
diff
changeset
|
389 | S : Sensor<F, N> + Copy + Serialize + std::fmt::Debug, |
|
9869fa1e0ccd
Print out experiment information when running it
Tuomo Valkonen <tuomov@iki.fi>
parents:
20
diff
changeset
|
390 | P : Spread<F, N> + Copy + Serialize + std::fmt::Debug, |
| 32 | 391 | Convolution<S, P>: Spread<F, N> + Bounded<F> + LocalAnalysis<F, Bounds<F>, N> + Copy |
| 392 | // TODO: shold not have differentiability as a requirement, but | |
| 393 | // decide availability of sliding based on it. | |
| 394 | //+ for<'b> Differentiable<&'b Loc<F, N>, Output = Loc<F, N>>, | |
| 395 | // TODO: very weird that rust only compiles with Differentiable | |
| 396 | // instead of the above one on references, which is required by | |
| 397 | // poitsource_sliding_fb_reg. | |
|
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
398 | + DifferentiableRealMapping<F, N> |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
399 | + Lipschitz<L2, FloatType=F>, |
| 32 | 400 | // <DefaultSG<F, S, P, N> as ForwardModel<Loc<F, N>, F>::PreadjointCodomain : for<'b> Differentiable<&'b Loc<F, N>, Output = Loc<F, N>>, |
| 0 | 401 | AutoConvolution<P> : BoundedBy<F, K>, |
|
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
402 | K : SimpleConvolutionKernel<F, N> |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
403 | + LocalAnalysis<F, Bounds<F>, N> |
|
23
9869fa1e0ccd
Print out experiment information when running it
Tuomo Valkonen <tuomov@iki.fi>
parents:
20
diff
changeset
|
404 | + Copy + Serialize + std::fmt::Debug, |
| 0 | 405 | Cube<F, N>: P2Minimise<Loc<F, N>, F> + SetOrd, |
| 406 | PlotLookup : Plotting<N>, | |
| 407 | DefaultBT<F, N> : SensorGridBT<F, S, P, N, Depth=DynamicDepth> + BTSearch<F, N>, | |
| 408 | BTNodeLookup: BTNode<F, usize, Bounds<F>, N>, | |
| 409 | DiscreteMeasure<Loc<F, N>, F> : SpikeMerging<F>, | |
|
23
9869fa1e0ccd
Print out experiment information when running it
Tuomo Valkonen <tuomov@iki.fi>
parents:
20
diff
changeset
|
410 | NoiseDistr : Distribution<F> + Serialize + std::fmt::Debug { |
| 0 | 411 | |
| 412 | fn algorithm_defaults(&self, alg : DefaultAlgorithm, cli : &AlgorithmOverrides<F>) | |
| 413 | -> Named<AlgorithmConfig<F>> { | |
| 414 | alg.to_named( | |
| 415 | self.data | |
| 416 | .algorithm_defaults | |
| 417 | .get(&alg) | |
| 418 | .map_or_else(|| alg.default_config(), | |
| 419 | |config| config.clone()) | |
| 420 | .cli_override(cli) | |
| 421 | ) | |
| 422 | } | |
| 423 | ||
|
9
21b0e537ac0e
Command line parameter passing simplifications and make `-o` required.
Tuomo Valkonen <tuomov@iki.fi>
parents:
0
diff
changeset
|
424 | fn runall(&self, cli : &CommandLineArgs, |
|
21b0e537ac0e
Command line parameter passing simplifications and make `-o` required.
Tuomo Valkonen <tuomov@iki.fi>
parents:
0
diff
changeset
|
425 | algs : Option<Vec<Named<AlgorithmConfig<F>>>>) -> DynError { |
|
21b0e537ac0e
Command line parameter passing simplifications and make `-o` required.
Tuomo Valkonen <tuomov@iki.fi>
parents:
0
diff
changeset
|
426 | // Get experiment configuration |
| 0 | 427 | let &Named { |
| 428 | name : ref experiment_name, | |
|
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
429 | data : $type { |
| 0 | 430 | domain, sensor_count, ref noise_distr, sensor, spread, kernel, |
|
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
431 | ref μ_hat, /*regularisation,*/ kernel_plot_width, dataterm, noise_seed, |
| 0 | 432 | .. |
| 433 | } | |
| 434 | } = self; | |
|
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
435 | let regularisation = $reg_convert(self.data.$reg_field); |
| 0 | 436 | |
|
23
9869fa1e0ccd
Print out experiment information when running it
Tuomo Valkonen <tuomov@iki.fi>
parents:
20
diff
changeset
|
437 | println!("{}\n{}", |
|
9869fa1e0ccd
Print out experiment information when running it
Tuomo Valkonen <tuomov@iki.fi>
parents:
20
diff
changeset
|
438 | format!("Performing experiment {}…", experiment_name).cyan(), |
|
9869fa1e0ccd
Print out experiment information when running it
Tuomo Valkonen <tuomov@iki.fi>
parents:
20
diff
changeset
|
439 | format!("{:?}", &self.data).bright_black()); |
|
9869fa1e0ccd
Print out experiment information when running it
Tuomo Valkonen <tuomov@iki.fi>
parents:
20
diff
changeset
|
440 | |
|
9
21b0e537ac0e
Command line parameter passing simplifications and make `-o` required.
Tuomo Valkonen <tuomov@iki.fi>
parents:
0
diff
changeset
|
441 | // Set up output directory |
|
21b0e537ac0e
Command line parameter passing simplifications and make `-o` required.
Tuomo Valkonen <tuomov@iki.fi>
parents:
0
diff
changeset
|
442 | let prefix = format!("{}/{}/", cli.outdir, self.name); |
|
21b0e537ac0e
Command line parameter passing simplifications and make `-o` required.
Tuomo Valkonen <tuomov@iki.fi>
parents:
0
diff
changeset
|
443 | |
|
21b0e537ac0e
Command line parameter passing simplifications and make `-o` required.
Tuomo Valkonen <tuomov@iki.fi>
parents:
0
diff
changeset
|
444 | // Set up algorithms |
|
21b0e537ac0e
Command line parameter passing simplifications and make `-o` required.
Tuomo Valkonen <tuomov@iki.fi>
parents:
0
diff
changeset
|
445 | let iterator_options = AlgIteratorOptions{ |
|
21b0e537ac0e
Command line parameter passing simplifications and make `-o` required.
Tuomo Valkonen <tuomov@iki.fi>
parents:
0
diff
changeset
|
446 | max_iter : cli.max_iter, |
|
21b0e537ac0e
Command line parameter passing simplifications and make `-o` required.
Tuomo Valkonen <tuomov@iki.fi>
parents:
0
diff
changeset
|
447 | verbose_iter : cli.verbose_iter |
|
21b0e537ac0e
Command line parameter passing simplifications and make `-o` required.
Tuomo Valkonen <tuomov@iki.fi>
parents:
0
diff
changeset
|
448 | .map_or(Verbose::Logarithmic(10), |
|
21b0e537ac0e
Command line parameter passing simplifications and make `-o` required.
Tuomo Valkonen <tuomov@iki.fi>
parents:
0
diff
changeset
|
449 | |n| Verbose::Every(n)), |
|
21b0e537ac0e
Command line parameter passing simplifications and make `-o` required.
Tuomo Valkonen <tuomov@iki.fi>
parents:
0
diff
changeset
|
450 | quiet : cli.quiet, |
|
21b0e537ac0e
Command line parameter passing simplifications and make `-o` required.
Tuomo Valkonen <tuomov@iki.fi>
parents:
0
diff
changeset
|
451 | }; |
|
21b0e537ac0e
Command line parameter passing simplifications and make `-o` required.
Tuomo Valkonen <tuomov@iki.fi>
parents:
0
diff
changeset
|
452 | let algorithms = match (algs, self.data.dataterm) { |
|
21b0e537ac0e
Command line parameter passing simplifications and make `-o` required.
Tuomo Valkonen <tuomov@iki.fi>
parents:
0
diff
changeset
|
453 | (Some(algs), _) => algs, |
|
21b0e537ac0e
Command line parameter passing simplifications and make `-o` required.
Tuomo Valkonen <tuomov@iki.fi>
parents:
0
diff
changeset
|
454 | (None, DataTerm::L2Squared) => vec![DefaultAlgorithm::FB.get_named()], |
|
21b0e537ac0e
Command line parameter passing simplifications and make `-o` required.
Tuomo Valkonen <tuomov@iki.fi>
parents:
0
diff
changeset
|
455 | (None, DataTerm::L1) => vec![DefaultAlgorithm::PDPS.get_named()], |
|
21b0e537ac0e
Command line parameter passing simplifications and make `-o` required.
Tuomo Valkonen <tuomov@iki.fi>
parents:
0
diff
changeset
|
456 | }; |
| 0 | 457 | |
| 458 | // Set up operators | |
|
9
21b0e537ac0e
Command line parameter passing simplifications and make `-o` required.
Tuomo Valkonen <tuomov@iki.fi>
parents:
0
diff
changeset
|
459 | let depth = DynamicDepth(8); |
| 0 | 460 | let opA = DefaultSG::new(domain, sensor_count, sensor, spread, depth); |
| 461 | let op𝒟 = DefaultSeminormOp::new(depth, domain, kernel); | |
| 462 | ||
| 463 | // Set up random number generator. | |
| 464 | let mut rng = StdRng::seed_from_u64(noise_seed); | |
| 465 | ||
| 466 | // Generate the data and calculate SSNR statistic | |
| 467 | let b_hat = opA.apply(μ_hat); | |
| 468 | let noise = DVector::from_distribution(b_hat.len(), &noise_distr, &mut rng); | |
| 469 | let b = &b_hat + &noise; | |
| 470 | // Need to wrap calc_ssnr into a function to hide ultra-lame nalgebra::RealField | |
| 471 | // overloading log10 and conflicting with standard NumTraits one. | |
| 472 | let stats = ExperimentStats::new(&b, &noise); | |
| 473 | ||
| 474 | // Save experiment configuration and statistics | |
| 475 | let mkname_e = |t| format!("{prefix}{t}.json", prefix = prefix, t = t); | |
| 476 | std::fs::create_dir_all(&prefix)?; | |
| 477 | write_json(mkname_e("experiment"), self)?; | |
|
9
21b0e537ac0e
Command line parameter passing simplifications and make `-o` required.
Tuomo Valkonen <tuomov@iki.fi>
parents:
0
diff
changeset
|
478 | write_json(mkname_e("config"), cli)?; |
| 0 | 479 | write_json(mkname_e("stats"), &stats)?; |
| 480 | ||
|
9
21b0e537ac0e
Command line parameter passing simplifications and make `-o` required.
Tuomo Valkonen <tuomov@iki.fi>
parents:
0
diff
changeset
|
481 | plotall(cli, &prefix, &domain, &sensor, &kernel, &spread, |
| 0 | 482 | &μ_hat, &op𝒟, &opA, &b_hat, &b, kernel_plot_width)?; |
| 483 | ||
| 484 | // Run the algorithm(s) | |
|
9
21b0e537ac0e
Command line parameter passing simplifications and make `-o` required.
Tuomo Valkonen <tuomov@iki.fi>
parents:
0
diff
changeset
|
485 | for named @ Named { name : alg_name, data : alg } in algorithms.iter() { |
| 0 | 486 | let this_prefix = format!("{}{}/", prefix, alg_name); |
| 487 | ||
|
9
21b0e537ac0e
Command line parameter passing simplifications and make `-o` required.
Tuomo Valkonen <tuomov@iki.fi>
parents:
0
diff
changeset
|
488 | let running = || if !cli.quiet { |
| 0 | 489 | println!("{}\n{}\n{}", |
| 490 | format!("Running {} on experiment {}…", alg_name, experiment_name).cyan(), | |
|
9
21b0e537ac0e
Command line parameter passing simplifications and make `-o` required.
Tuomo Valkonen <tuomov@iki.fi>
parents:
0
diff
changeset
|
491 | format!("{:?}", iterator_options).bright_black(), |
| 0 | 492 | format!("{:?}", alg).bright_black()); |
| 493 | }; | |
|
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
494 | let not_implemented = || { |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
495 | let msg = format!("Algorithm “{alg_name}” not implemented for \ |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
496 | dataterm {dataterm:?} and regularisation {regularisation:?}. \ |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
497 | Skipping.").red(); |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
498 | eprintln!("{}", msg); |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
499 | }; |
| 0 | 500 | // Create Logger and IteratorFactory |
| 501 | let mut logger = Logger::new(); | |
|
25
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
502 | let reg : Box<dyn WeightOptim<_, _, _, N>> = match regularisation { |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
503 | Regularisation::Radon(α) => Box::new(RadonRegTerm(α)), |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
504 | Regularisation::NonnegRadon(α) => Box::new(NonnegRadonRegTerm(α)), |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
505 | }; |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
506 | let findim_data = reg.prepare_optimise_weights(&opA, &b); |
| 0 | 507 | let inner_config : InnerSettings<F> = Default::default(); |
| 508 | let inner_it = inner_config.iterator_options; | |
| 509 | let logmap = |iter, Timed { cpu_time, data }| { | |
| 510 | let IterInfo { | |
| 511 | value, | |
| 512 | n_spikes, | |
| 513 | inner_iters, | |
| 514 | merged, | |
| 515 | pruned, | |
| 516 | postprocessing, | |
| 517 | this_iters, | |
| 518 | .. | |
| 519 | } = data; | |
|
25
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
520 | let post_value = match (postprocessing, dataterm) { |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
521 | (Some(mut μ), DataTerm::L2Squared) => { |
|
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
522 | // Comparison postprocessing is only implemented for the case handled |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
523 | // by the FW variants. |
|
25
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
524 | reg.optimise_weights( |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
525 | &mut μ, &opA, &b, &findim_data, &inner_config, |
|
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
526 | inner_it |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
527 | ); |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
528 | dataterm.value_at_residual(opA.apply(&μ) - &b) |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
529 | + regularisation.apply(&μ) |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
530 | }, |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
531 | _ => value, |
| 0 | 532 | }; |
| 533 | CSVLog { | |
| 534 | iter, | |
| 535 | value, | |
| 536 | post_value, | |
| 537 | n_spikes, | |
| 538 | cpu_time : cpu_time.as_secs_f64(), | |
| 539 | inner_iters, | |
| 540 | merged, | |
| 541 | pruned, | |
| 542 | this_iters | |
| 543 | } | |
| 544 | }; | |
|
9
21b0e537ac0e
Command line parameter passing simplifications and make `-o` required.
Tuomo Valkonen <tuomov@iki.fi>
parents:
0
diff
changeset
|
545 | let iterator = iterator_options.instantiate() |
|
21b0e537ac0e
Command line parameter passing simplifications and make `-o` required.
Tuomo Valkonen <tuomov@iki.fi>
parents:
0
diff
changeset
|
546 | .timed() |
|
21b0e537ac0e
Command line parameter passing simplifications and make `-o` required.
Tuomo Valkonen <tuomov@iki.fi>
parents:
0
diff
changeset
|
547 | .mapped(logmap) |
|
21b0e537ac0e
Command line parameter passing simplifications and make `-o` required.
Tuomo Valkonen <tuomov@iki.fi>
parents:
0
diff
changeset
|
548 | .into_log(&mut logger); |
| 0 | 549 | let plotgrid = lingrid(&domain, &[if N==1 { 1000 } else { 100 }; N]); |
| 550 | ||
| 551 | // Create plotter and directory if needed. | |
|
9
21b0e537ac0e
Command line parameter passing simplifications and make `-o` required.
Tuomo Valkonen <tuomov@iki.fi>
parents:
0
diff
changeset
|
552 | let plot_count = if cli.plot >= PlotLevel::Iter { 2000 } else { 0 }; |
| 0 | 553 | let plotter = SeqPlotter::new(this_prefix, plot_count, plotgrid); |
| 554 | ||
| 555 | // Run the algorithm | |
| 556 | let start = Instant::now(); | |
| 557 | let start_cpu = ProcessTime::now(); | |
|
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
558 | let μ = match alg { |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
559 | AlgorithmConfig::FB(ref algconfig) => { |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
560 | match (regularisation, dataterm) { |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
561 | (Regularisation::NonnegRadon(α), DataTerm::L2Squared) => { |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
562 | running(); |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
563 | pointsource_fb_reg( |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
564 | &opA, &b, NonnegRadonRegTerm(α), &op𝒟, algconfig, |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
565 | iterator, plotter |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
566 | ) |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
567 | }, |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
568 | (Regularisation::Radon(α), DataTerm::L2Squared) => { |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
569 | running(); |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
570 | pointsource_fb_reg( |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
571 | &opA, &b, RadonRegTerm(α), &op𝒟, algconfig, |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
572 | iterator, plotter |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
573 | ) |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
574 | }, |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
575 | _ => { |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
576 | not_implemented(); |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
577 | continue |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
578 | } |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
579 | } |
| 0 | 580 | }, |
| 32 | 581 | AlgorithmConfig::FISTA(ref algconfig) => { |
| 582 | match (regularisation, dataterm) { | |
| 583 | (Regularisation::NonnegRadon(α), DataTerm::L2Squared) => { | |
| 584 | running(); | |
| 585 | pointsource_fista_reg( | |
| 586 | &opA, &b, NonnegRadonRegTerm(α), &op𝒟, algconfig, | |
| 587 | iterator, plotter | |
| 588 | ) | |
| 589 | }, | |
| 590 | (Regularisation::Radon(α), DataTerm::L2Squared) => { | |
| 591 | running(); | |
| 592 | pointsource_fista_reg( | |
| 593 | &opA, &b, RadonRegTerm(α), &op𝒟, algconfig, | |
| 594 | iterator, plotter | |
| 595 | ) | |
| 596 | }, | |
| 597 | _ => { | |
| 598 | not_implemented(); | |
| 599 | continue | |
| 600 | } | |
| 601 | } | |
| 602 | }, | |
|
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
603 | AlgorithmConfig::RadonFB(ref algconfig) => { |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
604 | match (regularisation, dataterm) { |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
605 | (Regularisation::NonnegRadon(α), DataTerm::L2Squared) => { |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
606 | running(); |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
607 | pointsource_radon_fb_reg( |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
608 | &opA, &b, NonnegRadonRegTerm(α), algconfig, |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
609 | iterator, plotter |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
610 | ) |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
611 | }, |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
612 | (Regularisation::Radon(α), DataTerm::L2Squared) => { |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
613 | running(); |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
614 | pointsource_radon_fb_reg( |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
615 | &opA, &b, RadonRegTerm(α), algconfig, |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
616 | iterator, plotter |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
617 | ) |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
618 | }, |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
619 | _ => { |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
620 | not_implemented(); |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
621 | continue |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
622 | } |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
623 | } |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
624 | }, |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
625 | AlgorithmConfig::RadonFISTA(ref algconfig) => { |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
626 | match (regularisation, dataterm) { |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
627 | (Regularisation::NonnegRadon(α), DataTerm::L2Squared) => { |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
628 | running(); |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
629 | pointsource_radon_fista_reg( |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
630 | &opA, &b, NonnegRadonRegTerm(α), algconfig, |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
631 | iterator, plotter |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
632 | ) |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
633 | }, |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
634 | (Regularisation::Radon(α), DataTerm::L2Squared) => { |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
635 | running(); |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
636 | pointsource_radon_fista_reg( |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
637 | &opA, &b, RadonRegTerm(α), algconfig, |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
638 | iterator, plotter |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
639 | ) |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
640 | }, |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
641 | _ => { |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
642 | not_implemented(); |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
643 | continue |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
644 | } |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
645 | } |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
646 | }, |
| 32 | 647 | AlgorithmConfig::SlidingFB(ref algconfig) => { |
| 648 | match (regularisation, dataterm) { | |
| 649 | (Regularisation::NonnegRadon(α), DataTerm::L2Squared) => { | |
| 650 | running(); | |
| 651 | pointsource_sliding_fb_reg( | |
| 652 | &opA, &b, NonnegRadonRegTerm(α), &op𝒟, algconfig, | |
| 653 | iterator, plotter | |
| 654 | ) | |
| 655 | }, | |
| 656 | (Regularisation::Radon(α), DataTerm::L2Squared) => { | |
| 657 | running(); | |
| 658 | pointsource_sliding_fb_reg( | |
| 659 | &opA, &b, RadonRegTerm(α), &op𝒟, algconfig, | |
| 660 | iterator, plotter | |
| 661 | ) | |
| 662 | }, | |
| 663 | _ => { | |
| 664 | not_implemented(); | |
| 665 | continue | |
| 666 | } | |
| 667 | } | |
| 668 | }, | |
|
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
669 | AlgorithmConfig::PDPS(ref algconfig) => { |
| 0 | 670 | running(); |
|
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
671 | match (regularisation, dataterm) { |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
672 | (Regularisation::NonnegRadon(α), DataTerm::L2Squared) => { |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
673 | pointsource_pdps_reg( |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
674 | &opA, &b, NonnegRadonRegTerm(α), &op𝒟, algconfig, |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
675 | iterator, plotter, L2Squared |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
676 | ) |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
677 | }, |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
678 | (Regularisation::Radon(α),DataTerm::L2Squared) => { |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
679 | pointsource_pdps_reg( |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
680 | &opA, &b, RadonRegTerm(α), &op𝒟, algconfig, |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
681 | iterator, plotter, L2Squared |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
682 | ) |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
683 | }, |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
684 | (Regularisation::NonnegRadon(α), DataTerm::L1) => { |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
685 | pointsource_pdps_reg( |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
686 | &opA, &b, NonnegRadonRegTerm(α), &op𝒟, algconfig, |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
687 | iterator, plotter, L1 |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
688 | ) |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
689 | }, |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
690 | (Regularisation::Radon(α), DataTerm::L1) => { |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
691 | pointsource_pdps_reg( |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
692 | &opA, &b, RadonRegTerm(α), &op𝒟, algconfig, |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
693 | iterator, plotter, L1 |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
694 | ) |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
695 | }, |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
696 | } |
| 0 | 697 | }, |
|
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
698 | AlgorithmConfig::FW(ref algconfig) => { |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
699 | match (regularisation, dataterm) { |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
700 | (Regularisation::Radon(α), DataTerm::L2Squared) => { |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
701 | running(); |
|
25
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
702 | pointsource_fw_reg(&opA, &b, RadonRegTerm(α), |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
703 | algconfig, iterator, plotter) |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
704 | }, |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
705 | (Regularisation::NonnegRadon(α), DataTerm::L2Squared) => { |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
706 | running(); |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
707 | pointsource_fw_reg(&opA, &b, NonnegRadonRegTerm(α), |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
708 | algconfig, iterator, plotter) |
|
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
709 | }, |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
710 | _ => { |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
711 | not_implemented(); |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
712 | continue |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
713 | } |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
714 | } |
| 0 | 715 | } |
| 716 | }; | |
|
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
717 | |
| 0 | 718 | let elapsed = start.elapsed().as_secs_f64(); |
| 719 | let cpu_time = start_cpu.elapsed().as_secs_f64(); | |
| 720 | ||
| 721 | println!("{}", format!("Elapsed {elapsed}s (CPU time {cpu_time}s)… ").yellow()); | |
| 722 | ||
| 723 | // Save results | |
| 724 | println!("{}", "Saving results…".green()); | |
| 725 | ||
|
9
21b0e537ac0e
Command line parameter passing simplifications and make `-o` required.
Tuomo Valkonen <tuomov@iki.fi>
parents:
0
diff
changeset
|
726 | let mkname = |t| format!("{prefix}{alg_name}_{t}"); |
| 0 | 727 | |
| 728 | write_json(mkname("config.json"), &named)?; | |
| 729 | write_json(mkname("stats.json"), &AlgorithmStats { cpu_time, elapsed })?; | |
| 730 | μ.write_csv(mkname("reco.txt"))?; | |
| 731 | logger.write_csv(mkname("log.txt"))?; | |
| 732 | } | |
| 733 | ||
| 734 | Ok(()) | |
| 735 | } | |
| 736 | } | |
|
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
737 | // *** macro end boiler plate *** |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
738 | }} |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
739 | // *** actual code *** |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
740 | |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
23
diff
changeset
|
741 | impl_experiment!(ExperimentV2, regularisation, std::convert::identity); |
| 0 | 742 | |
| 743 | /// Plot experiment setup | |
| 744 | #[replace_float_literals(F::cast_from(literal))] | |
| 745 | fn plotall<F, Sensor, Kernel, Spread, 𝒟, A, const N : usize>( | |
|
9
21b0e537ac0e
Command line parameter passing simplifications and make `-o` required.
Tuomo Valkonen <tuomov@iki.fi>
parents:
0
diff
changeset
|
746 | cli : &CommandLineArgs, |
| 0 | 747 | prefix : &String, |
| 748 | domain : &Cube<F, N>, | |
| 749 | sensor : &Sensor, | |
| 750 | kernel : &Kernel, | |
| 751 | spread : &Spread, | |
| 752 | μ_hat : &DiscreteMeasure<Loc<F, N>, F>, | |
| 753 | op𝒟 : &𝒟, | |
| 754 | opA : &A, | |
| 755 | b_hat : &A::Observable, | |
| 756 | b : &A::Observable, | |
| 757 | kernel_plot_width : F, | |
| 758 | ) -> DynError | |
| 759 | where F : Float + ToNalgebraRealField, | |
| 760 | Sensor : RealMapping<F, N> + Support<F, N> + Clone, | |
| 761 | Spread : RealMapping<F, N> + Support<F, N> + Clone, | |
| 762 | Kernel : RealMapping<F, N> + Support<F, N>, | |
|
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
763 | Convolution<Sensor, Spread> : DifferentiableRealMapping<F, N> + Support<F, N>, |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
764 | //Differential<Loc<F, N>, Convolution<Sensor, Spread>> : RealVectorField<F, N, N>, |
| 0 | 765 | 𝒟 : DiscreteMeasureOp<Loc<F, N>, F>, |
| 766 | 𝒟::Codomain : RealMapping<F, N>, | |
| 767 | A : ForwardModel<Loc<F, N>, F>, | |
|
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
768 | A::PreadjointCodomain : DifferentiableRealMapping<F, N> + Bounded<F>, |
| 0 | 769 | PlotLookup : Plotting<N>, |
| 770 | Cube<F, N> : SetOrd { | |
| 771 | ||
|
9
21b0e537ac0e
Command line parameter passing simplifications and make `-o` required.
Tuomo Valkonen <tuomov@iki.fi>
parents:
0
diff
changeset
|
772 | if cli.plot < PlotLevel::Data { |
| 0 | 773 | return Ok(()) |
| 774 | } | |
| 775 | ||
| 776 | let base = Convolution(sensor.clone(), spread.clone()); | |
| 777 | ||
| 778 | let resolution = if N==1 { 100 } else { 40 }; | |
| 779 | let pfx = |n| format!("{}{}", prefix, n); | |
| 780 | let plotgrid = lingrid(&[[-kernel_plot_width, kernel_plot_width]; N].into(), &[resolution; N]); | |
| 781 | ||
| 782 | PlotLookup::plot_into_file(sensor, plotgrid, pfx("sensor"), "sensor".to_string()); | |
| 783 | PlotLookup::plot_into_file(kernel, plotgrid, pfx("kernel"), "kernel".to_string()); | |
| 784 | PlotLookup::plot_into_file(spread, plotgrid, pfx("spread"), "spread".to_string()); | |
|
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
785 | PlotLookup::plot_into_file_diff(&base, plotgrid, pfx("base_sensor"), "base_sensor".to_string()); |
| 0 | 786 | |
| 787 | let plotgrid2 = lingrid(&domain, &[resolution; N]); | |
| 788 | ||
| 789 | let ω_hat = op𝒟.apply(μ_hat); | |
| 790 | let noise = opA.preadjoint().apply(opA.apply(μ_hat) - b); | |
| 791 | PlotLookup::plot_into_file(&ω_hat, plotgrid2, pfx("omega_hat"), "ω̂".to_string()); | |
| 792 | PlotLookup::plot_into_file(&noise, plotgrid2, pfx("omega_noise"), | |
| 793 | "noise Aᵀ(Aμ̂ - b)".to_string()); | |
| 794 | ||
| 795 | let preadj_b = opA.preadjoint().apply(b); | |
| 796 | let preadj_b_hat = opA.preadjoint().apply(b_hat); | |
| 797 | //let bounds = preadj_b.bounds().common(&preadj_b_hat.bounds()); | |
| 798 | PlotLookup::plot_into_file_spikes( | |
| 799 | "Aᵀb".to_string(), &preadj_b, | |
| 800 | "Aᵀb̂".to_string(), Some(&preadj_b_hat), | |
| 801 | plotgrid2, None, &μ_hat, | |
| 802 | pfx("omega_b") | |
| 803 | ); | |
|
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
804 | PlotLookup::plot_into_file_diff(&preadj_b, plotgrid2, pfx("preadj_b"), |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
805 | "preadj_b".to_string()); |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
806 | PlotLookup::plot_into_file_diff(&preadj_b_hat, plotgrid2, pfx("preadj_b_hat"), |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
807 | "preadj_b_hat".to_string()); |
| 0 | 808 | |
| 809 | // Save true solution and observables | |
| 810 | let pfx = |n| format!("{}{}", prefix, n); | |
| 811 | μ_hat.write_csv(pfx("orig.txt"))?; | |
| 812 | opA.write_observable(&b_hat, pfx("b_hat"))?; | |
| 813 | opA.write_observable(&b, pfx("b_noisy")) | |
| 814 | } |