Fleet  0.0.9
Inference in the LOT
Public Types | Public Member Functions | List of all members
DeterministicGrammarHypothesis< this_t, _HYP, datum_t, data_t, _Predict_t > Class Template Reference

#include <DeterministicGrammarHypothesis.h>

Inheritance diagram for DeterministicGrammarHypothesis< this_t, _HYP, datum_t, data_t, _Predict_t >:
Inheritance graph
[legend]
Collaboration diagram for DeterministicGrammarHypothesis< this_t, _HYP, datum_t, data_t, _Predict_t >:
Collaboration graph
[legend]

Public Types

using HYP = _HYP
 
using Super = BaseGrammarHypothesis< this_t, _HYP, datum_t, data_t, _Predict_t >
 
using LL_t = Super::LL_t
 
using Predict_t = Super::Predict_t
 
- Public Types inherited from BaseGrammarHypothesis< this_t, _HYP, datum_t, data_t, _Predict_t >
using HYP = _HYP
 
using Predict_t = _Predict_t
 
using LL_t = std::unordered_map< typename datum_t::data_t *, std::vector< Vector > >
 
- Public Types inherited from Bayesable< Args... >
typedef Args... datum_t
 
typedef std::vector< Args... > data_t
 

Public Member Functions

 DeterministicGrammarHypothesis (std::vector< HYP > &hypotheses, const data_t *human_data)
 
virtual void recompute_P (std::vector< HYP > &hypotheses, const data_t &human_data) override
 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 override
 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...
 
- Public Member Functions inherited from BaseGrammarHypothesis< this_t, _HYP, datum_t, data_t, _Predict_t >
 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 const HYPcomputeMAP (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
 
- Public Member Functions inherited from MCMCable< this_t, datum_t, data_t >
 MCMCable ()
 
virtual bool operator!= (const this_t &h) const
 
- Public Member Functions inherited from Bayesable< Args... >
 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
 

Additional Inherited Members

- Static Public Member Functions inherited from BaseGrammarHypothesis< this_t, _HYP, datum_t, data_t, _Predict_t >
static this_t sample (std::vector< HYP > &hypotheses, const data_t *human_data)
 
static this_t deserialize (const std::string &s)
 
- Static Public Member Functions inherited from MCMCable< this_t, datum_t, data_t >
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 Public Member Functions inherited from Serializable< this_t >
static this_t deserialize (const std::string &)
 
- Public Attributes inherited from BaseGrammarHypothesis< this_t, _HYP, datum_t, data_t, _Predict_t >
HYP::Grammar_t * grammar
 
bool flat_prior
 
VectorHalfNormalHypothesis logA
 
std::shared_ptr< MatrixC
 
std::shared_ptr< LL_tLL
 
std::shared_ptr< Predict_tP
 
std::shared_ptr< MatrixdecayedLikelihood
 
const data_twhich_data
 
std::vector< HYP > * which_hypotheses
 
- Public Attributes inherited from Bayesable< Args... >
double prior
 
double likelihood
 
double posterior
 
uintmax_t born
 
size_t born_chain_idx
 
- Protected Attributes inherited from BaseGrammarHypothesis< this_t, _HYP, datum_t, data_t, _Predict_t >
UniformVariable alpha
 
ExponentialVariable decay
 

Detailed Description

template<typename this_t, typename _HYP, typename datum_t = HumanDatum<_HYP>, typename data_t = std::vector<datum_t>, typename _Predict_t = Vector2D<typename _HYP::output_t>>
class DeterministicGrammarHypothesis< this_t, _HYP, datum_t, data_t, _Predict_t >

Author
Steven Piantadosi
Date
02/05/22

Member Typedef Documentation

◆ HYP

template<typename this_t, typename _HYP, typename datum_t = HumanDatum<_HYP>, typename data_t = std::vector<datum_t>, typename _Predict_t = Vector2D<typename _HYP::output_t>>
using DeterministicGrammarHypothesis< this_t, _HYP, datum_t, data_t, _Predict_t >::HYP = _HYP

◆ LL_t

template<typename this_t, typename _HYP, typename datum_t = HumanDatum<_HYP>, typename data_t = std::vector<datum_t>, typename _Predict_t = Vector2D<typename _HYP::output_t>>
using DeterministicGrammarHypothesis< this_t, _HYP, datum_t, data_t, _Predict_t >::LL_t = Super::LL_t

◆ Predict_t

template<typename this_t, typename _HYP, typename datum_t = HumanDatum<_HYP>, typename data_t = std::vector<datum_t>, typename _Predict_t = Vector2D<typename _HYP::output_t>>
using DeterministicGrammarHypothesis< this_t, _HYP, datum_t, data_t, _Predict_t >::Predict_t = Super::Predict_t

◆ Super

template<typename this_t, typename _HYP, typename datum_t = HumanDatum<_HYP>, typename data_t = std::vector<datum_t>, typename _Predict_t = Vector2D<typename _HYP::output_t>>
using DeterministicGrammarHypothesis< this_t, _HYP, datum_t, data_t, _Predict_t >::Super = BaseGrammarHypothesis<this_t, _HYP, datum_t, data_t, _Predict_t>

Constructor & Destructor Documentation

◆ DeterministicGrammarHypothesis()

template<typename this_t, typename _HYP, typename datum_t = HumanDatum<_HYP>, typename data_t = std::vector<datum_t>, typename _Predict_t = Vector2D<typename _HYP::output_t>>
DeterministicGrammarHypothesis< this_t, _HYP, datum_t, data_t, _Predict_t >::DeterministicGrammarHypothesis ( std::vector< HYP > &  hypotheses,
const data_t human_data 
)
inline

Member Function Documentation

◆ compute_model_predictions()

template<typename this_t, typename _HYP, typename datum_t = HumanDatum<_HYP>, typename data_t = std::vector<datum_t>, typename _Predict_t = Vector2D<typename _HYP::output_t>>
virtual std::map<typename HYP::output_t, double> DeterministicGrammarHypothesis< this_t, _HYP, datum_t, data_t, _Predict_t >::compute_model_predictions ( const data_t human_data,
const size_t  i,
const Matrix hposterior 
) const
inlineoverridevirtual

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.

Parameters
hd
hposterior

Implements BaseGrammarHypothesis< this_t, _HYP, datum_t, data_t, _Predict_t >.

◆ recompute_P()

template<typename this_t, typename _HYP, typename datum_t = HumanDatum<_HYP>, typename data_t = std::vector<datum_t>, typename _Predict_t = Vector2D<typename _HYP::output_t>>
virtual void DeterministicGrammarHypothesis< this_t, _HYP, datum_t, data_t, _Predict_t >::recompute_P ( std::vector< HYP > &  hypotheses,
const data_t human_data 
)
inlineoverridevirtual

Recompute the predictions for the hypotheses and data.

Parameters
hypotheses
human_data
Returns

Implements BaseGrammarHypothesis< this_t, _HYP, datum_t, data_t, _Predict_t >.


The documentation for this class was generated from the following file: