Академический Документы
Профессиональный Документы
Культура Документы
IT 404
BIG DATA ANALYSIS
SUBMITTED BY:
RUJHAN SINGLA – 2K16/IT/093
SAAMARTH GUPTA - 2K16/IT/094
PROBLEM I – INFORMATION MAXIMISATION USING LINEAR
THRESHOLD MODEL
CODE
import networkx as nx
import random
import copy
# init thresholds
for n in DG.nodes():
if 'threshold' not in DG.node[n]:
# Set Deafult threshold
DG.node[n]['threshold'] = threshold
elif DG.node[n]['threshold'] > 1:
raise Exception("node threshold:", DG.node[n]['threshold'], \
"cannot be larger than 1")
# init influences
in_deg = DG.in_degree()
for e in DG.edges():
if 'influence' not in DG[e[0]][e[1]]:
DG[e[0]][e[1]]['influence'] = 1.0 / in_deg[e[1]]
elif DG[e[0]][e[1]]['influence'] > 1:
raise Exception("edge influence:", DG[e[0]][e[1]]['influence'], \
"cannot be larger than 1")
# perform diffusion
A = copy.deepcopy(seeds)
if steps <= 0:
# perform diffusion until no more nodes can be activated
return _diffuse_all(DG, A)
# perform diffusion for at most "steps" rounds only
return _diffuse_k_rounds(DG, A, steps)
G = nx.gnp_random_graph(edges, edgeProbability)
print(nx.info(G))
OUTPUT
PROBLEM II – INFORMATION MAXIMISATION USING INFORMATION
CASCADE MODEL
CODE
# init prob
in_deg = DG.in_degree()
for e in DG.edges():
if 'prob' not in DG[e[0]][e[1]]:
DG[e[0]][e[1]]['prob'] = 1.0 / in_deg[e[1]]
elif DG[e[0]][e[1]]['prob'] > 1:
raise Exception("probablity:", DG[e[0]][e[1]]['prob'], \
"cannot be larger than 1")
# perform diffusion
A = copy.deepcopy(seeds)
if steps <= 0:
# perform diffusion until no more nodes can be activated
return _diffuse_all(DG, A)
# perform diffusion for at most "steps" rounds only
return _diffuse_k_rounds(DG, A, steps)
G=nx.gnp_random_graph(50,0.045)
print(nx.info(G))
nx.draw(G,node_size=140,with_labels=True)
#plt.draw(markersize=8)
plt.show()
iterations=10000 # Number of Iterations
for i in range(iterations):
max_influence=0
seed_set=random.sample(G.nodes(),7)
S=set(seed_set)
influence=info_cascade(G,list(S))
if(len(influence)>max_influence):
max_influence=len(influence)
y=influence[:-1]
seeds=list(S)
print("Max influence for: ")
print(seeds)
print("Influence: ")
print(y)
OUTPUT