Skip to content

Commit

Permalink
proof of concept trial for accepting multiple interfaces for Kalman o…
Browse files Browse the repository at this point in the history
…bject, no updated docstrings yet
  • Loading branch information
mmcky committed Oct 26, 2017
1 parent ad6be3e commit eb2f677
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion quantecon/kalman.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,31 @@ class Kalman:
"""

def __init__(self, ss, x_hat=None, Sigma=None):
def __init__(self, *args, **kwargs):
args = list(args)
if type(args[0]) is LinearStateSpace:
self._init_lss(*args, **kwargs)
else:
self._init_matrix(*args, **kwargs)

def _init_lss(self, ss, x_hat=None, Sigma=None):
""" setup object using a LinearStateSpace as the first argument
"""
self.ss = ss
self.set_state(x_hat, Sigma)
self.K_infinity = None
self.Sigma_infinity = None

def _init_matrix(self, *args, **kwargs):
""" setup object by passing A, C, and G matrices directly
"""
kwargs = dict(**kwargs)
lss_kwarg_keys = ['H','mu_0','Sigma_0']
lss_kwargs = { key : kwargs[key] for key in lss_kwarg_keys if key in kwargs.keys() }
lss = LinearStateSpace(*args, **lss_kwargs)
kalman_kwargs = { key : value for key, value in kwargs.items() if key not in lss_kwargs}
self._init_lss(lss, **kalman_kwargs)

def set_state(self, x_hat, Sigma):
if Sigma is None:
Sigma = np.identity(self.ss.n)
Expand Down

0 comments on commit eb2f677

Please sign in to comment.