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