Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions ngraph/results/artifacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,9 @@ def from_values(
if not values:
raise ValueError("Cannot create envelope from empty values list")

# Single pass to calculate everything efficiently
# First pass: build frequency map and compute mean
frequencies = {}
Comment on lines +77 to 78
Copy link

Copilot AI Feb 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR description mentions refactoring Envelope.from_values(), but the code change is in CapacityEnvelope.from_values(). Please update the description (or code) to match the actual API being modified to avoid confusion for reviewers and future readers.

Copilot uses AI. Check for mistakes.
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@claude need an update?

total_sum = 0.0
sum_squares = 0.0
min_capacity = float("inf")
max_capacity = float("-inf")

Expand All @@ -87,17 +86,22 @@ def from_values(

# Update statistics
total_sum += value
sum_squares += value * value
min_capacity = min(min_capacity, value)
max_capacity = max(max_capacity, value)

# Calculate derived statistics
n = len(values)
mean_capacity = total_sum / n

# Use computational formula for variance: Var(X) = E[X²] - (E[X])²
variance = (sum_squares / n) - (mean_capacity * mean_capacity)
stdev_capacity = variance**0.5
# Second pass over unique values: compute variance using the
# numerically stable formula sum((x - mean)^2) / n.
# Iterating over the frequency map is efficient when there are
# many duplicate values (common in Monte Carlo results).
variance_sum = 0.0
for value, count in frequencies.items():
diff = value - mean_capacity
variance_sum += count * diff * diff
stdev_capacity = (variance_sum / n) ** 0.5
Comment on lines +96 to +104
Copy link

Copilot AI Feb 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variance/stdev computation was changed to a new two-pass algorithm, but there are no unit tests asserting stdev_capacity correctness or demonstrating improved numerical stability (e.g., large-magnitude values that cause catastrophic cancellation in the old formula, and duplicate-heavy inputs). Please add tests that validate mean_capacity/stdev_capacity for representative cases and edge cases.

Copilot uses AI. Check for mistakes.

# Process flow summaries if provided
flow_summary_stats = {}
Expand Down
Loading