Skip to content

Conversation

@Nimrais
Copy link
Member

@Nimrais Nimrais commented Mar 18, 2025

Fisher Information Metric and Second-Order Retractions for Exponential Family Manifolds

Key Features

1. Fisher Information Metric

The FisherInformationMetric type integrates the Fisher information matrix as a Riemannian metric for exponential family manifolds. This creates a proper geometric structure that respects the natural parameterization of exponential families.

2. Retraction Methods

Two levels of retraction accuracy are implemented:

First-Order Retraction

A simple linear retraction that applies a tangent vector directly in parameter space. This is equivalent to a standard Euclidean step in the natural parameters.

Second-Order Retraction

A more sophisticated retraction that accounts for manifold curvature using Christoffel symbols. This produces a much better approximation to the true exponential map, especially for highly curved distributions.

Usage Example

using ExponentialFamilyManifolds
using Manifolds

# Create a manifold for Beta distribution parameters
M = get_natural_manifold(Beta, ())

# Generate points and tangent vectors
p = rand(M)
X = rand(M; vector_at=p)

# Use first-order retraction
q1 = retract(M, p, X, FirstOrderRetraction())

# Use second-order retraction with ForwardDiff backend
using ADTypes: AutoForwardDiff
q2 = retract(M, p, X, SecondOrderRetraction(backend=AutoForwardDiff()))

Copy link

@kellertuer kellertuer left a comment

Choose a reason for hiding this comment

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

This is just a very short first impression – but it looks nice!

import ExponentialFamily: exponential_family_typetag


struct ChartNOrderRetraction{Order,E} <: AbstractRetractionMethod

Choose a reason for hiding this comment

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

getdims(M::NaturalParametersManifold) = M.dims
getbase(M::NaturalParametersManifold) = M.base
getconditioner(M::NaturalParametersManifold) = M.conditioner
getmetric(M::NaturalParametersManifold) = M.metric

Choose a reason for hiding this comment

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

Choose a reason for hiding this comment

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

I personally would prefer get_X methods, since Julia is often snake_case (ok also with counter examples like isapprox)

Copy link
Member Author

@Nimrais Nimrais Mar 20, 2025

Choose a reason for hiding this comment

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

Comment on lines +199 to +204
function ManifoldsBase.retract_fused!(
::NaturalParametersManifold, q, p, X, t::Number, method::FirstOrderRetraction
)
q .= p .+ t .* X
return q
end

Choose a reason for hiding this comment

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

This seems to indicate your retraction type atop should indeed be an AbstractRetraction subtype – and in the long run this could be documented a bit more. For me natural coordinates seemed a bit magic in the beginning ;)

@codecov
Copy link

codecov bot commented Mar 19, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.31%. Comparing base (bd8eff2) to head (cb1b998).

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #33      +/-   ##
==========================================
+ Coverage   96.81%   97.31%   +0.49%     
==========================================
  Files          25       25              
  Lines         345      409      +64     
==========================================
+ Hits          334      398      +64     
  Misses         11       11              

☔ 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.

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.

3 participants