Changes in / [20:30]


Ignore:
Files:
9 added
7 edited

Legend:

Unmodified
Added
Removed
  • /distools/clevald.m

    r20 r30  
    248248                                        J = JR(1:nj);
    249249                                        if isempty(repsize)
    250                                                 R = JR;
     250                                                R = J;
    251251                                        elseif repsize < 1
    252252                                                R = JR(1:ceil(repsize*nj));
  • /distools/genddat.m

    r20 r30  
    6060function [DTR,DTE,Itr,Ite] = genddat(D,m,k);
    6161
     62  if nargin < 3, k = []; end
     63
     64        % If input is a cell array of datasets, apply this procedure
     65  % to the individual datasets.
     66        if (iscell(D))
     67                A  = cell(size(D));
     68                B  = cell(size(D));
     69                IA = cell(size(D));
     70                IB = cell(size(D));
     71                seed = randreset;
     72                for j=1:length(D(:))
     73                        randreset(seed);
     74                        [DTR{j},DTE{j},Itr{j},Ite{j}] = feval(mfilename,D{j},m,k);
     75                end
     76                return;
     77        end
     78
     79
     80
    6281[n,nk,c] = getsize(D);
    6382nlab     = getnlab(D);
    6483discheck(D,[],1);   % allow for similarities     
    6584
    66 if nargin < 3,
    67         k = [];
    68 else
     85if ~isempty(k)
    6986        if length(k) == 1
    7087                k = k*ones(1,c);
  • /distools/pe_em.m

    r20 r30  
    3939% ALF of the total variance is preserved for ALF in (0,1). The resulting X is found
    4040% by D*W. The signature of the obtained PE space (numbers of positive and negative
    41 % directions) can be found by PE_SIG(W). The spectrum of the obtained space
    42 % can be found by PE_SPEC(W).
     41% directions) can be found by GETDATA(W,'sig'). The spectrum of the obtained space
     42% can be found by GETDAT(W,'eval').
    4343%
    4444% SEE ALSO
    45 % MAPPINGS, DATASETS, AUGPSEM, PCA, PE_PCA, PE_SPEC, GETSIG, SETSIG
     45% MAPPINGS, DATASETS, AUGPSEM, PCA, GETSIG, SETSIG
    4646%
    4747% LITERATURE
  • /distools/protselfd.m

    r20 r30  
    55%
    66% INPUT
    7 %   D     Dataset, square dissimilarity matrix
     7%   D     Dataset, dissimilarity matrix
    88%   K     Integer, desired number of prototypes
    9 %   PAR  'LOO' - leave-one-out option. This should be used if
    10 %          the objects are related to themselves. If D is not square,
    11 %          it is assumed that the first sets of objects in columns and
    12 %          rows match.
    13 %        'ALL' - use all objects (default).
     9%   PAR   'SUPER' supervised selection using 1NN error on prototypes.
     10%         'LOO' - supervised selection using leave-one-out error estimation.
     11%         'MAXDIST' - unsupervised selection minimizing the maximum
     12%                     distance to the nearest prototype.
     13%         'MEANDIST' - unsupervised selection minimizing the average
     14%                      distance to the nearest prototype.
    1415%
    1516% OUTPUT
    1617%   W     Selection mapping ('feature selection')
    1718%   E     Error stimate as a function of number of selected prototypes
    18 %         (only reliable for prototype sizes >= class size)
    19 %   KOPT  Estimate for best size in avoiding peaking
     19%         (for supervised selection only reliable for prototype sizes >= class size)
     20%   KOPT  Estimate for best size in avoiding peaking
     21%         (supervised selection only)
    2022%
    2123% DESCRIPTION
    22 % This procedure for optimizing the representation set of a
    23 % dissimilarity matrix is based on a greedy, forward selection of
    24 % prototypes using the leave-one-out error estimate of the 1NN rule
    25 % as a criterion. As this is computed on the given distances in
    26 % D, the procedure is based on sorting and counting only and is
    27 % thereby fast. In case K=1 just a single prototype has to be returned,
    28 % but computing the 1NN error is not possible as all objects are assigned
    29 % to the same class. In that case the centre object of the largest class
    30 % will be returned.
    31 %
    32 % Note that the search continues untill K prototypes are found.
    33 % This might be larger than desired due to peaking (curse of
    34 % dimensionality, overtraining). Therefor an estimate for the
    35 % optimal number of prototype is returned in KOPT.
    36 %
    37 % The prototype selection may be applied by C = B*W(:,1:KSEL),
    38 % in which B is a dissimilarity matrix based on the same
    39 % representation set as A (e.g. A itself) and C is a resulting
    40 % dissimilarity matrix in which the KSEL (e.g. KOPT) best prototypes
    41 % are selected.
     24% This procedure for optimizing the representation set of a dissimilarity
     25% matrix is based on a greedy, forward selection of prototypes.
     26%
     27% In case of supervised selection D should be a labeled dataset with
     28% prototype labels stored as feature labels. The 1NN error to the nearest
     29% prototype is used as a criterion. In case of leave-one-out error
     30% estimation it is assumed that the first objects in D correspond with the
     31% prototypes.
     32%
     33% In case K=1 just a single prototype has to be returned, but computing the
     34% 1NN error is not possible as all objects are assigned to the same class.
     35% In that case the centre object of the largest class will be returned.
     36%
     37% Note that the search continues untill K prototypes are found. This might
     38% be larger than desired due to peaking (overtraining). Therefor an
     39% estimate for the optimal number of prototype is returned in KOPT.
     40%
     41% The prototype selection may be applied by C = B*W(:,1:KSEL), in which B
     42% is a dissimilarity matrix based on the same representation set as A (e.g.
     43% A itself) and C is a resulting dissimilarity matrix in which the KSEL
     44% (e.g. KOPT) best prototypes are selected.
     45%
     46% In case of unsupervised selection the maximum or the mean distances to
     47% the nearest prototype are minimized. These criteria are the same as used
     48% in the KCENTRE and KMEDIOD cluster procedures.
    4249%
    4350% REFERENCE
     
    5562%
    5663
    57 function [R,e,D,J,nlab,clab] = protselfd(D,ksel,par,J,e,nlab,clab)
    58 
    59 if nargin < 2, ksel = []; end
    60 if nargin < 3 | isempty(par), par = 'all'; end
    61 
    62 if nargin < 4 % user call
    63  
    64   if nargin < 1 | isempty(D)  % allow for D*protselfd([],pars)
    65     R = mapping(mfilename,'untrained',{ksel,par});
     64function [R,e,D] = protselfd(D,ksel,type)
     65
     66  if nargin < 2, ksel = []; end
     67  if nargin < 3, type = []; end
     68
     69  if nargin < 1 || isempty(D)  % allow for D*protselfd([],pars)
     70    R = mapping(mfilename,'untrained',{ksel,type});
    6671    R = setname(R,'Forward Prototype Sel');
    6772    return
    6873  end
    6974 
     75  switch lower(type)
     76    case {'loo','LOO','super','SUPER','',''}
     77      [R,e,D,J,nlab,clab] = protselfd(D,ksel,type);
     78    case {'maxdist','meandist'}
     79      R = protselfd_unsuper(D,ksel,type);
     80    otherwise
     81      error('Unknown selection type')
     82  end
     83     
     84return 
     85
     86
     87function [R,e,D,J,nlab,clab] = protselfd_super_init(D,ksel,par)
     88% this routine takes care of the initialisation of supervised selection
     89
     90  isdataset(D);
    7091  [m,k,c] = getsize(D);
    7192  if isempty(ksel), ksel = k; end
     
    99120                % this will be a deep recursive call !!!
    100121                prwaitbar(ksel,'Forward prototype selection')
    101                 [R,e,D,J,nlab,clab] = protselfd(D,ksel,R,J,e,nlab,clab);
     122                [R,e,D,J,nlab,clab] = protselfd_super(D,ksel,R,J,e,nlab,clab);
    102123                prwaitbar(0);
    103124        end
     
    110131  D = floor((Jopt(end)+Jopt(1))/2);
    111132 
    112   % done!
    113  
    114 else  % internal call, parameters may have another meaning!
    115  
    116   R = par;  % prototypes sofar
     133return
     134 
     135function [R,e,D,J,nlab,clab] = protselfd_super(D,ksel,R,J,e,nlab,clab)
     136
    117137  [m,k,c] = getsize(D);
    118138  d = +D;
     
    135155    de = sum(ds);
    136156                % if better, use it
    137     if ee < emin | ((ee == emin) & (de < dmin))
     157    if ee < emin || ((ee == emin) && (de < dmin))
    138158      emin = ee;
    139159      jmin = j;
     
    145165  end
    146166
    147   if emin <= e(r) | 1 % we even continue if emin increases due to peaking
     167  if emin <= e(r) || 1 % we even continue if emin increases due to peaking
    148168    e(r+1) = emin;
    149169    R = Rmin;
    150170    if (r+1) < ksel
    151                         [R,e,D,J,nlab,clab] = protselfd(D,ksel,R,Jmin,e,nlab,clab);
     171                        [R,e,D,J,nlab,clab] = protselfd_super(D,ksel,R,Jmin,e,nlab,clab);
    152172    end
    153173  end
    154174 
     175return
     176
     177%PROTSELFD_UNSUPER Forward prototype selection
     178%
     179%               N = PROTSELFD_UNSUPER(D,P,CRIT)
     180%
     181% INPUT
     182%   D     Square dissimilarity matrix, zeros on diagonal
     183%   P     Number of prototypes to be selected
     184%   CRIT  'dist' or 'centre'
     185%
     186% OUTPUT
     187%   N     Indices of selected prototypes
     188%
     189% DESCRIPTION
     190% Sort objects given by square dissim matrix D using a greedy approach
     191% such that the maximum NN distance from all objects (prototypes)
     192% to the first K: max(min(D(:,N(1:K),[],2)) is minimized.
     193%
     194% This routines tries to sample the objects such that they are evenly
     195% spaced judged from their dissimilarities. This may be used as
     196% initialisation in KCENTRES. It works reasonably, but not very good.
     197%
     198% SEE ALSO
     199% KCENTRES
     200
     201% Copyright: R.P.W. Duin, r.p.w.duin@prtools.org
     202% Faculty EWI, Delft University of Technology
     203% P.O. Box 5031, 2600 GA Delft, The Netherlands
     204
     205function N = protselfd_unsuper(d,p,crit)
     206
     207d = +d;
     208[m,k] = size(d);
     209if isempty(crit), crit = 'max'; end
     210if nargin < 2 || isempty(p), p = k; end
     211L = 1:k;
     212N = zeros(1,p);
     213switch crit
     214  case 'maxdist'
     215    [~,n] = min(max(d));    % this is the first (central) prototype
     216  case 'meandist'
     217    [~,n] = min(mean(d));   % this is the first (central) prototype
    155218end
     219e = d(:,n);                 % store here the distances to the nearest prototype (dNNP)
     220f = min(d,repmat(e,1,k));   % replace distances that are larger than dNNP by dNNP
     221N(1) = n;                   % ranking of selected prototypes
     222L(n) = [];                  % candidate prototypes (all not yet selected objects)
     223
     224for j=2:p                   % extend prototype set
     225  switch crit               % select the next prototype out of candidates in L
     226    case 'maxdist'
     227      [~,n] = min(max(f(:,L)));
     228    case 'meandist'
     229      [~,n] = min(mean(f(:,L)));
     230  end
     231  e = min([d(:,L(n)) e],[],2);   % update dNNP
     232  f = min(d,repmat(e,1,k));      % update replacement of distances that are larger
     233                                 % than dNNP by dNNP
     234  N(j) = L(n);                   % update list of selected prototypes
     235  L(n) = [];                     % update list of candidate prototypes
     236end
     237
  • /prextra/Contents.m

    r20 r30  
    2424%rbsvc        Automatic radial basis SVC
    2525%kannc        Fast k-nn classifier for large datasets by annquery
     26%dectreec     Decision tree (fast, because it's using compiled code)
     27%randomforestc  Random Forest (fast, because it's using compiled code)
    2628%
    2729%auc          error under the curve estimator
  • /prextra/prcontent2html.m

    r20 r30  
    11%PRCONTENT2HTML Construct HTML file from PRTools Contents file
    22%
    3 %               PRCONTENT2HTML(NAME,RECREATE)
    4 
    5 
    6 function out = prcontent2html(name,recreate)
    7 
    8 if nargin < 2, recreate = 0; end
     3%               PRCONTENT2HTML(NAME,RECREATE,HTMLDIR)
     4
     5
     6function out = prcontent2html(name,recreate,htmldir)
     7
     8if nargin < 3, htmldir = cd; end
     9if nargin < 2 | isempty(recreate), recreate = 0; end
    910
    1011if exist([name '/Contents.m']) == 2
     
    6364                pp = fileparts(file);
    6465                [pp2,subdir] = fileparts(pp);
    65                 s = [s '<tr> <td width="100" valign="top">' commandrefs(tok,recreate,subdir) '</td>'];
     66                s = [s '<tr> <td width="100" valign="top">' commandrefs(tok,recreate,subdir,htmldir) '</td>'];
    6667                s = [s '<td>' posttok '</td></tr>'];
    6768        end
     
    6970s = [s '</table>'];
    7071s = [s '</p></body></html>'];
    71 writf([name '.html'],s);
     72writf([fullfile(htmldir,name) '.html'],s);
    7273if nargout > 0
    7374        out = s;
     
    130131return
    131132
    132 function s = commandrefs(r,recreate,subdir)
     133function s = commandrefs(r,recreate,subdir,htmldir)
    133134        if nargin < 2, recreate = 0; end
    134135        if regexp(r,'^ *$')
     
    143144        end
    144145       
    145         if exist(htmlname,'file') == 2
     146        if exist(fullfile(htmldir,htmlname),'file') == 2
    146147                s = [s '<a href="' htmlname '">' tok '</a>, '];
    147148        elseif isempty(tok) | regexp(tok,'^ *')
  • /prextra/prhelp2html.m

    r20 r30  
    11%PRHELP2HTML Construct HTML file from help part of PRTools routine
    22%
    3 %               S = PRHELP2HTML(COMMAND,RECREATE,SUBDIR)
     3%               S = PRHELP2HTML(COMMAND,RECREATE,HTMLDIR)
     4%               S = PRHELP2HTML(TOOLBOX,RECREATE,HTMLDIR)
    45%
    56% INPUT
    67%   COMMAND    String with PRTools command, default: all prtools m-files
     8%   TOOLBOX    Name of the toolbox to be handled, default PRTOOLS.
     9%              Toolbox should be in the bath in in this call the last
     10%              character should be a '/'.
    711%   RECREATE   0/1 flag indicating whether non-existing references
    812%              in the SEE ALSO section should be created as well
    9 %   SUBDIR     String with desired sub-directory in which the HTML
     13%   HTMLDIR     String with desired directory in which the HTML
    1014%              file should be stored
    1115%
     
    5660
    5761
    58 
    59 
    60 function out = prhelp2html(name,recreate,subdir)
    61 
    62 if nargin < 3, subdir = []; end
    63 if nargin < 2 || isempty(recreate), recreate = 0; end
    64 if nargin < 1
    65         run_all_files(mfilename);
    66         s = prcontent2html('prtools');
     62% BEFORE YOU START TO DEBUG, READ THIS
     63% This routine was original intended to work on the prtools dir only.
     64% Later it was somewhat changed in order to handle files in prdatasets,
     65% prdatafiles and possibly distools and dd_tools as well. Only for
     66% prtools the subdir structure (with the @dataset, @datafile, @mapping
     67% sub dirs) is recognized, and only if the first parameter, COMMAND, is
     68% empty.
     69%
     70% The Contents files have a special layout. It is handled by prcontent2html
     71% in case of PRTools, but for other toolboxes it most likely doesn't work.
     72%
     73% The formatting rules of the PRTools help are strict. Don't try to relax
     74% them in the below code, but change the help-text if you are not satisfied
     75% with the result. Especially avoid '  ' (double spaces) where they are not
     76% needed as the conversion jumps into a table-mode as soon as they are
     77% encountered.
     78%
     79% Bob Duin, April 2011
     80
     81function out = prhelp2html(name,recreate,htmldir)
     82
     83if nargin < 3, htmldir = cd; end
     84if nargin < 2 | isempty(recreate), recreate = 0; end
     85if nargin < 1 | isempty(name) % default is prtools
     86        dirs = {'ldc','dataset','datafile','mapping'};
     87        run_all_files(mfilename,dirs,htmldir);
     88        s = prcontent2html('prtools',[],htmldir);
    6789        if nargout > 0
    6890                out = s;
    6991        end
    7092        return;
     93else
     94        if strcmp(name(end),'/') & exist(name(1:end-1),'dir') == 7
     95                name = name(1:end-1);
     96                dirs = {fullfile(name,'Contents.m')};
     97                run_all_files(mfilename,dirs,htmldir);
     98                s = prcontent2html(name,[],htmldir); % does not work usually
     99                if nargout > 0
     100                        out = s;
     101                end
     102                return
     103        end
    71104end
    72105
     
    78111end
    79112%[pp,name] = fileparts(file);
    80 if isempty(subdir)
    81         [xx,subdir] = fileparts(fileparts(file));
    82 end
    83 if isempty(strmatch(subdir,char('prtools','@dataset','@datafile','@mapping'),'exact'))
    84 %       disp([name ' Not PRTools'])
    85         out = [];
    86         return
    87 end
     113if isempty(htmldir)
     114        [xx,htmldir] = fileparts(fileparts(file));
     115end
     116% if isempty(strmatch(subdir,char('prtools','@dataset','@datafile','@mapping'),'exact'))
     117% %     disp([name ' Not PRTools'])
     118%       out = [];
     119%       return
     120% end
    88121
    89122disp(file)
     
    295328                state = 'seealso';
    296329                if ~single
    297                         s = [s commandrefs(posttok,recreate)];
     330                        s = [s commandrefs(posttok,recreate,htmldir)];
    298331                end
    299332        else % undefined lines
    300333                if examplestate
    301334                        if length(u) > 3 && strcmpi(u(1:4),'see ')
    302                                 s = [s '</p>' commandrefs(u(5:end),recreate) '<p>'];
     335                                s = [s '</p>' commandrefs(u(5:end),recreate,fileparts(htmldir)) '<p>'];
    303336                        else
    304337                                s = [s strrep(code(strrep(r,' ','#$!'),0,3),'#$!','&nbsp;') '<br>'];
     
    316349                                s = [s '<strong><font size="4">' findmakecode(u(3:end)) '</font></strong><br>'];
    317350                        else
    318                                 s = [s commandrefs(u,recreate)];               
     351                                s = [s commandrefs(u,recreate,htmldir)];               
    319352                        end
    320353                elseif tabstartspace && tabstate && (colpos1 > colpos0) ...
     
    377410s = [s '</p>' content_manual '</body></html>'];
    378411[qq,name] = fileparts(name); % allows for names like dataset/show
    379 if exist(['./' subdir],'file') ~= 7
    380         mkdir(subdir);
    381 end
    382 writf([fullfile(subdir,name) '.html'],s);
     412% if exist(fullfile(htmldir,name),'file') == 2
     413%       htmlname = fullfile(htmldir,name);
     414% else
     415%       %htmlname = [tok '.html'];
     416%       file = which(name);
     417%       pp = fileparts(file);
     418%       [qq,subdir] = fileparts(pp);
     419%       htmldir = fullfile(fileparts(htmldir),subdir);
     420%       htmlname = fullfile(htmldir,name);
     421% end
     422       
     423if exist([htmldir],'file') ~= 7
     424        mkdir(htmldir);
     425end
     426writf([fullfile(htmldir,name) '.html'],s);
    383427disp([int2str(recreate) ' ' name ' html created'])
    384428if nargout > 0
     
    456500end
    457501
    458 function s = commandrefs(r,recreate)
    459         if nargin < 2, recreate = 0; end
     502function s = commandrefs(r,recreate,htmldir)
     503        if nargin < 3, htmldir = cd; end
     504        if nargin < 2 | isempty(recreate), recreate = 0; end
    460505        s = [];
    461506        r_debug = r;
     
    467512                pp = fileparts(file);
    468513                [qq,subdir] = fileparts(pp);
    469                 htmlname = fullfile(subdir,htmlname);
    470                 if exist(htmlname,'file') == 2
    471                         s = [s '<a href="../' htmlname '">' tok '</a>, '];
     514%               htmlname = fullfile(subdir,htmlname);
     515                htmlfullname1 = fullfile(htmldir,htmlname);
     516                htmlfullname2 = fullfile(fullfile(fileparts(htmldir),subdir),htmlname);
     517                if exist(htmlfullname1,'file') == 2  % check whether command is in htmldir
     518                        s = [s '<a href="./' htmlname '">' tok '</a>, '];
     519                elseif exist(htmlfullname2,'file') == 2 % exists elsewhere?
     520                        s = [s '<a href="../' fullfile(subdir,htmlname) '">' tok '</a>, '];
    472521                elseif isempty(tok) || ~isempty(regexp(tok,'^ *', 'once' ))
    473522                        ;
     
    554603return
    555604
    556 function run_all_files(command)
    557 
    558 dirs = {'ldc','dataset','datafile','mapping'};
     605function run_all_files(command,dirs,subdir)
     606
     607%dirs = {'ldc','dataset','datafile','mapping'};
    559608for n=1:length(dirs)
    560609        prtools_dir = fileparts(which(dirs{n}));
     
    564613                [qq,name] = fileparts(ff{j});
    565614                if n==1
    566                         feval(command,name); % prtools main commands
     615                        feval(command,name,[],fullfile(subdir,prtools_dirname)); % prtools main commands
    567616                else
    568                         feval(command,fullfile(prtools_dirname,name)); % subdir commands
     617                        feval(command,fullfile(prtools_dirname,name),[],fullfile(subdir,prtools_dirname)); % subdir commands
    569618                end
    570619        end
Note: See TracChangeset for help on using the changeset viewer.