`newff` is deprecated. How to implement the same BP network function in the new version of MATLAB?

`newff` has been removed in R2021a and later releases. Use `feedforwardnet` (Deep Learning Toolbox) as its equivalent.

Migration steps:
Network architecture:
Old: `net = newff(P,T,[10],{‘tansig’,’purelin’},’trainlm’);`
New: `net = feedforwardnet(10,’trainlm’);`

Transfer functions: The hidden layer defaults to `’tansig’` and the output layer defaults to `’purelin’`, matching the old version. If `’logsig’` was used in the old code, set `net.layers{1}.transferFcn = ‘logsig’`.

Training algorithm: `’trainlm’` (Levenberg–Marquardt) remains available for `feedforwardnet`. Specify it explicitly to reproduce legacy behavior.

Data partitioning and normalization: New releases use `dividerand` partitioning plus `mapminmax` normalization by default. The old `newff` also normalized data by default but used different partitioning rules. For reproducibility, set `net.divideFcn=’divideblock’` or implement custom partitioning, and ensure consistent timing for `removeconstantrows` and `mapminmax`.

Initialization: Weight initialization schemes differ between versions. You may run `net = configure(net,P,T)` followed by `init(net)`, or fix the random seed with `rng` for reproducible results.

Training parameters: Set `net.trainParam.epochs`, `goal`, `mu` and other parameters to match legacy settings. Train the network with `train(net,P,T)`.

Most discrepancies arise from preprocessing and default parameters. Align these items one by one to closely reproduce the network topology and training behavior. Refer to the MATLAB documentation for your specific release for authoritative default behavior.

Leave a Comment