pub struct Normal<F: Float> {
pub loc: F,
pub scale: F,
/* private fields */
}Expand description
Normal distribution structure
Fields§
§loc: FMean (location) parameter
scale: FStandard deviation (scale) parameter
Implementations§
Source§impl<F: Float + NumCast + Display> Normal<F>
impl<F: Float + NumCast + Display> Normal<F>
Sourcepub fn new(loc: F, scale: F) -> StatsResult<Self>
pub fn new(loc: F, scale: F) -> StatsResult<Self>
Create a new normal distribution with given mean and standard deviation
§Arguments
loc- Mean (location) parameterscale- Standard deviation (scale) parameter
§Returns
- A new Normal distribution instance
§Examples
use scirs2_stats::distributions::normal::Normal;
let norm = Normal::new(0.0f64, 1.0).expect("Operation failed");Sourcepub fn pdf(&self, x: F) -> F
pub fn pdf(&self, x: F) -> F
Calculate the probability density function (PDF) at a given point
§Arguments
x- The point at which to evaluate the PDF
§Returns
- The value of the PDF at the given point
§Examples
use scirs2_stats::distributions::normal::Normal;
let norm = Normal::new(0.0f64, 1.0).expect("Operation failed");
let pdf_at_zero = norm.pdf(0.0);
assert!((pdf_at_zero - 0.3989423).abs() < 1e-7);Sourcepub fn cdf(&self, x: F) -> F
pub fn cdf(&self, x: F) -> F
Calculate the cumulative distribution function (CDF) at a given point
§Arguments
x- The point at which to evaluate the CDF
§Returns
- The value of the CDF at the given point
§Examples
use scirs2_stats::distributions::normal::Normal;
let norm = Normal::new(0.0f64, 1.0).expect("Operation failed");
let cdf_at_zero = norm.cdf(0.0);
assert!((cdf_at_zero - 0.5).abs() < 1e-10);Sourcepub fn ppf(&self, p: F) -> StatsResult<F>
pub fn ppf(&self, p: F) -> StatsResult<F>
Inverse of the cumulative distribution function (quantile function)
§Arguments
p- Probability value (between 0 and 1)
§Returns
- The value x such that CDF(x) = p
§Examples
use scirs2_stats::distributions::normal::Normal;
let norm = Normal::new(0.0f64, 1.0).expect("Operation failed");
let x = norm.ppf(0.975).expect("Operation failed");
assert!((x - 1.96).abs() < 1e-2);Sourcepub fn rvs(&self, size: usize) -> StatsResult<Array1<F>>
pub fn rvs(&self, size: usize) -> StatsResult<Array1<F>>
Generate random samples from the distribution
§Arguments
size- Number of samples to generate
§Returns
- Vector of random samples
§Examples
use scirs2_stats::distributions::normal::Normal;
let norm = Normal::new(0.0f64, 1.0).expect("Operation failed");
let samples = norm.rvs(1000).expect("Operation failed");
assert_eq!(samples.len(), 1000);Trait Implementations§
Source§impl<F: Float + NumCast + Display> ContinuousDistribution<F> for Normal<F>
impl<F: Float + NumCast + Display> ContinuousDistribution<F> for Normal<F>
Source§fn ppf(&self, p: F) -> StatsResult<F>
fn ppf(&self, p: F) -> StatsResult<F>
Percent point function (inverse CDF) Read more
Source§fn pdf_array(&self, x: &ArrayView1<'_, F>) -> Array1<F>
fn pdf_array(&self, x: &ArrayView1<'_, F>) -> Array1<F>
Source§fn cdf_array(&self, x: &ArrayView1<'_, F>) -> Array1<F>
fn cdf_array(&self, x: &ArrayView1<'_, F>) -> Array1<F>
Source§fn ppf_array(&self, q: &ArrayView1<'_, F>) -> StatsResult<Array1<F>>
fn ppf_array(&self, q: &ArrayView1<'_, F>) -> StatsResult<Array1<F>>
Auto Trait Implementations§
impl<F> Freeze for Normal<F>where
F: Freeze,
impl<F> RefUnwindSafe for Normal<F>where
F: RefUnwindSafe,
impl<F> Send for Normal<F>where
F: Send,
impl<F> Sync for Normal<F>where
F: Sync,
impl<F> Unpin for Normal<F>where
F: Unpin,
impl<F> UnsafeUnpin for Normal<F>where
F: UnsafeUnpin,
impl<F> UnwindSafe for Normal<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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
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>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
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
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.