Files
Reseaux-de-neurones-artific…/app/Models/NetworksTraining/NetworkTraining.php
Matthias Guillitte ef90236adc
Some checks failed
linter / quality (push) Failing after 6m26s
tests / ci (8.4) (push) Successful in 5m6s
tests / ci (8.5) (push) Successful in 5m38s
Fix linting
2026-03-23 08:44:50 +01:00

55 lines
1.5 KiB
PHP

<?php
namespace App\Models\NetworksTraining;
use App\Events\PerceptronTrainingEnded;
use App\Models\ActivationsFunctions;
use App\Services\DatasetReader\IDataSetReader;
use App\Services\IterationEventBuffer\IPerceptronIterationEventBuffer;
abstract class NetworkTraining
{
protected int $epoch = 0;
/**
* @abstract
*/
public ActivationsFunctions $activationFunction;
public function __construct(
protected IDataSetReader $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);
}
public function getEpoch(): int
{
return $this->epoch;
}
abstract public function getSynapticWeights(): array;
}