Module connectome.models.brainnet_cnn
prepares the data for the CNN and trains the CNN
Functions
def augmented_data(x: pandas.core.frame.DataFrame, y: pandas.core.series.Series, X_img_cols: list, X_struc_cols: list, sd=0.17, augm_fact=5)-
Applies data augmentation to an input dataframe
Args
x- input dataframe to be augmented
y- labels
aggregation- Boolean, whether the matrices were aggregated based on yeo7
reorder- Boolean, whether to reorder the matrices based on the yeo7 network. (True is recommended when training with Brainnetome data. Only applicable to data based on the brainnetome atlas.
sd- Standard deviation of the random noise to be applied for data augmentation
augm_fact- Augmentation factor, Size of train dataset = original train dataset + augm_fact * noise dataset:
Returns
x_aug- augmented connectivity matrices
x_struc_aug- augmented structural information such as e.g. age etc.
y_aug- augmented dataset labels
def brain_net_cnn(input_dim_img, input_dim_struc, output_dim: int = 1, E2E_filter: int = 32, E2N_filter: int = 48, N2G_tiler: int = 64, dense_filter: int = 64, dropout_rate=0.5, kernel_regularizer=<keras.regularizers.L2 object>, kernel_initializer='he_uniform', opt=<keras.optimizer_v2.adam.Adam object>, activation='relu', loss='binary_crossentropy')-
Trains a Convolutional Neural Network model based on the design by Kawahara et al. (2016) http://doi.org/10.1016/j.neuroimage.2016.09.046.
Args
input_dim_img- Input dimension of the connectivity matrices
input_dim_struc- Input dimension of the structural information
output_dim- Output dimension for the neural network
E2E_filter- Number of E2E filters, for a detailed description check out: https://kawahara.ca/convolutional-neural-networks-for-adjacency-matrices/
E2N_filter- Number of E2N filters, for a detailed description check out: https://kawahara.ca/convolutional-neural-networks-for-adjacency-matrices/
N2G_tiler- Number of N2G filters , for a detailed description check out: https://kawahara.ca/convolutional-neural-networks-for-adjacency-matrices/
dense_filter- Dense layer size, default 64
dropout_rate- Size of nodes to randomly drop during training, default .5
kernel_regularizer- Layer weight regularizers to be applied, default l2 regularization
kernel_initializer- Kernel initilization strategy, default he_uniform
optimizer- Method to train the model, default Adam
activation- Hidden layer activation, default relu
loss- loss function, default binary_crossentropy
Returns
A fitted neural network model
def model_brainnet_cnn(X, y, aggregation=False, reorder=False, augmentation=False, scale=0.04, augm_fact=5, batch_size=32, epochs=400, patience=5, validation_size=0.2, E2E_filter: int = 32, E2N_filter: int = 48, N2G_tiler: int = 64, dense_filter: int = 64, dropout_rate=0.5, kernel_regularizer=<keras.regularizers.L2 object>, kernel_initializer='he_uniform', optimizer=<keras.optimizer_v2.adam.Adam object>, activation='relu', loss='binary_crossentropy')-
Trains a Convolutional Neural Network model based on the design by Kawahara et al. (2016) http://doi.org/10.1016/j.neuroimage.2016.09.046.
Args
X- The training dataset
y- The true labels
aggregation- Boolean, whether the matrices were aggregated based on yeo7
reorder- Boolean, whether to reorder the matrices based on the yeo7 network. (True is recommended when training with Brainnetome data. Only applicable to data based on the brainnetome atlas.
augmentation- Boolean, whether to apply data augmentation to increase the training data size
scale- Standard deviation of the random noise to be applied for data augmentation
augm_fact- Augmentation factor, Size of train dataset = original train dataset + augm_fact * noise dataset
batch_size- number of samples that will be propagated through the network
epochs- Number of training iterations
patience- Number of iterations to early stop if no improvement occurs
validation_size- Size of the validation set to evaluate during training
E2E_filter- Number of E2E filters, for a detailed description check out: https://kawahara.ca/convolutional-neural-networks-for-adjacency-matrices/
E2N_filter- Number of E2N filters, for a detailed description check out: https://kawahara.ca/convolutional-neural-networks-for-adjacency-matrices/
N2G_tiler- Number of N2G filters , for a detailed description check out: https://kawahara.ca/convolutional-neural-networks-for-adjacency-matrices/
dense_filter- Dense layer size, default 64
dropout_rate- Size of nodes to randomly drop during training, default .5
kernel_regularizer- Layer weight regularizers to be applied, default l2 regularization
kernel_initializer- Kernel initilization strategy, default he_uniform
optimizer- Method to train the model, default Adam
activation- Hidden layer activation, default relu
loss- loss function, default binary_crossentropy
Returns
A fitted neural network model
def preprocess_for_cnn(X, y, aggregation=False, reorder=False, augmentation=False, scale=0.07, augmentation_factor=5)-
Prepares and reformats the data for the cnn tensorflow mpde;
Args
X- The training dataset
y- The true labels
aggregation- Boolean,whether the matrices were aggregated based on yeo7
reorder- Boolean, whether to reorder the matrices based on the yeo7 network. Only applicable to data based on the brainnetome atlas.
augmentation- Boolean, whether to apply data augmentation to increase the training data size
scale- Standard deviation of the random noise to be applied for data augmentation
augmentation_factor- Augmentation factor, Size of train dataset = original dataset + augm_fact * noise dataset
Returns
X_img- symmetric np.array with the connectivity matrices
X_struc- np.array with structural information such as e.g. age etc.
y- dataset labels
def preprocess_test_data_for_cnn(X_test, y_test, aggregation=False, reorder=False)-
Preprares the test dataset for evaluation
Args
x- test dataframe
y- labels
aggregation- List of colnames of the connectivity matrix columns
reorder- List of colnames of the structural columns
Returns
Test dataframe and labels. The test dataframe is returned as list if structrual information exists.