Documentation of 'jhplot.PND' Java class.
PND
jhplot

Class PND

  • All Implemented Interfaces:
    java.io.Serializable


    public class PND
    extends java.lang.Object
    implements java.io.Serializable
    Data holder in 2D for double values. It is similar to a matrix in 2D. It has columns and rows. The number of columns may not be the same. For example, data can be presented as:

     1 2 3 4 5
     12 3 4
     1 3 4 555 5 66 77
     1 2 2 33 434 4
     

    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

      Constructors 
      Constructor and Description
      PND()
      Construct an empty container with no title
      PND(java.lang.String title)
      Construct an empty container with a title
      PND(java.lang.String title, boolean shallow, PND pnd)
      Construct a copy from a PND.
      PND(java.lang.String title, java.lang.String file)
      Construct a container with a title from external file (see the method toFile() how to write such ASCII file).
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      void add(double[] values)
      Adds (appends) the specified element to the end of this list.
      void add(P0D values)
      Adds (appends) P0D to the end of this list.
      void clear()
      Clear the container
      PND copy(java.lang.String newtitle)
      Create an exact copy of the current P0D.
      void doc()
      Show online documentation.
      double[] get(int row)
      Return a specific row as array
      double get(int row, int column)
      Return a specific value.
      double[][] getArray()
      Get a double array with values.
      java.util.ArrayList<double[]> getArrayList()
      Get data in form of ArrayList
      double[] getColumn(int column)
      Return a specific column as an array
      P0D getColumnP0D(int column)
      Return a specific column as P0D object
      int getDimension()
      Get last dimension of the data (or number of columns).
      int[] getDimensions()
      Get the numbers of columns.
      H1D getH1D(int bins)
      Create histogram.
      H1D getH1D(int bins, double min, double max)
      Return H1D histogram with PND content.
      H1D getH1D(int bins, double min, double max, int column)
      Make a histogram from a column of PND.
      IDataPointSet getIDataPointSet()
      Get the data point set for JAIDA
      double getMax()
      Get min value
      double getMin()
      Get max value
      java.lang.String getName()
      Get a new title
      P0D getP0D(int column)
      Return a specific column as an array
      P1D getP1D(int c1, int c2)
      Return 2 columns as P1D to show as a X-Y plot
      P2D getP2D(int c1, int c2, int c3)
      Return 3 columns as P2D to show as a X-Y-Z plot
      P0D getRow(int row)
      Return a specific row as array
      P0D getRowP0D(int row)
      Return a specific row as P0D
      PND getRows(java.lang.String newtitle, int indexMin, int indexMax)
      Get rows : min is inxluded, max is not;
      java.lang.String getTitle()
      Get a new title.
      static void main(java.lang.String[] args)
      Test
      PND oper(PND pnd, java.lang.String what)
      Operations on PND containers: add, subtract, multiply, divide.
      PND oper(PND pnd, java.lang.String title, java.lang.String what)
      Operations on PND containers: add, subtract, multiply, divide.
      void operScale(double scale)
      Scale each element of data
      void print()
      Print PND to System.out.
      int read(java.io.BufferedReader br)
      Read the data from an external source.
      int read(java.io.File sfile)
      Read PND from a file.
      int read(java.lang.String sfile)
      Read PND from a file.
      int read(java.net.URL url)
      Read data from URL.
      int readGZip(java.io.File sfile)
      Read PND from a GZiped file.
      int readGZip(java.lang.String sfile)
      Read PND from a GZiped file.
      PND readSerialized(java.lang.String name)
      Read a PND object from a serialized file
      int readZip(java.lang.String sfile)
      Read the data from ZIPed external file.
      PND remove(int index)
      Remove a row
      PND rescale(double[][] v)
      This is an inverse operation to rescale(type) function.
      double[][] rescale(int type)
      Rescale the column vectors.
      void set(int index, double[] values)
      Sets (replace) the specified row.
      void set(int index, P0D values)
      Sets (replace) the specified element with P0D.
      PND setArray(double[][] values)
      Set values from double array Old content will be lost.
      void setArrayList(java.util.ArrayList<double[]> array)
      Set the data in form of ArrayList
      void setName(java.lang.String title)
      Set a new title
      void setTitle(java.lang.String title)
      Set a new title
      int size()
      Data size (number of rows)
      PND standardize()
      Standardize each column.
      void toFile(java.lang.String name)
      Write a PND to an external file.
      java.lang.String toString()
      Get a string representing PND
      void toTable()
      Show container to a Table in a separate Frame.
      void write(java.lang.String name)
      Write a PND to an external file.
      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

      • PND

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

        public PND(java.lang.String title,
                   boolean shallow,
                   PND pnd)
        Construct a copy from a PND. 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.
        pnd - inpit data
      • PND

        public PND(java.lang.String title,
                   java.lang.String file)
        Construct a container with a title from external file (see the method toFile() how to write such ASCII file).
        Parameters:
        title - A title
        file - input file name. It can be either a file on a file system or URL location (must start from http or ftp)
      • PND

        public PND()
        Construct an empty container with no title
    • Method Detail

      • setTitle

        public void setTitle(java.lang.String title)
        Set a new title
        Parameters:
        title - New Title
      • setName

        public void setName(java.lang.String title)
        Set a new title
        Parameters:
        title - New Title
      • getTitle

        public java.lang.String getTitle()
        Get a new title.
        Returns:
        Title
      • getName

        public java.lang.String getName()
        Get a new title
        Returns:
        Title
      • clear

        public void clear()
        Clear the container
      • get

        public double[] get(int row)
        Return a specific row as array
        Parameters:
        row - index of the row
        Returns:
        array of values
      • getRowP0D

        public P0D getRowP0D(int row)
        Return a specific row as P0D
        Parameters:
        row - index of the row
        Returns:
        array of values
      • get

        public double get(int row,
                          int column)
        Return a specific value.
        Parameters:
        row - row index
        column - column index
        Returns:
        value
      • toString

        public java.lang.String toString()
        Get a string representing PND
        Overrides:
        toString in class java.lang.Object
        Returns:
        String with all values
      • print

        public void print()
        Print PND to System.out.
      • getP0D

        public P0D getP0D(int column)
        Return a specific column as an array
        Parameters:
        column - index of the column
        Returns:
        P0D array with values.
      • getColumn

        public double[] getColumn(int column)
        Return a specific column as an array
        Parameters:
        column - index of the column
        Returns:
        array with values.
      • getColumnP0D

        public P0D getColumnP0D(int column)
        Return a specific column as P0D object
        Parameters:
        column - index of the column
        Returns:
        array with values.
      • getP1D

        public P1D getP1D(int c1,
                          int c2)
        Return 2 columns as P1D to show as a X-Y plot
        Parameters:
        c1 - index of the first column
        c2 - index of the second column
        Returns:
        P1D array with X-Y values.
      • getP2D

        public P2D getP2D(int c1,
                          int c2,
                          int c3)
        Return 3 columns as P2D to show as a X-Y-Z plot
        Parameters:
        c1 - index of the first column
        c2 - index of the second column
        c3 - index of the third column
        Returns:
        P3D array with X-Y-Z values.
      • getDimension

        public int getDimension()
        Get last dimension of the data (or number of columns). The stored dimention is the one set after the last call "add", or if it set manually.
        Returns:
        dimension (number of elements in a row)
      • getDimensions

        public int[] getDimensions()
        Get the numbers of columns. The stored dimention is the one set after the last call "add", or if it set manually.
        Returns:
        dimension (number of elements in a row)
      • getRow

        public P0D getRow(int row)
        Return a specific row as array
        Parameters:
        row - index of the row
        Returns:
        array of values
      • getArrayList

        public java.util.ArrayList<double[]> getArrayList()
        Get data in form of ArrayList
        Returns:
        data in form of ArrayList
      • getIDataPointSet

        public IDataPointSet getIDataPointSet()
        Get the data point set for JAIDA
        Returns:
      • add

        public void add(double[] values)
        Adds (appends) the specified element to the end of this list.
        Parameters:
        values - array of values to be added.
      • add

        public void add(P0D values)
        Adds (appends) P0D to the end of this list.
        Parameters:
        values - array of values to be added.
      • set

        public void set(int index,
                        double[] values)
        Sets (replace) the specified row.
        Parameters:
        index - position index
        values - array of values to be added.
      • set

        public void set(int index,
                        P0D values)
        Sets (replace) the specified element with P0D.
        Parameters:
        index - position index
        values - array of values to be added.
      • read

        public int read(java.io.BufferedReader br)
        Read the data from an external source. Old data will be lost. Use "#" or "*" for comments. Use a space to separate values in columns and new line to put new row.
        Parameters:
        br - BufferedReader
        Returns:
        zero if success.
      • read

        public int read(java.io.File sfile)
        Read PND from a file. The old content will be lost. Use a space to separate values in columns and new line to put new row. 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 new line to put new row.
        Parameters:
        url - URL location of input file
      • readGZip

        public int readGZip(java.lang.String sfile)
        Read PND 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 new line 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 PND 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 new line 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 PND from a GZiped file. The old content will be lost. Use a space to separate values in columns and ne line to put new row. 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 the data from ZIPed external file. Old data will be lost. Use "#" or "*" for comments.
        Parameters:
        sfile - File name with the input (extension .zip)
        Returns:
        zero if success.
      • write

        public void write(java.lang.String name)
        Write a PND to an external file. Same method as toFile()
        Parameters:
        name - File name with 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 PND readSerialized(java.lang.String name)
        Read a PND object from a serialized file
        Parameters:
        name - serialized file name for input.
        Returns:
        new PND object
      • toFile

        public void toFile(java.lang.String name)
        Write a PND to an external file.
        Parameters:
        name - File name with output
      • remove

        public PND remove(int index)
        Remove a row
        Parameters:
        index - row index to be removed
      • oper

        public PND oper(PND pnd,
                        java.lang.String what)
        Operations on PND containers: add, subtract, multiply, divide. Keep the same graphical attributes and title.
        Parameters:
        pnd - Input PND 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 PND after the operation.
      • oper

        public PND oper(PND pnd,
                        java.lang.String title,
                        java.lang.String what)
        Operations on PND containers: add, subtract, multiply, divide. Keep the same graphical attributes
        Parameters:
        pnd - Input PND 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 PND after the operation.
      • operScale

        public void operScale(double scale)
        Scale each element of data
        Parameters:
        scale - Scale factor
      • size

        public int size()
        Data size (number of rows)
        Returns:
        number of rows
      • copy

        public PND copy(java.lang.String newtitle)
        Create an exact copy of the current P0D. New object is created.
        Parameters:
        newtitle - new title
      • getRows

        public PND getRows(java.lang.String newtitle,
                           int indexMin,
                           int indexMax)
        Get rows : min is inxluded, max is not;
        Parameters:
        title - New title
        indexMin - min index of row
        indexMax - max index of row
        Returns:
        new PND with rows indexMin-indexMax
      • setArrayList

        public void setArrayList(java.util.ArrayList<double[]> array)
        Set the data in form of ArrayList
        Parameters:
        array - ArrayList to be set.
      • getArray

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

        public PND setArray(double[][] values)
        Set values from double array Old content will be lost.
        Parameters:
        values - array to be set: [ROWS][dimension];
        Returns:
        PND with new values
      • standardize

        public PND standardize()
        Standardize each column. Useful for Neural Network studies. This means S(i)= (X(i) - mean) / std; i goes from 0 to size(); for each column in PND. mean - mean value for data in a certain column; std is the standard deviation. Usually used for neural net to standardize the input variables (column vectors). Operates on the original data.
        Returns:
        PND after standardize
      • rescale

        public double[][] rescale(int type)
        Rescale the column vectors. S(i)= (X(i) - v[0]) / v[1], where v[dimension] [2] is the 2D array returned by this function to be able calculate X(i) back. Usually used for a neural net (rescaling of the output).

        Parameters:
        type - 0: is ths standard rescaling, i.e. all columns are rescaled to the range [0,1] This is done as: v[0] is the min value of X(i), v[1] is the range (max-min).

        type 1: midrange rescaling, i.e. all values are in the range [-1,1]. v[0] is 0.5*(min+max), while [1] is (max-min) /2

        Returns:
        v[][] used to rescale the data: v[column][0] gives v[0], v[column][1] given by v[1]. Use this array to convert the data back.
      • getH1D

        public H1D getH1D(int bins,
                          double min,
                          double max)
        Return H1D histogram with PND content. All values are added. Histogram range is defined by Min and Max values.
        Parameters:
        bins - Number of bins for the histogram.
        min - Min value of histogram
        max - Max value of histogram
        Returns:
        H2D histogram filled with P0D.
      • getH1D

        public H1D getH1D(int bins,
                          double min,
                          double max,
                          int column)
        Make a histogram from a column of PND.
        Parameters:
        bins - Number of bins
        min - Min value
        max - Max value
        column - column of PND (
        Returns:
        histogram
      • getH1D

        public H1D getH1D(int bins)
        Create histogram. Min and Max are determined authomatically.
        Parameters:
        bins - Number of bins
        Returns:
      • getMax

        public double getMax()
        Get min value
        Returns:
        minimum value
      • getMin

        public double getMin()
        Get max value
        Returns:
      • rescale

        public PND rescale(double[][] v)
        This is an inverse operation to rescale(type) function. You should give array v[2], from which the original data can be calculated. Each column after the rescaling will be transformed to X(i)=S(i)*v[1]+v[0] (we drop here index for rows).
        Parameters:
        v - array used to rescale the data. applied as X(i)=S(i)*v[1]+v[0]
        Returns:
        PND after rescaling
      • main

        public static void main(java.lang.String[] args)
        Test
        Parameters:
        args -
      • toTable

        public void toTable()
        Show 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