Skip to content

Commit f1b74ee

Browse files
committed
add truncated gaussian priors
1 parent b07a0d4 commit f1b74ee

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

curepy/container/prior.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
"correlation": False,
1515
},
1616
"normal": {"function": ln_normal, "params": ["mu", "sigma"], "correlation": True},
17+
"trunc_normal": {
18+
"function": ln_trunc_normal,
19+
"params": ["mu", "sigma", "minimum", "maximum"],
20+
"correlation": False,
21+
}
1722
}
1823

1924

curepy/utilities/distributions.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,25 @@ def ln_multi_normal(
5858
"""
5959
diff = theta - mu
6060
return -0.5 * diff.T @ Sa_inv @ diff
61+
62+
def ln_trunc_normal(
63+
theta: Union[float, np.ndarray],
64+
mu: Union[float, np.ndarray],
65+
sigma: Union[float, np.ndarray],
66+
minimum: Union[float, np.ndarray],
67+
maximum: Union[float, np.ndarray],
68+
) -> Union[float, np.ndarray]:
69+
"""
70+
Evaluate the log of a truncated normal prior distribution.
71+
72+
:param theta: Current parameter value(s) to evaluate.
73+
:param mu: Mean of the normal distribution.
74+
:param sigma: Standard deviation of the normal distribution.
75+
:param minimum: Lower bound of the truncation.
76+
:param maximum: Upper bound of the truncation.
77+
:returns: Log probability proportional to the truncated normal log-density.
78+
"""
79+
if np.all(minimum < theta) and np.all(maximum > theta):
80+
return -0.5 * ((theta - mu) ** 2) / (2 * sigma**2)
81+
else:
82+
return -np.inf

0 commit comments

Comments
 (0)