26 double PROPOSAL_SCALE = 0.20;
42 void set(
int i,
double v) {
54 if(std::all_of(can_propose.begin(), can_propose.end(), [](
bool v) {
return not v; })) {
55 assert(
false &&
"*** Cannot set everything to no-propose or else Vector[Half]NormalHypothesis breaks! (loops infinitely on propose)");
61 value = Vector::Zero(n);
62 can_propose.resize(n,
true);
73 for(
auto i=0;i<value.size();i++) {
74 this->prior +=
normal_lpdf((
double)value(i), this->MEAN, this->SD);
85 virtual std::optional<std::pair<self_t,double>>
propose()
const override {
94 }
while(!can_propose.at(i));
100 return std::make_pair(out, 0.0);
105 for(
auto i=0;i<value.size();i++) {
113 virtual size_t hash()
const override {
114 if(value.size() == 0)
return 0;
116 size_t output = std::hash<double>{}(value(0));
117 for(
auto i=1;i<value.size();i++) {
118 hash_combine(output, std::hash<double>{}(value(i)));
124 return value.size() == h.
value.size() and value == h.
value;
127 virtual std::string
string(std::string prefix=
"")
const override {
128 std::string out = prefix+
"<";
129 for(
auto i=0;i<value.size();i++) {
130 out +=
str(value(i))+
",";
132 out.erase(out.size()-1);
T myrandom(T max)
Definition: Random.h:176
virtual std::string string(std::string prefix="") const override
Definition: VectorNormalHypothesis.h:127
virtual size_t hash() const override
Definition: VectorNormalHypothesis.h:113
size_t size() const
Definition: VectorNormalHypothesis.h:65
void set_can_propose(size_t i, bool b)
Set whether we can propose to each element of b or not.
Definition: VectorNormalHypothesis.h:50
virtual bool operator==(const self_t &h) const override
Definition: VectorNormalHypothesis.h:123
Definition: MCMCable.h:14
virtual self_t restart() const override
Definition: VectorNormalHypothesis.h:103
std::string str(BindingTree *t)
Definition: BindingTree.h:195
VectorNormalHypothesis()
Definition: VectorNormalHypothesis.h:34
double random_normal(double mu=0, double sd=1.0)
Definition: Random.h:39
constexpr double infinity
Definition: Numerics.h:20
Vector value
Definition: VectorNormalHypothesis.h:28
Definition: VectorNormalHypothesis.h:15
virtual std::optional< std::pair< self_t, double > > propose() const override
Definition: VectorNormalHypothesis.h:85
void set_size(size_t n)
Definition: VectorNormalHypothesis.h:60
std::vector< Args... > data_t
Definition: Bayesable.h:39
virtual 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: VectorNormalHypothesis.h:80
std::vector< bool > can_propose
Definition: VectorNormalHypothesis.h:32
double operator()(int i) const
Definition: VectorNormalHypothesis.h:37
VectorNormalHypothesis(int n)
Definition: VectorNormalHypothesis.h:35
A class is MCMCable if it is Bayesable and lets us propose, restart, and check equality (which MCMC d...
T normal_lpdf(T x, T mu=0.0, T sd=1.0)
Definition: Random.h:45
Eigen::VectorXf Vector
Definition: EigenLib.h:17
virtual double compute_prior() override
Definition: VectorNormalHypothesis.h:69