Files
Reseaux-de-neurones-artific…/app/Models/NetworkTraining.php
Matthias Guillitte a70b7670e7
Some checks failed
linter / quality (push) Failing after 7s
tests / ci (8.4) (push) Failing after 4s
tests / ci (8.5) (push) Failing after 4s
Use correct naming for iteration and epoch
2026-03-21 09:46:35 +01:00

46 lines
1.3 KiB
PHP

<?php
namespace App\Models;
use App\Events\PerceptronTrainingEnded;
use App\Services\DataSetReader;
use App\Services\IPerceptronIterationEventBuffer;
abstract class NetworkTraining
{
protected int $epoch = 0;
/**
* @abstract
* @var ActivationsFunctions
*/
public ActivationsFunctions $activationFunction;
public function __construct(
protected DataSetReader $datasetReader,
protected int $maxEpochs,
protected IPerceptronIterationEventBuffer $iterationEventBuffer,
protected string $sessionId,
protected string $trainingId,
) {
}
abstract public function start() : void;
abstract protected function stopCondition(): bool;
protected function checkPassedMaxIterations(?float $finalError) {
if ($this->epoch >= $this->maxEpochs) {
$message = 'Le nombre maximal d\'epoch 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->epoch, $this->datasetReader->getLastReadLineIndex(), $error, $synapticWeights);
}
}