validpy.ANN.src package¶
Submodules¶
validpy.ANN.src.BackPropTrainer module¶
-
class
validpy.ANN.src.BackPropTrainer.
Trainer
(network, momentum, learning_rate, lr_decay, data_set)¶ Backpropagation trainer
- Attributes:
- trainer (BackpropTrainer): Backpropagation trainer training_errors (list): List containing the training error for each epoch validation_errors (list): List containing the validation error for each epoch
-
plot_epochs
(folder)¶ Plot the training and validation errors over the epochs
Parameters: folder (str) – path to the plot file (.png) Returns: None Return type: None
-
train
(network, valid_bp, path)¶ Train until convergence, stopping the training when the training doesn’t reduce the validation error after 1000 continuous epochs
Parameters: - network (NeuralNetwork.NeuralNetwork) – model
- valid_bp (SupervisedDataSet) – Validation set
- path (str) – Path where to save the trained model
Returns: None
Return type: None
validpy.ANN.src.NeuralNetwork module¶
-
class
validpy.ANN.src.NeuralNetwork.
NeuralNetwork
(hidden_layers, units, function, input_length, output_length)¶ Class containing the ANN model
- Attributes:
- network (FeedForwardNetwork): ANN model
-
valid
(validation_set)¶ Compute the average euclidean distance activating the model over a validation set
Parameters: validation_set (SupervisedDataSet) – validation set Returns: average euclidean distance Return type: float
-
validpy.ANN.src.NeuralNetwork.
initialize_connection
(connection, prev_layer, layer)¶ Initialize a connection between two layers
Parameters: - connection (string) – layer’s connection topology (possible values: full)
- prev_layer (NeuronLayer) – first layer
- layer (NeuronLayer) – second Layer
Returns: connection
Return type: Connection
-
validpy.ANN.src.NeuralNetwork.
initialize_layer
(function, length)¶ Initialize a layer with the given parameters
Parameters: - function (string) – layer’s activation function (possible values: linear, sigmoid, gaussian)
- length (int) – layer’s length
Returns: layer
Return type: NeuronLayer
validpy.ANN.src.experimentKcross module¶
-
validpy.ANN.src.experimentKcross.
grid
(conf, data_sets)¶ Runs the k-cross validation over all possible parameter combinations
Parameters: - conf (JSON) – configuration JSON
- data_sets (list[list[tuple(list[float], list[float])]]) – examples as list of tuple (input, output)
Returns: None
-
validpy.ANN.src.experimentKcross.
k_cross_experiment
(hidden_layers, units, function, learning_rate, momentum, lr_decay, data_sets, out_folder, input_length, output_length, n_processes, csv=None)¶ Executes the k-cross validation
Parameters: - hidden_layers (int) – Number of hidden layers
- units (int) – Number of units for each hidden layer
- function (str) – Network’s activation function (possible values: linear, sigmoid, gaussian)
- learning_rate (float) – Learning rate value
- momentum (float) – Momentum value
- lr_decay (float) – Learning rate value
- data_sets (list[list[tuple(list[float], list[float])]]) – List of the k data sets
- out_folder (str) – Path to the output folder
- input_length (int) – Input length
- output_length (int) – Output length
- n_processes (int) – Number of parallel processes
- csv (FileIO) – Output csv file
Returns: Average error and average training time over the k experiments
Return type: tuple(float, float)
-
validpy.ANN.src.experimentKcross.
k_train
(hidden_layers, units, function, input_length, output_length, momentum, learning_rate, lr_decay, train, valid_bp, valid, folder, report, plot, net_path, q)¶ Runs the training and the model validation, this function have to been called via Process() https://docs.python.org/3/library/multiprocessing.html
Parameters: - hidden_layers (int) – number of hidden layers
- units (int) – number of units for each hidden layer
- function (str) – network’s activation function (possible values: linear, sigmoid, gaussian)
- input_length (int) – input length
- output_length (int) – output length
- momentum (float) – momentum value
- learning_rate (float) – learning rate value
- lr_decay (float) – learning rate value
- train (list[tuple(list[float], list[float])]) – training set
- valid_bp (list[tuple(list[float], list[float])]) – backpropagation validation set
- valid (list[tuple(list[float], list[float])]) – validation set
- folder (str) – path to the output experiment folder
- report (str) – path to the output experiment report file (.txt)
- plot (str) – path to the output experiment plot file (.png)
- net_path – path to the output experiment model file (.xml)
- q (Queue) – Queue
Returns: training time and average validation error
Return type: list[float]
-
validpy.ANN.src.experimentKcross.
main
(conf_file)¶ Reads configuration file and runs the k-cross validation experiments
Parameters: conf_file (str) – Path to the configuration file Returns: None
-
validpy.ANN.src.experimentKcross.
split_data_set_file
(file_name, input_length, output_length, k, separator=', ')¶ Reads the data set from csv, split the input and the output, shuffle the example list and split it in to k subsets
Parameters: - file_name (str) – path to the csv file
- input_length (int) – input length
- output_length (int) – output length
- k (int) – number of subsets
- separator (Optional[str]) – csv file separators, default = ‘,’
Returns: list of subsets
Return type: list[list[tuple]]
-
validpy.ANN.src.experimentKcross.
validates
(net_path, validation_set)¶ Compute the average euclidean distance activating the model over a validation set
Parameters: - net_path (str) – Path to the model
- validation_set (list[tuple(list[float], list[float])]) – Validation set
Returns: average euclidean distance
Return type: float