-
Notifications
You must be signed in to change notification settings - Fork 8
/
compactToMat.html
137 lines (90 loc) · 3.28 KB
/
compactToMat.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Convert Matrix from Compact Vector to Standard Form</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="R.css" />
</head><body>
<table width="100%" summary="page for compactToMat {fields}"><tr><td>compactToMat {fields}</td><td style="text-align: right;">R Documentation</td></tr></table>
<h2>
Convert Matrix from Compact Vector to Standard Form
</h2>
<h3>Description</h3>
<p><code>compactToMat</code> transforms a matrix from compact, vector form to
a standard matrix. Only symmetric matrices can be stored in this
form, since a compact matrix is stored as a vector with elements
representing the upper triangle of the matrix. This function assumes
the vector does not contain diagonal elements of the matrix.
</p>
<p>An example of a matrix stored in compact form is any matrix
generated from the <code>rdist</code> function with <code>compact=TRUE</code>.
</p>
<h3>Usage</h3>
<pre>
compactToMat(compactMat, diagVal=0, lower.tri=FALSE, upper.tri=TRUE)
</pre>
<h3>Arguments</h3>
<table summary="R argblock">
<tr valign="top"><td><code>compactMat</code></td>
<td>
<p>A symmetric matrix stored as a vector containing elements for the lower-triangular
portion of the true matrix (and none of the diagonal elements), as returned by
<code>rdist</code> with <code>compact=TRUE</code>.
</p>
</td></tr>
<tr valign="top"><td><code>diagVal</code></td>
<td>
<p>A number to put in the diagonal entries of the output matrix.
</p>
</td></tr>
<tr valign="top"><td><code>lower.tri</code></td>
<td>
<p>Whether or not to fill in the upper triangle of the output matrix
</p>
</td></tr>
<tr valign="top"><td><code>upper.tri</code></td>
<td>
<p>Whether or not to fill in the lower triangle of the output matrix
</p>
</td></tr>
</table>
<h3>Value</h3>
<p>The standard form matrix represented by the input compact matrix
</p>
<h3>Author(s)</h3>
<p>John Paige
</p>
<h3>See Also</h3>
<p><code><a href="rdist.html">rdist</a></code>, <code>link{dist}</code>
</p>
<h3>Examples</h3>
<pre>
################
#Calculate distance matrix from compact form:
################
#make a distance matrix
distOut = rdist(1:5, compact=TRUE)
print(distOut)
#note that distOut is in compact form:
print(c(distOut))
#convert to standard matrix form:
distMat = compactToMat(distOut)
################
#fast computation of covariance matrix:
################
#generate 5 random points on [0,1]x[0,1] square
x = matrix(runif(10), nrow=5)
#get compact distance matrix
distOut = rdist(x, compact=TRUE)
#evaluate Exponential covariance with range=1. Note that
#Covariance function is only evaluated over upper triangle
#so time is saved.
diagVal = Exponential(0, range=1)
compactCovMat = Exponential(distOut, range=1)
upperCovMat = compactToMat(compactCovMat, diagVal)
lowerCovMat = compactToMat(compactCovMat, diagVal, lower.tri=TRUE, upper.tri=FALSE)
fullCovMat = compactToMat(compactCovMat, diagVal, lower.tri=TRUE, upper.tri=TRUE)
compactCovMat
lowerCovMat
upperCovMat
fullCovMat
</pre>
<hr /><div style="text-align: center;">[Package <em>fields</em> version 9.9 <a href="00Index.html">Index</a>]</div>
</body></html>