def test_qm9(): adj, nf, ef, labels = qm9.load_data('numpy', amount=1000) correctly_padded(adj, nf, ef) assert adj.shape[0] == labels.shape[0] # Test that it doesn't crash qm9.load_data('networkx', amount=1000) qm9.load_data('sdf', amount=1000)
def test_qm9(): adj, nf, ef, labels = qm9.load_data('numpy') correctly_padded(adj, nf, ef) assert adj.shape[-1] == qm9.MAX_K assert adj.shape[0] == labels.shape[0] # Test that it doesn't crash qm9.load_data('networkx') qm9.load_data('sdf')
def test_nap(): adj, nf, ef, labels = qm9.load_data('numpy', amount=1000) N = nf.shape[-2] F = nf.shape[-1] model = Sequential() model.add(NodeAttentionPool(input_shape=(N, F))) assert model.output_shape == (None, F)
def test_gap(): adj, nf, ef, labels = qm9.load_data('numpy', amount=1000) N = nf.shape[-2] F = nf.shape[-1] channels_out = 32 model = Sequential() model.add(GlobalAttentionPool(channels_out, input_shape=(N, F))) assert model.output_shape == (None, channels_out)
from spektral.layers import EdgeConditionedConv, GlobalSumPool from spektral.utils import label_to_one_hot ################################################################################ # PARAMETERS ################################################################################ learning_rate = 1e-3 # Learning rate epochs = 10 # Number of training epochs batch_size = 32 # Batch size ################################################################################ # LOAD DATA ################################################################################ A, X, E, y = qm9.load_data(return_type='numpy', nf_keys='atomic_num', ef_keys='type', self_loops=True, amount=1000) # Set to None to train on whole dataset y = y[['cv']].values # Heat capacity at 298.15K # Preprocessing X_uniq = np.unique(X) X_uniq = X_uniq[X_uniq != 0] E_uniq = np.unique(E) E_uniq = E_uniq[E_uniq != 0] X = label_to_one_hot(X, X_uniq) E = label_to_one_hot(E, E_uniq) # Parameters N = X.shape[-2] # Number of nodes in the graphs
import tensorflow as tf from keras.layers import Input, Dense from keras.models import Model from keras.optimizers import Adam from sklearn.model_selection import train_test_split from sklearn.preprocessing import StandardScaler from spektral.datasets import qm9 from spektral.layers import GraphConv, GlobalAvgPool from spektral.utils import Batch, batch_iterator from spektral.utils import label_to_one_hot # Load data A, X, _, y = qm9.load_data(return_type='numpy', nf_keys='atomic_num', ef_keys='type', self_loops=True, auto_pad=False, amount=1000) y = y[['cv']].values # Heat capacity at 298.15K # Preprocessing uniq_X = np.unique([v for x in X for v in np.unique(x)]) X = [label_to_one_hot(x, uniq_X) for x in X] y = StandardScaler().fit_transform(y).reshape(-1, y.shape[-1]) # Parameters F = X[0].shape[-1] # Dimension of node features n_out = y.shape[-1] # Dimension of the target learning_rate = 1e-3 # Learning rate epochs = 25 # Number of training epochs batch_size = 64 # Batch size
import matplotlib.pyplot as plt import numpy as np from keras.callbacks import EarlyStopping from keras.layers import Input, Dense from keras.models import Model from keras.optimizers import Adam from sklearn.model_selection import train_test_split from sklearn.preprocessing import StandardScaler from spektral.datasets import qm9 from spektral.layers import EdgeConditionedConv, GlobalAttentionPool from spektral.utils import init_logging, label_to_one_hot # Load data adj, nf, ef, y = qm9.load_data(return_type='numpy', nf_keys='atomic_num', ef_keys='type', self_loops=True) y = y[['cv']].values # Heat capacity at 298.15K # Preprocessing uniq_nf = np.unique(nf) nf = label_to_one_hot(nf, uniq_nf) uniq_ef = np.unique(ef) ef = label_to_one_hot(ef, uniq_ef) y = StandardScaler().fit_transform(y).reshape(-1, y.shape[-1]) # Parameters N = nf.shape[-2] # Number of nodes in the graphs F = nf.shape[-1] # Node features dimensionality S = ef.shape[-1] # Edge features dimensionality n_out = y.shape[-1] # Dimensionality of the target
# %% ################################################################################ # PARAMETERS ################################################################################ learning_rate = 1e-3 # Learning rate epochs = 10 # Number of training epochs batch_size = 32 # Batch size # %% ################################################################################ # LOAD DATA ################################################################################ A, X, E, y = qm9.load_data( return_type="numpy", nf_keys="atomic_num", ef_keys="type", self_loops=True, amount=1000, ) # Set to None to train on whole dataset y = y[["cv"]].values # Heat capacity at 298.15K # %% # Preprocessing X_uniq = np.unique(X) X_uniq = X_uniq[X_uniq != 0] E_uniq = np.unique(E) E_uniq = E_uniq[E_uniq != 0] X = label_to_one_hot(X, X_uniq) E = label_to_one_hot(E, E_uniq)