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
impl UnitPowerLaw
sourcepub fn new(alpha: f64) -> Result<Self, UnitPowerLawError>
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());
sourcepub fn new_unchecked(alpha: f64) -> Self
pub fn new_unchecked(alpha: f64) -> Self
Creates a new UnitPowerLaw without checking whether the parameters are valid.
sourcepub fn uniform() -> Self
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());
sourcepub fn alpha(&self) -> f64
pub fn alpha(&self) -> f64
Get the alpha parameter
§Example
let powlaw = UnitPowerLaw::new(5.0).unwrap();
assert_eq!(powlaw.alpha(), 5.0);
sourcepub fn set_alpha(&mut self, alpha: f64) -> Result<(), UnitPowerLawError>
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());
sourcepub fn set_alpha_unchecked(&mut self, alpha: f64)
pub fn set_alpha_unchecked(&mut self, alpha: f64)
Set alpha without input validation
Trait Implementations§
source§impl Cdf<f32> for UnitPowerLaw
impl Cdf<f32> for UnitPowerLaw
source§impl Cdf<f64> for UnitPowerLaw
impl Cdf<f64> for UnitPowerLaw
source§impl Clone for UnitPowerLaw
impl Clone for UnitPowerLaw
source§fn clone(&self) -> UnitPowerLaw
fn clone(&self) -> UnitPowerLaw
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl<X: Booleable> ConjugatePrior<X, Bernoulli> for UnitPowerLaw
impl<X: Booleable> ConjugatePrior<X, Bernoulli> for UnitPowerLaw
fn posterior(&self, x: &DataOrSuffStat<'_, X, Bernoulli>) -> Beta
source§fn ln_m_cache(&self) -> Self::MCache
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
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
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
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
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
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
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
fn m(&self, x: &DataOrSuffStat<'_, X, Fx>) -> f64
Marginal likelihood of x
fn pp_with_cache(&self, cache: &Self::PpCache, y: &X) -> f64
source§impl ContinuousDistr<Bernoulli> for UnitPowerLaw
impl ContinuousDistr<Bernoulli> for UnitPowerLaw
source§impl ContinuousDistr<f32> for UnitPowerLaw
impl ContinuousDistr<f32> for UnitPowerLaw
source§impl ContinuousDistr<f64> for UnitPowerLaw
impl ContinuousDistr<f64> for UnitPowerLaw
source§impl Debug for UnitPowerLaw
impl Debug for UnitPowerLaw
source§impl Default for UnitPowerLaw
impl Default for UnitPowerLaw
source§impl<'de> Deserialize<'de> for UnitPowerLaw
impl<'de> Deserialize<'de> for UnitPowerLaw
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
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
impl Display for UnitPowerLaw
source§impl From<&UnitPowerLaw> for Beta
impl From<&UnitPowerLaw> for Beta
source§fn from(powlaw: &UnitPowerLaw) -> Beta
fn from(powlaw: &UnitPowerLaw) -> Beta
Converts to this type from the input type.
source§impl From<&UnitPowerLaw> for String
impl From<&UnitPowerLaw> for String
source§fn from(powlaw: &UnitPowerLaw) -> String
fn from(powlaw: &UnitPowerLaw) -> String
Converts to this type from the input type.
source§impl HasDensity<Bernoulli> for UnitPowerLaw
impl HasDensity<Bernoulli> for UnitPowerLaw
source§impl HasDensity<f32> for UnitPowerLaw
impl HasDensity<f32> for UnitPowerLaw
source§impl HasDensity<f64> for UnitPowerLaw
impl HasDensity<f64> for UnitPowerLaw
source§impl HasSuffStat<f32> for UnitPowerLaw
impl HasSuffStat<f32> for UnitPowerLaw
source§impl HasSuffStat<f64> for UnitPowerLaw
impl HasSuffStat<f64> for UnitPowerLaw
source§impl InverseCdf<f32> for UnitPowerLaw
impl InverseCdf<f32> for UnitPowerLaw
source§impl InverseCdf<f64> for UnitPowerLaw
impl InverseCdf<f64> for UnitPowerLaw
source§impl Mean<f32> for UnitPowerLaw
impl Mean<f32> for UnitPowerLaw
source§impl Mean<f64> for UnitPowerLaw
impl Mean<f64> for UnitPowerLaw
source§impl Mode<f32> for UnitPowerLaw
impl Mode<f32> for UnitPowerLaw
source§impl Mode<f64> for UnitPowerLaw
impl Mode<f64> for UnitPowerLaw
source§impl Parameterized for UnitPowerLaw
impl Parameterized for UnitPowerLaw
type Parameters = f64
fn emit_params(&self) -> Self::Parameters
fn from_params(alpha: Self::Parameters) -> Self
source§impl PartialEq for UnitPowerLaw
impl PartialEq for UnitPowerLaw
source§fn eq(&self, other: &UnitPowerLaw) -> bool
fn eq(&self, other: &UnitPowerLaw) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.source§impl Sampleable<Bernoulli> for UnitPowerLaw
impl Sampleable<Bernoulli> for UnitPowerLaw
source§impl Sampleable<f32> for UnitPowerLaw
impl Sampleable<f32> for UnitPowerLaw
source§impl Sampleable<f64> for UnitPowerLaw
impl Sampleable<f64> for UnitPowerLaw
source§impl Serialize for UnitPowerLaw
impl Serialize for UnitPowerLaw
source§impl Support<Bernoulli> for UnitPowerLaw
impl Support<Bernoulli> for UnitPowerLaw
source§impl Support<f32> for UnitPowerLaw
impl Support<f32> for UnitPowerLaw
source§impl Support<f64> for UnitPowerLaw
impl Support<f64> for UnitPowerLaw
Auto Trait Implementations§
impl !Freeze for UnitPowerLaw
impl RefUnwindSafe for UnitPowerLaw
impl Send for UnitPowerLaw
impl Sync for UnitPowerLaw
impl Unpin for UnitPowerLaw
impl UnwindSafe for UnitPowerLaw
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)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<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.