pub struct BayesianNetwork;Expand description
Bayesian-network model for binary spaces (BOA).
Implements ProbabilityModel by greedily learning a bounded-in-degree DAG
over the binary genes with a BIC structure score, then ancestral-sampling
from the fitted CPTs (see the module docs for the algorithm, the BIC
rationale, bit-packing, and references). Fitness is accepted but ignored; the
fit is always unweighted and non-incremental.
Trait Implementations§
Source§impl Clone for BayesianNetwork
impl Clone for BayesianNetwork
Source§fn clone(&self) -> BayesianNetwork
fn clone(&self) -> BayesianNetwork
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for BayesianNetwork
Source§impl Debug for BayesianNetwork
impl Debug for BayesianNetwork
Source§impl Default for BayesianNetwork
impl Default for BayesianNetwork
Source§fn default() -> BayesianNetwork
fn default() -> BayesianNetwork
Source§impl<B: Backend> ProbabilityModel<B> for BayesianNetwork
impl<B: Backend> ProbabilityModel<B> for BayesianNetwork
Source§fn fit(
&self,
params: &Self::Params,
prev: Option<&Self::State>,
population: Tensor<B, 2>,
fitness: Tensor<B, 1>,
device: &<B as BackendTypes>::Device,
) -> Self::State
fn fit( &self, params: &Self::Params, prev: Option<&Self::State>, population: Tensor<B, 2>, fitness: Tensor<B, 1>, device: &<B as BackendTypes>::Device, ) -> Self::State
Fit the Bayesian network to the selected population.
When prev = None returns the edgeless prior (natural order, empty
parent lists, single-cell CPTs at init_prob); population and
fitness are ignored. Otherwise the whole network is relearned from
scratch (the fit is non-incremental — prev is the not-bootstrap signal
only):
- Bitizes the selected rows to
{0, 1}via>= 0.5. - Greedily adds the highest-BIC-gain edge each round (subject to the
max_parentscap and acyclicity) until no strictly-positive gain remains, using aD × Dgain cache. - Estimates Laplace-smoothed CPTs from the final structure.
- Computes a deterministic topological order (Kahn, min-index).
The fitness argument is accepted but always ignored.
§Panics
In release builds, panics if the population tensor cannot be read back
as f32 (.expect("population tensor must be readable as f32")).
In debug builds, additionally panics on the following debug_assert
checks (all disabled in release):
- the population column count disagrees with
params.genome_dim; params.max_parents >= usize::BITS(which would overflow the1usize << qCPT table sizing);- the closing topological order fails to cover all
Dnodes (guaranteed by the DAG invariant).
Source§fn sample(
&self,
state: &Self::State,
n: usize,
rng: &mut dyn Rng,
device: &<B as BackendTypes>::Device,
) -> Tensor<B, 2>
fn sample( &self, state: &Self::State, n: usize, rng: &mut dyn Rng, device: &<B as BackendTypes>::Device, ) -> Tensor<B, 2>
Draw n binary genomes by ancestral sampling along the topological order.
Each gene v is sampled from P(v = 1 | parents) read out of its CPT at
the bit-packed parent configuration (parents already sampled, since the
traversal follows the topological order). Exactly one rng.random::<f32>()
call is consumed per gene regardless of structure, keeping RNG
consumption stable. Host RNG only (never Tensor::random / B::seed).
The returned tensor has shape (n, D) and contains only 0.0 and 1.0.
Source§type Params = BayesianNetworkParams
type Params = BayesianNetworkParams
Source§type State = BayesianNetworkState
type State = BayesianNetworkState
Auto Trait Implementations§
impl Freeze for BayesianNetwork
impl RefUnwindSafe for BayesianNetwork
impl Send for BayesianNetwork
impl Sync for BayesianNetwork
impl Unpin for BayesianNetwork
impl UnsafeUnpin for BayesianNetwork
impl UnwindSafe for BayesianNetwork
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
Source§impl<C> CloneExpand for Cwhere
C: Clone,
impl<C> CloneExpand for Cwhere
C: Clone,
fn __expand_clone_method(&self, _scope: &mut Scope) -> C
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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