TrieFn

Struct TrieFn 

Source
pub struct TrieFn<A, T> {
    pub func: fn(&mut TrieFnState<A, T>, A) -> T,
}
Expand description

Wrapper struct for functions that use the TrieFnState DSL (sample_at and trace_at) and automatically implement the GFI.

Fields§

§func: fn(&mut TrieFnState<A, T>, A) -> T

A random function that takes in a mutable reference to a TrieFnState<A,T> and some args A, effectfully mutates the state, and produces a value T.

Implementations§

Source§

impl<Args, Ret> TrieFn<Args, Ret>

Source

pub fn new(func: fn(&mut TrieFnState<Args, Ret>, Args) -> Ret) -> Self

Dynamically construct a TrieFn from a function at run-time.

Trait Implementations§

Source§

impl<Args: Clone + 'static, Ret: 'static> GenFn<Args, Trie<(Rc<dyn Any>, f64)>, Ret> for TrieFn<Args, Ret>

Source§

fn simulate(&self, args: Args) -> Trace<Args, Trie<(Rc<dyn Any>, f64)>, Ret>

Execute the generative function and return a sampled trace.
Source§

fn generate( &self, args: Args, constraints: Trie<(Rc<dyn Any>, f64)>, ) -> (Trace<Args, Trie<(Rc<dyn Any>, f64)>, Ret>, f64)

Execute the generative function consistent with constraints. Return the log probability log[p(t; args) / q(t; constraints, args)]
Source§

fn update( &self, trace: Trace<Args, Trie<(Rc<dyn Any>, f64)>, Ret>, args: Args, _: GfDiff, constraints: Trie<(Rc<dyn Any>, f64)>, ) -> (Trace<Args, Trie<(Rc<dyn Any>, f64)>, Ret>, Trie<(Rc<dyn Any>, f64)>, f64)

Update a trace
Source§

fn call(&self, args: Args) -> Ret

Call a generative function and return the output.
Source§

fn propose(&self, args: Args) -> (Data, f64)

Use a generative function to propose some data.
Source§

fn assess(&self, args: Args, constraints: Data) -> f64

Assess the conditional probability of some proposed constraints under a generative function.

Auto Trait Implementations§

§

impl<A, T> Freeze for TrieFn<A, T>

§

impl<A, T> RefUnwindSafe for TrieFn<A, T>

§

impl<A, T> Send for TrieFn<A, T>

§

impl<A, T> Sync for TrieFn<A, T>

§

impl<A, T> Unpin for TrieFn<A, T>

§

impl<A, T> UnwindSafe for TrieFn<A, T>

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<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V