Documentation of 'jhplot.P0I' Java class.
P0I
jhplot

Class P0I

  • All Implemented Interfaces:
    IntBufferConsumer, java.io.Serializable, java.lang.Cloneable


    public class P0I
    extends IntArrayList
    implements java.io.Serializable
    A container to hold integer 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 P0I 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
      P0I()
      Construct an empty container with a title
      P0I(int[] d)
      Construct P0I from array;
      P0I(java.lang.String title)
      Construct an empty container with a title
      P0I(java.lang.String title, int[] d)
      Create P0I from an array.
      P0I(java.lang.String title, P0I p)
      Construct a copy from a P0I.
      P0I(java.lang.String title, java.lang.String sfile)
      Construct a P0I from a file.
    • Constructor Detail

      • P0I

        public P0I(java.lang.String title)
        Construct an empty container with a title
        Parameters:
        title - New title
      • P0I

        public P0I(int[] d)
        Construct P0I from array;
        Parameters:
        d - array
      • P0I

        public P0I(java.lang.String title,
                   int[] d)
        Create P0I from an array.
        Parameters:
        title - title
        d - input array
      • P0I

        public P0I(java.lang.String title,
                   P0I p)
        Construct a copy from a P0I. 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
        p - input data in form of P0I
      • P0I

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

        public P0I(java.lang.String title,
                   java.lang.String sfile)
        Construct a P0I 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(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 P0I 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 P0I 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 P0I to an external file.
        Parameters:
        name - File name with output
      • writeBinary

        public void writeBinary(java.lang.String name)
        Write a P0I 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 P0I object to a serialized file
        Parameters:
        name - serialized file name for output.
        Returns:
        zero if no errors
      • readSerialized

        public P0I readSerialized(java.lang.String name)
        Read a P0I object from a serialized file
        Parameters:
        name - serialized file name for input.
        Returns:
        new P0I object
      • readBinary

        public int readBinary(java.lang.String name)
        Read a P0I 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 P0I as a string.
        Overrides:
        toString in class AbstractIntList
        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 P0I content. Histogram range is defined by Min and Max values.
        Parameters:
        bins - Number of bins for the histogram.
        Returns:
        H2D histogram filled with P0I.
      • getH1D

        public H1D getH1D(int bins,
                          double min,
                          double max)
        Return H1D histogram with P0I 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 P0I.
      • print

        public void print()
        Print a P0I container.
      • merge

        public P0I merge(P0I a)
        Merge two P0I containers
        Parameters:
        a - Container to be merged
        Returns:
        merged P0I container
      • fill

        public void fill(double[] values)
        Fill a P0I 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 P0I 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 P0I copy()
        Get a copy of the current holder
        Overrides:
        copy in class IntArrayList
        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 class java.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 index
        max - max index
      • setArrayList

        public void setArrayList(java.util.ArrayList<java.lang.Integer> array)
        Set the data in form of ArrayList
        Parameters:
        array - ArrayList to be set.
      • setArray

        public void setArray(int[] array)
        Set a double array. Old content will be lost.
        Parameters:
        array - array used to fill P0I
      • copy

        public P0I copy(java.lang.String newtitle)
        Create an exact copy of the current P0I.
        Parameters:
        newtitle - new title
      • get

        public P0I get(int d,
                       java.lang.String opi)
        Get P0I 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(int d)
        Returns the index of first occurrence of the specified element
        Parameters:
        d - input value
      • getArray

        public int[] getArray()
        Get a double array with P0I values.
        Returns:
        double array with values
      • getArrayInt

        public int[] getArrayInt()
        Get an integer array with P0I values.
        Returns:
        integer array with values
      • search

        public int search(int value)
        Search for the first occurrence of the given argument
        Parameters:
        value - value for searching
        Returns:
        first occurrence of the given argument
      • getMax

        public int getMax()
        Returns the minimum value.
        Returns:
        the minimum 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 int getMin()
        Returns the minimum value.
        Returns:
        the minimum value.
      • range

        public P0I range(int min,
                         int max)
        Get range between min and max
        Parameters:
        min - index
        max - index
        Returns:
        same P0I with removed range
      • oper

        public P0I oper(P0I p,
                        java.lang.String what)
        Operations on P0I containers: add, subtract, multiply, divide. Keep the same graphical attributes and the title.
        Parameters:
        Pp - Input P0I container for operation
        what - String representing the operation: "+" add a P0I container to the original; "-" subtract a P0I from the original; "*" multiply; "/" divide by P0I
        Returns:
        original P0I after the operation.
      • operScale

        public P0I operScale(double scale)
        Scale P0I with a factor scale. X(i)=scale*X(i)
        Parameters:
        scale - Scale factor
        Returns:
        P0I after the operation.
      • operShift

        public P0I operShift(double shift)
        Shift all values in the array by a constant. X(i)=X(i)+shift.
        Parameters:
        shift - constants used to add
        Returns:
        P0I after shift.
      • operShiftAndScale

        public P0I 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:
        P0I after shift and scale.
      • oper

        public P0I oper(P0I p0i,
                        java.lang.String title,
                        java.lang.String what)
        Operations on P0I containers: add, subtract, multiply, divide. Keep the same graphical attributes
        Parameters:
        p0i - Input P0I container for operation
        title - New title
        what - String representing the operation: "+" add a P0I container to the original; "-" subtract a P0I from the original; "*" multiply; "/" divide by P0I
        Returns:
        original P0I 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()
        Get string with all statistics
        Returns:
        string representing all statistics
      • getIntegerArrayList

        public DoubleArrayList getIntegerArrayList()
        Get data in form of DoubleArrayList from cern.colt package
        Returns:
        data in form of DoubleArrayList
      • 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 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(P0I P0I)
        Returns the covariance
        Parameters:
        P0I - P0I object for covariance calculations
        Returns:
        covariance value
      • getArrayDouble

        public double[] getArrayDouble()
        Get a double array with P0I values.
        Returns:
        Double array with values
      • correlation

        public double correlation(P0I P0I)
        Returns the correlation coefficient. Values between 0 (no correlation) and 1 (full linear correlation)
        Parameters:
        P0I - P0I object for correlation calculation.
        Returns:
        correlation coefficient.
      • func

        public P0I func(F1D f1d)
        Transform P0I 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 P0I
      • getSum

        public int getSum()
        Sum all ellements of this array.
        Returns:
        sum of all ellements
      • func

        public P0I func(java.lang.String title,
                        F1D f1d)
        Make transformation of P0I using a function.
        Parameters:
        title - new title
        f1d - function for transformation
        Returns:
        transformed P0I
      • 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 P0I 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