-
-
Notifications
You must be signed in to change notification settings - Fork 189
/
Copy pathZScaleStandardizerTest.php
107 lines (82 loc) · 2.76 KB
/
ZScaleStandardizerTest.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php
namespace Rubix\ML\Tests\Transformers;
use Rubix\ML\Persistable;
use Rubix\ML\Transformers\Elastic;
use Rubix\ML\Transformers\Stateful;
use Rubix\ML\Transformers\Reversible;
use Rubix\ML\Transformers\Transformer;
use Rubix\ML\Datasets\Generators\Blob;
use Rubix\ML\Transformers\ZScaleStandardizer;
use Rubix\ML\Exceptions\RuntimeException;
use PHPUnit\Framework\TestCase;
/**
* @group Transformers
* @covers \Rubix\ML\Transformers\ZScaleStandardizer
*/
class ZScaleStandardizerTest extends TestCase
{
/**
* @var Blob
*/
protected $generator;
/**
* @var ZScaleStandardizer
*/
protected $transformer;
/**
* @before
*/
protected function setUp() : void
{
$this->generator = new Blob([0.0, 3000.0, -6.0], [1.0, 30.0, 0.001]);
$this->transformer = new ZScaleStandardizer(true);
}
/**
* @test
*/
public function build() : void
{
$this->assertInstanceOf(ZScaleStandardizer::class, $this->transformer);
$this->assertInstanceOf(Transformer::class, $this->transformer);
$this->assertInstanceOf(Stateful::class, $this->transformer);
$this->assertInstanceOf(Elastic::class, $this->transformer);
$this->assertInstanceOf(Reversible::class, $this->transformer);
$this->assertInstanceOf(Persistable::class, $this->transformer);
}
/**
* @test
*/
public function fitUpdateTransformReverse() : void
{
$this->transformer->fit($this->generator->generate(30));
$this->transformer->update($this->generator->generate(30));
$this->assertTrue($this->transformer->fitted());
$means = $this->transformer->means();
$this->assertIsArray($means);
$this->assertCount(3, $means);
$this->assertContainsOnly('float', $means);
$variances = $this->transformer->variances();
$this->assertIsArray($variances);
$this->assertCount(3, $variances);
$this->assertContainsOnly('float', $variances);
$dataset = $this->generator->generate(1);
$original = $dataset->sample(0);
$dataset->apply($this->transformer);
$sample = $dataset->sample(0);
$this->assertCount(3, $sample);
$this->assertEqualsWithDelta(0, $sample[0], 6);
$this->assertEqualsWithDelta(0, $sample[1], 6);
$this->assertEqualsWithDelta(0, $sample[2], 6);
$dataset->reverseApply($this->transformer);
$this->assertEqualsWithDelta($original, $dataset->sample(0), 1e-8);
}
/**
* @test
*/
public function transformUnfitted() : void
{
$this->expectException(RuntimeException::class);
$samples = $this->generator->generate(1)->samples();
$this->transformer->transform($samples);
}
}