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

allow different lambda functions (besides logistic)? #517

Open
mathause opened this issue Sep 4, 2024 · 1 comment
Open

allow different lambda functions (besides logistic)? #517

mathause opened this issue Sep 4, 2024 · 1 comment

Comments

@mathause
Copy link
Member

mathause commented Sep 4, 2024

We have a TODO on allowing other lambda functions:

# TODO allow passing func instead of our fixed lambda_function?

E.g. logistic, constant, linear. I think we could maybe do this by collecting the necessary info in a class for each covariate function:

class LogisticLambda:
    
    bounds = np.array([[0, np.inf], [-0.1, 0.1]])
    first_guess = np.array([1, 0])

    @staticmethod
    def lambdas_from_covariates(coeffs, covariate):
        return 2 / (1 + coeffs[0] * np.exp(covariate * coeffs[1]))

class ConstantLambda:
    
    bounds = None
    first_guess = np.array([1])

    @staticmethod
    def lambdas_from_covariates(coeffs, covariate):
        return np.full_like(covariate, fill_value=coeffs)

def _get_lambda_cls(function):

    if function == "logistic":
        return LogisticLambda()
    elif function == "constant":
        return ConstantLambda()
    else:
        raise ValueError()

...
- lambdas = lambda_function(coeffs, yearly_pred)
+ lambda_cls = _get_lambda_cls("constant")
+ lambdas = lambda_cls.lambdas_from_covariates(coeffs, yearly_pred)

As a side note: we have similar goals and challenges as for MESMER-X: extending standard statistical methods with covariates...

@mathause
Copy link
Member Author

  1. A constant lambda would be much faster to estimate - good to have an interactive example on rtd.
  2. As we found out that lambda does not need to be in 0..2, a linear function could also be attractive

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants