[−][src]Struct loopybayesnet::BayesNet
Representation of a Bayesian Network
Once built by adding the nodes one by one, you can use it for inference computation on the graph given some evidence.
Methods
impl BayesNet
[src]
pub fn new() -> BayesNet
[src]
Create a new empty Bayesian Network
pub fn add_node_from_probabilities<D: Dimension + RemoveAxis>(
&mut self,
parents: &[usize],
probabilities: Array<f32, D>
) -> usize
[src]
&mut self,
parents: &[usize],
probabilities: Array<f32, D>
) -> usize
Add a new node to the network
You need to specify the list of its parents, and an array of probabilities representing p(x | parents)
.
If the parents are (p1, ... pk)
, the shape of the array should thus be: (N, N_p1, ... N_pk)
, where
N
is the number of possible values for the current variables, and N_pi
is the number of values of
parent pi
.
If the node has no parents, the propabilities must be single-dimenstionnal and represents a prior.
All values of probabilities should be finite, but the probabilities array does not need to be normalized, as it will be during the construction process.
pub fn add_node_from_log_probabilities<D: Dimension + RemoveAxis>(
&mut self,
parents: &[usize],
log_probabilities: Array<f32, D>
) -> usize
[src]
&mut self,
parents: &[usize],
log_probabilities: Array<f32, D>
) -> usize
Add a new node to the network from log-probabilities
Same as add_node_from_probabilities
, but the input is in the form of log-probabilities, for greated precision.
All values of log-probas should be strictly smaller than +inf
. -inf
is valid and represents a
probability of 0. The probabilities array does not need to be normalized, as it will be during the construction
process. For example, the log-vector [0.0, -inf]
will represent a vector of probabilities of [1.0, 0.0]
.
Log-probabilities are intepreted as computed with the natural logarithm (base e).
pub fn set_evidence(&mut self, evidence: &[(usize, usize)])
[src]
Sets the evidence for the network
Input is interpreted as a list of (node_id, node_value)
. Out-of-range evidence is not checked, but
will result into a probability of 0
.
pub fn reset_state(&mut self)
[src]
Resets the internal state of the inference algorithm, to begin a new inference
pub fn beliefs(&self) -> Vec<LogProbVector>
[src]
Compute the current state belief of each node according to the current internal messages
pub fn step(&mut self)
[src]
Compute one step of the Loopy Belief Propagation Algorithm
The algorithm can be run for any number of steps. it is up to you to decide when to stop.
A classic stopping criterion is when the yielded beliefs stop significantly changing.
Auto Trait Implementations
impl Send for BayesNet
impl Unpin for BayesNet
impl Sync for BayesNet
impl UnwindSafe for BayesNet
impl RefUnwindSafe for BayesNet
Blanket Implementations
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,