Wiki
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace App\Models\NetworksTraining;
|
||||
|
||||
use App\Events\PerceptronTrainingEnded;
|
||||
use App\Models\ActivationsFunctions;
|
||||
use App\Models\Perceptrons\GradientDescentPerceptron;
|
||||
use App\Models\Perceptrons\Perceptron;
|
||||
@@ -84,7 +83,7 @@ class ADALINEPerceptronTraining extends NetworkTraining
|
||||
{
|
||||
$condition = $this->epochError <= $this->minError;
|
||||
if ($condition === true) {
|
||||
event(new PerceptronTrainingEnded('Le perceptron à atteint l\'erreur minimale', $this->sessionId, $this->trainingId));
|
||||
$this->broadcastTrainingEnded('Le perceptron à atteint l\'erreur minimale');
|
||||
}
|
||||
|
||||
return $condition;
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace App\Models\NetworksTraining;
|
||||
|
||||
use App\Events\PerceptronTrainingEnded;
|
||||
use App\Models\ActivationsFunctions;
|
||||
use App\Models\Perceptrons\GradientDescentPerceptron;
|
||||
use App\Models\Perceptrons\Perceptron;
|
||||
@@ -80,7 +79,7 @@ class GradientDescentPerceptronTraining extends NetworkTraining
|
||||
{
|
||||
$condition = $this->epochError <= $this->minError;
|
||||
if ($condition === true) {
|
||||
event(new PerceptronTrainingEnded('Le perceptron à atteint l\'erreur minimale', $this->sessionId, $this->trainingId));
|
||||
$this->broadcastTrainingEnded('Le perceptron à atteint l\'erreur minimale');
|
||||
}
|
||||
|
||||
return $condition;
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace App\Models\NetworksTraining;
|
||||
|
||||
use App\Events\PerceptronTrainingEnded;
|
||||
use App\Models\ActivationsFunctions;
|
||||
use App\Models\Perceptrons\GradientDescentPerceptron;
|
||||
use App\Models\Perceptrons\NetworkPerceptron;
|
||||
@@ -19,6 +18,8 @@ class MonoLayerPerceptronTraining extends NetworkTraining
|
||||
|
||||
private array $labels;
|
||||
|
||||
private bool $isRegression;
|
||||
|
||||
public ActivationsFunctions $activationFunction = ActivationsFunctions::LINEAR;
|
||||
|
||||
public ?ActivationsFunctions $presentationLayerActivationFunction = ActivationsFunctions::STEP;
|
||||
@@ -36,11 +37,12 @@ class MonoLayerPerceptronTraining extends NetworkTraining
|
||||
private float $minError,
|
||||
) {
|
||||
parent::__construct($datasetReader, $maxEpochs, $iterationEventBuffer, $sessionId, $trainingId);
|
||||
$this->isRegression = $datasetReader->getInputSize() === 1;
|
||||
$networkWeightsProvider = new SimpleNetworkWeightsProvider($synapticWeightsProvider);
|
||||
$this->network = new NetworkPerceptron(
|
||||
$networkWeightsProvider->generate(
|
||||
$datasetReader->getInputSize(),
|
||||
$datasetReader->getOutputSize(),
|
||||
$this->isRegression ? 1 : $datasetReader->getOutputSize(),
|
||||
0, // No hidden layer
|
||||
0, // No hidden layer neurons
|
||||
),
|
||||
@@ -103,7 +105,7 @@ class MonoLayerPerceptronTraining extends NetworkTraining
|
||||
{
|
||||
$condition = $this->epochError <= $this->minError;
|
||||
if ($condition === true) {
|
||||
event(new PerceptronTrainingEnded('Le perceptron à atteint l\'erreur minimale', $this->sessionId, $this->trainingId));
|
||||
$this->broadcastTrainingEnded('Le perceptron à atteint l\'erreur minimale');
|
||||
}
|
||||
|
||||
return $condition;
|
||||
@@ -140,6 +142,10 @@ class MonoLayerPerceptronTraining extends NetworkTraining
|
||||
|
||||
private function getDesiredOutputFromCorrectOutput(float $correctOutput): array
|
||||
{
|
||||
if ($this->isRegression) {
|
||||
return [$correctOutput];
|
||||
}
|
||||
|
||||
$desiredOutput = array_fill(0, count($this->labels), -1);
|
||||
$labelIndex = Arr::first(array_keys($this->labels), fn ($key) => $this->labels[$key] == $correctOutput);
|
||||
if ($labelIndex !== null) {
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace App\Models\NetworksTraining;
|
||||
|
||||
use App\Events\PerceptronTrainingEnded;
|
||||
use App\Models\ActivationsFunctions;
|
||||
use App\Models\Perceptrons\GradientDescentPerceptron;
|
||||
use App\Models\Perceptrons\NetworkPerceptron;
|
||||
@@ -116,7 +115,7 @@ class MultiLayerPerceptronTraining extends NetworkTraining
|
||||
{
|
||||
$condition = $this->epochError <= $this->minError;
|
||||
if ($condition === true) {
|
||||
event(new PerceptronTrainingEnded('Le perceptron à atteint l\'erreur minimale', $this->sessionId, $this->trainingId));
|
||||
$this->broadcastTrainingEnded('Le perceptron à atteint l\'erreur minimale');
|
||||
}
|
||||
|
||||
return $condition;
|
||||
|
||||
@@ -33,7 +33,7 @@ abstract class NetworkTraining
|
||||
protected function checkPassedMaxIterations(?float $finalError)
|
||||
{
|
||||
if ($this->epoch >= $this->maxEpochs) {
|
||||
$message = 'Le nombre maximal d\'epoch a été atteint';
|
||||
$message = 'Le nombre maximal d\'époques a été atteint';
|
||||
if ($finalError) {
|
||||
$message .= " avec une erreur finale de $finalError";
|
||||
}
|
||||
@@ -42,6 +42,12 @@ abstract class NetworkTraining
|
||||
}
|
||||
}
|
||||
|
||||
protected function broadcastTrainingEnded(string $reason): void
|
||||
{
|
||||
$this->iterationEventBuffer->flush();
|
||||
event(new PerceptronTrainingEnded($reason, $this->sessionId, $this->trainingId));
|
||||
}
|
||||
|
||||
protected function addIterationToBuffer(float $error, array $synapticWeights)
|
||||
{
|
||||
$this->iterationEventBuffer->addIteration($this->epoch, $this->datasetReader->getLastReadLineIndex(), $error, $synapticWeights);
|
||||
|
||||
Reference in New Issue
Block a user