Beispiel #1
0
""" sbm graph classification """

from Esme.dgms.fil import nodefeat
from Esme.graph.function import fil_strategy
from Esme.graph.generativemodel import sbms
from networkx.linalg.algebraicconnectivity import fiedler_vector

if __name__ == '__main__':
    n = 1
    p, q = 0.5, 0.1
    gs = sbms(n=n, n1=100, n2=50, p=p, q=q)
    for i in range(len(gs)):
        g = gs[i]
        # lapfeat = nodefeat(g, 'fiedler', norm=True)
        nodefeat = fiedler_vector(g, normalized=False)  # np.ndarray
        nodefeat = nodefeat.reshape(len(g), 1)

        gs[i] = fil_strategy(g, nodefeat, method='node', viz_flag=False)

    print('Finish computing lapfeat')
Beispiel #2
0
from Esme.graph.function import fil_strategy
from Esme.graph.generativemodel import sbm2
from Esme.ml.svm import classifier

if __name__ == '__main__':
    radius, zigzag, fil, n1, n2 = 1, True, 'deg', 150, 150
    fil_method = 'combined'
    g, labels = sbm2(n1=n1, n2=n2, p=0.5, q=0.2)

    lp = LaplacianEigenmaps(d=1)
    lp.learn_embedding(g, weight='weight')
    lapfeat = lp.get_embedding()
    lapdist = cdist(lapfeat, lapfeat, metric='euclidean')

    kwargs = {'h': 0.3}
    g = fil_strategy(g, lapfeat, method=fil_method, viz_flag=False, **kwargs)

    ego = egograph(g,
                   radius=radius,
                   n=len(g),
                   recompute_flag=True,
                   norm_flag=True,
                   print_flag=False)
    egographs = ego.egographs(method='serial')
    dgms = alldgms(egographs,
                   radius=radius,
                   dataset='',
                   recompute_flag=True,
                   method='serial',
                   n=n1 + n2,
                   zigzag=zigzag)  # compute dgms in parallel
Beispiel #3
0
    plt.title('p: %s, q: %s' % (p, q))
    for i in range(len(gs)):
        g = gs[i]
        lp = LaplacianEigenmaps(d=1)
        lp.learn_embedding(g, weight='weight')
        lapfeat = lp.get_embedding()  # lapfeat is an array

        # viz = True if i%100==0 else False
        # plt.subplot(2, 1, 1+i//100)
        # plt.plot(lapfeat)
        # plt.show()

        gs[i] = fil_strategy(g,
                             lapfeat,
                             method=fil_method,
                             viz_flag=False,
                             **edge_kwargs)

    # plt.show()
    # sys.exit()
    # plot node fv value
    # viz fv value
    # val = dict(nx.get_node_attributes(gs[i], 'fv')).values()
    # plt.plot(val)
    # plt.title('q: %s, i: %s'%(q, i))
    # plt.show()
    # sys.exit()

    print('Finish computing lapfeat')
    dgms = alldgms(gs,