Skip to content

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

Open
Copilot wants to merge 4 commits intomainfrom
copilot/add-conditioned-distribution-sphere
Open

Add S2CondS2GridDistribution: conditional distribution on S²×S²#1590
Copilot wants to merge 4 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

github-actions bot commented Mar 31, 2026

MegaLinter analysis: Error

Descriptor Linter Files Fixed Errors Warnings Elapsed time
✅ COPYPASTE jscpd yes no no 7.87s
✅ JSON prettier 2 0 0 0 0.43s
✅ JSON v8r 2 0 0 2.38s
✅ MARKDOWN markdownlint 1 0 0 0 0.66s
✅ MARKDOWN markdown-table-formatter 1 0 0 0 0.24s
✅ PYTHON bandit 252 0 0 3.03s
✅ PYTHON black 252 1 0 0 4.47s
❌ PYTHON flake8 252 2 0 1.76s
✅ PYTHON isort 252 2 0 0 0.48s
✅ PYTHON mypy 252 0 0 3.96s
❌ PYTHON pylint 252 4 0 70.22s
❌ PYTHON ruff 252 2 2 0 0.05s
✅ REPOSITORY checkov yes no no 21.56s
✅ REPOSITORY gitleaks yes no no 5.23s
✅ REPOSITORY git_diff yes no no 0.05s
✅ REPOSITORY secretlint yes no no 5.67s
✅ REPOSITORY syft yes no no 3.48s
✅ REPOSITORY trivy-sbom yes no no 1.7s
✅ REPOSITORY trufflehog yes no no 18.06s
✅ YAML prettier 4 0 0 0 0.5s
✅ YAML v8r 4 0 0 5.54s
✅ YAML yamllint 4 0 0 0.44s

Detailed Issues

❌ PYTHON / flake8 - 2 errors
pyrecest/tests/distributions/test_s2_cond_s2_grid_distribution.py:99:13: F401 'numpy as np' imported but unused
pyrecest/tests/distributions/test_s2_cond_s2_grid_distribution.py:152:20: F821 undefined name 'np'
❌ PYTHON / pylint - 4 errors
************* Module pyrecest.tests.distributions.test_s2_cond_s2_grid_distribution
pyrecest/tests/distributions/test_s2_cond_s2_grid_distribution.py:7:0: W0622: Redefining built-in 'sum' (redefined-builtin)
pyrecest/tests/distributions/test_s2_cond_s2_grid_distribution.py:99:12: W0611: Unused numpy imported as np (unused-import)
pyrecest/tests/distributions/test_s2_cond_s2_grid_distribution.py:152:19: E0602: Undefined variable 'np' (undefined-variable)
pyrecest/tests/distributions/test_s2_cond_s2_grid_distribution.py:154:26: W0613: Unused argument 'xk' (unused-argument)

-----------------------------------
Your code has been rated at 9.99/10
❌ PYTHON / ruff - 2 errors
F821 Undefined name `np`
   --> pyrecest/tests/distributions/test_s2_cond_s2_grid_distribution.py:150:20
    |
148 |         def f_trans1(xkk, xk):
149 |             vals = dist.pdf(xkk)  # (n1,)
150 |             return np.tile(vals[:, None], (1, xk.shape[0]))  # (n1, n2)
    |                    ^^
151 |
152 |         def f_trans2(xkk, xk):
    |

Found 2 errors (1 fixed, 1 remaining).

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

0 files   -    12  0 suites   - 12   0s ⏱️ - 3h 18m 28s
0 tests  -   571  0 ✅  -   571  0 💤 ±    0  0 ❌ ±0 
0 runs   - 7 064  0 ✅  - 5 880  0 💤  - 1 184  0 ❌ ±0 

Results for commit 5d5deff. ± Comparison against base commit 8d19d73.

♻️ 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
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