Skip to content

Conversation

john-halloran
Copy link

@john-halloran john-halloran commented Aug 22, 2025

As part of the slow march towards scikit-learn compatibility, instantiating a model no longer immediately runs the optimization. This should make implementing something like a grid search a lot easier, because you can repeatedly call fit() with different rho and eta instead of having to __init__ over and over.

There are still a few things to address that make this not usable for the case I just described: for example, calling fit() repeatedly with different parameters would currently attempt to re-optimize the already found components, weights, and stretch, rather than reverting to the initial guesses to try again.

Then again, I'm not sure reverting to initial guesses is what sklearn does either. There are valid situations where you want to re-fit the existing fit. In fact, if they were decently correct, you might not mind starting from there at all. I'll admit I haven't looked into what the established way of handling this is, but the PR was getting large so I wanted to put it out for review. But deciding what to do here should probably be resolved before merging.

@sbillinge
Copy link
Contributor

nice progress. In general we want to support both UCs (multiple fits from the same starting point) and squential refinements (multiple fits starting the next fit from the previous one), so figuring out a structure that can support either based on some user input is best.

Copy link
Contributor

@sbillinge sbillinge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it looks good. I can merge it if you like. Just let me know. Some general questions

  1. why did you add the underscore after the attributes?
  2. This may be the moment we want to start writing tests so we can test these things. For example, a fairly easy test would be one that instantiates the class but doesn't run anything. What things do we want/need to be defined in the instantiated class? Write a test that instantiates the class and loads basic things and then tests that the class exists and has the right things in it.

Testing the fit() will be a bigger lift.

@john-halloran
Copy link
Author

john-halloran commented Aug 22, 2025

it looks good. I can merge it if you like. Just let me know. Some general questions

  1. why did you add the underscore after the attributes?
  2. This may be the moment we want to start writing tests so we can test these things. For example, a fairly easy test would be one that instantiates the class but doesn't run anything. What things do we want/need to be defined in the instantiated class? Write a test that instantiates the class and loads basic things and then tests that the class exists and has the right things in it.

Testing the fit() will be a bigger lift.

For 1. , Per sklearn, attributes learned from user data should end with an underscore.

For 2., That makes sense. I'll write a test for instantiating the class next.

@sbillinge
Copy link
Contributor

For 1. , Per sklearn, attributes learned from user data should end with an underscore.

interesting. I like it!

@john-halloran
Copy link
Author

john-halloran commented Aug 23, 2025

@sbillinge sklearn seems to use reset for the UCs above. That's been added now. If this looks good to you, feel free to merge it.

@sbillinge sbillinge merged commit 3c54016 into diffpy:john-development Aug 24, 2025
1 check passed
@john-halloran john-halloran deleted the new_init branch August 24, 2025 04:34
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