SCM

SCM Repository

[matrix] Annotation of /pkg/man/pMatrix-class.Rd
ViewVC logotype

Annotation of /pkg/man/pMatrix-class.Rd

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2005 - (view) (download) (as text)

1 : bates 638 \name{pMatrix-class}
2 :     \docType{class}
3 :     \alias{pMatrix-class}
4 : maechler 956 \alias{-,pMatrix,missing-method}
5 : bates 638 \alias{\%*\%,matrix,pMatrix-method}
6 :     \alias{\%*\%,pMatrix,matrix-method}
7 : maechler 657 \alias{\%*\%,pMatrix,pMatrix-method}
8 : maechler 953 \alias{\%*\%,Matrix,pMatrix-method}
9 :     \alias{\%*\%,pMatrix,Matrix-method}
10 : maechler 2005 \alias{crossprod,pMatrix,missing-method}
11 :     \alias{tcrossprod,pMatrix,missing-method}
12 : bates 638 \alias{coerce,integer,pMatrix-method}
13 : maechler 1407 \alias{coerce,numeric,pMatrix-method}
14 : maechler 2005 \alias{coerce,matrix,pMatrix-method}
15 : bates 638 \alias{coerce,pMatrix,matrix-method}
16 : maechler 1548 \alias{coerce,pMatrix,ngTMatrix-method}
17 : maechler 1747 \alias{coerce,pMatrix,lMatrix-method}
18 : maechler 2005 \alias{coerce,pMatrix,dMatrix-method}
19 : maechler 1714 \alias{coerce,pMatrix,nMatrix-method}
20 : maechler 1738 \alias{coerce,pMatrix,CsparseMatrix-method}
21 : maechler 1305 \alias{coerce,pMatrix,TsparseMatrix-method}
22 : maechler 2005 \alias{coerce,nMatrix,pMatrix-method}
23 :     %
24 : bates 638 \alias{solve,pMatrix,missing-method}
25 :     \alias{t,pMatrix-method}
26 : maechler 1673 \alias{[<-,pMatrix,index,ANY,ANY-method}
27 :     \alias{[<-,pMatrix,missing,index,ANY-method}
28 :     %
29 : bates 638 \title{Permutation matrices}
30 :     \description{The \code{"pMatrix"} class is the class of permutation
31 : maechler 659 matrices, stored as 1-based integer permutation vectors.}
32 : bates 638 \section{Objects from the Class}{
33 :     Objects can be created by calls of the form \code{new("pMatrix", ...)}
34 : maechler 659 or by coercion from an integer permutation vector, see below.
35 : bates 638 }
36 :     \section{Slots}{
37 :     \describe{
38 :     \item{\code{perm}:}{An integer, 1-based permutation vector, i.e.
39 :     an integer vector of length \code{Dim[1]} whose elements form a
40 :     permutation of \code{1:Dim[1]}.}
41 :     \item{\code{Dim}:}{Object of class \code{"integer"}. The dimensions
42 :     of the matrix which must be a two-element vector of equal,
43 :     non-negative integers.}
44 :     \item{\code{Dimnames}:}{list of length two; each component
45 :     containing NULL or a \code{\link{character}} vector length
46 :     equal the corresponding \code{Dim} element.}
47 :     }
48 :     }
49 :     \section{Extends}{
50 : maechler 1665 Class \code{"\linkS4class{sparseMatrix}"} and
51 :     \code{"\linkS4class{generalMatrix}"}, directly.
52 : bates 638 }
53 :     \section{Methods}{
54 :     \describe{
55 : maechler 657 \item{\%*\%}{\code{signature(x = "matrix", y = "pMatrix")} and other
56 :     signatures (use \code{showMethods("\%*\%", class="pMatrix")}): ... }
57 : maechler 659 \item{coerce}{\code{signature(from = "integer", to = "pMatrix")}:
58 : maechler 1407 This is enables typical \code{"pMatrix"} construction, given
59 : maechler 659 a permutation vector of \code{1:n}, see the first example.}
60 : maechler 1407 \item{coerce}{\code{signature(from = "numeric", to = "pMatrix")}:
61 :     a user convenience, to allow \code{as(perm, "pMatrix")} for
62 :     numeric \code{perm} with integer values.}
63 : bates 638 \item{coerce}{\code{signature(from = "pMatrix", to = "matrix")}: ... }
64 : maechler 1548 \item{coerce}{\code{signature(from = "pMatrix", to = "ngTMatrix")}:
65 :     coercion to sparse logical matrix of class \code{\linkS4class{ngTMatrix}}.}
66 : bates 638 \item{solve}{\code{signature(a = "pMatrix", b = "missing")}: return
67 :     the inverse permutation matrix.}
68 :     \item{t}{\code{signature(x = "pMatrix")}: return the transpose of
69 :     the permuation matrix (which is also the inverse of the
70 :     permutation matrix).}
71 :     }
72 :     }
73 : maechler 1407 \note{
74 :     The inverse of the typical \code{"pMatrix"} constructor,
75 :     \code{P <- as(ip, "pMatrix")} is simply \code{ip <- P@perm}.
76 : maechler 1673
77 :     Subsetting (\dQuote{indexing}) \code{"pMatrix"} objects treats them as
78 :     nonzero-pattern matrices, i.e., as \code{"linkS4class{ngTMatrix}"}
79 :     such that non-matrix subsetting result in \code{\link{logical}}
80 :     vectors. Sub-assignment (\code{M[i,j] <- v}) is not sensible and
81 :     hence an error for these permutation matrices.
82 : maechler 1407 }
83 : bates 638 %\seealso{}
84 :     \examples{
85 :     (pm1 <- as(as.integer(c(2,3,1)), "pMatrix"))
86 : maechler 659 t(pm1) # is the same as
87 : bates 638 solve(pm1)
88 : maechler 659 pm1 \%*\% t(pm1) # check that the transpose is the inverse
89 :     stopifnot(identical(diag(3), as(pm1 \%*\% t(pm1), "matrix")))
90 : maechler 1331
91 :     set.seed(11)
92 :     ## random permutation matrix :
93 :     (p10 <- as(sample(10),"pMatrix"))
94 :    
95 :     ## Permute rows / columns of a numeric matrix :
96 : bates 638 (mm <- round(array(rnorm(3 * 3), c(3, 3)), 2))
97 : bates 650 mm \%*\% pm1
98 :     pm1 \%*\% mm
99 : maechler 659 try(as(as.integer(c(3,3,1)), "pMatrix"))# Error: not a permutation
100 : maechler 868
101 : maechler 1548 as(pm1, "ngTMatrix")
102 :     p10[1:7, 1:4] # gives an "ngTMatrix" (most economic!)
103 : bates 638 }
104 :     \keyword{classes}

root@r-forge.r-project.org
ViewVC Help
Powered by ViewVC 1.0.0  
Thanks to:
Vienna University of Economics and Business Powered By FusionForge