Skip to content
Snippets Groups Projects
Commit a1ce0ead authored by Hu Zhao's avatar Hu Zhao
Browse files

feat: add overflow check for np.exp

parent 5e8fdbe0
Branches
No related tags found
No related merge requests found
...@@ -9,7 +9,8 @@ from beartype.typing import Callable ...@@ -9,7 +9,8 @@ from beartype.typing import Callable
from beartype import beartype from beartype import beartype
_min_float = 10**(sys.float_info.min_10_exp) _min_float = 10**(sys.float_info.min_10_exp)
_max_float = 10**(sys.float_info.max_10_exp)
_max_e = np.log(np.array(_max_float, dtype=np.float128))
class BayesInferenceBase(ABC): class BayesInferenceBase(ABC):
...@@ -192,6 +193,8 @@ class GridEstimation(BayesInferenceBase): ...@@ -192,6 +193,8 @@ class GridEstimation(BayesInferenceBase):
self.ln_pxl(point_i, *self.args_ln_pxl, **self.kwgs_ln_pxl) self.ln_pxl(point_i, *self.args_ln_pxl, **self.kwgs_ln_pxl)
ln_unnorm_posterior = ln_unnorm_posterior.reshape(xx_matrices[0].shape) ln_unnorm_posterior = ln_unnorm_posterior.reshape(xx_matrices[0].shape)
ln_unnorm_posterior = np.where(
ln_unnorm_posterior >= _max_e, _max_e, ln_unnorm_posterior)
unnorm_posterior = np.exp(ln_unnorm_posterior) unnorm_posterior = np.exp(ln_unnorm_posterior)
posterior = unnorm_posterior / np.sum(unnorm_posterior) / np.prod(steps) posterior = unnorm_posterior / np.sum(unnorm_posterior) / np.prod(steps)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment