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); } }