Mon, 21 Oct 2024 23:07:01 -0500
Basic face image export
5 | 1 | |
2 | use alg_tools::mapping::Apply; | |
3 | use crate::manifold::ManifoldPoint; | |
4 | use crate::fb::{Grad, Desc}; | |
5 | ||
6 | /// Structure for distance-to functions | |
7 | 7 | pub struct DistTo<M : ManifoldPoint>(pub M); |
5 | 8 | |
9 | impl<M : ManifoldPoint> Apply<M> for DistTo<M> { | |
10 | type Output = f64; | |
11 | ||
12 | fn apply(&self, x : M) -> Self::Output { | |
7 | 13 | self.0.dist_to(&x) |
5 | 14 | } |
15 | } | |
16 | ||
17 | impl<'a, M : ManifoldPoint> Apply<&'a M> for DistTo<M> { | |
18 | type Output = f64; | |
19 | ||
20 | fn apply(&self, x : &'a M) -> Self::Output { | |
7 | 21 | self.0.dist_to(x) |
5 | 22 | } |
23 | } | |
24 | ||
25 | /// Structure for distance-to functions | |
7 | 26 | pub struct DistToSquaredDiv2<M : ManifoldPoint>(pub M); |
5 | 27 | |
28 | impl<M : ManifoldPoint> Apply<M> for DistToSquaredDiv2<M> { | |
29 | type Output = f64; | |
30 | ||
31 | fn apply(&self, x : M) -> Self::Output { | |
7 | 32 | let d = self.0.dist_to(&x); |
5 | 33 | d*d / 2.0 |
34 | } | |
35 | } | |
36 | ||
37 | impl<'a, M : ManifoldPoint> Apply<&'a M> for DistToSquaredDiv2<M> { | |
38 | type Output = f64; | |
39 | ||
40 | fn apply(&self, x : &'a M) -> Self::Output { | |
7 | 41 | let d = self.0.dist_to(x); |
5 | 42 | d*d / 2.0 |
43 | } | |
44 | } | |
45 | ||
46 | impl<M : ManifoldPoint> Desc<M> for DistToSquaredDiv2<M> { | |
47 | fn desc(&self, τ : f64, x : M) -> M { | |
8 | 48 | let t = self.grad(&x) * τ; |
49 | x.exp(&t) | |
5 | 50 | } |
51 | } | |
52 | ||
53 | impl<M : ManifoldPoint> Grad<M> for DistToSquaredDiv2<M> { | |
54 | fn grad(&self, x : &M) -> M::Tangent { | |
7 | 55 | x.log(&self.0) |
5 | 56 | } |
57 | } |