Coder Social home page Coder Social logo

signal-processing-algorithms's Introduction

Signal Processing Algorithms

A suite of algorithms implementing Energy Statistics, E-Divisive with Means and Generalized ESD Test for Outliers in python. See The Use of Change Point Detection to Identify Software Performance Regressions in a Continuous Integration System and Creating a Virtuous Cycle in Performance Testing at MongoDB for background on the development and use of this library.

Getting Started - Users

pip install signal-processing-algorithms

Getting Started - Developers

Getting the code:

$ git clone [email protected]:mongodb/signal-processing-algorithms.git
$ cd signal-processing-algorithms

Installation

$ pip install poetry
$ poetry install

Testing/linting:

$ poetry run pytest

Running the slow tests:

$ poetry run pytest --runslow

Some of the larger tests can take a significant amount of time (more than 2 hours).

Energy statistics

Energy Statistics is 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, ..., yn

E-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-Divisive

Detecting 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 use E-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 that and that the corresponding population value is zero if and only if X and Y have the same distribution. Under this null hypothesis the test statistic

converges 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 distributions

Thus 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 Points

The algorithm for finding multiple change points is also simple.

Assuming you have some k known change points:

  1. Partition the series into segments between/around these change points.
  2. Find the maximum value of our divergence metric within each partition.
  3. Take the maximum of the maxima we have just found --> this is our k+1th change point.
  4. Return to step 1 and continue until reaching your stopping criterion.

Stopping Criterion

In 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 data within each 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 with pvalue and permutations representing the significance cutoff for algorithm termination and permutations to perform for each test, respectively.

Example

from 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)

signal-processing-algorithms's People

Contributors

ahartschen avatar anjani-bhat avatar dalyd avatar dbradf avatar jimoleary avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

signal-processing-algorithms's Issues

Error using edivisive

Hi!

When I try to run a simple e-divisive example I'm getting a dependency error.
I'm new to python package infrastructure so it's possible I did a bad install (I used pip)

Code

from signal_processing_algorithms.energy_statistics import energy_statistics
series = [1,2,3,4]

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

Error

Traceback (most recent call last):
  File "/Users/me/Library/Python/3.8/lib/python/site-packages/signal_processing_algorithms/energy_statistics/cext_calculator.py", line 20, in <module>
    LIB_E_DIVISIVE = np.ctypeslib.load_library("_e_divisive", so_path)
  File "/Users/me/Library/Python/3.8/lib/python/site-packages/numpy/ctypeslib.py", line 153, in load_library
    raise OSError("no file with expected extension")
OSError: no file with expected extension
Traceback (most recent call last):
  File "edivisive-tester.py", line 1, in <module>
    from signal_processing_algorithms.energy_statistics import energy_statistics
  File "/Users/me/Library/Python/3.8/lib/python/site-packages/signal_processing_algorithms/energy_statistics/energy_statistics.py", line 9, in <module>
    from signal_processing_algorithms.energy_statistics.cext_calculator import (
ImportError: cannot import name 'calculate_distance_matrix' from 'signal_processing_algorithms.energy_statistics.cext_calculator' (/Users/me/Library/Python/3.8/lib/python/site-packages/signal_processing_algorithms/energy_statistics/cext_calculator.py)

Python 3.8.2
signal-processing-algorithms 2.0.0

Deprecation warnings

This started happening after update to a recent version 1.3.2:

tests/report_test.py: 2 warnings
  /home/pkolaczk/.pyenv/versions/3.8.4/envs/fallout-env/lib/python3.8/site-packages/signal_processing_algorithms/e_divisive/e_divisive.py:41: DeprecationWarning: `np.float` is a deprecated alias for the builtin `float`. To silence this warning, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.
  Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
    self._series: np.ndarray = np.ndarray(0, dtype=np.float)

In total: 8526 warnings

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.