Neural Network Toolbox for Curve and Surface Fitting

N-Dimensional Curve Fitting, Surface Fitting, and Nonlinear Regression Toolbox

https://github.com/S0852306/Surface-Fitting-Neural-Networks

Ahora está siguiendo esta publicación

Neural Network for Curve Fitting and Nonlinear Regression
Lightweight MATLAB toolbox for N-dimensional curve fitting, nonlinear regression, surface fitting, and function approximation. Supports multiple built-in activations, learnable B-spline activations, ANN/ResNet architectures, and quasi-Newton refinement for high-precision fitting of sharp or nonsmooth targets.
Pure MATLAB implementation with no Deep Learning Toolbox, MEX, or external dependencies.
Core Function
NN = NeuralFit(x, y, [N, M]);
yPred = NN.Evaluate(x);
x is an [N-by-number-of-samples] input matrix, y is an [M-by-number-of-samples target matrix], and [N, M] defines the input and output dimensions
Basis / Activation Selection
The simplified workflow uses a Gaussian basis by default.
NN = NeuralFit(x, y, [N, M]); % default Gaussian basis
NN = NeuralFit(x, y, [N, M], 'basis', 'Wavelet'); % wavelet basis
NN = NeuralFit(x, y, [N, M], 'basis', 'BSpline'); % learnable B-Spline basis
Main Features
  • N-dimensional nonlinear regression and surface fitting
  • Arbitrary-dimensional mapping (N → M)
  • Learnable B-spline activation for sharp or nonsmooth targets
  • ResNet architectures for deep net fitting
  • Two-stage optimization: stochastic training + quasi-Newton refinement
  • Automatic input autoscaling
  • Pure MATLAB implementation with zero external dependencies
Quick Example — 2D Surface Fitting
clear; clc; close all;
x = linspace(-2, 2, 20);
[X, Y] = meshgrid(x);
U = X.^2 + Y.^2;
Z = exp(-0.5*U).*cos(2*U);
data = [X(:), Y(:)].';
label = Z(:).';
NN = NeuralFit(data, label, [2, 1]);
prediction = NN.Evaluate(data);
report = FittingReport(data, label, NN);
figure();
surf(X, Y, Z);
hold on;
scatter3(data(1,:), data(2,:), prediction);
Installation
Download and extract the package, then run:
run('installScript/installNeuralNetsPack.m')
For session-only setup:
addpath('installScript')
setupNeuralNetPath(struct('savePath', false))
Full Customizable Workflow
data = linspace(0, 2*pi, 1000);
label = data.*sin(data) + cos(3*data);
NN.Cost = 'MSE';
NN.ActivationFunction = 'Gaussian';
NN = Initialization([1, 7, 7, 7, 1], NN);
option.Solver = 'ADAM';
option.MaxIteration = 200;
option.BatchSize = 100;
NN = OptimizationSolver(data, label, NN, option);
option.Solver = 'BFGS';
option.MaxIteration = 400;
NN = OptimizationSolver(data, label, NN, option);
prediction = NN.Evaluate(data);
report = FittingReport(data, label, NN);
Included Demo Scripts
  • SimplifiedWorkflow.m % Minimal nonlinear regression workflow
  • CustomizableWorkflow.m % Full architecture and solver control
  • BenchmarkActivation1D.m % B-spline vs. fixed Gaussian activation comparison
  • SpiralClassification.m % 2D classification example
  • WeightedLeastSquares.m % Weighted fitting example
Training Tips
  • Use the B-spline activation for sharp or nonsmooth targets
  • Start with small networks before increasing width/depth
  • ADAM is recommended for the first-stage search
  • Apply BFGS or L-BFGS refinement for high-precision fitting
  • Input autoscaling is enabled by default
Documentation
for architecture customization, activation functions, optimizers, preprocessing, and mathematical details:
  • docs/Customization.md
  • docs/MathModel.md
References
  • Nocedal and Wright, Numerical Optimization
  • Goldfarb et al., practical quasi-Newton methods
  • Yi Ren et al., Kronecker-factored quasi-Newton methods

Citar como

S0852306 (2026). Neural Network Toolbox for Curve and Surface Fitting (https://es.mathworks.com/matlabcentral/fileexchange/129589-neural-network-toolbox-for-curve-and-surface-fitting), MATLAB Central File Exchange. Recuperado .

Información general

Compatibilidad con la versión de MATLAB

  • Compatible con cualquier versión

Compatibilidad con las plataformas

  • Windows
  • macOS
  • Linux
Versión Publicado Notas de la versión Action
1.2.9

- learnable B-Spline activation
- layer normalization

1.2.8

- fix path issue

1.2.7

Codebase refactored for improved structure and maintainability
Added L-BFGS solver for memory-efficient quasi-Newton optimization
Introduced a wavelet activation function for periodic data modeling
Fixed bug related to custom activation function con

1.2.6

Reorganized

1.2.5

Update instructions.

1.2.4

Fit data with a single line of code.

1.2.3

minor update

1.2.2

Add a weighted least-squares option, see "WeightedListSquare.m".

1.2.1

Explain the mathematical model of neural nets using a live script.

1.2.0

Solver update: AdamW, avoiding overfitting by weight decay.

1.1.9

Add MAE cost for robust surface fitting.

1.1.8

Minor update.

1.1.7

Solver minor update

1.1.6

1. Handwritten digit recognition (MNIST).
2. Bug fixed.

1.1.5

1. Add cross-entropy cost for classification problems.
2. ReLU bug fixed

1.1.4

1. Add Cross-Entropy Cost for Classification Task.
2. ReLU bug fixed.

1.1.3

New Solver 'RMSprop'

1.1.2

Minor Bug Fixed.
(Previous Version) There was an error in calculating the gradient for the bias in the last layer, but strangely, it didn't have a significant impact on the training results.

1.1.1

Solver Improvement.

1.1.0

Improve efficiency.
Bug fixed.

1.0.9

bug fixed

1.0.8

autoscaling
automatic derivatie

1.0.7

Added Autoscaling Function
Automatic Derivate Calculation (for x, i.e. input, not parameters of NN)
Simplified Command

1.0.6

Added autoscaling capability.
Added automatic derivate function for x.

1.0.5

guided

1.0.3

user guide

1.0.2

User Guide

1.0.1

Added User Guide. ("Guide.mlx")
See release notes for this release on GitHub: https://github.com/S0852306/Surface-Fitting-Neural-Networks/releases/tag/v1.0.1

1.0.0