function result=cosmo_naive_bayes_classifier_searchlight(ds, nbrhood, varargin)
% Run (fast) Naive Bayes classifier searchlight with crossvalidation
%
% result=cosmo_naive_bayes_classifier_searchlight(ds, nbrhood, ...)
%
% Inputs:
% ds dataset struct
% nbrhood Neighborhood structure with fields:
% .a struct with dataset attributes
% .fa struct with feature attributes. Each field
% should have NF values in the second dimension
% .neighbors cell with NF mappings from center_ids in output
% dataset to feature ids in input dataset.
% Suitable neighborhood structs can be generated
% using:
% - cosmo_spherical_neighborhood (fmri volume)
% - cosmo_surficial_neighborhood (fmri surface)
% - cosmo_meeg_chan_neigborhood (MEEG channels)
% - cosmo_interval_neighborhood (MEEG time, freq)
% - cosmo_cross_neighborhood (to cross neighborhoods
% from the neighborhood
% functions above)
% 'partitions', par Partition scheme to use. Typically this is the
% output from cosmo_nfold_partitioner or
% cosmo_oddeven_partitioner. Partitions schemes
% with more than one prediction for samples in the
% test set (such as the output from
% cosmo_nchoosek_partitioner(N) with N>1) are not
% supported
% 'output', out One of:
% 'accuracy' return classification accuracy
% 'predictions' return prediction for each sample
% in a test set in partitions
% 'progress', p Show progress every p folds (default: 1)
%
% Output:
% results_map a dataset struct where the samples
% contain classification accuracies or class
% predictions
%
% Example:
% % generate tiny dataset (6 voxels) and define a tiny spherical
% % neighborhood with a radius of 1 voxel.
% ds=cosmo_synthetic_dataset('nchunks',10,'ntargets',5);
% nh=cosmo_spherical_neighborhood(ds,'radius',1,'progress',false);
% %
% % set options
% opt=struct();
% opt.progress=false;
% % define take-one-chunk-out crossvalidation scheme (10 folds)
% opt.partitions=cosmo_nfold_partitioner(ds);
% %
% % run searchlight
% result=cosmo_naive_bayes_classifier_searchlight(ds,nh,opt);
% %
% % show result
% cosmo_disp(result);
% %|| .a
% %|| .fdim
% %|| .labels
% %|| { 'i' 'j' 'k' }
% %|| .values
% %|| { [ 1 2 3 ] [ 1 2 ] [ 1 ] }
% %|| .vol
% %|| .mat
% %|| [ 2 0 0 -3
% %|| 0 2 0 -3
% %|| 0 0 2 -3
% %|| 0 0 0 1 ]
% %|| .dim
% %|| [ 3 2 1 ]
% %|| .xform
% %|| 'scanner_anat'
% %|| .fa
% %|| .nvoxels
% %|| [ 3 4 3 3 4 3 ]
% %|| .radius
% %|| [ 1 1 1 1 1 1 ]
% %|| .center_ids
% %|| [ 1 2 3 4 5 6 ]
% %|| .i
% %|| [ 1 2 3 1 2 3 ]
% %|| .j
% %|| [ 1 1 1 2 2 2 ]
% %|| .k
% %|| [ 1 1 1 1 1 1 ]
% %|| .samples
% %|| [ 0.6 0.74 0.44 0.6 0.7 0.4 ]
% %|| .sa
% %|| .labels
% %|| { 'accuracy' }
%
%
% Notes:
% - this function runs considerably faster than using a searchlight with
% a classifier function and a crossvalidation scheme, because model
% parameters during training are estimated only once for each feature.
% Thus, speedups are most significant if elements in the neighborhood
% have many overlapping features
% - for other classifiers or other measures, use the more flexible
% cosmo_searchlight function
%
% See also: cosmo_searchlight
%
% # For CoSMoMVPA's copyright information and license terms, #
% # see the COPYING file distributed with CoSMoMVPA. #