diff --git a/app/Http/Controllers/PerceptronController.php b/app/Http/Controllers/PerceptronController.php index eebd210..5eeedfd 100644 --- a/app/Http/Controllers/PerceptronController.php +++ b/app/Http/Controllers/PerceptronController.php @@ -107,7 +107,7 @@ class PerceptronController extends Controller } break; case 'table_2_11': - $dataset['defaultMinError'] = 1.0; + $dataset['defaultMinError'] = 0.02; break; } $datasets[] = $dataset; diff --git a/app/Models/NetworksTraining/ADALINEPerceptronTraining.php b/app/Models/NetworksTraining/ADALINEPerceptronTraining.php index 9c213d1..b4982f5 100644 --- a/app/Models/NetworksTraining/ADALINEPerceptronTraining.php +++ b/app/Models/NetworksTraining/ADALINEPerceptronTraining.php @@ -82,7 +82,7 @@ class ADALINEPerceptronTraining extends NetworkTraining protected function stopCondition(): bool { - $condition = $this->epochError <= $this->minError && $this->perceptron->getSynapticWeights() !== [[0.0, 0.0, 0.0]]; + $condition = $this->epochError <= $this->minError; if ($condition === true) { event(new PerceptronTrainingEnded('Le perceptron à atteint l\'erreur minimale', $this->sessionId, $this->trainingId)); } diff --git a/app/Models/NetworksTraining/GradientDescentPerceptronTraining.php b/app/Models/NetworksTraining/GradientDescentPerceptronTraining.php index 082c083..a6e3293 100644 --- a/app/Models/NetworksTraining/GradientDescentPerceptronTraining.php +++ b/app/Models/NetworksTraining/GradientDescentPerceptronTraining.php @@ -78,7 +78,7 @@ class GradientDescentPerceptronTraining extends NetworkTraining protected function stopCondition(): bool { - $condition = $this->epochError <= $this->minError && $this->perceptron->getSynapticWeights() !== [[0.0, 0.0, 0.0]]; + $condition = $this->epochError <= $this->minError; if ($condition === true) { event(new PerceptronTrainingEnded('Le perceptron à atteint l\'erreur minimale', $this->sessionId, $this->trainingId)); } diff --git a/tests/Unit/Training/ADALINEPerceptronTest.php b/tests/Unit/Training/ADALINEPerceptronTest.php index ed62fb6..d50ad48 100644 --- a/tests/Unit/Training/ADALINEPerceptronTest.php +++ b/tests/Unit/Training/ADALINEPerceptronTest.php @@ -10,7 +10,7 @@ use Tests\Services\IterationEventBuffer\DullIterationEventBuffer; class ADALINEPerceptronTest extends TrainingTestCase { - public function test_simple_perceptron_training_logic_and() + public function test_adaline_perceptron_training_logic_and() { $training = new ADALINEPerceptronTraining( datasetReader: new LinearOrderDataSetReader(public_path('data_sets/logic_and_gradient.csv')), @@ -31,7 +31,7 @@ class ADALINEPerceptronTest extends TrainingTestCase ); } - // public function test_simple_perceptron_training_table_2_9() + // public function test_adaline_perceptron_training_table_2_9() // { // $training = new ADALINEPerceptronTraining( // datasetReader: new LinearOrderDataSetReader(public_path('data_sets/table_2_9.csv')), @@ -50,4 +50,25 @@ class ADALINEPerceptronTest extends TrainingTestCase // expectedEpochs: 92 // ); // } + + public function test_adaline_perceptron_training_table_2_10() + { + $training = new ADALINEPerceptronTraining( + datasetReader: new LinearOrderDataSetReader(public_path('data_sets/table_2_10.csv')), + learningRate: 0.0015, + maxEpochs: 1000, + synapticWeightsProvider: new ZeroSynapticWeights(), + iterationEventBuffer: new DullIterationEventBuffer(), + sessionId: 'test-session', + trainingId: 'test-training', + // minError: 16.597077, // Impossible pour un dataset avec des labels -1 et 1 d'avoir une erreur moyenne supérieure à 2 + minError: 0.000000001, + ); + + $this->verifyTrainingResults( + training: $training, + expectedWeights: [[[-0.022673, -0.25422, 0.294955]]], + expectedEpochs: 1000 + ); + } } diff --git a/tests/Unit/Training/GradientDescentPerceptronTest.php b/tests/Unit/Training/GradientDescentPerceptronTest.php index aa054c4..6c9b57b 100644 --- a/tests/Unit/Training/GradientDescentPerceptronTest.php +++ b/tests/Unit/Training/GradientDescentPerceptronTest.php @@ -10,7 +10,7 @@ use Tests\Services\IterationEventBuffer\DullIterationEventBuffer; class GradientDescentPerceptronTest extends TrainingTestCase { - public function test_simple_perceptron_training_logic_and() + public function test_gradient_descent_perceptron_training_logic_and() { $training = new GradientDescentPerceptronTraining( datasetReader: new LinearOrderDataSetReader(public_path('data_sets/logic_and_gradient.csv')), @@ -30,7 +30,7 @@ class GradientDescentPerceptronTest extends TrainingTestCase ); } - // public function test_simple_perceptron_training_table_2_9() + // public function test_gradient_descent_perceptron_training_table_2_9() // { // $training = new GradientDescentPerceptronTraining( // datasetReader: new LinearOrderDataSetReader(public_path('data_sets/table_2_9.csv')), @@ -49,4 +49,25 @@ class GradientDescentPerceptronTest extends TrainingTestCase // expectedEpochs: 402 // ); // } + + public function test_gradient_descent_perceptron_training_table_2_10() + { + $training = new GradientDescentPerceptronTraining( + datasetReader: new LinearOrderDataSetReader(public_path('data_sets/table_2_10.csv')), + learningRate: 0.0015, + maxEpochs: 1000, + synapticWeightsProvider: new ZeroSynapticWeights(), + iterationEventBuffer: new DullIterationEventBuffer(), + sessionId: 'test-session', + trainingId: 'test-training', + // minError: 16.388103, // Impossible pour un dataset avec des labels -1 et 1 d'avoir une erreur moyenne supérieure à 2 + minError: 0.000000001, + ); + + $this->verifyTrainingResults( + training: $training, + expectedWeights: [[[-0.04107, -0.263527, 0.286406]]], + expectedEpochs: 1000 + ); + } }