예제 #1
0
#graph = pcd.graphs.dolphins(weightFriend=-1)
##graph = pcd.graphs.relabel_nodes(graph)
#G = pcd.Graph.fromNetworkX(graph, defaultweight=1)

#g = pcd.graphs.karate_club()
#G = pcd.Graph.fromNetworkX(g, defaultweight=1)

G = pcd.graphs.bss2d_n240_T050()

print "N nodes", G.N
gamma = .001
G.verbosity = 1.5
G.cmtyCreate()
G.trials(gamma, trials=10, minimizer=G.anneal, attempts=10, Escale=10000)
print G.energy(gamma)
G.trials(gamma, trials=10, minimizer=G.minimize)
print G.energy(gamma)
#G.minimize(.1)
#G.anneal(.1)

MR = pcd.MultiResolution(minimizer='trials',
                         minimizerargs=dict(minimizer='anneal',
                                            Escale=10000,
                                            attempts=10,
                                            trials=1,
                                            betafactor=1.1),
                         savefigargs=dict(fname=dirname +
                                          'gamma%(gamma)09.4f.png'))

MR.run([G] * 2, gammas=dict(low=.01, high=10, density=2))
예제 #2
0
#sep = 16
imatrix, coords = fractalsquare2(L=16)
print imatrix
print coords
G = G.from_imatrix(imatrix)

G.minimize(gamma=0)
G.savefig('img.png', coords=coords)

if not os.path.exists('imgs'):
    print "Creating dir:",os.path.join(os.getcwd(),'imgs')
    os.mkdir('imgs')

def callback(gamma, data, state, **kwargs):
    G = data['Gmin']
    G.remap(check=False)
    fname = 'imgs/gamma%011.5f.png'%gamma
    Es = [ G.energy_n(gamma, n) for n in range(G.N) ]
    G.savefig(fname, coords=coords, energies=Es,
              nodes='circles')

nreplicas, ntrials, ldensity = 10, 250, 20
if globals().get('fast', True):
    nreplicas, ntrials, ldensity = 5, 5, 10

MR = pcd.MultiResolution()
MR.run([G]*nreplicas, gammas=dict(low=.001, high=100, density=ldensity),
      threads=2, callback=callback)
#MR.calc()
MR.plot("imgs.png")
예제 #3
0
from numpy import random
import os

import pcd
import pcd.graphs

outputdir = os.path.join("tests-output/overlapMR")
if not os.access(outputdir, os.F_OK):
    os.makedirs(outputdir)

G = pcd.graphs.bss2d_n240_T050()

#G.setOverlap(True)

#
# Test MR and overlaps
#
density = 10
nreplicas = 8
if 'fast' in globals():
    density = 3
    nreplicas = 3
MR = pcd.MultiResolution(overlap=5,
                         plotargs=dict(fname=os.path.join(outputdir, 'MR.png'),
                                       ax1items=('ov_N', 'entropy', 'In'),
                                       plotstyles={
                                           'ov_N': dict(scale=10),
                                           'In': dict(scale=3)
                                       }))
MR.run([G] * nreplicas, gammas=dict(low=.01, high=100, density=density))
예제 #4
0
G.savefig(os.path.join(dirname, 'amorphous_gamma0.png'),
          radii=G.radii,base_radius=0.4)

#def callback(G, gamma, **kwargs):
#    G.remapCommunities(check=False)
#    fname = os.path.join(dirname, 'amorphous_gamma%011.5f.svg'%gamma)
#    G.savefig(fname,radii=G.radii,base_radius=0.4)

#nreplicas, ntrials = 10, 20
nreplicas, ntrials = 3, 5
if fast:
    nreplicas, ntrials = 5, 5

from pcd import LogInterval
gammas = LogInterval(.001, 100, density=10).values()

MR = pcd.MultiResolution(
    savefigargs=dict(
        fname=os.path.join(dirname, 'amorphous_gamma%(gamma)011.5f.svg'),
        base_radius=0.4),
    minimizerargs=dict(trials=ntrials),
    )
MR.run([G]*nreplicas, gammas, threads=1,
       )
#MR = pcd.MultiResolution(0.1, 1, callback=callback, number=10)
#MR.do([G]*10, trials=10, threads=2)
MR.write(os.path.join(dirname, "mr.txt"))
#MR.plot(os.path.join(dirname, amorphous_mr.png"))
#MR.plot_nmean(os.path.join(dirname, "amorphous_mr_nmean.png"))
#MR.plot_nhists(os.path.join(dirname, "nhists.pdf"))
예제 #5
0
#nx.drawing.nx_pydot.pydot_layout(g)
#import networkx.drawing.layout as layout
import networkx.drawing.nx_pydot  #layout as layout
#G.coords = layout.spring_layout(g)
g2 = g.copy()
for a, b, d in g2.edges_iter(data=True):
    if G.cmty[a] == G.cmty[b]:
        d['weight'] = 5
    else:
        d['weight'] = 1
    #d['weight'] = -d['weight']
G.coords = networkx.drawing.nx_pydot.pydot_layout(g2)
print G.coords

#G.savefig('tests-output/overlapmin/gamma1.png', hulls=True)
#G.viz()
#exit()

trials = 10
density = 10
if 'fast' in globals():
    trials = 2
    density = 3

MR = pcd.MultiResolution(
    #savefigargs=dict(fname='tests-output/overlapmin/mr.png'),
    minimizerargs=dict(minimizer='ovGreedy', trials=trials),
    plotargs=dict(fname='tests-output/overlapmin/mr.png'),
    overlap=5)
MR.run([G] * 5, gammas=dict(low=.001, high=100, density=density))
예제 #6
0
nreplicas, ntrials, ldensity = 12, 100, 100
nreplicas, ntrials, ldensity = 12, 5, 30
if fast:
    nreplicas, ntrials, ldensity = 3, 10, 10

#for a,b in [random.sample(range(G.N), 2) for _ in range(1000)]:
#    pcd.util.matrix_swap_basis(G.imatrix, a, b)
from pcd import LogInterval
import pcd.F1

if fast:
    savefigargs = None
else:
    savefigargs = dict(fname="tests-output/tribes/gamma%(gamma)05.3f.png")
MR = pcd.MultiResolution(overlap=5,
        savefigargs=savefigargs
                         )
G.make_sparse('auto')
G.verbosity = -1

MRR = pcd.MRRunner(MR)
#raw_input('before MRR >')
MRR.do(Gs=[G]*nreplicas,
       #gammas=LogInterval(low=.01, high=10, density=ldensity).values(),
       gammas=dict(low=.01, high=10, density=ldensity),
       )
#raw_input('after MRR >')
MR.write("tests-output/tribes/tribes.txt")
f = MR.plot("tests-output/tribes/tribes.png",
            ax1items=('VI', 'In', #'s_F1'
                      ))
예제 #7
0
G2.cmtyListAddOverlap(0, 1)
G2.combineSubsets()
#sys.exit(0)

G.greedy(gamma=.1)
#print PO(G0, G)
G.ovgreedy(gamma=.1)
#print PO(G0, G)
#from fitz import interactnow
#sys.exit(0)

#sys.exit(0)
import pcd.F1

MR = pcd.MultiResolution(
    minimizerargs=dict(minimizer="ovfree", trials=5),
    output='tests-output/studyoverlap/tmp7c.txt',
    #G0=G0,
    overlap=3,
    #pairstyle='all',
)
MR.G0 = G0
MR.run(
    [G] * 3,
    #logGammaArgs=dict(low=.01, high=100, density=10),
    #logGammaArgs=dict(low=.01, high=1000, density=5),
    gammas=dict(low=.1, high=10, density=15),
    threads=1)
MR.write('tests-output/studyoverlap/tmp7c.txt')
MR.plot('tests-output/studyoverlap/tmp7c.png')