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

Adding models that don't require a derivative #92

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ironictoo
Copy link

This is an example model that shows how new models can be easily added without the need for an explicit derivative.

A numerical derivative is instead used, I included both a 3 point and 5 point version. In my use there was no significant difference between the two so I used the 3 point as the performance should be marginally better.

Adding this example or a similar one can gives users an easy option for models where the derivative can be difficult to calculate, or just cumbersome to input without errors.

@jkfindeisen
Copy link
Collaborator

I think this is a good idea.

@jkfindeisen
Copy link
Collaborator

I looked a bit more at the example and it seems to be a model for a 1D convolution with an exponential? Not sure. One would also need a bit of documentation about the model and maybe it should be one where it actually makes sense to use numerical derivatives, because they are otherwise difficult to compute. Here it might be simple to actually have an analytical solution for the derivatives.

Also the question is a bit how we want to support custom models. See especially #37. It would be good to make some progress there so new model PRs are easier to decide.

If it should only be an example model, currently one cannot add models without performance overheads. This means including it would affect performance in production. Therefore I'm currently undecided about this.

The ideal solution would be something like:

  • users can specify their own models on the fly (without needing to recompile Gpufit) and without performance overhead
  • these custom models can specify whether a derivative is supplied or not
  • if no derivative is supplied, it's approximated numerically within the framework

@jimkring
Copy link
Contributor

jimkring commented Oct 8, 2022

@jkfindeisen I agree with your points about an ideal solution. It might be useful to check out the jaxfit library, if you haven't seen it.  It uses automatic differentiation to calculate the Jacobians (instead of requiring partial derivatives or implementing numeric approximation), and does just-in-time (JIT) compilation of the model to allow "on the fly" changes to the user's model (written in Python code). Gpufit appears to perform much better for fitting smaller data sets (see screenshot below) and it would be interesting to see Gpufit could provide some of the flexibility of jaxfit without giving up computational performance.

Below is some benchmarking charts I found in a paper online...

@superchromix
Copy link
Collaborator

In the short term, I agree it would make sense to include an example model in which the derivatives are computed numerically. Even if the model is trivial with analytic derivatives, this would be useful for users.

@jimkring I will look into Jaxfit - that's an interesting development. Thanks.

@superchromix
Copy link
Collaborator

Regarding Jaxfit, I'd note that the package is designed to compute a single fit operation in each call, whereas Gpufit is designed for the parallel execution of large numbers of fits. Also, the smallest data size per fit which they tested is 10^4, which seems relatively large. Gpufit is not designed/optimized for calculation of a single fit with a large data size.

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.

None yet

4 participants