Skip to content

Commit 4033a9d

Browse files
committed
Merge branch '2.5' into 3.0
2 parents dd56e81 + 8e299a2 commit 4033a9d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+159
-130
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
"@test",
8181
"@check"
8282
],
83-
"analyze": "phpstan analyse -c phpstan.neon",
83+
"analyze": "phpstan analyse -c phpstan.neon --memory-limit 1G",
8484
"benchmark": "phpbench run --report=aggregate",
8585
"check": [
8686
"@putenv PHP_CS_FIXER_IGNORE_ENV=1",

docs/backends/swoole.md

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<span style="float:right;"><a href="https://github.com/RubixML/ML/blob/master/src/Backends/Swoole.php">[source]</a></span>
2+
3+
# Swoole
4+
[Swoole](https://swoole.com)/[OpenSwoole](https://openswoole.com/) is an async PHP extension that also supports multiprocessing.
5+
6+
!!! tip
7+
Swoole backend makes use of [Igbinary](https://www.php.net/manual/en/intro.igbinary.php) serializer. If you need to
8+
optimize the memory usage (or getting out-of-memory errors) consider installing [Igbinary](https://www.php.net/manual/en/intro.igbinary.php).
9+
10+
## Example
11+
12+
No parameters are required. It's a drop-in replacement for the [Serial](backends/serial.md) backend.
13+
14+
```php
15+
use Rubix\ML\Backends\Swoole;
16+
17+
$backend = new Swoole();
18+
```

docs/persisters/filesystem.md

+25-2
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,37 @@ Filesystems are local or remote storage drives that are organized by files and f
88
|---|---|---|---|---|
99
| 1 | path | | string | The path to the model file on the filesystem. |
1010
| 2 | history | false | bool | Should we keep a history of past saves? |
11-
| 3 | serializer | RBX | Serializer | The serializer used to convert to and from storage format. |
1211

1312
## Example
1413
```php
1514
use Rubix\ML\Persisters\Filesystem;
1615
use Rubix\ML\Serializers\RBX;
16+
use Rubix\ML\Classifiers\KNearestNeighbors;
17+
use Rubix\ML\Kernels\Distance\Manhattan;
1718

18-
$persister = new Filesystem('/path/to/example.model', true, new RBX());
19+
$persistable = new KNearestNeighbors(3, false, new Manhattan());
20+
21+
$persister = new Filesystem('/path/to/example.rbx', true);
22+
23+
$serializer = new RBX(6);
24+
25+
$encoding = $serializer->serialize($persistable);
26+
27+
$persister->save($encoding);
28+
```
29+
30+
## Example
31+
```php
32+
use Rubix\ML\Persisters\Filesystem;
33+
use Rubix\ML\Serializers\RBX;
34+
35+
$persister = new Filesystem('/path/to/example.rbx', true);
36+
37+
$encoding = $persister->load();
38+
39+
$serializer = new RBX(6);
40+
41+
$persistable = $serializer->deserialize($encoding);
1942
```
2043

2144
## Additional Methods

src/AnomalyDetectors/LocalOutlierFactor.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ class LocalOutlierFactor implements Estimator, Learner, Scoring, Persistable
104104
/**
105105
* @param int $k
106106
* @param float|null $contamination
107-
* @param \Rubix\ML\Graph\Trees\Spatial|null $tree
107+
* @param Spatial|null $tree
108108
* @throws InvalidArgumentException
109109
*/
110110
public function __construct(int $k = 20, ?float $contamination = null, ?Spatial $tree = null)

src/AnomalyDetectors/Loda.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ class Loda implements Estimator, Learner, Online, Scoring, Persistable
9898
/**
9999
* The sparse random projection matrix.
100100
*
101-
* @var \Tensor\Matrix|null
101+
* @var Matrix|null
102102
*/
103103
protected ?Matrix $r = null;
104104

src/AnomalyDetectors/OneClassSVM.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@ class OneClassSVM implements Estimator, Learner
5656
/**
5757
* The trained model instance.
5858
*
59-
* @var \svmmodel|null
59+
* @var svmmodel|null
6060
*/
6161
protected ?svmmodel $model = null;
6262

6363
/**
6464
* @param float $nu
65-
* @param \Rubix\ML\Kernels\SVM\Kernel|null $kernel
65+
* @param Kernel|null $kernel
6666
* @param bool $shrinking
6767
* @param float $tolerance
6868
* @param float $cacheSize

src/Backends/Swoole.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,10 @@ function (Process $worker) use ($maxMessageLength, $queueItem) {
9898
true,
9999
);
100100

101-
$workerProcess->setAffinity([$currentCpu]);
101+
if (method_exists($workerProcess, 'setAffinity')) {
102+
$workerProcess->setAffinity([$currentCpu]);
103+
}
104+
102105
$workerProcess->setBlocking(false);
103106
$workerProcess->start();
104107

src/Classifiers/AdaBoost.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ class AdaBoost implements Estimator, Learner, Probabilistic, Verbose, Persistabl
145145
protected ?int $featureCount = null;
146146

147147
/**
148-
* @param \Rubix\ML\Learner|null $base
148+
* @param Learner|null $base
149149
* @param float $rate
150150
* @param float $ratio
151151
* @param int $epochs

src/Classifiers/KDNeighbors.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class KDNeighbors implements Estimator, Learner, Probabilistic, Persistable
8181
/**
8282
* @param int $k
8383
* @param bool $weighted
84-
* @param \Rubix\ML\Graph\Trees\Spatial|null $tree
84+
* @param Spatial|null $tree
8585
* @throws InvalidArgumentException
8686
*/
8787
public function __construct(int $k = 5, bool $weighted = false, ?Spatial $tree = null)

src/Classifiers/KNearestNeighbors.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class KNearestNeighbors implements Estimator, Learner, Online, Probabilistic, Pe
9494
/**
9595
* @param int $k
9696
* @param bool $weighted
97-
* @param \Rubix\ML\Kernels\Distance\Distance|null $kernel
97+
* @param Distance|null $kernel
9898
* @throws InvalidArgumentException
9999
*/
100100
public function __construct(int $k = 5, bool $weighted = false, ?Distance $kernel = null)

src/Classifiers/LogisticRegression.php

+2-6
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,7 @@ class LogisticRegression implements Estimator, Learner, Online, Probabilistic, R
110110
*
111111
* @var \Rubix\ML\NeuralNet\Network|null
112112
*/
113-
<<<<<<< HEAD
114113
protected ?\Rubix\ML\NeuralNet\Network $network = null;
115-
=======
116-
protected ?FeedForward $network = null;
117-
>>>>>>> 2.5
118114

119115
/**
120116
* The unique class labels.
@@ -132,12 +128,12 @@ class LogisticRegression implements Estimator, Learner, Online, Probabilistic, R
132128

133129
/**
134130
* @param int $batchSize
135-
* @param \Rubix\ML\NeuralNet\Optimizers\Optimizer|null $optimizer
131+
* @param Optimizer|null $optimizer
136132
* @param float $l2Penalty
137133
* @param int $epochs
138134
* @param float $minChange
139135
* @param int $window
140-
* @param \Rubix\ML\NeuralNet\CostFunctions\ClassificationLoss|null $costFn
136+
* @param ClassificationLoss|null $costFn
141137
* @throws InvalidArgumentException
142138
*/
143139
public function __construct(

src/Classifiers/LogitBoost.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -183,15 +183,15 @@ class LogitBoost implements Estimator, Learner, Probabilistic, RanksFeatures, Ve
183183
protected ?int $featureCount = null;
184184

185185
/**
186-
* @param \Rubix\ML\Learner|null $booster
186+
* @param Learner|null $booster
187187
* @param float $rate
188188
* @param float $ratio
189189
* @param int $epochs
190190
* @param float $minChange
191191
* @param int $evalInterval
192192
* @param int $window
193193
* @param float $holdOut
194-
* @param \Rubix\ML\CrossValidation\Metrics\Metric|null $metric
194+
* @param Metric|null $metric
195195
* @throws InvalidArgumentException
196196
*/
197197
public function __construct(

src/Classifiers/MultilayerPerceptron.php

+7-6
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,7 @@ class MultilayerPerceptron implements Estimator, Learner, Online, Probabilistic,
141141
*
142142
* @var \Rubix\ML\NeuralNet\Network|null
143143
*/
144-
<<<<<<< HEAD
145144
protected ?\Rubix\ML\NeuralNet\Network $network = null;
146-
=======
147-
protected ?FeedForward $network = null;
148-
>>>>>>> 2.5
149145

150146
/**
151147
* The unique class labels.
@@ -171,14 +167,19 @@ class MultilayerPerceptron implements Estimator, Learner, Online, Probabilistic,
171167
/**
172168
* @param \Rubix\ML\NeuralNet\Layers\Hidden[] $hiddenLayers
173169
* @param int $batchSize
170+
<<<<<<< HEAD
174171
* @param \Rubix\ML\NeuralNet\Optimizers\Optimizer|null $optimizer
172+
=======
173+
* @param Optimizer|null $optimizer
174+
* @param float $l2Penalty
175+
>>>>>>> 2.5
175176
* @param int $epochs
176177
* @param float $minChange
177178
* @param int $evalInterval
178179
* @param int $window
179180
* @param float $holdOut
180-
* @param \Rubix\ML\NeuralNet\CostFunctions\ClassificationLoss|null $costFn
181-
* @param \Rubix\ML\CrossValidation\Metrics\Metric|null $metric
181+
* @param ClassificationLoss|null $costFn
182+
* @param Metric|null $metric
182183
* @throws InvalidArgumentException
183184
*/
184185
public function __construct(

src/Classifiers/RadiusNeighbors.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class RadiusNeighbors implements Estimator, Learner, Probabilistic, Persistable
8989
* @param float $radius
9090
* @param bool $weighted
9191
* @param string $outlierClass
92-
* @param \Rubix\ML\Graph\Trees\Spatial|null $tree
92+
* @param Spatial|null $tree
9393
* @throws InvalidArgumentException
9494
*/
9595
public function __construct(

src/Classifiers/RandomForest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ class RandomForest implements Estimator, Learner, Probabilistic, Parallel, Ranks
118118
protected ?int $featureCount = null;
119119

120120
/**
121-
* @param \Rubix\ML\Learner|null $base
121+
* @param Learner|null $base
122122
* @param int $estimators
123123
* @param float $ratio
124124
* @param bool $balanced

src/Classifiers/SVC.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class SVC implements Estimator, Learner
5858
/**
5959
* The trained model instance.
6060
*
61-
* @var \svmmodel|null
61+
* @var svmmodel|null
6262
*/
6363
protected $model;
6464

@@ -73,7 +73,7 @@ class SVC implements Estimator, Learner
7373

7474
/**
7575
* @param float $c
76-
* @param \Rubix\ML\Kernels\SVM\Kernel|null $kernel
76+
* @param Kernel|null $kernel
7777
* @param bool $shrinking
7878
* @param float $tolerance
7979
* @param float $cacheSize

src/Classifiers/SoftmaxClassifier.php

+2-6
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,7 @@ class SoftmaxClassifier implements Estimator, Learner, Online, Probabilistic, Ve
106106
*
107107
* @var \Rubix\ML\NeuralNet\Network|null
108108
*/
109-
<<<<<<< HEAD
110109
protected ?\Rubix\ML\NeuralNet\Network $network = null;
111-
=======
112-
protected ?FeedForward $network = null;
113-
>>>>>>> 2.5
114110

115111
/**
116112
* The unique class labels.
@@ -128,12 +124,12 @@ class SoftmaxClassifier implements Estimator, Learner, Online, Probabilistic, Ve
128124

129125
/**
130126
* @param int $batchSize
131-
* @param \Rubix\ML\NeuralNet\Optimizers\Optimizer|null $optimizer
127+
* @param Optimizer|null $optimizer
132128
* @param float $l2Penalty
133129
* @param int $epochs
134130
* @param float $minChange
135131
* @param int $window
136-
* @param \Rubix\ML\NeuralNet\CostFunctions\ClassificationLoss|null $costFn
132+
* @param ClassificationLoss|null $costFn
137133
* @throws InvalidArgumentException
138134
*/
139135
public function __construct(

src/Clusterers/DBSCAN.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class DBSCAN implements Estimator
7878
/**
7979
* @param float $radius
8080
* @param int $minDensity
81-
* @param \Rubix\ML\Graph\Trees\Spatial|null $tree
81+
* @param Spatial|null $tree
8282
* @throws InvalidArgumentException
8383
*/
8484
public function __construct(float $radius = 0.5, int $minDensity = 5, ?Spatial $tree = null)

src/Clusterers/FuzzyCMeans.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ class FuzzyCMeans implements Estimator, Learner, Probabilistic, Verbose, Persist
122122
* @param float $fuzz
123123
* @param int $epochs
124124
* @param float $minChange
125-
* @param \Rubix\ML\Kernels\Distance\Distance|null $kernel
126-
* @param Seeders\Seeder|null $seeder
125+
* @param Distance|null $kernel
126+
* @param Seeder|null $seeder
127127
* @throws InvalidArgumentException
128128
*/
129129
public function __construct(

src/Clusterers/GaussianMixture.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ class GaussianMixture implements Estimator, Learner, Probabilistic, Verbose, Per
138138
* @param float $smoothing
139139
* @param int $epochs
140140
* @param float $minChange
141-
* @param Seeders\Seeder|null $seeder
141+
* @param Seeder|null $seeder
142142
* @throws InvalidArgumentException
143143
*/
144144
public function __construct(

src/Clusterers/KMeans.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ class KMeans implements Estimator, Learner, Online, Probabilistic, Verbose, Pers
136136
* @param int $epochs
137137
* @param float $minChange
138138
* @param int $window
139-
* @param \Rubix\ML\Kernels\Distance\Distance|null $kernel
140-
* @param Seeders\Seeder|null $seeder
139+
* @param Distance|null $kernel
140+
* @param Seeder|null $seeder
141141
* @throws InvalidArgumentException
142142
*/
143143
public function __construct(

src/Clusterers/MeanShift.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ class MeanShift implements Estimator, Learner, Probabilistic, Verbose, Persistab
139139
*
140140
* @param Dataset $dataset
141141
* @param float $percentile
142-
* @param \Rubix\ML\Kernels\Distance\Distance|null $kernel
142+
* @param Distance|null $kernel
143143
* @throws InvalidArgumentException
144144
* @return float
145145
*/
@@ -175,8 +175,8 @@ public static function estimateRadius(
175175
* @param float $ratio
176176
* @param int $epochs
177177
* @param float $minShift
178-
* @param \Rubix\ML\Graph\Trees\Spatial|null $tree
179-
* @param Seeders\Seeder|null $seeder
178+
* @param Spatial|null $tree
179+
* @param Seeder|null $seeder
180180
* @throws InvalidArgumentException
181181
*/
182182
public function __construct(

src/Clusterers/Seeders/KMC2.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class KMC2 implements Seeder
4343

4444
/**
4545
* @param int $m
46-
* @param \Rubix\ML\Kernels\Distance\Distance|null $kernel
46+
* @param Distance|null $kernel
4747
* @throws InvalidArgumentException
4848
*/
4949
public function __construct(int $m = 50, ?Distance $kernel = null)

src/Clusterers/Seeders/PlusPlus.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class PlusPlus implements Seeder
3636
protected Distance $kernel;
3737

3838
/**
39-
* @param \Rubix\ML\Kernels\Distance\Distance|null $kernel
39+
* @param Distance|null $kernel
4040
*/
4141
public function __construct(?Distance $kernel = null)
4242
{

src/Datasets/Generators/Blob.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class Blob implements Generator
3737
/**
3838
* The standard deviation of the blob.
3939
*
40-
* @var \Tensor\Vector|int|float
40+
* @var Vector|int|float
4141
*/
4242
protected $stdDev;
4343

0 commit comments

Comments
 (0)