src/main.rs

changeset 25
9ac11616a2c5
parent 24
8b4b014277fa
child 28
334fd47c482e
child 31
49227d097d14
equal deleted inserted replaced
24:8b4b014277fa 25:9ac11616a2c5
78 78
79 /// A simple test on the cube 79 /// A simple test on the cube
80 fn simple_cube_test() -> DynError { 80 fn simple_cube_test() -> DynError {
81 81
82 let points = [ 82 let points = [
83 //OnCube::new(F1, Loc([0.5, 0.5])),
84 //OnCube::new(F2, Loc([0.5, 0.5])),
85 //OnCube::new(F4, Loc([0.1, 0.1])),
86 OnCube::new(F1, Loc([0.5, 0.7])), 83 OnCube::new(F1, Loc([0.5, 0.7])),
87 OnCube::new(F2, Loc([0.3, 0.5])), 84 OnCube::new(F2, Loc([0.3, 0.5])),
88 OnCube::new(F4, Loc([0.9, 0.9])), 85 OnCube::new(F4, Loc([0.9, 0.9])),
89 OnCube::new(F6, Loc([0.4, 0.3])), 86 OnCube::new(F6, Loc([0.4, 0.3])),
90 OnCube::new(F4, Loc([0.3, 0.7])), 87 OnCube::new(F4, Loc([0.3, 0.7])),
94 let origin = OnCube::new(F4, Loc([0.5, 0.5])); 91 let origin = OnCube::new(F4, Loc([0.5, 0.5]));
95 92
96 write_points(format!("{PREFIX}/data"), points.iter())?; 93 write_points(format!("{PREFIX}/data"), points.iter())?;
97 write_points(format!("{PREFIX}/origin"), std::iter::once(&origin))?; 94 write_points(format!("{PREFIX}/origin"), std::iter::once(&origin))?;
98 95
99 //let x = points[0].clone();
100 // OnCube::new(F3, Loc([0.5, 0.5])); goes to opposite side
101 let f = Sum::new(points.into_iter().map(DistToSquaredDiv2)); 96 let f = Sum::new(points.into_iter().map(DistToSquaredDiv2));
102 //let g = ZeroFn::new(); 97 //let g = ZeroFn::new();
103 let g = Scaled::new(0.5, DistTo(origin)); 98 let g = Scaled::new(0.5, DistTo(origin));
104 let τ = 0.05; 99 let τ = 0.05;
105 100
112 run_and_save("x1", &f, &g, OnCube::new(F3, Loc([0.1, 0.7])), τ)?; 107 run_and_save("x1", &f, &g, OnCube::new(F3, Loc([0.1, 0.7])), τ)?;
113 run_and_save("x2", &f, &g, OnCube::new(F2, Loc([0.1, 0.7])), τ)?; 108 run_and_save("x2", &f, &g, OnCube::new(F2, Loc([0.1, 0.7])), τ)?;
114 run_and_save("x3", &f, &g, OnCube::new(F6, Loc([0.6, 0.2])), τ) 109 run_and_save("x3", &f, &g, OnCube::new(F6, Loc([0.6, 0.2])), τ)
115 } 110 }
116 111
112 /// Runs [forward_backward] and saves the results.
117 pub fn run_and_save<F, G>( 113 pub fn run_and_save<F, G>(
118 name : &str, 114 name : &str,
119 f : &F, 115 f : &F,
120 g : &G, 116 g : &G,
121 x : OnCube, 117 x : OnCube,

mercurial