DeaglanBartlett / ESR

21 stars 6 forks source link

Accounting for zero-snap giving infinite likelihood in match.py #25

Closed tomasdsousa closed 10 months ago

tomasdsousa commented 10 months ago

Implementing in match.py the check already implemented in test_all_Fisher.py in issue #20, which checks whether it's fine to set parameters to zero when parameter/delta<1, or if doing that will return an infinite likelihood. To check it works we use the example likelihood class from that issue:

`class MyLikelihood(Likelihood):

def __init__(self, nx):
    super().__init__('data_file', 'cov_file', 'core_maths',)
    self.ylabel = r'$y$'
    self.xvar = np.random.uniform(0, 1, size=nx)
    self.yerr = np.full(nx, 0.2)
    self.yvar = np.ones(nx) + self.yerr * np.random.normal(0, 1, size=nx)

def negloglike(self, a, eq_numpy, **kwargs):
    try:
        if a[1] <= 0:
            return np.inf
    except:
        pass
    ypred = self.get_pred(self.xvar, np.atleast_1d(a), eq_numpy)
    if not np.all(np.isreal(ypred)):
        return np.inf
    nll = np.sum(0.5 * (ypred - self.yvar) ** 2 / self.yerr ** 2 + 0.5 * np.log(2 * np.pi) + np.log(self.yerr))
    if np.isnan(nll):
        return np.inf
    return nll`

Now, running ESR for complexity 5 using the core_maths function library, functions such as pow(Abs(a0),(pow(Abs(a1),x))) make it to the final list. Previosuly they would but with inf DL, even correcting what seemed to me to be a mistake in the match.py file that was leading to the nll to be set to nan for some functions, namely nparam in lines 129 and 141 which should be nparams.