Skip to content
Permalink
Browse files

Merge pull request #188 from nno/_enh/small_fixes

Small fixes
  • Loading branch information
nno committed Jan 31, 2020
2 parents 702a802 + a084954 commit 951d577061e50b5c88f9cd9f3923233b7862dd5d
@@ -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(:)))
@@ -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

@@ -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')
@@ -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
@@ -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,
@@ -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
@@ -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)
@@ -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{:});
@@ -558,7 +558,7 @@ function test_eeglab_io_exceptions()
case 'erspbase'
chan_suffix='_erspbase';

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

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


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

otherwise
@@ -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=[];
@@ -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);
@@ -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


@@ -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 951d577

Please sign in to comment.
You can’t perform that action at this time.