summaryrefslogtreecommitdiff
path: root/src/utils/ByteUtils.scala
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils/ByteUtils.scala')
-rw-r--r--src/utils/ByteUtils.scala3
1 files changed, 3 insertions, 0 deletions
diff --git a/src/utils/ByteUtils.scala b/src/utils/ByteUtils.scala
index 18942c0..723164d 100644
--- a/src/utils/ByteUtils.scala
+++ b/src/utils/ByteUtils.scala
@@ -108,4 +108,7 @@ object ByteUtils {
def hammingDistance[T : BitOps : SizedNumeric](a: Seq[T], b: Seq[T]): Int =
(a xor b).map(_.bitsSet).reduce(_ @+ _)
+
+ def avgHammingDistance[T : BitOps : SizedNumeric](xs: Seq[Seq[T]]): Double =
+ xs.sliding(2).map({ case Stream(a: Seq[T], b: Seq[T]) => hammingDistance(a, b) }).reduce(_ @+ _) / xs.length.toDouble
}