pub struct Efd<const D: usize>{ /* private fields */ }
Expand description
Elliptical Fourier Descriptor coefficients. Provide transformation between discrete points and coefficients.
Start with Efd::from_curve()
and its related methods.
§Normalization
The geometric normalization of EFD coefficients.
Implements Kuhl and Giardina method of normalizing the coefficients An, Bn, Cn, Dn. Performs 3 separate normalizations. First, it makes the data location invariant by re-scaling the data to a common origin. Secondly, the data is rotated with respect to the major axis. Thirdly, the coefficients are normalized with regard to the absolute value of A₁.
Please see Efd::as_geo()
and GeoVar
for more information.
Implementations§
source§impl<const D: usize> Efd<D>
impl<const D: usize> Efd<D>
sourcepub fn from_parts_unchecked(coeffs: Coeffs<D>, geo: GeoVar<Rot<D>, D>) -> Self
pub fn from_parts_unchecked(coeffs: Coeffs<D>, geo: GeoVar<Rot<D>, D>) -> Self
Create object from coefficients and geometric variables.
§Raw Coefficients
There is no “check method” for the input coefficients. Please use
Efd::from_curve()
and its related methods to create the object. This
method is designed for loading coefficients from external sources.
See also Efd::from_coeffs_unchecked()
and Efd::into_inner()
.
§Panics
Panics if the harmonic is zero. (coeffs.len() == 0
)
use efd::{Efd2, GeoVar};
let curve = Efd2::from_parts_unchecked(vec![], GeoVar::identity()).recon(20);
sourcepub fn from_coeffs_unchecked(coeffs: Coeffs<D>) -> Self
pub fn from_coeffs_unchecked(coeffs: Coeffs<D>) -> Self
Create object from coefficients without check.
§Panics
Panics if the harmonic is zero. (coeffs.len() == 0
)
sourcepub fn from_curve<C>(curve: C, is_open: bool) -> Selfwhere
C: Curve<D>,
pub fn from_curve<C>(curve: C, is_open: bool) -> Selfwhere
C: Curve<D>,
Fully automated coefficient calculation.
- The initial harmonic number is the same as the curve point.
- Fourier Power Anaysis (FPA) uses 99.99% threshold.
§Tail End Closed
If curve.first() != curve.last()
, the curve will be automatically
closed when is_open
is false.
§Open Curve Option
The open curve option is for the curve that duplicated a reversed part of itself. For example,
let efd = efd::Efd2::from_curve(curve_open, true);
is equivalent to
let curve_closed = curve_open
.iter()
.chain(curve_open.iter().rev().skip(1))
.cloned()
.collect::<Vec<_>>();
let efd = efd::Efd2::from_curve(curve_closed, false);
but not actually increase the data size.
§Panics
Panics if the curve length is not greater than 2 in debug mode. This
function check the lengths only. Please use valid_curve()
to verify
the curve if there has NaN input.
sourcepub fn from_curve_nyquist<C>(curve: C, is_open: bool) -> Selfwhere
C: Curve<D>,
pub fn from_curve_nyquist<C>(curve: C, is_open: bool) -> Selfwhere
C: Curve<D>,
Same as Efd::from_curve()
, but if your sampling points are large,
use Nyquist Frequency as the initial harmonic number.
Please ensure the sampling points meet the Nyquist–Shannon sampling theorem.
See also harmonic_nyquist
.
sourcepub fn from_curve_harmonic<C>(curve: C, is_open: bool, harmonic: usize) -> Selfwhere
C: Curve<D>,
pub fn from_curve_harmonic<C>(curve: C, is_open: bool, harmonic: usize) -> Selfwhere
C: Curve<D>,
Manual coefficient calculation.
- The initial harmonic is decided by user.
harmonic()
is used inEfd::from_curve()
.harmonic_nyquist()
is used inEfd::from_curve_nyquist()
.
- No harmonic reduced.
- Please call
Efd::fourier_power_anaysis()
manually.
- Please call
§Panics
Panics if the specific harmonic is zero or the curve length is not
greater than 2 in the debug mode. This function check the lengths
only. Please use valid_curve()
to verify the curve if there has NaN
input.
sourcepub fn from_curve_harmonic_unnorm<C>(
curve: C,
is_open: bool,
harmonic: usize
) -> Selfwhere
C: Curve<D>,
pub fn from_curve_harmonic_unnorm<C>(
curve: C,
is_open: bool,
harmonic: usize
) -> Selfwhere
C: Curve<D>,
Same as Efd::from_curve_harmonic()
but without normalization.
Please call Efd::normalized()
if you want to normalize later.
sourcepub fn fourier_power_anaysis<T>(self, threshold: T) -> Self
pub fn fourier_power_anaysis<T>(self, threshold: T) -> Self
A builder method using Fourier Power Anaysis (FPA) to reduce the harmonic number.
The coefficient memory will be saved but cannot be used twice due to undersampling.
The default threshold is 99.99%.
§Panics
Panics if the threshold is not in 0..1, or the harmonic is zero.
sourcepub fn set_harmonic(&mut self, harmonic: usize)
pub fn set_harmonic(&mut self, harmonic: usize)
Set the harmonic number of the coefficients.
§Panics
Panics if the harmonic is zero or greater than the current harmonic.
sourcepub fn normalized(self) -> Self
pub fn normalized(self) -> Self
Force normalize the coefficients.
If the coefficients are constructed by *_unnorm
or *_unchecked
methods, this method will normalize them.
See also Efd::from_curve_harmonic_unnorm()
.
§Panics
Panics if the harmonic is zero.
sourcepub fn into_inner(self) -> (Coeffs<D>, GeoVar<Rot<D>, D>)
pub fn into_inner(self) -> (Coeffs<D>, GeoVar<Rot<D>, D>)
Consume self and return the parts of this type.
See also Efd::from_parts_unchecked()
.
sourcepub fn coeff(&self, harmonic: usize) -> &Kernel<D>
pub fn coeff(&self, harmonic: usize) -> &Kernel<D>
Get a view to the specific coefficients. (0..self.harmonic()
)
sourcepub fn coeffs_iter(&self) -> impl Iterator<Item = &Kernel<D>>
pub fn coeffs_iter(&self) -> impl Iterator<Item = &Kernel<D>>
Get an iterator over all the coefficients per harmonic.
sourcepub fn coeffs_iter_mut(&mut self) -> impl Iterator<Item = &mut Kernel<D>>
pub fn coeffs_iter_mut(&mut self) -> impl Iterator<Item = &mut Kernel<D>>
Get a mutable iterator over all the coefficients per harmonic.
Warning: If you want to change the coefficients, the geometric variables will be wrong.
sourcepub fn as_geo_mut(&mut self) -> &mut GeoVar<Rot<D>, D>
pub fn as_geo_mut(&mut self) -> &mut GeoVar<Rot<D>, D>
Get the mutable reference of geometric variables.
sourcepub fn is_valid(&self) -> bool
pub fn is_valid(&self) -> bool
Check if the coefficients are valid.
- The harmonic number must be greater than 0.
- All the coefficients must be finite number.
It is only helpful if this object is constructed by
Efd::from_parts_unchecked()
.
sourcepub fn err(&self, rhs: &Self) -> f64
pub fn err(&self, rhs: &Self) -> f64
Calculate the L1 distance between two coefficient set.
For more distance methods, please see Distance
.
sourcepub fn reverse_inplace(&mut self)
pub fn reverse_inplace(&mut self)
Reverse the order of described curve then return a mutable reference.
sourcepub fn reversed(self) -> Self
pub fn reversed(self) -> Self
Consume and return a reversed version of the coefficients.
This method can avoid mutable require.
sourcepub fn recon(&self, n: usize) -> Vec<[f64; D]>
pub fn recon(&self, n: usize) -> Vec<[f64; D]>
Reconstruct the described curve.
If the described curve is open, the time series is 0..PI
instead of
0..TAU
.
sourcepub fn recon_norm(&self, n: usize) -> Vec<[f64; D]>
pub fn recon_norm(&self, n: usize) -> Vec<[f64; D]>
Reconstruct the described curve. (t=0~TAU
)
Normalized curve is without transformation.
sourcepub fn recon_by(&self, t: &[f64]) -> Vec<[f64; D]>
pub fn recon_by(&self, t: &[f64]) -> Vec<[f64; D]>
Reconstruct a described curve in a time series t
.
let efd = efd::Efd2::from_curve(curve, false);
let sig = efd::PathSig::new(curve, false);
let curve_recon = efd.recon_by(sig.as_t());
See also PathSig
.
sourcepub fn recon_norm_by(&self, t: &[f64]) -> Vec<[f64; D]>
pub fn recon_norm_by(&self, t: &[f64]) -> Vec<[f64; D]>
Reconstruct a normalized curve in a time series t
.
Normalized curve is without transformation.
See also Efd::recon_by()
.
Trait Implementations§
source§impl<const D: usize> Distance for Efd<D>
impl<const D: usize> Distance for Efd<D>
source§fn as_components(&self) -> impl Iterator<Item = &f64>
fn as_components(&self) -> impl Iterator<Item = &f64>
source§fn square_err(&self, rhs: &impl Distance) -> f64
fn square_err(&self, rhs: &impl Distance) -> f64
source§fn lp_err(&self, rhs: &impl Distance, p: f64) -> f64
fn lp_err(&self, rhs: &impl Distance, p: f64) -> f64
source§fn linf_err(&self, rhs: &impl Distance) -> f64
fn linf_err(&self, rhs: &impl Distance) -> f64
source§fn l0_norm(&self) -> f64
fn l0_norm(&self) -> f64
source§fn l1_norm(&self) -> f64
fn l1_norm(&self) -> f64
source§fn l2_norm(&self) -> f64
fn l2_norm(&self) -> f64
Auto Trait Implementations§
impl<const D: usize> !Freeze for Efd<D>
impl<const D: usize> !RefUnwindSafe for Efd<D>
impl<const D: usize> !Send for Efd<D>
impl<const D: usize> !Sync for Efd<D>
impl<const D: usize> !Unpin for Efd<D>
impl<const D: usize> !UnwindSafe for Efd<D>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self
from the equivalent element of its
superset. Read moresource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self
is actually part of its subset T
(and can be converted to it).source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset
but without any property checks. Always succeeds.source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.