def gen_pdf(self, state): dist_x20001 = dist.Normal(mu=0, sigma=1.0) x20001 = state['x20001'] p10000 = dist_x20001.log_pdf(x20001) f20004 = -x20001 cond_20003 = state['cond_20003'] dist_y20005 = dist.Normal(mu=1, sigma=1.0) p10001 = dist_y20005.log_pdf(1) if not cond_20003 else 0 dist_y20006 = dist.Normal(mu=-1, sigma=1.0) p10002 = dist_y20006.log_pdf(1) if cond_20003 else 0 logp = p10000 + p10001 + p10002 return logp
def gen_prior_samples(self): dist_x20001 = dist.Normal(mu=1.0, sigma=2.23606797749979) x20001 = dist_x20001.sample() dist_x20002 = dist.Normal(mu=1.0, sigma=2.23606797749979) x20002 = dist_x20002.sample() dist_y20003 = dist.Normal(mu=x20001, sigma=1.4142135623730951) y20003 = 7.0 dist_y20004 = dist.Normal(mu=x20002, sigma=1.4142135623730951) y20004 = 7.0 state = {} for _gv in self.gen_vars(): state[_gv] = locals()[_gv] return state # dictionary
def gen_pdf(self, state): dist_x20001 = dist.Normal(mu=1.0, sigma=2.23606797749979) x20001 = state['x20001'] p10000 = dist_x20001.log_pdf(x20001) dist_x20002 = dist.Normal(mu=1.0, sigma=2.23606797749979) x20002 = state['x20002'] p10001 = dist_x20002.log_pdf(x20002) dist_y20003 = dist.Normal(mu=x20001, sigma=1.4142135623730951) p10002 = dist_y20003.log_pdf(7.0) dist_y20004 = dist.Normal(mu=x20002, sigma=1.4142135623730951) p10003 = dist_y20004.log_pdf(7.0) logp = p10000 + p10001 + p10002 + p10003 return logp
def gen_prior_samples(self): dist_x20001 = dist.Normal(mu=0, sigma=1.0) x20001 = dist_x20001.sample() f20004 = -x20001 cond_20003 = (f20004 >= 0).data[0] dist_y20005 = dist.Normal(mu=1, sigma=1.0) y20005 = 1 dist_y20006 = dist.Normal(mu=-1, sigma=1.0) y20006 = 1 c20002 = y20005 if not cond_20003 else y20006 state = {} for _gv in self.gen_all_keys(): state[_gv] = locals()[_gv] return state # dictionary
def gen_pdf(self, state): dist_x20001 = dist.Normal(mu=0, sigma=1.0) x20001 = state['x20001'] p10000 = dist_x20001.log_pdf(x20001) f20004 = -x20001 # The line below has been added as cond_ was not previously updating cond_20003 = (f20004 >= 0).data[0] # cond_20003 = state['cond_20003'] dist_y20005 = dist.Normal(mu=1, sigma=1.0) p10001 = dist_y20005.log_pdf(1) if not cond_20003 else 0 dist_y20006 = dist.Normal(mu=-1, sigma=1.0) p10002 = dist_y20006.log_pdf(1) if cond_20003 else 0 logp = p10000 + p10001 + p10002 # this has changed for key in state: if key in locals(): state[key] = locals()[key] return logp
def gen_prior_samples(self): dist_x20001 = dist.Normal(mu=0, sigma=1.0) x20001 = dist_x20001.sample() f20004 = -x20001 cond_20003 = (f20004 >= 0).data[0] dist_x20005 = dist.Normal(mu=0, sigma=1.0) x20005 = dist_x20005.sample() dist_x20007 = dist.Normal(mu=0, sigma=1.0) x20007 = dist_x20007.sample() dist_y20006 = dist.Normal(mu=x20005, sigma=1.4142135623730951) y20006 = 10 dist_y20008 = dist.Normal(mu=x20007, sigma=1.4142135623730951) y20008 = 10 c20002 = y20006 if not cond_20003 else y20008 state = {} for _gv in self.gen_all_keys(): state[_gv] = locals()[_gv] return state # dictionary
def gen_pdf(self, state): dist_x20001 = dist.Normal(mu=0, sigma=1.0) x20001 = state['x20001'] p10000 = dist_x20001.log_pdf(x20001) f20004 = -x20001 cond_20003 = (f20004 >= 0).data[0] dist_x20005 = dist.Normal(mu=0, sigma=1.0) x20005 = state['x20005'] p10001 = dist_x20005.log_pdf(x20005) dist_x20007 = dist.Normal(mu=0, sigma=1.0) x20007 = state['x20007'] p10002 = dist_x20007.log_pdf(x20007) dist_y20006 = dist.Normal(mu=x20005, sigma=1.4142135623730951) p10003 = dist_y20006.log_pdf(10) if not cond_20003 else 0 dist_y20008 = dist.Normal(mu=x20007, sigma=1.4142135623730951) p10004 = dist_y20008.log_pdf(10) if cond_20003 else 0 _lcls = locals() for key in state: if key in _lcls: state[key] = _lcls[key] logp = p10000 + p10001 + p10002 + p10003 + p10004 return logp
def test_pce(): print('\n================ Test 1 ====================\n') marginals = distr.Marginals([distr.Uniform(), distr.Normal()]) #basis_truncation = {'total_degree':1, 'q_norm':1.0} basis_truncation = {'max_degree': 1} model = PCE(marginals, basis_truncation) print(model) model.info() print('\n') print(dir(PCE)) print('\n') #print(model._multiIndices) X = np.array([[1, 2], [3, 7], [9, 10], [10, 12], [14, 19]]) Y = np.array([[1, 3, 2, 5, 7]]).T model.fit(X, Y) model.fit(X, Y, method='projection') predicted_Y = model.predict(X) model.info() print('\n') print(model) print('predicted_Y =', predicted_Y) marginals = distr.Marginals([distr.Uniform(a=2, b=10)]) basis_truncation = {'max_degree': 1} model = PCE(marginals, basis_truncation) X = np.array([[1], [7], [10], [12], [19]]) Y = np.array([[1, 3, 2, 5, 7]]).T model.fit(X, Y) model.info() err = model.validate(X, Y) print(err) print('\n============================================\n')