Skip to content

Commit

Permalink
feat: use total components instead of adding all components for total
Browse files Browse the repository at this point in the history
  • Loading branch information
metacosm committed Jul 7, 2024
1 parent e1bcd60 commit 5df705c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void recordMeasure(double[] components) {
}

// record min / max totals
final var recordedTotal = PowerMeasure.sumOfComponents(recorded);
final var recordedTotal = PowerMeasure.sumOfSelectedComponents(recorded, metadata().totalComponents());
if (recordedTotal < minTotal) {
minTotal = recordedTotal;
}
Expand All @@ -44,7 +44,7 @@ public void recordMeasure(double[] components) {

@Override
public double total() {
return PowerMeasure.sumOfComponents(totals);
return PowerMeasure.sumOfSelectedComponents(totals, metadata().totalComponents());
}

public Duration duration() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ default double average() {

double maxMeasuredTotal();

static double sumOfComponents(double[] recorded) {
private static double sumOfComponents(double[] recorded) {
var componentSum = 0.0;
for (double value : recorded) {
componentSum += value;
Expand All @@ -47,6 +47,7 @@ static double sumOfSelectedComponents(double[] recorded, int... indices) {

default StdDev standardDeviations() {
final var cardinality = metadata().componentCardinality();
final var totalComponents = metadata().totalComponents();
final var stdDevs = new double[cardinality];
final var aggregate = new double[1];
final var samples = numberOfSamples() - 1; // unbiased so we remove one sample
Expand All @@ -60,7 +61,7 @@ default StdDev standardDeviations() {
.forEach(component -> {
final var sumOfSquares = measures().stream().parallel().peek(m -> {
// compute the std dev for total measure
final var total = sumOfComponents(m);
final var total = sumOfSelectedComponents(m, totalComponents);
aggregate[0] += total * total;
}).mapToDouble(m -> m[component] * m[component]).sum();
stdDevs[component] = stdDev(sumOfSquares, sqrdAverages[component], samples);
Expand Down

0 comments on commit 5df705c

Please sign in to comment.