spm_DFP_plot.m 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. function spm_DFP_plot(QU,pU)
  2. % plots particles for spm_DFP
  3. % FORMAT spm_DFP_plot(QU,Nt)
  4. % FORMAT spm_DFP_plot(QU,pU)
  5. %--------------------------------------------------------------------------
  6. % QU{t}(p).x{d} - ensemble of hidden states
  7. % QU{t}(p).v{d} - ensemble of causal states
  8. %__________________________________________________________________________
  9. % Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging
  10. % Karl Friston
  11. % $Id: spm_DFP_plot.m 6540 2015-09-05 10:06:42Z karl $
  12. % defaults for plotting
  13. %--------------------------------------------------------------------------
  14. clf
  15. try
  16. pX = pU.x{1};
  17. pV = pU.v{2};
  18. Nt = length(pX);
  19. catch
  20. try Nt = pU; catch, Nt = length(QU); end
  21. end
  22. % time-series specification
  23. %--------------------------------------------------------------------------
  24. nx = size(QU{1}(1).x{1},1);
  25. nv = size(QU{1}(1).v{1},1);
  26. np = length(QU{1});
  27. nt = length(QU);
  28. % unpack states
  29. %--------------------------------------------------------------------------
  30. for t = 1:nt
  31. for j = 1:np
  32. for i = 1:nx
  33. X{i}(t,j) = QU{t}(j).x{1}(i);
  34. end
  35. for i = 1:nv
  36. V{i}(t,j) = QU{t}(j).v{1}(i);
  37. end
  38. end
  39. end
  40. % causes
  41. %--------------------------------------------------------------------------
  42. if nt < 2, return, end
  43. subplot(2,1,1)
  44. for i = 1:nv
  45. plot(1:nt,V{i},':','Color',[1 1 1]/(2 + i - 1))
  46. hold on
  47. if np < 16
  48. plot(nt,V{i}(nt,:),'.','Color',[1 1 1]/(2 + i - 1),'MarkerSize',32)
  49. plot(nt,V{i}(nt,:),'.','Color',[1 1 1],'MarkerSize',4)
  50. else
  51. plot(nt,V{i}(nt,:),'.','Color',[1 0 0],'MarkerSize',8)
  52. end
  53. plot(1:nt,mean(V{i},2),'--b','LineWidth',2)
  54. hold on
  55. end
  56. try
  57. hold on
  58. plot((1:nt) - 1,pV,'r')
  59. end
  60. hold off
  61. title('causes','FontSize',16);
  62. xlabel('time (steps)','FontSize',14)
  63. grid on
  64. axis square
  65. set(gca,'XLim',[1 Nt])
  66. % hidden states
  67. %--------------------------------------------------------------------------
  68. if ~nx, drawnow, return, end
  69. subplot(2,1,2)
  70. for i = 1:nx
  71. plot(1:nt,X{i},':','Color',[1 1 1]/(2 + i - 1))
  72. hold on
  73. if np < 16
  74. plot(nt,X{i}(nt,:),'.','Color',[1 1 1]/(2 + i - 1),'MarkerSize',32)
  75. plot(nt,X{i}(nt,:),'.','Color',[1 1 1],'MarkerSize',4)
  76. else
  77. plot(nt,X{i}(nt,:),'.','Color',[1 0 0],'MarkerSize',8)
  78. end
  79. plot(1:nt,mean(X{i},2),'--b','LineWidth',2)
  80. hold on
  81. end
  82. try
  83. hold on
  84. plot((1:nt) - 1,pX,'r')
  85. end
  86. hold off
  87. title('hidden states','FontSize',16);
  88. xlabel('time (steps)','FontSize',14)
  89. grid on
  90. axis square
  91. set(gca,'XLim',[1 Nt])
  92. drawnow
  93. return
  94. % movie
  95. %--------------------------------------------------------------------------
  96. spm_figure('GetWin','DFP');
  97. subplot(2,1,2)
  98. try
  99. load DFP_movie
  100. M(end + 1) = getframe;
  101. catch
  102. M = getframe;
  103. end
  104. save DFP_movie M