Files
Reseaux-de-neurones-artific…/app/Models/NetworkTraining.php
Matthias Guillitte f0e7be4476
Some checks failed
linter / quality (push) Failing after 18s
tests / ci (8.4) (push) Failing after 10s
tests / ci (8.5) (push) Failing after 11s
Gradient descent training + Added all dataset + graphs improvements
2026-03-13 22:06:08 +01:00

46 lines
1.4 KiB
PHP

<?php
namespace App\Models;
use App\Events\PerceptronTrainingEnded;
use App\Services\DataSetReader;
use App\Services\PerceptronIterationEventBuffer;
abstract class NetworkTraining
{
protected int $iteration = 0;
/**
* @abstract
* @var ActivationsFunctions
*/
public ActivationsFunctions $activationFunction;
public function __construct(
protected DataSetReader $datasetReader,
protected int $maxIterations,
protected PerceptronIterationEventBuffer $iterationEventBuffer,
protected string $sessionId,
protected string $trainingId,
) {
}
abstract public function start() : void;
abstract protected function stopCondition(): bool;
protected function checkPassedMaxIterations(?float $finalError) {
if ($this->iteration >= $this->maxIterations) {
$message = 'Le nombre maximal d\'itérations a été atteint';
if ($finalError) {
$message .= " avec une erreur finale de $finalError";
}
event(new PerceptronTrainingEnded($message, $this->sessionId, $this->trainingId));
}
}
protected function addIterationToBuffer(float $error, array $synapticWeights) {
$this->iterationEventBuffer->addIteration($this->iteration, $this->datasetReader->getLastReadLineIndex(), $error, $synapticWeights);
}
}