|
| 1 | +clear all; |
| 2 | + |
| 3 | +addpath('../'); |
| 4 | + |
| 5 | +% Gives me: X (labels), Y (data), time, label |
| 6 | +tmp = load('../data/testdata_orientation.mat'); |
| 7 | + |
| 8 | +Y = tmp.Y; % Y: features x time x trials |
| 9 | +X = tmp.X'; |
| 10 | +time = tmp.time; |
| 11 | +label = tmp.label; |
| 12 | + |
| 13 | +phi = X * (180/8); % Presented orientation in degrees |
| 14 | + |
| 15 | +numF = size(Y, 1); |
| 16 | +numT = size(Y, 2); |
| 17 | +numN = size(Y, 3); |
| 18 | + |
| 19 | +%% Probabilistic classification |
| 20 | +% Create folds |
| 21 | +cfg = []; |
| 22 | +cfg.nFold = 5; |
| 23 | +folds = createFolds(cfg, phi); |
| 24 | + |
| 25 | +cfg = []; |
| 26 | +cfg.folds = folds; |
| 27 | +cfg.feedback = 'yes'; |
| 28 | +cfg.trainfun = 'train_array'; |
| 29 | +cfg.traincfg.feedback = 'yes'; |
| 30 | +cfg.traincfg.trainfun = 'train_probClass'; |
| 31 | +cfg.traincfg.traincfg.gamma = 0.01; |
| 32 | +cfg.decodefun = 'decode_arrayGeneralization'; |
| 33 | +cfg.decodecfg.feedback = 'yes'; |
| 34 | +cfg.decodecfg.decodefun = 'decode_probClass'; |
| 35 | + |
| 36 | +pPost = decodeCrossValidation(cfg, phi, Y); |
| 37 | + |
| 38 | +% Extract classes |
| 39 | +[~, class] = max(pPost, [], 1); |
| 40 | +class = squeeze(class); |
| 41 | + |
| 42 | +% Classification accuracy |
| 43 | +correct = (class == repmat(permute((X+1), [1 3 2]), [numT, numT])); |
| 44 | + |
| 45 | +[~, pCorrect] = ttest(correct*1, 1/8, 'dim', 3); |
| 46 | +mCorrect = mean(correct, 3); |
| 47 | + |
| 48 | +figure; colormap(jet(256)); |
| 49 | +subplot(2, 1, 1); imagesc(time, time, mCorrect); colorbar; eqClims(1/8); axis image; axis xy; |
| 50 | +subplot(2, 1, 2); imagesc(time, time, log10(pCorrect) .* (pCorrect < 0.05)); colorbar; axis image; axis xy; |
| 51 | + |
| 52 | +numC = 8; |
| 53 | + |
| 54 | +pPostCorrect = zeros(numT, numT, numN); |
| 55 | +for ic = 1:numC |
| 56 | + pPostCorrect(:, :, X==(ic-1)) = pPost(ic, :, :, X==(ic-1)); |
| 57 | +end |
| 58 | + |
| 59 | +[~, ppPost] = ttest(pPostCorrect, 1/8, 'dim', 3); |
| 60 | +mCorrect = mean(pPostCorrect, 3); |
| 61 | + |
| 62 | +% Plot |
| 63 | +figure; colormap(jet(256)); |
| 64 | +subplot(2, 1, 1); imagesc(time, time, mCorrect); colorbar; eqClims(1/8); axis image; axis xy; |
| 65 | +subplot(2, 1, 2); imagesc(time, time, log10(ppPost) .* (ppPost < 0.05)); colorbar; axis image; axis xy; |
| 66 | + |
| 67 | +%% B&H model |
| 68 | +% Create design matrix |
| 69 | +numC = 8; |
| 70 | + |
| 71 | +cfg = []; |
| 72 | +cfg.numC = numC; |
| 73 | +cfg.tuningCurve = 'vonMises'; |
| 74 | +cfg.kappa = 5; |
| 75 | + |
| 76 | +design = designMatrix_BH(cfg, phi); |
| 77 | + |
| 78 | +% Create folds |
| 79 | +cfg = []; |
| 80 | +cfg.nFold = 5; |
| 81 | +folds = createFolds(cfg, X); |
| 82 | + |
| 83 | +cfg = []; |
| 84 | +cfg.folds = folds; |
| 85 | +cfg.feedback = 'yes'; |
| 86 | +cfg.trainfun = 'train_array'; |
| 87 | +cfg.traincfg.feedback = 'yes'; |
| 88 | +cfg.traincfg.trainfun = 'train_beamformer'; |
| 89 | +cfg.traincfg.traincfg.gamma = 0.01; |
| 90 | +cfg.decodefun = 'decode_arrayGeneralization'; |
| 91 | +cfg.decodecfg.feedback = 'yes'; |
| 92 | +cfg.decodecfg.decodefun = 'decode_beamformer'; |
| 93 | + |
| 94 | +Xhat = decodeCrossValidation(cfg, design, Y); |
| 95 | + |
| 96 | +% Extract single orientations and correlate |
| 97 | +kernel = exp(1i * (0:(numC-1)) * (2*pi/numC)); |
| 98 | +Z = reshape(kernel*reshape(Xhat, [numC, numT*numT*numN]), [numT, numT, numN]); |
| 99 | +theta = mod(angle(Z), 2*pi) * (180/pi) * 0.5; % Decoded orientation |
| 100 | + |
| 101 | +r = exp(1i * (theta - repmat(permute(phi, [1 3 2]), [numT, numT, 1])) * (pi/180)*2); |
| 102 | +r = abs(r) .* cos(angle(r)); |
| 103 | + |
| 104 | +[~, p] = ttest(r, 0, 'dim', 3); |
| 105 | +mr = mean(r, 3); |
| 106 | + |
| 107 | +% Plot |
| 108 | +figure; colormap(jet(256)); |
| 109 | +subplot(2, 1, 1); imagesc(time, time, mr); colorbar; eqClims; axis image; axis xy; |
| 110 | +subplot(2, 1, 2); imagesc(time, time, log10(p) .* (p < 0.05)); colorbar; axis image; axis xy; |
| 111 | + |
| 112 | + |
| 113 | + |
| 114 | + |
| 115 | + |
| 116 | + |
| 117 | + |
| 118 | + |
| 119 | + |
| 120 | + |
| 121 | + |
| 122 | + |
| 123 | + |
0 commit comments