Class StandardKernel1dShape
- java.lang.Object
-
- uk.ac.starlink.ttools.plot2.layer.StandardKernel1dShape
-
- All Implemented Interfaces:
Kernel1dShape
@Equality public abstract class StandardKernel1dShape extends java.lang.Object implements Kernel1dShape
Implementation class for Kernel1dShapes based on evaluating symmetric functions over a limited extent.- Since:
- 12 Mar 2015
- Author:
- Mark Taylor
-
-
Field Summary
Fields Modifier and Type Field Description static StandardKernel1dShape
COS
Cosine kernel shape.static StandardKernel1dShape
COS2
Cosine squared kernel shape.static Kernel1d
DELTA
Delta function kernel.static StandardKernel1dShape
EPANECHNIKOV
Epanechnikov (parabola) kernel shape.static StandardKernel1dShape
LINEAR
Linear (triangular) kernel shape.static StandardKernel1dShape
SQUARE
Rectangular kernel shape.
-
Constructor Summary
Constructors Modifier Constructor Description protected
StandardKernel1dShape(java.lang.String name, java.lang.String description, double normExtent, boolean isSquare)
Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description Kernel1d
createFixedWidthKernel(double width)
Creates a fixed width kernel with a given nominal width.Kernel1d
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 numberk
of samples is found.Kernel1d
createMeanKernel(double width)
Creates an averaging kernel with a given nominal fixed width.static Kernel1d
createSymmetricMeanKernel(double[] levels, boolean isSquare)
Creates a symmetric averabing kernel based on a fixed array of function values.static Kernel1d
createSymmetricNormalisedKernel(double[] levels, boolean isSquare)
Creates a symmetric normalised kernel based on a fixed array of function values.static StandardKernel1dShape
createTruncatedGaussian(double truncSigma)
Returns a kernel shape based on the Gaussian function with truncation at a given number of standard deviations.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.java.lang.String
getDescription()
Returns a short description for this shape.java.lang.String
getName()
Returns a one-word name for this shape.double
getNormalisedExtent()
Returns the extent of a kernel with this shape of unit nominal width.static Kernel1dShape[]
getStandardOptions()
Returns an array of the generally recommended kernel shape options.boolean
isSquare()
Indicates whether this shape has features which are intentionally non-smooth and should be portrayed as such.java.lang.String
toString()
-
-
-
Field Detail
-
SQUARE
public static final StandardKernel1dShape SQUARE
Rectangular kernel shape.
-
LINEAR
public static final StandardKernel1dShape LINEAR
Linear (triangular) kernel shape.
-
EPANECHNIKOV
public static final StandardKernel1dShape EPANECHNIKOV
Epanechnikov (parabola) kernel shape.
-
COS
public static final StandardKernel1dShape COS
Cosine kernel shape.
-
COS2
public static final StandardKernel1dShape COS2
Cosine squared kernel shape.
-
DELTA
public static final Kernel1d DELTA
Delta function kernel. Convolution of a function with this kernel leaves it unaffected.
-
-
Constructor Detail
-
StandardKernel1dShape
protected StandardKernel1dShape(java.lang.String name, java.lang.String description, double normExtent, boolean isSquare)
Constructor.- Parameters:
name
- kernel shape namedescription
- short descriptionnormExtent
- kernel extent for unit nominal widthisSquare
- true iff kernel is considered non-smooth
-
-
Method Detail
-
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 ofx
out 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 forx
greater 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
public java.lang.String getName()
Returns a one-word name for this shape.- Specified by:
getName
in interfaceKernel1dShape
- Returns:
- name
-
getDescription
public java.lang.String getDescription()
Returns a short description for this shape.- Specified by:
getDescription
in interfaceKernel1dShape
- Returns:
- description
-
createFixedWidthKernel
public Kernel1d createFixedWidthKernel(double width)
Description copied from interface:Kernel1dShape
Creates 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:
createFixedWidthKernel
in interfaceKernel1dShape
- Parameters:
width
- half-width- Returns:
- new kernel
-
createMeanKernel
public Kernel1d createMeanKernel(double width)
Description copied from interface:Kernel1dShape
Creates 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:
createMeanKernel
in interfaceKernel1dShape
- Parameters:
width
- half-width- Returns:
- new kernel
-
createKnnKernel
public Kernel1d createKnnKernel(double k, boolean isSymmetric, int minWidth, int maxWidth)
Description copied from interface:Kernel1dShape
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 numberk
of 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:
createKnnKernel
in 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
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
getStandardOptions
public static Kernel1dShape[] getStandardOptions()
Returns an array of the generally recommended kernel shape options.- Returns:
- kernel shape options
-
createTruncatedGaussian
public static StandardKernel1dShape createTruncatedGaussian(double truncSigma)
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
public static Kernel1d createSymmetricNormalisedKernel(double[] levels, boolean isSquare)
Creates a symmetric normalised kernel based on a fixed array of function values. Thelevels
array 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
public static Kernel1d createSymmetricMeanKernel(double[] levels, boolean isSquare)
Creates a symmetric averabing kernel based on a fixed array of function values. Thelevels
array 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
-
-