Implement Commons RNG-like samplers in kmath-prob module for Multiplatform #164
@ -18,24 +18,6 @@ internal object InternalUtils {
|
|||||||
|
|
||||||
fun factorial(n: Int): Long = FACTORIALS[n]
|
fun factorial(n: Int): Long = FACTORIALS[n]
|
||||||
|
|
||||||
fun validateProbabilities(probabilities: DoubleArray): Double {
|
|
||||||
require(probabilities.isNotEmpty()) { "Probabilities must not be empty." }
|
|
||||||
var sumProb = 0.0
|
|
||||||
|
|
||||||
probabilities.forEach { prob ->
|
|
||||||
validateProbability(prob)
|
|
||||||
sumProb += prob
|
|
||||||
}
|
|
||||||
|
|
||||||
require(!(sumProb.isInfinite() || sumProb <= 0)) { "Invalid sum of probabilities: $sumProb" }
|
|
||||||
return sumProb
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun validateProbability(probability: Double): Unit =
|
|
||||||
require(!(probability < 0 || probability.isInfinite() || probability.isNaN())) {
|
|
||||||
"Invalid probability: $probability"
|
|
||||||
}
|
|
||||||
|
|
||||||
class FactorialLog private constructor(
|
class FactorialLog private constructor(
|
||||||
numValues: Int,
|
numValues: Int,
|
||||||
cache: DoubleArray?
|
cache: DoubleArray?
|
||||||
@ -64,9 +46,6 @@ internal object InternalUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun withCache(cacheSize: Int): FactorialLog =
|
|
||||||
FactorialLog(cacheSize, logFactorials)
|
|
||||||
|
|
||||||
fun value(n: Int): Double {
|
fun value(n: Int): Double {
|
||||||
if (n < logFactorials.size)
|
if (n < logFactorials.size)
|
||||||
return logFactorials[n]
|
return logFactorials[n]
|
||||||
|
Loading…
Reference in New Issue
Block a user