Skip to content

Add natural gamma manifold#26

Open
Nimrais wants to merge 12 commits into
mainfrom
add-natural-gamma-manifold
Open

Add natural gamma manifold#26
Nimrais wants to merge 12 commits into
mainfrom
add-natural-gamma-manifold

Conversation

@Nimrais

@Nimrais Nimrais commented Jan 22, 2025

Copy link
Copy Markdown
Member

No description provided.

@Nimrais
Nimrais marked this pull request as draft January 22, 2025 18:22
@codecov

codecov Bot commented Jan 22, 2025

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.28%. Comparing base (d59a096) to head (f9beac2).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #26      +/-   ##
==========================================
+ Coverage   96.69%   97.28%   +0.58%     
==========================================
  Files          25       28       +3     
  Lines         333      405      +72     
==========================================
+ Hits          322      394      +72     
  Misses         11       11              

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

@ismailsenoz

Copy link
Copy Markdown
Contributor

A more generic implementation of Christoffel symbol.

function christoffel(::Type{D}, ::NaturalParametersSpace, η) where D
    # Pre-compute values used multiple times
    ef = ExponentialFamilyDistribution(D, η, nothing)
    G = fisherinformation(ef)
    G⁻¹ = cholinv(G)
    dG = partial_metric(D, NaturalParametersSpace(), η)
    
    T = eltype(G)  # Get the element type from G
    
    # Pre-allocate output array
    rep_size = sum(representation_size(get_natural_manifold(D, size(η))))
    Γ = zeros(T, rep_size, rep_size, rep_size)
        
    # Pre-compute the sum of dG terms
    dG_sum = similar(dG)
    
    @tensor begin
        dG_sum[ℓ,j,i] = dG[ℓ,j,i] + dG[ℓ,i,j] - dG[i,j,ℓ]
    end
    
    # Use tensor operations with pre-computed sum
    @tensor begin
        Γ[k,i,j] = T(0.5) * G⁻¹[k,ℓ] * dG_sum[ℓ,j,i]
    end
    
    return Γ
end

@ismailsenoz

Copy link
Copy Markdown
Contributor

Is there an ETA on this one?

@Nimrais
Nimrais marked this pull request as ready for review February 7, 2025 12:02
@Nimrais

Nimrais commented Feb 7, 2025

Copy link
Copy Markdown
Member Author

@ismailsenoz I think there are nuances, but more or less all things are addressed.

I don't want to change the partial code for now, I will think about how to do it properly when I address a review for Juliacon, implementing all ideas from this PR but generically for all exponential families.

@ismailsenoz ismailsenoz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ForwardDiff instead of symbolic partial derivatives.

@Nimrais Nimrais mentioned this pull request Feb 20, 2025
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