Conversation
There was a problem hiding this comment.
Pull request overview
This PR reintroduces a neural-network “Network” interface and updates instantiation sites/tests to construct FeedForward networks instead of the removed Network concrete class, alongside reorganizing the NDArray-based network code under NeuralNet\Networks\Base\....
Changes:
- Replace
new Network(...)withnew FeedForward(...)across learners and tests. - Introduce
src/NeuralNet/Networks/Base/Contracts/Network.phpand refactor the NDArray-basedFeedForwardnetwork to implement it; remove the oldsrc/NeuralNet/Networks/Network.php. - Update snapshot/network tests and adjust one Swish layer expected value; update changelog entries.
Reviewed changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/NeuralNet/Snapshots/SnapshotTest.php | Switch snapshot test to NDArray “Base” FeedForward + new Network contract. |
| tests/NeuralNet/SnapshotTest.php | Switch legacy snapshot test to instantiate FeedForward instead of Network. |
| tests/NeuralNet/Networks/NetworkTest.php | Update NDArray network test imports and construction to use Base FeedForward. |
| tests/NeuralNet/NetworkTest.php | Switch legacy network test construction to FeedForward. |
| tests/NeuralNet/Layers/Swish/SwishTest.php | Update expected numeric output to match current computation. |
| tests/NeuralNet/FeedForwards/FeedForwardTest.php | Point feedforward tests at Base FeedForward and new contracts. |
| src/Regressors/MLPRegressor.php | Use FeedForward for the underlying network construction. |
| src/Regressors/Adaline.php | Use FeedForward for the underlying network construction. |
| src/NeuralNet/Snapshots/Snapshot.php | Update snapshot to accept Base Network contract. |
| src/NeuralNet/Networks/Network.php | Remove the old NDArray Network concrete class. |
| src/NeuralNet/Networks/Base/FeedForward/FeedForward.php | Move/rename Base FeedForward, implement Base Network contract, add sample-normalization branch. |
| src/NeuralNet/Networks/Base/Contracts/Network.php | Add Base Network interface (input/hidden/output/layers). |
| src/NeuralNet/Network.php | Convert legacy Network to an interface (currently only layers()). |
| src/NeuralNet/FeedForward.php | Update legacy FeedForward to implement the legacy Network interface. |
| src/Classifiers/SoftmaxClassifier.php | Construct FeedForward network instead of Network. |
| src/Classifiers/MultilayerPerceptron.php | Construct FeedForward network instead of Network. |
| src/Classifiers/LogisticRegression.php | Construct FeedForward network instead of Network. |
| CHANGELOG.md | Note NDArray conversion + “converted back Network interface” entry. |
Comments suppressed due to low confidence (2)
src/NeuralNet/Networks/Base/FeedForward/FeedForward.php:214
- The empty-dataset fast path (
if ($dataset->empty()) return ...) and the 1D-shape reshape are currently guarded by$this->normalizeSamples, but that flag is never enabled. If these safeguards are needed to avoid NumPower edge cases, they should be applied unconditionally (or the flag needs to be configurable) so inference on empty/non-packed samples is actually protected.
src/NeuralNet/Networks/Base/FeedForward/FeedForward.php:101 $this->normalizeSamplesis initialized tofalseand the property isprivate, but there is no constructor parameter or method to ever set it totrue(confirmed by repo-wide search). This makes the normalization/reshape logic ininfer()and thenormalizeSamples()helper effectively dead code. Consider either removing the flag and always normalizing (if required for NumPower), or exposing a supported way to enable it (constructor arg or public setter).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
andrewdalpino
left a comment
There was a problem hiding this comment.
Left some comments for you @apphp
| * @param array $samples | ||
| * @return array | ||
| */ | ||
| private function normalizeSamples(array $samples) : array |
There was a problem hiding this comment.
Let's avoid using the word "normalize" here as it's already used in the library to mean different things and this departs from the typical ML usage of the word.
Instead I would recommend something like packSamples(), or arrayToPackedArray().
In addition, since this is just a general function it does not need to be a method. If you prefer to make it a member of the class make it a static member instead otherwise consider implementing this as a helper function.
| $this->optimizer = $optimizer; | ||
| $this->backPass = $backPass; | ||
|
|
||
| $this->normalizeSamples = false; |
There was a problem hiding this comment.
This looks like a constant. If so, remove it including the conditional logic in the infer() method. If not, provide an API for changing its value.
Why do we not always pack the samples array?

No description provided.