Use correct naming for iteration and epoch
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user