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

Rename fit_method parameter #1366

Open
wd60622 opened this issue Jan 13, 2025 · 2 comments
Open

Rename fit_method parameter #1366

wd60622 opened this issue Jan 13, 2025 · 2 comments
Labels
CLV major API breaking changes priority: low

Comments

@wd60622
Copy link
Contributor

wd60622 commented Jan 13, 2025

This might conflict with one of the parameters of pm.sample but I find model.fit(fit_method="something") redundant

def fit( # type: ignore
self,
fit_method: str = "mcmc",

I think model.fit(method="something") reads a bit better. Maybe model.fit(algorithm="something") if there is a conflict.

Thoughts @ColtAllen

@wd60622 wd60622 changed the title Rename fit_method to method Rename fit_method parameter Jan 13, 2025
@wd60622 wd60622 added CLV and removed Needs Triage labels Jan 13, 2025
@ColtAllen ColtAllen added major API breaking changes priority: low labels Jan 13, 2025
@ColtAllen
Copy link
Collaborator

@wd60622 this crossed my mind as well when I worked on #1266. I should preface by saying the "fit_method" convention is over two years old and changing it could break the codebases of many, many users, but I never liked that param name either.

I don't want to use "method" because of the standard Python definition for that term (i.e. any function written inside a class object).

sampler could be a good alternative, but model.fit(sampler="map") would really trigger some Bayesians 😅 on that note, is MAP not supported in ModelBuilder?

model.fit(optimizer="mcmc") is another option. Bayesian sampling has many theoretical parallels with deterministic optimization, but that's a separate family of algorithms, and stochastic optimization itself is very different.

Perhaps I'm overthinking this. What are your thoughts?

@wd60622
Copy link
Contributor Author

wd60622 commented Jan 13, 2025

I don't want to use "method" because of the standard Python definition for that term (i.e. any function written inside a class object).

I am not against "method" as it is not a keyword in python

sampler could be a good alternative, but model.fit(sampler="map") would really trigger some Bayesians 😅 on that note, is MAP not supported in ModelBuilder?

That seems to fall apart with map

For me, optimizer doesn't match with mcmc then.

@wd60622 this crossed my mind as well when I worked on #1266. I should preface by saying the "fit_method" convention is over two years old and changing it could break the codebases of many, many users, but I never liked that param name either.

I'm not concerned about this. We can just deprecate it. Even if it was a keyword argument, we can just support both for a time being and have a warning. Juan and I discussed a 2 release cycle deprecation a while back with some MMM items. We could do that here as well.

For instance,

def fit(self, method: str = "mcmc", fit_method: str | None = None, **kwargs): 
    if method and fit_method: 
        raise ValueError("Both method and fit_method cannot be used. Use method in the future")

    if fit_method is not None: 
        warnings.warn("This will be deprecated in two releases. Use method instead.", DeprecationWarning)
        method = fit_method

    ...


# This stays the same
model.fit("map")
# Gets a deprecation warning
model.fit(fit_method="map")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLV major API breaking changes priority: low
Projects
None yet
Development

No branches or pull requests

2 participants