generator = new Blob(array_fill(0, 10, 0.0), 3.0); $this->transformer = new SparseRandomProjector(4); srand(self::RANDOM_SEED); } /** * @test */ public function build() : void { $this->assertInstanceOf(SparseRandomProjector::class, $this->transformer); $this->assertInstanceOf(Transformer::class, $this->transformer); $this->assertInstanceOf(Stateful::class, $this->transformer); } /** * @test */ public function fitTransform() : void { $this->assertCount(10, $this->generator->generate(1)->sample(0)); $this->transformer->fit($this->generator->generate(30)); $this->assertTrue($this->transformer->fitted()); $expected = [ 3.8861419746435, -17.801078083484, 0.29819783331323, -12.191560356574, ]; $sample = $this->generator->generate(1) ->apply($this->transformer) ->sample(0); $this->assertCount(4, $sample); $this->assertEqualsWithDelta($expected, $sample, 1e-8); } /** * @test */ public function transformUnfitted() : void { $this->expectException(RuntimeException::class); $samples = $this->generator->generate(1)->samples(); $this->transformer->transform($samples); } }