Skip to content

MLP_Python

Contains a Multi-Layer Perceptron (MLP) implementation using PyTorch and the train_nn function to train the network.

MLP

Bases: Module


              flowchart TD
              mmm_audio.MLP_Python.MLP[MLP]

              

              click mmm_audio.MLP_Python.MLP href "" "mmm_audio.MLP_Python.MLP"
            

The Multi-Layer Perceptron (MLP) class.

__init__(input_size, layers_data)

Initialize the MLP.

Parameters:

Name Type Description Default
input_size int

Size of the input layer.

required
layers_data list

A list of tuples where each tuple contains the size of the layer and the activation function.

required

forward(input_data)

Forward pass through the MLP.

Parameters:

Name Type Description Default
input_data list[list[float]]

Input tensor.

required

get_input_size()

Get the input size of the MLP.

get_output_size()

Get the output size of the MLP.

train_nn(X_train_list, y_train_list, layers, learn_rate, epochs, file_name)

Train the MLP and save the trained model.

Parameters:

Name Type Description Default
X_train_list list[list[float]]

List of input training data.

required
y_train_list list[list[float]]

List of output training data.

required
layers list[tuple[int, str | None]]

List of layer specifications (size and activation).

required
learn_rate float

Learning rate for the optimizer.

required
epochs int

Number of training epochs.

required
file_name str

File name to save the trained model.

required