lattice2node: Functions to define mapping between a lattice and nodes

Description Usage Arguments Value Author(s) See Also Examples

Description

These functions define mapping in between two-dimensional indices on a lattice and the one-dimensional node representation used in inla.

The mapping from node to lattice follows the default R behaviour (which is column based storage), and as.vector(A) and matrix(a, nrow, ncol) can be used instead of inla.matrix2vector and inla.vector2matrix.

Usage

1
2
3
4
5
6

Arguments

nrow

Number of rows in the lattice.

ncol

Number of columns in the lattice.

irow

Lattice row index, between 1 and nrow

icol

Lattice column index, between 1 and ncol

node

The node index, between 1 and ncol*nrow

a.matrix

is a matrix to be mapped to a vector using internal representation defined by inla.lattice2node

a.vector

is a vector to be mapped into a matrix using the internal representation defined by inla.node2lattice

Value

inla.lattice2node.mapping returns the hole mapping as a matrix, and inla.node2lattice.mapping returns the hole mapping as list(irow=..., icol=...). inla.lattice2node and inla.node2lattice provide the mapping for a given set of lattice indices and nodes. inla.matrix2vector provide the mapped vector from a matrix, and inla.vector2matrix provide the inverse mapped matrix from vector.

Author(s)

Havard Rue hrue@math.ntnu.no

See Also

inla

Examples

 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
## write out the mapping using the two alternatives
nrow = 2
ncol = 3
mapping = inla.lattice2node.mapping(nrow,ncol)

for (i in 1:nrow){
    for(j in 1:ncol){
        print(paste("Alt.1: lattice index [", i,",", j,"] corresponds",
                    "to node [", mapping[i,j],"]", sep=""))
    }
}

for (i in 1:nrow){
    for(j in 1:ncol){
        print(paste("Alt.2: lattice index [", i,",", j,"] corresponds to node [",
                    inla.lattice2node(i,j,nrow,ncol), "]", sep=""))
    }
}

inv.mapping = inla.node2lattice.mapping(nrow,ncol)
for(node in 1:(nrow*ncol))
   print(paste("Alt.1: node [", node, "] corresponds to lattice index [",
               inv.mapping$irow[node], ",",
               inv.mapping$icol[node],"]", sep=""))

for(node in 1:(nrow*ncol))
   print(paste("Alt.2: node [", node, "] corresponds to lattice index [",
               inla.node2lattice(node,nrow,ncol)$irow[1], ",",
               inla.node2lattice(node,nrow,ncol)$icol[1],"]", sep=""))

## apply the mapping from matrix to vector and back
n = nrow*ncol
z = matrix(1:n,nrow,ncol)
z.vector = inla.matrix2vector(z)  # as.vector(z) could also be used
print(mapping)
print(z)
print(z.vector)

## the vector2matrix is the inverse, and should give us the z-matrix
## back. matrix(z.vector, nrow, ncol) could also be used here.
z.matrix = inla.vector2matrix(z.vector, nrow, ncol) 
print(z.matrix)

andrewzm/INLA documentation built on May 10, 2019, 11:12 a.m.