In [258]:
%load_ext autoreload
%autoreload 2


The autoreload extension is already loaded. To reload it, use:
  %reload_ext autoreload

In [259]:
import networkx as nx
import autograd.numpy as np

from fingerprint import GraphFingerprint, softmax
from wb import WeightsAndBiases

In [260]:
shapes = dict()
shapes[0] = 10
shapes[1] = 10
shapes[2] = 10
wb = WeightsAndBiases(2, shapes)
wb[0]


Out[260]:
{'biases': array([[ 0.55355725,  0.84153394,  0.44207301,  0.77873934,  0.19751991,
          0.91383292,  0.05750184,  0.47897575,  0.98448656,  0.09844382]]),
 'nbr_weights': array([[ 0.39110328,  0.08572476,  0.73628931,  0.16632108,  0.75638455,
          0.60970852,  0.75654198,  0.51632943,  0.45120864,  0.20401733],
        [ 0.58606366,  0.54869377,  0.45139571,  0.01005688,  0.98731473,
          0.71340366,  0.09441683,  0.28936851,  0.77875158,  0.37298274],
        [ 0.61713867,  0.71252774,  0.14483785,  0.08960634,  0.67154464,
          0.10714952,  0.1407363 ,  0.85992033,  0.77445009,  0.44417993],
        [ 0.13136021,  0.8085531 ,  0.60510654,  0.7688252 ,  0.66422755,
          0.58326991,  0.68662313,  0.37612331,  0.4311985 ,  0.34335479],
        [ 0.71726317,  0.89583341,  0.50101567,  0.9388124 ,  0.72539454,
          0.94634312,  0.8839812 ,  0.18530613,  0.44772151,  0.96781432],
        [ 0.17120928,  0.01869977,  0.9849031 ,  0.03539084,  0.96937456,
          0.84774689,  0.91593257,  0.84295919,  0.74559044,  0.76669601],
        [ 0.56694997,  0.0010192 ,  0.5620088 ,  0.85299887,  0.76186684,
          0.25732112,  0.69878158,  0.71907284,  0.36505221,  0.99957877],
        [ 0.62608814,  0.01023978,  0.38433337,  0.84020975,  0.52063994,
          0.56566236,  0.01001864,  0.16604252,  0.39931777,  0.09849357],
        [ 0.92862271,  0.01283916,  0.14627766,  0.89649029,  0.30002507,
          0.7802425 ,  0.91471217,  0.2716025 ,  0.24608592,  0.85346514],
        [ 0.93805783,  0.99754182,  0.38438458,  0.39801116,  0.14563856,
          0.85622908,  0.67972561,  0.96655968,  0.45866084,  0.45037827]]),
 'self_weights': array([[ 0.69917697,  0.00255362,  0.29573018,  0.90427919,  0.37130294,
          0.44136045,  0.25598818,  0.55562718,  0.85093672,  0.90170419],
        [ 0.93727331,  0.83367992,  0.79120832,  0.76595866,  0.16675328,
          0.73342247,  0.14704185,  0.29731308,  0.55467922,  0.03501964],
        [ 0.56075089,  0.94687015,  0.13491993,  0.11786828,  0.62087643,
          0.43760012,  0.3426363 ,  0.88754031,  0.16290503,  0.94273424],
        [ 0.50532243,  0.40012214,  0.14762003,  0.56391942,  0.00207644,
          0.90623115,  0.43615426,  0.90890157,  0.94189778,  0.38302421],
        [ 0.83509285,  0.45554827,  0.26879963,  0.78684659,  0.03203782,
          0.54123352,  0.98759568,  0.02888921,  0.61461851,  0.30920399],
        [ 0.1708622 ,  0.73974972,  0.009563  ,  0.51546106,  0.16571402,
          0.33012926,  0.73829996,  0.97570587,  0.08570992,  0.23281873],
        [ 0.21385738,  0.09227591,  0.78705207,  0.51944924,  0.30948961,
          0.74126403,  0.88602643,  0.43711327,  0.09695114,  0.21191894],
        [ 0.84366859,  0.15736849,  0.06702918,  0.14729606,  0.46706187,
          0.42097786,  0.39947631,  0.44042858,  0.22934905,  0.72145266],
        [ 0.90836055,  0.57817211,  0.26217441,  0.46748608,  0.24511348,
          0.74610513,  0.32050991,  0.64867699,  0.24212034,  0.43652084],
        [ 0.76762563,  0.49659101,  0.474648  ,  0.74772782,  0.09484981,
          0.58170164,  0.70114871,  0.94058508,  0.18137319,  0.89777174]])}

In [261]:
softmax([0.9, 0.1])


Out[261]:
array([ 0.68997448,  0.31002552])

In [262]:
G = nx.read_gpickle('test_data/test_graph.pkl')
# Make A have high feature values.
G.node['A']['features'] = np.random.binomial(1, 0.2, size=10)
G.node['B']['features'] = np.random.binomial(1, 0.2, size=10)
G.node['C']['features'] = np.random.binomial(1, 0.2, size=10)
G.node['D']['features'] = np.random.binomial(1, 0.1, size=10)

In [263]:
len(G.edges())


Out[263]:
4

In [264]:
gcnn = GraphFingerprint(G, 2, wb)

In [265]:
gcnn.layers


Out[265]:
OrderedDict([(0, <networkx.classes.graph.Graph at 0x10d83b668>),
             (1, <networkx.classes.graph.Graph at 0x10d83b2e8>),
             (2, <networkx.classes.graph.Graph at 0x10d83bf60>)])

In [266]:
gcnn.layers[0].nodes(data=True)


Out[266]:
[('D', {'features': array([1, 0, 1, 0, 0, 0, 0, 1, 0, 0])}),
 ('A', {'features': array([0, 0, 0, 0, 0, 0, 1, 0, 0, 0])}),
 ('B', {'features': array([0, 0, 0, 0, 0, 0, 0, 0, 1, 0])}),
 ('C', {'features': array([0, 0, 0, 0, 0, 0, 1, 0, 1, 0])})]

In [267]:
gcnn.layers[0].nodes(data=True)


Out[267]:
[('D', {'features': array([1, 0, 1, 0, 0, 0, 0, 1, 0, 0])}),
 ('A', {'features': array([0, 0, 0, 0, 0, 0, 1, 0, 0, 0])}),
 ('B', {'features': array([0, 0, 0, 0, 0, 0, 0, 0, 1, 0])}),
 ('C', {'features': array([0, 0, 0, 0, 0, 0, 1, 0, 1, 0])})]

In [268]:
gcnn.compute_node_activations(wb)

In [269]:
gcnn.layers[1].nodes(data=True)


Out[269]:
[('D',
  {'features': array([[ 0.12469413,  0.01107716,  0.01959449,  0.09444446,  0.11412571,
            0.14466191,  0.09896684,  0.15444346,  0.02927944,  0.20871242]])}),
 ('A',
  {'features': array([[ 0.08550933,  0.00359055,  0.02143499,  0.09342888,  0.09698345,
            0.46213393,  0.15606869,  0.01469787,  0.02161323,  0.04453908]])}),
 ('B',
  {'features': array([[ 0.1064949 ,  0.01842547,  0.04369408,  0.1320953 ,  0.09564486,
            0.23463598,  0.14183482,  0.12677048,  0.03036481,  0.07003928]])}),
 ('C',
  {'features': array([[ 0.11567104,  0.00349119,  0.01519495,  0.08132479,  0.06758716,
            0.53151116,  0.11728073,  0.01533509,  0.01501711,  0.03758677]])})]

In [270]:
gcnn.compute_fingerprint(wb)


Out[270]:
array([[ 0.08781804,  0.11619792,  0.1229406 ,  0.08990017,  0.08279369,
         0.09902614,  0.09659486,  0.13640186,  0.07418085,  0.09414586]])

In [ ]:


In [ ]: