Exemplo n.º 1
0
def weight_label_generators(gen_dict,G,ascending=False):
	weighted_generators={};

	for key in gen_dict:
		weighted_generators[key]=[];

	edge_weights=nx.get_edge_attributes(G,'weight').values();
	edge_weights=list(set(edge_weights));

	if ascending==False:
		edge_weights=sorted(edge_weights, reverse=True);
		max_weight=edge_weights[0];
	else:
		edge_weights=sorted(edge_weights);
		max_weight=edge_weights[-1];

	for key in gen_dict:
		for rank_cycle in gen_dict[key]:
			b=int(float(rank_cycle.start));
			d=int(float(rank_cycle.end));
			comp=rank_cycle.composition;
			dim=rank_cycle.dim;
			if ascending==True:
				weighted_generators[key].append(ho.Cycle(dim,comp,edge_weights[b],edge_weights[d]));
			else: 
				weighted_generators[key].append(ho.Cycle(dim,comp,edge_weights[d],edge_weights[b]));

	return weighted_generators;
Exemplo n.º 2
0
import string
for h in range(dimension + 1):
    Generator_dictionary[h] = []
    list_gen = list(annotated_intervals.getGeneratorsAtDimension(h))
    # if save_generators==True:
    # 	gen_details_file=open(gendir+'details_generators_'+str(h)+'_'+str(stringie)+'.pck','w');
    # 	pickle.dump(list_gen,gen_details_file);

    list_intervals = list(annotated_intervals.getIntervalsAtDimension(h))
    for n, key in enumerate(list_gen):
        test = str(list_intervals[n]).split(',')
        test[0] = test[0].strip(' [')
        test[1] = test[1].strip(' )')
        if test[1] == 'infinity':
            test[1] = str(max_filtration_value)
        line = str(key)
        line = line.translate(string.maketrans('', ''), '-[]')
        line = re.sub('[,+ ]', ' ', line)
        line = line.split()
        tempcycle = Holes.Cycle(h, list2simplexes(line, h), test[0], test[1])
        Generator_dictionary[h].append(tempcycle)
        del tempcycle
    for cycle in Generator_dictionary[h]:
        cycle.summary()

filename = os.path.join(gendir, 'generators_' + str(stringie) + '.pck')
generator_dict_file = open(filename, 'w')
pickle.dump(Generator_dictionary, generator_dict_file)
print 'Generator dictionary dumped to ' + filename,
generator_dict_file.close()