diff options
author | Matthias Held <ilovemilk@wusa.io> | 2019-05-19 20:25:32 +0300 |
---|---|---|
committer | Matthias Held <ilovemilk@wusa.io> | 2019-05-19 20:25:32 +0300 |
commit | 1999852dd4c45e92982613d5946352a0a4b6a796 (patch) | |
tree | aa406ab97266f687e4654d4e538fd8b0fbf8d0e0 | |
parent | 16bfb4fd5d8d50863d4ec5cc156c4f1ad725e338 (diff) |
improve documentation and naming
-rw-r--r-- | lib/Analyzer/EntropyAnalyzer.php | 4 | ||||
-rw-r--r-- | lib/Entropy/Entropy.php | 28 |
2 files changed, 27 insertions, 5 deletions
diff --git a/lib/Analyzer/EntropyAnalyzer.php b/lib/Analyzer/EntropyAnalyzer.php index 1a69604..6aa39ba 100644 --- a/lib/Analyzer/EntropyAnalyzer.php +++ b/lib/Analyzer/EntropyAnalyzer.php @@ -143,8 +143,8 @@ class EntropyAnalyzer if (strlen($data) === $blockSize) { $entropy = $this->entropy->calculateEntropy($data); $sum = $sum + pow($entropy, 2); - $mean = $this->entropy->streamMean($mean, $entropy, $step); - $standardDeviation = $this->entropy->streamStandardDeviation($step, $sum, $mean); + $mean = $this->entropy->calculateMeanOfSeries($mean, $entropy, $step); + $standardDeviation = $this->entropy->calculateStandardDeviationOfSeries($step, $sum, $mean); } } fclose($handle); diff --git a/lib/Entropy/Entropy.php b/lib/Entropy/Entropy.php index 9f4f038..96b152e 100644 --- a/lib/Entropy/Entropy.php +++ b/lib/Entropy/Entropy.php @@ -57,11 +57,33 @@ class Entropy return $entropy; } - public function streamStandardDeviation($n, $sum, $mean) { - return sqrt((1 / $n) * $sum - pow($mean, 2)); + /** + * Calculates the standard deviation of a continoues series by passing + * the current number of values used to calculate the standard deviation + * the sum of all these values and the mean of all these values. + * + * @param float $step current value + * @param float $sum sum of all values + * @param float $mean mean of all values + * + * @return float + */ + public function calculateStandardDeviationOfSeries($step, $sum, $mean) { + return sqrt((1 / $step) * $sum - pow($mean, 2)); } - public function streamMean($oldMean, $value, $step) { + /** + * Calculates the mean of a continoues series by passing the old mean + * the new value and the number of values used to calculate the mean + * including the new one. + * + * @param float $oldMean + * @param float $value + * @param float $step + * + * @param float + */ + public function calculateMeanOfSeries($oldMean, $value, $step) { $mean = 0; if ($step === 1) { $mean = (($step - 1) / $step) + ($value / $step); |