IRootLab
An Open-Source MATLAB toolbox for vibrational biospectroscopy
data_split_classes.m
Go to the documentation of this file.
1 %> @ingroup datasettools
2 %> @file
3 %> @brief Splits data according to classes. Returns an array of structures.
4 %>
5 %> Split_classes separates data according to the class of each
6 %> instance. Instances are the rows of 'data'.
7 
8 %> @param data irdata object
9 %> @param hierarchy classlabel levels to be taken into account
10 %>
11 %> @return <em>[pieces]</em> or <em>[pieces, map]</em>. @c pieces: array of irdata objects; @c map cell array of vectors containing the
12 %> indexes of the rows in the original dataset that went to each element of piece.
13 function varargout = data_split_classes(data, hierarchy)
14 
15 if sum(data.classes < 0) > 0
16  irwarning('Dataset has negative classes which will be ignored!');
17 end;
18 
19 if data.nc == 0
20  out = data;
21  obsmaps = {1:data.no};
22 else
23 
24  if ~exist('hierarchy', 'var')
25  hierarchy = []; % means maximum possible
26  end;
27 
28  cellmap = classlabels2cell(data.classlabels, hierarchy);
29  idxs_cl_new = cell2mat(cellmap(:, 4));
30  no_classes = max(idxs_cl_new)+1;
31  classmaps = cell(1, no_classes);
32  for i = 1:no_classes
33  classmaps{i} = find(idxs_cl_new == i-1);
34  end;
35 
36 
37 
38  obsmaps = classmap2obsmap(classmaps, data.classes);
39  out = data.split_map(obsmaps);
40 end;
41 
42 if nargout == 1
43  varargout = {out};
44 else
45  varargout = {out, obsmaps};
46 end;
Dataset class.
Definition: irdata.m:30
function classmap2obsmap(in classmaps, in classes)
function data_split_classes(in data, in hierarchy)
function classlabels2cell(in classlabels, in new_hierarchy)
function irwarning(in s)