Skip to content

Commit

Permalink
Merge a084954 into 702a802
Browse files Browse the repository at this point in the history
  • Loading branch information
nno committed Jan 31, 2020
2 parents 702a802 + a084954 commit 74055eb
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 21 deletions.
2 changes: 1 addition & 1 deletion mvpa/cosmo_cartprod.m
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
p=cartprod(xs);

% if input was a struct, output is a cell with structs
if as_struct();
if as_struct
p=cell2structs(p, fns);
elseif convert_to_numeric && ~isempty(p) && ...
all(cellfun(@isnumeric,p(:)))
Expand Down
18 changes: 13 additions & 5 deletions mvpa/cosmo_check_external.m
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@

function is_ok=check_external_toolbox(external_name,raise_)
externals=get_externals();
if ~isfield(externals, external_name);
if ~isfield(externals, external_name)
error('Unknown external ''%s''', external_name);
end

Expand Down Expand Up @@ -292,10 +292,6 @@

tf=cached_tf;

%paths=cosmo_strsplit(path(),pathsep());
%starts_with_toolbox_dir=@(x)isempty(cosmo_strsplit(x,toolbox_dir,1));
%f=any(cellfun(starts_with_toolbox_dir,paths));


function s=url2str(url)
if strcmp(cosmo_wtf('environment'),'matlab')
Expand Down Expand Up @@ -405,6 +401,18 @@
'Article ID 156869, 9 pages.',...
'doi:10.1155/2011/156869'];

externals.eeglab.is_present=@() has('eeglab') ...
&& has('pop_loadset');
externals.eeglab.is_recent=yes;
externals.eeglab.label='EEGLAB toolbox';
externals.eeglab.url='https://sccn.ucsd.edu/eeglab/';
externals.eeglab.authors={'A. Delorme','S. Makeig'};
externals.eeglab.year='2004';
externals.eeglab.ref=['EEGLAB: an open source toolbox for analysis '...
'of single-trial EEG dynamics. '...
'Journal of Neuroscience Methods 134:9-21'];


externals.libsvm.is_present=@() has('svmpredict') && ...
has('svmtrain');
% require version 3.18 or later, because it has a 'quiet' option
Expand Down
9 changes: 5 additions & 4 deletions mvpa/cosmo_oddeven_partitioner.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
% partitions=cosmo_oddeven_partitioner(chunks,[type])
%
% Input
% ds dataset struct with field .ds.chunks, or Px1 chunk
% indices (for P samples).
% ds dataset struct with field .ds.chunks.
% type One of:
% - 'full': two partitions are returned, training on odd
% unique chunks and testing on even unique chunks,
Expand All @@ -30,7 +29,8 @@
%
% Example:
% ds=struct();
% ds.sa.samples=NaN(6,99); % will be ignored by this function
% ds.samples=NaN(8,99); % will be ignored by this function
% ds.sa.targets=[8 9 8 9 8 9 8 9]';
% ds.sa.chunks=[1 1 2 2 6 7 7 6]';
% p=cosmo_oddeven_partitioner(ds);
% % note that chunks=6 ends up in the odd chunks and chunks=7 in the
Expand Down Expand Up @@ -133,7 +133,8 @@
partitions.train_indices=train_indices;
partitions.test_indices=test_indices;


% final check to make sure all is kosher (including balanced-ness)
cosmo_check_partitions(partitions,ds);

function ds=get_chunks(ds)
if isnumeric(ds) && isvector(ds)
Expand Down
8 changes: 4 additions & 4 deletions tests/test_meeg_io.m
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ function test_eeglab_io_ersp()
{'ersp'},...
{false,true}});

ncombi=size(args,1);
ncombi=size(args,1);
for k=1:ncombi
arg=args(k,1:3);
[s,ds_cell,ext]=build_eeglab_dataset_struct(arg{:});
Expand Down Expand Up @@ -558,7 +558,7 @@ function test_eeglab_io_exceptions()
case 'erspbase'
chan_suffix='_erspbase';

case 'itc';
case 'itc'
chan_suffix='_itc';

otherwise
Expand All @@ -577,7 +577,7 @@ function test_eeglab_io_exceptions()
has_freq=true;


case {'erp'};
case {'erp'}
has_freq=false;

otherwise
Expand All @@ -602,7 +602,7 @@ function test_eeglab_io_exceptions()
if hastime
% include time dimension
time_label={'time'};
time_value={(1:time_dim())*.2-.1};
time_value={(1:time_dim)*.2-.1};
else
% no time dimension
time_dim=[];
Expand Down
33 changes: 26 additions & 7 deletions tests/test_oddeven_partitioner.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
initTestSuite;

function test_test_oddeven_partitioner_basics
for nchunks=[2 6 7 8]
for nchunks=[2 6 8]
ds=cosmo_synthetic_dataset('ntargets',3,'nchunks',nchunks);

nsamples=size(ds.samples,1);
rp=randperm(ceil(nsamples*.7));
rp=randperm(nsamples);
ds=cosmo_slice(ds,[rp rp]);

unq_chunks=unique(ds.sa.chunks);
Expand All @@ -27,15 +27,15 @@
fp.train_indices={idx_odd, idx_even};
fp.test_indices={idx_even, idx_odd};
assert_partitions_equal(fp,cosmo_oddeven_partitioner(ds,'full'));
c=ds.sa.chunks;
assert_partitions_equal(fp,cosmo_oddeven_partitioner(c,'full'));
%c=ds.sa.chunks;
%assert_partitions_equal(fp,cosmo_oddeven_partitioner(c,'full'));

hp=struct();
hp.train_indices={idx_odd};
hp.test_indices={idx_even};
assert_partitions_equal(hp,cosmo_oddeven_partitioner(ds,'half'));
c=ds.sa.chunks;
assert_partitions_equal(hp,cosmo_oddeven_partitioner(c,'half'));
%c=ds.sa.chunks;
%assert_partitions_equal(hp,cosmo_oddeven_partitioner(c,'half'));
end


Expand Down Expand Up @@ -69,7 +69,26 @@ function assert_cell_same_elements(p,q)
assertEqual(sort(p{k}),sort(q{k}));
end


function test_unbalanced_partitions()
ds=struct();
for ntargets=2:5
for nchunks=2:5
nsamples=ntargets*nchunks;
ds.samples=randn(nsamples,1);
ds.sa.chunks=repmat(1:nchunks,1,ntargets)';
ds.sa.targets=ceil((1:nsamples)'/nchunks);

idxs=cosmo_randperm(numel(ds.sa.chunks));
ds=cosmo_slice(ds,idxs);

% should be ok
cosmo_oddeven_partitioner(ds);

idx=ceil(rand()*ntargets*nchunks);
ds.sa.chunks(idx)=ds.sa.chunks(idx)+1;
assertExceptionThrown(@() cosmo_oddeven_partitioner(ds),'*');
end
end



0 comments on commit 74055eb

Please sign in to comment.