Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Summary stat #803

Merged
merged 26 commits into from
Jun 30, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
7886cbc
First implementation of the summary stat.
ASmirnov-HORIS Jun 16, 2023
d95a062
Update API for the stat_summary() function.
ASmirnov-HORIS Jun 20, 2023
b28bf7f
Small refactor in SummaryStat.
ASmirnov-HORIS Jun 21, 2023
6ce963b
Remove extra enum class from the SummaryStatUtil.
ASmirnov-HORIS Jun 21, 2023
b7a8f33
Remove SummaryStatUtil.
ASmirnov-HORIS Jun 21, 2023
05345ee
Use references instead of lambdas for the SummaryCalculator.
ASmirnov-HORIS Jun 21, 2023
756b626
Replace SummaryCalculator by the SummaryStatUtil.
ASmirnov-HORIS Jun 21, 2023
3b2bca7
Refactor functions in SummaryStatUtil.
ASmirnov-HORIS Jun 22, 2023
1f03da4
Refactor summary stat options in StatProto.
ASmirnov-HORIS Jun 22, 2023
baccb49
Fix statData emptiness case in the SummaryStat.
ASmirnov-HORIS Jun 22, 2023
c9e154c
Further code refactoring.
ASmirnov-HORIS Jun 22, 2023
0082f74
Small fixes.
ASmirnov-HORIS Jun 22, 2023
cbabbe3
Add new stat variables and use them in the SummaryStat.
ASmirnov-HORIS Jun 23, 2023
7fea03b
Add prefix to min/max stats in stat_summary().
ASmirnov-HORIS Jun 23, 2023
0ecc6ec
Change API of the summary_stat() - add 'quantiles' parameter.
ASmirnov-HORIS Jun 26, 2023
722b43a
Tiny refactor in SummaryStat and AggregateFunctions.
ASmirnov-HORIS Jun 27, 2023
e30b93b
Use AggregateFunctions in the FiveNumberSummary.
ASmirnov-HORIS Jun 27, 2023
f076938
Add tests for AggregateFunctions.
ASmirnov-HORIS Jun 27, 2023
2313872
Replace parameter fun_map by usual aesthetics list for the stat_summa…
ASmirnov-HORIS Jun 29, 2023
4bba413
Small fixes in code for summary stat.
ASmirnov-HORIS Jun 29, 2023
9cfeea5
Merge branch 'master' into summary-stats
ASmirnov-HORIS Jun 29, 2023
4586451
Add getMapping() method to the Flipped stat context.
ASmirnov-HORIS Jun 29, 2023
9dcdd79
Add docstrings to the stat_summary() function.
ASmirnov-HORIS Jun 29, 2023
37526eb
Add demo notebook for stat_summary().
ASmirnov-HORIS Jun 29, 2023
0a1d636
Mention stat_summary() in the future_changes.
ASmirnov-HORIS Jun 29, 2023
a392ba1
Refactor StatContext.
ASmirnov-HORIS Jun 30, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Prev Previous commit
Next Next commit
Refactor functions in SummaryStatUtil.
  • Loading branch information
ASmirnov-HORIS committed Jun 22, 2023
commit 3b2bca7c82d2edf68f309da299f0efa0bf3606b4
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class SummaryStat(
if (aes == Aes.X) {
statValues[aes]!!.add(x)
} else {
val aggFunction = aggFunctionsMap.getOrElse(aes) { SummaryStatUtil.nan }
val aggFunction = aggFunctionsMap.getOrElse(aes) { SummaryStatUtil::nan }
statValues[aes]!!.add(aggFunction(sortedBin))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,21 @@ import kotlin.math.floor
import kotlin.math.round

object SummaryStatUtil {
val nan: (List<Double>) -> Double = { Double.NaN }
fun nan(sortedValues: List<Double>): Double = Double.NaN

fun count(sortedValues: List<Double>): Double {
return sortedValues.size.toDouble()
}
fun count(sortedValues: List<Double>): Double = sortedValues.size.toDouble()

fun sum(sortedValues: List<Double>): Double {
return sortedValues.sum()
}
fun sum(sortedValues: List<Double>): Double = sortedValues.sum()

fun mean(sortedValues: List<Double>): Double {
return if (sortedValues.isEmpty()) {
Double.NaN
} else if (sortedValues.size == 1) {
sortedValues.first()
} else {
sum(sortedValues) / sortedValues.size
return when (sortedValues.size) {
0 -> Double.NaN
1 -> sortedValues.first()
else -> sum(sortedValues) / sortedValues.size
}
}

fun median(sortedValues: List<Double>): Double {
return quantile(0.5)(sortedValues)
}
fun median(sortedValues: List<Double>): Double = quantile(sortedValues, 0.5)

fun min(sortedValues: List<Double>): Double {
return if (sortedValues.isEmpty()) {
Expand All @@ -50,21 +42,15 @@ object SummaryStatUtil {
}
}

fun q1(sortedValues: List<Double>): Double {
return quantile(0.25)(sortedValues)
}
fun q1(sortedValues: List<Double>): Double = quantile(sortedValues, 0.25)

fun q3(sortedValues: List<Double>): Double {
return quantile(0.75)(sortedValues)
}
fun q3(sortedValues: List<Double>): Double = quantile(sortedValues, 0.75)

fun quantile(p: Double): (List<Double>) -> Double {
return { sortedValues ->
if (sortedValues.isEmpty()) {
Double.NaN
} else if (sortedValues.size == 1) {
sortedValues.first()
} else {
fun quantile(sortedValues: List<Double>, p: Double): Double {
return when (sortedValues.size) {
0 -> Double.NaN
1 -> sortedValues.first()
else -> {
val place = p * (sortedValues.size - 1)
val i = round(place)
if (place == i) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -411,11 +411,11 @@ object StatProto {
fun getAggFunction(opts: OptionsAccessor, option: String, default: String): (List<Double>) -> Double {
return if (opts.isNumber(option)) {
val p = opts.getDouble(option)!!
SummaryStatUtil.quantile(p)
{ values -> SummaryStatUtil.quantile(values, p) }
} else {
opts.getStringDef(option, default).let {
when (it.lowercase()) {
"nan" -> SummaryStatUtil.nan
"nan" -> SummaryStatUtil::nan
"count" -> SummaryStatUtil::count
"sum" -> SummaryStatUtil::sum
"mean" -> SummaryStatUtil::mean
Expand Down