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

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