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 @@ -3,7 +3,6 @@
from __future__ import annotations

import numpy as np

from pyrecest.backend_support._pytorch_assignment_index_contract import (
patch_pytorch_assignment_index_contract as _patch_pytorch_assignment_index_contract,
)
Expand Down
11 changes: 4 additions & 7 deletions src/pyrecest/filters/circular_fourier_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,10 @@ def predict_identity(self, d_sys):
# convolution. The inverse FFT returns the discrete circular sum;
# multiplying by the grid spacing approximates the convolution
# integral over [0, 2*pi).
predicted_values = (
fft.irfft(
fft.rfft(density_values) * fft.rfft(d_sys),
n=no_coefficients,
)
* (2.0 * pi / no_coefficients)
)
predicted_values = fft.irfft(
fft.rfft(density_values) * fft.rfft(d_sys),
n=no_coefficients,
) * (2.0 * pi / no_coefficients)
# Round-off in the FFT can produce tiny negative values although a
# convolution of nonnegative densities is nonnegative.
predicted_values = maximum(predicted_values, 0.0)
Expand Down
2 changes: 1 addition & 1 deletion src/pyrecest/filters/global_nearest_neighbor.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,4 +433,4 @@ def update_linear(
)

if self.log_posterior_estimates:
self.store_posterior_estimates()
self.store_posterior_estimates()
4 changes: 1 addition & 3 deletions src/pyrecest/filters/kalman_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ def _validate_kalman_state_covariance(covariance, dim):
check_symmetric=True,
)
eigenvalues = linalg.eigvalsh(covariance)
if not bool(
backend_all(eigenvalues >= -_STATE_COVARIANCE_EIGENVALUE_ATOL)
):
if not bool(backend_all(eigenvalues >= -_STATE_COVARIANCE_EIGENVALUE_ATOL)):
raise ValueError("state.covariance must be positive semidefinite.")
return covariance

Expand Down
4 changes: 1 addition & 3 deletions src/pyrecest/filters/state_space_subdivision_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,7 @@ def _validated_input_argument(values):
)
return values

system_matrices = _validated_matrix_argument(
system_matrices, "system_matrices"
)
system_matrices = _validated_matrix_argument(system_matrices, "system_matrices")
covariance_matrices = _validated_matrix_argument(
covariance_matrices, "covariance_matrices"
)
Expand Down
3 changes: 2 additions & 1 deletion src/pyrecest/filters/unscented_kalman_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
from typing import Callable

import pyrecest.backend
from pyrecest.backend import atleast_1d, zeros
from pyrecest.backend import atleast_1d
from pyrecest.backend import copy as backend_copy
from pyrecest.backend import zeros
from pyrecest.distributions import GaussianDistribution
from pyrecest.models import AdditiveNoiseMeasurementModel, AdditiveNoiseTransitionModel
from pyrecest.sampling.sigma_points import MerweScaledSigmaPoints
Expand Down
12 changes: 3 additions & 9 deletions src/pyrecest/models/_validated_motion_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,7 @@ def coordinated_turn_transition(
)


def coordinated_turn_model(
dt: float = 1.0, noise_covariance: Any | None = None
) -> Any:
def coordinated_turn_model(dt: float = 1.0, noise_covariance: Any | None = None) -> Any:
"""Return a coordinated-turn model with validated process-noise covariance."""
dt = _motion_models._as_scalar_float( # pylint: disable=protected-access
dt,
Expand Down Expand Up @@ -180,9 +178,7 @@ def se2_unicycle_transition(
)


def se2_unicycle_model(
dt: float = 1.0, noise_covariance: Any | None = None
) -> Any:
def se2_unicycle_model(dt: float = 1.0, noise_covariance: Any | None = None) -> Any:
"""Return an SE(2) unicycle model with validated process noise."""
dt = _motion_models._as_scalar_float( # pylint: disable=protected-access
dt,
Expand All @@ -193,9 +189,7 @@ def se2_unicycle_model(
return _se2_unicycle_model_impl(dt=dt, noise_covariance=noise_covariance)


def se3_pose_twist_model(
dt: float = 1.0, noise_covariance: Any | None = None
) -> Any:
def se3_pose_twist_model(dt: float = 1.0, noise_covariance: Any | None = None) -> Any:
"""Return an SE(3) pose/twist model with validated process noise."""
dt = _motion_models._as_scalar_float( # pylint: disable=protected-access
dt,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import importlib.util

import pytest

from tests.support.backend_runner import run_backend_code

pytestmark = pytest.mark.backend_portable
Expand Down
1 change: 0 additions & 1 deletion tests/filters/test_abstract_grid_filter_state_ownership.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import numpy.testing as npt

from pyrecest.backend import array
from pyrecest.distributions.circle.circular_grid_distribution import (
CircularGridDistribution,
Expand Down
2 changes: 1 addition & 1 deletion tests/filters/test_fejer_filter_control_validation.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import numpy as np
import pytest
import pyrecest.backend
import pytest
from pyrecest.filters import FejerIdentityFilter


Expand Down
7 changes: 2 additions & 5 deletions tests/filters/test_global_nearest_neighbor_gating.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import unittest

from scipy.stats import chi2

from pyrecest.filters import GlobalNearestNeighbor
from scipy.stats import chi2


class GlobalNearestNeighborGatingTest(unittest.TestCase):
def test_default_gate_matches_distance_representation(self):
squared_tracker = GlobalNearestNeighbor(
association_param={"square_dist": True}
)
squared_tracker = GlobalNearestNeighbor(association_param={"square_dist": True})
unsquared_tracker = GlobalNearestNeighbor(
association_param={"square_dist": False}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import numpy.testing as npt
import pyrecest.backend

from pyrecest.filters.hyperhemispherical_grid_filter import (
HyperhemisphericalGridFilter,
)
Expand Down
2 changes: 0 additions & 2 deletions tests/filters/test_hyperspherical_ukf_dimension_validation.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import numpy as np
import pyrecest.backend
import pytest

from pyrecest.filters.hyperspherical_ukf import HypersphericalUKF


pytestmark = pytest.mark.skipif(
pyrecest.backend.__backend_name__ == "jax",
reason="HypersphericalUKF is unsupported on JAX.",
Expand Down
2 changes: 0 additions & 2 deletions tests/filters/test_hyperspherical_ukf_state_ownership.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import numpy.testing as npt
import pyrecest.backend
import pytest

from pyrecest.backend import array, eye, to_numpy
from pyrecest.distributions import GaussianDistribution
from pyrecest.filters.hyperspherical_ukf import HypersphericalUKF


pytestmark = pytest.mark.skipif(
pyrecest.backend.__backend_name__ == "jax",
reason="HypersphericalUKF is unsupported on JAX.",
Expand Down
4 changes: 1 addition & 3 deletions tests/filters/test_imm_shared_python_matrices.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ def predict_linear(self, system_matrix, sys_noise_cov, sys_input=None):
covariance = (
system_matrix @ self.filter_state.C @ system_matrix.T + sys_noise_cov
)
self.filter_state = GaussianDistribution(
mean, covariance, check_validity=False
)
self.filter_state = GaussianDistribution(mean, covariance, check_validity=False)


@unittest.skipIf(
Expand Down
1 change: 0 additions & 1 deletion tests/filters/test_kalman_filter_covariance_validation.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import pytest

from pyrecest import backend
from pyrecest.distributions import GaussianDistribution
from pyrecest.filters import KalmanFilter
Expand Down
4 changes: 3 additions & 1 deletion tests/filters/test_low_rank_hypertoroidal_fourier_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ def test_filter_state_assignment_does_not_alias_low_rank_input(self):
state.coefficients = LowRankHypertoroidalFourierDistribution.uniform(
(5,), "identity"
).coefficients
npt.assert_allclose(low_rank_filter.filter_state.to_dense(), expected, atol=1e-12)
npt.assert_allclose(
low_rank_filter.filter_state.to_dense(), expected, atol=1e-12
)

def test_predict_identity_matches_dense_1d(self):
dense_filter = HypertoroidalFourierFilter((5,), "identity")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import unittest

import numpy as np

import pyrecest.backend
from pyrecest.distributions import GaussianDistribution
from pyrecest.filters.global_nearest_neighbor import GlobalNearestNeighbor
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import unittest

import numpy.testing as npt

from pyrecest.backend import array, copy
from pyrecest.distributions.circle.piecewise_constant_distribution import (
PiecewiseConstantDistribution,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
import numpy as np
from pyrecest.models import (
coordinated_turn_model,
motion_models,
nearly_constant_speed_model,
se2_unicycle_model,
se3_pose_twist_model,
)
from pyrecest.models import motion_models


class TestMotionModelNoiseCovarianceValidation(unittest.TestCase):
Expand Down