Code Duplication    Length = 19-19 lines in 2 locations

src/Phpml/DimensionReduction/LDA.php 1 location

@@ 52-70 (lines=19) @@
49
     *
50
     * @throws \Exception
51
     */
52
    public function __construct($totalVariance = null, $numFeatures = null)
53
    {
54
        if ($totalVariance !== null && ($totalVariance < 0.1 || $totalVariance > 0.99)) {
55
            throw new \Exception("Total variance can be a value between 0.1 and 0.99");
56
        }
57
        if ($numFeatures !== null && $numFeatures <= 0) {
58
            throw new \Exception("Number of features to be preserved should be greater than 0");
59
        }
60
        if ($totalVariance !== null && $numFeatures !== null) {
61
            throw new \Exception("Either totalVariance or numFeatures should be specified in order to run the algorithm");
62
        }
63
64
        if ($numFeatures !== null) {
65
            $this->numFeatures = $numFeatures;
66
        }
67
        if ($totalVariance !== null) {
68
            $this->totalVariance = $totalVariance;
69
        }
70
    }
71
72
    /**
73
     * Trains the algorithm to transform the given data to a lower dimensional space.

src/Phpml/DimensionReduction/PCA.php 1 location

@@ 36-54 (lines=19) @@
33
     *
34
     * @throws \Exception
35
     */
36
    public function __construct($totalVariance = null, $numFeatures = null)
37
    {
38
        if ($totalVariance !== null && ($totalVariance < 0.1 || $totalVariance > 0.99)) {
39
            throw new \Exception("Total variance can be a value between 0.1 and 0.99");
40
        }
41
        if ($numFeatures !== null && $numFeatures <= 0) {
42
            throw new \Exception("Number of features to be preserved should be greater than 0");
43
        }
44
        if ($totalVariance !== null && $numFeatures !== null) {
45
            throw new \Exception("Either totalVariance or numFeatures should be specified in order to run the algorithm");
46
        }
47
48
        if ($numFeatures !== null) {
49
            $this->numFeatures = $numFeatures;
50
        }
51
        if ($totalVariance !== null) {
52
            $this->totalVariance = $totalVariance;
53
        }
54
    }
55
56
    /**
57
     * Takes a data and returns a lower dimensional version