Commit ee695e7c authored by Sam Harrison's avatar Sam Harrison
Browse files

BUGFIX: Improve numerical stability of dual-reg

For some reason, not all versions of MATLAB propagate the zero maps through the
`pinv()`. Therefore have to re-null the timecourses etc.
parent 9197fbe5
......@@ -3,9 +3,10 @@ function [ P, A ] = runDR( D, Pg, params )
% and time courses
nComps = size(Pg, 2);
EPS = 1.0e-5;
% Remove any almost zero maps to keep things more computationally stable
Pg(:, std(Pg) < 1.0e-5 * max(std(Pg))) = 0.0;
Pg(:, std(Pg) < EPS * max(std(Pg))) = 0.0;
% Regression for the time courses
iPg = pinv(Pg - mean(Pg,1));
......@@ -16,6 +17,10 @@ for s = 1:params.S
% Extract time courses
Dsr = D{s}{r} - mean(D{s}{r},1);
A{s}{r} = iPg * Dsr;
% Remove any almost zero timecourses
sA = std(A{s}{r}');
A{s}{r}(sA < EPS * max(sA), :) = 0.0;
end
end
......@@ -31,6 +36,10 @@ for s = 1:params.S
end
% Pseudo-inverse to get P
P{s} = Ds * pinv(As);
% Remove any almost zero maps
sP = std(P{s});
P{s}(:, sP < EPS * max(sP)) = 0.0;
end
end
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment