-
-
Notifications
You must be signed in to change notification settings - Fork 189
/
Copy pathLinearDiscriminantAnalysisTest.php
83 lines (68 loc) · 1.95 KB
/
LinearDiscriminantAnalysisTest.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
<?php
namespace Rubix\ML\Tests\Transformers;
use Rubix\ML\Transformers\Stateful;
use Rubix\ML\Transformers\Transformer;
use Rubix\ML\Datasets\Generators\Blob;
use Rubix\ML\Datasets\Generators\Agglomerate;
use Rubix\ML\Transformers\LinearDiscriminantAnalysis;
use Rubix\ML\Exceptions\RuntimeException;
use PHPUnit\Framework\TestCase;
/**
* @group Transformers
* @requires extension tensor
* @covers \Rubix\ML\Transformers\LinearDiscriminantAnalysis
*/
class LinearDiscriminantAnalysisTest extends TestCase
{
/**
* @var Agglomerate
*/
protected $generator;
/**
* @var LinearDiscriminantAnalysis
*/
protected $transformer;
/**
* @before
*/
protected function setUp() : void
{
$this->generator = new Agglomerate([
'red' => new Blob([255, 0, 0], 30.0),
'green' => new Blob([0, 128, 0], 10.0),
'blue' => new Blob([0, 0, 255], 20.0),
], [3, 4, 3]);
$this->transformer = new LinearDiscriminantAnalysis(1);
}
/**
* @test
*/
public function build() : void
{
$this->assertInstanceOf(LinearDiscriminantAnalysis::class, $this->transformer);
$this->assertInstanceOf(Transformer::class, $this->transformer);
$this->assertInstanceOf(Stateful::class, $this->transformer);
}
/**
* @test
*/
public function fitTransform() : void
{
$dataset = $this->generator->generate(30);
$this->transformer->fit($dataset);
$this->assertTrue($this->transformer->fitted());
$sample = $this->generator->generate(3)
->apply($this->transformer)
->sample(0);
$this->assertCount(1, $sample);
}
/**
* @test
*/
public function transformUnfitted() : void
{
$this->expectException(RuntimeException::class);
$samples = $this->generator->generate(1)->samples();
$this->transformer->transform($samples);
}
}