org.kalasim.misc.Math.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kalasim Show documentation
Show all versions of kalasim Show documentation
kalasim is a process-oriented discrete event simulation engine
package org.kalasim.misc
import org.apache.commons.math3.distribution.EnumeratedDistribution
import org.apache.commons.math3.stat.descriptive.*
import org.apache.commons.math3.stat.descriptive.rank.Median
import org.kalasim.monitors.ValueTimeline
fun Collection.median() = Median().evaluate(toDoubleArray())
val DescriptiveStatistics.median: Double
get() = Median().evaluate(values)
// copied from krangl
fun List.cumSum(): Iterable =
drop(1).fold(listOf(first().toDouble())) { list, curVal ->
list + (list.last().toDouble() + curVal.toDouble())
}
fun List.merge(): StatisticalSummaryValues = AggregateSummaryStatistics.aggregate(this)
fun List>.mergeStats() = map { it.statisticsSummary() }.merge()
//
//fun List.mergeStats() = flatMap { it.statisticsSummary().pmf }.groupBy { it.first }
// .map { it.key to it.value.sumOf { it.second } }.asCMPairList().run {
// EnumeratedDistribution(this)
// }
fun List>.merge() =
flatMap { it.pmf }
.groupBy { it.first }
.map { kv -> kv.key to kv.value.sumOf { it.second } }
.asCMPairList()
.run {
EnumeratedDistribution(this)
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy