-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Derivative with numpy 1.25.2 errors with complex valued function #72
Comments
This is still an issue with numpy 1.26.1 |
In case people still come back to this issue, here is my quick fix for this. Though I have no idea how rigorous this is from an error propagation point of view, this makes the code run again for complex input: def _add_error_to_outliers_fixed(der, trim_fact=10):
"""
discard any estimate that differs wildly from the
median of all estimates. A factor of 10 to 1 in either
direction is probably wild enough here. The actual
trimming factor is defined as a parameter.
"""
if np.iscomplexobj(der):
return np.sqrt(
_add_error_to_outliers_fixed(np.real(der), trim_fact)**2
+ _add_error_to_outliers_fixed(np.imag(der), trim_fact)**2
)
try:
if np.any(np.isnan(der)):
p25, median, p75 = np.nanpercentile(der, [25,50, 75], axis=0)
else:
p25, median, p75 = np.percentile(der, [25,50, 75], axis=0)
iqr = np.abs(p75 - p25)
except ValueError as msg:
warnings.warn(str(msg))
return 0 * der
a_median = np.abs(median)
outliers = (((abs(der) < (a_median / trim_fact)) +
(abs(der) > (a_median * trim_fact))) * (a_median > 1e-8) +
((der < p25 - 1.5 * iqr) + (p75 + 1.5 * iqr < der)))
errors = outliers * np.abs(der - median)
return errors
_Limit._add_error_to_outliers = staticmethod(_add_error_to_outliers_fixed) The results seem to be sensible. Also, something like this is required because looking through the corresponding numpy changes, it is not a bug that |
This happens on the latest version of numpy (1.25.2), I guess something changed about the
percentile
function that numdifftools is using. It works fine on numpy 1.24.4.The text was updated successfully, but these errors were encountered: