Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CorrRSA is now more general PluginRSA
- Loading branch information
Showing
4 changed files
with
68 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
% RSA based on a custom function, applied to each feature in a parfor loop | ||
% (with optional varargs applied). This is slower than vectorised forms of | ||
% RSA but enables custom RSA types such as Kendall's tau. | ||
% | ||
% gl = PluginRSA(modelrdms,datardms,corrfun,[corrargs]) | ||
classdef PluginRSA < RSA | ||
properties | ||
corrfun = []; % type input to matlab's corr function | ||
corrargs = {}; | ||
end | ||
|
||
methods | ||
function gl = PluginRSA(modelrdms,datardms,corrfun,varargin) | ||
% use super-class to initialise | ||
gl = gl@RSA(modelrdms,datardms); | ||
assert(gl.npredictors==1,'only 1 model RDM input supported'); | ||
% must allow undefined corrfun to support resampling | ||
% (cloneargs method is only called on new instance _after_ it | ||
% has been created) | ||
if ieNotDefined('corrfun') | ||
corrfun = []; | ||
end | ||
if ischar(corrfun) | ||
% insure function handle | ||
corrfun = str2func(corrfun); | ||
end | ||
gl.corrfun = corrfun; | ||
gl.corrargs = varargin; | ||
end | ||
|
||
function cloneargs(self,oldinstance) | ||
% make sure corrfun and corrargs survive resampling. | ||
[self.corrfun] = deal(oldinstance.corrfun); | ||
[self.corrargs] = deal(oldinstance.corrargs); | ||
end | ||
|
||
function estimates = fit(self) | ||
% apply some corrfun to every feature in self.data. | ||
% estimates = fit(self) | ||
estimates = NaN([1 self(1).nfeatures]); | ||
X = vertcat(self.X); | ||
data = vertcat(self.data); | ||
inds = 1:self(1).nsamples; | ||
fun = self.corrfun; | ||
args = self.corrargs; | ||
% parfor here means we will encounter nested parfor loops when | ||
% e.g. bootstrapping or permutation testing. However, if we | ||
% don't do this e.g searchlight mapping is likely to turn out | ||
% to be ridiculously slow | ||
parfor f = 1:self(1).nfeatures | ||
estimates(1,f) = fun(X,data(inds,f),args{:}); | ||
end | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
% Split RDM variant of PluginRSA. | ||
% | ||
% gl = SplitPluginRSA(modelrdms,datardms,corrtype) | ||
classdef SplitPluginRSA < PluginRSA & SplitRSA | ||
methods | ||
function gl = SplitPluginRSA(modelrdms,datardms,varargin) | ||
gl = gl@SplitRSA; | ||
gl = gl@PluginRSA(modelrdms,datardms,varargin{:}); | ||
% ideally this should be set by calling SplitRSA constructor | ||
gl.nrandsamp = gl.ncon / 2; | ||
end | ||
end | ||
end |