annotate toolboxes/MIRtoolbox1.3.2/somtoolbox/som_dreval.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
rev   line source
wolffd@0 1 function [sig,cm,truex,truey] = som_dreval(sR,D,sigmea,inds1,inds2,andor)
wolffd@0 2
wolffd@0 3 % SOM_DREVAL Evaluate the significance of the given descriptive rule.
wolffd@0 4 %
wolffd@0 5 % [sig,Cm,truex,truey] = som_dreval(cR,D,sigmea,[inds1],[inds2],[andor])
wolffd@0 6 %
wolffd@0 7 % sR (struct) a rule struct, or an array of rule structs
wolffd@0 8 % D (matrix) the data, of size [dlen x nr]
wolffd@0 9 % sigmea (string) significance measure ('accuracy','accuracyI','mutuconf'),
wolffd@0 10 % see definitions below
wolffd@0 11 % [inds1] (vector) indeces belonging to the group
wolffd@0 12 % (by default: the whole data set)
wolffd@0 13 % [inds2] (vector) indeces belonging to the contrast group
wolffd@0 14 % (by default: the rest of the data set)
wolffd@0 15 % [andor] (string) 'and' or 'or': which conjunction operator to use
wolffd@0 16 % to join the rules for each variable
wolffd@0 17 %
wolffd@0 18 % sig (scalar) significance of the rule
wolffd@0 19 % cm (vector) length 4, vectorized confusion matrix ([a,c,b,d]: see below)
wolffd@0 20 % truex (vector) binary vector indicating for each item in the
wolffd@0 21 % group whether it was true or not
wolffd@0 22 % truey (vector) binary vector indicating for each item in the
wolffd@0 23 % contrast group whether it was true or not
wolffd@0 24 %
wolffd@0 25 % Descriptive rule significance is measured as the match between the
wolffd@0 26 % given groups (inds1 = G1, inds2 = G2) and the rule being true or false.
wolffd@0 27 %
wolffd@0 28 % G1 G2
wolffd@0 29 % --------------- accuracy = (a+d) / (a+b+c+d)
wolffd@0 30 % true | a | b |
wolffd@0 31 % |-------------- mutuconf = a*a / ((a+b)(a+c))
wolffd@0 32 % false | c | d |
wolffd@0 33 % --------------- accuracyI = a / (a+b+c)
wolffd@0 34 %
wolffd@0 35 % See also SOM_DRSIGNIF, SOM_DRMAKE.
wolffd@0 36
wolffd@0 37 % Contributed to SOM Toolbox 2.0, March 4th, 2002 by Juha Vesanto
wolffd@0 38 % Copyright (c) by Juha Vesanto
wolffd@0 39 % http://www.cis.hut.fi/projects/somtoolbox/
wolffd@0 40
wolffd@0 41 % Version 2.0beta juuso 040302
wolffd@0 42
wolffd@0 43 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
wolffd@0 44
wolffd@0 45 % input arguments
wolffd@0 46 if isstruct(D),
wolffd@0 47 switch D.type,
wolffd@0 48 case 'som_data', D = D.data;
wolffd@0 49 case 'som_map', D = D.codebook;
wolffd@0 50 end
wolffd@0 51 end
wolffd@0 52 [dlen,dim] = size(D);
wolffd@0 53 if nargin<4, inds1 = 1:dlen; end
wolffd@0 54 if nargin<5, i = ones(dlen,1); i(inds1) = 0; inds2 = find(i); end
wolffd@0 55 if nargin<6, andor = 'and'; end
wolffd@0 56
wolffd@0 57 % initialize
wolffd@0 58 nr = length(sR);
wolffd@0 59 X = D(inds1,:);
wolffd@0 60 Y = D(inds2,:);
wolffd@0 61 nx = size(X,1);
wolffd@0 62 ny = size(Y,1);
wolffd@0 63 truex = ones(nx,1);
wolffd@0 64 truey = ones(ny,1);
wolffd@0 65
wolffd@0 66 % go through the individual rules
wolffd@0 67 for i=1:nr,
wolffd@0 68 tx = (X(:,i)>=sR(i).low & X(:,i)<sR(i).high);
wolffd@0 69 tx(isnan(X(:,i))) = sR(i).nanis;
wolffd@0 70
wolffd@0 71 ty = (Y(:,i)>=sR(i).low & Y(:,i)<sR(i).high);
wolffd@0 72 ty(isnan(Y(:,i))) = sR(i).nanis;
wolffd@0 73
wolffd@0 74 switch andor,
wolffd@0 75 case 'and', truex = (truex & tx); truey = (truey & ty);
wolffd@0 76 case 'or', truex = (truex | tx); truey = (truey | ty);
wolffd@0 77 end
wolffd@0 78 end
wolffd@0 79
wolffd@0 80 % evaluate criteria
wolffd@0 81 tix = sum(truex(isfinite(truex)));
wolffd@0 82 tiy = sum(truey(isfinite(truey)));
wolffd@0 83 cm = [tix,nx-tix,tiy,ny-tiy];
wolffd@0 84 sig = som_drsignif(sigmea,cm);
wolffd@0 85
wolffd@0 86 return;
wolffd@0 87
wolffd@0 88