Commit 47e44c7d authored by leswing's avatar leswing
Browse files

Documentation update

parent f87fa51a
Loading
Loading
Loading
Loading
+145 −141
Original line number Diff line number Diff line
@@ -296,7 +296,6 @@ class Conv1D(Layer):


class Dense(Layer):

  def __init__(
      self,
      out_channels,
@@ -427,7 +426,6 @@ class Flatten(Layer):


class Reshape(Layer):

  def __init__(self, shape, **kwargs):
    super(Reshape, self).__init__(**kwargs)
    self._new_shape = tuple(-1 if x is None else x for x in shape)
@@ -458,7 +456,6 @@ class Reshape(Layer):


class Squeeze(Layer):

  def __init__(self, in_layers=None, squeeze_dims=None, **kwargs):
    self.squeeze_dims = squeeze_dims
    super(Squeeze, self).__init__(in_layers, **kwargs)
@@ -484,7 +481,6 @@ class Squeeze(Layer):


class Transpose(Layer):

  def __init__(self, perm, **kwargs):
    super(Transpose, self).__init__(**kwargs)
    self.perm = perm
@@ -548,7 +544,6 @@ class CombineMeanStd(Layer):


class Repeat(Layer):

  def __init__(self, n_times, **kwargs):
    self.n_times = n_times
    super(Repeat, self).__init__(**kwargs)
@@ -693,7 +688,6 @@ class GRU(Layer):


class TimeSeriesDense(Layer):

  def __init__(self, out_channels, **kwargs):
    self.out_channels = out_channels
    super(TimeSeriesDense, self).__init__(**kwargs)
@@ -713,7 +707,6 @@ class TimeSeriesDense(Layer):


class Input(Layer):

  def __init__(self, shape, dtype=tf.float32, **kwargs):
    self._shape = tuple(shape)
    self.dtype = dtype
@@ -743,25 +736,21 @@ class Input(Layer):


class Feature(Input):

  def __init__(self, **kwargs):
    super(Feature, self).__init__(**kwargs)


class Label(Input):

  def __init__(self, **kwargs):
    super(Label, self).__init__(**kwargs)


class Weights(Input):

  def __init__(self, **kwargs):
    super(Weights, self).__init__(**kwargs)


class L1Loss(Layer):

  def __init__(self, in_layers=None, **kwargs):
    super(L1Loss, self).__init__(in_layers, **kwargs)

@@ -776,7 +765,6 @@ class L1Loss(Layer):


class L2Loss(Layer):

  def __init__(self, in_layers=None, **kwargs):
    super(L2Loss, self).__init__(in_layers, **kwargs)
    try:
@@ -800,7 +788,6 @@ class L2Loss(Layer):


class SoftMax(Layer):

  def __init__(self, in_layers=None, **kwargs):
    super(SoftMax, self).__init__(in_layers, **kwargs)
    try:
@@ -820,7 +807,6 @@ class SoftMax(Layer):


class Concat(Layer):

  def __init__(self, in_layers=None, axis=1, **kwargs):
    self.axis = axis
    super(Concat, self).__init__(in_layers, **kwargs)
@@ -845,7 +831,6 @@ class Concat(Layer):


class Stack(Layer):

  def __init__(self, in_layers=None, axis=1, **kwargs):
    self.axis = axis
    super(Stack, self).__init__(in_layers, **kwargs)
@@ -1067,7 +1052,6 @@ class InteratomicL2Distances(Layer):


class SparseSoftMaxCrossEntropy(Layer):

  def __init__(self, in_layers=None, **kwargs):
    super(SparseSoftMaxCrossEntropy, self).__init__(in_layers, **kwargs)
    try:
@@ -1089,7 +1073,6 @@ class SparseSoftMaxCrossEntropy(Layer):


class SoftMaxCrossEntropy(Layer):

  def __init__(self, in_layers=None, **kwargs):
    super(SoftMaxCrossEntropy, self).__init__(in_layers, **kwargs)
    try:
@@ -1111,7 +1094,6 @@ class SoftMaxCrossEntropy(Layer):


class ReduceMean(Layer):

  def __init__(self, in_layers=None, axis=None, **kwargs):
    if axis is not None and not isinstance(axis, Sequence):
      axis = [axis]
@@ -1142,7 +1124,6 @@ class ReduceMean(Layer):


class ToFloat(Layer):

  def __init__(self, in_layers=None, **kwargs):
    super(ToFloat, self).__init__(in_layers, **kwargs)
    try:
@@ -1161,7 +1142,6 @@ class ToFloat(Layer):


class ReduceSum(Layer):

  def __init__(self, in_layers=None, axis=None, **kwargs):
    if axis is not None and not isinstance(axis, Sequence):
      axis = [axis]
@@ -1192,7 +1172,6 @@ class ReduceSum(Layer):


class ReduceSquareDifference(Layer):

  def __init__(self, in_layers=None, axis=None, **kwargs):
    if axis is not None and not isinstance(axis, Sequence):
      axis = [axis]
@@ -1378,7 +1357,6 @@ class Conv3D(Layer):


class MaxPool2D(Layer):

  def __init__(self,
               ksize=[1, 2, 2, 1],
               strides=[1, 2, 2, 1],
@@ -1491,7 +1469,6 @@ class InputFifoQueue(Layer):


class GraphConv(Layer):

  def __init__(self,
               out_channel,
               min_deg=0,
@@ -1606,7 +1583,6 @@ class GraphConv(Layer):


class GraphPool(Layer):

  def __init__(self, min_degree=0, max_degree=10, **kwargs):
    self.min_degree = min_degree
    self.max_degree = max_degree
@@ -1655,7 +1631,6 @@ class GraphPool(Layer):


class GraphGather(Layer):

  def __init__(self, batch_size, activation_fn=None, **kwargs):
    self.batch_size = batch_size
    self.activation_fn = activation_fn
@@ -2084,7 +2059,6 @@ class IterRefLSTMEmbedding(Layer):


class BatchNorm(Layer):

  def __init__(self, in_layers=None, **kwargs):
    super(BatchNorm, self).__init__(in_layers, **kwargs)
    try:
@@ -2103,7 +2077,6 @@ class BatchNorm(Layer):


class BatchNormalization(Layer):

  def __init__(self,
               epsilon=1e-5,
               axis=-1,
@@ -2147,7 +2120,6 @@ class BatchNormalization(Layer):


class WeightedError(Layer):

  def __init__(self, in_layers=None, **kwargs):
    super(WeightedError, self).__init__(in_layers, **kwargs)
    self._shape = tuple()
@@ -2597,7 +2569,6 @@ class NeighborList(Layer):


class Dropout(Layer):

  def __init__(self, dropout_prob, **kwargs):
    self.dropout_prob = dropout_prob
    super(Dropout, self).__init__(**kwargs)
@@ -2652,7 +2623,6 @@ class WeightDecay(Layer):


class AtomicConvolution(Layer):

  def __init__(self,
               atom_types=None,
               radial_params=list(),
@@ -3116,8 +3086,18 @@ class BetaShare(Layer):


class PassThroughLayer(Layer):
  """
  Layer which takes a tensor from in_tensor[0].out_tensors at an index
  """

  def __init__(self, output_num, **kwargs):
    """
    Parameters
    ----------
    output_num: int
      The index which to use as this layers out_tensor from in_layers[0]
    kwargs
    """
    self.output_num = output_num
    super(PassThroughLayer, self).__init__(**kwargs)

@@ -3125,15 +3105,26 @@ class PassThroughLayer(Layer):
    self.out_tensor = self.in_layers[0].out_tensors[self.output_num]


class GraphCNNPoolLayer(Layer):
class GraphEmbedPoolLayer(Layer):
  """
  GraphCNNPool Layer from Robust Spatial Filtering with Graph Convolutional Neural Networks
  https://arxiv.org/abs/1703.00792

  This is a learnable pool operation
  It constructs a new adjacency matrix for a graph of specified number of nodes.

  This differs from our other pool opertions which set vertices to a function value
  without altering the adjacency matrix.

  $V_{emb} = SpatialGraphCNN({V_{in}})$\\
  $V_{out} = \sigma(V_{emb})^{T} * V_{in}$
  $A_{out} = V_{emb}^{T} * A_{in} * V_{emb}$

  """

  def __init__(self, num_vertices, **kwargs):
    self.num_vertices = num_vertices
    super(GraphCNNPoolLayer, self).__init__(**kwargs)
    super(GraphEmbedPoolLayer, self).__init__(**kwargs)

  def create_tensor(self, in_layers=None, set_tensors=True, **kwargs):
    """
@@ -3180,7 +3171,7 @@ class GraphCNNPoolLayer(Layer):
                                     A.get_shape()[2].value, self.num_vertices))
    # We do not need the mask because every graph has self.num_vertices vertices now
    if set_tensors:
      self.out_tensor = result
      self.out_tensor = result[0]
    self.out_tensors = [result, result_A]
    return result, result_A

@@ -3218,7 +3209,7 @@ class GraphCNNPoolLayer(Layer):


def GraphCNNPool(num_vertices, **kwargs):
  gcnnpool_layer = GraphCNNPoolLayer(num_vertices, **kwargs)
  gcnnpool_layer = GraphEmbedPoolLayer(num_vertices, **kwargs)
  return [PassThroughLayer(x, in_layers=gcnnpool_layer) for x in range(2)]


@@ -3226,6 +3217,19 @@ class GraphCNN(Layer):
  """
  GraphCNN Layer from Robust Spatial Filtering with Graph Convolutional Neural Networks
  https://arxiv.org/abs/1703.00792

  Spatial-domain convolutions can be defined as
  H = h_0I + h_1A + h_2A^2 + ... + hkAk, H ∈ R**(N×N)

  We approximate it by
  H ≈ h_0I + h_1A

  We can define a convolution as applying multiple these linear filters
  over edges of different types (think up, down, left, right, diagonal in images)
  Where each edge type has its own adjacency matrix
  H ≈ h_0I + h_1A_1 + h_2A_2 + . . . h_(L−1)A_(L−1)

  V_out = \sum_{c=1}^{C} H^{c} V^{c} + b
  """

  def __init__(self, num_filters, **kwargs):
+2 −2
Original line number Diff line number Diff line
@@ -5,7 +5,7 @@ from tensorflow.python.framework import test_util

from deepchem.feat.graph_features import ConvMolFeaturizer
from deepchem.feat.mol_graphs import ConvMol
from deepchem.models.tensorgraph.layers import Add, Conv3D, MaxPool2D, MaxPool3D, GraphCNN, GraphCNNPoolLayer
from deepchem.models.tensorgraph.layers import Add, Conv3D, MaxPool2D, MaxPool3D, GraphCNN, GraphEmbedPoolLayer
from deepchem.models.tensorgraph.layers import AlphaShareLayer
from deepchem.models.tensorgraph.layers import AttnLSTMEmbedding
from deepchem.models.tensorgraph.layers import BatchNorm
@@ -739,7 +739,7 @@ class TestLayers(test_util.TensorFlowTestCase):
    V = np.random.uniform(size=(10, 100, 50)).astype(np.float32)
    adjs = np.random.uniform(size=(10, 100, 5, 100)).astype(np.float32)
    with self.test_session() as sess:
      vertex_props, adjs = GraphCNNPoolLayer(num_vertices=6)(V, adjs)
      vertex_props, adjs = GraphEmbedPoolLayer(num_vertices=6)(V, adjs)
      sess.run(tf.global_variables_initializer())
      vertex_props, adjs = vertex_props.eval(), adjs.eval()
      assert vertex_props.shape == (10, 6, 50)
+2 −2
Original line number Diff line number Diff line
@@ -11,7 +11,7 @@ from deepchem.models.tensorgraph.layers import Feature, Conv1D, Dense, Flatten,
  SoftMaxCrossEntropy, ReduceMean, ToFloat, ReduceSquareDifference, Conv2D, MaxPool2D, ReduceSum, GraphConv, GraphPool, \
  GraphGather, BatchNorm, WeightedError, \
  Conv3D, MaxPool3D, \
  LSTMStep, AttnLSTMEmbedding, IterRefLSTMEmbedding, GraphCNNPoolLayer, GraphCNN
  LSTMStep, AttnLSTMEmbedding, IterRefLSTMEmbedding, GraphEmbedPoolLayer, GraphCNN
from deepchem.models.tensorgraph.symmetry_functions import AtomicDifferentiatedDense


@@ -584,7 +584,7 @@ def testGraphCNN_pickle():
def testGraphCNNPoolLayer_pickle():
  V = Feature(shape=(None, 200, 50))
  A = Feature(shape=(None, 200, 1, 200))
  gcnnpool = GraphCNNPoolLayer(32, in_layers=[V, A])
  gcnnpool = GraphEmbedPoolLayer(32, in_layers=[V, A])
  tg = TensorGraph()
  tg.add_output(gcnnpool)
  tg.set_loss(gcnnpool)