Fleet  0.0.9
Inference in the LOT
MyHypothesis.h
Go to the documentation of this file.
1 #pragma once
2 
4 #include "Combinators.h"
5 
13 class InnerHypothesis final : public DeterministicLOTHypothesis<InnerHypothesis,CL,CL,Combinators::SKGrammar,&Combinators::skgrammar> {
14 public:
16  using Super::Super; // inherit constructors
17 
18  InnerHypothesis(std::string s) {
20  this->set_value(std::move(n), false);
21  }
22 };
23 
24 
25 #include "Lexicon.h"
26 
34 class MyHypothesis final : public Lexicon<MyHypothesis, S, InnerHypothesis, CL, CL, CLDatum> {
35 public:
36 
38  using Super::Super;
39 
40  virtual double compute_prior() override {
41 
42  // enforce uniqueness among the symbols
43  std::vector<SExpression::SExpNode> seen;
44  for(auto& x : symbols) {
46 
47  try{
50  return prior = -infinity;
51  }
52 
53  if(std::find(seen.begin(), seen.end(), xn) != seen.end()) {// see if we have it
54  return prior = -infinity;
55  }
56  else {
57  seen.push_back(xn);
58  }
59  }
60 
61  return Super::compute_prior();
62  }
63 
64  double compute_likelihood(const data_t& data, const double breakout=-infinity) override {
65 
66  //print(string());
67 
68  likelihood = 0.0;
69  for(const auto& d : data) {
70  SExpression::SExpNode lhs = d.lhs; // make a copy
71  SExpression::SExpNode rhs = d.rhs;
72 
73  try {
74  //print(lhs.string(), rhs.string());
75 
76  Combinators::substitute(lhs, *this);
77  Combinators::substitute(rhs, *this);
78  //print("\t", lhs.string(), rhs.string());
81  //print("\t", lhs.string(), rhs.string());
82  //print("\t", (lhs==rhs));
83  // check if they are right
84  if((lhs == rhs) != (d.equal == true)) {
85  //print("\t", d.lhs.string(), d.rhs.string());
87  }
89  likelihood -= LL_PENALTY; // penalty for exceptions
90  }
91  }
92 
93  //print(likelihood);
94 
95  return likelihood;
96 
97  }
98 
99 };
Definition: Combinators.h:75
A lexicon stores an association of numbers (in a vector) to some other kind of hypotheses (typically ...
double likelihood
Definition: Bayesable.h:43
SExpression::SExpNode NodeToSExpNode(const Node &n)
Definition: Combinators.h:164
void set_value(Node &v)
Definition: InnerHypothesis.h:39
Definition: Node.h:22
LOTHypothesis< InnerHypothesis, BindingTree *, bool, MyGrammar, grammar, defaultdatum_t< BindingTree *, bool >, std::vector< defaultdatum_t< BindingTree *, bool > >, typename MyGrammar ::VirtualMachineState_t > Super
Definition: DeterministicLOTHypothesis.h:17
virtual double compute_prior() override
Definition: MyHypothesis.h:40
Node SExpNodeToNode(const SExpression::SExpNode &n)
Definition: Combinators.h:181
void reduce(SExpression::SExpNode &n, int &remaining_calls)
Combinator reduction, assuming that n is a SExpNode.
Definition: Combinators.h:82
Definition: InnerHypothesis.h:9
double prior
Definition: Bayesable.h:42
A grammar for SK combinatory logic. NOTE: CustomOps must be defined here.
Definition: SExpression.h:20
void substitute(SExpression::SExpNode &n, const L &m)
Definition: Combinators.h:205
const double LL_PENALTY
Definition: Main.cpp:18
we don&#39;t need inputs/outputs for out MyHypothesis
Definition: MyHypothesis.h:6
constexpr double infinity
Definition: Numerics.h:20
Definition: DeterministicLOTHypothesis.h:14
std::vector< S > symbols
Definition: Main.cpp:15
SExpNode parse(std::vector< std::string > &tok)
Wrapper to parse to remove outer (...)
Definition: SExpression.h:172
Definition: Lexicon.h:27
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...
Definition: MyHypothesis.h:64
std::vector< Args... > data_t
Definition: Bayesable.h:39
InnerHypothesis(std::string s)
Definition: MyHypothesis.h:18