Package space.kscience.kmath.stat

Types

Link copied to clipboard
class BasicSampler<out T : Any>(chainBuilder: (RandomGenerator) -> Chain<T>) : Sampler<T>

Implements Sampler by delegating sampling to value of chainBuilder.

Link copied to clipboard
fun interface BlockingStatistic<in T, out R> : Statistic<T, R>

A statistic that is computed in a synchronous blocking mode

Link copied to clipboard
interface ComposableStatistic<in T, I, out R> : Statistic<T, R>

A statistic tha could be computed separately on different blocks of data and then composed

Link copied to clipboard
class ConstantSampler<out T : Any>(value: T) : Sampler<T>

Implements Sampler by sampling only certain value.

Link copied to clipboard
class DefaultGenerator(random: Random) : RandomGenerator

Implements RandomGenerator by delegating all operations to Random.

Link copied to clipboard
class MCScope(coroutineContext: CoroutineContext, random: RandomGenerator)

A scope for a Monte-Carlo computations or multi-coroutine random number generation. The scope preserves the order of random generator calls as long as all concurrency calls is done via launch and async functions.

Link copied to clipboard
class Mean<T>(group: Ring<T>, division: (T, count: Int) -> T) : ComposableStatistic<T, Pair<T, Int>, T> , BlockingStatistic<T, T>

Arithmetic mean

Link copied to clipboard
class Median<T>(comparator: Comparator<T>) : BlockingStatistic<T, T>

Non-composable median

Link copied to clipboard
class RandomChain<out R>(generator: RandomGenerator, gen: suspend RandomGenerator.() -> R) : Chain<R>

A possibly stateful chain producing random values.

Link copied to clipboard
interface RandomGenerator

An interface that is implemented by random number generator algorithms.

Link copied to clipboard
class RandomGeneratorProvider(generator: RandomGenerator) : UniformRandomProvider

Implements UniformRandomProvider by delegating all operations to RandomGenerator.

Link copied to clipboard
class RandomSourceGenerator : RandomGenerator

Implements RandomGenerator by delegating all operations to RandomSource.

Link copied to clipboard
fun interface Sampler<out T : Any>

Sampler that generates chains of values of type T.

Link copied to clipboard
class SamplerSpace<T : Any, out S : Group<T>, ScaleOperations<T>>(algebra: S) : Group<Sampler<T>> , ScaleOperations<Sampler<T>>

A space of samplers. Allows performing simple operations on distributions.

Link copied to clipboard
fun interface Statistic<in T, out R>

A function, that transforms a buffer of random quantities to some resulting value

Link copied to clipboard
class UniformDistribution(range: ClosedFloatingPointRange<Double>) : Distribution1D<Double>
Link copied to clipboard
class UniformDoubleChain(generator: RandomGenerator) : BlockingDoubleChain

A type-specific double chunk random chain

Link copied to clipboard
data class ValueAndError(value: Double, dispersion: Double)

A combination of a random value and its dispersion.

Link copied to clipboard
object ValueAndErrorField : Field<ValueAndError>

An algebra for double value + its error combination. The multiplication assumes linear error propagation

Functions

Link copied to clipboard
fun RandomGenerator.asUniformRandomProvider(): UniformRandomProvider

Represent this RandomGenerator as commons-rng UniformRandomProvider preserving and mirroring its current state. Getting new value from one of those changes the state of another.

Link copied to clipboard
inline fun <T> MCScope.async(context: CoroutineContext = EmptyCoroutineContext, start: CoroutineStart = CoroutineStart.DEFAULT, crossinline block: suspend MCScope.() -> T): Deferred<T>

Specialized async for MCScope. Behaves the same way as regular CoroutineScope.async, but also stores the generator fork. The method itself is not thread safe.

Link copied to clipboard
fun <R> RandomGenerator.chain(generator: suspend RandomGenerator.() -> R): RandomChain<R>

Create a generic random chain with provided generator

Link copied to clipboard
fun <T, I, R> ComposableStatistic<T, I, R>.flow(flow: Flow<Buffer<T>>, dispatcher: CoroutineDispatcher = Dispatchers.Default): Flow<R>

Perform a streaming statistical analysis on a chunked data. The computation of inner representation is done in parallel if dispatcher allows it.

Link copied to clipboard
fun RandomGenerator.Companion.fromSource(source: RandomSource, seed: Long? = null): RandomSourceGenerator

Returns RandomSourceGenerator with given RandomSource and seed.

Link copied to clipboard
operator fun <T, R> BlockingStatistic<T, R>.invoke(data: Buffer<T>): R
suspend operator fun <T, R> Statistic<T, R>.invoke(data: Buffer<T>): R
Link copied to clipboard
inline fun MCScope.launch(context: CoroutineContext = EmptyCoroutineContext, start: CoroutineStart = CoroutineStart.DEFAULT, crossinline block: suspend MCScope.() -> Unit): Job

Specialized launch for MCScope. Behaves the same way as regular CoroutineScope.launch, but also stores the generator fork. The method itself is not thread safe.

Link copied to clipboard
inline suspend fun <T> mcScope(seed: Long, block: MCScope.() -> T): T

Launch mc scope with a given seed

inline suspend fun <T> mcScope(generator: RandomGenerator, block: MCScope.() -> T): T

Launches a supervised Monte-Carlo scope

Link copied to clipboard
fun RandomGenerator.Companion.mersenneTwister(seed: Long? = null): RandomSourceGenerator

Returns RandomSourceGenerator with RandomSource.MT algorithm and given seed.

Link copied to clipboard
suspend fun <T : Any> Sampler<T>.next(generator: RandomGenerator): T

Samples one value from this Sampler.

Link copied to clipboard
suspend fun Sampler<Double>.nextBuffer(generator: RandomGenerator, size: Int): Buffer<Double>

Samples a Buffer of values from this Sampler.

Link copied to clipboard
@JvmName(name = "sampleRealBuffer")
fun Sampler<Double>.sampleBuffer(generator: RandomGenerator, size: Int): Chain<Buffer<Double>>

Generates size real samples and chunks them into some buffers.

@JvmName(name = "sampleIntBuffer")
fun Sampler<Int>.sampleBuffer(generator: RandomGenerator, size: Int): Chain<Buffer<Int>>

Generates size integer samples and chunks them into some buffers.

fun <T : Any> Sampler<T>.sampleBuffer(generator: RandomGenerator, size: Int, bufferFactory: BufferFactory<T> = Buffer.Companion::boxing): Chain<Buffer<T>>

Sample a bunch of values

Link copied to clipboard

Properties

Link copied to clipboard
val Double.Companion.mean: Mean<Double>
Link copied to clipboard
val Int.Companion.mean: Mean<Int>
Link copied to clipboard
val Long.Companion.mean: Mean<Long>