Class MView

java.lang.Object
edu.cmu.tetrad.util.MView
All Implemented Interfaces:
TetradSerializable, Serializable

public class MView extends Object implements TetradSerializable
Allows a view of a matrix to be created that is a subset of the original matrix, to allow parts of a matrix to be set using indices in the view. This is useful for the task, e.g., of constructing a matrix by consructing its parts. The view is not a Matrix object, since it is only used for setting values in the original matrix, but a method is included to construct a Matrix object for the submatrix being viewed.
Author:
josephramsey
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    double
    get(int row, int column)
    Retrieves the value at the specified row and column in the matrix view.
    int
    Returns the number of columns in the current matrix view.
    int
    Returns the number of rows in the current matrix view.
    mat()
    Creates and returns a new Matrix instance representing a submatrix based on the rows and columns specified in the MatrixView.
    void
    set(double value)
    Sets all elements in the specified rows and columns of the matrix view to the given value.
    void
    set(double[] arr)
    Sets all elements in the current matrix view to the corresponding values from the given matrix.
    void
    set(double[][] m)
    Updates the matrix view with the values from the specified 2D array.
    void
    set(int row, int column, double value)
    Updates the value at a specified position in the matrix view.
    void
    Sets the values of the current matrix view to match the provided matrix.
    void
    set(MView matrixView)
    Sets all elements in the current matrix view to the corresponding values from the given matrix view.
    void
    setColumn(int column, double[] values)
    Sets the values of a specific column in the matrix view using the provided array of values.
    void
    setColumn(int col, Vector v)
    Sets the values of a specific column in the matrix view using the provided vector.
    void
    setRow(int row, double[] values)
    Sets the values of a specific row in the matrix view.
    void
    setRow(int row, Vector v)
    Sets the values of a specific row in the matrix view using the provided vector.
     
    Converts a matrix view to a vector representation if the view corresponds to either a single row or a single column.
    Creates a view of the entire matrix.
    view(int[] range1, int[] range2)
    Creates a view of a matrix using the specified row and column indices.
    viewColumn(int column)
    Creates a view of a specific column from the matrix.
    viewPart(int fromRow, int fromColumn, int toRow, int toColumn)
    Creates a view of a specified submatrix defined by the given row and column ranges.
    viewRow(int row)
    Creates a sub-view of the matrix representing a specific row.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Method Details

    • mat

      public Matrix mat()
      Creates and returns a new Matrix instance representing a submatrix based on the rows and columns specified in the MatrixView.
      Returns:
      a Matrix object that is a submatrix extracted based on the specified rows and columns of the original matrix.
    • getNumRows

      public int getNumRows()
      Returns the number of rows in the current matrix view.
      Returns:
      the number of rows in the matrix view.
    • getNumColumns

      public int getNumColumns()
      Returns the number of columns in the current matrix view.
      Returns:
      the number of columns in the matrix view.
    • get

      public double get(int row, int column)
      Retrieves the value at the specified row and column in the matrix view.
      Parameters:
      row - the row index in the view
      column - the column index in the view
      Returns:
      the value at the specified row and column in the matrix view
    • set

      public void set(int row, int column, double value)
      Updates the value at a specified position in the matrix view.
      Parameters:
      row - the row index in the matrix view where the value should be updated
      column - the column index in the matrix view where the value should be updated
      value - the new value to set at the specified position
    • setRow

      public void setRow(int row, Vector v)
      Sets the values of a specific row in the matrix view using the provided vector. The vector's values are converted to an array internally.
      Parameters:
      row - the index of the row in the matrix view to be updated.
      v - a vector containing the values to assign to the specified row, where each value corresponds to a column in the matrix view.
    • setColumn

      public void setColumn(int col, Vector v)
      Sets the values of a specific column in the matrix view using the provided vector.
      Parameters:
      col - the index of the column in the matrix view to be updated
      v - a vector containing the values to assign to the specified column
    • setRow

      public void setRow(int row, double[] values)
      Sets the values of a specific row in the matrix view.
      Parameters:
      row - the index of the row in the matrix view to be updated
      values - an array of values to assign to the specified row where each value corresponds to a column in the matrix view
    • setColumn

      public void setColumn(int column, double[] values)
      Sets the values of a specific column in the matrix view using the provided array of values.
      Parameters:
      column - the index of the column in the matrix view to be updated
      values - an array of values to assign to the specified column, where each value corresponds to a row in the matrix view
      Throws:
      IllegalArgumentException - if the column index is out of bounds
      IllegalArgumentException - if the length of the provided values array does not match the number of rows in the matrix view
    • set

      public void set(double value)
      Sets all elements in the specified rows and columns of the matrix view to the given value.
      Parameters:
      value - the value to set for all the elements in the specified rows and columns
    • set

      public void set(double[] arr)
      Sets all elements in the current matrix view to the corresponding values from the given matrix. The dimensions of the provided matrix must match the dimensions of the matrix view.
      Parameters:
      arr - the array of values to set in the matrix view. The length of the array must match the number of
      Throws:
      IllegalArgumentException - if the dimensions of the provided matrix do not match the dimensions of the matrix view.
    • set

      public void set(MView matrixView)
      Sets all elements in the current matrix view to the corresponding values from the given matrix view.
      Parameters:
      matrixView - the matrix view containing the values to be set in the view. It must have the same
    • set

      public void set(double[][] m)
      Updates the matrix view with the values from the specified 2D array. The dimensions of the input array must match the dimensions of the current matrix view.
      Parameters:
      m - a two-dimensional array containing the values to set in the matrix view. The number of rows in the array must match the number of rows in the view, and the number of columns in the array must match the number of columns in the view.
      Throws:
      IllegalArgumentException - if the dimensions of the provided array do not match the dimensions of the matrix view.
    • set

      public void set(Matrix m)
      Sets the values of the current matrix view to match the provided matrix. The dimensions of the input matrix must match the dimensions of this matrix view.
      Parameters:
      m - the matrix whose values will be used to update the matrix view. The number of rows and columns in the input matrix must match the number of rows and columns in the matrix view.
      Throws:
      IllegalArgumentException - if the dimensions of the provided matrix do not match the dimensions of the matrix view.
    • view

      public MView view(int[] range1, int[] range2)
      Creates a view of a matrix using the specified row and column indices.
      Parameters:
      range1 - an array of row indices to include in the view. Each index must be within the range [0, number of rows).
      range2 - an array of column indices to include in the view. Each index must be within the range [0, number of columns).
      Returns:
      a MatrixView object representing the specified subset of the matrix.
      Throws:
      IllegalArgumentException - if any row index in range1 is out of bounds or any column index in range2 is out of bounds.
    • view

      public MView view()
      Creates a view of the entire matrix.
      Returns:
      a MatrixView object representing the entire matrix
    • viewRow

      public MView viewRow(int row)
      Creates a sub-view of the matrix representing a specific row.
      Parameters:
      row - the index of the row to be viewed
      Returns:
      a MatrixView object representing the specified row
    • viewColumn

      public MView viewColumn(int column)
      Creates a view of a specific column from the matrix.
      Parameters:
      column - the index of the column to be viewed
      Returns:
      a MatrixView object representing the specified column
    • viewPart

      public MView viewPart(int fromRow, int fromColumn, int toRow, int toColumn)
      Creates a view of a specified submatrix defined by the given row and column ranges.
      Parameters:
      fromRow - the starting row index (inclusive) of the submatrix
      fromColumn - the starting column index (inclusive) of the submatrix
      toRow - the ending row index (exclusive) of the submatrix
      toColumn - the ending column index (exclusive) of the submatrix
      Returns:
      a MatrixView object representing the specified submatrix view
    • vector

      public Vector vector()
      Converts a matrix view to a vector representation if the view corresponds to either a single row or a single column. If the matrix view has exactly one row, a vector containing all the columns in that row is returned. Similarly, if the matrix view has exactly one column, a vector containing all the rows in that column is returned.
      Returns:
      a Vector representing the single row or single column of the matrix view.
      Throws:
      IllegalArgumentException - if the matrix view is null or does not correspond to a single row or column.
    • toString

      public String toString()
      Overrides:
      toString in class Object