tree_getpath: tree_getpath

Description Usage Arguments Value Examples

View source: R/trees.R

Description

This function extracts a path from a tree.

Usage

1
tree_getpath(tree, n)

Arguments

tree

is a list encoding a tree genereated via the function tree_init or previously updated via the function tree_update.

n

the index of the path to extract.

Value

This function outputs a matrix of size dimX by nstep (see documentation of tree_init) corresponding to the path indexed by n.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
N = 5
dimX = 2
nstep = 10

#--- Artificially create N particles, each of dimension dimX, evolved for nstep timesteps ---#
X = array(rnorm(N*dimX*(nstep+1)), dim = c(dimX,N,nstep))
a = replicate(nstep-1, sample(1:N, size = N, replace = TRUE))
tree = tree_init(X[,,1])
for (t in 2:nstep){
tree = tree_update(tree, X[,,t], a[,t-1])
}

#--- List all the N final paths ---#
for (i in 1:N){
cat("Path",toString(i),"\n")
print(tree_getpath(tree, i))
}

pierrejacob/PET documentation built on May 25, 2019, 11:35 p.m.