question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Fitting different datasets simultaneously, using models with parameters tied across models

See original GitHub issue

Given two models called a with parameters a1, a2 and b with parameters b1, b2, I want to do a joint fit, of a evaluated on data1 (in my example that data is a two-dimensional image) and b evaluated on data2 (in my example a different image which happens to have the same dimensionality, but in the general case, that could be different), such that parameters a1 and b1 are tied through some arbitrary python function (in my example: the identity function, a1 = b1).

I’ll describe my specific use case in mode detail. In this case, I deal with PSF fitting, but note that this is outside of the scope of current photutils and the modeling problem is more general. I can give examples for fitting spectra or SEDs, too, I just happened to come upon this problem by working with images right now, that’s why I describe this example here: I have two images. They show the same object on the same WCS, but that object has different fluxes (duh, it’s in different bands). Unfortunately, there are a lot of unususable pixles in both images (saturated from a near-by object). Thus, I’d like to fit a psf (let’s call the models psf1 and psf2) to both images at the same time and require that x, y are the same, but the flux is different. So, I have two models, evaluated on two different datasets (psf_621_copy on image1 with parameters x, y, amplitude_1 and psf_845_copy evaluated on image2 with parameters x, y, flux2). I want to minimize the combined fit statistic. Is there a reasonable way to make that happen with astropy now or do I have to wait for #8769? Maybe something like psf1 | psf2 evaluated on data that is a list with two elements (image 1 and amplitude2). But then, how do I couple x and y? Seems that a problem like this is not unique to me, but I don’t find a way to express it well in the current astropy modelling paradigm.

I’m not asking for help with a specific problem, I’m describing the use case here for a feature request. If that’s already possible in the current version, an example in the docs might be enough.

For reference, I’ll paste below how I address this problem with a custom model, but I feel that there should be (and maybe is already?) a way to make that work by using operations on models as opposed to coding up a user model:

@custom_model
def twobandpsf(xy, x_0=0., y_0=0., amplitude1=1, amplitude2=1.):
    psf_621_copy.x_0_2 = x_0
    psf_621_copy.y_0_2 = y_0
    psf_621_copy.amplitude_3 = amplitude1
    psf_845_copy.x_0_2 = x_0
    psf_845_copy.y_0_2 = y_0
    psf_845_copy.amplitude_3 = amplitude2
    return np.stack([psf_621_copy(xy[0], xy[1]), psf_845_copy(xy[0], xy[1])])
@custom_model

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
karllarkcommented, Jan 11, 2022

Not fully. Tying parameters between models using a python function is not supported by JointFitter at this time.

0reactions
pllimcommented, Jan 11, 2022

tl;dr – Does #12720 completely resolve this issue?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to fit multiple datasets which have a combination of ...
A fit with lmfit always uses a single instance of a Parameters object, it does not take multiple Parameters objects.
Read more >
Simultaneous Fitting - CIAO 4.14 Sherpa
The Sherpa syntax easily allows the modeling of multiple, independent data sets. In this example, we have a source observed on two different...
Read more >
Fitting with two data sets with the same parameters
I have two different datasets ( dataTC and dataRho ) and two different models ( modelTC and modelRho ) which have shared parameters...
Read more >
Fitting multiple models to multiple data sets | Request PDF
In the context of extracting parameters for DEB models from data, we discuss the methodology of fitting multiple models, which share parameters, to...
Read more >
Chapter 5 Fitting models to data | Statistical Thinking for the ...
Thus, our simple model for height using a single parameter would be: ... Figure 5.4 we plot the root mean squared error values...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found