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

Set ar as an attribute in AgeReplacementModel class #31

Open
Nathan-Herzhaft opened this issue Feb 21, 2025 · 1 comment
Open

Set ar as an attribute in AgeReplacementModel class #31

Nathan-Herzhaft opened this issue Feb 21, 2025 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@Nathan-Herzhaft
Copy link
Collaborator

Exploring non-absolutely continuous models with respect to the Lebesgue-Stiltjes measure in the context of age replacement policy, I would like to use relife functions (typically, renewal_equation_solver) with modified model objects that include this preventive replacement.

To do so, we need the methods of these modified model objects to have the same inputs as a classic model objects. This means not calling ar explicitly when calling the sf method of an AgeReplacementModel, but instead retrieving ar from the model's attributes. Typically, we would like to do :

from relife.core.nested_model import AgeReplacementModel
from relife.models import Weibull

model = Weibull(shape=7.351,rate=0.036)

replacement_model = AgeReplacementModel(model,ar=15) # Create a model with age replacement 15. This will override the sf method of the Weibull method.

t = np.linspace(0,100,1000)
plt.plot(t,replacement_model.sf(t)) # We don't need to give ar as input when calling sf

Which would allow us to use renewal_equation_solver with replacement_model, since replacement_model.sf doesn't need an ar input :

renewal_equation_solver(
            timeline=t,
            model=replacement_model,
            evaluated_func,
            model_args=model_args,
        )

If AgeReplacementModel is not supposed to be part of the user's API, we could instantiate these replacement model objects with a method of the LifetimeModel class that will create an AgeReplacementModel when called. For example :

model = Weibull(shape=7.351,rate=0.036)
replacement_model = model.age_replacement(ar=15)

renewal_equation_solver(
            timeline=t,
            model=replacement_model,
            evaluated_func,
            model_args=model_args,
        )
@21ch216
Copy link
Collaborator

21ch216 commented Feb 24, 2025

I've supported this idea in #27 #32. In both cases, I encourage the use of fluent interface or something close to it.

The remaining question is: should a_r (or a_0 in the case of LeftTruncatedModel) be implemented as an attribute? Personally, I have a preference for using attributes because, in many scenarios like yours, an alternative approach would require using utilities like functools.partial or similar tools to assign a value to a_r

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants