dkirkby / bayesdesign

Utilities for Bayesian experiment design
MIT License
1 stars 0 forks source link

Invalid post_norm values #5

Open ashandonay opened 1 week ago

ashandonay commented 1 week ago

The normalization steps in calculateEIG lead to divide by zero errors:

Screenshot 2024-10-08 at 2 52 30 PM

The message appears when the sigma value in the likelihood is too small. In this example, it becomes an issue around values below ~1.0. Above this threshold, the full EIG array is calculated without any problems.

import numpy as np
from bed.grid import Grid, GridStack
from bed.design import ExperimentDesigner

designs = Grid(z=np.linspace(0, 5, 100))
params = Grid(Om=np.linspace(0.2, 0.4, 250))
features = Grid(D_H=np.linspace(0.1, 40, 250))

def likelihood_func(params, features, designs, sigma=1.2):
    with GridStack(features, designs, params):
        D_H_mean = 29.58/np.sqrt(params.Om * (1+designs.z)**3 + (1-params.Om))
        D_H_diff = features.D_H - D_H_mean
        likelihood = np.exp(-0.5 * (D_H_diff / sigma) ** 2)
    features.normalize(likelihood)
    return likelihood

likelihood = likelihood_func(params, features, designs)
prior = np.ones(params.shape)
params.normalize(prior);

designer = ExperimentDesigner(params, features, designs, likelihood)
designer.calculateEIG(prior)
ashandonay commented 1 week ago

Increasing the density of the params or features grid doesn't seem to resolve the problem.

ashandonay commented 1 week ago

I was testing this code with different sigmas. At sigma=0.8 the EIG becomes NaN at high design values due to the range of features being too far above the values of D_H_mean.

Screenshot 2024-10-08 at 3 45 32 PM

A more reasonable upper bound would probably be around 30. However, at smaller sigma values i.e. sigma=0.2, the EIGs all remain NaN seemingly regardless of the features range.