예제 #1
0
def pickRandEdges():
	global externalDG
	global clusterDG
	open('OutputExp6/clusterOpinions.csv', 'w').close()
	open('OutputExp6/nonClusterOpinions.csv', 'w').close()

	print 'creating Cluster graph with PRN'
	clusterDG = runPRN()
	print 'creating nonCluster graph'
	externalDG = readDotFile('advogato-graph-latest.dot')
	clusterEdges = clusterDG.edges()
	clusterNodes = clusterDG.nodes()
	externalDG.remove_edges_from(clusterEdges)
	externalDG.remove_nodes_from(clusterNodes)

	externalEdges = externalDG.edges()

	for i in range(0,1000):
		if len(clusterEdges) < 2:
			print "cluster too small to sample from, aborting..."
			break
		randClusterEdge = random.sample(clusterEdges, 1)
		randExtEdge = random.sample(externalEdges, 1)

		clusterOpn = TVSLTran(clusterDG[randClusterEdge[0][0]][randClusterEdge[0][1]]['level'])
		externalOpn = TVSLTran(externalDG[randExtEdge[0][0]][randExtEdge[0][1]]['level'])


		with open('OutputExp6/clusterOpinions.csv', 'a') as csvfile:
			toWrite = csv.writer(csvfile, delimiter = ',')
			toWrite.writerow([clusterOpn[0], clusterOpn[1], clusterOpn[2], clusterOpn[3]])

		with open('OutputExp6/nonClusterOpinions.csv', 'a') as csvfile:
			toWrite = csv.writer(csvfile, delimiter = ',')
			toWrite.writerow([externalOpn[0], externalOpn[1], externalOpn[2], externalOpn[3]])
예제 #2
0
def runPRN():
	#DG = readDotFile('/home/loenix/Documents/advogato_graph/advogato-graph-2014-03-16.dot')
	DG = readDotFile('advogato-graph-latest.dot')
	#DG = nx.DiGraph(nx.read_dot('/home/loenix/Documents/advogato_graph/advogato-graph-2014-03-16.dot'))

	Eps = 0.000001  #set up epsilon
	alpha = 0.15  # set alpha

	#pick up a nodes far enough from the seed
	#so that the subgraph on which APPR run will 
	#will be large enough

	numHops = 4
	rand = random.randint(0,len(DG.nodes())-1)
	Seed = DG.nodes()[rand]
	remoteSeed =  getTrustorsOfExactHop(DG, Seed, numHops)


	while remoteSeed == 0 :
	    Seed = DG.nodes()[rand]
	    remoteSeed =  getTrustorsOfExactHop(DG, Seed, numHops)

	#now got a seed which has 4 hop neighbor, run APPR

	#print('seed is:' + Seed)
	#print('nb of seed is: ' + str(DG.neighbors(Seed)))
	#since the algr works on undirected graph
	DG.to_undirected()
	PR = PageRankNibble(DG, Seed, alpha, Eps)
	#using the ranked nodes to form a subgraph. 
	H = DG.subgraph(PR)
	nx.write_dot(H, 'pprResult.dot')
	return H
예제 #3
0

# Creates a distribution of the shortest distance between nodes
# Samples 1000 nodes
# file[0] contains the number of nodes where no path exists
def smallWorldProblem(numberOfReps=1000):
    distribution = []
    for i in range(0, 50):
        distribution.append(0)

    for source in DG.nodes()[0:numberOfReps]:
        for D in DG.nodes():
            if source != D:
                if nx.has_path(DG, source, D) == False:
                    distribution[0] += 1
                else:
                    distribution[nx.shortest_path_length(DG, source, D)] += 1

    distWrite(distribution, "OutputExp2/smallworld.txt")


DG = readDotFile("data.dot")

if os.path.exists('OutputExp2') == False:
    print "Making the directory OutputExp2"
    os.mkdir("OutputExp2")

testTrustPropogation()
testTrustComposing()
smallWorldProblem()
예제 #4
0
	#need a sample of 1000 opinions. ideally, running for 50000 iterations will produce a list
	# that has at least 1000 opinions with expected belief over 0.75
	for i in range(0, numberOfReps):
		newPair = random.sample(DG.nodes(), 2)
		if newPair not in pairsList:

			if nx.has_path(DG, newPair[0], newPair[1]):
				pairOpnDG = nx.DiGraph()
				pathLength = nx.shortest_path_length(DG, newPair[0], newPair[1])
				paths = nx.all_simple_paths(DG, source=newPair[0], target=newPair[1], cutoff=pathLength+ additionToPathLength)
				for path in paths:
					nodeList = []
					for i in range(0, len(path)-1):
						pairOpnDG.add_edge(path[i], path[i+1], level=DG[path[i]][path[i+1]]['level'])
				pairOpinion = TVSLAlgr(pairOpnDG, newPair[0], newPair[1], pathLength+additionToPathLength, 0)
				print pathLength
				print pairOpinion

				with open('OutputExp4/opinionsList.csv', 'a') as csvfile:
					toWrite = csv.writer(csvfile, delimiter = ',')
					toWrite.writerow([pathLength, pairOpinion[0], pairOpinion[1], pairOpinion[2], pairOpinion[3]])

if os.path.exists('OutputExp4') == False:
	print "Making the directory OutputExp4"
	os.mkdir("OutputExp4")

DG = readDotFile("data.dot")
testCocitationCouplingAndTransitivity()
makeHighExpBeliefSample()

예제 #5
0
              and (oldDG.has_edge(B, C) == False)
              and cocitationCounter < desiredTriangles):
            print "cocitation"
            cocitationCounter += 1
            XLevel = newDG[A][B]['level']
            YLevel = newDG[A][C]['level']
            ZLevel = newDG[B][C]['level']
            writeTriangleOfTrust(XLevel, YLevel, ZLevel,
                                 "OutputExp5/CoCitation.csv")

        elif ((oldDG.has_edge(A, B) == False) and oldDG.has_edge(A, C)
              and oldDG.has_edge(B, C) and couplingCounter < desiredTriangles):
            print "couple"
            couplingCounter += 1
            XLevel = newDG[B][C]['level']
            YLevel = newDG[A][C]['level']
            ZLevel = newDG[A][B]['level']
            writeTriangleOfTrust(XLevel, YLevel, ZLevel,
                                 "OutputExp5/Coupling.csv")


if os.path.exists('OutputExp5') == False:
    print "Making the directory OutputExp5"
    os.mkdir("OutputExp5")

oldDG = readDotFile("old.dot")
newDG = readDotFile("data.dot")

newDG = newDG.subgraph(oldDG.nodes())
testCocitationCouplingAndTransitivityOverTime()
예제 #6
0
		clusterOpn = TVSLTran(clusterDG[randClusterEdge[0][0]][randClusterEdge[0][1]]['level'])
		externalOpn = TVSLTran(externalDG[randExtEdge[0][0]][randExtEdge[0][1]]['level'])


		with open('OutputExp6/clusterOpinions.csv', 'a') as csvfile:
			toWrite = csv.writer(csvfile, delimiter = ',')
			toWrite.writerow([clusterOpn[0], clusterOpn[1], clusterOpn[2], clusterOpn[3]])

		with open('OutputExp6/nonClusterOpinions.csv', 'a') as csvfile:
			toWrite = csv.writer(csvfile, delimiter = ',')
			toWrite.writerow([externalOpn[0], externalOpn[1], externalOpn[2], externalOpn[3]])


if os.path.exists('OutputExp6') == False:
	print "Making the directory OutputExp6"
	os.mkdir("OutputExp6")


DG = readDotFile('advogato-graph-latest.dot')
H = runPRN()

pickRandEdges()

print "within"
withinCluster(DG, H, 2)
print "out"
outOfCluster(DG, H, 2)
print "done"

예제 #7
0
		elif (oldDG.has_edge(A,B) and oldDG.has_edge(A,C) and 
			(oldDG.has_edge(B,C) == False) and cocitationCounter < desiredTriangles):
			print "cocitation"
			cocitationCounter+=1
			XLevel = newDG[A][B]['level']
			YLevel = newDG[A][C]['level']
			ZLevel = newDG[B][C]['level']
			writeTriangleOfTrust(XLevel,YLevel,ZLevel,"OutputExp5/CoCitation.csv")
		

		elif ((oldDG.has_edge(A,B)==False) and oldDG.has_edge(A,C) and 
			oldDG.has_edge(B,C) and couplingCounter < desiredTriangles):
			print "couple"
			couplingCounter+=1
			XLevel = newDG[B][C]['level']
			YLevel = newDG[A][C]['level']
			ZLevel = newDG[A][B]['level']
			writeTriangleOfTrust(XLevel,YLevel,ZLevel,"OutputExp5/Coupling.csv")

	

if os.path.exists('OutputExp5') == False:
	print "Making the directory OutputExp5"
	os.mkdir("OutputExp5")

oldDG = readDotFile("old.dot")
newDG = readDotFile("data.dot")

newDG = newDG.subgraph(oldDG.nodes())
testCocitationCouplingAndTransitivityOverTime()