mirror of
https://github.com/Llewellynvdm/php-ml.git
synced 2024-11-24 22:07:33 +00:00
[cs] remove more unused comments (#146)
* [cs] remove more unused comments * [cs] remove unused array phpdocs * [cs] remove empty lines in docs * [cs] space-proof useless docs * [cs] remove empty @param lines * [cs] remove references arrays
This commit is contained in:
parent
f4650c696c
commit
d85bfed468
@ -72,10 +72,6 @@ class DecisionTree implements Classifier
|
||||
$this->maxDepth = $maxDepth;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $samples
|
||||
* @param array $targets
|
||||
*/
|
||||
public function train(array $samples, array $targets)
|
||||
{
|
||||
$this->samples = array_merge($this->samples, $samples);
|
||||
@ -104,11 +100,6 @@ class DecisionTree implements Classifier
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $samples
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getColumnTypes(array $samples) : array
|
||||
{
|
||||
$types = [];
|
||||
@ -122,10 +113,6 @@ class DecisionTree implements Classifier
|
||||
return $types;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $records
|
||||
* @param int $depth
|
||||
*/
|
||||
protected function getSplitLeaf(array $records, int $depth = 0) : DecisionTreeLeaf
|
||||
{
|
||||
$split = $this->getBestSplit($records);
|
||||
@ -239,8 +226,6 @@ class DecisionTree implements Classifier
|
||||
*
|
||||
* If any of above methods were not called beforehand, then all features
|
||||
* are returned by default.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getSelectedFeatures() : array
|
||||
{
|
||||
@ -296,11 +281,6 @@ class DecisionTree implements Classifier
|
||||
return array_sum($giniParts) / count($colValues);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $samples
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function preprocess(array $samples) : array
|
||||
{
|
||||
// Detect and convert continuous data column values into
|
||||
@ -325,9 +305,6 @@ class DecisionTree implements Classifier
|
||||
return array_map(null, ...$columns);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $columnValues
|
||||
*/
|
||||
protected static function isCategoricalColumn(array $columnValues) : bool
|
||||
{
|
||||
$count = count($columnValues);
|
||||
|
@ -52,7 +52,6 @@ class Adaline extends Perceptron
|
||||
/**
|
||||
* Adapts the weights with respect to given samples and targets
|
||||
* by use of gradient descent learning rule
|
||||
* @param array $targets
|
||||
*/
|
||||
protected function runTraining(array $samples, array $targets)
|
||||
{
|
||||
|
@ -138,9 +138,6 @@ class LogisticRegression extends Adaline
|
||||
|
||||
/**
|
||||
* Executes Conjugate Gradient method to optimize the weights of the LogReg model
|
||||
*
|
||||
* @param array $samples
|
||||
* @param array $targets
|
||||
*/
|
||||
protected function runConjugateGradient(array $samples, array $targets, \Closure $gradientFunc)
|
||||
{
|
||||
|
@ -13,8 +13,6 @@ abstract class WeightedClassifier implements Classifier
|
||||
|
||||
/**
|
||||
* Sets the array including a weight for each sample
|
||||
*
|
||||
* @param array $weights
|
||||
*/
|
||||
public function setSampleWeights(array $weights)
|
||||
{
|
||||
|
@ -19,9 +19,6 @@ class ArrayDataset implements Dataset
|
||||
protected $targets = [];
|
||||
|
||||
/**
|
||||
* @param array $samples
|
||||
* @param array $targets
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public function __construct(array $samples, array $targets)
|
||||
@ -34,17 +31,11 @@ class ArrayDataset implements Dataset
|
||||
$this->targets = $targets;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getSamples() : array
|
||||
{
|
||||
return $this->samples;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getTargets() : array
|
||||
{
|
||||
return $this->targets;
|
||||
|
@ -47,8 +47,6 @@ abstract class EigenTransformerBase
|
||||
* Calculates eigenValues and eigenVectors of the given matrix. Returns
|
||||
* top eigenVectors along with the largest eigenValues. The total explained variance
|
||||
* of these eigenVectors will be no less than desired $totalVariance value
|
||||
*
|
||||
* @param array $matrix
|
||||
*/
|
||||
protected function eigenDecomposition(array $matrix)
|
||||
{
|
||||
@ -85,10 +83,6 @@ abstract class EigenTransformerBase
|
||||
|
||||
/**
|
||||
* Returns the reduced data
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function reduce(array $data) : array
|
||||
{
|
||||
|
@ -13,9 +13,6 @@ class TfIdfTransformer implements Transformer
|
||||
*/
|
||||
private $idf;
|
||||
|
||||
/**
|
||||
* @param array $samples
|
||||
*/
|
||||
public function __construct(array $samples = null)
|
||||
{
|
||||
if ($samples) {
|
||||
@ -23,9 +20,6 @@ class TfIdfTransformer implements Transformer
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $samples
|
||||
*/
|
||||
public function fit(array $samples)
|
||||
{
|
||||
$this->countTokensFrequency($samples);
|
||||
@ -36,9 +30,6 @@ class TfIdfTransformer implements Transformer
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $samples
|
||||
*/
|
||||
public function transform(array &$samples)
|
||||
{
|
||||
foreach ($samples as &$sample) {
|
||||
@ -48,9 +39,6 @@ class TfIdfTransformer implements Transformer
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $samples
|
||||
*/
|
||||
private function countTokensFrequency(array $samples)
|
||||
{
|
||||
$this->idf = array_fill_keys(array_keys($samples[0]), 0);
|
||||
|
@ -17,12 +17,6 @@ namespace Phpml\Helper\Optimizer;
|
||||
*/
|
||||
class ConjugateGradient extends GD
|
||||
{
|
||||
/**
|
||||
* @param array $samples
|
||||
* @param array $targets
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function runOptimization(array $samples, array $targets, \Closure $gradientCb) : array
|
||||
{
|
||||
$this->samples = $samples;
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
*
|
||||
* Class to obtain eigenvalues and eigenvectors of a real matrix.
|
||||
*
|
||||
* If A is symmetric, then A = V*D*V' where the eigenvalue matrix D
|
||||
@ -88,8 +87,6 @@ class EigenvalueDecomposition
|
||||
|
||||
/**
|
||||
* Constructor: Check for symmetry, then construct the eigenvalue decomposition
|
||||
*
|
||||
* @param array $Arg
|
||||
*/
|
||||
public function __construct(array $Arg)
|
||||
{
|
||||
|
@ -7,9 +7,6 @@ namespace Phpml\Math;
|
||||
class Product
|
||||
{
|
||||
/**
|
||||
* @param array $a
|
||||
* @param array $b
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function scalar(array $a, array $b)
|
||||
|
@ -9,8 +9,6 @@ use Phpml\Exception\InvalidArgumentException;
|
||||
class Mean
|
||||
{
|
||||
/**
|
||||
* @param array $numbers
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public static function arithmetic(array $numbers) : float
|
||||
@ -21,8 +19,6 @@ class Mean
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $numbers
|
||||
*
|
||||
* @return float|mixed
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
@ -44,8 +40,6 @@ class Mean
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $numbers
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
@ -60,8 +54,6 @@ class Mean
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $array
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
private static function checkArrayLength(array $array)
|
||||
|
@ -9,10 +9,6 @@ use Phpml\Exception\InvalidArgumentException;
|
||||
class Accuracy
|
||||
{
|
||||
/**
|
||||
* @param array $actualLabels
|
||||
* @param array $predictedLabels
|
||||
* @param bool $normalize
|
||||
*
|
||||
* @return float|int
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
|
@ -130,12 +130,6 @@ class ClassificationReport
|
||||
return 2.0 * (($precision * $recall) / $divider);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $actualLabels
|
||||
* @param array $predictedLabels
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private static function getLabelIndexedArray(array $actualLabels, array $predictedLabels) : array
|
||||
{
|
||||
$labels = array_values(array_unique(array_merge($actualLabels, $predictedLabels)));
|
||||
|
@ -6,13 +6,6 @@ namespace Phpml\Metric;
|
||||
|
||||
class ConfusionMatrix
|
||||
{
|
||||
/**
|
||||
* @param array $actualLabels
|
||||
* @param array $predictedLabels
|
||||
* @param array $labels
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function compute(array $actualLabels, array $predictedLabels, array $labels = null) : array
|
||||
{
|
||||
$labels = $labels ? array_flip($labels) : self::getUniqueLabels($actualLabels);
|
||||
@ -38,11 +31,6 @@ class ConfusionMatrix
|
||||
return $matrix;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $labels
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private static function generateMatrixWithZeros(array $labels) : array
|
||||
{
|
||||
$count = count($labels);
|
||||
@ -55,11 +43,6 @@ class ConfusionMatrix
|
||||
return $matrix;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $labels
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private static function getUniqueLabels(array $labels) : array
|
||||
{
|
||||
$labels = array_values(array_unique($labels));
|
||||
|
@ -39,9 +39,6 @@ abstract class LayeredNetwork implements Network
|
||||
return $this->layers[count($this->layers) - 1];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getOutput() : array
|
||||
{
|
||||
$result = [];
|
||||
|
@ -19,7 +19,6 @@ class Synapse
|
||||
protected $node;
|
||||
|
||||
/**
|
||||
* @param Node $node
|
||||
* @param float|null $weight
|
||||
*/
|
||||
public function __construct(Node $node, float $weight = null)
|
||||
|
@ -18,7 +18,6 @@ class Pipeline implements Estimator
|
||||
|
||||
/**
|
||||
* @param array|Transformer[] $transformers
|
||||
* @param Estimator $estimator
|
||||
*/
|
||||
public function __construct(array $transformers, Estimator $estimator)
|
||||
{
|
||||
@ -52,10 +51,6 @@ class Pipeline implements Estimator
|
||||
return $this->estimator;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $samples
|
||||
* @param array $targets
|
||||
*/
|
||||
public function train(array $samples, array $targets)
|
||||
{
|
||||
foreach ($this->transformers as $transformer) {
|
||||
@ -67,8 +62,6 @@ class Pipeline implements Estimator
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $samples
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function predict(array $samples)
|
||||
@ -78,9 +71,6 @@ class Pipeline implements Estimator
|
||||
return $this->estimator->predict($samples);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $samples
|
||||
*/
|
||||
private function transformSamples(array &$samples)
|
||||
{
|
||||
foreach ($this->transformers as $transformer) {
|
||||
|
@ -33,8 +33,6 @@ class Imputer implements Preprocessor
|
||||
|
||||
/**
|
||||
* @param mixed $missingValue
|
||||
* @param Strategy $strategy
|
||||
* @param int $axis
|
||||
* @param array|null $samples
|
||||
*/
|
||||
public function __construct($missingValue, Strategy $strategy, int $axis = self::AXIS_COLUMN, array $samples = [])
|
||||
@ -45,17 +43,11 @@ class Imputer implements Preprocessor
|
||||
$this->samples = $samples;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $samples
|
||||
*/
|
||||
public function fit(array $samples)
|
||||
{
|
||||
$this->samples = $samples;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $samples
|
||||
*/
|
||||
public function transform(array &$samples)
|
||||
{
|
||||
foreach ($samples as &$sample) {
|
||||
@ -63,9 +55,6 @@ class Imputer implements Preprocessor
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $sample
|
||||
*/
|
||||
private function preprocessSample(array &$sample)
|
||||
{
|
||||
foreach ($sample as $column => &$value) {
|
||||
@ -75,12 +64,6 @@ class Imputer implements Preprocessor
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $column
|
||||
* @param array $currentSample
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function getAxis(int $column, array $currentSample) : array
|
||||
{
|
||||
if (self::AXIS_ROW === $this->axis) {
|
||||
|
@ -9,9 +9,6 @@ use Phpml\Preprocessing\Imputer\Strategy;
|
||||
|
||||
class MeanStrategy implements Strategy
|
||||
{
|
||||
/**
|
||||
* @param array $currentAxis
|
||||
*/
|
||||
public function replaceValue(array $currentAxis) : float
|
||||
{
|
||||
return Mean::arithmetic($currentAxis);
|
||||
|
@ -9,9 +9,6 @@ use Phpml\Preprocessing\Imputer\Strategy;
|
||||
|
||||
class MedianStrategy implements Strategy
|
||||
{
|
||||
/**
|
||||
* @param array $currentAxis
|
||||
*/
|
||||
public function replaceValue(array $currentAxis) : float
|
||||
{
|
||||
return Mean::median($currentAxis);
|
||||
|
@ -10,8 +10,6 @@ use Phpml\Preprocessing\Imputer\Strategy;
|
||||
class MostFrequentStrategy implements Strategy
|
||||
{
|
||||
/**
|
||||
* @param array $currentAxis
|
||||
*
|
||||
* @return float|mixed
|
||||
*/
|
||||
public function replaceValue(array $currentAxis)
|
||||
|
@ -46,9 +46,6 @@ class Normalizer implements Preprocessor
|
||||
$this->norm = $norm;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $samples
|
||||
*/
|
||||
public function fit(array $samples)
|
||||
{
|
||||
if ($this->fitted) {
|
||||
@ -67,9 +64,6 @@ class Normalizer implements Preprocessor
|
||||
$this->fitted = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $samples
|
||||
*/
|
||||
public function transform(array &$samples)
|
||||
{
|
||||
$methods = [
|
||||
@ -86,9 +80,6 @@ class Normalizer implements Preprocessor
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $sample
|
||||
*/
|
||||
private function normalizeL1(array &$sample)
|
||||
{
|
||||
$norm1 = 0;
|
||||
@ -106,9 +97,6 @@ class Normalizer implements Preprocessor
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $sample
|
||||
*/
|
||||
private function normalizeL2(array &$sample)
|
||||
{
|
||||
$norm2 = 0;
|
||||
@ -126,9 +114,6 @@ class Normalizer implements Preprocessor
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $sample
|
||||
*/
|
||||
private function normalizeSTD(array &$sample)
|
||||
{
|
||||
foreach ($sample as $i => $val) {
|
||||
|
@ -189,11 +189,6 @@ class MLPClassifierTest extends TestCase
|
||||
new MLPClassifier(2, [2], [0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $synapses
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function getSynapsesNodes(array $synapses) : array
|
||||
{
|
||||
$nodes = [];
|
||||
|
@ -46,12 +46,6 @@ class StratifiedRandomSplitTest extends TestCase
|
||||
$this->assertEquals(1, $this->countSamplesByTarget($split->getTestLabels(), 2));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $splitTargets
|
||||
* @param $countTarget
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
private function countSamplesByTarget($splitTargets, $countTarget): int
|
||||
{
|
||||
$count = 0;
|
||||
|
@ -12,8 +12,6 @@ class ComparisonTest extends TestCase
|
||||
/**
|
||||
* @param mixed $a
|
||||
* @param mixed $b
|
||||
* @param string $operator
|
||||
* @param bool $expected
|
||||
*
|
||||
* @dataProvider provideData
|
||||
*/
|
||||
|
@ -261,7 +261,6 @@ class MatrixTest extends TestCase
|
||||
$matrix1 = [[1, 1], [2, 2]];
|
||||
$matrix2 = [[3, 3], [3, 3], [3, 3]];
|
||||
$dot = [6, 12];
|
||||
|
||||
$this->assertEquals($dot, Matrix::dot($matrix2, $matrix1));
|
||||
}
|
||||
}
|
||||
|
@ -10,9 +10,6 @@ use PHPUnit\Framework\TestCase;
|
||||
class BinaryStepTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @param $expected
|
||||
* @param $value
|
||||
*
|
||||
* @dataProvider binaryStepProvider
|
||||
*/
|
||||
public function testBinaryStepActivationFunction($expected, $value)
|
||||
|
@ -10,9 +10,6 @@ use PHPUnit\Framework\TestCase;
|
||||
class GaussianTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @param $expected
|
||||
* @param $value
|
||||
*
|
||||
* @dataProvider gaussianProvider
|
||||
*/
|
||||
public function testGaussianActivationFunction($expected, $value)
|
||||
|
@ -10,10 +10,6 @@ use PHPUnit\Framework\TestCase;
|
||||
class HyperboliTangentTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @param $beta
|
||||
* @param $expected
|
||||
* @param $value
|
||||
*
|
||||
* @dataProvider tanhProvider
|
||||
*/
|
||||
public function testHyperbolicTangentActivationFunction($beta, $expected, $value)
|
||||
|
@ -10,10 +10,6 @@ use PHPUnit\Framework\TestCase;
|
||||
class PReLUTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @param $beta
|
||||
* @param $expected
|
||||
* @param $value
|
||||
*
|
||||
* @dataProvider preluProvider
|
||||
*/
|
||||
public function testPReLUActivationFunction($beta, $expected, $value)
|
||||
|
@ -10,10 +10,6 @@ use PHPUnit\Framework\TestCase;
|
||||
class SigmoidTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @param $beta
|
||||
* @param $expected
|
||||
* @param $value
|
||||
*
|
||||
* @dataProvider sigmoidProvider
|
||||
*/
|
||||
public function testSigmoidActivationFunction($beta, $expected, $value)
|
||||
|
@ -10,10 +10,6 @@ use PHPUnit\Framework\TestCase;
|
||||
class ThresholdedReLUTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @param $theta
|
||||
* @param $expected
|
||||
* @param $value
|
||||
*
|
||||
* @dataProvider thresholdProvider
|
||||
*/
|
||||
public function testThresholdedReLUActivationFunction($theta, $expected, $value)
|
||||
|
Loading…
Reference in New Issue
Block a user