From 6247e79884069853f2c523013744826147b06354 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Sun, 10 Apr 2022 13:41:41 +0300 Subject: [PATCH] Refactor multivariate histograms --- CHANGELOG.md | 1 + gradle.properties | 2 + .../space/kscience/kmath/nd/AlgebraND.kt | 2 +- .../space/kscience/kmath/nd/BufferND.kt | 23 ++- .../space/kscience/kmath/histogram/Counter.kt | 3 +- .../kmath/histogram/DoubleHistogramGroup.kt | 140 --------------- .../kscience/kmath/histogram/Histogram.kt | 9 + .../kscience/kmath/histogram/HistogramND.kt | 76 ++++++++ .../kmath/histogram/IndexedHistogramGroup.kt | 84 --------- .../histogram/UniformHistogramGroupND.kt | 163 ++++++++++++++++++ .../histogram/MultivariateHistogramTest.kt | 9 +- .../kmath/histogram/TreeHistogramSpace.kt | 2 +- 12 files changed, 275 insertions(+), 239 deletions(-) delete mode 100644 kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/DoubleHistogramGroup.kt create mode 100644 kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/HistogramND.kt delete mode 100644 kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/IndexedHistogramGroup.kt create mode 100644 kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/UniformHistogramGroupND.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index d710c330b..bc5447449 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -49,6 +49,7 @@ - Default Buffer and ND algebras are now Ops and lack neutral elements (0, 1) as well as algebra-level shapes. - Tensor algebra takes read-only structures as input and inherits AlgebraND - `UnivariateDistribution` renamed to `Distribution1D` +- Rework of histograms. ### Deprecated - Specialized `DoubleBufferAlgebra` diff --git a/gradle.properties b/gradle.properties index a7cd2f876..847c3dda6 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,6 +6,8 @@ kotlin.code.style=official kotlin.jupyter.add.scanner=false kotlin.mpp.stability.nowarn=true kotlin.native.ignoreDisabledTargets=true +kotlin.incremental.js.ir=true + org.gradle.configureondemand=true org.gradle.jvmargs=-XX:MaxMetaspaceSize=1G org.gradle.parallel=true diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/AlgebraND.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/AlgebraND.kt index a071c1eb3..a9712e870 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/AlgebraND.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/AlgebraND.kt @@ -194,7 +194,7 @@ public interface RingOpsND> : RingOps>, Gro override fun multiply(left: StructureND, right: StructureND): StructureND = zip(left, right) { aValue, bValue -> multiply(aValue, bValue) } - //TODO move to extensions after KEEP-176 + //TODO move to extensions with context receivers /** * Multiplies an ND structure by an element of it. diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/BufferND.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/BufferND.kt index 539499794..2401f6319 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/BufferND.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/BufferND.kt @@ -32,18 +32,23 @@ public open class BufferND( /** * Transform structure to a new structure using provided [BufferFactory] and optimizing if argument is [BufferND] */ -public inline fun StructureND.mapToBuffer( - factory: BufferFactory = Buffer.Companion::auto, +public inline fun StructureND.mapToBuffer( + factory: BufferFactory, crossinline transform: (T) -> R, -): BufferND { - return if (this is BufferND) - BufferND(this.indices, factory.invoke(indices.linearSize) { transform(buffer[it]) }) - else { - val strides = DefaultStrides(shape) - BufferND(strides, factory.invoke(strides.linearSize) { transform(get(strides.index(it))) }) - } +): BufferND = if (this is BufferND) + BufferND(this.indices, factory.invoke(indices.linearSize) { transform(buffer[it]) }) +else { + val strides = DefaultStrides(shape) + BufferND(strides, factory.invoke(strides.linearSize) { transform(get(strides.index(it))) }) } +/** + * Transform structure to a new structure using inferred [BufferFactory] + */ +public inline fun StructureND.mapToBuffer( + crossinline transform: (T) -> R, +): BufferND = mapToBuffer(Buffer.Companion::auto, transform) + /** * Represents [MutableStructureND] over [MutableBuffer]. * diff --git a/kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/Counter.kt b/kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/Counter.kt index 291284444..fe3278026 100644 --- a/kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/Counter.kt +++ b/kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/Counter.kt @@ -18,7 +18,8 @@ public interface Counter { public val value: T public companion object { - public fun double(): ObjectCounter = ObjectCounter(DoubleField) + public fun ofDouble(): ObjectCounter = ObjectCounter(DoubleField) + public fun of(group: Group): ObjectCounter = ObjectCounter(group) } } diff --git a/kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/DoubleHistogramGroup.kt b/kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/DoubleHistogramGroup.kt deleted file mode 100644 index bb66b5dc5..000000000 --- a/kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/DoubleHistogramGroup.kt +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Copyright 2018-2021 KMath contributors. - * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. - */ - -package space.kscience.kmath.histogram - -import space.kscience.kmath.domains.HyperSquareDomain -import space.kscience.kmath.linear.Point -import space.kscience.kmath.misc.UnstableKMathAPI -import space.kscience.kmath.nd.* -import space.kscience.kmath.operations.DoubleField -import space.kscience.kmath.structures.* -import kotlin.math.floor - -/** - * Multivariate histogram space for hyper-square real-field bins. - */ -public class DoubleHistogramGroup( - private val lower: Buffer, - private val upper: Buffer, - private val binNums: IntArray = IntArray(lower.size) { 20 }, -) : IndexedHistogramGroup { - - init { - // argument checks - require(lower.size == upper.size) { "Dimension mismatch in histogram lower and upper limits." } - require(lower.size == binNums.size) { "Dimension mismatch in bin count." } - require(!lower.indices.any { upper[it] - lower[it] < 0 }) { "Range for one of axis is not strictly positive" } - } - - public val dimension: Int get() = lower.size - - override val shape: IntArray = IntArray(binNums.size) { binNums[it] + 2 } - override val histogramValueAlgebra: DoubleFieldND = DoubleField.ndAlgebra(*shape) - - private val binSize = DoubleBuffer(dimension) { (upper[it] - lower[it]) / binNums[it] } - - /** - * Get internal [StructureND] bin index for given axis - */ - private fun getIndex(axis: Int, value: Double): Int = when { - value >= upper[axis] -> binNums[axis] + 1 // overflow - value < lower[axis] -> 0 // underflow - else -> floor((value - lower[axis]) / binSize[axis]).toInt() - } - - override fun getIndexOrNull(point: Buffer): IntArray = IntArray(dimension) { - getIndex(it, point[it]) - } - - @OptIn(UnstableKMathAPI::class) - override fun getDomain(index: IntArray): HyperSquareDomain { - val lowerBoundary = index.mapIndexed { axis, i -> - when (i) { - 0 -> Double.NEGATIVE_INFINITY - shape[axis] - 1 -> upper[axis] - else -> lower[axis] + (i.toDouble()) * binSize[axis] - } - }.asBuffer() - - val upperBoundary = index.mapIndexed { axis, i -> - when (i) { - 0 -> lower[axis] - shape[axis] - 1 -> Double.POSITIVE_INFINITY - else -> lower[axis] + (i.toDouble() + 1) * binSize[axis] - } - }.asBuffer() - - return HyperSquareDomain(lowerBoundary, upperBoundary) - } - - @OptIn(UnstableKMathAPI::class) - override fun produceBin(index: IntArray, value: Double): DomainBin { - val domain = getDomain(index) - return DomainBin(domain, value) - } - - override fun produce(builder: HistogramBuilder.() -> Unit): IndexedHistogram { - val ndCounter = StructureND.auto(shape) { Counter.double() } - val hBuilder = object : HistogramBuilder { - override val defaultValue: Double get() = 1.0 - - override fun putValue(point: Point, value: Double) { - val index = getIndexOrNull(point) - ndCounter[index].add(value) - } - } - hBuilder.apply(builder) - val values: BufferND = ndCounter.mapToBuffer { it.value } - return IndexedHistogram(this, values) - } - - override fun IndexedHistogram.unaryMinus(): IndexedHistogram = this * (-1) - - public companion object { - /** - * Use it like - * ``` - *FastHistogram.fromRanges( - * (-1.0..1.0), - * (-1.0..1.0) - *) - *``` - */ - public fun fromRanges( - vararg ranges: ClosedFloatingPointRange, - ): DoubleHistogramGroup = DoubleHistogramGroup( - ranges.map(ClosedFloatingPointRange::start).asBuffer(), - ranges.map(ClosedFloatingPointRange::endInclusive).asBuffer() - ) - - /** - * Use it like - * ``` - *FastHistogram.fromRanges( - * (-1.0..1.0) to 50, - * (-1.0..1.0) to 32 - *) - *``` - */ - public fun fromRanges( - vararg ranges: Pair, Int>, - ): DoubleHistogramGroup = DoubleHistogramGroup( - ListBuffer( - ranges - .map(Pair, Int>::first) - .map(ClosedFloatingPointRange::start) - ), - - ListBuffer( - ranges - .map(Pair, Int>::first) - .map(ClosedFloatingPointRange::endInclusive) - ), - - ranges.map(Pair, Int>::second).toIntArray() - ) - } -} \ No newline at end of file diff --git a/kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/Histogram.kt b/kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/Histogram.kt index f9550df17..12edafd81 100644 --- a/kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/Histogram.kt +++ b/kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/Histogram.kt @@ -20,6 +20,15 @@ public interface Bin : Domain { public val binValue: V } +/** + * A simple histogram bin based on domain + */ +public data class DomainBin, D : Domain, out V>( + public val domain: D, + override val binValue: V, +) : Bin, Domain by domain + + public interface Histogram> { /** * Find existing bin, corresponding to given coordinates diff --git a/kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/HistogramND.kt b/kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/HistogramND.kt new file mode 100644 index 000000000..2af03abd4 --- /dev/null +++ b/kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/HistogramND.kt @@ -0,0 +1,76 @@ +/* + * Copyright 2018-2021 KMath contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package space.kscience.kmath.histogram + +import space.kscience.kmath.domains.Domain +import space.kscience.kmath.linear.Point +import space.kscience.kmath.nd.DefaultStrides +import space.kscience.kmath.nd.FieldOpsND +import space.kscience.kmath.nd.Shape +import space.kscience.kmath.nd.StructureND +import space.kscience.kmath.operations.Group +import space.kscience.kmath.operations.ScaleOperations +import space.kscience.kmath.operations.invoke + +/** + * @param T the type of the argument space + * @param V the type of bin value + */ +public class HistogramND, D : Domain, V : Any>( + public val group: HistogramGroupND, + internal val values: StructureND, +) : Histogram> { + + override fun get(point: Point): DomainBin? { + val index = group.getIndexOrNull(point) ?: return null + return group.produceBin(index, values[index]) + } + + override val dimension: Int get() = group.shape.size + + override val bins: Iterable> + get() = DefaultStrides(group.shape).asSequence().map { + group.produceBin(it, values[it]) + }.asIterable() +} + +/** + * A space for producing histograms with values in a NDStructure + */ +public interface HistogramGroupND, D : Domain, V : Any> : + Group>, ScaleOperations> { + public val shape: Shape + public val valueAlgebra: FieldOpsND //= NDAlgebra.space(valueSpace, Buffer.Companion::boxing, *shape), + + /** + * Resolve index of the bin including given [point]. Return null if point is outside histogram area + */ + public fun getIndexOrNull(point: Point): IntArray? + + /** + * Get a bin domain represented by given index + */ + public fun getDomain(index: IntArray): Domain? + + public fun produceBin(index: IntArray, value: V): DomainBin + + public fun produce(builder: HistogramBuilder.() -> Unit): HistogramND + + override fun add(left: HistogramND, right: HistogramND): HistogramND { + require(left.group == this && right.group == this) { + "A histogram belonging to a different group cannot be operated." + } + return HistogramND(this, valueAlgebra { left.values + right.values }) + } + + override fun scale(a: HistogramND, value: Double): HistogramND { + require(a.group == this) { "A histogram belonging to a different group cannot be operated." } + return HistogramND(this, valueAlgebra { a.values * value }) + } + + override val zero: HistogramND get() = produce { } +} + diff --git a/kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/IndexedHistogramGroup.kt b/kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/IndexedHistogramGroup.kt deleted file mode 100644 index 70913ecfb..000000000 --- a/kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/IndexedHistogramGroup.kt +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright 2018-2021 KMath contributors. - * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. - */ - -package space.kscience.kmath.histogram - -import space.kscience.kmath.domains.Domain -import space.kscience.kmath.linear.Point -import space.kscience.kmath.nd.DefaultStrides -import space.kscience.kmath.nd.FieldND -import space.kscience.kmath.nd.Shape -import space.kscience.kmath.nd.StructureND -import space.kscience.kmath.operations.Group -import space.kscience.kmath.operations.ScaleOperations -import space.kscience.kmath.operations.invoke - -/** - * A simple histogram bin based on domain - */ -public data class DomainBin, out V>( - public val domain: Domain, - override val binValue: V, -) : Bin, Domain by domain - -/** - * @param T the type of the argument space - * @param V the type of bin value - */ -public class IndexedHistogram, V : Any>( - public val histogramGroup: IndexedHistogramGroup, - public val values: StructureND, -) : Histogram> { - - override fun get(point: Point): DomainBin? { - val index = histogramGroup.getIndexOrNull(point) ?: return null - return histogramGroup.produceBin(index, values[index]) - } - - override val dimension: Int get() = histogramGroup.shape.size - - override val bins: Iterable> - get() = DefaultStrides(histogramGroup.shape).asSequence().map { - histogramGroup.produceBin(it, values[it]) - }.asIterable() -} - -/** - * A space for producing histograms with values in a NDStructure - */ -public interface IndexedHistogramGroup, V : Any> : Group>, - ScaleOperations> { - public val shape: Shape - public val histogramValueAlgebra: FieldND //= NDAlgebra.space(valueSpace, Buffer.Companion::boxing, *shape), - - /** - * Resolve index of the bin including given [point]. Return null if point is outside histogram area - */ - public fun getIndexOrNull(point: Point): IntArray? - - /** - * Get a bin domain represented by given index - */ - public fun getDomain(index: IntArray): Domain? - - public fun produceBin(index: IntArray, value: V): DomainBin - - public fun produce(builder: HistogramBuilder.() -> Unit): IndexedHistogram - - override fun add(left: IndexedHistogram, right: IndexedHistogram): IndexedHistogram { - require(left.histogramGroup == this && right.histogramGroup == this) { - "A histogram belonging to a different group cannot be operated." - } - return IndexedHistogram(this, histogramValueAlgebra { left.values + right.values }) - } - - override fun scale(a: IndexedHistogram, value: Double): IndexedHistogram { - require(a.histogramGroup == this) { "A histogram belonging to a different group cannot be operated." } - return IndexedHistogram(this, histogramValueAlgebra { a.values * value }) - } - - override val zero: IndexedHistogram get() = produce { } -} - diff --git a/kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/UniformHistogramGroupND.kt b/kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/UniformHistogramGroupND.kt new file mode 100644 index 000000000..b93da10b2 --- /dev/null +++ b/kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/UniformHistogramGroupND.kt @@ -0,0 +1,163 @@ +/* + * Copyright 2018-2021 KMath contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +@file:OptIn(UnstableKMathAPI::class) + +package space.kscience.kmath.histogram + +import space.kscience.kmath.domains.HyperSquareDomain +import space.kscience.kmath.linear.Point +import space.kscience.kmath.misc.UnstableKMathAPI +import space.kscience.kmath.nd.* +import space.kscience.kmath.operations.DoubleField +import space.kscience.kmath.operations.Field +import space.kscience.kmath.operations.invoke +import space.kscience.kmath.structures.* +import kotlin.math.floor + +public typealias HyperSquareBin = DomainBin + +/** + * Multivariate histogram space for hyper-square real-field bins. + * @param bufferFactory is an optional parameter used to optimize buffer production. + */ +public class UniformHistogramGroupND>( + override val valueAlgebra: FieldOpsND, + private val lower: Buffer, + private val upper: Buffer, + private val binNums: IntArray = IntArray(lower.size) { 20 }, + private val bufferFactory: BufferFactory = Buffer.Companion::boxing, +) : HistogramGroupND { + + init { + // argument checks + require(lower.size == upper.size) { "Dimension mismatch in histogram lower and upper limits." } + require(lower.size == binNums.size) { "Dimension mismatch in bin count." } + require(!lower.indices.any { upper[it] - lower[it] < 0 }) { "Range for one of axis is not strictly positive" } + } + + public val dimension: Int get() = lower.size + + override val shape: IntArray = IntArray(binNums.size) { binNums[it] + 2 } + + private val binSize = DoubleBuffer(dimension) { (upper[it] - lower[it]) / binNums[it] } + + /** + * Get internal [StructureND] bin index for given axis + */ + private fun getIndex(axis: Int, value: Double): Int = when { + value >= upper[axis] -> binNums[axis] + 1 // overflow + value < lower[axis] -> 0 // underflow + else -> floor((value - lower[axis]) / binSize[axis]).toInt() + } + + override fun getIndexOrNull(point: Buffer): IntArray = IntArray(dimension) { + getIndex(it, point[it]) + } + + override fun getDomain(index: IntArray): HyperSquareDomain { + val lowerBoundary = index.mapIndexed { axis, i -> + when (i) { + 0 -> Double.NEGATIVE_INFINITY + shape[axis] - 1 -> upper[axis] + else -> lower[axis] + (i.toDouble()) * binSize[axis] + } + }.asBuffer() + + val upperBoundary = index.mapIndexed { axis, i -> + when (i) { + 0 -> lower[axis] + shape[axis] - 1 -> Double.POSITIVE_INFINITY + else -> lower[axis] + (i.toDouble() + 1) * binSize[axis] + } + }.asBuffer() + + return HyperSquareDomain(lowerBoundary, upperBoundary) + } + + override fun produceBin(index: IntArray, value: V): HyperSquareBin { + val domain = getDomain(index) + return DomainBin(domain, value) + } + + + override fun produce(builder: HistogramBuilder.() -> Unit): HistogramND { + val ndCounter = StructureND.buffered(shape) { Counter.of(valueAlgebra.elementAlgebra) } + val hBuilder = object : HistogramBuilder { + override val defaultValue: V get() = valueAlgebra.elementAlgebra.one + + override fun putValue(point: Point, value: V) = with(valueAlgebra.elementAlgebra) { + val index = getIndexOrNull(point) + ndCounter[index].add(value) + } + } + hBuilder.apply(builder) + val values: BufferND = ndCounter.mapToBuffer(bufferFactory) { it.value } + return HistogramND(this, values) + } + + override fun HistogramND.unaryMinus(): HistogramND = + this * (-1) +} + +/** + * Use it like + * ``` + *FastHistogram.fromRanges( + * (-1.0..1.0), + * (-1.0..1.0) + *) + *``` + */ +public fun > Histogram.Companion.uniformNDFromRanges( + valueAlgebra: FieldOpsND, + vararg ranges: ClosedFloatingPointRange, + bufferFactory: BufferFactory = Buffer.Companion::boxing, +): UniformHistogramGroupND = UniformHistogramGroupND( + valueAlgebra, + ranges.map(ClosedFloatingPointRange::start).asBuffer(), + ranges.map(ClosedFloatingPointRange::endInclusive).asBuffer(), + bufferFactory = bufferFactory +) + +public fun Histogram.Companion.uniformDoubleNDFromRanges( + vararg ranges: ClosedFloatingPointRange, +): UniformHistogramGroupND = + uniformNDFromRanges(DoubleFieldOpsND, *ranges, bufferFactory = ::DoubleBuffer) + + +/** + * Use it like + * ``` + *FastHistogram.fromRanges( + * (-1.0..1.0) to 50, + * (-1.0..1.0) to 32 + *) + *``` + */ +public fun > Histogram.Companion.uniformNDFromRanges( + valueAlgebra: FieldOpsND, + vararg ranges: Pair, Int>, + bufferFactory: BufferFactory = Buffer.Companion::boxing, +): UniformHistogramGroupND = UniformHistogramGroupND( + valueAlgebra, + ListBuffer( + ranges + .map(Pair, Int>::first) + .map(ClosedFloatingPointRange::start) + ), + ListBuffer( + ranges + .map(Pair, Int>::first) + .map(ClosedFloatingPointRange::endInclusive) + ), + ranges.map(Pair, Int>::second).toIntArray(), + bufferFactory = bufferFactory +) + +public fun Histogram.Companion.uniformDoubleNDFromRanges( + vararg ranges: Pair, Int>, +): UniformHistogramGroupND = + uniformNDFromRanges(DoubleFieldOpsND, *ranges, bufferFactory = ::DoubleBuffer) \ No newline at end of file diff --git a/kmath-histograms/src/commonTest/kotlin/space/kscience/kmath/histogram/MultivariateHistogramTest.kt b/kmath-histograms/src/commonTest/kotlin/space/kscience/kmath/histogram/MultivariateHistogramTest.kt index 1426b35fa..ca7c2f324 100644 --- a/kmath-histograms/src/commonTest/kotlin/space/kscience/kmath/histogram/MultivariateHistogramTest.kt +++ b/kmath-histograms/src/commonTest/kotlin/space/kscience/kmath/histogram/MultivariateHistogramTest.kt @@ -3,8 +3,11 @@ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ +@file:OptIn(UnstableKMathAPI::class) + package space.kscience.kmath.histogram +import space.kscience.kmath.misc.UnstableKMathAPI import space.kscience.kmath.nd.DefaultStrides import space.kscience.kmath.operations.invoke import space.kscience.kmath.real.DoubleVector @@ -14,7 +17,7 @@ import kotlin.test.* internal class MultivariateHistogramTest { @Test fun testSinglePutHistogram() { - val hSpace = DoubleHistogramGroup.fromRanges( + val hSpace = Histogram.uniformDoubleNDFromRanges( (-1.0..1.0), (-1.0..1.0) ) @@ -29,7 +32,7 @@ internal class MultivariateHistogramTest { @Test fun testSequentialPut() { - val hSpace = DoubleHistogramGroup.fromRanges( + val hSpace = Histogram.uniformDoubleNDFromRanges( (-1.0..1.0), (-1.0..1.0), (-1.0..1.0) @@ -49,7 +52,7 @@ internal class MultivariateHistogramTest { @Test fun testHistogramAlgebra() { - DoubleHistogramGroup.fromRanges( + Histogram.uniformDoubleNDFromRanges( (-1.0..1.0), (-1.0..1.0), (-1.0..1.0) diff --git a/kmath-histograms/src/jvmMain/kotlin/space/kscience/kmath/histogram/TreeHistogramSpace.kt b/kmath-histograms/src/jvmMain/kotlin/space/kscience/kmath/histogram/TreeHistogramSpace.kt index e85bb0a3c..bff20c22c 100644 --- a/kmath-histograms/src/jvmMain/kotlin/space/kscience/kmath/histogram/TreeHistogramSpace.kt +++ b/kmath-histograms/src/jvmMain/kotlin/space/kscience/kmath/histogram/TreeHistogramSpace.kt @@ -45,7 +45,7 @@ internal class TreeHistogramBuilder(val binFactory: (Double) -> DoubleDomain1D) override val defaultValue: Double get() = 1.0 - internal class BinCounter(val domain: DoubleDomain1D, val counter: Counter = Counter.double()) : + internal class BinCounter(val domain: DoubleDomain1D, val counter: Counter = Counter.ofDouble()) : ClosedRange by domain.range private val bins: TreeMap = TreeMap()