Skip to content

Commit

Permalink
Dataset row() method is now sample()
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewdalpino committed Nov 14, 2019
1 parent 6cfb3b4 commit 5acfa5d
Show file tree
Hide file tree
Showing 21 changed files with 36 additions and 35 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- Added training and inference sections to the docs
- Decision tree rules method now outputs a string
- Added drop row and column methods to dataset interface
- Dataset row() method is now sample()

- 0.0.16-beta
- Radius Neighbors allows user-definable anomaly class
Expand Down
2 changes: 1 addition & 1 deletion docs/datasets/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public samples() : array

Select a single row containing the sample at a given offset (offsets begin at 0):
```php
public row(int $index) : array
public sample(int $index) : array
```

Select the values of a feature column at a given offset (offsets begin at 0):
Expand Down
2 changes: 1 addition & 1 deletion src/Datasets/Dataset.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public function samples() : array
* @param int $index
* @return array
*/
public function row(int $index) : array
public function sample(int $index) : array
{
return $this->offsetGet($index);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Graph/Nodes/Ball.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ public static function split(Labeled $dataset, Distance $kernel) : self

$radius = max($distances);

$leftCentroid = $dataset->row(argmax($distances));
$leftCentroid = $dataset->sample(argmax($distances));

$distances = [];

foreach ($dataset->samples() as $sample) {
$distances[] = $kernel->compute($sample, $leftCentroid);
}

$rightCentroid = $dataset->row(argmax($distances));
$rightCentroid = $dataset->sample(argmax($distances));

$groups = $dataset->spatialPartition($leftCentroid, $rightCentroid, $kernel);

Expand Down
12 changes: 6 additions & 6 deletions tests/Datasets/LabeledTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@ public function test_get_samples()
$this->assertEquals(self::SAMPLES, $this->dataset->samples());
}

public function test_get_row()
public function test_get_sample()
{
$this->assertEquals(self::SAMPLES[2], $this->dataset->row(2));
$this->assertEquals(self::SAMPLES[5], $this->dataset->row(5));
$this->assertEquals(self::SAMPLES[2], $this->dataset->sample(2));
$this->assertEquals(self::SAMPLES[5], $this->dataset->sample(5));
}

public function test_num_rows()
Expand Down Expand Up @@ -442,7 +442,7 @@ public function test_spatial_partition()
{
$kernel = new Gower(9.);

[$left, $right] = $this->dataset->spatialPartition($this->dataset->row(0), $this->dataset->row(3), $kernel);
[$left, $right] = $this->dataset->spatialPartition($this->dataset->sample(0), $this->dataset->sample(3), $kernel);

$this->assertInstanceOf(Labeled::class, $left);
$this->assertInstanceOf(Labeled::class, $right);
Expand Down Expand Up @@ -482,7 +482,7 @@ public function test_prepend_dataset()

$this->assertCount(count(self::SAMPLES) + 1, $merged);

$this->assertEquals(['nice', 'furry', 'friendly'], $merged->row(0));
$this->assertEquals(['nice', 'furry', 'friendly'], $merged->sample(0));
$this->assertEquals('not monster', $merged->label(6));
}

Expand All @@ -496,7 +496,7 @@ public function test_append_dataset()

$this->assertCount(count(self::SAMPLES) + 1, $merged);

$this->assertEquals(['nice', 'furry', 'friendly'], $merged->row(6));
$this->assertEquals(['nice', 'furry', 'friendly'], $merged->sample(6));
$this->assertEquals('not monster', $merged->label(6));
}

Expand Down
14 changes: 7 additions & 7 deletions tests/Datasets/UnlabeledTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ public function test_get_samples()
$this->assertEquals(self::SAMPLES, $this->dataset->samples());
}

public function test_get_row()
public function test_get_sample()
{
$this->assertEquals(self::SAMPLES[2], $this->dataset->row(2));
$this->assertEquals(self::SAMPLES[5], $this->dataset->row(5));
$this->assertEquals(self::SAMPLES[2], $this->dataset->sample(2));
$this->assertEquals(self::SAMPLES[5], $this->dataset->sample(5));
}

public function test_num_rows()
Expand Down Expand Up @@ -305,7 +305,7 @@ public function test_spatial_partition()
{
$kernel = new Gower(9.);

[$left, $right] = $this->dataset->spatialPartition($this->dataset->row(0), $this->dataset->row(3), $kernel);
[$left, $right] = $this->dataset->spatialPartition($this->dataset->sample(0), $this->dataset->sample(3), $kernel);

$this->assertInstanceOf(Unlabeled::class, $left);
$this->assertInstanceOf(Unlabeled::class, $right);
Expand Down Expand Up @@ -347,7 +347,7 @@ public function test_prepend_dataset()

$this->assertCount(count(self::SAMPLES) + 1, $merged);

$this->assertEquals(['nice', 'furry', 'friendly'], $merged->row(0));
$this->assertEquals(['nice', 'furry', 'friendly'], $merged->sample(0));
}

public function test_append_dataset()
Expand All @@ -360,10 +360,10 @@ public function test_append_dataset()

$this->assertCount(count(self::SAMPLES) + 1, $merged);

$this->assertEquals(['nice', 'furry', 'friendly'], $merged->row(6));
$this->assertEquals(['nice', 'furry', 'friendly'], $merged->sample(6));
}

public function test_drop_row()
public function test_drop_sample()
{
$dataset = $this->dataset->dropRow(1);

Expand Down
2 changes: 1 addition & 1 deletion tests/Graph/Trees/BallTreeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function test_grow_neighbors_range()

$this->assertGreaterThan(2, $this->tree->height());

$sample = $this->generator->generate(1)->row(0);
$sample = $this->generator->generate(1)->sample(0);

[$samples, $labels, $distances] = $this->tree->nearest($sample, 5);

Expand Down
2 changes: 1 addition & 1 deletion tests/Graph/Trees/ITreeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function test_grow_range()

$this->assertGreaterThan(5, $this->tree->height());

$sample = $this->generator->generate(1)->row(0);
$sample = $this->generator->generate(1)->sample(0);

$node = $this->tree->search($sample);

Expand Down
2 changes: 1 addition & 1 deletion tests/Graph/Trees/KDTreeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function test_grow_neighbors()

$this->assertGreaterThan(2, $this->tree->height());

$sample = $this->generator->generate(1)->row(0);
$sample = $this->generator->generate(1)->sample(0);

[$samples, $labels, $distances] = $this->tree->nearest($sample, 5);

Expand Down
4 changes: 2 additions & 2 deletions tests/Transformers/DenseRandomProjectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ public function test_build_transformer()

public function test_fit_transform()
{
$this->assertCount(10, $this->generator->generate(1)->row(0));
$this->assertCount(10, $this->generator->generate(1)->sample(0));

$this->transformer->fit($this->generator->generate(30));

$this->assertTrue($this->transformer->fitted());

$sample = $this->generator->generate(1)
->apply($this->transformer)
->row(0);
->sample(0);

$this->assertCount(3, $sample);
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Transformers/GaussianRandomProjectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ public function test_estimate_min_dimensions()

public function test_fit_transform()
{
$this->assertCount(10, $this->generator->generate(1)->row(0));
$this->assertCount(10, $this->generator->generate(1)->sample(0));

$this->transformer->fit($this->generator->generate(30));

$this->assertTrue($this->transformer->fitted());

$sample = $this->generator->generate(1)
->apply($this->transformer)
->row(0);
->sample(0);

$this->assertCount(5, $sample);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Transformers/ImageResizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function test_transform()
{
$this->dataset->apply($this->transformer);

$sample = $this->dataset->row(0);
$sample = $this->dataset->sample(0);

$image = $sample[0];

Expand Down
2 changes: 1 addition & 1 deletion tests/Transformers/IntervalDiscretizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function test_fit_transform()

$sample = $this->generator->generate(1)
->apply($this->transformer)
->row(0);
->sample(0);

$this->assertCount(4, $sample);

Expand Down
2 changes: 1 addition & 1 deletion tests/Transformers/LinearDiscriminantAnalysisTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function test_fit_transform()

$sample = $this->generator->generate(3)
->apply($this->transformer)
->row(0);
->sample(0);

$this->assertCount(1, $sample);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Transformers/MaxAbsoluteScalerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function test_fit_update_transform()

$sample = $this->generator->generate(1)
->apply($this->transformer)
->row(0);
->sample(0);

$this->assertCount(3, $sample);

Expand Down
2 changes: 1 addition & 1 deletion tests/Transformers/MinMaxNormalizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function test_fit_update_transform()

$sample = $this->generator->generate(1)
->apply($this->transformer)
->row(0);
->sample(0);

$this->assertCount(3, $sample);

Expand Down
2 changes: 1 addition & 1 deletion tests/Transformers/PrincipalComponentAnalysisTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function test_fit_transform()

$sample = $this->generator->generate(1)
->apply($this->transformer)
->row(0);
->sample(0);

$this->assertCount(2, $sample);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Transformers/RobustStandardizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function test_fit_update_transform()

$sample = $this->generator->generate(1)
->apply($this->transformer)
->row(0);
->sample(0);

$this->assertCount(3, $sample);

Expand Down
4 changes: 2 additions & 2 deletions tests/Transformers/SparseRandomProjectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ public function test_build_transformer()

public function test_fit_transform()
{
$this->assertCount(10, $this->generator->generate(1)->row(0));
$this->assertCount(10, $this->generator->generate(1)->sample(0));

$this->transformer->fit($this->generator->generate(30));

$this->assertTrue($this->transformer->fitted());

$sample = $this->generator->generate(1)
->apply($this->transformer)
->row(0);
->sample(0);

$this->assertCount(4, $sample);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Transformers/VarianceThresholdFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function test_fit_transform()

$sample = $this->generator->generate(1)
->apply($this->transformer)
->row(0);
->sample(0);

$this->assertCount(2, $sample);

Expand Down
2 changes: 1 addition & 1 deletion tests/Transformers/ZScaleStandardizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function test_fit_update_transform()

$sample = $this->generator->generate(1)
->apply($this->transformer)
->row(0);
->sample(0);

$this->assertCount(3, $sample);

Expand Down

0 comments on commit 5acfa5d

Please sign in to comment.