Class/Object

cogx.cogmath.algebra.real

Matrix

Related Docs: object Matrix | package real

Permalink

class Matrix extends Tensor with Serializable

A matrix.

In the following descriptions, "v" represents a vector, "s" a scalar, "m" a matrix, "b" a boolean, "i" and integer, "d" a double, "r" a range of integers (e.g. "1 to 5" or "3 until 9").

The update operations, such as "+=", update the elements of the matrix in place.

Constructors:
  Matrix(i, i)
  Matrix(i, i, Array[d])
  copy

Dimensions:
  rows               => i        (number of rows in matrix)
  columns            => i        (number of columns in matrix)
  size               => i        (total # elements in matrix)

Linear element access:
  apply(i)           => s        (access element linearly)
  update(i, s)                   (write element i with value s)

2D element access:
  apply(i, i)        => s        (access element by 2D coordinates)
  update(i, i, s)                (write element (i, i) with value s)

Submatrix multi-element reads:
  row(i)             => m        (extract a copy of a row)
  column(i)          => m        (extract a copy of a column)
  submatrix(r, r)    => m        (extract a subregion of a matrix)
  reshape(i, i)      => m        (reshape the matrix)

Matrix operations:
  map(f: d => d)     => m        (map a Matrix by applying f to each element)
  mapSelf(f: d => d)			    (use f to map each element in place)
  reduce((d, d)=> d) => d        (reduce a Matrix to a scalar)
  randomize                      (initialize to random values in [0, 1))

Matrix / Scalar operations:
  m + s   => m          (add scalar to each element to produce a new matrix)
  m += s                (add scalar to all elements of matrix in-place)
  m - s   => m
  m -= s
  m * s   => m
  m *= s
  m / s   => m
  m /= s
  -m      => m          (map each element to new matrix my multiplying by -1)
  m := s                (assign scalar to all elements of the matrix)

Matrix / Matrix operations:
  m + m          => m
  m += m
  m - m          => m
  m -= m
  m :* m         => m   (element-wise multiplication)
  m :*= m               (element-wise multiplication in-place)
  m :/ m         => m   (element-wise right division)
  m :/= n               (element-wise right division in-place)
  m :\ m         => m   (element-wise left division)
  m :\= m               (element-wise left division in-place)
  m1 === m2		=> b   (m1 and m2 have same shape, identical elements)
  m1 !=== m2     => b
  m1 ~== m2
  m1 !~== m2
  m1 := m2			   (assign elements of m2 to m1)

Matrix multiplication:
  m * m          => m   (matrix multiplication)

Matrix decompositions:
  cholesky       => m         (Cholesky decomposition)
  eigen          => (m, m)    (eigenvector matrix, diag eigenvalue matrix)
  lu             => (m, m)    (L matrix, U matrix)
  qr             => (m, m)    (Q matrix, R matrix)
  svd            => (m, m, m) (U matrix, S matrix, V matrix)

Miscellaneous cogx.utilities:
  abs            => m   (absolute value of each element)
  sgn            => m   (sign of each element: -1, 0, 1)
  rectify        => m   (clip negative elements to 0)
  normalizeRows         (normalize rows using L2 norm)
  normalizeColumns      (normalize columns using L2 norm)
  print                 (print a matrix for debugging)
Annotations
@SerialVersionUID()
Linear Supertypes
Tensor, Serializable, Serializable, AnyRef, Any
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. Matrix
  2. Tensor
  3. Serializable
  4. Serializable
  5. AnyRef
  6. Any
  1. Hide All
  2. Show all
Visibility
  1. Public
  2. All

Instance Constructors

  1. new Matrix(tensor: Tensor)

    Permalink

    Create a Matrix from a 2-D tensor.

  2. new Matrix(rows: Int, columns: Int)

    Permalink

    Constructor that allocates memory for Matrix (most common).

  3. new Matrix(rows: Int, columns: Int, data: Array[Float])

    Permalink

    rows

    The number of rows in the matrix.

    columns

    The number of columns in the matrix.

    data

    Storage for matrix elements; length must be equal to rows * columns.

Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. def !===(that: Matrix): Boolean

    Permalink
  3. def !~==(that: Matrix): Boolean

    Permalink
  4. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  5. def *(that: Vector): Vector

    Permalink

    Matrix multiplication.

  6. def *(that: Matrix): Matrix

    Permalink
  7. def *(scalar: Float): Matrix

    Permalink
  8. def *=(scalar: Float): Unit

    Permalink
  9. def +(that: Matrix): Matrix

    Permalink
  10. def +(scalar: Float): Matrix

    Permalink
  11. def +=(that: Matrix): Unit

    Permalink
  12. def +=(scalar: Float): Unit

    Permalink
  13. def -(that: Matrix): Matrix

    Permalink
  14. def -(scalar: Float): Matrix

    Permalink
  15. def -=(that: Matrix): Unit

    Permalink
  16. def -=(scalar: Float): Unit

    Permalink
  17. def /(scalar: Float): Matrix

    Permalink
  18. def /=(scalar: Float): Unit

    Permalink
  19. def :*(that: Matrix): Matrix

    Permalink
  20. def :*=(that: Matrix): Unit

    Permalink
  21. def :/(that: Matrix): Matrix

    Permalink
  22. def :/=(that: Matrix): Unit

    Permalink
  23. def :=(that: Matrix): Unit

    Permalink
  24. def :=(scalar: Float): Unit

    Permalink
  25. def :\(that: Matrix): Matrix

    Permalink
  26. def :\=(that: Matrix): Unit

    Permalink
  27. def :^(that: Matrix): Matrix

    Permalink
  28. def :^=(that: Matrix): Unit

    Permalink
  29. def <(v: Float): Matrix

    Permalink
  30. def <=(v: Float): Matrix

    Permalink
  31. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  32. def ===(that: Matrix): Boolean

    Permalink
  33. def >(v: Float): Matrix

    Permalink
  34. def >=(v: Float): Matrix

    Permalink
  35. def ^(scalar: Float): Matrix

    Permalink
  36. def ^=(scalar: Float): Unit

    Permalink
  37. def abs: Matrix

    Permalink
  38. def apply(rows: Range, columns: Range): Matrix

    Permalink

    Synonym for submatrix.

    Synonym for submatrix.

    rows

    Range of rows to extract.

    columns

    Range of columns to extract.

    returns

    The specified submatrix.

  39. def apply(row: Int, column: Int): Float

    Permalink

    2D coordinates element access

  40. def apply(index: Int): Float

    Permalink

    Linear element access

  41. def asArray: Array[Float]

    Permalink

    View the matrix as a flat array of data.

  42. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  43. def backwardDivergence(v1: Matrix): Matrix

    Permalink
  44. def canEqual(other: Any): Boolean

    Permalink

    Helper for equals.

    Helper for equals.

    Definition Classes
    Tensor
  45. def cholesky: Matrix

    Permalink
  46. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  47. def column(colIndex: Int): Matrix

    Permalink
  48. val columns: Int

    Permalink

    The number of columns in the matrix.

  49. def compactString: String

    Permalink
  50. def convolve(that: Matrix): Matrix

    Permalink

    Convolve this matrix with another.

    Convolve this matrix with another. Useful for convolving two filters. Works only with square, odd-sized filters.

    that

    The matrix to be convolved with this.

    returns

    The convolution of the filters, larger than either.

  51. def copy: Matrix

    Permalink

    Make a copy of a Matrix.

  52. def dot(that: Matrix): Float

    Permalink

    Dot product of "this" and "that"

  53. def eigen: (Matrix, Matrix)

    Permalink
  54. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  55. def equals(other: Any): Boolean

    Permalink

    Test "this" and "other" for deep equality.

    Test "this" and "other" for deep equality. Allows "==" to work.

    Definition Classes
    Tensor → AnyRef → Any
  56. def expand(bigRows: Int, bigColumns: Int, borderFill: Boolean): Matrix

    Permalink

    Expand the matrix, optionally extending the border into the expanded region.

    Expand the matrix, optionally extending the border into the expanded region. This operation is a key part of the FFT. The new matrix is of size "bigRows" x "bigColumns" and element (0, 0) of this is anchored at (0, 0) in the larger matrix. If "borderFill" is true, then the four edges of the matrix are extended evenly in all directions, as though the bigger matrix were actually a torus with opposite edges touching.

  57. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  58. def flip: Matrix

    Permalink

    Flip the matrix left-to-right and top-to-bottom.

    Flip the matrix left-to-right and top-to-bottom. This is useful for creating correlation matrices that are implemented using convolution.

  59. def forwardGradient: (Matrix, Matrix)

    Permalink
  60. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  61. def getData: Array[Float]

    Permalink

    Get the data in the tensor, flattened to a linear array.

    Get the data in the tensor, flattened to a linear array.

    Attributes
    protected[cogx]
  62. def hashCode(): Int

    Permalink

    Required because of overriding equals.

    Required because of overriding equals.

    Definition Classes
    Tensor → AnyRef → Any
  63. def invert: Matrix

    Permalink
  64. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  65. def length: Int

    Permalink

    The number of "numbers" held in the tensor.

    The number of "numbers" held in the tensor.

    Definition Classes
    Tensor
  66. def lu: (Matrix, Matrix)

    Permalink
  67. def map(f: (Float) ⇒ Float): Matrix

    Permalink
  68. def mapSelf(f: (Float) ⇒ Float): Unit

    Permalink
  69. def max(that: Matrix): Matrix

    Permalink
  70. def min(that: Matrix): Matrix

    Permalink
  71. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  72. def normalizeColumns: Unit

    Permalink
  73. def normalizeRows: Unit

    Permalink
  74. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  75. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  76. def print: Unit

    Permalink
  77. def pseudoInverse: Matrix

    Permalink

    Compute the Moore-Penrose pseudo inverse.

  78. def qr: (Matrix, Matrix)

    Permalink
  79. def randomize: Matrix

    Permalink
  80. def rank: Int

    Permalink

    Find the rank of a matrix.

    Find the rank of a matrix.

    returns

    Rank of the matrix.

  81. def read(index: Int): Float

    Permalink

    Tensor accessor.

    Tensor accessor.

    Definition Classes
    MatrixTensor
  82. def reciprocal: Matrix

    Permalink
  83. def rectify: Matrix

    Permalink
  84. def reduce(f: (Float, Float) ⇒ Float): Float

    Permalink

    Reduce the matrix to a scalar.

  85. def reshape(newRows: Int, newColumns: Int): Matrix

    Permalink
  86. def row(rowIndex: Int): Matrix

    Permalink
  87. val rows: Int

    Permalink

    The number of rows in the matrix.

  88. def separate: Option[(Vector, Vector)]

    Permalink

    Attempt to separate this matrix into an outer product of two vectors.

    Attempt to separate this matrix into an outer product of two vectors. Relies on a tolerance, here taken to be the machine epsilon.

    returns

    Some((verticalVector, horizontalVector)) if separable, otherwise None.

  89. def sgn: Matrix

    Permalink
  90. def shape: geometry.Shape

    Permalink

    Shape of the matrix.

    Shape of the matrix.

    Definition Classes
    MatrixTensor
  91. def shift(shiftRows: Int, shiftColumns: Int): Matrix

    Permalink

    Shift a matrix with zero fill on the edges.

    Shift a matrix with zero fill on the edges.

    shiftRows

    Number of rows to shift this down.

    shiftColumns

    Number of columns to shift this to the right.

    returns

    Shifted matrix, zero-filling on edges.

  92. def shiftAndExpand(shift: Int, bigRows: Int, bigColumns: Int): Matrix

    Permalink

    Shift "this" matrix down by "shift" rows and right by "shift" columns, expand to a "bigRows" x "bigColumns" complex matrix, padding with zeros everywhere an element is not defined by "this".

  93. def shiftCyclic(deltaRows: Int, deltaColumns: Int): Matrix

    Permalink

    Shifts the elements of a matrix cyclicly as though it were a torus, wrapping around the left side to the right side, and the top to the bottom.

    Shifts the elements of a matrix cyclicly as though it were a torus, wrapping around the left side to the right side, and the top to the bottom. The rotation is specified by the tuple("deltaRows", "deltaColumns"). For example, the tuple value (2, 3) would cause the element at location (0, 0) to be moved to location (2, 3). In a 5 x 5 matrix, the same tuple would cause the element at (4, 4) to be moved to (1, 2), wrapping around the torus. Returns the cyclicly shifted matrix.

  94. val size: Int

    Permalink
  95. def sizeString: String

    Permalink

    Get the size of the matrix as a string.

  96. def submatrix(rowRange: Range, columnRange: Range): Matrix

    Permalink
  97. def svd: (Matrix, Matrix, Matrix)

    Permalink
  98. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  99. def toString(): String

    Permalink
    Definition Classes
    AnyRef → Any
  100. def toVector: Vector

    Permalink

    Flatten the rows of this matrix to a vector.

  101. def transpose: Matrix

    Permalink
  102. def trim(smallRows: Int, smallColumns: Int): Matrix

    Permalink

    Trim "this" to a "smallRows" x "smallColumns" matrix.

  103. def unary_-: Matrix

    Permalink
  104. def update(row: Int, vector: Vector): Unit

    Permalink

    Write the row "row" with the data in "vector".

  105. def update(rowRange: Range, columnRange: Range, values: Matrix): Unit

    Permalink

    Update a subset of a matrix.

    Update a subset of a matrix.

    rowRange

    Range of rows to update.

    columnRange

    Range of columns to update.

    values

    The new values to be written in the submatrix specified by rows and columns. This must have the exact same shape as (rows, columns), or it must be a 1 x 1 matrix, in which case it is treated like a scalar.

  106. def update(row: Int, column: Int, value: Float): Unit

    Permalink

    Modify an element given its 2D coordinates.

  107. def update(index: Int, value: Float): Unit

    Permalink

    Modify an element given its linear position.

  108. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  109. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  110. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  111. def ~==(that: Matrix): Boolean

    Permalink

Inherited from Tensor

Inherited from Serializable

Inherited from Serializable

Inherited from AnyRef

Inherited from Any

Ungrouped