forked from kscience/kmath
MultivariateHistogram fix
This commit is contained in:
parent
98622e64c4
commit
20a7c6c4f1
@ -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 }
|
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() }
|
internal operator fun inc() = this.also { counter.increment() }
|
||||||
|
|
||||||
override val dimension: Int get() = center.size
|
override val dimension: Int get() = center.size
|
||||||
@ -51,8 +51,8 @@ class FastHistogram(
|
|||||||
val center = indexArray.mapIndexed { axis, index ->
|
val center = indexArray.mapIndexed { axis, index ->
|
||||||
when (index) {
|
when (index) {
|
||||||
0 -> Double.NEGATIVE_INFINITY
|
0 -> Double.NEGATIVE_INFINITY
|
||||||
actualSizes[axis] -> Double.POSITIVE_INFINITY
|
actualSizes[axis] - 1 -> Double.POSITIVE_INFINITY
|
||||||
else -> lower[axis] + (index - 1) * binSize[axis]
|
else -> lower[axis] + (index.toDouble() - 0.5) * binSize[axis]
|
||||||
}
|
}
|
||||||
}.toVector()
|
}.toVector()
|
||||||
MultivariateBin(center, binSize)
|
MultivariateBin(center, binSize)
|
||||||
|
@ -14,10 +14,11 @@ class MultivariateHistogramTest {
|
|||||||
(-1.0..1.0),
|
(-1.0..1.0),
|
||||||
(-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 }!!
|
val bin = histogram.find { it.value.toInt() > 0 }!!
|
||||||
assertTrue { bin.contains(Vector.ofReal(0.6, 0.6)) }
|
assertTrue { bin.contains(Vector.ofReal(0.55, 0.55)) }
|
||||||
assertFalse { bin.contains(Vector.ofReal(-0.6, 0.6)) }
|
assertTrue { bin.contains(Vector.ofReal(0.6, 0.5)) }
|
||||||
|
assertFalse { bin.contains(Vector.ofReal(-0.55, 0.55)) }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Loading…
Reference in New Issue
Block a user