public class KernelDensityEstimate
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
KernelDensityEstimate.Cosine |
static class |
KernelDensityEstimate.GaussianKernel
A Gaussian kernel function.
|
static interface |
KernelDensityEstimate.KDECorrelation |
static interface |
KernelDensityEstimate.Kernel
Defines a kernel.
|
static class |
KernelDensityEstimate.Overlap |
static class |
KernelDensityEstimate.RectangularKernel
A rectangular kernel function.
|
Modifier and Type | Field and Description |
---|---|
protected double[] |
accumulator |
protected KernelDensityEstimate.Kernel |
kernel |
Constructor and Description |
---|
KernelDensityEstimate(KernelDensityEstimate.Kernel kernel,
double[] accumulator) |
KernelDensityEstimate(KernelDensityEstimate.Kernel kernel,
int size) |
Modifier and Type | Method and Description |
---|---|
void |
add(double value)
Add the kernel to an accumulator for each value.
|
void |
add(KernelDensityEstimate other)
Adds a KDE to this accumulator
|
void |
clear()
Clears the data in the accumulator.
|
double |
correlation(KernelDensityEstimate other,
int positionsToShiftOther)
Calculate a correlation with another KernelDensityEstimate.
|
double[] |
getEstimate()
Returns the current estimate.
|
double |
getMaxElement() |
double[] |
getMedianFilteredEstimate(int medianFilterLength) |
double |
getSumFreq()
Returns the sum of all estimates in the accumulator.
|
double |
getValue(int index)
Return the value for the accumulator at a certain index.
|
KernelDensityEstimate |
map(int size)
Map the kernel density estimate to another size.
|
void |
max(KernelDensityEstimate other)
Takes the maximum of the value in the accumulator for two kde's.
|
static double |
median(double[] m) |
void |
normalize()
Sets the maximum value in accumulator to 1.0
|
void |
normalize(double newMaxvalue)
Sets a new maximum bin value.
|
double |
optimalCorrelation(KernelDensityEstimate.KDECorrelation correlationMeasure,
KernelDensityEstimate other)
Calculates the optimal correlation between two Kernel Density Estimates
by shifting and searching for optimal correlation.
|
double |
optimalCorrelation(KernelDensityEstimate other)
Calculates the optimal correlation between two Kernel Density Estimates
by shifting and searching for optimal correlation.
|
void |
pdfify()
Sets the area under the curve to 1.0.
|
void |
remove(double value)
Remove a value from the kde, removes a kernel at the specified position.
|
void |
shift(int shift)
Shift the accumulator x positions.
|
int |
shiftForOptimalCorrelation(KernelDensityEstimate.KDECorrelation correlationMeasure,
KernelDensityEstimate other)
Calculates how much the other KernelDensityEstimate needs to be shifted
for optimal correlation.
|
int |
shiftForOptimalCorrelation(KernelDensityEstimate other)
Calculates how much the other KernelDensityEstimate needs to be shifted
for optimal correlation.
|
int |
size() |
protected final double[] accumulator
protected final KernelDensityEstimate.Kernel kernel
public KernelDensityEstimate(KernelDensityEstimate.Kernel kernel, int size)
public KernelDensityEstimate(KernelDensityEstimate.Kernel kernel, double[] accumulator)
public void add(double value)
value
- The value to add.public void remove(double value)
value
- The value to remove.public void shift(int shift)
shift
- The number of positions the accumulator should be shifted.public double[] getEstimate()
public KernelDensityEstimate map(int size)
(1 2 4 9).map(2) = (5 11)
size
- The new size for the KDE.public double getValue(int index)
index
- The index.public int size()
public double getSumFreq()
public void normalize()
public void normalize(double newMaxvalue)
newMaxvalue
- The new maximum bin value.public double getMaxElement()
public void pdfify()
public void clear()
public void max(KernelDensityEstimate other)
other
- The other kde of the same size.public void add(KernelDensityEstimate other)
other
- The other KDE of the same size.public double correlation(KernelDensityEstimate other, int positionsToShiftOther)
Calculate a correlation with another KernelDensityEstimate. The index of the other estimates are shifted by a number which can be zero (or positive or negative). Beware: the index wraps around the edges.
This and the other KernelDensityEstimate should have the same size.
other
- The other estimate.positionsToShiftOther
- The number of positions to shift the estimate.public int shiftForOptimalCorrelation(KernelDensityEstimate other)
other
- The other KernelDensityEstimate.public double optimalCorrelation(KernelDensityEstimate other)
other
- The other KernelDensityEstimate.public double optimalCorrelation(KernelDensityEstimate.KDECorrelation correlationMeasure, KernelDensityEstimate other)
correlationMeasure
- other
- The other KernelDensityEstimate.public int shiftForOptimalCorrelation(KernelDensityEstimate.KDECorrelation correlationMeasure, KernelDensityEstimate other)
correlationMeasure
- other
- The other KernelDensityEstimate.public double[] getMedianFilteredEstimate(int medianFilterLength)
public static double median(double[] m)