public class Histogram extends VectorType implements Histogramming, AsciiComm
The dependent variable of Histogram is the histogrammed data. The independent variable is the set of delimiters of the intervals to which the dependent values relate. The convention is that the dependent data value whose index is j is defined on the interval between the independent data values (delimiters) with indices j and j + 1. The delimiters must be monotonically increasing but they can define intervals of variable length. /p>
The GraphType data model requires that the number of points in the independent and dependent variable should be the same. For a histogram, however, the highest delimiter (the upper end of the last interval) must have an index value one larger than the last index of the dependent data. To solve this problem, Histogram adopts the convention that the independent variable stores all the delimiters except the last one. This is stored in the parameter lastDelimiter.
Some histograms may be binned in such a way that the first or the last interval might be infinite; this happens for example if the data point represents the number of times a variable exceeds a certain value x (last interval stretches from x to infinity). In such cases Histogram stores the value Double.NEGATIVE_INFINITY in the first delimiter, and/or the value Double.POSITIVE_INFINITY in the parameter lastDelimiter, as appropriate. Histogram implements tests to determine if these infinite values are present, and it implements a method to return finite values for such delimiters, in order to aid graphing the data.
VectorType
,
Histogramming
,
GraphType
,
Triplet
,
Serialized FormModifier and Type | Field and Description |
---|---|
java.lang.String |
binLabel
(Parameter that is kept for consistency with previous versions, but which is obsolete.
|
double[] |
data
(Parameter that is kept for consistency with previous versions, but which is obsolete.
|
double[] |
delimiters
(Parameter that is kept for consistency with previous versions, but which is obsolete.
|
java.lang.String |
hLabel
(Parameter that is kept for consistency with previous versions, but which is obsolete.
|
x, xlabel, y, ylabel
NOT_CONNECTED, NOT_READY, OUT_OF_RANGE
Constructor and Description |
---|
Histogram()
Creates a new Histogram, setting its state to false
|
Histogram(double[] delims,
double[] values)
Creates a Histogram with given delimiter array and value array.
|
Histogram(double[] delims,
double[] values,
double last)
Creates a Histogram with given delimiter array, value array, and an explicitly given last delimiter.
|
Histogram(int nB,
int nH,
java.lang.String labelB,
java.lang.String labelH)
(Obsolete constructor kept for compatibility with previous version of Histogram.
|
Histogram(java.lang.String labelB,
java.lang.String labelH,
double[] bs,
double[] hv)
(Obsolete constructor kept for compatibility with previous version.
|
Modifier and Type | Method and Description |
---|---|
int |
bsize()
(Obsolete method required for compatibility with previous versions.)
|
protected void |
copyData(TrianaType source)
Copies the data held in this object, by value not reference.
|
TrianaType |
copyMe()
This is one of the most important methods of Triana data.
|
protected void |
copyParameters(TrianaType source)
Copies parameters from the source to the current object.
|
boolean |
equals(TrianaType obj)
Determines whether the argument TrianaType is equal to the current Histogram.
|
void |
extendWithZeros(int newLength,
boolean front)
Extends the histogram data (dependent data) to a longer set by padding with zeros.
|
double[] |
getDelimiterArray(int dim)
Returns the whole set of delimiters (including the last one) for the intervals of the histogram in the given
dimension (independent variable).
|
double[] |
getDelimiterMidpoints(int dim)
Returns x-axis values for graphing a histogram with a standard grapher that expects the same number of x-values
as y-values.
|
double[] |
getDelimiterMidpointsLog10(int dim)
Returns logarithmic x-axis values for graphing a histogram with a standard grapher that expects the same number
of x-values as y-values.
|
Triplet |
getDelimiterTriplet(int dim)
Returns a Triplet that describes the set of delimiters in the given dimension.
|
double[] |
getFiniteDelimiters(int dim)
Returns an entire set of delimiters in finite positions for the intervals of the histogram in the given dimension
(independent variable).
|
double |
getFirstDelimiter()
Return value of the first delimiter (the left-most delimiter).
|
double[] |
getIndependentScaleImag(int dim)
Returns null because the data is real.
|
double[] |
getIndependentScaleReal(int dim)
Returns the independent data scaled the way they should be graphed.
|
double |
getLastDelimiter()
Return value of lastDelimiter (the right-most delimiter).
|
int |
hsize()
(Obsolete method required for compatibility with previous versions.)
|
void |
inputFromStream(java.io.BufferedReader dis)
Used when Triana types want to be able to receive ASCII data from the output of other programs.
|
void |
interpolateZeros(int factor,
boolean before)
Overrides the method of VectorType, which inserts zeros between existing elements of the data set, to do nothing
at all in Histogram.
|
boolean |
isCompatible(TrianaType obj)
Tests the argument object to determine if it makes sense to perform arithmetic operations between it and the
current object.
|
boolean |
isUnboundedIntervalAbove(int dim)
Returns true if the last interval in the given dimension is unbounded above, i.e.
|
boolean |
isUnboundedIntervalBelow(int dim)
Returns true if the first interval in the given dimension is unbounded below, i.e.
|
boolean |
isUniformDelimiterSet(int dim)
Returns true if the set of delimiters in the given dimension is uniform, false otherwise.
|
void |
outputToStream(java.io.PrintWriter dos)
Used when Triana types want to be able to send ASCII data to other programs using strings.
|
void |
resetHData(double[] hdata)
(Obsolete method required for compatibility with previous versions.)
|
void |
setDefaultAxisLabelling()
Added by I.
|
void |
setDelimiters(double[] delims,
int dim)
Sets the independent variable data array and the parameter lastDelimiter from the data held in the given
array.
|
void |
setDelimiters(Triplet del,
int dim)
Sets the delimiters associated with the given dimension to values given by the given Triplet.
|
void |
setHistogramBinLabel(java.lang.String labelB)
(Obsolete method required for compatibility with previous versions.)
|
void |
setHistogramDataLabel(java.lang.String labelH)
(Obsolete method required for compatibility with previous versions.)
|
void |
setLastDelimiter(double ld)
Set value of lastDelimiter (the right-most delimiter) to the given value.
|
protected void |
updateObsoletePointers() |
getData, getDataImag, getDataReal, getGraph, getGraphImag, getGraphReal, getScale, getScaleImag, getScaleReal, getXArray, getXImag, getXReal, getXTriplet, initialiseData, initialiseDataComplex, initialiseDataReal, isTriplet, isUniform, length, setData, setData, setDataImag, setDataReal, setX, setX, setX, setXImag, setXReal, size, testDataModel
add, addToTitle, convertDependentDataArraysToBytes, convertDependentDataArraysToDoubles, convertDependentDataArraysToFloats, convertDependentDataArraysToInts, convertDependentDataArraysToLongs, convertDependentDataArraysToShorts, copyLabels, divide, equals, getDataArrayClass, getDataArrayImag, getDataArrayImag, getDataArrayImagAsBytes, getDataArrayImagAsDoubles, getDataArrayImagAsFloats, getDataArrayImagAsInts, getDataArrayImagAsLongs, getDataArrayImagAsShorts, getDataArrayReal, getDataArrayReal, getDataArrayRealAsBytes, getDataArrayRealAsDoubles, getDataArrayRealAsFloats, getDataArrayRealAsInts, getDataArrayRealAsLongs, getDataArrayRealAsShorts, getDataArrayTypeNames, getDependentLabels, getDependentVariableDimensions, getDependentVariables, getDimensionLengths, getDimensionLengths, getGraphArrayImag, getGraphArrayImagLog10, getGraphArrayReal, getGraphArrayRealLog10, getIndependentArrayImag, getIndependentArrayReal, getIndependentLabels, getIndependentScaleImagLog10, getIndependentScaleRealLog10, getIndependentTriplet, getIndependentVariables, getLabels, getLabelsColumn, getTitle, isArithmeticArray, isArithmeticData, isCompatible, isDependentComplex, isIndependentComplex, isPrimitiveArray, isPrimitiveData, isTriplet, isUniform, maxDependentGraphingValuesImag, maxDependentGraphingValuesReal, maxDependentVariablesImag, maxDependentVariablesReal, maxIndependentScalesImag, maxIndependentScalesReal, maxIndependentVariablesImag, maxIndependentVariablesReal, minDependentGraphingValuesImag, minDependentGraphingValuesReal, minDependentVariablesImag, minDependentVariablesReal, minIndependentScalesImag, minIndependentScalesReal, minIndependentVariablesImag, minIndependentVariablesReal, multiply, resetDependent, resetIndependent, restrictToSubdomain, restrictToSubdomain, setDataArrayImag, setDataArrayReal, setDependentLabels, setDependentVariableDimensions, setDimensionLengths, setDimensionLengths, setDimensions, setIndependentArrayImag, setIndependentArrayReal, setIndependentLabels, setIndependentTriplet, setIndependentTriplet, setLabels, setTitle, subtract
containerSize, dataExists, deleteFromContainer, getDataContainer, getFromContainer, getSequenceNumber, insertIntoContainer, inspectDataContainer, setDataContainer, setSequenceNumber
public java.lang.String binLabel
The bin-axis (independent variable) label. Must be kept up-to-date with GraphType.independentLabels.
public java.lang.String hLabel
The h-axis (dependent variable) label. Must be kept up-to-date with GraphType.dependentLabels.
public double[] delimiters
The interval delimiter data. It is not identical with the GraphType independent variable, since this array contains the last delimiter, which is stored as the parameter lastDelimiter.
public double[] data
The histogram data. Must be kept up-to-date with the dependent variable.
public Histogram()
public Histogram(double[] delims, double[] values)
delims
- An array containing all the delimiters, including the lastvalues
- The array of histogram datapublic Histogram(double[] delims, double[] values, double last)
delims
- An array containing all the delimiters, including the lastvalues
- The array of histogram datalast
- The last (greatest) delimiterpublic Histogram(int nB, int nH, java.lang.String labelB, java.lang.String labelH)
Creates a new Histogram of a given size, with given labels for the intervals and histogram values. It allocates storage for the data vectors, but only assigns values to possible infinite end delimiters. This follows the obsolete algorithm of the earlier version. First, if the number of delimiters nB is one less than the number of histogram values nH, the first interval is assumed to start at negative infinity and the final one to end at positive infinity. Second, if nB equals nH, then only the final interval is assumed infinite. If nB is one larger than nH then all intervals are of finite size. If nB and nH do not satisfy one of these conditions, then an empty Histogram is created.
nB
- the number of bin delimiter values.nH
- the number of histogram values.labelB
- the label for the bin values.labelH
- the label for the histogram values.public Histogram(java.lang.String labelB, java.lang.String labelH, double[] bs, double[] hv)
Creates a new Histogram for given values of the histogram and bin labels, with references to data for the bin delimiters and the histogram values, and with a description.
Normally the given delimiter array bs should have length one greater than that of the given histogram array hv. For compatibility with previous versions, however, bs is also allowed to have length equal to or one less than that of hv. The algorithm for constructing the delimiter set is given in the previous constructor.
labelB
- the bin label.labelH
- the histogram axis label.bs
- the bin-delimiter data in an array of doubleshv
- the histogram data in an array of doublespublic void setDefaultAxisLabelling()
setDefaultAxisLabelling
in class GraphType
public double getLastDelimiter()
public void setLastDelimiter(double ld)
public double getFirstDelimiter()
public double[] getDelimiterArray(int dim)
getDelimiterArray
in interface Histogramming
dim
- The index of the independent variable being queried, ignored herepublic double[] getFiniteDelimiters(int dim)
dim
- The index of the independent variable being queried, ignored herepublic Triplet getDelimiterTriplet(int dim)
getDelimiterTriplet
in interface Histogramming
dim
- The index of the independent variable being queried, ignored hereTriplet
public boolean isUniformDelimiterSet(int dim)
isUniformDelimiterSet
in interface Histogramming
dim
- The index of the independent variable being queried, ignored herepublic void setDelimiters(double[] delims, int dim)
setDelimiters
in interface Histogramming
delims
- An array containing all the delimitersdim
- The index of the independent variable being queried, ignored hereTriplet
public void setDelimiters(Triplet del, int dim)
setDelimiters
in interface Histogramming
del
- The Triplet that generates the array of delimitersdim
- The index of the independent variable being queried, ignored in this caseTriplet
public boolean isUnboundedIntervalBelow(int dim)
isUnboundedIntervalBelow
in interface Histogramming
dim
- The index of the independent variable being queriedpublic boolean isUnboundedIntervalAbove(int dim)
isUnboundedIntervalAbove
in interface Histogramming
dim
- The index of the independent variable being queriedpublic int hsize()
This is identical to size() but provides a name that makes it clear that the number being returned is the number of histogram values, which is one less than the number of bin delimiters.
public int bsize()
Returns the number of non-infinite bin delimiters.
public void resetHData(double[] hdata)
Resets the independent variable array to the array whose reference is passed to it. This is identical to setData.
hdata
- the new histogram datapublic void setHistogramBinLabel(java.lang.String labelB)
Sets the graph label for the histogram intervals.
labelB
- The histogram bin axis labelpublic void setHistogramDataLabel(java.lang.String labelH)
Sets the graph label for the histogram values.
labelH
- The histogram value axis labelpublic double[] getIndependentScaleReal(int dim)
getIndependentScaleReal
in class GraphType
dim
- The independent dimension under considerationgetFiniteDelimiters(int)
public double[] getIndependentScaleImag(int dim)
getIndependentScaleImag
in class GraphType
dim
- The independent dimension under considerationpublic double[] getDelimiterMidpoints(int dim)
dim
- The independent dimension under considerationpublic double[] getDelimiterMidpointsLog10(int dim)
dim
- The independent dimension under considerationpublic void extendWithZeros(int newLength, boolean front)
If the new length is shorter than the old, nothing is done.
For a Histogram, the extra zeros must be accompanied by an equal number of extra delimiters. If the zeros are to be added at the beginning, then the first delimiter must be finite; if it is NEGATIVE_INFINITY then the method returns without doing anything and prints a warning. Otherwise, it simply uses the extension method of VectorType. If the zeros are to be added at the end, then the last delimiter must be finite; if it is POSITIVE_INFINITY then the method returns without doing anything and prints a warning. Otherwise, it must move the last delimiter's position. It does this by artificially defining a scratch VectorType data type to hold a set of one greater size that can be interpolated in the usual way, and then makes end adjustments.
Derived types should override this if necessary to provide for the correct handling of parameters and other special features.
extendWithZeros
in class VectorType
newLength
- The new length of the data setfront
- True if padding is at the front, false for padding at the backpublic void interpolateZeros(int factor, boolean before)
interpolateZeros
in class VectorType
factor
- The number of zeros per data point to be insertedbefore
- True if the zeros go before each point, false if afterpublic boolean isCompatible(TrianaType obj)
In Histogram, this method first tests for compatibility with superior classes, and then (if the input object is a Histogram) tests that the input has the same delimiters as the current object.
Classes derived from this should over-ride this method with further tests as appropriate. The over-riding method should normally have the first lines
boolean test = super.isCompatible( obj );followed by other tests. If other types not subclassed from GraphType or Const should be allowed to be compatible then other tests must be implemented.
isCompatible
in class VectorType
obj
- The data object to be compared with the current onepublic boolean equals(TrianaType obj)
This method must be over-ridden in derived types. In a derived type called xxx the method should begin
if ( !( obj instanceof xxx ) ) return false; if ( !isCompatible( obj ) ) return false;followed by tests that are specific to type xxx (testing its own parameters) and then as a last line
return super.equals( obj );This line invokes the other equals methods up the chain to GraphType. Each superior object tests its own parameters.
obj
- The object being testedpublic TrianaType copyMe()
To override, the programmer should not invoke the super.copyMe method. Instead, create an object of the current type and call methods copyData and copyParameters. If these have been written correctly, then they will do the copying. The code should createTool, for type YourType:
YourType y = null; try { y = (YourType)getClass().newInstance(); y.copyData( this ); y.copyParameters( this ); y.setLegend( this.getLegend() ); } catch (IllegalAccessException ee) { System.out.println("Illegal Access: " + ee.getMessage()); } catch (InstantiationException ee) { System.out.println("Couldn't be instantiated: " + ee.getMessage()); } return y;
The copied object's data should be identical to the original. The method here modifies only one item: a String indicating that the object was created as a copy is added to the description StringVector.
copyMe
in class VectorType
protected void copyData(TrianaType source)
protected void copyParameters(TrianaType source)
copyParameters
in class GraphType
source
- The object from which the copy is madepublic void outputToStream(java.io.PrintWriter dos) throws java.io.IOException
This method must be overridden in every subclass that defines new data or parameters. The overriding method should first call<
super.outputToStream(dos)to get output from superior classes, and then new parameters defined for the current subclass must be output. Moreover, subclasses that first dimension their data arrays must explicitly transfer these data arrays.
outputToStream
in interface AsciiComm
outputToStream
in class GraphType
dos
- The data output streamjava.io.IOException
public void inputFromStream(java.io.BufferedReader dis) throws java.io.IOException
This method must be overridden in every subclass that defines new data or parameters. The overriding method should first call
super.inputFromStream(dis)to get input from superior classes, and then new parameters defined for the current subclass must be input. Moreover, subclasses that first dimension their data arrays must explicitly transfer these data arrays.
inputFromStream
in interface AsciiComm
inputFromStream
in class GraphType
dis
- The data input streamjava.io.IOException
protected void updateObsoletePointers()
updateObsoletePointers
in class VectorType