--- a/src/main.rs Wed Nov 06 21:12:14 2024 -0500 +++ b/src/main.rs Wed Nov 06 21:40:54 2024 -0500 @@ -24,10 +24,11 @@ use alg_tools::types::*; use alg_tools::mapping::{Sum, Apply}; use alg_tools::iterate::{AlgIteratorOptions, AlgIteratorFactory, Verbose}; +use alg_tools::mapping::Mapping; use image::{ImageFormat, ImageBuffer, Rgb}; use dist::{DistTo, DistToSquaredDiv2}; -use fb::{forward_backward, IterInfo}; +use fb::{forward_backward, IterInfo, Desc, Prox}; use manifold::EmbeddedManifoldPoint; use cube::*; use Face::*; @@ -97,12 +98,32 @@ //let x = points[0].clone(); // OnCube::new(F3, Loc([0.5, 0.5])); goes to opposite side - let x = OnCube::new(F3, Loc([0.1, 0.7])); let f = Sum::new(points.into_iter().map(DistToSquaredDiv2)); //let g = ZeroFn::new(); let g = Scaled::new(0.5, DistTo(origin)); let τ = 0.05; + std::fs::create_dir_all(PREFIX)?; + for face in Face::all() { + write_face_csv(format!("{PREFIX}/{face}"), face, 32, |x| f.apply(x) + g.apply(x))?; + write_face_img(format!("{PREFIX}/{face}"), face, 128, |x| f.apply(x) + g.apply(x))?; + } + + run_and_save("x1", &f, &g, OnCube::new(F3, Loc([0.1, 0.7])), τ)?; + run_and_save("x2", &f, &g, OnCube::new(F2, Loc([0.1, 0.7])), τ)?; + run_and_save("x3", &f, &g, OnCube::new(F6, Loc([0.6, 0.2])), τ) +} + +pub fn run_and_save<F, G>( + name : &str, + f : &F, + g : &G, + x : OnCube, + τ : f64, +) -> DynError +where F : Desc<OnCube> + Mapping<OnCube, Codomain = f64>, + G : Prox<OnCube> + Mapping<OnCube, Codomain = f64> { + let mut logger = Logger::new(); let logmap = |iter, IterInfo { value, point } : IterInfo<OnCube>| { let CSVPoint {x , y, z, face} = CSVPoint::from(&point); @@ -118,17 +139,10 @@ }.mapped(logmap) .into_log(&mut logger); - let x̂ = forward_backward(&f, &g, x, τ, iter); + let x̂ = forward_backward(f, g, x, τ, iter); println!("result = {}\n{:?}", x̂.embedded_coords(), &x̂); - std::fs::create_dir_all(PREFIX)?; - - logger.write_csv(format!("{PREFIX}/log.txt"))?; - - for face in Face::all() { - write_face_csv(format!("{PREFIX}/{face}"), face, 32, |x| f.apply(x) + g.apply(x))?; - write_face_img(format!("{PREFIX}/{face}"), face, 128, |x| f.apply(x) + g.apply(x))?; - } + logger.write_csv(format!("{PREFIX}/{name}_log.csv"))?; Ok(()) }