|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectbe.hogent.tarsos.util.histogram.Histogram
public class Histogram
A histogram is defined by a start value, a stop value and a number of classes. The 'key' of a class is the middle of the class. E.g. the keys of a histogram that starts at 0, stops at 5 and has 5 classes are {0.5,1.5,2.5,3.5,4.5}. The intervals for each key are {[0,1[;[1,2[;[2,3[;[3,4];[4,5[} with [0,1[ meaning the interval between 0 inclusive and 1 exclusive.
The histogram uses a red and black tree as underlying structure: Search, insert and delete are O(LOG n). The tree keeps the keys in order and makes iteration (in order) easy. Optimization is possible by replacing the tree with arrays.
The histogram uses doubles as key values. Java doubles are prone to rounding
errors. To prevent rounding errors the keys are rounded to a predefined
number of decimals. The number can be found in PRECISION_FACTOR
.
E.g. if PRECISION_FACTOR
is 10000 then the number of significant
decimals is 4; the minimum classWidth is 0.0001.
Constructor Summary | |
---|---|
Histogram(double startVal,
double stopVal,
int totalClasses)
Create a Histogram with a certain number of classes with values in the range ]start - classWidht / 2, stop + classWidth / 2 [ if
the histogram wraps otherwise values outside the range are mapped to
values inside using a modulo calculation. |
|
Histogram(double startVal,
double stopVal,
int totalClasses,
boolean wrapping)
Create a Histogram with a certain number of classes with values in the range ]start - classWidht / 2, stop + classWidth / 2 [ if
the histogram wraps otherwise values outside the range are mapped to
values inside using a modulo calculation. |
|
Histogram(double startVal,
double stopVal,
int totalClasses,
boolean wrapping,
boolean ignoreOutsideRange)
Create a Histogram with a certain number of classes with values in the range ]start - classWidht / 2, stop + classWidth / 2 [ if
the histogram wraps otherwise values outside the range are mapped to
values inside using a modulo calculation. |
|
Histogram(Histogram original)
Creates a new, empty histogram using the same parameters of the original histogram. |
Method Summary | |
---|---|
Histogram |
add(double value)
Adds a value to the Histogram. |
Histogram |
add(Histogram other)
Calculates the sum of two histograms. |
Histogram |
add(Histogram other,
int offset)
Calculates the sum of two histograms. |
Histogram |
addToEachBin(long value)
Adds a number of items to each bin. |
Histogram |
baselineHistogram()
Searches the minimum number of items in a bin and subtracts all bins with this value. |
void |
clear()
Sets each bin to 0. |
Histogram |
clone()
|
double |
correlation(Histogram otherHistogram)
Return the correlation of this histogram with another one. |
double |
correlation(Histogram otherHistogram,
CorrelationMeasure correlationMeasure)
Return the correlation of this histogram with another one. |
double |
correlationWithDisplacement(int displacement,
Histogram otherHistogram)
|
double |
correlationWithDisplacement(int displacement,
Histogram otherHistogram,
CorrelationMeasure correlationMeasure)
|
void |
displace(int displacement)
|
int |
displacementForOptimalCorrelation(Histogram otherHistogram)
|
int |
displacementForOptimalCorrelation(Histogram otherHistogram,
CorrelationMeasure correlationMeasure)
Returns the number of classes the other histogram needs to be displaced to get optimal correlation with this histogram. |
void |
export(java.lang.String fileName)
Export the histogram data as a plain text file. |
void |
exportMatLab(java.lang.String fileName)
Export the histogram data as a matlab text file. |
Histogram |
gaussianSmooth(double standardDeviation)
Smooth the histogram using Gaussians. |
long |
getAbsoluteSumFreq()
Returns the sum of all frequencies. |
double |
getClassWidth()
|
long |
getCount(double value)
Returns the number of values = v. |
long |
getCountForClass(int i)
Returns the number of items in class with index bufferCount. |
long |
getCumFreq(java.lang.Double v)
Returns the cumulative frequency of values less than or equal to v. |
double |
getCumPct(java.lang.Double v)
Returns the cumulative percentage of values less than or equal to v (as a proportion between 0 and 1). |
double |
getEntropy()
Returns the entropy of the histogram. |
double |
getKeyForClass(int i)
Returns the key for class with index bufferCount. |
long |
getMaxBinCount()
|
double |
getMean()
Calculates the mean count of each bin. |
double |
getMedian()
Calculates the mean count of each bin. |
int |
getNumberOfClasses()
|
double |
getPct(java.lang.Double v)
Returns the percentage of values that are equal to v (as a proportion between 0 and 1). |
double |
getStart()
The starting value is not the same as the first key. |
double |
getStop()
The stopping value is not the same as the last key. |
long |
getSumFreq()
Returns the sum of all frequencies (bin counts). |
Histogram |
invert()
Inverts this histograms. |
boolean |
isWrapped()
|
java.util.Set<java.lang.Double> |
keySet()
|
Histogram |
max(Histogram other)
Takes the maximum of the bin value in each histogram and changes the current histogram to this maximum value. |
static Histogram |
mean(java.util.List<Histogram> histograms)
Calculates a histogram mean of a list of histograms. |
Histogram |
multiply(double factor)
Multiplies each class (bin) count with a factor. |
Histogram |
normalize()
Normalizes the peaks in a histogram. |
void |
plot(java.lang.String fileName,
java.lang.String title)
Plots the histogram to a x y plot. |
void |
plotCorrelation(Histogram otherHistogram,
CorrelationMeasure correlationMeasure,
java.lang.String fileName,
java.lang.String title)
|
Histogram |
raise(double exponent)
Raises each class count to the power of exponent. |
void |
setCount(double value,
long count)
Sets the number of values for a key (bin) The value is automatically mapped to a key. |
Histogram |
smooth(boolean isWeighted,
int k)
Computes a smoothed version of the histogram. |
Histogram |
subtract(Histogram other)
Subtracts two histograms. |
java.lang.String |
toString()
Return a string representation of this histogram. |
java.lang.String |
toString(boolean asciiArt)
Returns a string representation of the histogram. |
protected void |
valueAddedHook(double value)
A hook to intercept added values. |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public Histogram(double startVal, double stopVal, int totalClasses, boolean wrapping, boolean ignoreOutsideRange)
Create a Histogram with a certain number of classes with values in the
range ]start - classWidht / 2, stop + classWidth / 2 [
if
the histogram wraps otherwise values outside the range are mapped to
values inside using a modulo calculation.
startVal
- the starting value of the histogram. The starting value is not
the same as the first class middle. The starting value is
equal to the first class middle - classWidth / 2
stopVal
- the stopping value of the histogram. The stopping value is not
the same as the last class middle. The stopping value is equal
to the last class middle + classWidth / 2
totalClasses
- the number of classes between the starting and stopping
values. Also defines the classWidth.wrapping
- indicates if the histogram wraps around the edges. More
formal: If the histogram wraps values outside the range
]start - classWidht / 2, stop + classWidth / 2 [
are mapped to values inside the range using a modulo
calculation.ignoreOutsideRange
- if true
values outside the valid range are
ignored. Otherwise if a value outside the valid range is added
an IllegalArgumentException is thrown.public Histogram(Histogram original)
original
- the original histogrampublic Histogram(double startVal, double stopVal, int totalClasses)
Create a Histogram with a certain number of classes with values in the
range ]start - classWidht / 2, stop + classWidth / 2 [
if
the histogram wraps otherwise values outside the range are mapped to
values inside using a modulo calculation.
startVal
- the starting value of the histogram. The starting value is not
the same as the first class middle. The starting value is
equal to the first class middle - classWidth / 2
stopVal
- the stopping value of the histogram. The stopping value is not
the same as the last class middle. The stopping value is equal
to the last class middle + classWidth / 2
totalClasses
- the number of classes between the starting and stopping
values. Also defines the classWidth.public Histogram(double startVal, double stopVal, int totalClasses, boolean wrapping)
Create a Histogram with a certain number of classes with values in the
range ]start - classWidht / 2, stop + classWidth / 2 [
if
the histogram wraps otherwise values outside the range are mapped to
values inside using a modulo calculation.
startVal
- the starting value of the histogram. The starting value is not
the same as the first class middle. The starting value is
equal to the first class middle - classWidth / 2
stopVal
- the stopping value of the histogram. The stopping value is not
the same as the last class middle. The stopping value is equal
to the last class middle + classWidth / 2
totalClasses
- the number of classes between the starting and stopping
values. Also defines the classWidth.wrapping
- indicates if the histogram wraps around the edges. More
formal: If the histogram wraps values outside the range
]start - classWidht / 2, stop + classWidth / 2 [
are mapped to values inside the range using a modulo
calculation.Method Detail |
---|
public final double getKeyForClass(int i)
i
- a class index. If bufferCount lays outside the interval
[0,getNumberOfClasses()[
it is mapped to a value
inside the interval using a modulo calculation.
public final long getCountForClass(int i)
i
- A class index. If bufferCount lays outside the interval
[0,getNumberOfClasses()[
it is mapped to a value
inside the interval using a modulo calculation.
public final java.util.Set<java.lang.Double> keySet()
public final Histogram add(double value)
value
- The value to add.
java.lang.IllegalArgumentException
- when the value is not in the range of the histogram.protected void valueAddedHook(double value)
value
- The value addedpublic final long getCount(double value)
value
- the value to lookup.
public final void setCount(double value, long count)
value
- the value mapped to a key of the class to set the count for.count
- the number of items in the binpublic final double getClassWidth()
public final int getNumberOfClasses()
public final double getStart()
firstKey - classWidth / 2.0
public double getStop()
lastKey + classWidth / 2.0
public boolean isWrapped()
true
if values outside the interval are wrapped,
false
otherwise.public long getCumFreq(java.lang.Double v)
Returns 0 if v is not comparable to the values set.
Uses code from Apache Commons Math" licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.
v
- the value to lookup.
public double getCumPct(java.lang.Double v)
Returns Double.NaN
if no values have been added.
v
- the value to lookup
public long getSumFreq()
getAbsoluteSumFreq()
public long getAbsoluteSumFreq()
public double getPct(java.lang.Double v)
Returns Double.NaN
if no values have been added.
v
- the value to lookup
public double getEntropy()
The histogram entropy is defined to be the negation of the sum of the products of the probability associated with each bin with the base-2 LOG of the probability.
Uses code from https://jai-core.dev.java.net/ The source code for the core Java Advanced Imaging API reference implementation is licensed under the Java Research License (JRL) for non-commercial use. The JRL allows users to download, build, and modify the source code in the jai-core project for research use, subject to the terms of the license.
public double getMean()
public double getMedian()
public java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String toString(boolean asciiArt)
Uses code from Apache Commons Math" licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.
asciiArt
- If true it generates an ascii representation of a histogram,
otherwise it generates a frequency table
public Histogram normalize()
Changes the current histogram and returns it so it is possible to chain
modifications. E.g. histo.normalize().addToEachBin(10)
public Histogram addToEachBin(long value)
Changes the current histogram and returns it so it is possible to chain
modifications. E.g. histo.normalize().addToEachBin(10)
value
- the number of items to add.
public Histogram baselineHistogram()
* * * * * * * * * * * * * => * * * ------- -------
Changes the current histogram and returns it so it is possible to chain
modifications. E.g. histo.normalize().addToEachBin(10)
public Histogram add(Histogram other)
Changes the current histogram and returns it so it is possible to chain
modifications. E.g.histo.normalize().addToEachBin(10)
other
- The other histogram
public Histogram add(Histogram other, int offset)
Changes the current histogram and returns it so it is possible to chain
modifications. E.g.histo.normalize().addToEachBin(10)
other
- The other histogramoffset
- The offset.
public Histogram max(Histogram other)
other
- Another histogram with the same number of bins.
public Histogram subtract(Histogram other)
Changes the current histogram and returns it so it is possible to chain
modifications. E.g.histo.normalize().addToEachBin(10)
other
- The other histogram
public Histogram invert()
Changes the current histogram and returns it so it is possible to chain
modifications. E.g.histo.normalize().addToEachBin(10)
public Histogram multiply(double factor)
Changes the current histogram and returns it so it is possible to chain
modifications. E.g. histo.normalize().addToEachBin(10)
factor
- the factor to multiply each bin value with.
public Histogram raise(double exponent)
Changes the current histogram and returns it so it is possible to chain
modifications. E.g. histo.normalize().addToEachBin(10)
exponent
- The exponent to raise each bincount with.
public Histogram clone() throws java.lang.CloneNotSupportedException
clone
in class java.lang.Object
java.lang.CloneNotSupportedException
public static Histogram mean(java.util.List<Histogram> histograms)
histograms
- a list of histograms
public Histogram smooth(boolean isWeighted, int k)
The histogram is smoothed by averaging over a moving window of a size
specified by the method parameter: if the value of the parameter is
Changes the current histogram and returns it so it is possible to chain
modification e.g. histo.normalize().addToEachBin(10)
Uses code from https://jai-core.dev.java.net/ The source code for the core Java Advanced Imaging API reference implementation is licensed under the Java Research License (JRL) for non-commercial use. The JRL allows users to download, build, and modify the source code in the jai-core project for research use, subject to the terms of the license.
isWeighted
- Whether bins will be weighted using a triangular weighting
scheme favoring bins near the central bin.k
- The smoothing parameter which must be non-negative or an
IllegalArgumentException
will be thrown. If zero,
the histogram object will be returned with no smoothing
applied.
public Histogram gaussianSmooth(double standardDeviation)
Each band of the histogram is smoothed by discrete convolution with a kernel approximating a Gaussian impulse response with the specified standard deviation.
Changes the current histogram and returns it so it is possible
to chain modification e.g.
histo.normalize().addToEachBin(10)
Uses code from https://jai-core.dev.java.net/ The source code for the core Java Advanced Imaging API reference implementation is licensed under the Java Research License (JRL) for non-commercial use. The JRL allows users to download, build, and modify the source code in the JAI-core project for research use, subject to the terms of the license.
standardDeviation
- The standard deviation of the Gaussian smoothing kernel which
must be non-negative or an
IllegalArgumentException
will be thrown. If zero,
the histogram object will be returned with no smoothing
applied.
public int displacementForOptimalCorrelation(Histogram otherHistogram)
public void displace(int displacement)
public double correlationWithDisplacement(int displacement, Histogram otherHistogram, CorrelationMeasure correlationMeasure)
public double correlationWithDisplacement(int displacement, Histogram otherHistogram)
public double correlation(Histogram otherHistogram, CorrelationMeasure correlationMeasure)
otherHistogram
- correlationMeasure
-
public double correlation(Histogram otherHistogram)
INTERSECTION
correlation
measure.
otherHistogram
- the other histogram
public int displacementForOptimalCorrelation(Histogram otherHistogram, CorrelationMeasure correlationMeasure)
otherHistogram
- The other histogram.correlationMeasure
- The correlation strategy.
public void plotCorrelation(Histogram otherHistogram, CorrelationMeasure correlationMeasure, java.lang.String fileName, java.lang.String title)
public void plot(java.lang.String fileName, java.lang.String title)
fileName
- The file is saved in PNG file format so the fileName should
end on PNG.title
- The title of the histogram. Use an empty string or null for an
empty title.public final void export(java.lang.String fileName)
fileName
- Where to save the text file.public final void exportMatLab(java.lang.String fileName)
fileName
- Where to save the matlab (.m) file.public final long getMaxBinCount()
public void clear()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |