示例#1
0
TestFile = u"Data/Social/Test.txt"
UserItemFile = u"Data/UserItem.csv"

Social_Data = np.loadtxt(SocialFile, delimiter=',')
Test_Data = np.loadtxt(TestFile, delimiter=',')
UserItem_Data = np.loadtxt(UserItemFile, delimiter=',', usecols=(1, 2))

print "Social_Data's is Shape :" + str(Social_Data.shape)
print "Test_Data's is Shape :" + str(Test_Data.shape)
print "UserItem_Data's is Shape :" + str(UserItem_Data.shape)
print '\n'

MatrixAdjacency_Social, MaxNode_Social = Initialize.Initialize_Social(
    Social_Data)
MatrixAdjacency_Test = Initialize.Initialize_Test(Test_Data, MaxNode_Social)
MatrixAdjacency_UserItem = Initialize.Initialize_UserItem(UserItem_Data)
print 'MatrixAdjacency_Social'
print MatrixAdjacency_Social
print 'MatrixAdjacency_Test'
print MatrixAdjacency_Test
print 'MatrixAdjacency_UserItem'
print MatrixAdjacency_UserItem

T_MatrixAdjacency_UserItem = MatrixAdjacency_UserItem.T
array_Degree_User = sum(T_MatrixAdjacency_UserItem)
MatrixDegree_User = np.diag(array_Degree_User)
INV_MatrixDegree_User = np.linalg.inv(MatrixDegree_User)

array_Degree_Item = sum(MatrixAdjacency_UserItem)
MatrixDegree_Item = np.diag(array_Degree_Item)
INV_MatrixDegree_Item = np.linalg.inv(MatrixDegree_Item)
示例#2
0
    #         ZhiHu_DB.rollback()
    #         print 'error'+str(list[0][0])+str(list[0][1])
    ZhiHu_DB.close()


import os
import MySQLdb
import Initialize
import numpy as np
import Evaluation_Indicators.AUC

#     MatrixAdjacency_Net,MaxNodeNum = Initialize_Divide.Init(NetFile),delimiter=','
import similarity_indicators.CommonNeighbor

NetFile = u'Data/Followees.txt'
MatrixAdjacency_Net = Initialize.Initialize_UserItem(
    np.loadtxt(NetFile, delimiter=','))
# print MatrixAdjacency_Net.shape
# temp = np.diag(MatrixAdjacency_Net)
# print np.argwhere(temp != 0)
m = 8
# for m in range(MatrixAdjacency_Net.shape[0]):
while m == 8:

    Array = MatrixAdjacency_Net[m]
    tempCN = []
    for n in range(MatrixAdjacency_Net.shape[0]):
        if m != n:
            tempArray = MatrixAdjacency_Net[n]
            CN_Array = Array * tempArray
            CN = np.argwhere(CN_Array != 0)
            CN.shape = (CN.shape[0])