Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/CoSMoMVPA/CoSMoMVPA
Browse files Browse the repository at this point in the history
  • Loading branch information
nno committed Jul 21, 2017
2 parents 98dada6 + 7057e2b commit 4c49646
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 0 deletions.
27 changes: 27 additions & 0 deletions mvpa/cosmo_correlation_measure.m
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@

params=cosmo_structjoin(defaults, varargin);

show_warning_if_no_defaults(defaults,params);

cached_params=params;
cached_varargin=varargin;
end
Expand Down Expand Up @@ -423,3 +425,28 @@
end


function show_warning_if_no_defaults(defaults,params)
keys={'output','post_corr_func'};
has_defaults=isequal(select_fields(defaults,keys),...
select_fields(params,keys));

if ~has_defaults && isequal(params.post_corr_func,@atanh)
name=mfilename();
msg=sprintf(...
['Please note that the ''%s'' function applies '...
'Fisher transformation after the correlations '...
'have been computed. This was a somewhat unfortunate '...
'implementation decision that will not be changed '...
'to avoid breaking behaviour with earlier versions.\n'...
'To disable using the Fisher transformation, use the '...
'''%s'' function while setting the ''post_corr_func'''...
'option to the empty array ([])'],name,name);
cosmo_warning(msg);
end

function subset=select_fields(s, keys)
n=numel(keys);
for k=1:n
key=keys{k};
subset.(key)=s.(key);
end
2 changes: 2 additions & 0 deletions mvpa/cosmo_unflatten.m
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@
error('second argument must be numeric');
end

cosmo_check_dataset(ds);

defaults=struct();
defaults.set_missing_to=0;
defaults.matrix_labels=cell(0);
Expand Down
68 changes: 68 additions & 0 deletions tests/test_correlation_measure.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ function test_correlation_measure_basis()
assertElementsAlmostEqual(delta,c1.samples,'relative',1e-5);
assertEqual(c1.sa.labels,{'corr'});

% reset state and do not show warnings
orig_warning_state=cosmo_warning();
warning_cleaner=onCleanup(@()cosmo_warning(orig_warning_state));
cosmo_warning('reset');
cosmo_warning('off');

c2=cosmo_correlation_measure(ds,'output','correlation');
assertElementsAlmostEqual(reshape(cxy,[],1),c2.samples);
assertEqual(kron((1:4)',ones(4,1)),c2.sa.half2);
Expand Down Expand Up @@ -99,6 +105,12 @@ function test_correlation_measure_regression_spearman()
helper_test_correlation_measure_regression(true);

function helper_test_correlation_measure_regression(test_spearman)
% reset state and do not show warnings
orig_warning_state=cosmo_warning();
warning_cleaner=onCleanup(@()cosmo_warning(orig_warning_state));
cosmo_warning('reset');
cosmo_warning('off');

ds=cosmo_synthetic_dataset('ntargets',3,'nchunks',5,'sigma',.5);
params=get_regression_test_params(test_spearman);

Expand Down Expand Up @@ -189,6 +201,12 @@ function helper_test_correlation_measure_regression(test_spearman)
aet=@(varargin)assertExceptionThrown(@()...
cosmo_correlation_measure(varargin{:}),'');

% reset state and do not show warnings
orig_warning_state=cosmo_warning();
warning_cleaner=onCleanup(@()cosmo_warning(orig_warning_state));
cosmo_warning('reset');
cosmo_warning('off');

ds=cosmo_synthetic_dataset('nchunks',2);
aet(ds,'template',eye(4));
aet(ds,'output','foo');
Expand All @@ -203,3 +221,53 @@ function helper_test_correlation_measure_regression(test_spearman)

ds.sa.targets(1)=2;
aet(ds);

function x=identity(x)

function test_correlation_measure_warning_shown_if_no_defaults()
orig_warning_state=cosmo_warning();
cleaner=onCleanup(@()cosmo_warning(orig_warning_state));

% reset state and do not show warnings
cosmo_warning('reset');
cosmo_warning('off');

funcs={[],@atanh};
outputs={[],'mean','raw','correlation'};



for k=1:numel(funcs)
func=funcs{k};
for j=1:numel(outputs)
output=outputs{j};

is_default_func=k<=2;
is_default_output=j<=2;
expect_warning=~(is_default_func && is_default_output);

opt=struct();
if ~isempty(func)
opt.post_corr_func=func;
end

if ~isempty(output)
opt.output=output;
end

cosmo_warning('reset');
cosmo_warning('off');

ds=cosmo_synthetic_dataset('nchunks',2);
cosmo_correlation_measure(ds,opt);

s=cosmo_warning();

showed_warning=numel(s.shown_warnings)>0;

assertEqual(expect_warning,showed_warning);
end
end



6 changes: 6 additions & 0 deletions tests/test_distatis.m
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,12 @@
% cannot take non-matrix input
aet({zeros([2 2 2])},opt);

% illegal field in dataset
ds_bad=ds;
ds_bad.foo=2;
opt=struct();
aet(ds_bad,opt);



function ds=get_distance_dataset(d)
Expand Down
9 changes: 9 additions & 0 deletions tests/test_flatten.m
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,12 @@ function run_helper_test_flatten(nsamples, nfdim, dim)
aet(ds,3);
aet(ds,[1 1]*dim,opt);

function test_unflatten_exceptions()
aet=@(varargin)assertExceptionThrown(@()...
cosmo_unflatten(varargin{:}),'');
ds=cosmo_synthetic_dataset();
cosmo_unflatten(ds); % should be ok

bad_ds=ds;
bad_ds.foo=2;
aet(bad_ds);

0 comments on commit 4c49646

Please sign in to comment.