Running Mean Std
Computing data statistics.
WelfordStatistics
Compute Welford statistics iteratively.
The Welford algorithm is used to compute the mean and variance of an array iteratively. Based on the implementation from: https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#Welford's_online_algorithm
finalize()
Finalize the Welford statistics.
Returns:
-
tuple or numpy arrays–Final mean and standard deviation.
update(array, sample_idx)
Update the Welford statistics.
Parameters:
-
array(NDArray) –Input array.
-
sample_idx(int) –Current sample number.
compute_normalization_stats(image)
Compute mean and standard deviation of an array.
Expected input shape is (S, C, (Z), Y, X). The mean and standard deviation are computed per channel.
Parameters:
-
image(NDArray) –Input array.
Returns:
-
tuple of (list of floats, list of floats)–Lists of mean and standard deviation values per channel.
finalize_iterative_stats(count, mean, m2)
Finalize the mean and variance computation.
Parameters:
-
count(NDArray) –Number of elements in the array. Shape: (C,).
-
mean(NDArray) –Mean of the array. Shape: (C,).
-
m2(NDArray) –Variance of the array. Shape: (C,).
Returns:
-
tuple[NDArray, NDArray]–Final channel-wise mean and standard deviation.
update_iterative_stats(count, mean, m2, new_values)
Update the mean and variance of an array iteratively.
Parameters:
-
count(NDArray) –Number of elements in the array. Shape: (C,).
-
mean(NDArray) –Mean of the array. Shape: (C,).
-
m2(NDArray) –Variance of the array. Shape: (C,).
-
new_values(NDArray) –New values to add to the mean and variance. Shape: (C, 1, 1, Z, Y, X).
Returns:
-
tuple[NDArray, NDArray, NDArray]–Updated count, mean, and variance.