Skip to content

Conversation

@apphp
Copy link

@apphp apphp commented Jan 25, 2026

No description provided.

apphp added 28 commits December 6, 2025 18:55
…hensive unit tests and fixed broken source file link in the documentation
…d updated documentation with fixed source file link. Added `Parametric` interface to define parameterized layers.
…ical stability during inference, and gradient computation logic
…ical stability during inference, and gradient computation logic
…ence/backward passes, unit tests, and documentation updates
…rward/inference/backward passes, unit tests
@apphp apphp requested review from a team and andrewdalpino January 25, 2026 15:02
@apphp apphp removed the request for review from a team January 26, 2026 17:46
@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.

use Stringable;

/**
* Hidden
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

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

The docblock says "Hidden" but this is the Layer interface, not the Hidden interface. This should be corrected to say "Layer" instead of "Hidden".

Suggested change
* Hidden
* Layer

Copilot uses AI. Check for mistakes.
@@ -14,9 +16,8 @@
#[CoversClass(GraphvizTest::class)]
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

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

The CoversClass attribute incorrectly references GraphvizTest::class instead of Graphviz::class. This should be changed to #[CoversClass(Graphviz::class)] to correctly indicate that this test covers the Graphviz class.

Copilot uses AI. Check for mistakes.
/**
* Return an array of hidden layers indexed left to right.
*
* @return list<Layers\Hidden>
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

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

The return type annotation uses Layers\Hidden which is incorrect. It should be list<Hidden> since the proper namespace is already imported with use Rubix\ML\NeuralNet\Layers\Base\Contracts\Hidden; at the top of the file.

Suggested change
* @return list<Layers\Hidden>
* @return list<Hidden>

Copilot uses AI. Check for mistakes.
use NumPower;
use Rubix\ML\NeuralNet\Layers\Base\Contracts\Hidden;
use Rubix\ML\NeuralNet\Layers\Base\Contracts\Input;
use Rubix\ML\NeuralNet\Layers\Base\Contracts\Output;
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

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

The import use Rubix\ML\NeuralNet\Layers\Base\Contracts\Layer; is missing at the top of the file. This is needed because line 127 references Traversable<Layers\Layer> in a docblock. Either add the import and change the reference to Traversable<Layer>, or use the full namespace path in the docblock.

Suggested change
use Rubix\ML\NeuralNet\Layers\Base\Contracts\Output;
use Rubix\ML\NeuralNet\Layers\Base\Contracts\Output;
use Rubix\ML\NeuralNet\Layers\Base\Contracts\Layer;

Copilot uses AI. Check for mistakes.
@@ -0,0 +1,192 @@
<?php

declare(strict_types = 1);
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

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

The spacing in the strict_types declaration is inconsistent with other test files in the codebase. The majority of test files use declare(strict_types=1); without spaces, but this file uses declare(strict_types = 1); with spaces. For consistency, it should match the predominant pattern in the codebase which is without spaces.

Copilot uses AI. Check for mistakes.
}
$expected = NumPower::array([$expected]);

$batchSize = count($this->labels);
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

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

The variable $batchSize is calculated but never used (other than the erroneous call on line 176). This line should be removed.

Copilot uses AI. Check for mistakes.
}

#[Test]
#[TestDox('Computes gradient directly given input, output, expected, and batch size')]
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

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

The TestDox attribute mentions "input, output, expected, and batch size" but the gradient method does not accept a batch size parameter. The description should be updated to remove the mention of "batch size" since it's not actually a parameter to the gradient method.

Copilot uses AI. Check for mistakes.
// Original formulation:
// derivative = (output / input) * (1 - output) + output
// Implemented using NumPower operations to avoid explicit ones matrix.
$term1 = NumPower::divide($output, $input);
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

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

The differentiate method performs division NumPower::divide($output, $input) which could cause division by zero if the input contains zero values. While NumPower might handle this, it would be safer to add a comment explaining the expected behavior or add explicit handling for this edge case.

Copilot uses AI. Check for mistakes.
@@ -0,0 +1,114 @@
<?php

declare(strict_types = 1);
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

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

The spacing in the strict_types declaration is inconsistent with other test files in the codebase. The majority of test files use declare(strict_types=1); without spaces, but this file uses declare(strict_types = 1); with spaces. For consistency, it should match the predominant pattern in the codebase which is without spaces.

Copilot uses AI. Check for mistakes.

$batchSize = count($this->labels);

$gradient = $this->layer->gradient($input, $output, $expected, $batchSize);
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

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

The test calls the gradient method with 4 parameters ($input, $output, $expected, $batchSize), but the Binary::gradient method signature only accepts 3 parameters (NDArray $input, NDArray $output, NDArray $expected). The fourth parameter $batchSize should be removed from this test call since it's not used by the gradient method.

Copilot uses AI. Check for mistakes.
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.

1 participant