Class 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
    • 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 number k 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()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • StandardKernel1dShape

        protected StandardKernel1dShape​(java.lang.String name,
                                        java.lang.String description,
                                        double normExtent,
                                        boolean isSquare)
        Constructor.
        Parameters:
        name - kernel shape name
        description - short description
        normExtent - kernel extent for unit nominal width
        isSquare - 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 of x out of the range 0<=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 the evaluate(x) method for x 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 interface Kernel1dShape
        Returns:
        name
      • getDescription

        public java.lang.String getDescription()
        Returns a short description for this shape.
        Specified by:
        getDescription in interface Kernel1dShape
        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 interface Kernel1dShape
        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 interface Kernel1dShape
        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 number k 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 interface Kernel1dShape
        Parameters:
        k - number of nearest neighbours included in the distance that characterises the smoothing
        isSymmetric - true for bidirectional KNN search, false for unidirectional
        minWidth - minimum smoothing width
        maxWidth - maximum smoothing width
        Returns:
        new kernel
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.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. The levels 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 0
        isSquare - 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. The levels 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 0
        isSquare - true iff the kernel is considered non-smooth
        Returns:
        new kernel