Skip to main content

NeuralNet

C++: phynexis::ml::NeuralNet
Python: phynexis.ml.NeuralNet
Header: src/ml/neural_net.hpp

Description

Unified neural network class supporting classification, regression, and gradient computation via a PyTorch backend.

Constructors

NeuralNet()

Creates an empty neural network.

Example:

import phynexis
net = phynexis.ml.NeuralNet()
print(net)

Methods

add_layer(layer_type, out_features)

Adds a Linear layer with the specified number of output features.

Parameters:

ParameterTypeDescription
layer_typeLayerTypeLayer type (must be LayerType.Linear)
out_featuresintNumber of output features

add_layer(layer_type)

Adds an activation layer.

Parameters:

ParameterTypeDescription
layer_typeLayerTypeActivation type (ReLU, Tanh, ELU, etc.)

train(data_x, data_y)

Trains the network on the given data.

Parameters:

ParameterTypeDescription
data_xndarrayInput data (features × samples)
data_yndarrayTarget data (outputs × samples)

train(data_x, data_y, config)

Trains with a custom TrainingConfig.

train_with_loss(loss_fn, data_dict)

Trains with a custom loss function (e.g. for PINN).

Parameters:

ParameterTypeDescription
loss_fncallableLoss function: loss_fn(model, data_dict) -> loss_tensor
data_dictdictDictionary mapping string keys to data arrays

predict(data_x)

Performs regression prediction.

Parameters:

ParameterTypeDescription
data_xndarrayInput data

Returns: ndarray — predicted output

classify(data_x)

Performs classification and returns class labels.

Parameters:

ParameterTypeDescription
data_xndarrayInput data

Returns: ndarray — class labels

regress(data_x)

Alias for predict().

gradient(data_x)

Computes the gradient with respect to input.

Parameters:

ParameterTypeDescription
data_xndarrayInput data

Returns: ndarray — gradient matrix

laplacian(data_x)

Computes the Laplacian (second-order derivative) with respect to input.

Parameters:

ParameterTypeDescription
data_xndarrayInput data

Returns: ndarray — Laplacian values

save(filename, label="model")

Saves the model to a file.

load(filename, label="model")

Loads the model from a file.

load_from_pytorch_model(pytorch_model)

Loads weights from a PyTorch nn.Module object.

Prints basic model information.

Prints detailed model information including layer details.

reset_model()

Resets the model.

Properties

PropertyTypeDefaultAccessDescription
step_sizefloat0.01read/writeLearning rate
batch_sizeint32read/writeBatch size
decay_rate_momentfloat0.9read/writeMomentum decay rate
decay_rate_normfloat0.9read/writeNorm decay rate
gradient_init_paramfloat1e-8read/writeGradient initialization parameter
epochsint100read/writeNumber of training epochs
stop_tolfloat1e-8read/writeStopping tolerance
enable_loggingboolTrueread/writeEnable training log output