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

More...

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

Public Member Functions

 MyGrammar ()
 
 MyGrammar ()
 
 MyGrammar ()
 
- Public Member Functions inherited from Grammar< MyObject, bool, MyObject, bool >
 Grammar ()
 
 Grammar (const Grammar &g)=delete
 
 Grammar (const Grammar &&g)=delete
 
RuleIterator begin () const
 
RuleIterator end () const
 
constexpr nonterminal_t start ()
 The start nonterminal type. More...
 
constexpr size_t count_nonterminals () const
 
size_t count_nonterminals (nonterminal_t nt) const
 
size_t count_rules (const nonterminal_t nt) const
 
size_t count_rules () const
 
size_t count_terminals (nonterminal_t nt) const
 
void add_vms (std::string fmt, FT *f, double p=1.0, Op o=Op::Standard, int a=0)
 
void add (std::string fmt, Primitive< T, args... > &b, double p=1.0, int a=0)
 
void add (std::string fmt, std::function< T(args...)> f, double p=1.0, Op o=Op::Standard, int a=0)
 
void add (std::string fmt, T(*_f)(args...), double p=1.0, Op o=Op::Standard, int a=0)
 
void add_terminal (std::string fmt, T x, double p=1.0, Op o=Op::Standard, int a=0)
 Add a variable that is NOT A function – simplification for adding alphabets etc. This just wraps stuff in a thunk for us to make it easier. NOTE: x is copied by value. More...
 
void remove_all (nonterminal_t nt)
 Remove all the nonterminals of this type from the grammar. NOTE: This is generally a really bad idea unless you know what you are doing. More...
 
size_t get_index_of (const Rule *r) const
 
virtual Ruleget_rule (const nonterminal_t nt, size_t k) const
 
virtual Ruleget_rule (const nonterminal_t nt, const Op o, const int a=0)
 
virtual Ruleget_rule (const nonterminal_t nt, size_t i)
 
virtual Ruleget_rule (const nonterminal_t nt, const std::string s) const
 
virtual Ruleget_rule (const std::string s) const
 
double rule_normalizer (const nonterminal_t nt) const
 
virtual Rulesample_rule (const nonterminal_t nt) const
 
Node makeNode (const Rule *r) const
 
Node generate (const nonterminal_t ntfrom=nt< output_t >(), unsigned long depth=0) const
 
Node copy_resample (const Node &node, bool f(const Node &n)) const
 
std::vector< size_t > get_cumulative_indices () const
 
std::vector< size_t > get_counts (const Node &node) const
 
std::vector< size_t > get_counts (const std::vector< T > &v) const
 Compute a vector of counts of how often each rule was used, in a standard order given by iterating over nts and then iterating over rules. More...
 
std::vector< size_t > get_counts (const std::map< K, T > &v) const
 
double log_probability (const Node &n) const
 
Node from_parseable (std::deque< std::string > &q) const
 
Node from_parseable (std::string s) const
 
Node from_parseable (const char *c) const
 
size_t neighbors (const Node &node) const
 
void expand_to_neighbor (Node &node, int &which)
 
double neighbor_prior (const Node &node, int &which) const
 
void complete (Node &node)
 
std::tuple< int, std::vector< int >, int > find_open_commas_close (const std::string s)
 
Node simple_parse (std::string s)
 Very simple parsing routine that takes a string like "and(not(or(eq_pos(pos(parent(x)),'NP-POSS'),eq_pos('NP-S',pos(x)))),corefers(x))" (from the Binding example) and parses it into a Node. More...
 
- Public Member Functions inherited from Singleton< MyGrammar >
 Singleton ()
 
- Public Member Functions inherited from Grammar< S, S, S, char, bool >
 Grammar ()
 
 Grammar (const Grammar &g)=delete
 
 Grammar (const Grammar &&g)=delete
 
RuleIterator begin () const
 
RuleIterator end () const
 
constexpr nonterminal_t start ()
 The start nonterminal type. More...
 
constexpr size_t count_nonterminals () const
 
size_t count_nonterminals (nonterminal_t nt) const
 
size_t count_rules (const nonterminal_t nt) const
 
size_t count_rules () const
 
size_t count_terminals (nonterminal_t nt) const
 
void add_vms (std::string fmt, FT *f, double p=1.0, Op o=Op::Standard, int a=0)
 
void add (std::string fmt, Primitive< T, args... > &b, double p=1.0, int a=0)
 
void add (std::string fmt, std::function< T(args...)> f, double p=1.0, Op o=Op::Standard, int a=0)
 
void add (std::string fmt, T(*_f)(args...), double p=1.0, Op o=Op::Standard, int a=0)
 
void add_terminal (std::string fmt, T x, double p=1.0, Op o=Op::Standard, int a=0)
 Add a variable that is NOT A function – simplification for adding alphabets etc. This just wraps stuff in a thunk for us to make it easier. NOTE: x is copied by value. More...
 
void remove_all (nonterminal_t nt)
 Remove all the nonterminals of this type from the grammar. NOTE: This is generally a really bad idea unless you know what you are doing. More...
 
size_t get_index_of (const Rule *r) const
 
virtual Ruleget_rule (const nonterminal_t nt, size_t k) const
 
virtual Ruleget_rule (const nonterminal_t nt, const Op o, const int a=0)
 
virtual Ruleget_rule (const nonterminal_t nt, size_t i)
 
virtual Ruleget_rule (const nonterminal_t nt, const std::string s) const
 
virtual Ruleget_rule (const std::string s) const
 
double rule_normalizer (const nonterminal_t nt) const
 
virtual Rulesample_rule (const nonterminal_t nt) const
 
Node makeNode (const Rule *r) const
 
Node generate (const nonterminal_t ntfrom=nt< output_t >(), unsigned long depth=0) const
 
Node copy_resample (const Node &node, bool f(const Node &n)) const
 
std::vector< size_t > get_cumulative_indices () const
 
std::vector< size_t > get_counts (const Node &node) const
 
std::vector< size_t > get_counts (const std::vector< T > &v) const
 Compute a vector of counts of how often each rule was used, in a standard order given by iterating over nts and then iterating over rules. More...
 
std::vector< size_t > get_counts (const std::map< K, T > &v) const
 
double log_probability (const Node &n) const
 
Node from_parseable (std::deque< std::string > &q) const
 
Node from_parseable (std::string s) const
 
Node from_parseable (const char *c) const
 
size_t neighbors (const Node &node) const
 
void expand_to_neighbor (Node &node, int &which)
 
double neighbor_prior (const Node &node, int &which) const
 
void complete (Node &node)
 
std::tuple< int, std::vector< int >, int > find_open_commas_close (const std::string s)
 
Node simple_parse (std::string s)
 Very simple parsing routine that takes a string like "and(not(or(eq_pos(pos(parent(x)),'NP-POSS'),eq_pos('NP-S',pos(x)))),corefers(x))" (from the Binding example) and parses it into a Node. More...
 
- Public Member Functions inherited from Grammar< MyInput, bool, bool, MyObject, MyInput, ObjectSet, ObjectToBool, ObjectxObjectToBool >
 Grammar ()
 
 Grammar (const Grammar &g)=delete
 
 Grammar (const Grammar &&g)=delete
 
RuleIterator begin () const
 
RuleIterator end () const
 
constexpr nonterminal_t start ()
 The start nonterminal type. More...
 
constexpr size_t count_nonterminals () const
 
size_t count_nonterminals (nonterminal_t nt) const
 
size_t count_rules (const nonterminal_t nt) const
 
size_t count_rules () const
 
size_t count_terminals (nonterminal_t nt) const
 
void add_vms (std::string fmt, FT *f, double p=1.0, Op o=Op::Standard, int a=0)
 
void add (std::string fmt, Primitive< T, args... > &b, double p=1.0, int a=0)
 
void add (std::string fmt, std::function< T(args...)> f, double p=1.0, Op o=Op::Standard, int a=0)
 
void add (std::string fmt, T(*_f)(args...), double p=1.0, Op o=Op::Standard, int a=0)
 
void add_terminal (std::string fmt, T x, double p=1.0, Op o=Op::Standard, int a=0)
 Add a variable that is NOT A function – simplification for adding alphabets etc. This just wraps stuff in a thunk for us to make it easier. NOTE: x is copied by value. More...
 
void remove_all (nonterminal_t nt)
 Remove all the nonterminals of this type from the grammar. NOTE: This is generally a really bad idea unless you know what you are doing. More...
 
size_t get_index_of (const Rule *r) const
 
virtual Ruleget_rule (const nonterminal_t nt, size_t k) const
 
virtual Ruleget_rule (const nonterminal_t nt, const Op o, const int a=0)
 
virtual Ruleget_rule (const nonterminal_t nt, size_t i)
 
virtual Ruleget_rule (const nonterminal_t nt, const std::string s) const
 
virtual Ruleget_rule (const std::string s) const
 
double rule_normalizer (const nonterminal_t nt) const
 
virtual Rulesample_rule (const nonterminal_t nt) const
 
Node makeNode (const Rule *r) const
 
Node generate (const nonterminal_t ntfrom=nt< output_t >(), unsigned long depth=0) const
 
Node copy_resample (const Node &node, bool f(const Node &n)) const
 
std::vector< size_t > get_cumulative_indices () const
 
std::vector< size_t > get_counts (const Node &node) const
 
std::vector< size_t > get_counts (const std::vector< T > &v) const
 Compute a vector of counts of how often each rule was used, in a standard order given by iterating over nts and then iterating over rules. More...
 
std::vector< size_t > get_counts (const std::map< K, T > &v) const
 
double log_probability (const Node &n) const
 
Node from_parseable (std::deque< std::string > &q) const
 
Node from_parseable (std::string s) const
 
Node from_parseable (const char *c) const
 
size_t neighbors (const Node &node) const
 
void expand_to_neighbor (Node &node, int &which)
 
double neighbor_prior (const Node &node, int &which) const
 
void complete (Node &node)
 
std::tuple< int, std::vector< int >, int > find_open_commas_close (const std::string s)
 
Node simple_parse (std::string s)
 Very simple parsing routine that takes a string like "and(not(or(eq_pos(pos(parent(x)),'NP-POSS'),eq_pos('NP-S',pos(x)))),corefers(x))" (from the Binding example) and parses it into a Node. More...
 

Additional Inherited Members

- Public Types inherited from Grammar< MyObject, bool, MyObject, bool >
using input_t = MyObject
 
using output_t = bool
 
using this_t = Grammar< input_t, output_t, GRAMMAR_TYPES... >
 
using TypeTuple = std::tuple< GRAMMAR_TYPES... >
 
using VirtualMachineState_t = VirtualMachineState< input_t, output_t, GRAMMAR_TYPES... >
 
using FT = typename VirtualMachineState_t::FT
 
- Public Types inherited from Grammar< S, S, S, char, bool >
using input_t = S
 
using output_t = S
 
using this_t = Grammar< input_t, output_t, GRAMMAR_TYPES... >
 
using TypeTuple = std::tuple< GRAMMAR_TYPES... >
 
using VirtualMachineState_t = VirtualMachineState< input_t, output_t, GRAMMAR_TYPES... >
 
using FT = typename VirtualMachineState_t::FT
 
- Public Types inherited from Grammar< MyInput, bool, bool, MyObject, MyInput, ObjectSet, ObjectToBool, ObjectxObjectToBool >
using input_t = MyInput
 
using output_t = bool
 
using this_t = Grammar< input_t, output_t, GRAMMAR_TYPES... >
 
using TypeTuple = std::tuple< GRAMMAR_TYPES... >
 
using VirtualMachineState_t = VirtualMachineState< input_t, output_t, GRAMMAR_TYPES... >
 
using FT = typename VirtualMachineState_t::FT
 
- Static Public Member Functions inherited from Grammar< MyObject, bool, MyObject, bool >
static constexpr nonterminal_t nt ()
 
static constexpr bool is_in_GRAMMAR_TYPES ()
 For a given nt, returns the number of finite trees that nt can expand to if its finite; 0 if its infinite. *. More...
 
- Static Public Member Functions inherited from Grammar< S, S, S, char, bool >
static constexpr nonterminal_t nt ()
 
static constexpr bool is_in_GRAMMAR_TYPES ()
 For a given nt, returns the number of finite trees that nt can expand to if its finite; 0 if its infinite. *. More...
 
- Static Public Member Functions inherited from Grammar< MyInput, bool, bool, MyObject, MyInput, ObjectSet, ObjectToBool, ObjectxObjectToBool >
static constexpr nonterminal_t nt ()
 
static constexpr bool is_in_GRAMMAR_TYPES ()
 For a given nt, returns the number of finite trees that nt can expand to if its finite; 0 if its infinite. *. More...
 
- Public Attributes inherited from Grammar< MyObject, bool, MyObject, bool >
std::vector< Rulerules [N_NTs]
 
std::array< double, N_NTsZ
 
size_t GRAMMAR_MAX_DEPTH
 
- Public Attributes inherited from Grammar< S, S, S, char, bool >
std::vector< Rulerules [N_NTs]
 
std::array< double, N_NTsZ
 
size_t GRAMMAR_MAX_DEPTH
 
- Public Attributes inherited from Grammar< MyInput, bool, bool, MyObject, MyInput, ObjectSet, ObjectToBool, ObjectxObjectToBool >
std::vector< Rulerules [N_NTs]
 
std::array< double, N_NTsZ
 
size_t GRAMMAR_MAX_DEPTH
 
- Static Public Attributes inherited from Grammar< MyObject, bool, MyObject, bool >
static constexpr size_t N_NTs
 
- Static Public Attributes inherited from Grammar< S, S, S, char, bool >
static constexpr size_t N_NTs
 
- Static Public Attributes inherited from Grammar< MyInput, bool, bool, MyObject, MyInput, ObjectSet, ObjectToBool, ObjectxObjectToBool >
static constexpr size_t N_NTs
 

Detailed Description

We need to define some structs to hold the object features
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
using S = std::string;
using MyObject = ShapeColorSizeObject;
// Define a set of objects -- really it's a multiset so we'll use a vector
using ObjectSet = std::vector<MyObject>;
// Declare function types
using ObjectToBool = std::function<bool(MyObject)>;
using ObjectxObjectToBool = std::function<bool(MyObject,MyObject)> ;
// The arguments to a hypothesis will be a pair of a set and an object (as in Piantadosi, Tenenbaum, Goodman 2016)
using MyInput = std::tuple<MyObject,ObjectSet>; // this is the type of arguments we give to our function
/*

Define the grammar Thid requires the types of the thing we will add to the grammar (bool,Object) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Set up some basic variables (which may get overwritten)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
S alphabet = "01"; // the alphabet we use (possibly specified on command line)
thread_local S datastr = "01,01001,010010001,01001000100001"; // the data, comma separated -- this data should be able to get a posterior of -34.9
const float strgamma = 0.01; //75; // penalty on string length
const size_t MAX_LENGTH = 64; // longest strings cons will handle
/*

Declare a grammar This requires a template to specify what types they are (and what order they are stored in) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

We need to define some structs to hold the MyObject features
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
// This is a default object with three dimensions (shape, color, size) and three values for each
using MyObject = ShapeColorSizeObject;
/*

Define the grammar Thid requires the types of the thing we will add to the grammar (bool,MyObject) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Constructor & Destructor Documentation

◆ MyGrammar() [1/3]

MyGrammar::MyGrammar ( )
inline

◆ MyGrammar() [2/3]

MyGrammar::MyGrammar ( )
inline

◆ MyGrammar() [3/3]

MyGrammar::MyGrammar ( )
inline

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