Exemplo n.º 1
0
#indecisive_path.py
#Finds a path through the DAG by moving connected nodes of the highest degree
#Method can be used from either end of the path


from random import choice
import networkx as nx
import data_DAG as maker
import dag_lib as dl


data = open('./Data/Cit-HepPh.DAT', 'r')
DAG = maker.birthdayDAG(data)



def indecisive_path(DAG,node,type,path=[]):
    path.append(node)
    print 'Current Node is: %s' %str(node)
    #Change type to change whether relations are found from bottom (of DAG) up or from the top down
    if type == 'start':
        things = DAG.successors(node)
    elif type == 'end':
        things = DAG.predecessors(node)
    else:
        print 'Error: type given in indecisive_path not recognised'
        
    print 'The things are: %s' %str(things)
    
    if len(things) == 0: #there are no preds/succs to consider so the end of the path has been reached
        print 'Path found!'
Exemplo n.º 2
0
    DAG.add_edge(nodes[0],nodes[1])

list_D = [2,3,4,5,6]
list_N = [25,50,75,100,125,150,175,200,225,250,275,300,325,350,375,400,425,450,475,500]
numrun = 25.
runs = range(int(numrun))
out.write('D' + '\t' + 'N' + '\t' + 'av_plus' + '\t'  + 'av_minus' + '\t' + 'ratio' + '\n')
for D in list_D:
    for N in list_N:
        plus_list = []
        minus_list = []
        for thing in runs:
            DAG = dl.box_generator(N,D)[0]                       
            result = clus.clustering(DAG)
            plus_list.append(result[0])
            minus_list.append(result[1])
        
        av_plus = sum(plus_list)/numrun
        av_minus = sum(minus_list)/numrun
        ratio = av_plus/av_minus
        out.write(str(D) + '\t' + str(N) + '\t' + str(av_plus) + '\t'  + str(av_minus) + '\t' + str(ratio) + '\n')
        print 'Finished %d nodes in %d dimensions' %(N,D)

#for node in DAG.nodes():
#    out.write('\n' + str(node) + '\t' + str(DAG.node[node]['clustering_plus']))'''

#DAG = dl.box_generator(100, 2)[0]
arxiv = open('./Data/Cit-HepTh.DAT', 'r')
DAG = maker.birthdayDAG(arxiv)
result = clus.calculate_2c(DAG, '++')
print result
Exemplo n.º 3
0
    return DAG
    

        

            
if __name__ == '__main__': 
    
    data = open('./Data/Cit-HepPh.DAT', 'r')
    #out = open('./Data/Cit-HepTh_TC_1.txt','w')

    #print DAG.number_of_edges()
    
    
    
    [DAG,node_tuples] = maker.birthdayDAG(data,True,True)
    node_list = []
    for thing in node_tuples:
        node_list.append(thing[0])
        
    #trans_comp(DAG,node_list)
        
    sample = 50
    out = open('./Cit-HepPh_dimensiontest.txt','w')
    while sample > 0:
        node1 = choice(node_list)
        node2 = choice(node_list)
        bday1 = DAG.node[node1]['birthday']
        bday2 = DAG.node[node2]['birthday']
        if bday1 > bday2:
            start = node1
Exemplo n.º 4
0
    # Write TR to data file
    full_filename = './Data/%s.txt' % filename
    TR_out = open(full_filename, 'w')
    for edge in TR.edges():
        TR_out.write(edge[0] + '\t' + edge[1] + '\n')
    return TR    
        

out = open(results_data_file, 'w')

out.write('DAG - ' + original_data_file + '\n')
original_data = open(original_data_file, 'r')
print 'Making DAG from data'
try:
    DAG = maker.birthdayDAG(original_data)
except:
    DAG = maker.basicDAG(original_data)
    print 'DAG made'

try: # Try getting the TR data from a file
    tr_data = open(tr_data_file, 'r')
    print 'Making TR DAG from data'
    try:
        TR = maker.birthdayDAG(tr_data)
    except:
        TR = maker.basicDAG(tr_data)
    print 'DAG made'  
except: # Couldn't find TR data from a file, so create a new TR now, and save it
    print 'Creating new TR data file'
    tr_data_file = 'new_TR_data'
Exemplo n.º 5
0
    end_int_prop = ax_d[end_int]
    
    out.write('Local' + '\t' + str(threshold) + '\t' + str(end) + '\t' + str(len(gip)) + '\t' + str(end_prop[0]) + '\t' + str(end_prop[1]) + '\n')
    out.write('Interval' + '\t' + str(threshold) + '\t' + str(end_int) + '\t' + str(len(interval_gip)) + '\t' + str(end_int_prop[0]) + '\t' + str(end_int_prop[1]) + '\n')

#def find_axis_test(DAG,apex,axis_node):
    
    
    
if __name__ == '__main__':    
    data = open('./Data/Cit-HepPh.DAT', 'r')
    no_in_file = open('./HepPh_no_in.txt', 'r')
    
    start_time = time.clock()
    print 'From function'
    DAG = maker.birthdayDAG(data,True)
    print DAG.number_of_nodes()

    print time.clock() - start_time
    
    no_in = []
    for line in no_in_file:
        no_in.append(line.strip())
    print 'Length no_in is %d' %len(no_in)

    #print lc.cone_axis(DAG,'9910429','forward',no_in)  

    start = '0302265'
    end = '9205221'
    
    '''lc.pythag_distance(DAG,start,end)
Exemplo n.º 6
0
        else:
            years[year] = 1
    x = []
    y = []
    for pair in years.iteritems():
        x.append(pair[0])
        y.append(pair[1])
    plt.bar(x,y, color= 'DodgerBlue',edgecolor= 'DarkSlateGrey',align='center',linewidth=0.8)
    plt.xlim(1991,2004)
    plt.title("Hep%s Papers in the arXiv" %name)
    plt.xlabel("Year of Publication")
    plt.ylabel("Number of Papers")
    plt.savefig( './Plots/%s_byyear.png' %name )
    
        
    
    
if __name__ == '__main__':    
    
    
    fields = ['Ph','Th']
    for field in fields:    
        
        data = open('./Data/Cit-Hep%s.DAT' %field, 'r')
        DAG = maker.birthdayDAG(data,rank=True)
        data_TR = open('./Data/Cit-Hep%s_TR.txt' %field, 'r')
        TR = maker.birthdayDAG(data_TR)
        data_properties(DAG,field)
        #TR_plot(DAG,TR,'Hep%s' %field)
        
        
Exemplo n.º 7
0
    
if __name__ == '__main__':
    
    print 'Making DAG'
    
    no_out_file = open('./HepPh_no_out.txt', 'r')
    no_in_file = open('./HepPh_no_in.txt', 'r')

    #outa = open('./HepPh_lp_tests_a.txt','w')
    outb = open('./HepPh_lp_tests_b.txt','w')
    data = open('./Data/Cit-HepPh.DAT', 'r')
    ar = open('./Data/Cit-HepPh_TR.txt', 'r')
    paths_file = open('./HepPh_lp.txt','w') #longest paths between every no_in_node and no_out_node
    #longest_path_file = open('./HepPh_lp_longest.txt','r') #the very longest path found from every no_in_node
    #DAG = maker.birthdayDAG(data)
    DAG = maker.birthdayDAG(ar) #using TR of data
    print 'Made DAG'

    no_out = []
    no_in = []

    for line in no_out_file:
        no_out.append(line.strip())

    for line in no_in_file:
        no_in.append(line.strip())
        
    IN = len(no_in)
    OUT = len(no_out)