Fleet  0.0.9
Inference in the LOT
Functions
Proposals Namespace Reference

Functions

double can_resample (const Node &n)
 Helper function for whether we can resample from a node (just accesses n.can_resample) More...
 
template<typename GrammarType >
std::optional< std::pair< Node, double > > prior_proposal (GrammarType *grammar, const Node &from)
 
template<typename GrammarType >
double p_regeneration_propose_to (GrammarType *grammar, const Node &a, const Node &b)
 Probability of proposing from a to b under regeneration. More...
 
template<typename GrammarType >
std::optional< std::pair< Node, double > > regenerate (GrammarType *grammar, const Node &from)
 A little helper function that resamples everything below when we can. If we can't, then we'll recurse. More...
 
template<typename GrammarType , int D>
std::optional< std::pair< Node, double > > regenerate_shallow (GrammarType *grammar, const Node &from)
 Regenerate with rational-rules style proposals, but only allow proposals to trees with a max depth of D. This encourages smaller changes, but also gets you stuck pretty bad in local maxima since you can't take big hops. Probably will work best with restarts. More...
 
template<typename GrammarType >
std::optional< std::pair< Node, double > > insert_tree (GrammarType *grammar, const Node &from)
 
template<typename GrammarType >
std::optional< std::pair< Node, double > > delete_tree (GrammarType *grammar, const Node &from)
 
template<typename GrammarType >
std::optional< std::pair< Node, double > > sample_function_leaving_args (GrammarType *grammar, const Node &from)
 This samples functions f(a,b) -> g(a,b) (e.g. without destroying what's below). This uses a little trick that the node only stores the rule, so we can swap it out if we want. More...
 
template<typename GrammarType >
std::optional< std::pair< Node, double > > swap_args (GrammarType *grammar, const Node &from)
 This propose swaps around arguments of the same type. More...
 

Function Documentation

◆ can_resample()

double Proposals::can_resample ( const Node n)

Helper function for whether we can resample from a node (just accesses n.can_resample)

Parameters
n- what node are we asking about?
Returns
- a double (1.0 or 0.0) depending on whether n can be sampled

◆ delete_tree()

template<typename GrammarType >
std::optional<std::pair<Node, double> > Proposals::delete_tree ( GrammarType *  grammar,
const Node from 
)

backward is we choose the new s, then generate everything else, and choose anything equal

◆ insert_tree()

template<typename GrammarType >
std::optional<std::pair<Node, double> > Proposals::insert_tree ( GrammarType *  grammar,
const Node from 
)

backward is we choose t exactly, then we pick anything below that is equal to s

◆ p_regeneration_propose_to()

template<typename GrammarType >
double Proposals::p_regeneration_propose_to ( GrammarType *  grammar,
const Node a,
const Node b 
)

Probability of proposing from a to b under regeneration.

Parameters
grammar
a
b
Returns

◆ prior_proposal()

template<typename GrammarType >
std::optional<std::pair<Node,double> > Proposals::prior_proposal ( GrammarType *  grammar,
const Node from 
)

◆ regenerate()

template<typename GrammarType >
std::optional<std::pair<Node,double> > Proposals::regenerate ( GrammarType *  grammar,
const Node from 
)

A little helper function that resamples everything below when we can. If we can't, then we'll recurse.

Parameters
grammar
fromRegenerate with a rational-rules (Goodman et al.) style regeneration proposal: pick a node uniformly and regenerate it from the grammar.
grammar- what grammar to use
from- what node are we proposing from
Returns
A pair of the new proposed tree and the forward-backward log probability (for use in MCMC)

◆ regenerate_shallow()

template<typename GrammarType , int D>
std::optional<std::pair<Node,double> > Proposals::regenerate_shallow ( GrammarType *  grammar,
const Node from 
)

Regenerate with rational-rules style proposals, but only allow proposals to trees with a max depth of D. This encourages smaller changes, but also gets you stuck pretty bad in local maxima since you can't take big hops. Probably will work best with restarts.

Parameters
grammar
from
Returns

◆ sample_function_leaving_args()

template<typename GrammarType >
std::optional<std::pair<Node,double> > Proposals::sample_function_leaving_args ( GrammarType *  grammar,
const Node from 
)

This samples functions f(a,b) -> g(a,b) (e.g. without destroying what's below). This uses a little trick that the node only stores the rule, so we can swap it out if we want.

Parameters
grammar
from
Returns

◆ swap_args()

template<typename GrammarType >
std::optional<std::pair<Node,double> > Proposals::swap_args ( GrammarType *  grammar,
const Node from 
)

This propose swaps around arguments of the same type.

Parameters
grammar
from
Returns