jhplot
Class P0D

java.lang.Object
  extended by jhplot.P0D
All Implemented Interfaces:
java.io.Serializable

public class P0D
extends java.lang.Object
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).

See Also:
Serialized Form

Constructor Summary
P0D()
          Construct an empty container with a title
P0D(double[] d)
          Construct P0D from array;
P0D(DoubleArrayList d)
          Construct P0D from DoubleArrayList from cern.colt.list.DoubleArrayList;
P0D(int[] d)
          Construct P0D from an integer array.
P0D(java.lang.String title)
          Construct an empty container with a title
P0D(java.lang.String title, boolean shallow, P0D p0d)
          Construct a copy from a P0D.
P0D(java.lang.String title, double[] d)
          Create P0D from an array.
P0D(java.lang.String title, int[] d)
          Construct P0D from integers.
P0D(java.lang.String title, java.lang.String sfile)
          Construct a P0D from a file.
 
Method Summary
 void add(double value)
          Adds (appends) the specified element to the end of this list.
 void add(int value)
          Adds (appends) the specified element to the end of this list.
 void clear()
          Clear the container
 boolean contains(double d)
          Returns true if value exists
 P0D copy()
          Get a copy of the current holder
 P0D 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 covariance
 void 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 element
 P0D 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.
 double get(int i)
          Return a specific value at ith position.
 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 ArrayList
 DoubleArrayList getDoubleArrayList()
          Get data in form of DoubleArrayList from cern.colt package
 H1D 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.lang.String getStat()
          Print all statistics of the container
 java.lang.String getStringValues()
          Return all values as a string.
 double getSum()
          Returns the sum of all values.
 java.lang.String getTitle()
          Get a new title
 double kurtosis()
          Returns the kurtosis.
static void main(java.lang.String[] args)
          Test
 double mean()
          Returns the mean value.
 double median()
          Returns the median.
 P0D merge(P0D a)
          Merge two P0D containers
 double 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 max
 int read(java.lang.String sfile)
          Read one dimensional data from uncompressed ASCII file.
 int readBinary(java.lang.String name)
          Read a P0D from a binary file (big endian by default).
 int readGZip(java.lang.String sfile)
          Read one dimensional data from GZIP ASCII file.
 P0D readSerialized(java.lang.String name)
          Read a P0D object from a serialized file
 int readZip(java.lang.String sfile)
          Read one dimensional data from ZIP ASCII file.
 void remove(int i)
          Remove a value at the specified position.
 P0D reverse()
          Reverse the order of elements
 int search(double value)
          Search for the first occurrence of the given argument
 void set(int i, double value)
          Sets a value at the specified position.
 void 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 ArrayList
 void setTitle(java.lang.String title)
          Set a new title
 int size()
          Return the P10 data length.
 double skew()
          Returns the skew, which is moment(3,mean()) / standardDeviation() Run getStat(0 for evaluation
 P0D sort()
          Sort into ascending order
 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.
 void toTable(boolean format)
          Print the P0D array 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 java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

P0D

public P0D(java.lang.String title)
Construct an empty container with a title

Parameters:
title - New title

P0D

public P0D(DoubleArrayList d)
Construct P0D from DoubleArrayList from cern.colt.list.DoubleArrayList;

Parameters:
d - DoubleArrayList from

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 - title
d - input array

P0D

public P0D(int[] d)
Construct P0D from an integer array.

Parameters:
d - integer array

P0D

public P0D(java.lang.String title,
           int[] d)
Construct P0D from integers.

Parameters:
title - title;
d - input array

P0D

public P0D(java.lang.String title,
           boolean shallow,
           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 title
shallow - if true, a shallow copy of a collection.
p0d - 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 container
sfile - File name with input
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.lang.String sfile)
Read one dimensional data from uncompressed ASCII file. Use "#" or "*" for comments. Each number should be written in separate line.

Parameters:
sfile - File name with input
Returns:
error: 0 in case of success. 3: parse error. 1-2: file not found.

readGZip

public int readGZip(java.lang.String sfile)
Read one dimensional data from GZIP ASCII file. Use "#" or "*" for comments. Each number should be written in separate line.

Parameters:
sfile - Gziped file name with input (file extension .gz)
Returns:
error: 0 in case of success. 3: parse error. 1-2: file not found.

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 class java.lang.Object
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 values
mu - mean value
sigma - 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 value
max - 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 values
min - min random value
max - 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 array
dist - 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 histogram
max - Max value of histogram
bins - 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

add

public void add(double value)
Adds (appends) the specified element to the end of this list.

Parameters:
value - value to be added.

add

public void add(int value)
Adds (appends) the specified element to the end of this list. Note: you can add integer, but it will be transformed to double.

Parameters:
value - value to be added.

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

set

public void set(int i,
                double value)
Sets a value at the specified position. Old value will be replaced.

Parameters:
i - position
value - value to be inserted

remove

public void remove(int i)
Remove a value at the specified position. Old value will be replaced.

Parameters:
i - position of a value to be removed

size

public int size()
Return the P10 data length.

Returns:
length of the PlotPoint vector

copy

public P0D copy()
Get a copy of the current holder

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

getDoubleArrayList

public DoubleArrayList getDoubleArrayList()
Get data in form of DoubleArrayList from cern.colt package

Returns:
data in form of DoubleArrayList

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 values
opi - if "=", take equal values;
if ">", take above values;
if "<", take below values;

contains

public boolean contains(double d)
Returns true if value exists

Parameters:
d - double value

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

get

public double get(int i)
Return a specific value at ith position.

Parameters:
i - index of the array
Returns:
the value of x at index i

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.

getSum

public double getSum()
Returns the sum of all values.

Returns:
sum of all values

range

public P0D range(int min,
                 int max)
Get range between min and max

Parameters:
min - index
max - 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 operation
what - 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 values
scale - constant used to scale after shifting.
Returns:
P0D after shift and scale.

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 operation
title - New title
what - 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

getStat

public java.lang.String getStat()
Print all statistics of the container

Returns:
string representing all statistics

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 order
c - 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.

clear

public void clear()
Clear the container


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

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 title
f1d - function for transformation
Returns:
transformed P0D

sort

public P0D sort()
Sort into ascending order

Returns:
same P0D but with sorted numbers

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.

reverse

public P0D reverse()
Reverse the order of elements

Returns:
same P0D but with reverse order

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)


toTable

public void toTable(boolean format)
Print the P0D array to a Table in a separate Frame. One can sort and search the data in this table (but not modify)

Parameters:
format - if false, numbers will not be formatted to scientific format ##.#####E00

main

public static void main(java.lang.String[] args)
Test

Parameters:
args -

doc

public void doc()
Show online documentation.



jHepWork 2.8 (©) S.Chekanov