def loglikelyhood_SI_relic(x): dest = DiffusionEstimator.default(echo=True) if x[0] < 1e-12 or x[1] < 1e-12: return 1e20 ll = dest.loglikelyhood(x[0], 0., 0., x[1]) #print(str(-ll) + ' ' + str(x)) return -ll
def llmax_for_diffusion_noconfirm_ensemble(theta0, decay0, relic0, observe_time=-1, disp=True, new_lib=False): dest = DiffusionEstimator.default(echo=disp) x0 = np.array([theta0, decay0, relic0]) if new_lib: res = minimize(loglikelyhood_noconfirm_ensemble, x0, args=(observe_time, ), method='nelder-mead', options={ 'xtol': 1e-11, 'disp': disp }) else: res = minimize(loglikelyhood_noconfirm_ensemble, x0, args=(observe_time, ), method='nelder-mead', options={ 'xtol': 1e-11, 'disp': disp }) return {'theta': res.x[0], 'decay': res.x[1], 'relic': res.x[2]}
def loglikelyhood_noconfirm_ensemble(x, observe_time=-1): dest = DiffusionEstimator.default(echo=True) if (x[0] < 1e-12 and x[2] < 1e-12) or x[1] < 0: return 1e20 ll = dest.loglikelyhood_ensemble(x[0], 0., x[1], x[2], observe_time) #print(str(-ll) + ' ' + str(x)) return -ll
def loglikelyhood(x): dest = DiffusionEstimator.default(echo=True) if x[0] < 1e-12 or x[3] < 1e-12 or x[2] < 0 or x[1] < -1. or x[1] > 1.: return 1e20 ll = dest.loglikelyhood(x[0], x[1], x[2], x[3]) print(str(-ll) + ' ' + str(x)) return -ll
def llfunc_for_diffusion(thetas, confirms, decays, relics): dest = DiffusionEstimator.default(echo=True) ps = np.zeros((len(thetas), len(confirms), len(decays), len(relics))) for i in range(len(thetas)): for j in range(len(confirms)): for k in range(len(decays)): for l in range(len(relics)): ps[i][j][k][l] = dest.loglikelyhood( thetas[i], confirms[j], decays[k], relics[l]) return ps
def loglikelyhood_noconfirm(x, observe_time=-1.): dest = DiffusionEstimator.default(echo=True) if x[0] < 1e-12 or x[2] < 1e-12 or x[1] < 0: return 1e20 start_time = time.time() ll = dest.loglikelyhood(x[0], 0., x[1], x[2], observe_time) end_time = time.time() print( str(-ll) + ' ' + str(x) + ' ex. time: ' + str(end_time - start_time)) return -ll
def llmax_for_diffusion_noconfirm_by_node_theta(node_id, theta, decay, relic, bounds, observe_time=0, disp=True): dest = DiffusionEstimator.default(echo=True) res = minimize_scalar(loglikelyhood_by_node_theta, bounds=bounds, method='bounded', args=(node_id, theta, decay, relic, observe_time)) return res.x
def llmax_for_diffusion_noconfirm_multiple_cases(thetas0, decay0, relics0, disp=True): dest = DiffusionEstimator.default(echo=disp) sx = thetas0 + relics0 + [decay0] x0 = np.array(sx) res = minimize(loglikelyhood_noconfirm_newlib_multiple_cases, x0, method='nelder-mead', options={ 'xtol': 1e-11, 'disp': disp }) return {'theta': res.x[0], 'decay': res.x[1], 'relic': res.x[2]}
def llmax_for_diffusion(theta0, confirm0, decay0, relic0): dest = DiffusionEstimator.default(echo=True) x0 = np.array([theta0, confirm0, decay0, relic0]) res = minimize(loglikelyhood, x0, method='nelder-mead', options={ 'xtol': 1e-11, 'disp': True }) return { 'theta': res.x[0], 'confirm': res.x[1], 'decay': res.x[2], 'relic': res.x[3] }
def llmax_for_diffusion_SI_relic(theta0, relic0, delta=.0, new_lib=False): dest = DiffusionEstimator.default(echo=True) x0 = np.array([theta0, relic0]) if new_lib: res = minimize(loglikelyhood_SI_relic_newlib, x0, args=(delta, ), method='nelder-mead', options={ 'xtol': 1e-11, 'disp': True }) else: res = minimize(loglikelyhood_SI_relic, x0, method='nelder-mead', options={ 'xtol': 1e-11, 'disp': True }) return {'theta': res.x[0], 'relic': res.x[1]}
def llmax_for_diffusion_ICM(theta0, relic0=.0): dest = DiffusionEstimator.default(echo=True) if relic0 == .0: x0 = np.array([theta0]) res = minimize(loglikelyhood_ICM_newlib, x0, method='nelder-mead', options={ 'xtol': 1e-11, 'disp': True }) return {'theta': res.x[0]} else: x0 = np.array([theta0, relic0]) res = minimize(loglikelyhood_ICM_newlib, x0, method='nelder-mead', options={ 'xtol': 1e-11, 'disp': True }) return {'theta': res.x[0], 'relic': res.x[1]}
def llmax_for_diffusion_SI_decay(theta0, delta0=.0, fixed_delta=False): dest = DiffusionEstimator.default(echo=True) if fixed_delta == True: x0 = np.array([theta0]) res = minimize(loglikelyhood_SI_decay_newlib, x0, method='nelder-mead', options={ 'xtol': 1e-11, 'disp': True }, args=(delta0, )) return {'theta': res.x[0]} else: x0 = np.array([theta0, delta0]) res = minimize(loglikelyhood_SI_decay_newlib, x0, method='nelder-mead', options={ 'xtol': 1e-11, 'disp': True }) return {'theta': res.x[0], 'decay': res.x[1]}
def set_diffusion_data_ensemble(netwf: str, outcomes, counters, echo=True): dest = DiffusionEstimator.default(echo=echo) dest.load_network_inf_ensemble(netwf, counters=counters, outcomes=outcomes)
def dlldthetas_noconfirm(theta, decay, relic, ids, observe_time=.0): dest = DiffusionEstimator.default(echo=True) dll = dest.thetas_derivatives(theta, .0, decay, relic, ids, observe_time) #print(str(dll) + ' ' + str(x)) return dll
def set_diffusion_data(netwf: str, outcome, counters, echo=True): dest = DiffusionEstimator.default(echo=echo) dest.load_network(netwf, counters=counters, outcome=outcome)
def loglikelyhood_by_node_theta(x, node_id, theta, decay, relic, observe_time): dest = DiffusionEstimator.default(echo=True) ll = dest.loglikelyhood_by_node_theta(x, node_id, theta, .0, decay, relic, observe_time) #print(str(-ll) + ' ' + str(x)) return -ll