Add StateSpaceSubdivisionGaussianDistribution for grid-based hybrid state spaces#1583
Add StateSpaceSubdivisionGaussianDistribution for grid-based hybrid state spaces#1583
Conversation
Agent-Logs-Url: https://github.com/FlorianPfaff/PyRecEst/sessions/b4cc14e7-6a0d-4c58-8e34-8ea0e18a0d7f Co-authored-by: FlorianPfaff <6773539+FlorianPfaff@users.noreply.github.com>
❌MegaLinter analysis: Error
Detailed Issues❌ PYTHON / flake8 - 1 errorSee detailed reports in MegaLinter artifacts Your project could benefit from a custom flavor, which would allow you to run only the linters you need, and thus improve runtime performances. (Skip this info by defining
|
|
@copilot Can you fix the failures in the test cases? Here's the log: self = <pyrecest.tests.distributions.test_state_space_subdivision_gaussian_distribution.TestStateSpaceSubdivisionGaussianDistribution testMethod=test_hybrid_mean>
pyrecest/tests/distributions/test_state_space_subdivision_gaussian_distribution.py:99: pyrecest/distributions/cart_prod/state_space_subdivision_distribution.py:54: in hybrid_mean a = array([0.00410837, 0.00392277, 0.0037559 , 0.0036067 , 0.00347416,
E ValueError: shapes (100,) and (3,100) not aligned: 100 (dim 0) != 3 (dim 0) pyrecest/_backend/_shared_numpy/init.py:385: ValueError |
Agent-Logs-Url: https://github.com/FlorianPfaff/PyRecEst/sessions/2f04bef9-8916-4022-983f-ad0b19be662c Co-authored-by: FlorianPfaff <6773539+FlorianPfaff@users.noreply.github.com>
Fixed in e0ef69f. The root cause was |
|
@copilot Do not import numpy for anything. Import the functions from pyrecest.backend instead. |
… E203 whitespace Agent-Logs-Url: https://github.com/FlorianPfaff/PyRecEst/sessions/96298e96-1a16-48b1-bf40-7c26aa7e99fb Co-authored-by: FlorianPfaff <6773539+FlorianPfaff@users.noreply.github.com>
Done in 41cb0db:
All 8 tests still pass. |

Ports the MATLAB
StateSpaceSubdivisionGaussianDistributionto Python: a joint distribution over a Cartesian product of a grid-based periodic/bounded space and a linear Gaussian space, where oneGaussianDistributionis conditioned on each grid point.New classes
StateSpaceSubdivisionDistribution(cart_prod/) — base class holding anAbstractGridDistribution(gd) and a list of linear distributions (one per grid point). Provideshybrid_mean(), abstractmarginalize_linear()/marginalize_periodic().StateSpaceSubdivisionGaussianDistribution— concrete subclass where every conditional is aGaussianDistribution:multiply(other)— per-grid-point Bayesian update; grid weights scaled by Gaussian overlap likelihoodN(μ_other; μ_self, C_self + C_other)linear_mean()/linear_covariance()— GM reduction viaGaussianMixture.mixture_parameters_to_gaussian_parametersmarginalize_periodic()→GaussianMixturewith normalized grid weightsmode()— discrete grid search maximisingpeak(C_i) × grid_value_i, with multimodality warningBug fix
GaussianMixture.mean()had the operands todotin the wrong order —dot(means_matrix, w)(shape(n, dim) · (n,)→ always fails) instead of the correct weighted sum. Fixed tosum(w.reshape(-1, 1) * means, axis=0), which is directly triggered bymarginalize_periodic().mean().Tests
Six tests covering S¹×ℝ¹ and S²×ℝ³ multiply,
linear_mean,hybrid_mean,mode, and the multimodality warning — mirroring the original MATLAB test suite.