def __init__(self, num_nodes, num_node_features, batch_size=64, init='glorot_uniform', combine_method='linear', **kwargs): """ Parameters ---------- num_nodes: int Number of nodes in the graph num_node_features: int Number of features per node in the graph batch_size: int, optional Batch size used for training init: str, optional Initialization method for the weights combine_method: str, optional How to combine adjacency matrix and node features """ if combine_method not in ['linear', 'prod']: raise ValueError( 'Combine method needs to be one of linear or product') self.num_nodes = num_nodes self.num_node_features = num_node_features self.batch_size = batch_size self.init = initializations.get(init) self.combine_method = combine_method super(AdaptiveFilter, self).__init__(**kwargs)
def __init__(self, num_nodes, num_node_features, batch_size=64, init='glorot_uniform', combine_method='linear', **kwargs): """ Parameters ---------- num_nodes: int Number of nodes in the graph num_node_features: int Number of features per node in the graph batch_size: int, optional Batch size used for training init: str, optional Initialization method for the weights combine_method: str, optional How to combine adjacency matrix and node features """ if combine_method not in ['linear', 'prod']: raise ValueError('Combine method needs to be one of linear or product') self.num_nodes = num_nodes self.num_node_features = num_node_features self.batch_size = batch_size self.init = initializations.get(init) self.combine_method = combine_method super(AdaptiveFilter, self).__init__(**kwargs)
def __init__(self, num_nodes, num_node_features, batch_size=64, init='glorot_uniform', **kwargs): """ Parameters ---------- num_nodes: int Number of nodes in the graph num_node_features: int Number of features per node in the graph batch_size: int, optional Batch size used for training init: str, optional Initialization method for the weights combine_method: str, optional How to combine adjacency matrix and node features """ self.num_nodes = num_nodes self.num_node_features = num_node_features self.batch_size = batch_size self.init = initializations.get(init) super(KOrderGraphConv, self).__init__(**kwargs)
def __init__(self, n_embedding=30, n_distance=100, n_hidden=60, init='glorot_uniform', activation='tanh', **kwargs): """ Parameters ---------- n_embedding: int, optional Number of features for each atom n_distance: int, optional granularity of distance matrix n_hidden: int, optional Number of nodes in hidden layer init: str, optional Weight initialization for filters. activation: str, optional Activation function applied """ self.n_embedding = n_embedding self.n_distance = n_distance self.n_hidden = n_hidden self.init = initializations.get(init) # Set weight initialization self.activation = activations.get(activation) # Get activations super(DTNNStep, self).__init__(**kwargs)
def __init__(self, n_embedding=30, n_distance=100, n_hidden=60, init='glorot_uniform', activation='tanh', **kwargs): """ Parameters ---------- n_embedding: int, optional Number of features for each atom n_distance: int, optional granularity of distance matrix n_hidden: int, optional Number of nodes in hidden layer init: str, optional Weight initialization for filters. activation: str, optional Activation function applied """ self.n_embedding = n_embedding self.n_distance = n_distance self.n_hidden = n_hidden self.init = initializations.get(init) # Set weight initialization self.activation = activations.get(activation) # Get activations super(DTNNStep, self).__init__(**kwargs)
def __init__(self, n_embedding=30, n_outputs=100, layer_sizes=[100], output_activation=True, init='glorot_uniform', activation='tanh', **kwargs): """ Parameters ---------- n_embedding: int, optional Number of features for each atom n_outputs: int, optional Number of features for each molecule(output) layer_sizes: list of int, optional(default=[1000]) Structure of hidden layer(s) init: str, optional Weight initialization for filters. activation: str, optional Activation function applied """ self.n_embedding = n_embedding self.n_outputs = n_outputs self.layer_sizes = layer_sizes self.output_activation = output_activation self.init = initializations.get(init) # Set weight initialization self.activation = activations.get(activation) # Get activations super(DTNNGather, self).__init__(**kwargs)
def __init__(self, n_embedding=30, n_outputs=100, layer_sizes=[100], output_activation=True, init='glorot_uniform', activation='tanh', **kwargs): """ Parameters ---------- n_embedding: int, optional Number of features for each atom n_outputs: int, optional Number of features for each molecule(output) layer_sizes: list of int, optional(default=[1000]) Structure of hidden layer(s) init: str, optional Weight initialization for filters. activation: str, optional Activation function applied """ self.n_embedding = n_embedding self.n_outputs = n_outputs self.layer_sizes = layer_sizes self.output_activation = output_activation self.init = initializations.get(init) # Set weight initialization self.activation = activations.get(activation) # Get activations super(DTNNGather, self).__init__(**kwargs)
def __init__(self, batch_size, n_input=128, gaussian_expand=False, init='glorot_uniform', activation='tanh', epsilon=1e-3, momentum=0.99, **kwargs): """ Parameters ---------- batch_size: int number of molecules in a batch n_input: int, optional number of features for each input molecule gaussian_expand: boolean. optional Whether to expand each dimension of atomic features by gaussian histogram init: str, optional Weight initialization for filters. activation: str, optional Activation function applied """ self.n_input = n_input self.batch_size = batch_size self.gaussian_expand = gaussian_expand self.init = initializations.get(init) # Set weight initialization self.activation = activations.get(activation) # Get activations self.epsilon = epsilon self.momentum = momentum self.W, self.b = None, None super(WeaveGather, self).__init__(**kwargs)
def __init__(self, batch_size, n_input=128, gaussian_expand=False, init='glorot_uniform', activation='tanh', epsilon=1e-3, momentum=0.99, **kwargs): """ Parameters ---------- batch_size: int number of molecules in a batch n_input: int, optional number of features for each input molecule gaussian_expand: boolean. optional Whether to expand each dimension of atomic features by gaussian histogram init: str, optional Weight initialization for filters. activation: str, optional Activation function applied """ self.n_input = n_input self.batch_size = batch_size self.gaussian_expand = gaussian_expand self.init = initializations.get(init) # Set weight initialization self.activation = activations.get(activation) # Get activations self.epsilon = epsilon self.momentum = momentum self.W, self.b = None, None super(WeaveGather, self).__init__(**kwargs)
def __init__(self, num_nodes, num_node_features, batch_size=64, init='glorot_uniform', **kwargs): """ Parameters ---------- num_nodes: int Number of nodes in the graph num_node_features: int Number of features per node in the graph batch_size: int, optional Batch size used for training init: str, optional Initialization method for the weights combine_method: str, optional How to combine adjacency matrix and node features """ self.num_nodes = num_nodes self.num_node_features = num_node_features self.batch_size = batch_size self.init = initializations.get(init) super(KOrderGraphConv, self).__init__(**kwargs)
def __init__(self, n_hidden=100, init='glorot_uniform'): self.n_hidden = n_hidden self.init = initializations.get(init) Wz = self.init([n_hidden, n_hidden]) Wr = self.init([n_hidden, n_hidden]) Wh = self.init([n_hidden, n_hidden]) Uz = self.init([n_hidden, n_hidden]) Ur = self.init([n_hidden, n_hidden]) Uh = self.init([n_hidden, n_hidden]) bz = model_ops.zeros(shape=(n_hidden,)) br = model_ops.zeros(shape=(n_hidden,)) bh = model_ops.zeros(shape=(n_hidden,)) self.trainable_weights = [Wz, Wr, Wh, Uz, Ur, Uh, bz, br, bh]
def __init__(self, pair_features, n_pair_features=8, n_hidden=100, init='glorot_uniform'): self.n_pair_features = n_pair_features self.n_hidden = n_hidden self.init = initializations.get(init) W = self.init([n_pair_features, n_hidden * n_hidden]) b = model_ops.zeros(shape=(n_hidden * n_hidden,)) self.A = tf.nn.xw_plus_b(pair_features, W, b) self.A = tf.reshape(self.A, (-1, n_hidden, n_hidden)) self.trainable_weights = [W, b]
def __init__(self, pair_features, n_pair_features=8, n_hidden=100, init='glorot_uniform'): self.n_pair_features = n_pair_features self.n_hidden = n_hidden self.init = initializations.get(init) W = self.init([n_pair_features, n_hidden * n_hidden]) b = model_ops.zeros(shape=(n_hidden * n_hidden,)) self.A = tf.nn.xw_plus_b(pair_features, W, b) self.A = tf.reshape(self.A, (-1, n_hidden, n_hidden)) self.trainable_weights = [W, b]
def __init__(self, n_hidden=100, init='glorot_uniform'): self.n_hidden = n_hidden self.init = initializations.get(init) Wz = self.init([n_hidden, n_hidden]) Wr = self.init([n_hidden, n_hidden]) Wh = self.init([n_hidden, n_hidden]) Uz = self.init([n_hidden, n_hidden]) Ur = self.init([n_hidden, n_hidden]) Uh = self.init([n_hidden, n_hidden]) bz = model_ops.zeros(shape=(n_hidden,)) br = model_ops.zeros(shape=(n_hidden,)) bh = model_ops.zeros(shape=(n_hidden,)) self.trainable_weights = [Wz, Wr, Wh, Uz, Ur, Uh, bz, br, bh]
def create_tensor(self, in_layers=None, set_tensors=True, **kwargs): """ Generate Radial Symmetry Function """ init_fn = initializations.get(self.init) # Set weight initialization if self.activation == 'ani': activation_fn = self.ani_activate else: activation_fn = activations.get(self.activation) if in_layers is None: in_layers = self.in_layers in_layers = convert_to_layers(in_layers) inputs = in_layers[0].out_tensor atom_numbers = in_layers[1].out_tensor in_channels = inputs.get_shape().as_list()[-1] self.W = init_fn( [len(self.atom_number_cases), in_channels, self.out_channels]) self.b = model_ops.zeros( (len(self.atom_number_cases), self.out_channels)) outputs = [] for i, atom_case in enumerate(self.atom_number_cases): # optimization to allow for tensorcontraction/broadcasted mmul # using a reshape trick. Note that the np and tf matmul behavior # differs when dealing with broadcasts a = inputs # (i,j,k) b = self.W[i, :, :] # (k, l) ai = tf.shape(a)[0] aj = tf.shape(a)[1] ak = tf.shape(a)[2] bl = tf.shape(b)[1] output = activation_fn( tf.reshape(tf.matmul(tf.reshape(a, [ai * aj, ak]), b), [ai, aj, bl]) + self.b[i, :]) mask = 1 - tf.cast(tf.cast(atom_numbers - atom_case, tf.bool), tf.float32) output = tf.reshape(output * tf.expand_dims(mask, 2), (-1, self.max_atoms, self.out_channels)) outputs.append(output) out_tensor = tf.add_n(outputs) if set_tensors: self.out_tensor = out_tensor return out_tensor
def __init__(self, M, batch_size, n_hidden=100, init='orthogonal', **kwargs): """ Parameters ---------- M: int Number of LSTM steps batch_size: int Number of samples in a batch(all batches must have same size) n_hidden: int, optional number of hidden units in the passing phase """ self.M = M self.batch_size = batch_size self.n_hidden = n_hidden self.init = initializations.get(init) super(SetGather, self).__init__(**kwargs)
def __init__(self, M, batch_size, n_hidden=100, init='orthogonal', **kwargs): """ Parameters ---------- M: int Number of LSTM steps batch_size: int Number of samples in a batch(all batches must have same size) n_hidden: int, optional number of hidden units in the passing phase """ self.M = M self.batch_size = batch_size self.n_hidden = n_hidden self.init = initializations.get(init) super(SetGather, self).__init__(**kwargs)
def create_tensor(self, in_layers=None, set_tensors=True, **kwargs): """ Generate Radial Symmetry Function """ init_fn = initializations.get(self.init) # Set weight initialization if self.activation == 'ani': activation_fn = self.ani_activate else: activation_fn = activations.get(self.activation) if in_layers is None: in_layers = self.in_layers in_layers = convert_to_layers(in_layers) inputs = in_layers[0].out_tensor atom_numbers = in_layers[1].out_tensor in_channels = inputs.get_shape().as_list()[-1] self.W = init_fn( [len(self.atom_number_cases), in_channels, self.out_channels]) self.b = model_ops.zeros((len(self.atom_number_cases), self.out_channels)) outputs = [] for i, atom_case in enumerate(self.atom_number_cases): # optimization to allow for tensorcontraction/broadcasted mmul # using a reshape trick. Note that the np and tf matmul behavior # differs when dealing with broadcasts a = inputs # (i,j,k) b = self.W[i, :, :] # (k, l) ai = tf.shape(a)[0] aj = tf.shape(a)[1] ak = tf.shape(a)[2] bl = tf.shape(b)[1] output = activation_fn( tf.reshape(tf.matmul(tf.reshape(a, [ai * aj, ak]), b), [ai, aj, bl]) + self.b[i, :]) mask = 1 - tf.cast(tf.cast(atom_numbers - atom_case, tf.bool), tf.float32) output = tf.reshape(output * tf.expand_dims(mask, 2), (-1, self.max_atoms, self.out_channels)) outputs.append(output) out_tensor = tf.add_n(outputs) if set_tensors: self.out_tensor = out_tensor return out_tensor
def __init__(self, n_graph_feat=30, n_atom_feat=75, max_atoms=50, layer_sizes=[100], init='glorot_uniform', activation='relu', dropout=None, batch_size=64, **kwargs): """ Parameters ---------- n_graph_feat: int, optional Number of features for each node(and the whole grah). n_atom_feat: int, optional Number of features listed per atom. max_atoms: int, optional Maximum number of atoms in molecules. layer_sizes: list of int, optional(default=[100]) List of hidden layer size(s): length of this list represents the number of hidden layers, and each element is the width of corresponding hidden layer. init: str, optional Weight initialization for filters. activation: str, optional Activation function applied. dropout: float, optional Dropout probability in hidden layer(s). batch_size: int, optional number of molecules in a batch. """ super(DAGLayer, self).__init__(**kwargs) self.init = initializations.get(init) # Set weight initialization self.activation = activations.get(activation) # Get activations self.layer_sizes = layer_sizes self.dropout = dropout self.max_atoms = max_atoms self.batch_size = batch_size self.n_inputs = n_atom_feat + (self.max_atoms - 1) * n_graph_feat # number of inputs each step self.n_graph_feat = n_graph_feat self.n_outputs = n_graph_feat self.n_atom_feat = n_atom_feat
def __init__(self, n_graph_feat=30, n_atom_feat=75, max_atoms=50, layer_sizes=[100], init='glorot_uniform', activation='relu', dropout=None, batch_size=64, **kwargs): """ Parameters ---------- n_graph_feat: int, optional Number of features for each node(and the whole grah). n_atom_feat: int, optional Number of features listed per atom. max_atoms: int, optional Maximum number of atoms in molecules. layer_sizes: list of int, optional(default=[100]) List of hidden layer size(s): length of this list represents the number of hidden layers, and each element is the width of corresponding hidden layer. init: str, optional Weight initialization for filters. activation: str, optional Activation function applied. dropout: float, optional Dropout probability in hidden layer(s). batch_size: int, optional number of molecules in a batch. """ super(DAGLayer, self).__init__(**kwargs) self.init = initializations.get(init) # Set weight initialization self.activation = activations.get(activation) # Get activations self.layer_sizes = layer_sizes self.dropout = dropout self.max_atoms = max_atoms self.batch_size = batch_size self.n_inputs = n_atom_feat + (self.max_atoms - 1) * n_graph_feat # number of inputs each step self.n_graph_feat = n_graph_feat self.n_outputs = n_graph_feat self.n_atom_feat = n_atom_feat
def build(self): """ Construct internal trainable weights. TODO(rbharath): Need to make this not set instance variables to follow style in other layers. """ init = initializations.get(self.init) # Set weight initialization self.W_AA = init([self.n_atom_input_feat, self.n_hidden_AA]) self.b_AA = model_ops.zeros(shape=[ self.n_hidden_AA, ]) self.W_PA = init([self.n_pair_input_feat, self.n_hidden_PA]) self.b_PA = model_ops.zeros(shape=[ self.n_hidden_PA, ]) self.W_A = init([self.n_hidden_A, self.n_atom_output_feat]) self.b_A = model_ops.zeros(shape=[ self.n_atom_output_feat, ]) self.trainable_weights = [ self.W_AA, self.b_AA, self.W_PA, self.b_PA, self.W_A, self.b_A ] if self.update_pair: self.W_AP = init([self.n_atom_input_feat * 2, self.n_hidden_AP]) self.b_AP = model_ops.zeros(shape=[ self.n_hidden_AP, ]) self.W_PP = init([self.n_pair_input_feat, self.n_hidden_PP]) self.b_PP = model_ops.zeros(shape=[ self.n_hidden_PP, ]) self.W_P = init([self.n_hidden_P, self.n_pair_output_feat]) self.b_P = model_ops.zeros(shape=[ self.n_pair_output_feat, ]) self.trainable_weights.extend([ self.W_AP, self.b_AP, self.W_PP, self.b_PP, self.W_P, self.b_P ])
def build(self): """ Construct internal trainable weights. TODO(rbharath): Need to make this not set instance variables to follow style in other layers. """ init = initializations.get(self.init) # Set weight initialization self.W_AA = init([self.n_atom_input_feat, self.n_hidden_AA]) self.b_AA = model_ops.zeros(shape=[ self.n_hidden_AA, ]) self.W_PA = init([self.n_pair_input_feat, self.n_hidden_PA]) self.b_PA = model_ops.zeros(shape=[ self.n_hidden_PA, ]) self.W_A = init([self.n_hidden_A, self.n_atom_output_feat]) self.b_A = model_ops.zeros(shape=[ self.n_atom_output_feat, ]) self.trainable_weights = [ self.W_AA, self.b_AA, self.W_PA, self.b_PA, self.W_A, self.b_A ] if self.update_pair: self.W_AP = init([self.n_atom_input_feat * 2, self.n_hidden_AP]) self.b_AP = model_ops.zeros(shape=[ self.n_hidden_AP, ]) self.W_PP = init([self.n_pair_input_feat, self.n_hidden_PP]) self.b_PP = model_ops.zeros(shape=[ self.n_hidden_PP, ]) self.W_P = init([self.n_hidden_P, self.n_pair_output_feat]) self.b_P = model_ops.zeros(shape=[ self.n_pair_output_feat, ]) self.trainable_weights.extend( [self.W_AP, self.b_AP, self.W_PP, self.b_PP, self.W_P, self.b_P])
def __init__(self, n_embedding=30, periodic_table_length=30, init='glorot_uniform', **kwargs): """ Parameters ---------- n_embedding: int, optional Number of features for each atom periodic_table_length: int, optional Length of embedding, 83=Bi init: str, optional Weight initialization for filters. """ self.n_embedding = n_embedding self.periodic_table_length = periodic_table_length self.init = initializations.get(init) # Set weight initialization super(DTNNEmbedding, self).__init__(**kwargs)
def __init__(self, n_embedding=30, periodic_table_length=30, init='glorot_uniform', **kwargs): """ Parameters ---------- n_embedding: int, optional Number of features for each atom periodic_table_length: int, optional Length of embedding, 83=Bi init: str, optional Weight initialization for filters. """ self.n_embedding = n_embedding self.periodic_table_length = periodic_table_length self.init = initializations.get(init) # Set weight initialization super(DTNNEmbedding, self).__init__(**kwargs)
def __init__(self, n_graph_feat=30, n_outputs=30, max_atoms=50, layer_sizes=[100], init='glorot_uniform', activation='relu', dropout=None, **kwargs): """ Parameters ---------- n_graph_feat: int, optional Number of features for each atom. n_outputs: int, optional Number of features for each molecule. max_atoms: int, optional Maximum number of atoms in molecules. layer_sizes: list of int, optional List of hidden layer size(s): length of this list represents the number of hidden layers, and each element is the width of corresponding hidden layer. init: str, optional Weight initialization for filters. activation: str, optional Activation function applied. dropout: float, optional Dropout probability in the hidden layer(s). """ super(DAGGather, self).__init__(**kwargs) self.init = initializations.get(init) # Set weight initialization self.activation = activations.get(activation) # Get activations self.layer_sizes = layer_sizes self.dropout = dropout self.max_atoms = max_atoms self.n_graph_feat = n_graph_feat self.n_outputs = n_outputs
def __init__(self, n_graph_feat=30, n_outputs=30, max_atoms=50, layer_sizes=[100], init='glorot_uniform', activation='relu', dropout=None, **kwargs): """ Parameters ---------- n_graph_feat: int, optional Number of features for each atom. n_outputs: int, optional Number of features for each molecule. max_atoms: int, optional Maximum number of atoms in molecules. layer_sizes: list of int, optional List of hidden layer size(s): length of this list represents the number of hidden layers, and each element is the width of corresponding hidden layer. init: str, optional Weight initialization for filters. activation: str, optional Activation function applied. dropout: float, optional Dropout probability in the hidden layer(s). """ super(DAGGather, self).__init__(**kwargs) self.init = initializations.get(init) # Set weight initialization self.activation = activations.get(activation) # Get activations self.layer_sizes = layer_sizes self.dropout = dropout self.max_atoms = max_atoms self.n_graph_feat = n_graph_feat self.n_outputs = n_outputs
def __init__(self, n_graph_feat=30, n_outputs=30, max_atoms=50, layer_sizes=[100], init='glorot_uniform', activation='relu', dropout=None, **kwargs): """ Parameters ---------- n_graph_feat: int, optional Number of features for each atom n_outputs: int, optional Number of features for each molecule. max_atoms: int, optional Maximum number of atoms in molecules. layer_sizes: list of int, optional Structure of hidden layer(s) init: str, optional Weight initialization for filters. activation: str, optional Activation function applied dropout: float, optional Dropout probability, not supported """ super(DAGGather, self).__init__(**kwargs) self.init = initializations.get(init) # Set weight initialization self.activation = activations.get(activation) # Get activations self.layer_sizes = layer_sizes self.dropout = dropout self.max_atoms = max_atoms self.n_graph_feat = n_graph_feat self.n_outputs = n_outputs