From 344e6cd97c1ff52121af116bf2902d5ca178e582 Mon Sep 17 00:00:00 2001 From: Per A Brodtkorb Date: Thu, 29 Dec 2016 15:25:23 +0100 Subject: [PATCH] Added inc property to _KDE class --- wafo/kdetools/kdetools.py | 44 ++++++++++++++++++++++--------------- wafo/kdetools/tests/data.py | 6 ++--- 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/wafo/kdetools/kdetools.py b/wafo/kdetools/kdetools.py index 3be3d19..56a75aa 100644 --- a/wafo/kdetools/kdetools.py +++ b/wafo/kdetools/kdetools.py @@ -71,6 +71,14 @@ class _KDE(object): self.xmax = xmax self.kernel = kernel if kernel else Kernel('gauss') + @property + def inc(self): + return self._inc + + @inc.setter + def inc(self, inc): + self._inc = inc + @property def dataset(self): return self._dataset @@ -121,21 +129,6 @@ class _KDE(object): def _check_xmax(self, xmax): return xmax - def get_args(self, xmin=None, xmax=None): - sxmin = self.xmin - if xmin is not None: - sxmin = np.minimum(xmin, sxmin) - - sxmax = self.xmax - if xmax is not None: - sxmax = np.maximum(xmax, sxmax) - - args = [] - inc = self.inc - for i in range(self.d): - args.append(np.linspace(sxmin[i], sxmax[i], inc)) - return args - def eval_grid_fast(self, *args, **kwds): """Evaluate the estimated pdf on a grid using fft. @@ -205,6 +198,21 @@ class _KDE(object): self._add_contour_levels(wdata) return wdata + def get_args(self, xmin=None, xmax=None): + sxmin = self.xmin + if xmin is not None: + sxmin = np.minimum(xmin, sxmin) + + sxmax = self.xmax + if xmax is not None: + sxmax = np.maximum(xmax, sxmax) + + args = [] + inc = self.inc + for i in range(self.d): + args.append(np.linspace(sxmin[i], sxmax[i], inc)) + return args + def eval_grid_fun(self, eval_grd, *args, **kwds): if len(args) == 0: args = self.get_args() @@ -1355,9 +1363,9 @@ def kreg_demo1(hs=None, fast=False, fun='hisj'): -0.08348306, 0.00812816, -0.00908206, 0.14528945, 0.02901065]) x = np.linspace(0, 1, N) - var_1 = 0.3 ** 2 - var_2 = 0.7 ** 2 - y0 = np.exp(-x ** 2 / (2 * var_1)) + 1.3*np.exp(-(x - 1) ** 2 / (2 * var_2)) + va_1 = 0.3 ** 2 + va_2 = 0.7 ** 2 + y0 = np.exp(-x ** 2 / (2 * va_1)) + 1.3*np.exp(-(x - 1) ** 2 / (2 * va_2)) y = y0 + ei kernel = Kernel('gauss', fun=fun) hopt = kernel.hisj(x) diff --git a/wafo/kdetools/tests/data.py b/wafo/kdetools/tests/data.py index 68ee9a3..bbf123f 100644 --- a/wafo/kdetools/tests/data.py +++ b/wafo/kdetools/tests/data.py @@ -3,7 +3,10 @@ Created on 29. des. 2016 @author: pab ''' +__all__ = ['DATA1D', 'DATA2D', 'DATA3D'] + # N = 20 +# import numpy as np # DATA1D = np.random.rayleigh(1, size=(N,)) # print(DATA1D.tolist()) DATA1D = [0.6493244636902034, 0.6562823794215175, 1.0905183896319681, @@ -35,6 +38,3 @@ DATA3D = [[0.932896, 0.89522635, 0.80636346, 1.32283371, 0.27125435, 1.66888649, 0.69036947, 0.99961448, 0.30657267, 0.98798713, 0.83298728, 1.83334948, 1.90144186, 1.25781913, 0.07122458, 2.42340852, 2.41342037, 0.87233305, 1.17537114, 1.69505988]] - -if __name__ == '__main__': - pass