Triplet Format for Sparse Matrices

Posted kaluotee

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Triplet Format for Sparse Matrices相关的知识,希望对你有一定的参考价值。

原网站http://www.coin-or.org/Ipopt/documentation/node37.html
Triplet Format for Sparse Matrices

I POPT  was designed for optimizing large sparse nonlinear programs. Because of problem sparsity, the required matrices (like the constraints Jacobian or Lagrangian Hessian) are not stored as dense matrices, but rather in a sparse matrix format. For the tutorials in this document, we use the triplet format. Consider the matrix

(14)

A standard dense matrix representation would need to store  floating point numbers, where many entries would be zero. In triplet format, however, only the nonzero entries are stored. The triplet format records the row number, the column number, and the value of all nonzero entries in the matrix. For the matrix above, this means storing  integers for the rows,  integers for the columns, and  floating point numbers for the values. While this does not seem like a huge space saving over the  floating point numbers stored in the dense representation, for larger matrices, the space savings are very dramatic24.

The parameter index_style in get_nlp_info tells IPOPT if you prefer to use C style indexing (0-based, i.e., starting the counting at 0) for the row and column indices or Fortran style (1-based). Tables 3 and 4 below show the triplet format for both indexing styles, using the example matrix (14).


Table 3: Triplet Format of Matrix ( 14) with  index_style=FORTRAN_STYLE
rowcolvalue
iRow[0] = 1jCol[0] = 1values[0] = 1.1
iRow[1] = 1jCol[1] = 7values[1] = 0.5
iRow[2] = 2jCol[2] = 2values[2] = 1.9
iRow[3] = 2jCol[3] = 7values[3] = 0.5
iRow[4] = 3jCol[4] = 3values[4] = 2.6
iRow[5] = 3jCol[5] = 7values[5] = 0.5
iRow[6] = 4jCol[6] = 3values[6] = 7.8
iRow[7] = 4jCol[7] = 4values[7] = 0.6
iRow[8] = 5jCol[8] = 4values[8] = 1.5
iRow[9] = 5jCol[9] = 5values[9] = 2.7
iRow[10] = 6jCol[10] = 1values[10] = 1.6
iRow[11] = 6jCol[11] = 5values[11] = 0.4
iRow[12] = 7jCol[12] = 6values[12] = 0.9
iRow[13] = 7jCol[13] = 7values[13] = 1.7



Table 4: Triplet Format of Matrix ( 14) with  index_style=C_STYLE
rowcolvalue
iRow[0] = 0jCol[0] = 0values[0] = 1.1
iRow[1] = 0jCol[1] = 6values[1] = 0.5
iRow[2] = 1jCol[2] = 1values[2] = 1.9
iRow[3] = 1jCol[3] = 6values[3] = 0.5
iRow[4] = 2jCol[4] = 2values[4] = 2.6
iRow[5] = 2jCol[5] = 6values[5] = 0.5
iRow[6] = 3jCol[6] = 2values[6] = 7.8
iRow[7] = 3jCol[7] = 3values[7] = 0.6
iRow[8] = 4jCol[8] = 3values[8] = 1.5
iRow[9] = 4jCol[9] = 4values[9] = 2.7
iRow[10] = 5jCol[10] = 0values[10] = 1.6
iRow[11] = 5jCol[11] = 4values[11] = 0.4
iRow[12] = 6jCol[12] = 5values[12] = 0.9
iRow[13] = 6jCol[13] = 6values[13] = 1.7


The individual elements of the matrix can be listed in any order, and if there are multiple items for the same nonzero position, the values provided for those positions are added.

The Hessian of the Lagrangian is a symmetric matrix. In the case of a symmetric matrix, you only need to specify the lower left triangular part (or, alternatively, the upper right triangular part). For example, given the matrix,

(15)

the triplet format is shown in Tables  5  and  6 .


Table 5: Triplet Format of Matrix ( 15) with  index_style=FORTRAN_STYLE
rowcolvalue
iRow[0] = 1jCol[0] = 1values[0] = 1.0
iRow[1] = 2jCol[1] = 1values[1] = 1.1
iRow[2] = 3jCol[2] = 1values[2] = 3.0
iRow[3] = 3jCol[3] = 3values[3] = 1.2
iRow[4] = 4jCol[4] = 3values[4] = 6.0
iRow[5] = 4jCol[5] = 4values[5] = 1.3
iRow[6] = 5jCol[6] = 1values[6] = 2.0
iRow[7] = 5jCol[7] = 2values[7] = 5.0
iRow[8] = 5jCol[8] = 4values[8] = 9.0
iRow[9] = 5jCol[9] = 5values[9] = 1.4




Table 6: Triplet Format of Matrix ( 15) with  index_style=C_STYLE
rowcolvalue
iRow[0] = 0jCol[0] = 0values[0] = 1.0
iRow[1] = 1jCol[1] = 0values[1] = 1.1
iRow[2] = 2jCol[2] = 0values[2] = 3.0
iRow[3] = 2jCol[3] = 2values[3] = 1.2
iRow[4] = 3jCol[4] = 2values[4] = 6.0
iRow[5] = 3jCol[5] = 3values[5] = 1.3
iRow[6] = 4jCol[6] = 0values[6] = 2.0
iRow[7] = 4jCol[7] = 1values[7] = 5.0
iRow[8] = 4jCol[8] = 3values[8] = 9.0
iRow[9] = 4jCol[9] = 4values[9] = 1.4




Footnotes


For an   matrix, the dense representation grows with the the square of  , while the sparse representation grows linearly in the number of nonzeros.

       
Next:  The Smart Pointer Implementation:  Up:  Introduction to IPOPT: A Previous:  Diagnostic Tags for IPOPT    Contents

以上是关于Triplet Format for Sparse Matrices的主要内容,如果未能解决你的问题,请参考以下文章

Special Pythagorean triplet

Paper Reading: In Defense of the Triplet Loss for Person Re-Identification

334. Increasing Triplet Subsequence

pyg安装——ERROR: Failed building wheel for torch-sparse

使用 scipy.sparse.bmat 从子块创建非常大的稀疏矩阵时出错

论文学习-sparse methods for direction of arrival estimation1.