| default_epsilon | [RW] |
calls DMatrix.rows with a splat (*)
DMatrix[[1,2,3],[4,5,6]]
is equivalent to
DMatrix.rows [[1,2,3],[4,5,6]]
Create a matrix using the elements of array as columns.
DMatrix.columns(array)
is equivalent to
DMatrix.new(array[0].size, array.size) { |i,j| array[j][i] }
DimensionError is raised if array is not rectangular.
In the first form, create a diagonal matrix with the elements of array along the diagonal. The second form is like the first but using elements of the column vector vector. In the third form, create an n x n diagonal matrix with diagonal elements of value scalar. In the fourth form, each element m[i,i] gets the block result.
Least squares minimization using QR factorization.
Find x for which
(a*x - b).norm_2
is a minimum.
Assumes a matrix of full rank.
Create a matrix by joining together a list of column vectors
m == DMatrix.join_columns(m.columns.map { |x| x })
Create a matrix by joining together a list of row vectors
m == DMatrix.join_rows(m.rows.map { |x| x })
Returns a new matrix with dimensions [vsize, hsize].
In the first form, the matrix is filled with zero. In the second form, the matrix is filled with scalar. In the third form, each index pair is passed to the block and the respective matrix element is assigned the block result.
DMatrix.new(4,4) { |i,j| i == j ? 1 : 0 }
is the 4 x 4 identity matrix.
Create a matrix filled with random numbers between -1.0 and 1.0.
Similar to
DMatrix.new(vsize, hsize) { 2*rand - 1 }
except uses rand() from stdlib.h
Create a matrix using the elements of array as rows.
DMatrix.rows(array)
is equivalent to
DMatrix.new(array.size, array[0].size) { |i,j| array[i][j] }
DimensionError is raised if array is not rectangular.
Solve the linear equation
a * x == b
Returns the solution x, or raises SingularMatrix if a was singular.
Solve the linear equation
a * x == b
a and b are both overwritten.
If a unique solution is found, a contains both L and U factors while b holds the solution x above.
Returns the solution x, or raises SingularMatrix if a was singular.
x = DMatrix.solve!(a, b) x.object_id == b.object_id
Implemented as
m.within(epsilon, other)
where
epsilon =
self.singleton_class.default_epsilon ||
self.class.default_epsilon
Given a symmetric positive definite matrix m, gives an upper-triangular matrix u such that
u.t * u
is equal to m.
Only the upper-triangular portion of m is considered for the algorithm.
Raises Diverged if m was not positive definite.
Returns the determinant of the matrix. Raises DimensionError if the matrix is not square.
Column vector dot product
a.dot(b)
DimensionError is raised unless
a.hsize == b.hsize and b.hsize == 1 and a.vsize == b.vsize
Find the eigenvectors and eigenvalues of the matrix.
The columns of eigvs hold the eigenvectors; the column vectors real and imag hold the eigenvalues.
Stepping through the eigenvalues in succession starting from the beginning, one will encounter either a real eigenvalue or a complex conjugate pair. That is, either the imaginary part will be exactly equal to zero
imag[n] == 0.0
or there will be a conjugate pair with the following exactly equal,
real[n] == real[n+1] imag[n] == -imag[n+1]
In the former case, the real eigenvector
eigvs.column(n)
corresponds to the real eigenvalue
real[n]
In the latter case, the complex eigenvector
eigvs.column(n) + i*eigvs.column(n+1)
corresponds to the complex eigenvalue
real[n] + i*imag[n]
and the conjugate eigenvector
eigvs.column(n) - i*eigvs.column(n+1)
corresponds to the conjugate eigenvalue
real[n] - i*imag[n]
for i = sqrt(-1).
The eigenvectors are each given unit length with largest component real.
Raises DimensionError if the given matrix is not square. May raise Diverged.
Returns the eigenvalues. See DMatrix#eigensystem for the format in which eigenvalues are returned.
In-place matrix inverse. Raises SingularMatrix if the matrix is singular.
a.object_id == a.inverse!.object_id
Generalized LU decomposition for rectangular matrices. The matrix is decomposed into
p * l * u
where p is a permutation matrix, l lower-triangular (or lower-trapezoidal), and u is upper-triangular (or upper-trapezoidal).
In-place LU decomposition. The matrix is overwritten with both L and U factors (the diagonal 1‘s of L are discarded). Returns the vector p of pivots.
Return the minor with upper-left position [i, j] and dimensions [vsize, hsize].
In-place matrix subtraction.
c = a - b
is equivalent to
c = a.minus!(b)
with
a.object_id == c.object_id
Frobenius norm. Square root of the sum of the squares of the elements.
For matrix m, equivalent to
Math.sqrt(m.elems.inject(0.0) { |acc, e| acc + e*e })
Returns a matrix whose columns form an orthogonal basis for the nullspace. (This is simply taken from vt.t in DMatrix#svd.) Returns nil if the matrix is of full rank.
For matrix m, a singular value less than or equal to m.norm*epsilon is considered a rank deficiency.
Alias for rankspace
In-place multiply
c = a * b
is equivalent to
c = a.postmul!(b)
with
a.object_id == c.object_id
Note this implies b must be square. DimensionError is raised otherwise.
In-place multiply
c = a * b
is equivalent to
c = b.premul!(a)
with
b.object_id == c.object_id
Note this implies a must be square. DimensionError is raised otherwise.
Returns a matrix whose columns form an orthonormal basis for the span of the matrix.
This is just the complement of the nullspace. See DMatrix#nullspace.
Decompose into
z * t * z.t
where z is orthogonal and t is quasi upper-diagonal. real and imag contain the respective eigenvalues in the format described in DMatrix#eigensystem.
Returns the singleton class of the object. Convenient for setting the default_epsilon on a per-object basis.
b = DMatrix.rand(4, 4)
a = b.map { |e| e + 0.0001 }
a.class.default_epsilon # => 1e-8
a =~ b # => false
a.singleton_class.default_epsilon = 0.001
a =~ b # => true
Decompose the m x n matrix into
u * s * vt
where u and vt are orthogonal matrices and s is an m x n matrix whose non-diagonal elements are all zero. The diagonal elements of s are called the singular values of the matrix. If called with
m.singular_value_decomposition(:diagonalize => false)
then s is a vector of singular values rather than a diagonal matrix.
May raise Diverged.
Returns a vector containing the singular values of the matrix. See DMatrix#singular_value_decomposition.
Tests whether the matrix is symmetric within epsilon
Create an array from the matrix
a = m.to_a
is equivalent to
a = Array.new(m.vsize) { Array.new(m.hsize) }
m.each_index { |i,j|
a[i][j] = m[i,j]
}
Actual pointer value of the matrix data. Subject to change after a bang (!) operation. This is called by the Lapack module.
Test if each matrix element is within epsilon of the respective matrix element of other.