Use correct naming for iteration and epoch
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

This commit is contained in:
2026-03-21 09:46:35 +01:00
parent 6abb417430
commit a70b7670e7
8 changed files with 38 additions and 37 deletions

View File

@@ -4,8 +4,8 @@ namespace App\Models;
use App\Events\PerceptronTrainingEnded;
use App\Services\DataSetReader;
use App\Services\IPerceptronIterationEventBuffer;
use App\Services\ISynapticWeightsProvider;
use App\Services\PerceptronIterationEventBuffer;
class SimpleBinaryPerceptronTraining extends NetworkTraining
{
@@ -19,25 +19,25 @@ class SimpleBinaryPerceptronTraining extends NetworkTraining
public function __construct(
DataSetReader $datasetReader,
protected float $learningRate,
int $maxIterations,
int $maxEpochs,
protected ISynapticWeightsProvider $synapticWeightsProvider,
PerceptronIterationEventBuffer $iterationEventBuffer,
IPerceptronIterationEventBuffer $iterationEventBuffer,
string $sessionId,
string $trainingId,
) {
parent::__construct($datasetReader, $maxIterations, $iterationEventBuffer, $sessionId, $trainingId);
parent::__construct($datasetReader, $maxEpochs, $iterationEventBuffer, $sessionId, $trainingId);
$this->perceptron = new SimpleBinaryPerceptron($synapticWeightsProvider->generate($datasetReader->getInputSize()));
}
public function start(): void
{
$this->iteration = 0;
$this->epoch = 0;
$error = 0;
do {
$this->iterationErrorCounter = 0;
$this->iteration++;
$this->epoch++;
while ($nextRow = $this->datasetReader->getRandomLine()) {
while ($nextRow = $this->datasetReader->getNextLine()) {
$inputs = array_slice($nextRow, 0, -1);
$correctOutput = (float) end($nextRow);
$correctOutput = $correctOutput > 0 ? 1 : 0; // Modify labels for non binary datasets
@@ -48,7 +48,7 @@ class SimpleBinaryPerceptronTraining extends NetworkTraining
$this->addIterationToBuffer($error, [[$this->perceptron->getSynapticWeights()]]);
}
$this->datasetReader->reset(); // Reset the dataset for the next iteration
} while ($this->iteration < $this->maxIterations && !$this->stopCondition());
} while ($this->epoch < $this->maxEpochs && !$this->stopCondition());
$this->iterationEventBuffer->flush(); // Ensure all iterations are sent to the frontend