pub struct DistributionLognormal { /* private fields */ }
Expand description

Defines the Lognormal distribution

Implementations§

source§

impl DistributionLognormal

source

pub fn new(mu_logx: f64, sig_logx: f64) -> Result<Self, StrError>

Creates a new Lognormal distribution

§Input
  • mu_logx – mean (μ) of log(x)
  • sig_logx – standard deviation (σ) of log(x)
Examples found in repository?
examples/distribution_lognormal.rs (line 6)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
fn main() -> Result<(), StrError> {
    // generate samples
    let mut rng = rand::thread_rng();
    let dist = DistributionLognormal::new(0.0, 0.25)?;
    let nsamples = 10_000;
    let mut data = vec![0.0; nsamples];
    for i in 0..nsamples {
        data[i] = dist.sample(&mut rng);
    }
    println!("{}", statistics(&data));

    // text-plot
    let stations = (0..25).map(|i| (i as f64) * 0.1).collect::<Vec<f64>>();
    let mut hist = Histogram::new(&stations)?;
    hist.set_bar_char('✨').set_bar_max_len(30);
    hist.count(&data);
    println!("{:.2}", hist);
    Ok(())
}
source

pub fn new_from_mu_sig(mu: f64, sig: f64) -> Result<Self, StrError>

Creates a new Lognormal distribution given mean and standard deviation parameters

§Input
  • mu – mean μ
  • sig – standard deviation σ

This function will hence calculate mu_logx (mean of log(x)) and sig_logx (std-dev of log(x))

Trait Implementations§

source§

impl ProbabilityDistribution for DistributionLognormal

source§

fn pdf(&self, x: f64) -> f64

Implements the Probability Density Function (CDF)

source§

fn cdf(&self, x: f64) -> f64

Implements the Cumulative Density Function (CDF)

source§

fn mean(&self) -> f64

Returns the Mean

source§

fn variance(&self) -> f64

Returns the Variance

source§

fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> f64

Generates a pseudo-random number belonging to this probability distribution

Auto Trait Implementations§

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, 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<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V