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