Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fitting functionality using Ceres-Solver #189

Open
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

mmccrackan
Copy link
Contributor

@mmccrackan mmccrackan commented Oct 29, 2024

This branch is an attempt at adding fitting functionality to so3g using the Ceres-Solver library to support both non-linear least squares and general optimization problems. It is used to duplicate the existing noise-fitting function in sotodlib. The idea of this function is to:

  1. Find an initial guess for the white noise by calculating the median of the PSD above an input lower frequency bound.
  2. Do a least-squares fit of the 1/f component of the PSD to a power law in logspace to estimate the index and knee frequency.
  3. Run the minimization using a negative log likelihood function as the cost function.

The cost function classes and fitting functions have been written in a model-independent manner, so they should be easy to adapt for other data and model types. Ceres includes options for bounds/constraints and supports auto differentiation so derivatives and gradients don't need be calculated manually. The general minimization routine for Ceres doesn't seem to have uncertainty calculations (its least-squares routines do) so I have manually calculated the inverted Hessian matrix to get the parameter uncertainties.

I put most of the code into new fitting_ops.cxx and fitting_ops.h files instead of putting it all in array_ops.cxx. I added an array_ops.h file to hold shared functions declarations.

I've added a cmake directory with cmake files for Ceres, Eigen, Gflag, and Glog with the last 3 being dependencies of Ceres-Solver. We could move these into spt3g at some point, but this also seems to work in my tests. Eigen is a nice optimized vector, matrix, and linear algebra library that might be useful on its own, but it is not required to use Eigen when working with Ceres.

Building the Docker image for tests will take a few minutes longer now as I found that Ceres needed to be built from source as the necessary version doesn't appear to be available through apt-get libceres-dev.

@mmccrackan mmccrackan changed the title Adds fitting functionality using Ceres-Solver Add fitting functionality using Ceres-Solver Oct 29, 2024
@mmccrackan mmccrackan marked this pull request as ready for review November 4, 2024 15:41
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