mTRF-Toolbox icon indicating copy to clipboard operation
mTRF-Toolbox copied to clipboard

bug in mTRFtransform.m

Open nbara opened this issue 6 years ago • 1 comments

Hi Mick,

There might be a small bug in mTRFtransform.m:

Consider the following toy example:


% Toy dataset
fs = 8;
X = rand(8, 500) / 4 - 0.125;  % eeg
y = rand(1, 500) / 4 - 0.125;  % stim
tmin = -125;
tmax = 250;

% Add some here and there, make sure spikes are delayed in X relative to y
X(3:end, [102, 202, 302, 402]) = 3;
y(:, [100, 200, 300, 400]) = 4;
X(1, :) = 0;  % zero out channel 1

% Train a backward model and invert it
[g,t,c] = mTRFtrain(y',X',fs,-1,tmin, tmax,1e-3);
[gt,tt,ct] = mTRFtransform(y',X', g, fs, -1, tmin, tmax, c);

% Gymnastics to format the new model weights
gtt = zeros(size(gt, 2), 1, size(gt, 1));
gtt(:, 1, :) = gt';
recon = mTRFpredict(y', [], gtt, fs, 1, tmin, tmax, ct');

% Plot
figure(1); clf;
plot(y, 'k:'); hold on;
plot(recon(:,3) - mean(ct));

There's an offset between the stim and the reconstruction: untitled

I think maybe this line should be changed from : model_t = reshape(model_t(size(x,2)+1:end,:),size(x,2),length(tmin:tmax),size(y,2)); to : model_t = reshape(model_t(1:end-size(x,2),:),size(x,2),length(tmin:tmax),size(y,2));

EDIT1: upon closer inspection of the code my solution is probably not correct either. Not sure where this comes from

nbara avatar Sep 24 '18 10:09 nbara