Package: signal-processing-algorithms
Signal Processing AlgorithmsA suite of algorithms implementingEnergy
Statistics,E-Divisive with
MeansandGeneralized ESD Test for
Outliersin python. SeeThe Use
of Change Point Detection to Identify Software Performance Regressions in a Continuous Integration
SystemandCreating a Virtuous Cycle in
Performance Testing at MongoDBfor background
on the development and use of this library.Getting Started - Userspip install signal-processing-algorithmsGetting Started - DevelopersGetting the code:$ git clone git@github.com:mongodb/signal-processing-algorithms.git
$ cd signal-processing-algorithmsInstallation$ pip install poetry
$ poetry installTesting/linting:$ poetry run pytestRunning the slow tests:$ poetry run pytest --runslowSome of the larger tests can take a significant amount of time (more than 2 hours).Energy statisticsEnergy Statisticsis the statistical concept of Energy Distance
and can be used to measure how similar/different two distributions are.For statistical samples from two random variables X and Y:
x1, x2, ..., xn and y1, y2, ..., ynE-Statistic is defined as:where,T-statistic is defined as:E-coefficient of inhomogeneity is defined as:from signal_processing_algorithms.energy_statistics import energy_statistics
from some_module import series1, series2

# To get Energy Statistics of the distributions.
es = energy_statistics.get_energy_statistics(series1, series2)

# To get Energy Statistics and permutation test results of the distributions.
es_with_probabilities = energy_statistics.get_energy_statistics_and_probabilities(series1, series2, permutations=100)Intro to E-DivisiveDetecting distributional changes in a series of numerical values can be surprisingly difficult. Simple systems based on thresholds or
mean values can be yield false positives due to outliers in the data, and will fail to detect changes in the noise
profile of the series you are analyzing.One robust way of detecting many of the changes missed by other approaches is to useE-Divisive with Means, an energy
statistic based approach that compares the expected distance (Euclidean norm) between samples of two portions of the
series with the expected distance between samples within those portions.That is to say, assuming that the two portions can each be modeled as i.i.d. samples drawn from distinct random variables
(X for the first portion, Y for the second portion), you would expect the E-statistic to be non-zero if there is a
difference between the two portions:where A, B and C are as defined in the Energy Statistics above.One can prove thatand that the corresponding population value is zero if and only if X and Y have the same distribution. Under this null hypothesis the test statisticconverges in distribution to a quadratic form of independent standard normal random variables. Under the alternative hypothesis T tends to infinity. This makes it possible to construct a consistent statistical test, the energy test for equal distributionsThus for a series Z of length L,we find the most likely change point by solving the following for τ such that it has the maximum T statistic value.Multiple Change PointsThe algorithm for finding multiple change points is also simple.Assuming you have some k known change points:Partition the series into segments between/around these change points.Find the maximum value of our divergence metricwithineach partition.Take the maximum of the maxima we have just found --> this is our k+1th change point.Return to step 1 and continue until reaching your stopping criterion.Stopping CriterionIn this package we have implemented a permutation based test as a stopping criterion:After step 3 of the multiple change point procedure above, randomly permute all of the datawithineach cluster, and
find the most likely change point for this permuted data using the procedure laid out above.After performing this operation z times, count the number of
permuted change points z' that have higher divergence metrics than the change point you calculated with un-permuted data.
The significance level of your change point is thus z'/(z+1).We allow users to configure a permutation tester withpvalueandpermutationsrepresenting the significance cutoff for algorithm termination and permutations to perform for each
test, respectively.Examplefrom signal_processing_algorithms.energy_statistics import energy_statistics
from some_module import series

change_points = energy_statistics.e_divisive(series, pvalue=0.01, permutations=100)