Class MatrixF

java.lang.Object
edu.cmu.tetrad.study.gene.tetrad.gene.algorithm.util.BasicMatrix
edu.cmu.tetrad.study.gene.tetrad.gene.algorithm.util.MatrixF

public class MatrixF extends BasicMatrix
Implements a Matrix of elements of type float
Version:
$Id: $Id
Author:
Raul Saavedra (rsaavedr@ai.uwf.edu)
  • Constructor Details

    • MatrixF

      public MatrixF(String mname, int nrows)
      Creates a matrix with name mname, and nrows rows.
      Parameters:
      mname - a String object
      nrows - a int
    • MatrixF

      public MatrixF(String fname) throws IOException
      Creates a matrix reading it from a file fname. The file has to be an ascii one and follow a particular format:

      *MATRIX* [matrix name]
      [n]
      [0, 0 ] [ 0, 1] ... [ 0, n-1]
      [1, 0 ] [ 1, 1] ... [ 1, n-1]
      :
      [n-1,0] [n-1,1] ... [n-1,n-1]

      First token should be a word with "MATRIX" as a substring (case insens.), followed by the name of the matrix (one word). [n] is the number of rows and columns in the matrix, and [i,j] is element at position i,j in the matrix.
      For example, a 3x3 identity matrix could be represented as follows:

      MATRIX Identity3x3

      3 // # rows and columns

      // Matrix elements:
      1 0 0
      0 1 0
      0 0 1

      Notice there can be slash-slash (and also slash-star) style comments anywhere in the file. Numbers can be separated by any number of blank delimiters: tabs, spaces, carriage returns. In the examples above they appear in different lines for more readability of the file. The file may have less elements than the total needed to fill the matrix. If it has more elements an illegal argument exception will be generated.

      Parameters:
      fname - a String object
      Throws:
      IOException - if any.
  • Method Details

    • setDoubleValue

      public void setDoubleValue(int r, int c, double x)
      Assigns double value x in matrix element (r, c). Notice the presence of this method does not really force the implementing class to actually store doubles.

      Casts double value x to float and assigns it to element (r,c)

      Specified by:
      setDoubleValue in class BasicMatrix
      Parameters:
      r - row index
      c - column index
      x - value to be assigned to element (r,c)
    • getDoubleValue

      public double getDoubleValue(int r, int c)
      Returns the value stored at element (r,c) as a double

      Returns the value stored at element (r,c) as a double

      Specified by:
      getDoubleValue in class BasicMatrix
      Parameters:
      r - row index
      c - column index
      Returns:
      the value stored at element (r,c) as a double
    • setValue

      public void setValue(int r, int c, float x)
      Assigns float x to matrix element at (r, c)
      Parameters:
      r - a int
      c - a int
      x - a float
    • setValue

      public void setValue(int r, int c, double x)
      Assigns double x to matrix element at (r, c). This method checks that the double x can be converted to a float without causing overflow.
      Parameters:
      r - a int
      c - a int
      x - a double
    • getValue

      public float getValue(int r, int c)
      Returns the value stored at element (r,c)
      Parameters:
      r - a int
      c - a int
      Returns:
      a float
    • setAllValuesToZero

      public void setAllValuesToZero()
      Assign zero to all elements in the matrix
      Specified by:
      setAllValuesToZero in class BasicMatrix