def test_zashitim_taigu_noconfirm(post_id, new_lib=False): casman = CascadesManager(name='Zashitim_taigu_-164443025_8726_8021_6846', base_dir='D:/BigData/Charity/Cascades/') casman.load_from_file() cascade = casman.get_cascade_by_id(post_id) min_delay = cascade.get_minimum_delay() #outcome = cascade.get_outcome(normalization_factor=min_delay) outcome = cascade.get_outcome(normalization_factor=3600) counters = casman.underlying_net.counters_meta print(casman.get_underlying_path()) tmax = max(outcome.values()) tmax *= 1.5 if new_lib: est.set_diffusion_data_newlib(casman.get_underlying_path(), outcome=outcome, observe_time=tmax) print('Max: ' + str( est.llmax_for_diffusion_noconfirm( 8.65381982e-04, 3.07426738e-08, 1.53208126e-07, new_lib=True))) else: est.set_diffusion_data(casman.get_underlying_path(), counters=counters, outcome=outcome) print('Max: ' + str( est.llmax_for_diffusion_noconfirm(1.41127581e-03, 1.07595601e-10, 2.65026813e-07, observe_time=tmax)))
def test_zashitim_taigu_ICM_compare(post_id): casman = CascadesManager(name='Zashitim_taigu_-164443025_8726_8021_6846', base_dir='D:/BigData/Charity/Cascades/') casman.load_from_file() cascades = [] tmaxs = [] cascade = casman.get_cascade_by_id(post_id) outcome_old = cascade.get_outcome(normalization_factor=3600) outcome = cascade.get_outcome_connected_only( casman.underlying_net.network.nodes, normalization_factor=3600) print("Outcome total size: " + str(len(outcome_old))) print("Outcome giant size: " + str(len(outcome))) print(outcome) print(casman.get_underlying_path()) tmax = max(outcome.values()) tmax *= 1.5 est.set_diffusion_data_newlib(casman.get_underlying_path(), outcome=outcome, observe_time=tmax) #est.set_alpha_for_node(-164443025, 30) result1 = est.llmax_for_diffusion_SI_decay(1.49969075e-05, 1.34657003e-02) #result1 = est.llmax_for_diffusion_SI_decay(1.49969075e-05, 0.03545553788287585, fixed_delta=True) print(result1) result2 = est.llmax_for_diffusion_ICM(0.001) print(result2) print("1-exp(theta/delta): " + str(1. - math.exp(-result1['theta'] / result1['decay']))) #print("1-exp(theta/delta): " + str(1. - math.exp(-result1['theta'] / 0.03545553788287585))) print("ICM p: " + str(result2['theta']))
def test_zashitim_taigu_confirm_multiple(post_ids=None): casman = CascadesManager(name='Zashitim_taigu_-164443025_8726_8021_6846', base_dir='D:/BigData/Charity/Cascades/') casman.load_from_file() cascades = [] outcomes = [] tmaxs = [] if post_ids is None: cascades = casman.cascades else: for post_id in post_ids: cascades.append(casman.get_cascade_by_id(post_id)) for cascade in cascades: outcome = cascade.get_outcome(normalization_factor=3600) print(len(outcome)) outcomes.append(outcome) tmaxs.append(1.5 * max(outcome.values())) return print(casman.get_underlying_path()) est.set_diffusion_data_ensemble_newlib(casman.get_underlying_path(), outcomes=outcomes, observe_times=tmaxs) thetas0 = [2.0334495598850714e-05 for i in range(len(outcomes))] relics0 = [1.1620706275554255e-08 for i in range(len(outcomes))] confirms0 = [0. for i in range(len(outcomes))] #thetas0 = [6.640777840198647e-05, 2.0334495598850714e-05, 2.4494338855225353e-05] #relics0 = [1.1620706275554255e-08, 1.8733700717464615e-08, 3.811750042715803e-08] print('Max: ' + str( est.llmax_for_diffusion_confirm_multiple_cases( thetas0=thetas0, decay0=0.03688237209138165, relics0=relics0, confirms0=confirms0)))
def simulate_diffusion_cascades_zashitim_taigu(n_cascades, theta, rho, delta): casman = CascadesManager(name='Zashitim_taigu_-164443025_8726_8021_6846', base_dir='D:/BigData/Charity/Cascades/') casman.load_from_file() cascade = casman.get_cascade_by_id(6846) print(cascade.get_minimum_delay()) print(max(cascade.get_outcome(normalization_factor=3600).values())) est.set_alpha_for_node(-164443025, 25) outcome = Simulator.simulate_SI_decay_confirm_relicexp_hetero( casman.underlying_net.network, theta, delta, .0, rho, infected={-164443025}, tmax=2500., dt=30, echo=True) print(outcome)
def test_zashitim_taigu_confirm(post_id): casman = CascadesManager(name='Zashitim_taigu_-164443025_8726_8021_6846', base_dir='D:/BigData/Charity/Cascades/') casman.load_from_file() cascade = casman.get_cascade_by_id(post_id) min_delay = cascade.get_minimum_delay() outcome = cascade.get_outcome(normalization_factor=min_delay) counters = casman.underlying_net.counters_meta print(casman.get_underlying_path()) est.set_diffusion_data(casman.get_underlying_path(), counters=counters, outcome=outcome) print('Max: ' + str( est.llmax_for_diffusion(1.00019217e-6, 3.61779381e-01, 4.07895457e-03, 1.24224204e-07)))
def test_zashitim_taigu_noconfirm_converge(post_id, delta, steps=10): casman = CascadesManager(name='Zashitim_taigu_-164443025_8726_8021_6846', base_dir='D:/BigData/Charity/Cascades/') casman.load_from_file() cascade = casman.get_cascade_by_id(post_id) outcome = cascade.get_outcome(normalization_factor=3600) print(casman.get_underlying_path()) tmax = max(outcome.values()) tmax *= 1.5 delta_t = tmax / (20 * steps + 1) thetas = [] rhos = [] lengths = [] thetasICM = [] rhosICM = [] print(outcome) for i in range(steps): t = delta_t * (i + 1) new_outcome = {} for k, v in outcome.items(): if v <= t: new_outcome[k] = v print("T: ", t) print("Outcome length: ", len(new_outcome)) est.set_diffusion_data_newlib(casman.get_underlying_path(), outcome=new_outcome, observe_time=t) #est.set_alpha_for_node(-164443025, 15) result = est.llmax_for_diffusion_SI_relic(6.102733267373096e-05, 1.2196174044195352e-08, delta=delta, new_lib=True) thetas.append(result['theta']) rhos.append(result['relic']) result2 = est.llmax_for_diffusion_ICM(0.0011, 0.0000011) thetasICM.append(result2['theta']) rhosICM.append(result2['relic']) lengths.append(len(new_outcome)) print(thetas) print(rhos) print(lengths) print(thetasICM) print(rhosICM)
def test_zashitim_taigu_dlldthetas(post_id, theta, decay, relic): casman = CascadesManager(name='Zashitim_taigu_-164443025_8726_8021_6846', base_dir='D:/BigData/Charity/Cascades/') casman.load_from_file() cascade = casman.get_cascade_by_id(post_id) min_delay = cascade.get_minimum_delay() outcome = cascade.get_outcome(normalization_factor=min_delay) counters = casman.underlying_net.counters_meta print(casman.get_underlying_path()) est.set_diffusion_data(casman.get_underlying_path(), counters=counters, outcome=outcome) dlldthetas = est.dlldthetas_noconfirm(theta, decay, relic, outcome.keys()) cascade.network.add_node_attribute('dth', 'dLL_dTheta', 'float') for k, v in dlldthetas.items(): cascade.network.add_meta_for_node(k, {'dth': v}) cascade.network.export_gexf( 'D:/BigData/Charity/Cascades/Zashitim_taigu_-164443025_' + str(post_id) + '_dlldth.gexf') show_dlldthetas(dlldthetas)
def test_zashitim_taigu_noconfirm_theta_graph(post_id, decay, relic): casman = CascadesManager(name='Zashitim_taigu_-164443025_8726_8021_6846', base_dir='D:/BigData/Charity/Cascades/') casman.load_from_file() cascade = casman.get_cascade_by_id(post_id) min_delay = cascade.get_minimum_delay() outcome = cascade.get_outcome(normalization_factor=min_delay) counters = casman.underlying_net.counters_meta print(casman.get_underlying_path()) est.set_diffusion_data(casman.get_underlying_path(), counters=counters, outcome=outcome) print(outcome) tmax = max(outcome.values()) tmax *= 1.5 thetas = np.arange(1e-9, 1e-6, 1e-8) lls = np.zeros(len(thetas)) maxll = -999999999999999999. for i in range(len(thetas)): lls[i] = -est.loglikelyhood_noconfirm([thetas[i], decay, relic], observe_time=tmax) print(str(i) + ' - ' + str(lls[i])) if (maxll < lls[i]): maxll = lls[i] maxll -= 300 for i in range(len(thetas)): lls[i] = lls[i] - maxll print(lls[i]) if lls[i] < 0: lls[i] = 0 else: lls[i] = math.exp(lls[i]) plt.plot(thetas, lls) plt.show()
return self.libr.DADSLogLikelyhoodByNodeTheta(node_theta, node_id, theta, confirm, decay, relic, observe_time) def thetas_derivatives(self, theta, confirm, decay, relic, ids, observe_time): self.libr.DADSCalculateDerivatives(theta, confirm, decay, relic, observe_time) derivatives = {} for id in ids: derivatives[id] = self.libr.DADSDLogLikelyhoodDthetaForId(id) return derivatives if __name__ == '__main__': casman = CascadesManager(name='Zashitim_taigu_-164443025_8726_8021_6846', base_dir='D:/BigData/Charity/Cascades/') casman.load_from_file() cascade = casman.get_cascade_by_id(8726) min_delay = cascade.get_minimum_delay() outcome = cascade.get_outcome(normalization_factor=min_delay) counters = casman.underlying_net.counters_meta estmtr = DiffusionEstimator(True) estmtr.load_network( 'D:/BigData/Charity/Cascades/Zashitim_taigu_-164443025_8726_8021_6846u_network.dos', counters, outcome) for i in range(10): ll = estmtr.loglikelyhood(0.0000001, 0.5, 0.00001, 0.00000001) print(str(i) + ' ' + str(ll)) #150437823 28082048 519339743
# Created by Gubanov Alexander (aka Derzhiarbuz) at 05.06.2019 # Contacts: [email protected] from da_icascades_manager import CascadesManager from da_information_conductivity import InformationConductivity import numpy as np import matplotlib.pylab as pl casman = CascadesManager(name='WorldVita', base_dir='D:/BigData/Charity/Cascades/') casman.load_from_file() casman.update_cascades(uselikes=False, usehiddens=False) cond_net = InformationConductivity() cond_net.make_cascades_summary(casman.cascades, logweight=False) cond_net.make_underlying_summary([casman.underlying_net]) # print(cond_net.cascades_network.links) # print(cond_net.cascades_network.nodes) # print(cond_net.cascades_network.nodes_attributes) # print(len(cond_net.underlying.nodes)) # cond_net.cascades_network.export_gexf('D:/BigData/Charity/Cascades/PomogatLegko100Summary.gexf', drop_singletones=True) summary = cond_net.nodes_summary() print(summary['in']) print(len(summary['in'])) print(summary['out']) print(len(summary['out'])) print(summary['in_w']) print(len(summary['in_w'])) print(summary['out_w']) print(len(summary['out_w']))