Fleet  0.0.9
Inference in the LOT
Public Types | Public Member Functions | List of all members
MyHypothesis Class Reference

we don't need inputs/outputs for out MyHypothesis More...

#include <MyHypothesis.h>

Inheritance diagram for MyHypothesis:
Inheritance graph
[legend]
Collaboration diagram for MyHypothesis:
Collaboration graph
[legend]

Public Types

using Super = Lexicon< MyHypothesis, S, InnerHypothesis, CL, CL, CLDatum >
 
using Super = StochasticLOTHypothesis< MyHypothesis, utterance, word, MyGrammar,&grammar >
 
using Super = DeterministicLOTHypothesis< MyHypothesis, set, word, MyGrammar,&grammar >
 
using Super = DeterministicLOTHypothesis< MyHypothesis, int, NumberSet, MyGrammar,&grammar, std::multiset< int > >
 
using Super = StochasticLOTHypothesis< MyHypothesis, S, S, MyGrammar,&grammar >
 
- Public Types inherited from StochasticLOTHypothesis< MyHypothesis, S, S, MyGrammar,&grammar >
using Super = LOTHypothesis< MyHypothesis, S, S, MyGrammar, grammar, defaultdatum_t< S, S >, std::vector< defaultdatum_t< S, S > >, typename MyGrammar ::VirtualMachineState_t >
 
using Grammar_t = MyGrammar
 
using input_t = S
 
using output_t = S
 
using call_output_t = DiscreteDistribution< output_t >
 
using VirtualMachineState_t = typename MyGrammar ::VirtualMachineState_t
 
- Public Types inherited from LOTHypothesis< MyHypothesis, S, S, MyGrammar, grammar, defaultdatum_t< S, S >, std::vector< defaultdatum_t< S, S > >, typename MyGrammar ::VirtualMachineState_t >
typedef Bayesable< defaultdatum_t< S, S >, std::vector< defaultdatum_t< S, S > > >::datum_t datum_t
 
typedef Bayesable< defaultdatum_t< S, S >, std::vector< defaultdatum_t< S, S > > >::data_t data_t
 
using Grammar_t = MyGrammar
 
using input_t = S
 
using output_t = S
 
using VirtualMachineState_t = typename MyGrammar ::VirtualMachineState_t
 
using ProposalType = std::optional< std::pair< MyHypothesis, double > >
 
- Public Types inherited from Bayesable< Args... >
typedef Args... datum_t
 
typedef std::vector< Args... > data_t
 
- Public Types inherited from Lexicon< MyHypothesis, std::string, InnerHypothesis, ignore_t, ignore_t, Utterance >
using Grammar_t = typename InnerHypothesis ::Grammar_t
 
using input_t = ignore_t
 
using output_t = ignore_t
 
using key_t = std::string
 
using VirtualMachineState_t = typename InnerHypothesis ::Grammar_t::VirtualMachineState_t
 
- Public Types inherited from DeterministicLOTHypothesis< MyHypothesis, int, NumberSet, MyGrammar,&grammar, std::multiset< int > >
using Super = LOTHypothesis< MyHypothesis, int, NumberSet, MyGrammar, grammar, std::multiset< int >, std::vector< std::multiset< int > >, typename MyGrammar ::VirtualMachineState_t >
 
using input_t = Super::input_t
 
using output_t = Super::output_t
 
using call_output_t = output_t
 
using VirtualMachineState_t = Super::VirtualMachineState_t
 
- Public Types inherited from LOTHypothesis< MyHypothesis, int, NumberSet, MyGrammar, grammar, std::multiset< int >, std::vector< std::multiset< int > >, typename MyGrammar ::VirtualMachineState_t >
typedef Bayesable< std::multiset< int >, std::vector< std::multiset< int > > >::datum_t datum_t
 
typedef Bayesable< std::multiset< int >, std::vector< std::multiset< int > > >::data_t data_t
 
using Grammar_t = MyGrammar
 
using input_t = int
 
using output_t = NumberSet
 
using VirtualMachineState_t = typename MyGrammar ::VirtualMachineState_t
 
using ProposalType = std::optional< std::pair< MyHypothesis, double > >
 
- Public Types inherited from DeterministicLOTHypothesis< MyHypothesis, set, word, MyGrammar,&grammar >
using Super = LOTHypothesis< MyHypothesis, set, word, MyGrammar, grammar, defaultdatum_t< set, word >, std::vector< defaultdatum_t< set, word > >, typename MyGrammar ::VirtualMachineState_t >
 
using input_t = Super::input_t
 
using output_t = Super::output_t
 
using call_output_t = output_t
 
using VirtualMachineState_t = Super::VirtualMachineState_t
 
- Public Types inherited from LOTHypothesis< MyHypothesis, set, word, MyGrammar, grammar, defaultdatum_t< set, word >, std::vector< defaultdatum_t< set, word > >, typename MyGrammar ::VirtualMachineState_t >
typedef Bayesable< defaultdatum_t< set, word >, std::vector< defaultdatum_t< set, word > > >::datum_t datum_t
 
typedef Bayesable< defaultdatum_t< set, word >, std::vector< defaultdatum_t< set, word > > >::data_t data_t
 
using Grammar_t = MyGrammar
 
using input_t = set
 
using output_t = word
 
using VirtualMachineState_t = typename MyGrammar ::VirtualMachineState_t
 
using ProposalType = std::optional< std::pair< MyHypothesis, double > >
 
- Public Types inherited from StochasticLOTHypothesis< MyHypothesis, utterance, word, MyGrammar,&grammar >
using Super = LOTHypothesis< MyHypothesis, utterance, word, MyGrammar, grammar, defaultdatum_t< utterance, word >, std::vector< defaultdatum_t< utterance, word > >, typename MyGrammar ::VirtualMachineState_t >
 
using Grammar_t = MyGrammar
 
using input_t = utterance
 
using output_t = word
 
using call_output_t = DiscreteDistribution< output_t >
 
using VirtualMachineState_t = typename MyGrammar ::VirtualMachineState_t
 
- Public Types inherited from LOTHypothesis< MyHypothesis, utterance, word, MyGrammar, grammar, defaultdatum_t< utterance, word >, std::vector< defaultdatum_t< utterance, word > >, typename MyGrammar ::VirtualMachineState_t >
typedef Bayesable< defaultdatum_t< utterance, word >, std::vector< defaultdatum_t< utterance, word > > >::datum_t datum_t
 
typedef Bayesable< defaultdatum_t< utterance, word >, std::vector< defaultdatum_t< utterance, word > > >::data_t data_t
 
using Grammar_t = MyGrammar
 
using input_t = utterance
 
using output_t = word
 
using VirtualMachineState_t = typename MyGrammar ::VirtualMachineState_t
 
using ProposalType = std::optional< std::pair< MyHypothesis, double > >
 
- Public Types inherited from Lexicon< MyHypothesis, S, InnerHypothesis, CL, CL, CLDatum >
using Grammar_t = typename InnerHypothesis ::Grammar_t
 
using input_t = CL
 
using output_t = CL
 
using key_t = S
 
using VirtualMachineState_t = typename InnerHypothesis ::Grammar_t::VirtualMachineState_t
 
- Public Types inherited from Lexicon< MyHypothesis, std::string, InnerHypothesis, BindingTree *, std::string >
using Grammar_t = typename InnerHypothesis ::Grammar_t
 
using input_t = BindingTree *
 
using output_t = std::string
 
using key_t = std::string
 
using VirtualMachineState_t = typename InnerHypothesis ::Grammar_t::VirtualMachineState_t
 

Public Member Functions

void clear_cache ()
 
double compute_likelihood (const data_t &data, const double breakout=-infinity) override
 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 void show (std::string prefix="") override
 
virtual double compute_prior () override
 
double compute_likelihood (const data_t &data, const double breakout=-infinity) override
 Compute the likelihood of a collection of data, by calling compute_single_likelihood on each. This stops if our likelihood falls below breakout. More...
 
double compute_prior () override
 
DiscreteDistribution< wordcall (const utterance &input)
 
double compute_single_likelihood (const datum_t &d) override
 Compute the likelihood of a single data point. More...
 
virtual void show (std::string prefix="") override
 
double compute_prior () override
 
virtual double compute_likelihood (const data_t &data, const double breakout=-infinity) override
 Compute the likelihood of a collection of data, by calling compute_single_likelihood on each. This stops if our likelihood falls below breakout. More...
 
std::string KLstring ()
 
virtual void show (std::string prefix="") override
 
virtual double compute_single_likelihood (const datum_t &datum) override
 Compute the likelihood of a single data point. More...
 
void clear_cache ()
 
virtual double compute_likelihood (const data_t &data, double breakout=-infinity) override
 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 std::string string (std::string prefix="") const override
 
virtual void show (std::string prefix="") override
 
double compute_single_likelihood (const datum_t &x) override
 Compute the likelihood of a single data point. More...
 
void print (std::string prefix="#\) override
 
virtual std::optional< std::pair< MyHypothesis, double > > propose () const override
 This proposal guarantees that there will be at least one factor that is proposed to. Each individual factor is proposed to with p_factor_propose. More...
 
- Public Member Functions inherited from StochasticLOTHypothesis< MyHypothesis, S, S, MyGrammar,&grammar >
virtual DiscreteDistribution< output_tcall (const input_t x, const output_t &err=output_t{})
 Run the virtual machine on input x, and marginalize over execution paths to return a distribution on outputs. Note that loader must be a program loader, and that is to handle recursion and other function calls. More...
 
- Public Member Functions inherited from LOTHypothesis< MyHypothesis, S, S, MyGrammar, grammar, defaultdatum_t< S, S >, std::vector< defaultdatum_t< S, S > >, typename MyGrammar ::VirtualMachineState_t >
 LOTHypothesis ()
 
 LOTHypothesis (Node &x)
 
 LOTHypothesis (Node &&x)
 
 LOTHypothesis (std::string s)
 
 LOTHypothesis (const LOTHypothesis &c)
 
 LOTHypothesis (const LOTHypothesis &&c)
 
LOTHypothesisoperator= (const LOTHypothesis &c)
 
LOTHypothesisoperator= (const LOTHypothesis &&c)
 
virtual MyHypothesis restart () const override
 This is used to restart chains, sampling from prior but ONLY for nodes that are can_resample. More...
 
Nodeget_value ()
 
const Nodeget_value () const
 
void set_value (Node &v, bool should_compile=true)
 Set the value to v. (NOTE: This compiles into a program) More...
 
void set_value (Node &&v, bool should_compile=true)
 
Grammar_tget_grammar () const
 
void compile ()
 
virtual void push_program (Program< VirtualMachineState_t > &s) override
 This puts the code from my node onto s. Used internally in e.g. recursion. More...
 
virtual std::string string (std::string prefix, bool usedot) const
 
virtual size_t hash () const override
 
virtual bool operator== (const MyHypothesis &h) const override
 Equality is checked on equality of values; note that greater-than is still on posteriors. More...
 
virtual void complete () override
 Modify this hypothesis's value by (randomly) filling in all the gaps. More...
 
virtual int neighbors () const override
 Count the number of neighbors that are possible. (This should be size_t but int is more convenient.) More...
 
virtual void expand_to_neighbor (int k) override
 Modify this hypothesis to become the k'th neighbor. NOTE This does not compile since it might not be complete. More...
 
virtual double neighbor_prior (int k) override
 What is the prior of the k'th neighbor? This does not need to return the full prior, only relative (among ks) More...
 
virtual bool is_evaluable () const override
 A node is "evaluable" if it is complete (meaning no null subnodes) More...
 
size_t recursion_count ()
 Count up how many times I use recursion – we keep a list of recursion here. More...
 
virtual std::string serialize () const override
 Convert this into a string which can be written to a file. More...
 
- Public Member Functions inherited from MCMCable< MyHypothesis, defaultdatum_t< S, S >, std::vector< defaultdatum_t< S, S > > >
 MCMCable ()
 
virtual bool operator!= (const MyHypothesis &h) const
 
- Public Member Functions inherited from Bayesable< Args... >
 Bayesable ()
 
virtual void clear_bayes ()
 
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
 
- Public Member Functions inherited from Searchable< MyHypothesis, S, S >
virtual MyHypothesis make_neighbor (int k) const
 Return a new hypothesis which is the k'th neighbor (just calls expand_to_neighbor) NOTE This does not compile since it might not be complete. More...
 
- Public Member Functions inherited from ProgramLoader< typename MyGrammar ::VirtualMachineState_t >
virtual void push_program (Program< typename MyGrammar ::VirtualMachineState_t > &s, const short a)
 
virtual void push_program (Program< typename MyGrammar ::VirtualMachineState_t > &s, const int a)
 
virtual void push_program (Program< typename MyGrammar ::VirtualMachineState_t > &s, const std::string k)
 
- Public Member Functions inherited from Lexicon< MyHypothesis, std::string, InnerHypothesis, ignore_t, ignore_t, Utterance >
 Lexicon ()
 
size_t nfactors () const
 Return the number of factors. More...
 
auto & get_value ()
 
const auto & get_value () const
 
InnerHypothesisat (const key_t &k)
 
const InnerHypothesisat (const key_t &k) const
 
InnerHypothesisoperator[] (const key_t &k)
 
const InnerHypothesisoperator[] (const key_t &k) const
 
bool contains (const key_t &key)
 
Grammar_tget_grammar ()
 
virtual size_t hash () const override
 
virtual bool operator== (const MyHypothesis &l) const override
 Equality checks equality on each part. More...
 
virtual void push_program (Program< VirtualMachineState_t > &s, const key_t k) override
 A lexicon has valid indices if calls to op_RECURSE, op_MEM_RECURSE, op_SAFE_RECURSE, and op_SAFE_MEM_RECURSE all have arguments that are less than the size. (So this places no restrictions on the calling earlier factors) More...
 
virtual void complete () override
 Fill in all the holes in this hypothesis, at random, modifying self. NOTE for LOTHypotheses this will also compile, which is what we need to do for a LOTHypothesis. More...
 
virtual MyHypothesis restart () const override
 
int neighbors () const override
 Count the number of neighbors that are possible. (This should be size_t but int is more convenient.) More...
 
void expand_to_neighbor (int k) override
 Modify this hypothesis to become the k'th neighbor. NOTE This does not compile since it might not be complete. More...
 
virtual double neighbor_prior (int k) override
 What is the prior of the k'th neighbor? This does not need to return the full prior, only relative (among ks) More...
 
bool is_evaluable () const override
 Check if we can evaluate this node (meaning compute a prior and posterior). NOTE that this is not the same as whether it has zero neighbors, since lexica might have neighbors but be evalable. More...
 
virtual DiscreteDistribution< output_tcall (const key_t k, const input_t x, const output_t &err=output_t{})
 
virtual std::string serialize () const override
 
- Public Member Functions inherited from MCMCable< MyHypothesis, Utterance >
 MCMCable ()
 
virtual bool operator!= (const MyHypothesis &h) const
 
- Public Member Functions inherited from Searchable< MyHypothesis, ignore_t, ignore_t >
virtual MyHypothesis make_neighbor (int k) const
 Return a new hypothesis which is the k'th neighbor (just calls expand_to_neighbor) NOTE This does not compile since it might not be complete. More...
 
- Public Member Functions inherited from ProgramLoader< typename InnerHypothesis ::Grammar_t::VirtualMachineState_t >
virtual void push_program (Program< typename InnerHypothesis ::Grammar_t::VirtualMachineState_t > &s)
 
virtual void push_program (Program< typename InnerHypothesis ::Grammar_t::VirtualMachineState_t > &s, const short a)
 
virtual void push_program (Program< typename InnerHypothesis ::Grammar_t::VirtualMachineState_t > &s, const int a)
 
- Public Member Functions inherited from DeterministicLOTHypothesis< MyHypothesis, int, NumberSet, MyGrammar,&grammar, std::multiset< int > >
virtual output_t call (const input_t x, const output_t &err=output_t{})
 A variant of call that assumes no stochasticity and therefore outputs only a single value. (This uses a nullptr virtual machine pool, so will throw an error on flip) More...
 
- Public Member Functions inherited from LOTHypothesis< MyHypothesis, int, NumberSet, MyGrammar, grammar, std::multiset< int >, std::vector< std::multiset< int > >, typename MyGrammar ::VirtualMachineState_t >
 LOTHypothesis ()
 
 LOTHypothesis (Node &x)
 
 LOTHypothesis (Node &&x)
 
 LOTHypothesis (std::string s)
 
 LOTHypothesis (const LOTHypothesis &c)
 
 LOTHypothesis (const LOTHypothesis &&c)
 
LOTHypothesisoperator= (const LOTHypothesis &c)
 
LOTHypothesisoperator= (const LOTHypothesis &&c)
 
virtual MyHypothesis restart () const override
 This is used to restart chains, sampling from prior but ONLY for nodes that are can_resample. More...
 
Nodeget_value ()
 
const Nodeget_value () const
 
void set_value (Node &v, bool should_compile=true)
 Set the value to v. (NOTE: This compiles into a program) More...
 
void set_value (Node &&v, bool should_compile=true)
 
Grammar_tget_grammar () const
 
void compile ()
 
virtual void push_program (Program< VirtualMachineState_t > &s) override
 This puts the code from my node onto s. Used internally in e.g. recursion. More...
 
virtual std::string string (std::string prefix, bool usedot) const
 
virtual size_t hash () const override
 
virtual bool operator== (const MyHypothesis &h) const override
 Equality is checked on equality of values; note that greater-than is still on posteriors. More...
 
virtual void complete () override
 Modify this hypothesis's value by (randomly) filling in all the gaps. More...
 
virtual int neighbors () const override
 Count the number of neighbors that are possible. (This should be size_t but int is more convenient.) More...
 
virtual void expand_to_neighbor (int k) override
 Modify this hypothesis to become the k'th neighbor. NOTE This does not compile since it might not be complete. More...
 
virtual double neighbor_prior (int k) override
 What is the prior of the k'th neighbor? This does not need to return the full prior, only relative (among ks) More...
 
virtual bool is_evaluable () const override
 A node is "evaluable" if it is complete (meaning no null subnodes) More...
 
size_t recursion_count ()
 Count up how many times I use recursion – we keep a list of recursion here. More...
 
virtual std::string serialize () const override
 Convert this into a string which can be written to a file. More...
 
- Public Member Functions inherited from MCMCable< MyHypothesis, std::multiset< int >, std::vector< std::multiset< int > > >
 MCMCable ()
 
virtual bool operator!= (const MyHypothesis &h) const
 
- Public Member Functions inherited from Searchable< MyHypothesis, int, NumberSet >
virtual MyHypothesis make_neighbor (int k) const
 Return a new hypothesis which is the k'th neighbor (just calls expand_to_neighbor) NOTE This does not compile since it might not be complete. More...
 
- Public Member Functions inherited from DeterministicLOTHypothesis< MyHypothesis, set, word, MyGrammar,&grammar >
virtual output_t call (const input_t x, const output_t &err=output_t{})
 A variant of call that assumes no stochasticity and therefore outputs only a single value. (This uses a nullptr virtual machine pool, so will throw an error on flip) More...
 
- Public Member Functions inherited from LOTHypothesis< MyHypothesis, set, word, MyGrammar, grammar, defaultdatum_t< set, word >, std::vector< defaultdatum_t< set, word > >, typename MyGrammar ::VirtualMachineState_t >
 LOTHypothesis ()
 
 LOTHypothesis (Node &x)
 
 LOTHypothesis (Node &&x)
 
 LOTHypothesis (std::string s)
 
 LOTHypothesis (const LOTHypothesis &c)
 
 LOTHypothesis (const LOTHypothesis &&c)
 
LOTHypothesisoperator= (const LOTHypothesis &c)
 
LOTHypothesisoperator= (const LOTHypothesis &&c)
 
virtual MyHypothesis restart () const override
 This is used to restart chains, sampling from prior but ONLY for nodes that are can_resample. More...
 
Nodeget_value ()
 
const Nodeget_value () const
 
void set_value (Node &v, bool should_compile=true)
 Set the value to v. (NOTE: This compiles into a program) More...
 
void set_value (Node &&v, bool should_compile=true)
 
Grammar_tget_grammar () const
 
void compile ()
 
virtual void push_program (Program< VirtualMachineState_t > &s) override
 This puts the code from my node onto s. Used internally in e.g. recursion. More...
 
virtual std::string string (std::string prefix, bool usedot) const
 
virtual size_t hash () const override
 
virtual bool operator== (const MyHypothesis &h) const override
 Equality is checked on equality of values; note that greater-than is still on posteriors. More...
 
virtual void complete () override
 Modify this hypothesis's value by (randomly) filling in all the gaps. More...
 
virtual int neighbors () const override
 Count the number of neighbors that are possible. (This should be size_t but int is more convenient.) More...
 
virtual void expand_to_neighbor (int k) override
 Modify this hypothesis to become the k'th neighbor. NOTE This does not compile since it might not be complete. More...
 
virtual double neighbor_prior (int k) override
 What is the prior of the k'th neighbor? This does not need to return the full prior, only relative (among ks) More...
 
virtual bool is_evaluable () const override
 A node is "evaluable" if it is complete (meaning no null subnodes) More...
 
size_t recursion_count ()
 Count up how many times I use recursion – we keep a list of recursion here. More...
 
virtual std::string serialize () const override
 Convert this into a string which can be written to a file. More...
 
- Public Member Functions inherited from MCMCable< MyHypothesis, defaultdatum_t< set, word >, std::vector< defaultdatum_t< set, word > > >
 MCMCable ()
 
virtual bool operator!= (const MyHypothesis &h) const
 
- Public Member Functions inherited from Searchable< MyHypothesis, set, word >
virtual MyHypothesis make_neighbor (int k) const
 Return a new hypothesis which is the k'th neighbor (just calls expand_to_neighbor) NOTE This does not compile since it might not be complete. More...
 
- Public Member Functions inherited from StochasticLOTHypothesis< MyHypothesis, utterance, word, MyGrammar,&grammar >
virtual DiscreteDistribution< output_tcall (const input_t x, const output_t &err=output_t{})
 Run the virtual machine on input x, and marginalize over execution paths to return a distribution on outputs. Note that loader must be a program loader, and that is to handle recursion and other function calls. More...
 
- Public Member Functions inherited from LOTHypothesis< MyHypothesis, utterance, word, MyGrammar, grammar, defaultdatum_t< utterance, word >, std::vector< defaultdatum_t< utterance, word > >, typename MyGrammar ::VirtualMachineState_t >
 LOTHypothesis ()
 
 LOTHypothesis (Node &x)
 
 LOTHypothesis (Node &&x)
 
 LOTHypothesis (std::string s)
 
 LOTHypothesis (const LOTHypothesis &c)
 
 LOTHypothesis (const LOTHypothesis &&c)
 
LOTHypothesisoperator= (const LOTHypothesis &c)
 
LOTHypothesisoperator= (const LOTHypothesis &&c)
 
virtual MyHypothesis restart () const override
 This is used to restart chains, sampling from prior but ONLY for nodes that are can_resample. More...
 
Nodeget_value ()
 
const Nodeget_value () const
 
void set_value (Node &v, bool should_compile=true)
 Set the value to v. (NOTE: This compiles into a program) More...
 
void set_value (Node &&v, bool should_compile=true)
 
Grammar_tget_grammar () const
 
void compile ()
 
virtual void push_program (Program< VirtualMachineState_t > &s) override
 This puts the code from my node onto s. Used internally in e.g. recursion. More...
 
virtual std::string string (std::string prefix, bool usedot) const
 
virtual size_t hash () const override
 
virtual bool operator== (const MyHypothesis &h) const override
 Equality is checked on equality of values; note that greater-than is still on posteriors. More...
 
virtual void complete () override
 Modify this hypothesis's value by (randomly) filling in all the gaps. More...
 
virtual int neighbors () const override
 Count the number of neighbors that are possible. (This should be size_t but int is more convenient.) More...
 
virtual void expand_to_neighbor (int k) override
 Modify this hypothesis to become the k'th neighbor. NOTE This does not compile since it might not be complete. More...
 
virtual double neighbor_prior (int k) override
 What is the prior of the k'th neighbor? This does not need to return the full prior, only relative (among ks) More...
 
virtual bool is_evaluable () const override
 A node is "evaluable" if it is complete (meaning no null subnodes) More...
 
size_t recursion_count ()
 Count up how many times I use recursion – we keep a list of recursion here. More...
 
virtual std::string serialize () const override
 Convert this into a string which can be written to a file. More...
 
- Public Member Functions inherited from MCMCable< MyHypothesis, defaultdatum_t< utterance, word >, std::vector< defaultdatum_t< utterance, word > > >
 MCMCable ()
 
virtual bool operator!= (const MyHypothesis &h) const
 
- Public Member Functions inherited from Searchable< MyHypothesis, utterance, word >
virtual MyHypothesis make_neighbor (int k) const
 Return a new hypothesis which is the k'th neighbor (just calls expand_to_neighbor) NOTE This does not compile since it might not be complete. More...
 
- Public Member Functions inherited from Lexicon< MyHypothesis, S, InnerHypothesis, CL, CL, CLDatum >
 Lexicon ()
 
size_t nfactors () const
 Return the number of factors. More...
 
auto & get_value ()
 
const auto & get_value () const
 
InnerHypothesisat (const key_t &k)
 
const InnerHypothesisat (const key_t &k) const
 
InnerHypothesisoperator[] (const key_t &k)
 
const InnerHypothesisoperator[] (const key_t &k) const
 
bool contains (const key_t &key)
 
Grammar_tget_grammar ()
 
virtual size_t hash () const override
 
virtual bool operator== (const MyHypothesis &l) const override
 Equality checks equality on each part. More...
 
virtual void push_program (Program< VirtualMachineState_t > &s, const key_t k) override
 A lexicon has valid indices if calls to op_RECURSE, op_MEM_RECURSE, op_SAFE_RECURSE, and op_SAFE_MEM_RECURSE all have arguments that are less than the size. (So this places no restrictions on the calling earlier factors) More...
 
virtual void complete () override
 Fill in all the holes in this hypothesis, at random, modifying self. NOTE for LOTHypotheses this will also compile, which is what we need to do for a LOTHypothesis. More...
 
virtual MyHypothesis restart () const override
 
int neighbors () const override
 Count the number of neighbors that are possible. (This should be size_t but int is more convenient.) More...
 
void expand_to_neighbor (int k) override
 Modify this hypothesis to become the k'th neighbor. NOTE This does not compile since it might not be complete. More...
 
virtual double neighbor_prior (int k) override
 What is the prior of the k'th neighbor? This does not need to return the full prior, only relative (among ks) More...
 
bool is_evaluable () const override
 Check if we can evaluate this node (meaning compute a prior and posterior). NOTE that this is not the same as whether it has zero neighbors, since lexica might have neighbors but be evalable. More...
 
virtual DiscreteDistribution< output_tcall (const key_t k, const input_t x, const output_t &err=output_t{})
 
virtual std::string serialize () const override
 
- Public Member Functions inherited from MCMCable< MyHypothesis, CLDatum >
 MCMCable ()
 
virtual bool operator!= (const MyHypothesis &h) const
 
- Public Member Functions inherited from Searchable< MyHypothesis, CL, CL >
virtual MyHypothesis make_neighbor (int k) const
 Return a new hypothesis which is the k'th neighbor (just calls expand_to_neighbor) NOTE This does not compile since it might not be complete. More...
 
- Public Member Functions inherited from Lexicon< MyHypothesis, std::string, InnerHypothesis, BindingTree *, std::string >
 Lexicon ()
 
size_t nfactors () const
 Return the number of factors. More...
 
auto & get_value ()
 
const auto & get_value () const
 
InnerHypothesisat (const key_t &k)
 
const InnerHypothesisat (const key_t &k) const
 
InnerHypothesisoperator[] (const key_t &k)
 
const InnerHypothesisoperator[] (const key_t &k) const
 
bool contains (const key_t &key)
 
Grammar_tget_grammar ()
 
virtual size_t hash () const override
 
virtual bool operator== (const MyHypothesis &l) const override
 Equality checks equality on each part. More...
 
virtual void push_program (Program< VirtualMachineState_t > &s, const key_t k) override
 A lexicon has valid indices if calls to op_RECURSE, op_MEM_RECURSE, op_SAFE_RECURSE, and op_SAFE_MEM_RECURSE all have arguments that are less than the size. (So this places no restrictions on the calling earlier factors) More...
 
virtual void complete () override
 Fill in all the holes in this hypothesis, at random, modifying self. NOTE for LOTHypotheses this will also compile, which is what we need to do for a LOTHypothesis. More...
 
virtual MyHypothesis restart () const override
 
int neighbors () const override
 Count the number of neighbors that are possible. (This should be size_t but int is more convenient.) More...
 
void expand_to_neighbor (int k) override
 Modify this hypothesis to become the k'th neighbor. NOTE This does not compile since it might not be complete. More...
 
virtual double neighbor_prior (int k) override
 What is the prior of the k'th neighbor? This does not need to return the full prior, only relative (among ks) More...
 
bool is_evaluable () const override
 Check if we can evaluate this node (meaning compute a prior and posterior). NOTE that this is not the same as whether it has zero neighbors, since lexica might have neighbors but be evalable. More...
 
virtual DiscreteDistribution< output_tcall (const key_t k, const input_t x, const output_t &err=output_t{})
 
virtual std::string serialize () const override
 
- Public Member Functions inherited from MCMCable< MyHypothesis, defaultdatum_t< BindingTree *, std::string > >
 MCMCable ()
 
virtual bool operator!= (const MyHypothesis &h) const
 
- Public Member Functions inherited from Searchable< MyHypothesis, BindingTree *, std::string >
virtual MyHypothesis make_neighbor (int k) const
 Return a new hypothesis which is the k'th neighbor (just calls expand_to_neighbor) NOTE This does not compile since it might not be complete. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from LOTHypothesis< MyHypothesis, S, S, MyGrammar, grammar, defaultdatum_t< S, S >, std::vector< defaultdatum_t< S, S > >, typename MyGrammar ::VirtualMachineState_t >
static MyHypothesis sample ()
 
static MyHypothesis from_string (Grammar_t *g, std::string s)
 
static MyHypothesis deserialize (const std::string &s)
 Convert this from a string which was in a file. More...
 
- Static Public Member Functions inherited from MCMCable< MyHypothesis, defaultdatum_t< S, S >, std::vector< defaultdatum_t< S, S > > >
static MyHypothesis sample ()
 Static function for making a hypothesis. Be careful using this with references because they may not foward right (for reasons that are unclear to me) More...
 
- Static Public Member Functions inherited from Serializable< MyHypothesis >
static MyHypothesis deserialize (const std::string &)
 
- Static Public Member Functions inherited from Lexicon< MyHypothesis, std::string, InnerHypothesis, ignore_t, ignore_t, Utterance >
static MyHypothesis sample (std::initializer_list< key_t > lst)
 Sample with n factors. More...
 
static MyHypothesis sample (const std::vector< key_t > &lst)
 
static MyHypothesis make (A... a)
 
static MyHypothesis deserialize (const std::string s)
 
- Static Public Member Functions inherited from MCMCable< MyHypothesis, Utterance >
static MyHypothesis sample ()
 Static function for making a hypothesis. Be careful using this with references because they may not foward right (for reasons that are unclear to me) More...
 
- Static Public Member Functions inherited from LOTHypothesis< MyHypothesis, int, NumberSet, MyGrammar, grammar, std::multiset< int >, std::vector< std::multiset< int > >, typename MyGrammar ::VirtualMachineState_t >
static MyHypothesis sample ()
 
static MyHypothesis from_string (Grammar_t *g, std::string s)
 
static MyHypothesis deserialize (const std::string &s)
 Convert this from a string which was in a file. More...
 
- Static Public Member Functions inherited from MCMCable< MyHypothesis, std::multiset< int >, std::vector< std::multiset< int > > >
static MyHypothesis sample ()
 Static function for making a hypothesis. Be careful using this with references because they may not foward right (for reasons that are unclear to me) More...
 
- Static Public Member Functions inherited from LOTHypothesis< MyHypothesis, set, word, MyGrammar, grammar, defaultdatum_t< set, word >, std::vector< defaultdatum_t< set, word > >, typename MyGrammar ::VirtualMachineState_t >
static MyHypothesis sample ()
 
static MyHypothesis from_string (Grammar_t *g, std::string s)
 
static MyHypothesis deserialize (const std::string &s)
 Convert this from a string which was in a file. More...
 
- Static Public Member Functions inherited from MCMCable< MyHypothesis, defaultdatum_t< set, word >, std::vector< defaultdatum_t< set, word > > >
static MyHypothesis sample ()
 Static function for making a hypothesis. Be careful using this with references because they may not foward right (for reasons that are unclear to me) More...
 
- Static Public Member Functions inherited from LOTHypothesis< MyHypothesis, utterance, word, MyGrammar, grammar, defaultdatum_t< utterance, word >, std::vector< defaultdatum_t< utterance, word > >, typename MyGrammar ::VirtualMachineState_t >
static MyHypothesis sample ()
 
static MyHypothesis from_string (Grammar_t *g, std::string s)
 
static MyHypothesis deserialize (const std::string &s)
 Convert this from a string which was in a file. More...
 
- Static Public Member Functions inherited from MCMCable< MyHypothesis, defaultdatum_t< utterance, word >, std::vector< defaultdatum_t< utterance, word > > >
static MyHypothesis sample ()
 Static function for making a hypothesis. Be careful using this with references because they may not foward right (for reasons that are unclear to me) More...
 
- Static Public Member Functions inherited from Lexicon< MyHypothesis, S, InnerHypothesis, CL, CL, CLDatum >
static MyHypothesis sample (std::initializer_list< key_t > lst)
 Sample with n factors. More...
 
static MyHypothesis sample (const std::vector< key_t > &lst)
 
static MyHypothesis make (A... a)
 
static MyHypothesis deserialize (const std::string s)
 
- Static Public Member Functions inherited from MCMCable< MyHypothesis, CLDatum >
static MyHypothesis sample ()
 Static function for making a hypothesis. Be careful using this with references because they may not foward right (for reasons that are unclear to me) More...
 
- Static Public Member Functions inherited from Lexicon< MyHypothesis, std::string, InnerHypothesis, BindingTree *, std::string >
static MyHypothesis sample (std::initializer_list< key_t > lst)
 Sample with n factors. More...
 
static MyHypothesis sample (const std::vector< key_t > &lst)
 
static MyHypothesis make (A... a)
 
static MyHypothesis deserialize (const std::string s)
 
- Static Public Member Functions inherited from MCMCable< MyHypothesis, defaultdatum_t< BindingTree *, std::string > >
static MyHypothesis sample ()
 Static function for making a hypothesis. Be careful using this with references because they may not foward right (for reasons that are unclear to me) More...
 
- Public Attributes inherited from LOTHypothesis< MyHypothesis, S, S, MyGrammar, grammar, defaultdatum_t< S, S >, std::vector< defaultdatum_t< S, S > >, typename MyGrammar ::VirtualMachineState_t >
unsigned long total_instruction_count_last_call
 
unsigned long total_vms_steps
 
Program< VirtualMachineState_tprogram
 
- Public Attributes inherited from Bayesable< Args... >
double prior
 
double likelihood
 
double posterior
 
uintmax_t born
 
size_t born_chain_idx
 
- Public Attributes inherited from ProgramLoader< typename MyGrammar ::VirtualMachineState_t >
bool was_called
 
- Public Attributes inherited from Lexicon< MyHypothesis, std::string, InnerHypothesis, ignore_t, ignore_t, Utterance >
std::map< key_t, InnerHypothesisfactors
 
- Public Attributes inherited from ProgramLoader< typename InnerHypothesis ::Grammar_t::VirtualMachineState_t >
bool was_called
 
- Public Attributes inherited from LOTHypothesis< MyHypothesis, int, NumberSet, MyGrammar, grammar, std::multiset< int >, std::vector< std::multiset< int > >, typename MyGrammar ::VirtualMachineState_t >
unsigned long total_instruction_count_last_call
 
unsigned long total_vms_steps
 
Program< VirtualMachineState_tprogram
 
- Public Attributes inherited from LOTHypothesis< MyHypothesis, set, word, MyGrammar, grammar, defaultdatum_t< set, word >, std::vector< defaultdatum_t< set, word > >, typename MyGrammar ::VirtualMachineState_t >
unsigned long total_instruction_count_last_call
 
unsigned long total_vms_steps
 
Program< VirtualMachineState_tprogram
 
- Public Attributes inherited from LOTHypothesis< MyHypothesis, utterance, word, MyGrammar, grammar, defaultdatum_t< utterance, word >, std::vector< defaultdatum_t< utterance, word > >, typename MyGrammar ::VirtualMachineState_t >
unsigned long total_instruction_count_last_call
 
unsigned long total_vms_steps
 
Program< VirtualMachineState_tprogram
 
- Public Attributes inherited from Lexicon< MyHypothesis, S, InnerHypothesis, CL, CL, CLDatum >
std::map< key_t, InnerHypothesisfactors
 
- Public Attributes inherited from Lexicon< MyHypothesis, std::string, InnerHypothesis, BindingTree *, std::string >
std::map< key_t, InnerHypothesisfactors
 
- Static Public Attributes inherited from LOTHypothesis< MyHypothesis, S, S, MyGrammar, grammar, defaultdatum_t< S, S >, std::vector< defaultdatum_t< S, S > >, typename MyGrammar ::VirtualMachineState_t >
static const char SerializationDelimiter
 
static const size_t MAX_NODES
 
- Static Public Attributes inherited from Lexicon< MyHypothesis, std::string, InnerHypothesis, ignore_t, ignore_t, Utterance >
static const char FactorDelimiter
 
static double p_factor_propose
 
- Static Public Attributes inherited from LOTHypothesis< MyHypothesis, int, NumberSet, MyGrammar, grammar, std::multiset< int >, std::vector< std::multiset< int > >, typename MyGrammar ::VirtualMachineState_t >
static const char SerializationDelimiter
 
static const size_t MAX_NODES
 
- Static Public Attributes inherited from LOTHypothesis< MyHypothesis, set, word, MyGrammar, grammar, defaultdatum_t< set, word >, std::vector< defaultdatum_t< set, word > >, typename MyGrammar ::VirtualMachineState_t >
static const char SerializationDelimiter
 
static const size_t MAX_NODES
 
- Static Public Attributes inherited from LOTHypothesis< MyHypothesis, utterance, word, MyGrammar, grammar, defaultdatum_t< utterance, word >, std::vector< defaultdatum_t< utterance, word > >, typename MyGrammar ::VirtualMachineState_t >
static const char SerializationDelimiter
 
static const size_t MAX_NODES
 
- Static Public Attributes inherited from Lexicon< MyHypothesis, S, InnerHypothesis, CL, CL, CLDatum >
static const char FactorDelimiter
 
static double p_factor_propose
 
- Static Public Attributes inherited from Lexicon< MyHypothesis, std::string, InnerHypothesis, BindingTree *, std::string >
static const char FactorDelimiter
 
static double p_factor_propose
 
- Protected Attributes inherited from LOTHypothesis< MyHypothesis, S, S, MyGrammar, grammar, defaultdatum_t< S, S >, std::vector< defaultdatum_t< S, S > >, typename MyGrammar ::VirtualMachineState_t >
Node value
 
- Protected Attributes inherited from LOTHypothesis< MyHypothesis, int, NumberSet, MyGrammar, grammar, std::multiset< int >, std::vector< std::multiset< int > >, typename MyGrammar ::VirtualMachineState_t >
Node value
 
- Protected Attributes inherited from LOTHypothesis< MyHypothesis, set, word, MyGrammar, grammar, defaultdatum_t< set, word >, std::vector< defaultdatum_t< set, word > >, typename MyGrammar ::VirtualMachineState_t >
Node value
 
- Protected Attributes inherited from LOTHypothesis< MyHypothesis, utterance, word, MyGrammar, grammar, defaultdatum_t< utterance, word >, std::vector< defaultdatum_t< utterance, word > >, typename MyGrammar ::VirtualMachineState_t >
Node value
 

Detailed Description

we don't need inputs/outputs for out MyHypothesis

Declare a grammar
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
class MyGrammar : public Grammar<utterance,word, bool,word,set,objectkind,utterance,wmset,magnitude,double>,
public Singleton<MyGrammar> {
public:
add("undef", +[]() -> word { return U; });
add("a", +[]() -> objectkind { return 'a'; });
add("b", +[]() -> objectkind { return 'b'; });
add("c", +[]() -> objectkind { return 'c'; });
add("d", +[]() -> objectkind { return 'd'; });
add("e", +[]() -> objectkind { return 'e'; });
add("one", +[]() -> word { return 1; }, 0.1);
add("two", +[]() -> word { return 2; }, 0.1);
add("three", +[]() -> word { return 3; }, 0.1);
add("four", +[]() -> word { return 4; }, 0.1);
add("five", +[]() -> word { return 5; }, 0.1);
add("six", +[]() -> word { return 6; }, 0.1);
add("seven", +[]() -> word { return 7; }, 0.1);
add("eight", +[]() -> word { return 8; }, 0.1);
add("nine", +[]() -> word { return 9; }, 0.1);
add("ten", +[]() -> word { return 10; }, 0.1);
add("next(%s)", +[](word w) -> word { return w == U ? U : w+1;});
add("prev(%s)", +[](word w) -> word { return w == U or w == 1 ? U : w-1; });
// extract from the context/utterance
add("%s.set", +[](utterance u) -> set { return u.s; }, 10.0);
add("%s.obj", +[](utterance u) -> objectkind { return u.o; }, 10.0);
// build utterances -- needed for useful recursion
add("<%s,%s>", +[](set s, objectkind o) -> utterance { return utterance{s,o}; });
add("union(%s,%s)", +[](set x, set y) -> set {
if(x.size()+y.size() > MAX_SET_SIZE)
throw VMSRuntimeError();
return x+y;
});
add("intersection(%s,%s)", +[](set x, set y) -> set {
std::string out = "";
for(size_t yi=0;yi<y.length();yi++) {
std::string s = y.substr(yi,1);
size_t pos = x.find(s); // do I occur?
if(pos != std::string::npos) {
out.append(s);
}
}
return out;
});
add("difference(%s,%s)", +[](set x, set y) -> set {
std::string out = x;
for(size_t yi=0;yi<y.length();yi++) {
std::string s = y.substr(yi,1);
size_t pos = out.find(s); // do I occur?
if(pos != std::string::npos) {
out.erase(pos,1); // remove that character
}
}
return out;
});
add("filter(%s,%s)", +[](set x, objectkind t) -> set {
std::string tstr = std::string(1,t); // a std::string to find
std::string out = "";
size_t pos = x.find(tstr);
while (pos != std::string::npos) {
out = out + tstr;
pos = x.find(tstr,pos+1);
}
return out;
});
add("select(%s)", +[](set x) -> set {
return x.substr(0,1);
});
add("selectO(%s,%s)", +[](set x, objectkind o) -> set {
if(x.find(o) != std::string::npos){
return std::string(1,o); // must exist there
}
else {
return set("");
}
});
add("match(%s,%s)", +[](wmset x, set s) -> bool { return x == (wmset)s.size(); }, 1.0);
add("{}", +[]() -> wmset { return (wmset)0; });
add("{o}", +[]() -> wmset { return (wmset)1; });
add("{o,o}", +[]() -> wmset { return (wmset)2; });
add("{o,o,o}", +[]() -> wmset { return (wmset)3; });
// // For the MIX version
// add("{o,o,o,o}", +[]() -> wmset { return (wmset)4; });
// add("{o,o,o,o,o}", +[]() -> wmset { return (wmset)5; });
// add("{o,o,o,o,o,o}", +[]() -> wmset { return (wmset)6; });
// ANS operations
add("ANSeq(%s,%s)", +[](set a, set b) -> double { return ANSzero(a.length(), b.length()); }, 1.0/3.0);
add("ANSeq(%s,%s)", +[](set a, wmset b) -> double { return ANSzero(a.length(), b); }, 1.0/3.0);
add("ANSeq(%s,%s)", +[](set a, magnitude b) -> double { return ANSzero(a.length(), b); }, 1.0/3.0);
add("ANSlt(%s,%s)", +[](set a, set b) -> double { return ANSdiff(a.length(), b.length()); }, 1.0/5.0);
add("ANSlt(%s,%s)", +[](set a, wmset b) -> double { return ANSdiff(a.length(), b); }, 1.0/5.0);
add("ANSlt(%s,%s)", +[](set a, magnitude b) -> double { return ANSdiff(a.length(), b); }, 1.0/5.0);
add("ANSlt(%s,%s)", +[](wmset b, set a) -> double { return ANSdiff(b, a.length()); }, 1.0/5.0);
add("ANSlt(%s,%s)", +[](magnitude b, set a) -> double { return ANSdiff(b, a.length()); }, 1.0/5.0);
add("1", +[]() -> magnitude { return 1; });
add("2", +[]() -> magnitude { return 2; });
add("3", +[]() -> magnitude { return 3; });
add("4", +[]() -> magnitude { return 4; });
add("5", +[]() -> magnitude { return 5; });
add("6", +[]() -> magnitude { return 6; });
add("7", +[]() -> magnitude { return 7; });
add("8", +[]() -> magnitude { return 8; });
add("9", +[]() -> magnitude { return 9; });
add("10", +[]() -> magnitude { return 10; });
add("and(%s,%s)", Builtins::And<MyGrammar>, 1./3);
add("or(%s,%s)", Builtins::Or<MyGrammar>, 1./3);
add("not(%s)", Builtins::Not<MyGrammar>, 1./3);
add("x", Builtins::X<MyGrammar>, 10.);
add("flip(%s)", Builtins::FlipP<MyGrammar>);
add("if(%s,%s,%s)", Builtins::If<MyGrammar,double>);
add("if(%s,%s,%s)", Builtins::If<MyGrammar,set>);
add("if(%s,%s,%s)", Builtins::If<MyGrammar,word>);
add("if(%s,%s,%s)", Builtins::If<MyGrammar,wmset>);
add("if(%s,%s,%s)", Builtins::If<MyGrammar,objectkind>);
add("if(%s,%s,%s)", Builtins::If<MyGrammar,magnitude>);
add("if(%s,%s,%s)", Builtins::If<MyGrammar,utterance>);
add("recurse(%s)", Builtins::Recurse<MyGrammar>);
}
/*

Declare our hypothesis type ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Declare a grammar
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
class MyGrammar : public Grammar<set, word, bool, word, set>,
public Singleton<MyGrammar> {
public:
add("undef", +[]() -> word { return U; });
add("one", +[]() -> word { return 1; }, 0.1);
add("two", +[]() -> word { return 2; }, 0.1);
add("three", +[]() -> word { return 3; }, 0.1);
add("four", +[]() -> word { return 4; }, 0.1);
add("five", +[]() -> word { return 5; }, 0.1);
add("six", +[]() -> word { return 6; }, 0.1);
add("seven", +[]() -> word { return 7; }, 0.1);
add("eight", +[]() -> word { return 8; }, 0.1);
add("nine", +[]() -> word { return 9; }, 0.1);
add("ten", +[]() -> word { return 10; }, 0.1);
add("next(%s)", +[](word w) -> word { return w == U ? U : w+1;});
add("prev(%s)", +[](word w) -> word { return w == U or w == 1 ? U : w-1; });
// extract from the context/utterance
add("singleton(%s)", +[](set s) -> bool { return s.count()==1; }, 2.0);
add("doubleton(%s)", +[](set s) -> bool { return s.count()==2; }, 2.0);
add("tripleton(%s)", +[](set s) -> bool { return s.count()==3; }, 2.0);
add("select(%s)", +[](set s) -> set {
if(s.count()==0) {
throw VMSRuntimeError();
}
else {
for(size_t i=0;i<s.size();i++) {
if(s[i]) { // return the first element of th eset
set out;
out[i] = true;
return out;
}
}
assert(false && "*** Should not get here");
}
});
// set operations on ints -- these will modify x in place
add("union(%s,%s)", +[](set x, set y) -> set { return x |= y; });
add("setdifference(%s,%s)", +[](set x, set y) -> set { return x &= ~y; });
add("intersection(%s,%s)", +[](set x, set y) -> set { return x &= y; });
add("complement(%s,%s)", +[](set x, set y) -> set { return x = ~x; }); // not in the original
add("and(%s,%s)", Builtins::And<MyGrammar>, 1./3.);
add("or(%s,%s)", Builtins::Or<MyGrammar>, 1./3.);
add("not(%s)", Builtins::Not<MyGrammar>, 1./3.);
add("x", Builtins::X<MyGrammar>, 25.0);
add("if(%s,%s,%s)", Builtins::If<MyGrammar,set>, 1./2);
add("if(%s,%s,%s)", Builtins::If<MyGrammar,word>, 1./2);
add("recurse(%s)", Builtins::Recurse<MyGrammar>);
}
/*

Declare our hypothesis type ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Define the grammar
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
class MyGrammar : public Grammar<int, NumberSet, int, NumberSet>,
public Singleton<MyGrammar> {
public:
add("numbers", +[]() -> NumberSet { return numbers; });
add("primes", +[]() -> NumberSet { return primes; });
add("evens", +[]() -> NumberSet { return evens; });
add("odds", +[]() -> NumberSet { return odds; });
add("squares", +[]() -> NumberSet { return squares; });
add("decades", +[]() -> NumberSet { return decades; });
add("elevens", +[]() -> NumberSet { return elevens; });
add("fibonacci", +[]() -> NumberSet { return fibonacci; });
add("weird", +[]() -> NumberSet { return weird; });
// we give range a very low prior here or else it sure dominates
add("range(%s,%s)", +[](int x, int y) -> NumberSet {
NumberSet out;
for(int i=std::max(x,Nlow);i<=std::min(y,N);i++) { // we need min/max bounds here or we spend all our time adding garbage
out.insert(i);
}
return out;
}, 0.1);
add("union(%s,%s)", +[](NumberSet a, NumberSet b) -> NumberSet {
for(auto& x : b) {
a.insert(x);
}
return a;
});
add("intersection(%s,%s)", +[](NumberSet a, NumberSet b) -> NumberSet {
NumberSet out;
for(auto& x : a) {
if(b.find(x) != b.end())
out.insert(x);
}
return out;
});
add("complement(%s)", +[](NumberSet a) -> NumberSet {
NumberSet out;
for(size_t i=Nlow;i<N;i++) {
if(a.find(i) == a.end())
out.insert(i);
}
return out;
});
add("(%s + %s)", +[](NumberSet s, int n) -> NumberSet {
NumberSet out;
for(auto& x : s) {
out.insert(x + n);
}
return out;
});
add("(%s * %s)", +[](NumberSet s, int n) -> NumberSet {
NumberSet out;
for(auto& x : s) {
out.insert(x * n);
}
return out;
});
add("pow(%s,%s)", +[](NumberSet s, int n) -> NumberSet {
NumberSet out;
for(auto& x : s) {
out.insert(std::pow(x,n));
}
return out;
});
// we'll give this a space so it's different -- cute
add("pow(%s, %s)", +[](int n, NumberSet s) -> NumberSet {
NumberSet out;
for(auto& x : s) {
out.insert(std::pow(n,x));
}
return out;
});
// int operations
add("(%s+%s)", +[](int x, int y) -> int { return x+y;});
add("(%s*%s)", +[](int x, int y) -> int { return x*y;});
add("(%s-%s)", +[](int x, int y) -> int { return x-y;});
add("(%s^%s)", +[](int x, int y) -> int { return std::pow(x,y);});
for(int i=Nlow;i<=N;i++) {
// We put "#" here so that in grammar inference we can find these rules easily!
add_terminal( "#"+str(i), i, 10.0/(N-Nlow));
}
add("x", Builtins::X<MyGrammar>);
}
/*

Define hypothesis This is an example where our data is different – it's a set instead of a vector ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Author
piantado
Date
04/05/20

Member Typedef Documentation

◆ Super [1/5]

◆ Super [2/5]

◆ Super [3/5]

◆ Super [4/5]

using MyHypothesis::Super = DeterministicLOTHypothesis<MyHypothesis,int,NumberSet,MyGrammar,&grammar,std::multiset<int> >

◆ Super [5/5]

Member Function Documentation

◆ call()

DiscreteDistribution<word> MyHypothesis::call ( const utterance &  input)
inline

◆ clear_cache() [1/2]

void MyHypothesis::clear_cache ( )
inline

◆ clear_cache() [2/2]

void MyHypothesis::clear_cache ( )
inline

◆ compute_likelihood() [1/4]

double MyHypothesis::compute_likelihood ( const data_t data,
const double  breakout = -infinity 
)
inlineoverridevirtual

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 from Bayesable< Args... >.

◆ compute_likelihood() [2/4]

double MyHypothesis::compute_likelihood ( const data_t data,
const double  breakout = -infinity 
)
inlineoverridevirtual

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 from Bayesable< Args... >.

◆ compute_likelihood() [3/4]

virtual double MyHypothesis::compute_likelihood ( const data_t data,
double  breakout = -infinity 
)
inlineoverridevirtual

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

TODO: CHECK THIS BECAUSE WHY ISNT nprseup npresuANDNOTTRUE?

Reimplemented from Bayesable< Args... >.

◆ compute_likelihood() [4/4]

virtual double MyHypothesis::compute_likelihood ( const data_t data,
const double  breakout = -infinity 
)
inlineoverridevirtual

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 from Bayesable< Args... >.

◆ compute_prior() [1/3]

virtual double MyHypothesis::compute_prior ( )
inlineoverridevirtual

◆ compute_prior() [2/3]

double MyHypothesis::compute_prior ( )
inlineoverridevirtual

◆ compute_prior() [3/3]

double MyHypothesis::compute_prior ( )
inlineoverridevirtual

◆ compute_single_likelihood() [1/3]

double MyHypothesis::compute_single_likelihood ( const datum_t datum)
inlineoverridevirtual

◆ compute_single_likelihood() [2/3]

virtual double MyHypothesis::compute_single_likelihood ( const datum_t datum)
inlineoverridevirtual

◆ compute_single_likelihood() [3/3]

double MyHypothesis::compute_single_likelihood ( const datum_t datum)
inlineoverridevirtual

◆ KLstring()

std::string MyHypothesis::KLstring ( )
inline

◆ print()

void MyHypothesis::print ( std::string  prefix = "#\n")
inlineoverride

◆ propose()

virtual std::optional<std::pair<MyHypothesis,double> > MyHypothesis::propose ( ) const
inlineoverridevirtual

This proposal guarantees that there will be at least one factor that is proposed to. Each individual factor is proposed to with p_factor_propose.

Returns

Reimplemented from Lexicon< MyHypothesis, std::string, InnerHypothesis, BindingTree *, std::string >.

◆ show() [1/4]

virtual void MyHypothesis::show ( std::string  prefix = "")
inlineoverridevirtual

Reimplemented from Bayesable< Args... >.

◆ show() [2/4]

virtual void MyHypothesis::show ( std::string  prefix = "")
inlineoverridevirtual

Reimplemented from Bayesable< Args... >.

◆ show() [3/4]

virtual void MyHypothesis::show ( std::string  prefix = "")
inlineoverridevirtual

Default printing of a hypothesis includes its posterior, prior, likelihood, and quoted string version

Parameters
prefix

Reimplemented from Bayesable< Args... >.

◆ show() [4/4]

virtual void MyHypothesis::show ( std::string  prefix = "")
inlineoverridevirtual

Reimplemented from Bayesable< Args... >.

◆ string()

virtual std::string MyHypothesis::string ( std::string  prefix = "") const
inlineoverridevirtual

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