HMMPLOT plots a Hidden Markov Model. CALL: hmmplot(x,z) hmmplot(x,z,t,z_range,Title,Ylabel,colType,fontsize) x = Switching process. z = Regime process. t = Time. z_range = Range of regime, e.g. [1 3] for 3 regime states. Title = Title of plot. Ylabel = Y-label of x-plot. colType = 0: One colour (default), 1: Different colours for each regime fontsize= Fontsize of text. Examples: Switching AR(1)-process. (Example 3 in thesis) P= [0.975 0.02 0.005; 0.01 0.98 0.01; 0.005 0.02 0.975]; C = [1 1 1]'; A = [1 -0.5; 1 -0.3; 1 0.5]; m = [-1 0 3]'; s2 = [1 1 1.44]'; [x,z] = sarmasim(C,A,m,s2,P,500); hmmplot(x,z) hmmplot(x,z,(0:499)/400,[1 3],'Switching AR(1)-process','X(t)') hmmplot(x,z,[],[1 3],'','',1,20)
Control axis scaling and appearance. | |
Get handle to current axis. | |
Get object properties. | |
Hold current graph. | |
Linear plot. | |
Set object properties. | |
Stairstep plot. | |
Create axes in tiled positions. | |
Graph title. | |
Y-axis label. |
Script to computer exercises 2 | |
Script to computer exercises 4 | |
Demo for switching AR(1)-processes. | |
Rainflow matrix for Switching Markov Chains of Turning Points. | |
Quick test of the routines in module 'markov' |
001 function hmmplot(x,z,t,z_range,Title,Ylabel,colType,fontsize) 002 % HMMPLOT plots a Hidden Markov Model. 003 % 004 % CALL: hmmplot(x,z) 005 % hmmplot(x,z,t,z_range,Title,Ylabel,colType,fontsize) 006 % 007 % x = Switching process. 008 % z = Regime process. 009 % t = Time. 010 % z_range = Range of regime, e.g. [1 3] for 3 regime states. 011 % Title = Title of plot. 012 % Ylabel = Y-label of x-plot. 013 % colType = 0: One colour (default), 1: Different colours for each regime 014 % fontsize= Fontsize of text. 015 % 016 % Examples: Switching AR(1)-process. (Example 3 in thesis) 017 % P= [0.975 0.02 0.005; 0.01 0.98 0.01; 0.005 0.02 0.975]; 018 % C = [1 1 1]'; 019 % A = [1 -0.5; 1 -0.3; 1 0.5]; 020 % m = [-1 0 3]'; 021 % s2 = [1 1 1.44]'; 022 % [x,z] = sarmasim(C,A,m,s2,P,500); 023 % hmmplot(x,z) 024 % hmmplot(x,z,(0:499)/400,[1 3],'Switching AR(1)-process','X(t)') 025 % hmmplot(x,z,[],[1 3],'','',1,20) 026 027 % Copyright (c) 1997 by Pär Johannesson 028 % Toolbox: Rainflow Cycles for Switching Processes V.1.0, 2-Oct-1997 029 030 if nargin<3, t=[]; end 031 if nargin<4, z_range=[]; end 032 if nargin<5, Title = ''; end 033 if nargin<6, Ylabel=''; end 034 if nargin<7, colType=0; end 035 if nargin<8, fontsize=[]; end 036 037 if isempty(t) 038 t = (1:length(x))'; 039 end 040 041 if isempty(z_range) 042 zmin = min(z); zmax = max(z); 043 else 044 zmin = z_range(1); zmax = z_range(2); 045 end 046 047 tmin = min(t); 048 tmax = max(t); 049 050 subplot(2,1,1) 051 if colType == 0 052 plot(t,x) 053 elseif colType == 1 054 col = get(gca,'ColorOrder'); 055 i0=1; n=length(x); 056 slut=0; 057 while ~slut 058 I=(find(z(i0:n)~=z(i0))); 059 if ~isempty(I) 060 i1 = min(I) + i0-1; 061 else 062 i1=n; slut = 1; 063 end 064 plot(t(i0:i1),x(i0:i1),'Color',col(z(i0),:)); 065 i0=i1; 066 hold on 067 end 068 end 069 070 v=axis; axis([tmin tmax v(3:4)]) 071 h1=gca; 072 if ~isempty(fontsize), set(h1,'Fontsize',fontsize); end 073 pos1 = get(h1,'Position'); 074 title(Title); ylabel(Ylabel); 075 076 subplot(2,1,2) 077 if colType == 0 078 stairs(t,z) 079 elseif colType == 1 080 i0=1; n=length(x); 081 slut=0; 082 while ~slut 083 I=(find(z(i0:n)~=z(i0))); 084 if ~isempty(I) 085 i1 = min(I) + i0-1; 086 else 087 i1=n; slut = 1; 088 end 089 [XX,YY] = stairs(t(i0:i1),z(i0:i1)); 090 plot(XX,YY,'Color',col(z(i0),:)); 091 i0=i1; 092 hold on 093 end 094 end 095 096 axis([tmin tmax zmin-0.5 zmax+0.5]); 097 h2=gca; 098 if ~isempty(fontsize), set(h2,'Fontsize',fontsize); end 099 100 pos2 = get(h2,'Position'); 101 102 Pos2 = pos2; Pos2(4)=.1; 103 Pos1 = pos1; Pos1(2) = Pos2(2)+Pos2(4)+0.02; Pos1(4) = pos1(4)+pos1(2)-Pos1(2); 104 105 set(h1,'Position',Pos1); 106 set(h2,'Position',Pos2); 107 108 set(h1,'XTickLabel',[]); 109 set(h2,'YTick',zmin:zmax); 110
Comments or corrections to the WAFO group