def tick(print_nets=False, fitness='eigvals'): global stats, populations, fitnesses for i in xrange(_npops): populations[i], fitnesses[i] = ga.tick(populations[i], fitnesses[i], fitness=fitness) sccs = [net.sccs_in_array(m) for m in populations[i]] sccs_flat = [x for s in sccs for x in s] # sccs across population sccs_hist = util.histogram(sccs_flat) sccs_hist = util.truncate_or_pad(sccs_hist, _n + 1, 0)[1:] hamm = util.mean_hamming(populations[i]) stats[i] = { 'mean_fit': sum(fitnesses[i]) / _popsize, 'mean_sccs': sum([len(s) for s in sccs]) / _popsize, 'mean_hamm': hamm, 'sccs_hist': sccs_hist } if print_nets: rand_net = populations[i][np.random.randint(_popsize)] stats[i]['net'] = net.array_to_dot(rand_net)
from __future__ import division import sys import numpy as np fp = np.load(sys.stdin) N = fp[fp.keys()[0]].shape[0] from modmat import net scc_count = [len(net.sccs_in_array(arr)) for k, arr in fp.iteritems()] mean_sccs = sum(scc_count) / len(scc_count) serr_sccs = np.std(scc_count, ddof=1) / np.sqrt(len(scc_count)) tot = 0 nonz = 0 for k, arr in fp.iteritems(): for i in xrange(N): for j in xrange(N): tot += 1 if arr[i, j] != 0: nonz += 1 print "Mean number of SCCS: %g +- %g" % (mean_sccs, serr_sccs) print "Mean entry density: %g" % (nonz/tot)
from __future__ import division import sys import numpy as np fp = np.load(sys.stdin) N = fp[fp.keys()[0]].shape[0] from modmat import net scc_count = [len(net.sccs_in_array(arr)) for k, arr in fp.iteritems()] mean_sccs = sum(scc_count) / len(scc_count) serr_sccs = np.std(scc_count, ddof=1) / np.sqrt(len(scc_count)) tot = 0 nonz = 0 for k, arr in fp.iteritems(): for i in xrange(N): for j in xrange(N): tot += 1 if arr[i, j] != 0: nonz += 1 print "Mean number of SCCS: %g +- %g" % (mean_sccs, serr_sccs) print "Mean entry density: %g" % (nonz / tot)