Add additional constructor
This commit is contained in:
parent
59b120e086
commit
55909aee0d
@ -36,7 +36,7 @@ internal class ViktorBenchmark {
|
|||||||
|
|
||||||
@Benchmark
|
@Benchmark
|
||||||
fun rawViktor() {
|
fun rawViktor() {
|
||||||
val one = F64Array.full(init = 1.0, shape = *intArrayOf(dim, dim))
|
val one = F64Array.full(init = 1.0, shape = intArrayOf(dim, dim))
|
||||||
var res = one
|
var res = one
|
||||||
repeat(n) { res = res + one }
|
repeat(n) { res = res + one }
|
||||||
}
|
}
|
||||||
|
@ -5,9 +5,17 @@ import kscience.kmath.prob.RandomGenerator
|
|||||||
import kscience.kmath.prob.UnivariateDistribution
|
import kscience.kmath.prob.UnivariateDistribution
|
||||||
import kscience.kmath.prob.internal.InternalErf
|
import kscience.kmath.prob.internal.InternalErf
|
||||||
import kscience.kmath.prob.samplers.GaussianSampler
|
import kscience.kmath.prob.samplers.GaussianSampler
|
||||||
|
import kscience.kmath.prob.samplers.NormalizedGaussianSampler
|
||||||
|
import kscience.kmath.prob.samplers.ZigguratNormalizedGaussianSampler
|
||||||
import kotlin.math.*
|
import kotlin.math.*
|
||||||
|
|
||||||
public inline class NormalDistribution(public val sampler: GaussianSampler) : UnivariateDistribution<Double> {
|
public inline class NormalDistribution(public val sampler: GaussianSampler) : UnivariateDistribution<Double> {
|
||||||
|
public constructor(
|
||||||
|
mean: Double,
|
||||||
|
standardDeviation: Double,
|
||||||
|
normalized: NormalizedGaussianSampler = ZigguratNormalizedGaussianSampler.of(),
|
||||||
|
) : this(GaussianSampler.of(mean, standardDeviation, normalized))
|
||||||
|
|
||||||
public override fun probability(arg: Double): Double {
|
public override fun probability(arg: Double): Double {
|
||||||
val x1 = (arg - sampler.mean) / sampler.standardDeviation
|
val x1 = (arg - sampler.mean) / sampler.standardDeviation
|
||||||
return exp(-0.5 * x1 * x1 - (ln(sampler.standardDeviation) + 0.5 * ln(2 * PI)))
|
return exp(-0.5 * x1 * x1 - (ln(sampler.standardDeviation) + 0.5 * ln(2 * PI)))
|
||||||
|
Loading…
Reference in New Issue
Block a user