Skip to content

Implement deterministic Fibonacci grid sampler for Euclidean spaces#1584

Merged
FlorianPfaff merged 3 commits intomainfrom
copilot/implement-fibonacci-eigen-function
Apr 1, 2026
Merged

Implement deterministic Fibonacci grid sampler for Euclidean spaces#1584
FlorianPfaff merged 3 commits intomainfrom
copilot/implement-fibonacci-eigen-function

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 31, 2026

Adds FibonacciGridSampler — a deterministic Gaussian sampler based on multi-dimensional Fibonacci grids (Frisch & Hanebeck, FUSION 2021), alongside a refactored GaussianSampler base class.

New classes

  • AbstractEuclideanSampler — thin base class for Euclidean samplers
  • GaussianSampler — stochastic standard normal sampler via GaussianDistribution
  • FibonacciGridSampler — deterministic moment-matched samples on ℝᵈ using Fibonacci grids

Core implementation

  • _fibonacci_eigen(d) — computes the Fibonacci eigenvector matrix V and scaling vector R per Purser's "Generalized Fibonacci Grids"; includes a special-case for d=4 (since 2*4+1=9 is not prime) and warns when 2d+1 is not prime
  • _fibonacci_grid(d, l, ...) — builds the full grid: rotates a regular hypercube grid by V, selects l points inside [-½, ½]^d, applies probit transform, and moment-matches marginals to unit variance

Public API

sampler = FibonacciGridSampler()

# Deterministic standard-normal samples, shape (n, d)
samples = sampler.sample_stochastic(200, 2)

# Transformed to arbitrary Gaussian
samples = sampler.get_gaussian_samples(200, 2, covariance=Σ, mean=μ)

# Uniform on [0, 1]^d
samples = sampler.get_uniform_samples(100, 2)

Tests

15 tests covering shape, mean/std correctness, determinism, uniform range, Gaussian moment matching, and orthonormality of V for both general and d=4 cases.

Agent-Logs-Url: https://github.com/FlorianPfaff/PyRecEst/sessions/b1c48535-d5d6-45c3-8ca8-accaba185686

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 6.31s
✅ JSON prettier 2 0 0 0 0.44s
✅ JSON v8r 2 0 0 2.43s
✅ MARKDOWN markdownlint 1 0 0 0 0.61s
✅ MARKDOWN markdown-table-formatter 1 0 0 0 0.22s
✅ PYTHON bandit 247 0 0 3.06s
✅ PYTHON black 247 1 0 0 4.43s
✅ PYTHON flake8 247 0 0 1.72s
✅ PYTHON isort 247 1 0 0 0.47s
✅ PYTHON mypy 247 0 0 4.05s
✅ PYTHON pylint 247 0 0 69.81s
✅ PYTHON ruff 247 1 0 0 0.04s
✅ REPOSITORY checkov yes no no 21.14s
✅ REPOSITORY gitleaks yes no no 4.03s
✅ REPOSITORY git_diff yes no no 0.04s
✅ REPOSITORY secretlint yes no no 5.45s
✅ REPOSITORY syft yes no no 3.56s
✅ REPOSITORY trivy-sbom yes no no 1.76s
✅ REPOSITORY trufflehog yes no no 18.26s
✅ YAML prettier 4 0 0 0 0.44s
✅ YAML v8r 4 0 0 4.66s
✅ 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

@FlorianPfaff
Copy link
Copy Markdown
Owner

@copilot Can you fix the megalinter errors?

Agent-Logs-Url: https://github.com/FlorianPfaff/PyRecEst/sessions/688b5508-5628-45e7-8319-184f5f714e95

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

Copilot AI commented Mar 31, 2026

@copilot Can you fix the megalinter errors?

Fixed in a02c38e. Changes made:

  • Renamed parameter ln_points to fix E741 ambiguous variable name (flagged by flake8 and ruff)
  • Removed spaces before : in slice expressions to fix E203 (flake8)
  • Added # pylint: disable=too-many-locals to _fibonacci_eigen and # pylint: disable=too-many-locals,too-many-statements to _fibonacci_grid to fix R0914/R0915

@github-actions
Copy link
Copy Markdown
Contributor

Test Results

   12 files  ±  0     12 suites  ±0   3h 8m 47s ⏱️ + 2m 34s
  544 tests + 11    544 ✅ + 11      0 💤 ±0  0 ❌ ±0 
6 740 runs  +132  5 564 ✅ +132  1 176 💤 ±0  0 ❌ ±0 

Results for commit a02c38e. ± Comparison against base commit f5c0f75.

@FlorianPfaff FlorianPfaff merged commit 674b75c into main Apr 1, 2026
18 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