generator = new Agglomerate([ 'east' => new Blob([5, -2, -2]), 'west' => new Blob([0, 5, -3]), ], [0.5, 0.5]); $this->tree = new BallTree(20, new Euclidean()); srand(self::RANDOM_SEED); } protected function assertPreConditions() : void { $this->assertEquals(0, $this->tree->height()); } /** * @test */ public function build() : void { $this->assertInstanceOf(BallTree::class, $this->tree); $this->assertInstanceOf(Spatial::class, $this->tree); $this->assertInstanceOf(BinaryTree::class, $this->tree); $this->assertInstanceOf(Tree::class, $this->tree); } /** * @test */ public function growNeighborsRange() : void { $this->tree->grow($this->generator->generate(self::DATASET_SIZE)); $this->assertGreaterThan(2, $this->tree->height()); $sample = $this->generator->generate(1)->sample(0); [$samples, $labels, $distances] = $this->tree->nearest($sample, 5); $this->assertCount(5, $samples); $this->assertCount(5, $labels); $this->assertCount(5, $distances); $this->assertCount(1, array_unique($labels)); [$samples, $labels, $distances] = $this->tree->range($sample, 4.3); $this->assertCount(50, $samples); $this->assertCount(50, $labels); $this->assertCount(50, $distances); $this->assertCount(1, array_unique($labels)); } /** * @test */ public function growWithSameSamples() : void { $generator = new Agglomerate([ 'east' => new Blob([5, -2, 10], 0.0), ]); $dataset = $generator->generate(self::DATASET_SIZE); $this->tree->grow($dataset); $this->assertEquals(2, $this->tree->height()); } }