Commit 6553a802 authored by Pierre Barbier de Reuille's avatar Pierre Barbier de Reuille

Merged NPR and corrected bootstrap for pandas

parents d3ac8b51 638b85b0
......@@ -16,11 +16,6 @@ from . import bootstrap_workers
from .compat import irange, izip
def adapt_curve_fit(fct, x, y, p0, args=(), **kwrds):
popt, pcov = optimize.curve_fit(fct, x, y, **kwrds)
return (popt, pcov, fct(popt, x, *args) - y)
def percentile(array, p, axis=0):
"""
Compute the percentiles of the values in array
......@@ -248,6 +243,8 @@ def bootstrap(fit, xdata, ydata, CI, shuffle_method=bootstrap_residuals,
confidence intervals and, if requested, the shuffled X, Y and the full
estimated distributions.
"""
xdata = np.asarray(xdata)
ydata = np.asarray(ydata)
y_fit = fit(xdata, ydata, *fit_args, **fit_kwrds)
y_fit.fit()
......
......@@ -160,6 +160,8 @@ class NonParamRegression(object):
"""
Lower bound of the domain for each dimension
"""
if self._lower is None:
return -np.inf*np.ones(self.dim, dtype=float)
return self._lower
@lower.setter
......@@ -178,6 +180,8 @@ class NonParamRegression(object):
"""
Lower bound of the domain for each dimension
"""
if self._upper is None:
return np.inf*np.ones(self.dim, dtype=float)
return self._upper
@upper.setter
......@@ -274,17 +278,19 @@ class NonParamRegression(object):
D, N = self._xdata.shape
assert self._ydata.shape[0] == N, "There must be as many points for X and Y"
self._kernel = self._create_kernel(D)
if self._lower is None:
self._lower = -np.inf * np.ones((D,), dtype=float)
if self._upper is None:
self._upper = np.inf * np.ones((D,), dtype=float)
self._n = N
self._d = D
lower = self.lower
upper = self.upper
assert len(lower) == D, "The 'lower' property must have one value per dimension of the domain."
assert len(upper) == D, "The 'upper' property must have one value per dimension of the domain."
self._fitted_method = self._method.fit(self)
assert self.bandwidth.shape == (D, D), "The bandwidth should have a shape of ({0},{0}) (actual: {1})".format(D, self.bandwidth.shape)
assert self.covariance.shape == (D, D), "The covariance should have a shape of ({0},{0}) (actual: {1})".format(D, self.covariance.shape)
self._fitted = True
def evaluate(self, points, out=None):
if not self.fitter:
if not self.fitted:
self.fit()
points = np.asanyarray(points)
real_shape = points.shape
......
......@@ -257,6 +257,17 @@ class LocalPolynomialKernel1D(RegressionKernelMethod):
def __init__(self, q=3):
self._q = q
@property
def q(self):
'''
Degree of the fitted polynomials
'''
return self._q
@q.setter
def q(self, val):
self._q = int(val)
def fit(self, reg):
assert reg.dim == 1, "This method can only be used with 1D data"
if self.q == 0:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment