14 static constexpr
double regenerate_p = 0.7;
16 [[nodiscard]]
virtual std::optional<std::pair<InnerHypothesis,double>>
propose()
const override {
18 std::optional<std::pair<Node,double>> x;
25 if(not x) {
return {}; }
27 return std::make_pair(
InnerHypothesis(std::move(x.value().first)), x.value().second);
46 for(
auto& [k,f] : factors) {
47 f.program.loader =
this;
51 return factors[factors.size()-1].call(x, err);
61 const float log_A = log(
alphabet.size());
64 for(
const auto& a : data) {
66 for(
const auto& m : M.
values()) {
69 alp =
logplusexp(alp, m.second + p_delete_append<alpha,alpha>(m.first, a.output, log_A));
73 if(ll == -
infinity or ll < breakout) {
93 for(
auto& [k,f] : factors) {
94 if(not f.was_called) {
100 return likelihood = string_likelihood(M, data, breakout);
104 void show(std::string prefix=
"")
override {
108 extern std::pair<double,double>
mem_pr;
112 COUT "# "; o.show(PRINT_STRINGS);
COUT "\n";
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
const std::string errorstring
Definition: Main.cpp:36
OrderedLock output_lock
Definition: IO.h:31
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
size_t PREC_REC_N
Definition: Main.cpp:26
std::string S
Definition: Main.cpp:28
#define TAB
Definition: IO.h:19
virtual std::optional< std::pair< InnerHypothesis, double > > propose() const override
Default proposal is rational-rules style regeneration.
Definition: InnerHypothesis.h:60
virtual std::string serialize() const override
Convert this into a string which can be written to a file.
Definition: LOTHypothesis.h:328
Node value
Definition: LOTHypothesis.h:72
DeterministicLOTHypothesis< InnerHypothesis, BindingTree *, bool, MyGrammar,&grammar > Super
Definition: InnerHypothesis.h:14
Definition: InnerHypothesis.h:9
double prior
Definition: Bayesable.h:42
Definition: DiscreteDistribution.h:25
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
bool flip(float p=0.5)
Definition: Random.h:25
double posterior
Definition: Bayesable.h:44
uintmax_t born
Definition: Bayesable.h:47
we don't need inputs/outputs for out MyHypothesis
Definition: MyHypothesis.h:6
std::optional< std::pair< Node, double > > delete_tree(GrammarType *grammar, const Node &from)
Definition: Proposers.h:275
constexpr double infinity
Definition: Numerics.h:20
T logplusexp(const T a, const T b)
Definition: Numerics.h:131
virtual void show(std::string prefix="")
Definition: Bayesable.h:197
Bayesable< defaultdatum_t< BindingTree *, bool >, std::vector< defaultdatum_t< BindingTree *, bool > > >::datum_t datum_t
Definition: LOTHypothesis.h:47
MyHypothesis::data_t prdata
Definition: Main.cpp:42
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
std::pair< double, double > mem_pr
Definition: Main.cpp:45
InnerHypothesis(const InnerHypothesis &c)
Definition: InnerHypothesis.h:25
#define ENDL
Definition: IO.h:21
const std::string EMPTY_STRING
Definition: Strings.h:17
std::optional< std::pair< Node, double > > insert_tree(GrammarType *grammar, const Node &from)
Definition: Proposers.h:192
std::vector< Args... > data_t
Definition: Bayesable.h:39
Definition: StochasticLOTHypothesis.h:14
const std::map< T, double > & values() const
Definition: DiscreteDistribution.h:128
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 double compute_likelihood(const data_t &data, const double breakout=-infinity)
Compute the likelihood of a collection of data, by calling compute_single_likelihood on each...
Definition: Bayesable.h:83
#define COUT
Definition: IO.h:24
size_t current_ntokens
Definition: Main.cpp:34
Super::data_t data_t
Definition: InnerHypothesis.h:23
unsigned long PRINT_STRINGS
Definition: Main.cpp:29
S current_data
Definition: Main.cpp:43
S alphabet
Definition: Main.cpp:19
virtual double compute_single_likelihood(const datum_t &datum) override
Compute the likelihood of a single data point.
Definition: LOTHypothesis.h:195