mirror of
https://github.com/Llewellynvdm/php-ml.git
synced 2024-11-21 20:45:10 +00:00
Run newest php-cs-fixer (#108)
This commit is contained in:
parent
08d974bb4c
commit
07041ec608
@ -101,7 +101,8 @@ class DecisionTree implements Classifier
|
||||
} elseif (count($this->columnNames) > $this->featureCount) {
|
||||
$this->columnNames = array_slice($this->columnNames, 0, $this->featureCount);
|
||||
} elseif (count($this->columnNames) < $this->featureCount) {
|
||||
$this->columnNames = array_merge($this->columnNames,
|
||||
$this->columnNames = array_merge(
|
||||
$this->columnNames,
|
||||
range(count($this->columnNames), $this->featureCount - 1)
|
||||
);
|
||||
}
|
||||
|
@ -39,9 +39,12 @@ class Adaline extends Perceptron
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function __construct(float $learningRate = 0.001, int $maxIterations = 1000,
|
||||
bool $normalizeInputs = true, int $trainingType = self::BATCH_TRAINING)
|
||||
{
|
||||
public function __construct(
|
||||
float $learningRate = 0.001,
|
||||
int $maxIterations = 1000,
|
||||
bool $normalizeInputs = true,
|
||||
int $trainingType = self::BATCH_TRAINING
|
||||
) {
|
||||
if (!in_array($trainingType, [self::BATCH_TRAINING, self::ONLINE_TRAINING])) {
|
||||
throw new \Exception("Adaline can only be trained with batch and online/stochastic gradient descent algorithm");
|
||||
}
|
||||
|
@ -67,10 +67,13 @@ class LogisticRegression extends Adaline
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function __construct(int $maxIterations = 500, bool $normalizeInputs = true,
|
||||
int $trainingType = self::CONJUGATE_GRAD_TRAINING, string $cost = 'sse',
|
||||
string $penalty = 'L2')
|
||||
{
|
||||
public function __construct(
|
||||
int $maxIterations = 500,
|
||||
bool $normalizeInputs = true,
|
||||
int $trainingType = self::CONJUGATE_GRAD_TRAINING,
|
||||
string $cost = 'sse',
|
||||
string $penalty = 'L2'
|
||||
) {
|
||||
$trainingTypes = range(self::BATCH_TRAINING, self::CONJUGATE_GRAD_TRAINING);
|
||||
if (!in_array($trainingType, $trainingTypes)) {
|
||||
throw new \Exception("Logistic regression can only be trained with " .
|
||||
|
@ -22,8 +22,14 @@ class SVC extends SupportVectorMachine implements Classifier
|
||||
* @param bool $probabilityEstimates
|
||||
*/
|
||||
public function __construct(
|
||||
int $kernel = Kernel::LINEAR, float $cost = 1.0, int $degree = 3, float $gamma = null, float $coef0 = 0.0,
|
||||
float $tolerance = 0.001, int $cacheSize = 100, bool $shrinking = true,
|
||||
int $kernel = Kernel::LINEAR,
|
||||
float $cost = 1.0,
|
||||
int $degree = 3,
|
||||
float $gamma = null,
|
||||
float $coef0 = 0.0,
|
||||
float $tolerance = 0.001,
|
||||
int $cacheSize = 100,
|
||||
bool $shrinking = true,
|
||||
bool $probabilityEstimates = false
|
||||
) {
|
||||
parent::__construct(Type::C_SVC, $kernel, $cost, 0.5, $degree, $gamma, $coef0, 0.1, $tolerance, $cacheSize, $shrinking, $probabilityEstimates);
|
||||
|
@ -243,7 +243,9 @@ class StochasticGD extends Optimizer
|
||||
function ($w1, $w2) {
|
||||
return abs($w1 - $w2) > $this->threshold ? 1 : 0;
|
||||
},
|
||||
$oldTheta, $this->theta);
|
||||
$oldTheta,
|
||||
$this->theta
|
||||
);
|
||||
|
||||
if (array_sum($diff) == 0) {
|
||||
return true;
|
||||
|
@ -150,7 +150,12 @@ class Covariance
|
||||
$cov[$i][$k] = $cov[$k][$i];
|
||||
} else {
|
||||
$cov[$i][$k] = self::fromDataset(
|
||||
$data, $i, $k, true, $means[$i], $means[$k]
|
||||
$data,
|
||||
$i,
|
||||
$k,
|
||||
true,
|
||||
$means[$i],
|
||||
$means[$k]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -22,9 +22,15 @@ class SVR extends SupportVectorMachine implements Regression
|
||||
* @param bool $shrinking
|
||||
*/
|
||||
public function __construct(
|
||||
int $kernel = Kernel::RBF, int $degree = 3, float $epsilon = 0.1, float $cost = 1.0,
|
||||
float $gamma = null, float $coef0 = 0.0, float $tolerance = 0.001,
|
||||
int $cacheSize = 100, bool $shrinking = true
|
||||
int $kernel = Kernel::RBF,
|
||||
int $degree = 3,
|
||||
float $epsilon = 0.1,
|
||||
float $cost = 1.0,
|
||||
float $gamma = null,
|
||||
float $coef0 = 0.0,
|
||||
float $tolerance = 0.001,
|
||||
int $cacheSize = 100,
|
||||
bool $shrinking = true
|
||||
) {
|
||||
parent::__construct(Type::EPSILON_SVR, $kernel, $cost, 0.5, $degree, $gamma, $coef0, $epsilon, $tolerance, $cacheSize, $shrinking, false);
|
||||
}
|
||||
|
@ -105,9 +105,18 @@ class SupportVectorMachine
|
||||
* @param bool $probabilityEstimates
|
||||
*/
|
||||
public function __construct(
|
||||
int $type, int $kernel, float $cost = 1.0, float $nu = 0.5, int $degree = 3,
|
||||
float $gamma = null, float $coef0 = 0.0, float $epsilon = 0.1, float $tolerance = 0.001,
|
||||
int $cacheSize = 100, bool $shrinking = true, bool $probabilityEstimates = false
|
||||
int $type,
|
||||
int $kernel,
|
||||
float $cost = 1.0,
|
||||
float $nu = 0.5,
|
||||
int $degree = 3,
|
||||
float $gamma = null,
|
||||
float $coef0 = 0.0,
|
||||
float $epsilon = 0.1,
|
||||
float $tolerance = 0.001,
|
||||
int $cacheSize = 100,
|
||||
bool $shrinking = true,
|
||||
bool $probabilityEstimates = false
|
||||
) {
|
||||
$this->type = $type;
|
||||
$this->kernel = $kernel;
|
||||
@ -241,7 +250,8 @@ class SupportVectorMachine
|
||||
*/
|
||||
private function buildTrainCommand(string $trainingSetFileName, string $modelFileName): string
|
||||
{
|
||||
return sprintf('%ssvm-train%s -s %s -t %s -c %s -n %s -d %s%s -r %s -p %s -m %s -e %s -h %d -b %d %s %s',
|
||||
return sprintf(
|
||||
'%ssvm-train%s -s %s -t %s -c %s -n %s -d %s%s -r %s -p %s -m %s -e %s -h %d -b %d %s %s',
|
||||
$this->binPath,
|
||||
$this->getOSExtension(),
|
||||
$this->type,
|
||||
|
@ -124,10 +124,12 @@ class NormalizerTest extends TestCase
|
||||
// Values in the vector should be some value between -3 and +3
|
||||
$this->assertCount(10, $samples);
|
||||
foreach ($samples as $sample) {
|
||||
$errors = array_filter($sample,
|
||||
$errors = array_filter(
|
||||
$sample,
|
||||
function ($element) {
|
||||
return $element < -3 || $element > 3;
|
||||
});
|
||||
}
|
||||
);
|
||||
$this->assertCount(0, $errors);
|
||||
$this->assertEquals(0, $sample[3]);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user