| Line 10... |
Line 10... |
| 10 |
\alias{coerce,pMatrix,matrix-method}
|
10 |
\alias{coerce,pMatrix,matrix-method}
|
| 11 |
\alias{solve,pMatrix,missing-method}
|
11 |
\alias{solve,pMatrix,missing-method}
|
| 12 |
\alias{t,pMatrix-method}
|
12 |
\alias{t,pMatrix-method}
|
| 13 |
\title{Permutation matrices}
|
13 |
\title{Permutation matrices}
|
| 14 |
\description{The \code{"pMatrix"} class is the class of permutation
|
14 |
\description{The \code{"pMatrix"} class is the class of permutation
|
| 15 |
matrices stored as 1-based integer permutation vectors.}
|
15 |
matrices, stored as 1-based integer permutation vectors.}
|
| 16 |
\section{Objects from the Class}{
|
16 |
\section{Objects from the Class}{
|
| 17 |
Objects can be created by calls of the form \code{new("pMatrix", ...)}
|
17 |
Objects can be created by calls of the form \code{new("pMatrix", ...)}
|
| 18 |
or by coercion from an integer permutation vector.
|
18 |
or by coercion from an integer permutation vector, see below.
|
| 19 |
}
|
19 |
}
|
| 20 |
\section{Slots}{
|
20 |
\section{Slots}{
|
| 21 |
\describe{
|
21 |
\describe{
|
| 22 |
\item{\code{perm}:}{An integer, 1-based permutation vector, i.e.
|
22 |
\item{\code{perm}:}{An integer, 1-based permutation vector, i.e.
|
| 23 |
an integer vector of length \code{Dim[1]} whose elements form a
|
23 |
an integer vector of length \code{Dim[1]} whose elements form a
|
| Line 29... |
Line 29... |
| 29 |
containing NULL or a \code{\link{character}} vector length
|
29 |
containing NULL or a \code{\link{character}} vector length
|
| 30 |
equal the corresponding \code{Dim} element.}
|
30 |
equal the corresponding \code{Dim} element.}
|
| 31 |
}
|
31 |
}
|
| 32 |
}
|
32 |
}
|
| 33 |
\section{Extends}{
|
33 |
\section{Extends}{
|
| 34 |
Class \code{"Matrix"}, directly.
|
34 |
Class \code{"Matrix"}, directly.
|
| 35 |
}
|
35 |
}
|
| 36 |
\section{Methods}{
|
36 |
\section{Methods}{
|
| 37 |
\describe{
|
37 |
\describe{
|
| 38 |
\item{\%*\%}{\code{signature(x = "matrix", y = "pMatrix")} and other
|
38 |
\item{\%*\%}{\code{signature(x = "matrix", y = "pMatrix")} and other
|
| 39 |
signatures (use \code{showMethods("\%*\%", class="pMatrix")}): ... }
|
39 |
signatures (use \code{showMethods("\%*\%", class="pMatrix")}): ... }
|
| 40 |
\item{coerce}{\code{signature(from = "integer", to = "pMatrix")}: ... }
|
40 |
\item{coerce}{\code{signature(from = "integer", to = "pMatrix")}:
|
| - |
|
41 |
This is enables typical \code{"pmatrix"} construction, given
|
| - |
|
42 |
a permutation vector of \code{1:n}, see the first example.}
|
| 41 |
\item{coerce}{\code{signature(from = "pMatrix", to = "matrix")}: ... }
|
43 |
\item{coerce}{\code{signature(from = "pMatrix", to = "matrix")}: ... }
|
| 42 |
\item{solve}{\code{signature(a = "pMatrix", b = "missing")}: return
|
44 |
\item{solve}{\code{signature(a = "pMatrix", b = "missing")}: return
|
| 43 |
the inverse permutation matrix.}
|
45 |
the inverse permutation matrix.}
|
| 44 |
\item{t}{\code{signature(x = "pMatrix")}: return the transpose of
|
46 |
\item{t}{\code{signature(x = "pMatrix")}: return the transpose of
|
| 45 |
the permuation matrix (which is also the inverse of the
|
47 |
the permuation matrix (which is also the inverse of the
|
| Line 47... |
Line 49... |
| 47 |
}
|
49 |
}
|
| 48 |
}
|
50 |
}
|
| 49 |
%\seealso{}
|
51 |
%\seealso{}
|
| 50 |
\examples{
|
52 |
\examples{
|
| 51 |
(pm1 <- as(as.integer(c(2,3,1)), "pMatrix"))
|
53 |
(pm1 <- as(as.integer(c(2,3,1)), "pMatrix"))
|
| 52 |
t(pm1)
|
54 |
t(pm1) # is the same as
|
| 53 |
solve(pm1)
|
55 |
solve(pm1)
|
| 54 |
pm1 \%*\% as(t(pm1), "matrix") # check that the transpose is the inverse
|
56 |
pm1 \%*\% t(pm1) # check that the transpose is the inverse
|
| - |
|
57 |
stopifnot(identical(diag(3), as(pm1 \%*\% t(pm1), "matrix")))
|
| 55 |
(mm <- round(array(rnorm(3 * 3), c(3, 3)), 2))
|
58 |
(mm <- round(array(rnorm(3 * 3), c(3, 3)), 2))
|
| 56 |
mm \%*\% pm1
|
59 |
mm \%*\% pm1
|
| 57 |
pm1 \%*\% mm
|
60 |
pm1 \%*\% mm
|
| 58 |
try(as(as.integer(c(3,3,1)), "pMatrix"))
|
61 |
try(as(as.integer(c(3,3,1)), "pMatrix"))# Error: not a permutation
|
| 59 |
}
|
62 |
}
|
| 60 |
\keyword{classes}
|
63 |
\keyword{classes}
|