找回密码
 注册
查看: 6802|回复: 0

R语言:sparseMatrix()函数中文帮助文档(中英文对照)

[复制链接]
发表于 2012-2-17 10:04:22 | 显示全部楼层 |阅读模式
sparseMatrix(Matrix)
sparseMatrix()所属R语言包:Matrix

                                        General Sparse Matrix Construction from Nonzero Entries
                                         一般稀疏矩阵非零建设

                                         译者:生物统计家园网 机器人LoveR

描述----------Description----------

User friendly construction of a compressed, column-oriented, sparse matrix, inheriting from class CsparseMatrix, from locations (and values) of its nonzero entries.
用户友好的建设,面向列压缩,稀疏矩阵,继承classCsparseMatrix,其非零元素的位置(和值)。

This is the recommended user interface rather than direct new("***Matrix", ....) calls.
这是建议,而不是直接new("***Matrix", ....)电话的用户界面。


用法----------Usage----------


sparseMatrix(i = ep, j = ep, p, x, dims, dimnames,
             symmetric = FALSE, index1 = TRUE,
             giveCsparse = TRUE, check = TRUE)



参数----------Arguments----------

参数:i,j
integer vectors of the same length specifying the locations (row and column indices) of the non-zero (or non-TRUE) entries of the matrix.
相同长度的整数向量指定的位置(行和列)非零(非TRUE)项的矩阵。


参数:p
numeric (integer valued) vector of pointers, one for each column (or row), to the initial (zero-based) index of elements in the column (or row).  Exactly one of i, j or p must be missing.
数字(整型值)指针,为每列(或行)向量,初始(从零开始)索引的列(或行)中的元素。恰好一个i,j或p必须失踪。


参数:x
optional values of the matrix entries.  If specified, must be of the same length as i / j, or of length one where it will be recycled to full length.  If missing, the resulting matrix will be a 0/1 pattern matrix, i.e., extending class nsparseMatrix.  
矩阵条目的可选值。如果指定,必须是具有相同长度的i/j,或它将被回收到全长的长度。如果缺少,由此产生的矩阵将是一个0/1模式矩阵,即,扩展类nsparseMatrix。


参数:dims
optional, non-negative, integer, dimensions vector of length 2.  Defaults to c(max(i), max(j)).
可选,非负整数,维向量长度为2。 c(max(i), max(j))默认。


参数:dimnames
optional list of dimnames; if not specified, none, i.e., NULL ones, are used.
可选列表dimnames;如果没有指定,没有,即NULL的,是用来。


参数:symmetric
logical indicating if the resulting matrix should be symmetric.  In that case, only the lower or upper triangle needs to be specified via (i/j/p).
逻辑表示如果矩阵是对称的。在这种情况下,只有较低或较高的三角形需要通过(i/j/p)指定。


参数:index1
logical scalar.  If TRUE, the default, the index vectors i and/or j are 1-based, as is the convention in R.  That is, counting of rows and columns starts at 1.  If FALSE the index vectors are 0-based so counting of rows and columns starts at 0; this corresponds to the internal representation.
逻辑标量。如果TRUE,默认情况下,索引向量i和/或j1,是在R的惯例,也就是说,行和列计数从1开始。如果FALSE指数向量0的基础,所以从0开始计数的行和列;此相对应的内部表示。


参数:giveCsparse
logical indicating if the result should be a CsparseMatrix or a TsparseMatrix.  The default, TRUE is very often more efficient subsequently, but not always.
逻辑表示,如果结果应该是一个CsparseMatrix或TsparseMatrix。默认情况下,TRUE往往更有效率其后,但并不总是。


参数:check
logical indicating if a validity check is performed; do not set to FALSE unless you know what you're doing!
逻辑表示的有效性进行检查,如果没有设置FALSE除非你知道你在做什么!


Details

详情----------Details----------

Exactly one of the arguments i, j and p must be missing.
确切的论据之一i,j和p必须失踪。

In typical usage, p is missing, i and j are vectors of positive integers and x is a numeric vector.  These three vectors, which must have the same length, form the triplet representation of the sparse matrix.
在典型的用法,p丢失,i和j是正整数向量和x是一个数字的向量。这三个向量,必须具有相同的长度,形成三重稀疏矩阵表示。

If i or j is missing then p must be a non-decreasing integer vector whose first element is zero.  It provides the compressed, or &ldquo;pointer&rdquo; representation of the row or column indices, whichever is missing.  The expanded form of p, rep(seq_along(dp),dp) where dp <- diff(p), is used as the (1-based) row or column indices.
如果i或j丢失p必须是一个非递减的整数向量,其第一个元素是零。它提供的压缩,或行或列的指数,取其失踪的“指针”表示。扩展形式p,rep(seq_along(dp),dp)其中dp <- diff(p),用于(1)行或列指数。

The values of i, j, p and index1 are used to create 1-based index vectors i and j from which a TsparseMatrix is constructed, with numerical values given by x, if non-missing.  The CsparseMatrix derived from this triplet form is returned.
值i,j,p和index1用于创建基于1的索引向量i和j从 TsparseMatrix构造x,如果非缺失数值。 CsparseMatrix这三重形式的返回。

The reason for returning a CsparseMatrix object instead of the triplet format by default is that the compressed column form is easier to work with when performing matrix operations.  In particular, if there are no zeros in x then a CsparseMatrix is a unique representation of the sparse matrix.
之所以返回一个CsparseMatrix对象,而不是由默认的三重格式是压缩列形式是执行矩阵操作时更容易的工作。特别是,如果有没有在零x然后CsparseMatrix是一个独特的稀疏矩阵表示。


值----------Value----------

A sparse matrix, by default (see giveCsparse) in compressed, column-oriented form, as an R object inheriting from both CsparseMatrix and generalMatrix.
默认情况下,稀疏矩阵(见giveCsparse)在压缩,面向列的形式,既CsparseMatrix和generalMatrix继承作为一个R对象。


参见----------See Also----------

Matrix(*, sparse=TRUE) for the more usual constructor of such matrices; further bdiag and Diagonal for (block-)diagonal and bandSparse for banded sparse matrix constructors.
Matrix(*, sparse=TRUE)这样的矩阵更通常的构造;进一步bdiag和Diagonal(块)对角线和bandSparse带状稀疏矩阵的构造。

Consider CsparseMatrix and similar class definition help files.
考虑CsparseMatrix“类似的类定义帮助文件。


举例----------Examples----------


## simple example[#简单的例子]
i <- c(1,3:8); j <- c(2,9,6:10); x <- 7 * (1:7)
(A <- sparseMatrix(i, j, x = x))
summary(A)
str(A) # note that *internally* 0-based row indices are used[*国内* 0行指数]

## dims can be larger than the maximum row or column indices[#变暗可能大于最大的行或列指数]
(AA <- sparseMatrix(c(1,3:8), c(2,9,6:10), x = 7 * (1:7), dims = c(10,20)))
summary(AA)

## i, j and x can be in an arbitrary order, as long as they are consistent[#I,J和X可以是任意顺序,只要他们是一致的]
set.seed(1); (perm <- sample(1:7))
(A1 <- sparseMatrix(i[perm], j[perm], x = x[perm]))
stopifnot(identical(A, A1))

## the (i,j) pairs can be repeated, in which case the x's are summed[#(I,J)对可重复,在这种情况下,X的总结]
(args <- data.frame(i = c(i, 1), j = c(j, 2), x = c(x, 2)))
(Aa <- do.call(sparseMatrix, args))

dn <- list(LETTERS[1:3], letters[1:5])
## pointer vectors can be used, and the (i,x) slots are sorted if necessary:[#指针向量可以用,如果有必要进行排序(I,X)插槽:]
m <- sparseMatrix(i = c(3,1, 3:2, 2:1), p= c(0:2, 4,4,6), x = 1:6, dimnames = dn)
m
str(m)
stopifnot(identical(dimnames(m), dn))

sparseMatrix(x = 2.72, i=1:3, j=2:4) # recycling x[回收x]
sparseMatrix(x = TRUE, i=1:3, j=2:4) # recycling x, |--&gt; "lgCMatrix"[回收X,|  - >“lgCMatrix”]

## no 'x' --&gt; patter*n* matrix:[#X - >的行话* N *矩阵:]
(n &lt;- sparseMatrix(i=1:6, j=rev(2:7)))# -&gt; ngCMatrix[ - > ngCMatrix]

## an empty sparse matrix:[#空稀疏矩阵:]
(e <- sparseMatrix(dims = c(4,6), i={}, j={}))

## a symmetric one:[#对称:]
(sy <- sparseMatrix(i= c(2,4,3:5), j= c(4,7:5,5), x = 1:5,
                    dims = c(7,7), symmetric=TRUE))
stopifnot(isSymmetric(sy))


## pointers example in converting from other sparse matrix representations.[#指针,例如从其他稀疏矩阵表示转换。]
if(require(SparseM) &amp;&amp; packageVersion("SparseM") >= 0.87 &amp;&amp;
   nzchar(dfil <- system.file("textdata", "rua_32_ax.rua",
                              package = "SparseM"))) {
  X <- model.matrix(read.matrix.hb(dfil))
  XX <- sparseMatrix(j = X@ja, p = X@ia - 1L, x = X@ra, dims = X@dimension)
  validObject(XX)

  ## Alternatively, and even more user friendly :[#此外,更为用户友好:]
  X. &lt;- as(X, "Matrix")  # or also[或者也]
  X2 <- as(X, "sparseMatrix")
  stopifnot(identical(XX, X.), identical(X., X2))
}


转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。


注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|小黑屋|生物统计家园 网站价格

GMT+8, 2025-1-22 23:40 , Processed in 0.030746 second(s), 15 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表