Skip to content

394 convert misc nn classes to num power#395

Open
apphp wants to merge 6 commits intoRubixML:3.0from
apphp:394-convert-misc-nn-classes-to-NumPower
Open

394 convert misc nn classes to num power#395
apphp wants to merge 6 commits intoRubixML:3.0from
apphp:394-convert-misc-nn-classes-to-NumPower

Conversation

@apphp
Copy link

@apphp apphp commented Jan 25, 2026

No description provided.

@apphp apphp requested review from a team and andrewdalpino and removed request for a team January 25, 2026 15:02
@andrewdalpino andrewdalpino requested review from a team and Copilot January 28, 2026 17:05
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors various neural network classes to use the NumPower library. It introduces new implementations for neural network layers, networks, snapshots, and their corresponding test files. The changes also update documentation paths to reflect the new class structure organized into subdirectories.

Changes:

  • Adds new neural network layer implementations (Dense, Activation, Binary, Continuous, Multiclass, Dropout, Noise, BatchNorm, PReLU, Swish, Placeholder1D) using NumPower
  • Introduces Network and FeedForward classes with comprehensive test coverage
  • Updates initializers to include explicit loc parameter for NumPower compatibility
  • Updates documentation paths to reflect new directory structure

Reviewed changes

Copilot reviewed 51 out of 51 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
src/NeuralNet/Networks/Network.php New base Network class implementation using NumPower
src/NeuralNet/FeedForwards/FeedForward.php New FeedForward network extending Network
src/NeuralNet/Layers//.php New layer implementations (Dense, Activation, Binary, etc.)
src/NeuralNet/Snapshots/Snapshot.php New snapshot class for network state management
tests/NeuralNet//.php Comprehensive test coverage for new implementations
src/NeuralNet/Initializers//.php Updated to include explicit loc parameter
docs/neural-network/hidden-layers/*.md Documentation path updates
phpunit.xml Memory limit increase for tests

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@apphp apphp self-assigned this Feb 1, 2026
@andrewdalpino
Copy link
Member

Hey @apphp I;m a little confused because I'm seeing some Neural Net layers in this PR and I thought those were handled in a separate PR.

@apphp
Copy link
Author

apphp commented Feb 20, 2026

@andrewdalpino - this PR is based on previous PR #393
(I wrote you about this in Telegram), so when PR #393 will be merged - you will see less changed files here.

@andrewdalpino
Copy link
Member

@apphp Gotcha, it's been targeted at the 3.0 branch even before #393 was merged so that made it confusing. In the future, let's target any sub branches of a "feature" branch at the feature branch instead of the "development" (3.0) branch. That way, the diff will be cleaner and easier to reason about.

*/
public function infer(Dataset $dataset) : NDArray
{
$input = NumPower::transpose(NumPower::array($dataset->samples()), [1, 0]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is working now? I remember you mentioned that we needed first "pack" (using array_values()) the dataset array first?

Copy link
Author

@apphp apphp Mar 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you're right, but later I found a real source of the problem (it doesn't occurs in this PR, only in #397)

The REAL source of the problem was found in Parameter.php in this line of code:
$this->param = clone $this->param;

 ✘ Serialization preserves predict output
   ┐
   ├ Test was run in child process and ended unexpectedly

   ┴

So this line of code was replaced with
$this->param = NumPower::array($this->param->toArray());
with proper explanation.

and now it works as expected.
So, this line is OK:
$input = NumPower::transpose(NumPower::array($dataset->samples()), [1, 0]);
Let's see if it created time running issues, so we can think how to improve this code.

P.S. let's speak with @SkibidiProduction about clone operation for NDArray, because seems it doesn't work correctly.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aha thanks for the backstory that makes alot of sense now, glad we got that worked out! Nice job.

* @author Andrew DalPino
* @author Samuel Akopyan <leumas.a@gmail.com>
*/
class Network
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class looks alot like FeedForward. Why both?

Copy link
Author

@apphp apphp Mar 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is how original Network and FeedForward classes where created.
FeedForward extends Network and they are exactly the same, so I created them in the same way for NumPower

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, I don't doubt that's how they came, but that's definitely not how I intended them to be originally. Network should be an interface.

See the master branch https://github.com/RubixML/ML/blob/master/src/NeuralNet/Network.php

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image You removed this interface 07/05/2023 May it was a reason why?

Copy link
Author

@apphp apphp Mar 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anyway, if you think it was done by mistake - I can convert it back into interface class.
But take in account we have few places in our code, where we create and use Network instance:
$this->network = new Network();

@apphp apphp requested review from SkibidiProduction and andrewdalpino and removed request for SkibidiProduction March 2, 2026 22:13
@apphp apphp closed this Mar 3, 2026
@apphp apphp reopened this Mar 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants