cerebral

Models

cerebral.models.setup_losses_and_metrics()[source]

Returns losses and metrics per target feature, accounting for numerical or categorical targets.

cerebral.models.build_input_layers(train_ds) list[source]

Returns a list of input layers, one for each input feature.

cerebral.models.build_base_model(inputs, num_shared_layers, ...)[source]

Constructs the base model, shared by all feature branches. See Figure 1 of https://pubs.rsc.org/en/content/articlelanding/2022/dd/d2dd00026a.

cerebral.models.build_feature_branch(feature, ensemble_size, ...)[source]

Constructs a branch of the model for a specific feature. See Figure 1 of https://pubs.rsc.org/en/content/articlelanding/2022/dd/d2dd00026a.

cerebral.models.build_model(train_ds, num_shared_layers, ...)[source]

Constructs a model containing a shared branch, and individual feature branches. See Figure 1 of https://pubs.rsc.org/en/content/articlelanding/2022/dd/d2dd00026a.

cerebral.models.save(model, path)[source]

Save a model to disk.

cerebral.models.load(path)[source]

Load a model from disk, associate all custom objects with their cerebral functions.

cerebral.models.compile_and_fit(train_ds, test_ds=None, ...)[source]

Compile a model, and perform training.

cerebral.models.fit(model, train_ds, test_ds=None, ...)[source]

Perform training of a model to data.

cerebral.models.calculate_prediction_errors(truth, ...) dict[source]

Calculate the prediction errors for each item of training data.

cerebral.models.calculate_regression_metrics(truth, ...) dict[source]

Calculate regression metrics to evaluate model performance.

cerebral.models.calculate_classification_metrics(truth, ...) dict[source]

Calculate classification metrics to evaluate model performance.

cerebral.models.evaluate_model(model, train_ds, test_ds=None)[source]

Evaluate the performance of a trained model by comparison to known data.

cerebral.models.get_model_prediction_features(model)[source]

Extract the names and types of output features from a model.

cerebral.models.get_model_input_features(model)[source]

Extract the names of expected input features from a model.

cerebral.models.predict(model, alloys, uncertainty=False)[source]

Use a trained model to produce predictions for a set of alloy compositions.

Loss

cerebral.loss.masked_MSE(y_true, y_pred)[source]

Calculate the mean-squared-error, ignoring masked values.

cerebral.loss.masked_MAE(y_true, y_pred)[source]

Calculate the mean-absolute-error, ignoring masked values.

cerebral.loss.masked_PseudoHuber(y_true, y_pred)[source]

Calculate the pseudo-Huber error, ignoring masked values.

cerebral.loss.masked_Huber(y_true, y_pred)[source]

Calculate the Huber error, ignoring masked values.

cerebral.loss.masked_sparse_categorical_crossentropy(y_true, y_pred)[source]

Calculate the sparse categorical cross-entropy, ignoring masked values.

Metrics

cerebral.metrics.tprPerClass(y_true, y_pred, class_index=0)[source]

Calculate the per-class true positive rate, ignoring masked values.

cerebral.metrics.truePositiveRate(y_true, y_pred)[source]

Calculate the true positive rate, ignoring masked values.

cerebral.metrics.falsePositiveRate(y_true, y_pred)[source]

Calculate the false positive rate, ignoring masked values.

cerebral.metrics.falseNegativeRate(y_true, y_pred)[source]

Calculate the false negative rate, ignoring masked values.

cerebral.metrics.ppvPerClass(y_true, y_pred, class_index=0)[source]

Calculate the per-class positive predictive value, ignoring masked values.

cerebral.metrics.positivePredictiveValue(y_true, y_pred)[source]

Calculate the positive predictive value, ignoring masked values.

cerebral.metrics.f1(y_true, y_pred)[source]

Calculate the f1 score, ignoring masked values.

cerebral.metrics.tnrPerClass(y_true, y_pred, class_index=0)[source]

Calculate the per-class true negative rate, ignoring masked values.

cerebral.metrics.trueNegativeRate(y_true, y_pred)[source]

Calculate the overall true negative rate, ignoring masked values.

cerebral.metrics.npvPerClass(y_true, y_pred, class_index=0)[source]

Calculate the per-class negative predictive value, ignoring masked values.

cerebral.metrics.negativePredictiveValue(y_true, y_pred)[source]

Calculate the overall negative predictive value, ignoring masked values.

cerebral.metrics.informedness(y_true, y_pred)[source]

Calculate the informedness, ignoring masked values.

cerebral.metrics.markedness(y_true, y_pred)[source]

Calculate the markedness, ignoring masked values.

cerebral.metrics.accuracy(y_true, y_pred)[source]

Calculate the accuracy, ignoring masked values.

cerebral.metrics.balancedAccuracy(y_true, y_pred) float[source]

Calculate the balanced accuracy, ignoring masked values.

cerebral.metrics.positiveLikelihood(y_true, y_pred) float[source]

Calculate the positive likelihood, ignoring masked values.

cerebral.metrics.negativeLikelihood(y_true, y_pred) float[source]

Calculate the negative likelihood, ignoring masked values.

cerebral.metrics.diagnosticOdds(y_true, y_pred) float[source]

Calculate the diagnostic odds, ignoring masked values.

cerebral.metrics.fowlkesMallows(y_true, y_pred) float[source]

Calculate the Fowlkes-Mallows index, ignoring masked values.

cerebral.metrics.jaccard(y_true, y_pred) float[source]

Calculate the Jaccard index, ignoring masked values.

cerebral.metrics.calc_R_sq(true, prediction) float[source]

Calculate the R-squared score.

cerebral.metrics.calc_RMSE(true, prediction) float[source]

Interface to calculate the root-mean-squared-error, ignoring masked values.

cerebral.metrics.calc_MAE(true, prediction) float[source]

Interface to calculate the mean-absolute-error, ignoring masked values.

cerebral.metrics.calc_accuracy(true, prediction) float[source]

Interface to calculate the accuracy.

cerebral.metrics.calc_f1(true, prediction) float[source]

Interface to calculate the F1 score.

cerebral.metrics.calc_recall(true, prediction) float[source]

Interface to calculate the recall score.

cerebral.metrics.calc_precision(true, prediction) float[source]

Interface to calculate the precision score.

cerebral.metrics.meanAbsoluteDeviation(data) float[source]

Calculate the mean-absolute-deviation of a dataset.

cerebral.metrics.rootMeanSquareDeviation(data) float[source]

Calculate the root-mean-square-deviation of a dataset.

K-folds cross-validation

cerebral.kfolds.kfolds_split(data, ...) list[list[DataFrame]][source]

Split a dataframe into several folds of training and test subsets.

cerebral.kfolds.kfolds(data: DataFrame, save: bool = False, ...)[source]

Performs k-folds cross-validation to evaluate a model.

cerebral.kfolds.kfoldsEnsemble(data: DataFrame)[source]

Construct an ensemble model using multiple k-folds submodels. See Section 4.2 of https://pubs.rsc.org/en/content/articlelanding/2022/dd/d2dd00026a.

Feature Permutation

cerebral.permutation.permutation(postprocess=None)[source]

Performs feature permutation analysis to identify important features. See Section 5 of https://pubs.rsc.org/en/content/articlelanding/2022/dd/d2dd00026a.

Hyperparameter Tuning

class cerebral.tuning.HyperModel(keras_tuner.engine.hypermodel.HyperModel)[source]

Variant of the keras-tuner HyperModel class

cerebral.tuning.tune(data, tuner='hyperband')[source]

Perform hyperparameter tuning using kerastuner.

Plot

cerebral.plots.plot_training(history)[source]

Plot metrics over the course of training.

cerebral.plots.plot_results_regression(train_truth, ...)[source]

Plot true versus prediction for regression outputs.

cerebral.plots.plot_results_regression_heatmap(train_truth, ...)[source]

Plot true versus prediction heatmaps for multiple regression models.

cerebral.plots.plot_results_classification(train_truth, ...)[source]

Plot a confusion matrix for a classifier.

cerebral.plots.plot_multiclass_roc(true, pred, feature_name, ...)[source]

Plot a reciever-operator characteristic graph for multiple classes.

cerebral.plots.plot_distributions(data)[source]

Plot distributions of input features in the training data set.

cerebral.plots.plot_feature_variation(data, suffix=None)[source]

Plot a the quartile coefficient of dispersion for each feature in the training data.

cerebral.plots.plot_correlation(data, suffix=None)[source]

Plot correlations between pairs of features, using a correlation matrix and a dendrogram.

cerebral.plots.plot_feature_permutation(data)[source]

Plot the results of feature permutation, ranking the most important features.

Utilities

cerebral.GFA.ensure_default_values_glass(data, ...) DataFrame[source]

Postprocessing function which assigns default values to compositions specific to GFA modellin

cerebral.features.load_data(...) DataFrame[source]

Load and process data for use by cerebral.

cerebral.features.extract_compositions(data: DataFrame) DataFrame[source]

Extracts alloy compositions from data files formatted with columns per element.

cerebral.features.prettyName(feature_name: str) str[source]

Converts a a feature name string to a LaTeX formatted string

cerebral.features.calculate_features(data: DataFrame, ...)[source]

Calculates features for a data set of alloy compositions.

cerebral.features.drop_unwanted_inputs(data, ...) DataFrame[source]

Remove columns from the input DataFrame if they are not specified as an input feature or a target feature.

cerebral.features.drop_invalid_compositions(data) DataFrame[source]

Remove invalid alloy compositions from the input DataFrame. Alloy compositions are be invalid if they have percentages which do not sum to 100%.

cerebral.features.remove_correlated_features(data, ...)[source]

Remove highly correlated features from the training data.

cerebral.features.drop_static_features(data, ...) DataFrame[source]

Drop static features by analysis of the quartile coefficient of dispersion. See Equation 7 of https://pubs.rsc.org/en/content/articlelanding/2022/dd/d2dd00026a.

cerebral.features.merge_duplicate_compositions(...) DataFrame[source]

Merge duplicate composition entries by either dropping exact copies, or averaging the data of compositions with multiple experimental values.

cerebral.features.get_features_from_model(model)[source]

Get names of features and targets from an existing model.

cerebral.features.train_test_split(...) tuple[DataFrame, DataFrame][source]

Split data into training and test subsets, ensuring that similar compositions are grouped together. See Section 3.1 of https://doi.org/10.1016/j.actamat.2018.08.002, and Section 4.1 of https://pubs.rsc.org/en/content/articlelanding/2022/dd/d2dd00026a.

cerebral.features.df_to_dataset(dataframe: DataFrame, ...)[source]

Convert a pandas dataframe to a tensorflow dataset

cerebral.features.generate_sample_weights_categorical(...) array[source]

Based on per-class weights, generate per-sample weights.

cerebral.features.create_datasets(data: DataFrame, targets, ...)[source]

Separates the total data set of alloy compositions into training and test subsets.

cerebral.features.filter_masked(data: Series | list, ...)[source]

Filters out masked or NaN values from data.

cerebral.layers.dense(units, activation, regularizer=None, ...)[source]

Helper function which creates a dense layer.


Last update: Feb 09, 2023