Skip to content

Add S2CondS2GridDistribution: conditional distribution on S²×S²#1590

Merged
FlorianPfaff merged 8 commits intomainfrom
copilot/add-conditioned-distribution-sphere
Apr 3, 2026
Merged

Add S2CondS2GridDistribution: conditional distribution on S²×S²#1590
FlorianPfaff merged 8 commits intomainfrom
copilot/add-conditioned-distribution-sphere

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 31, 2026

Python port of the MATLAB S2CondS2GridDistribution — a conditional distribution f(a|b) over the Cartesian product of two 2-spheres, represented by grid values.

New class: S2CondS2GridDistribution

  • Subclasses SdCondSdGridDistribution, restricting the grid to embedding dimension 3 (grid.shape == (n_points, 3))
  • Overrides fix_dim and marginalize_out to return SphericalGridDistribution instead of the generic HypersphericalGridDistribution
  • from_function factory delegates to the parent with dim=6 (S²×S²) and wraps the result
# VMF-based transition: f(xkk | xk) normalized per conditioning point
def trans(xkk, xk):
    result = np.zeros((xkk.shape[0], xk.shape[0]))
    for i in range(xk.shape[0]):
        result[:, i] = VonMisesFisherDistribution(xk[i], 1.0).pdf(xkk)
    return result

s2s2 = S2CondS2GridDistribution.from_function(trans, 112, fun_does_cartesian_product=True)

# Slice at a conditioning point → SphericalGridDistribution
sgd = s2s2.fix_dim(2, s2s2.grid[0])

Tests

Mirrors the MATLAB S2CondS2GridDistributionTest suite:

  • Warning-free construction from a normalized VMF transition
  • Warning emitted for unnormalized transitions
  • Warning-free construction from a manually normalized custom transition
  • Cartesian-product and non-Cartesian-product factory modes produce identical results
  • fix_dim(2, point).mean_direction() recovers the conditioning point
  • fix_dim and marginalize_out return SphericalGridDistribution instances

Copilot AI and others added 2 commits March 31, 2026 20:23
Agent-Logs-Url: https://github.com/FlorianPfaff/PyRecEst/sessions/5ab618f7-210c-4d7c-a7d7-2406930e6fc2

Co-authored-by: FlorianPfaff <6773539+FlorianPfaff@users.noreply.github.com>
Agent-Logs-Url: https://github.com/FlorianPfaff/PyRecEst/sessions/5ab618f7-210c-4d7c-a7d7-2406930e6fc2

Co-authored-by: FlorianPfaff <6773539+FlorianPfaff@users.noreply.github.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 31, 2026

MegaLinter analysis: Success

Descriptor Linter Files Fixed Errors Warnings Elapsed time
✅ COPYPASTE jscpd yes no no 7.47s
✅ JSON prettier 2 0 0 0 0.41s
✅ JSON v8r 2 0 0 2.59s
✅ MARKDOWN markdownlint 1 0 0 0 0.64s
✅ MARKDOWN markdown-table-formatter 1 0 0 0 0.26s
✅ PYTHON bandit 271 0 0 3.36s
✅ PYTHON black 271 8 0 0 5.21s
✅ PYTHON flake8 271 0 0 1.92s
✅ PYTHON isort 271 9 0 0 0.52s
✅ PYTHON mypy 271 0 0 4.09s
✅ PYTHON pylint 271 0 0 74.89s
✅ PYTHON ruff 271 9 0 0 0.05s
✅ REPOSITORY checkov yes no no 21.24s
✅ REPOSITORY gitleaks yes no no 4.45s
✅ REPOSITORY git_diff yes no no 0.03s
✅ REPOSITORY secretlint yes no no 5.66s
✅ REPOSITORY syft yes no no 2.9s
✅ REPOSITORY trivy-sbom yes no no 1.73s
✅ REPOSITORY trufflehog yes no no 18.19s
✅ YAML prettier 4 0 0 0 0.46s
✅ YAML v8r 4 0 0 4.97s
✅ YAML yamllint 4 0 0 0.45s

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
Contributor

github-actions Bot commented Mar 31, 2026

Test Results

   12 files  ±  0     12 suites  ±0   5h 4m 12s ⏱️ + 1h 48m 42s
  672 tests +  9    672 ✅ + 9      0 💤 ± 0  0 ❌ ±0 
8 324 runs  +108  6 960 ✅ +72  1 364 💤 +36  0 ❌ ±0 

Results for commit 08c24b0. ± Comparison against base commit d93e0af.

♻️ This comment has been updated with latest results.

@FlorianPfaff FlorianPfaff force-pushed the copilot/add-conditioned-distribution-sphere branch from 4424230 to 1ebcdac Compare April 1, 2026 16:11
@FlorianPfaff
Copy link
Copy Markdown
Owner

@copilot Do not use numpy functions, only use ones from pyrecest.backend (as other classes do)

… test file

Agent-Logs-Url: https://github.com/FlorianPfaff/PyRecEst/sessions/1f2766e8-1110-4de3-a516-b0205d621324

Co-authored-by: FlorianPfaff <6773539+FlorianPfaff@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 3, 2026

@copilot Do not use numpy functions, only use ones from pyrecest.backend (as other classes do)

Done in commit 68f03b7. Replaced all direct numpy/matplotlib imports with equivalents from pyrecest.backend (column_stack, tile, sum, zeros, pi, ones, array). Only numpy.testing for test assertions remains, which is the pattern used across all other test files in the repo.

@FlorianPfaff
Copy link
Copy Markdown
Owner

@copilot suppress the redefined-builtin error and fix the unused argument one

************* Module pyrecest.tests.distributions.test_s2_cond_s2_grid_distribution
pyrecest/tests/distributions/test_s2_cond_s2_grid_distribution.py:6:0: W0622: Redefining built-in 'sum' (redefined-builtin)
pyrecest/tests/distributions/test_s2_cond_s2_grid_distribution.py:150:26: W0613: Unused argument 'xk' (unused-argument)


Your code has been rated at 10.00/10

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 3, 2026

@copilot suppress the redefined-builtin error and fix the unused argument one

************* Module pyrecest.tests.distributions.test_s2_cond_s2_grid_distribution
...

Fixed in commit 7814d62:

  • Added # pylint: disable=redefined-builtin on the sum import line to suppress W0622
  • Renamed the unused xk parameter to _xk in f_trans2 to suppress W0613

@FlorianPfaff
Copy link
Copy Markdown
Owner

@copilot It is failing with the pytorch backend, fix it

junit_test_results_pytorch.xml -
=========================== short test summary info ============================
FAILED pyrecest/tests/distributions/test_s2_cond_s2_grid_distribution.py::TestS2CondS2GridDistributionFromFunction::test_warning_free_custom_normalized - DeprecationWarning: array_wrap must accept context and return_scalar arguments (positionally) in the future. (Deprecated NumPy 2.0)
FAILED pyrecest/tests/distributions/test_s2_cond_s2_grid_distribution.py::TestS2CondS2GridDistributionFromFunction::test_warning_free_normalized_vmf - DeprecationWarning: array_wrap must accept context and return_scalar arguments (positionally) in the future. (Deprecated NumPy 2.0)
= 2 failed, 550 passed, 73 skipped, 5561558 warnings, 11 subtests passed in 1089.69s (0:18:09) =

…rning) instead of simplefilter(\"error\")

Agent-Logs-Url: https://github.com/FlorianPfaff/PyRecEst/sessions/1dd4271f-8e52-4d2f-8a36-a54a1b5e6e22

Co-authored-by: FlorianPfaff <6773539+FlorianPfaff@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 3, 2026

@copilot It is failing with the pytorch backend, fix it

junit_test_results_pytorch.xml -
...

Fixed in commit f3bbb8f. The two failing tests used warnings.simplefilter("error") which turns all warnings into errors — including the DeprecationWarning: __array_wrap__ must accept context and return_scalar arguments emitted by PyTorch when numpy ufuncs interact with tensors under NumPy 2.0. Changed both occurrences to warnings.simplefilter("error", UserWarning), which only raises on UserWarning (the kind emitted by the normalization check) and ignores unrelated deprecation warnings.

@FlorianPfaff FlorianPfaff merged commit 90af825 into main Apr 3, 2026
19 checks passed
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