Run newest php-cs-fixer (#108)

This commit is contained in:
Ante Lucic 2017-07-26 02:24:47 -04:00 committed by Arkadiusz Kondas
parent 08d974bb4c
commit 07041ec608
11 changed files with 70 additions and 32 deletions

View File

@ -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)
);
}

View File

@ -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");
}

View File

@ -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 " .

View File

@ -99,11 +99,11 @@ class Perceptron implements Classifier, IncrementalEstimator
$this->trainByLabel($samples, $targets, $labels);
}
/**
* @param array $samples
* @param array $targets
* @param array $labels
*/
/**
* @param array $samples
* @param array $targets
* @param array $labels
*/
public function trainBinary(array $samples, array $targets, array $labels)
{
if ($this->normalizer) {

View File

@ -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);

View File

@ -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;

View File

@ -301,7 +301,7 @@ class EigenvalueDecomposition
$p = -$s * $s2 * $c3 * $el1 * $this->e[$l] / $dl1;
$this->e[$l] = $s * $p;
$this->d[$l] = $c * $p;
// Check for convergence.
// Check for convergence.
} while (abs($this->e[$l]) > $eps * $tst1);
}
$this->d[$l] = $this->d[$l] + $f;
@ -493,7 +493,7 @@ class EigenvalueDecomposition
$this->e[$n] = 0.0;
--$n;
$iter = 0;
// Two roots found
// Two roots found
} elseif ($l == $n - 1) {
$w = $this->H[$n][$n - 1] * $this->H[$n - 1][$n];
$p = ($this->H[$n - 1][$n - 1] - $this->H[$n][$n]) / 2.0;
@ -541,7 +541,7 @@ class EigenvalueDecomposition
$this->V[$i][$n - 1] = $q * $z + $p * $this->V[$i][$n];
$this->V[$i][$n] = $q * $this->V[$i][$n] - $p * $z;
}
// Complex pair
// Complex pair
} else {
$this->d[$n - 1] = $x + $p;
$this->d[$n] = $x + $p;
@ -550,7 +550,7 @@ class EigenvalueDecomposition
}
$n = $n - 2;
$iter = 0;
// No convergence yet
// No convergence yet
} else {
// Form shift
$x = $this->H[$n][$n];
@ -715,7 +715,7 @@ class EigenvalueDecomposition
} else {
$this->H[$i][$n] = -$r / ($eps * $norm);
}
// Solve real equations
// Solve real equations
} else {
$x = $this->H[$i][$i + 1];
$y = $this->H[$i + 1][$i];
@ -737,7 +737,7 @@ class EigenvalueDecomposition
}
}
}
// Complex vector
// Complex vector
} elseif ($q < 0) {
$l = $n - 1;
// Last vector component imaginary so matrix is triangular

View File

@ -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]
);
}
}

View File

@ -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);
}

View File

@ -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,

View File

@ -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]);
}