P0D
jhplot

Class P0D

  • All Implemented Interfaces:
    DoubleBufferConsumer, Serializable, Cloneable


    public class P0Dextends DoubleArrayListimplements 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 Detail

      • P0D

        public P0D(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(String title,   double[] d)
        Create P0D from an array.
        Parameters:
        title - title
        d - input array
      • P0D

        public P0D(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 title
        p0d - input data in form of P0D
      • P0D

        public P0D()
        Construct an empty container with a title
      • P0D

        public P0D(String title,   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. Can be either file location or URL. Must start as http or ftp
    • Method Detail

      • setTitle

        public void setTitle(String title)
        Set a new title
        Parameters:
        title - New Title
      • getTitle

        public String getTitle()
        Get a new title
        Returns:
        Title
      • read

        public int read(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(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(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(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(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(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(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(String name)
        Write a P0D to an external file.
        Parameters:
        name - File name with output
      • writeBinary

        public void writeBinary(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(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(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(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 String toString()
        Get a P0D as a string.
        Overrides:
        toString in class AbstractDoubleList
        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
      • 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 class DoubleArrayList
        Returns:
        a new copy
      • getArrayList

        public ArrayList<Double> getArrayList()
        Get data in form of ArrayList
        Returns:
        data in form of ArrayList
      • getStringValues

        public 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 class 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 index
        max - max index
      • setArrayList

        public void setArrayList(ArrayList<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(String newtitle)
        Create an exact copy of the current P0D.
        Parameters:
        newtitle - new title
      • get

        public P0D get(int d,      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;
      • 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 - index
        max - index
        Returns:
        same P0D with removed range
      • oper

        public P0D oper(P0D p0d,       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,       String title,       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
      • getStatString

        public String getStatString()
        Returns a string representing statistics.
        Returns:
        string representing statistics
      • getStat

        public Map<String,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 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.
      • 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(String title,       F1D f1d)
        Make transformation of P0D using a function.
        Parameters:
        title - new title
        f1d - 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.

SCaVis 2.1 © jWork.ORG