Skip to content

Commit

Permalink
Add MLP partial train test after restore from file (#243)
Browse files Browse the repository at this point in the history
  • Loading branch information
akondas authored Feb 25, 2018
1 parent 9e375ca commit d188790
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/Classification/MLPClassifierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,35 @@ public function testSaveAndRestore(): void
$this->assertEquals($predicted, $restoredClassifier->predict($testSamples));
}

public function testSaveAndRestoreWithPartialTraining(): void
{
$network = new MLPClassifier(2, [2], ['a', 'b'], 1000);
$network->partialTrain(
[[1, 0], [0, 1]],
['a', 'b']
);

$this->assertEquals('a', $network->predict([1, 0]));
$this->assertEquals('b', $network->predict([0, 1]));

$filename = 'perceptron-test-'.random_int(100, 999).'-'.uniqid();
$filepath = tempnam(sys_get_temp_dir(), $filename);
$modelManager = new ModelManager();
$modelManager->saveToFile($network, $filepath);

/** @var MLPClassifier $restoredNetwork */
$restoredNetwork = $modelManager->restoreFromFile($filepath);
$restoredNetwork->partialTrain(
[[1, 1], [0, 0]],
['a', 'b']
);

$this->assertEquals('a', $restoredNetwork->predict([1, 0]));
$this->assertEquals('b', $restoredNetwork->predict([0, 1]));
$this->assertEquals('a', $restoredNetwork->predict([1, 1]));
$this->assertEquals('b', $restoredNetwork->predict([0, 0]));
}

public function testThrowExceptionOnInvalidLayersNumber(): void
{
$this->expectException(InvalidArgumentException::class);
Expand Down

0 comments on commit d188790

Please sign in to comment.