Triplet Format for Sparse Matrices

2024-06-10 22:18
文章标签 format sparse triplet matrices

本文主要是介绍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

$\displaystyle \left[ \begin{array}{ccccccc} 1.1 & 0 & 0 & 0 & 0 & 0 & 0.5 \ 0 ......0 & 0 & 0 & 0.4 & 0 & 0 \ 0 & 0 & 0 & 0 & 0 & 0.9 & 1.7 \ \end{array} \right]$(14)

A standard dense matrix representation would need to store $ 7 \cdot7{=} 49$ 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 $ 14$ integers for the rows, $ 14$ integers for the columns, and $ 14$ floating point numbers for the values. While this does not seem like a huge space saving over the $ 49$ 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,

$\displaystyle \left[ \begin{array}{ccccccc} 1.0 & 0 & 3.0 & 0 & 2.0 \ 0 & 1.1 ......& 0 \ 0 & 0 & 6.0 & 1.3 & 9.0 \ 2.0 & 5.0 & 0 & 9.0 & 1.4 \end{array} \right]$(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  $ n \times n$ matrix, the dense representation grows with the the square of $ n$ , while the sparse representation grows linearly in the number of nonzeros.

这篇关于Triplet Format for Sparse Matrices的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1049420

相关文章

瑞芯微Parameter File Format解析

Rockchip android系统平台使用parameter文件来配置一些系统参数 主要包含:串口号:nandflash分区 固件版本,按键信息等; 如下是台电P98HD的parameter参数: FIRMWARE_VER:4.1.1        // 固件版本 //固件版本,打包 updata.img 时会使用到,升级工具会根据这个识别固件版本。 //Boot loader 会读取

【DL--04】深度学习基本概念—data_format

data_format 这是一个无可奈何的问题,在如何表示一组彩色图片的问题上,Theano和TensorFlow发生了分歧,’th’模式,也即Theano模式会把100张RGB三通道的16×32(高为16宽为32)彩色图表示为下面这种形式(100,3,16,32),Caffe采取的也是这种方式。第0个维度是样本维,代表样本的数目,第1个维度是通道维,代表颜色通道数。后面两个就是高和宽了。这种t

【稀疏矩阵】使用torch.sparse模块

文章目录 稀疏矩阵的格式coocsrcsc Construction of Sparse COO tensorsConstruction of CSR tensorsLinear Algebra operations(稀疏与稠密之间混合运算)Tensor methods and sparse(与稀疏有关的tensor成员函数)coo张量可用的tensor成员函数(经实测,csr也有一些可以用

String.format简单写法简单用

public String toString() {return String.format("Pair[key=%s, value=%s]", this.m_key, this.m_value);} public static String format(String format, Object... args) {return new Formatter().format(format,

BM3D--Image Denoising by Sparse 3-D Transform-Domain Collaborative Filtering

系列文章目录 文章目录 系列文章目录前言稀疏三维变换域协同滤波图像去噪摘要1 引言2 分组和协作过滤A.分组B.按匹配分组C.协同过滤D.基于变换域收缩的协同过滤 3 算法结论 前言 论文地址 如果下载不了可以从 https://download.csdn.net/download/m0_70420861/89708940 获取 参考博客 :图像去噪算法:NL-Me

MySQL变量-binlog_format:决定binlog的存储格式v1

1 global和session都可 2 三个值: STATEMENT:sql语句的格式 ROW:具体数据行记录的格式 MIXED:混合格式

10-python格式化字符串的四种方法(%,format,f-string,string template)

3 f-string (格式化字符串) in Python 自 Python 3.6 引入以来,f-string 提供了一种更加简洁和直观的方式来进行字符串格式化。其语法简单明了:只需在字符串前加上字母 f 或 F,并在字符串中使用 {} 来包裹需要插入的内容。 它相比于之前的%格式化和字符串format方法写起来更简洁 f-string 也可以用大写F开头或者与 r 原始字符串结合使

九度考研真题 浙大 2011-1浙大1001:A+B for Matrices

//题目1001:A+B for Matrices #include<iostream> #include<string.h> using namespace std; int main() { int M,N; int a1[11][11],a2[11][11]; int a_s[11],b_s[11]; int num=0; while(cin

论文笔记:Estimating future human trajectories from sparse time series data

sigspatial 2023 humob竞赛paper hiimryo816/humob2023-MOBB (github.com) 1 数据集分析 这里只分享了HuMob数据集1的内容 1.1 假日分析 对HuMob数据集#1地理数据的方差分析显示了非工作日的模式 在某些天的y坐标方差中有显著的峰值,这是非工作日的象征【x坐标有相似的模式】 ——>识别了任务1数据集中最有可能是

String.format常用方法

System.out.println(String.format("不够3位前面补0:%03d%n", 7));//007System.out.println(String.format("整数按3位分组:%,d%n", 9989997));//9,989,997System.out.println(String.format("空格50,结果保留5位小数:%50.5f元%n", 49.8