-
Notifications
You must be signed in to change notification settings - Fork 5
/
example.py
48 lines (40 loc) · 1.53 KB
/
example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import os
os.chdir("../../")
import kreveik
import logging
import numpy as num
import shelve
logging.basicConfig(level=logging.INFO)
os.chdir("examples/example1/")
petri = kreveik.classes.Family()
motiflist = []
scores = []
degrees = []
mean_distance = []
allmotifs = kreveik.network.motif.all_conn_motifs(3)
for i in xrange(200):
a = kreveik.network.generators.random(7, kreveik.network.boolfuncs.xor_masking_C,
probability=(0.5,0.5,0.5),
connected=True)
petri.add(a)
petri.scorer = network.scorers.sum_scorer_f
petri.selector = network.selectors.hard_threshold_with_probability
petri.mutator = network.mutators.degree_preserving_mutation
petri.killer = family.killer.random_killer
petri.populate_equilibria()
for i in xrange(100):
for j in xrange(50):
print "("+str(i)+"/100) ("+str(j)+"/50)"
kwargs = {'motiflist':allmotifs[:],'prob':0.5,'threshold':1.5}
genetic.genetic_iteration(petri,**kwargs)
degrees.append(num.mean([element.outdegree() for element in petri]))
scores.append(num.mean([network.score for network in petri]))
motiflist.append(family.motif_freqs(petri, 3, **kwargs))
mean_distance.append(petri.global_mean_spectral_distance())
theshelve = shelve.open("backup"+str(i)+"of100.dat")
theshelve["petri"] = petri
theshelve["scores"] = scores
theshelve["degrees"] = degrees
theshelve["motiflist"] = motiflist
theshelve["mean_distance"] = mean_distance
theshelve.close()