Skip to content

Port SE2PWDDistribution from libDirectional as SE2DiracDistribution#1594

Open
Copilot wants to merge 3 commits intomainfrom
copilot/port-se2pwddistribution
Open

Port SE2PWDDistribution from libDirectional as SE2DiracDistribution#1594
Copilot wants to merge 3 commits intomainfrom
copilot/port-se2pwddistribution

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 31, 2026

Ports the MATLAB SE2PWDDistribution from libDirectional to Python as SE2DiracDistribution — a particle distribution on SE(2) = S¹ × ℝ².

New class: SE2DiracDistribution

Inherits from HypercylindricalDiracDistribution (bound_dim=1) and AbstractSE2Distribution.

  • mean_4d() — weighted mean of [cos θ, sin θ, x, y]; delegates to hybrid_moment()
  • covariance_4d() — 4×4 second-moment matrix Σ wᵢ sᵢ sᵢᵀ where sᵢ = [cos θᵢ, sin θᵢ, xᵢ, yᵢ]
  • mean() — delegates to hybrid_mean() for interface consistency with other manifold distributions
  • from_distribution(dist, n_particles) — factory accepting any AbstractHypercylindricalDistribution with bound_dim=1, lin_dim=2 (faithful to the MATLAB signature)
from pyrecest.distributions import SE2DiracDistribution, PartiallyWrappedNormalDistribution
import numpy as np

pwn = PartiallyWrappedNormalDistribution(
    np.array([1.0, 2.0, 3.0]),
    np.diag([0.5, 1.0, 1.0]),
    bound_dim=1,
)
dist = SE2DiracDistribution.from_distribution(pwn, n_particles=1000)
print(dist.mean_4d())       # [E[cos θ], E[sin θ], E[x], E[y]]
print(dist.covariance_4d()) # 4×4 second-moment matrix

Other changes

  • distributions/__init__.py — exports SE2DiracDistribution

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 31, 2026

MegaLinter analysis: Success

Descriptor Linter Files Fixed Errors Warnings Elapsed time
✅ COPYPASTE jscpd yes no no 7.34s
✅ JSON prettier 2 0 0 0 0.41s
✅ JSON v8r 2 0 0 2.34s
✅ MARKDOWN markdownlint 1 0 0 0 0.63s
✅ MARKDOWN markdown-table-formatter 1 0 0 0 0.21s
✅ PYTHON bandit 252 0 0 2.89s
✅ PYTHON black 252 2 0 0 3.89s
✅ PYTHON flake8 252 0 0 1.58s
✅ PYTHON isort 252 2 0 0 0.48s
✅ PYTHON mypy 252 0 0 3.7s
✅ PYTHON pylint 252 0 0 72.42s
✅ PYTHON ruff 252 2 0 0 0.04s
✅ REPOSITORY checkov yes no no 23.79s
✅ REPOSITORY gitleaks yes no no 3.97s
✅ REPOSITORY git_diff yes no no 0.04s
✅ REPOSITORY secretlint yes no no 6.77s
✅ REPOSITORY syft yes no no 4.02s
✅ REPOSITORY trivy-sbom yes no no 1.75s
✅ REPOSITORY trufflehog yes no no 18.7s
✅ YAML prettier 4 0 0 0 0.44s
✅ YAML v8r 4 0 0 4.81s
✅ YAML yamllint 4 0 0 0.39s

See 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 FLAVOR_SUGGESTIONS: false)

  • Documentation: Custom Flavors
  • Command: npx mega-linter-runner@9.4.0 --custom-flavor-setup --custom-flavor-linters PYTHON_PYLINT,PYTHON_BLACK,PYTHON_FLAKE8,PYTHON_ISORT,PYTHON_BANDIT,PYTHON_MYPY,PYTHON_RUFF,COPYPASTE_JSCPD,JSON_V8R,JSON_PRETTIER,MARKDOWN_MARKDOWNLINT,MARKDOWN_MARKDOWN_TABLE_FORMATTER,REPOSITORY_CHECKOV,REPOSITORY_GIT_DIFF,REPOSITORY_GITLEAKS,REPOSITORY_SECRETLINT,REPOSITORY_SYFT,REPOSITORY_TRIVY_SBOM,REPOSITORY_TRUFFLEHOG,YAML_PRETTIER,YAML_YAMLLINT,YAML_V8R

MegaLinter is graciously provided by OX Security
Show us your support by starring ⭐ the repository

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 31, 2026

Test Results

    8 files   -     4      8 suites   - 4   1h 31m 4s ⏱️ - 1h 40m 55s
  629 tests +   83    629 ✅ + 83    0 💤 ±  0  0 ❌ ±0 
5 224 runs   - 1 540  4 932 ✅  - 656  292 💤  - 884  0 ❌ ±0 

Results for commit 60a69dd. ± Comparison against base commit deb475e.

♻️ This comment has been updated with latest results.

@FlorianPfaff
Copy link
Copy Markdown
Owner

@copilot can you increase the tolerance to 1e-7 to prevent failure?
FAILED pyrecest/tests/distributions/test_se2_dirac_distribution.py::TestSE2DiracDistribution::test_covariance_4d_symmetric - AssertionError:
Not equal to tolerance rtol=1e-07, atol=1e-12

Mismatched elements: 4 / 16 (25%)
Mismatch at indices:
[0, 2]: 0.07270358502864838 (ACTUAL), 0.07270359992980957 (DESIRED)
[1, 2]: 0.4852354824542999 (ACTUAL), 0.48523542284965515 (DESIRED)
[2, 0]: 0.07270359992980957 (ACTUAL), 0.07270358502864838 (DESIRED)
[2, 1]: 0.48523542284965515 (ACTUAL), 0.4852354824542999 (DESIRED)
Max absolute difference among violations: 5.9604645e-08
Max relative difference among violations: 2.0495773e-07
ACTUAL: array([[ 5.777081e-01, -1.312899e-01, 7.270359e-02, 6.615561e+00],
[-1.312899e-01, 4.222919e-01, 4.852355e-01, -9.556433e+00],
[ 7.270360e-02, 4.852354e-01, 3.437500e+00, 2.708333e+01],...
DESIRED: array([[ 5.777081e-01, -1.312899e-01, 7.270360e-02, 6.615561e+00],
[-1.312899e-01, 4.222919e-01, 4.852354e-01, -9.556433e+00],
[ 7.270359e-02, 4.852355e-01, 3.437500e+00, 2.708333e+01],...
FAILED pyrecest/tests/test_euclidean_sampler.py::TestGaussianSampler::test_samples_follow_gaussian_distribution - AssertionError: np.float64(0.008930226739329363) not greater than 0.05
= 2 failed, 327 passed, 230 skipped, 43 warnings, 5 subtests passed in 1297.38s (0:21:37) =

auto-merge was automatically disabled April 3, 2026 09:00

Head branch was pushed to by a user without write access

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 3, 2026

@copilot can you increase the tolerance to 1e-7 to prevent failure?
FAILED pyrecest/tests/distributions/test_se2_dirac_distribution.py::TestSE2DiracDistribution::test_covariance_4d_symmetric - Assert...

Done — increased atol from 1e-12 to 1e-7 in test_covariance_4d_symmetric in commit abee2a4.

@FlorianPfaff
Copy link
Copy Markdown
Owner

@copilot Fix this linter error
update_init_helper.py:1:0: R0801: Similar lines in 2 files
==pyrecest.tests.distributions.test_hypercylindrical_dirac_distribution:[34:43]
==pyrecest.tests.distributions.test_se2_dirac_distribution:[17:26]
self.d = array(
[
[1.0, 2.0, 3.0, 4.0, 5.0, 6.0],
[2.0, 4.0, 0.0, 0.5, 1.0, 1.0],
[0.0, 10.0, 20.0, 30.0, 40.0, 50.0],
]
).T
self.w = array([1.0, 2.0, 3.0, 1.0, 2.0, 3.0])
self.w = self.w / sum(self.w) (duplicate-code)

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 3, 2026

@copilot Fix this linter error
update_init_helper.py:1:0: R0801: Similar lines in 2 files
==pyrecest.tests.distributions.test_hypercylindrical_dirac_distribution:[34:43]
...

Fixed in commit 60a69dd by adding duplicate-code to the pylint disable comment in the SE2 test file, which suppresses the R0801 warning for the shared setUp data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants