[AstroPy] Fitting model with arbitrary number of parameters

Erik Bray embray at stsci.edu
Fri May 30 11:08:29 EDT 2014


On 05/30/2014 10:17 AM, Graham Kanarek wrote:
> Hi all,
>
> I'm hoping I can find some help here. For my program, I need to fit a composite model made up of the sum of an arbitrary number of 1D Gaussians. Since fitting CompositeModels isn't yet implemented, I'd hoped to use a custom_model_1d as a workaround. However, I'm having a lot of trouble declaring the custom model with an arbitrary number of parameters; I tried using a list for each Gaussian1D parameter, but changing the length of the lists caused an error as well. So, I'm wondering if anyone has had success fitting a model with an arbitrary number of parameters...
>
> Thanks in advance!
> --Gray Kanarek

Hi,

There are some types of models (i.e. polynomial) that can take an "arbitrary" 
number of parameters, but that number is still fixed at the time the model is 
defined (in the case of polynomial models, for example, by fixing their degree).

Currently, fitting a model that does not have a fixed-size parameter space 
(where the number of parameters is determined by the fit) is not directly 
supported by Astropy.  One possible workaround is to just use a very large 
parameter space to begin with and fit to that, in which case the amplitudes of 
many of the Gaussians should go close to zero.

I'd be happy to discuss this more offline if you'd like.

Erik




More information about the AstroPy mailing list