makeCholBlock(SpatioTemporal)
makeCholBlock()所属R语言包:SpatioTemporal
Computations for Block Diagonal Matrices
块对角矩阵的计算
译者:生物统计家园网 机器人LoveR
描述----------Description----------
Provides block diagonal version of the base package functions chol, chol2inv, and <br> backsolve.
提供块对角线版本的基础包功能chol,chol2inv,和<br> backsolve。
Computes the Cholesky factor, the matrix inverse and solves matrix equation systems for block diagonal matrices.
计算Cholesky因子,矩阵求逆,解决了分块对角矩阵的矩阵方程组。
用法----------Usage----------
makeCholBlock(mat, n.blocks = 1, block.sizes =
rep(dim(mat)[1]/n.blocks, n.blocks))
invCholBlock(R, n.blocks = 1, block.sizes =
rep(dim(R)[1]/n.blocks, n.blocks))
solveTriBlock(R, B, n.x = dim(B)[2], n.blocks = 1,
block.sizes = rep(dim(R)[1]/n.blocks, n.blocks),
transpose = FALSE)
参数----------Arguments----------
参数:mat
A block diagonal, square, positive definite matrix.
块对角,广场,正定矩阵。
参数:R
Upper right block diagonal Cholesky factor. The output from chol or <br> makeCholBlock.
右上块对角Cholesky因子。的输出chol或<br>makeCholBlock。
参数:n.blocks
Number of diagonal blocks in mat (or R). Defaults to 1 (i.e. a full matrix) if not given.
的对角线块mat(或R的数目)。如果没有给出,默认为1(即一个完整的矩阵)。
参数:block.sizes
A vector of length n.blocks with the size of each of the diagonal blocks. If not given it will assume equal size blocks.
的向量的长度n.blocks与每个对角块的大小。如果没有给它承担同等大小的块。
参数:B
Vector or matrix containg the right hand side of the equations system to be solved.
向量或矩阵containg的方程系统要解决的右手侧。
参数:n.x
Number of columns in B, defaults correctly if B is a matrix.
数列在正确的话B,默认B是一个矩阵。
参数:transpose
Transpose R before solving the equation system. Controls if we solve the equations system given by R*x = B or R'*x=B.
移调R然后解方程系统。控制,如果我们求解方程系统给出的R * X = B或R* X = B
Details
详细信息----------Details----------
makeCholBlock computes the Cholesky factor of a block diagonal matrix using the block diagonal structure to speed up computations.
makeCholBlock计算使用块对角结构,以加快计算的块对角矩阵的Cholesky因子。
invCholBlock uses the Cholesky factor from makeCholBlock to compute the inverse of mat.
invCholBlock使用Cholesky因子makeCholBlock计算的逆mat的。
solveTriBlock solves equation systems based on the Cholesky factor, using the block diagonal structure to speed up computations (c.f. backsolve). The function solves equations of the form R*x = B, and R'*x = B with respect to x, where the transpose is controlled by the parameter transpose. Aplying the function twice solves mat*x=B, see the examples.
solveTriBlock解决方程组的Cholesky因子的基础上,采用块对角结构,加快运算速度(CF backsolve“)。函数求解方程的形式R * = B,和R* =乙相对于x,其中的转置所控制的参数transpose。 Aplying两次的功能解决了垫* X = B,看到的例子。
For all three functions the block diagonal structure of the matrix is defined by two input variables, the number of blocks n.blocks, and the size of each block block.sizes. The size of the matrices must match the total number of blocks, i.e. sum(block.sizes) must equal dim(mat).
对于所有三个函数矩阵的块对角结构,由两个输入变量,定义的块的个数n.blocks,以及大小的每个块block.sizes。矩阵的大小必须匹配的总块数,即sum(block.sizes)必须等于dim(mat)。
The functions can be used for full matrices by setting the number of blocks to 1.
的功能都可以通过设置的块的个数为1,用于全矩阵。
值----------Value----------
makeCholBlock gives the Cholesky factor and invCholBlock gives the inverse of the matrix mat. solveTriBlock gives to answer to the equation system.
makeCholBlock给出了的Cholesky因子和invCholBlock给出的逆矩阵mat。 solveTriBlock给予回答的方程系统。
(作者)----------Author(s)----------
Johan Lindstr枚m and Adam Szpiro
参见----------See Also----------
Other block matrix functions dot.prod, block.mult, calc.tF.times.mat, <br> calc.iS.X, and sumLogDiag.
其他分块矩阵的功能dot.prod,block.mult,calc.tF.times.mat,参考calc.iS.X,sumLogDiag。
This function is used by loglike.
此功能使用loglike。
实例----------Examples----------
#create a matrix[创建一个矩阵]
mat <- cbind(c(1,0,0),c(0,2,1),c(0,1,2))
#define the number of blocks and block sizes[定义的块大小和块的数目]
block.sizes <- c(1,2)
n.blocks <- length(block.sizes)
#Compute the Cholesky factor[计算Cholesky因子]
R <- makeCholBlock(mat, n.blocks, block.sizes)
#and the matrix inverse[和矩阵的逆]
i.mat <- invCholBlock(R, n.blocks, block.sizes)
#compare to the alternative[比较的替代]
i.mat-solve(mat)
#define a B vector[定义一个向量B]
B <- c(1,2,3)
#solve the equation system (we need n.x since B is not a matrix)[求解方程系统(我们需要为nx由于B是不是一个矩阵)]
x1 <- solveTriBlock(R, B, n.x=1, n.blocks, block.sizes, tr=TRUE)
x2 <- solveTriBlock(R, x1, n.x=1, n.blocks, block.sizes, tr=FALSE)
print(x2)
#compare to the alternative[比较的替代]
print(solve(mat,B))
range(x2-solve(mat,B))
#compute the quadratic form B'*i.mat*B[计算二次型Bi.mat * B]
norm2(x1)
#compare to the alternative[比较的替代]
t(B) %*% i.mat %*% B
转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。
注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
|