Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/undo-ransomware/ransomware_detection.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias <ilovemilk@wusa.io>2019-05-17 18:43:06 +0300
committerMatthias <ilovemilk@wusa.io>2019-05-17 18:43:06 +0300
commitca94620e473a5c3ec48e548fe3e40d0d103ec47f (patch)
tree6596853e2de7a24d1b0104fe3dd3ca8a8da15f4f
parent8b22abc9a6c6ed29b54fe6ae480e670e2584353a (diff)
add more standard deviation tests
-rw-r--r--lib/Entropy/Entropy.php27
-rw-r--r--tests/Unit/Entropy/EntropyTest.php5
2 files changed, 3 insertions, 29 deletions
diff --git a/lib/Entropy/Entropy.php b/lib/Entropy/Entropy.php
index 798db8b..9f4f038 100644
--- a/lib/Entropy/Entropy.php
+++ b/lib/Entropy/Entropy.php
@@ -61,33 +61,6 @@ class Entropy
return sqrt((1 / $n) * $sum - pow($mean, 2));
}
- /**
- * Calculates the standard deviation.
- *
- * @param array $array
- *
- * @return float
- */
- public function sd($array)
- {
- if (is_array($array) && count($array) > 0) {
- // square root of sum of squares devided by N-1
- return sqrt(array_sum(array_map(
- function ($x, $mean) {
- return pow($x - $mean, 2);
- },
- $array,
- array_fill(
- 0,
- count($array),
- (array_sum($array) / count($array))
- )
- )) / (count($array) - 1));
- }
-
- return 0.0;
- }
-
public function streamMean($oldMean, $value, $step) {
$mean = 0;
if ($step === 1) {
diff --git a/tests/Unit/Entropy/EntropyTest.php b/tests/Unit/Entropy/EntropyTest.php
index c4f515d..2e74ecf 100644
--- a/tests/Unit/Entropy/EntropyTest.php
+++ b/tests/Unit/Entropy/EntropyTest.php
@@ -63,7 +63,9 @@ class EntropyTest extends TestCase
public function dataSd()
{
$tests = [];
- $tests[] = [[10, 2, 38, 23, 38, 23, 21], 13.284434];
+ $tests[] = [[10, 2, 38, 23, 38, 23, 21], 12.298996];
+ $tests[] = [[10, 12, 23, 23, 16, 23, 21, 16], 4.898979]
+ $tests[] = [[-5, 1, 8, 7, 2], 4.673328]
return $tests;
}
@@ -76,7 +78,6 @@ class EntropyTest extends TestCase
*/
public function testSd($data, $sd)
{
- $this->assertEquals(number_format($this->invokePrivate($this->entropy, 'sd', [$data]), 6), $sd);
$sum = 0.0;
$mean = 0.0;
$standardDeviation = 0.0;