Last active
August 29, 2015 14:00
-
-
Save matthew-brett/11301221 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Script to investigate exp errors | |
from __future__ import print_function, division | |
import numpy as np | |
import sympy.mpmath as mp | |
mp.mp.dps = 100 | |
EPS = np.finfo(np.float64).eps | |
N = 100000 | |
until = 20. | |
vals = np.arange(N) * until / N | |
exact_exp = np.zeros_like(vals) | |
for i, val in enumerate(vals): | |
mp_val = mp.mpf(val) | |
mp_exp = mp.exp(mp_val) | |
exact_exp[i] = float(str(mp_exp)) | |
errors = exact_exp - np.exp(vals) | |
rel_errs = errors / exact_exp | |
print("Proportion of zeros:", np.sum(errors == 0) / N) | |
print("Sum of error:", np.sum(errors)) | |
print("Sum of squared error:", np.sum(errors ** 2)) | |
print("Max / min error:", np.max(errors), np.min(errors)) | |
print("Sum of squared relative error:", np.sum(rel_errs ** 2)) | |
print("Max / min relative error:", np.max(rel_errs), np.min(rel_errs)) | |
print("eps: ", EPS) | |
print("Proportion of relative err >= eps:", np.sum(np.abs(rel_errs) >= EPS) / N) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment