def sample_breaks(self, breaks): return nd_norm(breaks, 0.5 * np.eye(len(np.atleast_1d(breaks)))).rvs()
if x > breaks[len(breaks) - 1]: # bud je x vetsi nez posledni zlomovy bod bracket = y - (x * b[2 * len(breaks)] + b[2 * len(breaks) + 1]) else: # a nebo je mensi nez nejaky break for i in range(len(breaks)): if x < breaks[i]: # b1 a b0 jsou za sebou v beckach bracket = y - (x * b[2 * i] + b[2 * i + 1]) break lik *= sig**(-1 / 2) * np.exp(-bracket**2 / (2 * sig)) return lik priorb = lambda b: nd_norm([0, 1, 1, 1], np.array([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 3, 0], [0, 0, 0, 3]])).pdf(b) priorbreak = lambda s: st.norm(5, 2).pdf(s) priorsig = lambda s: st.uniform(0, 3).pdf(s) post = lambda b, sig, s: likelihood(xs, ys, b, sig, [s]) * priorb( b) * priorsig(sig) * priorbreak(s) cov = np.array([[0.5, 0, 0, 0], [0, 0.5, 0, 0], [0, 0, 0.5, 0], [0, 0, 0, 0.5]]) proposalb_sampler = lambda b: nd_norm([b[0], b[1], b[2], b[3]], cov).rvs() proposalb = lambda b1, b2: nd_norm([b1[0], b1[1], b1[2], b1[3]], cov).pdf( [b2[0], b2[1], b2[2], b2[3]]) proposalbreak_sampler = lambda s: nd_norm(s, 1).rvs() proposalbreak = lambda s1, s2: nd_norm(s1, 1).pdf(s2)
def sample_bs(self, bs): return nd_norm(bs, np.eye(len(bs)) * 0.5).rvs()
def sample_sigs(self, sig): return np.abs(nd_norm(sig, 1).rvs())
def prior_breaks(self, breaks): return nd_norm(5, np.eye(len(breaks)) * 0.5).pdf(breaks)
def prior_b(self, bs): return nd_norm(np.ones(len(bs)), np.eye(len(bs))).pdf(bs)
def sampler_probability_breaks(self, breaks1, breaks2): return nd_norm(breaks1, 0.5 * np.eye(len(breaks1))).pdf(breaks2)
def sampler_probability_sigs(self, sig1, sig2): return nd_norm(sig1, 1).pdf(sig2)
def sampler_probability_bs(self, bs1, bs2): return nd_norm(bs1, np.eye(len(bs1)) * 0.5).pdf(bs2)