|
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< word > | call (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...
|
|
virtual DiscreteDistribution< output_t > | call (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...
|
|
| LOTHypothesis () |
|
| LOTHypothesis (Node &x) |
|
| LOTHypothesis (Node &&x) |
|
| LOTHypothesis (std::string s) |
|
| LOTHypothesis (const LOTHypothesis &c) |
|
| LOTHypothesis (const LOTHypothesis &&c) |
|
LOTHypothesis & | operator= (const LOTHypothesis &c) |
|
LOTHypothesis & | operator= (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...
|
|
Node & | get_value () |
|
const Node & | get_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_t * | get_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...
|
|
| MCMCable () |
|
virtual bool | operator!= (const MyHypothesis &h) const |
|
| 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 |
|
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...
|
|
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) |
|
| Lexicon () |
|
size_t | nfactors () const |
| Return the number of factors. More...
|
|
auto & | get_value () |
|
const auto & | get_value () const |
|
InnerHypothesis & | at (const key_t &k) |
|
const InnerHypothesis & | at (const key_t &k) const |
|
InnerHypothesis & | operator[] (const key_t &k) |
|
const InnerHypothesis & | operator[] (const key_t &k) const |
|
bool | contains (const key_t &key) |
|
Grammar_t * | get_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_t > | call (const key_t k, const input_t x, const output_t &err=output_t{}) |
|
virtual std::string | serialize () const override |
|
| MCMCable () |
|
virtual bool | operator!= (const MyHypothesis &h) const |
|
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...
|
|
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) |
|
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...
|
|
| LOTHypothesis () |
|
| LOTHypothesis (Node &x) |
|
| LOTHypothesis (Node &&x) |
|
| LOTHypothesis (std::string s) |
|
| LOTHypothesis (const LOTHypothesis &c) |
|
| LOTHypothesis (const LOTHypothesis &&c) |
|
LOTHypothesis & | operator= (const LOTHypothesis &c) |
|
LOTHypothesis & | operator= (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...
|
|
Node & | get_value () |
|
const Node & | get_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_t * | get_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...
|
|
| MCMCable () |
|
virtual bool | operator!= (const MyHypothesis &h) const |
|
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...
|
|
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...
|
|
| LOTHypothesis () |
|
| LOTHypothesis (Node &x) |
|
| LOTHypothesis (Node &&x) |
|
| LOTHypothesis (std::string s) |
|
| LOTHypothesis (const LOTHypothesis &c) |
|
| LOTHypothesis (const LOTHypothesis &&c) |
|
LOTHypothesis & | operator= (const LOTHypothesis &c) |
|
LOTHypothesis & | operator= (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...
|
|
Node & | get_value () |
|
const Node & | get_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_t * | get_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...
|
|
| MCMCable () |
|
virtual bool | operator!= (const MyHypothesis &h) const |
|
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...
|
|
virtual DiscreteDistribution< output_t > | call (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...
|
|
| LOTHypothesis () |
|
| LOTHypothesis (Node &x) |
|
| LOTHypothesis (Node &&x) |
|
| LOTHypothesis (std::string s) |
|
| LOTHypothesis (const LOTHypothesis &c) |
|
| LOTHypothesis (const LOTHypothesis &&c) |
|
LOTHypothesis & | operator= (const LOTHypothesis &c) |
|
LOTHypothesis & | operator= (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...
|
|
Node & | get_value () |
|
const Node & | get_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_t * | get_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...
|
|
| MCMCable () |
|
virtual bool | operator!= (const MyHypothesis &h) const |
|
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...
|
|
| Lexicon () |
|
size_t | nfactors () const |
| Return the number of factors. More...
|
|
auto & | get_value () |
|
const auto & | get_value () const |
|
InnerHypothesis & | at (const key_t &k) |
|
const InnerHypothesis & | at (const key_t &k) const |
|
InnerHypothesis & | operator[] (const key_t &k) |
|
const InnerHypothesis & | operator[] (const key_t &k) const |
|
bool | contains (const key_t &key) |
|
Grammar_t * | get_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_t > | call (const key_t k, const input_t x, const output_t &err=output_t{}) |
|
virtual std::string | serialize () const override |
|
| MCMCable () |
|
virtual bool | operator!= (const MyHypothesis &h) const |
|
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...
|
|
| Lexicon () |
|
size_t | nfactors () const |
| Return the number of factors. More...
|
|
auto & | get_value () |
|
const auto & | get_value () const |
|
InnerHypothesis & | at (const key_t &k) |
|
const InnerHypothesis & | at (const key_t &k) const |
|
InnerHypothesis & | operator[] (const key_t &k) |
|
const InnerHypothesis & | operator[] (const key_t &k) const |
|
bool | contains (const key_t &key) |
|
Grammar_t * | get_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_t > | call (const key_t k, const input_t x, const output_t &err=output_t{}) |
|
virtual std::string | serialize () const override |
|
| MCMCable () |
|
virtual bool | operator!= (const MyHypothesis &h) const |
|
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...
|
|
we don't need inputs/outputs for out MyHypothesis
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
class MyGrammar :
public Grammar<utterance,word, bool,word,set,objectkind,utterance,wmset,magnitude,double>,
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; });
add("%s.set", +[](utterance u) -> set { return u.s; }, 10.0);
add("%s.obj", +[](utterance u) -> objectkind { return u.o; }, 10.0);
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)
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);
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);
if(pos != std::string::npos) {
out.erase(pos,1);
}
}
return out;
});
add("filter(%s,%s)", +[](set x, objectkind t) -> set {
std::string tstr = std::string(1,t);
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);
}
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; });
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 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
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; });
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) {
}
else {
for(size_t i=0;i<s.size();i++) {
if(s[i]) {
set out;
out[i] = true;
return out;
}
}
assert(false && "*** Should not get here");
}
});
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; });
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 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
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; });
add("range(%s,%s)", +[](int x, int y) -> NumberSet {
NumberSet out;
for(
int i=std::max(x,Nlow);i<=std::min(y,
N);i++) {
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;
});
add("pow(%s, %s)", +[](int n, NumberSet s) -> NumberSet {
NumberSet out;
for(auto& x : s) {
out.insert(std::pow(n,x));
}
return out;
});
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++) {
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