Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
806e6f8
Wrote scaffold of new code
dankessler Oct 11, 2011
dfae375
First skeleton of svmbatch.sh written
dankessler Oct 13, 2011
8038ad4
Added two functions to the shell script.
dankessler Oct 24, 2011
917b94c
Huge update to svmbatch.
dankessler Dec 2, 2011
074a764
Added kernel and directory support to SVM batch options
dankessler Dec 5, 2011
6c58471
Added totem.suf (but currently dirty, contains examples of my data
dankessler Dec 2, 2011
b7d0948
Updated options (and updated options support to default to more reaso…
dankessler Dec 12, 2011
b0b0334
Huge rewrite. Everything in functional form now. Currently, main func…
dankessler Dec 12, 2011
b286e6a
Cleaned up functional rewrite
dankessler Dec 13, 2011
f27a9ab
Huge functional rewrite of svmbatch code
dankessler Dec 14, 2011
90c3993
More updates. About to start testing
dankessler Dec 14, 2011
3abb1ce
Testing completed on new functional form
dankessler Dec 14, 2011
2ae54f2
Removed dirty lines from sample totem.suf
dankessler Dec 14, 2011
4104278
Fixed errors around totem mode
dankessler Dec 14, 2011
7e27b7a
Fixed issues with totem processor (mostly quoting problems). Fixed on…
dankessler Dec 14, 2011
985372e
Fixed mistake in super cross validation that PROGRESSIVELY eliminated…
dankessler Dec 14, 2011
2945dec
Added tentative support for permutation testing
dankessler Dec 16, 2011
92f3fe9
hopefully fixed permutation test errors
dankessler Dec 16, 2011
b13d8ae
Permutation testing is now working. Planning to use symlinks for next…
dankessler Dec 19, 2011
6c7c26c
Updated permutation test to leverage preexisting training examples th…
dankessler Dec 19, 2011
f78e0d8
Added support for specifying count of permutation tests at command line
dankessler Dec 19, 2011
cbdb7ea
Added matlab code for completing permutation tests
dankessler Dec 19, 2011
21a2e4f
Added placeholder for code to rearrange permutation tests
dankessler Dec 19, 2011
4658ca3
updated permutation test results arranged
dankessler Dec 19, 2011
9843046
updated script for permutation test in matlab
dankessler Dec 19, 2011
35fca2d
Updated supplemental scripts related to permutation testing
dankessler Jan 6, 2012
2895662
Some hacky edits of permutation visualization functions
dankessler Feb 15, 2012
460eb7d
cleaned up matlab portion of permutation testing
dankessler Mar 7, 2012
652c850
updated svmbatch.sh with routines for permutation testing
dankessler Mar 7, 2012
591fc3a
This empty commit should close #18 by adding the current body of svmb…
dankessler Mar 7, 2012
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions svmbatch/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
SVM Batch

Written 2011 by Daniel Kessler, kesslerd@umich.edu

**Prerequisites**
This was code was written and tested in AFNI_2011_05_26_1457


This batch script should not require any modification by you. Instead, you customize it by editing the support text files that come with it, namely:

*svmdir
This file should contain a path to an extant directory where the script should store all of its intermediates and results

*filelist1
This should contain a whitespace-delimted list of (ideally absolute) paths to files that 3dsvm will consider to be examples of class 1. If you are giving it data from img/hdr pairs, be sure to point to the hdr (it will figure out where the img is based on the hdr).

*filelist2
Just like filelist1, except these are files that represent examples from class 2.

That's it. Other support files may be added as we extend functionality.


**Likely future additions

1) Automatic testing of model on training set
2) Automated partitioning of examples into training set and test set for model cross-validation
3) Permutation testing. This will be computationally intensive, but not too hard to implement.
Empty file added svmbatch/filelist1
Empty file.
Empty file added svmbatch/filelist2
Empty file.
77 changes: 77 additions & 0 deletions svmbatch/matlab_Scripts/permutation_test.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
%function [Y] = permutation_test(Pt,Pdir,name)
% Calculate nonparametric distributions based on svm permutation tests
% Pt - filename of weight vector from real model
% Pdir - file directory in which to search for results of permutation test
% img/hdr pairs
% name - string of name to write out (without .img extension)

%% Make list of files
Pp=spm_select('List',Pdir,'[0-9]+\.hdr');

%% Read in files
th=spm_vol(Pt);
tvol=spm_read_vols(th);


cd(Pdir);
ph=spm_vol(Pp);
pvol=spm_read_vols(ph);
cd ..

%% Create dumping space for comparisons

rvol=zeros(size(tvol));
rh=th;
rh.fname=[name '.img'];
rh.descrip='SPM{T_[10000000]}';

%% Loop over dimensions

% For each voxel, calculate proportion of permutations that resulted in
% smaller or equal value. This returns the nonparametric CDF. We then
% convert this, using norminv, to a z-score. Extremely positive values will
% have high CDF scores, high p scores, and high z scores. Very negative
% values will have very small CDF scores, small p scores, and negative z
% scores. We convert to z for easier visualization in xjview.

for i=1:size(rvol,1), for j=1:size(rvol,2), for k=1:size(rvol,3)
rvol(i,j,k)=norminv(sum(pvol(i,j,k,:)<=tvol(i,j,k))/size(pvol,4));
end,end,end

%% Mask based on tvol
% Some voxels that were zero in the real weight vector are out-of-brain
% voxels. Implicit masking during first level testing should have set them
% to 0. All permutation tests will likely also return 0, yielding a bizarre
% value for the CDF. To protect against this, we set the z-score of these
% points to be 0, for a corresponding p of .5

for i=1:size(rvol,1), for j=1:size(rvol,2), for k=1:size(rvol,3)
if tvol(i,j,k)==0, rvol(i,j,k)=0; end
end,end,end

%% Replace Inf and -Inf values with prior min and max, respectively
% rvol(find(rvol==Inf))=max(rvol(~isinf(rvol)));
% rvol(find(rvol==-Inf))=min(rvol(~isinf(rvol)));

rvol(find(rvol==Inf))=norminv((1-1/size(pvol,4)));
rvol(find(rvol==-Inf))=norminv((1/size(pvol,4)));

%Fix the origin for

rh.mat(:,4)=[-81 -115 -53 1];


%% Write out the resulting p values in one giant file
spm_write_vol(rh,rvol);

%%Slice up the file into its sub-totems, and write them out separately from
%%bottom up

for i=1:(th.dim(3)/46)
cth_range=[1:46] + (i-1)*46;
cth=rh;
cth.fname=sprintf('%s%s%s%.3d%s',pwd,'/', name ,i,'.img');
cth.dim(3)=[46];
ctvol=rvol(:,:,cth_range);
spm_write_vol(cth,ctvol);
end
Loading