Fleet  0.0.9
Inference in the LOT
Public Types | Public Member Functions | Public Attributes | List of all members
Bayesable< _datum_t, _data_t > Class Template Referenceabstract

#include <Bayesable.h>

Public Types

typedef _datum_t datum_t
 
typedef _data_t data_t
 

Public Member Functions

 Bayesable ()
 
virtual size_t hash () const =0
 
virtual std::string string (std::string prefix="") const =0
 
virtual double compute_prior ()=0
 
virtual double compute_single_likelihood (const datum_t &datum)
 Compute the likelihood of a single data point. More...
 
virtual void clear_bayes ()
 
virtual double compute_likelihood (const data_t &data, const double breakout=-infinity)
 Compute the likelihood of a collection of data, by calling compute_single_likelihood on each. This stops if our likelihood falls below breakout. More...
 
virtual double compute_posterior (const data_t &data, const std::pair< double, double > breakoutpair=std::make_pair(-infinity, 1.0))
 Compute the posterior, by calling prior and likelihood. This includes only a little bit of fanciness, which is that if our prior is -inf, then we don't both computing the likelihood. More...
 
virtual double at_temperature (double t) const
 
auto operator (const Bayesable< datum_t, data_t > &other) const
 
virtual void show (std::string prefix="")
 

Public Attributes

double prior
 
double likelihood
 
double posterior
 
uintmax_t born
 
size_t born_chain_idx
 

Detailed Description

template<typename _datum_t, typename _data_t = std::vector<_datum_t>>
class Bayesable< _datum_t, _data_t >

Author
steven piantadosi
Date
29/01/20

Member Typedef Documentation

◆ data_t

template<typename _datum_t, typename _data_t = std::vector<_datum_t>>
typedef _data_t Bayesable< _datum_t, _data_t >::data_t

◆ datum_t

template<typename _datum_t, typename _data_t = std::vector<_datum_t>>
typedef _datum_t Bayesable< _datum_t, _data_t >::datum_t

Constructor & Destructor Documentation

◆ Bayesable()

template<typename _datum_t, typename _data_t = std::vector<_datum_t>>
Bayesable< _datum_t, _data_t >::Bayesable ( )
inline

Member Function Documentation

◆ at_temperature()

template<typename _datum_t, typename _data_t = std::vector<_datum_t>>
virtual double Bayesable< _datum_t, _data_t >::at_temperature ( double  t) const
inlinevirtual

Return my posterior score at a given (likelihood) temperature

Parameters
t
Returns

◆ clear_bayes()

template<typename _datum_t, typename _data_t = std::vector<_datum_t>>
virtual void Bayesable< _datum_t, _data_t >::clear_bayes ( )
inlinevirtual

Zero by prior, likelihood, posterior

◆ compute_likelihood()

template<typename _datum_t, typename _data_t = std::vector<_datum_t>>
virtual double Bayesable< _datum_t, _data_t >::compute_likelihood ( const data_t data,
const double  breakout = -infinity 
)
inlinevirtual

Compute the likelihood of a collection of data, by calling compute_single_likelihood on each. This stops if our likelihood falls below breakout.

Parameters
data
breakout
Returns

Reimplemented in BaseGrammarHypothesis< this_t, _HYP, datum_t, data_t, _Predict_t >, MyHypothesis, MyHypothesis, VectorNormalHypothesis, VectorHalfNormalHypothesis, MyHypothesis, TNormalVariable<+[](float x) ->, MyGrammarHypothesis, and MyHypothesis.

◆ compute_posterior()

template<typename _datum_t, typename _data_t = std::vector<_datum_t>>
virtual double Bayesable< _datum_t, _data_t >::compute_posterior ( const data_t data,
const std::pair< double, double >  breakoutpair = std::make_pair(-infinity,1.0) 
)
inlinevirtual

Compute the posterior, by calling prior and likelihood. This includes only a little bit of fanciness, which is that if our prior is -inf, then we don't both computing the likelihood.

To understand breakout, look at MCMCChain.h and see how compute_posterior is called – the first term in breakout is (u + current.at_temperature(temperature) + fb), and the second is the temperature We have to pass in two pieces because the temperature only applies ot the likelihood. Note that when we use breakout in compute_likelihood, it is only for the likelihood temp.

NOTE: The order here is fixed to compute the prior first. This permits us to penalize the "prior" with something in the likelihood – for instance if we want to use a runtime prior that is computed as we run the likelihood

Parameters
data
breakout
Returns

◆ compute_prior()

template<typename _datum_t, typename _data_t = std::vector<_datum_t>>
virtual double Bayesable< _datum_t, _data_t >::compute_prior ( )
pure virtual

Implemented in BaseGrammarHypothesis< this_t, _HYP, datum_t, data_t, _Predict_t >, BaseGrammarHypothesis< MyGrammarHypothesis, MyHypothesis, HumanDatum< MyHypothesis >, std::vector< HumanDatum< MyHypothesis > >, Vector2D< typename MyHypothesis ::output_t > >, BaseGrammarHypothesis< MyGrammarHypothesis, MyHypothesis, MyHumanDatum, std::vector< MyHumanDatum >, Vector2D< typename MyHypothesis ::output_t > >, BaseGrammarHypothesis< MyGrammarHypothesis, MyHypothesis, MyHumanDatum, std::vector< MyHumanDatum >, Vector2D< DiscreteDistribution< S > > >, Lexicon< this_t, _key_t, INNER, _input_t, _output_t, datum_t, _VirtualMachineState_t >, Lexicon< MyHypothesis, std::string, InnerHypothesis, BindingTree *, std::string >, Lexicon< MyHypothesis, S, InnerHypothesis, CL, CL, CLDatum >, Lexicon< MyHypothesis, std::string, InnerHypothesis, ignore_t, ignore_t, Utterance >, MyHypothesis, LOTHypothesis< this_t, _input_t, _output_t, _Grammar_t, grammar, _datum_t, _data_t, _VirtualMachineState_t >, LOTHypothesis< MyHypothesis, S, S, MyGrammar, grammar, defaultdatum_t< S, S >, std::vector< defaultdatum_t< S, S > >, typename MyGrammar ::VirtualMachineState_t >, LOTHypothesis< InnerHypothesis, BindingTree *, bool, MyGrammar, grammar, defaultdatum_t< BindingTree *, bool >, std::vector< defaultdatum_t< BindingTree *, bool > >, typename MyGrammar ::VirtualMachineState_t >, LOTHypothesis< MyHypothesis, utterance, word, MyGrammar, grammar, defaultdatum_t< utterance, word >, std::vector< defaultdatum_t< utterance, word > >, typename MyGrammar ::VirtualMachineState_t >, LOTHypothesis< InnerHypothesis, CL, CL, Combinators::SKGrammar, grammar, defaultdatum_t< CL, CL >, std::vector< defaultdatum_t< CL, CL > >, typename Combinators::SKGrammar ::VirtualMachineState_t >, LOTHypothesis< MyHypothesis, int, NumberSet, MyGrammar, grammar, std::multiset< int >, std::vector< std::multiset< int > >, typename MyGrammar ::VirtualMachineState_t >, LOTHypothesis< InnerHypothesis, Utterance, TruthValue, MyGrammar, grammar, defaultdatum_t< Utterance, TruthValue >, std::vector< defaultdatum_t< Utterance, TruthValue > >, typename MyGrammar ::VirtualMachineState_t >, LOTHypothesis< MyHypothesis, set, word, MyGrammar, grammar, defaultdatum_t< set, word >, std::vector< defaultdatum_t< set, word > >, typename MyGrammar ::VirtualMachineState_t >, MyHypothesis, VectorNormalHypothesis, VectorHalfNormalHypothesis, InnerHypothesis, TNormalVariable< f >, TNormalVariable<+[](float x) ->, MyHypothesis, and InnerHypothesis.

◆ compute_single_likelihood()

template<typename _datum_t, typename _data_t = std::vector<_datum_t>>
virtual double Bayesable< _datum_t, _data_t >::compute_single_likelihood ( const datum_t datum)
inlinevirtual

◆ hash()

template<typename _datum_t, typename _data_t = std::vector<_datum_t>>
virtual size_t Bayesable< _datum_t, _data_t >::hash ( ) const
pure virtual

Implemented in BaseGrammarHypothesis< this_t, _HYP, datum_t, data_t, _Predict_t >, BaseGrammarHypothesis< MyGrammarHypothesis, MyHypothesis, HumanDatum< MyHypothesis >, std::vector< HumanDatum< MyHypothesis > >, Vector2D< typename MyHypothesis ::output_t > >, BaseGrammarHypothesis< MyGrammarHypothesis, MyHypothesis, MyHumanDatum, std::vector< MyHumanDatum >, Vector2D< typename MyHypothesis ::output_t > >, BaseGrammarHypothesis< MyGrammarHypothesis, MyHypothesis, MyHumanDatum, std::vector< MyHumanDatum >, Vector2D< DiscreteDistribution< S > > >, LOTHypothesis< this_t, _input_t, _output_t, _Grammar_t, grammar, _datum_t, _data_t, _VirtualMachineState_t >, LOTHypothesis< MyHypothesis, S, S, MyGrammar, grammar, defaultdatum_t< S, S >, std::vector< defaultdatum_t< S, S > >, typename MyGrammar ::VirtualMachineState_t >, LOTHypothesis< InnerHypothesis, BindingTree *, bool, MyGrammar, grammar, defaultdatum_t< BindingTree *, bool >, std::vector< defaultdatum_t< BindingTree *, bool > >, typename MyGrammar ::VirtualMachineState_t >, LOTHypothesis< MyHypothesis, utterance, word, MyGrammar, grammar, defaultdatum_t< utterance, word >, std::vector< defaultdatum_t< utterance, word > >, typename MyGrammar ::VirtualMachineState_t >, LOTHypothesis< InnerHypothesis, CL, CL, Combinators::SKGrammar, grammar, defaultdatum_t< CL, CL >, std::vector< defaultdatum_t< CL, CL > >, typename Combinators::SKGrammar ::VirtualMachineState_t >, LOTHypothesis< MyHypothesis, int, NumberSet, MyGrammar, grammar, std::multiset< int >, std::vector< std::multiset< int > >, typename MyGrammar ::VirtualMachineState_t >, LOTHypothesis< InnerHypothesis, Utterance, TruthValue, MyGrammar, grammar, defaultdatum_t< Utterance, TruthValue >, std::vector< defaultdatum_t< Utterance, TruthValue > >, typename MyGrammar ::VirtualMachineState_t >, LOTHypothesis< MyHypothesis, set, word, MyGrammar, grammar, defaultdatum_t< set, word >, std::vector< defaultdatum_t< set, word > >, typename MyGrammar ::VirtualMachineState_t >, Lexicon< this_t, _key_t, INNER, _input_t, _output_t, datum_t, _VirtualMachineState_t >, VectorHalfNormalHypothesis, Lexicon< MyHypothesis, std::string, InnerHypothesis, BindingTree *, std::string >, Lexicon< MyHypothesis, S, InnerHypothesis, CL, CL, CLDatum >, Lexicon< MyHypothesis, std::string, InnerHypothesis, ignore_t, ignore_t, Utterance >, VectorNormalHypothesis, TNormalVariable< f >, and TNormalVariable<+[](float x) ->.

◆ operator()

template<typename _datum_t, typename _data_t = std::vector<_datum_t>>
auto Bayesable< _datum_t, _data_t >::operator ( const Bayesable< datum_t, data_t > &  other) const
inline

Allow sorting of Bayesable hypotheses. We defaultly sort by posterior so that TopN works right. But we also need to be careful because std::set uses this to determine equality, so this also checks priors and then finally hashes (which should represent values).

Parameters
l
Returns

◆ show()

template<typename _datum_t, typename _data_t = std::vector<_datum_t>>
virtual void Bayesable< _datum_t, _data_t >::show ( std::string  prefix = "")
inlinevirtual

◆ string()

template<typename _datum_t, typename _data_t = std::vector<_datum_t>>
virtual std::string Bayesable< _datum_t, _data_t >::string ( std::string  prefix = "") const
pure virtual

Implemented in BaseGrammarHypothesis< this_t, _HYP, datum_t, data_t, _Predict_t >, BaseGrammarHypothesis< MyGrammarHypothesis, MyHypothesis, HumanDatum< MyHypothesis >, std::vector< HumanDatum< MyHypothesis > >, Vector2D< typename MyHypothesis ::output_t > >, BaseGrammarHypothesis< MyGrammarHypothesis, MyHypothesis, MyHumanDatum, std::vector< MyHumanDatum >, Vector2D< typename MyHypothesis ::output_t > >, BaseGrammarHypothesis< MyGrammarHypothesis, MyHypothesis, MyHumanDatum, std::vector< MyHumanDatum >, Vector2D< DiscreteDistribution< S > > >, LOTHypothesis< this_t, _input_t, _output_t, _Grammar_t, grammar, _datum_t, _data_t, _VirtualMachineState_t >, LOTHypothesis< MyHypothesis, S, S, MyGrammar, grammar, defaultdatum_t< S, S >, std::vector< defaultdatum_t< S, S > >, typename MyGrammar ::VirtualMachineState_t >, LOTHypothesis< InnerHypothesis, BindingTree *, bool, MyGrammar, grammar, defaultdatum_t< BindingTree *, bool >, std::vector< defaultdatum_t< BindingTree *, bool > >, typename MyGrammar ::VirtualMachineState_t >, LOTHypothesis< MyHypothesis, utterance, word, MyGrammar, grammar, defaultdatum_t< utterance, word >, std::vector< defaultdatum_t< utterance, word > >, typename MyGrammar ::VirtualMachineState_t >, LOTHypothesis< InnerHypothesis, CL, CL, Combinators::SKGrammar, grammar, defaultdatum_t< CL, CL >, std::vector< defaultdatum_t< CL, CL > >, typename Combinators::SKGrammar ::VirtualMachineState_t >, LOTHypothesis< MyHypothesis, int, NumberSet, MyGrammar, grammar, std::multiset< int >, std::vector< std::multiset< int > >, typename MyGrammar ::VirtualMachineState_t >, LOTHypothesis< InnerHypothesis, Utterance, TruthValue, MyGrammar, grammar, defaultdatum_t< Utterance, TruthValue >, std::vector< defaultdatum_t< Utterance, TruthValue > >, typename MyGrammar ::VirtualMachineState_t >, LOTHypothesis< MyHypothesis, set, word, MyGrammar, grammar, defaultdatum_t< set, word >, std::vector< defaultdatum_t< set, word > >, typename MyGrammar ::VirtualMachineState_t >, MyHypothesis, VectorHalfNormalHypothesis, VectorNormalHypothesis, Lexicon< this_t, _key_t, INNER, _input_t, _output_t, datum_t, _VirtualMachineState_t >, Lexicon< MyHypothesis, std::string, InnerHypothesis, BindingTree *, std::string >, Lexicon< MyHypothesis, S, InnerHypothesis, CL, CL, CLDatum >, Lexicon< MyHypothesis, std::string, InnerHypothesis, ignore_t, ignore_t, Utterance >, TNormalVariable< f >, and TNormalVariable<+[](float x) ->.

Member Data Documentation

◆ born

template<typename _datum_t, typename _data_t = std::vector<_datum_t>>
uintmax_t Bayesable< _datum_t, _data_t >::born

◆ born_chain_idx

template<typename _datum_t, typename _data_t = std::vector<_datum_t>>
size_t Bayesable< _datum_t, _data_t >::born_chain_idx

◆ likelihood

template<typename _datum_t, typename _data_t = std::vector<_datum_t>>
double Bayesable< _datum_t, _data_t >::likelihood

◆ posterior

template<typename _datum_t, typename _data_t = std::vector<_datum_t>>
double Bayesable< _datum_t, _data_t >::posterior

◆ prior

template<typename _datum_t, typename _data_t = std::vector<_datum_t>>
double Bayesable< _datum_t, _data_t >::prior

The documentation for this class was generated from the following file: