twallema / pySODM

Simulating and Optimising Dynamical Models in Python 3
Other
9 stars 2 forks source link

Allow uniform priors to handle infinite bounds --> equivalent to having "no prior" #82

Closed twallema closed 2 weeks ago

twallema commented 2 weeks ago

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