pub struct BayesianNetwork { /* private fields */ }Expand description
A Bayesian network that samples browser attributes.
Implementations§
Source§impl BayesianNetwork
impl BayesianNetwork
Sourcepub fn from_zip(archive: &[u8]) -> Result<Self>
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.
Sourcepub fn from_json(json: &[u8]) -> Result<Self>
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.
Sourcepub fn nodes(&self) -> impl ExactSizeIterator<Item = Node<'_>>
pub fn nodes(&self) -> impl ExactSizeIterator<Item = Node<'_>>
The nodes in sampling order.
Sourcepub fn sample(&self, rng: &mut Rng, fixed: &Values) -> Values
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.
Sourcepub fn consistent_sample(
&self,
rng: &mut Rng,
possibilities: &Restrictions,
) -> Option<Values>
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.
Sourcepub fn restricted_sample(
&self,
rng: &mut Rng,
fixed: &Values,
restrictions: &Restrictions,
) -> Option<Values>
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.
Sourcepub fn possible_values(
&self,
restrictions: &Restrictions,
) -> Result<Restrictions>
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.