From 9574099f9bb7062d5fe364189f7521f760ccad8c Mon Sep 17 00:00:00 2001 From: Iaroslav Postovalov Date: Wed, 31 Mar 2021 02:24:21 +0700 Subject: [PATCH] Fix post-merge issues --- examples/build.gradle.kts | 1 + .../kmath/commons/fit/fitWithAutoDiff.kt | 34 ++-- .../kmath/stat/DistributionBenchmark.kt | 4 +- .../kscience/kmath/stat/DistributionDemo.kt | 8 +- .../commons/optimization/OptimizeTest.kt | 29 ++-- .../space/kscience/kmath/structures/Buffer.kt | 157 +++++++++--------- .../kmath/chains/BlockingRealChain.kt | 9 - .../kmath/chains/BlockingDoubleChain.kt | 13 +- .../kscience/dimensions/DMatrixContextTest.kt | 2 +- .../kscience/kmath/stat/SamplerAlgebra.kt | 34 ---- .../space/kscience/kmath/stat/Distribution.kt | 19 ++- .../space/kscience/kmath/stat/RandomChain.kt | 10 +- .../kscience/kmath/stat/SamplerAlgebra.kt | 28 +++- .../stat/distributions/NormalDistribution.kt | 16 +- .../kmath/stat/internal/InternalErf.kt | 2 +- .../kmath/stat/internal/InternalGamma.kt | 2 +- .../kmath/stat/internal/InternalUtils.kt | 2 +- .../AhrensDieterExponentialSampler.kt | 12 +- .../AhrensDieterMarsagliaTsangGammaSampler.kt | 12 +- .../samplers/AliasMethodDiscreteSampler.kt | 12 +- .../BoxMullerNormalizedGaussianSampler.kt | 10 +- .../kmath/stat/samplers/GaussianSampler.kt | 10 +- .../samplers/KempSmallMeanPoissonSampler.kt | 10 +- .../stat/samplers/LargeMeanPoissonSampler.kt | 16 +- .../MarsagliaNormalizedGaussianSampler.kt | 10 +- .../samplers/NormalizedGaussianSampler.kt | 4 +- .../kmath/stat/samplers/PoissonSampler.kt | 8 +- .../stat/samplers/SmallMeanPoissonSampler.kt | 10 +- .../ZigguratNormalizedGaussianSampler.kt | 10 +- .../kmath/stat/CommonsDistributionsTest.kt | 2 +- 30 files changed, 234 insertions(+), 262 deletions(-) delete mode 100644 kmath-coroutines/src/commonMain/kotlin/kscience/kmath/chains/BlockingRealChain.kt delete mode 100644 kmath-stat/src/commonMain/kotlin/kscience/kmath/stat/SamplerAlgebra.kt rename kmath-stat/src/commonMain/kotlin/{ => space}/kscience/kmath/stat/distributions/NormalDistribution.kt (72%) rename kmath-stat/src/commonMain/kotlin/{ => space}/kscience/kmath/stat/internal/InternalErf.kt (90%) rename kmath-stat/src/commonMain/kotlin/{ => space}/kscience/kmath/stat/internal/InternalGamma.kt (99%) rename kmath-stat/src/commonMain/kotlin/{ => space}/kscience/kmath/stat/internal/InternalUtils.kt (98%) rename kmath-stat/src/commonMain/kotlin/{ => space}/kscience/kmath/stat/samplers/AhrensDieterExponentialSampler.kt (88%) rename kmath-stat/src/commonMain/kotlin/{ => space}/kscience/kmath/stat/samplers/AhrensDieterMarsagliaTsangGammaSampler.kt (94%) rename kmath-stat/src/commonMain/kotlin/{ => space}/kscience/kmath/stat/samplers/AliasMethodDiscreteSampler.kt (97%) rename kmath-stat/src/commonMain/kotlin/{ => space}/kscience/kmath/stat/samplers/BoxMullerNormalizedGaussianSampler.kt (88%) rename kmath-stat/src/commonMain/kotlin/{ => space}/kscience/kmath/stat/samplers/GaussianSampler.kt (86%) rename kmath-stat/src/commonMain/kotlin/{ => space}/kscience/kmath/stat/samplers/KempSmallMeanPoissonSampler.kt (92%) rename kmath-stat/src/commonMain/kotlin/{ => space}/kscience/kmath/stat/samplers/LargeMeanPoissonSampler.kt (92%) rename kmath-stat/src/commonMain/kotlin/{ => space}/kscience/kmath/stat/samplers/MarsagliaNormalizedGaussianSampler.kt (91%) rename kmath-stat/src/commonMain/kotlin/{ => space}/kscience/kmath/stat/samplers/NormalizedGaussianSampler.kt (72%) rename kmath-stat/src/commonMain/kotlin/{ => space}/kscience/kmath/stat/samplers/PoissonSampler.kt (88%) rename kmath-stat/src/commonMain/kotlin/{ => space}/kscience/kmath/stat/samplers/SmallMeanPoissonSampler.kt (88%) rename kmath-stat/src/commonMain/kotlin/{ => space}/kscience/kmath/stat/samplers/ZigguratNormalizedGaussianSampler.kt (93%) diff --git a/examples/build.gradle.kts b/examples/build.gradle.kts index 5dd40b609..a48b4d0d9 100644 --- a/examples/build.gradle.kts +++ b/examples/build.gradle.kts @@ -106,6 +106,7 @@ kotlin.sourceSets.all { with(languageSettings) { useExperimentalAnnotation("kotlin.contracts.ExperimentalContracts") useExperimentalAnnotation("kotlin.ExperimentalUnsignedTypes") + useExperimentalAnnotation("space.kscience.kmath.misc.UnstableKMathAPI") } } diff --git a/examples/src/main/kotlin/space/kscience/kmath/commons/fit/fitWithAutoDiff.kt b/examples/src/main/kotlin/space/kscience/kmath/commons/fit/fitWithAutoDiff.kt index 22d642d92..04c55b34c 100644 --- a/examples/src/main/kotlin/space/kscience/kmath/commons/fit/fitWithAutoDiff.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/commons/fit/fitWithAutoDiff.kt @@ -1,20 +1,22 @@ -package kscience.kmath.commons.fit +package space.kscience.kmath.commons.fit import kotlinx.html.br import kotlinx.html.h3 -import kscience.kmath.commons.optimization.chiSquared -import kscience.kmath.commons.optimization.minimize -import kscience.kmath.expressions.symbol -import kscience.kmath.real.RealVector -import kscience.kmath.real.map -import kscience.kmath.real.step -import kscience.kmath.stat.* -import kscience.kmath.stat.distributions.NormalDistribution -import kscience.kmath.structures.asIterable -import kscience.kmath.structures.toList import kscience.plotly.* import kscience.plotly.models.ScatterMode import kscience.plotly.models.TraceValues +import space.kscience.kmath.commons.optimization.chiSquared +import space.kscience.kmath.commons.optimization.minimize +import space.kscience.kmath.misc.symbol +import space.kscience.kmath.optimization.FunctionOptimization +import space.kscience.kmath.optimization.OptimizationResult +import space.kscience.kmath.real.DoubleVector +import space.kscience.kmath.real.map +import space.kscience.kmath.real.step +import space.kscience.kmath.stat.RandomGenerator +import space.kscience.kmath.stat.distributions.NormalDistribution +import space.kscience.kmath.structures.asIterable +import space.kscience.kmath.structures.toList import kotlin.math.pow import kotlin.math.sqrt @@ -27,7 +29,7 @@ private val c by symbol /** * Shortcut to use buffers in plotly */ -operator fun TraceValues.invoke(vector: RealVector) { +operator fun TraceValues.invoke(vector: DoubleVector) { numbers = vector.asIterable() } @@ -58,12 +60,12 @@ suspend fun main() { val yErr = y.map { sqrt(it) }//RealVector.same(x.size, sigma) // compute differentiable chi^2 sum for given model ax^2 + bx + c - val chi2 = Fitting.chiSquared(x, y, yErr) { x1 -> + val chi2 = FunctionOptimization.chiSquared(x, y, yErr) { x1 -> //bind variables to autodiff context val a = bind(a) val b = bind(b) //Include default value for c if it is not provided as a parameter - val c = bindOrNull(c) ?: one + val c = bindSymbolOrNull(c) ?: one a * x1.pow(2) + b * x1 + c } @@ -90,10 +92,10 @@ suspend fun main() { } } br() - h3{ + h3 { +"Fit result: $result" } - h3{ + h3 { +"Chi2/dof = ${result.value / (x.size - 3)}" } } diff --git a/examples/src/main/kotlin/space/kscience/kmath/stat/DistributionBenchmark.kt b/examples/src/main/kotlin/space/kscience/kmath/stat/DistributionBenchmark.kt index 4478903d9..bfd138502 100644 --- a/examples/src/main/kotlin/space/kscience/kmath/stat/DistributionBenchmark.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/stat/DistributionBenchmark.kt @@ -1,9 +1,9 @@ -package kscience.kmath.stat +package space.kscience.kmath.stat import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.async import kotlinx.coroutines.runBlocking -import kscience.kmath.stat.samplers.GaussianSampler +import space.kscience.kmath.stat.samplers.GaussianSampler import org.apache.commons.rng.simple.RandomSource import java.time.Duration import java.time.Instant diff --git a/examples/src/main/kotlin/space/kscience/kmath/stat/DistributionDemo.kt b/examples/src/main/kotlin/space/kscience/kmath/stat/DistributionDemo.kt index dd04c12e5..aac7d51d4 100644 --- a/examples/src/main/kotlin/space/kscience/kmath/stat/DistributionDemo.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/stat/DistributionDemo.kt @@ -1,9 +1,9 @@ -package kscience.kmath.stat +package space.kscience.kmath.stat import kotlinx.coroutines.runBlocking -import kscience.kmath.chains.Chain -import kscience.kmath.chains.collectWithState -import kscience.kmath.stat.distributions.NormalDistribution +import space.kscience.kmath.chains.Chain +import space.kscience.kmath.chains.collectWithState +import space.kscience.kmath.stat.distributions.NormalDistribution /** * The state of distribution averager. diff --git a/kmath-commons/src/test/kotlin/space/kscience/kmath/commons/optimization/OptimizeTest.kt b/kmath-commons/src/test/kotlin/space/kscience/kmath/commons/optimization/OptimizeTest.kt index 184d209d5..36f2639f4 100644 --- a/kmath-commons/src/test/kotlin/space/kscience/kmath/commons/optimization/OptimizeTest.kt +++ b/kmath-commons/src/test/kotlin/space/kscience/kmath/commons/optimization/OptimizeTest.kt @@ -1,13 +1,13 @@ -package kscience.kmath.commons.optimization +package space.kscience.kmath.commons.optimization import kotlinx.coroutines.runBlocking -import kscience.kmath.commons.expressions.DerivativeStructureExpression -import kscience.kmath.expressions.symbol -import kscience.kmath.stat.Fitting -import kscience.kmath.stat.RandomGenerator -import kscience.kmath.stat.distributions.NormalDistribution -import org.junit.jupiter.api.Test +import space.kscience.kmath.commons.expressions.DerivativeStructureExpression +import space.kscience.kmath.misc.symbol +import space.kscience.kmath.optimization.FunctionOptimization +import space.kscience.kmath.stat.RandomGenerator +import space.kscience.kmath.stat.distributions.NormalDistribution import kotlin.math.pow +import kotlin.test.Test internal class OptimizeTest { val x by symbol @@ -34,6 +34,7 @@ internal class OptimizeTest { simplexSteps(x to 2.0, y to 0.5) //this sets simplex optimizer } + println(result.point) println(result.value) } @@ -43,15 +44,20 @@ internal class OptimizeTest { val a by symbol val b by symbol val c by symbol + val sigma = 1.0 val generator = NormalDistribution(0.0, sigma) val chain = generator.sample(RandomGenerator.default(112667)) val x = (1..100).map(Int::toDouble) - val y = x.map { it.pow(2) + it + 1.0 + chain.next() } + + val y = x.map { + it.pow(2) + it + 1 + chain.next() + } + val yErr = List(x.size) { sigma } - val chi2 = Fitting.chiSquared(x, y, yErr) { x1 -> - val cWithDefault = bindOrNull(c) ?: one + val chi2 = FunctionOptimization.chiSquared(x, y, yErr) { x1 -> + val cWithDefault = bindSymbolOrNull(c) ?: one bind(a) * x1.pow(2) + bind(b) * x1 + cWithDefault } @@ -59,5 +65,4 @@ internal class OptimizeTest { println(result) println("Chi2/dof = ${result.value / (x.size - 3)}") } - -} \ No newline at end of file +} diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Buffer.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Buffer.kt index c5a51ca50..168a92c37 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Buffer.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Buffer.kt @@ -1,4 +1,4 @@ -package kscience.kmath.structures +package space.kscience.kmath.structures import kotlin.reflect.KClass @@ -17,11 +17,13 @@ public typealias BufferFactory = (Int, (Int) -> T) -> Buffer public typealias MutableBufferFactory = (Int, (Int) -> T) -> MutableBuffer /** - * A generic immutable random-access structure for both primitives and objects. + * A generic read-only random-access structure for both primitives and objects. + * + * [Buffer] is in general identity-free. [Buffer.contentEquals] should be used for content equality checks. * * @param T the type of elements contained in the buffer. */ -public interface Buffer { +public interface Buffer { /** * The size of this buffer. */ @@ -37,49 +39,45 @@ public interface Buffer { */ public operator fun iterator(): Iterator - /** - * Checks content equality with another buffer. - */ - public fun contentEquals(other: Buffer<*>): Boolean = - asSequence().mapIndexed { index, value -> value == other[index] }.all { it } - public companion object { /** - * Creates a [RealBuffer] with the specified [size], where each element is calculated by calling the specified - * [initializer] function. + * Check the element-by-element match of content of two buffers. */ - public inline fun real(size: Int, initializer: (Int) -> Double): RealBuffer = - RealBuffer(size) { initializer(it) } + public fun contentEquals(first: Buffer, second: Buffer): Boolean{ + if (first.size != second.size) return false + for (i in first.indices) { + if (first[i] != second[i]) return false + } + return true + } /** * Creates a [ListBuffer] of given type [T] with given [size]. Each element is calculated by calling the * specified [initializer] function. */ public inline fun boxing(size: Int, initializer: (Int) -> T): Buffer = - ListBuffer(List(size, initializer)) - - // TODO add resolution based on Annotation or companion resolution + List(size, initializer).asBuffer() /** * Creates a [Buffer] of given [type]. If the type is primitive, specialized buffers are used ([IntBuffer], - * [RealBuffer], etc.), [ListBuffer] is returned otherwise. + * [DoubleBuffer], etc.), [ListBuffer] is returned otherwise. * * The [size] is specified, and each element is calculated by calling the specified [initializer] function. */ @Suppress("UNCHECKED_CAST") public inline fun auto(type: KClass, size: Int, initializer: (Int) -> T): Buffer = when (type) { - Double::class -> real(size) { initializer(it) as Double } as Buffer - Short::class -> ShortBuffer(size) { initializer(it) as Short } as Buffer - Int::class -> IntBuffer(size) { initializer(it) as Int } as Buffer - Long::class -> LongBuffer(size) { initializer(it) as Long } as Buffer - Float::class -> FloatBuffer(size) { initializer(it) as Float } as Buffer + Double::class -> MutableBuffer.double(size) { initializer(it) as Double } as Buffer + Short::class -> MutableBuffer.short(size) { initializer(it) as Short } as Buffer + Int::class -> MutableBuffer.int(size) { initializer(it) as Int } as Buffer + Long::class -> MutableBuffer.long(size) { initializer(it) as Long } as Buffer + Float::class -> MutableBuffer.float(size) { initializer(it) as Float } as Buffer else -> boxing(size, initializer) } /** * Creates a [Buffer] of given type [T]. If the type is primitive, specialized buffers are used ([IntBuffer], - * [RealBuffer], etc.), [ListBuffer] is returned otherwise. + * [DoubleBuffer], etc.), [ListBuffer] is returned otherwise. * * The [size] is specified, and each element is calculated by calling the specified [initializer] function. */ @@ -89,21 +87,6 @@ public interface Buffer { } } -/** - * Creates a sequence that returns all elements from this [Buffer]. - */ -public fun Buffer.asSequence(): Sequence = Sequence(::iterator) - -/** - * Creates an iterable that returns all elements from this [Buffer]. - */ -public fun Buffer.asIterable(): Iterable = Iterable(::iterator) - -/** - * Converts this [Buffer] to a new [List] - */ -public fun Buffer.toList(): List = asSequence().toList() - /** * Returns an [IntRange] of the valid indices for this [Buffer]. */ @@ -126,6 +109,43 @@ public interface MutableBuffer : Buffer { public fun copy(): MutableBuffer public companion object { + /** + * Creates a [DoubleBuffer] with the specified [size], where each element is calculated by calling the specified + * [initializer] function. + */ + public inline fun double(size: Int, initializer: (Int) -> Double): DoubleBuffer = + DoubleBuffer(size, initializer) + + /** + * Creates a [ShortBuffer] with the specified [size], where each element is calculated by calling the specified + * [initializer] function. + */ + public inline fun short(size: Int, initializer: (Int) -> Short): ShortBuffer = + ShortBuffer(size, initializer) + + /** + * Creates a [IntBuffer] with the specified [size], where each element is calculated by calling the specified + * [initializer] function. + */ + public inline fun int(size: Int, initializer: (Int) -> Int): IntBuffer = + IntBuffer(size, initializer) + + /** + * Creates a [LongBuffer] with the specified [size], where each element is calculated by calling the specified + * [initializer] function. + */ + public inline fun long(size: Int, initializer: (Int) -> Long): LongBuffer = + LongBuffer(size, initializer) + + + /** + * Creates a [FloatBuffer] with the specified [size], where each element is calculated by calling the specified + * [initializer] function. + */ + public inline fun float(size: Int, initializer: (Int) -> Float): FloatBuffer = + FloatBuffer(size, initializer) + + /** * Create a boxing mutable buffer of given type */ @@ -134,37 +154,30 @@ public interface MutableBuffer : Buffer { /** * Creates a [MutableBuffer] of given [type]. If the type is primitive, specialized buffers are used - * ([IntBuffer], [RealBuffer], etc.), [ListBuffer] is returned otherwise. + * ([IntBuffer], [DoubleBuffer], etc.), [ListBuffer] is returned otherwise. * * The [size] is specified, and each element is calculated by calling the specified [initializer] function. */ @Suppress("UNCHECKED_CAST") public inline fun auto(type: KClass, size: Int, initializer: (Int) -> T): MutableBuffer = when (type) { - Double::class -> RealBuffer(size) { initializer(it) as Double } as MutableBuffer - Short::class -> ShortBuffer(size) { initializer(it) as Short } as MutableBuffer - Int::class -> IntBuffer(size) { initializer(it) as Int } as MutableBuffer - Float::class -> FloatBuffer(size) { initializer(it) as Float } as MutableBuffer - Long::class -> LongBuffer(size) { initializer(it) as Long } as MutableBuffer + Double::class -> double(size) { initializer(it) as Double } as MutableBuffer + Short::class -> short(size) { initializer(it) as Short } as MutableBuffer + Int::class -> int(size) { initializer(it) as Int } as MutableBuffer + Float::class -> float(size) { initializer(it) as Float } as MutableBuffer + Long::class -> long(size) { initializer(it) as Long } as MutableBuffer else -> boxing(size, initializer) } /** * Creates a [MutableBuffer] of given type [T]. If the type is primitive, specialized buffers are used - * ([IntBuffer], [RealBuffer], etc.), [ListBuffer] is returned otherwise. + * ([IntBuffer], [DoubleBuffer], etc.), [ListBuffer] is returned otherwise. * * The [size] is specified, and each element is calculated by calling the specified [initializer] function. */ @Suppress("UNCHECKED_CAST") public inline fun auto(size: Int, initializer: (Int) -> T): MutableBuffer = auto(T::class, size, initializer) - - /** - * Creates a [RealBuffer] with the specified [size], where each element is calculated by calling the specified - * [initializer] function. - */ - public inline fun real(size: Int, initializer: (Int) -> Double): RealBuffer = - RealBuffer(size) { initializer(it) } } } @@ -187,15 +200,6 @@ public inline class ListBuffer(public val list: List) : Buffer { */ public fun List.asBuffer(): ListBuffer = ListBuffer(this) -/** - * Creates a new [ListBuffer] with the specified [size], where each element is calculated by calling the specified - * [init] function. - * - * The function [init] is called for each array element sequentially starting from the first one. - * It should return the value for an array element given its index. - */ -public inline fun ListBuffer(size: Int, init: (Int) -> T): ListBuffer = List(size, init).asBuffer() - /** * [MutableBuffer] implementation over [MutableList]. * @@ -216,16 +220,20 @@ public inline class MutableListBuffer(public val list: MutableList) : Muta override fun copy(): MutableBuffer = MutableListBuffer(ArrayList(list)) } +/** + * Returns an [ListBuffer] that wraps the original list. + */ +public fun MutableList.asMutableBuffer(): MutableListBuffer = MutableListBuffer(this) + /** * [MutableBuffer] implementation over [Array]. * * @param T the type of elements contained in the buffer. * @property array The underlying array. */ -public class ArrayBuffer(private val array: Array) : MutableBuffer { +public class ArrayBuffer(internal val array: Array) : MutableBuffer { // Can't inline because array is invariant - override val size: Int - get() = array.size + override val size: Int get() = array.size override operator fun get(index: Int): T = array[index] @@ -237,6 +245,7 @@ public class ArrayBuffer(private val array: Array) : MutableBuffer { override fun copy(): MutableBuffer = ArrayBuffer(array.copyOf()) } + /** * Returns an [ArrayBuffer] that wraps the original array. */ @@ -269,27 +278,9 @@ public class VirtualBuffer(override val size: Int, private val generator: (In } override operator fun iterator(): Iterator = (0 until size).asSequence().map(generator).iterator() - - override fun contentEquals(other: Buffer<*>): Boolean { - return if (other is VirtualBuffer) { - this.size == other.size && this.generator == other.generator - } else { - super.contentEquals(other) - } - } } /** * Convert this buffer to read-only buffer. */ -public fun Buffer.asReadOnly(): Buffer = if (this is MutableBuffer) ReadOnlyBuffer(this) else this - -/** - * Typealias for buffer transformations. - */ -public typealias BufferTransform = (Buffer) -> Buffer - -/** - * Typealias for buffer transformations with suspend function. - */ -public typealias SuspendBufferTransform = suspend (Buffer) -> Buffer +public fun Buffer.asReadOnly(): Buffer = if (this is MutableBuffer) ReadOnlyBuffer(this) else this \ No newline at end of file diff --git a/kmath-coroutines/src/commonMain/kotlin/kscience/kmath/chains/BlockingRealChain.kt b/kmath-coroutines/src/commonMain/kotlin/kscience/kmath/chains/BlockingRealChain.kt deleted file mode 100644 index 7c463b109..000000000 --- a/kmath-coroutines/src/commonMain/kotlin/kscience/kmath/chains/BlockingRealChain.kt +++ /dev/null @@ -1,9 +0,0 @@ -package kscience.kmath.chains - -/** - * Performance optimized chain for real values - */ -public interface BlockingRealChain : Chain { - public override suspend fun next(): Double - public suspend fun nextBlock(size: Int): DoubleArray = DoubleArray(size) { next() } -} diff --git a/kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/chains/BlockingDoubleChain.kt b/kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/chains/BlockingDoubleChain.kt index ba6adf35b..d024147b4 100644 --- a/kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/chains/BlockingDoubleChain.kt +++ b/kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/chains/BlockingDoubleChain.kt @@ -1,12 +1,13 @@ package space.kscience.kmath.chains /** - * Performance optimized chain for real values + * Chunked, specialized chain for real values. */ -public abstract class BlockingDoubleChain : Chain { - public abstract fun nextDouble(): Double +public interface BlockingDoubleChain : Chain { + public override suspend fun next(): Double - override suspend fun next(): Double = nextDouble() - - public open fun nextBlock(size: Int): DoubleArray = DoubleArray(size) { nextDouble() } + /** + * Returns an [DoubleArray] chunk of [size] values of [next]. + */ + public suspend fun nextBlock(size: Int): DoubleArray = DoubleArray(size) { next() } } diff --git a/kmath-dimensions/src/commonTest/kotlin/kscience/dimensions/DMatrixContextTest.kt b/kmath-dimensions/src/commonTest/kotlin/kscience/dimensions/DMatrixContextTest.kt index e2a9628ac..58ed82723 100644 --- a/kmath-dimensions/src/commonTest/kotlin/kscience/dimensions/DMatrixContextTest.kt +++ b/kmath-dimensions/src/commonTest/kotlin/kscience/dimensions/DMatrixContextTest.kt @@ -1,4 +1,4 @@ -package kscience.dimensions +package space.kscience.dimensions import space.kscience.kmath.dimensions.D2 import space.kscience.kmath.dimensions.D3 diff --git a/kmath-stat/src/commonMain/kotlin/kscience/kmath/stat/SamplerAlgebra.kt b/kmath-stat/src/commonMain/kotlin/kscience/kmath/stat/SamplerAlgebra.kt deleted file mode 100644 index 8413424de..000000000 --- a/kmath-stat/src/commonMain/kotlin/kscience/kmath/stat/SamplerAlgebra.kt +++ /dev/null @@ -1,34 +0,0 @@ -package kscience.kmath.stat - -import kscience.kmath.chains.Chain -import kscience.kmath.chains.ConstantChain -import kscience.kmath.chains.map -import kscience.kmath.chains.zip -import kscience.kmath.operations.Space -import kscience.kmath.operations.invoke - -/** - * Implements [Sampler] by sampling only certain [value]. - * - * @property value the value to sample. - */ -public class ConstantSampler(public val value: T) : Sampler { - public override fun sample(generator: RandomGenerator): Chain = ConstantChain(value) -} - -/** - * A space of samplers. Allows to perform simple operations on distributions. - * - * @property space the space to provide addition and scalar multiplication for [T]. - */ -public class SamplerSpace(public val space: Space) : Space> { - public override val zero: Sampler = ConstantSampler(space.zero) - - public override fun add(a: Sampler, b: Sampler): Sampler = Sampler { generator -> - a.sample(generator).zip(b.sample(generator)) { aValue, bValue -> space { aValue + bValue } } - } - - public override fun multiply(a: Sampler, k: Number): Sampler = Sampler { generator -> - a.sample(generator).map { space { it * k.toDouble() } } - } -} diff --git a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/Distribution.kt b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/Distribution.kt index f85ba5d68..095182160 100644 --- a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/Distribution.kt +++ b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/Distribution.kt @@ -1,11 +1,12 @@ -package kscience.kmath.stat +package space.kscience.kmath.stat import kotlinx.coroutines.flow.first -import kscience.kmath.chains.Chain -import kscience.kmath.chains.collect -import kscience.kmath.structures.Buffer -import kscience.kmath.structures.BufferFactory -import kscience.kmath.structures.IntBuffer +import space.kscience.kmath.chains.Chain +import space.kscience.kmath.chains.collect +import space.kscience.kmath.structures.Buffer +import space.kscience.kmath.structures.BufferFactory +import space.kscience.kmath.structures.IntBuffer +import space.kscience.kmath.structures.MutableBuffer import kotlin.jvm.JvmName /** @@ -22,7 +23,7 @@ public fun interface Sampler { } /** - * A distribution of typed objects + * A distribution of typed objects. */ public interface Distribution : Sampler { /** @@ -60,7 +61,7 @@ public fun > UnivariateDistribution.integral(from: T, to: T public fun Sampler.sampleBuffer( generator: RandomGenerator, size: Int, - bufferFactory: BufferFactory = Buffer.Companion::boxing + bufferFactory: BufferFactory = Buffer.Companion::boxing, ): Chain> { require(size > 1) //creating temporary storage once @@ -86,7 +87,7 @@ public suspend fun Sampler.next(generator: RandomGenerator): T = sa */ @JvmName("sampleRealBuffer") public fun Sampler.sampleBuffer(generator: RandomGenerator, size: Int): Chain> = - sampleBuffer(generator, size, Buffer.Companion::real) + sampleBuffer(generator, size, MutableBuffer.Companion::double) /** * Generates [size] integer samples and chunks them into some buffers. diff --git a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/RandomChain.kt b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/RandomChain.kt index daad7392a..2f117a035 100644 --- a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/RandomChain.kt +++ b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/RandomChain.kt @@ -1,8 +1,8 @@ -package kscience.kmath.stat +package space.kscience.kmath.stat -import kscience.kmath.chains.BlockingIntChain -import kscience.kmath.chains.BlockingRealChain -import kscience.kmath.chains.Chain +import space.kscience.kmath.chains.BlockingDoubleChain +import space.kscience.kmath.chains.BlockingIntChain +import space.kscience.kmath.chains.Chain /** * A possibly stateful chain producing random values. @@ -18,5 +18,5 @@ public class RandomChain( } public fun RandomGenerator.chain(gen: suspend RandomGenerator.() -> R): RandomChain = RandomChain(this, gen) -public fun Chain.blocking(): BlockingRealChain = object : Chain by this, BlockingRealChain {} +public fun Chain.blocking(): BlockingDoubleChain = object : Chain by this, BlockingDoubleChain {} public fun Chain.blocking(): BlockingIntChain = object : Chain by this, BlockingIntChain {} diff --git a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/SamplerAlgebra.kt b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/SamplerAlgebra.kt index c5ec99dae..25ec7eca6 100644 --- a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/SamplerAlgebra.kt +++ b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/SamplerAlgebra.kt @@ -8,16 +8,28 @@ import space.kscience.kmath.operations.Group import space.kscience.kmath.operations.ScaleOperations import space.kscience.kmath.operations.invoke -public class BasicSampler(public val chainBuilder: (RandomGenerator) -> Chain) : Sampler { - public override fun sample(generator: RandomGenerator): Chain = chainBuilder(generator) -} - +/** + * Implements [Sampler] by sampling only certain [value]. + * + * @property value the value to sample. + */ public class ConstantSampler(public val value: T) : Sampler { public override fun sample(generator: RandomGenerator): Chain = ConstantChain(value) } /** - * A space for samplers. Allows to perform simple operations on distributions + * Implements [Sampler] by delegating sampling to value of [chainBuilder]. + * + * @property chainBuilder the provider of [Chain]. + */ +public class BasicSampler(public val chainBuilder: (RandomGenerator) -> Chain) : Sampler { + public override fun sample(generator: RandomGenerator): Chain = chainBuilder(generator) +} + +/** + * A space of samplers. Allows to perform simple operations on distributions. + * + * @property algebra the space to provide addition and scalar multiplication for [T]. */ public class SamplerSpace(public val algebra: S) : Group>, ScaleOperations> where S : Group, S : ScaleOperations { @@ -29,8 +41,10 @@ public class SamplerSpace(public val algebra: S) : Group> } public override fun scale(a: Sampler, value: Double): Sampler = BasicSampler { generator -> - a.sample(generator).map { algebra { it * value } } + a.sample(generator).map { a -> + algebra { a * value } + } } - override fun Sampler.unaryMinus(): Sampler = scale(this, -1.0) + public override fun Sampler.unaryMinus(): Sampler = scale(this, -1.0) } diff --git a/kmath-stat/src/commonMain/kotlin/kscience/kmath/stat/distributions/NormalDistribution.kt b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/distributions/NormalDistribution.kt similarity index 72% rename from kmath-stat/src/commonMain/kotlin/kscience/kmath/stat/distributions/NormalDistribution.kt rename to kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/distributions/NormalDistribution.kt index 9059a0038..6515cbaa7 100644 --- a/kmath-stat/src/commonMain/kotlin/kscience/kmath/stat/distributions/NormalDistribution.kt +++ b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/distributions/NormalDistribution.kt @@ -1,12 +1,12 @@ -package kscience.kmath.stat.distributions +package space.kscience.kmath.stat.distributions -import kscience.kmath.chains.Chain -import kscience.kmath.stat.RandomGenerator -import kscience.kmath.stat.UnivariateDistribution -import kscience.kmath.stat.internal.InternalErf -import kscience.kmath.stat.samplers.GaussianSampler -import kscience.kmath.stat.samplers.NormalizedGaussianSampler -import kscience.kmath.stat.samplers.ZigguratNormalizedGaussianSampler +import space.kscience.kmath.chains.Chain +import space.kscience.kmath.stat.RandomGenerator +import space.kscience.kmath.stat.UnivariateDistribution +import space.kscience.kmath.stat.internal.InternalErf +import space.kscience.kmath.stat.samplers.GaussianSampler +import space.kscience.kmath.stat.samplers.NormalizedGaussianSampler +import space.kscience.kmath.stat.samplers.ZigguratNormalizedGaussianSampler import kotlin.math.* /** diff --git a/kmath-stat/src/commonMain/kotlin/kscience/kmath/stat/internal/InternalErf.kt b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/internal/InternalErf.kt similarity index 90% rename from kmath-stat/src/commonMain/kotlin/kscience/kmath/stat/internal/InternalErf.kt rename to kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/internal/InternalErf.kt index 04eb3ef0e..4e1623867 100644 --- a/kmath-stat/src/commonMain/kotlin/kscience/kmath/stat/internal/InternalErf.kt +++ b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/internal/InternalErf.kt @@ -1,4 +1,4 @@ -package kscience.kmath.stat.internal +package space.kscience.kmath.stat.internal import kotlin.math.abs diff --git a/kmath-stat/src/commonMain/kotlin/kscience/kmath/stat/internal/InternalGamma.kt b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/internal/InternalGamma.kt similarity index 99% rename from kmath-stat/src/commonMain/kotlin/kscience/kmath/stat/internal/InternalGamma.kt rename to kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/internal/InternalGamma.kt index dce84712a..4f5adbe97 100644 --- a/kmath-stat/src/commonMain/kotlin/kscience/kmath/stat/internal/InternalGamma.kt +++ b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/internal/InternalGamma.kt @@ -1,4 +1,4 @@ -package kscience.kmath.stat.internal +package space.kscience.kmath.stat.internal import kotlin.math.* diff --git a/kmath-stat/src/commonMain/kotlin/kscience/kmath/stat/internal/InternalUtils.kt b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/internal/InternalUtils.kt similarity index 98% rename from kmath-stat/src/commonMain/kotlin/kscience/kmath/stat/internal/InternalUtils.kt rename to kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/internal/InternalUtils.kt index 9997eeb57..722eee946 100644 --- a/kmath-stat/src/commonMain/kotlin/kscience/kmath/stat/internal/InternalUtils.kt +++ b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/internal/InternalUtils.kt @@ -1,4 +1,4 @@ -package kscience.kmath.stat.internal +package space.kscience.kmath.stat.internal import kotlin.math.ln import kotlin.math.min diff --git a/kmath-stat/src/commonMain/kotlin/kscience/kmath/stat/samplers/AhrensDieterExponentialSampler.kt b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/samplers/AhrensDieterExponentialSampler.kt similarity index 88% rename from kmath-stat/src/commonMain/kotlin/kscience/kmath/stat/samplers/AhrensDieterExponentialSampler.kt rename to kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/samplers/AhrensDieterExponentialSampler.kt index 853e952bb..504c6b881 100644 --- a/kmath-stat/src/commonMain/kotlin/kscience/kmath/stat/samplers/AhrensDieterExponentialSampler.kt +++ b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/samplers/AhrensDieterExponentialSampler.kt @@ -1,10 +1,10 @@ -package kscience.kmath.stat.samplers +package space.kscience.kmath.stat.samplers -import kscience.kmath.chains.Chain -import kscience.kmath.stat.RandomGenerator -import kscience.kmath.stat.Sampler -import kscience.kmath.stat.chain -import kscience.kmath.stat.internal.InternalUtils +import space.kscience.kmath.chains.Chain +import space.kscience.kmath.stat.RandomGenerator +import space.kscience.kmath.stat.Sampler +import space.kscience.kmath.stat.chain +import space.kscience.kmath.stat.internal.InternalUtils import kotlin.math.ln import kotlin.math.pow diff --git a/kmath-stat/src/commonMain/kotlin/kscience/kmath/stat/samplers/AhrensDieterMarsagliaTsangGammaSampler.kt b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/samplers/AhrensDieterMarsagliaTsangGammaSampler.kt similarity index 94% rename from kmath-stat/src/commonMain/kotlin/kscience/kmath/stat/samplers/AhrensDieterMarsagliaTsangGammaSampler.kt rename to kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/samplers/AhrensDieterMarsagliaTsangGammaSampler.kt index 98cb83332..81182f6cd 100644 --- a/kmath-stat/src/commonMain/kotlin/kscience/kmath/stat/samplers/AhrensDieterMarsagliaTsangGammaSampler.kt +++ b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/samplers/AhrensDieterMarsagliaTsangGammaSampler.kt @@ -1,10 +1,10 @@ -package kscience.kmath.stat.samplers +package space.kscience.kmath.stat.samplers -import kscience.kmath.chains.Chain -import kscience.kmath.stat.RandomGenerator -import kscience.kmath.stat.Sampler -import kscience.kmath.stat.chain -import kscience.kmath.stat.next +import space.kscience.kmath.chains.Chain +import space.kscience.kmath.stat.RandomGenerator +import space.kscience.kmath.stat.Sampler +import space.kscience.kmath.stat.chain +import space.kscience.kmath.stat.next import kotlin.math.* /** diff --git a/kmath-stat/src/commonMain/kotlin/kscience/kmath/stat/samplers/AliasMethodDiscreteSampler.kt b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/samplers/AliasMethodDiscreteSampler.kt similarity index 97% rename from kmath-stat/src/commonMain/kotlin/kscience/kmath/stat/samplers/AliasMethodDiscreteSampler.kt rename to kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/samplers/AliasMethodDiscreteSampler.kt index a4dc537b5..cae97db65 100644 --- a/kmath-stat/src/commonMain/kotlin/kscience/kmath/stat/samplers/AliasMethodDiscreteSampler.kt +++ b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/samplers/AliasMethodDiscreteSampler.kt @@ -1,10 +1,10 @@ -package kscience.kmath.stat.samplers +package space.kscience.kmath.stat.samplers -import kscience.kmath.chains.Chain -import kscience.kmath.stat.RandomGenerator -import kscience.kmath.stat.Sampler -import kscience.kmath.stat.chain -import kscience.kmath.stat.internal.InternalUtils +import space.kscience.kmath.chains.Chain +import space.kscience.kmath.stat.RandomGenerator +import space.kscience.kmath.stat.Sampler +import space.kscience.kmath.stat.chain +import space.kscience.kmath.stat.internal.InternalUtils import kotlin.math.ceil import kotlin.math.max import kotlin.math.min diff --git a/kmath-stat/src/commonMain/kotlin/kscience/kmath/stat/samplers/BoxMullerNormalizedGaussianSampler.kt b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/samplers/BoxMullerNormalizedGaussianSampler.kt similarity index 88% rename from kmath-stat/src/commonMain/kotlin/kscience/kmath/stat/samplers/BoxMullerNormalizedGaussianSampler.kt rename to kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/samplers/BoxMullerNormalizedGaussianSampler.kt index 20412f64b..04beb448d 100644 --- a/kmath-stat/src/commonMain/kotlin/kscience/kmath/stat/samplers/BoxMullerNormalizedGaussianSampler.kt +++ b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/samplers/BoxMullerNormalizedGaussianSampler.kt @@ -1,9 +1,9 @@ -package kscience.kmath.stat.samplers +package space.kscience.kmath.stat.samplers -import kscience.kmath.chains.Chain -import kscience.kmath.stat.RandomGenerator -import kscience.kmath.stat.Sampler -import kscience.kmath.stat.chain +import space.kscience.kmath.chains.Chain +import space.kscience.kmath.stat.RandomGenerator +import space.kscience.kmath.stat.Sampler +import space.kscience.kmath.stat.chain import kotlin.math.* /** diff --git a/kmath-stat/src/commonMain/kotlin/kscience/kmath/stat/samplers/GaussianSampler.kt b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/samplers/GaussianSampler.kt similarity index 86% rename from kmath-stat/src/commonMain/kotlin/kscience/kmath/stat/samplers/GaussianSampler.kt rename to kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/samplers/GaussianSampler.kt index 92dd27d02..eba26cfb5 100644 --- a/kmath-stat/src/commonMain/kotlin/kscience/kmath/stat/samplers/GaussianSampler.kt +++ b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/samplers/GaussianSampler.kt @@ -1,9 +1,9 @@ -package kscience.kmath.stat.samplers +package space.kscience.kmath.stat.samplers -import kscience.kmath.chains.Chain -import kscience.kmath.chains.map -import kscience.kmath.stat.RandomGenerator -import kscience.kmath.stat.Sampler +import space.kscience.kmath.chains.Chain +import space.kscience.kmath.chains.map +import space.kscience.kmath.stat.RandomGenerator +import space.kscience.kmath.stat.Sampler /** * Sampling from a Gaussian distribution with given mean and standard deviation. diff --git a/kmath-stat/src/commonMain/kotlin/kscience/kmath/stat/samplers/KempSmallMeanPoissonSampler.kt b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/samplers/KempSmallMeanPoissonSampler.kt similarity index 92% rename from kmath-stat/src/commonMain/kotlin/kscience/kmath/stat/samplers/KempSmallMeanPoissonSampler.kt rename to kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/samplers/KempSmallMeanPoissonSampler.kt index 78da230ca..1d7f90023 100644 --- a/kmath-stat/src/commonMain/kotlin/kscience/kmath/stat/samplers/KempSmallMeanPoissonSampler.kt +++ b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/samplers/KempSmallMeanPoissonSampler.kt @@ -1,9 +1,9 @@ -package kscience.kmath.stat.samplers +package space.kscience.kmath.stat.samplers -import kscience.kmath.chains.Chain -import kscience.kmath.stat.RandomGenerator -import kscience.kmath.stat.Sampler -import kscience.kmath.stat.chain +import space.kscience.kmath.chains.Chain +import space.kscience.kmath.stat.RandomGenerator +import space.kscience.kmath.stat.Sampler +import space.kscience.kmath.stat.chain import kotlin.math.exp /** diff --git a/kmath-stat/src/commonMain/kotlin/kscience/kmath/stat/samplers/LargeMeanPoissonSampler.kt b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/samplers/LargeMeanPoissonSampler.kt similarity index 92% rename from kmath-stat/src/commonMain/kotlin/kscience/kmath/stat/samplers/LargeMeanPoissonSampler.kt rename to kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/samplers/LargeMeanPoissonSampler.kt index c880d7a20..de1e7cc89 100644 --- a/kmath-stat/src/commonMain/kotlin/kscience/kmath/stat/samplers/LargeMeanPoissonSampler.kt +++ b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/samplers/LargeMeanPoissonSampler.kt @@ -1,12 +1,12 @@ -package kscience.kmath.stat.samplers +package space.kscience.kmath.stat.samplers -import kscience.kmath.chains.Chain -import kscience.kmath.chains.ConstantChain -import kscience.kmath.stat.RandomGenerator -import kscience.kmath.stat.Sampler -import kscience.kmath.stat.chain -import kscience.kmath.stat.internal.InternalUtils -import kscience.kmath.stat.next +import space.kscience.kmath.chains.Chain +import space.kscience.kmath.chains.ConstantChain +import space.kscience.kmath.stat.RandomGenerator +import space.kscience.kmath.stat.Sampler +import space.kscience.kmath.stat.chain +import space.kscience.kmath.stat.internal.InternalUtils +import space.kscience.kmath.stat.next import kotlin.math.* /** diff --git a/kmath-stat/src/commonMain/kotlin/kscience/kmath/stat/samplers/MarsagliaNormalizedGaussianSampler.kt b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/samplers/MarsagliaNormalizedGaussianSampler.kt similarity index 91% rename from kmath-stat/src/commonMain/kotlin/kscience/kmath/stat/samplers/MarsagliaNormalizedGaussianSampler.kt rename to kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/samplers/MarsagliaNormalizedGaussianSampler.kt index 8077f9f75..8a659642f 100644 --- a/kmath-stat/src/commonMain/kotlin/kscience/kmath/stat/samplers/MarsagliaNormalizedGaussianSampler.kt +++ b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/samplers/MarsagliaNormalizedGaussianSampler.kt @@ -1,9 +1,9 @@ -package kscience.kmath.stat.samplers +package space.kscience.kmath.stat.samplers -import kscience.kmath.chains.Chain -import kscience.kmath.stat.RandomGenerator -import kscience.kmath.stat.Sampler -import kscience.kmath.stat.chain +import space.kscience.kmath.chains.Chain +import space.kscience.kmath.stat.RandomGenerator +import space.kscience.kmath.stat.Sampler +import space.kscience.kmath.stat.chain import kotlin.math.ln import kotlin.math.sqrt diff --git a/kmath-stat/src/commonMain/kotlin/kscience/kmath/stat/samplers/NormalizedGaussianSampler.kt b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/samplers/NormalizedGaussianSampler.kt similarity index 72% rename from kmath-stat/src/commonMain/kotlin/kscience/kmath/stat/samplers/NormalizedGaussianSampler.kt rename to kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/samplers/NormalizedGaussianSampler.kt index 8995d3030..4eb3d60e0 100644 --- a/kmath-stat/src/commonMain/kotlin/kscience/kmath/stat/samplers/NormalizedGaussianSampler.kt +++ b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/samplers/NormalizedGaussianSampler.kt @@ -1,6 +1,6 @@ -package kscience.kmath.stat.samplers +package space.kscience.kmath.stat.samplers -import kscience.kmath.stat.Sampler +import space.kscience.kmath.stat.Sampler /** * Marker interface for a sampler that generates values from an N(0,1) diff --git a/kmath-stat/src/commonMain/kotlin/kscience/kmath/stat/samplers/PoissonSampler.kt b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/samplers/PoissonSampler.kt similarity index 88% rename from kmath-stat/src/commonMain/kotlin/kscience/kmath/stat/samplers/PoissonSampler.kt rename to kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/samplers/PoissonSampler.kt index e9a6244a6..0c0234892 100644 --- a/kmath-stat/src/commonMain/kotlin/kscience/kmath/stat/samplers/PoissonSampler.kt +++ b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/samplers/PoissonSampler.kt @@ -1,8 +1,8 @@ -package kscience.kmath.stat.samplers +package space.kscience.kmath.stat.samplers -import kscience.kmath.chains.Chain -import kscience.kmath.stat.RandomGenerator -import kscience.kmath.stat.Sampler +import space.kscience.kmath.chains.Chain +import space.kscience.kmath.stat.RandomGenerator +import space.kscience.kmath.stat.Sampler /** * Sampler for the Poisson distribution. diff --git a/kmath-stat/src/commonMain/kotlin/kscience/kmath/stat/samplers/SmallMeanPoissonSampler.kt b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/samplers/SmallMeanPoissonSampler.kt similarity index 88% rename from kmath-stat/src/commonMain/kotlin/kscience/kmath/stat/samplers/SmallMeanPoissonSampler.kt rename to kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/samplers/SmallMeanPoissonSampler.kt index e9ce8a6a6..0fe7ff161 100644 --- a/kmath-stat/src/commonMain/kotlin/kscience/kmath/stat/samplers/SmallMeanPoissonSampler.kt +++ b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/samplers/SmallMeanPoissonSampler.kt @@ -1,9 +1,9 @@ -package kscience.kmath.stat.samplers +package space.kscience.kmath.stat.samplers -import kscience.kmath.chains.Chain -import kscience.kmath.stat.RandomGenerator -import kscience.kmath.stat.Sampler -import kscience.kmath.stat.chain +import space.kscience.kmath.chains.Chain +import space.kscience.kmath.stat.RandomGenerator +import space.kscience.kmath.stat.Sampler +import space.kscience.kmath.stat.chain import kotlin.math.ceil import kotlin.math.exp diff --git a/kmath-stat/src/commonMain/kotlin/kscience/kmath/stat/samplers/ZigguratNormalizedGaussianSampler.kt b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/samplers/ZigguratNormalizedGaussianSampler.kt similarity index 93% rename from kmath-stat/src/commonMain/kotlin/kscience/kmath/stat/samplers/ZigguratNormalizedGaussianSampler.kt rename to kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/samplers/ZigguratNormalizedGaussianSampler.kt index e9e8d91da..90815209f 100644 --- a/kmath-stat/src/commonMain/kotlin/kscience/kmath/stat/samplers/ZigguratNormalizedGaussianSampler.kt +++ b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/samplers/ZigguratNormalizedGaussianSampler.kt @@ -1,9 +1,9 @@ -package kscience.kmath.stat.samplers +package space.kscience.kmath.stat.samplers -import kscience.kmath.chains.Chain -import kscience.kmath.stat.RandomGenerator -import kscience.kmath.stat.Sampler -import kscience.kmath.stat.chain +import space.kscience.kmath.chains.Chain +import space.kscience.kmath.stat.RandomGenerator +import space.kscience.kmath.stat.Sampler +import space.kscience.kmath.stat.chain import kotlin.math.* /** diff --git a/kmath-stat/src/jvmTest/kotlin/space/kscience/kmath/stat/CommonsDistributionsTest.kt b/kmath-stat/src/jvmTest/kotlin/space/kscience/kmath/stat/CommonsDistributionsTest.kt index 59320e6b5..76aac65c4 100644 --- a/kmath-stat/src/jvmTest/kotlin/space/kscience/kmath/stat/CommonsDistributionsTest.kt +++ b/kmath-stat/src/jvmTest/kotlin/space/kscience/kmath/stat/CommonsDistributionsTest.kt @@ -3,9 +3,9 @@ package space.kscience.kmath.stat import kotlinx.coroutines.flow.take import kotlinx.coroutines.flow.toList import kotlinx.coroutines.runBlocking -import kscience.kmath.stat.samplers.GaussianSampler import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.Test +import space.kscience.kmath.stat.samplers.GaussianSampler internal class CommonsDistributionsTest { @Test