More Accuracy With Sicpy Interp1d
I am trying to implement a non parametric estimation of the KL divergence shown in this paper Here is my code: import numpy as np import math import itertools import random from sc
Solution 1:
As e
gets small you are effectively trying to compute the ratio of derivatives of P
and Q
numerically. As you are finding, you run out of precision really quickly in floating point doing it this way.
An alternate approach would be to use an interpolation function that can return derivatives directly. For example, you could try scipy.interpolate.InterpolatedUnivariateSpline
. You were saying kind='linear'
to interp1d
, so the equivalent is k=1
. Once you construct it, the spline has method derivatives()
that gives you all the derivatives at different points. For small values of e
you could switch to using the derivative.
Post a Comment for "More Accuracy With Sicpy Interp1d"