def compute_prior(self): self.prior = GaussianLOTHypothesis.compute_prior(self) self.prior += sum( map(lambda x: normlogpdf(x, 0.0, CONSTANT_SD), self.CONSTANT_VALUES)) self.posterior_score = self.prior + self.likelihood return self.prior
def __call__(self, *vals): """ Must overwrite call in order to include the constants """ vals = list(vals) vals.extend(self.CONSTANT_VALUES) return GaussianLOTHypothesis.__call__(self, *vals)
def toMaximize(fit_params): self.CONSTANT_VALUES = fit_params.tolist() # set these # And return the original likelihood, which by get_function_responses above uses this constant_prior = sum( map(lambda x: normlogpdf(x, 0.0, CONSTANT_SD), self.CONSTANT_VALUES)) return -(GaussianLOTHypothesis.compute_likelihood(self, data) + constant_prior)
def run(*args): # starting hypothesis -- here this generates at random h0 = GaussianLOTHypothesis(grammar) # We store the top 100 from each run fs = FiniteBestSet(10, max=True, key="posterior_score") fs.add(mh_sample(h0, data, STEPS, skip=SKIP)) return fs
def run(*args): # starting hypothesis -- here this generates at random h0 = GaussianLOTHypothesis(grammar, prior_temperature=PRIOR_TEMPERATURE) # We store the top 100 from each run pq = FiniteBestSet(100, max=True, key="posterior_score") pq.add(mh_sample(h0, data, STEPS, skip=SKIP)) return pq
def to_maximize(fit_params): self.CONSTANT_VALUES = fit_params.tolist() # set these # And return the original likelihood, which by get_function_responses above uses this constant_prior = sum(map(lambda x: normlogpdf(x,0.0,CONSTANT_SD), self.CONSTANT_VALUES)) return -(GaussianLOTHypothesis.compute_likelihood(self, data) + constant_prior)
def compute_prior(self): self.prior = GaussianLOTHypothesis.compute_prior(self) self.prior += sum(map(lambda x: normlogpdf(x,0.0,CONSTANT_SD), self.CONSTANT_VALUES)) self.posterior_score = self.prior + self.likelihood return self.prior
def make_h0(value=None): return GaussianLOTHypothesis(grammar, value=value)