(x, mu, sigma)
| 178 | |
| 179 | @scope.define |
| 180 | def lognormal_cdf(x, mu, sigma): |
| 181 | # wikipedia claims cdf is |
| 182 | # .5 + .5 erf( log(x) - mu / sqrt(2 sigma^2)) |
| 183 | # |
| 184 | # the maximum is used to move negative values and 0 up to a point |
| 185 | # where they do not cause nan or inf, but also don't contribute much |
| 186 | # to the cdf. |
| 187 | if len(x) == 0: |
| 188 | return np.asarray([]) |
| 189 | if x.min() < 0: |
| 190 | raise ValueError("negative arg to lognormal_cdf", x) |
| 191 | olderr = np.seterr(divide="ignore") |
| 192 | try: |
| 193 | top = np.log(np.maximum(x, EPS)) - mu |
| 194 | bottom = np.maximum(np.sqrt(2) * sigma, EPS) |
| 195 | z = old_div(top, bottom) |
| 196 | return 0.5 + 0.5 * erf(z) |
| 197 | finally: |
| 198 | np.seterr(**olderr) |
| 199 | |
| 200 | |
| 201 | @scope.define |
no test coverage detected