![]() |
Fleet
0.0.9
Inference in the LOT
|
#include <BaseGrammarHypothesis.h>
Public Types | |
using | HYP = _HYP |
using | Predict_t = _Predict_t |
using | LL_t = std::unordered_map< typename datum_t::data_t *, std::vector< Vector > > |
![]() | |
typedef Args... | datum_t |
typedef std::vector< Args... > | data_t |
Public Member Functions | |
BaseGrammarHypothesis () | |
BaseGrammarHypothesis (std::vector< HYP > &hypotheses, const data_t *human_data) | |
void | set_decay (const ExponentialVariable &ev) |
void | set_decay_untransformed (double v) |
void | set_alpha (const UniformVariable &a) |
void | set_alpha_untransformed (double v) |
void | copy_parameters (const BaseGrammarHypothesis &h) |
float | get_alpha () const |
float | get_decay () const |
size_t | ndata () const |
virtual void | set_hypotheses_and_data (std::vector< HYP > &hypotheses, const data_t &human_data) |
This is the primary function for setting hypothese and data on construction. More... | |
virtual void | set_can_propose (size_t i, bool b) |
Set whether I can propose to a value in logA – this is handled by VectorNormalHypothesis Here, though, we warn if the value is not 1.0. More... | |
void | set_flat_prior (bool fp) |
virtual size_t | nhypotheses () const |
A convenient function that uses C to say how many hypotheses. More... | |
virtual void | recompute_C (const std::vector< HYP > &hypotheses) |
Computes our matrix C[h,r] of hypotheses (rows) by counts of each grammar rule. (requires that each hypothesis use the same grammar) More... | |
virtual void | recompute_LL (std::vector< HYP > &hypotheses, const data_t &human_data) |
Recompute LL[h,di] a hypothesis from each hypothesis and data point to a vector of prior responses. (We need the vector instead of just the sum to implement memory decay. More... | |
virtual void | recompute_decayedLikelihood (const data_t &human_data) |
Recomputes the decayed likelihood (e.g. at the given decay level, the total ll for each data point. NOTE: This does create a new decayed likelihood each time we compute. More... | |
virtual void | recompute_P (std::vector< HYP > &hypotheses, const data_t &human_data)=0 |
Recompute the predictions for the hypotheses and data. More... | |
virtual std::map< typename HYP::output_t, double > | compute_model_predictions (const data_t &human_data, const size_t i, const Matrix &hposterior) const =0 |
This uses hposterior (computed via this->compute_normalized_posterior()) to compute the model predictions on a the i'th human data point. To do this, we marginalize over hypotheses, computing the weighted sum of outputs. More... | |
virtual const HYP & | computeMAP (const size_t di, const Matrix &hposterior) const |
virtual double | human_chance_lp (const typename datum_t::output_t &r, const datum_t &hd) const |
Get the chance probability of response r in hd (i.e. of a human response). This may typically be pretty boring (like just hd.chance) but w we need to be able to overwrite it. More... | |
virtual double | compute_prior () override |
virtual Matrix | compute_normalized_posterior () const |
This returns a matrix hposterior[h,di] giving the posterior on the h'th element. NOTE: not output is NOT logged. More... | |
virtual double | compute_likelihood (const data_t &human_data, const double breakout=-infinity) override |
This computes the likelihood of the human data. More... | |
virtual this_t | restart () const override |
virtual std::optional< std::pair< this_t, double > > | propose () const override |
Propose to the hypothesis. The sometimes does grammar parameters and sometimes other parameters, which are all stored as VectorHypotheses. It is sure to call the recompute functions when necessary. More... | |
virtual Vector | hypothesis_prior () const |
Compute a vector of the prior (one for each hypothesis) using the given counts matrix (hypotheses x rules), AT the specified temperature. More... | |
virtual bool | operator== (const this_t &h) const override |
virtual std::string | string (std::string prefix="") const override |
This returns a string for this hypothesis. Defaulty, now, just in tidy format with all the parameters, one on each row. Note these parameters are shown after transformation (e.g. the prior parameters are NOT logged) More... | |
virtual void | show (std::string prefix="") override |
Need to override print since it will print in a different format. More... | |
virtual size_t | hash () const override |
virtual std::string | serialize () const override |
![]() | |
MCMCable () | |
virtual bool | operator!= (const this_t &h) const |
![]() | |
Bayesable () | |
virtual double | compute_single_likelihood (const datum_t &datum) |
Compute the likelihood of a single data point. More... | |
virtual void | clear_bayes () |
virtual double | compute_tempered_likelihood (const data_t &data, int ladder_rank, const double breakout=-infinity) |
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 |
Static Public Member Functions | |
static this_t | sample (std::vector< HYP > &hypotheses, const data_t *human_data) |
static this_t | deserialize (const std::string &s) |
![]() | |
static this_t | sample () |
Static function for making a hypothesis. Be careful using this with references because they may not foward right (for reasons that are unclear to me) More... | |
![]() | |
static this_t | deserialize (const std::string &) |
Public Attributes | |
HYP::Grammar_t * | grammar |
bool | flat_prior |
VectorHalfNormalHypothesis | logA |
std::shared_ptr< Matrix > | C |
std::shared_ptr< LL_t > | LL |
std::shared_ptr< Predict_t > | P |
std::shared_ptr< Matrix > | decayedLikelihood |
const data_t * | which_data |
std::vector< HYP > * | which_hypotheses |
![]() | |
double | prior |
double | likelihood |
double | posterior |
uintmax_t | born |
size_t | born_chain_idx |
Protected Attributes | |
UniformVariable | alpha |
ExponentialVariable | decay |
using BaseGrammarHypothesis< this_t, _HYP, datum_t, data_t, _Predict_t >::HYP = _HYP |
using BaseGrammarHypothesis< this_t, _HYP, datum_t, data_t, _Predict_t >::LL_t = std::unordered_map<typename datum_t::data_t*, std::vector<Vector> > |
using BaseGrammarHypothesis< this_t, _HYP, datum_t, data_t, _Predict_t >::Predict_t = _Predict_t |
|
inline |
|
inline |
|
inlineoverridevirtual |
This computes the likelihood of the human data.
data | |
breakout |
Reimplemented from Bayesable< Args... >.
|
pure virtual |
This uses hposterior (computed via this->compute_normalized_posterior()) to compute the model predictions on a the i'th human data point. To do this, we marginalize over hypotheses, computing the weighted sum of outputs.
hd | |
hposterior |
Implemented in ThunkGrammarHypothesis< this_t, _HYP, datum_t, data_t, _Predict_t >, ThunkGrammarHypothesis< MyGrammarHypothesis, MyHypothesis, MyHumanDatum, std::vector< MyHumanDatum >, Vector2D< DiscreteDistribution< S > > >, FullGrammarHypothesis< this_t, _HYP, datum_t, data_t, _Predict_t >, DeterministicGrammarHypothesis< this_t, _HYP, datum_t, data_t, _Predict_t >, DeterministicGrammarHypothesis< MyGrammarHypothesis, MyHypothesis, MyHumanDatum >, and DeterministicGrammarHypothesis< MyGrammarHypothesis, MyHypothesis >.
|
inlinevirtual |
This returns a matrix hposterior[h,di] giving the posterior on the h'th element. NOTE: not output is NOT logged.
|
inlineoverridevirtual |
Implements Bayesable< Args... >.
|
inlinevirtual |
|
inline |
|
inlinestatic |
|
inline |
|
inline |
|
inlineoverridevirtual |
Implements Bayesable< Args... >.
|
inlinevirtual |
Get the chance probability of response r in hd (i.e. of a human response). This may typically be pretty boring (like just hd.chance) but w we need to be able to overwrite it.
hd |
|
inlinevirtual |
Compute a vector of the prior (one for each hypothesis) using the given counts matrix (hypotheses x rules), AT the specified temperature.
|
inline |
|
inlinevirtual |
A convenient function that uses C to say how many hypotheses.
|
inlineoverridevirtual |
Implements MCMCable< this_t, datum_t, data_t >.
|
inlineoverridevirtual |
Propose to the hypothesis. The sometimes does grammar parameters and sometimes other parameters, which are all stored as VectorHypotheses. It is sure to call the recompute functions when necessary.
data | |
breakout |
Implements MCMCable< this_t, datum_t, data_t >.
|
inlinevirtual |
Computes our matrix C[h,r] of hypotheses (rows) by counts of each grammar rule. (requires that each hypothesis use the same grammar)
hypotheses |
|
inlinevirtual |
Recomputes the decayed likelihood (e.g. at the given decay level, the total ll for each data point. NOTE: This does create a new decayed likelihood each time we compute.
hypotheses | |
human_data |
|
inlinevirtual |
Recompute LL[h,di] a hypothesis from each hypothesis and data point to a vector of prior responses. (We need the vector instead of just the sum to implement memory decay.
hypotheses | |
human_data |
Reimplemented in ThunkGrammarHypothesis< this_t, _HYP, datum_t, data_t, _Predict_t >, and ThunkGrammarHypothesis< MyGrammarHypothesis, MyHypothesis, MyHumanDatum, std::vector< MyHumanDatum >, Vector2D< DiscreteDistribution< S > > >.
|
pure virtual |
Recompute the predictions for the hypotheses and data.
hypotheses | |
human_data |
Implemented in ThunkGrammarHypothesis< this_t, _HYP, datum_t, data_t, _Predict_t >, ThunkGrammarHypothesis< MyGrammarHypothesis, MyHypothesis, MyHumanDatum, std::vector< MyHumanDatum >, Vector2D< DiscreteDistribution< S > > >, FullGrammarHypothesis< this_t, _HYP, datum_t, data_t, _Predict_t >, DeterministicGrammarHypothesis< this_t, _HYP, datum_t, data_t, _Predict_t >, DeterministicGrammarHypothesis< MyGrammarHypothesis, MyHypothesis, MyHumanDatum >, and DeterministicGrammarHypothesis< MyGrammarHypothesis, MyHypothesis >.
|
inlineoverridevirtual |
Implements MCMCable< this_t, datum_t, data_t >.
|
inlinestatic |
|
inlineoverridevirtual |
Implements Serializable< this_t >.
|
inline |
|
inline |
|
inlinevirtual |
Set whether I can propose to a value in logA – this is handled by VectorNormalHypothesis Here, though, we warn if the value is not 1.0.
i | |
b |
|
inline |
|
inline |
|
inline |
|
inlinevirtual |
This is the primary function for setting hypothese and data on construction.
hypotheses | |
human_data |
|
inlineoverridevirtual |
Need to override print since it will print in a different format.
Reimplemented from Bayesable< Args... >.
|
inlineoverridevirtual |
This returns a string for this hypothesis. Defaulty, now, just in tidy format with all the parameters, one on each row. Note these parameters are shown after transformation (e.g. the prior parameters are NOT logged)
Implements Bayesable< Args... >.
|
protected |
std::shared_ptr<Matrix> BaseGrammarHypothesis< this_t, _HYP, datum_t, data_t, _Predict_t >::C |
|
protected |
std::shared_ptr<Matrix> BaseGrammarHypothesis< this_t, _HYP, datum_t, data_t, _Predict_t >::decayedLikelihood |
bool BaseGrammarHypothesis< this_t, _HYP, datum_t, data_t, _Predict_t >::flat_prior |
HYP::Grammar_t* BaseGrammarHypothesis< this_t, _HYP, datum_t, data_t, _Predict_t >::grammar |
std::shared_ptr<LL_t> BaseGrammarHypothesis< this_t, _HYP, datum_t, data_t, _Predict_t >::LL |
VectorHalfNormalHypothesis BaseGrammarHypothesis< this_t, _HYP, datum_t, data_t, _Predict_t >::logA |
std::shared_ptr<Predict_t> BaseGrammarHypothesis< this_t, _HYP, datum_t, data_t, _Predict_t >::P |
const data_t* BaseGrammarHypothesis< this_t, _HYP, datum_t, data_t, _Predict_t >::which_data |
std::vector<HYP>* BaseGrammarHypothesis< this_t, _HYP, datum_t, data_t, _Predict_t >::which_hypotheses |