Skip to content

Initial implementation of finite-difference gradient approximations for likelihood#119

Open
alexnick83 wants to merge 5 commits into
devfrom
likelihood
Open

Initial implementation of finite-difference gradient approximations for likelihood#119
alexnick83 wants to merge 5 commits into
devfrom
likelihood

Conversation

@alexnick83

Copy link
Copy Markdown
Collaborator

Implements finite-difference 5-point stencil for computing the gradient and hessian of the likelihood. Also introduces small API changes, such as the following:

  • The Likelihood class now has two new methods, finite_difference_gradient_likelihood and finite_difference_hessian_likelihood, that implement the approximations.
  • Likelihood configuration now has a method attribute that takes values in ["exact", "finite-difference"]. The attribute can be used to switch between the analytical formula for gradients and the finite-difference approximation. Default value is "exact".
  • The method attribute is used in the new methods gradient_likelihood and hessian_likelihood that call evaluate_<x>_likelihood or finite_difference_<x>_likelihood (x is gradient or hessian) accordingly.
  • To facilitate the computation of the finite-difference approximation, the evaluate_likelihood method now returns the full vector instead of the sum.
  • The Likelihood class now has an evaluate_sum_likelihood method that calls evaluate_likelihood and sums up the vector entries.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements finite-difference gradient and Hessian approximations for likelihood functions as an alternative to exact analytical computations. It introduces a new method configuration option to switch between "exact" and "finite-difference" methods.

Key changes:

  • Added finite-difference gradient and Hessian computation methods using 5-point stencil
  • Modified likelihood API to return vectors instead of scalars from evaluate_likelihood
  • Updated method calls throughout the codebase to use new API methods

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/dalia/core/likelihood.py Core implementation of finite-difference methods and new API structure
src/dalia/configs/likelihood_config.py Added method configuration option
src/dalia/likelihoods/*.py Updated evaluate_likelihood to return NDArray instead of float
src/dalia/core/model.py Updated to use new likelihood API methods
src/dalia/models/coregional_model.py Updated to use new likelihood API methods
src/dalia/submodels/brainiac.py Added TODO comment about likelihood specialization

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread src/dalia/core/likelihood.py
Comment thread src/dalia/core/likelihood.py
Comment thread src/dalia/core/likelihood.py Outdated
Comment thread src/dalia/likelihoods/gaussian.py
@vincent-maillou

Copy link
Copy Markdown
Collaborator

Should close #22

@vincent-maillou vincent-maillou linked an issue Sep 12, 2025 that may be closed by this pull request
3 tasks
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.

Parallelize the Gradient and Hessian Finite Difference Scheme

3 participants