Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,9 @@ def hellinger_dist_fun(*args):
x = array(args)
return (sqrt(self.pdf(x)) - sqrt(other.pdf(x))) ** 2

squared_dist = 0.5 * self.integrate_fun_over_domain(hellinger_dist_fun, self.dim)
squared_dist = 0.5 * self.integrate_fun_over_domain(
hellinger_dist_fun, self.dim
)
return sqrt(squared_dist)

def total_variation_distance_numerical(self, other):
Expand Down
10 changes: 3 additions & 7 deletions src/pyrecest/filters/_ukf.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,7 @@ def update(self, z, R=None, hx=None, **hx_args):
sigmas_h = None
dim_z = None
for i in range(sigmas_f.shape[0]):
sigma_h = reshape(
asarray(hx(sigmas_f[i], **hx_args), dtype=float64), (-1,)
)
sigma_h = reshape(asarray(hx(sigmas_f[i], **hx_args), dtype=float64), (-1,))
if sigmas_h is None:
dim_z = sigma_h.shape[0]
sigmas_h = empty((sigmas_f.shape[0], dim_z))
Expand Down Expand Up @@ -179,9 +177,7 @@ def update(self, z, R=None, hx=None, **hx_args):
if using_default_R
else "measurement noise covariance R"
)
raise ValueError(
f"{source} has shape {R.shape}, expected {(dim_z, dim_z)}"
)
raise ValueError(f"{source} has shape {R.shape}, expected {(dim_z, dim_z)}")

z_pred = einsum("i,ij->j", Wm, sigmas_h)
Pz, Pxz = self._innovation_matrices(sigmas_f, sigmas_h, z_pred, R, Wc)
Expand All @@ -201,4 +197,4 @@ def __deepcopy__(self, memo):
memo[id(self)] = result
for k, v in self.__dict__.items():
setattr(result, k, deepcopy(v, memo))
return result
return result
4 changes: 3 additions & 1 deletion src/pyrecest/filters/abstract_particle_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ def _call_vectorized_sample_next(sample_next, particles, n_particles):
return sample_next(particles, n_particles)
return sample_next(particles, n=n_particles)

if any(param.kind == inspect.Parameter.VAR_KEYWORD for param in parameters.values()):
if any(
param.kind == inspect.Parameter.VAR_KEYWORD for param in parameters.values()
):
return sample_next(particles, n=n_particles)

return sample_next(particles)
Expand Down
6 changes: 5 additions & 1 deletion src/pyrecest/filters/unscented_kalman_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ def __init__(
raise ValueError(
"initial_state must be a GaussianDistribution or a tuple of (mean, covariance)"
)
dim_z = reshape(asarray(hx(initial_mean), dtype=float64), (-1,)).shape[0] if dim_z is None else dim_z
dim_z = (
reshape(asarray(hx(initial_mean), dtype=float64), (-1,)).shape[0]
if dim_z is None
else dim_z
)

if points is None:
# Standard settings for Gaussian approximations
Expand Down
4 changes: 1 addition & 3 deletions tests/filters/test_unscented_kalman_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,7 @@ def test_update_linear_rectangular_measurement(self):
kf.update_linear(array([1.0]), array([[1.0, 0.0]]), array([[0.5]]))

npt.assert_allclose(kf.get_point_estimate(), array([2.0 / 3.0, 1.0]))
npt.assert_allclose(
kf.filter_state.covariance(), diag(array([1.0 / 3.0, 2.0]))
)
npt.assert_allclose(kf.filter_state.covariance(), diag(array([1.0 / 3.0, 2.0])))

@unittest.skipIf(
pyrecest.backend.__backend_name__ in ("pytorch", "jax"),
Expand Down
Loading