-
-
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 #198 from RubixML/1.3
1.3
- Loading branch information
Showing
27 changed files
with
1,436 additions
and
334 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
namespace Rubix\ML\Benchmarks\NeuralNet\ActivationFunctions; | ||
|
||
use Tensor\Matrix; | ||
use Rubix\ML\NeuralNet\ActivationFunctions\SiLU; | ||
|
||
/** | ||
* @Groups({"ActivationFunctions"}) | ||
* @BeforeMethods({"setUp"}) | ||
*/ | ||
class SiLUBench | ||
{ | ||
/** | ||
* @var \Tensor\Matrix | ||
*/ | ||
protected $z; | ||
|
||
/** | ||
* @var \Tensor\Matrix | ||
*/ | ||
protected $computed; | ||
|
||
/** | ||
* @var \Rubix\ML\NeuralNet\ActivationFunctions\SiLU | ||
*/ | ||
protected $activationFn; | ||
|
||
public function setUp() : void | ||
{ | ||
$this->z = Matrix::uniform(500, 500); | ||
|
||
$this->computed = Matrix::uniform(500, 500); | ||
|
||
$this->activationFn = new SiLU(); | ||
} | ||
|
||
/** | ||
* @Subject | ||
* @Iterations(3) | ||
* @OutputTimeUnit("milliseconds", precision=3) | ||
*/ | ||
public function compute() : void | ||
{ | ||
$this->activationFn->activate($this->z); | ||
} | ||
|
||
/** | ||
* @Subject | ||
* @Iterations(3) | ||
* @OutputTimeUnit("milliseconds", precision=3) | ||
*/ | ||
public function differentiate() : void | ||
{ | ||
$this->activationFn->differentiate($this->z, $this->computed); | ||
} | ||
} |
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,31 @@ | ||
<span style="float:right;"><a href="https://github.com/RubixML/ML/blob/master/src/Extractors/Deduplicator.php">[source]</a></span> | ||
|
||
# Deduplicator | ||
Removes duplicate records from a dataset while the records are in flight. Deduplicator uses a Bloom filter under the hood to probabilistically identify records that have already been seen before. | ||
|
||
!!! note | ||
Due to its probabilistic nature, Deduplicator may mistakenly drop unique records at a bounded rate. | ||
|
||
**Interfaces:** [Extractor](api.md) | ||
|
||
## Parameters | ||
| # | Name | Default | Type | Description | | ||
|---|---|---|---|---| | ||
| 1 | iterator | | Traversable | The base iterator. | | ||
| 2 | maxFalsePositiveRate | 0.001 | float | The false positive rate to remain below. | | ||
| 3 | numHashes | 4 | int | The number of hash functions used, i.e. the number of slices per layer. Set to null for auto. | | ||
| 4 | layerSize | 32000000 | int | The size of each layer of the filter in bits. | | ||
|
||
## Example | ||
```php | ||
use Rubix\ML\Extractors\Deduplicator; | ||
use Rubix\ML\Extractors\CSV; | ||
|
||
$extractor = new Deduplicator(new CSV('example.csv', true), 0.01, 3, 32000000); | ||
``` | ||
|
||
## Additional Methods | ||
Return the number of records that have been dropped so far. | ||
```php | ||
public dropped() : int | ||
``` |
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,17 @@ | ||
<span style="float:right;"><a href="https://github.com/RubixML/ML/blob/master/src/NeuralNet/ActivationFunctions/SiLU.php">[source]</a></span> | ||
|
||
# SiLU | ||
Sigmoid Linear Units are smooth and non-monotonic rectified activation functions. Their inputs are weighted by the [Sigmoid](sigmoid.md) activation function acting as a self-gating mechanism. | ||
|
||
## Parameters | ||
This activation function does not have any parameters. | ||
|
||
## Example | ||
```php | ||
use Rubix\ML\NeuralNet\ActivationFunctions\SiLU; | ||
|
||
$activationFunction = new SiLU(); | ||
``` | ||
|
||
### References | ||
[^1]: S. Elwing et al. (2017). Sigmoid-Weighted Linear Units for Neural Network Function Approximation in Reinforcement Learning. |
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,21 @@ | ||
<span style="float:right;"><a href="https://github.com/RubixML/ML/blob/master/src/NeuralNet/Layers/Swish.php">[source]</a></span> | ||
|
||
# Swish | ||
Swish is a parametric activation layer that utilizes smooth rectified activation functions. The trainable *beta* parameter allows each activation function in the layer to tailor its output to the training set by interpolating between the linear function and ReLU. | ||
|
||
## Parameters | ||
| # | Name | Default | Type | Description | | ||
|---|---|---|---|---| | ||
| 1 | initializer | Constant | Initializer | The initializer of the beta parameter. | | ||
|
||
## Example | ||
```php | ||
use Rubix\ML\NeuralNet\Layers\Swish; | ||
use Rubix\ML\NeuralNet\Initializers\Constant; | ||
|
||
$layer = new Swish(new Constant(1.0)); | ||
``` | ||
|
||
## References | ||
[^1]: P. Ramachandran er al. (2017). Swish: A Self-gated Activation Function. | ||
[^2]: P. Ramachandran et al. (2017). Searching for Activation Functions. |
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
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,88 @@ | ||
<?php | ||
|
||
namespace Rubix\ML\Extractors; | ||
|
||
use OkBloomer\BloomFilter; | ||
use Generator; | ||
|
||
use function serialize; | ||
|
||
/** | ||
* Deduplicator | ||
* | ||
* Removes duplicate records from a dataset while the records are in flight. Deduplicator uses a memory-efficient | ||
* Bloom filter to probabilistically identify records that have already been seen before. | ||
* | ||
* @category Machine Learning | ||
* @package Rubix/ML | ||
* @author Andrew DalPino | ||
*/ | ||
class Deduplicator implements Extractor | ||
{ | ||
/** | ||
* The base iterator. | ||
* | ||
* @var iterable<array> | ||
*/ | ||
protected iterable $iterator; | ||
|
||
/** | ||
* The Bloom filter. | ||
* | ||
* @var \OkBloomer\BloomFilter | ||
*/ | ||
protected BloomFilter $filter; | ||
|
||
/** | ||
* The number of records that have been dropped so far. | ||
* | ||
* @var int | ||
*/ | ||
protected int $dropped = 0; | ||
|
||
/** | ||
* @param iterable<mixed[]> $iterator | ||
* @param float $maxFalsePositiveRate | ||
* @param int|null $numHashes | ||
* @param int $layerSize | ||
*/ | ||
public function __construct( | ||
iterable $iterator, | ||
float $maxFalsePositiveRate = 0.001, | ||
?int $numHashes = 4, | ||
int $layerSize = 32000000 | ||
) { | ||
$this->iterator = $iterator; | ||
$this->filter = new BloomFilter($maxFalsePositiveRate, $numHashes, $layerSize); | ||
} | ||
|
||
/** | ||
* Return the number of records that have been dropped so far. | ||
* | ||
* @return int | ||
*/ | ||
public function dropped() : int | ||
{ | ||
return $this->dropped; | ||
} | ||
|
||
/** | ||
* Return an iterator for the records in the data table. | ||
* | ||
* @return \Generator<mixed[]> | ||
*/ | ||
public function getIterator() : Generator | ||
{ | ||
foreach ($this->iterator as $record) { | ||
$token = serialize($record); | ||
|
||
if ($this->filter->existsOrInsert($token)) { | ||
++$this->dropped; | ||
|
||
continue; | ||
} | ||
|
||
yield $record; | ||
} | ||
} | ||
} |
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.