def export_colors(datafile, outfile):
    try:
        A = mmread(datafile)
        A = A.toarray()
        d = np.zeros_like(A)
        G = s.DirectedGraph(A, d)
        colors = G.coloring()
        with open(outfile, 'wb') as out:
            pickle.dump(colors, out)
    except Exception as e:
        with open('error_log.txt', 'w') as error_log:
            error_log.write(f'\n {e}')
    finally:
        return
Пример #2
0
    f = np.array([[sig, sig2, sig, sig, sig, sig, sig2, sig],
                  [sig2, sig2, sig2, sig2, sig2, sig2, sig2, sig2],
                  [sig, sig2, sig, sig, sig, sig, sig2, sig],
                  [sig, sig2, sig, sig, sig, sig, sig2, sig],
                  [sig, sig2, sig, sig, sig, sig, sig2, sig],
                  [sig, sig2, sig, sig, sig, sig, sig2, sig],
                  [sig2, sig2, sig2, sig2, sig2, sig2, sig2, sig2],
                  [sig, sig2, sig, sig, sig, sig, sig2, sig]])

    a = np.array([zero, f1, f1, f1, f1, f1, f1, f1])
    labels = ['1', '2', '3', '4', '5', '6', '7', '8']

    counts = []
    for i in range(20):
        G = s.DirectedGraph(A, (a, f), labels=labels)

        for i in range(5):
            base = np.random.choice(G.indices, int(G.n * 0.9), replace=False)
            G.specialize(base)

        data = G.coloring()
        for key in data.keys():
            counts.append(len(data[key]))

        print(G.n)
    plt.hist(counts)
    plt.show()

    # print(G.coloring())
    # G.network_vis()#use_eqp=True)
Пример #3
0
import sys
import os

path = os.getcwd()
sys.path.insert(1, path[:-4])

import core.specializer as s
import numpy as np
from importlib import reload
import networkx as nx
import matplotlib.pyplot as plt
import time
import autograd.numpy as anp
import pickle
from scipy.io import mmread

if __name__ == "__main__":
    # A = mmread('/home/ethan/Research/NetworkSpecialization/data/inf-power/inf-power.mtx')
    A = mmread('../data/inf-power/inf-power.mtx')
    A = A.toarray()
    d = np.zeros_like(A)
    G = s.DirectedGraph(A, d)
    colors = G.coloring()
    with open('colors', 'wb') as out:
        pickle.dump(colors, out)