text stringlengths 1 93.6k |
|---|
for k in xrange(len(adjacency[i][j])):
|
adjacency_pad[i][j][k] = adjacency[i][j][k]
|
dist_pad[i][j][k] = dist[i][j][k]
|
with tf.Session() as sess:
|
sess.run(tf.global_variables_initializer())
|
output = sess.run(
|
pred_op, feed_dict=build_feed_dict(ph, h, adjacency, dist, m))
|
output_pad = sess.run(
|
pred_op,
|
feed_dict=build_feed_dict(ph, h_pad, adjacency_pad, dist_pad, m_pad))
|
print "output no pad:"
|
print output
|
print "\noutput pad:"
|
print output_pad
|
return output, output_pad
|
class MPNNTest(tf.test.TestCase):
|
"""Tests for MPNNs."""
|
def test_build_two_graphs(self):
|
"""Test constructing the MPNN graph."""
|
batch_size = 5
|
num_nodes = 3
|
input_dim = 4
|
output_dim = 6
|
adjacency = np.random.randint(2, size=(batch_size, num_nodes, num_nodes))
|
h = np.random.rand(batch_size, num_nodes, input_dim)
|
dist = np.random.rand(batch_size, num_nodes, num_nodes)
|
m = np.full((batch_size, num_nodes), 1)
|
with tf.Graph().as_default():
|
hparams = mpnn.MPNN.default_hparams()
|
model = mpnn.MPNN(hparams, input_dim, output_dim, num_edge_class=5)
|
ph, _ = model.get_fprop_placeholders()
|
ph2, _ = model.get_fprop_placeholders()
|
print ph[0], ph2[0]
|
pred = model.fprop(*ph, train=True)
|
pred2 = model.fprop(*ph2)
|
with tf.Session() as sess:
|
sess.run(tf.global_variables_initializer())
|
pred1 = sess.run(
|
pred, feed_dict=build_feed_dict(ph, h, adjacency, dist, m))
|
pred2 = sess.run(
|
pred2, feed_dict=build_feed_dict(ph2, h, adjacency, dist, m))
|
self.assertListEqual(list(pred1.shape), [batch_size, output_dim])
|
self.assertListEqual(list(pred2.shape), [batch_size, output_dim])
|
self.assertAllClose(pred1, pred2)
|
print "Successfully constructed MPNN graph."
|
def test_permutation_and_pad_invariance(self):
|
# test GG-NN msg pass + graph level output
|
hparams = mpnn.MPNN.default_hparams()
|
output, output_perm = get_permutation_test_outputs(hparams)
|
self.assertAllClose(output, output_perm)
|
output, output_pad = get_pad_test_outputs(hparams)
|
self.assertAllClose(output, output_pad)
|
# test edge_network message function
|
hparams.message_function = "edge_network"
|
output, output_perm = get_permutation_test_outputs(hparams)
|
self.assertAllClose(output, output_perm)
|
output, output_pad = get_pad_test_outputs(hparams)
|
self.assertAllClose(output, output_pad)
|
# test edge_network + set2vec output
|
hparams.output_function = "set2vec"
|
output, output_perm = get_permutation_test_outputs(hparams)
|
self.assertAllClose(output, output_perm)
|
output, output_pad = get_pad_test_outputs(hparams)
|
self.assertAllClose(output, output_pad)
|
if __name__ == "__main__":
|
tf.test.main()
|
# <FILESEP>
|
"""
|
Copyright 2022 Google LLC
|
Licensed under the Apache License, Version 2.0 (the "License");
|
you may not use this file except in compliance with the License.
|
You may obtain a copy of the License at
|
ERROR: type should be string, got " https://www.apache.org/licenses/LICENSE-2.0\n" |
Unless required by applicable law or agreed to in writing, software
|
distributed under the License is distributed on an "AS IS" BASIS,
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.