result = [] for i in range(t): # i = t - 1 g, rvs_table = kmf.grounded_graph(i + 1, data) bp = HybridLBP(g, n=50, proposal_approximation='simple') # bp = GaLBP(g) print('number of vr', len(g.rvs)) num_evidence = 0 for rv in g.rvs: if rv.value is not None: num_evidence += 1 print('number of evidence', num_evidence) start_time = time.time() bp.run(6, c2f=0, log_enable=False) print('time lapse', time.time() - start_time) # for i in range(t): temp = [] for idx, rv in enumerate(rvs_table[i]): temp.append([idx, bp.map(rv)]) result.append(temp) result = np.array(result) np.save('Data/well_t_prediction', result) for idx in range(result.shape[1]): y = [] for i in range(t):
from VarInference import VarInference as VI from LiftedVarInference import VarInference as LVI from C2FVarInference import VarInference as C2FVI from GaBP import GaBP from HybridMaxWalkSAT import HybridMaxWalkSAT as HMWS from HybridLBPLogVersion import HybridLBP rel_g = generate_rel_graph() rel_g.ground_graph() data = {('recession', 'all'): 25} g, rvs_dict = rel_g.add_evidence(data) infer = HybridLBP(g, n=10, proposal_approximation='simple') infer.run(10, c2f=0, log_enable=False) # infer = HMWS(g) # infer.run(max_tries=1, max_flips=10000, epsilon=0.0, noise_std=0.5) # infer = LVI(g, num_mixtures=1, num_quadrature_points=3) # infer.run(200, lr=0.2) # infer = GaBP(g) # infer.run(20) map_res = dict() for key, rv in rvs_dict.items(): map_res[rv] = infer.map(rv) print(key, map_res[rv])