Mutation¶
Mutation is a key step in the genetic algorithm. Here are defined and explained all
the classes used to make those mutations possible. Mutation is the main and
generic class; then there are specific classes, one for each deatf.network.NetworkDescriptor.
These classes contains all the possible mutations that can be made in their defined functions.
But the two steps to follow are:
Initialize appropiate class for the Network to evolve.
Call
Mutation.apply_random_mutation()in order to apply a random possible mutation orMutation.apply_mutation()to apply an specific mutation (these functions are inherited from Mutation so they can be used in other mutation classes).
The mutation will be applied to the deatf.network.NetworkDescriptor object passed
i nthe parameter network in the initialization. The change will be made in the object, that
is why mutation function do not return anything.
-
class
deatf.mutation.Mutation(hypers, batch_norm, dropout, network, hyperparameters, custom_mutation_list=[])¶ Bases:
objectThis class implements the possible mutations that can be applied for a generic networks descriptors. This class contains the general mutations that could be applied to any descriptor, subclases will have specific mutations for their own network.
- Parameters
hypers – List with the hyperparameters to be evolved.
batch_norm – A boolean value that indicates if batch normalization can appear during evolution. Is different from the network’s one because this remains during all the process and the network’s one can be changed or mutated.
dropout – A boolean value that indicates the same as batch normalization but applied to dropout.
network – Network descriptor that will be mutated.
hyperparameters – Hyperparameters that are in the mutated network.
custom_mutation_list – Optinal list with the mutations that can be applied to the network. Is defined by the user with the mutations wanted, if is not defined, all possible mutations could be applied.
-
apply_random_mutation()¶ It selects all the available mutations for the network and after selecting one randomly, it applies that mutation.
-
apply_mutation(mutation)¶ Given a mutation method and a network, it applies that mutation to the network if it is possible; if not it raises a ValueError. This function is mainly though for the case where the user define the mutation list, in order to ensure that all the described mutation can be done.
- Parameters
mutation – Mutation that will be applied to the network.
-
methods()¶ Finds and returns all the possible mutations for that mutation class.
- Returns
List with all the possible mutations that can be applied.
-
mut_weight_init()¶ Changes the weight initialization in a random layer for a new random weight initialization function.
-
mut_activation()¶ Changes the activation function in a random layer for a new random activation function.
-
mut_dropout()¶ Changes the dropout boolean.
-
mut_dropout_prob()¶ Changes the dropout probabilites.
-
mut_batch_norm()¶ Changes the batch normalization boolean.
-
mut_hyper()¶ Changes one of the hyperparameters of the network for a new one selected randomly from the list of evolvable hyperparameters described in the initialization.
-
class
deatf.mutation.MLP_Mutation(hypers, batch_norm, dropout, network, hyperparameters, custom_mutation_list=[])¶ Bases:
deatf.mutation.MutationThis class implements the possible mutations that can be applied specialy to the MLP descriptors.
- Parameters
hypers – List with the hyperparameters to be evolved.
batch_norm – A boolean value that indicates if batch normalization can appear during evolution. Is different from the network’s one because this remains during all the process and the network’s one can be changed or mutated.
dropout – A boolean value that indicates the same as batch normalization but applied to dropout.possible_initializations
network – MLP descriptor that will be mutated.
hyperparameters – Hyperparameters that are in the mutated network.
custom_mutation_list – Optinal list with the mutations that can be applied to the network. Is defined by the user with the mutations wanted, if is not defined, all possible mutations could be applied.
-
mut_add_layer()¶ A new dense layer is added to the MLP descriptor.
-
mut_remove_layer()¶ Removes a random layer from the MLP descriptor.
-
mut_dimension()¶ Number of neurons of a random layer are changed to a new random number of neurons from 1 to maximum number of neurons described in the initialization.
-
class
deatf.mutation.CNN_Mutation(hypers, batch_norm, dropout, network, hyperparameters, custom_mutation_list=[])¶ Bases:
deatf.mutation.MutationThis class implements the possible mutations that can be applied specialy to the CNN descriptors.
- Parameters
hypers – List with the hyperparameters to be evolved.
batch_norm – A boolean value that indicates if batch normalization can appear during evolution. Is different from the network’s one because this remains during all the process and the network’s one can be changed or mutated.
dropout – A boolean value that indicates the same as batch normalization but applied to dropout.
network – CNN descriptor that will be mutated.
hyperparameters – Hyperparameters that are in the mutated network.
custom_mutation_list – Optinal list with the mutations that can be applied to the network. Is defined by the user with the mutations wanted, if is not defined, all possible mutations could be applied.
-
mut_add_conv_layer()¶ A new convolutional or pooling layer is added to the CNN descriptor.
-
mut_remove_conv_layer()¶ Removes a random layer from the CNN descriptor if it is possible (if there is only one layer, it can not be removed).
-
mut_stride_conv()¶ Stride of a random layer is changed to a new random stride from 1 to maximum stride size described in the network descriptor.
-
mut_filter_conv()¶ Filter of a random layer is changed to a new random filter with size from 2 to maximum filter size described in the network descriptor and with channels from 1 to 65.
-
mut_weight_init()¶ Changes the weight initialization in a random layer for a new random weight initialization function.
-
mut_activation()¶ Changes the activation function in a random layer for a new random activation function.
-
class
deatf.mutation.TCNN_Mutation(hypers, batch_norm, dropout, network, hyperparameters, custom_mutation_list=[])¶ Bases:
deatf.mutation.MutationThis class implements the possible mutations that can be applied specialy to the TCNN descriptors.
- Parameters
hypers – List with the hyperparameters to be evolved.
batch_norm – A boolean value that indicates if batch normalization can appear during evolution. Is different from the network’s one because this remains during all the process and the network’s one can be changed or mutated.
dropout – A boolean value that indicates the same as batch normalization but applied to dropout.
network – TCNN descriptor that will be mutated.
hyperparameters – Hyperparameters that are in the mutated network.
custom_mutation_list – Optinal list with the mutations that can be applied to the network. Is defined by the user with the mutations wanted, if is not defined, all possible mutations could be applied.
-
mut_add_deconv_layer()¶ A new transposed convolutional layer is added to the TCNN descriptor.
-
mut_remove_deconv_layer()¶ Removes a random layer from the TCNN descriptor if it is possible (if there is only one layer, it can not be removed).
-
mut_stride_deconv()¶ Stride of a random layer is changed to a new random stride from 1 to maximum stride size described in the network descriptor.
-
mut_filter_deconv()¶ Filter of a random layer is changed to a new random filter with size from 2 to maximum filter size described in the network descriptor and with channels from 1 to 65.
-
class
deatf.mutation.RNN_Mutation(hypers, batch_norm, dropout, network, hyperparameters, custom_mutation_list=[])¶ Bases:
deatf.mutation.MutationThis class implements the possible mutations that can be applied specialy to the RNN descriptors.
- Parameters
hypers – List with the hyperparameters to be evolved.
batch_norm – A boolean value that indicates if batch normalization can appear during evolution. Is different from the network’s one because this remains during all the process and the network’s one can be changed or mutated.
dropout – A boolean value that indicates the same as batch normalization but applied to dropout.
network – RNN descriptor that will be mutated.
hyperparameters – Hyperparameters that are in the mutated network.
custom_mutation_list – Optinal list with the mutations that can be applied to the network. Is defined by the user with the mutations wanted, if is not defined, all possible mutations could be applied.
-
mut_add_rnn_layer()¶ A new recurrent layer is added to the RNN descriptor.
-
mut_remove_rnn_layer()¶ Removes a random layer from the RNN descriptor.
-
mut_change_layer_type()¶ Type of a random layer is changed to a new random type.
-
mut_change_units()¶ Number of units in a random layer is changed to a new random number of units from 1 to maximum number of units described in network descriptor.
-
mut_change_bidirectional()¶ A random layer is changed to be biderctional if is not; otherwise, it stops beeing bidirectional.