model.rp_nn module

RosenPy: An Open Source Python Framework for Complex-Valued Neural Networks. Copyright © A. A. Cruz, K. S. Mayer, D. S. Arantes.

License: This file is part of RosenPy. RosenPy is an open source framework distributed under the terms of the GNU General Public License, as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. For additional information on license terms, please open the Readme.md file.

RosenPy is distributed in the hope that it will be useful to every user, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with RosenPy. If not, see <http://www.gnu.org/licenses/>.

class model.rp_nn.NeuralNetwork(cost_func=<function mse>, patience=inf, gpu_enable=False)[source]

Bases: object

Abstract base class for wrapping all neural network functionality from RosenPy. This is a superclass.

accuracy(y, y_pred)[source]

Computes the accuracy of the predictions.

Parameters:

yarray-like

The true labels or target values.

y_predarray-like

The predicted values.

Returns:

float

The accuracy of the predictions as a percentage.

add_layer()[source]
convert_data(data)[source]

Converts the input data to the appropriate format for the current backend (NUMPY or CUPY).

Parameters:

dataarray-like

The input data.

Returns:

array-like

The converted input data.

denormalize_outputs(normalized_output_data, mean=0, std_dev=0)[source]

Denormalizes the output data based on the provided mean and standard deviation.

Parameters:

normalized_output_dataarray-like

The data to be denormalized.

meanfloat, optional

The mean used for normalization. Default is 0.

std_devfloat, optional

The standard deviation used for normalization. Default is 0.

Returns:

array-like

The denormalized data.

fit(x_train, y_train, x_val=None, y_val=None, epochs=100, verbose=10, batch_gen=<function batch_sequential>, batch_size=1, optimizer=<model.rp_optimizer.GradientDescent object>)[source]

Trains the neural network on the provided training data.

Parameters:

x_trainarray-like

The input training data.

y_trainarray-like

The target training data.

x_valarray-like, optional

The input validation data. Default is None.

y_valarray-like, optional

The target validation data. Default is None.

epochsint, optional

The number of training epochs. Default is 100.

verboseint, optional

Controls the verbosity of the training process. Default is 10.

batch_genfunction, optional

The batch generation function to use during training. Default is batch_gen_func.batch_sequential.

batch_sizeint, optional

The batch size to use during training. Default is 1.

optimizerOptimizer, optional

The optimizer to use during training. Default is GradientDescent with specified parameters.

get_history()[source]

Returns the training history of the neural network.

Returns:

dict

A dictionary containing the training history.

normalize_data(input_data, mean=0, std_dev=0)[source]

Normalizes the input data based on the provided mean and standard deviation.

Parameters:

input_dataarray-like

The data to be normalized.

meanfloat, optional

The mean for normalization. Default is 0.

std_devfloat, optional

The standard deviation for normalization. Default is 0.

Returns:

array-like

The normalized data.

predict(x, status=1)[source]

Predicts the output for the given input data.

Parameters:

xarray-like

The input data for prediction.

Returns:

array-like

The predicted output for the input data.

update_learning_rate(epoch)[source]

Updates the learning rates of all layers based on the current epoch.

Parameters:

epochint

The current epoch number.

verify_input(data)[source]

Verifies the input data type for optimal performance of the RosenPY framework.

Parameters:

dataarray-like

The input data.