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 uniform priors to handle infinite bounds --> equivalent to having "no prior" #82

Merged
merged 2 commits into from
Aug 30, 2024

Conversation

twallema
Copy link
Owner

  • I have checked to ensure there aren't other open Pull Requests for the same update/change
  • I have updated the documentation accordingly.

Describe your fixes/additions/changes

In src/pySODM/optimization/objective_functions.py, the uniform prior probability was implemented as follows,

def log_prior_uniform(x, bounds):
    """ Uniform log prior distribution """
    prob = 1/(bounds[1]-bounds[0])
    condition = bounds[0] <= x <= bounds[1]
    if condition == True:
        # should be set to zero to accomodate bounds = np.inf --> prob is inf!!!
        return np.log(prob)
    else:
        return -np.inf

which, when given an infinite bound (i.e. having no physical bound to the parameter) returned an error because prob --> 0, so np.log(prob) --> inf.

As we are taking the log sum of the prior probabilities and likelihood, the value of this probability does not influence the location of the maximal log posterior probability, so I've changed this to simply returning a probability of zero,

def log_prior_uniform(x, bounds):
    """ Uniform log prior distribution """
    prob = 1/(bounds[1]-bounds[0])
    condition = bounds[0] <= x <= bounds[1]
    if condition == True:
        # should be set to zero to accomodate bounds = np.inf --> prob is inf!!!
        return 0
    else:
        return -np.inf

@twallema twallema merged commit da27479 into master Aug 30, 2024
2 checks passed
@twallema twallema deleted the correct-uniform-priors branch August 30, 2024 17:41
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.

1 participant