DrawViterbiTree: Arranges a Viterbi tree

Description Usage Arguments Details Value Author(s) Examples

View source: R/DrawViterbiTree.R

Description

The functions arranges the output of HFMviterbi in a way that can be displayed.

Usage

1
	DrawViterbiTree(maxPath)

Arguments

maxPath

The output of HFMViterbi.

Details

The function arranges the branches of the tree in a matrix.

Value

A matrix, foreground: Viterbi tree, background:0

Author(s)

Henrik Failmezger, failmezger@googlemail.com

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
## Fit a continous treeHFM ## 
nHStates = 2;
########create observation sequences########
obs1 <- rbind(runif(10,0,1),runif(10,0,1))
obs2 <- rbind(runif(8,0,1),runif(8,0,1))
data=list()
data[[1]]=obs1
data[[2]]=obs2
######### create guesses for gaussian covariance matrix and means #########
mc2 <- Mclust(t(cbind(obs1,obs2)), G=2)
muInit=mc2$parameters$mean;
SigmaInit=mc2$parameters$variance$sigma
#########create tree topology####################################
nodeIndices1=cbind(c(0,1,2,3,3,4,5,6,7,8),c(1,2,3,4,5,6,7,8,9,10));
nodeIndices2=cbind(c(0,1,2,3,4,4,5,6),c(1,2,3,4,5,6,7,8));
dataNodeIndices=list()
dataNodeIndices[[1]]=nodeIndices1;
dataNodeIndices[[2]]=nodeIndices2;
######### create guesses for prior and transition matrices#########
prior1=array(1,nHStates);
priorInit = array(1,nHStates)/nHStates;
transmatInit = matrix(1,nHStates,nHStates)*(1/nHStates);
transInitDiv= matrix(1,nHStates,nHStates*nHStates)*(1/(nHStates*nHStates))
#
hfm=HFMfit(data,nHStates,dataNodeIndices,priorInit,transmatInit,transInitDiv,'c',
SigmaInit=SigmaInit, muInit=muInit);
# calculate Viterbi path
viterbi=HFMviterbi(obs1,nHStates,nodeIndices1,hfm$initProb,hfm$transMatSeq,hfm$transMatDiv,
'c',sigma=hfm$sigma, mu=hfm$mu);
# draw the path
tree=DrawViterbiTree(viterbi$maxPath)
#plot the tree
#image(t(tree),col=rainbow(10))

treeHFM documentation built on May 30, 2017, 3:01 a.m.