Dev #280
@ -3,7 +3,6 @@ package space.kscience.kmath.samplers
|
||||
import space.kscience.kmath.chains.BlockingDoubleChain
|
||||
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.
|
||||
@ -18,7 +17,7 @@ public class GaussianSampler(
|
||||
public val mean: Double,
|
||||
public val standardDeviation: Double,
|
||||
private val normalized: NormalizedGaussianSampler = BoxMullerSampler
|
||||
) : Sampler<Double> {
|
||||
) : BlockingDoubleSampler {
|
||||
|
||||
init {
|
||||
require(standardDeviation > 0.0) { "standard deviation is not strictly positive: $standardDeviation" }
|
||||
|
@ -18,10 +18,12 @@ internal class CommonsDistributionsTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testNormalDistributionBlocking() = runBlocking {
|
||||
fun testNormalDistributionBlocking() {
|
||||
val distribution = GaussianSampler(7.0, 2.0)
|
||||
val generator = RandomGenerator.default(1)
|
||||
val sample = distribution.sample(generator).nextBufferBlocking(1000)
|
||||
Assertions.assertEquals(7.0, Mean.double(sample), 0.2)
|
||||
runBlocking {
|
||||
Assertions.assertEquals(7.0, Mean.double(sample), 0.2)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user