Struct rv::dist::UnitPowerLaw

source ·
pub struct UnitPowerLaw { /* private fields */ }
Expand description

UnitPowerLaw(α) over x in (0, 1).

§Examples

UnitPowerLaw as a conjugate prior for Bernoulli

use rv::prelude::*;

// A prior that encodes our strong belief that coins are fair:
let powlaw = UnitPowerLaw::new(5.0).unwrap();

Implementations§

source§

impl UnitPowerLaw

source

pub fn new(alpha: f64) -> Result<Self, UnitPowerLawError>

Create a UnitPowerLaw distribution with even density over (0, 1).

§Example
// Uniform
let powlaw_unif = UnitPowerLaw::new(1.0);
assert!(powlaw_unif.is_ok());

// Invalid negative parameter
let powlaw_nope  = UnitPowerLaw::new(-5.0);
assert!(powlaw_nope.is_err());
source

pub fn new_unchecked(alpha: f64) -> Self

Creates a new UnitPowerLaw without checking whether the parameters are valid.

source

pub fn uniform() -> Self

Create a UnitPowerLaw distribution with even density over (0, 1).

§Example
let powlaw = UnitPowerLaw::uniform();
assert_eq!(powlaw, UnitPowerLaw::new(1.0).unwrap());
source

pub fn alpha(&self) -> f64

Get the alpha parameter

§Example
let powlaw = UnitPowerLaw::new(5.0).unwrap();
assert_eq!(powlaw.alpha(), 5.0);
source

pub fn set_alpha(&mut self, alpha: f64) -> Result<(), UnitPowerLawError>

Set the alpha parameter

§Example
let mut powlaw = UnitPowerLaw::new(5.0).unwrap();

powlaw.set_alpha(2.0).unwrap();
assert_eq!(powlaw.alpha(), 2.0);

Will error for invalid values

assert!(powlaw.set_alpha(0.1).is_ok());
assert!(powlaw.set_alpha(0.0).is_err());
assert!(powlaw.set_alpha(-1.0).is_err());
assert!(powlaw.set_alpha(f64::INFINITY).is_err());
assert!(powlaw.set_alpha(f64::NAN).is_err());
source

pub fn set_alpha_unchecked(&mut self, alpha: f64)

Set alpha without input validation

source

pub fn alpha_inv(&self) -> f64

Evaluate or fetch cached ln(a*b)

source

pub fn alpha_ln(&self) -> f64

Evaluate or fetch cached ln(a*b)

Trait Implementations§

source§

impl Cdf<f32> for UnitPowerLaw

source§

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

The value of the Cumulative Density Function at x Read more
source§

fn sf(&self, x: &X) -> f64

Survival function, 1 - CDF(x)
source§

impl Cdf<f64> for UnitPowerLaw

source§

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

The value of the Cumulative Density Function at x Read more
source§

fn sf(&self, x: &X) -> f64

Survival function, 1 - CDF(x)
source§

impl Clone for UnitPowerLaw

source§

fn clone(&self) -> UnitPowerLaw

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<X: Booleable> ConjugatePrior<X, Bernoulli> for UnitPowerLaw

§

type Posterior = Beta

Type of the posterior distribution
§

type MCache = f64

Type of the cache for the marginal likelihood
§

type PpCache = (f64, f64)

Type of the cache for the posterior predictive
source§

fn posterior(&self, x: &DataOrSuffStat<'_, X, Bernoulli>) -> Beta

source§

fn ln_m_cache(&self) -> Self::MCache

Compute the cache for the log marginal likelihood.
source§

fn ln_m_with_cache( &self, cache: &Self::MCache, x: &DataOrSuffStat<'_, X, Bernoulli>, ) -> f64

Log marginal likelihood with supplied cache.
source§

fn ln_pp_cache(&self, x: &DataOrSuffStat<'_, X, Bernoulli>) -> Self::PpCache

Compute the cache for the Log posterior predictive of y given x. Read more
source§

fn ln_pp_with_cache(&self, cache: &Self::PpCache, y: &X) -> f64

Log posterior predictive of y given x with supplied ln(norm)
source§

fn posterior_from_suffstat(&self, stat: &Fx::Stat) -> Self::Posterior

Computes the posterior distribution from the data
source§

fn ln_m(&self, x: &DataOrSuffStat<'_, X, Fx>) -> f64

The log marginal likelihood
source§

fn ln_pp(&self, y: &X, x: &DataOrSuffStat<'_, X, Fx>) -> f64

Log posterior predictive of y given x
source§

fn m(&self, x: &DataOrSuffStat<'_, X, Fx>) -> f64

Marginal likelihood of x
source§

fn pp_with_cache(&self, cache: &Self::PpCache, y: &X) -> f64

source§

fn pp(&self, y: &X, x: &DataOrSuffStat<'_, X, Fx>) -> f64

Posterior Predictive distribution
source§

impl ContinuousDistr<Bernoulli> for UnitPowerLaw

source§

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

The value of the Probability Density Function (PDF) at x Read more
source§

fn ln_pdf(&self, x: &X) -> f64

The value of the log Probability Density Function (PDF) at x Read more
source§

impl ContinuousDistr<f32> for UnitPowerLaw

source§

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

The value of the Probability Density Function (PDF) at x Read more
source§

fn ln_pdf(&self, x: &X) -> f64

The value of the log Probability Density Function (PDF) at x Read more
source§

impl ContinuousDistr<f64> for UnitPowerLaw

source§

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

The value of the Probability Density Function (PDF) at x Read more
source§

fn ln_pdf(&self, x: &X) -> f64

The value of the log Probability Density Function (PDF) at x Read more
source§

impl Debug for UnitPowerLaw

source§

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

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

impl Default for UnitPowerLaw

source§

fn default() -> Self

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

impl<'de> Deserialize<'de> for UnitPowerLaw

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 Display for UnitPowerLaw

source§

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

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

impl Entropy for UnitPowerLaw

source§

fn entropy(&self) -> f64

The entropy, H(X)
source§

impl From<&UnitPowerLaw> for Beta

source§

fn from(powlaw: &UnitPowerLaw) -> Beta

Converts to this type from the input type.
source§

impl From<&UnitPowerLaw> for String

source§

fn from(powlaw: &UnitPowerLaw) -> String

Converts to this type from the input type.
source§

impl HasDensity<Bernoulli> for UnitPowerLaw

source§

fn ln_f(&self, x: &Bernoulli) -> f64

Probability function Read more
source§

fn f(&self, x: &X) -> f64

Probability function Read more
source§

impl HasDensity<f32> for UnitPowerLaw

source§

fn ln_f(&self, x: &f32) -> f64

Probability function Read more
source§

fn f(&self, x: &X) -> f64

Probability function Read more
source§

impl HasDensity<f64> for UnitPowerLaw

source§

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

Probability function Read more
source§

fn f(&self, x: &X) -> f64

Probability function Read more
source§

impl HasSuffStat<f32> for UnitPowerLaw

§

type Stat = UnitPowerLawSuffStat

source§

fn empty_suffstat(&self) -> Self::Stat

source§

fn ln_f_stat(&self, stat: &Self::Stat) -> f64

Return the log likelihood for the data represented by the sufficient statistic.
source§

impl HasSuffStat<f64> for UnitPowerLaw

§

type Stat = UnitPowerLawSuffStat

source§

fn empty_suffstat(&self) -> Self::Stat

source§

fn ln_f_stat(&self, stat: &Self::Stat) -> f64

Return the log likelihood for the data represented by the sufficient statistic.
source§

impl InverseCdf<f32> for UnitPowerLaw

source§

fn invcdf(&self, p: f64) -> f32

The value of the x at the given probability in the CDF Read more
source§

fn quantile(&self, p: f64) -> X

Alias for invcdf
source§

fn interval(&self, p: f64) -> (X, X)

Interval containing p proportion for the probability Read more
source§

impl InverseCdf<f64> for UnitPowerLaw

source§

fn invcdf(&self, p: f64) -> f64

The value of the x at the given probability in the CDF Read more
source§

fn quantile(&self, p: f64) -> X

Alias for invcdf
source§

fn interval(&self, p: f64) -> (X, X)

Interval containing p proportion for the probability Read more
source§

impl Kurtosis for UnitPowerLaw

source§

impl Mean<f32> for UnitPowerLaw

source§

fn mean(&self) -> Option<f32>

Returns None if the mean is undefined
source§

impl Mean<f64> for UnitPowerLaw

source§

fn mean(&self) -> Option<f64>

Returns None if the mean is undefined
source§

impl Mode<f32> for UnitPowerLaw

source§

fn mode(&self) -> Option<f32>

Returns None if the mode is undefined or is not a single value
source§

impl Mode<f64> for UnitPowerLaw

source§

fn mode(&self) -> Option<f64>

Returns None if the mode is undefined or is not a single value
source§

impl Parameterized for UnitPowerLaw

§

type Parameters = f64

source§

fn emit_params(&self) -> Self::Parameters

source§

fn from_params(alpha: Self::Parameters) -> Self

source§

impl PartialEq for UnitPowerLaw

source§

fn eq(&self, other: &UnitPowerLaw) -> 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 Sampleable<Bernoulli> for UnitPowerLaw

source§

fn draw<R: Rng>(&self, rng: &mut R) -> Bernoulli

Single draw from the Rv Read more
source§

fn sample<R: Rng>(&self, n: usize, rng: &mut R) -> Vec<X>

Multiple draws of the Rv Read more
source§

fn sample_stream<'r, R: Rng>( &'r self, rng: &'r mut R, ) -> Box<dyn Iterator<Item = X> + 'r>

Create a never-ending iterator of samples Read more
source§

impl Sampleable<f32> for UnitPowerLaw

source§

fn draw<R: Rng>(&self, rng: &mut R) -> f32

Single draw from the Rv Read more
source§

fn sample<R: Rng>(&self, n: usize, rng: &mut R) -> Vec<f32>

Multiple draws of the Rv Read more
source§

fn sample_stream<'r, R: Rng>( &'r self, rng: &'r mut R, ) -> Box<dyn Iterator<Item = X> + 'r>

Create a never-ending iterator of samples Read more
source§

impl Sampleable<f64> for UnitPowerLaw

source§

fn draw<R: Rng>(&self, rng: &mut R) -> f64

Single draw from the Rv Read more
source§

fn sample<R: Rng>(&self, n: usize, rng: &mut R) -> Vec<f64>

Multiple draws of the Rv Read more
source§

fn sample_stream<'r, R: Rng>( &'r self, rng: &'r mut R, ) -> Box<dyn Iterator<Item = X> + 'r>

Create a never-ending iterator of samples Read more
source§

impl Serialize for UnitPowerLaw

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 Skewness for UnitPowerLaw

source§

impl Support<Bernoulli> for UnitPowerLaw

source§

fn supports(&self, x: &Bernoulli) -> bool

Returns true if x is in the support of the Rv Read more
source§

impl Support<f32> for UnitPowerLaw

source§

fn supports(&self, x: &f32) -> bool

Returns true if x is in the support of the Rv Read more
source§

impl Support<f64> for UnitPowerLaw

source§

fn supports(&self, x: &f64) -> bool

Returns true if x is in the support of the Rv Read more
source§

impl Variance<f64> for UnitPowerLaw

source§

fn variance(&self) -> Option<f64>

Returns None if the variance is undefined

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> CloneToUninit for T
where T: Clone,

source§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> IntoEither for T

source§

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 more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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 more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
source§

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

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. 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<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

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

source§

impl<S, O, T> Process<S, O> for T
where T: Sampleable<S> + HasDensity<O>,

source§

impl<X, T> Rv<X> for T
where T: Sampleable<X> + HasDensity<X>,

source§

impl<T> Scalar for T
where T: 'static + Clone + PartialEq + Debug,

source§

impl<T> SendAlias for T

source§

impl<T> SyncAlias for T