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\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) {
|
||||
|
||||
Reference in New Issue
Block a user