cii-text-analysis/vendor/rubix/ml/benchmarks/Classifiers/MultilayerPerceptronBench.php
Jéremy Munsch f68d2ac333
premier poc
2026-02-11 08:24:04 +01:00

65 lines
1.5 KiB
PHP

<?php
namespace Rubix\ML\Benchmarks\Classifiers;
use Rubix\ML\NeuralNet\Layers\Dense;
use Rubix\ML\Datasets\Generators\Blob;
use Rubix\ML\NeuralNet\Layers\Activation;
use Rubix\ML\Datasets\Generators\Agglomerate;
use Rubix\ML\Classifiers\MultilayerPerceptron;
use Rubix\ML\NeuralNet\ActivationFunctions\ReLU;
/**
* @Groups({"Classifiers"})
* @BeforeMethods({"setUp"})
*/
class MultilayerPerceptronBench
{
protected const TRAINING_SIZE = 2500;
protected const TESTING_SIZE = 10000;
/**
* @var \Rubix\ML\Datasets\Labeled;
*/
protected $training;
/**
* @var \Rubix\ML\Datasets\Labeled;
*/
protected $testing;
/**
* @var \Rubix\ML\Classifiers\MultilayerPerceptron
*/
protected $estimator;
public function setUp() : void
{
$generator = new Agglomerate([
'Iris-setosa' => new Blob([5.0, 3.42, 1.46, 0.24], [0.35, 0.38, 0.17, 0.1]),
'Iris-virginica' => new Blob([6.59, 2.97, 5.55, 2.03], [0.63, 0.32, 0.55, 0.27]),
]);
$this->training = $generator->generate(self::TRAINING_SIZE);
$this->testing = $generator->generate(self::TESTING_SIZE);
$this->estimator = new MultilayerPerceptron([
new Dense(100),
new Activation(new ReLU()),
]);
}
/**
* @Subject
* @Iterations(3)
* @OutputTimeUnit("seconds", precision=3)
*/
public function trainPredict() : void
{
$this->estimator->train($this->training);
$this->estimator->predict($this->testing);
}
}