Skip to main content

BayesianNetwork

Struct BayesianNetwork 

Source
pub struct BayesianNetwork { /* private fields */ }
Expand description

A Bayesian network that samples browser attributes.

Implementations§

Source§

impl BayesianNetwork

Source

pub fn from_zip(archive: &[u8]) -> Result<Self>

Parses a network from a zip archive holding its network.json.

§Errors

Error::Zip when the archive is unreadable, Error::Network when the JSON is not a network definition.

Source

pub fn from_json(json: &[u8]) -> Result<Self>

Parses a network from its network.json bytes.

§Errors

Error::Network when the JSON is not a network definition.

Source

pub fn len(&self) -> usize

The number of nodes.

Source

pub fn is_empty(&self) -> bool

Returns true for a network without nodes.

Source

pub fn node(&self, name: &str) -> Option<Node<'_>>

The node called name.

Source

pub fn nodes(&self) -> impl ExactSizeIterator<Item = Node<'_>>

The nodes in sampling order.

Source

pub fn sample(&self, rng: &mut Rng, fixed: &Values) -> Values

browserforge’s generate_sample: starts from a copy of fixed, then samples every node it does not name, in sampling order, each given the values chosen so far. A node whose distribution is empty for its parent values stays out of the sample.

Source

pub fn consistent_sample( &self, rng: &mut Rng, possibilities: &Restrictions, ) -> Option<Values>

browserforge’s generate_consistent_sample_when_possible: a sample in which every node named in possibilities takes one of its listed values (other nodes range over their possible values). Searches depth first in sampling order, banning a value whose subtree has no consistent completion and backtracking when a node runs out of values. None when no consistent sample exists.

Source

pub fn restricted_sample( &self, rng: &mut Rng, fixed: &Values, restrictions: &Restrictions, ) -> Option<Values>

BayesianNetwork::sample in which every node named in restrictions (and not in fixed) takes one of its listed values.

Without restrictions the draws, and so the result, are exactly those of BayesianNetwork::sample. With restrictions the search is depth first in sampling order, banning a value whose subtree has no completion and backtracking, as BayesianNetwork::consistent_sample does; unrestricted nodes draw from their full distribution and, as in sample, stay out of the result when it is empty. None when no sample satisfies the restrictions.

Source

pub fn possible_values( &self, restrictions: &Restrictions, ) -> Result<Restrictions>

browserforge’s get_possible_values: extends the constraints with the values they induce on the parents of each constrained node, then intersects the constraints that meet on a node.

For each constrained node the parents may take the values on any CPT path (ignoring skip) that ends in one of the node’s allowed values. Every list keeps first-seen order.

§Errors

Error::TooRestrictive when a constraint is empty or an intersection is; Error::UnknownNode when a constraint names no node.

Trait Implementations§

Source§

impl Debug for BayesianNetwork

Source§

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

Formats the value using the given formatter. Read more

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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.