Struct fitting::Gaussian

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

Gaussian Distribution

Implementations§

Create a new Gaussian with given parameters.

Return a reference to mu.

Return a mutable reference to mu.

Return a reference to sigma.

Return a mutable reference to sigma.

Return a reference to a.

Return a mutable reference to a.

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

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

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

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

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());

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);

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§

Used for specifying relative comparisons.
The default tolerance to use when testing values that are close together. Read more
A test for equality that uses the absolute difference to compute the approximate equality of two numbers.
The inverse of AbsDiffEq::abs_diff_eq.
Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
Deserialize this value from the given Serde deserializer. Read more
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Feeds this value into the given Hasher. Read more
Feeds a slice of this type into the given Hasher. Read more
This method tests for self and other values to be equal, and is used by ==.
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
This method tests greater than (for self and other) and is used by the > operator. Read more
This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
The default relative tolerance for testing values that are far-apart. Read more
A test for equality that uses a relative comparison if the values are far apart.
The inverse of RelativeEq::relative_eq.
Serialize this value into the given Serde serializer. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The default ULPs to tolerate when testing values that are far-apart. Read more
A test for equality that uses units in the last place (ULP) if the values are far apart.
The inverse of UlpsEq::ulps_eq.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.