Exemplo n.º 1
0
def ProcessFile(filename):
	print("Processing '%s'" % (filename))

	file_title = os.path.splitext(os.path.basename(filename))[0]

	matrix = np.loadtxt(filename, delimiter=",")
	G      = nx.Graph()
	for i in range(0,matrix.shape[0]):
	  for j in range(i,matrix.shape[1]):
	    G.add_edge(i,j,weight=matrix[i][j])


	#Once the network has been loaded, one needs to produce the filtration of the
	#network.   This can be done in different ways. The simplest is to rank the
	#edges in descending order and use their rank as the indices for the sequence
	#of simplicial complex.    Holes contains a few options for different
	#filtrations (ascending, descending, metrical..).    Below we consider the one
	#with descending weights described in
	#[http://www.plosone.org/article/info%3Adoi%2F10.1371%2Fjournal.pone.0066506]:
	fil = ho.filtrations.dense_graph_weight_clique_rank_filtration(G,2)

	#Once the filtration has been created, it needs to be saved and passed to
	#jython, so that javaplex can receive the data and process it. This requires
	#calling a subprocess and feeding it the right file.
	clique_dictionary_file = './output/'+file_title+'_filtration.pck'
	pk.dump(fil,open(clique_dictionary_file,'w'))

	hom_dim     = 2 # max homology group calculated
	dataset_tag = 'test_IO2009'
	output_dir  = './output/';

	gen_file = './output/gen/generators_test_'+file_title+'_.pck'
	if not os.path.isfile(gen_file):
		ho.persistent_homology_calculation(clique_dictionary_file, hom_dim, dataset_tag, output_dir, jython_call='C:\\jython2.5.4rc1\\jython.bat', m1=2048, m2=2048)


	gen = pk.load(open(gen_file))

	#The properties of each generator can be listed easily:
	gen[1][0].summary()

	#One can also simply produce the barcodes for the network then: 
	ho.barcode_creator(gen[0])
	plt.title(r'Barcode for $H_0$, '+file_title)
	plt.savefig('Barcode0_2006.png')

	ho.barcode_creator(gen[1])
	plt.title(r'Barcode for $H_1$, '+file_title)
	plt.savefig('Barcode1_2006.png')

	ho.barcode_creator(gen[2])
	plt.title(r'Barcode for $H_2$, '+file_title)
	plt.savefig('Barcode2_2006.png')
Exemplo n.º 2
0
    original_graph= #name of the edgelist file
    dir= #output directory path
    dataset_tag= #name tag
    IR_weight_cutoff= #optional cutoff weight
else:
    if len(sys.argv)>=3:
        dir=str(sys.argv[1]); #insert final slash
        dataset_tag=str(sys.argv[2]); #without underlines
    else:
        print('Input is required as:\n 1) name of output directory 
        \n 2) name tag for output files');
        sys.exit();

if not os.path.exists(dir):
    os.makedirs(dir)


sys.path.append('../')
import Holes as ho

import pickle as pk
generators_dict=pk.load(open(dir+'gen/generators_'+dataset_tag+'_.pck'))


for key in generators_dict:
    if len(generators_dict[key])>0:
        print key
        ho.barcode_creator(generators_dict[key]);
        plt.show()
        ho.complete_persistence_diagram(generators_dict[key])
Exemplo n.º 3
0
import networkx as nx
sys.path.append('../../../')
import Holes  as ho
import pickle as pk
import numpy  as np

import matplotlib.pyplot as plt

gen_file = './output/gen/generators_test_IO2007_.pck'
if not os.path.isfile(gen_file):
	os.environ["JAVA_OPTS"]="-Xms2048m -Xmx2048m"
	ho.persistent_homology_calculation(clique_dictionary_file, hom_dim, dataset_tag, output_dir, jython_call='C:\\jython2.5.4rc1\\jython.bat', m1=2048, m2=2048)


gen = pk.load(open(gen_file))

#The properties of each generator can be listed easily:
gen[1][0].summary()

#One can also simply produce the barcodes for the network then: 
ho.barcode_creator(gen[0])
plt.title(r'Barcode for $H_0$, IO2007')
plt.savefig('Barcode0.png')

ho.barcode_creator(gen[1])
plt.title(r'Barcode for $H_1$, IO2007')
plt.savefig('Barcode1.png')

ho.barcode_creator(gen[2])
plt.title(r'Barcode for $H_2$, IO2007')
plt.savefig('Barcode2.png')