18 CachedCallHypothesis::operator=(c);
23 CachedCallHypothesis::operator=(c);
58 if(
cache.size() == 0) {
return 1.0; }
61 for(
auto& v :
cache) {
66 return 1.0 / (0.1 + double(numtrue) / cache.size());
81 class MyHypothesis :
public Lexicon<MyHypothesis, std::string, InnerHypothesis, ignore_t,ignore_t, Utterance> {
88 for(
auto& [k,f] : factors) {
97 for(
auto& [k,f] : factors)
98 f.program.loader =
this;
101 for(
auto& [k,f] : factors) {
109 std::map<key_t,double> weights;
111 for(
auto& [k, f] : factors) {
112 weights[k] = f.get_weight_fromcache();
118 for(
size_t i=0;i<data.size();i++) {
123 bool wpresup =
false;
128 for(
auto& [k,f] : factors) {
131 auto tv = f.cache.at(i);
140 if(utterance.
word == k) {
149 double w = weights.at(utterance.
word);
150 double p = (wtrue and wpresup ? alpha_p*alpha_t*w/Wpt : 0) +
151 (wpresup ? alpha_p*(1-alpha_t)*w/Wp : 0) +
159 virtual std::string
string(std::string prefix=
"")
const override {
162 std::string out = prefix;
163 for(
auto& [k,f] : factors) {
166 bool conservative =
true;
168 for(
size_t i=0;i<
PRDATA;i++) {
172 auto to = target.
at(k).
call(di);
176 auto conservative_di = di;
177 conservative_di.color =
DSL::intersection(conservative_di.shape, conservative_di.color);
180 conservative =
false;
185 f.get_weight_fromcache(),
189 QQ(f.string())) +
"\n";
191 assert(out.size() > 0);
192 out.erase(out.size()-1);
197 virtual void show(std::string prefix=
"")
override {
207 print(this->
string());
Node & get_value()
Definition: LOTHypothesis.h:161
A lexicon stores an association of numbers (in a vector) to some other kind of hypotheses (typically ...
std::optional< std::pair< Node, double > > sample_function_leaving_args(GrammarType *grammar, const Node &from)
This samples functions f(a,b) -> g(a,b) (e.g. without destroying what's below). This uses a little tr...
Definition: Proposers.h:331
std::string QQ(const std::string &x)
Definition: Strings.h:190
double likelihood
Definition: Bayesable.h:43
void set_value(Node &v)
Definition: MyHypothesis.h:27
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
Compute the prior – defaultly just the PCFG (grammar) prior.
Definition: MyHypothesis.h:36
void set_value(Node &v, bool should_compile=true)
Set the value to v. (NOTE: This compiles into a program)
Definition: LOTHypothesis.h:168
TruthValue
Definition: Main.cpp:32
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...
Definition: MyHypothesis.h:94
Node value
Definition: LOTHypothesis.h:72
DeterministicLOTHypothesis< InnerHypothesis, BindingTree *, bool, MyGrammar,&grammar > Super
Definition: InnerHypothesis.h:14
MyHypothesis bunny_spread
Definition: Main.cpp:56
Definition: InnerHypothesis.h:9
double prior
Definition: Bayesable.h:42
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...
Definition: DeterministicLOTHypothesis.h:32
const int PRDATA
Definition: Main.cpp:27
InnerHypothesis & operator=(const InnerHypothesis &c)
Definition: MyHypothesis.h:16
bool flip(float p=0.5)
Definition: Random.h:25
void clear_cache()
Definition: MyHypothesis.h:87
std::string str(BindingTree *t)
Definition: BindingTree.h:195
double posterior
Definition: Bayesable.h:44
virtual ProposalType propose() const override
Default proposal is rational-rules style regeneration.
Definition: MyHypothesis.h:40
Definition: CachedCallHypothesis.h:14
we don't need inputs/outputs for out MyHypothesis
Definition: MyHypothesis.h:6
virtual void show(std::string prefix="") override
Definition: MyHypothesis.h:197
const auto intersection
Definition: DSL.h:32
void print(FIRST f, ARGS... args)
Lock output_lock and print to std:cout.
Definition: IO.h:53
std::optional< std::pair< Node, double > > delete_tree(GrammarType *grammar, const Node &from)
Definition: Proposers.h:275
void set_value(Node &&v)
Definition: MyHypothesis.h:31
void clear_cache()
Definition: CachedCallHypothesis.h:23
constexpr double infinity
Definition: Numerics.h:20
Definition: DeterministicLOTHypothesis.h:14
MyHypothesis classical_spread
Definition: Main.cpp:57
MyHypothesis::data_t prdata
Definition: Main.cpp:42
virtual TruthValue cached_call_wrapper(const Utterance &di) override
This is how we access the data before calling – needed to say how this interfaces with the data...
Definition: MyHypothesis.h:70
InnerHypothesis & operator=(const InnerHypothesis &&c)
Definition: MyHypothesis.h:21
Definition: MyHypothesis.h:80
std::optional< std::pair< Node, double > > regenerate(GrammarType *grammar, const Node &from)
A little helper function that resamples everything below when we can. If we can't, then we'll recurse.
Definition: Proposers.h:107
MyHypothesis target
Definition: Main.cpp:55
double get_weight_fromcache() const
This computes the weight of this factor from its cached values.
Definition: MyHypothesis.h:57
virtual std::string string(std::string prefix="") const override
Definition: MyHypothesis.h:159
std::optional< std::pair< InnerHypothesis, double > > ProposalType
Definition: LOTHypothesis.h:55
InnerHypothesis(const InnerHypothesis &&c)
Definition: MyHypothesis.h:14
This is a hypothesis that allows you to cache an entire call on data. NOTE: This only catches std::ex...
LOTHypothesis & operator=(const LOTHypothesis &c)
Definition: LOTHypothesis.h:100
InnerHypothesis(const InnerHypothesis &c)
Definition: MyHypothesis.h:13
std::optional< std::pair< Node, double > > insert_tree(GrammarType *grammar, const Node &from)
Definition: Proposers.h:192
virtual double compute_prior() override
Compute the prior – defaultly just the PCFG (grammar) prior.
Definition: LOTHypothesis.h:185
const double MAX_NODES
Definition: InnerHypothesis.h:20
std::string word
Definition: Main.cpp:44
std::vector< Args... > data_t
Definition: Bayesable.h:39
std::optional< std::pair< Node, double > > swap_args(GrammarType *grammar, const Node &from)
This propose swaps around arguments of the same type.
Definition: Proposers.h:389
virtual size_t count() const
How many nodes total are below me?
Definition: BaseNode.h:358
INNER & at(const key_t &k)
Definition: Lexicon.h:60
Definition: LRUCache.h:19