(assoc-column m column numbers)
Sets a column in a matrix using the specified numbers.
Sets a column in a matrix using the specified numbers.
(assoc-diagonal m numbers)
Sets a diagonal in a matrix using the specified numbers.
Sets a diagonal in a matrix using the specified numbers.
(assoc-row m row numbers)
Sets a row in a matrix using the specified numbers.
Sets a row in a matrix using the specified numbers.
(column-matrix numbers)
(column-matrix size row->number)
Returns a column matrix created from numbers
or from size
and
row->number
. size
is the size of the returned matrix. Function
row->number
takes a row and returns a number.
Returns a column matrix created from `numbers` or from `size` and `row->number`. `size` is the size of the returned matrix. Function `row->number` takes a row and returns a number.
(column-matrix? x)
Returns true if a column-matrix (i.e., matrix with exactly one column).
Returns true if a column-matrix (i.e., matrix with exactly one column).
(columns m)
Returns the number of columns.
Returns the number of columns.
(compute-matrix rows columns row+column->number)
Function row+column->number
takes a row
and column
and returns a
number.
Function `row+column->number` takes a `row` and `column` and returns a number.
(concat-columns)
(concat-columns m & ms)
Appends columns from all the matrices after the first to the first. Each matrix's row count must be the same or will return nil.
Appends columns from all the matrices after the first to the first. Each matrix's row count must be the same or will return nil.
(concat-rows)
(concat-rows m & ms)
Appends rows from all the matrices after the first to the first. Each matrix's column count must be the same or will return nil.
Appends rows from all the matrices after the first to the first. Each matrix's column count must be the same or will return nil.
(constant-matrix rows columns)
(constant-matrix rows columns number)
Constructs a new matrix of value
's (or zeros (doubles)) with the given
rows
and columns
.
Constructs a new matrix of `value`'s (or zeros (doubles)) with the given `rows` and `columns`.
(deserialize-lower-triangular-matrix numbers)
(deserialize-lower-triangular-matrix numbers
{:provisdom.math.matrix/keys [by-row?]
:or {by-row? true}})
(deserialize-lower-triangular-matrix diagonal-numbers
off-diagonal-numbers
{:provisdom.math.matrix/keys [by-row?]
:or {by-row? true}})
Returns a (square) lower triangular matrix (a matrix with all elements above
the diagonal being 0.0). numbers
are the elements that will be used to
create the lower triangular matrix. off-diagonal-numbers
can be used to
create the off-diagonal elements, and then any existing diagonal-numbers
will fill the diagonal elements. The elements are placed by-row?
(default is
true).
Returns a (square) lower triangular matrix (a matrix with all elements above the diagonal being 0.0). `numbers` are the elements that will be used to create the lower triangular matrix. `off-diagonal-numbers` can be used to create the off-diagonal elements, and then any existing `diagonal-numbers` will fill the diagonal elements. The elements are placed `by-row?` (default is true).
(deserialize-symmetric-matrix numbers)
Returns a symmetric matrix (a matrix with elements at r,c equal to elements
at c,r). numbers
are the same as the elements used to create a triangular
matrix.
Returns a symmetric matrix (a matrix with elements at r,c equal to elements at c,r). `numbers` are the same as the elements used to create a triangular matrix.
(deserialize-upper-triangular-matrix numbers)
(deserialize-upper-triangular-matrix numbers
{:provisdom.math.matrix/keys [by-row?]
:or {by-row? true}})
(deserialize-upper-triangular-matrix diagonal-numbers
off-diagonal-numbers
{:provisdom.math.matrix/keys [by-row?]
:or {by-row? true}})
Returns a (square) upper triangular matrix (a matrix with all elements below
the diagonal being 0.0). numbers
are the elements that will be used to
create the upper triangular matrix. off-diagonal-numbers
can be used to
create the off-diagonal elements, and then any existing diagonal-numbers
will fill the diagonal elements. The elements are placed by-row?
(default
is true).
Returns a (square) upper triangular matrix (a matrix with all elements below the diagonal being 0.0). `numbers` are the elements that will be used to create the upper triangular matrix. `off-diagonal-numbers` can be used to create the off-diagonal elements, and then any existing `diagonal-numbers` will fill the diagonal elements. The elements are placed `by-row?` (default is true).
(diagonal m)
(diagonal m k)
Returns the specified diagonal of a matrix as a vector. If k
>0, returns a
diagonal above the main diagonal. If k
<0, returns a diagonal below the main
diagonal. Works on both square and rectangular matrices.
Returns the specified diagonal of a matrix as a vector. If `k`>0, returns a diagonal above the main diagonal. If `k`<0, returns a diagonal below the main diagonal. Works on both square and rectangular matrices.
(diagonal-matrix diagonal-numbers)
(diagonal-matrix size index->number)
(diagonal-matrix rows columns index->number)
Returns a diagonal matrix (a matrix with all elements not on the diagonal
being 0.0). The values on the diagonal can be given by the vector
diagonal-numbers
. size
is the size of the matrix given by a single number.
f
is a function that takes index
and returns a number. Can also return a
rectangular diagonal matrix using rows
and columns
.
Returns a diagonal matrix (a matrix with all elements not on the diagonal being 0.0). The values on the diagonal can be given by the vector `diagonal-numbers`. `size` is the size of the matrix given by a single number. `f` is a function that takes `index` and returns a number. Can also return a rectangular diagonal matrix using `rows` and `columns`.
(diagonal-matrix? x)
Returns true if a diagonal matrix (the entries outside the main diagonal are all zero).
Returns true if a diagonal matrix (the entries outside the main diagonal are all zero).
(ecount-of-symmetric-or-triangular-matrix size)
Returns the element count (ecount
) for a symmetric or triangular matrix.
This is the number of elements on the diagonal plus the number of elements
above or below the diagonal.
Returns the element count (`ecount`) for a symmetric or triangular matrix. This is the number of elements on the diagonal plus the number of elements above or below the diagonal.
(ecount-of-symmetric-or-triangular-matrix-without-diagonal size)
Returns the element count (ecount
) for a symmetric or triangular matrix
without the diagonal. This is the number of elements above or below the
diagonal.
Returns the element count (`ecount`) for a symmetric or triangular matrix without the diagonal. This is the number of elements above or below the diagonal.
(empty-matrix? x)
Returns true if the matrix is an empty matrix.
Returns true if the matrix is an empty matrix.
(ereduce-kv f init m)
(ereduce-kv f init m1 m2)
(ereduce-kv f init m1 m2 m3)
Function f
takes a result, row, column, and number(s). Reduces over 1, 2,
or 3 matrices. Number of columns in the first matrix must be the least.
Function `f` takes a result, row, column, and number(s). Reduces over 1, 2, or 3 matrices. Number of columns in the first matrix must be the least.
(filter-by-column column-v->bool m)
Returns a matrix. Function 'column-v->bool' takes a column-vector.
Returns a matrix. Function 'column-v->bool' takes a column-vector.
(filter-by-row row-v->bool m)
Returns a matrix. Function 'row-v->bool' takes a row-vector.
Returns a matrix. Function 'row-v->bool' takes a row-vector.
(filter-symmetric-matrix v->bool symmetric-m)
Takes and returns a symmetric matrix. 'v->bool' takes a row-vector or column-vector.
Takes and returns a symmetric matrix. 'v->bool' takes a row-vector or column-vector.
(get-column m column)
Gets a column
of a matrix, as a vector.
Gets a `column` of a matrix, as a vector.
(get-row m row)
Gets a row
of a matrix, as a vector.
Gets a `row` of a matrix, as a vector.
(get-slices-as-matrix m
{:provisdom.math.matrix/keys [row-indices column-indices
exception-row-indices
exception-column-indices]})
Performs a slice on the matrix given by the options.
Options:
::row-indices
returns all rows by default, can pass a row index or
sequence of row indices
::column-indices
returns all columns by default, can pass a column index
or sequence of column indices
::exception-row-indices
can pass a row index or sequence of row indices
to exclude
::exception-column-indices
can pass a column index or sequence of column
indices to exclude.
Exceptions override inclusions. Can be used to permute matrix through index
sequence ordering.
Performs a slice on the matrix given by the options. Options: `::row-indices` returns all rows by default, can pass a row index or sequence of row indices `::column-indices` returns all columns by default, can pass a column index or sequence of column indices `::exception-row-indices` can pass a row index or sequence of row indices to exclude `::exception-column-indices` can pass a column index or sequence of column indices to exclude. Exceptions override inclusions. Can be used to permute matrix through index sequence ordering.
(identity-matrix size)
Constructs an identity matrix with the given size
.
Constructs an identity matrix with the given `size`.
(insert-column m column numbers)
Inserts a column of numbers
in a matrix at the specified column
.
Inserts a column of `numbers` in a matrix at the specified `column`.
(insert-row m row numbers)
Inserts a row of numbers
in a matrix at the specified row
.
Inserts a row of `numbers` in a matrix at the specified `row`.
(kronecker-product)
(kronecker-product m)
(kronecker-product m1 m2)
(kronecker-product m1 m2 & ms)
Generalization of the outer product.
Generalization of the outer product.
(lower-triangular-matrix? x)
Returns true if a lower triangular matrix (the entries above the main diagonal are all zero).
Returns true if a lower triangular matrix (the entries above the main diagonal are all zero).
(matrix->sparse m)
(matrix->sparse m number->bool)
Returns a sparse-matrix (i.e., a vector of tuples of [row column number]).
Function number->bool
takes a number.
Returns a sparse-matrix (i.e., a vector of tuples of [row column number]). Function `number->bool` takes a number.
(matrix-finite-non-? x)
Returns true if a matrix of finite non-negative numbers.
Returns true if a matrix of finite non-negative numbers.
(matrix-finite? x)
Returns true if a matrix of finite numbers.
Returns true if a matrix of finite numbers.
(matrix-num? x)
Returns true if a matrix of num (numbers without NaN).
Returns true if a matrix of num (numbers without NaN).
(matrix-partition m first-bottom-row first-right-column)
Returns a map containing the four sub-matrices labeled ::top-left
,
::bottom-left
, ::top-right
, and ::bottom-right
. Matrices can be merged
back together using merge-matrices
. first-bottom-row
is the bottom of
where the slice will occur. first-right-column
is the right edge of where
the slice will occur.
Returns a map containing the four sub-matrices labeled `::top-left`, `::bottom-left`, `::top-right`, and `::bottom-right`. Matrices can be merged back together using [[merge-matrices]]. `first-bottom-row` is the bottom of where the slice will occur. `first-right-column` is the right edge of where the slice will occur.
(matrix-prob? x)
Returns true if a matrix of probabilities.
Returns true if a matrix of probabilities.
(matrix? x)
Returns true if a matrix (i.e., dimensionality is 2, contains numbers only, rows have equal positive lengths unless the empty matrix.)
Returns true if a matrix (i.e., dimensionality is 2, contains numbers only, rows have equal positive lengths unless the empty matrix.)
(merge-matrices {:provisdom.math.matrix/keys [top-left bottom-left top-right
bottom-right]})
Returns a Matrix created by binding four matrices together. Matrices can be
partitioned into four matrices using matrix-partition
. Takes a map
containing keys:
::top-left
::bottom-left
::top-right
::bottom-right
.
Returns a Matrix created by binding four matrices together. Matrices can be partitioned into four matrices using [[matrix-partition]]. Takes a map containing keys: `::top-left` `::bottom-left` `::top-right` `::bottom-right`.
(mx* m)
(mx* m1 m2)
(mx* m1 m2 & ms)
Matrix multiplication. Number of columns of the first matrix must match the number of rows of the second matrix. Use [tensor/multiply] for more general multiplication.
Matrix multiplication. Number of columns of the first matrix must match the number of rows of the second matrix. Use [tensor/multiply] for more general multiplication.
(outer-product v)
An outer product is the tensor product of two coordinate vectors, a special case of the Kronecker product of matrices. The outer product of two coordinate vectors is a matrix such that the coordinates satisfy w_ij = u_i × u_j.
An outer product is the tensor product of two coordinate vectors, a special case of the Kronecker product of matrices. The outer product of two coordinate vectors is a matrix such that the coordinates satisfy w_ij = u_i × u_j.
(remove-column m column)
Removes a column in a matrix
Removes a column in a matrix
(remove-row m row)
Removes a row in a matrix
Removes a row in a matrix
(replace-submatrix m submatrix row-start column-start)
Returns a Matrix after substituting a submatrix
at top-left location
row-start
and column-start
. row-start
and column-start
can be
negative. Unassigned elements will be 0.0.
Returns a Matrix after substituting a `submatrix` at top-left location `row-start` and `column-start`. `row-start` and `column-start` can be negative. Unassigned elements will be 0.0.
(rnd-matrix! rows columns)
Returns matrix with random elements.
Returns matrix with random elements.
(rnd-reflection-matrix! size)
Returns a random Householder reflection matrix of size
.
Returns a random Householder reflection matrix of `size`.
(rnd-spectral-matrix! spectrum-vector)
Returns a random matrix with a particular spectrum-vector
. The orthogonal
matrices are generated by using 2 × size of spectrum-vector
composed
Householder reflections.
Returns a random matrix with a particular `spectrum-vector`. The orthogonal matrices are generated by using 2 × size of `spectrum-vector` composed Householder reflections.
(round-roughly-zero-columns m accu)
Returns a matrix after rounding any roughly-zero columns.
Returns a matrix after rounding any roughly-zero columns.
(round-roughly-zero-rows m accu)
Returns a matrix after rounding any roughly-zero rows.
Returns a matrix after rounding any roughly-zero rows.
(row-matrix numbers)
(row-matrix size column->number)
Returns a row matrix created from numbers
or from size
and
column->number
. size
is the size of the returned matrix. Function
column->number
takes a column
and returns a number.
Returns a row matrix created from `numbers` or from `size` and `column->number`. `size` is the size of the returned matrix. Function `column->number` takes a `column` and returns a number.
(row-matrix? x)
Returns true if a row-matrix (i.e., matrix with exactly one row)
Returns true if a row-matrix (i.e., matrix with exactly one row)
(serialize-symmetric-or-triangular-matrix m)
(serialize-symmetric-or-triangular-matrix m
{:provisdom.math.matrix/keys [by-row?]
:or {by-row? true}})
Returns a vector that contains the upper (default) or lower half of the
matrix. m
doesn't have to be symmetric. Options: ::by-row?
(default: true). Set to false to get lower triangular values instead of
upper.
Returns a vector that contains the upper (default) or lower half of the matrix. `m` doesn't have to be symmetric. Options: `::by-row?` (default: true). Set to false to get lower triangular values instead of upper.
(size-of-symmetric-or-triangular-matrix ecount)
Returns the size of the matrix given ecount
. ecount
is the number of
independent symmetric or triangular matrix elements (the number of elements on
the diagonal plus the number either above or below the diagonal).
Returns the size of the matrix given `ecount`. `ecount` is the number of independent symmetric or triangular matrix elements (the number of elements on the diagonal plus the number either above or below the diagonal).
(size-of-symmetric-or-triangular-matrix-without-diagonal ecount)
Returns the size of the matrix given ecount
. ecount
is the number of
elements above or below the diagonal.
Returns the size of the matrix given `ecount`. `ecount` is the number of elements above or below the diagonal.
(some-kv pred m)
(some-kv pred m {:provisdom.math.matrix/keys [by-row?] :or {by-row? true}})
Returns the first logical true value of (pred row column number) for any
number in matrix, else nil. Options: ::by-row?
(default: true).
Returns the first logical true value of (pred row column number) for any number in matrix, else nil. Options: `::by-row?` (default: true).
(sparse->matrix sparse m)
Builds a matrix using a sparse representation and an existing matrix (often
a zero-matrix). sparse
is a vector of triples of [row column value]
. Later
values will override prior overlapping values.
Builds a matrix using a sparse representation and an existing matrix (often a zero-matrix). `sparse` is a vector of triples of `[row column value]`. Later values will override prior overlapping values.
(sparse->symmetric-matrix sparse symmetric-m)
Builds a symmetric matrix using a sparse representation and an existing
symmetric matrix (often a zero-matrix). sparse
is a vector of triples of
[row column value]. Later values will override prior overlapping values.
Each off-diagonal inner sparse form is applied twice, with the row and column
switched.
Builds a symmetric matrix using a sparse representation and an existing symmetric matrix (often a zero-matrix). `sparse` is a vector of triples of [row column value]. Later values will override prior overlapping values. Each off-diagonal inner sparse form is applied twice, with the row and column switched.
(square-matrix? x)
Returns true if matrix is square (i.e., same number of rows and columns)
Returns true if matrix is square (i.e., same number of rows and columns)
(symmetric-matrix->sparse symmetric-m)
(symmetric-matrix->sparse symmetric-m number->bool)
Returns a sparse-matrix (i.e., a vector of tuples of [row column number]).
number->bool
takes a number and will be evaluated only for upper-right
triangle of symmetric-m
.
Returns a sparse-matrix (i.e., a vector of tuples of [row column number]). `number->bool` takes a number and will be evaluated only for upper-right triangle of `symmetric-m`.
(symmetric-matrix-by-averaging square-m)
Returns a symmetric matrix where each element above or below the diagonal is equal to the average of the corresponding numbers. This is useful to help with rounding errors.
Returns a symmetric matrix where each element above or below the diagonal is equal to the average of the corresponding numbers. This is useful to help with rounding errors.
(symmetric-matrix? x)
Returns true if a symmetric matrix.
Returns true if a symmetric matrix.
(to-matrix tensor rows)
(to-matrix tensor
rows
{:provisdom.math.matrix/keys [by-row?] :or {by-row? true}})
Builds a matrix representing the flattened elements of tensor
(onto a
matrix of zeros (doubles) if necessary). rows
is the number of rows of the
returned matrix. The elements are placed by-row?
(default is true). To set
the number of columns instead, transpose returned matrix.
Builds a matrix representing the flattened elements of `tensor` (onto a matrix of zeros (doubles) if necessary). `rows` is the number of rows of the returned matrix. The elements are placed `by-row?` (default is true). To set the number of columns instead, transpose returned matrix.
(toeplitz-matrix first-row first-column)
Returns a toeplitz matrix (a matrix whose elements on any diagonal are the
same). A Toeplitz matrix is also called a diagonal-constant matrix.
first-row
is the first row in the matrix and first-column
is the first
column in the matrix.
Returns a toeplitz matrix (a matrix whose elements on any diagonal are the same). A Toeplitz matrix is also called a diagonal-constant matrix. `first-row` is the first row in the matrix and `first-column` is the first column in the matrix.
(trace square-m)
Calculates the trace of a square matrix (sum of elements on main diagonal).
Calculates the trace of a square matrix (sum of elements on main diagonal).
(transpose m)
Transposes a matrix by swapping rows and columns, returning a new matrix.
Transposes a matrix by swapping rows and columns, returning a new matrix.
(update-column m column row+number->number)
Updates a column
of matrix m
, using function row+number->number
, which
is a function the row
and number
and returns a number.
Updates a `column` of matrix `m`, using function `row+number->number`, which is a function the `row` and `number` and returns a number.
(update-diagonal m row+number->number)
Updates the diagonal of matrix m
, using function row+number->number
,
which is a function of the row
and number
and returns a number.
Updates the diagonal of matrix `m`, using function `row+number->number`, which is a function of the `row` and `number` and returns a number.
(update-row m row column+number->number)
Updates a row
of matrix m
, using function column+number->number
, which
is a function of the column
and number
and returns a number.
Updates a `row` of matrix `m`, using function `column+number->number`, which is a function of the `column` and `number` and returns a number.
(upper-triangular-matrix? x)
Returns true if an upper triangular matrix (the entries below the main diagonal are all zero).
Returns true if an upper triangular matrix (the entries below the main diagonal are all zero).
(zero-matrix? x)
Returns true if all the elements of the matrix are zeros.
Returns true if all the elements of the matrix are zeros.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close