From 20a7c6c4f11f334a2bd9eab37aab04e790c26f9a Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Mon, 5 Nov 2018 16:11:53 +0300 Subject: [PATCH] MultivariateHistogram fix --- .../kotlin/scientifik/kmath/histogram/FastHistogram.kt | 6 +++--- .../kmath/histogram/MultivariateHistogramTest.kt | 7 ++++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/kmath-core/src/commonMain/kotlin/scientifik/kmath/histogram/FastHistogram.kt b/kmath-core/src/commonMain/kotlin/scientifik/kmath/histogram/FastHistogram.kt index 5f69f9d12..3852de316 100644 --- a/kmath-core/src/commonMain/kotlin/scientifik/kmath/histogram/FastHistogram.kt +++ b/kmath-core/src/commonMain/kotlin/scientifik/kmath/histogram/FastHistogram.kt @@ -17,7 +17,7 @@ class MultivariateBin(override val center: RealVector, val sizes: RealVector, va return vector.asSequence().mapIndexed { i, value -> value in (center[i] - sizes[i] / 2)..(center[i] + sizes[i] / 2) }.all { it } } - override val value: Number get() = counter.sum() + override val value get() = counter.sum() internal operator fun inc() = this.also { counter.increment() } override val dimension: Int get() = center.size @@ -51,8 +51,8 @@ class FastHistogram( val center = indexArray.mapIndexed { axis, index -> when (index) { 0 -> Double.NEGATIVE_INFINITY - actualSizes[axis] -> Double.POSITIVE_INFINITY - else -> lower[axis] + (index - 1) * binSize[axis] + actualSizes[axis] - 1 -> Double.POSITIVE_INFINITY + else -> lower[axis] + (index.toDouble() - 0.5) * binSize[axis] } }.toVector() MultivariateBin(center, binSize) diff --git a/kmath-core/src/commonTest/kotlin/scientifik/kmath/histogram/MultivariateHistogramTest.kt b/kmath-core/src/commonTest/kotlin/scientifik/kmath/histogram/MultivariateHistogramTest.kt index 2fbbbc88d..842a12ae4 100644 --- a/kmath-core/src/commonTest/kotlin/scientifik/kmath/histogram/MultivariateHistogramTest.kt +++ b/kmath-core/src/commonTest/kotlin/scientifik/kmath/histogram/MultivariateHistogramTest.kt @@ -14,10 +14,11 @@ class MultivariateHistogramTest { (-1.0..1.0), (-1.0..1.0) ) - histogram.put(0.6, 0.6) + histogram.put(0.55, 0.55) val bin = histogram.find { it.value.toInt() > 0 }!! - assertTrue { bin.contains(Vector.ofReal(0.6, 0.6)) } - assertFalse { bin.contains(Vector.ofReal(-0.6, 0.6)) } + assertTrue { bin.contains(Vector.ofReal(0.55, 0.55)) } + assertTrue { bin.contains(Vector.ofReal(0.6, 0.5)) } + assertFalse { bin.contains(Vector.ofReal(-0.55, 0.55)) } } @Test