Class P0D
- java.lang.Object
-
- All Implemented Interfaces:
- DoubleBufferConsumer, java.io.Serializable, java.lang.Cloneable
public class P0D extends DoubleArrayList implements java.io.Serializable
A container to hold data points in one dimension. All numbers are expected to be in double precision. It extends ArrayList and adds many new features for data manipulation. The class does not have graphical option (use H1D to show the data or methods of this class which transform P0D to a H1D histogram).This is a high-speed a small footprint container designed for numerical analysis.
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description P0D()
Construct an empty container with a titleP0D(double[] d)
Construct P0D from array;P0D(java.lang.String title)
Construct an empty container with a titleP0D(java.lang.String title, double[] d)
Create P0D from an array.P0D(java.lang.String title, P0D p0d)
Construct a copy from a P0D.P0D(java.lang.String title, java.lang.String sfile)
Construct a P0D from a file.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description boolean
containsAll(double[] array)
Tests the collection to determine if all of the elements in array are present.P0D
copy()
Get a copy of the current holderP0D
copy(java.lang.String newtitle)
Create an exact copy of the current P0D.double
correlation(P0D p0d)
Returns the correlation coefficient.double
covariance(P0D p0d)
Returns the covariancevoid
doc()
Show online documentation.void
fill(double[] values)
Fill a P0D container from an array.void
fill(int[] values)
Fill a P0D container from an array.void
fill(int TotNumber, double min, double max)
Fill with a sequence of numbers between min and max.int
find(double d)
Returns the index of first occurrence of the specified elementP0D
func(F1D f1d)
Transform P0D array to array with values given by a function.P0D
func(java.lang.String title, F1D f1d)
Make transformation of P0D using a function.P0D
get(int d, java.lang.String opi)
Get P0D with values below, above or equal a specified value.double[]
getArray()
Get a double array with P0D values.int[]
getArrayInt()
Get an integer array with P0D values.java.util.ArrayList<java.lang.Double>
getArrayList()
Get data in form of ArrayListH1D
getH1D(int bins)
Return H1D histogram with P0D content.H1D
getH1D(int bins, double min, double max)
Return H1D histogram with P0D content.double
getMax()
Returns the maximum value.int
getMaxIndex()
Returns index corresponding to maximum value.double
getMin()
Returns the minimum value.int
getMinIndex()
Returns index corresponding to minimum value.java.util.Map<java.lang.String,java.lang.Double>
getStat()
Get complete statistics for this container.java.lang.String
getStatString()
Returns a string representing statistics.java.lang.String
getStringValues()
Return all values as a string.double
getSum()
Sum all ellements of this array.java.lang.String
getTitle()
Get a new titleint
hashCode()
Returns the hash code value for this collection.double
kurtosis()
Returns the kurtosis.int
lastIndexOf(int offset, int value)
Searches the list back to front for the last index of value, starting at offset.double
mean()
Returns the mean value.double
median()
Returns the median.P0D
merge(P0D a)
Merge two P0D containersdouble
moment(int k, double c)
Returns the moment of k-th order with value c, which is Sum( (x[i]-c)k ) / size().P0D
oper(P0D p0d, java.lang.String what)
Operations on P0D containers: add, subtract, multiply, divide.P0D
oper(P0D p0d, java.lang.String title, java.lang.String what)
Operations on P0D containers: add, subtract, multiply, divide.P0D
operScale(double scale)
Scale P0D with a factor scale.P0D
operShift(double shift)
Shift all values in the array by a constant.P0D
operShiftAndScale(double shift, double scale)
Shift all values by a constant "shift", then scale it.void
print()
Print a P0D container.void
random(int TotNumber, AbstractDistribution dist)
Fill array with random numbers Random generators are taken from cern.jet.random.*.void
randomNormal(int TotNumber, double mu, double sigma)
Fill with random numbers distributed using the normal (gaussian) distribution.void
randomUniform(int TotNumber, double min, double max)
Fill with with uniform random numbers between min and max.P0D
range(int min, int max)
Get range between min and maxint
read(java.io.BufferedReader br)
Read one dimensional data from uncompressed ASCII file.int
read(java.io.File sfile)
Read P0D from a file.int
read(java.lang.String sfile)
Read PNI from a file.int
read(java.net.URL url)
Read data from URL.int
readBinary(java.lang.String name)
Read a P0D from a binary file (big endian by default).int
readGZip(java.io.File sfile)
Read PNI from a GZiped file.int
readGZip(java.lang.String sfile)
Read P0D from a GZiped file.P0D
readSerialized(java.lang.String name)
Read a P0D object from a serialized fileint
readZip(java.lang.String sfile)
Read one dimensional data from ZIP ASCII file.void
removeAll(int min, int max)
Remove elementsint
search(double value)
Search for the first occurrence of the given argumentvoid
setArray(double[] array)
Set a double array.void
setArray(int[] array)
Set an integer array.void
setArrayList(java.util.ArrayList<java.lang.Double> array)
Set the data in form of ArrayListvoid
setTitle(java.lang.String title)
Set a new titledouble
skew()
Returns the skew, which is moment(3,mean()) / standardDeviation() Run getStat(0 for evaluationvoid
sort(int fromIndex, int toIndex)
Sort a slice of the list (ascending) using the Sun quicksort implementation.int[]
sortIndex()
Return indexes of sorted array in increasing order.double
standardError()
Returns the sample standard error, which is Math.sqrt(variance() / size()).double
stddeviation()
Returns the standard deviation (square root of variance)void
toFile(java.lang.String name)
Write a P0D to an external file.java.lang.String
toString()
Get a P0D as a string.void
toTable()
Print the P0D container to a Table in a separate Frame.double
variance()
Returns the variance.void
writeBinary(java.lang.String name)
Write a P0D to a binary file (big endian by default).int
writeSerialized(java.lang.String name)
Write a P0D object to a serialized file-
Methods inherited from class cern.colt.list.DoubleArrayList
add, beforeInsert, binarySearchFromTo, clone, elements, elements, ensureCapacity, equals, fillRandom, forEach, get, getQuick, indexOfFromTo, lastIndexOfFromTo, partFromTo, removeAll, replaceFromToWithFrom, retainAll, reverse, set, setQuick, shuffleFromTo, trimToSize
-
Methods inherited from class cern.colt.list.AbstractDoubleList
addAllOf, addAllOfFromTo, beforeInsertAllOfFromTo, binarySearch, contains, delete, fillFromToWith, indexOf, lastIndexOf, mergeSortFromTo, mergeSortFromTo, quickSortFromTo, quickSortFromTo, removeFromTo, replaceFromToWithFromTo, replaceFromWith, size, times, toList
-
Methods inherited from class cern.colt.list.AbstractList
addAllOf, beforeInsertAllOf, clear, mergeSort, quickSort, remove, setSize, shuffle, sort, sortFromTo
-
Methods inherited from class cern.colt.list.AbstractCollection
isEmpty
-
-
-
-
Constructor Detail
-
P0D
public P0D(java.lang.String title)
Construct an empty container with a title- Parameters:
title
- New title
-
P0D
public P0D(double[] d)
Construct P0D from array;- Parameters:
d
- array
-
P0D
public P0D(java.lang.String title, double[] d)
Create P0D from an array.- Parameters:
title
- titled
- input array
-
P0D
public P0D(java.lang.String title, P0D p0d)
Construct a copy from a P0D. If the last argument is true, a shallow copy of a collection. In this case a new collection contains references to same objects as the source collection. Data are not cloned- Parameters:
title
- new titlep0d
- input data in form of P0D
-
P0D
public P0D()
Construct an empty container with a title
-
P0D
public P0D(java.lang.String title, java.lang.String sfile)
Construct a P0D from a file. Use "#" or "*" for comments. each number should be written in separate line.- Parameters:
title
- Title of the containersfile
- File name with input. Can be either file location or URL. Must start as http or ftp
-
-
Method Detail
-
setTitle
public void setTitle(java.lang.String title)
Set a new title- Parameters:
title
- New Title
-
getTitle
public java.lang.String getTitle()
Get a new title- Returns:
- Title
-
read
public int read(java.io.BufferedReader br)
Read one dimensional data from uncompressed ASCII file. Use "#" or "*" for comments. Each number should be written on a separate line.- Parameters:
sfile
- File name with input- Returns:
- error: 0 in case of success. 3: parse error. 1-2: file not found.
-
read
public int read(java.io.File sfile)
Read P0D from a file. The old content will be lost. Comment lines starting with "#" and "*" are ignored.- Parameters:
sfile
- input file- Returns:
- zero if success
-
read
public int read(java.net.URL url)
Read data from URL. Use a space to separate values in columns and tab to put new row.- Parameters:
url
- URL location of input file
-
readGZip
public int readGZip(java.lang.String sfile)
Read P0D from a GZiped file. It can read URL if the string starts from http or ftp, otherwise a file on the file system is assumed.Use a space to separate values in columns and tab to put new row.
- Parameters:
sfile
- File name with input (extension .gz)- Returns:
- zero if success
-
read
public int read(java.lang.String sfile)
Read PNI from a file. It can read URL if the string starts from http or ftp, otherwise a file on the file system is assumed.The old content will be lost. Use a space to separate values in columns and tab to put new row. Comment lines starting with "#" and "*" are ignored.
- Parameters:
sfile
- File name with input- Returns:
- zero if success
-
readGZip
public int readGZip(java.io.File sfile)
Read PNI from a GZiped file. The old content will be lost. Comment lines start from "#" and "*" are ignored.- Parameters:
sfile
- File name with input (extension .gz)- Returns:
- zero if success
-
readZip
public int readZip(java.lang.String sfile)
Read one dimensional data from ZIP ASCII file. Use "#" or "*" for comments. Each number should be written in separate line.- Parameters:
sfile
- Zipped file name with input (file extension .zip)- Returns:
- error (int): 0 in case of success. 3: parse error. 1-2: file not found.
-
toFile
public void toFile(java.lang.String name)
Write a P0D to an external file.- Parameters:
name
- File name with output
-
writeBinary
public void writeBinary(java.lang.String name)
Write a P0D to a binary file (big endian by default).- Parameters:
name
- Binary file name for the output.
-
writeSerialized
public int writeSerialized(java.lang.String name)
Write a P0D object to a serialized file- Parameters:
name
- serialized file name for output.- Returns:
- zero if no errors
-
readSerialized
public P0D readSerialized(java.lang.String name)
Read a P0D object from a serialized file- Parameters:
name
- serialized file name for input.- Returns:
- new P0D object
-
readBinary
public int readBinary(java.lang.String name)
Read a P0D from a binary file (big endian by default). Old elements will be removed. Only read files created by the method writeBinary().- Parameters:
name
- Binary file name for input.- Returns:
- 0 in case of no problems
-
toString
public java.lang.String toString()
Get a P0D as a string.- Overrides:
toString
in classAbstractDoubleList
- Returns:
- Output String. Each value separated by new line.
-
randomNormal
public void randomNormal(int TotNumber, double mu, double sigma)
Fill with random numbers distributed using the normal (gaussian) distribution. Previous content will be lost.- Parameters:
TotNumber
- total number of random valuesmu
- mean valuesigma
- Standard deviation of the random variable.
-
fill
public void fill(int TotNumber, double min, double max)
Fill with a sequence of numbers between min and max. min and max are included to the range, If non-empty, previous content will be lost.The step is evaluated as (max-min) / (TotNumber -1). For example, fill(11,0,10) will fill with 11 number: 0,1,2,3,4,5,6,7,8,9,10
- Parameters:
TotNumber
- total number of values.min
- min valuemax
- max value
-
randomUniform
public void randomUniform(int TotNumber, double min, double max)
Fill with with uniform random numbers between min and max. Previous content will be lost.- Parameters:
TotNumber
- of random valuesmin
- min random valuemax
- max random value
-
random
public void random(int TotNumber, AbstractDistribution dist)
Fill array with random numbers Random generators are taken from cern.jet.random.*. Examples: Beta, Binominal, Poisson, BreitWigner,ChiSquare,Empirical Exponential, Gamma, Hyperbolic, Logarithmic, Normal, NegativeBinomial- Parameters:
TotNumber
- Total number in arraydist
- A custom random distribution from cern.jet.random.*.
-
getH1D
public H1D getH1D(int bins)
Return H1D histogram with P0D content. Histogram range is defined by Min and Max values.- Parameters:
bins
- Number of bins for the histogram.- Returns:
- H2D histogram filled with P0D.
-
getH1D
public H1D getH1D(int bins, double min, double max)
Return H1D histogram with P0D content. Histogram range is defined by Min and Max values.- Parameters:
min
- Min value of histogrammax
- Max value of histogrambins
- Number of bins for the histogram.- Returns:
- H2D histogram filled with P0D.
-
print
public void print()
Print a P0D container.
-
merge
public P0D merge(P0D a)
Merge two P0D containers- Parameters:
a
- Container to be merged- Returns:
- merged P0D container
-
fill
public void fill(double[] values)
Fill a P0D container from an array. If it is not empty, add values will be appended.- Parameters:
values
- array with double values
-
fill
public void fill(int[] values)
Fill a P0D container from an array. If it is not empty, add values will be appended. Integers will be converted to double.- Parameters:
values
- array with double values
-
copy
public P0D copy()
Get a copy of the current holder- Overrides:
copy
in classDoubleArrayList
- Returns:
- a new copy
-
getArrayList
public java.util.ArrayList<java.lang.Double> getArrayList()
Get data in form of ArrayList- Returns:
- data in form of ArrayList
-
getStringValues
public java.lang.String getStringValues()
Return all values as a string. Values are separated by space- Returns:
- values as a single string
-
sort
public void sort(int fromIndex, int toIndex)
Sort a slice of the list (ascending) using the Sun quicksort implementation.- Parameters:
fromIndex
-toIndex
-
-
hashCode
public int hashCode()
Returns the hash code value for this collection.- Overrides:
hashCode
in classjava.lang.Object
-
lastIndexOf
public int lastIndexOf(int offset, int value)
Searches the list back to front for the last index of value, starting at offset.- Parameters:
offset
-value
-- Returns:
-
containsAll
public boolean containsAll(double[] array)
Tests the collection to determine if all of the elements in array are present.- Parameters:
array
-- Returns:
- true if contains
-
removeAll
public void removeAll(int min, int max)
Remove elements- Parameters:
min
- min indexmax
- max index
-
setArrayList
public void setArrayList(java.util.ArrayList<java.lang.Double> array)
Set the data in form of ArrayList- Parameters:
array
- ArrayList to be set.
-
setArray
public void setArray(double[] array)
Set a double array. Old content will be lost.- Parameters:
array
- array used to fill P0D
-
setArray
public void setArray(int[] array)
Set an integer array. Old content will be lost. It will be automatically transformed to the double.- Parameters:
array
- array used to fill P0D
-
copy
public P0D copy(java.lang.String newtitle)
Create an exact copy of the current P0D.- Parameters:
newtitle
- new title
-
get
public P0D get(int d, java.lang.String opi)
Get P0D with values below, above or equal a specified value. Specify in the input string "<,> or =".- Parameters:
d
- input valuesopi
- if "=", take equal values;
if ">", take above values;
if "<", take below values;
-
find
public int find(double d)
Returns the index of first occurrence of the specified element- Parameters:
d
- input value
-
getArray
public double[] getArray()
Get a double array with P0D values.- Returns:
- double array with values
-
getArrayInt
public int[] getArrayInt()
Get an integer array with P0D values.- Returns:
- integer array with values
-
search
public int search(double value)
Search for the first occurrence of the given argument- Parameters:
value
- value for searching- Returns:
- first occurrence of the given argument
-
getMax
public double getMax()
Returns the maximum value.- Returns:
- the maximum value.
-
getMaxIndex
public int getMaxIndex()
Returns index corresponding to maximum value.- Returns:
- index of maximum value.
-
getMinIndex
public int getMinIndex()
Returns index corresponding to minimum value.- Returns:
- index of minimum value.
-
getMin
public double getMin()
Returns the minimum value.- Returns:
- the minimum value.
-
range
public P0D range(int min, int max)
Get range between min and max- Parameters:
min
- indexmax
- index- Returns:
- same P0D with removed range
-
oper
public P0D oper(P0D p0d, java.lang.String what)
Operations on P0D containers: add, subtract, multiply, divide. Keep the same graphical attributes and the title.- Parameters:
p0d
- Input P0D container for operationwhat
- String representing the operation: "+" add a P0D container to the original; "-" subtract a P0D from the original; "*" multiply; "/" divide by P0D- Returns:
- original P0D after the operation.
-
operScale
public P0D operScale(double scale)
Scale P0D with a factor scale. X(i)=scale*X(i)- Parameters:
scale
- Scale factor- Returns:
- P0D after the operation.
-
operShift
public P0D operShift(double shift)
Shift all values in the array by a constant. X(i)=X(i)+shift.- Parameters:
shift
- constants used to add- Returns:
- P0D after shift.
-
operShiftAndScale
public P0D operShiftAndScale(double shift, double scale)
Shift all values by a constant "shift", then scale it. X(i)=(X(i)+shift)*scale.- Parameters:
shift
- constants used to add to all valuesscale
- constant used to scale after shifting.- Returns:
- P0D after shift and scale.
-
getSum
public double getSum()
Sum all ellements of this array.- Returns:
- sum of all ellements
-
oper
public P0D oper(P0D p0d, java.lang.String title, java.lang.String what)
Operations on P0D containers: add, subtract, multiply, divide. Keep the same graphical attributes- Parameters:
p0d
- Input P0D container for operationtitle
- New titlewhat
- String representing the operation: "+" add a P0D container to the original; "-" subtract a P0D from the original; "*" multiply; "/" divide by P0D- Returns:
- original P0D after the operation.
-
mean
public double mean()
Returns the mean value.- Returns:
- Mean value
-
kurtosis
public double kurtosis()
Returns the kurtosis. Run getStat() to update or evaluate the sampling- Returns:
- kurtosis
-
median
public double median()
Returns the median. First run getStat() to evaluate or update.- Returns:
- median
-
getStatString
public java.lang.String getStatString()
Returns a string representing statistics.- Returns:
- string representing statistics
-
getStat
public java.util.Map<java.lang.String,java.lang.Double> getStat()
Get complete statistics for this container. It return mean, error on the mean, RMS, variance, standard deviation.The key for the output map are: mean, error, rms, variance, stddev . Print the key to find out what is inside.
- Returns:
- map representing statistical characteristics of this data
-
moment
public double moment(int k, double c)
Returns the moment of k-th order with value c, which is Sum( (x[i]-c)k ) / size(). First run getStat() for evaluation- Parameters:
k
- k-th orderc
- c- Returns:
- moment
-
standardError
public double standardError()
Returns the sample standard error, which is Math.sqrt(variance() / size()). Run getStat(0) before.- Returns:
- sample standard error
-
skew
public double skew()
Returns the skew, which is moment(3,mean()) / standardDeviation() Run getStat(0 for evaluation- Returns:
- skewness
-
variance
public double variance()
Returns the variance. Run getStat() first to update or evaluate- Returns:
- variance
-
stddeviation
public double stddeviation()
Returns the standard deviation (square root of variance)- Returns:
- variance
-
covariance
public double covariance(P0D p0d)
Returns the covariance- Parameters:
p0d
- P0D object for covariance calculations- Returns:
- covariance value
-
correlation
public double correlation(P0D p0d)
Returns the correlation coefficient. Values between 0 (no correlation) and 1 (full linear correlation)- Parameters:
p0d
- P0D object for correlation calculation.- Returns:
- correlation coefficient.
-
func
public P0D func(F1D f1d)
Transform P0D array to array with values given by a function. The function may have up to 3 independent variables in it (x,y,z).This class is not fool proof. If the answer is wrong then use the parenthesis to force the order of evaluation. The most likely place this will be needed is in the use of the power command. The exponent is not evaluated correctly if it begins with a unary operator.
List of commands
- ( ) parenthesis , comma
- +, -, unary -, unary +
- , /
- ^ (raise to a power)
- pi, e, All the constants in class SpecialFunction
- log
- sin, cos, tan
- asin, acos, atan
- sqrt
- rand
- exp
- remainder
- atan2
- All the functions in class SpecialFunction
- Independent variables x,y,z
- Scientific notation using "e", "E", "d", "D".
- Parameters:
f1d
- function for transformation- Returns:
- transformed P0D
-
func
public P0D func(java.lang.String title, F1D f1d)
Make transformation of P0D using a function.- Parameters:
title
- new titlef1d
- function for transformation- Returns:
- transformed P0D
-
sortIndex
public int[] sortIndex()
Return indexes of sorted array in increasing order. The array itself will not be changed, since it acts on a clone. Used quicksort stable algorithm.- Returns:
- indexes of sorted array.
-
toTable
public void toTable()
Print the P0D container to a Table in a separate Frame. The numbers are formatted to scientific format. One can sort and search the data in this table (but not modify)
-
doc
public void doc()
Show online documentation.
-
-
DMelt 3.0 © DataMelt by jWork.ORG