8
8
use Rubix \ML \Transformers \Transformer ;
9
9
use Rubix \ML \Transformers \BM25Transformer ;
10
10
use PHPUnit \Framework \TestCase ;
11
- use Rubix \ML \Exceptions \RuntimeException ;
12
11
13
12
/**
14
13
* @group Transformers
15
14
* @covers \Rubix\ML\Transformers\BM25Transformer
16
15
*/
17
16
class BM25TransformerTest extends TestCase
18
17
{
19
- /**
20
- * @var \Rubix\ML\Datasets\Unlabeled
21
- */
22
- protected $ dataset ;
23
-
24
18
/**
25
19
* @var \Rubix\ML\Transformers\BM25Transformer
26
20
*/
@@ -31,12 +25,6 @@ class BM25TransformerTest extends TestCase
31
25
*/
32
26
protected function setUp () : void
33
27
{
34
- $ this ->dataset = new Unlabeled ([
35
- [1 , 3 , 0 , 0 , 1 , 0 , 0 , 0 , 1 , 2 , 0 , 2 , 0 , 0 , 0 , 4 , 1 , 0 , 1 ],
36
- [0 , 1 , 1 , 0 , 0 , 2 , 1 , 0 , 0 , 0 , 0 , 3 , 0 , 1 , 0 , 0 , 0 , 0 , 0 ],
37
- [0 , 0 , 0 , 1 , 2 , 3 , 0 , 0 , 4 , 2 , 0 , 0 , 1 , 0 , 2 , 0 , 1 , 0 , 0 ],
38
- ]);
39
-
40
28
$ this ->transformer = new BM25Transformer (1.2 , 0.75 );
41
29
}
42
30
@@ -56,7 +44,13 @@ public function build() : void
56
44
*/
57
45
public function fitTransform () : void
58
46
{
59
- $ this ->transformer ->fit ($ this ->dataset );
47
+ $ dataset = new Unlabeled ([
48
+ [1 , 3 , 0 , 0 , 1 , 0 , 0 , 0 , 1 , 2 , 0 , 2 , 0 , 0 , 0 , 4 , 1 , 0 , 1 ],
49
+ [0 , 1 , 1 , 0 , 0 , 2 , 1 , 0 , 0 , 0 , 0 , 3 , 0 , 1 , 0 , 0 , 0 , 0 , 0 ],
50
+ [0 , 0 , 0 , 1 , 2 , 3 , 0 , 0 , 4 , 2 , 0 , 0 , 1 , 0 , 2 , 0 , 1 , 0 , 0 ],
51
+ ]);
52
+
53
+ $ this ->transformer ->fit ($ dataset );
60
54
61
55
$ this ->assertTrue ($ this ->transformer ->fitted ());
62
56
@@ -66,26 +60,14 @@ public function fitTransform() : void
66
60
$ this ->assertCount (19 , $ dfs );
67
61
$ this ->assertContainsOnly ('int ' , $ dfs );
68
62
69
- $ this -> dataset ->apply ($ this ->transformer );
63
+ $ dataset ->apply ($ this ->transformer );
70
64
71
65
$ expected = [
72
66
[0.2562582002070131 , 0.22742881339794754 , 0.0 , 0.0 , 0.13186359514416618 , 0.0 , 0.0 , 0.0 , 0.13186359514416618 , 0.19254341937443092 , 0.0 , 0.19254341937443092 , 0.0 , 0.0 , 0.0 , 0.4860031535349766 , 0.13186359514416618 , 0.0 , 0.2562582002070131 ],
73
67
[0.0 , 0.17063795450977862 , 0.3316106698128093 , 0.0 , 0.0 , 0.23083934808978732 , 0.3316106698128093 , 0.0 , 0.0 , 0.0 , 0.0 , 0.26160416281731713 , 0.0 , 0.3316106698128093 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 ],
74
68
[0.0 , 0.0 , 0.0 , 0.2562582002070131 , 0.19254341937443092 , 0.22742881339794754 , 0.0 , 0.0 , 0.25008418471976107 , 0.19254341937443092 , 0.0 , 0.0 , 0.2562582002070131 , 0.0 , 0.3741808347986538 , 0.0 , 0.13186359514416618 , 0.0 , 0.0 ],
75
69
];
76
70
77
- $ this ->assertEquals ($ expected , $ this ->dataset ->samples ());
78
- }
79
-
80
- /**
81
- * @test
82
- */
83
- public function transformUnfitted () : void
84
- {
85
- $ this ->expectException (RuntimeException::class);
86
-
87
- $ samples = $ this ->dataset ->samples ();
88
-
89
- $ this ->transformer ->transform ($ samples );
71
+ $ this ->assertEqualsWithDelta ($ expected , $ dataset ->samples (), 1e-8 );
90
72
}
91
73
}
0 commit comments