-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding Kalman filter book: chapters 1-5
- Loading branch information
jbris
committed
Jan 8, 2024
1 parent
702c827
commit 4a08862
Showing
22 changed files
with
7,824 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Building Energy Statistical Models | ||
|
||
See https://github.com/srouchier/buildingenergygeeks |
Large diffs are not rendered by default.
Oops, something went wrong.
1,099 changes: 1,099 additions & 0 deletions
1,099
kalman_and_bayesian_filters/02-Discrete-Bayes.ipynb
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
911 changes: 911 additions & 0 deletions
911
kalman_and_bayesian_filters/04-One-Dimensional-Kalman-Filters.ipynb
Large diffs are not rendered by default.
Oops, something went wrong.
1,015 changes: 1,015 additions & 0 deletions
1,015
kalman_and_bayesian_filters/05-Multivariate-Gaussians.ipynb
Large diffs are not rendered by default.
Oops, something went wrong.
33 changes: 33 additions & 0 deletions
33
kalman_and_bayesian_filters/06-Multivariate-Kalman-Filters.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "e6b03f7e", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3 (ipykernel)", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.10.13" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2015 Roger R. Labbe Jr | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.TION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Kalman and Bayesian Filters in Python | ||
|
||
See https://github.com/rlabbe/Kalman-and-Bayesian-Filters-in-Python |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,183 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
"""Copyright 2015 Roger R Labbe Jr. | ||
Code supporting the book | ||
Kalman and Bayesian Filters in Python | ||
https://github.com/rlabbe/Kalman-and-Bayesian-Filters-in-Python | ||
This is licensed under an MIT license. See the LICENSE.txt file | ||
for more information. | ||
""" | ||
|
||
from contextlib import contextmanager | ||
from IPython.core.display import HTML | ||
import json | ||
import os.path | ||
import sys | ||
import warnings | ||
from kf_book.book_plots import set_figsize, reset_figsize | ||
|
||
def test_installation(): | ||
try: | ||
import filterpy | ||
except: | ||
print("Please install FilterPy from the command line by running the command\n\t$ pip install filterpy\n\nSee chapter 0 for instructions.") | ||
|
||
try: | ||
import numpy | ||
except: | ||
print("Please install NumPy before continuing. See chapter 0 for instructions.") | ||
|
||
try: | ||
import scipy | ||
except: | ||
print("Please install SciPy before continuing. See chapter 0 for instructions.") | ||
|
||
try: | ||
import sympy | ||
except: | ||
print("Please install SymPy before continuing. See chapter 0 for instructions.") | ||
|
||
try: | ||
import matplotlib | ||
except: | ||
print("Please install matplotlib before continuing. See chapter 0 for instructions.") | ||
|
||
from distutils.version import LooseVersion | ||
|
||
v = filterpy.__version__ | ||
min_version = "1.4.4" | ||
if LooseVersion(v) < LooseVersion(min_version): | ||
print("Minimum FilterPy version supported is {}. " | ||
"Please install a more recent version.\n" | ||
" ex: pip install filterpy --upgrade".format( | ||
min_version)) | ||
|
||
|
||
v = matplotlib.__version__ | ||
min_version = "3.0" # this is really old!!! | ||
if LooseVersion(v) < LooseVersion(min_version): | ||
print("Minimum Matplotlib version supported is {}. " | ||
"Please install a more recent version.".format(min_version)) | ||
|
||
# require Python 3.6+ | ||
import sys | ||
v = sys.version_info | ||
if v.major < 3 or (v.major == 3 and v.minor < 6): | ||
print('You must use Python version 3.6 or later for the notebooks to work correctly') | ||
|
||
|
||
# need to add test for IPython. I think I want to be at 6, which also implies | ||
# Python 3, matplotlib 2+, etc. | ||
|
||
# ensure that we have the correct packages loaded. This is | ||
# called when this module is imported at the top of each book | ||
# chapter so the reader can see that they need to update their environment. | ||
test_installation() | ||
|
||
|
||
# now that we've tested the existence of all packages go ahead and import | ||
|
||
import matplotlib | ||
import matplotlib.pylab as pylab | ||
import matplotlib.pyplot as plt | ||
import numpy as np | ||
|
||
|
||
try: | ||
matplotlib.style.use('default') | ||
except: | ||
pass | ||
|
||
|
||
with warnings.catch_warnings(): | ||
warnings.simplefilter("ignore", matplotlib.MatplotlibDeprecationWarning) | ||
pylab.rcParams['figure.max_open_warning'] = 50 | ||
|
||
|
||
@contextmanager | ||
def numpy_precision(precision): | ||
old = np.get_printoptions()['precision'] | ||
np.set_printoptions(precision=precision) | ||
yield | ||
np.set_printoptions(old) | ||
|
||
@contextmanager | ||
def printoptions(*args, **kwargs): | ||
original = np.get_printoptions() | ||
np.set_printoptions(*args, **kwargs) | ||
yield | ||
np.set_printoptions(**original) | ||
|
||
def _decode_list(data): | ||
rv = [] | ||
for item in data: | ||
if isinstance(item, unicode): | ||
item = item.encode('utf-8') | ||
elif isinstance(item, list): | ||
item = _decode_list(item) | ||
elif isinstance(item, dict): | ||
item = _decode_dict(item) | ||
rv.append(item) | ||
return rv | ||
|
||
def _decode_dict(data): | ||
rv = {} | ||
for key, value in data.iteritems(): | ||
if isinstance(key, unicode): | ||
key = key.encode('utf-8') | ||
if isinstance(value, unicode): | ||
value = value.encode('utf-8') | ||
elif isinstance(value, list): | ||
value = _decode_list(value) | ||
elif isinstance(value, dict): | ||
value = _decode_dict(value) | ||
rv[key] = value | ||
return rv | ||
|
||
|
||
def set_style(): | ||
version = [int(version_no) for version_no in matplotlib.__version__.split('.')] | ||
|
||
try: | ||
if sys.version_info[0] >= 3: | ||
style = json.load(open("./kf_book/538.json")) | ||
else: | ||
style = json.load(open(".//kf_book/538.json"), object_hook=_decode_dict) | ||
|
||
with warnings.catch_warnings(): | ||
warnings.simplefilter("ignore", matplotlib.MatplotlibDeprecationWarning) | ||
plt.rcParams.update(style) | ||
except: | ||
pass | ||
np.set_printoptions(suppress=True, precision=3, | ||
threshold=10000., linewidth=70, | ||
formatter={'float':lambda x:' {:.3}'.format(x)}) | ||
|
||
# I don't know why I have to do this, but I have to call | ||
# with suppress a second time or the notebook doesn't suppress | ||
# exponents | ||
np.set_printoptions(suppress=True) | ||
reset_figsize() | ||
|
||
style = ''' | ||
<style> | ||
.output_wrapper, .output { | ||
height:auto !important; | ||
max-height:100000px; | ||
} | ||
.output_scroll { | ||
box-shadow:none !important; | ||
webkit-box-shadow:none !important; | ||
} | ||
</style> | ||
''' | ||
jscript = ''' | ||
%%javascript | ||
IPython.OutputArea.auto_scroll_threshold = 9999; | ||
''' | ||
return HTML(style) |
Oops, something went wrong.