Add utility functions for banded-then-dense symmetric matrices.

PiperOrigin-RevId: 528757637
Change-Id: I916d843140322c28e857100a6b305a041f704d53
This commit is contained in:
Yuval Tassa
2023-05-02 05:57:22 -07:00
committed by Copybara-Service
parent 2ad82d5998
commit b0bc330b54
13 changed files with 1147 additions and 10 deletions
+96 -1
View File
@@ -2748,7 +2748,7 @@ mju_cholSolve
.. mujoco-include:: mju_cholSolve
Solve mat * res = vec, where mat is Cholesky-factorized
Solve (mat*mat') * res = vec, where mat is a Cholesky factor.
.. _mju_cholUpdate:
@@ -2759,6 +2759,101 @@ mju_cholUpdate
Cholesky rank-one update: L*L' +/- x*x'; return rank.
.. _mju_cholFactorBand:
mju_cholFactorBand
~~~~~~~~~~~~~~~~~~
.. mujoco-include:: mju_cholFactorBand
Band-dense Cholesky decomposition.
|br| Add ``diagadd + diagmul*mat_ii`` to diagonal before decomposition.
|br| Returns the minimum value of the factorized diagonal or 0 if rank-defficient.
**Symmetric band-dense matrices**
:ref:`mju_cholFactorBand` and subsequent functions containing the substring "band" operate on matrices which are a
generalization of symmetric `band matrices <https://en.wikipedia.org/wiki/Band_matrix>`_. *Symmetric band-dense* or
"arrowhead" matrices have non-zeros along proximal diagonal bands and dense blocks on the bottom rows and right
columns. These matrices have the property that Cholesky factorization creates no fill-in and can therefore be
performed efficiently in-place. Matrix structure is defined by three integers:
- ``ntotal``: the number of rows (columns) of the symmetric matrix.
- ``nband``: the number of bands under (over) the diagonal, inclusive of the diagonal.
- ``ndense``: the number of dense rows (columns) at the bottom (right).
The non-zeros are stored in memory as two contiguous row-major blocks, colored green and blue in the illustration
below. The first block has size ``nband x (ntotal-ndense)`` and contains the diagonal and the bands below it. The
second block has size ``ndense x ntotal`` and contains the dense part. Total required memory is the sum of the block
sizes.
.. figure:: /images/APIreference/arrowhead.svg
:width: 750px
:align: left
For example, consider an arrowhead matrix with ``nband = 3``, ``ndense = 2`` and ``ntotal = 8``. In this example, the
total memory required is ``3*(8-2) + 2*8 = 34`` mjtNum's, laid out as follows:
.. code-block::
0 1 2
3 4 5
6 7 8
9 10 11
12 13 14
15 16 17
18 19 20 21 22 23 24 25
26 27 28 29 30 31 32 33
The diagonal elements are ``2, 5, 8, 11, 14, 17, 24, 33``.
|br| Elements ``0, 1, 3, 25`` are present in memory but never touched.
.. _mju_cholSolveBand:
mju_cholSolveBand
~~~~~~~~~~~~~~~~~
.. mujoco-include:: mju_cholSolveBand
Solve (mat*mat')*res = vec where mat is a band-dense Cholesky factor.
.. _mju_band2Dense:
mju_band2Dense
~~~~~~~~~~~~~~
.. mujoco-include:: mju_band2Dense
Convert banded matrix to dense matrix, fill upper triangle if flg_sym>0.
.. _mju_dense2Band:
mju_dense2Band
~~~~~~~~~~~~~~
.. mujoco-include:: mju_dense2Band
Convert dense matrix to banded matrix.
.. _mju_bandMulMatVec:
mju_bandMulMatVec
~~~~~~~~~~~~~~~~~
.. mujoco-include:: mju_bandMulMatVec
Multiply band-diagonal matrix with nvec vectors, include upper triangle if flg_sym>0.
.. _mju_bandDiag:
mju_bandDiag
~~~~~~~~~~~~
.. mujoco-include:: mju_bandDiag
Address of diagonal element i in band-dense matrix representation.
.. _mju_eig3:
mju_eig3
+45
View File
@@ -321,6 +321,51 @@ mju_ceil
.. _Decompositions:
.. _mju_cholFactorBand:
Band-dense Cholesky decomposition.
|br| Add ``diagadd + diagmul*mat_ii`` to diagonal before decomposition.
|br| Returns the minimum value of the factorized diagonal or 0 if rank-defficient.
**Symmetric band-dense matrices**
:ref:`mju_cholFactorBand` and subsequent functions containing the substring "band" operate on matrices which are a
generalization of symmetric `band matrices <https://en.wikipedia.org/wiki/Band_matrix>`_. *Symmetric band-dense* or
"arrowhead" matrices have non-zeros along proximal diagonal bands and dense blocks on the bottom rows and right
columns. These matrices have the property that Cholesky factorization creates no fill-in and can therefore be
performed efficiently in-place. Matrix structure is defined by three integers:
- ``ntotal``: the number of rows (columns) of the symmetric matrix.
- ``nband``: the number of bands under (over) the diagonal, inclusive of the diagonal.
- ``ndense``: the number of dense rows (columns) at the bottom (right).
The non-zeros are stored in memory as two contiguous row-major blocks, colored green and blue in the illustration
below. The first block has size ``nband x (ntotal-ndense)`` and contains the diagonal and the bands below it. The
second block has size ``ndense x ntotal`` and contains the dense part. Total required memory is the sum of the block
sizes.
.. figure:: /images/APIreference/arrowhead.svg
:width: 750px
:align: left
For example, consider an arrowhead matrix with ``nband = 3``, ``ndense = 2`` and ``ntotal = 8``. In this example, the
total memory required is ``3*(8-2) + 2*8 = 34`` mjtNum's, laid out as follows:
.. code-block::
0 1 2
3 4 5
6 7 8
9 10 11
12 13 14
15 16 17
18 19 20 21 22 23 24 25
26 27 28 29 30 31 32 33
The diagonal elements are ``2, 5, 8, 11, 14, 17, 24, 33``.
|br| Elements ``0, 1, 3, 25`` are present in memory but never touched.
.. _mju_boxQP:
Minimize :math:`\tfrac{1}{2} x^T H x + x^T g \quad \text{s.t.} \quad l \le x \le u`, return rank or -1 if failed.
+13 -5
View File
@@ -5,18 +5,26 @@ Changelog
Upcoming version (not yet released)
-----------------------------------
Plugins
^^^^^^^
.. youtube:: hqIMTNGaLF4
:align: right
:width: 240px
Plugins
^^^^^^^
- Added touch-grid sensor plugin. See `documentation <https://github.com/deepmind/mujoco/blob/main/plugin/sensor/README.md>`_
for details, and associated `touch_grid.xml <https://github.com/deepmind/mujoco/blob/main/model/plugin/touch_grid.xml>`_
example model. The plugin includes `in-scene visualisation <https://youtu.be/0LOJ3WMnqeA>`_.
- Add ``mj_multiRay`` function for intersecting multiple rays emanating from a single point. This is significantly
faster than calling ``mj_ray`` multiple times.
General
^^^^^^^
- Added :ref:`mjd_inverseFD` for finite-differenced inverse-dynamics derivatives.
- Added functions for operations on banded-then-dense "arrowhead" matrices. Such matrices are
common when doing direct trajectory optimization.
See :ref:`mju_cholFactorBand` documentation for details.
- Added :ref:`mj_multiRay` function for intersecting multiple rays emanating from a single point.
This is significantly faster than calling :ref:`mj_ray` multiple times.
Version 2.3.5 (April 25, 2023)
------------------------------
File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 17 KiB

+10
View File
@@ -2408,6 +2408,16 @@ void mju_trnVecPose(mjtNum res[3], const mjtNum pos[3], const mjtNum quat[4],
int mju_cholFactor(mjtNum* mat, int n, mjtNum mindiag);
void mju_cholSolve(mjtNum* res, const mjtNum* mat, const mjtNum* vec, int n);
int mju_cholUpdate(mjtNum* mat, mjtNum* x, int n, int flg_plus);
mjtNum mju_cholFactorBand(mjtNum* mat, int ntotal, int nband, int ndense,
mjtNum diagadd, mjtNum diagmul);
void mju_cholSolveBand(mjtNum* res, const mjtNum* mat, const mjtNum* vec,
int ntotal, int nband, int ndense);
void mju_band2Dense(mjtNum* res, const mjtNum* mat, int ntotal, int nband, int ndense,
mjtByte flg_sym);
void mju_dense2Band(mjtNum* res, const mjtNum* mat, int ntotal, int nband, int ndense);
void mju_bandMulMatVec(mjtNum* res, const mjtNum* mat, const mjtNum* vec,
int ntotal, int nband, int ndense, int nvec, mjtByte flg_sym);
int mju_bandDiag(int i, int ntotal, int nband, int ndense);
int mju_eig3(mjtNum eigval[3], mjtNum eigvec[9], mjtNum quat[4], const mjtNum mat[9]);
int mju_boxQP(mjtNum* res, mjtNum* R, int* index, const mjtNum* H, const mjtNum* g, int n,
const mjtNum* lower, const mjtNum* upper);