megnet.layers.graph.megnet module¶
-
class
MEGNetLayer
(units_v, units_e, units_u, pool_method='mean', activation=None, use_bias=True, kernel_initializer='glorot_uniform', bias_initializer='zeros', kernel_regularizer=None, bias_regularizer=None, activity_regularizer=None, kernel_constraint=None, bias_constraint=None, **kwargs)[source]¶ Bases:
megnet.layers.graph.base.GraphNetworkLayer
The MEGNet graph implementation as described in the paper
Chen, Chi; Ye, Weike Ye; Zuo, Yunxing; Zheng, Chen; Ong, Shyue Ping. Graph Networks as a Universal Machine Learning Framework for Molecules and Crystals, 2018, arXiv preprint. [arXiv:1812.05055](https://arxiv.org/abs/1812.05055)
- Parameters
units_v (list of integers) – the hidden layer sizes for node update neural network
units_e (list of integers) – the hidden layer sizes for edge update neural network
units_u (list of integers) – the hidden layer sizes for state update neural network
pool_method (str) – ‘mean’ or ‘sum’, determines how information is gathered to nodes from neighboring edges
activation (str) – Default: None. The activation function used for each sub-neural network. Examples include ‘relu’, ‘softmax’, ‘tanh’, ‘sigmoid’ and etc.
use_bias (bool) – Default: True. Whether to use the bias term in the neural network.
kernel_initializer (str) – Default: ‘glorot_uniform’. Initialization function for the layer kernel weights,
bias_initializer (str) – Default: ‘zeros’
activity_regularizer (str) – Default: None. The regularization function for the output
kernel_constraint (str) – Default: None. Keras constraint for kernel values
bias_constraint (str) – Default: None .Keras constraint for bias values
-
call
(inputs, mask=None)¶ the logic of the layer, returns the final graph
-
compute_output_shape
(input_shape)[source]¶ compute static output shapes, returns list of tuple shapes
-
phi_v
(b_e_p, inputs)[source]¶ update the atom attributes by the results from previous step b_e_p and all the inputs returns v_p.
-
build
(input_shapes)[source]¶ Creates the variables of the layer (optional, for subclass implementers).
This is a method that implementers of subclasses of Layer or Model can override if they need a state-creation step in-between layer instantiation and layer call.
This is typically used to create the weights of Layer subclasses.
- Parameters
input_shape – Instance of TensorShape, or list of instances of TensorShape if the layer expects a list of inputs (one instance per input).
-
compute_output_shape
(input_shape)[source]¶ Computes the output shape of the layer.
If the layer has not been built, this method will call build on the layer. This assumes that the layer will later be used with inputs that match the input shape provided here.
- Parameters
input_shape – Shape tuple (tuple of integers) or list of shape tuples (one per output tensor of the layer). Shape tuples can include None for free dimensions, instead of an integer.
- Returns
An input shape tuple.
-
get_config
()[source]¶ Part of keras layer interface, where the signature is converted into a dict :returns: configurational dictionary
-
phi_e
(inputs)[source]¶ This is for updating the edge attributes ek’ = phi_e(ek, vrk, vsk, u)
- Parameters
inputs (Sequence) – list or tuple for the graph inputs
- Returns
updated edge/bond attributes
-
phi_u
(b_e_p, b_v_p, inputs)[source]¶ u’ = phi_u(ar e’, ar v’, u) :param b_e_p: edge/bond to global aggregated tensor :type b_e_p: tf.Tensor :param b_v_p: node/atom to global aggregated tensor :type b_v_p: tf.Tensor :param inputs: list or tuple for the graph inputs :type inputs: Sequence
- Returns
updated globa/state attributes
-
phi_v
(b_ei_p, inputs)[source]¶ Step 3. Compute updated node attributes v_i’ = phi_v(ar e_i, vi, u)
- Parameters
b_ei_p (tf.Tensor) – edge-to-node aggregated tensor
inputs (Sequence) – list or tuple for the graph inputs
- Returns
updated node/atom attributes
-
rho_e_u
(e_p, inputs)[source]¶ let V’ = {v’} i = 1:Nv let E’ = {(e_k’, rk, sk)} k = 1:Ne ar e’ = rho_e_u(E’)
- Parameters
e_p (tf.Tensor) – updated edge/bond attributes
inputs (Sequence) – list or tuple for the graph inputs
- Returns
edge/bond to global/state aggregated tensor