pub struct ProbabilisticProgramEngine { /* private fields */ }Expand description
The main engine struct — declared here so all modules share one definition.
Implementations§
Source§impl ProbabilisticProgramEngine
impl ProbabilisticProgramEngine
Sourcepub fn new(config: PpeEngineConfig) -> Self
pub fn new(config: PpeEngineConfig) -> Self
Create a new engine with the given configuration.
Sourcepub fn add_variable(&mut self, name: String, prior: PpePrior) -> VarId
pub fn add_variable(&mut self, name: String, prior: PpePrior) -> VarId
Register a new variable with the given name and prior. Returns its
stable VarId.
Sourcepub fn observe(&mut self, var_id: VarId, value: f64)
pub fn observe(&mut self, var_id: VarId, value: f64)
Condition variable var_id on the observed value.
Sourcepub fn clear_observation(&mut self, var_id: VarId)
pub fn clear_observation(&mut self, var_id: VarId)
Remove an observation, allowing the variable to be sampled freely.
Sourcepub fn sample(
&mut self,
method: PpeSamplingMethod,
) -> Result<PpeSampleResult, String>
pub fn sample( &mut self, method: PpeSamplingMethod, ) -> Result<PpeSampleResult, String>
Run posterior sampling with the given method.
§Errors
Returns an error string if no variables have been registered.
Sourcepub fn posterior_mean(&self, var_id: VarId) -> Option<f64>
pub fn posterior_mean(&self, var_id: VarId) -> Option<f64>
Posterior mean of variable var_id from the last sampling run.
Sourcepub fn posterior_std(&self, var_id: VarId) -> Option<f64>
pub fn posterior_std(&self, var_id: VarId) -> Option<f64>
Posterior standard deviation of variable var_id.
Sourcepub fn credible_interval(&self, var_id: VarId, alpha: f64) -> Option<(f64, f64)>
pub fn credible_interval(&self, var_id: VarId, alpha: f64) -> Option<(f64, f64)>
Central credible interval at coverage 1 - alpha.
E.g., alpha = 0.05 returns the 95% CI as (lower, upper).
Sourcepub fn log_likelihood(&self, var_id: VarId, value: f64) -> f64
pub fn log_likelihood(&self, var_id: VarId, value: f64) -> f64
Log-density (log prior) of value under the prior of var_id.
Sourcepub fn marginal_distribution(
&self,
var_id: VarId,
n_bins: usize,
) -> Vec<(f64, f64)>
pub fn marginal_distribution( &self, var_id: VarId, n_bins: usize, ) -> Vec<(f64, f64)>
Approximate marginal distribution as a histogram with n_bins equal-width bins.
Returns a Vec<(bin_centre, frequency)> in ascending order.
Sourcepub fn sampling_stats(&self) -> PpeSamplingStats
pub fn sampling_stats(&self) -> PpeSamplingStats
Diagnostics about the current state of the engine.
Sourcepub fn config(&self) -> &PpeEngineConfig
pub fn config(&self) -> &PpeEngineConfig
Return a reference to the engine configuration.
Sourcepub fn get_variable(&self, var_id: VarId) -> Option<&ProbVar>
pub fn get_variable(&self, var_id: VarId) -> Option<&ProbVar>
Look up a variable by its id.
Sourcepub fn n_variables(&self) -> usize
pub fn n_variables(&self) -> usize
Number of registered variables.
Sourcepub fn n_samples(&self, var_id: VarId) -> usize
pub fn n_samples(&self, var_id: VarId) -> usize
Number of retained samples for a given variable (0 if no sampling has been run).
Sourcepub fn raw_samples(&self, var_id: VarId) -> Option<&[f64]>
pub fn raw_samples(&self, var_id: VarId) -> Option<&[f64]>
Raw posterior samples for var_id.
Sourcepub fn last_result(&self) -> Option<&PpeSampleResult>
pub fn last_result(&self) -> Option<&PpeSampleResult>
Last PpeSampleResult returned by sample.
Auto Trait Implementations§
impl Freeze for ProbabilisticProgramEngine
impl RefUnwindSafe for ProbabilisticProgramEngine
impl Send for ProbabilisticProgramEngine
impl Sync for ProbabilisticProgramEngine
impl Unpin for ProbabilisticProgramEngine
impl UnsafeUnpin for ProbabilisticProgramEngine
impl UnwindSafe for ProbabilisticProgramEngine
Blanket Implementations§
impl<T> Allocation for T
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
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>
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>
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