-
-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #250 from RubixML/2.2
2.2
- Loading branch information
Showing
97 changed files
with
1,580 additions
and
188 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
|
||
namespace Rubix\ML\Benchmarks\Classifiers; | ||
|
||
use Rubix\ML\Classifiers\OneVsRest; | ||
use Rubix\ML\Datasets\Generators\Blob; | ||
use Rubix\ML\Classifiers\LogisticRegression; | ||
use Rubix\ML\NeuralNet\Optimizers\Stochastic; | ||
use Rubix\ML\Datasets\Generators\Agglomerate; | ||
|
||
/** | ||
* @Groups({"Classifiers"}) | ||
* @BeforeMethods({"setUp"}) | ||
*/ | ||
class OneVsRestBench | ||
{ | ||
protected const TRAINING_SIZE = 2500; | ||
|
||
protected const TESTING_SIZE = 10000; | ||
|
||
/** | ||
* @var \Rubix\ML\Datasets\Labeled; | ||
*/ | ||
protected $training; | ||
|
||
/** | ||
* @var \Rubix\ML\Datasets\Labeled; | ||
*/ | ||
protected $testing; | ||
|
||
/** | ||
* @var \Rubix\ML\Classifiers\OneVsRest | ||
*/ | ||
protected $estimator; | ||
|
||
public function setUp() : void | ||
{ | ||
$generator = new Agglomerate([ | ||
'Iris-setosa' => new Blob([5.0, 3.42, 1.46, 0.24], [0.35, 0.38, 0.17, 0.1]), | ||
'Iris-versicolor' => new Blob([5.94, 2.77, 4.26, 1.33], [0.51, 0.31, 0.47, 0.2]), | ||
'Iris-virginica' => new Blob([6.59, 2.97, 5.55, 2.03], [0.63, 0.32, 0.55, 0.27]), | ||
]); | ||
|
||
$this->training = $generator->generate(self::TRAINING_SIZE); | ||
|
||
$this->testing = $generator->generate(self::TESTING_SIZE); | ||
|
||
$this->estimator = new OneVsRest(new LogisticRegression(64, new Stochastic(0.001))); | ||
} | ||
|
||
/** | ||
* @Subject | ||
* @Iterations(5) | ||
* @OutputTimeUnit("seconds", precision=3) | ||
*/ | ||
public function trainPredict() : void | ||
{ | ||
$this->estimator->train($this->training); | ||
|
||
$this->estimator->predict($this->testing); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
|
||
namespace Rubix\ML\Benchmarks\Kernels\Distance; | ||
|
||
use Rubix\ML\Datasets\Generators\Blob; | ||
use Rubix\ML\Kernels\Distance\Gower; | ||
use Rubix\ML\Transformers\LambdaFunction; | ||
|
||
/** | ||
* @Groups({"DistanceKernels"}) | ||
* @BeforeMethods({"setUp"}) | ||
*/ | ||
class GowerBench | ||
{ | ||
protected const NUM_SAMPLES = 10000; | ||
|
||
/** | ||
* @var list<list<float>> | ||
*/ | ||
protected $aSamples; | ||
|
||
/** | ||
* @var list<list<float>> | ||
*/ | ||
protected $bSamples; | ||
|
||
/** | ||
* @var \Rubix\ML\Kernels\Distance\Gower | ||
*/ | ||
protected $kernel; | ||
|
||
public function setUp() : void | ||
{ | ||
$generator = new Blob([0, 0, 0, 0, 0, 0, 0, 0], 5.0); | ||
|
||
$dropValues = new LambdaFunction((function ($sample) { | ||
$sample[4] = rand(0, 5) === 0 ? NAN : $sample[4]; | ||
$sample[5] = rand(0, 10) === 0 ? NAN : $sample[5]; | ||
})); | ||
|
||
$discretize = new LambdaFunction(function ($sample) { | ||
$sample[6] = $sample[6] > 0.0 ? 'over' : 'under'; | ||
$sample[7] = abs($sample[7]) > 0.5 ? 'big' : 'small'; | ||
}); | ||
|
||
$this->aSamples = $generator->generate(self::NUM_SAMPLES) | ||
->apply($dropValues) | ||
->apply($discretize) | ||
->samples(); | ||
|
||
$this->bSamples = $generator->generate(self::NUM_SAMPLES) | ||
->apply($dropValues) | ||
->apply($discretize) | ||
->samples(); | ||
|
||
$this->kernel = new Gower(5.0); | ||
} | ||
|
||
/** | ||
* @Subject | ||
* @Iterations(5) | ||
* @OutputTimeUnit("milliseconds", precision=3) | ||
*/ | ||
public function compute() : void | ||
{ | ||
array_map([$this->kernel, 'compute'], $this->aSamples, $this->bSamples); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
<?php | ||
|
||
namespace Rubix\ML\Benchmarks\Kernels\Distance; | ||
|
||
use Tensor\Matrix; | ||
use Rubix\ML\Kernels\Distance\SparseCosine; | ||
|
||
/** | ||
* @Groups({"DistanceKernels"}) | ||
*/ | ||
class SparseCosineBench | ||
{ | ||
protected const NUM_SAMPLES = 10000; | ||
|
||
/** | ||
* @var list<list<float>> | ||
*/ | ||
protected $aSamples; | ||
|
||
/** | ||
* @var list<list<float>> | ||
*/ | ||
protected $bSamples; | ||
|
||
/** | ||
* @var \Rubix\ML\Kernels\Distance\SparseCosine | ||
*/ | ||
protected $kernel; | ||
|
||
public function setUp() : void | ||
{ | ||
$this->kernel = new SparseCosine(); | ||
} | ||
|
||
public function setUpDense() : void | ||
{ | ||
$this->aSamples = Matrix::gaussian(self::NUM_SAMPLES, 8)->asArray(); | ||
$this->bSamples = Matrix::gaussian(self::NUM_SAMPLES, 8)->asArray(); | ||
} | ||
|
||
/** | ||
* @Subject | ||
* @Iterations(5) | ||
* @BeforeMethods({"setUp", "setUpDense"}) | ||
* @OutputTimeUnit("milliseconds", precision=3) | ||
*/ | ||
public function computeDense() : void | ||
{ | ||
array_map([$this->kernel, 'compute'], $this->aSamples, $this->bSamples); | ||
} | ||
|
||
public function setUpSparse() : void | ||
{ | ||
$mask = Matrix::rand(self::NUM_SAMPLES, 8) | ||
->greater(0.5); | ||
|
||
$this->aSamples = Matrix::gaussian(self::NUM_SAMPLES, 8) | ||
->multiply($mask) | ||
->asArray(); | ||
|
||
$mask = Matrix::rand(self::NUM_SAMPLES, 8) | ||
->greater(0.5); | ||
|
||
$this->bSamples = Matrix::gaussian(self::NUM_SAMPLES, 8) | ||
->multiply($mask) | ||
->asArray(); | ||
} | ||
|
||
/** | ||
* @Subject | ||
* @Iterations(5) | ||
* @BeforeMethods({"setUp", "setUpSparse"}) | ||
* @OutputTimeUnit("milliseconds", precision=3) | ||
*/ | ||
public function computeSparse() : void | ||
{ | ||
array_map([$this->kernel, 'compute'], $this->aSamples, $this->bSamples); | ||
} | ||
|
||
public function setUpVerySparse() : void | ||
{ | ||
$mask = Matrix::rand(self::NUM_SAMPLES, 8) | ||
->greater(0.9); | ||
|
||
$this->aSamples = Matrix::gaussian(self::NUM_SAMPLES, 8) | ||
->multiply($mask) | ||
->asArray(); | ||
|
||
$mask = Matrix::rand(self::NUM_SAMPLES, 8) | ||
->greater(0.9); | ||
|
||
$this->bSamples = Matrix::gaussian(self::NUM_SAMPLES, 8) | ||
->multiply($mask) | ||
->asArray(); | ||
} | ||
|
||
/** | ||
* @Subject | ||
* @Iterations(5) | ||
* @BeforeMethods({"setUp", "setUpVerySparse"}) | ||
* @OutputTimeUnit("milliseconds", precision=3) | ||
*/ | ||
public function computeVerySparse() : void | ||
{ | ||
array_map([$this->kernel, 'compute'], $this->aSamples, $this->bSamples); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<span style="float:right;"><a href="https://github.com/RubixML/ML/blob/master/src/Classifiers/OneVsRest.php">[source]</a></span> | ||
|
||
# One Vs Rest | ||
One Vs Rest is an ensemble learner that trains a binary classifier to predict a particular class vs every other class for every possible class. The final class prediction is the class whose binary classifier returned the highest probability. One of the features of One Vs Rest is that it allows you to build a multiclass classifier out of an ensemble of otherwise binary classifiers. | ||
|
||
**Interfaces:** [Estimator](../estimator.md), [Learner](../learner.md), [Probabilistic](../probabilistic.md), [Parallel](../parallel.md), [Persistable](../persistable.md) | ||
|
||
**Data Type Compatibility:** Depends on the base learner | ||
|
||
## Parameters | ||
| # | Name | Default | Type | Description | | ||
|---|---|---|---|---| | ||
| 1 | base | | Learner|Probabilistic | The base classifier. | | ||
|
||
## Example | ||
```php | ||
use Rubix\ML\Classifiers\OneVsRest; | ||
use Rubix\ML\Classifiers\LogisticRegression; | ||
use Rubix\ML\NeuralNet\Optimizers\Stochastic; | ||
|
||
$estimator = new OneVsRest(new LogisticRegression(64, new Stochastic(0.001))); | ||
``` | ||
|
||
## Additional Methods | ||
This estimator does not have any additional methods. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<span style="float:right;"><a href="https://github.com/RubixML/ML/blob/master/src/Extractors/ColumnFilter.php">[source]</a></span> | ||
|
||
# Column Filter | ||
|
||
**Interfaces:** [Extractor](api.md) | ||
|
||
## Parameters | ||
| # | Name | Default | Type | Description | | ||
|---|---|---|---|---| | ||
| 1 | iterator | | Traversable | The base iterator. | | ||
| 2 | keys | | array | The string and/or integer keys of the columns to filter from the table | | ||
|
||
## Example | ||
```php | ||
use Rubix\ML\Extractors\ColumnFilter; | ||
use Rubix\ML\Extractors\CSV; | ||
|
||
$extractor = new ColumnFilter(new CSV('example.csv', true), [ | ||
'texture', 'class', | ||
]); | ||
``` | ||
|
||
## Additional Methods | ||
This extractor does not have any additional methods. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.