Dev #20
@ -12,7 +12,7 @@ class MultivariateBin(override val center: RealVector, val sizes: RealVector, va
|
||||
}
|
||||
|
||||
override fun contains(vector: RealVector): Boolean {
|
||||
assert(vector.size == center.size)
|
||||
if(vector.size != center.size) error("Dimension mismatch for input vector. Expected ${center.size}, but found ${vector.size}")
|
||||
return vector.asSequence().mapIndexed { i, value -> value in (center[i] - sizes[i] / 2)..(center[i] + sizes[i] / 2) }.all { it }
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
package scientifik.kmath.histogram
|
||||
|
||||
import org.junit.Test
|
||||
import scientifik.kmath.linear.Vector
|
||||
import kotlin.random.Random
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertFalse
|
||||
import kotlin.test.assertTrue
|
@ -70,11 +70,10 @@ class UnivariateHistogram private constructor(private val factory: (Double) -> U
|
||||
fun custom(borders: DoubleArray): UnivariateHistogram {
|
||||
val sorted = borders.sortedArray()
|
||||
return UnivariateHistogram { value ->
|
||||
if (value < sorted.first()) {
|
||||
UnivariateBin(Double.NEGATIVE_INFINITY, Double.MAX_VALUE)
|
||||
} else if (value > sorted.last()) {
|
||||
UnivariateBin(Double.POSITIVE_INFINITY, Double.MAX_VALUE)
|
||||
} else {
|
||||
when {
|
||||
value < sorted.first() -> UnivariateBin(Double.NEGATIVE_INFINITY, Double.MAX_VALUE)
|
||||
value > sorted.last() -> UnivariateBin(Double.POSITIVE_INFINITY, Double.MAX_VALUE)
|
||||
else -> {
|
||||
val index = (0 until sorted.size).first { value > sorted[it] }
|
||||
val left = sorted[index]
|
||||
val right = sorted[index + 1]
|
||||
@ -84,5 +83,6 @@ class UnivariateHistogram private constructor(private val factory: (Double) -> U
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun UnivariateHistogram.fill(sequence: Iterable<Double>) = sequence.forEach { put(it) }
|
||||
|
Loading…
Reference in New Issue
Block a user