-
Notifications
You must be signed in to change notification settings - Fork 55
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 support for sum of models and custom models #160
Conversation
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #160 +/- ##
==========================================
+ Coverage 89.75% 90.74% +0.99%
==========================================
Files 23 23
Lines 2274 2475 +201
==========================================
+ Hits 2041 2246 +205
+ Misses 233 229 -4
☔ View full report in Codecov by Sentry. |
Hi @rhugonnet, Nice, thanks for all the effort! I am currently on vacation, but will be back next Tuesday. Is that early enough for you, if I only add a detailed response then? A few quick thoughts: passing Maybe an option to define a sum-combination of pre-defined functions would be to add something like: I would like to think about the parameters for a moment longer, and give you some thoughts on how to handle the parameters then. I think it would be problematic to change the structure of Thanks again and you will hear from me soon, |
Sounds good, I like all ideas! No problem, priority to holiday and I'm busy on other things next week anyway, will continue the week after next 🙂 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Thanks for the contribution. I have only one comment regarding the docstring, but will approve anyway.
…be(), parameters() and get_fit_bounds()
Sorry, was still working on your comments! |
Alright, I think this PR is now at a good stage! 😄 In short: To make this work for custom models: You've already seen 80% of the changes in the first draft, I just had to add a couple other exceptions in To make this work for sums: I introduced a Wrote a lot of tests, and added descriptions in the function docstrings! Points left to finalize:
|
Hi, I really like your changes! I think it would be helpful if you could add an example, or maybe even a little tutorial notebook to the docs for others. Concerning all the other points: I will think them through and give you my opinion on them. I'll come back to this soon |
Thanks for the feedback, will start on the tutorial and wait for the other points!
|
I will add my review as soon as possible.
That sounds great! And yes, I would also do that in a separate PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really like the changes, fixed a lot of stuff that was on the agenda for ages, along with the sum of models.
Do you have any idea, why the python 3.9 unittests are failing? is this still connected to the bug in curve_fit
?
Just did some tests in this PR changing the |
Otherwise all passing with NumPy 1.24 and SciPy 1.11.1! 😅 |
For the SciPy issue persisting with 1.11.3, I maanged to make a reproducible example and opened an issue on SciPy directly, see: #161 (comment) Investigating the NumPy one... |
It looks like the NumPy issue started with 1.25, but I couldn't reproduce it locally or track down why exactly... |
I was also not successful in finding the exact problem. I guess we go for less precision, but open an issue to remind ourselves to test again with newer numpy versions? |
Yes, I agree! For SciPy: they are going to revert the changes to how it was in |
I agree. Thanks for all the input, I am really glad that you are aware of all the changes happening in scipy. |
Hey @rhugonnet, The Thanks for all your effort |
@mmaelicke Perfect, thanks! All done, we can merge 🙂 If you want to work directly on the PRs I opened, I think normally you can push on someone's fork (maybe depends on repo params? but usually works for me):
|
Ah cool, I was unaware of that. Nice to see all the checks green again. I'll merge and go home :) |
Early draft! Stopped here to discuss the way forward, I prefer having your point of view before adjusting too many things in
Variogram
! 🙂For now:
Variogram._is_model_custom
defined duringset_model()
. This allows to separate the definition of bounds and p0 inVariogram.fit()
, defined based the length ofargs
frominspect
.However, doing it the current way, bounds and p0 will be quite poorly defined (at this point the script cannot tell which parameter matches which dimension). The user would likely have to pass them manually to reach a good fitting performance.
Additionally, the current implementation will raise issues in
Variogram.describe()
which then passes on toVariogram.parameters
.One way we could move forward would be to divide in 2 cases:
skgstat/models
, which would allow._get_bounds()
,.describe()
,.parameters
to function normally and make it easy for the user;bounds
andp0
to reach good fitting performance (in case those aren't passed).To implement 1., however, I see several questions:
model
argument? I'm not sure of the best option. A dictionary such asmodel={"op": np.sum, "models": ["spherical", "gaussian", "matern"]}
could do the job? But maybe this will get overly complex. Thinking about it, for something more complex than a sum, I'm not sure we'll be able to benefit much from knowing the nature of the models to infer "bounds" and "p0" efficiently anyways. We could simply leave it to case number 2, and add support just the sum for convenience, for which we can easily pass a list ["spherical", "gaussian", "matern"]?.parameters
? Right now it's alist
, should we simply concatenate into a longer one keeping always the same parameter order? Or switch to a dictionary?describe()
, I guess we can simply detect that it is a combination of models and return a more detailed list of parameters.To implement 2.:
bounds
andp0
to be passed by the user. I guess this should be both inVariogram.fit()
and__init__()
? We could addfit_bounds
andfit_p0
inVariogram.__init__
. But there's already a lot of arguments, so could also be inkwargs
. What do you think?That's all I noticed for now, but there might be a few additional things down the line! 😅
Resolves #159