Dev #20
@ -12,7 +12,7 @@ class MultivariateBin(override val center: RealVector, val sizes: RealVector, va
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun contains(vector: RealVector): Boolean {
|
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 }
|
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
|
package scientifik.kmath.histogram
|
||||||
|
|
||||||
import org.junit.Test
|
|
||||||
import scientifik.kmath.linear.Vector
|
import scientifik.kmath.linear.Vector
|
||||||
import kotlin.random.Random
|
import kotlin.random.Random
|
||||||
|
import kotlin.test.Test
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
import kotlin.test.assertFalse
|
import kotlin.test.assertFalse
|
||||||
import kotlin.test.assertTrue
|
import kotlin.test.assertTrue
|
@ -70,11 +70,10 @@ class UnivariateHistogram private constructor(private val factory: (Double) -> U
|
|||||||
fun custom(borders: DoubleArray): UnivariateHistogram {
|
fun custom(borders: DoubleArray): UnivariateHistogram {
|
||||||
val sorted = borders.sortedArray()
|
val sorted = borders.sortedArray()
|
||||||
return UnivariateHistogram { value ->
|
return UnivariateHistogram { value ->
|
||||||
if (value < sorted.first()) {
|
when {
|
||||||
UnivariateBin(Double.NEGATIVE_INFINITY, Double.MAX_VALUE)
|
value < sorted.first() -> UnivariateBin(Double.NEGATIVE_INFINITY, Double.MAX_VALUE)
|
||||||
} else if (value > sorted.last()) {
|
value > sorted.last() -> UnivariateBin(Double.POSITIVE_INFINITY, Double.MAX_VALUE)
|
||||||
UnivariateBin(Double.POSITIVE_INFINITY, Double.MAX_VALUE)
|
else -> {
|
||||||
} else {
|
|
||||||
val index = (0 until sorted.size).first { value > sorted[it] }
|
val index = (0 until sorted.size).first { value > sorted[it] }
|
||||||
val left = sorted[index]
|
val left = sorted[index]
|
||||||
val right = sorted[index + 1]
|
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) }
|
fun UnivariateHistogram.fill(sequence: Iterable<Double>) = sequence.forEach { put(it) }
|
||||||
|
Loading…
Reference in New Issue
Block a user