-
-
Notifications
You must be signed in to change notification settings - Fork 189
/
Copy pathL2NormalizerTest.php
59 lines (50 loc) · 1.35 KB
/
L2NormalizerTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
namespace Rubix\ML\Tests\Transformers;
use Rubix\ML\Datasets\Unlabeled;
use Rubix\ML\Transformers\Transformer;
use Rubix\ML\Transformers\L2Normalizer;
use PHPUnit\Framework\TestCase;
/**
* @group Transformers
* @covers \Rubix\ML\Transformers\L2Normalizer
*/
class L2NormalizerTest extends TestCase
{
/**
* @var L2Normalizer
*/
protected $transformer;
/**
* @before
*/
protected function setUp() : void
{
$this->transformer = new L2Normalizer();
}
/**
* @test
*/
public function build() : void
{
$this->assertInstanceOf(L2Normalizer::class, $this->transformer);
$this->assertInstanceOf(Transformer::class, $this->transformer);
}
/**
* @test
*/
public function transform() : void
{
$dataset = new Unlabeled([
[1, 2, 3, 4],
[40, 0, 30, 10],
[100, 300, 200, 400],
]);
$dataset->apply($this->transformer);
$expected = [
[0.18257418583505536, 0.3651483716701107, 0.5477225575051661, 0.7302967433402214],
[0.7844645405527362, 0.0, 0.5883484054145521, 0.19611613513818404],
[0.18257418583505536, 0.5477225575051661, 0.3651483716701107, 0.7302967433402214],
];
$this->assertEqualsWithDelta($expected, $dataset->samples(), 1e-8);
}
}