Skip to content

Commit

Permalink
refactor continues
Browse files Browse the repository at this point in the history
  • Loading branch information
jooh committed Nov 6, 2013
1 parent 025a88c commit 621ff11
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 43 deletions.
13 changes: 5 additions & 8 deletions RidgeGLM.m
@@ -1,22 +1,19 @@
% CovGLM sub-class for regularised ridge fits.
% gl = RidgeGLM(X,data,k,[unscale],[covariatedegree]);
classdef RidgeGLM < CovGLM
% GLM sub-class for regularised ridge fits.
% gl = RidgeGLM(X,data,k,[unscale])
classdef RidgeGLM < GLM
properties
k % regularisation parameter (gets scaled by k*nsamples in ridgevec)
unscale % return data to original scale (default 0)
end

methods
function gl = RidgeGLM(X,data,k,unscale,covariatedegree)
function gl = RidgeGLM(X,data,k,unscale)
if nargin == 0
% support no input case
[X,data,k] = deal([]);
end
% initialise with super-class constructor
if ieNotDefined('covariatedegree')
covariatedegree = [];
end
gl = gl@CovGLM(X,data,covariatedegree);
gl = gl@GLM(X,data);
gl.k = k;
if ieNotDefined('unscale')
unscale = 0;
Expand Down
21 changes: 4 additions & 17 deletions containers/BaseVolume.m
Expand Up @@ -98,12 +98,12 @@
metafeatures);
end

function processchunks(self,fname,varargin)
function filterbychunk(self,fname,varargin)
% general method for fevaling some fname which takes sample data
% from each chunk as a first input and anything else in the
% following.
%
% processchunks(self,fname,[varargin])
% filterbychunk(self,fname,[varargin])
for c = 1:self.desc.samples.nunique.chunks
chunkind = self.meta.samples.chunks == ...
self.desc.samples.unique.chunks(c);
Expand All @@ -112,28 +112,15 @@ function processchunks(self,fname,varargin)
end
end

function medianfilter(self,n)
% medianfilter(n)
% filter the data in place along the sample dimension (time) with
% filter size n. Operates separately on each chunk.
processchunks(self,'medianfilter',n);
end

function sgdetrend(self,k,f)
% use a Savitzky-Golay filter to detrend the data across time.
% Operates separately on each chunk
processchunks(self,@(data,k,f)data-sgolayfilt(data,k,f,[],...
filterbychunk(self,@(data,k,f)data-sgolayfilt(data,k,f,[],...
1),k,f);
end

function sgfilter(self,k,f)
processchunks(self,'sgolayfilt',k,f,[],1);
end

function zscore(self)
% Zscore the data across time, operating separately on each
% chunk.
processchunks(self,'zscore',[],1);
filterbychunk(self,'sgolayfilt',k,f,[],1);
end

function checkmeta(self)
Expand Down
21 changes: 5 additions & 16 deletions decoding/roidata_lindisc.m
Expand Up @@ -4,12 +4,6 @@
%
% Named inputs:
%
% (for vol2glm_batch)
% sgolayK: degree of optional Savitsky-Golay detrend
% sgolayF: filter size of optional Savitsky-Golay detrend
% covariatedeg: polynomial detrend degree (or 'adaptive')
% targetlabels: labels to explicitly include (default all)
% ignorelabels: labels to explicitly exclude (default none)
% glmclass: char defining CovGLM sub-class (e.g. 'CovGLM')
% glmvarargs: any additional arguments for GLM (e.g. k for RidgeGLM)
%
Expand All @@ -21,10 +15,9 @@
% [res,nulldist,bootdist] = roidata_lindisc(rois,designvol,epivol,contrasts,varargin)
function [res,nulldist,bootdist] = roidata_lindisc(rois,designvol,epivol,contrasts,varargin)

ts = varargs2structfields(varargin,struct('sgolayK',[],'sgolayF',[],...
'split',[],'covariatedeg','adaptive','targetlabels',[],...
'ignorelabels','responses','glmclass','CovGLM','glmvarargs',[],...
'nperm',1,'nboot',0,'usegpu',false));
ts = varargs2structfields(varargin,struct(...
'split',[],'glmclass','GLM','glmvarargs',[],...
'nperm',1,'nboot',0));

if ~iscell(ts.split)
% so we can easily deal to cvgroup field later
Expand Down Expand Up @@ -72,13 +65,9 @@
% (we will need to strip out 0 cons eventually for speed - maybe move
% this inside contrast loop and apply a skipcon that gets applied just
% before volume stage?)
model = vol2glm_batch(designvol,epivol(:,validvox),...
'sgolayK',ts.sgolayK,'sgolayF',ts.sgolayF,'split',[],...
'covariatedeg',ts.covariatedeg,'targetlabels',ts.targetlabels,...
'ignorelabels',ts.ignorelabels,'glmclass',ts.glmclass,...
'glmvarargs',ts.glmvarargs,'usegpu',ts.usegpu);
model = vol2glm(designvol,epivol(:,validvox),ts.glmclass,...
ts.glmvarargs{:});
% nb model can still have multiple array entries
model = model{1};
[model.cvgroup] = ts.split{:};
res.nfeatures(r) = model.nfeatures;

Expand Down
4 changes: 2 additions & 2 deletions rsa/roidata2rdmvol_lindisc.m
Expand Up @@ -11,7 +11,7 @@
%
% named varargs:
%
% glmclass: char defining CovGLM sub-class (e.g. 'CovGLM')
% glmclass: char defining GLM class (default GLM)
% glmvarargs: any additional arguments for GLM (e.g. k for RidgeGLM)
% split: indices to define GLM cvgroups (if crossvalidate) - NB NOT used in
% vol2glm_batch
Expand All @@ -29,7 +29,7 @@
function disvol = roidata2rdmvol_lindisc(rois,designvol,epivol,varargin)

ts = varargs2structfields(varargin,struct(...
'split',[],'covariatedeg',[],...
'split',[],...
'glmclass','GLM','glmvarargs',{},'sterrunits',false,'crossvalidate',...
false,'minvoxeln',0,'batchsize',5000));

Expand Down

0 comments on commit 621ff11

Please sign in to comment.