Skip to main content

NeuralBridge

Struct NeuralBridge 

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

Bridge for converting neural outputs to probabilistic constructs.

Handles numerical stability through epsilon clamping and normalization.

Implementations§

Source§

impl NeuralBridge

Source

pub fn new() -> Self

Create a new bridge with default epsilon (1e-8).

Source

pub fn with_epsilon(epsilon: f64) -> Self

Create a bridge with custom epsilon.

Source

pub fn to_ad_probabilities(&self, output: &NeuralOutput) -> Vec<ADProbability>

Convert softmax output to annotated disjunction probabilities.

Each probability is clamped to [epsilon, 1.0] for numerical stability.

Source

pub fn batch_to_circuit_leaves( &self, outputs: &[NeuralOutput], ) -> Vec<Vec<CircuitLeaf>>

Convert batch of neural outputs to circuit leaf weights.

Returns a 2D structure: leaves[sample_idx][label_idx]

Source

pub fn to_log_probabilities(&self, output: &NeuralOutput) -> Vec<f64>

Convert to log probabilities for numerical stability.

Log probabilities are used for:

  • Computing NLL loss: -log(p_true)
  • Avoiding underflow in product of many small probabilities
Source

pub fn normalize(&self, output: &NeuralOutput) -> NeuralOutput

Normalize probabilities to sum to 1.0.

Useful when network outputs have small numerical errors.

Source

pub fn extract_gradient_weights(&self, output: &NeuralOutput) -> Vec<f64>

Extract raw weights for gradient computation.

These weights are passed to the backward pass to compute gradients w.r.t. the neural network parameters.

Source

pub fn probability_of(&self, output: &NeuralOutput, label: &str) -> Option<f64>

Compute the probability of a specific label.

Source

pub fn log_probability_of( &self, output: &NeuralOutput, label: &str, ) -> Option<f64>

Compute the log probability of a specific label.

Source

pub fn to_circuit_leaves_with_offset( &self, output: &NeuralOutput, variable_offset: usize, ) -> Vec<CircuitLeaf>

Create circuit leaves for a single sample with variable ID offset.

Used when multiple samples share a circuit structure but have different variable ID ranges.

Trait Implementations§

Source§

impl Default for NeuralBridge

Source§

fn default() -> Self

Returns the “default value” for a type. 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,

§

impl<T> Ungil for T
where T: Send,