Tabular API Reference
Contents
Tabular API Reference#
Complete API reference for NeurEco Tabular models: Regressor, Classifier, and Compressor.
On this page
Import#
from NeurEco import NeurEcoTabular as tab
Regressor#
class tab.Regressor
Regression model for predicting continuous values.
File extension: .ednn
Constructor#
model = tab.Regressor(dll_path=None)
Parameters:
dll_path(str, optional) — Path to NeurEco binaries. If None, uses default installation path.
Methods#
build#
status = model.build(config)
Train the model using the provided configuration.
Parameters:
config(RegressorBuildConfig) — Build configuration object
Returns: int — Status code (0 = success)
Raises:
ConfigurationError— Invalid configuration parametersArrayShapeMismatchError— Data shapes incompatibleModelOperationError— Build failed
evaluate#
outputs = model.evaluate(inputs, vec=None, gradient_cache=False)
Run inference on input data.
Parameters:
inputs(ndarray or list) — Input data, shape(n_samples, n_inputs)or list of arraysvec(ndarray, optional) — Custom weights (uses trained weights if None)gradient_cache(bool) — Cache inputs for gradient computation
Returns: ndarray or list — Predictions with same structure as inputs
Raises:
ModelNotReadyError— No model loaded/builtArrayShapeMismatchError— Input shape mismatchDataContainsNaNError— Inputs contain NaN
compute_error#
error = model.compute_error(predictions, targets)
Compute L2 relative error between predictions and targets.
Parameters:
predictions(ndarray) — Model predictionstargets(ndarray) — Ground truth values
Returns: float — L2 relative error (0.0 = perfect, 1.0 = 100% error)
load / save#
model.load(path)
model.save(path)
Load or save model from/to disk.
Parameters:
path(str) — File path (extension optional)
Returns: int — Status code (0 = success)
load reads a saved model file only. To load a model from a checkpoint, use
load_model_from_checkpoint.
get_number_of_networks_from_checkpoint / load_model_from_checkpoint#
n = model.get_number_of_networks_from_checkpoint(path)
model.load_model_from_checkpoint(path, model_index)
Get the number of models saved in a checkpoint, or load one of them.
Parameters:
path(str) — Checkpoint path (.checkpointis added when the path does not end with it)model_index(int) — Model index (0-based)
The build log and the GUI number checkpoints from 1: “Checkpoint N” there is
model_index N - 1 here.
Returns: int — The number of models (get_number_of_networks_from_checkpoint),
or a status code, 0 = success (load_model_from_checkpoint)
get_input_count / get_output_count#
n_inputs = model.get_input_count()
n_outputs = model.get_output_count()
Get number of input/output features.
Returns: int
get_weights / set_weights#
weights = model.get_weights()
model.set_weights(weights)
Get or set model weights.
Parameters (set):
weights(ndarray) — Weight array, shape(n_parameters, 1)
Returns (get): ndarray — Weight array
export_onnx#
status = model.export_onnx(path, precision="float32")
Export to ONNX format.
Parameters:
path(str) — Output file pathprecision(str) —"float32","float16", or"float64"(legacy"float"/"double"still accepted)
Returns: int — Status code
export_c#
status = model.export_c(path, precision="float32")
Export to C header file.
Parameters:
path(str) — Output .h file pathprecision(str) —"float32"or"float64"(legacy"float"/"double"still accepted)
Returns: int — Status code
export_vba#
status = model.export_vba(path, precision="float32")
Export to VBA (Visual Basic for Applications).
Parameters:
path(str) — Output file pathprecision(str) —"float32"or"float64"(legacy"float"/"double"still accepted)
Returns: int — Status code
export_fmu#
status = model.export_fmu(path)
Export to FMU format.
Parameters:
path(str) — Output .fmu file path
Returns: int — Status code
Note
Requires NeurEco Embed license.
sensitivity#
sensitivity = model.sensitivity(inputs, id_output)
Compute sensitivity of an output with respect to each input.
Parameters:
inputs(ndarray) — Input dataid_output(int) — Output index to analyze
Returns: ndarray — Sensitivity values for each input feature
perform_input_sweep#
model.perform_input_sweep(
input_feature,
input_id,
input_interval,
output_id,
n_points=100,
show=True,
save_path=None
)
Visualize how one input affects the output.
Parameters:
input_feature(ndarray) — Reference input sample (1D)input_id(int) — Index of input to sweepinput_interval(list) —[min, max]rangeoutput_id(int) — Output to plotn_points(int) — Number of sweep pointsshow(bool) — Display plotsave_path(str) — Path to save figure
plot_network#
model.plot_network(save_address=None, show=True)
Visualize the neural network architecture.
Parameters:
save_address(str) — Path to save PNGshow(bool) — Display plot
gradient#
pw, px = model.gradient(w, x, py)
Compute backward derivative (backpropagation).
Parameters:
w(ndarray) — Weightsx(ndarray) — Inputspy(ndarray) — Output perturbation
Returns: tuple — (weight gradient, input gradient)
forward_derivative#
dy = model.forward_derivative(w, dw, x, dx=None)
Compute forward derivative (tangent mode).
Parameters:
w(ndarray) — Weightsdw(ndarray) — Weight perturbationx(ndarray) — Inputsdx(ndarray, optional) — Input perturbation
Returns: ndarray — Output perturbation
delete#
model.delete()
Free native memory. Always call when done.
RegressorBuildConfig#
config = tab.RegressorBuildConfig(
# Required
input_data,
output_data,
# Optional validation / test data
validation_input_data=None,
validation_output_data=None,
test_input_data=None,
test_output_data=None,
# Validation settings
valid_percentage=33.33,
validation_indices=None,
write_validation_indexes_to="",
# Output paths
write_model_to="",
checkpoint_address="",
# Resume settings
checkpoint_to_start_build_from="",
start_build_from_model_number=-1,
freeze_structure=False,
# GPU settings
use_gpu=False,
gpu_id=0,
# Normalization settings
inputs_scaling="auto",
inputs_shifting="auto",
outputs_scaling="auto",
outputs_shifting="auto",
inputs_normalize_per_feature=True,
outputs_normalize_per_feature=False,
# Build settings
initial_beta_reg=0.1,
links_maximum_number=0,
disconnect_inputs_if_possible=True,
final_learning=True,
field_output=False,
)
Parameters:
Parameter |
Default |
Description |
|---|---|---|
|
(required) |
Training inputs: array or list of arrays, shape |
|
(required) |
Training outputs: array or list of arrays, shape |
|
|
Optional validation inputs (same format as |
|
|
Optional validation outputs |
|
|
Optional test inputs (monitored during the build, never used for training) |
|
|
Optional test outputs |
|
|
Percentage of training data used for validation when no validation set is given (10–50) |
|
|
Explicit 1-based indices of the samples to use for validation (overrides |
|
|
Path to save the chosen validation indices as a CSV file |
|
|
Path to save the final trained model ( |
|
|
Path for the checkpoint file written during the build |
|
|
Path to an existing checkpoint to resume the build from |
|
|
Model index within that checkpoint to resume from ( |
|
|
When resuming, retrain only the weights and keep the existing network structure (requires |
|
|
Use the GPU for the build |
|
|
GPU device id to use when |
|
|
Input scaling: |
|
|
Input shifting: |
|
|
Output scaling (same options as |
|
|
Output shifting (same options as |
|
|
Normalize each input feature independently ( |
|
|
Normalize each output feature independently ( |
|
|
Initial regularization coefficient (see The Regularization Coefficient) |
|
|
Maximum number of links (trainable parameters) in the network ( |
|
|
Allow NeurEco to prune the links from the inputs each time it changes the network structure and, when |
|
|
Final pruning, a last pass that disconnects unused inputs (if |
|
|
Flag the output as a single physical field, not independent scalars (distinct from |
Classifier#
class tab.Classifier
Classification model for predicting discrete classes.
File extension: .ednn
Same methods as Regressor, with these differences:
Output data must be one-hot encoded
compute_errorreturns classification error rate
ClassifierBuildConfig#
Same parameters as RegressorBuildConfig.
Note
Output data must be one-hot encoded: shape (n_samples, n_classes)
Compressor#
class tab.Compressor
Autoencoder for dimensionality reduction.
File extension: .ednn
Additional Methods#
separate_models#
encoder = Tabular.Compressor()
decoder = Tabular.Compressor()
model.separate_models(encoder, decoder)
Split a built Compressor into its encoder (compression) and decoder (decompression) sub-models.
Parameters:
encoder(Compressor) — Receives the encoder sub-modeldecoder(Compressor) — Receives the decoder sub-model
Returns: int — Status code (0 = success)
Note
The encoder and decoder are also written directly at build time via the
write_compression_model_to and write_decompression_model_to options
of CompressorBuildConfig; load them back with Compressor.load.
Compressing and reconstructing#
Once you have the encoder and decoder, compress and reconstruct with the normal
evaluate call, and read the compressed dimension from the result shape:
compressed = encoder.evaluate(inputs) # lower-dimensional representation
reconstructed = decoder.evaluate(compressed) # back to the input space
latent_dim = compressed.shape[1] # size of the compressed space
CompressorBuildConfig#
config = tab.CompressorBuildConfig(
input_data,
compress_tolerance=0.01,
# ... other parameters same as RegressorBuildConfig
)
Additional Parameter:
compress_tolerance(float) — Reconstruction error tolerance (default: 0.01)
Example Usage#
Regression#
from NeurEco import NeurEcoTabular as tab
import numpy as np
# Prepare data
X_train = np.random.randn(1000, 5)
Y_train = np.random.randn(1000, 2)
# Build
model = tab.Regressor()
config = tab.RegressorBuildConfig(
input_data=X_train,
output_data=Y_train,
write_model_to="./regressor.ednn"
)
model.build(config)
# Evaluate
predictions = model.evaluate(X_test)
error = model.compute_error(predictions, Y_test)
print(f"Error: {100*error:.2f}%")
# Cleanup
model.delete()
Classification#
from NeurEco import NeurEcoTabular as tab
import numpy as np
# One-hot encode labels
n_classes = 3
Y_onehot = np.eye(n_classes)[labels]
# Build
model = tab.Classifier()
config = tab.ClassifierBuildConfig(
input_data=X_train,
output_data=Y_onehot,
write_model_to="./classifier.ednn"
)
model.build(config)
# Predict
probs = model.evaluate(X_test)
predictions = np.argmax(probs, axis=1)
model.delete()