Shifted

Struct Shifted 

Source
pub struct Shifted<D> { /* private fields */ }
Expand description

A wrapper for distributions that adds a shift parameter

§Example

use rv::prelude::*;
use rv::dist::{Shifted, Gaussian};

let shifted = Shifted::new(Gaussian::standard(), 5.0).expect("Valid Input");

assert_eq!(shifted.mean(), Some(5.0));
assert_eq!(shifted.variance(), Some(1.0));

Implementations§

Source§

impl<D> Shifted<D>

Source

pub fn new(parent: D, shift: f64) -> Result<Self, ShiftedError>

Create a new shifted distribution with a given parent distribution and a offset parameter.

§Example
use rv::prelude::*;

let _ok = Shifted::new(Gaussian::standard(), 5.0).unwrap();
let _err = Shifted::new(Gaussian::standard(), f64::INFINITY);
Source

pub fn new_unchecked(parent: D, shift: f64) -> Self

Create a new Shifted distribution without checking the shift parameter is finite.

Source

pub fn shift(&self) -> f64

Extract the shift from a given Shifted distribution

§Example
use rv::prelude::*;

let dist = Shifted::new(Gaussian::standard(), 5.0).unwrap();

assert_eq!(dist.shift(), 5.0);

Trait Implementations§

Source§

impl<D> Cdf<f64> for Shifted<D>
where D: Cdf<f64>,

Source§

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

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

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

Survival function, 1 - CDF(x)
Source§

impl<D: Clone> Clone for Shifted<D>

Source§

fn clone(&self) -> Shifted<D>

Returns a duplicate 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<Pr, Fx> ConjugatePrior<f64, Shifted<Fx>> for ShiftedPrior<Pr, Fx>
where Pr: ConjugatePrior<f64, Fx, Posterior = Pr>, Fx: HasSuffStat<f64> + Shiftable + HasDensity<f64>, Shifted<Fx>: HasSuffStat<f64, Stat = ShiftedSuffStat<Fx::Stat>>,

Source§

type Posterior = ShiftedPrior<Pr, Fx>

Type of the posterior distribution
Source§

type MCache = <Pr as ConjugatePrior<f64, Fx>>::MCache

Type of the cache for the marginal likelihood
Source§

type PpCache = <Pr as ConjugatePrior<f64, Fx>>::PpCache

Type of the cache for the posterior predictive
Source§

fn empty_stat(&self) -> ShiftedSuffStat<Fx::Stat>

Generate and empty sufficient statistic
Source§

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

Computes the posterior distribution from the data
Source§

fn posterior(&self, x: &DataOrSuffStat<'_, f64, Shifted<Fx>>) -> Self::Posterior

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<'_, f64, Shifted<Fx>>, ) -> f64

Log marginal likelihood with supplied cache.
Source§

fn ln_pp_cache(&self, x: &DataOrSuffStat<'_, f64, Shifted<Fx>>) -> 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: &f64) -> f64

Log posterior predictive of y given x with supplied ln(norm)
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<D> ContinuousDistr<f64> for Shifted<D>
where D: ContinuousDistr<f64>,

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<D: Debug> Debug for Shifted<D>

Source§

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

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

impl<'de, D> Deserialize<'de> for Shifted<D>
where D: Deserialize<'de>,

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<D> Entropy for Shifted<D>
where D: Entropy,

Source§

fn entropy(&self) -> f64

The entropy, H(X)
Source§

impl<D> HasDensity<f64> for Shifted<D>
where D: HasDensity<f64>,

Source§

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

Probability function Read more
Source§

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

Probability function Read more
Source§

impl<D> HasSuffStat<f64> for Shifted<D>
where D: HasSuffStat<f64>,

Source§

type Stat = ShiftedSuffStat<<D as HasSuffStat<f64>>::Stat>

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<D> InverseCdf<f64> for Shifted<D>
where D: InverseCdf<f64>,

Source§

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

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

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

Interval containing p proportion for the probability Read more
Source§

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

Alias for invcdf
Source§

impl<D> Kurtosis for Shifted<D>
where D: Kurtosis,

Source§

impl<D> Mean<f64> for Shifted<D>
where D: Mean<f64>,

Source§

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

Returns None if the mean is undefined
Source§

impl<D> Median<f64> for Shifted<D>
where D: Median<f64>,

Source§

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

Returns None if the median is undefined
Source§

impl<D> Mode<f64> for Shifted<D>
where D: Mode<f64>,

Source§

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

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

impl<D> Parameterized for Shifted<D>
where D: Parameterized,

Source§

type Parameters = ShiftedParameters<D>

Source§

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

Source§

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

Source§

fn map_params(&self, f: impl Fn(Self::Parameters) -> Self::Parameters) -> Self

Source§

impl<D: PartialEq> PartialEq for Shifted<D>

Source§

fn eq(&self, other: &Shifted<D>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<Pr, Fx> Sampleable<Shifted<Fx>> for ShiftedPrior<Pr, Fx>
where Pr: Sampleable<Fx>, Fx: Shiftable,

Source§

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

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<D> Sampleable<f64> for Shifted<D>
where D: Sampleable<f64>,

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<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<D> Serialize for Shifted<D>
where D: Serialize,

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<D> Shiftable for Shifted<D>
where D: Shiftable,

Source§

type Output = Shifted<D>

Source§

type Error = ShiftedError

Source§

fn shifted(self, shift: f64) -> Result<Self::Output, Self::Error>
where Self: Sized,

Source§

fn shifted_unchecked(self, shift: f64) -> Self::Output
where Self: Sized,

Source§

impl<D> Skewness for Shifted<D>
where D: Skewness,

Source§

impl<D> Support<f64> for Shifted<D>
where D: Support<f64>,

Source§

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

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

impl<D> Variance<f64> for Shifted<D>
where D: Variance<f64>,

Source§

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

Returns None if the variance is undefined
Source§

impl<D> StructuralPartialEq for Shifted<D>

Auto Trait Implementations§

§

impl<D> Freeze for Shifted<D>
where D: Freeze,

§

impl<D> RefUnwindSafe for Shifted<D>
where D: RefUnwindSafe,

§

impl<D> Send for Shifted<D>
where D: Send,

§

impl<D> Sync for Shifted<D>
where D: Sync,

§

impl<D> Unpin for Shifted<D>
where D: Unpin,

§

impl<D> UnwindSafe for Shifted<D>
where D: UnwindSafe,

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§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

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

Source§

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,

Source§

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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>,

Source§

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