| |
- adaptive_kde(dataset, width=None, symmetric=True, cov=None, wrapped=False, alpha=0.5, pilot=<class 'densityEstimation.NormalKDE'>, adaptive=<class 'densityEstimation.NormalKDE'>)
- Return a class 'adaptive' instance: the adaptive kernel density estimate.
Arguments dataset, width, symmetric, cov, and wrapped are those required for
KDE instantiation; alpha is the sensitivity parameter used in the local
width calculation from the pilot density estimate:
lambdai = [pilot_f(Xi)/g]^-alpha
with lambdai the local width of the kernel centered at vector Xi, where the
pilot desity is pilot_f(Xi), and log[g] = n^-1 SUM_i{log[pilot_f(Xi)]} (eq.
5.7 in Silverman 1986, Sec. 5.3, p.101). The kernels used in the pilot and
adaptive stages are respectively specified with arguments pilot and
adaptive, which expect the names of the corresponding classes; the global
width of both kernels is the same, specified with the width argument. The
overall procedure is described by (Silverman, 1986, Sec. 5.3); for more
details see KDE docstring.
Reference: Silverman, B.W. (1986). Density Estimation for Statistics and
Data Analysis. Chapman & Hall.
- gengrid(npoints, ranges, periodic=False)
- Return a Python itertools.product object representing a d-dimesional grid.
Note: This is a Python generator version of the grid function; another
difference with grid is that it lacks the functionality associated with the
axes argument (there is no such argument here).
npoints is a sequence with the number of points in each dimension. ranges
is a sequence of (min, max) pairs, with the min and max values in each
dimension (the order of values within a pair is irrelevant). The number of
dimensions, d, is len(npoints) (or len(ranges); ValueError is raised if
len(npoints)!=len(ranges)). For example:
npoints = (5, 3)
ranges = ([-10, 10], [-5, 5])
represents a system with d=2, where the first dimension or axis has values
in the [-10, 10] range, and the second axis in the [-5, 5]. 5 points are
requested from the first axis and 3 from the second; points are equally
spaced to make the grid, i.e.
Axis 1: [-10.0, -5.0, 0.0, 5.0, 10.0]
Axis 2: [-5.0, 0.0, 5.0]
The grid associated with the above axes is the matrix
-10, -10, -10, -5, -5, ..., 10 # from axis 1
-5, 0, 5, -5, 0, ..., 5 # from axis 2
The matrix columns are the multidimensional (in this example two-
dimensional) points in the grid. They are returned via a Python
itertools.product object, a generator that yields each point packed into a
tuple.
The optional argument periodic is a sequence with True/False for each axis;
if True, the last point in the corresponding axis is omitted. For example,
gengrid(npoints, ranges, (True, False)) is associated with a grid generated
from axes
Axis 1: [-10.0, -5.0, 0.0, 5.0]
Axis 2: [-5.0, 0.0, 5.0]
Alternatively, all axes can be given the same True or False periodic value
by setting periodic=True or periodic=False, respectively, i.e.,
gengrid(npoints, ranges, (True, True)) <-> gengrid(npoints, ranges, True)
gengrid(npoints, ranges, (False, False)) <-> gengrid(npoints, ranges, False)
- grid(npoints, ranges, periodic=False, axes=False)
- Return a cdsMatrix.CDSMatrix_double representing a d-dimesional grid.
npoints is a sequence with the number of points in each dimension. ranges
is a sequence of (min, max) pairs, with the min and max values in each
dimension (the order of values within a pair is irrelevant). The number of
dimensions, d, is len(npoints) (or len(ranges); ValueError is raised if
len(npoints)!=len(ranges)). For example:
npoints = (5, 3)
ranges = ([-10, 10], [-5, 5])
represents a system with d=2, where the first dimension or axis has values
in the [-10, 10] range, and the second axis in the [-5, 5]. 5 points are
requested from the first axis and 3 from the second; points are equally
spaced to make the grid, i.e.
Axis 1: [-10.0, -5.0, 0.0, 5.0, 10.0]
Axis 2: [-5.0, 0.0, 5.0]
The grid can be generated via grid(npoints, ranges), which, following the
above example, returns a cdsMatrix.CDSMatrix_double(2, 5*3) representing
[[-10, -10, -10, -5, -5, ..., 10] # axis 1
[ -5, 0, 5, -5, 0, ..., 5]] # axis 2
The optional argument periodic is a sequence with True/False for each axis;
if True, the last point in the corresponding axis is omitted. For example,
grid(npoints, ranges, (True, False)) returns a grid with
Axis 1: [-10.0, -5.0, 0.0, 5.0]
Axis 2: [-5.0, 0.0, 5.0]
Alternatively, all axes can be given the same True or False periodic value
by setting periodic=True or periodic=False, respectively, i.e.,
grid(npoints, ranges, (True, True)) <-> grid(npoints, ranges, True)
grid(npoints, ranges, (False, False)) <-> grid(npoints, ranges, False)
The axes may be obtained by setting argument axes=True, in which case the
function returns a tuple with the grid (the cdsMatrix.CDSMatrix_double)
as first element and the axes, packed into a list, as second element. For
example, grid(npoints, ranges, True, True) returns
(grid(npoints, ranges, True), [[-10.0, -5.0, 0.0, 5.0], [-5.0, 0.0]])
i.e., (the grid, [axis 1, axis 2]).
- wraparound(dataset, spectral_widths)
- Return an augmented dataset by adding shifted copies of it.
Impose a periodic or "wrap around" boundary condition on the dataset by
augmenting it via the addition of shifted copies of it (Silverman, 1986,
Sec. 2.10, p. 31, 32).
dataset is cdsMatrix.CDSMatrix_type(d, n) (type=int, double), where d is
the dimensionality and n the number of points (like in KDE instantiation).
For example, two 3D points with coordinates (1.0, 2.0, 3.0) and
(4.0, 5.0, 6.0) yield:
dataset = cdsMatrix.CDSMatrix_double(3, 2).fromList([[1.0, 4.0],
[2.0, 5.0],
[3.0, 6.0]])
After wrapping around the number of points is (3^d)n.
spectral_widths is a sequence with the size of the domain in each dimension.
For example, if dataset contains directions or angles defined within the
range [-pi, pi], the associated size in spectral_widths is 2pi. Sizes in
spectral_widths and dimensions in dataset are matched by offset: row i in
dataset corresponds to spectral_widths[i]; ValueError is raised if the
dimensionality of dataset and spectral_widths do not match.
Reference: Silverman, B.W. (1986). Density Estimation for Statistics and
Data Analysis. Chapman & Hall.
|