pub struct Gaussian<F: Float> { /* private fields */ }
Expand description
Gaussian Distribution
Implementations§
source§impl<F: Float> Gaussian<F>
impl<F: Float> Gaussian<F>
sourcepub fn as_mut_tuple(&mut self) -> (&mut F, &mut F, &mut F)
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)
.
sourcepub fn into_tuple(self) -> (F, F, F)
pub fn into_tuple(self) -> (F, F, F)
Consume self
and returns a tuple (mu, sigma, a)
.
sourcepub fn value(&self, x: F) -> F
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());
sourcepub fn values(&self, x_vec: Array1<F>) -> Array1<F>
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);
sourcepub fn fit(
x_vec: Array1<F>,
y_vec: Array1<F>
) -> Result<Gaussian<F>, GaussianError>
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
Trait Implementations§
source§impl<F: Float> AbsDiffEq for Gaussian<F>
impl<F: Float> AbsDiffEq for Gaussian<F>
source§fn default_epsilon() -> F::Epsilon
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
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
fn abs_diff_ne(&self, other: &Rhs, epsilon: Self::Epsilon) -> bool
The inverse of
AbsDiffEq::abs_diff_eq
.source§impl<'de, F> Deserialize<'de> for Gaussian<F>where
F: Deserialize<'de> + Float,
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>,
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: PartialEq + Float> PartialEq for Gaussian<F>
impl<F: PartialEq + Float> PartialEq for Gaussian<F>
source§impl<F: PartialOrd + Float> PartialOrd for Gaussian<F>
impl<F: PartialOrd + Float> PartialOrd for Gaussian<F>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
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 moresource§impl<F: Float> RelativeEq for Gaussian<F>
impl<F: Float> RelativeEq for Gaussian<F>
source§fn default_max_relative() -> F::Epsilon
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
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
fn relative_ne( &self, other: &Rhs, epsilon: Self::Epsilon, max_relative: Self::Epsilon ) -> bool
The inverse of
RelativeEq::relative_eq
.source§impl<F: Float> UlpsEq for Gaussian<F>
impl<F: Float> UlpsEq for Gaussian<F>
impl<F: Copy + Float> Copy for Gaussian<F>
impl<F: Eq + Float> Eq for Gaussian<F>
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> 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
Mutably borrows from an owned value. Read more