
I’ll post the comment later, if I manage to make it fit for consumption.Meanwhile, while trying to assemble what I wanted to say, a note more objective in its nature. I believe there is an error in this video: the example with current measurement. The total energy consumed includes the peaks. It’s the integral of current over time, and that is exactly equal to time multiplied by the mean, not the median. They may of course contribute close to nothing. True. But if this is the case, there will also be close to no difference between the mean and the median.
If you have a product with a predictable repeatable current pattern, then yes, that would be true. (…) My point was that if you measured a bunch of data points to find a base current consumption of your widget, and it happened to include a random large current spike, then that could eronerously increase the overwise "base current" specification.


#!/usr/bin/env python
# SPDX-License-Identifier: CC0-1.0
# Copyright © 2024 mpan; <https://mpan.pl/>
import matplotlib.pyplot as plt
import numpy as np
import random
import time
def generate_mcu_curve(*, n=1000, vscale=0.75, noise=0.1, reps=4,
extras_scale=8, extras_width=0.01, extras_n=8):
# n: number of points
# vscale: scale signal shifts
# noise: scale of the random noise to add, None for none
# reps: signal repetitions
# extras_*: scale, width and number of extra peaks
nTotal = n
n = n // reps
x = np.linspace(0, 1, nTotal)
y = np.ones(n)
for i in range(0, 4):
t0 = int(n * random.random())
t1 = t0 + n // 2
r = random.gauss(0, vscale / 3)
if t1 < n:
y[t0:t1] += r
else:
y[t0:] += r
y[:t1-n] += r
y = np.concatenate([y] * reps)
for i in range(0, extras_n):
t1 = nTotal
while t1 >= nTotal:
t0 = int(nTotal * random.random())
t1 = t0 + int(extras_width * nTotal)
y[t0:t1] = extras_scale
if None is not noise:
y += np.random.normal(0, noise / 3, nTotal)
return (x, y)
def run():
seed = time.monotonic_ns() % 2**32
random.seed(seed)
np.random.seed(seed)
extrasScale = 10
n = 1000
x, y = generate_mcu_curve(n=n, extras_scale=extrasScale)
mean = np.mean(y)
q2 = np.median(y)
total = sum(y) / n
cutoff = extrasScale / 2
goodTotal = sum(v for v in y if v < cutoff) / n
print(f'Seed: {seed}')
print(f'Mean: {mean:.3f}')
print(f'Median: {q2:.3f}')
print(f'Cutoff: {cutoff:.3f}')
print(f'Sum: {total:.3f}')
print(f'Good sum: {goodTotal:.3f}')
plots = plt.figure().subplot_mosaic([['sig'], ['hist'], ['histZoom']])
sigPlt = plots['sig']
histPlt = plots['hist']
histZoomPlt = plots['histZoom']
sigPlt.set_title('Mean vs median in a signal with outliers')
sigPlt.set_xlabel('Time (no unit)')
sigPlt.set_ylabel('Value (no unit)')
sigPlt.set_ylim([0, max(y) * 1.05])
sigPlt.plot(x, y, c='gray', label='Signal')
sigPlt.plot([0, 0.25], [mean, mean], ls=':', c='red', label=f'Mean {mean:.3f}')
sigPlt.plot([0, 0.25], [q2, q2], ls='--', c='blue', label=f'Median {q2:.3f}')
sigPlt.legend()
counts, b, p = histPlt.hist(y, bins=300, color='gray',
label='Histogram (detail below)')
countsMax = max(counts)
histPlt.set_ylabel('Count')
histPlt.set_xlim([0, max(y) * 1.05])
histPlt.plot([mean, mean], [0, countsMax], c='red', ls=':', label=None)
histPlt.plot([q2, q2], [0, countsMax], c='blue', ls='--', label=None)
histPlt.legend()
ySub = [v for v in y if v < cutoff]
counts, b, p = histZoomPlt.hist(ySub, bins=50, color='gray', label=None)
countsMax = max(counts)
histZoomPlt.set_xlabel('Signal value')
histZoomPlt.set_ylabel('Count')
histZoomPlt.set_xlim([min(ySub) * 0.95, max(max(ySub), mean) * 1.05])
histZoomPlt.plot([mean, mean], [0, countsMax], c='red', ls=':', label=None)
histZoomPlt.plot([q2, q2], [0, countsMax], c='blue', ls='--', label=None)
histZoomPlt.plot([goodTotal, goodTotal], [countsMax / 2, countsMax / 2],
'x', c='blue', label='Good value')
histZoomPlt.legend()
plt.tight_layout()
plt.show()
if '__main__' == __name__:
run()
I loved the comment where the guy says: "I was expecting an awesome video, but overall it was quite mean"



I loved the comment where the guy says: "I was expecting an awesome video, but overall it was quite mean"Noooooo!
First of all, the video is fine! That single example at the end didn’t really work too well. But that’s the only problem and my long post above is, I hope, explaining what was the goal.
I loved the comment where the guy says: "I was expecting an awesome video, but overall it was quite mean"
Great video, Dave!
I loved the comment where the guy says: "I was expecting an awesome video, but overall it was quite mean"
Great video, Dave!People just can't resist returning to the mean. The joke comment was spoiled by using mean instead of average.
My language use makes people often interpret it contrary to what my intention was or what mood I expressed.
First of all, the video is fine! That single example at the end didn’t really work too well.
I loved the comment where the guy says: "I was expecting an awesome video, but overall it was quite mean"