Struct fitting::gaussian::Gaussian

source ·
pub struct Gaussian<F: Float> { /* private fields */ }
Expand description

Gaussian Distribution

Implementations§

source§

impl<F: Float> Gaussian<F>

source

pub fn new(mu: F, sigma: F, a: F) -> Gaussian<F>

Create a new Gaussian with given parameters.

source

pub fn mu(&self) -> &F

Return a reference to mu.

source

pub fn mu_mut(&mut self) -> &mut F

Return a mutable reference to mu.

source

pub fn sigma(&self) -> &F

Return a reference to sigma.

source

pub fn sigma_mut(&mut self) -> &mut F

Return a mutable reference to sigma.

source

pub fn a(&self) -> &F

Return a reference to a.

source

pub fn a_mut(&mut self) -> &mut F

Return a mutable reference to a.

source

pub fn as_tuple(&self) -> (&F, &F, &F)

Return a reference to self as a tuple (mu, sigma, a).

source

pub fn as_mut_tuple(&mut self) -> (&mut F, &mut F, &mut F)

Return a mutable reference to self as a tuple (mu, sigma, a).

source

pub fn to_tuple(&self) -> (F, F, F)

Returns a copy of self as a new tuple (mu, sigma, a).

source

pub fn into_tuple(self) -> (F, F, F)

Consume self and returns a tuple (mu, sigma, a).

source

pub fn value(&self, x: F) -> F

Returns a value of gaussian function.

§Examples

Returns a value of gaussian function.

use fitting::Gaussian;

let gaussian = Gaussian::new(5., 3., 1.);
let x = 5.;
let y = gaussian.value(x);
assert_eq!(&y, gaussian.a());
source

pub fn values(&self, x_vec: Array1<F>) -> Array1<F>

Returns the values of gaussian function.

§Examples

Returns the values of gaussian function.

use fitting::approx::assert_abs_diff_eq;
use fitting::Gaussian;
use fitting::ndarray::{array, Array, Array1};

let gaussian = Gaussian::new(5., 3., 1.);
let x_vec: Array1<f64> = Array::range(1., 10., 1.);
let y_vec: Array1<f64> = gaussian.values(x_vec);
let expected_ans = array![
    0.41111229050718745,
    0.6065306597126334,
    0.8007374029168081,
    0.9459594689067654,
    1.,
    0.9459594689067654,
    0.8007374029168081,
    0.6065306597126334,
    0.41111229050718745
];
assert_abs_diff_eq!(&y_vec, &expected_ans, epsilon = 1e-9);
source

pub fn fit( x_vec: Array1<F>, y_vec: Array1<F> ) -> Result<Gaussian<F>, GaussianError>

Estimates the parameters of gaussian function for generic data. The return value is (mu, sigma, a)

This function implements the Guos Algorithm.

§Examples

Estimates the parameters for sample data.

use fitting::approx::assert_abs_diff_eq;
use fitting::Gaussian;
use fitting::ndarray::{array, Array, Array1};

let gaussian = Gaussian::new(5., 3., 1.);
let x_vec: Array1<f64> = Array::range(1., 10., 1.);
let y_vec: Array1<f64> = gaussian.values(x_vec.clone());
let estimated = Gaussian::fit(x_vec, y_vec).unwrap();
assert_abs_diff_eq!(gaussian, estimated, epsilon = 1e-9);
§Limitations
  • x_vec must have at least one element
  • All elements of y_vec must be positive numbers
  • If the distribution is “long-tailed”, it affects the fitting accuracy.
    • A detailed description can be found in Reference 1.
    • Also, you can see the reproduction and workaround in GitHub.
§References

[1] E. Pastuchov ́a and M. Z ́akopˇcan, ”Comparison of Algorithms for Fitting a Gaussian Function used in Testing Smart Sensors”, Journal of Electrical Engineering, vol. 66, no. 3, pp. 178-181, 2015.

Trait Implementations§

source§

impl<F: Float> AbsDiffEq for Gaussian<F>
where F::Epsilon: Copy,

§

type Epsilon = <F as AbsDiffEq>::Epsilon

Used for specifying relative comparisons.
source§

fn default_epsilon() -> F::Epsilon

The default tolerance to use when testing values that are close together. Read more
source§

fn abs_diff_eq(&self, other: &Self, epsilon: F::Epsilon) -> bool

A test for equality that uses the absolute difference to compute the approximate equality of two numbers.
source§

fn abs_diff_ne(&self, other: &Rhs, epsilon: Self::Epsilon) -> bool

The inverse of AbsDiffEq::abs_diff_eq.
source§

impl<F: Clone + Float> Clone for Gaussian<F>

source§

fn clone(&self) -> Gaussian<F>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<F: Debug + Float> Debug for Gaussian<F>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<F: Default + Float> Default for Gaussian<F>

source§

fn default() -> Gaussian<F>

Returns the “default value” for a type. Read more
source§

impl<'de, F> Deserialize<'de> for Gaussian<F>
where F: Deserialize<'de> + Float,

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl<F: Float> From<(F, F, F)> for Gaussian<F>

source§

fn from(tuple: (F, F, F)) -> Self

Converts to this type from the input type.
source§

impl<F: Float> From<Gaussian<F>> for (F, F, F)

source§

fn from(gaussian: Gaussian<F>) -> Self

Converts to this type from the input type.
source§

impl<F: Float> From<Gaussian<F>> for Array1<F>

source§

fn from(gaussian: Gaussian<F>) -> Self

Converts to this type from the input type.
source§

impl<F: Hash + Float> Hash for Gaussian<F>

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<F: PartialEq + Float> PartialEq for Gaussian<F>

source§

fn eq(&self, other: &Gaussian<F>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<F: PartialOrd + Float> PartialOrd for Gaussian<F>

source§

fn partial_cmp(&self, other: &Gaussian<F>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<F: Float> RelativeEq for Gaussian<F>
where F::Epsilon: Copy,

source§

fn default_max_relative() -> F::Epsilon

The default relative tolerance for testing values that are far-apart. Read more
source§

fn relative_eq( &self, other: &Self, epsilon: F::Epsilon, max_relative: F::Epsilon ) -> bool

A test for equality that uses a relative comparison if the values are far apart.
source§

fn relative_ne( &self, other: &Rhs, epsilon: Self::Epsilon, max_relative: Self::Epsilon ) -> bool

The inverse of RelativeEq::relative_eq.
source§

impl<F> Serialize for Gaussian<F>
where F: Serialize + Float,

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl<F: Float> TryFrom<ArrayBase<OwnedRepr<F>, Dim<[usize; 1]>>> for Gaussian<F>

§

type Error = &'static str

The type returned in the event of a conversion error.
source§

fn try_from(arr: Array1<F>) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl<F: Float> UlpsEq for Gaussian<F>
where F::Epsilon: Copy,

source§

fn default_max_ulps() -> u32

The default ULPs to tolerate when testing values that are far-apart. Read more
source§

fn ulps_eq(&self, other: &Self, epsilon: F::Epsilon, max_ulps: u32) -> bool

A test for equality that uses units in the last place (ULP) if the values are far apart.
source§

fn ulps_ne(&self, other: &Rhs, epsilon: Self::Epsilon, max_ulps: u32) -> bool

The inverse of UlpsEq::ulps_eq.
source§

impl<F: Copy + Float> Copy for Gaussian<F>

source§

impl<F: Eq + Float> Eq for Gaussian<F>

source§

impl<F: Float> StructuralPartialEq for Gaussian<F>

Auto Trait Implementations§

§

impl<F> RefUnwindSafe for Gaussian<F>
where F: RefUnwindSafe,

§

impl<F> Send for Gaussian<F>

§

impl<F> Sync for Gaussian<F>

§

impl<F> Unpin for Gaussian<F>
where F: Unpin,

§

impl<F> UnwindSafe for Gaussian<F>
where F: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,