Class StandardKernel1dShape
java.lang.Object
uk.ac.starlink.ttools.plot2.layer.StandardKernel1dShape
- All Implemented Interfaces:
Kernel1dShape
Implementation class for Kernel1dShapes based on evaluating
symmetric functions over a limited extent.
- Since:
- 12 Mar 2015
- Author:
- Mark Taylor
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StandardKernel1dShapeCosine kernel shape.static final StandardKernel1dShapeCosine squared kernel shape.static final Kernel1dDelta function kernel.static final StandardKernel1dShapeEpanechnikov (parabola) kernel shape.static final StandardKernel1dShapeLinear (triangular) kernel shape.static final StandardKernel1dShapeRectangular kernel shape. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedStandardKernel1dShape(String name, String description, double normExtent, boolean isSquare) Constructor. -
Method Summary
Modifier and TypeMethodDescriptioncreateFixedWidthKernel(double width) Creates a fixed width kernel with a given nominal width.createKnnKernel(double k, boolean isSymmetric, int minWidth, int maxWidth) Creates an adaptive kernel that uses a K-nearest-neighbours algorithm to determine local smoothing width, so that the width of the kernel is determined by the distance (number of 1-pixel bins) within which the given numberkof samples is found.createMeanKernel(double width) Creates an averaging kernel with a given nominal fixed width.static Kernel1dcreateSymmetricMeanKernel(double[] levels, boolean isSquare) Creates a symmetric averabing kernel based on a fixed array of function values.static Kernel1dcreateSymmetricNormalisedKernel(double[] levels, boolean isSquare) Creates a symmetric normalised kernel based on a fixed array of function values.static StandardKernel1dShapecreateTruncatedGaussian(double truncSigma) Returns a kernel shape based on the Gaussian function with truncation at a given number of standard deviations.protected abstract doubleevaluate(double x) Returns the point value of the function defining this shape at a point a given absolute fraction of the nominal width from the center.Returns a short description for this shape.getName()Returns a one-word name for this shape.doubleReturns the extent of a kernel with this shape of unit nominal width.static Kernel1dShape[]Returns an array of the generally recommended kernel shape options.booleanisSquare()Indicates whether this shape has features which are intentionally non-smooth and should be portrayed as such.toString()
-
Field Details
-
SQUARE
Rectangular kernel shape. -
LINEAR
Linear (triangular) kernel shape. -
EPANECHNIKOV
Epanechnikov (parabola) kernel shape. -
COS
Cosine kernel shape. -
COS2
Cosine squared kernel shape. -
DELTA
Delta function kernel. Convolution of a function with this kernel leaves it unaffected.
-
-
Constructor Details
-
StandardKernel1dShape
-
-
Method Details
-
evaluate
protected abstract double evaluate(double x) Returns the point value of the function defining this shape at a point a given absolute fraction of the nominal width from the center. Calling this method for values ofxout of the range0<=x<=getNormalisedExtent()has an undefined effect; the function value is assumed symmetric and zero for larger absolute values.- Parameters:
x- normalised absolute distance in range 0..normExtent- Returns:
- function value at
x
-
getNormalisedExtent
public double getNormalisedExtent()Returns the extent of a kernel with this shape of unit nominal width. The value of theevaluate(x)method forxgreater than the value returned from this method is taken to be zero. -
isSquare
public boolean isSquare()Indicates whether this shape has features which are intentionally non-smooth and should be portrayed as such. This non-smoothness applies either within the extent or at its edge.- Returns:
- true iff there are non-smooth features that should be visible
-
getName
Returns a one-word name for this shape.- Specified by:
getNamein interfaceKernel1dShape- Returns:
- name
-
getDescription
Returns a short description for this shape.- Specified by:
getDescriptionin interfaceKernel1dShape- Returns:
- description
-
createFixedWidthKernel
Description copied from interface:Kernel1dShapeCreates a fixed width kernel with a given nominal width. The width is some kind of characteristic half-width in one direction of the smoothing function. It is in units of grid points (array element spacing). It would generally be less than or equal to the kernel's extent.- Specified by:
createFixedWidthKernelin interfaceKernel1dShape- Parameters:
width- half-width- Returns:
- new kernel
-
createMeanKernel
Description copied from interface:Kernel1dShapeCreates an averaging kernel with a given nominal fixed width. The 'convolution' it performs is not really a convolution, instead it's a sort of weighted moving average. This is a smoothing that's suitable for intensive quantities. Using proper convolution for intensive quantities like the mean or median is problematic if there may be blank values in the input array, since the smoothed value has to keep track of how many non-blank values it has encountered.- Specified by:
createMeanKernelin interfaceKernel1dShape- Parameters:
width- half-width- Returns:
- new kernel
-
createKnnKernel
Description copied from interface:Kernel1dShapeCreates an adaptive kernel that uses a K-nearest-neighbours algorithm to determine local smoothing width, so that the width of the kernel is determined by the distance (number of 1-pixel bins) within which the given numberkof samples is found.The nearest neighbour search may be symmetric or asymmetric. In the asymmetric case, the kernel width is determined separately for the positive and negative directions along the axis.
Minimum and maximum smoothing widths are also supplied as bounds on the smoothing width for the case that the samples are very dense or very spread out (the latter case covers the edge of the data region as well). If
minWidth==maxWidth, the result is a fixed-width kernel.- Specified by:
createKnnKernelin interfaceKernel1dShape- Parameters:
k- number of nearest neighbours included in the distance that characterises the smoothingisSymmetric- true for bidirectional KNN search, false for unidirectionalminWidth- minimum smoothing widthmaxWidth- maximum smoothing width- Returns:
- new kernel
-
toString
-
getStandardOptions
Returns an array of the generally recommended kernel shape options.- Returns:
- kernel shape options
-
createTruncatedGaussian
Returns a kernel shape based on the Gaussian function with truncation at a given number of standard deviations.- Parameters:
truncSigma- number of sigma at which to truncate the kernel- Returns:
- new kernel shape
-
createSymmetricNormalisedKernel
Creates a symmetric normalised kernel based on a fixed array of function values. Thelevelsarray gives a list of the values at x=0, 1 (and -1), 2 (and -2), ....- Parameters:
levels- kernel function values on 1d grid starting from 0isSquare- true iff the kernel is considered non-smooth- Returns:
- new kernel
-
createSymmetricMeanKernel
Creates a symmetric averabing kernel based on a fixed array of function values. Thelevelsarray gives a list of the values at x=0, 1 (and -1), 2 (and -2), ....- Parameters:
levels- kernel function values on 1d grid starting from 0isSquare- true iff the kernel is considered non-smooth- Returns:
- new kernel
-