• Stars
    star
    176
  • Rank 216,987 (Top 5 %)
  • Language
    Python
  • License
    MIT License
  • Created about 7 years ago
  • Updated 12 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Python Kalman filters vectorized as Single Instruction, Multiple Data

SIMD Kalman

Docs Status PyPI PyPi downloads

Fast Kalman filters in Python leveraging single-instruction multiple-data vectorization. That is, running n similar Kalman filters on n independent series of observations. Not to be confused with SIMD processor instructions.

import simdkalman

kf = simdkalman.KalmanFilter(
    state_transition = np.array([[1,1],[0,1]]),
    process_noise = np.diag([0.1, 0.01]),
    observation_model = np.array([[1,0]]),
    observation_noise = 1.0)

data = numpy.random.normal(size=(200, 1000))

# smooth and explain existing data
smoothed = kf.smooth(data)
# predict new data
pred = kf.predict(data, 15)

See examples/example.py for a more comprehensive example and ReadTheDocs for the full documentation. For the changelog, see releases page

According to examples/benchmark.py. This can be up to 100x faster than pykalman and 70x faster than filterpy when can be vectorized over many independent timeseries. Also in the non-vectorized case, it can be 2x faster.

Installation

pip install simdkalman

Development

  1. Create virtualenv
    • Python 2: virtualenv venvs/python2
    • Python 3: python3 -m venv venvs/python3
  2. Activate virtualenv: source venvs/pythonNNN/bin/activate
  3. Install locally pip install -e .[dev,test,docs]
  4. ./run-tests.sh
  5. deactivate virtualenv

Distribution

(personal howto)

Once:

  1. create an account in https://testpypi.python.org/pypi and https://pypi.python.org/pypi
  2. create ~/.pypirc as described here
  3. sudo pip install twine
  4. create testing virutalenvs:
    • virtualenv venvs/test-python2
    • python3 -m venv venvs/test-python3

Each distribution:

# first, set version in setup.py
# then create distributable package
python setup.py bdist_wheel
# test PyPI site
twine upload --repository testpypi dist/simdkalman-VERSION*
# the real thing
twine upload dist/simdkalman-VERSION*
# update git tags
git tag VERSION -m "released VERSION"
git push --tags

Test installation from the test site with

source venvs/test-pythonNNN/bin/activate
pip install \
    --index-url https://test.pypi.org/simple/ \
    --extra-index-url https://pypi.org/simple \
    simdkalman --upgrade
# or the real thing with just
# pip install simdkalman
pip install matplotlib
python examples/example.py
deactivate

TODO

  • EM algorithm documentation and options