Skip to content

400 refactor network class to interface#401

Closed
apphp wants to merge 302 commits intoRubixML:masterfrom
apphp:400-refactor-network-class-to-interface
Closed

400 refactor network class to interface#401
apphp wants to merge 302 commits intoRubixML:masterfrom
apphp:400-refactor-network-class-to-interface

Conversation

@apphp
Copy link

@apphp apphp commented Mar 10, 2026

No description provided.

andrewdalpino and others added 30 commits May 27, 2023 15:54
* Initial commit

* Better testing

* Improve the docs

* Rename benchmark

* Explicitly import max() function
* Add Wrapper interface for models wrappers

* Add WrapperAware trait

* Fix PhpDoc

* Revert "Add WrapperAware trait"

This reverts commit 241abc4.

* Rename Wrapper interface to EstimatorWrapper

* PHP CS fix
* add Swoole backend

* phpstan: ignore swoole

* feat: swoole process scheduler

* fix(swoole): redo tasks when hash collision happens

* chore(swoole): make sure coroutines are at the root of the scheduler

* chore(swoole): set affinity / bind worker to a specific CPU core

* chore(swoole): use igbinary if available

* fix: remove comment

* fix(swoole): worker cpu affinity

* fix(swoole): cpu num

* feat: scheduler improvements

* style

* chore(swoole): remove unnecessary atomics

* chore(swoole): php backwards compatibility

* fix: phpstan, socket message size

* fix: uncomment test

* style: composer fix
* Initial commit

* Allow deltas in units tests
* add Swoole backend

* phpstan: ignore swoole

* feat: swoole process scheduler

* fix(swoole): redo tasks when hash collision happens

* chore(swoole): make sure coroutines are at the root of the scheduler

* chore(swoole): set affinity / bind worker to a specific CPU core

* chore(swoole): use igbinary if available

* fix: remove comment

* fix(swoole): worker cpu affinity

* fix(swoole): cpu num

* feat: scheduler improvements

* style

* chore(swoole): remove unnecessary atomics

* chore(swoole): php backwards compatibility

* fix: phpstan, socket message size

* fix: uncomment test

* style: composer fix

* docs: Swoole backend
* chore: add NumPower to workflow pipeline.

* chore: install openbla.

* chore: install openblas from apt repo.
* Add is_finite checks to skip NAN values

* Tests and fix issue with samples that are all non-finite
apphp added 23 commits January 25, 2026 16:22
…-to-NumPower

394 convert misc nn classes to num power
@apphp apphp requested review from andrewdalpino and Copilot March 10, 2026 23:41
@apphp apphp self-assigned this Mar 10, 2026
@apphp apphp closed this Mar 10, 2026
@apphp apphp reopened this Mar 10, 2026
@apphp apphp closed this Mar 10, 2026
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 upgrades the codebase to a PHP 8.4+/PHPUnit 12 toolchain while refactoring several ML/neural-net components (including network/optimizer/initializer abstractions), updating serialization/backends, and modernizing type declarations across the project.

Changes:

  • Modernize typing/API surfaces (strict_types, typed properties/returns, named args) and update PHPUnit tests to attributes.
  • Add/extend neural-net abstractions and implementations (optimizers, initializers, activation + cost functions, snapshot/shape assertions).
  • Introduce Swoole backend support and change extractor exporting behavior to append-by-default with an overwrite flag.

Reviewed changes

Copilot reviewed 269 out of 584 changed files in this pull request and generated 22 comments.

Show a summary per file
File Description
tests/Backends/Tasks/TrainLearnerTest.php Modernize test (attributes, strict types, named args).
tests/Backends/Tasks/TrainAndValidateTest.php Modernize test (attributes, strict types, named args).
tests/Backends/Tasks/ProbaTest.php Modernize test (attributes, strict types, named args).
tests/Backends/Tasks/PredictTest.php Modernize test (attributes, strict types, named args).
tests/Backends/SwooleTest.php Add Swoole backend test coverage (extension-gated).
tests/Backends/SerialTest.php Modernize backend tests and task construction.
tests/Backends/AmpTest.php Modernize backend tests and task construction.
src/functions.php Tighten iterator_first typing/behavior (now throws on empty).
src/constants.php Bump library VERSION to major-only string.
src/Transformers/TfIdfTransformer.php Rename TF-IDF dampening flag to sublinear.
src/Transformers/MinMaxNormalizer.php Ignore non-finite values in fit/transform/reverseTransform.
src/Transformers/MaxAbsoluteScaler.php Ignore non-finite values when updating max-abs.
src/Transformers/LambdaFunction.php Add mixed typing for context parameter.
src/Transformers/IntervalDiscretizer.php Encode bin ordinals as base-26 strings.
src/Transformers/ImageRotator.php Minor array formatting / trailing comma fix.
src/Transformers/BooleanConverter.php Tighten typing and enforce same-type true/false replacements.
src/Traits/AssertsShapes.php Add shared NDArray shape assertion helper.
src/Strategies/Constant.php Add union typing and return type.
src/Specifications/SwooleExtensionIsLoaded.php Add specification to validate swoole extension availability.
src/Specifications/SpecificationChain.php Remove a stale/incorrect @throws annotation.
src/Serializers/RBX.php Adjust RBX compatibility checks to support format versions range.
src/Regressors/SVR.php Use null-coalescing assignment and add predictSample return type.
src/Regressors/Ridge.php Refactor Ridge to NDArray-based math for training/prediction.
src/Regressors/RegressionTree.php Add predictSample return type.
src/Regressors/RadiusNeighborsRegressor.php Add predictSample return type.
src/Regressors/KNNRegressor.php Add predictSample return type.
src/Regressors/KDNeighborsRegressor.php Add predictSample return type.
src/Regressors/ExtraTreeRegressor.php Add predictSample return type.
src/Regressors/Adaline.php Refactor network type to Network interface.
src/Pipeline.php Add __call() return type mixed.
src/PersistentModel.php Use null-coalescing assignment and add __call() return type mixed.
src/NeuralNet/Snapshots/Snapshot.php Add snapshot/restore of parametric layer parameters.
src/NeuralNet/Parameter.php Add __clone() return type void.
src/NeuralNet/Optimizers/Stochastic/Stochastic.php Add SGD optimizer implementation under new namespace.
src/NeuralNet/Optimizers/Cyclical.php Fix typo in exception message.
src/NeuralNet/Optimizers/Base/Optimizer.php Add Optimizer interface contract.
src/NeuralNet/Optimizers/Base/Adaptive.php Add Adaptive optimizer contract.
src/NeuralNet/Networks/Base/Contracts/Network.php Add base network contract for layers traversal.
src/NeuralNet/Network.php Update attribution in Network interface.
src/NeuralNet/Layers/Binary.php Add explanatory comment for BCE+sigmoid gradient shortcut.
src/NeuralNet/Layers/Base/Contracts/Parametric.php Add Parametric layer contract for parameters/restore.
src/NeuralNet/Layers/Base/Contracts/Output.php Add Output layer contract for backprop endpoint.
src/NeuralNet/Layers/Base/Contracts/Layer.php Add Layer contract using NDArray forward/infer.
src/NeuralNet/Layers/Base/Contracts/Input.php Add Input marker interface.
src/NeuralNet/Layers/Base/Contracts/Hidden.php Add Hidden layer backprop contract.
src/NeuralNet/Initializers/Xavier/XavierUniform.php Add Xavier uniform initializer.
src/NeuralNet/Initializers/Xavier/XavierNormal.php Add Xavier normal initializer.
src/NeuralNet/Initializers/Uniform/Uniform.php Add Uniform initializer and beta validation.
src/NeuralNet/Initializers/Uniform/Exceptions/InvalidBetaException.php Add custom exception for invalid beta.
src/NeuralNet/Initializers/Normal/TruncatedNormal.php Add truncated normal initializer with validation.
src/NeuralNet/Initializers/Normal/Normal.php Add normal initializer with validation.
src/NeuralNet/Initializers/Normal/Exceptions/InvalidStandardDeviationException.php Add custom exception for invalid std dev.
src/NeuralNet/Initializers/LeCun/LeCunUniform.php Add LeCun uniform initializer.
src/NeuralNet/Initializers/LeCun/LeCunNormal.php Add LeCun normal initializer.
src/NeuralNet/Initializers/He/HeUniform.php Add He uniform initializer.
src/NeuralNet/Initializers/He/HeNormal.php Add He normal initializer.
src/NeuralNet/Initializers/Constant/Constant.php Add constant initializer.
src/NeuralNet/Initializers/Base/Initializer.php Add Initializer interface.
src/NeuralNet/Initializers/Base/Exceptions/InvalidFanOutException.php Add invalid fanOut exception.
src/NeuralNet/Initializers/Base/Exceptions/InvalidFanInException.php Add invalid fanIn exception.
src/NeuralNet/Initializers/Base/AbstractInitializer.php Add shared fanIn/fanOut validation base class.
src/NeuralNet/CostFunctions/RelativeEntropy/RelativeEntropy.php Add KL-divergence style classification loss.
src/NeuralNet/CostFunctions/MeanAbsoluteError/MeanAbsoluteError.php Add MAE regression loss.
src/NeuralNet/CostFunctions/LeastSquares/LeastSquares.php Add least-squares regression loss.
src/NeuralNet/CostFunctions/HuberLoss/Exceptions/InvalidAlphaException.php Add custom exception for invalid HuberLoss alpha.
src/NeuralNet/CostFunctions/Base/Contracts/RegressionLoss.php Add RegressionLoss marker contract.
src/NeuralNet/CostFunctions/Base/Contracts/CostFunction.php Add CostFunction interface contract.
src/NeuralNet/CostFunctions/Base/Contracts/ClassificationLoss.php Add ClassificationLoss marker contract.
src/NeuralNet/ActivationFunctions/ThresholdedReLU/ThresholdedReLU.php Add ThresholdedReLU activation function.
src/NeuralNet/ActivationFunctions/ThresholdedReLU/Exceptions/InvalidThresholdException.php Add invalid threshold exception.
src/NeuralNet/ActivationFunctions/Softsign/Softsign.php Add Softsign activation function.
src/NeuralNet/ActivationFunctions/Softplus/Softplus.php Add Softplus activation function.
src/NeuralNet/ActivationFunctions/Sigmoid/Sigmoid.php Add Sigmoid activation function (output-buffer derivative).
src/NeuralNet/ActivationFunctions/SiLU/SiLU.php Add SiLU activation function.
src/NeuralNet/ActivationFunctions/ReLU6/ReLU6.php Add ReLU6 activation function.
src/NeuralNet/ActivationFunctions/ReLU/ReLU.php Add ReLU activation function.
src/NeuralNet/ActivationFunctions/LeakyReLU/Exceptions/InvalidLeakageException.php Add invalid leakage exception.
src/NeuralNet/ActivationFunctions/HyperbolicTangent/HyperbolicTangent.php Add tanh activation function.
src/NeuralNet/ActivationFunctions/HardSiLU/HardSiLU.php Add HardSiLU activation function.
src/NeuralNet/ActivationFunctions/ELU/Exceptions/InvalidAlphaException.php Add invalid alpha exception.
src/NeuralNet/ActivationFunctions/Base/Contracts/OBufferDerivative.php Add output-buffer derivative contract.
src/NeuralNet/ActivationFunctions/Base/Contracts/IOBufferDerivative.php Add input/output-buffer derivative contract.
src/NeuralNet/ActivationFunctions/Base/Contracts/IBufferDerivative.php Add input-buffer derivative contract.
src/NeuralNet/ActivationFunctions/Base/Contracts/Derivative.php Add derivative marker interface.
src/NeuralNet/ActivationFunctions/Base/Contracts/ActivationFunction.php Add ActivationFunction interface contract.
src/Loggers/Screen.php Update logger to accept Stringable messages safely.
src/Loggers/BlackHole.php Update logger signature to accept Stringable messages.
src/Helpers/Stats.php Tighten typing and use null-coalescing assignment.
src/Helpers/Params.php Update toString signature to accept mixed.
src/GridSearch.php Add __call() return type mixed.
src/Graph/Nodes/Split.php Add union typing for split value and return type.
src/Graph/Nodes/Outcome.php Add return type to outcome() in interface.
src/Graph/Nodes/Isolator.php Add union typing for split value and return type.
src/Graph/Nodes/Depth.php Remove stale/incorrect @throws annotation.
src/Graph/Nodes/Box.php Add union typing for split value and return type.
src/Graph/Nodes/Best.php Remove stale/incorrect @throws annotation.
src/Graph/Nodes/Average.php Add union typing and return type.
src/Extractors/NDJSON.php Add overwrite flag; switch to append-by-default.
src/Extractors/Exporter.php Add overwrite parameter to Exporter interface.
src/Extractors/CSV.php Add overwrite flag; switch to append-by-default; improve errors.
src/Exceptions/ClassRevisionMismatch.php Improve exception message clarity.
src/Deferred.php Add mixed return types for compute() and __invoke().
src/Datasets/Unlabeled.php Type splitByFeature value parameter.
src/Datasets/Labeled.php Add return type for label(); type splitByFeature value parameter.
src/Datasets/Dataset.php Add overwrite flag to exportTo(); type splitByFeature value parameter.
src/DataType.php Use mixed typing and adjust type detection logic.
src/CrossValidation/Metrics/Metric.php Docblock tag ordering tweak.
src/CommitteeMachine.php Add decideDiscrete return type.
src/Clusterers/MeanShift.php Use null-coalescing assignment.
src/Classifiers/SoftmaxClassifier.php Refactor network type to Network interface.
src/Classifiers/SVC.php Use null-coalescing assignment.
src/Classifiers/LogisticRegression.php Refactor network type to Network interface; add __unserialize workaround.
src/Classifiers/AdaBoost.php Update phpdoc types; use nullsafe logger call.
src/BootstrapAggregator.php Add typed constants/docs; improve typing around backend processing.
src/Backends/Tasks/TrainAndValidate.php Clarify labels type and use named args for metric score.
src/Backends/Serial.php Type backend enqueue context parameter as mixed.
src/Backends/Backend.php Type backend enqueue context parameter as mixed.
src/Backends/Amp.php Use null-coalescing assignment; type context parameters as mixed.
src/AnomalyDetectors/RobustZScore.php Add typed constant; adjust epsilon smoothing code.
src/AnomalyDetectors/OneClassSVM.php Use null-coalescing assignment.
src/AnomalyDetectors/Loda.php Adjust phpdoc return array types and add inline non-empty annotation.
src/AnomalyDetectors/GaussianMLE.php Adjust epsilon smoothing code.
phpunit.xml Rework PHPUnit configuration (source/test suites/display details).
phpstan.neon Add baseline, PHP version config, and exclude Swoole paths.
docs/transformers/tf-idf-transformer.md Update TF-IDF parameter name and related guidance.
docs/transformers/regex-filter.md Fix predefined patterns table ordering/format.
docs/regressors/mlp-regressor.md Update MLP regressor params (eval interval / remove l2Penalty).
docs/regressors/gradient-boost.md Update GBM params (eval interval).
docs/neural-network/optimizers/stochastic.md Update optimizer namespace and add math section.
docs/neural-network/optimizers/step-decay.md Update optimizer namespace and add math section.
docs/neural-network/optimizers/rms-prop.md Update optimizer namespace and add math section.
docs/neural-network/optimizers/momentum.md Update optimizer namespace and add math section.
docs/neural-network/optimizers/cyclical.md Update optimizer namespace and add math section.
docs/neural-network/optimizers/adamax.md Update optimizer namespace and add math section.
docs/neural-network/optimizers/adam.md Update optimizer namespace and add math section.
docs/neural-network/optimizers/adagrad.md Update optimizer namespace and add math section.
docs/neural-network/hidden-layers/swish.md Update layer/initializer namespaces.
docs/neural-network/hidden-layers/prelu.md Update layer/initializer namespaces.
docs/neural-network/hidden-layers/placeholder1d.md Add Placeholder1D layer documentation.
docs/neural-network/hidden-layers/noise.md Update layer namespace.
docs/neural-network/hidden-layers/dropout.md Update layer namespace.
docs/neural-network/hidden-layers/dense.md Update layer namespace.
docs/neural-network/hidden-layers/batch-norm.md Update layer/initializer namespaces.
docs/neural-network/hidden-layers/activation.md Update layer/activation namespaces.
docs/neural-network/cost-functions/relative-entropy.md Update cost function namespace.
docs/neural-network/cost-functions/mean-absolute-error.md Add MAE cost function documentation.
docs/neural-network/cost-functions/least-squares.md Update cost function namespace.
docs/neural-network/cost-functions/huber-loss.md Reformat math block for clarity.
docs/neural-network/cost-functions/cross-entropy.md Update cost function namespace.
docs/neural-network/activation-functions/thresholded-relu.md Update namespace, add plots, improve math.
docs/neural-network/activation-functions/softsign.md Update namespace, add plots, references formatting.
docs/neural-network/activation-functions/softplus.md Add Softplus documentation.
docs/neural-network/activation-functions/softmax.md Update namespace, improve math/plots.
docs/neural-network/activation-functions/soft-plus.md Remove legacy Soft Plus doc (replaced by softplus).
docs/neural-network/activation-functions/silu.md Update namespace, add math/plots.
docs/neural-network/activation-functions/sigmoid.md Update namespace, add plots.
docs/neural-network/activation-functions/selu.md Update namespace, improve math/plots.
docs/neural-network/activation-functions/relu6.md Add ReLU6 documentation.
docs/neural-network/activation-functions/relu.md Update namespace, improve math/plots and refs.
docs/neural-network/activation-functions/leaky-relu.md Update namespace, improve math/plots and refs.
docs/neural-network/activation-functions/hyperbolic-tangent.md Update namespace, add plots.
docs/neural-network/activation-functions/hard-silu.md Add HardSiLU documentation.
docs/neural-network/activation-functions/hard-sigmoid.md Add HardSigmoid documentation.
docs/neural-network/activation-functions/gelu.md Update namespace, add math/plots.
docs/neural-network/activation-functions/elu.md Update namespace, improve math/plots and refs.
docs/installation.md Update docs to PHP 8+ stated requirement.
docs/extractors/api.md Document new overwrite behavior for exporters.
docs/exploring-data.md Adjust dataset export examples for overwrite flag.
docs/datasets/api.md Document dataset exportTo overwrite flag.
docs/classifiers/multilayer-perceptron.md Update MLP classifier params (eval interval / remove l2Penalty).
docs/classifiers/logit-boost.md Update LogitBoost params (eval interval).
docs/backends/swoole.md Add backend documentation for Swoole.
composer.json Bump PHP requirement, add ext-rubixnumpower, update dev tooling versions.
benchmarks/Transformers/TSNEBench.php Fix phpdoc syntax.
benchmarks/Tokenizers/WordStemmerBench.php Add typed constants/properties and imports.
benchmarks/Tokenizers/WordBench.php Add typed constants/properties and imports.
benchmarks/Tokenizers/WhitespaceBench.php Add typed constants/properties and imports.
benchmarks/Tokenizers/SentenceBench.php Add typed constants/properties and imports.
benchmarks/Tokenizers/NGramBench.php Add typed constants/properties and imports.
benchmarks/Tokenizers/KSkipNGramBench.php Add typed constants/properties and imports.
benchmarks/Regressors/SVRBench.php Add typed constants/properties and imports.
benchmarks/Regressors/RidgeBench.php Add typed constants/properties and imports.
benchmarks/Regressors/RegressionTreeBench.php Add typed constants/properties and imports.
benchmarks/Regressors/RadiusNeighborsRegressorBench.php Add typed constants/properties and imports.
benchmarks/Regressors/MLPRegressorBench.php Add typed constants/properties and imports.
benchmarks/Regressors/KNNRegressorBench.php Add typed constants/properties and imports.
benchmarks/Regressors/KDNeighborsRegressorBench.php Add typed constants/properties and imports.
benchmarks/Regressors/GradientBoostBench.php Add typed constants/properties and imports.
benchmarks/Regressors/ExtraTreeRegressorBench.php Add typed constants/properties and imports.
benchmarks/Regressors/AdalineBench.php Add typed constants/properties and imports.
benchmarks/Graph/Trees/VantageTreeBench.php Fix phpdoc syntax.
benchmarks/Graph/Trees/KDTreeBench.php Fix phpdoc syntax.
benchmarks/Graph/Trees/BallTreeBench.php Fix phpdoc syntax.
benchmarks/Datasets/SplittingBench.php Fix phpdoc syntax.
benchmarks/Datasets/SortingBench.php Fix phpdoc syntax.
benchmarks/Datasets/RandomizationBench.php Fix phpdoc syntax.
benchmarks/Clusterers/MeanShiftBench.php Add typed constants/properties and imports.
benchmarks/Classifiers/SoftmaxClassifierBench.php Add typed constants/properties and imports.
benchmarks/Classifiers/SVCBench.php Add typed constants/properties and imports.
benchmarks/Classifiers/RandomForestBench.php Add backend param provider integration; typed properties.
benchmarks/Classifiers/RadiusNeighborsBench.php Add typed constants/properties and imports.
benchmarks/Classifiers/OneVsRestBench.php Add backend param provider integration; typed properties.
benchmarks/Classifiers/NaiveBayesBench.php Add typed constants/properties and imports.
benchmarks/Classifiers/MultilayerPerceptronBench.php Add typed constants/properties and imports.
benchmarks/Classifiers/LogitBoostBench.php Add typed constants/properties and imports.
benchmarks/Classifiers/LogisticRegressionBench.php Add typed constants/properties and imports.
benchmarks/Classifiers/KNearestNeighborsBench.php Add typed constants/properties and imports.
benchmarks/Classifiers/KDNeighborsBench.php Add typed constants/properties and imports.
benchmarks/Classifiers/GaussianNBBench.php Add typed constants/properties and imports.
benchmarks/Classifiers/ExtraTreeClassifierBench.php Add typed constants/properties and imports.
benchmarks/Classifiers/ClassificationTreeBench.php Add typed constants/properties and imports.
benchmarks/Classifiers/AdaBoostBench.php Add typed constants/properties and imports.
benchmarks/AnomalyDetectors/RobustZScoreBench.php Add typed constants/properties and imports.
benchmarks/AnomalyDetectors/OneClassSVMBench.php Add typed constants/properties and imports.
benchmarks/AnomalyDetectors/LodaBench.php Add typed constants/properties and imports.
benchmarks/AnomalyDetectors/LocalOutlierFactorBench.php Add typed constants/properties and imports.
benchmarks/AnomalyDetectors/IsolationForestBench.php Add typed constants/properties and imports.
benchmarks/AnomalyDetectors/GaussianMLEBench.php Add typed constants/properties and imports.
README.md Update stated PHP requirement.
CHANGELOG.md Add 3.0.0 release notes and other entries.
.phplint.yml Add PHPLint configuration.
.php-cs-fixer.dist.php Update CS fixer finder/rules for PHP 8.4 and caching.
.github/workflows/ci.yml Update CI matrix and add NumPower build/install steps.

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

Comment on lines +168 to 175
function iterator_first(iterable $iterator) : mixed
{
foreach ($iterator as $element) {
return $element;
}

throw new RuntimeException('Iterator did not return any elements.');
}
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

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

In a namespaced file, RuntimeException resolves to Rubix\\ML\\RuntimeException unless qualified/imported. This will fatally error if that class does not exist. Use \\RuntimeException (global) or import/qualify the intended exception class.

Copilot uses AI. Check for mistakes.
*/
protected ?Vector $coefficients = null;

protected ?nd $coefficientsNd = null;
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

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

$this->coefficientsNd appears to include the bias term (since you array_shift() the first element into $this->bias but keep $this->coefficientsNd unchanged). In predict(), you dot datasetNd (shape: n_samples × n_features) with $this->coefficientsNd (likely length n_features+1), which will cause a shape mismatch or incorrect results. Fix by either (a) storing $this->coefficientsNd without the bias term, or (b) augmenting the dataset matrix with a bias column (ones) and omitting the explicit + $this->bias.

Copilot uses AI. Check for mistakes.

$x = Matrix::build($dataset->samples())->augmentLeft($biases);
$y = Vector::build($dataset->labels());
$y = nd::array($dataset->labels());
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

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

$this->coefficientsNd appears to include the bias term (since you array_shift() the first element into $this->bias but keep $this->coefficientsNd unchanged). In predict(), you dot datasetNd (shape: n_samples × n_features) with $this->coefficientsNd (likely length n_features+1), which will cause a shape mismatch or incorrect results. Fix by either (a) storing $this->coefficientsNd without the bias term, or (b) augmenting the dataset matrix with a bias column (ones) and omitting the explicit + $this->bias.

Copilot uses AI. Check for mistakes.
$this->coefficientsNd = nd::dot($xMulAddInv, $xtDotY);
$coefficients = $this->coefficientsNd->toArray();

$this->bias = (float) array_shift($coefficients);
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

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

$this->coefficientsNd appears to include the bias term (since you array_shift() the first element into $this->bias but keep $this->coefficientsNd unchanged). In predict(), you dot datasetNd (shape: n_samples × n_features) with $this->coefficientsNd (likely length n_features+1), which will cause a shape mismatch or incorrect results. Fix by either (a) storing $this->coefficientsNd without the bias term, or (b) augmenting the dataset matrix with a bias column (ones) and omitting the explicit + $this->bias.

Suggested change
$this->bias = (float) array_shift($coefficients);
$this->bias = (float) array_shift($coefficients);
$this->coefficientsNd = nd::array($coefficients);

Copilot uses AI. Check for mistakes.
Comment on lines +208 to +211
$datasetNd = nd::array($dataset->samples());
$datasetDotCoefficients = nd::dot($datasetNd, $this->coefficientsNd);

return nd::add($datasetDotCoefficients, $this->bias)->toArray();
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

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

$this->coefficientsNd appears to include the bias term (since you array_shift() the first element into $this->bias but keep $this->coefficientsNd unchanged). In predict(), you dot datasetNd (shape: n_samples × n_features) with $this->coefficientsNd (likely length n_features+1), which will cause a shape mismatch or incorrect results. Fix by either (a) storing $this->coefficientsNd without the bias term, or (b) augmenting the dataset matrix with a bias column (ones) and omitting the explicit + $this->bias.

Copilot uses AI. Check for mistakes.

return new self(self::OTHER);

default:
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

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

Image detection via GD appears to have been removed entirely. In PHP 8+, GD commonly returns a \\GdImage object (not a resource), so falling through to OTHER will regress image support. Consider explicitly handling object values that are instances of \\GdImage to return self::IMAGE (or equivalent).

Copilot uses AI. Check for mistakes.
Comment on lines 118 to 119
return new self(self::OTHER);
}
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

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

Image detection via GD appears to have been removed entirely. In PHP 8+, GD commonly returns a \\GdImage object (not a resource), so falling through to OTHER will regress image support. Consider explicitly handling object values that are instances of \\GdImage to return self::IMAGE (or equivalent).

Copilot uses AI. Check for mistakes.
- Remove Network interface
- RBX Serializer only tracks major library version number
- Convert NeuralNet classes to use NDArray instead of Matrix
- Turn back Network interface
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

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

These entries are contradictory as written and make it unclear what actually changed in 3.0.0. Please reconcile into a single accurate bullet (e.g., 'Replaced concrete Network with interface', or 'Renamed/moved Network contract') to avoid confusing release notes.

Suggested change
- Turn back Network interface

Copilot uses AI. Check for mistakes.
@@ -20,7 +22,7 @@ class BlackHole extends Logger
* @param string $message
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

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

The docblock still says @param string $message but the method signature now accepts string|Stringable. Update the docblock to match the new accepted types.

Suggested change
* @param string $message
* @param string|Stringable $message

Copilot uses AI. Check for mistakes.
use Rubix\ML\Specifications\SwooleExtensionIsLoaded;
use Swoole\Event;

#[Group('backends')]
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

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

Group naming is inconsistent with other backend tests using #[Group('Backends')] (capitalized). Consider standardizing group names/casing to make filtered runs (--group) predictable.

Suggested change
#[Group('backends')]
#[Group('Backends')]

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.

8 participants