Port ComplexBinghamDistribution from MATLAB libDirectional#1646
Draft
Port ComplexBinghamDistribution from MATLAB libDirectional#1646
Conversation
Agent-Logs-Url: https://github.com/FlorianPfaff/PyRecEst/sessions/d6ee9815-175f-4e2e-b052-1edc7b73a37e Co-authored-by: FlorianPfaff <6773539+FlorianPfaff@users.noreply.github.com>
Agent-Logs-Url: https://github.com/FlorianPfaff/PyRecEst/sessions/d6ee9815-175f-4e2e-b052-1edc7b73a37e Co-authored-by: FlorianPfaff <6773539+FlorianPfaff@users.noreply.github.com>
Copilot created this pull request from a session on behalf of
FlorianPfaff
April 6, 2026 05:45
View session
❌MegaLinter analysis: Error
Detailed Issues❌ PYTHON / pylint - 2 errorsSee 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
|
Test Results 12 files 12 suites 4h 42m 29s ⏱️ Results for commit 7fdedd7. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
Ports the ComplexBinghamDistribution from the MATLAB libDirectional library to Python.
New files
pyrecest/distributions/complex_hypersphere/New submodule for distributions on the complex unit hypersphere.
abstract_complex_hyperspherical_distribution.py— abstract base class for distributions on the complex unit sphere{z ∈ Cᵈ : ‖z‖ = 1}. Inherits fromAbstractManifoldSpecificDistribution; exposescomplex_dim,input_dim, andget_manifold_size()(surface area of S^{2d-1}).complex_bingham_distribution.py— main distribution class:__init__(B)— accepts any Hermitian matrix B; computeslog_c = -log C(B)pdf(za)— evaluatesexp(log_c + Re(z^H B z)); accepts a single column vector or a(d, n)batchsample(n)— rejection sampler (Kent, Constable & Er, 2004 algorithm) returning complex unit vectors of shape(d, n)log_norm(B, variant)— (negative) log of the normalization integral via the divided-differences analytical formula (exact for distinct eigenvalues; near-duplicate eigenvalues are perturbed à la the MATLABmakeSureEigenvaluesAreNotTooCloseworkaround); optional Monte Carlo variantfit(Z)— ML estimate from a(d, N)complex sample matrixestimate_parameter_matrix(S)— ML estimate from a scatter matrix viascipy.optimize.least_squarescauchy_schwarz_divergence(cB1, cB2)—log_c(B1+B2) - ½(log_c(2B1) + log_c(2B2))pyrecest/distributions/__init__.pyExports
ComplexBinghamDistribution.pyrecest/tests/distributions/test_complex_bingham_distribution.py17 unit tests covering constructor validation, normalization, pdf mode/batch/normalization, sampling, fitting, and divergence. All pass in ~1.3 s.
Notes
The MATLAB source uses
abs(dot(za, B*za))in its PDF formula. Sincez^H B zis real for Hermitian B and unit vectors, theabs()applies as a magnitude operation on a signed real value, which is inconsistent with the normalization constant computation and makes the mode land at the wrong eigenvector. This Python port correctly uses.realto strip any floating-point imaginary residual while preserving the sign, matching the standard complex Bingham distribution definition from Kent (1994).References