45 lines
1.5 KiB
PHP
45 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit\Events;
|
|
|
|
use App\Events\PerceptronTrainingIteration;
|
|
use Tests\TestCase;
|
|
|
|
class PerceptronTrainingIterationTest extends TestCase
|
|
{
|
|
public function test_small_networks_keep_weights_for_every_iteration(): void
|
|
{
|
|
$event = new PerceptronTrainingIteration(
|
|
iterations: [
|
|
['epoch' => 1, 'exampleIndex' => 0, 'error' => 1, 'weights' => [[[1, 2]]]],
|
|
['epoch' => 1, 'exampleIndex' => 1, 'error' => 0, 'weights' => [[[3, 4]]]],
|
|
],
|
|
sessionId: 'session',
|
|
trainingId: 'training',
|
|
);
|
|
|
|
$iterations = $event->broadcastWith()['iterations'];
|
|
|
|
$this->assertSame([[[1, 2]]], $iterations[0]['weights']);
|
|
$this->assertSame([[[3, 4]]], $iterations[1]['weights']);
|
|
}
|
|
|
|
public function test_large_networks_only_keep_the_last_iteration_weights(): void
|
|
{
|
|
$largeWeights = [[array_fill(0, config('perceptron.max_displayed_weights') + 1, 0)]];
|
|
$event = new PerceptronTrainingIteration(
|
|
iterations: [
|
|
['epoch' => 1, 'exampleIndex' => 0, 'error' => 1, 'weights' => $largeWeights],
|
|
['epoch' => 1, 'exampleIndex' => 1, 'error' => 0, 'weights' => $largeWeights],
|
|
],
|
|
sessionId: 'session',
|
|
trainingId: 'training',
|
|
);
|
|
|
|
$iterations = $event->broadcastWith()['iterations'];
|
|
|
|
$this->assertSame([], $iterations[0]['weights']);
|
|
$this->assertSame($largeWeights, $iterations[1]['weights']);
|
|
}
|
|
}
|