jhplot
Class P0D

java.lang.Object
  extended by jhplot.P0D

public class P0D
extends java.lang.Object

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).


Constructor Summary
P0D()
          Construct an empty container with a title
P0D(java.lang.String title)
          Construct an empty container with a title
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
 P0D copy()
          Get a copy of the current holder
 P0D copy(java.lang.String newtitle)
          Create an exact copy of the currentP0D.
 double correlation(P0D p0d)
          Returns the correlation coefficient.
 double covariance(P0D p0d)
          Returns the covariance
 void fill(double[] values)
          Fill a P0D container from an array.
 void fill(int[] values)
          Fill a P0D container from an array.
 P0D fill(int TotNumber, double min, double max)
          Fill with a sequence of numbers between min and max.
 P0D func(Function f)
          Transform P0D array to array with values given by a function.
 P0D func(java.lang.String definition)
          Transform P0D array to array with values given by a function.
 double get(int i)
          Return a specific value at ith position.
 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
 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.
 double getSum()
          Returns the sum of all values.
 java.lang.String getTitle()
          Get a new title
static void main(java.lang.String[] args)
          Test
 double mean()
          Returns the mean value.
 P0D merge(P0D a)
          Merge two P0D containers
 P0D oper(P0D p0d, java.lang.String title, java.lang.String what)
          Operations on P0D containers: add, subtract, multiply, divide.
 void print()
          Print a P1D container.
 P0D randomNormal(int TotNumber, double mu, double sigma)
          Fill with random numbers with normal random values.
 P0D 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
 P0D readBinary(java.lang.String name)
          Read a P0D from a binary file (big endian by default).
 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.
 P0D sort()
          Sort into ascending order
 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).
 
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()
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

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.

readBinary

public P0D readBinary(java.lang.String name)
Read a P0D from a binary file (big endian by default). Old elements will be removed.

Parameters:
name - Binary file name for input.

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 P0D randomNormal(int TotNumber,
                        double mu,
                        double sigma)
Fill with random numbers with normal random values. Previous content will be lost.

Parameters:
TotNumber - total number of random values
mu - parameter
sigma - sigma
Returns:
P0D with random numbers.

fill

public P0D 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
Returns:
P0D with random numbers.

randomUniform

public P0D 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
Returns:
P0D with random numbers.

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 P1D container.


merge

public P0D merge(P0D a)
Merge two P0D containers

Parameters:
a - Container to be added
Returns:
New P2D 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

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 currentP0D.

Parameters:
newtitle - new title

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 title,
                java.lang.String what)
Operations on P0D containers: add, subtract, multiply, divide. Keep the same graphical attributes

Parameters:
p0d - Input P1D 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

variance

public double variance()
Returns the variance

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(Function f)
Transform P0D array to array with values given by a function.

Parameters:
f - input function for transformation.
Returns:
transformed P0D

func

public P0D func(java.lang.String definition)
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).

Known Bugs 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:
definition - function definition for transformation
Returns:
transformed P0D

sort

public P0D sort()
Sort into ascending order

Returns:
same P0D but with sorted numbers

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 -


jHepWork 1.1 (C) Chekanov