metamod.ANN_tf module

Custom ANN definition using TensorFlow.

This module contains the definition of an ANN comptable with the SMT Toolbox

Notes

Keras tuner logs are not stored in data due to max path length issues in kerastuner.

See also

Tensorflow Keras documentation - https://www.tensorflow.org/api_docs/python/tf/keras

class metamod.ANN_tf.ANN(**kwargs)

Bases: metamod.ANN.ANN_base

ANN class.

name

Name of the surrogate model.

Type:str
model

The model of the ANN.

early_stop

Number of training epchs before early stopping.

Type:int
build_dense_model(neurons_hyp, activation_hyp, kernel_regularizer, in_dim, layers_hyp, out_dim)

Defines an fully connected ANN.

Parameters:
  • neurons_hyp (int) – Number of neurons per layer.
  • activation_hyp (str) – Activation function name.
  • () (kernel_regularizer) –
  • in_dim (int) – Number of input dimensions.
  • layers_hyp (int) – Number of hidden layers.
  • out_dim (int) – Number of output dimensions.
Returns:

The model of the ANN.

Return type:

model ()

build_hypermodel(hp)

General claass to build the ANN using TensorFlow with Keras Tuner hyperparameters defined.

Parameters:hp (kerastuner.engine.hyperparameters.HyperParameters) – Hyperparameters.
Returns:The model of the ANN.
Return type:model ()

Notes

Hyperparameters initialized using default values in config file.

build_sparse_model(neurons_hyp, activation_hyp, kernel_regularizer, in_dim, layers_hyp, out_dim)

Defines an ANN with a subnetwork for each output.

Parameters:
  • neurons_hyp (int) – Number of neurons per layer.
  • activation_hyp (str) – Activation function name.
  • () (kernel_regularizer) –
  • in_dim (int) – Number of input dimensions.
  • layers_hyp (int) – Number of hidden layers.
  • out_dim (int) – Number of output dimensions.
Returns:

The model of the ANN.

Return type:

model ()

get_callbacks()

Set-up the requiested callbacks to be entered into the model.

Returns:A list of callbacks.
Return type:callbacks (list)

Notes

MyStopping is never used.

pretrain(inputs, outputs, iteration)

Optimize the hyperparameters of the ANN.

Parameters:
  • inputs (np.array) – All input data.
  • outputs (np.array) – All output data.
  • iteration (int) – Iteration number.
Returns:

Optimal hyperparameters.

Return type:

best_hp (kerastuner.engine.hyperparameters.HyperParameters)

Notes

Optimization objective fixed on val_loss.

prune_model(model, target_sparsity)

Extends the ANN’s model with priuning layers.

Parameters:
  • () (model) – The model of the ANN.
  • target_sparsity (float) – Target constant sparsity of the network.
Returns:

The model of the ANN.

Return type:

model ()

Notes

Only constant sparsity active.

save()

Save the ANN into an external file.