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