Skip to content

Implement closed form strategy#86

Merged
Nimrais merged 18 commits into
mainfrom
implement-closed-form-strategy
Nov 24, 2025
Merged

Implement closed form strategy#86
Nimrais merged 18 commits into
mainfrom
implement-closed-form-strategy

Conversation

@Nimrais
Copy link
Copy Markdown
Member

@Nimrais Nimrais commented Nov 23, 2025

Feature: ClosedFormStrategy for Exact Gradient Projections

Overview

This PR introduces a new projection strategy, ClosedFormStrategy, which leverages ClosedFormExpectations.jl to compute exact, analytic gradients for KL divergence minimization. By replacing Monte Carlo sampling with symbolic-numeric integration, this strategy offers "Zero-Variance" gradients, improving both accuracy and convergence speed for supported distributions.

Key Changes

1. New Strategy

  • Added ClosedFormStrategy struct in src/strategies/closed_form.jl.
  • Implemented compute_gradient! logic within a new package extension: ext/ClosedFormExpectationsExt.
  • This design ensures ExponentialFamilyProjection.jl maintains a weak dependency on ClosedFormExpectations.jl (only loaded when the user explicitly uses it).

2. Analytic Gradient Computation

  • Implemented gradient calculation using ClosedWilliamsProduct from ClosedFormExpectations.jl.

Design Choices

  • Extension Mechanism: utilized Julia’s [extensions] to isolate heavy symbolic dependencies. The core package remains lightweight.

@codecov
Copy link
Copy Markdown

codecov Bot commented Nov 23, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.41%. Comparing base (3f77bab) to head (c92114f).
⚠️ Report is 20 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #86      +/-   ##
==========================================
+ Coverage   99.38%   99.41%   +0.03%     
==========================================
  Files          12       14       +2     
  Lines         486      517      +31     
==========================================
+ Hits          483      514      +31     
  Misses          3        3              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@albertpod
Copy link
Copy Markdown
Member

Tests are failing, but LGTM overall

@Nimrais Nimrais requested a review from albertpod November 24, 2025 17:53
@Nimrais Nimrais merged commit 9608246 into main Nov 24, 2025
6 of 8 checks passed
@Nimrais Nimrais deleted the implement-closed-form-strategy branch November 24, 2025 18:50
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